@panphora/clayjs 1.13.1 → 1.15.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 (146) hide show
  1. package/THIRD-PARTY-NOTICES.md +19 -0
  2. package/dist/clay.standalone.js +69385 -40992
  3. package/dist/server/checkpoint.cjs +1 -0
  4. package/dist/server/checkpoint.mjs +8 -0
  5. package/dist/server/core.cjs +72210 -0
  6. package/dist/server/rooms.cjs +1 -0
  7. package/dist/server/rooms.mjs +66 -0
  8. package/docs/guide.md +127 -99
  9. package/entries/clay.js +22 -0
  10. package/entries/sap.js +5 -5
  11. package/package.json +16 -2
  12. package/packed-contract.json +18 -3
  13. package/src/core/boot-phase.js +6 -0
  14. package/src/core/conflict-download.js +12 -3
  15. package/src/core/host-meta.js +75 -0
  16. package/src/core/persist.js +11 -0
  17. package/src/core/save-core.js +266 -31
  18. package/src/core/save.js +154 -36
  19. package/src/core/snapshot.js +51 -13
  20. package/src/core/style-comparisons.js +37 -0
  21. package/src/dom/insert-style-tag.js +11 -12
  22. package/src/lib/derived.js +116 -0
  23. package/src/lib/effect.js +130 -0
  24. package/src/lib/mutation.js +3 -1
  25. package/src/lib/style-adoption.js +9 -0
  26. package/src/lib/style.js +47 -0
  27. package/src/live/fast-lane.js +347 -60
  28. package/src/live/local-lane.js +32 -6
  29. package/src/live/ops.js +77 -0
  30. package/src/live/provenance.js +129 -0
  31. package/src/live/save-history.js +188 -0
  32. package/src/live/server-lane.js +9 -2
  33. package/src/live/store.js +194 -16
  34. package/src/loader-logic.js +16 -4
  35. package/src/loader.js +37 -1
  36. package/src/page/address.js +20 -0
  37. package/src/page/adopt-boot.js +189 -0
  38. package/src/page/adopt.js +240 -0
  39. package/src/page/ai-tool.js +188 -0
  40. package/src/page/announce.js +21 -0
  41. package/src/page/blocks.js +1170 -0
  42. package/src/page/blocksel.js +269 -0
  43. package/src/page/board-drag.js +226 -0
  44. package/src/page/board-panel.js +353 -0
  45. package/src/page/board-style.js +146 -0
  46. package/src/page/board-view.js +447 -0
  47. package/src/page/board.js +41 -0
  48. package/src/page/chart.js +220 -0
  49. package/src/page/checklist.js +143 -0
  50. package/src/page/chrome.js +587 -0
  51. package/src/page/csv-import.js +169 -0
  52. package/src/page/drag.js +202 -0
  53. package/src/page/drop.js +112 -0
  54. package/src/page/editor.js +386 -0
  55. package/src/page/highlight.js +268 -0
  56. package/src/page/inline.js +60 -1
  57. package/src/page/items.js +159 -0
  58. package/src/page/link.js +247 -0
  59. package/src/page/markdown.js +71 -0
  60. package/src/page/media.js +570 -0
  61. package/src/page/merge.js +130 -0
  62. package/src/page/model.js +71 -9
  63. package/src/page/placeholder.js +23 -0
  64. package/src/page/projection.js +647 -0
  65. package/src/page/recover.js +193 -0
  66. package/src/page/rich/cell.js +16 -0
  67. package/src/page/rich/chart.js +104 -0
  68. package/src/page/rich/csv.js +118 -0
  69. package/src/page/rich/page-tool.js +86 -0
  70. package/src/page/rich/tool-runtime.js +195 -0
  71. package/src/page/save-projection.js +53 -0
  72. package/src/page/save-states.js +85 -0
  73. package/src/page/schema.js +12 -5
  74. package/src/page/table-kinds.js +20 -0
  75. package/src/page/table-paste.js +57 -0
  76. package/src/page/table-select.js +244 -0
  77. package/src/page/table-style.js +25 -0
  78. package/src/page/table.js +650 -0
  79. package/src/page/themes/content.css +46 -0
  80. package/src/page/themes/light-1.css +269 -0
  81. package/src/page/themes/light-2.css +211 -0
  82. package/src/page/themes/light-3.css +130 -0
  83. package/src/page/themes/light-4.css +299 -0
  84. package/src/page/tool-data.js +25 -0
  85. package/src/page/tool-view.js +68 -0
  86. package/src/page/tools.js +133 -0
  87. package/src/page/view.js +136 -0
  88. package/src/page/ybind/author.js +25 -0
  89. package/src/page/ybind/binding.js +92 -0
  90. package/src/page/ybind/board-commands.js +170 -0
  91. package/src/page/ybind/board.js +89 -0
  92. package/src/page/ybind/bridge.js +382 -0
  93. package/src/page/ybind/conversion.js +26 -0
  94. package/src/page/ybind/core.js +7 -0
  95. package/src/page/ybind/decode.js +208 -0
  96. package/src/page/ybind/doc.js +58 -0
  97. package/src/page/ybind/external.js +190 -0
  98. package/src/page/ybind/group.js +124 -0
  99. package/src/page/ybind/index.js +12 -0
  100. package/src/page/ybind/layout.js +27 -0
  101. package/src/page/ybind/marks.js +18 -0
  102. package/src/page/ybind/migrate.js +152 -0
  103. package/src/page/ybind/moves.js +288 -0
  104. package/src/page/ybind/origins.js +257 -0
  105. package/src/page/ybind/parts.js +44 -0
  106. package/src/page/ybind/projection-map.js +92 -0
  107. package/src/page/ybind/provider.js +285 -0
  108. package/src/page/ybind/recovery.js +411 -0
  109. package/src/page/ybind/seed.js +27 -0
  110. package/src/page/ybind/table.js +166 -0
  111. package/src/page/ybind/tokens.js +93 -0
  112. package/src/page/ybind/walk.js +333 -0
  113. package/src/page/ybind/writer.js +307 -0
  114. package/src/plugins/derive.js +12 -0
  115. package/src/plugins/indicator.js +16 -6
  116. package/src/plugins/live.js +742 -65
  117. package/src/plugins/page.js +547 -0
  118. package/src/plugins/undo.js +62 -4
  119. package/src/server/checkpoint/index.js +218 -0
  120. package/src/server/rooms/index.js +59 -0
  121. package/src/server/rooms/live-data-ops.js +369 -0
  122. package/src/server/rooms/live-data-rooms.js +965 -0
  123. package/src/server/rooms/live-data-tags.js +49 -0
  124. package/src/server/rooms/live-page-history.js +41 -0
  125. package/src/server/rooms/live-provenance.js +142 -0
  126. package/src/server/rooms/page-admission.js +79 -0
  127. package/src/server/rooms/page-conversion.js +62 -0
  128. package/src/server/rooms/page-rebase.js +108 -0
  129. package/src/server/rooms/page-state.js +91 -0
  130. package/src/server/rooms/page-write-admission.js +63 -0
  131. package/src/server/rooms/page-write-guard.js +23 -0
  132. package/src/server/rooms/recent.js +18 -0
  133. package/src/server/rooms/spec-wire.js +17 -0
  134. package/src/standalone.js +22 -0
  135. package/src/sync/conflict-revert.js +2 -0
  136. package/src/sync/conflicts.js +2 -2
  137. package/src/sync/live-sync.js +36 -8
  138. package/src/sync/stream.js +62 -16
  139. package/src/ui/index.js +4 -0
  140. package/src/ui/toast.js +21 -5
  141. package/src/vendor/pierre/pierre.vendor.js +3 -0
  142. package/src/vendor/sap-core.vendor.js +9 -0
  143. package/src/vendor/sap-ownership.vendor.js +111 -0
  144. package/src/vendor/yjs.vendor.js +7 -0
  145. package/src/page/binding.js +0 -647
  146. package/src/page/replay.js +0 -578
@@ -0,0 +1,9 @@
1
+ // GENERATED — do not edit. Vendored from sapjs/dist/sap-core.min.js via sapjs
2
+ // `npm run copy-to-clayjs`. Edit the sapjs source and re-run.
3
+ var SapCoreBundle=(()=>{var st=Object.defineProperty;var Ce=Object.getOwnPropertyDescriptor;var $e=Object.getOwnPropertyNames;var Pe=Object.prototype.hasOwnProperty;var Me=(t,e)=>{for(var r in e)st(t,r,{get:e[r],enumerable:!0})},Oe=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of $e(e))!Pe.call(t,o)&&o!==r&&st(t,o,{get:()=>e[o],enumerable:!(n=Ce(e,o))||n.enumerable});return t};var Ie=t=>Oe(st({},"__esModule",{value:!0}),t);var Sn={};Me(Sn,{FULL_SAPJS:()=>U,Sap:()=>q,default:()=>vn,mount:()=>An,mountAll:()=>_e,needsFullSapjs:()=>St,runtime:()=>En});function Nt(t){let e=!1,r=new Set,n=[];function o(a){a&&(n.push(a),n.length>8&&n.shift())}function u(a,m){o(m),!a._broken&&(r.add(a),!e&&(e=!0,queueMicrotask(i)))}function i(){e=!1;let a=[...r];r.clear();for(let m of a)d(m)}function d(a,m=!1){if(!(a._broken||a.halted)){if(a._passes=(a._passes||0)+1,a._passes>50){a._broken=!0,a._breakerRing=n.slice(),t(a,{breaker:!0});return}a._resetArmed||(a._resetArmed=!0,setTimeout(()=>{a._passes=0,a._resetArmed=!1},0)),t(a,m?{full:!0}:{})}}function l(a,m){o(m),d(a,!0)}function c(a){a._broken=!1,a._passes=0}return{schedule:u,runNow:l,rearm:c,ring:n}}var at={E01:{slug:"foreign-dialect",behavior:"HALT"},E02:{slug:"moustaches-in-text",behavior:"HALT"},E04:{slug:"duplicate-declaration",behavior:"HALT"},E05:{slug:"reserved-name",behavior:"HALT"},E06:{slug:"global-html-name",behavior:"HALT"},E07:{slug:"calc-cycle",behavior:"ERR"},E08:{slug:"expression-syntax",behavior:"HALT"},E10:{slug:"orphan-item",behavior:"HALT"},E12:{slug:"unknown-state-key",behavior:"ERR"},E15:{slug:"write-to-undeclared-key",behavior:"ERR"},E16:{slug:"write-to-computed-field",behavior:"ERR"},E17:{slug:"unresolvable-action-target",behavior:"HALT"},E18:{slug:"paint-on-form-control",behavior:"HALT"},E20:{slug:"bind-on-non-control",behavior:"HALT"},E22:{slug:"format-type",behavior:"ERR"},E24:{slug:"runtime-expression-throw",behavior:"ERR"},E26:{slug:"circuit-breaker",behavior:"HALT"},E30:{slug:"attr-on-bound-control",behavior:"HALT"},E31:{slug:"password-without-transient",behavior:"HALT"},E32:{slug:"file-bind",behavior:"HALT"},E33:{slug:"dialog-state-open",behavior:"HALT"},E34:{slug:"transient-persist-collision",behavior:"HALT"},E35:{slug:"presence-state-misuse",behavior:"HALT"},E40:{slug:"each-not-array",behavior:"ERR"},E41:{slug:"each-bad-key",behavior:"ERR"},E42:{slug:"each-template",behavior:"ERR"},E43:{slug:"bind-in-each-row",behavior:"ERR"},E50:{slug:"needs-full-sapjs",behavior:"HALT"},W03:{slug:"unknown-colon-attribute",behavior:"WARN"},W04:{slug:"expression-in-when",behavior:"WARN"},W30:{slug:"nonzero-mount-writes",behavior:"WARN"},W31:{slug:"detail-dialog-saved-open",behavior:"WARN"}},O=["disabled","readonly","required","checked","selected","multiple","open","inert","autofocus","novalidate","hidden"],ut=new Set(["title","style","hidden","lang","dir","translate","class","id","nonce","autofocus","tabindex","contenteditable","spellcheck","draggable","role","slot","part","name","value","type","itemscope","itemtype","itemid","itemprop","itemref"]),Tt=new Set(["sap","scope","items","item","template","bind","calc","text","show","attr","set","trigger","move","sort","detail","each","effect","invalid","confirm","transient","default","persist","sortable","editmode"]);function De(t){if(!t||t.nodeType!==1)return"?";if(t.id)return`${t.tagName.toLowerCase()}#${t.id}`;let e=[],r=t,n=0;for(;r&&r.nodeType===1&&n<4;){let o=r.tagName.toLowerCase();if(r.hasAttribute("sap"))o+="[sap]";else if(r.parentElement){let u=0,i=0;for(let d=r.parentElement.firstElementChild;d;d=d.nextElementSibling)d.tagName===r.tagName&&(u++,d===r&&(i=u));u>1&&(o+=`:nth-of-type(${i})`)}if(e.unshift(o),r.hasAttribute("sap"))break;r=r.parentElement,n++}return e.join(" > ")}var Y=class{constructor(e){this.appName=e,this.errors=[],this.warnings=[],this.halted=!1,this.haltReason=null}block(e,r,n={}){let o=(at[e]||{}).slug||"error",u={code:e,slug:o,el:De(r),attr:n.attr||null,expr:n.expr||null,key:n.key||null,problem:n.problem||"",didYouMean:n.didYouMean||null,fix:n.fix||null,phase:n.phase||"runtime"},i=[`
4
+ `+(e[0]==="W"?"sap \u26A0 ":"sap \u2717 ")+e+" "+o];return i.push(` at ${u.el}${u.attr?` \u2014 ${u.attr}="${u.expr??""}"`:""}`),u.problem&&i.push(` problem: ${u.problem}`),u.didYouMean&&i.push(` did you mean: ${u.didYouMean}`),u.fix&&i.push(` fix: ${u.fix}`),(e[0]==="W"?console.warn:console.error)(i.join(`
5
+ `)),u}error(e,r,n={}){let o=this.block(e,r,n);return this.errors.push(o),o}warn(e,r,n={}){let o=this.block(e,r,n);return this.warnings.push(o),o}report(){return{ok:this.errors.length===0&&!this.halted,app:this.appName,halted:this.halted,haltReason:this.haltReason,errors:this.errors.slice(),warnings:this.warnings.slice()}}};function P(t,e){t&&t.getAttribute("sap-error")!==e&&t.setAttribute("sap-error",e)}function Lt(t){t&&t.hasAttribute("sap-error")&&t.removeAttribute("sap-error")}function ct(t,e){let r=null,n=3;for(let o of e){let u=Be(t,o);u<n&&(n=u,r=o)}return r}function Be(t,e){let r=t.length,n=e.length,o=Array.from({length:r+1},(u,i)=>[i,...new Array(n).fill(0)]);for(let u=0;u<=n;u++)o[0][u]=u;for(let u=1;u<=r;u++)for(let i=1;i<=n;i++)o[u][i]=Math.min(o[u-1][i]+1,o[u][i-1]+1,o[u-1][i-1]+(t[u-1]===e[i-1]?0:1));return o[r][n]}var Fe=new Set(O),We={readonly:"readOnly",novalidate:"noValidate"},ze=0,_t=new WeakMap;function Rt(t,e="sap"){let r=t.getAttribute("data-id");if(r)return r;if(t.id)return t.id;let n=_t.get(t);return n||(n=`${e}-${(ze++).toString(36)}`,_t.set(t,n)),n}function Ct(t){let e=[];for(let r=t.firstElementChild;r;r=r.nextElementSibling)r.hasAttribute("item")&&!r.hasAttribute("template")&&!r.hasAttribute("cms-template")&&e.push(r);return e}function lt(t,e){if(!t||!e)return null;let r=[...t.querySelectorAll(`template[items="${e}"]`)].find(o=>o.closest("[sap]")===t),n=r&&r.content.firstElementChild;return n&&n.hasAttribute("item")?n:null}function $t(t){for(let e=t.firstElementChild;e;e=e.nextElementSibling)if(e.hasAttribute("item")&&e.hasAttribute("template"))return e;return lt(t.closest("[sap]"),t.getAttribute("items"))}function G(t){let e=[];if(!t)return e;for(let r of t.trim().split(/\s+/)){if(!r)continue;let n=r,o,u=n.indexOf("=");u>=0&&(o=n.slice(u+1),n=n.slice(0,u));let i=n.split(":"),d=i[0],l="string",c=!1;for(let g of i.slice(1))g==="num"?l="num":g==="bool"?l="bool":g==="presence"?l="presence":g==="transient"&&(c=!0);let a=d,m=a.startsWith("data-")&&a.length>5?a.slice(5).replace(/-([a-z])/g,(g,A)=>A.toUpperCase()):a;e.push({name:m,attr:a,type:l,default:o,transient:c})}return e}function X(t,e){if(e==="num"){if(t==null||t==="")return 0;let r=Number(t);return Number.isNaN(r)?0:r}return e==="bool"?t==="true"||t===""||t==="1":t??""}function Pt(t,e){return e==="bool"?t?"true":"false":t==null?"":String(t)}function ft(t,e){return Fe.has(e)&&typeof t[We[e]||e]=="boolean"}function Mt(t,e){return e.type==="presence"||e.type!=="num"&&ft(t,e.attr||e.name)}function dt(t){return t.default!=null?t.default:t.type==="num"?"0":t.type==="bool"?"false":""}function Ot(t,e){let r=e.attr||e.name,n=t._sapTransient||(t._sapTransient={});if(!(e.name in n)){let o=t.getAttribute(r);o==null&&(o=dt(e)),n[e.name]=X(o,e.type)}return t.hasAttribute(r)&&t.removeAttribute(r),n[e.name]}function S(t){if(typeof t=="number")return t;if(t==null||t==="")return 0;let e=Number(typeof t=="string"?t.replace(/[$,%\s]/g,""):t);return Number.isNaN(e)?0:e}function K(t,e){return Array.isArray(t)?e==null?t:t.map(r=>typeof e=="function"?e(r):r?.[e]):[]}function pt(t,e){return K(t,e).reduce((r,n)=>r+S(n),0)}function It(t,e){return Array.isArray(t)?e==null?t.length:t.reduce((r,n)=>r+(e(n)?1:0),0):0}function Dt(t,e){let r=K(t,e);return r.length?pt(t,e)/r.length:0}function Bt(t,e){let r=K(t,e).filter(n=>n!=null&&n!=="");return r.length?r.every(n=>typeof n=="number"||!Number.isNaN(Number(n)))?Math.min(...r.map(Number)):r.reduce((n,o)=>String(n)<=String(o)?n:o):0}function Ft(t,e){let r=K(t,e).filter(n=>n!=null&&n!=="");return r.length?r.every(n=>typeof n=="number"||!Number.isNaN(Number(n)))?Math.max(...r.map(Number)):r.reduce((n,o)=>String(n)>=String(o)?n:o):0}function Wt(t,e,r){let n=S(t)===1?e:r??e+"s";return`${t} ${n}`}function zt(t,e){let r=new Date(t),n=new Date(e);return Number.isNaN(+r)||Number.isNaN(+n)?0:Math.round((n-r)/864e5)}function T(t){return typeof t=="number"?t:Number(t)}var I={usd:t=>"$"+T(t).toLocaleString("en-US",{maximumFractionDigits:0}),usd2:t=>"$"+T(t).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2}),pct:t=>Math.round(T(t))+"%",pct1:t=>T(t).toFixed(1)+"%",int:t=>Math.round(T(t)).toLocaleString("en-US"),num:t=>T(t).toLocaleString("en-US"),num2:t=>T(t).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2}),compact:t=>T(t).toLocaleString("en-US",{notation:"compact"}),date:t=>{let e=new Date(t);return Number.isNaN(+e)?String(t):e.toLocaleDateString("en-US")},clock:t=>{let e=T(t),r=Math.floor(e/100),n=r%10,o=Math.floor(r/10)%60;return`${Math.floor(r/600)}:${String(o).padStart(2,"0")}.${n}`}},He=new Set(["usd","usd2","pct","pct1","int","num","num2","compact","clock"]);function Ht(t,e){if(!t)return e==null?"":String(e);let r=I[t];if(typeof r!="function"){let n=new Error(`unknown format "${t}"`);throw n.sapCode="E22",n}if(He.has(t)){let n=typeof e=="number"?e:Number(e);if(!Number.isFinite(n)){let o=new Error(`format "${t}" received ${typeof e=="string"?`"${e}"`:e}`);throw o.sapCode="E22",o}}return r(e)}var je=["state","item","el","root","fmt","num","sum","count","avg","min","max","plural","days"],J=new Map,jt=/\bstate\.([a-z][a-z0-9_]*)/g,Ut=/\bitem\.([a-z][a-z0-9_]*)/g;function Ue(t){let e=new Set,r=new Set,n;for(jt.lastIndex=0;n=jt.exec(t);)e.add(n[1]);for(Ut.lastIndex=0;n=Ut.exec(t);)r.add(n[1]);return{state:e,item:r}}function N(t,e=!1){let r=(e?"!":"")+t,n=J.get(r);if(n)return n;J.size>512&&J.clear();try{let o=e?`"use strict";
6
+ ${t}`:`"use strict"; return (${t});`;n={fn:new Function(...je,o),src:t,statement:e,deps:Ue(t),error:null}}catch(o){n={fn:null,src:t,statement:e,deps:{state:new Set,item:new Set},error:o}}return J.set(r,n),n}function qt(t,e,r,n,o){if(t.error)throw t.error;return t.fn(e,r,n,o,I,S,pt,It,Dt,Bt,Ft,Wt,zt)}var j={},H=null,Yt=!0,Z=!1;function Gt(){j={}}function Xt(t){let e=Z;return H?Jt(H.takeRecords()):Yt&&qe(),Z=!!H&&t.getRootNode()===document,e}function Kt(t){Z=t}function qe(){if(typeof document>"u"||typeof MutationObserver!="function"){Yt=!1;return}H=new MutationObserver(Jt),H.observe(document,{attributes:!0,childList:!0,subtree:!0})}function Jt(t){for(let e of t)if(e.type==="attributes")e.target._sapPlan&&(e.target._sapPlan=null);else for(let r of e.addedNodes)r.nodeType===1&&Qt(r)}function Qt(t){t._sapPlan&&(t._sapPlan=null);for(let e=t.firstElementChild;e;e=e.nextElementSibling)Qt(e)}function tt(t){if(!Z)return Vt(t);let e=t._sapPlan;return e&&e.gen===j?e:t._sapPlan=Vt(t)}function Vt(t){let e={gen:j,inert:t.tagName==="TEMPLATE",template:!1,item:!1,scope:!1,items:!1,detail:!1,each:!1,boundary:null,bind:null,transient:!1,decls:null,calcs:null,paints:null,effects:null,invalids:null};for(let r of t.attributes){let n=r.name,o=r.value,u=n.indexOf(":");if(u<0){switch(n){case"sap-ignore":e.inert=!0;break;case"cms-template":e.inert=!0;break;case"template":e.inert=!0,e.template=!0;break;case"item":e.item=!0;break;case"scope":e.scope=!0;break;case"items":e.items=!0;break;case"detail":e.detail=!0;break;case"each":e.each=!0;break;case"bind":e.bind=o;break;case"transient":e.transient=!0;break;case"state":e.decls=G(o);break;case"text":(e.paints||(e.paints=[])).push({kind:"text",fmt:null,entry:N(o)});break;case"show":(e.paints||(e.paints=[])).push({kind:"show",entry:N(o)});break;case"effect":(e.effects||(e.effects=[])).push({entry:N(o,!0)});break;case"invalid":(e.invalids||(e.invalids=[])).push({entry:N(o)});break}continue}let i=n.slice(0,u),d=n.slice(u+1);switch(i){case"calc":(e.calcs||(e.calcs=[])).push({name:d,entry:N(o)});break;case"text":(e.paints||(e.paints=[])).push({kind:"text",fmt:d,entry:N(o)});break;case"attr":(e.paints||(e.paints=[])).push({kind:"attr",arg:d,entry:N(o)});break;case"class":(e.paints||(e.paints=[])).push({kind:"class",arg:d,entry:N(o)});break;case"css":(e.paints||(e.paints=[])).push({kind:"css",arg:d,entry:N(o)});break;case"show-when":case"option":(e.paints||(e.paints=[])).push({kind:"when",match:"show",field:d,values:o.split("|")});break;case"hide-when":(e.paints||(e.paints=[])).push({kind:"when",match:"hide",field:d,values:o.split("|")});break;case"option-not":(e.paints||(e.paints=[])).push({kind:"when",match:"show-not",field:d,values:o.split("|")});break}}return e.boundary=e.scope?"scope":e.items?"items":e.detail?"detail":e.each?"each":null,Ye(e)?Ve():e}var Q=null;function Ve(){return(!Q||Q.gen!==j)&&(Q=Object.freeze({gen:j,inert:!1,template:!1,item:!1,scope:!1,items:!1,detail:!1,each:!1,boundary:null,bind:null,transient:!1,decls:null,calcs:null,paints:null,effects:null,invalids:null})),Q}function Ye(t){return!t.inert&&!t.item&&t.boundary===null&&t.bind===null&&!t.transient&&!t.decls&&!t.calcs&&!t.paints&&!t.effects&&!t.invalids}function Zt(t){return(t.getAttribute("type")||"text").toLowerCase()}function D(t){let e=t.tagName;if(e==="INPUT"){let r=Zt(t);r==="checkbox"||r==="radio"?t.checked?t.setAttribute("checked",""):t.removeAttribute("checked"):t.setAttribute("value",t.value);return}if(e==="TEXTAREA"){t.setAttribute("data-value",t.value);return}if(e==="SELECT"){let r=t.options;for(let n=0;n<r.length;n++)r[n].selected?r[n].setAttribute("selected",""):r[n].removeAttribute("selected")}}function te(t,e=t){let r=t.tagName;if(r==="INPUT"){let n=Zt(t);n==="checkbox"||n==="radio"?e.checked?t.hasAttribute("checked")||t.setAttribute("checked",""):t.removeAttribute("checked"):e.value!==(t.getAttribute("value")??"")&&t.setAttribute("value",e.value);return}if(r==="TEXTAREA"){let n=e.value.startsWith(`
7
+ `)?`
8
+ `+e.value:e.value;t.textContent!==n&&(t.textContent=n),t.removeAttribute("data-value");return}if(r==="SELECT"){let n=t.options,o=e.options;for(let u=0;u<n.length;u++)o[u]&&o[u].selected?n[u].hasAttribute("selected")||n[u].setAttribute("selected",""):n[u].removeAttribute("selected")}}function et(t){t.tagName!=="TEXTAREA"||!t.hasAttribute("data-value")||t!==t.ownerDocument.activeElement&&(t.textContent=t.getAttribute("data-value"),t.removeAttribute("data-value"))}function w(t){if(typeof window>"u")return null;let e=window.clay,r=window.hyperclay;return t==="consent"?e?.confirm||r?.consent||null:e?.[t]||r?.[t]||null}function ee(){let t=w("visitorDrafts");return!!(t&&typeof t.restored=="function"&&t.restored()?.restored)}var mt=["clay:mutation-ready","hyperclay:mutation-ready"],Ge=["clay:sync-applied","hyperclay:livesync-applied"],Xe=["clay:ready","hyperclay:ready"],Ke=["clay:route"];function B(t,e,r){let n=null,o=u=>{n!==null&&n!==u.type||(n=u.type,queueMicrotask(()=>{n=null}),r(u))};for(let u of e)t.addEventListener(u,o);return()=>{for(let u of e)t.removeEventListener(u,o)}}function ne(t){let e=typeof window<"u"&&window.clay&&window.clay.ready;e&&typeof e.then=="function"?e.then(()=>t(),()=>t()):t()}function nt(t){let e=w("region");return!e||typeof e.resolveRegionPolicy!="function"||typeof e.skipForPolicy!="function"?!1:e.skipForPolicy(e.resolveRegionPolicy(t),void 0,["no-save","freeze"])}function re(t,e){if(typeof e!="function")throw new Error("Sap.batch(label, fn): fn must be a function");let r=w("undo");r&&r.flush&&r.flush();let n=e();if(n&&typeof n.then=="function")throw new Error("Sap.batch fn must be synchronous (it returned a promise)");return r&&r.commitCaptured&&r.commitCaptured(t),n}function oe(t){if(typeof window>"u"||typeof document>"u")return;let e=()=>{let c=!1;for(let a of t.apps())a.root.isConnected?t.runNow(a,"platform"):c=!0;c&&t.pruneDisconnected(),t.remountIfPresent()},r=w("derived"),n=r&&typeof r.register=="function"?r.register(e):null,o=typeof n=="function"?null:B(document,Ge,e),u=B(document,Ke,e),i=!1,d=()=>{},l=()=>{if(i)return!0;let c=w("undo");if(!c||typeof c.on!="function")return!1;let a=c.on("undo",e);return typeof a!="function"?!1:typeof c.on("redo",e)!="function"?(a(),!1):(i=!0,d(),!0)};if(!l()){let c=B(document,mt,l),a=B(document,Xe,l);d=()=>{c(),a()};let m=w("ready");m&&typeof m.then=="function"&&m.then(l,()=>{})}return()=>{typeof n=="function"&&n(),o&&o(),u(),d()}}function ht(t){let e=t.tagName;if(e==="INPUT"){let r=(t.getAttribute("type")||"text").toLowerCase();return r==="checkbox"?"checkbox":r==="radio"?"radio":r==="number"||r==="range"?"number":r==="hidden"?"hidden":"text"}return e==="TEXTAREA"?"text":e==="SELECT"?t.multiple?"select-multiple":"select-one":"leaf"}function Je(t){if(t.validity&&t.validity.badInput)return t.hasAttribute("value")?Number(t.getAttribute("value"))||0:t._sapLastGood??0;if(t.value==="")return 0;let e=Number(t.value);return Number.isNaN(e)?t._sapLastGood??0:(t._sapLastGood=e,e)}function se(t,e){switch(e){case"checkbox":return t.checked;case"radio":return t.checked?t.value:void 0;case"number":return Je(t);case"select-one":return t.value;case"select-multiple":return[...t.selectedOptions].map(r=>r.value);case"hidden":case"text":return t.value;case"leaf":return t.textContent;default:return t.value}}function Qe(t,e,r){switch(e){case"checkbox":t.checked=!!r;break;case"radio":t.checked=String(t.value)===String(r);break;case"number":case"text":case"hidden":t.value=r==null?"":String(r);break;case"select-one":t.value=r==null?"":String(r);break;case"select-multiple":{let n=new Set((Array.isArray(r)?r:[r]).map(String));for(let o of t.options)o.selected=n.has(o.value);break}case"leaf":t.textContent=r==null?"":String(r);break;default:t.value=r==null?"":String(r)}}function ie(t){if(t.hasAttribute("transient")){t.removeAttribute("value"),t.removeAttribute("checked"),t.removeAttribute("data-value");return}nt(t)||D(t)}function Ze(t){t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0}))}function ae(t,e){return se(t,e)}function ue(t){let e=ht(t);return{el:t,kind:e,read(){return se(t,e)},write(r,n={}){Qe(t,e,r),n.noMirror||ie(t),n.silent||Ze(t)},mirror(){ie(t)}}}var _=null,ot=!1,F=null;function ce(t){let e=null;return{kind:"hub",subscribe(r){let n=t.onAnyChange({debounce:0,require:"observed"},r);typeof n=="function"&&(e=n)},suppress(r){t.pause();try{return r()}finally{t.resume()}},teardown(){if(e){try{e()}catch{}e=null}}}}function tn(){let t=null;return{kind:"native",subscribe(e){t=new MutationObserver(n=>e(en(n)));let r=typeof document<"u"&&document.body||typeof document<"u"&&document.documentElement;r&&t.observe(r,{childList:!0,subtree:!0,attributes:!0,characterData:!0})},suppress(e){let r=w("undo");r&&r.pause&&r.pause();try{return e()}finally{t&&t.takeRecords(),r&&r.resume&&r.resume()}},teardown(){t&&(t.disconnect(),t=null)}}}function en(t){let e=[];for(let r of t)if(r.type==="attributes"){let n=r.target;n&&n.nodeType===1&&!rt(n)&&e.push({type:"attribute",element:n})}else if(r.type==="characterData"){let n=r.target&&r.target.parentElement;n&&!rt(n)&&e.push({type:"characterData",element:n})}else if(r.type==="childList"){for(let n of r.addedNodes)if(!(n.nodeType!==1||rt(n))&&(e.push({type:"add",element:n}),n.querySelectorAll))for(let o of n.querySelectorAll("*"))rt(o)||e.push({type:"add",element:o});for(let n of r.removedNodes)n.nodeType===1&&e.push({type:"remove",element:n,parent:r.target})}return e}function rt(t){return!!(t.closest&&t.closest("[sap-ignore],[template],[cms-template]"))}function nn(t,e){t.pruneDisconnected();let r=new Set,n=!1;for(let o of e){let u=o.type==="remove"?o.parent:o.element,i=u&&t.appFor(u);i&&r.add(i),o.type==="add"&&o.element&&o.element.nodeType===1&&o.element.hasAttribute&&o.element.hasAttribute("sap")&&!(t.isRegistered&&t.isRegistered(o.element))&&(n=!0)}n&&t.remountIfPresent();for(let o of r)o.root.isConnected&&t.schedule(o,"mutation")}function le(t){if(_)return _.suppress(t);let e=w("undo");if(e&&e.pause&&e.resume){e.pause();try{return t()}finally{e.resume()}}return t()}function bt(t,e){ot=!0,_=t,t.subscribe(r=>nn(e,r))}function gt(t){if(ot||typeof window>"u"||typeof document>"u")return;let e=w("Mutation");if(e&&typeof e.onAnyChange=="function"){bt(ce(e),t);return}typeof MutationObserver=="function"&&(bt(tn(),t),F=B(document,mt,function(){let n=w("Mutation");n&&(F(),F=null,_&&_.teardown(),ot=!1,bt(ce(n),t))}))}function yt(){if(_)try{_.teardown()}catch{}F&&typeof document<"u"&&F(),_=null,ot=!1,F=null}var rn=new Set(O),R=[],de={},pe={};function me(t){R.includes(t)||(R.push(t),t.boundary&&Object.assign(de,t.boundary),t.paintKinds&&Object.assign(pe,t.paintKinds))}function it(t,e={}){if(e.breaker){t.diag.error("E26",t.root,{problem:"recompute loop halted after 50 passes; recent triggers: "+(t._breakerRing||[]).join(", ")}),P(t.root,"loop");return}e.full&&Gt();let r=Xt(t.root);try{le(()=>on(t,e))}finally{Kt(r)}t._viewsChanged&&(t._viewsChanged=!1,t.root.dispatchEvent(new CustomEvent("sap:views-updated",{bubbles:!0})))}function on(t,e){let r=t.root,n={},o=[],u=[],i=new Set;t.diag.errors=[];let d={root:n,state:n,item:null,ownerEl:r,projection:!1};function l(s,f){let h=f.attr||f.name,p=s.getAttribute(h);return p==null&&(p=dt(f),u.push({el:s,name:f.name,attr:h,value:Pt(X(p,f.type),f.type)})),X(p,f.type)}function c(s,f,h){let p=f.decls;if(p)for(let b of p){if(b.transient){h[b.name]=Ot(s,b);continue}if(Mt(s,b)){h[b.name]=s.hasAttribute(b.attr);continue}h[b.name]=l(s,b)}}function a(s,f,h){let p=f.bind,b=h.item||h.state,$=ht(s);$==="radio"?(p in b||(b[p]=""),s.checked&&(b[p]=s.value)):b[p]=ae(s,$),f.transient&&(s.removeAttribute("value"),s.removeAttribute("checked"))}function m(s,f,h){if(f.paints)for(let p of f.paints)p.kind==="when"&&i.add(p.field),o.push({def:p,el:s,ctx:h});for(let p of R)p.collect&&p.collect(v,s,f,h)}function g(s,f,h){Object.defineProperty(s,"$key",{value:Rt(f,"row"),enumerable:!1}),Object.defineProperty(s,"$index",{value:h,enumerable:!1}),Object.defineProperty(s,"$el",{value:f,enumerable:!1})}function A(s,f,h){let p=tt(s);c(s,p,f),s._sapScope=f,!h.projection&&p.bind!=null&&a(s,p,h),m(s,p,h),p.items?z(s,f,h):E(s,f,h)}function E(s,f,h){for(let p=s.firstElementChild;p;p=p.nextElementSibling)x(p,f,h)}function x(s,f,h){let p=tt(s);if(!p.inert){if(p.boundary){p.boundary==="scope"?k(s,f,h):p.boundary==="items"?(m(s,p,h),z(s,f,h)):de[p.boundary](v,s,p,f,h);return}!h.projection&&!h.view&&p.bind!=null&&a(s,p,h),m(s,p,h);for(let b=s.firstElementChild;b;b=b.nextElementSibling)x(b,f,h)}}function k(s,f,h){let p=s.getAttribute("scope"),b={};f[p]=b;let $={root:h.root,state:b,item:null,ownerEl:s,projection:h.projection};A(s,b,$)}function z(s,f,h){let p=s.getAttribute("items"),b=[];f[p]=b,s._sapList=b;let $=0;for(let L=s.firstElementChild;L;L=L.nextElementSibling){let kt=tt(L);if(!kt.item||kt.template||L.hasAttribute("cms-template"))continue;let V={};g(V,L,$);let Re={root:h.root,state:h.state,item:V,ownerEl:L,projection:h.projection};A(L,V,Re),b.push(V),$++}}let v={app:t,root:r,rootObj:n,paints:o,stats:{calcs:0,lists:0},resolveDefault:l,collectEl:m,walkScope:E};for(let s of R)s.begin&&s.begin(v);if(A(r,n,d),t.halted)return;for(let s of R)s.afterIntake&&s.afterIntake(v);if(u.length&&i.size)for(let s of u)i.has(s.attr)&&s.el.getAttribute(s.attr)==null&&s.el.setAttribute(s.attr,s.value);for(let s of R)s.compute&&s.compute(v);let M=0;for(let s of R)s.reconcile&&(M+=s.reconcile(v));let C=0,y=M;for(let s of o){let f=an(s,t);s.ctx.view?y+=f:C+=f}for(let s of R)s.afterPaint&&s.afterPaint(v);t._state=n,t._stats={fields:Object.keys(n).filter(s=>typeof n[s]!="function").length,calcs:v.stats.calcs,paints:o.length,lists:v.stats.lists,writes:C,viewWrites:y},t._viewsChanged=y>0,t._lastPass={trigger:e.trigger||"refresh",writes:C},t._debug&&console.log(`sap pass \xB7 trigger: ${t._lastPass.trigger} \xB7 writes ${C}/${o.length}`)}function sn(t){return t.kind==="text"?t.fmt?"text:"+t.fmt:"text":t.kind==="attr"?"attr:"+t.arg:t.kind==="class"?"class:"+t.arg:t.kind==="css"?"css:"+t.arg:t.kind==="when"?(t.match==="hide"?"hide-when:":t.match==="show-not"?"option-not:":"show-when:")+t.field:t.kind}function wt(t,e,r,n){let o=t;for(;o&&o.nodeType===1;){if(o.hasAttribute&&o.hasAttribute(e)){let u=r.includes(o.getAttribute(e));if(n?!u:u)return!0}o=o.parentElement}return!1}function an(t,e){let r=t.def,n=t.el,o=pe[r.kind];if(o)return o(t,e);if(r.kind==="when")return fe(r,n,null);try{let u=qt(r.entry,t.ctx.state,t.ctx.item,n,t.ctx.root),i=fe(r,n,u);return Lt(n),i}catch(u){return e.diag.error(u.sapCode==="E22"?"E22":"E24",n,{attr:sn(r),expr:r.entry&&r.entry.src,problem:String(u.message)}),P(n,u.sapCode||"E24"),0}}function fe(t,e,r){switch(t.kind){case"text":{let n=t.fmt!=null?Ht(t.fmt,r):r==null?"":String(r);return e.textContent!==n?(e.textContent=n,1):0}case"show":{let n=!r;return e.hidden!==n?(e.hidden=n,1):0}case"when":{let n=w("optionVisibility");if(n&&n._started)return e._sapWhen&&e.hidden?(e.hidden=!1,e._sapWhen=!1,1):0;let o;t.match==="hide"?o=!wt(e,t.field,t.values,!1):t.match==="show-not"?o=wt(e,t.field,t.values,!0):o=wt(e,t.field,t.values,!1),e._sapWhen=!0;let u=!o;return e.hidden!==u?(e.hidden=u,1):0}case"attr":{let n=t.arg;if((n==="checked"||n==="selected")&&typeof e[n]=="boolean"&&!e.hasAttribute("bind")&&!e.closest("select[bind]")){let u=0;return e[n]!==!!r&&(e[n]=!!r,u=1),!!r!==e.hasAttribute(n)&&(r?e.setAttribute(n,""):e.removeAttribute(n),u=1),u}if(rn.has(n)){let u=e.hasAttribute(n);return r&&!u?(e.setAttribute(n,""),1):!r&&u?(e.removeAttribute(n),1):0}let o=typeof r=="boolean"?String(r):r==null?"":String(r);return e.getAttribute(n)!==o?(e.setAttribute(n,o),1):0}case"class":{let n=!!r;return e.classList.contains(t.arg)!==n?(e.classList.toggle(t.arg,n),1):0}case"css":{let n=r==null?"":String(r);return e.style.getPropertyValue("--"+t.arg)!==n?(e.style.setProperty("--"+t.arg,n),1):0}default:return 0}}var un=new Set(O),he=new Set(["calc","text","attr","class","css","set","move","sort","option","option-not","show-when","hide-when","editmode"]),cn=new Set(["show-when","hide-when","option","option-not"]),ln=/\b(?:state|item|root)\.|===|!==|&&|\|\||[()]|^\s*!/,be=new Set(["sap","scope","items","item","template","bind","show","effect","invalid","detail","state","transient","confirm","default","persist","sortable","trigger-add","trigger-remove","trigger-reset","sap-ignore","sap-error","no-save","no-watch","no-undo","no-trigger-autosave","freeze","mutations-ignore","save-remove","save-ignore","save-freeze"]),Et=[];function ge(t){Et.includes(t)||Et.push(t)}function fn(t){return t.tagName==="INPUT"||t.tagName==="SELECT"||t.tagName==="TEXTAREA"}function At(t){return t.hasAttribute("bind")}function dn(t,e){e(t);for(let n=t.firstElementChild;n;n=n.nextElementSibling)r(n);function r(n){if(!n.hasAttribute("sap-ignore")){if(n.tagName==="TEMPLATE"){if(n.hasAttribute("items"))for(let o=n.content.firstElementChild;o;o=o.nextElementSibling)r(o);return}e(n);for(let o=n.firstElementChild;o;o=o.nextElementSibling)r(o)}}}function ye(t,e){let r=!1,n=(i,d,l)=>{e.error(i,d,l),r=!0},o=t.ownerDocument.createTreeWalker(t,4),u;for(;u=o.nextNode();)if(/\{\{.*\}\}/.test(u.nodeValue||"")){n("E02",u.parentElement||t,{problem:"moustaches in text content are not a Sap feature",fix:'move the expression onto the element: text="state.x"'});break}return dn(t,i=>{let d=new Set;for(let c of Et)c(i,n,a=>d.add(a));let l=i.closest&&i.closest("[detail]");for(let c of[...i.attributes]){let a=c.name;if(d.has(a))continue;if(a.includes(":")){let g=a.slice(0,a.indexOf(":"));if(he.has(g)){if(cn.has(g)&&ln.test(c.value)){let A=a.slice(a.indexOf(":")+1);e.warn("W04",i,{attr:a,expr:c.value,problem:`${g}: compares the "${A}" attribute against a literal value, not a JS expression`,fix:`use show="${c.value}" for an expression, or a literal like ${g}:${A}="overview"`})}}else{let A=ct(g,[...he]);e.warn("W03",i,{attr:a,problem:`unknown "${g}:" attribute`,didYouMean:A?`${A}:`:null})}}else if(!be.has(a)&&!ut.has(a)&&!un.has(a)&&!/^(data-|aria-|on)/.test(a)&&!(a in i)){let g=ct(a,[...be]);g&&e.warn("W03",i,{attr:a,problem:`unknown "${a}" attribute`,didYouMean:g})}a==="attr:hidden"&&e.warn("W03",i,{attr:a,problem:"attr:hidden paints the wrong attribute",fix:'use show="expr"'});let m=At(i)||a==="attr:selected"&&i.tagName==="OPTION"&&!!i.closest("select[bind]");(a==="attr:value"||a==="attr:checked"||a==="attr:selected")&&m&&n("E30",i,{attr:a,problem:"attr: on a bound control collides with persist ownership",fix:"remove it; bind owns this attribute"}),a==="effect"&&At(i)&&/\b(value|checked)\s*=[^=]/.test(c.value)&&n("E30",i,{attr:a,expr:c.value,problem:"effect writes value/checked on a bound control (writes a stale value with no synthetic event)",fix:"write through onclick + Sap(this) instead"}),(a==="text"||a.startsWith("text:")||a==="show")&&fn(i)&&(a==="show"||n("E18",i,{attr:a,problem:"paint belongs on output elements, not form controls",fix:"move the paint to an <output> or <span>"}))}if(i.hasAttribute("state")){let c=G(i.getAttribute("state")),a=new Set;for(let m of c){m.name.includes("-")&&n("E08",i,{attr:"state",problem:`field "${m.name}" is not a valid identifier (the hyphen parses as subtraction)`,fix:`rename to ${m.name.replace(/-/g,"")}`}),a.has(m.name)&&n("E04",i,{attr:"state",problem:`field "${m.name}" is declared twice in one scope`}),a.add(m.name),Tt.has(m.attr)&&n("E05",i,{attr:"state",problem:`"${m.name}" is a reserved Sap word`}),ut.has(m.attr)&&n("E06",i,{attr:"state",problem:`"${m.name}" is a global HTML attribute name; pick another field name`}),m.name==="open"&&i.tagName==="DIALOG"&&n("E33",i,{attr:"state",problem:"dialog open is transient",fix:"use showModal() \u2014 declare state= only on <details> or popovers"});let g=ft(i,m.attr);g&&(m.attr==="checked"||m.attr==="selected")&&n("E35",i,{attr:"state",problem:`"${m.attr}" on a form control is the control's own state, not a declared field`,fix:'bind the control instead, e.g. <input type="checkbox" bind="done">'}),g&&m.type==="num"&&n("E35",i,{attr:"state",problem:`"${m.attr}" is an HTML boolean attribute; it cannot hold a number`,fix:`declare it bare: state="${m.attr}"`}),m.transient&&(g||m.type==="presence")&&n("E35",i,{attr:"state",problem:`"${m.name}" is carried by attribute presence, which transient would strip`,fix:"declare a separate name:bool:transient field and paint the attribute from it"})}}if(At(i)){if(i.hasAttribute("-"),i.tagName==="INPUT"){let c=(i.getAttribute("type")||"text").toLowerCase();c==="file"&&n("E32",i,{attr:"bind",problem:"files never serialize into an HTML file",fix:"use no-save + effect instead of bind"}),c==="password"&&!i.hasAttribute("transient")&&n("E31",i,{attr:"bind",problem:"a password must never serialize into a world-readable file",fix:"add transient to the password input"})}else if(i.tagName!=="SELECT"&&i.tagName!=="TEXTAREA"){let c=i.getAttribute("contenteditable");!(c!=null&&c!=="false")&&i.children.length>0&&n("E20",i,{attr:"bind",problem:"bind on a container element is not a control; a write would overwrite its children",fix:"bind a control (input/select/textarea), a contenteditable, or an empty text leaf"})}}if(i.hasAttribute("transient")&&i.hasAttribute("persist")&&n("E34",i,{problem:"transient and persist are opposite: persist forces the live value into the saved bytes, leaking exactly what transient drops",fix:"remove one \u2014 transient to keep it out of the file, or persist to save it"}),i.tagName==="DIALOG"&&i.hasAttribute("detail")&&!(i.parentElement&&i.parentElement.closest('[clay~="freeze"], [freeze], [save-freeze]'))&&e.warn("W31",i,{attr:"detail",problem:"a detail dialog writes open when it opens, and that attribute would be saved into the file",fix:'wrap the dialog in an element with clay="freeze" (not editor-ui, which removes it from the file), and make its key field transient'}),i.hasAttribute("item")&&!i.hasAttribute("template")&&i.parentNode&&i.parentNode.nodeType===1){let c=i.parentElement;(!c||!c.hasAttribute("items"))&&n("E10",i,{problem:"an [item] must be a direct child of an [items] list",fix:'wrap it in a container with items="name"'})}if(i.hasAttribute("items")&&l&&n("E17",i,{attr:"items",problem:"nested items inside a detail panel is a v1 mount error (nested collections ship in v1.1)"}),i.hasAttribute("items")){let c=t.querySelector(`[trigger-add="${i.getAttribute("items")}"]`);!$t(i)&&!lt(t,i.getAttribute("items"))&&Ct(i).length===0&&c&&n("E17",i,{attr:"items",problem:`trigger-add targets items="${i.getAttribute("items")}" but it has no [item template] to clone`})}}),r&&(e.halted=!0,e.haltReason=e.errors[0]?e.errors[0].code:"halt",P(t,e.haltReason)),!r}var we="sap-styles",Ae="[item][template]{display:none!important}[hidden]{display:none!important}[sap-error]{outline:2px solid #e5484d;outline-offset:1px}",xt=new WeakSet;function pn(t){if(xt.has(t))return;let e=t.defaultView,r=e&&e.CSSStyleSheet;if(r&&"adoptedStyleSheets"in t)try{let n=new r;n.replaceSync(Ae),t.adoptedStyleSheets=[...t.adoptedStyleSheets,n],xt.add(t);return}catch{}if(!t.getElementById(we)){let n=t.createElement("style");n.id=we,n.textContent=Ae,(t.head||t.documentElement).appendChild(n)}xt.add(t)}var mn=0;function Ee(){return typeof performance<"u"&&performance.now?performance.now():0}function vt(t){let e=t.id||t.getAttribute("sap")||`app-${mn++}`,r=new Y(e),n={root:t,name:e,diag:r,_state:null,_stats:null,_lastPass:null,_passes:0,_broken:!1,_mountMs:0,_mountWrites:0};if(!ye(t,r))return n.halted=!0,n;pn(t.ownerDocument);for(let i of t.querySelectorAll("textarea[data-value]"))et(i);let u=Ee();return it(n,{trigger:"mount",full:!0}),n._mountMs=Ee()-u,n._mountWrites=n._stats?n._stats.writes:0,n._mountWrites>0&&!ee()&&!w("derived")&&r.warn("W30",t,{problem:`${n._mountWrites} paint(s) ran at mount; the saved file was out of sync with its declared state`,fix:"re-save once so the file mounts clean (a settled file writes nothing)"}),n}var xe=/^(set:|move:|sort:|trigger-add$|trigger-remove$|trigger-reset$)/;function hn(t){return`${t.tagName.toLowerCase()}[sap]`}function bn(t){let e=0;for(let r of t.querySelectorAll("*"))for(let n of r.attributes)if(xe.test(n.name)){e++;break}for(let r of t.attributes)if(xe.test(r.name)){e++;break}return e}function ve(t){function e(d){let l=d._stats||{},c=d.root;return{root:hn(c),fields:l.fields||0,calcs:l.calcs||0,paints:l.paints||0,actions:bn(c),lists:(c.hasAttribute("items")?1:0)+c.querySelectorAll("[items]").length,rows:c.querySelectorAll("[item]:not([template])").length,warnings:d.diag.warnings.length,errors:d.diag.errors.length,mountWrites:d._mountWrites||0,ms:Math.round((d._mountMs||0)*10)/10,passes:d._passes||0,lastPass:d._lastPass||null,ok:d.diag.errors.length===0&&!d.halted}}function r(){let d=t.apps().map(e);return{ok:d.every(l=>l.ok),apps:d}}function n(d){let l=e(d);return l.ok?`sap \u2713 ${l.root} \xB7 fields ${l.fields} \xB7 calcs ${l.calcs} \xB7 paints ${l.paints} \xB7 actions ${l.actions} \xB7 lists ${l.lists} \xB7 rows ${l.rows} \xB7 warnings ${l.warnings} \xB7 mount writes ${l.mountWrites} \xB7 ${l.ms}ms`:`sap \u2717 ${l.root} \xB7 errors ${l.errors} \xB7 warnings ${l.warnings} \xB7 ${l.ms}ms`}function o(){for(let d of t.apps()){let l=n(d);d.diag.errors.length||d.halted?console.error(l):console.log(l)}}function u(){let d=[],l=[];for(let c of t.apps())d.push(...c.diag.errors),l.push(...c.diag.warnings);return{ok:d.length===0,errors:d,warnings:l,counts:{errors:d.length,warnings:l.length}}}function i(d){let l=d===void 0?!0:!!d;for(let c of t.apps())c._debug=l;return console.log(`sap debug ${l?"on":"off"} \u2014 per-pass headers will ${l?"":"no longer "}log`),l}return{status:r,report:u,debug:i,greenLine:n,printGreenLines:o,REGISTRY:at}}var Se="0.6.0";function ke({createAccessor:t,installInput:e,debugExtras:r}){let n=new Map,o=[],u=Nt(it);function i(s){let f=s;for(;f;){if(f.nodeType===1&&f.hasAttribute&&f.hasAttribute("sap"))return n.get(f)||null;f=f.parentNode&&f.parentNode.host?f.parentNode.host:f.parentElement}return null}function d(){for(let s=o.length-1;s>=0;s--){let f=o[s];f.root.isConnected||(n.delete(f.root),o.splice(s,1))}}function l(s,f){if(s.moveBefore)try{s.moveBefore(f,null);return}catch{}s.appendChild(f)}function c(s,f){let h=f.parentElement;if(h){if(h.moveBefore)try{h.moveBefore(s,f);return}catch{}h.insertBefore(s,f)}}let a={apps:()=>o.slice(),appFor:i,isRegistered:s=>n.has(s),pruneDisconnected:d,schedule:(s,f)=>u.schedule(s,f),runNow:(s,f)=>u.runNow(s,f),moveInto:l,placeBefore:c,remountIfPresent:()=>M()},m=t(a),g=ve(a),A=r?r(a,g):{},E=!1,x=!1,k=null;function z(){E||(E=!0,e(a,m,document),k=oe(a))}function v(){let s=w("derived");s&&typeof s.mounted=="function"&&s.mounted()}function M(s=document){if(x)return[];z(),gt(a);let f=s.querySelectorAll("[sap]"),h=[];for(let p of f){if(n.has(p))continue;let b=vt(p);n.set(p,b),o.push(b),h.push(b)}for(let p of h){let b=g.greenLine(p);p.diag.errors.length||p.halted?console.error(b):console.log(b)}return v(),h}function C(s){if(x)return null;if(z(),gt(a),!s)return M();let f=typeof s=="string"?document.querySelector(s):s;if(!f)return null;if(n.has(f))return n.get(f);let h=vt(f);n.set(f,h),o.push(h);let p=g.greenLine(h);return h.diag.errors.length||h.halted?console.error(p):console.log(p),h}let y=m.Sap;return y.version=Se,y.refresh=function(){for(let f of o)f.root.isConnected&&u.runNow(f,"refresh")},y.batch=re,y.status=g.status,y.report=g.report,y.why=A.why,y.debug=g.debug,y.doctor=A.doctor,y.greenLine=g.greenLine,y.formats=I,y.serializeControlToAttributes=D,y.finalizeControlForSave=te,y.rehydrateControlFromAttributes=et,y.mount=C,y.config=function(f={}){return f.formats&&Object.assign(I,f.formats),y},y._registry=n,y._reset=function(){n.clear(),o.length=0,yt()},y.unmount=function(){x=!0,n.clear(),o.length=0,yt(),typeof k=="function"&&k()},{Sap:y,mountAll:M,mount:C,runtime:a}}function Ne(t){if(typeof document>"u")return;let e=()=>ne(()=>t());document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e):e()}function Te(t){let e=[];function r(l){let c=l.target;if(!c||c.nodeType!==1)return;let a=t.appFor(c);if(a){c.hasAttribute("persist")&&!nt(c)&&D(c);for(let m of e)if(m(c,a))return;t.schedule(a,l.type+" "+(c.id||c.tagName.toLowerCase()))}}function n(l){let c=l.target,a=t.appFor(c);a&&setTimeout(()=>{c.querySelectorAll("[bind]").forEach(m=>{m.dispatchEvent(new Event("input",{bubbles:!0})),m.dispatchEvent(new Event("change",{bubbles:!0}))}),t.schedule(a,"reset")},0)}function o(l){let c=t.appFor(l.target);c&&t.schedule(c,"toggle")}function u(l){let c=l.detail||{};for(let a of[c.from,c.to,l.target]){if(!a||a.nodeType!==1)continue;let m=t.appFor(a);m&&t.schedule(m,"sorted")}}function i(l){if(l.key!=="ArrowUp"&&l.key!=="ArrowDown")return;let c=l.target;if(!c||c.nodeType!==1||c.tagName!=="INPUT"||!c.hasAttribute("bind")||!c.hasAttribute("step"))return;let a=(c.getAttribute("type")||"text").toLowerCase();if(a!=="text"&&a!=="tel"&&a!=="search"||!t.appFor(c))return;l.preventDefault();let g=S(c.getAttribute("step"))||1,A=l.key==="ArrowUp"?1:-1,E=S(c.value)+g*(l.shiftKey?10:1)*A,x=c.getAttribute("min"),k=c.getAttribute("max");x!==null&&x!==""&&E<S(x)&&(E=S(x)),k!==null&&k!==""&&E>S(k)&&(E=S(k)),ue(c).write(String(Number(E.toFixed(2))))}function d(l=document){l.addEventListener("reset",n),l.addEventListener("toggle",o,!0),l.addEventListener("input",r),l.addEventListener("change",r),l.addEventListener("clay:sorted",u),l.addEventListener("keydown",i)}return{install:d,addRouter:l=>e.push(l)}}var U="https://clayjs.com/v1/sap.js",gn=/^(calc|set|move|sort):/,yn=new Set(["each","detail","effect","invalid","confirm","trigger-add","trigger-remove","trigger-reset"]);function St(t){return gn.test(t)||yn.has(t)}ge((t,e)=>{for(let r of t.attributes)St(r.name)&&e("E50",t,{attr:r.name,expr:r.value,problem:`${r.name} is full sapjs; the sapjs core only paints declared state`,fix:`load ${U}; the markup stays as it is`})});function W(t,e,r){t.app.diag.error("E50",e,{attr:r,problem:`${r} is full sapjs; the sapjs core only paints declared state`,fix:`load ${U}; the markup stays as it is`}),P(e,"E50"),t.app.halted=!0}me({name:"core-only",collect(t,e,r){r.calcs&&W(t,e,"calc:"+r.calcs[0].name),r.effects&&W(t,e,"effect"),r.invalids&&W(t,e,"invalid");for(let n of e.attributes)St(n.name)&&(n.name.startsWith("calc:")&&r.calcs||n.name==="effect"&&r.effects||n.name==="invalid"&&r.invalids||W(t,e,n.name))},boundary:{each(t,e){W(t,e,"each")},detail(t,e){W(t,e,"detail")}}});function wn(){return{Sap:function(){throw new Error(`Sap(el) is full sapjs; load ${U}`)}}}var Le=t=>()=>(console.warn(`Sap.${t} is full sapjs; load ${U}`),null),{Sap:q,mountAll:_e,mount:An,runtime:En}=ke({createAccessor:wn,debugExtras:()=>({why:Le("why"),doctor:Le("doctor")}),installInput(t,e,r){Te(t).install(r)}});q.core=!0;var xn=typeof window<"u"&&window.Sap&&!window.Sap.core;xn?q.unmount():Ne(_e);typeof window<"u"&&!window.Sap&&(window.Sap=q);var vn=q;return Ie(Sn);})();
9
+ export default SapCoreBundle.default;
@@ -0,0 +1,111 @@
1
+ // GENERATED — do not edit. Vendored from sapjs/src/ownership.js
2
+ // via sapjs `npm run propagate`, which writes every client's copy from one
3
+ // table. Edit the sapjs source and re-run.
4
+
5
+ // What sapjs paints on an element, read from that element's own attributes. No
6
+ // expression runs and no engine state is read, so a host can ask it of any tree:
7
+ // the live page, a snapshot clone, or a parsed frame. Self-contained on purpose:
8
+ // ClayJS vendors this file verbatim.
9
+
10
+ export const BEACON = "sap-error";
11
+
12
+ const WHEN = /^(show-when|hide-when|option|option-not):/;
13
+ // Identity and the attributes that declare the record itself are never paint
14
+ // output. Form state is, unless a bind or persist owns it.
15
+ const NEVER = new Set([
16
+ "id", "data-id", "class", "style",
17
+ "sap", "scope", "items", "item", "bind", "state", "template", "cms-template", "sap-ignore",
18
+ ]);
19
+ const FORM_STATE = new Set(["value", "checked", "selected"]);
20
+
21
+ function recordOwnsFormState(el) {
22
+ return el.hasAttribute("bind") || el.hasAttribute("persist") || !!el.closest("select[bind]");
23
+ }
24
+
25
+ function inert(el) {
26
+ return el.localName === "template" || el.hasAttribute("template") || el.hasAttribute("cms-template") || el.hasAttribute("sap-ignore");
27
+ }
28
+
29
+ // The [sap] root an element is painted under, or null when it sits outside every
30
+ // app or inside a subtree the engine never reads.
31
+ export function appOf(el) {
32
+ for (let cur = el; cur && cur.nodeType === 1; cur = cur.parentElement) {
33
+ if (inert(cur)) return null;
34
+ if (cur.hasAttribute("sap")) return cur;
35
+ }
36
+ return null;
37
+ }
38
+
39
+ function declares(el, name) {
40
+ const decl = el.getAttribute("state");
41
+ if (!decl) return false;
42
+ for (const token of decl.trim().split(/\s+/)) {
43
+ if (token.split("=")[0].split(":")[0] === name) return true;
44
+ }
45
+ return false;
46
+ }
47
+
48
+ function paintsHidden(el) {
49
+ if (el.hasAttribute("show")) return true;
50
+ for (const a of el.attributes) if (WHEN.test(a.name)) return true;
51
+ return false;
52
+ }
53
+
54
+ // True when a sapjs paint writes attribute `name` on `el`.
55
+ export function ownsAttr(el, name) {
56
+ if (!el || el.nodeType !== 1 || !name) return false;
57
+ if (name === BEACON) return !!appOf(el);
58
+ if (NEVER.has(name)) return false;
59
+ if (FORM_STATE.has(name) && recordOwnsFormState(el)) return false;
60
+ if (name === "hidden") return paintsHidden(el) && !!appOf(el);
61
+ return el.hasAttribute("attr:" + name) && !declares(el, name) && !!appOf(el);
62
+ }
63
+
64
+ // Everything a paint writes on `el`: whole attributes, class tokens, --custom
65
+ // properties in style, and whether text owns its children. Null when nothing.
66
+ export function paintsOf(el) {
67
+ if (!el || el.nodeType !== 1 || !appOf(el)) return null;
68
+ let out = null;
69
+ const add = (key, v) => ((out || (out = { attrs: [], classes: [], vars: [], text: false }))[key].push(v));
70
+ for (const a of el.attributes) {
71
+ const n = a.name;
72
+ if (n === "text" || n.startsWith("text:")) {
73
+ if (!el.hasAttribute("bind")) (out || (out = { attrs: [], classes: [], vars: [], text: false })).text = true;
74
+ }
75
+ else if (n.startsWith("attr:")) {
76
+ const target = n.slice(5);
77
+ if (target && !NEVER.has(target) && !(FORM_STATE.has(target) && recordOwnsFormState(el)) && !declares(el, target)) add("attrs", target);
78
+ } else if (n.startsWith("class:")) add("classes", n.slice(6));
79
+ else if (n.startsWith("css:")) add("vars", "--" + n.slice(4));
80
+ }
81
+ if (paintsHidden(el)) add("attrs", "hidden");
82
+ if (el.hasAttribute(BEACON)) add("attrs", BEACON);
83
+ return out;
84
+ }
85
+
86
+ // Calls visit(el, paints) for every painted element under root, in document order.
87
+ export function eachPainted(root, visit) {
88
+ if (!root || root.nodeType !== 1 && root.nodeType !== 9) return;
89
+ const apps = root.nodeType === 1 && root.hasAttribute("sap")
90
+ ? [root]
91
+ : [...root.querySelectorAll("[sap]")].filter((app) => !app.parentElement || !app.parentElement.closest("[sap]"));
92
+ for (const app of apps) {
93
+ for (const el of [app, ...app.querySelectorAll("*")]) {
94
+ const p = paintsOf(el);
95
+ if (p) visit(el, p);
96
+ }
97
+ }
98
+ }
99
+
100
+ // Removes every painted value from a detached tree, in place: owned attributes,
101
+ // owned class tokens and --properties, and the children of text paints.
102
+ export function stripPaints(root) {
103
+ eachPainted(root, (el, p) => {
104
+ for (const name of p.attrs) if (el.hasAttribute(name)) el.removeAttribute(name);
105
+ for (const token of p.classes) if (el.classList.contains(token)) el.classList.remove(token);
106
+ if (!el.getAttribute("class") && el.hasAttribute("class") && p.classes.length) el.removeAttribute("class");
107
+ for (const v of p.vars) if (el.style.getPropertyValue(v) !== "") el.style.removeProperty(v);
108
+ if (p.vars.length && el.hasAttribute("style") && !el.getAttribute("style").trim()) el.removeAttribute("style");
109
+ if (p.text && el.firstChild) el.replaceChildren();
110
+ });
111
+ }
@@ -0,0 +1,7 @@
1
+ /* Yjs (MIT) and lib0 (MIT), bundled for clayjs: yjs 13.6.27, lib0 0.2.119.
2
+ https://github.com/yjs/yjs, regenerate with node scripts/build-yjs-vendor.mjs */
3
+ var Gi=Object.defineProperty;var zi=(e,t,n)=>t in e?Gi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Ge=(e,t,n)=>zi(e,typeof t!="symbol"?t+"":t,n);var A=()=>new Map,ze=e=>{let t=A();return e.forEach((n,r)=>{t.set(r,n)}),t},L=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},Kr=(e,t)=>{let n=[];for(let[r,s]of e)n.push(t(s,r));return n},Yr=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1};var rt=()=>new Set;var He=e=>e[e.length-1];var Wr=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},Y=Array.from,Je=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},de=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1};var Zr=(e,t)=>{let n=new Array(e);for(let r=0;r<e;r++)n[r]=t(r,n);return n};var st=Array.isArray;var Dt=class{constructor(){this._observers=A()}on(t,n){return L(this._observers,t,rt).add(n),n}once(t,n){let r=(...s)=>{this.off(t,r),n(...s)};this.on(t,r)}off(t,n){let r=this._observers.get(t);r!==void 0&&(r.delete(n),r.size===0&&this._observers.delete(t))}emit(t,n){return Y((this._observers.get(t)||A()).values()).forEach(r=>r(...n))}destroy(){this._observers=A()}};var B=Math.floor;var yt=Math.abs;var Xe=(e,t)=>e<t?e:t,it=(e,t)=>e>t?e:t,Ol=Number.isNaN;var Pe=e=>e!==0?e<0:1/e<0;var Tt=Number.MAX_SAFE_INTEGER,Fn=Number.MIN_SAFE_INTEGER,Nl=1<<31;var Qr=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&B(e)===e),Ll=Number.isNaN,Bl=Number.parseInt;var ge=String.fromCharCode,Hi=String.fromCodePoint,Ml=ge(65535),Ji=e=>e.toLowerCase(),Xi=/^\s*/g,Pi=e=>e.replace(Xi,""),Ki=/([A-Z])/g,qn=(e,t)=>Pi(e.replace(Ki,n=>`${t}${Ji(n)}`));var Yi=e=>{let t=unescape(encodeURIComponent(e)),n=t.length,r=new Uint8Array(n);for(let s=0;s<n;s++)r[s]=t.codePointAt(s);return r},Vt=typeof TextEncoder<"u"?new TextEncoder:null,Wi=e=>Vt.encode(e),ts=Vt?Wi:Yi;var vt=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});vt&&vt.decode(new Uint8Array).length===1&&(vt=null);var Ke=(e,t)=>Zr(t,()=>e).join("");var xt=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},kt=()=>new xt;var Zi=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t};var q=e=>{let t=new Uint8Array(Zi(e)),n=0;for(let r=0;r<e.bufs.length;r++){let s=e.bufs[r];t.set(s,n),n+=s.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},Qi=(e,t)=>{let n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(it(n,t)*2),e.cpos=0)},D=(e,t)=>{let n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t};var Mt=D;var g=(e,t)=>{for(;t>127;)D(e,128|127&t),t=B(t/128);D(e,127&t)},we=(e,t)=>{let n=Pe(t);for(n&&(t=-t),D(e,(t>63?128:0)|(n?64:0)|63&t),t=B(t/64);t>0;)D(e,(t>127?128:0)|127&t),t=B(t/128)},Gn=new Uint8Array(3e4),to=Gn.length/3,eo=(e,t)=>{if(t.length<to){let n=Vt.encodeInto(t,Gn).written||0;g(e,n);for(let r=0;r<n;r++)D(e,Gn[r])}else $(e,ts(t))},no=(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;g(e,r);for(let s=0;s<r;s++)D(e,n.codePointAt(s))},lt=Vt&&Vt.encodeInto?eo:no;var is=(e,t)=>Rt(e,q(t)),Rt=(e,t)=>{let n=e.cbuf.length,r=e.cpos,s=Xe(n-r,t.length),i=t.length-s;e.cbuf.set(t.subarray(0,s),r),e.cpos+=s,i>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(it(n*2,i)),e.cbuf.set(t.subarray(s)),e.cpos=i)},$=(e,t)=>{g(e,t.byteLength),Rt(e,t)},zn=(e,t)=>{Qi(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},ro=(e,t)=>zn(e,4).setFloat32(0,t,!1),so=(e,t)=>zn(e,8).setFloat64(0,t,!1),io=(e,t)=>zn(e,8).setBigInt64(0,t,!1);var ns=new DataView(new ArrayBuffer(4)),oo=e=>(ns.setFloat32(0,e),ns.getFloat32(0)===e),Lt=(e,t)=>{switch(typeof t){case"string":D(e,119),lt(e,t);break;case"number":Qr(t)&&yt(t)<=2147483647?(D(e,125),we(e,t)):oo(t)?(D(e,124),ro(e,t)):(D(e,123),so(e,t));break;case"bigint":D(e,122),io(e,t);break;case"object":if(t===null)D(e,126);else if(st(t)){D(e,117),g(e,t.length);for(let n=0;n<t.length;n++)Lt(e,t[n])}else if(t instanceof Uint8Array)D(e,116),$(e,t);else{D(e,118);let n=Object.keys(t);g(e,n.length);for(let r=0;r<n.length;r++){let s=n[r];lt(e,s),Lt(e,t[s])}}break;case"boolean":D(e,t?120:121);break;default:D(e,127)}},me=class extends xt{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&g(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}};var rs=e=>{e.count>0&&(we(e.encoder,e.count===1?e.s:-e.s),e.count>1&&g(e.encoder,e.count-2))},bt=class{constructor(){this.encoder=new xt,this.s=0,this.count=0}write(t){this.s===t?this.count++:(rs(this),this.count=1,this.s=t)}toUint8Array(){return rs(this),q(this.encoder)}};var ss=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);we(e.encoder,t),e.count>1&&g(e.encoder,e.count-2)}},Bt=class{constructor(){this.encoder=new xt,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(ss(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return ss(this),q(this.encoder)}},Ye=class{constructor(){this.sarr=[],this.s="",this.lensE=new bt}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){let t=new xt;return this.sarr.push(this.s),this.s="",lt(t,this.sarr.join("")),Rt(t,this.lensE.toUint8Array()),q(t)}};var G=e=>new Error(e),z=()=>{throw G("Method unimplemented")},T=()=>{throw G("Unexpected case")};var Ze=G("Unexpected end of array"),os=G("Integer out of Range"),lo=(e,t,n)=>{if(t<0||n<0||t+n>e.length)throw Ze;return new Uint8Array(e.buffer,e.byteOffset+t,n)},ao=(e,t,n)=>{if(t<0||n<0||t+n>e.length)throw Ze;return new DataView(e.buffer,e.byteOffset+t,n)},$t=class{constructor(t){this.arr=t,this.pos=0}},V=e=>new $t(e),Jn=e=>e.pos!==e.arr.length;var ho=(e,t)=>{let n=lo(e.arr,e.pos,t);return e.pos+=t,n},F=e=>ho(e,w(e));var St=e=>e.arr[e.pos++];var w=e=>{let t=0,n=1,r=e.arr.length;for(;e.pos<r;){let s=e.arr[e.pos++];if(t=t+(s&127)*n,n*=128,s<128)return t;if(t>Tt)throw os}throw Ze},xe=e=>{let t=e.arr[e.pos++],n=t&63,r=64,s=(t&64)>0?-1:1;if((t&128)===0)return s*n;let i=e.arr.length;for(;e.pos<i;){if(t=e.arr[e.pos++],n=n+(t&127)*r,r*=128,t<128)return s*n;if(n>Tt)throw os}throw Ze};var uo=e=>{let t=w(e);if(t===0)return"";{let n=String.fromCodePoint(St(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(St(e));else for(;t>0;){let r=t<1e4?t:1e4,s=e.arr.subarray(e.pos,e.pos+r);e.pos+=r,n+=String.fromCodePoint.apply(null,s),t-=r}return decodeURIComponent(escape(n))}},fo=e=>vt.decode(F(e)),ht=vt?fo:uo;var Xn=(e,t)=>{let n=ao(e.arr,e.pos,t);return e.pos+=t,n},po=e=>Xn(e,4).getFloat32(0,!1),go=e=>Xn(e,8).getFloat64(0,!1),mo=e=>Xn(e,8).getBigInt64(0,!1);var wo=[e=>{},e=>null,xe,po,go,mo,e=>!1,e=>!0,ht,e=>{let t=w(e),n={};for(let r=0;r<t;r++){let s=ht(e);n[s]=Ft(e)}return n},e=>{let t=w(e),n=[];for(let r=0;r<t;r++)n.push(Ft(e));return n},F],Ft=e=>wo[127-St(e)](e),ye=class extends $t{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Jn(this)?this.count=w(this)+1:this.count=-1),this.count--,this.s}};var _t=class extends $t{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=xe(this);let t=Pe(this.s);this.count=1,t&&(this.s=-this.s,this.count=w(this)+2)}return this.count--,this.s}};var jt=class extends $t{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let t=xe(this),n=t&1;this.diff=B(t/2),this.count=1,n&&(this.count=w(this)+2)}return this.s+=this.diff,this.count--,this.s}},We=class{constructor(t){this.decoder=new _t(t),this.str=ht(this.decoder),this.spos=0}read(){let t=this.spos+this.decoder.read(),n=this.str.slice(this.spos,t);return this.spos=t,n}};var Fl=crypto.subtle,cs=crypto.getRandomValues.bind(crypto);var Pn=()=>cs(new Uint32Array(1))[0];var xo="10000000-1000-4000-8000"+-1e11,ls=()=>xo.replace(/[018]/g,e=>(e^Pn()&15>>e/4).toString(16));var Qe=Date.now;var Kn=e=>new Promise(e);var Gl=Promise.all.bind(Promise);var Yn=e=>e===void 0?null:e;var Wn=class{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}},hs=new Wn,_o=!0;try{typeof localStorage<"u"&&localStorage&&(hs=localStorage,_o=!1)}catch{}var us=hs;var Et=Symbol("Equality"),tn=(e,t)=>e===t||!!e?.[Et]?.(t)||!1;var ds=e=>typeof e=="object",fs=Object.assign,Uo=Object.keys;var ps=(e,t)=>{for(let n in e)t(e[n],n)};var be=e=>Uo(e).length;var gs=e=>{for(let t in e)return!1;return!0},qt=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},ke=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Qn=(e,t)=>e===t||be(e)===be(t)&&qt(e,(n,r)=>(n!==void 0||ke(t,r))&&tn(t[r],n)),Co=Object.freeze,tr=e=>{for(let t in e){let n=e[t];(typeof n=="object"||typeof n=="function")&&tr(e[t])}return Co(e)};var _e=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&_e(e,t,n+1)}};var nr=e=>e;var Se=(e,t)=>{if(e===t)return!0;if(e==null||t==null||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(e[Et]!=null)return e[Et](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:{if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;break}case Set:{if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;break}case Map:{if(e.size!==t.size)return!1;for(let n of e.keys())if(!t.has(n)||!Se(e.get(n),t.get(n)))return!1;break}case void 0:case Object:if(be(e)!==be(t))return!1;for(let n in e)if(!ke(e,n)||!Se(e[n],t[n]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!Se(e[n],t[n]))return!1;break;default:return!1}return!0},ms=(e,t)=>t.includes(e);var Gt=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",en=typeof window<"u"&&typeof document<"u"&&!Gt,zl=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,W,Ao=[],Io=()=>{if(W===void 0)if(Gt){W=A();let e=process.argv,t=null;for(let n=0;n<e.length;n++){let r=e[n];r[0]==="-"?(t!==null&&W.set(t,""),t=r):t!==null?(W.set(t,r),t=null):Ao.push(r)}t!==null&&W.set(t,"")}else typeof location=="object"?(W=A(),(location.search||"?").slice(1).split("&").forEach(e=>{if(e.length!==0){let[t,n]=e.split("=");W.set(`--${qn(t,"-")}`,n),W.set(`-${qn(t,"-")}`,n)}})):W=A();return W},sr=e=>Io().has(e);var Ee=e=>Gt?Yn(process.env[e.toUpperCase().replaceAll("-","_")]):Yn(us.getItem(e));var ws=e=>sr("--"+e)||Ee(e)!==null,ys=ws("production"),Do=Gt&&ms(process.env.FORCE_COLOR,["true","1","2"]),xs=Do||!sr("--no-colors")&&!ws("no-color")&&(!Gt||process.stdout.isTTY)&&(!Gt||sr("--color")||Ee("COLORTERM")!==null||(Ee("TERM")||"").includes("color"));var bs=e=>new Uint8Array(e);var To=e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=ge(e[n]);return btoa(t)},vo=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),Vo=e=>{let t=atob(e),n=bs(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return n},Oo=e=>new Uint8Array(Buffer.from(e,"base64")),No=en?To:vo,Lo=en?Vo:Oo;var ks=e=>{let t=bs(e.byteLength);return t.set(e),t};var ir=class{constructor(t,n){this.left=t,this.right=n}},Z=(e,t)=>new ir(e,t);var or=e=>e.next()>=.5,rn=(e,t,n)=>B(e.next()*(n+1-t)+t);var cr=(e,t,n)=>B(e.next()*(n+1-t)+t);var lr=(e,t,n)=>cr(e,t,n);var Ro=e=>ge(lr(e,97,122)),Ss=(e,t=0,n=20)=>{let r=lr(e,t,n),s="";for(let i=0;i<r;i++)s+=Ro(e);return s};var sn=(e,t)=>t[lr(e,0,t.length-1)];var Fo=Symbol("0schema"),ar=class{constructor(){this._rerrs=[]}extend(t,n,r,s=null){this._rerrs.push({path:t,expected:n,has:r,message:s})}toString(){let t=[];for(let n=this._rerrs.length-1;n>0;n--){let r=this._rerrs[n];t.push(Ke(" ",(this._rerrs.length-n)*2)+`${r.path!=null?`[${r.path}] `:""}${r.has} doesn't match ${r.expected}. ${r.message}`)}return t.join(`
4
+ `)}},hr=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[Et]?tn(e,t):st(e)?Je(e,n=>de(t,r=>hr(n,r))):ds(e)?qt(e,(n,r)=>hr(n,t[r])):!1,v=class{extends(t){let[n,r]=[this.shape,t.shape];return this.constructor._dilutes&&([r,n]=[n,r]),hr(n,r)}equals(t){return this.constructor===t.constructor&&Se(this.shape,t.shape)}[Fo](){return!0}[Et](t){return this.equals(t)}validate(t){return this.check(t)}check(t,n){z()}get nullable(){return Kt(this,yn)}get optional(){return new on(this)}cast(t){return _s(t,this),t}expect(t){return _s(t,this),t}};Ge(v,"_dilutes",!1);var Ue=class extends v{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n=void 0){let r=t?.constructor===this.shape&&(this._c==null||this._c(t));return!r&&n?.extend(null,this.shape.name,t?.constructor.name,t?.constructor!==this.shape?"Constructor match failed":"Check failed"),r}},E=(e,t=null)=>new Ue(e,t),Jl=E(Ue),Ce=class extends v{constructor(t){super(),this.shape=t}check(t,n){let r=this.shape(t);return!r&&n?.extend(null,"custom prop",t?.constructor.name,"failed to check custom prop"),r}},I=e=>new Ce(e),Xl=E(Ce),Xt=class extends v{constructor(t){super(),this.shape=t}check(t,n){let r=this.shape.some(s=>s===t);return!r&&n?.extend(null,this.shape.join(" | "),t.toString()),r}},mn=(...e)=>new Xt(e),Es=E(Xt),jo=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,t=>"\\"+t)),Us=e=>{if(Pt.check(e))return[jo(e)];if(Es.check(e))return e.shape.map(t=>t+"");if(Ts.check(e))return["[+-]?\\d+.?\\d*"];if(vs.check(e))return[".*"];if(fn.check(e))return e.shape.map(Us).flat(1);T()},ur=class extends v{constructor(t){super(),this.shape=t,this._r=new RegExp("^"+t.map(Us).map(n=>`(${n.join("|")})`).join("")+"$")}check(t,n){let r=this._r.exec(t)!=null;return!r&&n?.extend(null,this._r.toString(),t.toString(),"String doesn't match string template."),r}};var Pl=E(ur),qo=Symbol("optional"),on=class extends v{constructor(t){super(),this.shape=t}check(t,n){let r=t===void 0||this.shape.check(t);return!r&&n?.extend(null,"undefined (optional)","()"),r}get[qo](){return!0}},Go=E(on),cn=class extends v{check(t,n){return n?.extend(null,"never",typeof t),!1}},Kl=new cn,Yl=E(cn),gn=class gn extends v{constructor(t,n=!1){super(),this.shape=t,this._isPartial=n}get partial(){return new gn(this.shape,!0)}check(t,n){return t==null?(n?.extend(null,"object","null"),!1):qt(this.shape,(r,s)=>{let i=this._isPartial&&!ke(t,s)||r.check(t[s],n);return!i&&n?.extend(s.toString(),r.toString(),typeof t[s],"Object property does not match"),i})}};Ge(gn,"_dilutes",!0);var ln=gn,zo=e=>new ln(e),Ho=E(ln),Jo=I(e=>e!=null&&(e.constructor===Object||e.constructor==null)),an=class extends v{constructor(t,n){super(),this.shape={keys:t,values:n}}check(t,n){return t!=null&&qt(t,(r,s)=>{let i=this.shape.keys.check(s,n);return!i&&n?.extend(s+"","Record",typeof t,i?"Key doesn't match schema":"Value doesn't match value"),i&&this.shape.values.check(r,n)})}},Cs=(e,t)=>new an(e,t),Xo=E(an),hn=class extends v{constructor(t){super(),this.shape=t}check(t,n){return t!=null&&qt(this.shape,(r,s)=>{let i=r.check(t[s],n);return!i&&n?.extend(s.toString(),"Tuple",typeof r),i})}},Po=(...e)=>new hn(e),Wl=E(hn),un=class extends v{constructor(t){super(),this.shape=t.length===1?t[0]:new Ht(t)}check(t,n){let r=st(t)&&Je(t,s=>this.shape.check(s));return!r&&n?.extend(null,"Array",""),r}},As=(...e)=>new un(e),Ko=E(un),Yo=I(e=>st(e)),dn=class extends v{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n){let r=t instanceof this.shape&&(this._c==null||this._c(t));return!r&&n?.extend(null,this.shape.name,t?.constructor.name),r}},Wo=(e,t=null)=>new dn(e,t),Zl=E(dn),Zo=Wo(v),dr=class extends v{constructor(t){super(),this.len=t.length-1,this.args=Po(...t.slice(-1)),this.res=t[this.len]}check(t,n){let r=t.constructor===Function&&t.length<=this.len;return!r&&n?.extend(null,"function",typeof t),r}};var Qo=E(dr),tc=I(e=>typeof e=="function"),fr=class extends v{constructor(t){super(),this.shape=t}check(t,n){let r=Je(this.shape,s=>s.check(t,n));return!r&&n?.extend(null,"Intersectinon",typeof t),r}};var Ql=E(fr,e=>e.shape.length>0),Ht=class extends v{constructor(t){super(),this.shape=t}check(t,n){let r=de(this.shape,s=>s.check(t,n));return n?.extend(null,"Union",typeof t),r}};Ge(Ht,"_dilutes",!0);var Kt=(...e)=>e.findIndex(t=>fn.check(t))>=0?Kt(...e.map(t=>Ae(t)).map(t=>fn.check(t)?t.shape:[t]).flat(1)):e.length===1?e[0]:new Ht(e),fn=E(Ht),Is=()=>!0,pn=I(Is),ec=E(Ce,e=>e.shape===Is),gr=I(e=>typeof e=="bigint"),nc=I(e=>e===gr),Ds=I(e=>typeof e=="symbol"),ta=I(e=>e===Ds),Jt=I(e=>typeof e=="number"),Ts=I(e=>e===Jt),Pt=I(e=>typeof e=="string"),vs=I(e=>e===Pt),wn=I(e=>typeof e=="boolean"),rc=I(e=>e===wn),Vs=mn(void 0),ea=E(Xt,e=>e.shape.length===1&&e.shape[0]===void 0),na=mn(void 0);var yn=mn(null),sc=E(Xt,e=>e.shape.length===1&&e.shape[0]===null),ra=E(Uint8Array),sa=E(Ue,e=>e.shape===Uint8Array),ic=Kt(Jt,Pt,yn,Vs,gr,wn,Ds),ia=(()=>{let e=As(pn),t=Cs(Pt,pn),n=Kt(Jt,Pt,yn,wn,e,t);return e.shape=n,t.shape.values=n,n})(),Ae=e=>{if(Zo.check(e))return e;if(Jo.check(e)){let t={};for(let n in e)t[n]=Ae(e[n]);return zo(t)}else{if(Yo.check(e))return Kt(...e.map(Ae));if(ic.check(e))return mn(e);if(tc.check(e))return E(e)}T()},_s=ys?()=>{}:(e,t)=>{let n=new ar;if(!t.check(e,n))throw G(`Expected value to be of type ${t.constructor.name}.
5
+ ${n.toString()}`)},pr=class{constructor(t){this.patterns=[],this.$state=t}if(t,n){return this.patterns.push({if:Ae(t),h:n}),this}else(t){return this.if(pn,t)}done(){return(t,n)=>{for(let r=0;r<this.patterns.length;r++){let s=this.patterns[r];if(s.if.check(t))return s.h(t,n)}throw G("Unhandled pattern")}}},oc=e=>new pr(e),Os=oc(pn).if(Ts,(e,t)=>rn(t,Fn,Tt)).if(vs,(e,t)=>Ss(t)).if(rc,(e,t)=>or(t)).if(nc,(e,t)=>BigInt(rn(t,Fn,Tt))).if(fn,(e,t)=>zt(t,sn(t,e.shape))).if(Ho,(e,t)=>{let n={};for(let r in e.shape){let s=e.shape[r];if(Go.check(s)){if(or(t))continue;s=s.shape}n[r]=Os(s,t)}return n}).if(Ko,(e,t)=>{let n=[],r=cr(t,0,42);for(let s=0;s<r;s++)n.push(zt(t,e.shape));return n}).if(Es,(e,t)=>sn(t,e.shape)).if(sc,(e,t)=>null).if(Qo,(e,t)=>{let n=zt(t,e.res);return()=>n}).if(ec,(e,t)=>zt(t,sn(t,[Jt,Pt,yn,Vs,gr,wn,As(Jt),Cs(Kt("a","b","c"),Jt)]))).if(Xo,(e,t)=>{let n={},r=rn(t,0,3);for(let s=0;s<r;s++){let i=zt(t,e.shape.keys),o=zt(t,e.shape.values);n[i]=o}return n}).done(),zt=(e,t)=>Os(Ae(t),e);var Ut=typeof document<"u"?document:{};var ca=I(e=>e.nodeType===uc);var la=typeof DOMParser<"u"?new DOMParser:null;var aa=I(e=>e.nodeType===lc);var ha=I(e=>e.nodeType===ac);var Ns=e=>Kr(e,(t,n)=>`${n}:${t};`).join("");var lc=Ut.ELEMENT_NODE,ac=Ut.TEXT_NODE,ua=Ut.CDATA_SECTION_NODE,da=Ut.COMMENT_NODE,hc=Ut.DOCUMENT_NODE,fa=Ut.DOCUMENT_TYPE_NODE,uc=Ut.DOCUMENT_FRAGMENT_NODE,pa=I(e=>e.nodeType===hc);var Q=Symbol;var Ie=Q(),De=Q(),mr=Q(),wr=Q(),yr=Q(),Te=Q(),xr=Q(),Yt=Q(),br=Q(),Ls=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=0;for(;r<e.length;r++){let s=e[r];if(s===void 0)break;if(s.constructor===String||s.constructor===Number)t.push(s);else if(s.constructor===Object)break}for(r>0&&n.push(t.join(""));r<e.length;r++){let s=e[r];s instanceof Symbol||n.push(s)}return n};var ga=Qe();var gc={[Ie]:Z("font-weight","bold"),[De]:Z("font-weight","normal"),[mr]:Z("color","blue"),[yr]:Z("color","green"),[wr]:Z("color","grey"),[Te]:Z("color","red"),[xr]:Z("color","purple"),[Yt]:Z("color","orange"),[br]:Z("color","black")},mc=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=A(),s=[],i=0;for(;i<e.length;i++){let o=e[i],c=gc[o];if(c!==void 0)r.set(c.left,c.right);else{if(o===void 0)break;if(o.constructor===String||o.constructor===Number){let l=Ns(r);i>0||l.length>0?(t.push("%c"+o),n.push(l)):t.push(o)}else break}}for(i>0&&(s=n,s.unshift(t.join("")));i<e.length;i++){let o=e[i];o instanceof Symbol||s.push(o)}return s},Bs=xs?mc:Ls,xn=(...e)=>{console.log(...Bs(e)),Ms.forEach(t=>t.print(e))},kr=(...e)=>{console.warn(...Bs(e)),e.unshift(Yt),Ms.forEach(t=>t.print(e))};var Ms=rt();var Rs=e=>({[Symbol.iterator](){return this},next:e}),$s=(e,t)=>Rs(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),bn=(e,t)=>Rs(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}});var qs=class extends Dt{constructor(t,n){super(),this.doc=t,this.awareness=n}},Ve=class{constructor(t,n){this.clock=t,this.len=n}},gt=class{constructor(){this.clients=new Map}},Qt=(e,t,n)=>t.clients.forEach((r,s)=>{let i=e.doc.store.clients.get(s);if(i!=null){let o=i[i.length-1],c=o.id.clock+o.length;for(let l=0,h=r[l];l<r.length&&h.clock<c;h=r[++l])mi(e,i,h.clock,h.len,n)}}),kc=(e,t)=>{let n=0,r=e.length-1;for(;n<=r;){let s=B((n+r)/2),i=e[s],o=i.clock;if(o<=t){if(t<o+i.len)return s;n=s+1}else r=s-1}return null},ae=(e,t)=>{let n=e.clients.get(t.client);return n!==void 0&&kc(n,t.clock)!==null},Mr=e=>{e.clients.forEach(t=>{t.sort((s,i)=>s.clock-i.clock);let n,r;for(n=1,r=1;n<t.length;n++){let s=t[r-1],i=t[n];s.clock+s.len>=i.clock?s.len=it(s.len,i.clock+i.len-s.clock):(r<n&&(t[r]=i),r++)}t.length=r})},te=e=>{let t=new gt;for(let n=0;n<e.length;n++)e[n].clients.forEach((r,s)=>{if(!t.clients.has(s)){let i=r.slice();for(let o=n+1;o<e.length;o++)Wr(i,e[o].clients.get(s)||[]);t.clients.set(s,i)}});return Mr(t),t},Oe=(e,t,n,r)=>{L(e.clients,t,()=>[]).push(new Ve(n,r))},Rr=()=>new gt,ci=e=>{let t=Rr();return e.clients.forEach((n,r)=>{let s=[];for(let i=0;i<n.length;i++){let o=n[i];if(o.deleted){let c=o.id.clock,l=o.length;if(i+1<n.length)for(let h=n[i+1];i+1<n.length&&h.deleted;h=n[++i+1])l+=h.length;s.push(new Ve(c,l))}}s.length>0&&t.clients.set(r,s)}),t},tt=(e,t)=>{g(e.restEncoder,t.clients.size),Y(t.clients.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{e.resetDsCurVal(),g(e.restEncoder,n);let s=r.length;g(e.restEncoder,s);for(let i=0;i<s;i++){let o=r[i];e.writeDsClock(o.clock),e.writeDsLen(o.len)}})},ot=e=>{let t=new gt,n=w(e.restDecoder);for(let r=0;r<n;r++){e.resetDsCurVal();let s=w(e.restDecoder),i=w(e.restDecoder);if(i>0){let o=L(t.clients,s,()=>[]);for(let c=0;c<i;c++)o.push(new Ve(e.readDsClock(),e.readDsLen()))}}return t},Gs=(e,t,n)=>{let r=new gt,s=w(e.restDecoder);for(let i=0;i<s;i++){e.resetDsCurVal();let o=w(e.restDecoder),c=w(e.restDecoder),l=n.clients.get(o)||[],h=_(n,o);for(let a=0;a<c;a++){let u=e.readDsClock(),d=u+e.readDsLen();if(u<h){h<d&&Oe(r,o,h,d-h);let f=P(l,u),p=l[f];for(!p.deleted&&p.id.clock<u&&(l.splice(f+1,0,Ln(t,p,u-p.id.clock)),f++);f<l.length&&(p=l[f++],p.id.clock<d);)p.deleted||(d<p.id.clock+p.length&&l.splice(f,0,Ln(t,p,d-p.id.clock)),p.delete(t))}else Oe(r,o,u,d-u)}}if(r.clients.size>0){let i=new X;return g(i.restEncoder,0),tt(i,r),i.toUint8Array()}return null},Sc=(e,t)=>{if(e.clients.size!==t.clients.size)return!1;for(let[n,r]of e.clients.entries()){let s=t.clients.get(n);if(s===void 0||r.length!==s.length)return!1;for(let i=0;i<r.length;i++){let o=r[i],c=s[i];if(o.clock!==c.clock||o.len!==c.len)return!1}}return!0},li=Pn,Ct=class e extends Dt{constructor({guid:t=ls(),collectionid:n=null,gc:r=!0,gcFilter:s=()=>!0,meta:i=null,autoLoad:o=!1,shouldLoad:c=!0}={}){super(),this.gc=r,this.gcFilter=s,this.clientID=li(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new Dn,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=c,this.autoLoad=o,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Kn(h=>{this.on("load",()=>{this.isLoaded=!0,h(this)})});let l=()=>Kn(h=>{let a=u=>{(u===void 0||u===!0)&&(this.off("sync",a),h())};this.on("sync",a)});this.on("sync",h=>{h===!1&&this.isSynced&&(this.whenSynced=l()),this.isSynced=h===void 0||h===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=l()}load(){let t=this._item;t!==null&&!this.shouldLoad&&x(t.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Y(this.subdocs).map(t=>t.guid))}transact(t,n=null){return x(this,t,n)}get(t,n=U){let r=L(this.share,t,()=>{let i=new n;return i._integrate(this,null),i}),s=r.constructor;if(n!==U&&s!==n)if(s===U){let i=new n;i._map=r._map,r._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=i}),i._start=r._start;for(let o=i._start;o!==null;o=o.right)o.parent=i;return i._length=r._length,this.share.set(t,i),i._integrate(this,null),i}else throw new Error(`Type with the name ${t} has already been defined with a different constructor`);return r}getArray(t=""){return this.get(t,re)}getText(t=""){return this.get(t,$e)}getMap(t=""){return this.get(t,se)}getXmlElement(t=""){return this.get(t,oe)}getXmlFragment(t=""){return this.get(t,ie)}toJSON(){let t={};return this.share.forEach((n,r)=>{t[r]=n.toJSON()}),t}destroy(){this.isDestroyed=!0,Y(this.subdocs).forEach(n=>n.destroy());let t=this._item;if(t!==null){this._item=null;let n=t.content;n.doc=new e({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,x(t.parent.doc,r=>{let s=n.doc;t.deleted||r.subdocsAdded.add(s),r.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}},At=class{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return w(this.restDecoder)}readDsLen(){return w(this.restDecoder)}},H=class extends At{readLeftID(){return m(w(this.restDecoder),w(this.restDecoder))}readRightID(){return m(w(this.restDecoder),w(this.restDecoder))}readClient(){return w(this.restDecoder)}readInfo(){return St(this.restDecoder)}readString(){return ht(this.restDecoder)}readParentInfo(){return w(this.restDecoder)===1}readTypeRef(){return w(this.restDecoder)}readLen(){return w(this.restDecoder)}readAny(){return Ft(this.restDecoder)}readBuf(){return ks(F(this.restDecoder))}readJSON(){return JSON.parse(ht(this.restDecoder))}readKey(){return ht(this.restDecoder)}},Cn=class{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=w(this.restDecoder),this.dsCurrVal}readDsLen(){let t=w(this.restDecoder)+1;return this.dsCurrVal+=t,t}},j=class extends Cn{constructor(t){super(t),this.keys=[],w(t),this.keyClockDecoder=new jt(F(t)),this.clientDecoder=new _t(F(t)),this.leftClockDecoder=new jt(F(t)),this.rightClockDecoder=new jt(F(t)),this.infoDecoder=new ye(F(t),St),this.stringDecoder=new We(F(t)),this.parentInfoDecoder=new ye(F(t),St),this.typeRefDecoder=new _t(F(t)),this.lenDecoder=new _t(F(t))}readLeftID(){return new pt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new pt(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return Ft(this.restDecoder)}readBuf(){return F(this.restDecoder)}readJSON(){return Ft(this.restDecoder)}readKey(){let t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{let n=this.stringDecoder.read();return this.keys.push(n),n}}},mt=class{constructor(){this.restEncoder=kt()}toUint8Array(){return q(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){g(this.restEncoder,t)}writeDsLen(t){g(this.restEncoder,t)}},ct=class extends mt{writeLeftID(t){g(this.restEncoder,t.client),g(this.restEncoder,t.clock)}writeRightID(t){g(this.restEncoder,t.client),g(this.restEncoder,t.clock)}writeClient(t){g(this.restEncoder,t)}writeInfo(t){Mt(this.restEncoder,t)}writeString(t){lt(this.restEncoder,t)}writeParentInfo(t){g(this.restEncoder,t?1:0)}writeTypeRef(t){g(this.restEncoder,t)}writeLen(t){g(this.restEncoder,t)}writeAny(t){Lt(this.restEncoder,t)}writeBuf(t){$(this.restEncoder,t)}writeJSON(t){lt(this.restEncoder,JSON.stringify(t))}writeKey(t){lt(this.restEncoder,t)}},ee=class{constructor(){this.restEncoder=kt(),this.dsCurrVal=0}toUint8Array(){return q(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){let n=t-this.dsCurrVal;this.dsCurrVal=t,g(this.restEncoder,n)}writeDsLen(t){t===0&&T(),g(this.restEncoder,t-1),this.dsCurrVal+=t}},X=class extends ee{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Bt,this.clientEncoder=new bt,this.leftClockEncoder=new Bt,this.rightClockEncoder=new Bt,this.infoEncoder=new me(Mt),this.stringEncoder=new Ye,this.parentInfoEncoder=new me(Mt),this.typeRefEncoder=new bt,this.lenEncoder=new bt}toUint8Array(){let t=kt();return g(t,0),$(t,this.keyClockEncoder.toUint8Array()),$(t,this.clientEncoder.toUint8Array()),$(t,this.leftClockEncoder.toUint8Array()),$(t,this.rightClockEncoder.toUint8Array()),$(t,q(this.infoEncoder)),$(t,this.stringEncoder.toUint8Array()),$(t,q(this.parentInfoEncoder)),$(t,this.typeRefEncoder.toUint8Array()),$(t,this.lenEncoder.toUint8Array()),Rt(t,q(this.restEncoder)),q(t)}writeLeftID(t){this.clientEncoder.write(t.client),this.leftClockEncoder.write(t.clock)}writeRightID(t){this.clientEncoder.write(t.client),this.rightClockEncoder.write(t.clock)}writeClient(t){this.clientEncoder.write(t)}writeInfo(t){this.infoEncoder.write(t)}writeString(t){this.stringEncoder.write(t)}writeParentInfo(t){this.parentInfoEncoder.write(t?1:0)}writeTypeRef(t){this.typeRefEncoder.write(t)}writeLen(t){this.lenEncoder.write(t)}writeAny(t){Lt(this.restEncoder,t)}writeBuf(t){$(this.restEncoder,t)}writeJSON(t){Lt(this.restEncoder,t)}writeKey(t){let n=this.keyMap.get(t);n===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(n)}},_c=(e,t,n,r)=>{r=it(r,t[0].id.clock);let s=P(t,r);g(e.restEncoder,t.length-s),e.writeClient(n),g(e.restEncoder,r);let i=t[s];i.write(e,r-i.id.clock);for(let o=s+1;o<t.length;o++)t[o].write(e,0)},$r=(e,t,n)=>{let r=new Map;n.forEach((s,i)=>{_(t,i)>s&&r.set(i,s)}),qe(t).forEach((s,i)=>{n.has(i)||r.set(i,0)}),g(e.restEncoder,r.size),Y(r.entries()).sort((s,i)=>i[0]-s[0]).forEach(([s,i])=>{_c(e,t.clients.get(s),s,i)})},Ec=(e,t)=>{let n=A(),r=w(e.restDecoder);for(let s=0;s<r;s++){let i=w(e.restDecoder),o=new Array(i),c=e.readClient(),l=w(e.restDecoder);n.set(c,{i:0,refs:o});for(let h=0;h<i;h++){let a=e.readInfo();switch(31&a){case 0:{let u=e.readLen();o[h]=new R(m(c,l),u),l+=u;break}case 10:{let u=w(e.restDecoder);o[h]=new N(m(c,l),u),l+=u;break}default:{let u=(a&192)===0,d=new b(m(c,l),null,(a&128)===128?e.readLeftID():null,null,(a&64)===64?e.readRightID():null,u?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,u&&(a&32)===32?e.readString():null,Fi(e,a));o[h]=d,l+=d.length}}}}return n},Uc=(e,t,n)=>{let r=[],s=Y(n.keys()).sort((f,p)=>f-p);if(s.length===0)return null;let i=()=>{if(s.length===0)return null;let f=n.get(s[s.length-1]);for(;f.refs.length===f.i;)if(s.pop(),s.length>0)f=n.get(s[s.length-1]);else return null;return f},o=i();if(o===null)return null;let c=new Dn,l=new Map,h=(f,p)=>{let y=l.get(f);(y==null||y>p)&&l.set(f,p)},a=o.refs[o.i++],u=new Map,d=()=>{for(let f of r){let p=f.id.client,y=n.get(p);y?(y.i--,c.clients.set(p,y.refs.slice(y.i)),n.delete(p),y.i=0,y.refs=[]):c.clients.set(p,[f]),s=s.filter(k=>k!==p)}r.length=0};for(;;){if(a.constructor!==N){let p=L(u,a.id.client,()=>_(t,a.id.client))-a.id.clock;if(p<0)r.push(a),h(a.id.client,a.id.clock-1),d();else{let y=a.getMissing(e,t);if(y!==null){r.push(a);let k=n.get(y)||{refs:[],i:0};if(k.refs.length===k.i)h(y,_(t,y)),d();else{a=k.refs[k.i++];continue}}else(p===0||p<a.length)&&(a.integrate(e,p),u.set(a.id.client,a.id.clock+a.length))}}if(r.length>0)a=r.pop();else if(o!==null&&o.i<o.refs.length)a=o.refs[o.i++];else{if(o=i(),o===null)break;a=o.refs[o.i++]}}if(c.clients.size>0){let f=new X;return $r(f,c,new Map),g(f.restEncoder,0),{missing:l,update:f.toUint8Array()}}return null},Cc=(e,t)=>$r(e,t.doc.store,t.beforeState),ai=(e,t,n,r=new j(e))=>x(t,s=>{s.local=!1;let i=!1,o=s.doc,c=o.store,l=Ec(r,o),h=Uc(s,c,l),a=c.pendingStructs;if(a){for(let[d,f]of a.missing)if(f<_(c,d)){i=!0;break}if(h){for(let[d,f]of h.missing){let p=a.missing.get(d);(p==null||p>f)&&a.missing.set(d,f)}a.update=Tn([a.update,h.update])}}else c.pendingStructs=h;let u=Gs(r,s,c);if(c.pendingDs){let d=new j(V(c.pendingDs));w(d.restDecoder);let f=Gs(d,s,c);u&&f?c.pendingDs=Tn([u,f]):c.pendingDs=u||f}else c.pendingDs=u;if(i){let d=c.pendingStructs.update;c.pendingStructs=null,Fr(s.doc,d)}},n,!1),Ea=(e,t,n)=>ai(e,t,n,new H(e)),Fr=(e,t,n,r=j)=>{let s=V(t);ai(s,e,n,new r(s))},Ua=(e,t,n)=>Fr(e,t,n,H),Ac=(e,t,n=new Map)=>{$r(e,t.store,n),tt(e,ci(t.store))},Ic=(e,t=new Uint8Array([0]),n=new X)=>{let r=ui(t);Ac(n,e,r);let s=[n.toUint8Array()];if(e.store.pendingDs&&s.push(e.store.pendingDs),e.store.pendingStructs&&s.push(bi(e.store.pendingStructs.update,t)),s.length>1){if(n.constructor===ct)return Gc(s.map((i,o)=>o===0?i:Xc(i)));if(n.constructor===X)return Tn(s)}return s[0]},Ca=(e,t)=>Ic(e,t,new ct),hi=e=>{let t=new Map,n=w(e.restDecoder);for(let r=0;r<n;r++){let s=w(e.restDecoder),i=w(e.restDecoder);t.set(s,i)}return t},ui=e=>hi(new At(V(e))),jr=(e,t)=>(g(e.restEncoder,t.size),Y(t.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{g(e.restEncoder,n),g(e.restEncoder,r)}),e),Dc=(e,t)=>jr(e,qe(t.store)),Tc=(e,t=new ee)=>(e instanceof Map?jr(t,e):Dc(t,e),t.toUint8Array()),Aa=e=>Tc(e,new mt),_r=class{constructor(){this.l=[]}},zs=()=>new _r,Hs=(e,t)=>e.l.push(t),Js=(e,t)=>{let n=e.l,r=n.length;e.l=n.filter(s=>t!==s),r===e.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},di=(e,t,n)=>_e(e.l,[t,n]),pt=class{constructor(t,n){this.client=t,this.clock=n}},Wt=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,m=(e,t)=>new pt(e,t),Xs=(e,t)=>{g(e,t.client),g(e,t.clock)},Ps=e=>m(w(e),w(e)),fi=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw T()},An=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1},Ia=e=>{let t=[],n=e._start;for(;n;)t.push(n),n=n.right;console.log("Children: ",t),console.log("Children content: ",t.filter(r=>!r.deleted).map(r=>r.content))},Ks=class{constructor(t,n=t.getMap("users")){let r=new Map;this.yusers=n,this.doc=t,this.clients=new Map,this.dss=r;let s=(i,o)=>{let c=i.get("ds"),l=i.get("ids"),h=a=>this.clients.set(a,o);c.observe(a=>{a.changes.added.forEach(u=>{u.content.getContent().forEach(d=>{d instanceof Uint8Array&&this.dss.set(o,te([this.dss.get(o)||Rr(),ot(new At(V(d)))]))})})}),this.dss.set(o,te(c.map(a=>ot(new At(V(a)))))),l.observe(a=>a.changes.added.forEach(u=>u.content.getContent().forEach(h))),l.forEach(h)};n.observe(i=>{i.keysChanged.forEach(o=>s(n.get(o),o))}),n.forEach(s)}setUserMapping(t,n,r,{filter:s=()=>!0}={}){let i=this.yusers,o=i.get(r);o||(o=new se,o.set("ids",new re),o.set("ds",new re),i.set(r,o)),o.get("ids").push([n]),i.observe(c=>{setTimeout(()=>{let l=i.get(r);if(l!==o){o=l,this.clients.forEach((u,d)=>{r===u&&o.get("ids").push([d])});let h=new mt,a=this.dss.get(r);a&&(tt(h,a),o.get("ds").push([h.toUint8Array()]))}},0)}),t.on("afterTransaction",c=>{setTimeout(()=>{let l=o.get("ds"),h=c.deleteSet;if(c.local&&h.clients.size>0&&s(c,h)){let a=new mt;tt(a,h),l.push([a.toUint8Array()])}})})}getUserByClientId(t){return this.clients.get(t)||null}getUserByDeletedId(t){for(let[n,r]of this.dss.entries())if(ae(r,t))return n;return null}},Ne=class{constructor(t,n,r,s=0){this.type=t,this.tname=n,this.item=r,this.assoc=s}},Da=e=>{let t={};return e.type&&(t.type=e.type),e.tname&&(t.tname=e.tname),e.item&&(t.item=e.item),e.assoc!=null&&(t.assoc=e.assoc),t},Ta=e=>new Ne(e.type==null?null:m(e.type.client,e.type.clock),e.tname??null,e.item==null?null:m(e.item.client,e.item.clock),e.assoc==null?0:e.assoc),Er=class{constructor(t,n,r=0){this.type=t,this.index=n,this.assoc=r}},vc=(e,t,n=0)=>new Er(e,t,n),kn=(e,t,n)=>{let r=null,s=null;return e._item===null?s=fi(e):r=m(e._item.id.client,e._item.id.clock),new Ne(r,s,t,n)},va=(e,t,n=0)=>{let r=e._start;if(n<0){if(t===0)return kn(e,null,n);t--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>t)return kn(e,m(r.id.client,r.id.clock+t),n);t-=r.length}if(r.right===null&&n<0)return kn(e,r.lastId,n);r=r.right}return kn(e,null,n)},Vc=(e,t)=>{let{type:n,tname:r,item:s,assoc:i}=t;if(s!==null)g(e,0),Xs(e,s);else if(r!==null)Mt(e,1),lt(e,r);else if(n!==null)Mt(e,2),Xs(e,n);else throw T();return we(e,i),e},Va=e=>{let t=kt();return Vc(t,e),q(t)},Oc=e=>{let t=null,n=null,r=null;switch(w(e)){case 0:r=Ps(e);break;case 1:n=ht(e);break;case 2:t=Ps(e)}let s=Jn(e)?xe(e):0;return new Ne(t,n,r,s)},Oa=e=>Oc(V(e)),Nc=(e,t)=>{let n=Zt(e,t),r=t.clock-n.id.clock;return{item:n,diff:r}},Na=(e,t,n=!0)=>{let r=t.store,s=e.item,i=e.type,o=e.tname,c=e.assoc,l=null,h=0;if(s!==null){if(_(r,s.client)<=s.clock)return null;let a=n?Lr(r,s):Nc(r,s),u=a.item;if(!(u instanceof b))return null;if(l=u.parent,l._item===null||!l._item.deleted){h=u.deleted||!u.countable?0:a.diff+(c>=0?0:1);let d=u.left;for(;d!==null;)!d.deleted&&d.countable&&(h+=d.length),d=d.left}}else{if(o!==null)l=t.get(o);else if(i!==null){if(_(r,i.client)<=i.clock)return null;let{item:a}=n?Lr(r,i):{item:Zt(r,i)};if(a instanceof b&&a.content instanceof K)l=a.content.type;else return null}else throw T();c>=0?h=l._length:h=0}return vc(l,h,e.assoc)},La=(e,t)=>e===t||e!==null&&t!==null&&e.tname===t.tname&&Wt(e.item,t.item)&&Wt(e.type,t.type)&&e.assoc===t.assoc,In=class{constructor(t,n){this.ds=t,this.sv=n}},Ba=(e,t)=>{let n=e.ds.clients,r=t.ds.clients,s=e.sv,i=t.sv;if(s.size!==i.size||n.size!==r.size)return!1;for(let[o,c]of s.entries())if(i.get(o)!==c)return!1;for(let[o,c]of n.entries()){let l=r.get(o)||[];if(c.length!==l.length)return!1;for(let h=0;h<c.length;h++){let a=c[h],u=l[h];if(a.clock!==u.clock||a.len!==u.len)return!1}}return!0},Lc=(e,t=new ee)=>(tt(t,e.ds),jr(t,e.sv),t.toUint8Array()),Ma=e=>Lc(e,new mt),Bc=(e,t=new Cn(V(e)))=>new In(ot(t),hi(t)),Ra=e=>Bc(e,new At(V(e))),pi=(e,t)=>new In(e,t),$a=pi(Rr(),new Map),Fa=e=>pi(ci(e.store),qe(e.store)),ut=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!ae(t.ds,e.id),Ur=(e,t)=>{let n=L(e.meta,Ur,rt),r=e.doc.store;n.has(t)||(t.sv.forEach((s,i)=>{s<_(r,i)&&M(e,m(i,s))}),Qt(e,t.ds,s=>{}),n.add(t))},ja=(e,t,n=new Ct)=>{if(e.gc)throw new Error("Garbage-collection must be disabled in `originDoc`!");let{sv:r,ds:s}=t,i=new X;return e.transact(o=>{let c=0;r.forEach(l=>{l>0&&c++}),g(i.restEncoder,c);for(let[l,h]of r){if(h===0)continue;h<_(e.store,l)&&M(o,m(l,h));let a=e.store.clients.get(l)||[],u=P(a,h-1);g(i.restEncoder,u+1),i.writeClient(l),g(i.restEncoder,0);for(let d=0;d<=u;d++)a[d].write(i,0)}tt(i,s)}),Fr(n,i.toUint8Array(),"snapshot"),n},Mc=(e,t,n=j)=>{let r=new n(V(t)),s=new et(r,!1);for(let o=s.curr;o!==null;o=s.next())if((e.sv.get(o.id.client)||0)<o.id.clock+o.length)return!1;let i=te([e.ds,ot(r)]);return Sc(e.ds,i)},qa=(e,t)=>Mc(e,t,H),Dn=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},qe=e=>{let t=new Map;return e.clients.forEach((n,r)=>{let s=n[n.length-1];t.set(r,s.id.clock+s.length)}),t},_=(e,t)=>{let n=e.clients.get(t);if(n===void 0)return 0;let r=n[n.length-1];return r.id.clock+r.length},gi=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{let r=n[n.length-1];if(r.id.clock+r.length!==t.id.clock)throw T()}n.push(t)},P=(e,t)=>{let n=0,r=e.length-1,s=e[r],i=s.id.clock;if(i===t)return r;let o=B(t/(i+s.length-1)*r);for(;n<=r;){if(s=e[o],i=s.id.clock,i<=t){if(t<i+s.length)return o;n=o+1}else r=o-1;o=B((n+r)/2)}throw T()},Rc=(e,t)=>{let n=e.clients.get(t.client);return n[P(n,t.clock)]},Zt=Rc,Cr=(e,t,n)=>{let r=P(t,n),s=t[r];return s.id.clock<n&&s instanceof b?(t.splice(r+1,0,Ln(e,s,n-s.id.clock)),r+1):r},M=(e,t)=>{let n=e.doc.store.clients.get(t.client);return n[Cr(e,n,t.clock)]},Ys=(e,t,n)=>{let r=t.clients.get(n.client),s=P(r,n.clock),i=r[s];return n.clock!==i.id.clock+i.length-1&&i.constructor!==R&&r.splice(s+1,0,Ln(e,i,n.clock-i.id.clock+1)),i},$c=(e,t,n)=>{let r=e.clients.get(t.id.client);r[P(r,t.id.clock)]=n},mi=(e,t,n,r,s)=>{if(r===0)return;let i=n+r,o=Cr(e,t,n),c;do c=t[o++],i<c.id.clock+c.length&&Cr(e,t,i),s(c);while(o<t.length&&t[o].id.clock<i)},Ar=class{constructor(t,n,r){this.doc=t,this.deleteSet=new gt,this.beforeState=qe(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=n,this.meta=new Map,this.local=r,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}},Ws=(e,t)=>t.deleteSet.clients.size===0&&!Yr(t.afterState,(n,r)=>t.beforeState.get(r)!==n)?!1:(Mr(t.deleteSet),Cc(e,t),tt(e,t.deleteSet),!0),Zs=(e,t,n)=>{let r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&L(e.changed,t,rt).add(n)},En=(e,t)=>{let n=e[t],r=e[t-1],s=t;for(;s>0;n=r,r=e[--s-1]){if(r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n)){n instanceof b&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);continue}break}let i=t-s;return i&&e.splice(t+1-i,i),i},wi=(e,t,n)=>{for(let[r,s]of e.clients.entries()){let i=t.clients.get(r);for(let o=s.length-1;o>=0;o--){let c=s[o],l=c.clock+c.len;for(let h=P(i,c.clock),a=i[h];h<i.length&&a.id.clock<l;a=i[++h]){let u=i[h];if(c.clock+c.len<=u.id.clock)break;u instanceof b&&u.deleted&&!u.keep&&n(u)&&u.gc(t,!1)}}}},yi=(e,t)=>{e.clients.forEach((n,r)=>{let s=t.clients.get(r);for(let i=n.length-1;i>=0;i--){let o=n[i],c=Xe(s.length-1,1+P(s,o.clock+o.len-1));for(let l=c,h=s[l];l>0&&h.id.clock>=o.clock;h=s[l])l-=1+En(s,l)}})},Ga=(e,t,n)=>{wi(e,t,n),yi(e,t)},xi=(e,t)=>{if(t<e.length){let n=e[t],r=n.doc,s=r.store,i=n.deleteSet,o=n._mergeStructs;try{Mr(i),n.afterState=qe(n.doc.store),r.emit("beforeObserverCalls",[n,r]);let c=[];n.changed.forEach((l,h)=>c.push(()=>{(h._item===null||!h._item.deleted)&&h._callObserver(n,l)})),c.push(()=>{n.changedParentTypes.forEach((l,h)=>{h._dEH.l.length>0&&(h._item===null||!h._item.deleted)&&(l=l.filter(a=>a.target._item===null||!a.target._item.deleted),l.forEach(a=>{a.currentTarget=h,a._path=null}),l.sort((a,u)=>a.path.length-u.path.length),di(h._dEH,l,n))})}),c.push(()=>r.emit("afterTransaction",[n,r])),_e(c,[]),n._needFormattingCleanup&&sl(n)}finally{r.gc&&wi(i,s,r.gcFilter),yi(i,s),n.afterState.forEach((a,u)=>{let d=n.beforeState.get(u)||0;if(d!==a){let f=s.clients.get(u),p=it(P(f,d),1);for(let y=f.length-1;y>=p;)y-=1+En(f,y)}});for(let a=o.length-1;a>=0;a--){let{client:u,clock:d}=o[a].id,f=s.clients.get(u),p=P(f,d);p+1<f.length&&En(f,p+1)>1||p>0&&En(f,p)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(xn(Yt,Ie,"[yjs] ",De,Te,"Changed the client-id because another client seems to be using it."),r.clientID=li()),r.emit("afterTransactionCleanup",[n,r]),r._observers.has("update")){let a=new ct;Ws(a,n)&&r.emit("update",[a.toUint8Array(),n.origin,r,n])}if(r._observers.has("updateV2")){let a=new X;Ws(a,n)&&r.emit("updateV2",[a.toUint8Array(),n.origin,r,n])}let{subdocsAdded:c,subdocsLoaded:l,subdocsRemoved:h}=n;(c.size>0||h.size>0||l.size>0)&&(c.forEach(a=>{a.clientID=r.clientID,a.collectionid==null&&(a.collectionid=r.collectionid),r.subdocs.add(a)}),h.forEach(a=>r.subdocs.delete(a)),r.emit("subdocs",[{loaded:l,added:c,removed:h},r,n]),h.forEach(a=>a.destroy())),e.length<=t+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,e])):xi(e,t+1)}}},x=(e,t,n=null,r=!0)=>{let s=e._transactionCleanups,i=!1,o=null;e._transaction===null&&(i=!0,e._transaction=new Ar(e,n,r),s.push(e._transaction),s.length===1&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{o=t(e._transaction)}finally{if(i){let c=e._transaction===s[0];e._transaction=null,c&&xi(s,0)}}return o},Ir=class{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}},Qs=(e,t,n)=>{Qt(e,n.deletions,r=>{r instanceof b&&t.scope.some(s=>s===e.doc||An(s,r))&&Jr(r,!1)})},ti=(e,t,n)=>{let r=null,s=e.doc,i=e.scope;x(s,c=>{for(;t.length>0&&e.currStackItem===null;){let l=s.store,h=t.pop(),a=new Set,u=[],d=!1;Qt(c,h.insertions,f=>{if(f instanceof b){if(f.redone!==null){let{item:p,diff:y}=Lr(l,f.id);y>0&&(p=M(c,m(p.id.client,p.id.clock+y))),f=p}!f.deleted&&i.some(p=>p===c.doc||An(p,f))&&u.push(f)}}),Qt(c,h.deletions,f=>{f instanceof b&&i.some(p=>p===c.doc||An(p,f))&&!ae(h.insertions,f.id)&&a.add(f)}),a.forEach(f=>{d=$i(c,f,a,h.insertions,e.ignoreRemoteMapChanges,e)!==null||d});for(let f=u.length-1;f>=0;f--){let p=u[f];e.deleteFilter(p)&&(p.delete(c),d=!0)}e.currStackItem=d?h:null}c.changed.forEach((l,h)=>{l.has(null)&&h._searchMarker&&(h._searchMarker.length=0)}),r=c},e);let o=e.currStackItem;if(o!=null){let c=r.changedParentTypes;e.emit("stack-item-popped",[{stackItem:o,type:n,changedParentTypes:c,origin:e},e]),e.currStackItem=null}return o},ei=class extends Dt{constructor(t,{captureTimeout:n=500,captureTransaction:r=l=>!0,deleteFilter:s=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:c=st(t)?t[0].doc:t instanceof Ct?t:t.doc}={}){super(),this.scope=[],this.doc=c,this.addToScope(t),this.deleteFilter=s,i.add(this),this.trackedOrigins=i,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=o,this.captureTimeout=n,this.afterTransactionHandler=l=>{if(!this.captureTransaction(l)||!this.scope.some(k=>l.changedParentTypes.has(k)||k===this.doc)||!this.trackedOrigins.has(l.origin)&&(!l.origin||!this.trackedOrigins.has(l.origin.constructor)))return;let h=this.undoing,a=this.redoing,u=h?this.redoStack:this.undoStack;h?this.stopCapturing():a||this.clear(!1,!0);let d=new gt;l.afterState.forEach((k,S)=>{let Xr=l.beforeState.get(S)||0,Pr=k-Xr;Pr>0&&Oe(d,S,Xr,Pr)});let f=Qe(),p=!1;if(this.lastChange>0&&f-this.lastChange<this.captureTimeout&&u.length>0&&!h&&!a){let k=u[u.length-1];k.deletions=te([k.deletions,l.deleteSet]),k.insertions=te([k.insertions,d])}else u.push(new Ir(l.deleteSet,d)),p=!0;!h&&!a&&(this.lastChange=f),Qt(l,l.deleteSet,k=>{k instanceof b&&this.scope.some(S=>S===l.doc||An(S,k))&&Jr(k,!0)});let y=[{stackItem:u[u.length-1],origin:l.origin,type:h?"redo":"undo",changedParentTypes:l.changedParentTypes},this];p?this.emit("stack-item-added",y):this.emit("stack-item-updated",y)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(t){let n=new Set(this.scope);t=st(t)?t:[t],t.forEach(r=>{n.has(r)||(n.add(r),(r instanceof U?r.doc!==this.doc:r!==this.doc)&&kr("[yjs#509] Not same Y.Doc"),this.scope.push(r))})}addTrackedOrigin(t){this.trackedOrigins.add(t)}removeTrackedOrigin(t){this.trackedOrigins.delete(t)}clear(t=!0,n=!0){(t&&this.canUndo()||n&&this.canRedo())&&this.doc.transact(r=>{t&&(this.undoStack.forEach(s=>Qs(r,this,s)),this.undoStack=[]),n&&(this.redoStack.forEach(s=>Qs(r,this,s)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:t,redoStackCleared:n}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let t;try{t=ti(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=ti(this,this.redoStack,"redo")}finally{this.redoing=!1}return t}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}};function*Fc(e){let t=w(e.restDecoder);for(let n=0;n<t;n++){let r=w(e.restDecoder),s=e.readClient(),i=w(e.restDecoder);for(let o=0;o<r;o++){let c=e.readInfo();if(c===10){let l=w(e.restDecoder);yield new N(m(s,i),l),i+=l}else if((31&c)!==0){let l=(c&192)===0,h=new b(m(s,i),null,(c&128)===128?e.readLeftID():null,null,(c&64)===64?e.readRightID():null,l?e.readParentInfo()?e.readString():e.readLeftID():null,l&&(c&32)===32?e.readString():null,Fi(e,c));yield h,i+=h.length}else{let l=e.readLen();yield new R(m(s,i),l),i+=l}}}}var et=class{constructor(t,n){this.gen=Fc(t),this.curr=null,this.done=!1,this.filterSkips=n,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===N);return this.curr}},za=e=>jc(e,H),jc=(e,t=j)=>{let n=[],r=new t(V(e)),s=new et(r,!1);for(let o=s.curr;o!==null;o=s.next())n.push(o);xn("Structs: ",n);let i=ot(r);xn("DeleteSet: ",i)},Ha=e=>qc(e,H),qc=(e,t=j)=>{let n=[],r=new t(V(e)),s=new et(r,!1);for(let i=s.curr;i!==null;i=s.next())n.push(i);return{structs:n,ds:ot(r)}},Le=class{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}},Gc=e=>Tn(e,H,ct),zc=(e,t=ee,n=j)=>{let r=new t,s=new et(new n(V(e)),!1),i=s.curr;if(i!==null){let o=0,c=i.id.client,l=i.id.clock!==0,h=l?0:i.id.clock+i.length;for(;i!==null;i=s.next())c!==i.id.client&&(h!==0&&(o++,g(r.restEncoder,c),g(r.restEncoder,h)),c=i.id.client,h=0,l=i.id.clock!==0),i.constructor===N&&(l=!0),l||(h=i.id.clock+i.length);h!==0&&(o++,g(r.restEncoder,c),g(r.restEncoder,h));let a=kt();return g(a,o),is(a,r.restEncoder),r.restEncoder=a,r.toUint8Array()}else return g(r.restEncoder,0),r.toUint8Array()},Ja=e=>zc(e,mt,H),Hc=(e,t=j)=>{let n=new Map,r=new Map,s=new et(new t(V(e)),!1),i=s.curr;if(i!==null){let o=i.id.client,c=i.id.clock;for(n.set(o,c);i!==null;i=s.next())o!==i.id.client&&(r.set(o,c),n.set(i.id.client,i.id.clock),o=i.id.client),c=i.id.clock+i.length;r.set(o,c)}return{from:n,to:r}},Xa=e=>Hc(e,H),Jc=(e,t)=>{if(e.constructor===R){let{client:n,clock:r}=e.id;return new R(m(n,r+t),e.length-t)}else if(e.constructor===N){let{client:n,clock:r}=e.id;return new N(m(n,r+t),e.length-t)}else{let n=e,{client:r,clock:s}=n.id;return new b(m(r,s+t),null,m(r,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},Tn=(e,t=j,n=X)=>{if(e.length===1)return e[0];let r=e.map(a=>new t(V(a))),s=r.map(a=>new et(a,!0)),i=null,o=new n,c=new Le(o);for(;s=s.filter(d=>d.curr!==null),s.sort((d,f)=>{if(d.curr.id.client===f.curr.id.client){let p=d.curr.id.clock-f.curr.id.clock;return p===0?d.curr.constructor===f.curr.constructor?0:d.curr.constructor===N?1:-1:p}else return f.curr.id.client-d.curr.id.client}),s.length!==0;){let a=s[0],u=a.curr.id.client;if(i!==null){let d=a.curr,f=!1;for(;d!==null&&d.id.clock+d.length<=i.struct.id.clock+i.struct.length&&d.id.client>=i.struct.id.client;)d=a.next(),f=!0;if(d===null||d.id.client!==u||f&&d.id.clock>i.struct.id.clock+i.struct.length)continue;if(u!==i.struct.id.client)dt(c,i.struct,i.offset),i={struct:d,offset:0},a.next();else if(i.struct.id.clock+i.struct.length<d.id.clock)if(i.struct.constructor===N)i.struct.length=d.id.clock+d.length-i.struct.id.clock;else{dt(c,i.struct,i.offset);let p=d.id.clock-i.struct.id.clock-i.struct.length;i={struct:new N(m(u,i.struct.id.clock+i.struct.length),p),offset:0}}else{let p=i.struct.id.clock+i.struct.length-d.id.clock;p>0&&(i.struct.constructor===N?i.struct.length-=p:d=Jc(d,p)),i.struct.mergeWith(d)||(dt(c,i.struct,i.offset),i={struct:d,offset:0},a.next())}}else i={struct:a.curr,offset:0},a.next();for(let d=a.curr;d!==null&&d.id.client===u&&d.id.clock===i.struct.id.clock+i.struct.length&&d.constructor!==N;d=a.next())dt(c,i.struct,i.offset),i={struct:d,offset:0}}i!==null&&(dt(c,i.struct,i.offset),i=null),qr(c);let l=r.map(a=>ot(a)),h=te(l);return tt(o,h),o.toUint8Array()},bi=(e,t,n=j,r=X)=>{let s=ui(t),i=new r,o=new Le(i),c=new n(V(e)),l=new et(c,!1);for(;l.curr;){let a=l.curr,u=a.id.client,d=s.get(u)||0;if(l.curr.constructor===N){l.next();continue}if(a.id.clock+a.length>d)for(dt(o,a,it(d-a.id.clock,0)),l.next();l.curr&&l.curr.id.client===u;)dt(o,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===u&&l.curr.id.clock+l.curr.length<=d;)l.next()}qr(o);let h=ot(c);return tt(i,h),i.toUint8Array()},Pa=(e,t)=>bi(e,t,H,ct),ki=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:q(e.encoder.restEncoder)}),e.encoder.restEncoder=kt(),e.written=0)},dt=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&ki(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),g(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},qr=e=>{ki(e);let t=e.encoder.restEncoder;g(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){let r=e.clientStructs[n];g(t,r.written),Rt(t,r.restEncoder)}},Bn=(e,t,n,r)=>{let s=new n(V(e)),i=new et(s,!1),o=new r,c=new Le(o);for(let h=i.curr;h!==null;h=i.next())dt(c,t(h),0);qr(c);let l=ot(s);return tt(o,l),o.toUint8Array()},Si=({formatting:e=!0,subdocs:t=!0,yxml:n=!0}={})=>{let r=0,s=A(),i=A(),o=A(),c=A();return c.set(null,null),l=>{switch(l.constructor){case R:case N:return l;case b:{let h=l,a=h.content;switch(a.constructor){case je:break;case K:{if(n){let u=a.type;u instanceof oe&&(u.nodeName=L(i,u.nodeName,()=>"node-"+r)),u instanceof On&&(u.hookName=L(i,u.hookName,()=>"hook-"+r))}break}case It:{let u=a;u.arr=u.arr.map(()=>r);break}case ce:{let u=a;u.content=new Uint8Array([r]);break}case le:{let u=a;t&&(u.opts={},u.doc.guid=r+"");break}case wt:{let u=a;u.embed={};break}case C:{let u=a;e&&(u.key=L(o,u.key,()=>r+""),u.value=L(c,u.value,()=>({i:r})));break}case Nn:{let u=a;u.arr=u.arr.map(()=>r);break}case nt:{let u=a;u.str=Ke(r%10+"",u.str.length);break}default:T()}return h.parentSub&&(h.parentSub=L(s,h.parentSub,()=>r+"")),r++,l}default:T()}}},Ka=(e,t)=>Bn(e,Si(t),H,ct),Ya=(e,t)=>Bn(e,Si(t),j,X),Wa=e=>Bn(e,nr,H,X),Xc=e=>Bn(e,nr,j,ct),ni="You must not compute changes after the event-handler fired.",ne=class{constructor(t,n){this.target=t,this.currentTarget=t,this.transaction=n,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=Pc(this.currentTarget,this.target))}deletes(t){return ae(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw G(ni);let t=new Map,n=this.target;this.transaction.changed.get(n).forEach(s=>{if(s!==null){let i=n._map.get(s),o,c;if(this.adds(i)){let l=i.left;for(;l!==null&&this.adds(l);)l=l.left;if(this.deletes(i))if(l!==null&&this.deletes(l))o="delete",c=He(l.content.getContent());else return;else l!==null&&this.deletes(l)?(o="update",c=He(l.content.getContent())):(o="add",c=void 0)}else if(this.deletes(i))o="delete",c=He(i.content.getContent());else return;t.set(s,{action:o,oldValue:c})}}),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(t===null){if(this.transaction.doc._transactionCleanups.length===0)throw G(ni);let n=this.target,r=rt(),s=rt(),i=[];if(t={added:r,deleted:s,delta:i,keys:this.keys},this.transaction.changed.get(n).has(null)){let c=null,l=()=>{c&&i.push(c)};for(let h=n._start;h!==null;h=h.right)h.deleted?this.deletes(h)&&!this.adds(h)&&((c===null||c.delete===void 0)&&(l(),c={delete:0}),c.delete+=h.length,s.add(h)):this.adds(h)?((c===null||c.insert===void 0)&&(l(),c={insert:[]}),c.insert=c.insert.concat(h.content.getContent()),r.add(h)):((c===null||c.retain===void 0)&&(l(),c={retain:0}),c.retain+=h.length);c!==null&&c.retain===void 0&&l()}this._changes=t}return t}},Pc=(e,t)=>{let n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let r=0,s=t._item.parent._start;for(;s!==t._item&&s!==null;)!s.deleted&&s.countable&&(r+=s.length),s=s.right;n.unshift(r)}t=t._item.parent}return n},O=()=>{kr("Invalid access: Add Yjs type to a document before reading data.")},_i=80,Gr=0,Dr=class{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=Gr++}},Kc=e=>{e.timestamp=Gr++},Ei=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Gr++},Yc=(e,t,n)=>{if(e.length>=_i){let r=e.reduce((s,i)=>s.timestamp<i.timestamp?s:i);return Ei(r,t,n),r}else{let r=new Dr(t,n);return e.push(r),r}},Mn=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;let n=e._searchMarker.length===0?null:e._searchMarker.reduce((i,o)=>yt(t-i.index)<yt(t-o.index)?i:o),r=e._start,s=0;for(n!==null&&(r=n.p,s=n.index,Kc(n));r.right!==null&&s<t;){if(!r.deleted&&r.countable){if(t<s+r.length)break;s+=r.length}r=r.right}for(;r.left!==null&&s>t;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);return n!==null&&yt(n.index-s)<r.parent.length/_i?(Ei(n,r,s),n):Yc(e._searchMarker,r,s)},Be=(e,t,n)=>{for(let r=e.length-1;r>=0;r--){let s=e[r];if(n>0){let i=s.p;for(i.marker=!1;i&&(i.deleted||!i.countable);)i=i.left,i&&!i.deleted&&i.countable&&(s.index-=i.length);if(i===null||i.marker===!0){e.splice(r,1);continue}s.p=i,i.marker=!0}(t<s.index||n>0&&t===s.index)&&(s.index=it(t,s.index+n))}},Za=e=>{e.doc??O();let t=e._start,n=[];for(;t;)n.push(t),t=t.right;return n},Rn=(e,t,n)=>{let r=e,s=t.changedParentTypes;for(;L(s,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;di(r._eH,n,t)},U=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=zs(),this._dEH=zs(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw z()}clone(){throw z()}_write(t){}get _first(){let t=this._start;for(;t!==null&&t.deleted;)t=t.right;return t}_callObserver(t,n){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){Hs(this._eH,t)}observeDeep(t){Hs(this._dEH,t)}unobserve(t){Js(this._eH,t)}unobserveDeep(t){Js(this._dEH,t)}toJSON(){}},Ui=(e,t,n)=>{e.doc??O(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t,s=[],i=e._start;for(;i!==null&&r>0;){if(i.countable&&!i.deleted){let o=i.content.getContent();if(o.length<=t)t-=o.length;else{for(let c=t;c<o.length&&r>0;c++)s.push(o[c]),r--;t=0}}i=i.right}return s},Ci=e=>{e.doc??O();let t=[],n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){let r=n.content.getContent();for(let s=0;s<r.length;s++)t.push(r[s])}n=n.right}return t},Qa=(e,t)=>{let n=[],r=e._start;for(;r!==null;){if(r.countable&&ut(r,t)){let s=r.content.getContent();for(let i=0;i<s.length;i++)n.push(s[i])}r=r.right}return n},Me=(e,t)=>{let n=0,r=e._start;for(e.doc??O();r!==null;){if(r.countable&&!r.deleted){let s=r.content.getContent();for(let i=0;i<s.length;i++)t(s[i],n++,e)}r=r.right}},Ai=(e,t)=>{let n=[];return Me(e,(r,s)=>{n.push(t(r,s,e))}),n},Wc=e=>{let t=e._start,n=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};n=t.content.getContent(),r=0,t=t.right}let s=n[r++];return n.length<=r&&(n=null),{done:!1,value:s}}}},Ii=(e,t)=>{e.doc??O();let n=Mn(e,t),r=e._start;for(n!==null&&(r=n.p,t-=n.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(t<r.length)return r.content.getContent()[t];t-=r.length}},vn=(e,t,n,r)=>{let s=n,i=e.doc,o=i.clientID,c=i.store,l=n===null?t._start:n.right,h=[],a=()=>{h.length>0&&(s=new b(m(o,_(c,o)),s,s&&s.lastId,l,l&&l.id,t,null,new It(h)),s.integrate(e,0),h=[])};r.forEach(u=>{if(u===null)h.push(u);else switch(u.constructor){case Number:case Object:case Boolean:case Array:case String:h.push(u);break;default:switch(a(),u.constructor){case Uint8Array:case ArrayBuffer:s=new b(m(o,_(c,o)),s,s&&s.lastId,l,l&&l.id,t,null,new ce(new Uint8Array(u))),s.integrate(e,0);break;case Ct:s=new b(m(o,_(c,o)),s,s&&s.lastId,l,l&&l.id,t,null,new le(u)),s.integrate(e,0);break;default:if(u instanceof U)s=new b(m(o,_(c,o)),s,s&&s.lastId,l,l&&l.id,t,null,new K(u)),s.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),a()},Di=()=>G("Length exceeded!"),Ti=(e,t,n,r)=>{if(n>t._length)throw Di();if(n===0)return t._searchMarker&&Be(t._searchMarker,n,r.length),vn(e,t,null,r);let s=n,i=Mn(t,n),o=t._start;for(i!==null&&(o=i.p,n-=i.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n<o.length&&M(e,m(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&Be(t._searchMarker,s,r.length),vn(e,t,o,r)},Zc=(e,t,n)=>{let s=(t._searchMarker||[]).reduce((i,o)=>o.index>i.index?o:i,{index:0,p:t._start}).p;if(s)for(;s.right;)s=s.right;return vn(e,t,s,n)},vi=(e,t,n,r)=>{if(r===0)return;let s=n,i=r,o=Mn(t,n),c=t._start;for(o!==null&&(c=o.p,n-=o.index);c!==null&&n>0;c=c.right)!c.deleted&&c.countable&&(n<c.length&&M(e,m(c.id.client,c.id.clock+n)),n-=c.length);for(;r>0&&c!==null;)c.deleted||(r<c.length&&M(e,m(c.id.client,c.id.clock+r)),c.delete(e),r-=c.length),c=c.right;if(r>0)throw Di();t._searchMarker&&Be(t._searchMarker,s,-i+r)},Vn=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},zr=(e,t,n,r)=>{let s=t._map.get(n)||null,i=e.doc,o=i.clientID,c;if(r==null)c=new It([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:c=new It([r]);break;case Uint8Array:c=new ce(r);break;case Ct:c=new le(r);break;default:if(r instanceof U)c=new K(r);else throw new Error("Unexpected content type")}new b(m(o,_(i.store,o)),s,s&&s.lastId,null,null,t,n,c).integrate(e,0)},Hr=(e,t)=>{e.doc??O();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},Vi=e=>{let t={};return e.doc??O(),e._map.forEach((n,r)=>{n.deleted||(t[r]=n.content.getContent()[n.length-1])}),t},Oi=(e,t)=>{e.doc??O();let n=e._map.get(t);return n!==void 0&&!n.deleted},th=(e,t,n)=>{let r=e._map.get(t)||null;for(;r!==null&&(!n.sv.has(r.id.client)||r.id.clock>=(n.sv.get(r.id.client)||0));)r=r.left;return r!==null&&ut(r,n)?r.content.getContent()[r.length-1]:void 0},Qc=(e,t)=>{let n={};return e._map.forEach((r,s)=>{let i=r;for(;i!==null&&(!t.sv.has(i.id.client)||i.id.clock>=(t.sv.get(i.id.client)||0));)i=i.left;i!==null&&ut(i,t)&&(n[s]=i.content.getContent()[i.length-1])}),n},Sn=e=>(e.doc??O(),$s(e._map.entries(),t=>!t[1].deleted)),Tr=class extends ne{},re=class e extends U{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){let n=new e;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(n=>n instanceof U?n.clone():n)),t}get length(){return this.doc??O(),this._length}_callObserver(t,n){super._callObserver(t,n),Rn(this,t,new Tr(this,t))}insert(t,n){this.doc!==null?x(this.doc,r=>{Ti(r,this,t,n)}):this._prelimContent.splice(t,0,...n)}push(t){this.doc!==null?x(this.doc,n=>{Zc(n,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){this.doc!==null?x(this.doc,r=>{vi(r,this,t,n)}):this._prelimContent.splice(t,n)}get(t){return Ii(this,t)}toArray(){return Ci(this)}slice(t=0,n=this.length){return Ui(this,t,n)}toJSON(){return this.map(t=>t instanceof U?t.toJSON():t)}map(t){return Ai(this,t)}forEach(t){Me(this,t)}[Symbol.iterator](){return Wc(this)}_write(t){t.writeTypeRef(kl)}},tl=e=>new re,vr=class extends ne{constructor(t,n,r){super(t,n),this.keysChanged=r}},se=class e extends U{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,n){super._integrate(t,n),this._prelimContent.forEach((r,s)=>{this.set(s,r)}),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return this.forEach((n,r)=>{t.set(r,n instanceof U?n.clone():n)}),t}_callObserver(t,n){Rn(this,t,new vr(this,t,n))}toJSON(){this.doc??O();let t={};return this._map.forEach((n,r)=>{if(!n.deleted){let s=n.content.getContent()[n.length-1];t[r]=s instanceof U?s.toJSON():s}}),t}get size(){return[...Sn(this)].length}keys(){return bn(Sn(this),t=>t[0])}values(){return bn(Sn(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return bn(Sn(this),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this.doc??O(),this._map.forEach((n,r)=>{n.deleted||t(n.content.getContent()[n.length-1],r,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?x(this.doc,n=>{Vn(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?x(this.doc,r=>{zr(r,this,t,n)}):this._prelimContent.set(t,n),n}get(t){return Hr(this,t)}has(t){return Oi(this,t)}clear(){this.doc!==null?x(this.doc,t=>{this.forEach(function(n,r,s){Vn(t,s,r)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(Sl)}},el=e=>new se,ft=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&Qn(e,t),Re=class{constructor(t,n,r,s){this.left=t,this.right=n,this.index=r,this.currentAttributes=s}forward(){this.right===null&&T(),this.right.content.constructor===C?this.right.deleted||he(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}},ri=(e,t,n)=>{for(;t.right!==null&&n>0;)t.right.content.constructor===C?t.right.deleted||he(t.currentAttributes,t.right.content):t.right.deleted||(n<t.right.length&&M(e,m(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length),t.left=t.right,t.right=t.right.right;return t},_n=(e,t,n,r)=>{let s=new Map,i=r?Mn(t,n):null;if(i){let o=new Re(i.p.left,i.p,i.index,s);return ri(e,o,n-i.index)}else{let o=new Re(null,t._start,0,s);return ri(e,o,n)}},Ni=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===C&&ft(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();let s=e.doc,i=s.clientID;r.forEach((o,c)=>{let l=n.left,h=n.right,a=new b(m(i,_(s.store,i)),l,l&&l.lastId,h,h&&h.id,t,null,new C(c,o));a.integrate(e,0),n.right=a,n.forward()})},he=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},Li=(e,t)=>{for(;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===C&&ft(t[e.right.content.key]??null,e.right.content.value)))break;e.forward()}},Bi=(e,t,n,r)=>{let s=e.doc,i=s.clientID,o=new Map;for(let c in r){let l=r[c],h=n.currentAttributes.get(c)??null;if(!ft(h,l)){o.set(c,h);let{left:a,right:u}=n;n.right=new b(m(i,_(s.store,i)),a,a&&a.lastId,u,u&&u.id,t,null,new C(c,l)),n.right.integrate(e,0),n.forward()}}return o},Sr=(e,t,n,r,s)=>{n.currentAttributes.forEach((d,f)=>{s[f]===void 0&&(s[f]=null)});let i=e.doc,o=i.clientID;Li(n,s);let c=Bi(e,t,n,s),l=r.constructor===String?new nt(r):r instanceof U?new K(r):new wt(r),{left:h,right:a,index:u}=n;t._searchMarker&&Be(t._searchMarker,n.index,l.getLength()),a=new b(m(o,_(i.store,o)),h,h&&h.lastId,a,a&&a.id,t,null,l),a.integrate(e,0),n.right=a,n.index=u,n.forward(),Ni(e,t,n,c)},si=(e,t,n,r,s)=>{let i=e.doc,o=i.clientID;Li(n,s);let c=Bi(e,t,n,s);t:for(;n.right!==null&&(r>0||c.size>0&&(n.right.deleted||n.right.content.constructor===C));){if(!n.right.deleted)switch(n.right.content.constructor){case C:{let{key:l,value:h}=n.right.content,a=s[l];if(a!==void 0){if(ft(a,h))c.delete(l);else{if(r===0)break t;c.set(l,h)}n.right.delete(e)}else n.currentAttributes.set(l,h);break}default:r<n.right.length&&M(e,m(n.right.id.client,n.right.id.clock+r)),r-=n.right.length;break}n.forward()}if(r>0){let l="";for(;r>0;r--)l+=`
6
+ `;n.right=new b(m(o,_(i.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new nt(l)),n.right.integrate(e,0),n.forward()}Ni(e,t,n,c)},Mi=(e,t,n,r,s)=>{let i=t,o=A();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===C){let h=i.content;o.set(h.key,h)}i=i.right}let c=0,l=!1;for(;t!==i;){if(n===t&&(l=!0),!t.deleted){let h=t.content;if(h.constructor===C){let{key:a,value:u}=h,d=r.get(a)??null;(o.get(a)!==h||d===u)&&(t.delete(e),c++,!l&&(s.get(a)??null)===u&&d!==u&&(d===null?s.delete(a):s.set(a,d))),!l&&!t.deleted&&he(s,h)}}t=t.right}return c},nl=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;let n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===C){let r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}},rl=e=>{let t=0;return x(e.doc,n=>{let r=e._start,s=e._start,i=A(),o=ze(i);for(;s;)s.deleted===!1&&(s.content.constructor===C?he(o,s.content):(t+=Mi(n,r,s,i,o),i=ze(o),r=s)),s=s.right}),t},sl=e=>{let t=new Set,n=e.doc;for(let[r,s]of e.afterState.entries()){let i=e.beforeState.get(r)||0;s!==i&&mi(e,n.store.clients.get(r),i,s,o=>{!o.deleted&&o.content.constructor===C&&o.constructor!==R&&t.add(o.parent)})}x(n,r=>{Qt(e,e.deleteSet,s=>{if(s instanceof R||!s.parent._hasFormatting||t.has(s.parent))return;let i=s.parent;s.content.constructor===C?t.add(i):nl(r,s)});for(let s of t)rl(s)})},ii=(e,t,n)=>{let r=n,s=ze(t.currentAttributes),i=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case K:case wt:case nt:n<t.right.length&&M(e,m(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}i&&Mi(e,i,t.right,s,t.currentAttributes);let o=(t.left||t.right).parent;return o._searchMarker&&Be(o._searchMarker,t.index,-r+n),t},Vr=class extends ne{constructor(t,n,r){super(t,n),this.childListChanged=!1,this.keysChanged=new Set,r.forEach(s=>{s===null?this.childListChanged=!0:this.keysChanged.add(s)})}get changes(){if(this._changes===null){let t={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=t}return this._changes}get delta(){if(this._delta===null){let t=this.target.doc,n=[];x(t,r=>{let s=new Map,i=new Map,o=this.target._start,c=null,l={},h="",a=0,u=0,d=()=>{if(c!==null){let f=null;switch(c){case"delete":u>0&&(f={delete:u}),u=0;break;case"insert":(typeof h=="object"||h.length>0)&&(f={insert:h},s.size>0&&(f.attributes={},s.forEach((p,y)=>{p!==null&&(f.attributes[y]=p)}))),h="";break;case"retain":a>0&&(f={retain:a},gs(l)||(f.attributes=fs({},l))),a=0;break}f&&n.push(f),c=null}};for(;o!==null;){switch(o.content.constructor){case K:case wt:this.adds(o)?this.deletes(o)||(d(),c="insert",h=o.content.getContent()[0],d()):this.deletes(o)?(c!=="delete"&&(d(),c="delete"),u+=1):o.deleted||(c!=="retain"&&(d(),c="retain"),a+=1);break;case nt:this.adds(o)?this.deletes(o)||(c!=="insert"&&(d(),c="insert"),h+=o.content.str):this.deletes(o)?(c!=="delete"&&(d(),c="delete"),u+=o.length):o.deleted||(c!=="retain"&&(d(),c="retain"),a+=o.length);break;case C:{let{key:f,value:p}=o.content;if(this.adds(o)){if(!this.deletes(o)){let y=s.get(f)??null;ft(y,p)?p!==null&&o.delete(r):(c==="retain"&&d(),ft(p,i.get(f)??null)?delete l[f]:l[f]=p)}}else if(this.deletes(o)){i.set(f,p);let y=s.get(f)??null;ft(y,p)||(c==="retain"&&d(),l[f]=y)}else if(!o.deleted){i.set(f,p);let y=l[f];y!==void 0&&(ft(y,p)?y!==null&&o.delete(r):(c==="retain"&&d(),p===null?delete l[f]:l[f]=p))}o.deleted||(c==="insert"&&d(),he(s,o.content));break}}o=o.right}for(d();n.length>0;){let f=n[n.length-1];if(f.retain!==void 0&&f.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}},$e=class e extends U{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??O(),this._length}_integrate(t,n){super._integrate(t,n);try{this._pending.forEach(r=>r())}catch(r){console.error(r)}this._pending=null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);let r=new Vr(this,t,n);Rn(this,t,r),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??O();let t="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===nt&&(t+=n.content.str),n=n.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:n=!0}={}){this.doc!==null?x(this.doc,r=>{let s=new Re(null,this._start,0,new Map);for(let i=0;i<t.length;i++){let o=t[i];if(o.insert!==void 0){let c=!n&&typeof o.insert=="string"&&i===t.length-1&&s.right===null&&o.insert.slice(-1)===`
7
+ `?o.insert.slice(0,-1):o.insert;(typeof c!="string"||c.length>0)&&Sr(r,this,s,c,o.attributes||{})}else o.retain!==void 0?si(r,this,s,o.retain,o.attributes||{}):o.delete!==void 0&&ii(r,s,o.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,n,r){this.doc??O();let s=[],i=new Map,o=this.doc,c="",l=this._start;function h(){if(c.length>0){let u={},d=!1;i.forEach((p,y)=>{d=!0,u[y]=p});let f={insert:c};d&&(f.attributes=u),s.push(f),c=""}}let a=()=>{for(;l!==null;){if(ut(l,t)||n!==void 0&&ut(l,n))switch(l.content.constructor){case nt:{let u=i.get("ychange");t!==void 0&&!ut(l,t)?(u===void 0||u.user!==l.id.client||u.type!=="removed")&&(h(),i.set("ychange",r?r("removed",l.id):{type:"removed"})):n!==void 0&&!ut(l,n)?(u===void 0||u.user!==l.id.client||u.type!=="added")&&(h(),i.set("ychange",r?r("added",l.id):{type:"added"})):u!==void 0&&(h(),i.delete("ychange")),c+=l.content.str;break}case K:case wt:{h();let u={insert:l.content.getContent()[0]};if(i.size>0){let d={};u.attributes=d,i.forEach((f,p)=>{d[p]=f})}s.push(u);break}case C:ut(l,t)&&(h(),he(i,l.content));break}l=l.right}h()};return t||n?x(o,u=>{t&&Ur(u,t),n&&Ur(u,n),a()},"cleanup"):a(),s}insert(t,n,r){if(n.length<=0)return;let s=this.doc;s!==null?x(s,i=>{let o=_n(i,this,t,!r);r||(r={},o.currentAttributes.forEach((c,l)=>{r[l]=c})),Sr(i,this,o,n,r)}):this._pending.push(()=>this.insert(t,n,r))}insertEmbed(t,n,r){let s=this.doc;s!==null?x(s,i=>{let o=_n(i,this,t,!r);Sr(i,this,o,n,r||{})}):this._pending.push(()=>this.insertEmbed(t,n,r||{}))}delete(t,n){if(n===0)return;let r=this.doc;r!==null?x(r,s=>{ii(s,_n(s,this,t,!0),n)}):this._pending.push(()=>this.delete(t,n))}format(t,n,r){if(n===0)return;let s=this.doc;s!==null?x(s,i=>{let o=_n(i,this,t,!1);o.right!==null&&si(i,this,o,n,r)}):this._pending.push(()=>this.format(t,n,r))}removeAttribute(t){this.doc!==null?x(this.doc,n=>{Vn(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?x(this.doc,r=>{zr(r,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return Hr(this,t)}getAttributes(){return Vi(this)}_write(t){t.writeTypeRef(_l)}},il=e=>new $e,ve=class{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??O()}[Symbol.iterator](){return this}next(){let t=this._currentNode,n=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(n)))do if(n=t.content.type,!t.deleted&&(n.constructor===oe||n.constructor===ie)&&n._start!==null)t=n._start;else for(;t!==null;){let r=t.next;if(r!==null){t=r;break}else t.parent===this._root?t=null:t=t.parent._item}while(t!==null&&(t.deleted||!this._filter(t.content.type)));return this._firstCall=!1,t===null?{value:void 0,done:!0}:(this._currentNode=t,{value:t.content.type,done:!1})}},ie=class e extends U{constructor(){super(),this._prelimContent=[]}get firstChild(){let t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(n=>n instanceof U?n.clone():n)),t}get length(){return this.doc??O(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new ve(this,t)}querySelector(t){t=t.toUpperCase();let r=new ve(this,s=>s.nodeName&&s.nodeName.toUpperCase()===t).next();return r.done?null:r.value}querySelectorAll(t){return t=t.toUpperCase(),Y(new ve(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){Rn(this,t,new Or(this,n,t))}toString(){return Ai(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,n={},r){let s=t.createDocumentFragment();return r!==void 0&&r._createAssociation(s,this),Me(this,i=>{s.insertBefore(i.toDOM(t,n,r),null)}),s}insert(t,n){this.doc!==null?x(this.doc,r=>{Ti(r,this,t,n)}):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(this.doc!==null)x(this.doc,r=>{let s=t&&t instanceof U?t._item:t;vn(r,this,s,n)});else{let r=this._prelimContent,s=t===null?0:r.findIndex(i=>i===t)+1;if(s===0&&t!==null)throw G("Reference item not found");r.splice(s,0,...n)}}delete(t,n=1){this.doc!==null?x(this.doc,r=>{vi(r,this,t,n)}):this._prelimContent.splice(t,n)}toArray(){return Ci(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Ii(this,t)}slice(t=0,n=this.length){return Ui(this,t,n)}forEach(t){Me(this,t)}_write(t){t.writeTypeRef(Ul)}},ol=e=>new ie,oe=class e extends ie{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){let t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){let t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,n){super._integrate(t,n),this._prelimAttrs.forEach((r,s)=>{this.setAttribute(s,r)}),this._prelimAttrs=null}_copy(){return new e(this.nodeName)}clone(){let t=new e(this.nodeName),n=this.getAttributes();return ps(n,(r,s)=>{typeof r=="string"&&t.setAttribute(s,r)}),t.insert(0,this.toArray().map(r=>r instanceof U?r.clone():r)),t}toString(){let t=this.getAttributes(),n=[],r=[];for(let c in t)r.push(c);r.sort();let s=r.length;for(let c=0;c<s;c++){let l=r[c];n.push(l+'="'+t[l]+'"')}let i=this.nodeName.toLocaleLowerCase(),o=n.length>0?" "+n.join(" "):"";return`<${i}${o}>${super.toString()}</${i}>`}removeAttribute(t){this.doc!==null?x(this.doc,n=>{Vn(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?x(this.doc,r=>{zr(r,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return Hr(this,t)}hasAttribute(t){return Oi(this,t)}getAttributes(t){return t?Qc(this,t):Vi(this)}toDOM(t=document,n={},r){let s=t.createElement(this.nodeName),i=this.getAttributes();for(let o in i){let c=i[o];typeof c=="string"&&s.setAttribute(o,c)}return Me(this,o=>{s.appendChild(o.toDOM(t,n,r))}),r!==void 0&&r._createAssociation(s,this),s}_write(t){t.writeTypeRef(El),t.writeKey(this.nodeName)}},cl=e=>new oe(e.readKey()),Or=class extends ne{constructor(t,n,r){super(t,r),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(s=>{s===null?this.childListChanged=!0:this.attributesChanged.add(s)})}},On=class e extends se{constructor(t){super(),this.hookName=t}_copy(){return new e(this.hookName)}clone(){let t=new e(this.hookName);return this.forEach((n,r)=>{t.set(r,n)}),t}toDOM(t=document,n={},r){let s=n[this.hookName],i;return s!==void 0?i=s.createDom(this):i=document.createElement(this.hookName),i.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(i,this),i}_write(t){t.writeTypeRef(Cl),t.writeKey(this.hookName)}},ll=e=>new On(e.readKey()),Nr=class e extends $e{get nextSibling(){let t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){let t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}toDOM(t=document,n,r){let s=t.createTextNode(this.toString());return r!==void 0&&r._createAssociation(s,this),s}toString(){return this.toDelta().map(t=>{let n=[];for(let s in t.attributes){let i=[];for(let o in t.attributes[s])i.push({key:o,value:t.attributes[s][o]});i.sort((o,c)=>o.key<c.key?-1:1),n.push({nodeName:s,attrs:i})}n.sort((s,i)=>s.nodeName<i.nodeName?-1:1);let r="";for(let s=0;s<n.length;s++){let i=n[s];r+=`<${i.nodeName}`;for(let o=0;o<i.attrs.length;o++){let c=i.attrs[o];r+=` ${c.key}="${c.value}"`}r+=">"}r+=t.insert;for(let s=n.length-1;s>=0;s--)r+=`</${n[s].nodeName}>`;return r}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(Al)}},al=e=>new Nr,Fe=class{constructor(t,n){this.id=t,this.length=n}get deleted(){throw z()}mergeWith(t){return!1}write(t,n,r){throw z()}integrate(t,n){throw z()}},hl=0,R=class extends Fe{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){n>0&&(this.id.clock+=n,this.length-=n),gi(t.doc.store,this)}write(t,n){t.writeInfo(hl),t.writeLen(this.length-n)}getMissing(t,n){return null}},ce=class e{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new e(this.content)}splice(t){throw z()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}},ul=e=>new ce(e.readBuf()),je=class e{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.len)}splice(t){let n=new e(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){Oe(t.deleteSet,n.id.client,n.id.clock,this.len),n.markDeleted()}delete(t){}gc(t){}write(t,n){t.writeLen(this.len-n)}getRef(){return 1}},dl=e=>new je(e.readLen()),Ri=(e,t)=>new Ct({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),le=class e{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;let n={};this.opts=n,t.gc||(n.gc=!1),t.autoLoad&&(n.autoLoad=!0),t.meta!==null&&(n.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new e(Ri(this.doc.guid,this.opts))}splice(t){throw z()}mergeWith(t){return!1}integrate(t,n){this.doc._item=n,t.subdocsAdded.add(this.doc),this.doc.shouldLoad&&t.subdocsLoaded.add(this.doc)}delete(t){t.subdocsAdded.has(this.doc)?t.subdocsAdded.delete(this.doc):t.subdocsRemoved.add(this.doc)}gc(t){}write(t,n){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}},fl=e=>new le(Ri(e.readString(),e.readAny())),wt=class e{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new e(this.embed)}splice(t){throw z()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}},pl=e=>new wt(e.readJSON()),C=class e{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.key,this.value)}splice(t){throw z()}mergeWith(t){return!1}integrate(t,n){let r=n.parent;r._searchMarker=null,r._hasFormatting=!0}delete(t){}gc(t){}write(t,n){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}},gl=e=>new C(e.readKey(),e.readJSON()),Nn=class e{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){let r=this.arr.length;t.writeLen(r-n);for(let s=n;s<r;s++){let i=this.arr[s];t.writeString(i===void 0?"undefined":JSON.stringify(i))}}getRef(){return 2}},ml=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++){let s=e.readString();s==="undefined"?n.push(void 0):n.push(JSON.parse(s))}return new Nn(n)},wl=Ee("node_env")==="development",It=class e{constructor(t){this.arr=t,wl&&tr(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){let r=this.arr.length;t.writeLen(r-n);for(let s=n;s<r;s++){let i=this.arr[s];t.writeAny(i)}}getRef(){return 8}},yl=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new It(n)},nt=class e{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new e(this.str)}splice(t){let n=new e(this.str.slice(t));this.str=this.str.slice(0,t);let r=this.str.charCodeAt(t-1);return r>=55296&&r<=56319&&(this.str=this.str.slice(0,t-1)+"\uFFFD",n.str="\uFFFD"+n.str.slice(1)),n}mergeWith(t){return this.str+=t.str,!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeString(n===0?this.str:this.str.slice(n))}getRef(){return 4}},xl=e=>new nt(e.readString()),bl=[tl,el,il,cl,ol,ll,al],kl=0,Sl=1,_l=2,El=3,Ul=4,Cl=5,Al=6,K=class e{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new e(this.type._copy())}splice(t){throw z()}mergeWith(t){return!1}integrate(t,n){this.type._integrate(t.doc,n)}delete(t){let n=this.type._start;for(;n!==null;)n.deleted?n.id.clock<(t.beforeState.get(n.id.client)||0)&&t._mergeStructs.push(n):n.delete(t),n=n.right;this.type._map.forEach(r=>{r.deleted?r.id.clock<(t.beforeState.get(r.id.client)||0)&&t._mergeStructs.push(r):r.delete(t)}),t.changed.delete(this.type)}gc(t){let n=this.type._start;for(;n!==null;)n.gc(t,!0),n=n.right;this.type._start=null,this.type._map.forEach(r=>{for(;r!==null;)r.gc(t,!0),r=r.left}),this.type._map=new Map}write(t,n){this.type._write(t)}getRef(){return 7}},Il=e=>new K(bl[e.readTypeRef()](e)),Lr=(e,t)=>{let n=t,r=0,s;do r>0&&(n=m(n.client,n.clock+r)),s=Zt(e,n),r=n.clock-s.id.clock,n=s.redone;while(n!==null&&s instanceof b);return{item:s,diff:r}},Jr=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Ln=(e,t,n)=>{let{client:r,clock:s}=t.id,i=new b(m(r,s+n),t,m(r,s+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&i.markDeleted(),t.keep&&(i.keep=!0),t.redone!==null&&(i.redone=m(t.redone.client,t.redone.clock+n)),t.right=i,i.right!==null&&(i.right.left=i),e._mergeStructs.push(i),i.parentSub!==null&&i.right===null&&i.parent._map.set(i.parentSub,i),t.length=n,i},oi=(e,t)=>de(e,n=>ae(n.deletions,t)),$i=(e,t,n,r,s,i)=>{let o=e.doc,c=o.store,l=o.clientID,h=t.redone;if(h!==null)return M(e,h);let a=t.parent._item,u=null,d;if(a!==null&&a.deleted===!0){if(a.redone===null&&(!n.has(a)||$i(e,a,n,r,s,i)===null))return null;for(;a.redone!==null;)a=M(e,a.redone)}let f=a===null?t.parent:a.content.type;if(t.parentSub===null){for(u=t.left,d=t;u!==null;){let S=u;for(;S!==null&&S.parent._item!==a;)S=S.redone===null?null:M(e,S.redone);if(S!==null&&S.parent._item===a){u=S;break}u=u.left}for(;d!==null;){let S=d;for(;S!==null&&S.parent._item!==a;)S=S.redone===null?null:M(e,S.redone);if(S!==null&&S.parent._item===a){d=S;break}d=d.right}}else if(d=null,t.right&&!s){for(u=t;u!==null&&u.right!==null&&(u.right.redone||ae(r,u.right.id)||oi(i.undoStack,u.right.id)||oi(i.redoStack,u.right.id));)for(u=u.right;u.redone;)u=M(e,u.redone);if(u&&u.right!==null)return null}else u=f._map.get(t.parentSub)||null;let p=_(c,l),y=m(l,p),k=new b(y,u,u&&u.lastId,d,d&&d.id,f,t.parentSub,t.content.copy());return t.redone=y,Jr(k,!0),k.integrate(e,0),k},b=class e extends Fe{constructor(t,n,r,s,i,o,c,l){super(t,l.getLength()),this.origin=r,this.left=n,this.right=s,this.rightOrigin=i,this.parent=o,this.parentSub=c,this.redone=null,this.content=l,this.info=this.content.isCountable()?2:0}set marker(t){(this.info&8)>0!==t&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(t){this.keep!==t&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(t){this.deleted!==t&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=_(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=_(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===pt&&this.id.client!==this.parent.client&&this.parent.clock>=_(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Ys(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=M(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===R||this.right&&this.right.constructor===R)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===e?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===e&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===pt){let r=Zt(n,this.parent);r.constructor===R?this.parent=null:this.parent=r.content.type}return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=Ys(t,t.doc.store,m(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let r=this.left,s;if(r!==null)s=r.right;else if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start;let i=new Set,o=new Set;for(;s!==null&&s!==this.right;){if(o.add(s),i.add(s),Wt(this.origin,s.origin)){if(s.id.client<this.id.client)r=s,i.clear();else if(Wt(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&o.has(Zt(t.doc.store,s.origin)))i.has(Zt(t.doc.store,s.origin))||(r=s,i.clear());else break;s=s.right}this.left=r}if(this.left!==null){let r=this.left.right;this.right=r,this.left.right=this}else{let r;if(this.parentSub!==null)for(r=this.parent._map.get(this.parentSub)||null;r!==null&&r.left!==null;)r=r.left;else r=this.parent._start,this.parent._start=this;this.right=r}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(t)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),gi(t.doc.store,this),this.content.integrate(t,this),Zs(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new R(this.id,this.length).integrate(t,0)}get next(){let t=this.right;for(;t!==null&&t.deleted;)t=t.right;return t}get prev(){let t=this.left;for(;t!==null&&t.deleted;)t=t.left;return t}get lastId(){return this.length===1?this.id:m(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&Wt(t.origin,this.lastId)&&this.right===t&&Wt(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&this.redone===null&&t.redone===null&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){let n=this.parent._searchMarker;return n&&n.forEach(r=>{r.p===t&&(r.p=this,!this.deleted&&this.countable&&(r.index-=this.length))}),t.keep&&(this.keep=!0),this.right=t.right,this.right!==null&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){let n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),Oe(t.deleteSet,this.id.client,this.id.clock,this.length),Zs(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw T();this.content.gc(t),n?$c(t,this,new R(this.id,this.length)):this.content=new je(this.length)}write(t,n){let r=n>0?m(this.id.client,this.id.clock+n-1):this.origin,s=this.rightOrigin,i=this.parentSub,o=this.content.getRef()&31|(r===null?0:128)|(s===null?0:64)|(i===null?0:32);if(t.writeInfo(o),r!==null&&t.writeLeftID(r),s!==null&&t.writeRightID(s),r===null&&s===null){let c=this.parent;if(c._item!==void 0){let l=c._item;if(l===null){let h=fi(c);t.writeParentInfo(!0),t.writeString(h)}else t.writeParentInfo(!1),t.writeLeftID(l.id)}else c.constructor===String?(t.writeParentInfo(!0),t.writeString(c)):c.constructor===pt?(t.writeParentInfo(!1),t.writeLeftID(c)):T();i!==null&&t.writeString(i)}this.content.write(t,n)}},Fi=(e,t)=>Dl[t&31](e),Dl=[()=>{T()},dl,ml,ul,xl,pl,gl,Il,yl,fl,()=>{T()}],Tl=10,N=class extends Fe{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){T()}write(t,n){t.writeInfo(Tl),g(t.restEncoder,this.length-n)}getMissing(t,n){return null}},ji=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},qi="__ $YJS$ __";ji[qi]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");ji[qi]=!0;export{Er as AbsolutePosition,qs as AbstractConnector,Fe as AbstractStruct,U as AbstractType,re as Array,It as ContentAny,ce as ContentBinary,je as ContentDeleted,le as ContentDoc,wt as ContentEmbed,C as ContentFormat,Nn as ContentJSON,nt as ContentString,K as ContentType,Ct as Doc,R as GC,pt as ID,b as Item,se as Map,Ks as PermanentUserData,Ne as RelativePosition,N as Skip,In as Snapshot,$e as Text,Ar as Transaction,ei as UndoManager,H as UpdateDecoderV1,j as UpdateDecoderV2,ct as UpdateEncoderV1,X as UpdateEncoderV2,oe as XmlElement,ie as XmlFragment,On as XmlHook,Nr as XmlText,Tr as YArrayEvent,ne as YEvent,vr as YMapEvent,Vr as YTextEvent,Or as YXmlEvent,Ua as applyUpdate,Fr as applyUpdateV2,rl as cleanupYTextFormatting,Wt as compareIDs,La as compareRelativePositions,Wa as convertUpdateFormatV1ToV2,Xc as convertUpdateFormatV2ToV1,Na as createAbsolutePositionFromRelativePosition,Rr as createDeleteSet,ci as createDeleteSetFromStructStore,ja as createDocFromSnapshot,m as createID,Ta as createRelativePositionFromJSON,va as createRelativePositionFromTypeIndex,pi as createSnapshot,Oa as decodeRelativePosition,Ra as decodeSnapshot,Bc as decodeSnapshotV2,ui as decodeStateVector,Ha as decodeUpdate,qc as decodeUpdateV2,Pa as diffUpdate,bi as diffUpdateV2,$a as emptySnapshot,Va as encodeRelativePosition,Ma as encodeSnapshot,Lc as encodeSnapshotV2,Ca as encodeStateAsUpdate,Ic as encodeStateAsUpdateV2,Aa as encodeStateVector,Ja as encodeStateVectorFromUpdate,zc as encodeStateVectorFromUpdateV2,Sc as equalDeleteSets,Ba as equalSnapshots,P as findIndexSS,fi as findRootTypeKey,Lo as fromBase64,Zt as getItem,Ys as getItemCleanEnd,M as getItemCleanStart,_ as getState,Za as getTypeChildren,ae as isDeleted,An as isParentOf,Qt as iterateDeletedStructs,Ia as logType,za as logUpdate,jc as logUpdateV2,te as mergeDeleteSets,Gc as mergeUpdates,Tn as mergeUpdatesV2,Ka as obfuscateUpdate,Ya as obfuscateUpdateV2,Xa as parseUpdateMeta,Hc as parseUpdateMetaV2,Ea as readUpdate,ai as readUpdateV2,Da as relativePositionToJSON,Fa as snapshot,qa as snapshotContainsUpdate,No as toBase64,x as transact,Ga as tryGc,Qa as typeListToArraySnapshot,Qc as typeMapGetAllSnapshot,th as typeMapGetSnapshot};