@superdoc/mcp 1.2.1-next.3 → 1.2.1-next.4
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/index.js +989 -781
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -31314,7 +31314,7 @@ var init_host = __esm(() => {
|
|
|
31314
31314
|
});
|
|
31315
31315
|
|
|
31316
31316
|
// ../../packages/sdk/langs/node/src/runtime/sdk-version.generated.ts
|
|
31317
|
-
var SDK_VERSION = "2.15.1-next.
|
|
31317
|
+
var SDK_VERSION = "2.15.1-next.4";
|
|
31318
31318
|
|
|
31319
31319
|
// ../../packages/sdk/langs/node/src/runtime/embedded-platform.ts
|
|
31320
31320
|
import { chmodSync, existsSync } from "node:fs";
|
|
@@ -118889,6 +118889,11 @@ function validateId(id, operationName) {
|
|
|
118889
118889
|
});
|
|
118890
118890
|
}
|
|
118891
118891
|
}
|
|
118892
|
+
function validateContentControlId(id, operationName) {
|
|
118893
|
+
if (id !== undefined && (typeof id !== "string" || id.length === 0)) {
|
|
118894
|
+
throw new DocumentApiValidationError("INVALID_INPUT", `${operationName} requires a non-empty 'contentControlId' string when provided.`);
|
|
118895
|
+
}
|
|
118896
|
+
}
|
|
118892
118897
|
function validateNamespace(namespace, operationName) {
|
|
118893
118898
|
if (typeof namespace !== "string" || namespace.length === 0) {
|
|
118894
118899
|
throw new DocumentApiValidationError("INVALID_INPUT", `${operationName} requires a non-empty 'namespace' string.`, {
|
|
@@ -118956,6 +118961,14 @@ function executeAnchoredMetadataList(adapter, query2) {
|
|
|
118956
118961
|
}
|
|
118957
118962
|
function executeAnchoredMetadataGet(adapter, input) {
|
|
118958
118963
|
validateId(input.id, "metadata.get");
|
|
118964
|
+
validateContentControlId(input.contentControlId, "metadata.get");
|
|
118965
|
+
if (input.contentControlId !== undefined) {
|
|
118966
|
+
if (input.story === undefined)
|
|
118967
|
+
return null;
|
|
118968
|
+
validateStoryLocator(input.story, "metadata.get.story");
|
|
118969
|
+
if (input.story.storyType !== "body")
|
|
118970
|
+
return null;
|
|
118971
|
+
}
|
|
118959
118972
|
return adapter.get(input);
|
|
118960
118973
|
}
|
|
118961
118974
|
function executeAnchoredMetadataUpdate(adapter, input, options) {
|
|
@@ -118969,6 +118982,14 @@ function executeAnchoredMetadataRemove(adapter, input, options) {
|
|
|
118969
118982
|
}
|
|
118970
118983
|
function executeAnchoredMetadataResolve(adapter, input) {
|
|
118971
118984
|
validateId(input.id, "metadata.resolve");
|
|
118985
|
+
validateContentControlId(input.contentControlId, "metadata.resolve");
|
|
118986
|
+
if (input.contentControlId !== undefined) {
|
|
118987
|
+
if (input.story === undefined)
|
|
118988
|
+
return null;
|
|
118989
|
+
validateStoryLocator(input.story, "metadata.resolve.story");
|
|
118990
|
+
if (input.story.storyType !== "body")
|
|
118991
|
+
return null;
|
|
118992
|
+
}
|
|
118972
118993
|
return adapter.resolve(input);
|
|
118973
118994
|
}
|
|
118974
118995
|
var init_anchored_metadata = __esm(() => {
|
|
@@ -118976,6 +118997,7 @@ var init_anchored_metadata = __esm(() => {
|
|
|
118976
118997
|
init_errors5();
|
|
118977
118998
|
init_selection_target_validator();
|
|
118978
118999
|
init_validation_primitives();
|
|
119000
|
+
init_story_validator();
|
|
118979
119001
|
});
|
|
118980
119002
|
|
|
118981
119003
|
// ../../packages/document-api/dist/protection/protection.js
|
|
@@ -209802,7 +209824,7 @@ function planCut(pieces, levelStart, input, rootPieces, chain = []) {
|
|
|
209802
209824
|
if (strict.kind === "container" && strict.containerKind === "sdt" && input.allowMetadataAnchorSplit) {
|
|
209803
209825
|
if (input.space === "tracked")
|
|
209804
209826
|
return { kind: "reject", reason: "paragraph-split-point-unsupported" };
|
|
209805
|
-
const chunks = anchoredMetadataChunks(strict, input.allocateWId);
|
|
209827
|
+
const chunks = anchoredMetadataChunks(strict, input.allocateWId, input.knownMetadataAnchorIds, input.onMetadataAnchorClone);
|
|
209806
209828
|
if (!chunks)
|
|
209807
209829
|
return { kind: "reject", reason: "paragraph-split-point-unsupported" };
|
|
209808
209830
|
return planCut(strict.children, chunks.contentStart, input, rootPieces, [
|
|
@@ -209858,7 +209880,7 @@ function wrapperChunks(piece) {
|
|
|
209858
209880
|
contentStart: piece.charStart + openEnd
|
|
209859
209881
|
};
|
|
209860
209882
|
}
|
|
209861
|
-
function anchoredMetadataChunks(piece, allocateWId) {
|
|
209883
|
+
function anchoredMetadataChunks(piece, allocateWId, knownMetadataAnchorIds, onMetadataAnchorClone) {
|
|
209862
209884
|
if (piece.children.length === 0)
|
|
209863
209885
|
return null;
|
|
209864
209886
|
const raw = piece.rawXml;
|
|
@@ -209872,16 +209894,23 @@ function anchoredMetadataChunks(piece, allocateWId) {
|
|
|
209872
209894
|
const originalId = /<w:id w:val="\d+"\s*\/>/.exec(properties)?.[0];
|
|
209873
209895
|
const alias = '<w:alias w:val="Anchored metadata"/>';
|
|
209874
209896
|
const tag = /<w:tag w:val="[^"]+"\/>/.exec(normalizedProperties)?.[0];
|
|
209897
|
+
const tagValue = tag ? /w:val="([^"]+)"/.exec(tag)?.[1] : null;
|
|
209875
209898
|
const appearance = '<w15:appearance w15:val="hidden"/>';
|
|
209876
209899
|
const plainText = "<w:text/>";
|
|
209877
|
-
|
|
209900
|
+
const canonical = `<w:sdtPr>${id}${alias}${tag}${appearance}${plainText}</w:sdtPr>`;
|
|
209901
|
+
const legacy = `<w:sdtPr>${id}${tag}${appearance}${plainText}</w:sdtPr>`;
|
|
209902
|
+
if (!id || !originalId || !tag || !tagValue || !knownMetadataAnchorIds?.has(decodeXmlAttributeValue(tagValue)) || !normalizedProperties.includes(appearance) || !normalizedProperties.includes(plainText) || normalizedProperties !== canonical && !(normalizedProperties === legacy && knownMetadataAnchorIds?.has(decodeXmlAttributeValue(tagValue)))) {
|
|
209878
209903
|
return null;
|
|
209879
209904
|
}
|
|
209880
209905
|
const originalPrefix = prefix[0];
|
|
209881
209906
|
return {
|
|
209882
209907
|
contentStart: piece.charStart + originalPrefix.length,
|
|
209883
209908
|
close,
|
|
209884
|
-
reopen: () =>
|
|
209909
|
+
reopen: () => {
|
|
209910
|
+
const cloneId = String(allocateWId());
|
|
209911
|
+
onMetadataAnchorClone?.(decodeXmlAttributeValue(tagValue), /\d+/.exec(originalId)[0], cloneId);
|
|
209912
|
+
return originalPrefix.replace(originalId, originalId.replace(/(w:val=")\d+/, (_match, attribute) => `${attribute}${cloneId}`));
|
|
209913
|
+
}
|
|
209885
209914
|
};
|
|
209886
209915
|
}
|
|
209887
209916
|
function openTagEnd(raw) {
|
|
@@ -214176,7 +214205,9 @@ function prepareParagraphSplit(input) {
|
|
|
214176
214205
|
space: input.coordinateSpace,
|
|
214177
214206
|
allocateWId: input.allocateWId,
|
|
214178
214207
|
atomicObjectsAsCaretSlots: true,
|
|
214179
|
-
allowMetadataAnchorSplit: true
|
|
214208
|
+
allowMetadataAnchorSplit: true,
|
|
214209
|
+
knownMetadataAnchorIds: new Set(input.knownMetadataAnchorIds),
|
|
214210
|
+
onMetadataAnchorClone: input.onMetadataAnchorClone
|
|
214180
214211
|
});
|
|
214181
214212
|
if (!slice.ok)
|
|
214182
214213
|
return slice;
|
|
@@ -214211,6 +214242,64 @@ function renderPreparedParagraphSplit(split, trackedStamp) {
|
|
|
214211
214242
|
const head = trackedStamp ? injectParagraphMarkTrackedMarker(split.headXml, "ins", trackedStamp) : split.headXml;
|
|
214212
214243
|
return head + split.tailXml;
|
|
214213
214244
|
}
|
|
214245
|
+
function prepareMetadataSplitStorage(state, bindings, clones) {
|
|
214246
|
+
const perPart = {};
|
|
214247
|
+
const preconditions = [];
|
|
214248
|
+
const parts = new Map;
|
|
214249
|
+
for (const clone3 of clones) {
|
|
214250
|
+
const binding = bindings?.find((candidate2) => candidate2.id === clone3.id);
|
|
214251
|
+
if (!binding || binding.physicalIds && !binding.physicalIds.includes(clone3.originalId))
|
|
214252
|
+
return { ok: false };
|
|
214253
|
+
const entries = parts.get(binding.partUri) ?? [];
|
|
214254
|
+
entries.push({ ...clone3, physicalIds: binding.physicalIds });
|
|
214255
|
+
parts.set(binding.partUri, entries);
|
|
214256
|
+
}
|
|
214257
|
+
for (const [partUri, entries] of parts) {
|
|
214258
|
+
const bytes = state.packageBytes.get(partUri);
|
|
214259
|
+
if (!bytes)
|
|
214260
|
+
return { ok: false };
|
|
214261
|
+
let xml = TD51.decode(bytes);
|
|
214262
|
+
const updatedIds = new Map;
|
|
214263
|
+
for (const entry of entries) {
|
|
214264
|
+
let matched = 0;
|
|
214265
|
+
let updated = 0;
|
|
214266
|
+
xml = xml.replace(/<ref\b[^>]*>/g, (tag) => {
|
|
214267
|
+
const rawId = /\bid="([^"]*)"/.exec(tag)?.[1];
|
|
214268
|
+
if (rawId === undefined || decodeXmlAttributeValue(rawId) !== entry.id)
|
|
214269
|
+
return tag;
|
|
214270
|
+
matched += 1;
|
|
214271
|
+
const bindingAttributes = [...tag.matchAll(/\bsdAnchorIdsV1\s*=\s*(['"])(.*?)\1/g)];
|
|
214272
|
+
const currentIds = updatedIds.get(entry.id);
|
|
214273
|
+
if (bindingAttributes.length > 1 || bindingAttributes.length === 0 && /\bsdAnchorIdsV1\b/.test(tag))
|
|
214274
|
+
return tag;
|
|
214275
|
+
const rawIds = bindingAttributes[0]?.[2];
|
|
214276
|
+
if (rawIds !== undefined && decodeXmlAttributeValue(rawIds) !== (currentIds ?? entry.physicalIds)?.join(","))
|
|
214277
|
+
return tag;
|
|
214278
|
+
if (rawIds === undefined && (entry.physicalIds || currentIds))
|
|
214279
|
+
return tag;
|
|
214280
|
+
const ids = currentIds ?? entry.physicalIds ?? [entry.originalId];
|
|
214281
|
+
if (ids.includes(entry.cloneId))
|
|
214282
|
+
return tag;
|
|
214283
|
+
const attribute = `sdAnchorIdsV1="${[...ids, entry.cloneId].join(",")}"`;
|
|
214284
|
+
updatedIds.set(entry.id, [...ids, entry.cloneId]);
|
|
214285
|
+
updated += 1;
|
|
214286
|
+
return rawIds === undefined ? tag.replace(/>$/, ` ${attribute}>`) : tag.replace(bindingAttributes[0][0], attribute);
|
|
214287
|
+
});
|
|
214288
|
+
if (matched !== 1 || updated !== 1)
|
|
214289
|
+
return { ok: false };
|
|
214290
|
+
}
|
|
214291
|
+
const patches = [{
|
|
214292
|
+
kind: "replaceBytes",
|
|
214293
|
+
order: 0,
|
|
214294
|
+
startByte: 0,
|
|
214295
|
+
endByte: bytes.length,
|
|
214296
|
+
bytes: TE24.encode(xml)
|
|
214297
|
+
}];
|
|
214298
|
+
perPart[partUri] = { kind: "modify", patches };
|
|
214299
|
+
preconditions.push(localizedByteWindowPrecondition2(partUri, bytes, patches));
|
|
214300
|
+
}
|
|
214301
|
+
return { ok: true, perPart, preconditions };
|
|
214302
|
+
}
|
|
214214
214303
|
function runParagraphSplitCommit(input) {
|
|
214215
214304
|
const op = input.op;
|
|
214216
214305
|
if (input.options.expectedPackageRevision && input.options.expectedPackageRevision !== input.state.packageRevision) {
|
|
@@ -214226,12 +214315,15 @@ function runParagraphSplitCommit(input) {
|
|
|
214226
214315
|
const provisionalParaId = op.provisionalParaId ?? mintParaId(input.state, input.state.packageRevision, target.entry.ordinal + 1);
|
|
214227
214316
|
const tailParaId = provisionalParaId;
|
|
214228
214317
|
const splitAllocatedWIds = [];
|
|
214318
|
+
const metadataClones = [];
|
|
214229
214319
|
const primarySplit = prepareParagraphSplit({
|
|
214230
214320
|
paragraphXml: paraXml,
|
|
214231
214321
|
partBytes: bytes,
|
|
214232
214322
|
paragraphByteStart: target.entry.byteStart,
|
|
214233
214323
|
offset: op.offset,
|
|
214234
214324
|
coordinateSpace: op.coordinateSpace ?? "visible",
|
|
214325
|
+
knownMetadataAnchorIds: op.knownMetadataAnchorIds,
|
|
214326
|
+
onMetadataAnchorClone: (id, originalId, cloneId) => metadataClones.push({ id, originalId, cloneId }),
|
|
214235
214327
|
tailParaId,
|
|
214236
214328
|
allocateWId: () => {
|
|
214237
214329
|
const wId = allocateRevisionWId(input.state);
|
|
@@ -214267,6 +214359,7 @@ function runParagraphSplitCommit(input) {
|
|
|
214267
214359
|
paragraphByteStart: context.byteStart,
|
|
214268
214360
|
offset: op.offset,
|
|
214269
214361
|
coordinateSpace: op.coordinateSpace ?? "visible",
|
|
214362
|
+
knownMetadataAnchorIds: op.knownMetadataAnchorIds,
|
|
214270
214363
|
tailParaId,
|
|
214271
214364
|
allocateWId: () => {
|
|
214272
214365
|
const wId = splitAllocatedWIds[replayIndex++];
|
|
@@ -214293,6 +214386,9 @@ function runParagraphSplitCommit(input) {
|
|
|
214293
214386
|
});
|
|
214294
214387
|
if (!counterpartRewrite.ok)
|
|
214295
214388
|
return rejected8(input.txId, counterpartRewrite.reason);
|
|
214389
|
+
const metadataStorage = prepareMetadataSplitStorage(input.state, op.metadataAnchorBindings, metadataClones);
|
|
214390
|
+
if (!metadataStorage.ok)
|
|
214391
|
+
return rejected8(input.txId, "paragraph-split-point-unsupported");
|
|
214296
214392
|
const patch = counterpartRewrite.plan?.patch ?? {
|
|
214297
214393
|
kind: "replaceBytes",
|
|
214298
214394
|
order: 0,
|
|
@@ -214306,6 +214402,8 @@ function runParagraphSplitCommit(input) {
|
|
|
214306
214402
|
partUri: target.entry.partUri,
|
|
214307
214403
|
partBytes: bytes,
|
|
214308
214404
|
patches: [patch],
|
|
214405
|
+
extraPerPart: metadataStorage.perPart,
|
|
214406
|
+
extraPreconditions: metadataStorage.preconditions,
|
|
214309
214407
|
textRangeShifts: [],
|
|
214310
214408
|
createdRefs: [
|
|
214311
214409
|
{ kind: "block", nodeId: tailParaId, storyId: op.target.storyId },
|
|
@@ -271829,7 +271927,7 @@ function ensureCustomXmlPartForNamespace(context, namespace) {
|
|
|
271829
271927
|
return listCustomXmlRecords(context).find((record3) => record3.rootNamespace === namespace) ?? null;
|
|
271830
271928
|
}
|
|
271831
271929
|
function buildMetadataStorageXml(namespace, refs) {
|
|
271832
|
-
const body = refs.map((ref5) => `<ref id="${xmlEscapeAttr(ref5.id)}" encoding="json">${xmlEscapeAttr(ref5.payloadJson)}</ref>`).join("");
|
|
271930
|
+
const body = refs.map((ref5) => `<ref id="${xmlEscapeAttr(ref5.id)}" encoding="json"${ref5.physicalIds === undefined ? "" : ` sdAnchorIdsV1="${xmlEscapeAttr(ref5.physicalIds?.join(",") ?? "")}"`}>${xmlEscapeAttr(ref5.payloadJson)}</ref>`).join("");
|
|
271833
271931
|
return `<refs xmlns="${xmlEscapeAttr(namespace)}">${body}</refs>`;
|
|
271834
271932
|
}
|
|
271835
271933
|
function buildCustomXmlCreateUpdates(context, input) {
|
|
@@ -295218,6 +295316,737 @@ var init_context = __esm(() => {
|
|
|
295218
295316
|
init_story_surface();
|
|
295219
295317
|
});
|
|
295220
295318
|
|
|
295319
|
+
// ../../../v2/document-api-v2-adapter/dist/metadata/adapter.js
|
|
295320
|
+
class V2AnchoredMetadataAdapter {
|
|
295321
|
+
constructor(context) {
|
|
295322
|
+
this.context = context;
|
|
295323
|
+
}
|
|
295324
|
+
attach(input, options) {
|
|
295325
|
+
const mutationGuard = guardDirectOnlyMutation(this.context, input, options);
|
|
295326
|
+
if (mutationGuard)
|
|
295327
|
+
return mutationGuard;
|
|
295328
|
+
const id = input.id ?? newOpaqueId("metadata");
|
|
295329
|
+
const existingRecords = listMetadataRecords(this.context);
|
|
295330
|
+
if (existingRecords.some((record3) => record3.id === id)) {
|
|
295331
|
+
throw operationError("INVALID_INPUT", `metadata id ${id} already exists.`);
|
|
295332
|
+
}
|
|
295333
|
+
const payloadJson = JSON.stringify(input.payload);
|
|
295334
|
+
if (payloadJson === undefined)
|
|
295335
|
+
throw operationError("INVALID_INPUT", "metadata payload must be JSON serializable.");
|
|
295336
|
+
const documentXml = readDocumentXml(this.context);
|
|
295337
|
+
if (findMetadataAnchor(documentXml, id)) {
|
|
295338
|
+
throw operationError("INVALID_INPUT", `metadata id ${id} already exists.`);
|
|
295339
|
+
}
|
|
295340
|
+
const resolvedSegments = input.target.kind === "text" ? resolveMultiSegmentTarget(documentXml, input.target) : resolveSingleSegmentTarget(this.context, documentXml, input.target);
|
|
295341
|
+
if ("error" in resolvedSegments)
|
|
295342
|
+
throw operationError(resolvedSegments.error, resolvedSegments.message);
|
|
295343
|
+
const knownIds = new Set(existingRecords.map((record3) => record3.id));
|
|
295344
|
+
if (hasOverlappingMetadataAnchor(documentXml, resolvedSegments.segments, knownIds)) {
|
|
295345
|
+
return failure2("INVALID_TARGET", "metadata.attach target overlaps an existing metadata anchor.");
|
|
295346
|
+
}
|
|
295347
|
+
const existingPart = ensureCustomXmlPartForNamespace(this.context, input.namespace);
|
|
295348
|
+
const allocatedPart = existingPart ? null : allocateCustomXmlPartNames(this.context);
|
|
295349
|
+
const partName = existingPart?.partName ?? allocatedPart.partName;
|
|
295350
|
+
const partUri = existingPart?.partUri ?? allocatedPart.partUri;
|
|
295351
|
+
const storageXml = existingPart?.content ?? buildMetadataStorageXml(input.namespace, []);
|
|
295352
|
+
const sdtIds = allocateMetadataSdtIds(documentXml, resolvedSegments.segments.length);
|
|
295353
|
+
const refs = readMetadataRefs(storageXml, input.namespace);
|
|
295354
|
+
refs.push({ id, payloadJson, physicalIds: sdtIds.map(String) });
|
|
295355
|
+
const nextStorageXml = buildMetadataStorageXml(input.namespace, refs);
|
|
295356
|
+
const bySegmentPosition = resolvedSegments.segments.map((segment, index) => ({ segment, sdtId: sdtIds[index] })).sort((a, b) => b.segment.para.start - a.segment.para.start);
|
|
295357
|
+
let nextDocumentXml = documentXml;
|
|
295358
|
+
for (const { segment, sdtId } of bySegmentPosition) {
|
|
295359
|
+
const wrapped = wrapTextRangeWithMetadataSdt(segment.para.xml, segment.startOffset, segment.endOffset, id, sdtId);
|
|
295360
|
+
if (!wrapped.ok)
|
|
295361
|
+
throw metadataWrapRejectError(wrapped.reason);
|
|
295362
|
+
nextDocumentXml = replaceRange2(nextDocumentXml, segment.para.start, segment.para.end, wrapped.xml);
|
|
295363
|
+
}
|
|
295364
|
+
if (!dryRunRequested(input, options)) {
|
|
295365
|
+
nextDocumentXml = ensureW15Namespace(nextDocumentXml);
|
|
295366
|
+
const updates = existingPart ? { [partUri]: encodeXml(nextStorageXml) } : buildCustomXmlCreateUpdates(this.context, {
|
|
295367
|
+
id: newGuid(),
|
|
295368
|
+
content: nextStorageXml,
|
|
295369
|
+
partUri,
|
|
295370
|
+
propsPartUri: allocatedPart.propsPartUri,
|
|
295371
|
+
relsPartUri: allocatedPart.relsPartUri
|
|
295372
|
+
});
|
|
295373
|
+
updates[DOCUMENT_PART_URI5] = encodeXml(nextDocumentXml);
|
|
295374
|
+
const committed = commitWholePartUpdates(this.context, "metadata-attach", updates, {
|
|
295375
|
+
expectedRevision: expectedRevisionFrom(input, options),
|
|
295376
|
+
storySurface: {
|
|
295377
|
+
family: "storyAnchor",
|
|
295378
|
+
targetBlockIds: resolvedSegments.segments.map((segment) => segment.blockId)
|
|
295379
|
+
}
|
|
295380
|
+
});
|
|
295381
|
+
if (!committed.ok)
|
|
295382
|
+
return { success: false, failure: { code: committed.code, message: committed.message } };
|
|
295383
|
+
}
|
|
295384
|
+
return { success: true, id, namespace: input.namespace, partName };
|
|
295385
|
+
}
|
|
295386
|
+
list(query3) {
|
|
295387
|
+
let records = listMetadataRecords(this.context);
|
|
295388
|
+
const recordCounts = new Map;
|
|
295389
|
+
for (const record3 of records)
|
|
295390
|
+
recordCounts.set(record3.id, (recordCounts.get(record3.id) ?? 0) + 1);
|
|
295391
|
+
if (query3?.namespace !== undefined)
|
|
295392
|
+
records = records.filter((record3) => record3.namespace === query3.namespace);
|
|
295393
|
+
const documentXml = readDocumentXml(this.context);
|
|
295394
|
+
if (query3?.resolvedOnly === true) {
|
|
295395
|
+
records = records.filter((record3) => recordCounts.get(record3.id) === 1 && groupMetadataAnchor(documentXml, record3.id, new Set([record3.id]), record3.physicalIds) !== null);
|
|
295396
|
+
}
|
|
295397
|
+
if (query3?.within !== undefined) {
|
|
295398
|
+
records = records.filter((record3) => {
|
|
295399
|
+
const resolved = this.resolve({ id: record3.id });
|
|
295400
|
+
return resolved ? overlaps(query3.within, resolved.target) : false;
|
|
295401
|
+
});
|
|
295402
|
+
}
|
|
295403
|
+
const page = pageSlice(records, query3);
|
|
295404
|
+
return buildDiscoveryResult({
|
|
295405
|
+
evaluatedRevision: this.context.currentPublicRevision(),
|
|
295406
|
+
total: records.length,
|
|
295407
|
+
items: page.items.map((record3) => buildDiscoveryItem(record3.id, buildResolvedHandle(`metadata:${record3.id}`, "stable", "ext:metadata"), metadataSummary(record3, documentXml))),
|
|
295408
|
+
page: { offset: page.offset, limit: page.limit, returned: page.items.length }
|
|
295409
|
+
});
|
|
295410
|
+
}
|
|
295411
|
+
get(input) {
|
|
295412
|
+
if (input.contentControlId !== undefined && input.story?.storyType !== "body")
|
|
295413
|
+
return null;
|
|
295414
|
+
const record3 = findMetadataRecord(this.context, input.id);
|
|
295415
|
+
if (record3 && input.contentControlId !== undefined && !matchesPhysicalMetadataAnchor(readDocumentXml(this.context), record3, input.contentControlId))
|
|
295416
|
+
return null;
|
|
295417
|
+
return record3 ? { ...metadataSummary(record3, readDocumentXml(this.context)), payload: record3.payload } : null;
|
|
295418
|
+
}
|
|
295419
|
+
update(input, options) {
|
|
295420
|
+
const mutationGuard = guardDirectOnlyMutation(this.context, input, options);
|
|
295421
|
+
if (mutationGuard)
|
|
295422
|
+
return mutationGuard;
|
|
295423
|
+
if (listMetadataRecords(this.context).filter((candidate2) => candidate2.id === input.id).length > 1) {
|
|
295424
|
+
return failure2("INVALID_TARGET", `metadata ${input.id} has ambiguous payload records.`);
|
|
295425
|
+
}
|
|
295426
|
+
const record3 = findMetadataRecord(this.context, input.id);
|
|
295427
|
+
if (!record3)
|
|
295428
|
+
throw operationError("TARGET_NOT_FOUND", `metadata ${input.id} not found.`);
|
|
295429
|
+
const payloadJson = JSON.stringify(input.payload);
|
|
295430
|
+
if (payloadJson === undefined)
|
|
295431
|
+
throw operationError("INVALID_INPUT", "metadata payload must be JSON serializable.");
|
|
295432
|
+
if (dryRunRequested(input, options))
|
|
295433
|
+
return { success: true, id: input.id };
|
|
295434
|
+
const records = listMetadataRecords(this.context).filter((candidate2) => candidate2.partUri === record3.partUri);
|
|
295435
|
+
const refs = records.map((candidate2) => ({
|
|
295436
|
+
id: candidate2.id,
|
|
295437
|
+
payloadJson: candidate2.id === input.id ? payloadJson : JSON.stringify(candidate2.payload),
|
|
295438
|
+
physicalIds: candidate2.physicalIds
|
|
295439
|
+
}));
|
|
295440
|
+
const committed = commitWholePartUpdates(this.context, "metadata-update", { [record3.partUri]: encodeXml(buildMetadataStorageXml(record3.namespace, refs)) }, { expectedRevision: expectedRevisionFrom(input, options) });
|
|
295441
|
+
if (!committed.ok)
|
|
295442
|
+
return { success: false, failure: { code: committed.code, message: committed.message } };
|
|
295443
|
+
return { success: true, id: input.id };
|
|
295444
|
+
}
|
|
295445
|
+
remove(input, options) {
|
|
295446
|
+
const mutationGuard = guardDirectOnlyMutation(this.context, input, options);
|
|
295447
|
+
if (mutationGuard)
|
|
295448
|
+
return mutationGuard;
|
|
295449
|
+
if (listMetadataRecords(this.context).filter((candidate2) => candidate2.id === input.id).length > 1) {
|
|
295450
|
+
return failure2("INVALID_TARGET", `metadata ${input.id} has ambiguous payload records.`);
|
|
295451
|
+
}
|
|
295452
|
+
const record3 = findMetadataRecord(this.context, input.id);
|
|
295453
|
+
if (!record3)
|
|
295454
|
+
throw operationError("TARGET_NOT_FOUND", `metadata ${input.id} not found.`);
|
|
295455
|
+
const documentXml = readDocumentXml(this.context);
|
|
295456
|
+
const knownIds = new Set(listMetadataRecords(this.context).map((candidate2) => candidate2.id));
|
|
295457
|
+
const matchingAnchors = listMetadataAnchors(documentXml, knownIds).filter((anchor) => anchor.id === input.id);
|
|
295458
|
+
const grouped = groupMetadataAnchor(documentXml, input.id, knownIds, record3.physicalIds);
|
|
295459
|
+
const malformedLegacyAnchor = record3.physicalIds === undefined && matchingAnchors.length === 1 && (matchingAnchors[0].unmatched || unwrapSdt(matchingAnchors[0].xml) === null);
|
|
295460
|
+
if ((matchingAnchors.length > 0 || record3.physicalIds !== undefined) && !grouped && !malformedLegacyAnchor) {
|
|
295461
|
+
return { success: false, failure: { code: "INVALID_TARGET", message: `metadata ${input.id} has ambiguous anchors.` } };
|
|
295462
|
+
}
|
|
295463
|
+
if (dryRunRequested(input, options))
|
|
295464
|
+
return { success: true, id: input.id };
|
|
295465
|
+
const updates = {};
|
|
295466
|
+
if (grouped) {
|
|
295467
|
+
const bySegmentPosition = [...grouped.segments].sort((a, b) => b.start - a.start);
|
|
295468
|
+
let nextDocumentXml = documentXml;
|
|
295469
|
+
for (const anchor of bySegmentPosition) {
|
|
295470
|
+
if (anchor.unmatched)
|
|
295471
|
+
continue;
|
|
295472
|
+
const unwrapped = unwrapSdt(anchor.xml);
|
|
295473
|
+
if (unwrapped === null)
|
|
295474
|
+
continue;
|
|
295475
|
+
nextDocumentXml = replaceRange2(nextDocumentXml, anchor.start, anchor.end, unwrapped);
|
|
295476
|
+
}
|
|
295477
|
+
if (nextDocumentXml !== documentXml)
|
|
295478
|
+
updates[DOCUMENT_PART_URI5] = encodeXml(nextDocumentXml);
|
|
295479
|
+
}
|
|
295480
|
+
const remaining = listMetadataRecords(this.context).filter((candidate2) => candidate2.partUri === record3.partUri && candidate2.id !== input.id).map((candidate2) => ({ id: candidate2.id, payloadJson: JSON.stringify(candidate2.payload), physicalIds: candidate2.physicalIds }));
|
|
295481
|
+
const targetBlockIds2 = grouped ? grouped.segments.map((anchor) => anchor.blockId) : undefined;
|
|
295482
|
+
if (remaining.length > 0) {
|
|
295483
|
+
updates[record3.partUri] = encodeXml(buildMetadataStorageXml(record3.namespace, remaining));
|
|
295484
|
+
const committed = commitWholePartUpdates(this.context, "metadata-remove", updates, {
|
|
295485
|
+
expectedRevision: expectedRevisionFrom(input, options),
|
|
295486
|
+
...targetBlockIds2 ? { storySurface: { family: "storyAnchor", targetBlockIds: targetBlockIds2 } } : {}
|
|
295487
|
+
});
|
|
295488
|
+
if (!committed.ok)
|
|
295489
|
+
return { success: false, failure: { code: committed.code, message: committed.message } };
|
|
295490
|
+
} else {
|
|
295491
|
+
Object.assign(updates, buildCustomXmlRemoveUpdates(this.context, record3));
|
|
295492
|
+
const committed = commitWholePartUpdates(this.context, "metadata-remove", updates, {
|
|
295493
|
+
expectedRevision: expectedRevisionFrom(input, options),
|
|
295494
|
+
...targetBlockIds2 ? { storySurface: { family: "storyAnchor", targetBlockIds: targetBlockIds2 } } : {}
|
|
295495
|
+
});
|
|
295496
|
+
if (!committed.ok)
|
|
295497
|
+
return { success: false, failure: { code: committed.code, message: committed.message } };
|
|
295498
|
+
}
|
|
295499
|
+
return { success: true, id: input.id };
|
|
295500
|
+
}
|
|
295501
|
+
resolve(input) {
|
|
295502
|
+
if (input.contentControlId !== undefined && input.story?.storyType !== "body")
|
|
295503
|
+
return null;
|
|
295504
|
+
const record3 = findMetadataRecord(this.context, input.id);
|
|
295505
|
+
if (!record3)
|
|
295506
|
+
return null;
|
|
295507
|
+
const knownIds = new Set(listMetadataRecords(this.context).map((candidate2) => candidate2.id));
|
|
295508
|
+
const grouped = groupMetadataAnchor(readDocumentXml(this.context), input.id, knownIds, record3.physicalIds);
|
|
295509
|
+
if (!grouped)
|
|
295510
|
+
return null;
|
|
295511
|
+
if (input.contentControlId !== undefined && !grouped.segments.some((anchor) => metadataAnchorPhysicalId(anchor) === input.contentControlId))
|
|
295512
|
+
return null;
|
|
295513
|
+
return { id: input.id, target: grouped.target };
|
|
295514
|
+
}
|
|
295515
|
+
}
|
|
295516
|
+
function matchesPhysicalMetadataAnchor(documentXml, record3, contentControlId) {
|
|
295517
|
+
const grouped = groupMetadataAnchor(documentXml, record3.id, new Set([record3.id]), record3.physicalIds);
|
|
295518
|
+
return grouped !== null && grouped.segments.some((anchor) => metadataAnchorPhysicalId(anchor) === contentControlId);
|
|
295519
|
+
}
|
|
295520
|
+
function listMetadataSplitBindings(context, paragraphXml) {
|
|
295521
|
+
const candidateIds = new Set([...paragraphXml.matchAll(/<w:tag\b[^>]*\/>/g)].map((match) => attrValue(match[0], "val")).filter((id) => id !== null));
|
|
295522
|
+
if (candidateIds.size === 0)
|
|
295523
|
+
return [];
|
|
295524
|
+
const records = listMetadataRecords(context);
|
|
295525
|
+
const counts = new Map;
|
|
295526
|
+
for (const record3 of records)
|
|
295527
|
+
counts.set(record3.id, (counts.get(record3.id) ?? 0) + 1);
|
|
295528
|
+
const documentXml = readDocumentXml(context);
|
|
295529
|
+
return records.filter((record3) => candidateIds.has(record3.id) && counts.get(record3.id) === 1 && groupMetadataAnchor(documentXml, record3.id, new Set([record3.id]), record3.physicalIds) !== null).map((record3) => ({
|
|
295530
|
+
id: record3.id,
|
|
295531
|
+
partUri: record3.partUri,
|
|
295532
|
+
...record3.physicalIds ? { physicalIds: record3.physicalIds } : {}
|
|
295533
|
+
}));
|
|
295534
|
+
}
|
|
295535
|
+
function listMetadataRecords(context) {
|
|
295536
|
+
const out = [];
|
|
295537
|
+
for (const part of listCustomXmlRecords(context)) {
|
|
295538
|
+
if (!part.rootNamespace || !/^<refs\b/.test(part.content.replace(/^<\?xml[^>]*>/, "").trim()))
|
|
295539
|
+
continue;
|
|
295540
|
+
for (const ref5 of readMetadataRefs(part.content, part.rootNamespace)) {
|
|
295541
|
+
let payload = null;
|
|
295542
|
+
try {
|
|
295543
|
+
payload = JSON.parse(ref5.payloadJson);
|
|
295544
|
+
} catch {
|
|
295545
|
+
payload = null;
|
|
295546
|
+
}
|
|
295547
|
+
out.push({
|
|
295548
|
+
id: ref5.id,
|
|
295549
|
+
namespace: part.rootNamespace,
|
|
295550
|
+
partName: part.partName,
|
|
295551
|
+
partUri: part.partUri,
|
|
295552
|
+
...part.propsPartUri ? { propsPartUri: part.propsPartUri } : {},
|
|
295553
|
+
payload,
|
|
295554
|
+
...ref5.physicalIds !== undefined ? { physicalIds: ref5.physicalIds } : {}
|
|
295555
|
+
});
|
|
295556
|
+
}
|
|
295557
|
+
}
|
|
295558
|
+
return out;
|
|
295559
|
+
}
|
|
295560
|
+
function findMetadataRecord(context, id) {
|
|
295561
|
+
const matches = listMetadataRecords(context).filter((record3) => record3.id === id);
|
|
295562
|
+
return matches.length === 1 ? matches[0] : null;
|
|
295563
|
+
}
|
|
295564
|
+
function metadataSummary(record3, documentXml) {
|
|
295565
|
+
return {
|
|
295566
|
+
id: record3.id,
|
|
295567
|
+
namespace: record3.namespace,
|
|
295568
|
+
partName: record3.partName,
|
|
295569
|
+
anchorStatus: groupMetadataAnchor(documentXml, record3.id, new Set([record3.id]), record3.physicalIds) ? "resolved" : "orphan"
|
|
295570
|
+
};
|
|
295571
|
+
}
|
|
295572
|
+
function readMetadataRefs(xml, _namespace) {
|
|
295573
|
+
const refs = [];
|
|
295574
|
+
const re = /(<ref\b[^>]*\bid="([^"]*)"[^>]*>)([\s\S]*?)<\/ref>/g;
|
|
295575
|
+
for (let match = re.exec(xml);match; match = re.exec(xml)) {
|
|
295576
|
+
const bindingAttributes = [...match[1].matchAll(/\bsdAnchorIdsV1\s*=\s*(['"])(.*?)\1/g)];
|
|
295577
|
+
const ids = bindingAttributes.length === 0 && !/\bsdAnchorIdsV1\b/.test(match[1]) ? undefined : bindingAttributes.length === 1 ? decodeXmlEntities(bindingAttributes[0][2]).split(",") : [];
|
|
295578
|
+
const validIds = ids && ids.length > 0 && ids.every((value2) => /^(?:0|[1-9]\d*)$/.test(value2)) && new Set(ids).size === ids.length;
|
|
295579
|
+
refs.push({
|
|
295580
|
+
id: decodeXmlEntities(match[2]),
|
|
295581
|
+
payloadJson: decodeXmlEntities(match[3]),
|
|
295582
|
+
...ids !== undefined ? { physicalIds: validIds ? ids : null } : {}
|
|
295583
|
+
});
|
|
295584
|
+
}
|
|
295585
|
+
return refs;
|
|
295586
|
+
}
|
|
295587
|
+
function findMetadataAnchor(documentXml, id) {
|
|
295588
|
+
return listMetadataAnchors(documentXml, new Set([id])).find((anchor) => anchor.id === id) ?? null;
|
|
295589
|
+
}
|
|
295590
|
+
function listMetadataAnchors(documentXml, knownIds) {
|
|
295591
|
+
const anchors = [];
|
|
295592
|
+
for (const sdt of listSdtRanges(documentXml)) {
|
|
295593
|
+
const pr = ownSdtPr(sdt.xml);
|
|
295594
|
+
const tag = attrValue(/<w:tag\b[^>]*\/>/.exec(pr)?.[0] ?? "", "val");
|
|
295595
|
+
if (!tag || !isMetadataAnchorPr(pr, tag, knownIds))
|
|
295596
|
+
continue;
|
|
295597
|
+
const anchor = materializeMetadataAnchor(documentXml, sdt, tag);
|
|
295598
|
+
if (anchor)
|
|
295599
|
+
anchors.push(anchor);
|
|
295600
|
+
}
|
|
295601
|
+
return anchors.sort((left, right) => left.start - right.start);
|
|
295602
|
+
}
|
|
295603
|
+
function ownSdtPr(sdtXml) {
|
|
295604
|
+
const openTag = /<w:sdt\b[^>]*>/.exec(sdtXml);
|
|
295605
|
+
if (!openTag)
|
|
295606
|
+
return "";
|
|
295607
|
+
const headStart = openTag.index + openTag[0].length;
|
|
295608
|
+
const contentOrNested = /<w:sdtContent\b[^>]*>|<w:sdt\b[^>]*>/.exec(sdtXml.slice(headStart));
|
|
295609
|
+
const head = contentOrNested ? sdtXml.slice(headStart, headStart + contentOrNested.index) : sdtXml.slice(headStart);
|
|
295610
|
+
return /<w:sdtPr\b[^>]*>[\s\S]*?<\/w:sdtPr>/.exec(head)?.[0] ?? "";
|
|
295611
|
+
}
|
|
295612
|
+
function listSdtRanges(documentXml) {
|
|
295613
|
+
const ranges = [];
|
|
295614
|
+
const stack = [];
|
|
295615
|
+
const tokenRe = /<w:sdt\b[^>]*>|<\/w:sdt>/g;
|
|
295616
|
+
for (let match = tokenRe.exec(documentXml);match; match = tokenRe.exec(documentXml)) {
|
|
295617
|
+
if (match[0].startsWith("</")) {
|
|
295618
|
+
const start = stack.pop();
|
|
295619
|
+
if (start === undefined)
|
|
295620
|
+
continue;
|
|
295621
|
+
const end = tokenRe.lastIndex;
|
|
295622
|
+
ranges.push({ start, end, xml: documentXml.slice(start, end) });
|
|
295623
|
+
} else if (/\/\s*>$/.test(match[0])) {
|
|
295624
|
+
ranges.push({ start: match.index, end: tokenRe.lastIndex, xml: match[0] });
|
|
295625
|
+
} else {
|
|
295626
|
+
stack.push(match.index);
|
|
295627
|
+
}
|
|
295628
|
+
}
|
|
295629
|
+
for (const start of stack) {
|
|
295630
|
+
const end = unmatchedSdtExtent(documentXml, start);
|
|
295631
|
+
ranges.push({ start, end, xml: documentXml.slice(start, end), unmatched: true });
|
|
295632
|
+
}
|
|
295633
|
+
return ranges.sort((left, right) => left.start - right.start);
|
|
295634
|
+
}
|
|
295635
|
+
function unmatchedSdtExtent(documentXml, start) {
|
|
295636
|
+
const paraClose = documentXml.indexOf("</w:p>", start);
|
|
295637
|
+
return paraClose === -1 ? documentXml.length : paraClose;
|
|
295638
|
+
}
|
|
295639
|
+
function isMetadataAnchorPr(pr, tag, knownIds) {
|
|
295640
|
+
const alias = attrValue(/<w:alias\b[^>]*\/>/.exec(pr)?.[0] ?? "", "val");
|
|
295641
|
+
if (alias !== null && alias !== METADATA_ANCHOR_ALIAS)
|
|
295642
|
+
return false;
|
|
295643
|
+
const hasHiddenAppearance = attrValue(/<w15:appearance\b[^>]*\/>/.exec(pr)?.[0] ?? "", "val") === "hidden";
|
|
295644
|
+
const hasPlainTextPr = /<w:text\b/.test(pr);
|
|
295645
|
+
return knownIds.has(tag) && hasHiddenAppearance && hasPlainTextPr;
|
|
295646
|
+
}
|
|
295647
|
+
function materializeMetadataAnchor(documentXml, sdt, id) {
|
|
295648
|
+
const para = findParagraphContaining2(documentXml, sdt.start);
|
|
295649
|
+
if (!para)
|
|
295650
|
+
return null;
|
|
295651
|
+
const startOffset = extractVisibleTextFromXml2(para.xml.slice(0, sdt.start - para.start)).length;
|
|
295652
|
+
const length = extractVisibleTextFromXml2(unwrapSdt(sdt.xml) ?? sdt.xml).length;
|
|
295653
|
+
const endOffset = startOffset + length;
|
|
295654
|
+
return {
|
|
295655
|
+
id,
|
|
295656
|
+
start: sdt.start,
|
|
295657
|
+
end: sdt.end,
|
|
295658
|
+
xml: sdt.xml,
|
|
295659
|
+
blockId: para.blockId,
|
|
295660
|
+
startOffset,
|
|
295661
|
+
endOffset,
|
|
295662
|
+
unmatched: sdt.unmatched === true,
|
|
295663
|
+
target: {
|
|
295664
|
+
kind: "selection",
|
|
295665
|
+
start: { kind: "text", blockId: para.blockId, offset: startOffset, story: bodyStoryLocator2() },
|
|
295666
|
+
end: { kind: "text", blockId: para.blockId, offset: endOffset, story: bodyStoryLocator2() }
|
|
295667
|
+
}
|
|
295668
|
+
};
|
|
295669
|
+
}
|
|
295670
|
+
function groupMetadataAnchor(documentXml, id, knownIds, physicalIds) {
|
|
295671
|
+
const matches = listMetadataAnchors(documentXml, knownIds).filter((anchor) => anchor.id === id);
|
|
295672
|
+
if (matches.length === 0)
|
|
295673
|
+
return null;
|
|
295674
|
+
if (physicalIds === null)
|
|
295675
|
+
return null;
|
|
295676
|
+
if (physicalIds === undefined && matches.length !== 1)
|
|
295677
|
+
return null;
|
|
295678
|
+
if (physicalIds !== undefined && (matches.length !== physicalIds.length || matches.some((anchor) => {
|
|
295679
|
+
const physicalId = metadataAnchorPhysicalId(anchor);
|
|
295680
|
+
return physicalId === null || !physicalIds.includes(physicalId);
|
|
295681
|
+
}) || new Set(matches.map(metadataAnchorPhysicalId)).size !== matches.length))
|
|
295682
|
+
return null;
|
|
295683
|
+
const controlIdCounts = countBodyControlIds(documentXml);
|
|
295684
|
+
if (!controlIdCounts)
|
|
295685
|
+
return null;
|
|
295686
|
+
if (matches.some((anchor) => controlIdCounts.get(metadataAnchorPhysicalId(anchor) ?? "") !== 1))
|
|
295687
|
+
return null;
|
|
295688
|
+
const kept = contiguousAnchorPrefix(documentXml, matches);
|
|
295689
|
+
if (kept.length !== matches.length)
|
|
295690
|
+
return null;
|
|
295691
|
+
if (kept.some((anchor) => anchor.unmatched || unwrapSdt(anchor.xml) === null))
|
|
295692
|
+
return null;
|
|
295693
|
+
if (kept.length === 1)
|
|
295694
|
+
return { id, segments: kept, target: kept[0].target };
|
|
295695
|
+
const textSegments = [];
|
|
295696
|
+
for (const anchor of kept) {
|
|
295697
|
+
const previous = textSegments.at(-1);
|
|
295698
|
+
if (previous?.blockId === anchor.blockId && previous.range.end === anchor.startOffset) {
|
|
295699
|
+
previous.range.end = anchor.endOffset;
|
|
295700
|
+
} else {
|
|
295701
|
+
textSegments.push({ blockId: anchor.blockId, range: { start: anchor.startOffset, end: anchor.endOffset } });
|
|
295702
|
+
}
|
|
295703
|
+
}
|
|
295704
|
+
if (textSegments.length === 1) {
|
|
295705
|
+
const range = textSegments[0];
|
|
295706
|
+
return {
|
|
295707
|
+
id,
|
|
295708
|
+
segments: kept,
|
|
295709
|
+
target: {
|
|
295710
|
+
kind: "selection",
|
|
295711
|
+
start: { kind: "text", blockId: range.blockId, offset: range.range.start, story: bodyStoryLocator2() },
|
|
295712
|
+
end: { kind: "text", blockId: range.blockId, offset: range.range.end, story: bodyStoryLocator2() }
|
|
295713
|
+
}
|
|
295714
|
+
};
|
|
295715
|
+
}
|
|
295716
|
+
return {
|
|
295717
|
+
id,
|
|
295718
|
+
segments: kept,
|
|
295719
|
+
target: { kind: "text", segments: [textSegments[0], ...textSegments.slice(1)] }
|
|
295720
|
+
};
|
|
295721
|
+
}
|
|
295722
|
+
function metadataAnchorPhysicalId(anchor) {
|
|
295723
|
+
const idTag = /<w:id\b[^>]*\/>/.exec(ownSdtPr(anchor.xml))?.[0];
|
|
295724
|
+
const value2 = idTag && /\bw:val\s*=\s*(['"])(.*?)\1/.exec(idTag)?.[2];
|
|
295725
|
+
return value2 === undefined ? null : decodeXmlEntities(value2);
|
|
295726
|
+
}
|
|
295727
|
+
function countBodyControlIds(documentXml) {
|
|
295728
|
+
const counts = new Map;
|
|
295729
|
+
const stack = [];
|
|
295730
|
+
const parser = createXmlSaxParser({ namespaceAware: true });
|
|
295731
|
+
let parseFailed = false;
|
|
295732
|
+
parser.on("error", () => {
|
|
295733
|
+
parseFailed = true;
|
|
295734
|
+
});
|
|
295735
|
+
parser.on("opentag", (tag) => {
|
|
295736
|
+
const parent = stack.at(-1);
|
|
295737
|
+
const owner = stack.at(-2);
|
|
295738
|
+
if (tag.namespaceUri === WORD_NAMESPACE5 && tag.localName === "id" && parent?.namespaceUri === WORD_NAMESPACE5 && parent.localName === "sdtPr" && owner?.namespaceUri === WORD_NAMESPACE5 && owner.localName === "sdt") {
|
|
295739
|
+
const value2 = tag.attributes.find((attribute) => attribute.namespaceUri === WORD_NAMESPACE5 && attribute.localName === "val")?.value;
|
|
295740
|
+
if (value2 !== undefined)
|
|
295741
|
+
counts.set(value2, (counts.get(value2) ?? 0) + 1);
|
|
295742
|
+
}
|
|
295743
|
+
stack.push(tag);
|
|
295744
|
+
});
|
|
295745
|
+
parser.on("closetag", () => {
|
|
295746
|
+
stack.pop();
|
|
295747
|
+
});
|
|
295748
|
+
try {
|
|
295749
|
+
parser.write(documentXml).close();
|
|
295750
|
+
} catch {
|
|
295751
|
+
return null;
|
|
295752
|
+
}
|
|
295753
|
+
return parseFailed ? null : counts;
|
|
295754
|
+
}
|
|
295755
|
+
function contiguousAnchorPrefix(documentXml, matches) {
|
|
295756
|
+
if (matches.length <= 1)
|
|
295757
|
+
return [...matches];
|
|
295758
|
+
const map3 = buildStructuralBoundaryMap(TEXT_ENCODER.encode(documentXml));
|
|
295759
|
+
const first = map3.byBlockId(matches[0].blockId);
|
|
295760
|
+
if (!first)
|
|
295761
|
+
return [matches[0]];
|
|
295762
|
+
const kept = [matches[0]];
|
|
295763
|
+
let prev = first;
|
|
295764
|
+
for (let i2 = 1;i2 < matches.length; i2 += 1) {
|
|
295765
|
+
const context = map3.byBlockId(matches[i2].blockId);
|
|
295766
|
+
if (!context)
|
|
295767
|
+
break;
|
|
295768
|
+
const sameParagraph = context.ordinal === prev.ordinal;
|
|
295769
|
+
if (sameParagraph) {
|
|
295770
|
+
const previousAnchor = kept.at(-1);
|
|
295771
|
+
if (context.blockId !== previousAnchor.blockId || matches[i2].startOffset !== previousAnchor.endOffset || !isMetadataCarrierGap(documentXml.slice(previousAnchor.end, matches[i2].start)))
|
|
295772
|
+
break;
|
|
295773
|
+
} else if (context.ordinal !== prev.ordinal + 1)
|
|
295774
|
+
break;
|
|
295775
|
+
if (!sameTableCellPath(context.tableCellPath, first.tableCellPath))
|
|
295776
|
+
break;
|
|
295777
|
+
if (!sameOrdinalPath2(context.blockSdtPath, first.blockSdtPath))
|
|
295778
|
+
break;
|
|
295779
|
+
if (!sameOrdinalPath2(context.blockCustomXmlPath, first.blockCustomXmlPath))
|
|
295780
|
+
break;
|
|
295781
|
+
if (context.sectionIndex !== first.sectionIndex)
|
|
295782
|
+
break;
|
|
295783
|
+
if (prev.carriesSectionBreak)
|
|
295784
|
+
break;
|
|
295785
|
+
kept.push(matches[i2]);
|
|
295786
|
+
prev = context;
|
|
295787
|
+
}
|
|
295788
|
+
return kept;
|
|
295789
|
+
}
|
|
295790
|
+
function isMetadataCarrierGap(xml) {
|
|
295791
|
+
return /^(?:\s*<w:proofErr\s+w:type="(?:spellStart|spellEnd|gramStart|gramEnd)"\s*\/>)*\s*$/.test(xml);
|
|
295792
|
+
}
|
|
295793
|
+
function sameOrdinalPath2(left, right) {
|
|
295794
|
+
return left.length === right.length && left.every((value2, index) => value2 === right[index]);
|
|
295795
|
+
}
|
|
295796
|
+
function resolveSingleSegmentTarget(context, documentXml, target) {
|
|
295797
|
+
const resolved = resolveBodySelectionTarget(context, target);
|
|
295798
|
+
if ("error" in resolved)
|
|
295799
|
+
return resolved;
|
|
295800
|
+
if (resolved.startBlockId !== resolved.endBlockId) {
|
|
295801
|
+
return { error: "INVALID_TARGET", message: "metadata.attach requires a same-paragraph text selection." };
|
|
295802
|
+
}
|
|
295803
|
+
if (resolved.startOffset >= resolved.endOffset) {
|
|
295804
|
+
return { error: "INVALID_TARGET", message: "metadata.attach requires a non-empty text range." };
|
|
295805
|
+
}
|
|
295806
|
+
const para = findParagraphById2(documentXml, resolved.startBlockId);
|
|
295807
|
+
if (!para)
|
|
295808
|
+
return { error: "TARGET_NOT_FOUND", message: `paragraph ${resolved.startBlockId} not found.` };
|
|
295809
|
+
return {
|
|
295810
|
+
segments: [{ blockId: para.blockId, startOffset: resolved.startOffset, endOffset: resolved.endOffset, para }]
|
|
295811
|
+
};
|
|
295812
|
+
}
|
|
295813
|
+
function resolveMultiSegmentTarget(documentXml, target) {
|
|
295814
|
+
if (target.story !== undefined && target.story.storyType !== "body") {
|
|
295815
|
+
return {
|
|
295816
|
+
error: "TARGET_NOT_FOUND",
|
|
295817
|
+
message: "metadata.attach resolves paragraphs against the main document body only."
|
|
295818
|
+
};
|
|
295819
|
+
}
|
|
295820
|
+
if (target.coordinateSpace === "tracked") {
|
|
295821
|
+
return {
|
|
295822
|
+
error: "INVALID_TARGET",
|
|
295823
|
+
message: "metadata.attach does not support a tracked-coordinate-space TextTarget."
|
|
295824
|
+
};
|
|
295825
|
+
}
|
|
295826
|
+
const segments = [];
|
|
295827
|
+
for (const segment of target.segments) {
|
|
295828
|
+
if (segment.range.start >= segment.range.end) {
|
|
295829
|
+
return {
|
|
295830
|
+
error: "INVALID_TARGET",
|
|
295831
|
+
message: "metadata.attach requires a non-empty text range in every TextTarget segment."
|
|
295832
|
+
};
|
|
295833
|
+
}
|
|
295834
|
+
const para = findParagraphById2(documentXml, segment.blockId);
|
|
295835
|
+
if (!para)
|
|
295836
|
+
return { error: "TARGET_NOT_FOUND", message: `paragraph ${segment.blockId} not found.` };
|
|
295837
|
+
segments.push({ blockId: segment.blockId, startOffset: segment.range.start, endOffset: segment.range.end, para });
|
|
295838
|
+
}
|
|
295839
|
+
const boundaryError = validateContiguousStructuralRun(documentXml, segments.map((segment) => segment.blockId));
|
|
295840
|
+
if (boundaryError)
|
|
295841
|
+
return boundaryError;
|
|
295842
|
+
return { segments };
|
|
295843
|
+
}
|
|
295844
|
+
function validateContiguousStructuralRun(documentXml, blockIds) {
|
|
295845
|
+
if (blockIds.length <= 1)
|
|
295846
|
+
return null;
|
|
295847
|
+
const map3 = buildStructuralBoundaryMap(TEXT_ENCODER.encode(documentXml));
|
|
295848
|
+
const contexts = blockIds.map((blockId) => map3.byBlockId(blockId));
|
|
295849
|
+
const first = contexts[0];
|
|
295850
|
+
if (!first) {
|
|
295851
|
+
return { error: "INVALID_TARGET", message: `paragraph "${blockIds[0]}" is not visible to the structural map.` };
|
|
295852
|
+
}
|
|
295853
|
+
for (let i2 = 1;i2 < contexts.length; i2 += 1) {
|
|
295854
|
+
const context = contexts[i2];
|
|
295855
|
+
const prev = contexts[i2 - 1];
|
|
295856
|
+
if (!context) {
|
|
295857
|
+
return { error: "INVALID_TARGET", message: `paragraph "${blockIds[i2]}" is not visible to the structural map.` };
|
|
295858
|
+
}
|
|
295859
|
+
if (context.ordinal !== prev.ordinal + 1) {
|
|
295860
|
+
return {
|
|
295861
|
+
error: "INVALID_TARGET",
|
|
295862
|
+
message: "metadata.attach TextTarget segments must be contiguous paragraphs in document order."
|
|
295863
|
+
};
|
|
295864
|
+
}
|
|
295865
|
+
if (!sameTableCellPath(context.tableCellPath, first.tableCellPath)) {
|
|
295866
|
+
return { error: "INVALID_TARGET", message: "metadata.attach TextTarget cannot cross a table-cell boundary." };
|
|
295867
|
+
}
|
|
295868
|
+
if (!sameOrdinalPath2(context.blockSdtPath, first.blockSdtPath)) {
|
|
295869
|
+
return {
|
|
295870
|
+
error: "INVALID_TARGET",
|
|
295871
|
+
message: "metadata.attach TextTarget cannot cross a block content-control boundary."
|
|
295872
|
+
};
|
|
295873
|
+
}
|
|
295874
|
+
if (!sameOrdinalPath2(context.blockCustomXmlPath, first.blockCustomXmlPath)) {
|
|
295875
|
+
return {
|
|
295876
|
+
error: "INVALID_TARGET",
|
|
295877
|
+
message: "metadata.attach TextTarget cannot cross a block custom-XML boundary."
|
|
295878
|
+
};
|
|
295879
|
+
}
|
|
295880
|
+
if (context.sectionIndex !== first.sectionIndex) {
|
|
295881
|
+
return { error: "INVALID_TARGET", message: "metadata.attach TextTarget cannot cross a section boundary." };
|
|
295882
|
+
}
|
|
295883
|
+
if (prev.carriesSectionBreak) {
|
|
295884
|
+
return { error: "INVALID_TARGET", message: "metadata.attach TextTarget cannot cross a section boundary." };
|
|
295885
|
+
}
|
|
295886
|
+
}
|
|
295887
|
+
if (contexts[contexts.length - 1].carriesSectionBreak) {
|
|
295888
|
+
return { error: "INVALID_TARGET", message: "metadata.attach TextTarget cannot cross a section boundary." };
|
|
295889
|
+
}
|
|
295890
|
+
return null;
|
|
295891
|
+
}
|
|
295892
|
+
function hasOverlappingMetadataAnchor(documentXml, segments, knownIds) {
|
|
295893
|
+
const anchors = listMetadataAnchors(documentXml, knownIds);
|
|
295894
|
+
return segments.some((segment) => anchors.some((anchor) => anchor.blockId === segment.blockId && rangesStrictlyOverlap(segment.startOffset, segment.endOffset, anchor.startOffset, anchor.endOffset)));
|
|
295895
|
+
}
|
|
295896
|
+
function rangesStrictlyOverlap(leftStart, leftEnd, rightStart, rightEnd) {
|
|
295897
|
+
return leftStart < rightEnd && rightStart < leftEnd;
|
|
295898
|
+
}
|
|
295899
|
+
function bodyStoryLocator2() {
|
|
295900
|
+
return { kind: "story", storyType: "body" };
|
|
295901
|
+
}
|
|
295902
|
+
function wrapTextRangeWithMetadataSdt(paragraphXml, start, end, id, sdtId) {
|
|
295903
|
+
return wrapRangeWithMarkupInParagraphXml({
|
|
295904
|
+
paragraphXml,
|
|
295905
|
+
rangeStart: start,
|
|
295906
|
+
rangeEnd: end,
|
|
295907
|
+
open: metadataSdtOpenXml(id, sdtId),
|
|
295908
|
+
close: "</w:sdtContent></w:sdt>"
|
|
295909
|
+
});
|
|
295910
|
+
}
|
|
295911
|
+
function metadataSdtOpenXml(id, sdtId) {
|
|
295912
|
+
return [
|
|
295913
|
+
`<w:sdt xmlns:w15="${W15_NS}"><w:sdtPr>`,
|
|
295914
|
+
`<w:id w:val="${sdtId}"/>`,
|
|
295915
|
+
`<w:alias w:val="${xmlEscapeAttr(METADATA_ANCHOR_ALIAS)}"/>`,
|
|
295916
|
+
`<w:tag w:val="${xmlEscapeAttr(id)}"/>`,
|
|
295917
|
+
'<w15:appearance w15:val="hidden"/>',
|
|
295918
|
+
"<w:text/>",
|
|
295919
|
+
"</w:sdtPr><w:sdtContent>"
|
|
295920
|
+
].join("");
|
|
295921
|
+
}
|
|
295922
|
+
function metadataWrapRejectError(reason) {
|
|
295923
|
+
if (reason === "invalid-range") {
|
|
295924
|
+
return operationError("TARGET_NOT_FOUND", "metadata target text range not found.");
|
|
295925
|
+
}
|
|
295926
|
+
return operationError("INVALID_TARGET", `metadata.attach target overlaps unsupported content (${reason}).`);
|
|
295927
|
+
}
|
|
295928
|
+
function allocateMetadataSdtIds(documentXml, count) {
|
|
295929
|
+
const used = new Set;
|
|
295930
|
+
const idRe = /<w:id\b[^>]*(?:\/>|>)/g;
|
|
295931
|
+
for (let match = idRe.exec(documentXml);match; match = idRe.exec(documentXml)) {
|
|
295932
|
+
const value2 = Number.parseInt(attrValue(match[0], "val") ?? "", 10);
|
|
295933
|
+
if (Number.isInteger(value2))
|
|
295934
|
+
used.add(value2);
|
|
295935
|
+
}
|
|
295936
|
+
const ids = [];
|
|
295937
|
+
for (let i2 = 0;i2 < count; i2 += 1) {
|
|
295938
|
+
let candidate2 = Math.max(1, Math.floor(Math.random() * MAX_SDT_ID));
|
|
295939
|
+
while (used.has(candidate2))
|
|
295940
|
+
candidate2 = candidate2 >= MAX_SDT_ID ? 1 : candidate2 + 1;
|
|
295941
|
+
used.add(candidate2);
|
|
295942
|
+
ids.push(candidate2);
|
|
295943
|
+
}
|
|
295944
|
+
return ids;
|
|
295945
|
+
}
|
|
295946
|
+
function ensureW15Namespace(documentXml) {
|
|
295947
|
+
return documentXml.replace(/<w:document\b[^>]*>/, (openTag) => {
|
|
295948
|
+
let next = openTag;
|
|
295949
|
+
if (!/\sxmlns:w15\s*=/.test(next))
|
|
295950
|
+
next = next.replace(/>$/, ` xmlns:w15="${W15_NS}">`);
|
|
295951
|
+
const ignorable = /\smc:Ignorable\s*=\s*(["'])([^"']*)\1/.exec(next);
|
|
295952
|
+
if (!ignorable)
|
|
295953
|
+
return next;
|
|
295954
|
+
const prefixes = ignorable[2].split(/\s+/).filter(Boolean);
|
|
295955
|
+
if (prefixes.includes("w15"))
|
|
295956
|
+
return next;
|
|
295957
|
+
return next.replace(ignorable[0], ` mc:Ignorable="${[...prefixes, "w15"].join(" ")}"`);
|
|
295958
|
+
});
|
|
295959
|
+
}
|
|
295960
|
+
function readDocumentXml(context) {
|
|
295961
|
+
const xml = readPartXml(context, DOCUMENT_PART_URI5);
|
|
295962
|
+
if (!xml)
|
|
295963
|
+
throw operationError("PRECONDITION_FAILED", "document.xml bytes are unavailable.");
|
|
295964
|
+
return xml;
|
|
295965
|
+
}
|
|
295966
|
+
function findParagraphById2(documentXml, blockId) {
|
|
295967
|
+
const paraRe = /<w:p\b[^>]*>[\s\S]*?<\/w:p>/g;
|
|
295968
|
+
for (let match = paraRe.exec(documentXml);match; match = paraRe.exec(documentXml)) {
|
|
295969
|
+
if (match[0].includes(`w14:paraId="${blockId}"`))
|
|
295970
|
+
return { start: match.index, end: paraRe.lastIndex, xml: match[0], blockId };
|
|
295971
|
+
}
|
|
295972
|
+
return null;
|
|
295973
|
+
}
|
|
295974
|
+
function findParagraphContaining2(documentXml, index) {
|
|
295975
|
+
const paraRe = /<w:p\b[^>]*>[\s\S]*?<\/w:p>/g;
|
|
295976
|
+
for (let match = paraRe.exec(documentXml);match; match = paraRe.exec(documentXml)) {
|
|
295977
|
+
if (match.index <= index && paraRe.lastIndex >= index) {
|
|
295978
|
+
const open = /^<w:p\b[^>]*>/.exec(match[0])?.[0] ?? "";
|
|
295979
|
+
return {
|
|
295980
|
+
start: match.index,
|
|
295981
|
+
end: paraRe.lastIndex,
|
|
295982
|
+
xml: match[0],
|
|
295983
|
+
blockId: attrValue(open, "paraId") ?? "unknown"
|
|
295984
|
+
};
|
|
295985
|
+
}
|
|
295986
|
+
}
|
|
295987
|
+
return null;
|
|
295988
|
+
}
|
|
295989
|
+
function unwrapSdt(sdtXml) {
|
|
295990
|
+
const open = /<w:sdtContent\b[^>]*>/.exec(sdtXml);
|
|
295991
|
+
if (!open)
|
|
295992
|
+
return null;
|
|
295993
|
+
if (/\/\s*>$/.test(open[0]))
|
|
295994
|
+
return "";
|
|
295995
|
+
const contentStart = open.index + open[0].length;
|
|
295996
|
+
const tokenRe = /<w:sdtContent\b[^>]*>|<\/w:sdtContent>/g;
|
|
295997
|
+
tokenRe.lastIndex = contentStart;
|
|
295998
|
+
let depth = 0;
|
|
295999
|
+
for (let match = tokenRe.exec(sdtXml);match; match = tokenRe.exec(sdtXml)) {
|
|
296000
|
+
if (match[0].startsWith("</")) {
|
|
296001
|
+
if (depth === 0)
|
|
296002
|
+
return sdtXml.slice(contentStart, match.index);
|
|
296003
|
+
depth -= 1;
|
|
296004
|
+
} else if (!/\/\s*>$/.test(match[0])) {
|
|
296005
|
+
depth += 1;
|
|
296006
|
+
}
|
|
296007
|
+
}
|
|
296008
|
+
return null;
|
|
296009
|
+
}
|
|
296010
|
+
function replaceRange2(xml, start, end, replacement) {
|
|
296011
|
+
return `${xml.slice(0, start)}${replacement}${xml.slice(end)}`;
|
|
296012
|
+
}
|
|
296013
|
+
function toFlatSegments(target) {
|
|
296014
|
+
if (target.story !== undefined && target.story.storyType !== "body")
|
|
296015
|
+
return null;
|
|
296016
|
+
if (target.coordinateSpace === "tracked")
|
|
296017
|
+
return null;
|
|
296018
|
+
if (target.kind === "text") {
|
|
296019
|
+
return target.segments.map((segment) => ({
|
|
296020
|
+
blockId: segment.blockId,
|
|
296021
|
+
start: segment.range.start,
|
|
296022
|
+
end: segment.range.end
|
|
296023
|
+
}));
|
|
296024
|
+
}
|
|
296025
|
+
if (target.start.kind !== "text" || target.end.kind !== "text")
|
|
296026
|
+
return null;
|
|
296027
|
+
if (target.start.blockId !== target.end.blockId)
|
|
296028
|
+
return null;
|
|
296029
|
+
return [{ blockId: target.start.blockId, start: target.start.offset, end: target.end.offset }];
|
|
296030
|
+
}
|
|
296031
|
+
function overlaps(left, right) {
|
|
296032
|
+
const leftSegments = toFlatSegments(left);
|
|
296033
|
+
const rightSegments = toFlatSegments(right);
|
|
296034
|
+
if (!leftSegments || !rightSegments)
|
|
296035
|
+
return false;
|
|
296036
|
+
return leftSegments.some((leftSegment) => rightSegments.some((rightSegment) => leftSegment.blockId === rightSegment.blockId && rangesStrictlyOverlap(leftSegment.start, leftSegment.end, rightSegment.start, rightSegment.end)));
|
|
296037
|
+
}
|
|
296038
|
+
var TEXT_ENCODER, WORD_NAMESPACE5 = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", METADATA_ANCHOR_ALIAS = "Anchored metadata", W15_NS = "http://schemas.microsoft.com/office/word/2012/wordml", MAX_SDT_ID = 2147483646;
|
|
296039
|
+
var init_adapter9 = __esm(() => {
|
|
296040
|
+
init_src3();
|
|
296041
|
+
init_sd_document_session_internal();
|
|
296042
|
+
init_visible_text();
|
|
296043
|
+
init_inline();
|
|
296044
|
+
init_adapter2();
|
|
296045
|
+
init_shared();
|
|
296046
|
+
init_xml();
|
|
296047
|
+
TEXT_ENCODER = new TextEncoder;
|
|
296048
|
+
});
|
|
296049
|
+
|
|
295221
296050
|
// ../../../v2/document-api-v2-adapter/dist/core/cooperative-slices.js
|
|
295222
296051
|
function createCooperativeSliceGate(yieldPoint, sliceTargetMs = COOPERATIVE_SLICE_TARGET_MS) {
|
|
295223
296052
|
let sliceStartedAt = now();
|
|
@@ -295605,11 +296434,14 @@ function prepareNativeCellSplit(resolved, original, columnInsertIndex) {
|
|
|
295605
296434
|
if (grids.length !== 1 || rows.length !== original.rows.length)
|
|
295606
296435
|
return null;
|
|
295607
296436
|
const grid = grids[0];
|
|
295608
|
-
|
|
296437
|
+
const originalGridChangeXml = original.tblGrid.changeXml;
|
|
296438
|
+
const gridChildren = children2(grid);
|
|
296439
|
+
const gridChanges = gridChildren.filter((range) => owns(range, "tblGridChange"));
|
|
296440
|
+
if (gridChanges.length > 1 || gridChildren.some((range) => !owns(range, "gridCol") && !owns(range, "tblGridChange")) || gridChanges[0] && source.slice(gridChanges[0].start, gridChanges[0].end) !== originalGridChangeXml)
|
|
295609
296441
|
return null;
|
|
295610
296442
|
const originalGridXml = source.slice(grid.start, grid.end);
|
|
295611
296443
|
const originalGridColumns = [...original.tblGrid.gridColXmls];
|
|
295612
|
-
const gridColumns =
|
|
296444
|
+
const gridColumns = gridChildren.filter((range) => owns(range, "gridCol"));
|
|
295613
296445
|
if (gridColumns.length !== originalGridColumns.length || columnInsertIndex < 0 || columnInsertIndex > gridColumns.length)
|
|
295614
296446
|
return null;
|
|
295615
296447
|
const rowFacts = new Map;
|
|
@@ -295712,7 +296544,7 @@ function prepareNativeCellSplit(resolved, original, columnInsertIndex) {
|
|
|
295712
296544
|
const addedColumns = model.tblGrid.gridColXmls.length - originalGridColumns.length;
|
|
295713
296545
|
if (addedColumns < 0 || originalGridColumns.some((column, index) => model.tblGrid.gridColXmls[index < columnInsertIndex ? index : index + addedColumns] !== column))
|
|
295714
296546
|
return null;
|
|
295715
|
-
if (model.tblGrid.changeXml || addedColumns) {
|
|
296547
|
+
if (model.tblGrid.changeXml !== originalGridChangeXml || addedColumns) {
|
|
295716
296548
|
const gridPatches = [];
|
|
295717
296549
|
if (addedColumns) {
|
|
295718
296550
|
const at = columnInsertIndex > 0 ? gridColumns[columnInsertIndex - 1].end : grid.openEnd;
|
|
@@ -295722,12 +296554,15 @@ function prepareNativeCellSplit(resolved, original, columnInsertIndex) {
|
|
|
295722
296554
|
xml: model.tblGrid.gridColXmls.slice(columnInsertIndex, columnInsertIndex + addedColumns).join("")
|
|
295723
296555
|
});
|
|
295724
296556
|
}
|
|
295725
|
-
if (model.tblGrid.changeXml)
|
|
296557
|
+
if (model.tblGrid.changeXml !== originalGridChangeXml) {
|
|
296558
|
+
const previousChange = gridChanges[0];
|
|
296559
|
+
const at = previousChange?.start ?? grid.closeStart;
|
|
295726
296560
|
gridPatches.push({
|
|
295727
|
-
start:
|
|
295728
|
-
end:
|
|
295729
|
-
xml: model.tblGrid.changeXml
|
|
296561
|
+
start: at,
|
|
296562
|
+
end: previousChange?.end ?? at,
|
|
296563
|
+
xml: model.tblGrid.changeXml ?? ""
|
|
295730
296564
|
});
|
|
296565
|
+
}
|
|
295731
296566
|
patches.push({ start: grid.start, end: grid.end, xml: apply(grid, gridPatches) });
|
|
295732
296567
|
}
|
|
295733
296568
|
return apply(table, patches);
|
|
@@ -301412,7 +302247,7 @@ function writeAfterPropertyXml(model, spec, wrappedXml) {
|
|
|
301412
302247
|
}
|
|
301413
302248
|
}
|
|
301414
302249
|
var COLLABORATIVE_TABLE_REWRITE_PREFIXES, TD89, EMPTY_TABLE_CONTEXT_AT_SELECTION, TRACKED_TABLE_COLUMN_RESTORE_NS2 = "urn:superdoc:tracked-table-column", DEFAULT_PAGE_WIDTH_TWIPS = 12240, DEFAULT_PAGE_MARGIN_TWIPS = 1440;
|
|
301415
|
-
var
|
|
302250
|
+
var init_adapter10 = __esm(() => {
|
|
301416
302251
|
init_src3();
|
|
301417
302252
|
init_sd_document_session_internal();
|
|
301418
302253
|
init_tracked_paragraph_body();
|
|
@@ -304178,6 +305013,8 @@ class V2BlocksAdapter {
|
|
|
304178
305013
|
const paraXml = partBytes ? TD90.decode(partBytes.subarray(resolved.entry.byteStart, resolved.entry.byteEnd)) : "";
|
|
304179
305014
|
const objectSlack = (paraXml.match(/<[\w.-]+:(?:drawing|pict|object)\b/g) ?? []).length;
|
|
304180
305015
|
const coordinateSpace = input.coordinateSpace ?? "visible";
|
|
305016
|
+
const metadataAnchorBindings = storyPartUriFromId5(resolved.storyId) === "/word/document.xml" ? listMetadataSplitBindings(this.context, paraXml) : [];
|
|
305017
|
+
const knownMetadataAnchorIds = metadataAnchorBindings.map((binding) => binding.id);
|
|
304181
305018
|
const offset = coordinateSpace === "tracked" ? Math.max(0, Math.trunc(Number.isFinite(input.offset) ? input.offset : 0)) : clampStructuralOffset(input.offset, resolved.entry.textLength + objectSlack);
|
|
304182
305019
|
if (options?.dryRun) {
|
|
304183
305020
|
const policy = this.context.validateMutation(options);
|
|
@@ -304190,7 +305027,8 @@ class V2BlocksAdapter {
|
|
|
304190
305027
|
partBytes,
|
|
304191
305028
|
paragraphByteStart: resolved.entry.byteStart,
|
|
304192
305029
|
offset,
|
|
304193
|
-
coordinateSpace
|
|
305030
|
+
coordinateSpace,
|
|
305031
|
+
knownMetadataAnchorIds
|
|
304194
305032
|
});
|
|
304195
305033
|
if (!planned.ok)
|
|
304196
305034
|
return failure4(mapRejectionReason(planned.reason), planned.reason);
|
|
@@ -304204,6 +305042,8 @@ class V2BlocksAdapter {
|
|
|
304204
305042
|
target: { storyId: resolved.storyId, paraId: input.target.nodeId },
|
|
304205
305043
|
offset,
|
|
304206
305044
|
coordinateSpace,
|
|
305045
|
+
knownMetadataAnchorIds,
|
|
305046
|
+
metadataAnchorBindings,
|
|
304207
305047
|
changeMode: options?.changeMode ?? "direct"
|
|
304208
305048
|
});
|
|
304209
305049
|
const txPerf = createSDTxPerfProbe();
|
|
@@ -305393,13 +306233,14 @@ function readTailParaId(provisionalToFinal, createdRefs) {
|
|
|
305393
306233
|
return null;
|
|
305394
306234
|
}
|
|
305395
306235
|
var TD90, PARAGRAPH_TYPES, TOP_LEVEL_LIST_ROWS_CACHE;
|
|
305396
|
-
var
|
|
306236
|
+
var init_adapter11 = __esm(() => {
|
|
305397
306237
|
init_sd_document_session_internal();
|
|
306238
|
+
init_adapter9();
|
|
305398
306239
|
init_materialize_slot();
|
|
305399
306240
|
init_adapter();
|
|
305400
306241
|
init_stories();
|
|
305401
306242
|
init_text_range_shifts();
|
|
305402
|
-
|
|
306243
|
+
init_adapter10();
|
|
305403
306244
|
init_tracked_pr_change();
|
|
305404
306245
|
init_note_story();
|
|
305405
306246
|
init_textbox_story();
|
|
@@ -305583,7 +306424,7 @@ function operationError4(code, message) {
|
|
|
305583
306424
|
error48.code = code;
|
|
305584
306425
|
return error48;
|
|
305585
306426
|
}
|
|
305586
|
-
var
|
|
306427
|
+
var init_adapter12 = __esm(() => {
|
|
305587
306428
|
init_src3();
|
|
305588
306429
|
init_sd_document_session_internal();
|
|
305589
306430
|
init_runtime2();
|
|
@@ -329448,7 +330289,7 @@ class V2ContentControlsAdapter {
|
|
|
329448
330289
|
}
|
|
329449
330290
|
}
|
|
329450
330291
|
if (input.at) {
|
|
329451
|
-
const anchor = input.at.start.kind === "text" ?
|
|
330292
|
+
const anchor = input.at.start.kind === "text" ? findParagraphById3(part.xml, input.at.start.blockId) : null;
|
|
329452
330293
|
if (anchor && /<(?:[\w.-]+:)?(?:ins|del|moveFrom|moveTo)\b/.test(anchor.xml)) {
|
|
329453
330294
|
this.requireDirectControlStructure(input, options);
|
|
329454
330295
|
}
|
|
@@ -329459,7 +330300,7 @@ class V2ContentControlsAdapter {
|
|
|
329459
330300
|
let beforeXml = "";
|
|
329460
330301
|
let namespaceBindings = new Map(Object.entries(collectXmlElementRanges(part.xml).ranges[0]?.namespaceBindings ?? {}));
|
|
329461
330302
|
if (input.at?.start.kind === "text") {
|
|
329462
|
-
const anchor =
|
|
330303
|
+
const anchor = findParagraphById3(part.xml, input.at.start.blockId);
|
|
329463
330304
|
if (anchor) {
|
|
329464
330305
|
namespaceBindings = new Map(contentControlNamespaceBindings(part.xml, anchor.start, true));
|
|
329465
330306
|
if (input.kind === "block" && extractVisibleTextFromXml2(anchor.xml).trim().length === 0) {
|
|
@@ -329501,11 +330342,11 @@ class V2ContentControlsAdapter {
|
|
|
329501
330342
|
if (wholeBlocks.kind === "failure") {
|
|
329502
330343
|
return { success: false, failure: { code: wholeBlocks.code, message: wholeBlocks.message } };
|
|
329503
330344
|
}
|
|
329504
|
-
const anchor = at.start.kind === "text" ?
|
|
330345
|
+
const anchor = at.start.kind === "text" ? findParagraphById3(part.xml, at.start.blockId) : null;
|
|
329505
330346
|
if (wholeBlocks.kind === "ok") {
|
|
329506
330347
|
const selectedXml = part.xml.slice(wholeBlocks.start, wholeBlocks.end);
|
|
329507
330348
|
const wrapped = replaceSdtContentInTemplate(sdtXml, buildInnerXml(selectedXml));
|
|
329508
|
-
nextXml =
|
|
330349
|
+
nextXml = replaceRange3(part.xml, wholeBlocks.start, wholeBlocks.end, wrapped);
|
|
329509
330350
|
targetBlockIds2 = wholeBlocks.blockIds;
|
|
329510
330351
|
} else if (anchor && at.start.kind === "text" && at.end.kind === "text" && at.start.offset !== at.end.offset && input.content === undefined && input.html === undefined && input.json === undefined) {
|
|
329511
330352
|
const splitMarker = "<sd-content-control-split/>";
|
|
@@ -329546,7 +330387,7 @@ class V2ContentControlsAdapter {
|
|
|
329546
330387
|
});
|
|
329547
330388
|
if (!prepared.ok)
|
|
329548
330389
|
return { success: false, failure: prepared.failure };
|
|
329549
|
-
nextXml =
|
|
330390
|
+
nextXml = replaceRange3(part.xml, anchor.start, anchor.end, prepared.xml);
|
|
329550
330391
|
createRefOptions = {
|
|
329551
330392
|
createdRefs: prepared.wordIds.map((entityId) => ({
|
|
329552
330393
|
kind: "trackedChange",
|
|
@@ -329555,7 +330396,7 @@ class V2ContentControlsAdapter {
|
|
|
329555
330396
|
}))
|
|
329556
330397
|
};
|
|
329557
330398
|
} else {
|
|
329558
|
-
nextXml =
|
|
330399
|
+
nextXml = replaceRange3(part.xml, anchor.start, anchor.end, replacementXml);
|
|
329559
330400
|
}
|
|
329560
330401
|
targetBlockIds2 = [at.start.blockId];
|
|
329561
330402
|
} else {
|
|
@@ -329700,7 +330541,7 @@ class V2ContentControlsAdapter {
|
|
|
329700
330541
|
const preview = this.validateDryRun(input, options, control.target);
|
|
329701
330542
|
return preview.success ? { ...preview, updatedRef } : preview;
|
|
329702
330543
|
}
|
|
329703
|
-
const nextXml =
|
|
330544
|
+
const nextXml = replaceRange3(loaded.documentXml, control.start, control.end, wrapper);
|
|
329704
330545
|
return this.commitDocument(nextXml, "content-control-wrap", input, options, control.target, {
|
|
329705
330546
|
updatedRef,
|
|
329706
330547
|
createdRefs,
|
|
@@ -329817,7 +330658,7 @@ class V2ContentControlsAdapter {
|
|
|
329817
330658
|
const updatedRef = { ...source.target, nodeId: clone3.rootId };
|
|
329818
330659
|
if (dryRunRequested(input, options))
|
|
329819
330660
|
return { success: true, contentControl: source.target, updatedRef };
|
|
329820
|
-
const withSource =
|
|
330661
|
+
const withSource = replaceRange3(loaded.documentXml, source.start, source.end, prepared.sourceXml);
|
|
329821
330662
|
const offset = destination.offset >= source.end ? destination.offset + prepared.sourceXml.length - source.xml.length : destination.offset;
|
|
329822
330663
|
const xml2 = withSource.slice(0, offset) + prepared.destinationXml + withSource.slice(offset);
|
|
329823
330664
|
return this.commitDocument(xml2, "content-control-move", input, options, source.target, {
|
|
@@ -329827,7 +330668,7 @@ class V2ContentControlsAdapter {
|
|
|
329827
330668
|
}
|
|
329828
330669
|
if (dryRunRequested(input, options))
|
|
329829
330670
|
return { success: true, contentControl: source.target };
|
|
329830
|
-
let xml =
|
|
330671
|
+
let xml = replaceRange3(loaded.documentXml, source.start, source.end, "");
|
|
329831
330672
|
const adjustedOffset = destination.offset >= source.end ? destination.offset - (source.end - source.start) : destination.offset;
|
|
329832
330673
|
const movedXml = destination.wrapInlineInParagraph && source.info.kind === "inline" ? buildParaIdParagraphXml(createParaIdAllocator(this.context)(), source.xml) : source.xml;
|
|
329833
330674
|
xml = `${xml.slice(0, adjustedOffset)}${movedXml}${xml.slice(adjustedOffset)}`;
|
|
@@ -329853,7 +330694,7 @@ class V2ContentControlsAdapter {
|
|
|
329853
330694
|
const destinationXml = rewriteContentControlMoveDestinationXml(source.xml, destinationId, createParaIdAllocator(this.context));
|
|
329854
330695
|
const sourceSideXml = wrapMoveSourceBlock(source.xml, stamp);
|
|
329855
330696
|
const destinationSideXml = wrapMoveDestinationBlock(destinationXml, stamp);
|
|
329856
|
-
const withSource =
|
|
330697
|
+
const withSource = replaceRange3(loaded.documentXml, source.start, source.end, sourceSideXml);
|
|
329857
330698
|
const inserted = insertAfterExactlyOnce(withSource, destination.xml, destinationSideXml);
|
|
329858
330699
|
if (!inserted.ok) {
|
|
329859
330700
|
return { success: false, failure: { code: "INTERNAL_ERROR", message: inserted.message } };
|
|
@@ -329880,7 +330721,7 @@ class V2ContentControlsAdapter {
|
|
|
329880
330721
|
}
|
|
329881
330722
|
moveToParagraphCaret(input, options, loaded, source) {
|
|
329882
330723
|
const blockId = typeof input.destination?.target?.nodeId === "string" ? input.destination.target.nodeId : "";
|
|
329883
|
-
const anchor =
|
|
330724
|
+
const anchor = findParagraphById3(loaded.documentXml, blockId);
|
|
329884
330725
|
if (!anchor) {
|
|
329885
330726
|
return {
|
|
329886
330727
|
success: false,
|
|
@@ -329905,7 +330746,7 @@ class V2ContentControlsAdapter {
|
|
|
329905
330746
|
requestedOffset = Math.max(beforeSource, requestedOffset - sourceVisible);
|
|
329906
330747
|
}
|
|
329907
330748
|
if (source.info.kind === "inline") {
|
|
329908
|
-
const preview =
|
|
330749
|
+
const preview = findParagraphById3(replaceRange3(loaded.documentXml, source.start, source.end, ""), blockId);
|
|
329909
330750
|
if (!preview || spliceXmlAtVisibleOffset(preview.xml, requestedOffset, source.xml).kind === "shared-run") {
|
|
329910
330751
|
return { success: false, failure: {
|
|
329911
330752
|
code: "CAPABILITY_UNAVAILABLE",
|
|
@@ -329946,8 +330787,8 @@ class V2ContentControlsAdapter {
|
|
|
329946
330787
|
}
|
|
329947
330788
|
if (dryRunRequested(input, options))
|
|
329948
330789
|
return { success: true, contentControl: source.target, updatedRef: commitOptions.updatedRef };
|
|
329949
|
-
const withoutSource =
|
|
329950
|
-
const para =
|
|
330790
|
+
const withoutSource = replaceRange3(loaded.documentXml, source.start, source.end, sourceReplacement);
|
|
330791
|
+
const para = findParagraphById3(withoutSource, blockId);
|
|
329951
330792
|
if (!para) {
|
|
329952
330793
|
return {
|
|
329953
330794
|
success: false,
|
|
@@ -329967,7 +330808,7 @@ class V2ContentControlsAdapter {
|
|
|
329967
330808
|
};
|
|
329968
330809
|
}
|
|
329969
330810
|
const updatedPara = spliced.kind === "ok" ? spliced.xml : insertXmlIntoParagraphContent(para.xml, destinationXml);
|
|
329970
|
-
nextXml =
|
|
330811
|
+
nextXml = replaceRange3(withoutSource, para.start, para.end, updatedPara);
|
|
329971
330812
|
} else {
|
|
329972
330813
|
const insertBefore = requestedOffset === 0 && extractVisibleTextFromXml2(para.xml).trim().length > 0;
|
|
329973
330814
|
nextXml = insertBefore ? `${withoutSource.slice(0, para.start)}${destinationXml}${withoutSource.slice(para.start)}` : `${withoutSource.slice(0, para.end)}${destinationXml}${withoutSource.slice(para.end)}`;
|
|
@@ -330057,7 +330898,7 @@ class V2ContentControlsAdapter {
|
|
|
330057
330898
|
return { success: false, failure: replacement.failure };
|
|
330058
330899
|
if (dryRunRequested(input, options))
|
|
330059
330900
|
return this.validateDryRun(input, options, control.target);
|
|
330060
|
-
const nextXml2 =
|
|
330901
|
+
const nextXml2 = replaceRange3(part.xml, control.start, control.end, replaceSdtContentXml(control, replacement.xml));
|
|
330061
330902
|
return this.commitDocument(nextXml2, "content-control-replace-content", input, options, control.target, {
|
|
330062
330903
|
partUri: part.partUri,
|
|
330063
330904
|
storySurface: { family: "storyBlocks", contentControlRewrite: true, targetBlockIds: [] },
|
|
@@ -330071,7 +330912,7 @@ class V2ContentControlsAdapter {
|
|
|
330071
330912
|
}
|
|
330072
330913
|
if (dryRunRequested(input, options))
|
|
330073
330914
|
return this.validateDryRun(input, options, control.target);
|
|
330074
|
-
const nextXml =
|
|
330915
|
+
const nextXml = replaceRange3(part.xml, control.start, control.end, replaceSdtContentXml(control, contentXml));
|
|
330075
330916
|
return this.commitDocument(nextXml, "content-control-replace-content", input, options, control.target, {
|
|
330076
330917
|
partUri: part.partUri,
|
|
330077
330918
|
storySurface: { family: "storyBlocks", contentControlRewrite: true, targetBlockIds: [] },
|
|
@@ -330129,7 +330970,7 @@ class V2ContentControlsAdapter {
|
|
|
330129
330970
|
if (at.start.kind !== "text" || at.end.kind !== "text" || at.start.blockId !== at.end.blockId) {
|
|
330130
330971
|
throw operationError("CAPABILITY_UNAVAILABLE", "Content-control creation requires a selection within one paragraph.");
|
|
330131
330972
|
}
|
|
330132
|
-
const paragraph4 =
|
|
330973
|
+
const paragraph4 = findParagraphById3(part.xml, at.start.blockId);
|
|
330133
330974
|
if (!paragraph4)
|
|
330134
330975
|
throw operationError("TARGET_NOT_FOUND", `Paragraph ${at.start.blockId} was not found in the target story.`);
|
|
330135
330976
|
if (![at.start.offset, at.end.offset].every((offset) => Number.isInteger(offset) && offset >= 0 && offset <= parseParagraphInlineMap(paragraph4.xml).visibleLength) || at.start.offset > at.end.offset) {
|
|
@@ -330162,7 +331003,7 @@ class V2ContentControlsAdapter {
|
|
|
330162
331003
|
return this.validateDryRun(input, options, control.target);
|
|
330163
331004
|
const part = loaded.parts.find((candidate2) => candidate2.storyId === control.storyId);
|
|
330164
331005
|
const replacement = replaceSdtContentXml(control, buildTextReplacementContentXml(value2, control.info.kind, createParaIdAllocator(this.context), control.contentXml, false));
|
|
330165
|
-
const nextXml =
|
|
331006
|
+
const nextXml = replaceRange3(part.xml, control.start, control.end, replacement);
|
|
330166
331007
|
return this.commitDocument(nextXml, "content-control-replace-content", input, options, control.target, {
|
|
330167
331008
|
partUri: part.partUri,
|
|
330168
331009
|
storySurface: { family: "storyBlocks", contentControlRewrite: true, targetBlockIds: [] },
|
|
@@ -330202,7 +331043,7 @@ class V2ContentControlsAdapter {
|
|
|
330202
331043
|
createdRefs: [{ kind: "trackedChange", entityId: String(stamp.revisionId), storyId: body.storyId }]
|
|
330203
331044
|
};
|
|
330204
331045
|
}
|
|
330205
|
-
const nextXml =
|
|
331046
|
+
const nextXml = replaceRange3(loaded.documentXml, control.start, control.end, replacement);
|
|
330206
331047
|
return this.commitDocument(nextXml, "content-control-pr", input, options, control.target, commitOptions);
|
|
330207
331048
|
}
|
|
330208
331049
|
setChoiceListItems(input, options) {
|
|
@@ -330424,7 +331265,7 @@ class V2ContentControlsAdapter {
|
|
|
330424
331265
|
replacement = prepared.xml;
|
|
330425
331266
|
createdRefs = prepared.wordIds.map((entityId) => ({ kind: "trackedChange", entityId, storyId: control.storyId }));
|
|
330426
331267
|
}
|
|
330427
|
-
const nextXml =
|
|
331268
|
+
const nextXml = replaceRange3(part.xml, control.start, control.end, replacement);
|
|
330428
331269
|
return this.commitDocument(nextXml, prefix, input, options, control.target, {
|
|
330429
331270
|
partUri: part.partUri,
|
|
330430
331271
|
storySurface: { family: "storyBlocks", contentControlRewrite: true, targetBlockIds: [] },
|
|
@@ -330471,7 +331312,7 @@ class V2ContentControlsAdapter {
|
|
|
330471
331312
|
const replacement = !anchor || insertIndex <= 0 ? replaceSdtContentXml(control, `${item}${control.contentXml}`) : `${control.xml.slice(0, anchor.end - control.start)}${item}${control.xml.slice(anchor.end - control.start)}`;
|
|
330472
331313
|
if (dryRunRequested(input, options))
|
|
330473
331314
|
return { success: true, contentControl: target };
|
|
330474
|
-
const nextXml =
|
|
331315
|
+
const nextXml = replaceRange3(loaded.documentXml, control.start, control.end, replacement);
|
|
330475
331316
|
return this.commitDocument(nextXml, "content-control-repeat-insert", input, options, target, { createdRefs });
|
|
330476
331317
|
}
|
|
330477
331318
|
cloneRepeatingItem(input, options) {
|
|
@@ -330515,13 +331356,13 @@ class V2ContentControlsAdapter {
|
|
|
330515
331356
|
return this.validateDryRun(input, options, control.target);
|
|
330516
331357
|
const localEnd = item.end - control.start;
|
|
330517
331358
|
const replacement = `${control.xml.slice(0, localEnd)}${clone3}${control.xml.slice(localEnd)}`;
|
|
330518
|
-
const nextXml =
|
|
331359
|
+
const nextXml = replaceRange3(loaded.documentXml, control.start, control.end, replacement);
|
|
330519
331360
|
return this.commitDocument(nextXml, "content-control-repeat-clone", input, options, control.target, { createdRefs });
|
|
330520
331361
|
}
|
|
330521
331362
|
deleteRepeatingItem(input, options) {
|
|
330522
331363
|
return this.mutateControl(input.target, input, options, (control, loaded) => {
|
|
330523
331364
|
const item = this.repeatingItems(control, loaded)[input.index];
|
|
330524
|
-
return
|
|
331365
|
+
return replaceRange3(control.xml, item.start - control.start, item.end - control.start, "");
|
|
330525
331366
|
}, "content-control-repeat-delete", (control, loaded) => {
|
|
330526
331367
|
if (control.info.controlType !== "repeatingSection") {
|
|
330527
331368
|
throw operationError("INVALID_TARGET", "contentControls.repeatingSection operation requires control type repeatingSection.");
|
|
@@ -331790,7 +332631,7 @@ function unwrapSdtXml(sdtXml) {
|
|
|
331790
332631
|
const contentRange = findDirectSdtChildRange(sdtXml, "sdtContent");
|
|
331791
332632
|
return contentRange ? sdtXml.slice(contentRange.openEnd, contentRange.closeStart) : "";
|
|
331792
332633
|
}
|
|
331793
|
-
function
|
|
332634
|
+
function replaceRange3(xml, start, end, replacement) {
|
|
331794
332635
|
return `${xml.slice(0, start)}${replacement}${xml.slice(end)}`;
|
|
331795
332636
|
}
|
|
331796
332637
|
function resolveContentControlMoveDestination(loaded, destination) {
|
|
@@ -332332,7 +333173,7 @@ function wrapSelectionInXml(context, documentXml, target, sdtXml, kind, replacem
|
|
|
332332
333173
|
if (target?.kind !== "selection" || target.start?.kind !== "text" || target.end?.kind !== "text") {
|
|
332333
333174
|
return { ok: false, failure: { code: "INVALID_TARGET", message: "A text selection is required." } };
|
|
332334
333175
|
}
|
|
332335
|
-
const para =
|
|
333176
|
+
const para = findParagraphById3(documentXml, target.start.blockId);
|
|
332336
333177
|
if (!para)
|
|
332337
333178
|
return { ok: false, failure: { code: "TARGET_NOT_FOUND", message: "Target paragraph was not found." } };
|
|
332338
333179
|
if (kind === "inline" && target.start.offset === target.end.offset) {
|
|
@@ -332349,12 +333190,12 @@ function wrapSelectionInXml(context, documentXml, target, sdtXml, kind, replacem
|
|
|
332349
333190
|
const insertXml = replaceSdtContentInTemplate(sdtXml, buildReplacementContentXml2(hasReplacementContent ? replacementContent : ""));
|
|
332350
333191
|
const spliced = spliceXmlAtVisibleOffset(para.xml, target.start.offset, insertXml);
|
|
332351
333192
|
if (spliced.kind === "ok") {
|
|
332352
|
-
return { ok: true, xml:
|
|
333193
|
+
return { ok: true, xml: replaceRange3(documentXml, para.start, para.end, spliced.xml) };
|
|
332353
333194
|
}
|
|
332354
333195
|
if (spliced.kind === "empty") {
|
|
332355
333196
|
return {
|
|
332356
333197
|
ok: true,
|
|
332357
|
-
xml:
|
|
333198
|
+
xml: replaceRange3(documentXml, para.start, para.end, insertXmlIntoParagraphContent(para.xml, insertXml))
|
|
332358
333199
|
};
|
|
332359
333200
|
}
|
|
332360
333201
|
return {
|
|
@@ -332384,7 +333225,7 @@ function wrapSelectionInXml(context, documentXml, target, sdtXml, kind, replacem
|
|
|
332384
333225
|
close: template.close
|
|
332385
333226
|
});
|
|
332386
333227
|
if (wrappedRuns.ok) {
|
|
332387
|
-
return { ok: true, xml:
|
|
333228
|
+
return { ok: true, xml: replaceRange3(documentXml, para.start, para.end, wrappedRuns.xml) };
|
|
332388
333229
|
}
|
|
332389
333230
|
return { ok: false, failure: { code: "CAPABILITY_UNAVAILABLE", message: "Content-control selection spans unsupported inline structures." } };
|
|
332390
333231
|
}
|
|
@@ -332396,7 +333237,7 @@ function wrapSelectionInXml(context, documentXml, target, sdtXml, kind, replacem
|
|
|
332396
333237
|
replacementXml: replaceSdtContentInTemplate(sdtXml, buildReplacementContentXml2(replacementContent))
|
|
332397
333238
|
});
|
|
332398
333239
|
if (replaced.ok) {
|
|
332399
|
-
return { ok: true, xml:
|
|
333240
|
+
return { ok: true, xml: replaceRange3(documentXml, para.start, para.end, replaced.xml) };
|
|
332400
333241
|
}
|
|
332401
333242
|
return {
|
|
332402
333243
|
ok: false,
|
|
@@ -332412,7 +333253,7 @@ function wrapSelectionInXml(context, documentXml, target, sdtXml, kind, replacem
|
|
|
332412
333253
|
});
|
|
332413
333254
|
if (wrapped === para.xml)
|
|
332414
333255
|
return { ok: false, failure: { code: "CAPABILITY_UNAVAILABLE", message: "Content-control selection spans unsupported inline structures." } };
|
|
332415
|
-
return { ok: true, xml:
|
|
333256
|
+
return { ok: true, xml: replaceRange3(documentXml, para.start, para.end, wrapped) };
|
|
332416
333257
|
}
|
|
332417
333258
|
function splitSdtTemplateAroundContent(sdtXml) {
|
|
332418
333259
|
const sdtRange = findFirstSdtElementRange(sdtXml);
|
|
@@ -332436,7 +333277,7 @@ function insertBlockContentControlAtSelection(documentXml, paragraphs, target, s
|
|
|
332436
333277
|
throw operationError("TARGET_NOT_FOUND", "Target paragraph was not found.");
|
|
332437
333278
|
const collapsed = target.start.blockId === target.end.blockId && target.start.offset === target.end.offset;
|
|
332438
333279
|
if (collapsed && extractVisibleTextFromXml2(anchor.xml).trim().length === 0) {
|
|
332439
|
-
return
|
|
333280
|
+
return replaceRange3(documentXml, anchor.start, anchor.end, sdtXml);
|
|
332440
333281
|
}
|
|
332441
333282
|
return `${documentXml.slice(0, anchor.end)}${sdtXml}${documentXml.slice(anchor.end)}`;
|
|
332442
333283
|
}
|
|
@@ -332565,7 +333406,7 @@ function findFirstSdtElementRange(xml) {
|
|
|
332565
333406
|
}
|
|
332566
333407
|
return null;
|
|
332567
333408
|
}
|
|
332568
|
-
function
|
|
333409
|
+
function findParagraphById3(documentXml, blockId) {
|
|
332569
333410
|
const paraRe = /<w:p\b[^>]*?(?:\/>|>[\s\S]*?<\/w:p>)/g;
|
|
332570
333411
|
for (let match = paraRe.exec(documentXml);match; match = paraRe.exec(documentXml)) {
|
|
332571
333412
|
if (match[0].includes(`w14:paraId="${blockId}"`)) {
|
|
@@ -332679,7 +333520,7 @@ function replaceTextRangeInParagraph2(paragraphXml, start, end, replacement) {
|
|
|
332679
333520
|
return paragraphXml;
|
|
332680
333521
|
}
|
|
332681
333522
|
var DEFAULT_CHECKED, DEFAULT_UNCHECKED, SECONDARY_STORY_MUTATION_MESSAGE = "Content control mutations outside the document body are not supported by this adapter.", TYPE_TAGS, COOPERATIVE_PARSE_SLICE_PARAGRAPHS = 128, COOPERATIVE_PARSE_SLICE_CONTROLS = 16, RAW_ATTRIBUTE_PATTERN;
|
|
332682
|
-
var
|
|
333523
|
+
var init_adapter13 = __esm(() => {
|
|
332683
333524
|
init_sd_document_session_internal();
|
|
332684
333525
|
init_src6();
|
|
332685
333526
|
init_part();
|
|
@@ -332856,7 +333697,7 @@ var init_tracked_regeneration = __esm(() => {
|
|
|
332856
333697
|
init_tracked_pr_change();
|
|
332857
333698
|
init_runtime2();
|
|
332858
333699
|
init_xml();
|
|
332859
|
-
|
|
333700
|
+
init_adapter14();
|
|
332860
333701
|
});
|
|
332861
333702
|
|
|
332862
333703
|
// ../../../v2/document-api-v2-adapter/dist/captions/tracked-commit.js
|
|
@@ -333156,8 +333997,8 @@ var nativeStamp = (stamp) => ({
|
|
|
333156
333997
|
});
|
|
333157
333998
|
var init_tracked_generated_paragraph = __esm(() => {
|
|
333158
333999
|
init_sd_document_session_internal();
|
|
333159
|
-
init_adapter15();
|
|
333160
334000
|
init_adapter16();
|
|
334001
|
+
init_adapter17();
|
|
333161
334002
|
init_tracked_commit();
|
|
333162
334003
|
init_tracked_paragraph();
|
|
333163
334004
|
init_paragraph_ids();
|
|
@@ -334048,7 +334889,7 @@ function operationError5(code2, message) {
|
|
|
334048
334889
|
return error48;
|
|
334049
334890
|
}
|
|
334050
334891
|
var EMPTY_TOC_CONTEXT_AT_SELECTION, TOC_CONFIGURABLE_SWITCH_FLAGS, TOC_SWITCH_FRAGMENT_RE;
|
|
334051
|
-
var
|
|
334892
|
+
var init_adapter14 = __esm(() => {
|
|
334052
334893
|
init_tracked_regeneration();
|
|
334053
334894
|
init_removal();
|
|
334054
334895
|
init_deletion_locks();
|
|
@@ -334225,7 +335066,7 @@ var init_tracked_creation = __esm(() => {
|
|
|
334225
335066
|
init_tracked_pr_change();
|
|
334226
335067
|
init_runtime2();
|
|
334227
335068
|
init_xml();
|
|
334228
|
-
|
|
335069
|
+
init_adapter14();
|
|
334229
335070
|
});
|
|
334230
335071
|
|
|
334231
335072
|
// ../../../v2/document-api-v2-adapter/dist/sections/adapter.js
|
|
@@ -334739,7 +335580,7 @@ function documentFailure(message, code2 = "CAPABILITY_UNAVAILABLE") {
|
|
|
334739
335580
|
return { success: false, failure: { code: code2, message } };
|
|
334740
335581
|
}
|
|
334741
335582
|
var VALID_BREAK_TYPES, VALID_PAGE_NUMBER_FORMATS, VALID_LINE_NUMBER_RESTARTS, VALID_VERTICAL_ALIGNS, VALID_PAGE_BORDER_DISPLAYS, VALID_PAGE_BORDER_OFFSETS, VALID_PAGE_BORDER_Z_ORDERS;
|
|
334742
|
-
var
|
|
335583
|
+
var init_adapter15 = __esm(() => {
|
|
334743
335584
|
init_src3();
|
|
334744
335585
|
init_sd_document_session_internal();
|
|
334745
335586
|
init_document_reader();
|
|
@@ -335869,20 +336710,20 @@ function storyErrorMessage3(error48) {
|
|
|
335869
336710
|
}
|
|
335870
336711
|
}
|
|
335871
336712
|
var VALUED_TOC_SWITCHES;
|
|
335872
|
-
var
|
|
336713
|
+
var init_adapter16 = __esm(() => {
|
|
335873
336714
|
init_sd_document_session_internal();
|
|
335874
336715
|
init_sd_document_session_internal();
|
|
335875
336716
|
init_materialize_slot();
|
|
335876
|
-
|
|
336717
|
+
init_adapter13();
|
|
335877
336718
|
init_adapter();
|
|
335878
336719
|
init_runtime2();
|
|
335879
336720
|
init_xml();
|
|
335880
336721
|
init_section_xml();
|
|
335881
|
-
|
|
336722
|
+
init_adapter10();
|
|
335882
336723
|
init_xml3();
|
|
335883
|
-
init_adapter13();
|
|
335884
|
-
init_tracked_creation();
|
|
335885
336724
|
init_adapter14();
|
|
336725
|
+
init_tracked_creation();
|
|
336726
|
+
init_adapter15();
|
|
335886
336727
|
init_note_story();
|
|
335887
336728
|
init_textbox_story();
|
|
335888
336729
|
init_src6();
|
|
@@ -336542,11 +337383,11 @@ function operationError6(code2, message) {
|
|
|
336542
337383
|
error48.code = code2;
|
|
336543
337384
|
return error48;
|
|
336544
337385
|
}
|
|
336545
|
-
var
|
|
337386
|
+
var init_adapter17 = __esm(() => {
|
|
336546
337387
|
init_src3();
|
|
336547
337388
|
init_sd_document_session_internal();
|
|
336548
337389
|
init_document_reader();
|
|
336549
|
-
|
|
337390
|
+
init_adapter16();
|
|
336550
337391
|
init_composite();
|
|
336551
337392
|
init_paragraph_ids();
|
|
336552
337393
|
init_xml();
|
|
@@ -346256,7 +347097,7 @@ function commitTrackedImageCaption(context, change, options) {
|
|
|
346256
347097
|
});
|
|
346257
347098
|
}
|
|
346258
347099
|
var init_tracked_caption = __esm(() => {
|
|
346259
|
-
|
|
347100
|
+
init_adapter17();
|
|
346260
347101
|
init_tracked_commit();
|
|
346261
347102
|
init_tracked_paragraph();
|
|
346262
347103
|
init_paragraph_ids();
|
|
@@ -350168,7 +351009,7 @@ function escapeRegExp17(value2) {
|
|
|
350168
351009
|
return value2.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
350169
351010
|
}
|
|
350170
351011
|
var IMAGE_HYPERLINK_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", EMU_PER_PX5 = 9525, CROP_SCALE2 = 1000, DEFAULT_FLOATING_RELATIVE_HEIGHT = 251659264, DECORATIVE_EXT_URI = "{C183D7F6-B498-43B3-948B-1728B52AA6E4}", DECORATIVE_NAMESPACE = "http://schemas.microsoft.com/office/drawing/2017/decorative", DRAWING_NAMESPACE = "http://schemas.openxmlformats.org/drawingml/2006/main", RELATIONSHIP_NAMESPACE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships", CONVERTED_INLINE_ANCHORS, DEFAULT_PAGE_WIDTH_TWIPS2 = 12240, DEFAULT_PAGE_MARGIN_TWIPS2 = 1440, TWIPS_PER_PX = 15;
|
|
350171
|
-
var
|
|
351012
|
+
var init_adapter18 = __esm(() => {
|
|
350172
351013
|
init_pending_image_insertion();
|
|
350173
351014
|
init_src3();
|
|
350174
351015
|
init_sd_document_session_internal();
|
|
@@ -350185,7 +351026,7 @@ var init_adapter17 = __esm(() => {
|
|
|
350185
351026
|
init_receipt_entities();
|
|
350186
351027
|
init_xml_rewrite();
|
|
350187
351028
|
init_public_model();
|
|
350188
|
-
|
|
351029
|
+
init_adapter16();
|
|
350189
351030
|
init_adapter3();
|
|
350190
351031
|
init_runtime2();
|
|
350191
351032
|
init_tracked_caption();
|
|
@@ -350459,7 +351300,7 @@ function projectOperationCapabilities(context) {
|
|
|
350459
351300
|
return out;
|
|
350460
351301
|
}
|
|
350461
351302
|
var V2_SUPPORTED_STEP_OPS, V2_SUPPORTED_NON_UNIFORM_STRATEGIES, V2_SUPPORTED_SET_MARKS, V2_REGEX_LIMITS;
|
|
350462
|
-
var
|
|
351303
|
+
var init_adapter19 = __esm(() => {
|
|
350463
351304
|
init_src3();
|
|
350464
351305
|
init_search();
|
|
350465
351306
|
init_support_contract();
|
|
@@ -350468,8 +351309,8 @@ var init_adapter18 = __esm(() => {
|
|
|
350468
351309
|
init_rich_fragment_apply();
|
|
350469
351310
|
init_digest();
|
|
350470
351311
|
init_registry3();
|
|
350471
|
-
|
|
350472
|
-
|
|
351312
|
+
init_adapter18();
|
|
351313
|
+
init_adapter10();
|
|
350473
351314
|
V2_SUPPORTED_STEP_OPS = MUTATION_PLAN_SUPPORTED_STEP_OPS;
|
|
350474
351315
|
V2_SUPPORTED_NON_UNIFORM_STRATEGIES = Object.freeze([]);
|
|
350475
351316
|
V2_SUPPORTED_SET_MARKS = Object.freeze([]);
|
|
@@ -351092,10 +351933,10 @@ function operationError8(code2, message) {
|
|
|
351092
351933
|
error48.code = code2;
|
|
351093
351934
|
return error48;
|
|
351094
351935
|
}
|
|
351095
|
-
var
|
|
351936
|
+
var init_adapter20 = __esm(() => {
|
|
351096
351937
|
init_src3();
|
|
351097
351938
|
init_sd_document_session_internal();
|
|
351098
|
-
|
|
351939
|
+
init_adapter16();
|
|
351099
351940
|
init_adapter8();
|
|
351100
351941
|
init_tracked_generated_paragraph();
|
|
351101
351942
|
init_tracked_pr_change();
|
|
@@ -353391,7 +354232,7 @@ class V2CommentsAdapter {
|
|
|
353391
354232
|
function notImplemented(message) {
|
|
353392
354233
|
return { success: false, failure: { code: "CAPABILITY_UNAVAILABLE", message } };
|
|
353393
354234
|
}
|
|
353394
|
-
var
|
|
354235
|
+
var init_adapter21 = __esm(() => {
|
|
353395
354236
|
init_create2();
|
|
353396
354237
|
init_edit();
|
|
353397
354238
|
init_move();
|
|
@@ -353680,7 +354521,7 @@ function operationError9(code2, message) {
|
|
|
353680
354521
|
error48.code = code2;
|
|
353681
354522
|
return error48;
|
|
353682
354523
|
}
|
|
353683
|
-
var
|
|
354524
|
+
var init_adapter22 = __esm(() => {
|
|
353684
354525
|
init_src3();
|
|
353685
354526
|
init_adapter8();
|
|
353686
354527
|
init_inline();
|
|
@@ -354422,7 +355263,7 @@ var TD99, TE56, SETTINGS_PART_URI4 = "/word/settings.xml", WORDPROCESSINGML_NS3
|
|
|
354422
355263
|
var init_definitions = __esm(() => {
|
|
354423
355264
|
init_src2();
|
|
354424
355265
|
init_sd_document_session_internal();
|
|
354425
|
-
|
|
355266
|
+
init_adapter15();
|
|
354426
355267
|
init_part();
|
|
354427
355268
|
TD99 = new TextDecoder("utf-8", { fatal: false });
|
|
354428
355269
|
TE56 = new TextEncoder;
|
|
@@ -356285,13 +357126,13 @@ function recordWhole(overlapsByFragment, entry, logical) {
|
|
|
356285
357126
|
});
|
|
356286
357127
|
}
|
|
356287
357128
|
function normalizeNestedOverlaps(overlapsByFragment, rangeByFragment) {
|
|
356288
|
-
const
|
|
357129
|
+
const overlaps2 = Array.from(overlapsByFragment.values());
|
|
356289
357130
|
const remove = new Set;
|
|
356290
|
-
for (const parent of
|
|
357131
|
+
for (const parent of overlaps2) {
|
|
356291
357132
|
const parentRange = rangeByFragment.get(fragmentKey(parent.fragment));
|
|
356292
357133
|
if (!parentRange || parent.coverage !== "partial")
|
|
356293
357134
|
continue;
|
|
356294
|
-
for (const child of
|
|
357135
|
+
for (const child of overlaps2) {
|
|
356295
357136
|
if (child === parent)
|
|
356296
357137
|
continue;
|
|
356297
357138
|
const childRange = rangeByFragment.get(fragmentKey(child.fragment));
|
|
@@ -356316,7 +357157,7 @@ function normalizeNestedOverlaps(overlapsByFragment, rangeByFragment) {
|
|
|
356316
357157
|
}
|
|
356317
357158
|
return {
|
|
356318
357159
|
ok: true,
|
|
356319
|
-
overlaps:
|
|
357160
|
+
overlaps: overlaps2.filter((overlap) => !remove.has(fragmentKey(overlap.fragment)))
|
|
356320
357161
|
};
|
|
356321
357162
|
}
|
|
356322
357163
|
function fragmentKey(fragment3) {
|
|
@@ -357419,12 +358260,12 @@ function pushTextTarget(targets, seen, target) {
|
|
|
357419
358260
|
seen.add(key2);
|
|
357420
358261
|
targets.push(target);
|
|
357421
358262
|
}
|
|
357422
|
-
function shouldExpandWholePairedReplacementSide(overlap,
|
|
358263
|
+
function shouldExpandWholePairedReplacementSide(overlap, overlaps2) {
|
|
357423
358264
|
const logical = overlap.logical;
|
|
357424
358265
|
if (overlap.coverage !== "whole" || !logical || logical.type !== "replacement" || !logical.sides?.inserted || !logical.sides.deleted) {
|
|
357425
358266
|
return false;
|
|
357426
358267
|
}
|
|
357427
|
-
const sameLogicalOverlaps =
|
|
358268
|
+
const sameLogicalOverlaps = overlaps2.filter((candidate2) => candidate2.logical?.id === logical.id);
|
|
357428
358269
|
return !sameLogicalOverlaps.some((candidate2) => candidate2.coverage === "partial");
|
|
357429
358270
|
}
|
|
357430
358271
|
function isLogicalRangeDecideTarget(target) {
|
|
@@ -358179,7 +359020,7 @@ function extractStructuralCellTexts(xml, side) {
|
|
|
358179
359020
|
}
|
|
358180
359021
|
function extractStructuralText(xml, side) {
|
|
358181
359022
|
const readText = side === "deleted" ? extractTrackedTextFromXml : extractVisibleTextFromXml2;
|
|
358182
|
-
const paragraphs = scanParagraphXmlSpans({ bytes:
|
|
359023
|
+
const paragraphs = scanParagraphXmlSpans({ bytes: TEXT_ENCODER2.encode(xml) });
|
|
358183
359024
|
if (paragraphs.length === 0)
|
|
358184
359025
|
return readText(xml);
|
|
358185
359026
|
return paragraphs.map((paragraph4) => readText(paragraph4.xml).trim()).filter(Boolean).join(`
|
|
@@ -358754,8 +359595,8 @@ function structuralFieldSemanticSubtype(entry, context, resolveSession) {
|
|
|
358754
359595
|
if (!partBytes)
|
|
358755
359596
|
return null;
|
|
358756
359597
|
const partXml = decodeTrackedChangePartXml(partBytes, entry.partUri, resolveSession);
|
|
358757
|
-
const entryByteStart =
|
|
358758
|
-
const entryByteEnd =
|
|
359598
|
+
const entryByteStart = TEXT_ENCODER2.encode(partXml.slice(0, entry.documentOrderStart)).byteLength;
|
|
359599
|
+
const entryByteEnd = TEXT_ENCODER2.encode(partXml.slice(0, entry.documentOrderEnd)).byteLength;
|
|
358759
359600
|
const fields = catalog.fields.filter((candidate2) => candidate2.complete && candidate2.byteStart >= entryByteStart && candidate2.byteEnd <= entryByteEnd);
|
|
358760
359601
|
const field = fields.length === 1 ? fields[0] : undefined;
|
|
358761
359602
|
const subtype = field && field.classification !== "unknown" ? field.classification : null;
|
|
@@ -359090,8 +359931,8 @@ function createSuccessorRsidAllocator(raw) {
|
|
|
359090
359931
|
return counter.toString(16).toUpperCase().padStart(8, "0");
|
|
359091
359932
|
};
|
|
359092
359933
|
}
|
|
359093
|
-
var resolvedTrackedChangeIdsBySession,
|
|
359094
|
-
var
|
|
359934
|
+
var resolvedTrackedChangeIdsBySession, TEXT_ENCODER2, EMUS_PER_CSS_PIXEL = 9525, BROWSER_RENDERABLE_IMAGE_CONTENT_TYPES, DocumentApiAdapterError, STRUCTURAL_DESCRIPTOR_OPERATIONS;
|
|
359935
|
+
var init_adapter23 = __esm(() => {
|
|
359095
359936
|
init_review_read_model();
|
|
359096
359937
|
init_review_read_model();
|
|
359097
359938
|
init_src3();
|
|
@@ -359107,7 +359948,7 @@ var init_adapter22 = __esm(() => {
|
|
|
359107
359948
|
init_logical_view_cache();
|
|
359108
359949
|
init_local_text_projection();
|
|
359109
359950
|
resolvedTrackedChangeIdsBySession = new WeakMap;
|
|
359110
|
-
|
|
359951
|
+
TEXT_ENCODER2 = new TextEncoder;
|
|
359111
359952
|
BROWSER_RENDERABLE_IMAGE_CONTENT_TYPES = new Map([
|
|
359112
359953
|
["png", "image/png"],
|
|
359113
359954
|
["jpg", "image/jpeg"],
|
|
@@ -361960,7 +362801,7 @@ var init_legacy_body = __esm(() => {
|
|
|
361960
362801
|
init_src3();
|
|
361961
362802
|
init_document_reader();
|
|
361962
362803
|
init_adapter();
|
|
361963
|
-
|
|
362804
|
+
init_adapter23();
|
|
361964
362805
|
init_sd_document_session_internal();
|
|
361965
362806
|
init_payloads();
|
|
361966
362807
|
});
|
|
@@ -364818,13 +365659,13 @@ function stripRootReplayNamespaceDeclarations(xml) {
|
|
|
364818
365659
|
return stripReplayNamespaceDeclarations(xml.slice(0, openEnd)) + xml.slice(openEnd);
|
|
364819
365660
|
}
|
|
364820
365661
|
var FULL_DIFF_APPLY_SUPPORTED_FAMILIES, TE65, TD109, DOCUMENT_PART_URI6 = "/word/document.xml", NUMBERING_PART_URI4 = "/word/numbering.xml", EMPTY_MAIN_DOCUMENT_SOURCE, WORDPROCESSINGML_NS7 = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", WORDPROCESSINGML_2010_NS2 = "http://schemas.microsoft.com/office/word/2010/wordml", WORDPROCESSING_MATH_NS = "http://schemas.openxmlformats.org/officeDocument/2006/math", MARKUP_COMPATIBILITY_NS3 = "http://schemas.openxmlformats.org/markup-compatibility/2006", VML_NS = "urn:schemas-microsoft-com:vml", STRUCTURAL_PARA_EDIT_DELETE_WML_NAMES, STRUCTURAL_PARA_EDIT_DELETE_MATH_NAMES, STRUCTURAL_PARA_FORMAT_EDIT_WML_NAMES;
|
|
364821
|
-
var
|
|
365662
|
+
var init_adapter24 = __esm(() => {
|
|
364822
365663
|
init_tracked_table_property_replay();
|
|
364823
365664
|
init_src2();
|
|
364824
365665
|
init_compare();
|
|
364825
365666
|
init_sd_document_session_internal();
|
|
364826
365667
|
init_section_xml();
|
|
364827
|
-
|
|
365668
|
+
init_adapter23();
|
|
364828
365669
|
init_header_footer_lifecycle();
|
|
364829
365670
|
init_errors8();
|
|
364830
365671
|
init_main_document_revision_closure();
|
|
@@ -364932,7 +365773,7 @@ class V2ExportAdapter {
|
|
|
364932
365773
|
};
|
|
364933
365774
|
}
|
|
364934
365775
|
}
|
|
364935
|
-
var
|
|
365776
|
+
var init_adapter25 = __esm(() => {
|
|
364936
365777
|
init_src3();
|
|
364937
365778
|
init_sd_document_session_internal();
|
|
364938
365779
|
});
|
|
@@ -365393,9 +366234,9 @@ function operationError10(code2, message) {
|
|
|
365393
366234
|
error48.code = code2;
|
|
365394
366235
|
return error48;
|
|
365395
366236
|
}
|
|
365396
|
-
var
|
|
366237
|
+
var init_adapter26 = __esm(() => {
|
|
365397
366238
|
init_src3();
|
|
365398
|
-
|
|
366239
|
+
init_adapter16();
|
|
365399
366240
|
init_adapter8();
|
|
365400
366241
|
init_tracked_field_prefix();
|
|
365401
366242
|
init_tracked_generated_paragraph();
|
|
@@ -370442,7 +371283,7 @@ function readCreatedParagraphRefId(createdRefs, provisionalToFinal) {
|
|
|
370442
371283
|
return null;
|
|
370443
371284
|
}
|
|
370444
371285
|
var LISTS_XML_DECODER, BULLET_GLYPH_BY_LEVEL;
|
|
370445
|
-
var
|
|
371286
|
+
var init_adapter27 = __esm(() => {
|
|
370446
371287
|
init_src3();
|
|
370447
371288
|
init_sd_document_session_internal();
|
|
370448
371289
|
init_adapter();
|
|
@@ -370450,7 +371291,7 @@ var init_adapter26 = __esm(() => {
|
|
|
370450
371291
|
init_stories();
|
|
370451
371292
|
init_text_range_shifts();
|
|
370452
371293
|
init_adapter7();
|
|
370453
|
-
|
|
371294
|
+
init_adapter23();
|
|
370454
371295
|
init_tracked_pr_change();
|
|
370455
371296
|
init_receipt_entities();
|
|
370456
371297
|
init_runtime3();
|
|
@@ -370482,7 +371323,7 @@ class V2GetTextAdapter {
|
|
|
370482
371323
|
}
|
|
370483
371324
|
}
|
|
370484
371325
|
var TD111, extractVisibleTextFromXml4;
|
|
370485
|
-
var
|
|
371326
|
+
var init_adapter28 = __esm(() => {
|
|
370486
371327
|
init_sd_document_session_internal();
|
|
370487
371328
|
init_story_identity();
|
|
370488
371329
|
init_story_surface();
|
|
@@ -370790,7 +371631,7 @@ var init_node_discovery = __esm(() => {
|
|
|
370790
371631
|
init_sd_document_session_internal();
|
|
370791
371632
|
init_document_reader();
|
|
370792
371633
|
init_paragraph();
|
|
370793
|
-
|
|
371634
|
+
init_adapter28();
|
|
370794
371635
|
init_note_story();
|
|
370795
371636
|
init_textbox_story();
|
|
370796
371637
|
init_within();
|
|
@@ -371829,7 +372670,7 @@ function txIdPrefixToOperation(prefix) {
|
|
|
371829
372670
|
}
|
|
371830
372671
|
}
|
|
371831
372672
|
var TD113, TE67;
|
|
371832
|
-
var
|
|
372673
|
+
var init_adapter29 = __esm(() => {
|
|
371833
372674
|
init_sd_document_session_internal();
|
|
371834
372675
|
init_src6();
|
|
371835
372676
|
init_materialize_slot();
|
|
@@ -373626,7 +374467,7 @@ var init_engine3 = __esm(() => {
|
|
|
373626
374467
|
init_tracked_text_search();
|
|
373627
374468
|
init_structural_rewrite_span();
|
|
373628
374469
|
init_adapter7();
|
|
373629
|
-
|
|
374470
|
+
init_adapter29();
|
|
373630
374471
|
init_adapter6();
|
|
373631
374472
|
init_composite();
|
|
373632
374473
|
init_stories();
|
|
@@ -373648,7 +374489,7 @@ class V2MutationsAdapter {
|
|
|
373648
374489
|
return applyPlan(this.context, input);
|
|
373649
374490
|
}
|
|
373650
374491
|
}
|
|
373651
|
-
var
|
|
374492
|
+
var init_adapter30 = __esm(() => {
|
|
373652
374493
|
init_engine3();
|
|
373653
374494
|
});
|
|
373654
374495
|
|
|
@@ -373782,7 +374623,7 @@ function deleteFailure(code2, message) {
|
|
|
373782
374623
|
return { success: false, failure: { code: code2, message } };
|
|
373783
374624
|
}
|
|
373784
374625
|
var OPERATION_ID = "v2-textbox-geometry";
|
|
373785
|
-
var
|
|
374626
|
+
var init_adapter31 = __esm(() => {
|
|
373786
374627
|
init_sd_document_session_internal();
|
|
373787
374628
|
init_adapter();
|
|
373788
374629
|
init_stories();
|
|
@@ -374319,7 +375160,7 @@ function containsOnlyZeroWidthReferenceTail(xml) {
|
|
|
374319
375160
|
return normalized.length === 0;
|
|
374320
375161
|
}
|
|
374321
375162
|
var TD115;
|
|
374322
|
-
var
|
|
375163
|
+
var init_adapter32 = __esm(() => {
|
|
374323
375164
|
init_sd_document_session_internal();
|
|
374324
375165
|
init_materialize_slot();
|
|
374325
375166
|
init_story_surface();
|
|
@@ -374875,9 +375716,9 @@ function operationError11(code2, message) {
|
|
|
374875
375716
|
error48.code = code2;
|
|
374876
375717
|
return error48;
|
|
374877
375718
|
}
|
|
374878
|
-
var
|
|
375719
|
+
var init_adapter33 = __esm(() => {
|
|
374879
375720
|
init_src3();
|
|
374880
|
-
|
|
375721
|
+
init_adapter16();
|
|
374881
375722
|
init_adapter8();
|
|
374882
375723
|
init_tracked_field_prefix();
|
|
374883
375724
|
init_tracked_generated_paragraph();
|
|
@@ -376215,7 +377056,7 @@ function defaultRelationshipsXml3() {
|
|
|
376215
377056
|
return '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"></Relationships>';
|
|
376216
377057
|
}
|
|
376217
377058
|
var HYPERLINK_REL_TYPE3 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", TD116, TE68;
|
|
376218
|
-
var
|
|
377059
|
+
var init_adapter34 = __esm(() => {
|
|
376219
377060
|
init_sd_document_session_internal();
|
|
376220
377061
|
init_inline();
|
|
376221
377062
|
init_adapter();
|
|
@@ -376974,12 +377815,12 @@ function failure22(code2, message) {
|
|
|
376974
377815
|
return { success: false, failure: { code: code2, message } };
|
|
376975
377816
|
}
|
|
376976
377817
|
var IMAGE_REL = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", RELATIONSHIPS_CT2 = "application/vnd.openxmlformats-package.relationships+xml", EMPTY_RELATIONSHIPS_XML4, TD117;
|
|
376977
|
-
var
|
|
377818
|
+
var init_adapter35 = __esm(() => {
|
|
376978
377819
|
init_src3();
|
|
376979
377820
|
init_sd_document_session_internal();
|
|
376980
377821
|
init_document_reader();
|
|
376981
377822
|
init_adapter3();
|
|
376982
|
-
|
|
377823
|
+
init_adapter18();
|
|
376983
377824
|
init_public_model();
|
|
376984
377825
|
init_section_xml();
|
|
376985
377826
|
init_xml();
|
|
@@ -378057,7 +378898,7 @@ function structuredError4(code2, message) {
|
|
|
378057
378898
|
return error48;
|
|
378058
378899
|
}
|
|
378059
378900
|
var W14_NS4 = "http://schemas.microsoft.com/office/word/2010/wordml", FOOTNOTES_PART_URI4 = "/word/footnotes.xml", ENDNOTES_PART_URI4 = "/word/endnotes.xml", FOOTNOTES_CT = "application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml", ENDNOTES_CT = "application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml", FOOTNOTES_REL = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes", ENDNOTES_REL = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes";
|
|
378060
|
-
var
|
|
378901
|
+
var init_adapter36 = __esm(() => {
|
|
378061
378902
|
init_src3();
|
|
378062
378903
|
init_tracked_pr_change();
|
|
378063
378904
|
init_tracked_structural_wrapper();
|
|
@@ -382033,7 +382874,7 @@ function isPasteReason(reason) {
|
|
|
382033
382874
|
return !!reason && reason.startsWith("paste-");
|
|
382034
382875
|
}
|
|
382035
382876
|
var CLIPBOARD_TD;
|
|
382036
|
-
var
|
|
382877
|
+
var init_adapter37 = __esm(() => {
|
|
382037
382878
|
init_src3();
|
|
382038
382879
|
init_sd_document_session_internal();
|
|
382039
382880
|
init_note_story();
|
|
@@ -382085,7 +382926,7 @@ class V2SelectionAdapter {
|
|
|
382085
382926
|
};
|
|
382086
382927
|
}
|
|
382087
382928
|
}
|
|
382088
|
-
var
|
|
382929
|
+
var init_adapter38 = __esm(() => {
|
|
382089
382930
|
init_sd_document_session_internal();
|
|
382090
382931
|
});
|
|
382091
382932
|
|
|
@@ -382233,651 +383074,6 @@ var init_clear_content_adapter = __esm(() => {
|
|
|
382233
383074
|
TE69 = new TextEncoder;
|
|
382234
383075
|
});
|
|
382235
383076
|
|
|
382236
|
-
// ../../../v2/document-api-v2-adapter/dist/metadata/adapter.js
|
|
382237
|
-
class V2AnchoredMetadataAdapter {
|
|
382238
|
-
constructor(context) {
|
|
382239
|
-
this.context = context;
|
|
382240
|
-
}
|
|
382241
|
-
attach(input, options) {
|
|
382242
|
-
const mutationGuard = guardDirectOnlyMutation(this.context, input, options);
|
|
382243
|
-
if (mutationGuard)
|
|
382244
|
-
return mutationGuard;
|
|
382245
|
-
const id = input.id ?? newOpaqueId("metadata");
|
|
382246
|
-
const existingRecords = listMetadataRecords(this.context);
|
|
382247
|
-
if (existingRecords.some((record3) => record3.id === id)) {
|
|
382248
|
-
throw operationError("INVALID_INPUT", `metadata id ${id} already exists.`);
|
|
382249
|
-
}
|
|
382250
|
-
const payloadJson = JSON.stringify(input.payload);
|
|
382251
|
-
if (payloadJson === undefined)
|
|
382252
|
-
throw operationError("INVALID_INPUT", "metadata payload must be JSON serializable.");
|
|
382253
|
-
const documentXml = readDocumentXml(this.context);
|
|
382254
|
-
if (findMetadataAnchor(documentXml, id)) {
|
|
382255
|
-
throw operationError("INVALID_INPUT", `metadata id ${id} already exists.`);
|
|
382256
|
-
}
|
|
382257
|
-
const resolvedSegments = input.target.kind === "text" ? resolveMultiSegmentTarget(documentXml, input.target) : resolveSingleSegmentTarget(this.context, documentXml, input.target);
|
|
382258
|
-
if ("error" in resolvedSegments)
|
|
382259
|
-
throw operationError(resolvedSegments.error, resolvedSegments.message);
|
|
382260
|
-
const knownIds = new Set(existingRecords.map((record3) => record3.id));
|
|
382261
|
-
if (hasOverlappingMetadataAnchor(documentXml, resolvedSegments.segments, knownIds)) {
|
|
382262
|
-
return failure2("INVALID_TARGET", "metadata.attach target overlaps an existing metadata anchor.");
|
|
382263
|
-
}
|
|
382264
|
-
const existingPart = ensureCustomXmlPartForNamespace(this.context, input.namespace);
|
|
382265
|
-
const allocatedPart = existingPart ? null : allocateCustomXmlPartNames(this.context);
|
|
382266
|
-
const partName = existingPart?.partName ?? allocatedPart.partName;
|
|
382267
|
-
const partUri = existingPart?.partUri ?? allocatedPart.partUri;
|
|
382268
|
-
const storageXml = existingPart?.content ?? buildMetadataStorageXml(input.namespace, []);
|
|
382269
|
-
const refs = readMetadataRefs(storageXml, input.namespace);
|
|
382270
|
-
refs.push({ id, payloadJson });
|
|
382271
|
-
const nextStorageXml = buildMetadataStorageXml(input.namespace, refs);
|
|
382272
|
-
const sdtIds = allocateMetadataSdtIds(documentXml, resolvedSegments.segments.length);
|
|
382273
|
-
const bySegmentPosition = resolvedSegments.segments.map((segment, index2) => ({ segment, sdtId: sdtIds[index2] })).sort((a, b) => b.segment.para.start - a.segment.para.start);
|
|
382274
|
-
let nextDocumentXml = documentXml;
|
|
382275
|
-
for (const { segment, sdtId } of bySegmentPosition) {
|
|
382276
|
-
const wrapped = wrapTextRangeWithMetadataSdt(segment.para.xml, segment.startOffset, segment.endOffset, id, sdtId);
|
|
382277
|
-
if (!wrapped.ok)
|
|
382278
|
-
throw metadataWrapRejectError(wrapped.reason);
|
|
382279
|
-
nextDocumentXml = replaceRange3(nextDocumentXml, segment.para.start, segment.para.end, wrapped.xml);
|
|
382280
|
-
}
|
|
382281
|
-
if (!dryRunRequested(input, options)) {
|
|
382282
|
-
nextDocumentXml = ensureW15Namespace(nextDocumentXml);
|
|
382283
|
-
const updates = existingPart ? { [partUri]: encodeXml(nextStorageXml) } : buildCustomXmlCreateUpdates(this.context, {
|
|
382284
|
-
id: newGuid(),
|
|
382285
|
-
content: nextStorageXml,
|
|
382286
|
-
partUri,
|
|
382287
|
-
propsPartUri: allocatedPart.propsPartUri,
|
|
382288
|
-
relsPartUri: allocatedPart.relsPartUri
|
|
382289
|
-
});
|
|
382290
|
-
updates[DOCUMENT_PART_URI5] = encodeXml(nextDocumentXml);
|
|
382291
|
-
const committed = commitWholePartUpdates(this.context, "metadata-attach", updates, {
|
|
382292
|
-
expectedRevision: expectedRevisionFrom(input, options),
|
|
382293
|
-
storySurface: {
|
|
382294
|
-
family: "storyAnchor",
|
|
382295
|
-
targetBlockIds: resolvedSegments.segments.map((segment) => segment.blockId)
|
|
382296
|
-
}
|
|
382297
|
-
});
|
|
382298
|
-
if (!committed.ok)
|
|
382299
|
-
return { success: false, failure: { code: committed.code, message: committed.message } };
|
|
382300
|
-
}
|
|
382301
|
-
return { success: true, id, namespace: input.namespace, partName };
|
|
382302
|
-
}
|
|
382303
|
-
list(query3) {
|
|
382304
|
-
let records = listMetadataRecords(this.context);
|
|
382305
|
-
const recordCounts = new Map;
|
|
382306
|
-
for (const record3 of records)
|
|
382307
|
-
recordCounts.set(record3.id, (recordCounts.get(record3.id) ?? 0) + 1);
|
|
382308
|
-
if (query3?.namespace !== undefined)
|
|
382309
|
-
records = records.filter((record3) => record3.namespace === query3.namespace);
|
|
382310
|
-
const documentXml = readDocumentXml(this.context);
|
|
382311
|
-
if (query3?.resolvedOnly === true) {
|
|
382312
|
-
records = records.filter((record3) => recordCounts.get(record3.id) === 1 && groupMetadataAnchor(documentXml, record3.id, new Set([record3.id])) !== null);
|
|
382313
|
-
}
|
|
382314
|
-
if (query3?.within !== undefined) {
|
|
382315
|
-
records = records.filter((record3) => {
|
|
382316
|
-
const resolved = this.resolve({ id: record3.id });
|
|
382317
|
-
return resolved ? overlaps(query3.within, resolved.target) : false;
|
|
382318
|
-
});
|
|
382319
|
-
}
|
|
382320
|
-
const page = pageSlice(records, query3);
|
|
382321
|
-
return buildDiscoveryResult({
|
|
382322
|
-
evaluatedRevision: this.context.currentPublicRevision(),
|
|
382323
|
-
total: records.length,
|
|
382324
|
-
items: page.items.map((record3) => buildDiscoveryItem(record3.id, buildResolvedHandle(`metadata:${record3.id}`, "stable", "ext:metadata"), metadataSummary(record3, documentXml))),
|
|
382325
|
-
page: { offset: page.offset, limit: page.limit, returned: page.items.length }
|
|
382326
|
-
});
|
|
382327
|
-
}
|
|
382328
|
-
get(input) {
|
|
382329
|
-
const record3 = findMetadataRecord(this.context, input.id);
|
|
382330
|
-
return record3 ? { ...metadataSummary(record3, readDocumentXml(this.context)), payload: record3.payload } : null;
|
|
382331
|
-
}
|
|
382332
|
-
update(input, options) {
|
|
382333
|
-
const mutationGuard = guardDirectOnlyMutation(this.context, input, options);
|
|
382334
|
-
if (mutationGuard)
|
|
382335
|
-
return mutationGuard;
|
|
382336
|
-
if (listMetadataRecords(this.context).filter((candidate2) => candidate2.id === input.id).length > 1) {
|
|
382337
|
-
return failure2("INVALID_TARGET", `metadata ${input.id} has ambiguous payload records.`);
|
|
382338
|
-
}
|
|
382339
|
-
const record3 = findMetadataRecord(this.context, input.id);
|
|
382340
|
-
if (!record3)
|
|
382341
|
-
throw operationError("TARGET_NOT_FOUND", `metadata ${input.id} not found.`);
|
|
382342
|
-
const payloadJson = JSON.stringify(input.payload);
|
|
382343
|
-
if (payloadJson === undefined)
|
|
382344
|
-
throw operationError("INVALID_INPUT", "metadata payload must be JSON serializable.");
|
|
382345
|
-
if (dryRunRequested(input, options))
|
|
382346
|
-
return { success: true, id: input.id };
|
|
382347
|
-
const records = listMetadataRecords(this.context).filter((candidate2) => candidate2.partUri === record3.partUri);
|
|
382348
|
-
const refs = records.map((candidate2) => ({
|
|
382349
|
-
id: candidate2.id,
|
|
382350
|
-
payloadJson: candidate2.id === input.id ? payloadJson : JSON.stringify(candidate2.payload)
|
|
382351
|
-
}));
|
|
382352
|
-
const committed = commitWholePartUpdates(this.context, "metadata-update", { [record3.partUri]: encodeXml(buildMetadataStorageXml(record3.namespace, refs)) }, { expectedRevision: expectedRevisionFrom(input, options) });
|
|
382353
|
-
if (!committed.ok)
|
|
382354
|
-
return { success: false, failure: { code: committed.code, message: committed.message } };
|
|
382355
|
-
return { success: true, id: input.id };
|
|
382356
|
-
}
|
|
382357
|
-
remove(input, options) {
|
|
382358
|
-
const mutationGuard = guardDirectOnlyMutation(this.context, input, options);
|
|
382359
|
-
if (mutationGuard)
|
|
382360
|
-
return mutationGuard;
|
|
382361
|
-
if (listMetadataRecords(this.context).filter((candidate2) => candidate2.id === input.id).length > 1) {
|
|
382362
|
-
return failure2("INVALID_TARGET", `metadata ${input.id} has ambiguous payload records.`);
|
|
382363
|
-
}
|
|
382364
|
-
const record3 = findMetadataRecord(this.context, input.id);
|
|
382365
|
-
if (!record3)
|
|
382366
|
-
throw operationError("TARGET_NOT_FOUND", `metadata ${input.id} not found.`);
|
|
382367
|
-
const documentXml = readDocumentXml(this.context);
|
|
382368
|
-
const knownIds = new Set(listMetadataRecords(this.context).map((candidate2) => candidate2.id));
|
|
382369
|
-
const matchingAnchors = listMetadataAnchors(documentXml, knownIds).filter((anchor) => anchor.id === input.id);
|
|
382370
|
-
const grouped = groupMetadataAnchor(documentXml, input.id, knownIds);
|
|
382371
|
-
if (matchingAnchors.length > 0 && !grouped) {
|
|
382372
|
-
return { success: false, failure: { code: "INVALID_TARGET", message: `metadata ${input.id} has ambiguous anchors.` } };
|
|
382373
|
-
}
|
|
382374
|
-
if (dryRunRequested(input, options))
|
|
382375
|
-
return { success: true, id: input.id };
|
|
382376
|
-
const updates = {};
|
|
382377
|
-
if (grouped) {
|
|
382378
|
-
const bySegmentPosition = [...grouped.segments].sort((a, b) => b.start - a.start);
|
|
382379
|
-
let nextDocumentXml = documentXml;
|
|
382380
|
-
for (const anchor of bySegmentPosition) {
|
|
382381
|
-
if (anchor.unmatched)
|
|
382382
|
-
continue;
|
|
382383
|
-
const unwrapped = unwrapSdt(anchor.xml);
|
|
382384
|
-
if (unwrapped === null)
|
|
382385
|
-
continue;
|
|
382386
|
-
nextDocumentXml = replaceRange3(nextDocumentXml, anchor.start, anchor.end, unwrapped);
|
|
382387
|
-
}
|
|
382388
|
-
if (nextDocumentXml !== documentXml)
|
|
382389
|
-
updates[DOCUMENT_PART_URI5] = encodeXml(nextDocumentXml);
|
|
382390
|
-
}
|
|
382391
|
-
const remaining = listMetadataRecords(this.context).filter((candidate2) => candidate2.partUri === record3.partUri && candidate2.id !== input.id).map((candidate2) => ({ id: candidate2.id, payloadJson: JSON.stringify(candidate2.payload) }));
|
|
382392
|
-
const targetBlockIds2 = grouped ? grouped.segments.map((anchor) => anchor.blockId) : undefined;
|
|
382393
|
-
if (remaining.length > 0) {
|
|
382394
|
-
updates[record3.partUri] = encodeXml(buildMetadataStorageXml(record3.namespace, remaining));
|
|
382395
|
-
const committed = commitWholePartUpdates(this.context, "metadata-remove", updates, {
|
|
382396
|
-
expectedRevision: expectedRevisionFrom(input, options),
|
|
382397
|
-
...targetBlockIds2 ? { storySurface: { family: "storyAnchor", targetBlockIds: targetBlockIds2 } } : {}
|
|
382398
|
-
});
|
|
382399
|
-
if (!committed.ok)
|
|
382400
|
-
return { success: false, failure: { code: committed.code, message: committed.message } };
|
|
382401
|
-
} else {
|
|
382402
|
-
Object.assign(updates, buildCustomXmlRemoveUpdates(this.context, record3));
|
|
382403
|
-
const committed = commitWholePartUpdates(this.context, "metadata-remove", updates, {
|
|
382404
|
-
expectedRevision: expectedRevisionFrom(input, options),
|
|
382405
|
-
...targetBlockIds2 ? { storySurface: { family: "storyAnchor", targetBlockIds: targetBlockIds2 } } : {}
|
|
382406
|
-
});
|
|
382407
|
-
if (!committed.ok)
|
|
382408
|
-
return { success: false, failure: { code: committed.code, message: committed.message } };
|
|
382409
|
-
}
|
|
382410
|
-
return { success: true, id: input.id };
|
|
382411
|
-
}
|
|
382412
|
-
resolve(input) {
|
|
382413
|
-
const record3 = findMetadataRecord(this.context, input.id);
|
|
382414
|
-
if (!record3)
|
|
382415
|
-
return null;
|
|
382416
|
-
const knownIds = new Set(listMetadataRecords(this.context).map((candidate2) => candidate2.id));
|
|
382417
|
-
const grouped = groupMetadataAnchor(readDocumentXml(this.context), input.id, knownIds);
|
|
382418
|
-
if (!grouped)
|
|
382419
|
-
return null;
|
|
382420
|
-
return { id: input.id, target: grouped.target };
|
|
382421
|
-
}
|
|
382422
|
-
}
|
|
382423
|
-
function listMetadataRecords(context) {
|
|
382424
|
-
const out = [];
|
|
382425
|
-
for (const part of listCustomXmlRecords(context)) {
|
|
382426
|
-
if (!part.rootNamespace || !/^<refs\b/.test(part.content.replace(/^<\?xml[^>]*>/, "").trim()))
|
|
382427
|
-
continue;
|
|
382428
|
-
for (const ref5 of readMetadataRefs(part.content, part.rootNamespace)) {
|
|
382429
|
-
let payload = null;
|
|
382430
|
-
try {
|
|
382431
|
-
payload = JSON.parse(ref5.payloadJson);
|
|
382432
|
-
} catch {
|
|
382433
|
-
payload = null;
|
|
382434
|
-
}
|
|
382435
|
-
out.push({
|
|
382436
|
-
id: ref5.id,
|
|
382437
|
-
namespace: part.rootNamespace,
|
|
382438
|
-
partName: part.partName,
|
|
382439
|
-
partUri: part.partUri,
|
|
382440
|
-
...part.propsPartUri ? { propsPartUri: part.propsPartUri } : {},
|
|
382441
|
-
payload
|
|
382442
|
-
});
|
|
382443
|
-
}
|
|
382444
|
-
}
|
|
382445
|
-
return out;
|
|
382446
|
-
}
|
|
382447
|
-
function findMetadataRecord(context, id) {
|
|
382448
|
-
const matches = listMetadataRecords(context).filter((record3) => record3.id === id);
|
|
382449
|
-
return matches.length === 1 ? matches[0] : null;
|
|
382450
|
-
}
|
|
382451
|
-
function metadataSummary(record3, documentXml) {
|
|
382452
|
-
return {
|
|
382453
|
-
id: record3.id,
|
|
382454
|
-
namespace: record3.namespace,
|
|
382455
|
-
partName: record3.partName,
|
|
382456
|
-
anchorStatus: groupMetadataAnchor(documentXml, record3.id, new Set([record3.id])) ? "resolved" : "orphan"
|
|
382457
|
-
};
|
|
382458
|
-
}
|
|
382459
|
-
function readMetadataRefs(xml, _namespace) {
|
|
382460
|
-
const refs = [];
|
|
382461
|
-
const re = /<ref\b[^>]*\bid="([^"]*)"[^>]*>([\s\S]*?)<\/ref>/g;
|
|
382462
|
-
for (let match = re.exec(xml);match; match = re.exec(xml)) {
|
|
382463
|
-
refs.push({ id: decodeXmlEntities(match[1]), payloadJson: decodeXmlEntities(match[2]) });
|
|
382464
|
-
}
|
|
382465
|
-
return refs;
|
|
382466
|
-
}
|
|
382467
|
-
function findMetadataAnchor(documentXml, id) {
|
|
382468
|
-
return listMetadataAnchors(documentXml, new Set([id])).find((anchor) => anchor.id === id) ?? null;
|
|
382469
|
-
}
|
|
382470
|
-
function listMetadataAnchors(documentXml, knownIds) {
|
|
382471
|
-
const anchors = [];
|
|
382472
|
-
for (const sdt of listSdtRanges(documentXml)) {
|
|
382473
|
-
const pr = ownSdtPr(sdt.xml);
|
|
382474
|
-
const tag = attrValue(/<w:tag\b[^>]*\/>/.exec(pr)?.[0] ?? "", "val");
|
|
382475
|
-
if (!tag || !isMetadataAnchorPr(pr, tag, knownIds))
|
|
382476
|
-
continue;
|
|
382477
|
-
const anchor = materializeMetadataAnchor(documentXml, sdt, tag);
|
|
382478
|
-
if (anchor)
|
|
382479
|
-
anchors.push(anchor);
|
|
382480
|
-
}
|
|
382481
|
-
return anchors.sort((left, right) => left.start - right.start);
|
|
382482
|
-
}
|
|
382483
|
-
function ownSdtPr(sdtXml) {
|
|
382484
|
-
const openTag = /<w:sdt\b[^>]*>/.exec(sdtXml);
|
|
382485
|
-
if (!openTag)
|
|
382486
|
-
return "";
|
|
382487
|
-
const headStart = openTag.index + openTag[0].length;
|
|
382488
|
-
const contentOrNested = /<w:sdtContent\b[^>]*>|<w:sdt\b[^>]*>/.exec(sdtXml.slice(headStart));
|
|
382489
|
-
const head = contentOrNested ? sdtXml.slice(headStart, headStart + contentOrNested.index) : sdtXml.slice(headStart);
|
|
382490
|
-
return /<w:sdtPr\b[^>]*>[\s\S]*?<\/w:sdtPr>/.exec(head)?.[0] ?? "";
|
|
382491
|
-
}
|
|
382492
|
-
function listSdtRanges(documentXml) {
|
|
382493
|
-
const ranges = [];
|
|
382494
|
-
const stack = [];
|
|
382495
|
-
const tokenRe = /<w:sdt\b[^>]*>|<\/w:sdt>/g;
|
|
382496
|
-
for (let match = tokenRe.exec(documentXml);match; match = tokenRe.exec(documentXml)) {
|
|
382497
|
-
if (match[0].startsWith("</")) {
|
|
382498
|
-
const start = stack.pop();
|
|
382499
|
-
if (start === undefined)
|
|
382500
|
-
continue;
|
|
382501
|
-
const end = tokenRe.lastIndex;
|
|
382502
|
-
ranges.push({ start, end, xml: documentXml.slice(start, end) });
|
|
382503
|
-
} else if (/\/\s*>$/.test(match[0])) {
|
|
382504
|
-
ranges.push({ start: match.index, end: tokenRe.lastIndex, xml: match[0] });
|
|
382505
|
-
} else {
|
|
382506
|
-
stack.push(match.index);
|
|
382507
|
-
}
|
|
382508
|
-
}
|
|
382509
|
-
for (const start of stack) {
|
|
382510
|
-
const end = unmatchedSdtExtent(documentXml, start);
|
|
382511
|
-
ranges.push({ start, end, xml: documentXml.slice(start, end), unmatched: true });
|
|
382512
|
-
}
|
|
382513
|
-
return ranges.sort((left, right) => left.start - right.start);
|
|
382514
|
-
}
|
|
382515
|
-
function unmatchedSdtExtent(documentXml, start) {
|
|
382516
|
-
const paraClose = documentXml.indexOf("</w:p>", start);
|
|
382517
|
-
return paraClose === -1 ? documentXml.length : paraClose;
|
|
382518
|
-
}
|
|
382519
|
-
function isMetadataAnchorPr(pr, tag, knownIds) {
|
|
382520
|
-
const alias = attrValue(/<w:alias\b[^>]*\/>/.exec(pr)?.[0] ?? "", "val");
|
|
382521
|
-
if (alias !== null && alias !== METADATA_ANCHOR_ALIAS)
|
|
382522
|
-
return false;
|
|
382523
|
-
const hasHiddenAppearance = attrValue(/<w15:appearance\b[^>]*\/>/.exec(pr)?.[0] ?? "", "val") === "hidden";
|
|
382524
|
-
const hasPlainTextPr = /<w:text\b/.test(pr);
|
|
382525
|
-
return knownIds.has(tag) && hasHiddenAppearance && hasPlainTextPr;
|
|
382526
|
-
}
|
|
382527
|
-
function materializeMetadataAnchor(documentXml, sdt, id) {
|
|
382528
|
-
const para = findParagraphContaining2(documentXml, sdt.start);
|
|
382529
|
-
if (!para)
|
|
382530
|
-
return null;
|
|
382531
|
-
const startOffset = extractVisibleTextFromXml2(para.xml.slice(0, sdt.start - para.start)).length;
|
|
382532
|
-
const length = extractVisibleTextFromXml2(unwrapSdt(sdt.xml) ?? sdt.xml).length;
|
|
382533
|
-
const endOffset = startOffset + length;
|
|
382534
|
-
return {
|
|
382535
|
-
id,
|
|
382536
|
-
start: sdt.start,
|
|
382537
|
-
end: sdt.end,
|
|
382538
|
-
xml: sdt.xml,
|
|
382539
|
-
blockId: para.blockId,
|
|
382540
|
-
startOffset,
|
|
382541
|
-
endOffset,
|
|
382542
|
-
unmatched: sdt.unmatched === true,
|
|
382543
|
-
target: {
|
|
382544
|
-
kind: "selection",
|
|
382545
|
-
start: { kind: "text", blockId: para.blockId, offset: startOffset, story: bodyStoryLocator2() },
|
|
382546
|
-
end: { kind: "text", blockId: para.blockId, offset: endOffset, story: bodyStoryLocator2() }
|
|
382547
|
-
}
|
|
382548
|
-
};
|
|
382549
|
-
}
|
|
382550
|
-
function groupMetadataAnchor(documentXml, id, knownIds) {
|
|
382551
|
-
const matches = listMetadataAnchors(documentXml, knownIds).filter((anchor) => anchor.id === id);
|
|
382552
|
-
if (matches.length === 0)
|
|
382553
|
-
return null;
|
|
382554
|
-
const kept = contiguousAnchorPrefix(documentXml, matches);
|
|
382555
|
-
if (kept.length !== matches.length)
|
|
382556
|
-
return null;
|
|
382557
|
-
if (kept.length === 1)
|
|
382558
|
-
return { id, segments: kept, target: kept[0].target };
|
|
382559
|
-
const textSegments = [];
|
|
382560
|
-
for (const anchor of kept) {
|
|
382561
|
-
const previous3 = textSegments.at(-1);
|
|
382562
|
-
if (previous3?.blockId === anchor.blockId && previous3.range.end === anchor.startOffset) {
|
|
382563
|
-
previous3.range.end = anchor.endOffset;
|
|
382564
|
-
} else {
|
|
382565
|
-
textSegments.push({ blockId: anchor.blockId, range: { start: anchor.startOffset, end: anchor.endOffset } });
|
|
382566
|
-
}
|
|
382567
|
-
}
|
|
382568
|
-
if (textSegments.length === 1) {
|
|
382569
|
-
const range = textSegments[0];
|
|
382570
|
-
return {
|
|
382571
|
-
id,
|
|
382572
|
-
segments: kept,
|
|
382573
|
-
target: {
|
|
382574
|
-
kind: "selection",
|
|
382575
|
-
start: { kind: "text", blockId: range.blockId, offset: range.range.start, story: bodyStoryLocator2() },
|
|
382576
|
-
end: { kind: "text", blockId: range.blockId, offset: range.range.end, story: bodyStoryLocator2() }
|
|
382577
|
-
}
|
|
382578
|
-
};
|
|
382579
|
-
}
|
|
382580
|
-
return {
|
|
382581
|
-
id,
|
|
382582
|
-
segments: kept,
|
|
382583
|
-
target: { kind: "text", segments: [textSegments[0], ...textSegments.slice(1)] }
|
|
382584
|
-
};
|
|
382585
|
-
}
|
|
382586
|
-
function contiguousAnchorPrefix(documentXml, matches) {
|
|
382587
|
-
if (matches.length <= 1)
|
|
382588
|
-
return [...matches];
|
|
382589
|
-
const map3 = buildStructuralBoundaryMap(TEXT_ENCODER2.encode(documentXml));
|
|
382590
|
-
const first = map3.byBlockId(matches[0].blockId);
|
|
382591
|
-
if (!first)
|
|
382592
|
-
return [matches[0]];
|
|
382593
|
-
const kept = [matches[0]];
|
|
382594
|
-
let prev = first;
|
|
382595
|
-
for (let i2 = 1;i2 < matches.length; i2 += 1) {
|
|
382596
|
-
const context = map3.byBlockId(matches[i2].blockId);
|
|
382597
|
-
if (!context)
|
|
382598
|
-
break;
|
|
382599
|
-
const sameParagraph = context.ordinal === prev.ordinal;
|
|
382600
|
-
if (sameParagraph) {
|
|
382601
|
-
const previousAnchor = kept.at(-1);
|
|
382602
|
-
if (context.blockId !== previousAnchor.blockId || matches[i2].startOffset !== previousAnchor.endOffset || !isMetadataCarrierGap(documentXml.slice(previousAnchor.end, matches[i2].start)))
|
|
382603
|
-
break;
|
|
382604
|
-
} else if (context.ordinal !== prev.ordinal + 1)
|
|
382605
|
-
break;
|
|
382606
|
-
if (!sameTableCellPath(context.tableCellPath, first.tableCellPath))
|
|
382607
|
-
break;
|
|
382608
|
-
if (!sameOrdinalPath2(context.blockSdtPath, first.blockSdtPath))
|
|
382609
|
-
break;
|
|
382610
|
-
if (!sameOrdinalPath2(context.blockCustomXmlPath, first.blockCustomXmlPath))
|
|
382611
|
-
break;
|
|
382612
|
-
if (context.sectionIndex !== first.sectionIndex)
|
|
382613
|
-
break;
|
|
382614
|
-
if (prev.carriesSectionBreak)
|
|
382615
|
-
break;
|
|
382616
|
-
kept.push(matches[i2]);
|
|
382617
|
-
prev = context;
|
|
382618
|
-
}
|
|
382619
|
-
return kept;
|
|
382620
|
-
}
|
|
382621
|
-
function isMetadataCarrierGap(xml) {
|
|
382622
|
-
return /^(?:\s*<w:proofErr\s+w:type="(?:spellStart|spellEnd|gramStart|gramEnd)"\s*\/>)*\s*$/.test(xml);
|
|
382623
|
-
}
|
|
382624
|
-
function sameOrdinalPath2(left, right) {
|
|
382625
|
-
return left.length === right.length && left.every((value2, index2) => value2 === right[index2]);
|
|
382626
|
-
}
|
|
382627
|
-
function resolveSingleSegmentTarget(context, documentXml, target) {
|
|
382628
|
-
const resolved = resolveBodySelectionTarget(context, target);
|
|
382629
|
-
if ("error" in resolved)
|
|
382630
|
-
return resolved;
|
|
382631
|
-
if (resolved.startBlockId !== resolved.endBlockId) {
|
|
382632
|
-
return { error: "INVALID_TARGET", message: "metadata.attach requires a same-paragraph text selection." };
|
|
382633
|
-
}
|
|
382634
|
-
if (resolved.startOffset >= resolved.endOffset) {
|
|
382635
|
-
return { error: "INVALID_TARGET", message: "metadata.attach requires a non-empty text range." };
|
|
382636
|
-
}
|
|
382637
|
-
const para = findParagraphById3(documentXml, resolved.startBlockId);
|
|
382638
|
-
if (!para)
|
|
382639
|
-
return { error: "TARGET_NOT_FOUND", message: `paragraph ${resolved.startBlockId} not found.` };
|
|
382640
|
-
return {
|
|
382641
|
-
segments: [{ blockId: para.blockId, startOffset: resolved.startOffset, endOffset: resolved.endOffset, para }]
|
|
382642
|
-
};
|
|
382643
|
-
}
|
|
382644
|
-
function resolveMultiSegmentTarget(documentXml, target) {
|
|
382645
|
-
if (target.story !== undefined && target.story.storyType !== "body") {
|
|
382646
|
-
return {
|
|
382647
|
-
error: "TARGET_NOT_FOUND",
|
|
382648
|
-
message: "metadata.attach resolves paragraphs against the main document body only."
|
|
382649
|
-
};
|
|
382650
|
-
}
|
|
382651
|
-
if (target.coordinateSpace === "tracked") {
|
|
382652
|
-
return {
|
|
382653
|
-
error: "INVALID_TARGET",
|
|
382654
|
-
message: "metadata.attach does not support a tracked-coordinate-space TextTarget."
|
|
382655
|
-
};
|
|
382656
|
-
}
|
|
382657
|
-
const segments = [];
|
|
382658
|
-
for (const segment of target.segments) {
|
|
382659
|
-
if (segment.range.start >= segment.range.end) {
|
|
382660
|
-
return {
|
|
382661
|
-
error: "INVALID_TARGET",
|
|
382662
|
-
message: "metadata.attach requires a non-empty text range in every TextTarget segment."
|
|
382663
|
-
};
|
|
382664
|
-
}
|
|
382665
|
-
const para = findParagraphById3(documentXml, segment.blockId);
|
|
382666
|
-
if (!para)
|
|
382667
|
-
return { error: "TARGET_NOT_FOUND", message: `paragraph ${segment.blockId} not found.` };
|
|
382668
|
-
segments.push({ blockId: segment.blockId, startOffset: segment.range.start, endOffset: segment.range.end, para });
|
|
382669
|
-
}
|
|
382670
|
-
const boundaryError = validateContiguousStructuralRun(documentXml, segments.map((segment) => segment.blockId));
|
|
382671
|
-
if (boundaryError)
|
|
382672
|
-
return boundaryError;
|
|
382673
|
-
return { segments };
|
|
382674
|
-
}
|
|
382675
|
-
function validateContiguousStructuralRun(documentXml, blockIds) {
|
|
382676
|
-
if (blockIds.length <= 1)
|
|
382677
|
-
return null;
|
|
382678
|
-
const map3 = buildStructuralBoundaryMap(TEXT_ENCODER2.encode(documentXml));
|
|
382679
|
-
const contexts = blockIds.map((blockId) => map3.byBlockId(blockId));
|
|
382680
|
-
const first = contexts[0];
|
|
382681
|
-
if (!first) {
|
|
382682
|
-
return { error: "INVALID_TARGET", message: `paragraph "${blockIds[0]}" is not visible to the structural map.` };
|
|
382683
|
-
}
|
|
382684
|
-
for (let i2 = 1;i2 < contexts.length; i2 += 1) {
|
|
382685
|
-
const context = contexts[i2];
|
|
382686
|
-
const prev = contexts[i2 - 1];
|
|
382687
|
-
if (!context) {
|
|
382688
|
-
return { error: "INVALID_TARGET", message: `paragraph "${blockIds[i2]}" is not visible to the structural map.` };
|
|
382689
|
-
}
|
|
382690
|
-
if (context.ordinal !== prev.ordinal + 1) {
|
|
382691
|
-
return {
|
|
382692
|
-
error: "INVALID_TARGET",
|
|
382693
|
-
message: "metadata.attach TextTarget segments must be contiguous paragraphs in document order."
|
|
382694
|
-
};
|
|
382695
|
-
}
|
|
382696
|
-
if (!sameTableCellPath(context.tableCellPath, first.tableCellPath)) {
|
|
382697
|
-
return { error: "INVALID_TARGET", message: "metadata.attach TextTarget cannot cross a table-cell boundary." };
|
|
382698
|
-
}
|
|
382699
|
-
if (!sameOrdinalPath2(context.blockSdtPath, first.blockSdtPath)) {
|
|
382700
|
-
return {
|
|
382701
|
-
error: "INVALID_TARGET",
|
|
382702
|
-
message: "metadata.attach TextTarget cannot cross a block content-control boundary."
|
|
382703
|
-
};
|
|
382704
|
-
}
|
|
382705
|
-
if (!sameOrdinalPath2(context.blockCustomXmlPath, first.blockCustomXmlPath)) {
|
|
382706
|
-
return {
|
|
382707
|
-
error: "INVALID_TARGET",
|
|
382708
|
-
message: "metadata.attach TextTarget cannot cross a block custom-XML boundary."
|
|
382709
|
-
};
|
|
382710
|
-
}
|
|
382711
|
-
if (context.sectionIndex !== first.sectionIndex) {
|
|
382712
|
-
return { error: "INVALID_TARGET", message: "metadata.attach TextTarget cannot cross a section boundary." };
|
|
382713
|
-
}
|
|
382714
|
-
if (prev.carriesSectionBreak) {
|
|
382715
|
-
return { error: "INVALID_TARGET", message: "metadata.attach TextTarget cannot cross a section boundary." };
|
|
382716
|
-
}
|
|
382717
|
-
}
|
|
382718
|
-
if (contexts[contexts.length - 1].carriesSectionBreak) {
|
|
382719
|
-
return { error: "INVALID_TARGET", message: "metadata.attach TextTarget cannot cross a section boundary." };
|
|
382720
|
-
}
|
|
382721
|
-
return null;
|
|
382722
|
-
}
|
|
382723
|
-
function hasOverlappingMetadataAnchor(documentXml, segments, knownIds) {
|
|
382724
|
-
const anchors = listMetadataAnchors(documentXml, knownIds);
|
|
382725
|
-
return segments.some((segment) => anchors.some((anchor) => anchor.blockId === segment.blockId && rangesStrictlyOverlap(segment.startOffset, segment.endOffset, anchor.startOffset, anchor.endOffset)));
|
|
382726
|
-
}
|
|
382727
|
-
function rangesStrictlyOverlap(leftStart, leftEnd, rightStart, rightEnd) {
|
|
382728
|
-
return leftStart < rightEnd && rightStart < leftEnd;
|
|
382729
|
-
}
|
|
382730
|
-
function bodyStoryLocator2() {
|
|
382731
|
-
return { kind: "story", storyType: "body" };
|
|
382732
|
-
}
|
|
382733
|
-
function wrapTextRangeWithMetadataSdt(paragraphXml, start, end, id, sdtId) {
|
|
382734
|
-
return wrapRangeWithMarkupInParagraphXml({
|
|
382735
|
-
paragraphXml,
|
|
382736
|
-
rangeStart: start,
|
|
382737
|
-
rangeEnd: end,
|
|
382738
|
-
open: metadataSdtOpenXml(id, sdtId),
|
|
382739
|
-
close: "</w:sdtContent></w:sdt>"
|
|
382740
|
-
});
|
|
382741
|
-
}
|
|
382742
|
-
function metadataSdtOpenXml(id, sdtId) {
|
|
382743
|
-
return [
|
|
382744
|
-
`<w:sdt xmlns:w15="${W15_NS}"><w:sdtPr>`,
|
|
382745
|
-
`<w:id w:val="${sdtId}"/>`,
|
|
382746
|
-
`<w:alias w:val="${xmlEscapeAttr(METADATA_ANCHOR_ALIAS)}"/>`,
|
|
382747
|
-
`<w:tag w:val="${xmlEscapeAttr(id)}"/>`,
|
|
382748
|
-
'<w15:appearance w15:val="hidden"/>',
|
|
382749
|
-
"<w:text/>",
|
|
382750
|
-
"</w:sdtPr><w:sdtContent>"
|
|
382751
|
-
].join("");
|
|
382752
|
-
}
|
|
382753
|
-
function metadataWrapRejectError(reason) {
|
|
382754
|
-
if (reason === "invalid-range") {
|
|
382755
|
-
return operationError("TARGET_NOT_FOUND", "metadata target text range not found.");
|
|
382756
|
-
}
|
|
382757
|
-
return operationError("INVALID_TARGET", `metadata.attach target overlaps unsupported content (${reason}).`);
|
|
382758
|
-
}
|
|
382759
|
-
function allocateMetadataSdtIds(documentXml, count) {
|
|
382760
|
-
const used = new Set;
|
|
382761
|
-
const idRe = /<w:id\b[^>]*(?:\/>|>)/g;
|
|
382762
|
-
for (let match = idRe.exec(documentXml);match; match = idRe.exec(documentXml)) {
|
|
382763
|
-
const value2 = Number.parseInt(attrValue(match[0], "val") ?? "", 10);
|
|
382764
|
-
if (Number.isInteger(value2))
|
|
382765
|
-
used.add(value2);
|
|
382766
|
-
}
|
|
382767
|
-
const ids = [];
|
|
382768
|
-
for (let i2 = 0;i2 < count; i2 += 1) {
|
|
382769
|
-
let candidate2 = Math.max(1, Math.floor(Math.random() * MAX_SDT_ID));
|
|
382770
|
-
while (used.has(candidate2))
|
|
382771
|
-
candidate2 = candidate2 >= MAX_SDT_ID ? 1 : candidate2 + 1;
|
|
382772
|
-
used.add(candidate2);
|
|
382773
|
-
ids.push(candidate2);
|
|
382774
|
-
}
|
|
382775
|
-
return ids;
|
|
382776
|
-
}
|
|
382777
|
-
function ensureW15Namespace(documentXml) {
|
|
382778
|
-
return documentXml.replace(/<w:document\b[^>]*>/, (openTag) => {
|
|
382779
|
-
let next = openTag;
|
|
382780
|
-
if (!/\sxmlns:w15\s*=/.test(next))
|
|
382781
|
-
next = next.replace(/>$/, ` xmlns:w15="${W15_NS}">`);
|
|
382782
|
-
const ignorable = /\smc:Ignorable\s*=\s*(["'])([^"']*)\1/.exec(next);
|
|
382783
|
-
if (!ignorable)
|
|
382784
|
-
return next;
|
|
382785
|
-
const prefixes = ignorable[2].split(/\s+/).filter(Boolean);
|
|
382786
|
-
if (prefixes.includes("w15"))
|
|
382787
|
-
return next;
|
|
382788
|
-
return next.replace(ignorable[0], ` mc:Ignorable="${[...prefixes, "w15"].join(" ")}"`);
|
|
382789
|
-
});
|
|
382790
|
-
}
|
|
382791
|
-
function readDocumentXml(context) {
|
|
382792
|
-
const xml = readPartXml(context, DOCUMENT_PART_URI5);
|
|
382793
|
-
if (!xml)
|
|
382794
|
-
throw operationError("PRECONDITION_FAILED", "document.xml bytes are unavailable.");
|
|
382795
|
-
return xml;
|
|
382796
|
-
}
|
|
382797
|
-
function findParagraphById3(documentXml, blockId) {
|
|
382798
|
-
const paraRe = /<w:p\b[^>]*>[\s\S]*?<\/w:p>/g;
|
|
382799
|
-
for (let match = paraRe.exec(documentXml);match; match = paraRe.exec(documentXml)) {
|
|
382800
|
-
if (match[0].includes(`w14:paraId="${blockId}"`))
|
|
382801
|
-
return { start: match.index, end: paraRe.lastIndex, xml: match[0], blockId };
|
|
382802
|
-
}
|
|
382803
|
-
return null;
|
|
382804
|
-
}
|
|
382805
|
-
function findParagraphContaining2(documentXml, index2) {
|
|
382806
|
-
const paraRe = /<w:p\b[^>]*>[\s\S]*?<\/w:p>/g;
|
|
382807
|
-
for (let match = paraRe.exec(documentXml);match; match = paraRe.exec(documentXml)) {
|
|
382808
|
-
if (match.index <= index2 && paraRe.lastIndex >= index2) {
|
|
382809
|
-
const open = /^<w:p\b[^>]*>/.exec(match[0])?.[0] ?? "";
|
|
382810
|
-
return {
|
|
382811
|
-
start: match.index,
|
|
382812
|
-
end: paraRe.lastIndex,
|
|
382813
|
-
xml: match[0],
|
|
382814
|
-
blockId: attrValue(open, "paraId") ?? "unknown"
|
|
382815
|
-
};
|
|
382816
|
-
}
|
|
382817
|
-
}
|
|
382818
|
-
return null;
|
|
382819
|
-
}
|
|
382820
|
-
function unwrapSdt(sdtXml) {
|
|
382821
|
-
const open = /<w:sdtContent\b[^>]*>/.exec(sdtXml);
|
|
382822
|
-
if (!open)
|
|
382823
|
-
return null;
|
|
382824
|
-
if (/\/\s*>$/.test(open[0]))
|
|
382825
|
-
return "";
|
|
382826
|
-
const contentStart = open.index + open[0].length;
|
|
382827
|
-
const tokenRe = /<w:sdtContent\b[^>]*>|<\/w:sdtContent>/g;
|
|
382828
|
-
tokenRe.lastIndex = contentStart;
|
|
382829
|
-
let depth = 0;
|
|
382830
|
-
for (let match = tokenRe.exec(sdtXml);match; match = tokenRe.exec(sdtXml)) {
|
|
382831
|
-
if (match[0].startsWith("</")) {
|
|
382832
|
-
if (depth === 0)
|
|
382833
|
-
return sdtXml.slice(contentStart, match.index);
|
|
382834
|
-
depth -= 1;
|
|
382835
|
-
} else if (!/\/\s*>$/.test(match[0])) {
|
|
382836
|
-
depth += 1;
|
|
382837
|
-
}
|
|
382838
|
-
}
|
|
382839
|
-
return null;
|
|
382840
|
-
}
|
|
382841
|
-
function replaceRange3(xml, start, end, replacement) {
|
|
382842
|
-
return `${xml.slice(0, start)}${replacement}${xml.slice(end)}`;
|
|
382843
|
-
}
|
|
382844
|
-
function toFlatSegments(target) {
|
|
382845
|
-
if (target.story !== undefined && target.story.storyType !== "body")
|
|
382846
|
-
return null;
|
|
382847
|
-
if (target.coordinateSpace === "tracked")
|
|
382848
|
-
return null;
|
|
382849
|
-
if (target.kind === "text") {
|
|
382850
|
-
return target.segments.map((segment) => ({
|
|
382851
|
-
blockId: segment.blockId,
|
|
382852
|
-
start: segment.range.start,
|
|
382853
|
-
end: segment.range.end
|
|
382854
|
-
}));
|
|
382855
|
-
}
|
|
382856
|
-
if (target.start.kind !== "text" || target.end.kind !== "text")
|
|
382857
|
-
return null;
|
|
382858
|
-
if (target.start.blockId !== target.end.blockId)
|
|
382859
|
-
return null;
|
|
382860
|
-
return [{ blockId: target.start.blockId, start: target.start.offset, end: target.end.offset }];
|
|
382861
|
-
}
|
|
382862
|
-
function overlaps(left, right) {
|
|
382863
|
-
const leftSegments = toFlatSegments(left);
|
|
382864
|
-
const rightSegments = toFlatSegments(right);
|
|
382865
|
-
if (!leftSegments || !rightSegments)
|
|
382866
|
-
return false;
|
|
382867
|
-
return leftSegments.some((leftSegment) => rightSegments.some((rightSegment) => leftSegment.blockId === rightSegment.blockId && rangesStrictlyOverlap(leftSegment.start, leftSegment.end, rightSegment.start, rightSegment.end)));
|
|
382868
|
-
}
|
|
382869
|
-
var TEXT_ENCODER2, METADATA_ANCHOR_ALIAS = "Anchored metadata", W15_NS = "http://schemas.microsoft.com/office/word/2012/wordml", MAX_SDT_ID = 2147483646;
|
|
382870
|
-
var init_adapter38 = __esm(() => {
|
|
382871
|
-
init_src3();
|
|
382872
|
-
init_sd_document_session_internal();
|
|
382873
|
-
init_visible_text();
|
|
382874
|
-
init_inline();
|
|
382875
|
-
init_adapter2();
|
|
382876
|
-
init_shared();
|
|
382877
|
-
init_xml();
|
|
382878
|
-
TEXT_ENCODER2 = new TextEncoder;
|
|
382879
|
-
});
|
|
382880
|
-
|
|
382881
383077
|
// ../../../v2/document-api-v2-adapter/dist/formatting/styles.js
|
|
382882
383078
|
function applyStylesDocDefaultsPatch(stylesXml, input) {
|
|
382883
383079
|
const normalized = normalizeStylesWordprocessingMlQNames(stylesXml);
|
|
@@ -386032,47 +386228,47 @@ function createV2DocumentApiAdapter(session, options = {}) {
|
|
|
386032
386228
|
}
|
|
386033
386229
|
var init_factory = __esm(() => {
|
|
386034
386230
|
init_context();
|
|
386035
|
-
init_adapter10();
|
|
386036
386231
|
init_adapter11();
|
|
386037
|
-
|
|
386038
|
-
|
|
386232
|
+
init_adapter12();
|
|
386233
|
+
init_adapter17();
|
|
386039
386234
|
init_adapter19();
|
|
386040
386235
|
init_adapter20();
|
|
386041
|
-
init_adapter12();
|
|
386042
|
-
init_adapter15();
|
|
386043
386236
|
init_adapter21();
|
|
386237
|
+
init_adapter13();
|
|
386238
|
+
init_adapter16();
|
|
386239
|
+
init_adapter22();
|
|
386044
386240
|
init_adapter2();
|
|
386045
|
-
init_adapter23();
|
|
386046
386241
|
init_adapter24();
|
|
386047
|
-
init_adapter();
|
|
386048
386242
|
init_adapter25();
|
|
386243
|
+
init_adapter();
|
|
386049
386244
|
init_adapter26();
|
|
386050
|
-
|
|
386245
|
+
init_adapter27();
|
|
386246
|
+
init_adapter30();
|
|
386051
386247
|
init_adapter6();
|
|
386052
386248
|
init_adapter7();
|
|
386053
|
-
|
|
386054
|
-
init_adapter30();
|
|
386055
|
-
init_adapter13();
|
|
386056
|
-
init_adapter22();
|
|
386057
|
-
init_reader();
|
|
386249
|
+
init_adapter10();
|
|
386058
386250
|
init_adapter31();
|
|
386059
|
-
|
|
386251
|
+
init_adapter14();
|
|
386252
|
+
init_adapter23();
|
|
386253
|
+
init_reader();
|
|
386060
386254
|
init_adapter32();
|
|
386255
|
+
init_search2();
|
|
386061
386256
|
init_adapter33();
|
|
386257
|
+
init_adapter34();
|
|
386062
386258
|
init_adapter8();
|
|
386063
|
-
|
|
386259
|
+
init_adapter18();
|
|
386064
386260
|
init_adapter3();
|
|
386065
|
-
init_adapter34();
|
|
386066
386261
|
init_adapter35();
|
|
386067
386262
|
init_adapter36();
|
|
386068
|
-
init_adapter27();
|
|
386069
386263
|
init_adapter37();
|
|
386070
|
-
init_clear_content_adapter();
|
|
386071
386264
|
init_adapter28();
|
|
386265
|
+
init_adapter38();
|
|
386266
|
+
init_clear_content_adapter();
|
|
386267
|
+
init_adapter29();
|
|
386072
386268
|
init_adapter4();
|
|
386073
386269
|
init_adapter5();
|
|
386074
|
-
|
|
386075
|
-
|
|
386270
|
+
init_adapter9();
|
|
386271
|
+
init_adapter15();
|
|
386076
386272
|
init_adapter39();
|
|
386077
386273
|
init_adapter40();
|
|
386078
386274
|
init_read_adapters();
|
|
@@ -419976,7 +420172,7 @@ class XmlEmissionContext {
|
|
|
419976
420172
|
stack.push(namespaceBindings);
|
|
419977
420173
|
if (namespaceBindings !== inherited)
|
|
419978
420174
|
events.push({ offset: end, bindings: namespaceBindings });
|
|
419979
|
-
if (tag.localName !== "p" || tag.namespaceUri !==
|
|
420175
|
+
if (tag.localName !== "p" || tag.namespaceUri !== WORD_NAMESPACE6)
|
|
419980
420176
|
return;
|
|
419981
420177
|
if (paragraphDepth++ > 0)
|
|
419982
420178
|
return;
|
|
@@ -419986,7 +420182,7 @@ class XmlEmissionContext {
|
|
|
419986
420182
|
this.paragraphs.set(blockIdForParagraphXmlSpan({ paraId: id2 ?? null, ordinal: paragraphOrdinal++ }), context);
|
|
419987
420183
|
},
|
|
419988
420184
|
onCloseTag: ({ tag, end }) => {
|
|
419989
|
-
if (tag.localName === "p" && tag.namespaceUri ===
|
|
420185
|
+
if (tag.localName === "p" && tag.namespaceUri === WORD_NAMESPACE6)
|
|
419990
420186
|
paragraphDepth -= 1;
|
|
419991
420187
|
const previous3 = stack.pop();
|
|
419992
420188
|
const bindings = stack[stack.length - 1] ?? this.initial;
|
|
@@ -420011,17 +420207,17 @@ function paragraphEmissionNames(context, preservedXml) {
|
|
|
420011
420207
|
bindings[prefix] = namespace;
|
|
420012
420208
|
return prefix;
|
|
420013
420209
|
};
|
|
420014
|
-
const word3 = choose("w",
|
|
420210
|
+
const word3 = choose("w", WORD_NAMESPACE6);
|
|
420015
420211
|
const word2010 = choose("w14", WORD_2010_NAMESPACE3);
|
|
420016
420212
|
const declarations = Object.entries({ "": "", ...bindings }).filter(([prefix, uri]) => prefix !== "xml" && (context.inherited[prefix] ?? "") !== uri).sort(([left], [right]) => left.localeCompare(right)).map(([prefix, uri]) => ` xmlns${prefix ? `:${prefix}` : ""}="${xmlEscape(uri)}"`).join("");
|
|
420017
420213
|
return { word: word3, word2010, declarations };
|
|
420018
420214
|
}
|
|
420019
|
-
var
|
|
420215
|
+
var WORD_NAMESPACE6 = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", WORD_2010_NAMESPACE3 = "http://schemas.microsoft.com/office/word/2010/wordml", CANONICAL_NAMESPACES;
|
|
420020
420216
|
var init_xml_emission_context = __esm(() => {
|
|
420021
420217
|
init_sd_document_session_internal();
|
|
420022
420218
|
init_canonical();
|
|
420023
420219
|
CANONICAL_NAMESPACES = {
|
|
420024
|
-
w:
|
|
420220
|
+
w: WORD_NAMESPACE6,
|
|
420025
420221
|
w14: WORD_2010_NAMESPACE3
|
|
420026
420222
|
};
|
|
420027
420223
|
});
|
|
@@ -426525,6 +426721,7 @@ function syncTrackedDecisionTableOverlaysFromSession(session, prepared, storyId,
|
|
|
426525
426721
|
partUri,
|
|
426526
426722
|
preparedTxId: prepared.txId,
|
|
426527
426723
|
lastDeltaKind: "tracked-change.decision.sync",
|
|
426724
|
+
reversibleReviewDecision: prepared.backendExtensions.storySurface?.historyReplay != null,
|
|
426528
426725
|
tableXml,
|
|
426529
426726
|
sourceXmlStart,
|
|
426530
426727
|
sourceXmlEnd: sourceXmlStart + tableXml.length,
|
|
@@ -426579,6 +426776,16 @@ function writeTableOverlayState(input) {
|
|
|
426579
426776
|
input.tableMap.set(overlayTableNodeId, tableValue);
|
|
426580
426777
|
}
|
|
426581
426778
|
const tableState = tableValue;
|
|
426779
|
+
if (input.lastDeltaKind === "tracked-change.decision.sync") {
|
|
426780
|
+
const previousTableXml = tableState.get("xml");
|
|
426781
|
+
const previousGridXml = typeof previousTableXml === "string" ? readDirectChildPropertyXml3(previousTableXml, "tbl", "tblGrid") : "";
|
|
426782
|
+
const nextGridXml = readDirectChildPropertyXml3(input.tableXml, "tbl", "tblGrid");
|
|
426783
|
+
writeTableRevisionDecisionDiff(tableState, "grid", overlayTableNodeId, previousGridXml, nextGridXml, input.reversibleReviewDecision === true);
|
|
426784
|
+
const nextGridChangeXml = readDirectChildPropertyXml3(nextGridXml, "tblGrid", "tblGridChange");
|
|
426785
|
+
if (nextGridChangeXml || tableState.has("gridChange")) {
|
|
426786
|
+
tableState.set("gridChange", nextGridChangeXml || null);
|
|
426787
|
+
}
|
|
426788
|
+
}
|
|
426582
426789
|
tableState.set("tableNodeId", overlayTableNodeId);
|
|
426583
426790
|
if (overlayTableNodeId === input.table.tableNodeId)
|
|
426584
426791
|
tableState.delete("currentTableNodeId");
|
|
@@ -426968,6 +427175,7 @@ var init_story_surface_session_sync = __esm(() => {
|
|
|
426968
427175
|
init_table_structural_refs();
|
|
426969
427176
|
init_schema4();
|
|
426970
427177
|
init_seed();
|
|
427178
|
+
init_table_revision_decisions();
|
|
426971
427179
|
init_story_surface_origin();
|
|
426972
427180
|
init_paragraph_inline_sync();
|
|
426973
427181
|
init_story_surface_origin();
|