@stll/folio-core 0.75.0 → 0.77.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.
- package/dist/ai-edits/headless.d.ts +8 -5
- package/dist/ai-edits/headless.js +49 -26
- package/dist/ai-edits/pending-suggestions.d.ts +9 -0
- package/dist/ai-edits/pending-suggestions.js +13 -3
- package/dist/ai-edits/read.js +33 -4
- package/dist/ai-edits/table-geometry.js +12 -4
- package/dist/ai-edits/types.d.ts +9 -4
- package/dist/canonical/batchCommentReferences.js +2 -1
- package/dist/canonical/canonicalBatchReview.js +5 -8
- package/dist/canonical/canonicalComments.js +8 -2
- package/dist/canonical/canonicalCompilerRefusal.d.ts +2 -4
- package/dist/canonical/canonicalCompilerRefusal.js +20 -14
- package/dist/canonical/canonicalInlineProjection.d.ts +2 -2
- package/dist/canonical/canonicalInlineProjection.js +2 -2
- package/dist/canonical/canonicalProjectionBlocks.d.ts +10 -1
- package/dist/canonical/canonicalPublicOperations.js +214 -107
- package/dist/canonical/canonicalSeedContent.d.ts +18 -3
- package/dist/canonical/canonicalSeedContent.js +28 -15
- package/dist/canonical/canonicalSession.d.ts +22 -12
- package/dist/canonical/canonicalSession.js +181 -187
- package/dist/controller/canonicalClipboard.d.ts +3 -2
- package/dist/controller/canonicalClipboard.js +377 -58
- package/dist/controller/canonicalComposition.js +67 -14
- package/dist/controller/canonicalContentControlValue.js +7 -7
- package/dist/controller/canonicalReview.d.ts +21 -0
- package/dist/controller/canonicalReview.js +44 -9
- package/dist/controller/canonicalStoryEditor.js +2 -0
- package/dist/controller/canonicalStructure.d.ts +1 -2
- package/dist/controller/canonicalStructure.js +51 -24
- package/dist/controller/fontReadiness.js +50 -23
- package/dist/controller/hiddenEditorManager.js +7 -20
- package/dist/docx/bulletMarkers.d.ts +8 -0
- package/dist/docx/bulletMarkers.js +9 -1
- package/dist/docx/canonicalSessionInput.js +25 -11
- package/dist/docx/ensureParaIds.d.ts +31 -0
- package/dist/docx/ensureParaIds.js +57 -32
- package/dist/docx/ensureUniqueControlIds.d.ts +13 -0
- package/dist/docx/ensureUniqueControlIds.js +47 -29
- package/dist/docx/ensureUniqueRevisionIds.d.ts +13 -0
- package/dist/docx/ensureUniqueRevisionIds.js +52 -29
- package/dist/docx/importedIdCollisions.js +29 -4
- package/dist/docx/server/templatePlan/apply.js +108 -9
- package/dist/docx/server/templatePlan/blocks.d.ts +77 -5
- package/dist/docx/server/templatePlan/blocks.js +281 -14
- package/dist/docx/server/templatePlan/builders.d.ts +22 -1
- package/dist/docx/server/templatePlan/builders.js +37 -3
- package/dist/docx/server/templatePlan/effects.d.ts +27 -0
- package/dist/docx/server/templatePlan/effects.js +188 -0
- package/dist/docx/server/templatePlan/emit.d.ts +4 -1
- package/dist/docx/server/templatePlan/emit.js +152 -8
- package/dist/docx/server/templatePlan/inspect.js +21 -1
- package/dist/docx/server/templatePlan/labels.js +16 -1
- package/dist/docx/server/templatePlan/plan.d.ts +35 -3
- package/dist/docx/server/templatePlan/plan.js +197 -20
- package/dist/docx/server/templatePlan/planShape.js +58 -22
- package/dist/docx/server/templatePlan/revisions.d.ts +101 -0
- package/dist/docx/server/templatePlan/revisions.js +681 -0
- package/dist/docx/server/templatePlan/story.d.ts +61 -2
- package/dist/docx/server/templatePlan/story.js +175 -13
- package/dist/docx/server/templatePlan/types.d.ts +313 -1
- package/dist/docx/server/templatePlan/verify.js +175 -12
- package/dist/docx/server/templatePlan/xml.d.ts +3 -0
- package/dist/docx/server/templatePlan/xml.js +4 -1
- package/dist/docx/settingsHeaderFooterUpdate.d.ts +1 -1
- package/dist/docx/tableGridXml.d.ts +3 -7
- package/dist/docx/tableGridXml.js +5 -13
- package/dist/layout-bridge/convert/footnoteLayout.js +34 -8
- package/dist/prosemirror/canonicalMarkupDocument.d.ts +20 -0
- package/dist/prosemirror/canonicalMarkupDocument.js +73 -0
- package/dist/prosemirror/canonicalTableCommands.d.ts +1 -1
- package/dist/prosemirror/canonicalTableCommands.js +1 -3
- package/dist/prosemirror/commands/comments.d.ts +6 -234
- package/dist/prosemirror/commands/comments.js +5 -2464
- package/dist/prosemirror/commands/index.d.ts +4 -2
- package/dist/prosemirror/commands/index.js +4 -2
- package/dist/prosemirror/conversion/markupViewSource.d.ts +17 -0
- package/dist/prosemirror/conversion/markupViewSource.js +11 -0
- package/dist/prosemirror/conversion/toProseDoc.d.ts +3 -0
- package/dist/prosemirror/conversion/toProseDoc.js +31 -14
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +6 -8
- package/dist/prosemirror/hyperlinkRemoval.d.ts +11 -8
- package/dist/prosemirror/hyperlinkRemoval.js +24 -15
- package/dist/prosemirror/independentMarkupProjection.d.ts +27 -0
- package/dist/prosemirror/independentMarkupProjection.js +147 -0
- package/dist/prosemirror/markupViewNotes.d.ts +1 -1
- package/dist/prosemirror/markupViewNotes.js +24 -27
- package/dist/prosemirror/markupViewPositionMap.d.ts +16 -0
- package/dist/prosemirror/markupViewPositionMap.js +316 -0
- package/dist/prosemirror/markupViewProjection.d.ts +3 -46
- package/dist/prosemirror/markupViewProjection.js +90 -17
- package/dist/prosemirror/paraIds.d.ts +1 -14
- package/dist/prosemirror/paraIds.js +1 -14
- package/dist/prosemirror/paragraphMarkJoin.d.ts +0 -16
- package/dist/prosemirror/paragraphMarkJoin.js +3 -46
- package/dist/prosemirror/projectionReview.d.ts +49 -0
- package/dist/prosemirror/projectionReview.js +292 -0
- package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -13
- package/dist/prosemirror/rebaseParagraphRunFormatting.js +1 -16
- package/dist/prosemirror/replacedAnnotations.d.ts +6 -83
- package/dist/prosemirror/replacedAnnotations.js +11 -203
- package/dist/prosemirror/revisionCarriers.d.ts +9 -1
- package/dist/prosemirror/revisionCarriers.js +15 -1
- package/dist/prosemirror/revisionRangeQueries.d.ts +32 -0
- package/dist/prosemirror/revisionRangeQueries.js +76 -0
- package/dist/prosemirror/runFormattingMarkNames.d.ts +1 -1
- package/dist/prosemirror/runFormattingMarkNames.js +1 -1
- package/dist/prosemirror/styles/styleResolver.d.ts +1 -0
- package/dist/prosemirror/styles/styleResolver.js +4 -1
- package/dist/prosemirror/suggestionQueries.d.ts +114 -0
- package/dist/prosemirror/suggestionQueries.js +320 -0
- package/dist/prosemirror/tableGridMutation.d.ts +1 -16
- package/dist/prosemirror/tableGridMutation.js +1 -78
- package/dist/prosemirror/tableRowRevisionOwnership.d.ts +18 -0
- package/dist/prosemirror/tableRowRevisionOwnership.js +7 -0
- package/dist/prosemirror/utils/extractTrackedChanges.js +14 -4
- package/dist/server.d.ts +2 -2
- package/dist/types/canonicalCapabilities.d.ts +4 -35
- package/dist/types/canonicalCapabilities.js +4 -33
- package/package.json +2 -2
- package/dist/internal/headlessRevisionResolutionGuard.d.ts +0 -3
- package/dist/internal/headlessRevisionResolutionGuard.js +0 -18
- package/dist/internal/revisionResolutionEdits.d.ts +0 -11
- package/dist/internal/revisionResolutionEdits.js +0 -18
- package/dist/internal/revisionResolutionInline.d.ts +0 -24
- package/dist/internal/revisionResolutionInline.js +0 -302
- package/dist/internal/revisionResolutionStep.d.ts +0 -32
- package/dist/internal/revisionResolutionStep.js +0 -282
- package/dist/internal/revisionResolutionTracking.d.ts +0 -9
- package/dist/internal/revisionResolutionTracking.js +0 -124
- package/dist/internal/wholeStoryRevisionResolution.d.ts +0 -56
- package/dist/internal/wholeStoryRevisionResolution.js +0 -783
- package/dist/prosemirror/commands/resolveAllTableChanges.d.ts +0 -38
- package/dist/prosemirror/commands/resolveAllTableChanges.js +0 -642
- package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.d.ts +0 -13
- package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.js +0 -45
- package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +0 -18
- package/dist/prosemirror/commands/tableCellMergeResolution.js +0 -207
- package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +0 -60
- package/dist/prosemirror/commands/tableMergeFoldDecisions.js +0 -78
- package/dist/prosemirror/rejoinRunCarriers.d.ts +0 -42
- package/dist/prosemirror/rejoinRunCarriers.js +0 -65
- package/dist/prosemirror/runPropertyChangeResolution.d.ts +0 -15
- package/dist/prosemirror/runPropertyChangeResolution.js +0 -34
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { splitsSurrogatePair } from "../ai-edits/character-boundaries.js";
|
|
2
2
|
import { CanonicalSessionError } from "../canonical/canonicalSession.js";
|
|
3
|
-
import { CANONICAL_CONDITION
|
|
3
|
+
import { CANONICAL_CONDITION } from "../types/canonicalCapabilities.js";
|
|
4
4
|
import { setCanonicalInputTimer } from "./canonicalInputTimer.js";
|
|
5
5
|
import { Result } from "better-result";
|
|
6
6
|
import { EditorState, TextSelection } from "prosemirror-state";
|
|
7
7
|
import { DOMParser, DOMSerializer, Fragment } from "prosemirror-model";
|
|
8
8
|
// src/controller/canonicalComposition.ts
|
|
9
|
-
/**
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* A composition the browser's own input did not reduce to one text
|
|
11
|
+
* replacement, restored. The commit reads what native input changed from the
|
|
12
|
+
* view; where it changed an atom (an image, a field, a note reference) or
|
|
13
|
+
* more than one textblock, or a plugin rewrote more than text, the DOM states
|
|
14
|
+
* no edit the session can tell from noise. The user types the text again, as
|
|
15
|
+
* input outside a composition reaches the session as intents.
|
|
16
|
+
*/
|
|
17
|
+
const UNSUPPORTED_COMPOSITION = { condition: CANONICAL_CONDITION.invalidRequest };
|
|
11
18
|
const REVIEW_MARK_NAMES = /* @__PURE__ */ new Set(["insertion", "deletion"]);
|
|
12
19
|
const readBackCache = /* @__PURE__ */ new WeakMap();
|
|
13
20
|
/**
|
|
@@ -31,6 +38,35 @@ const readBack = (mark) => {
|
|
|
31
38
|
readBackCache.set(mark, read);
|
|
32
39
|
return read;
|
|
33
40
|
};
|
|
41
|
+
/** The depth of the innermost textblock holding `position`, if one does. */
|
|
42
|
+
const textblockDepth = (position) => {
|
|
43
|
+
for (let depth = position.depth; depth >= 0; depth -= 1) if (position.node(depth).isTextblock) return depth;
|
|
44
|
+
};
|
|
45
|
+
/** The child of `fragment` that `position` falls in, with its offset. */
|
|
46
|
+
const childAround = (fragment, position) => {
|
|
47
|
+
let found;
|
|
48
|
+
fragment.forEach((node, offset) => {
|
|
49
|
+
if (found === void 0 && position < offset + node.nodeSize) found = {
|
|
50
|
+
node,
|
|
51
|
+
offset
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
return found;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* One character for each position of `fragment`: a text node's own, the
|
|
58
|
+
* object replacement character for an inline atom, and a private-use
|
|
59
|
+
* character for each edge of an inline node holding content.
|
|
60
|
+
*/
|
|
61
|
+
const positionText = (fragment) => {
|
|
62
|
+
let text = "";
|
|
63
|
+
fragment.forEach((node) => {
|
|
64
|
+
if (node.isText) text += node.text ?? "";
|
|
65
|
+
else if (node.isLeaf) text += "".repeat(node.nodeSize);
|
|
66
|
+
else text += `\uE000${positionText(node.content)}\uE001`;
|
|
67
|
+
});
|
|
68
|
+
return text;
|
|
69
|
+
};
|
|
34
70
|
/**
|
|
35
71
|
* Whether a native proposal is one plain replacement. The commit is a text
|
|
36
72
|
* replacement over the captured model, so this only has to tell DOM noise from a
|
|
@@ -142,7 +178,9 @@ const createCanonicalComposition = (options) => {
|
|
|
142
178
|
};
|
|
143
179
|
const replacement = (baseline, proposed) => {
|
|
144
180
|
const { $from, $to } = baseline.selection;
|
|
145
|
-
|
|
181
|
+
const fromDepth = textblockDepth($from);
|
|
182
|
+
const toDepth = textblockDepth($to);
|
|
183
|
+
if (fromDepth === void 0 || toDepth === void 0) return null;
|
|
146
184
|
const selected = selectedReplacement(baseline, proposed);
|
|
147
185
|
if (selected) {
|
|
148
186
|
if ($from.sameParent($to) && selected.text === baseline.doc.textBetween(selected.from, selected.to, "", "")) return {
|
|
@@ -153,12 +191,12 @@ const createCanonicalComposition = (options) => {
|
|
|
153
191
|
};
|
|
154
192
|
return selected;
|
|
155
193
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const changedFrom =
|
|
194
|
+
const paragraphStart = $from.start(fromDepth);
|
|
195
|
+
if (paragraphStart !== $to.start(toDepth)) return null;
|
|
196
|
+
const textblock = $from.node(fromDepth);
|
|
197
|
+
const proposedParagraph = proposed.doc.nodeAt(paragraphStart - 1);
|
|
198
|
+
if (!proposedParagraph || proposedParagraph.type !== textblock.type) return null;
|
|
199
|
+
const changedFrom = textblock.content.findDiffStart(proposedParagraph.content);
|
|
162
200
|
if (changedFrom === null) {
|
|
163
201
|
if (!baseline.doc.eq(proposed.doc)) return null;
|
|
164
202
|
return {
|
|
@@ -168,7 +206,7 @@ const createCanonicalComposition = (options) => {
|
|
|
168
206
|
semantic: "composition"
|
|
169
207
|
};
|
|
170
208
|
}
|
|
171
|
-
const changedEnd =
|
|
209
|
+
const changedEnd = textblock.content.findDiffEnd(proposedParagraph.content);
|
|
172
210
|
if (changedEnd === null) return null;
|
|
173
211
|
let from = changedFrom;
|
|
174
212
|
let oldEnd = changedEnd.a;
|
|
@@ -178,8 +216,23 @@ const createCanonicalComposition = (options) => {
|
|
|
178
216
|
oldEnd += overlap;
|
|
179
217
|
newEnd += overlap;
|
|
180
218
|
}
|
|
181
|
-
|
|
182
|
-
|
|
219
|
+
let start = paragraphStart;
|
|
220
|
+
let previous = textblock.content;
|
|
221
|
+
let next = proposedParagraph.content;
|
|
222
|
+
for (;;) {
|
|
223
|
+
const held = childAround(previous, from);
|
|
224
|
+
const read = childAround(next, from);
|
|
225
|
+
if (held === void 0 || read === void 0 || held.node.isText || held.node.isLeaf || held.offset !== read.offset || !held.node.sameMarkup(read.node) || from <= held.offset || oldEnd >= held.offset + held.node.nodeSize || newEnd >= read.offset + read.node.nodeSize) break;
|
|
226
|
+
const inner = held.offset + 1;
|
|
227
|
+
start += inner;
|
|
228
|
+
from -= inner;
|
|
229
|
+
oldEnd -= inner;
|
|
230
|
+
newEnd -= inner;
|
|
231
|
+
previous = held.node.content;
|
|
232
|
+
next = read.node.content;
|
|
233
|
+
}
|
|
234
|
+
const before = positionText(previous);
|
|
235
|
+
const after = positionText(next);
|
|
183
236
|
while (from < oldEnd && from < newEnd && before[from] === after[from]) from++;
|
|
184
237
|
while (oldEnd > from && newEnd > from && before[oldEnd - 1] === after[newEnd - 1]) {
|
|
185
238
|
oldEnd--;
|
|
@@ -191,7 +244,7 @@ const createCanonicalComposition = (options) => {
|
|
|
191
244
|
newEnd++;
|
|
192
245
|
}
|
|
193
246
|
const removed = previous.cut(from, oldEnd);
|
|
194
|
-
const inserted = next.
|
|
247
|
+
const inserted = next.cut(from, newEnd);
|
|
195
248
|
const text = inserted.textBetween(0, inserted.size, "", "");
|
|
196
249
|
if (removed.textBetween(0, removed.size, "", "").length !== removed.size || text.length !== inserted.size) return null;
|
|
197
250
|
if (!matchesNativeReplacement({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CanonicalSessionError } from "../canonical/canonicalSession.js";
|
|
2
2
|
import { ContentControlBoundError, ContentControlLockedError, ContentControlTypeError } from "../content-controls/errors.js";
|
|
3
3
|
import { setContentControlValue } from "../content-controls/mutateContentControls.js";
|
|
4
|
-
import {
|
|
4
|
+
import { CANONICAL_CONDITION, CANONICAL_RULE } from "../types/canonicalCapabilities.js";
|
|
5
5
|
import { readModel } from "../types/documentModel.js";
|
|
6
6
|
import { Result, panic } from "better-result";
|
|
7
7
|
import { DOCUMENT_OP_TYPES, blockControlHolding, storyBody } from "@stll/docx-core/ops";
|
|
@@ -14,35 +14,35 @@ import { DOCUMENT_OP_TYPES, blockControlHolding, storyBody } from "@stll/docx-co
|
|
|
14
14
|
* The headless content-control rules decide the new value: a lock, a type
|
|
15
15
|
* mismatch or a data binding refuses, and the refusal names its ground.
|
|
16
16
|
*/
|
|
17
|
-
const refuse = (message, ground
|
|
17
|
+
const refuse = (message, ground) => Result.err(new CanonicalSessionError({
|
|
18
18
|
ground,
|
|
19
19
|
message,
|
|
20
20
|
reason: "refused"
|
|
21
21
|
}));
|
|
22
22
|
const prepareContentControlValue = (session, state, command) => {
|
|
23
23
|
const node = session.projection.doc.nodeAt(command.at);
|
|
24
|
-
if (node?.type.name !== "blockSdt") return refuse("The content control is no longer there.");
|
|
24
|
+
if (node?.type.name !== "blockSdt") return refuse("The content control is no longer there.", { condition: CANONICAL_CONDITION.stale });
|
|
25
25
|
let paragraphsOnly = node.childCount > 0;
|
|
26
26
|
node.forEach((child) => {
|
|
27
27
|
if (child.type.name !== "paragraph") paragraphsOnly = false;
|
|
28
28
|
});
|
|
29
|
-
if (!paragraphsOnly) return refuse("A control that holds more than paragraphs has no value.");
|
|
29
|
+
if (!paragraphsOnly) return refuse("A control that holds more than paragraphs has no value.", { condition: CANONICAL_CONDITION.invalidRequest });
|
|
30
30
|
const from = session.projection.addressAt(command.at + 2);
|
|
31
31
|
if (from.isErr()) return from;
|
|
32
32
|
const to = session.projection.addressAt(command.at + node.nodeSize - 2);
|
|
33
33
|
if (to.isErr()) return to;
|
|
34
34
|
const document = readModel(session.document);
|
|
35
35
|
const held = blockControlHolding(storyBody(document, from.value.story).content, from.value.blockId);
|
|
36
|
-
if (held === void 0) return refuse("The content control is no longer there.");
|
|
36
|
+
if (held === void 0) return refuse("The content control is no longer there.", { condition: CANONICAL_CONDITION.stale });
|
|
37
37
|
const { control } = held;
|
|
38
38
|
const controlId = control.properties.id;
|
|
39
|
-
if (controlId === void 0) return refuse("A content control without an id cannot be set.");
|
|
39
|
+
if (controlId === void 0) return refuse("A content control without an id cannot be set.", { condition: CANONICAL_CONDITION.invalidRequest });
|
|
40
40
|
let next;
|
|
41
41
|
try {
|
|
42
42
|
next = setContentControlValue({ package: { document: { content: [control] } } }, { id: controlId }, command.input).package.document.content.at(0);
|
|
43
43
|
} catch (error) {
|
|
44
44
|
if (error instanceof ContentControlLockedError) return refuse(error.message, { rule: CANONICAL_RULE.contentControlLock });
|
|
45
|
-
if (error instanceof ContentControlTypeError || error instanceof ContentControlBoundError) return refuse(error.message);
|
|
45
|
+
if (error instanceof ContentControlTypeError || error instanceof ContentControlBoundError) return refuse(error.message, { condition: CANONICAL_CONDITION.invalidRequest });
|
|
46
46
|
throw error;
|
|
47
47
|
}
|
|
48
48
|
if (next?.type !== "blockSdt") return panic("A control's value keeps it a block-level control.");
|
|
@@ -1,4 +1,25 @@
|
|
|
1
1
|
import { FolioEditor } from "./folioEditor.js";
|
|
2
|
+
import { EditorState } from "prosemirror-state";
|
|
3
|
+
import { OpStory } from "@stll/docx-core/ops";
|
|
4
|
+
export type ReviewRange = {
|
|
5
|
+
from: number;
|
|
6
|
+
to: number;
|
|
7
|
+
};
|
|
8
|
+
export type CanonicalReviewEditor = Pick<FolioEditor, "getCanonicalStoryProjection" | "getDocument">;
|
|
9
|
+
type CanonicalReviewLockOptions = {
|
|
10
|
+
editor: CanonicalReviewEditor | null | undefined;
|
|
11
|
+
state: EditorState;
|
|
12
|
+
story: OpStory;
|
|
13
|
+
target: ({
|
|
14
|
+
type: "range";
|
|
15
|
+
} & ReviewRange) | {
|
|
16
|
+
type: "revisions";
|
|
17
|
+
ids: readonly number[];
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
type HeldReviewRevisionIds = Record<"accept" | "reject", ReadonlySet<number>>;
|
|
21
|
+
/** Predict the session's lock decision for the groups its review will settle. */
|
|
22
|
+
export declare const canonicalReviewHeldRevisionIds: ({ editor, state, story, target }: CanonicalReviewLockOptions) => HeldReviewRevisionIds;
|
|
2
23
|
type ResolveCanonicalReviewRangeOptions = {
|
|
3
24
|
editor: Pick<FolioEditor, "getCanonicalDocument" | "getState" | "resolveCanonicalRevisions"> | null | undefined;
|
|
4
25
|
from: number;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { getTrackedChangeGroupIdsFromDoc, getTrackedChangesFromDoc } from "../ai-edits/read.js";
|
|
2
|
-
import {
|
|
1
|
+
import { getTrackedChangeGroupIdsFromDoc, getTrackedChangeGroupsForIds, getTrackedChangesFromDoc } from "../ai-edits/read.js";
|
|
2
|
+
import { hasLockedControls } from "../canonical/canonicalLockGuard.js";
|
|
3
|
+
import { canonicalRevisionLocks } from "../canonical/canonicalRevisionLocks.js";
|
|
4
|
+
import { findAIEditRevisionRange } from "../prosemirror/revisionRangeQueries.js";
|
|
5
|
+
import { readModel } from "../types/documentModel.js";
|
|
6
|
+
import { OP_STORIES } from "@stll/docx-core/ops";
|
|
3
7
|
// src/controller/canonicalReview.ts
|
|
4
|
-
|
|
5
|
-
const resolveCanonicalReviewRange = ({ editor, from, to, resolution }) => {
|
|
6
|
-
if (!editor?.getCanonicalDocument()) return null;
|
|
7
|
-
const state = editor.getState();
|
|
8
|
-
if (!state) return false;
|
|
8
|
+
const revisionIdsAtRange = (state, { from, to }) => {
|
|
9
9
|
const ids = /* @__PURE__ */ new Set();
|
|
10
10
|
for (const change of getTrackedChangesFromDoc(state.doc)) {
|
|
11
11
|
const groupIds = getTrackedChangeGroupIdsFromDoc(state.doc, change.id);
|
|
@@ -13,6 +13,41 @@ const resolveCanonicalReviewRange = ({ editor, from, to, resolution }) => {
|
|
|
13
13
|
if (!range) continue;
|
|
14
14
|
if (from === to ? range.from <= from && range.to >= to : range.from < to && range.to > from) for (const id of groupIds) ids.add(id);
|
|
15
15
|
}
|
|
16
|
-
return
|
|
16
|
+
return [...ids];
|
|
17
|
+
};
|
|
18
|
+
const NO_HELD_REVISIONS = {
|
|
19
|
+
accept: /* @__PURE__ */ new Set(),
|
|
20
|
+
reject: /* @__PURE__ */ new Set()
|
|
21
|
+
};
|
|
22
|
+
/** Predict the session's lock decision for the groups its review will settle. */
|
|
23
|
+
const canonicalReviewHeldRevisionIds = ({ editor, state, story, target }) => {
|
|
24
|
+
if (!editor?.getCanonicalStoryProjection(OP_STORIES.MAIN)) return NO_HELD_REVISIONS;
|
|
25
|
+
const model = editor.getDocument();
|
|
26
|
+
if (!model) return NO_HELD_REVISIONS;
|
|
27
|
+
const document = readModel(model);
|
|
28
|
+
if (!hasLockedControls(document)) return NO_HELD_REVISIONS;
|
|
29
|
+
const ids = target.type === "range" ? revisionIdsAtRange(state, target) : target.ids;
|
|
30
|
+
const groups = getTrackedChangeGroupsForIds(state.doc, ids);
|
|
31
|
+
const heldIds = (decision) => new Set(canonicalRevisionLocks({
|
|
32
|
+
document,
|
|
33
|
+
story,
|
|
34
|
+
groups,
|
|
35
|
+
decision
|
|
36
|
+
}).held.flatMap((group) => group.ids));
|
|
37
|
+
return {
|
|
38
|
+
accept: heldIds("accept"),
|
|
39
|
+
reject: heldIds("reject")
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
/** Null when the editor holds no canonical session, which leaves the review as it is. */
|
|
43
|
+
const resolveCanonicalReviewRange = ({ editor, from, to, resolution }) => {
|
|
44
|
+
if (!editor?.getCanonicalDocument()) return null;
|
|
45
|
+
const state = editor.getState();
|
|
46
|
+
if (!state) return false;
|
|
47
|
+
const ids = revisionIdsAtRange(state, {
|
|
48
|
+
from,
|
|
49
|
+
to
|
|
50
|
+
});
|
|
51
|
+
return ids.length > 0 && editor.resolveCanonicalRevisions(ids, resolution);
|
|
17
52
|
};
|
|
18
|
-
export { resolveCanonicalReviewRange };
|
|
53
|
+
export { canonicalReviewHeldRevisionIds, resolveCanonicalReviewRange };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CanonicalSessionError } from "../canonical/canonicalSession.js";
|
|
2
|
+
import { retainMarkupViewSource } from "../prosemirror/conversion/markupViewSource.js";
|
|
2
3
|
import { adoptNativeSelection, isCompositionKeyDown } from "../prosemirror/nativeSelection.js";
|
|
3
4
|
import { CANONICAL_CONDITION } from "../types/canonicalCapabilities.js";
|
|
4
5
|
import { createCanonicalInputBoundary, unclassifiedMutationMessage } from "./canonicalInput.js";
|
|
@@ -116,6 +117,7 @@ const createCanonicalStoryEditor = ({ story, getView, getApi, onRefusal, onSelec
|
|
|
116
117
|
view.updateState(view.state);
|
|
117
118
|
return;
|
|
118
119
|
}
|
|
120
|
+
retainMarkupViewSource(view.state, applied.state);
|
|
119
121
|
view.updateState(applied.state);
|
|
120
122
|
if (applied.transactions.some((step) => step.selectionSet)) {
|
|
121
123
|
getApi()?.noteCanonicalStoryView({
|
|
@@ -5,14 +5,13 @@ import { CanonicalStructureInput } from "./canonicalInput.js";
|
|
|
5
5
|
import { Result } from "better-result";
|
|
6
6
|
import { EditorState } from "prosemirror-state";
|
|
7
7
|
import { OpStory } from "@stll/docx-core/ops";
|
|
8
|
-
export declare const CELL_SELECTION_PLACEMENT_REFUSAL = "A note or table of contents goes at a caret, not over selected cells.";
|
|
9
8
|
/** Whether a paragraph is in a list, by numbering of its own or its style's. */
|
|
10
9
|
export declare const isCanonicalListParagraph: (paragraph: document_d_exports.Paragraph | undefined) => boolean;
|
|
11
10
|
/**
|
|
12
11
|
* Toolbar meanings enter the same operation journal as native input, in the
|
|
13
12
|
* story whose editor holds `state`: the body, or a header, footer or note.
|
|
14
13
|
*/
|
|
15
|
-
export declare const prepareCanonicalCommands: (session: CanonicalSession, state: EditorState,
|
|
14
|
+
export declare const prepareCanonicalCommands: (session: CanonicalSession, state: EditorState, requested: readonly CanonicalCommandIntent[], story?: OpStory) => Result<CanonicalCommit, CanonicalSessionError>;
|
|
16
15
|
/**
|
|
17
16
|
* The structure edit a key asks for at the selection of the editor showing
|
|
18
17
|
* `story`, the body or a header, footer or note, as one commit: Enter splits
|
|
@@ -4,11 +4,12 @@ import { createNote } from "../docx/noteReferenceMark.js";
|
|
|
4
4
|
import { getCachedNumberingMap, numberingLevelUsesBulletMarker } from "../docx/numberingParser.js";
|
|
5
5
|
import { cloneParagraphWithoutPropertySource } from "../docx/paragraphPropertySource.js";
|
|
6
6
|
import { visitDocxParagraphs } from "../docx/paragraphTraversal.js";
|
|
7
|
+
import { canonicalCellSelectionRanges } from "../prosemirror/canonicalSelectionRange.js";
|
|
7
8
|
import { listRequestsForMarker } from "../prosemirror/listAutoformatMarkers.js";
|
|
8
9
|
import { unusedListInstanceFor } from "../prosemirror/listNumbering.js";
|
|
9
10
|
import { effectiveParagraphNumbering, paragraphNumberingSourcesFromBoundary } from "../prosemirror/numberingAttr.js";
|
|
10
11
|
import { createStyleResolver } from "../prosemirror/styles/styleResolver.js";
|
|
11
|
-
import { CANONICAL_CONDITION
|
|
12
|
+
import { CANONICAL_CONDITION } from "../types/canonicalCapabilities.js";
|
|
12
13
|
import { readModel } from "../types/documentModel.js";
|
|
13
14
|
import { maxOf } from "../utils/extremes.js";
|
|
14
15
|
import { collectHeadings } from "../utils/headingCollector.js";
|
|
@@ -31,14 +32,14 @@ const currentSectionEndpoint = (paragraph) => {
|
|
|
31
32
|
if (Object.hasOwn(paragraph, "sectionProperties")) return { type: "undefined" };
|
|
32
33
|
return { type: "omitted" };
|
|
33
34
|
};
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
ground: { gap: CANONICAL_GAP.commands },
|
|
35
|
+
const refuse = (message, condition) => Result.err(new CanonicalSessionError({
|
|
36
|
+
ground: { condition },
|
|
37
37
|
message,
|
|
38
38
|
reason: "refused"
|
|
39
39
|
}));
|
|
40
|
+
/** The request asks for nothing to change; hosts report no refusal for it. */
|
|
40
41
|
const noChange = (message) => Result.err(new CanonicalSessionError({
|
|
41
|
-
ground: {
|
|
42
|
+
ground: { condition: CANONICAL_CONDITION.invalidRequest },
|
|
42
43
|
message,
|
|
43
44
|
reason: "noChange"
|
|
44
45
|
}));
|
|
@@ -78,9 +79,9 @@ const paragraphPositions = (projection, paragraphs) => {
|
|
|
78
79
|
const positions = [];
|
|
79
80
|
for (const paragraph of paragraphs) {
|
|
80
81
|
const address = projection.paragraph(paragraph.paraId ?? "");
|
|
81
|
-
if (address === void 0) return refuse("A selected paragraph has no canonical address.");
|
|
82
|
+
if (address === void 0) return refuse("A selected paragraph has no canonical address.", CANONICAL_CONDITION.stale);
|
|
82
83
|
const index = address.container.findIndex((item) => item === paragraph);
|
|
83
|
-
if (index < 0) return refuse("A selected paragraph is missing from its block container.");
|
|
84
|
+
if (index < 0) return refuse("A selected paragraph is missing from its block container.", CANONICAL_CONDITION.stale);
|
|
84
85
|
positions.push({
|
|
85
86
|
container: address.container,
|
|
86
87
|
index,
|
|
@@ -190,21 +191,48 @@ const numberingIntent = (session, positions, request, story = OP_STORIES.MAIN) =
|
|
|
190
191
|
};
|
|
191
192
|
};
|
|
192
193
|
/**
|
|
194
|
+
* Note and contents commands over selected cells, placed as over the text
|
|
195
|
+
* they hold: a note reference follows the selected text, at the end of the
|
|
196
|
+
* last selected cell's text; a table of contents goes where the selection
|
|
197
|
+
* starts, at the start of the first selected cell's text. A note reference is
|
|
198
|
+
* deleted only from a selected cell, not from a cell the range passes over.
|
|
199
|
+
*/
|
|
200
|
+
const placeInSelectedCells = (state, commands) => {
|
|
201
|
+
const { selection } = state;
|
|
202
|
+
if (!(selection instanceof CellSelection)) return commands;
|
|
203
|
+
const ranges = canonicalCellSelectionRanges(selection);
|
|
204
|
+
const first = ranges.at(0);
|
|
205
|
+
const last = ranges.at(-1);
|
|
206
|
+
if ((first === void 0 || last === void 0) && commands.some(({ type }) => type === "insertNote" || type === "generateTOC")) return null;
|
|
207
|
+
return commands.flatMap((command) => {
|
|
208
|
+
switch (command.type) {
|
|
209
|
+
case "insertNote": return last === void 0 ? [] : [{
|
|
210
|
+
...command,
|
|
211
|
+
at: last.to
|
|
212
|
+
}];
|
|
213
|
+
case "generateTOC": return first === void 0 ? [] : [{
|
|
214
|
+
...command,
|
|
215
|
+
at: first.from
|
|
216
|
+
}];
|
|
217
|
+
case "deleteNote": return ranges.some(({ from, to }) => from <= command.from && command.from <= to) ? [command] : [];
|
|
218
|
+
default: return [command];
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
/**
|
|
193
223
|
* Toolbar meanings enter the same operation journal as native input, in the
|
|
194
224
|
* story whose editor holds `state`: the body, or a header, footer or note.
|
|
195
225
|
*/
|
|
196
|
-
const prepareCanonicalCommands = (session, state,
|
|
197
|
-
if (story !== OP_STORIES.MAIN &&
|
|
198
|
-
ground: { condition: CANONICAL_CONDITION.invalidRequest },
|
|
199
|
-
message: "Section breaks, notes and tables of contents go in the main story.",
|
|
200
|
-
reason: "refused"
|
|
201
|
-
}));
|
|
226
|
+
const prepareCanonicalCommands = (session, state, requested, story = OP_STORIES.MAIN) => {
|
|
227
|
+
if (story !== OP_STORIES.MAIN && requested.some(({ type }) => type === "setSectionBreak" || type === "removeSectionBreak" || type === "insertNote" || type === "deleteNote" || type === "generateTOC")) return refuse("Section breaks, notes and tables of contents go in the main story.", CANONICAL_CONDITION.invalidRequest);
|
|
202
228
|
const projected = session.projectStory(story);
|
|
203
229
|
if (projected.isErr()) return projected;
|
|
204
230
|
const projection = projected.value;
|
|
231
|
+
const commands = placeInSelectedCells(state, requested);
|
|
232
|
+
if (commands === null) return refuse("The selected cells hold no text for a note or a table of contents.", CANONICAL_CONDITION.invalidRequest);
|
|
205
233
|
const replacements = commands.filter((command) => command.type === "replaceText");
|
|
206
234
|
if (replacements.length > 0) {
|
|
207
|
-
if (replacements.length !== commands.length) return refuse("A text replacement must be prepared on its own.");
|
|
235
|
+
if (replacements.length !== commands.length) return refuse("A text replacement must be prepared on its own.", CANONICAL_CONDITION.invalidRequest);
|
|
208
236
|
const [only] = replacements;
|
|
209
237
|
if (only !== void 0 && replacements.length === 1) return session.prepareReplace(state, {
|
|
210
238
|
from: only.from,
|
|
@@ -228,19 +256,18 @@ const prepareCanonicalCommands = (session, state, commands, story = OP_STORIES.M
|
|
|
228
256
|
}
|
|
229
257
|
return session.prepareIntents(state, { intents });
|
|
230
258
|
}
|
|
231
|
-
if (state.selection instanceof CellSelection && commands.some(({ type }) => type === "generateTOC" || type === "insertNote" || type === "deleteNote")) return refuse(CELL_SELECTION_PLACEMENT_REFUSAL);
|
|
232
259
|
const intents = [];
|
|
233
260
|
const valueCommands = commands.filter((command) => command.type === "setContentControlValue");
|
|
234
261
|
if (valueCommands.length > 0) {
|
|
235
262
|
const [valueCommand] = valueCommands;
|
|
236
|
-
if (valueCommand === void 0 || commands.length !== 1) return refuse("A content control's value must be set on its own.");
|
|
263
|
+
if (valueCommand === void 0 || commands.length !== 1) return refuse("A content control's value must be set on its own.", CANONICAL_CONDITION.invalidRequest);
|
|
237
264
|
return prepareContentControlValue(session, state, valueCommand);
|
|
238
265
|
}
|
|
239
266
|
const sectionCommands = commands.filter((command) => command.type === "setSectionBreak" || command.type === "removeSectionBreak");
|
|
240
267
|
if (sectionCommands.length > 0) {
|
|
241
|
-
if (sectionCommands.length !== commands.length || sectionCommands.length !== 1) return refuse("A section change must be prepared on its own.");
|
|
268
|
+
if (sectionCommands.length !== commands.length || sectionCommands.length !== 1) return refuse("A section change must be prepared on its own.", CANONICAL_CONDITION.invalidRequest);
|
|
242
269
|
const paragraphs = selectedParagraphs(projection, state, true);
|
|
243
|
-
if (paragraphs.length === 0) return refuse("Section breaks require a top-level document paragraph.");
|
|
270
|
+
if (paragraphs.length === 0) return refuse("Section breaks require a top-level document paragraph.", CANONICAL_CONDITION.invalidRequest);
|
|
244
271
|
const command = sectionCommands.at(0) ?? panic("A section command was counted.");
|
|
245
272
|
return session.prepareOperations(state, paragraphs.map((paragraph) => {
|
|
246
273
|
const current = paragraph.sectionProperties;
|
|
@@ -265,7 +292,7 @@ const prepareCanonicalCommands = (session, state, commands, story = OP_STORIES.M
|
|
|
265
292
|
const paragraphs = selectedParagraphs(projection, state);
|
|
266
293
|
const noteCommands = commands.filter((command) => command.type === "insertNote" || command.type === "deleteNote");
|
|
267
294
|
if (noteCommands.length > 0) {
|
|
268
|
-
if (noteCommands.length !== commands.length) return refuse("Note changes must be prepared on their own.");
|
|
295
|
+
if (noteCommands.length !== commands.length) return refuse("Note changes must be prepared on their own.", CANONICAL_CONDITION.invalidRequest);
|
|
269
296
|
const ops = [];
|
|
270
297
|
const ordered = noteCommands.toReversed();
|
|
271
298
|
const blockIdGroups = session.freshBlockIds(ordered.map((command) => command.type === "insertNote" ? command.content.length : 0));
|
|
@@ -286,7 +313,7 @@ const prepareCanonicalCommands = (session, state, commands, story = OP_STORIES.M
|
|
|
286
313
|
}
|
|
287
314
|
const at = projection.addressAt(command.at);
|
|
288
315
|
if (at.isErr()) return at;
|
|
289
|
-
if (command.content.some((block) => block.type !== "paragraph")) return refuse("Canonical note insertion requires paragraph content.");
|
|
316
|
+
if (command.content.some((block) => block.type !== "paragraph")) return refuse("Canonical note insertion requires paragraph content.", CANONICAL_CONDITION.invalidRequest);
|
|
290
317
|
const blockIds = blockIdGroups.value[commandIndex] ?? panic("A fresh identity group was reserved per note.");
|
|
291
318
|
const content = command.content.map((block, index) => {
|
|
292
319
|
if (block.type !== "paragraph") panic("Canonical note content was already validated.");
|
|
@@ -311,7 +338,7 @@ const prepareCanonicalCommands = (session, state, commands, story = OP_STORIES.M
|
|
|
311
338
|
const address = projection.addressAt(heading.pmPos + 1);
|
|
312
339
|
if (address.isErr()) return address;
|
|
313
340
|
const outline = headingOutlineLevel(heading.level);
|
|
314
|
-
if (outline?.kind !== "heading") return refuse("A TOC heading has an invalid outline level.");
|
|
341
|
+
if (outline?.kind !== "heading") return refuse("A TOC heading has an invalid outline level.", CANONICAL_CONDITION.invalidRequest);
|
|
315
342
|
const styleId = styles.styleIdForTableOfContentsLevel(outline.level + 1);
|
|
316
343
|
headings.push({
|
|
317
344
|
blockId: address.value.blockId,
|
|
@@ -580,9 +607,9 @@ const prepareCanonicalCommands = (session, state, commands, story = OP_STORIES.M
|
|
|
580
607
|
};
|
|
581
608
|
} else {
|
|
582
609
|
const start = command.start ?? 1;
|
|
583
|
-
if (!Number.isSafeInteger(start) || start < 0) return refuse("The numbering start must be a non-negative integer.");
|
|
610
|
+
if (!Number.isSafeInteger(start) || start < 0) return refuse("The numbering start must be a non-negative integer.", CANONICAL_CONDITION.invalidRequest);
|
|
584
611
|
const original = definitions.nums.find((num) => num.numId === numPr.numId);
|
|
585
|
-
if (original === void 0) return refuse("The numbering instance does not exist.");
|
|
612
|
+
if (original === void 0) return refuse("The numbering instance does not exist.", CANONICAL_CONDITION.invalidRequest);
|
|
586
613
|
targetId = maxOf(definitions.nums.map((num) => num.numId), 0) + 1;
|
|
587
614
|
const level = numPr.ilvl ?? 0;
|
|
588
615
|
target = {
|
|
@@ -753,4 +780,4 @@ const prepareCanonicalAutoformat = (session, state, typed) => {
|
|
|
753
780
|
text: ""
|
|
754
781
|
}, paragraphIntent] });
|
|
755
782
|
};
|
|
756
|
-
export {
|
|
783
|
+
export { isCanonicalListParagraph, prepareCanonicalAutoformat, prepareCanonicalCommands, prepareCanonicalStructure };
|
|
@@ -124,8 +124,20 @@ function waitForInitialLayoutFonts(model, pmDoc, fontSet = getDocumentFontSet())
|
|
|
124
124
|
*/
|
|
125
125
|
function collectLayoutText(documentModel, pmDoc) {
|
|
126
126
|
const characters = /* @__PURE__ */ new Set([" "]);
|
|
127
|
+
const seenUnits = /* @__PURE__ */ new Uint8Array(65536);
|
|
128
|
+
seenUnits[32] = 1;
|
|
127
129
|
const addText = (text) => {
|
|
128
|
-
for (
|
|
130
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
131
|
+
const unit = text.charCodeAt(index);
|
|
132
|
+
if (isHighSurrogate(unit) && isLowSurrogate(text.charCodeAt(index + 1))) {
|
|
133
|
+
characters.add(text.slice(index, index + 2));
|
|
134
|
+
index += 1;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (unit < 32 || seenUnits[unit] === 1) continue;
|
|
138
|
+
seenUnits[unit] = 1;
|
|
139
|
+
characters.add(String.fromCharCode(unit));
|
|
140
|
+
}
|
|
129
141
|
};
|
|
130
142
|
pmDoc.descendants((node) => {
|
|
131
143
|
if (node.isText) addText(node.text ?? "");
|
|
@@ -148,7 +160,9 @@ function collectInitialLayoutFontFaces(documentModel, pmDoc) {
|
|
|
148
160
|
const faces = /* @__PURE__ */ new Map();
|
|
149
161
|
const resolution = {
|
|
150
162
|
fontAlternates: buildFontAlternates(documentModel?.package.fontTable),
|
|
151
|
-
documentFontFacts: buildDocumentFontFacts(documentModel?.package.fontTable)
|
|
163
|
+
documentFontFacts: buildDocumentFontFacts(documentModel?.package.fontTable),
|
|
164
|
+
resolvedFamilies: /* @__PURE__ */ new Map(),
|
|
165
|
+
requested: /* @__PURE__ */ new Set()
|
|
152
166
|
};
|
|
153
167
|
addLayoutFontFamilyFace({
|
|
154
168
|
faces,
|
|
@@ -261,14 +275,13 @@ function layoutDescriptorFromFormattingAndMarks(formatting, marks) {
|
|
|
261
275
|
weight: bold ? 700 : 400
|
|
262
276
|
};
|
|
263
277
|
}
|
|
264
|
-
function addLayoutFontFamilyFace({ faces, value, descriptor,
|
|
278
|
+
function addLayoutFontFamilyFace({ faces, value, descriptor, complexScriptDescriptor = descriptor, ...resolution }) {
|
|
265
279
|
if (typeof value === "string") {
|
|
266
280
|
addLayoutFontFamilyNameFace({
|
|
267
281
|
faces,
|
|
268
282
|
family: value,
|
|
269
283
|
descriptor,
|
|
270
|
-
|
|
271
|
-
documentFontFacts
|
|
284
|
+
...resolution
|
|
272
285
|
});
|
|
273
286
|
return;
|
|
274
287
|
}
|
|
@@ -278,42 +291,54 @@ function addLayoutFontFamilyFace({ faces, value, descriptor, fontAlternates, doc
|
|
|
278
291
|
faces,
|
|
279
292
|
value: fontFamily.ascii,
|
|
280
293
|
descriptor,
|
|
281
|
-
|
|
282
|
-
documentFontFacts
|
|
294
|
+
...resolution
|
|
283
295
|
});
|
|
284
296
|
addLayoutFontFamilyFace({
|
|
285
297
|
faces,
|
|
286
298
|
value: fontFamily.hAnsi,
|
|
287
299
|
descriptor,
|
|
288
|
-
|
|
289
|
-
documentFontFacts
|
|
300
|
+
...resolution
|
|
290
301
|
});
|
|
291
302
|
addLayoutFontFamilyFace({
|
|
292
303
|
faces,
|
|
293
304
|
value: fontFamily.cs,
|
|
294
305
|
descriptor: complexScriptDescriptor,
|
|
295
|
-
|
|
296
|
-
documentFontFacts
|
|
306
|
+
...resolution
|
|
297
307
|
});
|
|
298
308
|
addLayoutFontFamilyFace({
|
|
299
309
|
faces,
|
|
300
310
|
value: fontFamily.eastAsia,
|
|
301
311
|
descriptor,
|
|
302
|
-
|
|
303
|
-
documentFontFacts
|
|
312
|
+
...resolution
|
|
304
313
|
});
|
|
305
314
|
}
|
|
306
|
-
function addLayoutFontFamilyNameFace({ faces, family, descriptor,
|
|
315
|
+
function addLayoutFontFamilyNameFace({ faces, family, descriptor, ...resolution }) {
|
|
316
|
+
const request = `${family}|${descriptor.style}|${descriptor.weight}`;
|
|
317
|
+
if (resolution.requested.has(request)) return;
|
|
318
|
+
resolution.requested.add(request);
|
|
319
|
+
for (const resolved of resolveLayoutFamilies(family, resolution)) addLayoutFontFace(faces, resolved, descriptor);
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* The families an authored name loads: the name, its alternate and the stack
|
|
323
|
+
* the renderer resolves it to, or none for a blank or generic name.
|
|
324
|
+
*/
|
|
325
|
+
function resolveLayoutFamilies(family, resolution) {
|
|
326
|
+
const known = resolution.resolvedFamilies.get(family);
|
|
327
|
+
if (known !== void 0) return known;
|
|
307
328
|
const normalized = family.trim();
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
329
|
+
const resolved = [];
|
|
330
|
+
if (normalized && !CSS_GENERIC_FONT_FAMILIES.has(normalized)) {
|
|
331
|
+
resolved.push(normalized);
|
|
332
|
+
const alternate = getFontAlternate(normalized, resolution.fontAlternates);
|
|
333
|
+
if (alternate) resolved.push(alternate);
|
|
334
|
+
resolved.push(...resolvedStackFamilies({
|
|
335
|
+
family: normalized,
|
|
336
|
+
alternate,
|
|
337
|
+
documentFontFacts: resolution.documentFontFacts
|
|
338
|
+
}));
|
|
339
|
+
}
|
|
340
|
+
resolution.resolvedFamilies.set(family, resolved);
|
|
341
|
+
return resolved;
|
|
317
342
|
}
|
|
318
343
|
function resolvedStackFamilies({ family, alternate, documentFontFacts }) {
|
|
319
344
|
const { cssFallback } = resolveFontFamily(family, {
|
|
@@ -328,6 +353,8 @@ function addLayoutFontFace(faces, family, descriptor) {
|
|
|
328
353
|
...descriptor
|
|
329
354
|
});
|
|
330
355
|
}
|
|
356
|
+
const isHighSurrogate = (unit) => unit >= 55296 && unit <= 56319;
|
|
357
|
+
const isLowSurrogate = (unit) => unit >= 56320 && unit <= 57343;
|
|
331
358
|
function escapeCssFontFamily(family) {
|
|
332
359
|
return family.replace(/\\/gu, "\\\\").replace(/"/gu, "\\\"");
|
|
333
360
|
}
|