@ac-kit/model-markup 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/LICENSE +28 -0
  3. package/README.md +199 -2
  4. package/dist/_text-run.d.ts +26 -0
  5. package/dist/_text-run.d.ts.map +1 -0
  6. package/dist/_text-run.js +56 -0
  7. package/dist/_text-run.js.map +1 -0
  8. package/dist/index-markup-tree.d.ts +37 -0
  9. package/dist/index-markup-tree.d.ts.map +1 -0
  10. package/dist/index-markup-tree.js +200 -0
  11. package/dist/index-markup-tree.js.map +1 -0
  12. package/dist/index.d.ts +7 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +7 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/markup-namespace-scope.d.ts +24 -0
  17. package/dist/markup-namespace-scope.d.ts.map +1 -0
  18. package/dist/markup-namespace-scope.js +63 -0
  19. package/dist/markup-namespace-scope.js.map +1 -0
  20. package/dist/markup-navigation.d.ts +38 -0
  21. package/dist/markup-navigation.d.ts.map +1 -0
  22. package/dist/markup-navigation.js +55 -0
  23. package/dist/markup-navigation.js.map +1 -0
  24. package/dist/markup-tree-shape.d.ts +186 -0
  25. package/dist/markup-tree-shape.d.ts.map +1 -0
  26. package/dist/markup-tree-shape.js +2 -0
  27. package/dist/markup-tree-shape.js.map +1 -0
  28. package/dist/markup-values.d.ts +90 -0
  29. package/dist/markup-values.d.ts.map +1 -0
  30. package/dist/markup-values.js +169 -0
  31. package/dist/markup-values.js.map +1 -0
  32. package/dist/namespaces.d.ts +16 -0
  33. package/dist/namespaces.d.ts.map +1 -0
  34. package/dist/namespaces.js +16 -0
  35. package/dist/namespaces.js.map +1 -0
  36. package/dist/parse5/index.d.ts +99 -0
  37. package/dist/parse5/index.d.ts.map +1 -0
  38. package/dist/parse5/index.js +84 -0
  39. package/dist/parse5/index.js.map +1 -0
  40. package/dist/testing/index.d.ts +2 -0
  41. package/dist/testing/index.d.ts.map +1 -0
  42. package/dist/testing/index.js +2 -0
  43. package/dist/testing/index.js.map +1 -0
  44. package/dist/testing/record-tree.d.ts +102 -0
  45. package/dist/testing/record-tree.d.ts.map +1 -0
  46. package/dist/testing/record-tree.js +212 -0
  47. package/dist/testing/record-tree.js.map +1 -0
  48. package/package.json +68 -3
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export * from "./index-markup-tree.js";
2
+ export * from "./markup-namespace-scope.js";
3
+ export * from "./markup-navigation.js";
4
+ export * from "./markup-tree-shape.js";
5
+ export * from "./markup-values.js";
6
+ export * from "./namespaces.js";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,24 @@
1
+ import type { WorkBudget } from "@ac-kit/core";
2
+ import type { MarkupNamespaceBinding, MarkupTreeShape } from "./markup-tree-shape.js";
3
+ /**
4
+ * The namespace bindings in scope at `element`, derived from the namespace
5
+ * declarations among its own and its element ancestors' attributes — what a
6
+ * shape whose tree keeps declarations as attributes, such as an HTML parser's
7
+ * or the DOM, answers as `namespacesInScopeOf`.
8
+ *
9
+ * A declaration is an attribute in {@link XMLNS_NAMESPACE}: `xmlns` binds the
10
+ * default namespace (prefix `null`), `xmlns:p` binds `p`. The nearest
11
+ * declaration of a prefix shadows those above it, and one with an empty value
12
+ * undeclares it, so the prefix is then out of scope. The `xml` prefix is always
13
+ * bound to {@link XML_NAMESPACE}, whatever is declared, and `xmlns` is never a
14
+ * binding. Bindings come nearest element first, in attribute order, the `xml`
15
+ * binding last; each prefix once.
16
+ *
17
+ * The walk stops at the first ancestor that is not an element. O(depth +
18
+ * attributes on the ancestor chain), allocating the result; nothing is cached,
19
+ * so the tree is read as it is at the call. The optional `budget` is charged
20
+ * for each element and its attributes before scanning them, and for the
21
+ * implicit `xml` binding. Whatever `spend` throws propagates unchanged.
22
+ */
23
+ export declare function markupNamespacesFromAttributes<TNode, TAttribute>(shape: MarkupTreeShape<TNode, TAttribute>, element: TNode, budget?: WorkBudget): MarkupNamespaceBinding[];
24
+ //# sourceMappingURL=markup-namespace-scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markup-namespace-scope.d.ts","sourceRoot":"","sources":["../src/markup-namespace-scope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,OAAO,KAAK,EACX,sBAAsB,EACtB,eAAe,EACf,MAAM,wBAAwB,CAAC;AAGhC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,UAAU,EAC/D,KAAK,EAAE,eAAe,CAAC,KAAK,EAAE,UAAU,CAAC,EACzC,OAAO,EAAE,KAAK,EACd,MAAM,CAAC,EAAE,UAAU,GACjB,sBAAsB,EAAE,CA8C1B"}
@@ -0,0 +1,63 @@
1
+ import { XML_NAMESPACE, XMLNS_NAMESPACE } from "./namespaces.js";
2
+ /**
3
+ * The namespace bindings in scope at `element`, derived from the namespace
4
+ * declarations among its own and its element ancestors' attributes — what a
5
+ * shape whose tree keeps declarations as attributes, such as an HTML parser's
6
+ * or the DOM, answers as `namespacesInScopeOf`.
7
+ *
8
+ * A declaration is an attribute in {@link XMLNS_NAMESPACE}: `xmlns` binds the
9
+ * default namespace (prefix `null`), `xmlns:p` binds `p`. The nearest
10
+ * declaration of a prefix shadows those above it, and one with an empty value
11
+ * undeclares it, so the prefix is then out of scope. The `xml` prefix is always
12
+ * bound to {@link XML_NAMESPACE}, whatever is declared, and `xmlns` is never a
13
+ * binding. Bindings come nearest element first, in attribute order, the `xml`
14
+ * binding last; each prefix once.
15
+ *
16
+ * The walk stops at the first ancestor that is not an element. O(depth +
17
+ * attributes on the ancestor chain), allocating the result; nothing is cached,
18
+ * so the tree is read as it is at the call. The optional `budget` is charged
19
+ * for each element and its attributes before scanning them, and for the
20
+ * implicit `xml` binding. Whatever `spend` throws propagates unchanged.
21
+ */
22
+ export function markupNamespacesFromAttributes(shape, element, budget) {
23
+ const { kindOf, parentOf, attributesOf, attributeLocalNameOf, attributeNamespaceOf, attributePrefixOf, attributeValueOf, } = shape;
24
+ const bindings = [];
25
+ const decided = new Set(["xml", "xmlns"]);
26
+ let current = element;
27
+ while (current !== null && kindOf(current) === "element") {
28
+ budget?.spend(1);
29
+ const attributes = attributesOf(current);
30
+ budget?.spend(attributes.length);
31
+ for (let index = 0; index < attributes.length; index++) {
32
+ const attribute = attributes[index];
33
+ if (attributeNamespaceOf(attribute) !== XMLNS_NAMESPACE) {
34
+ continue;
35
+ }
36
+ const localName = attributeLocalNameOf(attribute);
37
+ const declaredPrefix = attributePrefixOf(attribute);
38
+ let prefix;
39
+ if (declaredPrefix === null && localName === "xmlns") {
40
+ prefix = null;
41
+ }
42
+ else if (declaredPrefix === "xmlns") {
43
+ prefix = localName;
44
+ }
45
+ else {
46
+ continue;
47
+ }
48
+ if (decided.has(prefix)) {
49
+ continue;
50
+ }
51
+ decided.add(prefix);
52
+ const uri = attributeValueOf(attribute);
53
+ if (uri !== "") {
54
+ bindings.push({ prefix, uri });
55
+ }
56
+ }
57
+ current = parentOf(current);
58
+ }
59
+ budget?.spend(1);
60
+ bindings.push({ prefix: "xml", uri: XML_NAMESPACE });
61
+ return bindings;
62
+ }
63
+ //# sourceMappingURL=markup-namespace-scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markup-namespace-scope.js","sourceRoot":"","sources":["../src/markup-namespace-scope.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEjE;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YACV,CAAC;YACD,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;gBACzB,SAAS;YACV,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACpB,MAAM,GAAG,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC;YACxC,IAAI,GAAG,KAAK,EAAE,EAAE,CAAC;gBAChB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;YAChC,CAAC;QACF,CAAC;QACD,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IACD,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IACjB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,EAAE,CAAC,CAAC;IACrD,OAAO,QAAQ,CAAC;AACjB,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { WorkBudget } from "@ac-kit/core";
2
+ import type { MarkupTreeShape } from "./markup-tree-shape.js";
3
+ /**
4
+ * The position of `node` among its parent's children, `0` for a node without a
5
+ * parent.
6
+ *
7
+ * Answers through the shape's `siblingIndexOf` in O(1) when it has one, and
8
+ * otherwise scans the parent's children in O(siblings) — so an engine asking
9
+ * this of every child of a large element wants an indexed shape ({@link
10
+ * indexMarkupTree}).
11
+ *
12
+ * @throws {TypeError} When the shape has no `siblingIndexOf` and the parent its
13
+ * `parentOf` names does not hold `node` among its `childrenOf`: the shape
14
+ * contradicts itself.
15
+ */
16
+ export declare function markupSiblingIndex<TNode, TAttribute>(shape: MarkupTreeShape<TNode, TAttribute>, node: TNode): number;
17
+ /**
18
+ * The node standing for the run of text `node` belongs to.
19
+ *
20
+ * A **text run** is a maximal sequence of adjacent siblings whose kind is
21
+ * `"text"` — a parser's split text, or text and CDATA side by side. A comment,
22
+ * a processing instruction or an element ends a run; an empty text node does
23
+ * not, and belongs to the run like any other. The run is represented by its
24
+ * first node, which is what this returns for any member of the run. A text node
25
+ * without a parent is a run of one, and a node of any other kind stands for
26
+ * itself.
27
+ *
28
+ * O(1) for a node that is not text; otherwise O(siblings) without
29
+ * `siblingIndexOf`, O(run) with it.
30
+ *
31
+ * @param budget Charged before the work it pays for, as `markupStringValue`
32
+ * charges: one unit for the node, the full sibling count when locating a text
33
+ * node without `siblingIndexOf`, and one unit per sibling inspected for the
34
+ * start of the run. Whatever `spend` throws propagates unchanged.
35
+ * @throws {TypeError} As {@link markupSiblingIndex} does.
36
+ */
37
+ export declare function markupTextRunStart<TNode, TAttribute>(shape: MarkupTreeShape<TNode, TAttribute>, node: TNode, budget?: WorkBudget): TNode;
38
+ //# sourceMappingURL=markup-navigation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markup-navigation.d.ts","sourceRoot":"","sources":["../src/markup-navigation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,UAAU,EACnD,KAAK,EAAE,eAAe,CAAC,KAAK,EAAE,UAAU,CAAC,EACzC,IAAI,EAAE,KAAK,GACT,MAAM,CAMR;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,UAAU,EACnD,KAAK,EAAE,eAAe,CAAC,KAAK,EAAE,UAAU,CAAC,EACzC,IAAI,EAAE,KAAK,EACX,MAAM,CAAC,EAAE,UAAU,GACjB,KAAK,CAYP"}
@@ -0,0 +1,55 @@
1
+ import { siblingPosition, textRunStartIndex } from "./_text-run.js";
2
+ /**
3
+ * The position of `node` among its parent's children, `0` for a node without a
4
+ * parent.
5
+ *
6
+ * Answers through the shape's `siblingIndexOf` in O(1) when it has one, and
7
+ * otherwise scans the parent's children in O(siblings) — so an engine asking
8
+ * this of every child of a large element wants an indexed shape ({@link
9
+ * indexMarkupTree}).
10
+ *
11
+ * @throws {TypeError} When the shape has no `siblingIndexOf` and the parent its
12
+ * `parentOf` names does not hold `node` among its `childrenOf`: the shape
13
+ * contradicts itself.
14
+ */
15
+ export function markupSiblingIndex(shape, node) {
16
+ const { siblingIndexOf } = shape;
17
+ if (siblingIndexOf !== undefined) {
18
+ return siblingIndexOf(node);
19
+ }
20
+ return siblingPosition(shape, node, undefined)?.index ?? 0;
21
+ }
22
+ /**
23
+ * The node standing for the run of text `node` belongs to.
24
+ *
25
+ * A **text run** is a maximal sequence of adjacent siblings whose kind is
26
+ * `"text"` — a parser's split text, or text and CDATA side by side. A comment,
27
+ * a processing instruction or an element ends a run; an empty text node does
28
+ * not, and belongs to the run like any other. The run is represented by its
29
+ * first node, which is what this returns for any member of the run. A text node
30
+ * without a parent is a run of one, and a node of any other kind stands for
31
+ * itself.
32
+ *
33
+ * O(1) for a node that is not text; otherwise O(siblings) without
34
+ * `siblingIndexOf`, O(run) with it.
35
+ *
36
+ * @param budget Charged before the work it pays for, as `markupStringValue`
37
+ * charges: one unit for the node, the full sibling count when locating a text
38
+ * node without `siblingIndexOf`, and one unit per sibling inspected for the
39
+ * start of the run. Whatever `spend` throws propagates unchanged.
40
+ * @throws {TypeError} As {@link markupSiblingIndex} does.
41
+ */
42
+ export function markupTextRunStart(shape, node, budget) {
43
+ budget?.spend(1);
44
+ const { kindOf } = shape;
45
+ if (kindOf(node) !== "text") {
46
+ return node;
47
+ }
48
+ const position = siblingPosition(shape, node, budget);
49
+ if (position === null) {
50
+ return node;
51
+ }
52
+ const { siblings, index } = position;
53
+ return siblings[textRunStartIndex(kindOf, siblings, index, budget)];
54
+ }
55
+ //# sourceMappingURL=markup-navigation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markup-navigation.js","sourceRoot":"","sources":["../src/markup-navigation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGpE;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,kBAAkB,CACjC,KAAyC,EACzC,IAAW;IAEX,MAAM,EAAE,cAAc,EAAE,GAAG,KAAK,CAAC;IACjC,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;QAClC,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IACD,OAAO,eAAe,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC;AAC5D,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,kBAAkB,CACjC,KAAyC,EACzC,IAAW,EACX,MAAmB;IAEnB,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IACzB,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,MAAM,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IACb,CAAC;IACD,MAAM,QAAQ,GAAG,eAAe,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACtD,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC;IACb,CAAC;IACD,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAC;IACrC,OAAO,QAAQ,CAAC,iBAAiB,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,CAAC,CAAE,CAAC;AACtE,CAAC"}
@@ -0,0 +1,186 @@
1
+ import type { Callable, WorkBudget } from "@ac-kit/core";
2
+ /**
3
+ * What a node is to an engine reading the tree.
4
+ *
5
+ * A CDATA section is `"text"`: no selector or path language tells the two
6
+ * apart. A node an engine must not see — a template's content, a node a parser
7
+ * keeps for its own bookkeeping — is never returned by `childrenOf` and so has
8
+ * no kind to report.
9
+ */
10
+ export type MarkupNodeKind = "document" | "fragment" | "element" | "text" | "comment" | "processingInstruction" | "doctype";
11
+ /**
12
+ * How the document a node belongs to compares names and values.
13
+ *
14
+ * - `"xml"` compares every name and value exactly.
15
+ * - `"html"` follows the HTML Standard's case rules: an HTML element's name and
16
+ * its attribute names compare ASCII case-insensitively.
17
+ * - `"html-quirks"` is `"html"` with `class` and `id` also compared ASCII
18
+ * case-insensitively, as a quirks-mode document does. Limited-quirks mode
19
+ * changes nothing a selector reads, so it is `"html"`.
20
+ */
21
+ export type MarkupDocumentMode = "xml" | "html" | "html-quirks";
22
+ /**
23
+ * A namespace declaration in scope; `prefix` is `null` for the default
24
+ * namespace.
25
+ */
26
+ export type MarkupNamespaceBinding = {
27
+ readonly prefix: string | null;
28
+ readonly uri: string;
29
+ };
30
+ /**
31
+ * How a markup tree is read: a record of functions, so an XML tree, an HTML
32
+ * parser's tree or a DOM are all read without converting to a node type of this
33
+ * package.
34
+ *
35
+ * `TNode` is every node kind and `TAttribute` an attribute. Nodes and
36
+ * attributes are compared by identity (`===`), so a shape must hand back the
37
+ * same value for the same node every time.
38
+ *
39
+ * **Every operation is O(1) unless its documentation says otherwise**, and the
40
+ * complexity statements of the engines reading a shape assume it. The members
41
+ * are plain functions: an engine calls them unbound, never through the shape.
42
+ *
43
+ * Element accessors (`localNameOf`, `namespaceOf`, `prefixOf`, `attributesOf`)
44
+ * are only called on nodes whose `kindOf` is `"element"`.
45
+ *
46
+ * **Namespaces.** `null` is "no namespace" everywhere, as in the DOM; an
47
+ * empty-string namespace never appears. Namespace declarations (`xmlns`,
48
+ * `xmlns:p`) are attributes in {@link XMLNS_NAMESPACE}: `xmlns` has local name
49
+ * `"xmlns"` and prefix `null`, `xmlns:p` has local name `"p"` and prefix
50
+ * `"xmlns"`.
51
+ *
52
+ * **Text.** Adjacent text siblings are kept as the tree has them. Engines that
53
+ * need one node per run of text, such as XPath, use {@link markupTextRunStart}
54
+ * and {@link markupStringValue}, which define the run once for all of them.
55
+ */
56
+ export type MarkupTreeShape<TNode, TAttribute> = {
57
+ readonly kindOf: (node: TNode) => MarkupNodeKind;
58
+ /** `null` for the root of the tree, whatever its kind. */
59
+ readonly parentOf: (node: TNode) => TNode | null;
60
+ /** Children in document order; empty for a node that cannot have any. */
61
+ readonly childrenOf: (node: TNode) => ArrayLike<TNode>;
62
+ /**
63
+ * The position of `node` in `childrenOf(parentOf(node))`, `0` for a node
64
+ * without a parent.
65
+ *
66
+ * Optional because few trees store it; {@link indexMarkupTree} fills it in and
67
+ * {@link markupSiblingIndex} falls back to a scan of the siblings when it is
68
+ * absent.
69
+ */
70
+ readonly siblingIndexOf?: (node: TNode) => number;
71
+ /** May walk to the root: O(depth). */
72
+ readonly documentModeOf: (node: TNode) => MarkupDocumentMode;
73
+ /**
74
+ * Trusted adapter assertion: `documentModeOf(node)` is O(1) and equals
75
+ * `documentModeOf(root)` for every node, where `root` is reached through
76
+ * `parentOf`. Omit for root-only lookups or when either guarantee is absent.
77
+ */
78
+ readonly documentModeIsUniform?: true;
79
+ /** The local name, without any prefix, exactly as the tree spells it. */
80
+ readonly localNameOf: (element: TNode) => string;
81
+ /**
82
+ * The namespace URI, or `null` for none. A tolerant adapter may also return
83
+ * `null` for an unbound prefix. A no-namespace name test checks both this
84
+ * accessor and `prefixOf` for `null`.
85
+ */
86
+ readonly namespaceOf: (element: TNode) => string | null;
87
+ /** The prefix as written, `null` for none. */
88
+ readonly prefixOf: (element: TNode) => string | null;
89
+ /** In source order. */
90
+ readonly attributesOf: (element: TNode) => ArrayLike<TAttribute>;
91
+ readonly attributeLocalNameOf: (attribute: TAttribute) => string;
92
+ /**
93
+ * The namespace URI, or `null` for none. A tolerant adapter may also return
94
+ * `null` for an unbound prefix. A no-namespace name test checks both this
95
+ * accessor and `attributePrefixOf` for `null`.
96
+ */
97
+ readonly attributeNamespaceOf: (attribute: TAttribute) => string | null;
98
+ /** The prefix as written, `null` for none. */
99
+ readonly attributePrefixOf: (attribute: TAttribute) => string | null;
100
+ readonly attributeValueOf: (attribute: TAttribute) => string;
101
+ /**
102
+ * A text or comment node's data, a processing instruction's data; `""` for
103
+ * every other kind.
104
+ */
105
+ readonly dataOf: (node: TNode) => string;
106
+ /** A processing instruction's target; `""` for every other kind. */
107
+ readonly targetOf: (node: TNode) => string;
108
+ /**
109
+ * Every namespace binding in scope at `element`, the nearest declaration of a
110
+ * prefix winning, each prefix once, `xml` included. May walk the ancestors:
111
+ * O(depth + attributes on the ancestor chain), as
112
+ * {@link markupNamespacesFromAttributes} does for a tree that keeps
113
+ * declarations as attributes.
114
+ *
115
+ * When neither scope hook is present, only the implicit `xml` binding to
116
+ * {@link XML_NAMESPACE} is in scope, as in a tree without declarations.
117
+ */
118
+ readonly namespacesInScopeOf?: (element: TNode) => Iterable<MarkupNamespaceBinding>;
119
+ /**
120
+ * Budgeted counterpart to `namespacesInScopeOf`, returning the same bindings
121
+ * in the same order. Charges `budget` for enumeration work done during the
122
+ * call or iteration and propagates budget exhaustion unchanged. Prefer it
123
+ * when present for queries on untrusted trees; fall back to the unary hook
124
+ * for adapters that do not support budgeted enumeration.
125
+ */
126
+ readonly namespacesInScopeWithin?: (element: TNode, budget: WorkBudget) => Iterable<MarkupNamespaceBinding>;
127
+ /**
128
+ * Negative, zero or positive as `a` precedes, is, or follows `b` in document
129
+ * order. When absent, an engine derives the order itself.
130
+ */
131
+ readonly compareDocumentOrder?: (a: TNode, b: TNode) => number;
132
+ /**
133
+ * The first element in document order, among `root` and its descendants,
134
+ * whose `id` attribute (no namespace) equals `id` exactly; `null` when there
135
+ * is none or `id` is empty. May be O(log k) for `k` elements sharing the id,
136
+ * as {@link indexMarkupTree}'s is. When absent, an engine scans.
137
+ */
138
+ readonly elementByIdOf?: (root: TNode, id: string) => TNode | null;
139
+ /**
140
+ * Where `element` stands among its parent's element children — the neighbours
141
+ * and ranks selector engines read for `+`, `~`, `:nth-child()` and
142
+ * `:nth-of-type()`. Amortised O(1); the same record for the same element
143
+ * every time. {@link indexMarkupTree} fills it in, building each parent's
144
+ * records on the first question about one of its children. When absent, an
145
+ * engine scans the siblings.
146
+ */
147
+ readonly elementSiblingsOf?: (element: TNode) => MarkupElementSiblings<TNode>;
148
+ /**
149
+ * Budget-aware counterpart to `elementSiblingsOf`. Prefer it when present: it
150
+ * charges any cold preparation to `budget` and propagates exhaustion
151
+ * unchanged. Warm lookups are O(1) and require no preparation charge.
152
+ */
153
+ readonly elementSiblingsWithin?: Callable<[
154
+ element: TNode,
155
+ budget: WorkBudget
156
+ ], MarkupElementSiblings<TNode>>;
157
+ };
158
+ /**
159
+ * An element's place among its parent's element children; text, comments and
160
+ * other nodes are not counted. An element without a parent is alone: index `0`
161
+ * of `1`, no neighbours.
162
+ */
163
+ export type MarkupElementSiblings<TNode> = {
164
+ /** The nearest element sibling before it, `null` for none. */
165
+ readonly previous: TNode | null;
166
+ /** The nearest element sibling after it, `null` for none. */
167
+ readonly next: TNode | null;
168
+ /** 0-based position among the element siblings, itself included. */
169
+ readonly index: number;
170
+ /** How many element siblings there are, itself included. */
171
+ readonly count: number;
172
+ /**
173
+ * 0-based position among the element siblings of the same type: the same
174
+ * namespace and the same local name.
175
+ */
176
+ readonly typeIndex: number;
177
+ /** How many element siblings share its type, itself included. */
178
+ readonly typeCount: number;
179
+ };
180
+ /**
181
+ * A shape that can only go downwards — what {@link indexMarkupTree} needs, since
182
+ * it derives the upward and positional members itself. Every
183
+ * {@link MarkupTreeShape} is one.
184
+ */
185
+ export type MarkupTreeDownShape<TNode, TAttribute> = Omit<MarkupTreeShape<TNode, TAttribute>, "parentOf" | "siblingIndexOf" | "compareDocumentOrder" | "elementByIdOf" | "elementSiblingsOf" | "elementSiblingsWithin">;
186
+ //# sourceMappingURL=markup-tree-shape.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markup-tree-shape.d.ts","sourceRoot":"","sources":["../src/markup-tree-shape.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAEzD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EnE;;;;;;;OAOG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,KAAK,qBAAqB,CAAC,KAAK,CAAC,CAAC;IAE9E;;;;OAIG;IACH,QAAQ,CAAC,qBAAqB,CAAC,EAAE,QAAQ,CACxC;QAAC,OAAO,EAAE,KAAK;QAAE,MAAM,EAAE,UAAU;KAAC,EACpC,qBAAqB,CAAC,KAAK,CAAC,CAC5B,CAAC;CACF,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,CAAC,KAAK,IAAI;IAC1C,8DAA8D;IAC9D,QAAQ,CAAC,QAAQ,EAAE,KAAK,GAAG,IAAI,CAAC;IAChC,6DAA6D;IAC7D,QAAQ,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC;IAC5B,oEAAoE;IACpE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,4DAA4D;IAC5D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,iEAAiE;IACjE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,CAAC,KAAK,EAAE,UAAU,IAAI,IAAI,CACxD,eAAe,CAAC,KAAK,EAAE,UAAU,CAAC,EAChC,UAAU,GACV,gBAAgB,GAChB,sBAAsB,GACtB,eAAe,GACf,mBAAmB,GACnB,uBAAuB,CACzB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=markup-tree-shape.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markup-tree-shape.js","sourceRoot":"","sources":["../src/markup-tree-shape.ts"],"names":[],"mappings":""}
@@ -0,0 +1,90 @@
1
+ import { type WorkBudget } from "@ac-kit/core";
2
+ import type { MarkupTreeDownShape, MarkupTreeShape } from "./markup-tree-shape.js";
3
+ /**
4
+ * The default and hard ceiling for {@link markupStringValue}: core's
5
+ * `MAX_PORTABLE_STRING_LENGTH`, 2²⁸ − 16 UTF-16 code units.
6
+ */
7
+ export declare const DEFAULT_MARKUP_STRING_VALUE_MAX_LENGTH: 268435440;
8
+ /**
9
+ * How much work {@link markupStringValue} may do, and how long a result it may
10
+ * build.
11
+ */
12
+ export type MarkupStringValueOptions = {
13
+ /**
14
+ * Charged before the work it pays for: one unit per node visited, plus the
15
+ * number of UTF-16 code units appended, one unit per sibling inspected to
16
+ * find either text-run boundary, and the full sibling count when locating a
17
+ * text node without `siblingIndexOf`. Whatever `spend` throws propagates
18
+ * unchanged.
19
+ */
20
+ readonly budget?: WorkBudget;
21
+ /**
22
+ * The longest result accepted, in UTF-16 code units; a non-negative safe
23
+ * integer. Defaults to and is capped at
24
+ * {@link DEFAULT_MARKUP_STRING_VALUE_MAX_LENGTH} (2²⁸).
25
+ */
26
+ readonly maxLength?: number;
27
+ };
28
+ /**
29
+ * Thrown by {@link markupStringValue} when the string-value would exceed the
30
+ * effective `maxLength` or the engine cannot represent it.
31
+ */
32
+ export declare class MarkupStringValueLengthError extends Error {
33
+ readonly limit: number;
34
+ /**
35
+ * @param limit The effective maximum, or an upper bound on the engine's
36
+ * maximum if concatenation fails below that limit.
37
+ */
38
+ constructor(limit: number);
39
+ }
40
+ /**
41
+ * The string-value of a node, as XPath 1.0 defines it — the one definition
42
+ * every engine reading a {@link MarkupTreeShape} shares.
43
+ *
44
+ * - **document, fragment, element**: the data of every text descendant,
45
+ * concatenated in document order, descending through nested fragments too.
46
+ * Comments and processing instructions contribute nothing, and neither does
47
+ * anything the shape keeps out of `childrenOf`, such as a template's
48
+ * content.
49
+ * - **text**: the data of the whole text run the node belongs to (see
50
+ * {@link markupTextRunStart}), whichever member of the run is passed. Empty
51
+ * text nodes contribute `""`, so a run of empty text nodes has the empty
52
+ * string-value; an engine following the XPath data model, which has no empty
53
+ * text nodes, skips such a run rather than asking.
54
+ * - **comment, processing instruction**: its data.
55
+ * - **doctype**: `""`.
56
+ *
57
+ * O(subtree) for a document, fragment or element, plus the length of the
58
+ * result; for text, O(siblings) to locate the run without `siblingIndexOf`,
59
+ * O(run) with it, plus the length. Iterative: the tree's depth costs heap,
60
+ * never stack.
61
+ *
62
+ * @throws {MarkupStringValueLengthError} When the result would be longer than
63
+ * the effective `options.maxLength` or the engine cannot represent it.
64
+ * @throws {RangeError} When `options.maxLength` is not a non-negative safe
65
+ * integer.
66
+ * @throws {TypeError} As {@link markupSiblingIndex} does, for a text node.
67
+ * @throws Whatever `options.budget.spend` throws once it is spent.
68
+ */
69
+ export declare function markupStringValue<TNode, TAttribute>(shape: MarkupTreeShape<TNode, TAttribute>, node: TNode, options?: MarkupStringValueOptions): string;
70
+ /**
71
+ * The value of `element`'s attribute named `localName` in `namespace`, or
72
+ * `null` when it has none.
73
+ *
74
+ * `namespace` defaults to `null`, matching only unprefixed attributes with no
75
+ * namespace, not ones with an unbound prefix. Names compare exactly: an engine
76
+ * applying HTML's case rules folds the name first. The first match in source
77
+ * order wins, for a tree that tolerates duplicates. Takes O(attributes
78
+ * inspected plus code units compared) time and O(1) extra space.
79
+ *
80
+ * @param shape Accessors for the element's attributes.
81
+ * @param element The owner of the attributes to search.
82
+ * @param localName The exact local name to match.
83
+ * @param namespace The exact namespace URI, or `null` for no namespace.
84
+ * @param budget Optional work allowance. Charged before inspecting each entry,
85
+ * plus one unit per UTF-16 code unit of each equal-length name or URI pair
86
+ * compared. Reading the matching value does not scan or charge its contents.
87
+ * @throws Whatever `budget.spend` throws, unchanged.
88
+ */
89
+ export declare function markupAttributeValue<TNode, TAttribute>(shape: MarkupTreeDownShape<TNode, TAttribute>, element: TNode, localName: string, namespace?: string | null, budget?: WorkBudget): string | null;
90
+ //# sourceMappingURL=markup-values.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markup-values.d.ts","sourceRoot":"","sources":["../src/markup-values.ts"],"names":[],"mappings":"AACA,OAAO,EAGN,KAAK,UAAU,EACf,MAAM,cAAc,CAAC;AAOtB,OAAO,KAAK,EACX,mBAAmB,EACnB,eAAe,EACf,MAAM,wBAAwB,CAAC;AAEhC;;;GAGG;AACH,eAAO,MAAM,sCAAsC,WACxB,CAAC;AAE5B;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACtC;;;;;;OAMG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC;IAE7B;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF;;;GAGG;AACH,qBAAa,4BAA6B,SAAQ,KAAK;IAK1C,QAAQ,CAAC,KAAK,EAAE,MAAM;IAJlC;;;OAGG;IACH,YAAqB,KAAK,EAAE,MAAM,EAGjC;CACD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,UAAU,EAClD,KAAK,EAAE,eAAe,CAAC,KAAK,EAAE,UAAU,CAAC,EACzC,IAAI,EAAE,KAAK,EACX,OAAO,GAAE,wBAA6B,GACpC,MAAM,CA4BR;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,UAAU,EACrD,KAAK,EAAE,mBAAmB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC7C,OAAO,EAAE,KAAK,EACd,SAAS,EAAE,MAAM,EACjB,SAAS,GAAE,MAAM,GAAG,IAAW,EAC/B,MAAM,CAAC,EAAE,UAAU,GACjB,MAAM,GAAG,IAAI,CAgCf"}