@panphora/clayjs 1.16.0 → 1.17.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.
- package/dist/all.js +1 -1
- package/dist/clay-dom.js +1 -1
- package/dist/clay-events.js +1 -1
- package/dist/clay-internals.js +1 -1
- package/dist/clay-options.js +1 -1
- package/dist/clay-router.js +1 -1
- package/dist/clay-ui.js +1 -1
- package/dist/clay-utils.js +1 -1
- package/dist/clay.js +1 -1
- package/dist/clay.standalone.js +7917 -5621
- package/dist/m/attrs/refetch-on-save-ZUE7PSCI.js +1 -0
- package/dist/m/attrs/save-freeze-MYNVXREN.js +1 -0
- package/dist/m/c-2YYDMLNZ.js +1 -0
- package/dist/m/c-336SGU5W.js +1 -0
- package/dist/m/c-3H6BZDNJ.js +6 -0
- package/dist/m/{c-LR4CGEPT.js → c-3RUU4TPX.js} +1 -1
- package/dist/m/c-3XIRD4NU.js +1 -0
- package/dist/m/c-4DFEJ2PO.js +3 -0
- package/dist/m/c-56QRZTZH.js +1 -0
- package/dist/m/c-5J4E7O4Y.js +4 -0
- package/dist/m/c-5LKDWQTL.js +19 -0
- package/dist/m/c-5QWQ7A5L.js +1 -0
- package/dist/m/c-5RJFTLSF.js +1 -0
- package/dist/m/c-6AZOGAPE.js +1 -0
- package/dist/m/{c-Y6USGTS5.js → c-6CRUUXOX.js} +5 -5
- package/dist/m/{c-54RCDCBU.js → c-6KEVEQ7L.js} +1 -1
- package/dist/m/{c-LTGMXXKO.js → c-6NC5I2TV.js} +1 -1
- package/dist/m/{c-YDH7Q3NY.js → c-74MGYWZF.js} +1 -1
- package/dist/m/{c-Z36J63PP.js → c-7OLLJPWP.js} +1 -1
- package/dist/m/c-A3E3NIMC.js +1 -0
- package/dist/m/{c-5R4PTRG2.js → c-AMSNPOCX.js} +1 -1
- package/dist/m/c-B3JM5ZXC.js +1 -0
- package/dist/m/c-BPF2NSPV.js +1 -0
- package/dist/m/c-BQ6LOBEE.js +1 -0
- package/dist/m/c-CJ3A7ZKE.js +1 -0
- package/dist/m/c-CQHPGKX2.js +1 -0
- package/dist/m/c-DCXOXBF3.js +1 -0
- package/dist/m/c-DFS4XZJV.js +2 -0
- package/dist/m/{c-F3CKJTJS.js → c-DNENWY4O.js} +1 -1
- package/dist/m/c-E4LIR5X5.js +1 -0
- package/dist/m/c-EVCQ3BKA.js +1 -0
- package/dist/m/{c-5Y6TNX5W.js → c-EZU56NQV.js} +2 -2
- package/dist/m/c-FDNHHZY5.js +1 -0
- package/dist/m/{c-SWRJFCNN.js → c-FRLHSY7E.js} +1 -1
- package/dist/m/c-FROJUZMV.js +1 -0
- package/dist/m/c-G2JPKCTP.js +1 -0
- package/dist/m/c-GB6TU7WV.js +1 -0
- package/dist/m/{c-GB3JTV6E.js → c-GFJJEBTU.js} +1 -1
- package/dist/m/{c-J7CA54IP.js → c-GSFIGKOP.js} +1 -1
- package/dist/m/{c-OYTFP5QN.js → c-GY422N3Q.js} +1 -1
- package/dist/m/c-HAWFNBYG.js +1 -0
- package/dist/m/{c-33HUYEDI.js → c-HDDEEL77.js} +1 -1
- package/dist/m/c-HFKUVACH.js +1 -0
- package/dist/m/c-HHDFCNHV.js +1 -0
- package/dist/m/c-I2ZATQCD.js +2 -0
- package/dist/m/c-IEM4NTCS.js +1 -0
- package/dist/m/c-IW6GGOU2.js +1 -0
- package/dist/m/{c-SGCCC4FW.js → c-JDCX26UP.js} +2 -2
- package/dist/m/c-JRKY44DK.js +1 -0
- package/dist/m/c-JU3NK25H.js +1 -0
- package/dist/m/{c-VFX45IZQ.js → c-KAU6E43D.js} +1 -1
- package/dist/m/c-KBS3UV6B.js +1 -0
- package/dist/m/c-KGVGROZT.js +1 -0
- package/dist/m/{c-YG2NJYS6.js → c-KQ6TYJAP.js} +2 -2
- package/dist/m/{c-2JL6E75N.js → c-KU3ZFADW.js} +1 -1
- package/dist/m/c-LWLBHLVC.js +3 -0
- package/dist/m/c-M2L47S2X.js +7 -0
- package/dist/m/c-MFP2ZWD4.js +1 -0
- package/dist/m/{c-4YSCRICO.js → c-MKSQ4Y57.js} +1 -1
- package/dist/m/{c-2M73252O.js → c-NUFFJVVJ.js} +1 -1
- package/dist/m/c-NUHSPT5P.js +1 -0
- package/dist/m/c-O72HVYSA.js +1 -0
- package/dist/m/c-OW5QIGG3.js +1 -0
- package/dist/m/c-PGRCK73F.js +1 -0
- package/dist/m/{c-4DRMS4QG.js → c-PS5ARVWR.js} +1 -1
- package/dist/m/c-Q622NS2Y.js +1 -0
- package/dist/m/c-Q7NQD65V.js +1 -0
- package/dist/m/c-QH63LQOS.js +1 -0
- package/dist/m/{c-TQZ2JYHD.js → c-QICP2YR5.js} +1 -1
- package/dist/m/{c-7VGZ7RU5.js → c-QJ4OM3G6.js} +1 -1
- package/dist/m/{c-MMUIUUZG.js → c-R3L7ZJGB.js} +1 -1
- package/dist/m/c-R7IWVINQ.js +1 -0
- package/dist/m/{c-HVYXIS72.js → c-RSMOODDU.js} +1 -1
- package/dist/m/{c-KKWLDOPM.js → c-RYUXUUBX.js} +1 -1
- package/dist/m/c-S4ZEH46B.js +9 -0
- package/dist/m/c-SDAXDM2D.js +1 -0
- package/dist/m/c-SMBZG5X4.js +1 -0
- package/dist/m/{c-UXBMRDZB.js → c-SMGU7RT3.js} +1 -1
- package/dist/m/c-SPIORRYS.js +1 -0
- package/dist/m/c-SWLRT66R.js +1 -0
- package/dist/m/c-SZGYW5HT.js +1 -0
- package/dist/m/c-TCJTVAFN.js +1 -0
- package/dist/m/{c-HRDCD3WN.js → c-TJ6WOJL3.js} +1 -1
- package/dist/m/c-TYLXX4NF.js +21 -0
- package/dist/m/c-U62OB4BT.js +1 -0
- package/dist/m/{c-NMJRXKPC.js → c-U6YWUAR3.js} +1 -1
- package/dist/m/c-UDCSU5G5.js +2 -0
- package/dist/m/{c-NZMNXVF6.js → c-UDUUJPFZ.js} +1 -1
- package/dist/m/c-VE6ZMYMC.js +1 -0
- package/dist/m/c-VG5XIN4T.js +1 -0
- package/dist/m/c-VHM5XQHK.js +1 -0
- package/dist/m/c-VI5RMSVY.js +1 -0
- package/dist/m/c-VRZN56XY.js +1 -0
- package/dist/m/c-W5MCHEGA.js +1 -0
- package/dist/m/c-WDC5GVKU.js +1 -0
- package/dist/m/c-WWXIDH4O.js +28 -0
- package/dist/m/{c-QIX5BJYN.js → c-XCNTK76U.js} +1 -1
- package/dist/m/c-XMS6DPBR.js +1 -0
- package/dist/m/c-Y5HBBIQ4.js +1 -0
- package/dist/m/{c-5M4YEKCX.js → c-ZVPVXTJF.js} +1 -1
- package/dist/m/c-ZVRKXKM7.js +1 -0
- package/dist/m/{c-HT33EQRN.js → c-ZWIOJGMT.js} +1 -1
- package/dist/m/core/admin-attrs-QHOKPJ7W.js +1 -0
- package/dist/m/core/autosave-HRYGUWV6.js +1 -0
- package/dist/m/core/conflict-notice-6MROJN2L.js +1 -0
- package/dist/m/core/host-permission-FNXVEFNE.js +1 -0
- package/dist/m/core/is-edit-mode-KTWA3O5N.js +1 -0
- package/dist/m/core/{persist-HKHA66IY.js → persist-JFYRHMRJ.js} +1 -1
- package/dist/m/core/recovery-FLTCC2OC.js +1 -0
- package/dist/m/core/save-HQZ4S667.js +1 -0
- package/dist/m/core/save-core-KGQWFUNH.js +1 -0
- package/dist/m/core/snapshot-EGQZNT45.js +1 -0
- package/dist/m/core/unsaved-warning-IDJLD66H.js +1 -0
- package/dist/m/events/index-RN2JNGBV.js +1 -0
- package/dist/m/internals/index-PVXGPUDA.js +1 -0
- package/dist/m/lib/cache-bust-MUMFXZK6.js +1 -0
- package/dist/m/loader-S4I7GKXR.js +1 -0
- package/dist/m/manifest-4C419D67.js +1 -0
- package/dist/m/manifest-edit-B077F288.js +1 -0
- package/dist/m/manifest.json +1555 -1058
- package/dist/m/options/options-EJMS3K24.js +1 -0
- package/dist/m/page/{editor-XUTB2HB2.js → editor-NNJA4OKD.js} +21 -8
- package/dist/m/plugins/{ai-edit-ZQ4CGWIP.js → ai-edit-QN4PMMNL.js} +1 -1
- package/dist/m/plugins/demo-RM5IR6AO.js +1 -0
- package/dist/m/plugins/indicator-URDBBOQO.js +1 -0
- package/dist/m/plugins/live-HFWD4OIH.js +1 -0
- package/dist/m/plugins/{menu-HCKO3DSP.js → menu-3HIEQSI6.js} +2 -2
- package/dist/m/plugins/page-JOKB6XPR.js +2 -0
- package/dist/m/plugins/page-view-NXOJHNW6.js +1 -0
- package/dist/m/plugins/people-SGPJKANK.js +1 -0
- package/dist/m/plugins/{richclay-RC3L2F6X.js → richclay-NRQDSWX6.js} +2 -2
- package/dist/m/plugins/sortable-GWT4PWDV.js +1 -0
- package/dist/m/plugins/source-4ZRSAIYM.js +1 -0
- package/dist/m/plugins/undo-VDA5P7FH.js +1 -0
- package/dist/m/plugins/{upgrade-ZNYODP5Y.js → upgrade-W7FG5VFG.js} +1 -1
- package/dist/m/plugins/upload-WLYKK6TL.js +1 -0
- package/dist/m/plugins/visitor-drafts-LIDY7NH6.js +21 -0
- package/dist/m/plugins/visitor-drafts-owner-ZXCKBZE7.js +1 -0
- package/dist/m/plugins/wire-4N6GYAF6.js +1 -0
- package/dist/m/{reader-core-ILWLXVMP.js → reader-core-DXYCURFF.js} +2 -2
- package/dist/m/sync/live-sync-J7VMYTKS.js +1 -0
- package/dist/m/ui/{index-EVHKMKBL.js → index-3JLVI27O.js} +1 -1
- package/dist/offline-manifest.json +857 -623
- package/dist/page/themes/light-1.css +25 -1
- package/dist/server/core.cjs +115 -24
- package/package.json +1 -1
- package/src/core/boot-phase.js +2 -1
- package/src/core/conflict-download.js +3 -29
- package/src/core/download.js +32 -0
- package/src/core/host-meta.js +18 -0
- package/src/core/save-core.js +8 -4
- package/src/core/save.js +4 -4
- package/src/core/snapshot.js +39 -1
- package/src/lib/autosave-scheduler.js +3 -4
- package/src/page/blocks.js +34 -1
- package/src/page/board-views.js +2 -16
- package/src/page/chart-tables.js +11 -0
- package/src/page/chart.js +6 -10
- package/src/page/checkpoint-proof.js +289 -0
- package/src/page/chrome.js +24 -6
- package/src/page/document-title-dom.js +12 -0
- package/src/page/document-title-runtime.js +15 -1
- package/src/page/document-title.js +4 -1
- package/src/page/editor.js +77 -12
- package/src/page/emoji-data.js +162 -0
- package/src/page/features/board.js +12 -3
- package/src/page/features/chart.js +11 -0
- package/src/page/features/dates.js +180 -0
- package/src/page/features/emoji.js +187 -0
- package/src/page/features/mentions.js +188 -0
- package/src/page/features/registry.js +6 -1
- package/src/page/features/table.js +2 -2
- package/src/page/format-command.js +9 -0
- package/src/page/format-host.js +54 -0
- package/src/page/format-native-commands.js +142 -0
- package/src/page/format-native.js +42 -0
- package/src/page/inline.js +32 -8
- package/src/page/items.js +15 -3
- package/src/page/markdown.js +26 -2
- package/src/page/mention-picker.js +99 -0
- package/src/page/merge.js +1 -1
- package/src/page/projection.js +58 -15
- package/src/page/save-projection.js +39 -0
- package/src/page/save-states.js +1 -1
- package/src/page/schema.js +33 -0
- package/src/page/themes/content.css +25 -1
- package/src/page/themes/light-1.css +25 -1
- package/src/page/view-hooks.js +32 -0
- package/src/page/ybind/binding.js +31 -4
- package/src/page/ybind/marks.js +2 -1
- package/src/page/ybind/provider.js +13 -2
- package/src/page/ybind/recovery-replay.js +362 -4
- package/src/plugins/live.js +37 -1
- package/src/plugins/page.js +117 -3
- package/src/plugins/visitor-drafts/intro.js +2 -1
- package/src/server/checkpoint/index.js +2 -2
- package/src/sync/saved-stream.js +17 -8
- package/dist/m/attrs/refetch-on-save-NWPPXOCZ.js +0 -1
- package/dist/m/attrs/save-freeze-FUP4Q4X3.js +0 -1
- package/dist/m/c-35NBGMZB.js +0 -1
- package/dist/m/c-3IQRECYS.js +0 -1
- package/dist/m/c-4B6H4G5V.js +0 -1
- package/dist/m/c-4FFHZM32.js +0 -1
- package/dist/m/c-66O32MV3.js +0 -28
- package/dist/m/c-7O6AFR65.js +0 -1
- package/dist/m/c-ANQTJ3B5.js +0 -2
- package/dist/m/c-AYVOREBE.js +0 -1
- package/dist/m/c-B2ZXPOS3.js +0 -3
- package/dist/m/c-BMIZKMPV.js +0 -1
- package/dist/m/c-CJZSLMVQ.js +0 -1
- package/dist/m/c-DBE6ORSI.js +0 -1
- package/dist/m/c-EDHUR4MX.js +0 -1
- package/dist/m/c-EY6UOM54.js +0 -1
- package/dist/m/c-F7Y6FLPY.js +0 -1
- package/dist/m/c-FA4DZVTC.js +0 -1
- package/dist/m/c-G2BUZITR.js +0 -1
- package/dist/m/c-GBGWXTX4.js +0 -1
- package/dist/m/c-GHBCCVG4.js +0 -1
- package/dist/m/c-IB52R237.js +0 -1
- package/dist/m/c-IKWNE4R4.js +0 -1
- package/dist/m/c-IU3IYEU6.js +0 -1
- package/dist/m/c-IZ2EBRAJ.js +0 -1
- package/dist/m/c-KR4UW4KW.js +0 -1
- package/dist/m/c-KY3VJGUA.js +0 -8
- package/dist/m/c-LXENEBV7.js +0 -1
- package/dist/m/c-PPOSCAQD.js +0 -1
- package/dist/m/c-QQHEX6HA.js +0 -1
- package/dist/m/c-R7RMANJI.js +0 -9
- package/dist/m/c-RI4NT75Y.js +0 -1
- package/dist/m/c-RUJKSUQW.js +0 -1
- package/dist/m/c-T4VO4OCB.js +0 -1
- package/dist/m/c-TR6RMDQ7.js +0 -3
- package/dist/m/c-UKHTLWUW.js +0 -1
- package/dist/m/c-UNN7LWCT.js +0 -1
- package/dist/m/c-V7PZZRG7.js +0 -1
- package/dist/m/c-VL52ADDR.js +0 -1
- package/dist/m/c-WWDBYXLK.js +0 -1
- package/dist/m/c-XNNW2CWK.js +0 -1
- package/dist/m/c-Z4VRC7GU.js +0 -7
- package/dist/m/c-Z6K52OLP.js +0 -19
- package/dist/m/c-ZDY2MDAA.js +0 -21
- package/dist/m/core/admin-attrs-VGNLAUDK.js +0 -1
- package/dist/m/core/autosave-E4PEFPZ6.js +0 -1
- package/dist/m/core/conflict-notice-VQ6Y64PH.js +0 -1
- package/dist/m/core/host-permission-XN3K2IW3.js +0 -1
- package/dist/m/core/is-edit-mode-JXHDVGUL.js +0 -1
- package/dist/m/core/recovery-TBBSICE2.js +0 -1
- package/dist/m/core/save-WUCHTQBE.js +0 -1
- package/dist/m/core/save-core-FJVHT5M3.js +0 -1
- package/dist/m/core/snapshot-F3SWDZMM.js +0 -1
- package/dist/m/core/unsaved-warning-STKBHE6G.js +0 -1
- package/dist/m/events/index-23DPTUT4.js +0 -1
- package/dist/m/internals/index-WOVAP3RU.js +0 -1
- package/dist/m/lib/cache-bust-CGWT6ZJI.js +0 -1
- package/dist/m/loader-HXX6YNH5.js +0 -1
- package/dist/m/manifest-F22DEDAC.js +0 -1
- package/dist/m/manifest-edit-C3C7376B.js +0 -1
- package/dist/m/options/options-2LH76JQ3.js +0 -1
- package/dist/m/plugins/demo-ZIBFAA3R.js +0 -1
- package/dist/m/plugins/indicator-PV4YW2ID.js +0 -1
- package/dist/m/plugins/live-NUTTXSBS.js +0 -1
- package/dist/m/plugins/page-KSUH7G6J.js +0 -2
- package/dist/m/plugins/page-view-W73OW7WI.js +0 -1
- package/dist/m/plugins/people-AJJ32YCG.js +0 -1
- package/dist/m/plugins/sortable-YRMQX3ZU.js +0 -1
- package/dist/m/plugins/source-KHK5UUSK.js +0 -1
- package/dist/m/plugins/undo-OF2L3CXU.js +0 -1
- package/dist/m/plugins/upload-XSGNILUY.js +0 -1
- package/dist/m/plugins/visitor-drafts-XK5GW55Q.js +0 -21
- package/dist/m/plugins/visitor-drafts-owner-KSSH75EV.js +0 -1
- package/dist/m/plugins/wire-ZWVWKF76.js +0 -1
- package/dist/m/sync/live-sync-4AUVXVJU.js +0 -1
- /package/dist/m/plugins/{richclay-RC3L2F6X.js.LEGAL.txt → richclay-NRQDSWX6.js.LEGAL.txt} +0 -0
package/dist/m/c-KY3VJGUA.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import{A as Ae,D as Yt,E as Vt,F as oe,G as ht,H as se,P as jo,R as Bo,S as Ee,T as Ro,a as To,b as $o,c as Do,d as kn,e as _o,f as bn,g as Se,h as Oe,i as Zt,j as Me,o as te,q as No,r as ee,t as st,u as wn,v as Ct,w as Ce,x as Lo,y as ne}from"./c-Y6USGTS5.js";import{a as Ie,c as Zo}from"./c-EDHUR4MX.js";import{c as Go,e as Xo,f as Te,g as Qo}from"./c-54RCDCBU.js";import{A as F,B as vn,C as qo,D as Sn,E as Jo,F as Wo,a as Ko,c as Po,e as re,f as zo,i as Fo,l as wt,o as xn,q as Yo,r as Vo,t as Ho,u as Uo,y as _t,z as Y}from"./c-TR6RMDQ7.js";import{$ as yn,A as kt,B as V,C as bt,D as X,E as R,F as xe,G as ko,H as bo,J as Ft,O as wo,P as ve,Q as gn,R as xo,S as vo,T as So,U as Oo,V as Mo,W as Co,X as Ao,b as q,d as hn,da as Eo,f as we,g as fo,ga as Io,h as mn,ha as tt,j as po,l as ho,m as S,o as mo,p as go,t as yo,y as Dt}from"./c-66O32MV3.js";import{a as ie}from"./c-4L3BTFRK.js";import{a as Qt,b as uo,c as ot,d as be}from"./c-5V3MOVJT.js";var Cn="page-origins",Cr="page-undo-overlap-repair",ts=(e,t)=>JSON.stringify(["span",e,t]),An=(e,t)=>JSON.stringify(["alias",e,t]),es=(e,t)=>JSON.stringify(["boundary",e,t]),Ar=["copy","removed","restore"],ns=/^(?:0|[1-9]\d*)$/,Nt=(e,t)=>`${e}.${t}`,H=e=>Number.isSafeInteger(e)&&e>=0,Er=e=>Number.isSafeInteger(e)&&e>0,Ir=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),$e=e=>new Error(`Conflicting immutable origin record: ${e}`),Tr=e=>{if(typeof e!="string")return!1;let t=e.indexOf(".");if(t<1||t===e.length-1)return!1;let n=e.slice(0,t),o=e.slice(t+1);return ns.test(n)&&ns.test(o)&&H(Number(n))&&H(Number(o))},On=e=>{if(!Ir(e))return null;for(let t of Object.keys(e))if(t!=="blockId"&&t!=="kind"&&t!=="recoveryOf")return null;return typeof e.blockId!="string"||!e.blockId||!Ar.includes(e.kind)||e.recoveryOf!==void 0&&!Tr(e.recoveryOf)?null:e.recoveryOf===void 0?{blockId:e.blockId,kind:e.kind}:{blockId:e.blockId,kind:e.kind,recoveryOf:e.recoveryOf}},$r=(e,t)=>e.blockId===t.blockId&&e.kind===t.kind&&e.recoveryOf===t.recoveryOf,Dr=e=>{if(typeof e!="string"||e.charCodeAt(0)!==91)return null;let t;try{t=JSON.parse(e)}catch{return null}return!Array.isArray(t)||t.length!==3||t[0]!=="span"&&t[0]!=="alias"&&t[0]!=="boundary"?null:H(t[1])&&H(t[2])?t:null};function ce(e){let t=new Map,n=new Map,o=new Map,s=(p,m)=>{let g=0,y=p.length;for(;g<y;){let x=g+y>>1;p[x].clock<m?g=x+1:y=x}return g},r=(p,m)=>{let g=Dr(p);if(!g)return;let[y,x,C]=g;if(y==="alias"){m&&H(m.sourceClient)&&H(m.sourceClock)?n.set(Nt(x,C),{client:m.sourceClient,clock:m.sourceClock}):n.delete(Nt(x,C));return}if(y==="boundary"){let A=On(m);A?o.set(Nt(x,C),A):o.delete(Nt(x,C));return}let T=t.get(x)??[],L=s(T,C);T[L]?.clock===C&&T.splice(L,1),m&&Er(m.length)&&H(m.sourceClient)&&H(m.sourceClock)&&T.splice(s(T,C),0,{client:x,clock:C,length:m.length,sourceClient:m.sourceClient,sourceClock:m.sourceClock}),T.length?t.set(x,T):t.delete(x)};for(let[p,m]of e)r(p,m);let i=p=>{for(let m of p.keysChanged)r(m,e.get(m))};e.observe(i);let c=p=>{let m=n.get(Nt(p.client,p.clock));if(m)return{client:m.client,clock:m.clock};let g=t.get(p.client);if(!g)return{client:p.client,clock:p.clock};let y=0,x=g.length-1,C=-1;for(;y<=x;){let A=y+x>>1;g[A].clock<=p.clock?(C=A,y=A+1):x=A-1}if(C<0)return{client:p.client,clock:p.clock};let T=g[C],L=p.clock-T.clock;return L>=T.length?{client:p.client,clock:p.clock}:{client:T.sourceClient,clock:T.sourceClock+L}},f=p=>{if(!p||!H(p.client)||!H(p.clock))return null;let m=Nt(p.client,p.clock),g=new Set;for(;!g.has(m);){g.add(m);let x=n.get(m);if(!x)break;m=Nt(x.client,x.clock)}if(g.has(m)&&n.has(m))return null;let y=o.get(m);return y?{...y}:null},h=(p,m,g)=>{let y=ts(p,m),x=e.get(y);if(x!==void 0&&(x.length!==g.length||x.sourceClient!==g.sourceClient||x.sourceClock!==g.sourceClock))throw $e(y);let C=t.get(p)??[],T=s(C,m);for(let L of[C[T-1],C[T]])if(L&&L.clock!==m&&L.clock<m+g.length&&m<L.clock+L.length)throw $e(y);x===void 0&&e.set(y,g)};return{origins:e,resolve:c,recordSpans:p=>{let m=[],g=()=>{if(!m.length)return;let y=m[0],x={length:m.length,sourceClient:y.source.client,sourceClock:y.source.clock};if(!H(x.sourceClock+x.length-1))throw new Error(`Unsafe origin span: ${ts(y.dest.client,y.dest.clock)}`);h(y.dest.client,y.dest.clock,x),m.length=0};for(let y of p){if(!y?.dest||!y?.source)throw new Error("Invalid origin destination");let x=y.dest,C=y.source;if(!H(x.client)||!H(x.clock)||!H(C.client)||!H(C.clock))throw new Error("Invalid origin destination");let T=c(C),L=m[m.length-1];L&&L.dest.client===x.client&&L.dest.clock+1===x.clock&&L.source.client===T.client&&L.source.clock+1===T.clock?m.push({dest:x,source:T}):(g(),m.push({dest:x,source:T}))}g()},recordAlias:(p,m)=>{if(!p||!m||!H(p.client)||!H(p.clock)||!H(m.client)||!H(m.clock))throw new Error("Invalid origin destination");let g=c(m),y=An(p.client,p.clock),x=e.get(y);if(x!==void 0&&(x.sourceClient!==g.client||x.sourceClock!==g.clock))throw $e(y);x===void 0&&e.set(y,{sourceClient:g.client,sourceClock:g.clock})},recordBoundary:(p,m)=>{if(!p||!H(p.client)||!H(p.clock))throw new Error("Invalid origin destination");let g=On(m);if(!g)throw new Error(`Invalid boundary record: ${es(p.client,p.clock)}`);let y=es(p.client,p.clock),x=e.get(y);if(x===void 0){e.set(y,g);return}let C=On(x);if(!C||!$r(C,g))throw $e(y)},boundaryOf:f,get size(){return e.size},dispose(){e.unobserve(i)}}}function Pc(e,t,n){let o=[],s=0;for(let r=e._start;r&&s<n;r=r.right){if(r.deleted||!r.countable)continue;let i=s;if(s+=r.length,s<=t)continue;let c=Math.max(0,t-i),f=Math.min(r.length,n-i);for(let h=c;h<f;h++)o.push({client:r.id.client,clock:r.id.clock+h})}return o}var _r=(e,t,n)=>e.some(o=>o.actor===t||o.client!==n.client||n.clock<o.clock||n.clock>=o.clock+o.length?!1:o.sv.some(([s,r])=>s===n.client&&r>n.clock)),Nr=(e,t)=>{let n=0;for(let o=e._start;o;o=o.right)if(!(o.deleted||!o.countable)){if(o.id.client===t.client&&o.id.clock<=t.clock&&t.clock<o.id.clock+o.length)return n+t.clock-o.id.clock;n+=o.length}return null},Lr=(e,t)=>{let n=[];for(let s of t){let r=Nr(e.flow,s);r!==null&&n.push(r)}n.sort((s,r)=>s-r);let o=[];for(let s of n){let r=o[o.length-1];r&&s<=r[1]?r[1]=Math.max(r[1],s+1):o.push([s,s+1])}for(let s=o.length-1;s>=0;s--){let[r,i]=o[s];i>r&&e.flow.delete(r,i-r)}};function zc(e,t,n=ce(e.origins),o=()=>[]){let s=r=>{if(r.origin!==t||!t.currStackItem)return;let i=[],c=[],f=[],h=o(e.gone);Do(r,t.currStackItem.deletions,a=>{if(!(a instanceof Ce)||a.parent!==e.flow||!a.countable||!a.redone)return;let l=a.content instanceof st&&a.content.embed?.b!==void 0;for(let u=0;u<a.length;u++){let p={client:a.id.client,clock:a.id.clock+u},m=n.resolve(p),g={client:a.redone.client,clock:a.redone.clock+u},y=te(e.ydoc.store,g);for(;y instanceof Ce&&y.redone;)g={client:y.redone.client,clock:y.redone.clock+g.clock-y.id.clock},y=te(e.ydoc.store,g);if(!(!(y instanceof Ce)||y.deleted)&&!(g.clock<(r.beforeState.get(g.client)??0))){if(!l&&_r(h,e.ydoc.clientID,p)){f.push(g);continue}(l?c:i).push({dest:g,source:m})}}}),(i.length||c.length)&&e.ydoc.transact(()=>{i.length&&n.recordSpans(i);for(let a of c)n.recordAlias(a.dest,a.source)},Cn),f.length&&e.ydoc.transact(()=>Lr(e,f),Cr)};return e.ydoc.on("beforeObserverCalls",s),()=>e.ydoc.off("beforeObserverCalls",s)}var Hc=typeof TextEncoder=="function"?new TextEncoder:null;var jr=(e,t)=>e.length===t.length&&e.every((n,o)=>n===t[o]);function os(e,t,n=null){let o=n?.mergeUpdatesV2??ee,s=o([e]);return jr(s,o([s,t]))}var En=e=>To(e),At=e=>$o(e),De=12*1024,_e=e=>Qt.exec(e)?.[1]??e;function Qc(e){return{v:1,g:0,y:{seed:En(Oe(e))}}}var Q=class extends Error{constructor(t,n){super(n),this.name="YDecodeError",this.code=t}};function Rr(e){if(e?.v!==1||!e.y||typeof e.y!="object"||Array.isArray(e.y))throw new Q("invalid-value","Expected a version 1 Yjs page value");let t=new Map,n=new Set;for(let[o,s]of Object.entries(e.y)){if(typeof s!="string")throw new Q("invalid-update",`Invalid Yjs update: ${o}`);let r=Qt.exec(o);if(!r){n.add(o);continue}let i=Number(r[2]),c=Number(r[3]);if(!Number.isSafeInteger(i)||!Number.isSafeInteger(c)||c<1||i>=c)throw new Q("invalid-update",`Invalid Yjs update part: ${o}`);let f=t.get(r[1])??{count:c,indices:new Set};if(f.count!==c||f.indices.has(i))throw new Q("invalid-update",`Conflicting Yjs update parts: ${r[1]}`);f.indices.add(i),t.set(r[1],f)}for(let[o,s]of t){if(n.has(o))throw new Q("invalid-update",`Conflicting Yjs update forms: ${o}`);if(s.indices.size!==s.count)throw new Q("incomplete-update",`Incomplete Yjs update: ${o}`)}return ot(e.y)}function Br(e,{strict:t=!1}={}){let n=t?Rr(e):ot(e.y),o=new bn;try{for(let[s,r]of n){let i=t?r.replace(/[\t\n\f\r ]/g,""):r;if(t&&!uo.test(i))throw new Q("invalid-update",`Invalid base64 in Yjs update: ${s}`);Se(o,At(i),ne)}if(t&&(o.store.pendingStructs||o.store.pendingDs))throw new Q("unresolved-update","Yjs page updates have missing prerequisites");return o}catch(s){throw o.destroy(),t&&!(s instanceof Q)?new Q("invalid-update",`Invalid Yjs page update: ${s.message}`):s}}var ss=typeof TextEncoder=="function"?new TextEncoder:null,Kr=e=>ss?ss.encode(e).length:e.length*2,Pr=(e,t)=>_o(kn(e.store),kn(t.store)),zr=(e,t)=>{if(e.size!==t.size)return!1;for(let[n,o]of e)if(t.get(n)!==o)return!1;return!0};function Zc({store:e,ydoc:t,compact:n={},setTimer:o=setTimeout,clearTimer:s=clearTimeout,onStopped:r=()=>{},stats:i={applied:0,offered:0,compactions:0}}){let c=ot(e.value.y),f=new Set,h=null,a=w=>{h||(h=w,r(w))},l=!c.some(([w])=>w[0]==="m"),u=0,p=t.clientID.toString(36),m=w=>`${w}${p}-${(u++).toString(36)}`,g=null,y=e.value.g,x=new Set,C=(w,v)=>{if(v.length<=De)return[[w,v]];let D=Math.ceil(v.length/De);return Array.from({length:D},(E,d)=>[`${w}.${d}.${D}`,v.slice(d*De,(d+1)*De)])},T=(w,v)=>{l=!0,f.add(w),x.add(w);let D=C(w,En(v));e.handle.update(E=>{for(let[d,k]of D)E.y[d]=k})};for(let[w]of c)f.add(w);let L=(w,v)=>{h||v===ne||v===Cn||T(m("u"),w)};t.on("updateV2",L);let A=(w,v)=>{h||f.has(w)||(l=!0,f.add(w),i.applied++,Se(t,At(v),ne))},_=!1,P=!1,G=(w,v)=>{_||=w,P||=v,!g&&(g=o(()=>{g=null,_&&ct(),zt()},0))},Z=()=>{ct(),zt()};function ct(){if(h)return!1;let w=e.value.y,v=new bn;for(let[,b]of ot(w))Se(v,At(b),ne);let D=Me(v),E=Zt(Me(t)),d=Zt(D);if(zr(E,d)&&Pr(t,v))return v.destroy(),_=!1,P=!1,!1;let k=Oe(t,D);return v.destroy(),i.offered++,T(m("r"),k),_=!1,P=!1,!0}let pt={keys:32,room:3840*1024,...n},$=null,Ot=0,j=256,et=new Map,lt=w=>e.handle.update(v=>{for(let D of w)delete v.y[D]}),Jt=(w,v)=>Object.keys(w).filter(D=>v.has(_e(D))),Mt=(w,v)=>{let D=e.value.y??{};lt(v.filter(E=>E in D&&D[E]===w[E]))};function gt(){let w=e.authoritative.y??{},v=e.value.y??{};for(let k of x)k in v||x.delete(k);let D=$?[...$.parts.map(([k])=>k),...$.inputs.keys()]:[],E=new Set([...Object.keys(w),...x,...D]);for(let k of f)E.has(k)||f.delete(k);let d=new Map(ot(w));for(let[k,b]of et)(!E.has(k)||d.get(k)!==b.value)&&et.delete(k)}function Pt(w,v,D,E){let d=et.get(w);return d&&d.value!==v&&(et.delete(w),d=null),d||(et.size>=j&&et.delete(et.keys().next().value),d={value:v,folds:new Map},et.set(w,d)),d.folds.has(D)||d.folds.set(D,os(E,At(v))),d.folds.get(D)}let ye=(w,v)=>{for(let[D,E]of v.held)if(w[D]!==void 0&&w[D]!==E)return!1;return!0},ke=w=>{let v=At(w.merged);for(let[D,E]of w.inputs)if(E!==null&&!Pt(D,E,w.key,v))return!1;return!0};function un(w){let v=$,D=be({v:1,y:w}).y,E=v.parts.filter(([d,k])=>w[d]===k&&D[d]===k);return E.length!==v.parts.length?e.pending.length?!1:($=null,E.length&&Mt(w,E.map(([d])=>d)),Ot=ot(w).length+pt.keys,gt(),!0):e.pending.length||!ye(w,v)||!ke(v)?!1:($=null,Mt(w,Jt(w,v.inputs)),gt(),!0)}function dn(w,v,D){let E=v.filter(([O])=>O[0]==="m"),d=new Map(v),k=new Map(E),b=O=>{let B=k.get(O);return typeof B=="string"&&k.set(O,ee([At(B)])),k.get(O)},M=(O,B,N)=>Pt(O,B,N,b(N)),I=new Set;for(let[O,B]of v)if(!(!D&&O[0]!=="m")){for(let[N]of E)if(!(N===O||I.has(N)||!M(O,B,N))&&!(O[0]==="m"&&O<N&&M(N,d.get(N),O))){I.add(O);break}}return I.size?(Mt(w,Jt(w,I)),!0):!1}function zt(){if(h||!l||e.value.g!==y)return!1;let w=e.authoritative.y;if($)return un(w);let v=ot(w),D=v.length>Math.max(pt.keys,Ot);if(!D&&v.filter(([N])=>N[0]==="m").length<2)return!1;if(dn(w,v,D))return gt(),!0;if(!D)return!1;let E=En(ee(v.map(([,N])=>At(N)))),d=m("m"),k=C(d,E),b={...e.value,y:{...e.value.y}};for(let[N,yt]of k)b.y[N]=yt;if(Kr(JSON.stringify(b))>pt.room)return Ot=v.length+pt.keys,!1;let M=be({v:1,y:w}).y,I=Object.keys(w).filter(N=>!(N in M)).map(_e).filter(N=>N[0]==="m"),O=new Map(v);for(let N of I)O.set(N,null);let B=new Map;for(let N of Jt(w,O))O.get(_e(N))!==null&&B.set(N,M[N]??w[N]);return $={key:d,parts:k,merged:E,inputs:O,held:B},f.add(d),e.handle.update(N=>{for(let[yt,z]of k)N.y[yt]=z}),i.compactions++,!0}let at=w=>{let v=new Set;for(let[,D]of ot(w??{}))for(let E of Zt(No(At(D))).keys())v.add(E);return v},fn=new Map(c),Wt=w=>{let v=at(w),D=[...Zt(Me(t)).keys()];return!v.size||!D.length||D.some(E=>v.has(E))?!0:ot(w??{}).some(([E,d])=>fn.get(E)===d)},Gt=e.onRebase(w=>{if(h)return;let v=w.source==="remote"&&w.frame?w.frame.ops:null,D=v&&v.every(E=>E.path[0]==="y"&&E.path.length===2&&!Qt.test(E.path[1]));if(!D&&w.cause!=="refused"&&!Wt(w.next.y)){a("lineage");return}if(D)for(let E of v)E.op==="set"&&A(E.path[1],E.value);else for(let[E,d]of ot(w.next.y??{}))A(E,d);gt(),G(w.source!=="remote"||!v,w.source!=="remote")}),Xt=e.onDelivery(w=>{if(w.phase!=="refused")return;if(w.code!=="too-large"||h){gt();return}a("too-large");let v=e.authoritative.y??{},D=be({v:1,y:v}).y,E=Object.keys(e.value.y??{}).filter(k=>!(k in v)),d=Object.keys(v).filter(k=>Qt.test(k)&&!(k in D)&&_e(k).slice(1).startsWith(`${p}-`));(E.length||d.length)&<([...E,...d]),gt()});return{known:f,stats:i,settle:Z,reconcile:ct,get reconcilePending(){return P},get stopped(){return h},_diagnostics:()=>({known:f.size,cover:et.size,fold:$?$.parts.length:0,generation:y}),compact:zt,dispose(){Gt(),Xt(),t.off("updateV2",L),g&&s(g)}}}var rs=new WeakMap;function Ne(e){let t=rs.get(e);if(t)return t;t={};for(let[n,o]of X(e.attrs.cols).entries()){let s=[];e.forEach(r=>{n<r.childCount&&s.push(r.child(n).textContent.trim())}),t[o]=vo(e.attrs.cols[o].kind,s)}return rs.set(e,t),t}var sl=Object.freeze({text:"Aa",number:"#",date:"\u{1F4C5}"}),rl=Object.freeze({text:"Text",number:"Number",date:"Date"});var Le="page-history-intent",Fr=500,Yr=(e,t)=>{let n=e.resolve(t);return n.depth?n.node(1).attrs.id:null},Vr=e=>(e.storedMarks??e.selection.$from.marks()).map(t=>`${t.type.name}:${JSON.stringify(t.attrs)}`).sort().join(",");function Tn(e,t,n,o){return{kind:"insert",blockId:Yr(e.doc,t),from:t,end:t+o.length,replaced:t!==n,text:o,marks:Vr(e),at:Date.now()}}function al(e,t){return!e||!t||e.kind!==t.kind?!1:t.kind==="compose"?e.id===t.id:e.blockId!==t.blockId||t.at-e.at>Fr?!1:t.kind==="insert"?!t.replaced&&t.from===e.end&&t.marks===e.marks&&!(/\s$/.test(e.text)&&/^\S/.test(t.text)):t.direction===e.direction&&(t.direction<0?t.to===e.from:t.from===e.from)}var Hr={deleteContentBackward:-1,deleteContentForward:1},In=new WeakMap,Ur=1e3,$n="page-derived";function qr(e){let t=In.get(e)??null;return In.delete(e),t}function Jr(e,t){if(!t||e.before!==t.doc||Date.now()-t.at>Ur||e.getMeta(Po)||e.steps.length!==1)return null;let n=e.steps[0];if(n.slice?.size!==0||n.from===n.to)return null;let o=e.before.resolve(n.from),s=e.before.resolve(n.to);return!o.parent.isTextblock||!o.sameParent(s)?null:{kind:"delete",blockId:o.depth?o.node(1).attrs.id:null,direction:t.direction,from:n.from,to:n.to,at:t.at}}function ul(e,t=null){let n=t?qr(t):null,o=e.filter(i=>!i.getMeta($n));if(o.length!==1)return null;let s=o[0],r=s.getMeta("composition");return r!=null?{kind:"compose",id:r,at:Date.now()}:s.getMeta(Le)??Jr(s,n)}function dl(){return new q.Plugin({props:{handleTextInput(e,t,n,o,s){return e.dispatch(s().setMeta(Le,Tn(e.state,t,n,o))),!0},handleDOMEvents:{beforeinput(e,t){let n=Hr[t.inputType];return n&&In.set(e,{direction:n,at:Date.now(),doc:e.state.doc}),!1}}}})}var{Plugin:Wr,TextSelection:Gr}=q,Dn=S.nodes;var as=(e,t)=>{let n=null;return e.forEach((o,s)=>{!n&&o.type===Dn.table&&o.attrs.id===t&&(n={node:o,pos:s})}),n};function Et(e,t){if(!t)return null;let n=as(e,t.table);if(!n)return null;let o=[];n.node.forEach(p=>o.push(p.attrs.id));let s=X(n.node.attrs.cols),r=[o.indexOf(t.anchor[0]),o.indexOf(t.head[0])],i=[s.indexOf(t.anchor[1]),s.indexOf(t.head[1])];if(r.includes(-1)||i.includes(-1))return null;let c=Math.min(...r),f=Math.max(...r),h=Math.min(...i),a=Math.max(...i),l=[],u=n.pos+1;return n.node.forEach((p,m,g)=>{if(g>=c&&g<=f){let y=[],x=u+1;p.forEach((C,T,L)=>{L>=h&&L<=a&&y.push({cell:C,pos:x}),x+=C.nodeSize}),l.push(y)}u+=p.nodeSize}),{...n,top:c,bottom:f,left:h,right:a,cells:l}}var le=(e,t)=>{let n=e.resolve(t);for(let o=n.depth;o>0;o--)if(n.node(o).type===Dn.table_cell&&o>=3)return{table:n.node(o-2).attrs.id,row:n.node(o-1).attrs.id,col:n.node(o).attrs.col,start:n.start(o)};return null};function je(e,t,n){let o=le(e.state.doc,t),s=le(e.state.doc,n);if(!o||!s||o.table!==s.table)return!1;let r={table:o.table,anchor:[o.row,o.col],head:[s.row,s.col]},i=e.state.tr.setSelection(Gr.create(e.state.doc,s.start)).setMeta(Y,r);e.dispatch(i);let c=Et(e.state.doc,r),f=c?(c.bottom-c.top+1)*(c.right-c.left+1):0;return _t(e,`${f} ${f===1?"cell":"cells"} selected`),!0}function vl(e,t,n,o){let s=e.state.doc.nodeAt(t);if(s?.type!==Dn.table||!s.childCount)return!1;let r=s.childCount-1,i=s.child(0).childCount-1,c=(f,h)=>{let a=t+1;for(let l=0;l<f;l++)a+=s.child(l).nodeSize;a++;for(let l=0;l<h;l++)a+=s.child(f).child(l).nodeSize;return a+1};return n==="row"?je(e,c(o,0),c(o,i)):je(e,c(0,o),c(r,o))}var Xr=new Set(["Shift","Control","Alt","Meta","CapsLock"]),Qr=e=>/[\t\n\r"]/.test(e)?`"${e.replace(/"/g,'""')}"`:e;function Zr(e,t){let n=e.cells.map(r=>r.map(({cell:i})=>Qr(Dt(xe(i)))).join(" ")).join(`
|
|
2
|
-
`),o=t.createElement("table"),s=o.appendChild(t.createElement("tbody"));for(let r of e.cells){let i=s.appendChild(t.createElement("tr"));for(let{cell:c}of r){let f=i.appendChild(t.createElement("td"));f.dataset.col=c.attrs.col,f.append(Uo.serializeFragment(c.content,{document:t}))}}return{text:n,html:o.outerHTML}}function is(e,t){let n=Et(e.doc,Y.getState(e));if(!n)return!1;if(t){let o=e.tr;for(let s of[...n.cells].reverse())for(let{cell:r,pos:i}of[...s].reverse())r.content.size&&o.delete(i+1,i+r.nodeSize-1);o.setMeta(Y,Y.getState(e)),t(F(o))}return!0}var cs=(e,t,n)=>{let{text:o,html:s}=Zr(t,n.dom.ownerDocument);e.clipboardData.setData("text/plain",o),e.clipboardData.setData("text/html",s),e.preventDefault()},ti=(e,t)=>(n,o,s)=>{let r=Y.getState(n),i=Et(n.doc,r);if(!i||!s)return!1;let c=[],f=X(i.node.attrs.cols);i.node.forEach(l=>c.push(l.attrs.id));let h=Math.max(0,Math.min(c.length-1,c.indexOf(r.head[0])+e)),a=Math.max(0,Math.min(f.length-1,f.indexOf(r.head[1])+t));return o&&o(n.tr.setMeta(Y,{...r,head:[c[h],f[a]]})),!0},ls=(e,t)=>{let n=t.target?.closest?.("td");if(!n||!e.dom.contains(n))return null;try{return e.posAtDOM(n,0)}catch{return null}};function Sl(){let e=null;return new Wr({key:Y,state:{init:()=>null,apply(t,n,o,s){let r=t.getMeta(Y);return r!==void 0?r:!n||t.selectionSet||t.docChanged&&!t.getMeta(Ae)?null:Et(s.doc,n)?n:null}},props:{attributes:t=>Y.getState(t)?{class:"has-cell-rect"}:{},createSelectionBetween:t=>Y.getState(t.state)?t.state.selection:null,decorations(t){let n=Et(t.doc,Y.getState(t));return n?hn.DecorationSet.create(t.doc,n.cells.flat().map(({cell:o,pos:s})=>hn.Decoration.node(s,s+o.nodeSize,{class:"is-cell-selected"}))):null},handleKeyDown(t,n){let o=t.state;if(!Y.getState(o))return!1;if(n.key==="Escape")return t.dispatch(o.tr.setMeta(Y,null)),!0;if(n.key==="Backspace"||n.key==="Delete")return is(o,t.dispatch);if(n.shiftKey){let s={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]}[n.key];if(s)return ti(...s)(o,t.dispatch,t)}return Xr.has(n.key)||(n.metaKey||n.ctrlKey)&&(n.key==="a"||n.key==="c"||n.key==="x"||n.key==="v")||t.dispatch(o.tr.setMeta(Y,null)),!1},handleDOMEvents:{mousedown(t,n){if(n.button!==0)return!1;!n.shiftKey&&Y.getState(t.state)&&t.dispatch(t.state.tr.setMeta(Y,null));let o=ls(t,n);if(o===null)return!1;if(n.shiftKey){let f=Y.getState(t.state),h=(f&&ei(t.state.doc,f))??t.state.selection.$anchor.pos;return le(t.state.doc,h)?(n.preventDefault(),je(t,h,o)):!1}let s=t.dom.ownerDocument,r=o,i=f=>{let h=ls(t,f);if(h===null)return;let a=le(t.state.doc,r),l=le(t.state.doc,h);if(!a||!l||a.table!==l.table)return;let u=Y.getState(t.state);a.row===l.row&&a.col===l.col&&!u||u&&u.head[0]===l.row&&u.head[1]===l.col||(f.preventDefault(),je(t,r,h))},c=()=>{s.removeEventListener("mouseover",i),s.removeEventListener("mouseup",c),e=null};return e?.(),e=c,s.addEventListener("mouseover",i),s.addEventListener("mouseup",c),!1},copy(t,n){let o=Et(t.state.doc,Y.getState(t.state));return!o||!n.clipboardData?!1:(cs(n,o,t),!0)},cut(t,n){let o=Et(t.state.doc,Y.getState(t.state));return!o||!n.clipboardData?!1:(cs(n,o,t),is(t.state,t.dispatch),!0)}}},view:()=>({destroy:()=>e?.()})})}function ei(e,t){let n=as(e,t.table),o=null;return n?.node.forEach((s,r)=>{if(s.attrs.id!==t.anchor[0])return;let i=n.pos+1+r+1;s.forEach(c=>{c.attrs.col===t.anchor[1]&&(o=i+1),i+=c.nodeSize})}),o}var us=e=>{let t=Et(e.doc,Y.getState(e));return t?{row:t.top,cell:t.left,rows:t.bottom-t.top+1,cols:t.right-t.left+1}:null};var ds=new WeakMap;var fs=Object.freeze({row:Object.freeze(["alive","pos"]),col:Object.freeze(["alive","name","kind","width","pos"])}),hs=["name","kind","width","pos"],ni=new Set(["kind","width"]),Lt=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),_n=e=>typeof e=="string"&&e.length>0&&!["__proto__","constructor","prototype"].includes(e),ae=e=>{throw new Q("unsupported-content",`Unsupported table field: ${e}`)},ms=e=>e===null||typeof e!="object"?e:JSON.parse(JSON.stringify(e)),xt=(e,t,n,o)=>JSON.stringify([e,t,n,o]);function oi(e){if(typeof e=="string")return!0;if(!Lt(e)||Object.keys(e).sort().join(",")!=="c,m"||typeof e.c!="string"||!Array.isArray(e.m)||!e.m.every(Array.isArray))return!1;let t=Eo(e.m,e.c.length);return t?t.every((n,o)=>{if(typeof n!="string")return!1;if(n.startsWith("@"))return n===Ao&&e.c[o]===Co;try{return yo(S,n),!0}catch{return!1}}):!1}var si=(e,t)=>e==="alive"?typeof t=="boolean":e==="width"?t===null||typeof t=="number"&&Number.isFinite(t)&&t>0:e==="kind"&&t===null||typeof t=="string";function ps(e,t){if(Object.keys(e).length)return;let[n]=Object.keys(t).sort((o,s)=>{let r=t[o].pos??"",i=t[s].pos??"";return r!==i?r<i?-1:1:o<s?-1:o>s?1:0});n&&(e[n]=t[n])}function Re(e,t=null,n=null){let o=new Map,s=new Map,r=new Map;for(let[a,l]of e){let u;try{u=JSON.parse(a)}catch{ae(a)}(!Array.isArray(u)||u.length!==4)&&ae(a);let[p,m,g,y]=u;if((!_n(p)||!_n(g))&&ae(a),m==="cell"?(!_n(y)||!oi(l))&&ae(a):(!Object.hasOwn(fs,m)||!fs[m].includes(y)||!si(y,l))&&ae(a),p!==t)continue;if(m==="cell"){let T=r.get(g)??new Map;T.set(y,l),r.set(g,T);continue}let x=m==="row"?o:s,C=x.get(g)??{};C[y]=l,x.set(g,C)}let i={...Lt(n?.cols)?n.cols:{}},c={...Lt(n?.rows)?n.rows:{}},f={},h={};for(let[a,l]of s){let u=Lt(i[a])?{...i[a]}:{};Object.hasOwn(u,"pos")||(u.pos=""),Object.hasOwn(u,"name")||(u.name="");for(let p of hs)Object.hasOwn(l,p)&&(l[p]===null?delete u[p]:u[p]=l[p]);if(l.alive===!1||!Object.hasOwn(i,a)&&l.alive!==!0){l.alive===!1&&(f[a]=u),delete i[a];continue}i[a]=u}for(let a of new Set([...o.keys(),...r.keys()])){let l=o.get(a)??{},u={pos:"",cells:{},...Lt(c[a])?c[a]:{}};Object.hasOwn(l,"pos")&&(u.pos=l.pos);let p=r.get(a);if(p&&(u.cells={...Lt(u.cells)?u.cells:{},...Object.fromEntries([...p].map(([m,g])=>[m,ms(g)]))}),l.alive===!1||!Object.hasOwn(c,a)&&l.alive!==!0){l.alive===!1&&(h[a]=u),delete c[a];continue}c[a]=u}return ps(i,f),ps(c,h),{cols:i,rows:c}}var Be=(e,t)=>e?.[t]??(ni.has(t)?null:"");function ri(e,t,n,o,s){let r=[],i=(u,p)=>t.has(u)?t.get(u):p,c=(u,p)=>r.push([u,ms(p)]),f=o?.cols??{},h=s?.cols??{},a=o?.rows??{},l=s?.rows??{};for(let u of new Set([...Object.keys(f),...Object.keys(h)])){let p=f[u],m=h[u];if(!m){p&&c(xt(e,"col",u,"alive"),!1);continue}(!p||i(xt(e,"col",u,"alive"),!0)===!1)&&c(xt(e,"col",u,"alive"),!0);for(let g of hs){let y=xt(e,"col",u,g),x=p?Be(p,g):i(y,Be(n?.cols?.[u],g));tt(x)!==tt(Be(m,g))&&c(y,Be(m,g))}}for(let u of new Set([...Object.keys(a),...Object.keys(l)])){let p=a[u],m=l[u];if(!m){p&&c(xt(e,"row",u,"alive"),!1);continue}(!p||i(xt(e,"row",u,"alive"),!0)===!1)&&c(xt(e,"row",u,"alive"),!0);let g=xt(e,"row",u,"pos"),y=m.pos??"";i(g,n?.rows?.[u]?.pos??"")!==y&&c(g,y);let x=Lt(m.cells)?m.cells:{};for(let C of Object.keys(h)){let T=xt(e,"cell",u,C),L=x[C]??"",A=p&&f[C]?p.cells?.[C]??"":i(T,n?.rows?.[u]?.cells?.[C]??"");tt(A)!==tt(L)&&c(T,L)}}return r}function ii(e,t){let n=e.attrs.get(t);return{cols:n?.get("cols")??{},rows:n?.get("rows")??{}}}function $l(e,t,n,o){let s=ii(e,t);for(let[r,i]of ri(t,e.tableFields,s,n,o))e.tableFields.set(r,i)}var Ln=Object.freeze({column:Object.freeze(["alive","name","pos"]),card:Object.freeze(["alive","title","owner","due","placement"])}),gs={column:new Set(Ln.column),card:new Set(Ln.card)},ci=[["column","columns"],["card","cards"]],jn=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),ys=e=>typeof e=="string"&&e.length>0&&!["__proto__","constructor","prototype"].includes(e),Ke=e=>{throw new Q("unsupported-content",`Unsupported board field: ${e}`)},li=e=>e===null||typeof e!="object"?e:JSON.parse(JSON.stringify(e)),Nn=(e,t,n,o)=>JSON.stringify([e,t,n,o]);function bs(e,t){let n=new Map;for(let[o,s]of e){let r;try{r=JSON.parse(o)}catch{Ke(o)}(!Array.isArray(r)||r.length!==4)&&Ke(o);let[i,c,f,h]=r;if((!ys(i)||!ys(f)||!Object.hasOwn(gs,c)||!gs[c].has(h))&&Ke(o),(h==="alive"?typeof s!="boolean":h==="placement"?!jn(s)||Object.keys(s).sort().join(",")!=="columnId,pos"||typeof s.columnId!="string"||typeof s.pos!="string":h==="owner"||h==="due"?s!==null&&typeof s!="string":typeof s!="string")&&Ke(o),i!==t)continue;let a=n.get(c)??new Map,l=a.get(f)??{};l[h]=s,a.set(f,l),n.set(c,a)}return n}var ws=e=>({pos:e.pos??"",name:e.name??""}),xs=e=>({pos:e.placement?.pos??"",col:e.placement?.columnId??"",title:e.title??"",...e.owner!=null?{owner:e.owner}:{},...e.due!=null?{due:e.due}:{}}),Pe=(e,t,n,o)=>Object.fromEntries([...e.get(t)??[]].filter(([,s])=>s.alive!==!1===o).map(([s,r])=>[s,n(r)]));function ze(e,t=null){let n=bs(e,t),o=Pe(n,"column",ws,!0),s=Pe(n,"card",xs,!0),r=yn(o),i=[...new Set(Object.values(s).map(f=>f.col))].filter(f=>!Object.hasOwn(o,f)).sort(),c=[...r,...i].flatMap(f=>yn(Object.fromEntries(Object.entries(s).filter(([,h])=>h.col===f))));return{columns:Object.fromEntries(r.map(f=>[f,o[f]])),cards:Object.fromEntries(c.map(f=>[f,s[f]]))}}function Fe(e,t){let n=bs(e,t);return{columns:Pe(n,"column",ws,!1),cards:Pe(n,"card",xs,!1)}}var vs={name:"",pos:"",title:"",owner:null,due:null,placement:{columnId:"",pos:""}},ks=(e,t,n)=>e==="card"&&n==="placement"?{columnId:t.col??"",pos:t.pos??""}:t[n]??vs[n];function ai(e,t,n,o){let s=[];for(let[r,i]of ci){let c=jn(n?.[i])?n[i]:{},f=jn(o?.[i])?o[i]:{};for(let h of new Set([...Object.keys(c),...Object.keys(f)])){let a=c[h],l=f[h];if(!l){a&&s.push([Nn(e,r,h,"alive"),!1]);continue}a||s.push([Nn(e,r,h,"alive"),!0]);for(let u of Ln[r]){if(u==="alive")continue;let p=Nn(e,r,h,u),m=ks(r,l,u),g=a?ks(r,a,u):t.has(p)?t.get(p):vs[u];tt(g)!==tt(m)&&s.push([p,li(m)])}}}return s}function Ss(e,t,n,o){for(let[s,r]of ai(t,e.boardFields,n,o))e.boardFields.set(s,r)}var Rn="remove",Ts="restore",Kn="copy-active",He="copy-lost",$s="attr",Ds="text-delete",Ye=class extends Error{constructor(t){super(t),this.name="RecoveryError"}},K=e=>{throw new Ye(e)},It=e=>Number.isSafeInteger(e)&&e>=0,ui=e=>Number.isSafeInteger(e)&&e>0,Os=/^(?:0|[1-9]\d*)$/,_s=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),rt=e=>e===null||typeof e!="object"?e:JSON.parse(JSON.stringify(e)),de=(e,t)=>e<t?-1:e>t?1:0,Ns=e=>[...e].sort(de),Ms=e=>`${e.client}.${e.clock}`,di=e=>JSON.stringify(["author",e]),Vl=(e,t)=>JSON.stringify([Rn,e,t]),Hl=(e,t)=>JSON.stringify([Ts,e,t]),Ls=e=>JSON.stringify([Kn,e]),js=e=>JSON.stringify([He,e]),Ul=(e,t,n)=>JSON.stringify([Ds,e,t,n]),Ue=(e,t)=>JSON.stringify([$s,e,t]);function ut(e){if(typeof e!="string")return null;let t=e.indexOf(".");if(t<1||t===e.length-1)return null;let n=e.slice(0,t),o=e.slice(t+1);if(!Os.test(n)||!Os.test(o))return null;let s=Number(n),r=Number(o);return It(s)&&It(r)?{client:s,clock:r}:null}var ue=(e,t,n)=>{_s(e)||K(`Invalid gone record: ${n}`);for(let o of Object.keys(e))t.includes(o)||K(`Unsupported gone field ${o} in ${n}`)},Cs=(e,t)=>{Array.isArray(e)||K(`Invalid state vector in ${t}`);let n=[],o=-1;for(let s of e){(!Array.isArray(s)||s.length!==2)&&K(`Invalid state vector in ${t}`);let[r,i]=s;(!It(r)||!It(i)||r<=o)&&K(`Invalid state vector in ${t}`),o=r,n.push([r,i])}return n},fi=e=>{if(typeof e!="string")return!1;if(e.charCodeAt(0)!==91)return ut(e)!==null;let t;try{t=JSON.parse(e)}catch{return!1}return!Array.isArray(t)||!ut(t[1])?!1:t[0]===Rn?t.length===3&&typeof t[2]=="string"&&t[2]!=="":(t[0]===Kn||t[0]===He)&&t.length===2},pi=(e,t,n)=>{if(t.charCodeAt(0)===91){let r=null;try{r=JSON.parse(t)}catch{K(`Malformed gone key: ${t}`)}if((!Array.isArray(r)||typeof r[0]!="string")&&K(`Malformed gone key: ${t}`),r[0]===Rn){(r.length!==3||typeof r[2]!="string"||!r[2])&&K(`Malformed gone key: ${t}`);let i=ut(r[1]);i||K(`Malformed gone key: ${t}`),ue(e,["blockId","end","sv"],t),(typeof e.blockId!="string"||!e.blockId)&&K(`Invalid removal record: ${t}`);let c=e.end??null;c!==null&&!ut(c)&&K(`Invalid removal record: ${t}`),n.removals.push({key:t,sourceKey:r[1],source:i,operationId:r[2],blockId:e.blockId,end:c,sv:Cs(e.sv,t),legacy:!1});return}if(r[0]===Ts){(r.length!==3||typeof r[2]!="string"||!r[2])&&K(`Malformed gone key: ${t}`),ut(r[1])||K(`Malformed gone key: ${t}`),ue(e,["covers","baseline"],t),(!Array.isArray(e.covers)||e.covers.some(c=>!fi(c)))&&K(`Invalid restore record: ${t}`);let i=e.baseline??{};ue(i,["type","attrs"],t),(typeof i.type!="string"||!_s(i.attrs))&&K(`Invalid restore record: ${t}`),n.restores.push({key:t,sourceKey:r[1],operationId:r[2],covers:Ns(e.covers),baseline:{type:i.type,attrs:rt(i.attrs)}});return}if(r[0]===Kn){(r.length!==2||!ut(r[1]))&&K(`Malformed gone key: ${t}`),e!==!0&&K(`Invalid copy-active record: ${t}`),n.copyActive.add(r[1]);return}if(r[0]===Ds){(r.length!==4||!It(r[1])||!It(r[2])||typeof r[3]!="string"||!r[3])&&K(`Malformed gone key: ${t}`),ue(e,["length","actor","sv"],t),(!ui(e.length)||!It(r[2]+e.length-1))&&K(`Invalid text-delete record: ${t}`),It(e.actor)||K(`Invalid text-delete record: ${t}`),n.textDeletes.push({key:t,client:r[1],clock:r[2],length:e.length,actor:e.actor,sv:Cs(e.sv,t)});return}if(r[0]===$s){(r.length!==3||!ut(r[1])||typeof r[2]!="string"||!r[2])&&K(`Malformed gone key: ${t}`),e===void 0&&K(`Invalid attribute override: ${t}`);let i=n.attrs.get(r[1])??new Map;i.set(r[2],rt(e)),n.attrs.set(r[1],i);return}K(`Unsupported gone record: ${t}`)}let o=ut(t);o||K(`Malformed gone key: ${t}`),ue(e,["b","e"],t),(typeof e.b!="string"||!e.b)&&K(`Invalid gone record: ${t}`);let s=e.e??null;s!==null&&!ut(s)&&K(`Invalid gone record: ${t}`),n.removals.push({key:t,sourceKey:t,source:o,operationId:null,blockId:e.b,end:s,sv:[],legacy:!0})};function Pn(e,{strict:t=!1}={}){let n={removals:[],restores:[],copyActive:new Set,attrs:new Map,textDeletes:[]};return e.forEach((o,s)=>{try{pi(o,s,n)}catch(r){if(t||!(r instanceof Ye))throw r}}),n}var Bn=e=>{if(Array.isArray(e))return e.map(Bn);if(e!==null&&typeof e=="object"){let t={};for(let n of Object.keys(e).sort())t[n]=Bn(e[n]);return t}return e},hi=e=>JSON.stringify(Bn(e)),Ve=e=>S.nodes[e]??S.nodes.paragraph,mi=(e,t,n=null)=>{let o=e.attrs.get(t),s=n?.get("t"),r=o&&o.get("t")||"paragraph",i=typeof s=="string"&&S.nodes[s]?s:r,c=Ve(i),f={};for(let h of Yt(c))f[h]=rt(o&&o.has(h)?o.get(h):Vt(c,h));if(i==="table"&&Object.assign(f,rt(Re(e.tableFields,t,{cols:f.cols,rows:f.rows}))),i==="board"&&Object.assign(f,rt(ze(e.boardFields,t))),n)for(let[h,a]of n)h!=="t"&&Object.hasOwn(f,h)&&(f[h]=rt(a));return{id:t,type:i,attrs:f}},gi=e=>{let t={};if(!e)return t;for(let n of[...e.keys()].sort())t[n]=rt(e.get(n));return t},As="recovered:",jt=e=>typeof e=="string"&&e.startsWith(As)?e.slice(As.length):null;function zn(e,t,n){let o=new Set(t.map(l=>l.key)),s=null;for(let l of n.restores){if(l.sourceKey!==e)continue;let u=l.covers.reduce((p,m)=>p+(o.has(m)?1:0),0);(!s||u>s.count||u===s.count&&de(l.key,s.restore.key)<0)&&(s={restore:l,count:u})}if(!s)return null;let r=n.attrs.get(e),i=r?.get("t"),c=S.nodes[s.restore.baseline.type]?s.restore.baseline.type:"paragraph",f=typeof i=="string"&&S.nodes[i]?i:c,h=Ve(f),a={};for(let l of Yt(h))r&&r.has(l)?a[l]=rt(r.get(l)):Object.hasOwn(s.restore.baseline.attrs,l)?a[l]=rt(s.restore.baseline.attrs[l]):a[l]=rt(Vt(h,l));return{type:f,attrs:a,key:s.restore.key}}var yi=e=>{let t={};for(let n of Object.keys(e).sort())t[n]=rt(e[n]);return t},ki=(e,t)=>t.some(n=>e.clock>=(n.get(e.client)??0)),bi=(e,t)=>{let n=e[e.length-1];if(n&&t<=n.end){t===n.end&&(n.end=t+1);return}e.push({start:t,end:t+1})},wi=e=>{let t=[];for(let n of[...e].sort(de))bi(t,n);return t},xi=(e,t)=>{let n=0,o=e.length-1;for(;n<=o;){let s=n+o>>1,r=e[s];if(t<r.start)o=s-1;else if(t>=r.end)n=s+1;else return!0}return!1},vi=(e,t,n)=>{let o=Ro(t,e.length).physicalRanges(0,t.tokens),s=new Map,r=(h,a,l)=>{for(let u=a;u<l;u++){let p=n.resolve({client:h.id.client,clock:h.id.clock+u}),m=s.get(p.client);m?m.push(p.clock):s.set(p.client,[p.clock])}},i=0,c=0;for(let h=e._start;h&&c<o.length;h=h.right){if(h.deleted||!h.countable)continue;let a=i;i+=h.length;let l=h.content,u=l instanceof Ct;if(!u&&!(l instanceof st)||!u&&l.embed.b!==void 0)continue;for(;c<o.length&&o[c][1]<=a;)c++;let p=c;for(;p<o.length&&o[p][0]<i&&(r(h,Math.max(a,o[p][0])-a,Math.min(i,o[p][1])-a),!(o[p][1]>=i));)p++;c=p}let f=new Map;for(let[h,a]of s)f.set(h,wi(a));return(h,a)=>{let l=f.get(h);return l?xi(l,a):!1}},Es=(e,t,n,o,s)=>{let r=e.resolve({client:t.client,clock:t.clock}),i=t.kind==="text"?jo(Ee(t.raw,o)):{},c=!ki(t,n);return{client:t.client,clock:t.clock,length:t.length,sourceClient:r.client,sourceClock:r.clock,baseline:c,displaced:!c&&!s(r.client,r.clock),kind:t.kind,text:t.kind==="text"?t.text:null,marks:i,raw:yi(t.raw)}},Is=(e,t)=>{let n=e[e.length-1];if(n&&n.kind===t.kind&&n.baseline===t.baseline&&n.displaced===t.displaced&&n.client===t.client&&n.clock+n.length===t.clock&&n.sourceClient===t.sourceClient&&n.sourceClock+n.length===t.sourceClock&&oe(n.marks,t.marks)&&oe(n.raw,t.raw)){n.length+=t.length,n.kind==="text"&&(n.text+=t.text);return}e.push(t)},Si=(e,t)=>({id:Ms(e),length:e.length,source:Ms({client:e.sourceClient,clock:e.sourceClock}),baseline:e.baseline,displaced:e.displaced,kind:e.kind,...e.kind==="text"?{text:e.text}:{},marks:e.marks,raw:e.raw,author:t(e.sourceClient)});function Oi(e,t,n,o,s,r,i,c){let f=(A,_,P=null)=>{let G=t.boundaryOf(_);if(!G||G.blockId!==A||!G.recoveryOf)return mi(e,A,P);let Z=zn(G.recoveryOf,c.get(G.recoveryOf)??[],r),ct=typeof P?.get("t")=="string"&&S.nodes[P.get("t")]?P.get("t"):Z?.type??"paragraph",pt={};for(let $ of Yt(Ve(ct)))pt[$]=rt(P?.has($)?P.get($):Z&&Object.hasOwn(Z.attrs,$)?Z.attrs[$]:Vt(Ve(ct),$));return{id:A,type:ct,attrs:pt}},h=A=>{let _=e.origins.get(di(A));return typeof _=="string"&&_?_:null},a=[...o].sort((A,_)=>de(A.key,_.key)),l=a[0].blockId,u=r.attrs.get(n),p=gi(u),m=f(l,a[0].source,u),g=new Map(a.map(A=>[A.key,new Map(A.sv)])),y=new Map;for(let A of a){let _=s.get(A.key);if(!_)continue;let P=g.get(A.key);for(let G of _.items){let Z=y.get(G.id);Z?Z.vectors.push(P):y.set(G.id,{item:G,vectors:[P]})}}let x=[...y.values()].sort((A,_)=>A.item.at-_.item.at),C=[{...m,author:h(t.resolve(a[0].source).client),runs:[]}],T=C[0];for(let A of x){let _=A.item;if(_.kind==="marker"){if(t.boundaryOf({client:_.client,clock:_.clock})?.kind==="restore"||!_.blockId||_.blockId===T.id)continue;T={...f(_.blockId,{client:_.client,clock:_.clock}),author:h(t.resolve({client:_.client,clock:_.clock}).client),runs:[]},C.push(T);continue}if(_.kind==="text")for(let P=0;P<_.length;P++)Is(T.runs,Es(t,{..._,clock:_.clock+P,length:1,text:_.text[P]},A.vectors,T.type,i));else Is(T.runs,Es(t,_,A.vectors,T.type,i))}let L={source:n,blockId:l,type:m.type,attrs:m.attrs,author:C[0].author,blocks:C.map(A=>({id:A.id,type:A.type,attrs:A.attrs,author:A.author,runs:A.runs.map(_=>Si(_,h))})),removals:a.map(A=>({key:A.key,operationId:A.operationId,end:A.end,sv:A.sv})),restores:r.restores.filter(A=>A.covers.some(_=>a.some(P=>P.key===_))).sort((A,_)=>de(A.key,_.key)).map(A=>({key:A.key,covers:Ns(A.covers)})),copyActive:r.copyActive.has(n),overrides:p,recoverable:C.some(A=>A.runs.some(_=>_.displaced))};return{...L,revision:hi(L)}}function ql(e,t={}){let n=t.index??ce(e.origins);try{let o=t.walked??qe(e,n),s=t.intents??Pn(e.gone,{strict:t.strict===!0}),r=new Map;for(let l of o.hidden??[])r.set(l.key,l);let i=new Map;for(let l of o.removals??s.removals){let u=i.get(l.sourceKey);u?u.push(l):i.set(l.sourceKey,[l])}let c=null,f=(l,u)=>(c||(c=vi(e.flow,o,n)),c(l,u)),h=new Map;for(let[l,u]of i)h.set(l,Oi(e,n,l,u,r,s,f,i));let a=[...h.values()].sort((l,u)=>{let p=ut(l.source),m=ut(u.source);return p.client-m.client||p.clock-m.clock});return{sources:h,list:a,intents:s}}finally{t.index||n.dispose()}}var Bs=e=>{let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)},Mi=(e,t)=>e.id.client===t.client&&t.clock>=e.id.clock&&t.clock<e.id.clock+e.length,Ci=e=>{if(typeof e!="string"||e.charCodeAt(0)!==91)return null;let t;try{t=JSON.parse(e)}catch{return null}return Array.isArray(t)&&t.length===2&&t[0]===He&&typeof t[1]=="string"?t[1]:null},Ai=e=>e.reduce((t,n)=>n.brk.client<t.brk.client||n.brk.client===t.brk.client&&n.brk.clock<t.brk.clock?n:t);function qe(e,t=null){let n=t?null:ce(e.origins);try{return Ei(e,n??t)}finally{n&&n.dispose()}}function Ei(e,t){let n=e.ydoc.store,o=Pn(e.gone),s=new Map,r=new Map;for(let d=e.flow._start;d;d=d.right){if(d.deleted||!(d.content instanceof st)||d.content.embed.b===void 0)continue;r.set(d.content.embed.b,(r.get(d.content.embed.b)??0)+1);let k=ht(t.resolve(d.id)),b=s.get(k);(!b||d.id.client<b.id.client||d.id.client===b.id.client&&d.id.clock<b.id.clock)&&s.set(k,d)}let i=new Set(s.keys()),c=new Set,f=[],h=new Map;for(let d of e.origins.keys()){let k;try{k=JSON.parse(d)}catch{continue}if(!Array.isArray(k)||k.length!==3||k[0]!=="boundary"&&k[0]!=="alias")continue;let[,b,M]=k;if(!Number.isSafeInteger(b)||b<0||!Number.isSafeInteger(M)||M<0)continue;if(k[0]==="boundary"){let O=`${b}.${M}`,B=t.boundaryOf({client:b,clock:M});B&&B.kind==="copy"&&(o.copyActive.has(O)?B.recoveryOf&&c.add(B.recoveryOf):i.has(O)&&f.push({key:Ls(O),sourceKey:O,source:{client:b,clock:M},operationId:null,blockId:B.blockId,end:null,sv:[],legacy:!1,implicit:!0}))}(h.get(b)??h.set(b,new Set).get(b)).add(M)}let a=[],l=new Set(f.map(d=>d.key));for(let d of o.restores)for(let k of d.covers){let b=Ci(k);b===null||l.has(k)||!s.has(b)||(l.add(k),a.push({key:k,sourceKey:b,source:se(b),operationId:null,blockId:s.get(b).content.embed.b,end:null,sv:[],legacy:!1,implicit:!0}))}let u=f.length||a.length?[...o.removals,...f,...a]:o.removals,p=new Map,m=new Map,g=new Map;for(let d of u){(g.get(d.sourceKey)??g.set(d.sourceKey,[]).get(d.sourceKey)).push(d);let b=null;if(d.implicit)b=s.get(d.sourceKey);else try{b=te(n,d.source)}catch{b=null}let M=ht(t.resolve(d.source)),I=s.get(M);if((!b||b.deleted)&&I?.content.embed.b===d.blockId&&(b=I),!b)continue;if(d.legacy){!b.deleted&&b.content instanceof st&&b.content.embed.b===d.blockId&&ht(t.resolve(b.id))===M&&p.set(b,{key:d.key,blockId:d.blockId,end:d.end?se(d.end):null});continue}(m.get(b)??m.set(b,[]).get(b)).push(d)}let y=new Map,x=new Set(o.restores.map(d=>d.sourceKey)),C=(d,k)=>{let b=jt(k);if(b===null)return null;let M=t.boundaryOf({client:d.id.client,clock:d.id.clock});return M&&M.blockId===k&&M.recoveryOf===b?M:null},T=(d,k)=>{let b=C(d,k);return b&&b.kind==="restore"?b.recoveryOf:null},L=(d,k)=>{let b=C(d,k);return b&&b.kind==="copy"?b.recoveryOf:null},A=(d,k)=>{let b=T(d,k);return b!==null&&x.has(b)&&g.has(b)?b:null};for(let d of o.restores){let k=y.get(d.sourceKey)??y.set(d.sourceKey,new Set).get(d.sourceKey);for(let b of d.covers)k.add(b)}let _=new Map;for(let d=e.flow._start;d;d=d.right){if(d.deleted)continue;let k=d.content instanceof st?A(d,d.content.embed&&d.content.embed.b):null;if(k===null)continue;(_.get(k)??_.set(k,[]).get(k)).push(d)}let P=d=>{let k=g.get(d);if(!k||!k.length)return!1;let b=y.get(d);if(!b)return!1;for(let M of k)if(!b.has(M.key))return!1;return(_.get(d)?.length??0)>0||c.has(d)},G=[],Z=[],ct=[],pt=[],$=null,Ot="start",j=null,et=0,lt={},Jt=d=>{let k=e.attrs.get(d);return k&&k.get("t")||"paragraph"},Mt=d=>{d&&($&&!$.atom?$.runs.push({hole:d}):G.push({kind:"h",len:d,key:null}))},gt=(d,k,b=!1)=>{let M=zn(d,g.get(d)??[],o),I=`recovered:${d}`,O=M?M.type:"paragraph",B=!Object.hasOwn(S.nodes,O);$={kind:"b",id:I,baseId:I,brk:{client:k.id.client,clock:k.id.clock},implicit:!1,runs:[],len:1,atom:!B&&!S.nodes[O]?.isTextblock,opaque:B,recovered:!0,restored:!b,sourceKey:d,t:O,fields:M?M.attrs:null},G.push($),Ot=I},Pt=(d,k,b)=>{$={kind:"b",id:d,baseId:d,brk:k,implicit:b,runs:[],len:b?0:1,atom:!1,items:!b&&(r.get(d)??0)>1?[]:null},b?$.t="paragraph":($.t=Jt(d),$.opaque=!Object.hasOwn(S.nodes,$.t),$.atom=!$.opaque&&!S.nodes[$.t]?.isTextblock),G.push($),Ot=d},ye=()=>{j&&(j.len&&(j.resume?j.resume.runs.push({hole:j.len}):G.push({kind:"h",len:j.len,key:j.active[0]?.key})),$=j.resume,j=null)},ke=d=>{d.legacy&&d.text&&Z.push({key:d.key,id:d.blockId,text:d.text,h:Bs(d.text)}),ct.push({key:d.key,sourceKey:d.sourceKey,blockId:d.blockId,end:d.end,sv:d.sv,at:d.at,live:d.live,items:d.items})},un=(d,k)=>Mi(d,k)?!0:zt(d).some(b=>{if(!e.origins.has(An(b.client,b.clock)))return!1;let M=t.resolve(b);return M.client===k.client&&M.clock===k.clock}),dn=new Map([...h].map(([d,k])=>[d,[...k].sort((b,M)=>b-M)])),zt=d=>{let k=dn.get(d.id.client)??[],b=0,M=k.length;for(;b<M;){let O=b+M>>1;k[O]<d.id.clock?b=O+1:M=O}let I=[];for(let O=b;O<k.length&&k[O]<d.id.clock+d.length;O++)I.push({client:d.id.client,clock:k[O]});return I},at=[],fn=d=>({blockId:d.blockId,end:d.end?se(d.end):null,implicit:d.implicit===!0,sourceKey:d.sourceKey});for(let d=e.flow._start;d;d=d.right){let k=et;if(!d.deleted&&d.countable&&(et+=d.length),j||at.length){let O=!d.deleted&&d.content instanceof st?d.content.embed.b:void 0,B=O!==void 0&&T(d,O)===null,N=d.deleted?zt(d).flatMap(z=>{let nt=ht(t.resolve(z)),pn=t.boundaryOf(z);return!pn||pn.kind!=="removed"||i.has(nt)?[]:[{blockId:pn.blockId,sourceKey:nt}]}):[],yt=z=>z.end?un(d,z.end):z.implicit?B||N.some(nt=>nt.sourceKey!==z.sourceKey):B&&O!==z.blockId||N.some(nt=>nt.blockId!==z.blockId);if(j){let z=[];for(let nt of j.active)yt(nt)?ke(nt):z.push(nt);j.active=z,z.length||ye()}for(let z=at.length-1;z>=0;z--)at[z].active=at[z].active.filter(nt=>!yt(nt)),at[z].active.length||at.splice(z,1)}let b=m.get(d);if(b){if(!j&&P(b[0].sourceKey)){d.deleted||Mt(d.length),at.push({active:b.map(fn),sourceKey:b[0].sourceKey,root:null});continue}!j&&d.deleted&&pt.push({client:d.id.client,clock:d.id.clock});for(let O of b){let B={legacy:!1,implicit:O.implicit===!0,key:O.key,sourceKey:O.sourceKey,blockId:O.blockId,end:O.end?se(O.end):null,sv:O.sv,at:k,live:!d.deleted,items:[]};j?j.active.push(B):j={active:[B],len:0,resume:$}}d.deleted||(j.len+=d.length);continue}let M=p.get(d);if(M){if(!j&&P(M.key)){d.deleted||Mt(d.length),at.push({active:[{blockId:M.blockId,end:M.end}],sourceKey:M.key,root:null});continue}let O={legacy:!0,key:M.key,sourceKey:M.key,blockId:M.blockId,end:M.end,sv:[],at:k,live:!0,items:[],text:""};j?j.active.push(O):j={active:[O],len:0,resume:$},j.len+=1;continue}if(d.deleted)continue;let I=d.content;if(I instanceof wn){I.value===null?delete lt[I.key]:lt[I.key]=I.value;continue}if(j){if(I instanceof Ct||I instanceof st){let O=I instanceof Ct?I.str:I.embed.b!==void 0?"\xB6":`
|
|
3
|
-
`,B={...lt};for(let N of j.active)N.legacy&&(N.text+=O),N.items.push({at:k,id:ht(d.id),client:d.id.client,clock:d.id.clock,length:d.length,kind:I instanceof Ct?"text":I.embed.b!==void 0?"marker":"br",text:I instanceof Ct?I.str:null,blockId:I instanceof st&&I.embed.b!==void 0?I.embed.b:null,raw:B});j.len+=d.length}continue}if(I instanceof wn){I.value===null?delete lt[I.key]:lt[I.key]=I.value;continue}if(I instanceof st){let O=A(d,I.embed.b);if(O!==null){let yt=at.find(z=>z.sourceKey===O&&!z.root);yt&&!c.has(O)?(gt(O,d),yt.root=$):Mt(d.length);continue}if(T(d,I.embed.b)!==null){Mt(d.length);continue}let B=L(d,I.embed.b);if(B!==null){gt(B,d,!0);continue}let N=I.embed;N.b!==void 0?Pt(N.b,{client:d.id.client,clock:d.id.clock},!1):((!$||$.atom)&&Pt(`~${Ot}`,null,!0),$.runs.push({br:!0}),$.items&&$.items.push({at:k,id:ht(d.id),client:d.id.client,clock:d.id.clock,length:d.length,kind:"br",text:null,blockId:null,raw:{...lt}}),$.len+=1);continue}if(I instanceof Ct){(!$||$.atom)&&Pt(`~${Ot}`,null,!0);let O=Ee(lt,$.t);$.runs.push({text:I.str,marks:O,mk:Bo(O)}),$.items&&$.items.push({at:k,id:ht(d.id),client:d.id.client,clock:d.id.clock,length:d.length,kind:"text",text:I.str,blockId:null,raw:{...lt}}),$.len+=I.str.length}}if(j){for(let d of j.active)ke(d);ye()}let Wt=new Map;for(let d of G)d.kind!=="b"||d.implicit||(Wt.get(d.baseId)??Wt.set(d.baseId,[]).get(d.baseId)).push(d);let Gt=d=>d.runs.map(k=>k.br?`
|
|
4
|
-
`:k.hole?"":k.text).join(""),Xt=new Map,w=[];for(let[d,k]of Wt){if(k.length<2)continue;let b=Ai(k);for(let M of k)if(M!==b&&(M.hide=!0,(Xt.get(d)??Xt.set(d,[]).get(d)).push(ht(M.brk)),!(oe(M.runs,b.runs)&&M.t===b.t)&&Gt(M)&&(Z.push({key:`d${M.brk.client}.${M.brk.clock}`,id:d,text:Gt(M),h:Bs(Gt(M)),copy:!0}),M.items?.length))){let I=ht(t.resolve(M.brk)),O=js(I);w.push({key:O,sourceKey:I,source:{client:M.brk.client,clock:M.brk.clock},operationId:null,blockId:d,end:null,sv:[],legacy:!1,implicit:!0}),ct.push({key:O,sourceKey:I,blockId:d,end:null,sv:[],at:M.items[0].at,live:!0,items:M.items})}}let v=[],D=[],E=0;for(let d of G){if(d.kind==="h"){D.push({at:E,len:d.len});continue}if(d.hide){D.push({at:E,len:d.len+d.runs.reduce((b,M)=>b+(M.hole??0),0)});continue}v.push(d);let k=d.implicit?0:1;for(let b of d.runs)b.hole?D.push({at:E+k,len:b.hole}):k+=b.br?1:b.text.length;E+=d.len}return{visible:v,holes:D,orphans:Z,tokens:E,copies:Xt,hidden:ct,removals:w.length?[...u,...w]:u,fences:pt}}var Fn=(e,t,n)=>{let o=e.attrs.get(t.baseId),s={};for(let r of Yt(n))s[r]=o&&o.has(r)?o.get(r):Vt(n,r);return n.name==="board"&&Object.assign(s,ze(e.boardFields,t.baseId)),n.name==="table"&&Object.assign(s,Re(e.tableFields,t.baseId,{cols:s.cols,rows:s.rows})),s},Rs=e=>e===void 0?e:JSON.parse(JSON.stringify(e)),Ii=(e,t)=>{let n={},o=e.attrs.get(t.baseId);return o&&o.forEach((s,r)=>{r!=="pos"&&(n[r]=Rs(s))}),n.t=t.t,n};function ca(e,t){let n=t.visible.map(i=>{if(i.opaque){let f=i.recovered?{...Rs(i.fields??{})}:Ii(e,i);return{b:i,type:S.nodes.opaque_block,fields:f,opaque:!0}}let c=S.nodes[i.t]??S.nodes.paragraph;return{b:i,type:c,fields:{...i.fields??Fn(e,i,c)}}}),o=new Map(n.map(i=>[i.b.id,i])),s=i=>(i.b.recovered?e.gone._map.get(Ue(i.b.sourceKey,"parent")):e.attrs.get(i.b.baseId)?._map.get("parent"))?.id??{clock:-1,client:-1};for(let i of o.keys()){let c=new Map,f=[],h=i;for(;o.has(h)&&!c.has(h);)c.set(h,f.length),f.push(h),h=o.get(h).fields.parent;if(!c.has(h))continue;let l=f.slice(c.get(h)).reduce((u,p)=>{let m=s(o.get(u)),g=s(o.get(p));return m.clock<g.clock||m.clock===g.clock&&m.client<g.client?u:p});o.get(l).fields.parent=null}let r=n.map(({b:i,type:c,fields:f,opaque:h})=>{if(h){let u=[];for(let p of i.runs)p.hole||(p.br?u.push(S.nodes.hard_break.create()):u.push(S.text(p.text,p.marks)));return c.create({id:i.id,pos:null,raw:f},u)}let a={id:i.id,pos:null,...f};if(c.name==="table"&&Object.keys(a.rows??{}).length&&Object.keys(a.cols??{}).length)return Ft(S,i.id,{t:"table",...a});if(!c.isTextblock)return c.create(a);let l=[];for(let u of i.runs)u.hole||(u.br?l.push(S.nodes.hard_break.create()):l.push(S.text(u.text,u.marks)));return c.create(a,l)});return r.length?S.nodes.doc.create(null,r):S.nodes.doc.createAndFill()}var J=e=>({status:"refused",code:e}),Je=e=>JSON.parse(JSON.stringify(e)),Ti=["title","owner","due"],$i=/^\d{4}-\d{2}-\d{2}$/,We=(e,t)=>e==="title"?typeof t=="string":e==="due"?t===null||typeof t=="string"&&$i.test(t):t===null||typeof t=="string"&&t.length>0,Di=e=>e!==null&&typeof e=="object"&&!Array.isArray(e);function Ks(e,t){let n=t>0?e[t-1]:null,o=e.slice(t).find(r=>n===null||r>n)??null,s=r=>(n===null||r>n)&&(o===null||r<o);for(let[r,i]of[[n,o],[null,o],[n,null]]){if(r!==null&&!kt(r)||i!==null&&!kt(i)||r!==null&&i!==null&&r>=i)continue;let c=V(r,i);if(s(c))return c}return`${e.reduce((r,i)=>i>r?i:r,"")}V`}function Yn(e,t,n){let o=e.map(t),s=n>0?o[n-1]:null,r=n;for(;s!==null&&r<o.length&&o[r]===s;)r++;if(r===n)return{pos:Ks(o,n),rekey:[]};let i=o.slice(r).find(f=>f>s)??null,c=[];for(let f=n,h=s;f<=r;f++)c.push(h=Ks(i===null?[h]:[h,i],1));return{pos:c[0],rekey:e.slice(n,r).map((f,h)=>[f,c[h+1]])}}var Ge=(e,t,n)=>{let{pos:o,rekey:s}=Yn(t,r=>e[r].pos,n);for(let[r,i]of s)e[r]={...e[r],pos:i};return o};function ya({pd:e,um:t=null,origins:n=null,render:o=()=>{}}){let s=a=>{if(typeof a!="string")return null;let l=qe(e,n).visible.find(p=>p.id===a);if(!l||l.t!=="board")return null;let u=l.fields??Fn(e,l,S.nodes.board);return{columns:Je(u.columns??{}),cards:Je(u.cards??{})}},r=(a,l,u,p)=>{let m=jt(a);return t?.stopCapturing(),e.ydoc.transact(()=>{if(!m)Ss(e,a,l,u);else for(let g of["columns","cards"])tt(l[g])!==tt(u[g])&&e.gone.set(Ue(m,g),Je(u[g]))},Lo),t?.stopCapturing(),o(),p},i=(a,l,u=null)=>X(Object.fromEntries(Object.entries(a.cards).filter(([p,m])=>m.col===l&&p!==u))),c=(a,l)=>l===void 0?a.length:l===null?0:a.indexOf(l)+1,f=(a,l)=>l!=null&&!a.includes(l),h=(a,l)=>{let u=s(a);return u?l(u,Je(u)):J("missing-board")};return{read:a=>s(a),removed(a){return s(a)?jt(a)?{columns:{},cards:{}}:Fe(e.boardFields,a):null},createColumn:(a,{name:l="",afterId:u}={})=>h(a,(p,m)=>{if(typeof l!="string")return J("invalid-value");let g=X(p.columns);if(f(g,u))return J("missing-destination");let y=R("c");return m.columns[y]={pos:Ge(m.columns,g,c(g,u)),name:l},r(a,p,m,{status:"created",id:y})}),renameColumn:(a,l,u)=>h(a,(p,m)=>Object.hasOwn(p.columns,l)?typeof u!="string"?J("invalid-value"):p.columns[l].name===u?{status:"unchanged"}:(m.columns[l].name=u,r(a,p,m,{status:"changed"})):J("missing-column")),moveColumn:(a,l,{afterId:u=null}={})=>h(a,(p,m)=>{if(!Object.hasOwn(p.columns,l))return J("missing-column");let g=X(p.columns).filter(C=>C!==l);if(f(g,u))return J("missing-destination");let y=c(g,u),x=X(p.columns);return[...g.slice(0,y),l,...g.slice(y)].every((C,T)=>C===x[T])?{status:"unchanged"}:(m.columns[l].pos=Ge(m.columns,g,y),r(a,p,m,{status:"moved"}))}),removeColumn:(a,l)=>h(a,(u,p)=>Object.hasOwn(u.columns,l)?(delete p.columns[l],r(a,u,p,{status:"removed",cards:i(u,l).length})):J("missing-column")),restoreColumn:(a,l)=>h(a,(u,p)=>{if(Object.hasOwn(u.columns,l))return{status:"unchanged"};let m=jt(a)?null:Fe(e.boardFields,a).columns[l];return m?(p.columns[l]=m,r(a,u,p,{status:"restored"})):J("missing-column")}),createCard:(a,{columnId:l,title:u="",owner:p=null,due:m=null,afterId:g}={})=>h(a,(y,x)=>{if(!Object.hasOwn(y.columns,l))return J("missing-column");if(!We("title",u)||!We("owner",p)||!We("due",m))return J("invalid-value");let C=i(y,l);if(f(C,g))return J("missing-destination");let T=R("k");return x.cards[T]={pos:Ge(x.cards,C,c(C,g)),col:l,title:u,...p!==null?{owner:p}:{},...m!==null?{due:m}:{}},r(a,y,x,{status:"created",id:T})}),editCard:(a,l,u)=>h(a,(p,m)=>{if(!Object.hasOwn(p.cards,l))return J("missing-card");if(!Di(u)||!Object.keys(u).length||Object.keys(u).some(y=>!Ti.includes(y)))return J("invalid-field");if(Object.entries(u).some(([y,x])=>!We(y,x)))return J("invalid-value");let g={...p.cards[l]};for(let[y,x]of Object.entries(u))x===null?delete g[y]:g[y]=x;return tt(g)===tt(p.cards[l])?{status:"unchanged"}:(m.cards[l]=g,r(a,p,m,{status:"changed"}))}),moveCard:(a,l,{columnId:u,afterId:p=null}={})=>h(a,(m,g)=>{if(!Object.hasOwn(m.cards,l))return J("missing-card");if(!Object.hasOwn(m.columns,u))return J("missing-column");let y=i(m,u,l);if(f(y,p))return J("missing-destination");let x=c(y,p),C=m.cards[l];if(C.col===u){let T=i(m,u);if([...y.slice(0,x),l,...y.slice(x)].every((L,A)=>L===T[A]))return{status:"unchanged"}}return g.cards[l]={...C,col:u,pos:Ge(g.cards,y,x)},r(a,m,g,{status:"moved"})}),removeCard:(a,l)=>h(a,(u,p)=>Object.hasOwn(u.cards,l)?(delete p.cards[l],r(a,u,p,{status:"removed"})):J("missing-card")),restoreCard:(a,l)=>h(a,(u,p)=>{if(Object.hasOwn(u.cards,l))return{status:"unchanged"};let m=jt(a)?null:Fe(e.boardFields,a).cards[l];return m?(p.cards[l]=m,r(a,u,p,{status:"restored"})):J("missing-card")})}}function _i(e,t){if(!e||!/<table[\s>]/i.test(e))return null;let n=t.defaultView?.DOMParser??globalThis.DOMParser;if(!n)return null;let o=new n().parseFromString(e,"text/html").body,s=[...o.querySelectorAll("table")].filter(h=>!h.parentElement.closest("table"));if(s.length!==1)return null;let r=o.cloneNode(!0);for(let h of r.querySelectorAll("table, style, script, template, meta, title"))h.remove();if(r.textContent.trim())return null;let i=s[0];return{grid:[...i.querySelectorAll("tr")].filter(h=>h.closest("table")===i).map(h=>[...h.children].filter(a=>a.tagName==="TD"||a.tagName==="TH").map(a=>xe(Ho.parse(a,{topNode:S.nodes.table_cell.create()})))).filter(h=>h.length),own:!!i.querySelector("td[data-col]")}}function Ni(e){if(!e||!e.includes(" "))return null;let{header:t,rows:n}=ve(e.replace(/\r?\n$/,""),{delimiter:" "});return{grid:[t,...n],own:!1}}function Ps(e,t,n=globalThis.document){let o=null;try{o=_i(e,n)}catch{o=null}if(!o)try{o=Ni(t)}catch{o=null}if(!o||!o.grid.length)return null;let s=Math.max(...o.grid.map(r=>r.length));for(let r of o.grid)for(;r.length<s;)r.push("");return{...o,width:s,height:o.grid.length}}function Xe(e,{header:t=e.length>1}={}){let n=Math.max(0,...e.map(l=>l.length));if(!n)return null;let o=t?e[0]:[],s=t?e.slice(1):e,r=Array.from({length:n},()=>R("c")),i=bt(null,null,n),c=Object.fromEntries(r.map((l,u)=>[l,{pos:i[u],name:Dt(o[u]??"").replace(/\s+/g," ").trim()||`Column ${u+1}`}])),f=s.length?s:[[]],h=bt(null,null,f.length),a=Object.fromEntries(f.map((l,u)=>[R("r"),{pos:h[u],cells:Object.fromEntries(r.map((p,m)=>[p,l[m]??""]))}]));return Ft(S,R(),{t:"table",pos:null,cols:c,rows:a})}var{Plugin:Li,TextSelection:Bt}=q,U=S.nodes,Hn=256*1024,St=e=>X(e.attrs.cols),zs=e=>{let t=e.selection.$head;for(let n=t.depth;n>0;n--)if(t.node(n).type===U.table){let o=t.node(n),s=n<t.depth?t.index(n):0,r=n+1<t.depth?t.index(n+1):0;return{table:o,pos:t.before(n),row:s,cell:r}}return null},fe=(e,t,n,o)=>{let s=e.nodeAt(t);if(!s||!s.childCount)return null;n=Math.max(0,Math.min(n,s.childCount-1)),o=Math.max(0,Math.min(o,s.child(n).childCount-1));let r=t+1;for(let i=0;i<n;i++)r+=s.child(i).nodeSize;r++;for(let i=0;i<o;i++)r+=s.child(n).child(i).nodeSize;return r+1},Qe=(e,t=V())=>U.table_row.create({id:R("r"),pos:t},e.map(n=>U.table_cell.create({col:n}))),it=(e,t,n)=>U.table.create({...e.attrs,...t},n);function dt(e,t,n){let o=zs(e);if(!o)return!1;let s=n(o.table,o);if(!s)return!1;if(t){let{table:r,row:i=o.row,cell:c=o.cell}=s,f=e.tr.replaceWith(o.pos,o.pos+o.table.nodeSize,r),h=fe(f.doc,o.pos,i,c);h!==null&&f.setSelection(Bt.create(f.doc,h)),t(F(f))}return!0}function vt(e,t,n,o=null,s=null,r=null){r??=o?e.doc.resolve(o.from).index(0):e.selection.$head.index(0);let i=e.doc.child(r),c=0;for(let u=0;u<r;u++)c+=e.doc.child(u).nodeSize;let f=i.isTextblock&&(i.content.size===0||o?.from===c+1&&o?.to===c+i.nodeSize-1),h=e.doc.maybeChild(r+1),a=f?i.attrs.pos:V(i.attrs.pos,h?.attrs.pos??null),l=n.type.create({...n.attrs,pos:a,parent:i.attrs.parent??null},n.content);if(t){let u=e.tr;o&&u.delete(o.from,o.to);let p=u.mapping.map(c),m=u.doc.child(r),g=f?p:p+m.nodeSize;if(u.replaceWith(g,f?p+m.nodeSize:g,l),s){let y=s.type.create({...s.attrs,pos:V(a,h?.attrs.pos??null),parent:i.attrs.parent??null},s.content);u.insert(g+l.nodeSize,y)}u.setSelection(Bt.create(u.doc,fe(u.doc,g,0,0))),t(F(u).scrollIntoView())}return!0}function Fs(e=3,t=3){if(!Number.isInteger(e)||!Number.isInteger(t)||e<1||t<1)return null;let n=Array.from({length:t},()=>R("c")),o=bt(null,null,t),s=Object.fromEntries(n.map((c,f)=>[c,{pos:o[f],name:`Column ${f+1}`}])),i=bt(null,null,e).map(c=>Qe(n,c));return U.table.create({id:R(),cols:s},i)}var Un=e=>(t,n)=>{let o=zs(t);if(!o||t.selection.$head.parent.type!==U.table_cell)return!1;let s=o.table.child(o.row).childCount,r=o.row,i=o.cell;return e==="down"?r++:(i+=e,i>=s&&(r++,i=0),i<0&&(r--,i=s-1)),r<0?!0:r>=o.table.childCount?e===-1?!0:ji(t,n,o,i):(n&&n(t.tr.setSelection(Bt.create(t.doc,fe(t.doc,o.pos,r,i))).scrollIntoView()),!0)};function ji(e,t,n,o){let s=[...n.table.content.content];if(s.push(Qe(St(n.table),V(s.at(-1).attrs.pos,null))),t){let r=e.tr.replaceWith(n.pos,n.pos+n.table.nodeSize,it(n.table,{sort:null},s));r.setSelection(Bt.create(r.doc,fe(r.doc,n.pos,s.length-1,o))),t(F(r).scrollIntoView())}return!0}var Bi=Un(1),Ri=Un(-1),Ki=Un("down"),Pi=(e=!0)=>(t,n)=>dt(t,n,(o,s)=>{let r=[...o.content.content],i=s.row+(e?1:0),c=V(r[i-1]?.attrs.pos??null,r[i]?.attrs.pos??null);return r.splice(i,0,Qe(St(o),c)),{table:it(o,{sort:null},r),row:i}}),Ra=(e,t)=>dt(e,t,(n,o)=>{let s=[...n.content.content];if(s.length===1){let r=s[0];s[0]=U.table_row.create(r.attrs,St(n).map(i=>U.table_cell.create({col:i})))}else s.splice(o.row,1);return{table:it(n,{sort:null},s),row:Math.min(o.row,s.length-1)}}),Ys=(e,t,n,o,s)=>{let{pos:r,rekey:i}=Yn(t,f=>e[f]?.pos??"",n),c={...e,[o]:{...s,pos:r}};for(let[f,h]of i)c[f]={...c[f],pos:h};return c},Ka=(e=!0)=>(t,n)=>dt(t,n,(o,s)=>{let r=St(o),i=s.cell+(e?1:0),c=R("c"),f=Ys(o.attrs.cols,r,i,c,{name:`Column ${r.length+1}`}),h=o.content.content.map(a=>{let l=[...a.content.content];return l.splice(i,0,U.table_cell.create({col:c})),U.table_row.create(a.attrs,l)});return{table:it(o,{cols:f},h),cell:i}}),Pa=(e,t)=>dt(e,t,(n,o)=>{let s=St(n);if(s.length<=1)return null;let r={...n.attrs.cols};delete r[s[o.cell]];let i=n.content.content.map(c=>U.table_row.create(c.attrs,c.content.content.filter((f,h)=>h!==o.cell)));return{table:it(n,{cols:r,sort:n.attrs.sort?.col===s[o.cell]?null:n.attrs.sort},i),cell:Math.min(o.cell,s.length-2)}}),za=e=>(t,n)=>dt(t,n,(o,s)=>{let r=s.row+e;if(r<0||r>=o.childCount)return null;let i=[...o.content.content],[c]=i.splice(s.row,1);i.splice(r,0,c);let f=V(i[r-1]?.attrs.pos??null,i[r+1]?.attrs.pos??null);return i[r]=U.table_row.create({...c.attrs,pos:f},c.content),{table:it(o,{sort:null},i),row:r}}),Fa=e=>(t,n)=>dt(t,n,(o,s)=>{let r=St(o),i=s.cell+e;if(i<0||i>=r.length)return null;let c=[...r],[f]=c.splice(s.cell,1);c.splice(i,0,f);let h=Ys(o.attrs.cols,c.filter(l=>l!==f),i,f,o.attrs.cols[f]),a=o.content.content.map(l=>{let u=[...l.content.content],[p]=u.splice(s.cell,1);return u.splice(i,0,p),U.table_row.create(l.attrs,u)});return{table:it(o,{cols:h},a),cell:i}}),zi=48,Fi=1200,Ya=160,Yi=e=>Number.isFinite(e)&&e>0?Math.round(Math.min(Fi,Math.max(zi,e))):null,Va=(e,t)=>(n,o)=>dt(n,o,s=>{let r=s.attrs.cols[e];if(!r)return null;let i=t===null?null:Yi(t);if(t!==null&&i===null||(r.width??null)===i)return null;let{width:c,...f}=r,h={...s.attrs.cols,[e]:i===null?f:{...r,width:i}};return{table:it(s,{cols:h},s.content),cell:St(s).indexOf(e)}}),Ha=(e,t)=>(n,o)=>dt(n,o,s=>{if(!s.attrs.cols[e]||!String(t).trim())return null;let r={...s.attrs.cols,[e]:{...s.attrs.cols[e],name:String(t).trim()}};return{table:it(s,{cols:r},s.content)}}),Ua=(e,t)=>(n,o)=>dt(n,o,s=>{if(!s.attrs.cols[e]||!(t==="auto"||xo.includes(t)))return null;let{kind:r,...i}=s.attrs.cols[e],c={...s.attrs.cols,[e]:t==="auto"?i:{...s.attrs.cols[e],kind:t}};return{table:it(s,{cols:c,sort:s.attrs.sort?.col===e?null:s.attrs.sort},s.content)}}),qa=(e,t="asc")=>(n,o)=>dt(n,o,s=>{if(!s.attrs.cols[e]||!["asc","desc"].includes(t))return null;let r=St(s).indexOf(e),i=Ne(s)[e],c=[...s.content.content].map((a,l)=>({row:a,previous:l,text:a.child(r).textContent.trim()}));c.sort((a,l)=>{if(!a.text||!l.text)return!a.text&&!l.text?a.previous-l.previous:a.text?-1:1;let u=i==="number"?gn(a.text):a.text,p=i==="number"?gn(l.text):l.text;if(u==null||p==null)return u==null&&p==null?a.previous-l.previous:u==null?1:-1;let m=i==="number"?u-p:i==="date"?u<p?-1:u>p?1:0:u.localeCompare(p,void 0,{numeric:!0,sensitivity:"base"});return m?t==="asc"?m:-m:a.previous-l.previous});let f=bt(null,null,c.length),h=c.map(({row:a},l)=>U.table_row.create({...a.attrs,pos:f[l]},a.content));return{table:it(s,{sort:{col:e,dir:t}},h)}}),Vn=(e,t=null)=>(n,o)=>dt(n,o,(s,r)=>{let i=St(s),c=t?.row??r.row,f=t?.cell??r.cell,h=[...s.content.content];e.forEach((l,u)=>{let p=c+u;p>=h.length&&h.push(Qe(i,V(h.at(-1).attrs.pos,null)));let m=[...h[p].content.content];l.forEach((g,y)=>{f+y<i.length&&(m[f+y]=U.table_cell.create({col:i[f+y]},ko(S,g)))}),h[p]=U.table_row.create(h[p].attrs,m)});let a=Math.max(1,...e.map(l=>l.length));return{table:it(s,{sort:null},h),row:c+e.length-1,cell:Math.min(f+a-1,i.length-1)}}),Vi=e=>new TextEncoder().encode(JSON.stringify(e.toJSON())).length;function Hi(e,t){let n=t.clipboardData;if(!n||n.files?.length)return!1;let o=e.state;if(o.selection.$from.parent.type.spec.code)return!1;let s=us(o),r=n.getData("text/plain").replace(/\r?\n$/,""),i=Ps(n.getData("text/html"),n.getData("text/plain"),e.dom.ownerDocument)??(s&&r&&!/[\r\n]/.test(r)?{grid:[[r]],width:1,height:1,own:!1}:null);if(!i)return!1;if(s&&s.rows*s.cols>1&&i.width*i.height===1)return Vn(Array.from({length:s.rows},()=>Array(s.cols).fill(i.grid[0][0])),{row:s.row,cell:s.cell})(o,e.dispatch);if(s)return Vn(i.grid,{row:s.row,cell:s.cell})(o,e.dispatch);if(o.selection.$head.parent.type===U.table_cell)return i.width*i.height<2?!1:Vn(i.grid)(o,e.dispatch);if(i.width*i.height<2||i.height<2&&!/<table[\s>]/i.test(n.getData("text/html")))return!1;let c=Xe(i.grid,{header:!i.own&&i.height>1});if(!c)return!1;if(Vi(c)>Hn)return ie("This paste is too large for one table.","error"),!0;let{from:f,to:h,empty:a,$from:l,$to:u}=o.selection;if(!a&&l.index(0)!==u.index(0)){let p=o.tr.deleteSelection();return vt(o.apply(p),m=>{for(let g of m.steps)p.step(g);p.setSelection(Bt.create(p.doc,m.selection.from)),e.dispatch(F(p).scrollIntoView())},c)}return vt(o,e.dispatch,c,a?null:{from:f,to:h})}var Ja=we.keymap({Tab:Bi,"Shift-Tab":Ri,Enter:Ki,"Mod-Enter":Pi(!0)});function Wa(){return new Li({props:{handlePaste:Hi,handleClickOn(e,t,n,o,s,r){if(n.type!==U.table_cell||!r||s.button)return!1;let i=e.nodeDOM(o),c=i&&ds.get(i);return c&&c.openDate(),!1}},appendTransaction(e,t,n){if(!e.some(r=>r.docChanged&&!r.getMeta(Ae)))return null;let o=new Map;t.doc.forEach(r=>{r.type===U.table&&o.set(r.attrs.id,r)});let s=n.tr;return n.doc.forEach((r,i)=>{if(r.type!==U.table||!r.attrs.sort)return;let c=o.get(r.attrs.id),f=r.attrs.sort.col;if(!c)return;let h=u=>Object.fromEntries(u.content.content.map(p=>[p.attrs.id,p.content.content.find(m=>m.attrs.col===f)?.textContent])),a=h(c),l=h(r);(Object.keys(a).length!==Object.keys(l).length||Object.keys(a).some(u=>a[u]!==l[u]||!Object.hasOwn(l,u)))&&s.setNodeMarkup(i,null,{...r.attrs,sort:null})}),s.docChanged?s.setMeta($n,!0):null}})}function Ga(e,t,n){let o=e.state.doc.nodeAt(t);if(o?.type!==U.table_cell)return!1;let s=e.state.tr.replaceWith(t+1,t+o.nodeSize-1,n?S.text(n):[]);return e.dispatch(s.setSelection(Bt.create(s.doc,t+1+n.length))),!0}function Xa(e,t,n,o){let s=fe(e.state.doc,t,n,o);return s===null?!1:(e.dispatch(e.state.tr.setSelection(Bt.create(e.state.doc,s))),!0)}var{TextSelection:Ui}=q,qn=S.nodes,qi=Object.freeze(["To do","In progress","Done"]),Vs=(e,t)=>kt(e)&&(t===null||kt(t)&&e<t)?V(e,t):null;function Jn(e=qi){let t=bt(null,null,e.length),n=Object.fromEntries(e.map((o,s)=>[R("c"),{pos:t[s],name:o}]));return qn.board.create({id:R(),columns:n,cards:{}})}function Hs(e,t,n=Jn(),o=null,s=null){let r=e.tr;o&&r.delete(o.from,o.to),s??=r.doc.resolve(r.mapping.map(e.selection.head)).index(0);let i=re(r.doc),c=r.doc.child(s),f=c.isTextblock&&c.content.size===0,h=f?s:i[s].subEnd,a=f?i[s].at:i[h].end,l=i[h+1]?.node.attrs.pos??null,u=c.attrs.parent??null,p=f?c.attrs.pos:Vs(i[h].node.attrs.pos,l),m=qn.board.create({...n.attrs,pos:p,parent:u}),g=qn.paragraph.create({id:R(),pos:Vs(p,l),parent:u});return r.replaceWith(a,f?i[s].end:a,[m,g]),r.setSelection(Ui.create(r.doc,a+m.nodeSize+1)),t&&t(F(r).scrollIntoView()),!0}var pe=new WeakMap;function Ze(e,t){let n=null;return e.forEach(o=>{o.type===S.nodes.table&&o.attrs.id===t&&(n=o)}),n}function Us(e){return e?Io({[e.attrs.id]:bo(e)})[0]:null}function Ws(e,t,n){let o=X(e.attrs.cols);if(!o.length)return null;let s=Ne(e),r=o.filter(i=>i!==o[0]&&s[i]==="number");return{id:R(),pos:t,parent:n,source:e.attrs.id,kind:"bar",x:o[0],series:r.length?r:o[1]?[o[1]]:[],title:"",highlight:null}}function Gs(e,t){let n=e.state.doc,o=n.nodeAt(t);if(o?.type!==S.nodes.table)return!1;let s=t+o.nodeSize,r=n.maybeChild(n.resolve(s).index(0)),i=Ws(o,V(o.attrs.pos,r?.attrs.pos??null),o.attrs.parent);return i?(e.dispatch(e.state.tr.insert(s,S.nodes.chart.create(i))),!0):!1}function Wn(e){let t=[];return e.forEach(n=>{n.type===S.nodes.table&&X(n.attrs.cols).length&&t.push(n)}),t}function qs(e,t,n,o){let s=e.state.tr;if(o&&s.delete(o.from,o.to),!Ze(s.doc,n.attrs.id)||t>=s.doc.childCount)return!1;let r=0;for(let u=0;u<t;u++)r+=s.doc.child(u).nodeSize;let i=s.doc.child(t),c=i.isTextblock&&i.content.size===0,f=s.doc.maybeChild(t+1),h=c?i.attrs.pos:V(i.attrs.pos,f?.attrs.pos??null),a=Ws(n,h,i.attrs.parent??null);if(!a)return!1;let l=S.nodes.chart.create(a);return s=c?s.replaceWith(r,r+i.nodeSize,l):s.insert(r+i.nodeSize,l),e.dispatch(s.scrollIntoView()),!0}var Ji=e=>X(e.attrs.cols).map(t=>e.attrs.cols[t].name||"Untitled").join(", ");function Xs(e,t,n=null){let o=Wn(e.state.doc);if(!o.length)return!1;if(o.length===1)return qs(e,t,o[0],n);let s=e.nodeDOM(e.state.doc.resolve(e.state.selection.head).before(1))??e.dom;return Gn(e,s,o.map((r,i)=>({label:`Table ${i+1}`,description:Ji(r),icon:"\u25A6",run:()=>qs(e,t,r,n)})))}var Js=class{constructor(t,n,o){this.node=t,this.view=n,this.getPos=o,this.source=void 0,this.frame=null;let s=n.dom.ownerDocument;this.dom=s.createElement("figure"),this.dom.className="page-chart",this.dom.dataset.id=t.attrs.id??"",this.dom.dataset.type="chart",this.plot=s.createElement("div"),this.plot.className="page-chart-plot",this.caption=s.createElement("figcaption"),this.settings=s.createElement("button"),this.settings.type="button",this.settings.className="page-chart-settings",this.settings.textContent="Chart settings",this.settings.setAttribute("aria-label","Chart settings"),this.settings.contentEditable="false",this.settings.addEventListener("click",()=>this.openSettings()),this.dom.append(this.plot,this.caption,this.settings),pe.has(n)||pe.set(n,new Set),pe.get(n).add(this),this.refresh()}refresh(){let t=Ze(this.view.state.doc,this.node.attrs.source);t!==this.source&&(this.source=t,this.schedule())}schedule(){if(this.frame!==null)return;let t=this.dom.ownerDocument.defaultView,n=t.requestAnimationFrame?.bind(t)??(o=>t.setTimeout(o,0));this.frame=n(()=>{this.frame=null,this.draw()})}draw(){let t=this.node.attrs,n=Oo({id:t.id,type:t.kind,x:t.x,series:t.series,title:t.title,highlight:t.highlight},Us(this.source));this.plot.innerHTML=Mo(n,{width:640,height:320,narrow:this.dom.getBoundingClientRect().width<480}),this.caption.textContent=t.title}setAttrs(t){let n=this.getPos();if(n==null)return;let o=this.view.state.doc.nodeAt(n);o?.type===S.nodes.chart&&this.view.dispatch(this.view.state.tr.setNodeMarkup(n,null,{...o.attrs,...t}))}submenu(t){Gn(this.view,this.settings,t)}openSettings(){let t=this.node.attrs,n=Us(Ze(this.view.state.doc,t.source)),o=n?.cols??[],s=n?.rows??[];this.submenu([{label:"Line",icon:t.kind==="line"?"\u2713":"",run:()=>this.setAttrs({kind:"line"})},{label:"Bar",icon:t.kind==="bar"?"\u2713":"",run:()=>this.setAttrs({kind:"bar"})},{label:"X column \u25B8",focus:!1,run:()=>this.submenu(o.map(r=>({label:r.name||r.id,icon:t.x===r.id?"\u2713":"",run:()=>this.setAttrs({x:r.id,series:t.series.filter(i=>i!==r.id)})})))},{label:"Series \u25B8",focus:!1,run:()=>this.submenu(o.filter(r=>r.id!==t.x).map(r=>({label:r.name||r.id,icon:t.series.includes(r.id)?"\u2713":"",checked:t.series.includes(r.id),run:()=>this.setAttrs({series:t.series.includes(r.id)?t.series.filter(i=>i!==r.id):[...t.series,r.id]})})))},{label:"Highlight row \u25B8",focus:!1,run:()=>this.submenu([{label:"None",icon:t.highlight?"":"\u2713",run:()=>this.setAttrs({highlight:null})},...s.map(r=>({label:Dt(r.cells[t.x])||r.id,icon:t.highlight===r.id?"\u2713":"",run:()=>this.setAttrs({highlight:r.id})}))])},{label:"Edit title",focus:!1,run:()=>this.editTitle()}])}editTitle(){let t=this.dom.ownerDocument.createElement("input");t.type="text",t.className="page-chart-title-input",t.setAttribute("aria-label","Chart title"),t.value=this.node.attrs.title??"";let n=o=>{t.remove(),this.caption.hidden=!1,o?this.setAttrs({title:t.value}):this.settings.focus()};t.addEventListener("keydown",o=>{(o.key==="Enter"||o.key==="Escape")&&(o.preventDefault(),o.stopPropagation(),n(o.key==="Enter"))}),this.caption.hidden=!0,this.caption.after(t),t.focus(),t.select()}update(t){if(t.type!==S.nodes.chart)return!1;let n=!t.sameMarkup(this.node);return this.node=t,this.dom.dataset.id=t.attrs.id??"",n&&(this.source=Ze(this.view.state.doc,t.attrs.source),this.schedule()),!0}stopEvent(t){return!!t.target.closest?.(".page-chart-settings, .page-chart-title-input")}destroy(){if(pe.get(this.view)?.delete(this),this.frame!==null){let t=this.dom.ownerDocument.defaultView;t.cancelAnimationFrame?t.cancelAnimationFrame(this.frame):t.clearTimeout(this.frame)}}};function pu(){return new q.Plugin({view:()=>({update(e){for(let t of pe.get(e)??[])t.refresh()}})})}var{TextSelection:Qn}=q,mt=S.nodes,Tt=[{key:"text",label:"Text",description:"Plain writing",icon:"T",type:"paragraph",aliases:["p","paragraph","plain"]},{key:"h1",label:"Heading 1",description:"Big section heading",icon:"H1",type:"heading",attrs:{level:1},hint:"#",aliases:["h1","title"]},{key:"h2",label:"Heading 2",description:"Medium section heading",icon:"H2",type:"heading",attrs:{level:2},hint:"##",aliases:["h2","subtitle"]},{key:"h3",label:"Heading 3",description:"Small section heading",icon:"H3",type:"heading",attrs:{level:3},hint:"###",aliases:["h3"]},{key:"bullet",label:"Bulleted list",description:"A simple list",icon:"\u2022",type:"list_item",attrs:{kind:"bullet"},hint:"-",aliases:["ul","bullet","list","unordered"]},{key:"ordered",label:"Numbered list",description:"A list with numbers",icon:"1.",type:"list_item",attrs:{kind:"ordered"},hint:"1.",aliases:["ol","num","numbered","ordered"]},{key:"check",label:"Checklist",description:"Tasks to tick off",icon:"\u2610",type:"list_item",attrs:{kind:"check"},hint:"[]",aliases:["todo","to-do","task","check","checkbox"]},{key:"toggle",label:"Toggle",description:"Hide details under a line",icon:"\u25B8",type:"toggle",attrs:{open:!0},hint:">",aliases:["collapse","details","fold"]},{key:"callout",label:"Callout",description:"Make a note stand out",icon:"!",type:"callout",aliases:["note","aside","info"]},{key:"code",label:"Code",description:"Code with highlighting",icon:"</>",type:"code_block",hint:"```",aliases:["pre","snippet"]}],Wi=[{key:"divider",label:"Divider",description:"A line between sections",icon:"\u2014",hint:"---",aliases:["hr","line","separator","rule"],insert:"divider"},{key:"image",label:"Image",description:"Upload or paste a picture",icon:"\u25A3",aliases:["img","picture","photo"],insert:"image"},{key:"file",label:"File",description:"Attach any file",icon:"\u2398",aliases:["upload","attachment","pdf"],insert:"file"},{key:"table",label:"Table",description:"Rows and columns, paste from a spreadsheet",icon:"\u25A6",aliases:["grid","spreadsheet"],insert:"table"},{key:"csv",label:"Import CSV\u2026",description:"Turn a CSV file into a table",icon:"\u21E7",aliases:["comma separated","import"],insert:"csv"},{key:"board",label:"Board",description:"Cards in columns, like a kanban",icon:"\u25A5",aliases:["kanban","cards","columns","status"],insert:"board"}],Gi={key:"chart",label:"Chart",description:"A bar or line chart from a table",icon:"\u{1F4CA}",aliases:["graph","plot","bar","line"],insert:"chart"},en=[...Tt,...Wi],Qs=(e,t=en)=>Wn(e.doc).length?[...t,Gi]:t;function nn(e){let t=e.type.name;return Tt.find(n=>n.type===t&&(!n.attrs||(t==="heading"?n.attrs.level===e.attrs.level:t==="list_item"?n.attrs.kind===e.attrs.kind:!0)))??Tt[0]}var Zs=(e,t)=>{let n=0;for(let o=0;o<t;o++)n+=e.child(o).nodeSize;return n};function Rt(e,t,n){let o=Zs(e.doc,t),s=e.doc.child(t),r={id:s.attrs.id,pos:s.attrs.pos,parent:s.attrs.parent};return s.type===mt.list_item&&n.type==="list_item"&&(r.indent=s.attrs.indent),e.setBlockType(o+1,o+s.nodeSize-1,mt[n.type],{...r,...n.attrs||{}})}var Xi=Object.freeze({status:"refused",code:"unsupported-format"}),Qi=go([]).type,Zi=e=>{let t=!1;return e.forEach(n=>{!t&&n.marks.some(mo)&&(t=!0)}),t};function he(e,t){return!e.isTextblock||e.type===mt.opaque_block?!1:!Zi(e)||mt[t.type].allowsMarkType(Qi)}function tr(e,t,n=e.tr){let o=re(n.doc),{to:s}=zo(o,t),r=n.doc.child(t);return n.insert(s,mt.paragraph.create({parent:r.attrs.parent??null})),n.setSelection(Qn.create(n.doc,s+1))}var Xn=(e,t)=>kt(e)&&(t===null||kt(t)&&e<t)?V(e,t):null;function Zn(e,t){let n=Zs(e.doc,t),o=e.doc.child(t),s=e.doc.maybeChild(t+1),{id:r,pos:i,parent:c}=o.attrs;return e.replaceWith(n,n+o.nodeSize,[mt.divider.create({id:r,pos:i,parent:c}),mt.paragraph.create({id:R(),pos:Xn(i,s?s.attrs.pos:null),parent:c})]),e.setSelection(Qn.create(e.doc,n+2))}function tc(e,t,n=e.tr){let o=n.doc.child(t);if(o.type===mt.paragraph&&o.content.size===0)return Zn(n,t);let s=re(n.doc),r=s[t].subEnd,i=s[r].end,c=s[r+1]?.node.attrs.pos??null,f=Xn(s[r].node.attrs.pos,c),h=o.attrs.parent??null;return n.insert(i,[mt.divider.create({id:R(),pos:f,parent:h}),mt.paragraph.create({id:R(),pos:Xn(f,c),parent:h})]),n.setSelection(Qn.create(n.doc,i+2))}function ec(e,t){if(e.length<2||e.length>32)return 1/0;let n=-1,o=0;for(let s of e){let r=t.indexOf(s,n+1);if(r<0)return 1/0;o+=r-n-1,n=r}return o}function er(e,t){let n=t.trim().toLowerCase();if(!n)return e;let o=s=>{let r=s.label.toLowerCase(),i=[s.key,...s.aliases||[],...s.hint?[s.hint]:[]].map(f=>f.toLowerCase());if(r===n||i.includes(n))return[0,0];if(r.startsWith(n))return[1,0];if([...r.split(/\s+/),...i].some(f=>f.startsWith(n)))return[2,0];if([r,...i].some(f=>f.includes(n)))return[3,0];if(n.length>=3&&s.description&&s.description.toLowerCase().split(/[^a-z0-9]+/).some(f=>f.startsWith(n)))return[4,0];let c=Math.min(...[r,s.key,...s.aliases||[]].map(f=>ec(n,f.toLowerCase())));return c===1/0?null:[5,c]};return e.map((s,r)=>({it:s,order:r,rank:o(s)})).filter(s=>s.rank).sort((s,r)=>s.rank[0]-r.rank[0]||s.rank[1]-r.rank[1]||s.order-r.order).map(s=>s.it)}function nr(e,t,n,o=null){let s=e.state;if(t.insert==="image"||t.insert==="file")return Xo(e,t.insert==="image"?"image/*":"",Go(s,n),o);if(t.insert==="csv")return tn(e,o);if(t.insert==="table")return vt(s,e.dispatch,Fs(),o,null,n);if(t.insert==="board")return Hs(s,e.dispatch,Jn(),o,n);if(t.insert==="chart")return Xs(e,n,o);let r=s.tr;o&&r.delete(o.from,o.to);let i=r.doc.child(n);return i.isTextblock&&i.content.size===0&&!he(i,t)?Xi:(t.insert==="divider"?r=tc(s,n,r):i.isTextblock&&i.content.size===0?r=Rt(r,n,t):(r=tr(s,n,r),r=Rt(r,r.doc.resolve(r.selection.head).index(0),t)),e.dispatch(F(r).scrollIntoView()),e.focus(),!0)}var{InputRule:no}=mn,qt=S.nodes,on=(e,t,n)=>e.doc.rangeHasMark(t,n,S.marks.code)||!!S.marks.code.isInSet(e.storedMarks||e.selection.$from.marks()),Ht=(e,t,n=["paragraph"],o=!1)=>new no(e,(s,r,i,c)=>{let f=s.doc.resolve(i);return!s.selection.empty||f.depth!==1||f.parentOffset!==0||!n.includes(f.parent.type.name)||o&&c!==f.end()||on(s,i,c)?null:F(Rt(s.tr.delete(i,c),f.index(0),typeof t=="function"?t(r):t))}),nc=new no(/^---$/,(e,t,n,o)=>{let s=e.doc.resolve(n);return!e.selection.empty||s.depth!==1||s.parent.type!==qt.paragraph||s.parentOffset!==0||s.parent.content.size!==o-n||on(e,n,o)?null:F(Zn(e.tr,s.index(0)))}),oo=`\\s\\(\\[\\{'\u2018\u201C"`,oc=new RegExp(`[${oo}]`),to=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),or=e=>`([^\\s${e}](?:[\\s\\S]*?[^\\s${e}])?)`,sn=(e,t)=>!!e?.isComposing||e?.keyCode===229||!!t?.composing,sr=e=>{let t=0;for(let n=e.length-1;n>=0&&e[n]==="\\";n--)t++;return t},sc=(e,t)=>{let n=e.doc.resolve(t);return!n.parent.inlineContent||sr(n.parent.textBetween(0,n.parentOffset,null,"\uFFFC"))%2?!1:n.parentOffset===0||oc.test(n.parent.textBetween(n.parentOffset-1,n.parentOffset))},rc=(e,t,n,o,s)=>{let r=s(t);if(!r||!e.selection.empty||n<0||n>o||o>e.doc.content.size)return null;let i=e.doc.resolve(n),c=e.doc.resolve(o);if(!i.sameParent(c)||!i.parent.inlineContent)return null;let[f,h,a,l]=t;if(on(e,n,o))return null;let u=f.slice(h.length,f.length-a.length-l.length),p=n+h.length;if(!sc(e,p)||sr(f.slice(0,f.length-l.length))%2)return null;let m=f.length-(o-n);if(m<0)return null;let g=e.tr;m&&g.insertText(f.slice(-m),o,o);let y=p+u.length,x=y+a.length;return g.delete(x,n+f.length),g.delete(p,y),g.addMark(p,p+a.length,r),g.removeStoredMark(r.type),F(g)},rr=(e,t)=>new no(e,(n,o,s,r)=>rc(n,o,s,r,t),{inCodeMark:!1}),Ut=(e,t,n)=>rr(new RegExp(`(^|[${oo}])${to(e)}${or(to(t))}(${to(t)})$`),()=>n.create()),ic=rr(new RegExp(`(^|[${oo}])\\[${or("\\[\\]")}(\\]\\([^()\\s]*\\))$`),e=>{let t=po(e[3].slice(2,-1));return t?S.marks.link.create({href:t}):null}),cc=[Ut("**","**",S.marks.strong),Ut("__","__",S.marks.strong),Ut("*","*",S.marks.em),Ut("_","_",S.marks.em),Ut("`","`",S.marks.code),Ut("~~","~~",S.marks.strike),ic],eo=["paragraph","list_item"],lc=[Ht(/^(#{1,3})\s$/,e=>({type:"heading",attrs:{level:e[1].length}})),Ht(/^[-*+]\s$/,{type:"list_item",attrs:{kind:"bullet"}},eo),Ht(/^\d+[.)]\s$/,{type:"list_item",attrs:{kind:"ordered"}},eo),Ht(/^\[( |x|X)?\]\s$/,e=>({type:"list_item",attrs:{kind:"check",checked:!!e[1]&&e[1]!==" "}}),eo),Ht(/^>\s$/,{type:"toggle",attrs:{open:!0}}),Ht(/^```$/,{type:"code_block"},["paragraph"],!0),nc,...cc],Nu=()=>mn.inputRules({rules:lc}),ac=/^\s*\|(.*)\|\s*$/;function uc(e,t){let{$from:n,empty:o}=e.selection;if(!o||n.depth!==1||n.parent.type!==qt.paragraph||n.parentOffset!==n.parent.content.size||on(e,n.start(),n.end()))return!1;let s=ac.exec(n.parent.textContent);if(!s)return!1;let r=s[1].split("|").map(c=>c.trim());if(!r.some(Boolean))return!1;let i=Xe([r,r.map(()=>"")],{header:!0});return vt(e,t,i,{from:n.start(),to:n.end()})}var Lu=()=>we.keymap({Enter:(e,t,n)=>!sn(null,n)&&uc(e,t)});function ju(e,t){let{$from:n,empty:o}=e.selection;if(!o||n.depth!==1||n.parentOffset!==0)return!1;let s=n.parent;return s.type===qt.heading||s.type===qt.callout||s.type===qt.code_block&&s.content.size===0?(t&&t(F(e.tr.setNodeMarkup(n.before(),qt.paragraph,{id:s.attrs.id,pos:s.attrs.pos,parent:s.attrs.parent}))),!0):!1}var{Plugin:dr,PluginKey:fr,TextSelection:cn,NodeSelection:dc}=q,pr=S.marks,$t=S.nodes,so=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"\u2318":"Ctrl+",hr=e=>{let t=Ie(e.doc),{lo:n,hi:o}=e.selection.span(e.doc);return t.slice(n,o+1).filter(s=>s.up===t[n].up)},rn=(e,t)=>e.state.doc.child(t).attrs.id,fc=(e,t)=>{let n=0;for(let o=0;o<t;o++)n+=e.child(o).nodeSize;return n},ir=["aria-haspopup","aria-controls","aria-activedescendant"],pc="That block is no longer available.",co="This block holds content from a newer version, so it can't be converted here.";function cr(e){let t=e.visualViewport;return t?{left:t.offsetLeft,top:t.offsetTop,width:t.width,height:t.height}:{left:0,top:0,width:e.innerWidth,height:e.innerHeight}}function hc(e,t,n,o=0){let s=Kt,r=Math.min(t,Math.max(0,e.width-s*2));return{left:e.left+(e.width-r)/2,top:Math.max(e.top+s,e.top+e.height-n-o-s),width:r}}function mc(e,t=globalThis.location){return`${t.origin}${t.pathname}${t.search}#${encodeURIComponent(e)}`}function gc(e){if(!e)return;let t=()=>ie("Link copied"),n=()=>ie("Could not copy the link.","error");if(!globalThis.navigator?.clipboard?.writeText){n();return}globalThis.navigator.clipboard.writeText(mc(e)).then(t,n)}var mr=[{key:"up",label:"Move up",icon:"\u2191",hint:`${so}\u21E7\u2191`,run:e=>xn(-1)(e.state,e.dispatch)},{key:"down",label:"Move down",icon:"\u2193",hint:`${so}\u21E7\u2193`,run:e=>xn(1)(e.state,e.dispatch)},{key:"indent",label:"Indent",icon:"\u2192",hint:"Tab",run:e=>Yo(e.state,e.dispatch)},{key:"outdent",label:"Outdent",icon:"\u2190",hint:"\u21E7Tab",run:e=>Vo(e.state,e.dispatch)},{key:"duplicate",label:"Duplicate",icon:"\u29C9",hint:`${so}D`,run:e=>Jo(e.state,e.dispatch)},{key:"delete",label:"Delete",icon:"\xD7",hint:"Del",run:e=>Sn(e.state,e.dispatch)},{key:"turn",label:"Turn into",icon:"\u21BB",hint:"\u203A",only:"text",run:(e,t)=>t.openMenu("turn",t.plus)},{key:"link",label:"Copy link",icon:"\u{1F517}",run:(e,t,n)=>gc(e.state.doc.child(n).attrs.id)},{key:"alt",label:"Alt text\u2026",icon:"Aa",only:"image",focus:!1,run:(e,t,n)=>Qo(e,rn(e,n))},{key:"small",label:"Small",icon:"\u25AB",only:"image",run:(e,t,n)=>Te(e,rn(e,n),{width:240})},{key:"medium",label:"Medium",icon:"\u25FB",only:"image",run:(e,t,n)=>Te(e,rn(e,n),{width:480})},{key:"full",label:"Full width",icon:"\u2B1C",only:"image",run:(e,t,n)=>Te(e,rn(e,n),{width:null})},{key:"chart",label:"Chart this table",icon:"\u{1F4CA}",only:"table",run:(e,t,n)=>Gs(e,fc(e.state.doc,n))},{key:"csv",label:"Import CSV\u2026",icon:"\u21E7",only:"table",focus:!1,run:(e,t,n)=>tn(e,null,e.state.doc.child(n).attrs.id)}],yc=e=>{if(!(e.selection instanceof wt))return[];let t=hr(e),n=t.every(r=>r.node.isTextblock),o=t.length===1&&t[0].node.type===$t.image,s=t.length===1&&t[0].node.type===$t.table;return mr.filter(r=>r.only==="text"?n:r.only==="image"?o:r.only==="table"?s:!0)},ft=e=>`<svg viewBox="0 0 16 16" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${e}</svg>`,me={plus:ft('<path d="M8 3.5v9M3.5 8h9"/>'),grip:ft('<path stroke-width="2.2" d="M6 3.5h.01M10 3.5h.01M6 8h.01M10 8h.01M6 12.5h.01M10 12.5h.01"/>'),strong:ft('<path d="M5 3h4a2.5 2.5 0 0 1 0 5H5zM5 8h4.6a2.5 2.5 0 0 1 0 5H5z"/>'),em:ft('<path d="M10 3H6.5M9.5 13H6M9 3l-2 10"/>'),strike:ft('<path d="M3 8h10M10.8 5.2C10.5 4 9.4 3.2 8 3.2c-1.7 0-2.8.9-2.8 2.1M5.2 10.8c.3 1.2 1.4 2 2.8 2 1.7 0 2.8-.9 2.8-2.1"/>'),code:ft('<path d="M6 4.5 2.5 8 6 11.5M10 4.5 13.5 8 10 11.5"/>'),link:ft('<path d="M7 9a2.5 2.5 0 0 0 3.5 0l2-2A2.5 2.5 0 0 0 9 3.5l-.7.7M9 7a2.5 2.5 0 0 0-3.5 0l-2 2A2.5 2.5 0 0 0 7 12.5l.7-.7"/>'),bullet:ft('<path d="M6.5 4.5h7M6.5 8h7M6.5 11.5h7"/><path stroke-width="2.4" d="M3 4.5h.01M3 8h.01M3 11.5h.01"/>'),ordered:ft('<path d="M7 4.5h6.5M7 8h6.5M7 11.5h6.5M2.5 3.5l1-.5v3M2.5 9.3c.2-.5.6-.8 1.1-.8.6 0 1 .4 1 .9 0 .9-2.1 1.4-2.1 2.6h2.1"/>'),check:ft('<rect x="2.5" y="2.5" width="11" height="11" rx="2.5"/><path d="M5.5 8.2l1.8 1.8 3.4-4"/>'),more:ft('<path stroke-width="2.2" d="M3 8h.01M8 8h.01M13 8h.01"/>')},ro=[["strong","Bold"],["em","Italic"],["strike","Strikethrough"],["link","Link"],["bullet","Bulleted list"],["ordered","Numbered list"],["check","Checklist"],["code","Code"]],gr=new Set(["strong","em","link"]),kc=new Set(["up","down","indent","outdent"]),bc=204,wc=52,Kt=8,yr=new Set(["bullet","ordered","check"]),xc=new Set(["paragraph","heading","list_item"]),ge=e=>{let t=e.selection;if(t instanceof wt)return hr(e).map(c=>c.i);let{$from:n,$to:o,empty:s}=t,r=Math.min(!s&&o.depth===0?o.index(0)-1:o.index(0),e.doc.childCount-1),i=[];for(let c=n.index(0);c<=r;c++)i.push(c);return i},kr=e=>ge(e).filter(t=>{let n=e.doc.child(t);return n.isTextblock&&n.type!==$t.code_block}),br=(e,t)=>e.type===$t.list_item&&e.attrs.kind===t,wr=(e,t)=>{let n=kr(e);return n.length>0&&n.every(o=>br(e.doc.child(o),t))},vc=e=>{let t="";return e.forEach(n=>{t+=n.isText?n.text:n.type===$t.hard_break?`
|
|
5
|
-
`:""}),t};function Sc(e){let{$from:t,$to:n,empty:o}=e.selection;if(o||!(e.selection instanceof cn)||t.depth!==1||n.depth!==1||t.parentOffset!==0||n.parentOffset!==n.parent.content.size)return null;let s=ge(e);return s.every(r=>xc.has(e.doc.child(r).type.name))?s:null}function Oc(e,t){let n=e.doc.child(t[0]),o=e.selection.$from.before(1),s=e.selection.$to.after(1),r=t.map(a=>vc(e.doc.child(a))).join(`
|
|
6
|
-
`),{id:i,pos:c,parent:f}=n.attrs,h=e.tr.replaceWith(o,s,$t.code_block.create({id:i,pos:c,parent:f},r?S.text(r):null));return h.setSelection(cn.create(h.doc,o+1,o+1+r.length))}function Mc(e,t){let n=e.tr,o=e.doc.resolve(e.selection.from).before(1),s=0;for(let r of[...t].reverse()){let i=0;for(let u=0;u<r;u++)i+=e.doc.child(u).nodeSize;let c=e.doc.child(r),{id:f,pos:h,parent:a}=c.attrs,l=c.textContent.split(`
|
|
7
|
-
`).map((u,p)=>$t.paragraph.create(p===0?{id:f,pos:h,parent:a}:{parent:a},u?S.text(u):null));n.replaceWith(i,i+c.nodeSize,l),s||(s=i+l.reduce((u,p)=>u+p.nodeSize,0))}return s=n.mapping.slice(1).map(s),n.setSelection(cn.create(n.doc,o+1,s-1))}var xr=e=>{let t=ge(e);return t.length>0&&t.every(n=>e.doc.child(n).type===$t.code_block)?t:null};function lr(e,t){if(yr.has(t))return wr(e,t);if(t==="code"&&xr(e))return!0;let n=pr[t],{from:o,to:s,empty:r,$from:i}=e.selection;return r?!!n.isInSet(e.storedMarks||i.marks()):e.doc.rangeHasMark(o,s,n)}function Cc(e,t){let n=e.state,o=wr(n,t),s=Tt.find(c=>c.key===(o?"text":t)),r=kr(n).filter(c=>o||!br(n.doc.child(c),t));if(r.some(c=>!he(n.doc.child(c),s))){_t(e,co);return}let i=n.tr;for(let c of r)Rt(i,c,s);i.docChanged&&e.dispatch(F(i))}function ar(e,t){if(t==="link")return Ko(e);let n=e.state,o=t==="code"?xr(n):null,s=t==="code"&&!o?Sc(n):null;yr.has(t)?Cc(e,t):o?e.dispatch(F(Mc(n,o)).scrollIntoView()):s&&s.some(r=>!he(n.doc.child(r),Tt.find(i=>i.key==="code")))?_t(e,co):s?e.dispatch(F(Oc(n,s)).scrollIntoView()):fo.toggleMark(pr[t])(n,e.dispatch),e.focus()}var W=(e,t,n={})=>{let o=document.createElement(e);t&&(o.className=t);for(let[s,r]of Object.entries(n))o.setAttribute(s,r);return o};function ur(e,t){let n=W("button",`page-tool${gr.has(e)?" page-tool-primary":" page-tool-desk"}`,{type:"button","data-cmd":e,"aria-label":t,title:t});return n.innerHTML=me[e],n}var Ac=1600,Ec=0,Ic=new fr("page-chrome"),vr=new WeakMap,ln=new fr("page-slash-range"),Tc={init:()=>null,apply(e,t){let n=t;if(n&&e.docChanged){let s=e.mapping.map(n.from,1),r=e.mapping.map(n.to,-1);n=s<=r&&e.doc.textBetween(s,r)===n.text?{...n,from:s,to:r}:null}let o=e.getMeta(ln);return o!==void 0&&(n=o),n}},nd=()=>new dr({key:ln,state:Tc}),Sr=(e,t)=>{let n=t?e.state.doc.textBetween(t.from,t.to):null;e.dispatch(e.state.tr.setMeta(ln,t?{...t,text:n}:null))},Or=e=>{let t=ln.getState(e);return t?{from:t.from,to:t.to}:null};function Gn(e,t,n){let o=vr.get(e);return o?(o.openMenu("external",t),o.menu.externalItems=n,o.renderMenu(),!0):!1}var io=class{constructor(t,n){this.view=t,this.onAiTool=n,this.shell=t.dom.parentElement,this.menu=null,this.priorAria=null,this.movedTimer=0,this.hover=null,this.pendingHover=null,this.win=t.dom.ownerDocument.defaultView??globalThis,this.frame=null,this.destroyed=!1,this.probe=null,this.roving=null,this.dock=W("div","page-dock",{role:"toolbar","aria-label":"Formatting"}),this.turn=W("button","page-tool page-tool-turn page-tool-desk",{type:"button","aria-haspopup":"menu"}),this.more=W("button","page-tool page-tool-primary page-tool-more",{type:"button","aria-label":"More",title:"More","aria-haspopup":"menu"}),this.more.innerHTML=me.more,this.dock.append(this.turn,W("span","page-tool-sep page-tool-desk"),...ro.map(([s,r])=>ur(s,r)),this.more),this.plus=W("button","page-plus",{type:"button","aria-label":"Add a block",title:"Add a block"}),this.plus.innerHTML=me.plus,this.grip=W("button","page-grip",{type:"button","aria-label":"Block actions",title:"Drag to move, click for actions","aria-haspopup":"menu"}),this.grip.innerHTML=me.grip,this.bubble=W("div","page-bubble",{role:"toolbar","aria-label":"Selection",hidden:""}),this.bubble.append(...ro.map(([s,r])=>ur(s,r))),this.menuId=`page-menu-${++Ec}`,this.menuEl=W("div","page-menu",{role:"menu",id:this.menuId,hidden:""}),this.scrim=W("div","page-scrim",{hidden:""}),this.shell.insertBefore(this.dock,t.dom),this.shell.append(this.plus,this.grip,this.bubble,this.scrim,this.menuEl);let o=s=>s.preventDefault();for(let s of[this.dock,this.plus,this.grip,this.bubble,this.menuEl])s.addEventListener("mousedown",o);for(let s of[this.dock,this.bubble])s.addEventListener("click",r=>{let i=r.target.closest("[data-cmd]");i&&ar(this.view,i.dataset.cmd)});this.turn.addEventListener("click",()=>this.toggleMenu("turn",this.turn)),this.more.addEventListener("click",()=>this.toggleMenu("more",this.more)),this.dock.addEventListener("keydown",s=>this.dockKey(s)),this.plus.addEventListener("click",()=>this.fromPlus()),this.grip.addEventListener("click",s=>{s.detail===0&&this.gripAction(this.gutterIndex())}),this.drag=new Zo(t,this.grip,{index:()=>this.gutterIndex(),onClick:s=>this.gripAction(s)}),this.scrim.addEventListener("click",()=>this.closeMenu()),this.menuEl.addEventListener("click",s=>{let r=s.target.closest(".page-menu-item");r&&this.pick(Number(r.dataset.index))}),this.menuEl.addEventListener("keydown",s=>{this.key(s)&&s.preventDefault()}),this.onMove=s=>{this.shell.classList.add("is-moved"),clearTimeout(this.movedTimer),this.movedTimer=setTimeout(()=>this.shell.classList.remove("is-moved"),Ac),this.trackHover(s)},this.onKey=()=>{clearTimeout(this.movedTimer),this.shell.classList.remove("is-moved"),this.pendingHover=null,this.setHover(null)},this.onLeave=()=>{this.pendingHover=null,this.setHover(null)},this.onResize=()=>this.scheduleLayout(),this.onDocDown=s=>{this.menu&&([this.menuEl,this.plus,this.grip,this.turn].some(r=>r.contains(s.target))||this.closeMenu())},document.addEventListener("mousedown",this.onDocDown,!0),this.shell.addEventListener("mousemove",this.onMove),this.shell.addEventListener("mouseleave",this.onLeave),this.shell.addEventListener("keydown",this.onKey),this.win.addEventListener("resize",this.onResize),this.win.addEventListener("scroll",this.onResize,!0),this.win.visualViewport?.addEventListener("resize",this.onResize),this.win.visualViewport?.addEventListener("scroll",this.onResize),this.update(t,null)}blockIndex(){let t=this.view.state,n=t.selection,o=n instanceof wt||n instanceof dc?n.from:n.head;return Math.min(t.doc.resolve(o).index(0),t.doc.childCount-1)}isPhone(){return!!this.win?.matchMedia?.("(max-width: 560px)").matches}gutterIndex(){return this.isPhone()?this.blockIndex():(this.settleHover(),Math.min(this.hover??this.blockIndex(),this.view.state.doc.childCount-1))}dockControls(){let t=[...this.dock.querySelectorAll("button")].filter(n=>this.rendered(n));return this.isPhone()?t.filter(n=>n.classList.contains("page-tool-primary")):t}inRoving(t){return!t||!this.dock.contains(t)||this.isPhone()&&!t.classList.contains("page-tool-primary")?!1:this.rendered(t)}rendered(t){if(t.hidden)return!1;let n=this.win?.getComputedStyle?.(t);return!n||n.display!=="none"}setRoving(t){this.roving=t;let n=new Set(this.dockControls());for(let o of this.dock.querySelectorAll("button"))o.tabIndex=o===t&&n.has(o)?0:-1}leaveToToolbar(){queueMicrotask(()=>{this.view.isDestroyed||this.focusToolbar()})}focusToolbar(){let[t]=this.dockControls();return t?(this.setRoving(t),t.focus(),!0):!1}dockKey(t){if(t.key==="Escape"){t.preventDefault(),this.view.focus();return}if(t.key!=="ArrowRight"&&t.key!=="ArrowLeft")return;let n=this.dockControls(),o=n.indexOf(t.target);if(o<0)return;t.preventDefault();let s=n[(o+(t.key==="ArrowRight"?1:-1)+n.length)%n.length];this.setRoving(s),s.focus()}selectionIds(){let t=this.view.state;return ge(t).map(n=>t.doc.child(n).attrs.id)}idIndex(t){let n=-1;return this.view.state.doc.forEach((o,s,r)=>{o.attrs.id===t&&(n=r)}),n}invoker(){let t=this.menu;if(!t||t.slashAt!==null)return this.view.dom;let n=t.anchor;return n&&n!==this.view.dom&&(n.tagName==="BUTTON"||n.hasAttribute("tabindex"))?n:this.view.dom}selectCaretBlock(t=null){let n=this.view.state;if(n.selection instanceof wt)return;let o=(t??[]).map(r=>this.idIndex(r)).filter(r=>r>=0),s=o.length?o[0]:this.blockIndex();this.view.dispatch(n.tr.setSelection(vn(n.doc,s,o.length?o[o.length-1]:s)))}gripAction(t){this.menu?this.closeMenu():this.openActions(this.grip,t)}trackHover(t){this.menu||this.drag.state||[this.plus,this.grip,this.dock,this.bubble].some(n=>n.contains(t.target))||(this.pendingHover={clientY:t.clientY},this.scheduleLayout())}hoverAt(t){let n=this.view,o=n.posAtCoords({left:n.dom.getBoundingClientRect().left+2,top:t});if(!o)return;let s=n.state.doc,r=Ie(s),i=Math.min(s.resolve(o.inside>=0?o.inside:o.pos).index(0),r.length-1);for(;i>0&&r[i].hidden;)i--;this.hover=i}setHover(t){t!==this.hover&&(this.hover=t,this.scheduleLayout())}settleHover(){if(!this.pendingHover)return;let{clientY:t}=this.pendingHover;this.pendingHover=null,this.hoverAt(t)}fromPlus(){this.view.focus();let t=this.gutterIndex();this.openMenu("insert",this.plus,null,null,this.view.state.doc.child(t).attrs.id)}toggleMenu(t,n){this.menu?this.closeMenu():this.openMenu(t,n)}openMenu(t,n,o=null,s=null,r=null){this.menu={mode:t,anchor:n,slashAt:o,anchorId:r,ids:s??(t==="insert"?[]:this.selectionIds()),query:"",active:0,items:[]},n.setAttribute("aria-expanded","true"),o!==null?(this.priorAria||(this.priorAria=ir.map(i=>[i,this.view.dom.getAttribute(i)])),this.view.dom.setAttribute("aria-haspopup","listbox")):this.view.dom.setAttribute("aria-haspopup","menu"),this.view.dom.setAttribute("aria-controls",this.menuId),this.renderMenu()}closeMenu(){if(this.menu?.anchor.setAttribute("aria-expanded","false"),this.menu=null,this.menuEl.hidden=!0,this.scrim.hidden=!0,this.priorAria){for(let[t,n]of this.priorAria)n===null?this.view.dom.removeAttribute(t):this.view.dom.setAttribute(t,n);this.priorAria=null}else for(let t of ir)this.view.dom.removeAttribute(t)}moreItems(){let t=ro.filter(([o])=>!gr.has(o)).map(([o,s])=>({key:o,label:s,icon:me[o],run:r=>ar(r,o)})),n=mr.filter(o=>kc.has(o.key)).map(o=>({...o,blocks:!0}));return[...t,{key:"turn",label:"Turn into",icon:"\u21BB",run:(o,s)=>s.openMenu("turn",s.more)},{key:"insert",label:"Insert",icon:"+",run:(o,s)=>s.openMenu("insert",s.more,null,null,o.state.doc.child(s.blockIndex()).attrs.id)},...n]}menuItems(t){if(t.mode==="external")return t.externalItems||[];if(t.mode==="actions")return yc(this.view.state);if(t.mode==="more")return this.moreItems();let n=t.mode==="turn"?Tt:Qs(this.view.state,this.onAiTool?[...en,{key:"ai",label:"Make a tool with AI\u2026",icon:"\u2726",aliases:["tool","generate"],insert:"ai"}]:en);return er(n,t.query)}currentTypes(){let t=this.view.state;return new Set(ge(t).map(n=>nn(t.doc.child(n)).key))}openActions(t=this.plus,n=null){let o=this.view.state,s=Ie(o.doc),r=o.selection,i=n!==null&&r instanceof wt&&r.span(o.doc).lo<=n&&n<=r.span(o.doc).hi,{lo:c,hi:f}=n===null||i?qo(o,s):Fo(s,n,n);this.view.dispatch(o.tr.setSelection(vn(o.doc,c,f,s)));let h=[];for(let a=c;a<=f;a++)h.push(o.doc.child(a).attrs.id);this.openMenu("actions",t,null,h)}renderMenu(){let t=this.menu;t.items=this.menuItems(t),t.active=Math.min(t.active,Math.max(0,t.items.length-1));let n=t.slashAt!==null,o=t.mode==="turn"?this.currentTypes():null;this.menuEl.setAttribute("role",n?"listbox":"menu");let s=[];if(t.mode==="turn"){let r=W("div","page-menu-title");r.textContent=t.query?`Turn into \u201C${t.query}\u201D`:"Turn into",s.push(r)}if(!t.items.length){let r=W("div","page-menu-empty");r.textContent="No matching blocks",s.push(r)}t.items.forEach((r,i)=>{let c=i===t.active,f=o?o.size===1&&r.key===[...o][0]:typeof r.checked=="boolean"?r.checked:null,h=t.mode==="turn"?"menuitemradio":typeof f=="boolean"?"menuitemcheckbox":n?"option":"menuitem",a=W("button",`page-menu-item${c?" is-active":""}`,{type:"button",role:h,tabindex:!n&&c?"0":"-1",id:`${this.menuId}-${i}`,"data-index":String(i),...h==="menuitemradio"?{}:{"aria-selected":c?"true":"false"},...typeof f=="boolean"?{"aria-checked":String(f)}:{}}),l=W("span","page-menu-icon");l.textContent=r.icon||"";let u=W("span","page-menu-label");if(u.textContent=r.label,r.description){let p=W("span","page-menu-text"),m=W("span","page-menu-desc");m.textContent=r.description,p.append(u,m),a.append(l,p)}else a.append(l,u);if(r.hint){let p=W("span","page-menu-hint");p.textContent=r.hint,a.append(p)}s.push(a)}),this.menuEl.replaceChildren(...s),n&&t.items.length?this.view.dom.setAttribute("aria-activedescendant",`${this.menuId}-${t.active}`):this.view.dom.removeAttribute("aria-activedescendant"),this.menuEl.hidden=!1,this.scrim.hidden=!1,this.scheduleLayout(),n||this.menuEl.querySelectorAll("button")[t.active]?.focus()}pick(t){let n=this.menu,o=n?.items[t];if(!o)return;let s=this.view.state,r=n.slashAt!==null&&s.selection.head>=n.slashAt?{from:n.slashAt-1,to:s.selection.head}:null,i=n.mode==="insert"?n.anchorId?[n.anchorId]:[]:n.ids,c=i.some(h=>!h||this.idIndex(h)<0),f=i.length?this.idIndex(i[0]):-1;if(this.closeMenu(),c&&n.mode!=="external"){_t(this.view,pc),this.view.focus();return}if(n.mode==="turn"){if(i.some(a=>!he(s.doc.child(this.idIndex(a)),o))){_t(this.view,co),this.view.focus();return}let h=s.tr;for(let a of i)Rt(h,this.idIndex(a),o);this.view.dispatch(F(h).scrollIntoView()),this.view.focus()}else n.mode==="actions"||n.mode==="more"||n.mode==="external"?(o.blocks&&this.selectCaretBlock(i),o.run(this.view,this,f>=0?f:this.blockIndex()),!this.menu&&o.focus!==!1&&this.view.focus()):o.insert==="ai"?this.onAiTool(this.view,r):nr(this.view,o,f>=0?f:this.blockIndex(),r)}key(t){if(sn(t,this.view))return!1;let n=this.menu;if(!n)return t.key==="Escape"&&!t.metaKey&&!t.ctrlKey&&!t.altKey&&this.view.state.selection instanceof wt&&this.leaveToToolbar(),!1;if((t.key==="Backspace"||t.key==="Delete")&&n.mode==="actions"&&this.view.state.selection instanceof wt)return this.closeMenu(),this.view.focus(),Sn(this.view.state,this.view.dispatch),!0;if(t.key==="ArrowDown"||t.key==="ArrowUp")return n.items.length&&(n.active=(n.active+(t.key==="ArrowDown"?1:-1)+n.items.length)%n.items.length,this.renderMenu()),!0;if(t.key==="Enter")return n.items.length&&this.pick(n.active),!0;if(t.key==="Escape"){let o=this.invoker();return this.closeMenu(),o===this.view.dom?this.view.focus():o?.focus?.(),!0}return!1}slashQuery(){let t=this.menu;if(!t||t.slashAt===null)return;let{$head:n}=this.view.state.selection,o=n.start();if(n.pos<t.slashAt||t.slashAt<o||this.view.state.doc.textBetween(t.slashAt-1,t.slashAt)!=="/")return this.closeMenu();if(t.query=this.view.state.doc.textBetween(t.slashAt,n.pos),t.active=0,/\s$/.test(t.query)&&!this.menuItems(t).length)return this.closeMenu();this.renderMenu()}scheduleLayout(){this.frame!==null||this.destroyed||(this.frame=this.win.requestAnimationFrame(()=>{if(this.frame=null,this.destroyed)return;let t=this.measureLayout();this.paintLayout(t)}))}safeBottom(){return this.probe||(this.probe=W("div","page-safe-probe"),this.shell.append(this.probe)),parseFloat(this.win.getComputedStyle(this.probe).paddingBottom)||0}menuBox(t){let n=cr(this.win),o=Math.max(0,n.height-Kt*2),s=Math.min(280,Math.max(0,n.width-Kt*2)),r=this.menuEl.style.getPropertyValue("--page-pop-max");this.menuEl.style.removeProperty("--page-pop-max");let i=this.menuEl.offsetHeight||0;r&&this.menuEl.style.setProperty("--page-pop-max",r);let c=Math.min(i,o),f=Math.max(n.left+Kt,Math.min(t.left,n.left+n.width-Kt-s)),h=t.top-6-c;return h<n.top+Kt&&(h=Math.min(t.top+t.height+6,n.top+n.height-Kt-c)),{left:f,top:h,width:s,maxHeight:o}}measureLayout(){let t=this.view,n=t.state;this.settleHover();let o=this.shell.getBoundingClientRect(),s=t.dom.getBoundingClientRect(),r=this.gutterIndex(),i=0;for(let l=0;l<r;l++)i+=n.doc.child(l).nodeSize;let c=t.nodeDOM(i),f={textLeft:s.left-o.left,gutter:null,bubble:null,menu:null,bar:null,desk:!1};if(c&&c.getBoundingClientRect){let l=c.getBoundingClientRect(),u=parseFloat(getComputedStyle(c).lineHeight)||l.height;f.gutter={top:l.top-o.top+Math.min(l.height,u)/2,left:l.left-o.left}}let h=this.isPhone();if(h){let l=cr(this.win),u=this.dock.offsetHeight||wc;f.bar={...hc(l,this.dock.offsetWidth||bc,u,this.safeBottom()),height:u}}else f.desk=!!this.dock.style.left;let a=n.selection;if(!this.bubble.hidden&&!h){let l=t.coordsAtPos(a.from),u=t.coordsAtPos(a.to,-1),p=(Math.min(l.left,u.left)+Math.max(l.right,u.right))/2;f.bubble={x:p-o.left,y:Math.min(l.top,u.top)-o.top}}if(this.menu&&h){let l=this.menuBox(f.bar);f.menu={x:l.left,y:l.top,width:l.width,maxHeight:l.maxHeight}}else if(this.menu){let l=this.menu,u,p;if(l.slashAt!==null){let m=t.coordsAtPos(l.slashAt-1);u=m.left,p=m.bottom+6;let g=this.menuEl.offsetHeight;p+g>this.win.innerHeight-8&&m.top-6-g>=8&&(p=m.top-6-g)}else{let m=l.anchor===this.plus?c?.getBoundingClientRect?.()??s:l.anchor.getBoundingClientRect();u=m.left,p=m.bottom+6}f.menu={x:Math.max(8,Math.min(u-o.left,o.width-280)),y:p-o.top}}return f}paintLayout(t){if(t.bar)this.dock.style.left=`${t.bar.left}px`,this.dock.style.top=`${t.bar.top}px`,this.dock.style.width=`${t.bar.width}px`,this.grip.style.setProperty("--page-grip-lift",`${t.bar.height}px`);else{if(t.desk)for(let n of["left","top","width"])this.dock.style.removeProperty(n);this.grip.style.removeProperty("--page-grip-lift")}if(t.gutter)for(let n of[this.plus,this.grip])n.style.setProperty("--page-plus-top",`${t.gutter.top}px`),n.style.setProperty("--page-plus-left",`${t.gutter.left}px`);this.plus.style.setProperty("--page-text-left",`${t.textLeft}px`),t.bubble&&(this.bubble.style.setProperty("--page-pop-x",`${t.bubble.x}px`),this.bubble.style.setProperty("--page-pop-y",`${t.bubble.y}px`)),t.menu&&(this.menuEl.style.setProperty("--page-pop-x",`${t.menu.x}px`),this.menuEl.style.setProperty("--page-pop-y",`${t.menu.y}px`),t.menu.width!==void 0&&(this.menuEl.style.setProperty("--page-pop-width",`${t.menu.width}px`),this.menuEl.style.setProperty("--page-pop-max",`${t.menu.maxHeight}px`)))}update(t,n){if(this.view=t,this.menu&&this.menu.slashAt===null&&n&&n.doc!==t.state.doc){let i=this.menuEl.contains(document.activeElement);this.closeMenu(),i&&t.focus()}let o=t.state,s=o.doc.child(this.blockIndex());this.turn.textContent=`${nn(s).label} \u25BE`;for(let i of this.dock.querySelectorAll("[data-cmd]"))i.setAttribute("aria-pressed",String(lr(o,i.dataset.cmd)));let r=!o.selection.empty&&o.selection instanceof cn&&t.hasFocus();if(this.bubble.hidden=!r,r)for(let i of this.bubble.querySelectorAll("[data-cmd]"))i.setAttribute("aria-pressed",String(lr(o,i.dataset.cmd)));this.grip.classList.toggle("is-on",o.selection instanceof wt),this.inRoving(this.roving)||this.setRoving(this.dockControls()[0]),this.slashQuery(),this.scheduleLayout()}destroy(){this.destroyed=!0,this.frame!==null&&this.win.cancelAnimationFrame(this.frame),this.frame=null,clearTimeout(this.movedTimer),this.drag.destroy(),this.shell.removeEventListener("mousemove",this.onMove),this.shell.removeEventListener("mouseleave",this.onLeave),this.shell.removeEventListener("keydown",this.onKey),this.win.removeEventListener("resize",this.onResize),this.win.removeEventListener("scroll",this.onResize,!0),this.win.visualViewport?.removeEventListener("resize",this.onResize),this.win.visualViewport?.removeEventListener("scroll",this.onResize),document.removeEventListener("mousedown",this.onDocDown,!0);for(let t of[this.dock,this.plus,this.grip,this.bubble,this.scrim,this.menuEl,this.probe])t?.remove()}};function od({onAiTool:e=null}={}){let t=null;return new dr({key:Ic,view(n){return t=new io(n,e),vr.set(n,t),t},props:{handleKeyDown(n,o){return t?o.key==="/"&&(o.metaKey||o.ctrlKey)&&!o.altKey&&!t.menu?(o.preventDefault(),t.openActions(),!0):t.key(o):!1},handleTextInput(n,o,s,r){if(r!=="/"||!t)return!1;let i=Wo(n,r);i&&(o=n.state.selection.from-1);let c=n.state.doc.resolve(o);if(c.depth!==1||!c.parent.isTextblock||c.parent.type.spec.code||c.parentOffset>0&&!/\s/.test(n.state.doc.textBetween(o-1,o,"",`
|
|
8
|
-
`)))return i;i||n.dispatch(n.state.tr.insertText("/",o,s).setMeta(Le,Tn(n.state,o,s,"/")));let f=Math.min(n.state.doc.resolve(o).index(0),n.state.doc.childCount-1);return t.openMenu("insert",t.plus,o+1,null,n.state.doc.child(f).attrs.id),!0},handleDOMEvents:{keydown(n,o){return sn(o,n)},blur(n){return t&&(t.bubble.hidden=!0),!1}}}})}var{Plugin:$c}=q,ao=new WeakMap,Dc=e=>typeof e.text=="function"?e.text():new Promise((t,n)=>{let o=new FileReader;o.onload=()=>t(o.result),o.onerror=()=>n(o.error),o.readAsText(e)});function an(e,t){let n=e.dom.ownerDocument,o=e.dom.parentElement.querySelector(".page-csv-error");o||(o=n.createElement("div"),o.className="page-csv-error",o.setAttribute("role","alert"),e.dom.parentElement.append(o)),o.textContent=t}function _c(e){let t=0,n=So(e,{maxBytes:Hn,newId:()=>R(t++<e.header.length?"c":"r")});if(!Object.keys(n.cols).length)return null;if(!Object.keys(n.rows).length){let o=Object.fromEntries(Object.keys(n.cols).map(s=>[s,""]));n.rows[R("r")]={pos:V(),cells:o}}return{node:Ft(S,R(),{t:"table",pos:null,cols:n.cols,rows:n.rows}),truncated:n.truncated}}async function Nc({kept:e,total:t}){let n=`This file has ${t} rows. The first ${e} fit in a table.`,o=globalThis.clay?.confirm,s=globalThis.clay?.modal;o||(o=(await import("./c-F3CKJTJS.js")).consent,s=(await import("./c-RM7J7BV2.js")).default);let r=o(n);s&&(s.yes=`Insert first ${e} rows and attach the file`);try{return await r,!0}catch{return!1}}var Lc=(e,t)=>{let n=-1;return e.forEach((o,s,r)=>{n<0&&o.type===S.nodes.table&&o.attrs.id===t&&(n=r)}),n},jc=e=>{let t=!0;return e.descendants(n=>(n.isText&&(t=!1),t)),t};function Bc(e,t,n,o){let s=e.state,r=Lc(s.doc,n);if(r<0)return vt(s,e.dispatch,t,null,o);let i=0;for(let a=0;a<r;a++)i+=s.doc.child(a).nodeSize;let c=s.doc.child(r);if(!jc(c)||o){let a=s.doc.maybeChild(r+1),l=c.attrs.parent??null,u=V(c.attrs.pos,a?.attrs.pos??null),p=t.type.create({...t.attrs,pos:u,parent:l},t.content),m=i+c.nodeSize,g=s.tr.insert(m,p);return o&&g.insert(m+p.nodeSize,o.type.create({...o.attrs,pos:V(u,a?.attrs.pos??null),parent:l},o.content)),g.setSelection(q.TextSelection.create(g.doc,m+3)),e.dispatch(F(g).scrollIntoView()),!0}let f=t.type.create({...t.attrs,id:c.attrs.id,pos:c.attrs.pos,parent:c.attrs.parent},t.content),h=s.tr.replaceWith(i,i+c.nodeSize,f);return h.setSelection(q.TextSelection.create(h.doc,i+3)),e.dispatch(F(h).scrollIntoView()),!0}async function lo(e,t,{upload:n,remove:o=null,table:s=null}={}){try{e.dom.parentElement.querySelector(".page-csv-error")?.remove();let r=ve(await Dc(t)),i=_c(r);if(!i)return an(e,"Couldn't read this CSV: no columns."),!1;let c=null;if(i.truncated){if(!await Nc(i.truncated))return!1;let a=await n?.(t),l=ho(a?.uploads?.[0]?.url);if(!a?.ok||!l)return an(e,"Couldn't attach the original CSV."),!1;c=S.nodes.file.create({id:R(),src:l,name:t.name,size:t.size??null,mime:t.type||"text/csv"})}if(e.isDestroyed)return!1;if(s)return Bc(e,i.node,s,c);let f=o?Or(e.state):null;return o&&!f&&Kc(e,o.block),vt(e.state,e.dispatch,i.node,f,c)}catch(r){return r instanceof wo?an(e,`Couldn't read this CSV: unclosed quote on line ${r.line}.`):an(e,"Couldn't read this CSV."),!1}}function tn(e,t=null,n=null){let o=ao.get(e);return o?(t&&Sr(e,t),o._remove=t?{...t,block:Rc(e.state.doc,t.from)}:null,o._table=n,o.click(),!0):!1}var Rc=(e,t)=>e.child(e.resolve(Math.max(0,Math.min(t,e.content.size))).index(0)).attrs.id;function Kc(e,t){let n=e.state,o=null;return n.doc.forEach((s,r)=>{o===null&&s.attrs.id===t&&(o=r)}),o===null?!1:(e.dispatch(n.tr.setSelection(q.TextSelection.near(n.doc.resolve(o)))),!0)}var Mr=e=>[...e].filter(t=>/\.csv$/i.test(t.name||"")||/^(text\/csv|application\/csv)$/i.test(t.type||""));function hd({upload:e}){return new $c({view(t){let n=t.dom.ownerDocument.createElement("input");return n.type="file",n.accept=".csv,text/csv",n.hidden=!0,n.className="page-csv-input",t.dom.parentElement.append(n),ao.set(t,n),n.addEventListener("change",()=>{let o=n.files?.[0];o&&lo(t,o,{upload:e,remove:n._remove,table:n._table}),n._remove=null,n._table=null,n.value=""}),{destroy(){ao.delete(t),n.remove()}}},props:{handlePaste(t,n){let o=Mr(n.clipboardData?.files||[]);return o.length?(n.preventDefault(),lo(t,o[0],{upload:e}),!0):!1},handleDrop(t,n,o,s){let r=Mr(n.dataTransfer?.files||[]);if(s||!r.length)return!1;n.preventDefault();let i=t.posAtCoords({left:n.clientX,top:n.clientY});return i&&t.dispatch(t.state.tr.setSelection(q.TextSelection.near(t.state.doc.resolve(i.pos)))),lo(t,r[0],{upload:e}),!0}}})}export{ce as a,Pc as b,zc as c,En as d,At as e,De as f,Qc as g,Q as h,Br as i,Zc as j,Re as k,ii as l,$l as m,Nn as n,ze as o,Ss as p,Ye as q,Ms as r,di as s,Vl as t,Hl as u,Ls as v,Ul as w,Ue as x,ut as y,Pn as z,hi as A,As as B,jt as C,zn as D,ql as E,qe as F,ca as G,ya as H,Ne as I,sl as J,rl as K,al as L,ul as M,dl as N,vl as O,Sl as P,ds as Q,Pi as R,Ra as S,Ka as T,Pa as U,za as V,Fa as W,zi as X,Fi as Y,Ya as Z,Va as _,Ha as $,Ua as aa,qa as ba,Ja as ca,Wa as da,Ga as ea,Xa as fa,hd as ga,Gs as ha,Js as ia,pu as ja,sn as ka,Nu as la,Lu as ma,ju as na,nd as oa,Sr as pa,Or as qa,Gn as ra,od as sa};
|
package/dist/m/c-LXENEBV7.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as _,d as v}from"./c-BWFVSBDF.js";import{b as c}from"./c-RVMWGXEJ.js";import{b as u,c as s}from"./c-NUHP2XDB.js";import{e as b}from"./c-AYVOREBE.js";import"./c-7O6AFR65.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-HA6INT6J.js";import"./c-DCFSEJZG.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var d="#FFFCF6",l=["all:initial","color-scheme:inherit","direction:ltr","unicode-bidi:isolate"],y=18,h=3,p=null,f=null;function C(){return f??=Promise.all([import("./c-6HMB24EV.js"),import("./c-ZE46QDIH.js")]).then(([i,e])=>p={RUNTIME_ONLY:i.RUNTIME_ONLY,CHIP_FONT:`600 11px/16px ${e.FONT_MONO}`}).catch(i=>{throw f=null,i}),f}var $=()=>C().then(()=>!0,()=>!1);function a(i){return i.setAttribute("clay",p.RUNTIME_ONLY),i}function A(i){let e=i&&Array.isArray(i.people)?i.people:[],o=[];for(let t of e){if(!t||t.you===!0||typeof t.id!="string"||!t.id||typeof t.editing!="string"||!_.test(t.editing))continue;let n=typeof t.name=="string"&&t.name.trim()?t.name.trim():"Someone";o.push({id:t.id,name:n,path:t.editing})}return o}var m=class{constructor(){this.editors=[],this.root=null,this._gate=null,this._frame=0,this._following=!1,this._onMove=()=>this.schedule()}supported(){return this._gate||(this._gate=b("presence").then(e=>e===!0,()=>!1)),this._gate}async update(e){this.editors=A(e),await this.supported()&&await this.render()}clear(){this.editors=[],this.follow(!1),this._frame&&cancelAnimationFrame(this._frame),this._frame=0,this.root&&this.root.remove(),this.root=null}schedule(){this._frame||(this._frame=requestAnimationFrame(()=>{this._frame=0,this.render()}))}render(){return p?(this.paint(),Promise.resolve()):$().then(e=>{e&&this.paint()})}paint(){let e=new Map;for(let t of this.editors){let n=v(t.path);n&&(e.has(n)||e.set(n,[]),e.get(n).push(t))}let o=[];for(let[t,n]of e){let r=this.box(t,n);r&&o.push(r)}if(!o.length){this.root&&(this.root.textContent="",u(this.root,"display","none")),this.follow(this.editors.length>0);return}this.build()&&(this.root.textContent="",this.root.append(...o),u(this.root,"display","block"),this.follow(!0))}box(e,o){let t=e.getBoundingClientRect();if(!(t.width||t.height))return null;let n=c(o[0].id),r=a(s("div",[...l,"position:fixed","box-sizing:border-box","pointer-events:none",`top:${Math.round(t.top-h)}px`,`left:${Math.round(t.left-h)}px`,`width:${Math.round(t.width+h*2)}px`,`height:${Math.round(t.height+h*2)}px`,`border:2px solid ${n}`,`box-shadow:0 0 0 1px ${d}, inset 0 0 0 1px ${d}`]));r.setAttribute("data-clay-editing-marker","");let M=t.top-h>=y+2,x=a(s("div",[...l,"position:absolute","left:-2px",M?"bottom:100%":"top:100%","display:flex","gap:2px","pointer-events:none"]));for(let g of o){let w=a(s("span",[...l,"box-sizing:border-box",`height:${y}px`,"padding:1px 6px",`font:${p.CHIP_FONT}`,"letter-spacing:.02em","white-space:nowrap","max-width:180px","overflow:hidden","text-overflow:ellipsis",`background-color:${c(g.id)}`,`color:${d}`,`box-shadow:0 0 0 1px ${d}`],g.name));w.setAttribute("data-clay-editing-chip",""),x.appendChild(w)}return r.appendChild(x),r}build(){return this.root&&this.root.isConnected?!0:typeof document>"u"||!document.body?!1:(this.root=a(s("div",[...l,"position:fixed","top:0","left:0","width:0","height:0","overflow:visible","z-index:2147482999","pointer-events:none","display:none"])),this.root.setAttribute("data-clay-editing",""),document.body.appendChild(this.root),!0)}follow(e){if(typeof window>"u"||!!e===this._following)return;this._following=!!e;let o=e?"addEventListener":"removeEventListener";window[o]("scroll",this._onMove,{capture:!0,passive:!0}),window[o]("resize",this._onMove,{passive:!0}),document[o]("input",this._onMove),document[o]("clay:sync-applied",this._onMove)}},N=new m;var O=N;export{m as EditingMarker,O as default,N as editingMarker};
|
package/dist/m/c-PPOSCAQD.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a,b}from"./c-HVYXIS72.js";import"./c-66O32MV3.js";import"./c-VHNSBD2M.js";export{a as tablesFromDoc,b as toolContext};
|
package/dist/m/c-QQHEX6HA.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{e as g,f as h}from"./c-TRS6TM6O.js";import{d as m}from"./c-3IQRECYS.js";import"./c-AYVOREBE.js";import"./c-7O6AFR65.js";import"./c-P7KNDG34.js";import{b as f}from"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-HA6INT6J.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var v="clay.undo",S=1,x="conflict",N="text",k="undo";function R(){let e=f.local.get(k);return Number.isFinite(e?.count)&&e.count>0?e.count:0}function _(e){e>0?f.local.set(k,{count:e,at:Date.now()}):f.local.remove(k)}function T(){return(globalThis.window?.clay??globalThis.clay)?.recovery??null}var y=null;function p(){let e=T();if(!e||typeof e.register!="function")return null;if(y?.service===e)return y.channel;try{y={service:e,channel:e.register({channel:v,version:S})}}catch{return null}return y.channel}var O=(e,t)=>`refused:${e}:${t}`;function D(e){if(e==null||typeof document>"u")return null;let t=globalThis.CSS?.escape?globalThis.CSS.escape(String(e)):String(e).replace(/["\\]/g,"\\$&");try{return document.querySelector(`[data-id="${t}"]`)}catch{return null}}function E(){let t=(globalThis.window?.clay??globalThis.clay)?.conflicts;return typeof t?.contextFor=="function"?t:null}function A({id:e=null}={}){let t=e==null?null:String(e),r=E();return(r?r.contextFor({source:"undo",id:t,element:D(t)},null):null)??{kind:null,id:t,label:null,field:null}}function C(e){return e.map(t=>h(A(t)))}async function F(e,t,r){let n;try{n=await e.list()}catch{return}if(n?.ok){for(let o of n.records)if(!(o.key!==t||String(o.id)===String(r)))try{await e.dismiss(o.id,{revision:o.revision})}catch{}}}var w=Promise.resolve();function H(e,t){let r=w.then(()=>I(e,t));return w=r.catch(()=>{}),r}async function I(e,t){let r=p();if(!r)return{ok:!1,code:"unavailable"};let n=null;try{n=e?.describe?.(t?.entryId)??null}catch{n=null}if(!n)return{ok:!1,code:"unknown-entry"};let o=n.refused&&typeof n.refused=="object"?n.refused:{},c=t?.direction??o.direction??null,i=(Array.isArray(o.targets)?o.targets:[]).map(l=>({id:l?.id==null?null:String(l.id),kind:l?.kind==null?null:String(l.kind)})),s=O(n.id??t?.entryId,c),a=g({label:n.label??null,direction:c,code:t?.code??o.code??null,targets:i,context:C(i),steps:n.steps??[]},[],""),u;try{u=r.stage({key:s,kind:x,baseEtag:m()??null,base:null,payload:a})}catch(l){return console.error("clayjs: the refused step could not be kept for a later reload; it is still in this tab's history",l),{ok:!1,code:"error"}}let d=await r.flush();return d?.ok&&(await F(r,s,u.id),await b()),d?.ok?d:{ok:!1,code:d?.code||"error"}}async function K({key:e,label:t=null,context:r=null,payload:n=null}={}){let o=p();if(!o)return{ok:!1,code:"unavailable"};let c=e==null?"":String(e);if(!c)return{ok:!1,code:"invalid"};let i=n&&typeof n=="object"?n:{},s=g({...i,label:t,context:h(r)},[],"");try{o.stage({key:`app:${c}`,kind:typeof i.text=="string"?N:x,payload:s})}catch(u){return console.error("clayjs: the app's recovery copy could not be kept; it is still in this tab only",u),{ok:!1,code:"error"}}let a=await o.flush();return a?.ok&&await b(),a}async function b(){let e=p();if(!e)return{ok:!0,records:[]};let t=await e.list();return t?.ok&&_(Array.isArray(t.records)?t.records.length:0),t}async function q(e,{revision:t}={}){let r=p();if(!r)return{ok:!1,code:"unavailable"};let n=await r.dismiss(e,{revision:t});if(n?.ok)try{await b()}catch{}return n}export{v as UNDO_CHANNEL,x as UNDO_KIND,N as UNDO_TEXT,S as UNDO_VERSION,A as contextForTarget,q as dismissKept,K as keep,H as keepRefusal,b as kept,R as pendingUndo};
|
package/dist/m/c-R7RMANJI.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import{a as Re}from"./c-TCCA5BZN.js";import{a as Q,b as Qe,c as et,d as tt,e as gt,f as mt,g as nt,h as wn,i as Be,j as yt,k as V,l as rt,m as Rt,n as ot,o as bn}from"./c-LRPUO2MX.js";import{b as Tt}from"./c-A7LS5UZW.js";import{d as qn}from"./c-5V3MOVJT.js";import{e as vn}from"./c-LZJPNR2W.js";import{E as Mt,J as yn,f as gn,q as mn}from"./c-CJZSLMVQ.js";import{a as Ot}from"./c-2SPVQSHC.js";import{e as cn,f as fn,g as dn,h as pn,i as hn}from"./c-B2ZXPOS3.js";import{a as Et}from"./c-TQEMVJCS.js";import{a as an,c as un}from"./c-3IQRECYS.js";import{e as ht,i as ln}from"./c-AYVOREBE.js";import{i as He}from"./c-7O6AFR65.js";import{i as sn}from"./c-35NBGMZB.js";var pr=/^[A-Za-z0-9_-]{1,64}$/,hr=/^[1-9]\d{0,15}$/;var $t=e=>hr.test(e)&&Number.isSafeInteger(Number(e));function Fe(...e){let t=new Map;for(let r of e)for(let[o,n]of r??[])t.has(o)||t.set(o,[]),t.get(o).push(...n.map(([i,a])=>[i,a]));return[...t].sort(([r],[o])=>r<o?-1:r>o?1:0).map(([r,o])=>{let n=[];for(let[i,a]of o.sort((d,m)=>d[0]-m[0])){let d=n[n.length-1];d&&i<=d[1]+1?d[1]=Math.max(d[1],a):n.push([i,a])}return[r,n]}).filter(([,r])=>r.length)}var Sn=e=>e.reduce((t,[,r])=>t+r.length,0),We=(e,t)=>!!e?.some(([r,o])=>r<=t&&t<=o),st=(e,t,r)=>We(e?.find(([o])=>o===t)?.[1],r),gr=([e,t])=>[[e,[[t,t]]]],vt=e=>e?.v===2?e.frames:e?[[e.client,[[1,e.n]]]]:[],kn=e=>e?.v===2?Fe(e.ancestors,gr(e.capture)):[];function An(e){if(!e)return[];let t=[],r=0;for(let o of e.split(";")){let n=o.split(":");if(n.length!==2||!pr.test(n[0])||!n[1])return null;let i=[];for(let a of n[1].split(",")){if(++r>256)return null;let d=a.split("-");if(d.length>2||!d.every($t))return null;let m=Number(d[0]),q=Number(d[1]??d[0]);if(q<m)return null;i.push([m,q])}t.push([n[0],i])}return Fe(t)}function xn(e){return Fe(e).map(([t,r])=>`${t}:${r.map(([o,n])=>o===n?String(o):`${o}-${n}`).join(",")}`).join(";")}function it(e){if(typeof e!="string"||e.length>32768)return null;if(!e.startsWith("v2|")){let a=/^([A-Za-z0-9_-]{1,64}):([1-9]\d{0,15})$/.exec(e);return a&&$t(a[2])?{client:a[1],n:Number(a[2])}:null}let t=e.split("|");if(t.length!==4)return null;let r=An(t[1]),o=An(t[2]),n=/^([A-Za-z0-9_-]{1,64}):([1-9]\d{0,15})$/.exec(t[3]);if(!r||!o||!n||!$t(n[2])||Sn(r)+Sn(o)+1>256)return null;let i=[n[1],Number(n[2])];return st(o,...i)?null:{v:2,frames:r,ancestors:o,capture:i}}function En(e){let t=`v2|${xn(e.frames)}|${xn(e.ancestors)}|${e.capture[0]}:${e.capture[1]}`;return it(t)?t:null}var mr=new Set(["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"]),yr=/^(0|[1-9]\d*)$/,Ne=e=>e!==null&&typeof e=="object",Ue=e=>Array.isArray(e)?"a list":"an object";function $e(e,t){let r=e;for(let o of t){if(!Ne(r))return;Array.isArray(r)?r=r[Number(o)]:r=Object.prototype.hasOwnProperty.call(r,o)?r[o]:void 0}return r}var wt=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),vr=(e,t)=>V(e)===V(t);function On(e,t){let r=[];try{for(let o of t){let n=mt(e,o);n&&(r.push(n),e=n.root)}return r}catch{return Nt(r),null}}function Nt(e){let t;for(let r=e.length-1;r>=0;r--)t=nt(e[r]);return t}function wr(e,t,r){let o=[];for(let n of e){if(n.at===null||Array.isArray(n.at))return null;let i=o.find(a=>a.path.length===n.path.length&&Be(a.path,n.path));if(i){if(i.removed&&n.kind!=="remove")return null;n.kind==="remove"&&(i.removed=!0);continue}if(o.some(a=>Be(a.path,n.path)))return null;o.push({path:n.path,at:n.at,key:n.key,had:n.kind!=="add",old:n.old,removed:n.kind==="remove"})}for(let n of o){if(n.has=wt(n.at,n.key),n.had&&n.has&&n.removed||(n.into=$e(r,n.path.slice(0,-1)),!Ne(n.into)||Array.isArray(n.into)||wt(n.into,n.key)!==n.had))return null;let i=n.path.slice(0,-1);for(let a of t){let d=a.op.path;if(Be(n.path,d)||a.op.op==="del"&&d.length<=n.path.length&&Be(d.slice(0,-1),n.path)&&Array.isArray($e(r,d.slice(0,-1))))return null;if(!n.had&&n.has&&d.length>i.length&&Be(i,d)){let m=d[i.length];if(d.length===i.length+1&&a.op.op==="del"||!wt(n.at,String(m)))return null}}}return o}function br(e,t){if(t.op==="set"){let r=$e(e,t.path);if(Ne(r)&&Ne(t.value)&&Array.isArray(r)===Array.isArray(t.value)){yt(r,Q(t.value));return}}tt(e,t)}function It({name:e,value:t,ephemeral:r=!1}){if(!Ne(t))throw new TypeError(`clay.live("${e}"): the tag must hold a JSON object or list`);let o=Q(t),n=Q(t),i=!0,a=[],d=1,m=null,q="file",g=new Set,P=new Set,F=new Set,_=new Set,C=new Set,U=new WeakMap;function O(f,y){let v={source:f,ops:y};for(let k of[...g])try{k(v)}catch(L){console.error(`clay.live("${e}"): a change listener threw`,L)}}function B(){let f=Q(o),y=[];for(let v of a)try{et(f,v.op),f=tt(f,v.op),y.push(v)}catch{}a=y,yt(n,f),i=!0}function X(f){for(let y of[...F])try{y(f)}catch(v){console.error(`clay.live("${e}"): a rebase listener threw`,v)}}function T(f,{source:y="remote",confirmed:v=0,through:k,drop:L,dropIds:W,frame:ue=null,room:oe=null,cause:re=null}={}){if(!Ne(f)||Ue(f)!==Ue(n))return console.warn(`clay.live("${e}"): ignored an incoming value that is not ${Ue(n)}`),!1;let he=V(n),ge=o;if(o=Q(f),L)a=a.filter(te=>te.id<L[0]||te.id>L[1]);else if(W){let te=new Set(W);a=a.filter(we=>!te.has(we.id))}else a=k===void 0?a.slice(v):a.filter(te=>te.id>k);return B(),X({source:y,frame:ue,room:oe,cause:re,prev:ge,before:te=>$e(ge,te),next:o}),V(n)!==he&&O(y,null),!0}function ee(f){let y=Q(o);for(let v=f.length-1;v>=0;v--){let k=f[v];nt({...k,at:$e(y,k.path.slice(0,-1))})}return y}function w(f){for(let y of[...P])try{y(f)}catch(v){console.error(`clay.live("${e}"): a transport threw`,v)}O("local",f)}function J(f){let y=f.map(Qe);for(let v of y)if(v.path.length===0&&Ue(v.value)!==Ue(n))throw new TypeError(`clay.live("${e}"): the whole value must stay ${Ue(n)}`);y.length===1?et(n,y[0]):gt(Q(n),y);for(let v of y)br(n,v);a.push(...y.map(v=>({id:d++,op:v}))),m?m.push(...y):w(y)}function D(f,y){let v=U.get(f);v||U.set(f,v=new Map);let k=JSON.stringify(y),L=v.get(k);return L||(L=new Proxy(f,de(y)),v.set(k,L)),L}function de(f){return{get(y,v){if(Array.isArray(y)&&mr.has(v))return(...L)=>{let W=Q(y),ue=Array.prototype[v].apply(W,L);return J([{op:"set",path:f,value:W}]),ue===W?D(y,f):ue};let k=y[v];return typeof v=="symbol"||!Ne(k)||!Object.prototype.hasOwnProperty.call(y,v)?k:D(k,[...f,Array.isArray(y)?Number(v):v])},set(y,v,k){if(typeof v=="symbol")throw new TypeError(`clay.live("${e}"): symbol keys are not JSON`);if(Array.isArray(y)){if(v==="length"){let L=Q(y);return L.length=k,J([{op:"set",path:f,value:L}]),!0}if(!yr.test(v))throw new TypeError(`clay.live("${e}"): "${v}" is not a list index`);return J([{op:"set",path:[...f,Number(v)],value:k}]),!0}return J([{op:"set",path:[...f,v],value:k}]),!0},deleteProperty(y,v){if(typeof v=="symbol")return!0;if(Array.isArray(y))throw new TypeError(`clay.live("${e}"): remove a list item with splice`);return J([{op:"del",path:[...f,v]}]),!0},defineProperty(){throw new TypeError(`clay.live("${e}"): assign values instead of defining properties`)},setPrototypeOf(){return!1},preventExtensions(){return!1}}}let Y=D(n,[]),ae,pe=new Promise(f=>{ae=f}),z=Object.freeze({name:e,ephemeral:r,ready:pe,get data(){return Y},get status(){return{mode:q}},set(f,y){J([{op:"set",path:f,value:y}])},delete(f){J([{op:"del",path:f}])},add(f,y=1){J([{op:"add",path:f,n:y}])},update(f){if(typeof f!="function")throw new TypeError(`clay.live("${e}"): update() takes a function`);if(m)return f(Y);m=[];let y=a.length,v=d,k;try{if(k=f(Y),k&&typeof k.then=="function")throw new TypeError(`clay.live("${e}"): update() runs synchronously; do async work before calling it`)}catch(W){throw m=null,a.length=y,d=v,B(),W}let L=wn(m);return m=null,a.length=y,d=v,a.push(...L.map(W=>({id:d++,op:W}))),L.length&&w(L),k},on(f,y){if(f!=="change")throw new TypeError(`clay.live("${e}"): the only event is "change"`);if(typeof y!="function")throw new TypeError(`clay.live("${e}"): on() takes a function`);return g.add(y),()=>g.delete(y)},off(f,y){g.delete(y)},toJSON(){return Q(n)}});return ae(z),{handle:z,name:e,ephemeral:r,get value(){return n},get authoritative(){return o},get pending(){return a.map(f=>f.op)},pendingEntries(){return a.map(f=>({id:f.id,op:f.op}))},get mark(){return d-1},setMode(f){q=f},onLocal(f){return P.add(f),()=>P.delete(f)},confirm(f){let y=a.filter(v=>v.id<=f);if(y.length){try{o=gt(Q(o),y.map(v=>v.op))}catch{o=Q(n),i=!1}a=a.filter(v=>v.id>f);for(let v of[..._])try{v({through:f})}catch(k){console.error(`clay.live("${e}"): a confirmation listener threw`,k)}}},onConfirm(f){return _.add(f),()=>_.delete(f)},rebase:T,checkOps(f){let y;try{y=f.map(Qe)}catch{return null}let v=On(o,y);return v?(Nt(v),y):null},rebaseOps(f,{source:y="remote",confirmed:v=0,through:k,frame:L=null,room:W=null,cause:ue=null}={}){let oe=On(o,f);if(!oe)return!1;let re=k===void 0?a.slice(v):a.filter($=>$.id>k),he=a.length-re.length,ge=oe.some($=>$.at===null),te=i&&!ge&&he===f.length&&f.every(($,Z)=>vr($,a[Z].op)),we=i&&!te&&he===0?wr(oe,re,n):null;if(!te&&!we)return Nt(oe),T(gt(Q(o),f),{source:y,confirmed:v,through:k,frame:L,room:W,cause:ue});a=re;let Ce=!1;for(let $ of we??[]){let Z=$.into;if($.has){let je=$.at[$.key];(!$.had||V($.old)!==V(je))&&(Ce=!0);let s=$.had?Z[$.key]:void 0,p=Q(je),A=Ne(s)&&Ne(p)&&Array.isArray(s)===Array.isArray(p);Object.defineProperty(Z,$.key,{value:A?yt(s,p):p,enumerable:!0,writable:!0,configurable:!0})}else $.had&&(Ce=!0,delete Z[$.key])}let be=null,Oe=()=>be??=ee(oe),ce=oe.some($=>Array.isArray($.at)&&$.kind!=="put");return X({source:y,frame:L,room:W,cause:ue,get prev(){return Oe()},before:$=>{if(ce)return $e(Oe(),$);for(let Z of oe)if(Be(Z.path,$))return Z.path.length>$.length?$e(Oe(),$):$e(Z.old,$.slice(Z.path.length));return $e(o,$)},next:o}),Ce&&O(y,null),!0},onRebase(f){return F.add(f),()=>F.delete(f)},onDelivery(f){return C.add(f),()=>C.delete(f)},deliver(f){for(let y of[...C])try{y(f)}catch(v){console.error(`clay.live("${e}"): a delivery listener threw`,v)}}}}function Mn({needsSave:e,blocked:t,save:r,saveNow:o,now:n=()=>Date.now(),setTimer:i=setTimeout,clearTimer:a=clearTimeout}){let d=null,m=null,q=!1,g=!1,P=0;function F(O){let B=O&&!O.ok&&O.msgType==="skipped";return P=O?.ok||B?0:n()+8e3,B?1e3:8e3}function _(O){d=O,m!==null&&a(m),m=i(U,Math.max(0,O-n()))}function C(){m!==null&&a(m),m=null,d=null}async function U(){if(m=null,d=null,!e())return;if(t()){_(n()+1e3);return}q=!0;let O=null;try{O=await r()}catch{O=null}finally{q=!1}let B=F(O);e()&&_(n()+B)}return{changed(){d===null&&!q&&_(n()+8e3)},flush(){q||!e()||t()||(C(),q=!0,g=!0,Promise.resolve().then(o).catch(()=>null).then(O=>{q=!1,g=!1;let B=F(O);e()&&_(n()+B)}))},soon(){if(q)return;let O=Math.max(n(),P);(d===null||O<d)&&_(O)},within(O){if(q)return;let B=Math.max(n()+O,P);(d===null||B<d)&&_(B)},get flushing(){return g},get deadline(){return d}}}var qr=40,Tn=128,lt=500,Sr=1e4,Ar=63*1024,Rn=15*1024,xr=/^page(\.[0-9]+)?$/,kr=512,_t=8e3,Er=new Set([401,403]),Or=new Set([401,403,404]),Mr=new TextEncoder,bt=e=>Mr.encode(JSON.stringify(e)).length,$n=e=>e===0||e===408||e===429||e>=500,Nn=e=>e===429||e===503;function Pt({transport:e,entries:t,onEpoch:r=()=>{},onLeave:o=()=>{},onWriter:n=()=>{},onApplied:i=()=>{},onLanded:a=()=>{},onCheckpoint:d=()=>{},held:m=()=>!1,heldIds:q=()=>[],hold:g=()=>!0,taken:P=()=>{},onStop:F=()=>{},now:_=()=>Date.now(),setTimer:C=setTimeout,clearTimer:U=clearTimeout}){let O=null,B=!1,X=!1,T=null,ee=null,w=null,J=0,D=0,de=null,Y=new Set,ae=[],pe=!1,z=!1,f=!1,y=null,v=-1/0,k=0,L=null,W=null,ue=lt,oe=Ar,re=lt,he=0,ge,te=0,we=!1,Ce=0,be=!1,Oe=null,ce=new Map,Me=new Set,$=(l,c)=>t.get(l)?.store.deliver?.({code:null,n:null,seq:null,through:null,retryAfter:null,client:O,...c});function Z(l){let c=ce.get(l);return c||ce.set(l,c={n:0,unsent:[],awaiting:[],framed:0}),c}function je(l,c){!l.adopted||c.through<l.adopted.through||(c.adopted=l.adopted.rev,l.adopted=null)}function s(l,c){let u=t.get(l)?.store;return u?u.pendingEntries().filter(h=>h.id>c.framed):[]}function p(l,c){let u=t.get(l)?.store;if(!u)return;let h=new Set(u.pendingEntries().map(S=>S.id));c.awaiting=c.awaiting.filter(S=>S===y||!S.entries||S.entries.some(x=>h.has(x.id)))}let A=l=>l.refused===!0&&!l.uncertain;function M(l,c,u=!0){let h=t.get(l)?.store;for(let S of c.awaiting)S===y&&(S.undecided=!0);u&&(be=!0),c.out=!0,o(l,{epoch:T,seq:D}),c.unsent=[],h?.setMode("file"),i()}function b(){if(L!==null||f||z)return;let l=_(),c=Math.max(0,v+qr-l,k-l);L=C(()=>{L=null,se()},c)}function N(){for(let[l,c]of ce){if(!Y.has(l)||m(l))continue;let u=c.awaiting.find(h=>!h.sent);if(u)return{name:l,lane:c,frame:u}}for(let[l,c]of ce){if(!c.unsent.length||!Y.has(l)||m(l))continue;let u=bt({name:l,n:c.n+1,ops:[],epoch:T}),h=0;for(;h<c.unsent.length&&h<Tn;){let I=bt(c.unsent[h].op)+1;if(h&&u+I>oe)break;u+=I,h++}let S=c.unsent.splice(0,h),x={n:++c.n,ops:S.map(I=>I.op),entries:S,first:S[0].id,through:S[S.length-1].id,seq:null,sent:!1,receiptGeneration:ee,pageGeneration:w};return je(c,x),c.framed=Math.max(c.framed,x.through),c.awaiting.push(x),{name:l,lane:c,frame:x}}return null}async function se(){if(f||z||!B||!X||ge===null)return;let l=N();if(!l)return;let{name:c,lane:u,frame:h}=l;ce.delete(c),ce.set(c,u);let S=T;h.epoch=S,h.client=O,h.sentOn=he,h.sent=!0,$(c,{phase:"sent",n:h.n,first:h.first,through:h.through}),h.refused=!1,f=!0,y=h,v=_();let x;try{x=await e.send(O,{name:c,n:h.n,ops:h.ops,epoch:S,...ge!==void 0&&{conn:ge},...h.receiptGeneration!==null&&{receiptGeneration:h.receiptGeneration},...h.pageGeneration!==null&&xr.test(c)&&{pageGeneration:h.pageGeneration},...h.adopted&&{adopted:h.adopted}})}catch{x=null}f=!1,y=null,!z&&(h.undecided?xe(c,u,h,x||{status:0}):S===T&&u.awaiting.includes(h)&&De(c,u,h,x||{status:0}),b())}function xe(l,c,u,{status:h,body:S}){if(delete u.undecided,!c.awaiting.includes(u))return;if((S?.stale===!0||Nn(h)||h>=400&&h<500&&!$n(h))&&!u.uncertain){u.refused=!0,u.sent=!1,u.seq=null,u.epoch!==T&&(u.receiptGeneration=ee),u.epoch!==T&&(u.pageGeneration=w);return}if(!Y.has(l)){h>=200&&h<300&&Number.isInteger(S?.seq)&&!S?.stale?u.seq=S.seq:(u.uncertain=!0,u.uncertainSince??=u.sentOn);return}c.awaiting.splice(c.awaiting.indexOf(u),1);let I=t.get(l)?.store;I?.rebase(I.authoritative,{source:"state",through:u.through,cause:"decided"})}function Ve(){for(let[l,c]of ce){if(!Y.has(l))continue;let u;for(;c.awaiting.length&&c.awaiting[0].seq!==null&&c.awaiting[0].seq<=D;)u=c.awaiting.shift().through;if(u===void 0)continue;let h=t.get(l)?.store;h?.rebase(h.authoritative,{source:"state",through:u,cause:"settled"})}}function De(l,c,u,{status:h,body:S,retryAfter:x}){if(h>=200&&h<300){if(ue=lt,S?.stale){u.sent=!1,u.refused=!0,S.epoch!==T?ne():b();return}if(S?.epoch&&S.epoch!==T){ne();return}u.seq=Number.isInteger(S?.seq)?S.seq:null,$(l,{phase:"landed",n:u.n,seq:u.seq,through:u.through}),Ve();return}if($n(h)){if(u.sent=!1,$(l,{phase:"retry",code:S?.code??(h===0?"offline":h===429?"rate-limited":"server"),n:u.n,through:u.through,retryAfter:x??null}),Nn(h)?u.refused=!0:(u.uncertain=!0,u.uncertainSince??=u.sentOn),h===503&&S?.code==="not-connected"){ge=null,ne();return}if(h===503&&S?.code==="busy"){$(l,{phase:"left",code:"busy",n:u.n,through:u.through}),console.warn(`clay.live("${l}"): the room is full, so it stays at save speed for now`),Y.delete(l),M(l,c),C(ne,(x>0?x:60)*1e3);return}if(u.uncertain&&u.sentOn!==he){ne();return}k=_()+(x>0?x*1e3:ue),ue=Math.min(ue*2,_t);return}if(Er.has(h)){$(l,{phase:"refused",code:"revoked",n:u.n,through:u.through}),u.uncertain||(u.refused=!0),kt();return}let I=S?.error||S?.code||`status ${h}`;if(h===404){$(l,{phase:"left",code:"no-store",n:u.n,through:u.through}),console.warn(`clay.live("${l}"): the room has no such store, so it stays at save speed (${I})`),u.refused=!0,Y.delete(l),M(l,c,!1);return}if(c.awaiting.splice(c.awaiting.indexOf(u),1),h===413&&!S?.code&&u.entries?.length>1&&oe>Rn){oe=Rn,console.warn(`clay.live("${l}"): the host takes smaller updates, so they go in frames of ${oe} bytes`),c.unsent.unshift(...u.entries),u.adopted&&(c.adopted={rev:u.adopted,through:u.through}),c.framed=u.first-1;return}let G=t.get(l)?.store,me=S?.code??(h===413&&u.entries?.length===1?"too-large":"refused");$(l,{phase:"refused",code:me,n:u.n,from:u.first,through:u.through,...S?.code==="receipt-expired"&&{ops:u.ops}}),console.warn(`clay.live("${l}"): the host refused an update, so it was undone (${I})`),G?.rebase(G.authoritative,{source:"state",drop:u.first===void 0?void 0:[u.first,u.through],through:u.first===void 0?u.through:void 0,cause:"refused"}),S?.code==="receipt-expired"&&ne()}function pt(l){D=l.seq;let c=t.get(l.name)?.store;if(!c||Me.has(l.name))return;if(!Y.has(l.name)){be=!0;return}let u=c.checkOps(l.ops);if(!u){ne();return}let h,S=l.from===O;if(S){let x=Z(l.name),I=x.awaiting.findIndex(G=>G.n===l.n);I>=0&&(h=x.awaiting[I].through,$(l.name,{phase:"echoed",n:l.n,seq:l.seq,through:h}),x.awaiting.splice(0,I+1))}c.rebaseOps(u,{source:S?"state":"remote",through:h,frame:{seq:l.seq,from:l.from,n:l.n,ops:l.ops}}),t.get(l.name).last=l.seq,i(),l.checkpoint===!0&&d(),Ve()}function Xe(l){if(!(z||!l||!Number.isInteger(l.seq))){if(!X){ae.push(l),ae.length>kr&&ae.shift();return}if(l.epoch!==T){ae.push(l),ne();return}if(!(l.seq<=D)){if(l.seq!==D+1){ae.push(l),ne();return}pt(l)}}}function ke(l,c){let u=c.seen?c.seen[O]??0:null,h=[],S=[];for(let x of l)u!==null&&x.n<=u||We(c.saved,x.n)?S.push(...x.entries.map(I=>I.id)):x.sent&&x===y?(x.undecided=!0,h.push(x)):A(x)?h.push(x):S.push(...x.entries.map(I=>I.id));return{resend:h,dropIds:S}}function Ge(l,c,u,h){let S=q(l);if(!S.length)return!1;if(!h){let x=new Set;for(let I of c.awaiting)if(We(u.saved,I.n))for(let G of I.entries??[])x.add(G.id);if(S.every(I=>x.has(I)))return!1}return g(l,S)?!0:(p(l,c),!1)}function en(l,c=0){if(z||!l||typeof l.epoch!="string")return;if(te++,l.epoch===T&&Number.isInteger(l.seq)&&l.seq<D){tn();return}let u=l.epoch!==T;J=Number.isInteger(l.provenanceVersion)?l.provenanceVersion:0,ee=Number.isSafeInteger(l.receiptGeneration)?l.receiptGeneration:null;let h=w;w=typeof l.pageTransition?.id=="string"?l.pageTransition.id:null;let S=w!==h,x=!1;be=!1,T=l.epoch,D=Number.isInteger(l.seq)?l.seq:0,de=l.writer??null,"conn"in l&&(ge=l.conn);let I=l.stores||{};Y=new Set(Object.keys(I));for(let H of Me)Y.delete(H);let G=!1,me=!1;for(let[H,ye]of t){if(Me.has(H))continue;let K=I[H],j=Z(H);p(H,j);let fr=j.room;if(j.room=!!K,!K){j.out||(fr&&S&&$(H,{phase:"left",code:"no-store"}),M(H,j,!1)),j.after!==void 0&&c>=j.after&&(j.after=void 0,j.deferred=!1,P(H));continue}let nn=j.after!==void 0&&c<j.after;if(nn||Ge(H,j,K,u||j.stale===!0)){Y.delete(H),j.deferred=!0,u&&(j.stale=!0),nn&&(me=!0),G=!0;continue}let rn=u||j.stale===!0;j.deferred=!1,j.stale=!1,j.after=void 0;let dr=ye.store.handle.status.mode==="file";j.out=!1,ye.store.setMode("fast"),ye.last=Number.isInteger(K.last)?K.last:0,ye.landed=Number.isInteger(K.landed)?K.landed:0;let on=[];if(!rn&&ee!==null){let Te=K.seen?.[O];j.awaiting=j.awaiting.filter(ie=>We(K.saved,ie.n)||Te!==void 0&&ie.n<=Te||ie.seq!==null&&ie.seq<=D||(ie.receiptGeneration??0)===ee?!0:(on.push(...ie.entries.map(le=>le.id)),$(H,{phase:"refused",code:"receipt-expired",n:ie.n,from:ie.first,through:ie.through,ops:ie.ops}),console.warn(`clay.live("${H}"): the room retired an update receipt, so the update was not replayed. Check the saved value before restoring it.`),!1))}if(rn){let{resend:Te,dropIds:ie}=ke(j.awaiting,K);for(let qe of Te)qe.undecided||(qe.sent=!1,qe.seq=null,qe.receiptGeneration=ee,qe.pageGeneration=w);j.awaiting=Te,ye.store.rebase(K.value,{source:"state",dropIds:ie,room:{seq:D,fresh:!0,moves:l.moves?.[H]??null,floor:Number.isInteger(K.floor)?K.floor:null}}),j.unsent=s(H,j)}else{let Te=K.seen?K.seen[O]:void 0,ie=[],qe=[...on];for(let le of j.awaiting)We(K.saved,le.n)?qe.push(...le.entries.map(Ze=>Ze.id)):le===y?ie.push(le):le.seq!==null&&le.seq<=D||Te!==void 0&&le.n<=Te?qe.push(...le.entries.map(Ze=>Ze.id)):le.seq!==null?ie.push(le):!le.uncertain||Te!==void 0||le.uncertainSince===he?(le.sent=!1,ie.push(le)):qe.push(...le.entries.map(Ze=>Ze.id));j.awaiting=ie,ye.store.rebase(K.value,{source:"state",dropIds:qe,room:{seq:D,fresh:!1,moves:l.moves?.[H]??null,floor:Number.isInteger(K.floor)?K.floor:null}}),dr&&(j.unsent=s(H,j),x=!0)}P(H)}G&&(be=!0),(u||x)&&r(T),i(),n(),tn(),me&&ne()}function tn(){X=!0;let l=ae.filter(c=>c.epoch===T&&c.seq>D).sort((c,u)=>c.seq-u.seq);ae=[];for(let c of l)Xe(c);b()}async function ne(){if(z)return;if(pe){we=!0;return}pe=!0,we=!1,X=!1;let l={connection:he,stateCount:te,read:++Ce},c=null,u=typeof AbortController=="function"?new AbortController:null,h=new Promise(S=>{W=C(()=>{W=null,u?.abort(),S(null)},Sr)});try{c=await Promise.race([e.fetchState(O,T!==null&&D>0&&!be?{epoch:T,seq:D}:null,u?{signal:u.signal}:{}),h])}catch{}if(W!==null&&U(W),W=null,pe=!1,!z){if(l.connection!==he||we){B&&ne();return}if(l.stateCount!==te){if(X)return;c=null}if(c&&typeof c.epoch=="string"){re=lt,en(c,l.read);return}if(c&&Or.has(c.status)){kt();return}if(c&&c.status===503){let S=c.code==="busy";for(let[x,I]of t)I.store.handle.status.mode==="fast"&&($(x,{phase:"left",code:S?"busy":"unavailable"}),console.warn(`clay.live("${x}"): the host has no room for this document now, so it stays at save speed for now`),M(x,Z(x)));if(Y=new Set,!B)return;S||c.retryAfter>0?(re=lt,C(ne,(c.retryAfter>0?c.retryAfter:60)*1e3)):(C(ne,re),re=Math.min(re*2,_t));return}B&&(C(ne,re),re=Math.min(re*2,_t))}}function kt(){if(!z){z=!0,L!==null&&U(L),L=null,W!==null&&U(W),W=null,Oe?.();for(let[l,c]of t){let u=ce.get(l);u?.out||(u?M(l,u):(o(l,{epoch:T,seq:D}),c.store.setMode("file")))}F()}}let cr={open(l){O=l.clientId,B=!0,he++,ne()},close(){B=!1,he++,X=!1,ae=[]},frame:Xe,state(l){be&&l&&!("moves"in l)?ne():en(l)},writer(l){if(!(!l||l.epoch!==T)){if(de=l.writer??null,l.landed&&typeof l.landed=="object"){te++;for(let[c,u]of Object.entries(l.landed)){let h=t.get(c);h&&Number.isInteger(u)&&(h.landed=u,$(c,{phase:"checkpointed",seq:u}))}a()}n()}}};return{start(){!Oe&&!z&&(Oe=e.start(cr))},local(l,c,u){if(z||T===null||!Y.has(l))return;let h=Z(l),S=u-c.length+1;c.forEach((x,I)=>h.unsent.push({id:S+I,op:x})),b()},abandon(l){if(Me.has(l))return;Me.add(l),Y.delete(l);let c=Z(l);c.awaiting=c.awaiting.filter(u=>u===y),c.unsent=[],c.adopted=null},adopted(l,c,u){if(z||!Y.has(l))return;let h=Z(l),S=h.awaiting.find(x=>!x.sent&&x.through>=u);S?S.adopted=c:h.adopted={rev:c,through:u}},release(l,{read:c=!1}={}){if(z)return;let u=Z(l);if(u.deferred||c){u.after=Ce+1,T!==null&&B&&ne();return}T!==null&&Y.has(l)&&(p(l,u),u.unsent=s(l,u),b())},framed(l){return ce.get(l)?.n??0},pendingFrames(l,c,{reserve:u=!1}={}){let h=ce.get(l);if(u&&h&&O&&T===c?.epoch){let G=s(l,h);for(;G.length;){let me=bt({name:l,n:h.n+1,ops:[],epoch:T}),H=0;for(;H<G.length&&H<Tn;){let j=bt(G[H].op)+1;if(H&&me+j>oe)break;me+=j,H++}let ye=G.splice(0,H),K={n:++h.n,ops:ye.map(j=>j.op),entries:ye,first:ye[0].id,through:ye[ye.length-1].id,seq:null,sent:!1,refused:!0,epoch:T,client:O,receiptGeneration:ee,pageGeneration:w};je(h,K),h.awaiting.push(K),h.framed=K.through}h.unsent=[]}let S=new Set(t.get(l)?.store.pendingEntries().map(G=>G.id)??[]),x=[],I=!0;for(let G of h?.awaiting??[]){let me=G.entries.filter(H=>S.has(H.id));if(me.length){if(me.length!==G.entries.length||G.epoch!==c?.epoch||!G.client){I=!1;continue}x=Fe(x,[[G.client,[[G.n,G.n]]]])}}return{frames:x,complete:I}},captured(l,c,u){let h=ce.get(l);if(!h||!c||c.epoch!==T)return[];let S=vt(u),x=[];return h.awaiting=h.awaiting.filter(I=>{let G=I.epoch===c.epoch&&(st(S,I.client,I.n)||I.seq!==null&&I.seq<=c.seq);return G&&x.push(...I.entries.map(me=>me.id)),!G}),x},refresh(){T!==null&&B&&ne()},storeOpened(){T!==null&&B&&ne()},roomBound(l){return!z&&ce.get(l)?.room===!0},isWriter(){return de!==null&&de===O},get status(){return{connected:B,synced:X,epoch:T,seq:D,writer:de,clientId:O,stopped:z,provenanceVersion:J,receiptGeneration:ee}},stop:kt}}var Je=[0,1e4,3e4],Tr=6e3,Rr=2;async function $r(e){let t=globalThis.crypto&&globalThis.crypto.subtle;if(!t)return null;try{let r=new TextEncoder().encode(String(e)),o=await t.digest("SHA-256",r),n=new Uint8Array(o),i="";for(let a=0;a<n.length;a+=1)i+=n[a].toString(16).padStart(2,"0");return i}catch{return null}}function Nr(e){let t=[];for(let r of e||[]){let o=r&&r.saveId;if(typeof o=="string"&&o&&!t.includes(o)&&t.push(o),t.length>=Rr)break}return t}function Ir(e,t,r){return!!(e&&typeof e=="object"&&e.saveId===t&&e.requestHash===r&&e.status==="applied")}function In({query:e,digest:t=$r,now:r=()=>Date.now(),setTimer:o=setTimeout,clearTimer:n=clearTimeout}={}){function i({captureId:a,html:d,attempts:m,initialOutcome:q,startedAt:g,onApplied:P,onUnknown:F}){let _=g+45e3,C=Nr(m),U=new Set,O=new Set,B=d,X=null,T=!1;function ee(f,y){try{typeof f=="function"&&f(y)}catch(v){console.error("clayjs: save-history callback failed:",v)}}function w(){T=!0,B=null;for(let f of U)n(f);U.clear();for(let f of O)f.abort();O.clear()}function J(f,y){T||(w(),ee(P,{captureId:a,saveId:f,requestHash:y}))}function D(f){T||(w(),ee(F,{captureId:a,reason:f}))}function de(f,y){let v=null;return v=o(()=>{v!==null&&U.delete(v),f()},Math.max(0,y)),U.add(v),v}function Y(f){f!==null&&(n(f),U.delete(f))}async function ae(f){if(T)return;let y=_-r();if(y<=0)return;let v=new AbortController;O.add(v);let k=de(()=>v.abort(),Math.min(Tr,y)),L=null;try{L=await e({saveId:f,requestHash:X,signal:v.signal})}catch{L=null}finally{Y(k),O.delete(v)}T||Ir(L,f,X)&&J(f,X)}function pe(){if(!T&&!(r()>=_))for(let f of C)ae(f)}async function z(){let f=null;try{f=await t(B)}catch{f=null}if(B=null,T)return;if(typeof f!="string"||!f){D("unavailable");return}if(X=f,q&&typeof q=="object"&&q.status==="applied"&&q.requestHash===X&&C.includes(q.saveId)){J(q.saveId,X);return}let y=r()-g;if(y>=45e3){D("expired");return}let v=-1;for(let k=0;k<Je.length;k+=1)Je[k]<=y&&(v=k);if(v<0){for(let k=0;k<Je.length;k+=1)de(pe,g+Je[k]-r());return}pe();for(let k=v+1;k<Je.length;k+=1)de(pe,g+Je[k]-r())}return de(()=>D("expired"),_-r()),z(),{cancel(){w()}}}return{start:i}}var _r="/_/sync/data";function Pn(){return new URL(_r,window.location.origin)}async function Pr(e,t){let r=Pn();r.searchParams.set("client-id",e);try{let o=await fetch(r.href,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json","Document-URL":window.location.href,[Et]:String(1)},body:JSON.stringify(t)}),n=null;try{n=await o.json()}catch{}let i=Number(o.headers?.get?.("Retry-After"))||0;return{status:o.status,body:n,retryAfter:i}}catch{return{status:0,body:null,retryAfter:0}}}async function Cr(e,t=null,{signal:r}={}){let o=Pn();e&&o.searchParams.set("client-id",e),t&&typeof t.epoch=="string"&&Number.isInteger(t.seq)&&o.searchParams.set("since",`${t.epoch}:${t.seq}`);try{let n=await fetch(o.href,{credentials:"same-origin",cache:"no-store",headers:{"Document-URL":window.location.href,[Et]:String(1)},signal:r});if(!n.ok){let a=null;try{a=await n.json()}catch{}return{status:n.status,code:a?.code??null,retryAfter:Number(n.headers?.get?.("Retry-After"))||0}}let i=await n.json();return i&&typeof i.epoch=="string"&&i.conn===null?null:i}catch{return null}}function Cn(){return{start(e){return vn({open(t){t.lane==="live"&&e.open(t)},close:()=>e.close(),event(t,r){t==="data"?e.frame(r):t==="data-state"?e.state(r):t==="data-writer"&&e.writer(r)}})},send:Pr,fetchState:Cr}}function Ln(e,t){return!t||!Number.isInteger(t.seq)?null:t.seq>=(e.last??0)?[]:t.seq<(e.floor??0)?null:e.log.filter(r=>r.seq>t.seq).map(r=>({seq:r.seq,ops:r.ops}))}var Lr=4,jr=2e3,Br=500,Fr=1024,Dr=256*1024;function jn(e,t){let r=[],o=()=>{for(let n=r.length-1;n>=0;n--)nt(r[n])};try{for(let n of t){let i=mt(e,n);i&&(r.push(i),e=i.root)}}catch(n){throw o(),n}return{value:e,undo:o}}var Gr=new TextEncoder,Bn="page-format:1";function Dn(){return typeof BroadcastChannel=="function"&&typeof navigator<"u"&&typeof navigator.locks?.request=="function"}function Fn(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2)+Date.now().toString(36)}function Gn({seed:e,key:t="clay-live:"+window.location.pathname,channel:r=null,floor:o=0}){let n=Fn(),i=o>=1?1:0,a=i?`${t}:${Bn}`:t,d=null,m=null,q=null,g=null,P=!1,F=null,_=!1,C=null,U=0,O=0,B=new Map,X=new Map,T=new Set,ee=new Map,w={epoch:null,seq:0,sequencer:null,closedBy:null,stale:!1,seen:new Map,stores:new Map};function J(s){d?.post(s)}function D(s,p){for(p.bytes=Gr.encode(JSON.stringify(p.ops)).length,s.log.push(p),s.logBytes+=p.bytes;s.log.length>Fr||s.logBytes>Dr;){let A=s.log.shift();s.logBytes-=A.bytes,s.floor=A.seq}}function de(s){let p=w.stores.get(s.name);p&&(p.value=jn(p.value,s.ops).value,p.last=s.seq,p.ephemeral||D(p,{seq:s.seq,ops:s.ops})),w.seq=s.seq;let A=s.name+`
|
|
2
|
-
`+s.from;(w.seen.get(A)??0)<s.n&&w.seen.set(A,s.n)}function Y(s){let p={};for(let[A,M]of w.seen){let b=A.indexOf(`
|
|
3
|
-
`);A.slice(0,b)===s&&(p[A.slice(b+1)]=M)}return p}let ae=s=>s.behind||s.landed===null?-1:s.landed;function pe(s){let p={},A={};for(let[b,N]of w.stores)p[b]={value:Q(N.value),ephemeral:N.ephemeral,seen:Y(b),last:N.last,landed:ae(N)},A[b]={log:N.log,last:N.last,landed:N.landed,floor:N.floor,behind:N.behind,file:N.file,inFile:N.inFile};let M={epoch:g.epoch,seq:g.seq,writer:n,stores:p,mirror:{seen:[...w.seen],stores:A}};if(s!==void 0){let b=s&&s.epoch===w.epoch&&Number.isInteger(s.seq)?s.seq:0,N={};for(let[se,xe]of w.stores)N[se]=Ln(xe,{seq:b});M.moves=N}return M}function z(s,p){return s?.file?p.seq!=null&&s.file.seq!=null?p.seq<=s.file.seq:s.file.hash===rt(V(Re(p.text))):!1}function f(){for(let[s,p]of ee)try{z(w.stores.get(s),p)&&ee.delete(s)}catch{ee.delete(s)}}function y(s){if(g||!s||typeof s.epoch!="string"||!Number.isInteger(s.seq)||!s.mirror||T.has(s.epoch)||s.epoch===w.epoch&&s.seq<w.seq)return!1;w.epoch!==null&&s.epoch!==w.epoch&&T.add(w.epoch);let p=new Map;for(let[A,M]of Object.entries(s.stores||{})){let b=s.mirror.stores?.[A]||{},N=Array.isArray(b.log)?b.log:[];p.set(A,{value:Q(M.value),ephemeral:M.ephemeral===!0,log:N,logBytes:N.reduce((se,xe)=>se+(xe.bytes||0),0),last:Number.isInteger(b.last)?b.last:0,landed:Number.isInteger(b.landed)?b.landed:null,floor:Number.isInteger(b.floor)?b.floor:0,behind:b.behind===!0,file:b.file||null,inFile:Array.isArray(b.inFile)?[...b.inFile]:[]})}return w={epoch:s.epoch,seq:s.seq,sequencer:s.writer??null,closedBy:null,stale:!1,seen:new Map(s.mirror.seen||[]),stores:p},f(),O+=1,!0}function v(){let s=pe();J({type:"data-state",state:s}),q.state(s)}function k(){w.epoch!==null&&T.add(w.epoch),w.epoch=Fn(),w.seq=0;for(let s of w.stores.values())s.log=[],s.logBytes=0,s.last=0,s.landed=null,s.floor=0,s.behind=!0,s.file=null,s.inFile=[]}function L({fresh:s}){let p=w.epoch===null;p&&k();for(let[M,b]of e())w.stores.has(M)||w.stores.set(M,{value:Q(b.value),ephemeral:b.ephemeral,log:[],logBytes:0,last:0,landed:0,floor:0,behind:!1,file:null,inFile:[]});w.stale=!1,w.sequencer=n,w.closedBy=null;let A=new Map;for(let[M,b]of w.seen)A.set(M,{n:b,seq:0});g={epoch:w.epoch,seq:w.seq,lastN:A};for(let[M,b]of ee){let N=w.stores.get(M);if(!(!N||N.ephemeral)){try{if(z(N,b))continue}catch{continue}we(M,b)}}ee.clear(),s&&!p&&(k(),g.epoch=w.epoch,g.seq=0),O+=1,v()}function W(){k(),g.epoch=w.epoch,g.seq=0,O+=1,v()}function ue(){g&&(J({type:"closed",from:n,state:pe()}),g=null,F?.(),F=null)}function oe(s){return w.closedBy!==null&&(s===null||w.closedBy===s)?Promise.resolve(!0):new Promise(p=>{let A=setTimeout(()=>{C=null,p(!1)},Br);C={sequencer:s,resolve(M){clearTimeout(A),C=null,p(M)}}})}function re(){_||P||(_=!0,navigator.locks.request(a,async()=>{if(P)return;let s=await oe(w.sequencer);if(!P)return L({fresh:w.epoch===null||!s}),new Promise(p=>{F=p})}).catch(()=>{}).finally(()=>{_=!1}))}function he(s,p){if(!p||typeof p.name!="string"||!Number.isInteger(p.n)||p.n<1||!Array.isArray(p.ops)||!p.ops.length)return{status:400,body:{error:"bad-frame"},retryAfter:0};let A=w.stores.get(p.name);if(!A)return{status:404,body:{error:"unknown-store"},retryAfter:0};let M=p.name+`
|
|
4
|
-
`+s,b=g.lastN.get(M);if(b&&p.n<=b.n)return{status:200,body:{duplicate:!0,seq:b.seq,epoch:g.epoch},retryAfter:0};let N;try{N=p.ops.map(Qe),jn(A.value,N).undo()}catch(xe){return{status:422,body:{error:xe.message},retryAfter:0}}g.seq+=1,g.lastN.set(M,{n:p.n,seq:g.seq});let se={epoch:g.epoch,seq:g.seq,name:p.name,ops:N,from:s,n:p.n};return de(se),J({type:"data",data:se}),q.frame(Q(se)),{status:200,body:{seq:g.seq,epoch:g.epoch},retryAfter:0}}function ge(s){if(!g||!s.length)return;let p={};for(let A of s){let M=w.stores.get(A);M&&(p[A]=ae(M))}q.writer({epoch:g.epoch,writer:n,landed:p})}function te(s,p){let A=w.stores.get(s);return!A||A.ephemeral||!p||p.epoch!==w.epoch||!Number.isInteger(p.seq)||!A.behind&&A.landed!==null&&p.seq<=A.landed?!1:(A.landed=p.seq,A.behind=!1,!0)}function we(s,{text:p,at:A,seq:M}){let b=w.stores.get(s);if(!b||b.ephemeral)return null;let N;try{N=Q(Re(p))}catch{return null}if(N===null||typeof N!="object"||Array.isArray(N)!==Array.isArray(b.value))return null;let se={seq:M??null,hash:rt(V(N))},xe=!!A&&A.epoch===w.epoch&&A.seq<=g.seq,Ve=xe&&A.hash===se.hash,De=xe?A.seq:b.behind?null:b.landed;if(De===null||De<b.floor){let ke=!b.behind;return b.behind=!0,b.file=se,{changed:!1,moved:ke}}let pt=b.log.filter(ke=>ke.seq>De&&(Ve||!b.inFile.includes(ke.seq)));Ve&&(b.inFile=[]);for(let ke of pt)for(let Ge of ke.ops)try{et(N,Ge),N=tt(N,Ge)}catch{}let Xe=!1;if(V(N)!==V(b.value)){let ke=bn(b.value,N);b.value=N,g.seq+=1,w.seq=g.seq,b.last=g.seq,D(b,{seq:g.seq,ops:ke}),b.inFile=[...b.inFile.filter(Ge=>Ge>b.floor),g.seq],Xe=!0}return b.landed=pt.length?De:b.last,b.behind=!1,b.file=se,{changed:Xe,moved:!0}}function Ce(s){let p=!1,A=[];for(let[M,b]of s){let N=w.stores.get(M);if(!N||N.ephemeral)continue;if(!g){ee.set(M,b);continue}let se=we(M,b);se&&(se.changed?p=!0:se.moved&&A.push(M))}p?v():ge(A)}function be(s){return new Promise(p=>{let A=++U,M=setTimeout(()=>{B.delete(A),X.delete(A),p(null)},jr);s.type==="post"&&X.set(A,w.sequencer),B.set(A,b=>{clearTimeout(M),B.delete(A),X.delete(A),p(b)}),J({...s,from:n,rid:A})})}function Oe(s){if(!(!s||typeof s.name!="string"||typeof s.epoch!="string"||!Number.isInteger(s.seq))&&!(g||T.has(s.epoch))){if(s.epoch!==w.epoch)w.stale=!0;else if(!w.stale&&s.seq===w.seq+1)try{de(s)}catch{w.stale=!0}else s.seq>w.seq&&(w.stale=!0);q.frame(s)}}function ce(s,p){if(!(typeof s!="string"||!p)){y(p)&&(w.closedBy=s,q.state(p));for(let[A,M]of X)M===s&&B.get(A)?.(null);C&&(C.sequencer===null||C.sequencer===s)&&C.resolve(w.closedBy===s)}}function Me({data:s}){if(!(P||!s||s.v!==Lr)){if(g&&(s.type==="data"&&s.data?.epoch===g.epoch||(s.type==="data-state"||s.type==="closed")&&s.state?.epoch===g.epoch&&s.state.writer!==n)){W();return}if(!g&&s.type==="data-state"&&s.state?.epoch===w.epoch&&s.state.writer!==w.sequencer&&Number.isInteger(s.state.seq)&&s.state.seq<w.seq){J({type:"forked",epoch:w.epoch,to:s.state.writer});return}if(s.type==="forked"){g&&s.epoch===g.epoch&&s.to===n&&W();return}s.type==="data"?Oe(s.data):s.type==="data-state"?y(s.state)&&q.state(s.state):s.type==="closed"?ce(s.from,s.state):s.type==="landed"?typeof s.name=="string"&&te(s.name,s.at)&&ge([s.name]):s.type==="answer"?s.to===n&&B.get(s.rid)?.(s.result):g&&s.type==="post"?s.epoch===g.epoch&&J({type:"answer",to:s.from,rid:s.rid,result:he(s.from,s.frame)}):g&&s.type==="state-request"&&J({type:"answer",to:s.from,rid:s.rid,result:pe(s.since)})}}function $(){ue()}function Z(s){!s.persisted||P||g||_||(w.sequencer=null,w.closedBy=null,re(),q.close(),q.open({clientId:n,lane:"live"}))}function je(s,{covered:p=!1}={}){let A=s>=1?1:0,M={floor:i,scope:a};return A<=i?{status:"already",...M}:P||!d?{status:"refused",code:"lane-stopped",...M}:r?{status:"refused",code:"shared-channel",...M}:p?(ue(),m?.(),a=A?`${t}:${Bn}`:t,i=A,d=Tt(a),m=d.subscribe("durable",b=>Me({data:b})),w.sequencer=w.closedBy=null,_=!1,re(),q.close(),q.open({clientId:n,lane:"live"}),{status:"switched",floor:i,scope:a}):{status:"refused",code:"uncovered",...M}}return{clientId:n,get scope(){return a},get floor(){return i},switchScope:je,start(s){return q=s,d=r??Tt(a),m=d.subscribe("durable",p=>Me({data:p})),window.addEventListener("pagehide",$),window.addEventListener("pageshow",Z),re(),q.open({clientId:n,lane:"live"}),()=>{ue(),P=!0,C?.resolve(!1),window.removeEventListener("pagehide",$),window.removeEventListener("pageshow",Z);for(let p of B.values())p(null);m?.(),m=null,d=null}},async send(s,p){return g?he(n,p):await be({type:"post",frame:p,epoch:w.epoch})||{status:0,body:null,retryAfter:0}},async fetchState(s,p=null){if(g)return pe(p);let A=O,M=await be({type:"state-request",since:p});return g?pe(p):A!==O||!y(M)?null:M},fileFrame(s){P||Ce(s)},landed(s,p){P||!p||(te(s,p)&&ge([s]),J({type:"landed",name:s,at:{epoch:p.epoch,seq:p.seq}}))},get isSequencer(){return g!==null}}}var Wr=/^[A-Za-z0-9_.:-]{1,64}$/,R=new Map,Vn="save_"+[...crypto.getRandomValues(new Uint32Array(4))].map(e=>e.toString(16).padStart(8,"0")).join(""),Lt=0,Ur=0,Jr=45e3;function Gt(e){let t=ot(e.getAttribute("live-at"));if(!t||t.hash!==ho(e.textContent))return null;let r=e.getAttribute("live-by"),o=r===null?null:it(r);return r!==null&&!o?null:o&&o.v!==2?{disk:!0}:{epoch:t.epoch,seq:t.seq,frames:vt(o),ancestors:kn(o)}}function Yr(e,t){let r=e.leftAt;if(!r||r.disk)return null;let o=E?.pendingFrames(e.store.name,r,{reserve:t})??{frames:[],complete:!0};if(!o.complete)return null;let n=Fe(r.frames??[],o.frames),i=r.ancestors??[],a=V(e.store.value),d=JSON.stringify([r.epoch,r.seq,n,i,e.store.mark,a]);if(e.capture?.key===d)return e.capture.value;let m={v:2,frames:n,ancestors:i,capture:[Vn,Lt+1]},q=En(m),g=q?{at:Rt(r.epoch,r.seq,a),by:q}:null;return e.capture={key:d,value:g},g}var Le=new Map,Ie=null,Se=null,Ee=null,zr=In({query:e=>ln?.(e)??null}),Ae=new Map;function Xn(e){if(!e.captureOps.size)return;let t=new Set(e.store.pendingEntries().map(r=>r.id));for(let[r,o]of e.captureOps)o.ids=o.ids.filter(n=>t.has(n)),o.ids.length||e.captureOps.delete(r);[...e.captureOps.values()].some(r=>r.ended)||ft(e)}var Zn=(e,t)=>Ie===null||!fn()?!1:Le.get(Ie)?.get(e)?.key===t;function ut(e){let t=R.get(e);if(!t||!t.captureOps.size)return[];let r=new Set(t.store.pendingEntries().map(n=>n.id)),o=new Set;for(let[n,i]of t.captureOps)if(!(!i.ended&&!Zn(e,n)))for(let a of i.ids)r.has(a)&&o.add(a);return[...o]}function Ht(e){for(let[t,r]of e.captureOps)if(r.ended)return[t,r];return null}Ot({id:"live:held",isPending:()=>[...R.values()].some(e=>Ht(e))});var Hn=e=>[...e.captureOps].some(([t,r])=>!r.ended&&Zn(e.store.name,t));function Kr({op:e,path:t,n:r,value:o}){let n=t.length?t.join("."):"the whole value",i=e==="add"?`${n} + ${r}`:e==="del"?`${n} removed`:`${n} = ${JSON.stringify(o)}`;return i.length>60?`${i.slice(0,57)}...`:i}function Wt(e){clearTimeout(e.timer),e.timer=setTimeout(()=>{e.timer=null,ze(e)},Jr)}function ft(e){clearTimeout(e.timer),e.timer=null}function ze(e,{read:t=!0}={}){let r=e.store.name,o=ut(r);if(ft(e),e.withheld=!1,e.reading=!1,er(e),o.length){let n=e.store.pendingEntries().filter(m=>o.includes(m.id)).map(m=>m.op);e.store.handle.status.mode==="file"&&(e.leftAt=null),e.store.rebase(e.store.authoritative,{source:"state",dropIds:o});let i=n.slice(0,5).map(Kr).join("; "),a=n.length>5?` and ${n.length-5} more`:"",d=`A save of "${r}" ended without an answer, so ${n.length===1?"this edit was":"these edits were"} not sent again: ${i}${a}. Check the value, and redo ${n.length===1?"it":"any"} if missing.`;console.warn(`clay.live("${r}"): ${d}`,n),document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:r,code:"save-uncertain",ops:n,message:d}}))}t&&E?.release(r,{read:E.roomBound(r)})}function ct(e){Xn(e);let t=e.store.name;if(e.recovery&&!Zr(e)&&er(e),!(!e.withheld||e.reading||ut(t).length)){if(!E?.roomBound(t)){e.withheld=!1,ft(e);return}e.reading=!0,Wt(e),E.release(t,{read:!0})}}function Vr(e){let t=R.get(e);t&&(Ut(t),!(!t.withheld&&!t.reading)&&(t.withheld=!1,t.reading=!1,[...t.captureOps.values()].some(r=>r.ended)||ft(t)))}function Xr(){for(let e of R.values())if(e.recovery||e.historicalRefreshPending)return!0;return!1}function Zr(e){let t=new Set(e.store.pendingEntries().map(o=>o.id));return e.recovery.targets.find(({name:o})=>o===e.store.name)?.ids.some(o=>t.has(o))??!1}function Qr(e){if(!Ee||Ee.captureId!==e||typeof Ee.html!="string")return null;let t=[];for(let[r,o]of Ee.qualified)!R.get(r)||!o.length||t.push({name:r,ids:[...o],saved:Ee.saved.get(r)});return t.length?{captureId:e,html:Ee.html,targets:t}:null}function qt(){Ee&&(Ee.html=null)}function eo(e,t){Qn(e);let r=e.store.name;e.refreshTimer=setTimeout(()=>{if(e.refreshTimer=null,!e.historicalRefreshPending)return;let o=`The save of "${r}" that ended without an answer did happen, but the value the file holds now must load before newer edits can be saved.`;console.warn(`clay.live("${r}"): ${o}`),document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:r,code:"save-history-refresh-required",message:o}}))},Math.max(0,t-Date.now()))}function Ut(e){e.historicalRefreshPending&&(e.historicalRefreshPending=!1,Qn(e))}function Qn(e){e.refreshTimer!==null&&(clearTimeout(e.refreshTimer),e.refreshTimer=null)}function er(e){let t=e.recovery;t&&(e.recovery=null,!t.targets.some(r=>R.get(r.name)?.recovery===t)&&(Ae.delete(t.captureId),t.run?.cancel()))}function tr(e){if(e==null)return;let t=Ae.get(e);if(t){Ae.delete(e);for(let r of t.targets){let o=R.get(r.name);o&&o.recovery===t&&(o.recovery=null)}t.run?.cancel()}}function to(e,{result:t,attempts:r,startedAt:o}){let{captureId:n,html:i}=e,a={captureId:n,deadline:o+45e3,targets:e.targets,run:null};Ae.set(n,a);for(let d of e.targets){let m=R.get(d.name);ft(m),m.recovery=a}ht("save-history").then(d=>{if(Ae.get(n)===a){if(e.html=null,!d)return Wn(n);a.run=zr.start({captureId:n,html:i,attempts:r,initialOutcome:t?.saveOutcome??null,startedAt:o,onApplied:({saveId:m,requestHash:q})=>no(n,m,q),onUnknown:({reason:m})=>ro(n,m)})}},()=>{e.html=null,Wn(n)})}function no(e,t,r){let o=Ae.get(e);if(o){Ae.delete(e);for(let n of o.targets){let i=R.get(n.name);if(!i||i.recovery!==o)continue;i.recovery=null,i.historicalRefreshPending=!0;let a=new Set(i.store.pendingEntries().map(m=>m.id)),d=n.ids.filter(m=>a.has(m));if(i.store.rebase(JSON.parse(n.saved),{source:"state",dropIds:d}),!E){Ut(i);continue}E.release(i.store.name,{read:!0}),eo(i,o.deadline)}}}function Wn(e){let t=Ae.get(e);if(t){Ae.delete(e);for(let r of t.targets){let o=R.get(r.name);if(!(!o||o.recovery!==t)){if(o.recovery=null,!E?.roomBound(o.store.name)){ze(o,{read:!1});continue}o.withheld=!0,o.reading=!0,Wt(o),E.release(o.store.name,{read:!0})}}}}function ro(e,t){let r=Ae.get(e);if(r){Ae.delete(e);for(let o of r.targets){let n=R.get(o.name);!n||n.recovery!==r||(n.recovery=null,ze(n))}}}function oo(e,t,r){let o=e.captureOps.get(t),n=e.store.name;if(!o){e.store.handle.status.mode==="file"&&(e.leftAt=null);return}if(o.ended=!0,r?.has(n)){e.withheld=!0,e.reading=!0;return}if(!E?.roomBound(n)){ze(e,{read:!1});return}e.withheld=!0,e.reading=!0,Wt(e),E.release(n,{read:!0})}function jt(e){if(Array.isArray(e))return e.map(jt);if(e===null||typeof e!="object")return e;let t={};for(let r of Object.keys(e).sort())t[r]=jt(e[r]);return t}function Jt(e){try{return JSON.stringify(jt(Re(e)))}catch{return null}}var fe=null,dt=()=>!fe||fe.admitted;function so(){if(!He||!dt())return!1;for(let e of R.values())if(!e.store.ephemeral){if(e.store.handle.status.mode==="fast"){if(E?.isWriter()&&e.landed<e.last)return!0}else if(e.store.pending.length>0)return!0}return!1}var Bt=new Set;function nr(){for(let e of[...Bt])e()}var ve=Mn({needsSave:so,blocked:()=>!dt()||!yn()||mn()||gn()||Xr(),save:()=>Mt().finally(nr),saveNow:()=>cn(!0,()=>Mt())}),E=null,Ft=!1,Dt=0,St=null,Yt=!1,_e=null,zt=!1;function Kt(){return[...R.values()].filter(e=>!e.store.ephemeral)}function rr(){if(!fe||fe.admitted||!E||E.status.stopped)return!1;for(let e of Kt())if(e.store.handle.status.mode==="fast"&&e.store.pending.length>0)return!0;return!1}async function or({timeoutMs:e=5e3}={}){let t=Date.now()+e,r=()=>{for(let o of Kt())o.store.handle.status.mode==="fast"&&o.store.pending.length>0&&E?.release(o.store.name)};for(r();rr();){if(Date.now()>=t)return{ok:!1,code:"timeout"};await new Promise(o=>setTimeout(o,5)),r()}return{ok:!0}}Ot({id:"live:writer",isPending:rr,flush:or});function io(){for(let e of R.values()){e.framesSince=!1;let t=e.store.pendingEntries().map(r=>r.id);t.length&&e.store.rebase(e.store.authoritative,{source:"state",dropIds:t})}}function lo(){let e=E;E=null,Ft=!1,Dt++,St=null,_e=null,Yt=!1,At=null,Vt=null,at=null,Ye=null,e?.stop()}function ns(){return{id:"clay:live",order:200,prepare(e={}){if(e.initial===!0)return fe||(fe={admitted:!0}),Jn(fe,{adopted:!0});sr();let t={admitted:!1,wantsLane:!0};return fe=t,io(),xt(),Jn(t)}}}function Un(){for(let e of Kt())e.store.pending.length>0&&E?.release(e.store.name)}function Jn(e,{adopted:t=!1}={}){return{enable(){t||fe!==e||(e.admitted=!0,xt(),Un())},quiesce(){if(fe===e)return e.admitted=!1,or()},resume(){fe===e&&(e.admitted=!0,Un())},dispose(){fe===e&&(fe=null,lo())}}}var At=null,Vt=null,at=null,Ye=null;function sr(){At=new Promise(e=>{at=e}),Vt=new Promise(e=>{Ye=e})}function Xt(){return At||sr(),{laneReady:At,writerReady:Vt}}function rs(){return Xt().laneReady}function os(){return Xt().writerReady}function Yn(){for(let e of R.values())if(!e.store.ephemeral&&e.store.handle.status.mode==="fast"&&e.landed===-1){ve.soon();return}ve.changed()}function Ct(e,t){e.store.rebase(e.store.authoritative,{source:"state",through:t})}function Zt(e,t,r=null){if(e)for(let[o,n]of e){let i=R.get(o);!i||n.mode!=="file"||(t||n.maybeLanded?oo(i,n.key,r):(i.captureOps.delete(n.key),ct(i)),i.store.handle.status.mode==="fast"&&E?.release(o))}}function Ke(e){let t=Le.get(e);return Le.delete(e),Ie===e&&(Ie=null),Se===e&&(Se=null),t}function ir(e,t=null){let r=t??Ie??Se;r!==null&&Zt(Ke(r),e)}function ao(e,t){let r=e?.code,o=r==="page-converting"||r==="page-capacity";return r==="save-already-applied"||e?.hadTimeout===!0||t!==!1&&!o&&!(e?.status>=400&&e?.status<500)}function zn(e){return{transport:e,entries:R,onWriter:()=>{ve.changed(),E&&E.status.writer!==null&&Ye?.(E)},onApplied:Yn,onLanded:()=>{Yn(),nr()},onCheckpoint:()=>ve.soon(),onLeave:(t,r)=>{let o=R.get(t);o?.store.handle.status.mode==="fast"&&(o.leftAt={...r,frames:[],ancestors:[]})},held:t=>ut(t).length>0,heldIds:ut,hold:t=>{let r=R.get(t);return r?r.recovery?!0:Hn(r)?(r.withheld=!0,!0):(ze(r,{read:!1}),!1):!1},taken:Vr,onStop:()=>{for(let t of R.values())Ut(t),!t.recovery&&(Hn(t)||ze(t,{read:!1}))}}}function uo(){let e=new Map;for(let[t,r]of Pe(document,{warn:!1})){let o=R.get(t);if(o){e.set(t,{value:o.store.authoritative,ephemeral:o.store.ephemeral});continue}try{let n=Re(r.element.textContent);n!==null&&typeof n=="object"&&e.set(t,{value:n,ephemeral:r.ephemeral})}catch{}}return e}function xt(){if(Xt(),Ft||!(fe?fe.admitted||fe.wantsLane:He))return;Ft=!0;let e=++Dt;ht("live-data").then(async t=>{let r=t&&await ht("live-provenance");if(e===Dt){if(St=t,Yt=r,t)E=Pt(zn(Cn()));else if(Dn())_e=Gn({seed:uo,floor:document.querySelector('meta[name="clay-page-format"]')?.getAttribute("content")}),E=Pt(zn(_e));else{at?.(null),Ye?.(null);return}for(let o of Pe(document,{warn:!1}).keys())if(!R.has(o))try{ar(o)}catch{}for(let[o,n]of R)n.historicalRefreshPending&&E.release(o,{read:!0});E.start(),at?.(E),E.status.writer!==null&&Ye?.(E)}}).catch(()=>{at?.(null),Ye?.(null)})}function co(e){let t=(e||"").split(";")[0].trim().toLowerCase();return t==="application/json"||t.endsWith("+json")}function Pe(e=document,{warn:t=!0}={}){let r=new Map,o=new Set;for(let n of e.querySelectorAll('script[merge][clay~="live"]')){if(n.hasAttribute("src")||!co(n.getAttribute("type")))continue;let i=n.getAttribute("merge");if(Wr.test(i)){if(r.has(i)){o.add(i);continue}r.set(i,{name:i,ephemeral:n.getAttribute("clay").split(/\s+/).includes("ephemeral"),element:n})}}for(let n of o)t&&console.warn(`clay.live: more than one live tag is named "${n}", so none of them is live`),r.delete(n);return r}function Qt(e){return new DOMParser().parseFromString(e,"text/html")}function fo(e){let t=e.store.handle.status.mode==="fast",r=t?e.store.authoritative:e.store.value,o=t&&/^page(\.[0-9]+)?$/.test(e.store.name)?qn(r):r;return e.layout==="lines"?po(o):e.layout==="pretty"?JSON.stringify(o,null,2).replace(/</g,"\\u003c"):V(o)}var Kn=e=>e!==null&&typeof e=="object"&&!Array.isArray(e);function po(e){return Kn(e)?`{${Object.entries(e).map(([r,o])=>!Kn(o)||!Object.keys(o).length?`${V(r)}:${V(o)}`:`${V(r)}:{
|
|
5
|
-
${Object.entries(o).map(([n,i])=>`${V(n)}:${V(i)}`).join(`,
|
|
6
|
-
`)}
|
|
7
|
-
}`).join(`,
|
|
8
|
-
`)}}`:V(e)}function ho(e){try{return rt(V(Re(e)))}catch{return null}}function go(e,t,r,o){let n;try{n=Re(t)}catch{return}e.store.rebase(n,{source:r,...o?.length&&{dropIds:o}})&&(e.framesSince=!0)}function lr(e,t,{layout:r="line",leftAt:o=null,staged:n=null}={}){let i={store:t,layout:r,framesSince:!1,last:0,landed:0,leftAt:o,captureOps:new Map,withheld:!1,reading:!1,timer:null,recovery:null,historicalRefreshPending:!1,refreshTimer:null,staged:n};return R.set(e,i),t.onDelivery(a=>{a.code==="receipt-expired"&&document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:e,code:a.code,ops:a.ops,message:"The room retired an update receipt. Check the saved value before restoring this update."}})),a.phase==="refused"&&a.code==="too-large"&&!/^page(\.[0-9]+)?$/.test(e)&&document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:e,code:"op-too-large",message:"That change was too large to share, so it was undone."}})),a.phase==="left"&&a.code==="no-store"&&/^page(\.[0-9]+)?$/.test(e)&&document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:e,code:"unknown-store",message:`The room has no "${e}" store, so the page it holds is not the one this tab is editing.`}}))}),t.onRebase(a=>{ct(i),t.handle.status.mode==="file"&&["undone","refused","decided"].includes(a.cause)&&(i.leftAt=null)}),t.ephemeral||t.onLocal(()=>ve.changed()),t.onLocal(a=>{!i.staged&&dt()&&E?.local(e,a,t.mark)}),t.handle.on("change",()=>{!t.ephemeral&&t.handle.status.mode==="fast"&&ve.changed()}),n||(E?.storeOpened(e),xt()),i}function ar(e){let t=R.get(e);if(t)return t.store.handle;let r=Pe().get(e);if(!r)throw new Error(`clay.live: this page has no <script type="application/json" merge="${e}" clay="live"> tag`);let o=r.element.textContent,n;try{n=Re(o)}catch(m){throw new SyntaxError(`clay.live("${e}"): the tag's JSON does not parse: ${m.message}`)}let i=It({name:e,value:n,ephemeral:r.ephemeral}),a=r.element.getAttribute("live-format")==="lines"?"lines":o.includes(`
|
|
9
|
-
`)?"pretty":"line";return lr(e,i,{layout:a,leftAt:Gt(r.element)}).store.handle}function ss(e,{value:t,represented:r=null,signal:o=null}={}){let n=R.get(e);if(n&&!n.staged)throw new Error(`clay.live("${e}"): the store is open in a room`);let i=n??lr(e,It({name:e,value:t,ephemeral:!1}),{staged:{represented:r,signal:o}});return{handle:i.store.handle,isPending:()=>!!i.staged&&i.store.pending.length>0,flush:(a={})=>mo(i,a),dispose(){i.staged&&R.get(e)===i&&R.delete(e)},close(){R.get(e)===i&&R.delete(e)}}}async function mo(e,{timeoutMs:t=1e4}={}){let r=e.staged;if(!r||!e.store.pending.length)return{ok:!0};if(r.conflict)return{ok:!1,code:r.conflict};let o=r.represented?.etag||null,n=an();if(o&&n&&o!==n)return{ok:!1,code:"stale-document"};o&&!n&&un(o);let i=await qo({timeoutMs:t});return i.ok?{ok:!0}:{ok:!1,code:r.conflict??i.code??null}}function yo(e){e.staged&&(e.staged=null,e.tagless=!0,E?.storeOpened(e.store.name),xt())}sn((e,{forSave:t,requestRefresh:r})=>{if(!R.size)return;let o=Pe(e,{warn:!1});for(let n of R.values()){if(n.store.ephemeral)continue;let i=o.get(n.store.name);if(!i&&(n.staged||n.tagless)){let m=e.querySelector("article[data-page]");if(!m)continue;let q=m.ownerDocument.createElement("script");q.setAttribute("type","application/json"),q.setAttribute("merge",n.store.name),q.setAttribute("clay","live"),m.parentNode.insertBefore(q,m),i={name:n.store.name,ephemeral:!1,element:q}}if(!i)continue;if(t&&(n.recovery||n.historicalRefreshPending)){let m=n.historicalRefreshPending;m&&r&&E?.release(n.store.name,{read:!0});let q=m?"save-history-refresh-required":"save-history-pending",g=m?`clay.live("${n.store.name}"): the earlier save happened, but the current value must load before newer edits can be saved. Your edits are still in this tab.`:`clay.live("${n.store.name}"): a save ended without an answer, so the saved value must be checked before this one is sent. Your edits are still in this tab.`;throw console.warn(`clay.live("${n.store.name}"): ${g}`),m||document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:n.store.name,code:q,message:g}})),Object.assign(new Error(g),{code:q})}let a=t&&n.store.handle.status.mode==="file"?Ht(n)?.[1]:null;if(a){i.element.textContent=a.text;for(let[m,q]of[["live-at",a.at],["live-by",a.by]])q===null?i.element.removeAttribute(m):i.element.setAttribute(m,q);continue}let d=fo(n);if(i.element.textContent=d,n.store.handle.status.mode==="fast"&&E)i.element.setAttribute("live-at",Rt(E.status.epoch,E.status.seq,V(n.store.authoritative))),i.element.removeAttribute("live-by");else{let m=n.store.pending.length>0||n.leftAt&&!n.leftAt.disk,q=St===null&&n.leftAt&&!n.leftAt.disk;if(t&&m&&(q||St&&!Yt)){let P="This host must update its live data protocol before this save can be sent. Your edits are still in this tab.";throw console.warn(`clay.live("${n.store.name}"): ${P}`),document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:n.store.name,code:"provenance-unsupported",message:P}})),E?.refresh(),Object.assign(new Error(P),{code:"provenance-unsupported"})}let g=Yr(n,t);g?(i.element.setAttribute("live-at",g.at),i.element.setAttribute("live-by",g.by)):(i.element.removeAttribute("live-at"),i.element.removeAttribute("live-by"))}}});document.addEventListener("clay:snapshot-ready",e=>{if(e.detail?.forSave!==!0||!R.size)return;let t=e.detail.captureId??null,r=Pe(e.detail.documentElement,{warn:!1}),o=new Map;for(let n of R.values()){if(n.store.ephemeral)continue;let i=r.get(n.store.name);if(!i)continue;let a=n.store.handle.status.mode==="fast"&&E?"fast":"file",d=a==="fast"?{epoch:E.status.epoch,seq:E.status.seq}:null,m=a==="file"?Gt(i.element):null,q=it(i.element.getAttribute("live-by")),g=a==="file"?Ht(n):null,P=n.store.pendingEntries().map(O=>O.id),F=g?g[1].ids.filter(O=>P.includes(O)):a==="file"?P:[],_=a==="file"&&q?.v===2?q.capture:null,C=F.length?g?g[0]:_?JSON.stringify(_):`anonymous:${++Ur}`:null,U=g?g[1].mark:n.store.mark;o.set(n.store.name,{mode:a,mark:U,canonical:Jt(i.element.textContent),at:d,lineage:m,by:i.element.getAttribute("live-by"),key:C,maybeLanded:!!g,ids:F}),m&&!m.disk&&n.leftAt&&(n.leftAt={...n.leftAt,ancestors:m.ancestors}),_&&_[0]===Vn&&(Lt=Math.max(Lt,_[1])),C&&(n.captureOps.set(C,{capture:_,ids:F,ended:!1,mark:U,text:i.element.textContent,at:i.element.getAttribute("live-at"),by:i.element.getAttribute("live-by")}),Xn(n)),n.framesSince=!1,a==="fast"&&zt&&ve.flushing&&_e?.landed(n.store.name,d)}Se!==null&&Se!==Ie&&Zt(Ke(Se),!1),t!==null&&(Le.set(t,o),Se=t)});document.addEventListener("clay:save-conflict",e=>{ir(e.detail?.hadTimeout===!0,e.detail?.captureId)});for(let e of["clay:save-error","clay:save-offline"])document.addEventListener(e,t=>{let r=t.detail?.status,o=t.detail?.code,n=o==="page-converting"||o==="page-capacity";ir(o==="save-already-applied"||t.detail?.hadTimeout===!0||t.detail?.sent!==!1&&!n&&!(r>=400&&r<500),t.detail?.captureId)});function ur(e,t){if(!t||typeof e!="string")return;let r=Pe(Qt(e),{warn:!1});for(let[o,n]of t){let i=R.get(o);if(!i)continue;let a=r.get(o),d=i.store.handle.status.mode;if(!a||Jt(a.element.textContent)!==n.canonical){n.mode==="file"&&(E?.roomBound(o)&&Ct(i,n.mark),d==="fast"&&E?.release(o),ct(i));continue}if(n.mode==="fast"){n.at&&_e?.landed(o,n.at);continue}d==="fast"?(Ct(i,n.mark),_e?.fileFrame(new Map([[o,{text:a.element.textContent,at:ot(a.element.getAttribute("live-at")),seq:null}]])),E?.release(o),E?.refresh()):i.framesSince?(!i.leftAt||i.leftAt.disk||E?.roomBound(o))&&Ct(i,n.mark):(i.store.confirm(n.mark),i.leftAt=n.lineage&&a.element.getAttribute("live-by")===n.by?n.lineage:{disk:!0},yo(i)),ct(i)}}function vo(e,t,r){let o=Pe(Qt(r),{warn:!1}),n=new Map,i=new Map;for(let[a,d]of t){if(d.qualifiedIds=null,d.mode!=="file"||d.key===null)continue;let m=R.get(a);if(!m)continue;let q=o.get(a);if(!q||Jt(q.element.textContent)!==d.canonical)continue;let g=m.captureOps.get(d.key);if(!g||q.element.getAttribute("live-at")!==g.at||q.element.getAttribute("live-by")!==d.by)continue;let P=new Set(m.store.pendingEntries().map(C=>C.id)),F=new Set(g.ids),_=d.ids.filter(C=>P.has(C)&&F.has(C));_.length&&(d.qualifiedIds=_,n.set(a,_),i.set(a,d.canonical))}Ee={captureId:e,qualified:n,saved:i,html:r}}pn(({captureId:e,html:t})=>{if(e==null)return;let r=Le.get(e);r&&(Ie=e,Se===e&&(Se=null),vo(e,r,t))});hn(({captureId:e,result:t,attempts:r,sent:o})=>{if(e==null||t?.ok)return;let n=Le.get(e);if(!n)return;let i=[...n.keys()].map(m=>R.get(m)).find(m=>m?.staged);if(i&&t.code==="page-nothing-to-write"){i.store.confirm(i.store.mark),Ke(e),qt(),ct(i);return}i&&t.code==="page-lineage-stale"&&(i.staged.conflict="conflict"),Ke(e);let a=ao(t,o),d=a?Qr(e):null;qt(),Zt(n,a,d?new Set(d.targets.map(m=>m.name)):null),d&&to(d,{result:t,attempts:r,startedAt:Date.now()})});function wo(e,t){let r=t?.captureId;if(r==null)return;let o=Le.get(r);o&&(Ke(r),qt(),tr(r),ur(e,o))}dn(wo);function is(e){let t=Se??Ie,r=t===null?null:Ke(t);qt(),tr(t),ur(e,r)}function ls(){return Ee}function bo(e,t=null){if(typeof e!="string"||!e)return;let r=Pe(Qt(e),{warn:!1});if(!r.size)return;if(_e){let n=new Map;for(let[i,a]of r)a.ephemeral||n.set(i,{text:a.element.textContent,at:ot(a.element.getAttribute("live-at")),seq:Number.isInteger(t)?t:null});_e.fileFrame(n)}let o=Pe(document,{warn:!1});for(let[n,i]of r){let a=i.element.textContent,d=R.get(n),m=i.element.getAttribute("live-at"),q=i.element.getAttribute("live-by"),g=o.get(n)?.element;if(d&&!d.store.ephemeral&&d.store.handle.status.mode==="file"&&m!==null&&q===null&&(d.withheld||ut(n).length)){d.withheld=!0;continue}let P=[];if(d&&d.store.handle.status.mode==="file"){let F=Gt(i.element),_=F&&!F.disk&&(!E?.status.epoch||F.epoch===E.status.epoch);if(_?P=E?.captured(n,F,it(q))??[]:F?.disk&&(P=E?.captured(n,ot(m),null)??[]),F&&!F.disk)for(let[C,U]of d.captureOps)U.capture&&st(F.ancestors,...U.capture)&&(P.push(...U.ids),d.captureOps.delete(C));d.leftAt=_||F?.disk?F:null}if(g&&(!d||d.store.handle.status.mode==="file")&&(m===null?g.removeAttribute("live-at"):g.getAttribute("live-at")!==m&&g.setAttribute("live-at",m),q===null?g.removeAttribute("live-by"):g.getAttribute("live-by")!==q&&g.setAttribute("live-by",q)),d&&!d.store.ephemeral){if(d.staged)continue;d.store.handle.status.mode==="file"&&go(d,a,"remote",P);continue}g&&g.textContent!==a&&(g.textContent=a)}}document.addEventListener("clay:sync-applied",e=>bo(e.detail?.html,e.detail?.seq));document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&He&&dt()&&ve.flush()});window.addEventListener("pagehide",()=>{if(zt=!0,!He||!dt())return;let e=Se??Ie,t=ve.flushing&&e!==null?Le.get(e):null;if(t)for(let[r,o]of t)o.mode==="fast"&&o.at&&_e?.landed(r,o.at);ve.flush()});window.addEventListener("pageshow",()=>{zt=!1});function as(e){return R.get(e)?.store||null}function us(e,t){let r=R.get(e);r&&r.store===t&&!r.staged&&R.delete(e)}function cs(){return[...R.values()].map(e=>e.store)}function fs(){return E}function ds(e){ve.within(e)}function qo({timeoutMs:e=1e4}={}){let t=new Map;for(let[o,n]of R)n.store.ephemeral||t.set(o,n.store.handle.status.mode==="fast"?n.last??0:null);let r=()=>[...t].every(([o,n])=>{let i=R.get(o);return i?n===null||i.store.handle.status.mode!=="fast"?i.store.pending.length===0:(i.landed??0)>=n:!0});return r()?Promise.resolve({ok:!0}):new Promise(o=>{let n=d=>{clearTimeout(a),Bt.delete(i),o(d)},i=()=>{r()&&n({ok:!0})},a=setTimeout(()=>n({ok:!1,code:"timeout"}),e);Bt.add(i),He&&(!E||E.isWriter())&&ve.soon()})}var ps=ar;export{Jr as a,or as b,ns as c,rs as d,os as e,Pe as f,po as g,ar as h,ss as i,is as j,ls as k,bo as l,as as m,us as n,cs as o,fs as p,ds as q,qo as r,ps as s};
|
package/dist/m/c-RI4NT75Y.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{f as S}from"./c-YDH7Q3NY.js";import{a as ne,b as F,c as re,d as oe}from"./c-N326R2JD.js";import{a as H}from"./c-JAX2667S.js";import{b as le,c as ae}from"./c-KR4UW4KW.js";import"./c-Z36J63PP.js";import"./c-LZJPNR2W.js";import{b as ce,g as ie}from"./c-2M73252O.js";import{b as Z}from"./c-KKWLDOPM.js";import{b as se}from"./c-T4VO4OCB.js";import"./c-FILLTJA7.js";import"./c-QIX5BJYN.js";import"./c-VKEDWYDF.js";import{D as te}from"./c-CJZSLMVQ.js";import"./c-GQ6F6IDK.js";import"./c-2SPVQSHC.js";import"./c-5VYOWDTI.js";import{g as ee}from"./c-7VGZ7RU5.js";import"./c-4YSCRICO.js";import"./c-WYFDLITL.js";import"./c-UGHH4MB3.js";import{a as J}from"./c-HT33EQRN.js";import"./c-B2ZXPOS3.js";import"./c-TQEMVJCS.js";import"./c-3IQRECYS.js";import"./c-AYVOREBE.js";import{f as X}from"./c-IJUK2GPW.js";import"./c-7O6AFR65.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-35NBGMZB.js";import"./c-XQXZAO7N.js";import"./c-S7LK4KUE.js";import{i as Q}from"./c-GHBCCVG4.js";import"./c-HA6INT6J.js";import"./c-DCFSEJZG.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var T="This spot changed again. Review the latest edit or download your copy.",ue="\uFFFC",C="",M=new Set("A ABBR B BDI BDO CITE CODE DATA DEL DFN EM FONT I INS KBD MARK Q S SAMP SMALL SPAN STRIKE STRONG SUB SUP TIME TT U VAR".split(" ")),ge=new Set(["BR","WBR","IMG"]),L=new Set("ADDRESS ARTICLE ASIDE AUDIO BLOCKQUOTE BODY CANVAS CAPTION CENTER COL COLGROUP DD DETAILS DIALOG DIR DIV DL DT FIELDSET FIGCAPTION FIGURE FOOTER FORM FRAME FRAMESET H1 H2 H3 H4 H5 H6 HEAD HEADER HGROUP HR HTML IFRAME LEGEND LI MAIN MATH MENU NAV NOSCRIPT OBJECT OL OPTGROUP OPTION P PRE SCRIPT SECTION SELECT STYLE SUMMARY SVG TABLE TBODY TD TEMPLATE TEXTAREA TFOOT TH THEAD TITLE TR UL VIDEO".split(" ")),ke=new Set("P H1 H2 H3 H4 H5 H6 DIV LI DD DT BLOCKQUOTE FIGCAPTION SUMMARY ADDRESS".split(" ")),we=new Set("P H1 H2 H3 H4 H5 H6 SUMMARY".split(" ")),Ne=/[\u001E]/,ve={subtree:!0,childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0},k=e=>!!e&&e.nodeType===1,W=e=>k(e)&&M.has(e.tagName),B=e=>e.matches(le),z=e=>e.matches(ae),y=e=>e.localName==="template"&&e.content?e.content:e,w=e=>Array.prototype.indexOf.call(e.parentNode.childNodes,e),x=e=>e.getAttribute("data-id")||e.getAttribute("id")||null;function Ce(e){return!e.firstChild||e.textContent===""&&!e.querySelector("br,img,wbr")}function ye(e){if(e.nodeType===3)return!0;if(!k(e))return!1;if(B(e)||ge.has(e.tagName))return!0;if(!M.has(e.tagName))return!L.has(e.tagName);if(z(e))return!1;for(let n of e.childNodes)if(!ye(n))return!1;return!0}function Y(e){if(!ke.has(e.tagName)||B(e)||z(e))return!1;for(let n of e.childNodes)if(n.nodeType===8||!ye(n))return!1;return!0}function xe(e,n=document){for(let t of n.querySelectorAll("template")){if(t.content===e)return t;let r=xe(e,t.content);if(r)return r}return null}function m(e,n){for(let t=e;t;t=t.nodeType===11?xe(t):t.parentNode)if(t===n)return!0;return!1}var h=e=>m(e,document);function Ae(e,n){let t=e;for(let r of n)if(t=r==="content"?t.content:t.childNodes[r],!t)return null;return t}function D(e,n=new Set){if(k(e)){let t=x(e);t&&n.add(t)}if(e.nodeType===1||e.nodeType===11)for(let t of y(e).childNodes)D(t,n);return n}function Re(e){let n=document.createElement("template");return n.innerHTML=e,n.content}var Ie=e=>[...e.querySelectorAll("*")].some(n=>L.has(n.tagName));function Se(e){let n=[];for(let t=e;t.childNodes.length===1&&k(t.firstChild);t=t.firstChild)n.push(t.firstChild);return n}function De(e,n){let t=e.lastIndexOf("content");if(t<0)return document;let r=$(e.slice(0,t),n);return r&&r.content?r.content:null}function $(e,n){let t=Ae(n.root,e);if(!k(t))return null;let r=x(t),o=r?De(e,n):null;if(!o)return null;let s=[...o.querySelectorAll(t.localName)].filter(i=>i.namespaceURI===t.namespaceURI&&x(i)===r);return s.length===1?s[0]:null}function Me(e){let n=x(e);if(!n)return null;let t=[...document.querySelectorAll(e.localName)].filter(r=>r.namespaceURI===e.namespaceURI&&x(r)===n);return t.length===1?t[0]:null}function b(e,n,t=e?e.nodeType:1){if(!e)return null;for(let o of e.live)if(o.nodeType===t&&h(o))return o;if(t!==1)return null;if(e.local.length)return $(e.local[0],n);let r=e.live.find(k);return r?Me(r):null}function Pe(e){let n=e.live.find(k),t=n?x(n):null;return!!t&&![...document.querySelectorAll(n.localName)].some(r=>x(r)===t)}function _(e){let n=y(e),t={root:e,container:n,text:"",nodes:[],atoms:[],blocks:[]},r=s=>{for(let i of s){if(i.nodeType===3){if(!i.data)continue;t.nodes.push({node:i,s:t.text.length,e:t.text.length+i.data.length}),t.text+=i.data;continue}if(!k(i)||B(i))continue;if(Y(i)){t.text.length&&t.text[t.text.length-1]!==C&&(t.text+=C);let l={el:i,from:t.text.length,to:-1};t.blocks.push(l),r(i.childNodes),t.text+=C,l.to=t.text.length;continue}let c=M.has(i.tagName)&&Ce(i);if(ge.has(i.tagName)||!M.has(i.tagName)||z(i)||c){t.atoms.push({i:t.text.length,el:i}),t.text+=ue;continue}r(i.childNodes)}};if(r(n.childNodes),t.atoms.length===1&&t.atoms[0].el.tagName==="BR"&&!t.blocks.length&&t.text.replace(ue,"").trim()===""){let s=t.atoms[0].i;t.text=t.text.slice(0,s)+t.text.slice(s+1),t.atoms=[];for(let i of t.nodes)i.s>s&&(i.s--,i.e--)}return t}function fe(e,n,t){for(let s of e.nodes)if(t==="start"?s.s<=n&&n<s.e:s.s<n&&n<=s.e)return[s.node,n-s.s];let r=t==="start"?n:n-1,o=e.atoms.find(s=>s.i===r);if(o)return[o.el.parentNode,w(o.el)+(t==="start"?0:1)];if(e.text[r]===C){let s=e.blocks.find(c=>c.to===r+1);if(s)return t==="start"?[s.el,s.el.childNodes.length]:[s.el.parentNode,w(s.el)+1];let i=e.blocks.find(c=>c.from===r+1);if(i)return t==="start"?[i.el,0]:[i.el.parentNode,w(i.el)]}for(let s of e.nodes)if(s.s===n||s.e===n)return[s.node,n-s.s];return[e.container,n===0?0:e.container.childNodes.length]}function j(e,n){let t=document.createRange();return t.setStart(e,n),t.setEnd(e,n),t}function K(e,n,t){if(n.nodeType===3){let i=e.nodes.find(c=>c.node===n);return i?i.s+t:null}if(n!==e.container&&!m(n,e.root))return null;let r=j(n,t),o=e.text.length,s=(i,c)=>{try{return r.comparePoint(i,c)>=0}catch{return!1}};for(let i of e.nodes)s(i.node,0)&&(o=Math.min(o,i.s));for(let i of e.atoms)s(i.el.parentNode,w(i.el))&&(o=Math.min(o,i.i));return o}function Le(e,n){let t=e.slice(n.bs,n.be),r=0;for(;r<t.length&&r<n.text.length&&t[r]===n.text[r];)r++;let o=0;for(;o<t.length-r&&o<n.text.length-r&&t[t.length-1-o]===n.text[n.text.length-1-o];)o++;return{bs:n.bs+r,be:n.be-o,text:n.text.slice(r,n.text.length-o)}}function G(e,n,t,r){if(e===n)return{s:t,e:r};let o=0,s=0,i=H.diff(e,n).map(c=>Le(e,c)).sort((c,l)=>c.bs-l.bs);for(let c of i){if(c.bs===c.be&&!c.text)continue;let l=c.text.length-(c.be-c.bs);if(c.be<=t)o+=l;else{if(c.bs>=r)continue;if(c.bs>=t&&c.be<=r){if(Ne.test(e.slice(c.bs,c.be)+c.text))return null;s+=l}else return null}}return{s:t+o,e:r+o+s}}function Be(e,n,t){let r=e.liveScope;if(r&&r.startContainer&&m(r.startContainer,n)&&m(r.endContainer,n)){let s=K(t,r.startContainer,r.startOffset);if(s!==null)return s}if(Y(n))return 0;let o=e.merged.text?t.text.indexOf(e.merged.text):-1;return o>=0&&t.text.indexOf(e.merged.text,o+1)<0?o:null}function Te(e,n){let t=e.commonAncestorContainer;for(t.nodeType===3&&(t=t.parentNode);t&&t!==n;t=t.parentNode)if(k(t)&&Y(t))return t;return n}var Oe=(e,n)=>e.tagName===n.tagName&&e.attributes.length===n.attributes.length&&[...e.attributes].every(t=>n.getAttribute(t.name)===t.value);function de(e,n){let t=[];for(let r=k(e)?e:e.parentNode;r&&r!==n&&W(r);r=r.parentNode)t.unshift(r);return t}function Ue(e,n,t){let[r,o]=e;if(r.nodeType===3){if(o!==0&&o!==r.data.length)return e;[r,o]=[r.parentNode,w(r)+(o===0?0:1)]}let s=!1;for(;r!==n&&W(r)&&(o===0||o===r.childNodes.length)&&!t.some(i=>Oe(i,r));)[r,o]=[r.parentNode,w(r)+(o===0?0:1)],s=!0;return s?[r,o]:e}function He(e,n,t){let r=de(n.startContainer,t),o=de(n.endContainer,t);return r.length!==o.length||r.some((s,i)=>s!==o[i])||r.length>e.wrappers.length||r.some((s,i)=>!Oe(s,e.wrappers[i]))?!1:(e.peel=r.length,!e.wrappers.slice(e.peel).some(s=>r.some(i=>i.tagName===s.tagName)))}function Fe(e,n,t,r){let o=e.childNodes.length===1&&k(e.firstChild)?e.firstChild:null;if(!o||!L.has(o.tagName))return;let s=document.createRange();s.setStart(...n),s.setEnd(...t);let i=Te(s,r);i===r||i.tagName!==o.tagName||i.namespaceURI!==o.namespaceURI||x(i)!==x(o)||o.replaceWith(...o.childNodes)}function Ge(e){if(!e.parsed)return e.fragment;let n=e.parsed.childNodes;return n.length?n.length===1&&n[0].nodeType===3?n[0].data:null:""}function Ve(e,n){let t=e.recovery.text,r=e.recovery.subject,o=b(r,n,r.nodeType);if(!o)return null;let s=o.nodeType===3&&o.parentNode?.localName==="textarea"?o.parentNode:o,i=t.local.text.slice(t.local.start,t.local.end);if(Ne.test(t.merged.text.slice(t.merged.start,t.merged.end))||i.includes(C))return null;let c={kind:"text",id:e.id,ticket:n.ticket,key:r.key,fragment:t.local.fragment,encoding:t.encoding,local:i,ids:new Set,range:document.createRange()};if(o.nodeType===8){let g=G(t.merged.text,o.data,t.merged.start,t.merged.end);return g?(c.range.setStart(o,g.s),c.range.setEnd(o,g.e),{...c,root:o,owner:o,scope:o,s:g.s,e:g.e,before:o.data,bs:g.s,be:g.e}):null}if(s.localName==="textarea"){if(c.encoding!=="plain")return null;let g=G(t.merged.text,s.value,t.merged.start,t.merged.end);return g?(c.range.selectNodeContents(s),{...c,root:s,field:s,scope:s,f:{text:s.value},s:g.s,e:g.e,before:s.value,bs:g.s,be:g.e}):null}let l=_(o),u=Be(t,o,l);if(u===null)return null;let d=G(t.merged.text,l.text.slice(u),t.merged.start,t.merged.end);if(!d)return null;let N=u+d.s,v=u+d.e,A=fe(l,N,"start"),a=N===v?A:fe(l,v,"end");if(c.parsed=c.encoding==="html"?Re(c.fragment):null,c.parsed&&Fe(c.parsed,A,a,o),c.parsed&&Ie(c.parsed)||(c.wrappers=c.parsed?Se(c.parsed):[],c.parsed&&D(c.parsed,c.ids),c.plain=Ge(c),N===v&&(A=a=Ue(A,o,c.wrappers)),c.range.setStart(...A),c.range.setEnd(...a),!He(c,c.range,o)))return null;let f=Te(c.range,o),p=f===o?l:_(f),E=K(p,...A),U=N===v?E:K(p,...a);return E===null||U===null||p.text.slice(E,U)!==l.text.slice(N,v)?null:{...c,root:o,f:l,s:N,e:v,scope:f,before:p.text,bs:E,be:U}}function qe(e){if(e.owner){let o=e.owner.data;e.owner.data=o.slice(0,e.s)+e.fragment+o.slice(e.e),e.check=()=>e.owner.data.slice(e.s,e.s+e.fragment.length)===e.fragment&&h(e.owner);return}if(e.field){let o=e.field,s=o.value.slice(0,e.s)+e.fragment+o.value.slice(e.e);o.textContent=s,o.value!==s&&(o.value=s,e.wroteProperty=!0),o.hasAttribute("data-value")&&o.setAttribute("data-value",s),e.check=()=>h(o)&&o.value===s&&o.textContent===s;return}let n=e.range,t=n.startContainer;if(e.plain!==null&&t.nodeType===3&&n.endContainer===t){let o=n.startOffset;t.replaceData(o,n.endOffset-o,e.plain),e.check=()=>h(t)&&t.data.slice(o,o+e.plain.length)===e.plain;return}n.deleteContents();let r=[];if(e.fragment)if(e.parsed){let o=document.importNode(e.parsed,!0),s=Se(o);for(let i=0;i<e.peel;i++)s[i].replaceWith(...s[i].childNodes);r=[...o.childNodes],n.insertNode(o)}else r=[document.createTextNode(e.fragment)],n.insertNode(r[0]);e.check=()=>r.every(h)&&(e.parsed||!r.length||r[0].data===e.fragment)}function _e(e,n){let t=b(e.recovery.subject,n,1);if(!t)return null;let r=e.recovery.attribute,o={kind:"attr",id:e.id,ticket:n.ticket,key:e.recovery.subject.key,el:t,ns:r.namespaceURI,name:r.qualifiedName,local:r.localName,value:e.local??null,ids:new Set};try{o.ns===null?document.createAttribute(o.name):document.createAttributeNS(o.ns,o.name)}catch{return null}return o}var je=new Set(["hidden","submit","image","reset","button","checkbox","radio","file"]);function Ke(e,n){let t=document.createElement("input");return t.type=e.type,t.value=n,t.value}function We(e){let n=e.el;return e.ns!==null||n.namespaceURI!=="http://www.w3.org/1999/xhtml"?null:n.localName==="input"&&e.name==="checked"&&(n.type==="checkbox"||n.type==="radio")?["checked",e.value!==null]:n.localName==="input"&&e.name==="value"&&!je.has(n.type)?["value",Ke(n,e.value??"")]:n.localName==="option"&&e.name==="selected"?["selected",e.value!==null]:null}function ze(e){e.ns===null?e.value===null?e.el.removeAttribute(e.name):e.el.setAttribute(e.name,e.value):e.value===null?e.el.removeAttributeNS(e.ns,e.local):e.el.setAttributeNS(e.ns,e.name,e.value);let n=We(e);n&&e.el[n[0]]!==n[1]&&(e.el[n[0]]=n[1],e.wroteProperty=!0);let t=()=>e.ns===null?e.el.getAttribute(e.name):e.el.getAttributeNS(e.ns,e.local);e.check=()=>h(e.el)&&t()===e.value&&(!n||e.el[n[0]]===n[1])}function Ye(e,n){let t=e.recovery.structure,r=e.recovery.subject,o=b(r,n,r.nodeType),s={id:e.id,ticket:n.ticket,key:r.key,apply:n,ids:new Set},i=c=>c?b(c.parent,n,1):null;if(t.localAction==="deleted")return o?{...s,kind:"remove",node:o}:Pe(r)?{...s,kind:"done",check:()=>!0}:null;if(t.localAction==="moved"){let c=i(t.localPlacement);return!o||!c||o===c||m(c,o)?null:{...s,kind:"move",node:o,parent:c,placement:t.localPlacement}}if(t.localAction==="reordered"){if(!o||!t.localOrder)return null;let c=y(o),l=t.localOrder.map(u=>b(u,n,u.nodeType)).filter(u=>u&&u.parentNode===c);return l.length<2?null:{...s,kind:"reorder",parent:o,order:l}}if(t.localAction==="inserted"){let c=i(t.localPlacement);if(!c||o&&o.parentNode!==y(c))return null;if(t.fragmentKind!=="element")return typeof t.localFragment!="string"?null:{...s,kind:"run",node:o,parent:c,placement:t.localPlacement,text:t.localFragment,nodeType:r.nodeType};let l=r.local.length?Ae(n.root,r.local[0]):null;if(!k(l))return null;let u=o?o.tagName===l.tagName&&o.namespaceURI===l.namespaceURI?"morph":"replace":"place";return{...s,kind:"realize",node:o,parent:c,placement:t.localPlacement,src:l,mode:u,ids:D(l)}}return null}function V(e,n,t,r){let o=y(n),s=l=>{for(let u of l){let d=b(u,r,u.nodeType);if(d&&d!==e&&d.parentNode===o)return d}return null},i=s(t.before);if(i)return o.insertBefore(e,i);let c=s(t.after);return c?o.insertBefore(e,c.nextSibling):t.before.length?o.insertBefore(e,o.firstChild):o.appendChild(e)}function $e(e){let n=document.importNode(e.src,!0),t=document.createDocumentFragment();return t.append(n),e.apply.domain==="save"&&(se(t),ce(t),ie(t),Z(t)),n}function Qe(e,n){let t=e.filter(r=>r.kind==="move");for(let r of t)n.append(r.node);for(let r of e){if(r.kind==="run"){r.node?r.node.data=r.text:r.node=V(r.nodeType===8?document.createComment(r.text):document.createTextNode(r.text),r.parent,r.placement,r.apply),r.check=()=>h(r.node)&&r.node.parentNode===y(r.parent)&&r.node.data===r.text;continue}if(r.kind!=="realize")continue;let o=$e(r);r.mode==="morph"?H.morphElement(r.node,o,{ignore:B,scripts:{execute:!1}}):r.mode==="replace"?(r.node.replaceWith(o),r.node=o):r.node=V(o,r.parent,r.placement,r.apply),r.check=()=>h(r.node)&&r.node.parentNode===y(r.parent)}for(let r of t)V(r.node,r.parent,r.placement,r.apply),r.check=()=>r.node.parentNode===y(r.parent)&&h(r.node);for(let r of e){if(r.kind!=="reorder")continue;let o=y(r.parent),s=r.order.filter(u=>u.parentNode===o),i=s.slice(),c=[...o.childNodes].map(u=>s.includes(u)?i.shift():u),l=null;for(let u=c.length-1;u>=0;u--){let d=c[u];s.includes(d)&&d.nextSibling!==l&&o.insertBefore(d,l),l=d}r.check=()=>{let u=[...o.childNodes].filter(d=>s.includes(d));return u.length===s.length&&u.every((d,N)=>d===s[N])}}for(let r of e)r.kind==="remove"&&(r.node.remove(),r.check=()=>!h(r.node))}function O(e){return e.kind==="move"||e.kind==="remove"?[e.node]:e.kind==="realize"||e.kind==="run"?e.node?[e.node]:[]:[]}function R(e){return e.kind==="text"?[e.scope]:e.kind==="move"||e.kind==="reorder"?[e.parent]:(e.kind==="realize"||e.kind==="run")&&!e.node?[e.parent]:[]}var be=e=>e.kind==="attr"?[e.el]:[...O(e),...R(e)];function Xe(e,n){try{let t=j(e.startContainer,e.startOffset),r=j(n.startContainer,n.startOffset);return e.collapsed&&n.collapsed?t.comparePoint(n.startContainer,n.startOffset)===0:t.comparePoint(n.endContainer,n.endOffset)>0&&r.comparePoint(e.endContainer,e.endOffset)>0}catch{return!1}}function Je(e,n){try{return e.comparePoint(n.startContainer,n.startOffset)===0&&e.comparePoint(n.endContainer,n.endOffset)===0}catch{return!1}}function Ze(e,n){try{return e.intersectsNode(n)&&!m(e.commonAncestorContainer,n)}catch{return!1}}function I(e,n){if(!e.ids.size&&!n.ids.size)return!1;let t=s=>{let i=new Set;for(let c of be(s))D(c,i);return i},r=e.ids.size?null:t(e),o=t(n);return[...e.ids].some(s=>n.ids.has(s)||o.has(s))||[...n.ids].some(s=>(r||t(e)).has(s))}function me(e,n){return n.kind==="text"?Ze(n.range,e.el):O(n).some(t=>m(e.el,t))||n.ids.has(x(e.el))}function pe(e,n){return n.kind==="reorder"?m(n.parent,e.scope)||I(e,n):O(n).some(t=>m(t,e.scope)||m(e.scope,t))||R(n).some(t=>m(t,e.scope))?!0:I(e,n)}function he(e,n){return O(n).some(t=>e.order.includes(t)||m(e.parent,t))||R(n).includes(e.parent)?!0:I(e,n)}function q(e,n){if(e.kind==="done"||n.kind==="done")return!1;if(e.kind==="text"&&n.kind==="text")return Xe(e.range,n.range);if(e.kind==="attr"&&n.kind==="attr")return e.el===n.el&&e.ns===n.ns&&e.local===n.local;if(e.kind==="attr")return me(e,n);if(n.kind==="attr")return me(n,e);if(e.kind==="text")return pe(e,n);if(n.kind==="text")return pe(n,e);if(e.kind==="reorder"&&n.kind==="reorder")return e.parent===n.parent||I(e,n);if(e.kind==="reorder")return he(e,n);if(n.kind==="reorder")return he(n,e);for(let t of O(e))for(let r of O(n))if(m(t,r)||m(r,t))return!0;for(let t of O(e))for(let r of R(n))if(m(r,t))return!0;for(let t of O(n))for(let r of R(e))if(m(r,t))return!0;return I(e,n)}function et(e,n){return e.kind==="done"?!1:e.kind==="attr"?m(e.el,n.node):be(e).some(t=>m(t,n.node)||m(n.node,t))?!0:e.ids.size?(n.ids||(n.ids=D(n.node)),[...e.ids].some(t=>n.ids.has(t))):!1}function tt(e,n){return e.kind==="text"&&n.kind==="text"&&!e.field&&e.root===n.root&&Je(e.range,n.range)}function nt(e,n){let t=oe(e);return t?t.nodes:[rt(e,n)]}function rt(e,n){let t=e.recovery,r=t.subject;for(let c of t.text?[t.text.liveSpan,t.text.liveScope]:[])if(c&&c.startContainer&&h(c.startContainer)&&h(c.endContainer))return st(ot(c));let o=r?b(r,n,r.nodeType):null;if(o)return o;let s=t.structure&&t.structure.localPlacement?b(t.structure.localPlacement.parent,n,1):null;if(s)return s;let i=r&&r.local.length?r.local[0]:[];for(let c=i.length-1;c>0;c--){if(i[c-1]==="content")continue;let l=$(i.slice(0,c),n);if(l)return l}return document.documentElement}function ot(e){let n=new Set;for(let r=e.startContainer;r;r=r.parentNode)n.add(r);let t=e.endContainer;for(;t&&!n.has(t);)t=t.parentNode;return t.nodeType===1||t.nodeType===11?t:t.parentNode}function st(e){for(let n=e;n;n=n.parentNode)if(k(n)&&ke.has(n.tagName))return n;return e}function ct(e,n){let t=e.recovery;return t.applied===!1||t.unavailable?null:t.structure?Ye(e,n):t.text?Ve(e,n):t.attribute?_e(e,n):null}var P=()=>`${re()}|${S.hasPendingApply()?1:0}|${S.list().map(e=>e.id).join(",")}`;function Ee(){let e={ids:new Map,nested:new Set},n=r=>{for(let o of["id","data-id"]){let s=r.getAttribute(o);s&&e.ids.set(`${o} ${s}`,(e.ids.get(`${o} ${s}`)||0)+1)}},t=(r,o)=>{for(let s of y(r).children)n(s),o&&L.has(s.tagName)&&e.nested.add(s),t(s,o||W(s)||we.has(s.tagName))};return n(document.documentElement),t(document.documentElement,!1),e}function it(e){let n=Ee();for(let[r,o]of n.ids)if(o>1&&(e.before.ids.get(r)||0)<=1)return!1;for(let r of n.nested)if(!e.before.nested.has(r))return!1;let t=new Map;for(let r of e.ops)r.kind==="text"&&t.set(r.scope,[...t.get(r.scope)||[],r]);for(let[r,o]of t){let s=o[0].before;for(let c of[...o].sort((l,u)=>u.bs-l.bs))s=s.slice(0,c.bs)+c.local+s.slice(c.be);if((o[0].owner?r.data:o[0].field?r.value:_(r).text)!==s)return!1}return!0}function lt(){let e=new Map,n=c=>{for(let l of c.querySelectorAll("*"))e.set(l,[...l.attributes].map(u=>[u,u.value])),l.localName==="template"&&l.content&&n(l.content)};n(document);let t=[];for(let c of document.querySelectorAll("input, textarea"))t.push([c,"value",c.value]);for(let c of document.querySelectorAll("input"))t.push([c,"checked",c.checked]);for(let c of document.querySelectorAll("option"))t.push([c,"selected",c.selected]);let r=document.activeElement,o=null;try{r&&typeof r.selectionStart=="number"&&(o=[r.selectionStart,r.selectionEnd,r.selectionDirection])}catch{}let s=document.getSelection(),i=s&&s.rangeCount?[s.anchorNode,s.anchorOffset,s.focusNode,s.focusOffset]:null;return{attrs:e,controls:t,active:r,caret:o,selection:i}}function at(e,n){let t=e.attributes;return t.length===n.length&&n.every(([r,o],s)=>t[s]===r&&r.value===o)}function ut(e,n){let t=new Set;for(let s=e.length-1;s>=0;s--){let i=e[s];if(i.type==="characterData")i.target.data=i.oldValue;else if(i.type==="attributes")t.add(i.target);else{for(let c of i.addedNodes)c.parentNode===i.target&&i.target.removeChild(c);for(let c of i.removedNodes)i.target.insertBefore(c,i.nextSibling)}}for(let s of t){let i=n.attrs.get(s);if(!(!i||at(s,i))){for(let c of[...s.attributes])s.removeAttributeNode(c);for(let[c,l]of i)c.value=l,s.setAttributeNode(c)}}for(let[s,i,c]of n.controls)if(s[i]!==c)try{s[i]=c}catch{}let r=document.getSelection();r&&n.selection?h(n.selection[0])&&h(n.selection[2])&&r.setBaseAndExtent(...n.selection):r&&r.rangeCount&&r.removeAllRanges();let o=n.active;if(o&&o!==document.activeElement&&o!==document.body&&h(o)&&o.focus&&o.focus({preventScroll:!0}),n.caret&&document.activeElement===o)try{o.setSelectionRange(...n.caret)}catch{}}function ft(e){let n=t=>{e.observe(t,ve);for(let r of t.querySelectorAll("template"))r.content&&n(r.content)};n(document)}function dt(e){let n=new Set;for(let t of e)if(t.type==="characterData"){if(n.has(t.target))return!1;n.add(t.target)}return!0}function mt(e){let n=P(),t=new Map,r=new Map,o=[],s=new Set;for(let a of e){if(s.has(a))continue;s.add(a);let f=S.get(a);f&&(f.claimedBy||f.kind==="apply-incomplete"||f.kind==="json"||!f.recovery?t.set(a,T):o.push(f))}if(S.hasPendingApply()){for(let a of o)t.set(a.id,T);return{ops:[],covered:r,blocked:t,revision:n,before:null}}let i=[],c=a=>{let f=S.recoveryOf(a.id),p=f?ct(a,f):null;if(!p&&f)for(let E of nt(a,f))i.push({ticket:f.ticket,node:E});return p},l=[];for(let a of o){let f=c(a);f?l.push(f):t.set(a.id,T)}let u=[];for(let a of S.list())if(!s.has(a.id)){if(a.kind==="apply-incomplete")i.push({ticket:a.ticket,node:document.documentElement});else if(a.recovery){let f=c(a);f&&u.push(f)}}l.sort((a,f)=>f.ticket-a.ticket);let d=[],N=[],v=a=>{t.set(a.id,T),N.push(a)};for(let a of l){if(i.some(p=>p.ticket>a.ticket&&et(a,p))||u.some(p=>p.ticket>a.ticket&&q(p,a))||N.some(p=>q(p,a))){v(a);continue}let f=d.find(p=>q(p,a));if(!f){d.push(a);continue}if(tt(f,a)){r.set(a.id,f.id);continue}v(a),f.ticket===a.ticket&&(d.splice(d.indexOf(f),1),v(f))}let A=ne(i.filter(a=>d.some(f=>a.ticket>f.ticket)).map(a=>a.node));return{ops:d,covered:r,blocked:t,revision:P(),protectedWitnesses:A,before:Ee()}}function pt(e){if(e.revision!==P()||!F(e.protectedWitnesses||[])){for(let c of e.ops)e.blocked.set(c.id,T);for(let c of e.covered.keys())e.blocked.set(c,T);return[]}let n=lt(),t=window.clay?.undo;t?.pause?.();let r=new MutationObserver(()=>{}),o=document.createDocumentFragment(),s=[],i=!1;try{ft(r),r.observe(o,ve);let c=e.ops.filter(l=>l.kind==="text").sort((l,u)=>l.root===u.root?u.s-l.s||u.e-l.e:0);for(let l of c)qe(l);for(let l of e.ops)l.kind==="attr"&&ze(l);Qe(e.ops.filter(l=>l.kind!=="text"&&l.kind!=="attr"),o),s=r.takeRecords(),i=e.ops.every(l=>l.check())&&it(e)&&e.revision===P()&&F(e.protectedWitnesses||[])}catch(c){console.error("[clay] Revert to mine failed while writing and was undone",c)}finally{s=s.concat(r.takeRecords()),r.disconnect()}if(i)return dt(s)&&!e.ops.some(c=>c.wroteProperty)?t?.commitCaptured?.("Revert to mine"):t?.discardCaptured?.(),t?.resume?.(),[...e.ops.map(c=>c.id),...e.covered.keys()];try{ut(s,n)}finally{J.dropQueued(),t?.discardCaptured?.(),t?.resume?.()}for(let c of e.ops)e.blocked.set(c.id,T);for(let c of e.covered.keys())e.blocked.set(c,T);return[]}async function wt(e){await Promise.resolve();let n=mt(e),t=pt(n);Q();let r=null;return t.length&&(ee(),S.acknowledge(t,{reason:"reverted"}),X(),await Promise.resolve(),r=await te()),{revertedIds:t,blockedIds:[...n.blocked.keys()],saveResult:r}}export{T as BLOCKED,pt as applyRevert,mt as prepareRevert,wt as revertConflicts};
|
package/dist/m/c-RUJKSUQW.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{b as L,c as M,d as _,f as N}from"./c-GB3JTV6E.js";import"./c-BWFVSBDF.js";import{a as D,b as x}from"./c-A7LS5UZW.js";import"./c-AYVOREBE.js";import"./c-7O6AFR65.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-HA6INT6J.js";import"./c-DCFSEJZG.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var m="This computer",C=64,O=64,R=/^[\x20-\x7e]{1,128}$/;function X(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2)+Date.now().toString(36)}function B(e){return typeof e!="string"?m:e.trim().slice(0,O)||m}function v(e){let r=_(e===void 0?null:e);return r.ok?r.target:null}function j(e,r){let c=null,f=-1;for(let l of r)l.editing===null||l.n<=f||(c=l.editing,f=l.n);return e.editing!==null&&e.n>=f?e.editing:c}function Y({scope:e=null,key:r=null,store:c=N,channel:f=null,label:l=m}={}){let S=B(l),w=r??"clay-live:"+(e??(typeof window<"u"?window.location.pathname:"/")),P="local:"+(e??w),b=X(),i=new Map,d=null,u=0,p=null,I=null,s=null,g=null,a=!1;function h(n){p&&p.post({type:D,from:b,...n})}function y(){let n={id:b,you:!0,n:u,editing:d},t=[];for(let o of i.values())t.push({id:o.id,you:!1,n:o.n,editing:o.editing});let E=[n,...t].sort((o,A)=>o.id<A.id?-1:o.id>A.id?1:0);c.receive({people:[{id:P,name:S,you:!0,canEdit:!0,editing:j(n,t),sessions:E}],anonymous:0})}function T(n){if(!n||n.from===b||typeof n.from!="string"||!R.test(n.from))return;let t=i.get(n.from);if(n.op==="bye"){t&&i.delete(n.from),y();return}if(n.op!=="hello"&&n.op!=="update"&&n.op!=="beat"||!t&&i.size>=C)return;let E=n.op==="beat"?t?t.editing:null:v(n.editing),o=Number.isSafeInteger(n.n)&&n.n>=0?n.n:0;t&&o<t.n||(i.set(n.from,{id:n.from,n:o,editing:E,seenAt:Date.now()}),n.op==="hello"&&!t&&h({op:"hello",n:u,editing:d,label:S}),y())}function U(){if(!a)return;h({op:"beat",n:u});let n=Date.now(),t=!1;for(let[E,o]of i)n-o.seenAt<=M||(i.delete(E),t=!0);t&&y()}function k(n){let t=n&&typeof n=="object"&&"editing"in n?n.editing:null;return d=v(t),u+=1,h({op:"update",n:u,editing:d}),y(),!0}return{sessionId:b,start(){return a||(a=!0,p=f??x(w),I=p.subscribe("presence",T),s=c.attachTransport({send:k}),h({op:"hello",n:u,editing:d,label:S}),y(),g=setInterval(U,L)),s},stop(){a&&(a=!1,g!==null&&clearInterval(g),g=null,h({op:"bye"}),i.clear(),I?.(),I=null,p=null,s?.detach(),s=null)}}}export{m as LOCAL_LABEL,C as MAX_SESSIONS,Y as localPresence};
|
package/dist/m/c-T4VO4OCB.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a,b as d,c,d as o}from"./c-QIX5BJYN.js";import{a as l}from"./c-VKEDWYDF.js";import{i}from"./c-7O6AFR65.js";import{k as u}from"./c-35NBGMZB.js";var n="[editmode\\:contenteditable]";function f(){u(t=>{t.querySelectorAll(n).forEach(o)})}function m(){i&&l(()=>{s()})}function s(t=document){t.querySelectorAll(n).forEach(e=>{a(e);let r=e.getAttribute("inert-contenteditable")??e.getAttribute("contenteditable")??d(e,"inert-contenteditable")??"true",b=r.toLowerCase();e.setAttribute("contenteditable",["","true","false","plaintext-only"].includes(b)?r:"true"),e.removeAttribute("inert-contenteditable")})}function h(){document.querySelectorAll(n).forEach(t=>{o(t),c(t)})}function y(){f(),m()}export{n as a,s as b,h as c,y as d};
|