@panphora/clayjs 1.26.1 → 1.26.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/dist/all.js +1 -1
  2. package/dist/clay-dom.js +1 -1
  3. package/dist/clay-events.js +1 -1
  4. package/dist/clay-internals.js +1 -1
  5. package/dist/clay-options.js +1 -1
  6. package/dist/clay-router.js +1 -1
  7. package/dist/clay-ui.js +1 -1
  8. package/dist/clay-utils.js +1 -1
  9. package/dist/clay.js +1 -1
  10. package/dist/clay.standalone.js +4 -3
  11. package/dist/m/{c-EQ5NBOGA.js → c-26W3BMWK.js} +1 -1
  12. package/dist/m/{c-AQVQKFKB.js → c-3JQY5MB2.js} +1 -1
  13. package/dist/m/{c-MKAUC6DB.js → c-3KG4SDZ5.js} +1 -1
  14. package/dist/m/{c-HYNM5U6B.js → c-5CJCIAFK.js} +1 -1
  15. package/dist/m/{c-O3DPFZCE.js → c-6266A3CU.js} +1 -1
  16. package/dist/m/{c-WOJ2RTV4.js → c-627JDXWT.js} +1 -1
  17. package/dist/m/{c-MMEVDN6D.js → c-7PZS45FY.js} +1 -1
  18. package/dist/m/{c-NYJ577NL.js → c-7RJCYD4F.js} +1 -1
  19. package/dist/m/{c-EHAR4RJJ.js → c-CKG4NF7J.js} +2 -2
  20. package/dist/m/{c-EXZOA6XY.js → c-E37MV4WS.js} +1 -1
  21. package/dist/m/{c-N4GEJMXW.js → c-EFXPKDJP.js} +1 -1
  22. package/dist/m/{c-ZPI7M5U5.js → c-G426P2SE.js} +1 -1
  23. package/dist/m/{c-BJ2RRQBQ.js → c-GXOUAT7E.js} +1 -1
  24. package/dist/m/{c-VU4WEWPH.js → c-H25R2UF3.js} +1 -1
  25. package/dist/m/{c-VO6RSFCO.js → c-HBSBQBD7.js} +1 -1
  26. package/dist/m/{c-CL5LSATX.js → c-I4ZVJZC7.js} +1 -1
  27. package/dist/m/{c-67TBU56I.js → c-I62KCFMW.js} +1 -1
  28. package/dist/m/{c-Y3MPVURA.js → c-IJ4VUYDN.js} +1 -1
  29. package/dist/m/{c-FC5RUFPR.js → c-IOJOJTPL.js} +1 -1
  30. package/dist/m/{c-HXGNH6GY.js → c-IPCSVZAB.js} +1 -1
  31. package/dist/m/c-JEWSJHMK.js +1 -0
  32. package/dist/m/{c-3F3AADKG.js → c-JOA4OJGK.js} +1 -1
  33. package/dist/m/{c-GFASNR55.js → c-JUSHNY3I.js} +1 -1
  34. package/dist/m/{c-7RHOMAMR.js → c-K5HRHUTK.js} +1 -1
  35. package/dist/m/{c-H3M6UDNV.js → c-KFXW6SZO.js} +1 -1
  36. package/dist/m/{c-EAV7A6BT.js → c-MB5FZ2PD.js} +1 -1
  37. package/dist/m/{c-2EPHRF47.js → c-MIQYK2VM.js} +1 -1
  38. package/dist/m/{c-ARO6CPMA.js → c-O3BSWMVD.js} +1 -1
  39. package/dist/m/{c-U35T5NAY.js → c-O54PVIAQ.js} +1 -1
  40. package/dist/m/{c-H4M2T4A6.js → c-OEEJRV2M.js} +1 -1
  41. package/dist/m/{c-KU3PX7LL.js → c-OSGTRM4C.js} +1 -1
  42. package/dist/m/{c-YZGWSCMT.js → c-QLGTY326.js} +1 -1
  43. package/dist/m/{c-WOWGGNCJ.js → c-RC37IFYT.js} +1 -1
  44. package/dist/m/{c-SMLAJASY.js → c-RHYX6KUH.js} +1 -1
  45. package/dist/m/{c-RGFPLQGV.js → c-SMCZC3V6.js} +1 -1
  46. package/dist/m/{c-P73XPAOA.js → c-T6RRRHX7.js} +1 -1
  47. package/dist/m/{c-3S5TNRZA.js → c-USO6XV23.js} +1 -1
  48. package/dist/m/{c-ZFAPQQIB.js → c-VPUSMVKE.js} +1 -1
  49. package/dist/m/{c-YYIN4NAF.js → c-VXJJ7BJL.js} +1 -1
  50. package/dist/m/{c-EEWPNUM2.js → c-W3DMFFGK.js} +1 -1
  51. package/dist/m/{c-755ZOHOM.js → c-W5HY5JHM.js} +1 -1
  52. package/dist/m/{c-C5UGNOC2.js → c-WJVW76R6.js} +1 -1
  53. package/dist/m/{c-Q2CB57UG.js → c-X3WLDGBX.js} +1 -1
  54. package/dist/m/{c-SRW5OBCF.js → c-XLVZN7DT.js} +1 -1
  55. package/dist/m/{c-3WX5FABT.js → c-YIFBOWQE.js} +1 -1
  56. package/dist/m/{c-34J5HC7N.js → c-YJS2V3MX.js} +1 -1
  57. package/dist/m/core/{admin-attrs-43JBA6JB.js → admin-attrs-H26XE2AE.js} +1 -1
  58. package/dist/m/core/{autosave-HD7Y7UNV.js → autosave-U5UIKPM3.js} +1 -1
  59. package/dist/m/core/{conflict-notice-UNDOD4BL.js → conflict-notice-HTF6CECH.js} +1 -1
  60. package/dist/m/core/{host-permission-5BYP24GC.js → host-permission-JHMPKRPO.js} +1 -1
  61. package/dist/m/core/{is-edit-mode-73OXKK5H.js → is-edit-mode-QBJUFMVF.js} +1 -1
  62. package/dist/m/core/{persist-MX3VYVBN.js → persist-TRXZPS6T.js} +1 -1
  63. package/dist/m/core/{recovery-VZF7RJZF.js → recovery-YJS7CI66.js} +1 -1
  64. package/dist/m/core/{save-JZ7R4ET2.js → save-KY3ZMPU4.js} +1 -1
  65. package/dist/m/core/{save-core-I4N6S4ED.js → save-core-LBW6DNJ6.js} +1 -1
  66. package/dist/m/core/{site-edits-C22O53GS.js → site-edits-M44KWAQN.js} +1 -1
  67. package/dist/m/core/{unsaved-warning-BP6ZY3PG.js → unsaved-warning-2X7NJNHZ.js} +1 -1
  68. package/dist/m/internals/{index-3LAVREAU.js → index-CDXUFQZK.js} +1 -1
  69. package/dist/m/{loader-RHUGUKXI.js → loader-CRCEH7TD.js} +1 -1
  70. package/dist/m/manifest-6D031725.js +1 -0
  71. package/dist/m/{manifest-edit-93AA79D7.js → manifest-edit-A75598BC.js} +1 -1
  72. package/dist/m/manifest.json +584 -584
  73. package/dist/m/plugins/{ai-edit-WDV2GLDU.js → ai-edit-T2SM7TRD.js} +1 -1
  74. package/dist/m/plugins/{demo-LMCMBILC.js → demo-57MJ3GOO.js} +1 -1
  75. package/dist/m/plugins/{indicator-OLPZ4WFI.js → indicator-D5PZJGVS.js} +1 -1
  76. package/dist/m/plugins/{live-DF5YS5AH.js → live-J52JO243.js} +1 -1
  77. package/dist/m/plugins/{menu-ESEFQARM.js → menu-KCCEDUMJ.js} +1 -1
  78. package/dist/m/plugins/{page-GZSU77JS.js → page-F7JG3JZX.js} +2 -2
  79. package/dist/m/plugins/{page-view-7MM3FEAR.js → page-view-QPRXXAT3.js} +1 -1
  80. package/dist/m/plugins/{people-EBWE337I.js → people-FEMXINJK.js} +1 -1
  81. package/dist/m/plugins/{richclay-MXH2GFAZ.js → richclay-XL64ZGOZ.js} +2 -2
  82. package/dist/m/plugins/{sortable-BAG3MSWS.js → sortable-HE7Q4KKP.js} +1 -1
  83. package/dist/m/plugins/{source-OYHDXKTB.js → source-5RTLTD75.js} +1 -1
  84. package/dist/m/plugins/{undo-KLHAGV75.js → undo-5MFW3OD5.js} +1 -1
  85. package/dist/m/plugins/{upgrade-SZQJYEQQ.js → upgrade-ORK24FK6.js} +1 -1
  86. package/dist/m/plugins/{upload-NZET3DNQ.js → upload-YMBDWTLR.js} +1 -1
  87. package/dist/m/plugins/{visitor-drafts-ZE6PCAFP.js → visitor-drafts-DCVGLCBX.js} +2 -2
  88. package/dist/m/plugins/{visitor-drafts-owner-TLECTYWS.js → visitor-drafts-owner-QLF6IALP.js} +1 -1
  89. package/dist/m/plugins/{visitor-menu-5XY57JQA.js → visitor-menu-VNWJZ6PV.js} +1 -1
  90. package/dist/m/plugins/{wire-S5ATC4QI.js → wire-I3TDGBGZ.js} +1 -1
  91. package/dist/m/{reader-core-AHOAP5DH.js → reader-core-7JOVUCEQ.js} +2 -2
  92. package/dist/m/sync/{live-sync-RZQSDMZW.js → live-sync-2UYQQSD7.js} +1 -1
  93. package/dist/offline-manifest.json +377 -377
  94. package/package.json +1 -1
  95. package/src/core/mode-receipt.js +7 -5
  96. package/dist/m/c-C7SUMNMI.js +0 -1
  97. package/dist/m/manifest-D70FE013.js +0 -1
  98. /package/dist/m/plugins/{richclay-MXH2GFAZ.js.LEGAL.txt → richclay-XL64ZGOZ.js.LEGAL.txt} +0 -0
@@ -1 +1 @@
1
- import{g as Y}from"./c-C7SUMNMI.js";var me=500,ye=5e3,O="text";var _e=1024*1024,Se=256,Ae=1024*1024;function Be(){let s=globalThis.crypto?.randomUUID?.();return s||`wr-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}var W="clay-recovery-writer:";function Me(s){let a=globalThis.navigator?.locks;typeof a?.request=="function"&&a.request(W+s,()=>new Promise(()=>{})).catch(()=>{})}async function Te(s){let a=globalThis.navigator?.locks;if(typeof a?.query!="function")return new Set;try{let{held:p=[]}=await a.query();return new Set(p.map(f=>f.name).filter(f=>typeof f=="string"&&f.startsWith(W)).map(f=>f.slice(W.length)).filter(f=>f!==s))}catch{return new Set}}function D(s){return Array.isArray(s)?s.join("\0"):String(s)}function F(s,a){return Array.isArray(s)&&Array.isArray(a)?s.length===a.length&&s.every((p,f)=>p===a[f]):s===a}function Ue(s){return globalThis.crypto?.randomUUID?.()??`rec-${s}-${Math.random().toString(36).slice(2)}`}function C(s){return s instanceof Uint8Array?new Uint8Array(s):s instanceof ArrayBuffer?s.slice(0):s}function V(s,a){if(s===a)return!0;if(!s||!a||typeof s!="object"||typeof a!="object")return!1;if(s instanceof Uint8Array||a instanceof Uint8Array){if(!(s instanceof Uint8Array)||!(a instanceof Uint8Array)||s.length!==a.length)return!1;for(let g=0;g<s.length;g++)if(s[g]!==a[g])return!1;return!0}let p=Object.keys(a),f=Object.keys(s);if(p.length!==f.length)return!1;for(let g=0;g<p.length;g++)if(p[g]!==f[g]||a[p[g]]!==s[f[g]])return!1;return!0}var B=new Set;function xe({captureId:s,html:a}={}){if(B.size)for(let p of B)p.capture(s,a)}function De(s){if(!(!B.size||s==null))for(let a of B)a.pinCapture(s)}function qe(s,a){if(!(!B.size||s==null))for(let p of B)p.coverCapture(s,a)}function ze({captureId:s,ok:a=!1,etag:p=null}={}){if(B.size)for(let f of B)f.settle(s,a===!0,p)}function Ce({mode:s=Y==="draft"?"draft":"edit",writerId:a=Be(),indexedDB:p,maxScopeBytes:f,maxDbBytes:g,now:E}={}){let S=new Map,Q=new Set,q=new Map,z=new Map,R=null,P=null,h=null,A={ok:!0,code:null,durable:!1};Me(a);function _(){return{ok:A.ok,code:A.code,durable:A.durable,usage:h?.status().usage??null,identityMismatch:P?P.check().ok===!1:!1}}function w(e){let n={channel:e.channel,status:_(),count:e.pending.size,revisions:[...e.pending.values()].map(({id:t,revision:o})=>({id:t,revision:o}))};for(let t of e.listeners)try{t(n)}catch{}for(let t of Q)try{t(n)}catch{}}function b(e){if(e&&e.ok){let t=A.ok;if(A={ok:!0,code:null,durable:!0},!t)for(let o of S.values())w(o);return}let n=e?.code||"error";if(A.ok||A.code!==n){A={ok:!1,code:n,durable:!1};for(let t of S.values())w(t);return}A={ok:!1,code:n,durable:!1}}async function G(){let[{createIdentity:e},{createStore:n}]=await Promise.all([import("./c-B3JM5ZXC.js"),import("./c-R7LBFMF5.js")]);P=e({mode:s,writerId:a}),h=n({scope:P.scope,indexedDB:p,maxScopeBytes:f,maxDbBytes:g,now:E});let t=await h.open();return t.ok?A={ok:!0,code:null,durable:!1}:b(t),t}function m(){return R||(R=G().catch(e=>({ok:!1,code:e?.name==="DataCloneError"?"uncloneable":"unavailable"}))),R}function I(e,n){let t;try{t=e.readSaved(n)}catch{return[]}if(!t||typeof t.get!="function")return[];let o=[];for(let r of e.held.values())r.kind===O&&t.has(r.key)&&V(t.get(r.key),r.payload)&&o.push({id:r.id,revision:r.revision});return o}function J(e){let n=[];for(let t of S.values())if(!(typeof t.readSaved!="function"||!t.held.size))for(let o of t.held.values())o.kind===O&&n.push({channel:t.channel,key:o.key,id:o.id,revision:o.revision,payload:o.payload});n.length&&z.set(e,n)}function Z(e,n){let t=z.get(e);if(z.delete(e),!t||typeof n!="string")return;let o=new Map,r=new Map;for(let i of t){if(!o.has(i.channel)){let u=S.get(i.channel),d=null;try{d=typeof u?.readSaved=="function"?u.readSaved(n):null}catch{d=null}o.set(i.channel,d&&typeof d.get=="function"?d:null)}let l=o.get(i.channel);if(!l||!l.has(i.key)||!V(l.get(i.key),i.payload))continue;let c=r.get(i.channel)??[];c.push({id:i.id,revision:i.revision}),r.set(i.channel,c)}r.size&&q.set(e,r)}function ee(e,n){if(e==null||typeof n!="string")return;let t=new Map;for(let o of S.values()){if(typeof o.readSaved!="function"||!o.held.size)continue;let r=I(o,n);r.length&&t.set(o.channel,r)}t.size&&q.set(e,t)}async function ne(e,n,t,o){if((await m()).ok){for(let{id:i,revision:l}of n){let c=await h.acknowledge(i,{revision:l,etag:t,captureId:o});b(c);let u=D(i),d=e.held.get(u);d&&d.revision<=l&&e.held.delete(u)}w(e)}}function te(e,n,t){z.delete(e);let o=q.get(e);if(!o||(q.delete(e),!n))return Promise.resolve();let r=[];for(let[i,l]of o){let c=S.get(i);if(!c)continue;let u=()=>ne(c,l,t,e);c.writing=c.writing.then(u,u),r.push(c.writing)}return Promise.all(r).then(()=>{},()=>{})}function oe(e){let n=E?.()??Date.now();e.burstStart||(e.burstStart=n);let t=Math.max(0,Math.min(me,e.burstStart+ye-n));e.timer&&clearTimeout(e.timer),e.timer=setTimeout(()=>{e.timer=null,e.burstStart=0,$(e).catch(()=>{})},t)}function ie(e,{key:n,kind:t=O,baseEtag:o=null,base:r=null,payload:i=null,lineage:l=null}={}){let c=n==null?"":String(n);if(!c)throw new TypeError("clay.recovery.stage needs a key");let u=E?.()??Date.now(),d=++e.revision,k=t===O?[e.channel,c,a]:globalThis.crypto?.randomUUID?.()??`rec-${d}-${Math.random().toString(36).slice(2)}`,M=D(k),T=e.pending.get(M),y={id:k,kind:t,channel:e.channel,version:e.version,key:c,writerId:a,revision:d,status:"journaled",baseEtag:o,base:C(r),payload:C(i),lineage:l,created:T?.created??u,updated:u};return e.pending.set(M,y),e.held.set(M,{id:k,kind:t,key:c,revision:d,payload:y.payload}),oe(e),w(e),{id:k,revision:d}}async function re(e){let n=[...e.pending.values()];if(!n.length)return{ok:!0,stored:[]};let t=await m();if(!t.ok)return{ok:!1,code:t.code};let o=[],r=null;for(let i of n){let l=await h.put(i);if(l.ok){let c=D(i.id);if(e.pending.get(c)===i&&e.pending.delete(c),l.skipped){let u=e.held.get(c);u&&u.revision===i.revision&&e.held.delete(c)}else o.push({id:i.id,revision:i.revision})}else r=r||l.code||"error"}return b(r?{ok:!1,code:r}:{ok:!0}),w(e),r?{ok:!1,code:r}:{ok:!0,stored:o}}function X(e,n){return[e.channel,n,a]}function se(e,n,t,o,r){return{id:n,kind:"binary",channel:e.channel,version:e.version,writerId:a,revision:0,context:t,payload:{base:r??new Uint8Array(0),dependencies:new Uint8Array(0),owned:new Uint8Array(0)},acknowledged:null,created:o,updated:o}}function H(e,n,t){return e.batchQueue.size>=Se||e.queuedBytes+n.payload.byteLength>Ae?!1:(e.batchQueue.set(D(n.id),{record:n,capsule:t}),e.queuedBytes+=n.payload.byteLength,!0)}async function ce(e){if(!e.batchQueue.size)return{ok:!0};let n=await m();if(!n.ok)return{ok:!1,code:n.code};let t=[],o=null;for(let[r,i]of[...e.batchQueue.entries()]){let l=await h.appendBinary(i.record,i.capsule);if(!l.ok){o=o||l.code||"error";continue}e.batchQueue.delete(r),e.queuedBytes=Math.max(0,e.queuedBytes-i.record.payload.byteLength),!l.skipped&&(e.batches+=1,e.batchBytes+=i.record.payload.byteLength,t.push({id:i.record.id,revision:i.record.revision}))}return b(o?{ok:!1,code:o}:{ok:!0}),w(e),o?{ok:!1,code:o}:{ok:!0,stored:t}}async function ae(e,{key:n,context:t=null,update:o,origin:r="local",base:i=null}={}){let l=n==null?"":String(n);if(!l)throw new TypeError("clay.recovery.append needs a key");if(!(o instanceof Uint8Array)&&!(o instanceof ArrayBuffer))throw new TypeError("clay.recovery.append needs binary bytes");let c=E?.()??Date.now(),u=++e.revision,d=X(e,l),k={id:Ue(u),kind:"binary-batch",channel:e.channel,version:e.version,writerId:a,revision:u,capsuleId:d,origin:r==="dependency"?"dependency":"local",context:t,payload:C(o),updated:c},M=se(e,d,t,c,i==null?null:C(i)),T=await m();if(!T.ok)return H(e,k,M)?{ok:!1,code:T.code}:{ok:!1,code:"over-budget"};let y=await h.appendBinary(k,M);return b(y),w(e),y.ok?(e.batches+=1,e.batchBytes+=k.payload.byteLength,y.skipped?{ok:!0,id:k.id,revision:u,skipped:!0}:{ok:!0,id:k.id,revision:u}):H(e,k,M)?{ok:!1,code:y.code}:{ok:!1,code:y.code}}async function le(e,{records:n=[],authority:t=null,epoch:o=null,sequence:r=null}={}){let i=(n||[]).filter(u=>u&&u.id!==void 0&&typeof u.revision=="number");if(!i.length)return{ok:!0,acknowledged:0};let l=await m();if(!l.ok)return{ok:!1,code:l.code};let c=await h.acknowledgeBinary({channel:e.channel,version:e.version,writerId:a,records:i,authority:t,epoch:o,sequence:r});return b(c),w(e),c.ok?{ok:!0,acknowledged:c.acknowledged}:{ok:!1,code:c.code}}async function ue(e,{records:n=[],proof:t=null}={}){let o=(n||[]).filter(u=>u&&u.id!==void 0&&typeof u.revision=="number");if(!o.length)return{ok:!0,retired:[]};if(typeof e.validateCheckpoint!="function")return{ok:!0,retired:[]};let r;try{r=await e.validateCheckpoint(t,o.map(({id:u,revision:d})=>({id:u,revision:d})))}catch{return{ok:!1,code:"invalid",retired:[]}}if(!Array.isArray(r))return{ok:!1,code:"invalid",retired:[]};let i=o.filter(u=>r.some(d=>d&&d.revision===u.revision&&F(d.id,u.id)));if(!i.length)return{ok:!0,retired:[]};let l=await m();if(!l.ok)return{ok:!1,code:l.code,retired:[]};let c=await h.checkpointBinary({channel:e.channel,version:e.version,writerId:a,records:i});return b(c),w(e),c.ok?{ok:!0,retired:c.retired}:{ok:!1,code:c.code,retired:[]}}function L(e){return e&&typeof e.byteLength=="number"&&e.byteLength>0?e:null}async function K(e,n,t=null){for(let o=0;o<3;o++){let r=t?.capsuleId??null,i=[];for(let{id:v,revision:be}of n){let j=await h.get(v);if(!j.ok||!j.record)continue;let U=j.record;U.revision!==be||U.kind!=="binary-batch"||!U.capsuleId||(r||(r=U.capsuleId),F(r,U.capsuleId)&&i.push(U))}if(!r||!(i.length||t))return{ok:!0,retired:[]};let l=await h.get(r);if(!l.ok||!l.record)return{ok:!1,code:"missing"};let c=l.record,u=[L(c.payload?.owned),...i.filter(v=>v.origin!=="dependency").map(v=>L(v.payload))].filter(Boolean),d=[L(c.payload?.dependencies),...i.filter(v=>v.origin==="dependency").map(v=>L(v.payload))].filter(Boolean),k=u.length?C(await e.merge(u)):new Uint8Array(0),M=d.length?C(await e.merge(d)):new Uint8Array(0),T={base:c.payload?.base??new Uint8Array(0),dependencies:M,owned:k};t&&(T=await t.rebuild(T));let y=Math.max(e.revision,c.revision)+1;e.revision=y;let x=await h.compactBinary({channel:e.channel,version:e.version,capsuleId:r,expectedRevision:c.revision,replacement:{revision:y,updated:E?.()??Date.now(),context:t?.context,payload:T},inputs:i.map(v=>({id:v.id,revision:v.revision}))});if(x.ok)return i.length&&(e.batches=e.batchBytes=0),{ok:!0,retired:x.retired,revision:x.revision};if(x.code!=="stale")return{ok:!1,code:x.code}}return{ok:!1,code:"stale"}}async function de(e,{records:n=[]}={}){if(typeof e.merge!="function")return{ok:!1,code:"invalid",retired:[]};let t=(n||[]).filter(i=>i&&i.id!==void 0&&typeof i.revision=="number");if(!t.length)return{ok:!0,retired:[]};let o=await m();if(!o.ok)return{ok:!1,code:o.code,retired:[]};let r=await K(e,t);return b(r),w(e),r.ok?{ok:!0,retired:r.retired}:{ok:!1,code:r.code,retired:[]}}async function fe(e,{key:n,context:t,rebuild:o}={}){let r=await m(),i=r.ok?await K(e,[],{capsuleId:X(e,String(n)),context:t,rebuild:o}):r;return b(i),i}function $(e){e.timer&&clearTimeout(e.timer),e.timer=null,e.burstStart=0;let n=async()=>{let t=await ce(e);return t.ok?re(e):t};return e.writing=e.writing.then(n,n),e.writing}async function pe(e){let n=await m();if(!n.ok)return{ok:!1,code:n.code,records:[],status:_()};let t=await h.list();if(b(t),!t.ok)return{ok:!1,code:t.code,records:[],status:_()};let o=await Te(a);return{ok:!0,records:t.records.filter(i=>i.channel===e.channel&&!o.has(i.writerId)).map(i=>({...i,supported:i.version===e.version})),status:_()}}async function he(e,n,{revision:t}={}){let o=await m();if(!o.ok)return{ok:!1,code:o.code};e.timer&&clearTimeout(e.timer),e.timer=null,e.burstStart=0,await e.writing;let r=D(n),i=e.pending.get(r);i&&(t===void 0||i.revision===t)&&e.pending.delete(r);let l=e.held.get(r);l&&(t===void 0||l.revision===t)&&e.held.delete(r);let c=await h.remove(n,{revision:t});return b(c),w(e),c.ok?{ok:!0,id:n,revision:t}:{ok:!1,code:c.code}}function ke(e,n){return e.listeners.add(n),()=>e.listeners.delete(n)}function ge(e){e.timer&&clearTimeout(e.timer),e.timer=null,e.burstStart=0;let n=$(e).catch(()=>({ok:!1,code:"aborted"}));return e.listeners.clear(),S.delete(e.channel),S.size||B.delete(N),n}let N={capture:ee,settle:te,pinCapture:J,coverCapture:Z};function ve(e){return{channel:e.channel,version:e.version,stage:n=>ie(e,n),flush:()=>$(e),list:()=>pe(e),dismiss:(n,t)=>he(e,n,t),append:n=>ae(e,n),markAcknowledged:n=>le(e,n),checkpoint:n=>ue(e,n),compact:n=>de(e,n),rebase:n=>fe(e,n),subscribe:n=>ke(e,n),dispose:()=>ge(e)}}function we({channel:e,version:n=1,readSaved:t=null,describe:o=null,validateCheckpoint:r=null,merge:i=null}={}){if(!e||typeof e!="string")throw new TypeError("clay.recovery.register needs a channel name");let l=S.get(e);if(l)throw new Error(`clay.recovery: the "${e}" channel is already registered at version ${l.version}`);let c={channel:e,version:n,readSaved:t,describe:o,validateCheckpoint:r,merge:i,revision:0,pending:new Map,held:new Map,batchQueue:new Map,queuedBytes:0,batches:0,batchBytes:0,compaction:null,timer:null,burstStart:0,writing:Promise.resolve(),listeners:new Set};return S.set(e,c),B.add(N),m(),ve(c)}return{register:we,status:_,subscribe(e){return Q.add(e),()=>Q.delete(e)}}}var Pe=Ce();export{xe as a,De as b,qe as c,ze as d,Ce as e,Pe as f};
1
+ import{g as Y}from"./c-JEWSJHMK.js";var me=500,ye=5e3,O="text";var _e=1024*1024,Se=256,Ae=1024*1024;function Be(){let s=globalThis.crypto?.randomUUID?.();return s||`wr-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}var W="clay-recovery-writer:";function Me(s){let a=globalThis.navigator?.locks;typeof a?.request=="function"&&a.request(W+s,()=>new Promise(()=>{})).catch(()=>{})}async function Te(s){let a=globalThis.navigator?.locks;if(typeof a?.query!="function")return new Set;try{let{held:p=[]}=await a.query();return new Set(p.map(f=>f.name).filter(f=>typeof f=="string"&&f.startsWith(W)).map(f=>f.slice(W.length)).filter(f=>f!==s))}catch{return new Set}}function D(s){return Array.isArray(s)?s.join("\0"):String(s)}function F(s,a){return Array.isArray(s)&&Array.isArray(a)?s.length===a.length&&s.every((p,f)=>p===a[f]):s===a}function Ue(s){return globalThis.crypto?.randomUUID?.()??`rec-${s}-${Math.random().toString(36).slice(2)}`}function C(s){return s instanceof Uint8Array?new Uint8Array(s):s instanceof ArrayBuffer?s.slice(0):s}function V(s,a){if(s===a)return!0;if(!s||!a||typeof s!="object"||typeof a!="object")return!1;if(s instanceof Uint8Array||a instanceof Uint8Array){if(!(s instanceof Uint8Array)||!(a instanceof Uint8Array)||s.length!==a.length)return!1;for(let g=0;g<s.length;g++)if(s[g]!==a[g])return!1;return!0}let p=Object.keys(a),f=Object.keys(s);if(p.length!==f.length)return!1;for(let g=0;g<p.length;g++)if(p[g]!==f[g]||a[p[g]]!==s[f[g]])return!1;return!0}var B=new Set;function xe({captureId:s,html:a}={}){if(B.size)for(let p of B)p.capture(s,a)}function De(s){if(!(!B.size||s==null))for(let a of B)a.pinCapture(s)}function qe(s,a){if(!(!B.size||s==null))for(let p of B)p.coverCapture(s,a)}function ze({captureId:s,ok:a=!1,etag:p=null}={}){if(B.size)for(let f of B)f.settle(s,a===!0,p)}function Ce({mode:s=Y==="draft"?"draft":"edit",writerId:a=Be(),indexedDB:p,maxScopeBytes:f,maxDbBytes:g,now:E}={}){let S=new Map,Q=new Set,q=new Map,z=new Map,R=null,P=null,h=null,A={ok:!0,code:null,durable:!1};Me(a);function _(){return{ok:A.ok,code:A.code,durable:A.durable,usage:h?.status().usage??null,identityMismatch:P?P.check().ok===!1:!1}}function w(e){let n={channel:e.channel,status:_(),count:e.pending.size,revisions:[...e.pending.values()].map(({id:t,revision:o})=>({id:t,revision:o}))};for(let t of e.listeners)try{t(n)}catch{}for(let t of Q)try{t(n)}catch{}}function b(e){if(e&&e.ok){let t=A.ok;if(A={ok:!0,code:null,durable:!0},!t)for(let o of S.values())w(o);return}let n=e?.code||"error";if(A.ok||A.code!==n){A={ok:!1,code:n,durable:!1};for(let t of S.values())w(t);return}A={ok:!1,code:n,durable:!1}}async function G(){let[{createIdentity:e},{createStore:n}]=await Promise.all([import("./c-B3JM5ZXC.js"),import("./c-R7LBFMF5.js")]);P=e({mode:s,writerId:a}),h=n({scope:P.scope,indexedDB:p,maxScopeBytes:f,maxDbBytes:g,now:E});let t=await h.open();return t.ok?A={ok:!0,code:null,durable:!1}:b(t),t}function m(){return R||(R=G().catch(e=>({ok:!1,code:e?.name==="DataCloneError"?"uncloneable":"unavailable"}))),R}function I(e,n){let t;try{t=e.readSaved(n)}catch{return[]}if(!t||typeof t.get!="function")return[];let o=[];for(let r of e.held.values())r.kind===O&&t.has(r.key)&&V(t.get(r.key),r.payload)&&o.push({id:r.id,revision:r.revision});return o}function J(e){let n=[];for(let t of S.values())if(!(typeof t.readSaved!="function"||!t.held.size))for(let o of t.held.values())o.kind===O&&n.push({channel:t.channel,key:o.key,id:o.id,revision:o.revision,payload:o.payload});n.length&&z.set(e,n)}function Z(e,n){let t=z.get(e);if(z.delete(e),!t||typeof n!="string")return;let o=new Map,r=new Map;for(let i of t){if(!o.has(i.channel)){let u=S.get(i.channel),d=null;try{d=typeof u?.readSaved=="function"?u.readSaved(n):null}catch{d=null}o.set(i.channel,d&&typeof d.get=="function"?d:null)}let l=o.get(i.channel);if(!l||!l.has(i.key)||!V(l.get(i.key),i.payload))continue;let c=r.get(i.channel)??[];c.push({id:i.id,revision:i.revision}),r.set(i.channel,c)}r.size&&q.set(e,r)}function ee(e,n){if(e==null||typeof n!="string")return;let t=new Map;for(let o of S.values()){if(typeof o.readSaved!="function"||!o.held.size)continue;let r=I(o,n);r.length&&t.set(o.channel,r)}t.size&&q.set(e,t)}async function ne(e,n,t,o){if((await m()).ok){for(let{id:i,revision:l}of n){let c=await h.acknowledge(i,{revision:l,etag:t,captureId:o});b(c);let u=D(i),d=e.held.get(u);d&&d.revision<=l&&e.held.delete(u)}w(e)}}function te(e,n,t){z.delete(e);let o=q.get(e);if(!o||(q.delete(e),!n))return Promise.resolve();let r=[];for(let[i,l]of o){let c=S.get(i);if(!c)continue;let u=()=>ne(c,l,t,e);c.writing=c.writing.then(u,u),r.push(c.writing)}return Promise.all(r).then(()=>{},()=>{})}function oe(e){let n=E?.()??Date.now();e.burstStart||(e.burstStart=n);let t=Math.max(0,Math.min(me,e.burstStart+ye-n));e.timer&&clearTimeout(e.timer),e.timer=setTimeout(()=>{e.timer=null,e.burstStart=0,$(e).catch(()=>{})},t)}function ie(e,{key:n,kind:t=O,baseEtag:o=null,base:r=null,payload:i=null,lineage:l=null}={}){let c=n==null?"":String(n);if(!c)throw new TypeError("clay.recovery.stage needs a key");let u=E?.()??Date.now(),d=++e.revision,k=t===O?[e.channel,c,a]:globalThis.crypto?.randomUUID?.()??`rec-${d}-${Math.random().toString(36).slice(2)}`,M=D(k),T=e.pending.get(M),y={id:k,kind:t,channel:e.channel,version:e.version,key:c,writerId:a,revision:d,status:"journaled",baseEtag:o,base:C(r),payload:C(i),lineage:l,created:T?.created??u,updated:u};return e.pending.set(M,y),e.held.set(M,{id:k,kind:t,key:c,revision:d,payload:y.payload}),oe(e),w(e),{id:k,revision:d}}async function re(e){let n=[...e.pending.values()];if(!n.length)return{ok:!0,stored:[]};let t=await m();if(!t.ok)return{ok:!1,code:t.code};let o=[],r=null;for(let i of n){let l=await h.put(i);if(l.ok){let c=D(i.id);if(e.pending.get(c)===i&&e.pending.delete(c),l.skipped){let u=e.held.get(c);u&&u.revision===i.revision&&e.held.delete(c)}else o.push({id:i.id,revision:i.revision})}else r=r||l.code||"error"}return b(r?{ok:!1,code:r}:{ok:!0}),w(e),r?{ok:!1,code:r}:{ok:!0,stored:o}}function X(e,n){return[e.channel,n,a]}function se(e,n,t,o,r){return{id:n,kind:"binary",channel:e.channel,version:e.version,writerId:a,revision:0,context:t,payload:{base:r??new Uint8Array(0),dependencies:new Uint8Array(0),owned:new Uint8Array(0)},acknowledged:null,created:o,updated:o}}function H(e,n,t){return e.batchQueue.size>=Se||e.queuedBytes+n.payload.byteLength>Ae?!1:(e.batchQueue.set(D(n.id),{record:n,capsule:t}),e.queuedBytes+=n.payload.byteLength,!0)}async function ce(e){if(!e.batchQueue.size)return{ok:!0};let n=await m();if(!n.ok)return{ok:!1,code:n.code};let t=[],o=null;for(let[r,i]of[...e.batchQueue.entries()]){let l=await h.appendBinary(i.record,i.capsule);if(!l.ok){o=o||l.code||"error";continue}e.batchQueue.delete(r),e.queuedBytes=Math.max(0,e.queuedBytes-i.record.payload.byteLength),!l.skipped&&(e.batches+=1,e.batchBytes+=i.record.payload.byteLength,t.push({id:i.record.id,revision:i.record.revision}))}return b(o?{ok:!1,code:o}:{ok:!0}),w(e),o?{ok:!1,code:o}:{ok:!0,stored:t}}async function ae(e,{key:n,context:t=null,update:o,origin:r="local",base:i=null}={}){let l=n==null?"":String(n);if(!l)throw new TypeError("clay.recovery.append needs a key");if(!(o instanceof Uint8Array)&&!(o instanceof ArrayBuffer))throw new TypeError("clay.recovery.append needs binary bytes");let c=E?.()??Date.now(),u=++e.revision,d=X(e,l),k={id:Ue(u),kind:"binary-batch",channel:e.channel,version:e.version,writerId:a,revision:u,capsuleId:d,origin:r==="dependency"?"dependency":"local",context:t,payload:C(o),updated:c},M=se(e,d,t,c,i==null?null:C(i)),T=await m();if(!T.ok)return H(e,k,M)?{ok:!1,code:T.code}:{ok:!1,code:"over-budget"};let y=await h.appendBinary(k,M);return b(y),w(e),y.ok?(e.batches+=1,e.batchBytes+=k.payload.byteLength,y.skipped?{ok:!0,id:k.id,revision:u,skipped:!0}:{ok:!0,id:k.id,revision:u}):H(e,k,M)?{ok:!1,code:y.code}:{ok:!1,code:y.code}}async function le(e,{records:n=[],authority:t=null,epoch:o=null,sequence:r=null}={}){let i=(n||[]).filter(u=>u&&u.id!==void 0&&typeof u.revision=="number");if(!i.length)return{ok:!0,acknowledged:0};let l=await m();if(!l.ok)return{ok:!1,code:l.code};let c=await h.acknowledgeBinary({channel:e.channel,version:e.version,writerId:a,records:i,authority:t,epoch:o,sequence:r});return b(c),w(e),c.ok?{ok:!0,acknowledged:c.acknowledged}:{ok:!1,code:c.code}}async function ue(e,{records:n=[],proof:t=null}={}){let o=(n||[]).filter(u=>u&&u.id!==void 0&&typeof u.revision=="number");if(!o.length)return{ok:!0,retired:[]};if(typeof e.validateCheckpoint!="function")return{ok:!0,retired:[]};let r;try{r=await e.validateCheckpoint(t,o.map(({id:u,revision:d})=>({id:u,revision:d})))}catch{return{ok:!1,code:"invalid",retired:[]}}if(!Array.isArray(r))return{ok:!1,code:"invalid",retired:[]};let i=o.filter(u=>r.some(d=>d&&d.revision===u.revision&&F(d.id,u.id)));if(!i.length)return{ok:!0,retired:[]};let l=await m();if(!l.ok)return{ok:!1,code:l.code,retired:[]};let c=await h.checkpointBinary({channel:e.channel,version:e.version,writerId:a,records:i});return b(c),w(e),c.ok?{ok:!0,retired:c.retired}:{ok:!1,code:c.code,retired:[]}}function L(e){return e&&typeof e.byteLength=="number"&&e.byteLength>0?e:null}async function K(e,n,t=null){for(let o=0;o<3;o++){let r=t?.capsuleId??null,i=[];for(let{id:v,revision:be}of n){let j=await h.get(v);if(!j.ok||!j.record)continue;let U=j.record;U.revision!==be||U.kind!=="binary-batch"||!U.capsuleId||(r||(r=U.capsuleId),F(r,U.capsuleId)&&i.push(U))}if(!r||!(i.length||t))return{ok:!0,retired:[]};let l=await h.get(r);if(!l.ok||!l.record)return{ok:!1,code:"missing"};let c=l.record,u=[L(c.payload?.owned),...i.filter(v=>v.origin!=="dependency").map(v=>L(v.payload))].filter(Boolean),d=[L(c.payload?.dependencies),...i.filter(v=>v.origin==="dependency").map(v=>L(v.payload))].filter(Boolean),k=u.length?C(await e.merge(u)):new Uint8Array(0),M=d.length?C(await e.merge(d)):new Uint8Array(0),T={base:c.payload?.base??new Uint8Array(0),dependencies:M,owned:k};t&&(T=await t.rebuild(T));let y=Math.max(e.revision,c.revision)+1;e.revision=y;let x=await h.compactBinary({channel:e.channel,version:e.version,capsuleId:r,expectedRevision:c.revision,replacement:{revision:y,updated:E?.()??Date.now(),context:t?.context,payload:T},inputs:i.map(v=>({id:v.id,revision:v.revision}))});if(x.ok)return i.length&&(e.batches=e.batchBytes=0),{ok:!0,retired:x.retired,revision:x.revision};if(x.code!=="stale")return{ok:!1,code:x.code}}return{ok:!1,code:"stale"}}async function de(e,{records:n=[]}={}){if(typeof e.merge!="function")return{ok:!1,code:"invalid",retired:[]};let t=(n||[]).filter(i=>i&&i.id!==void 0&&typeof i.revision=="number");if(!t.length)return{ok:!0,retired:[]};let o=await m();if(!o.ok)return{ok:!1,code:o.code,retired:[]};let r=await K(e,t);return b(r),w(e),r.ok?{ok:!0,retired:r.retired}:{ok:!1,code:r.code,retired:[]}}async function fe(e,{key:n,context:t,rebuild:o}={}){let r=await m(),i=r.ok?await K(e,[],{capsuleId:X(e,String(n)),context:t,rebuild:o}):r;return b(i),i}function $(e){e.timer&&clearTimeout(e.timer),e.timer=null,e.burstStart=0;let n=async()=>{let t=await ce(e);return t.ok?re(e):t};return e.writing=e.writing.then(n,n),e.writing}async function pe(e){let n=await m();if(!n.ok)return{ok:!1,code:n.code,records:[],status:_()};let t=await h.list();if(b(t),!t.ok)return{ok:!1,code:t.code,records:[],status:_()};let o=await Te(a);return{ok:!0,records:t.records.filter(i=>i.channel===e.channel&&!o.has(i.writerId)).map(i=>({...i,supported:i.version===e.version})),status:_()}}async function he(e,n,{revision:t}={}){let o=await m();if(!o.ok)return{ok:!1,code:o.code};e.timer&&clearTimeout(e.timer),e.timer=null,e.burstStart=0,await e.writing;let r=D(n),i=e.pending.get(r);i&&(t===void 0||i.revision===t)&&e.pending.delete(r);let l=e.held.get(r);l&&(t===void 0||l.revision===t)&&e.held.delete(r);let c=await h.remove(n,{revision:t});return b(c),w(e),c.ok?{ok:!0,id:n,revision:t}:{ok:!1,code:c.code}}function ke(e,n){return e.listeners.add(n),()=>e.listeners.delete(n)}function ge(e){e.timer&&clearTimeout(e.timer),e.timer=null,e.burstStart=0;let n=$(e).catch(()=>({ok:!1,code:"aborted"}));return e.listeners.clear(),S.delete(e.channel),S.size||B.delete(N),n}let N={capture:ee,settle:te,pinCapture:J,coverCapture:Z};function ve(e){return{channel:e.channel,version:e.version,stage:n=>ie(e,n),flush:()=>$(e),list:()=>pe(e),dismiss:(n,t)=>he(e,n,t),append:n=>ae(e,n),markAcknowledged:n=>le(e,n),checkpoint:n=>ue(e,n),compact:n=>de(e,n),rebase:n=>fe(e,n),subscribe:n=>ke(e,n),dispose:()=>ge(e)}}function we({channel:e,version:n=1,readSaved:t=null,describe:o=null,validateCheckpoint:r=null,merge:i=null}={}){if(!e||typeof e!="string")throw new TypeError("clay.recovery.register needs a channel name");let l=S.get(e);if(l)throw new Error(`clay.recovery: the "${e}" channel is already registered at version ${l.version}`);let c={channel:e,version:n,readSaved:t,describe:o,validateCheckpoint:r,merge:i,revision:0,pending:new Map,held:new Map,batchQueue:new Map,queuedBytes:0,batches:0,batchBytes:0,compaction:null,timer:null,burstStart:0,writing:Promise.resolve(),listeners:new Set};return S.set(e,c),B.add(N),m(),ve(c)}return{register:we,status:_,subscribe(e){return Q.add(e),()=>Q.delete(e)}}}var Pe=Ce();export{xe as a,De as b,qe as c,ze as d,Ce as e,Pe as f};
@@ -1 +1 @@
1
- import{a as D,b as x}from"./c-A7LS5UZW.js";import{b as L,c as M,d as _,f as N}from"./c-VO6RSFCO.js";import"./c-WN3MXOLT.js";import"./c-EQ5NBOGA.js";import"./c-C7SUMNMI.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-U4TWEIKZ.js";import"./c-HA6INT6J.js";import"./c-ICMAOOGK.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var m="This computer",C=64,O=64,R=/^[\x20-\x7e]{1,128}$/;function X(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2)+Date.now().toString(36)}function B(e){return typeof e!="string"?m:e.trim().slice(0,O)||m}function v(e){let r=_(e===void 0?null:e);return r.ok?r.target:null}function j(e,r){let c=null,f=-1;for(let l of r)l.editing===null||l.n<=f||(c=l.editing,f=l.n);return e.editing!==null&&e.n>=f?e.editing:c}function Y({scope:e=null,key:r=null,store:c=N,channel:f=null,label:l=m}={}){let S=B(l),w=r??"clay-live:"+(e??(typeof window<"u"?window.location.pathname:"/")),P="local:"+(e??w),b=X(),i=new Map,d=null,u=0,p=null,I=null,s=null,g=null,a=!1;function h(n){p&&p.post({type:D,from:b,...n})}function y(){let n={id:b,you:!0,n:u,editing:d},t=[];for(let o of i.values())t.push({id:o.id,you:!1,n:o.n,editing:o.editing});let E=[n,...t].sort((o,A)=>o.id<A.id?-1:o.id>A.id?1:0);c.receive({people:[{id:P,name:S,you:!0,canEdit:!0,editing:j(n,t),sessions:E}],anonymous:0})}function T(n){if(!n||n.from===b||typeof n.from!="string"||!R.test(n.from))return;let t=i.get(n.from);if(n.op==="bye"){t&&i.delete(n.from),y();return}if(n.op!=="hello"&&n.op!=="update"&&n.op!=="beat"||!t&&i.size>=C)return;let E=n.op==="beat"?t?t.editing:null:v(n.editing),o=Number.isSafeInteger(n.n)&&n.n>=0?n.n:0;t&&o<t.n||(i.set(n.from,{id:n.from,n:o,editing:E,seenAt:Date.now()}),n.op==="hello"&&!t&&h({op:"hello",n:u,editing:d,label:S}),y())}function U(){if(!a)return;h({op:"beat",n:u});let n=Date.now(),t=!1;for(let[E,o]of i)n-o.seenAt<=M||(i.delete(E),t=!0);t&&y()}function k(n){let t=n&&typeof n=="object"&&"editing"in n?n.editing:null;return d=v(t),u+=1,h({op:"update",n:u,editing:d}),y(),!0}return{sessionId:b,start(){return a||(a=!0,p=f??x(w),I=p.subscribe("presence",T),s=c.attachTransport({send:k}),h({op:"hello",n:u,editing:d,label:S}),y(),g=setInterval(U,L)),s},stop(){a&&(a=!1,g!==null&&clearInterval(g),g=null,h({op:"bye"}),i.clear(),I?.(),I=null,p=null,s?.detach(),s=null)}}}export{m as LOCAL_LABEL,C as MAX_SESSIONS,Y as localPresence};
1
+ import{a as D,b as x}from"./c-A7LS5UZW.js";import{b as L,c as M,d as _,f as N}from"./c-HBSBQBD7.js";import"./c-WN3MXOLT.js";import"./c-26W3BMWK.js";import"./c-JEWSJHMK.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-U4TWEIKZ.js";import"./c-HA6INT6J.js";import"./c-ICMAOOGK.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var m="This computer",C=64,O=64,R=/^[\x20-\x7e]{1,128}$/;function X(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2)+Date.now().toString(36)}function B(e){return typeof e!="string"?m:e.trim().slice(0,O)||m}function v(e){let r=_(e===void 0?null:e);return r.ok?r.target:null}function j(e,r){let c=null,f=-1;for(let l of r)l.editing===null||l.n<=f||(c=l.editing,f=l.n);return e.editing!==null&&e.n>=f?e.editing:c}function Y({scope:e=null,key:r=null,store:c=N,channel:f=null,label:l=m}={}){let S=B(l),w=r??"clay-live:"+(e??(typeof window<"u"?window.location.pathname:"/")),P="local:"+(e??w),b=X(),i=new Map,d=null,u=0,p=null,I=null,s=null,g=null,a=!1;function h(n){p&&p.post({type:D,from:b,...n})}function y(){let n={id:b,you:!0,n:u,editing:d},t=[];for(let o of i.values())t.push({id:o.id,you:!1,n:o.n,editing:o.editing});let E=[n,...t].sort((o,A)=>o.id<A.id?-1:o.id>A.id?1:0);c.receive({people:[{id:P,name:S,you:!0,canEdit:!0,editing:j(n,t),sessions:E}],anonymous:0})}function T(n){if(!n||n.from===b||typeof n.from!="string"||!R.test(n.from))return;let t=i.get(n.from);if(n.op==="bye"){t&&i.delete(n.from),y();return}if(n.op!=="hello"&&n.op!=="update"&&n.op!=="beat"||!t&&i.size>=C)return;let E=n.op==="beat"?t?t.editing:null:v(n.editing),o=Number.isSafeInteger(n.n)&&n.n>=0?n.n:0;t&&o<t.n||(i.set(n.from,{id:n.from,n:o,editing:E,seenAt:Date.now()}),n.op==="hello"&&!t&&h({op:"hello",n:u,editing:d,label:S}),y())}function U(){if(!a)return;h({op:"beat",n:u});let n=Date.now(),t=!1;for(let[E,o]of i)n-o.seenAt<=M||(i.delete(E),t=!0);t&&y()}function k(n){let t=n&&typeof n=="object"&&"editing"in n?n.editing:null;return d=v(t),u+=1,h({op:"update",n:u,editing:d}),y(),!0}return{sessionId:b,start(){return a||(a=!0,p=f??x(w),I=p.subscribe("presence",T),s=c.attachTransport({send:k}),h({op:"hello",n:u,editing:d,label:S}),y(),g=setInterval(U,L)),s},stop(){a&&(a=!1,g!==null&&clearInterval(g),g=null,h({op:"bye"}),i.clear(),I?.(),I=null,p=null,s?.detach(),s=null)}}}export{m as LOCAL_LABEL,C as MAX_SESSIONS,Y as localPresence};
@@ -1,4 +1,4 @@
1
- import{a as ee}from"./c-755ZOHOM.js";import{b as Q}from"./c-3G2DGZUP.js";import{p as K,q as Z}from"./c-EHAR4RJJ.js";import"./c-LD6UVV5R.js";import"./c-PGSBXHUE.js";import{a as B,h as X}from"./c-KU3PX7LL.js";import"./c-EQ5NBOGA.js";import"./c-IJUK2GPW.js";import"./c-C7SUMNMI.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-U4TWEIKZ.js";import"./c-UW6MMZ4V.js";import"./c-XQXZAO7N.js";import"./c-S7LK4KUE.js";import"./c-MOP5KBWZ.js";import"./c-2YYDMLNZ.js";import"./c-HA6INT6J.js";import"./c-ICMAOOGK.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var We=Object.defineProperty,Ve=(e,t)=>{for(var r in t)We(e,r,{get:t[r],enumerable:!0})},Fe=["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"],ze=new Set(Fe),_e=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),he=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]),te=new Set(["checked","selected","disabled","readOnly","paused"]);function Je(e,t){return t==null?te.has(e)?!1:"":te.has(e)?t==="false"?!1:!!t:t}var Ye={};Ve(Ye,{CodecRefused:()=>et,EmptyListInsert:()=>R,MAX_RULE_DEPTH:()=>L,MaxRuleDepthExceeded:()=>G,NoRulesTag:()=>Ze,RuleTargetReadOnly:()=>ge,RulesParseError:()=>$,ShapeMismatch:()=>ye,UnknownCodec:()=>we,UnknownRulesVersion:()=>me,WriteNotRoundTripped:()=>Ke,WriteRefused:()=>Ge,WriteRejected:()=>Qe});var $=class extends Error{constructor(e,t){super(e),this.name="RulesParseError",this.cause=t}},me=class extends Error{constructor(e){super(`unknown rules version: ${e}. Library supports "1" and "2".`),this.name="UnknownRulesVersion",this.version=e}},L=20,G=class extends Error{constructor(e){super(`rule depth exceeded ${L} at path: ${e.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=e}},ye=class extends Error{constructor(e){super(`shape mismatch: ${e.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=e}},R=class extends Error{constructor(e,t){super(t?`cannot add items to empty list at "${e.join(".")}" \u2014 ${t}`:`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}},ge=class extends Error{constructor(e){super(`cannot write to read-only DOM property "${e}"`),this.name="RuleTargetReadOnly",this.target=e}},Ge=class extends Error{constructor(e){super(`write refused: ${e.length} write(s) broke the content-only policy`),this.name="WriteRefused",this.refusals=e}};function Xe(e){return e.reduce((t,r)=>typeof r=="number"?`${t}[${r}]`:t?`${t}.${r}`:String(r),"")||"(root)"}var Ke=class extends Error{constructor(e){super(`write did not round-trip at "${Xe(e)}"`),this.name="WriteNotRoundTripped",this.path=e}},Ze=class extends Error{constructor(e){super(`no <script data-rules-name~="${e}"> rules tag in this document`),this.name="NoRulesTag",this.token=e}},Qe=class extends Error{constructor(e,t){super(`write rejected: ${e.length} unknown key(s), ${t.length} rule(s) with no matching element`),this.name="WriteRejected",this.unknownKeys=e,this.unmatched=t}},we=class extends Error{constructor(e){super(`unknown codec "${e}": no codec by that name is given to this call`),this.name="UnknownCodec",this.code="unknown-codec",this.codec=e}},et=class extends Error{constructor(e,t){super(t),this.name="CodecRefused",this.code=e}};function M(e){let t=0,r=null,l=-1;for(let n=0;n<e.length;n++){let o=e[n];o==="\\"?n++:r?o===r&&(r=null):o==='"'||o==="'"?r=o:o==="["||o==="("?t++:o==="]"||o===")"?t>0&&t--:o==="@"&&t===0&&(l=n)}return l}var re="[*]";function j(e){let t=M(e),r=t===-1?e:e.slice(0,t),l=r.endsWith(re),n={selector:l?r.slice(0,-re.length):r,prop:t===-1?null:e.slice(t+1)||null};return l&&(n.all=!0),n}function ve(e){let t=0,r=null,l=-1,n=!1;for(let o=0;o<e.length;o++){let i=e[o];i==="\\"?o++:r?i===r&&(r=null):i==='"'||i==="'"?r=i:i==="["||i==="("?t++:i==="]"||i===")"?t>0&&t--:t===0&&i===">"?l=o:t===0&&i===","&&(n=!0)}return n||l===-1||!tt(e,l+1)?null:e.slice(0,l).trim()||null}function tt(e,t){let r=t,l=e.replace(/\s+$/,"").length;for(;r<l&&/\s/.test(e[r]);)r++;let n=0,o=null;for(;r<l;r++){let i=e[r];if(i==="\\")r++;else if(o)i===o&&(o=null);else if(i==='"'||i==="'")o=i;else if(i==="["||i==="(")n++;else if(i==="]"||i===")")n>0&&n--;else if(n===0&&(i==="+"||i==="~"||/\s/.test(i)))return!1}return!0}var rt=/^codec\(([a-z][a-z0-9-]*)\)$/;function P(e){if(typeof e!="string")return null;let t=M(e);if(t===-1)return null;let r=rt.exec(e.slice(t+1));if(!r)return null;let{selector:l,all:n}=j(e);if(n)throw new $("A @codec(name) rule cannot use [*].");return{selector:l,name:r[1]}}var nt=/^--[A-Za-z0-9_-]+$/;function be(e){return typeof e=="string"&&nt.test(e)}function xe(e){let t=[],r=[],l=null,n=0;for(let o=0;o<e.length;o++){let i=e[o];if(l){i==="\\"?o++:i===l&&(l=null);continue}if(i==="/"&&e[o+1]==="*"){let a=e.indexOf("*/",o+2);o=a===-1?e.length:a+1;continue}i==='"'||i==="'"?l=i:i==="("?r.push(")"):i==="["?r.push("]"):i==="{"?r.push("}"):(i===")"||i==="]"||i==="}")&&r[r.length-1]===i?r.pop():i===";"&&r.length===0&&(t.push(e.slice(n,o)),n=o+1)}return t.push(e.slice(n)),t}function lt(e){let t="",r=null;for(let l=0;l<e.length;l++){let n=e[l];if(r){t+=n,n==="\\"&&l+1<e.length?t+=e[++l]:n===r&&(r=null);continue}if(n==="/"&&e[l+1]==="*"){let o=e.indexOf("*/",l+2);l=o===-1?e.length:o+1,t+=" ";continue}(n==='"'||n==="'")&&(r=n),t+=n}return t}function Ae(e){e=lt(e);let t=e.indexOf(":");if(t===-1)return null;let r=e.slice(0,t).trim(),l=e.slice(t+1).trim(),n=/!\s*important\s*$/i.exec(l);return n&&(l=l.slice(0,n.index).trim()),{name:r,value:l,important:!!n}}function Te(e,t){if(e==null)return null;let r=null;for(let l of xe(String(e))){let n=Ae(l);!n||n.name!==t||(!r||n.important||!r.important)&&(r=n)}return r?r.value:null}function ot(e,t,r){let l=e==null?"":String(e),n=r==null||r==="",o=xe(l),i=o.map(Ae),a=i.some(u=>u&&u.name===t&&u.important),s=[],c=!1;o.forEach((u,d)=>{let m=i[d];if(!m||m.name!==t){s.push(u);return}if(n||c)return;let p=/^\s*/.exec(u)[0];s.push(`${p}${t}: ${r}${a?" !important":""}`),c=!0});let f=s.join(";");if(!n&&!c){let u=f.trimEnd();f=u===""?`${t}: ${r}`:`${u}${u.endsWith(";")?" ":"; "}${t}: ${r}`}return f.trim()===""?null:f}function it(e,t,r,l){let n=e.attr(t,"style");if((Te(n,r)??"")===l)return;let o=ot(n,r,l);o==null?e.removeAttr(t,"style"):e.attr(t,"style",o)}var at='The @codec(name) rule form needs a rules tag with data-rules-version="2".',st="A @codec(name) rule must be the value of a top level key.";function Oe(e,t){let r=P(e);return r?{...r,codec:t.codecs[r.name]}:null}function Ee(e,t={}){let r=t.version??"1",l=t.codecs??{};n(e,0);function n(o,i){if(!(i>L)){if(typeof o=="string"){let a=P(o);if(!a)return;if(r!=="2")throw new $(at);if(i!==1)throw new $(st);if(!Object.prototype.hasOwnProperty.call(l,a.name))throw new we(a.name);return}if(Array.isArray(o)){n(o[1],i+1);return}if(o&&typeof o=="object")for(let a of Object.values(o))n(a,i+1)}}}function ke(e,t,r,l={}){if(Object.prototype.hasOwnProperty.call(l,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");return Ee(r,l),V(e,t,r,{depth:0,path:[]},l)}function V(e,t,r,l,n){if(l.depth>L)throw new G(l.path);if(typeof r=="string")return ut(e,t,r,l,n);if(Array.isArray(r)){let[o,i]=r,a=e.find(t,o,n);return Ne(n,l,a),a.map((s,c)=>V(e,s,i,{depth:l.depth+1,path:[...l.path,c]},n))}if(typeof r=="object"&&r!==null){let o={};for(let[i,a]of Object.entries(r))o[i]=V(e,t,a,{depth:l.depth+1,path:[...l.path,i]},n);return o}return null}function ut(e,t,r,l,n){if(r.endsWith("[]")){let f=r.slice(0,-2),u=e.find(t,f,n);return Ne(n,l,u),u.map(d=>e.text(d))}let o=Oe(r,n);if(o)return ct(e,t,o,n);if(r.startsWith("@"))return W(e,t,r.slice(1));let i=M(r);if(i!==-1){let{selector:f,all:u}=j(r),d=r.slice(i+1),m=f?e.find(t,f,n):[t];return u&&n.allMatches?m.map(p=>W(e,p,d)):m.length===0?null:W(e,m[0],d)}if(r===".")return e.text(t);let{selector:a,all:s}=j(r),c=e.find(t,a,n);return s&&n.allMatches?c.map(f=>e.text(f)):c.length===0?null:e.text(c[0])}function ct(e,t,{selector:r,codec:l},n){let o=r?e.find(t,r,n):[t];return o.length===0?null:l.read(e,o[0],{query:n.query,view:n.view,region:n.region})}function Ne(e,t,r){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),r)}catch(l){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,l)}}function W(e,t,r){if(be(r))return Te(e.attr(t,"style"),r);if(ze.has(r)){let n=e.prop(t,r);return n==null?null:String(n)}return e.attr(t,r)??null}function ft(e,t,r,l){let n=e.length,o=t.length,i=new Array(n).fill(-1);if(l){let h=new Set;for(let y=0;y<n;y++){let g=l[y];!(g>=0&&g<o)||h.has(g)||(i[y]=g,h.add(g))}}if(n===0||o===0)return i;let a=e.map(h=>ne(h,r)),s=t.map(h=>ne(h,r)),c=new Array(o).fill(!1);for(let h of i)h>=0&&(c[h]=!0);let f=new Map;s.forEach((h,y)=>{c[y]||f.set(h,f.has(h)?-1:y)});let u=new Map;a.forEach((h,y)=>{i[y]>=0||u.set(h,(u.get(h)||0)+1)}),a.forEach((h,y)=>{if(i[y]>=0||u.get(h)!==1)return;let g=f.get(h);g===void 0||g===-1||c[g]||(i[y]=g,c[g]=!0)});let d=[];for(let h=0;h<n;h++)i[h]<0&&d.push(h);let m=[];for(let h=0;h<o;h++)c[h]||m.push(h);if(d.length===0||m.length===0)return i;let p=n*o+1,w=dt(e,t,r),v=(h,y)=>w(h,y)*p+Math.abs(h-y);for(let[h,y]of pt(d,m,v))i[h]=y;return i}var Se=e=>typeof e=="object"&&e!==null;function ne(e,t){if(!Se(t))return e==null?" null":String(e);let r=Object.keys(t);return JSON.stringify(r.map(l=>{let n=JSON.stringify(e?.[l]);return n===void 0?" undef":n}))}function dt(e,t,r){if(!Se(r))return(a,s)=>e[a]===t[s]?0:1;let l=Object.keys(r),n=a=>l.map(s=>JSON.stringify(a?.[s])),o=e.map(n),i=t.map(n);return(a,s)=>{let c=o[a],f=i[s],u=0;for(let d=0;d<l.length;d++)c[d]!==f[d]&&u++;return u}}function pt(e,t,r){return e.length<=t.length?le(e,t,r,!1):le(t,e,(l,n)=>r(n,l),!0)}function le(e,t,r,l){let n=e.length,o=t.length,i=[];for(let u=0;u<=n;u++)i.push(new Float64Array(o+1).fill(1/0));let a=[];for(let u=0;u<=n;u++)a.push(new Uint8Array(o+1));for(let u=0;u<=o;u++)i[n][u]=0;for(let u=n-1;u>=0;u--)for(let d=o-1;d>=0;d--){let m=r(e[u],t[d])+i[u+1][d+1],p=i[u][d+1];m<=p?(i[u][d]=m,a[u][d]=1):i[u][d]=p}let s=[],c=0,f=0;for(;c<n&&f<o;)a[c][f]&&(s.push(l?[t[f],e[c]]:[e[c],t[f]]),c++),f++;return s}function Re(e,t,r,l,n,o,i,a={}){let s=e.find(t,r,a);if(n.length===0){s.forEach(A=>e.remove(A)),F(a,"onRowsApplied",o.path,[]);return}let c=n.length>s.length,f=s[0]||null;if(c&&!f&&(f=gt(e,t,r,a),!f))throw new R(o.path);let u=s.map(A=>yt(e,A,l,a)),d=null;if(c&&f){d=e.clone(f);let A=a.templateAttr&&e.attr(f,a.templateAttr)!=null;a.templateAttr&&e.removeAttr(d,a.templateAttr),A&&e.removeAttr(d,"hidden");let T=e.stripIds(d);T>0&&console.warn(`[hyper-html-api] stripped ${T} id attribute(s) from cloned template at "${o.path.join(".")||"(root)"}"`)}let m=ft(n,u,l,ht(e,s,n,o,a)),p=s.length>0?e.parent(s[0]):xt(e,t,r,f,o,a),w=s.length>0?$e(e,p,s[0]):0,v=Ot(e,s),h=new Set,y=[],g=n.map((A,T)=>{let k=m[T];if(k>=0)return h.add(k),y.push(!1),s[k];y.push(!0);let O=e.clone(d);return e.stripIds(O),O});s.forEach((A,T)=>{h.has(T)||e.remove(A)}),v?Tt(e,p,w,g,y):Et(e,g,y,p,w),mt(e,g,l,n,o,i,a),F(a,"onRowsApplied",o.path,g)}function F(e,t,r,l){if(typeof e[t]=="function")try{return e[t](r.slice(),l)}catch(n){console.warn(`[hyper-html-api] ${t} threw at "${r.join(".")||"(root)"}"`,n);return}}function ht(e,t,r,l,n){let o=F(n,"identifyRows",l.path,r);if(!Array.isArray(o))return null;let i=new Array(r.length).fill(-1),a=new Set,s=new Map(t.map((c,f)=>[e.identity(c),f]));for(let c=0;c<r.length;c++){if(!o[c])continue;let f=s.get(e.identity(o[c]));f===void 0||a.has(f)||(i[c]=f,a.add(f))}return i}function mt(e,t,r,l,n,o,i){t.forEach((a,s)=>{if(r===null){let c=l[s],f=c==null?"":String(c);e.text(a)!==f&&e.text(a,f)}else{let c=o(e,a,r,l[s],{depth:n.depth+1,path:[...n.path,s]},i);c&&c!==a&&(t[s]=c)}})}function yt(e,t,r,l){return r===null?e.text(t):ke(e,t,r,l.onRowsRead?{...l,onRowsRead:void 0}:l)}function $e(e,t,r){let l=e.children(t);for(let n=0;n<l.length;n++)if(e.sameNode(l[n],r))return n;return-1}function gt(e,t,r,l){if(!l.templateAttr)return null;let n=/^\s*:scope\s*>\s*/.test(r),o=new RegExp(":not\\(\\["+l.templateAttr.replace(/[.*+?^${}()|[\]\\-]/g,"\\$&")+"\\]\\)","g"),i=r.replace(/^\s*:scope\s*>\s*/,"").replace(o,""),a=n?wt(i):0,s=ve(i),c=t;for(;c;){let f=e.find(c,i,{includeRulesTag:!1,templateAttr:null});for(let u of f)if(e.attr(u,l.templateAttr)!=null&&!(n&&!bt(e,t,u,a))&&!(s&&!e.matches(e.parent(u),s)))return u;c=e.parent(c)}return null}function wt(e){let t=0,r=null,l=1;for(let n=0;n<e.length;n++){let o=e[n];if(o==="\\")n++;else if(r)o===r&&(r=null);else if(o==='"'||o==="'")r=o;else if(o==="["||o==="(")t++;else if(o==="]"||o===")")t>0&&t--;else if(t===0&&o===">")l++;else{if(t===0&&(o==="+"||o==="~"))return null;if(t===0&&/\s/.test(o)){if(!vt(e,n))return null;for(;n+1<e.length&&/\s/.test(e[n+1]);)n++}}}return l}function vt(e,t){let r=t;for(;r<e.length&&/\s/.test(e[r]);)r++;let l=t>0?e[t-1]:"",n=r<e.length?e[r]:"";return oe(l)||oe(n)}function oe(e){return e===">"||e==="+"||e==="~"}function bt(e,t,r,l){if(l===null)return!0;let n=r;for(let s=0;s<l;s++)if(n=e.parent(n),!n)return!1;let o=e.prop(t,"tagName");if(!o)return!0;let i=e.prop(n,"tagName");if(!i||String(i).toLowerCase()!==String(o).toLowerCase())return!1;let a=new Set(ie(e,n));return ie(e,t).every(s=>a.has(s))}function ie(e,t){let r=e.attr(t,"class");return r?String(r).split(/\s+/).filter(Boolean):[]}function xt(e,t,r,l,n,o){let i=e.parent(l);if(i&&At(e,t,i)&&!se(e,i,o))return i;let a=ve(r);if(!a)throw new R(n.path,`the list selector "${r}" 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 s=(a===":scope"?e.prop(t,"tagName")?[t]:[]:e.find(t,a,o)).filter(c=>!se(e,c,o));if(s.length===0)throw new R(n.path,`no container matching "${a}" inside this context to hold the new rows`);if(s.length>1)throw new R(n.path,`"${a}" matches ${s.length} containers inside this context, so the new rows have no single destination`);return s[0]}function At(e,t,r){let l=r;for(;l;){if(e.sameNode(l,t))return!0;l=e.parent(l)}return e.parent(t)?!1:e.find(t,"*",{includeRulesTag:!0,templateAttr:null}).some(n=>e.sameNode(n,r))}var ae=["no-data","editor-ui"];function se(e,t,r){let l=t;for(;l;){if(r.templateAttr&&e.attr(l,r.templateAttr)!=null||ae.some(o=>e.attr(l,o)!=null))return!0;let n=e.attr(l,"clay");if(n&&n.split(/\s+/).some(o=>ae.includes(o)))return!0;l=e.parent(l)}return!1}function Tt(e,t,r,l,n){let o=e.children(t),i=o.map(s=>e.identity(s)),a=!1;l.forEach((s,c)=>{let f=e.identity(s),u=r+c;if(i[u]===f)return;if(!n[c]){let m=i.indexOf(f);m!==-1&&(i.splice(m,1),o.splice(m,1))}let d=Math.min(u,o.length);d<o.length?e.insertBefore(o[d],s):o.length?a?e.insertAfter(o[o.length-1],s):(e.insertAt(t,s,u),a=!0):e.insertAt(t,s,0),i.splice(d,0,f),o.splice(d,0,s)})}function Ot(e,t){if(t.length<=1)return!0;let r=e.parent(t[0]);if(!r)return!1;let l=new Map(e.children(r).map((o,i)=>[e.identity(o),i])),n=[];for(let o of t){let i=l.get(e.identity(o));if(i===void 0)return!1;n.push(i)}return n.sort((o,i)=>o-i),n[n.length-1]-n[0]===n.length-1}function Et(e,t,r,l,n){let o=null,i=n;for(let a=0;a<t.length;a++){if(!r[a]){o=t[a];continue}let s=o?e.parent(o):l;if(!s)continue;let c=o?$e(e,s,o)+1:i++;e.insertAt(s,t[a],c),o=t[a]}}function kt(e,t,r,l,n={}){if(Object.prototype.hasOwnProperty.call(n,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");Ee(r,n);let o=[];if(z(r,l,[],o),o.length)throw new ye(o);I(e,t,r,l,{depth:0,path:[]},n)}function I(e,t,r,l,n,o={}){if(n.depth>L)throw new G(n.path);if(l===void 0)return t;if(typeof r=="string")return Nt(e,t,r,l,n,o);if(Array.isArray(r)){let[i,a]=r;return Re(e,t,i,a,l,n,I,o),t}if(typeof r=="object"&&r!==null){for(let[i,a]of Object.entries(r)){let s=I(e,t,a,l==null?l:l[i],{depth:n.depth+1,path:[...n.path,i]},o);s&&s!==t&&(t=s)}return t}return t}function Nt(e,t,r,l,n,o){if(r.endsWith("[]")){let u=r.slice(0,-2);return Re(e,t,u,null,l,n,I,o),t}let i=Oe(r,o);if(i){let u=i.selector?e.find(t,i.selector,o):[t];return u.length&&i.codec.write(e,u[0],l,{query:o.query}),t}if(r.startsWith("@"))return ce(e,t,r.slice(1),l);let a=M(r);if(a!==-1){let{selector:u,all:d}=j(r),m=r.slice(a+1),p=u?e.find(t,u,o):[t];for(let w of d?p:p.slice(0,1))ce(e,w,m,l);return t}if(r===".")return ue(e,t,l),t;let{selector:s,all:c}=j(r),f=e.find(t,s,o);for(let u of c?f:f.slice(0,1))ue(e,u,l);return t}function ue(e,t,r){let l=r==null?"":String(r);e.text(t)!==l&&e.text(t,l)}function St(e,t,r,l){if(e.styleVar){e.styleVar(t,r,l);return}it(e,t,r,l)}function ce(e,t,r,l){if(be(r))return St(e,t,r,l==null?"":String(l).trim()),t;if(he.has(r)){let n=e.prop(t,r);if(n===l||n!=null&&l!=null&&String(n)===String(l))return t;throw new ge(r)}if(r==="outerHTML"){let n=l==null?"":String(l);return e.replaceWith(t,n)}if(_e.has(r)){let n=Je(r,l);return e.prop(t,r)!==n&&e.prop(t,r,n),t}if(l==null)e.attr(t,r)!=null&&e.removeAttr(t,r);else{let n=String(l);e.attr(t,r)!==n&&e.attr(t,r,n)}return t}function z(e,t,r,l){if(t!==void 0){if(typeof e=="string"){if(P(e))return;if(e.endsWith("[]")){Array.isArray(t)?t.forEach((n,o)=>{typeof n=="object"&&n!==null&&l.push({path:S([...r,o]),expected:"scalar",got:N(n)})}):l.push({path:S(r),expected:"array",got:N(t)});return}t!==null&&typeof t=="object"&&l.push({path:S(r),expected:"scalar",got:N(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){l.push({path:S(r),expected:"array",got:N(t)});return}let n=e[1];t.forEach((o,i)=>z(n,o,[...r,i],l));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){l.push({path:S(r),expected:"object",got:N(t)});return}for(let[n,o]of Object.entries(e))z(o,t[n],[...r,n],l)}}}function N(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function S(e){return e.join(".")}function Rt(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 r(n){let o=[],i=0;for(;i<n.length;){let a=n[i];if(/\s/.test(a)){i++;continue}if("{}".includes(a)){o.push({type:a,value:a}),i++;continue}if(a==="["){let u=!1,d=i+1;for(;d<n.length&&/\s/.test(n[d]);)d++;if(d<n.length&&/[a-zA-Z_]/.test(n[d])&&(u=!0),!u){o.push({type:a,value:a}),i++;continue}}if(a==="]"){o.push({type:a,value:a}),i++;continue}if(a===":"){o.push({type:t.COLON,value:a}),i++;continue}if(a===","){o.push({type:t.COMMA,value:a}),i++;continue}if(a==='"'||a==="'"){let u=a,d=i+1;for(;d<n.length&&n[d]!==u;)n[d]==="\\"&&d++,d++;o.push({type:t.STRING,value:n.substring(i+1,d),quoted:!0,sourceQuote:u}),i=d+1;continue}let s=i,c;for(;s<n.length&&!/[{},]/.test(n[s]);)if(n[s]===":"){let u=[":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"],d=!1;for(let m of u){let p=m.substring(1);if(n.substring(s+1,s+1+p.length)===p){d=!0,s+=p.length;break}}if(!d)break}else if(n[s]==="["){for(s++;s<n.length&&n[s]!=="]";){if(n[s]==='"'||n[s]==="'"){let u=n[s];for(s++;s<n.length&&n[s]!==u;)n[s]==="\\"&&s++,s++}s++}s<n.length&&n[s]==="]"&&s++}else s++;c=n.substring(i,s);let f=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(c)?f=t.NUMBER:c==="true"||c==="false"||c==="null"?f=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(c)&&(f=t.SELECTOR),o.push({type:f,value:c,quoted:!1}),i=s}return o}function l(n){let o="";for(let i=0;i<n.length;i++){let a=n[i];if("{}".includes(a.type)||"[]".includes(a.type)){o+=a.value;continue}if(a.type===t.COLON){o+=a.value;continue}if(a.type===t.COMMA){let s=n[i+1];if(s&&(s.type==="}"||s.type==="]"))continue;o+=a.value;continue}if(a.type===t.STRING&&a.quoted){let s=a.value;a.sourceQuote==="'"&&(s=s.replace(/\\'/g,"'"),s=s.replace(/(\\*)"/g,(c,f)=>f.length%2===0?f+'\\"':c)),o+=`"${s}"`;continue}if(a.type===t.NUMBER||a.type===t.BOOLEAN){o+=a.value;continue}if(a.type===t.SELECTOR||a.type===t.IDENTIFIER){o+=`"${a.value}"`;continue}o+=`"${a.value}"`}return o}try{let n=r(e),o=l(n);return JSON.parse(o)}catch(n){throw new $("Invalid extraction rules syntax: "+n.message,n)}}var $t=["1","2"];var Ar=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"]})}),Tr=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),jt=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui","live"]);var Or=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",...jt],refusedAttributePrefixes:["on"],urlAttributes:["href","src","srcset","action","formaction","poster","cite","data","ping","background","longdesc","usemap","xlink:href","manifest","codebase","icon"],refusedSchemes:["javascript","vbscript","data"],customPropertyValues:Object.freeze({maxLength:200,refusedCharacters:[";","{","}","<",">","\\"],refusedFunctions:["url","src","image","image-set","-webkit-image-set","cross-fade","element","expression","paint"]})});function Ct(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function Lt(e){return e?(e.nodeType===9||e.nodeType,e):null}function fe(e,t,r){!e||e.nodeType!==1||(t==="value"&&e.tagName==="INPUT"?e.value=r===null?"":r:t==="checked"&&e.tagName==="INPUT"?e.checked=r!==null:t==="selected"&&e.tagName==="OPTION"&&(e.selected=r!==null))}function Mt(e,t){e&&e.tagName==="TEXTAREA"&&(e.value=t)}function Ut(e){if(!e||e.nodeType!==1)return;let t=[e,...e.querySelectorAll?e.querySelectorAll("textarea, input, option"):[]];for(let r of t)if(r.tagName==="TEXTAREA")r.value=r.defaultValue;else if(r.tagName==="INPUT"){let l=r.type;l!=="file"&&l!=="checkbox"&&l!=="radio"&&(r.value=r.defaultValue),r.checked=r.defaultChecked}else r.tagName==="OPTION"&&(r.selected=r.defaultSelected)}var It={semanticExclude:!0,find(e,t,r={}){let l=Lt(e);if(!l||!l.querySelectorAll)return[];let n=Array.from(l.querySelectorAll(t));r.includeRulesTag||(n=n.filter(a=>!Ct(a)));let o=[];r.skip&&o.push(r.skip);let i=r.templateAttr===null?null:r.templateAttr||"cms-template";if(i&&o.push("["+i+"]"),o.length){let a=o.join(", ");n=n.filter(s=>!s.closest||!s.closest(a))}return n},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,Mt(e,t)},attr(e,t,r){if(r===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,r),fe(e,t,r)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t),fe(e,t,null)},prop(e,t,r){if(r===void 0){let l=e?e[t]:void 0;return l!==void 0?l:null}e[t]=r},clone(e){let t=e.cloneNode(!0);return Ut(t),t},insertAt(e,t,r){let l=e.children[r]||null;e.insertBefore(t,l)},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 r=e.ownerDocument.createElement("template");r.innerHTML=t;let l=r.content.firstElementChild;if(!l)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(l,e),l},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(r=>{r.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}};var U=It;var Pt="hha:upgrade-check:";function b(e,t){let r=e.querySelector(`meta[name="${t}"]`),l=r?r.getAttribute("content"):null;return l&&l.trim()?l.trim():null}function de(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function Dt(e,t){let r=de(e),l=de(t);if(!r||!l)return!1;let n=Math.max(r.length,l.length);for(let o=0;o<n;o++){let i=r[o]||0,a=l[o]||0;if(i!==a)return i>a}return!1}function qt(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function Ht(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function Bt({force:e=!1,doc:t,loc:r,fetchFn:l,now:n,ttlMs:o=864e5}={}){if(t=t||(typeof document<"u"?document:null),r=r||(typeof location<"u"?location:null),l=l||(d=>fetch(d)),n=n??Date.now(),!t)return null;let i=b(t,"hyper-source");if(!i)return null;let a=b(t,"hyper-version"),s;try{s=new URL(i,r?r.href:void 0)}catch{return null}if(r&&s.origin===r.origin&&s.pathname===r.pathname)return null;let c=`${Pt}${s.href}:${a||"none"}`,f,u=e?null:qt(c);if(u&&typeof u.checkedAt=="number"&&n-u.checkedAt<o)f=u.sourceVersion;else{try{let d=await l(s.href);if(!d.ok)throw new Error(`HTTP ${d.status}`);let m=await d.text(),p=new DOMParser().parseFromString(m,"text/html");f=b(p,"hyper-version")}catch{f=null}Ht(c,{checkedAt:n,sourceVersion:f})}return f?{available:Dt(f,a||"0.0.0"),currentVersion:a,sourceVersion:f,sourceUrl:s.href}:null}var Wt="script[data-rules-name]";function Vt(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function je(e,t){let r=e.find(t,Wt,{includeRulesTag:!0}),l=new Set,n=[];for(let o of r){let i=Vt(e.attr(o,"data-rules-name"));if(!i)continue;if(l.has(i)){console.warn(`hyper-html-api: duplicate rules tag name "${i}"; using the first.`);continue}let a=e.attr(o,"data-rules-version");if(!$t.includes(a))throw new me(a);l.add(i),n.push({name:i,rules:Rt(e.text(o)),version:a})}return n}function Ce(e,t){if(t!=="2"||!e||typeof e!="object"||Array.isArray(e))return{rules:e,carried:[]};let r={},l=[];for(let[n,o]of Object.entries(e)){let i=P(o);i?l.push({key:n,selector:i.selector}):r[n]=o}return{rules:r,carried:l}}function Le(e,t,r){return e.find(t,r)[0]||null}function Me(e,t){let r={};for(let{name:l,rules:n,version:o}of je(e,t)){let{rules:i,carried:a}=Ce(n,o),s=ke(e,t,i,{version:o});for(let{key:c,selector:f}of a){let u=Le(e,t,f);s[c]=u?e.prop(u,"innerHTML"):null}r[l]=s}return r}function Ft(e){let t=e||document,r=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:Me(U,t),version:b(r,"hyper-version")}}var pe=class extends Error{constructor(e,t){super(`could not fetch upgrade source: ${e}`),this.name="UpgradeSourceUnreachable",this.sourceUrl=e,this.cause=t}},zt=class extends Error{constructor(e){super(`upgrade source has no rules tags; refusing to drop all existing data: ${e}`),this.name="UpgradeSourceHasNoRules",this.sourceUrl=e}},_=class extends Error{constructor(e,t){super(e),this.name="UpgradeTransformInvalid",this.cause=t}},_t=class extends Error{constructor(e){super(`found ${e} script[type="text/hyper-upgrade"] tags; only one is allowed per document.`),this.name="UpgradeMultipleTransforms",this.count=e}},Jt="text/hyper-upgrade";function Yt(e,t){let r=e.find(t,`script[type="${Jt}"]`);if(r.length===0)return null;if(r.length>1)throw new _t(r.length);return e.text(r[0])||null}var Gt=new Function("url","return import(url)");async function Xt(e){let t=new Blob([e],{type:"text/javascript"}),r=URL.createObjectURL(t),l;try{l=await Gt(r)}catch(n){throw new _(`transform failed to load: ${n&&n.message?n.message:n}`,n)}finally{URL.revokeObjectURL(r)}if(typeof l.default!="function")throw new _("transform must `export default` a function");return l.default}function Ue(e,t){let r={carriedOver:0,discarded:0,listItems:0},l=J(t,e,r);return Y(t,e,r),{data:l,summary:r}}function J(e,t,r,l=!1){if(typeof e=="string")return e.endsWith("[]")?Array.isArray(t)?(r.listItems+=t.length,r.carriedOver+=t.length,t):l?[]:void 0:t==null||typeof t=="object"?l&&!Kt(e)?null:void 0:(r.carriedOver++,t);if(Array.isArray(e)){let[,n]=e;return Array.isArray(t)?(r.listItems+=t.length,t.map(o=>J(n,o,r,!0))):l?[]:void 0}if(typeof e=="object"&&e!==null){let n={};for(let[o,i]of Object.entries(e)){let a=J(i,t?.[o],r,l);a!==void 0&&(n[o]=a)}return n}}function Kt(e){let t=M(e);return t!==-1&&he.has(e.slice(t+1))}function Y(e,t,r){if(t!=null){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){if(typeof t!="object"||Array.isArray(t))return;let l=new Set(Object.keys(e));for(let n of Object.keys(t))l.has(n)?Y(e[n],t[n],r):r.discarded+=C(t[n]);return}if(Array.isArray(e)&&Array.isArray(t)){let l=e[1];t.forEach(n=>Y(l,n,r));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(r.discarded+=C(t))}}function C(e){return e==null?0:Array.isArray(e)?e.reduce((t,r)=>t+C(r),0):typeof e=="object"?Object.values(e).reduce((t,r)=>t+C(r),0):1}function Zt(e,t,r){let l=je(e,t),n={carriedOver:0,discarded:0,listItems:0},o={},i=new Set;for(let{name:a,rules:s,version:c}of l){if(i.add(a),!Object.prototype.hasOwnProperty.call(r,a)){o[a]={carriedOver:0,discarded:0,listItems:0};continue}let{rules:f,carried:u}=Ce(s,c),d=r[a],{data:m,summary:p}=Ue(Qt(d,u),f);kt(e,t,f,m,{templateAttr:"cms-template"});for(let{key:w,selector:v}of u){let h=Ie(d)?d[w]:void 0;if(h==null)continue;let y=Le(e,t,v);typeof h=="string"&&y?(e.prop(y,"innerHTML",h),p.carriedOver+=1):p.discarded+=1}o[a]=p,n.carriedOver+=p.carriedOver,n.discarded+=p.discarded,n.listItems+=p.listItems}for(let a of Object.keys(r))i.has(a)||(n.discarded+=C(r[a]));return{totals:n,byName:o,rulesTagCount:l.length}}function Ie(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Qt(e,t){if(!t.length||!Ie(e))return e;let r={...e};for(let{key:l}of t)delete r[l];return r}async function er({sourceUrl:e,dataByName:t,fromVersion:r,doc:l,loc:n,fetchFn:o}={}){if(l=l||(typeof document<"u"?document:null),n=n||(typeof location<"u"?location:null),o=o||(h=>fetch(h)),!l)throw new Error("upgrade.run requires a document context");if(e=e||b(l,"hyper-source"),!e)throw new Error("upgrade.run: no sourceUrl given and no hyper-source meta tag found");let i=new URL(e,n?n.href:void 0);r=r!==void 0?r:b(l,"hyper-version"),t=t||Me(U,l);let a;try{a=await o(i.href)}catch(h){throw new pe(i.href,h)}if(!a.ok)throw new pe(i.href,new Error(`HTTP ${a.status}`));let s=await a.text(),c=new DOMParser().parseFromString(s,"text/html"),f=b(c,"hyper-version"),u=t,d=!1,m=Yt(U,c);if(m){let h=await(await Xt(m))(u,{fromVersion:r,toVersion:f});if(!h||typeof h!="object"||Array.isArray(h))throw new _("transform must return a plain object map of { rulesName: data }");u=h,d=!0}let{totals:p,byName:w,rulesTagCount:v}=Zt(U,c,u);if(v===0&&Object.keys(u).length>0)throw new zt(i.href);return{html:rr(c),fromVersion:r,toVersion:f,summary:{transformApplied:d,totals:p,byName:w}}}function tr(e){for(let t of e.querySelectorAll("input")){let r=(t.getAttribute("type")||"").toLowerCase();r!=="file"&&(r==="checkbox"||r==="radio"?t.checked!==t.hasAttribute("checked")&&t.toggleAttribute("checked",t.checked):t.value!==(t.getAttribute("value")??"")&&t.setAttribute("value",t.value))}for(let t of e.querySelectorAll("textarea"))t.value!==t.textContent&&(t.textContent=t.value);for(let t of e.querySelectorAll("select")){let r=[...t.options];if(!t.multiple){let l=r.findIndex(n=>n.hasAttribute("selected"));if(t.selectedIndex===l||l===-1&&t.selectedIndex<=0)continue}for(let l of r)l.selected!==l.hasAttribute("selected")&&l.toggleAttribute("selected",l.selected)}}function rr(e){return tr(e),`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
1
+ import{a as ee}from"./c-W5HY5JHM.js";import{b as Q}from"./c-3G2DGZUP.js";import{p as K,q as Z}from"./c-CKG4NF7J.js";import"./c-LD6UVV5R.js";import"./c-PGSBXHUE.js";import{a as B,h as X}from"./c-OSGTRM4C.js";import"./c-26W3BMWK.js";import"./c-IJUK2GPW.js";import"./c-JEWSJHMK.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-U4TWEIKZ.js";import"./c-UW6MMZ4V.js";import"./c-XQXZAO7N.js";import"./c-S7LK4KUE.js";import"./c-MOP5KBWZ.js";import"./c-2YYDMLNZ.js";import"./c-HA6INT6J.js";import"./c-ICMAOOGK.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var We=Object.defineProperty,Ve=(e,t)=>{for(var r in t)We(e,r,{get:t[r],enumerable:!0})},Fe=["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"],ze=new Set(Fe),_e=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),he=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]),te=new Set(["checked","selected","disabled","readOnly","paused"]);function Je(e,t){return t==null?te.has(e)?!1:"":te.has(e)?t==="false"?!1:!!t:t}var Ye={};Ve(Ye,{CodecRefused:()=>et,EmptyListInsert:()=>R,MAX_RULE_DEPTH:()=>L,MaxRuleDepthExceeded:()=>G,NoRulesTag:()=>Ze,RuleTargetReadOnly:()=>ge,RulesParseError:()=>$,ShapeMismatch:()=>ye,UnknownCodec:()=>we,UnknownRulesVersion:()=>me,WriteNotRoundTripped:()=>Ke,WriteRefused:()=>Ge,WriteRejected:()=>Qe});var $=class extends Error{constructor(e,t){super(e),this.name="RulesParseError",this.cause=t}},me=class extends Error{constructor(e){super(`unknown rules version: ${e}. Library supports "1" and "2".`),this.name="UnknownRulesVersion",this.version=e}},L=20,G=class extends Error{constructor(e){super(`rule depth exceeded ${L} at path: ${e.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=e}},ye=class extends Error{constructor(e){super(`shape mismatch: ${e.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=e}},R=class extends Error{constructor(e,t){super(t?`cannot add items to empty list at "${e.join(".")}" \u2014 ${t}`:`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}},ge=class extends Error{constructor(e){super(`cannot write to read-only DOM property "${e}"`),this.name="RuleTargetReadOnly",this.target=e}},Ge=class extends Error{constructor(e){super(`write refused: ${e.length} write(s) broke the content-only policy`),this.name="WriteRefused",this.refusals=e}};function Xe(e){return e.reduce((t,r)=>typeof r=="number"?`${t}[${r}]`:t?`${t}.${r}`:String(r),"")||"(root)"}var Ke=class extends Error{constructor(e){super(`write did not round-trip at "${Xe(e)}"`),this.name="WriteNotRoundTripped",this.path=e}},Ze=class extends Error{constructor(e){super(`no <script data-rules-name~="${e}"> rules tag in this document`),this.name="NoRulesTag",this.token=e}},Qe=class extends Error{constructor(e,t){super(`write rejected: ${e.length} unknown key(s), ${t.length} rule(s) with no matching element`),this.name="WriteRejected",this.unknownKeys=e,this.unmatched=t}},we=class extends Error{constructor(e){super(`unknown codec "${e}": no codec by that name is given to this call`),this.name="UnknownCodec",this.code="unknown-codec",this.codec=e}},et=class extends Error{constructor(e,t){super(t),this.name="CodecRefused",this.code=e}};function M(e){let t=0,r=null,l=-1;for(let n=0;n<e.length;n++){let o=e[n];o==="\\"?n++:r?o===r&&(r=null):o==='"'||o==="'"?r=o:o==="["||o==="("?t++:o==="]"||o===")"?t>0&&t--:o==="@"&&t===0&&(l=n)}return l}var re="[*]";function j(e){let t=M(e),r=t===-1?e:e.slice(0,t),l=r.endsWith(re),n={selector:l?r.slice(0,-re.length):r,prop:t===-1?null:e.slice(t+1)||null};return l&&(n.all=!0),n}function ve(e){let t=0,r=null,l=-1,n=!1;for(let o=0;o<e.length;o++){let i=e[o];i==="\\"?o++:r?i===r&&(r=null):i==='"'||i==="'"?r=i:i==="["||i==="("?t++:i==="]"||i===")"?t>0&&t--:t===0&&i===">"?l=o:t===0&&i===","&&(n=!0)}return n||l===-1||!tt(e,l+1)?null:e.slice(0,l).trim()||null}function tt(e,t){let r=t,l=e.replace(/\s+$/,"").length;for(;r<l&&/\s/.test(e[r]);)r++;let n=0,o=null;for(;r<l;r++){let i=e[r];if(i==="\\")r++;else if(o)i===o&&(o=null);else if(i==='"'||i==="'")o=i;else if(i==="["||i==="(")n++;else if(i==="]"||i===")")n>0&&n--;else if(n===0&&(i==="+"||i==="~"||/\s/.test(i)))return!1}return!0}var rt=/^codec\(([a-z][a-z0-9-]*)\)$/;function P(e){if(typeof e!="string")return null;let t=M(e);if(t===-1)return null;let r=rt.exec(e.slice(t+1));if(!r)return null;let{selector:l,all:n}=j(e);if(n)throw new $("A @codec(name) rule cannot use [*].");return{selector:l,name:r[1]}}var nt=/^--[A-Za-z0-9_-]+$/;function be(e){return typeof e=="string"&&nt.test(e)}function xe(e){let t=[],r=[],l=null,n=0;for(let o=0;o<e.length;o++){let i=e[o];if(l){i==="\\"?o++:i===l&&(l=null);continue}if(i==="/"&&e[o+1]==="*"){let a=e.indexOf("*/",o+2);o=a===-1?e.length:a+1;continue}i==='"'||i==="'"?l=i:i==="("?r.push(")"):i==="["?r.push("]"):i==="{"?r.push("}"):(i===")"||i==="]"||i==="}")&&r[r.length-1]===i?r.pop():i===";"&&r.length===0&&(t.push(e.slice(n,o)),n=o+1)}return t.push(e.slice(n)),t}function lt(e){let t="",r=null;for(let l=0;l<e.length;l++){let n=e[l];if(r){t+=n,n==="\\"&&l+1<e.length?t+=e[++l]:n===r&&(r=null);continue}if(n==="/"&&e[l+1]==="*"){let o=e.indexOf("*/",l+2);l=o===-1?e.length:o+1,t+=" ";continue}(n==='"'||n==="'")&&(r=n),t+=n}return t}function Ae(e){e=lt(e);let t=e.indexOf(":");if(t===-1)return null;let r=e.slice(0,t).trim(),l=e.slice(t+1).trim(),n=/!\s*important\s*$/i.exec(l);return n&&(l=l.slice(0,n.index).trim()),{name:r,value:l,important:!!n}}function Te(e,t){if(e==null)return null;let r=null;for(let l of xe(String(e))){let n=Ae(l);!n||n.name!==t||(!r||n.important||!r.important)&&(r=n)}return r?r.value:null}function ot(e,t,r){let l=e==null?"":String(e),n=r==null||r==="",o=xe(l),i=o.map(Ae),a=i.some(u=>u&&u.name===t&&u.important),s=[],c=!1;o.forEach((u,d)=>{let m=i[d];if(!m||m.name!==t){s.push(u);return}if(n||c)return;let p=/^\s*/.exec(u)[0];s.push(`${p}${t}: ${r}${a?" !important":""}`),c=!0});let f=s.join(";");if(!n&&!c){let u=f.trimEnd();f=u===""?`${t}: ${r}`:`${u}${u.endsWith(";")?" ":"; "}${t}: ${r}`}return f.trim()===""?null:f}function it(e,t,r,l){let n=e.attr(t,"style");if((Te(n,r)??"")===l)return;let o=ot(n,r,l);o==null?e.removeAttr(t,"style"):e.attr(t,"style",o)}var at='The @codec(name) rule form needs a rules tag with data-rules-version="2".',st="A @codec(name) rule must be the value of a top level key.";function Oe(e,t){let r=P(e);return r?{...r,codec:t.codecs[r.name]}:null}function Ee(e,t={}){let r=t.version??"1",l=t.codecs??{};n(e,0);function n(o,i){if(!(i>L)){if(typeof o=="string"){let a=P(o);if(!a)return;if(r!=="2")throw new $(at);if(i!==1)throw new $(st);if(!Object.prototype.hasOwnProperty.call(l,a.name))throw new we(a.name);return}if(Array.isArray(o)){n(o[1],i+1);return}if(o&&typeof o=="object")for(let a of Object.values(o))n(a,i+1)}}}function ke(e,t,r,l={}){if(Object.prototype.hasOwnProperty.call(l,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");return Ee(r,l),V(e,t,r,{depth:0,path:[]},l)}function V(e,t,r,l,n){if(l.depth>L)throw new G(l.path);if(typeof r=="string")return ut(e,t,r,l,n);if(Array.isArray(r)){let[o,i]=r,a=e.find(t,o,n);return Ne(n,l,a),a.map((s,c)=>V(e,s,i,{depth:l.depth+1,path:[...l.path,c]},n))}if(typeof r=="object"&&r!==null){let o={};for(let[i,a]of Object.entries(r))o[i]=V(e,t,a,{depth:l.depth+1,path:[...l.path,i]},n);return o}return null}function ut(e,t,r,l,n){if(r.endsWith("[]")){let f=r.slice(0,-2),u=e.find(t,f,n);return Ne(n,l,u),u.map(d=>e.text(d))}let o=Oe(r,n);if(o)return ct(e,t,o,n);if(r.startsWith("@"))return W(e,t,r.slice(1));let i=M(r);if(i!==-1){let{selector:f,all:u}=j(r),d=r.slice(i+1),m=f?e.find(t,f,n):[t];return u&&n.allMatches?m.map(p=>W(e,p,d)):m.length===0?null:W(e,m[0],d)}if(r===".")return e.text(t);let{selector:a,all:s}=j(r),c=e.find(t,a,n);return s&&n.allMatches?c.map(f=>e.text(f)):c.length===0?null:e.text(c[0])}function ct(e,t,{selector:r,codec:l},n){let o=r?e.find(t,r,n):[t];return o.length===0?null:l.read(e,o[0],{query:n.query,view:n.view,region:n.region})}function Ne(e,t,r){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),r)}catch(l){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,l)}}function W(e,t,r){if(be(r))return Te(e.attr(t,"style"),r);if(ze.has(r)){let n=e.prop(t,r);return n==null?null:String(n)}return e.attr(t,r)??null}function ft(e,t,r,l){let n=e.length,o=t.length,i=new Array(n).fill(-1);if(l){let h=new Set;for(let y=0;y<n;y++){let g=l[y];!(g>=0&&g<o)||h.has(g)||(i[y]=g,h.add(g))}}if(n===0||o===0)return i;let a=e.map(h=>ne(h,r)),s=t.map(h=>ne(h,r)),c=new Array(o).fill(!1);for(let h of i)h>=0&&(c[h]=!0);let f=new Map;s.forEach((h,y)=>{c[y]||f.set(h,f.has(h)?-1:y)});let u=new Map;a.forEach((h,y)=>{i[y]>=0||u.set(h,(u.get(h)||0)+1)}),a.forEach((h,y)=>{if(i[y]>=0||u.get(h)!==1)return;let g=f.get(h);g===void 0||g===-1||c[g]||(i[y]=g,c[g]=!0)});let d=[];for(let h=0;h<n;h++)i[h]<0&&d.push(h);let m=[];for(let h=0;h<o;h++)c[h]||m.push(h);if(d.length===0||m.length===0)return i;let p=n*o+1,w=dt(e,t,r),v=(h,y)=>w(h,y)*p+Math.abs(h-y);for(let[h,y]of pt(d,m,v))i[h]=y;return i}var Se=e=>typeof e=="object"&&e!==null;function ne(e,t){if(!Se(t))return e==null?" null":String(e);let r=Object.keys(t);return JSON.stringify(r.map(l=>{let n=JSON.stringify(e?.[l]);return n===void 0?" undef":n}))}function dt(e,t,r){if(!Se(r))return(a,s)=>e[a]===t[s]?0:1;let l=Object.keys(r),n=a=>l.map(s=>JSON.stringify(a?.[s])),o=e.map(n),i=t.map(n);return(a,s)=>{let c=o[a],f=i[s],u=0;for(let d=0;d<l.length;d++)c[d]!==f[d]&&u++;return u}}function pt(e,t,r){return e.length<=t.length?le(e,t,r,!1):le(t,e,(l,n)=>r(n,l),!0)}function le(e,t,r,l){let n=e.length,o=t.length,i=[];for(let u=0;u<=n;u++)i.push(new Float64Array(o+1).fill(1/0));let a=[];for(let u=0;u<=n;u++)a.push(new Uint8Array(o+1));for(let u=0;u<=o;u++)i[n][u]=0;for(let u=n-1;u>=0;u--)for(let d=o-1;d>=0;d--){let m=r(e[u],t[d])+i[u+1][d+1],p=i[u][d+1];m<=p?(i[u][d]=m,a[u][d]=1):i[u][d]=p}let s=[],c=0,f=0;for(;c<n&&f<o;)a[c][f]&&(s.push(l?[t[f],e[c]]:[e[c],t[f]]),c++),f++;return s}function Re(e,t,r,l,n,o,i,a={}){let s=e.find(t,r,a);if(n.length===0){s.forEach(A=>e.remove(A)),F(a,"onRowsApplied",o.path,[]);return}let c=n.length>s.length,f=s[0]||null;if(c&&!f&&(f=gt(e,t,r,a),!f))throw new R(o.path);let u=s.map(A=>yt(e,A,l,a)),d=null;if(c&&f){d=e.clone(f);let A=a.templateAttr&&e.attr(f,a.templateAttr)!=null;a.templateAttr&&e.removeAttr(d,a.templateAttr),A&&e.removeAttr(d,"hidden");let T=e.stripIds(d);T>0&&console.warn(`[hyper-html-api] stripped ${T} id attribute(s) from cloned template at "${o.path.join(".")||"(root)"}"`)}let m=ft(n,u,l,ht(e,s,n,o,a)),p=s.length>0?e.parent(s[0]):xt(e,t,r,f,o,a),w=s.length>0?$e(e,p,s[0]):0,v=Ot(e,s),h=new Set,y=[],g=n.map((A,T)=>{let k=m[T];if(k>=0)return h.add(k),y.push(!1),s[k];y.push(!0);let O=e.clone(d);return e.stripIds(O),O});s.forEach((A,T)=>{h.has(T)||e.remove(A)}),v?Tt(e,p,w,g,y):Et(e,g,y,p,w),mt(e,g,l,n,o,i,a),F(a,"onRowsApplied",o.path,g)}function F(e,t,r,l){if(typeof e[t]=="function")try{return e[t](r.slice(),l)}catch(n){console.warn(`[hyper-html-api] ${t} threw at "${r.join(".")||"(root)"}"`,n);return}}function ht(e,t,r,l,n){let o=F(n,"identifyRows",l.path,r);if(!Array.isArray(o))return null;let i=new Array(r.length).fill(-1),a=new Set,s=new Map(t.map((c,f)=>[e.identity(c),f]));for(let c=0;c<r.length;c++){if(!o[c])continue;let f=s.get(e.identity(o[c]));f===void 0||a.has(f)||(i[c]=f,a.add(f))}return i}function mt(e,t,r,l,n,o,i){t.forEach((a,s)=>{if(r===null){let c=l[s],f=c==null?"":String(c);e.text(a)!==f&&e.text(a,f)}else{let c=o(e,a,r,l[s],{depth:n.depth+1,path:[...n.path,s]},i);c&&c!==a&&(t[s]=c)}})}function yt(e,t,r,l){return r===null?e.text(t):ke(e,t,r,l.onRowsRead?{...l,onRowsRead:void 0}:l)}function $e(e,t,r){let l=e.children(t);for(let n=0;n<l.length;n++)if(e.sameNode(l[n],r))return n;return-1}function gt(e,t,r,l){if(!l.templateAttr)return null;let n=/^\s*:scope\s*>\s*/.test(r),o=new RegExp(":not\\(\\["+l.templateAttr.replace(/[.*+?^${}()|[\]\\-]/g,"\\$&")+"\\]\\)","g"),i=r.replace(/^\s*:scope\s*>\s*/,"").replace(o,""),a=n?wt(i):0,s=ve(i),c=t;for(;c;){let f=e.find(c,i,{includeRulesTag:!1,templateAttr:null});for(let u of f)if(e.attr(u,l.templateAttr)!=null&&!(n&&!bt(e,t,u,a))&&!(s&&!e.matches(e.parent(u),s)))return u;c=e.parent(c)}return null}function wt(e){let t=0,r=null,l=1;for(let n=0;n<e.length;n++){let o=e[n];if(o==="\\")n++;else if(r)o===r&&(r=null);else if(o==='"'||o==="'")r=o;else if(o==="["||o==="(")t++;else if(o==="]"||o===")")t>0&&t--;else if(t===0&&o===">")l++;else{if(t===0&&(o==="+"||o==="~"))return null;if(t===0&&/\s/.test(o)){if(!vt(e,n))return null;for(;n+1<e.length&&/\s/.test(e[n+1]);)n++}}}return l}function vt(e,t){let r=t;for(;r<e.length&&/\s/.test(e[r]);)r++;let l=t>0?e[t-1]:"",n=r<e.length?e[r]:"";return oe(l)||oe(n)}function oe(e){return e===">"||e==="+"||e==="~"}function bt(e,t,r,l){if(l===null)return!0;let n=r;for(let s=0;s<l;s++)if(n=e.parent(n),!n)return!1;let o=e.prop(t,"tagName");if(!o)return!0;let i=e.prop(n,"tagName");if(!i||String(i).toLowerCase()!==String(o).toLowerCase())return!1;let a=new Set(ie(e,n));return ie(e,t).every(s=>a.has(s))}function ie(e,t){let r=e.attr(t,"class");return r?String(r).split(/\s+/).filter(Boolean):[]}function xt(e,t,r,l,n,o){let i=e.parent(l);if(i&&At(e,t,i)&&!se(e,i,o))return i;let a=ve(r);if(!a)throw new R(n.path,`the list selector "${r}" 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 s=(a===":scope"?e.prop(t,"tagName")?[t]:[]:e.find(t,a,o)).filter(c=>!se(e,c,o));if(s.length===0)throw new R(n.path,`no container matching "${a}" inside this context to hold the new rows`);if(s.length>1)throw new R(n.path,`"${a}" matches ${s.length} containers inside this context, so the new rows have no single destination`);return s[0]}function At(e,t,r){let l=r;for(;l;){if(e.sameNode(l,t))return!0;l=e.parent(l)}return e.parent(t)?!1:e.find(t,"*",{includeRulesTag:!0,templateAttr:null}).some(n=>e.sameNode(n,r))}var ae=["no-data","editor-ui"];function se(e,t,r){let l=t;for(;l;){if(r.templateAttr&&e.attr(l,r.templateAttr)!=null||ae.some(o=>e.attr(l,o)!=null))return!0;let n=e.attr(l,"clay");if(n&&n.split(/\s+/).some(o=>ae.includes(o)))return!0;l=e.parent(l)}return!1}function Tt(e,t,r,l,n){let o=e.children(t),i=o.map(s=>e.identity(s)),a=!1;l.forEach((s,c)=>{let f=e.identity(s),u=r+c;if(i[u]===f)return;if(!n[c]){let m=i.indexOf(f);m!==-1&&(i.splice(m,1),o.splice(m,1))}let d=Math.min(u,o.length);d<o.length?e.insertBefore(o[d],s):o.length?a?e.insertAfter(o[o.length-1],s):(e.insertAt(t,s,u),a=!0):e.insertAt(t,s,0),i.splice(d,0,f),o.splice(d,0,s)})}function Ot(e,t){if(t.length<=1)return!0;let r=e.parent(t[0]);if(!r)return!1;let l=new Map(e.children(r).map((o,i)=>[e.identity(o),i])),n=[];for(let o of t){let i=l.get(e.identity(o));if(i===void 0)return!1;n.push(i)}return n.sort((o,i)=>o-i),n[n.length-1]-n[0]===n.length-1}function Et(e,t,r,l,n){let o=null,i=n;for(let a=0;a<t.length;a++){if(!r[a]){o=t[a];continue}let s=o?e.parent(o):l;if(!s)continue;let c=o?$e(e,s,o)+1:i++;e.insertAt(s,t[a],c),o=t[a]}}function kt(e,t,r,l,n={}){if(Object.prototype.hasOwnProperty.call(n,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");Ee(r,n);let o=[];if(z(r,l,[],o),o.length)throw new ye(o);I(e,t,r,l,{depth:0,path:[]},n)}function I(e,t,r,l,n,o={}){if(n.depth>L)throw new G(n.path);if(l===void 0)return t;if(typeof r=="string")return Nt(e,t,r,l,n,o);if(Array.isArray(r)){let[i,a]=r;return Re(e,t,i,a,l,n,I,o),t}if(typeof r=="object"&&r!==null){for(let[i,a]of Object.entries(r)){let s=I(e,t,a,l==null?l:l[i],{depth:n.depth+1,path:[...n.path,i]},o);s&&s!==t&&(t=s)}return t}return t}function Nt(e,t,r,l,n,o){if(r.endsWith("[]")){let u=r.slice(0,-2);return Re(e,t,u,null,l,n,I,o),t}let i=Oe(r,o);if(i){let u=i.selector?e.find(t,i.selector,o):[t];return u.length&&i.codec.write(e,u[0],l,{query:o.query}),t}if(r.startsWith("@"))return ce(e,t,r.slice(1),l);let a=M(r);if(a!==-1){let{selector:u,all:d}=j(r),m=r.slice(a+1),p=u?e.find(t,u,o):[t];for(let w of d?p:p.slice(0,1))ce(e,w,m,l);return t}if(r===".")return ue(e,t,l),t;let{selector:s,all:c}=j(r),f=e.find(t,s,o);for(let u of c?f:f.slice(0,1))ue(e,u,l);return t}function ue(e,t,r){let l=r==null?"":String(r);e.text(t)!==l&&e.text(t,l)}function St(e,t,r,l){if(e.styleVar){e.styleVar(t,r,l);return}it(e,t,r,l)}function ce(e,t,r,l){if(be(r))return St(e,t,r,l==null?"":String(l).trim()),t;if(he.has(r)){let n=e.prop(t,r);if(n===l||n!=null&&l!=null&&String(n)===String(l))return t;throw new ge(r)}if(r==="outerHTML"){let n=l==null?"":String(l);return e.replaceWith(t,n)}if(_e.has(r)){let n=Je(r,l);return e.prop(t,r)!==n&&e.prop(t,r,n),t}if(l==null)e.attr(t,r)!=null&&e.removeAttr(t,r);else{let n=String(l);e.attr(t,r)!==n&&e.attr(t,r,n)}return t}function z(e,t,r,l){if(t!==void 0){if(typeof e=="string"){if(P(e))return;if(e.endsWith("[]")){Array.isArray(t)?t.forEach((n,o)=>{typeof n=="object"&&n!==null&&l.push({path:S([...r,o]),expected:"scalar",got:N(n)})}):l.push({path:S(r),expected:"array",got:N(t)});return}t!==null&&typeof t=="object"&&l.push({path:S(r),expected:"scalar",got:N(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){l.push({path:S(r),expected:"array",got:N(t)});return}let n=e[1];t.forEach((o,i)=>z(n,o,[...r,i],l));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){l.push({path:S(r),expected:"object",got:N(t)});return}for(let[n,o]of Object.entries(e))z(o,t[n],[...r,n],l)}}}function N(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function S(e){return e.join(".")}function Rt(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 r(n){let o=[],i=0;for(;i<n.length;){let a=n[i];if(/\s/.test(a)){i++;continue}if("{}".includes(a)){o.push({type:a,value:a}),i++;continue}if(a==="["){let u=!1,d=i+1;for(;d<n.length&&/\s/.test(n[d]);)d++;if(d<n.length&&/[a-zA-Z_]/.test(n[d])&&(u=!0),!u){o.push({type:a,value:a}),i++;continue}}if(a==="]"){o.push({type:a,value:a}),i++;continue}if(a===":"){o.push({type:t.COLON,value:a}),i++;continue}if(a===","){o.push({type:t.COMMA,value:a}),i++;continue}if(a==='"'||a==="'"){let u=a,d=i+1;for(;d<n.length&&n[d]!==u;)n[d]==="\\"&&d++,d++;o.push({type:t.STRING,value:n.substring(i+1,d),quoted:!0,sourceQuote:u}),i=d+1;continue}let s=i,c;for(;s<n.length&&!/[{},]/.test(n[s]);)if(n[s]===":"){let u=[":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"],d=!1;for(let m of u){let p=m.substring(1);if(n.substring(s+1,s+1+p.length)===p){d=!0,s+=p.length;break}}if(!d)break}else if(n[s]==="["){for(s++;s<n.length&&n[s]!=="]";){if(n[s]==='"'||n[s]==="'"){let u=n[s];for(s++;s<n.length&&n[s]!==u;)n[s]==="\\"&&s++,s++}s++}s<n.length&&n[s]==="]"&&s++}else s++;c=n.substring(i,s);let f=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(c)?f=t.NUMBER:c==="true"||c==="false"||c==="null"?f=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(c)&&(f=t.SELECTOR),o.push({type:f,value:c,quoted:!1}),i=s}return o}function l(n){let o="";for(let i=0;i<n.length;i++){let a=n[i];if("{}".includes(a.type)||"[]".includes(a.type)){o+=a.value;continue}if(a.type===t.COLON){o+=a.value;continue}if(a.type===t.COMMA){let s=n[i+1];if(s&&(s.type==="}"||s.type==="]"))continue;o+=a.value;continue}if(a.type===t.STRING&&a.quoted){let s=a.value;a.sourceQuote==="'"&&(s=s.replace(/\\'/g,"'"),s=s.replace(/(\\*)"/g,(c,f)=>f.length%2===0?f+'\\"':c)),o+=`"${s}"`;continue}if(a.type===t.NUMBER||a.type===t.BOOLEAN){o+=a.value;continue}if(a.type===t.SELECTOR||a.type===t.IDENTIFIER){o+=`"${a.value}"`;continue}o+=`"${a.value}"`}return o}try{let n=r(e),o=l(n);return JSON.parse(o)}catch(n){throw new $("Invalid extraction rules syntax: "+n.message,n)}}var $t=["1","2"];var Ar=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"]})}),Tr=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),jt=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui","live"]);var Or=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",...jt],refusedAttributePrefixes:["on"],urlAttributes:["href","src","srcset","action","formaction","poster","cite","data","ping","background","longdesc","usemap","xlink:href","manifest","codebase","icon"],refusedSchemes:["javascript","vbscript","data"],customPropertyValues:Object.freeze({maxLength:200,refusedCharacters:[";","{","}","<",">","\\"],refusedFunctions:["url","src","image","image-set","-webkit-image-set","cross-fade","element","expression","paint"]})});function Ct(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function Lt(e){return e?(e.nodeType===9||e.nodeType,e):null}function fe(e,t,r){!e||e.nodeType!==1||(t==="value"&&e.tagName==="INPUT"?e.value=r===null?"":r:t==="checked"&&e.tagName==="INPUT"?e.checked=r!==null:t==="selected"&&e.tagName==="OPTION"&&(e.selected=r!==null))}function Mt(e,t){e&&e.tagName==="TEXTAREA"&&(e.value=t)}function Ut(e){if(!e||e.nodeType!==1)return;let t=[e,...e.querySelectorAll?e.querySelectorAll("textarea, input, option"):[]];for(let r of t)if(r.tagName==="TEXTAREA")r.value=r.defaultValue;else if(r.tagName==="INPUT"){let l=r.type;l!=="file"&&l!=="checkbox"&&l!=="radio"&&(r.value=r.defaultValue),r.checked=r.defaultChecked}else r.tagName==="OPTION"&&(r.selected=r.defaultSelected)}var It={semanticExclude:!0,find(e,t,r={}){let l=Lt(e);if(!l||!l.querySelectorAll)return[];let n=Array.from(l.querySelectorAll(t));r.includeRulesTag||(n=n.filter(a=>!Ct(a)));let o=[];r.skip&&o.push(r.skip);let i=r.templateAttr===null?null:r.templateAttr||"cms-template";if(i&&o.push("["+i+"]"),o.length){let a=o.join(", ");n=n.filter(s=>!s.closest||!s.closest(a))}return n},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,Mt(e,t)},attr(e,t,r){if(r===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,r),fe(e,t,r)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t),fe(e,t,null)},prop(e,t,r){if(r===void 0){let l=e?e[t]:void 0;return l!==void 0?l:null}e[t]=r},clone(e){let t=e.cloneNode(!0);return Ut(t),t},insertAt(e,t,r){let l=e.children[r]||null;e.insertBefore(t,l)},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 r=e.ownerDocument.createElement("template");r.innerHTML=t;let l=r.content.firstElementChild;if(!l)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(l,e),l},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(r=>{r.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}};var U=It;var Pt="hha:upgrade-check:";function b(e,t){let r=e.querySelector(`meta[name="${t}"]`),l=r?r.getAttribute("content"):null;return l&&l.trim()?l.trim():null}function de(e){if(typeof e!="string")return null;let t=e.trim().replace(/^v/,"");return/^\d+(\.\d+)*$/.test(t)?t.split(".").map(Number):null}function Dt(e,t){let r=de(e),l=de(t);if(!r||!l)return!1;let n=Math.max(r.length,l.length);for(let o=0;o<n;o++){let i=r[o]||0,a=l[o]||0;if(i!==a)return i>a}return!1}function qt(e){try{let t=globalThis.localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function Ht(e,t){try{globalThis.localStorage.setItem(e,JSON.stringify(t))}catch{}}async function Bt({force:e=!1,doc:t,loc:r,fetchFn:l,now:n,ttlMs:o=864e5}={}){if(t=t||(typeof document<"u"?document:null),r=r||(typeof location<"u"?location:null),l=l||(d=>fetch(d)),n=n??Date.now(),!t)return null;let i=b(t,"hyper-source");if(!i)return null;let a=b(t,"hyper-version"),s;try{s=new URL(i,r?r.href:void 0)}catch{return null}if(r&&s.origin===r.origin&&s.pathname===r.pathname)return null;let c=`${Pt}${s.href}:${a||"none"}`,f,u=e?null:qt(c);if(u&&typeof u.checkedAt=="number"&&n-u.checkedAt<o)f=u.sourceVersion;else{try{let d=await l(s.href);if(!d.ok)throw new Error(`HTTP ${d.status}`);let m=await d.text(),p=new DOMParser().parseFromString(m,"text/html");f=b(p,"hyper-version")}catch{f=null}Ht(c,{checkedAt:n,sourceVersion:f})}return f?{available:Dt(f,a||"0.0.0"),currentVersion:a,sourceVersion:f,sourceUrl:s.href}:null}var Wt="script[data-rules-name]";function Vt(e){return typeof e=="string"?e.trim().replace(/\s+/g," "):""}function je(e,t){let r=e.find(t,Wt,{includeRulesTag:!0}),l=new Set,n=[];for(let o of r){let i=Vt(e.attr(o,"data-rules-name"));if(!i)continue;if(l.has(i)){console.warn(`hyper-html-api: duplicate rules tag name "${i}"; using the first.`);continue}let a=e.attr(o,"data-rules-version");if(!$t.includes(a))throw new me(a);l.add(i),n.push({name:i,rules:Rt(e.text(o)),version:a})}return n}function Ce(e,t){if(t!=="2"||!e||typeof e!="object"||Array.isArray(e))return{rules:e,carried:[]};let r={},l=[];for(let[n,o]of Object.entries(e)){let i=P(o);i?l.push({key:n,selector:i.selector}):r[n]=o}return{rules:r,carried:l}}function Le(e,t,r){return e.find(t,r)[0]||null}function Me(e,t){let r={};for(let{name:l,rules:n,version:o}of je(e,t)){let{rules:i,carried:a}=Ce(n,o),s=ke(e,t,i,{version:o});for(let{key:c,selector:f}of a){let u=Le(e,t,f);s[c]=u?e.prop(u,"innerHTML"):null}r[l]=s}return r}function Ft(e){let t=e||document,r=t.nodeType===9?t:t.ownerDocument||t;return{dataByName:Me(U,t),version:b(r,"hyper-version")}}var pe=class extends Error{constructor(e,t){super(`could not fetch upgrade source: ${e}`),this.name="UpgradeSourceUnreachable",this.sourceUrl=e,this.cause=t}},zt=class extends Error{constructor(e){super(`upgrade source has no rules tags; refusing to drop all existing data: ${e}`),this.name="UpgradeSourceHasNoRules",this.sourceUrl=e}},_=class extends Error{constructor(e,t){super(e),this.name="UpgradeTransformInvalid",this.cause=t}},_t=class extends Error{constructor(e){super(`found ${e} script[type="text/hyper-upgrade"] tags; only one is allowed per document.`),this.name="UpgradeMultipleTransforms",this.count=e}},Jt="text/hyper-upgrade";function Yt(e,t){let r=e.find(t,`script[type="${Jt}"]`);if(r.length===0)return null;if(r.length>1)throw new _t(r.length);return e.text(r[0])||null}var Gt=new Function("url","return import(url)");async function Xt(e){let t=new Blob([e],{type:"text/javascript"}),r=URL.createObjectURL(t),l;try{l=await Gt(r)}catch(n){throw new _(`transform failed to load: ${n&&n.message?n.message:n}`,n)}finally{URL.revokeObjectURL(r)}if(typeof l.default!="function")throw new _("transform must `export default` a function");return l.default}function Ue(e,t){let r={carriedOver:0,discarded:0,listItems:0},l=J(t,e,r);return Y(t,e,r),{data:l,summary:r}}function J(e,t,r,l=!1){if(typeof e=="string")return e.endsWith("[]")?Array.isArray(t)?(r.listItems+=t.length,r.carriedOver+=t.length,t):l?[]:void 0:t==null||typeof t=="object"?l&&!Kt(e)?null:void 0:(r.carriedOver++,t);if(Array.isArray(e)){let[,n]=e;return Array.isArray(t)?(r.listItems+=t.length,t.map(o=>J(n,o,r,!0))):l?[]:void 0}if(typeof e=="object"&&e!==null){let n={};for(let[o,i]of Object.entries(e)){let a=J(i,t?.[o],r,l);a!==void 0&&(n[o]=a)}return n}}function Kt(e){let t=M(e);return t!==-1&&he.has(e.slice(t+1))}function Y(e,t,r){if(t!=null){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){if(typeof t!="object"||Array.isArray(t))return;let l=new Set(Object.keys(e));for(let n of Object.keys(t))l.has(n)?Y(e[n],t[n],r):r.discarded+=C(t[n]);return}if(Array.isArray(e)&&Array.isArray(t)){let l=e[1];t.forEach(n=>Y(l,n,r));return}typeof e=="string"&&!e.endsWith("[]")&&typeof t=="object"&&t!==null&&(r.discarded+=C(t))}}function C(e){return e==null?0:Array.isArray(e)?e.reduce((t,r)=>t+C(r),0):typeof e=="object"?Object.values(e).reduce((t,r)=>t+C(r),0):1}function Zt(e,t,r){let l=je(e,t),n={carriedOver:0,discarded:0,listItems:0},o={},i=new Set;for(let{name:a,rules:s,version:c}of l){if(i.add(a),!Object.prototype.hasOwnProperty.call(r,a)){o[a]={carriedOver:0,discarded:0,listItems:0};continue}let{rules:f,carried:u}=Ce(s,c),d=r[a],{data:m,summary:p}=Ue(Qt(d,u),f);kt(e,t,f,m,{templateAttr:"cms-template"});for(let{key:w,selector:v}of u){let h=Ie(d)?d[w]:void 0;if(h==null)continue;let y=Le(e,t,v);typeof h=="string"&&y?(e.prop(y,"innerHTML",h),p.carriedOver+=1):p.discarded+=1}o[a]=p,n.carriedOver+=p.carriedOver,n.discarded+=p.discarded,n.listItems+=p.listItems}for(let a of Object.keys(r))i.has(a)||(n.discarded+=C(r[a]));return{totals:n,byName:o,rulesTagCount:l.length}}function Ie(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Qt(e,t){if(!t.length||!Ie(e))return e;let r={...e};for(let{key:l}of t)delete r[l];return r}async function er({sourceUrl:e,dataByName:t,fromVersion:r,doc:l,loc:n,fetchFn:o}={}){if(l=l||(typeof document<"u"?document:null),n=n||(typeof location<"u"?location:null),o=o||(h=>fetch(h)),!l)throw new Error("upgrade.run requires a document context");if(e=e||b(l,"hyper-source"),!e)throw new Error("upgrade.run: no sourceUrl given and no hyper-source meta tag found");let i=new URL(e,n?n.href:void 0);r=r!==void 0?r:b(l,"hyper-version"),t=t||Me(U,l);let a;try{a=await o(i.href)}catch(h){throw new pe(i.href,h)}if(!a.ok)throw new pe(i.href,new Error(`HTTP ${a.status}`));let s=await a.text(),c=new DOMParser().parseFromString(s,"text/html"),f=b(c,"hyper-version"),u=t,d=!1,m=Yt(U,c);if(m){let h=await(await Xt(m))(u,{fromVersion:r,toVersion:f});if(!h||typeof h!="object"||Array.isArray(h))throw new _("transform must return a plain object map of { rulesName: data }");u=h,d=!0}let{totals:p,byName:w,rulesTagCount:v}=Zt(U,c,u);if(v===0&&Object.keys(u).length>0)throw new zt(i.href);return{html:rr(c),fromVersion:r,toVersion:f,summary:{transformApplied:d,totals:p,byName:w}}}function tr(e){for(let t of e.querySelectorAll("input")){let r=(t.getAttribute("type")||"").toLowerCase();r!=="file"&&(r==="checkbox"||r==="radio"?t.checked!==t.hasAttribute("checked")&&t.toggleAttribute("checked",t.checked):t.value!==(t.getAttribute("value")??"")&&t.setAttribute("value",t.value))}for(let t of e.querySelectorAll("textarea"))t.value!==t.textContent&&(t.textContent=t.value);for(let t of e.querySelectorAll("select")){let r=[...t.options];if(!t.multiple){let l=r.findIndex(n=>n.hasAttribute("selected"));if(t.selectedIndex===l||l===-1&&t.selectedIndex<=0)continue}for(let l of r)l.selected!==l.hasAttribute("selected")&&l.toggleAttribute("selected",l.selected)}}function rr(e){return tr(e),`<!DOCTYPE ${e.doctype&&e.doctype.name?e.doctype.name:"html"}>
2
2
  `+e.documentElement.outerHTML}var D={checkForUpdate:Bt,run:er,extractAll:Ft,shapeMatch:Ue};var x="The new version could not be downloaded. Nothing was changed.",q="The upgrade could not be saved. Nothing was changed.",qe="This document changed somewhere else. Reload and try again.",nr="Something else is changing this document. Nothing was changed.",lr="This document does not say which parts are its data, so it cannot be upgraded safely. Nothing was changed.",or="The new version has no place for this page's content. Nothing was changed.";async function ir(e){let t=globalThis.crypto&&globalThis.crypto.subtle;if(!t)return null;let r=await t.digest("SHA-256",e);return[...new Uint8Array(r)].map(l=>l.toString(16).padStart(2,"0")).join("")}async function Pe(e,t){try{let r=await e(t,{credentials:"omit"});return!r||!r.ok?null:r}catch{return null}}function ar(e,t,r){if(e&&typeof e.latestUrl=="string"&&e.latestUrl)return e.latestUrl;let l=b(t,"hyper-source");if(!l)return null;try{let n=new URL(l,r?r.href:void 0);return n.pathname=n.pathname.replace(/\.html$/,".json"),n.href}catch{return null}}function sr(e){let t=b(e,"clay-template");if(!t)return null;let[r,l]=t.split(/\s+/);return r&&l?{id:r,variant:l}:null}function H(e,t="",r=[]){if(Array.isArray(e)){for(let l of e)H(l,`${t}[]`,r);return r}if(e&&typeof e=="object"){for(let[l,n]of Object.entries(e))H(n,t?`${t}.${l}`:l,r);return r}return e!=null&&r.push({path:t,value:e}),r}function ur(e,t){let r=[e];for(let l of String(t).split(".")){let n=l.endsWith("[]"),o=n?l.slice(0,-2):l,i=[];for(let a of r){let s=o?a?.[o]:a;n?Array.isArray(s)&&i.push(...s):i.push(s)}r=i}return r}function cr(e,t,r={}){let l=new Map;for(let{path:o,value:i}of H(t)){let a=`${o}\0${String(i)}`;l.set(a,(l.get(a)||0)+1)}let n=[];for(let{path:o,value:i}of H(e)){let a=`${o}\0${String(i)}`;if(l.get(a)>0){l.set(a,l.get(a)-1);continue}let s=r[o];typeof s=="string"&&ur(t,s).some(c=>c===i)||n.push({path:o,value:i})}return n}async function fr(e){let t=new Blob([e],{type:"text/javascript"}),r=URL.createObjectURL(t);try{return await new Function("url","return import(url)")(r)}finally{URL.revokeObjectURL(r)}}async function dr(e){let r=new DOMParser().parseFromString(e,"text/html").querySelector('script[type="text/hyper-upgrade"]');if(!r)return{};let l=await fr(r.textContent||"");return l&&l.renames&&typeof l.renames=="object"?l.renames:{}}var De='script[clay~="live"][merge]';function pr(e,t,r){let l=t.querySelector("article[data-blockeditor]");if(!l)return null;l.replaceWith(t.importNode(r,!0));for(let o of e.querySelectorAll(De)){let i=o.getAttribute("merge");if(i!=="blockeditor"&&!i.startsWith("blockeditor."))continue;let a=t.importNode(o,!0),s=[...t.querySelectorAll(De)].find(c=>c.getAttribute("merge")===i);s?s.replaceWith(a):t.querySelector("article[data-blockeditor]").after(a)}return(t.doctype?`<!DOCTYPE ${t.doctype.name}>
3
3
  `:"")+t.documentElement.outerHTML}async function He(e,{doc:t=document,loc:r=location,fetchFn:l=(n,o)=>fetch(n,o)}={}){if((typeof window<"u"&&window.clay||{}).isDraftMode)return{ok:!1,code:"draft"};if(!e||typeof e.version!="string")return{ok:!1,code:"unavailable",message:x};let o=ar(e,t,r);if(!o)return{ok:!1,code:"unavailable",message:x};let i=await Pe(l,o);if(!i)return{ok:!1,code:"unavailable",message:x};let a;try{a=await i.json()}catch{return{ok:!1,code:"unavailable",message:x}}if(!a||typeof a!="object")return{ok:!1,code:"unavailable",message:x};let s=sr(t);if(!s||a.id!==s.id||a.variant!==s.variant)return{ok:!1,code:"template",message:"This upgrade is for a different document."};let c=b(t,"hyper-version");if(!c||typeof a.version!="string"||!Q(a.version,c))return{ok:!1,code:"not-newer",message:"There is no newer version to install."};if(typeof a.html!="string"||!a.html)return{ok:!1,code:"unavailable",message:x};let f;try{f=new URL(a.html,o).href}catch{return{ok:!1,code:"unavailable",message:x}}if(!/^https:\/\/hyperclay\.com\/templates\//.test(f))return{ok:!1,code:"source",message:"This upgrade is not from the template host."};let u=await Pe(l,f);if(!u)return{ok:!1,code:"unavailable",message:x};let d;try{d=await u.text()}catch{return{ok:!1,code:"unavailable",message:x}}let m=await ir(new TextEncoder().encode(d));if(!m||m!==String(a.sha256||"").toLowerCase())return{ok:!1,code:"unavailable",message:x};let p,w;try{w=await dr(d),p=await D.run({sourceUrl:f,doc:t,loc:r,fromVersion:c,fetchFn:async()=>({ok:!0,status:200,text:async()=>d})})}catch(O){return{ok:!1,code:"transform",message:O&&O.message?O.message:x}}let v=new DOMParser().parseFromString(p.html,"text/html"),h=D.extractAll(t).dataByName,y=t.querySelector("article[data-blockeditor]");if(!y&&!Object.keys(h||{}).length)return{ok:!1,code:"undeclared",message:lr};let g=p.html;if(y){let O=pr(t,v,y);if(!O)return{ok:!1,code:"lost",lost:[],discarded:0,message:or};g=O}let A=D.extractAll(v).dataByName,T=cr(h,A,w),k=p.summary&&p.summary.totals&&p.summary.totals.discarded||0;return T.length||k>0?{ok:!1,code:"lost",lost:T,discarded:k,message:hr(T,k)}:{ok:!0,html:g,version:p.toVersion||a.version}}function hr(e,t){let r=e.slice(0,5).map(({path:n})=>n),l=e.length>r.length?` and ${e.length-r.length} more`:"";return r.length?`This upgrade would lose data: ${r.join(", ")}${l}. Nothing was changed.`:`This upgrade would lose ${t} value${t===1?"":"s"}. Nothing was changed.`}function mr(e){let t=e&&e.state;if(t==="conflict")return{ok:!1,code:"conflict",message:qe};let r=e&&e.message?e.message:"The document could not be saved.";return{ok:!1,code:"flush",state:t||"failed",message:r}}async function Be(e,{doc:t=document,loc:r=location,fetchFn:l=(s,c)=>fetch(s,c),clay:n=typeof window<"u"?window.clay:null,reload:o=()=>window.location.reload(),replace:i=null,etag:a}={}){if((n||{}).isDraftMode)return{ok:!1,code:"draft"};let c=K("upgrade");if(!c)return{ok:!1,code:"busy",message:nr};try{return await yr(e,{doc:t,loc:r,fetchFn:l,clay:n,reload:o,replace:i,etag:a})}finally{Z(c)}}async function yr(e,{doc:t,loc:r,fetchFn:l,clay:n,reload:o,replace:i,etag:a}){let s=n||{};if(s.isEditMode&&s.save&&typeof s.save.flush=="function"){let p;try{p=await s.save.flush()}catch(w){return mr(w)}if(p&&typeof p.state=="string"&&p.state!=="saved"&&p.state!=="clean"&&p.state!=="view")return{ok:!1,code:"flush",state:p.state,message:"This document has changes that could not be saved. Nothing was changed."}}if(a===void 0&&!B())try{await X()}catch{}let c=a!==void 0?a:B(),f=t;if(s.isEditMode&&typeof s.getHTML=="function")try{f=new DOMParser().parseFromString(await s.getHTML(),"text/html")}catch{return{ok:!1,code:"failed",message:q}}else f=new DOMParser().parseFromString(`<!DOCTYPE html>
4
4
  `+t.documentElement.outerHTML,"text/html");let u=await He(e,{doc:f,loc:r,fetchFn:l});if(!u.ok)return u;let d=typeof i=="function"?i:s.save&&typeof s.save.replace=="function"?s.save.replace:ee,m;try{m=await d(u.html,{etag:c})}catch{return{ok:!1,code:"failed",message:q}}if(!m||!m.ok){let p=m&&m.code?m.code:"failed";return p==="conflict"?{ok:!1,code:p,message:qe}:p==="forbidden"?{ok:!1,code:p,message:"You are not allowed to save this document."}:p==="unsupported"?{ok:!1,code:p,message:"This host cannot save the upgrade."}:{ok:!1,code:p,message:q}}return o(),{ok:!0,html:u.html,version:u.version,etag:m.etag}}function E(e,t,r={}){let l=e.createElement(t);l.setAttribute("clay","editor-ui");for(let[n,o]of Object.entries(r))n==="style"?l.setAttribute("style",o):n==="text"?l.textContent=o:l.setAttribute(n,o);return l}function gr(e){let r=(e&&e.pathname?e.pathname:"/").split("/").filter(Boolean).pop()||"page.html";try{r=decodeURIComponent(r)}catch{}return/\.html?$/i.test(r)?r:`${r}.html`}async function wr(e,{loc:t=location,fetchFn:r=(l,n)=>fetch(l,n)}={}){if(typeof e.getHTML=="function")return e.getHTML();let l=await r(t.href,{cache:"no-store",credentials:"same-origin"});if(!l.ok)throw new Error(`copy fetch ${l.status}`);return l.text()}async function vr({clay:e,doc:t=document,loc:r=location,fetchFn:l}={}){if(typeof URL>"u"||typeof URL.createObjectURL!="function")return!1;try{let n=await wr(e,{loc:r,fetchFn:l});if(typeof n=="string"&&/clay|data-paid-only/i.test(n)){let{stripCopyContent:a}=await import("./c-C4IIQZGJ.js");n=a(n)}let o=URL.createObjectURL(new Blob([n],{type:"text/html"})),i=t.createElement("a");return i.setAttribute("clay","editor-ui"),i.href=o,i.download=gr(r),i.style.setProperty("display","none","important"),t.body.appendChild(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(o),4e4),!0}catch{return!1}}async function br(e){let t=e&&e.host;if(!t||!t.versions)return!1;try{return await t.versions===!0}catch{return!1}}async function xr(e,t={}){let r=t.doc||document,l=t.clay||(typeof window<"u"?window.clay:null)||{};if(l.isDraftMode||!e||typeof e.version!="string")return null;let n=await br(l),o=E(r,"div",{role:"dialog","aria-modal":"true","data-clay-upgrade":"",style:"position:fixed;inset:0;z-index:2147483000;display:flex;align-items:center;justify-content:center;padding:16px;background:rgba(15,17,21,.42);font-family:system-ui,-apple-system,'Segoe UI',sans-serif;"}),i=E(r,"div",{style:"width:min(460px,100%);padding:20px;border-radius:14px;background:var(--clay-ui-bg,#fff);color:var(--clay-ui-fg,#1f2328);box-shadow:0 18px 48px -16px rgba(0,0,0,.55);font-size:14px;line-height:1.5;"}),a=E(r,"h2",{text:`Upgrade to version ${e.version}`,style:"margin:0 0 8px;font-size:16px;"}),s=E(r,"p",{text:`Your data moves into version ${e.version}. The page's layout and code are replaced; your current version stays in this document's history.`,style:"margin:0 0 16px;"}),c=E(r,"p",{role:"status",style:"margin:0 0 12px;min-height:1.5em;"}),f=E(r,"div",{style:"display:flex;flex-wrap:wrap;gap:8px;justify-content:flex-end;"}),u="padding:7px 12px;border-radius:8px;border:1px solid rgba(23,28,36,.2);background:transparent;color:inherit;font:inherit;cursor:pointer;",d=E(r,"button",{type:"button",text:"Cancel",style:u}),m=n?null:E(r,"button",{type:"button",text:"Download a copy first",style:u}),p=E(r,"button",{type:"button",text:"Upgrade",style:`${u}border-color:transparent;background:#2f6fed;color:#fff;font-weight:600;`});n||(p.disabled=!0),m&&f.append(m),f.append(d,p),i.append(a,s,c,f),o.append(i),r.body.appendChild(o);let w=!1,v=()=>{w||(w=!0,o.remove())};m&&m.addEventListener("click",async()=>{await vr({clay:l,doc:r,loc:t.loc,fetchFn:t.fetchFn})?(p.disabled=!1,c.textContent="Your copy was downloaded."):c.textContent="The copy could not be downloaded. Nothing was changed."}),d.addEventListener("click",v);let h,y=new Promise(g=>{h=g});return p.addEventListener("click",async()=>{p.disabled=!0,m&&(m.disabled=!0),c.textContent=`Upgrading to version ${e.version}\u2026`;let g=await Be(e,t);if(g.ok){v(),h(g);return}c.textContent=g.message||q,p.disabled=!1,m&&(m.disabled=!1),h(g)}),{root:o,title:a,body:s,status:c,cancel:d,download:m,upgrade:p,close:v,done:y}}export{Be as apply,He as prepare,xr as start};
@@ -1 +1 @@
1
- import{a as O}from"./c-WN3MXOLT.js";import{d as A}from"./c-EQ5NBOGA.js";var p=1,D=8*1024,B=256,L=1024,Y=128,X=128,G=Object.freeze(["title","description","labels","members","dates","checklist","comment","attachments"]),m=250,E=5e3,it=15e3;var W=new Set(["kind","id","field"]),$=new Set(["kind","v","epoch","generation","selection"]),q=new Set(["kind","anchor","head"]),F=new Set(["kind","ids"]),J=new Set(["kind","block","row","col"]),V=new Set(["block","rel"]),H=/^[\x20-\x7e]+$/,U=/^[A-Za-z0-9+/]+={0,2}$/,Z=/[\u0000-\u001f\u007f]/,o=t=>({ok:!1,reason:t}),a=t=>({ok:!0,target:t}),g=t=>!!t&&typeof t=="object"&&!Array.isArray(t),d=(t,e)=>{for(let n of Object.keys(t))if(!e.has(n))return!1;return!0};function T(t){let e=0;for(let n of t){let s=n.codePointAt(0);e+=s<128?1:s<2048?2:s<65536?3:4}return e}function u(t){return typeof t=="string"&&t.length>0&&!Z.test(t)&&T(t)<=B}function Q(t){if(typeof t!="string"||!t.length||t.length%4!==0||!U.test(t))return!1;let e=t.endsWith("==")?2:t.endsWith("=")?1:0;return t.length/4*3-e<=L}function _(t){return!g(t)||!d(t,V)||!u(t.block)||!Q(t.rel)?null:{block:t.block,rel:t.rel}}function v(t){if(!g(t))return null;if(t.kind==="text"){if(!d(t,q))return null;let e=_(t.anchor),n=_(t.head);return e&&n?{kind:"text",anchor:e,head:n}:null}if(t.kind==="blocks"){if(!d(t,F)||!Array.isArray(t.ids)||!t.ids.length||t.ids.length>X)return null;for(let e of t.ids)if(!u(e))return null;return{kind:"blocks",ids:[...t.ids]}}return t.kind==="cell"?!d(t,J)||!u(t.block)||!u(t.row)||!u(t.col)?null:{kind:"cell",block:t.block,row:t.row,col:t.col}:null}function w(t){return T(JSON.stringify(t))<=D}function tt(t){if(!d(t,W))return o("key");let e=t.id;if(typeof e!="string"||!e.length||e.length>Y||!H.test(e))return o("id");if(t.field===void 0){let s={kind:"record",id:e};return w(s)?a(s):o("size")}if(typeof t.field!="string"||!G.includes(t.field))return o("field");let n={kind:"record",id:e,field:t.field};return w(n)?a(n):o("size")}function et(t){if(!d(t,$))return o("key");if(t.v!==p)return o("version");if(!u(t.epoch))return o("epoch");if(!Number.isSafeInteger(t.generation)||t.generation<0)return o("generation");let e=v(t.selection);if(!e)return o("selection");let n={kind:"blockeditor",v:p,epoch:t.epoch,generation:t.generation,selection:e};return w(n)?a(n):o("size")}function y(t){return t===null?a(null):typeof t=="string"?O.test(t)?a(t):o("path"):g(t)?t.kind==="record"?tt(t):t.kind==="blockeditor"?et(t):o("kind"):o("shape")}function R(t){let e=y(t===void 0?null:t);return!e.ok||e.target!==null&&typeof e.target=="object"&&e.target.kind!=="record"?null:e.target}function z(t){return t==null?"":typeof t=="string"?`path:${t}`:`target:${JSON.stringify(t)}`}function C(t,e=null){let n=Array.isArray(t)?t:[],s=[];for(let i of n){if(!g(i))continue;let r=u(i.id)?i.id:null;if(!r)continue;let h=Number.isSafeInteger(i.n)&&i.n>=0?i.n:0,c=e&&e.get(r);if(c&&h<c.n){s.push(c);continue}let f=y(i.editing===void 0?null:i.editing);s.push({id:r,you:i.you===!0,n:h,editing:f.ok?f.target:null})}return s}function I(t){if(!g(t))return null;let e=u(t.id)?t.id:null,n=typeof t.token=="string"&&t.token.length?t.token:null;return e&&n?{id:e,token:n}:null}function N({target:t=null,session:e=null,n=0}){if(t==null||typeof t=="string")return{editing:t??null};let s=e&&typeof e.token=="string"&&e.token.length?e.token:null;return s?!Number.isSafeInteger(n)||n<0?null:{v:p,session:s,n,editing:t}:t.kind==="record"?{editing:t}:null}var nt=()=>Object.freeze({supported:!1,recordAwareness:!1,pageAwareness:!1,people:Object.freeze([]),anonymous:0}),k=class{constructor(){this.supported=!1,this.recordAwareness=!1,this.pageAwareness=!1,this.people=[],this.anonymous=0,this.snapshot=nt(),this.listeners=new Set,this.sessions=new Map,this.session=null,this.target=null,this.heldKey="",this.owner=null,this.explicit=!1,this.connecting=null,this.n=0,this.sentKey=null,this.timer=null,this.timerKind=null,this.inflight=!1,this.inflightOwner=null,this.inflightKey=null}getSnapshot(){return this.snapshot}subscribe(e){if(typeof e!="function")throw new TypeError("clay.presence.subscribe needs a listener function");return this.listeners.add(e),e(this.snapshot),()=>{this.listeners.delete(e)}}setCapabilities({supported:e=!1,recordAwareness:n=!1,pageAwareness:s=!1}={}){let i=e===!0,r=n===!0,h=s===!0;return i===this.supported&&r===this.recordAwareness&&h===this.pageAwareness?this.snapshot:(this.supported=i,this.recordAwareness=r,this.pageAwareness=h,this.emit())}receive(e){let n=e&&typeof e=="object"?e:{},s=Array.isArray(n.people)?n.people:[],i=this.sessions,r=new Map,h=[];for(let l of s){if(!l||typeof l.id!="string"||!l.id)continue;let P=typeof l.name=="string"&&l.name.trim()?l.name.trim():"Someone",b=C(l.sessions,i);for(let K of b)r.set(K.id,K);let x={id:l.id,name:P,you:l.you===!0,editing:R(l.editing),sessions:b};typeof l.canEdit=="boolean"&&(x.canEdit=l.canEdit),h.push(x)}this.people=h,this.sessions=r;let c=n.anonymous;this.anonymous=typeof c=="number"&&Number.isFinite(c)&&c>0?Math.floor(c):0;let f=I(n.selfSession),M=!this.session||!this.session.token;f&&(this.session=f);let j=this.emit();return f&&M&&this.owner&&this.target!==null&&(this.sentKey=null,this.flush()),j}clear(){return this.people=[],this.anonymous=0,this.sessions=new Map,this.session=null,this.cancel(),this.sentKey=null,this.emit()}setTarget(e){let n=y(e===void 0?null:e);return n.ok?(this.explicit=!0,this.hold(n.target)):!1}setGeneric(e){if(this.explicit)return!1;let n=y(e===void 0?null:e);return n.ok?this.hold(n.target):!1}releaseTarget(){return this.explicit?(this.explicit=!1,this.hold(null)):!1}hold(e){let n=z(e);return n===this.heldKey?(this.owner&&this.sentKey!==n&&this.schedule(m),!0):(this.target=e,this.heldKey=n,e===null?(this.cancel(),this.flush(),!0):(this.schedule(m),!0))}attachTransport(e){if(!e||typeof e.send!="function")throw new TypeError("clay.presence.attachTransport needs a transport with a send function");let n=this,s={send:e.send,get active(){return n.owner===s},detach(){if(n.owner!==s)return;let i=n.heldKey===""&&typeof n.inflightKey=="string"&&n.inflightKey!=="";if(n.owner=null,n.session=null,n.n=0,n.sentKey=null,n.inflight=!1,n.inflightOwner=null,n.inflightKey=null,n.cancel(),n.target=null,n.heldKey="",n.explicit=!1,n.clear(),i)try{Promise.resolve(s.send({editing:null})).catch(()=>{})}catch{}}};return this.owner=s,this.session=null,this.n=0,this.sentKey=null,this.inflight=!1,this.inflightOwner=null,this.inflightKey=null,this.cancel(),this.target!==null&&this.flush(),s}connect({send:e=null}={}){return this.connecting?this.connecting:(this.connecting=A().then(n=>{let s=Array.isArray(n?.extensions)?n.extensions:[],i=n?.document&&typeof n.document=="object"?n.document.awareness:null;if(i&&i.transport==="broadcast"&&(s.includes("blockeditor-awareness-v1")||s.includes("record-awareness-v1"))){let r=typeof i.scope=="string"&&i.scope?i.scope:null;return import("./c-BJ2RRQBQ.js").then(({localPresence:h})=>{let c=h({scope:r,store:this}),f=c.start();return f?Object.defineProperty(f,"stop",{value:()=>c.stop()}):null})}return typeof e=="function"&&s.includes("presence-editing")?this.attachTransport({send:e}):null}).finally(()=>{this.connecting=null}),this.connecting)}reconnect(){this.session=null,this.n=0,this.sentKey=null,this.cancel(),!(!this.owner||this.target===null)&&this.flush()}emit(){let e=this.people.map(n=>Object.freeze({...n,sessions:Object.freeze(n.sessions)}));this.snapshot=Object.freeze({supported:this.supported,recordAwareness:this.recordAwareness,pageAwareness:this.pageAwareness,people:Object.freeze(e),anonymous:this.anonymous});for(let n of[...this.listeners])n(this.snapshot);return this.snapshot}schedule(e,n="coalesce"){if(this.timer!==null){if(this.timerKind==="coalesce")return;clearTimeout(this.timer)}this.timerKind=n,this.timer=setTimeout(()=>{this.timer=null,this.timerKind=null,this.flush()},e)}cancel(){this.timer!==null&&(clearTimeout(this.timer),this.timer=null,this.timerKind=null)}renew(){this.timer!==null||!this.owner||this.target===null||this.schedule(E,"renew")}flush(){if(this.inflight)return;let e=this.owner;if(!e)return;let n=this.n+1,s=N({target:this.target,session:this.session,n});if(!s)return;this.cancel(),this.sentKey=this.heldKey,this.inflight=!0,this.inflightOwner=e,this.inflightKey=this.sentKey,s.v===p&&(this.n=n);let i=r=>{if(this.inflightOwner===e&&(this.inflight=!1,this.inflightOwner=null,this.inflightKey=null,this.owner===e)){if(this.heldKey!==this.sentKey){this.flush();return}r?this.renew():this.schedule(E,"renew")}};Promise.resolve(e.send(s)).then(r=>i(!!r),()=>i(!1))}},S=new k,ct=S;if(typeof window<"u"&&(window.clay=window.clay||{},!window.clay.presence)){window.clay.presence=S;try{document.dispatchEvent(new CustomEvent("clay:presence-ready",{detail:{presence:S}}))}catch{}}export{p as a,E as b,it as c,y as d,k as e,S as f,ct as g};
1
+ import{a as O}from"./c-WN3MXOLT.js";import{d as A}from"./c-26W3BMWK.js";var p=1,D=8*1024,B=256,L=1024,Y=128,X=128,G=Object.freeze(["title","description","labels","members","dates","checklist","comment","attachments"]),m=250,E=5e3,it=15e3;var W=new Set(["kind","id","field"]),$=new Set(["kind","v","epoch","generation","selection"]),q=new Set(["kind","anchor","head"]),F=new Set(["kind","ids"]),J=new Set(["kind","block","row","col"]),V=new Set(["block","rel"]),H=/^[\x20-\x7e]+$/,U=/^[A-Za-z0-9+/]+={0,2}$/,Z=/[\u0000-\u001f\u007f]/,o=t=>({ok:!1,reason:t}),a=t=>({ok:!0,target:t}),g=t=>!!t&&typeof t=="object"&&!Array.isArray(t),d=(t,e)=>{for(let n of Object.keys(t))if(!e.has(n))return!1;return!0};function T(t){let e=0;for(let n of t){let s=n.codePointAt(0);e+=s<128?1:s<2048?2:s<65536?3:4}return e}function u(t){return typeof t=="string"&&t.length>0&&!Z.test(t)&&T(t)<=B}function Q(t){if(typeof t!="string"||!t.length||t.length%4!==0||!U.test(t))return!1;let e=t.endsWith("==")?2:t.endsWith("=")?1:0;return t.length/4*3-e<=L}function _(t){return!g(t)||!d(t,V)||!u(t.block)||!Q(t.rel)?null:{block:t.block,rel:t.rel}}function v(t){if(!g(t))return null;if(t.kind==="text"){if(!d(t,q))return null;let e=_(t.anchor),n=_(t.head);return e&&n?{kind:"text",anchor:e,head:n}:null}if(t.kind==="blocks"){if(!d(t,F)||!Array.isArray(t.ids)||!t.ids.length||t.ids.length>X)return null;for(let e of t.ids)if(!u(e))return null;return{kind:"blocks",ids:[...t.ids]}}return t.kind==="cell"?!d(t,J)||!u(t.block)||!u(t.row)||!u(t.col)?null:{kind:"cell",block:t.block,row:t.row,col:t.col}:null}function w(t){return T(JSON.stringify(t))<=D}function tt(t){if(!d(t,W))return o("key");let e=t.id;if(typeof e!="string"||!e.length||e.length>Y||!H.test(e))return o("id");if(t.field===void 0){let s={kind:"record",id:e};return w(s)?a(s):o("size")}if(typeof t.field!="string"||!G.includes(t.field))return o("field");let n={kind:"record",id:e,field:t.field};return w(n)?a(n):o("size")}function et(t){if(!d(t,$))return o("key");if(t.v!==p)return o("version");if(!u(t.epoch))return o("epoch");if(!Number.isSafeInteger(t.generation)||t.generation<0)return o("generation");let e=v(t.selection);if(!e)return o("selection");let n={kind:"blockeditor",v:p,epoch:t.epoch,generation:t.generation,selection:e};return w(n)?a(n):o("size")}function y(t){return t===null?a(null):typeof t=="string"?O.test(t)?a(t):o("path"):g(t)?t.kind==="record"?tt(t):t.kind==="blockeditor"?et(t):o("kind"):o("shape")}function R(t){let e=y(t===void 0?null:t);return!e.ok||e.target!==null&&typeof e.target=="object"&&e.target.kind!=="record"?null:e.target}function z(t){return t==null?"":typeof t=="string"?`path:${t}`:`target:${JSON.stringify(t)}`}function C(t,e=null){let n=Array.isArray(t)?t:[],s=[];for(let i of n){if(!g(i))continue;let r=u(i.id)?i.id:null;if(!r)continue;let h=Number.isSafeInteger(i.n)&&i.n>=0?i.n:0,c=e&&e.get(r);if(c&&h<c.n){s.push(c);continue}let f=y(i.editing===void 0?null:i.editing);s.push({id:r,you:i.you===!0,n:h,editing:f.ok?f.target:null})}return s}function I(t){if(!g(t))return null;let e=u(t.id)?t.id:null,n=typeof t.token=="string"&&t.token.length?t.token:null;return e&&n?{id:e,token:n}:null}function N({target:t=null,session:e=null,n=0}){if(t==null||typeof t=="string")return{editing:t??null};let s=e&&typeof e.token=="string"&&e.token.length?e.token:null;return s?!Number.isSafeInteger(n)||n<0?null:{v:p,session:s,n,editing:t}:t.kind==="record"?{editing:t}:null}var nt=()=>Object.freeze({supported:!1,recordAwareness:!1,pageAwareness:!1,people:Object.freeze([]),anonymous:0}),k=class{constructor(){this.supported=!1,this.recordAwareness=!1,this.pageAwareness=!1,this.people=[],this.anonymous=0,this.snapshot=nt(),this.listeners=new Set,this.sessions=new Map,this.session=null,this.target=null,this.heldKey="",this.owner=null,this.explicit=!1,this.connecting=null,this.n=0,this.sentKey=null,this.timer=null,this.timerKind=null,this.inflight=!1,this.inflightOwner=null,this.inflightKey=null}getSnapshot(){return this.snapshot}subscribe(e){if(typeof e!="function")throw new TypeError("clay.presence.subscribe needs a listener function");return this.listeners.add(e),e(this.snapshot),()=>{this.listeners.delete(e)}}setCapabilities({supported:e=!1,recordAwareness:n=!1,pageAwareness:s=!1}={}){let i=e===!0,r=n===!0,h=s===!0;return i===this.supported&&r===this.recordAwareness&&h===this.pageAwareness?this.snapshot:(this.supported=i,this.recordAwareness=r,this.pageAwareness=h,this.emit())}receive(e){let n=e&&typeof e=="object"?e:{},s=Array.isArray(n.people)?n.people:[],i=this.sessions,r=new Map,h=[];for(let l of s){if(!l||typeof l.id!="string"||!l.id)continue;let P=typeof l.name=="string"&&l.name.trim()?l.name.trim():"Someone",b=C(l.sessions,i);for(let K of b)r.set(K.id,K);let x={id:l.id,name:P,you:l.you===!0,editing:R(l.editing),sessions:b};typeof l.canEdit=="boolean"&&(x.canEdit=l.canEdit),h.push(x)}this.people=h,this.sessions=r;let c=n.anonymous;this.anonymous=typeof c=="number"&&Number.isFinite(c)&&c>0?Math.floor(c):0;let f=I(n.selfSession),M=!this.session||!this.session.token;f&&(this.session=f);let j=this.emit();return f&&M&&this.owner&&this.target!==null&&(this.sentKey=null,this.flush()),j}clear(){return this.people=[],this.anonymous=0,this.sessions=new Map,this.session=null,this.cancel(),this.sentKey=null,this.emit()}setTarget(e){let n=y(e===void 0?null:e);return n.ok?(this.explicit=!0,this.hold(n.target)):!1}setGeneric(e){if(this.explicit)return!1;let n=y(e===void 0?null:e);return n.ok?this.hold(n.target):!1}releaseTarget(){return this.explicit?(this.explicit=!1,this.hold(null)):!1}hold(e){let n=z(e);return n===this.heldKey?(this.owner&&this.sentKey!==n&&this.schedule(m),!0):(this.target=e,this.heldKey=n,e===null?(this.cancel(),this.flush(),!0):(this.schedule(m),!0))}attachTransport(e){if(!e||typeof e.send!="function")throw new TypeError("clay.presence.attachTransport needs a transport with a send function");let n=this,s={send:e.send,get active(){return n.owner===s},detach(){if(n.owner!==s)return;let i=n.heldKey===""&&typeof n.inflightKey=="string"&&n.inflightKey!=="";if(n.owner=null,n.session=null,n.n=0,n.sentKey=null,n.inflight=!1,n.inflightOwner=null,n.inflightKey=null,n.cancel(),n.target=null,n.heldKey="",n.explicit=!1,n.clear(),i)try{Promise.resolve(s.send({editing:null})).catch(()=>{})}catch{}}};return this.owner=s,this.session=null,this.n=0,this.sentKey=null,this.inflight=!1,this.inflightOwner=null,this.inflightKey=null,this.cancel(),this.target!==null&&this.flush(),s}connect({send:e=null}={}){return this.connecting?this.connecting:(this.connecting=A().then(n=>{let s=Array.isArray(n?.extensions)?n.extensions:[],i=n?.document&&typeof n.document=="object"?n.document.awareness:null;if(i&&i.transport==="broadcast"&&(s.includes("blockeditor-awareness-v1")||s.includes("record-awareness-v1"))){let r=typeof i.scope=="string"&&i.scope?i.scope:null;return import("./c-GXOUAT7E.js").then(({localPresence:h})=>{let c=h({scope:r,store:this}),f=c.start();return f?Object.defineProperty(f,"stop",{value:()=>c.stop()}):null})}return typeof e=="function"&&s.includes("presence-editing")?this.attachTransport({send:e}):null}).finally(()=>{this.connecting=null}),this.connecting)}reconnect(){this.session=null,this.n=0,this.sentKey=null,this.cancel(),!(!this.owner||this.target===null)&&this.flush()}emit(){let e=this.people.map(n=>Object.freeze({...n,sessions:Object.freeze(n.sessions)}));this.snapshot=Object.freeze({supported:this.supported,recordAwareness:this.recordAwareness,pageAwareness:this.pageAwareness,people:Object.freeze(e),anonymous:this.anonymous});for(let n of[...this.listeners])n(this.snapshot);return this.snapshot}schedule(e,n="coalesce"){if(this.timer!==null){if(this.timerKind==="coalesce")return;clearTimeout(this.timer)}this.timerKind=n,this.timer=setTimeout(()=>{this.timer=null,this.timerKind=null,this.flush()},e)}cancel(){this.timer!==null&&(clearTimeout(this.timer),this.timer=null,this.timerKind=null)}renew(){this.timer!==null||!this.owner||this.target===null||this.schedule(E,"renew")}flush(){if(this.inflight)return;let e=this.owner;if(!e)return;let n=this.n+1,s=N({target:this.target,session:this.session,n});if(!s)return;this.cancel(),this.sentKey=this.heldKey,this.inflight=!0,this.inflightOwner=e,this.inflightKey=this.sentKey,s.v===p&&(this.n=n);let i=r=>{if(this.inflightOwner===e&&(this.inflight=!1,this.inflightOwner=null,this.inflightKey=null,this.owner===e)){if(this.heldKey!==this.sentKey){this.flush();return}r?this.renew():this.schedule(E,"renew")}};Promise.resolve(e.send(s)).then(r=>i(!!r),()=>i(!1))}},S=new k,ct=S;if(typeof window<"u"&&(window.clay=window.clay||{},!window.clay.presence)){window.clay.presence=S;try{document.dispatchEvent(new CustomEvent("clay:presence-ready",{detail:{presence:S}}))}catch{}}export{p as a,E as b,it as c,y as d,k as e,S as f,ct as g};
@@ -1 +1 @@
1
- import{a,b,c,d,e,f,g,h}from"./c-KU3PX7LL.js";import"./c-EQ5NBOGA.js";import"./c-C7SUMNMI.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-U4TWEIKZ.js";import"./c-HA6INT6J.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";export{b as conditionalSaves,f as forgetEtag,e as forgetRepresentedEtag,a as lastSeenEtag,g as learnConditionalSaves,c as recordEtag,d as representedEtag,h as seedEtag};
1
+ import{a,b,c,d,e,f,g,h}from"./c-OSGTRM4C.js";import"./c-26W3BMWK.js";import"./c-JEWSJHMK.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-U4TWEIKZ.js";import"./c-HA6INT6J.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";export{b as conditionalSaves,f as forgetEtag,e as forgetRepresentedEtag,a as lastSeenEtag,g as learnConditionalSaves,c as recordEtag,d as representedEtag,h as seedEtag};
@@ -1,4 +1,4 @@
1
- import{e as X,f as G,h as J,i as Q,j as P,k as U}from"./c-DEYHCYJB.js";import{a as C,f as L}from"./c-VO6RSFCO.js";import"./c-WN3MXOLT.js";import"./c-EIUKME3W.js";import{a as O,b as N,n as z,o as K,p as j,q as V,z as T}from"./c-WHQUZM2V.js";import{p as w}from"./c-3XGLJAS7.js";import"./c-OH2FPYSY.js";import{b as y,d as H}from"./c-RETTCOWO.js";import{b as W}from"./c-NL4I4KNG.js";import"./c-7SWMYKAI.js";import"./c-UGHH4MB3.js";import"./c-MZCOGNZL.js";import{d as q}from"./c-EQ5NBOGA.js";import"./c-IJUK2GPW.js";import"./c-C7SUMNMI.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-U4TWEIKZ.js";import"./c-MOP5KBWZ.js";import"./c-2YYDMLNZ.js";import"./c-HA6INT6J.js";import"./c-ICMAOOGK.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var ce=128,D=r=>r.depth?r.node(1).attrs.id:null,Z=r=>!!r.depth&&r.node(1).type.name==="table",ae=(r,t,o,e,n)=>O(K(z(r.flow,J(t,o.holes,e,o.visible),n)));function te({pd:r,w:t,doc:o},e){if(!r||!t||!o||!e)return null;if(e instanceof y.TextSelection){let n=e.$anchor,s=e.$head;if(Z(n)||Z(s)){let a=P(o,n.pos),u=P(o,s.pos);return!a||!u||a.table!==u.table||a.row!==u.row||a.col!==u.col?null:{kind:"cell",block:a.table,row:a.row,col:a.col}}let i=Math.min(e.from,e.to),l=a=>{let u=D(a);return u===null?null:{block:u,rel:ae(r,o,t,a.pos,e.empty||a.pos===i?0:-1)}},c=l(n),m=l(s);return c&&m?{kind:"text",anchor:c,head:m}:null}if(e instanceof w||e instanceof y.NodeSelection){let n=[];if(e instanceof w){let{lo:s,hi:i}=e.span();o.forEach((l,c,m)=>{m>=s&&m<=i&&n.push(l.attrs.id)})}else{let s=o.nodeAt(e.from);s&&n.push(s.attrs.id)}if(!n.length)return null;if(n.length>ce){let s=D(e.$from);return s?{kind:"blocks",ids:[s]}:null}return{kind:"blocks",ids:n}}return null}var ue=(r,t)=>{if(!t||typeof t!="object"||typeof t.block!="string"||!t.block||typeof t.rel!="string"||!t.rel)return null;let o;try{o=j(N(t.rel))}catch{return null}let e;try{e=V(o,r.ydoc)}catch{return null}return!e||e.type!==r.flow?null:e.index},fe=(r,t)=>{let o=0;for(let e=r.flow._start;e;e=e.right){let n=o+e.length;if(t<n)return!e.deleted;o=n}return!1},de=(r,t)=>{for(let o=r.flow._start;o;o=o.right)if(!o.deleted&&o.content instanceof T&&o.content.embed?.b===t)return!0;return!1},me=(r,t)=>{let o=0,e=null,n=0;for(let s=r.flow._start;s;s=s.right)if(s.content instanceof T&&s.content.embed?.b!==void 0&&(e=s.content.embed.b,n=o+s.length),o+=s.length,o>t&&e!==null)return{id:e,offset:t-n};return e===null?null:{id:e,offset:t-n}},pe=(r,t,o)=>{let e=null;return r.forEach((n,s)=>{e===null&&n.attrs.id===t&&n.isTextblock&&(e=s+1+Math.min(Math.max(o,0),n.content.size))}),e},ee=({pd:r,w:t,doc:o},e)=>{let n=ue(r,e);if(n===null)return null;let s=Q(o,t.holes,t.tokens,n,t.visible);if(D(o.resolve(s))===e.block)return s;let i=me(r,n);if(i&&i.id===e.block){let l=pe(o,e.block,i.offset);if(l!==null)return l}return de(r,e.block)||!fe(r,n)||t.holes.some(l=>n>=G(t.holes,l.at)&&n<X(t.holes,l.at))?null:o.resolve(s).parent.inlineContent?s:null};function oe({pd:r,w:t,doc:o},e){if(!r||!t||!o||!e||typeof e!="object")return null;if(e.kind==="text"){let n=ee({pd:r,w:t,doc:o},e.anchor),s=ee({pd:r,w:t,doc:o},e.head);return n===null||s===null?null:{kind:"text",from:Math.min(n,s),to:Math.max(n,s)}}if(e.kind==="cell"){let n=U(o,{table:e.block,row:e.row,col:e.col,offset:0});return n?{kind:"cell",from:n.from,to:n.to,block:n.block,row:n.row,col:n.col}:null}if(e.kind==="blocks"){let n=[],s=[];for(let i of Array.isArray(e.ids)?e.ids:[])o.forEach((l,c)=>{l.attrs.id!==i||n.includes(i)||(n.push(i),s.push({from:c,to:c+l.nodeSize}))});return s.length?{kind:"blocks",ids:n,ranges:s}:null}return null}var{Plugin:be,PluginKey:ge}=y,{Decoration:h,DecorationSet:x}=H,k=new ge("blockeditor-awareness"),ne="blockeditor-awareness-style",he=`
1
+ import{e as X,f as G,h as J,i as Q,j as P,k as U}from"./c-DEYHCYJB.js";import{a as C,f as L}from"./c-HBSBQBD7.js";import"./c-WN3MXOLT.js";import"./c-EIUKME3W.js";import{a as O,b as N,n as z,o as K,p as j,q as V,z as T}from"./c-WHQUZM2V.js";import{p as w}from"./c-3XGLJAS7.js";import"./c-OH2FPYSY.js";import{b as y,d as H}from"./c-RETTCOWO.js";import{b as W}from"./c-NL4I4KNG.js";import"./c-7SWMYKAI.js";import"./c-UGHH4MB3.js";import"./c-MZCOGNZL.js";import{d as q}from"./c-26W3BMWK.js";import"./c-IJUK2GPW.js";import"./c-JEWSJHMK.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-U4TWEIKZ.js";import"./c-MOP5KBWZ.js";import"./c-2YYDMLNZ.js";import"./c-HA6INT6J.js";import"./c-ICMAOOGK.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var ce=128,D=r=>r.depth?r.node(1).attrs.id:null,Z=r=>!!r.depth&&r.node(1).type.name==="table",ae=(r,t,o,e,n)=>O(K(z(r.flow,J(t,o.holes,e,o.visible),n)));function te({pd:r,w:t,doc:o},e){if(!r||!t||!o||!e)return null;if(e instanceof y.TextSelection){let n=e.$anchor,s=e.$head;if(Z(n)||Z(s)){let a=P(o,n.pos),u=P(o,s.pos);return!a||!u||a.table!==u.table||a.row!==u.row||a.col!==u.col?null:{kind:"cell",block:a.table,row:a.row,col:a.col}}let i=Math.min(e.from,e.to),l=a=>{let u=D(a);return u===null?null:{block:u,rel:ae(r,o,t,a.pos,e.empty||a.pos===i?0:-1)}},c=l(n),m=l(s);return c&&m?{kind:"text",anchor:c,head:m}:null}if(e instanceof w||e instanceof y.NodeSelection){let n=[];if(e instanceof w){let{lo:s,hi:i}=e.span();o.forEach((l,c,m)=>{m>=s&&m<=i&&n.push(l.attrs.id)})}else{let s=o.nodeAt(e.from);s&&n.push(s.attrs.id)}if(!n.length)return null;if(n.length>ce){let s=D(e.$from);return s?{kind:"blocks",ids:[s]}:null}return{kind:"blocks",ids:n}}return null}var ue=(r,t)=>{if(!t||typeof t!="object"||typeof t.block!="string"||!t.block||typeof t.rel!="string"||!t.rel)return null;let o;try{o=j(N(t.rel))}catch{return null}let e;try{e=V(o,r.ydoc)}catch{return null}return!e||e.type!==r.flow?null:e.index},fe=(r,t)=>{let o=0;for(let e=r.flow._start;e;e=e.right){let n=o+e.length;if(t<n)return!e.deleted;o=n}return!1},de=(r,t)=>{for(let o=r.flow._start;o;o=o.right)if(!o.deleted&&o.content instanceof T&&o.content.embed?.b===t)return!0;return!1},me=(r,t)=>{let o=0,e=null,n=0;for(let s=r.flow._start;s;s=s.right)if(s.content instanceof T&&s.content.embed?.b!==void 0&&(e=s.content.embed.b,n=o+s.length),o+=s.length,o>t&&e!==null)return{id:e,offset:t-n};return e===null?null:{id:e,offset:t-n}},pe=(r,t,o)=>{let e=null;return r.forEach((n,s)=>{e===null&&n.attrs.id===t&&n.isTextblock&&(e=s+1+Math.min(Math.max(o,0),n.content.size))}),e},ee=({pd:r,w:t,doc:o},e)=>{let n=ue(r,e);if(n===null)return null;let s=Q(o,t.holes,t.tokens,n,t.visible);if(D(o.resolve(s))===e.block)return s;let i=me(r,n);if(i&&i.id===e.block){let l=pe(o,e.block,i.offset);if(l!==null)return l}return de(r,e.block)||!fe(r,n)||t.holes.some(l=>n>=G(t.holes,l.at)&&n<X(t.holes,l.at))?null:o.resolve(s).parent.inlineContent?s:null};function oe({pd:r,w:t,doc:o},e){if(!r||!t||!o||!e||typeof e!="object")return null;if(e.kind==="text"){let n=ee({pd:r,w:t,doc:o},e.anchor),s=ee({pd:r,w:t,doc:o},e.head);return n===null||s===null?null:{kind:"text",from:Math.min(n,s),to:Math.max(n,s)}}if(e.kind==="cell"){let n=U(o,{table:e.block,row:e.row,col:e.col,offset:0});return n?{kind:"cell",from:n.from,to:n.to,block:n.block,row:n.row,col:n.col}:null}if(e.kind==="blocks"){let n=[],s=[];for(let i of Array.isArray(e.ids)?e.ids:[])o.forEach((l,c)=>{l.attrs.id!==i||n.includes(i)||(n.push(i),s.push({from:c,to:c+l.nodeSize}))});return s.length?{kind:"blocks",ids:n,ranges:s}:null}return null}var{Plugin:be,PluginKey:ge}=y,{Decoration:h,DecorationSet:x}=H,k=new ge("blockeditor-awareness"),ne="blockeditor-awareness-style",he=`
2
2
  .blockeditor-remote-selection { background-color: color-mix(in srgb, var(--blockeditor-remote-color, currentColor) 22%, transparent); }
3
3
  .blockeditor-remote-caret { position: relative; display: inline-block; width: 0; height: 1.1em; vertical-align: text-bottom; }
4
4
  .blockeditor-remote-caret::before { content: ""; position: absolute; inset-inline-start: -1px; top: 0; bottom: 0; width: 2px; background: var(--blockeditor-remote-color, currentColor); }
@@ -1 +1 @@
1
- import{a}from"./c-755ZOHOM.js";import"./c-EHAR4RJJ.js";import"./c-LD6UVV5R.js";import"./c-PGSBXHUE.js";import"./c-KU3PX7LL.js";import"./c-EQ5NBOGA.js";import"./c-IJUK2GPW.js";import"./c-C7SUMNMI.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-U4TWEIKZ.js";import"./c-UW6MMZ4V.js";import"./c-XQXZAO7N.js";import"./c-S7LK4KUE.js";import"./c-MOP5KBWZ.js";import"./c-2YYDMLNZ.js";import"./c-HA6INT6J.js";import"./c-ICMAOOGK.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";export{a as replace};
1
+ import{a}from"./c-W5HY5JHM.js";import"./c-CKG4NF7J.js";import"./c-LD6UVV5R.js";import"./c-PGSBXHUE.js";import"./c-OSGTRM4C.js";import"./c-26W3BMWK.js";import"./c-IJUK2GPW.js";import"./c-JEWSJHMK.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-U4TWEIKZ.js";import"./c-UW6MMZ4V.js";import"./c-XQXZAO7N.js";import"./c-S7LK4KUE.js";import"./c-MOP5KBWZ.js";import"./c-2YYDMLNZ.js";import"./c-HA6INT6J.js";import"./c-ICMAOOGK.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";export{a as replace};
@@ -1 +1 @@
1
- import{a as Qt}from"./c-4ASQPRQL.js";import{a as Ot}from"./c-GQ6F6IDK.js";import{c as F}from"./c-I2SCCUEW.js";import{b as We}from"./c-5VYOWDTI.js";import{a as Vt,d as $,e as Ge,f as R,h as N}from"./c-P73XPAOA.js";import{a as Ke,b as Yt,c as jt,d as zt}from"./c-ZPI7M5U5.js";import{a as $t}from"./c-UGHH4MB3.js";import{a as kt}from"./c-MZCOGNZL.js";import{a as Rt,f as Ft,g as P,h as Ut,i as qt,j as Bt,m as Ht,u as Gt,w as Wt,x as Kt}from"./c-EHAR4RJJ.js";import{b as Nt,h as He}from"./c-PGSBXHUE.js";import{a as qe,c as It,g as bt,h as Be}from"./c-KU3PX7LL.js";import{a as be,f as Re,h as Q}from"./c-IJUK2GPW.js";import{b as K,e as Pt,f as A}from"./c-C7SUMNMI.js";import{k as Ct,m as Mt,o as xt}from"./c-U4TWEIKZ.js";import{E as Ue,h as Ne,r as Fe,u as Lt,y as V,z as me}from"./c-UW6MMZ4V.js";import{d as Dt}from"./c-MOP5KBWZ.js";import{a as pe}from"./c-2YYDMLNZ.js";import{d as Et,e as wt,g as At,h as Tt}from"./c-HA6INT6J.js";import{k as _t}from"./c-ICMAOOGK.js";var An="clay:debug:autosave";function ve(){try{return localStorage.getItem(An)==="true"}catch{return!1}}function ge(){return import("./c-CFHW5AMY.js").catch(e=>(console.warn("[autosave-debug] Failed to load the debug logger:",e),null))}function he(e,t){ve()&&ge().then(n=>n?.logSaveCheck(e,t))}function re(e,t=""){ve()&&ge().then(n=>n?.logBaseline(e,t))}function Xt(e,t){ve()&&ge().then(n=>n?.logUnloadDiffSync(e,t))}function Jt(){ve()&&ge().then(e=>e?.preloadIfEnabled())}var U=Number.NEGATIVE_INFINITY;function Tn({firstDirtyAt:e=U,lastActivityAt:t=U,finishedAt:n=U,costMs:o=0}={}){let r=e??U,i=t??U,a=n??U,f=Math.min(3e4,Math.max(1200,4*o)),u=Math.max(i,a)+1500,m=Math.max(r+1e4,a+f);return Math.max(a+1200,Math.min(u,m))}function Zt({now:e=()=>Date.now(),setTimer:t=(r,i)=>setTimeout(r,i),clearTimer:n=r=>clearTimeout(r),run:o=()=>{}}={}){let r=null,i=null,a=U,f=0,u=null,m=null,c=!1,p=!1;function S(){return Tn({firstDirtyAt:r,lastActivityAt:i,finishedAt:a,costMs:f})}function y(){if(!c||p)return;let E=S();if(u!==null){if(m===E)return;n(u)}m=E,u=t(d,Math.max(0,E-e()))}function d(){if(u=null,m=null,!(!c||p)){if(e()<S()){y();return}g()}}function g(){c=!1,p=!0,r=null,i=null;let E;try{E=o()}catch{l();return}Promise.resolve(E).then(l,l)}function l(){p=!1,a=e(),c&&y()}function s({at:E=e()}={}){r===null&&(r=E),i=E,c=!0,y()}function v(){c=!0,y()}function M(E){E>0&&(f=Math.max(E,f*.8))}return{noteActivity:s,request:v,noteCost:M,dueAt:S,costEstimate:()=>f,pending:()=>c||p,running:()=>p}}Fe(e=>{for(let t of Tt)e.removeAttribute(t)},{required:!0});Fe(e=>{for(let t of[...Et,...wt,...At])e.removeAttribute(t)},{required:!0});var x=null;function w(e,t="",n="",o=null){x&&(clearTimeout(x),x=null),document.documentElement.setAttribute("savestatus",e);let r=new CustomEvent(`clay:save-${e}`,{detail:{msg:t,msgType:n,timestamp:Date.now(),...o||{}}});document.dispatchEvent(r),Mn(e,r.detail)}var an=Symbol.for("clay.saveFailureClaimed"),Br=e=>{e?.detail&&(e.detail[an]=!0)},Ee=null,un=()=>(Ee??=import("./c-2EFMJYGJ.js").catch(e=>{throw Ee=null,e}),Ee),Cn=()=>{un().then(e=>e.warm(),()=>{})};for(let e of["beforeinput","keydown","pointerdown"])document.addEventListener(e,Cn,{once:!0,capture:!0});function Mn(e,t){if(e==="saved"){Ee?.then(n=>n.clearFailures(),()=>{});return}e!=="error"&&e!=="offline"||t?.[an]||un().then(n=>n.reportFailure(e),n=>{console.error("clayjs: a save failed and the notice for it could not be downloaded",n)})}function ot(){x&&(clearTimeout(x),x=null),document.documentElement.setAttribute("savestatus","offline")}function xn(){x=setTimeout(()=>{w("saving")},500)}window.addEventListener("offline",()=>{ot()});window.addEventListener("online",()=>{document.documentElement.getAttribute("savestatus")==="offline"&&I().then(e=>{e.msgType==="skipped"&&document.documentElement.getAttribute("savestatus")==="offline"&&document.documentElement.setAttribute("savestatus","saved")})});var q=!1,L="",C="",ie=0,we=new Set,D=!1,k=!1,Ae=!1,B=0,je=!1;function Pn(){B++}function ln(){B!==0&&(B--,!(B>0)&&(fe&&(fe=!1,Z=setTimeout(mt,0)),je&&(je=!1,Oe())))}function _n(){return B>0}var Y=0,ne=!1,ae=!1,Te=!1;function de(e=null){return Y===0||dn(e)}function st(){return ne}function Dn(){if(ne)return!0;try{let e=V({flushUndo:!1});return St(e)?!1:e!==C}catch{return!0}}function kn(){let e="idle",t=0;return{get phase(){return e},get open(){return e==="open"},changedWhileClosed(){return e==="quiesced"&&Ge()!==t},start(){e==="idle"&&(e="open")},quiesce(){e==="open"&&(e="quiesced",t=Ge(),Y++)},resume(){e==="quiesced"&&(e="open",Y--,!(Y>0)&&(zn(),on()))},stop(){if(e==="stopped")return;let n=e==="quiesced";(n||e==="open")&&Dn()&&(Te=!0),e="stopped",n&&(Y--,Y===0&&on())}}}var en=!1,oe=null,ze=null,Xe=!1;function Hr(e=b){if(!oe||oe.generation!==e)return null;let{bytes:t,etag:n}=oe;return{bytes:t,etag:n}}function Gr({represented:e}={}){let t=R(),{forComparison:n,forDirty:o}=me(),r=typeof e?.etag=="string"&&e.etag?e.etag:null;return!(Xe&&r!==null&&r!==ze)&&Te&&(n!==L||o!==C)?{ok:!1,code:"pending-input"}:(Te=!1,ue(n,o),W=n,ee=!1,vt=!0,ze=r,Xe=!0,N(t),document.documentElement.setAttribute("savestatus","saved"),document.dispatchEvent(new CustomEvent("clay:baseline-settled")),{ok:!0})}var it=Promise.resolve(!1),Ce=!1,Ln=()=>(Ce=!0,bt().catch(()=>!1).then(e=>(Ce=!1,e)));function Wr(){return{id:"clay:save",order:10,prepare(e={}){let t=kn();return e.initial===!0&&t.start(),{enable(){it=Ln();let n=e.represented?.etag;typeof n=="string"&&n&&It(n),e.initial!==!0&&(On(),t.start())},quiesce:()=>t.quiesce(),resume:()=>t.resume(),dispose:()=>t.stop()}}}}function On(){en||(en=!0,Vt(),be(),En(),wn())}var O=0,Je=!1,Me=!1,at="Waiting for the AI edit to be kept or reverted",j=new Map;function Kr(e=at){O++,j.set(e,(j.get(e)||0)+1)}function Qr({replay:e=!0,reason:t=at}={}){let n=j.get(t)||0;if(n===0||(n===1?j.delete(t):j.set(t,n-1),O--,O>0))return;let o=Je,r=Me;Je=!1,Me=!1,e&&(o?I():r&&Oe())}function Vr(){return O>0}function ut(){return O===0?null:j.keys().next().value||at}function fn(e,t){if(O===0)return!1;Je=!0,Q();let n=h(ut());return e(n),t(n),n}var H=!1,se=null;function In(e){se=e??null,!H&&(H=!0,Pn())}function bn(){H&&(H=!1,se=null,ln())}function Ze(){return H}function $r(e){if(!H||se&&e!==se)return;H=!1,se=null,!We()&&$()||(document.documentElement.getAttribute("savestatus")==="conflict"&&document.documentElement.setAttribute("savestatus","saved"),document.dispatchEvent(new CustomEvent("clay:save-conflict-resolved",{detail:{timestamp:Date.now()}}))),document.dispatchEvent(new CustomEvent("clay:save-conflict-released",{detail:{etag:e??null}})),ln()}function h(e){return{ok:!1,msg:e,msgType:"skipped",code:null,etag:null}}function lt(e){return($()||F())&&(ne=!0),h(e)}function cn(){return{ok:!1,msg:"You are not allowed to save this document.",msgType:"forbidden",code:"forbidden",status:403,sent:!1,etag:null}}function ft(){return Pt()===!1}var ct=new Set,b=0;function Yr(){return b}function jr(e){typeof e=="number"&&(b=e)}function Rn(e=b){let t=Object.freeze({generation:e});return ct.add(t),t}function Nn(e){ct.delete(e)}function dn(e){return!!e&&ct.has(e)&&e.generation===b}function z(e,t){e!=null&&zt({captureId:e,ok:t.ok===!0,etag:t.etag??null})}function Fn(e,t,n,o,r,i=null,a=null,f=!1){if(z(a,e),e.ok)ne=!1,ue(t,n),xe=i,oe={bytes:i,etag:qe(),generation:b},ze=oe.etag,Xe=!0,Te=!1,q=!1,N(r),w("saved",e.msg||"Saved",e.msgType,{etag:e.etag??null,captureId:a}),re(o,`${L.length} chars`),bn();else if(e.msgType==="conflict"){if(f){x&&(clearTimeout(x),x=null),document.documentElement.setAttribute("savestatus","saved");return}In(e.conflictEtag),w("conflict",e.msg,e.msgType,{hadTimeout:e.hadTimeout===!0,changedBy:e.changedBy??null,afterTimeout:e.afterTimeout===!0,etag:e.conflictEtag??null,code:e.code??null,reason:e.reason??null,retryAfter:e.retryAfter??null,captureId:a})}else if(e.msgType!=="skipped"){let u={status:e.status??null,hadTimeout:e.hadTimeout===!0,code:e.code??null,reason:e.reason??null,retryAfter:e.retryAfter??null,captureId:a};navigator.onLine?w("error",e.msg,e.msgType||"error",u):w("offline",e.msg,e.msgType||"error",u)}}function pn(){if(!(!D&&!k)&&!Ht()){if(D){D=!1,k=!1,I();return}k=!1,nt.request()}}function zr(){return q}function Xr(e){q=e}function Jr(){return L}function dt(){return C}var xe=null;function Zr(){return xe}function ue(e,t){L=e,C=t,ie++}function eo(e){ue(e,e)}var G=()=>typeof performance<"u"&&performance.now?performance.now():Date.now();var Un=4,tn="Save cancelled: the page changed while it prepared",X=null,le=null,Qe=null,mn=!1;function vn(){return Qe||(Qe=import("./c-DYTBSJBI.js").then(e=>(le=e,e),e=>(mn=!0,console.info("clayjs: sliced save off ("+(e&&e.message?e.message:e)+"); saves prepare in one task"),null))),Qe}function qn(){try{return performance.getEntriesByType("navigation")[0]?.decodedBodySize||0}catch{return 0}}var Bn=()=>typeof xe=="string"?xe.length:qn();function Pe(){return mn||document.hidden||Bt()?!1:Bn()>=307200}function nn(e,t,n){return n?"morph":b!==t.generation||!A?"mode":de(e.permit)?ft()?"refused":ie!==t.baselines?"newer save":Math.max(He(),e.blockeditorFormatFloor)>t.floor?"floor":null:"session"}function Hn(e=150,t=2e3){return new Promise(n=>{let o=G(),r=null,i=()=>{document.removeEventListener("clay:sync-applied",a),n()},a=()=>{clearTimeout(r),r=setTimeout(i,Math.max(0,Math.min(e,t-(G()-o))))};document.addEventListener("clay:sync-applied",a),a()})}async function pt({explicit:e,forced:t=!1,forSave:n,forComparison:o,forDirty:r,captureId:i,gateToken:a,costMs:f,blockeditorFormatFloor:u=0,quietConflict:m=!1,laneHeld:c=!1,lane:p=null,capture:S,noteRecovery:y,release:d,callback:g}){if(y(),e&&!t){if(q=r!==C,he("savePage dirty check",!q),!q){Q(),N(a),d();let s=h("No changes to save");return z(i,s),typeof g=="function"&&g(s),{result:s,dispatched:!1}}}else if(!e){let s=!ee||o!==W,v=o!==L;if(he("throttled vs baseline",!s),he("throttled vs lastSave",!v),!(s&&v)){let M=!1;try{M=!v&&(!document.querySelector(_t)||$()&&r===C)}catch(yt){console.error("savePageThrottled: dirty domain check failed",yt)}M&&N(a),nt.noteCost(f),d();let E=h("No changes to save");return z(i,E),typeof g=="function"&&g(E),{result:E,dispatched:!1}}if(q=!0,!c&&P()){D=!0,d();let M=h("Save already in progress");return z(i,M),typeof g=="function"&&g(M),{result:M,dispatched:!1}}}xn();let l={forComparison:o,forDirty:r};return we.add(l),Ae=!0,new Promise(s=>{Gt(n,i,v=>{Ae=!1,we.delete(l);let M=G();Fn(v,l.forComparison,l.forDirty,t?"updated after force save":"updated after save",a,n,i,m),e||nt.noteCost(f+(G()-M)),typeof g=="function"&&g(v),s({result:v,dispatched:!0}),c||pn()},{capture:S,blockeditorFormatFloor:u,lane:p,gateToken:a})})}async function Gn(e,t){let n={over:!1},o=()=>{n.over=!0};document.addEventListener("clay:sync-applied",o);try{for(let i=0;i<2;i++){let a=R(),f={generation:b,baselines:ie,floor:Math.max(He(),e.blockeditorFormatFloor)},u=le.beginSaveCapture({requestRefresh:!0,forRequest:!0,pageFormatMarker:f.floor?{name:Nt,content:String(f.floor)}:null});Yt(u.captureId);let m=null,c={get aborted(){let d=nn(e,f,n.over);return d&&(m=d),!!d}},p;try{p=await le.runPreparedSteps(u.steps(),{budgetMs:Un,signal:c})}catch(d){console.error(`${e.explicit?"savePage":"savePageThrottled"}: preparing the save failed`,d),u.drop();let g={msg:d&&d.message?d.message:"Save failed",msgType:"error",code:d?.code??null,etag:null};return w("error",g.msg,"",{sent:!1,code:g.code}),z(u.captureId,g),typeof e.callback=="function"&&e.callback(g),{result:g,dispatched:!1}}let S=p.aborted?m:nn(e,f,n.over);if(!S){let d=p.result;return await pt({explicit:e.explicit,forced:e.forced,forSave:d.forSave,forComparison:d.forComparison,forDirty:d.forDirty,captureId:d.captureId,gateToken:a,costMs:p.activeMs,blockeditorFormatFloor:e.blockeditorFormatFloor,quietConflict:e.quietConflict,laneHeld:!0,lane:t,capture:d,noteRecovery:()=>jt(d.captureId,d.forSave),release:()=>u.drop(),callback:e.callback})}u.drop();let y=h(tn);if(S==="session"&&(ae=!0),z(u.captureId,y),!(S==="floor"&&i===0)){if(S==="morph"&&e.explicit&&i===0){await Hn(),n.over=!1;continue}return typeof e.callback=="function"&&e.callback(y),{result:y,dispatched:!1}}}let r=h(tn);return typeof e.callback=="function"&&e.callback(r),{result:r,dispatched:!1}}finally{document.removeEventListener("clay:sync-applied",o),qt(t)}}function gn(e){let t=Ut();if(!t)return!1;let n=Gn(e,t).catch(o=>{console.error("save: preparing the save failed",o);let r={msg:o&&o.message?o.message:"Save failed",msgType:"error",code:o?.code??null,etag:null};return w("error",r.msg,"",{sent:!1,code:r.code}),typeof e.callback=="function"&&e.callback(r),{result:r,dispatched:!1}});return X=n,n.then(o=>{X===n&&(X=null),e.resolve(o.result),e.settleSoonQueued(o.result),(o.dispatched||D||k||ke.length)&&pn()}),!0}function Le(e,t=()=>{}){return Ce?it.then(()=>Le(e,t)):te?ce.then(()=>De(e,t)):De(e,t)}function _e(e,t){let n=!1,o=setTimeout(()=>{n=!0,w("saving")},500);return e.then(()=>(clearTimeout(o),t())).then(r=>(n&&!P()&&!$()&&document.documentElement.getAttribute("savestatus")==="saving"&&(document.documentElement.setAttribute("savestatus","saved"),document.dispatchEvent(new CustomEvent("clay:save-status",{detail:{state:"saved"}}))),r))}function De({kind:e,permit:t=null},n=()=>{}){let o=e==="explicit";return new Promise(r=>{if(!A&&!window.clay?.testMode){o&&Q();let s=h("Not in edit mode");return T().forEach(v=>v(s)),n(s),r(s)}if(!de(t)){ae=!0;let s=lt("Save session is quiesced");return o&&T().forEach(v=>v(s)),n(s),r(s)}if(ft()){o&&Q();let s=cn();return w("error",s.msg,"",{code:s.code,status:s.status,sent:!1}),T().forEach(v=>v(s)),n(s),r(s)}if(o){let s=fn(n,r);if(s){T().forEach(v=>v(s));return}if(P()){D=!0;let v=h("Save already in progress");return n(v),r(v)}}else{if(O>0){Me=!0;let s=h(ut());return n(s),r(s)}if(P()&&!ee&&Ae){k=!0;let s=h("Save already in progress");return n(s),r(s)}if(X){k=!0;let s=h("Save already in progress");return n(s),r(s)}if(!ee&&!$()){let s=h("No changes to save");return n(s),r(s)}}let i=window.clay?.source?.ensureForSave?.();if(i)return r(_e(i,()=>De({kind:e,permit:t},n)));if(Pe()&&!le){r(_e(vn(),()=>De({kind:e,permit:t},n)));return}let a=o?T():[],f=s=>a.forEach(v=>v(s));if(!navigator.onLine&&ot(),Pe()&&gn({explicit:o,forced:!1,permit:t,blockeditorFormatFloor:0,quietConflict:!1,settleSoonQueued:f,callback:n,resolve:r}))return;let m=G(),c,p,S,y,d,g=R();try{c=Ue({requestRefresh:!0,forRequest:!0}),{forSave:p,forComparison:S,forDirty:y,captureId:d}=c}catch(s){console.error(`${o?"savePage":"savePageThrottled"}: captureForSaveAndComparison failed`,s),o?(Q(),w("error",s.message,"error",{sent:!1,code:s.code??null})):w("error",s.message,"error");let v={ok:!1,msg:s.message,msgType:"error",code:o?s.code??null:null,etag:null};typeof n=="function"&&n(v),r(v),f(v);return}let l=G()-m;pt({explicit:o,forSave:p,forComparison:S,forDirty:y,captureId:d,gateToken:g,costMs:l,capture:c,noteRecovery:()=>Ke({captureId:d,html:p}),release:()=>Ne(c),callback:n}).then(s=>{r(s.result),f(s.result)})})}function I(e=()=>{}){return Le({kind:"explicit"},e)}function Wn(e,t=()=>{}){return Le({kind:"explicit",permit:e},t)}function J(e=()=>{},{quietConflict:t=!1,blockeditorFormatFloor:n=0,permit:o=null}={}){return Ce?it.then(()=>J(e,{quietConflict:t,blockeditorFormatFloor:n,permit:o})):new Promise(r=>{if(!A&&!window.clay?.testMode){let l=h("Not in edit mode");return T().forEach(s=>s(l)),e(l),r(l)}if(!de(o)||o&&!dn(o)){let l=lt("Save session is quiesced");return T().forEach(s=>s(l)),e(l),r(l)}if(ft()){let l=cn();return w("error",l.msg,"",{code:l.code,status:l.status,sent:!1}),T().forEach(s=>s(l)),e(l),r(l)}let i=fn(e,r);if(i){T().forEach(l=>l(i));return}if(P()){D=!0;let l=h("Save already in progress");return T().forEach(s=>s(l)),e(l),r(l)}let a=window.clay?.source?.ensureForSave?.();if(a)return r(_e(a,()=>J(e,{quietConflict:t,blockeditorFormatFloor:n,permit:o})));if(!navigator.onLine&&ot(),Pe()&&!le){r(_e(vn(),()=>J(e,{quietConflict:t,blockeditorFormatFloor:n,permit:o})));return}let u=T(),m=l=>u.forEach(s=>s(l));if(Pe()&&gn({explicit:!0,forced:!0,permit:o,blockeditorFormatFloor:n,quietConflict:t,settleSoonQueued:m,callback:e,resolve:r}))return;let c,p,S,y,d,g=R();try{c=Ue({requestRefresh:!0,forRequest:!0}),{forSave:p,forComparison:S,forDirty:y,captureId:d}=c}catch(l){console.error("savePageForce: captureForSaveAndComparison failed",l),w("error",l.message,"error",{sent:!1,code:l.code??null});let s={ok:!1,msg:l.message,msgType:"error",code:l.code??null,etag:null};typeof e=="function"&&e(s),r(s),m(s);return}pt({explicit:!0,forced:!0,forSave:p,forComparison:S,forDirty:y,captureId:d,gateToken:g,costMs:0,blockeditorFormatFloor:n,quietConflict:t,capture:c,noteRecovery:()=>Ke({captureId:d,html:p}),release:()=>Ne(c),callback:e}).then(l=>{r(l.result),m(l.result)})})}Kt(e=>J(()=>{},{permit:e}));function Kn(e){let t=["clay:save-saved","clay:save-error","clay:save-offline","clay:save-conflict"];return new Promise((n,o)=>{let r=null,i=()=>{clearTimeout(r);for(let u of t)document.removeEventListener(u,a)},a=()=>{i(),n()},f=e-Date.now();if(f<=0){o(Object.assign(new Error("Save timed out."),{state:"failed"}));return}r=setTimeout(()=>{i(),o(Object.assign(new Error("Save timed out."),{state:"failed"}))},f);for(let u of t)document.addEventListener(u,a)})}function _(e,t){return Object.assign(new Error(e),{state:t})}function Qn(e,t){return new Promise((n,o)=>{let r=t-Date.now();if(r<=0)return o(_("Save timed out.","failed"));let i=setTimeout(()=>{document.removeEventListener(e,a),o(_("Save timed out.","failed"))},r),a=()=>{clearTimeout(i),n()};document.addEventListener(e,a,{once:!0})})}async function to({keepalive:e=!1,timeoutMs:t=15e3,permit:n=null}={}){if(!A)return{state:"view",etag:null};let o=Date.now()+t,r=n||Rn(),i={over:!1},a=null,f=new Promise((u,m)=>{a=setTimeout(()=>m(Object.assign(_("Save timed out.","failed"),{timedOut:!0})),Math.max(0,t))});try{return await Promise.race([Vn(e,o,r,i),f])}catch(u){throw u&&typeof u.state=="string"?u:_(u?.message||"Save failed","failed")}finally{i.over=!0,clearTimeout(a),n||Nn(r)}}async function Vn(e,t,n,o={over:!1}){if(hn()||await Qn("clay:baseline-settled",t),o.over)return null;let r=!1,i=null;for(let a=0;a<4;a++){if(X&&(await X,o.over)||P()&&(await Kn(t),o.over))return null;if(Ze())throw _("This document has a conflict to resolve.","conflict");let f=R();if(!rt()){if(N(f),F())throw _("This document has unsaved work a save cannot write.","blocked");return ne=!1,{state:r?"saved":"clean",etag:i??qe()}}if(o.over)return null;let u=await Ft(e,()=>Wn(n));if(u.msgType!=="skipped"){if(!u.ok)throw _(u.msg||"Save failed",u.msgType==="conflict"||Ze()?"conflict":"failed");r=!0,i=u.etag??null}}throw _("The document kept changing while saving.","failed")}async function no(e=()=>{}){return await Be({fresh:!0}),J(e)}function ro(e){!A||K||Wt(e,t=>{t.ok?window.location.reload():t.msgType==="skipped"?w("error",t.msg||"Template not saved"):w("error",t.msg||"Failed to save template")})}var $n=Ot(e=>Le({kind:"automatic"},e),1200),Yn=250,jn=1e3,Z=null,rn=0,et=[],ke=[],fe=!1,T=()=>{let e=ke;return ke=[],e};function mt(){if(Z=null,B>0||!de()){fe=!0;return}let e=et;if(et=[],P()){ke.push(...e),I();return}I().then(t=>e.forEach(n=>n(t)))}function oo(){let e=Date.now();return Z===null?rn=e:clearTimeout(Z),new Promise(t=>{et.push(t),Z=setTimeout(mt,Math.max(0,Math.min(Yn,rn+jn-e)))})}function zn(){ae&&(ae=!1,Oe())}function on(){fe&&(fe=!1,Z=setTimeout(mt,0))}var W="",ee=!0,vt=!1;function hn(){return vt}var Ve=!1,Xn=250,Jn=1250,$e=null,Sn="clay:paint-heal:"+location.pathname;function yn(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t+e.charCodeAt(n)|0;return String(t>>>0)}function Zn(e){try{return localStorage.getItem(Sn)===yn(e)}catch{return!1}}function er(e){try{localStorage.setItem(Sn,yn(e))}catch{}}function tr(){return Dt(Lt({flushUndo:!1}))}function so(e){!A||K||(clearTimeout($e),$e=setTimeout(async()=>{$e=null,te&&await ce;let t=typeof e=="function"?e():e;t==null||!We()||!hn()||Ze()||_n()||V({flushUndo:!1})===C&&t!==tr()&&(Zn(t)||(er(t),J(()=>{},{quietConflict:!0})))},Xn+Math.random()*Jn))}var Se=null,Ye=null,te=0,ce=Promise.resolve(),gt=!1,ht=[];function nr(){return Ye??=import("./c-KNPDOMDY.js").catch(e=>(Ye=null,console.error("style-comparisons failed to load",e),null)),Ye}async function rr(e){try{if(Se||(Se=(await nr())?.styleComparisonStripper??null),!Se)return;let t=Se(e);L=t(L),C=t(C),W=t(W);for(let n of we)n.forComparison=t(n.forComparison),n.forDirty=t(n.forDirty)}catch(t){console.error("style adoption failed",t)}finally{te--,ht.shift()}}var ye=e=>e.replace(/&/g,"&amp;").replace(/"/g,"&quot;");function or(e){if(e.name!==void 0){let n=[`data-name="${ye(e.name)}"`];return e.legacyId!==void 0&&n.push(`id="${ye(e.legacyId)}"`),n}let t=[ye(e.href)];try{let{pathname:n}=new URL(e.href);n&&t.push(ye(n))}catch{}return t}function sr(e){let t=[L,C,W];for(let n of we)t.push(n.forComparison,n.forDirty);return t.some(n=>n&&e.some(o=>o&&n.includes(o)))}function ir(e,t){let n=[];for(let{markers:i,tag:a}of t)for(let f of i)for(let u=e.indexOf(f);u>=0;u=e.indexOf(f,u+f.length)){let m=e.lastIndexOf("<",u);if(m<0||e.slice(m+1,m+1+a.length).toLowerCase()!==a)continue;let c=a==="style"?e.indexOf("</style",u):u;if(c<0)continue;let p=e.indexOf(">",c);p>=0&&n.push([m,p+1])}n.sort((i,a)=>i[0]-a[0]);let o="",r=0;for(let[i,a]of n)i<r||(o+=e.slice(r,i),r=a);return o+e.slice(r)}$t(e=>{let t=or(e);sr(t)&&(te||(gt=!1),te++,ht.push({markers:t,tag:e.name!==void 0?"style":"link"}),ce=ce.then(()=>rr(e)))});function io(){return ce}function St(e){return!te||gt||F()||P()||D||k||ne||typeof e!="string"?!1:e===ir(C,ht)}var ar=500,ur=3e3,lr=1e4,tt=null;function fr(){pe.holdSettle=!1,tt&&tt()}function sn(){if(!A)return;let e=!1,t=null,{forComparison:n,forDirty:o}=me();ue(n,o);let r=ie;W=n,re("immediate capture",`${n.length} chars`);let i=["keydown","pointerdown","drop","input","change","paste"],a=new Set(["Shift","Control","Alt","Meta"]),f=c=>{c.type==="keydown"&&a.has(c.key)||(gt=!0,e||(Ve=!0))};i.forEach(c=>document.addEventListener(c,f,!0));let u=()=>{if(!e){if(e=!0,t&&t(),!Ve&&ie===r){let c=R(),{forComparison:p,forDirty:S}=me();ue(p,S),W=p,N(c),re("settled capture",`${p.length} chars`)}else re("settled skipped",Ve?"user edited":"save occurred during settle");ee=!1,document.documentElement.setAttribute("savestatus","saved"),vt=!0,document.dispatchEvent(new CustomEvent("clay:baseline-settled"))}};tt=u;let m=()=>{pe.holdSettle||u()};t=kt.onAnyChange({debounce:ar,omitChangeDetails:!0,require:"autosave"},m),setTimeout(()=>{e||m()},ur),setTimeout(()=>{!e&&pe.holdSettle&&fr()},lr)}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",sn):sn();function Oe(e=()=>{}){if(!A){let t=h("Not in edit mode");return e(t),Promise.resolve(t)}if(O>0){Me=!0;let t=h(ut());return e(t),Promise.resolve(t)}if(!de()){ae=!0;let t=lt("Save session is quiesced");return e(t),Promise.resolve(t)}if(B>0){je=!0;let t=h("Autosave suspended");return e(t),Promise.resolve(t)}if(!ee&&Ae){k=!0;let t=h("Save already in progress");return e(t),Promise.resolve(t)}return $n(e).catch(t=>{let n={ok:!1,msg:t?.message||"Save failed",msgType:"error",code:null,etag:null};return w("error",n.msg),n})}var nt=Zt({now:G,run:()=>Oe()});function En(){document.addEventListener("keydown",function(e){if((window.navigator.platform.match("Mac")?e.metaKey:e.ctrlKey)&&e.keyCode==83){if(!A)return;e.preventDefault(),e.isTrusted&&Re(),I()}})}function wn(){document.addEventListener("click",e=>{e.target.closest("[trigger-save]")&&(e.isTrusted&&Re(),I())})}function cr(){A&&(Be(),Rt(),be(),En(),wn())}cr();var ao=I;var Ie=!1;function go({isCurrent:e,reload:t}){return e()?(Ie=!0,setTimeout(()=>{Ie=!1},1e3),t(),!0):!1}Jt();function dr(){return st()?!0:A?F()?!0:K?Mt()||xt():window.clay?.demo?!1:rt():!1}function rt(){if(!A)return!1;try{let e=V();return St(e)?!1:e!==dt()}catch{return!0}}window.addEventListener("beforeunload",e=>{if(!A&&!st())return;if(Ie){Ie=!1;return}if(!((!K||Ct())&&!dr())&&(e.preventDefault(),e.returnValue="",!window.clay?.demo&&!F()))try{let n=V(),o=dt();n!==o&&Xt(n,o)}catch{}});export{go as a,dr as b,rt as c,Br as d,Pn as e,ln as f,_n as g,de as h,st as i,kn as j,Hr as k,Gr as l,Wr as m,Kr as n,Qr as o,Vr as p,ut as q,Ze as r,$r as s,Yr as t,jr as u,Rn as v,Nn as w,zr as x,Xr as y,Jr as z,dt as A,Zr as B,ue as C,eo as D,I as E,J as F,to as G,no as H,ro as I,oo as J,hn as K,tr as L,so as M,io as N,St as O,fr as P,Oe as Q,nt as R,En as S,wn as T,cr as U,ao as V};
1
+ import{a as Qt}from"./c-4ASQPRQL.js";import{a as Ot}from"./c-GQ6F6IDK.js";import{c as F}from"./c-I2SCCUEW.js";import{b as We}from"./c-5VYOWDTI.js";import{a as Vt,d as $,e as Ge,f as R,h as N}from"./c-T6RRRHX7.js";import{a as Ke,b as Yt,c as jt,d as zt}from"./c-G426P2SE.js";import{a as $t}from"./c-UGHH4MB3.js";import{a as kt}from"./c-MZCOGNZL.js";import{a as Rt,f as Ft,g as P,h as Ut,i as qt,j as Bt,m as Ht,u as Gt,w as Wt,x as Kt}from"./c-CKG4NF7J.js";import{b as Nt,h as He}from"./c-PGSBXHUE.js";import{a as qe,c as It,g as bt,h as Be}from"./c-OSGTRM4C.js";import{a as be,f as Re,h as Q}from"./c-IJUK2GPW.js";import{b as K,e as Pt,f as A}from"./c-JEWSJHMK.js";import{k as Ct,m as Mt,o as xt}from"./c-U4TWEIKZ.js";import{E as Ue,h as Ne,r as Fe,u as Lt,y as V,z as me}from"./c-UW6MMZ4V.js";import{d as Dt}from"./c-MOP5KBWZ.js";import{a as pe}from"./c-2YYDMLNZ.js";import{d as Et,e as wt,g as At,h as Tt}from"./c-HA6INT6J.js";import{k as _t}from"./c-ICMAOOGK.js";var An="clay:debug:autosave";function ve(){try{return localStorage.getItem(An)==="true"}catch{return!1}}function ge(){return import("./c-CFHW5AMY.js").catch(e=>(console.warn("[autosave-debug] Failed to load the debug logger:",e),null))}function he(e,t){ve()&&ge().then(n=>n?.logSaveCheck(e,t))}function re(e,t=""){ve()&&ge().then(n=>n?.logBaseline(e,t))}function Xt(e,t){ve()&&ge().then(n=>n?.logUnloadDiffSync(e,t))}function Jt(){ve()&&ge().then(e=>e?.preloadIfEnabled())}var U=Number.NEGATIVE_INFINITY;function Tn({firstDirtyAt:e=U,lastActivityAt:t=U,finishedAt:n=U,costMs:o=0}={}){let r=e??U,i=t??U,a=n??U,f=Math.min(3e4,Math.max(1200,4*o)),u=Math.max(i,a)+1500,m=Math.max(r+1e4,a+f);return Math.max(a+1200,Math.min(u,m))}function Zt({now:e=()=>Date.now(),setTimer:t=(r,i)=>setTimeout(r,i),clearTimer:n=r=>clearTimeout(r),run:o=()=>{}}={}){let r=null,i=null,a=U,f=0,u=null,m=null,c=!1,p=!1;function S(){return Tn({firstDirtyAt:r,lastActivityAt:i,finishedAt:a,costMs:f})}function y(){if(!c||p)return;let E=S();if(u!==null){if(m===E)return;n(u)}m=E,u=t(d,Math.max(0,E-e()))}function d(){if(u=null,m=null,!(!c||p)){if(e()<S()){y();return}g()}}function g(){c=!1,p=!0,r=null,i=null;let E;try{E=o()}catch{l();return}Promise.resolve(E).then(l,l)}function l(){p=!1,a=e(),c&&y()}function s({at:E=e()}={}){r===null&&(r=E),i=E,c=!0,y()}function v(){c=!0,y()}function M(E){E>0&&(f=Math.max(E,f*.8))}return{noteActivity:s,request:v,noteCost:M,dueAt:S,costEstimate:()=>f,pending:()=>c||p,running:()=>p}}Fe(e=>{for(let t of Tt)e.removeAttribute(t)},{required:!0});Fe(e=>{for(let t of[...Et,...wt,...At])e.removeAttribute(t)},{required:!0});var x=null;function w(e,t="",n="",o=null){x&&(clearTimeout(x),x=null),document.documentElement.setAttribute("savestatus",e);let r=new CustomEvent(`clay:save-${e}`,{detail:{msg:t,msgType:n,timestamp:Date.now(),...o||{}}});document.dispatchEvent(r),Mn(e,r.detail)}var an=Symbol.for("clay.saveFailureClaimed"),Br=e=>{e?.detail&&(e.detail[an]=!0)},Ee=null,un=()=>(Ee??=import("./c-2EFMJYGJ.js").catch(e=>{throw Ee=null,e}),Ee),Cn=()=>{un().then(e=>e.warm(),()=>{})};for(let e of["beforeinput","keydown","pointerdown"])document.addEventListener(e,Cn,{once:!0,capture:!0});function Mn(e,t){if(e==="saved"){Ee?.then(n=>n.clearFailures(),()=>{});return}e!=="error"&&e!=="offline"||t?.[an]||un().then(n=>n.reportFailure(e),n=>{console.error("clayjs: a save failed and the notice for it could not be downloaded",n)})}function ot(){x&&(clearTimeout(x),x=null),document.documentElement.setAttribute("savestatus","offline")}function xn(){x=setTimeout(()=>{w("saving")},500)}window.addEventListener("offline",()=>{ot()});window.addEventListener("online",()=>{document.documentElement.getAttribute("savestatus")==="offline"&&I().then(e=>{e.msgType==="skipped"&&document.documentElement.getAttribute("savestatus")==="offline"&&document.documentElement.setAttribute("savestatus","saved")})});var q=!1,L="",C="",ie=0,we=new Set,D=!1,k=!1,Ae=!1,B=0,je=!1;function Pn(){B++}function ln(){B!==0&&(B--,!(B>0)&&(fe&&(fe=!1,Z=setTimeout(mt,0)),je&&(je=!1,Oe())))}function _n(){return B>0}var Y=0,ne=!1,ae=!1,Te=!1;function de(e=null){return Y===0||dn(e)}function st(){return ne}function Dn(){if(ne)return!0;try{let e=V({flushUndo:!1});return St(e)?!1:e!==C}catch{return!0}}function kn(){let e="idle",t=0;return{get phase(){return e},get open(){return e==="open"},changedWhileClosed(){return e==="quiesced"&&Ge()!==t},start(){e==="idle"&&(e="open")},quiesce(){e==="open"&&(e="quiesced",t=Ge(),Y++)},resume(){e==="quiesced"&&(e="open",Y--,!(Y>0)&&(zn(),on()))},stop(){if(e==="stopped")return;let n=e==="quiesced";(n||e==="open")&&Dn()&&(Te=!0),e="stopped",n&&(Y--,Y===0&&on())}}}var en=!1,oe=null,ze=null,Xe=!1;function Hr(e=b){if(!oe||oe.generation!==e)return null;let{bytes:t,etag:n}=oe;return{bytes:t,etag:n}}function Gr({represented:e}={}){let t=R(),{forComparison:n,forDirty:o}=me(),r=typeof e?.etag=="string"&&e.etag?e.etag:null;return!(Xe&&r!==null&&r!==ze)&&Te&&(n!==L||o!==C)?{ok:!1,code:"pending-input"}:(Te=!1,ue(n,o),W=n,ee=!1,vt=!0,ze=r,Xe=!0,N(t),document.documentElement.setAttribute("savestatus","saved"),document.dispatchEvent(new CustomEvent("clay:baseline-settled")),{ok:!0})}var it=Promise.resolve(!1),Ce=!1,Ln=()=>(Ce=!0,bt().catch(()=>!1).then(e=>(Ce=!1,e)));function Wr(){return{id:"clay:save",order:10,prepare(e={}){let t=kn();return e.initial===!0&&t.start(),{enable(){it=Ln();let n=e.represented?.etag;typeof n=="string"&&n&&It(n),e.initial!==!0&&(On(),t.start())},quiesce:()=>t.quiesce(),resume:()=>t.resume(),dispose:()=>t.stop()}}}}function On(){en||(en=!0,Vt(),be(),En(),wn())}var O=0,Je=!1,Me=!1,at="Waiting for the AI edit to be kept or reverted",j=new Map;function Kr(e=at){O++,j.set(e,(j.get(e)||0)+1)}function Qr({replay:e=!0,reason:t=at}={}){let n=j.get(t)||0;if(n===0||(n===1?j.delete(t):j.set(t,n-1),O--,O>0))return;let o=Je,r=Me;Je=!1,Me=!1,e&&(o?I():r&&Oe())}function Vr(){return O>0}function ut(){return O===0?null:j.keys().next().value||at}function fn(e,t){if(O===0)return!1;Je=!0,Q();let n=h(ut());return e(n),t(n),n}var H=!1,se=null;function In(e){se=e??null,!H&&(H=!0,Pn())}function bn(){H&&(H=!1,se=null,ln())}function Ze(){return H}function $r(e){if(!H||se&&e!==se)return;H=!1,se=null,!We()&&$()||(document.documentElement.getAttribute("savestatus")==="conflict"&&document.documentElement.setAttribute("savestatus","saved"),document.dispatchEvent(new CustomEvent("clay:save-conflict-resolved",{detail:{timestamp:Date.now()}}))),document.dispatchEvent(new CustomEvent("clay:save-conflict-released",{detail:{etag:e??null}})),ln()}function h(e){return{ok:!1,msg:e,msgType:"skipped",code:null,etag:null}}function lt(e){return($()||F())&&(ne=!0),h(e)}function cn(){return{ok:!1,msg:"You are not allowed to save this document.",msgType:"forbidden",code:"forbidden",status:403,sent:!1,etag:null}}function ft(){return Pt()===!1}var ct=new Set,b=0;function Yr(){return b}function jr(e){typeof e=="number"&&(b=e)}function Rn(e=b){let t=Object.freeze({generation:e});return ct.add(t),t}function Nn(e){ct.delete(e)}function dn(e){return!!e&&ct.has(e)&&e.generation===b}function z(e,t){e!=null&&zt({captureId:e,ok:t.ok===!0,etag:t.etag??null})}function Fn(e,t,n,o,r,i=null,a=null,f=!1){if(z(a,e),e.ok)ne=!1,ue(t,n),xe=i,oe={bytes:i,etag:qe(),generation:b},ze=oe.etag,Xe=!0,Te=!1,q=!1,N(r),w("saved",e.msg||"Saved",e.msgType,{etag:e.etag??null,captureId:a}),re(o,`${L.length} chars`),bn();else if(e.msgType==="conflict"){if(f){x&&(clearTimeout(x),x=null),document.documentElement.setAttribute("savestatus","saved");return}In(e.conflictEtag),w("conflict",e.msg,e.msgType,{hadTimeout:e.hadTimeout===!0,changedBy:e.changedBy??null,afterTimeout:e.afterTimeout===!0,etag:e.conflictEtag??null,code:e.code??null,reason:e.reason??null,retryAfter:e.retryAfter??null,captureId:a})}else if(e.msgType!=="skipped"){let u={status:e.status??null,hadTimeout:e.hadTimeout===!0,code:e.code??null,reason:e.reason??null,retryAfter:e.retryAfter??null,captureId:a};navigator.onLine?w("error",e.msg,e.msgType||"error",u):w("offline",e.msg,e.msgType||"error",u)}}function pn(){if(!(!D&&!k)&&!Ht()){if(D){D=!1,k=!1,I();return}k=!1,nt.request()}}function zr(){return q}function Xr(e){q=e}function Jr(){return L}function dt(){return C}var xe=null;function Zr(){return xe}function ue(e,t){L=e,C=t,ie++}function eo(e){ue(e,e)}var G=()=>typeof performance<"u"&&performance.now?performance.now():Date.now();var Un=4,tn="Save cancelled: the page changed while it prepared",X=null,le=null,Qe=null,mn=!1;function vn(){return Qe||(Qe=import("./c-DYTBSJBI.js").then(e=>(le=e,e),e=>(mn=!0,console.info("clayjs: sliced save off ("+(e&&e.message?e.message:e)+"); saves prepare in one task"),null))),Qe}function qn(){try{return performance.getEntriesByType("navigation")[0]?.decodedBodySize||0}catch{return 0}}var Bn=()=>typeof xe=="string"?xe.length:qn();function Pe(){return mn||document.hidden||Bt()?!1:Bn()>=307200}function nn(e,t,n){return n?"morph":b!==t.generation||!A?"mode":de(e.permit)?ft()?"refused":ie!==t.baselines?"newer save":Math.max(He(),e.blockeditorFormatFloor)>t.floor?"floor":null:"session"}function Hn(e=150,t=2e3){return new Promise(n=>{let o=G(),r=null,i=()=>{document.removeEventListener("clay:sync-applied",a),n()},a=()=>{clearTimeout(r),r=setTimeout(i,Math.max(0,Math.min(e,t-(G()-o))))};document.addEventListener("clay:sync-applied",a),a()})}async function pt({explicit:e,forced:t=!1,forSave:n,forComparison:o,forDirty:r,captureId:i,gateToken:a,costMs:f,blockeditorFormatFloor:u=0,quietConflict:m=!1,laneHeld:c=!1,lane:p=null,capture:S,noteRecovery:y,release:d,callback:g}){if(y(),e&&!t){if(q=r!==C,he("savePage dirty check",!q),!q){Q(),N(a),d();let s=h("No changes to save");return z(i,s),typeof g=="function"&&g(s),{result:s,dispatched:!1}}}else if(!e){let s=!ee||o!==W,v=o!==L;if(he("throttled vs baseline",!s),he("throttled vs lastSave",!v),!(s&&v)){let M=!1;try{M=!v&&(!document.querySelector(_t)||$()&&r===C)}catch(yt){console.error("savePageThrottled: dirty domain check failed",yt)}M&&N(a),nt.noteCost(f),d();let E=h("No changes to save");return z(i,E),typeof g=="function"&&g(E),{result:E,dispatched:!1}}if(q=!0,!c&&P()){D=!0,d();let M=h("Save already in progress");return z(i,M),typeof g=="function"&&g(M),{result:M,dispatched:!1}}}xn();let l={forComparison:o,forDirty:r};return we.add(l),Ae=!0,new Promise(s=>{Gt(n,i,v=>{Ae=!1,we.delete(l);let M=G();Fn(v,l.forComparison,l.forDirty,t?"updated after force save":"updated after save",a,n,i,m),e||nt.noteCost(f+(G()-M)),typeof g=="function"&&g(v),s({result:v,dispatched:!0}),c||pn()},{capture:S,blockeditorFormatFloor:u,lane:p,gateToken:a})})}async function Gn(e,t){let n={over:!1},o=()=>{n.over=!0};document.addEventListener("clay:sync-applied",o);try{for(let i=0;i<2;i++){let a=R(),f={generation:b,baselines:ie,floor:Math.max(He(),e.blockeditorFormatFloor)},u=le.beginSaveCapture({requestRefresh:!0,forRequest:!0,pageFormatMarker:f.floor?{name:Nt,content:String(f.floor)}:null});Yt(u.captureId);let m=null,c={get aborted(){let d=nn(e,f,n.over);return d&&(m=d),!!d}},p;try{p=await le.runPreparedSteps(u.steps(),{budgetMs:Un,signal:c})}catch(d){console.error(`${e.explicit?"savePage":"savePageThrottled"}: preparing the save failed`,d),u.drop();let g={msg:d&&d.message?d.message:"Save failed",msgType:"error",code:d?.code??null,etag:null};return w("error",g.msg,"",{sent:!1,code:g.code}),z(u.captureId,g),typeof e.callback=="function"&&e.callback(g),{result:g,dispatched:!1}}let S=p.aborted?m:nn(e,f,n.over);if(!S){let d=p.result;return await pt({explicit:e.explicit,forced:e.forced,forSave:d.forSave,forComparison:d.forComparison,forDirty:d.forDirty,captureId:d.captureId,gateToken:a,costMs:p.activeMs,blockeditorFormatFloor:e.blockeditorFormatFloor,quietConflict:e.quietConflict,laneHeld:!0,lane:t,capture:d,noteRecovery:()=>jt(d.captureId,d.forSave),release:()=>u.drop(),callback:e.callback})}u.drop();let y=h(tn);if(S==="session"&&(ae=!0),z(u.captureId,y),!(S==="floor"&&i===0)){if(S==="morph"&&e.explicit&&i===0){await Hn(),n.over=!1;continue}return typeof e.callback=="function"&&e.callback(y),{result:y,dispatched:!1}}}let r=h(tn);return typeof e.callback=="function"&&e.callback(r),{result:r,dispatched:!1}}finally{document.removeEventListener("clay:sync-applied",o),qt(t)}}function gn(e){let t=Ut();if(!t)return!1;let n=Gn(e,t).catch(o=>{console.error("save: preparing the save failed",o);let r={msg:o&&o.message?o.message:"Save failed",msgType:"error",code:o?.code??null,etag:null};return w("error",r.msg,"",{sent:!1,code:r.code}),typeof e.callback=="function"&&e.callback(r),{result:r,dispatched:!1}});return X=n,n.then(o=>{X===n&&(X=null),e.resolve(o.result),e.settleSoonQueued(o.result),(o.dispatched||D||k||ke.length)&&pn()}),!0}function Le(e,t=()=>{}){return Ce?it.then(()=>Le(e,t)):te?ce.then(()=>De(e,t)):De(e,t)}function _e(e,t){let n=!1,o=setTimeout(()=>{n=!0,w("saving")},500);return e.then(()=>(clearTimeout(o),t())).then(r=>(n&&!P()&&!$()&&document.documentElement.getAttribute("savestatus")==="saving"&&(document.documentElement.setAttribute("savestatus","saved"),document.dispatchEvent(new CustomEvent("clay:save-status",{detail:{state:"saved"}}))),r))}function De({kind:e,permit:t=null},n=()=>{}){let o=e==="explicit";return new Promise(r=>{if(!A&&!window.clay?.testMode){o&&Q();let s=h("Not in edit mode");return T().forEach(v=>v(s)),n(s),r(s)}if(!de(t)){ae=!0;let s=lt("Save session is quiesced");return o&&T().forEach(v=>v(s)),n(s),r(s)}if(ft()){o&&Q();let s=cn();return w("error",s.msg,"",{code:s.code,status:s.status,sent:!1}),T().forEach(v=>v(s)),n(s),r(s)}if(o){let s=fn(n,r);if(s){T().forEach(v=>v(s));return}if(P()){D=!0;let v=h("Save already in progress");return n(v),r(v)}}else{if(O>0){Me=!0;let s=h(ut());return n(s),r(s)}if(P()&&!ee&&Ae){k=!0;let s=h("Save already in progress");return n(s),r(s)}if(X){k=!0;let s=h("Save already in progress");return n(s),r(s)}if(!ee&&!$()){let s=h("No changes to save");return n(s),r(s)}}let i=window.clay?.source?.ensureForSave?.();if(i)return r(_e(i,()=>De({kind:e,permit:t},n)));if(Pe()&&!le){r(_e(vn(),()=>De({kind:e,permit:t},n)));return}let a=o?T():[],f=s=>a.forEach(v=>v(s));if(!navigator.onLine&&ot(),Pe()&&gn({explicit:o,forced:!1,permit:t,blockeditorFormatFloor:0,quietConflict:!1,settleSoonQueued:f,callback:n,resolve:r}))return;let m=G(),c,p,S,y,d,g=R();try{c=Ue({requestRefresh:!0,forRequest:!0}),{forSave:p,forComparison:S,forDirty:y,captureId:d}=c}catch(s){console.error(`${o?"savePage":"savePageThrottled"}: captureForSaveAndComparison failed`,s),o?(Q(),w("error",s.message,"error",{sent:!1,code:s.code??null})):w("error",s.message,"error");let v={ok:!1,msg:s.message,msgType:"error",code:o?s.code??null:null,etag:null};typeof n=="function"&&n(v),r(v),f(v);return}let l=G()-m;pt({explicit:o,forSave:p,forComparison:S,forDirty:y,captureId:d,gateToken:g,costMs:l,capture:c,noteRecovery:()=>Ke({captureId:d,html:p}),release:()=>Ne(c),callback:n}).then(s=>{r(s.result),f(s.result)})})}function I(e=()=>{}){return Le({kind:"explicit"},e)}function Wn(e,t=()=>{}){return Le({kind:"explicit",permit:e},t)}function J(e=()=>{},{quietConflict:t=!1,blockeditorFormatFloor:n=0,permit:o=null}={}){return Ce?it.then(()=>J(e,{quietConflict:t,blockeditorFormatFloor:n,permit:o})):new Promise(r=>{if(!A&&!window.clay?.testMode){let l=h("Not in edit mode");return T().forEach(s=>s(l)),e(l),r(l)}if(!de(o)||o&&!dn(o)){let l=lt("Save session is quiesced");return T().forEach(s=>s(l)),e(l),r(l)}if(ft()){let l=cn();return w("error",l.msg,"",{code:l.code,status:l.status,sent:!1}),T().forEach(s=>s(l)),e(l),r(l)}let i=fn(e,r);if(i){T().forEach(l=>l(i));return}if(P()){D=!0;let l=h("Save already in progress");return T().forEach(s=>s(l)),e(l),r(l)}let a=window.clay?.source?.ensureForSave?.();if(a)return r(_e(a,()=>J(e,{quietConflict:t,blockeditorFormatFloor:n,permit:o})));if(!navigator.onLine&&ot(),Pe()&&!le){r(_e(vn(),()=>J(e,{quietConflict:t,blockeditorFormatFloor:n,permit:o})));return}let u=T(),m=l=>u.forEach(s=>s(l));if(Pe()&&gn({explicit:!0,forced:!0,permit:o,blockeditorFormatFloor:n,quietConflict:t,settleSoonQueued:m,callback:e,resolve:r}))return;let c,p,S,y,d,g=R();try{c=Ue({requestRefresh:!0,forRequest:!0}),{forSave:p,forComparison:S,forDirty:y,captureId:d}=c}catch(l){console.error("savePageForce: captureForSaveAndComparison failed",l),w("error",l.message,"error",{sent:!1,code:l.code??null});let s={ok:!1,msg:l.message,msgType:"error",code:l.code??null,etag:null};typeof e=="function"&&e(s),r(s),m(s);return}pt({explicit:!0,forced:!0,forSave:p,forComparison:S,forDirty:y,captureId:d,gateToken:g,costMs:0,blockeditorFormatFloor:n,quietConflict:t,capture:c,noteRecovery:()=>Ke({captureId:d,html:p}),release:()=>Ne(c),callback:e}).then(l=>{r(l.result),m(l.result)})})}Kt(e=>J(()=>{},{permit:e}));function Kn(e){let t=["clay:save-saved","clay:save-error","clay:save-offline","clay:save-conflict"];return new Promise((n,o)=>{let r=null,i=()=>{clearTimeout(r);for(let u of t)document.removeEventListener(u,a)},a=()=>{i(),n()},f=e-Date.now();if(f<=0){o(Object.assign(new Error("Save timed out."),{state:"failed"}));return}r=setTimeout(()=>{i(),o(Object.assign(new Error("Save timed out."),{state:"failed"}))},f);for(let u of t)document.addEventListener(u,a)})}function _(e,t){return Object.assign(new Error(e),{state:t})}function Qn(e,t){return new Promise((n,o)=>{let r=t-Date.now();if(r<=0)return o(_("Save timed out.","failed"));let i=setTimeout(()=>{document.removeEventListener(e,a),o(_("Save timed out.","failed"))},r),a=()=>{clearTimeout(i),n()};document.addEventListener(e,a,{once:!0})})}async function to({keepalive:e=!1,timeoutMs:t=15e3,permit:n=null}={}){if(!A)return{state:"view",etag:null};let o=Date.now()+t,r=n||Rn(),i={over:!1},a=null,f=new Promise((u,m)=>{a=setTimeout(()=>m(Object.assign(_("Save timed out.","failed"),{timedOut:!0})),Math.max(0,t))});try{return await Promise.race([Vn(e,o,r,i),f])}catch(u){throw u&&typeof u.state=="string"?u:_(u?.message||"Save failed","failed")}finally{i.over=!0,clearTimeout(a),n||Nn(r)}}async function Vn(e,t,n,o={over:!1}){if(hn()||await Qn("clay:baseline-settled",t),o.over)return null;let r=!1,i=null;for(let a=0;a<4;a++){if(X&&(await X,o.over)||P()&&(await Kn(t),o.over))return null;if(Ze())throw _("This document has a conflict to resolve.","conflict");let f=R();if(!rt()){if(N(f),F())throw _("This document has unsaved work a save cannot write.","blocked");return ne=!1,{state:r?"saved":"clean",etag:i??qe()}}if(o.over)return null;let u=await Ft(e,()=>Wn(n));if(u.msgType!=="skipped"){if(!u.ok)throw _(u.msg||"Save failed",u.msgType==="conflict"||Ze()?"conflict":"failed");r=!0,i=u.etag??null}}throw _("The document kept changing while saving.","failed")}async function no(e=()=>{}){return await Be({fresh:!0}),J(e)}function ro(e){!A||K||Wt(e,t=>{t.ok?window.location.reload():t.msgType==="skipped"?w("error",t.msg||"Template not saved"):w("error",t.msg||"Failed to save template")})}var $n=Ot(e=>Le({kind:"automatic"},e),1200),Yn=250,jn=1e3,Z=null,rn=0,et=[],ke=[],fe=!1,T=()=>{let e=ke;return ke=[],e};function mt(){if(Z=null,B>0||!de()){fe=!0;return}let e=et;if(et=[],P()){ke.push(...e),I();return}I().then(t=>e.forEach(n=>n(t)))}function oo(){let e=Date.now();return Z===null?rn=e:clearTimeout(Z),new Promise(t=>{et.push(t),Z=setTimeout(mt,Math.max(0,Math.min(Yn,rn+jn-e)))})}function zn(){ae&&(ae=!1,Oe())}function on(){fe&&(fe=!1,Z=setTimeout(mt,0))}var W="",ee=!0,vt=!1;function hn(){return vt}var Ve=!1,Xn=250,Jn=1250,$e=null,Sn="clay:paint-heal:"+location.pathname;function yn(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t+e.charCodeAt(n)|0;return String(t>>>0)}function Zn(e){try{return localStorage.getItem(Sn)===yn(e)}catch{return!1}}function er(e){try{localStorage.setItem(Sn,yn(e))}catch{}}function tr(){return Dt(Lt({flushUndo:!1}))}function so(e){!A||K||(clearTimeout($e),$e=setTimeout(async()=>{$e=null,te&&await ce;let t=typeof e=="function"?e():e;t==null||!We()||!hn()||Ze()||_n()||V({flushUndo:!1})===C&&t!==tr()&&(Zn(t)||(er(t),J(()=>{},{quietConflict:!0})))},Xn+Math.random()*Jn))}var Se=null,Ye=null,te=0,ce=Promise.resolve(),gt=!1,ht=[];function nr(){return Ye??=import("./c-KNPDOMDY.js").catch(e=>(Ye=null,console.error("style-comparisons failed to load",e),null)),Ye}async function rr(e){try{if(Se||(Se=(await nr())?.styleComparisonStripper??null),!Se)return;let t=Se(e);L=t(L),C=t(C),W=t(W);for(let n of we)n.forComparison=t(n.forComparison),n.forDirty=t(n.forDirty)}catch(t){console.error("style adoption failed",t)}finally{te--,ht.shift()}}var ye=e=>e.replace(/&/g,"&amp;").replace(/"/g,"&quot;");function or(e){if(e.name!==void 0){let n=[`data-name="${ye(e.name)}"`];return e.legacyId!==void 0&&n.push(`id="${ye(e.legacyId)}"`),n}let t=[ye(e.href)];try{let{pathname:n}=new URL(e.href);n&&t.push(ye(n))}catch{}return t}function sr(e){let t=[L,C,W];for(let n of we)t.push(n.forComparison,n.forDirty);return t.some(n=>n&&e.some(o=>o&&n.includes(o)))}function ir(e,t){let n=[];for(let{markers:i,tag:a}of t)for(let f of i)for(let u=e.indexOf(f);u>=0;u=e.indexOf(f,u+f.length)){let m=e.lastIndexOf("<",u);if(m<0||e.slice(m+1,m+1+a.length).toLowerCase()!==a)continue;let c=a==="style"?e.indexOf("</style",u):u;if(c<0)continue;let p=e.indexOf(">",c);p>=0&&n.push([m,p+1])}n.sort((i,a)=>i[0]-a[0]);let o="",r=0;for(let[i,a]of n)i<r||(o+=e.slice(r,i),r=a);return o+e.slice(r)}$t(e=>{let t=or(e);sr(t)&&(te||(gt=!1),te++,ht.push({markers:t,tag:e.name!==void 0?"style":"link"}),ce=ce.then(()=>rr(e)))});function io(){return ce}function St(e){return!te||gt||F()||P()||D||k||ne||typeof e!="string"?!1:e===ir(C,ht)}var ar=500,ur=3e3,lr=1e4,tt=null;function fr(){pe.holdSettle=!1,tt&&tt()}function sn(){if(!A)return;let e=!1,t=null,{forComparison:n,forDirty:o}=me();ue(n,o);let r=ie;W=n,re("immediate capture",`${n.length} chars`);let i=["keydown","pointerdown","drop","input","change","paste"],a=new Set(["Shift","Control","Alt","Meta"]),f=c=>{c.type==="keydown"&&a.has(c.key)||(gt=!0,e||(Ve=!0))};i.forEach(c=>document.addEventListener(c,f,!0));let u=()=>{if(!e){if(e=!0,t&&t(),!Ve&&ie===r){let c=R(),{forComparison:p,forDirty:S}=me();ue(p,S),W=p,N(c),re("settled capture",`${p.length} chars`)}else re("settled skipped",Ve?"user edited":"save occurred during settle");ee=!1,document.documentElement.setAttribute("savestatus","saved"),vt=!0,document.dispatchEvent(new CustomEvent("clay:baseline-settled"))}};tt=u;let m=()=>{pe.holdSettle||u()};t=kt.onAnyChange({debounce:ar,omitChangeDetails:!0,require:"autosave"},m),setTimeout(()=>{e||m()},ur),setTimeout(()=>{!e&&pe.holdSettle&&fr()},lr)}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",sn):sn();function Oe(e=()=>{}){if(!A){let t=h("Not in edit mode");return e(t),Promise.resolve(t)}if(O>0){Me=!0;let t=h(ut());return e(t),Promise.resolve(t)}if(!de()){ae=!0;let t=lt("Save session is quiesced");return e(t),Promise.resolve(t)}if(B>0){je=!0;let t=h("Autosave suspended");return e(t),Promise.resolve(t)}if(!ee&&Ae){k=!0;let t=h("Save already in progress");return e(t),Promise.resolve(t)}return $n(e).catch(t=>{let n={ok:!1,msg:t?.message||"Save failed",msgType:"error",code:null,etag:null};return w("error",n.msg),n})}var nt=Zt({now:G,run:()=>Oe()});function En(){document.addEventListener("keydown",function(e){if((window.navigator.platform.match("Mac")?e.metaKey:e.ctrlKey)&&e.keyCode==83){if(!A)return;e.preventDefault(),e.isTrusted&&Re(),I()}})}function wn(){document.addEventListener("click",e=>{e.target.closest("[trigger-save]")&&(e.isTrusted&&Re(),I())})}function cr(){A&&(Be(),Rt(),be(),En(),wn())}cr();var ao=I;var Ie=!1;function go({isCurrent:e,reload:t}){return e()?(Ie=!0,setTimeout(()=>{Ie=!1},1e3),t(),!0):!1}Jt();function dr(){return st()?!0:A?F()?!0:K?Mt()||xt():window.clay?.demo?!1:rt():!1}function rt(){if(!A)return!1;try{let e=V();return St(e)?!1:e!==dt()}catch{return!0}}window.addEventListener("beforeunload",e=>{if(!A&&!st())return;if(Ie){Ie=!1;return}if(!((!K||Ct())&&!dr())&&(e.preventDefault(),e.returnValue="",!window.clay?.demo&&!F()))try{let n=V(),o=dt();n!==o&&Xt(n,o)}catch{}});export{go as a,dr as b,rt as c,Br as d,Pn as e,ln as f,_n as g,de as h,st as i,kn as j,Hr as k,Gr as l,Wr as m,Kr as n,Qr as o,Vr as p,ut as q,Ze as r,$r as s,Yr as t,jr as u,Rn as v,Nn as w,zr as x,Xr as y,Jr as z,dt as A,Zr as B,ue as C,eo as D,I as E,J as F,to as G,no as H,ro as I,oo as J,hn as K,tr as L,so as M,io as N,St as O,fr as P,Oe as Q,nt as R,En as S,wn as T,cr as U,ao as V};
@@ -1,4 +1,4 @@
1
- import{b as x}from"./c-QY7F6EN6.js";import{a as w}from"./c-EAV7A6BT.js";import"./c-I2SCCUEW.js";import"./c-EQ5NBOGA.js";import"./c-C7SUMNMI.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-U4TWEIKZ.js";import"./c-HA6INT6J.js";import"./c-ICMAOOGK.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var S=`.clay-upload {
1
+ import{b as x}from"./c-QY7F6EN6.js";import{a as w}from"./c-MB5FZ2PD.js";import"./c-I2SCCUEW.js";import"./c-26W3BMWK.js";import"./c-JEWSJHMK.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-U4TWEIKZ.js";import"./c-HA6INT6J.js";import"./c-ICMAOOGK.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var S=`.clay-upload {
2
2
  display: flex;
3
3
  flex-wrap: wrap;
4
4
  align-items: center;
@@ -0,0 +1 @@
1
+ import{b as k,d as l,e as r}from"./c-BPF2NSPV.js";import{a as M}from"./c-P7KNDG34.js";import{a as S}from"./c-CYWLPPUS.js";import{e as b}from"./c-U4TWEIKZ.js";var A=Object.fromEntries(new URLSearchParams(window.location.search)),n=A;var w=()=>S("mode-receipt"),R=3e4;function T(){try{return performance.getEntriesByType("navigation")[0]?.type??null}catch{return null}}function P(){let e=null;try{e=sessionStorage.getItem(w()),sessionStorage.removeItem(w())}catch{return null}if(!e)return null;let t;try{t=JSON.parse(e)}catch{return null}if(t?.v!==1||t.path!==location.pathname||t.mode!=="edit"&&t.mode!=="view")return null;let i=T();return i!=="back_forward"&&Date.now()-t.at>R||!t.internal&&i!=="reload"&&i!=="back_forward"?null:t}function J({mode:e,canEdit:t,internal:i}){try{sessionStorage.setItem(w(),JSON.stringify({v:1,path:location.pathname,mode:e,canEdit:t,at:Date.now(),internal:i}))}catch{}}var o=null;typeof window<"u"&&(window.clayEditMode!=null?o=!!window.clayEditMode:window.__hyperclayEditMode!=null&&(o=!!window.__hyperclayEditMode));var d=typeof document<"u"&&document.documentElement.hasAttribute("viewonly"),B=typeof document<"u"&&b(),p=!!M.get("isAdminOfCurrentResource"),g=n.editmode==="document",y=B&&n.editmode!=="false"&&!((n.editmode==="true"||g)&&p)&&!d&&!r()&&o==null&&!l(),u=typeof window<"u"?P():null,_=typeof document<"u"&&document.documentElement.getAttribute("opens-in")==="edit",D=g?!d&&!r()&&o!==!1:n.editmode?n.editmode==="true"||!d&&!r()&&(o??(l()||p)):d||r()?!1:o??(l()||p),V=u?.canEdit===!0&&o!==!1&&!r()&&!(d&&n.editmode!=="true"),h=D||V,q=y||r()||o===!1||n.editmode==="false"||d&&n.editmode!=="true",m=h,C=null;function z(e){C=typeof e=="boolean"?e:null;let t=e===!1?!1:e===!0?h||!q:h;t!==m&&(m=t,typeof document<"u"&&document.dispatchEvent(new Event("clay:capabilitychange")))}function Q(){return C}var F=u?u.mode==="edit"||_&&!u.internal:n.editmode&&!g?n.editmode==="true":o===!0||_,a=y?!0:m&&F,I=y?"draft":a?"edit":"view",Y=p,s={phase:"idle",destination:y?"draft":"host",generation:0,reason:null};function Z(e){e.mode!==void 0&&(I=e.mode),e.isEditMode!==void 0&&(a=e.isEditMode,typeof window<"u"&&(window.__hyperclayEditMode=a)),e.canEdit!==void 0&&(m=e.canEdit);for(let t in s)e[t]!==void 0&&(s[t]=e[t])}var U=()=>({mode:I,...s});function ee(){return a&&U().phase==="idle"}var c=typeof window>"u"||!window.clay?[]:(window.clay.modeParticipants||Object.defineProperty(window.clay,"modeParticipants",{value:[],writable:!0,configurable:!0}),window.clay.modeParticipants),f=new Set,O=()=>{},te=e=>O=e,ne=()=>c.slice(),E=e=>{throw new TypeError(`clay.modeLifecycle: ${e}`)},W=()=>{(s.phase!=="idle"||a)&&E("the page is not idle in view")},x=()=>{s.phase==="blocked"&&!a||W()};function oe(){return f.clear(),c.splice(0)}function ie(e){let t=e&&e.id;(typeof t!="string"||!t||typeof e.prepare!="function")&&E("a participant needs an id and a prepare()"),f.has(t)&&E(`duplicate participant id "${t}"`),x(),f.add(t),c.push(e);let i=!0;return()=>{if(!i)return;x(),i=!1,f.delete(t);let v=c.indexOf(e);v!==-1&&c.splice(v,1),O(t)}}var re=k;export{J as a,y as b,m as c,z as d,Q as e,a as f,I as g,Y as h,Z as i,U as j,ee as k,te as l,ne as m,oe as n,ie as o,re as p};
@@ -1 +1 @@
1
- import{a as d}from"./c-Y3J5LDKB.js";import"./c-PZ4XEPUP.js";import"./c-SFKI6OLM.js";import"./c-Q3XOWZEV.js";import"./c-RHMPKZZ7.js";import{c as m,h as v,j as x,m as s}from"./c-J2ZW4HMR.js";import"./c-A5LASUEZ.js";import{a as p}from"./c-4JZDZFF6.js";import{e as f}from"./c-5RZNFTWD.js";import{b as w}from"./c-PKCCHJ5X.js";import{b as c}from"./c-NUHP2XDB.js";import{f as l}from"./c-C7SUMNMI.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-U4TWEIKZ.js";import"./c-UW6MMZ4V.js";import"./c-XQXZAO7N.js";import"./c-S7LK4KUE.js";import"./c-MOP5KBWZ.js";import"./c-2YYDMLNZ.js";import"./c-HA6INT6J.js";import"./c-ICMAOOGK.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var $="Download a copy, then reduce its size; saving still works.",b="Download a copy to keep your work.",t=null,r=null,i=null,a=null;function h(e){return typeof e!="number"||!Number.isFinite(e)||e<0?"an unknown size":e>=1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:e>=1024?`${Math.max(1,Math.round(e/1024))} KB`:`${e} bytes`}function y({bytes:e,maxBytes:n,state:S}){let u=`At the last save attempt: ${h(e)} of ${h(n)}.`;return S==="over"?`This host can't save a file this size. ${u} ${b}`:`This file is getting large. ${u} ${$}`}function o(){if(!t)return;let e=window.visualViewport,n=e?Math.max(0,window.innerHeight-e.height-e.offsetTop):0;c(t,"bottom",`calc(${16+n}px + env(safe-area-inset-bottom,0px))`)}async function z(){await d({})}function A(){t=v("div",["position:fixed","left:50%","transform:translateX(-50%)","z-index:2147483000","display:flex","align-items:center","gap:10px 12px","width:max-content","max-width:calc(100vw - 24px)","flex-wrap:wrap","padding:8px 8px 8px 14px","text-align:left",`color-scheme:${p()}`]),t.setAttribute("clay","editor-ui"),t.setAttribute("data-clay-save-size",""),t.setAttribute("role","status"),r=x("span",[],""),i=m("Download my copy",{small:!0,onClick:z}),s(i,!1,"inline-flex"),t.append(r,i),document.body.appendChild(t),o(),window.visualViewport?.addEventListener("resize",o),window.visualViewport?.addEventListener("scroll",o)}function M(e){t||A(),r.textContent=y(e),s(i,e.state==="over","inline-flex"),o(),w(t,{background:f.surface})}function E(){t&&(window.visualViewport?.removeEventListener("resize",o),window.visualViewport?.removeEventListener("scroll",o),t.remove(),t=null,r=null,i=null)}function g(e){let n=e?.detail;n&&(n.state==="near"||n.state==="over"?M(n):E())}function k(){l||L()}function N(e){l&&(a||=new AbortController,document.addEventListener("clay:save-size",g,{signal:a.signal}),document.addEventListener("clay:modechange",k,{signal:a.signal}),e?.type==="clay:save-size"&&g(e))}function L(){a?.abort(),a=null,E()}export{N as start,L as stop};
1
+ import{a as d}from"./c-Y3J5LDKB.js";import"./c-PZ4XEPUP.js";import"./c-SFKI6OLM.js";import"./c-Q3XOWZEV.js";import"./c-RHMPKZZ7.js";import{c as m,h as v,j as x,m as s}from"./c-J2ZW4HMR.js";import"./c-A5LASUEZ.js";import{a as p}from"./c-4JZDZFF6.js";import{e as f}from"./c-5RZNFTWD.js";import{b as w}from"./c-PKCCHJ5X.js";import{b as c}from"./c-NUHP2XDB.js";import{f as l}from"./c-JEWSJHMK.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-U4TWEIKZ.js";import"./c-UW6MMZ4V.js";import"./c-XQXZAO7N.js";import"./c-S7LK4KUE.js";import"./c-MOP5KBWZ.js";import"./c-2YYDMLNZ.js";import"./c-HA6INT6J.js";import"./c-ICMAOOGK.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var $="Download a copy, then reduce its size; saving still works.",b="Download a copy to keep your work.",t=null,r=null,i=null,a=null;function h(e){return typeof e!="number"||!Number.isFinite(e)||e<0?"an unknown size":e>=1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:e>=1024?`${Math.max(1,Math.round(e/1024))} KB`:`${e} bytes`}function y({bytes:e,maxBytes:n,state:S}){let u=`At the last save attempt: ${h(e)} of ${h(n)}.`;return S==="over"?`This host can't save a file this size. ${u} ${b}`:`This file is getting large. ${u} ${$}`}function o(){if(!t)return;let e=window.visualViewport,n=e?Math.max(0,window.innerHeight-e.height-e.offsetTop):0;c(t,"bottom",`calc(${16+n}px + env(safe-area-inset-bottom,0px))`)}async function z(){await d({})}function A(){t=v("div",["position:fixed","left:50%","transform:translateX(-50%)","z-index:2147483000","display:flex","align-items:center","gap:10px 12px","width:max-content","max-width:calc(100vw - 24px)","flex-wrap:wrap","padding:8px 8px 8px 14px","text-align:left",`color-scheme:${p()}`]),t.setAttribute("clay","editor-ui"),t.setAttribute("data-clay-save-size",""),t.setAttribute("role","status"),r=x("span",[],""),i=m("Download my copy",{small:!0,onClick:z}),s(i,!1,"inline-flex"),t.append(r,i),document.body.appendChild(t),o(),window.visualViewport?.addEventListener("resize",o),window.visualViewport?.addEventListener("scroll",o)}function M(e){t||A(),r.textContent=y(e),s(i,e.state==="over","inline-flex"),o(),w(t,{background:f.surface})}function E(){t&&(window.visualViewport?.removeEventListener("resize",o),window.visualViewport?.removeEventListener("scroll",o),t.remove(),t=null,r=null,i=null)}function g(e){let n=e?.detail;n&&(n.state==="near"||n.state==="over"?M(n):E())}function k(){l||L()}function N(e){l&&(a||=new AbortController,document.addEventListener("clay:save-size",g,{signal:a.signal}),document.addEventListener("clay:modechange",k,{signal:a.signal}),e?.type==="clay:save-size"&&g(e))}function L(){a?.abort(),a=null,E()}export{N as start,L as stop};
@@ -1 +1 @@
1
- import"./c-7WZSUTYP.js";import{b as s,d as n,f as l,h as m}from"./c-PGSBXHUE.js";import{f as i}from"./c-EQ5NBOGA.js";import"./c-C7SUMNMI.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-U4TWEIKZ.js";import"./c-HA6INT6J.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var p="blockeditor-format-activation-failed";function u(){let e=document.querySelector(`meta[name="${s}"]`);return e?l(e.outerHTML):0}var F=async e=>(await import("./core/save-JZ7R4ET2.js")).savePageForce(()=>{},e),P=4,f=1e4,w=e=>e?.ok===!1&&e?.msgType==="skipped"&&/in progress/i.test(e?.msg??""),A=async()=>{let{isSaveInProgress:e}=await import("./core/save-core-I4N6S4ED.js"),a=Date.now()+f;for(;e()&&Date.now()<a;)await new Promise(c=>setTimeout(c,50))};function k({save:e=F,settles:a=A,supported:c=()=>i().then(o=>o===1)}={}){return{read(){return{floor:Math.max(m(),u()),revision:null}},capabilities(){return[]},supported:c,async activate({floor:o=1}={}){let t;try{t=await e({blockeditorFormatFloor:o});for(let r=1;r<P&&w(t);r+=1)await a(),t=await e({blockeditorFormatFloor:o})}catch(r){return{accepted:!1,code:r?.code??p}}return t?.ok?{accepted:!0,revision:null,receipt:t.receipt??t.etag??null}:t?.code===n?{accepted:!1,code:n}:{accepted:!1,code:t?.code??p}}}}export{k as createFormatHost};
1
+ import"./c-7WZSUTYP.js";import{b as s,d as n,f as l,h as m}from"./c-PGSBXHUE.js";import{f as i}from"./c-26W3BMWK.js";import"./c-JEWSJHMK.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-U4TWEIKZ.js";import"./c-HA6INT6J.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var p="blockeditor-format-activation-failed";function u(){let e=document.querySelector(`meta[name="${s}"]`);return e?l(e.outerHTML):0}var F=async e=>(await import("./core/save-KY3ZMPU4.js")).savePageForce(()=>{},e),P=4,f=1e4,w=e=>e?.ok===!1&&e?.msgType==="skipped"&&/in progress/i.test(e?.msg??""),A=async()=>{let{isSaveInProgress:e}=await import("./core/save-core-LBW6DNJ6.js"),a=Date.now()+f;for(;e()&&Date.now()<a;)await new Promise(c=>setTimeout(c,50))};function k({save:e=F,settles:a=A,supported:c=()=>i().then(o=>o===1)}={}){return{read(){return{floor:Math.max(m(),u()),revision:null}},capabilities(){return[]},supported:c,async activate({floor:o=1}={}){let t;try{t=await e({blockeditorFormatFloor:o});for(let r=1;r<P&&w(t);r+=1)await a(),t=await e({blockeditorFormatFloor:o})}catch(r){return{accepted:!1,code:r?.code??p}}return t?.ok?{accepted:!0,revision:null,receipt:t.receipt??t.etag??null}:t?.code===n?{accepted:!1,code:n}:{accepted:!1,code:t?.code??p}}}}export{k as createFormatHost};