hyper-html-api 0.10.1 → 0.11.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.
@@ -1,2 +1,2 @@
1
- var hyperHtmlApiUpgrade=(()=>{var ie=Object.defineProperty;var Ge=Object.getOwnPropertyDescriptor;var Xe=Object.getOwnPropertyNames;var Ze=Object.prototype.hasOwnProperty;var Ee=(e,t)=>{for(var n in t)ie(e,n,{get:t[n],enumerable:!0})},Qe=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Xe(t))!Ze.call(e,r)&&r!==n&&ie(e,r,{get:()=>t[r],enumerable:!(o=Ge(t,r))||o.enumerable});return e};var et=e=>Qe(ie({},"__esModule",{value:!0}),e);var Dt={};Ee(Dt,{default:()=>Pt,engine:()=>we,upgrade:()=>Je});var Y=["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"],se=new Set(Y),Oe=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),G=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var Z={};Ee(Z,{EmptyListInsert:()=>U,MAX_RULE_DEPTH:()=>_,MaxRuleDepthExceeded:()=>k,NoRulesTag:()=>ce,RuleTargetReadOnly:()=>H,RulesParseError:()=>D,ShapeMismatch:()=>W,UnknownRulesVersion:()=>j,WriteRefused:()=>X,WriteRejected:()=>le});var D=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},j=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},_=20,k=class extends Error{constructor(t){super(`rule depth exceeded ${_} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},W=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},U=class extends Error{constructor(t){super(`cannot add items to empty list at "${t.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=t}},H=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}},X=class extends Error{constructor(t){super(`write refused: ${t.length} write(s) broke the content-only policy`),this.name="WriteRefused",this.refusals=t}},ce=class extends Error{constructor(t){super(`no <script data-rules-name~="${t}"> rules tag in this document`),this.name="NoRulesTag",this.token=t}},le=class extends Error{constructor(t,n){super(`write rejected: ${t.length} unknown key(s), ${n.length} rule(s) with no matching element`),this.name="WriteRejected",this.unknownKeys=t,this.unmatched=n}};function R(e){let t=0,n=null,o=-1;for(let r=0;r<e.length;r++){let i=e[r];i==="\\"?r++:n?i===n&&(n=null):i==='"'||i==="'"?n=i:i==="["||i==="("?t++:i==="]"||i===")"?t>0&&t--:i==="@"&&t===0&&(o=r)}return o}function fe(e){let t=R(e);return t===-1?{selector:e,prop:null}:{selector:e.slice(0,t),prop:e.slice(t+1)||null}}function C(e,t,n,o={}){if(Object.prototype.hasOwnProperty.call(o,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");return ue(e,t,n,{depth:0,path:[]},o)}function ue(e,t,n,o,r){if(o.depth>_)throw new k(o.path);if(typeof n=="string")return tt(e,t,n,o,r);if(Array.isArray(n)){let[i,l]=n,s=e.find(t,i,r);return Se(r,o,s),s.map((c,d)=>ue(e,c,l,{depth:o.depth+1,path:[...o.path,d]},r))}if(typeof n=="object"&&n!==null){let i={};for(let[l,s]of Object.entries(n))i[l]=ue(e,t,s,{depth:o.depth+1,path:[...o.path,l]},r);return i}return null}function tt(e,t,n,o,r){if(n.endsWith("[]")){let s=n.slice(0,-2),c=e.find(t,s,r);return Se(r,o,c),c.map(d=>e.text(d))}if(n.startsWith("@"))return be(e,t,n.slice(1));let i=R(n);if(i!==-1){let s=n.slice(0,i),c=n.slice(i+1),d=s?e.find(t,s,r):[t];return d.length===0?null:be(e,d[0],c)}if(n===".")return e.text(t);let l=e.find(t,n,r);return l.length===0?null:e.text(l[0])}function Se(e,t,n){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),n)}catch(o){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,o)}}function be(e,t,n){if(se.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let o=e.attr(t,n);return o||null}function Ne(e,t,n,o){let r=e.length,i=t.length,l=new Array(r).fill(-1);if(o){let u=new Set;for(let m=0;m<r;m++){let w=o[m];!(w>=0&&w<i)||u.has(w)||(l[m]=w,u.add(w))}}if(r===0||i===0)return l;let s=e.map(u=>Re(u,n)),c=t.map(u=>Re(u,n)),d=new Array(i).fill(!1);for(let u of l)u>=0&&(d[u]=!0);let a=new Map;c.forEach((u,m)=>{d[m]||a.set(u,a.has(u)?-1:m)});let y=new Map;s.forEach((u,m)=>{l[m]>=0||y.set(u,(y.get(u)||0)+1)}),s.forEach((u,m)=>{if(l[m]>=0||y.get(u)!==1)return;let w=a.get(u);w===void 0||w===-1||d[w]||(l[m]=w,d[w]=!0)});let h=[];for(let u=0;u<r;u++)l[u]<0&&h.push(u);let x=[];for(let u=0;u<i;u++)d[u]||x.push(u);if(h.length===0||x.length===0)return l;let f=r*i+1,p=nt(e,t,n),g=(u,m)=>p(u,m)*f+Math.abs(u-m);for(let[u,m]of rt(h,x,g))l[u]=m;return l}var Me=e=>typeof e=="object"&&e!==null;function Re(e,t){if(!Me(t))return e==null?" null":String(e);let n=Object.keys(t);return JSON.stringify(n.map(o=>{let r=JSON.stringify(e?.[o]);return r===void 0?" undef":r}))}function nt(e,t,n){if(!Me(n))return(s,c)=>e[s]===t[c]?0:1;let o=Object.keys(n),r=s=>o.map(c=>JSON.stringify(s?.[c])),i=e.map(r),l=t.map(r);return(s,c)=>{let d=i[s],a=l[c],y=0;for(let h=0;h<o.length;h++)d[h]!==a[h]&&y++;return y}}function rt(e,t,n){return e.length<=t.length?Ce(e,t,n,!1):Ce(t,e,(o,r)=>n(r,o),!0)}function Ce(e,t,n,o){let r=e.length,i=t.length,l=[];for(let y=0;y<=r;y++)l.push(new Float64Array(i+1).fill(1/0));let s=[];for(let y=0;y<=r;y++)s.push(new Uint8Array(i+1));for(let y=0;y<=i;y++)l[r][y]=0;for(let y=r-1;y>=0;y--)for(let h=i-1;h>=0;h--){let x=n(e[y],t[h])+l[y+1][h+1],f=l[y][h+1];x<=f?(l[y][h]=x,s[y][h]=1):l[y][h]=f}let c=[],d=0,a=0;for(;d<r&&a<i;)s[d][a]&&(c.push(o?[t[a],e[d]]:[e[d],t[a]]),d++),a++;return c}function de(e,t,n,o,r,i,l,s={}){let c=e.find(t,n,s);if(r.length===0){c.forEach(T=>e.remove(T)),ae(s,"onRowsApplied",i.path,[]);return}let d=r.length>c.length,a=c[0]||null;if(d&&!a&&(a=ct(e,t,n,s),!a))throw new U(i.path);let y=c.map(T=>st(e,T,o,s)),h=null;if(d&&a){h=e.clone(a),s.templateAttr&&e.removeAttr(h,s.templateAttr);let T=e.stripIds(h);T>0&&console.warn(`[hyper-html-api] stripped ${T} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let x=Ne(r,y,o,ot(e,c,r,i,s)),f=c[0]||a,p=e.parent(f),g=c.length>0?je(e,p,f):0,u=ft(e,c),m=new Set,w=[],A=r.map((T,O)=>{let E=x[O];if(E>=0)return m.add(E),w.push(!1),c[E];w.push(!0);let M=e.clone(h);return e.stripIds(M),M});c.forEach((T,O)=>{m.has(O)||e.remove(T)}),u?lt(e,p,g,A,w):ut(e,A,w,p,g),it(e,A,o,r,i,l,s),ae(s,"onRowsApplied",i.path,A)}function ae(e,t,n,o){if(typeof e[t]=="function")try{return e[t](n.slice(),o)}catch(r){console.warn(`[hyper-html-api] ${t} threw at "${n.join(".")||"(root)"}"`,r);return}}function ot(e,t,n,o,r){let i=ae(r,"identifyRows",o.path,n);if(!Array.isArray(i))return null;let l=new Array(n.length).fill(-1),s=new Set,c=new Map(t.map((d,a)=>[e.identity(d),a]));for(let d=0;d<n.length;d++){if(!i[d])continue;let a=c.get(e.identity(i[d]));a===void 0||s.has(a)||(l[d]=a,s.add(a))}return l}function it(e,t,n,o,r,i,l){t.forEach((s,c)=>{if(n===null){let d=o[c],a=d==null?"":String(d);e.text(s)!==a&&e.text(s,a)}else{let d=i(e,s,n,o[c],{depth:r.depth+1,path:[...r.path,c]},l);d&&d!==s&&(t[c]=d)}})}function st(e,t,n,o){return n===null?e.text(t):C(e,t,n,o.onRowsRead?{...o,onRowsRead:void 0}:o)}function je(e,t,n){let o=e.children(t);for(let r=0;r<o.length;r++)if(e.sameNode(o[r],n))return r;return-1}function ct(e,t,n,o){if(!o.templateAttr)return null;let r=t;for(;r;){let i=e.find(r,n,{includeRulesTag:!1,templateAttr:null});for(let l of i)if(e.attr(l,o.templateAttr)!=null)return l;r=e.parent(r)}return null}function lt(e,t,n,o,r){let i=e.children(t),l=i.map(c=>e.identity(c)),s=!1;o.forEach((c,d)=>{let a=e.identity(c),y=n+d;if(l[y]===a)return;if(!r[d]){let x=l.indexOf(a);x!==-1&&(l.splice(x,1),i.splice(x,1))}let h=Math.min(y,i.length);h<i.length?e.insertBefore(i[h],c):i.length?s?e.insertAfter(i[i.length-1],c):(e.insertAt(t,c,y),s=!0):e.insertAt(t,c,0),l.splice(h,0,a),i.splice(h,0,c)})}function ft(e,t){if(t.length<=1)return!0;let n=e.parent(t[0]);if(!n)return!1;let o=new Map(e.children(n).map((i,l)=>[e.identity(i),l])),r=[];for(let i of t){let l=o.get(e.identity(i));if(l===void 0)return!1;r.push(l)}return r.sort((i,l)=>i-l),r[r.length-1]-r[0]===r.length-1}function ut(e,t,n,o,r){let i=null,l=r;for(let s=0;s<t.length;s++){if(!n[s]){i=t[s];continue}let c=i?e.parent(i):o;if(!c)continue;let d=i?je(e,c,i)+1:l++;e.insertAt(c,t[s],d),i=t[s]}}var ke=new Set(["checked","selected","disabled","readOnly","paused"]);function I(e,t,n,o,r={}){if(Object.prototype.hasOwnProperty.call(r,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");let i=[];if(pe(n,o,[],i),i.length)throw new W(i);Q(e,t,n,o,{depth:0,path:[]},r)}function Q(e,t,n,o,r,i={}){if(r.depth>_)throw new k(r.path);if(o===void 0)return t;if(typeof n=="string")return at(e,t,n,o,r,i);if(Array.isArray(n)){let[l,s]=n;return de(e,t,l,s,o,r,Q,i),t}if(typeof n=="object"&&n!==null){for(let[l,s]of Object.entries(n)){let c=Q(e,t,s,o==null?o:o[l],{depth:r.depth+1,path:[...r.path,l]},i);c&&c!==t&&(t=c)}return t}return t}function at(e,t,n,o,r,i){if(n.endsWith("[]")){let c=n.slice(0,-2);return de(e,t,c,null,o,r,Q,i),t}if(n.startsWith("@"))return Le(e,t,n.slice(1),o);let l=R(n);if(l!==-1){let c=n.slice(0,l),d=n.slice(l+1),a=c?e.find(t,c,i):[t];return a.length===0||Le(e,a[0],d,o),t}if(n===".")return Ie(e,t,o),t;let s=e.find(t,n,i);return s.length===0||Ie(e,s[0],o),t}function Ie(e,t,n){let o=n==null?"":String(n);e.text(t)!==o&&e.text(t,o)}function Le(e,t,n,o){if(G.has(n)){let i=e.prop(t,n);if(i===o||i!=null&&o!=null&&String(i)===String(o))return t;throw new H(n)}if(n==="outerHTML"){let i=o==null?"":String(o);return e.replaceWith(t,i)}if(Oe.has(n)){let i=dt(n,o);return e.prop(t,n)!==i&&e.prop(t,n,i),t}let r=o==null?"":String(o);return e.attr(t,n)!==r&&e.attr(t,n,r),t}function dt(e,t){return t==null?ke.has(e)?!1:"":ke.has(e)?t==="false"?!1:!!t:t}function pe(e,t,n,o){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((r,i)=>{typeof r=="object"&&r!==null&&o.push({path:B([...n,i]),expected:"scalar",got:v(r)})}):o.push({path:B(n),expected:"array",got:v(t)});return}t!==null&&typeof t=="object"&&o.push({path:B(n),expected:"scalar",got:v(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:B(n),expected:"array",got:v(t)});return}let r=e[1];t.forEach((i,l)=>pe(r,i,[...n,l],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:B(n),expected:"object",got:v(t)});return}for(let[r,i]of Object.entries(e))pe(i,t[r],[...n,r],o)}}}function v(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function B(e){return e.join(".")}function he(e){try{return JSON.parse(e)}catch(t){throw new D(`Invalid strict JSON: ${t.message}`,t)}}function L(e){try{return JSON.parse(e)}catch{}let t={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=[],l=0;for(;l<r.length;){let s=r[l];if(/\s/.test(s)){l++;continue}if("{}".includes(s)){i.push({type:s,value:s}),l++;continue}if(s==="["){let y=!1,h=l+1;for(;h<r.length&&/\s/.test(r[h]);)h++;if(h<r.length&&/[a-zA-Z_]/.test(r[h])&&(y=!0),!y){i.push({type:s,value:s}),l++;continue}}if(s==="]"){i.push({type:s,value:s}),l++;continue}if(s===":"){i.push({type:t.COLON,value:s}),l++;continue}if(s===","){i.push({type:t.COMMA,value:s}),l++;continue}if(s==='"'||s==="'"){let y=s,h=l+1;for(;h<r.length&&r[h]!==y;)r[h]==="\\"&&h++,h++;i.push({type:t.STRING,value:r.substring(l+1,h),quoted:!0,sourceQuote:y}),l=h+1;continue}let c=l,d;for(;c<r.length&&!/[{},]/.test(r[c]);)if(r[c]===":"){let y=[":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 x of y){let f=x.substring(1);if(r.substring(c+1,c+1+f.length)===f){h=!0,c+=f.length;break}}if(!h)break}else if(r[c]==="["){for(c++;c<r.length&&r[c]!=="]";){if(r[c]==='"'||r[c]==="'"){let y=r[c];for(c++;c<r.length&&r[c]!==y;)r[c]==="\\"&&c++,c++}c++}c<r.length&&r[c]==="]"&&c++}else c++;d=r.substring(l,c);let a=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(d)?a=t.NUMBER:d==="true"||d==="false"||d==="null"?a=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(d)&&(a=t.SELECTOR),i.push({type:a,value:d,quoted:!1}),l=c}return i}function o(r){let i="";for(let l=0;l<r.length;l++){let s=r[l];if("{}".includes(s.type)||"[]".includes(s.type)){i+=s.value;continue}if(s.type===t.COLON){i+=s.value;continue}if(s.type===t.COMMA){let c=r[l+1];if(c&&(c.type==="}"||c.type==="]"))continue;i+=s.value;continue}if(s.type===t.STRING&&s.quoted){let c=s.value;s.sourceQuote==="'"&&(c=c.replace(/\\'/g,"'"),c=c.replace(/(\\*)"/g,(d,a)=>a.length%2===0?a+'\\"':d)),i+=`"${c}"`;continue}if(s.type===t.NUMBER||s.type===t.BOOLEAN){i+=s.value;continue}if(s.type===t.SELECTOR||s.type===t.IDENTIFIER){i+=`"${s.value}"`;continue}i+=`"${s.value}"`}return i}try{let r=n(e),i=o(r);return JSON.parse(i)}catch(r){throw new D("Invalid extraction rules syntax: "+r.message,r)}}var me="1",Pe=/^[a-zA-Z0-9_-]+$/;function q(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!Pe.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${Pe})`);o=`script[data-rules-name~="${n}"]`}let r=e.find(t,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],l=e.attr(i,"data-rules-version");if(l!==me)throw new j(l);return{rules:L(e.text(i)),tagNode:i}}var ee=Object.freeze({data:Object.freeze({tokens:["no-data"],bundles:["editor-ui"]}),save:Object.freeze({tokens:["no-save"],bundles:["editor-ui"]}),snapshot:Object.freeze({tokens:["no-snapshot"],bundles:["editor-ui"]}),watch:Object.freeze({tokens:["no-watch"],bundles:["editor-ui"]}),undo:Object.freeze({tokens:["no-undo"],bundles:["editor-ui"]}),history:Object.freeze({tokens:[],bundles:["editor-ui"]})}),pt=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),De=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui","live"]);function K(e,t){if(!e||e.nodeType!==1)return!1;let n=e.getAttribute?.("clay");return!!(n&&n.split(/\s+/).includes(t)||e.hasAttribute?.(t))}function ye(e,t){if(K(e,t))return!0;for(let[n,o]of Object.entries(pt))if(o.includes(t)&&K(e,n))return!0;return!1}function z(e){let t=ee[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}function ht(e,t){let n=e&&e.nodeType===1?e:e?.parentElement;for(;n&&n.nodeType===1;){let o=ee[t];if(!o)throw new Error(`Unknown region capability: ${t}`);if(o.tokens.some(r=>ye(n,r))||o.bundles.some(r=>K(n,r)))return n;n=n.parentElement}return null}function _e(e,t){return!!ht(e,t)}var mt=Object.freeze({refusedRuleForms:["innerHTML","outerHTML"],refusedTargets:["script","style","template","noscript","iframe","object","embed","xmp","plaintext","noembed","noframes","meta","link","base","animate","set","animatemotion","animatetransform"],refusedAttributes:["style","srcdoc","is","http-equiv","sandbox","allow","nonce","integrity","charset","htmlclaytoken","htmlclayid","data-rules-name","data-rules-version","clay","contenteditable",...De],refusedAttributePrefixes:["on"],urlAttributes:["href","src","srcset","action","formaction","poster","cite","data","ping","background","longdesc","usemap","xlink:href","manifest","codebase","icon"],refusedSchemes:["javascript","vbscript","data"]});function ge(e,t,n){if(n&&typeof n=="object")return{rules:n,tagNode:null};if(typeof n=="string"){let o=t&&t.ownerDocument?t.ownerDocument:t;return q(e,o,n)}return null}var At=/:(?:focus(?:-within|-visible)?|hover|active|visited|defined)\b/i;function Tt(e,t){if(!/^(INPUT|TEXTAREA|SELECT|OPTION)$/.test(e.tagName||""))return;let n=(e.getAttribute?.("type")||"").toLowerCase();"value"in e&&"value"in t&&e.tagName!=="OPTION"&&n!=="checkbox"&&n!=="radio"&&n!=="file"&&(t.value=e.value),e.tagName==="INPUT"&&(n==="checkbox"||n==="radio")&&(t.checked=e.checked),e.tagName==="OPTION"&&(t.selected=e.selected),"indeterminate"in e&&"indeterminate"in t&&(t.indeterminate=e.indeterminate)}function $e(e,t,n,o){if(o)return!!e.closest?.(t);let r=e;for(;r?.nodeType===1;){if(r.matches(t))return!0;if(r===n)break;r=r.parentElement}return!1}function We(e,t,n,o,r,i){return(i?_e(e,t):$e(e,n,r,!1))||!!(o&&(i&&e!==r?e.matches(o):$e(e,o,r,i)))}function xt(e,t){let n=ee[t];return n.tokens.some(o=>ye(e,o))||n.bundles.some(o=>K(e,o))}var Et=new Set(["INPUT","TEXTAREA","SELECT","OPTION"]);function Ue(e,t,n,o){if(e.nodeType===1&&o(e)){n.dropped.push(t);return}n.cloneToLive.set(t,e),n.liveToClone.set(e,t);let r=e,i=t;if(e.nodeType===1){if(Et.has(e.tagName)&&n.controls.push(e,t),e.tagName==="TEMPLATE"){for(;t.firstChild;)t.removeChild(t.firstChild);r=e.content,i=t.content,n.cloneToLive.set(i,r),n.liveToClone.set(r,i)}}else if(e.nodeType!==11)return;let l=i.firstChild;for(let s=r.firstChild;s&&l;s=s.nextSibling)Ue(s,l,n,o),l=l.nextSibling}function F(e,{capability:t="data",exclude:n=null,inherit:o=!0,provenance:r=null}={}){if(!e)throw new TypeError("createContentView requires a DOM context");let i=e.nodeType===9?e:e.ownerDocument;if(!i?.implementation?.createHTMLDocument)throw new TypeError("createContentView requires an HTML DOM implementation");let l=i.implementation.createHTMLDocument(""),s=r||new WeakMap,c=new WeakMap,d=e.nodeType===9?e.documentElement:e;n&&l.documentElement.matches(n);let a=z(t),y=o?f=>xt(f,t)||!!(n&&f.matches(n)):f=>We(f,t,a,n,d,!1),h=null;if(d.nodeType!==1||!We(d,t,a,n,d,o)){h=l.importNode(d,!0);let f={cloneToLive:s,liveToClone:c,dropped:[],controls:[]};Ue(d,h,f,y);for(let p of f.dropped)p.remove();for(let p=0;p<f.controls.length;p+=2)Tt(f.controls[p],f.controls[p+1])}e.nodeType===9&&h&&(l.replaceChild(h,l.documentElement),c.set(e,l),s.set(l,e));let x=f=>{if(At.test(f))throw new Error(`Filtered content queries do not support stateful selector: ${f}`)};return{root:h,document:l,capability:t,selector:z(t),cloneToLive:s,liveToClone:c,original(f){return s.get(f)||null},cloneOf(f){return c.get(f)||null},query(f,p=h){return x(f),Array.from(p.querySelectorAll(f),g=>s.get(g)||g)},text(f=h){return(f===h?h:c.get(f))?.textContent||""},html(f=h){return(f===h?h:c.get(f))?.innerHTML??""},clone(f=h){let p=f===h?h:c.get(f);return p?l.importNode(p,!0):null}}}function He(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function Ot(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var b={semanticExclude:!0,find(e,t,n={}){let o=Ot(e);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(t));n.includeRulesTag||(r=r.filter(s=>!He(s)));let i=[];n.skip&&i.push(n.skip);let l=n.templateAttr===null?null:n.templateAttr||"cms-template";if(l&&i.push("["+l+"]"),i.length){let s=i.join(", ");r=r.filter(c=>!c.closest||!c.closest(s))}return r},parent(e){return e?e.parentElement:null},children(e){return e?Array.from(e.children):[]},text(e,t){if(t===void 0)return(e.textContent||"").trim();e.textContent=t},attr(e,t,n){if(n===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,n)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t)},prop(e,t,n){if(n===void 0){let o=e?e[t]:void 0;return o!==void 0?o:null}e[t]=n},clone(e){return e.cloneNode(!0)},insertAt(e,t,n){let o=e.children[n]||null;e.insertBefore(t,o)},insertBefore(e,t){e.parentNode.insertBefore(t,e)},insertAfter(e,t){e.parentNode.insertBefore(t,e.nextSibling)},identity(e){return e||null},remove(e){e&&e.parentNode&&e.parentNode.removeChild(e)},replaceWith(e,t){if(!e||!e.parentNode)throw new Error("dom.replaceWith: node has no parent");let o=e.ownerDocument.createElement("template");o.innerHTML=t;let r=o.content.firstElementChild;if(!r)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(r,e),r},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(o=>{o.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}};function V(e,t={}){if(t.exclude===null)return b;let n=[z("data"),t.exclude].filter(Boolean).join(", "),o=e.nodeType===9?e:e.ownerDocument||e,r=e.nodeType===9?e.documentElement:e;if(!t._write&&!r?.matches?.(n)&&!r?.querySelector?.(n)&&!o?.querySelector?.(n))return b;let i=e.nodeType===9||!e.isConnected?e:e.ownerDocument,l=e.nodeType===9?e:e.ownerDocument,s=null,c=()=>s||(s=F(i,{capability:"data",exclude:t.exclude||null})),d=f=>{let p=c();return f===e?p.cloneOf(e):p.cloneOf(f)||f},a=f=>s?.original(f)||f,y=(f,p)=>{c().liveToClone.set(f,p),c().cloneToLive.set(p,f);let g=f.childNodes||[],u=p.childNodes||[];for(let m=0;m<Math.min(g.length,u.length);m++)y(g[m],u[m])},h=(f,p,g,u)=>{let m=Array.from(f.childNodes).filter(E=>s.cloneOf(E)),A=m[0];for(;A&&m.includes(A);)A=A.nextSibling;for(let E of m)E.remove();if(g==="innerHTML"){let E=l.createElement("template");E.innerHTML=u;for(let M of Array.from(E.content.childNodes))f.insertBefore(M,A||null)}else f.insertBefore(l.createTextNode(u),A||null);let T=F(f,{capability:"data",exclude:t.exclude||null});p.replaceChildren(...Array.from(T.root?.childNodes||[]));let O=E=>{let M=T.original(E);M&&(s.liveToClone.set(M,E),s.cloneToLive.set(E,M));for(let Ye of Array.from(E.childNodes||[]))O(Ye)};for(let E of Array.from(p.childNodes))O(E)},x={...b,find(f,p,g={}){let u=d(f);if(!u?.querySelectorAll)return[];let m=c().query(p,u);g.includeRulesTag||(m=m.filter(T=>!He(T)));let w=[];g.skip&&w.push(g.skip);let A=g.templateAttr===null?null:g.templateAttr||"cms-template";if(A&&w.push(`[${A}]`),w.length){let T=w.join(", ");m=m.filter(O=>!O.closest?.(T))}return m},parent(f){let p=d(f)?.parentElement;return p?a(p):null},children(f){return Array.from(d(f)?.children||[],a)},text(f,p){if(p===void 0){let m=a(f);return!m?.matches?.(n)&&!m?.querySelector?.(n)?b.text(m):(d(f)?.textContent||"").trim()}let g=a(f);if(!g?.matches?.(n)&&!g?.querySelector?.(n)&&!s){b.text(g,p);return}let u=c().cloneOf(g);u?h(g,u,"textContent",p):b.text(g,p)},attr(f,p,g){let u=a(f);if(g===void 0)return b.attr(u,p);b.attr(u,p,g);let m=s?.cloneOf(u);m&&(b.attr(m,p,g),F(u,{capability:"data",exclude:t.exclude||null}).root===null&&(m.remove(),s.liveToClone.delete(u),s.cloneToLive.delete(m)))},removeAttr(f,p){let g=a(f);b.removeAttr(g,p);let u=s?.cloneOf(g);u&&b.removeAttr(u,p)},prop(f,p,g){let u=a(f);if(g===void 0)return p==="innerHTML"||p==="outerHTML"||p==="textContent"||p==="innerText"?b.prop(d(u),p):b.prop(u,p);let m=p==="innerHTML"||p==="textContent"||p==="innerText",w=m?c().cloneOf(u):s?.cloneOf(u);w&&m?h(u,w,p,g):(b.prop(u,p,g),w&&b.prop(w,p,g))},clone(f){let p=d(f);return p===f?b.clone(f):l.importNode(p,!0)},insertAt(f,p,g){let u=a(f),w=x.children(u)[g]||(()=>{for(let O=u.children.length-1;O>=0;O--){let E=u.children[O];if(c().cloneOf(E))return E.nextElementSibling}return u.firstElementChild})(),A=a(p);u.insertBefore(A,w||null);let T=c().cloneOf(u);if(T){let O=c().cloneOf(A);O||(O=l.importNode(A,!0),y(A,O));let E=Array.from(T.children);T.insertBefore(O,E[g]||null)}},insertBefore(f,p){let g=a(f),u=a(p);g.parentNode.insertBefore(u,g);let m=c().cloneOf(g.parentNode);if(m){let w=c().cloneOf(u);w||(w=l.importNode(u,!0),y(u,w));let A=c().cloneOf(g);A?A.before(w):m.appendChild(w)}},insertAfter(f,p){let g=a(f),u=a(p);g.parentNode.insertBefore(u,g.nextSibling);let m=c().cloneOf(g.parentNode);if(m){let w=c().cloneOf(u);w||(w=l.importNode(u,!0),y(u,w));let A=c().cloneOf(g);A?A.after(w):m.appendChild(w)}},identity(f){return a(f)||null},remove(f){let p=a(f),g=c().cloneOf(p);b.remove(p),g&&b.remove(g)},replaceWith(f,p){let g=a(f),u=c().cloneOf(g),m=b.replaceWith(g,p);if(u){let w=F(m,{capability:"data",exclude:t.exclude||null});if(!w.root)u.remove();else{u.replaceWith(w.root);let A=T=>{let O=w.original(T);O&&(s.liveToClone.set(O,T),s.cloneToLive.set(T,O));for(let E of Array.from(T.childNodes||[]))A(E)};A(w.root)}}return m}};return x}var S=b;var we={extract:(e,t,n={})=>C(V(e,n),e,t,n),apply:(e,t,n,o={})=>I(V(e,{...o,_write:!0}),e,t,n,o),findRulesIn:(e,t)=>q(S,e,t),findRules:(e,t)=>ge(S,e,t),bind:(e,t,n={})=>{let o=ge(S,e,t);if(!o){let r=typeof t=="string"?`data-rules-name~="${t}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${r}`)}return{...o,get:()=>C(V(e,n),e,o.rules,n),set:r=>I(V(e,{...n,_write:!0}),e,o.rules,r,n)}},parseStrict:he,parseRelaxed:L,ruleAttrIndex:R,splitRule:fe,errors:Z,DOM_PROPERTIES:Y};var bt="hha:upgrade-check:";function N(e,t){let n=e.querySelector(`meta[name="${t}"]`),o=n?n.getAttribute("content"):null;return o&&o.trim()?o.trim():null}function ve(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function St(e,t){let n=ve(e),o=ve(t);if(!n||!o)return!1;let r=Math.max(n.length,o.length);for(let i=0;i<r;i++){let l=n[i]||0,s=o[i]||0;if(l!==s)return l>s}return!1}function Rt(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function Ct(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function Be({force:e=!1,doc:t,loc:n,fetchFn:o,now:r,ttlMs:i=864e5}={}){if(t=t||(typeof document<"u"?document:null),n=n||(typeof location<"u"?location:null),o=o||(h=>fetch(h)),r=r??Date.now(),!t)return null;let l=N(t,"hyper-source");if(!l)return null;let s=N(t,"hyper-version"),c;try{c=new URL(l,n?n.href:void 0)}catch{return null}if(n&&c.origin===n.origin&&c.pathname===n.pathname)return null;let d=`${bt}${c.href}:${s||"none"}`,a,y=e?null:Rt(d);if(y&&typeof y.checkedAt=="number"&&r-y.checkedAt<i)a=y.sourceVersion;else{try{let h=await o(c.href);if(!h.ok)throw new Error(`HTTP ${h.status}`);let x=await h.text(),f=new DOMParser().parseFromString(x,"text/html");a=N(f,"hyper-version")}catch{a=null}Ct(d,{checkedAt:r,sourceVersion:a})}return a?{available:St(a,s||"0.0.0"),currentVersion:s,sourceVersion:a,sourceUrl:c.href}:null}var Nt="script[data-rules-name]";function Mt(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function te(e,t){let n=e.find(t,Nt,{includeRulesTag:!0}),o=new Set,r=[];for(let i of n){let l=Mt(e.attr(i,"data-rules-name"));if(!l)continue;if(o.has(l)){console.warn(`hyper-html-api: duplicate rules tag name "${l}"; using the first.`);continue}let s=e.attr(i,"data-rules-version");if(s!==me)throw new j(s);o.add(l),r.push({name:l,rules:L(e.text(i))})}return r}function Ae(e,t){let n={};for(let{name:o,rules:r}of te(e,t))n[o]=C(e,t,r);return n}function qe(e){let t=e||document,n=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:Ae(S,t),version:N(n,"hyper-version")}}var J=class extends Error{constructor(t,n){super(`could not fetch upgrade source: ${t}`),this.name="UpgradeSourceUnreachable",this.sourceUrl=t,this.cause=n}},ne=class extends Error{constructor(t){super(`upgrade source has no rules tags; refusing to drop all existing data: ${t}`),this.name="UpgradeSourceHasNoRules",this.sourceUrl=t}},P=class extends Error{constructor(t,n){super(t),this.name="UpgradeTransformInvalid",this.cause=n}},re=class extends Error{constructor(t){super(`found ${t} script[type="text/hyper-upgrade"] tags; only one is allowed per document.`),this.name="UpgradeMultipleTransforms",this.count=t}};var jt="text/hyper-upgrade";function Ke(e,t){let n=e.find(t,`script[type="${jt}"]`);if(n.length===0)return null;if(n.length>1)throw new re(n.length);return e.text(n[0])||null}var kt=new Function("url","return import(url)");async function ze(e){let t=new Blob([e],{type:"text/javascript"}),n=URL.createObjectURL(t),o;try{o=await kt(n)}catch(r){throw new P(`transform failed to load: ${r&&r.message?r.message:r}`,r)}finally{URL.revokeObjectURL(n)}if(typeof o.default!="function")throw new P("transform must `export default` a function");return o.default}function oe(e,t){let n={carriedOver:0,discarded:0,listItems:0},o=Te(t,e,n);return xe(t,e,n),{data:o,summary:n}}function Te(e,t,n){if(typeof e=="string")return e.endsWith("[]")?Array.isArray(t)?(n.listItems+=t.length,n.carriedOver+=t.length,t):void 0:t==null||typeof t=="object"?void 0:(n.carriedOver++,t);if(Array.isArray(e)){let[,o]=e;return Array.isArray(t)?(n.listItems+=t.length,t.map(r=>Te(o,r,n))):void 0}if(typeof e=="object"&&e!==null){let o={};for(let[r,i]of Object.entries(e)){let l=Te(i,t?.[r],n);l!==void 0&&(o[r]=l)}return o}}function xe(e,t,n){if(t!=null){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){if(typeof t!="object"||Array.isArray(t))return;let o=new Set(Object.keys(e));for(let r of Object.keys(t))o.has(r)?xe(e[r],t[r],n):n.discarded+=$(t[r]);return}if(Array.isArray(e)&&Array.isArray(t)){let o=e[1];t.forEach(r=>xe(o,r,n));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(n.discarded+=$(t))}}function $(e){return e==null?0:Array.isArray(e)?e.reduce((t,n)=>t+$(n),0):typeof e=="object"?Object.values(e).reduce((t,n)=>t+$(n),0):1}function Fe(e,t,n){let o=te(e,t),r={carriedOver:0,discarded:0,listItems:0},i={},l=new Set;for(let{name:s,rules:c}of o){if(l.add(s),!Object.prototype.hasOwnProperty.call(n,s)){i[s]={carriedOver:0,discarded:0,listItems:0};continue}let{data:d,summary:a}=oe(n[s],c);I(e,t,c,d),i[s]=a,r.carriedOver+=a.carriedOver,r.discarded+=a.discarded,r.listItems+=a.listItems}for(let s of Object.keys(n))l.has(s)||(r.discarded+=$(n[s]));return{totals:r,byName:i,rulesTagCount:o.length}}async function Ve({sourceUrl:e,dataByName:t,fromVersion:n,doc:o,loc:r,fetchFn:i}={}){if(o=o||(typeof document<"u"?document:null),r=r||(typeof location<"u"?location:null),i=i||(u=>fetch(u)),!o)throw new Error("upgrade.run requires a document context");if(e=e||N(o,"hyper-source"),!e)throw new Error("upgrade.run: no sourceUrl given and no hyper-source meta tag found");let l=new URL(e,r?r.href:void 0);n=n!==void 0?n:N(o,"hyper-version"),t=t||Ae(S,o);let s;try{s=await i(l.href)}catch(u){throw new J(l.href,u)}if(!s.ok)throw new J(l.href,new Error(`HTTP ${s.status}`));let c=await s.text(),d=new DOMParser().parseFromString(c,"text/html"),a=N(d,"hyper-version"),y=t,h=!1,x=Ke(S,d);if(x){let m=await(await ze(x))(y,{fromVersion:n,toVersion:a});if(!m||typeof m!="object"||Array.isArray(m))throw new P("transform must return a plain object map of { rulesName: data }");y=m,h=!0}let{totals:f,byName:p,rulesTagCount:g}=Fe(S,d,y);if(g===0&&Object.keys(y).length>0)throw new ne(l.href);return{html:It(d),fromVersion:n,toVersion:a,summary:{transformApplied:h,totals:f,byName:p}}}function It(e){return`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
2
- `+e.documentElement.outerHTML}var Je={checkForUpdate:Be,run:Ve,extractAll:qe,shapeMatch:oe};var Lt={engine:we,upgrade:Je},Pt=Lt;return et(Dt);})();
1
+ var hyperHtmlApiUpgrade=(()=>{var ce=Object.defineProperty;var st=Object.getOwnPropertyDescriptor;var ct=Object.getOwnPropertyNames;var lt=Object.prototype.hasOwnProperty;var Re=(e,t)=>{for(var n in t)ce(e,n,{get:t[n],enumerable:!0})},ft=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ct(t))!lt.call(e,r)&&r!==n&&ce(e,r,{get:()=>t[r],enumerable:!(o=st(t,r))||o.enumerable});return e};var ut=e=>ft(ce({},"__esModule",{value:!0}),e);var Xt={};Re(Xt,{default:()=>Gt,engine:()=>Ee,upgrade:()=>ot});var Y=["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"],G=new Set(Y),le=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),X=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]),Ne=new Set(["checked","selected","disabled","readOnly","paused"]);function fe(e,t){return t==null?Ne.has(e)?!1:"":Ne.has(e)?t==="false"?!1:!!t:t}var ee={};Re(ee,{EmptyListInsert:()=>M,MAX_RULE_DEPTH:()=>$,MaxRuleDepthExceeded:()=>P,NoRulesTag:()=>ue,RuleTargetReadOnly:()=>v,RulesParseError:()=>_,ShapeMismatch:()=>U,UnknownRulesVersion:()=>k,WriteNotRoundTripped:()=>Q,WriteRefused:()=>Z,WriteRejected:()=>ae});var _=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},k=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},$=20,P=class extends Error{constructor(t){super(`rule depth exceeded ${$} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},U=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},M=class extends Error{constructor(t,n){super(n?`cannot add items to empty list at "${t.join(".")}" \u2014 ${n}`:`cannot add items to empty list at "${t.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=t}},v=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}},Z=class extends Error{constructor(t){super(`write refused: ${t.length} write(s) broke the content-only policy`),this.name="WriteRefused",this.refusals=t}};function at(e){return e.reduce((n,o)=>typeof o=="number"?`${n}[${o}]`:n?`${n}.${o}`:String(o),"")||"(root)"}var Q=class extends Error{constructor(t){super(`write did not round-trip at "${at(t)}"`),this.name="WriteNotRoundTripped",this.path=t}},ue=class extends Error{constructor(t){super(`no <script data-rules-name~="${t}"> rules tag in this document`),this.name="NoRulesTag",this.token=t}},ae=class extends Error{constructor(t,n){super(`write rejected: ${t.length} unknown key(s), ${n.length} rule(s) with no matching element`),this.name="WriteRejected",this.unknownKeys=t,this.unmatched=n}};function S(e){let t=0,n=null,o=-1;for(let r=0;r<e.length;r++){let i=e[r];i==="\\"?r++:n?i===n&&(n=null):i==='"'||i==="'"?n=i:i==="["||i==="("?t++:i==="]"||i===")"?t>0&&t--:i==="@"&&t===0&&(o=r)}return o}function de(e){let t=S(e);return t===-1?{selector:e,prop:null}:{selector:e.slice(0,t),prop:e.slice(t+1)||null}}function he(e){let t=0,n=null,o=-1,r=!1;for(let i=0;i<e.length;i++){let s=e[i];s==="\\"?i++:n?s===n&&(n=null):s==='"'||s==="'"?n=s:s==="["||s==="("?t++:s==="]"||s===")"?t>0&&t--:t===0&&s===">"?o=i:t===0&&s===","&&(r=!0)}return r||o===-1||!dt(e,o+1)?null:e.slice(0,o).trim()||null}function dt(e,t){let n=t,o=e.replace(/\s+$/,"").length;for(;n<o&&/\s/.test(e[n]);)n++;let r=0,i=null;for(;n<o;n++){let s=e[n];if(s==="\\")n++;else if(i)s===i&&(i=null);else if(s==='"'||s==="'")i=s;else if(s==="["||s==="(")r++;else if(s==="]"||s===")")r>0&&r--;else if(r===0&&(s==="+"||s==="~"||/\s/.test(s)))return!1}return!0}function N(e,t,n,o={}){if(Object.prototype.hasOwnProperty.call(o,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");return pe(e,t,n,{depth:0,path:[]},o)}function pe(e,t,n,o,r){if(o.depth>$)throw new P(o.path);if(typeof n=="string")return ht(e,t,n,o,r);if(Array.isArray(n)){let[i,s]=n,c=e.find(t,i,r);return Me(r,o,c),c.map((l,a)=>pe(e,l,s,{depth:o.depth+1,path:[...o.path,a]},r))}if(typeof n=="object"&&n!==null){let i={};for(let[s,c]of Object.entries(n))i[s]=pe(e,t,c,{depth:o.depth+1,path:[...o.path,s]},r);return i}return null}function ht(e,t,n,o,r){if(n.endsWith("[]")){let c=n.slice(0,-2),l=e.find(t,c,r);return Me(r,o,l),l.map(a=>e.text(a))}if(n.startsWith("@"))return Ce(e,t,n.slice(1));let i=S(n);if(i!==-1){let c=n.slice(0,i),l=n.slice(i+1),a=c?e.find(t,c,r):[t];return a.length===0?null:Ce(e,a[0],l)}if(n===".")return e.text(t);let s=e.find(t,n,r);return s.length===0?null:e.text(s[0])}function Me(e,t,n){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),n)}catch(o){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,o)}}function Ce(e,t,n){if(G.has(n)){let r=e.prop(t,n);return r==null?null:String(r)}let o=e.attr(t,n);return o??null}function Ie(e,t,n,o){let r=e.length,i=t.length,s=new Array(r).fill(-1);if(o){let u=new Set;for(let m=0;m<r;m++){let A=o[m];!(A>=0&&A<i)||u.has(A)||(s[m]=A,u.add(A))}}if(r===0||i===0)return s;let c=e.map(u=>ke(u,n)),l=t.map(u=>ke(u,n)),a=new Array(i).fill(!1);for(let u of s)u>=0&&(a[u]=!0);let d=new Map;l.forEach((u,m)=>{a[m]||d.set(u,d.has(u)?-1:m)});let y=new Map;c.forEach((u,m)=>{s[m]>=0||y.set(u,(y.get(u)||0)+1)}),c.forEach((u,m)=>{if(s[m]>=0||y.get(u)!==1)return;let A=d.get(u);A===void 0||A===-1||a[A]||(s[m]=A,a[A]=!0)});let p=[];for(let u=0;u<r;u++)s[u]<0&&p.push(u);let T=[];for(let u=0;u<i;u++)a[u]||T.push(u);if(p.length===0||T.length===0)return s;let f=r*i+1,h=pt(e,t,n),g=(u,m)=>h(u,m)*f+Math.abs(u-m);for(let[u,m]of mt(p,T,g))s[u]=m;return s}var Le=e=>typeof e=="object"&&e!==null;function ke(e,t){if(!Le(t))return e==null?" null":String(e);let n=Object.keys(t);return JSON.stringify(n.map(o=>{let r=JSON.stringify(e?.[o]);return r===void 0?" undef":r}))}function pt(e,t,n){if(!Le(n))return(c,l)=>e[c]===t[l]?0:1;let o=Object.keys(n),r=c=>o.map(l=>JSON.stringify(c?.[l])),i=e.map(r),s=t.map(r);return(c,l)=>{let a=i[c],d=s[l],y=0;for(let p=0;p<o.length;p++)a[p]!==d[p]&&y++;return y}}function mt(e,t,n){return e.length<=t.length?Pe(e,t,n,!1):Pe(t,e,(o,r)=>n(r,o),!0)}function Pe(e,t,n,o){let r=e.length,i=t.length,s=[];for(let y=0;y<=r;y++)s.push(new Float64Array(i+1).fill(1/0));let c=[];for(let y=0;y<=r;y++)c.push(new Uint8Array(i+1));for(let y=0;y<=i;y++)s[r][y]=0;for(let y=r-1;y>=0;y--)for(let p=i-1;p>=0;p--){let T=n(e[y],t[p])+s[y+1][p+1],f=s[y][p+1];T<=f?(s[y][p]=T,c[y][p]=1):s[y][p]=f}let l=[],a=0,d=0;for(;a<r&&d<i;)c[a][d]&&(l.push(o?[t[d],e[a]]:[e[a],t[d]]),a++),d++;return l}function ye(e,t,n,o,r,i,s,c={}){let l=e.find(t,n,c);if(r.length===0){l.forEach(w=>e.remove(w)),me(c,"onRowsApplied",i.path,[]);return}let a=r.length>l.length,d=l[0]||null;if(a&&!d&&(d=wt(e,t,n,c),!d))throw new M(i.path);let y=l.map(w=>At(e,w,o,c)),p=null;if(a&&d){p=e.clone(d),c.templateAttr&&e.removeAttr(p,c.templateAttr);let w=e.stripIds(p);w>0&&console.warn(`[hyper-html-api] stripped ${w} id attribute(s) from cloned template at "${i.path.join(".")||"(root)"}"`)}let T=Ie(r,y,o,yt(e,l,r,i,c)),f=l.length>0?e.parent(l[0]):Ot(e,t,n,d,i,c),h=l.length>0?We(e,f,l[0]):0,g=Rt(e,l),u=new Set,m=[],A=r.map((w,b)=>{let E=T[b];if(E>=0)return u.add(E),m.push(!1),l[E];m.push(!0);let x=e.clone(p);return e.stripIds(x),x});l.forEach((w,b)=>{u.has(b)||e.remove(w)}),g?St(e,f,h,A,m):Nt(e,A,m,f,h),gt(e,A,o,r,i,s,c),me(c,"onRowsApplied",i.path,A)}function me(e,t,n,o){if(typeof e[t]=="function")try{return e[t](n.slice(),o)}catch(r){console.warn(`[hyper-html-api] ${t} threw at "${n.join(".")||"(root)"}"`,r);return}}function yt(e,t,n,o,r){let i=me(r,"identifyRows",o.path,n);if(!Array.isArray(i))return null;let s=new Array(n.length).fill(-1),c=new Set,l=new Map(t.map((a,d)=>[e.identity(a),d]));for(let a=0;a<n.length;a++){if(!i[a])continue;let d=l.get(e.identity(i[a]));d===void 0||c.has(d)||(s[a]=d,c.add(d))}return s}function gt(e,t,n,o,r,i,s){t.forEach((c,l)=>{if(n===null){let a=o[l],d=a==null?"":String(a);e.text(c)!==d&&e.text(c,d)}else{let a=i(e,c,n,o[l],{depth:r.depth+1,path:[...r.path,l]},s);a&&a!==c&&(t[l]=a)}})}function At(e,t,n,o){return n===null?e.text(t):N(e,t,n,o.onRowsRead?{...o,onRowsRead:void 0}:o)}function We(e,t,n){let o=e.children(t);for(let r=0;r<o.length;r++)if(e.sameNode(o[r],n))return r;return-1}function wt(e,t,n,o){if(!o.templateAttr)return null;let r=/^\s*:scope\s*>\s*/.test(n),i=new RegExp(":not\\(\\["+o.templateAttr.replace(/[.*+?^${}()|[\]\\-]/g,"\\$&")+"\\]\\)","g"),s=n.replace(/^\s*:scope\s*>\s*/,"").replace(i,""),c=r?Tt(s):0,l=he(s),a=t;for(;a;){let d=e.find(a,s,{includeRulesTag:!1,templateAttr:null});for(let y of d)if(e.attr(y,o.templateAttr)!=null&&!(r&&!Et(e,t,y,c))&&!(l&&!e.matches(e.parent(y),l)))return y;a=e.parent(a)}return null}function Tt(e){let t=0,n=null,o=1;for(let r=0;r<e.length;r++){let i=e[r];if(i==="\\")r++;else if(n)i===n&&(n=null);else if(i==='"'||i==="'")n=i;else if(i==="["||i==="(")t++;else if(i==="]"||i===")")t>0&&t--;else if(t===0&&i===">")o++;else{if(t===0&&(i==="+"||i==="~"))return null;if(t===0&&/\s/.test(i)){if(!xt(e,r))return null;for(;r+1<e.length&&/\s/.test(e[r+1]);)r++}}}return o}function xt(e,t){let n=t;for(;n<e.length&&/\s/.test(e[n]);)n++;let o=t>0?e[t-1]:"",r=n<e.length?e[n]:"";return je(o)||je(r)}function je(e){return e===">"||e==="+"||e==="~"}function Et(e,t,n,o){if(o===null)return!0;let r=n;for(let l=0;l<o;l++)if(r=e.parent(r),!r)return!1;let i=e.prop(t,"tagName");if(!i)return!0;let s=e.prop(r,"tagName");if(!s||String(s).toLowerCase()!==String(i).toLowerCase())return!1;let c=new Set(_e(e,r));return _e(e,t).every(l=>c.has(l))}function _e(e,t){let n=e.attr(t,"class");return n?String(n).split(/\s+/).filter(Boolean):[]}function Ot(e,t,n,o,r,i){let s=e.parent(o);if(s&&bt(e,t,s)&&!De(e,s,i))return s;let c=he(n);if(!c)throw new M(r.path,`the list selector "${n}" names no container to hold the new rows \u2014 write it as "container > row" (for example "ol.comments > li") so the cloned row lands in the list`);let a=(c===":scope"?e.prop(t,"tagName")?[t]:[]:e.find(t,c,i)).filter(d=>!De(e,d,i));if(a.length===0)throw new M(r.path,`no container matching "${c}" inside this context to hold the new rows`);if(a.length>1)throw new M(r.path,`"${c}" matches ${a.length} containers inside this context, so the new rows have no single destination`);return a[0]}function bt(e,t,n){let o=n;for(;o;){if(e.sameNode(o,t))return!0;o=e.parent(o)}return e.parent(t)?!1:e.find(t,"*",{includeRulesTag:!0,templateAttr:null}).some(r=>e.sameNode(r,n))}var $e=["no-data","editor-ui"];function De(e,t,n){let o=t;for(;o;){if(n.templateAttr&&e.attr(o,n.templateAttr)!=null||$e.some(i=>e.attr(o,i)!=null))return!0;let r=e.attr(o,"clay");if(r&&r.split(/\s+/).some(i=>$e.includes(i)))return!0;o=e.parent(o)}return!1}function St(e,t,n,o,r){let i=e.children(t),s=i.map(l=>e.identity(l)),c=!1;o.forEach((l,a)=>{let d=e.identity(l),y=n+a;if(s[y]===d)return;if(!r[a]){let T=s.indexOf(d);T!==-1&&(s.splice(T,1),i.splice(T,1))}let p=Math.min(y,i.length);p<i.length?e.insertBefore(i[p],l):i.length?c?e.insertAfter(i[i.length-1],l):(e.insertAt(t,l,y),c=!0):e.insertAt(t,l,0),s.splice(p,0,d),i.splice(p,0,l)})}function Rt(e,t){if(t.length<=1)return!0;let n=e.parent(t[0]);if(!n)return!1;let o=new Map(e.children(n).map((i,s)=>[e.identity(i),s])),r=[];for(let i of t){let s=o.get(e.identity(i));if(s===void 0)return!1;r.push(s)}return r.sort((i,s)=>i-s),r[r.length-1]-r[0]===r.length-1}function Nt(e,t,n,o,r){let i=null,s=r;for(let c=0;c<t.length;c++){if(!n[c]){i=t[c];continue}let l=i?e.parent(i):o;if(!l)continue;let a=i?We(e,l,i)+1:s++;e.insertAt(l,t[c],a),i=t[c]}}function I(e,t,n,o,r={}){if(Object.prototype.hasOwnProperty.call(r,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");let i=[];if(ge(n,o,[],i),i.length)throw new U(i);te(e,t,n,o,{depth:0,path:[]},r)}function te(e,t,n,o,r,i={}){if(r.depth>$)throw new P(r.path);if(o===void 0)return t;if(typeof n=="string")return Ct(e,t,n,o,r,i);if(Array.isArray(n)){let[s,c]=n;return ye(e,t,s,c,o,r,te,i),t}if(typeof n=="object"&&n!==null){for(let[s,c]of Object.entries(n)){let l=te(e,t,c,o==null?o:o[s],{depth:r.depth+1,path:[...r.path,s]},i);l&&l!==t&&(t=l)}return t}return t}function Ct(e,t,n,o,r,i){if(n.endsWith("[]")){let l=n.slice(0,-2);return ye(e,t,l,null,o,r,te,i),t}if(n.startsWith("@"))return ve(e,t,n.slice(1),o);let s=S(n);if(s!==-1){let l=n.slice(0,s),a=n.slice(s+1),d=l?e.find(t,l,i):[t];return d.length===0||ve(e,d[0],a,o),t}if(n===".")return Ue(e,t,o),t;let c=e.find(t,n,i);return c.length===0||Ue(e,c[0],o),t}function Ue(e,t,n){let o=n==null?"":String(n);e.text(t)!==o&&e.text(t,o)}function ve(e,t,n,o){if(X.has(n)){let r=e.prop(t,n);if(r===o||r!=null&&o!=null&&String(r)===String(o))return t;throw new v(n)}if(n==="outerHTML"){let r=o==null?"":String(o);return e.replaceWith(t,r)}if(le.has(n)){let r=fe(n,o);return e.prop(t,n)!==r&&e.prop(t,n,r),t}if(o==null)e.attr(t,n)!=null&&e.removeAttr(t,n);else{let r=String(o);e.attr(t,n)!==r&&e.attr(t,n,r)}return t}function ge(e,t,n,o){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((r,i)=>{typeof r=="object"&&r!==null&&o.push({path:B([...n,i]),expected:"scalar",got:H(r)})}):o.push({path:B(n),expected:"array",got:H(t)});return}t!==null&&typeof t=="object"&&o.push({path:B(n),expected:"scalar",got:H(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){o.push({path:B(n),expected:"array",got:H(t)});return}let r=e[1];t.forEach((i,s)=>ge(r,i,[...n,s],o));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){o.push({path:B(n),expected:"object",got:H(t)});return}for(let[r,i]of Object.entries(e))ge(i,t[r],[...n,r],o)}}}function H(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function B(e){return e.join(".")}function Ae(e){try{return JSON.parse(e)}catch(t){throw new _(`Invalid strict JSON: ${t.message}`,t)}}function L(e){try{return JSON.parse(e)}catch{}let t={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=[],s=0;for(;s<r.length;){let c=r[s];if(/\s/.test(c)){s++;continue}if("{}".includes(c)){i.push({type:c,value:c}),s++;continue}if(c==="["){let y=!1,p=s+1;for(;p<r.length&&/\s/.test(r[p]);)p++;if(p<r.length&&/[a-zA-Z_]/.test(r[p])&&(y=!0),!y){i.push({type:c,value:c}),s++;continue}}if(c==="]"){i.push({type:c,value:c}),s++;continue}if(c===":"){i.push({type:t.COLON,value:c}),s++;continue}if(c===","){i.push({type:t.COMMA,value:c}),s++;continue}if(c==='"'||c==="'"){let y=c,p=s+1;for(;p<r.length&&r[p]!==y;)r[p]==="\\"&&p++,p++;i.push({type:t.STRING,value:r.substring(s+1,p),quoted:!0,sourceQuote:y}),s=p+1;continue}let l=s,a;for(;l<r.length&&!/[{},]/.test(r[l]);)if(r[l]===":"){let y=[":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"],p=!1;for(let T of y){let f=T.substring(1);if(r.substring(l+1,l+1+f.length)===f){p=!0,l+=f.length;break}}if(!p)break}else if(r[l]==="["){for(l++;l<r.length&&r[l]!=="]";){if(r[l]==='"'||r[l]==="'"){let y=r[l];for(l++;l<r.length&&r[l]!==y;)r[l]==="\\"&&l++,l++}l++}l<r.length&&r[l]==="]"&&l++}else l++;a=r.substring(s,l);let d=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(a)?d=t.NUMBER:a==="true"||a==="false"||a==="null"?d=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(a)&&(d=t.SELECTOR),i.push({type:d,value:a,quoted:!1}),s=l}return i}function o(r){let i="";for(let s=0;s<r.length;s++){let c=r[s];if("{}".includes(c.type)||"[]".includes(c.type)){i+=c.value;continue}if(c.type===t.COLON){i+=c.value;continue}if(c.type===t.COMMA){let l=r[s+1];if(l&&(l.type==="}"||l.type==="]"))continue;i+=c.value;continue}if(c.type===t.STRING&&c.quoted){let l=c.value;c.sourceQuote==="'"&&(l=l.replace(/\\'/g,"'"),l=l.replace(/(\\*)"/g,(a,d)=>d.length%2===0?d+'\\"':a)),i+=`"${l}"`;continue}if(c.type===t.NUMBER||c.type===t.BOOLEAN){i+=c.value;continue}if(c.type===t.SELECTOR||c.type===t.IDENTIFIER){i+=`"${c.value}"`;continue}i+=`"${c.value}"`}return i}try{let r=n(e),i=o(r);return JSON.parse(i)}catch(r){throw new _("Invalid extraction rules syntax: "+r.message,r)}}var we="1",He=/^[a-zA-Z0-9_-]+$/;function q(e,t,n){let o;if(n===void 0)o="script[data-rules-name]";else{if(typeof n!="string"||!He.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${He})`);o=`script[data-rules-name~="${n}"]`}let r=e.find(t,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],s=e.attr(i,"data-rules-version");if(s!==we)throw new k(s);return{rules:L(e.text(i)),tagNode:i}}var ne=Object.freeze({data:Object.freeze({tokens:["no-data"],bundles:["editor-ui"]}),save:Object.freeze({tokens:["no-save"],bundles:["editor-ui"]}),snapshot:Object.freeze({tokens:["no-snapshot"],bundles:["editor-ui"]}),watch:Object.freeze({tokens:["no-watch"],bundles:["editor-ui"]}),undo:Object.freeze({tokens:["no-undo"],bundles:["editor-ui"]}),history:Object.freeze({tokens:[],bundles:["editor-ui"]})}),Mt=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),Be=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui","live"]);function K(e,t){if(!e||e.nodeType!==1)return!1;let n=e.getAttribute?.("clay");return!!(n&&n.split(/\s+/).includes(t)||e.hasAttribute?.(t))}function Te(e,t){if(K(e,t))return!0;for(let[n,o]of Object.entries(Mt))if(o.includes(t)&&K(e,n))return!0;return!1}function F(e){let t=ne[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}function kt(e,t){let n=e&&e.nodeType===1?e:e?.parentElement;for(;n&&n.nodeType===1;){let o=ne[t];if(!o)throw new Error(`Unknown region capability: ${t}`);if(o.tokens.some(r=>Te(n,r))||o.bundles.some(r=>K(n,r)))return n;n=n.parentElement}return null}function qe(e,t){return!!kt(e,t)}var Pt=Object.freeze({refusedRuleForms:["innerHTML","outerHTML"],refusedTargets:["script","style","template","noscript","iframe","object","embed","xmp","plaintext","noembed","noframes","meta","link","base","animate","set","animatemotion","animatetransform"],refusedAttributes:["style","srcdoc","is","http-equiv","sandbox","allow","nonce","integrity","charset","htmlclaytoken","htmlclayid","data-rules-name","data-rules-version","clay","contenteditable",...Be],refusedAttributePrefixes:["on"],urlAttributes:["href","src","srcset","action","formaction","poster","cite","data","ping","background","longdesc","usemap","xlink:href","manifest","codebase","icon"],refusedSchemes:["javascript","vbscript","data"]});function xe(e,t,n){if(n&&typeof n=="object")return{rules:n,tagNode:null};if(typeof n=="string"){let o=t&&t.ownerDocument?t.ownerDocument:t;return q(e,o,n)}return null}var _t=/:(?:focus(?:-within|-visible)?|hover|active|visited|defined)\b/i;function $t(e,t){if(!/^(INPUT|TEXTAREA|SELECT|OPTION)$/.test(e.tagName||""))return;let n=(e.getAttribute?.("type")||"").toLowerCase();"value"in e&&"value"in t&&e.tagName!=="OPTION"&&n!=="checkbox"&&n!=="radio"&&n!=="file"&&(t.value=e.value),e.tagName==="INPUT"&&(n==="checkbox"||n==="radio")&&(t.checked=e.checked),e.tagName==="OPTION"&&(t.selected=e.selected),"indeterminate"in e&&"indeterminate"in t&&(t.indeterminate=e.indeterminate)}function Ke(e,t,n,o){if(o)return!!e.closest?.(t);let r=e;for(;r?.nodeType===1;){if(r.matches(t))return!0;if(r===n)break;r=r.parentElement}return!1}function Fe(e,t,n,o,r,i){return(i?qe(e,t):Ke(e,n,r,!1))||!!(o&&(i&&e!==r?e.matches(o):Ke(e,o,r,i)))}function Dt(e,t){let n=ne[t];return n.tokens.some(o=>Te(e,o))||n.bundles.some(o=>K(e,o))}var Wt=new Set(["INPUT","TEXTAREA","SELECT","OPTION"]);function ze(e,t,n,o){if(e.nodeType===1&&o(e)){n.dropped.push(t);return}n.cloneToLive.set(t,e),n.liveToClone.set(e,t);let r=e,i=t;if(e.nodeType===1){if(Wt.has(e.tagName)&&n.controls.push(e,t),e.tagName==="TEMPLATE"){for(;t.firstChild;)t.removeChild(t.firstChild);r=e.content,i=t.content,n.cloneToLive.set(i,r),n.liveToClone.set(r,i)}}else if(e.nodeType!==11)return;let s=i.firstChild;for(let c=r.firstChild;c&&s;c=c.nextSibling)ze(c,s,n,o),s=s.nextSibling}function z(e,{capability:t="data",exclude:n=null,inherit:o=!0,provenance:r=null}={}){if(!e)throw new TypeError("createContentView requires a DOM context");let i=e.nodeType===9?e:e.ownerDocument;if(!i?.implementation?.createHTMLDocument)throw new TypeError("createContentView requires an HTML DOM implementation");let s=i.implementation.createHTMLDocument(""),c=r||new WeakMap,l=new WeakMap,a=e.nodeType===9?e.documentElement:e;n&&s.documentElement.matches(n);let d=F(t),y=o?f=>Dt(f,t)||!!(n&&f.matches(n)):f=>Fe(f,t,d,n,a,!1),p=null;if(a.nodeType!==1||!Fe(a,t,d,n,a,o)){p=s.importNode(a,!0);let f={cloneToLive:c,liveToClone:l,dropped:[],controls:[]};ze(a,p,f,y);for(let h of f.dropped)h.remove();for(let h=0;h<f.controls.length;h+=2)$t(f.controls[h],f.controls[h+1])}e.nodeType===9&&p&&(s.replaceChild(p,s.documentElement),l.set(e,s),c.set(s,e));let T=f=>{if(_t.test(f))throw new Error(`Filtered content queries do not support stateful selector: ${f}`)};return{root:p,document:s,capability:t,selector:F(t),cloneToLive:c,liveToClone:l,original(f){return c.get(f)||null},cloneOf(f){return l.get(f)||null},query(f,h=p){return T(f),Array.from(h.querySelectorAll(f),g=>c.get(g)||g)},text(f=p){return(f===p?p:l.get(f))?.textContent||""},html(f=p){return(f===p?p:l.get(f))?.innerHTML??""},clone(f=p){let h=f===p?p:l.get(f);return h?s.importNode(h,!0):null}}}function Je(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function Ut(e){return e?(e.nodeType===9||e.nodeType===11,e):null}function Ve(e,t,n){!e||e.nodeType!==1||(t==="value"&&e.tagName==="INPUT"?e.value=n===null?"":n:t==="checked"&&e.tagName==="INPUT"?e.checked=n!==null:t==="selected"&&e.tagName==="OPTION"&&(e.selected=n!==null))}function Ye(e,t){e&&e.tagName==="TEXTAREA"&&(e.value=t)}function Ge(e){if(!e||e.nodeType!==1)return;let t=[e,...e.querySelectorAll?e.querySelectorAll("textarea, input, option"):[]];for(let n of t)if(n.tagName==="TEXTAREA")n.value=n.defaultValue;else if(n.tagName==="INPUT"){let o=n.type;o!=="file"&&o!=="checkbox"&&o!=="radio"&&(n.value=n.defaultValue),n.checked=n.defaultChecked}else n.tagName==="OPTION"&&(n.selected=n.defaultSelected)}var O={semanticExclude:!0,find(e,t,n={}){let o=Ut(e);if(!o||!o.querySelectorAll)return[];let r=Array.from(o.querySelectorAll(t));n.includeRulesTag||(r=r.filter(c=>!Je(c)));let i=[];n.skip&&i.push(n.skip);let s=n.templateAttr===null?null:n.templateAttr||"cms-template";if(s&&i.push("["+s+"]"),i.length){let c=i.join(", ");r=r.filter(l=>!l.closest||!l.closest(c))}return r},parent(e){return e?e.parentElement:null},children(e){return e?Array.from(e.children):[]},matches(e,t){return!!(e&&e.matches)&&e.matches(t)},text(e,t){if(t===void 0)return(e.textContent||"").trim();e.textContent=t,Ye(e,t)},attr(e,t,n){if(n===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,n),Ve(e,t,n)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t),Ve(e,t,null)},prop(e,t,n){if(n===void 0){let o=e?e[t]:void 0;return o!==void 0?o:null}e[t]=n},clone(e){let t=e.cloneNode(!0);return Ge(t),t},insertAt(e,t,n){let o=e.children[n]||null;e.insertBefore(t,o)},insertBefore(e,t){e.parentNode.insertBefore(t,e)},insertAfter(e,t){e.parentNode.insertBefore(t,e.nextSibling)},identity(e){return e||null},remove(e){e&&e.parentNode&&e.parentNode.removeChild(e)},replaceWith(e,t){if(!e||!e.parentNode)throw new Error("dom.replaceWith: node has no parent");let o=e.ownerDocument.createElement("template");o.innerHTML=t;let r=o.content.firstElementChild;if(!r)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(r,e),r},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(o=>{o.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}};function V(e,t={}){if(t.exclude===null)return O;let n=[F("data"),t.exclude].filter(Boolean).join(", "),o=e.nodeType===9?e:e.ownerDocument||e,r=e.nodeType===9?e.documentElement:e;if(!t._write&&!r?.matches?.(n)&&!r?.querySelector?.(n)&&!o?.querySelector?.(n))return O;let i=e.nodeType===9||!e.isConnected?e:e.ownerDocument,s=e.nodeType===9?e:e.ownerDocument,c=null,l=()=>c||(c=z(i,{capability:"data",exclude:t.exclude||null})),a=f=>{let h=l();return f===e?h.cloneOf(e):h.cloneOf(f)||f},d=f=>c?.original(f)||f,y=(f,h)=>{l().liveToClone.set(f,h),l().cloneToLive.set(h,f);let g=f.childNodes||[],u=h.childNodes||[];for(let m=0;m<Math.min(g.length,u.length);m++)y(g[m],u[m])},p=(f,h,g,u)=>{let m=Array.from(f.childNodes).filter(x=>c.cloneOf(x)),w=m[0];for(;w&&m.includes(w);)w=w.nextSibling;for(let x of m)x.remove();if(g==="innerHTML"){let x=s.createElement("template");x.innerHTML=u;for(let W of Array.from(x.content.childNodes))f.insertBefore(W,w||null)}else f.insertBefore(s.createTextNode(u),w||null),Ye(f,u);let b=z(f,{capability:"data",exclude:t.exclude||null});h.replaceChildren(...Array.from(b.root?.childNodes||[]));let E=x=>{let W=b.original(x);W&&(c.liveToClone.set(W,x),c.cloneToLive.set(x,W));for(let it of Array.from(x.childNodes||[]))E(it)};for(let x of Array.from(h.childNodes))E(x)},T={...O,find(f,h,g={}){let u=a(f);if(!u?.querySelectorAll)return[];let m=l().query(h,u);g.includeRulesTag||(m=m.filter(b=>!Je(b)));let A=[];g.skip&&A.push(g.skip);let w=g.templateAttr===null?null:g.templateAttr||"cms-template";if(w&&A.push(`[${w}]`),A.length){let b=A.join(", ");m=m.filter(E=>!E.closest?.(b))}return m},parent(f){let h=a(f)?.parentElement;return h?d(h):null},children(f){return Array.from(a(f)?.children||[],d)},text(f,h){if(h===void 0){let m=d(f);return!m?.matches?.(n)&&!m?.querySelector?.(n)?O.text(m):(a(f)?.textContent||"").trim()}let g=d(f);if(!g?.matches?.(n)&&!g?.querySelector?.(n)&&!c){O.text(g,h);return}let u=l().cloneOf(g);u?p(g,u,"textContent",h):O.text(g,h)},attr(f,h,g){let u=d(f);if(g===void 0)return O.attr(u,h);O.attr(u,h,g);let m=c?.cloneOf(u);m&&(O.attr(m,h,g),z(u,{capability:"data",exclude:t.exclude||null}).root===null&&(m.remove(),c.liveToClone.delete(u),c.cloneToLive.delete(m)))},removeAttr(f,h){let g=d(f);O.removeAttr(g,h);let u=c?.cloneOf(g);u&&O.removeAttr(u,h)},prop(f,h,g){let u=d(f);if(g===void 0)return h==="innerHTML"||h==="outerHTML"||h==="textContent"||h==="innerText"?O.prop(a(u),h):O.prop(u,h);let m=h==="innerHTML"||h==="textContent"||h==="innerText",A=m?l().cloneOf(u):c?.cloneOf(u);A&&m?p(u,A,h,g):(O.prop(u,h,g),A&&O.prop(A,h,g))},clone(f){let h=a(f);if(h===f)return O.clone(f);let g=s.importNode(h,!0);return Ge(g),g},insertAt(f,h,g){let u=d(f),A=T.children(u)[g]||(()=>{for(let E=u.children.length-1;E>=0;E--){let x=u.children[E];if(l().cloneOf(x))return x.nextElementSibling}return u.firstElementChild})(),w=d(h);u.insertBefore(w,A||null);let b=l().cloneOf(u);if(b){let E=l().cloneOf(w);E||(E=s.importNode(w,!0),y(w,E));let x=Array.from(b.children);b.insertBefore(E,x[g]||null)}},insertBefore(f,h){let g=d(f),u=d(h);g.parentNode.insertBefore(u,g);let m=l().cloneOf(g.parentNode);if(m){let A=l().cloneOf(u);A||(A=s.importNode(u,!0),y(u,A));let w=l().cloneOf(g);w?w.before(A):m.appendChild(A)}},insertAfter(f,h){let g=d(f),u=d(h);g.parentNode.insertBefore(u,g.nextSibling);let m=l().cloneOf(g.parentNode);if(m){let A=l().cloneOf(u);A||(A=s.importNode(u,!0),y(u,A));let w=l().cloneOf(g);w?w.after(A):m.appendChild(A)}},identity(f){return d(f)||null},remove(f){let h=d(f),g=l().cloneOf(h);O.remove(h),g&&O.remove(g)},replaceWith(f,h){let g=d(f),u=l().cloneOf(g),m=O.replaceWith(g,h);if(u){let A=z(m,{capability:"data",exclude:t.exclude||null});if(!A.root)u.remove();else{u.replaceWith(A.root);let w=b=>{let E=A.original(b);E&&(c.liveToClone.set(E,b),c.cloneToLive.set(b,E));for(let x of Array.from(b.childNodes||[]))w(x)};w(A.root)}}return m}};return T}var R=O;var Ee={extract:(e,t,n={})=>N(V(e,n),e,t,n),apply:(e,t,n,o={})=>I(V(e,{...o,_write:!0}),e,t,n,o),findRulesIn:(e,t)=>q(R,e,t),findRules:(e,t)=>xe(R,e,t),bind:(e,t,n={})=>{let o=xe(R,e,t);if(!o){let r=typeof t=="string"?`data-rules-name~="${t}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${r}`)}return{...o,get:()=>N(V(e,n),e,o.rules,n),set:r=>I(V(e,{...n,_write:!0}),e,o.rules,r,n)}},parseStrict:Ae,parseRelaxed:L,ruleAttrIndex:S,splitRule:de,errors:ee,DOM_PROPERTIES:Y};var vt="hha:upgrade-check:";function C(e,t){let n=e.querySelector(`meta[name="${t}"]`),o=n?n.getAttribute("content"):null;return o&&o.trim()?o.trim():null}function Xe(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function Ht(e,t){let n=Xe(e),o=Xe(t);if(!n||!o)return!1;let r=Math.max(n.length,o.length);for(let i=0;i<r;i++){let s=n[i]||0,c=o[i]||0;if(s!==c)return s>c}return!1}function Bt(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function qt(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function Ze({force:e=!1,doc:t,loc:n,fetchFn:o,now:r,ttlMs:i=864e5}={}){if(t=t||(typeof document<"u"?document:null),n=n||(typeof location<"u"?location:null),o=o||(p=>fetch(p)),r=r??Date.now(),!t)return null;let s=C(t,"hyper-source");if(!s)return null;let c=C(t,"hyper-version"),l;try{l=new URL(s,n?n.href:void 0)}catch{return null}if(n&&l.origin===n.origin&&l.pathname===n.pathname)return null;let a=`${vt}${l.href}:${c||"none"}`,d,y=e?null:Bt(a);if(y&&typeof y.checkedAt=="number"&&r-y.checkedAt<i)d=y.sourceVersion;else{try{let p=await o(l.href);if(!p.ok)throw new Error(`HTTP ${p.status}`);let T=await p.text(),f=new DOMParser().parseFromString(T,"text/html");d=C(f,"hyper-version")}catch{d=null}qt(a,{checkedAt:r,sourceVersion:d})}return d?{available:Ht(d,c||"0.0.0"),currentVersion:c,sourceVersion:d,sourceUrl:l.href}:null}var Kt="script[data-rules-name]";function Ft(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function re(e,t){let n=e.find(t,Kt,{includeRulesTag:!0}),o=new Set,r=[];for(let i of n){let s=Ft(e.attr(i,"data-rules-name"));if(!s)continue;if(o.has(s)){console.warn(`hyper-html-api: duplicate rules tag name "${s}"; using the first.`);continue}let c=e.attr(i,"data-rules-version");if(c!==we)throw new k(c);o.add(s),r.push({name:s,rules:L(e.text(i))})}return r}function Oe(e,t){let n={};for(let{name:o,rules:r}of re(e,t))n[o]=N(e,t,r);return n}function Qe(e){let t=e||document,n=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:Oe(R,t),version:C(n,"hyper-version")}}var J=class extends Error{constructor(t,n){super(`could not fetch upgrade source: ${t}`),this.name="UpgradeSourceUnreachable",this.sourceUrl=t,this.cause=n}},oe=class extends Error{constructor(t){super(`upgrade source has no rules tags; refusing to drop all existing data: ${t}`),this.name="UpgradeSourceHasNoRules",this.sourceUrl=t}},j=class extends Error{constructor(t,n){super(t),this.name="UpgradeTransformInvalid",this.cause=n}},ie=class extends Error{constructor(t){super(`found ${t} script[type="text/hyper-upgrade"] tags; only one is allowed per document.`),this.name="UpgradeMultipleTransforms",this.count=t}};var zt="text/hyper-upgrade";function et(e,t){let n=e.find(t,`script[type="${zt}"]`);if(n.length===0)return null;if(n.length>1)throw new ie(n.length);return e.text(n[0])||null}var Vt=new Function("url","return import(url)");async function tt(e){let t=new Blob([e],{type:"text/javascript"}),n=URL.createObjectURL(t),o;try{o=await Vt(n)}catch(r){throw new j(`transform failed to load: ${r&&r.message?r.message:r}`,r)}finally{URL.revokeObjectURL(n)}if(typeof o.default!="function")throw new j("transform must `export default` a function");return o.default}function se(e,t){let n={carriedOver:0,discarded:0,listItems:0},o=be(t,e,n);return Se(t,e,n),{data:o,summary:n}}function be(e,t,n){if(typeof e=="string")return e.endsWith("[]")?Array.isArray(t)?(n.listItems+=t.length,n.carriedOver+=t.length,t):void 0:t==null||typeof t=="object"?void 0:(n.carriedOver++,t);if(Array.isArray(e)){let[,o]=e;return Array.isArray(t)?(n.listItems+=t.length,t.map(r=>be(o,r,n))):void 0}if(typeof e=="object"&&e!==null){let o={};for(let[r,i]of Object.entries(e)){let s=be(i,t?.[r],n);s!==void 0&&(o[r]=s)}return o}}function Se(e,t,n){if(t!=null){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){if(typeof t!="object"||Array.isArray(t))return;let o=new Set(Object.keys(e));for(let r of Object.keys(t))o.has(r)?Se(e[r],t[r],n):n.discarded+=D(t[r]);return}if(Array.isArray(e)&&Array.isArray(t)){let o=e[1];t.forEach(r=>Se(o,r,n));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(n.discarded+=D(t))}}function D(e){return e==null?0:Array.isArray(e)?e.reduce((t,n)=>t+D(n),0):typeof e=="object"?Object.values(e).reduce((t,n)=>t+D(n),0):1}function nt(e,t,n){let o=re(e,t),r={carriedOver:0,discarded:0,listItems:0},i={},s=new Set;for(let{name:c,rules:l}of o){if(s.add(c),!Object.prototype.hasOwnProperty.call(n,c)){i[c]={carriedOver:0,discarded:0,listItems:0};continue}let{data:a,summary:d}=se(n[c],l);I(e,t,l,a),i[c]=d,r.carriedOver+=d.carriedOver,r.discarded+=d.discarded,r.listItems+=d.listItems}for(let c of Object.keys(n))s.has(c)||(r.discarded+=D(n[c]));return{totals:r,byName:i,rulesTagCount:o.length}}async function rt({sourceUrl:e,dataByName:t,fromVersion:n,doc:o,loc:r,fetchFn:i}={}){if(o=o||(typeof document<"u"?document:null),r=r||(typeof location<"u"?location:null),i=i||(u=>fetch(u)),!o)throw new Error("upgrade.run requires a document context");if(e=e||C(o,"hyper-source"),!e)throw new Error("upgrade.run: no sourceUrl given and no hyper-source meta tag found");let s=new URL(e,r?r.href:void 0);n=n!==void 0?n:C(o,"hyper-version"),t=t||Oe(R,o);let c;try{c=await i(s.href)}catch(u){throw new J(s.href,u)}if(!c.ok)throw new J(s.href,new Error(`HTTP ${c.status}`));let l=await c.text(),a=new DOMParser().parseFromString(l,"text/html"),d=C(a,"hyper-version"),y=t,p=!1,T=et(R,a);if(T){let m=await(await tt(T))(y,{fromVersion:n,toVersion:d});if(!m||typeof m!="object"||Array.isArray(m))throw new j("transform must return a plain object map of { rulesName: data }");y=m,p=!0}let{totals:f,byName:h,rulesTagCount:g}=nt(R,a,y);if(g===0&&Object.keys(y).length>0)throw new oe(s.href);return{html:Jt(a),fromVersion:n,toVersion:d,summary:{transformApplied:p,totals:f,byName:h}}}function Jt(e){return`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
2
+ `+e.documentElement.outerHTML}var ot={checkForUpdate:Ze,run:rt,extractAll:Qe,shapeMatch:se};var Yt={engine:Ee,upgrade:ot},Gt=Yt;return ut(Xt);})();
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "apply",
10
10
  "CMS"
11
11
  ],
12
- "version": "0.10.1",
12
+ "version": "0.11.1",
13
13
  "homepage": "https://github.com/panphora/hyper-html-api",
14
14
  "bugs": {
15
15
  "url": "https://github.com/panphora/hyper-html-api/issues"
@@ -37,12 +37,13 @@
37
37
  "./write": "./src/write.js"
38
38
  },
39
39
  "scripts": {
40
- "build": "npx esbuild src/hyper-html-api.js --bundle --minify --format=iife --global-name=HyperHtmlApi --outfile=dist/hyper-html-api.min.js",
40
+ "build": "npx esbuild src/hyper-html-api.js --bundle --minify --format=iife --global-name=HyperHtmlApi --outfile=dist/hyper-html-api.min.js && npm run build:engine && npm run build:engine:esm",
41
41
  "build:engine": "npx esbuild src/data.js --bundle --minify --format=iife --global-name=hyperHtmlApiData --outfile=dist/hyper-html-api.engine.min.js",
42
+ "build:engine:esm": "npx esbuild src/data.js --bundle --minify --format=esm --outfile=dist/hyper-html-api.engine.esm.js",
42
43
  "build:upgrade": "npx esbuild src/upgrade.js --bundle --minify --format=iife --global-name=hyperHtmlApiUpgrade --outfile=dist/hyper-html-api.upgrade.min.js",
43
44
  "copy-to-hyperclayjs": "npm run build:engine && npm run build:upgrade && node scripts/copy-to-hyperclayjs.js",
44
- "copy-to-clayjs": "npm run build:engine && node scripts/copy-to-clayjs.js",
45
- "prepublishOnly": "npm run build && npm run build:engine && npm run build:upgrade",
45
+ "copy-to-clayjs": "npm run build:engine && npm run build:engine:esm && node scripts/copy-to-clayjs.js",
46
+ "prepublishOnly": "npm run build && npm run build:upgrade",
46
47
  "demo": "http-server . -p 5693 -c-1 -o /demo/",
47
48
  "test": "web-test-runner",
48
49
  "test:debug": "web-test-runner --manual --open",
@@ -63,7 +64,7 @@
63
64
  "url": "git+https://github.com/panphora/hyper-html-api.git"
64
65
  },
65
66
  "dependencies": {
66
- "hyper-morph": "^1.6.2"
67
+ "hyper-morph": "^1.6.3"
67
68
  },
68
69
  "devDependencies": {
69
70
  "@web/test-runner": "^0.20.0",
@@ -103,6 +103,10 @@ const cheerioAdapter = {
103
103
  return p && p.length ? p : null
104
104
  },
105
105
 
106
+ matches(node, selector) {
107
+ return !!node && node.length > 0 && isElement(node) && node.is(selector)
108
+ },
109
+
106
110
  children(node) {
107
111
  if (!node || !node.children) return []
108
112
  const kids = node.children()
@@ -128,8 +132,12 @@ const cheerioAdapter = {
128
132
 
129
133
  attr(node, name, value) {
130
134
  if (value === undefined) {
131
- const v = node.attr(name)
132
- return v !== undefined ? v : null
135
+ // Read the raw attribs map rather than .attr(): cheerio's getter returns
136
+ // the attribute NAME for HTML boolean attributes (hidden, open, required,
137
+ // multiple, autofocus...), which is not what the DOM adapter reports.
138
+ const attribs = node[0] && node[0].attribs
139
+ if (!attribs || !Object.prototype.hasOwnProperty.call(attribs, name)) return null
140
+ return attribs[name]
133
141
  }
134
142
  node.attr(name, value)
135
143
  },
@@ -13,6 +13,35 @@ function resolveSearchRoot(ctx) {
13
13
  return ctx
14
14
  }
15
15
 
16
+ function mirrorLiveState(node, name, value) {
17
+ if (!node || node.nodeType !== 1) return
18
+ if (name === 'value' && node.tagName === 'INPUT') node.value = value === null ? '' : value
19
+ else if (name === 'checked' && node.tagName === 'INPUT') node.checked = value !== null
20
+ else if (name === 'selected' && node.tagName === 'OPTION') node.selected = value !== null
21
+ }
22
+
23
+ function syncTextareaValue(node, value) {
24
+ if (node && node.tagName === 'TEXTAREA') node.value = value
25
+ }
26
+
27
+ function resetFormState(node) {
28
+ if (!node || node.nodeType !== 1) return
29
+ const controls = [node, ...(node.querySelectorAll ? node.querySelectorAll('textarea, input, option') : [])]
30
+ for (const control of controls) {
31
+ if (control.tagName === 'TEXTAREA') {
32
+ control.value = control.defaultValue
33
+ } else if (control.tagName === 'INPUT') {
34
+ const type = control.type
35
+ // A checkbox or radio has no value content attribute by default, and
36
+ // assigning one writes the attribute: the clone would carry value="".
37
+ if (type !== 'file' && type !== 'checkbox' && type !== 'radio') control.value = control.defaultValue
38
+ control.checked = control.defaultChecked
39
+ } else if (control.tagName === 'OPTION') {
40
+ control.selected = control.defaultSelected
41
+ }
42
+ }
43
+ }
44
+
16
45
  const dom = {
17
46
  semanticExclude: true,
18
47
  find(ctx, selector, opts = {}) {
@@ -43,9 +72,14 @@ const dom = {
43
72
  return node ? Array.from(node.children) : []
44
73
  },
45
74
 
75
+ matches(node, selector) {
76
+ return !!(node && node.matches) && node.matches(selector)
77
+ },
78
+
46
79
  text(node, value) {
47
80
  if (value === undefined) return (node.textContent || '').trim()
48
81
  node.textContent = value
82
+ syncTextareaValue(node, value)
49
83
  },
50
84
 
51
85
  attr(node, name, value) {
@@ -53,10 +87,12 @@ const dom = {
53
87
  return node.hasAttribute && node.hasAttribute(name) ? node.getAttribute(name) : null
54
88
  }
55
89
  node.setAttribute(name, value)
90
+ mirrorLiveState(node, name, value)
56
91
  },
57
92
 
58
93
  removeAttr(node, name) {
59
94
  if (node && node.removeAttribute) node.removeAttribute(name)
95
+ mirrorLiveState(node, name, null)
60
96
  },
61
97
 
62
98
  prop(node, name, value) {
@@ -68,7 +104,9 @@ const dom = {
68
104
  },
69
105
 
70
106
  clone(node) {
71
- return node.cloneNode(true)
107
+ const copy = node.cloneNode(true)
108
+ resetFormState(copy)
109
+ return copy
72
110
  },
73
111
 
74
112
  insertAt(parent, node, index) {
@@ -163,6 +201,7 @@ export function createDomAdapter(operationRoot, opts = {}) {
163
201
  for (const child of Array.from(template.content.childNodes)) target.insertBefore(child, anchor || null)
164
202
  } else {
165
203
  target.insertBefore(outputDocument.createTextNode(value), anchor || null)
204
+ syncTextareaValue(target, value)
166
205
  }
167
206
  const filteredView = createContentView(target, { capability: 'data', exclude: opts.exclude || null })
168
207
  copy.replaceChildren(...Array.from(filteredView.root?.childNodes || []))
@@ -255,7 +294,10 @@ export function createDomAdapter(operationRoot, opts = {}) {
255
294
  },
256
295
  clone(node) {
257
296
  const copy = projected(node)
258
- return copy === node ? dom.clone(node) : outputDocument.importNode(copy, true)
297
+ if (copy === node) return dom.clone(node)
298
+ const clone = outputDocument.importNode(copy, true)
299
+ resetFormState(clone)
300
+ return clone
259
301
  },
260
302
  insertAt(parent, node, index) {
261
303
  const targetParent = live(parent)
@@ -110,7 +110,7 @@ function handleClick(e) {
110
110
  const rule = getRuleAtPath(rules, path)
111
111
  if (!Array.isArray(rule)) return
112
112
  const current = getValueAtPath(getData(), path) || []
113
- onChange(setAtPath(getData(), path, [...current, scaffold(rule[1])]), {
113
+ onChange(setAtPath(getData(), path, [...current, scaffold(rule[1], rule[0])]), {
114
114
  structural: true,
115
115
  })
116
116
  return
@@ -1,3 +1,6 @@
1
+ import { DOM_PROPERTIES_SET } from '../engine/dom-properties.js'
2
+ import { splitRule } from '../engine/rule-syntax.js'
3
+
1
4
  /**
2
5
  * Produce an empty value matching a rule shape.
3
6
  *
@@ -6,19 +9,84 @@
6
9
  * list.
7
10
  *
8
11
  * "title" → ""
12
+ * "@data-id" → null (an attribute: absent, not present-and-empty)
9
13
  * "li[]" → []
10
14
  * ["sel", { ... }] → []
11
15
  * { name: "h1", ... } → { name: "" , ... }
12
16
  *
17
+ * `rowSelector` is the list rule's own selector ("ul > li[data-id]"), so an
18
+ * attribute the row cannot be a row without arrives present-and-empty instead.
19
+ *
13
20
  * Anything else falls through to the scalar default ("").
14
21
  */
15
- export function scaffold(shape) {
16
- if (typeof shape === 'string') return shape.endsWith('[]') ? [] : ''
22
+ export function scaffold(shape, rowSelector) {
23
+ if (typeof shape === 'string') {
24
+ if (shape.endsWith('[]')) return []
25
+ if (!isAttributeRule(shape)) return ''
26
+ return rowRequiresAttribute(rowSelector, splitRule(shape).prop) ? '' : null
27
+ }
17
28
  if (Array.isArray(shape)) return []
18
29
  if (typeof shape === 'object' && shape !== null) {
19
30
  const out = {}
20
- for (const [k, v] of Object.entries(shape)) out[k] = scaffold(v)
31
+ for (const [k, v] of Object.entries(shape)) out[k] = scaffold(v, rowSelector)
21
32
  return out
22
33
  }
23
34
  return ''
24
35
  }
36
+
37
+ // "" is the present-and-empty value for an attribute, so a scaffolded row that
38
+ // used it would arrive with every presence flag set (a new task done, a new
39
+ // card archived). An attribute field starts null — the writer removes the
40
+ // attribute — while text fields keep "". DOM properties have no presence to
41
+ // speak of and keep "" too.
42
+ function isAttributeRule(rule) {
43
+ const { prop } = splitRule(rule)
44
+ return prop !== null && !DOM_PROPERTIES_SET.has(prop)
45
+ }
46
+
47
+ // An attribute the row selector itself requires is structural: apply removes a
48
+ // null attribute, and a row without "data-id" falls straight out of the data on
49
+ // the next read. Only the selector's final compound speaks for the row; an
50
+ // attribute named earlier belongs to an ancestor.
51
+ function rowRequiresAttribute(rowSelector, prop) {
52
+ if (!rowSelector || !prop) return false
53
+ const compound = lastCompound(rowSelector)
54
+ const wanted = prop.toLowerCase()
55
+ for (let i = 0; i < compound.length; i++) {
56
+ if (compound[i] === '\\') {
57
+ i++
58
+ } else if (compound[i] === '[') {
59
+ const end = compound.indexOf(']', i)
60
+ if (end === -1) return false
61
+ const name = /^\s*([^\s\]=~^|*$]+)/.exec(compound.slice(i + 1, end))
62
+ if (name && name[1].toLowerCase() === wanted) return true
63
+ i = end
64
+ }
65
+ }
66
+ return false
67
+ }
68
+
69
+ // Everything after the last top-level combinator, which is the compound that
70
+ // describes the row itself.
71
+ function lastCompound(selector) {
72
+ let depth = 0
73
+ let quote = null
74
+ let start = 0
75
+ for (let i = 0; i < selector.length; i++) {
76
+ const ch = selector[i]
77
+ if (ch === '\\') {
78
+ i++
79
+ } else if (quote) {
80
+ if (ch === quote) quote = null
81
+ } else if (ch === '"' || ch === "'") {
82
+ quote = ch
83
+ } else if (ch === '[' || ch === '(') {
84
+ depth++
85
+ } else if (ch === ']' || ch === ')') {
86
+ if (depth > 0) depth--
87
+ } else if (depth === 0 && (ch === '>' || ch === '+' || ch === '~' || /\s/.test(ch))) {
88
+ start = i + 1
89
+ }
90
+ }
91
+ return selector.slice(start)
92
+ }
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  DOM_PROPERTIES_WRITE_SET,
3
3
  DOM_PROPERTIES_READ_ONLY_SET,
4
+ coercePropValue,
4
5
  } from './dom-properties.js'
5
6
  import {
6
7
  MaxRuleDepthExceeded,
@@ -11,8 +12,6 @@ import {
11
12
  import { listDiff } from './diff.js'
12
13
  import { ruleAttrIndex } from './rule-syntax.js'
13
14
 
14
- const BOOLEAN_PROPS = new Set(['checked', 'selected', 'disabled', 'readOnly', 'paused'])
15
-
16
15
  export function apply(adapter, root, rules, data, opts = {}) {
17
16
  if (Object.prototype.hasOwnProperty.call(opts, 'exclude') && adapter.semanticExclude === false) {
18
17
  throw new Error('This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.')
@@ -126,19 +125,13 @@ function writePropOrAttr(adapter, node, name, value) {
126
125
  if (adapter.prop(node, name) !== next) adapter.prop(node, name, next)
127
126
  return node
128
127
  }
129
- const next = value == null ? '' : String(value)
130
- if (adapter.attr(node, name) !== next) adapter.attr(node, name, next)
131
- return node
132
- }
133
-
134
- function coercePropValue(name, value) {
135
- if (value === null || value === undefined) {
136
- return BOOLEAN_PROPS.has(name) ? false : ''
128
+ if (value == null) {
129
+ if (adapter.attr(node, name) != null) adapter.removeAttr(node, name)
130
+ } else {
131
+ const next = String(value)
132
+ if (adapter.attr(node, name) !== next) adapter.attr(node, name, next)
137
133
  }
138
- // Form state and attribute round-trips deliver booleans as strings, and
139
- // Boolean("false") is true: writing "false" would CHECK an unchecked box.
140
- if (BOOLEAN_PROPS.has(name)) return value === 'false' ? false : Boolean(value)
141
- return value
134
+ return node
142
135
  }
143
136
 
144
137
  function validateShape(rule, value, path, mismatches) {