@panphora/clayjs 1.24.0 → 1.24.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) 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 +15016 -13603
  11. package/dist/m/c-277QP5ET.js +1 -0
  12. package/dist/m/{c-BULK5J4M.js → c-3UW5EJ77.js} +1 -1
  13. package/dist/m/{c-GM7OA6EJ.js → c-42ZNV7LI.js} +1 -1
  14. package/dist/m/{c-RXTPKCMC.js → c-6IJEVE6B.js} +1 -1
  15. package/dist/m/{c-2R4OBWIP.js → c-6LEYVQJK.js} +1 -1
  16. package/dist/m/{c-LO4C4J77.js → c-6Q6RGFBF.js} +1 -1
  17. package/dist/m/{c-PD5AKHY3.js → c-7CM4GMTS.js} +1 -1
  18. package/dist/m/c-APGHGDZM.js +1 -0
  19. package/dist/m/{c-Q6VNQDJE.js → c-B7GOFGQR.js} +1 -1
  20. package/dist/m/{c-RJKKRWHW.js → c-BGN7RCTJ.js} +1 -1
  21. package/dist/m/{c-A7N5TNSL.js → c-C5AKJVRH.js} +1 -1
  22. package/dist/m/{c-SNVDWMM3.js → c-CJ7QYEWI.js} +1 -1
  23. package/dist/m/{c-PVJMJL3P.js → c-CZHTXGJS.js} +1 -1
  24. package/dist/m/{c-KJHVB2KG.js → c-DDS23EY6.js} +1 -1
  25. package/dist/m/{c-VSEUFJAO.js → c-DFKBGSN2.js} +1 -1
  26. package/dist/m/{c-DLBX4JCJ.js → c-EDE45NM7.js} +1 -1
  27. package/dist/m/c-EILLN2H2.js +1 -0
  28. package/dist/m/{c-EY5KDUZF.js → c-FEC6LGFF.js} +1 -1
  29. package/dist/m/{c-PMRRMT72.js → c-HDVH3MVC.js} +1 -1
  30. package/dist/m/c-HKSLOVU4.js +1 -0
  31. package/dist/m/{c-GNIVHLEJ.js → c-HL6BLJNA.js} +1 -1
  32. package/dist/m/c-HTLYXCUH.js +1 -0
  33. package/dist/m/{c-RTSRGGTP.js → c-JQF2EUCG.js} +1 -1
  34. package/dist/m/{c-O5ARALMJ.js → c-JWDCQL6J.js} +1 -1
  35. package/dist/m/{c-WOELSNWS.js → c-LATNQ6Q5.js} +1 -1
  36. package/dist/m/{c-UM7VZDTW.js → c-LSVN3OLG.js} +1 -1
  37. package/dist/m/{c-HSNGLIFB.js → c-MFOSMAVM.js} +2 -2
  38. package/dist/m/{c-FZRZPIFS.js → c-MQYEDF3Q.js} +1 -1
  39. package/dist/m/{c-2OIKXOY6.js → c-ND3Q2G2I.js} +1 -1
  40. package/dist/m/{c-PZRWZZRO.js → c-OCYG4NBQ.js} +1 -1
  41. package/dist/m/{c-54ZZZYUN.js → c-P2HKMJAW.js} +1 -1
  42. package/dist/m/{c-VI3BJHCM.js → c-PCNJETUA.js} +1 -1
  43. package/dist/m/{c-7YETSAVY.js → c-PDBNCJCT.js} +1 -1
  44. package/dist/m/{c-A5ZBFICF.js → c-PYG2NGWU.js} +1 -1
  45. package/dist/m/{c-RBPZNU2D.js → c-QQFHEODI.js} +1 -1
  46. package/dist/m/{c-YINHPF4V.js → c-SGH3UTF3.js} +1 -1
  47. package/dist/m/{c-FV46ZKGX.js → c-SKMIR5HQ.js} +1 -1
  48. package/dist/m/{c-TWOXQQKV.js → c-STRI73GQ.js} +1 -1
  49. package/dist/m/{c-75N3KG35.js → c-T3P3AXEW.js} +1 -1
  50. package/dist/m/c-U4NTUVDZ.js +1 -0
  51. package/dist/m/{c-P5NKFRL4.js → c-UOOIF2AL.js} +1 -1
  52. package/dist/m/c-VHSMPITY.js +1 -0
  53. package/dist/m/{c-6UPEKW6O.js → c-X75G43SZ.js} +1 -1
  54. package/dist/m/{c-YGGO2G2L.js → c-XW5TIYYB.js} +1 -1
  55. package/dist/m/{c-DZPO22O3.js → c-YDW4VCHP.js} +1 -1
  56. package/dist/m/{c-YB3CDTDZ.js → c-YLHTD3KX.js} +1 -1
  57. package/dist/m/c-Z4G2UK6T.js +4 -0
  58. package/dist/m/{c-VNAYHV2J.js → c-ZGCO4J3H.js} +1 -1
  59. package/dist/m/core/{admin-attrs-5UGMYCKW.js → admin-attrs-ONRWVXPK.js} +1 -1
  60. package/dist/m/core/{autosave-4P66VXX7.js → autosave-TBKAAAFB.js} +1 -1
  61. package/dist/m/core/{conflict-notice-BAR23OWH.js → conflict-notice-FOEE6I7E.js} +1 -1
  62. package/dist/m/core/draft-mode-4MCL3LYI.js +1 -0
  63. package/dist/m/core/{host-permission-3HE4CFD6.js → host-permission-X4BENZEU.js} +1 -1
  64. package/dist/m/core/{is-edit-mode-GK7IFFMT.js → is-edit-mode-FFHCQ5DR.js} +1 -1
  65. package/dist/m/core/{persist-AIJGTKKI.js → persist-6ILUR34S.js} +1 -1
  66. package/dist/m/core/{recovery-LPB6X72P.js → recovery-APWADU4K.js} +1 -1
  67. package/dist/m/core/{save-FV4ZCKBI.js → save-6HT2LABE.js} +1 -1
  68. package/dist/m/core/{save-core-K7XFAWQ4.js → save-core-EVMNZQ4V.js} +1 -1
  69. package/dist/m/core/{site-edits-TEQORBJU.js → site-edits-G4BOZMV4.js} +1 -1
  70. package/dist/m/core/{unsaved-warning-FF63QGKI.js → unsaved-warning-ITZDIZ2I.js} +1 -1
  71. package/dist/m/internals/{index-AX4CG7B2.js → index-HS3CQDFW.js} +1 -1
  72. package/dist/m/loader-GLLVDUZA.js +1 -0
  73. package/dist/m/manifest-50FF1C45.js +1 -0
  74. package/dist/m/manifest-edit-BE1A621D.js +1 -0
  75. package/dist/m/manifest.json +710 -674
  76. package/dist/m/plugins/{ai-edit-CUKQQWJX.js → ai-edit-LABECCSN.js} +1 -1
  77. package/dist/m/plugins/{cms-JANMGPHM.js → cms-T2HLI7JG.js} +16 -16
  78. package/dist/m/plugins/{demo-JIR7DXJA.js → demo-T7B4RIKL.js} +1 -1
  79. package/dist/m/plugins/{derive-QVI3LI3A.js → derive-6LPJOCAV.js} +1 -1
  80. package/dist/m/plugins/{indicator-DAKZGAWI.js → indicator-J4ABFARX.js} +1 -1
  81. package/dist/m/plugins/{live-UAJGWRNP.js → live-PGBIEMGB.js} +1 -1
  82. package/dist/m/plugins/{menu-BFJ644YX.js → menu-YZL3X2AJ.js} +1 -1
  83. package/dist/m/plugins/page-WOCNX2IN.js +2 -0
  84. package/dist/m/plugins/{page-view-OYN7Z5TS.js → page-view-SJODOOGE.js} +1 -1
  85. package/dist/m/plugins/{people-VBDR5Y22.js → people-C4TCWFOQ.js} +1 -1
  86. package/dist/m/plugins/{richclay-CBLZRFB4.js → richclay-Y2NV44NA.js} +3 -3
  87. package/dist/m/plugins/sortable-XCHQG65Z.js +1 -0
  88. package/dist/m/plugins/{source-ZXDD7F6X.js → source-YK7MO23W.js} +1 -1
  89. package/dist/m/plugins/{undo-5JI5G7CQ.js → undo-VLRBQNPN.js} +1 -1
  90. package/dist/m/plugins/{upgrade-6B6QS3NR.js → upgrade-NNTJBSK2.js} +1 -1
  91. package/dist/m/plugins/{upload-DNJNW6H3.js → upload-ZKKJV76X.js} +1 -1
  92. package/dist/m/plugins/visitor-drafts-RTZNONHT.js +20 -0
  93. package/dist/m/plugins/{visitor-drafts-owner-VIAZC3CF.js → visitor-drafts-owner-LHUHFU3L.js} +1 -1
  94. package/dist/m/plugins/{visitor-menu-ZHKWIKKY.js → visitor-menu-FY4KM2SW.js} +1 -1
  95. package/dist/m/plugins/wire-M2NR354P.js +1 -0
  96. package/dist/m/{reader-core-F6RY3V64.js → reader-core-T2S3JC4E.js} +2 -2
  97. package/dist/m/sync/{live-sync-M2PP2IWY.js → live-sync-Z64YREWQ.js} +1 -1
  98. package/dist/m/vendor/{sap-core.vendor-OA5SKL7Q.js → sap-core.vendor-QAEPMETX.js} +1 -1
  99. package/dist/offline-manifest.json +455 -425
  100. package/entries/clay-data.js +1 -1
  101. package/entries/sap.js +1 -1
  102. package/package.json +2 -2
  103. package/src/core/draft-mode.js +6 -0
  104. package/src/core/save-core.js +7 -8
  105. package/src/core/unsaved-warning.js +2 -2
  106. package/src/lib/idb-error-code.js +20 -0
  107. package/src/loader.js +2 -0
  108. package/src/plugins/page.js +19 -5
  109. package/src/plugins/sortable.js +7 -0
  110. package/src/plugins/visitor-drafts/commit.js +303 -0
  111. package/src/plugins/visitor-drafts/idb.js +221 -0
  112. package/src/plugins/visitor-drafts/prompt.js +23 -3
  113. package/src/plugins/visitor-drafts/session.js +345 -0
  114. package/src/plugins/visitor-drafts/store.js +210 -26
  115. package/src/plugins/visitor-drafts.js +148 -28
  116. package/src/vendor/hyper-html-api-data.vendor.js +1 -1
  117. package/src/vendor/hyper-html-api-upgrade.vendor.js +2 -2
  118. package/src/vendor/hypercms.vendor.js +16 -16
  119. package/src/vendor/richclay.vendor.js +1 -1
  120. package/src/vendor/sap-core.vendor.js +1 -1
  121. package/dist/m/c-234RSEIW.js +0 -1
  122. package/dist/m/c-2YIJ6ZA6.js +0 -1
  123. package/dist/m/c-H2H7TI6O.js +0 -1
  124. package/dist/m/c-JMDKPBMC.js +0 -4
  125. package/dist/m/c-N7JPUPGC.js +0 -1
  126. package/dist/m/c-NEXFVJIT.js +0 -1
  127. package/dist/m/c-T527QHOB.js +0 -1
  128. package/dist/m/core/draft-mode-WSQAT67S.js +0 -1
  129. package/dist/m/loader-5IA5OJ3J.js +0 -1
  130. package/dist/m/manifest-98258645.js +0 -1
  131. package/dist/m/manifest-edit-ABF56000.js +0 -1
  132. package/dist/m/plugins/page-ZBIYHGK4.js +0 -2
  133. package/dist/m/plugins/sortable-HDOQ6GAC.js +0 -1
  134. package/dist/m/plugins/visitor-drafts-A5FDQ2G7.js +0 -20
  135. package/dist/m/plugins/wire-XOT7XKJL.js +0 -1
  136. /package/dist/m/plugins/{richclay-CBLZRFB4.js.LEGAL.txt → richclay-Y2NV44NA.js.LEGAL.txt} +0 -0
@@ -0,0 +1 @@
1
+ import{a,b,c,d}from"./c-HKSLOVU4.js";import"./c-VHNSBD2M.js";export{c as applyData,d as default,a as engine,b as extractData};
@@ -1 +1 @@
1
- import{e as k}from"./c-N326R2JD.js";import{a as w}from"./c-I2SCCUEW.js";import{f as v}from"./c-DLBX4JCJ.js";var j=new Set(["accepted","reverted","reconciled"]),T=Math.random().toString(36).slice(2,8),z=0,l=new Map,f=new Map,p=new Set,h=new Set,x=null,O=20,y=null,b=null,u=[];function E(){b??=import("./c-LUXAB2XI.js").then(e=>{for(y=e;u.length;)y.keep(u.shift())},e=>{b=null,console.error("clayjs: the conflict recovery module could not be downloaded; conflicts stay in this tab only",e)})}v&&E();function S(e=""){return`${T}:${e}${++z}`}function m(){return x||=w({id:"live-sync-conflicts",isPending:()=>l.size>0||p.size>0}),x}function g(e){m().changed(),document.dispatchEvent(new CustomEvent("clay:sync-conflicts-changed",{detail:{open:[...l.keys()],added:[],removedIds:[],updatedIds:[],...e}}))}function $(e){let t=e.recovery;return t?t.applied===!1&&t.unavailable==="hook-veto"?!1:t.localLost!==!1:!0}var C=["kind","id","label","field"];function I(e){if(!e||typeof e!="object")return null;let t={};for(let n of C){let o=e[n];typeof o=="string"&&o?t[n]=o:typeof o=="number"&&Number.isFinite(o)&&(t[n]=String(o))}return Object.keys(t).length?t:null}function F(e){let t=I(e);return t?(typeof e.open=="function"&&(t.open=e.open),t):null}function A(e,t){for(let n of[...h].reverse()){let o;try{o=n(e,t)}catch(r){console.error("clayjs: a conflict context resolver threw; the conflict stays generic",r);continue}let c=F(o);if(c)return c}return null}function L(e){if(typeof e!="function")throw new TypeError("clay.conflicts.registerContext needs a resolver function");return h.add(e),()=>h.delete(e)}function B(e,t){let n=S(),o=Object.assign(t[0],{id:n,applyId:e.id,source:e.source,ticket:e.ticket,rawReports:t,claimedBy:null});return o.context=A(o,e),l.set(n,o),e.ids.add(n),n}function D({source:e,seq:t=null,etag:n=null,domain:o,root:c,recoveryRoot:r=null}){let i=S("a");return f.set(i,{id:i,source:e,seq:t,etag:n,ticket:0,domain:o,root:c,recoveryRoot:r,ids:new Set}),p.add(i),m().changed(),i}function N(e){if(!e.every(n=>n.kind==="structure"&&n.detail==="insert-collision"&&n.recovery?.applied===!0&&!n.recovery.unavailable&&n.recovery.structure?.localAction==="inserted"&&n.recovery.structure.fragmentKind==="element"))return null;let t=e[0].recovery.subject;return t?.local?.length!==1||t.merged?.length!==1||t.live?.length!==1?null:{local:t.local[0],merged:t.merged[0],live:t.live[0]}}function P(e){let t=new Map(e.map(r=>[r,N(r)])),n=(r,i)=>r.length<i.length&&r.every((s,d)=>s===i[d]),o=(r,i)=>i.reduce((s,d)=>d==="content"?s?.content:s?.childNodes[d],r),c=new Map;for(let r of e){let i=t.get(r),s=r;if(i)for(let d of e){let a=t.get(d);a&&a.local.length<t.get(s).local.length&&n(a.local,i.local)&&n(a.merged,i.merged)&&(a.live.contains(i.live)||o(a.live,i.merged.slice(a.merged.length))===i.live)&&(s=d)}c.has(s)||c.set(s,[...s]),r!==s&&c.get(s).push(...r)}return[...c.values()]}function M(e,t){let n=t.map(c=>l.get(c)).filter(Boolean);if(!n.length)return;let o={apply:e,records:n.map(c=>({rec:c,context:I(c.context)}))};if(y)return y.keep(o);u.push(o),u.length>O&&u.shift(),E()}function Q(e,t,{ticket:n}){let o=f.get(e);if(!o)return[];o.ticket=n;let c=new Map;for(let i of t){if(!$(i))continue;let s=i.recovery?.key??Symbol();c.has(s)||c.set(s,[]),c.get(s).push(i)}let r=P([...c.values()]).map(i=>B(o,i));return r.length&&M(o,r),p.delete(e),r.length||f.delete(e),r.length?g({added:r.map(i=>l.get(i))}):m().changed(),r}function X(e,t,{ticket:n=0}={}){let o=f.get(e);if(!o)return[];o.ticket=n,p.delete(e);let c=B(o,[{kind:"apply-incomplete",detail:null,error:String(t)}]);return l.get(c).rawReports=[],M(o,[c]),g({added:[l.get(c)]}),[c]}var q={get size(){return l.size},list(){return[...l.values()]},get(e){return l.get(e)||null},acknowledge(e,{reason:t}={}){if(!Array.isArray(e))throw new TypeError("clay.conflicts.acknowledge needs an array of ids");if(!j.has(t))throw new TypeError(`clay.conflicts.acknowledge: unknown reason "${t}"`);let n=[];for(let o of e){let c=l.get(o);if(!c)continue;k(c),l.delete(o),n.push(o);let r=f.get(c.applyId);r&&(r.ids.delete(o),r.ids.size||f.delete(c.applyId))}return n.length&&(g({removedIds:n,reason:t}),import("./c-LUXAB2XI.js").then(o=>o.dismiss(n),()=>{})),{removedIds:n,remainingIds:[...l.keys()]}},claim(e,{owner:t}){if(!t)throw new TypeError("clay.conflicts.claim needs an owner");for(let c of e){let r=l.get(c);if(r&&r.claimedBy&&r.claimedBy!==t)throw new Error(`conflict ${c} is already claimed by ${r.claimedBy}`)}let n=[];for(let c of e){let r=l.get(c);r&&!r.claimedBy&&(r.claimedBy=t,n.push(c))}n.length&&g({updatedIds:n,reason:"claimed"});let o=!1;return{release(){if(o)return;o=!0;let c=n.filter(r=>l.get(r)?.claimedBy===t);for(let r of c)l.get(r).claimedBy=null;c.length&&g({updatedIds:c,reason:"released"})}}},registerContext:L,contextFor:A,recoveryOf(e){let t=l.get(e);return t&&f.get(t.applyId)||null},hasPendingApply(){return p.size>0}};export{E as a,L as b,D as c,Q as d,X as e,q as f};
1
+ import{e as k}from"./c-N326R2JD.js";import{a as w}from"./c-I2SCCUEW.js";import{f as v}from"./c-EDE45NM7.js";var j=new Set(["accepted","reverted","reconciled"]),T=Math.random().toString(36).slice(2,8),z=0,l=new Map,f=new Map,p=new Set,h=new Set,x=null,O=20,y=null,b=null,u=[];function E(){b??=import("./c-LUXAB2XI.js").then(e=>{for(y=e;u.length;)y.keep(u.shift())},e=>{b=null,console.error("clayjs: the conflict recovery module could not be downloaded; conflicts stay in this tab only",e)})}v&&E();function S(e=""){return`${T}:${e}${++z}`}function m(){return x||=w({id:"live-sync-conflicts",isPending:()=>l.size>0||p.size>0}),x}function g(e){m().changed(),document.dispatchEvent(new CustomEvent("clay:sync-conflicts-changed",{detail:{open:[...l.keys()],added:[],removedIds:[],updatedIds:[],...e}}))}function $(e){let t=e.recovery;return t?t.applied===!1&&t.unavailable==="hook-veto"?!1:t.localLost!==!1:!0}var C=["kind","id","label","field"];function I(e){if(!e||typeof e!="object")return null;let t={};for(let n of C){let o=e[n];typeof o=="string"&&o?t[n]=o:typeof o=="number"&&Number.isFinite(o)&&(t[n]=String(o))}return Object.keys(t).length?t:null}function F(e){let t=I(e);return t?(typeof e.open=="function"&&(t.open=e.open),t):null}function A(e,t){for(let n of[...h].reverse()){let o;try{o=n(e,t)}catch(r){console.error("clayjs: a conflict context resolver threw; the conflict stays generic",r);continue}let c=F(o);if(c)return c}return null}function L(e){if(typeof e!="function")throw new TypeError("clay.conflicts.registerContext needs a resolver function");return h.add(e),()=>h.delete(e)}function B(e,t){let n=S(),o=Object.assign(t[0],{id:n,applyId:e.id,source:e.source,ticket:e.ticket,rawReports:t,claimedBy:null});return o.context=A(o,e),l.set(n,o),e.ids.add(n),n}function D({source:e,seq:t=null,etag:n=null,domain:o,root:c,recoveryRoot:r=null}){let i=S("a");return f.set(i,{id:i,source:e,seq:t,etag:n,ticket:0,domain:o,root:c,recoveryRoot:r,ids:new Set}),p.add(i),m().changed(),i}function N(e){if(!e.every(n=>n.kind==="structure"&&n.detail==="insert-collision"&&n.recovery?.applied===!0&&!n.recovery.unavailable&&n.recovery.structure?.localAction==="inserted"&&n.recovery.structure.fragmentKind==="element"))return null;let t=e[0].recovery.subject;return t?.local?.length!==1||t.merged?.length!==1||t.live?.length!==1?null:{local:t.local[0],merged:t.merged[0],live:t.live[0]}}function P(e){let t=new Map(e.map(r=>[r,N(r)])),n=(r,i)=>r.length<i.length&&r.every((s,d)=>s===i[d]),o=(r,i)=>i.reduce((s,d)=>d==="content"?s?.content:s?.childNodes[d],r),c=new Map;for(let r of e){let i=t.get(r),s=r;if(i)for(let d of e){let a=t.get(d);a&&a.local.length<t.get(s).local.length&&n(a.local,i.local)&&n(a.merged,i.merged)&&(a.live.contains(i.live)||o(a.live,i.merged.slice(a.merged.length))===i.live)&&(s=d)}c.has(s)||c.set(s,[...s]),r!==s&&c.get(s).push(...r)}return[...c.values()]}function M(e,t){let n=t.map(c=>l.get(c)).filter(Boolean);if(!n.length)return;let o={apply:e,records:n.map(c=>({rec:c,context:I(c.context)}))};if(y)return y.keep(o);u.push(o),u.length>O&&u.shift(),E()}function Q(e,t,{ticket:n}){let o=f.get(e);if(!o)return[];o.ticket=n;let c=new Map;for(let i of t){if(!$(i))continue;let s=i.recovery?.key??Symbol();c.has(s)||c.set(s,[]),c.get(s).push(i)}let r=P([...c.values()]).map(i=>B(o,i));return r.length&&M(o,r),p.delete(e),r.length||f.delete(e),r.length?g({added:r.map(i=>l.get(i))}):m().changed(),r}function X(e,t,{ticket:n=0}={}){let o=f.get(e);if(!o)return[];o.ticket=n,p.delete(e);let c=B(o,[{kind:"apply-incomplete",detail:null,error:String(t)}]);return l.get(c).rawReports=[],M(o,[c]),g({added:[l.get(c)]}),[c]}var q={get size(){return l.size},list(){return[...l.values()]},get(e){return l.get(e)||null},acknowledge(e,{reason:t}={}){if(!Array.isArray(e))throw new TypeError("clay.conflicts.acknowledge needs an array of ids");if(!j.has(t))throw new TypeError(`clay.conflicts.acknowledge: unknown reason "${t}"`);let n=[];for(let o of e){let c=l.get(o);if(!c)continue;k(c),l.delete(o),n.push(o);let r=f.get(c.applyId);r&&(r.ids.delete(o),r.ids.size||f.delete(c.applyId))}return n.length&&(g({removedIds:n,reason:t}),import("./c-LUXAB2XI.js").then(o=>o.dismiss(n),()=>{})),{removedIds:n,remainingIds:[...l.keys()]}},claim(e,{owner:t}){if(!t)throw new TypeError("clay.conflicts.claim needs an owner");for(let c of e){let r=l.get(c);if(r&&r.claimedBy&&r.claimedBy!==t)throw new Error(`conflict ${c} is already claimed by ${r.claimedBy}`)}let n=[];for(let c of e){let r=l.get(c);r&&!r.claimedBy&&(r.claimedBy=t,n.push(c))}n.length&&g({updatedIds:n,reason:"claimed"});let o=!1;return{release(){if(o)return;o=!0;let c=n.filter(r=>l.get(r)?.claimedBy===t);for(let r of c)l.get(r).claimedBy=null;c.length&&g({updatedIds:c,reason:"released"})}}},registerContext:L,contextFor:A,recoveryOf(e){let t=l.get(e);return t&&f.get(t.applyId)||null},hasPendingApply(){return p.size>0}};export{E as a,L as b,D as c,Q as d,X as e,q as f};
@@ -1,4 +1,4 @@
1
- import{d as Ae,h as Ve,i as qe}from"./c-TRS6TM6O.js";import{a as Ne,b as Pe}from"./c-4PO3YGDC.js";import{a as Ie,b as Oe}from"./c-PZ4XEPUP.js";import"./c-SFKI6OLM.js";import"./c-Q3XOWZEV.js";import"./c-RHMPKZZ7.js";import{e as ke,f as Ke,g as W,h as Ue,l as re,m as $e,n as p}from"./c-MR75YPRT.js";import"./c-4JZDZFF6.js";import{b as U,c as Z,e as l,f as Ye}from"./c-5RZNFTWD.js";import{b as He}from"./c-PKCCHJ5X.js";import{b as T,c as Fe}from"./c-NUHP2XDB.js";import{a as We,r as V}from"./c-2YIJ6ZA6.js";import"./c-4ASQPRQL.js";import"./c-GQ6F6IDK.js";import"./c-I2SCCUEW.js";import"./c-5VYOWDTI.js";import{f as Te}from"./c-LO4C4J77.js";import"./c-FV46ZKGX.js";import"./c-WYFDLITL.js";import"./c-UGHH4MB3.js";import"./c-LA2BW7UY.js";import"./c-HSNGLIFB.js";import"./c-LD6UVV5R.js";import"./c-PGSBXHUE.js";import"./c-RXTPKCMC.js";import"./c-RBPZNU2D.js";import"./c-IJUK2GPW.js";import{f as _e}from"./c-DLBX4JCJ.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-PWJSJEJU.js";import"./c-XQXZAO7N.js";import"./c-S7LK4KUE.js";import"./c-VG5XIN4T.js";import"./c-2YYDMLNZ.js";import"./c-HA6INT6J.js";import"./c-ICMAOOGK.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var E="light-dark(#D08A1E, #E3A33F)",lt=5e3,st=4e3,dt=500,ct={"another-tab":"in another tab","another-person":"by someone else","an-agent":"by an agent"},pt='<svg viewBox="0 0 12 12" width="12" height="12" aria-hidden="true"><path d="M2.5 9.5h7" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="square"/></svg>',F=(e,t)=>`${e} ${t}${e===1?"":"s"}`,ut="This spot changed again. Review the latest edit or download your copy.",ft="A data value can't be put back from here. Download your copy to keep yours.",m="hidden",P=!1,S=[],J=new Set,M=new Set,h=null,Ee=0,I=null,v=null,le=null,u=null,R=!1,Y=!1,ve=!1,G=new Map,se=0,ae=!1,te=!1,b=null,j=null,L=null,Se=0,D=!1,de=0,ce=null,ne=null,k=[],x=[],oe=!1,pe=null,ue=null,s=null,B=null,q=new Map,z=()=>window.clay?.conflicts||null,Qe=()=>k.reduce((e,t)=>e+t.conflicts.length,0)+x.length,Le=()=>{let e=window.clay?.undo;return e&&typeof e.kept=="function"?e:null},fe=()=>z()?.list().filter(e=>!e.claimedBy&&e.kind!=="apply-incomplete")??[],De=()=>z()?.list().filter(e=>!e.claimedBy&&e.kind==="apply-incomplete")??[];function ze(){return I?"upgraded":h?"refused":fe().length?"replaced":De().length?"failed":k.length||x.length?"recovered":null}function f(e,t,n){let o=Fe(e,t,n);return t[0]==="all:initial"&&T(o,"color-scheme","inherit"),o.setAttribute("clay",ke),o}function _(e,t){return q.set(t,e),e}function ie(){if(!s)return;let e=window.visualViewport,t=e?Math.max(0,window.innerHeight-e.height-e.offsetTop):0;T(s,"bottom",`calc(${16+t}px + env(safe-area-inset-bottom,0px))`),ne&&T(ne,"max-height",`${Math.max(160,(e?.height||window.innerHeight)-32)}px`)}function ht(){s=f("div",["all:initial","position:fixed","left:50%","transform:translateX(-50%)","z-index:2147483001","display:none","flex-direction:column","align-items:center","max-width:calc(100vw - 24px)",`font:14px/1.5 ${U}`,`color:${l.ink}`,"text-align:left"]),s.setAttribute("data-clay-conflict",""),document.body.appendChild(s),window.visualViewport?.addEventListener("resize",ie),window.visualViewport?.addEventListener("scroll",ie)}function d(){if(ae)return;ae=!0;let e=()=>{ae=!1,w()};typeof requestAnimationFrame=="function"?requestAnimationFrame(e):setTimeout(e,16)}function w(){te&&(te=!1,h&&!V()&&(h=null));let e=ze();if(e?m==="hidden"&&(m="bar"):(m="hidden",P=!1,J.clear(),M.clear(),S=[],y(),ce=null,D=!1),!s){if(m==="hidden"&&!b||!document.body)return;ht()}!s.isConnected&&document.body&&document.body.appendChild(s);let t=document.activeElement,n=null;for(let[a,r]of q)r===t&&(n=a);let o=B?B.scrollTop:0;q=new Map,B=null,ne=null,s.replaceChildren(),b?s.append(wt(b)):m==="bar"?s.append(yt(e)):m==="panel"&&s.append(xt(e)),T(s,"display",b||m!=="hidden"?"flex":"none"),B&&(B.scrollTop=o);let i=L||n;i&&q.has(i)&&q.get(i).focus({preventScroll:!0}),b||(L=null),ie(),He(s)}function Xe(){return f("span",["all:initial","display:inline-block","flex:none","width:8px","height:8px","border-radius:50%",`background:${E}`])}function Ze(){return ct[h?.changedBy]||null}function gt(e,t){if(e==="upgraded")return I;if(e==="refused"){let n=Ze();return!n&&h.afterTimeout?"This page changed elsewhere, possibly by your own save that timed out. Your edits here are safe.":`This page changed ${n||"elsewhere"}. Your edits here are safe.`}return e==="failed"?"A sync update did not finish. Your edits here are safe.":e==="recovered"?`${F(t,"change")} replaced before this page loaded ${t===1?"is":"are"} still here.`:`Another edit replaced ${F(t,"change")}.`}function mt(e,t){return e==="upgraded"?I:e==="refused"?`This page changed ${Ze()||"elsewhere"}`:e==="failed"?"A sync update did not finish":e==="recovered"?`${F(t,"change")} kept from before this page loaded`:`Another edit replaced ${F(t,"change")}`}function wt(e){let t=re("div",["display:block",`border-left:3px solid ${l.teal}`,"padding:10px 14px","width:max-content","max-width:calc(100vw - 24px)"]);return t.setAttribute("role","status"),t.textContent=e,t}function yt(e){let t=e==="failed"?De().length:e==="recovered"?Qe():fe().length,n=re("div",["display:flex","flex-wrap:wrap","align-items:center","gap:10px 12px","padding:8px 8px 8px 14px","width:max-content","max-width:calc(100vw - 24px)"]),o=gt(e,t);return o!==ce&&(n.setAttribute("role",e==="refused"?"alert":"status"),ce=o),n.append(Xe(),p("span",[],o)),e==="upgraded"?(n.append(_(W("Reload",{variant:"primary",onClick:()=>window.location.reload()}),"reload")),n):(n.append(_(W("Review",{onClick:Dt}),"review")),n)}function $(e,t,{variant:n="default",onClick:o,push:i=!1}={}){let r=window.innerWidth<480?["flex:1 1 100%",...n==="primary"?["order:-1"]:[]]:i?["margin-left:auto"]:[];return _(W(e,{variant:n,onClick:o,extra:r}),t)}function A(e){return p("div",["display:block","padding:0 16px 12px",`color:${l["ink-2"]}`,"font-size:13.5px"],e)}function xt(e){let t=e==="replaced"?fe():e==="failed"?De():[],n=e==="refused"?fe():t,o=e==="recovered"?Qe():t.length;if(J.size)for(let c of t)J.has(c.id)||M.add(c.id);for(let c of[...M])t.some(N=>N.id===c)||M.delete(c);let i=mt(e,o),a=Math.max(160,(window.visualViewport?.height||window.innerHeight)-32),r=re("div",["display:flex","flex-direction:column","width:520px","max-width:calc(100vw - 24px)",`max-height:${a}px`]);ne=r,r.setAttribute("role","dialog"),r.setAttribute("aria-label",i);let g=f("div",["all:initial","display:flex","align-items:center","gap:8px","padding:12px 12px 8px 16px",`font:14px/1.5 ${U}`,`color:${l.ink}`]),K=_(p("b",["font-weight:600","font-size:14.5px","outline:none"],i),"title");K.setAttribute("tabindex","-1"),g.append(Xe(),K),e==="replaced"&&M.size&&g.append(p("span",[`font:600 10.5px/1 ${Z}`,"letter-spacing:.12em","text-transform:uppercase","padding:3px 6px",`color:color-mix(in srgb, ${l.brass} 80%, ${l.ink})`,`background:${l["brass-soft"]}`],`${M.size} new`));let X=f("span",["all:initial","display:inline-flex","margin-left:auto"]),Be=_(Ue(pt,{label:"Minimize",onClick:Je}),"minimize");if(Be.title="Minimize to the bar. Nothing is accepted until you choose.",X.append(Be),g.append(X),r.append(g),e==="recovered")return Et(r),r;if(e==="refused"){if(r.append(A("Your edits here are safe and not saved yet; nothing will be overwritten until you choose. Their version is not on this page, so there is no list of edits to compare. Keep yours, which saves over theirs, or accept theirs, which reloads the page and drops your unsaved edits.")),n.length&&r.append(A(`${F(n.length,"earlier replaced edit")} ${n.length===1?"is":"are"} also held in this tab. Download my copy includes them.`)),R&&r.append(A("That did not save either. Your edits here are still here.")),D&&r.append(A("Something changed on the page after your first press, so nothing was dropped. Press Accept theirs again if you still want their version.")),v){let c=f("div",["all:initial","display:block","margin:0 16px 12px","padding:8px 10px",`border-left:3px solid ${E}`,`background:color-mix(in srgb, ${E} 14%, transparent)`,`color:${l.ink}`,`font:13px/1.5 ${U}`]);c.append(f("b",["all:initial","font:inherit","font-weight:700","color:inherit"],"This drops your unsaved edits."),document.createTextNode(" Download your copy first if you might want them. Press again to confirm.")),r.append(c)}}else e==="upgraded"?r.append(A("Its layout and code changed with it, so this page stops here. Reload to see the new version.")):e==="failed"?r.append(A("Part of an update from elsewhere could not be applied, so this page may be missing some of it. Your edits here are safe. Download a copy of the page as you had it, or accept to keep the page as it is.")):r.append(A("The page is showing the other edit. This stays until you choose. You can also save a copy of the page as you had it."));let O=f("div",["all:initial","display:flex","flex-wrap:wrap","gap:8px","padding:0 16px 14px"]);if(e==="upgraded")return O.append($("Reload","reload",{variant:"primary",onClick:()=>window.location.reload(),push:!0})),r.append(O),S=[],r;let at=$(ve?"Try again":Y?"Downloaded":"Download my copy","download",{onClick:Bt});if(O.append(at),e==="refused"){let c=$(u==="overwrite"?"Saving\u2026":R?"Try again":"Keep mine","keep",{onClick:Pt});c.setDisabled(u==="overwrite"),O.append(c,$(v?"Yes, drop my edits":"Accept theirs","accept",{variant:"primary",onClick:Ft,push:!0}))}else{if(e==="replaced"){let c=z().hasPendingApply(),N=$(c?"Finishing the incoming edit\u2026":u==="revert"?"Putting back\u2026":"Revert to mine","revert",{onClick:Mt});N.setDisabled(c||u==="revert"),O.append(N)}O.append($("Accept theirs","accept",{variant:"primary",onClick:zt,push:!0}))}if(r.append(O),e==="replaced")if(P)r.append(vt(t));else{let c=f("div",["all:initial","display:flex","align-items:center","gap:8px",`border-top:1px solid ${l.line}`,"padding:8px 10px 8px 16px",`color:${l.muted}`,`font:13px/1.5 ${U}`]),N=f("span",["all:initial","display:inline-flex","margin-left:auto"]);N.append(_(W("See the edits",{small:!0,onClick:et}),"list")),c.append(f("span",["all:initial","font:inherit","color:inherit"],F(t.length,"edit")),N),r.append(c)}S=n.map(c=>c.id);for(let c of t)J.add(c.id);return r}function vt(e){let t=$e(["flex:1 1 auto","margin:0 16px 12px","min-height:0","overflow:auto",`background:${l.sunk}`,`border:1px solid ${l["line-2"]}`]),n=f("div",["all:initial","position:sticky","top:0","z-index:1","display:flex","align-items:center","gap:8px","padding:8px 12px",`background:${l.sunk}`,`border-bottom:1px solid ${l["line-2"]}`,`color:${l.muted}`,`font:600 10.5px/1 ${Z}`,"letter-spacing:.12em","text-transform:uppercase"]),o=f("span",["all:initial","display:inline-flex","margin-left:auto"]);return o.append(_(W("Hide",{small:!0,variant:"quiet",onClick:et}),"list")),n.append(f("span",["all:initial","font:inherit","color:inherit","letter-spacing:inherit","text-transform:inherit"],"Replaced edits"),o),t.append(n),e.forEach((i,a)=>t.append(St(i,a))),B=t,t}function Me(e){let t=e.context?.label||e.name||(e.context?.kind==="entry"?"Entry":"Edit");return e.context?.field?`${t} \xB7 ${e.context.field}`:t}var bt={"content-changed":"the page changed there","structure-changed":"the structure changed there","target-detached":"that part of the page is gone","duplicate-id":"another part of the page now has the same id",protected:"that region keeps its own history",unsupported:"this kind of step cannot be put back"},kt=e=>bt[e]||"the page changed there";function $t(e,t){let n=Array.isArray(e)?e:[];for(let o of n){if(!o||o.kind!=="text"&&o.kind!=="value")continue;let i=t==="redo"?o.after:o.before;if(typeof i=="string"&&i)return{text:i,id:o.target?.id??null}}for(let o of n){if(!o||o.kind!=="add"&&o.kind!=="remove")continue;let i=Array.isArray(o.nodes)?o.nodes.find(a=>typeof a?.html=="string"&&a.html):null;if(i)return{text:Ie(i.html).replace(/\s+/g," ").trim(),id:o.parent?.id??null}}for(let o of n){if(!o)continue;let i=t==="redo"?o.after:o.before;if(typeof i=="string"&&i)return{text:i,id:o.target?.id??null}}return{text:"",id:null}}function Tt(e){if(e==null||typeof document>"u")return"";let t=window.CSS?.escape?window.CSS.escape(String(e)):String(e).replace(/["\\]/g,"\\$&"),n=null;try{n=document.querySelector(`[data-id="${t}"]`)}catch{return""}if(!n)return"";let o=n.matches?.("input, textarea, select")?n.value:null;return(typeof o=="string"?o:n.textContent??"").replace(/\s+/g," ").trim()}function At(e){let t=e?.payload&&typeof e.payload=="object"?e.payload:{},n=String(e?.key??""),o={id:e?.id,revision:e?.revision,record:e,kind:e?.kind??"conflict"};if(n.startsWith("app:"))return{...o,name:typeof t.label=="string"&&t.label?t.label:n.slice(4),sentence:"",yours:typeof t.text=="string"?t.text:"",now:""};let i=t.direction==="redo"?"redo":"undo",g=((Array.isArray(t.context)?t.context:[]).find(X=>typeof X?.label=="string"&&X.label)??null)?.label||typeof t.label=="string"&&t.label||"Edit",K=$t(t.steps,i);return{...o,name:g,sentence:`The ${i} of "${g}" was not applied because ${kt(t.code)}.`,yours:K.text,now:K.id==null?"":Tt(K.id)}}function Ct(e){let t=Le();if(!e.record||typeof t?.reviewActionsFor!="function")return[];try{return(t.reviewActionsFor(e.record)||[]).filter(n=>n&&typeof n.run=="function"&&n.label)}catch{return[]}}var Ge=e=>({before:"",hit:e,after:"",cutBefore:!1,cutAfter:!1});function je(e){let t=p("div",["display:block","padding:8px 12px 10px"]),n=p("div",["display:flex","align-items:center","gap:8px","font-size:12.5px","font-weight:600",`color:${l["ink-2"]}`,"margin-bottom:4px"]);if(n.append(p("span",[],Me(e))),t.append(n),e.sentence&&t.append(p("div",["display:block","font-size:13px",`color:${l["ink-2"]}`],e.sentence)),e.yours){let i=p("div",["display:grid","grid-template-columns:44px 1fr","gap:3px 10px","align-items:start",`font:12.5px/1.5 ${Z}`,...e.sentence?["margin-top:4px"]:[]]);i.append(...he("Yours",Ge(e.yours),{mine:!0})),e.now&&i.append(...he("Now",Ge(e.now),{mine:!1})),t.append(i)}let o=f("div",["all:initial","display:flex","flex-wrap:wrap","gap:8px","margin-top:8px"]);return Ct(e).forEach((i,a)=>{let r=$(i.label,`run:${e.id}:${a}`,{onClick:()=>Nt(e,i,r)});o.append(r)}),o.append($(pe===e.id?"Copied":"Copy",`copy:${e.id}`,{onClick:()=>It(e)})),o.append($("Dismiss",`dismiss:${e.id}`,{onClick:()=>tt(e)})),t.append(o),t}function Et(e){e.append(A(k.length?"These copies were replaced before this page loaded. The page never puts them back on its own. Copy or download the ones you want; dismiss one when you no longer need it.":"These copies were kept because an undo could not be put back or the page set them aside. The page never puts them back on its own. Copy or download the ones you want; dismiss one when you no longer need it.")),oe&&e.append(A("That action did not run. The copy is still here."));let t=$e(["flex:1 1 auto","margin:0 16px 12px","min-height:0","overflow:auto",`background:${l.sunk}`,`border:1px solid ${l["line-2"]}`]);for(let o of k)for(let i of o.conflicts)t.append(je(i));for(let o of x)t.append(je(o));B=t,e.append(t);let n=f("div",["all:initial","display:flex","flex-wrap:wrap","gap:8px","padding:0 16px 14px"]);(k.some(o=>o.root)||x.length)&&n.append($(Y?"Downloaded":"Download my copy","download",{onClick:Ot})),e.append(n),S=[]}function he(e,t,{mine:n}){let o=[p("span",[`color:${l.faint}`,`font-family:${U}`],e)],i=p("span",["display:-webkit-box","-webkit-line-clamp:2","-webkit-box-orient:vertical","overflow:hidden","overflow-wrap:anywhere",...n?[`color:${l.ink}`]:[`color:${l.muted}`]]),a=(t.cutBefore?"\u2026":"")+t.before+t.hit+t.after+(t.cutAfter?"\u2026":"");i.title=a,t.before&&i.append(p("span",[`color:${l.faint}`],(t.cutBefore?"\u2026":"")+t.before));let r=p("span",n?[`background:color-mix(in srgb, ${E} 18%, transparent)`,"padding:0 4px"]:t.before||t.after?["text-decoration:underline",`text-decoration-color:color-mix(in srgb, ${E} 70%, transparent)`,"text-underline-offset:3px"]:[],t.hit||"(empty)");return i.append(r),t.after&&i.append(p("span",[`color:${l.faint}`],t.after+(t.cutAfter?"\u2026":""))),o.push(i),o}function St(e,t){let n=Oe(e),o=p("div",["display:block","padding:8px 12px 10px",...t?[`border-top:1px solid ${l.line}`]:[]]),i=p("div",["display:flex","align-items:center","gap:4px","font-size:12.5px","font-weight:600",`color:${l["ink-2"]}`,"margin-bottom:4px"]);if(i.append(p("span",[],n.name)),n.target&&n.target.isConnected&&i.append(_(Rt(n),`eye:${e.id}`)),o.append(i),n.sentence&&o.append(p("div",["display:block","font-size:13px",`color:${l["ink-2"]}`],n.sentence)),G.has(e.id)&&o.append(p("div",["display:block","font-size:13px","margin-top:4px",`color:${E}`],G.get(e.id))),n.yours){let a=p("div",["display:grid","grid-template-columns:44px 1fr","gap:3px 10px","align-items:start",`font:12.5px/1.5 ${Z}`,...n.sentence?["margin-top:4px"]:[]]);a.append(...he("Yours",n.yours,{mine:!0})),n.now&&a.append(...he("Now",n.now,{mine:!1})),o.append(a)}return o}function Rt(e){let t=["all:initial","color-scheme:inherit","box-sizing:border-box","cursor:pointer","display:inline-grid","place-items:center","width:22px","height:20px",`color:${l.ink}`],n=f("button",t);n.type="button",n.innerHTML=Ye.conflictEye,Ke(n.firstElementChild,16),n.setAttribute("aria-label",`Show ${e.name} on page`),n.title="Show on page";let o=i=>{n.style.cssText="";for(let a of[...t,...i]){let r=a.indexOf(":");n.style.setProperty(a.slice(0,r),a.slice(r+1),"important")}};return n.addEventListener("pointerenter",()=>o([`background:color-mix(in srgb, ${E} 16%, transparent)`])),n.addEventListener("pointerleave",()=>o([])),n.addEventListener("focus",()=>o([`outline:2px solid ${l.brass}`,"outline-offset:1px"])),n.addEventListener("blur",()=>o([])),n.addEventListener("click",()=>Lt(e.target)),n}var C=null,ge=null,me=null;function we(){clearTimeout(ge),window.removeEventListener("scroll",ee,!0),window.removeEventListener("resize",ee),C?.remove(),C=null,me=null}function ee(){if(!C||!me)return;let e=me.getBoundingClientRect();T(C,"left",`${e.left}px`),T(C,"top",`${e.top}px`),T(C,"width",`${e.width}px`),T(C,"height",`${e.height}px`)}function Lt(e){if(we(),!e||!e.isConnected)return;let n=!!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches?"instant":"smooth",o=s?.getBoundingClientRect().top??0,i=s&&o>0?Math.max(0,window.innerHeight-o):0;if(!i)e.scrollIntoView?.({block:"center",behavior:n});else{e.scrollIntoView?.({block:"center",behavior:"instant"});let a=e.getBoundingClientRect(),r=window.innerHeight-i,g=a.height>r-24?a.top-12:a.top+a.height/2-r/2;window.scrollBy?.({top:g,behavior:n})}me=e,C=f("div",["all:initial","color-scheme:inherit","position:fixed","pointer-events:none","z-index:2147483001",`outline:2px solid ${E}`,"outline-offset:3px",`background:color-mix(in srgb, ${E} 14%, transparent)`]),document.body.appendChild(C),ee(),window.addEventListener("scroll",ee,!0),window.addEventListener("resize",ee),ge=setTimeout(we,2500)}function Dt(){I||(m="panel",L="title",w())}function Je(){we(),m="bar",y(),L="review",w()}function et(){P=!P,P&&M.clear(),w()}function zt(){let e=z(),t=S.filter(n=>{let o=e?.get(n);return o&&!o.claimedBy});e&&t.length&&e.acknowledge(t,{reason:"accepted"}),m=ze()?"bar":"hidden",L="review",d()}async function Mt(){let e=z();if(u||!e||e.hasPendingApply())return;let t=S.filter(r=>{let g=e.get(r);return g&&!g.claimedBy});if(!t.length)return;u="revert",w();let n=!0,o=r=>{n=!!s?.contains(r.target)};document.addEventListener("focus",o,!0);let i;try{let{revertConflicts:r}=await import("./c-UM7VZDTW.js");i=await r(t)}catch(r){console.error("[clay] Revert to mine did not finish",r),i={revertedIds:[],blockedIds:t,saveResult:null}}finally{document.removeEventListener("focus",o,!0)}u=null;for(let r of i.blockedIds)G.set(r,z()?.get(r)?.kind==="json"?ft:ut);m=ze()?"bar":"hidden",L=n?"review":null;let a=i.saveResult&&(i.saveResult.ok||i.saveResult.msg==="Save already in progress");i.revertedIds.length&&a?be(`Put back ${F(i.revertedIds.length,"change")}. Saving.`):w()}var Q=null;async function Bt(){let e=z(),t=h?e?.list()??[]:S.map(o=>e?.get(o)).filter(Boolean),n=await Pe(t,{refused:!!h});ve=!n,Y=n,clearTimeout(Q),n&&(Q=setTimeout(()=>{Y=!1,d()},1200)),w()}async function H(){let e=null;if(Ae())try{e=await Ve()}catch{e=null}let t=Le(),n=null;if(t)try{n=await t.kept()}catch{n=null}let o=!1;if(e?.ok?(k=e.records,o=!0):!Ae()&&k.length&&(k=[],o=!0),n?.ok){let i=(Array.isArray(n.records)?n.records:[]).filter(r=>r&&r.supported!==!1).map(At);i.length===x.length&&i.every((r,g)=>r.id===x[g].id&&r.revision===x[g].revision)||(o=!0),x=i}else n&&x.length&&(x=[],o=!0);o&&d()}async function _t(e){try{return await navigator.clipboard.writeText(e),!0}catch{}let t=document.createElement("textarea");t.value=e,t.setAttribute("clay",ke),t.style.setProperty("position","fixed","important"),t.style.setProperty("opacity","0","important"),document.body?.append(t),t.select();let n=!1;try{n=document.execCommand?.("copy")===!0}catch{}return t.remove(),n}async function It(e){let t=e.record?e.yours:`${Me(e)}
1
+ import{d as Ae,h as Ve,i as qe}from"./c-TRS6TM6O.js";import{a as Ne,b as Pe}from"./c-4PO3YGDC.js";import{a as Ie,b as Oe}from"./c-PZ4XEPUP.js";import"./c-SFKI6OLM.js";import"./c-Q3XOWZEV.js";import"./c-RHMPKZZ7.js";import{e as ke,f as Ke,g as W,h as Ue,l as re,m as $e,n as p}from"./c-MR75YPRT.js";import"./c-4JZDZFF6.js";import{b as U,c as Z,e as l,f as Ye}from"./c-5RZNFTWD.js";import{b as He}from"./c-PKCCHJ5X.js";import{b as T,c as Fe}from"./c-NUHP2XDB.js";import{a as We,r as V}from"./c-HTLYXCUH.js";import"./c-4ASQPRQL.js";import"./c-GQ6F6IDK.js";import"./c-I2SCCUEW.js";import"./c-5VYOWDTI.js";import{f as Te}from"./c-6Q6RGFBF.js";import"./c-SKMIR5HQ.js";import"./c-WYFDLITL.js";import"./c-UGHH4MB3.js";import"./c-LA2BW7UY.js";import"./c-MFOSMAVM.js";import"./c-LD6UVV5R.js";import"./c-PGSBXHUE.js";import"./c-6IJEVE6B.js";import"./c-QQFHEODI.js";import"./c-IJUK2GPW.js";import{f as _e}from"./c-EDE45NM7.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-U4NTUVDZ.js";import"./c-PWJSJEJU.js";import"./c-XQXZAO7N.js";import"./c-S7LK4KUE.js";import"./c-VG5XIN4T.js";import"./c-2YYDMLNZ.js";import"./c-HA6INT6J.js";import"./c-ICMAOOGK.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var E="light-dark(#D08A1E, #E3A33F)",lt=5e3,st=4e3,dt=500,ct={"another-tab":"in another tab","another-person":"by someone else","an-agent":"by an agent"},pt='<svg viewBox="0 0 12 12" width="12" height="12" aria-hidden="true"><path d="M2.5 9.5h7" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="square"/></svg>',F=(e,t)=>`${e} ${t}${e===1?"":"s"}`,ut="This spot changed again. Review the latest edit or download your copy.",ft="A data value can't be put back from here. Download your copy to keep yours.",m="hidden",P=!1,S=[],J=new Set,M=new Set,h=null,Ee=0,I=null,v=null,le=null,u=null,R=!1,Y=!1,ve=!1,G=new Map,se=0,ae=!1,te=!1,b=null,j=null,L=null,Se=0,D=!1,de=0,ce=null,ne=null,k=[],x=[],oe=!1,pe=null,ue=null,s=null,B=null,q=new Map,z=()=>window.clay?.conflicts||null,Qe=()=>k.reduce((e,t)=>e+t.conflicts.length,0)+x.length,Le=()=>{let e=window.clay?.undo;return e&&typeof e.kept=="function"?e:null},fe=()=>z()?.list().filter(e=>!e.claimedBy&&e.kind!=="apply-incomplete")??[],De=()=>z()?.list().filter(e=>!e.claimedBy&&e.kind==="apply-incomplete")??[];function ze(){return I?"upgraded":h?"refused":fe().length?"replaced":De().length?"failed":k.length||x.length?"recovered":null}function f(e,t,n){let o=Fe(e,t,n);return t[0]==="all:initial"&&T(o,"color-scheme","inherit"),o.setAttribute("clay",ke),o}function _(e,t){return q.set(t,e),e}function ie(){if(!s)return;let e=window.visualViewport,t=e?Math.max(0,window.innerHeight-e.height-e.offsetTop):0;T(s,"bottom",`calc(${16+t}px + env(safe-area-inset-bottom,0px))`),ne&&T(ne,"max-height",`${Math.max(160,(e?.height||window.innerHeight)-32)}px`)}function ht(){s=f("div",["all:initial","position:fixed","left:50%","transform:translateX(-50%)","z-index:2147483001","display:none","flex-direction:column","align-items:center","max-width:calc(100vw - 24px)",`font:14px/1.5 ${U}`,`color:${l.ink}`,"text-align:left"]),s.setAttribute("data-clay-conflict",""),document.body.appendChild(s),window.visualViewport?.addEventListener("resize",ie),window.visualViewport?.addEventListener("scroll",ie)}function d(){if(ae)return;ae=!0;let e=()=>{ae=!1,w()};typeof requestAnimationFrame=="function"?requestAnimationFrame(e):setTimeout(e,16)}function w(){te&&(te=!1,h&&!V()&&(h=null));let e=ze();if(e?m==="hidden"&&(m="bar"):(m="hidden",P=!1,J.clear(),M.clear(),S=[],y(),ce=null,D=!1),!s){if(m==="hidden"&&!b||!document.body)return;ht()}!s.isConnected&&document.body&&document.body.appendChild(s);let t=document.activeElement,n=null;for(let[a,r]of q)r===t&&(n=a);let o=B?B.scrollTop:0;q=new Map,B=null,ne=null,s.replaceChildren(),b?s.append(wt(b)):m==="bar"?s.append(yt(e)):m==="panel"&&s.append(xt(e)),T(s,"display",b||m!=="hidden"?"flex":"none"),B&&(B.scrollTop=o);let i=L||n;i&&q.has(i)&&q.get(i).focus({preventScroll:!0}),b||(L=null),ie(),He(s)}function Xe(){return f("span",["all:initial","display:inline-block","flex:none","width:8px","height:8px","border-radius:50%",`background:${E}`])}function Ze(){return ct[h?.changedBy]||null}function gt(e,t){if(e==="upgraded")return I;if(e==="refused"){let n=Ze();return!n&&h.afterTimeout?"This page changed elsewhere, possibly by your own save that timed out. Your edits here are safe.":`This page changed ${n||"elsewhere"}. Your edits here are safe.`}return e==="failed"?"A sync update did not finish. Your edits here are safe.":e==="recovered"?`${F(t,"change")} replaced before this page loaded ${t===1?"is":"are"} still here.`:`Another edit replaced ${F(t,"change")}.`}function mt(e,t){return e==="upgraded"?I:e==="refused"?`This page changed ${Ze()||"elsewhere"}`:e==="failed"?"A sync update did not finish":e==="recovered"?`${F(t,"change")} kept from before this page loaded`:`Another edit replaced ${F(t,"change")}`}function wt(e){let t=re("div",["display:block",`border-left:3px solid ${l.teal}`,"padding:10px 14px","width:max-content","max-width:calc(100vw - 24px)"]);return t.setAttribute("role","status"),t.textContent=e,t}function yt(e){let t=e==="failed"?De().length:e==="recovered"?Qe():fe().length,n=re("div",["display:flex","flex-wrap:wrap","align-items:center","gap:10px 12px","padding:8px 8px 8px 14px","width:max-content","max-width:calc(100vw - 24px)"]),o=gt(e,t);return o!==ce&&(n.setAttribute("role",e==="refused"?"alert":"status"),ce=o),n.append(Xe(),p("span",[],o)),e==="upgraded"?(n.append(_(W("Reload",{variant:"primary",onClick:()=>window.location.reload()}),"reload")),n):(n.append(_(W("Review",{onClick:Dt}),"review")),n)}function $(e,t,{variant:n="default",onClick:o,push:i=!1}={}){let r=window.innerWidth<480?["flex:1 1 100%",...n==="primary"?["order:-1"]:[]]:i?["margin-left:auto"]:[];return _(W(e,{variant:n,onClick:o,extra:r}),t)}function A(e){return p("div",["display:block","padding:0 16px 12px",`color:${l["ink-2"]}`,"font-size:13.5px"],e)}function xt(e){let t=e==="replaced"?fe():e==="failed"?De():[],n=e==="refused"?fe():t,o=e==="recovered"?Qe():t.length;if(J.size)for(let c of t)J.has(c.id)||M.add(c.id);for(let c of[...M])t.some(N=>N.id===c)||M.delete(c);let i=mt(e,o),a=Math.max(160,(window.visualViewport?.height||window.innerHeight)-32),r=re("div",["display:flex","flex-direction:column","width:520px","max-width:calc(100vw - 24px)",`max-height:${a}px`]);ne=r,r.setAttribute("role","dialog"),r.setAttribute("aria-label",i);let g=f("div",["all:initial","display:flex","align-items:center","gap:8px","padding:12px 12px 8px 16px",`font:14px/1.5 ${U}`,`color:${l.ink}`]),K=_(p("b",["font-weight:600","font-size:14.5px","outline:none"],i),"title");K.setAttribute("tabindex","-1"),g.append(Xe(),K),e==="replaced"&&M.size&&g.append(p("span",[`font:600 10.5px/1 ${Z}`,"letter-spacing:.12em","text-transform:uppercase","padding:3px 6px",`color:color-mix(in srgb, ${l.brass} 80%, ${l.ink})`,`background:${l["brass-soft"]}`],`${M.size} new`));let X=f("span",["all:initial","display:inline-flex","margin-left:auto"]),Be=_(Ue(pt,{label:"Minimize",onClick:Je}),"minimize");if(Be.title="Minimize to the bar. Nothing is accepted until you choose.",X.append(Be),g.append(X),r.append(g),e==="recovered")return Et(r),r;if(e==="refused"){if(r.append(A("Your edits here are safe and not saved yet; nothing will be overwritten until you choose. Their version is not on this page, so there is no list of edits to compare. Keep yours, which saves over theirs, or accept theirs, which reloads the page and drops your unsaved edits.")),n.length&&r.append(A(`${F(n.length,"earlier replaced edit")} ${n.length===1?"is":"are"} also held in this tab. Download my copy includes them.`)),R&&r.append(A("That did not save either. Your edits here are still here.")),D&&r.append(A("Something changed on the page after your first press, so nothing was dropped. Press Accept theirs again if you still want their version.")),v){let c=f("div",["all:initial","display:block","margin:0 16px 12px","padding:8px 10px",`border-left:3px solid ${E}`,`background:color-mix(in srgb, ${E} 14%, transparent)`,`color:${l.ink}`,`font:13px/1.5 ${U}`]);c.append(f("b",["all:initial","font:inherit","font-weight:700","color:inherit"],"This drops your unsaved edits."),document.createTextNode(" Download your copy first if you might want them. Press again to confirm.")),r.append(c)}}else e==="upgraded"?r.append(A("Its layout and code changed with it, so this page stops here. Reload to see the new version.")):e==="failed"?r.append(A("Part of an update from elsewhere could not be applied, so this page may be missing some of it. Your edits here are safe. Download a copy of the page as you had it, or accept to keep the page as it is.")):r.append(A("The page is showing the other edit. This stays until you choose. You can also save a copy of the page as you had it."));let O=f("div",["all:initial","display:flex","flex-wrap:wrap","gap:8px","padding:0 16px 14px"]);if(e==="upgraded")return O.append($("Reload","reload",{variant:"primary",onClick:()=>window.location.reload(),push:!0})),r.append(O),S=[],r;let at=$(ve?"Try again":Y?"Downloaded":"Download my copy","download",{onClick:Bt});if(O.append(at),e==="refused"){let c=$(u==="overwrite"?"Saving\u2026":R?"Try again":"Keep mine","keep",{onClick:Pt});c.setDisabled(u==="overwrite"),O.append(c,$(v?"Yes, drop my edits":"Accept theirs","accept",{variant:"primary",onClick:Ft,push:!0}))}else{if(e==="replaced"){let c=z().hasPendingApply(),N=$(c?"Finishing the incoming edit\u2026":u==="revert"?"Putting back\u2026":"Revert to mine","revert",{onClick:Mt});N.setDisabled(c||u==="revert"),O.append(N)}O.append($("Accept theirs","accept",{variant:"primary",onClick:zt,push:!0}))}if(r.append(O),e==="replaced")if(P)r.append(vt(t));else{let c=f("div",["all:initial","display:flex","align-items:center","gap:8px",`border-top:1px solid ${l.line}`,"padding:8px 10px 8px 16px",`color:${l.muted}`,`font:13px/1.5 ${U}`]),N=f("span",["all:initial","display:inline-flex","margin-left:auto"]);N.append(_(W("See the edits",{small:!0,onClick:et}),"list")),c.append(f("span",["all:initial","font:inherit","color:inherit"],F(t.length,"edit")),N),r.append(c)}S=n.map(c=>c.id);for(let c of t)J.add(c.id);return r}function vt(e){let t=$e(["flex:1 1 auto","margin:0 16px 12px","min-height:0","overflow:auto",`background:${l.sunk}`,`border:1px solid ${l["line-2"]}`]),n=f("div",["all:initial","position:sticky","top:0","z-index:1","display:flex","align-items:center","gap:8px","padding:8px 12px",`background:${l.sunk}`,`border-bottom:1px solid ${l["line-2"]}`,`color:${l.muted}`,`font:600 10.5px/1 ${Z}`,"letter-spacing:.12em","text-transform:uppercase"]),o=f("span",["all:initial","display:inline-flex","margin-left:auto"]);return o.append(_(W("Hide",{small:!0,variant:"quiet",onClick:et}),"list")),n.append(f("span",["all:initial","font:inherit","color:inherit","letter-spacing:inherit","text-transform:inherit"],"Replaced edits"),o),t.append(n),e.forEach((i,a)=>t.append(St(i,a))),B=t,t}function Me(e){let t=e.context?.label||e.name||(e.context?.kind==="entry"?"Entry":"Edit");return e.context?.field?`${t} \xB7 ${e.context.field}`:t}var bt={"content-changed":"the page changed there","structure-changed":"the structure changed there","target-detached":"that part of the page is gone","duplicate-id":"another part of the page now has the same id",protected:"that region keeps its own history",unsupported:"this kind of step cannot be put back"},kt=e=>bt[e]||"the page changed there";function $t(e,t){let n=Array.isArray(e)?e:[];for(let o of n){if(!o||o.kind!=="text"&&o.kind!=="value")continue;let i=t==="redo"?o.after:o.before;if(typeof i=="string"&&i)return{text:i,id:o.target?.id??null}}for(let o of n){if(!o||o.kind!=="add"&&o.kind!=="remove")continue;let i=Array.isArray(o.nodes)?o.nodes.find(a=>typeof a?.html=="string"&&a.html):null;if(i)return{text:Ie(i.html).replace(/\s+/g," ").trim(),id:o.parent?.id??null}}for(let o of n){if(!o)continue;let i=t==="redo"?o.after:o.before;if(typeof i=="string"&&i)return{text:i,id:o.target?.id??null}}return{text:"",id:null}}function Tt(e){if(e==null||typeof document>"u")return"";let t=window.CSS?.escape?window.CSS.escape(String(e)):String(e).replace(/["\\]/g,"\\$&"),n=null;try{n=document.querySelector(`[data-id="${t}"]`)}catch{return""}if(!n)return"";let o=n.matches?.("input, textarea, select")?n.value:null;return(typeof o=="string"?o:n.textContent??"").replace(/\s+/g," ").trim()}function At(e){let t=e?.payload&&typeof e.payload=="object"?e.payload:{},n=String(e?.key??""),o={id:e?.id,revision:e?.revision,record:e,kind:e?.kind??"conflict"};if(n.startsWith("app:"))return{...o,name:typeof t.label=="string"&&t.label?t.label:n.slice(4),sentence:"",yours:typeof t.text=="string"?t.text:"",now:""};let i=t.direction==="redo"?"redo":"undo",g=((Array.isArray(t.context)?t.context:[]).find(X=>typeof X?.label=="string"&&X.label)??null)?.label||typeof t.label=="string"&&t.label||"Edit",K=$t(t.steps,i);return{...o,name:g,sentence:`The ${i} of "${g}" was not applied because ${kt(t.code)}.`,yours:K.text,now:K.id==null?"":Tt(K.id)}}function Ct(e){let t=Le();if(!e.record||typeof t?.reviewActionsFor!="function")return[];try{return(t.reviewActionsFor(e.record)||[]).filter(n=>n&&typeof n.run=="function"&&n.label)}catch{return[]}}var Ge=e=>({before:"",hit:e,after:"",cutBefore:!1,cutAfter:!1});function je(e){let t=p("div",["display:block","padding:8px 12px 10px"]),n=p("div",["display:flex","align-items:center","gap:8px","font-size:12.5px","font-weight:600",`color:${l["ink-2"]}`,"margin-bottom:4px"]);if(n.append(p("span",[],Me(e))),t.append(n),e.sentence&&t.append(p("div",["display:block","font-size:13px",`color:${l["ink-2"]}`],e.sentence)),e.yours){let i=p("div",["display:grid","grid-template-columns:44px 1fr","gap:3px 10px","align-items:start",`font:12.5px/1.5 ${Z}`,...e.sentence?["margin-top:4px"]:[]]);i.append(...he("Yours",Ge(e.yours),{mine:!0})),e.now&&i.append(...he("Now",Ge(e.now),{mine:!1})),t.append(i)}let o=f("div",["all:initial","display:flex","flex-wrap:wrap","gap:8px","margin-top:8px"]);return Ct(e).forEach((i,a)=>{let r=$(i.label,`run:${e.id}:${a}`,{onClick:()=>Nt(e,i,r)});o.append(r)}),o.append($(pe===e.id?"Copied":"Copy",`copy:${e.id}`,{onClick:()=>It(e)})),o.append($("Dismiss",`dismiss:${e.id}`,{onClick:()=>tt(e)})),t.append(o),t}function Et(e){e.append(A(k.length?"These copies were replaced before this page loaded. The page never puts them back on its own. Copy or download the ones you want; dismiss one when you no longer need it.":"These copies were kept because an undo could not be put back or the page set them aside. The page never puts them back on its own. Copy or download the ones you want; dismiss one when you no longer need it.")),oe&&e.append(A("That action did not run. The copy is still here."));let t=$e(["flex:1 1 auto","margin:0 16px 12px","min-height:0","overflow:auto",`background:${l.sunk}`,`border:1px solid ${l["line-2"]}`]);for(let o of k)for(let i of o.conflicts)t.append(je(i));for(let o of x)t.append(je(o));B=t,e.append(t);let n=f("div",["all:initial","display:flex","flex-wrap:wrap","gap:8px","padding:0 16px 14px"]);(k.some(o=>o.root)||x.length)&&n.append($(Y?"Downloaded":"Download my copy","download",{onClick:Ot})),e.append(n),S=[]}function he(e,t,{mine:n}){let o=[p("span",[`color:${l.faint}`,`font-family:${U}`],e)],i=p("span",["display:-webkit-box","-webkit-line-clamp:2","-webkit-box-orient:vertical","overflow:hidden","overflow-wrap:anywhere",...n?[`color:${l.ink}`]:[`color:${l.muted}`]]),a=(t.cutBefore?"\u2026":"")+t.before+t.hit+t.after+(t.cutAfter?"\u2026":"");i.title=a,t.before&&i.append(p("span",[`color:${l.faint}`],(t.cutBefore?"\u2026":"")+t.before));let r=p("span",n?[`background:color-mix(in srgb, ${E} 18%, transparent)`,"padding:0 4px"]:t.before||t.after?["text-decoration:underline",`text-decoration-color:color-mix(in srgb, ${E} 70%, transparent)`,"text-underline-offset:3px"]:[],t.hit||"(empty)");return i.append(r),t.after&&i.append(p("span",[`color:${l.faint}`],t.after+(t.cutAfter?"\u2026":""))),o.push(i),o}function St(e,t){let n=Oe(e),o=p("div",["display:block","padding:8px 12px 10px",...t?[`border-top:1px solid ${l.line}`]:[]]),i=p("div",["display:flex","align-items:center","gap:4px","font-size:12.5px","font-weight:600",`color:${l["ink-2"]}`,"margin-bottom:4px"]);if(i.append(p("span",[],n.name)),n.target&&n.target.isConnected&&i.append(_(Rt(n),`eye:${e.id}`)),o.append(i),n.sentence&&o.append(p("div",["display:block","font-size:13px",`color:${l["ink-2"]}`],n.sentence)),G.has(e.id)&&o.append(p("div",["display:block","font-size:13px","margin-top:4px",`color:${E}`],G.get(e.id))),n.yours){let a=p("div",["display:grid","grid-template-columns:44px 1fr","gap:3px 10px","align-items:start",`font:12.5px/1.5 ${Z}`,...n.sentence?["margin-top:4px"]:[]]);a.append(...he("Yours",n.yours,{mine:!0})),n.now&&a.append(...he("Now",n.now,{mine:!1})),o.append(a)}return o}function Rt(e){let t=["all:initial","color-scheme:inherit","box-sizing:border-box","cursor:pointer","display:inline-grid","place-items:center","width:22px","height:20px",`color:${l.ink}`],n=f("button",t);n.type="button",n.innerHTML=Ye.conflictEye,Ke(n.firstElementChild,16),n.setAttribute("aria-label",`Show ${e.name} on page`),n.title="Show on page";let o=i=>{n.style.cssText="";for(let a of[...t,...i]){let r=a.indexOf(":");n.style.setProperty(a.slice(0,r),a.slice(r+1),"important")}};return n.addEventListener("pointerenter",()=>o([`background:color-mix(in srgb, ${E} 16%, transparent)`])),n.addEventListener("pointerleave",()=>o([])),n.addEventListener("focus",()=>o([`outline:2px solid ${l.brass}`,"outline-offset:1px"])),n.addEventListener("blur",()=>o([])),n.addEventListener("click",()=>Lt(e.target)),n}var C=null,ge=null,me=null;function we(){clearTimeout(ge),window.removeEventListener("scroll",ee,!0),window.removeEventListener("resize",ee),C?.remove(),C=null,me=null}function ee(){if(!C||!me)return;let e=me.getBoundingClientRect();T(C,"left",`${e.left}px`),T(C,"top",`${e.top}px`),T(C,"width",`${e.width}px`),T(C,"height",`${e.height}px`)}function Lt(e){if(we(),!e||!e.isConnected)return;let n=!!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches?"instant":"smooth",o=s?.getBoundingClientRect().top??0,i=s&&o>0?Math.max(0,window.innerHeight-o):0;if(!i)e.scrollIntoView?.({block:"center",behavior:n});else{e.scrollIntoView?.({block:"center",behavior:"instant"});let a=e.getBoundingClientRect(),r=window.innerHeight-i,g=a.height>r-24?a.top-12:a.top+a.height/2-r/2;window.scrollBy?.({top:g,behavior:n})}me=e,C=f("div",["all:initial","color-scheme:inherit","position:fixed","pointer-events:none","z-index:2147483001",`outline:2px solid ${E}`,"outline-offset:3px",`background:color-mix(in srgb, ${E} 14%, transparent)`]),document.body.appendChild(C),ee(),window.addEventListener("scroll",ee,!0),window.addEventListener("resize",ee),ge=setTimeout(we,2500)}function Dt(){I||(m="panel",L="title",w())}function Je(){we(),m="bar",y(),L="review",w()}function et(){P=!P,P&&M.clear(),w()}function zt(){let e=z(),t=S.filter(n=>{let o=e?.get(n);return o&&!o.claimedBy});e&&t.length&&e.acknowledge(t,{reason:"accepted"}),m=ze()?"bar":"hidden",L="review",d()}async function Mt(){let e=z();if(u||!e||e.hasPendingApply())return;let t=S.filter(r=>{let g=e.get(r);return g&&!g.claimedBy});if(!t.length)return;u="revert",w();let n=!0,o=r=>{n=!!s?.contains(r.target)};document.addEventListener("focus",o,!0);let i;try{let{revertConflicts:r}=await import("./c-LSVN3OLG.js");i=await r(t)}catch(r){console.error("[clay] Revert to mine did not finish",r),i={revertedIds:[],blockedIds:t,saveResult:null}}finally{document.removeEventListener("focus",o,!0)}u=null;for(let r of i.blockedIds)G.set(r,z()?.get(r)?.kind==="json"?ft:ut);m=ze()?"bar":"hidden",L=n?"review":null;let a=i.saveResult&&(i.saveResult.ok||i.saveResult.msg==="Save already in progress");i.revertedIds.length&&a?be(`Put back ${F(i.revertedIds.length,"change")}. Saving.`):w()}var Q=null;async function Bt(){let e=z(),t=h?e?.list()??[]:S.map(o=>e?.get(o)).filter(Boolean),n=await Pe(t,{refused:!!h});ve=!n,Y=n,clearTimeout(Q),n&&(Q=setTimeout(()=>{Y=!1,d()},1200)),w()}async function H(){let e=null;if(Ae())try{e=await Ve()}catch{e=null}let t=Le(),n=null;if(t)try{n=await t.kept()}catch{n=null}let o=!1;if(e?.ok?(k=e.records,o=!0):!Ae()&&k.length&&(k=[],o=!0),n?.ok){let i=(Array.isArray(n.records)?n.records:[]).filter(r=>r&&r.supported!==!1).map(At);i.length===x.length&&i.every((r,g)=>r.id===x[g].id&&r.revision===x[g].revision)||(o=!0),x=i}else n&&x.length&&(x=[],o=!0);o&&d()}async function _t(e){try{return await navigator.clipboard.writeText(e),!0}catch{}let t=document.createElement("textarea");t.value=e,t.setAttribute("clay",ke),t.style.setProperty("position","fixed","important"),t.style.setProperty("opacity","0","important"),document.body?.append(t),t.select();let n=!1;try{n=document.execCommand?.("copy")===!0}catch{}return t.remove(),n}async function It(e){let t=e.record?e.yours:`${Me(e)}
2
2
 
3
3
  Yours:
4
4
  ${e.yours}
@@ -1 +1 @@
1
- import{d as i}from"./c-RBPZNU2D.js";import{f as l}from"./c-DLBX4JCJ.js";import{a as r}from"./c-BPF2NSPV.js";var e=r,a=r,s=!1,n=0;function k(){return e}function w(){return s}function p(t){e=typeof t=="string"&&t!==""?t:null,n++,a=e}function L(){return a}function g(){a=null}function m(){p(null)}function c(t){typeof t.spec=="number"&&(s=t.extensions.includes("conditional"))}async function b(){return c(await i()),s}async function y({fresh:t=!1,clearIfMissing:d=t}={}){let f=n,u=await i({fresh:t});if(c(u),n!==f||r&&!(t&&d))return e;let o=u.document?.etag;return typeof o=="string"&&o!==""?(e=o,n++):d&&(e=null,n++),e}document.addEventListener("clay:sync-applied",t=>{t.detail?.source==="disk"&&(typeof t.detail.etag=="string"&&t.detail.etag||g())});document.addEventListener("clay:sync-applied",t=>{l&&t.detail?.source==="disk"&&(typeof t.detail.etag=="string"&&t.detail.etag||(m(),y({fresh:!0})))});export{k as a,w as b,p as c,L as d,g as e,m as f,b as g,y as h};
1
+ import{d as i}from"./c-QQFHEODI.js";import{f as l}from"./c-EDE45NM7.js";import{a as r}from"./c-BPF2NSPV.js";var e=r,a=r,s=!1,n=0;function k(){return e}function w(){return s}function p(t){e=typeof t=="string"&&t!==""?t:null,n++,a=e}function L(){return a}function g(){a=null}function m(){p(null)}function c(t){typeof t.spec=="number"&&(s=t.extensions.includes("conditional"))}async function b(){return c(await i()),s}async function y({fresh:t=!1,clearIfMissing:d=t}={}){let f=n,u=await i({fresh:t});if(c(u),n!==f||r&&!(t&&d))return e;let o=u.document?.etag;return typeof o=="string"&&o!==""?(e=o,n++):d&&(e=null,n++),e}document.addEventListener("clay:sync-applied",t=>{t.detail?.source==="disk"&&(typeof t.detail.etag=="string"&&t.detail.etag||g())});document.addEventListener("clay:sync-applied",t=>{l&&t.detail?.source==="disk"&&(typeof t.detail.etag=="string"&&t.detail.etag||(m(),y({fresh:!0})))});export{k as a,w as b,p as c,L as d,g as e,m as f,b as g,y as h};
@@ -1 +1 @@
1
- import"./c-VHNSBD2M.js";var l=(e,n)=>Object.assign(new Error(`clayjs: ${e}`),{code:n}),u=(e,n)=>!e||n.seq===null||e.seq===null||n.seq>e.seq?n:e;function a({stream:e,apply:n,retire:f,yieldArticle:i=()=>!1,reclaimArticle:s=()=>!1}){let t=null,r=!1;e.adopt({onSnapshot:o=>(t=u(t,o),!0)});let d=()=>{let o=t;return t=null,o};return{get represented(){return e.represented},get held(){return t??e.represented},yieldArticle(){return r||!i()?!1:(r=!0,!0)},reclaimArticle(){return!r||!s()?!1:(r=!1,!0)},reconcile(){let o=d();return o&&!n(o)?Promise.reject(l("the switch could not apply the saved file","load-failed")):Promise.resolve()},resume(){e.adopt({onSnapshot:n});let o=d();o&&n(o)},commit(){if(!r){let o=d();if(o&&!n(o))return!1}return e.represented.bytes===null?!1:(e.stop(),f())}}}async function c({stream:e,options:n,apply:f,retire:i,yieldArticle:s=()=>!1,reclaimArticle:t=()=>!1}){if(e)return a({stream:e,apply:f,retire:i,yieldArticle:s,reclaimArticle:t});let r=await import("./sync/live-sync-M2PP2IWY.js").then(({liveSync:d})=>d.prepareHandoff(n));return{get represented(){return r.represented},get held(){return r.held},yieldArticle:s,reclaimArticle:t,reconcile:()=>r.reconcile(),resume:()=>r.resume(),commit:()=>r.commit()&&i()}}async function p(e,{signal:n,deadline:f=15e3}={}){let i=Date.now()+f;for(;e._morphInFlight;){if(n?.aborted)throw e._handoffHeld=!1,l("the switch was cancelled","aborted");if(Date.now()>=i)throw e._handoffHeld=!1,l("the apply did not settle","timeout");await new Promise(t=>setTimeout(t,1))}let s=()=>e._pendingHtml!=null||e._pendingExternal!=null;return{get represented(){return e._represented},get held(){let t=e._represented;return e._pendingHtml!=null&&(t=u(t,{bytes:e._pendingHtml,etag:e._pendingEtag??null,seq:e._pendingSeq??null})),e._pendingExternal&&(t=u(t,{bytes:e._pendingExternal.html,etag:e._pendingExternal.etag??null,seq:e._pendingExternal.seq??null})),t},async reconcile(){if(!(!e._handoff||e.isDestroyed)){for(let t=0;t<8;t++){if(e._morphInFlight){await new Promise(r=>setTimeout(r,1));continue}if(!s())return;await e._runPending()}if(s())throw l("the held frame could not be applied","load-failed")}},resume(){e._handoff&&(e._handoff=null,e._handoffHeld=!1,e._scheduleNextFrame())},commit(){return e._represented.bytes?(e._handoff=null,e._handoffHeld=!1,e.stop(),!0):!1}}}export{p as engineHandoff,c as readerHandoff};
1
+ import"./c-VHNSBD2M.js";var l=(e,n)=>Object.assign(new Error(`clayjs: ${e}`),{code:n}),u=(e,n)=>!e||n.seq===null||e.seq===null||n.seq>e.seq?n:e;function a({stream:e,apply:n,retire:f,yieldArticle:i=()=>!1,reclaimArticle:s=()=>!1}){let t=null,r=!1;e.adopt({onSnapshot:o=>(t=u(t,o),!0)});let d=()=>{let o=t;return t=null,o};return{get represented(){return e.represented},get held(){return t??e.represented},yieldArticle(){return r||!i()?!1:(r=!0,!0)},reclaimArticle(){return!r||!s()?!1:(r=!1,!0)},reconcile(){let o=d();return o&&!n(o)?Promise.reject(l("the switch could not apply the saved file","load-failed")):Promise.resolve()},resume(){e.adopt({onSnapshot:n});let o=d();o&&n(o)},commit(){if(!r){let o=d();if(o&&!n(o))return!1}return e.represented.bytes===null?!1:(e.stop(),f())}}}async function c({stream:e,options:n,apply:f,retire:i,yieldArticle:s=()=>!1,reclaimArticle:t=()=>!1}){if(e)return a({stream:e,apply:f,retire:i,yieldArticle:s,reclaimArticle:t});let r=await import("./sync/live-sync-Z64YREWQ.js").then(({liveSync:d})=>d.prepareHandoff(n));return{get represented(){return r.represented},get held(){return r.held},yieldArticle:s,reclaimArticle:t,reconcile:()=>r.reconcile(),resume:()=>r.resume(),commit:()=>r.commit()&&i()}}async function p(e,{signal:n,deadline:f=15e3}={}){let i=Date.now()+f;for(;e._morphInFlight;){if(n?.aborted)throw e._handoffHeld=!1,l("the switch was cancelled","aborted");if(Date.now()>=i)throw e._handoffHeld=!1,l("the apply did not settle","timeout");await new Promise(t=>setTimeout(t,1))}let s=()=>e._pendingHtml!=null||e._pendingExternal!=null;return{get represented(){return e._represented},get held(){let t=e._represented;return e._pendingHtml!=null&&(t=u(t,{bytes:e._pendingHtml,etag:e._pendingEtag??null,seq:e._pendingSeq??null})),e._pendingExternal&&(t=u(t,{bytes:e._pendingExternal.html,etag:e._pendingExternal.etag??null,seq:e._pendingExternal.seq??null})),t},async reconcile(){if(!(!e._handoff||e.isDestroyed)){for(let t=0;t<8;t++){if(e._morphInFlight){await new Promise(r=>setTimeout(r,1));continue}if(!s())return;await e._runPending()}if(s())throw l("the held frame could not be applied","load-failed")}},resume(){e._handoff&&(e._handoff=null,e._handoffHeld=!1,e._scheduleNextFrame())},commit(){return e._represented.bytes?(e._handoff=null,e._handoffHeld=!1,e.stop(),!0):!1}}}export{p as engineHandoff,c as readerHandoff};
@@ -1 +1 @@
1
- import{a as r}from"./c-WYFDLITL.js";import{a as p}from"./c-LA2BW7UY.js";import{f as u}from"./c-DLBX4JCJ.js";import{n as d,o as l}from"./c-ICMAOOGK.js";var n=0,g=0,c=!1,m=!1,y=!1,i=!1;function o(){!u||i||(i=!0,queueMicrotask(()=>{if(i=!1,typeof document>"u")return;let e=C();if(e===y)return;y=e;let t=document.documentElement;e?t.setAttribute("unsaved","true"):t.removeAttribute("unsaved"),document.dispatchEvent(new CustomEvent(e?"clay:dirty":"clay:clean"))}))}var T=`input${r}, textarea${r}, select${r}`,h=`${d}, ${l}`,a=new WeakMap;function v(){let e=[];for(let t of document.querySelectorAll(T))t.closest(h)||e.push(t);return e}function E(e){let t=e.target;!t||t.nodeType!==1||(t.matches("input, textarea, select")||t.isContentEditable)&&(t.closest(h)||(n++,o()))}function x(){m||(m=!0,p.onAnyChange({omitChangeDetails:!0,require:"dirty"},()=>{c||(n++,o())}),document.addEventListener("input",E,!0),document.addEventListener("change",E,!0))}function L(){c=!0}function k(){c=!1}function f(e){return e instanceof HTMLSelectElement?Array.from(e.selectedOptions,t=>t.value).join("\0"):e instanceof HTMLInputElement&&(e.type==="checkbox"||e.type==="radio")?e.checked?"1":"0":e.value}function M(e){return e instanceof HTMLSelectElement?Array.from(e.options).every(t=>t.selected===t.defaultSelected):e instanceof HTMLInputElement?e.type==="checkbox"||e.type==="radio"?e.checked===e.defaultChecked:e.value===e.defaultValue:e instanceof HTMLTextAreaElement?e.hasAttribute("data-value")?e.value===e.getAttribute("data-value"):e.value===e.defaultValue:!0}function S(){for(let e of v()){let t=f(e);if(a.get(e)!==t){if(M(e)){a.set(e,t);continue}return!0}}return!1}function C(){return n>g||S()}function D(){return n}function O(){let e=[];for(let t of v())e.push([t,f(t)]);return{gen:n,probe:e}}function b(){n++,o()}function H(e){if(e){n===e.gen&&(g=e.gen);for(let[t,s]of e.probe)f(t)===s&&a.set(t,s);o()}}typeof document<"u"&&u&&x();typeof window<"u"&&(window.clay=window.clay||{},window.clay.markDirty=b);export{x as a,L as b,k as c,C as d,D as e,O as f,b as g,H as h};
1
+ import{a as r}from"./c-WYFDLITL.js";import{a as p}from"./c-LA2BW7UY.js";import{f as u}from"./c-EDE45NM7.js";import{n as d,o as l}from"./c-ICMAOOGK.js";var n=0,g=0,c=!1,m=!1,y=!1,i=!1;function o(){!u||i||(i=!0,queueMicrotask(()=>{if(i=!1,typeof document>"u")return;let e=C();if(e===y)return;y=e;let t=document.documentElement;e?t.setAttribute("unsaved","true"):t.removeAttribute("unsaved"),document.dispatchEvent(new CustomEvent(e?"clay:dirty":"clay:clean"))}))}var T=`input${r}, textarea${r}, select${r}`,h=`${d}, ${l}`,a=new WeakMap;function v(){let e=[];for(let t of document.querySelectorAll(T))t.closest(h)||e.push(t);return e}function E(e){let t=e.target;!t||t.nodeType!==1||(t.matches("input, textarea, select")||t.isContentEditable)&&(t.closest(h)||(n++,o()))}function x(){m||(m=!0,p.onAnyChange({omitChangeDetails:!0,require:"dirty"},()=>{c||(n++,o())}),document.addEventListener("input",E,!0),document.addEventListener("change",E,!0))}function L(){c=!0}function k(){c=!1}function f(e){return e instanceof HTMLSelectElement?Array.from(e.selectedOptions,t=>t.value).join("\0"):e instanceof HTMLInputElement&&(e.type==="checkbox"||e.type==="radio")?e.checked?"1":"0":e.value}function M(e){return e instanceof HTMLSelectElement?Array.from(e.options).every(t=>t.selected===t.defaultSelected):e instanceof HTMLInputElement?e.type==="checkbox"||e.type==="radio"?e.checked===e.defaultChecked:e.value===e.defaultValue:e instanceof HTMLTextAreaElement?e.hasAttribute("data-value")?e.value===e.getAttribute("data-value"):e.value===e.defaultValue:!0}function S(){for(let e of v()){let t=f(e);if(a.get(e)!==t){if(M(e)){a.set(e,t);continue}return!0}}return!1}function C(){return n>g||S()}function D(){return n}function O(){let e=[];for(let t of v())e.push([t,f(t)]);return{gen:n,probe:e}}function b(){n++,o()}function H(e){if(e){n===e.gen&&(g=e.gen);for(let[t,s]of e.probe)f(t)===s&&a.set(t,s);o()}}typeof document<"u"&&u&&x();typeof window<"u"&&(window.clay=window.clay||{},window.clay.markDirty=b);export{x as a,L as b,k as c,C as d,D as e,O as f,b as g,H as h};
@@ -1,4 +1,4 @@
1
- import{a as Tt,c as Rt,d as Pt,e as $t,f as be,g as Ct}from"./c-JKZJIUIP.js";import{a as ee}from"./c-TCCA5BZN.js";import{a as T,b as Fe,c as Ye,d as Be,e as ke,f as Mt,g as ze,h as Lt,i as G,j as Ae,k as R,l as _t,m as qt,n as Ve,o as ue}from"./c-3LDGIBMN.js";import{d as jt}from"./c-57XDY6HC.js";import{e as Ot}from"./c-LZJPNR2W.js";import{F as Je,K as Ue,g as Et,r as Ie}from"./c-2YIJ6ZA6.js";import{a as We}from"./c-I2SCCUEW.js";import{f as De,g as He,k as kt,l as At,m as St,y as xt}from"./c-HSNGLIFB.js";import{a as vt}from"./c-LD6UVV5R.js";import{a as Ne}from"./c-PGSBXHUE.js";import{a as je,c as bt}from"./c-RXTPKCMC.js";import{e as we,k as wt}from"./c-RBPZNU2D.js";import{b as mt,f as Z}from"./c-DLBX4JCJ.js";import{f as gt,k as yt}from"./c-PWJSJEJU.js";var gn=new Set(["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"]),yn=/^(0|[1-9]\d*)$/,U=e=>e!==null&&typeof e=="object",te=e=>Array.isArray(e)?"a list":"an object";function J(e,t){let r=e;for(let o of t){if(!U(r))return;Array.isArray(r)?r=r[Number(o)]:r=Object.prototype.hasOwnProperty.call(r,o)?r[o]:void 0}return r}var Se=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),vn=(e,t)=>R(e)===R(t);function Nt(e,t){let r=[];try{for(let o of t){let n=Mt(e,o);n&&(r.push(n),e=n.root)}return r}catch{return Ke(r),null}}function Ke(e){let t;for(let r=e.length-1;r>=0;r--)t=ze(e[r]);return t}function wn(e,t,r){let o=[];for(let n of e){if(n.at===null||Array.isArray(n.at))return null;let s=o.find(a=>a.path.length===n.path.length&&G(a.path,n.path));if(s){if(s.removed&&n.kind!=="remove")return null;n.kind==="remove"&&(s.removed=!0);continue}if(o.some(a=>G(a.path,n.path)))return null;o.push({path:n.path,at:n.at,key:n.key,had:n.kind!=="add",old:n.old,removed:n.kind==="remove"})}for(let n of o){if(n.has=Se(n.at,n.key),n.had&&n.has&&n.removed||(n.into=J(r,n.path.slice(0,-1)),!U(n.into)||Array.isArray(n.into)||Se(n.into,n.key)!==n.had))return null;let s=n.path.slice(0,-1);for(let a of t){let i=a.op.path;if(G(n.path,i)||a.op.op==="del"&&i.length<=n.path.length&&G(i.slice(0,-1),n.path)&&Array.isArray(J(r,i.slice(0,-1))))return null;if(!n.had&&n.has&&i.length>s.length&&G(s,i)){let c=i[s.length];if(i.length===s.length+1&&a.op.op==="del"||!Se(n.at,String(c)))return null}}}return o}function bn(e,t){if(t.op==="set"){let r=J(e,t.path);if(U(r)&&U(t.value)&&Array.isArray(r)===Array.isArray(t.value)){Ae(r,T(t.value));return}}Be(e,t)}function Ge({name:e,value:t,ephemeral:r=!1}){if(!U(t))throw new TypeError(`clay.live("${e}"): the tag must hold a JSON object or list`);let o=T(t),n=null,s=T(t),a=!0,i=[],c=1,d=null,h="file",w=new Set,A=new Set,b=new Set,x=new Set,E=new Set,v=new WeakMap;function O(l,u){let f={source:l,ops:u};for(let g of[...w])try{g(f)}catch(S){console.error(`clay.live("${e}"): a change listener threw`,S)}}function I(){let l=T(o),u=[];for(let f of i)try{Ye(l,f.op),l=Be(l,f.op),u.push(f)}catch{}i=u,Ae(s,l),a=!0}function N(l){for(let u of[...b])try{u(l)}catch(f){console.error(`clay.live("${e}"): a rebase listener threw`,f)}}function se(l,{source:u="remote",confirmed:f=0,through:g,drop:S,dropIds:$,frame:K=null,room:L=null,cause:ce=null}={}){if(!U(l)||te(l)!==te(s))return console.warn(`clay.live("${e}"): ignored an incoming value that is not ${te(s)}`),!1;L&&(n=L);let me=T(s),ge=o;if(o=T(l),S)i=i.filter(_=>_.id<S[0]||_.id>S[1]);else if($){let _=new Set($);i=i.filter(ye=>!_.has(ye.id))}else i=g===void 0?i.slice(f):i.filter(_=>_.id>g);return I(),N({source:u,frame:K,room:L,cause:ce,prev:ge,before:_=>J(ge,_),next:o}),_t(me,s)||O(u,null),!0}function ie(l){let u=T(o);for(let f=l.length-1;f>=0;f--){let g=l[f];ze({...g,at:J(u,g.path.slice(0,-1))})}return u}function ae(l){for(let u of[...A])try{u(l)}catch(f){console.error(`clay.live("${e}"): a transport threw`,f)}O("local",l)}function C(l){let u=l.map(Fe);for(let f of u)if(f.path.length===0&&te(f.value)!==te(s))throw new TypeError(`clay.live("${e}"): the whole value must stay ${te(s)}`);u.length===1?Ye(s,u[0]):ke(T(s),u);for(let f of u)bn(s,f);i.push(...u.map(f=>({id:c++,op:f}))),d?d.push(...u):ae(u)}function B(l,u){let f=v.get(l);f||v.set(l,f=new Map);let g=JSON.stringify(u),S=f.get(g);return S||(S=new Proxy(l,Ce(u)),f.set(g,S)),S}function Ce(l){return{get(u,f){if(Array.isArray(u)&&gn.has(f))return(...S)=>{let $=T(u),K=Array.prototype[f].apply($,S);return C([{op:"set",path:l,value:$}]),K===$?B(u,l):K};let g=u[f];return typeof f=="symbol"||!U(g)||!Object.prototype.hasOwnProperty.call(u,f)?g:B(g,[...l,Array.isArray(u)?Number(f):f])},set(u,f,g){if(typeof f=="symbol")throw new TypeError(`clay.live("${e}"): symbol keys are not JSON`);if(Array.isArray(u)){if(f==="length"){let S=T(u);return S.length=g,C([{op:"set",path:l,value:S}]),!0}if(!yn.test(f))throw new TypeError(`clay.live("${e}"): "${f}" is not a list index`);return C([{op:"set",path:[...l,Number(f)],value:g}]),!0}return C([{op:"set",path:[...l,f],value:g}]),!0},deleteProperty(u,f){if(typeof f=="symbol")return!0;if(Array.isArray(u))throw new TypeError(`clay.live("${e}"): remove a list item with splice`);return C([{op:"del",path:[...l,f]}]),!0},defineProperty(){throw new TypeError(`clay.live("${e}"): assign values instead of defining properties`)},setPrototypeOf(){return!1},preventExtensions(){return!1}}}let le=B(s,[]),Q,Me=new Promise(l=>{Q=l}),y=Object.freeze({name:e,ephemeral:r,ready:Me,get data(){return le},get status(){return{mode:h}},set(l,u){C([{op:"set",path:l,value:u}])},delete(l){C([{op:"del",path:l}])},add(l,u=1){C([{op:"add",path:l,n:u}])},update(l){if(typeof l!="function")throw new TypeError(`clay.live("${e}"): update() takes a function`);if(d)return l(le);d=[];let u=i.length,f=c,g;try{if(g=l(le),g&&typeof g.then=="function")throw new TypeError(`clay.live("${e}"): update() runs synchronously; do async work before calling it`)}catch($){throw d=null,i.length=u,c=f,I(),$}let S=Lt(d);return d=null,i.length=u,c=f,i.push(...S.map($=>({id:c++,op:$}))),S.length&&ae(S),g},on(l,u){if(l!=="change")throw new TypeError(`clay.live("${e}"): the only event is "change"`);if(typeof u!="function")throw new TypeError(`clay.live("${e}"): on() takes a function`);return w.add(u),()=>w.delete(u)},off(l,u){w.delete(u)},toJSON(){return T(s)}});return Q(y),{handle:y,name:e,ephemeral:r,get value(){return s},get authoritative(){return o},get room(){return n},get pending(){return i.map(l=>l.op)},pendingEntries(){return i.map(l=>({id:l.id,op:l.op}))},get mark(){return c-1},setMode(l){h=l,l!=="fast"&&(n=null)},onLocal(l){return A.add(l),()=>A.delete(l)},confirm(l){let u=i.filter(f=>f.id<=l);if(u.length){try{o=ke(T(o),u.map(f=>f.op))}catch{o=T(s),a=!1}i=i.filter(f=>f.id>l);for(let f of[...x])try{f({through:l})}catch(g){console.error(`clay.live("${e}"): a confirmation listener threw`,g)}}},onConfirm(l){return x.add(l),()=>x.delete(l)},rebase:se,checkOps(l){let u;try{u=l.map(Fe)}catch{return null}let f=Nt(o,u);return f?(Ke(f),u):null},rebaseOps(l,{source:u="remote",confirmed:f=0,through:g,frame:S=null,room:$=null,cause:K=null}={}){let L=Nt(o,l);if(!L)return!1;let ce=g===void 0?i.slice(f):i.filter(k=>k.id>g),me=i.length-ce.length,ge=L.some(k=>k.at===null),_=a&&!ge&&me===l.length&&l.every((k,D)=>vn(k,i[D].op)),ye=a&&!_&&me===0?wn(L,ce,s):null;if(!_&&!ye)return Ke(L),se(ke(T(o),l),{source:u,confirmed:f,through:g,frame:S,room:$,cause:K});i=ce;let Le=!1;for(let k of ye??[]){let D=k.into;if(k.has){let ht=k.at[k.key];(!k.had||R(k.old)!==R(ht))&&(Le=!0);let qe=k.had?D[k.key]:void 0,ve=T(ht),mn=U(qe)&&U(ve)&&Array.isArray(qe)===Array.isArray(ve);Object.defineProperty(D,k.key,{value:mn?Ae(qe,ve):ve,enumerable:!0,writable:!0,configurable:!0})}else k.had&&(Le=!0,delete D[k.key])}let dn=null,_e=()=>dn??=ie(L),pn=L.some(k=>Array.isArray(k.at)&&k.kind!=="put"),hn=k=>{if(pn)return J(_e(),k);for(let D of L)if(G(D.path,k))return D.path.length>k.length?J(_e(),k):J(D.old,k.slice(D.path.length));return J(o,k)};return $&&(n=$),N({source:u,frame:S,room:$,cause:K,get prev(){return _e()},before:hn,next:o}),Le&&O(u,null),!0},onRebase(l){return b.add(l),()=>b.delete(l)},onDelivery(l){return E.add(l),()=>E.delete(l)},deliver(l){for(let u of[...E])try{u(l)}catch(f){console.error(`clay.live("${e}"): a delivery listener threw`,f)}}}}function Dt({needsSave:e,blocked:t,save:r,saveNow:o,now:n=()=>Date.now(),setTimer:s=setTimeout,clearTimer:a=clearTimeout}){let i=null,c=null,d=!1,h=!1,w=0;function A(v){let O=v&&!v.ok&&v.msgType==="skipped";return w=v?.ok||O?0:n()+8e3,O?1e3:8e3}function b(v){i=v,c!==null&&a(c),c=s(E,Math.max(0,v-n()))}function x(){c!==null&&a(c),c=null,i=null}async function E(){if(c=null,i=null,!e())return;if(t()){b(n()+1e3);return}d=!0;let v=null;try{v=await r()}catch{v=null}finally{d=!1}let O=A(v);e()&&b(n()+O)}return{changed(){i===null&&!d&&b(n()+8e3)},flush(){d||!e()||t()||(x(),d=!0,h=!0,Promise.resolve().then(o).catch(()=>null).then(v=>{d=!1,h=!1;let O=A(v);e()&&b(n()+O)}))},soon(){if(d)return;let v=Math.max(n(),w);(i===null||v<i)&&b(v)},within(v){if(d)return;let O=Math.max(n()+v,w);(i===null||O<i)&&b(O)},get flushing(){return h},get deadline(){return i}}}var ne=[0,1e4,3e4],kn=6e3,An=2;async function Sn(e){let t=globalThis.crypto&&globalThis.crypto.subtle;if(!t)return null;try{let r=new TextEncoder().encode(String(e)),o=await t.digest("SHA-256",r),n=new Uint8Array(o),s="";for(let a=0;a<n.length;a+=1)s+=n[a].toString(16).padStart(2,"0");return s}catch{return null}}function xn(e){let t=[];for(let r of e||[]){let o=r&&r.saveId;if(typeof o=="string"&&o&&!t.includes(o)&&t.push(o),t.length>=An)break}return t}function En(e,t,r){return!!(e&&typeof e=="object"&&e.saveId===t&&e.requestHash===r&&e.status==="applied")}function Ht({query:e,digest:t=Sn,now:r=()=>Date.now(),setTimer:o=setTimeout,clearTimer:n=clearTimeout}={}){function s({captureId:a,html:i,attempts:c,initialOutcome:d,startedAt:h,onApplied:w,onUnknown:A}){let b=h+45e3,x=xn(c),E=new Set,v=new Set,O=i,I=null,N=!1;function se(y,l){try{typeof y=="function"&&y(l)}catch(u){console.error("clayjs: save-history callback failed:",u)}}function ie(){N=!0,O=null;for(let y of E)n(y);E.clear();for(let y of v)y.abort();v.clear()}function ae(y,l){N||(ie(),se(w,{captureId:a,saveId:y,requestHash:l}))}function C(y){N||(ie(),se(A,{captureId:a,reason:y}))}function B(y,l){let u=null;return u=o(()=>{u!==null&&E.delete(u),y()},Math.max(0,l)),E.add(u),u}function Ce(y){y!==null&&(n(y),E.delete(y))}async function le(y){if(N)return;let l=b-r();if(l<=0)return;let u=new AbortController;v.add(u);let f=B(()=>u.abort(),Math.min(kn,l)),g=null;try{g=await e({saveId:y,requestHash:I,signal:u.signal})}catch{g=null}finally{Ce(f),v.delete(u)}N||En(g,y,I)&&ae(y,I)}function Q(){if(!N&&!(r()>=b))for(let y of x)le(y)}async function Me(){let y=null;try{y=await t(O)}catch{y=null}if(O=null,N)return;if(typeof y!="string"||!y){C("unavailable");return}if(I=y,d&&typeof d=="object"&&d.status==="applied"&&d.requestHash===I&&x.includes(d.saveId)){ae(d.saveId,I);return}let l=r()-h;if(l>=45e3){C("expired");return}let u=-1;for(let f=0;f<ne.length;f+=1)ne[f]<=l&&(u=f);if(u<0){for(let f=0;f<ne.length;f+=1)B(Q,h+ne[f]-r());return}Q();for(let f=u+1;f<ne.length;f+=1)B(Q,h+ne[f]-r())}return B(()=>C("expired"),b-r()),Me(),{cancel(){ie()}}}return{start:s}}var On="/_/sync/data";function It(){return new URL(On,window.location.origin)}async function Tn(e,t){let r=It();r.searchParams.set("client-id",e);try{let o=await fetch(r.href,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json","Document-URL":window.location.href,[Ne]:String(1)},body:JSON.stringify(t)}),n=null;try{n=await o.json()}catch{}let s=Number(o.headers?.get?.("Retry-After"))||0;return{status:o.status,body:n,retryAfter:s}}catch{return{status:0,body:null,retryAfter:0}}}async function Rn(e,t=null,{signal:r}={}){let o=It();e&&o.searchParams.set("client-id",e),t&&typeof t.epoch=="string"&&Number.isInteger(t.seq)&&o.searchParams.set("since",`${t.epoch}:${t.seq}`),o.searchParams.set("compaction","1");try{let n=await fetch(o.href,{credentials:"same-origin",cache:"no-store",headers:{"Document-URL":window.location.href,[Ne]:String(1)},signal:r});if(!n.ok){let a=null;try{a=await n.json()}catch{}return{status:n.status,code:a?.code??null,retryAfter:Number(n.headers?.get?.("Retry-After"))||0}}let s=await n.json();return s&&typeof s.epoch=="string"&&s.conn===null?null:s}catch{return null}}function Jt(){return{start(e){return Ot({open(t){t.lane==="live"&&e.open(t)},close:()=>e.close(),event(t,r){t==="data"?e.frame(r):t==="data-state"?e.state(r):t==="data-writer"&&e.writer(r)}})},send:Tn,fetchState:Rn}}var $n=()=>Promise.all([import("./c-IXO7EI2Q.js"),import("./c-XUZMRQ7O.js")]).then(([e,t])=>({createFastLane:e.createFastLane,localTransport:t.localTransport,localLaneSupported:t.localLaneSupported})),Cn=/^[A-Za-z0-9_.:-]{1,64}$/,m=new Map,Gt="save_"+[...crypto.getRandomValues(new Uint32Array(4))].map(e=>e.toString(16).padStart(8,"0")).join(""),Qe=0,Mn=0,Ln=45e3;function rt(e){let t=ue(e.getAttribute("live-at"));if(!t||t.hash!==Zn(e.textContent))return null;let r=e.getAttribute("live-by"),o=r===null?null:be(r);return r!==null&&!o?null:o&&o.v!==2?{disk:!0}:{epoch:t.epoch,seq:t.seq,frames:Pt(o),ancestors:$t(o)}}function _n(e,t){let r=e.leftAt;if(!r||r.disk)return null;let o=p?.pendingFrames(e.store.name,r,{reserve:t})??{frames:[],complete:!0};if(!o.complete)return null;let n=Tt(r.frames??[],o.frames),s=r.ancestors??[],a=R(e.store.value),i=JSON.stringify([r.epoch,r.seq,n,s,e.store.mark,a]);if(e.capture?.key===i)return e.capture.value;let c={v:2,frames:n,ancestors:s,capture:[Gt,Qe+1]},d=Ct(c),h=d?{at:Ve(r.epoch,r.seq,a),by:d}:null;return e.capture={key:i,value:h},h}var V=new Map,F=null,q=null,H=null,qn=Ht({query:e=>wt?.(e)??null}),j=new Map;function Xt(e){if(!e.captureOps.size)return;let t=new Set(e.store.pendingEntries().map(r=>r.id));for(let[r,o]of e.captureOps)o.ids=o.ids.filter(n=>t.has(n)),o.ids.length||e.captureOps.delete(r);[...e.captureOps.values()].some(r=>r.ended)||pe(e)}var Qt=(e,t)=>F===null||!He()?!1:V.get(F)?.get(e)?.key===t;function fe(e){let t=m.get(e);if(!t||!t.captureOps.size)return[];let r=new Set(t.store.pendingEntries().map(n=>n.id)),o=new Set;for(let[n,s]of t.captureOps)if(!(!s.ended&&!Qt(e,n)))for(let a of s.ids)r.has(a)&&o.add(a);return[...o]}function ot(e){for(let[t,r]of e.captureOps)if(r.ended)return[t,r];return null}We({id:"live:held",isPending:()=>[...m.values()].some(e=>ot(e))});var Ut=e=>[...e.captureOps].some(([t,r])=>!r.ended&&Qt(e.store.name,t));function jn({op:e,path:t,n:r,value:o}){let n=t.length?t.join("."):"the whole value",s=e==="add"?`${n} + ${r}`:e==="del"?`${n} removed`:`${n} = ${JSON.stringify(o)}`;return s.length>60?`${s.slice(0,57)}...`:s}function st(e){clearTimeout(e.timer),e.timer=setTimeout(()=>{e.timer=null,re(e)},Ln)}function pe(e){clearTimeout(e.timer),e.timer=null}function re(e,{read:t=!0}={}){let r=e.store.name,o=fe(r);if(pe(e),e.withheld=!1,e.reading=!1,tn(e),o.length){let n=e.store.pendingEntries().filter(c=>o.includes(c.id)).map(c=>c.op);e.store.handle.status.mode==="file"&&(e.leftAt=null),e.store.rebase(e.store.authoritative,{source:"state",dropIds:o});let s=n.slice(0,5).map(jn).join("; "),a=n.length>5?` and ${n.length-5} more`:"",i=`A save of "${r}" ended without an answer, so ${n.length===1?"this edit was":"these edits were"} not sent again: ${s}${a}. Check the value, and redo ${n.length===1?"it":"any"} if missing.`;console.warn(`clay.live("${r}"): ${i}`,n),document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:r,code:"save-uncertain",ops:n,message:i}}))}t&&p?.release(r,{read:p.roomBound(r)})}function de(e){Xt(e);let t=e.store.name;if(e.recovery&&!Dn(e)&&tn(e),!(!e.withheld||e.reading||fe(t).length)){if(!p?.roomBound(t)){e.withheld=!1,pe(e);return}e.reading=!0,st(e),p.release(t,{read:!0})}}function Nn(e){let t=m.get(e);t&&(it(t),!(!t.withheld&&!t.reading)&&(t.withheld=!1,t.reading=!1,[...t.captureOps.values()].some(r=>r.ended)||pe(t)))}function Zt(){for(let e of m.values())if(e.recovery||e.historicalRefreshPending)return!0;return!1}function Dn(e){let t=new Set(e.store.pendingEntries().map(o=>o.id));return e.recovery.targets.find(({name:o})=>o===e.store.name)?.ids.some(o=>t.has(o))??!1}function Hn(e){if(!H||H.captureId!==e||typeof H.html!="string")return null;let t=[];for(let[r,o]of H.qualified)!m.get(r)||!o.length||t.push({name:r,ids:[...o],saved:H.saved.get(r)});return t.length?{captureId:e,html:H.html,targets:t}:null}function Ee(){H&&(H.html=null)}function Wn(e,t){en(e);let r=e.store.name;e.refreshTimer=setTimeout(()=>{if(e.refreshTimer=null,!e.historicalRefreshPending)return;let o=`The save of "${r}" that ended without an answer did happen, but the value the file holds now must load before newer edits can be saved.`;console.warn(`clay.live("${r}"): ${o}`),document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:r,code:"save-history-refresh-required",message:o}}))},Math.max(0,t-Date.now()))}function it(e){e.historicalRefreshPending&&(e.historicalRefreshPending=!1,en(e))}function en(e){e.refreshTimer!==null&&(clearTimeout(e.refreshTimer),e.refreshTimer=null)}function tn(e){let t=e.recovery;t&&(e.recovery=null,!t.targets.some(r=>m.get(r.name)?.recovery===t)&&(j.delete(t.captureId),t.run?.cancel()))}function nn(e){if(e==null)return;let t=j.get(e);if(t){j.delete(e);for(let r of t.targets){let o=m.get(r.name);o&&o.recovery===t&&(o.recovery=null)}t.run?.cancel()}}function In(e,{result:t,attempts:r,startedAt:o}){let{captureId:n,html:s}=e,a={captureId:n,deadline:o+45e3,targets:e.targets,run:null};j.set(n,a);for(let i of e.targets){let c=m.get(i.name);pe(c),c.recovery=a}we("save-history").then(i=>{if(j.get(n)===a){if(e.html=null,!i)return Ft(n);a.run=qn.start({captureId:n,html:s,attempts:r,initialOutcome:t?.saveOutcome??null,startedAt:o,onApplied:({saveId:c,requestHash:d})=>Jn(n,c,d),onUnknown:({reason:c})=>Un(n,c)})}},()=>{e.html=null,Ft(n)})}function Jn(e,t,r){let o=j.get(e);if(o){j.delete(e);for(let n of o.targets){let s=m.get(n.name);if(!s||s.recovery!==o)continue;s.recovery=null,s.historicalRefreshPending=!0;let a=new Set(s.store.pendingEntries().map(c=>c.id)),i=n.ids.filter(c=>a.has(c));if(s.store.rebase(JSON.parse(n.saved),{source:"state",dropIds:i}),!p){it(s);continue}p.release(s.store.name,{read:!0}),Wn(s,o.deadline)}}}function Ft(e){let t=j.get(e);if(t){j.delete(e);for(let r of t.targets){let o=m.get(r.name);if(!(!o||o.recovery!==t)){if(o.recovery=null,!p?.roomBound(o.store.name)){re(o,{read:!1});continue}o.withheld=!0,o.reading=!0,st(o),p.release(o.store.name,{read:!0})}}}}function Un(e,t){let r=j.get(e);if(r){j.delete(e);for(let o of r.targets){let n=m.get(o.name);!n||n.recovery!==r||(n.recovery=null,re(n))}}}function Fn(e,t,r){let o=e.captureOps.get(t),n=e.store.name;if(!o){e.store.handle.status.mode==="file"&&(e.leftAt=null);return}if(o.ended=!0,r?.has(n)){e.withheld=!0,e.reading=!0;return}if(!p?.roomBound(n)){re(e,{read:!1});return}e.withheld=!0,e.reading=!0,st(e),p.release(n,{read:!0})}function Ze(e){if(Array.isArray(e))return e.map(Ze);if(e===null||typeof e!="object")return e;let t={};for(let r of Object.keys(e).sort())t[r]=Ze(e[r]);return t}function at(e){try{return JSON.stringify(Ze(ee(e)))}catch{return null}}var P=null,he=()=>!P||P.admitted;function Yn(){if(!Z||!he())return!1;for(let e of m.values())if(!e.store.ephemeral){if(e.store.handle.status.mode==="fast"){if(p?.isWriter()&&e.landed<e.last)return!0}else if(e.store.pending.length>0)return!0}return!1}var et=new Set;function rn(){for(let e of[...et])e()}var M=Dt({needsSave:Yn,blocked:()=>!he()||!Ue()||Ie()||Et()||Zt(),save:()=>Je().finally(rn),saveNow:()=>De(!0,()=>Je())}),p=null,tt=!1,xe=0,Oe=null,lt=!1,W=null,ct=!1;function Re(){return[...m.values()].filter(e=>!e.store.ephemeral)}function on(){if(!P||P.admitted||!p||p.status.stopped)return!1;for(let e of Re())if(e.store.handle.status.mode==="fast"&&e.store.pending.length>0)return!0;return!1}async function sn({timeoutMs:e=5e3}={}){let t=Date.now()+e,r=()=>{for(let o of Re())o.store.handle.status.mode==="fast"&&o.store.pending.length>0&&p?.release(o.store.name)};for(r();on();){if(Date.now()>=t)return{ok:!1,code:"timeout"};await new Promise(o=>setTimeout(o,5)),r()}return{ok:!0}}We({id:"live:writer",isPending:on,flush:sn});function Bn(){for(let e of m.values()){e.framesSince=!1;let t=e.store.pendingEntries().map(r=>r.id);t.length&&e.store.rebase(e.store.authoritative,{source:"state",dropIds:t})}}function zn(){let e=p;p=null,tt=!1,xe++,Oe=null,W=null,lt=!1,Te=null,ut=null,X=null,z=null,e?.stop()}function $r(){return{id:"clay:live",order:200,prepare(e={}){if(e.initial===!0)return P||(P={admitted:!0}),Bt(P,{adopted:!0});an();let t={admitted:!1,wantsLane:!0};return P=t,Bn(),Pe(),Bt(t)}}}function Yt(){for(let e of Re())e.store.pending.length>0&&p?.release(e.store.name)}function Bt(e,{adopted:t=!1}={}){return{enable(){t||P!==e||(e.admitted=!0,Pe(),Yt())},quiesce(){if(P===e)return e.admitted=!1,sn()},resume(){P===e&&(e.admitted=!0,Yt())},dispose(){P===e&&(P=null,zn())}}}var Te=null,ut=null,X=null,z=null;function an(){Te=new Promise(e=>{X=e}),ut=new Promise(e=>{z=e})}function ft(){return Te||an(),{laneReady:Te,writerReady:ut}}function Cr(){return ft().laneReady}function Mr(){return ft().writerReady}function zt(){for(let e of m.values())if(!e.store.ephemeral&&e.store.handle.status.mode==="fast"&&e.landed===-1){M.soon();return}M.changed()}function Xe(e,t){e.store.rebase(e.store.authoritative,{source:"state",through:t})}function dt(e,t,r=null){if(e)for(let[o,n]of e){let s=m.get(o);!s||n.mode!=="file"||(t||n.maybeLanded?Fn(s,n.key,r):(s.captureOps.delete(n.key),de(s)),s.store.handle.status.mode==="fast"&&p?.release(o))}}function oe(e){let t=V.get(e);return V.delete(e),F===e&&(F=null),q===e&&(q=null),t}function ln(e,t=null){let r=t??F??q;r!==null&&dt(oe(r),e)}function Vn(e,t){if(e?.code==="draft-storage"||e?.code==="draft-not-ready")return!1;let r=e?.code,o=r==="blockeditor-converting"||r==="blockeditor-capacity";return r==="save-already-applied"||e?.hadTimeout===!0||t!==!1&&!o&&!(e?.status>=400&&e?.status<500)}function Vt(e){return{transport:e,entries:m,onWriter:()=>{M.changed(),p&&p.status.writer!==null&&z?.(p)},onApplied:zt,onLanded:()=>{zt(),rn()},onCheckpoint:()=>M.soon(),onLeave:(t,r)=>{let o=m.get(t);o?.store.handle.status.mode==="fast"&&(o.leftAt={...r,frames:[],ancestors:[]})},held:t=>fe(t).length>0,heldIds:fe,hold:t=>{let r=m.get(t);return r?r.recovery?!0:Ut(r)?(r.withheld=!0,!0):(re(r,{read:!1}),!1):!1},taken:Nn,onStop:()=>{for(let t of m.values())it(t),!t.recovery&&(Ut(t)||re(t,{read:!1}))}}}function Kn(){let e=new Map;for(let[t,r]of Y(document,{warn:!1})){let o=m.get(t);if(o){e.set(t,{value:o.store.authoritative,ephemeral:o.store.ephemeral});continue}try{let n=ee(r.element.textContent);n!==null&&typeof n=="object"&&e.set(t,{value:n,ephemeral:r.ephemeral})}catch{}}for(let[t,r]of m)r.staged||e.set(t,{value:r.store.authoritative,ephemeral:r.store.ephemeral});return e}function Pe(){if(ft(),tt||!(P?P.admitted||P.wantsLane:Z))return;if(tt=!0,mt){X?.(null),z?.(null);return}let e=++xe;we("live-data").then(async t=>{let r=t&&await we("live-provenance");if(e!==xe)return;Oe=t,lt=r;let o=await $n().catch(()=>null);if(e===xe){if(!o){X?.(null),z?.(null);return}if(t)p=o.createFastLane(Vt(Jt()));else if(o.localLaneSupported())W=o.localTransport({seed:Kn,rooms:!0,floor:document.querySelector('meta[name="clay-blockeditor-format"]')?.getAttribute("content")}),p=o.createFastLane(Vt(W));else{X?.(null),z?.(null);return}for(let n of Y(document,{warn:!1}).keys())if(!m.has(n))try{un(n)}catch{}for(let[n,s]of m)s.historicalRefreshPending&&p.release(n,{read:!0});p.start(),X?.(p),p.status.writer!==null&&z?.(p)}}).catch(()=>{X?.(null),z?.(null)})}function Gn(e){let t=(e||"").split(";")[0].trim().toLowerCase();return t==="application/json"||t.endsWith("+json")}function Y(e=document,{warn:t=!0}={}){let r=new Map,o=new Set;for(let n of e.querySelectorAll('script[merge][clay~="live"]')){if(n.hasAttribute("src")||!Gn(n.getAttribute("type")))continue;let s=n.getAttribute("merge");if(Cn.test(s)){if(r.has(s)){o.add(s);continue}r.set(s,{name:s,ephemeral:n.getAttribute("clay").split(/\s+/).includes("ephemeral"),element:n})}}for(let n of o)t&&console.warn(`clay.live: more than one live tag is named "${n}", so none of them is live`),r.delete(n);return r}function $e(e){return new DOMParser().parseFromString(e,"text/html")}function Xn(e){let t=e.store.handle.status.mode==="fast",r=t?e.store.authoritative:e.store.value,o=t&&/^blockeditor(\.[0-9]+)?$/.test(e.store.name)?jt(r):r;return e.layout==="lines"?Qn(o):e.layout==="pretty"?JSON.stringify(o,null,2).replace(/</g,"\\u003c"):R(o)}var Kt=e=>e!==null&&typeof e=="object"&&!Array.isArray(e);function Qn(e){return Kt(e)?`{${Object.entries(e).map(([r,o])=>!Kt(o)||!Object.keys(o).length?`${R(r)}:${R(o)}`:`${R(r)}:{
1
+ import{a as Tt,c as Rt,d as Pt,e as $t,f as be,g as Ct}from"./c-JKZJIUIP.js";import{a as ee}from"./c-TCCA5BZN.js";import{a as T,b as Fe,c as Ye,d as Be,e as ke,f as Mt,g as ze,h as Lt,i as G,j as Ae,k as R,l as _t,m as qt,n as Ve,o as ue}from"./c-3LDGIBMN.js";import{d as jt}from"./c-57XDY6HC.js";import{e as Ot}from"./c-LZJPNR2W.js";import{F as Je,K as Ue,g as Et,r as Ie}from"./c-HTLYXCUH.js";import{a as We}from"./c-I2SCCUEW.js";import{f as De,g as He,k as kt,l as At,m as St,y as xt}from"./c-MFOSMAVM.js";import{a as vt}from"./c-LD6UVV5R.js";import{a as Ne}from"./c-PGSBXHUE.js";import{a as je,c as bt}from"./c-6IJEVE6B.js";import{e as we,k as wt}from"./c-QQFHEODI.js";import{b as mt,f as Z}from"./c-EDE45NM7.js";import{f as gt,k as yt}from"./c-PWJSJEJU.js";var gn=new Set(["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"]),yn=/^(0|[1-9]\d*)$/,U=e=>e!==null&&typeof e=="object",te=e=>Array.isArray(e)?"a list":"an object";function J(e,t){let r=e;for(let o of t){if(!U(r))return;Array.isArray(r)?r=r[Number(o)]:r=Object.prototype.hasOwnProperty.call(r,o)?r[o]:void 0}return r}var Se=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),vn=(e,t)=>R(e)===R(t);function Nt(e,t){let r=[];try{for(let o of t){let n=Mt(e,o);n&&(r.push(n),e=n.root)}return r}catch{return Ke(r),null}}function Ke(e){let t;for(let r=e.length-1;r>=0;r--)t=ze(e[r]);return t}function wn(e,t,r){let o=[];for(let n of e){if(n.at===null||Array.isArray(n.at))return null;let s=o.find(a=>a.path.length===n.path.length&&G(a.path,n.path));if(s){if(s.removed&&n.kind!=="remove")return null;n.kind==="remove"&&(s.removed=!0);continue}if(o.some(a=>G(a.path,n.path)))return null;o.push({path:n.path,at:n.at,key:n.key,had:n.kind!=="add",old:n.old,removed:n.kind==="remove"})}for(let n of o){if(n.has=Se(n.at,n.key),n.had&&n.has&&n.removed||(n.into=J(r,n.path.slice(0,-1)),!U(n.into)||Array.isArray(n.into)||Se(n.into,n.key)!==n.had))return null;let s=n.path.slice(0,-1);for(let a of t){let i=a.op.path;if(G(n.path,i)||a.op.op==="del"&&i.length<=n.path.length&&G(i.slice(0,-1),n.path)&&Array.isArray(J(r,i.slice(0,-1))))return null;if(!n.had&&n.has&&i.length>s.length&&G(s,i)){let c=i[s.length];if(i.length===s.length+1&&a.op.op==="del"||!Se(n.at,String(c)))return null}}}return o}function bn(e,t){if(t.op==="set"){let r=J(e,t.path);if(U(r)&&U(t.value)&&Array.isArray(r)===Array.isArray(t.value)){Ae(r,T(t.value));return}}Be(e,t)}function Ge({name:e,value:t,ephemeral:r=!1}){if(!U(t))throw new TypeError(`clay.live("${e}"): the tag must hold a JSON object or list`);let o=T(t),n=null,s=T(t),a=!0,i=[],c=1,d=null,h="file",w=new Set,A=new Set,b=new Set,x=new Set,E=new Set,v=new WeakMap;function O(l,u){let f={source:l,ops:u};for(let g of[...w])try{g(f)}catch(S){console.error(`clay.live("${e}"): a change listener threw`,S)}}function I(){let l=T(o),u=[];for(let f of i)try{Ye(l,f.op),l=Be(l,f.op),u.push(f)}catch{}i=u,Ae(s,l),a=!0}function N(l){for(let u of[...b])try{u(l)}catch(f){console.error(`clay.live("${e}"): a rebase listener threw`,f)}}function se(l,{source:u="remote",confirmed:f=0,through:g,drop:S,dropIds:$,frame:K=null,room:L=null,cause:ce=null}={}){if(!U(l)||te(l)!==te(s))return console.warn(`clay.live("${e}"): ignored an incoming value that is not ${te(s)}`),!1;L&&(n=L);let me=T(s),ge=o;if(o=T(l),S)i=i.filter(_=>_.id<S[0]||_.id>S[1]);else if($){let _=new Set($);i=i.filter(ye=>!_.has(ye.id))}else i=g===void 0?i.slice(f):i.filter(_=>_.id>g);return I(),N({source:u,frame:K,room:L,cause:ce,prev:ge,before:_=>J(ge,_),next:o}),_t(me,s)||O(u,null),!0}function ie(l){let u=T(o);for(let f=l.length-1;f>=0;f--){let g=l[f];ze({...g,at:J(u,g.path.slice(0,-1))})}return u}function ae(l){for(let u of[...A])try{u(l)}catch(f){console.error(`clay.live("${e}"): a transport threw`,f)}O("local",l)}function C(l){let u=l.map(Fe);for(let f of u)if(f.path.length===0&&te(f.value)!==te(s))throw new TypeError(`clay.live("${e}"): the whole value must stay ${te(s)}`);u.length===1?Ye(s,u[0]):ke(T(s),u);for(let f of u)bn(s,f);i.push(...u.map(f=>({id:c++,op:f}))),d?d.push(...u):ae(u)}function B(l,u){let f=v.get(l);f||v.set(l,f=new Map);let g=JSON.stringify(u),S=f.get(g);return S||(S=new Proxy(l,Ce(u)),f.set(g,S)),S}function Ce(l){return{get(u,f){if(Array.isArray(u)&&gn.has(f))return(...S)=>{let $=T(u),K=Array.prototype[f].apply($,S);return C([{op:"set",path:l,value:$}]),K===$?B(u,l):K};let g=u[f];return typeof f=="symbol"||!U(g)||!Object.prototype.hasOwnProperty.call(u,f)?g:B(g,[...l,Array.isArray(u)?Number(f):f])},set(u,f,g){if(typeof f=="symbol")throw new TypeError(`clay.live("${e}"): symbol keys are not JSON`);if(Array.isArray(u)){if(f==="length"){let S=T(u);return S.length=g,C([{op:"set",path:l,value:S}]),!0}if(!yn.test(f))throw new TypeError(`clay.live("${e}"): "${f}" is not a list index`);return C([{op:"set",path:[...l,Number(f)],value:g}]),!0}return C([{op:"set",path:[...l,f],value:g}]),!0},deleteProperty(u,f){if(typeof f=="symbol")return!0;if(Array.isArray(u))throw new TypeError(`clay.live("${e}"): remove a list item with splice`);return C([{op:"del",path:[...l,f]}]),!0},defineProperty(){throw new TypeError(`clay.live("${e}"): assign values instead of defining properties`)},setPrototypeOf(){return!1},preventExtensions(){return!1}}}let le=B(s,[]),Q,Me=new Promise(l=>{Q=l}),y=Object.freeze({name:e,ephemeral:r,ready:Me,get data(){return le},get status(){return{mode:h}},set(l,u){C([{op:"set",path:l,value:u}])},delete(l){C([{op:"del",path:l}])},add(l,u=1){C([{op:"add",path:l,n:u}])},update(l){if(typeof l!="function")throw new TypeError(`clay.live("${e}"): update() takes a function`);if(d)return l(le);d=[];let u=i.length,f=c,g;try{if(g=l(le),g&&typeof g.then=="function")throw new TypeError(`clay.live("${e}"): update() runs synchronously; do async work before calling it`)}catch($){throw d=null,i.length=u,c=f,I(),$}let S=Lt(d);return d=null,i.length=u,c=f,i.push(...S.map($=>({id:c++,op:$}))),S.length&&ae(S),g},on(l,u){if(l!=="change")throw new TypeError(`clay.live("${e}"): the only event is "change"`);if(typeof u!="function")throw new TypeError(`clay.live("${e}"): on() takes a function`);return w.add(u),()=>w.delete(u)},off(l,u){w.delete(u)},toJSON(){return T(s)}});return Q(y),{handle:y,name:e,ephemeral:r,get value(){return s},get authoritative(){return o},get room(){return n},get pending(){return i.map(l=>l.op)},pendingEntries(){return i.map(l=>({id:l.id,op:l.op}))},get mark(){return c-1},setMode(l){h=l,l!=="fast"&&(n=null)},onLocal(l){return A.add(l),()=>A.delete(l)},confirm(l){let u=i.filter(f=>f.id<=l);if(u.length){try{o=ke(T(o),u.map(f=>f.op))}catch{o=T(s),a=!1}i=i.filter(f=>f.id>l);for(let f of[...x])try{f({through:l})}catch(g){console.error(`clay.live("${e}"): a confirmation listener threw`,g)}}},onConfirm(l){return x.add(l),()=>x.delete(l)},rebase:se,checkOps(l){let u;try{u=l.map(Fe)}catch{return null}let f=Nt(o,u);return f?(Ke(f),u):null},rebaseOps(l,{source:u="remote",confirmed:f=0,through:g,frame:S=null,room:$=null,cause:K=null}={}){let L=Nt(o,l);if(!L)return!1;let ce=g===void 0?i.slice(f):i.filter(k=>k.id>g),me=i.length-ce.length,ge=L.some(k=>k.at===null),_=a&&!ge&&me===l.length&&l.every((k,D)=>vn(k,i[D].op)),ye=a&&!_&&me===0?wn(L,ce,s):null;if(!_&&!ye)return Ke(L),se(ke(T(o),l),{source:u,confirmed:f,through:g,frame:S,room:$,cause:K});i=ce;let Le=!1;for(let k of ye??[]){let D=k.into;if(k.has){let ht=k.at[k.key];(!k.had||R(k.old)!==R(ht))&&(Le=!0);let qe=k.had?D[k.key]:void 0,ve=T(ht),mn=U(qe)&&U(ve)&&Array.isArray(qe)===Array.isArray(ve);Object.defineProperty(D,k.key,{value:mn?Ae(qe,ve):ve,enumerable:!0,writable:!0,configurable:!0})}else k.had&&(Le=!0,delete D[k.key])}let dn=null,_e=()=>dn??=ie(L),pn=L.some(k=>Array.isArray(k.at)&&k.kind!=="put"),hn=k=>{if(pn)return J(_e(),k);for(let D of L)if(G(D.path,k))return D.path.length>k.length?J(_e(),k):J(D.old,k.slice(D.path.length));return J(o,k)};return $&&(n=$),N({source:u,frame:S,room:$,cause:K,get prev(){return _e()},before:hn,next:o}),Le&&O(u,null),!0},onRebase(l){return b.add(l),()=>b.delete(l)},onDelivery(l){return E.add(l),()=>E.delete(l)},deliver(l){for(let u of[...E])try{u(l)}catch(f){console.error(`clay.live("${e}"): a delivery listener threw`,f)}}}}function Dt({needsSave:e,blocked:t,save:r,saveNow:o,now:n=()=>Date.now(),setTimer:s=setTimeout,clearTimer:a=clearTimeout}){let i=null,c=null,d=!1,h=!1,w=0;function A(v){let O=v&&!v.ok&&v.msgType==="skipped";return w=v?.ok||O?0:n()+8e3,O?1e3:8e3}function b(v){i=v,c!==null&&a(c),c=s(E,Math.max(0,v-n()))}function x(){c!==null&&a(c),c=null,i=null}async function E(){if(c=null,i=null,!e())return;if(t()){b(n()+1e3);return}d=!0;let v=null;try{v=await r()}catch{v=null}finally{d=!1}let O=A(v);e()&&b(n()+O)}return{changed(){i===null&&!d&&b(n()+8e3)},flush(){d||!e()||t()||(x(),d=!0,h=!0,Promise.resolve().then(o).catch(()=>null).then(v=>{d=!1,h=!1;let O=A(v);e()&&b(n()+O)}))},soon(){if(d)return;let v=Math.max(n(),w);(i===null||v<i)&&b(v)},within(v){if(d)return;let O=Math.max(n()+v,w);(i===null||O<i)&&b(O)},get flushing(){return h},get deadline(){return i}}}var ne=[0,1e4,3e4],kn=6e3,An=2;async function Sn(e){let t=globalThis.crypto&&globalThis.crypto.subtle;if(!t)return null;try{let r=new TextEncoder().encode(String(e)),o=await t.digest("SHA-256",r),n=new Uint8Array(o),s="";for(let a=0;a<n.length;a+=1)s+=n[a].toString(16).padStart(2,"0");return s}catch{return null}}function xn(e){let t=[];for(let r of e||[]){let o=r&&r.saveId;if(typeof o=="string"&&o&&!t.includes(o)&&t.push(o),t.length>=An)break}return t}function En(e,t,r){return!!(e&&typeof e=="object"&&e.saveId===t&&e.requestHash===r&&e.status==="applied")}function Ht({query:e,digest:t=Sn,now:r=()=>Date.now(),setTimer:o=setTimeout,clearTimer:n=clearTimeout}={}){function s({captureId:a,html:i,attempts:c,initialOutcome:d,startedAt:h,onApplied:w,onUnknown:A}){let b=h+45e3,x=xn(c),E=new Set,v=new Set,O=i,I=null,N=!1;function se(y,l){try{typeof y=="function"&&y(l)}catch(u){console.error("clayjs: save-history callback failed:",u)}}function ie(){N=!0,O=null;for(let y of E)n(y);E.clear();for(let y of v)y.abort();v.clear()}function ae(y,l){N||(ie(),se(w,{captureId:a,saveId:y,requestHash:l}))}function C(y){N||(ie(),se(A,{captureId:a,reason:y}))}function B(y,l){let u=null;return u=o(()=>{u!==null&&E.delete(u),y()},Math.max(0,l)),E.add(u),u}function Ce(y){y!==null&&(n(y),E.delete(y))}async function le(y){if(N)return;let l=b-r();if(l<=0)return;let u=new AbortController;v.add(u);let f=B(()=>u.abort(),Math.min(kn,l)),g=null;try{g=await e({saveId:y,requestHash:I,signal:u.signal})}catch{g=null}finally{Ce(f),v.delete(u)}N||En(g,y,I)&&ae(y,I)}function Q(){if(!N&&!(r()>=b))for(let y of x)le(y)}async function Me(){let y=null;try{y=await t(O)}catch{y=null}if(O=null,N)return;if(typeof y!="string"||!y){C("unavailable");return}if(I=y,d&&typeof d=="object"&&d.status==="applied"&&d.requestHash===I&&x.includes(d.saveId)){ae(d.saveId,I);return}let l=r()-h;if(l>=45e3){C("expired");return}let u=-1;for(let f=0;f<ne.length;f+=1)ne[f]<=l&&(u=f);if(u<0){for(let f=0;f<ne.length;f+=1)B(Q,h+ne[f]-r());return}Q();for(let f=u+1;f<ne.length;f+=1)B(Q,h+ne[f]-r())}return B(()=>C("expired"),b-r()),Me(),{cancel(){ie()}}}return{start:s}}var On="/_/sync/data";function It(){return new URL(On,window.location.origin)}async function Tn(e,t){let r=It();r.searchParams.set("client-id",e);try{let o=await fetch(r.href,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json","Document-URL":window.location.href,[Ne]:String(1)},body:JSON.stringify(t)}),n=null;try{n=await o.json()}catch{}let s=Number(o.headers?.get?.("Retry-After"))||0;return{status:o.status,body:n,retryAfter:s}}catch{return{status:0,body:null,retryAfter:0}}}async function Rn(e,t=null,{signal:r}={}){let o=It();e&&o.searchParams.set("client-id",e),t&&typeof t.epoch=="string"&&Number.isInteger(t.seq)&&o.searchParams.set("since",`${t.epoch}:${t.seq}`),o.searchParams.set("compaction","1");try{let n=await fetch(o.href,{credentials:"same-origin",cache:"no-store",headers:{"Document-URL":window.location.href,[Ne]:String(1)},signal:r});if(!n.ok){let a=null;try{a=await n.json()}catch{}return{status:n.status,code:a?.code??null,retryAfter:Number(n.headers?.get?.("Retry-After"))||0}}let s=await n.json();return s&&typeof s.epoch=="string"&&s.conn===null?null:s}catch{return null}}function Jt(){return{start(e){return Ot({open(t){t.lane==="live"&&e.open(t)},close:()=>e.close(),event(t,r){t==="data"?e.frame(r):t==="data-state"?e.state(r):t==="data-writer"&&e.writer(r)}})},send:Tn,fetchState:Rn}}var $n=()=>Promise.all([import("./c-IXO7EI2Q.js"),import("./c-XUZMRQ7O.js")]).then(([e,t])=>({createFastLane:e.createFastLane,localTransport:t.localTransport,localLaneSupported:t.localLaneSupported})),Cn=/^[A-Za-z0-9_.:-]{1,64}$/,m=new Map,Gt="save_"+[...crypto.getRandomValues(new Uint32Array(4))].map(e=>e.toString(16).padStart(8,"0")).join(""),Qe=0,Mn=0,Ln=45e3;function rt(e){let t=ue(e.getAttribute("live-at"));if(!t||t.hash!==Zn(e.textContent))return null;let r=e.getAttribute("live-by"),o=r===null?null:be(r);return r!==null&&!o?null:o&&o.v!==2?{disk:!0}:{epoch:t.epoch,seq:t.seq,frames:Pt(o),ancestors:$t(o)}}function _n(e,t){let r=e.leftAt;if(!r||r.disk)return null;let o=p?.pendingFrames(e.store.name,r,{reserve:t})??{frames:[],complete:!0};if(!o.complete)return null;let n=Tt(r.frames??[],o.frames),s=r.ancestors??[],a=R(e.store.value),i=JSON.stringify([r.epoch,r.seq,n,s,e.store.mark,a]);if(e.capture?.key===i)return e.capture.value;let c={v:2,frames:n,ancestors:s,capture:[Gt,Qe+1]},d=Ct(c),h=d?{at:Ve(r.epoch,r.seq,a),by:d}:null;return e.capture={key:i,value:h},h}var V=new Map,F=null,q=null,H=null,qn=Ht({query:e=>wt?.(e)??null}),j=new Map;function Xt(e){if(!e.captureOps.size)return;let t=new Set(e.store.pendingEntries().map(r=>r.id));for(let[r,o]of e.captureOps)o.ids=o.ids.filter(n=>t.has(n)),o.ids.length||e.captureOps.delete(r);[...e.captureOps.values()].some(r=>r.ended)||pe(e)}var Qt=(e,t)=>F===null||!He()?!1:V.get(F)?.get(e)?.key===t;function fe(e){let t=m.get(e);if(!t||!t.captureOps.size)return[];let r=new Set(t.store.pendingEntries().map(n=>n.id)),o=new Set;for(let[n,s]of t.captureOps)if(!(!s.ended&&!Qt(e,n)))for(let a of s.ids)r.has(a)&&o.add(a);return[...o]}function ot(e){for(let[t,r]of e.captureOps)if(r.ended)return[t,r];return null}We({id:"live:held",isPending:()=>[...m.values()].some(e=>ot(e))});var Ut=e=>[...e.captureOps].some(([t,r])=>!r.ended&&Qt(e.store.name,t));function jn({op:e,path:t,n:r,value:o}){let n=t.length?t.join("."):"the whole value",s=e==="add"?`${n} + ${r}`:e==="del"?`${n} removed`:`${n} = ${JSON.stringify(o)}`;return s.length>60?`${s.slice(0,57)}...`:s}function st(e){clearTimeout(e.timer),e.timer=setTimeout(()=>{e.timer=null,re(e)},Ln)}function pe(e){clearTimeout(e.timer),e.timer=null}function re(e,{read:t=!0}={}){let r=e.store.name,o=fe(r);if(pe(e),e.withheld=!1,e.reading=!1,tn(e),o.length){let n=e.store.pendingEntries().filter(c=>o.includes(c.id)).map(c=>c.op);e.store.handle.status.mode==="file"&&(e.leftAt=null),e.store.rebase(e.store.authoritative,{source:"state",dropIds:o});let s=n.slice(0,5).map(jn).join("; "),a=n.length>5?` and ${n.length-5} more`:"",i=`A save of "${r}" ended without an answer, so ${n.length===1?"this edit was":"these edits were"} not sent again: ${s}${a}. Check the value, and redo ${n.length===1?"it":"any"} if missing.`;console.warn(`clay.live("${r}"): ${i}`,n),document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:r,code:"save-uncertain",ops:n,message:i}}))}t&&p?.release(r,{read:p.roomBound(r)})}function de(e){Xt(e);let t=e.store.name;if(e.recovery&&!Dn(e)&&tn(e),!(!e.withheld||e.reading||fe(t).length)){if(!p?.roomBound(t)){e.withheld=!1,pe(e);return}e.reading=!0,st(e),p.release(t,{read:!0})}}function Nn(e){let t=m.get(e);t&&(it(t),!(!t.withheld&&!t.reading)&&(t.withheld=!1,t.reading=!1,[...t.captureOps.values()].some(r=>r.ended)||pe(t)))}function Zt(){for(let e of m.values())if(e.recovery||e.historicalRefreshPending)return!0;return!1}function Dn(e){let t=new Set(e.store.pendingEntries().map(o=>o.id));return e.recovery.targets.find(({name:o})=>o===e.store.name)?.ids.some(o=>t.has(o))??!1}function Hn(e){if(!H||H.captureId!==e||typeof H.html!="string")return null;let t=[];for(let[r,o]of H.qualified)!m.get(r)||!o.length||t.push({name:r,ids:[...o],saved:H.saved.get(r)});return t.length?{captureId:e,html:H.html,targets:t}:null}function Ee(){H&&(H.html=null)}function Wn(e,t){en(e);let r=e.store.name;e.refreshTimer=setTimeout(()=>{if(e.refreshTimer=null,!e.historicalRefreshPending)return;let o=`The save of "${r}" that ended without an answer did happen, but the value the file holds now must load before newer edits can be saved.`;console.warn(`clay.live("${r}"): ${o}`),document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:r,code:"save-history-refresh-required",message:o}}))},Math.max(0,t-Date.now()))}function it(e){e.historicalRefreshPending&&(e.historicalRefreshPending=!1,en(e))}function en(e){e.refreshTimer!==null&&(clearTimeout(e.refreshTimer),e.refreshTimer=null)}function tn(e){let t=e.recovery;t&&(e.recovery=null,!t.targets.some(r=>m.get(r.name)?.recovery===t)&&(j.delete(t.captureId),t.run?.cancel()))}function nn(e){if(e==null)return;let t=j.get(e);if(t){j.delete(e);for(let r of t.targets){let o=m.get(r.name);o&&o.recovery===t&&(o.recovery=null)}t.run?.cancel()}}function In(e,{result:t,attempts:r,startedAt:o}){let{captureId:n,html:s}=e,a={captureId:n,deadline:o+45e3,targets:e.targets,run:null};j.set(n,a);for(let i of e.targets){let c=m.get(i.name);pe(c),c.recovery=a}we("save-history").then(i=>{if(j.get(n)===a){if(e.html=null,!i)return Ft(n);a.run=qn.start({captureId:n,html:s,attempts:r,initialOutcome:t?.saveOutcome??null,startedAt:o,onApplied:({saveId:c,requestHash:d})=>Jn(n,c,d),onUnknown:({reason:c})=>Un(n,c)})}},()=>{e.html=null,Ft(n)})}function Jn(e,t,r){let o=j.get(e);if(o){j.delete(e);for(let n of o.targets){let s=m.get(n.name);if(!s||s.recovery!==o)continue;s.recovery=null,s.historicalRefreshPending=!0;let a=new Set(s.store.pendingEntries().map(c=>c.id)),i=n.ids.filter(c=>a.has(c));if(s.store.rebase(JSON.parse(n.saved),{source:"state",dropIds:i}),!p){it(s);continue}p.release(s.store.name,{read:!0}),Wn(s,o.deadline)}}}function Ft(e){let t=j.get(e);if(t){j.delete(e);for(let r of t.targets){let o=m.get(r.name);if(!(!o||o.recovery!==t)){if(o.recovery=null,!p?.roomBound(o.store.name)){re(o,{read:!1});continue}o.withheld=!0,o.reading=!0,st(o),p.release(o.store.name,{read:!0})}}}}function Un(e,t){let r=j.get(e);if(r){j.delete(e);for(let o of r.targets){let n=m.get(o.name);!n||n.recovery!==r||(n.recovery=null,re(n))}}}function Fn(e,t,r){let o=e.captureOps.get(t),n=e.store.name;if(!o){e.store.handle.status.mode==="file"&&(e.leftAt=null);return}if(o.ended=!0,r?.has(n)){e.withheld=!0,e.reading=!0;return}if(!p?.roomBound(n)){re(e,{read:!1});return}e.withheld=!0,e.reading=!0,st(e),p.release(n,{read:!0})}function Ze(e){if(Array.isArray(e))return e.map(Ze);if(e===null||typeof e!="object")return e;let t={};for(let r of Object.keys(e).sort())t[r]=Ze(e[r]);return t}function at(e){try{return JSON.stringify(Ze(ee(e)))}catch{return null}}var P=null,he=()=>!P||P.admitted;function Yn(){if(!Z||!he())return!1;for(let e of m.values())if(!e.store.ephemeral){if(e.store.handle.status.mode==="fast"){if(p?.isWriter()&&e.landed<e.last)return!0}else if(e.store.pending.length>0)return!0}return!1}var et=new Set;function rn(){for(let e of[...et])e()}var M=Dt({needsSave:Yn,blocked:()=>!he()||!Ue()||Ie()||Et()||Zt(),save:()=>Je().finally(rn),saveNow:()=>De(!0,()=>Je())}),p=null,tt=!1,xe=0,Oe=null,lt=!1,W=null,ct=!1;function Re(){return[...m.values()].filter(e=>!e.store.ephemeral)}function on(){if(!P||P.admitted||!p||p.status.stopped)return!1;for(let e of Re())if(e.store.handle.status.mode==="fast"&&e.store.pending.length>0)return!0;return!1}async function sn({timeoutMs:e=5e3}={}){let t=Date.now()+e,r=()=>{for(let o of Re())o.store.handle.status.mode==="fast"&&o.store.pending.length>0&&p?.release(o.store.name)};for(r();on();){if(Date.now()>=t)return{ok:!1,code:"timeout"};await new Promise(o=>setTimeout(o,5)),r()}return{ok:!0}}We({id:"live:writer",isPending:on,flush:sn});function Bn(){for(let e of m.values()){e.framesSince=!1;let t=e.store.pendingEntries().map(r=>r.id);t.length&&e.store.rebase(e.store.authoritative,{source:"state",dropIds:t})}}function zn(){let e=p;p=null,tt=!1,xe++,Oe=null,W=null,lt=!1,Te=null,ut=null,X=null,z=null,e?.stop()}function $r(){return{id:"clay:live",order:200,prepare(e={}){if(e.initial===!0)return P||(P={admitted:!0}),Bt(P,{adopted:!0});an();let t={admitted:!1,wantsLane:!0};return P=t,Bn(),Pe(),Bt(t)}}}function Yt(){for(let e of Re())e.store.pending.length>0&&p?.release(e.store.name)}function Bt(e,{adopted:t=!1}={}){return{enable(){t||P!==e||(e.admitted=!0,Pe(),Yt())},quiesce(){if(P===e)return e.admitted=!1,sn()},resume(){P===e&&(e.admitted=!0,Yt())},dispose(){P===e&&(P=null,zn())}}}var Te=null,ut=null,X=null,z=null;function an(){Te=new Promise(e=>{X=e}),ut=new Promise(e=>{z=e})}function ft(){return Te||an(),{laneReady:Te,writerReady:ut}}function Cr(){return ft().laneReady}function Mr(){return ft().writerReady}function zt(){for(let e of m.values())if(!e.store.ephemeral&&e.store.handle.status.mode==="fast"&&e.landed===-1){M.soon();return}M.changed()}function Xe(e,t){e.store.rebase(e.store.authoritative,{source:"state",through:t})}function dt(e,t,r=null){if(e)for(let[o,n]of e){let s=m.get(o);!s||n.mode!=="file"||(t||n.maybeLanded?Fn(s,n.key,r):(s.captureOps.delete(n.key),de(s)),s.store.handle.status.mode==="fast"&&p?.release(o))}}function oe(e){let t=V.get(e);return V.delete(e),F===e&&(F=null),q===e&&(q=null),t}function ln(e,t=null){let r=t??F??q;r!==null&&dt(oe(r),e)}function Vn(e,t){if(e?.code==="draft-storage"||e?.code==="draft-not-ready")return!1;let r=e?.code,o=r==="blockeditor-converting"||r==="blockeditor-capacity";return r==="save-already-applied"||e?.hadTimeout===!0||t!==!1&&!o&&!(e?.status>=400&&e?.status<500)}function Vt(e){return{transport:e,entries:m,onWriter:()=>{M.changed(),p&&p.status.writer!==null&&z?.(p)},onApplied:zt,onLanded:()=>{zt(),rn()},onCheckpoint:()=>M.soon(),onLeave:(t,r)=>{let o=m.get(t);o?.store.handle.status.mode==="fast"&&(o.leftAt={...r,frames:[],ancestors:[]})},held:t=>fe(t).length>0,heldIds:fe,hold:t=>{let r=m.get(t);return r?r.recovery?!0:Ut(r)?(r.withheld=!0,!0):(re(r,{read:!1}),!1):!1},taken:Nn,onStop:()=>{for(let t of m.values())it(t),!t.recovery&&(Ut(t)||re(t,{read:!1}))}}}function Kn(){let e=new Map;for(let[t,r]of Y(document,{warn:!1})){let o=m.get(t);if(o){e.set(t,{value:o.store.authoritative,ephemeral:o.store.ephemeral});continue}try{let n=ee(r.element.textContent);n!==null&&typeof n=="object"&&e.set(t,{value:n,ephemeral:r.ephemeral})}catch{}}for(let[t,r]of m)r.staged||e.set(t,{value:r.store.authoritative,ephemeral:r.store.ephemeral});return e}function Pe(){if(ft(),tt||!(P?P.admitted||P.wantsLane:Z))return;if(tt=!0,mt){X?.(null),z?.(null);return}let e=++xe;we("live-data").then(async t=>{let r=t&&await we("live-provenance");if(e!==xe)return;Oe=t,lt=r;let o=await $n().catch(()=>null);if(e===xe){if(!o){X?.(null),z?.(null);return}if(t)p=o.createFastLane(Vt(Jt()));else if(o.localLaneSupported())W=o.localTransport({seed:Kn,rooms:!0,floor:document.querySelector('meta[name="clay-blockeditor-format"]')?.getAttribute("content")}),p=o.createFastLane(Vt(W));else{X?.(null),z?.(null);return}for(let n of Y(document,{warn:!1}).keys())if(!m.has(n))try{un(n)}catch{}for(let[n,s]of m)s.historicalRefreshPending&&p.release(n,{read:!0});p.start(),X?.(p),p.status.writer!==null&&z?.(p)}}).catch(()=>{X?.(null),z?.(null)})}function Gn(e){let t=(e||"").split(";")[0].trim().toLowerCase();return t==="application/json"||t.endsWith("+json")}function Y(e=document,{warn:t=!0}={}){let r=new Map,o=new Set;for(let n of e.querySelectorAll('script[merge][clay~="live"]')){if(n.hasAttribute("src")||!Gn(n.getAttribute("type")))continue;let s=n.getAttribute("merge");if(Cn.test(s)){if(r.has(s)){o.add(s);continue}r.set(s,{name:s,ephemeral:n.getAttribute("clay").split(/\s+/).includes("ephemeral"),element:n})}}for(let n of o)t&&console.warn(`clay.live: more than one live tag is named "${n}", so none of them is live`),r.delete(n);return r}function $e(e){return new DOMParser().parseFromString(e,"text/html")}function Xn(e){let t=e.store.handle.status.mode==="fast",r=t?e.store.authoritative:e.store.value,o=t&&/^blockeditor(\.[0-9]+)?$/.test(e.store.name)?jt(r):r;return e.layout==="lines"?Qn(o):e.layout==="pretty"?JSON.stringify(o,null,2).replace(/</g,"\\u003c"):R(o)}var Kt=e=>e!==null&&typeof e=="object"&&!Array.isArray(e);function Qn(e){return Kt(e)?`{${Object.entries(e).map(([r,o])=>!Kt(o)||!Object.keys(o).length?`${R(r)}:${R(o)}`:`${R(r)}:{
2
2
  ${Object.entries(o).map(([n,s])=>`${R(n)}:${R(s)}`).join(`,
3
3
  `)}
4
4
  }`).join(`,
@@ -0,0 +1 @@
1
+ import{e as a,f as b,g as c}from"./c-CZHTXGJS.js";import"./c-WN3MXOLT.js";import"./c-QQFHEODI.js";import"./c-EDE45NM7.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-U4NTUVDZ.js";import"./c-HA6INT6J.js";import"./c-ICMAOOGK.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";export{a as PresenceStore,c as default,b as presence};
@@ -1 +1 @@
1
- import{a,b,c,d,e,f,g,h,i,j,k}from"./c-RBPZNU2D.js";import"./c-DLBX4JCJ.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-HA6INT6J.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";export{i as hostActions,d as hostMeta,c as hostMetaOrder,a as hostMetaOutcome,b as hostMetaPath,f as hostPageFormat,g as hostPageStateHref,e as hostSupports,h as hostVersions,k as querySaveOutcome,j as resetHostMeta};
1
+ import{a,b,c,d,e,f,g,h,i,j,k}from"./c-QQFHEODI.js";import"./c-EDE45NM7.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-U4NTUVDZ.js";import"./c-HA6INT6J.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";export{i as hostActions,d as hostMeta,c as hostMetaOrder,a as hostMetaOutcome,b as hostMetaPath,f as hostPageFormat,g as hostPageStateHref,e as hostSupports,h as hostVersions,k as querySaveOutcome,j as resetHostMeta};
@@ -1 +1 @@
1
- import{a as d}from"./c-4PO3YGDC.js";import"./c-PZ4XEPUP.js";import"./c-SFKI6OLM.js";import"./c-Q3XOWZEV.js";import"./c-RHMPKZZ7.js";import{g as m,l as v,n as x,q as s}from"./c-MR75YPRT.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-DLBX4JCJ.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-PWJSJEJU.js";import"./c-XQXZAO7N.js";import"./c-S7LK4KUE.js";import"./c-VG5XIN4T.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-4PO3YGDC.js";import"./c-PZ4XEPUP.js";import"./c-SFKI6OLM.js";import"./c-Q3XOWZEV.js";import"./c-RHMPKZZ7.js";import{g as m,l as v,n as x,q as s}from"./c-MR75YPRT.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-EDE45NM7.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-U4NTUVDZ.js";import"./c-PWJSJEJU.js";import"./c-XQXZAO7N.js";import"./c-S7LK4KUE.js";import"./c-VG5XIN4T.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{a as D,b as x}from"./c-A7LS5UZW.js";import{b as L,c as M,d as _,f as N}from"./c-PVJMJL3P.js";import"./c-WN3MXOLT.js";import"./c-RBPZNU2D.js";import"./c-DLBX4JCJ.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.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-CZHTXGJS.js";import"./c-WN3MXOLT.js";import"./c-QQFHEODI.js";import"./c-EDE45NM7.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-U4NTUVDZ.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 +1 @@
1
- import{a as A,b as m,c as n}from"./c-TWCXBWS3.js";import{a as c}from"./c-VKEDWYDF.js";import{f as i}from"./c-DLBX4JCJ.js";import{b as l,r as d}from"./c-PWJSJEJU.js";var f="[editmode\\:onclick]";function b(){d(o=>{o.querySelectorAll(f).forEach(t=>{let e=t.getAttribute("onclick");e!==null&&(t.setAttribute("inert-onclick",e),t.removeAttribute("onclick"),n(t,l(t)??t))})})}function p(){i&&c(()=>{E()})}function E(o=document){o.querySelectorAll(f).forEach(t=>{let e=t.getAttribute("inert-onclick");e&&(t.setAttribute("onclick",e),t.removeAttribute("inert-onclick"))})}function D(){document.querySelectorAll(f).forEach(o=>{let t=o.getAttribute("onclick");t&&(o.setAttribute("inert-onclick",t),o.removeAttribute("onclick")),n(o)})}function q(){b(),p()}var O="[viewmode\\:disabled]",S="[viewmode\\:readonly]",u=[[O,"disabled"],[S,"readonly"]];function k(){d(o=>{for(let[t,e]of u)o.querySelectorAll(t).forEach(r=>{if(r.hasAttribute(e))return;let a=l(r),s=a?m(a,e):null;r.setAttribute(e,s===null?"":s),n(r,a??r)})})}function h(){i&&c(()=>{x()})}function x(o=document){for(let[t,e]of u)o.querySelectorAll(t).forEach(r=>{A(r),r.removeAttribute(e)})}function M(){for(let[o,t]of u)document.querySelectorAll(o).forEach(e=>{let r=m(e,t);r===null?e.removeAttribute(t):e.setAttribute(t,r),n(e)})}function P(){k(),h()}export{f as a,E as b,D as c,q as d,O as e,S as f,x as g,M as h,P as i};
1
+ import{a as A,b as m,c as n}from"./c-TWCXBWS3.js";import{a as c}from"./c-VKEDWYDF.js";import{f as i}from"./c-EDE45NM7.js";import{b as l,r as d}from"./c-PWJSJEJU.js";var f="[editmode\\:onclick]";function b(){d(o=>{o.querySelectorAll(f).forEach(t=>{let e=t.getAttribute("onclick");e!==null&&(t.setAttribute("inert-onclick",e),t.removeAttribute("onclick"),n(t,l(t)??t))})})}function p(){i&&c(()=>{E()})}function E(o=document){o.querySelectorAll(f).forEach(t=>{let e=t.getAttribute("inert-onclick");e&&(t.setAttribute("onclick",e),t.removeAttribute("inert-onclick"))})}function D(){document.querySelectorAll(f).forEach(o=>{let t=o.getAttribute("onclick");t&&(o.setAttribute("inert-onclick",t),o.removeAttribute("onclick")),n(o)})}function q(){b(),p()}var O="[viewmode\\:disabled]",S="[viewmode\\:readonly]",u=[[O,"disabled"],[S,"readonly"]];function k(){d(o=>{for(let[t,e]of u)o.querySelectorAll(t).forEach(r=>{if(r.hasAttribute(e))return;let a=l(r),s=a?m(a,e):null;r.setAttribute(e,s===null?"":s),n(r,a??r)})})}function h(){i&&c(()=>{x()})}function x(o=document){for(let[t,e]of u)o.querySelectorAll(t).forEach(r=>{A(r),r.removeAttribute(e)})}function M(){for(let[o,t]of u)document.querySelectorAll(o).forEach(e=>{let r=m(e,t);r===null?e.removeAttribute(t):e.setAttribute(t,r),n(e)})}function P(){k(),h()}export{f as a,E as b,D as c,q as d,O as e,S as f,x as g,M as h,P as i};
@@ -1 +1 @@
1
- import{a as O}from"./c-WN3MXOLT.js";import{d as A}from"./c-RBPZNU2D.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-A7N5TNSL.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-QQFHEODI.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-C5AKJVRH.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,4 +1,4 @@
1
- import{b as x}from"./c-QY7F6EN6.js";import{a as w}from"./c-54ZZZYUN.js";import"./c-I2SCCUEW.js";import"./c-RBPZNU2D.js";import"./c-DLBX4JCJ.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.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-P2HKMJAW.js";import"./c-I2SCCUEW.js";import"./c-QQFHEODI.js";import"./c-EDE45NM7.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-U4NTUVDZ.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;
@@ -1 +1 @@
1
- import{d as A,e as I}from"./c-RBPZNU2D.js";import{f as b,j as T}from"./c-DLBX4JCJ.js";import{c as M}from"./c-BPF2NSPV.js";var B=15e3,P=12e4,K=15e3,V=4e3,W=5e3,U=50,y=new Set(["sent","acked"]),R=new Set(["done","error","cancelled"]),j="wire",a=new Map,k=new Set,f=null,g=null,D=0,h=null;function Q(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`page-${Date.now()}-${Math.random().toString(16).slice(2)}`}function H(e){return new URL(e,window.location.origin).href}function N(){let e=M();return typeof e=="string"&&e!==""?e:null}function w(e){return{id:e.id,type:e.type,state:e.state,helper:e.helper,text:e.text,result:e.result,error:e.error,errorCode:e.errorCode,errorDetails:e.errorDetails,errorSource:e.errorSource,startedAt:e.startedAt}}function m(e,t){let n=w(e);for(let r of k)try{r(n,t||null)}catch(s){console.error("clay.wire: a listener threw",s)}document.dispatchEvent(new CustomEvent("clay:wire-state",{detail:n}))}function Y(e,t){e.state!==t&&(e.state=t,m(e))}function v(e,t,n,{cancelFirst:r=!1,errorCode:s=null}={}){clearTimeout(e.timer),e.timer=setTimeout(()=>{e.timer=null,r&&z(e),l(e,"error",n,{errorCode:s,errorSource:"client"})},t)}function q(e){clearTimeout(e.timer),e.timer=null}function Z(){if(!(a.size<=U))for(let[e,t]of a){if(a.size<=U)break;!y.has(t.state)&&t.state!=="landing"&&a.delete(e)}}function ee(){if(g)return g;let e=N(),t=`/_/wire/subscribe?page-url=${encodeURIComponent(window.location.href)}`+(e?`&token=${encodeURIComponent(e)}`:"");return f=new EventSource(H(t)),f.onmessage=n=>{let r;try{r=JSON.parse(n.data)}catch{return}te(r)},f.onerror=()=>{},g=new Promise(n=>{let r=!1,s=()=>{r||(r=!0,n())};f.onopen=s,setTimeout(s,2e3)}),g}function L(){for(let e of a.values())if(y.has(e.state))return;f&&(f.close(),f=null,g=null)}function te(e){if(!e||typeof e.id!="string")return;let t=a.get(e.id);if(!(!t||!y.has(t.state)))switch(e.type){case"wire/ack":e.payload?.mode==="jsonl"&&Number.isFinite(e.payload.budgetMs)&&e.payload.budgetMs>0?(t.structured=!0,v(t,e.payload.budgetMs+K,"the helper did not finish within its execution budget",{cancelFirst:!0,errorCode:"helper_timeout"})):v(t,P,"the agent stopped responding"),Y(t,"acked");break;case"wire/status":t.structured||v(t,P,"the agent stopped responding"),t.text=typeof e.text=="string"?e.text:"",t.state="acked",ne(t,e),m(t,e);break;case"wire/done":t.result=Object.prototype.hasOwnProperty.call(e,"payload")?e.payload:null,t.document==="edit"?ie(t):l(t,"done",null);break;case"wire/error":re(t,e);break;default:break}}function ne(e,t){if(!e.onStatus||typeof t.text!="string")return;let n={text:t.text};t.payload&&typeof t.payload=="object"&&Object.prototype.hasOwnProperty.call(t.payload,"progress")&&(n.progress=t.payload.progress);try{e.onStatus(n)}catch(r){console.error("clay.wire: an onStatus listener threw",r)}}function re(e,t){let n=t.payload,r=n&&typeof n=="object"&&!Array.isArray(n)&&(n.source==="application"||n.source==="host")&&typeof n.code=="string"&&n.code,s=typeof t.text=="string"&&t.text?t.text:"the handler reported an error";if(!r){l(e,"error",s);return}let i=n.source==="host"&&n.code==="helper_cancelled"?"cancelled":"error";l(e,i,s,{errorCode:n.code,errorDetails:Object.prototype.hasOwnProperty.call(n,"details")?n.details:null,errorSource:n.source})}function oe(){h||(h=e=>{if(e.detail?.source!=="peer"){for(let t of a.values())if(t.state==="landing"){l(t,"done",null);return}}},document.addEventListener("clay:sync-applied",h))}function se(){D>0||!h||(document.removeEventListener("clay:sync-applied",h),h=null)}function ie(e){R.has(e.state)||e.state==="landing"||(q(e),e.state="landing",D++,oe(),e.landingTimer=setTimeout(()=>{l(e,"done",null)},V),m(e),L())}function l(e,t,n,r={}){if(R.has(e.state))return;let s=e.state==="landing";if(q(e),clearTimeout(e.landingTimer),e.landingTimer=null,e.abort?.abort(),s&&(D--,se()),e.error=n,Object.prototype.hasOwnProperty.call(r,"errorCode")&&(e.errorCode=r.errorCode),Object.prototype.hasOwnProperty.call(r,"errorDetails")&&(e.errorDetails=r.errorDetails),Object.prototype.hasOwnProperty.call(r,"errorSource")&&(e.errorSource=r.errorSource),e.state=t,e.signal&&e.signalHandler&&(e.signal.removeEventListener("abort",e.signalHandler),e.signalHandler=null),ue(e),m(e),L(),Z(),e.settle){let i=e.settle;e.settle=null,i(w(e))}}var C=0,$=null,E=null;function ae(){return E||(E=import("./core/save-FV4ZCKBI.js")),E}async function le(e){if(!b||e.holdsSave)return;let t=await ae();e.state==="sent"&&($=t,e.holdsSave=!0,!(C++>0)&&t.suspendAutosave())}function ue(e){e.holdsSave&&(e.holdsSave=!1,!(--C>0)&&(C=0,$?.resumeAutosave()))}var c=null,de=()=>!c||c.admitted,ce=(e,t,n)=>Object.assign(new Error(`clay.wire: ${e}`),{code:t,pending:n});function O(e){return e.document!=="edit"||e.generation===T().generation&&de()?!0:(l(e,"error","the page changed mode before this request went out",{errorCode:"stale-document",errorSource:"client"}),!1)}function _e(){return{id:"clay:wire",order:900,prepare(e={}){let t={admitted:e.initial===!0};return c=t,{enable(){c===t&&(t.admitted=!0)},quiesce(){if(c!==t)return;t.admitted=!1;let n=[...a.values()].filter(r=>r.document==="edit"&&(r.holdsSave||y.has(r.state))).map(r=>r.id);if(n.length)throw ce("a request on this page has not settled","pending-input",n)},resume(){c===t&&(t.admitted=!0)},dispose(){c===t&&(c=null)}}}}}function fe(e,t){return new Promise(n=>{let r=!1,s=()=>{r||(r=!0,document.removeEventListener(e,s),n())};document.addEventListener(e,s),setTimeout(s,t)})}async function pe(){if(!b)return;let e=window.clay;if(!e||typeof e.save!="function")return;let{isSaveInProgress:t}=await import("./core/save-core-K7XFAWQ4.js"),{savesHeld:n,saveHoldReason:r}=await import("./core/save-FV4ZCKBI.js");if(n())throw new Error(r());let s=Date.now()+W;for(let i=0;i<3;i++){t()&&await fe("clay:save-saved",Math.max(0,s-Date.now()));let u=await e.save();if(u?.ok||u?.msgType==="skipped"&&!t())return;if(u?.msgType==="error"||u?.msgType==="unknown")throw new Error(`could not save this page first: ${u.msg||u.msgType}`);if(Date.now()>=s)break}throw new Error("could not save this page before sending")}async function F(e,t){let n={"Content-Type":"application/json","Page-URL":window.location.href},r=N();r&&(n["Save-Token"]=r);let s=await fetch(H("/_/wire/send"),{method:"POST",headers:n,body:JSON.stringify(e),signal:t}),i=null;try{i=await s.json()}catch{i=null}return{ok:s.ok,status:s.status,reply:i}}function he(e,t={}){let n=typeof t.id=="string"&&t.id?t.id:Q(),r=typeof t.type=="string"&&t.type?t.type:"wire/request",s=Object.prototype.hasOwnProperty.call(t,"helper"),i=s&&typeof t.helper=="string"&&t.helper?t.helper:null,u=t.document===void 0?i?"none":"edit":t.document;if(s&&!i)return _(n,r,null,"helper must be a nonempty string","invalid_helper");if(u!=="edit"&&u!=="none")return _(n,r,i,'document must be "edit" or "none"',"invalid_document");if(a.has(n))return _(n,r,i,"a request with this id is already on the wire","duplicate_request");let o={id:n,type:r,state:"sent",helper:i,document:u,structured:!1,onStatus:typeof t.onStatus=="function"?t.onStatus:null,text:"",result:null,error:null,errorCode:null,errorDetails:null,errorSource:null,startedAt:Date.now(),timer:null,landingTimer:null,abort:typeof AbortController=="function"?new AbortController:null,holdsSave:!1,generation:T().generation,settle:null,signal:t.signal&&typeof t.signal.addEventListener=="function"?t.signal:null,signalHandler:null};return o.done=new Promise(d=>{o.settle=d}),a.set(n,o),m(o),o.signal&&(o.signalHandler=()=>x(n),o.signal.addEventListener("abort",o.signalHandler,{once:!0}),o.signal.aborted&&o.signalHandler()),(async()=>{if(o.state!=="sent")return;if(o.helper){let X=await I(j);if(o.state!=="sent")return;if(!X){l(o,"error","this host does not support named wire helpers",{errorCode:"helper_protocol_unsupported",errorSource:"client"});return}}if(!O(o)||o.document==="edit"&&(await le(o),o.state!=="sent"||!O(o)||(await pe(),o.state!=="sent")||!O(o)))return;if(await ee(),o.state!=="sent"){L();return}v(o,B,"the agent never answered",o.helper?{cancelFirst:!0,errorCode:"ack_timeout"}:void 0);let d={type:o.type,id:o.id,text:t.text,payload:e};o.helper&&(d.helper=o.helper),(o.helper||t.document!==void 0)&&(d.document=o.document);let{ok:G,status:J,reply:S}=await F(d,o.abort?.signal);if(o.state!=="sent")return;if(!G){l(o,"error",`the wire refused this request (${J})`);return}let p=S&&S.refused;if(p&&typeof p.code=="string"&&p.code){l(o,"error",p.message||"the handler refused this request",{errorCode:p.code,errorSource:p.source==="application"?"application":"host",errorDetails:null});return}(!S||S.delivered===0)&&l(o,"error",o.helper?`The local program "${o.helper}" is not connected to this file.`:"No program is connected to this file.")})().catch(d=>{l(o,"error",d&&d.message?d.message:String(d))}),{id:n,get state(){return o.state},done:o.done,cancel:()=>x(n)}}function _(e,t,n,r,s){let i={id:e,type:t,state:"error",helper:n,text:"",result:null,error:r,errorCode:s,errorDetails:null,errorSource:"client",startedAt:Date.now()};return{id:e,get state(){return i.state},done:Promise.resolve(w(i)),cancel:()=>!1}}function x(e){let t=a.get(e);return!t||!y.has(t.state)?!1:(z(t),l(t,"cancelled",null),!0)}function z(e){F({type:"wire/cancel",id:e.id}).catch(()=>{})}function ye(e){let t=a.get(e);return t?w(t):void 0}function ge(){return[...a.values()].map(w)}function we(){for(let e of a.values())if(y.has(e.state))return!0;return!1}function me(e){return typeof e!="function"?()=>{}:(k.add(e),()=>k.delete(e))}async function Se(){let e=await A({fresh:!0});if(!e.extensions.includes(j))return[];let t=e.document?.helpers;return Array.isArray(t)?t.filter(n=>n&&typeof n.name=="string"&&["ready","denied","unavailable"].includes(n.state)).map(({name:n,state:r})=>({name:n,state:r})):[]}var ve={send:he,cancel:x,get:ye,list:ge,isBusy:we,on:me,helpers:Se},ke=ve;export{_e as a,ve as b,ke as c};
1
+ import{d as A,e as I}from"./c-QQFHEODI.js";import{f as b,j as T}from"./c-EDE45NM7.js";import{c as M}from"./c-BPF2NSPV.js";var B=15e3,P=12e4,K=15e3,V=4e3,W=5e3,U=50,y=new Set(["sent","acked"]),R=new Set(["done","error","cancelled"]),j="wire",a=new Map,k=new Set,f=null,g=null,D=0,h=null;function Q(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`page-${Date.now()}-${Math.random().toString(16).slice(2)}`}function H(e){return new URL(e,window.location.origin).href}function N(){let e=M();return typeof e=="string"&&e!==""?e:null}function w(e){return{id:e.id,type:e.type,state:e.state,helper:e.helper,text:e.text,result:e.result,error:e.error,errorCode:e.errorCode,errorDetails:e.errorDetails,errorSource:e.errorSource,startedAt:e.startedAt}}function m(e,t){let n=w(e);for(let r of k)try{r(n,t||null)}catch(s){console.error("clay.wire: a listener threw",s)}document.dispatchEvent(new CustomEvent("clay:wire-state",{detail:n}))}function Y(e,t){e.state!==t&&(e.state=t,m(e))}function v(e,t,n,{cancelFirst:r=!1,errorCode:s=null}={}){clearTimeout(e.timer),e.timer=setTimeout(()=>{e.timer=null,r&&z(e),l(e,"error",n,{errorCode:s,errorSource:"client"})},t)}function q(e){clearTimeout(e.timer),e.timer=null}function Z(){if(!(a.size<=U))for(let[e,t]of a){if(a.size<=U)break;!y.has(t.state)&&t.state!=="landing"&&a.delete(e)}}function ee(){if(g)return g;let e=N(),t=`/_/wire/subscribe?page-url=${encodeURIComponent(window.location.href)}`+(e?`&token=${encodeURIComponent(e)}`:"");return f=new EventSource(H(t)),f.onmessage=n=>{let r;try{r=JSON.parse(n.data)}catch{return}te(r)},f.onerror=()=>{},g=new Promise(n=>{let r=!1,s=()=>{r||(r=!0,n())};f.onopen=s,setTimeout(s,2e3)}),g}function L(){for(let e of a.values())if(y.has(e.state))return;f&&(f.close(),f=null,g=null)}function te(e){if(!e||typeof e.id!="string")return;let t=a.get(e.id);if(!(!t||!y.has(t.state)))switch(e.type){case"wire/ack":e.payload?.mode==="jsonl"&&Number.isFinite(e.payload.budgetMs)&&e.payload.budgetMs>0?(t.structured=!0,v(t,e.payload.budgetMs+K,"the helper did not finish within its execution budget",{cancelFirst:!0,errorCode:"helper_timeout"})):v(t,P,"the agent stopped responding"),Y(t,"acked");break;case"wire/status":t.structured||v(t,P,"the agent stopped responding"),t.text=typeof e.text=="string"?e.text:"",t.state="acked",ne(t,e),m(t,e);break;case"wire/done":t.result=Object.prototype.hasOwnProperty.call(e,"payload")?e.payload:null,t.document==="edit"?ie(t):l(t,"done",null);break;case"wire/error":re(t,e);break;default:break}}function ne(e,t){if(!e.onStatus||typeof t.text!="string")return;let n={text:t.text};t.payload&&typeof t.payload=="object"&&Object.prototype.hasOwnProperty.call(t.payload,"progress")&&(n.progress=t.payload.progress);try{e.onStatus(n)}catch(r){console.error("clay.wire: an onStatus listener threw",r)}}function re(e,t){let n=t.payload,r=n&&typeof n=="object"&&!Array.isArray(n)&&(n.source==="application"||n.source==="host")&&typeof n.code=="string"&&n.code,s=typeof t.text=="string"&&t.text?t.text:"the handler reported an error";if(!r){l(e,"error",s);return}let i=n.source==="host"&&n.code==="helper_cancelled"?"cancelled":"error";l(e,i,s,{errorCode:n.code,errorDetails:Object.prototype.hasOwnProperty.call(n,"details")?n.details:null,errorSource:n.source})}function oe(){h||(h=e=>{if(e.detail?.source!=="peer"){for(let t of a.values())if(t.state==="landing"){l(t,"done",null);return}}},document.addEventListener("clay:sync-applied",h))}function se(){D>0||!h||(document.removeEventListener("clay:sync-applied",h),h=null)}function ie(e){R.has(e.state)||e.state==="landing"||(q(e),e.state="landing",D++,oe(),e.landingTimer=setTimeout(()=>{l(e,"done",null)},V),m(e),L())}function l(e,t,n,r={}){if(R.has(e.state))return;let s=e.state==="landing";if(q(e),clearTimeout(e.landingTimer),e.landingTimer=null,e.abort?.abort(),s&&(D--,se()),e.error=n,Object.prototype.hasOwnProperty.call(r,"errorCode")&&(e.errorCode=r.errorCode),Object.prototype.hasOwnProperty.call(r,"errorDetails")&&(e.errorDetails=r.errorDetails),Object.prototype.hasOwnProperty.call(r,"errorSource")&&(e.errorSource=r.errorSource),e.state=t,e.signal&&e.signalHandler&&(e.signal.removeEventListener("abort",e.signalHandler),e.signalHandler=null),ue(e),m(e),L(),Z(),e.settle){let i=e.settle;e.settle=null,i(w(e))}}var C=0,$=null,E=null;function ae(){return E||(E=import("./core/save-6HT2LABE.js")),E}async function le(e){if(!b||e.holdsSave)return;let t=await ae();e.state==="sent"&&($=t,e.holdsSave=!0,!(C++>0)&&t.suspendAutosave())}function ue(e){e.holdsSave&&(e.holdsSave=!1,!(--C>0)&&(C=0,$?.resumeAutosave()))}var c=null,de=()=>!c||c.admitted,ce=(e,t,n)=>Object.assign(new Error(`clay.wire: ${e}`),{code:t,pending:n});function O(e){return e.document!=="edit"||e.generation===T().generation&&de()?!0:(l(e,"error","the page changed mode before this request went out",{errorCode:"stale-document",errorSource:"client"}),!1)}function _e(){return{id:"clay:wire",order:900,prepare(e={}){let t={admitted:e.initial===!0};return c=t,{enable(){c===t&&(t.admitted=!0)},quiesce(){if(c!==t)return;t.admitted=!1;let n=[...a.values()].filter(r=>r.document==="edit"&&(r.holdsSave||y.has(r.state))).map(r=>r.id);if(n.length)throw ce("a request on this page has not settled","pending-input",n)},resume(){c===t&&(t.admitted=!0)},dispose(){c===t&&(c=null)}}}}}function fe(e,t){return new Promise(n=>{let r=!1,s=()=>{r||(r=!0,document.removeEventListener(e,s),n())};document.addEventListener(e,s),setTimeout(s,t)})}async function pe(){if(!b)return;let e=window.clay;if(!e||typeof e.save!="function")return;let{isSaveInProgress:t}=await import("./core/save-core-EVMNZQ4V.js"),{savesHeld:n,saveHoldReason:r}=await import("./core/save-6HT2LABE.js");if(n())throw new Error(r());let s=Date.now()+W;for(let i=0;i<3;i++){t()&&await fe("clay:save-saved",Math.max(0,s-Date.now()));let u=await e.save();if(u?.ok||u?.msgType==="skipped"&&!t())return;if(u?.msgType==="error"||u?.msgType==="unknown")throw new Error(`could not save this page first: ${u.msg||u.msgType}`);if(Date.now()>=s)break}throw new Error("could not save this page before sending")}async function F(e,t){let n={"Content-Type":"application/json","Page-URL":window.location.href},r=N();r&&(n["Save-Token"]=r);let s=await fetch(H("/_/wire/send"),{method:"POST",headers:n,body:JSON.stringify(e),signal:t}),i=null;try{i=await s.json()}catch{i=null}return{ok:s.ok,status:s.status,reply:i}}function he(e,t={}){let n=typeof t.id=="string"&&t.id?t.id:Q(),r=typeof t.type=="string"&&t.type?t.type:"wire/request",s=Object.prototype.hasOwnProperty.call(t,"helper"),i=s&&typeof t.helper=="string"&&t.helper?t.helper:null,u=t.document===void 0?i?"none":"edit":t.document;if(s&&!i)return _(n,r,null,"helper must be a nonempty string","invalid_helper");if(u!=="edit"&&u!=="none")return _(n,r,i,'document must be "edit" or "none"',"invalid_document");if(a.has(n))return _(n,r,i,"a request with this id is already on the wire","duplicate_request");let o={id:n,type:r,state:"sent",helper:i,document:u,structured:!1,onStatus:typeof t.onStatus=="function"?t.onStatus:null,text:"",result:null,error:null,errorCode:null,errorDetails:null,errorSource:null,startedAt:Date.now(),timer:null,landingTimer:null,abort:typeof AbortController=="function"?new AbortController:null,holdsSave:!1,generation:T().generation,settle:null,signal:t.signal&&typeof t.signal.addEventListener=="function"?t.signal:null,signalHandler:null};return o.done=new Promise(d=>{o.settle=d}),a.set(n,o),m(o),o.signal&&(o.signalHandler=()=>x(n),o.signal.addEventListener("abort",o.signalHandler,{once:!0}),o.signal.aborted&&o.signalHandler()),(async()=>{if(o.state!=="sent")return;if(o.helper){let X=await I(j);if(o.state!=="sent")return;if(!X){l(o,"error","this host does not support named wire helpers",{errorCode:"helper_protocol_unsupported",errorSource:"client"});return}}if(!O(o)||o.document==="edit"&&(await le(o),o.state!=="sent"||!O(o)||(await pe(),o.state!=="sent")||!O(o)))return;if(await ee(),o.state!=="sent"){L();return}v(o,B,"the agent never answered",o.helper?{cancelFirst:!0,errorCode:"ack_timeout"}:void 0);let d={type:o.type,id:o.id,text:t.text,payload:e};o.helper&&(d.helper=o.helper),(o.helper||t.document!==void 0)&&(d.document=o.document);let{ok:G,status:J,reply:S}=await F(d,o.abort?.signal);if(o.state!=="sent")return;if(!G){l(o,"error",`the wire refused this request (${J})`);return}let p=S&&S.refused;if(p&&typeof p.code=="string"&&p.code){l(o,"error",p.message||"the handler refused this request",{errorCode:p.code,errorSource:p.source==="application"?"application":"host",errorDetails:null});return}(!S||S.delivered===0)&&l(o,"error",o.helper?`The local program "${o.helper}" is not connected to this file.`:"No program is connected to this file.")})().catch(d=>{l(o,"error",d&&d.message?d.message:String(d))}),{id:n,get state(){return o.state},done:o.done,cancel:()=>x(n)}}function _(e,t,n,r,s){let i={id:e,type:t,state:"error",helper:n,text:"",result:null,error:r,errorCode:s,errorDetails:null,errorSource:"client",startedAt:Date.now()};return{id:e,get state(){return i.state},done:Promise.resolve(w(i)),cancel:()=>!1}}function x(e){let t=a.get(e);return!t||!y.has(t.state)?!1:(z(t),l(t,"cancelled",null),!0)}function z(e){F({type:"wire/cancel",id:e.id}).catch(()=>{})}function ye(e){let t=a.get(e);return t?w(t):void 0}function ge(){return[...a.values()].map(w)}function we(){for(let e of a.values())if(y.has(e.state))return!0;return!1}function me(e){return typeof e!="function"?()=>{}:(k.add(e),()=>k.delete(e))}async function Se(){let e=await A({fresh:!0});if(!e.extensions.includes(j))return[];let t=e.document?.helpers;return Array.isArray(t)?t.filter(n=>n&&typeof n.name=="string"&&["ready","denied","unavailable"].includes(n.state)).map(({name:n,state:r})=>({name:n,state:r})):[]}var ve={send:he,cancel:x,get:ye,list:ge,isBusy:we,on:me,helpers:Se},ke=ve;export{_e as a,ve as b,ke as c};
@@ -1 +1 @@
1
- import{b as k,d as l,e as i}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-N7JPUPGC.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}return t?.v!==1||t.path!==location.pathname||t.mode!=="edit"&&t.mode!=="view"||Date.now()-t.at>R||!t.internal&&T()!=="reload"?null:t}function J({mode:e,canEdit:t,internal:s}){try{sessionStorage.setItem(w(),JSON.stringify({v:1,path:location.pathname,mode:e,canEdit:t,at:Date.now(),internal:s}))}catch{}}var o=null;typeof window<"u"&&(window.clayEditMode!=null?o=!!window.clayEditMode:window.__hyperclayEditMode!=null&&(o=!!window.__hyperclayEditMode));var r=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)&&!r&&!i()&&o==null&&!l(),u=typeof window<"u"?P():null,x=typeof document<"u"&&document.documentElement.getAttribute("opens-in")==="edit",D=g?!r&&!i()&&o!==!1:n.editmode?n.editmode==="true"||!r&&!i()&&(o??(l()||p)):r||i()?!1:o??(l()||p),V=u?.canEdit===!0&&o!==!1&&!i()&&!(r&&n.editmode!=="true"),h=D||V,q=y||i()||o===!1||n.editmode==="false"||r&&n.editmode!=="true",m=h,I=null;function z(e){I=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 I}var F=u?u.mode==="edit"||x&&!u.internal:n.editmode&&!g?n.editmode==="true":o===!0||x,d=y?!0:m&&F,O=y?"draft":d?"edit":"view",Y=p,c={phase:"idle",destination:y?"draft":"host",generation:0,reason:null};function Z(e){e.mode!==void 0&&(O=e.mode),e.isEditMode!==void 0&&(d=e.isEditMode,typeof window<"u"&&(window.__hyperclayEditMode=d)),e.canEdit!==void 0&&(m=e.canEdit);for(let t in c)e[t]!==void 0&&(c[t]=e[t])}var U=()=>({mode:O,...c});function ee(){return d&&U().phase==="idle"}var a=typeof window>"u"||!window.clay?[]:(window.clay.modeParticipants||Object.defineProperty(window.clay,"modeParticipants",{value:[],writable:!0,configurable:!0}),window.clay.modeParticipants),f=new Set,_=()=>{},te=e=>_=e,ne=()=>a.slice(),E=e=>{throw new TypeError(`clay.modeLifecycle: ${e}`)},W=()=>{(c.phase!=="idle"||d)&&E("the page is not idle in view")},C=()=>{c.phase==="blocked"&&!d||W()};function oe(){return f.clear(),a.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}"`),C(),f.add(t),a.push(e);let s=!0;return()=>{if(!s)return;C(),s=!1,f.delete(t);let v=a.indexOf(e);v!==-1&&a.splice(v,1),_(t)}}var re=k;export{J as a,y as b,m as c,z as d,Q as e,d as f,O 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
+ import{b as k,d as l,e as i}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-U4NTUVDZ.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}return t?.v!==1||t.path!==location.pathname||t.mode!=="edit"&&t.mode!=="view"||Date.now()-t.at>R||!t.internal&&T()!=="reload"?null:t}function J({mode:e,canEdit:t,internal:s}){try{sessionStorage.setItem(w(),JSON.stringify({v:1,path:location.pathname,mode:e,canEdit:t,at:Date.now(),internal:s}))}catch{}}var o=null;typeof window<"u"&&(window.clayEditMode!=null?o=!!window.clayEditMode:window.__hyperclayEditMode!=null&&(o=!!window.__hyperclayEditMode));var r=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)&&!r&&!i()&&o==null&&!l(),u=typeof window<"u"?P():null,x=typeof document<"u"&&document.documentElement.getAttribute("opens-in")==="edit",D=g?!r&&!i()&&o!==!1:n.editmode?n.editmode==="true"||!r&&!i()&&(o??(l()||p)):r||i()?!1:o??(l()||p),V=u?.canEdit===!0&&o!==!1&&!i()&&!(r&&n.editmode!=="true"),h=D||V,q=y||i()||o===!1||n.editmode==="false"||r&&n.editmode!=="true",m=h,I=null;function z(e){I=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 I}var F=u?u.mode==="edit"||x&&!u.internal:n.editmode&&!g?n.editmode==="true":o===!0||x,d=y?!0:m&&F,O=y?"draft":d?"edit":"view",Y=p,c={phase:"idle",destination:y?"draft":"host",generation:0,reason:null};function Z(e){e.mode!==void 0&&(O=e.mode),e.isEditMode!==void 0&&(d=e.isEditMode,typeof window<"u"&&(window.__hyperclayEditMode=d)),e.canEdit!==void 0&&(m=e.canEdit);for(let t in c)e[t]!==void 0&&(c[t]=e[t])}var U=()=>({mode:O,...c});function ee(){return d&&U().phase==="idle"}var a=typeof window>"u"||!window.clay?[]:(window.clay.modeParticipants||Object.defineProperty(window.clay,"modeParticipants",{value:[],writable:!0,configurable:!0}),window.clay.modeParticipants),f=new Set,_=()=>{},te=e=>_=e,ne=()=>a.slice(),E=e=>{throw new TypeError(`clay.modeLifecycle: ${e}`)},W=()=>{(c.phase!=="idle"||d)&&E("the page is not idle in view")},C=()=>{c.phase==="blocked"&&!d||W()};function oe(){return f.clear(),a.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}"`),C(),f.add(t),a.push(e);let s=!0;return()=>{if(!s)return;C(),s=!1,f.delete(t);let v=a.indexOf(e);v!==-1&&a.splice(v,1),_(t)}}var re=k;export{J as a,y as b,m as c,z as d,Q as e,d as f,O 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};
@@ -0,0 +1 @@
1
+ import{j as z}from"./c-U4NTUVDZ.js";import"./c-VHNSBD2M.js";function M(e){let n=e?.name||"";return n==="QuotaExceededError"||n==="NS_ERROR_DOM_QUOTA_REACHED"?"quota":n==="VersionError"?"unknown-schema":n==="DataCloneError"?"uncloneable":n==="AbortError"||n==="TransactionInactiveError"||n==="InvalidStateError"?"aborted":n==="SecurityError"||n==="UnknownError"||n==="NotSupportedError"?"unavailable":"error"}var ve="clay-visitor-drafts",Se=1,P="records",Y="parts",Ee=2e3;function T(e,n){let p=new Error(`visitor-drafts: the draft database failed (${e})`);return p.code=e,n!==void 0&&(p.cause=n),p}function ue(e,n){return new Promise((p,w)=>{let b=[],f=e.openCursor(n);f.onerror=()=>w(f.error),f.onsuccess=()=>{let o=f.result;if(!o)return p(b);b.push([o.key,o.value]),o.continue()}})}function de({factory:e=globalThis.indexedDB,keyRange:n=globalThis.IDBKeyRange,name:p=ve,timeout:w=Ee}={}){return new Promise((b,f)=>{if(!e||typeof e.open!="function"||!n)return f(T("unavailable"));let o;try{o=e.open(p,Se)}catch(d){return f(T(M(d),d))}let S=!1,u=(d,h)=>S?!1:(S=!0,clearTimeout(t),d(h),!0),t=setTimeout(()=>u(f,T("blocked")),w);o.onupgradeneeded=()=>{let d=o.result;d.objectStoreNames.contains(P)||d.createObjectStore(P),d.objectStoreNames.contains(Y)||d.createObjectStore(Y)},o.onsuccess=()=>{let d=o.result;u(b,Oe(d,n))||d.close()},o.onerror=()=>u(f,T(M(o.error),o.error)),o.onblocked=()=>u(f,T("blocked"))})}function Oe(e,n){let p=!1;e.onversionchange=()=>{p=!0;try{e.close()}catch{}};function w(t,d){if(p)throw T("closed");try{return e.transaction(t,d)}catch(h){throw T(M(h),h)}}async function b(t){let d=w(P,"readonly"),h=n.bound(t,t+":\uFFFF");try{let s=await ue(d.objectStore(P),h);return new Map(s.filter(([i])=>i===t||i.startsWith(t+":")))}catch(s){throw T(M(s),s)}}async function f(t,d){let h=w(Y,"readonly"),s=n.bound([t,d],[t,d,[]]);try{let i=await ue(h.objectStore(Y),s);return new Map(i.map(([y,g])=>[y[2],g]))}catch(i){throw T(M(i),i)}}function o(t,d,{timeout:h=0}={}){return new Promise((s,i)=>{let y;try{y=w([P,Y],"readwrite")}catch(l){return i(l)}let g=null,k,D=!1,c,E=(l,v)=>{D||(D=!0,clearTimeout(c),l(v))};h>0&&(c=setTimeout(()=>{g=T("blocked");try{y.abort()}catch{}E(i,g)},h)),y.oncomplete=()=>E(s,k),y.onabort=()=>E(i,g||T(y.error?M(y.error):"aborted",y.error));try{let l=y.objectStore(P),v=n.bound(t+":op:",t+":op:\uFFFF"),O={record:l.get(t),meta:l.get(t+":meta"),v1base:l.get(t+":v1base"),names:l.getAllKeys(v),values:l.getAll(v)};O.values.onsuccess=()=>{if(!D)try{let R={record:O.record.result??null,meta:O.meta.result??null,v1base:O.v1base.result??null,rows:O.names.result.map((N,F)=>[N,O.values.result[F]])},x=d(R);for(let[N,F]of x.puts)l.put(F,N);for(let N of x.deletes)l.delete(N);k=x.result}catch(R){g=T(M(R),R);try{y.abort()}catch{}}}}catch(l){g=T(M(l),l);try{y.abort()}catch{}}})}function S(t,d){return new Promise((h,s)=>{if(!/:op:[^:]+$/.test(t))return s(T("bad-op"));let i;try{i=w(P,"readwrite"),i.objectStore(P).put(d,t),i.commit?.()}catch(y){return s(y instanceof Error&&y.code?y:T(M(y),y))}i.oncomplete=()=>h(),i.onabort=()=>s(T(i.error?M(i.error):"aborted",i.error))})}function u(){p=!0;try{e.close()}catch{}}return{readAll:b,readParts:f,change:o,putRow:S,close:u}}var _=e=>e===void 0?void 0:JSON.parse(JSON.stringify(e)),K=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),Ae=e=>e+":meta",se=(e,n)=>`${e}:op:${n}`,le=(e,n)=>n===void 0?e+":conflict":`${e}:conflict:${n}`,Z=(e,n)=>`${e}:recovery:${n}`,H=e=>K(e)&&e.v===1&&e.w===void 0&&K(e.data),J=e=>typeof e.id=="string"?e.id:"at:"+e.savedAt,he=(e,n)=>`${e}~${n}`;function Q(e){let n=/^(\d+)~/.exec(e??"");return n?Number(n[1]):null}function Ie(e,n,p){let w={...e},b={...e};for(let[f,o]of Object.entries(n))"b"in o?w[f]=o.b:delete w[f],"m"in o?b[f]=o.m:delete b[f];return p(w,b,e)}var oe=e=>K(e)&&typeof e.tab=="string"&&typeof e.reset=="string"&&Array.isArray(e.ops),$=e=>oe(e)?`op:${e.tab}:${e.ops.at(-1)?.seq??e.acked??0}`:J(e);function ie(e,n){if(K(e)&&n.recovery?.includes($(e)))return!0;if(!oe(e))return!1;let p=Math.max(e.acked??0,e.reset===n.reset?n.tabs[e.tab]?.seq??0:0);return e.ops.every(w=>w.seq<=p)}function ae(e=null){return{gen:Q(e)??1,rev:0,reset:e??"",tabs:{},foreign:null,unit:null}}var q=e=>e&&e.blockeditor?{live:e.live,blockeditor:e.blockeditor}:null;function pe(e,n,p){let w=[...e,n?.id,...n?.ancestry??[]].filter(b=>typeof b=="string");return w.length?w.slice(0,32):["root:"+p.reset]}function ke(e,{record:n,seen:p,direct:w,v1base:b,meta:f}){let o=K(p)&&p.v===1&&K(p.data)&&p.w?.reset===f.reset?p:null,S=t=>t&&typeof t.id=="string"?e.indexOf(t.id):-1,u=[[n,S(n)],[o,o&&w?0:S(o)],[b,S(b)]].filter(([,t])=>t>=0);return u.length?u.reduce((t,d)=>d[1]<t[1]?d:t)[0]:null}function Te(e,{seed:n,newId:p,now:w,merge3:b,unitMark:f,marker:o=null,resets:S=[],chains:u=[],local:t=null,seen:d=null,direct:h=!1}){let s=e.meta?_(e.meta):ae(o);!e.meta&&Number.isInteger(t?.w?.rev)&&(s.rev=t.w.rev);let i=e.record?_(e.record):null,y=e.v1base?_(e.v1base):null,g={conflicts:[],recovered:[],released:[],dropped:[],stale:[],applied:{},changed:!e.meta};function k(c,E=[]){let l=$(c);if(s.recovery?.includes(l))return;g.recovered.push(_(c));let v=[l,...(s.recovery??[]).filter(O=>O!==l&&!E.includes(O))].slice(0,8);return g.dropped=[...new Set([...g.dropped,...s.recovery??[]])].filter(O=>!v.includes(O)),s.recovery=v,g.changed=!0,!0}let D=[...S];o&&o!==s.reset&&D.push({ends:Q(o)===null?null:Q(o)-1,marker:o});for(let c of D){if(c.marker===s.reset||s.ended?.includes(c.marker)||c.ends!==null&&c.ends<s.gen)continue;c.ends!==s.gen&&i&&k(i);let E=typeof t?.reset=="string"?t.reset===c.marker:c.ends===null||Array.isArray(t?.ancestry)&&t.ancestry.includes("root:"+c.marker);H(t)&&J(t)!==s.foreign&&!E&&(k(t),s.foreign=J(t)),s.ended=[...s.ended??[],s.reset].slice(-32),Object.assign(s,{gen:s.gen+1,reset:c.marker,tabs:{},unit:null}),s.rev++,i=null,y=null,g.changed=!0}if(!e.meta&&!i&&K(t)&&t.v===1&&K(t.data)&&(t.w===void 0||t.w.reset===s.reset)){let{w:c,...E}=t;i=_(E),c===void 0&&(y=_(E),s.foreign=J(t),s.rev++)}if(e.meta||(s.unit=f(q(i))),e.meta&&H(t)&&J(t)!==s.foreign){let c=J(t),E=Array.isArray(t.ancestry)?t.ancestry:[],l=i?ke(E,{record:i,seen:d,direct:h,v1base:y,meta:s}):null;if(typeof t.reset=="string"&&s.ended?.includes(t.reset))k(t,E)&&g.released.push(_(t));else if(!i)i=_(t),y=_(t),s.unit=f(q(i)),s.rev++;else if(l){let v=b(l.data,t.data,i.data),O=q(t),R=!!O&&f(O)!==f(q(l)),x=R&&q(i)&&f(q(l))!==s.unit;(v.conflict||x)&&g.conflicts.push(_(i));let N=R?O:q(i);i={v:1,savedAt:t.savedAt??new Date(w).toISOString(),id:p(),ancestry:pe(typeof t.id=="string"?[t.id]:[],i,s),data:v.value,...N&&{live:N.live,blockeditor:N.blockeditor}},R&&(s.unit=f(N)),y=_(t),s.rev++}else k(t,E)&&g.released.push(_(t));s.foreign=c,g.changed=!0}for(let c of u){if(!oe(c))continue;if(c.reset!==s.reset){let v=c.reset===e.meta?.reset?e.meta.tabs[c.tab]?.seq??0:0;c.ops.some(O=>O.seq>Math.max(v,c.acked??0))&&k(c),g.stale.includes(c.tab)||g.stale.push(c.tab);continue}let E=s.tabs[c.tab]?.seq??0,l=Math.max(E,Number.isInteger(c.acked)?c.acked:0);for(let v of c.ops){if(v.seq<=l)continue;if(v.seq!==l+1)break;let O=Ie(i?i.data:n,v.keys??{},b),R=v.unit!==void 0&&i&&q(i)&&v.unit.seen!==s.unit;i&&(O.conflict||R)&&g.conflicts.push(_(i));let x=v.unit!==void 0?v.unit.to:q(i),N=p();i={v:1,savedAt:v.savedAt??new Date(w).toISOString(),id:N,ancestry:pe([],i,s),data:O.value,...x&&{live:x.live,blockeditor:x.blockeditor}},v.unit!==void 0&&(s.unit=f(x)),s.rev++,l=v.seq,g.changed=!0}(l!==E||s.tabs[c.tab])&&(s.tabs[c.tab]={seq:l,at:w},g.changed=!0),g.applied[c.tab]=l}for(let[c,E]of Object.entries(s.tabs))w-(E.at??0)>2592e6&&(delete s.tabs[c],g.changed=!0);return{meta:s,record:i,v1base:y,...g}}var X=e=>{if(e==null)return null;try{return JSON.parse(e)}catch{return null}};function me(e,n,p,w){return e.change(n,b=>{let f={meta:X(b.meta),record:X(b.record),v1base:X(b.v1base)},o=b.rows.map(([h,s])=>[h,X(s)]),S=p(f),u=Te(f,{...S,chains:[...o.map(([,h])=>h),...S.chains??[]]}),t=[],d=[];u.changed&&(t.push([Ae(n),JSON.stringify(u.meta)]),u.record?t.push([n,JSON.stringify(u.record)]):f.record&&d.push(n),u.v1base?t.push([n+":v1base",JSON.stringify(u.v1base)]):f.v1base&&d.push(n+":v1base"));for(let h of u.conflicts)t.push([le(n,J(h)),JSON.stringify(h)]);u.conflicts.length&&t.push([le(n),JSON.stringify(u.conflicts[u.conflicts.length-1])]);for(let h of u.recovered)t.push([Z(n,$(h)),JSON.stringify(h)]);for(let h of u.dropped)d.push(Z(n,h));for(let[h,s]of o)ie(s,u.meta)&&d.push(h);return{puts:t,deletes:d,result:u}},w)}var xe=256*1024,Ne=2*1024,_e=new Set(["v","savedAt","id","ancestry","reset","data"]),Re=10*1e3,Me=1500,ge=2e3,De="This draft was started over in another tab.",qe="This draft was started over in another tab. The earlier draft was kept aside in this browser.",Je="A tab that was open before an update saved another copy of this draft. That copy was kept aside, and this draft was not changed. Reload that tab to go on from this draft.",B=e=>{if(e==null)return null;try{return JSON.parse(e)}catch{return null}};function Pe(e,n){let p={},w=Object.keys(e).every(b=>_e.has(b));for(let[b,f]of Object.entries(e.data))JSON.stringify(f).length<Ne?p[b]=f:w=!1;return JSON.stringify({v:2,savedAt:e.savedAt,id:e.id,ancestry:e.ancestry,idb:!0,...w&&{full:!0},data:p,w:n})}async function je({store:e,storage:n,doc:p=document,now:w=()=>Date.now(),reload:b=()=>window.location.reload()}){let f=await de(),{key:o}=e,S=o+":reset",u=r=>{try{return n?.getItem(r)??null}catch{return null}},t=r=>{try{n?.removeItem(r)}catch{}},d=o+":started-over",h=o+":recovery-notice";try{window.sessionStorage.getItem(d)&&(window.sessionStorage.removeItem(d),window.sessionStorage.getItem(h)||import("./c-NVU3DORS.js").then(r=>r.toastPersistent(De,"info")).catch(()=>{}))}catch{}let s=null,i="",y=null,g=null,k=null,D=0,c=!1,E=e.held()?.id,l=null,v=null,O=new Set;try{let r=window.sessionStorage.getItem(h);if(r){window.sessionStorage.removeItem(h);let a=B(r);ce({id:a?.mark??r},!!a?.reset)}}catch{}function R(r){try{window.sessionStorage.setItem(h,JSON.stringify({mark:r,reset:!0}))}catch{}}function x(r){try{window.sessionStorage.setItem(o+":generation",JSON.stringify({marker:i,reset:r}))}catch{}}function N(){let r=u(S);i=r??"";let a=e.journalSlots().filter(I=>I!==e.slotKey).map(I=>B(u(I)));k=e.stopped()?null:g,D=e.chain().ops.at(-1)?.seq??0;let m=e.held();m?.v===1&&m.w!==void 0&&(l=m);let A=k?[k]:[];return{seed:e.seed(),newId:e.newId,merge3:e.merge3,unitMark:e.unitMark,now:w(),marker:r,resets:A,local:m,seen:l,direct:v!==null&&u(o)===v,chains:e.pending()?[...a,e.chain()]:a}}function F(r){let a=w();for(let m of e.journalSlots()){if(m===e.slotKey)continue;let A=B(u(m));ie(A,r)&&a-(A?.at??0)>Re&&t(m)}}function ee({meta:r,record:a}){let m=e.held();if(H(m)&&J(m)!==r.foreign)return void setTimeout(G,0);if((u(S)??"")!==r.reset)return;if(!a)return void(m&&t(o));if(m?.w&&m.w.reset===r.reset&&m.w.rev>=r.rev)return;let A={rev:r.rev,reset:r.reset},I=JSON.stringify({...a,w:A});try{if(I.length<=xe){n.setItem(o,I),l={...a,w:A};return}}catch{}try{n.setItem(o,Pe(a,A))}catch{}}async function te(r){c=!0;let a=e.chain(),m=$(a),A=a.ops.some(C=>C.seq>D)||r.meta.recovery?.includes(m)?m:r.meta.recovery?.includes(E)?E:null;if(e.acknowledge(D),e.stop({keepPending:!0}),e.unsafe()){try{await f.putRow(se(o,e.tab),JSON.stringify(e.chain()))}catch(C){throw e.failed(C)}e.acknowledge(e.chain().ops.at(-1)?.seq??0)}ee(r),A&&R(A);let I=e.held();I?.w&&I.w.reset!==r.meta.reset&&t(o);try{window.sessionStorage.setItem(d,"1")}catch{}return x(r.meta.reset),c=!1,b(),r}async function we(){let r=e.generation(),a=()=>{e.stop(),z(!1)},m=()=>(u(S)??"")!==r&&(y===null||(u(S)??"")!==i);if(m())return a();let A=y??Q(r);if(A===null){let L=await re.catch(()=>f.change(o,({meta:U})=>({puts:[],deletes:[],result:{meta:B(U)??ae(r)}}),{timeout:ge}));if(m())return a();if(A=L.meta.gen,L.meta.reset!==r){g={ends:null,marker:r};let U=await W();if(e.stopped())return a();A=U.meta.gen}}let I=he(A+1,e.newId());g={ends:A,marker:I};let C=u(o);e.held()?.w&&t(o);try{n.setItem(S,I)}catch{}let fe;try{let L=W();u(S)!==I?await L:await Promise.race([L.catch(()=>{}),new Promise(U=>{fe=setTimeout(U,Me)})]),a()}catch(L){if(g=null,C!==null&&u(o)===null&&(u(S)??"")===r)try{n.setItem(o,C)}catch{}throw L}finally{clearTimeout(fe)}}function ce(r,a=!1){console.warn(a?"visitor-drafts: the draft was started over; the earlier draft was kept in this browser's draft database under":"visitor-drafts: a tab on an earlier ClayJS saved a copy that could not be merged exactly; it was kept in this browser's draft database under",Z(o,$(r))),!O.has(a)&&(O.add(a),import("./c-NVU3DORS.js").then(m=>m.toastPersistent(a?qe:Je,"warning")).catch(()=>{}))}function be(r){let{meta:a,record:m}=r;if(i!==a.reset&&(u(S)??"")===i)try{n.setItem(S,a.reset)}catch{}if(k&&k===g&&a.reset!==e.generation()&&(k.marker===a.reset&&x(a.reset),e.stop(),z(!1)),k===g&&(g=null),e.stopped())return c?te(r):(ee(r),r);if(r.conflicts.length&&console.warn("visitor-drafts: another tab changed the same thing; its copy was kept in this browser's draft database under",o+":conflict"),r.stale.includes(e.tab))return te(r);if(a.reset!==e.generation()){if(!e.fresh())return te(r);e.enter(a.reset)}r.released.length&&ce(r.released[0]),y=a.gen,x(a.reset);let A=e.acknowledge(a.tabs[e.tab]?.seq??0);if(F(a),ee(r),e.pending())return r;if(A&&(z(!1),p.dispatchEvent(new CustomEvent("clay:drafts-saved",{detail:{data:m.data}}))),!e.shown())return s=a.rev,r;e.changed()||(m&&a.rev!==s&&e.take(m.data),E=m?.id,s=a.rev);let I=e.externalUnit(m);return I&&p.dispatchEvent(new CustomEvent("clay:drafts-blockeditor-external",{detail:{live:I.live,adopted:()=>e.adoptedUnit(I)}})),r}let V=null,j=null;function ne(r){return V=me(f,o,N,r).then(be,a=>{throw e.pending()?e.failed(a):a}).finally(()=>{V=null}),V}function W(){return j||(V?(j=V.then(()=>{},()=>{}).then(()=>(j=null,ne())),j):ne())}let G=()=>{W().catch(()=>{})};function ye(){e.unsafe()&&f.putRow(se(o,e.tab),JSON.stringify(e.chain())).catch(()=>{}),e.pending()&&G()}window.addEventListener("storage",r=>{if(r.key===o){let[a,m]=[B(r.oldValue),B(r.newValue)];m?.v===1&&m.w!==void 0?l=m:H(m)&&a?.v===1&&a.w!==void 0&&([l,v]=[a,r.newValue])}(r.key===null||r.key===o||r.key===S)&&G()}),window.addEventListener("pageshow",r=>{r.persisted&&G()}),p.addEventListener("clay:drafts-blockeditor-listening",G);let re=ne({timeout:ge});return re.catch(()=>{}),{first:re,sync:W,hide:ye,startOver:we}}export{xe as FULL_COPY_LIMIT,je as openSession};