@stll/folio-core 0.75.0 → 0.76.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 (92) hide show
  1. package/dist/ai-edits/headless.d.ts +2 -1
  2. package/dist/ai-edits/headless.js +18 -12
  3. package/dist/ai-edits/pending-suggestions.js +2 -3
  4. package/dist/ai-edits/read.js +9 -3
  5. package/dist/ai-edits/types.d.ts +9 -4
  6. package/dist/canonical/batchCommentReferences.js +2 -1
  7. package/dist/canonical/canonicalBatchReview.js +5 -8
  8. package/dist/canonical/canonicalComments.js +8 -2
  9. package/dist/canonical/canonicalCompilerRefusal.d.ts +2 -4
  10. package/dist/canonical/canonicalCompilerRefusal.js +20 -14
  11. package/dist/canonical/canonicalPublicOperations.js +203 -71
  12. package/dist/canonical/canonicalSession.js +3 -1
  13. package/dist/controller/canonicalClipboard.d.ts +1 -1
  14. package/dist/controller/canonicalClipboard.js +71 -17
  15. package/dist/controller/canonicalContentControlValue.js +7 -7
  16. package/dist/controller/canonicalReview.d.ts +21 -0
  17. package/dist/controller/canonicalReview.js +44 -9
  18. package/dist/controller/canonicalStructure.d.ts +1 -2
  19. package/dist/controller/canonicalStructure.js +51 -24
  20. package/dist/controller/fontReadiness.js +50 -23
  21. package/dist/controller/hiddenEditorManager.js +5 -20
  22. package/dist/docx/bulletMarkers.d.ts +8 -0
  23. package/dist/docx/bulletMarkers.js +9 -1
  24. package/dist/docx/canonicalSessionInput.js +25 -11
  25. package/dist/docx/ensureParaIds.d.ts +31 -0
  26. package/dist/docx/ensureParaIds.js +57 -32
  27. package/dist/docx/ensureUniqueControlIds.d.ts +13 -0
  28. package/dist/docx/ensureUniqueControlIds.js +47 -29
  29. package/dist/docx/ensureUniqueRevisionIds.d.ts +13 -0
  30. package/dist/docx/ensureUniqueRevisionIds.js +52 -29
  31. package/dist/docx/server/templatePlan/apply.js +62 -8
  32. package/dist/docx/server/templatePlan/blocks.d.ts +55 -3
  33. package/dist/docx/server/templatePlan/blocks.js +182 -6
  34. package/dist/docx/server/templatePlan/builders.d.ts +16 -1
  35. package/dist/docx/server/templatePlan/builders.js +31 -3
  36. package/dist/docx/server/templatePlan/effects.d.ts +27 -0
  37. package/dist/docx/server/templatePlan/effects.js +188 -0
  38. package/dist/docx/server/templatePlan/emit.d.ts +2 -1
  39. package/dist/docx/server/templatePlan/emit.js +44 -2
  40. package/dist/docx/server/templatePlan/inspect.js +21 -1
  41. package/dist/docx/server/templatePlan/labels.js +16 -1
  42. package/dist/docx/server/templatePlan/plan.d.ts +12 -3
  43. package/dist/docx/server/templatePlan/plan.js +36 -12
  44. package/dist/docx/server/templatePlan/planShape.js +47 -22
  45. package/dist/docx/server/templatePlan/revisions.d.ts +46 -0
  46. package/dist/docx/server/templatePlan/revisions.js +407 -0
  47. package/dist/docx/server/templatePlan/story.d.ts +15 -1
  48. package/dist/docx/server/templatePlan/story.js +50 -2
  49. package/dist/docx/server/templatePlan/types.d.ts +217 -1
  50. package/dist/docx/server/templatePlan/verify.js +117 -8
  51. package/dist/docx/server/templatePlan/xml.d.ts +3 -0
  52. package/dist/docx/server/templatePlan/xml.js +4 -1
  53. package/dist/internal/revisionResolutionStep.d.ts +2 -31
  54. package/dist/internal/revisionResolutionStep.js +2 -171
  55. package/dist/prosemirror/commands/comments.d.ts +6 -234
  56. package/dist/prosemirror/commands/comments.js +5 -2464
  57. package/dist/prosemirror/commands/index.d.ts +4 -2
  58. package/dist/prosemirror/commands/index.js +4 -2
  59. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +1 -11
  60. package/dist/prosemirror/commands/tableCellMergeResolution.js +3 -154
  61. package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +6 -8
  62. package/dist/prosemirror/hyperlinkRemoval.d.ts +11 -8
  63. package/dist/prosemirror/hyperlinkRemoval.js +24 -15
  64. package/dist/prosemirror/paraIds.d.ts +1 -14
  65. package/dist/prosemirror/paraIds.js +1 -14
  66. package/dist/prosemirror/paragraphMarkJoin.d.ts +0 -16
  67. package/dist/prosemirror/paragraphMarkJoin.js +3 -46
  68. package/dist/prosemirror/projectionReview.d.ts +49 -0
  69. package/dist/prosemirror/projectionReview.js +292 -0
  70. package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -13
  71. package/dist/prosemirror/rebaseParagraphRunFormatting.js +1 -16
  72. package/dist/prosemirror/replacedAnnotations.d.ts +2 -5
  73. package/dist/prosemirror/replacedAnnotations.js +1 -10
  74. package/dist/prosemirror/revisionCarriers.d.ts +9 -1
  75. package/dist/prosemirror/revisionCarriers.js +15 -1
  76. package/dist/prosemirror/revisionRangeQueries.d.ts +32 -0
  77. package/dist/prosemirror/revisionRangeQueries.js +76 -0
  78. package/dist/prosemirror/runFormattingMarkNames.d.ts +1 -1
  79. package/dist/prosemirror/runFormattingMarkNames.js +1 -1
  80. package/dist/prosemirror/suggestionQueries.d.ts +114 -0
  81. package/dist/prosemirror/suggestionQueries.js +320 -0
  82. package/dist/prosemirror/tableGridMutation.d.ts +1 -16
  83. package/dist/prosemirror/tableGridMutation.js +1 -78
  84. package/dist/prosemirror/tableRowRevisionOwnership.d.ts +18 -0
  85. package/dist/prosemirror/tableRowRevisionOwnership.js +7 -0
  86. package/dist/prosemirror/utils/extractTrackedChanges.js +14 -4
  87. package/dist/server.d.ts +2 -2
  88. package/dist/types/canonicalCapabilities.d.ts +1 -25
  89. package/dist/types/canonicalCapabilities.js +1 -23
  90. package/package.json +2 -2
  91. package/dist/internal/headlessRevisionResolutionGuard.d.ts +0 -3
  92. package/dist/internal/headlessRevisionResolutionGuard.js +0 -18
@@ -0,0 +1,188 @@
1
+ import { spliceXml } from "../../selectiveXmlPatch.js";
2
+ import { getLocalName } from "../../xmlParser.js";
3
+ import { elementChildren, integerOrNull, isW, rangeOf, wAttr, wChild } from "./xml.js";
4
+ // src/docx/server/templatePlan/effects.ts
5
+ /**
6
+ * Text effects that show nothing.
7
+ *
8
+ * A run's properties can carry text effects of the `w14` extension (`w14:glow`,
9
+ * `w14:shadow`, `w14:reflection`, `w14:textOutline`, `w14:textFill`,
10
+ * `w14:scene3d`, `w14:props3d`). An effect whose values make it invisible
11
+ * still changes how some consumers treat the text: a run with a 3-D scene,
12
+ * even the default one, is drawn as a picture, so its text cannot be found,
13
+ * copied or read aloud in the exported document. Each rule here names the
14
+ * values that make one effect invisible; an effect that meets no rule is
15
+ * left alone.
16
+ */
17
+ const WORD_2010_NAMESPACE = "http://schemas.microsoft.com/office/word/2010/wordml";
18
+ const TEXT_EFFECTS = [
19
+ "glow",
20
+ "shadow",
21
+ "reflection",
22
+ "textOutline",
23
+ "textFill",
24
+ "scene3d",
25
+ "props3d"
26
+ ];
27
+ const isEffect = (element, effect) => element.type === "element" && element.namespaceUri === WORD_2010_NAMESPACE && getLocalName(element.name) === effect;
28
+ const effectChild = (element, name) => elementChildren(element).find((child) => isEffect(child, name)) ?? null;
29
+ /** An attribute of an effect element by its local name, whatever prefix
30
+ * the part binds the namespace to. */
31
+ const effectAttr = (element, name) => {
32
+ for (const [key, value] of Object.entries(element.attributes ?? {})) if (value !== void 0 && (key === name || key.endsWith(`:${name}`))) return String(value);
33
+ return null;
34
+ };
35
+ /** Whether every named attribute is stated and zero. */
36
+ const allZero = (element, names) => names.every((name) => Number(effectAttr(element, name) ?? NaN) === 0);
37
+ /** Whether a named attribute is zero, or left to its default of zero. */
38
+ const zeroOrAbsent = (element, name) => {
39
+ const value = effectAttr(element, name);
40
+ return value === null || Number(value) === 0;
41
+ };
42
+ const FULLY_TRANSPARENT = 1e5;
43
+ /**
44
+ * Whether the colour an effect is drawn in is fully transparent. `alpha`
45
+ * states transparency here, in thousandths of a percent: the whole of it
46
+ * leaves nothing of the effect.
47
+ */
48
+ const drawnTransparent = (element) => elementChildren(element).some((colour) => {
49
+ const alpha = isEffect(colour, "srgbClr") || isEffect(colour, "schemeClr") ? effectChild(colour, "alpha") : null;
50
+ return alpha !== null && Number(effectAttr(alpha, "val")) === FULLY_TRANSPARENT;
51
+ });
52
+ /** Blur, distance and both scales at zero: nothing is drawn, whatever the
53
+ * colour, the direction or the skew. */
54
+ const ZERO_SIZE = [
55
+ "blurRad",
56
+ "dist",
57
+ "sx",
58
+ "sy"
59
+ ];
60
+ /** No depth, no contour and no bevel: nothing for a 3-D scene to light. */
61
+ const flatProperties = (props3d) => zeroOrAbsent(props3d, "extrusionH") && zeroOrAbsent(props3d, "contourW") && effectChild(props3d, "bevelT") === null && effectChild(props3d, "bevelB") === null;
62
+ /** The camera every flat text has: straight on, not turned. */
63
+ const defaultCamera = (scene3d) => {
64
+ const camera = effectChild(scene3d, "camera");
65
+ const rotation = camera === null ? null : effectChild(camera, "rot");
66
+ return camera !== null && effectAttr(camera, "prst") === "orthographicFront" && (rotation === null || allZero(rotation, [
67
+ "lat",
68
+ "lon",
69
+ "rev"
70
+ ]));
71
+ };
72
+ const HEX_COLOUR = /^[0-9a-f]{6}$/iu;
73
+ /** A solid fill in exactly the colour the run states for its text. */
74
+ const fillIsRunColour = (textFill, runProperties) => {
75
+ const solid = elementChildren(textFill).length === 1 ? effectChild(textFill, "solidFill") : null;
76
+ const colour = (solid === null ? [] : elementChildren(solid)).length === 1 ? effectChild(solid ?? textFill, "srgbClr") : null;
77
+ const stated = wChild(runProperties, "color");
78
+ const filled = colour === null ? null : effectAttr(colour, "val");
79
+ const run = wAttr(stated, "val");
80
+ return colour !== null && elementChildren(colour).length === 0 && filled !== null && run !== null && wAttr(stated, "themeColor") === null && HEX_COLOUR.test(filled) && filled.toLowerCase() === run.toLowerCase();
81
+ };
82
+ /**
83
+ * Whether an effect of `runProperties` shows nothing. One rule per effect:
84
+ *
85
+ * - `glow`: radius zero, or a fully transparent colour.
86
+ * - `shadow`: blur, distance and both scales zero, or a fully transparent
87
+ * colour. A shadow of full size straight under the text is not one: its
88
+ * edge shows around the glyphs.
89
+ * - `reflection`: blur, distance and both scales zero.
90
+ * - `textOutline`: no fill, a width of zero, or a fully transparent solid
91
+ * fill.
92
+ * - `textFill`: a plain solid fill in the colour the run states. A
93
+ * transparent fill is the opposite of nothing: it hides the text.
94
+ * - `props3d`: no extrusion, no contour, no bevel.
95
+ * - `scene3d`: the default camera, not turned, and nothing 3-D beside it.
96
+ */
97
+ const showsNothing = (effect, element, runProperties) => {
98
+ switch (effect) {
99
+ case "glow": return allZero(element, ["rad"]) || drawnTransparent(element);
100
+ case "shadow": return allZero(element, ZERO_SIZE) || drawnTransparent(element);
101
+ case "reflection": return allZero(element, ZERO_SIZE);
102
+ case "textOutline": {
103
+ const solid = effectChild(element, "solidFill");
104
+ return allZero(element, ["w"]) || solid !== null && drawnTransparent(solid) || effectChild(element, "noFill") !== null && solid === null && effectChild(element, "gradFill") === null;
105
+ }
106
+ case "textFill": return fillIsRunColour(element, runProperties);
107
+ case "props3d": return flatProperties(element);
108
+ case "scene3d": {
109
+ const props3d = effectChild(runProperties, "props3d");
110
+ return defaultCamera(element) && (props3d === null || flatProperties(props3d));
111
+ }
112
+ default: return effect;
113
+ }
114
+ };
115
+ const ownerOf = (element, owner) => {
116
+ if (isW(element, "abstractNum")) return {
117
+ kind: "level",
118
+ abstractNumId: integerOrNull(wAttr(element, "abstractNumId")),
119
+ ilvl: null
120
+ };
121
+ if (isW(element, "lvl")) return {
122
+ kind: "level",
123
+ abstractNumId: owner.kind === "level" ? owner.abstractNumId : null,
124
+ ilvl: integerOrNull(wAttr(element, "ilvl"))
125
+ };
126
+ if (isW(element, "style")) return {
127
+ kind: "style",
128
+ styleId: wAttr(element, "styleId")
129
+ };
130
+ return isW(element, "docDefaults") ? { kind: "defaults" } : owner;
131
+ };
132
+ /** Every text effect of a part that shows nothing, in document order. */
133
+ const findInvisibleEffects = ({ root }) => {
134
+ const found = [];
135
+ const stack = [{
136
+ element: root,
137
+ owner: { kind: "text" }
138
+ }];
139
+ for (let next = stack.pop(); next !== void 0; next = stack.pop()) {
140
+ const { element } = next;
141
+ const owner = ownerOf(element, next.owner);
142
+ const children = elementChildren(element);
143
+ if (isW(element, "rPr")) for (const effect of TEXT_EFFECTS) {
144
+ const stated = effectChild(element, effect);
145
+ const range = stated === null ? null : rangeOf(stated);
146
+ if (stated !== null && range !== null && showsNothing(effect, stated, element)) found.push({
147
+ effect,
148
+ owner,
149
+ range
150
+ });
151
+ }
152
+ for (let index = children.length - 1; index >= 0; index -= 1) {
153
+ const child = children[index];
154
+ if (child !== void 0) stack.push({
155
+ element: child,
156
+ owner
157
+ });
158
+ }
159
+ }
160
+ return found.toSorted((left, right) => left.range.start - right.range.start);
161
+ };
162
+ /**
163
+ * `part` without its text effects that show nothing; every other byte
164
+ * stays. `xml` is the part as it stands when nothing qualifies. Null when
165
+ * the part cannot be rewritten.
166
+ */
167
+ const removeInvisibleEffects = (part) => {
168
+ const removed = findInvisibleEffects(part);
169
+ if (removed.length === 0) return {
170
+ xml: part.xml,
171
+ removed
172
+ };
173
+ const xml = spliceXml(part.xml, removed.map(({ range }) => ({
174
+ ...range,
175
+ newXml: ""
176
+ })));
177
+ return xml === null ? null : {
178
+ xml,
179
+ removed
180
+ };
181
+ };
182
+ /** How many of each effect a part lost, for a report. */
183
+ const countEffects = (part, effects) => TEXT_EFFECTS.map((effect) => ({
184
+ part,
185
+ effect,
186
+ count: effects.filter((found) => found.effect === effect).length
187
+ })).filter(({ count }) => count > 0);
188
+ export { TEXT_EFFECTS, countEffects, findInvisibleEffects, removeInvisibleEffects };
@@ -103,7 +103,8 @@ export type TableEmit = {
103
103
  /**
104
104
  * A source table rebuilt: its grid, spans and merges, with every cell
105
105
  * paragraph placed like a body paragraph. Without a template table style the
106
- * source's borders are kept so the grid stays visible.
106
+ * source's borders are kept so the grid stays visible, and the fill of its
107
+ * cells with them: a header row, the colours of a legend.
107
108
  */
108
109
  export declare const tableXml: ({ table, styleId, paragraphOf }: TableEmit, context: EmitContext) => RunsResult;
109
110
  export type NoteEmit = {
@@ -221,6 +221,14 @@ const pieceRunXml = (piece, context, linked) => {
221
221
  const mark = `<${w}:${kind}Reference ${w}:id="${context.noteId(kind, sourceId)}"/>`;
222
222
  return Result.ok(style === null ? `<${w}:r><${w}:rPr><${w}:vertAlign ${w}:val="superscript"/></${w}:rPr>${mark}</${w}:r>` : `<${w}:r><${w}:rPr><${w}:rStyle ${w}:val="${escapeXmlAttribute(style)}"/></${w}:rPr>${mark}</${w}:r>`);
223
223
  }
224
+ case "selfNumber": {
225
+ const instruction = piece.atom?.instruction;
226
+ return Result.ok(instruction === void 0 ? "" : [
227
+ `<${w}:fldChar ${w}:fldCharType="begin"/>`,
228
+ `<${w}:instrText xml:space="preserve"> ${escapeXmlText(instruction)} </${w}:instrText>`,
229
+ `<${w}:fldChar ${w}:fldCharType="end"/>`
230
+ ].map((content) => run(content)).join(""));
231
+ }
224
232
  case "object": {
225
233
  const transferred = transferObject(piece, context);
226
234
  if (Result.isError(transferred)) return transferred;
@@ -326,9 +334,25 @@ const paragraphXml = (emit, context) => {
326
334
  const { styleId, numbering } = emit.paragraph;
327
335
  const properties = [];
328
336
  if (styleId !== null) properties.push(`<${w}:pStyle ${w}:val="${escapeXmlAttribute(styleId)}"/>`);
337
+ if (emit.paragraph.keepNext) properties.push(`<${w}:keepNext/>`);
329
338
  if (emit.paragraph.pageBreakBefore) properties.push(`<${w}:pageBreakBefore/>`);
330
339
  if (numbering.kind === "direct") properties.push(`<${w}:numPr><${w}:ilvl ${w}:val="${numbering.ilvl}"/><${w}:numId ${w}:val="${numbering.numId}"/></${w}:numPr>`);
331
340
  else if (numbering.kind === "none" && emit.styleBindsList) properties.push(`<${w}:numPr><${w}:numId ${w}:val="${NO_LIST_NUM_ID}"/></${w}:numPr>`);
341
+ const { indent, tabStops } = emit.paragraph;
342
+ if (tabStops !== null) {
343
+ const stops = tabStops.map((stop) => `<${w}:tab ${w}:val="left" ${w}:pos="${String(stop)}"/>`).join("");
344
+ properties.push(`<${w}:tabs>${stops}</${w}:tabs>`);
345
+ }
346
+ if (indent !== null) {
347
+ const sides = [
348
+ "left",
349
+ "hanging",
350
+ "firstLine"
351
+ ].filter((side) => indent[side] !== void 0).map((side) => ` ${w}:${side}="${String(indent[side])}"`).join("");
352
+ properties.push(`<${w}:ind${sides}/>`);
353
+ }
354
+ const { alignment } = emit.paragraph;
355
+ if (alignment !== null) properties.push(`<${w}:jc ${w}:val="${alignment}"/>`);
332
356
  if (emit.sectionXml !== null) properties.push(emit.sectionXml);
333
357
  const runs = segmentsRunsXml(emit.paragraph.segments, context, emit.instructionOf);
334
358
  if (Result.isError(runs)) return runs;
@@ -358,6 +382,23 @@ const CELL_SPAN_PROPERTIES = [
358
382
  "hMerge",
359
383
  "vMerge"
360
384
  ];
385
+ /** What a cell's fill states by itself; a theme colour is the template's. */
386
+ const SHADING_KEPT = [
387
+ "val",
388
+ "color",
389
+ "fill"
390
+ ];
391
+ /**
392
+ * The fill of a cell as its own colours state it. A theme colour would be
393
+ * read from the template's theme, which is another one; a fill stated by a
394
+ * theme colour alone is left out.
395
+ */
396
+ const cellShadingXml = (properties, prefix) => {
397
+ const shading = wChild(properties, "shd");
398
+ const fill = wAttr(shading, "fill");
399
+ if (shading === null || fill === null || fill === "auto") return "";
400
+ return `<${prefix}:shd${SHADING_KEPT.map((name) => [name, wAttr(shading, name)]).filter(([, value]) => value !== null).map(([name, value]) => ` ${prefix}:${name}="${escapeXmlAttribute(value ?? "")}"`).join("")}/>`;
401
+ };
361
402
  const keptChildrenXml = (properties, names, prefix) => names.map((name) => {
362
403
  const child = wChild(properties, name);
363
404
  return child === null ? "" : wSubtreeXml(child, prefix);
@@ -365,7 +406,8 @@ const keptChildrenXml = (properties, names, prefix) => names.map((name) => {
365
406
  /**
366
407
  * A source table rebuilt: its grid, spans and merges, with every cell
367
408
  * paragraph placed like a body paragraph. Without a template table style the
368
- * source's borders are kept so the grid stays visible.
409
+ * source's borders are kept so the grid stays visible, and the fill of its
410
+ * cells with them: a header row, the colours of a legend.
369
411
  */
370
412
  const tableXml = ({ table, styleId, paragraphOf }, context) => {
371
413
  const { w } = context.prefixes;
@@ -395,7 +437,7 @@ const tableXml = ({ table, styleId, paragraphOf }, context) => {
395
437
  const name = wName(child);
396
438
  if (name === "tc") {
397
439
  const cellProperties = wChild(child, "tcPr");
398
- const kept = `${keptChildrenXml(cellProperties, CELL_SPAN_PROPERTIES, w)}${styleId === null ? keptChildrenXml(cellProperties, ["tcBorders"], w) : ""}${keptChildrenXml(cellProperties, ["vAlign"], w)}`;
440
+ const kept = `${keptChildrenXml(cellProperties, CELL_SPAN_PROPERTIES, w)}${styleId === null ? `${keptChildrenXml(cellProperties, ["tcBorders"], w)}${cellShadingXml(cellProperties, w)}` : ""}${keptChildrenXml(cellProperties, ["vAlign"], w)}`;
399
441
  const blocks = blocksXml(child);
400
442
  if (Result.isError(blocks)) return blocks;
401
443
  const content = blocks.value.endsWith(`</${w}:p>`) ? blocks.value : `${blocks.value}<${w}:p/>`;
@@ -1,6 +1,7 @@
1
1
  import { RELATIONSHIP_TYPES } from "../../relsParser.js";
2
2
  import { parseSectionProperties } from "../../sectionParser.js";
3
- import { analyzeDocument, statedAlignments, storySections, styleAlignment, styleOutlineLevel } from "./blocks.js";
3
+ import { analyzeDocument, statedAlignments, statedLooks, storySections, styleAlignment, styleLook, styleOutlineLevel } from "./blocks.js";
4
+ import { findInvisibleEffects } from "./effects.js";
4
5
  import { styleNumbering } from "./labels.js";
5
6
  import { guarded, readPartText } from "./package.js";
6
7
  import { createStoryState, endStory, readParagraph, walkBlocks } from "./story.js";
@@ -33,8 +34,10 @@ const NO_INDENT = {
33
34
  const inspectStyles = (analyzed) => {
34
35
  const { styles, numbering } = analyzed;
35
36
  const stated = statedAlignments(analyzed.stylesPath, analyzed.stylesXml);
37
+ const looks = statedLooks(analyzed.stylesPath, analyzed.stylesXml);
36
38
  return [...styles.values()].map((style) => {
37
39
  const bound = styleNumbering(style.styleId, styles, numbering);
40
+ const { bold, size, keepNext, indentLeft } = styleLook(style.styleId, styles, looks);
38
41
  return {
39
42
  styleId: style.styleId,
40
43
  name: style.name ?? null,
@@ -46,6 +49,10 @@ const inspectStyles = (analyzed) => {
46
49
  } : null,
47
50
  outlineLvl: styleOutlineLevel(style),
48
51
  alignment: styleAlignment(style.styleId, styles, stated),
52
+ bold,
53
+ size,
54
+ keepNext,
55
+ indentLeft,
49
56
  isDefault: style.default === true
50
57
  };
51
58
  });
@@ -176,8 +183,21 @@ const inspectAnalyzedTemplate = async (analyzed) => {
176
183
  fields.push(...partFields(part).map((field) => fieldOf(part.path, field)));
177
184
  bookmarks.push(...bookmarksOf(part));
178
185
  }
186
+ const effectParts = [
187
+ document,
188
+ ...[[analyzed.numberingPath, analyzed.numberingXml], [analyzed.stylesPath, analyzed.stylesXml]].flatMap(([path, xml]) => {
189
+ const part = path === null || xml === null ? null : readRawPart(path, xml);
190
+ return part === null ? [] : [part];
191
+ }),
192
+ ...headersAndFooters.value
193
+ ];
179
194
  return Result.ok({
180
195
  ...manifest,
196
+ invisibleEffects: effectParts.flatMap((part) => findInvisibleEffects(part).map(({ effect, owner }) => ({
197
+ part: part.path,
198
+ effect,
199
+ owner
200
+ }))),
181
201
  styles: inspectStyles(analyzed),
182
202
  numbering: inspectNumbering(analyzed),
183
203
  fields,
@@ -1,3 +1,4 @@
1
+ import { bulletMarkerFontName, bulletTextFace } from "../../bulletMarkers.js";
1
2
  import { computeListMarker } from "../../listMarkerComputation.js";
2
3
  import { resolveListTemplateWithComponents } from "../../listTemplate.js";
3
4
  import { computeListRendering } from "../../numberingParser.js";
@@ -25,6 +26,19 @@ const PLAIN_FORMATS = /* @__PURE__ */ new Set([
25
26
  "lowerLetter"
26
27
  ]);
27
28
  const LEVEL_PLACEHOLDER = /%([1-9])/gu;
29
+ /**
30
+ * What a block says of a bullet level: that it is one, and the text face its
31
+ * mark is a character of. `mark` is the level's own text, before it is read
32
+ * as the glyph it paints.
33
+ */
34
+ const bulletFacts = ({ isBullet, markerFormatting }, mark) => {
35
+ if (!isBullet) return {};
36
+ const face = bulletTextFace(mark, bulletMarkerFontName(markerFormatting));
37
+ return face === void 0 ? { bullet: true } : {
38
+ bullet: true,
39
+ bulletFont: face
40
+ };
41
+ };
28
42
  const labelAsText = ({ label, template, levelFormats, suffix, ordinalKnown }) => {
29
43
  if (label.trim() === "") return null;
30
44
  for (const [, digit] of template.matchAll(LEVEL_PLACEHOLDER)) {
@@ -206,7 +220,8 @@ const createLabelCounter = ({ numbering, styles, defaultStyleId, defaultLanguage
206
220
  const numberingInfo = abstractNumId === null ? null : {
207
221
  numId: resolved.numId,
208
222
  ilvl: resolved.ilvl,
209
- abstractNumId
223
+ abstractNumId,
224
+ ...bulletFacts(listRendering, template)
210
225
  };
211
226
  if (listRendering.markerHidden === true) return {
212
227
  ...NO_LABEL,
@@ -9,7 +9,7 @@ import { AnalyzedBlock, AnalyzedDocument } from "./blocks.js";
9
9
  import { BookmarkWrap } from "./builders.js";
10
10
  import { StoryOrigin } from "./resources.js";
11
11
  import { AtomKind, AtomLink, InlineAtom, ParagraphRead, StoryField } from "./story.js";
12
- import { TemplatePlan, TemplatePlanError, TemplatePlanOmitReason, TemplatePlanReference, TemplatePlanSection } from "./types.js";
12
+ import { TemplatePlan, TemplatePlanAlignment, TemplatePlanError, TemplatePlanIndent, TemplatePlanOmitReason, TemplatePlanReference, TemplatePlanSection } from "./types.js";
13
13
  import { Result } from "better-result";
14
14
  export type ExpectedPiece = {
15
15
  kind: AtomKind;
@@ -69,6 +69,14 @@ export type ResolvedParagraph = {
69
69
  placement: "body" | "nested" | "slot";
70
70
  /** Whether the paragraph starts on a new page. */
71
71
  pageBreakBefore: boolean;
72
+ /** Whether the paragraph is kept with the one after it. */
73
+ keepNext: boolean;
74
+ /** The paragraph's own indent, or null. */
75
+ indent: TemplatePlanIndent | null;
76
+ /** The paragraph's own left tab stops, or null. */
77
+ tabStops: readonly number[] | null;
78
+ /** The paragraph's own alignment, or null. */
79
+ alignment: TemplatePlanAlignment | null;
72
80
  /** The section the paragraph is the last of, or null. */
73
81
  endsSection: TemplatePlanSection | null;
74
82
  };
@@ -124,8 +132,9 @@ export type ResolvedPlan = {
124
132
  /**
125
133
  * Whether `label` reads as a manual list label: up to three leading words
126
134
  * ("Article", "§", "Annex No.") and one designator, a number, a roman numeral
127
- * or a letter with its brackets and punctuation; or a single bullet. This is
128
- * the only text a plan may have removed.
135
+ * or a letter with its brackets and punctuation; or a single bullet; or a
136
+ * number whose parts stand apart (`1. 1.` for `1.1.`). This is the only text
137
+ * a plan may have removed.
129
138
  */
130
139
  export declare const isManualLabel: (label: string) => boolean;
131
140
  /** Whether a block holds no text and no object. */
@@ -27,16 +27,19 @@ const ROMAN_NUMERAL = /^(?=.)M{0,3}(?:CM|CD|D?C{0,3})(?:XC|XL|L?X{0,3})(?:IX|IV|
27
27
  const LABEL_WORD = /^(?:\p{L}[\p{L}\p{M}]*\.?|§{1,2}|№|#)$/u;
28
28
  const LABEL_DESIGNATOR = /^[([]?(?<core>\d+(?:[.\-\u2013]\d+)*[a-z]?|\p{L}+)[)\]]?[.:)]*$/u;
29
29
  const LABEL_BULLET = /^[-\u2013\u2014\u2022\u00B7\u25AA\u25E6*]$/u;
30
+ /** A number of several parts typed with blanks between them: `1. 1.`. */
31
+ const LABEL_SPACED_NUMBER = /^\d{1,3}\.(?:[ \u00A0]+\d{1,3}\.){1,3}$/u;
30
32
  const MAX_LABEL_WORDS = 3;
31
33
  /**
32
34
  * Whether `label` reads as a manual list label: up to three leading words
33
35
  * ("Article", "§", "Annex No.") and one designator, a number, a roman numeral
34
- * or a letter with its brackets and punctuation; or a single bullet. This is
35
- * the only text a plan may have removed.
36
+ * or a letter with its brackets and punctuation; or a single bullet; or a
37
+ * number whose parts stand apart (`1. 1.` for `1.1.`). This is the only text
38
+ * a plan may have removed.
36
39
  */
37
40
  const isManualLabel = (label) => {
38
41
  if (label === "" || label.length > MAX_LABEL_LENGTH) return false;
39
- if (LABEL_BULLET.test(label)) return true;
42
+ if (LABEL_BULLET.test(label) || LABEL_SPACED_NUMBER.test(label)) return true;
40
43
  const tokens = label.split(/[ \u00A0]/u);
41
44
  const designator = tokens.at(-1) ?? "";
42
45
  const words = tokens.slice(0, -1);
@@ -48,6 +51,8 @@ const NOTES_OF_REFERENCE = {
48
51
  endnoteReference: "endnotes"
49
52
  };
50
53
  const LABEL_SPACE = /^[ \t ]+/u;
54
+ /** The blank behind a label when a line break behind it goes too. */
55
+ const LABEL_SPACE_AND_BREAK = /^[ \t ]*(?:\n[ \t ]*)?/u;
51
56
  const LEADING_SPACE = /^[ \t ]*/u;
52
57
  /** Whether a block holds no text and no object. */
53
58
  const isBlankBlock = ({ block }) => block.text.trim() === "" && block.inlineObjects === 0;
@@ -69,6 +74,8 @@ const hyperlinkFieldLink = ({ instruction, kind }) => {
69
74
  const NOTE_REFERENCE_KINDS = /* @__PURE__ */ new Set(["footnoteReference", "endnoteReference"]);
70
75
  /** What a stripped label may consist of. */
71
76
  const STRIPPABLE_KINDS = /* @__PURE__ */ new Set(["text", "tab"]);
77
+ /** The same when a line break behind the label goes with it. */
78
+ const STRIPPABLE_WITH_BREAK = /* @__PURE__ */ new Set([...STRIPPABLE_KINDS, "lineBreak"]);
72
79
  /**
73
80
  * Character styles that only give a link its look. The template supplies
74
81
  * that look; any other character style inside a link is emphasis.
@@ -157,7 +164,8 @@ const spansOverlap = (spans) => {
157
164
  return previous !== void 0 && span.start < previous.end;
158
165
  });
159
166
  };
160
- const partSegments = ({ block, pieces, strippedLength, references, highlights }) => {
167
+ const partSegments = ({ block, pieces, strippedLength, strippedBreak, references, highlights }) => {
168
+ const strippable = strippedBreak ? STRIPPABLE_WITH_BREAK : STRIPPABLE_KINDS;
161
169
  const blockId = block.block.id;
162
170
  const length = block.block.text.length;
163
171
  const badReference = (message) => Result.err(refuse({
@@ -192,7 +200,7 @@ const partSegments = ({ block, pieces, strippedLength, references, highlights })
192
200
  for (const entry of split) {
193
201
  const empty = entry.start === entry.end;
194
202
  if (entry.end <= strippedLength && !empty) {
195
- if (!STRIPPABLE_KINDS.has(entry.piece.kind)) return Result.err(refuse({
203
+ if (!strippable.has(entry.piece.kind)) return Result.err(refuse({
196
204
  code: "strip-label-mismatch",
197
205
  message: `The label to strip from block ${blockId} covers more than text.`,
198
206
  blockId
@@ -461,7 +469,7 @@ const resolvePlan = (source, template, plan) => {
461
469
  placed.add(id);
462
470
  return Result.ok(void 0);
463
471
  };
464
- const resolveParagraph = ({ parts, separators, styleId, numbering, placement, ordinal, pageBreakBefore = false, endsSection }) => {
472
+ const resolveParagraph = ({ parts, separators, styleId, numbering, placement, ordinal, pageBreakBefore = false, keepNext = false, indent, tabStops, alignment, endsSection }) => {
465
473
  const first = parts.at(0);
466
474
  if (first === void 0) return invalid("A plan item names no source block.");
467
475
  const firstId = first.block.block.id;
@@ -477,7 +485,7 @@ const resolvePlan = (source, template, plan) => {
477
485
  const segments = [];
478
486
  const resolvedParts = [];
479
487
  for (const [index, planned] of parts.entries()) {
480
- const { block, stripLabel } = planned;
488
+ const { block, stripLabel, stripLabelBreak } = planned;
481
489
  const { id, text } = block.block;
482
490
  if (block.read === null) return invalid(`Block ${id} is a table and cannot be joined or slotted.`);
483
491
  const placedOnce = place(block);
@@ -493,7 +501,8 @@ const resolvePlan = (source, template, plan) => {
493
501
  message: `Block ${id} does not start with the label to strip.`,
494
502
  blockId: id
495
503
  }));
496
- strippedPrefix = text.slice(0, labelEnd + (LABEL_SPACE.exec(text.slice(labelEnd))?.[0].length ?? 0));
504
+ const blank = stripLabelBreak === true ? LABEL_SPACE_AND_BREAK : LABEL_SPACE;
505
+ strippedPrefix = text.slice(0, labelEnd + (blank.exec(text.slice(labelEnd))?.[0].length ?? 0));
497
506
  }
498
507
  const part = partSegments({
499
508
  block,
@@ -504,6 +513,7 @@ const resolvePlan = (source, template, plan) => {
504
513
  fields: source.story.state.fields
505
514
  }),
506
515
  strippedLength: strippedPrefix.length,
516
+ strippedBreak: stripLabelBreak === true,
507
517
  references: referencesByBlock.get(id) ?? [],
508
518
  highlights: highlightsByBlock.get(id) ?? []
509
519
  });
@@ -554,6 +564,10 @@ const resolvePlan = (source, template, plan) => {
554
564
  inlineObjects: pieces.filter(({ kind }) => kind === "object").length,
555
565
  placement,
556
566
  pageBreakBefore,
567
+ keepNext,
568
+ indent: indent ?? null,
569
+ tabStops: tabStops ?? null,
570
+ alignment: alignment ?? null,
557
571
  endsSection: endsSection ?? null
558
572
  };
559
573
  for (const { block } of resolvedParts) byBlockId.set(block.block.id, paragraph);
@@ -570,7 +584,7 @@ const resolvePlan = (source, template, plan) => {
570
584
  };
571
585
  const resolveTable = (block, item, tableOrdinal) => {
572
586
  const { id } = block.block;
573
- if (item.mergeNext !== void 0 || item.stripLabel !== void 0 || item.labelAsText !== void 0 || item.pageBreakBefore !== void 0 || item.endsSection !== void 0 || item.numbering !== void 0) return invalid(`Table ${id} takes a style and nested placements only.`);
587
+ if (item.mergeNext !== void 0 || item.stripLabel !== void 0 || item.stripLabelBreak !== void 0 || item.labelAsText !== void 0 || item.pageBreakBefore !== void 0 || item.keepNext !== void 0 || item.indent !== void 0 || item.tabStops !== void 0 || item.alignment !== void 0 || item.endsSection !== void 0 || item.numbering !== void 0) return invalid(`Table ${id} takes a style and nested placements only.`);
574
588
  if (item.styleId !== void 0 && template.styles.get(item.styleId)?.type !== "table") return Result.err(refuse({
575
589
  code: "style-unknown",
576
590
  message: `The template has no table style ${item.styleId}.`,
@@ -599,7 +613,11 @@ const resolvePlan = (source, template, plan) => {
599
613
  styleId: override?.styleId ?? item.cellStyleId,
600
614
  numbering: override?.numbering,
601
615
  placement: "nested",
602
- ordinal: tableOrdinal * 1e6 + nested.block.index
616
+ ordinal: tableOrdinal * 1e6 + nested.block.index,
617
+ keepNext: override?.keepNext === true,
618
+ indent: override?.indent,
619
+ tabStops: override?.tabStops,
620
+ alignment: override?.alignment
603
621
  });
604
622
  if (Result.isError(paragraph)) return paragraph;
605
623
  cells.set(nested.element, paragraph.value);
@@ -667,6 +685,7 @@ const resolvePlan = (source, template, plan) => {
667
685
  const parts = [{
668
686
  block: block.value,
669
687
  stripLabel: item.stripLabel,
688
+ stripLabelBreak: item.stripLabelBreak === true,
670
689
  labelAsText: item.labelAsText === true
671
690
  }];
672
691
  const separators = [];
@@ -684,15 +703,16 @@ const resolvePlan = (source, template, plan) => {
684
703
  message: `Block ${next.blockId} does not have the hash the plan pins.`,
685
704
  blockId: next.blockId
686
705
  }));
687
- if (next.styleId !== void 0 || next.numbering !== void 0 || next.cellStyleId !== void 0 || next.nested !== void 0 || next.pageBreakBefore !== void 0 || next.endsSection !== void 0) return Result.err(refuse({
706
+ if (next.styleId !== void 0 || next.numbering !== void 0 || next.cellStyleId !== void 0 || next.nested !== void 0 || next.pageBreakBefore !== void 0 || next.keepNext !== void 0 || next.indent !== void 0 || next.tabStops !== void 0 || next.alignment !== void 0 || next.endsSection !== void 0) return Result.err(refuse({
688
707
  code: "merge-invalid",
689
- message: `Block ${next.blockId} joins the paragraph before it and cannot carry a style, a list, a page start or a section end of its own.`,
708
+ message: `Block ${next.blockId} joins the paragraph before it and cannot carry a style, a list, a page start, a format or a section end of its own.`,
690
709
  blockId: next.blockId
691
710
  }));
692
711
  separators.push(merge);
693
712
  parts.push({
694
713
  block: nextBlock.value,
695
714
  stripLabel: next.stripLabel,
715
+ stripLabelBreak: next.stripLabelBreak === true,
696
716
  labelAsText: next.labelAsText === true
697
717
  });
698
718
  merge = next.mergeNext;
@@ -706,6 +726,10 @@ const resolvePlan = (source, template, plan) => {
706
726
  placement: "body",
707
727
  ordinal,
708
728
  pageBreakBefore: item.pageBreakBefore === true,
729
+ keepNext: item.keepNext === true,
730
+ indent: item.indent,
731
+ tabStops: item.tabStops,
732
+ alignment: item.alignment,
709
733
  endsSection: item.endsSection
710
734
  });
711
735
  if (Result.isError(paragraph)) return paragraph;