@panphora/clayjs 1.25.1 → 1.26.0

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 (105) 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 +1141 -345
  11. package/dist/m/c-2EPHRF47.js +1 -0
  12. package/dist/m/{c-2GB34XL4.js → c-2SUFMUZX.js} +2 -2
  13. package/dist/m/{c-BHLYQGTA.js → c-3S3647J6.js} +1 -1
  14. package/dist/m/{c-QL4NYM2L.js → c-3S5TNRZA.js} +1 -1
  15. package/dist/m/{c-3Y234AUB.js → c-3XGLJAS7.js} +2 -2
  16. package/dist/m/{c-O4YIDULY.js → c-42WBOKFM.js} +1 -1
  17. package/dist/m/{c-42RLKGEY.js → c-4TP3UXBT.js} +1 -1
  18. package/dist/m/{c-ASGHHLFX.js → c-5ELELG2F.js} +1 -1
  19. package/dist/m/{c-T5IWJOMW.js → c-5ZYLTN3Q.js} +1 -1
  20. package/dist/m/{c-DDCYVLGG.js → c-67TBU56I.js} +1 -1
  21. package/dist/m/{c-WNOLMHI2.js → c-6BGJAJ67.js} +1 -1
  22. package/dist/m/{c-XS7G6U3Z.js → c-ABOBD7F3.js} +1 -1
  23. package/dist/m/{c-5IIEOPIV.js → c-ARO6CPMA.js} +1 -1
  24. package/dist/m/{c-XUZMRQ7O.js → c-BCS3AZQZ.js} +1 -1
  25. package/dist/m/c-BOS7GONO.js +1 -0
  26. package/dist/m/{c-NICICT4P.js → c-DEYHCYJB.js} +1 -1
  27. package/dist/m/{c-T7LOTEWO.js → c-DZT6W2NG.js} +1 -1
  28. package/dist/m/c-EHJWIGWN.js +1 -0
  29. package/dist/m/{c-V2V5FKXX.js → c-EIUKME3W.js} +1 -1
  30. package/dist/m/{c-ASMLERFA.js → c-EXZOA6XY.js} +1 -1
  31. package/dist/m/{c-STAPQ2X6.js → c-EYFMAR3M.js} +1 -1
  32. package/dist/m/{c-DVMDYRAE.js → c-FUN6AKFE.js} +1 -1
  33. package/dist/m/{c-XMIDHEKF.js → c-GY36NO7C.js} +1 -1
  34. package/dist/m/{c-TWB5ZQU4.js → c-H47C6PJZ.js} +1 -1
  35. package/dist/m/c-KD2ME5UN.js +2 -0
  36. package/dist/m/{c-GO635CRU.js → c-LAKBBJOU.js} +2 -2
  37. package/dist/m/{c-GNFDX6SU.js → c-LETPPG2F.js} +1 -1
  38. package/dist/m/{c-LS7IVQVW.js → c-MMV5JULA.js} +1 -1
  39. package/dist/m/{c-NEQRFC4O.js → c-MVVEIJUU.js} +1 -1
  40. package/dist/m/{c-XCOQNISP.js → c-N362HNGO.js} +1 -1
  41. package/dist/m/{c-7K4SCQB7.js → c-ND3W7D5U.js} +1 -1
  42. package/dist/m/{c-4NAYDOWH.js → c-NNHNXD6M.js} +1 -1
  43. package/dist/m/{c-DAUQ6JZ3.js → c-NYJ577NL.js} +1 -1
  44. package/dist/m/{c-3AAQJAKJ.js → c-PWILUN4T.js} +1 -1
  45. package/dist/m/{c-7Z2625LX.js → c-QA3Q3MDI.js} +1 -1
  46. package/dist/m/{c-2A2ATCIH.js → c-QKOKMQXA.js} +1 -1
  47. package/dist/m/{c-TGIMBAWE.js → c-RBWVF4N5.js} +1 -1
  48. package/dist/m/{c-A5IYL7JI.js → c-SPOEDIMP.js} +1 -1
  49. package/dist/m/{c-ZJ7726FO.js → c-SRW5OBCF.js} +1 -1
  50. package/dist/m/{c-A3OKSYRI.js → c-SYOA4T7V.js} +1 -1
  51. package/dist/m/{c-MHTO3QAD.js → c-TJ5PFOJ2.js} +1 -1
  52. package/dist/m/{c-NW4ZFKCY.js → c-TKV273YU.js} +1 -1
  53. package/dist/m/{c-D4N4UJCQ.js → c-UEKJWXCB.js} +2 -2
  54. package/dist/m/{c-44WITKWQ.js → c-V4DBV5ZV.js} +1 -1
  55. package/dist/m/c-WHMZCRQD.js +6 -0
  56. package/dist/m/{c-WMRJKQ2V.js → c-WHQUZM2V.js} +1 -1
  57. package/dist/m/{c-C27EVUQ6.js → c-XHD7XJTE.js} +1 -1
  58. package/dist/m/{c-PP3CUF3U.js → c-XONFK3WC.js} +1 -1
  59. package/dist/m/c-YYIN4NAF.js +30 -0
  60. package/dist/m/c-ZFAPQQIB.js +1 -0
  61. package/dist/m/core/{conflict-notice-Y2NTMDGJ.js → conflict-notice-UNDOD4BL.js} +1 -1
  62. package/dist/m/core/site-edits-C22O53GS.js +1 -0
  63. package/dist/m/loader-DCKCZKY6.js +1 -0
  64. package/dist/m/{manifest-A27A4278.js → manifest-7954CBE3.js} +1 -1
  65. package/dist/m/{manifest-edit-E8A61EB4.js → manifest-edit-93AA79D7.js} +1 -1
  66. package/dist/m/manifest.json +442 -441
  67. package/dist/m/page/{editor-HS2CAV3W.js → editor-UF3CIA6V.js} +2 -2
  68. package/dist/m/plugins/{cms-4KET6RZT.js → cms-KG6TCTR3.js} +1 -1
  69. package/dist/m/plugins/{live-CO4VJS46.js → live-DF5YS5AH.js} +1 -1
  70. package/dist/m/plugins/page-GZSU77JS.js +2 -0
  71. package/dist/m/plugins/{page-view-6KNTXABH.js → page-view-7MM3FEAR.js} +1 -1
  72. package/dist/m/plugins/{quickcrop-VNRXGRPC.js → quickcrop-UHURKA2F.js} +2 -2
  73. package/dist/m/plugins/richclay-MXH2GFAZ.js +549 -0
  74. package/dist/m/plugins/undo-KLHAGV75.js +1 -0
  75. package/dist/m/sync/{live-sync-DX4K5GDB.js → live-sync-RZQSDMZW.js} +1 -1
  76. package/dist/offline-manifest.json +360 -360
  77. package/package.json +1 -1
  78. package/src/core/site-edits.js +1 -1
  79. package/src/loader-logic.js +0 -13
  80. package/src/page/boot-pack.js +1 -0
  81. package/src/page/history-intent.js +111 -4
  82. package/src/page/ybind/bridge.js +14 -7
  83. package/src/page/ybind/moves.js +437 -3
  84. package/src/page/ybind/origins.js +1 -1
  85. package/src/page/ybind/recovery.js +1 -1
  86. package/src/plugins/page.js +48 -4
  87. package/src/plugins/richclay.js +136 -0
  88. package/src/plugins/undo.js +169 -7
  89. package/src/recovery/undo.js +14 -7
  90. package/src/sync/live-sync.js +24 -0
  91. package/src/ui/vendor-skin.js +9 -4
  92. package/dist/m/c-3XNTQQEJ.js +0 -1
  93. package/dist/m/c-4OZZ7ENT.js +0 -30
  94. package/dist/m/c-D2OPWOWO.js +0 -2
  95. package/dist/m/c-LUBZU4AZ.js +0 -6
  96. package/dist/m/c-LYNLY3MR.js +0 -1
  97. package/dist/m/c-MLMJUNRV.js +0 -1
  98. package/dist/m/c-V5L6HWVL.js +0 -1
  99. package/dist/m/core/site-edits-TIJDPG6H.js +0 -1
  100. package/dist/m/loader-7ORQVRCK.js +0 -1
  101. package/dist/m/plugins/page-L3VKIQU2.js +0 -2
  102. package/dist/m/plugins/richclay-V6WKJTUF.js +0 -549
  103. package/dist/m/plugins/undo-WUK2NLBA.js +0 -1
  104. /package/dist/m/plugins/{quickcrop-VNRXGRPC.js.LEGAL.txt → quickcrop-UHURKA2F.js.LEGAL.txt} +0 -0
  105. /package/dist/m/plugins/{richclay-V6WKJTUF.js.LEGAL.txt → richclay-MXH2GFAZ.js.LEGAL.txt} +0 -0
@@ -1 +0,0 @@
1
- import{b as xt,c as Vt}from"../c-7DJDKPGL.js";import{g as we}from"../c-P73XPAOA.js";import{a as ye}from"../c-WYFDLITL.js";import"../c-MZCOGNZL.js";import"../c-IJUK2GPW.js";import{k as Et}from"../c-C7SUMNMI.js";import"../c-BPF2NSPV.js";import"../c-P7KNDG34.js";import"../c-CYWLPPUS.js";import"../c-U4TWEIKZ.js";import{a as St}from"../c-MOP5KBWZ.js";import"../c-2YYDMLNZ.js";import{l as At}from"../c-HA6INT6J.js";import"../c-ICMAOOGK.js";import"../c-WRBKEJD4.js";import"../c-VHNSBD2M.js";var Nt=(()=>{var c=Object.defineProperty,m=Object.getOwnPropertyDescriptor,E=Object.getOwnPropertyNames,A=Object.prototype.hasOwnProperty,I=(e,n)=>{for(var t in n)c(e,t,{get:n[t],enumerable:!0})},re=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of E(n))!A.call(e,a)&&a!==t&&c(e,a,{get:()=>n[a],enumerable:!(o=m(n,a))||o.enumerable});return e},de=e=>re(c({},"__esModule",{value:!0}),e),K={};I(K,{default:()=>Rn,endsSentence:()=>Xe,undo:()=>Ne});function se(e,n=null){let t=[];if(e.type==="attributes"){let o=e.target,a=e.attributeName,i=e.oldValue,l=o.getAttribute(a);return i==null&&l!=null?t.push({kind:"attr-add",target:o,name:a,newValue:l}):i!=null&&l==null?t.push({kind:"attr-remove",target:o,name:a,oldValue:i}):i!==l&&t.push({kind:"attr-set",target:o,name:a,oldValue:i,newValue:l}),t}if(e.type==="characterData")return t.push({kind:"text",target:e.target,oldValue:e.oldValue,newValue:e.target.data}),t;if(e.type==="childList"){let o=e.target,a=e.nextSibling,i=e.nextSibling;for(;i&&n?.(i);)i=i.nextSibling;let l=e.previousSibling;for(;l&&n?.(l);)l=l.previousSibling;let s=n?Array.from(e.addedNodes).filter(w=>!n(w)):Array.from(e.addedNodes),p=n?Array.from(e.removedNodes).filter(w=>!n(w)):Array.from(e.removedNodes);return s.length>0&&t.push({kind:"add",parent:o,nodes:s,before:a,afterAuthored:i,beforeAuthored:l,record:e}),p.length>0&&t.push({kind:"remove",parent:o,nodes:p,before:a,afterAuthored:i,beforeAuthored:l,record:e}),t}return t}function Lt(e,n=null){let t=[],o=new Map;for(let a of e){if(a.type==="attributes"){let i=a.target,l=a.attributeName,s=o.get(i);s||(s=new Map,o.set(i,s)),s.has(l)||(s.set(l,{idx:t.length,oldValue:a.oldValue}),t.push(null));continue}for(let i of se(a,n))t.push(i)}for(let[a,i]of o)for(let[l,s]of i){let p=s.oldValue,w=a.getAttribute(l),y=null;p===w?y=null:p==null?y={kind:"attr-add",target:a,name:l,newValue:w}:w==null?y={kind:"attr-remove",target:a,name:l,oldValue:p}:y={kind:"attr-set",target:a,name:l,oldValue:p,newValue:w},t[s.idx]=y}return t.filter(a=>a!=null)}function Mt(e,{sameContent:n=(t,o)=>t===o}={}){let t=[],o=new Map;for(let i of e){let l=Be(i);if(l==null){t.push(i);continue}let s=o.get(i.target);s||(s=new Map,o.set(i.target,s));let p=s.get(l);if(p==null){let w=_e(i);if(w.oldValue===w.newValue)continue;s.set(l,t.length),t.push({...i,...w})}else t[p]={...t[p],newValue:_e(i).newValue}}let a=[];for(let i of t){if(Be(i)==null){a.push(i);continue}i.oldValue!==i.newValue&&(i.kind==="value"&&i.content===!0&&n(i.oldValue,i.newValue)||a.push(Kt(i)))}return a}var Dt=new Set(["attr-set","attr-add","attr-remove","text","value"]);function Be(e){return Dt.has(e.kind)?e.kind==="text"?"#text":e.kind==="value"?`#${e.prop||"value"}`:e.name==null?null:`@${e.name}`:null}function _e(e){return e.kind==="attr-add"?{oldValue:null,newValue:e.newValue}:e.kind==="attr-remove"?{oldValue:e.oldValue,newValue:null}:{oldValue:e.oldValue,newValue:e.newValue}}function Kt(e){return e.kind!=="attr-add"&&e.kind!=="attr-remove"?e:e.oldValue==null&&e.newValue!=null?{...e,kind:"attr-add"}:e.oldValue!=null&&e.newValue==null?{...e,kind:"attr-remove"}:{...e,kind:"attr-set"}}var ze=new WeakMap,jt=0;function j(e){let n=ze.get(e);return n||(n=`n${++jt}`,ze.set(e,n)),n}function P(e){return!!e&&typeof e=="object"&&typeof e.nodeType=="number"}function qt(e){return e.kind==="add"||e.kind==="remove"}function Fe(e,n){let t=[],o=e.childNodes;if(!o)return t;for(let a of o)n&&n(a)||t.push(j(a));return t}function Ue(e,n,t){if(typeof n!="function"||!P(e)||e.nodeType!==1)return null;let o=null;try{o=n(e,t)}catch{o=null}return typeof o=="string"?`#form:${JSON.stringify(o)}`:null}function oe(e,n,t=null,o=null,a=null,i=null){if(!P(e))return null;let l=Ue(e,a,t);if(l!=null)return l;if(e.nodeType===3)return`#text:${JSON.stringify(i&&i.has(e)?i.get(e):e.data)}`;if(e.nodeType===8)return`#comment:${JSON.stringify(e.data)}`;if(e.nodeType!==1)return`#node:${e.nodeType}`;let s=[];if(e.attributes){for(let w of e.attributes)$t(w.name,e,n,t)||s.push(`${w.name}=${JSON.stringify(w.value)}`);s.sort()}let p=[];if(e.childNodes)for(let w of e.childNodes){let y=Ue(w,a,t);if(y!=null){p.push(y);continue}Bt(w,o)||p.push(oe(w,n,t,o,a,i))}return`<${String(e.tagName||"").toLowerCase()}${s.length?` ${s.join(" ")}`:""}>${p.join("")}</>`}function ve(e,n=[]){if(!P(e))return n;if(e.nodeType===1){let t=e.getAttribute&&e.getAttribute("data-id");t&&n.push(t)}if(e.childNodes)for(let t of e.childNodes)ve(t,n);return n}function $t(e,n,t,o=null){if(typeof t!="function")return!1;try{return!!t(e,n,o)}catch{return!1}}function Bt(e,n){if(typeof n!="function")return!1;try{return!!n(e)}catch{return!1}}function We(e,n){if(typeof n!="function")return[];let t=[],o=a=>{if(!P(a))return;let i=!1;try{i=!!n(a)}catch{i=!1}if(i&&t.push(M(a,"protected")),a.childNodes)for(let l of a.childNodes)o(l)};for(let a of e)o(a);return t}function M(e,n,t=null){let o=e;o&&o.nodeType!==1&&(o=o.parentElement);let a=o&&typeof o.closest=="function"?o.closest("[data-id]"):null;return!a&&t&&typeof t.closest=="function"&&(a=t.closest("[data-id]")),{id:(a?a.getAttribute("data-id"):null)||null,kind:n||null}}function _t(e,n,t=null){return(e||[]).filter(P).map(o=>M(o,n,t))}function ie(e){return{replayable:!1,reason:e,steps:[]}}function ce(e,n){let t=[[n.afterAuthored,a=>a],[n.beforeAuthored,a=>a+1],[n.before,a=>a]],o=!1;for(let[a,i]of t){if(!P(a))continue;o=!0;let l=e.indexOf(j(a));if(l>=0)return i(l)}return o?null:e.length}function zt(e,n={}){let t=n.isIgnored||null,o=n.ignoreAttribute||null,a=n.durableForm||null,i=Mt(e,{sameContent:ke}),l=[];for(let v of i){if(!qt(v)){if(!P(v.target))return ie("non-dom-target");continue}if(!P(v.parent))return ie("non-dom-parent");let x=Array.from(v.nodes||[]).filter(P);if(x.length!==0){if(x.length!==Array.from(v.nodes||[]).length)return ie("non-dom-node");l.push({primitive:v,nodes:x,parent:v.parent})}}if(Ft(l))return ie("in-record-move");let s=Ut(l,t);if(!s)return ie("ambiguous-structure");let p=Wt(l,s),w=new Map(l.map(v=>[v.primitive,v])),y=[];for(let v of i){let x=w.get(v);if(!x){y.push(Jt(v));continue}let N=p.get(x);if(N){N.at===x&&y.push(N.step);continue}y.push(Ht(x,s.get(x),o,t,a))}return{replayable:!0,reason:null,steps:y}}function Ft(e){let n=new Map;for(let t of e){let o=t.primitive.record;if(!o)continue;let a=n.get(o);a||(a=new Map,n.set(o,a));for(let i of t.nodes){let l=a.get(i);l||(l=new Set,a.set(i,l)),l.add(t.primitive.kind)}}for(let t of n.values())for(let o of t.values())if(o.size>1)return!0;return!1}function Ut(e,n){let t=new Map;for(let a of e)t.has(a.parent)||t.set(a.parent,Fe(a.parent,n));let o=new Map;for(let a=e.length-1;a>=0;a--){let i=e[a],l=t.get(i.parent);if(!l)return null;let s=l.slice(),p;if(i.primitive.kind==="add"){let w=i.nodes.map(j);if(!w.every(y=>l.includes(y)))return null;p=l.filter(y=>!w.includes(y))}else{let w=ce(s,i.primitive);if(w==null)return null;p=s.slice(),p.splice(w,0,...i.nodes.map(j))}o.set(i,{before:p,after:s}),t.set(i.parent,p)}return o}function Wt(e,n){let t=new Map,o=new Map;e.forEach((i,l)=>{for(let s of i.nodes){let p=j(s);i.primitive.kind==="remove"?t.set(p,{item:i,index:l,node:s}):o.set(p,{item:i,index:l,node:s})}});let a=new Map;for(let[i,l]of t){let s=o.get(i);if(!s||s.index<l.index||l.item.nodes.length!==1||s.item.nodes.length!==1)continue;let p={type:"move",node:l.node,sourceParent:l.item.parent,destParent:s.item.parent,source:n.get(l.item),dest:n.get(s.item),sourceSlot:l.item.primitive,destSlot:s.item.primitive,targets:[M(l.node,"move")]};a.set(l.item,{step:p,at:s.item}),a.set(s.item,{step:p,at:s.item})}return a}function Ht(e,n,t,o,a=null){let i=e.primitive.kind;return{type:i==="add"?"add":"restore",parent:e.parent,nodes:e.nodes,seqBefore:n.before,seqAfter:n.after,slot:e.primitive,content:e.nodes.map(l=>oe(l,t,e.parent,o,a)),ids:i==="remove"?e.nodes.flatMap(l=>ve(l)):[],targets:_t(e.nodes,i==="add"?"added":"removed",e.parent)}}function Jt(e){return{type:e.kind,primitive:e,targets:[M(e.target,e.name||e.prop||"text")]}}function Yt(e,n,t={}){if(!e||!e.replayable)return{ok:!1,code:"unsupported",targets:[]};let o={isIgnored:t.isIgnored||null,ignoreAttribute:t.ignoreAttribute||null,durableForm:t.durableForm||null,isProtected:t.isProtected||null,inScope:t.inScope||(()=>!0),liveNodesWithIds:t.liveNodesWithIds||(()=>[]),sim:new Map,planned:new Map,texts:new Map,operations:[]};for(let a=0;a<e.steps.length;a++){let i=e.steps[n==="undo"?e.steps.length-1-a:a],l=Xt(i,n,o);if(l)return{ok:!1,code:l.code,targets:l.targets}}return{ok:!0,operations:o.operations}}function G(e,n){return e.sim.has(n)||e.sim.set(n,Fe(n,e.isIgnored)),e.sim.get(n)}function X(e,n){for(let t=e;t;t=t.parentNode)if(n.planned.has(t))return n.planned.get(t);return n.inScope(e)}function He(e,n){return n.liveNodesWithIds(e).filter(t=>X(t,n)).length>0}function S(e,n){return{code:e,targets:n||[]}}function ke(e,n){return e===n?!0:typeof e!="string"||typeof n!="string"?!1:e.replace(/\u00A0|&nbsp;/g," ")===n.replace(/\u00A0|&nbsp;/g," ")}function Gt(e){return e.kind==="text"?e.target.data:e.kind==="value"?typeof e.read=="function"?e.read(e.target):e.target[e.prop||"value"]:e.target.getAttribute(e.name)}function Xt(e,n,t){let o=n==="undo";return e.type==="move"?nn(e,o,t):e.type==="add"?Qt(e,o,t):e.type==="restore"?en(e,o,t):Zt(e,o,t)}function Zt(e,n,t){let o=e.primitive,a=n?o.newValue:o.oldValue,i=n?o.oldValue:o.newValue;if(!P(o.target))return S("unsupported",e.targets);if(!X(o.target,t))return S("target-detached",e.targets);if(o.kind==="value"&&typeof o.write=="function"&&typeof o.read!="function")return S("unsupported",e.targets);let l=Gt(o);return(o.content===!0?!ke(l,a):l!==a)?S("content-changed",e.targets):(o.kind==="value"?t.operations.push({type:"value",target:o.target,prop:o.prop||"value",value:i,read:o.read||null,write:o.write||null,content:o.content===!0}):o.kind==="text"?(t.operations.push({type:"text",target:o.target,data:i}),t.texts.set(o.target,i)):t.operations.push({type:"attr",target:o.target,name:o.name,value:i??null}),null)}function Qt(e,n,t){if(!P(e.parent)||!X(e.parent,t))return S("target-detached",e.targets);if(n){if(!Z(G(t,e.parent),e.seqAfter))return S("structure-changed",e.targets);let s=We(e.nodes,t.isProtected);if(s.length>0)return S("protected",s);for(let p=0;p<e.nodes.length;p++)if(oe(e.nodes[p],t.ignoreAttribute,e.parent,t.isIgnored,t.durableForm)!==e.content[p])return S("content-changed",e.targets);for(let p of e.nodes)t.operations.push({type:"remove",node:p}),t.planned.set(p,!1);return t.sim.set(e.parent,e.seqBefore.slice()),null}if(!Z(G(t,e.parent),e.seqBefore))return S("structure-changed",e.targets);for(let s of e.nodes)if(s.parentNode)return S("structure-changed",e.targets);let o=e.nodes.flatMap(s=>ve(s));if(o.length>0&&He(o,t))return S("duplicate-id",e.targets);let a=ce(e.seqBefore,e.slot);if(a==null)return S("unsupported",e.targets);let i=e.seqBefore.slice(),l=a;for(let s of e.nodes)t.operations.push({type:"insert",parent:e.parent,node:s,beforeId:i[l]??null}),i=i.slice(0,l).concat(j(s),i.slice(l)),l+=1,t.planned.set(s,!0);return t.sim.set(e.parent,e.seqAfter.slice()),null}function en(e,n,t){if(!P(e.parent)||!X(e.parent,t))return S("target-detached",e.targets);if(n){if(!Z(G(t,e.parent),e.seqAfter))return S("structure-changed",e.targets);for(let p=0;p<e.nodes.length;p++){let w=e.nodes[p];if(w.parentNode||oe(w,t.ignoreAttribute,e.parent,t.isIgnored,t.durableForm)!==e.content[p])return S("content-changed",e.targets)}if(e.ids.length>0&&He(e.ids,t))return S("duplicate-id",e.targets);let i=ce(e.seqAfter,e.slot);if(i==null)return S("unsupported",e.targets);let l=e.seqAfter.slice(),s=i;for(let p of e.nodes)t.operations.push({type:"insert",parent:e.parent,node:p,beforeId:l[s]??null}),l=l.slice(0,s).concat(j(p),l.slice(s)),s+=1,t.planned.set(p,!0);return t.sim.set(e.parent,e.seqBefore.slice()),null}if(!Z(G(t,e.parent),e.seqBefore))return S("structure-changed",e.targets);let o=We(e.nodes,t.isProtected);if(o.length>0)return S("protected",o);let a=i=>t.planned.get(i)===!0||typeof t.isIgnored=="function"&&t.isIgnored(i);for(let i=0;i<e.nodes.length;i++){let l=e.nodes[i];if(l.parentNode!==e.parent||oe(l,t.ignoreAttribute,e.parent,a,t.durableForm,t.texts)!==e.content[i])return S("content-changed",e.targets)}for(let i of e.nodes)t.operations.push({type:"remove",node:i}),t.planned.set(i,!1);return t.sim.set(e.parent,e.seqAfter.slice()),null}function tn(e,n){let t=e.indexOf(n);return t<0?null:e.slice(0,t).concat(e.slice(t+1))}function nn(e,n,t){let o=j(e.node),a=n?e.destParent:e.sourceParent,i=n?e.sourceParent:e.destParent,l=G(t,a),s=G(t,i),p=n?e.dest.after:e.source.before,w=n?e.source.after:e.dest.before,y=n?e.sourceSlot:e.destSlot;if(!P(a)||!P(i)||!X(a,t)||!X(i,t))return S("target-detached",e.targets);if(!Z(l,p))return S("structure-changed",e.targets);let v=a===i?tn(s,o):s;if(!Z(v,w))return S("structure-changed",e.targets);let x=ce(w,y);return x==null?S("unsupported",e.targets):(t.operations.push({type:"insert",parent:i,node:e.node,beforeId:w[x]??null}),t.planned.set(e.node,!0),n?(t.sim.set(i,e.source.before.slice()),a!==i&&t.sim.set(a,e.dest.before.slice())):(t.sim.set(i,e.dest.after.slice()),a!==i&&t.sim.set(a,e.source.after.slice())),null)}function Z(e,n){if(!e||!n||e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(e[t]!==n[t])return!1;return!0}function rn(e,n){for(let t of e.childNodes||[])if(j(t)===n)return t;return null}function Je(e,n){let t=Math.min(e.length,n.length),o=0;for(;o<t&&e[o]===n[o];)o++;let a=0;for(;a<t-o&&e[e.length-1-a]===n[n.length-1-a];)a++;return n.length-a}function Ye(e,n){typeof e.write=="function"?e.write(e.target,n):e.target[e.prop]=n}function on(e){let n=[];try{let t=null;for(let o of e)t=an(o,n)||t;return{ok:!0,caret:t}}catch(t){for(let o=n.length-1;o>=0;o--)try{n[o]()}catch{}return{ok:!1,error:t}}}function an(e,n){if(e.type==="attr"){let t=e.target.getAttribute(e.name);e.value==null?e.target.removeAttribute(e.name):e.target.setAttribute(e.name,e.value),n.push(()=>{t==null?e.target.removeAttribute(e.name):e.target.setAttribute(e.name,t)});return}if(e.type==="text"){let t=e.target.data;return e.target.data=e.data,n.push(()=>{e.target.data=t}),{node:e.target,offset:Je(t,e.data)}}if(e.type==="value"){let t=typeof e.read=="function"?e.read(e.target):e.target[e.prop],o=e.content?e.target.textContent:null;if(Ye(e,e.value),n.push(()=>Ye(e,t)),!e.content)return;let a=e.target.textContent;return a===o?void 0:{root:e.target,textOffset:Je(o,a)}}if(e.type==="insert"){let t=e.beforeId==null?null:rn(e.parent,e.beforeId);if(e.beforeId!=null&&!t)throw new Error("hyper-undo: replay anchor vanished");let o=e.node.parentNode,a=e.node.nextSibling;return e.parent.insertBefore(e.node,t),n.push(()=>{o?o.insertBefore(e.node,a&&a.parentNode===o?a:null):e.node.parentNode===e.parent&&e.parent.removeChild(e.node)}),e.node.nodeType!==3?void 0:{node:e.node,offset:e.node.data.length}}if(e.type==="remove"){let t=e.node.parentNode;if(!t)throw new Error("hyper-undo: replay target is no longer attached");let o=e.node.nextSibling,a=Array.prototype.indexOf.call(t.childNodes,e.node);return t.removeChild(e.node),n.push(()=>t.insertBefore(e.node,o)),e.node.nodeType!==3?void 0:{node:t,offset:a}}}var un=['[src^="chrome-extension://"]','[href^="chrome-extension://"]','[src^="moz-extension://"]','[href^="moz-extension://"]','[src^="safari-web-extension://"]','[href^="safari-web-extension://"]','[id="1p-menu-live-region"]',"com-1password-button","com-1password-menu","com-1password-notification","grammarly-extension","grammarly-desktop-integration","lt-div","lt-card","lt-toolbar","lt-highlighter","[data-lastpass-root]","[data-lastpass-icon-root]","[data-dashlane-shadowhost]","[data-klarna-extension]",'[class*="klarna-extension"]',".skiptranslate","#goog-gt-tt",".goog-te-banner-frame",".goog-te-balloon-frame","style.darkreader","style[data-darkreader-mode]","style[data-darkreader-scheme]","#loom-companion-mv3","loom-container","[ext-id]"],ln=["data-grammarly","data-lt","data-1p","data-com-onepassword","data-lastpass","data-lp","data-kwimpala","data-bitwarden","data-bw","data-dashlane","data-np","data-protonpass","data-proton-pass","data-keeper","data-rf","data-roboform","data-honey","data-rakuten","data-capital-one","data-wikibuy","data-klarna","data-darkreader","data-evernote","data-pocket","data-pin"],dn=un.join(","),sn=new RegExp("^(?:"+ln.join("|")+")(?:-|$)"),wr=Object.freeze({data:Object.freeze({tokens:["no-data"],bundles:["editor-ui"]}),save:Object.freeze({tokens:["no-save"],bundles:["editor-ui"]}),snapshot:Object.freeze({tokens:["no-snapshot"],bundles:["editor-ui"]}),watch:Object.freeze({tokens:["no-watch"],bundles:["editor-ui"]}),undo:Object.freeze({tokens:["no-undo"],bundles:["editor-ui"]}),history:Object.freeze({tokens:[],bundles:["editor-ui"]})}),cn=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),fn=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui","live"]);function Ae(e,n){if(!e||e.nodeType!==1)return!1;let t=e.getAttribute?.("clay");return!!(t&&t.split(/\s+/).includes(n)||e.hasAttribute?.(n))}function Ge(e,n){if(Ae(e,n))return!0;for(let[t,o]of Object.entries(cn))if(o.includes(n)&&Ae(e,t))return!0;return!1}function pn(e){return e==="clay"||fn.includes(e)}var mn=["mutations-ignore","save-remove","save-ignore","save-freeze","no-undo","no-watch"];function gn(){if(typeof window>"u")return null;let e=window.clay?.region||window.hyperclay?.region;return e&&typeof e.resolveRegionPolicy=="function"?e.resolveRegionPolicy:null}function Ee(e){let n=gn();if(n)try{if(!n(e).undoable)return!0}catch{}let t=e&&e.nodeType!==1?e.parentElement:e;if(t&&t.closest&&t.closest(dn))return!0;for(;t&&t.nodeType===1;){if(Ge(t,"no-undo")||Ge(t,"no-watch"))return!0;for(let o of mn)if(Ae(t,o))return!0;t=t.parentElement}return!1}function hn(e){let n=e.target,t=n.cloneNode(!1),o=t;for(;n.parentElement;){n=n.parentElement;let a=n.cloneNode(!1);a.appendChild(t),t=a}return e.oldValue==null?o.removeAttribute(e.attributeName):o.setAttribute(e.attributeName,e.oldValue),Ee(o)}function fe(e,n,t){if(t?.type==="attributes"&&pn(t.attributeName)){if(Ee(e)&&hn(t))return!0}else if(Ee(e))return!0;if(t&&t.type==="attributes"){if(t.attributeName&&sn.test(t.attributeName.toLowerCase()))return!0;if(n)try{if(n(t.attributeName,t.target))return!0}catch{}}return!1}function yn(){let e=new Map;function n(a,i){let l=e.get(a);return l||(l=new Set,e.set(a,l)),l.add(i),()=>t(a,i)}function t(a,i){let l=e.get(a);l&&l.delete(i)}function o(a,i){let l=e.get(a);if(l)for(let s of Array.from(l))try{s(i)}catch(p){console.error("[hyper-undo] listener threw",p)}}return{on:n,off:t,emit:o}}var wn=/[.?!]["'\u201D\u2019)\]]*$/,bn=new Set(["insertParagraph","insertLineBreak"]),vn=new Set(["insertFromPaste","insertFromDrop","insertFromYank","insertReplacementText","deleteByCut","deleteByDrag"]),kn=new Set(["Enter","Backspace","Delete"]),An=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"]);function Xe(e){return wn.test(e)}function En(e,{sentence:n,endStep:t,stepOpen:o=()=>!0,composing:a}){let i=e.ownerDocument&&e.ownerDocument.defaultView;if(!i)return()=>{};let l=h=>!!h&&typeof h.nodeType=="number"&&(h===e||e.contains(h)),s=!1,p=!1,w=!1,y={kind:"other",host:null},v=h=>vn.has(h)||h.startsWith("format")?"alone":h.startsWith("delete")?"delete":h.startsWith("insert")?"insert":"other",x=h=>{if(!h)return null;let T=h.nodeType===1?h:h.parentElement;return T&&T.closest&&T.closest('[contenteditable]:not([contenteditable="false"])')||h},N=()=>{s&&(s=!1,t())},R=h=>{if(!n||h.isComposing||!l(h.target))return;let T=h.inputType||"",$=v(T),ae=x(h.target),pe=i.getSelection&&i.getSelection(),ue=!pe||pe.isCollapsed,Ce=p;p=!1;let Q=w;if(w=!1,($==="alone"||!Q&&$!==y.kind&&$!=="other"&&y.kind!=="other"||!Q&&(y.host!==null&&ae!==y.host||!ue||Ce))&&t(),y={kind:$,host:ae},$==="alone"){s=!0,setTimeout(N,0);return}let ee=T==="insertText"&&(h.data===" "||h.data==="\xA0");!ee&&!bn.has(T)||ee&&!o()||Xe(Sn(i))&&(s=!0,setTimeout(N,0))},q=h=>{l(h.target)&&N()},O=h=>{l(h.target)&&a(!0)},F=h=>{l(h.target)&&a(!1)},U=h=>{l(h.target)&&(p=!0)},W=h=>{if(!l(h.target))return;if(An.has(h.key)){p=!0;return}if(!n||h.isComposing||h.keyCode===229||h.ctrlKey||h.metaKey||!h.key||h.key.length!==1&&!kn.has(h.key))return;let T=i.getSelection&&i.getSelection(),$=y.host!==null&&x(h.target)!==y.host;!p&&!$&&(!T||T.isCollapsed)||(t(),p=!1,w=!0,setTimeout(()=>{w=!1},0))};return e.addEventListener("beforeinput",R,!0),e.addEventListener("input",q,!0),e.addEventListener("compositionstart",O,!0),e.addEventListener("compositionend",F,!0),e.addEventListener("pointerdown",U,!0),e.addEventListener("keydown",W,!0),()=>{e.removeEventListener("beforeinput",R,!0),e.removeEventListener("input",q,!0),e.removeEventListener("compositionstart",O,!0),e.removeEventListener("compositionend",F,!0),e.removeEventListener("pointerdown",U,!0),e.removeEventListener("keydown",W,!0)}}function Sn(e){let n=e.getSelection&&e.getSelection();if(!n||!n.isCollapsed||!n.anchorNode)return"";let t=n.anchorNode,o=t.nodeType===1?t:t.parentElement,a=o&&o.closest('[contenteditable]:not([contenteditable="false"])');if(!a)return"";let i=a.ownerDocument.createRange();return i.setStart(a,0),i.setEnd(t,n.anchorOffset),i.toString().replace(/\u200B/g,"").slice(-8)}var xn={maxHistory:100,idleWindowMs:500,idleLabel:"Edit",recording:"automatic",ignoreAttribute:null,isProtected:null,ignoreNode:null,durableForm:null,typingBreak:null,refused:null,debug:!1};function Ze(e){let n={...xn,...e};if(!n.scope)throw new Error("hyper-undo: scope is required");let t=yn(),o=[],a=[],i=`u${Math.random().toString(36).slice(2,8)}`,l=0,s=null,p=[],w=null,y=null,v=0,x=!1,N=n.recording==="commands"?"commands":"automatic",R=null,q=!1,O=new WeakMap,F=!1,U=!1,W=null;function h(...r){n.debug&&console.log("[hyper-undo]",...r)}function T(){x||(x=!0,y=$(H),y.observe(n.scope,{childList:!0,attributes:!0,characterData:!0,subtree:!0,attributeOldValue:!0,characterDataOldValue:!0}),W=En(n.scope,{sentence:n.typingBreak==="sentence",stepOpen:()=>(v===0&&y&&H(y.takeRecords()),p.length>0),endStep:Y,composing:On}),h("started"))}function $(r){let u=typeof document<"u"&&n.scope===document.body,d=typeof window<"u"&&(window.clay?.Mutation||window.hyperclay?.Mutation)||null;return u&&d&&typeof d.createObserver=="function"?(h("sourcing records from the platform Mutation hub (shared observer)"),d.createObserver(r)):new MutationObserver(r)}function ae(){x&&(x=!1,y&&(y.disconnect(),y=null),W&&(W(),W=null),F=!1,J(),o.length=0,a.length=0,p=[],s=null,R=null,q=!1,v=0,O=new WeakMap,h("stopped"))}function pe(){let r=n.scope;return!!(r&&r.nodeType===1&&r.isConnected===!1)}function ue(r,u){try{let d=u(r);return typeof d=="string"?d:null}catch{return null}}function Ce(r,{read:u,write:d,prop:f="content"}={}){if(!r||typeof u!="function"||typeof d!="function")return()=>{};let b={prop:f,read:u,write:d,baseline:ue(r,u)};return O.set(r,b),()=>{O.get(r)===b&&O.delete(r)}}function Q(r){for(let u=r;u;u=u.parentNode)if(O.has(u))return u;return null}function ee(r){let u=Q(r.target);return!!u&&!(r.type==="attributes"&&r.target===u)}function z(r){let u=new Set;for(let d of r)ee(d)&&u.add(Q(d.target));return u}function Pe(r){let u=[];for(let d of r){let f=O.get(d),b=ue(d,f.read);if(b!=null){if(ke(b,f.baseline)){f.baseline=b;continue}f.baseline!=null&&u.push({kind:"value",target:d,prop:f.prop,oldValue:f.baseline,newValue:b,read:f.read,write:f.write,content:!0}),f.baseline=b}}return u}function te(r){for(let u of r){let d=O.get(u);d.baseline=ue(u,d.read)}}function it(r){let u=z(r);!U&&p.some(d=>d.kind==="value"?u.has(d.target):r.some(f=>f.target===d.target&&(f.type==="characterData"?d.kind==="text":f.type==="attributes"&&f.attributeName===d.name)))&&(U=!0),te(u)}function H(r){at(r,!1)}function at(r,u){if(R){for(let f of r)R.records.push(f);return}if(N==="commands"){te(z(r));return}if(v>0){it(r);return}let d=Re(In(r),u);for(let f of Pe(z(r)))d.push(f);if(d.length>0){for(let f of d)p.push(f);Ie()}}function In(r){return typeof n.ignoreNode!="function"?r:r.filter(u=>{if(u.type!=="childList")return!0;let d=[...u.addedNodes,...u.removedNodes];return d.length===0?!0:!d.every(f=>Tn(f))})}function Tn(r){try{return!!n.ignoreNode(r)}catch{return!1}}function Re(r,u=!1){let d=Gn(r),f=r.filter(b=>(Me(b.target)||d(b.target)||u&&kt(b.target))&&!ee(b)&&!fe(b.target,n.ignoreAttribute,b));return Lt(f,b=>fe(b,n.ignoreAttribute))}function On(r){F=!!r,!F&&p.length>0&&Ie()}function Ie(){J(),w=setTimeout(ut,n.idleWindowMs)}function ut(){if(w=null,F){w=setTimeout(ut,n.idleWindowMs);return}Te()}function J(){w!=null&&(clearTimeout(w),w=null)}function Te(){if(w=null,p.length===0)return;let r=p;p=[],me(n.idleLabel,r)}function me(r,u){let d=zt(u,{isIgnored:ge,ignoreAttribute:lt,durableForm:n.durableForm});if(d.steps.length===0)return h("commit",r,"with nothing to record"),t.emit("commit"),null;let f={id:`${i}-${++l}`,label:r,timestamp:Date.now(),primitives:u,certificate:d};for(o.push(f),a.length=0,s=null;o.length>n.maxHistory;)o.shift();return h("commit",r,"primitives:",u.length),t.emit("commit"),f}function ge(r){return fe(r,n.ignoreAttribute)}function lt(r,u,d=null){if(typeof n.ignoreAttribute!="function")return!1;try{return!!n.ignoreAttribute(r,u,d)}catch{return!1}}function Ln(r){if(typeof n.isProtected!="function")return!1;try{return!!n.isProtected(r)}catch{return!1}}function Mn(r,u){if(!x)throw new Error("hyper-undo: scope not started");if(N==="commands")return ct(r,u,{honorPause:!0,receipt:!1});H(y.takeRecords()),Y();let d=v===0?dt():null,f=u();if(f&&typeof f.then=="function")throw new Error("hyper-undo: commit() fn must be synchronous; returned a Promise");if(at(y.takeRecords(),!0),d!=null&&st(d),p.length===0){t.emit("commit");return}J();let b=p;p=[],me(r,b)}function Dn(r){if(!x)throw new Error("hyper-undo: scope not started");if(!y)return;if(v>1){te(z(y.takeRecords()));return}Y();let u=y.takeRecords(),d=Re(u,!0);for(let f of Pe(z(u)))d.push(f);d.length!==0&&(J(),me(r,d))}function Kn(){y&&te(z(y.takeRecords()))}function Oe(){let r=n.scope;return r&&r.ownerDocument||(typeof document<"u"?document:null)}function he(){let r=Oe();return!r||!r.head||typeof r.head.querySelector!="function"?null:r.head.querySelector("title")}function dt(){let r=he();return r?r.textContent:null}function st(r){let u=he();if(!u||r==null)return;let d=u.textContent;d!==r&&pt({kind:"value",target:u,prop:"textContent",oldValue:r,newValue:d})}function jn(r){if(!r)return null;let u=Oe();if(!u||r.target!==u||r.prop!=="title")return r;let d=he();return d?{kind:"value",target:d,prop:"textContent",oldValue:r.oldValue,newValue:r.newValue}:null}function qn(){if(typeof window>"u")return!1;let r=window.clay?.effect||window.hyperclay?.effect;return!!(r&&r.running)}function $n(){y&&H(y.takeRecords()),Y(),R={records:[],primitives:[]}}function Bn(){let r=R;if(R=null,!r)return[];let u=Re(r.records,!0);for(let d of Pe(z(r.records)))u.push(d);for(let d of r.primitives)u.push(d);return u}function ct(r,u,{honorPause:d,receipt:f}){if(typeof u!="function")throw new Error("hyper-undo: command() needs a synchronous function");if(R)throw new Error("hyper-undo: command() cannot nest inside another command");if(q)throw new Error("hyper-undo: command() cannot run during undo or redo");if(qn())throw new Error("hyper-undo: command() cannot run inside a derived-effect context");if(u.constructor&&u.constructor.name==="AsyncFunction")throw new Error("hyper-undo: command() fn must be synchronous; it was declared async");let b=d&&v>0,V=b?null:dt();$n();let L=[],C=null,D;try{try{D=u()}catch(ne){C=ne}if(y&&H(y.takeRecords()),D&&typeof D.then=="function"){try{D.then(void 0,()=>{})}catch{}C||(C=new Error("hyper-undo: command() fn must be synchronous; returned a Promise"))}b||st(V)}finally{L=Bn()}let B=b||L.length===0?null:me(r,L);if(C)throw C;return f?B?{id:B.id,label:B.label}:null:B}function _n(r,u){if(!x)throw new Error("hyper-undo: scope not started");return ct(r,u,{honorPause:!1,receipt:!0})}function zn(r){if(r!=="automatic"&&r!=="commands")throw new Error("hyper-undo: setRecording() takes 'automatic' or 'commands'");if(R)throw new Error("hyper-undo: setRecording() cannot change while a command is running");return N===r||(Y(),N=r,h("recording",r)),N}function ft(r){if(!x||!r||!R&&(v>0||N==="commands"))return;let u=jn(r);u&&pt(u)}function pt(r){if(R){R.primitives.push(r);return}p.push(r),Ie()}function Fn(r,{prop:u="value",oldValue:d,newValue:f,read:b,write:V}={}){!r||d===f||ft({kind:"value",target:r,prop:u,oldValue:d,newValue:f,read:b,write:V})}function Y(){v===0&&y&&H(y.takeRecords()),p.length!==0&&(J(),Te())}function mt(){v===0&&y&&H(y.takeRecords()),v++,h("paused",v)}function gt(){v!==0&&(v--,v===0&&y&&(it(y.takeRecords()),U&&(U=!1,J(),Te())),h("resumed",v))}function ht(r,u){if(pe())return ae(),{ok:!1,code:"disconnected"};if(typeof n.holdReplay=="function"&&n.holdReplay())return{ok:!1,code:"held"};Y();let d=r==="undo"?o:a,f=r==="undo"?a:o,b=[],V=d.at(-1);if(!V)return{ok:!1,code:"empty"};if(u&&u!==V.id){let C=wt(u)||V;return Le(C,r,"stale-entry")}let L=n.refused==="skip"&&!u;for(;V;){let C;q=!0;try{C=Yt(V.certificate,r,{isIgnored:ge,ignoreAttribute:lt,durableForm:n.durableForm,isProtected:Ln,inScope:Xn,liveNodesWithIds:Zn})}finally{q=!1}if(!C.ok){if(!L)return Le(V,r,C.code,C.targets);yt(V,r,C.code,C.targets,b),V=d.at(-1);continue}mt();let D;q=!0;try{D=on(C.operations)}finally{q=!1,gt()}if(!D.ok){if(h(`${r} failed and was rolled back`,D.error),!L)return Le(V,r,"replay-error");yt(V,r,"replay-error",[],b),V=d.at(-1);continue}te(new Set(C.operations.filter(ne=>ne.type==="value"&&O.has(ne.target)).map(ne=>ne.target))),d.pop(),f.push(V),s=null;let B={ok:!0,entryId:V.id,label:V.label,direction:r};return b.length&&(B.skipped=b),D.caret&&(B.caret=D.caret),h(r,V.label),t.emit(r,B),B}return{ok:!1,code:"empty",direction:r,skipped:b}}function yt(r,u,d,f,b){s={entryId:r.id,direction:u,code:d,targets:f};let V=bt(r.id);(u==="undo"?o:a).pop(),s=null;let L={entryId:r.id,label:r.label,direction:u,code:d,targets:f,description:V};h("skipped",u,d),t.emit("skipped",L),b.push(L)}function Un(r){return ht("undo",r&&r.entryId)}function Wn(r){return ht("redo",r&&r.entryId)}function wt(r){return o.find(u=>u.id===r)||a.find(u=>u.id===r)||null}function Le(r,u,d,f=[]){return s={entryId:r.id,direction:u,code:d,targets:f},h("refused",u,d),t.emit("refused",{entryId:r.id,label:r.label,direction:u,code:d,targets:f}),{ok:!1,code:d,entryId:r.id,label:r.label,direction:u}}function Hn(r){if(!s||s.entryId!==r)return{ok:!1,code:"not-refused",entryId:r};let u=s.direction,d=u==="undo"?o:a,f=d.at(-1);return!f||f.id!==r?{ok:!1,code:"stale-entry",entryId:r}:(d.pop(),s=null,h("discarded",f.label),t.emit("discard",{entryId:r,label:f.label,direction:u}),{ok:!0,entryId:r,direction:u})}function bt(r){let u=wt(r);if(!u||!u.certificate||!u.certificate.replayable)return null;let d=s&&s.entryId===u.id?{direction:s.direction,code:s.code,targets:(s.targets||[]).map(f=>({id:f.id??null,kind:f.kind??null}))}:null;return{id:u.id,label:u.label,timestamp:u.timestamp,refused:d,steps:u.certificate.steps.map(Yn)}}function Jn(r){return typeof r!="string"?null:r.replace(/#form:("(?:[^"\\]|\\.)*")/g,(u,d)=>{try{return JSON.parse(d)}catch{return""}})}function Yn(r){if(r.type==="move")return{kind:"move",node:{id:M(r.node).id},from:{id:M(r.sourceParent).id},to:{id:M(r.destParent).id}};if(r.type==="add"||r.type==="restore")return{kind:r.type==="add"?"add":"remove",parent:{id:M(r.parent).id},nodes:r.nodes.map((V,L)=>({id:M(V).id,html:Jn(r.content[L])}))};let u=r.primitive,d={id:M(u.target).id},f=u.oldValue??null,b=u.newValue??null;return r.type==="value"?{kind:"value",target:d,prop:u.prop??"value",before:f,after:b}:r.type==="text"?{kind:"text",target:d,before:f,after:b}:r.type==="attr-set"||r.type==="attr-add"||r.type==="attr-remove"?{kind:"attribute",target:d,name:u.name??null,before:f,after:b}:{kind:r.type,target:d,before:f,after:b}}function Gn(r){let u=new Set,d=!0;for(;d;){d=!1;for(let f of r)if(!(f.type!=="childList"||!f.removedNodes?.length)&&!ee(f)&&!(!Me(f.target)&&!vt(f.target,u))&&!fe(f.target,n.ignoreAttribute,f))for(let b of f.removedNodes)u.has(b)||(u.add(b),d=!0)}return f=>!Me(f)&&vt(f,u)}function vt(r,u){for(let d=r;d;d=d.parentNode)if(u.has(d))return!0;return!1}function Me(r){let u=n.scope;return!u||!r||typeof r.nodeType!="number"?!1:r===u||typeof u.contains=="function"&&u.contains(r)}function kt(r){let u=Oe(),d=u&&u.head;if(!d||!r)return!1;let f=r.nodeType===1?r:r.parentElement;for(;f&&f!==d;f=f.parentElement)if(f.localName==="title")return!1;return f===d}function Xn(r){let u=n.scope;return!r||!u?!1:r===u||he()===r||kt(r)?!0:typeof u.contains=="function"?u.contains(r):!1}function Zn(r){let u=n.scope;if(!r||r.length===0||typeof u?.querySelectorAll!="function")return[];let d=new Set(r),f=[];for(let b of u.querySelectorAll("[data-id]"))d.has(b.getAttribute("data-id"))&&(ge(b)||f.push(b));return f}function Qn(){y&&te(z(y.takeRecords())),o.length=0,a.length=0,p=[],s=null,J(),h("cleared"),t.emit("clear")}return{_config:n,_tracksContentAt:r=>N!=="commands"&&!!Q(r),_recordsAt:r=>N!=="commands"&&!ge(r),start:T,stop:ae,commit:Mn,commitCaptured:Dn,discardCaptured:Kn,flush:Y,command:_n,setRecording:zn,record:ft,recordValue:Fn,trackContent:Ce,undo:Un,redo:Wn,clear:Qn,discard:Hn,describe:bt,pause:mt,resume:gt,on:t.on,off:t.off,get canUndo(){return o.length>0},get canRedo(){return a.length>0},get isPaused(){return v>0},get history(){return o.map(r=>{let u={id:r.id,label:r.label,timestamp:r.timestamp};return s&&s.entryId===r.id&&(u.refused={direction:s.direction,code:s.code,targets:s.targets}),u})},get future(){return a.map(r=>{let u={id:r.id,label:r.label,timestamp:r.timestamp};return s&&s.entryId===r.id&&(u.refused={direction:s.direction,code:s.code,targets:s.targets}),u}).reverse()},get scope(){return n.scope}}}var Vn=new Set(["checkbox","radio","button","submit","reset","image","file","range","color"]);function Qe(e){let n=typeof e.composedPath=="function"?e.composedPath():[];return n.length>0?n:Cn(e.target)}function Nn(e){for(let n of Qe(e)){if(!n||n.nodeType!==1)continue;let t=String(n.tagName||"").toUpperCase();if(t==="TEXTAREA"||t==="SELECT"||t==="INPUT"&&!Vn.has(String(n.type||n.getAttribute?.("type")||"text").toLowerCase()))return!0}return!1}function et(e){for(let n of Qe(e)){if(!n||n.nodeType!==1)continue;if(n.isContentEditable===!0)return!0;let t=n.getAttribute&&n.getAttribute("contenteditable");if(t!=null&&String(t).toLowerCase()!=="false")return!0}return!1}function Se(e,n){if(!e||!e.closest||!Array.isArray(n))return!1;for(let t of n)try{if(e.closest(t))return!0}catch{}return!1}function tt(e,n){if(Nn(e))return!0;let t=n._config,o=e.target;return t.editableKeys!=="page"?et(e)||Se(o,t.shadowKeydownIn):Se(o,t.ownKeysIn)||n._tracksContentAt(o)?!1:Se(o,t.shadowKeydownIn)?!0:et(e)&&!n._recordsAt(o)}function Cn(e){let n=[];for(let t=e;t;t=t.parentNode||(t.host??null))n.push(t);return n}function Pn(e,n){let t=i=>{let l=e.scope;if(l&&l.nodeType===1&&l.isConnected===!1){n&&n();return}if(i.defaultPrevented||i.isComposing||i.keyCode===229||tt(i,e)||!(i.metaKey||i.ctrlKey))return;let s=(i.key||"").toLowerCase();if(s==="z"&&!i.shiftKey){i.preventDefault(),i.stopPropagation(),e.undo();return}if(s==="z"&&i.shiftKey){i.preventDefault(),i.stopPropagation(),e.redo();return}if(s==="y"&&!i.shiftKey){i.preventDefault(),i.stopPropagation(),e.redo();return}},o=i=>{if(i.inputType!=="historyUndo"&&i.inputType!=="historyRedo")return;let l=e.scope;l&&l.nodeType===1&&l.isConnected===!1||i.defaultPrevented||i.isComposing||tt(i,e)||(i.preventDefault(),i.stopPropagation(),i.inputType==="historyRedo"?e.redo():e.undo())},a=e._config.editableKeys==="page";return window.addEventListener("keydown",t,!0),a&&window.addEventListener("beforeinput",o,!0),()=>{window.removeEventListener("keydown",t,!0),a&&window.removeEventListener("beforeinput",o,!0)}}var xe=[".CodeMirror",".cm-editor",".monaco-editor",".ace_editor",".ql-editor",".tiptap",".ProseMirror",".overtype-input","[data-richclay-active]",".ck-editor__editable","[data-lexical-editor]","[data-slate-editor]","trix-editor",".mce-content-body"],g=null,Ve=null,nt=null,_=null;function rt(e,n){if(_){if(_.inst===e)return _.cleanup;throw new Error("hyper-undo: another scope already owns the global Cmd+Z binding (bindKeys: true). Stop it first, or use bindKeys: false for additional scopes.")}let t=Pn(e,n);return _={inst:e,cleanup:t},t}function ot(e){_&&_.inst===e&&(_.cleanup(),_=null)}var Ne={defaults:{shadowKeydownIn:xe},start(e={}){let n=e.scope||(typeof document<"u"?document.body:null);if(!n)throw new Error("hyper-undo: no scope (need document.body or explicit { scope })");if(g){if(Ve===n)return console.warn("[hyper-undo] start() called again on existing singleton; ignoring new options"),g;throw new Error("hyper-undo: start() called with a different scope while the singleton is already started. Use undo.create({ scope }) for additional scopes, or call undo.stop() first.")}let t={...e,scope:n,shadowKeydownIn:e.shadowKeydownIn||xe};return g=Ze(t),g.start(),Ve=n,e.bindKeys!==!1&&(nt=rt(g,()=>Ne.stop())),g},stop(){g&&(ot(g),nt=null,g.stop(),g=null,Ve=null)},create(e={}){let n=e.scope||(typeof document<"u"?document.body:null);if(!n)throw new Error("hyper-undo: no scope (need document.body or explicit { scope })");let t={...e,scope:n,shadowKeydownIn:e.shadowKeydownIn||xe},o=Ze(t),a=null,i={_config:o._config,commit:o.commit,command:o.command,setRecording:o.setRecording,commitCaptured:o.commitCaptured,discardCaptured:o.discardCaptured,flush:o.flush,record:o.record,recordValue:o.recordValue,trackContent:o.trackContent,undo:o.undo,redo:o.redo,clear:o.clear,discard:o.discard,describe:o.describe,pause:o.pause,resume:o.resume,on:o.on,off:o.off,get canUndo(){return o.canUndo},get canRedo(){return o.canRedo},get isPaused(){return o.isPaused},get history(){return o.history},get future(){return o.future},get scope(){return o.scope},start(){e.bindKeys&&(a=rt(o,()=>i.stop())),o.start()},stop(){ot(o),a=null,o.stop()}};return i},commit(e,n){return g?g.commit(e,n):void 0},command(e,n){return g?g.command(e,n):void 0},setRecording(e){return g?g.setRecording(e):void 0},commitCaptured(e){return g?g.commitCaptured(e):void 0},discardCaptured(){return g?g.discardCaptured():void 0},record(e){return g?g.record(e):void 0},recordValue(e,n){return g?g.recordValue(e,n):void 0},trackContent(e,n){return g?g.trackContent(e,n):()=>{}},undo(e){return g?g.undo(e):void 0},redo(e){return g?g.redo(e):void 0},clear(){return g?g.clear():void 0},discard(e){return g?g.discard(e):void 0},describe(e){return g?g.describe(e):void 0},pause(){return g?g.pause():void 0},resume(){return g?g.resume():void 0},flush(){return g?g.flush():void 0},on(e,n){return g?g.on(e,n):void 0},off(e,n){return g?g.off(e,n):void 0},get canUndo(){return g?g.canUndo:!1},get canRedo(){return g?g.canRedo:!1},get history(){return g?g.history:[]},get future(){return g?g.future:[]},get isPaused(){return g?g.isPaused:!1}},Rn=Ne;return de(K)})();window.__hyperclayNoAutoExport||(window.hyperclay=window.hyperclay||{},window.hyperclay.undo=Nt.undo,window.h=window.hyperclay);var k=Nt.undo;var Ke=new Set,Tt=(c={})=>{let m=c.ignoreAttribute;return{...c,ignoreAttribute:(E,A,I)=>Ke.has(E)||At(E,A)||St(A,E,I)||xt(E,A)||(m?m(E,A,I):!1),isProtected:c.isProtected||er,ignoreNode:c.ignoreNode||Vt}};function er(c){let m=window.clay?.region?.resolveRegionPolicy;if(!m||c.nodeType!==1)return!1;let E=m(c);if(E.undoable!==!1||E.persist==="none")return!1;let A=c.parentElement;return!A||m(A).undoable!==!1}var tr=k.create.bind(k);k.create=c=>tr(Tt(c));var je=null,nr=k.setRecording.bind(k);k.setRecording=c=>(je=c??null,nr(c));var Ct=()=>k.history.at(-1)?.id??null,rr=k.command.bind(k);k.command=(c,m)=>{let E=rr(c,m);return E&&we(),E};var or=k.commit.bind(k),Pt=!1;k.commit=(c,m)=>{!Pt&&window.clay?.effect?.running&&(Pt=!0,console.warn(`clay.effect: undo.commit("${c}") was called inside an effect. Run commands from event handlers, not from an effect.`));let E=Ct(),A=or(c,m);return(A||Ct()!==E)&&we(),A};var ir=`input${ye}:not([type="password"]):not([type="hidden"]):not([type="file"]), textarea${ye}, select${ye}`;function ar(){let c=m=>window.clay?.region?.resolveRegionPolicy?.(m)?.undoable!==!1;document.querySelectorAll(ir).forEach(m=>{if(!c(m))return;if(m.tagName==="SELECT"){for(let K of m.options){let se=K.hasAttribute("selected");K.selected!==se&&(K.selected=se)}return}let E=(m.getAttribute("type")||"text").toLowerCase();if(m.tagName==="INPUT"&&(E==="checkbox"||E==="radio")){let K=m.hasAttribute("checked");m.checked!==K&&(m.checked=K);return}let A=m.tagName==="TEXTAREA"?m.getAttribute("data-value")??m.textContent:m.getAttribute("value")??"";if(m.value===A)return;let I=m===document.activeElement,re,de;try{re=m.selectionStart,de=m.selectionEnd}catch{}if(m.value=A,I&&re!=null)try{m.setSelectionRange(Math.min(re,A.length),Math.min(de,A.length))}catch{}})}var Rt=c=>{c?.ok&&(we(),ar())},It=({entryId:c,label:m,direction:E,code:A})=>{document.dispatchEvent(new CustomEvent("clay:undo-refused",{detail:{ok:!1,code:A,entryId:c,label:m,direction:E}})),ur({ok:!1,code:A,entryId:c,label:m,direction:E})},De=null;function Ot(){return De??=import("../c-V5L6HWVL.js").catch(c=>(De=null,console.error("clayjs: the undo recovery module could not be downloaded; a refused step stays in this tab only",c),null)),De}async function ur(c){let m={ok:!1,code:"unavailable"};try{let A=await Ot();A&&(m=await A.keepRefusal(k,c))}catch{m={ok:!1,code:"error"}}let E=m?.ok===!0?{ok:!0,entryId:c.entryId,direction:c.direction}:{ok:!1,code:m?.code||"error",entryId:c.entryId,direction:c.direction};document.dispatchEvent(new CustomEvent("clay:undo-kept",{detail:E}))}var $e=(c,m)=>(...E)=>Ot().then(A=>A?A[c](...E):m,()=>m),lr=$e("keep",{ok:!1,code:"unavailable"});k.ignoreAttribute=c=>{let m=String(c||"");return m?(Ke.add(m),()=>{Ke.delete(m)}):()=>{}};k.keep=async c=>{let m=await lr(c);return m?.ok===!0&&document.dispatchEvent(new CustomEvent("clay:undo-kept",{detail:{ok:!0,key:c?.key==null?null:`app:${c.key}`}})),m};k.kept=$e("kept",{ok:!1,code:"unavailable",records:[]});k.dismissKept=$e("dismissKept",{ok:!1,code:"unavailable"});var qe=new Set;k.reviewActions=c=>typeof c!="function"?()=>{}:(qe.add(c),()=>{qe.delete(c)});k.reviewActionsFor=c=>{let m=[];for(let E of qe){let A;try{A=E(c)}catch(I){console.error("clayjs: a review action could not describe itself; the copy stays reviewable",I);continue}for(let I of Array.isArray(A)?A:[])I&&typeof I.run=="function"&&I.label&&m.push(I)}return m};var dr=["commit","undo","redo","refused","discard","clear"],be=()=>{let c=!!le?.started;document.dispatchEvent(new CustomEvent("clay:undo-change",{detail:{canUndo:c&&k.canUndo,canRedo:c&&k.canRedo,undo:c&&k.history.at(-1)||null,redo:c&&k.future?.[0]||null}}))},le=null;function sr(){return{started:!1,admitted:!1,subscriptions:[]}}var cr=c=>c?c.signal?.aborted?!0:typeof c.isCurrent=="function"&&!c.isCurrent():!1;function fr(){return typeof document>"u"||document.readyState!=="loading"?Promise.resolve():new Promise(c=>document.addEventListener("DOMContentLoaded",c,{once:!0}))}function pr(c){return{enable(){if(!c.started){c.started=!0,c.admitted=!0,k.start(Tt({bindKeys:!0,...je?{recording:je}:{}}));for(let m of["undo","redo"])k.on(m,Rt),c.subscriptions.push({type:m,handler:Rt});k.on("refused",It),c.subscriptions.push({type:"refused",handler:It});for(let m of dr)k.on(m,be),c.subscriptions.push({type:m,handler:be});be()}},quiesce(){c.admitted&&(c.admitted=!1,k.pause())},resume(){c.admitted||(c.admitted=!0,k.resume())},dispose(){if(c.admitted=!1,le===c&&(le=null),!!c.started){c.started=!1;for(let{type:m,handler:E}of c.subscriptions.splice(0))k.off(m,E);k.stop(),be()}}}}function mr(){return{id:"clay:undo",order:350,async prepare(c={}){if(c.initial===!0)return gr();if(await fr(),cr(c))throw Object.assign(new Error("clay:undo prepared for a stale generation"),{code:"stale-document"});return pr(le||(le=sr()))}}}async function gr(){let c=await yr;return{enable(){},quiesce:()=>c?.quiesce(),resume:()=>c?.resume(),dispose:()=>c?.dispose()}}async function hr(){if(!Et()||typeof document>"u")return null;let c=await mr().prepare();return c.enable(),c}var yr=hr();var Cr=k;export{Cr as default,hr as init,mr as modeParticipant,yr as ready,ar as restoreControls,k as undo,mr as undoParticipant};