{"schemaVersion":1,"slug":"component-crop-box-input","kind":"component","version":"0.1.0","files":[{"path":"Component.jsx","content":"'use client'\nimport React from 'react'\nimport Example from './crop-box-input.jsx'\nimport './collection.css'\nexport default function Component(props) {\n  return <div className=\"lq-component\" data-family=\"forms\"><Example {...props}/></div>\n}\n","sha256":"fd2594f0997bde4ff415b2e5ca7c96aef400c57d4e11c14f94e1aac1b8b887eb"},{"path":"crop-box-input.jsx","content":"import React, { useState } from 'react'\nimport { translator, Surface, Field, Row, Result } from './shared.jsx'\n\nconst initial = { x: '16', y: '14', w: '58', h: '62' }\n\nexport default function CropBoxInput({ locale = 'en' }) {\n  const t = translator(locale)\n  const [saved, setSaved] = useState(initial)\n  const [draft, setDraft] = useState(initial)\n  const fields = {\n    x: t('Left (%)', '左边距（%）', 'Izquierda (%)', '左位置（%）'),\n    y: t('Top (%)', '上边距（%）', 'Parte superior (%)', '上位置（%）'),\n    w: t('Width (%)', '宽度（%）', 'Ancho (%)', '幅（%）'),\n    h: t('Height (%)', '高度（%）', 'Alto (%)', '高さ（%）'),\n  }\n  const valid =\n    Object.entries(draft).every(\n      ([key, value]) =>\n        value !== '' &&\n        Number.isInteger(Number(value)) &&\n        Number(value) >= (key === 'x' || key === 'y' ? 0 : 1) &&\n        Number(value) <= 100,\n    ) &&\n    Number(draft.x) + Number(draft.w) <= 100 &&\n    Number(draft.y) + Number(draft.h) <= 100\n  const changed = Object.keys(initial).some((key) => draft[key] !== saved[key])\n  const box = valid ? draft : saved\n  return (\n    <Surface>\n      <div\n        role=\"img\"\n        aria-label={\n          t(\n            'Crop preview',\n            '裁剪预览',\n            'Vista previa del recorte',\n            '切り抜きプレビュー',\n          ) +\n          ' · ' +\n          [box.x, box.y, box.w, box.h].join(', ')\n        }\n        style={{\n          position: 'relative',\n          overflow: 'hidden',\n          isolation: 'isolate',\n          height: 'min(32vw,160px)',\n          minHeight: 96,\n          borderRadius: 6,\n          backgroundColor: '#253d50',\n          backgroundImage:\n            'repeating-linear-gradient(116deg,transparent 0 23px,#849dab28 24px 25px),linear-gradient(154deg,#172b3a 4%,#7091a6 49%,#304e66 50%,#1d3446 88%)',\n        }}\n      >\n        <div\n          aria-hidden=\"true\"\n          style={{\n            position: 'absolute',\n            left: box.x + '%',\n            top: box.y + '%',\n            width: box.w + '%',\n            height: box.h + '%',\n            border: '2px solid white',\n            boxShadow: '0 0 0 500px #0a142876',\n          }}\n        />\n      </div>\n      <Row>\n        {Object.entries(fields).map(([key, label]) => (\n          <Field key={key} label={label}>\n            <input\n              type=\"number\"\n              min={key === 'x' || key === 'y' ? 0 : 1}\n              max=\"100\"\n              step=\"1\"\n              value={draft[key]}\n              onChange={(e) => setDraft({ ...draft, [key]: e.target.value })}\n            />\n          </Field>\n        ))}\n      </Row>\n      <Row>\n        <button\n          type=\"button\"\n          disabled={!valid || !changed}\n          onClick={() => setSaved({ ...draft })}\n        >\n          {t('Apply crop', '应用裁剪', 'Aplicar recorte', '切り抜きを適用')}\n        </button>\n        <button\n          type=\"button\"\n          disabled={!changed}\n          onClick={() => setDraft({ ...saved })}\n        >\n          {t(\n            'Restore applied crop',\n            '恢复已应用的裁剪',\n            'Restaurar recorte aplicado',\n            '適用済みの範囲に戻す',\n          )}\n        </button>\n      </Row>\n      <Result>\n        {!valid\n          ? t(\n              'Keep the entire rectangle inside the image. Showing the applied crop.',\n              '矩形必须完全位于图像内。当前显示已应用的裁剪。',\n              'El rectángulo debe quedar dentro de la imagen. Se muestra el recorte aplicado.',\n              '矩形を画像内に収めてください。適用済みの範囲を表示しています。',\n            )\n          : changed\n            ? t(\n                'Draft preview',\n                '草稿预览',\n                'Vista previa del borrador',\n                '下書きプレビュー',\n              )\n            : t(\n                'Applied crop',\n                '已应用的裁剪',\n                'Recorte aplicado',\n                '適用済みの範囲',\n              )}{' '}\n        · {[box.x, box.y, box.w, box.h].join(', ')}\n      </Result>\n    </Surface>\n  )\n}\n","sha256":"1d618cfd91491b93aa1004c17c70a08ae89b028e3b9bd6b25390e7c9bf3ae450"},{"path":"collection.css","content":"/* Portable styles for the optional wrapper in Component.jsx. */\n.lq-component {\n  --cc-ink:#162632; --cc-muted:#526572; --cc-stroke:#cbd5dc; --cc-tint:#edf3f6;\n  --cc-blue:#426981; --cc-surface:#fff; --cc-inverse:#fff;\n  font:400 15px/1.55 system-ui,sans-serif; color:var(--cc-ink);\n  min-width:0; width:100%; overflow-wrap:anywhere; color-scheme:light;\n}\n.lq-component *, .lq-component *::before,.lq-component *::after { box-sizing:border-box; }\n.lq-component :is(h2,h3,h4,p,ul,ol,dl,form,fieldset,figure,table) { margin:0 0 .85em; }\n.lq-component :is(h2,h3) { font-size:clamp(20px,2vw,29px); line-height:1.18; letter-spacing:-.035em; }\n.lq-component h4 {font-size:1rem}\n.lq-component :is(ol,ul){padding-inline-start:1.4em}\n.lq-component label { display:inline-flex; flex-direction:column; gap:4px; max-width:100%; font-size:14px; font-weight:550; }\n.lq-component label:has(input[type=checkbox]),.lq-component label:has(input[type=radio]) {flex-direction:row;align-items:center}\n.lq-component :is(input,select,textarea,button){font:inherit;max-width:100%;accent-color:var(--cc-blue)}\n.lq-component :is(input:not([type=checkbox],[type=radio],[type=range],[type=file]),select,textarea){\n  color:var(--cc-ink); background:var(--cc-surface); border:1px solid #a9bac5; border-radius:6px; padding:7px 10px;min-width:0;\n}\n.lq-component textarea{min-height:64px}\n.lq-component :is(button,summary){cursor:pointer;}\n.lq-component button{\n  color:var(--cc-ink);background:var(--cc-tint);border:1px solid var(--cc-stroke);\n  border-radius:6px;min-height:35px;padding:5px 11px;font-weight:600;font-size:14px;\n}\n.lq-component button:disabled{opacity:.5;cursor:default}\n.lq-component button[aria-pressed=true],.lq-component [role=tab][aria-selected=true]{background:var(--cc-ink);color:var(--cc-inverse)}\n.lq-component :focus-visible{outline:2px solid var(--cc-blue);outline-offset:2px}\n.lq-component output {display:block;color:var(--cc-ink);font-weight:650;font-variant-numeric:tabular-nums}\n.lq-component :is(.collection-actions,.collection-row,.demo-actions){display:flex;align-items:end;gap:9px;flex-wrap:wrap;margin-block:12px}\n.lq-component :is(.collection-fields,.form-fields){display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,180px),1fr));gap:14px;margin-block:14px}\n.lq-component :is(.collection-output,.demo-output){padding:12px;border-inline-start:3px solid var(--cc-blue);background:var(--cc-tint);margin-block:14px}\n.lq-component fieldset {border:1px solid var(--cc-stroke);border-radius:8px;padding:12px;min-width:0}\n.lq-component .collection-demo>*,.lq-component .viz-study>*{max-width:100%}\n.lq-component :is(form,fieldset)>label {margin:0 10px 10px 0}\n.lq-component :is(button+button,label+button) {margin-inline-start:3px}\n.lq-component table{width:100%;border-collapse:collapse;font-variant-numeric:tabular-nums;overflow-wrap:anywhere}\n.lq-component :is(th,td){padding:6px;text-align:start;border-bottom:1px solid var(--cc-stroke)}\n.lq-component dialog{max-width:min(90vw,500px);border:1px solid var(--cc-stroke);border-radius:10px;padding:20px;color:var(--cc-ink);background:white}\n.lq-component dialog::backdrop{background:rgb(17 29 39/.45)}\n.lq-component :is(svg,canvas,img){max-width:100%}\n@media(hover:hover){.lq-component button:not(:disabled):hover{border-color:var(--cc-blue)}}\n@media(pointer:coarse){.lq-component button,.lq-component select,.lq-component input[type=range]{min-height:44px}}\n@media(prefers-reduced-motion:reduce){.lq-component *, .lq-component *::before,.lq-component *::after{animation-duration:0s!important;transition-duration:0s!important;scroll-behavior:auto!important}}\n.lq-component :is(.viz-study,.wf-demo,.collection-demo)>label {margin:0 16px 12px 0}\n.lq-component .viz-study>svg[role=img]{display:block;margin:6px 0 14px}\n.lq-component .viz-study>output{border-top:1px solid var(--cc-stroke);padding:12px 0 0;font-variant-numeric:tabular-nums}\n.lq-component :is(.wf-demo,.collection-demo) form{display:flex;align-items:end;flex-wrap:wrap;gap:9px 14px}\n.lq-component :is(.wf-demo,.collection-demo) label textarea{width:min(100%,34rem)}\n.lq-component :is(.wf-demo,.collection-demo)>:is(output,[role=status]){display:block;margin-top:12px;color:var(--cc-blue);font-weight:600}\n.lq-component .collection-fields>.collection-row,.lq-component .collection-fields>.collection-output,.lq-component .collection-fields>svg{grid-column:1/-1}\n","sha256":"9a629a50c65fc07377b3d164b571ed33b8bd54c392ff4dab06c4fd317c0864ab"},{"path":"shared.jsx","content":"import React from 'react'\n\nconst languages = ['en', 'zh-CN', 'es', 'ja']\nexport function translator(locale) {\n  const index = Math.max(0, languages.indexOf(locale))\n  return (english, chinese, spanish, japanese) =>\n    [english, chinese, spanish, japanese][index] || english\n}\n\nexport function Surface({ children, onSubmit }) {\n  return (\n    <form\n      className=\"collection-form\"\n      onSubmit={(event) => {\n        event.preventDefault()\n        onSubmit?.()\n      }}\n    >\n      <div className=\"collection-fields\">{children}</div>\n    </form>\n  )\n}\nexport function Field({ label, children }) {\n  return (\n    <label className=\"collection-field\">\n      <span>{label}</span>\n      {children}\n    </label>\n  )\n}\nexport function Row({ children }) {\n  return <div className=\"collection-row\">{children}</div>\n}\nexport function Result({ children }) {\n  return (\n    <p className=\"collection-output\" role=\"status\" aria-live=\"polite\">\n      {children}\n    </p>\n  )\n}\n","sha256":"3a02aa15a3aede03a581a4e8eafb427492a0dfff64bddfdb91f2664bf6b8f3d5"},{"path":"README.md","content":"# Crop box editor\n\nPosition and resize a crop inside an image, then apply or restore the preview.\n\nImport the default export from Component.jsx into a React client entry. The locale prop accepts en, zh-CN, es and ja. Use your host’s existing React dependency and test and build commands. The sample runs locally.\n","sha256":"bf22d0f6da259f01af41f4bc4f3c78906182be257f96d5c40d500421cb3336fe"}]}
