@open-document/core 0.10.0 → 0.12.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 (86) hide show
  1. package/dist/{build-DJMLK50m.js → build-DfUfpeTR.js} +1 -1
  2. package/dist/{check-CUKuufBm.js → check-CHxiOkQG.js} +3 -3
  3. package/dist/cli/bin.js +20 -33
  4. package/dist/{config-CvzpyAUA.js → config-9IdbhVuT.js} +2015 -725
  5. package/dist/{context-B4ip7SoI.js → context-BLI1-64_.js} +2 -2
  6. package/dist/{dev-dnH7DTlD.js → dev-yNYKv5mm.js} +1 -1
  7. package/dist/{diff-QTo0A5Rx.js → diff-Bs205mOx.js} +2 -2
  8. package/dist/{export-BrRFrexj.js → export-tkquS5O5.js} +11 -4
  9. package/dist/{import-C14Vn9ER.js → import-D1hIKIr3.js} +3 -2
  10. package/dist/index.d.ts +2 -2
  11. package/dist/index.js +63 -28
  12. package/dist/ops/index.d.ts +111 -2
  13. package/dist/ops/index.js +3 -3
  14. package/dist/{ops-DKidjLXP.js → ops-Dgqujq5a.js} +85 -164
  15. package/dist/package-version-C89gtYSk.js +36 -0
  16. package/dist/{preview-wKM4C6Uk.js → preview-BImdTH6K.js} +1 -1
  17. package/dist/{sdk-CpDEGRIo.d.ts → sdk-CHEGeINh.d.ts} +46 -1
  18. package/dist/templates-DT5zzqHq.js +34 -0
  19. package/dist/vite/index.js +1 -1
  20. package/package.json +2 -1
  21. package/skills/apply-comments/SKILL.md +3 -1
  22. package/skills/create-doc/SKILL.md +2 -0
  23. package/skills/doc-authoring/SKILL.md +2 -0
  24. package/src/app/components/browser/browser-ui.tsx +21 -0
  25. package/src/app/components/browser/new-document-dialog.tsx +208 -0
  26. package/src/app/components/changes/changes-overlay.tsx +68 -0
  27. package/src/app/components/changes/changes-panel.tsx +341 -0
  28. package/src/app/components/changes/use-changes.ts +85 -0
  29. package/src/app/components/comments/comments-overlay.tsx +50 -0
  30. package/src/app/components/comments/comments-panel.tsx +272 -0
  31. package/src/app/components/comments/use-comments.ts +61 -0
  32. package/src/app/components/doc-sidebar.tsx +32 -2
  33. package/src/app/components/inspector/field-source.tsx +41 -0
  34. package/src/app/components/inspector/format-section.tsx +434 -0
  35. package/src/app/components/inspector/inspector.tsx +311 -118
  36. package/src/app/components/inspector/use-style-edits.ts +210 -0
  37. package/src/app/components/overlay-frame.tsx +79 -0
  38. package/src/app/components/page-frame.tsx +4 -0
  39. package/src/app/components/page-placement.ts +68 -0
  40. package/src/app/components/panel/fields.tsx +95 -7
  41. package/src/app/components/record-picker.tsx +79 -0
  42. package/src/app/components/themes/theme-preview.tsx +5 -4
  43. package/src/app/lib/agent-bridge.ts +29 -1
  44. package/src/app/lib/docx/ooxml.test.ts +24 -1
  45. package/src/app/lib/docx/ooxml.ts +27 -1
  46. package/src/app/lib/export-docx.ts +3 -1
  47. package/src/app/lib/export-dom.ts +2 -1
  48. package/src/app/lib/export-html.ts +4 -2
  49. package/src/app/lib/export-image.ts +2 -1
  50. package/src/app/lib/flow-measure.test.ts +30 -0
  51. package/src/app/lib/flow-measure.ts +35 -10
  52. package/src/app/lib/i18n-ja/browser.ts +10 -0
  53. package/src/app/lib/i18n-ja/doc.ts +4 -0
  54. package/src/app/lib/i18n-ja/panels.ts +92 -5
  55. package/src/app/lib/i18n-ko/browser.ts +10 -0
  56. package/src/app/lib/i18n-ko/doc.ts +4 -0
  57. package/src/app/lib/i18n-ko/panels.ts +90 -5
  58. package/src/app/lib/i18n-zh-cn/browser.ts +10 -0
  59. package/src/app/lib/i18n-zh-cn/doc.ts +4 -0
  60. package/src/app/lib/i18n-zh-cn/panels.ts +88 -5
  61. package/src/app/lib/i18n-zh-tw/browser.ts +10 -0
  62. package/src/app/lib/i18n-zh-tw/doc.ts +4 -0
  63. package/src/app/lib/i18n-zh-tw/panels.ts +88 -5
  64. package/src/app/lib/inspector/format.ts +156 -0
  65. package/src/app/lib/records.test.ts +38 -0
  66. package/src/app/lib/records.ts +127 -0
  67. package/src/app/lib/sdk.ts +29 -0
  68. package/src/app/lib/use-doc-module.ts +7 -0
  69. package/src/app/lib/use-doc-pages.ts +15 -9
  70. package/src/app/routes/doc.tsx +274 -11
  71. package/src/app/routes/home.tsx +30 -5
  72. package/src/app/styles.css +23 -0
  73. package/templates/blank/index.tsx +63 -0
  74. package/templates/blank/template.json +6 -0
  75. package/templates/certificate/data/recipients.csv +4 -0
  76. package/templates/certificate/index.tsx +128 -0
  77. package/templates/certificate/template.json +6 -0
  78. package/templates/letter/index.tsx +106 -0
  79. package/templates/letter/template.json +5 -0
  80. package/templates/meeting-notes/index.tsx +194 -0
  81. package/templates/meeting-notes/template.json +6 -0
  82. package/templates/proposal/index.tsx +264 -0
  83. package/templates/proposal/template.json +6 -0
  84. package/templates/report/data/metrics.csv +5 -0
  85. package/templates/report/index.tsx +224 -0
  86. package/templates/report/template.json +6 -0
@@ -4,6 +4,7 @@ import { buildDocDocx } from './export-docx';
4
4
  import { buildDocHtmlBundle } from './export-html';
5
5
  import { mountPrintCopy, type PrintCopy } from './export-pdf';
6
6
  import { exposeOutline } from './outline';
7
+ import { recordFileName, setRecordIndex } from './records';
7
8
  import type { DocModule, PageGeometry } from './sdk';
8
9
  import type { ExpandedPage } from './use-doc-pages';
9
10
 
@@ -16,6 +17,10 @@ export type BridgeStatus = {
16
17
  ready: boolean;
17
18
  pageCount: number;
18
19
  geometry: PageGeometry;
20
+ /** Rows the document prints one copy for (`records`); 0 when it has none. */
21
+ records: number;
22
+ /** The row the pages are laid out for right now, 0-based. */
23
+ record: number;
19
24
  };
20
25
 
21
26
  export type BridgeReport = BridgeStatus & { findings: LayoutFinding[] };
@@ -32,6 +37,12 @@ export type OpenDocBridge = {
32
37
  releasePrint(): void;
33
38
  htmlBundle(): Promise<BridgeBundle | null>;
34
39
  docxBundle(): Promise<BridgeBundle | null>;
40
+ /**
41
+ * Lays the document out for one row and names its file — from `pattern`,
42
+ * else `meta.recordName`, else `<id>-{#}`. Wait for `status()` to report
43
+ * that row and `ready` before printing.
44
+ */
45
+ setRecord(index: number, pattern?: string): { name: string };
35
46
  };
36
47
 
37
48
  type BridgeInput = {
@@ -41,6 +52,8 @@ type BridgeInput = {
41
52
  geometry: PageGeometry;
42
53
  measuring: boolean;
43
54
  oversized: Array<{ section: number; block: number }>;
55
+ /** The row this render is laid out for — read from the render, never the store, so `ready` and the row agree. */
56
+ record: number;
44
57
  };
45
58
 
46
59
  type GlobalWithBridge = typeof globalThis & { [BRIDGE_KEY]?: OpenDocBridge };
@@ -70,13 +83,15 @@ export function useAgentBridge(input: BridgeInput): void {
70
83
  let held: PrintCopy | null = null;
71
84
 
72
85
  const status = (): BridgeStatus => {
73
- const { docId, doc, pages, geometry, measuring } = latest.current;
86
+ const { docId, doc, pages, geometry, measuring, record } = latest.current;
74
87
  return {
75
88
  docId,
76
89
  title: doc?.meta?.title ?? docId,
77
90
  ready: doc !== null && !measuring && pages.length > 0,
78
91
  pageCount: pages.length,
79
92
  geometry,
93
+ records: doc?.records?.length ?? 0,
94
+ record,
80
95
  };
81
96
  };
82
97
 
@@ -126,6 +141,19 @@ export function useAgentBridge(input: BridgeInput): void {
126
141
  base64: toBase64(bundle.bytes),
127
142
  };
128
143
  },
144
+ setRecord(index, pattern) {
145
+ const { docId, doc } = latest.current;
146
+ const records = doc?.records ?? [];
147
+ setRecordIndex(index);
148
+ return {
149
+ name: recordFileName(
150
+ pattern ?? doc?.meta?.recordName ?? `${docId}-{#}`,
151
+ records[index],
152
+ index,
153
+ records.length,
154
+ ),
155
+ };
156
+ },
129
157
  async docxBundle() {
130
158
  const { docId, doc, pages } = latest.current;
131
159
  if (!doc || pages.length === 0) return null;
@@ -1,5 +1,12 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { buildDocxParts, type DocxModel, escapeXml, fontsFor, hexColor } from './ooxml.ts';
2
+ import {
3
+ buildDocxParts,
4
+ type DocxModel,
5
+ escapeXml,
6
+ fontsFor,
7
+ hexColor,
8
+ wordLang,
9
+ } from './ooxml.ts';
3
10
 
4
11
  describe('fontsFor', () => {
5
12
  it('skips system aliases for the first real family', () => {
@@ -313,3 +320,19 @@ describe('buildDocxParts', () => {
313
320
  expect(numbering).toContain('<w:num w:numId="2"><w:abstractNumId w:val="1"/><w:lvlOverride');
314
321
  });
315
322
  });
323
+
324
+ describe('wordLang', () => {
325
+ it('files Chinese, Japanese and Korean as the East Asian language', () => {
326
+ expect(wordLang('zh-Hant-TW')).toBe('<w:lang w:val="en-US" w:eastAsia="zh-TW"/>');
327
+ expect(wordLang('zh-Hans')).toBe('<w:lang w:val="en-US" w:eastAsia="zh-CN"/>');
328
+ expect(wordLang('zh-HK')).toBe('<w:lang w:val="en-US" w:eastAsia="zh-HK"/>');
329
+ expect(wordLang('ja')).toBe('<w:lang w:val="en-US" w:eastAsia="ja-JP"/>');
330
+ expect(wordLang('ko-KR')).toBe('<w:lang w:val="en-US" w:eastAsia="ko-KR"/>');
331
+ });
332
+
333
+ it('files anything else as the Latin language', () => {
334
+ expect(wordLang()).toBe('<w:lang w:val="en-US"/>');
335
+ expect(wordLang('en-GB')).toBe('<w:lang w:val="en-GB"/>');
336
+ expect(wordLang('de"x')).toBe('<w:lang w:val="dex"/>');
337
+ });
338
+ });
@@ -169,8 +169,34 @@ export type DocxModel = {
169
169
  images: ImagePart[];
170
170
  /** One entry per list; ordered lists restart at 1 each. */
171
171
  lists: Array<'bullet' | 'decimal'>;
172
+ /** The document's language as a BCP 47 tag — see `pageLang`. */
173
+ lang?: string;
172
174
  };
173
175
 
176
+ /**
177
+ * The document's language the way Word files it. Word keeps Latin and East
178
+ * Asian text apart: a Chinese document still has Latin runs, and its
179
+ * proofing, line-breaking (kinsoku) and fallback fonts follow the East Asian
180
+ * language, so that one goes in `eastAsia`.
181
+ */
182
+ export function wordLang(lang = 'en'): string {
183
+ const tag = lang.toLowerCase();
184
+ const eastAsia = tag.startsWith('zh')
185
+ ? /hant|-tw|-hk|-mo/.test(tag)
186
+ ? tag.includes('-hk')
187
+ ? 'zh-HK'
188
+ : 'zh-TW'
189
+ : 'zh-CN'
190
+ : tag.startsWith('ja')
191
+ ? 'ja-JP'
192
+ : tag.startsWith('ko')
193
+ ? 'ko-KR'
194
+ : null;
195
+ if (eastAsia) return `<w:lang w:val="en-US" w:eastAsia="${eastAsia}"/>`;
196
+ const latin = tag === 'en' ? 'en-US' : lang.replace(/[^A-Za-z0-9-]/g, '');
197
+ return `<w:lang w:val="${latin}"/>`;
198
+ }
199
+
174
200
  export const PX_TO_TWIPS = 15;
175
201
  export const PX_TO_EMU = 9525;
176
202
  export const PX_TO_HALF_POINTS = 1.5;
@@ -546,7 +572,7 @@ function stylesXml(model: DocxModel): string {
546
572
  `<w:style w:type="paragraph" w:styleId="TOC${level}"><w:name w:val="toc ${level}"/><w:basedOn w:val="Normal"/><w:next w:val="Normal"/><w:uiPriority w:val="39"/><w:pPr><w:tabs><w:tab w:val="right" w:leader="dot" w:pos="${textWidth}"/></w:tabs><w:spacing w:after="60"/><w:ind w:left="${(level - 1) * 240}"/></w:pPr></w:style>`;
547
573
  return (
548
574
  `${XML_HEAD}<w:styles ${NS}>` +
549
- `<w:docDefaults><w:rPrDefault><w:rPr>${fontsXml(fonts.body)}<w:color w:val="${colors.text}"/><w:sz w:val="${sizes.body}"/><w:szCs w:val="${sizes.body}"/></w:rPr></w:rPrDefault>` +
575
+ `<w:docDefaults><w:rPrDefault><w:rPr>${fontsXml(fonts.body)}<w:color w:val="${colors.text}"/><w:sz w:val="${sizes.body}"/><w:szCs w:val="${sizes.body}"/>${wordLang(model.lang)}</w:rPr></w:rPrDefault>` +
550
576
  `<w:pPrDefault><w:pPr><w:spacing w:after="160" w:line="${Math.round(model.line)}" w:lineRule="atLeast"/></w:pPr></w:pPrDefault></w:docDefaults>` +
551
577
  '<w:style w:type="paragraph" w:default="1" w:styleId="Normal"><w:name w:val="Normal"/><w:qFormat/></w:style>' +
552
578
  '<w:style w:type="character" w:default="1" w:styleId="DefaultParagraphFont"><w:name w:val="Default Paragraph Font"/><w:uiPriority w:val="1"/><w:semiHidden/></w:style>' +
@@ -27,7 +27,7 @@ import { downloadBlob, withRenderedPages } from './export-dom';
27
27
  import { type DocEntry, type FlowSection, isFlowSection } from './flow';
28
28
  import { DocPageProvider } from './page-context';
29
29
  import { nextFrame, waitForFonts } from './print-ready';
30
- import { type DocModule, resolvePageGeometry } from './sdk';
30
+ import { type DocModule, pageLang, resolvePageGeometry } from './sdk';
31
31
  import type { ExpandedPage } from './use-doc-pages';
32
32
 
33
33
  export type DocxBundle = { filename: string; mimeType: string; bytes: Uint8Array };
@@ -108,6 +108,7 @@ async function runningLineOf(
108
108
  host.setAttribute('aria-hidden', 'true');
109
109
  // The sheet's base styles (styles.css), so the line reads as it prints.
110
110
  host.setAttribute('data-od-measure', '');
111
+ host.setAttribute('lang', pageLang(doc.meta));
111
112
  Object.assign(host.style, { position: 'fixed', left: '-99999px', top: '0', width: `${width}px` });
112
113
  for (const [name, value] of Object.entries(designToCssVars(design))) {
113
114
  host.style.setProperty(name, value);
@@ -178,6 +179,7 @@ export async function buildDocDocx(
178
179
  const size = (px: number) => Math.round(px * PX_TO_HALF_POINTS);
179
180
  const text = hexColor(design.palette.text) ?? '000000';
180
181
  const model: DocxModel = {
182
+ lang: pageLang(doc.meta),
181
183
  title: doc.meta?.title ?? docId,
182
184
  ...(doc.meta?.author ? { author: doc.meta.author } : {}),
183
185
  page: {
@@ -11,7 +11,7 @@ import { PAGE_ATTR, PAGE_INDEX_ATTR } from './outline';
11
11
  import { DocPageProvider } from './page-context';
12
12
  import { nextFrame, waitForFonts, waitForImages } from './print-ready';
13
13
  import { captureScan, restoreScan, scanDocument } from './scan';
14
- import type { DocModule, PageGeometry } from './sdk';
14
+ import { type DocModule, type PageGeometry, pageLang } from './sdk';
15
15
  import { scopeSvgIds } from './svg-ids';
16
16
  import type { ExpandedPage } from './use-doc-pages';
17
17
 
@@ -52,6 +52,7 @@ export async function withRenderedPages<T>(
52
52
  const host = document.createElement('div');
53
53
  host.setAttribute(PAGE_ATTR, '');
54
54
  host.setAttribute(PAGE_INDEX_ATTR, String(i));
55
+ host.setAttribute('lang', pageLang(doc.meta));
55
56
  host.style.width = `${geometry.width}px`;
56
57
  host.style.height = `${geometry.height}px`;
57
58
  if (designVars) {
@@ -12,7 +12,7 @@ import {
12
12
  uniqueAssetName,
13
13
  } from './export-dom';
14
14
  import { PAGE_ATTR, PAGE_INDEX_ATTR } from './outline';
15
- import { type DocModule, type PageGeometry, resolvePageGeometry } from './sdk';
15
+ import { type DocModule, type PageGeometry, pageLang, resolvePageGeometry } from './sdk';
16
16
  import type { ExpandedPage } from './use-doc-pages';
17
17
 
18
18
  type AssetEntry = { name: string; bytes: Uint8Array };
@@ -61,6 +61,7 @@ export async function buildDocHtmlBundle(
61
61
 
62
62
  const html = buildHtml({
63
63
  title,
64
+ lang: pageLang(doc.meta),
64
65
  geometry,
65
66
  design: doc.design,
66
67
  pagesHtml: pagesHtml.map((page) => rewriteUrls(page, assets, 'html')),
@@ -112,6 +113,7 @@ function rewriteUrls(
112
113
 
113
114
  function buildHtml(opts: {
114
115
  title: string;
116
+ lang: string;
115
117
  geometry: PageGeometry;
116
118
  design: DocModule['design'];
117
119
  pagesHtml: string[];
@@ -133,7 +135,7 @@ function buildHtml(opts: {
133
135
  .join('\n');
134
136
 
135
137
  return `<!doctype html>
136
- <html lang="en">
138
+ <html lang="${escapeAttr(opts.lang)}">
137
139
  <head>
138
140
  <meta charset="utf-8">
139
141
  <meta name="viewport" content="width=device-width, initial-scale=1">
@@ -20,7 +20,7 @@ import {
20
20
  toAbsolute,
21
21
  } from './export-dom';
22
22
  import { PAGE_ATTR } from './outline';
23
- import { type DocModule, type PageGeometry, resolvePageGeometry } from './sdk';
23
+ import { type DocModule, type PageGeometry, pageLang, resolvePageGeometry } from './sdk';
24
24
  import type { ExpandedPage } from './use-doc-pages';
25
25
 
26
26
  export type ImageFormat = 'png' | 'svg';
@@ -186,6 +186,7 @@ function buildSvg(pageHtml: string, css: string, geometry: Box, doc: DocModule):
186
186
  const content = document.createElementNS(XHTML_NS, 'div');
187
187
  content.setAttribute('style', 'width:100%;height:100%');
188
188
  content.setAttribute(PAGE_ATTR, '');
189
+ content.setAttribute('lang', pageLang(doc.meta));
189
190
  content.innerHTML = pageHtml;
190
191
  wrapper.appendChild(content);
191
192
 
@@ -0,0 +1,30 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { metricsFor } from './flow-measure';
3
+
4
+ /** Just what `metricsFor` reads of a block's wrapper. */
5
+ function block(inner: { tagName: string; attrs?: Record<string, string> } | null): HTMLElement {
6
+ return {
7
+ firstElementChild: inner && {
8
+ tagName: inner.tagName,
9
+ getAttribute: (name: string) => inner.attrs?.[name] ?? null,
10
+ },
11
+ } as unknown as HTMLElement;
12
+ }
13
+
14
+ describe('metricsFor', () => {
15
+ it('treats a block that renders nothing as plain, not as a page break', () => {
16
+ expect(metricsFor(block(null), 0, 0)).toMatchObject({
17
+ breakBefore: false,
18
+ keepWithNext: false,
19
+ keepWithPrevious: false,
20
+ });
21
+ });
22
+
23
+ it('glues a heading to what follows, and reads declared breaks', () => {
24
+ expect(metricsFor(block({ tagName: 'H2' }), 20, 0).keepWithNext).toBe(true);
25
+ expect(
26
+ metricsFor(block({ tagName: 'DIV', attrs: { 'data-od-break-before': '' } }), 20, 0)
27
+ .breakBefore,
28
+ ).toBe(true);
29
+ });
30
+ });
@@ -1,4 +1,5 @@
1
1
  import { createElement, type ReactNode } from 'react';
2
+ import { flushSync } from 'react-dom';
2
3
  import { createRoot } from 'react-dom/client';
3
4
  import { FLOW_BLOCK_ATTR, FlowBlock } from '../components/flow-page';
4
5
  import { FOOTNOTE_AREA_MARGIN_TOP, FOOTNOTE_ROW_ATTR, Footnotes } from '../components/footnote';
@@ -18,12 +19,15 @@ export type MeasurableSection = {
18
19
  padding?: number;
19
20
  };
20
21
 
21
- function metricsFor(el: HTMLElement, height: number, footnoteHeight: number): BlockMetrics {
22
+ export function metricsFor(el: HTMLElement, height: number, footnoteHeight: number): BlockMetrics {
22
23
  const inner = el.firstElementChild;
23
24
  const tag = inner?.tagName ?? '';
24
- const declaredKeepNext = inner?.getAttribute('data-od-keep-with-next');
25
- const declaredKeepPrev = inner?.getAttribute('data-od-keep-with-previous');
26
- const declaredBreak = inner?.getAttribute('data-od-break-before');
25
+ // `?? null`: a block that renders nothing has no child, and `undefined`
26
+ // would pass every `!== null` below — an empty block then broke the page
27
+ // before it and glued itself to the next.
28
+ const declaredKeepNext = inner?.getAttribute('data-od-keep-with-next') ?? null;
29
+ const declaredKeepPrev = inner?.getAttribute('data-od-keep-with-previous') ?? null;
30
+ const declaredBreak = inner?.getAttribute('data-od-break-before') ?? null;
27
31
 
28
32
  return {
29
33
  height,
@@ -73,7 +77,7 @@ function stackedHeights(container: HTMLElement, selector: string): number[] {
73
77
  */
74
78
  export async function measureFlowSections(
75
79
  sections: MeasurableSection[],
76
- opts: { geometry: PageGeometry; design?: DesignSystem },
80
+ opts: { geometry: PageGeometry; design?: DesignSystem; lang?: string },
77
81
  ): Promise<FlowMeasurement[]> {
78
82
  if (sections.length === 0) return [];
79
83
 
@@ -82,6 +86,9 @@ export async function measureFlowSections(
82
86
  // The sheet's own element styles (styles.css) apply here too, so a block
83
87
  // measures as it will print.
84
88
  host.setAttribute('data-od-measure', '');
89
+ // Where a line breaks depends on the language, so it is measured in the one
90
+ // it prints in.
91
+ host.setAttribute('lang', opts.lang ?? 'en');
85
92
  Object.assign(host.style, {
86
93
  position: 'fixed',
87
94
  left: '-99999px',
@@ -112,16 +119,23 @@ export async function measureFlowSections(
112
119
  };
113
120
 
114
121
  try {
122
+ // Out of the effect that called us, so `flushSync` below may commit.
123
+ await Promise.resolve();
115
124
  for (const section of sections) {
116
125
  const width = opts.geometry.width - paddingOf(section) * 2;
117
126
 
118
127
  const blocks = makeContainer(width);
119
128
  blockContainers.push(blocks);
120
129
  const blockRoot = createRoot(blocks);
121
- blockRoot.render(
122
- section.blocks.map((block, index) =>
123
- createElement(FlowBlock, { key: index }, block),
124
- ) as unknown as Parameters<typeof blockRoot.render>[0],
130
+ // Committed now, not on React's schedule: on a slow machine a render
131
+ // left to finish on its own was still empty when the frames below had
132
+ // passed, the section measured as no blocks, and it printed as no pages.
133
+ flushSync(() =>
134
+ blockRoot.render(
135
+ section.blocks.map((block, index) =>
136
+ createElement(FlowBlock, { key: index }, block),
137
+ ) as unknown as Parameters<typeof blockRoot.render>[0],
138
+ ),
125
139
  );
126
140
  roots.push(blockRoot);
127
141
 
@@ -133,13 +147,24 @@ export async function measureFlowSections(
133
147
  const notes = makeContainer(width);
134
148
  noteContainers.push(notes);
135
149
  const noteRoot = createRoot(notes);
136
- noteRoot.render(createElement(Footnotes, { notes: allNotes }));
150
+ flushSync(() => noteRoot.render(createElement(Footnotes, { notes: allNotes })));
137
151
  roots.push(noteRoot);
138
152
  }
139
153
 
140
154
  await nextFrame();
141
155
  await waitForFonts();
142
156
  await nextFrame();
157
+ // Every block has its wrapper before anything is read: a short count would
158
+ // be packed as a short section.
159
+ for (let frame = 0; frame < 60; frame++) {
160
+ const complete = sections.every(
161
+ (section, index) =>
162
+ (blockContainers[index]?.querySelectorAll(`:scope > [${FLOW_BLOCK_ATTR}]`).length ?? 0) >=
163
+ section.blocks.length,
164
+ );
165
+ if (complete) break;
166
+ await nextFrame();
167
+ }
143
168
 
144
169
  return sections.map((section, sectionIndex) => {
145
170
  const padding = paddingOf(section);
@@ -85,4 +85,14 @@ export const BROWSER: Record<string, string> = {
85
85
  'Light theme': 'ライトテーマ',
86
86
  'Dark theme': 'ダークテーマ',
87
87
  'System theme': 'システムテーマ',
88
+ 'New document': '新しいドキュメント',
89
+ Template: 'テンプレート',
90
+ 'This workspace': 'このワークスペース',
91
+ Create: '作成',
92
+ 'Could not create the document': 'ドキュメントを作成できませんでした',
93
+ Blank: '白紙',
94
+ Report: 'レポート',
95
+ Proposal: '提案書',
96
+ 'Meeting notes': '議事録',
97
+ Letter: 'レター',
88
98
  };
@@ -62,4 +62,8 @@ export const DOC: Record<string, string> = {
62
62
  'Actual size (100%)': '実際のサイズ (100%)',
63
63
  'Link copied': 'リンクをコピーしました',
64
64
  'Copy link': 'リンクをコピー',
65
+ Record: 'レコード',
66
+ 'Previous record': '前のレコード',
67
+ 'Next record': '次のレコード',
68
+ Certificate: '修了証',
65
69
  };
@@ -92,13 +92,100 @@ export const PANELS: Record<string, string> = {
92
92
  'クリックで選択 · ダブルクリックで編集 · Esc で終了',
93
93
  Element: '要素',
94
94
  Close: '閉じる',
95
- 'Editing on the page. Enter keeps the change, Shift+Enter starts a new line, Esc reverts it.':
96
- 'ページ上で編集中です。Enter で変更を確定、Shift+Enter で改行、Esc で元に戻します。',
97
- 'Double-click the text on the page, or press Enter, to edit it where it is printed.':
98
- 'ページ上のテキストをダブルクリックするか Enter を押すと、印刷される位置でそのまま編集できます。',
99
- 'Inline markup stays as written.': 'インラインのマークアップはそのまま残ります。',
100
95
  'Not editable here.': 'ここでは編集できません。',
101
96
  'Comment for the agent': 'エージェントへのコメント',
102
97
  'make this bold, shorten to one line…': '太字にする、1 行に短くする…',
103
98
  'Mark comment': 'コメントを記録',
99
+ Typography: 'タイポグラフィ',
100
+ Color: '色',
101
+ Font: 'フォント',
102
+ Size: 'サイズ',
103
+ 'Size in pixels': 'サイズ(ピクセル)',
104
+ Weight: 'ウェイト',
105
+ 'Line height': '行の高さ',
106
+ 'Letter spacing in pixels': '字間(ピクセル)',
107
+ Fill: '塗り',
108
+ Background: '背景',
109
+ None: 'なし',
110
+ Inherited: '継承',
111
+ 'From {name}': '{name} から',
112
+ 'from {name}': '{name} から',
113
+ 'set in code: {code}': 'コードで設定:{code}',
114
+ Custom: 'カスタム',
115
+ 'Align left': '左揃え',
116
+ 'Align center': '中央揃え',
117
+ 'Align right': '右揃え',
118
+ Justify: '両端揃え',
119
+ 'This is a component — its styles are set inside it, not here.':
120
+ 'これはコンポーネントです。スタイルはここではなく、コンポーネントの内部で設定されます。',
121
+ 'This element’s style is not written as an object.':
122
+ 'この要素の style はオブジェクトで書かれていません。',
123
+ 'source does not match this element': 'ソースがこの要素と一致しません',
124
+ 'element not found': '要素が見つかりません',
125
+ 'Light 300': 'Light 300',
126
+ 'Regular 400': 'Regular 400',
127
+ 'Medium 500': 'Medium 500',
128
+ 'Semibold 600': 'Semibold 600',
129
+ 'Bold 700': 'Bold 700',
130
+ 'Extrabold 800': 'Extrabold 800',
131
+ 'Heading {level}': '見出し {level}',
132
+ Paragraph: '段落',
133
+ List: 'リスト',
134
+ Table: '表',
135
+ Image: '画像',
136
+ Box: 'ボックス',
137
+ Alignment: '配置',
138
+ Emphasis: '強調',
139
+ 'Edit on page': 'ページ上で編集',
140
+ Source: 'ソース',
141
+ Location: '位置',
142
+ 'Letter spacing': '字間',
143
+ 'Text color': '文字色',
144
+ '{label} token': '{label} のトークン',
145
+ 'Inherited font': '継承されたフォント',
146
+ '{name} font': '{name}フォント',
147
+ 'Custom font': 'カスタムフォント',
148
+ Done: '完了',
149
+ '{count} elements print from this line of source':
150
+ 'このソース行から {count} 個の要素が出力されます',
151
+ Changes: '変更',
152
+ 'Changes ({count})': '変更({count})',
153
+ 'Changes since the last commit': '前回のコミット以降の変更',
154
+ 'Close the changes panel': '変更パネルを閉じる',
155
+ 'Show changes since the last commit': '前回のコミット以降の変更を表示',
156
+ 'Previous change': '前の変更',
157
+ 'Next change': '次の変更',
158
+ Since: '比較',
159
+ 'Compare with': '比較対象',
160
+ 'Last commit': '前回のコミット',
161
+ 'git is not installed': 'git がインストールされていません',
162
+ 'Not a git repository': 'git リポジトリではありません',
163
+ 'No changes': '変更はありません',
164
+ 'Page {page}, changed': '{page} ページ(変更あり)',
165
+ Files: 'ファイル',
166
+ 'Revert this change': 'この変更を元に戻す',
167
+ 'that change is no longer there — reload the changes':
168
+ 'この変更はもうありません。変更を再読み込みしてください',
169
+ 'the file changed since the diff was read': '差分を読んだ後にファイルが変更されました',
170
+ 'reverting this change alone would break the source — revert the changes around it too':
171
+ 'この変更だけを戻すとソースが壊れます。周辺の変更も一緒に戻してください',
172
+ 'a binary file cannot be reverted here': 'バイナリファイルはここでは元に戻せません',
173
+ 'this workspace is not under git': 'このワークスペースは git で管理されていません',
174
+ Comments: 'コメント',
175
+ 'Comments ({count})': 'コメント({count})',
176
+ 'Close the comments panel': 'コメントパネルを閉じる',
177
+ 'Show comments': 'コメントを表示',
178
+ 'New comment': '新しいコメント',
179
+ Resolve: '解決済みにする',
180
+ 'Copy request for the agent': 'エージェントへの依頼をコピー',
181
+ 'No comments': 'コメントはありません',
182
+ 'p.{page}': '{page} ページ',
183
+ 'Page {page}, with comments': '{page} ページ(コメントあり)',
184
+ 'Could not resolve the comment': '解決済みにできませんでした',
185
+ 'Pick an element on the page': 'ページ上の要素を選択',
186
+ 'Click the element to comment on · Esc to cancel':
187
+ 'コメントする要素をクリック · Esc でキャンセル',
188
+ Records: 'レコード',
189
+ 'Row {row} of {count}': '{count} 行中 {row} 行目',
190
+ 'Esc to deselect': 'Esc で選択解除',
104
191
  };
@@ -84,4 +84,14 @@ export const BROWSER: Record<string, string> = {
84
84
  'Light theme': '라이트 테마',
85
85
  'Dark theme': '다크 테마',
86
86
  'System theme': '시스템 테마',
87
+ 'New document': '새 문서',
88
+ Template: '템플릿',
89
+ 'This workspace': '이 작업 공간',
90
+ Create: '만들기',
91
+ 'Could not create the document': '문서를 만들 수 없습니다',
92
+ Blank: '빈 문서',
93
+ Report: '보고서',
94
+ Proposal: '제안서',
95
+ 'Meeting notes': '회의록',
96
+ Letter: '서신',
87
97
  };
@@ -62,4 +62,8 @@ export const DOC: Record<string, string> = {
62
62
  'Actual size (100%)': '실제 크기 (100%)',
63
63
  'Link copied': '링크 복사됨',
64
64
  'Copy link': '링크 복사',
65
+ Record: '레코드',
66
+ 'Previous record': '이전 레코드',
67
+ 'Next record': '다음 레코드',
68
+ Certificate: '수료증',
65
69
  };
@@ -90,13 +90,98 @@ export const PANELS: Record<string, string> = {
90
90
  '클릭하여 선택 · 더블 클릭하여 편집 · Esc 종료',
91
91
  Element: '요소',
92
92
  Close: '닫기',
93
- 'Editing on the page. Enter keeps the change, Shift+Enter starts a new line, Esc reverts it.':
94
- '페이지에서 편집 중입니다. Enter는 변경 사항 유지, Shift+Enter는 줄바꿈, Esc는 되돌리기입니다.',
95
- 'Double-click the text on the page, or press Enter, to edit it where it is printed.':
96
- '페이지의 텍스트를 더블 클릭하거나 Enter를 누르면 인쇄되는 위치에서 바로 편집할 수 있습니다.',
97
- 'Inline markup stays as written.': '인라인 마크업은 그대로 유지됩니다.',
98
93
  'Not editable here.': '여기에서 편집할 수 없습니다.',
99
94
  'Comment for the agent': '에이전트에게 남길 댓글',
100
95
  'make this bold, shorten to one line…': '굵게 표시, 한 줄로 줄이기…',
101
96
  'Mark comment': '댓글 표시',
97
+ Typography: '타이포그래피',
98
+ Color: '색상',
99
+ Font: '글꼴',
100
+ Size: '크기',
101
+ 'Size in pixels': '크기(픽셀)',
102
+ Weight: '굵기',
103
+ 'Line height': '줄 높이',
104
+ 'Letter spacing in pixels': '자간(픽셀)',
105
+ Fill: '채우기',
106
+ Background: '배경',
107
+ None: '없음',
108
+ Inherited: '상속',
109
+ 'From {name}': '{name}에서',
110
+ 'from {name}': '{name}에서',
111
+ 'set in code: {code}': '코드로 설정: {code}',
112
+ Custom: '사용자 지정',
113
+ 'Align left': '왼쪽 정렬',
114
+ 'Align center': '가운데 정렬',
115
+ 'Align right': '오른쪽 정렬',
116
+ Justify: '양쪽 정렬',
117
+ 'This is a component — its styles are set inside it, not here.':
118
+ '컴포넌트입니다. 스타일은 여기가 아니라 컴포넌트 내부에서 설정됩니다.',
119
+ 'This element’s style is not written as an object.':
120
+ '이 요소의 style은 객체로 작성되어 있지 않습니다.',
121
+ 'source does not match this element': '소스가 이 요소와 일치하지 않습니다',
122
+ 'element not found': '요소를 찾을 수 없습니다',
123
+ 'Light 300': 'Light 300',
124
+ 'Regular 400': 'Regular 400',
125
+ 'Medium 500': 'Medium 500',
126
+ 'Semibold 600': 'Semibold 600',
127
+ 'Bold 700': 'Bold 700',
128
+ 'Extrabold 800': 'Extrabold 800',
129
+ 'Heading {level}': '제목 {level}',
130
+ Paragraph: '단락',
131
+ List: '목록',
132
+ Table: '표',
133
+ Image: '이미지',
134
+ Box: '상자',
135
+ Alignment: '정렬',
136
+ Emphasis: '강조',
137
+ 'Edit on page': '페이지에서 편집',
138
+ Source: '소스',
139
+ Location: '위치',
140
+ 'Letter spacing': '자간',
141
+ 'Text color': '텍스트 색상',
142
+ '{label} token': '{label} 토큰',
143
+ 'Inherited font': '상속된 글꼴',
144
+ '{name} font': '{name} 글꼴',
145
+ 'Custom font': '사용자 지정 글꼴',
146
+ Done: '완료',
147
+ '{count} elements print from this line of source': '이 소스 줄에서 {count}개의 요소가 출력됩니다',
148
+ Changes: '변경 사항',
149
+ 'Changes ({count})': '변경 사항({count})',
150
+ 'Changes since the last commit': '마지막 커밋 이후 변경 사항',
151
+ 'Close the changes panel': '변경 사항 패널 닫기',
152
+ 'Show changes since the last commit': '마지막 커밋 이후 변경 사항 표시',
153
+ 'Previous change': '이전 변경',
154
+ 'Next change': '다음 변경',
155
+ Since: '비교',
156
+ 'Compare with': '비교 대상',
157
+ 'Last commit': '마지막 커밋',
158
+ 'git is not installed': 'git이 설치되어 있지 않습니다',
159
+ 'Not a git repository': 'git 저장소가 아닙니다',
160
+ 'No changes': '변경 사항 없음',
161
+ 'Page {page}, changed': '{page}페이지, 변경됨',
162
+ Files: '파일',
163
+ 'Revert this change': '이 변경 되돌리기',
164
+ 'that change is no longer there — reload the changes':
165
+ '이 변경은 더 이상 없습니다. 변경 사항을 다시 불러오세요',
166
+ 'the file changed since the diff was read': '차이를 읽은 뒤 파일이 변경되었습니다',
167
+ 'reverting this change alone would break the source — revert the changes around it too':
168
+ '이 변경만 되돌리면 소스가 깨집니다. 주변 변경도 함께 되돌리세요',
169
+ 'a binary file cannot be reverted here': '바이너리 파일은 여기서 되돌릴 수 없습니다',
170
+ 'this workspace is not under git': '이 작업 공간은 git으로 관리되지 않습니다',
171
+ Comments: '댓글',
172
+ 'Comments ({count})': '댓글({count})',
173
+ 'Close the comments panel': '댓글 패널 닫기',
174
+ 'Show comments': '댓글 표시',
175
+ 'New comment': '새 댓글',
176
+ Resolve: '해결됨으로 표시',
177
+ 'Copy request for the agent': '에이전트 요청 복사',
178
+ 'No comments': '댓글 없음',
179
+ 'p.{page}': '{page}쪽',
180
+ 'Page {page}, with comments': '{page}페이지, 댓글 있음',
181
+ 'Could not resolve the comment': '해결됨으로 표시할 수 없습니다',
182
+ 'Pick an element on the page': '페이지에서 요소 선택',
183
+ 'Click the element to comment on · Esc to cancel': '댓글을 남길 요소를 클릭 · Esc로 취소',
184
+ Records: '레코드',
185
+ 'Row {row} of {count}': '{count}행 중 {row}행',
186
+ 'Esc to deselect': 'Esc로 선택 해제',
102
187
  };
@@ -81,4 +81,14 @@ export const BROWSER: Record<string, string> = {
81
81
  'Light theme': '浅色主题',
82
82
  'Dark theme': '深色主题',
83
83
  'System theme': '跟随系统主题',
84
+ 'New document': '新建文档',
85
+ Template: '模板',
86
+ 'This workspace': '这个工作区',
87
+ Create: '创建',
88
+ 'Could not create the document': '无法创建文档',
89
+ Blank: '空白',
90
+ Report: '报告',
91
+ Proposal: '提案',
92
+ 'Meeting notes': '会议记录',
93
+ Letter: '信函',
84
94
  };