@open-document/core 0.13.2 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/dist/{build-CvsOak5B.js → build-CyBlmrjS.js} +1 -1
  2. package/dist/{check-CbUBwYmf.js → check-DUKDEem-.js} +3 -3
  3. package/dist/cli/bin.js +10 -21
  4. package/dist/{config-BWtOZ1jc.d.ts → config-cAV1OCuY.d.ts} +9 -1
  5. package/dist/{config-CltJJVsw.js → config-cNpYUpF6.js} +2746 -369
  6. package/dist/{context-CWgfsHoE.js → context-BPApOW9n.js} +1 -1
  7. package/dist/{dev-B8H2qT6G.js → dev-DrnOvsX3.js} +1 -1
  8. package/dist/{diff-BvIjjgnc.js → diff-BPMD2Knh.js} +2 -2
  9. package/dist/{export-DX30_s2q.js → export-DeVtL8aX.js} +3 -3
  10. package/dist/{import-DgsdJT5e.js → import-WAgWsuOv.js} +3 -2
  11. package/dist/index.d.ts +2 -2
  12. package/dist/ops/index.d.ts +3 -1
  13. package/dist/ops/index.js +2 -2
  14. package/dist/{ops-CSR5RlrE.js → ops-raK6424A.js} +2 -854
  15. package/dist/{preview-DYMUNjXL.js → preview-B8Vw9QCh.js} +1 -1
  16. package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
  17. package/dist/{templates-B5Tz0AKb.js → templates-D9jAFJ8R.js} +3 -3
  18. package/dist/vite/index.d.ts +1 -1
  19. package/dist/vite/index.js +1 -1
  20. package/package.json +1 -1
  21. package/skills/create-doc/SKILL.md +1 -1
  22. package/skills/doc-authoring/SKILL.md +6 -0
  23. package/src/app/app.tsx +2 -0
  24. package/src/app/components/agent/agent-dock.tsx +75 -0
  25. package/src/app/components/agent/agent-markdown.tsx +45 -0
  26. package/src/app/components/agent/agent-panel.tsx +690 -0
  27. package/src/app/components/agent/agent-presence.tsx +74 -0
  28. package/src/app/components/agent/composer.tsx +120 -0
  29. package/src/app/components/agent/connect-view.tsx +183 -0
  30. package/src/app/components/agent/history-view.tsx +134 -0
  31. package/src/app/components/agent/provider-logo.tsx +23 -0
  32. package/src/app/components/agent/transcript.tsx +609 -0
  33. package/src/app/components/comments/comments-panel.tsx +26 -2
  34. package/src/app/components/inspector/inspector.tsx +17 -0
  35. package/src/app/components/note-markdown.tsx +85 -0
  36. package/src/app/components/page-error-boundary.tsx +84 -0
  37. package/src/app/components/page-frame.tsx +2 -1
  38. package/src/app/components/panel/resize-handle.tsx +129 -0
  39. package/src/app/components/ui/button.tsx +97 -0
  40. package/src/app/components/ui/popover.tsx +144 -0
  41. package/src/app/components/ui/tooltip.tsx +123 -0
  42. package/src/app/lib/agent/use-agent.ts +543 -0
  43. package/src/app/lib/diagnostics.ts +13 -0
  44. package/src/app/lib/docx/from-dom.ts +91 -6
  45. package/src/app/lib/docx/ooxml.test.ts +58 -0
  46. package/src/app/lib/docx/ooxml.ts +58 -9
  47. package/src/app/lib/export-dom.ts +2 -1
  48. package/src/app/lib/export-pdf.ts +2 -1
  49. package/src/app/lib/i18n-ja/agent-panel.ts +107 -0
  50. package/src/app/lib/i18n-ja/agent.ts +9 -0
  51. package/src/app/lib/i18n-ja/index.ts +9 -1
  52. package/src/app/lib/i18n-ko/agent-panel.ts +106 -0
  53. package/src/app/lib/i18n-ko/agent.ts +9 -0
  54. package/src/app/lib/i18n-ko/index.ts +9 -1
  55. package/src/app/lib/i18n-zh-cn/agent-panel.ts +105 -0
  56. package/src/app/lib/i18n-zh-cn/agent.ts +9 -0
  57. package/src/app/lib/i18n-zh-cn/index.ts +9 -1
  58. package/src/app/lib/i18n-zh-tw/agent-panel.ts +105 -0
  59. package/src/app/lib/i18n-zh-tw/agent.ts +9 -0
  60. package/src/app/lib/i18n-zh-tw/index.ts +9 -1
  61. package/src/app/lib/note-markdown.ts +116 -0
  62. package/src/app/lib/toast.ts +50 -0
  63. package/src/app/lib/use-auto-grow.ts +15 -0
  64. package/src/app/lib/use-doc-titles.ts +28 -0
  65. package/src/app/lib/use-locale.ts +144 -0
  66. package/src/app/lib/utils.ts +4 -0
  67. package/src/app/routes/doc-preview.tsx +103 -0
  68. package/src/app/routes/doc.tsx +118 -11
  69. package/src/app/routes/home.tsx +43 -8
  70. package/src/app/styles.css +193 -0
@@ -63,6 +63,7 @@ export type WalkResult = {
63
63
  finalRunning: boolean;
64
64
  finalColumns?: SectionLayout['columns'];
65
65
  finalContinuous?: boolean;
66
+ finalFoot?: Paragraph;
66
67
  };
67
68
 
68
69
  type Ctx = WalkOptions & {
@@ -116,10 +117,14 @@ const INLINE_DISPLAYS = new Set([
116
117
  const STRUCTURE = 'p,h1,h2,h3,h4,h5,h6,table,ul,ol,pre,blockquote';
117
118
 
118
119
  /** Where each block sat on its sheet, for fixed pages whose layout is by position. */
119
- const placed = new WeakMap<Block, { top: number; bottom: number }>();
120
+ type Box = { top: number; bottom: number; left: number; right: number };
120
121
 
121
- function place(block: Block, box: { top: number; bottom: number }) {
122
- if (!placed.has(block)) placed.set(block, { top: box.top, bottom: box.bottom });
122
+ const placed = new WeakMap<Block, Box>();
123
+
124
+ function place(block: Block, box: Box) {
125
+ if (!placed.has(block)) {
126
+ placed.set(block, { top: box.top, bottom: box.bottom, left: box.left, right: box.right });
127
+ }
123
128
  }
124
129
 
125
130
  function isHidden(el: Element): boolean {
@@ -303,12 +308,32 @@ async function inlinesOf(
303
308
  );
304
309
  out.push({ type: 'link', href: node.getAttribute('href') as string, runs });
305
310
  } else {
306
- out.push(...(await inlinesOf(Array.from(node.childNodes), base, ctx, linked)));
311
+ const inner = await inlinesOf(Array.from(node.childNodes), base, ctx, linked);
312
+ out.push(...shaded(node, inner));
307
313
  }
308
314
  }
309
315
  return out;
310
316
  }
311
317
 
318
+ /**
319
+ * Words set on a tint of their own — a pill, a badge — keep it as a character
320
+ * background, and a pill's side padding as a space on either side.
321
+ */
322
+ function shaded(el: Element, inlines: Inline[]): Inline[] {
323
+ const style = getComputedStyle(el);
324
+ if (!INLINE_DISPLAYS.has(style.display) || style.display === 'contents') return inlines;
325
+ const shade = hexColor(style.backgroundColor);
326
+ if (!shade) return inlines;
327
+ const tinted = inlines.map(
328
+ (inline): Inline =>
329
+ inline.type === 'text' ? { ...inline, shade: inline.shade ?? shade } : inline,
330
+ );
331
+ const first = tinted.find((inline): inline is TextRun => inline.type === 'text');
332
+ if (!first || (Number.parseFloat(style.paddingLeft) || 0) < 4) return tinted;
333
+ const pad: TextRun = { ...first, text: '\u00a0' };
334
+ return [pad, ...tinted, { ...pad }];
335
+ }
336
+
312
337
  /** Trims the whitespace a browser would not draw: at either end, and doubled between runs. */
313
338
  function tidy(inlines: Inline[]): Inline[] {
314
339
  const texts: TextRun[] = [];
@@ -523,10 +548,20 @@ async function blockOfElement(el: Element, ctx: Ctx, out: Block[], style: StyleI
523
548
  inlines.push(...tidy(await inlinesOf([piece], ctx.baselines[style], ctx)));
524
549
  }
525
550
  if (inlines.some((inline) => inline.type !== 'tab')) {
551
+ const look = getComputedStyle(el);
552
+ const rule = border(look, 'Top');
526
553
  out.push({
527
554
  type: 'paragraph',
528
555
  inlines,
529
556
  rightTab: ctx.textWidth * PX_TO_TWIPS,
557
+ ...(rule
558
+ ? {
559
+ ruleAbove: {
560
+ ...rule,
561
+ gap: (Number.parseFloat(look.paddingTop) || 0) * PX_TO_TWIPS,
562
+ },
563
+ }
564
+ : {}),
530
565
  ...spacing(el),
531
566
  ...(style !== 'Normal' ? { style } : {}),
532
567
  });
@@ -829,10 +864,15 @@ async function tableOf(table: HTMLTableElement, ctx: Ctx): Promise<Table> {
829
864
  const edge = border(style, side);
830
865
  if (edge) borders[side.toLowerCase() as 'top'] = edge;
831
866
  }
867
+ const fill =
868
+ dataBarFill(style) ??
869
+ hexColor(style.backgroundColor) ??
870
+ hexColor(getComputedStyle(row).backgroundColor);
832
871
  cells.push({
833
872
  blocks: paragraphs,
834
873
  ...(cell.colSpan > 1 ? { span: cell.colSpan } : {}),
835
874
  borders,
875
+ ...(fill ? { fill } : {}),
836
876
  padding: {
837
877
  top: (Number.parseFloat(style.paddingTop) || 0) * PX_TO_TWIPS,
838
878
  left: (Number.parseFloat(style.paddingLeft) || 0) * PX_TO_TWIPS,
@@ -846,6 +886,31 @@ async function tableOf(table: HTMLTableElement, ctx: Ctx): Promise<Table> {
846
886
  return out;
847
887
  }
848
888
 
889
+ /**
890
+ * A cell drawn with a bar behind its value — `linear-gradient(to right, tint
891
+ * n%, transparent n%)`, a data bar. Neither Word nor Pages can fill part of a
892
+ * cell, and Pages drops a picture pinned inside one, so the value is told by
893
+ * how deep the cell's tint is instead of how far it reaches.
894
+ */
895
+ function dataBarFill(style: CSSStyleDeclaration): string | null {
896
+ const gradient = style.backgroundImage.match(
897
+ /^linear-gradient\(to right,\s*((?:rgba?|color)\([^)]*\))\s+([\d.]+)%/,
898
+ );
899
+ if (!gradient?.[1] || !gradient[2]) return null;
900
+ const tint = hexColor(gradient[1]);
901
+ const ratio = Math.min(1, Number(gradient[2]) / 100);
902
+ if (!tint || !(ratio > 0)) return null;
903
+ const depth = 0.25 + 0.75 * ratio;
904
+ return [0, 2, 4]
905
+ .map((at) => {
906
+ const channel = Number.parseInt(tint.slice(at, at + 2), 16);
907
+ return Math.round(255 - (255 - channel) * depth)
908
+ .toString(16)
909
+ .padStart(2, '0');
910
+ })
911
+ .join('');
912
+ }
913
+
849
914
  async function figureOf(figure: Element, ctx: Ctx, out: Block[]) {
850
915
  const start = out.length;
851
916
  await figureParts(figure, ctx, out);
@@ -955,6 +1020,7 @@ export async function docxFromPages(
955
1020
  first: index === 0,
956
1021
  };
957
1022
  const own: Block[] = [];
1023
+ let foot: Paragraph | undefined;
958
1024
  const flowBlocks = Array.from(host.querySelectorAll(`[${FLOW_BLOCK_ATTR}]`));
959
1025
  const columnsHere = flowBlocks.length > 0 ? columnBoxOf(host) : null;
960
1026
  if (flowBlocks.length > 0) {
@@ -1030,6 +1096,22 @@ export async function docxFromPages(
1030
1096
  }
1031
1097
  bottom = Math.max(bottom, box.bottom);
1032
1098
  }
1099
+ // A last line laid out against the foot of the sheet — a cover's byline,
1100
+ // pushed down by `justify-content: space-between` — becomes this page's
1101
+ // footer: as flowed text its place would depend on how tall everything
1102
+ // above it came out in Word, which is never quite what the page drew.
1103
+ const last = own[own.length - 1];
1104
+ const lastBox = last ? placed.get(last) : undefined;
1105
+ if (
1106
+ last?.type === 'paragraph' &&
1107
+ lastBox &&
1108
+ own.length > 1 &&
1109
+ rect.bottom - options.margin - lastBox.bottom < 24 &&
1110
+ (last.spacingBefore ?? 0) > 48 * PX_TO_TWIPS
1111
+ ) {
1112
+ own.pop();
1113
+ foot = { ...last, spacingBefore: 0, spacingAfter: 0 };
1114
+ }
1033
1115
  // Word sets a heading's line from the font's own height, taller than the
1034
1116
  // page's CSS line-height, so a sheet laid out to its last pixel — a
1035
1117
  // cover's byline at the foot — would spill its last lines onto a page of
@@ -1052,7 +1134,7 @@ export async function docxFromPages(
1052
1134
  // prints its own running lines, so it sits in a section without them. A
1053
1135
  // flow set in columns is a section of that many columns. The section
1054
1136
  // break itself starts the next page.
1055
- const layout: SectionLayout = { running: !ctx.page.fixed };
1137
+ const layout: SectionLayout = { running: !ctx.page.fixed, ...(foot ? { foot } : {}) };
1056
1138
  if (!ctx.page.fixed && columnsHere) {
1057
1139
  layout.columns = { count: columnsHere.count, gap: columnsHere.gap * PX_TO_TWIPS };
1058
1140
  }
@@ -1060,7 +1142,9 @@ export async function docxFromPages(
1060
1142
  own.length > 0 &&
1061
1143
  blocks.length > 0 &&
1062
1144
  (layout.running !== previous.running ||
1063
- (layout.columns?.count ?? 1) !== (previous.columns?.count ?? 1));
1145
+ (layout.columns?.count ?? 1) !== (previous.columns?.count ?? 1) ||
1146
+ Boolean(layout.foot) ||
1147
+ Boolean(previous.foot));
1064
1148
  // Columns fill one at a time to the foot of the page unless a continuous
1065
1149
  // break ends them, so the section after a set of columns starts on their
1066
1150
  // page and breaks to its own with the first paragraph instead.
@@ -1133,6 +1217,7 @@ export async function docxFromPages(
1133
1217
  finalRunning: previous.running,
1134
1218
  ...(previous.columns ? { finalColumns: previous.columns } : {}),
1135
1219
  ...(previous.continuous ? { finalContinuous: true } : {}),
1220
+ ...(previous.foot ? { finalFoot: previous.foot } : {}),
1136
1221
  };
1137
1222
  }
1138
1223
 
@@ -28,6 +28,11 @@ describe('fontsFor', () => {
28
28
  });
29
29
  });
30
30
 
31
+ it('skips Apple system faces no app can pick by name', () => {
32
+ expect(fontsFor('ui-monospace, "SF Mono", Menlo, monospace', 'mono').ascii).toBe('Menlo');
33
+ expect(fontsFor('"SF Pro Text", Helvetica, sans-serif', 'sans').ascii).toBe('Helvetica');
34
+ });
35
+
31
36
  it('falls back by generic family when nothing is named', () => {
32
37
  expect(fontsFor('system-ui, sans-serif', 'sans').ascii).toBe('Arial');
33
38
  expect(fontsFor('serif', 'sans').ascii).toBe('Times New Roman');
@@ -368,6 +373,59 @@ describe('buildDocxParts', () => {
368
373
  expect(doc.match(/<w:cols /g)).toHaveLength(1);
369
374
  });
370
375
 
376
+ it('shades a pill and rules a line above a paragraph', () => {
377
+ const doc = buildDocxParts({
378
+ ...MODEL,
379
+ blocks: [
380
+ {
381
+ type: 'paragraph',
382
+ ruleAbove: { color: 'e2e8f0', size: 6, gap: 210 },
383
+ inlines: [{ type: 'text', text: 'OPEN-DOC', shade: 'e9effd' }],
384
+ },
385
+ ],
386
+ })['word/document.xml'] as string;
387
+ expect(doc).toContain(
388
+ '<w:pBdr><w:top w:val="single" w:sz="6" w:space="11" w:color="e2e8f0"/></w:pBdr>',
389
+ );
390
+ expect(doc).toContain(
391
+ '<w:rPr><w:shd w:val="clear" w:color="auto" w:fill="e9effd"/></w:rPr><w:t xml:space="preserve">OPEN-DOC</w:t>',
392
+ );
393
+ });
394
+
395
+ it('gives a sheet’s own foot a footer of its section, and the rest an empty one', () => {
396
+ const parts = buildDocxParts({
397
+ ...MODEL,
398
+ footer: undefined,
399
+ blocks: [
400
+ {
401
+ type: 'paragraph',
402
+ inlines: [{ type: 'text', text: 'Cover' }],
403
+ sectionEnd: {
404
+ running: false,
405
+ foot: { type: 'paragraph', inlines: [{ type: 'text', text: 'Byline' }] },
406
+ },
407
+ },
408
+ { type: 'paragraph', inlines: [{ type: 'text', text: 'Body' }] },
409
+ ],
410
+ });
411
+ const doc = parts['word/document.xml'] as string;
412
+ const rels = parts['word/_rels/document.xml.rels'] as string;
413
+ const id = (target: string) =>
414
+ rels.match(new RegExp(`Id="(rId\\d+)"[^>]*Target="${target}"`))?.[1];
415
+ expect(parts['word/footer3.xml']).toContain('Byline');
416
+ // Set in the body's style, and placed a page margin above the sheet's edge.
417
+ expect(parts['word/footer3.xml']).not.toContain('w:val="Footer"');
418
+ expect(doc).toMatch(
419
+ new RegExp(
420
+ `<w:footerReference w:type="default" r:id="${id('footer3.xml')}"/>.*w:footer="1140".*Cover`,
421
+ ),
422
+ );
423
+ // Without a footer of its own, the next section would inherit the cover's.
424
+ expect(doc).toMatch(
425
+ new RegExp(`Body.*<w:footerReference w:type="default" r:id="${id('footer2.xml')}"/>`),
426
+ );
427
+ });
428
+
371
429
  it('stamps the watermark behind the text from every header', () => {
372
430
  const parts = buildDocxParts({
373
431
  ...MODEL,
@@ -27,6 +27,8 @@ export type TextRun = {
27
27
  /** Font size in half-points, only when it differs from the paragraph style's. */
28
28
  halfPoints?: number;
29
29
  vert?: 'superscript' | 'subscript';
30
+ /** Background behind the characters, `rrggbb` — an inline pill or badge. */
31
+ shade?: string;
30
32
  };
31
33
 
32
34
  export type Run =
@@ -78,6 +80,8 @@ export type Paragraph = {
78
80
  hanging?: number;
79
81
  /** Background behind the paragraph, `rrggbb` — a highlighted line of code. */
80
82
  shade?: string;
83
+ /** A rule above the paragraph and the gap between it and the text, twips. */
84
+ ruleAbove?: { color: string; size: number; gap: number };
81
85
  /** An exact line height, twips — a spacer that holds open a gap. */
82
86
  lineExact?: number;
83
87
  /**
@@ -105,6 +109,12 @@ export type SectionLayout = {
105
109
  * columns of a section only where a continuous break ends it.
106
110
  */
107
111
  continuous?: boolean;
112
+ /**
113
+ * A line the sheet laid out against its own foot — a cover's byline. It is
114
+ * this section's footer, so it sits at the foot of the page whatever came
115
+ * out above it.
116
+ */
117
+ foot?: Paragraph;
108
118
  };
109
119
 
110
120
  export type CellBorder = { color: string /** Eighths of a point. */; size: number };
@@ -187,6 +197,7 @@ export type DocxModel = {
187
197
  /** The last section's columns and start, as `SectionLayout`. */
188
198
  finalColumns?: SectionLayout['columns'];
189
199
  finalContinuous?: boolean;
200
+ finalFoot?: Paragraph;
190
201
  /** A picture behind the text of every page, the size of the sheet — `meta.watermark`. */
191
202
  watermark?: string;
192
203
  images: ImagePart[];
@@ -253,6 +264,13 @@ const GENERIC = new Set([
253
264
  'inherit',
254
265
  ]);
255
266
 
267
+ /**
268
+ * Apple's system faces: a page draws in them, but no app outside the system can
269
+ * pick one by name, so Pages and Word would fall back to Courier or Times. The
270
+ * next family in the stack — Menlo, Helvetica — is the one that will be there.
271
+ */
272
+ const SYSTEM_ONLY = /^(\.?sf ?(mono|pro|compact)|sfmono-|sfns)/i;
273
+
256
274
  const CJK_FONT =
257
275
  /noto (sans|serif) (tc|sc|jp|kr|hk|cjk)|pingfang|hiragino|jhenghei|yahei|正黑|明體|楷|source han|思源|yu gothic|yu mincho|meiryo|malgun|ms mincho|ms gothic|heiti|songti|kaiti|biaukai|dfkai|simsun|simhei|mingliu|gulim|batang|lxgw|霞鶩/i;
258
276
 
@@ -268,7 +286,9 @@ export function fontsFor(stack: string, fallback: 'sans' | 'serif' | 'mono'): Fo
268
286
  .split(',')
269
287
  .map((family) => family.trim().replace(/^['"]|['"]$/g, ''))
270
288
  .filter((family) => family !== '');
271
- const real = families.filter((family) => !GENERIC.has(family.toLowerCase()));
289
+ const real = families.filter(
290
+ (family) => !GENERIC.has(family.toLowerCase()) && !SYSTEM_ONLY.test(family),
291
+ );
272
292
  const generic =
273
293
  families.find((family) => ['serif', 'monospace', 'ui-monospace'].includes(family)) ?? '';
274
294
  const kind = generic === 'serif' ? 'serif' : generic.includes('monospace') ? 'mono' : fallback;
@@ -388,6 +408,7 @@ function runPropsXml(run: TextRun, ctx: WriteContext): string {
388
408
  if (run.halfPoints)
389
409
  parts.push(`<w:sz w:val="${run.halfPoints}"/><w:szCs w:val="${run.halfPoints}"/>`);
390
410
  if (run.underline) parts.push('<w:u w:val="single"/>');
411
+ if (run.shade) parts.push(`<w:shd w:val="clear" w:color="auto" w:fill="${run.shade}"/>`);
391
412
  if (run.vert) parts.push(`<w:vertAlign w:val="${run.vert}"/>`);
392
413
  return parts.length > 0 ? `<w:rPr>${parts.join('')}</w:rPr>` : '';
393
414
  }
@@ -491,6 +512,14 @@ export function paragraphXml(paragraph: Paragraph, ctx: WriteContext): string {
491
512
  `<w:numPr><w:ilvl w:val="${paragraph.list.level}"/><w:numId w:val="${paragraph.list.numId}"/></w:numPr>`,
492
513
  );
493
514
  }
515
+ if (paragraph.ruleAbove) {
516
+ const { color, size, gap } = paragraph.ruleAbove;
517
+ // A border's space is in points, and Word allows no more than 31.
518
+ const space = Math.min(31, Math.round(gap / 20));
519
+ props.push(
520
+ `<w:pBdr><w:top w:val="single" w:sz="${size}" w:space="${space}" w:color="${color}"/></w:pBdr>`,
521
+ );
522
+ }
494
523
  if (paragraph.shade)
495
524
  props.push(`<w:shd w:val="clear" w:color="auto" w:fill="${paragraph.shade}"/>`);
496
525
  if (paragraph.rightTab !== undefined) {
@@ -732,13 +761,19 @@ export function buildDocxParts(model: DocxModel): Record<string, string | Uint8A
732
761
  const bare =
733
762
  model.finalRunning === false ||
734
763
  model.blocks.some((block) => block.type === 'paragraph' && block.sectionEnd?.running === false);
764
+ // A section with a foot of its own changes the footer, so every other
765
+ // section needs a footer to point at, if only an empty one.
766
+ const feet =
767
+ Boolean(model.finalFoot) ||
768
+ model.blocks.some((block) => block.type === 'paragraph' && block.sectionEnd?.foot);
735
769
  const running = (kind: 'header' | 'footer') => {
736
770
  // The watermark is drawn from the header, so a document with one needs a
737
771
  // header even when it has no running line to put there.
738
- if (!model[kind] && !(kind === 'header' && model.watermark)) return { full: null, bare: null };
772
+ const full = Boolean(model[kind]) || (kind === 'header' && Boolean(model.watermark));
773
+ const empty = full ? bare : kind === 'footer' && feet;
739
774
  return {
740
- full: relFor(docCtx, `${REL_BASE}/${kind}`, `${kind}1.xml`),
741
- bare: bare ? relFor(docCtx, `${REL_BASE}/${kind}`, `${kind}2.xml`) : null,
775
+ full: full ? relFor(docCtx, `${REL_BASE}/${kind}`, `${kind}1.xml`) : null,
776
+ bare: empty ? relFor(docCtx, `${REL_BASE}/${kind}`, `${kind}2.xml`) : null,
742
777
  };
743
778
  };
744
779
  const headerRels = running('header');
@@ -746,9 +781,18 @@ export function buildDocxParts(model: DocxModel): Record<string, string | Uint8A
746
781
 
747
782
  const { page } = model;
748
783
  const margin = Math.round(page.margin);
749
- docCtx.section = ({ running: on, columns, continuous }) => {
784
+ const footParts: Array<{ name: string; paragraph: Paragraph }> = [];
785
+ docCtx.section = ({ running: on, columns, continuous, foot }) => {
750
786
  const header = on ? headerRels.full : headerRels.bare;
751
- const footer = on ? footerRels.full : footerRels.bare;
787
+ let footer = on ? (footerRels.full ?? footerRels.bare) : footerRels.bare;
788
+ if (foot) {
789
+ const name = `footer${footParts.length + 3}`;
790
+ footParts.push({ name, paragraph: foot });
791
+ footer = relFor(docCtx, `${REL_BASE}/footer`, `${name}.xml`);
792
+ }
793
+ // The foot sat a page margin above the sheet's edge; a footer is placed by
794
+ // its distance from that edge.
795
+ const footerAt = foot ? margin : Math.round(margin / 2);
752
796
  const cols =
753
797
  columns && columns.count > 1
754
798
  ? `<w:cols w:num="${columns.count}" w:space="${Math.round(columns.gap)}"/>`
@@ -759,7 +803,7 @@ export function buildDocxParts(model: DocxModel): Record<string, string | Uint8A
759
803
  (footer ? `<w:footerReference w:type="default" r:id="${footer}"/>` : '') +
760
804
  (continuous ? '<w:type w:val="continuous"/>' : '') +
761
805
  `<w:pgSz w:w="${Math.round(page.width)}" w:h="${Math.round(page.height)}"${page.landscape ? ' w:orient="landscape"' : ''}/>` +
762
- `<w:pgMar w:top="${margin}" w:right="${margin}" w:bottom="${margin}" w:left="${margin}" w:header="${Math.round(margin / 2)}" w:footer="${Math.round(margin / 2)}" w:gutter="0"/>` +
806
+ `<w:pgMar w:top="${margin}" w:right="${margin}" w:bottom="${margin}" w:left="${margin}" w:header="${Math.round(margin / 2)}" w:footer="${footerAt}" w:gutter="0"/>` +
763
807
  cols +
764
808
  '</w:sectPr>'
765
809
  );
@@ -769,6 +813,7 @@ export function buildDocxParts(model: DocxModel): Record<string, string | Uint8A
769
813
  running: model.finalRunning !== false,
770
814
  ...(model.finalColumns ? { columns: model.finalColumns } : {}),
771
815
  ...(model.finalContinuous ? { continuous: true } : {}),
816
+ ...(model.finalFoot ? { foot: model.finalFoot } : {}),
772
817
  });
773
818
  const documentXml = `${XML_HEAD}<w:document ${NS}><w:body>${body}${sectPr}</w:body></w:document>`;
774
819
 
@@ -806,7 +851,6 @@ export function buildDocxParts(model: DocxModel): Record<string, string | Uint8A
806
851
  ['header', headerRels, 'hdr', 'Header'],
807
852
  ['footer', footerRels, 'ftr', 'Footer'],
808
853
  ] as const) {
809
- if (!rels.full) continue;
810
854
  const line: Paragraph = model[kind] ?? { type: 'paragraph', inlines: [] };
811
855
  const stamp = kind === 'header' ? model.watermark : undefined;
812
856
  const part = (name: string, paragraph: Paragraph) => {
@@ -821,8 +865,13 @@ export function buildDocxParts(model: DocxModel): Record<string, string | Uint8A
821
865
  if (ctx.rels.length > 0) runningParts[`word/_rels/${name}.xml.rels`] = relsXml(ctx.rels);
822
866
  runningTypes.push(`/word/${name}.xml|${kind}`);
823
867
  };
824
- part(`${kind}1`, line);
868
+ if (rels.full) part(`${kind}1`, line);
825
869
  if (rels.bare) part(`${kind}2`, { type: 'paragraph', inlines: [] });
870
+ // A sheet's own foot is set in the body's style: its runs say only how
871
+ // they differ from that, not from the running footer's.
872
+ if (kind === 'footer') {
873
+ for (const foot of footParts) part(foot.name, { ...foot.paragraph, style: 'Normal' });
874
+ }
826
875
  }
827
876
 
828
877
  const settingsXml =
@@ -6,6 +6,7 @@
6
6
 
7
7
  import { createElement } from 'react';
8
8
  import { createRoot, type Root } from 'react-dom/client';
9
+ import { PageErrorBoundary } from '../components/page-error-boundary';
9
10
  import { SheetWatermark } from '../components/page-frame';
10
11
  import { designToCssVars } from './design';
11
12
  import { PAGE_ATTR, PAGE_INDEX_ATTR } from './outline';
@@ -72,7 +73,7 @@ export async function withRenderedPages<T>(
72
73
  createElement(
73
74
  DocPageProvider,
74
75
  { index: i, total: pages.length },
75
- page.content,
76
+ createElement(PageErrorBoundary, { index: i }, page.content),
76
77
  opts.includeWatermark
77
78
  ? createElement(SheetWatermark, { text: doc.meta?.watermark })
78
79
  : null,
@@ -1,5 +1,6 @@
1
1
  import { createElement } from 'react';
2
2
  import { createRoot, type Root } from 'react-dom/client';
3
+ import { PageErrorBoundary } from '../components/page-error-boundary';
3
4
  import { SheetWatermark } from '../components/page-frame';
4
5
  import { designToCssVars } from './design';
5
6
  import { PAGE_ATTR, PAGE_INDEX_ATTR } from './outline';
@@ -129,7 +130,7 @@ export async function mountPrintCopy(
129
130
  createElement(
130
131
  DocPageProvider,
131
132
  { index: i, total },
132
- page.content,
133
+ createElement(PageErrorBoundary, { index: i }, page.content),
133
134
  createElement(SheetWatermark, { text: doc.meta?.watermark }),
134
135
  ),
135
136
  );
@@ -0,0 +1,107 @@
1
+ // The agent panel's strings, keyed by the English text in `use-locale.ts`.
2
+ export const AGENT_PANEL: Record<string, string> = {
3
+ Agent: 'エージェント',
4
+ Beta: 'Beta',
5
+ 'Early preview': 'プレビュー版',
6
+ 'Replies, edits and tool calls can occasionally fail or do something unexpected.':
7
+ '返答・編集・ツール実行が失敗したり、思わぬ動作をしたりすることがあります。',
8
+ 'Open the agent panel': 'エージェントパネルを開く',
9
+ 'Close agent panel': 'エージェントパネルを閉じる',
10
+ 'New chat': '新しいチャット',
11
+ History: '履歴',
12
+ 'No conversations yet.': 'まだ会話はありません。',
13
+ 'Delete conversation': '会話を削除',
14
+ 'Other documents': '他のドキュメント',
15
+ 'Chats you start in this panel show up here.': 'このパネルで始めた会話がここに表示されます。',
16
+ Working: '実行中',
17
+ 'Ask {provider} to create or edit documents…': '{provider} にドキュメントの作成や編集を依頼…',
18
+ Send: '送信',
19
+ Stop: '停止',
20
+ 'Page {n}': '{n} ページ目',
21
+ Selection: '選択中',
22
+ '{count} comment': '{count} 件のコメント',
23
+ '{count} comments': '{count} 件のコメント',
24
+ 'Apply comments': 'コメントを適用',
25
+ 'Apply with {provider}': '{provider} で適用',
26
+ 'Create a document with {provider}': '{provider} でドキュメントを作成',
27
+ 'Draft a new document': '新しいドキュメントを下書き',
28
+ 'Opens a blank document; describe it and the agent drafts it section by section.':
29
+ '空のドキュメントを開きます。内容を説明すると、エージェントがセクションごとに下書きします。',
30
+ 'Apply pending comments': '未処理のコメントを適用',
31
+ 'Resolves every @doc-comment marker in this document.':
32
+ 'このドキュメントのすべての @doc-comment マーカーを解決します。',
33
+ 'Create a theme': 'テーマを作成',
34
+ 'Extracts or designs a reusable theme under themes/.':
35
+ 'themes/ に再利用できるテーマを抽出・設計します。',
36
+ 'Edit this page': 'このページを編集',
37
+ 'Describe a change to the page you are viewing.': '表示中のページへの変更内容を書いてください。',
38
+ 'What should we build?': '何を作りますか?',
39
+ 'Describe a document, or pick a starting point.':
40
+ 'ドキュメントを説明するか、出発点を選んでください。',
41
+ Continue: '続ける',
42
+ Other: 'その他',
43
+ 'Type your own answer': '自由に入力',
44
+ Dismissed: 'スキップ',
45
+ 'Needs approval': '承認が必要です',
46
+ Allow: '許可',
47
+ Deny: '拒否',
48
+ Allowed: '許可済み',
49
+ Denied: '拒否済み',
50
+ 'Auto-approve': '自動承認',
51
+ 'Run commands without asking. Edits inside the workspace are always allowed.':
52
+ '確認なしでコマンドを実行します。ワークスペース内の編集は常に許可されます。',
53
+ Stopped: '停止',
54
+ '{seconds}s': '{seconds} 秒',
55
+ Error: 'エラー',
56
+ 'Checking agents': 'エージェントを確認中',
57
+ 'The agent panel is disabled in open-doc.config.ts.':
58
+ 'エージェントパネルは open-doc.config.ts で無効化されています。',
59
+ 'Connect an agent': 'エージェントを接続',
60
+ 'Drive your coding agent from here instead of a terminal. Agents installed on this machine connect automatically and reuse their sign-in.':
61
+ 'ターミナルの代わりにここからコーディングエージェントを操作できます。このマシンにインストール済みのエージェントは自動で接続され、そのログインを再利用します。',
62
+ Connect: '接続',
63
+ Connecting: '接続中',
64
+ Connected: '接続済み',
65
+ 'Adds {pkg} to this workspace with {pm}.': '{pm} で {pkg} をこのワークスペースに追加します。',
66
+ 'CLI found · v{version}': 'CLI を検出 · v{version}',
67
+ 'CLI found': 'CLI を検出',
68
+ 'CLI not found on PATH': 'PATH に CLI が見つかりません',
69
+ 'Install the {name} CLI and sign in once; the panel reuses its login.':
70
+ '{name} CLI をインストールして一度ログインしてください。パネルはそのログインを再利用します。',
71
+ 'Install Codex first': '先に Codex をインストールしてください',
72
+ 'The panel drives the Codex CLI on this machine, and it was not found on your PATH. Install it, sign in once in a terminal with `codex`, then check again.':
73
+ 'エージェントパネルはこのコンピューターの Codex CLI を使いますが、PATH に見つかりませんでした。インストールしてターミナルで `codex` に一度サインインしてから、もう一度確認してください。',
74
+ 'Check again': 'もう一度確認',
75
+ Retry: '再試行',
76
+ '{name} connected': '{name} を接続しました',
77
+ 'Could not install {pkg}': '{pkg} をインストールできませんでした',
78
+ 'Manage agents': 'エージェントを管理',
79
+ Back: '戻る',
80
+ 'Could not send message': 'メッセージを送信できませんでした',
81
+ "What's this document about?": 'どんなドキュメントにしますか?',
82
+ 'Describe the topic, audience and tone. {provider} drafts it section by section while you watch.':
83
+ 'テーマ・読者・トーンを説明してください。{provider} がセクションごとに下書きする様子を見られます。',
84
+ 'A two-page project brief on…': '…についての2ページの企画書',
85
+ 'Could not create a document': 'ドキュメントを作成できませんでした',
86
+ '{count} step': '{count} ステップ',
87
+ '{count} steps': '{count} ステップ',
88
+ Skip: 'スキップ',
89
+ Copy: 'コピー',
90
+ Cancel: 'キャンセル',
91
+ 'Sending replaces the conversation after this message. Edits already made to files stay.':
92
+ '送信すると、このメッセージ以降の会話が置き換わります。ファイルへの変更は元に戻りません。',
93
+ Default: 'デフォルト',
94
+ Reasoning: '推論',
95
+ Auto: '自動',
96
+ Minimal: '最小',
97
+ Low: '低',
98
+ Medium: '中',
99
+ High: '高',
100
+ 'Extra high': '最高',
101
+ Max: '最大',
102
+ '{provider} is editing': '{provider} が編集中',
103
+ Thinking: '考え中',
104
+ 'Waiting for you': 'あなたの回答待ち',
105
+ 'Draft with agent': 'エージェントで下書き',
106
+ 'Resize the agent panel': 'エージェントパネルの幅を変更',
107
+ };
@@ -0,0 +1,9 @@
1
+ export const AGENT: Record<string, string> = {
2
+ Agent: 'エージェント',
3
+ 'Close the agent panel': 'エージェントパネルを閉じる',
4
+ 'Ask the agent': 'エージェントに依頼',
5
+ Ran: '実行',
6
+ 'This page could not be drawn': 'このページを表示できません',
7
+ 'It is drawn again as soon as the source is saved.': 'ソースを保存すると再描画されます。',
8
+ 'Apply with {agent}': '{agent} で反映',
9
+ };
@@ -1,5 +1,13 @@
1
+ import { AGENT } from './agent';
2
+ import { AGENT_PANEL } from './agent-panel';
1
3
  import { BROWSER } from './browser';
2
4
  import { DOC } from './doc';
3
5
  import { PANELS } from './panels';
4
6
 
5
- export const JA: Record<string, string> = { ...BROWSER, ...DOC, ...PANELS };
7
+ export const JA: Record<string, string> = {
8
+ ...BROWSER,
9
+ ...DOC,
10
+ ...PANELS,
11
+ ...AGENT,
12
+ ...AGENT_PANEL,
13
+ };