xnl-core 0.1.2 → 0.1.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.cjs +227 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -3
- package/dist/index.d.ts +10 -3
- package/dist/index.js +227 -41
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -65,7 +65,13 @@ interface StringifyOptions {
|
|
|
65
65
|
pretty?: boolean;
|
|
66
66
|
indent?: number | string;
|
|
67
67
|
}
|
|
68
|
-
declare function stringify(value: XnlDocument | XnlNode, options?: StringifyOptions): string;
|
|
68
|
+
declare function stringify$1(value: XnlDocument | XnlNode, options?: StringifyOptions): string;
|
|
69
|
+
|
|
70
|
+
interface LineBlockStringifyOptions {
|
|
71
|
+
indent?: number | string;
|
|
72
|
+
textMarkerFactory?: () => string;
|
|
73
|
+
}
|
|
74
|
+
declare function stringify(value: XnlDocument | XnlNode, options?: LineBlockStringifyOptions): string;
|
|
69
75
|
|
|
70
76
|
type PathItemType = "UniqueName" | "MetadataSelector" | "InstanceProperty" | "MapKey" | "ListIndex";
|
|
71
77
|
interface PathItem {
|
|
@@ -133,7 +139,8 @@ declare const XNL: {
|
|
|
133
139
|
parseMany: typeof parseXnl;
|
|
134
140
|
parseSingle: typeof parseXnlSingleNode;
|
|
135
141
|
parseUnique: typeof parseUniqueChildren;
|
|
136
|
-
stringify: typeof stringify;
|
|
142
|
+
stringify: typeof stringify$1;
|
|
143
|
+
stringifyLineBlock: typeof stringify;
|
|
137
144
|
path: {
|
|
138
145
|
parse: typeof parsePath;
|
|
139
146
|
resolve: typeof resolvePath;
|
|
@@ -151,4 +158,4 @@ declare const XNL: {
|
|
|
151
158
|
};
|
|
152
159
|
};
|
|
153
160
|
|
|
154
|
-
export { type AttributeMap, type CommentNode, type DataElementNode, type ElementNode, type ElementNodeKind, type ExtendBody, GetWordFullName, MakeWord, type MetadataIdMode, type MutationType, type ParseWarning, type PathItem, type PathItemType, type SingleNodeResult, type TextElementNode, type UniqueChildrenResult, type ValueLiteral, XNL, type XnlDocument, type XnlErrorCode, type XnlMutation, type XnlMutationOptions, type XnlNode, XnlParseError, type XnlPath, XnlPathError, type XnlWord, applyMutations, batchLoad, deleteAtPath, diffNodes, isWord, loadFromString, resolveNode as loadNode, parsePath, parseUniqueChildren, parseXnl, parseXnlSingleNode, resolvePath, setPathValue, wordToString };
|
|
161
|
+
export { type AttributeMap, type CommentNode, type DataElementNode, type ElementNode, type ElementNodeKind, type ExtendBody, GetWordFullName, MakeWord, type MetadataIdMode, type MutationType, type ParseWarning, type PathItem, type PathItemType, type SingleNodeResult, type TextElementNode, type UniqueChildrenResult, type ValueLiteral, XNL, type XnlDocument, type XnlErrorCode, type XnlMutation, type XnlMutationOptions, type XnlNode, XnlParseError, type XnlPath, XnlPathError, type XnlWord, applyMutations, batchLoad, deleteAtPath, diffNodes, isWord, loadFromString, resolveNode as loadNode, parsePath, parseUniqueChildren, parseXnl, parseXnlSingleNode, resolvePath, setPathValue, stringify as stringifyLineBlock, wordToString };
|
package/dist/index.d.ts
CHANGED
|
@@ -65,7 +65,13 @@ interface StringifyOptions {
|
|
|
65
65
|
pretty?: boolean;
|
|
66
66
|
indent?: number | string;
|
|
67
67
|
}
|
|
68
|
-
declare function stringify(value: XnlDocument | XnlNode, options?: StringifyOptions): string;
|
|
68
|
+
declare function stringify$1(value: XnlDocument | XnlNode, options?: StringifyOptions): string;
|
|
69
|
+
|
|
70
|
+
interface LineBlockStringifyOptions {
|
|
71
|
+
indent?: number | string;
|
|
72
|
+
textMarkerFactory?: () => string;
|
|
73
|
+
}
|
|
74
|
+
declare function stringify(value: XnlDocument | XnlNode, options?: LineBlockStringifyOptions): string;
|
|
69
75
|
|
|
70
76
|
type PathItemType = "UniqueName" | "MetadataSelector" | "InstanceProperty" | "MapKey" | "ListIndex";
|
|
71
77
|
interface PathItem {
|
|
@@ -133,7 +139,8 @@ declare const XNL: {
|
|
|
133
139
|
parseMany: typeof parseXnl;
|
|
134
140
|
parseSingle: typeof parseXnlSingleNode;
|
|
135
141
|
parseUnique: typeof parseUniqueChildren;
|
|
136
|
-
stringify: typeof stringify;
|
|
142
|
+
stringify: typeof stringify$1;
|
|
143
|
+
stringifyLineBlock: typeof stringify;
|
|
137
144
|
path: {
|
|
138
145
|
parse: typeof parsePath;
|
|
139
146
|
resolve: typeof resolvePath;
|
|
@@ -151,4 +158,4 @@ declare const XNL: {
|
|
|
151
158
|
};
|
|
152
159
|
};
|
|
153
160
|
|
|
154
|
-
export { type AttributeMap, type CommentNode, type DataElementNode, type ElementNode, type ElementNodeKind, type ExtendBody, GetWordFullName, MakeWord, type MetadataIdMode, type MutationType, type ParseWarning, type PathItem, type PathItemType, type SingleNodeResult, type TextElementNode, type UniqueChildrenResult, type ValueLiteral, XNL, type XnlDocument, type XnlErrorCode, type XnlMutation, type XnlMutationOptions, type XnlNode, XnlParseError, type XnlPath, XnlPathError, type XnlWord, applyMutations, batchLoad, deleteAtPath, diffNodes, isWord, loadFromString, resolveNode as loadNode, parsePath, parseUniqueChildren, parseXnl, parseXnlSingleNode, resolvePath, setPathValue, wordToString };
|
|
161
|
+
export { type AttributeMap, type CommentNode, type DataElementNode, type ElementNode, type ElementNodeKind, type ExtendBody, GetWordFullName, MakeWord, type MetadataIdMode, type MutationType, type ParseWarning, type PathItem, type PathItemType, type SingleNodeResult, type TextElementNode, type UniqueChildrenResult, type ValueLiteral, XNL, type XnlDocument, type XnlErrorCode, type XnlMutation, type XnlMutationOptions, type XnlNode, XnlParseError, type XnlPath, XnlPathError, type XnlWord, applyMutations, batchLoad, deleteAtPath, diffNodes, isWord, loadFromString, resolveNode as loadNode, parsePath, parseUniqueChildren, parseXnl, parseXnlSingleNode, resolvePath, setPathValue, stringify as stringifyLineBlock, wordToString };
|
package/dist/index.js
CHANGED
|
@@ -543,24 +543,24 @@ function isDocument(value) {
|
|
|
543
543
|
}
|
|
544
544
|
function serializeNode(node, state) {
|
|
545
545
|
if (isComment(node)) {
|
|
546
|
-
const
|
|
547
|
-
return `${
|
|
546
|
+
const pad2 = state.pretty ? state.indent.repeat(state.depth) : "";
|
|
547
|
+
return `${pad2}<!-- ${node.value} -->`;
|
|
548
548
|
}
|
|
549
549
|
if (isElement(node)) {
|
|
550
|
-
const
|
|
550
|
+
const pad2 = state.pretty ? state.indent.repeat(state.depth) : "";
|
|
551
551
|
if (node.kind === "TextElement") {
|
|
552
552
|
const metaStr2 = serializeInlineAttributes(node.metadata, state);
|
|
553
553
|
const attrStr = node.attributes ? ` ${serializeAttributeBlock(node.attributes, state)}` : "";
|
|
554
554
|
const idPart2 = node.id ? ` #${formatWord(node.id)}` : "";
|
|
555
555
|
const marker = node.textMarker ?? "";
|
|
556
|
-
return `${
|
|
556
|
+
return `${pad2}<${node.tag}${idPart2}${metaStr2}${attrStr} ?${marker}>${node.text ?? ""}</?${marker}>`;
|
|
557
557
|
}
|
|
558
558
|
const metaStr = serializeInlineAttributes(node.metadata, state);
|
|
559
559
|
const attrPart = node.attributes ? ` ${serializeAttributeBlock(node.attributes, state)}` : "";
|
|
560
560
|
const bodyPart = node.body ? ` ${serializeArrayBlock(node.body, state)}` : "";
|
|
561
561
|
const extendPart = node.extend ? ` ${serializeExtendBlock(node.extend, state)}` : "";
|
|
562
562
|
const idPart = node.id ? ` #${formatWord(node.id)}` : "";
|
|
563
|
-
return `${
|
|
563
|
+
return `${pad2}<${node.tag}${idPart}${metaStr}${attrPart}${bodyPart}${extendPart}>`;
|
|
564
564
|
}
|
|
565
565
|
if (Array.isArray(node)) {
|
|
566
566
|
return serializeArrayLiteral(node, state);
|
|
@@ -583,9 +583,9 @@ function serializeAttributeBlock(attrs, state) {
|
|
|
583
583
|
return `{ ${entries} }`;
|
|
584
584
|
}
|
|
585
585
|
const nextDepth = state.depth + 1;
|
|
586
|
-
const
|
|
586
|
+
const pad2 = state.indent.repeat(nextDepth);
|
|
587
587
|
const lines = Object.entries(attrs).map(
|
|
588
|
-
([k, v]) => `${
|
|
588
|
+
([k, v]) => `${pad2}${serializeKey(k)} = ${serializeValueNode(v, { ...state, depth: nextDepth })}`
|
|
589
589
|
);
|
|
590
590
|
const closingPad = state.indent.repeat(state.depth);
|
|
591
591
|
return `{
|
|
@@ -598,8 +598,8 @@ function serializeArrayBlock(items, state) {
|
|
|
598
598
|
return `[ ${serialized} ]`;
|
|
599
599
|
}
|
|
600
600
|
const nextDepth = state.depth + 1;
|
|
601
|
-
const
|
|
602
|
-
const lines = items.map((item) => `${
|
|
601
|
+
const pad2 = state.indent.repeat(nextDepth);
|
|
602
|
+
const lines = items.map((item) => `${pad2}${serializeValueNode(item, { ...state, depth: nextDepth })}`);
|
|
603
603
|
const closingPad = state.indent.repeat(state.depth);
|
|
604
604
|
return `[
|
|
605
605
|
${lines.join("\n")}
|
|
@@ -611,8 +611,8 @@ function serializeExtendBlock(extend, state) {
|
|
|
611
611
|
return `( ${children} )`;
|
|
612
612
|
}
|
|
613
613
|
const nextDepth = state.depth + 1;
|
|
614
|
-
const
|
|
615
|
-
const childStrings = extend.order.map((name) => `${
|
|
614
|
+
const pad2 = state.indent.repeat(nextDepth);
|
|
615
|
+
const childStrings = extend.order.map((name) => `${pad2}${serializeNode(extend.children[name], { ...state, depth: nextDepth })}`);
|
|
616
616
|
const closingPad = state.indent.repeat(state.depth);
|
|
617
617
|
return `(
|
|
618
618
|
${childStrings.join("\n")}
|
|
@@ -636,9 +636,9 @@ function serializeObjectLiteral(obj, state) {
|
|
|
636
636
|
return `{ ${Object.entries(obj).map(([k, v]) => `${serializeKey(k)} = ${serializeValueNode(v, state)}`).join(" ")} }`;
|
|
637
637
|
}
|
|
638
638
|
const nextDepth = state.depth + 1;
|
|
639
|
-
const
|
|
639
|
+
const pad2 = state.indent.repeat(nextDepth);
|
|
640
640
|
const lines = Object.entries(obj).map(
|
|
641
|
-
([k, v]) => `${
|
|
641
|
+
([k, v]) => `${pad2}${serializeKey(k)} = ${serializeValueNode(v, { ...state, depth: nextDepth })}`
|
|
642
642
|
);
|
|
643
643
|
const closingPad = state.indent.repeat(state.depth);
|
|
644
644
|
return `{
|
|
@@ -650,8 +650,8 @@ function serializeArrayLiteral(arr, state) {
|
|
|
650
650
|
return `[${arr.map((v) => serializeValueNode(v, state)).join(" ")}]`;
|
|
651
651
|
}
|
|
652
652
|
const nextDepth = state.depth + 1;
|
|
653
|
-
const
|
|
654
|
-
const lines = arr.map((v) => `${
|
|
653
|
+
const pad2 = state.indent.repeat(nextDepth);
|
|
654
|
+
const lines = arr.map((v) => `${pad2}${serializeValueNode(v, { ...state, depth: nextDepth })}`);
|
|
655
655
|
const closingPad = state.indent.repeat(state.depth);
|
|
656
656
|
return `[
|
|
657
657
|
${lines.join("\n")}
|
|
@@ -677,6 +677,191 @@ function formatWord(word) {
|
|
|
677
677
|
return wordToString(word) ?? "";
|
|
678
678
|
}
|
|
679
679
|
|
|
680
|
+
// src/lineBlockFormatter.ts
|
|
681
|
+
var ULID_ENCODING = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
682
|
+
var lastUlidTime = -1;
|
|
683
|
+
var lastUlidRandom = [];
|
|
684
|
+
function stringify2(value, options = {}) {
|
|
685
|
+
const state = {
|
|
686
|
+
indent: typeof options.indent === "string" ? options.indent : " ".repeat(options.indent ?? 2),
|
|
687
|
+
depth: 0,
|
|
688
|
+
textMarkerFactory: options.textMarkerFactory ?? makeUlid
|
|
689
|
+
};
|
|
690
|
+
if (isDocument2(value)) {
|
|
691
|
+
return value.nodes.map((node) => serializeNode2(node, state)).join("\n");
|
|
692
|
+
}
|
|
693
|
+
return serializeNode2(value, state);
|
|
694
|
+
}
|
|
695
|
+
function serializeNode2(node, state) {
|
|
696
|
+
if (isComment2(node)) return `${pad(state)}<!-- ${node.value} -->`;
|
|
697
|
+
if (isElement2(node)) return serializeElement(node, state);
|
|
698
|
+
return `${pad(state)}${serializeInlineValue(node, state)}`;
|
|
699
|
+
}
|
|
700
|
+
function serializeElement(node, state) {
|
|
701
|
+
if (node.kind === "TextElement") return serializeTextElement(node, state);
|
|
702
|
+
return serializeDataElement(node, state);
|
|
703
|
+
}
|
|
704
|
+
function serializeTextElement(node, state) {
|
|
705
|
+
const marker = node.textMarker ?? state.textMarkerFactory();
|
|
706
|
+
const open = [
|
|
707
|
+
`<${node.tag}`,
|
|
708
|
+
serializeId(node.id),
|
|
709
|
+
serializeMetadata(node.metadata, state),
|
|
710
|
+
node.attributes ? ` ${serializeAttributeBlock2(node.attributes, state)}` : "",
|
|
711
|
+
` ?${marker}>`
|
|
712
|
+
].join("");
|
|
713
|
+
const text = node.text ?? "";
|
|
714
|
+
const currentPad = pad(state);
|
|
715
|
+
const alignedText = text.replace(/\r?\n/g, (lineBreak) => `${lineBreak}${currentPad}`);
|
|
716
|
+
return `${currentPad}${open}${alignedText}</?${marker}>`;
|
|
717
|
+
}
|
|
718
|
+
function serializeDataElement(node, state) {
|
|
719
|
+
const open = [
|
|
720
|
+
`<${node.tag}`,
|
|
721
|
+
serializeId(node.id),
|
|
722
|
+
serializeMetadata(node.metadata, state),
|
|
723
|
+
node.attributes ? ` ${serializeAttributeBlock2(node.attributes, state)}` : ""
|
|
724
|
+
].join("");
|
|
725
|
+
const sections = [];
|
|
726
|
+
if (node.body) sections.push(serializeArrayBlock2(node.body, state));
|
|
727
|
+
if (node.extend) sections.push(serializeExtendBlock2(node.extend, state));
|
|
728
|
+
if (sections.length === 0) return `${pad(state)}${open}>`;
|
|
729
|
+
if (sections.length === 1) return `${pad(state)}${open} ${sections[0]}>`;
|
|
730
|
+
return `${pad(state)}${open} ${sections.join(" ")}>`;
|
|
731
|
+
}
|
|
732
|
+
function serializeArrayBlock2(items, state) {
|
|
733
|
+
if (items.length === 0) return "[]";
|
|
734
|
+
const nextState = { ...state, depth: state.depth + 1 };
|
|
735
|
+
const lines = items.map((item) => serializeNode2(item, nextState));
|
|
736
|
+
return `[
|
|
737
|
+
${lines.join("\n")}
|
|
738
|
+
${pad(state)}]`;
|
|
739
|
+
}
|
|
740
|
+
function serializeExtendBlock2(extend, state) {
|
|
741
|
+
if (extend.order.length === 0) return "()";
|
|
742
|
+
const nextState = { ...state, depth: state.depth + 1 };
|
|
743
|
+
const lines = extend.order.map((name) => serializeElement(extend.children[name], nextState));
|
|
744
|
+
return `(
|
|
745
|
+
${lines.join("\n")}
|
|
746
|
+
${pad(state)})`;
|
|
747
|
+
}
|
|
748
|
+
function serializeMetadata(attrs, state) {
|
|
749
|
+
const entries = Object.entries(attrs);
|
|
750
|
+
if (entries.length === 0) return "";
|
|
751
|
+
return " " + entries.map(([key, value]) => `${serializeKey2(key)}=${serializeInlineValue(value, state)}`).join(" ");
|
|
752
|
+
}
|
|
753
|
+
function serializeAttributeBlock2(attrs, state) {
|
|
754
|
+
const entries = Object.entries(attrs).map(([key, value]) => `${serializeKey2(key)} = ${serializeInlineValue(value, state)}`).join(" ");
|
|
755
|
+
return `{ ${entries} }`;
|
|
756
|
+
}
|
|
757
|
+
function serializeInlineValue(value, state) {
|
|
758
|
+
if (isComment2(value)) return `<!-- ${value.value} -->`;
|
|
759
|
+
if (isElement2(value)) return serializeInlineElement(value, state);
|
|
760
|
+
if (isWord(value)) return formatWord2(value);
|
|
761
|
+
if (Array.isArray(value)) return serializeInlineArray(value, state);
|
|
762
|
+
if (isPlainObject2(value)) return serializeInlineObject(value, state);
|
|
763
|
+
return serializePrimitive2(value);
|
|
764
|
+
}
|
|
765
|
+
function serializeInlineElement(node, state) {
|
|
766
|
+
const marker = node.kind === "TextElement" ? node.textMarker ?? state.textMarkerFactory() : void 0;
|
|
767
|
+
const open = [
|
|
768
|
+
`<${node.tag}`,
|
|
769
|
+
serializeId(node.id),
|
|
770
|
+
serializeMetadata(node.metadata, state),
|
|
771
|
+
node.attributes ? ` ${serializeAttributeBlock2(node.attributes, state)}` : ""
|
|
772
|
+
].join("");
|
|
773
|
+
if (node.kind === "TextElement") return `${open} ?${marker}>${node.text ?? ""}</?${marker}>`;
|
|
774
|
+
const sections = [];
|
|
775
|
+
if (node.body) sections.push(serializeInlineArrayBlock(node.body, state));
|
|
776
|
+
if (node.extend) sections.push(serializeInlineExtendBlock(node.extend, state));
|
|
777
|
+
if (sections.length === 0) return `${open}>`;
|
|
778
|
+
return `${open} ${sections.join(" ")}>`;
|
|
779
|
+
}
|
|
780
|
+
function serializeInlineArrayBlock(items, state) {
|
|
781
|
+
return `[ ${items.map((item) => serializeInlineValue(item, state)).join(" ")} ]`;
|
|
782
|
+
}
|
|
783
|
+
function serializeInlineExtendBlock(extend, state) {
|
|
784
|
+
return `( ${extend.order.map((name) => serializeInlineElement(extend.children[name], state)).join(" ")} )`;
|
|
785
|
+
}
|
|
786
|
+
function serializeInlineObject(value, state) {
|
|
787
|
+
const entries = Object.entries(value).map(([key, child]) => `${serializeKey2(key)} = ${serializeInlineValue(child, state)}`).join(" ");
|
|
788
|
+
return `{ ${entries} }`;
|
|
789
|
+
}
|
|
790
|
+
function serializeInlineArray(value, state) {
|
|
791
|
+
return `[${value.map((child) => serializeInlineValue(child, state)).join(" ")}]`;
|
|
792
|
+
}
|
|
793
|
+
function serializePrimitive2(value) {
|
|
794
|
+
if (value === null) return "null";
|
|
795
|
+
if (typeof value === "string") return `"${escapeString2(value)}"`;
|
|
796
|
+
if (typeof value === "boolean") return value ? "true" : "false";
|
|
797
|
+
return String(value);
|
|
798
|
+
}
|
|
799
|
+
function serializeId(id) {
|
|
800
|
+
const value = formatWord2(id);
|
|
801
|
+
return value ? ` #${value}` : "";
|
|
802
|
+
}
|
|
803
|
+
function formatWord2(word) {
|
|
804
|
+
return wordToString(word) ?? "";
|
|
805
|
+
}
|
|
806
|
+
function serializeKey2(key) {
|
|
807
|
+
if (/^[A-Za-z_][A-Za-z0-9_-]*$/.test(key)) return key;
|
|
808
|
+
return `"${escapeString2(key)}"`;
|
|
809
|
+
}
|
|
810
|
+
function escapeString2(value) {
|
|
811
|
+
return value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\t/g, "\\t").replace(/\r/g, "\\r");
|
|
812
|
+
}
|
|
813
|
+
function pad(state) {
|
|
814
|
+
return state.indent.repeat(state.depth);
|
|
815
|
+
}
|
|
816
|
+
function isDocument2(value) {
|
|
817
|
+
return value && Array.isArray(value.nodes);
|
|
818
|
+
}
|
|
819
|
+
function isElement2(value) {
|
|
820
|
+
return typeof value === "object" && value !== null && (value.kind === "DataElement" || value.kind === "TextElement");
|
|
821
|
+
}
|
|
822
|
+
function isComment2(value) {
|
|
823
|
+
return typeof value === "object" && value !== null && value.kind === "Comment";
|
|
824
|
+
}
|
|
825
|
+
function isPlainObject2(value) {
|
|
826
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
827
|
+
const kind = value.kind;
|
|
828
|
+
return kind !== "DataElement" && kind !== "TextElement" && kind !== "Comment" && kind !== "Word";
|
|
829
|
+
}
|
|
830
|
+
function makeUlid(now = Date.now()) {
|
|
831
|
+
if (now > lastUlidTime) {
|
|
832
|
+
lastUlidTime = now;
|
|
833
|
+
lastUlidRandom = nextRandom();
|
|
834
|
+
} else {
|
|
835
|
+
lastUlidRandom = incrementRandom(lastUlidRandom);
|
|
836
|
+
}
|
|
837
|
+
return encodeTime(lastUlidTime, 10) + encodeRandom(lastUlidRandom);
|
|
838
|
+
}
|
|
839
|
+
function encodeTime(time, length) {
|
|
840
|
+
let out = "";
|
|
841
|
+
for (let index = length - 1; index >= 0; index--) {
|
|
842
|
+
out = ULID_ENCODING.charAt(time % 32) + out;
|
|
843
|
+
time = Math.floor(time / 32);
|
|
844
|
+
}
|
|
845
|
+
return out;
|
|
846
|
+
}
|
|
847
|
+
function encodeRandom(values) {
|
|
848
|
+
return values.map((value) => ULID_ENCODING.charAt(value)).join("");
|
|
849
|
+
}
|
|
850
|
+
function nextRandom() {
|
|
851
|
+
return Array.from({ length: 16 }, () => Math.random() * 32 | 0);
|
|
852
|
+
}
|
|
853
|
+
function incrementRandom(values) {
|
|
854
|
+
const next = [...values];
|
|
855
|
+
for (let index = next.length - 1; index >= 0; index--) {
|
|
856
|
+
if (next[index] < 31) {
|
|
857
|
+
next[index] += 1;
|
|
858
|
+
return next;
|
|
859
|
+
}
|
|
860
|
+
next[index] = 0;
|
|
861
|
+
}
|
|
862
|
+
return next;
|
|
863
|
+
}
|
|
864
|
+
|
|
680
865
|
// src/path/index.ts
|
|
681
866
|
var XnlPathError = class extends Error {
|
|
682
867
|
};
|
|
@@ -772,7 +957,7 @@ function resolvePath(target, path, options = {}) {
|
|
|
772
957
|
current = current[item.value];
|
|
773
958
|
} else if (current && isTextElement(current)) {
|
|
774
959
|
current = current[item.value];
|
|
775
|
-
} else if (
|
|
960
|
+
} else if (isPlainObject3(current) || isDocument3(current)) {
|
|
776
961
|
current = current[item.value];
|
|
777
962
|
} else {
|
|
778
963
|
if (strict) throw new XnlPathError(`InstanceProperty '${item.value}' not allowed on current node`);
|
|
@@ -790,7 +975,7 @@ function resolvePath(target, path, options = {}) {
|
|
|
790
975
|
current = child;
|
|
791
976
|
continue;
|
|
792
977
|
}
|
|
793
|
-
if (!
|
|
978
|
+
if (!isPlainObject3(current)) {
|
|
794
979
|
if (strict) throw new XnlPathError("MapKey requires a map/object target");
|
|
795
980
|
return void 0;
|
|
796
981
|
}
|
|
@@ -888,7 +1073,7 @@ function deleteAtPath(target, path, options = {}) {
|
|
|
888
1073
|
const { parent, last } = getParentAndLast(target, parsed, { strict, createMissing: false });
|
|
889
1074
|
switch (last.type) {
|
|
890
1075
|
case "InstanceProperty":
|
|
891
|
-
if (
|
|
1076
|
+
if (isPlainObject3(parent) || isDataElement(parent) || isTextElement(parent) || isDocument3(parent)) {
|
|
892
1077
|
if (!(last.value in parent) && strict) {
|
|
893
1078
|
throw new XnlPathError(`InstanceProperty '${last.value}' not found`);
|
|
894
1079
|
}
|
|
@@ -972,8 +1157,8 @@ function getParentAndLast(target, path, opts) {
|
|
|
972
1157
|
current = current[item.value];
|
|
973
1158
|
} else if (current && isTextElement(current)) {
|
|
974
1159
|
current = current[item.value];
|
|
975
|
-
} else if (
|
|
976
|
-
if (current[item.value] === void 0 && createMissing &&
|
|
1160
|
+
} else if (isPlainObject3(current) || isDocument3(current)) {
|
|
1161
|
+
if (current[item.value] === void 0 && createMissing && isPlainObject3(current)) {
|
|
977
1162
|
current[item.value] = {};
|
|
978
1163
|
}
|
|
979
1164
|
current = current[item.value];
|
|
@@ -1085,7 +1270,7 @@ function readWhile(input, start, pred) {
|
|
|
1085
1270
|
return out;
|
|
1086
1271
|
}
|
|
1087
1272
|
function findByUniqueName(target, id) {
|
|
1088
|
-
const roots =
|
|
1273
|
+
const roots = isDocument3(target) ? target.nodes : [target];
|
|
1089
1274
|
for (const root of roots) {
|
|
1090
1275
|
const found = findInNode(root, id);
|
|
1091
1276
|
if (found) return found;
|
|
@@ -1094,7 +1279,7 @@ function findByUniqueName(target, id) {
|
|
|
1094
1279
|
}
|
|
1095
1280
|
function findByMetadataSelector(target, selector) {
|
|
1096
1281
|
const parsed = parseMetadataSelectorValue(selector);
|
|
1097
|
-
const roots =
|
|
1282
|
+
const roots = isDocument3(target) ? target.nodes : [target];
|
|
1098
1283
|
for (const root of roots) {
|
|
1099
1284
|
const found = findInNodeByMeta(root, parsed.key, parsed.value);
|
|
1100
1285
|
if (found) return found;
|
|
@@ -1103,7 +1288,7 @@ function findByMetadataSelector(target, selector) {
|
|
|
1103
1288
|
}
|
|
1104
1289
|
function findAllByMetadataSelector(target, selector) {
|
|
1105
1290
|
const parsed = parseMetadataSelectorValue(selector);
|
|
1106
|
-
const roots =
|
|
1291
|
+
const roots = isDocument3(target) ? target.nodes : [target];
|
|
1107
1292
|
const out = [];
|
|
1108
1293
|
for (const root of roots) {
|
|
1109
1294
|
collectInNodeByMeta(root, parsed.key, parsed.value, out);
|
|
@@ -1139,7 +1324,7 @@ function findInNodeByMeta(node, key, value) {
|
|
|
1139
1324
|
const found = findInNodeByMeta(child, key, value);
|
|
1140
1325
|
if (found) return found;
|
|
1141
1326
|
}
|
|
1142
|
-
} else if (
|
|
1327
|
+
} else if (isPlainObject3(node)) {
|
|
1143
1328
|
for (const k of Object.keys(node)) {
|
|
1144
1329
|
const found = findInNodeByMeta(node[k], key, value);
|
|
1145
1330
|
if (found) return found;
|
|
@@ -1173,7 +1358,7 @@ function collectInNodeByMeta(node, key, value, out) {
|
|
|
1173
1358
|
for (const child of node) {
|
|
1174
1359
|
collectInNodeByMeta(child, key, value, out);
|
|
1175
1360
|
}
|
|
1176
|
-
} else if (
|
|
1361
|
+
} else if (isPlainObject3(node)) {
|
|
1177
1362
|
for (const k of Object.keys(node)) {
|
|
1178
1363
|
collectInNodeByMeta(node[k], key, value, out);
|
|
1179
1364
|
}
|
|
@@ -1220,7 +1405,7 @@ function findInNode(node, id) {
|
|
|
1220
1405
|
const found = findInNode(child, id);
|
|
1221
1406
|
if (found) return found;
|
|
1222
1407
|
}
|
|
1223
|
-
} else if (
|
|
1408
|
+
} else if (isPlainObject3(node)) {
|
|
1224
1409
|
for (const key of Object.keys(node)) {
|
|
1225
1410
|
const found = findInNode(node[key], id);
|
|
1226
1411
|
if (found) return found;
|
|
@@ -1240,14 +1425,14 @@ function isTextElement(node) {
|
|
|
1240
1425
|
function isExtendBody(value) {
|
|
1241
1426
|
return value && typeof value === "object" && Array.isArray(value.order) && value.children;
|
|
1242
1427
|
}
|
|
1243
|
-
function
|
|
1428
|
+
function isDocument3(value) {
|
|
1244
1429
|
return value && typeof value === "object" && Array.isArray(value.nodes);
|
|
1245
1430
|
}
|
|
1246
|
-
function
|
|
1431
|
+
function isPlainObject3(value) {
|
|
1247
1432
|
return value !== null && typeof value === "object" && !Array.isArray(value) && !isElementNode(value) && !isExtendBody(value) && !isWord(value);
|
|
1248
1433
|
}
|
|
1249
1434
|
function ensureMap(value, strict) {
|
|
1250
|
-
if (!
|
|
1435
|
+
if (!isPlainObject3(value)) {
|
|
1251
1436
|
if (strict) throw new XnlPathError("Target is not a map/object");
|
|
1252
1437
|
}
|
|
1253
1438
|
}
|
|
@@ -1286,13 +1471,13 @@ function diffNodes(oldNode, newNode, basePath = [], opts = {}) {
|
|
|
1286
1471
|
if (!sameKind(oldNode, newNode)) {
|
|
1287
1472
|
throw new XnlPathError("Root kinds must match to diff");
|
|
1288
1473
|
}
|
|
1289
|
-
if (isValueLiteral(oldNode) ||
|
|
1474
|
+
if (isValueLiteral(oldNode) || isComment3(oldNode)) {
|
|
1290
1475
|
return oldNode === newNode ? [] : [{ type: "OBJECT_UPDATE", path: pathItems, valueAfter: newNode }];
|
|
1291
1476
|
}
|
|
1292
1477
|
if (Array.isArray(oldNode) && Array.isArray(newNode)) {
|
|
1293
1478
|
return diffArray(oldNode, newNode, pathItems, void 0, void 0, opts);
|
|
1294
1479
|
}
|
|
1295
|
-
if (
|
|
1480
|
+
if (isPlainObject4(oldNode) && isPlainObject4(newNode)) {
|
|
1296
1481
|
return diffMap(oldNode, newNode, pathItems, void 0, void 0, opts);
|
|
1297
1482
|
}
|
|
1298
1483
|
if (isTextElement2(oldNode) && isTextElement2(newNode)) {
|
|
@@ -1584,7 +1769,7 @@ function sameKind(a, b) {
|
|
|
1584
1769
|
if (isDataElement2(a) && isDataElement2(b)) return true;
|
|
1585
1770
|
if (isTextElement2(a) && isTextElement2(b)) return true;
|
|
1586
1771
|
if (Array.isArray(a) && Array.isArray(b)) return true;
|
|
1587
|
-
if (
|
|
1772
|
+
if (isPlainObject4(a) && isPlainObject4(b)) return true;
|
|
1588
1773
|
if (isValueLiteral(a) && isValueLiteral(b)) return true;
|
|
1589
1774
|
return typeof a === typeof b;
|
|
1590
1775
|
}
|
|
@@ -1598,7 +1783,7 @@ function isEqual(a, b) {
|
|
|
1598
1783
|
if (a.length !== b.length) return false;
|
|
1599
1784
|
return a.every((item, idx) => isEqual(item, b[idx]));
|
|
1600
1785
|
}
|
|
1601
|
-
if (
|
|
1786
|
+
if (isPlainObject4(a) && isPlainObject4(b)) {
|
|
1602
1787
|
const keysA = Object.keys(a);
|
|
1603
1788
|
const keysB = Object.keys(b);
|
|
1604
1789
|
if (keysA.length !== keysB.length) return false;
|
|
@@ -1606,7 +1791,7 @@ function isEqual(a, b) {
|
|
|
1606
1791
|
}
|
|
1607
1792
|
return false;
|
|
1608
1793
|
}
|
|
1609
|
-
function
|
|
1794
|
+
function isPlainObject4(value) {
|
|
1610
1795
|
return value !== null && typeof value === "object" && !Array.isArray(value) && !isDataElement2(value) && !isTextElement2(value) && !isWord(value);
|
|
1611
1796
|
}
|
|
1612
1797
|
function isDataElement2(node) {
|
|
@@ -1618,7 +1803,7 @@ function isTextElement2(node) {
|
|
|
1618
1803
|
function isValueLiteral(node) {
|
|
1619
1804
|
return typeof node === "string" || typeof node === "number" || typeof node === "boolean" || node === null || isWord(node);
|
|
1620
1805
|
}
|
|
1621
|
-
function
|
|
1806
|
+
function isComment3(node) {
|
|
1622
1807
|
return node && node.kind === "Comment";
|
|
1623
1808
|
}
|
|
1624
1809
|
var ip = (value) => ({ type: "InstanceProperty", value });
|
|
@@ -1953,7 +2138,7 @@ function cloneNode(node) {
|
|
|
1953
2138
|
if (isWord(node)) {
|
|
1954
2139
|
return cloneWord(node);
|
|
1955
2140
|
}
|
|
1956
|
-
if (
|
|
2141
|
+
if (isPlainObject5(node)) {
|
|
1957
2142
|
const out = {};
|
|
1958
2143
|
for (const key of Object.keys(node)) {
|
|
1959
2144
|
out[key] = cloneNode(node[key]);
|
|
@@ -1979,7 +2164,7 @@ function mergeMaps(ctx, base, override, scope) {
|
|
|
1979
2164
|
continue;
|
|
1980
2165
|
}
|
|
1981
2166
|
const resolvedValue = resolveValue(ctx, value, scope);
|
|
1982
|
-
if (
|
|
2167
|
+
if (isPlainObject5(resolvedValue) && isPlainObject5(result[key])) {
|
|
1983
2168
|
result[key] = mergeMaps(ctx, result[key], resolvedValue, scope);
|
|
1984
2169
|
} else if (Array.isArray(resolvedValue) && Array.isArray(result[key])) {
|
|
1985
2170
|
result[key] = mergeArray(ctx, result[key], resolvedValue, scope);
|
|
@@ -2000,7 +2185,7 @@ function mergeArray(ctx, baseArr, overrideArr, scope) {
|
|
|
2000
2185
|
const resolved = resolveValue(ctx, value, scope);
|
|
2001
2186
|
if (i < result.length) {
|
|
2002
2187
|
const baseVal = result[i];
|
|
2003
|
-
if (
|
|
2188
|
+
if (isPlainObject5(baseVal) && isPlainObject5(resolved)) {
|
|
2004
2189
|
result[i] = mergeMaps(ctx, baseVal, resolved, scope);
|
|
2005
2190
|
} else if (Array.isArray(baseVal) && Array.isArray(resolved)) {
|
|
2006
2191
|
result[i] = mergeArray(ctx, baseVal, resolved, scope);
|
|
@@ -2055,7 +2240,7 @@ function isDataElement3(node) {
|
|
|
2055
2240
|
function isTextElement3(node) {
|
|
2056
2241
|
return node && node.kind === "TextElement";
|
|
2057
2242
|
}
|
|
2058
|
-
function
|
|
2243
|
+
function isPlainObject5(value) {
|
|
2059
2244
|
return value !== null && typeof value === "object" && !Array.isArray(value) && !isDataElement3(value) && !isWord(value);
|
|
2060
2245
|
}
|
|
2061
2246
|
function resolveValue(ctx, value, scope) {
|
|
@@ -2072,7 +2257,7 @@ function resolveValue(ctx, value, scope) {
|
|
|
2072
2257
|
if (Array.isArray(value)) {
|
|
2073
2258
|
return value.map((v) => resolveValue(ctx, v, scope));
|
|
2074
2259
|
}
|
|
2075
|
-
if (
|
|
2260
|
+
if (isPlainObject5(value)) {
|
|
2076
2261
|
const out = {};
|
|
2077
2262
|
for (const key of Object.keys(value)) {
|
|
2078
2263
|
out[key] = resolveValue(ctx, value[key], scope);
|
|
@@ -2144,6 +2329,7 @@ var XNL = {
|
|
|
2144
2329
|
parseSingle: parseXnlSingleNode,
|
|
2145
2330
|
parseUnique: parseUniqueChildren,
|
|
2146
2331
|
stringify,
|
|
2332
|
+
stringifyLineBlock: stringify2,
|
|
2147
2333
|
path: {
|
|
2148
2334
|
parse: parsePath,
|
|
2149
2335
|
resolve: resolvePath,
|
|
@@ -2161,6 +2347,6 @@ var XNL = {
|
|
|
2161
2347
|
}
|
|
2162
2348
|
};
|
|
2163
2349
|
|
|
2164
|
-
export { GetWordFullName, MakeWord, XNL, XnlParseError, XnlPathError, applyMutations, batchLoad, deleteAtPath, diffNodes, isWord, loadFromString, resolveNode as loadNode, parsePath, parseUniqueChildren, parseXnl, parseXnlSingleNode, resolvePath, setPathValue, wordToString };
|
|
2350
|
+
export { GetWordFullName, MakeWord, XNL, XnlParseError, XnlPathError, applyMutations, batchLoad, deleteAtPath, diffNodes, isWord, loadFromString, resolveNode as loadNode, parsePath, parseUniqueChildren, parseXnl, parseXnlSingleNode, resolvePath, setPathValue, stringify2 as stringifyLineBlock, wordToString };
|
|
2165
2351
|
//# sourceMappingURL=index.js.map
|
|
2166
2352
|
//# sourceMappingURL=index.js.map
|