hyper-html-api 0.5.1 → 0.6.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.
- package/conformance/MANIFEST.json +6 -0
- package/conformance/cases/basic-scalar-and-list.expected.json +7 -0
- package/conformance/cases/basic-scalar-and-list.html +4 -0
- package/conformance/cases/basic-scalar-and-list.meta +4 -0
- package/conformance/cases/basic-scalar-and-list.parsed.json +4 -0
- package/conformance/cases/basic-scalar-and-list.rules +1 -0
- package/conformance/cases/cms-template-skipped-by-default.expected.json +7 -0
- package/conformance/cases/cms-template-skipped-by-default.html +7 -0
- package/conformance/cases/cms-template-skipped-by-default.meta +7 -0
- package/conformance/cases/cms-template-skipped-by-default.parsed.json +5 -0
- package/conformance/cases/cms-template-skipped-by-default.rules +1 -0
- package/conformance/cases/depth-at-limit-ok.expected.json +41 -0
- package/conformance/cases/depth-at-limit-ok.html +3 -0
- package/conformance/cases/depth-at-limit-ok.meta +6 -0
- package/conformance/cases/depth-at-limit-ok.parsed.json +41 -0
- package/conformance/cases/depth-at-limit-ok.rules +1 -0
- package/conformance/cases/depth-exceeded-path-contains-selector.error.json +5 -0
- package/conformance/cases/depth-exceeded-path-contains-selector.html +3 -0
- package/conformance/cases/depth-exceeded-path-contains-selector.meta +9 -0
- package/conformance/cases/depth-exceeded-path-contains-selector.parsed.json +43 -0
- package/conformance/cases/depth-exceeded-path-contains-selector.rules +1 -0
- package/conformance/cases/depth-exceeded.error.json +5 -0
- package/conformance/cases/depth-exceeded.html +3 -0
- package/conformance/cases/depth-exceeded.meta +6 -0
- package/conformance/cases/depth-exceeded.parsed.json +43 -0
- package/conformance/cases/depth-exceeded.rules +1 -0
- package/conformance/cases/props-boolean-on-any-element.expected.json +5 -0
- package/conformance/cases/props-boolean-on-any-element.html +3 -0
- package/conformance/cases/props-boolean-on-any-element.meta +7 -0
- package/conformance/cases/props-boolean-on-any-element.parsed.json +5 -0
- package/conformance/cases/props-boolean-on-any-element.rules +1 -0
- package/conformance/cases/props-empty-attr-vs-empty-prop.expected.json +4 -0
- package/conformance/cases/props-empty-attr-vs-empty-prop.html +3 -0
- package/conformance/cases/props-empty-attr-vs-empty-prop.meta +6 -0
- package/conformance/cases/props-empty-attr-vs-empty-prop.parsed.json +4 -0
- package/conformance/cases/props-empty-attr-vs-empty-prop.rules +1 -0
- package/conformance/cases/props-null-set.expected.json +9 -0
- package/conformance/cases/props-null-set.html +3 -0
- package/conformance/cases/props-null-set.meta +7 -0
- package/conformance/cases/props-null-set.parsed.json +9 -0
- package/conformance/cases/props-null-set.rules +1 -0
- package/conformance/cases/props-readonly-always-false.expected.json +4 -0
- package/conformance/cases/props-readonly-always-false.html +4 -0
- package/conformance/cases/props-readonly-always-false.meta +11 -0
- package/conformance/cases/props-readonly-always-false.parsed.json +4 -0
- package/conformance/cases/props-readonly-always-false.rules +1 -0
- package/conformance/cases/props-select-textarea-value-null.expected.json +5 -0
- package/conformance/cases/props-select-textarea-value-null.html +5 -0
- package/conformance/cases/props-select-textarea-value-null.meta +8 -0
- package/conformance/cases/props-select-textarea-value-null.parsed.json +5 -0
- package/conformance/cases/props-select-textarea-value-null.rules +1 -0
- package/conformance/cases/props-tagname-and-nodetype.expected.json +5 -0
- package/conformance/cases/props-tagname-and-nodetype.html +3 -0
- package/conformance/cases/props-tagname-and-nodetype.meta +6 -0
- package/conformance/cases/props-tagname-and-nodetype.parsed.json +5 -0
- package/conformance/cases/props-tagname-and-nodetype.rules +1 -0
- package/conformance/cases/props-type-is-node-type.expected.json +5 -0
- package/conformance/cases/props-type-is-node-type.html +5 -0
- package/conformance/cases/props-type-is-node-type.meta +11 -0
- package/conformance/cases/props-type-is-node-type.parsed.json +5 -0
- package/conformance/cases/props-type-is-node-type.rules +1 -0
- package/conformance/cases/rules-duplicate-keys-last-wins.expected.json +3 -0
- package/conformance/cases/rules-duplicate-keys-last-wins.html +4 -0
- package/conformance/cases/rules-duplicate-keys-last-wins.meta +5 -0
- package/conformance/cases/rules-duplicate-keys-last-wins.parsed.json +3 -0
- package/conformance/cases/rules-duplicate-keys-last-wins.rules +1 -0
- package/conformance/cases/rules-iterate-dot-leading-works.expected.json +10 -0
- package/conformance/cases/rules-iterate-dot-leading-works.html +3 -0
- package/conformance/cases/rules-iterate-dot-leading-works.meta +6 -0
- package/conformance/cases/rules-iterate-dot-leading-works.parsed.json +8 -0
- package/conformance/cases/rules-iterate-dot-leading-works.rules +1 -0
- package/conformance/cases/rules-iterate-lookahead-quoted.error.json +5 -0
- package/conformance/cases/rules-iterate-lookahead-quoted.html +3 -0
- package/conformance/cases/rules-iterate-lookahead-quoted.meta +7 -0
- package/conformance/cases/rules-iterate-lookahead-quoted.rules +1 -0
- package/conformance/cases/rules-iterate-lookahead-unquoted.error.json +5 -0
- package/conformance/cases/rules-iterate-lookahead-unquoted.html +3 -0
- package/conformance/cases/rules-iterate-lookahead-unquoted.meta +8 -0
- package/conformance/cases/rules-iterate-lookahead-unquoted.parsed.json +3 -0
- package/conformance/cases/rules-iterate-lookahead-unquoted.rules +1 -0
- package/conformance/cases/rules-lastindexof-at-split.expected.json +3 -0
- package/conformance/cases/rules-lastindexof-at-split.html +3 -0
- package/conformance/cases/rules-lastindexof-at-split.meta +11 -0
- package/conformance/cases/rules-lastindexof-at-split.parsed.json +3 -0
- package/conformance/cases/rules-lastindexof-at-split.rules +1 -0
- package/conformance/cases/rules-primitives-extract-null.expected.json +5 -0
- package/conformance/cases/rules-primitives-extract-null.html +3 -0
- package/conformance/cases/rules-primitives-extract-null.meta +6 -0
- package/conformance/cases/rules-primitives-extract-null.parsed.json +5 -0
- package/conformance/cases/rules-primitives-extract-null.rules +1 -0
- package/conformance/cases/rules-proto-key-omitted.expected.json +3 -0
- package/conformance/cases/rules-proto-key-omitted.html +3 -0
- package/conformance/cases/rules-proto-key-omitted.meta +7 -0
- package/conformance/cases/rules-proto-key-omitted.parsed.json +6 -0
- package/conformance/cases/rules-proto-key-omitted.rules +1 -0
- package/conformance/cases/rules-quoted-attr-in-unquoted-selector.error.json +5 -0
- package/conformance/cases/rules-quoted-attr-in-unquoted-selector.html +4 -0
- package/conformance/cases/rules-quoted-attr-in-unquoted-selector.meta +5 -0
- package/conformance/cases/rules-quoted-attr-in-unquoted-selector.rules +1 -0
- package/conformance/cases/rules-trailing-comma-dropped.expected.json +3 -0
- package/conformance/cases/rules-trailing-comma-dropped.html +3 -0
- package/conformance/cases/rules-trailing-comma-dropped.meta +5 -0
- package/conformance/cases/rules-trailing-comma-dropped.parsed.json +3 -0
- package/conformance/cases/rules-trailing-comma-dropped.rules +1 -0
- package/conformance/cases/rules-unwhitelisted-pseudo-breaks-tokenizer.error.json +5 -0
- package/conformance/cases/rules-unwhitelisted-pseudo-breaks-tokenizer.html +3 -0
- package/conformance/cases/rules-unwhitelisted-pseudo-breaks-tokenizer.meta +7 -0
- package/conformance/cases/rules-unwhitelisted-pseudo-breaks-tokenizer.rules +1 -0
- package/conformance/cases/rules-whitespace-clings.expected.json +4 -0
- package/conformance/cases/rules-whitespace-clings.html +4 -0
- package/conformance/cases/rules-whitespace-clings.meta +6 -0
- package/conformance/cases/rules-whitespace-clings.parsed.json +4 -0
- package/conformance/cases/rules-whitespace-clings.rules +1 -0
- package/conformance/cases/selector-unknown-pseudo-is-500.error.json +5 -0
- package/conformance/cases/selector-unknown-pseudo-is-500.html +4 -0
- package/conformance/cases/selector-unknown-pseudo-is-500.meta +7 -0
- package/conformance/cases/selector-unknown-pseudo-is-500.parsed.json +3 -0
- package/conformance/cases/selector-unknown-pseudo-is-500.rules +1 -0
- package/conformance/cases/tag-basic.expected.json +7 -0
- package/conformance/cases/tag-basic.html +5 -0
- package/conformance/cases/tag-basic.meta +6 -0
- package/conformance/cases/tag-basic.parsed.json +4 -0
- package/conformance/cases/tag-duplicate-names-first-wins.expected.json +3 -0
- package/conformance/cases/tag-duplicate-names-first-wins.html +6 -0
- package/conformance/cases/tag-duplicate-names-first-wins.meta +7 -0
- package/conformance/cases/tag-duplicate-names-first-wins.parsed.json +3 -0
- package/conformance/cases/tag-missing.error.json +5 -0
- package/conformance/cases/tag-missing.html +4 -0
- package/conformance/cases/tag-missing.meta +8 -0
- package/conformance/cases/tag-name-is-space-separated.expected.json +3 -0
- package/conformance/cases/tag-name-is-space-separated.html +4 -0
- package/conformance/cases/tag-name-is-space-separated.meta +6 -0
- package/conformance/cases/tag-name-is-space-separated.parsed.json +3 -0
- package/conformance/cases/tag-relaxed-body.expected.json +7 -0
- package/conformance/cases/tag-relaxed-body.html +5 -0
- package/conformance/cases/tag-relaxed-body.meta +7 -0
- package/conformance/cases/tag-relaxed-body.parsed.json +4 -0
- package/conformance/cases/tag-wrong-version.error.json +5 -0
- package/conformance/cases/tag-wrong-version.html +4 -0
- package/conformance/cases/tag-wrong-version.meta +6 -0
- package/conformance/cases/template-simple-vs-combinator.expected.json +7 -0
- package/conformance/cases/template-simple-vs-combinator.html +4 -0
- package/conformance/cases/template-simple-vs-combinator.meta +8 -0
- package/conformance/cases/template-simple-vs-combinator.parsed.json +4 -0
- package/conformance/cases/template-simple-vs-combinator.rules +1 -0
- package/conformance/cases/text-root-leaks-rules-tag.expected.json +4 -0
- package/conformance/cases/text-root-leaks-rules-tag.html +4 -0
- package/conformance/cases/text-root-leaks-rules-tag.meta +7 -0
- package/conformance/cases/text-root-leaks-rules-tag.parsed.json +4 -0
- package/conformance/cases/text-root-leaks-rules-tag.rules +1 -0
- package/conformance/cases/text-trim-asymmetry.expected.json +5 -0
- package/conformance/cases/text-trim-asymmetry.html +5 -0
- package/conformance/cases/text-trim-asymmetry.meta +6 -0
- package/conformance/cases/text-trim-asymmetry.parsed.json +5 -0
- package/conformance/cases/text-trim-asymmetry.rules +1 -0
- package/dist/hyper-html-api.engine.min.js +1 -1
- package/dist/hyper-html-api.min.js +4 -3
- package/dist/hyper-html-api.upgrade.min.js +2 -2
- package/package.json +13 -5
- package/src/cms/form-builder.js +3 -2
- package/src/dom-api.js +5 -0
- package/src/engine/apply.js +3 -2
- package/src/engine/diff.js +70 -13
- package/src/engine/extract.js +3 -2
- package/src/engine/index.js +1 -0
- package/src/engine/rule-syntax.js +43 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
tier: 1
|
|
2
|
+
face: query
|
|
3
|
+
expect: error
|
|
4
|
+
note: Same `[`-lookahead bug as rules-iterate-lookahead-unquoted, different exit. The swallowed
|
|
5
|
+
note: run contains double quotes, and the SELECTOR branch re-emits a token value unescaped, so
|
|
6
|
+
note: the generated JSON is malformed and this dies at PARSE instead of at extract. Message
|
|
7
|
+
note: contains "JSON", so 400.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{forms:[form,{id:"@id"}]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
tier: 1
|
|
2
|
+
face: query
|
|
3
|
+
expect: error
|
|
4
|
+
note: BUG, pinned as-is. The `[` lookahead only asks whether the next char matches /[a-zA-Z_]/
|
|
5
|
+
note: to decide "attribute selector", so an iterate form whose selector starts with a tag name
|
|
6
|
+
note: is swallowed whole: the value parses as the STRING "[form,{a:@action}]", not a pair.
|
|
7
|
+
note: Extraction then splits it at the last @ and hands css-select a truncated selector. The
|
|
8
|
+
note: message contains "selector", so the reference host answers 400 here.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{forms:[form,{a:@action}]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
tier: 3
|
|
2
|
+
face: query
|
|
3
|
+
expect: ok
|
|
4
|
+
note: The property split scans for the last "@" at bracket depth zero and outside quotes, so an @
|
|
5
|
+
note: inside an attribute value stays part of the selector. `a[href*="@"]` is one selector reading
|
|
6
|
+
note: the link's text, not a broken split into 'a[href*="' plus a property name.
|
|
7
|
+
note: This case previously pinned the opposite: a plain lastIndexOf over the whole rule, which cut
|
|
8
|
+
note: the selector mid-bracket and left css-what to report "Attribute value didn't end". It was
|
|
9
|
+
note: fixed across all four implementations at once (2026-08-13) rather than left as a divergence,
|
|
10
|
+
note: because splitting inside the brackets always leaves an unclosed "[" or quote, so every rule
|
|
11
|
+
note: the old split touched was a hard parse error and nothing could have depended on it.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{x:'a[href*="@"]'}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
tier: 1
|
|
2
|
+
face: query
|
|
3
|
+
expect: ok
|
|
4
|
+
note: Numbers, booleans and null tokenize and parse as real JSON primitives, but extractAt has
|
|
5
|
+
note: no arm for them: not a string, not an array, and null fails the object guard, so all
|
|
6
|
+
note: three fall through to the trailing `return null`. A typo'd rule reads as an empty field.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{a:1,b:true,c:null}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
tier: 1
|
|
2
|
+
face: query
|
|
3
|
+
expect: ok
|
|
4
|
+
note: A "__proto__" rule key parses (JSON.parse defines it as an OWN property, so it is in the
|
|
5
|
+
note: parsed tree) but cannot be written: extractAt does `result[key] =`, which on a plain object
|
|
6
|
+
note: hits the legacy Object.prototype __proto__ setter and re-parents `result` instead of adding
|
|
7
|
+
note: a key. The key is silently absent from the output; sibling keys are unaffected.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"__proto__":{"x":"h1"},"ok":"h1"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{x:a[href^="http"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{a:"h1",}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
tier: 1
|
|
2
|
+
face: query
|
|
3
|
+
expect: error
|
|
4
|
+
note: An unwhitelisted pseudo breaks TOKENIZING, not just matching. :is is not in the hardcoded
|
|
5
|
+
note: list, so the identifier run stops at the colon, which is then emitted as a bare COLON and
|
|
6
|
+
note: yields "h1":"is(.a)" inside an object. Parse error, message contains "JSON", so 400.
|
|
7
|
+
note: Contrast selector-unknown-pseudo-is-500, where a whitelist PREFIX match lets it tokenize.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{x:h1:is(.a)}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
tier: 1
|
|
2
|
+
face: query
|
|
3
|
+
expect: ok
|
|
4
|
+
note: Whitespace clings asymmetrically. The tokenizer skips leading whitespace before a token
|
|
5
|
+
note: but never trims the token it then reads to the next {},: so the second key is "y " with
|
|
6
|
+
note: a trailing space and its value is ".i " with one too. Both survive into the output shape.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{x:.i, y : .i }
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
tier: 3
|
|
2
|
+
face: query
|
|
3
|
+
expect: error
|
|
4
|
+
note: DIVERGENCE. The pseudo whitelist prefix-matches, so this TOKENIZES fine and then throws
|
|
5
|
+
note: from css-select at find time. The message contains neither "JSON" nor "selector", so the
|
|
6
|
+
note: JS hosts answer 500. htmlclay answers 400 by mapping on error type. Upstream fix moves
|
|
7
|
+
note: all four hosts to 400; until then Go is expected to differ here, in this direction.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{x:h1:nth-childx(2)}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<!doctype html><html><body>
|
|
2
|
+
<h1>Hello</h1>
|
|
3
|
+
<ul><li class="i">one</li><li class="i">two</li></ul>
|
|
4
|
+
<script data-rules-name="api" data-rules-version="1">{first:"h1"}</script>
|
|
5
|
+
<script data-rules-name="api" data-rules-version="1">{second:".i"}</script>
|
|
6
|
+
</body></html>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
tier: 1
|
|
2
|
+
face: tag
|
|
3
|
+
token: api
|
|
4
|
+
expect: ok
|
|
5
|
+
note: Two tags claim the same token. findRulesIn warns and uses the FIRST in document order,
|
|
6
|
+
note: it does not merge them and does not error, so the second tag's rules never run. The two
|
|
7
|
+
note: bodies use different keys so the output says unambiguously which one won.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
tier: 1
|
|
2
|
+
face: tag
|
|
3
|
+
token: api
|
|
4
|
+
expect: error
|
|
5
|
+
note: No script[data-rules-name~="api"], so findRulesIn returns null rather than throwing: the
|
|
6
|
+
note: absence is not an engine error, and the host is what turns it into a 400. The document
|
|
7
|
+
note: does carry a rules tag under a different name, so this pins the TOKEN match, not the
|
|
8
|
+
note: mere presence of a tag.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
tier: 1
|
|
2
|
+
face: tag
|
|
3
|
+
token: api
|
|
4
|
+
expect: ok
|
|
5
|
+
note: A script body takes the same relaxed syntax as the ?data= parameter: unquoted keys,
|
|
6
|
+
note: single-quoted strings and a trailing comma. It parses to exactly the tree tag-basic gets
|
|
7
|
+
note: from strict JSON, so the two faces share one parser and the quoting is authorial taste.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
tier: 3
|
|
2
|
+
face: query
|
|
3
|
+
expect: ok
|
|
4
|
+
skip: htmlclay=deliberately matches the browser, not cheerio. The selector shadow tree is phase 4; until it lands, htmlclay TestTemplateContentIsCurrentlyVisible pins the current pre-shadow-tree counts and states what they become
|
|
5
|
+
note: DIVERGENCE. cheerio finds template content with a simple selector but not through a
|
|
6
|
+
note: combinator, disagreeing with itself AND with the browser. In cheerio template content is
|
|
7
|
+
note: a detached forest: reachable by descendant traversal, but with no parent links. htmlclay
|
|
8
|
+
note: detaches it into a selector shadow tree, so BOTH keys are [] there, matching the browser.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{simple:".i[]",viaCombinator:"template .i[]"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
tier: 1
|
|
2
|
+
face: query
|
|
3
|
+
expect: ok
|
|
4
|
+
note: The rules-tag filter lives in find(), not in text(). So `.` on the root concatenates the
|
|
5
|
+
note: rules tag's own source into the extracted text, while the sibling key, a plain `script`
|
|
6
|
+
note: selector, goes through find() and matches nothing. A document's whole-page text read
|
|
7
|
+
note: leaks its own rule definitions.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":".","viaFind":"script"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
tier: 1
|
|
2
|
+
face: query
|
|
3
|
+
expect: ok
|
|
4
|
+
note: One element, three reads, two answers. A plain selector rule goes through adapter.text(),
|
|
5
|
+
note: which trims; @textContent and @innerText bypass that and return the raw concatenation,
|
|
6
|
+
note: leading newline and interior run of spaces intact. Nested markup is flattened either way.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"trimmed":"#p","textContent":"#p@textContent","innerText":"#p@innerText"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var hyperHtmlApiData=(()=>{var k=Object.defineProperty;var lt=Object.getOwnPropertyDescriptor;var ct=Object.getOwnPropertyNames;var ft=Object.prototype.hasOwnProperty;var K=(t,e)=>{for(var n in e)k(t,n,{get:e[n],enumerable:!0})},ut=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of ct(e))!ft.call(t,r)&&r!==n&&k(t,r,{get:()=>e[r],enumerable:!(o=lt(e,r))||o.enumerable});return t};var at=t=>ut(k({},"__esModule",{value:!0}),t);var wt={};K(wt,{applyData:()=>X,default:()=>It,engine:()=>P,extractData:()=>G});var C=["textContent","innerText","innerHTML","outerHTML","value","checked","selected","disabled","readOnly","type","tagName","nodeName","nodeType","nodeValue","childElementCount","id","className","classList","baseURI","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","dataset","currentSrc","duration","paused","title","documentURI","contentType"],B=new Set(C),Y=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),Q=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var j={};K(j,{EmptyListInsert:()=>I,MAX_RULE_DEPTH:()=>A,MaxRuleDepthExceeded:()=>E,RuleTargetReadOnly:()=>w,RulesParseError:()=>S,ShapeMismatch:()=>b,UnknownRulesVersion:()=>N});var S=class extends Error{constructor(e,n){super(e),this.name="RulesParseError",this.cause=n}},N=class extends Error{constructor(e){super(`unknown rules version: ${e}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=e}},A=20,E=class extends Error{constructor(e){super(`rule depth exceeded ${A} at path: ${e.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=e}},b=class extends Error{constructor(e){super(`shape mismatch: ${e.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=e}},I=class extends Error{constructor(e){super(`cannot add items to empty list at "${e.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=e}},w=class extends Error{constructor(e){super(`cannot write to read-only DOM property "${e}"`),this.name="RuleTargetReadOnly",this.target=e}};function g(t,e,n,o={}){return U(t,e,n,{depth:0,path:[]},o)}function U(t,e,n,o,r){if(o.depth>A)throw new E(o.path);if(typeof n=="string")return ht(t,e,n,r);if(Array.isArray(n)){let[i,c]=n;return t.find(e,i,r).map((l,a)=>U(t,l,c,{depth:o.depth+1,path:[...o.path,a]},r))}if(typeof n=="object"&&n!==null){let i={};for(let[c,s]of Object.entries(n))i[c]=U(t,e,s,{depth:o.depth+1,path:[...o.path,c]},r);return i}return null}function ht(t,e,n,o){if(n.endsWith("[]")){let i=n.slice(0,-2);return t.find(e,i,o).map(c=>t.text(c))}if(n.startsWith("@"))return Z(t,e,n.slice(1));if(n.includes("@")){let i=n.lastIndexOf("@"),c=n.slice(0,i),s=n.slice(i+1),l=c?t.find(e,c,o):[e];return l.length===0?null:Z(t,l[0],s)}if(n===".")return t.text(e);let r=t.find(e,n,o);return r.length===0?null:t.text(r[0])}function Z(t,e,n){if(B.has(n)){let r=t.prop(e,n);return r==null?null:String(r)}let o=t.attr(e,n);return o||null}var dt=.5;function q(t,e,n,o,r,i,c,s={}){let l=t.find(e,n,s);if(r.length===0){l.forEach(h=>t.remove(h));return}let a=r.length>l.length,u=l[0]||null;if(a&&!u&&(u=Et(t,e,n,s),!u))throw new I(i.path);let d=l.map(h=>pt(t,h,o,s)),f=null;if(u){f=t.clone(u),s.templateAttr&&t.removeAttr(f,s.templateAttr);let h=t.stripIds(f);h>0&&console.warn(`[hyper-html-api] stripped ${h} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let H=mt(r,d,o),R=l[0]||u,L=t.parent(R),it=l.length>0?gt(t,L,R):0,z=new Set,W=r.map((h,m)=>{let p=H[m];if(p>=0)return z.add(p),l[p];let O=t.clone(f);return t.stripIds(O),O});l.forEach((h,m)=>{z.has(m)||t.remove(h)}),W.forEach((h,m)=>{let p=it+m;t.children(L).findIndex(st=>t.sameNode(st,h))!==p&&t.insertAt(L,h,p)}),W.forEach((h,m)=>{if(o===null){let p=r[m],O=p==null?"":String(p);t.text(h)!==O&&t.text(h,O)}else{let p=c(t,h,o,r[m],{depth:i.depth+1,path:[...i.path,m]},s);p&&p!==h&&(W[m]=p)}})}function pt(t,e,n,o){return n===null?t.text(e):g(t,e,n,o)}function mt(t,e,n){let o=new Array(t.length).fill(-1),r=new Set;return t.forEach((i,c)=>{let s=-1,l=-1;e.forEach((a,u)=>{if(r.has(u))return;let d=yt(i,a,n),f=d===l&&s>=0?Math.abs(u-c)<Math.abs(s-c):!1;(d>l||f)&&(l=d,s=u)}),l>=dt&&(o[c]=s,r.add(s))}),o}function yt(t,e,n){if(n===null)return t===e?1:0;let o=Object.keys(n||{});if(o.length===0)return 0;let r=0;for(let i of o)JSON.stringify(t?.[i])===JSON.stringify(e?.[i])&&r++;return r/o.length}function gt(t,e,n){let o=t.children(e);for(let r=0;r<o.length;r++)if(t.sameNode(o[r],n))return r;return-1}function Et(t,e,n,o){if(!o.templateAttr)return null;let r=e;for(;r;){let i=t.find(r,n,{includeRulesTag:!1,templateAttr:null});for(let c of i)if(t.attr(c,o.templateAttr)!=null)return c;r=t.parent(r)}return null}var tt=new Set(["checked","selected","disabled","readOnly","paused"]);function T(t,e,n,o,r={}){let i=[];if(v(n,o,[],i),i.length)throw new b(i);$(t,e,n,o,{depth:0,path:[]},r)}function $(t,e,n,o,r,i={}){if(r.depth>A)throw new E(r.path);if(o===void 0)return e;if(typeof n=="string")return Rt(t,e,n,o,r,i);if(Array.isArray(n)){let[c,s]=n;return q(t,e,c,s,o,r,$,i),e}if(typeof n=="object"&&n!==null){for(let[c,s]of Object.entries(n)){let l=$(t,e,s,o==null?o:o[c],{depth:r.depth+1,path:[...r.path,c]},i);l&&l!==e&&(e=l)}return e}return e}function Rt(t,e,n,o,r,i){if(n.endsWith("[]")){let s=n.slice(0,-2);return q(t,e,s,null,o,r,$,i),e}if(n.startsWith("@"))return et(t,e,n.slice(1),o);if(n.includes("@")){let s=n.lastIndexOf("@"),l=n.slice(0,s),a=n.slice(s+1),u=l?t.find(e,l,i):[e];return u.length===0||et(t,u[0],a,o),e}if(n===".")return t.text(e,o==null?"":String(o)),e;let c=t.find(e,n,i);return c.length===0||t.text(c[0],o==null?"":String(o)),e}function et(t,e,n,o){if(Q.has(n))throw new w(n);if(n==="outerHTML"){let r=o==null?"":String(o);return t.replaceWith(e,r)}return Y.has(n)?(t.prop(e,n,Ot(n,o)),e):(t.attr(e,n,o==null?"":String(o)),e)}function Ot(t,e){return e==null?tt.has(t)?!1:"":tt.has(t)?!!e:e}function v(t,e,n,o){if(e!==void 0){if(typeof t=="string"){if(t.endsWith("[]")){Array.isArray(e)?e.forEach((r,i)=>{typeof r=="object"&&r!==null&&o.push({path:_([...n,i]),expected:"scalar",got:M(r)})}):o.push({path:_(n),expected:"array",got:M(e)});return}e!==null&&typeof e=="object"&&o.push({path:_(n),expected:"scalar",got:M(e)});return}if(Array.isArray(t)){if(!Array.isArray(e)){o.push({path:_(n),expected:"array",got:M(e)});return}let r=t[1];e.forEach((i,c)=>v(r,i,[...n,c],o));return}if(typeof t=="object"&&t!==null){if(e===null||Array.isArray(e)||typeof e!="object"){o.push({path:_(n),expected:"object",got:M(e)});return}for(let[r,i]of Object.entries(t))v(i,e[r],[...n,r],o)}}}function M(t){return t===null?"null":Array.isArray(t)?"array":typeof t}function _(t){return t.join(".")}function J(t){try{return JSON.parse(t)}catch(e){throw new S(`Invalid strict JSON: ${e.message}`,e)}}function D(t){try{return JSON.parse(t)}catch{}let e={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function n(r){let i=[],c=0;for(;c<r.length;){let s=r[c];if(/\s/.test(s)){c++;continue}if("{}".includes(s)){i.push({type:s,value:s}),c++;continue}if(s==="["){let d=!1,f=c+1;for(;f<r.length&&/\s/.test(r[f]);)f++;if(f<r.length&&/[a-zA-Z_]/.test(r[f])&&(d=!0),!d){i.push({type:s,value:s}),c++;continue}}if(s==="]"){i.push({type:s,value:s}),c++;continue}if(s===":"){i.push({type:e.COLON,value:s}),c++;continue}if(s===","){i.push({type:e.COMMA,value:s}),c++;continue}if(s==='"'||s==="'"){let d=s,f=c+1;for(;f<r.length&&r[f]!==d;)r[f]==="\\"&&f++,f++;i.push({type:e.STRING,value:r.substring(c+1,f),quoted:!0,sourceQuote:d}),c=f+1;continue}let l=c,a;for(;l<r.length&&!/[{},]/.test(r[l]);)if(r[l]===":"){let d=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],f=!1;for(let H of d){let R=H.substring(1);if(r.substring(l+1,l+1+R.length)===R){f=!0,l+=R.length;break}}if(!f)break}else if(r[l]==="["){for(l++;l<r.length&&r[l]!=="]";){if(r[l]==='"'||r[l]==="'"){let d=r[l];for(l++;l<r.length&&r[l]!==d;)r[l]==="\\"&&l++,l++}l++}l<r.length&&r[l]==="]"&&l++}else l++;a=r.substring(c,l);let u=e.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(a)?u=e.NUMBER:a==="true"||a==="false"||a==="null"?u=e.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(a)&&(u=e.SELECTOR),i.push({type:u,value:a,quoted:!1}),c=l}return i}function o(r){let i="";for(let c=0;c<r.length;c++){let s=r[c];if("{}".includes(s.type)||"[]".includes(s.type)){i+=s.value;continue}if(s.type===e.COLON){i+=s.value;continue}if(s.type===e.COMMA){let l=r[c+1];if(l&&(l.type==="}"||l.type==="]"))continue;i+=s.value;continue}if(s.type===e.STRING&&s.quoted){let l=s.value;s.sourceQuote==="'"&&(l=l.replace(/\\'/g,"'"),l=l.replace(/(\\*)"/g,(a,u)=>u.length%2===0?u+'\\"':a)),i+=`"${l}"`;continue}if(s.type===e.NUMBER||s.type===e.BOOLEAN){i+=s.value;continue}if(s.type===e.SELECTOR||s.type===e.IDENTIFIER){i+=`"${s.value}"`;continue}i+=`"${s.value}"`}return i}try{let r=n(t),i=o(r);return JSON.parse(i)}catch(r){throw new S("Invalid extraction rules syntax: "+r.message,r)}}var St="1",nt=/^[a-zA-Z0-9_-]+$/;function x(t,e,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!nt.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${nt})`);o=`script[data-rules-name~="${n}"]`}let r=t.find(e,o,{includeRulesTag:!0});if(r.length===0)return null;n!==void 0&&r.length>1&&console.warn(`hyper-html-api: ${r.length} rules tags match data-rules-name~="${n}"; using the first.`);let i=r[0],c=t.attr(i,"data-rules-version");if(c!==St)throw new N(c);return{rules:D(t.text(i)),tagNode:i}}function V(t,e,n){if(n&&typeof n=="object")return{rules:n,tagNode:null};if(typeof n=="string"){let o=e&&e.ownerDocument?e.ownerDocument:e;return x(t,o,n)}return null}function rt(t,e,n,o){let r=V(t,e,n);if(!r){let s=typeof n=="string"?`data-rules-name~="${n}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${s}`)}let{rules:i,tagNode:c}=r;return{rules:i,tagNode:c,get:()=>g(t,e,i,o),set:s=>T(t,e,i,s,o)}}function Tt(t){return t&&t.nodeType===1&&t.tagName==="SCRIPT"&&t.hasAttribute&&t.hasAttribute("data-rules-name")}function xt(t){return t?(t.nodeType===9||t.nodeType===11,t):null}var Nt={find(t,e,n={}){let o=xt(t);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(e));n.includeRulesTag||(r=r.filter(s=>!Tt(s)));let i=[];n.skip&&i.push(n.skip);let c=n.templateAttr===null?null:n.templateAttr||"cms-template";if(c&&i.push("["+c+"]"),i.length){let s=i.join(", ");r=r.filter(l=>!l.closest||!l.closest(s))}return r},parent(t){return t?t.parentElement:null},children(t){return t?Array.from(t.children):[]},text(t,e){if(e===void 0)return(t.textContent||"").trim();t.textContent=e},attr(t,e,n){if(n===void 0)return t.hasAttribute&&t.hasAttribute(e)?t.getAttribute(e):null;t.setAttribute(e,n)},removeAttr(t,e){t&&t.removeAttribute&&t.removeAttribute(e)},prop(t,e,n){if(n===void 0){let o=t?t[e]:void 0;return o!==void 0?o:null}t[e]=n},clone(t){return t.cloneNode(!0)},insertAt(t,e,n){let o=t.children[n]||null;t.insertBefore(e,o)},remove(t){t&&t.parentNode&&t.parentNode.removeChild(t)},replaceWith(t,e){if(!t||!t.parentNode)throw new Error("dom.replaceWith: node has no parent");let o=t.ownerDocument.createElement("template");o.innerHTML=e;let r=o.content.firstElementChild;if(!r)throw new Error("dom.replaceWith: html did not parse to an element");return t.parentNode.replaceChild(r,t),r},stripIds(t){let e=0;return t.id&&(t.removeAttribute("id"),e++),(t.querySelectorAll?t.querySelectorAll("[id]"):[]).forEach(o=>{o.removeAttribute("id"),e++}),e},sameNode(t,e){return t===e}},y=Nt;var P={extract:(t,e,n)=>g(y,t,e,n),apply:(t,e,n,o)=>T(y,t,e,n,o),findRulesIn:(t,e)=>x(y,t,e),findRules:(t,e)=>V(y,t,e),bind:(t,e,n)=>rt(y,t,e,n),parseStrict:J,parseRelaxed:D,errors:j,DOM_PROPERTIES:C},F=t=>!!t&&typeof t.nodeType=="number";function ot(t){let e=t&&t.ownerDocument?t.ownerDocument:t,n=y.find(e,"script[data-rules-name]",{includeRulesTag:!0});if(n.length===0)throw new Error('hyper-html-api: no rules tag found. Add <script type="application/json" data-rules-name="\u2026" data-rules-version="1"> or pass rules.');if(n.length>1)throw new Error('hyper-html-api: multiple rules tags found; pass a name, e.g. extractData("api").');return x(y,e).rules}function G(t,e){let n=F(t)?t:document,o=F(t)?e:t;return o===void 0?g(y,n,ot(n)):P.bind(n,o).get()}function X(t,e,n){if(!F(t))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");return n===void 0?T(y,t,ot(t),e):P.bind(t,n).set(e),t}var bt={engine:P,extractData:G,applyData:X},It=bt;return at(wt);})();
|
|
1
|
+
var hyperHtmlApiData=(()=>{var U=Object.defineProperty;var pt=Object.getOwnPropertyDescriptor;var dt=Object.getOwnPropertyNames;var mt=Object.prototype.hasOwnProperty;var tt=(t,e)=>{for(var n in e)U(t,n,{get:e[n],enumerable:!0})},gt=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of dt(e))!mt.call(t,r)&&r!==n&&U(t,r,{get:()=>e[r],enumerable:!(o=pt(e,r))||o.enumerable});return t};var yt=t=>gt(U({},"__esModule",{value:!0}),t);var jt={};tt(jt,{applyData:()=>Y,default:()=>Ct,engine:()=>L,extractData:()=>K});var j=["textContent","innerText","innerHTML","outerHTML","value","checked","selected","disabled","readOnly","type","tagName","nodeName","nodeType","nodeValue","childElementCount","id","className","classList","baseURI","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","dataset","currentSrc","duration","paused","title","documentURI","contentType"],q=new Set(j),et=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),nt=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var $={};tt($,{EmptyListInsert:()=>w,MAX_RULE_DEPTH:()=>O,MaxRuleDepthExceeded:()=>y,RuleTargetReadOnly:()=>M,RulesParseError:()=>A,ShapeMismatch:()=>N,UnknownRulesVersion:()=>b});var A=class extends Error{constructor(e,n){super(e),this.name="RulesParseError",this.cause=n}},b=class extends Error{constructor(e){super(`unknown rules version: ${e}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=e}},O=20,y=class extends Error{constructor(e){super(`rule depth exceeded ${O} at path: ${e.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=e}},N=class extends Error{constructor(e){super(`shape mismatch: ${e.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=e}},w=class extends Error{constructor(e){super(`cannot add items to empty list at "${e.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=e}},M=class extends Error{constructor(e){super(`cannot write to read-only DOM property "${e}"`),this.name="RuleTargetReadOnly",this.target=e}};function m(t){let e=0,n=null,o=-1;for(let r=0;r<t.length;r++){let i=t[r];i==="\\"?r++:n?i===n&&(n=null):i==='"'||i==="'"?n=i:i==="["||i==="("?e++:i==="]"||i===")"?e>0&&e--:i==="@"&&e===0&&(o=r)}return o}function v(t){let e=m(t);return e===-1?{selector:t,prop:null}:{selector:t.slice(0,e),prop:t.slice(e+1)||null}}function g(t,e,n,o={}){return J(t,e,n,{depth:0,path:[]},o)}function J(t,e,n,o,r){if(o.depth>O)throw new y(o.path);if(typeof n=="string")return Et(t,e,n,r);if(Array.isArray(n)){let[i,c]=n;return t.find(e,i,r).map((l,f)=>J(t,l,c,{depth:o.depth+1,path:[...o.path,f]},r))}if(typeof n=="object"&&n!==null){let i={};for(let[c,s]of Object.entries(n))i[c]=J(t,e,s,{depth:o.depth+1,path:[...o.path,c]},r);return i}return null}function Et(t,e,n,o){if(n.endsWith("[]")){let c=n.slice(0,-2);return t.find(e,c,o).map(s=>t.text(s))}if(n.startsWith("@"))return rt(t,e,n.slice(1));let r=m(n);if(r!==-1){let c=n.slice(0,r),s=n.slice(r+1),l=c?t.find(e,c,o):[e];return l.length===0?null:rt(t,l[0],s)}if(n===".")return t.text(e);let i=t.find(e,n,o);return i.length===0?null:t.text(i[0])}function rt(t,e,n){if(q.has(n)){let r=t.prop(e,n);return r==null?null:String(r)}let o=t.attr(e,n);return o||null}var Rt=.5;function F(t,e,n,o,r,i,c,s={}){let l=t.find(e,n,s);if(r.length===0){l.forEach(p=>t.remove(p));return}let f=r.length>l.length,u=l[0]||null;if(f&&!u&&(u=xt(t,e,n,s),!u))throw new w(i.path);let a=l.map(p=>At(t,p,o,s)),h=null;if(u){h=t.clone(u),s.templateAttr&&t.removeAttr(h,s.templateAttr);let p=t.stripIds(h);p>0&&console.warn(`[hyper-html-api] stripped ${p} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let k=Ot(r,a,o),E=l[0]||u,T=t.parent(E),Q=l.length>0?it(t,T,E):0,ht=Tt(t,l),Z=new Set,W=[],C=r.map((p,I)=>{let R=k[I];if(R>=0)return Z.add(R),W.push(!1),l[R];W.push(!0);let B=t.clone(h);return t.stripIds(B),B});if(l.forEach((p,I)=>{Z.has(I)||t.remove(p)}),ht){C.forEach((p,I)=>{let R=Q+I;t.children(T).findIndex(at=>t.sameNode(at,p))!==R&&t.insertAt(T,p,R)}),ot(t,C,o,r,i,c,s);return}It(t,C,W,T,Q),ot(t,C,o,r,i,c,s)}function ot(t,e,n,o,r,i,c){e.forEach((s,l)=>{if(n===null){let f=o[l],u=f==null?"":String(f);t.text(s)!==u&&t.text(s,u)}else{let f=i(t,s,n,o[l],{depth:r.depth+1,path:[...r.path,l]},c);f&&f!==s&&(e[l]=f)}})}function At(t,e,n,o){return n===null?t.text(e):g(t,e,n,o)}function Ot(t,e,n){let o=new Array(t.length).fill(-1),r=new Set;return t.forEach((i,c)=>{let s=-1,l=-1;e.forEach((f,u)=>{if(r.has(u))return;let a=St(i,f,n),h=a===l&&s>=0?Math.abs(u-c)<Math.abs(s-c):!1;(a>l||h)&&(l=a,s=u)}),l>=Rt&&(o[c]=s,r.add(s))}),o}function St(t,e,n){if(n===null)return t===e?1:0;let o=Object.keys(n||{});if(o.length===0)return 0;let r=0;for(let i of o)JSON.stringify(t?.[i])===JSON.stringify(e?.[i])&&r++;return r/o.length}function it(t,e,n){let o=t.children(e);for(let r=0;r<o.length;r++)if(t.sameNode(o[r],n))return r;return-1}function xt(t,e,n,o){if(!o.templateAttr)return null;let r=e;for(;r;){let i=t.find(r,n,{includeRulesTag:!1,templateAttr:null});for(let c of i)if(t.attr(c,o.templateAttr)!=null)return c;r=t.parent(r)}return null}function Tt(t,e){if(e.length<=1)return!0;let n=t.parent(e[0]);if(!n)return!1;let o=t.children(n),r=[];for(let i of e){let c=o.findIndex(s=>t.sameNode(s,i));if(c===-1)return!1;r.push(c)}return r.sort((i,c)=>i-c),r[r.length-1]-r[0]===r.length-1}function It(t,e,n,o,r){let i=null,c=r;for(let s=0;s<e.length;s++){if(!n[s]){i=e[s];continue}let l=i?t.parent(i):o;if(!l)continue;let f=i?it(t,l,i)+1:c++;t.insertAt(l,e[s],f),i=e[s]}}var st=new Set(["checked","selected","disabled","readOnly","paused"]);function S(t,e,n,o,r={}){let i=[];if(V(n,o,[],i),i.length)throw new N(i);H(t,e,n,o,{depth:0,path:[]},r)}function H(t,e,n,o,r,i={}){if(r.depth>O)throw new y(r.path);if(o===void 0)return e;if(typeof n=="string")return bt(t,e,n,o,r,i);if(Array.isArray(n)){let[c,s]=n;return F(t,e,c,s,o,r,H,i),e}if(typeof n=="object"&&n!==null){for(let[c,s]of Object.entries(n)){let l=H(t,e,s,o==null?o:o[c],{depth:r.depth+1,path:[...r.path,c]},i);l&&l!==e&&(e=l)}return e}return e}function bt(t,e,n,o,r,i){if(n.endsWith("[]")){let l=n.slice(0,-2);return F(t,e,l,null,o,r,H,i),e}if(n.startsWith("@"))return lt(t,e,n.slice(1),o);let c=m(n);if(c!==-1){let l=n.slice(0,c),f=n.slice(c+1),u=l?t.find(e,l,i):[e];return u.length===0||lt(t,u[0],f,o),e}if(n===".")return t.text(e,o==null?"":String(o)),e;let s=t.find(e,n,i);return s.length===0||t.text(s[0],o==null?"":String(o)),e}function lt(t,e,n,o){if(nt.has(n))throw new M(n);if(n==="outerHTML"){let r=o==null?"":String(o);return t.replaceWith(e,r)}return et.has(n)?(t.prop(e,n,Nt(n,o)),e):(t.attr(e,n,o==null?"":String(o)),e)}function Nt(t,e){return e==null?st.has(t)?!1:"":st.has(t)?!!e:e}function V(t,e,n,o){if(e!==void 0){if(typeof t=="string"){if(t.endsWith("[]")){Array.isArray(e)?e.forEach((r,i)=>{typeof r=="object"&&r!==null&&o.push({path:D([...n,i]),expected:"scalar",got:_(r)})}):o.push({path:D(n),expected:"array",got:_(e)});return}e!==null&&typeof e=="object"&&o.push({path:D(n),expected:"scalar",got:_(e)});return}if(Array.isArray(t)){if(!Array.isArray(e)){o.push({path:D(n),expected:"array",got:_(e)});return}let r=t[1];e.forEach((i,c)=>V(r,i,[...n,c],o));return}if(typeof t=="object"&&t!==null){if(e===null||Array.isArray(e)||typeof e!="object"){o.push({path:D(n),expected:"object",got:_(e)});return}for(let[r,i]of Object.entries(t))V(i,e[r],[...n,r],o)}}}function _(t){return t===null?"null":Array.isArray(t)?"array":typeof t}function D(t){return t.join(".")}function G(t){try{return JSON.parse(t)}catch(e){throw new A(`Invalid strict JSON: ${e.message}`,e)}}function P(t){try{return JSON.parse(t)}catch{}let e={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function n(r){let i=[],c=0;for(;c<r.length;){let s=r[c];if(/\s/.test(s)){c++;continue}if("{}".includes(s)){i.push({type:s,value:s}),c++;continue}if(s==="["){let a=!1,h=c+1;for(;h<r.length&&/\s/.test(r[h]);)h++;if(h<r.length&&/[a-zA-Z_]/.test(r[h])&&(a=!0),!a){i.push({type:s,value:s}),c++;continue}}if(s==="]"){i.push({type:s,value:s}),c++;continue}if(s===":"){i.push({type:e.COLON,value:s}),c++;continue}if(s===","){i.push({type:e.COMMA,value:s}),c++;continue}if(s==='"'||s==="'"){let a=s,h=c+1;for(;h<r.length&&r[h]!==a;)r[h]==="\\"&&h++,h++;i.push({type:e.STRING,value:r.substring(c+1,h),quoted:!0,sourceQuote:a}),c=h+1;continue}let l=c,f;for(;l<r.length&&!/[{},]/.test(r[l]);)if(r[l]===":"){let a=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],h=!1;for(let k of a){let E=k.substring(1);if(r.substring(l+1,l+1+E.length)===E){h=!0,l+=E.length;break}}if(!h)break}else if(r[l]==="["){for(l++;l<r.length&&r[l]!=="]";){if(r[l]==='"'||r[l]==="'"){let a=r[l];for(l++;l<r.length&&r[l]!==a;)r[l]==="\\"&&l++,l++}l++}l<r.length&&r[l]==="]"&&l++}else l++;f=r.substring(c,l);let u=e.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(f)?u=e.NUMBER:f==="true"||f==="false"||f==="null"?u=e.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(f)&&(u=e.SELECTOR),i.push({type:u,value:f,quoted:!1}),c=l}return i}function o(r){let i="";for(let c=0;c<r.length;c++){let s=r[c];if("{}".includes(s.type)||"[]".includes(s.type)){i+=s.value;continue}if(s.type===e.COLON){i+=s.value;continue}if(s.type===e.COMMA){let l=r[c+1];if(l&&(l.type==="}"||l.type==="]"))continue;i+=s.value;continue}if(s.type===e.STRING&&s.quoted){let l=s.value;s.sourceQuote==="'"&&(l=l.replace(/\\'/g,"'"),l=l.replace(/(\\*)"/g,(f,u)=>u.length%2===0?u+'\\"':f)),i+=`"${l}"`;continue}if(s.type===e.NUMBER||s.type===e.BOOLEAN){i+=s.value;continue}if(s.type===e.SELECTOR||s.type===e.IDENTIFIER){i+=`"${s.value}"`;continue}i+=`"${s.value}"`}return i}try{let r=n(t),i=o(r);return JSON.parse(i)}catch(r){throw new A("Invalid extraction rules syntax: "+r.message,r)}}var wt="1",ct=/^[a-zA-Z0-9_-]+$/;function x(t,e,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!ct.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${ct})`);o=`script[data-rules-name~="${n}"]`}let r=t.find(e,o,{includeRulesTag:!0});if(r.length===0)return null;n!==void 0&&r.length>1&&console.warn(`hyper-html-api: ${r.length} rules tags match data-rules-name~="${n}"; using the first.`);let i=r[0],c=t.attr(i,"data-rules-version");if(c!==wt)throw new b(c);return{rules:P(t.text(i)),tagNode:i}}function X(t,e,n){if(n&&typeof n=="object")return{rules:n,tagNode:null};if(typeof n=="string"){let o=e&&e.ownerDocument?e.ownerDocument:e;return x(t,o,n)}return null}function ft(t,e,n,o){let r=X(t,e,n);if(!r){let s=typeof n=="string"?`data-rules-name~="${n}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${s}`)}let{rules:i,tagNode:c}=r;return{rules:i,tagNode:c,get:()=>g(t,e,i,o),set:s=>S(t,e,i,s,o)}}function _t(t){return t&&t.nodeType===1&&t.tagName==="SCRIPT"&&t.hasAttribute&&t.hasAttribute("data-rules-name")}function Dt(t){return t?(t.nodeType===9||t.nodeType===11,t):null}var Pt={find(t,e,n={}){let o=Dt(t);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(e));n.includeRulesTag||(r=r.filter(s=>!_t(s)));let i=[];n.skip&&i.push(n.skip);let c=n.templateAttr===null?null:n.templateAttr||"cms-template";if(c&&i.push("["+c+"]"),i.length){let s=i.join(", ");r=r.filter(l=>!l.closest||!l.closest(s))}return r},parent(t){return t?t.parentElement:null},children(t){return t?Array.from(t.children):[]},text(t,e){if(e===void 0)return(t.textContent||"").trim();t.textContent=e},attr(t,e,n){if(n===void 0)return t.hasAttribute&&t.hasAttribute(e)?t.getAttribute(e):null;t.setAttribute(e,n)},removeAttr(t,e){t&&t.removeAttribute&&t.removeAttribute(e)},prop(t,e,n){if(n===void 0){let o=t?t[e]:void 0;return o!==void 0?o:null}t[e]=n},clone(t){return t.cloneNode(!0)},insertAt(t,e,n){let o=t.children[n]||null;t.insertBefore(e,o)},remove(t){t&&t.parentNode&&t.parentNode.removeChild(t)},replaceWith(t,e){if(!t||!t.parentNode)throw new Error("dom.replaceWith: node has no parent");let o=t.ownerDocument.createElement("template");o.innerHTML=e;let r=o.content.firstElementChild;if(!r)throw new Error("dom.replaceWith: html did not parse to an element");return t.parentNode.replaceChild(r,t),r},stripIds(t){let e=0;return t.id&&(t.removeAttribute("id"),e++),(t.querySelectorAll?t.querySelectorAll("[id]"):[]).forEach(o=>{o.removeAttribute("id"),e++}),e},sameNode(t,e){return t===e}},d=Pt;var L={extract:(t,e,n)=>g(d,t,e,n),apply:(t,e,n,o)=>S(d,t,e,n,o),findRulesIn:(t,e)=>x(d,t,e),findRules:(t,e)=>X(d,t,e),bind:(t,e,n)=>ft(d,t,e,n),parseStrict:G,parseRelaxed:P,ruleAttrIndex:m,splitRule:v,errors:$,DOM_PROPERTIES:j},z=t=>!!t&&typeof t.nodeType=="number";function ut(t){let e=t&&t.ownerDocument?t.ownerDocument:t,n=d.find(e,"script[data-rules-name]",{includeRulesTag:!0});if(n.length===0)throw new Error('hyper-html-api: no rules tag found. Add <script type="application/json" data-rules-name="\u2026" data-rules-version="1"> or pass rules.');if(n.length>1)throw new Error('hyper-html-api: multiple rules tags found; pass a name, e.g. extractData("api").');return x(d,e).rules}function K(t,e){let n=z(t)?t:document,o=z(t)?e:t;return o===void 0?g(d,n,ut(n)):L.bind(n,o).get()}function Y(t,e,n){if(!z(t))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");return n===void 0?S(d,t,ut(t),e):L.bind(t,n).set(e),t}var Lt={engine:L,extractData:K,applyData:Y},Ct=Lt;return yt(jt);})();
|