{"schemaVersion":1,"slug":"component-diff-paste-review","kind":"component","version":"0.1.0","files":[{"path":"Component.jsx","content":"'use client'\nimport React from 'react'\nimport Example from './diff-paste-review.jsx'\nimport './collection.css'\nexport default function Component(props) {\n  return <div className=\"lq-component\" data-family=\"forms\"><Example {...props}/></div>\n}\n","sha256":"6f133f80b57c42a469c02e0982ac4bd8f90567a3bd6c1042702ba8e4c23c3c64"},{"path":"diff-paste-review.jsx","content":"import React, { useMemo, useState } from 'react'\nimport { translator, Surface, Field, Row, Result } from './shared.jsx'\n\n// Match stable lines before pairing insertions and removals. The input limit caps the matrix.\nfunction compare(base, proposal) {\n  const left = base ? base.split('\\n') : [],\n    right = proposal ? proposal.split('\\n') : []\n  if (left.length > 80 || right.length > 80) return null\n  const scores = Array.from(\n    { length: left.length + 1 },\n    () => new Uint8Array(right.length + 1),\n  )\n  for (let i = left.length - 1; i >= 0; i--) {\n    for (let j = right.length - 1; j >= 0; j--) {\n      scores[i][j] =\n        left[i] === right[j]\n          ? 1 + scores[i + 1][j + 1]\n          : Math.max(scores[i + 1][j], scores[i][j + 1])\n    }\n  }\n  const rows = [],\n    removed = [],\n    inserted = []\n  function flush() {\n    for (let n = 0; n < Math.max(removed.length, inserted.length); n++) {\n      rows.push({ before: removed[n], after: inserted[n], changed: true })\n    }\n    removed.length = 0\n    inserted.length = 0\n  }\n  let i = 0,\n    j = 0\n  while (i < left.length || j < right.length) {\n    if (i < left.length && j < right.length && left[i] === right[j]) {\n      flush()\n      rows.push({ before: left[i++], after: right[j++], changed: false })\n    } else if (\n      i < left.length &&\n      (j === right.length || scores[i + 1][j] >= scores[i][j + 1])\n    ) {\n      removed.push(left[i++])\n    } else inserted.push(right[j++])\n  }\n  flush()\n  return rows\n}\nexport default function DiffPasteReview({ locale = 'en' }) {\n  const t = translator(locale),\n    [base, setBase] = useState('theme=frost\\nlimit=12\\nmode=local'),\n    [proposal, setProposal] = useState(\n      'theme=slate\\nlimit=12\\nformat=json\\nmode=local',\n    )\n  const [accepted, setAccepted] = useState([])\n  const rows = useMemo(() => compare(base, proposal), [base, proposal])\n  const merged = rows\n    ?.map((row, i) => (accepted.includes(i) ? row.after : row.before))\n    .filter((line) => line !== undefined)\n    .join('\\n')\n  function edit(set, value) {\n    set(value)\n    setAccepted([])\n  }\n  return (\n    <Surface>\n      <Row>\n        <Field\n          label={t(\n            'Original text',\n            '原始文本',\n            'Texto original',\n            '元のテキスト',\n          )}\n        >\n          <textarea\n            rows={3}\n            value={base}\n            maxLength={4000}\n            onChange={(e) => edit(setBase, e.target.value)}\n          />\n        </Field>\n        <Field\n          label={t('Proposed text', '建议文本', 'Texto propuesto', '変更案')}\n        >\n          <textarea\n            rows={3}\n            value={proposal}\n            maxLength={4000}\n            onChange={(e) => edit(setProposal, e.target.value)}\n          />\n        </Field>\n      </Row>\n      {rows && (\n        <fieldset>\n          <legend>\n            {t(\n              'Accept selected changes',\n              '选择要接受的改动',\n              'Aceptar los cambios seleccionados',\n              '採用する変更',\n            )}\n          </legend>\n          {rows.map(\n            (row, i) =>\n              row.changed && (\n                <label\n                  key={i}\n                  style={{ display: 'flex', gap: 8, marginBlock: 4 }}\n                >\n                  <input\n                    type=\"checkbox\"\n                    checked={accepted.includes(i)}\n                    onChange={(e) =>\n                      setAccepted(\n                        e.target.checked\n                          ? [...accepted, i]\n                          : accepted.filter((id) => id !== i),\n                      )\n                    }\n                  />\n                  <span>\n                    <strong>{i + 1}</strong>{' '}\n                    {row.before !== undefined && <del>{row.before || '␣'}</del>}{' '}\n                    {row.after !== undefined && (\n                      <ins style={{ textDecoration: 'none' }}>\n                        {row.after || '␣'}\n                      </ins>\n                    )}\n                  </span>\n                </label>\n              ),\n          )}\n        </fieldset>\n      )}\n      <Result>\n        {rows\n          ? accepted.length +\n            ' / ' +\n            rows.filter((row) => row.changed).length +\n            ' · ' +\n            t(\n              'changes accepted',\n              '项改动已接受',\n              'cambios aceptados',\n              '件の変更を採用',\n            )\n          : t(\n              'Limit each text to 80 lines.',\n              '每段文本最多 80 行。',\n              'Limita cada texto a 80 líneas.',\n              '各テキストは80行以内にしてください。',\n            )}\n      </Result>\n      {rows && (\n        <Field\n          label={t(\n            'Merged result',\n            '合并结果',\n            'Resultado combinado',\n            'マージ結果',\n          )}\n        >\n          <textarea rows={3} readOnly value={merged} />\n        </Field>\n      )}\n    </Surface>\n  )\n}\n","sha256":"4257776b8518d18404d835ef1366cea7b8bb79338225de37adcb77a1f0d78532"},{"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":"# Line-by-line merge\n\nCompare two pasted texts, accept individual changes and read the merged result.\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":"5ebbbb2e8e5cc824fe33b0b7928d8d6c1a66dab77d5b2eb1fe2c51e1a13d96b9"}]}
