xnl-core 0.1.1 → 0.1.3
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 +239 -42
- 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 +239 -43
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -375,8 +375,15 @@ function parseWordLiteral(state) {
|
|
|
375
375
|
return { kind: "Word", namespace: parts, name };
|
|
376
376
|
}
|
|
377
377
|
function readOptionalMarker(state) {
|
|
378
|
-
if (!
|
|
379
|
-
return
|
|
378
|
+
if (!isMarkerStart(peek(state))) return void 0;
|
|
379
|
+
return readMarker(state);
|
|
380
|
+
}
|
|
381
|
+
function readMarker(state) {
|
|
382
|
+
const start = state.pos;
|
|
383
|
+
while (!eof(state) && isIdentifierChar(state.input[state.pos])) {
|
|
384
|
+
state.pos++;
|
|
385
|
+
}
|
|
386
|
+
return state.input.slice(start, state.pos);
|
|
380
387
|
}
|
|
381
388
|
function readKey(state, message) {
|
|
382
389
|
const ch = peek(state);
|
|
@@ -491,6 +498,9 @@ function isIdentifierChar(ch) {
|
|
|
491
498
|
if (!ch) return false;
|
|
492
499
|
return /[A-Za-z0-9_-]/.test(ch);
|
|
493
500
|
}
|
|
501
|
+
function isMarkerStart(ch) {
|
|
502
|
+
return isIdentifierStart(ch) || isDigit(ch);
|
|
503
|
+
}
|
|
494
504
|
function isWhitespace(ch) {
|
|
495
505
|
return ch === " " || ch === " " || ch === "\n" || ch === "\r";
|
|
496
506
|
}
|
|
@@ -535,24 +545,24 @@ function isDocument(value) {
|
|
|
535
545
|
}
|
|
536
546
|
function serializeNode(node, state) {
|
|
537
547
|
if (isComment(node)) {
|
|
538
|
-
const
|
|
539
|
-
return `${
|
|
548
|
+
const pad2 = state.pretty ? state.indent.repeat(state.depth) : "";
|
|
549
|
+
return `${pad2}<!-- ${node.value} -->`;
|
|
540
550
|
}
|
|
541
551
|
if (isElement(node)) {
|
|
542
|
-
const
|
|
552
|
+
const pad2 = state.pretty ? state.indent.repeat(state.depth) : "";
|
|
543
553
|
if (node.kind === "TextElement") {
|
|
544
554
|
const metaStr2 = serializeInlineAttributes(node.metadata, state);
|
|
545
555
|
const attrStr = node.attributes ? ` ${serializeAttributeBlock(node.attributes, state)}` : "";
|
|
546
556
|
const idPart2 = node.id ? ` #${formatWord(node.id)}` : "";
|
|
547
557
|
const marker = node.textMarker ?? "";
|
|
548
|
-
return `${
|
|
558
|
+
return `${pad2}<${node.tag}${idPart2}${metaStr2}${attrStr} ?${marker}>${node.text ?? ""}</?${marker}>`;
|
|
549
559
|
}
|
|
550
560
|
const metaStr = serializeInlineAttributes(node.metadata, state);
|
|
551
561
|
const attrPart = node.attributes ? ` ${serializeAttributeBlock(node.attributes, state)}` : "";
|
|
552
562
|
const bodyPart = node.body ? ` ${serializeArrayBlock(node.body, state)}` : "";
|
|
553
563
|
const extendPart = node.extend ? ` ${serializeExtendBlock(node.extend, state)}` : "";
|
|
554
564
|
const idPart = node.id ? ` #${formatWord(node.id)}` : "";
|
|
555
|
-
return `${
|
|
565
|
+
return `${pad2}<${node.tag}${idPart}${metaStr}${attrPart}${bodyPart}${extendPart}>`;
|
|
556
566
|
}
|
|
557
567
|
if (Array.isArray(node)) {
|
|
558
568
|
return serializeArrayLiteral(node, state);
|
|
@@ -575,9 +585,9 @@ function serializeAttributeBlock(attrs, state) {
|
|
|
575
585
|
return `{ ${entries} }`;
|
|
576
586
|
}
|
|
577
587
|
const nextDepth = state.depth + 1;
|
|
578
|
-
const
|
|
588
|
+
const pad2 = state.indent.repeat(nextDepth);
|
|
579
589
|
const lines = Object.entries(attrs).map(
|
|
580
|
-
([k, v]) => `${
|
|
590
|
+
([k, v]) => `${pad2}${serializeKey(k)} = ${serializeValueNode(v, { ...state, depth: nextDepth })}`
|
|
581
591
|
);
|
|
582
592
|
const closingPad = state.indent.repeat(state.depth);
|
|
583
593
|
return `{
|
|
@@ -590,8 +600,8 @@ function serializeArrayBlock(items, state) {
|
|
|
590
600
|
return `[ ${serialized} ]`;
|
|
591
601
|
}
|
|
592
602
|
const nextDepth = state.depth + 1;
|
|
593
|
-
const
|
|
594
|
-
const lines = items.map((item) => `${
|
|
603
|
+
const pad2 = state.indent.repeat(nextDepth);
|
|
604
|
+
const lines = items.map((item) => `${pad2}${serializeValueNode(item, { ...state, depth: nextDepth })}`);
|
|
595
605
|
const closingPad = state.indent.repeat(state.depth);
|
|
596
606
|
return `[
|
|
597
607
|
${lines.join("\n")}
|
|
@@ -603,8 +613,8 @@ function serializeExtendBlock(extend, state) {
|
|
|
603
613
|
return `( ${children} )`;
|
|
604
614
|
}
|
|
605
615
|
const nextDepth = state.depth + 1;
|
|
606
|
-
const
|
|
607
|
-
const childStrings = extend.order.map((name) => `${
|
|
616
|
+
const pad2 = state.indent.repeat(nextDepth);
|
|
617
|
+
const childStrings = extend.order.map((name) => `${pad2}${serializeNode(extend.children[name], { ...state, depth: nextDepth })}`);
|
|
608
618
|
const closingPad = state.indent.repeat(state.depth);
|
|
609
619
|
return `(
|
|
610
620
|
${childStrings.join("\n")}
|
|
@@ -628,9 +638,9 @@ function serializeObjectLiteral(obj, state) {
|
|
|
628
638
|
return `{ ${Object.entries(obj).map(([k, v]) => `${serializeKey(k)} = ${serializeValueNode(v, state)}`).join(" ")} }`;
|
|
629
639
|
}
|
|
630
640
|
const nextDepth = state.depth + 1;
|
|
631
|
-
const
|
|
641
|
+
const pad2 = state.indent.repeat(nextDepth);
|
|
632
642
|
const lines = Object.entries(obj).map(
|
|
633
|
-
([k, v]) => `${
|
|
643
|
+
([k, v]) => `${pad2}${serializeKey(k)} = ${serializeValueNode(v, { ...state, depth: nextDepth })}`
|
|
634
644
|
);
|
|
635
645
|
const closingPad = state.indent.repeat(state.depth);
|
|
636
646
|
return `{
|
|
@@ -642,8 +652,8 @@ function serializeArrayLiteral(arr, state) {
|
|
|
642
652
|
return `[${arr.map((v) => serializeValueNode(v, state)).join(" ")}]`;
|
|
643
653
|
}
|
|
644
654
|
const nextDepth = state.depth + 1;
|
|
645
|
-
const
|
|
646
|
-
const lines = arr.map((v) => `${
|
|
655
|
+
const pad2 = state.indent.repeat(nextDepth);
|
|
656
|
+
const lines = arr.map((v) => `${pad2}${serializeValueNode(v, { ...state, depth: nextDepth })}`);
|
|
647
657
|
const closingPad = state.indent.repeat(state.depth);
|
|
648
658
|
return `[
|
|
649
659
|
${lines.join("\n")}
|
|
@@ -669,6 +679,191 @@ function formatWord(word) {
|
|
|
669
679
|
return wordToString(word) ?? "";
|
|
670
680
|
}
|
|
671
681
|
|
|
682
|
+
// src/lineBlockFormatter.ts
|
|
683
|
+
var ULID_ENCODING = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
684
|
+
var lastUlidTime = -1;
|
|
685
|
+
var lastUlidRandom = [];
|
|
686
|
+
function stringify2(value, options = {}) {
|
|
687
|
+
const state = {
|
|
688
|
+
indent: typeof options.indent === "string" ? options.indent : " ".repeat(options.indent ?? 2),
|
|
689
|
+
depth: 0,
|
|
690
|
+
textMarkerFactory: options.textMarkerFactory ?? makeUlid
|
|
691
|
+
};
|
|
692
|
+
if (isDocument2(value)) {
|
|
693
|
+
return value.nodes.map((node) => serializeNode2(node, state)).join("\n");
|
|
694
|
+
}
|
|
695
|
+
return serializeNode2(value, state);
|
|
696
|
+
}
|
|
697
|
+
function serializeNode2(node, state) {
|
|
698
|
+
if (isComment2(node)) return `${pad(state)}<!-- ${node.value} -->`;
|
|
699
|
+
if (isElement2(node)) return serializeElement(node, state);
|
|
700
|
+
return `${pad(state)}${serializeInlineValue(node, state)}`;
|
|
701
|
+
}
|
|
702
|
+
function serializeElement(node, state) {
|
|
703
|
+
if (node.kind === "TextElement") return serializeTextElement(node, state);
|
|
704
|
+
return serializeDataElement(node, state);
|
|
705
|
+
}
|
|
706
|
+
function serializeTextElement(node, state) {
|
|
707
|
+
const marker = node.textMarker ?? state.textMarkerFactory();
|
|
708
|
+
const open = [
|
|
709
|
+
`<${node.tag}`,
|
|
710
|
+
serializeId(node.id),
|
|
711
|
+
serializeMetadata(node.metadata, state),
|
|
712
|
+
node.attributes ? ` ${serializeAttributeBlock2(node.attributes, state)}` : "",
|
|
713
|
+
` ?${marker}>`
|
|
714
|
+
].join("");
|
|
715
|
+
const text = node.text ?? "";
|
|
716
|
+
const textLines = text.length > 0 ? text.split(/\r?\n/).map((line) => `${state.indent.repeat(state.depth + 1)}${line}`) : [];
|
|
717
|
+
const close = `${pad(state)}</?${marker}>`;
|
|
718
|
+
return [`${pad(state)}${open}`, ...textLines, close].join("\n");
|
|
719
|
+
}
|
|
720
|
+
function serializeDataElement(node, state) {
|
|
721
|
+
const open = [
|
|
722
|
+
`<${node.tag}`,
|
|
723
|
+
serializeId(node.id),
|
|
724
|
+
serializeMetadata(node.metadata, state),
|
|
725
|
+
node.attributes ? ` ${serializeAttributeBlock2(node.attributes, state)}` : ""
|
|
726
|
+
].join("");
|
|
727
|
+
const sections = [];
|
|
728
|
+
if (node.body) sections.push(serializeArrayBlock2(node.body, state));
|
|
729
|
+
if (node.extend) sections.push(serializeExtendBlock2(node.extend, state));
|
|
730
|
+
if (sections.length === 0) return `${pad(state)}${open}>`;
|
|
731
|
+
if (sections.length === 1) return `${pad(state)}${open} ${sections[0]}>`;
|
|
732
|
+
return `${pad(state)}${open} ${sections.join(" ")}>`;
|
|
733
|
+
}
|
|
734
|
+
function serializeArrayBlock2(items, state) {
|
|
735
|
+
if (items.length === 0) return "[]";
|
|
736
|
+
const nextState = { ...state, depth: state.depth + 1 };
|
|
737
|
+
const lines = items.map((item) => serializeNode2(item, nextState));
|
|
738
|
+
return `[
|
|
739
|
+
${lines.join("\n")}
|
|
740
|
+
${pad(state)}]`;
|
|
741
|
+
}
|
|
742
|
+
function serializeExtendBlock2(extend, state) {
|
|
743
|
+
if (extend.order.length === 0) return "()";
|
|
744
|
+
const nextState = { ...state, depth: state.depth + 1 };
|
|
745
|
+
const lines = extend.order.map((name) => serializeElement(extend.children[name], nextState));
|
|
746
|
+
return `(
|
|
747
|
+
${lines.join("\n")}
|
|
748
|
+
${pad(state)})`;
|
|
749
|
+
}
|
|
750
|
+
function serializeMetadata(attrs, state) {
|
|
751
|
+
const entries = Object.entries(attrs);
|
|
752
|
+
if (entries.length === 0) return "";
|
|
753
|
+
return " " + entries.map(([key, value]) => `${serializeKey2(key)}=${serializeInlineValue(value, state)}`).join(" ");
|
|
754
|
+
}
|
|
755
|
+
function serializeAttributeBlock2(attrs, state) {
|
|
756
|
+
const entries = Object.entries(attrs).map(([key, value]) => `${serializeKey2(key)} = ${serializeInlineValue(value, state)}`).join(" ");
|
|
757
|
+
return `{ ${entries} }`;
|
|
758
|
+
}
|
|
759
|
+
function serializeInlineValue(value, state) {
|
|
760
|
+
if (isComment2(value)) return `<!-- ${value.value} -->`;
|
|
761
|
+
if (isElement2(value)) return serializeInlineElement(value, state);
|
|
762
|
+
if (isWord(value)) return formatWord2(value);
|
|
763
|
+
if (Array.isArray(value)) return serializeInlineArray(value, state);
|
|
764
|
+
if (isPlainObject2(value)) return serializeInlineObject(value, state);
|
|
765
|
+
return serializePrimitive2(value);
|
|
766
|
+
}
|
|
767
|
+
function serializeInlineElement(node, state) {
|
|
768
|
+
const marker = node.kind === "TextElement" ? node.textMarker ?? state.textMarkerFactory() : void 0;
|
|
769
|
+
const open = [
|
|
770
|
+
`<${node.tag}`,
|
|
771
|
+
serializeId(node.id),
|
|
772
|
+
serializeMetadata(node.metadata, state),
|
|
773
|
+
node.attributes ? ` ${serializeAttributeBlock2(node.attributes, state)}` : ""
|
|
774
|
+
].join("");
|
|
775
|
+
if (node.kind === "TextElement") return `${open} ?${marker}>${node.text ?? ""}</?${marker}>`;
|
|
776
|
+
const sections = [];
|
|
777
|
+
if (node.body) sections.push(serializeInlineArrayBlock(node.body, state));
|
|
778
|
+
if (node.extend) sections.push(serializeInlineExtendBlock(node.extend, state));
|
|
779
|
+
if (sections.length === 0) return `${open}>`;
|
|
780
|
+
return `${open} ${sections.join(" ")}>`;
|
|
781
|
+
}
|
|
782
|
+
function serializeInlineArrayBlock(items, state) {
|
|
783
|
+
return `[ ${items.map((item) => serializeInlineValue(item, state)).join(" ")} ]`;
|
|
784
|
+
}
|
|
785
|
+
function serializeInlineExtendBlock(extend, state) {
|
|
786
|
+
return `( ${extend.order.map((name) => serializeInlineElement(extend.children[name], state)).join(" ")} )`;
|
|
787
|
+
}
|
|
788
|
+
function serializeInlineObject(value, state) {
|
|
789
|
+
const entries = Object.entries(value).map(([key, child]) => `${serializeKey2(key)} = ${serializeInlineValue(child, state)}`).join(" ");
|
|
790
|
+
return `{ ${entries} }`;
|
|
791
|
+
}
|
|
792
|
+
function serializeInlineArray(value, state) {
|
|
793
|
+
return `[${value.map((child) => serializeInlineValue(child, state)).join(" ")}]`;
|
|
794
|
+
}
|
|
795
|
+
function serializePrimitive2(value) {
|
|
796
|
+
if (value === null) return "null";
|
|
797
|
+
if (typeof value === "string") return `"${escapeString2(value)}"`;
|
|
798
|
+
if (typeof value === "boolean") return value ? "true" : "false";
|
|
799
|
+
return String(value);
|
|
800
|
+
}
|
|
801
|
+
function serializeId(id) {
|
|
802
|
+
const value = formatWord2(id);
|
|
803
|
+
return value ? ` #${value}` : "";
|
|
804
|
+
}
|
|
805
|
+
function formatWord2(word) {
|
|
806
|
+
return wordToString(word) ?? "";
|
|
807
|
+
}
|
|
808
|
+
function serializeKey2(key) {
|
|
809
|
+
if (/^[A-Za-z_][A-Za-z0-9_-]*$/.test(key)) return key;
|
|
810
|
+
return `"${escapeString2(key)}"`;
|
|
811
|
+
}
|
|
812
|
+
function escapeString2(value) {
|
|
813
|
+
return value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\t/g, "\\t").replace(/\r/g, "\\r");
|
|
814
|
+
}
|
|
815
|
+
function pad(state) {
|
|
816
|
+
return state.indent.repeat(state.depth);
|
|
817
|
+
}
|
|
818
|
+
function isDocument2(value) {
|
|
819
|
+
return value && Array.isArray(value.nodes);
|
|
820
|
+
}
|
|
821
|
+
function isElement2(value) {
|
|
822
|
+
return typeof value === "object" && value !== null && (value.kind === "DataElement" || value.kind === "TextElement");
|
|
823
|
+
}
|
|
824
|
+
function isComment2(value) {
|
|
825
|
+
return typeof value === "object" && value !== null && value.kind === "Comment";
|
|
826
|
+
}
|
|
827
|
+
function isPlainObject2(value) {
|
|
828
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
829
|
+
const kind = value.kind;
|
|
830
|
+
return kind !== "DataElement" && kind !== "TextElement" && kind !== "Comment" && kind !== "Word";
|
|
831
|
+
}
|
|
832
|
+
function makeUlid(now = Date.now()) {
|
|
833
|
+
if (now > lastUlidTime) {
|
|
834
|
+
lastUlidTime = now;
|
|
835
|
+
lastUlidRandom = nextRandom();
|
|
836
|
+
} else {
|
|
837
|
+
lastUlidRandom = incrementRandom(lastUlidRandom);
|
|
838
|
+
}
|
|
839
|
+
return encodeTime(lastUlidTime, 10) + encodeRandom(lastUlidRandom);
|
|
840
|
+
}
|
|
841
|
+
function encodeTime(time, length) {
|
|
842
|
+
let out = "";
|
|
843
|
+
for (let index = length - 1; index >= 0; index--) {
|
|
844
|
+
out = ULID_ENCODING.charAt(time % 32) + out;
|
|
845
|
+
time = Math.floor(time / 32);
|
|
846
|
+
}
|
|
847
|
+
return out;
|
|
848
|
+
}
|
|
849
|
+
function encodeRandom(values) {
|
|
850
|
+
return values.map((value) => ULID_ENCODING.charAt(value)).join("");
|
|
851
|
+
}
|
|
852
|
+
function nextRandom() {
|
|
853
|
+
return Array.from({ length: 16 }, () => Math.random() * 32 | 0);
|
|
854
|
+
}
|
|
855
|
+
function incrementRandom(values) {
|
|
856
|
+
const next = [...values];
|
|
857
|
+
for (let index = next.length - 1; index >= 0; index--) {
|
|
858
|
+
if (next[index] < 31) {
|
|
859
|
+
next[index] += 1;
|
|
860
|
+
return next;
|
|
861
|
+
}
|
|
862
|
+
next[index] = 0;
|
|
863
|
+
}
|
|
864
|
+
return next;
|
|
865
|
+
}
|
|
866
|
+
|
|
672
867
|
// src/path/index.ts
|
|
673
868
|
var XnlPathError = class extends Error {
|
|
674
869
|
};
|
|
@@ -764,7 +959,7 @@ function resolvePath(target, path, options = {}) {
|
|
|
764
959
|
current = current[item.value];
|
|
765
960
|
} else if (current && isTextElement(current)) {
|
|
766
961
|
current = current[item.value];
|
|
767
|
-
} else if (
|
|
962
|
+
} else if (isPlainObject3(current) || isDocument3(current)) {
|
|
768
963
|
current = current[item.value];
|
|
769
964
|
} else {
|
|
770
965
|
if (strict) throw new XnlPathError(`InstanceProperty '${item.value}' not allowed on current node`);
|
|
@@ -782,7 +977,7 @@ function resolvePath(target, path, options = {}) {
|
|
|
782
977
|
current = child;
|
|
783
978
|
continue;
|
|
784
979
|
}
|
|
785
|
-
if (!
|
|
980
|
+
if (!isPlainObject3(current)) {
|
|
786
981
|
if (strict) throw new XnlPathError("MapKey requires a map/object target");
|
|
787
982
|
return void 0;
|
|
788
983
|
}
|
|
@@ -880,7 +1075,7 @@ function deleteAtPath(target, path, options = {}) {
|
|
|
880
1075
|
const { parent, last } = getParentAndLast(target, parsed, { strict, createMissing: false });
|
|
881
1076
|
switch (last.type) {
|
|
882
1077
|
case "InstanceProperty":
|
|
883
|
-
if (
|
|
1078
|
+
if (isPlainObject3(parent) || isDataElement(parent) || isTextElement(parent) || isDocument3(parent)) {
|
|
884
1079
|
if (!(last.value in parent) && strict) {
|
|
885
1080
|
throw new XnlPathError(`InstanceProperty '${last.value}' not found`);
|
|
886
1081
|
}
|
|
@@ -964,8 +1159,8 @@ function getParentAndLast(target, path, opts) {
|
|
|
964
1159
|
current = current[item.value];
|
|
965
1160
|
} else if (current && isTextElement(current)) {
|
|
966
1161
|
current = current[item.value];
|
|
967
|
-
} else if (
|
|
968
|
-
if (current[item.value] === void 0 && createMissing &&
|
|
1162
|
+
} else if (isPlainObject3(current) || isDocument3(current)) {
|
|
1163
|
+
if (current[item.value] === void 0 && createMissing && isPlainObject3(current)) {
|
|
969
1164
|
current[item.value] = {};
|
|
970
1165
|
}
|
|
971
1166
|
current = current[item.value];
|
|
@@ -1077,7 +1272,7 @@ function readWhile(input, start, pred) {
|
|
|
1077
1272
|
return out;
|
|
1078
1273
|
}
|
|
1079
1274
|
function findByUniqueName(target, id) {
|
|
1080
|
-
const roots =
|
|
1275
|
+
const roots = isDocument3(target) ? target.nodes : [target];
|
|
1081
1276
|
for (const root of roots) {
|
|
1082
1277
|
const found = findInNode(root, id);
|
|
1083
1278
|
if (found) return found;
|
|
@@ -1086,7 +1281,7 @@ function findByUniqueName(target, id) {
|
|
|
1086
1281
|
}
|
|
1087
1282
|
function findByMetadataSelector(target, selector) {
|
|
1088
1283
|
const parsed = parseMetadataSelectorValue(selector);
|
|
1089
|
-
const roots =
|
|
1284
|
+
const roots = isDocument3(target) ? target.nodes : [target];
|
|
1090
1285
|
for (const root of roots) {
|
|
1091
1286
|
const found = findInNodeByMeta(root, parsed.key, parsed.value);
|
|
1092
1287
|
if (found) return found;
|
|
@@ -1095,7 +1290,7 @@ function findByMetadataSelector(target, selector) {
|
|
|
1095
1290
|
}
|
|
1096
1291
|
function findAllByMetadataSelector(target, selector) {
|
|
1097
1292
|
const parsed = parseMetadataSelectorValue(selector);
|
|
1098
|
-
const roots =
|
|
1293
|
+
const roots = isDocument3(target) ? target.nodes : [target];
|
|
1099
1294
|
const out = [];
|
|
1100
1295
|
for (const root of roots) {
|
|
1101
1296
|
collectInNodeByMeta(root, parsed.key, parsed.value, out);
|
|
@@ -1131,7 +1326,7 @@ function findInNodeByMeta(node, key, value) {
|
|
|
1131
1326
|
const found = findInNodeByMeta(child, key, value);
|
|
1132
1327
|
if (found) return found;
|
|
1133
1328
|
}
|
|
1134
|
-
} else if (
|
|
1329
|
+
} else if (isPlainObject3(node)) {
|
|
1135
1330
|
for (const k of Object.keys(node)) {
|
|
1136
1331
|
const found = findInNodeByMeta(node[k], key, value);
|
|
1137
1332
|
if (found) return found;
|
|
@@ -1165,7 +1360,7 @@ function collectInNodeByMeta(node, key, value, out) {
|
|
|
1165
1360
|
for (const child of node) {
|
|
1166
1361
|
collectInNodeByMeta(child, key, value, out);
|
|
1167
1362
|
}
|
|
1168
|
-
} else if (
|
|
1363
|
+
} else if (isPlainObject3(node)) {
|
|
1169
1364
|
for (const k of Object.keys(node)) {
|
|
1170
1365
|
collectInNodeByMeta(node[k], key, value, out);
|
|
1171
1366
|
}
|
|
@@ -1212,7 +1407,7 @@ function findInNode(node, id) {
|
|
|
1212
1407
|
const found = findInNode(child, id);
|
|
1213
1408
|
if (found) return found;
|
|
1214
1409
|
}
|
|
1215
|
-
} else if (
|
|
1410
|
+
} else if (isPlainObject3(node)) {
|
|
1216
1411
|
for (const key of Object.keys(node)) {
|
|
1217
1412
|
const found = findInNode(node[key], id);
|
|
1218
1413
|
if (found) return found;
|
|
@@ -1232,14 +1427,14 @@ function isTextElement(node) {
|
|
|
1232
1427
|
function isExtendBody(value) {
|
|
1233
1428
|
return value && typeof value === "object" && Array.isArray(value.order) && value.children;
|
|
1234
1429
|
}
|
|
1235
|
-
function
|
|
1430
|
+
function isDocument3(value) {
|
|
1236
1431
|
return value && typeof value === "object" && Array.isArray(value.nodes);
|
|
1237
1432
|
}
|
|
1238
|
-
function
|
|
1433
|
+
function isPlainObject3(value) {
|
|
1239
1434
|
return value !== null && typeof value === "object" && !Array.isArray(value) && !isElementNode(value) && !isExtendBody(value) && !isWord(value);
|
|
1240
1435
|
}
|
|
1241
1436
|
function ensureMap(value, strict) {
|
|
1242
|
-
if (!
|
|
1437
|
+
if (!isPlainObject3(value)) {
|
|
1243
1438
|
if (strict) throw new XnlPathError("Target is not a map/object");
|
|
1244
1439
|
}
|
|
1245
1440
|
}
|
|
@@ -1278,13 +1473,13 @@ function diffNodes(oldNode, newNode, basePath = [], opts = {}) {
|
|
|
1278
1473
|
if (!sameKind(oldNode, newNode)) {
|
|
1279
1474
|
throw new XnlPathError("Root kinds must match to diff");
|
|
1280
1475
|
}
|
|
1281
|
-
if (isValueLiteral(oldNode) ||
|
|
1476
|
+
if (isValueLiteral(oldNode) || isComment3(oldNode)) {
|
|
1282
1477
|
return oldNode === newNode ? [] : [{ type: "OBJECT_UPDATE", path: pathItems, valueAfter: newNode }];
|
|
1283
1478
|
}
|
|
1284
1479
|
if (Array.isArray(oldNode) && Array.isArray(newNode)) {
|
|
1285
1480
|
return diffArray(oldNode, newNode, pathItems, void 0, void 0, opts);
|
|
1286
1481
|
}
|
|
1287
|
-
if (
|
|
1482
|
+
if (isPlainObject4(oldNode) && isPlainObject4(newNode)) {
|
|
1288
1483
|
return diffMap(oldNode, newNode, pathItems, void 0, void 0, opts);
|
|
1289
1484
|
}
|
|
1290
1485
|
if (isTextElement2(oldNode) && isTextElement2(newNode)) {
|
|
@@ -1576,7 +1771,7 @@ function sameKind(a, b) {
|
|
|
1576
1771
|
if (isDataElement2(a) && isDataElement2(b)) return true;
|
|
1577
1772
|
if (isTextElement2(a) && isTextElement2(b)) return true;
|
|
1578
1773
|
if (Array.isArray(a) && Array.isArray(b)) return true;
|
|
1579
|
-
if (
|
|
1774
|
+
if (isPlainObject4(a) && isPlainObject4(b)) return true;
|
|
1580
1775
|
if (isValueLiteral(a) && isValueLiteral(b)) return true;
|
|
1581
1776
|
return typeof a === typeof b;
|
|
1582
1777
|
}
|
|
@@ -1590,7 +1785,7 @@ function isEqual(a, b) {
|
|
|
1590
1785
|
if (a.length !== b.length) return false;
|
|
1591
1786
|
return a.every((item, idx) => isEqual(item, b[idx]));
|
|
1592
1787
|
}
|
|
1593
|
-
if (
|
|
1788
|
+
if (isPlainObject4(a) && isPlainObject4(b)) {
|
|
1594
1789
|
const keysA = Object.keys(a);
|
|
1595
1790
|
const keysB = Object.keys(b);
|
|
1596
1791
|
if (keysA.length !== keysB.length) return false;
|
|
@@ -1598,7 +1793,7 @@ function isEqual(a, b) {
|
|
|
1598
1793
|
}
|
|
1599
1794
|
return false;
|
|
1600
1795
|
}
|
|
1601
|
-
function
|
|
1796
|
+
function isPlainObject4(value) {
|
|
1602
1797
|
return value !== null && typeof value === "object" && !Array.isArray(value) && !isDataElement2(value) && !isTextElement2(value) && !isWord(value);
|
|
1603
1798
|
}
|
|
1604
1799
|
function isDataElement2(node) {
|
|
@@ -1610,7 +1805,7 @@ function isTextElement2(node) {
|
|
|
1610
1805
|
function isValueLiteral(node) {
|
|
1611
1806
|
return typeof node === "string" || typeof node === "number" || typeof node === "boolean" || node === null || isWord(node);
|
|
1612
1807
|
}
|
|
1613
|
-
function
|
|
1808
|
+
function isComment3(node) {
|
|
1614
1809
|
return node && node.kind === "Comment";
|
|
1615
1810
|
}
|
|
1616
1811
|
var ip = (value) => ({ type: "InstanceProperty", value });
|
|
@@ -1945,7 +2140,7 @@ function cloneNode(node) {
|
|
|
1945
2140
|
if (isWord(node)) {
|
|
1946
2141
|
return cloneWord(node);
|
|
1947
2142
|
}
|
|
1948
|
-
if (
|
|
2143
|
+
if (isPlainObject5(node)) {
|
|
1949
2144
|
const out = {};
|
|
1950
2145
|
for (const key of Object.keys(node)) {
|
|
1951
2146
|
out[key] = cloneNode(node[key]);
|
|
@@ -1971,7 +2166,7 @@ function mergeMaps(ctx, base, override, scope) {
|
|
|
1971
2166
|
continue;
|
|
1972
2167
|
}
|
|
1973
2168
|
const resolvedValue = resolveValue(ctx, value, scope);
|
|
1974
|
-
if (
|
|
2169
|
+
if (isPlainObject5(resolvedValue) && isPlainObject5(result[key])) {
|
|
1975
2170
|
result[key] = mergeMaps(ctx, result[key], resolvedValue, scope);
|
|
1976
2171
|
} else if (Array.isArray(resolvedValue) && Array.isArray(result[key])) {
|
|
1977
2172
|
result[key] = mergeArray(ctx, result[key], resolvedValue, scope);
|
|
@@ -1992,7 +2187,7 @@ function mergeArray(ctx, baseArr, overrideArr, scope) {
|
|
|
1992
2187
|
const resolved = resolveValue(ctx, value, scope);
|
|
1993
2188
|
if (i < result.length) {
|
|
1994
2189
|
const baseVal = result[i];
|
|
1995
|
-
if (
|
|
2190
|
+
if (isPlainObject5(baseVal) && isPlainObject5(resolved)) {
|
|
1996
2191
|
result[i] = mergeMaps(ctx, baseVal, resolved, scope);
|
|
1997
2192
|
} else if (Array.isArray(baseVal) && Array.isArray(resolved)) {
|
|
1998
2193
|
result[i] = mergeArray(ctx, baseVal, resolved, scope);
|
|
@@ -2047,7 +2242,7 @@ function isDataElement3(node) {
|
|
|
2047
2242
|
function isTextElement3(node) {
|
|
2048
2243
|
return node && node.kind === "TextElement";
|
|
2049
2244
|
}
|
|
2050
|
-
function
|
|
2245
|
+
function isPlainObject5(value) {
|
|
2051
2246
|
return value !== null && typeof value === "object" && !Array.isArray(value) && !isDataElement3(value) && !isWord(value);
|
|
2052
2247
|
}
|
|
2053
2248
|
function resolveValue(ctx, value, scope) {
|
|
@@ -2064,7 +2259,7 @@ function resolveValue(ctx, value, scope) {
|
|
|
2064
2259
|
if (Array.isArray(value)) {
|
|
2065
2260
|
return value.map((v) => resolveValue(ctx, v, scope));
|
|
2066
2261
|
}
|
|
2067
|
-
if (
|
|
2262
|
+
if (isPlainObject5(value)) {
|
|
2068
2263
|
const out = {};
|
|
2069
2264
|
for (const key of Object.keys(value)) {
|
|
2070
2265
|
out[key] = resolveValue(ctx, value[key], scope);
|
|
@@ -2136,6 +2331,7 @@ var XNL = {
|
|
|
2136
2331
|
parseSingle: parseXnlSingleNode,
|
|
2137
2332
|
parseUnique: parseUniqueChildren,
|
|
2138
2333
|
stringify,
|
|
2334
|
+
stringifyLineBlock: stringify2,
|
|
2139
2335
|
path: {
|
|
2140
2336
|
parse: parsePath,
|
|
2141
2337
|
resolve: resolvePath,
|
|
@@ -2171,6 +2367,7 @@ exports.parseXnl = parseXnl;
|
|
|
2171
2367
|
exports.parseXnlSingleNode = parseXnlSingleNode;
|
|
2172
2368
|
exports.resolvePath = resolvePath;
|
|
2173
2369
|
exports.setPathValue = setPathValue;
|
|
2370
|
+
exports.stringifyLineBlock = stringify2;
|
|
2174
2371
|
exports.wordToString = wordToString;
|
|
2175
2372
|
//# sourceMappingURL=index.cjs.map
|
|
2176
2373
|
//# sourceMappingURL=index.cjs.map
|