@heycys/gallery 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/THIRD-PARTY-NOTICES.md +51 -1
- package/browser/editor/components/callout/index.mjs +40 -15
- package/browser/editor/components/columns/page.mjs +41 -28
- package/browser/editor/components/details/index.mjs +2 -1
- package/browser/editor/components/dialog/index.mjs +2 -1
- package/browser/editor/components/dialog/page.mjs +0 -18
- package/browser/editor/components/divider/index.mjs +1 -1
- package/browser/editor/components/figure/page.mjs +10 -1
- package/browser/editor/components/file/page.mjs +2 -2
- package/browser/editor/components/flowchart/add.mjs +2 -2
- package/browser/editor/components/heading/index.mjs +2 -0
- package/browser/editor/components/heading/page.mjs +6 -0
- package/browser/editor/components/highlight/index.mjs +4 -20
- package/browser/editor/components/icons.mjs +5 -2
- package/browser/editor/components/image/page.mjs +2 -2
- package/browser/editor/components/installed/index.mjs +71 -25
- package/browser/editor/components/installed/page.mjs +122 -21
- package/browser/editor/components/kit.mjs +3 -0
- package/browser/editor/components/media/page.mjs +44 -14
- package/browser/editor/components/pages.mjs +2 -2
- package/browser/editor/components/registry.mjs +56 -30
- package/browser/editor/components/section/index.mjs +2 -1
- package/browser/editor/components/set-apart.mjs +24 -0
- package/browser/editor/components/table/index.mjs +5 -3
- package/browser/editor/components/table/page.mjs +29 -18
- package/browser/editor/page/annotate/anchors.mjs +4 -3
- package/browser/editor/page/annotate/index.mjs +61 -34
- package/browser/editor/page/autosave.mjs +50 -4
- package/browser/editor/page/beside.mjs +5 -5
- package/browser/editor/page/block-menu/colors.mjs +3 -1
- package/browser/editor/page/block-menu/index.mjs +8 -6
- package/browser/editor/page/blocks.mjs +16 -7
- package/browser/editor/page/caret.mjs +4 -1
- package/browser/editor/page/changes/bar.mjs +102 -0
- package/browser/editor/page/changes/ghost.mjs +206 -0
- package/browser/editor/page/changes/gone-words.mjs +94 -0
- package/browser/editor/page/changes/index.mjs +447 -0
- package/browser/editor/page/changes/words.mjs +27 -0
- package/browser/editor/page/clipboard/import/colors.mjs +3 -3
- package/browser/editor/page/clipboard/index.mjs +32 -13
- package/browser/editor/page/clipboard/own/blocks.mjs +14 -5
- package/browser/editor/page/clipboard/own/describe.mjs +16 -7
- package/browser/editor/page/clipboard/own/export.mjs +6 -6
- package/browser/editor/page/clipboard/own/selection.mjs +2 -2
- package/browser/editor/page/clipboard/own/writers.mjs +0 -11
- package/browser/editor/page/columns/index.mjs +1 -1
- package/browser/editor/page/commit.mjs +19 -4
- package/browser/editor/page/conflicts.mjs +6 -26
- package/browser/editor/page/convert.mjs +8 -7
- package/browser/editor/page/core.mjs +55 -17
- package/browser/editor/page/drag/index.mjs +40 -24
- package/browser/editor/page/drag/preview.mjs +9 -4
- package/browser/editor/page/editor.mjs +70 -15
- package/browser/editor/page/emoji-picker/emoji-tab.mjs +22 -13
- package/browser/editor/page/emoji-picker/grid.mjs +7 -5
- package/browser/editor/page/emoji-picker/icon-tab.mjs +4 -4
- package/browser/editor/page/emoji-picker/icons.mjs +0 -1
- package/browser/editor/page/emoji-picker/index.mjs +11 -9
- package/browser/editor/page/emoji-picker/styles.mjs +161 -2
- package/browser/editor/page/emoji-picker/support.mjs +6 -4
- package/browser/editor/page/emoji-picker/upload.mjs +12 -11
- package/browser/editor/page/fills.mjs +5 -3
- package/browser/editor/page/fold/index.mjs +348 -0
- package/browser/editor/page/fold/rule.mjs +125 -0
- package/browser/editor/page/folded.mjs +23 -0
- package/browser/editor/page/format-bar/bar.mjs +2 -1
- package/browser/editor/page/format-bar/index.mjs +1 -1
- package/browser/editor/page/geometry.mjs +8 -6
- package/browser/editor/page/handle/index.mjs +17 -6
- package/browser/editor/page/hints/index.mjs +1 -1
- package/browser/editor/page/insert/index.mjs +30 -17
- package/browser/editor/page/long-runs.mjs +75 -0
- package/browser/editor/page/look.mjs +15 -3
- package/browser/editor/page/margin.mjs +45 -24
- package/browser/editor/page/menu.mjs +69 -25
- package/browser/editor/page/merge.mjs +24 -0
- package/browser/editor/page/notices.mjs +1 -1
- package/browser/editor/page/offered.mjs +1 -1
- package/browser/editor/page/outline/folds.mjs +11 -10
- package/browser/editor/page/outline/index.mjs +131 -45
- package/browser/editor/page/outline/list.mjs +23 -11
- package/browser/editor/page/outline/read.mjs +1 -1
- package/browser/editor/page/outline/strip.mjs +7 -1
- package/browser/editor/page/panel.mjs +5 -4
- package/browser/editor/page/resize/index.mjs +1 -1
- package/browser/editor/page/selection/delete.mjs +8 -6
- package/browser/editor/page/selection/index.mjs +10 -3
- package/browser/editor/page/session.mjs +54 -3
- package/browser/editor/page/table/cell-bar.mjs +4 -1
- package/browser/editor/page/table/cells.mjs +1 -1
- package/browser/editor/page/table/icons.mjs +1 -1
- package/browser/editor/page/table/index.mjs +13 -8
- package/browser/editor/page/table/widths.mjs +9 -4
- package/browser/editor/page/text-select/index.mjs +18 -3
- package/browser/editor/page/tooltip.mjs +1 -1
- package/browser/editor/page/type-grid.mjs +4 -3
- package/browser/editor/page/typing/code-edges.mjs +63 -17
- package/browser/editor/page/typing/index.mjs +12 -6
- package/browser/editor/page/typing/leave.mjs +1 -1
- package/browser/shared/annotations.mjs +8 -10
- package/browser/shared/code-folds.mjs +5 -1
- package/browser/shared/colors.mjs +15 -13
- package/browser/shared/component-catalog.mjs +24 -10
- package/browser/shared/components/callout.mjs +4 -2
- package/browser/shared/components/index.mjs +61 -7
- package/browser/shared/components/installed.mjs +75 -5
- package/browser/shared/components/page.mjs +10 -1
- package/browser/shared/components/table.mjs +1 -1
- package/browser/shared/components/text.mjs +2 -2
- package/browser/shared/document-look.mjs +178 -0
- package/browser/shared/emoji/data/LICENSE-lucide.txt +43 -0
- package/browser/shared/emoji/data/README.md +4 -2
- package/browser/shared/emoji/data/categories.json +1 -1
- package/browser/shared/emoji/data/keywords-en.json +1 -1
- package/browser/shared/emoji/data/keywords-zh.json +1 -1
- package/browser/shared/emoji/data/names.json +1 -1
- package/browser/shared/emoji/data/positions.json +1 -1
- package/browser/shared/emoji/data/twemoji-index.json +1 -1
- package/browser/shared/emoji/data/twemoji-svg.bin +0 -0
- package/browser/shared/emoji/data.mjs +10 -12
- package/browser/shared/emoji/emoji.mjs +8 -7
- package/browser/shared/emoji/icon-value.mjs +4 -3
- package/browser/shared/html-tree.mjs +11 -5
- package/browser/shared/i18n/en.mjs +67 -8
- package/browser/shared/long-runs.mjs +39 -0
- package/browser/shared/new-names.mjs +5 -2
- package/browser/shared/outline.mjs +194 -0
- package/browser/shared/preferences.mjs +10 -4
- package/browser/shared/session.mjs +5 -4
- package/browser/shared/workspace-look.mjs +91 -0
- package/browser/shared/zoom.mjs +5 -5
- package/dist/chunk-3HIRPVLU.mjs +2 -0
- package/dist/chunk-4FS7Z7WR.mjs +2 -0
- package/dist/{chunk-LHTFLRB6.mjs → chunk-5MHMDLZD.mjs} +2 -2
- package/dist/{chunk-YXAUQPVK.mjs → chunk-5ZKJ3H4P.mjs} +3 -3
- package/dist/{chunk-ZBIM6ARY.mjs → chunk-64K7IPLO.mjs} +55 -16
- package/dist/{chunk-QYKCJ7FG.mjs → chunk-6QXGZM36.mjs} +1 -1
- package/dist/chunk-6RGJOMJP.mjs +16 -0
- package/dist/{chunk-EUX7IC5J.mjs → chunk-7DTINW6U.mjs} +2 -2
- package/dist/{chunk-6CYG3Z4V.mjs → chunk-AJ73XJF3.mjs} +1 -1
- package/dist/chunk-AUZGSZJH.mjs +13 -0
- package/dist/{chunk-7QQBR7PB.mjs → chunk-BFE45AKL.mjs} +1 -1
- package/dist/chunk-BGGDRNYQ.mjs +10 -0
- package/dist/{chunk-L4DVONOG.mjs → chunk-BXO2ZY5P.mjs} +1 -1
- package/dist/chunk-CEH4MRCC.mjs +2 -0
- package/dist/chunk-CY2FNNAB.mjs +16 -0
- package/dist/{chunk-LC7YNQFG.mjs → chunk-DFUDV4LX.mjs} +1 -1
- package/dist/chunk-DKXG4XDG.mjs +2 -0
- package/dist/chunk-E7LWZRXY.mjs +4 -0
- package/dist/chunk-EZQ34M3F.mjs +124 -0
- package/dist/chunk-FDLXYYG4.mjs +4 -0
- package/dist/chunk-FUKQNOQS.mjs +9 -0
- package/dist/{chunk-DB4WKGYF.mjs → chunk-GB5SOYQJ.mjs} +2 -2
- package/dist/{chunk-ACOPDCNB.mjs → chunk-IVDLMMBD.mjs} +1 -1
- package/dist/chunk-JPOSLGOC.mjs +6 -0
- package/dist/chunk-JVHHHGEA.mjs +3 -0
- package/dist/chunk-L3QKH4OK.mjs +26 -0
- package/dist/{chunk-B3VTYBYR.mjs → chunk-LCTHTZIL.mjs} +2 -2
- package/dist/chunk-LEF6DRCK.mjs +59 -0
- package/dist/chunk-LS4F7JUM.mjs +2 -0
- package/dist/chunk-NO5NJCHO.mjs +2 -0
- package/dist/{chunk-UNUEWH4S.mjs → chunk-NQPVAU63.mjs} +1 -1
- package/dist/chunk-O35FIXRB.mjs +2 -0
- package/dist/chunk-PL6GHLGD.mjs +15 -0
- package/dist/{chunk-G7TOXONE.mjs → chunk-QJIR2BLP.mjs} +1 -1
- package/dist/chunk-QUPLVPB2.mjs +7 -0
- package/dist/chunk-R7BNENLY.mjs +4 -0
- package/dist/chunk-S6O4UHLC.mjs +2 -0
- package/dist/{chunk-HMHK3EQ6.mjs → chunk-SGJWQKEI.mjs} +1 -1
- package/dist/chunk-SYGN7GLU.mjs +2 -0
- package/dist/chunk-TYK6VNAB.mjs +10 -0
- package/dist/{chunk-EVJ3BX3M.mjs → chunk-U6KNPJPR.mjs} +1 -1
- package/dist/{chunk-YZ5Z6H4W.mjs → chunk-UALRNVSE.mjs} +1 -1
- package/dist/chunk-UMHUSOPJ.mjs +2 -0
- package/dist/chunk-V3HXVQEM.mjs +2 -0
- package/dist/{chunk-UXUK4PMC.mjs → chunk-V5JTW2LH.mjs} +1 -1
- package/dist/chunk-V5VXUJKG.mjs +2 -0
- package/dist/chunk-VBXMADMP.mjs +2 -0
- package/dist/chunk-VNV55RUA.mjs +2 -0
- package/dist/chunk-VPD2PS35.mjs +2 -0
- package/dist/chunk-W3BGBJQW.mjs +2 -0
- package/dist/chunk-W4VKN3GF.mjs +7 -0
- package/dist/chunk-W5BXXPDJ.mjs +3 -0
- package/dist/{chunk-Z52HTUW7.mjs → chunk-XNROSH2T.mjs} +2 -2
- package/dist/chunk-XUNHRCOG.mjs +6 -0
- package/dist/{chunk-6U2SLSDN.mjs → chunk-Y6RLRPG3.mjs} +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/server.mjs +1 -1
- package/dist/worker.mjs +1 -1
- package/kit/math.js +18 -2
- package/kit/report.css +248 -137
- package/kit/runtime.js +126 -51
- package/kit/tables.js +51 -1
- package/kit/ui.js +97 -0
- package/package.json +1 -1
- package/release.json +8 -8
- package/sdk/doc-kit.d.ts +9 -3
- package/skill/SKILL.md +22 -10
- package/skill/references/building-components.md +46 -6
- package/skill/references/example-report.html +1 -1
- package/skill/references/writing-html.md +4 -4
- package/skill/sdk/doc-kit.d.ts +9 -3
- package/web/assets/index-Bh74DfsV.css +1 -0
- package/web/assets/index-UW0RyFFt.js +13 -0
- package/web/index.html +2 -2
- package/browser/editor/components/callout/page.mjs +0 -13
- package/dist/chunk-2PBALTR3.mjs +0 -57
- package/dist/chunk-3LA3EMDE.mjs +0 -15
- package/dist/chunk-5FRMCDPY.mjs +0 -16
- package/dist/chunk-5LEK2CBS.mjs +0 -2
- package/dist/chunk-5OFN5AHC.mjs +0 -2
- package/dist/chunk-5SIYS5HN.mjs +0 -2
- package/dist/chunk-5TEK3RAD.mjs +0 -2
- package/dist/chunk-7GHT2UCA.mjs +0 -15
- package/dist/chunk-ATCJYAR4.mjs +0 -2
- package/dist/chunk-C7HWOBIF.mjs +0 -2
- package/dist/chunk-E7VYDG2X.mjs +0 -2
- package/dist/chunk-FQGQH4KM.mjs +0 -2
- package/dist/chunk-GPF4YWWB.mjs +0 -9
- package/dist/chunk-GYQV7Y4J.mjs +0 -120
- package/dist/chunk-HQQMJCQJ.mjs +0 -10
- package/dist/chunk-IERUOGC3.mjs +0 -6
- package/dist/chunk-ITNLYXXV.mjs +0 -3
- package/dist/chunk-NFIBI4IP.mjs +0 -26
- package/dist/chunk-O52JMOCZ.mjs +0 -2
- package/dist/chunk-QMQUXTU4.mjs +0 -12
- package/dist/chunk-QVWVFC5K.mjs +0 -6
- package/dist/chunk-QZY6Q64C.mjs +0 -2
- package/dist/chunk-TDQP3DKQ.mjs +0 -10
- package/dist/chunk-V4CPWKMZ.mjs +0 -2
- package/dist/chunk-VACRB2NE.mjs +0 -3
- package/dist/chunk-W63L7367.mjs +0 -7
- package/dist/chunk-W7CXPCRV.mjs +0 -6
- package/dist/chunk-XINNG4F2.mjs +0 -4
- package/dist/chunk-YL2DPWVS.mjs +0 -4
- package/web/assets/index-B6Ai3wsa.js +0 -13
- package/web/assets/index-SYPC3EZy.css +0 -1
package/dist/chunk-NFIBI4IP.mjs
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{d as ht,n as Wt,p as Pt}from"./chunk-W63L7367.mjs";import{b as P,c as U,e as st}from"./chunk-A55HN5OK.mjs";import{createHash as Je}from"node:crypto";import{BLOCK_LEVEL as K}from"../browser/shared/html-tree.mjs";var nt=t=>Je("sha256").update(t).digest("hex").slice(0,16),F=t=>t.nodeName==="#text"&&!t.value.trim();function Nt(t,e){for(let s of t.childNodes??[]){if(s.tagName===e)return s;let a=s.tagName&&Nt(s,e);if(a)return a}return null}import{ATTRIBUTES as Qe,BOX_CLASSES as ts,COMPONENT_ATTRIBUTES as es,COMPONENT_CLASSES as ss,GROUPING as ns,IDENTITY as j,TOGGLES as as,UNIT_KINDS as os}from"../browser/editor/components/registry.mjs";import{attr as I,hasClass as xt}from"../browser/shared/html-tree.mjs";import{idsNamed as rs}from"../browser/shared/copy-ids.mjs";import{DIALOG as is,PAGE as cs,SECTION as ls,SHEETS as G,TABLE as Ut}from"../browser/editor/components/kit.mjs";import{matchesNode as Z,partOf as $t}from"../browser/shared/components/index.mjs";import{FLOW as at,HELD_TAGS as Ot}from"../browser/editor/components/list/index.mjs";var fs=new Set(["section","div","blockquote","ul","ol","aside","article"]),Ht=new Set(["script","style","template","noscript","link","meta","header","dialog","form","fieldset","label","input","select","textarea","button","summary","main","caption","dd","dt","tbody","thead","tfoot","tr","td","th","figcaption"]),Kt=new Set(["img","picture","svg","canvas","video","audio","iframe","object"]),kt=new Set(["hr","img"]),ds=new Set(["label","input","select","textarea","button"]),J=t=>ss.some(e=>xt(t,e))||es.some(e=>I(t,e)!==void 0);function Tt(t){let e=t.childNodes??[],s=e.findIndex(o=>Ot.has(o.tagName));if(s<0)return[];let a=e.slice(s);return a.every(o=>Ot.has(o.tagName)||F(o))?a.filter(o=>o.tagName):null}function Lt(t){return t.tagName==="li"&&t.parentNode?.tagName==="ol"&&xt(t.parentNode,at)&&t.childNodes.some(e=>e.tagName)&&t.childNodes.every(e=>e.tagName?Ot.has(e.tagName):e.nodeName!=="#text"||!e.value.trim())}function Ft(t){let e=t.tagName,s=t.sourceCodeLocation;return Ht.has(e)||!(K.has(e)||Kt.has(e))||I(t,"contenteditable")!==void 0?!1:!!(s?.startTag&&(s.endTag||kt.has(e)))}function Gt(t){if(!t.childNodes.every(s=>s.nodeName!=="#text"||!s.value.trim()))return!1;let e=t.childNodes.filter(s=>s.tagName);return e.length>0&&!e.some(s=>ds.has(s.tagName)||!(K.has(s.tagName)||Kt.has(s.tagName)||Ht.has(s.tagName)))}function bt(t,e=null){let s=t.tagName;if(!fs.has(s)||J(t)||I(t,"contenteditable")!==void 0)return null;let a=(I(t,"class")??"").split(/\s+/).filter(Boolean),o=t.childNodes.filter(d=>d.tagName),n=()=>o.every(d=>d.tagName==="li")&&t.childNodes.every(d=>d.tagName||!d.value?.trim());if(s==="ol"&&a.includes(at))return a.every(d=>d===at)&&n()?"flowchart":null;if(s==="ul"||s==="ol")return a.every(d=>(as.list??[]).includes(d))&&n()?"list":null;let r=t.childNodes.every(d=>d.nodeName!=="#text"||!d.value.trim()),l=Z(t,ls.match);if(s==="section"&&(a.length===0||l))return r&&(o.length>0||l)?"section":null;let u=ts.find(([d])=>a.includes(d))?.[1];return u&&r&&o.length===0?u:Gt(t)?u||(a.length>0?null:s==="blockquote"?"quote":ns.has(e)?"plain":null):null}var us=(t,e,s=()=>!1)=>Object.entries(e.sourceCodeLocation.attrs??{}).filter(([a])=>a!=="class"&&a!==j&&!s(a,I(e,a))).sort((a,o)=>a[1].startOffset-o[1].startOffset).map(([,a])=>` ${t.slice(a.startOffset,a.endOffset)}`).join("");function z(t,e=t.parentNode){let s=(o,n,r)=>(!n||[n].flat().includes(o?.tagName))&&(!r||xt(o,r));return os.find(({tag:o,class:n,attr:r,parent:l})=>s(t,o,n)&&(!r||I(t,r)!==void 0)&&(!l||e?.tagName&&s(e,l.tag,l.class)))?.kind??"block"}var ms={flowchart:{tagName:"ol",attrs:[{name:"class",value:at}]}},Ma=(t,e)=>z(t,ms[e]??null);function qt(t,e){let s=[],a=[],o=i=>i.parentNode.childNodes,n=i=>o(i)[o(i).indexOf(i)-1]??null,r=i=>/^[ \t]*$/.test(e.slice(e.lastIndexOf(`
|
|
3
|
-
`,i-1)+1,i)),l=i=>{let f=n(i);for(;f&&F(f);)f=n(f);return f?.tagName?f:null},u=i=>{if(!Z(i,Ut.frame))return null;let f=l(i);return f&&Z(f,Ut.lead)&&f.sourceCodeLocation?.endTag?f:null},d=(i,f)=>{let $=i.sourceCodeLocation.startOffset;for(let x=n(i);x;)if(F(x)&&(x.value.match(/\n/g)?.length??0)<=1)x=n(x);else if(x.nodeName==="#comment"&&x.sourceCodeLocation&&r(x.sourceCodeLocation.startOffset))f.add(x),$=x.sourceCodeLocation.startOffset,x=n(x);else break;return $},m=(i,f,$,x)=>{let c=i.sourceCodeLocation,N=u(i),L=c.attrs?.class,O={id:s.length,tag:i.tagName,kind:z(i),box:f.id,parent:$?.id??null,start:d(N??i,x),end:c.endOffset,elStart:c.startOffset,at:c.startTag.endOffset-1,lead:N?N.sourceCodeLocation.startTag.endOffset-1:null,classAttr:L?{start:L.startOffset,end:L.endOffset,value:I(i,"class")}:null,attrs:i.attrs.map(({name:S,value:A})=>({name:S,value:A})),blockId:I(i,j)??null,carried:us(e,i,S=>!!Qe[z(i)]?.[S]),blockIdAttr:c.attrs?.[j]?{start:c.attrs[j].startOffset,end:c.attrs[j].endOffset}:null,companion:null,keep:null,node:i,nodes:N?[N,i]:[i]};return s.push(O),N&&x.add(N),O},g=(i,f,$,x=null)=>{let c=i.sourceCodeLocation,N={id:a.length,kind:f,unit:$?.id??null,key:x,at:c.startTag.endOffset-1,innerEnd:c.endTag?.startOffset??null,pure:!0};return a.push(N),N},T=(i,f,$)=>{let x=g(i,"tabs",f),c=new Set;for(let N of i.childNodes){if(!N.tagName){N.nodeName==="#text"&&N.value.trim()&&(x.pure=!1);continue}let L=I(N,G.tabKey),O=L&&$.find(M=>I(M,G.panelKey)===L);if(N.tagName!=="button"||!Z(N,G.tab)||!O?.sourceCodeLocation?.endTag||!N.sourceCodeLocation?.endTag){x.pure=!1;continue}let S=m(N,x,f,c);S.kind="tab",S.key=L;let A=O.sourceCodeLocation;S.companion={tag:O.tagName,start:d(O,new Set),end:A.endOffset,elStart:A.startOffset},S.nodes.push(O)}for(let N of i.childNodes)N.nodeName==="#comment"&&!c.has(N)&&(x.pure=!1)},E=(i,f,$,x=null)=>{let c=g(i,f,$,x),N=new Set,L=i.childNodes.filter(O=>O.tagName);L.forEach((O,S)=>{if(L[S+1]&&u(L[S+1])===O)return;if(f==="header"&&O.tagName==="h1"||!Ft(O)){c.pure=!1,O.tagName==="dialog"&&k(O,$),f==="main"&&Z(O,cs.header)&&O.sourceCodeLocation?.endTag&&E(O,"header",null);return}y(O,m(O,c,$,N),f)});for(let O of i.childNodes)(O.nodeName==="#text"?O.value.trim():!O.tagName&&!N.has(O))&&(c.pure=!1)},y=(i,f,$)=>{if(f.kind==="sheets"){let x=$t(i,G.panels),[c]=$t(i,G.row);c&&T(c,f,x);for(let N of x)(Gt(N)||N.sourceCodeLocation?.endTag&&N.childNodes.every(F))&&E(N,"panel",f,I(N,G.panelKey))}else if(i.tagName==="details")for(let x of i.childNodes)x.tagName&&bt(x)==="details"&&E(x,"details",f);else if(i.tagName==="li"&&Lt(i))E(i,"node",f);else if(i.tagName==="li")C.push([i,f]);else{let x=bt(i,$);x&&E(i,x,f)}},k=(i,f)=>{let[$]=$t(i,is.content);$&&bt($)==="dialog"&&E($,"dialog",f,I(i,"id")??null)},C=[],h=(i,f)=>{let $=Tt(i);if($===null||!i.sourceCodeLocation?.endTag)return;let x=g(i,"nest",f);x.pure=!1,f.nested=$.length>0;let c=new Set;for(let N of $)Ft(N)&&y(N,m(N,x,f,c),"nest")},b=Nt(t,"main");b?.sourceCodeLocation?.startTag&&E(b,"main",null);for(let i=0;i<C.length;i++)h(...C[i]);let p=Os(t,s);return{units:s,boxes:a,referenced:p}}var ps=t=>t===void 0||/^\s*(?:module|(?:text|application)\/(?:x-)?(?:javascript|ecmascript)|text\/javascript1\.[0-5]|text\/(?:jscript|livescript))?\s*$/i.test(t);function gs(t){let e=hs(t),s=new Set,a=[],o=/(["'`])((?:(?!\1)[^\\\n]|\\.)*)\1/g,n=m=>m.split(/\s+/).filter(Boolean).forEach(g=>s.add(g)),r=/(?:\bclassList\s*\.\s*(?:add|remove|toggle|contains|replace)|\.classed|\bgetElementsByClassName|\.(?:has|add|remove|toggle)Class|\bclassName\s*\.\s*(?:includes|indexOf|startsWith|endsWith)|\bclassName\s*\.\s*split\s*\([^)]*\)\s*\.\s*(?:includes|indexOf))\s*\(\s*((?:(["'`])(?:(?!\2)[^\\\n]|\\.)*\2\s*,?\s*)+)/g;for(let[,m]of t.matchAll(r))for(let[,,g]of m.matchAll(o))n(g);if(/(["'`])[^"'`\n]*\.\1\s*\+|\.\$\{/.test(t)||/(?:\bclassList\s*\.\s*(?:add|remove|toggle|contains|replace)|\.classed|\.(?:has|add|remove|toggle)Class)\s*\(\s*[A-Za-z_$][\w$.]*\s*[,)]/.test(t))for(let m of e)/^-?[A-Za-z_][\w-]*$/.test(m)&&s.add(m);let u=/\bclassName\s*(?:[!=]==?|=)\s*(["'`])((?:(?!\1)[^\\\n]|\\.)*)\1|(["'`])((?:(?!\3)[^\\\n]|\\.)*)\3\s*[!=]==?\s*[\w$.]*\bclassName\b/g;for(let m of t.matchAll(u))n(m[2]??m[4]);let d=/\[\s*class\s*([~|^$*]?)=\s*(?:"([^"]*)"|'([^']*)'|([^\]\s]+))\s*(?:[is]\s*)?\]/g;for(let m of e)for(let g of m.matchAll(d)){let T=g[2]??g[3]??g[4];g[1]===""||g[1]==="~"||g[1]==="|"?n(T):a.push(T)}return{names:s,partial:a,selectors:e.join(`
|
|
4
|
-
`)}}function hs(t){let e=[],s=[],a=0,o="",n=0,r=l=>{let u="";for(let d=l;d<t.length;d++){let m=t[d];if(m==="\\"){u+=t.slice(d,d+2),d++;continue}if(m==="`")return e.push(u),d+1;if(m==="$"&&t[d+1]==="{")return e.push(u),s.push(a),d+2;u+=m}return e.push(u),t.length};for(;n<t.length;){let l=t[n],u=t[n+1];if(l==="/"&&u==="/"){let d=t.indexOf(`
|
|
5
|
-
`,n);n=d<0?t.length:d;continue}if(l==="/"&&u==="*"){let d=t.indexOf("*/",n+2);n=d<0?t.length:d+2;continue}if(l==='"'||l==="'"){let d=n+1,m="";for(;d<t.length&&t[d]!==l&&t[d]!==`
|
|
6
|
-
`;)t[d]==="\\"?(m+=t.slice(d,d+2),d+=2):m+=t[d++];e.push(m),n=d+1,o="a";continue}if(l==="`"){n=r(n+1),o="a";continue}if(l==="}"&&s.length&&s.at(-1)===a){s.pop(),n=r(n+1),o="a";continue}if(l==="/"&&(!/[\w$)\]}]/.test(o)||/(?:^|[^\w$.])(?:return|typeof|case|in|of|void|delete|throw|yield|await|else|do)\s*$/.test(t.slice(Math.max(0,n-12),n)))){let d=n+1,m=!1;for(;d<t.length&&t[d]!==`
|
|
7
|
-
`&&(m||t[d]!=="/");)t[d]==="\\"?d++:t[d]==="["?m=!0:t[d]==="]"&&(m=!1),d++;if(t[d]==="/"){for(n=d+1;/[a-z]/i.test(t[n]??"");)n++;o="a";continue}}l==="{"?a++:l==="}"&&a--,/\s/.test(l)||(o=l),n++}return e}var Ns=/\bDocSheets\b|["'`]sheets-|\bactiveSheet\b|data-active-sheet|["'`]sheet["'`]|\bsheet\s*:/,$s=t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");function bs(t,e){if(!Ns.test(e))return!1;let s=$s(t),a=`(["'\`])${s}\\1`;return[`\\bsheet["'\`]?\\s*:\\s*${a}`,`\\.set\\(\\s*(["'\`])${s}\\1`,`\\.set\\(\\s*(["'\`])sheet\\1\\s*,\\s*(["'\`])${s}\\2`,`[!=]==?\\s*${a}`,`${a}\\s*[!=]==?`,`\\bcase\\s+${a}\\s*:`,`active-sheet\\s*=\\s*["']?${s}["'\\]]`].some(o=>new RegExp(o).test(e))}function Os(t,e){let s=[],a=new Map,o=h=>{for(let b of h.childNodes??[]){if(!b.tagName)continue;let p=b.sourceCodeLocation?.startOffset??-1;b.tagName==="script"&&I(b,"src")===void 0&&s.push({at:p,code:ps(I(b,"type")),text:b.childNodes.map(i=>i.value??"").join("")});for(let{name:i,value:f}of b.attrs)if(!(i==="aria-labelledby"&&b.tagName==="section"))for(let $ of rs(i,f))(a.get($)??a.set($,[]).get($)).push(p);o(b.tagName==="template"?b.content:b)}};o(t);let n=h=>h.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=h=>h.slice(5).replace(/-([a-z])/g,(b,p)=>p.toUpperCase()),l=s.filter(h=>h.code),u=l.map(h=>h.text).join(`
|
|
8
|
-
`),d=h=>l.some(b=>h(b.at))?l.filter(b=>!h(b.at)).map(b=>b.text).join(`
|
|
9
|
-
`):u,m=new Map,g=(h,b)=>(p,i)=>{if(i!==u)return b(p,i);let f=`${h} ${p}`;return m.has(f)||m.set(f,b(p,i)),m.get(f)},T=g("id",(h,b)=>new RegExp(`#${n(h)}(?![\\w-])|(["'\`])${n(h)}\\1`).test(b)),E=g("data",(h,b)=>new RegExp(`${n(h)}(?![\\w-])|dataset\\.${r(h)}(?![\\w$])`).test(b)),y=new Map,k=g("class",(h,b)=>{y.has(b)||y.set(b,gs(b));let{names:p,partial:i,selectors:f}=y.get(b);return p.has(h)||i.some($=>$.includes(h))||new RegExp(`\\.${n(h)}(?![\\w-])`).test(f)}),C=h=>h.split(/\s+/).filter(b=>b&&!/^(doc-|katex)/.test(b));for(let h of e){let b=[[h.start,h.end],...h.companion?[[h.companion.start,h.companion.end]]:[]],p=v=>b.some(([w,_])=>v>=w&&v<_),i=new Map,f=new Map,$=new Map,x=(v,w,_)=>(v.get(w)??v.set(w,[]).get(w)).push(_),c=v=>{if(!v.tagName)return;let w=v.sourceCodeLocation?.startOffset??h.start;for(let{name:_,value:W}of v.attrs)_==="id"&&W?x(i,W,w):_.startsWith("data-")&&_!==j?x(f,_,w):_==="class"&&C(W).forEach(gt=>x($,gt,w));(v.tagName==="template"?v.content:v).childNodes?.forEach(c)};h.nodes.forEach(c);let N=d(p),L=(v,w,_)=>[...v].filter(([W])=>w(W)).map(([W,gt])=>({name:_(W),at:gt})),O=[...h.key&&s.some(v=>!p(v.at)&&bs(h.key,v.text))?[{name:`"${h.key}"`,at:[h.start]}]:[],...L(i,v=>T(v,N),v=>`#${v}`),...L(f,v=>E(v,N),v=>`[${v}]`),...L($,v=>k(v,N),v=>`.${v}`)],S=L(i,v=>(a.get(v)??[]).some(w=>!p(w)),v=>`#${v}`),A=O.length>0?O:S,M=A.flatMap(v=>v.at),pt=M.some(v=>!e.some(w=>w!==h&&h.start<=w.start&&w.end<=h.end&&w.start<=v&&v<w.end));h.keep=A.length>0?{reason:O.length>0?"script":"ref",names:A.map(v=>v.name),at:M,own:pt}:null}return h=>{let b=h.sourceCodeLocation;if(!b||!h.attrs.some(({name:$})=>$==="id"||$==="class"||$.startsWith("data-")))return null;let p=$=>$>=b.startOffset&&$<b.endOffset,i=d(p),f=null;for(let{name:$,value:x}of h.attrs)if($==="id"&&x){if(T(x,i))return"script";(a.get(x)??[]).some(c=>!p(c))&&(f="ref")}else{if($.startsWith("data-")&&$!==j&&E($,i))return"script";if($==="class"&&C(x).some(c=>k(c,i)))return"script"}return f}}function xs(t,e){let s=[],a=o=>{let n=o.sourceCodeLocation?.attrs?.[j];if(n){let r=n.startOffset>0&&/\s/.test(t[n.startOffset-1])?n.startOffset-1:n.startOffset;s.push({start:r,end:n.endOffset})}for(let r of o.content?.childNodes??o.childNodes??[])a(r)};return e.forEach(a),s.sort((o,n)=>o.start-n.start)}var zt=(t,e,s,a)=>{let o="",n=e;for(let r of a)r.start<n||r.end>s||(o+=t.slice(n,r.start),n=r.end);return o+t.slice(n,s)},ja=(t,e)=>{let s=xs(t,e.nodes),a=zt(t,e.start,e.end,s);return nt(e.companion?`${a}\0${zt(t,e.companion.start,e.companion.end,s)}`:a)};st();import{IDENTITY as ks}from"../browser/editor/components/registry.mjs";import{SHEETS as ot,TABLE as Xt}from"../browser/editor/components/kit.mjs";import{escapeAttribute as rt,escapeText as Vt}from"../browser/shared/escape.mjs";import{isInstance as Ts,matchesNode as yt}from"../browser/shared/components/index.mjs";import{attr as R}from"../browser/shared/html-tree.mjs";import{CHART_DATA as Ls,CHART_SOURCE as Yt}from"../browser/shared/table-chart.mjs";import{freshPrefix as ys,referencedIds as vs,rewrite as Cs}from"../browser/shared/copy-ids.mjs";var Zt=(t={})=>Object.entries(t).map(([e,s])=>s===""?` ${e}`:` ${e}="${rt(String(s))}"`).join(""),ct=(t,e)=>t[e-1]==="/"?e-1:e;function it(t,e,s){let a=e;for(;a>0&&/\s/.test(t[a-1]);)a--;return{start:a,end:s}}function qa(t){let e=s=>s.nodeName==="#text"?s.value:(s.childNodes??[]).map(e).join("");return e(U(t)).replace(/\s+/g," ").trim()}function Xa(t,{from:e,to:s}){let o=Jt(P(t,{sourceCodeLocationInfo:!0}))?.sourceCodeLocation;if(!o?.endTag||!e)return null;let n=t.slice(o.startTag.endOffset,o.endTag.startOffset),r=Vt(e),l=n.indexOf(r);if(l<0||n.indexOf(r,l+1)>=0)return null;let u=o.startTag.endOffset+l;return{start:u,end:u+r.length,text:Vt(s)}}function Jt(t){for(let e of t.childNodes??[]){if(e.tagName==="title")return e;if(e.tagName==="body")continue;let s=e.tagName&&Jt(e);if(s)return s}return null}function Ss(t){let e=[],s=0,a=null,o=0;for(let n=0;n<t.length;n++){let r=t[n];if(r==="&"){let l=/^&(#\d+|#x[\da-f]+|[a-z]\w*);/i.exec(t.slice(n));l&&(n+=l[0].length-1)}else a?r===a?a=null:r==="\\"&&n++:r==='"'||r==="'"?a=r:r==="("?s++:r===")"?s=Math.max(0,s-1):r===";"&&s===0&&(e.push(t.slice(o,n)),o=n+1)}return e.push(t.slice(o)),e.map(n=>n.trim()).filter(Boolean)}function Ct(t,e){let s=Ss(t);for(let[a,o]of e){let n=s.findIndex(r=>r.slice(0,r.indexOf(":")).trim()===a);o===null?n>=0&&s.splice(n,1):n>=0?s[n]=`${a}: ${o}`:s.push(`${a}: ${o}`)}return s.join("; ")}var Es=new Set(["pre","textarea","script","style"]);function Va(t){if(typeof t!="string"||!t.trim())return null;let s=U(t,{sourceCodeLocationInfo:!0}).childNodes.filter(u=>u.nodeName!=="#comment"&&!(u.nodeName==="#text"&&!u.value.trim())),[a,o]=s;if(s.length===2&&a.tagName==="button"&&yt(a,ot.tab)&&o.tagName&&o.sourceCodeLocation?.endTag&&R(a,ot.tabKey)&&R(o,ot.panelKey)===R(a,ot.tabKey)){let u=a.sourceCodeLocation.endOffset;return{element:a,source:t.slice(0,u),panel:t.slice(u).replace(/^\s+/,""),kind:"tab"}}let n=s.at(-1),r=s.length===2?s[0]:null;if(!n?.tagName||!n.sourceCodeLocation?.startTag||s.length>2||r&&!(r.tagName&&yt(r,Xt.lead)&&yt(n,Xt.frame)))return null;let l=z(n);return{element:n,source:t,kind:l}}function ws(t){let e=[],s=a=>{for(let o of a.childNodes??[]){if(!o.tagName)continue;let n=R(o,"id");n&&e.push(n),s(o.tagName==="template"?o.content:o)}};return s(P(t)),e}var Ya=(t,e)=>`${vt(t.slice(e.start,e.end),H(t,e.start),"")}
|
|
10
|
-
${vt(t.slice(e.companion.start,e.companion.end),H(t,e.companion.start),"")}`;function Za(t,e,{keys:s=null,taken:a=null}={}){let o=t.slice(e.start,e.end),n=[],r=U(o,{sourceCodeLocationInfo:!0}),l=[],u=y=>{for(let k of y.childNodes??[])k.tagName&&(l.push(k),u(k.tagName==="template"?k.content:k))};u(r);let d=vs(l.flatMap(y=>y.attrs)),m=new Set(l.map(y=>R(y,"id")).filter(y=>y&&d.has(y))),g=new Map;if(m.size>0){let y=a??new Set(ws(t)),k=ys(y);for(let C of m)g.set(C,`${k}${C}`),y.add(`${k}${C}`)}let T=y=>{for(let k of y.childNodes??[])if(k.tagName){for(let C of[ks,"id"]){let h=k.sourceCodeLocation?.attrs?.[C];h&&(C==="id"&&g.has(R(k,"id"))?n.push({start:h.startOffset,end:h.endOffset,text:`id="${rt(g.get(R(k,"id")))}"`}):n.push(it(o,h.startOffset,h.endOffset)))}for(let{name:C,prefix:h,value:b}of g.size>0?k.attrs:[]){let p=h?`${h}:${C}`:C,i=Cs(p,b,g),f=k.sourceCodeLocation?.attrs?.[p];i!==null&&f&&n.push({start:f.startOffset,end:f.endOffset,text:`${p}="${rt(i)}"`})}for(let C of[Ls,Yt]){let h=k.sourceCodeLocation?.attrs?.[C],b=R(k,C);!h||!s||!Object.hasOwn(s,b)||(s[b]!==null?n.push({start:h.startOffset,end:h.endOffset,text:`${C}="${rt(s[b])}"`}):C===Yt&&n.push(it(o,h.startOffset,h.endOffset)))}T(k.tagName==="template"?k.content:k)}};T(r);let E=n.sort((y,k)=>k.start-y.start).reduce((y,{start:k,end:C,text:h=""})=>y.slice(0,k)+h+y.slice(C),o);return vt(E,H(t,e.start),"")}function vt(t,e,s){if(e===null||s===null||e===s||!t.includes(`
|
|
11
|
-
`))return t;let a=[],o=l=>{for(let u of l.childNodes??[]){if(!u.tagName)continue;let d=u.sourceCodeLocation;(Es.has(u.tagName)||Ts(u))&&d?.startTag&&d.endTag?a.push([d.startTag.endOffset,d.endTag.startOffset]):o(u.tagName==="template"?u.content:u)}};o(U(t,{sourceCodeLocationInfo:!0}));let n="",r=0;for(let l of t.split(/(?<=\n)/)){let u=a.some(([m,g])=>r>m&&r<=g),d=l===`
|
|
12
|
-
`||l===`\r
|
|
13
|
-
`;n+=r>0&&!u&&!d&&l.startsWith(e)?s+l.slice(e.length):l,r+=l.length}return n}function H(t,e){let s=t.slice(t.lastIndexOf(`
|
|
14
|
-
`,e-1)+1,e);return/^[ \t]*$/.test(s)?s:null}function Is(t,e,s){let a=t.lastIndexOf(`
|
|
15
|
-
`,e-1)+1,o=t.indexOf(`
|
|
16
|
-
`,s),n=o<0?t.length:o+1;return/^[ \t]*$/.test(t.slice(a,e))&&/^[ \t]*\r?\n?$/.test(t.slice(s,n))?{start:a,end:n,text:""}:{start:e,end:s,text:""}}function Ja(t,e,s){let a=/^\s*(?=<\/li\s*>)/i.exec(t.slice(s,s+400));if(a)return{start:e-/\s*$/.exec(t.slice(Math.max(0,e-400),e))[0].length,end:s+a[0].length,text:""};let o=Is(t,e,s);if(o.start===e&&o.end===s)return o;let n=/^[ \t]*\r?\n$/,r=t.indexOf(`
|
|
17
|
-
`,o.end),l=r>=0&&n.test(t.slice(o.end,r+1)),u=t.lastIndexOf(`
|
|
18
|
-
`,o.start-2)+1,d=o.start>0&&n.test(t.slice(u,o.start)),m=t.slice(0,e).trimEnd(),g=m.endsWith(">")?m.slice(m.lastIndexOf("<")):"",T=/^<[a-z]/i.test(g)&&!/\/\s*>$/.test(g)&&!kt.has(g.match(/^<([a-z0-9-]+)/i)?.[1].toLowerCase()),E=/^\s*<\//.test(t.slice(s,s+200));return l&&(d||T)?{...o,end:r+1}:d&&E?{...o,start:u}:o}import{iconKind as As}from"../browser/shared/emoji/icon-value.mjs";import{SHEETS_LABEL as Bs}from"../browser/shared/components/sheets.mjs";var Qt=/^[a-z0-9][a-z0-9_-]{0,63}$/i,_s=(t,e="")=>`<button class="doc-sheet-tab" type="button" data-sheet-tab="${t.sheet}"${t.icon?` data-tab-icon="${t.icon}"`:""}${e}>${t.title}</button>`,te={sheets:{check:t=>typeof t.name=="string"&&Qt.test(t.name)&&t.children.length>=1&&t.children.every(e=>e.type==="tab")&&new Set(t.children.map(e=>e.sheet)).size===t.children.length,write(t,e){let s=e.inner===null?null:e.inner+e.step,a=Bs[e.language],o=e.block(`<div class="doc-sheet-tabs" aria-label="${a}">`,t.children.map(r=>_s(r,e.idOf(r))),"</div>",e.inner,s),n=t.children.map(r=>r.children.length===0?`<div data-doc-sheet="${r.sheet}"></div>`:e.block(`<div data-doc-sheet="${r.sheet}">`,r.children.map(l=>e.render(l,s)),"</div>",e.inner,s));return e.block(`<section class="doc-sheet-shell" data-doc-sheets="${t.name}" aria-label="${a}"${e.id}>`,[o,...n],"</section>")}},tab:{empty:!0,check:t=>typeof t.title=="string"&&t.title.trim()!==""&&t.title.length<=200&&!/[<>\r\n]/.test(t.title)&&typeof t.sheet=="string"&&Qt.test(t.sheet)&&(t.icon===void 0||As(t.icon)==="emoji")}};import{escapeMarkup as lt}from"../browser/shared/escape.mjs";import{imageFile as Ms}from"../browser/shared/media.mjs";import{emptyFigure as js}from"../browser/editor/components/media/write.mjs";var Rs=t=>typeof t=="string"&&t.length<=2e3&&/^https?:\/\/[^\s"<>]+$/.test(t),ee=(t,e)=>typeof t=="string"&&t.length<=e&&!/[\u0000-\u001f]/.test(t),se=t=>t.href===""&&!t.title&&!t.description&&!t.icon&&!t.cover&&t.caption==="",ne=t=>t==null||Ms(t),ae={bookmark:{check:(t,{validLeaf:e})=>se(t)||Rs(t.href)&&ee(t.title,300)&&ee(t.description??"",600)&&ne(t.icon)&&ne(t.cover)&&typeof t.caption=="string"&&(t.caption===""||e({tag:"figcaption"},t.caption)),write(t,e){if(se(t))return js("bookmark",e);let s=t.title.trim()||new URL(t.href).hostname,a=[`<span class="doc-bookmark-title">${lt(s)}</span>`,t.description?`<span class="doc-bookmark-description">${lt(t.description)}</span>`:"",`<span class="doc-bookmark-url">${t.icon?`<img class="doc-bookmark-icon" src="${t.icon}" alt="">`:""}<span class="doc-bookmark-href">${lt(t.href)}</span></span>`].join(""),o=t.cover?`<span class="doc-bookmark-cover"><img src="${t.cover}" alt=""></span>`:"",n=`<a class="doc-bookmark-card" href="${lt(t.href)}" target="_blank" rel="noopener noreferrer"><span class="doc-bookmark-text">${a}</span>${o}</a>`;return e.block(`<figure class="doc-bookmark"${e.id}>`,[n,`<figcaption>${t.caption}</figcaption>`],"</figure>")}}};import{BLOCK_TYPES as Ds,sizeValue as Ws}from"../browser/editor/components/registry.mjs";import{LINE_START as re,lineStart as Ps}from"../browser/shared/code-lines.mjs";import{hasClass as oe}from"../browser/shared/html-tree.mjs";import{CODE_HEIGHT as St,FOLDED_LINES as ie,validFolded as Us,validLanguage as Fs}from"../browser/editor/components/code/index.mjs";var zs=(t,e,s,a,o="",n="",r="",l="")=>`<div class="${t.className}"${s?` data-language="${s}"`:""}${l?` ${re}="${l}"`:""}${r?` ${ie}="${r}"`:""}${a?` style="${St}: ${a}"`:""}${o}><div class="doc-code-title">${n}</div><pre><code>${e}</code></pre></div>`,Hs=(t,e)=>t==="data-language"||t===ie||t===re||t==="style"&&new RegExp(`^\\s*${St}\\s*:[^;]*;?\\s*$`).test(e??""),Ks=t=>typeof t=="string"&&t.length<=200&&!/[<>\n]|&(?!(amp|lt|gt|quot|#39);)/.test(t),Gs=t=>(t.language===void 0||Fs(t.language))&&(t.folded===void 0||Us(t.folded))&&(t.height===void 0||Ws("code",St,t.height)===t.height)&&(t.title===void 0||Ks(t.title))&&(t.lineStart===void 0||typeof t.lineStart=="string"&&String(Ps(t.lineStart))===t.lineStart);function qs(t){let{node:e}=t;if(t.tag!=="div"||t.nested||!oe(e,Ds.code.className))return!1;let s=(o,n)=>{let r=o.childNodes??[],l=r.filter(u=>u.tagName);return l.length===n.length&&l.every((u,d)=>u.tagName===n[d])&&r.every(u=>u.tagName||!(u.value??"").trim())?l:null},a=s(e,["div","pre"]);return!!a&&oe(a[0],"doc-code-title")&&!!s(a[1],["code"])}var ce={code:{fields:["language","folded","height","title","lineStart"],check:Gs,leaf:(t,e,s)=>zs(t,e.html,e.language,e.height,s,e.title,e.folded,e.lineStart),written:qs,attribute:Hs}};import{sizeValue as Xs}from"../browser/editor/components/registry.mjs";import{MIN_COLUMNS as Vs,RATIO as le}from"../browser/editor/components/columns/index.mjs";var fe={columns:{check:t=>t.children.length>=Vs&&t.children.every(e=>e.type==="column")},column:{check:t=>t.ratio===void 0||Xs("column",le,t.ratio)===t.ratio,write(t,e){let s=t.ratio===void 0?"":` style="${le}: ${t.ratio}"`;return e.block(`<div class="doc-column"${s}${e.id}>`,e.children(e.inner),"</div>")}}};var de={details:{empty:!0,check:(t,{validLeaf:e})=>t.title===""||e({tag:"span"},t.title),write(t,e){let s=e.inner===null?null:e.inner+e.step,a=e.block('<div class="doc-details-content">',e.children(s),"</div>",e.inner,s),o=t.classes?.length?` ${t.classes.join(" ")}`:"";return e.block(`<details class="doc-details${o}"${e.id}>`,[`<summary><span class="doc-details-summary-label">${t.title}</span></summary>`,t.children.length>0?a:'<div class="doc-details-content"></div>'],"</details>")}}};var ue={dialog:{empty:!0,check(t,{usedIds:e}){return typeof t.id!="string"||!/^[A-Za-z][\w-]{0,63}$/.test(t.id)||e.has(t.id)?!1:(e.add(t.id),!0)},write(t,e){let s=t.children.length>0?e.block('<div class="doc-dialog-content">',e.children(e.deep(3)),"</div>",e.deep(2),e.deep(3)):'<div class="doc-dialog-content"></div>',a=e.block('<div class="doc-dialog-panel">',[s],"</div>",e.deep(1),e.deep(2));return e.block(`<dialog class="doc-dialog" id="${t.id}">`,[a],"</dialog>")}}};import{escapeAttribute as Ys}from"../browser/shared/escape.mjs";import{embedFile as me}from"../browser/shared/media.mjs";import{emptyFigure as Zs}from"../browser/editor/components/media/write.mjs";import{FILE_SANDBOX as Js,WEB_SANDBOX as Qs}from"../browser/editor/components/embed/index.mjs";var tn=t=>typeof t=="string"&&t.length<=2e3&&/^https:\/\/[^\s"<>]+$/.test(t),pe=t=>t.src===""&&t.height===void 0&&t.caption==="",ge={embed:{check:(t,{validLeaf:e})=>pe(t)||(tn(t.src)||me(t.src))&&(t.height===void 0||/^\d{2,4}px$/.test(t.height))&&typeof t.caption=="string"&&(t.caption===""||e({tag:"figcaption"},t.caption)),write(t,e){if(pe(t))return Zs("embed",e);let s=me(t.src),a=s?/\.pdf$/i.test(t.src)?"":` sandbox="${Js}"`:` sandbox="${Qs}" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen`,o=`<iframe class="doc-embed-frame" src="${Ys(t.src)}"${a} loading="lazy"></iframe>`,n=t.height?` style="--doc-embed-height: ${t.height}"`:"";return e.block(`<figure class="doc-embed${s?" doc-embed--file":""}"${n}${e.id}>`,[o,`<figcaption>${t.caption}</figcaption>`],"</figure>")}}};import{escapeMarkup as he}from"../browser/shared/escape.mjs";import{assetFile as en}from"../browser/shared/media.mjs";import{emptyFigure as sn}from"../browser/editor/components/media/write.mjs";var Ne=t=>t.href===""&&t.name===""&&t.size===void 0&&t.caption==="",nn=t=>typeof t=="string"&&t.trim()!==""&&t.length<=120&&!/[\u0000-\u001f<>:"/\\|?*]/.test(t),$e={file:{check:(t,{validLeaf:e})=>Ne(t)||en(t.href)&&nn(t.name)&&(t.size===void 0||/^\d+(\.\d)? (B|KiB|MiB|GiB)$/.test(t.size))&&typeof t.caption=="string"&&(t.caption===""||e({tag:"figcaption"},t.caption)),write(t,e){if(Ne(t))return sn("file",e);let s=t.size?`<span class="doc-file-size">${t.size}</span>`:"",a=`<a class="doc-file-link" href="${t.href}" download="${he(t.name)}"><span class="doc-file-name">${he(t.name)}</span>${s}</a>`;return e.block(`<figure class="doc-file"${e.id}>`,[a,`<figcaption>${t.caption}</figcaption>`],"</figure>")}}};import{FLOW as an,FLOW_DIRECTION as be,FLOW_RATIO as Oe}from"../browser/editor/components/flowchart/index.mjs";import{START as on,validDirection as xe,validStart as rn}from"../browser/editor/components/list/index.mjs";import{sizeValue as cn,TOGGLES as ln}from"../browser/editor/components/registry.mjs";var ke={flowchart:{check:t=>(t.start===void 0||rn(t.start))&&(t.direction===void 0||xe(t.direction))&&t.children.length>0,write:(t,e)=>e.block(`<ol class="${an}"${t.start?` ${on}="${t.start}"`:""}${t.direction?` ${be}="${t.direction}"`:""}${e.id}>`,e.children(e.inner),"</ol>")},step:{check:t=>(t.classes===void 0||Array.isArray(t.classes)&&new Set(t.classes).size===t.classes.length&&t.classes.every(e=>(ln.step??[]).includes(e)))&&(t.ratio===void 0||cn("step",Oe,t.ratio)===t.ratio)&&(t.direction===void 0||xe(t.direction))&&t.children.length>0,write(t,e){let s=t.classes?.length?` class="${t.classes.join(" ")}"`:"",a=t.direction?` ${be}="${t.direction}"`:"",o=t.ratio===void 0?"":` style="${Oe}: ${t.ratio}"`;return e.block(`<li${s}${a}${o}${e.id}>`,e.children(e.inner),"</li>")}}};import{SPAN as fn,SPAN_SIZE as Te,imageFile as Le}from"../browser/shared/media.mjs";import{emptyFigure as dn}from"../browser/editor/components/media/write.mjs";var un=/^\d{1,3}(\.\d{1,3})?( \d{1,3}(\.\d{1,3})?){3}$/,ye=t=>t.src===""&&t.caption===""&&t.span===void 0&&t.original===void 0&&t.classes===void 0,mn=t=>typeof t=="number"&&Number.isFinite(t)&&t>=Te.min&&t<=Te.max,ve={image:{check:(t,{validLeaf:e})=>ye(t)||Le(t.src)&&typeof t.caption=="string"&&(t.caption===""||e({tag:"figcaption"},t.caption))&&(t.span===void 0||mn(t.span))&&(t.original===void 0||Le(t.original)&&typeof t.crop=="string"&&un.test(t.crop)),write(t,e){if(ye(t))return dn("image",e);let s=["doc-image",...t.classes??[]].join(" "),a=t.span===void 0?"":` style="${fn}: ${Math.round(t.span*1e3)/1e3}"`,o=t.original===void 0?"":` data-original="${t.original}" data-crop="${t.crop}"`;return e.block(`<figure class="${s}"${a}${e.id}>`,[`<img src="${t.src}" alt=""${o}>`,`<figcaption>${t.caption}</figcaption>`],"</figure>")}}};st();import{isInstance as wt,partOf as we}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as ft,DATA_MOST as pn,NO_TEXT as gn,PACKAGE_ID as Ce,SCHEMA as Se,fitsDataScript as hn,isDataScript as Nn,noDataPart as $n,refusedInCopy as bn,refusedInData as On,schemaAhead as Ee}from"../browser/shared/components/installed.mjs";import{attr as q,walk as Ie}from"../browser/shared/html-tree.mjs";var dt=(t,e)=>{for(let s=t.parentNode;s;s=s.parentNode)if(s===e)return!0;return!1},Ae=t=>{let e=t.parentNode;for(;e&&!wt(e);)e=e.parentNode;return e??null};function Et(t,e){let a=Object.entries(e.get(q(t,ft))?.parts??{}).filter(([,{edit:o}])=>o==="data").map(([o,{at:n}])=>[o,we(t,n).find(r=>r.sourceCodeLocation&&!wt(r)&&Ae(r)===t)]).filter(([,o])=>o);return a.filter(([,o],n)=>!a.some(([,r],l)=>dt(o,r)||r===o&&l<n))}var xn=new Set(["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"]),kn="http://www.w3.org/1999/xhtml",Tn=t=>(t.content??t).childNodes;function Be(t,e,s,a){let o=s;for(let n of Tn(t)){let r=n.sourceCodeLocation;if(r?.startOffset!==o)return!1;if(n.tagName){let{startTag:l,endTag:u}=r,d=xn.has(n.tagName)||n.namespaceURI!==kn&&e.startsWith("/>",r.endOffset-2);if(u?!Be(n,e,l.endOffset,u.startOffset):!d)return!1}o=r.endOffset}return o===a}function Ln(t,e,s){if(e.tagName==="script")return Nn(e.tagName,e.attrs)&&hn(s);if($n(e.tagName))return!1;let{startTag:a,endTag:o}=e.sourceCodeLocation,n=t.slice(a.startOffset,a.endOffset),r=`${n}${s}${t.slice(o.startOffset,o.endOffset)}`,[l,...u]=U(e.parentNode,r,{sourceCodeLocationInfo:!0}).childNodes;if(u.length>0||l?.tagName!==e.tagName||l.sourceCodeLocation?.endOffset!==r.length||!l.sourceCodeLocation.endTag||!Be(l,r,n.length,n.length+s.length))return!1;let d=!1;return Ie(l,m=>{d||=On(m.tagName,m.attrs)}),!d}var _e={installed:{textParts(t,e){let s=e.get(q(t,ft));if(Ee(q(t,Se),s?.schema))return[];let a=Object.values(s?.parts??{}).filter(({edit:r})=>r==="text"),o=Et(t,e).map(([,r])=>r),n=[...new Set(a.flatMap(({at:r})=>we(t,r)))].filter(r=>r.sourceCodeLocation&&!wt(r)&&!gn.has(r.tagName)&&Ae(r)===t).filter(r=>!o.some(l=>l===r||dt(r,l)||dt(l,r)));return n.filter(r=>!n.some(l=>dt(r,l))).map(r=>({kind:"installed",part:r}))},source({package:t,html:e},{packages:s,written:a}){if(typeof t!="string"||!Ce.test(t))return null;if(e===void 0){let r=s.has(t)?Pt(s.get(t)):null;return r&&a(r)}let o=typeof e=="string"?Wt(e,t):null;if(!o)return null;let n=!1;return Ie({childNodes:[o.root]},r=>{n||=bn(r.tagName,r.attrs)}),n?null:a(o.markup)},unwritten:({package:t,html:e},{packages:s})=>e===void 0&&Ce.test(t)&&!s.has(t)?"no-package":"invalid",definition:(t,e)=>e.get(q(t,ft))?.definition,dataOf(t,e,s){let a=Et(e,s).filter(([,o])=>o.sourceCodeLocation.endTag);return a.length>0?Object.fromEntries(a.map(([o,n])=>[o,t.slice(n.sourceCodeLocation.startTag.endOffset,n.sourceCodeLocation.endTag.startOffset)])):null},rewrite(t,e,s,{packages:a}){let o=new Map(Et(e,a)),n=Object.keys(s),r=n.map(u=>s[u]);if(Ee(q(e,Se),a.get(q(e,ft))?.schema)||n.length===0||!r.every(u=>typeof u=="string")||!n.every(u=>o.has(u))||r.reduce((u,d)=>u+Buffer.byteLength(d),0)>pn||!n.every(u=>o.get(u).sourceCodeLocation.endTag&&Ln(t,o.get(u),s[u])))return null;let l=t.includes(`\r
|
|
19
|
-
`)?`\r
|
|
20
|
-
`:`
|
|
21
|
-
`;return n.map(u=>{let{startTag:d,endTag:m}=o.get(u).sourceCodeLocation;return{start:d.endOffset,end:m.startOffset,text:s[u].replace(/\r?\n/g,l)}})}}};import{CONTINUE as yn,START as vn,validStart as Cn}from"../browser/editor/components/list/index.mjs";var Me={item:{children:(t,e)=>t.children.length>0&&t.children.every(s=>e(s,"nest")),write:(t,e)=>e.block(`<li${t.classes?.length?` class="${t.classes.join(" ")}"`:""}${Zt(t.attributes)}${e.id}>${t.html}`,e.children(e.inner),"</li>")},numbers:{check:t=>(t.start===void 0||Cn(t.start))&&(t.continue===void 0||t.continue===!0),write:(t,e)=>e.block(`<ol${t.start?` ${vn}="${t.start}"`:""}${t.continue?` ${yn}`:""}${e.id}>`,e.children(e.inner),"</ol>")}};import{COLUMN_WIDTH as jn,NUMBERS as Rn,tableTiling as Dn,validTable as Wn}from"../browser/editor/components/table/index.mjs";import{CHART_SOURCE as Pn}from"../browser/shared/table-chart.mjs";import{widthHolder as Un}from"../browser/shared/table-slots.mjs";import{CELL_LOOKS as wn,COLUMN_WIDTH as De,validLook as In,validWidth as An}from"../browser/editor/components/table/index.mjs";import{tileSpans as We}from"../browser/shared/table-slots.mjs";import{attr as At}from"../browser/shared/html-tree.mjs";function Sn(t,e){let s=t.slice(e.startOffset,e.endOffset),a=/^[^=\s]+\s*=\s*(["'])([\s\S]*)\1$/.exec(s);return a?{value:a[2],quote:a[1]}:{value:s.replace(/^[^=\s]+\s*=?\s*/,""),quote:'"'}}function En(t,e,s){let a=ct(t,e.endOffset-1);for(;a-1>e.startOffset&&/\s/.test(t[a-1]);)a--;let o=[];for(let[n,r]of s){let l=e.attrs?.[n],u=l?Sn(t,l):null,d=typeof r=="function"?r(u):r,m=u&&typeof r=="function"?u.quote:'"',g=d===null?"":d===""&&typeof r!="function"?n:`${n}=${m}${d}${m}`;l&&d===null?o.push({...it(t,l.startOffset,l.endOffset),text:g}):l?o.push({start:l.startOffset,end:l.endOffset,text:g}):d!==null&&o.push({start:a,end:a,text:` ${g}`})}return o}function je(t,e,s,a){let o=e.sourceCodeLocation.startTag,n=t.slice(o.startOffset,o.endOffset),r=En(t,o,s).map((l,u)=>({...l,index:u}));for(let{start:l,end:u,text:d}of r.sort((m,g)=>g.start-m.start||g.index-m.index))n=n.slice(0,l-o.startOffset)+d+n.slice(u-o.startOffset);return a?n.replace(/^<\w+/,`<${a}`):n}function Bt(t){let e=t?.tagName==="table"?t:t?.childNodes?.find(g=>g.tagName==="table"),s=g=>!!(g?.sourceCodeLocation?.startTag&&g.sourceCodeLocation.endTag),a=g=>g.childNodes.filter(T=>T.tagName),o=g=>g.childNodes.every(T=>T.tagName||F(T));if(!s(e)||!o(e))return null;let n=a(e);if(n.some(g=>!["thead","tbody","colgroup","caption"].includes(g.tagName)))return null;let r=n.filter(g=>g.tagName==="thead"),l=n.filter(g=>g.tagName==="tbody");if(r.length>1||l.length!==1||r.length===1&&n.indexOf(r[0])>n.indexOf(l[0]))return null;let u=g=>g.tagName==="tr"&&s(g)&&o(g)&&a(g).every(T=>(T.tagName==="td"||T.tagName==="th")&&s(T)&&X(T,"rowspan")!==null&&X(T,"colspan")!==null),d=[...r,...l];if(!d.every(g=>s(g)&&o(g)&&a(g).every(u)))return null;let m=d.flatMap(g=>a(g).map(T=>({node:T,head:g.tagName==="thead",cells:a(T)})));return We(m.map(g=>({head:g.head,cells:g.cells.map(T=>[X(T,"rowspan"),X(T,"colspan")])})))?{table:e,head:r[0]??null,body:l[0],rows:m}:null}var Pe=1e3;function X(t,e){let s=At(t,e);return s===void 0?1:/^\s*\d{1,4}\s*$/.test(s)&&Number(s)>=1&&Number(s)<=Pe?Number(s):null}var Re=t=>t===void 0||Number.isInteger(t)&&t>=1&&t<=Pe,It=(t,e)=>t.slice(e.sourceCodeLocation.startTag.startOffset,e.sourceCodeLocation.startTag.endOffset),Bn=(t,e)=>t.slice(e.sourceCodeLocation.startTag.endOffset,e.sourceCodeLocation.endTag.startOffset),Ue=(t,e)=>[...(t??"").split(/\s+/).filter(s=>s&&!wn.includes(s)),...e.split(" ").filter(Boolean)].join(" "),_n=(t,e)=>`${e>1?` colspan="${e}"`:""}${t>1?` rowspan="${t}"`:""}`,Mn=(t,e,s,a,o,n,r)=>je(t,e,[...o!==void 0?[["class",l=>Ue(l?.value,o)||null]]:[],...n!==void 0?[["style",l=>Ct(l?.value??"",[[De,n]])||null]]:[],["scope",a],...r!==void 0?[["colspan",r[1]>1?String(r[1]):null],["rowspan",r[0]>1?String(r[0]):null]]:[]],s);function Fe(t,e,s,{validCell:a}){let o=Bt(e);if(!o||!Array.isArray(s?.rows)||s.rows.length===0||s.rows.length>2e3)return null;let{table:n,rows:r}=o,l=new Set;if(!s.rows.every((c,N)=>c&&typeof c.head=="boolean"&&(N===0||!c.head||s.rows[N-1].head)&&(c.from===null||Number.isInteger(c.from)&&r[c.from])&&Array.isArray(c.cells)&&c.cells.length<=5e3&&c.cells.every(L=>{if(!L||!["td","th"].includes(L.tag)||![void 0,null,"row","col"].includes(L.scope)||L.look!==void 0&&!In(L.look)||L.width!==void 0&&!An(L.width)||!Re(L.rowspan)||!Re(L.colspan)||L.rowspan===void 0!=(L.colspan===void 0)||L.scope&&L.tag!=="th")return!1;if(L.from!==null){let[O,S]=Array.isArray(L.from)?L.from:[];if(!r[O]?.cells[S]||l.has(`${O}:${S}`))return!1;l.add(`${O}:${S}`)}else if(typeof L.html!="string")return!1;return L.html===void 0||typeof L.html=="string"&&L.html.length<=1e5&&(L.html===""||a(L.tag,L.html))}))||!s.rows.some(c=>!c.head))return null;let d=c=>c.rowspan!==void 0?[c.rowspan,c.colspan]:c.from===null?[1,1]:[X(r[c.from[0]].cells[c.from[1]],"rowspan"),X(r[c.from[0]].cells[c.from[1]],"colspan")],m=We(s.rows.map(c=>({head:c.head,cells:c.cells.map(d)})));if(!m||s.rows.length*m.columns>5e3)return null;let g=r[0]?.node,T=g?H(t,g.sourceCodeLocation.startOffset):null,E=H(t,o.body.sourceCodeLocation.startOffset),y=H(t,n.sourceCodeLocation.startOffset),k=t.includes(`\r
|
|
22
|
-
`)?`\r
|
|
23
|
-
`:`
|
|
24
|
-
`,C=c=>{if(c.from===null){let pt=c.look?` class="${Ue("",c.look)}"`:"",v=c.width?` style="${Ct("",[[De,c.width]])}"`:"";return`<${c.tag}${pt}${v}${c.scope?` scope="${c.scope}"`:""}${_n(c.rowspan??1,c.colspan??1)}>${c.html}</${c.tag}>`}let[N,L]=c.from,O=r[N].cells[L],S=c.tag==="th"?c.scope??null:null;return`${O.tagName===c.tag&&(At(O,"scope")??null)===S&&c.look===void 0&&c.width===void 0&&c.rowspan===void 0?It(t,O):Mn(t,O,c.tag,S,c.look,c.width,c.rowspan===void 0?void 0:[c.rowspan,c.colspan])}${c.html??Bn(t,O)}</${c.tag}>`},h=c=>{let N=c.from===null?null:r[c.from];return N&&N.cells.length===c.cells.length&&c.cells.every((O,S)=>O.from?.[0]===c.from&&O.from[1]===S&&O.html===void 0&&O.look===void 0&&O.width===void 0&&O.rowspan===void 0&&O.tag===N.cells[S].tagName&&(O.tag!=="th"||(O.scope??null)===(At(N.cells[S],"scope")??null)))?t.slice(N.node.sourceCodeLocation.startOffset,N.node.sourceCodeLocation.endOffset):`${N?It(t,N.node):"<tr>"}${c.cells.map(C).join("")}</tr>`},b=(c,N,L)=>{let O=L?It(t,L):`<${c}>`;return T===null||E===null?`${O}${N.map(h).join("")}</${c}>`:`${O}${N.map(S=>`${k}${T}${h(S)}`).join("")}${k}${E}</${c}>`},p=s.rows.filter(c=>c.head),i=s.rows.filter(c=>!c.head),$=[...n.childNodes.filter(c=>c.tagName==="caption"||c.tagName==="colgroup").map(c=>t.slice(c.sourceCodeLocation.startOffset,c.sourceCodeLocation.endOffset)),...p.length?[b("thead",p,o.head)]:[],b("tbody",i,o.body)],x=E===null||y===null?$.join(""):`${$.map(c=>`${k}${E}${c}`).join("")}${k}${y}`;return{start:n.sourceCodeLocation.startTag.endOffset,end:n.sourceCodeLocation.endTag.startOffset,text:x}}var ze={table:{rewrite:Fe,plain:t=>Bt(t)!==null,check:(t,{validLeaf:e})=>Wn(t,s=>typeof s=="string"&&e({tag:"td"},s,{empty:!0})),write(t,e){let s=Dn(t),a=(y,k)=>t.spans?.[y]?.[k]??[1,1],o=new Map((t.widths??[]).map((y,k)=>[Un(s,k),y]).filter(([y,k])=>y&&k)),n=(y,k)=>{let[C,h]=a(y,k),b=o.get(`${y}:${k}`);return`${t.looks?.[y]?.[k]?` class="${t.looks[y][k]}"`:""}${b?` style="${jn}: ${b}"`:""}${h>1?` colspan="${h}"`:""}${C>1?` rowspan="${C}"`:""}`},r=(y,k,C)=>`<tr>${y.map((h,b)=>k?`<th${n(C,b)}>${h}</th>`:t.column&&s.places.get(`${C}:${b}`).c===0?`<th${n(C,b)} scope="row">${h}</th>`:`<td${n(C,b)}>${h}</td>`).join("")}</tr>`,l=e.inner===null?null:e.inner+e.step,u=l===null?null:l+e.step,[d,...m]=t.rows,g=[];t.header&&g.push(e.block("<thead>",[r(d,!0,0)],"</thead>",l,u));let T=t.header?m:t.rows,E=t.header?1:0;return T.length>0&&g.push(e.block("<tbody>",T.map((y,k)=>r(y,!1,k+E)),"</tbody>",l,u)),e.block(`<div class="doc-table-wrap"${t.numbers===!1?` ${Rn}="off"`:""}${t.chart?` ${Pn}="${t.chart}"`:""}${e.id}>`,[e.block('<table class="doc-table">',g,"</table>",e.inner,l)],"</div>")}}};var Q={...ae,...ce,...fe,...de,...ue,...ge,...$e,...ke,...ve,..._e,...Me,...te,...ze},Fn=Object.entries(Q).flatMap(([t,e])=>(e.fields??[]).map(s=>[s,t])),hr=t=>Fn.some(([e,s])=>t[e]!==void 0&&t.type!==s);st();import{HOSTS as et,IDENTITY as zn}from"../browser/editor/components/registry.mjs";import{CODE as Hn,MATH as Xe,MEDIA as Kn,PAGE as Gn,TABLE as qn}from"../browser/editor/components/kit.mjs";import{TAB as Xn}from"../browser/editor/components/paragraph/index.mjs";import{componentOf as Vn,isInstance as ut,matchesNode as D,partOf as Yn}from"../browser/shared/components/index.mjs";import{texSource as Zn}from"../browser/editor/components/math/index.mjs";import{MENTION as Mt,MENTION_ICON as He,MENTION_PAGE as Ke}from"../browser/shared/components/mention.mjs";import{imageFile as Jn}from"../browser/shared/media.mjs";import{isFileLink as Qn}from"../browser/shared/page-address.mjs";import{isInkClass as ta}from"../browser/editor/page/marks.mjs";import{ownInline as ea}from"../browser/editor/page/own.mjs";import{attr as B,hasClass as sa}from"../browser/shared/html-tree.mjs";var na=new Set(["h1","h2","h3","h4","p","li"]),aa=new Set(["h3","h4","p","figcaption"]),oa=Object.entries(et).flatMap(([t,e])=>(e.parts??[]).map(([s,a])=>{let o=Vn(s);if(o?.parts?.[a]?.edit!=="text")throw new Error(`Host ${t}: ${s} has no part ${a} edited as text`);return{kind:t,match:o.match,at:o.parts[a].at}})),ra=t=>oa.filter(({match:e})=>D(t,e)).flatMap(({kind:e,at:s})=>Yn(t,s).map(a=>({kind:e,part:a}))),ia=t=>t.sort((e,s)=>e.part.sourceCodeLocation.startOffset-s.part.sourceCodeLocation.startOffset),ca=Object.entries(et).filter(([,t])=>t.whole).map(([t,e])=>({kind:t,at:e.whole})),Ge=t=>ca.find(({at:e})=>D(t,e))?.kind,la=new Set(["strong","em","b","i","u","s","code","a","br","sup","sub"]),fa=new Set(["ul","ol","blockquote"]),_t=new Set(["pre","summary","button","label","select","textarea","form","template","script","style","svg","math","iframe","object","noscript","canvas","video","audio"]),_r={p:"p",h1:"p",h2:"p",h3:"p",h4:"p",li:"li"};function da(t,e,s){let a=et[t];if(!a)throw new Error(`Unknown block kind ${t}`);return a.caps({bound:s,blockLevel:K.has(e)})}var jt=t=>t.tagName==="span"&&D(t,Xe.inline),ua=t=>t.tagName==="a"&&sa(t,Mt),ma=/^https?:\/\/[^\s"<>]+$/i,tt=t=>t.attrs.map(e=>e.name).sort().join(),pa=t=>B(t,"class")===Mt&&t.childNodes.length===0&&(tt(t)==="class"||tt(t)===`class,${Ke}`&&B(t,Ke)==="");function ga(t){if(pa(t))return null;if(tt(t)!=="class,href"||B(t,"class")!==Mt||!(ma.test(B(t,"href"))||Qn(B(t,"href"))))return"mention";let[e,...s]=t.childNodes;return(e?.tagName==="img"?tt(e)==="alt,class,src"&&B(e,"class")===He&&B(e,"alt")===""&&Jn(B(e,"src")):e?.tagName==="span"&&tt(e)==="class"&&B(e,"class")===He&&e.childNodes.length===0)&&s.length>0&&s.every(o=>o.nodeName==="#text")&&s.some(o=>o.value.trim())?null:"mention"}var ha=t=>t.tagName==="span"&&t.attrs.length===1&&t.attrs[0].name==="class"&&t.attrs[0].value.trim().split(/\s+/).every(ta),Na=t=>t.tagName==="span"&&t.attrs.length===1&&t.attrs[0].name==="class"&&t.attrs[0].value===Xn,Rt=t=>la.has(t.tagName)||ha(t)||Na(t),$a=t=>Rt(t)||jt(t),mt=t=>(t.childNodes??[]).some(e=>e.nodeName==="#text"?e.value.trim()!=="":mt(e)),Ve=t=>ea(t.tagName,t.attrs,mt(t)),qe=t=>t.attrs.some(e=>e.name==="id"||e.name.startsWith("data-")&&e.name!==zn),ba=t=>/^(javascript|vbscript|data):/i.test(t.replace(/[\u0000- ]/g,"")),Oa=(t,e,s={})=>t==="text"?K.has(e)?!1:"atoms":t==="title"||t==="code"||t==="codeTitle"||t==="tex"||!!s.plain;function Dt(t,e,s=!1,{lists:a=!1,known:o=null}={}){for(let n of t.childNodes){if(n.nodeName==="#text")continue;if(!n.tagName)return"comment";if(s===!0)return`tag:${n.tagName}`;if(n.attrs.some(l=>/^on/i.test(l.name)))return"markup";if(s==="atoms"){if(!n.sourceCodeLocation?.endTag&&n.tagName!=="br")return"markup";if(o&&!o(n.sourceCodeLocation))return`tag:${n.tagName}`;e.push(n.sourceCodeLocation);continue}if(a&&(n.tagName==="ul"||n.tagName==="ol")){let l=xa(n,e,o);if(l)return l;continue}if(jt(n)){if(n.childNodes.some(l=>l.nodeName!=="#text"))return"markup";e.push(n.sourceCodeLocation);continue}if(ua(n)){let l=ga(n);if(l)return l;e.push(n.sourceCodeLocation);continue}if(Ve(n)){if(!n.sourceCodeLocation?.endTag)return"markup";if(o&&!o(n.sourceCodeLocation))return`tag:${n.tagName}`;e.push(n.sourceCodeLocation);continue}if(!Rt(n))return`tag:${n.tagName}`;if(n.tagName!=="br"&&!n.sourceCodeLocation?.endTag)return"markup";if(n.tagName==="a"&&ba(B(n,"href")??""))return"link";let r=Dt(n,e,!1,{known:o});if(r)return r}return null}function xa(t,e,s){if(t.attrs.length>0||!t.sourceCodeLocation?.endTag)return"markup";for(let a of t.childNodes){if(a.nodeName==="#text"&&!a.value.trim())continue;if(a.tagName!=="li")return`tag:${a.tagName??"text"}`;if(a.attrs.length>0||!a.sourceCodeLocation?.endTag)return"markup";let o=Dt(a,e,!1,{known:s});if(o)return o}return null}function V(t){let e=[],s=[],a=new Map,o=null,n=(p,i,f=null)=>{let $=p.sourceCodeLocation;if(!et[i]||!$?.startTag||B(p,"contenteditable")!==void 0)return!1;let x=[],c=Oa(i,p.tagName),N=f?{childNodes:p.childNodes.slice(0,p.childNodes.indexOf(f))}:p,L=$.endTag?Dt(N,x,c,{lists:i==="cell"}):"markup";if(L)return s.push({at:$.startTag.endOffset-1,reason:L}),!1;let O=$.startTag.endOffset,S=f?O+t.slice(O,f.sourceCodeLocation.startOffset).replace(/[ \t\r\n\f]+$/,"").length:$.endTag.startOffset,A={id:e.length,tag:p.tagName,kind:i,bound:!1,caps:{},start:$.startOffset,end:$.endOffset,innerStart:O,innerEnd:S,atoms:x.map(M=>[M.startOffset-O,M.endOffset-O]),wrapper:null,nested:!!f,node:p};return e.push(A),a.set(p,A),!0},r=p=>(p.childNodes??[]).filter(i=>i.tagName),l=p=>{let i=p.sourceCodeLocation;return i?.startTag&&i.endTag?t.slice(i.startTag.endOffset,i.endTag.startOffset):null},u=p=>p.tagName!=="a"&&!qe(p)&&mt(p)&&r(p).every(i=>Ve(i)?!mt(i):Rt(i)||jt(i)),d=p=>{for(let i of r(p))i.tagName==="td"||i.tagName==="th"?n(i,"cell"):["thead","tbody","tfoot","tr"].includes(i.tagName)&&d(i)},m=p=>{for(let i of r(p))i.tagName==="table"?d(i):!_t.has(i.tagName)&&!ut(i)&&m(i)},g=p=>{let i=r(p);i.length===1&&i[0].tagName==="code"&&p.childNodes.every(f=>f.tagName||!f.value?.trim())?n(i[0],"code"):i.length===0?n(p,"code"):p.sourceCodeLocation?.startTag&&s.push({at:p.sourceCodeLocation.startTag.endOffset-1,reason:"markup"})},T=(p,i=!0)=>{for(let f of r(p)){let $=f.tagName,x=ut(f);for(let{kind:c,part:N}of ia(x?Q[z(f)].textParts(f,o??=ht().packages):ra(f)))n(N,c);if(!x){if($==="div"&&D(f,Hn.match)){for(let c of r(f))c.tagName==="pre"&&B(c,"contenteditable")===void 0&&g(c);continue}if(!(_t.has($)||B(f,"contenteditable")!==void 0))if(Ge(f)&&r(f).every($a))n(f,Ge(f));else if($==="table")d(f);else if($==="figure"){let c=D(f,Kn);for(let N of r(f))if(!(c&&N.tagName==="figcaption"))if(aa.has(N.tagName))n(N,"field");else if(N.tagName==="table")d(N);else{if(_t.has(N.tagName))continue;ut(N)?T({childNodes:[N]},i):c||J(N)||qe(N)?m(N):T({childNodes:[N]},i)}}else if($==="details")for(let c of r(f))ut(c)?T({childNodes:[c]},i):c.tagName!=="summary"&&T(c,i);else if($==="h1"&&(p.tagName==="header"||D(f,Gn.title)))n(f,"title");else if($==="li"&&Lt(f))T({childNodes:r(f)},i);else if(na.has($)){let c=$==="li"?Tt(f):[];c?.length>0?(n(f,"flow",c[0]),T({childNodes:c},i)):n(f,"flow")||T(f,!1)}else if($==="div"&&D(f,Xe.block)&&r(f).length===0&&Zn(l(f)))n(f,"tex");else if($==="div"&&D(f,qn.lead))for(let c of r(f))c.tagName==="span"&&n(c,"field");else i&&!J(f)&&u(f)?n(f,"text"):(T(f,i&&!J(f)),fa.has($)&&E(f))}}},E=p=>{let i=p.sourceCodeLocation,f=r(p).map(c=>a.get(c));if(!(f.length>0&&f.every(Boolean)&&p.childNodes.every(c=>c.tagName||c.nodeName==="#text"&&!c.value.trim()))||!i?.endTag)return;let x={start:i.startOffset,end:i.endOffset,ids:f.map(c=>c.id)};f.forEach(c=>c.wrapper=x)},y=p=>{for(let i of r(p))(i.tagName==="main"?T:y)(i)},k=P(t,{sourceCodeLocationInfo:!0});y(k);let{units:C,boxes:h,referenced:b}=qt(k,t);for(let p of C)p.grid=!!Q[p.kind]?.plain?.(p.node);for(let p of C){let i=Q[p.kind]?.dataOf?.(t,p.node,o??=ht().packages);i&&(p.parts=Object.fromEntries(Object.entries(i).map(([f,$])=>[f,nt($)])))}for(let p of e){let i=null;for(let f of C)f.start<=p.start&&p.start<f.end&&(!i||f.start>i.start)&&(i=f);p.unit=i?.id??null,p.self=i&&i.at===p.innerStart-1?i.id:null,p.self!==null&&(i.text=p.id),p.path=i&&p.self===null?ka(i,p.node):null,et.text&&p.kind==="flow"&&p.self===null&&(i?.kind==="block"||i?.kind==="figure")&&(p.kind="text"),p.bound=b(p.node)!==null,p.caps=Object.fromEntries(da(p.kind,p.tag,p.bound).map(f=>[f,!0]))}return{blocks:e,locks:s,units:C,boxes:h}}function ka(t,e){let s=[],a=e;for(;a&&!t.nodes.includes(a);a=a.parentNode){let o=(a.parentNode?.childNodes??[]).filter(n=>n.tagName===a.tagName);s.unshift([a.tagName,o.indexOf(a),o.length])}return a?[a===t.node?"unit":a===t.nodes[0]&&t.lead!==null?"lead":"panel",...s]:null}var Mr=t=>V(t).blocks;function jr(t){let{units:e,boxes:s}=V(t);return{units:e,boxes:s}}st();import{randomBlockId as Ta}from"../browser/shared/ids.mjs";import{IDENTITY as Y}from"../browser/editor/components/registry.mjs";var La=/\sdata-block-id\s*=\s*(?:"([^"]*)"|'([^']*)')/gi;function zr(t,e=Ta){let{units:s}=V(t),a=new Set([...t.matchAll(La)].map(m=>m[1]??m[2])),o=()=>{for(;;){let m=e();if(!a.has(m))return a.add(m)&&m}},n=new Set,r=[],l=[],u=[];for(let m of s)if(m.blockId)n.has(m.blockId)&&m.blockIdAttr?(l.push(m.blockId),r.push({start:m.blockIdAttr.start,end:m.blockIdAttr.end,text:`${Y}="${o()}"`})):n.add(m.blockId);else{let g=o();if(m.blockIdAttr)r.push({start:m.blockIdAttr.start,end:m.blockIdAttr.end,text:`${Y}="${g}"`});else{let T=ct(t,m.at);r.push({start:T,end:T,text:` ${Y}="${g}"`})}u.push({id:g,tag:Ze(m.tag,m.attrs),at:m.elStart})}let d=t;for(let m of r.sort((g,T)=>T.start-g.start))d=d.slice(0,m.start)+m.text+d.slice(m.end);return u.sort((m,g)=>m.at-g.at),{text:d,added:u.length,renamed:l,given:u.map(({id:m,tag:g})=>({id:m,tag:g}))}}function Hr(t){let e=Ye(t);return V(t).units.filter(s=>!s.blockId).sort((s,a)=>s.elStart-a.elStart).map(s=>({line:e(s.elStart),tag:Ze(s.tag,s.attrs)}))}function Kr(t,e){let s=new Map(e.map(o=>[o.id,o])),a=Ye(t);return V(t).units.filter(o=>s.has(o.blockId)).sort((o,n)=>o.elStart-n.elStart).map(o=>({...s.get(o.blockId),line:a(o.elStart)}))}function Ye(t){let e=[0];for(let s=t.indexOf(`
|
|
25
|
-
`);s!==-1;s=t.indexOf(`
|
|
26
|
-
`,s+1))e.push(s+1);return s=>{let[a,o]=[0,e.length-1];for(;a<o;){let n=a+o+1>>1;e[n]<=s?a=n:o=n-1}return a+1}}function Ze(t,e=[]){let s=e.filter(({name:n})=>n!==Y&&n!=="style"),a=n=>{let r=n.replace(/\s+/g," "),l=r.length>32?`${r.slice(0,31)}\u2026`:r;return l===""?"":/[\s"'=<>`]/.test(l)?`="${l.replaceAll('"',""")}"`:`=${l}`},o=s.slice(0,3).map(({name:n,value:r})=>`${n}${a(r)}`);return`<${[t,...o,...s.length>3?["\u2026"]:[]].join(" ")}>`}function Gr(t){let e=new Map,s=a=>{let o=a.attrs?.find(r=>r.name===Y)?.value,n=a.sourceCodeLocation?.attrs?.[Y]??a.sourceCodeLocation;o!==void 0&&e.set(o,[...e.get(o)??[],n]);for(let r of a.content?.childNodes??a.childNodes??[])s(r)};return s(P(t,{sourceCodeLocationInfo:!0})),[...e].filter(([,a])=>a.length>1).map(([a,o])=>({id:a,lines:o.map(n=>n?.startLine),columns:o.map(n=>n?.startCol)}))}export{nt as a,Nt as b,K as c,J as d,us as e,Ma as f,xs as g,ja as h,Zt as i,ct as j,it as k,qa as l,Xa as m,Ct as n,Va as o,ws as p,Ya as q,Za as r,vt as s,H as t,Is as u,Ja as v,_s as w,En as x,Q as y,hr as z,Ge as A,_r as B,$a as C,Oa as D,Dt as E,V as F,Mr as G,jr as H,Ta as I,La as J,zr as K,Hr as L,Kr as M,Gr as N};
|
package/dist/chunk-O52JMOCZ.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{a,b}from"./chunk-V4CPWKMZ.mjs";import"./chunk-XINNG4F2.mjs";import"./chunk-7GHT2UCA.mjs";import"./chunk-G7TOXONE.mjs";import"./chunk-P2CAZPDP.mjs";import"./chunk-ITNLYXXV.mjs";import"./chunk-NSKUTQ5J.mjs";import"./chunk-QMQUXTU4.mjs";import"./chunk-HQQMJCQJ.mjs";import"./chunk-QYKCJ7FG.mjs";import"./chunk-YZ5Z6H4W.mjs";import"./chunk-VACRB2NE.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-TDQP3DKQ.mjs";import"./chunk-5FRMCDPY.mjs";import"./chunk-E7VYDG2X.mjs";import"./chunk-NFIBI4IP.mjs";import"./chunk-W63L7367.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";export{a as noDocuments,b as run};
|
package/dist/chunk-QMQUXTU4.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{a as ae,b as Z,c as V,f as re,g as A,h as ce,i as le,l as de,m as he}from"./chunk-HQQMJCQJ.mjs";import{b as Xt,c as lt,e as U,f as Yt,i as Qt,j as te,m as ee,n as oe,o as ne,p as se,q as ie,r as dt}from"./chunk-QYKCJ7FG.mjs";import{a as rt}from"./chunk-YZ5Z6H4W.mjs";import{b as ct,c as jt,d as zt,e as Dt,f as _t,h as Mt,i as Pt,j as Ut,k as Bt,l as Wt,m as Ht,n as Gt,o as Kt,s as Jt}from"./chunk-VACRB2NE.mjs";import{a as g,b as Ft,c as Rt}from"./chunk-HYMEEXKN.mjs";import{d as T,g as Zt,i as Vt,j as qt}from"./chunk-W63L7367.mjs";import{existsSync as Qe,readFileSync as Is,readdirSync as Fs}from"node:fs";import N from"node:fs/promises";import S from"node:path";function fe(t){if(!t||!Array.isArray(t.lines))throw new Error("diff: lines must be an array.");t.lines.forEach(o=>{if(!o||!["added","removed","unchanged"].includes(o.type)||typeof o.content!="string"||/[\r\n]/.test(o.content))throw new Error("diff: each line needs a valid type and single-line content.");if(o.lineNumber!=null&&(!Number.isInteger(o.lineNumber)||o.lineNumber<1))throw new Error("diff: lineNumber must be a positive integer.")})}import{isInstance as ue}from"../browser/shared/components/index.mjs";import{attr as I,elementsOf as B,hasClass as yo,walk as pe}from"../browser/shared/html-tree.mjs";import{CHART_DATA as No,CHART_SOURCE as q,cellWords as me,rowsReading as ge,tableRows as So}from"../browser/shared/table-chart.mjs";var xo=t=>t.tagName==="script"&&(I(t,"type")??"").trim().toLowerCase()==="application/json",ht=t=>t.nodeName==="#text"?t.value:(t.childNodes??[]).map(ht).join("");function vo(t){let o=t;for(;o&&o.tagName!=="figure";)o=o.parentNode;let n=o?B(o).find(e=>/^h[2-4]$/.test(e.tagName)):null;return n?me(ht(n)):""}function $e(t,o,n=g(t)){let e=[];return pe(n,s=>{let i=o(s);if(i===void 0||!s.sourceCodeLocation)return;let a=s.childNodes.find(xo);e.push({type:i,line:s.sourceCodeLocation.startLine,text:a?a.childNodes.map(r=>r.value??"").join(""):null,source:I(s,No),tag:s.tagName,holder:s.parentNode?.tagName,title:vo(s)})},{stop:ue}),e}var Oo=t=>t.tagName==="ol"&&I(t,"data-doc-chart")==="flow",X=(t,o)=>$e(t,n=>Oo(n)?void 0:I(n,"data-doc-chart"),o),Eo=t=>$e(t,o=>yo(o,"doc-diff")?"diff":void 0),C=t=>B(t).filter(o=>o.tagName==="td"||o.tagName==="th"),To=t=>["rowspan","colspan"].some(o=>{let n=Number.parseInt(I(t,o)??"1",10);return Number.isFinite(n)&&n!==1});function Lo(t){let o=B(t),n=r=>B(r).filter(l=>l.tagName==="tr"),e=o.find(r=>r.tagName==="thead"),s=e?n(e)[0]??null:null,i=o.filter(r=>r.tagName==="tbody").flatMap(n);!s&&i.length>0&&C(i[0]).length>0&&C(i[0]).every(r=>r.tagName==="th")&&([s,...i]=i);let a=r=>me(ht(r));return{names:s?C(s).map(a):null,types:s?C(s).map(r=>I(r,"data-sort-type")??null):null,rows:i.map(r=>C(r).map(l=>({words:a(l),sort:I(l,"data-sort-value")?.trim()??null}))),foot:o.filter(r=>r.tagName==="tfoot").flatMap(n).map(r=>C(r)[0]?a(C(r)[0]):""),merged:[s,...i].some(r=>r&&C(r).some(To))}}function ft(t){let o=new Map;return pe(t,n=>{let e=I(n,q);if(e===void 0||!n.sourceCodeLocation)return;(o.get(e)??o.set(e,[]).get(e)).push({line:n.sourceCodeLocation.startLine,table:B(n).find(i=>i.tagName==="table")??null})},{inTemplates:!1,stop:ue}),o}function ut(t,o){let n=o.get(t)??[];if(n.length===0)return{error:`no table's frame carries ${q}="${t}", so the chart has nothing to draw: put the table back, or delete the card`};if(n.length>1)return{error:`${n.length} tables carry ${q}="${t}" (lines ${n.map(({line:r})=>r).join(", ")}): a key names one table (the chart draws the first); take it off the copies`};let[{line:e,table:s}]=n;if(!s)return{error:`the frame carrying ${q}="${t}" (line ${e}) holds no table`};let i=Lo(s),a=So(i);return a.error?{error:`its table (line ${e}) ${a.error}`}:{...a,line:e,cells:i}}function pt(t){let o=new Set([...t.matchAll(/DocCharts\.define\(\s*(["'`])([a-z][a-z0-9-]*)\1/g)].map(e=>e[2])),n=new Set([...t.matchAll(/DocCharts\.define\(\s*(["'`])([^"'`\n]*)\1/g)].map(e=>e[2]).filter(e=>!o.has(e)));return{defined:o,misnamed:n}}function mt(t){let o=g(t),n=[],{defined:e,misnamed:s}=pt(t),i=null;for(let{type:a,line:r,text:l,source:c,tag:d,holder:h}of X(t,o)){let f=`data-doc-chart="${a}" (line ${r})`;if(d==="table"){n.push(h==="figure"?`${f} is on a table inside a <figure>: the chart's card is a figure of its own, so write the table outside it, its <caption> the chart's title`:`${f} is on a table the tools leave as written (inside a whole block, an element with a class of the document's own, a cell): a chart is drawn from a table outside one`);continue}if(s.has(a)){n.push(`${f}: the document's script defines "${a}" with DocCharts.define, which refuses that name: a chart type's name is lowercase letters, digits and hyphens, a letter first ("interval", "ci-plot"); rename it in both places`);continue}if(!e.has(a)){n.push(`${f}: the document's script does not define "${a}": define it once in the document's <script> with DocCharts.define("${a}", ({ host, data, tokens, width, height }) => { \u2026 }) (references/writing-html.md, "Figures and charts")`);continue}if(c!==void 0){if(l!==null){n.push(`${f}: a chart drawn from a table takes its data from the table: take its <script type="application/json"> out`);continue}let u=ut(c,i??=ft(o));u.error&&n.push(`${f}: ${u.error}`);continue}if(l===null){n.push(`${f} needs its data in a <script type="application/json"> child`);continue}try{JSON.parse(l)}catch(u){n.push(`${f}: its data is not valid JSON (${u.message})`)}}for(let{line:a,text:r}of Eo(t)){if(r===null)continue;let l=`.doc-diff (line ${a})`;try{fe(JSON.parse(r))}catch(c){n.push(`${l}: ${c instanceof SyntaxError?`its options are not valid JSON (${c.message})`:c.message}`)}}return n}function we(t,{written:o=t}={}){let n=g(t),e=[],{defined:s}=pt(t),i=null,a=null;for(let{type:r,line:l,text:c,source:d,title:h,tag:f}of X(t,n)){if(d===void 0||f==="table"||c!==null||!s.has(r))continue;let u=`data-doc-chart="${r}" (line ${l})`;if(!h){a??=new Set(o===t?[]:X(o).map(b=>b.source).filter(b=>b!==void 0));let y=o!==t&&!a.has(d);e.push(`${u}: this chart card has no title: ${y?"write a <caption> on its table (the one with data-doc-chart), which becomes the card's h3":"write an h3 in the card's figure, before the chart"}`)}let p=ut(d,i??=ft(n));if(p.error)continue;let{blank:m,twice:w}=ge(p.cells,p.data);m&&e.push(`${u}: its table's header (line ${p.line}) has a cell with no words, so that column's values are keyed "" in data: write the column's name there`),w.length>0&&e.push(`${u}: its table's header (line ${p.line}) names ${w.map(y=>`"${y}"`).join(", ")} twice, so data keeps the later column's value under it: give each column a name of its own`)}return e}function be(t){let o=g(t),n=[],e=[],{defined:s}=pt(t),i=null,a=(r,l)=>`${r} ${l}${r===1?"":"s"}`;for(let{type:r,line:l,text:c,source:d,tag:h}of X(t,o)){if(d===void 0||h==="table"||c!==null||!s.has(r))continue;let f=ut(d,i??=ft(o));if(f.error)continue;let{rows:u,columns:p,foot:m,extra:w}=ge(f.cells,f.data),y=`data-doc-chart="${r}" (line ${l})`,b=[a(u,"row")];for(let{name:k,numbers:v,words:E,empty:P}of p){let R=v+E+P,J=v===R&&R>0?"numbers":E===R&&R>0?"words":[v&&a(v,"number"),E&&`${E} as words`,P&&`${P} empty (null)`].filter(Boolean).join(", ")||"no rows";b.push(`"${k}": ${J}`),v>0&&E>0&&e.push(`${y}: its table's column "${k}" (line ${f.line}) reads as numbers in ${a(v,"row")} and as words in ${E}: write each of its cells as one number (an empty cell, "\u2014" or "n/a" for none: null in data), or, for a column of words, data-sort-type="text" on its header cell`)}m>0&&e.push(`${y}: its table's <tfoot> (line ${f.line}) holds ${a(m,"row")} the chart leaves out, and a table with a <tfoot> has no table tools in the preview: keep a total out of a table you chart and say it in the text`),w>0&&e.push(`${y}: ${a(w,"row")} of its table (line ${f.line}) ${w===1?"has":"have"} cells past the header, which the chart does not read: give each column a header cell`),n.push(`${r} (line ${l}) reads its table (line ${f.line}): ${b.join("; ")}`)}return{readings:n,notes:e}}import{componentOf as Rs,isInstance as js,matchesNode as to}from"../browser/shared/components/index.mjs";import{FLOW as zs}from"../browser/shared/components/list.mjs";import{attr as O,elementsOf as eo,walk as j}from"../browser/shared/html-tree.mjs";import{GLYPH_SETS as Ds,ICON_COLORS as oo,glyphOf as _s,glyphValue as Ms,iconKind as Et,iconMarkup as Ps,iconValueOf as Us}from"../browser/shared/emoji/icon-value.mjs";import Ao from"node:vm";import{LINE_START as tt,lineStart as Co}from"../browser/shared/code-lines.mjs";import{COMPONENTS as Io,FLOWS as Fo,instancesOf as Ro,isInstance as W,matchesNode as D,partOf as ke,vocabulary as jo}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as L,INSTANCE as zo,PACKAGE_ID as Oe,SCHEMA as gt,schemaAhead as Do}from"../browser/shared/components/installed.mjs";import{packageScript as _o}from"../browser/shared/export-wrap.mjs";import{asDocName as Mo,kitNamespace as Po}from"../browser/shared/old-names.mjs";import{shortSheets as Uo}from"../browser/shared/components/sheets.mjs";import{attr as x,curlyQuoted as Bo,hasClass as Wo,walk as et}from"../browser/shared/html-tree.mjs";var{authoring:Q,runtime:ye}=jo(),Ho="input, select, textarea, button, details, table",ot=t=>t.sourceCodeLocation?.startLine,$=t=>ot(t)?` (line ${ot(t)})`:"";function Ne(t){let o=(e,s)=>{let i=Array.from({length:s.length+1},(a,r)=>r);for(let a=1;a<=e.length;a++){let r=i[0];i[0]=a;for(let l=1;l<=s.length;l++){let c=i[l];i[l]=Math.min(i[l]+1,i[l-1]+1,r+(e[a-1]===s[l-1]?0:1)),r=c}}return i[s.length]},[n]=[...Q.keys()].filter(e=>e.startsWith(t.slice(0,7))).map(e=>[e,o(t,e)]).sort((e,s)=>e[1]-s[1]);return n&&n[1]<=3?` (${n[0]}?)`:""}function Go(t,o,n){let{part:e,property:s,min:i}=t.shares,a=new RegExp(`(?:^|;)\\s*${s}\\s*:\\s*([^;]*)`),r=n.map(h=>a.exec(x(h,"style")??"")?.[1].trim()??null),l=r.filter(h=>h!==null);if(l.length===0)return[];let c=`${t.id}${$(o)}`;return l.length<r.length?[`${c}: ${s} on ${l.length} of its ${r.length} ${e}: write it on every one of them, or on none (equal widths)`]:l.map(Number).some(h=>!Number.isFinite(h)||h<i-1e-9||h>1)?[`${c}: ${s} is a share of the row, a number from ${Math.round(i*1e3)/1e3} to 1 (${l.join(", ")})`]:[]}var Y={"doc-dialog-header":'a detail card has no header: its content region (<div class="doc-dialog-content">) stands alone in its panel',"doc-dialog-title":"a detail card's title is an ordinary heading (<h3>), first in its content region","doc-dialog-close":"a detail card has no close button: Esc and a press outside it close it","data-doc-dialog-close":"a detail card has no close button: Esc and a press outside it close it","doc-section-header":"a section's title is a plain heading (<h2>) with an ordinary paragraph below it for the line that says what the section is: no <div> goes around them","doc-grid":'a card row is now columns: <div class="doc-columns"> holding one <div class="doc-column"> per card',"doc-grid-3":'a card row is now columns: <div class="doc-columns"> holding three <div class="doc-column">',"doc-lede":`write the line under the title as a paragraph of the header (an ordinary <p>), or as small text, <p class="doc-note"): the header's lines read as the body's paragraphs`,"doc-source":`write the line under the title as a plain paragraph of the header (an ordinary <p>), or as small text (<p class="doc-note">): the header's lines read as the body's paragraphs`,"doc-prose":"write the text straight in its flow (the page, a Sheet panel, a section, a panel, a column\u2026): it reads the same there","doc-prose-h1":"write an h1","doc-prose-h2":"write an h2","doc-prose-h3":"write an h3","doc-prose-h4":"write an h4","doc-state-grid":'put the groups side by side in columns (<div class="doc-columns">)',"doc-state-group":"write the group's title as a heading and its controls as blocks of their own in a column","doc-state-status":'write the line as small text, <p class="doc-note">',"doc-code-block":'a code block is <div class="doc-code"> holding its title (<div class="doc-code-title">) and the <pre><code>',"doc-code-card":'a code block is <div class="doc-code"> holding its title and its <pre>; a diff is <div class="doc-diff">',"doc-code-header":'write the title as <div class="doc-code-title">: the kit draws the rest of the header',"data-doc-diff":'a diff is <div class="doc-diff"> holding its title and its options as JSON (sdk/doc-code.d.ts)',"data-doc-diff-stats":"the kit shows a diff's counts in its header: remove it","doc-code--wrap":"a code block wraps its long lines by itself: remove it (doc-code--nowrap scrolls them instead)"},Ko={[tt]:'write it on its <div class="doc-code">',"data-start":`write ${tt} on its <div class="doc-code">`,"data-line-numbers":'write it on its <div class="doc-code">',"data-folded-lines":'write it on its <div class="doc-code">',"data-title":'write the title in its <div class="doc-code-title">',"data-wrap":'for long lines that scroll, write class="doc-code doc-code--nowrap" on its <div class="doc-code">'};function Jo(t){let o=[],n=t.tagName==="pre"?t.parentNode:t.tagName==="code"&&t.parentNode?.tagName==="pre"?t.parentNode.parentNode:null;if(n?.tagName&&D(n,".doc-code"))for(let[s,i]of Object.entries(Ko))x(t,s)!==void 0&&o.push(`${s}${$(t)} on the <${t.tagName}> of a code block does nothing: ${i}`);let e=t.tagName==="div"&&D(t,".doc-code")?x(t,tt):void 0;return e!==void 0&&Co(e)===null&&o.push(`${tt}="${e}"${$(t)}: the number of a code block's first line is a whole number from 1`),o}var Se=Fo.join(", "),Zo=t=>D(t.parentNode,Se)||t.parentNode?.tagName==="div"&&!x(t.parentNode,"class")&&D(t.parentNode.parentNode,Se);function Vo(t,o){let n=[];et(o,s=>n.push(...Bo(t,s)));let e=s=>s.replace(/=(\s*)[“”]/,'=$1"').replace(/[“”]$/,'"');return n.map(({written:s,line:i},a)=>a===0?`line ${i}: attribute ${s} uses curly quotes (U+201C/U+201D), which HTML reads as part of the value: write straight quotes, ${e(s)}; an editor keeping a file's \u201C\u2026\u201D style may change them`:`line ${i}: attribute ${s} uses curly quotes too: write ${e(s)}`)}var xe={details:"write a plain <details> without the class (its <summary>, then what it holds): the export makes it the kit's"},qo="write a <section> of no attribute straight in it for each tab, starting with its heading (<h2>\u2013<h4>), the tab's name, the rest its blocks, and nothing else: the export makes the kit's tabs",Xo='a bookmark written the short way is a paragraph in a flow holding only <a class="doc-bookmark" href="https://\u2026">its title</a> (a title attribute its description, nothing else on it, words alone in it): the export makes the card';function Ee(t){let o=[];return et(t,n=>{x(n,L)!==void 0&&o.push(n)},{stop:W}),o}var Yo=t=>t.flatMap(o=>W(o)?Oe.test(x(o,L))?[]:[`${L}="${x(o,L)}"${$(o)} names no package: write <scope>/<name>, a package of the workspace's components/ folder`]:[`${L}${$(o)} on a <${o.tagName}>: an instance of a component is a block-level <div> or <section>`]);function Te(t){let o=Ee(t).filter(e=>W(e)&&Oe.test(x(e,L))),n=o.length>0?T():null;return o.flatMap(e=>{let s=x(e,L),i=n.packages.get(s);if(i&&!Do(x(e,gt),i.schema))return[];if(i)return[`line ${ot(e)}: <${e.tagName} ${L}="${s}">: ${gt}="${x(e,gt)}" is past the ${i.schema??1} its package's manifest reads (schema): nothing can write it back, and the block shows read-only until the package reads it`];let a=n.problems.get(s)?.problem,r=a?`package ${s} does not load (${Zt("en",a)})`:`no package ${s} in this workspace (components/${s}/component.json)`;return[`line ${ot(e)}: <${e.tagName} ${L}="${s}">: ${r}: the block shows what it holds, read-only, and moves, copies and deletes whole`]})}function $t(t,o){let n=[];for(let{name:e,value:s}of t.attrs){if(Y[e]&&!Q.has(e)){n.push(`${e}${$(t)} is gone: ${Y[e]}`);continue}if(e.startsWith("data-doc-")&&!Q.has(e)&&n.push(ye.has(e)?`${e}${$(t)} is the kit's to set: remove it`:`${e}${$(t)} is no attribute of the kit's${Ne(e)}`),e==="class"){for(let i of s.split(/\s+/).filter(o))if(!Q.has(i)){if(Y[i]){n.push(`class ${i}${$(t)} is gone: ${Y[i]}`);continue}n.push(ye.has(i)?`class ${i}${$(t)} is the kit's to set: remove it`:`class ${i}${$(t)} is no class of the kit's${Ne(Mo(i))}: give a class of the document's own a name of its own (not doc-\u2026)`)}}}return n}var ve=t=>t.startsWith("doc-");function Qo(t){try{return new Ao.Script(_o(t),{filename:"kit.js"}),null}catch(o){let n=/^kit\.js:(\d+)/.exec(o.stack??"")?.[1];return{message:o.message,line:n?Number(n):null}}}var wt=new Map;function tn(t){if(!t.files.includes("kit.js"))return null;if(wt.get(t.folder)?.stamp!==t.stamp){let o=le(t,"kit.js"),n=o===null?null:Qo(o),e=o===null?`${t.id}: its kit.js cannot be read`:n&&`${t.id}: its kit.js does not run: ${n.message}${n.line?` (line ${n.line})`:""}`;wt.set(t.folder,{stamp:t.stamp,failure:e})}return wt.get(t.folder).failure}function bt(t,o=g(t),n=null){let e=Vo(t,o),s=Ee(o);e.push(...Yo(s));let i=s.length>0?n??T():null,a=i?[...i.packages.values()]:[];i&&e.push(...A(t,i,o).map(tn).filter(Boolean));for(let c of[...Io,...a].filter(d=>d.match&&(d.parts||d.pairs)))for(let d of Ro(o,c)){if(c.empty&&!(d.childNodes??[]).some(u=>u.tagName||u.nodeName==="#text"&&u.value.trim()))continue;let h=c.id==="sheets"?Uo(d):null;if(h){e.push(`${c.id}${$(d)} has no tabs and is no short form: ${h.why??"it stands where no block does (in a whole block or a figure)"}; ${qo}`);continue}if(xe[c.id]&&Object.values(c.parts??{}).some(u=>ke(d,u.at).length<(u.optional?0:u.min??1))){e.push(`${c.id}${$(d)} carries the kit's class without the kit's parts: ${xe[c.id]}`);continue}let f={};for(let[u,p]of Object.entries(c.parts??{})){f[u]=ke(d,p.at);let m=p.optional?0:p.min??1,w=p.max??1/0;f[u].length<m?e.push(`${c.id}${$(d)} has ${f[u].length===0?"no":`${f[u].length} of`} ${u} (${p.at.replace(":scope > ","")})${f[u].length>0?`, at least ${m}`:""}`):f[u].length>w&&e.push(`${c.id}${$(d)} has ${f[u].length} of ${u}, at most ${w}`)}if(c.only){let u=new Set(c.only.flatMap(p=>f[p]));for(let p of(d.childNodes??[]).filter(m=>m.tagName&&!u.has(m)))e.push(`${c.id}${$(d)} holds a <${p.tagName}>${$(p)}: only its ${c.only.join(", ")} (${c.only.map(m=>c.parts[m].at.replace(":scope > ","")).join(", ")}) go in it`)}c.shares&&e.push(...Go(c,d,f[c.shares.part]));for(let{a:u,attrA:p,b:m,attrB:w}of c.pairs??[]){let y=f[u].map(k=>x(k,p)),b=f[m].map(k=>x(k,w));for(let k of new Set(y.filter((v,E)=>y.indexOf(v)!==E)))e.push(`${c.id}${$(d)}: ${u} "${k}" twice`);for(let k of y.filter(v=>!b.includes(v)))e.push(`${c.id}${$(d)}: ${u.replace(/s$/,"")} "${k}" has no ${m.replace(/s$/,"")} (${w}="${k}")`);for(let k of b.filter(v=>!y.includes(v)))e.push(`${c.id}${$(d)}: ${m.replace(/s$/,"")} "${k}" has no ${u.replace(/s$/,"")} (${p}="${k}")`)}}let r=new Set,l=[];et(o,c=>{if(W(c)){e.push(...$t(c,ve)),et(c,f=>e.push(...$t(f,ve)));return}c.tagName==="pre"&&Zo(c)&&e.push(`<pre>${$(c)} straight in the text: a code block is <div class="doc-code"> holding its title (<div class="doc-code-title">) and the <pre>`),e.push(...Jo(c)),c.tagName==="a"&&Wo(c,"doc-bookmark")&&e.push(`<a class="doc-bookmark">${$(c)} is no bookmark: ${Xo}`),e.push(...$t(c,Po));let d=x(c,"data-doc-bind");d!==void 0&&(d.trim()?D(c,Ho)?c.tagName==="button"&&x(c,"value")===void 0?e.push(`data-doc-bind${$(c)} on a button without a value: give it the value a click chooses`):r.add(d.trim()):e.push(`data-doc-bind${$(c)} on a ${c.tagName}: only inputs, selects, textareas, buttons with a value, details and tables hold a key`):e.push(`data-doc-bind${$(c)} names no key`));let h=x(c,"data-doc-show");h!==void 0&&l.push([c,h])},{stop:W});for(let[c,d]of l){let h=d.split(":")[0].trim();!h||!d.includes(":")?e.push(`data-doc-show="${d}"${$(c)}: write key:value`):r.has(h)||e.push(`data-doc-show="${d}"${$(c)}: nothing binds "${h}" (data-doc-bind="${h}")`)}return e.push(...rn(t,o)),e}var en=/(?<![\\$])\$(?=[^\s$])([^$]*?[^\s$\\])\$(?![$\d])/g,on=/(?:(?<![A-Za-z0-9_])[A-Za-z]|[)\]}])_[A-Za-z0-9{]/,nn=t=>/[\\^]/.test(t)||!t.startsWith("{")&&on.test(t),sn=new Set(["head","code","pre","kbd","samp","script","style","template","textarea","noscript","svg","math","title","iframe","object"]),an=`.doc-math-inline, .doc-math-block, .doc-code, .doc-diff, [data-doc-math-dollar], [data-doc-chart], ${zo}`;function rn(t,o){let n=[],e=s=>{for(let i of s.childNodes??[])if(i.nodeName==="#text"&&i.sourceCodeLocation&&i.value.includes("$")){let{startOffset:a,endOffset:r}=i.sourceCodeLocation;for(let l of t.slice(a,r).matchAll(en)){if(!nn(l[1]))continue;let c=l[1].replace(/\s+/g," "),d=c.length>60?`${c.slice(0,59)}\u2026`:c;n.push(`line ${Rt(t,a+l.index)}: $${d}$ is not drawn as a formula (single dollars are off: they are money): write \\(${d}\\)`)}}else i.tagName&&!sn.has(i.tagName)&&!D(i,an)&&e(i)};return e(o),n}import H from"node:fs";import _ from"node:path";import{COLOR_NAMES as fn}from"../browser/shared/colors.mjs";import{FOLD_DOTS as un}from"../browser/shared/code-folds.mjs";import{kitPublicDirectory as pn,kitSourceDirectory as mn,release as gn}from"../browser/shared/paths.mjs";import{FLOW_LABEL as Zi}from"../browser/shared/components/list.mjs";var cn={"code-title":{zh:"\u4EE3\u7801\u5757",en:"Code"},"plain-text":{zh:"\u7EAF\u6587\u672C",en:"Plain text"},"fold-code":{zh:"\u6298\u53E0\u6216\u5C55\u5F00\u4EE3\u7801\u5757",en:"Collapse or expand the code block"},"copy-code":{zh:"\u590D\u5236\u4EE3\u7801",en:"Copy code"},copied:{zh:"\u5DF2\u590D\u5236",en:"Copied"},wrap:{zh:"\u81EA\u52A8\u6362\u884C",en:"Wrap lines"},"no-wrap":{zh:"\u53D6\u6D88\u81EA\u52A8\u6362\u884C",en:"Stop wrapping lines"},fold:{zh:"\u6298\u53E0",en:"Collapse"},unfold:{zh:"\u5C55\u5F00",en:"Expand"},line:{zh:"\u7B2C {0} \u884C",en:"Line {0}"},lines:{zh:"\u7B2C {0}\u2013{1} \u884C",en:"Lines {0}\u2013{1}"},"diff-counts":{zh:"\u65B0\u589E {0} \u884C\uFF0C\u5220\u9664 {1} \u884C",en:"Lines added: {0}, removed: {1}"}};var Le="data-ge-language",ln={"code-title":"--doc-word-code-title"};function dn(t,o,n,...e){let s=t[n];if(!s)throw new Error(`The kit has no word "${n}" here (src/render/kit/words.js).`);let i=s[o]??s.zh;return e.length===0?i:i.replace(/\{(\d+)\}/g,(a,r)=>r<e.length?String(e[r]):a)}var hn=`:root[${Le}="en"], :root:not([${Le}])[lang|="en" i]`;function Ae(){let t=o=>Object.entries(ln).map(([n,e])=>`${e}: ${JSON.stringify(dn(cn,o,n))};`).join(" ");return`:root { ${t("zh")} }
|
|
3
|
-
${hn} { ${t("en")} }`}var Ce=Object.fromEntries(U.filter(t=>t.file).map(t=>[t.file,t.build])),sa=Object.keys(Ce),G=t=>_.join(mn,t),$n=(t,o,n)=>({entryPoints:[G(t)],bundle:!0,write:!1,format:"iife",platform:"browser",target:"es2022",...typeof o=="function"?o():o,...n}),wn=t=>{let o=Ce[t];if(!o)throw new Error(`src/render/kit-build.mjs: no kit file "${t}"`);return o},nt=new Map;function bn(t,o){let n=[...o.matchAll(/^@import\s+"\.\/([a-z0-9-]+\.css)";\s*$/gm)].map(i=>i[1]),e=H.readdirSync(_.dirname(G(t))).filter(i=>i.endsWith(".css")&&i!==_.basename(t)),s=[...e.filter(i=>!n.includes(i)).map(i=>`${i} is not listed`),...n.filter((i,a)=>!e.includes(i)||n.indexOf(i)!==a).map(i=>`${i} is listed but missing, or listed twice`)];if(s.length>0)throw new Error(`src/render/kit/${t}: ${s.join("; ")}`);return n.map(i=>_.join(_.dirname(t),i))}var kn=t=>t.replace(/@(text|highlight)-colors\b/g,(o,n)=>fn.map(e=>`.doc-${n}-${e}`).join(", ")),yn=t=>kn(t.join(`
|
|
4
|
-
`)).replaceAll("@fold-dots",un).replace(/^@kit-words;$/m,()=>Ae());function kt(t,{fresh:o=!1}={}){let n=wn(t);if(gn)return H.promises.readFile(_.join(pn,t),"utf8");if(n.read)return H.promises.readFile(G(n.read),"utf8");if(n.styles)return H.promises.readFile(G(n.styles),"utf8").then(e=>Promise.all(bn(n.styles,e).map(s=>H.promises.readFile(G(s),"utf8")))).then(yn);if(o||!nt.has(t)){let e=Xt($n(n.bundle,n.options)).then(s=>s.outputFiles[0].text);e.catch(()=>nt.delete(t)),nt.set(t,e)}return nt.get(t)}import{kitNamespace as Nn}from"../browser/shared/old-names.mjs";import{attr as yt,hasClass as st}from"../browser/shared/html-tree.mjs";var Ie=t=>t.tagName==="section"&&st(t,"doc-section"),Sn=new Set(["section","header","footer","nav","script","style","template","dialog","link","meta"]),xn=t=>!Sn.has(t.tagName),Nt=t=>t.nodeName==="#text"?t.value:(t.childNodes??[]).map(Nt).join("");function Re(t,o=[]){for(let n of t.childNodes??[])n.tagName&&((n.tagName==="main"&&st(n,"doc-page")||yt(n,"data-doc-sheet")!==void 0)&&o.push(n),Re(n.tagName==="template"?n.content:n,o));return o}var vn=/^(p|li|h[1-4]|blockquote|ul|ol)$/,je=["doc-summary","doc-panel","doc-note","doc-callout"],On=t=>vn.test(t.tagName)||je.some(o=>st(t,o)),En=new Set(["none","auto","100%","inherit","initial","unset","revert"]),Fe=t=>[...t.matchAll(/(?:^|[;{\s])(?:max-)?width\s*:\s*([^;}]+)/gi)].some(([,o])=>!En.has(o.replace(/!important/i,"").trim().toLowerCase())),Tn=t=>{let o=t.trim().split(/\s*[\s>+~]\s*/).at(-1)??"",n=/^(p|li|h[1-4]|blockquote|ul|ol)\b/.test(o)||je.some(s=>o.includes(`.${s}`)),e=[...t.matchAll(/\.([\w-]+)/g)].some(([,s])=>!Nn(s))||t.includes("#");return n&&!e};function Ln(t){let o=[],n=(e,s)=>{for(let i of e.childNodes??[]){if(!i.tagName)continue;let a=s||i.tagName==="main"&&st(i,"doc-page");if(a&&On(i)&&Fe(yt(i,"style")??"")&&o.push(`<${i.tagName}> with style="${yt(i,"style").trim()}"`),i.tagName==="style"){let r=Nt(i).replace(/\/\*[\s\S]*?\*\//g,"");for(let[,l,c]of r.matchAll(/([^{}]+)\{([^{}]*)\}/g))if(Fe(c))for(let d of l.split(","))Tn(d)&&o.push(`"${d.trim()}" in the document's style`)}n(i.tagName==="template"?i.content:i,a)}};return n(t,!1),o}function ze(t,{written:o=t}={}){let n=[],e=g(t),s=Ln(e);s.length>0&&n.push(`body text given a width of its own (${s.slice(0,3).join("; ")}${s.length>3?`; ${s.length-3} more`:""}): its lines break before the reading column's edge, leaving an extra right margin; let body text fill the column`);for(let i of Re(e)){let a=i.childNodes.filter(r=>r.tagName);a.forEach((r,l)=>{if(!Ie(r))return;let c=l+1;for(;c<a.length&&xn(a[c]);)c++;let d=a.slice(l+1,c);if(d.length===0||!Ie(a[c]??{})||/^h[1-4]$/.test(d[0].tagName))return;let h=r.childNodes.map(f=>f.tagName?f:null).filter(Boolean).map(Nt).find(f=>f.trim())?.replace(/\s+/g," ").trim().slice(0,40)??"";n.push(`${d.length} block${d.length===1?"":"s"} of body text right after the section "${h}" stand outside it, between two sections, with no heading of their own: fine if meant, otherwise they belong inside that section`)})}return n.push(...we(t,{written:o})),n}import{attr as De,hasClass as An}from"../browser/shared/html-tree.mjs";var _e="Write instead where it came from, in words, or a path relative to materials/ (materials/data.csv)",Cn=new Set(["script","style","template","noscript","textarea","pre","code","kbd","samp","var"]),In=["doc-math-inline","doc-math-block"],Fn=/\\\([\s\S]*?\\\)|\\\[[\s\S]*?\\\]|\$\$[\s\S]*?\$\$/g,Rn=/(?<!\\)\$(?:\\[\s\S]|[^\\$])+\$/g,jn=/[\s"'<>|()[\]{};,。;:、!?()《》「」『』“”‘’【】]/u,zn=/[^\s"'<>|()[\]{};,。;:、!?()《》「」『』“”‘’【】]+/gu,Ue=/^[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/u,Dn=/\.[A-Za-z0-9]{1,8}$/,_n=[/(?<![A-Za-z0-9_\\])[A-Za-z]:[\\/]/g,/(?<![A-Za-z0-9_.~:/\\-])\/(?:Users|home|root|tmp|private|mnt|opt|Volumes|var\/folders)\/(?=\S)/g,/(?<![A-Za-z0-9_.~:/\\-])~\/(?=\S)/g,/(?<![A-Za-z0-9_$\\])\$(?:HOME|\{HOME\})\/(?=\S)/g,/(?<![A-Za-z0-9_:\\])\\\\[A-Za-z0-9][\w.$-]*\\(?=[^\s\\])/g,/%(?:TEMP|TMP|APPDATA|LOCALAPPDATA|USERPROFILE)%/gi],Mn=/(?:^|[\\/])(?:AppData|scratchpad)(?=[\\/]|$)/i,Pn=/^(?:[A-Za-z]:|[\\/]|%[A-Za-z]+%)[\s\S]*[\\/](?:temp|tmp)(?=[\\/])/i,Un=t=>t.includes("://")&&!/^file:/i.test(t),Me=12;function Pe(t,o){let n=o;for(;n<t.length&&!jn.test(t[n])&&!(Ue.test(t[n])&&Dn.test(t.slice(o,n)));)n++;return t.slice(o,n).replace(/[.,;:!?]+$/,"")}function Bn(t,o=!1){let n=r=>r.replace(/[^\n]/g," "),e=t.replace(Fn,n),s=o?e.replace(Rn,n):e,i=[],a=(r,l)=>i.some(c=>c.at<=r+l.length&&r<=c.at+c.path.length);for(let r of _n)for(let l of s.matchAll(r)){let c=Pe(s,l.index);c.length>=l[0].length+2&&!a(l.index,c)&&i.push({at:l.index,path:c})}for(let r of s.matchAll(zn)){let l=r.index;for(;l<r.index+r[0].length&&Ue.test(s[l]);)l++;let c=Pe(s,l);/[\\/]/.test(c)&&(Mn.test(c)||Pn.test(c))&&!Un(c)&&!a(l,c)&&i.push({at:l,path:c})}return i.sort((r,l)=>r.at-l.at)}function Be(t,o=g(t)){let n=[],e=(a,r)=>{for(let l of a.childNodes??[])if(l.nodeName==="#text"){if(!l.sourceCodeLocation)continue;for(let{at:c,path:d}of Bn(l.value,r))n.push({line:l.sourceCodeLocation.startLine+(l.value.slice(0,c).match(/\n/g)?.length??0),path:d})}else l.tagName&&!Cn.has(l.tagName)&&De(l,"hidden")===void 0&&!In.some(c=>An(l,c))&&e(l,r||De(l,"data-doc-math-dollar")!==void 0)};e(o,!1);let s=n.slice(0,Me).map(({line:a,path:r})=>`line ${a}: "${r.length>80?`${r.slice(0,77)}\u2026`:r}" is a path of this machine in the text a reader reads: a reader on another machine cannot open it. ${_e}`),i=n.slice(Me);return i.length>0&&s.push(`${i.length} more path${i.length===1?"":"s"} of this machine in the text a reader reads, on line${new Set(i.map(({line:a})=>a)).size===1?"":"s"} ${[...new Set(i.map(({line:a})=>a))].join(", ")}. ${_e}`),s}import{MENTION as Wn,MENTION_ICON as Hn}from"../browser/shared/components/mention.mjs";import{escapeAttribute as Gn}from"../browser/shared/escape.mjs";import{attr as We,elementsOf as Kn,hasClass as He,walk as Jn}from"../browser/shared/html-tree.mjs";import{addressOn as Zn,decoded as Vn,fromFile as qn,hosted as Xn,pageAddress as Yn,workbenchHash as Qn}from"../browser/shared/page-address.mjs";function ts(t,o,n){let e=qn(t,o),s=Zn(e,n);return s||Xn(t)?s:Yn(e)??(Qn(e)===null?null:{slug:null,block:null})}function es(t,o,n,e){let s=g(t),i=new Set,a=[];Jn(s,c=>{let d=We(c,"data-block-id");d!==void 0&&i.add(d),c.tagName==="a"&&We(c,"href")!==void 0&&c.sourceCodeLocation?.startTag&&a.push(c)});let r=new Map,l=({startOffset:c,endOffset:d})=>r.set(c,[d,""]);for(let c of a){let{prefix:d,value:h}=c.attrs.find(({name:b})=>b==="href"),f=h.startsWith("#")?Vn(h.slice(1)):null,u=f===null?h&&ts(h,o,e):i.has(f)?{slug:o,block:f}:null;if(!u)continue;let p=n(u,h);if(p===h)continue;let{attrs:m,startTag:w,endTag:y}=c.sourceCodeLocation;if(p===null)l(w),y&&l(y),He(c,Wn)&&Kn(c).filter(b=>He(b,Hn)).forEach(b=>l(b.sourceCodeLocation));else{let b=d?`${d}:href`:"href";r.set(m[b].startOffset,[m[b].endOffset,`${b}="${Gn(p)}"`])}}return[...r].sort(([c],[d])=>d-c).reduce((c,[d,[h,f]])=>`${c.slice(0,d)}${f}${c.slice(h)}`,t)}function Ge(t,o,n,{blocks:e=!0,links:s}){return es(t,o,({slug:i,block:a})=>{let r=n(i);if(r===null)return null;if(!a||!e)return i===o&&a?null:r;let l=`#${encodeURIComponent(a)}`;return i===o?l:`${r}${l}`},s)}import it from"node:fs";import os from"node:path";import{extensionOf as ns,imageFile as ss,mediaTypeOf as is}from"../browser/shared/media.mjs";var vt=1024*1024,as=vt,Je=2400,St=2e3,rs=.25,cs=new Set(["png","gif"]),Ke=.75;function ls(t){if(t.length<16||t.toString("latin1",0,4)!=="RIFF"||t.toString("latin1",8,12)!=="WEBP")return!1;for(let o=12;o+8<=t.length;){let n=t.toString("latin1",o,o+4);if(n==="VP8L")return!0;if(n==="VP8 "||n==="ANMF")return!1;let e=t.readUInt32LE(o+4);o+=8+e+e%2}return!1}function ds(t){let o=(n,e)=>n+e<=t.length;if(o(0,24)&&t.readUInt32BE(0)===2303741511&&t.toString("latin1",12,16)==="IHDR")return{width:t.readUInt32BE(16),height:t.readUInt32BE(20)};if(o(0,10)&&/^GIF8[79]a$/.test(t.toString("latin1",0,6)))return{width:t.readUInt16LE(6),height:t.readUInt16LE(8)};if(o(0,4)&&t[0]===255&&t[1]===216){for(let n=2;o(n,4);){if(t[n]!==255)return null;let e=t[n+1];if(e===255){n+=1;continue}if(e===216||e===1||e>=208&&e<=215){n+=2;continue}if(e>=192&&e<=207&&![196,200,204].includes(e))return o(n,9)?{width:t.readUInt16BE(n+7),height:t.readUInt16BE(n+5)}:null;if(e===217||e===218)return null;n+=2+t.readUInt16BE(n+2)}return null}if(o(0,30)&&t.toString("latin1",0,4)==="RIFF"&&t.toString("latin1",8,12)==="WEBP"){let n=t.toString("latin1",12,16);if(n==="VP8 ")return{width:t.readUInt16LE(26)&16383,height:t.readUInt16LE(28)&16383};if(n==="VP8L"){let e=t.readUInt32LE(21);return{width:(e&16383)+1,height:(e>>>14&16383)+1}}return n==="VP8X"?{width:t.readUIntLE(24,3)+1,height:t.readUIntLE(27,3)+1}:null}if(o(0,12)&&t.toString("latin1",4,8)==="ftyp"&&/avi[fs]/.test(t.toString("latin1",8,Math.min(t.length,t.readUInt32BE(0))))){let n=null;for(let e=t.indexOf("ispe",0,"latin1");e>=0&&o(e,16);e=t.indexOf("ispe",e+4,"latin1")){let s={width:t.readUInt32BE(e+8),height:t.readUInt32BE(e+12)};(!n||s.width*s.height>n.width*n.height)&&(n=s)}return n}return null}var hs=vt;function fs(t){let o;try{o=it.openSync(t,"r");let{size:n}=it.fstatSync(o),e=Buffer.alloc(Math.min(n,hs));return it.readSync(o,e,0,e.length,0),{length:n,head:e}}catch{return null}finally{o!==void 0&&it.closeSync(o)}}var F=t=>`${Math.max(.1,t/vt).toFixed(1)} MB`;function us({bytes:t,width:o,height:n,extension:e,lossless:s}){let i=Math.max(o,n),a=Math.min(1,St/i),r=Math.min(t,o*n*a*a*rs);if(i>Je){if(!s)return r<=t*Ke?` \u2014 a ${St}px copy would be about ${F(r)}`:"";let l=t*a*a;return` \u2014 a ${St}px copy would be about ${F(l)}${e==="png"&&r<l/2?`, or ${F(r)} as a JPEG (for a photograph)`:""}`}return!s&&r<=t*Ke?` \u2014 written again as a JPEG of quality about 82, it would be about ${F(r)}`:e==="png"&&r<t/2?` \u2014 as a JPEG (for a photograph) it would be about ${F(r)}`:""}var xt=t=>t===2?"twice":`${t} times`;function Ze({html:t,directory:o,tree:n=g(t)}){let{embedded:e,unserved:s}=Kt({html:t,directory:o,tree:n}),i=new Map,a=(l,c,d,h=!1)=>{let f=i.get(l)??i.set(l,{at:[],shows:0,served:d}).get(l);f.at.push(c),h||(f.shows+=1)};for(let{file:l,line:c,icon:d}of e)ss(l)&&a(l,c,!0,d);for(let{file:l,line:c}of s)is(l).startsWith("image/")&&a(l,c,!1);let r=[];for(let[l,{at:c,shows:d,served:h}]of[...i].sort(([,f],[,u])=>Math.min(...f.at)-Math.min(...u.at))){let f=fs(os.join(o,l));if(!f)continue;let{length:u,head:p}=f,m=ds(p),w=m?Math.max(m.width,m.height):0,y=u>as||w>Je,b=h&&d>1;if(!y&&!b)continue;let k=[...new Set(c)],v=`line${k.length===1?"":"s"} ${k.length>1?`${k.slice(0,-1).join(", ")} and ${k.at(-1)}`:k[0]}`,E=b?`shown ${xt(d)}: the export embeds it ${xt(d)}; show it once and refer back to it in words`:"";if(!y){r.push(`${l} (${v}): ${E} (${F(Math.ceil(u/3)*4*d)} as data: URLs)`);continue}let P=c.length===1||!h?"":`, ${xt(c.length)}`,R=h?c.length:1,J=`${F(Math.ceil(u/3)*4*R)} as ${R===1?"a data: URL":"data: URLs"}`,bo=m?`, ${m.width}\xD7${m.height}px`:"",Ct=ns(l),It=m?us({bytes:u,...m,extension:Ct,lossless:cs.has(Ct)||ls(p)}):"",ko=h?`the export embeds it as it is${P}, ${J}${It}`:`its name keeps it out of the preview and the export (the failure at its line says why); copied into assets/ under a name they take, the export embeds it as it is, ${J}${It}: copy it in at the size the page needs`;r.push(`${l} (${v}): ${F(u)}${bo}; ${ko}${E?`; ${E}`:""}`)}return r}import{COMPONENTS as Ls}from"../browser/shared/components/index.mjs";import Ve from"node:fs";import{MENTION as qe,MENTION_ICON as Xe}from"../browser/shared/components/mention.mjs";import{escapeAttribute as ps,escapeText as ms}from"../browser/shared/escape.mjs";import{iconUrl as gs,validIcon as $s}from"../browser/shared/emoji/icon-value.mjs";import{attr as ws,hasClass as bs,walk as ks}from"../browser/shared/html-tree.mjs";import{fromFile as ys,isFileLink as Ns,pageAddress as Ss}from"../browser/shared/page-address.mjs";import{reportsDirectory as xs}from"../browser/shared/paths.mjs";import{documentDirectory as vs,documentFiles as Os}from"../browser/shared/workspace.mjs";function Es(t,o){let{html:n,json:e}=Os(vs(t,o));if(!Ve.existsSync(n))return null;try{let{title:s,icon:i}=JSON.parse(Ve.readFileSync(e,"utf8"));return{title:s,icon:i}}catch{return{}}}function Ts(t,o,n,e){if(n==="words"||typeof t!="string"||!$s(t))return null;if(n==="preview")return gs(t,o,{tab:!0});let s=zt({value:t,slug:o,tab:!0,reportsDirectory:e});return s&&`data:${s.type};base64,${s.body.toString("base64")}`}function Ye(t,{slug:o,mode:n="export",reportsDirectory:e=xs}){if(!t.includes(qe))return t;let s=new Map,i=r=>(s.has(r)||s.set(r,Es(r,e)),s.get(r)),a=new Map;return ks(g(t),r=>{let l=r.tagName==="a"&&bs(r,qe)?ws(r,"href"):void 0,{startTag:c,endTag:d}=r.sourceCodeLocation??{};if(!l||!Ns(l)||!c||!d)return;let h=Ss(ys(l,o))?.slug;if(!h)return;let f=i(h);if(!f)a.set(c.endOffset-1,[c.endOffset-1," data-doc-gone"]);else if(f.title){let u=Ts(f.icon,h,n,e);a.set(c.endOffset,[d.startOffset,`${u?`<img class="${Xe}" src="${ps(u)}" alt="">`:`<span class="${Xe}"></span>`}${ms(f.title)}`])}}),[...a].sort(([r],[l])=>l-r).reduce((r,[l,[c,d]])=>`${r.slice(0,l)}${d}${r.slice(c)}`,t)}var As=/<script\b[^>]*\bdata-doc-kit="runtime"[^>]*><\/script>/;function Cs(t,o,n){let e=Vt(o).filter(({id:s})=>!n.some(i=>i.id===s)).map(qt).join(" ");return e?t.replace(As,s=>`${s}
|
|
5
|
-
<script data-doc-dev>${e}</script>`):t}function Ot(t,{slug:o,mode:n="export",files:e=!0,reportsDirectory:s,kit:i}){let a=T(s),r=A(t,a),{html:l,removed:c,used:d}=Qt(t,[...Ls,...r]),h={slug:o,mode:n,...s?{reportsDirectory:s}:{}},f=ce(te(l,{used:d,...i?{href:i}:{}}),r),u=Dt(n==="preview"?Cs(f,a,r):f,h),p=e?Jt(Mt(Ut(Wt(u,h),h),h),h):u;return{html:Ye(p,h),removed:c}}import{exportsDirectory as Tt,generatedDirectory as K,kitPublicDirectory as Bs,release as Ws,reportsDirectory as z,vendorDirectory as Hs}from"../browser/shared/paths.mjs";import{referencedFile as Gs}from"../browser/shared/media.mjs";import{decoded as Ks,fromFile as Js,hashAddress as Zs,hosted as lo,pageAddress as Vs,workbenchHash as qs}from"../browser/shared/page-address.mjs";import{pageLinks as Xs}from"../browser/shared/page-links.mjs";import{documentLinks as Ys,listReportSlugs as Qs}from"../browser/shared/reports.mjs";import{documentDirectory as M,documentFiles as At}from"../browser/shared/workspace.mjs";import{sha256 as at}from"../browser/shared/files.mjs";import{EXPORT_CSP as ti,GENERATOR as ei,isolateUmd as oi,packagesMeta as ni,sourceMeta as si}from"../browser/shared/export-wrap.mjs";var no=/__REPORT_[A-Z_]+__/,so=1e6,io=t=>t.length>1?`${t.slice(0,-1).join(", ")} and ${t.at(-1)}`:`${t[0]}`;function ii(t){return t.map(({id:o,lines:n,columns:e})=>{let s=new Set(n).size<n.length,i=n.map((a,r)=>s?`${a}:${e[r]}`:`${a}`);return`data-block-id repeats: "${o}" on lines ${io(i)}${s?" (line:column)":""}; each id names one block: remove it from the copy, which needs none (the later ${i.length>2?`ones, lines ${io(i.slice(1))}`:`one, line ${i[1]}`}, unless the copy went before its original)`})}var ai=({slug:t,htmlPath:o,metadataPath:n})=>{let e=o?{html:o,json:n??o.replace(/\.html$/,".json")}:At(M(t,z));return{htmlName:S.basename(e.html),jsonName:S.basename(e.json)}};function ri({slug:t,html:o,metadata:n,htmlPath:e,metadataPath:s,tree:i=g(o)}){let a=[],{htmlName:r,jsonName:l}=ai({slug:t,htmlPath:e,metadataPath:s}),c=[[/<meta\s+name=["']viewport["']/i,"missing viewport metadata"],[/<title>[^<]+<\/title>/i,"missing document title"],[/<main(?:\s|>)/i,"missing semantic main element"],[/aria-label|aria-labelledby|<title>/i,"missing accessible labels"]];for(let[p,m]of c)p.test(o)||a.push(m);let d=Buffer.byteLength(o);d>so&&a.push(`the document's editable source is ${d.toLocaleString("en-US")} bytes, over the ${so.toLocaleString("en-US")}-byte limit: aggregate or sample the embedded data, or split the document`),no.test(o)&&a.push(`${r} still contains a starter placeholder such as __REPORT_TITLE__`);for(let[p,m]of Object.entries(n))typeof m=="string"&&no.test(m)&&a.push(`${l} "${p}" is still a starter placeholder such as __REPORT_TITLE__`);/<[a-z][^>]*\sdata-doc-placeholder\b/i.test(o)&&a.push("starter placeholder content ([data-doc-placeholder]) is still present; replace it with the document's content");let h=new Map;j(i,p=>{let m=O(p,"data-block-id"),w=p.sourceCodeLocation?.attrs?.["data-block-id"]??p.sourceCodeLocation;m!==void 0&&h.set(m,[...h.get(m)??[],{line:w?.startLine,column:w?.startCol}])});let f=[...h].filter(([,p])=>p.length>1);a.push(...ii(f.map(([p,m])=>({id:p,lines:m.map(({line:w})=>w),columns:m.map(({column:w})=>w)}))));let u=null;if(j(i,p=>{!u&&p.tagName==="main"&&(u=p)},{inTemplates:!1}),u){let p=O(u,"data-doc-id");p===void 0?a.push(`main.doc-page needs data-doc-id="${t}"`):p!==t&&a.push(`main[data-doc-id] is "${p}": it must be the document's slug "${t}"`)}return a}var ho=t=>eo(eo(t).find(o=>o.tagName==="html")??{}).find(o=>o.tagName==="head")?.sourceCodeLocation?.startTag?.endOffset,Lt=new Set(["localStorage","sessionStorage"]);function fo(t){let o=[],n=[];return j(t,e=>{e.tagName==="script"&&O(e,"src")!==void 0&&o.push(O(e,"src")),(e.tagName==="link"?(O(e,"rel")??"").toLowerCase().split(/\s+/):[]).includes("stylesheet")&&O(e,"href")!==void 0&&n.push(O(e,"href"))}),{scripts:o,styles:n}}function uo({slug:t,html:o,directory:n=M(t,z),tree:e=g(o),uses:s=V(o,Z,{tree:e}),catalog:i}){let a=[];ho(e)===void 0&&a.push("the page writes no <head> start tag, which an export puts its Content-Security-Policy right after: write <head> \u2026 </head> before <body>");let r=[];j(e,d=>{if(["script","link","img"].includes(d.tagName))for(let h of["src","href"]){let f=O(d,h)?.trim();f&&/^https?:\/\//i.test(f)&&r.push(f)}}),r.length>0&&a.push(`external resources are not portable: ${r.join(", ")}`);for(let{name:d,how:h,line:f,where:u}of s){if(!Z.has(d))continue;let p={call:`calls ${d}(\u2026)`,new:`creates new ${d}(\u2026)`}[h]??`uses ${d}`;a.push(`line ${f}: ${u} ${p}: embed its data (inline JSON, DocState); the export blocks the network`)}let{scripts:l,styles:c}=fo(e);for(let d of l)se.has(d)||a.push(`unsupported script dependency ${d}`);for(let d of c)ie.has(d)||a.push(`unsupported stylesheet dependency ${d}`);return a.push(...Ht({html:o,directory:n,tree:e}),...Bt({html:o,directory:n,tree:e}),...Pt({html:o,directory:n,tree:e}),...Gt({html:o,directory:n,tree:e})),a.push(...de(A(o,i,e))),[...new Set(a)]}var ci=[[/\bDocSheets\.mount\s*\(/,"Sheet areas start on their own: remove DocSheets.mount (an area keeps its tab under its data-doc-sheets name)"],[/\bDocCode\.(?:View|DiffView|DiffStats|enhance)\b/,'code blocks are highlighted on their own, and a diff is declared as <div class="doc-diff"> holding { path, lines } as JSON (sdk/doc-code.d.ts)'],[/\bDocTables\.(?:enhance|enhanceAll|makeSortable)\b/,"tables start on their own: remove the call"],[/\bDocDialogs\.(?:enhance|enhanceAll)\b/,"detail cards start on their own: remove the call"]];function li({html:t,tree:o=g(t),uses:n=V(t,Lt,{tree:o})}){let e=ae(t,o),s=[...ee(t,o),...oe(t,o)];for(let[i,a]of ci)i.test(e)&&s.push(`${e.match(i)[0].replace(/\s*\($/,"")} is gone: ${a}`);for(let{name:i,line:a,where:r}of n)Lt.has(i)&&s.push(`line ${a}: ${r} uses ${i}: use DocState instead of direct browser storage`);return[...new Set(s)]}var di=(t,o)=>o.childNodes.find(n=>n.tagName||n.nodeName==="#text"&&n.value.trim())===t,hi=t=>to(t,Rs("highlight").match)||t.tagName==="li"&&to(t.parentNode,`ol.${zs}`),fi=`an icon is one of three kinds: an emoji, <div class="doc-icon">\u{1F3AF}</div>; an icon of Gallery's sets in one of ${oo.length} colors, <div class="doc-icon" data-icon="/icons/airplane_blue.svg"></div> (MingCute's names; Tabler's as /icons/tabler/plane_blue.svg; the colors ${oo.join(", ")}); or a picture of the document's folder, <div class="doc-icon"><img src="assets/logo.png" alt=""></div>`,po=t=>t.nodeName==="#text"?t.value:(t.childNodes??[]).map(po).join("");function ao(t,o,n){let e=o.sourceCodeLocation?.attrs?.[n],s=e?t.slice(e.startOffset,e.endOffset):`${n}="${O(o,n)??""}"`;return s.length>72?`${s.slice(0,71)}\u2026`:s}function ui(t,o){let n=O(o,"data-icon");if(n!==void 0)return{held:ao(t,o,"data-icon"),meant:Et(n)==="glyph"?n:null};let e=null;if(j(o,i=>{e??=["img","svg"].includes(i.tagName)?i:null}),e?.tagName==="img"){let i=O(e,"src");return{held:`<img ${ao(t,e,"src")}>`,meant:Et(i)==="image"?i:null}}if(e)return{held:"an <svg>"};let s=po(o).replace(/\s+/g," ").trim();return{held:s?`"${s.slice(0,40)}"`:"nothing"}}function pi({set:t,name:o,color:n}){let e=Ds.find(a=>a!==t);if(ct(e).includes(o))return`; "${o}" is ${e==="tabler"?"Tabler":"MingCute"}'s: ${Ms(e,o,n)}`;let s=o.split("-").filter(a=>a.length>=3),i=ct(t).filter(a=>a.split("-").some(r=>s.includes(r))).slice(0,6);return i.length>0?`; names of its set near it: ${i.join(", ")}`:""}function mi({html:t,tree:o=g(t)}){let{all:n,own:e}=_t(o),s=[],i=a=>a.sourceCodeLocation?.startLine;e.length>1&&s.push(`line ${i(e[1])}: ${e.length} page icons (.doc-icon) in the header (the first at line ${i(e[0])}): a document has one, right before its title`);for(let a of n){let r=i(a),l=a.parentNode;!e.includes(a)&&!(hi(l)&&di(a,l))&&s.push(`line ${r}: an icon (.doc-icon) stands only right before the document's title, first in a highlight block (.doc-panel, .doc-summary), or first in a flowchart's step (ol.doc-flow > li, in its number's place)`);let c=Us(Ft(t,a)),{held:d,meant:h}=c?{}:ui(t,a);h?s.push(`line ${r}: an icon (.doc-icon) holds ${d}, an icon a page reads only in double quotes: write ${Ps(h)}`):c?Et(c)==="glyph"&&!jt(c)&&s.push(`line ${r}: the icon ${c} is none of the icon sets' (MingCute: /icons/<name>_<color>.svg, Tabler: /icons/tabler/<name>_<color>.svg; src/shared/emoji/data/icons.json lists the names of each)${pi(_s(c))}`):s.push(`line ${r}: an icon (.doc-icon) holds no icon (it holds ${d}): ${fi}`)}return[...new Set(s)]}function mo(t){let o=g(t.html),n={...t,tree:o,uses:V(t.html,new Set([...Z,...Lt]),{tree:o})};return[...ri(n),...bt(t.html,o),...li(n),...mi(n),...uo(n)]}function gi(t){let o=new Map(t.map(s=>[s.slug,[...mo(s),...mt(s.html)]])),n=new Map(t.map(s=>[S.resolve(s.htmlPath),s.slug])),e=new Map(t.map(s=>[S.resolve(s.htmlPath),s]));for(let s of t)s.scriptNotes=[];if(t.length>0)for(let{htmlPath:s,text:i,typeOnly:a,note:r}of re(t)){if(a){e.get(s)?.scriptNotes.push(r);continue}let l=s?[n.get(s)]:[...o.keys()];for(let c of l)o.get(c).push(s?i:`${i} (shared SDK declaration)`)}for(let[s,i]of o)i.length===0&&o.delete(s);return o}async function Tr(t=[],{prepare:o=null}={}){let{reports:n,failures:e}=await rt(t,{prepare:o});for(let s of n){let i=[...mo(s),...mt(s.html)];i.length&&e.set(s.slug,i)}return e}async function $i(t=[],{prepare:o=null}={}){let{reports:n,failures:e}=await rt(t,{prepare:o});for(let[s,i]of gi(n))e.set(s,i);return{reports:n,failures:e}}async function wi({fresh:t=!1,kit:o=Bs,vendor:n=Hs}={}){if(Ws)return;let e=U.map(a=>[a,a.file?kt(a.file,{fresh:t}):dt(a)]);await N.mkdir(o,{recursive:!0});let s=S.join(n,"katex","fonts");await N.mkdir(s,{recursive:!0});let i=(await N.readdir(lt)).filter(a=>a.endsWith(".woff2"));await Promise.all(i.map(a=>N.copyFile(S.join(lt,a),S.join(s,a)))),await Promise.all(e.map(async([a,r])=>N.writeFile(a.file?S.join(o,a.file):S.join(n,...a.vendor.path.split("/").slice(2)),await r)))}async function bi(t,o){let n=await N.readdir(t).catch(()=>[]);await Promise.all(n.filter(e=>e.endsWith(".html")&&!o.has(e.slice(0,-5))).map(e=>N.rm(S.join(t,e),{force:!0})))}async function ki(t){let o=S.join(K,"reports.json"),n=await N.readFile(o,"utf8").then(JSON.parse,()=>[]),e=new Map(Array.isArray(n)?n.map(i=>[i.slug,i]):[]);for(let{entry:i}of t)e.set(i.slug,i);let s=[];for(let[i,a]of[...e].sort(([r],[l])=>r.localeCompare(l))){let r=S.join(K,`${i}.html`);await N.stat(r).then(()=>!0,()=>!1)&&s.push(a)}await N.writeFile(o,`${JSON.stringify(s,null,2)}
|
|
6
|
-
`)}async function yi(t=[],{prepare:o=null}={}){let{reports:n,failures:e}=await $i(t,{prepare:o});await wi(),await N.mkdir(K,{recursive:!0}),await bi(K,new Set(await Qs()));let s=[];for(let i of n){let a=`${i.slug}.html`,r=S.join(K,a);if(e.has(i.slug)){await N.rm(r,{force:!0});continue}let{html:l,removed:c}=Ot(i.html,{slug:i.slug});await N.writeFile(r,l),s.push({report:i,html:l,removed:c,entry:{slug:i.slug,...i.metadata,preview:`/generated/${a}`,sourceSha256:at(i.html),outputSha256:at(l)}})}return await ki(s),{built:s,failures:e}}var Ni=t=>t.replace(/<\/script/gi,"<\\/script");async function go(){return new Map(await Promise.all(U.map(async t=>{let o=await(t.file?kt(t.file):dt(t,{inline:!0}));return Yt(t).endsWith(".css")||(o=Ni(o)),[t.id,t.umd?oi(o):o]})))}function Si(t,o,n=null,e=[]){let s=ho(g(o));if(s===void 0)throw new Error(`${t}: the page writes no <head> start tag, which the export's Content-Security-Policy goes right after`);let i=n?`
|
|
7
|
-
${si(n)}${e.length>0?`
|
|
8
|
-
${ni(e)}`:""}`:"";return`${o.slice(0,s)}
|
|
9
|
-
<meta name="generator" content="${ei}">
|
|
10
|
-
<meta http-equiv="Content-Security-Policy" content="${ti}">${i}${o.slice(s)}`}function $o(t,o,n,e=null,s=T()){let i=A(o,s);o=ne(he(Si(t,o,e,i),s),({id:l,element:c,attribute:d})=>{let h=n.get(l);if(typeof h!="string")throw new Error(`${t}: no inline source for the asset "${l}" (loadInlineSources in src/render/pipeline.mjs)`);return`<${c} ${d}="${l}-inline">${h}</${c}>`});let{scripts:a,styles:r}=fo(g(o));if(a.length+r.length>0)throw new Error(`${t}: export still contains a linked script or stylesheet`);return o}async function ro(t,o=z,{components:n=!0}={}){let e=M(t,o),s=await N.readFile(At(e).html),i=s.toString("utf8"),a=g(i),r=n?T(o):{packages:new Map},l=[...n?bt(i,a,r):[],...uo({slug:t,html:i,directory:e,tree:a,catalog:r})];if(l.length>0){let c=A(i,r,a).find(({id:d})=>l[0].startsWith(`${d}:`)||l[0].startsWith(`${d} (`))?.id;throw Object.assign(new Error(`${t}: ${l[0]}`),{reason:"check",slug:t,failures:l,...c?{component:c}:{}})}return{html:i,sha256:at(s)}}async function Lr({directory:t=z}={}){let o=await go(),n=async(e,{files:s=!0}={})=>{let i=await ro(e,t);return $o(e,Ot(i.html,{slug:e,files:s,reportsDirectory:t}).html,o,i.sha256,T(t))};return n.check=async e=>{await ro(e,t,{components:!1})},n}async function Ar(t=[],{prepare:o=null}={}){let{built:n,failures:e}=await yi(t,{prepare:o}),s=await go();await N.mkdir(Tt,{recursive:!0});let i=new Set(n.map(({report:l})=>l.slug)),{links:a}=await Ys(),r=[];for(let{report:l,html:c}of n)try{let d=Ge(c,l.slug,f=>i.has(f)?`${f}.html`:null,{links:a}),h=$o(l.slug,d,s,l.fileSha256);await N.writeFile(S.join(Tt,`${l.slug}.html`),h),r.push({slug:l.slug,bytes:Buffer.byteLength(h),sha256:at(h)})}catch(d){e.set(l.slug,[d.message])}return{built:n,exported:r,failures:e}}function co(t){let o=new Set;return j(t,n=>{for(let e of["id","data-block-id"])O(n,e)!==void 0&&o.add(O(n,e))}),o}function xi(t,o,n){if(lo(t)||/^(?:[a-z][a-z0-9+.-]*:|\/)/i.test(t)||Gs(t))return!1;let{pathname:e}=new URL(o);return!e.startsWith(`/${n}/`)||e.endsWith(".html")}function vi({slug:t,tree:o,directory:n}){let e=[],s=co(o),i=n===M(S.basename(n),z)?z:S.dirname(n),a=new Map([[t,s]]),r=d=>{if(!a.has(d)){let h=At(M(d,i));a.set(d,Qe(h.html)?co(g(Is(h.html,"utf8"))):null)}return a.get(d)},l=null,c=(d,h)=>h===null?Vs(d):Zs(h,l??=Xs((Qe(i)?Fs(i):[]).map(f=>({slug:f}))));return j(o,d=>{let h=d.tagName==="a"?O(d,"href"):void 0;if(!h||h==="#"||h==="#top")return;let f=d.sourceCodeLocation?.startLine;if(h.startsWith("#")){s.has(Ks(h.slice(1)))||e.push(`the link to ${h} (line ${f}) names no block or element of this document`);return}let u=Js(h,t),p=qs(u),m=c(u,p);(m?!r(m.slug):p!==null)?lo(h)||e.push(`the link to ${h} (line ${f}) names a document that is not there: gallery list has the slugs`):m?.block&&!r(m.slug).has(m.block)?e.push(`the link to ${h} (line ${f}) names a block document ${m.slug} does not hold`):u&&!m&&xi(h,u,t)&&e.push(`the link to ${h} (line ${f}) leads to no document: a link to one is ../<slug>/doc.html, gallery list has the slugs`)},{stop:js}),e}function wo({slug:t,html:o,directory:n=M(t,z),written:e=o,scriptNotes:s=[]}){let i=g(o),a=be(o);return{fix:[...Be(o,i),...Ze({html:o,directory:n,tree:i})],notes:[...ze(o,{written:e}),...Te(i),...vi({slug:t,tree:i,directory:n}),...a.notes,...s],readings:a.readings}}function Cr(t){let{fix:o,notes:n}=wo(t);return[...o,...n]}function Ir(t){let o=t.map(n=>[n.slug,wo(n)]);for(let[n,{fix:e}]of o)for(let s of e)console.log(`fix ${n}: ${s}`);for(let[n,{notes:e}]of o)for(let s of e)console.log(`note ${n}: ${s}`);for(let[n,{readings:e}]of o)for(let s of e)console.log(`chart ${n}: ${s}`)}async function Oi(t,{exportNote:o=!1}={}){for(let[n,e]of t){console.error(`
|
|
11
|
-
FAIL ${n}: ${e.length} problem${e.length===1?"":"s"}`);for(let i of e)console.error(` - ${i}`);let s=S.join(Tt,`${n}.html`);o&&await N.stat(s).then(()=>!0,()=>!1)&&console.error(` ${s} was not updated; it still holds an earlier export.`)}}function Ei(t,{above:o=!1,allow:n=process.argv.includes("--allow-failures")}={}){t.size!==0&&(console.error(`
|
|
12
|
-
${t.size} document${t.size===1?"":"s"} failed: ${[...t.keys()].join(", ")}${o?" (the failures are listed first, above)":""}`),n||(process.exitCode=1))}async function Fr(t,{exportNote:o=!1,allow:n}={}){await Oi(t,{exportNote:o}),Ei(t,{allow:n})}export{Qo as a,es as b,Ge as c,Ye as d,Ot as e,ii as f,uo as g,mo as h,gi as i,Tr as j,$i as k,wi as l,yi as m,Si as n,Lr as o,Ar as p,wo as q,Cr as r,Ir as s,Oi as t,Ei as u,Fr as v};
|
package/dist/chunk-QVWVFC5K.mjs
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{b as Q}from"./chunk-FQGQH4KM.mjs";import{a as b,b as J}from"./chunk-TX6JH7TR.mjs";import{a as X,b as _,c as B,i as G}from"./chunk-YXAUQPVK.mjs";import{a as Z,b as ee}from"./chunk-W7CXPCRV.mjs";import{c as V,d as Y,e as T}from"./chunk-B3VTYBYR.mjs";import"./chunk-LAE5NQ4B.mjs";import"./chunk-P2CAZPDP.mjs";import"./chunk-ITNLYXXV.mjs";import{b as N,f as A,g as H}from"./chunk-NSKUTQ5J.mjs";import{k as q}from"./chunk-QYKCJ7FG.mjs";import{b as I}from"./chunk-YZ5Z6H4W.mjs";import"./chunk-VACRB2NE.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-TDQP3DKQ.mjs";import{b as U,g as W}from"./chunk-5FRMCDPY.mjs";import"./chunk-E7VYDG2X.mjs";import"./chunk-NFIBI4IP.mjs";import"./chunk-W63L7367.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";import v from"node:fs/promises";import le from"node:os";import x from"node:path";import{IMPORT_EXT as se,kindOf as re}from"../browser/shared/import-types.mjs";import{reportsDirectory as M}from"../browser/shared/paths.mjs";import{documentDirectory as oe,documentFiles as S}from"../browser/shared/workspace.mjs";var ie=Object.values(se).flat().join(" "),E=m=>{let s=m.normalize("NFKD").replace(/[̀-ͯ]/g,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"");return/[a-z]{3}/.test(s)?s.length<=60?s:s.slice(0,61).replace(/-[^-]*$/,"")||s.slice(0,60):""},j=(m,s)=>`${m} ${s}${m===1?"":"s"}`;function ae(m,s,p){let n=(g,r=s)=>(r.match(g)??[]).length,f=n(/<ol class="doc-flow"/g,p),u=n(/<li id="fn-\d+"/g,p),w=[[n(/<section class="doc-section"/g),"section"],[n(/<h[2-4][\s>]/g),"heading"],[n(/<p[\s>]/g),"paragraph"],[n(/<(?:ul|ol)[\s>]/g),"list"],[n(/<table\b/g),"table"],[n(/class="doc-math-(?:inline|block)"/g,p),"formula"],[n(/<div class="doc-code"/g),"code block"],[n(/<figure class="doc-image"/g),"picture"],[f,"flow"],[u,"footnote"]].filter(([g])=>g>0).map(([g,r])=>j(g,r)),d=(m.raws?.length??0)-f-(u?1:0);return d>0&&w.push(`${j(d,"HTML block")} kept as written`),w}async function Fe(m){let{positional:s,options:p}=A({options:["--no-preview","--no-browser"],argv:m}),[n,f,u]=s;if(s.length<1||s.length>3||!n)throw new N("Name the file; then the slug and the title, if you choose them.");let w=re(n);if(!w)throw new N(`Not a kind of file gallery import takes: ${n} (${ie}).`);f!==void 0&&H(f);let d=x.resolve(n);await v.stat(d).then(a=>a.isFile(),()=>!1)||(console.error(`No such file: ${n}`),process.exit(1));let g=f!==void 0?await Q(f):null;g&&(console.error(g),process.exit(1));let r=x.basename(d),O=await v.mkdtemp(x.join(le.tmpdir(),"gallery-import-")),L,y,R;try{let a,$=[];if(w==="markdown")a=[{...await Y(d,O),from:r,children:[]}];else try{({pages:a,skipped:$}=await V([{file:d,name:r}],O))}catch(e){console.error(`${r} could not be read: ${e.message}`),process.exit(1)}a.length===0&&(console.error(`Nothing in ${r} could be read as a page${$.length?` (not taken: ${$.join(", ")})`:""}.`),process.exit(1)),u?.trim()&&(a[0]={...a[0],title:u.replace(/\s+/g," ").trim()});let C=new Map,D=ee({edits:{},reports:{},reportsDirectory:M});y=(await Z(a,{create:async(e,t,i,{lang:l})=>{let{directory:o}=await I(e,t,i,{blank:!0,lang:l});C.set(e,await v.readFile(S(o).html,"utf8"))},slugOf:(e,t)=>t===0&&f!==void 0?f:D.freeSlug(E(e.title)||E(e.from?.replace(/\.[^.]+$/,"")??"")||E(r.replace(/\.[^.]+$/,""))||"doc"),folderOf:e=>oe(e,M),fill:e=>T(e),place:(e,t)=>D.place(e,t)})).made;let K=[],P=(e,t)=>{K.push({page:e,depth:t});for(let i of e.children??[])P(i,t+1)};for(let e of a)P(e,0);let h=await Promise.all(K.map(async({page:e,depth:t},i)=>{let l=y[i],o=oe(l,M),c=S(o).html,k=await v.readFile(c,"utf8"),te=(await T({source:C.get(l),nodes:e.nodes,icon:e.icon,own:e.own})).replace(/<p>\u{E000}\d+\u{E001}<\/p>/gu,""),ne=W(U(k,{finish:q}).text);return{slug:l,depth:t,page:e,directory:o,htmlFile:c,made:ae(e,te,k),readOnly:ne}}));if(L={slug:y[0]},h.length===1){let[{page:e,directory:t,htmlFile:i,made:l,readOnly:o}]=h;if(console.log(`Created ${b(i)} and ${x.basename(S(t).json)} from ${r}`),console.log(`Title: ${e.title}`),console.log(`Made: ${l.length?l.join(", "):"nothing but the title"}${e.files.length?` (${j(e.files.length,"file")} in ${b(x.join(t,"assets"))})`:""}`),e.notes?.length){console.log(`Not brought as the file has it (${e.notes.length}):`);for(let c of e.notes)console.log(` ${c.line?`line ${c.line}: `:""}${c.text}`)}if(o.length){console.log(`Text the preview leaves read-only (${o.length}), by doc.html's lines as gallery check gives them:`);for(let c of o)console.log(` ${c}`)}}else{console.log(`Created ${j(h.length,"document")} from ${r} (each nested as in the file):`);for(let{slug:i,depth:l,page:o,htmlFile:c,made:k}of h)console.log(`${" ".repeat(l+1)}${i} ${o.title} ${b(c)}`),console.log(`${" ".repeat(l+2)}Made: ${k.length?k.join(", "):"nothing but the title"}${o.files.length?` (${j(o.files.length,"file")} in its assets/)`:""}`);let e=h.flatMap(({slug:i,page:l})=>(l.notes??[]).map(o=>` ${i}: ${o.line?`line ${o.line}: `:""}${o.text}`));e.length&&console.log(`Not brought as the file has it (${e.length}):
|
|
3
|
-
${e.join(`
|
|
4
|
-
`)}`);let t=h.flatMap(({slug:i,readOnly:l})=>l.map(o=>` ${i}: ${o}`));t.length&&console.log(`Text the preview leaves read-only (${t.length}), by doc.html's lines as gallery check gives them:
|
|
5
|
-
${t.join(`
|
|
6
|
-
`)}`)}$.length&&console.log(`Not taken from ${r} (${$.length}): ${$.join(", ")}`);for(let e of await J())console.log(e);R=`edit ${b(h[0].htmlFile)}${h.length>1?" (and the others)":""} into the document as \u5199\u4F5C\u504F\u597D asks.`}finally{await v.rm(O,{recursive:!0,force:!0})}let F=await G(L.slug,{skipped:B(p),command:`gallery import ${r}`});console.log(X(F,R)),console.log(`Hand in: gallery export ${y.join(" ")}, then gallery qa ${y.join(" ")}`);let z=await _(F,p);z&&console.log(z);for(let a of F)console.log(a)}export{Fe as run};
|
package/dist/chunk-QZY6Q64C.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{a as d,b as u}from"./chunk-TX6JH7TR.mjs";import{f as g,h as f}from"./chunk-NSKUTQ5J.mjs";import"./chunk-5L7RYZCL.mjs";import p from"node:fs/promises";import{fullAddress as S,namedPlace as k}from"../browser/shared/page-address.mjs";import{reportsDirectory as h}from"../browser/shared/paths.mjs";import{documentLinks as D,listReportSlugs as F,roleOf as N}from"../browser/shared/reports.mjs";import{documentDirectory as j,documentFiles as M,isSlugName as b}from"../browser/shared/workspace.mjs";import{rankReports as A}from"../browser/shared/search.mjs";async function L(){let l=(await F(h)).filter(b);return(await Promise.all(l.map(async e=>{let n=j(e,h),{html:i,json:r}=M(n),s=await p.stat(i).catch(()=>null);if(!s?.isFile()||await N(n)==="instructions")return null;let a=await p.readFile(r,"utf8").then(JSON.parse).catch(()=>({})),c=t=>typeof t=="string"?t.replace(/\s+/g," ").trim():"";return{slug:e,title:c(a.title)||e,description:c(a.description),edited:s.mtimeMs,file:i}}))).filter(Boolean)}var O=l=>{let o=new Date(l),e=n=>String(n).padStart(2,"0");return`${o.getFullYear()}-${e(o.getMonth()+1)}-${e(o.getDate())} ${e(o.getHours())}:${e(o.getMinutes())}`};async function q(l){let{positional:o}=g({argv:l}),e=o.join(" ").trim(),n=await L(),{links:i}=await D(),r=o.length===1?k(o[0],i):null,s=r&&r.slug!==o[0]?n.filter(({slug:t})=>t===r.slug):A(n,e),a=o.length===1&&s.length===0?await f(o[0]):null;for(let t of await u())console.log(t);let c=t=>`${t} document${t===1?"":"s"}`;if(a)console.log(a);else if(n.length===0)console.log('No documents yet: gallery new <slug> "<title>" makes one.');else if(s.length===0)console.log(`No document's title, description or slug holds ${e.split(/\s+/).map(t=>`"${t}"`).join(" or ")}: gallery list lists all ${n.length}.`);else{console.log(e?`${s.length} of ${c(n.length)}, the best match first:`:`${c(n.length)}, the one edited last first:`);for(let{slug:t,title:$,description:m,edited:w,file:y}of s)console.log(`${t} ${$}`),m&&console.log(` \u8BF4\u660E\uFF1A${m}`),console.log(` \u5730\u5740\uFF1A${S("",{slug:t},i)}`),console.log(` \u4E0A\u6B21\u7F16\u8F91\uFF1A${O(w)}`),console.log(` ${d(y)}`)}}export{q as run};
|
package/dist/chunk-TDQP3DKQ.mjs
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{B as Je,D as Qe,E as me,F as Et,I as Xe,J as tn,a as pe,e as Fe,f as Ee,g as Re,h as wt,i as he,j as Oe,k as Xt,l as Rt,m as De,n as Ve,o as At,p as Ne,q as Ge,r as $e,s as gt,t as Y,u as Le,v as Ye,w as We,x as Me,y as W,z as Ze}from"./chunk-NFIBI4IP.mjs";import{d as Tt}from"./chunk-W63L7367.mjs";import{b as ue,c as de,e as Ae}from"./chunk-A55HN5OK.mjs";import{BLOCK_TYPES as ve,COPIED_AS_ITSELF as zn,IDENTITY as gn}from"../browser/editor/components/registry.mjs";import{copyKeys as Un}from"../browser/editor/components/figure/index.mjs";import{accepts as ye,attributeValue as An,BLOCK_TYPES as Dt,boxRole as be,CHAPTER as En,holdsStraight as On,IDENTITY as Pe,isLead as rn,SIZES as Nn,sizeValue as ln,TOGGLES as an}from"../browser/editor/components/registry.mjs";import{iconMarkup as $n,iconValueOf as Ln,validIcon as Mn}from"../browser/editor/components/icon/index.mjs";Ae();import{attributeValue as bn,BLOCK_TYPES as en,HOSTS as xn,TOGGLES as wn}from"../browser/editor/components/registry.mjs";import{texSource as nn}from"../browser/editor/components/math/index.mjs";var je=new Set(Object.entries(en).filter(([,s])=>!s.box&&!s.bare).map(([s])=>s)),te=(s,m,w="")=>{let g=W[m.type]?.leaf;if(g)return g(s,m,w);let k=[s.className,...m.classes??[]].filter(Boolean).join(" ");return`<${s.tag}${k?` class="${k}"`:""}${he(m.attributes)}${w}>${m.html}</${s.tag}>`},Ce=(s,m)=>s===void 0||!!s&&typeof s=="object"&&!Array.isArray(s)&&Object.entries(s).every(([w,g])=>typeof g=="string"&&bn(m,w,g)),Te=s=>s?.empty===!0,Be=(s,m)=>s===void 0?null:w=>s.includes(m.slice(w.startOffset,w.endOffset));function ke(s,m,{empty:w=!1,file:g}={}){if(typeof m!="string"||!m.trim()&&!(w&&m===""))return!1;if(m==="")return!0;if(s.tex&&!nn(m))return!1;let k=s.inside??s.tag,O=`<${k}>${m}</${k}>`,[I,...a]=de(O,{sourceCodeLocationInfo:!0}).childNodes;return a.length===0&&I?.tagName===k&&me(I,[],s.inside!==void 0,{lists:k==="td"||k==="th",known:Be(g,O)})===null}var vn=new Set(Object.values(en).filter(s=>s.text&&s.className).map(s=>s.kind));function qe(s,m){if(s.keep?.reason==="script")return null;if(s.kind==="list")return m.some(g=>g.unit===s.id&&g.kind==="list")?"list":null;let w=W[s.kind];return w?.written?w.written(s)?"written":null:s.text===void 0||s.nested?null:["p","h1","h2","h3","h4","li"].includes(s.tag)||vn.has(s.kind)?"text":null}function ge(s,m,w){if(!Array.isArray(m)||!m.every(k=>Sn(s,k,w)))return"invalid";let g=m.filter(k=>k.keep);return g.length>1?"invalid":m.length>g.length&&!s.caps.split||g.length===0&&!s.caps.remove||m.length===0&&s.nested?"fixed":g.length===1&&g[0].html.trim()===""&&!s.caps.empty?"empty":null}function sn(s,m,w){let g=`<table><tbody><tr><${s}>${m}</${s}></tr></tbody></table>`,[k,...O]=de(g,{sourceCodeLocationInfo:!0}).childNodes,I=O.length===0&&k?.tagName==="table"&&k.childNodes.length===1?k.childNodes[0]:null,a=I?.childNodes.length===1?I.childNodes[0]:null,p=a?.childNodes.length===1?a.childNodes[0]:null;return p?.tagName===s&&me(p,[],!1,{lists:!0,known:Be(w,g)})===null}var on={p:"paragraph",h1:"heading",h2:"heading",h3:"heading",h4:"heading",li:"item"},In=(s,m)=>s.classes===void 0||!s.keep&&Array.isArray(s.classes)&&new Set(s.classes).size===s.classes.length&&s.classes.every(w=>(wn[on[m]]??[]).includes(w));function Sn(s,m,w){if(!m||typeof m.html!="string"||xn[s.kind]?.tex&&!nn(m.html))return!1;let g=m.keep?s.tag:m.tag;if(!m.keep&&Je[s.tag]!==g||!In(m,g)||m.attributes!==void 0&&(m.keep||!Ce(m.attributes,on[g])))return!1;let k=g==="td"||g==="th",O=k?`<table><tbody><tr><${g}>${m.html}</${g}></tr></tbody></table>`:`<${g}>${m.html}</${g}>`,[I,...a]=de(O,{sourceCodeLocationInfo:!0}).childNodes;if(a.length>0||!I)return!1;let p=I;if(k){let h=I.tagName==="table"&&I.childNodes.length===1?I.childNodes[0]:null,u=h?.childNodes.length===1?h.childNodes[0]:null;p=u?.childNodes.length===1?u.childNodes[0]:null}return p?.tagName===g&&me(p,[],Qe(s.kind,s.tag,s.caps),{lists:k,known:Be(w,O)})===null}import{attr as cn}from"../browser/shared/html-tree.mjs";import{pageLanguage as jn}from"../browser/shared/components/page.mjs";import{SHEETS as Cn}from"../browser/editor/components/kit.mjs";import{BLOCK_ID as Tn}from"../browser/shared/ids.mjs";function fn({current:s,edits:m,units:w=[],partial:g=!1,ids:k=!1,touch:O=[],proposals:I=null}){let a=Et(s),p=a.blocks,h=s.includes(`\r
|
|
3
|
-
`)?`\r
|
|
4
|
-
`:`
|
|
5
|
-
`,u=[],$=[],j=[],K=new Map,q=null,Z,yt=!1,J=(t,n)=>u.push({unit:t.id,reason:n}),X=t=>{let r=Rt(t).replace(/[0-9.]/g,l=>String.fromCharCode(l.charCodeAt(0)-65248)).replace(/[\s,,]/g,"").replace(/[−–]/g,"-").match(/-?\d+(?:\.\d+)?/)?.[0];return r===void 0?null:Number(r)},ct=(t,n,r)=>{if(t.kind!=="cell")return;let l=s.slice(t.start,t.innerStart),c=/\sdata-sort-value(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+)))?/.exec(l);if(!c)return;let d=(c[1]??c[2]??c[3]??"").trim(),x=/^-?\d+(\.\d+)?(e[-+]?\d+)?$/i.test(d)?Number(d):null,[S,f]=[X(s.slice(t.innerStart,t.innerEnd)),X(n)],b="";x!==null&&f!==null?b=` data-sort-value="${Number((f*(S?x/S:1)).toPrecision(12))}"`:x!==null&&S===null&&(b=c[0]),b!==c[0]&&$.push({start:t.start+c.index,end:t.start+c.index+c[0].length,text:b,of:[{id:r}]})},Vt=t=>{t.keep&&e(t)?J(t,"referenced"):j.push({start:t.start,end:t.end},...t.companion?[t.companion]:[])},ne=(t,n)=>{let r=t.classAttr,l=r?r.value.split(/\s+/).filter(Boolean):[],c=l;for(let[x,S]of n)c=S?c.includes(x)?c:[...c,x]:c.filter(f=>f!==x);if(c.join(" ")===l.join(" "))return;if(at(t),!r){let x=/^<[A-Za-z][\w-]*/.exec(s.slice(t.elStart,t.elStart+40));if(!x)return J(t,"unknown");let S=t.elStart+x[0].length;$.push({start:S,end:S,text:` class="${c.join(" ")}"`});return}if(c.length===0){$.push({...Xt(s,r.start,r.end),text:""});return}let d=/=\s*'/.test(s.slice(r.start,r.end))?"'":'"';$.push({start:r.start,end:r.end,text:`class=${d}${c.join(" ")}${d}`})},vt=typeof k=="function"?k:k?Xe:null,rt=new Set([...s.matchAll(tn)].map(t=>t[1]??t[2])),Bt=()=>{for(;;){let t=vt();if(!rt.has(t))return rt.add(t)&&t}},se=[],qt=[],Gt=t=>t?` ${Pe}="${t}"`:"",ie=t=>typeof t=="string"&&Tn.test(t)&&!rt.has(t),lt=(t,n)=>{let r=vt?ie(n)?(rt.add(n),n):Bt():null;return r&&t!==void 0&&qt.push({key:t,id:r}),Gt(r)},et=new Set,Pt=t=>{et.add(t.at);let n=I?.get(t.id),r=vt?ie(n)?(rt.add(n),n):Bt():null;return r&&se.push({at:t.at,id:r}),Gt(r)},at=t=>{if(!vt||!t||t.blockId||t.at===void 0||et.has(t.at))return;let n=Oe(s,t.at);$.push({start:n,end:n,text:Pt(t)})},Ot=t=>{let{element:n,source:r}=At(t.restore),l=n.sourceCodeLocation,c=cn(n,Pe);if(c&&!rt.has(c))return rt.add(c),t.key!==void 0&&qt.push({key:t.key,id:c}),r;let d=r,x=l.startTag.endOffset-1;if(c){let S=l.attrs[Pe],f=Xt(d,S.startOffset,S.endOffset);d=d.slice(0,f.start)+d.slice(f.end),x-=f.end-f.start}return x=Oe(d,x),d.slice(0,x)+lt(t.key,t.blockId)+d.slice(x)},pt=t=>{let n=null;for(let r of a.units)r.elStart<=t.start&&t.start<r.end&&(!n||r.elStart>n.elStart)&&(n=r);return n},P=new Set;for(let t of m){let{id:n,parts:r}=t??{},l=Number.isInteger(n)?p[n]:void 0;if(!l){u.push({id:n,reason:"unknown"});continue}if(Array.isArray(r)&&r.length===0&&l.self!==null&&a.units[l.self].keep){u.push({id:n,reason:"referenced"});continue}let c=ge(l,r,s);if(c){u.push({id:n,reason:c});continue}if(r.length===0){let N={...Le(s,l.start,l.end),of:[{id:n}]};$.push(N),K.set(n,N),l.self!==null&&P.add(l.self);continue}let d=Y(s,l.start),x=d===null?"":h+d,S=N=>`<${N.tag}${N.classes?` class="${N.classes.join(" ")}"`:""}${he(N.attributes)}${lt(N.key,N.blockId)}>${N.html}</${N.tag}>`,f=r.findIndex(N=>N.keep),b=pt(l),v=b&&b.at===l.innerStart-1;if((!v||l.tag==="li")&&at(b),l.tag==="li"&&f>=0){let N=r.slice(0,f),H=r.slice(f+1),z=b?{start:b.start,end:b.end}:null;$.push({start:l.innerStart,end:l.innerEnd,text:r[f].html,of:[{id:n}]}),N.length>0&&$.push({start:l.start,end:l.start,seq:1/0,text:N.map(S).join(x)+x,edge:z,of:[{id:n}]}),H.length>0&&$.push({start:l.end,end:l.end,text:x+H.map(S).join(x),edge:z,of:[{id:n}]})}else{let N=s.slice(l.start,l.innerStart);if(v&&vt&&!b.blockId&&!et.has(b.at)&&(N=`${N.slice(0,-1)}${Pt(b)}>`),r.length===1&&f===0&&N===s.slice(l.start,l.innerStart)){$.push({start:l.innerStart,end:l.innerEnd,text:r[0].html,of:[{id:n}]}),ct(l,r[0].html,n),l.kind==="title"&&(q={from:Rt(s.slice(l.innerStart,l.innerEnd)),to:Rt(r[0].html)});continue}let H=r.map(z=>z.keep?N+z.html+s.slice(l.innerEnd,l.end):S(z)).join(x);$.push({start:l.start,end:l.end,text:H,of:[{id:n}]})}l.kind==="title"&&(q={from:Rt(s.slice(l.innerStart,l.innerEnd)),to:Rt(r[0].html)})}let G=(t,n,r)=>{let l=a.units.filter(f=>f.box===t),c=[];for(let f=1;f<l.length;f++){let b=s.slice(l[f-1].end,l[f].start);b.trim()||c.push({pair:[l[f-1],l[f]],gap:b})}let d=c.find(({pair:f})=>f.includes(n))??c[0];if(d)return d.gap.replace(/\r?\n/g,h);let x=Y(s,r.start),S=be(a.boxes[t]?.kind)==="root"?h:"";return x===null?"":S+h+x},Yt=t=>{if(t.kind!=="nest"||Y(s,t.innerEnd)!==null)return null;let n=a.units[t.unit];return n?Y(s,n.elStart):null},Wt=(t,n)=>{let r=s.slice(t.at+1,t.innerEnd).match(/\n([ \t]*)\S/);return r?r[1]:`${n??""} `},zt=(t,n)=>n!==null&&be(t.kind)==="root",ft=[],Zt=(t,n,r,l)=>{let c=Number.isInteger(n?.into)?a.boxes[n.into]:null,d=Number.isInteger(n?.after),x=c?null:a.units[d?n.after:n?.before],S=c??(x?a.boxes[x.box]:null),f=H=>H>=t.start&&H<t.end;if(!S||!(ye(S.kind,Jt(t))||l===S.kind)||t.kind==="tab"&&S.id!==t.box||x&&(x===t||!r.has(x.id)||f(x.elStart))||c&&f(S.at))return J(t,"position");let b=Y(s,t.start);if(at(t),c){if(c.innerEnd===null)return J(t,"missing");let H=Yt(c);if(H!==null){ft.push({start:t.start,end:t.end,at:c.innerEnd,seq:o++,from:b,to:H+nt,wrap:_=>h+H+nt+_+h+H});return}let z=Y(s,c.innerEnd),ot=Wt(c,z),B=z!==null&&ot.startsWith(z)?ot.slice(z.length):" ",U=zt(c,z);ft.push({start:t.start,end:t.end,at:U?c.innerEnd-z.length:c.innerEnd,seq:o++,from:b,to:ot,wrap:_=>z===null?_:U?z+B+_+h:B+_+h+z});return}let v=G(x.box,x,x),N=d?v.includes(`
|
|
6
|
-
`)?v.slice(v.lastIndexOf(`
|
|
7
|
-
`)+1):null:Y(s,x.start);ft.push({start:t.start,end:t.end,at:d?x.end:x.start,seq:o++,from:b,to:N,wrap:H=>d?v+H:H+v})},ht=(t,n)=>t.classes===void 0||Array.isArray(t.classes)&&new Set(t.classes).size===t.classes.length&&t.classes.every(r=>(an[n.kind]??[]).includes(r)),Ut=(t,n)=>!Ze(t)&&(W[t.type]?.check?.(t)??!0)&&ht(t,n)&&Ce(t.attributes,n.kind),_t=(t,n,r={})=>ke(t,n,{...r,file:s}),Ht=(t,n)=>{if(it.has(t.id))return;let r=Dt[n?.type],l=qe(t,a.boxes);if(!(l==="text"||l==="written"&&r?.kind!==t.kind)||!je.has(n?.type)||!ke(r,n.html,{empty:Te(r),file:s}))return J(t,"invalid");if(!dt.has(t.id)&&!mt.has(t.id)&&!ye(a.boxes[t.box].kind,r.kind))return J(t,"position");if(!Ut(n,r))return J(t,"invalid");let c=t.blockId?Gt(t.blockId):Pt(t);et.add(t.at);let d=l==="written"&&t.node?Fe(s,t.node,W[t.kind].attribute):t.carried;$.push({start:t.elStart,end:t.end,text:te(r,n,d+c)})},oe=(t,n)=>{if(it.has(t.id))return;let r=W[t.kind]?.rewrite;if(!r)return J(t,"invalid");let l=r(s,t.node,n,{validCell:(c,d)=>sn(c,d,s),get packages(){return Tt().packages}});if(!l)return J(t,"invalid");at(t),$.push(...[l].flat())},re=(t,n)=>{if(qe(t,a.boxes)!=="list"||n!=="ul"&&n!=="ol")return J(t,"invalid");let r=/^<(ul|ol)\b/i.exec(s.slice(t.elStart,t.elStart+3)),l=/<\/(ul|ol)\s*>$/i.exec(s.slice(t.elStart,t.end));if(!r||!l)return J(t,"unknown");if(r[1].toLowerCase()===n)return;at(t);let c=t.end-l[0].length+2;$.push({start:t.elStart+1,end:t.elStart+3,text:n},{start:c,end:c+2,text:n})},Kt=new Set([...s.matchAll(/\sid\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/gi)].map(t=>t[1]??t[2]??t[3])),Nt=new Map,$t=new Set,nt=/\n(\t|[ ]+)</.exec(s)?.[1]??" ",bt=(t,n)=>{let r=d=>ye(n,d)||t?.stood===n;if(t?.restore!==void 0){let d=At(t.restore),x=d?.kind==="item"?Ee(d.element,n):d?.kind;if(!d||!r(x))return!1;if(t.children===void 0)return!0;let S=Dt[t.type];return On(S)&&S.kind===x&&t.children.every(f=>bt(f,S.box))}if(t?.unit!==void 0){let d=Number.isInteger(t.unit)?a.units[t.unit]:void 0;return!d||$t.has(d.id)||it.has(d.id)||dt.has(d.id)||P.has(d.id)||d.kind==="tab"||!r(Jt(d))?!1:($t.add(d.id),!0)}let l=Dt[t?.type];if(!l||!r(l.kind))return!1;if(t.type==="divider")return!0;if(t.type==="icon")return Mn(t.icon);let c=W[t.type];return l.bare&&c?.check?c.check(t,{validLeaf:_t,usedIds:Kt})&&ht(t,l):l.box?!Array.isArray(t.children)||t.children.length===0&&!c?.empty||!ht(t,l)||c?.check&&!c.check(t,{validLeaf:_t,usedIds:Kt})?!1:t.children.every(d=>bt(d,l.box)):!je.has(t.type)||!ke(l,t.html,{empty:Te(l),file:s})||!Ut(t,l)?!1:t.children===void 0?!0:Array.isArray(t.children)&&c?.children?.(t,bt)===!0},Q=(t,n)=>{if(t.unit!==void 0){let b=Nt.get(t.unit);return gt(F(b),b.from,n)}if(t.restore!==void 0&&t.children===void 0)return gt(Ot(t),"",n);let r=Dt[t.type];if(t.type==="divider")return`<hr${lt(t.key,t.blockId)}>`;if(t.type==="icon")return $n(t.icon,lt(t.key,t.blockId));let l=n===null?null:n+nt,c=(b,v,N,H=n,z=l)=>z===null?b+v.join("")+N:b+v.map(ot=>h+z+ot).join("")+h+H+N,d=b=>t.children.map(v=>Q(v,b));if(t.restore!==void 0){let b=Ot(t),{element:v}=At(b),{startTag:N,endTag:H}=v.sourceCodeLocation,z=v.childNodes.findLastIndex(B=>B.tagName),ot=v.childNodes.slice(z+1).filter(B=>B.nodeName==="#comment").map(({sourceCodeLocation:{startOffset:B,endOffset:U}})=>gt(b.slice(B,U),Y(b,B),l));return c(gt(b.slice(0,N.endOffset),"",n),[...d(l),...ot],H?b.slice(H.startOffset):`</${r.tag}>`)}let x={get id(){return lt(t.key,t.blockId)},get language(){return jn(s)},idOf:b=>lt(b.key,b.blockId),render:(b,v)=>Q(b,v),indent:n,inner:l,step:nt,block:c,children:d,deep:b=>n===null?null:n+nt.repeat(b)},S=W[t.type]?.write;if(r.bare&&S)return S(t,x);if(!r.box)return t.children?S(t,x):te(r,t,lt(t.key,t.blockId));if(S)return S(t,x);let f=[r.className,...t.classes??[]].filter(Boolean).join(" ");return c(`<${r.tag}${f?` class="${f}"`:""}${lt(t.key,t.blockId)}>`,d(l),`</${r.tag}>`)},st=[],le=t=>{let{insert:n,place:r}=t,l=B=>u.push({unit:t.id,reason:B}),c=n?.restore!==void 0?At(n.restore):null;if(n?.type==="icon"||c?.kind==="icon"){let B=Number.isInteger(r?.into)?a.boxes[r.into]:null,U=B?null:a.units[Number.isInteger(r?.after)?r.after:r?.before],_=B??(U?a.boxes[U.box]:null);if(rn(_?.kind,"icon")){if(!bt(n,_.kind))return l("invalid");if(_.innerEnd===null)return l("missing");let kt=a.units.find(Ke=>Ke.box===_.id&&Ke.kind!=="icon"),Qt=kt?kt.start:_.innerEnd,Ct=Y(s,Qt);st.push({at:Qt,seq:o++,text:()=>Q(n,Ct)+(Ct===null?"":h+Ct)});return}if(!bt(n,"header"))return l("invalid");let tt=p.find(kt=>kt.kind==="title");if(!tt)return l("missing");let xt=Y(s,tt.start);st.push({at:tt.start,seq:o++,text:()=>Q(n,xt)+(xt===null?"":h+xt)}),Z=c?Ln(c.source):n.icon;return}if(n?.type==="tab"||c?.kind==="tab")return Lt(t,c,l);let d=Number.isInteger(r?.into)?a.boxes[r.into]:null,x=Number.isInteger(r?.after),S=d?null:a.units[x?r.after:r?.before],f=d??(S?a.boxes[S.box]:null),b=n?.restore!==void 0?At(n.restore):null,v=b?f&&b.kind==="item"?Ee(b.element,f.kind):b.kind:Dt[n?.type]?.kind;if(!f||!v||!(ye(f.kind,v)||n.stood===f.kind)||S&&!jt.has(S.id))return l("position");let N=new Set($t);if(!bt(n,f.kind))return l("invalid");for(let B of $t){if(N.has(B))continue;let U=a.units[B];at(U);let _={start:U.start,end:U.end,at:null,from:Y(s,U.start)};Nt.set(B,_),ft.push(_)}if(d){if(d.innerEnd===null)return l("missing");let B=Yt(d);if(B!==null){st.push({at:d.innerEnd,seq:o++,text:()=>h+B+nt+Q(n,B+nt)+h+B});return}let U=Y(s,d.innerEnd),_=Wt(d,U),tt=U!==null&&_.startsWith(U)?_.slice(U.length):nt,xt=a.units.filter(Ct=>Ct.box===d.id),kt=be(d.kind)==="root"&&En.has(v)&&(xt.some(Ct=>jt.has(Ct.id))||!d.pure&&(xt.length>0||n.restore!==void 0))?h:"",Qt=zt(d,U);st.push({at:Qt?d.innerEnd-U.length:d.innerEnd,seq:o++,text:()=>U===null?Q(n,null):Qt?kt+U+tt+Q(n,_)+h:tt+Q(n,_)+h+U});return}let H=x?S.end:S.start;if(be(f.kind)==="root"){let B=G(S.box,S,S),U=x?B.includes(`
|
|
8
|
-
`)?B.slice(B.lastIndexOf(`
|
|
9
|
-
`)+1):null:Y(s,S.start);st.push({at:H,seq:o++,text:()=>x?B+Q(n,U):Q(n,U)+B});return}let z=Y(s,S.start),ot=z===null?"":h+z;st.push({at:H,seq:o++,text:()=>x?ot+Q(n,z):Q(n,z)+ot})},Lt=({insert:t,place:n},r,l)=>{let c=Number.isInteger(n?.after),d=a.units[c?n.after:n?.before];if(d?.kind!=="tab"||!jt.has(d.id))return l("position");if(!bt(t,"tabs"))return l("invalid");let x=d.companion,S=a.units[d.parent??-1];if(!x||!S)return l("missing");let f=r?cn(r.element,Cn.tabKey):t.sheet,b=s.slice(S.start,S.end);if(b.includes(`data-sheet-tab="${f}"`)||b.includes(`data-doc-sheet="${f}"`))return l("invalid");let v=Y(s,d.start),N=Y(s,x.start),H=(_,tt)=>_===null?tt:c?h+_+tt:tt+h+_,z=()=>r?gt(Ot(t),"",v):We({...t,sheet:f},lt(t.key,t.blockId)),ot=()=>{if(r)return gt(r.panel,"",N);let _=`<div data-doc-sheet="${f}">`;if(t.children.length===0)return N===null?`${_}</div>`:`${_}${h}${N}</div>`;let tt=N===null?null:N+nt,xt=t.children.map(kt=>Q(kt,tt));return tt===null?_+xt.join("")+"</div>":_+xt.map(kt=>h+tt+kt).join("")+h+N+"</div>"};st.push({at:c?d.end:d.start,seq:o++,text:()=>H(v,z())});let B=c?/^\s*/.exec(s.slice(x.end))[0]:/\s*$/.exec(s.slice(0,x.start))[0],U=N!==null&&/\n[ \t]*\r?\n/.test(B)?h:"";st.push({at:c?x.end:x.start,seq:o++,text:()=>c?U+H(N,ot()):H(N,ot())+U})},Ie=(t,n)=>{let r=t.node?.sourceCodeLocation;if(t.at===void 0||!r)return J(t,"unknown");at(t),$.push(...Me(s,r.startTag,[["style",l=>Ve(l?.value??"",n)||null]]))},D=(t,n)=>{let r=t.node?.sourceCodeLocation;if(t.at===void 0||!r)return J(t,"unknown");at(t),$.push(...Me(s,r.startTag,n))},Mt=new Map,ut=new Map,It=new Map,it=new Set(w.filter(t=>t?.remove===!0).map(t=>t.id)),dt=new Set(w.filter(t=>t?.move).map(t=>t.id)),mt=new Map,ae=(t,n)=>n?.unit!==void 0?mt.set(n.unit,t.id):Array.isArray(n?.children)&&n.children.forEach(r=>ae(t,r));w.forEach(t=>ae(t,t?.insert));let ce=new Map(w.filter(t=>Number.isInteger(t?.id)&&t.replace).map(t=>[t.id,t.replace])),Jt=t=>Dt[ce.get(t.id)?.type]?.kind??t.kind,jt=new Set(a.units.map(t=>t.id).filter(t=>!it.has(t)&&!dt.has(t)&&!mt.has(t)&&!P.has(t))),fe=a.units.filter(t=>dt.has(t.id)||mt.has(t.id)),Se=(t,n)=>r=>n.some(l=>l!==t&&t.start<=l.start&&l.end<=t.end&&l.start<=r&&r<l.end),e=t=>!!t.keep&&!t.keep.at.every(Se(t,fe)),i=(t,n)=>{let r=[$,j,ft,st],l=r.map(c=>c.length);n(),r.forEach((c,d)=>c.slice(l[d]).forEach(x=>x.of??=t))},o=0;for(let t of w){let{id:n,remove:r,toggle:l,on:c,move:d,size:x,value:S,attribute:f,stood:b}=t??{},v=Number.isInteger(n)?a.units[n]:void 0;i([{unit:n}],()=>{if(t?.insert&&typeof n=="string")le(t);else if(v&&t.replace){let N=u.length;Ht(v,t.replace),u.length>N&&ce.delete(v.id)}else v&&t.retag?re(v,t.retag):v&&(t.table||t.source)?oe(v,t.table??t.source):v&&r===!0?e(v)?u.push({unit:n,reason:"referenced"}):v.kind==="tab"&&a.units.every(N=>N.box!==v.box||it.has(N.id))?u.push({unit:n,reason:"last"}):(v.kind==="icon"&&!rn(a.boxes[v.box]?.kind,"icon")&&(yt=!0),Vt(v)):v&&d&&typeof d=="object"&&!it.has(n)?P.has(n)||Zt(v,d,jt,b):v&&typeof c=="boolean"&&(an[v.kind]??[]).includes(l)?(Mt.get(v)??Mt.set(v,new Map).get(v)).set(l,c):v&&Nn[v.kind]?.[x]&&(S===null||ln(v.kind,x,S)!==null)?it.has(n)||(ut.get(v)??ut.set(v,new Map).get(v)).set(x,S===null?null:ln(v.kind,x,S)):v&&typeof f=="string"&&An(v.kind,f,S)?it.has(n)||(It.get(v)??It.set(v,new Map).get(v)).set(f,S):u.push({unit:n,reason:x===void 0&&f===void 0?"unknown":"invalid"})})}let y=new Set(u.map(t=>t.unit).filter(t=>t!==void 0)),M=t=>(it.has(t.id)||dt.has(t.id)||mt.has(t.id))&&!y.has(mt.get(t.id)??t.id);for(let t of a.boxes){if(!["list","quote"].includes(t.kind)||!t.pure||t.unit===null)continue;let n=a.units[t.unit];if(!n||it.has(n.id)||dt.has(n.id)||mt.has(n.id))continue;let r=a.units.filter(c=>c.box===t.id);if(r.length===0||!r.every(M))continue;let l=c=>!!c&&(c.into===t.id||[n,...r].some(d=>c.after===d.id||c.before===d.id));w.some(c=>l(c?.insert?c.place:c?.move))||Vt(n)}for(let[t,n]of Mt)i([{unit:t.id}],()=>ne(t,n));for(let[t,n]of ut)i([{unit:t.id}],()=>Ie(t,n));for(let[t,n]of It)i([{unit:t.id}],()=>D(t,n));for(let t of O)at(a.units[t]);let E=new Set([...K.keys()].map(t=>p[t].wrapper).filter(Boolean));for(let t of E){let n=t.ids.map(r=>K.get(r));n.some(r=>!r)||j.some(r=>r.start<=t.start&&t.end<=r.end)||(n.forEach(r=>r.skip=!0),$.push({...Le(s,t.start,t.end),of:t.ids.map(r=>({id:r}))}))}if(q&&q.from!==q.to){let t=De(s,q);q.synced=!!t,t&&$.push(t)}else q=null;let L=new Map;for(let t of j){let n=`${t.start}:${t.end}`;L.has(n)?L.get(n).of=[...L.get(n).of??[],...t.of??[]]:L.set(n,t)}j.splice(0,j.length,...L.values());let A=(t,n)=>{t.of?.length||u.push({reason:n});for(let r of t.of??[])u.push({...r,reason:n})},C=(t,n,r)=>n===r?t.start<n&&n<t.end:t.start<=n&&r<=t.end,R=(t,n,r,l=null)=>{let c=null;for(let d of ft){let x=l!==null&&d.start===l.start&&d.end===l.end;d!==r&&(x||C(d,t,n))&&(!c||d.start>=c.start)&&(c=d)}return c},V=(t,n,r,l=null)=>{let c=R(t,n,r,l);return j.some(d=>d!==r&&C(d,t,n)&&!(c&&C(d,c.start,c.end)))},T=new Set,F=t=>{if(T.has(t))return A(t,"position"),"";T.add(t);try{return St(t)}finally{T.delete(t)}},St=t=>{let[n,r]=t?[t.start,t.end]:[0,s.length],l=(f,b,v=null,N=null)=>R(f,b,v,N)===t&&!V(f,b,v,N),c=[];for(let f of[...j,...ft].filter(b=>b!==t&&l(b.start,b.end,b)).sort((b,v)=>b.start-v.start)){let b=c.at(-1);b&&(f.start<=b.end||!s.slice(b.end,f.start).trim())?(b.end=Math.max(b.end,f.end),b.of.push(...f.of??[])):c.push({start:f.start,end:f.end,of:[...f.of??[]]})}let d=[...$.filter(f=>!f.skip&&l(f.start,f.end,null,f.edge??null)).map(f=>({...f,seq:f.seq??-2})),...c.map(f=>({...Ye(s,f.start,f.end),seq:-1,of:f.of})),...[...ft.filter(f=>f.at!==null),...st].filter(f=>l(f.at,f.at,f)).map(f=>({start:f.at,end:f.at,seq:f.seq,text:f.text?f.text():f.wrap(gt(F(f),f.from,f.to)),of:f.of}))].sort((f,b)=>f.start-b.start||f.end-f.start-(b.end-b.start)||f.seq-b.seq),x=[];for(let f of d)x.length>0&&f.start<x.at(-1).end?A(f,"overlap"):x.push(f);let S=s.slice(n,r);for(let f of x.reverse())S=S.slice(0,f.start-n)+f.text+S.slice(f.end-n);return S},Ft=F(null);if(u.length>0&&!g)return{ok:!1,conflicts:u};let He=Z??(yt?null:void 0);return{ok:u.length===0,text:Ft,version:pe(Ft),ids:{assigned:se,created:qt},...q?{title:q}:{},...He!==void 0?{icon:He}:{},...g?{conflicts:u}:{}}}import{attr as yn}from"../browser/shared/html-tree.mjs";import{outsideKey as _n}from"../browser/shared/ids.mjs";Ae();import{commonPrefix as un,commonSuffix as dn,mergeText as pn}from"../browser/editor/page/merge.mjs";var ee=new Map;function xe(s){let m=ee.get(s);if(m)return m;let w=/data-block-id/i.test(s)?Re(s,[ue(s,{sourceCodeLocationInfo:!0})]):[],g="",k=0,O=0,I=[];for(let p of w)g+=s.slice(k,p.start),k=p.end,O+=p.end-p.start,I.push({at:g.length,end:p.end,removed:O});g+=s.slice(k);let a={text:g,at:p=>p-(I.findLast(h=>h.end<=p)?.removed??0),source:p=>p+(I.findLast(h=>h.at<=p)?.removed??0)};for(ee.set(s,a);ee.size>4;)ee.delete(ee.keys().next().value);return a}function ze(s,m,w,g=w.start){let[k,O]=[xe(s),xe(m)],I=k.at(w.start),a=k.text.slice(I,k.at(w.end)),p=K=>O.source(K+k.at(g)-I),h=K=>{let q=[];for(let Z=K.indexOf(a);Z>=0;Z=K.indexOf(a,Z+1))q.push(Z);return q},u=h(O.text);if(u.length<=1&&h(k.text).length<=1)return u.length===1?p(u[0]):-1;let $=k.text.slice(Math.max(0,I-120),I),j=u.filter(K=>O.text.slice(Math.max(0,K-$.length),K)===$);return j.length===1?p(j[0]):u.length>1?-2:-1}function Ue(s,m,w,g){let[O,I]=[xe(s),xe(m)],[a,p]=[O.at(w.start),O.at(w.end)],h=O.text.slice(Math.max(0,a-400),a),u=O.text.slice(p,p+400),$=g.filter(q=>q.tag===w.tag).map(q=>{let[Z,yt]=[I.at(q.start),I.at(q.end)];return{other:q,score:dn(h,I.text.slice(Math.max(0,Z-400),Z))+un(u,I.text.slice(yt,yt+400))}}).sort((q,Z)=>Z.score-q.score),[j,K]=$;return j&&j.score>=40&&j.score-(K?.score??0)>=20?j.other:null}function hn(s,m){let w=p=>p.replace(/<[^>]*>/g," ").replace(/&(?:[a-z]+|#\d+);/gi," ").replace(/\s+/g," ").trim(),g=w(s),k=w(m);if(!g||!k)return!g&&!k;if(g.length<2||k.length<2)return g===k;let O=p=>{let h=new Map;for(let u=0;u<p.length-1;u++)h.set(p.slice(u,u+2),(h.get(p.slice(u,u+2))??0)+1);return h},I=O(k),a=0;for(let[p,h]of O(g))a+=Math.min(h,I.get(p)??0);return 2*a/(g.length-1+k.length-1)>=.5}Ae();import{IDENTITY as Bn}from"../browser/editor/components/registry.mjs";import{escapeAttribute as qn}from"../browser/shared/escape.mjs";import{attr as mn}from"../browser/shared/html-tree.mjs";import{CHART_DATA as _e,CHART_SOURCE as we,nextChartKey as Pn}from"../browser/shared/table-chart.mjs";function kn(s,m){if(m.size===0||!s.includes(we))return{text:s,keys:{}};let w=[],g=(a,p)=>{for(let h of a.childNodes??[]){if(!h.tagName)continue;let u=p||m.has(mn(h,Bn));for(let $ of[_e,we]){let j=mn(h,$);j!==void 0&&w.push({name:$,key:j,made:u,at:h.sourceCodeLocation?.attrs?.[$]??null})}g(h.tagName==="template"?h.content:h,u)}};g(ue(s,{sourceCodeLocationInfo:!0}),!1);let k=new Set(w.map(({key:a})=>a)),O={};for(let a of new Set(w.filter(p=>p.made&&p.name===we).map(p=>p.key))){let p=w.filter(u=>u.key===a&&!u.made),h=w.some(u=>u.key===a&&u.made&&u.name===_e);h&&p.length>0?(O[a]=Pn(k),k.add(O[a])):!h&&p.some(u=>u.name===we)&&(O[a]=null)}return{text:w.filter(({name:a,key:p,made:h,at:u})=>h&&u&&Object.hasOwn(O,p)&&!(O[p]===null&&a===_e)).map(({name:a,key:p,at:h})=>O[p]===null?{...Xt(s,h.startOffset,h.endOffset),put:""}:{start:h.startOffset,end:h.endOffset,put:`${a}="${qn(O[p])}"`}).sort((a,p)=>p.start-a.start).reduce((a,{start:p,end:h,put:u})=>a.slice(0,p)+u+a.slice(h),s),keys:O}}function Hn({current:s,opening:m=null,texts:w=[],units:g=[],touch:k=[],ids:O=!0,seal:I=null,pageIds:a=null}){let p=Et(s),h=typeof m=="string"?Et(m):null,u=e=>s.slice(e.innerStart,e.innerEnd),$=null,j=e=>($??=new Map(p.units.map(i=>[i.id,wt(s,i)]))).get(e.id),K=new Map,q=new Set,Z=new Map,yt=new Set(Array.isArray(a)?a.filter(e=>typeof e=="string"):[]),J=(e,i,o=!0,y=[])=>{let M=F=>!!F.blockId&&yt.has(F.blockId)&&!y.includes(F.blockId),E=yt.size>0?p.units.filter(F=>!M(F)):p.units,L=typeof i=="string"?E.filter(F=>j(F)===i):[],A=e>=0?h?.units[e]:void 0,C=A&&L.length>1?h.units.filter(F=>!M(F)&&wt(m,F)===i):[];if(L.length===1)return{unit:L[0]};if(C.length===L.length&&C.includes(A))return{unit:L[C.indexOf(A)]};if(!A)return L.length>1?{reason:"ambiguous"}:{gone:!0};let R=ze(m,s,A,A.elStart),V=R>=0?E.find(F=>F.elStart===R):null;if(V)return{unit:V};if(R===-2||L.length>1)return{reason:"ambiguous"};if(!o)return{gone:!0};let T=Ue(m,s,A,E);return T&&hn(m.slice(A.start,A.end),s.slice(T.start,T.end))?{unit:T,changed:!0}:{gone:!0}},X=e=>{if(!e||typeof e.key!="number"&&typeof e.key!="string")return{reason:"invalid"};if(K.has(e.key))return K.get(e.key);let i,o=typeof e.blockId=="string"?p.units.filter(y=>y.blockId===e.blockId):[];if(o.length===1&&typeof e.id!="string")i={unit:o[0]};else if(typeof e.id=="string"){let y=p.units.filter(M=>M.blockId===e.id);i=y.length===1?{unit:y[0]}:y.length>1?{reason:"ambiguous"}:Number.isInteger(e.open)&&typeof e.openHash=="string"?J(e.open,e.openHash,!1,[e.id]):{gone:!0}}else Number.isInteger(e.open)?i=J(e.open,e.hash,!0,[e.blockId]):i={reason:"invalid"};return i.unit&&!i.unit.blockId&&typeof e.blockId=="string"&&Z.set(i.unit.id,e.blockId),K.set(e.key,i),i.unit&&ct(e,i)&&q.add(e.key),i},ct=(e,i)=>i.changed||e.hash===null||typeof e.hash=="string"&&j(i.unit)!==e.hash,Vt=new Set(p.units.map(e=>e.blockId).filter(Boolean)),ne=[],vt=e=>e?.restore!==void 0?yn(At(e.restore?.source)?.element??{},gn)??e.blockId:e?.blockId,rt=e=>{let i=vt(e);if(typeof i=="string"&&Vt.has(i))return!0;let o=ve[e?.type];return!!o?.keyed&&typeof e.id=="string"&&p.boxes.some(y=>y.kind===o.box&&y.key===e.id)},Bt=e=>{let i=vt(e);e?.key!==void 0&&typeof i=="string"&&Vt.has(i)&&ne.push({key:e.key,id:i}),Array.isArray(e?.children)&&e.children.forEach(Bt)},se=(e,i)=>{let o=ve[i?.type];return!!o&&s.slice(e.elStart,e.end)===te(o,i,(e.carried??"")+(e.blockId?` ${gn}="${e.blockId}"`:""))},qt=(e,i,o)=>Array.isArray(e)&&Array.isArray(i)&&e.length===i.length&&e[0]===i[0]&&e.slice(1).every((y,M)=>y[0]===i[M+1]?.[0]&&y[1]===i[M+1][1]&&(!o||y[2]===i[M+1][2])),Gt=e=>{if(!e||typeof e.before!="string")return{reason:"invalid"};let i=o=>({block:o,changed:u(o)!==e.before});if(e.title){let o=p.blocks.filter(y=>y.kind==="title");return o.length===1?i(o[0]):{reason:o.length?"ambiguous":"missing"}}if(e.unit){let o=X(e.unit);if(!o.unit)return{reason:o.gone?"missing":o.reason};let y=p.blocks.filter(L=>L.unit===o.unit.id);if(e.self){let L=y.find(A=>A.self===o.unit.id);return L?i(L):{reason:"missing"}}let M=y.find(L=>qt(L.path,e.path,!1));if(M&&qt(M.path,e.path,!0))return i(M);let E=y.filter(L=>u(L)===e.before);return E.length===1?i(E[0]):{reason:W[o.unit.kind]?.textParts&&!ct(e.unit,o)?"package":"structure"}}if(Number.isInteger(e.open)||e.outside){let o=p.blocks.filter(A=>A.unit===null&&A.kind!=="title"&&u(A)===e.before);if(o.length===1)return i(o[0]);let y=Number.isInteger(e.open)?h?.blocks[e.open]:null;if(!y||o.length>1)return{reason:o.length>1?"ambiguous":"missing"};let M=ze(m,s,y),E=M>=0?p.blocks.find(A=>A.start===M):null;if(E)return i(E);let L=M===-2?null:Ue(m,s,y,p.blocks.filter(A=>A.unit===null));return L?i(L):{reason:M===-2?"ambiguous":"missing"}}return{reason:"invalid"}},ie=e=>{if(e?.main)return p.boxes.find(o=>o.kind==="main")??null;if(e&&!e.unit&&typeof e.kind=="string")return p.boxes.find(o=>o.unit===null&&o.kind===e.kind&&(o.key??null)===(e.key??null))??null;let i=e?.unit?X(e.unit):null;return i?.unit?p.boxes.find(o=>o.unit===i.unit.id&&o.kind===e.kind&&(o.key??null)===(e.key??null))??null:null},lt=[],et=e=>{e&&typeof e=="object"&&(typeof e.key=="number"||typeof e.key=="string")&<.push(e)},Pt=e=>{e?.unit!==void 0&&et(e.unit),e?.copy!==void 0&&et(e.copy),e?.children?.forEach(Pt)},at=e=>{et(e?.after),et(e?.before),et(e?.into?.unit)};for(let e of w)et(e?.block?.unit);for(let e of g)et(e?.unit),at(e?.place),at(e?.move),Pt(e?.insert);k.forEach(et);let Ot=new Map;for(let e of lt){let i=X(e);i.unit&&(Ot.get(i.unit)??Ot.set(i.unit,[]).get(i.unit)).push({key:e.key,changed:!!i.changed})}for(let e of Ot.values())if(!(new Set(e.map(i=>i.key)).size<2))for(let i of e)i.changed&&K.set(i.key,{gone:!0});let pt=new Map,P=new Map,G=(e,i,o,y={})=>e.set(i,{key:i,status:"conflict",reason:o,...y}),Yt=new Map,Wt=(e,i,o,y)=>{let M=L=>{for(let A=L.unit;A!=null;A=i.units[A]?.parent)if(A===o.id)return!0;return!1};if(!y)return{hash:wt(e,o),theirs:i.blocks.filter(M).map(L=>e.slice(L.innerStart,L.innerEnd)).join(`
|
|
10
|
-
`)};let E=L=>Object.fromEntries(y.filter(A=>typeof L?.[A]=="string").map(A=>[A,L[A]]));return{theirs:E(W[o.kind]?.dataOf?.(e,o.node,Tt().packages)??{}),parts:E(o.parts)}},zt=(e,i,o=null,y={})=>{Yt.set(e,{unit:i,held:o}),G(P,e,"changed",{...Wt(s,p,i,o),...y})},ft=[],Zt=new Map;for(let e of w){let{key:i,block:o}=e??{},y=e?.parts,M=Array.isArray(y)?y.filter(A=>!A?.keep):[];M.some(rt)&&(M.forEach(Bt),y=y.filter(A=>A?.keep||!rt(A)));let E=Gt(o);if(!E.block){E.reason==="missing"&&Array.isArray(y)&&!y.some(A=>A?.keep)&&y.every(rt)?pt.set(i,{key:i,status:"applied"}):G(pt,i,E.reason);continue}let L=Array.isArray(y)&&y.length===1&&y[0]?.keep&&typeof y[0].html=="string"?y[0].html:null;if(E.changed&&L!==null&&L===u(E.block))pt.set(i,{key:i,status:"applied"});else if(E.changed){let A=L===null?null:pn(o.before,L,u(E.block));if(A===null||ge(E.block,[{keep:!0,html:A}],s)){G(pt,i,"changed",{theirs:u(E.block)});continue}y=[{keep:!0,html:A}],pt.set(i,{key:i,status:"merged",html:A})}else pt.set(i,{key:i,status:"applied"});Zt.set(E.block.id,i),ft.push({id:E.block.id,parts:y})}let ht=[],Ut=new Map,_t=(e,i)=>Ut.set(e,[...Ut.get(e)??[],i]),Ht={},oe=e=>{if(e?.into){let y=ie(e.into);return y?{into:y.id}:null}let i=!!e?.after,o=X(i?e.after:e?.before);return o?.unit?{[i?"after":"before"]:o.unit.id}:null},re=null,Kt=e=>{if(e?.unit!==void 0){let y=X(e.unit);return y.unit?{unit:y.unit.id,stood:e.stood}:null}if(e?.restore!==void 0){let{source:y,seal:M}=e.restore??{};if(!I||typeof y!="string"||M!==I(y))return null;let E=Array.isArray(e.children)?e.children.map(Kt):void 0;return E?.includes(null)?null:{restore:y,key:e.key,blockId:e.blockId,stood:e.stood,...E?{type:e.type,children:E}:{}}}if(e?.copy!==void 0){let y=X(e.copy),M=e.keys===void 0?null:Un(e.keys);return e.keys!==void 0&&!M?null:y.unit&&zn.has(y.unit.kind)?{restore:$e(s,y.unit,{keys:M,taken:re??=new Set(Ne(s))}),key:e.key,blockId:e.blockId}:null}if(!e||typeof e!="object")return null;let i=W[e.type]?.source;if(i){let y=E=>$e(E,{start:0,end:E.length},{taken:re??=new Set(Ne(s))}),M=i(e,{packages:Tt().packages,written:y});return M?{restore:M,key:e.key,blockId:e.blockId}:null}let o=Array.isArray(e.children)?e.children.map(Kt):void 0;return o?.includes(null)?null:{...e,...o?{children:o}:{}}},Nt=new Set,$t=e=>[...Nt].filter(i=>i!==e&&[e,e.companion].some(o=>o&&o.start<=i.start&&i.end<=o.end)),nt=e=>{if(e?.unit!==void 0){let i=X(e.unit);i.unit&&Nt.add(i.unit)}else Array.isArray(e?.children)&&e.children.forEach(nt)};for(let e of g)e?.move?nt({unit:e.unit}):e?.insert&&nt(e.insert);let bt=(e,i)=>{let o=p.boxes.filter(E=>E.unit===e.id),y=new Map(i.map(E=>[X(E).unit,E])),M=p.units.filter(E=>o.some(L=>L.id===E.box));return o.every(E=>E.pure)&&M.length>0&&M.every(E=>Nt.has(E)||y.has(E)&&!ct(y.get(E),{unit:E}))},Q=new Set,st=e=>{if(e?.unit!==void 0){let i=X(e.unit);i.unit&&Q.add(i.unit)}else Array.isArray(e?.children)&&e.children.forEach(st)},le=[],Lt=new Map;for(let e of g){let i=e?.key;if(e?.insert&&rt(e.insert)){Bt({...e.insert,key:e.insert.key??i}),P.set(i,{key:i,status:"applied"});continue}if(e?.insert){let C=Kt({...e.insert,key:e.insert.key??i}),R=oe(e.place);if(!C||!R){G(P,i,!C&&W[e.insert.type]?.source?W[e.insert.type].unwritten(e.insert,{packages:Tt().packages}):"position");continue}P.set(i,{key:i,status:"applied"}),_t(i,i),ht.push({id:i,insert:C,place:R}),st(e.insert);continue}let o=X(e?.unit);if(e?.force===!0&&o.gone&&typeof e.hash=="string"&&typeof e.unit.id!="string"){let C=Number.isInteger(e.unit.open)&&e.unit.open>=0?h?.units[e.unit.open]:void 0;o=!h||h.units.some(V=>V!==C&&wt(m,V)===e.hash)?{reason:"ambiguous"}:J(-1,e.hash,!1,[e.unit.blockId]),o.unit&&!o.unit.blockId&&typeof e.unit.blockId=="string"&&Z.set(o.unit.id,e.unit.blockId),K.set(e.unit.key,o)}if(e?.source&&o.gone&&typeof e.unit.id=="string"&&e.parts&&typeof e.parts=="object"){let C=Object.entries(e.parts).filter(([,V])=>typeof V=="string"),R=C.length>0?p.units.filter(V=>V.parts&&!yt.has(V.blockId)&&C.every(([T,F])=>V.parts[T]===F)):[];R.length===1&&(o={unit:R[0]},R[0].blockId||Z.set(R[0].id,e.unit.id),K.set(e.unit.key,o),ct(e.unit,o)&&q.add(e.unit.key))}let y=typeof e?.size=="string"||typeof e?.toggle=="string"||typeof e?.attribute=="string",M=e?.remove===!0&&Array.isArray(e.items)&&e.force!==!0&&!!o.unit&&ct(e.unit,o)&&bt(o.unit,e.items);if(e?.remove===!0&&Array.isArray(e.items)&&e.force!==!0&&!M&&(o.gone||o.unit&&ct(e.unit,o))){let C=e.items.map(T=>({ref:T,found:X(T)})),R=C.find(T=>!T.found.unit&&!T.found.gone),V=C.filter(T=>T.found.unit&&!Nt.has(T.found.unit));if(R)G(P,i,R.found.reason);else if(V.some(T=>ct(T.ref,T.found)))o.unit?zt(i,o.unit):G(P,i,"changed");else if(V.some(T=>Lt.has(T.found.unit)))G(P,i,"ambiguous");else{P.set(i,{key:i,status:"applied"});for(let{ref:T,found:F}of V)Lt.set(F.unit,T.key),_t(F.unit.id,i),ht.push({id:F.unit.id,remove:!0})}continue}if(!o.unit){o.gone&&(e?.remove===!0||y)?P.set(i,{key:i,status:"applied"}):G(P,i,o.gone?"missing":o.reason);continue}if(e.replace&&se(o.unit,e.replace)){P.set(i,{key:i,status:"applied"});continue}if(e.source){let C=W[o.unit.kind]?.definition?.(o.unit.node,Tt().packages);if(typeof C!="string"||C!==e.definition){G(P,i,"definition");continue}}if(e.table&&W[o.unit.kind]?.definition){G(P,i,"invalid");continue}let E=e.source;if(e.source&&typeof e.source=="object"&&(e.force===!0||ct(e.unit,o))){let C=e.force===!0||!o.changed,R=St=>C&&St.every(Ft=>typeof e.parts?.[Ft]=="string"&&e.parts[Ft]===o.unit.parts?.[Ft]),V=Kn(e.source,e.together),T=V.filter(R).flat(),F=V.filter(St=>!R(St)).flat();if(F.length>0){if(zt(i,o.unit,F,T.length>0?{wrote:T}:{}),T.length===0)continue;E=Object.fromEntries(T.map(St=>[St,e.source[St]]))}}else if((e.remove===!0||e.replace||e.table)&&!M&&(e.force===!0?j(o.unit)!==e.hash:ct(e.unit,o))){zt(i,o.unit);continue}let L=E!==e.source;if(Lt.has(o.unit)&&Lt.get(o.unit)!==e.unit.key){G(P,i,"ambiguous");continue}Lt.set(o.unit,e.unit.key);let A=null;if(e.remove===!0){A={remove:!0};let{unit:C}=o,R=C.companion?Ge(s,C):gt(s.slice(C.start,C.end),Y(s,C.start),"");Ht[i]={source:R,seal:I?I(R):null,...$t(C).length>0?{around:!0}:{}}}else if(e.move){let C=oe(e.move);if(!C){G(P,i,"position");continue}A={move:C,stood:e.stood}}else e.replace?A={replace:e.replace}:typeof e.retag=="string"?A={retag:e.retag}:e.table&&typeof e.table=="object"?A={table:e.table}:E&&typeof E=="object"?A={source:E}:typeof e.toggle=="string"?A={toggle:e.toggle,on:e.on}:typeof e.size=="string"?A={size:e.size,value:e.value}:typeof e.attribute=="string"&&(A={attribute:e.attribute,value:e.value});if(!A){G(P,i,"unknown");continue}L||P.set(i,{key:i,status:"applied"}),_t(o.unit.id,i),ht.push({id:o.unit.id,...A}),A.move&&Q.add(o.unit),A.remove&&le.push({key:i,unit:o.unit})}for(let{key:e,unit:i}of le)$t(i).every(o=>Q.has(o))||(G(P,e,"position"),delete Ht[e],ht.splice(ht.findIndex(o=>o.id===i.id&&o.remove),1));let Ie=[...new Set(k.map(X).filter(e=>e.unit).map(e=>e.unit.id))],D=fn({current:s,edits:ft,units:ht,partial:!0,ids:O,touch:Ie,proposals:Z}),Mt=kn(D.text,new Set((D.ids?.created??[]).map(({id:e})=>e)));D.text=Mt.text;for(let e of D.conflicts??[]){e.id!==void 0&&Zt.has(e.id)&&G(pt,Zt.get(e.id),e.reason);for(let i of Ut.get(e.unit)??[])G(P,i,e.reason),delete Ht[i]}let ut=Et(D.text),It=new Map,it=new Map(D.ids.assigned.map(({at:e,id:i})=>[e,i]));for(let[e,i]of K){let o=i.unit?i.unit.blockId??it.get(i.unit.at):null;o&&It.set(e,o)}for(let[e,{unit:i,held:o}]of Yt){let y=i.blockId??it.get(i.at),M=y?ut.units.filter(E=>E.blockId===y):[];M.length===1&&P.get(e)?.reason==="changed"&&Object.assign(P.get(e),Wt(D.text,ut,M[0],o))}let dt=new Map([...ne,...D.ids.created].map(({key:e,id:i})=>[e,i])),mt=new Set([...It.values(),...dt.values()]),ae=new Set(ut.units.map(e=>e.blockId).filter(Boolean)),ce=[...mt].filter(e=>!ae.has(e)),Jt=new Map,jt=new Map,fe=e=>{let o=(Array.isArray(e?.children)?e.children.map(fe).some(Boolean):!1)||[e?.unit,e?.copy].some(y=>y!==void 0&&q.has(y?.key));return e?.key!==void 0&&jt.set(e.key,o),o};for(let e of g)e?.insert&&fe({...e.insert,key:e.insert.key??e.key});for(let[e,i]of[...It,...[...dt].filter(([o])=>jt.get(o)!==!0)]){if(q.has(e))continue;let o=ut.units.filter(y=>y.blockId===i);o.length===1&&Jt.set(e,wt(D.text,o[0]))}let Se=g.filter(e=>ve[e?.insert?.type]?.keyed&&typeof e.insert.id=="string"&&P.get(e.key)?.status==="applied").map(e=>({key:e.insert.id,box:ve[e.insert.type].box}));return{text:D.text,version:pe(D.text),texts:[...pt.values()],units:[...P.values()],ids:Object.fromEntries(It),made:Object.fromEntries(dt),hashes:Object.fromEntries(Jt),removed:Ht,gone:ce,file:Dn(D.text,ut,mt,new Set(dt.values())),outside:Rn(D.text,ut),keyed:Fn(D.text,ut,Se),...Object.keys(Mt.keys).length>0?{chartKeys:Mt.keys}:{},...D.title?{title:D.title}:{},...D.icon!==void 0?{icon:D.icon}:{}}}function Kn(s,m){let w=[];for(let g of[...Array.isArray(m)?m:[],...Object.keys(s).map(k=>[k])]){let k=Array.isArray(g)?g.filter(I=>typeof I=="string"&&Object.hasOwn(s,I)):[],O=w.filter(I=>k.some(a=>I.includes(a)));if(k.length!==0){for(let I of O)w.splice(w.indexOf(I),1);w.push([...new Set([...O.flat(),...k])])}}return w}function Fn(s,m,w){let g={};for(let{key:k,box:O}of w){let I=m.boxes.find(a=>a.kind===O&&a.key===k);I&&(g[k]={units:m.units.filter(a=>a.box===I.id).map(a=>a.blockId??{hash:wt(s,a)})})}return g}function Rn(s,m){let w={};for(let g of m.blocks){let k=g.unit===null?_n(g.kind==="title",yn(g.node,"id")):null;k&&(w[k]=s.slice(g.innerStart,g.innerEnd))}return w}function Dn(s,m,w,g){let k=new Map;for(let a of m.units)a.blockId&&k.set(a.blockId,(k.get(a.blockId)??0)+1);let O=a=>{for(let p=a.parent;p!=null;p=m.units[p].parent)if(g.has(m.units[p].blockId))return!0;return!1},I={};for(let a of m.units){if(!a.blockId||k.get(a.blockId)!==1||!(w.has(a.blockId)||O(a)))continue;let p=a.parent===null?null:m.units[a.parent];I[a.blockId]={kind:a.kind,hash:wt(s,a),keep:a.keep??null,...a.grid?{grid:!0}:{},...a.parts?{parts:a.parts}:{},parent:p?p.blockId??"":null,boxes:m.boxes.filter(h=>h.unit===a.id).map(h=>({kind:h.kind,key:h.key,units:m.units.filter(u=>u.box===h.id).map(u=>u.blockId??{hash:wt(s,u)})})),blocks:m.blocks.filter(h=>h.unit===a.id).map(h=>({...h.self!==null?{self:!0}:{path:h.path},kind:h.kind,caps:Object.keys(h.caps),inner:s.slice(h.innerStart,h.innerEnd),...h.atoms.length>0?{atoms:h.atoms}:{}})),...W[a.kind]?.definition&&(g.has(a.blockId)||O(a))?{markup:s.slice(a.elStart,a.end)}:{}}}return I}function Rs({current:s,units:m=[]}){let w=Et(s),g=[];for(let k of m){if(typeof k?.id!="string"||typeof k.key!="string"&&typeof k.key!="number")continue;let O=w.units.filter(a=>a.blockId===k.id);if(O.length===0){g.push({key:k.key,gone:!0});continue}if(O.length>1||k.from===void 0||k.from===k.parent||k.from===""||k.parent==="")continue;(O[0].parent===null?null:w.units[O[0].parent].blockId??"")===k.from&&g.push({key:k.key,moved:!0})}return g}function Ds({current:s,instances:m=[],pageIds:w=null}){let g=Et(s),k=new Set(Array.isArray(w)?w.filter(I=>typeof I=="string"):[]),O=[];for(let I of m){if(typeof I?.id!="string"||typeof I.key!="string"&&typeof I.key!="number"||!I.parts||typeof I.parts!="object")continue;let a=j=>Object.entries(I.parts).filter(([K,q])=>typeof j.parts?.[K]=="string"&&j.parts[K]!==q?.after&&Array.isArray(q?.before)&&q.before.includes(j.parts[K])),p=g.units.filter(j=>j.blockId===I.id),h=p.length===0?g.units.filter(j=>j.parts&&!k.has(j.blockId)&&a(j).length>0):[],u=p.length===1?p[0]:h.length===1?h[0]:null,$=u?a(u):[];$.length>0&&O.push({key:I.key,parts:Object.fromEntries($.map(([j])=>[j,u.parts[j]])),markup:s.slice(u.elStart,u.end)})}return O}function Vs({current:s,opening:m=null,texts:w=[],pageIds:g=null}){let k=w.filter(u=>typeof u?.block?.before=="string"&&typeof u.original=="string").map(u=>({entry:u,was:new Set([u.original,...Array.isArray(u.earlier)?u.earlier.filter($=>typeof $=="string"):[]].filter($=>$!==u.block.before))})).filter(({was:u})=>u.size>0),O=u=>Hn({current:s,opening:m,ids:!1,pageIds:g,texts:u.map(({entry:{key:$,block:j}})=>({key:$,block:j,parts:[{keep:!0,html:j.before}]}))}).texts,I=O(k),a=new Set(I.filter(u=>u.reason==="overlap").map(u=>u.key)),p=[...I.filter(u=>!a.has(u.key)),...k.filter(({entry:u})=>a.has(u.key)).flatMap(u=>O([u]))],h=new Map(k.map(({entry:u,was:$})=>[u.key,$]));return p.filter(u=>u.status==="merged"&&h.get(u.key)?.has(u.html)).map(({key:u,html:$})=>({key:u,theirs:$}))}export{fn as a,Hn as b,Rs as c,Ds as d,Vs as e};
|
package/dist/chunk-V4CPWKMZ.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{b as p,d as m,e as u,f,g as d}from"./chunk-XINNG4F2.mjs";import{j as n}from"./chunk-NSKUTQ5J.mjs";import{k as i,s as a,v as c}from"./chunk-QMQUXTU4.mjs";import{reportsDirectory as g}from"../browser/shared/paths.mjs";import{documentDirectory as $,documentFiles as y}from"../browser/shared/workspace.mjs";var k=()=>`No documents in ${g} yet: gallery new <slug> "<title>" makes one.`;async function A(w){let{slugs:e,options:h}=await n({options:["--allow-failures"],argv:w,noneIsAll:!0});e.length===0&&(console.error(k()),process.exit(1)),await p(e),await f(e),await d(e);let{reports:r,failures:t}=await i(e,{prepare:m()}),s=r.filter(o=>!t.has(o.slug));for(let o of s)console.log(`OK ${o.slug}`);for(let o of e)y($(o,g)).both&&console.log(`note ${o}: both doc.html and report.html: report.html is not read`);a(r),u(r);let l=s.length+t.size;console.log(`Checked ${l} document${l===1?"":"s"}: ${s.length} passed, ${t.size} failed.`),await c(t,{allow:h.has("--allow-failures")})}export{k as a,A as b};
|
package/dist/chunk-VACRB2NE.mjs
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{a as m,b as G,c as J}from"./chunk-HYMEEXKN.mjs";import w from"node:fs";import k from"node:path";import je from"node:zlib";import{escapeAttribute as I}from"../browser/shared/escape.mjs";import{componentOf as M,instancesOf as Ee,partOf as q}from"../browser/shared/components/index.mjs";import{ICON_COLOR_VALUES as Y,TAB_ICON as Q,glyphOf as ee,iconKind as j,iconUrl as te,iconValueOf as P,tabIconValue as Ce}from"../browser/shared/emoji/icon-value.mjs";import{mediaTypeOf as se,mediaUrl as De}from"../browser/shared/media.mjs";import{emojiDataDirectory as Re,reportsDirectory as oe}from"../browser/shared/paths.mjs";import{slugPattern as Te}from"../browser/shared/reports.mjs";import{documentDirectory as ne}from"../browser/shared/workspace.mjs";var N=Re,X=String.fromCodePoint(65039),Z=null,B=null;function Me(){return Z??={positions:JSON.parse(w.readFileSync(k.join(N,"positions.json"),"utf8")),index:JSON.parse(w.readFileSync(k.join(N,"twemoji-index.json"),"utf8")),svg:je.gunzipSync(w.readFileSync(k.join(N,"twemoji-svg.bin")))},Z}function re(e){let{positions:t,index:s,svg:n}=Me(),o=[e,e.replaceAll(X,""),`${e}${X}`].find(i=>t[i]),r=o&&s[t[o][0]];return r?n.subarray(r[0],r[0]+r[1]):null}function ie(e){let t=re(e);return t?`data:image/svg+xml;base64,${t.toString("base64")}`:null}function es(e){return E(""),[...B.keys()].filter(t=>t.startsWith(`${e}/`)).map(t=>t.slice(e.length+1))}function E(e,t="currentColor"){B??=new Map(JSON.parse(w.readFileSync(k.join(N,"icons.json"),"utf8")).icons.flatMap(([,o,r,i,a])=>[[`mingcute/${o}`,i],[`tabler/${r}`,a]].filter(([,c])=>c)));let s=ee(e),n=s&&B.get(`${s.set}/${s.name}`);return n?n.split("#COLOR").join(t).replace("<svg ",'<svg aria-hidden="true" '):null}function Ie(e){let[t,s]=Y[ee(e)?.color]??Y.gray,n=E(e);return n&&n.replace(/<svg\b[^>]*>/,o=>`${o.replace(/ aria-hidden="true"/,"").replace(/^<svg /,'<svg xmlns="http://www.w3.org/2000/svg" ').replace(/ xmlns="http:\/\/www\.w3\.org\/2000\/svg"(?=.* xmlns=)/,"")}<style>svg{color:${t}}@media (prefers-color-scheme:dark){svg{color:${s}}}</style>`)}function Be({value:e,slug:t=null,tab:s=!1,reportsDirectory:n=oe}){let o=j(e);if(o==="emoji"){let i=re(e);return i&&{type:"image/svg+xml",body:i}}if(o==="glyph"){let i=s?Ie(e):E(e,"#000");return i&&{type:"image/svg+xml",body:Buffer.from(i)}}if(o!=="image"||!t||!Te.test(t))return null;let r=k.join(ne(t,n),e);return w.existsSync(r)?{type:se(e),body:w.readFileSync(r)}:null}var ae=/(<div\b[^>]*\bclass="doc-icon"[^>]*>)([\s\S]*?)(<\/div>)/g;function ts(e,{slug:t,mode:s="export",reportsDirectory:n=oe}){return He(Ae(e,{mode:s}).replace(ae,(o,r,i,a)=>{let c=P(o),l=j(c);if(!l)return o;let f=null;if(l==="emoji"){let d=ie(c);f=d&&`<img alt="${I(c)}" src="${d}">`}else if(l==="glyph")f=E(c);else if(s==="preview")f=`<img src="${De("asset",t,c)}" alt="">`;else{let d=k.join(ne(t,n),c),p=w.existsSync(d)?w.readFileSync(d):null;f=p&&`<img src="data:${se(c)};base64,${p.toString("base64")}" alt="">`}let u=s==="preview"?r.replace(/>$/,` data-ge-icon="${I(c)}">`):r;return f?`${u}${f}${a}`:`${u}${i}${a}`}),ze(_e(e),{slug:t,mode:s,reportsDirectory:n}))}var ce=e=>[...e.matchAll(ae)].flatMap(t=>{let s=j(P(t[0]))==="image"?/<img\b[^>]*\bsrc="/.exec(t[2]):null;return s?[t.index+t[1].length+s.index]:[]}),Pe=/<button\b[^>]*\bdata-tab-icon="([^"]*)"[^>]*>/g;function Ae(e,{mode:t="export"}={}){return e.replace(Pe,(s,n)=>{if(j(n)!=="emoji"||s.includes(Q))return s;let o=t==="preview"?te(n):ie(n);if(!o)return s;let r=`${Q}: ${Ce(o)}`;return/\sstyle="/.test(s)?s.replace(/\sstyle="([^"]*)"/,(i,a)=>` style="${a.replace(/;?\s*$/,"; ")}${r}"`):s.replace(/>$/,` style="${r}">`)})}function Ue(e){let t=q(e,M("page").header)[0];return{all:Ee(e,M("icon")),own:t?q(t,M("icon").match):[]}}function _e(e){let[t]=Ue(m(e)).own;return t?P(G(e,t)):null}function ze(e,{slug:t,mode:s,reportsDirectory:n}){if(!e)return null;if(s==="preview")return te(e,t,{tab:!0});let o=Be({value:e,slug:t,tab:!0,reportsDirectory:n});return o&&`data:${o.type};base64,${Buffer.from(o.body).toString("base64")}`}var He=(e,t)=>t&&/<\/head>/i.test(e)&&!e.includes("data-doc-tab-icon")?e.replace(/<\/head>/i,()=>` <link rel="icon" href="${I(t)}" data-doc-tab-icon>
|
|
3
|
-
</head>`):e;import Ze from"node:fs";import et from"node:path";import{reportsDirectory as tt}from"../browser/shared/paths.mjs";import{assetFile as st,assetProblem as ot,embedFile as nt}from"../browser/shared/media.mjs";import{attr as le,hasClass as rt,walk as it}from"../browser/shared/html-tree.mjs";import fe from"node:fs";import We from"node:path";import{attr as Ve,hasClass as Ke,walk as Ge}from"../browser/shared/html-tree.mjs";import{MEDIA_ROUTES as Je,mediaTypeOf as qe,mediaUrl as Ye}from"../browser/shared/media.mjs";import{documentDirectory as Qe}from"../browser/shared/workspace.mjs";function x(e,t,s){let n=null;return Ge(e,o=>{!n&&o.tagName===t&&Ke(o,s)&&(n=o)}),n}function A(e,t){let s=We.join(e,t);return fe.statSync(s,{throwIfNoEntry:!1})?.isFile()?`data:${qe(t)};base64,${fe.readFileSync(s).toString("base64")}`:null}function Xe(e,{attribute:t,route:s,slug:n,mode:o,reportsDirectory:r}){if(!Je[s](e))return null;if(o==="preview")return`${t}="${Ye(s,n,e)}" data-ge-${t}="${e}"`;let i=A(Qe(n,r),e);return i&&`${t}="${i}"`}function S(e,t,{attribute:s,route:n,slug:o,mode:r,reportsDirectory:i}){let a=t.map(f=>({place:f.sourceCodeLocation?.attrs?.[s],value:Ve(f,s)})).filter(({place:f})=>f).sort((f,u)=>f.place.startOffset-u.place.startOffset),c=[],l=0;for(let{place:f,value:u}of a){let d=Xe(u,{attribute:s,route:n,slug:o,mode:r,reportsDirectory:i});d===null||f.startOffset<l||(c.push(e.slice(l,f.startOffset),d),l=f.endOffset)}return c.push(e.slice(l)),c.join("")}function U(e){let t=[];return it(e,s=>{let n=s.tagName==="figure"&&rt(s,"doc-embed")?x(s,"iframe","doc-embed-frame"):null;n&&t.push(n)}),t}function gs(e,{slug:t,mode:s="export",reportsDirectory:n=tt}){return e.includes("doc-embed")?S(e,U(m(e)),{attribute:"src",route:"embed",slug:t,mode:s,reportsDirectory:n}):e}var de=(e,t=m(e))=>U(t).map(s=>s.sourceCodeLocation.startOffset);function $s({html:e,directory:t,tree:s=m(e)}){let n=[];for(let o of U(s)){let r=`line ${o.sourceCodeLocation.startLine}`,i=le(o,"src")??"",a=le(o,"sandbox"),c=/^https:\/\/[^\s"]+$/.test(i),l=!c&&!/^[a-z][a-z0-9+.-]*:/i.test(i)&&!st(i)?ot(i):null;l?n.push(`${r}: an embed's frame (${i.slice(0,80)}): ${l} (an HTML or PDF file; or a web page, https://\u2026)`):!c&&!nt(i)?n.push(`${r}: an embed's frame (${i.slice(0,80)}) shows a web page (https://\u2026, never http) or an HTML or PDF file of the document's folder (assets/<file>)`):!c&&!Ze.existsSync(et.join(t,i))?n.push(`${r}: the embed's file ${i} is not in the document's folder`):(c||/\.html?$/i.test(i))&&a===void 0?n.push(`${r}: an embed's frame (${i.slice(0,80)}) is sandboxed: sandbox="allow-scripts allow-popups \u2026"`):!c&&/\.html?$/i.test(i)&&/\ballow-same-origin\b/.test(a)?n.push(`${r}: an embedded HTML file (${i}) keeps its own origin: its sandbox has no allow-same-origin`):!c&&/\.pdf$/i.test(i)&&a!==void 0&&n.push(`${r}: an embedded PDF (${i}) is sandboxed, and a sandboxed frame shows no PDF: take its sandbox attribute off`)}return[...new Set(n)]}import at from"node:fs";import ct from"node:path";import{reportsDirectory as ft}from"../browser/shared/paths.mjs";import{assetFile as lt,assetProblem as dt}from"../browser/shared/media.mjs";import{attr as ue,hasClass as ut,walk as pt}from"../browser/shared/html-tree.mjs";function C(e,t=m(e)){let s=[];return pt(t,n=>{n.tagName==="figure"&&ut(n,"doc-file")&&s.push({node:n,link:x(n,"a","doc-file-link")})}),s}function Fs(e,{slug:t,mode:s="export",reportsDirectory:n=ft}){if(!e.includes("doc-file"))return e;let o=C(e).flatMap(({link:r})=>r?[r]:[]);return S(e,o,{attribute:"href",route:"file",slug:t,mode:s,reportsDirectory:n})}function Ls({html:e,directory:t,tree:s=m(e)}){let n=[];for(let{link:o}of C(e,s)){if(!o)continue;let r=`line ${o.sourceCodeLocation?.startLine}`,i=ue(o,"href")??"";lt(i)?at.existsSync(ct.join(t,i))||n.push(`${r}: the file block's file ${i} is not in the document's folder`):n.push(`${r}: a file block's file (${i.slice(0,80)}): ${dt(i)} (<a class="doc-file-link" href="assets/<file>" download="<name>">)`),ue(o,"download")||n.push(`${r}: a file block's link (${i.slice(0,80)}) says the name to save it as: download="<name>"`)}return[...new Set(n)]}import mt from"node:fs";import ht from"node:path";import{reportsDirectory as gt}from"../browser/shared/paths.mjs";import{assetProblem as pe,imageFile as me}from"../browser/shared/media.mjs";import{attr as _,hasClass as $t,walk as z}from"../browser/shared/html-tree.mjs";var bt={"doc-image":"image","doc-bookmark":"bookmark"},wt={image:"an image's picture",bookmark:"a bookmark's icon or cover"},yt=/doc-(?:image|bookmark|link-mention-icon)/;function he(e){let t=[];return z(e,s=>{let n=s.tagName==="figure"&&(_(s,"class")??"").split(/\s+/).map(o=>bt[o]).find(Boolean);n&&t.push({node:s,kind:n})}),t}function D(e,t=m(e)){let s=new Map,n=(o,r,i)=>{let a=o.sourceCodeLocation;a&&!s.has(a.startOffset)&&s.set(a.startOffset,{at:a.startOffset,line:a.startLine,node:o,what:r,kind:i,mention:i==="mention"})};for(let{node:o,kind:r}of he(t))z(o,i=>i.tagName==="img"&&n(i,wt[r],r));return z(t,o=>o.tagName==="img"&&$t(o,"doc-link-mention-icon")&&n(o,"a link's icon","mention")),[...s.values()].sort((o,r)=>o.at-r.at)}function Is(e,{slug:t,mode:s="export",reportsDirectory:n=gt}){return yt.test(e)?S(e,D(e).map(({node:o})=>o),{attribute:"src",route:"asset",slug:t,mode:s,reportsDirectory:n}):e}function Bs({html:e,directory:t,tree:s=m(e)}){let n=[];for(let{line:o,node:r,what:i,mention:a}of D(e,s)){let c=_(r,"src");a&&!me(c)?n.push(`line ${o}: a link's icon (${(c??"").slice(0,80)}): ${pe(c,{picture:!0})}; or write an empty <span class="doc-link-mention-icon"></span>`):c===void 0?n.push(`line ${o}: ${i} has no src: <img src="assets/<file>" alt="\u2026">`):me(c)?mt.existsSync(ht.join(t,c))||n.push(`line ${o}: ${i} ${c} is not in the document's folder`):n.push(`line ${o}: ${i} (${c.slice(0,80)}): ${pe(c,{picture:!0})}`)}for(let{node:o,kind:r}of he(s)){let i=r==="bookmark"?x(o,"a","doc-bookmark-card"):null,a=i&&_(i,"href");i&&!/^https?:\/\/[^\s"]+$/.test(a??"")&&n.push(`line ${i.sourceCodeLocation?.startLine}: a bookmark's link (${(a??"").slice(0,80)}) is a web address: <a class="doc-bookmark-card" href="https://\u2026">`)}return[...new Set(n)]}import Se from"node:fs";import Oe from"node:path";import{escapeAttribute as F}from"../browser/shared/escape.mjs";import{attr as O,hasClass as kt,walk as xt}from"../browser/shared/html-tree.mjs";import{cssReferences as ge}from"../browser/shared/css-references.mjs";import{assetFile as St,assetProblem as Ot,imageFile as vt,mediaUrl as Ft,referencedFile as L}from"../browser/shared/media.mjs";import{reportsDirectory as Lt}from"../browser/shared/paths.mjs";import{documentDirectory as Nt}from"../browser/shared/workspace.mjs";var $e=/^\s*(?:\.\/)?assets\//i,be=1e6;function jt(e){let t=[],s=0;for(;s<e.length;){for(;s<e.length&&/[\s,]/.test(e[s]);)s++;if(s>=e.length)break;let n=s;for(;n<e.length&&!/\s/.test(e[n]);)n++;let o=e.slice(s,n),r="";if(o.endsWith(","))o=o.replace(/,+$/,""),s=n;else{let a=n;for(let c=0;a<e.length&&(e[a]!==","||c>0);a++)e[a]==="("?c++:e[a]===")"&&c--;r=e.slice(n,a).trim(),s=a+1}let i=r.split(/\s+/).find(a=>/^\d*\.?\d+[wx]$/i.test(a));t.push({url:o,descriptor:r,size:i?parseFloat(i):1,wide:/w$/i.test(i??"")})}return t}function Et(e){let t=e.filter(s=>s.wide);return(t.length>0?t:e).reduce((s,n)=>!s||n.size>s.size?n:s,null)}var Ct=new Set(["body","table","thead","tbody","tfoot","tr","td","th"]);function W(e,t,s=n=>$e.test(n)){let n=[],o=r=>{s(r.value,r.node)&&n.push({...r,value:r.value.trim(),written:r.css?.written})};return xt(t,r=>{let i=r.sourceCodeLocation;if(i){for(let{name:a,value:c,prefix:l}of r.attrs){let f=l?`${l}:${a}`:a,u=i.attrs?.[f],d={node:r,how:a,key:f,place:u,line:u?.startLine??i.startLine};if(a==="src"||a==="href"||a==="poster"||a==="data"&&r.tagName==="object"||a==="background"&&Ct.has(r.tagName))o({...d,value:c});else if(a==="srcset"){let p=jt(c),y=Et(p.filter(b=>$e.test(b.url)));p.forEach((b,h)=>o({...d,value:b.url,candidates:p,index:h,largest:b===y}))}else if(a==="style")for(let p of ge(c))o({...d,value:p.value,css:p})}if(r.tagName==="style")for(let a of r.childNodes){if(a.nodeName!=="#text"||!a.sourceCodeLocation)continue;let{startOffset:c,endOffset:l}=a.sourceCodeLocation;for(let f of ge(e.slice(c,l)))o({node:r,how:"css",value:f.value,line:J(e,c+f.index),css:{...f,offset:c}})}}}),n}function ve(e,t){let s=new Map;for(let{at:n,kind:o}of D(e,t))s.set(n,{attribute:"src",owner:"block",icon:o!=="image"});for(let{link:n}of C(e,t))n&&s.set(n.sourceCodeLocation.startOffset,{attribute:"href",owner:"block"});for(let n of de(e,t))s.set(n,{attribute:"src",owner:"block"});for(let n of ce(e))s.set(n,{attribute:"src",owner:"icon"});return s}var Fe=(e,t)=>{let s=e.get(t.node.sourceCodeLocation.startOffset);return s?.attribute===t.how?s:null},Dt=new Set(["img","input","video","audio","source","track"]),we="an export holds no stylesheet of the folder (the addresses in one are read from its own place): put its rules in the page's <style>",ye=e=>(O(e,"rel")??"").toLowerCase().split(/\s+/),H=/\.html?$/i,Rt={html:'src="assets/<file>.html" sandbox="allow-scripts"',pdf:'src="assets/<file>.pdf"'},V=e=>`<figure class="doc-embed doc-embed--file"><iframe class="doc-embed-frame" ${Rt[e]}></iframe><figcaption></figcaption></figure>`,ke=`its frame with no sandbox (a sandboxed one shows no PDF): ${V("pdf")}`,xe='show a picture with <img src="assets/<file>">, a file to save with a link, <a href="assets/<file>" download="<name>">';function K({node:e,how:t,css:s,value:n}){let o=e.tagName;if(t==="style"||t==="css")return s.kind==="import"?{not:we}:{use:"shown"};if(t==="srcset"&&(o==="img"||o==="source")||t==="poster"&&o==="video"||t==="src"&&Dt.has(o)||t==="background")return{use:"shown"};if(t==="src"&&o==="iframe"){let r=L(n)??"";return H.test(r)?{use:"frame"}:/\.pdf$/i.test(r)?{not:`a PDF shows in an embed block alone (the kit hands its file to the browser's PDF viewer, in the preview and in an export): make it one, ${ke}`}:{not:`a frame shows a page of the folder (an HTML file), not this file, which the preview would hand out for saving: ${xe}`}}if(t==="href"&&(o==="a"||o==="area"))return{use:"link"};if(t==="href"&&(o==="image"||o==="link"&&ye(e).some(r=>r.endsWith("icon"))))return{use:"shown"};if(o==="object"||o==="embed"){let r=L(n)??"";return{not:`an export's policy loads no plugin content (<object>, <embed>): ${/\.pdf$/i.test(r)?`show a PDF in an embed block, ${ke}`:H.test(r)?`show a page in an embed block, ${V("html")}`:xe}`}}return o==="script"?{not:"an export runs the page's own scripts alone: put the code in the page's <script>"}:o==="link"&&ye(e).includes("stylesheet")?{not:we}:{not:"an export holds a file of the folder as a picture, a font, a video or audio, a link or a frame, not there"}}var R=e=>e.startsWith("assets/")&&St(e),Tt=e=>Ot(e)??`the folder is assets/, in lowercase: write it so (assets/${e.slice(7)})`,Le=(e,t,s)=>t==="link"&&H.test(s)&&O(e.node,"download")===void 0,Mt=(e,t)=>e==="frame"?"embed":e==="shown"&&vt(t)?"asset":"file",It=(e,t)=>!!Se.statSync(Oe.join(e,t),{throwIfNoEntry:!1})?.isFile(),v=({node:e,how:t,value:s,written:n})=>({srcset:`<${e.tagName} srcset="\u2026 ${s} \u2026">`,style:`${n} in the style of <${e.tagName}>`,css:`${n} in <style>`})[t]??`<${e.tagName} ${t}="${s}">`,Bt=e=>{for(let t=e.parentNode;t;t=t.parentNode)if(t.tagName&&kt(t,"doc-icon"))return!0;return!1},Pt=e=>e.length>1?`${e.slice(0,-1).join(", ")} and ${e.at(-1)}`:`${e[0]}`;function At(e,t){let s=new Map;for(let{file:i,line:a,owned:c}of e){let l=s.get(i)??s.set(i,{lines:[],owned:!1}).get(i);c?l.owned=!0:l.lines.push(a)}let n=0,o=[];for(let[i,{lines:a,owned:c}]of s){let l=c?a.length:a.length-1;if(l<1)continue;let f=l*Math.ceil(Se.statSync(Oe.join(t,i)).size/3)*4;n+=f;let u=a.length===1?"once":a.length===2?"twice":`${a.length} times`;o.push({bytes:f,said:`${i} ${u}${c?" besides a media block's or the icon's":""} (line${new Set(a).size>1?"s":""} ${Pt([...new Set(a)])})`})}if(n<=be)return[];let r=o.sort((i,a)=>a.bytes-i.bytes).map(({said:i})=>i).join(", ");return[`files embedded more than once make an export ${n.toLocaleString("en-US")} bytes bigger, over the ${be.toLocaleString("en-US")} bytes the copies outside the media blocks may add: ${r}; show each fewer times (a picture, a link or a frame holds a copy of its own each time it is written), or, for a CSS background (url() in a <style> or a style attribute), name it once in the page's <style> (--picture: url(assets/<file>)) and write var(--picture) where it shows`]}function Ne({html:e,directory:t,tree:s}){let n=ve(e,s),o=[],r=[],i=[];for(let a of W(e,s)){let{line:c}=a,l=Fe(n,a),f=L(a.value),u=f!==null&&It(t,f);if(u&&!R(f)&&i.push({file:f,line:c}),l?.owner==="block"){u&&R(f)&&r.push({file:f,line:c,owned:!0,icon:!!l.icon});continue}if(u||o.push(l?`line ${c}: the icon's image ${a.value} is not in the document's folder`:`line ${c}: ${v(a)} names a file that is not in the document's folder`),l){u&&r.push({file:f,line:c,owned:!0,icon:!0});continue}let{use:d,not:p}=K(a);p&&o.push(`line ${c}: ${v(a)}: ${p}`),!(!d||!u)&&(R(f)?Le(a,d,f)?o.push(`line ${c}: ${v(a)} opens an HTML file, which an export cannot (a browser opens no page from a data: address): show it in an embed block, ${V("html")}, or give the link download="<name>" to hand it out as a file`):a.node.tagName==="img"&&a.how==="src"&&Bt(a.node)?o.push(`line ${c}: ${v(a)} is in an icon (.doc-icon) written as an icon is not read (its picker, the browser tab's icon): write it <div class="doc-icon"><img src="assets/<file>" alt=""></div>, in double quotes and with no other class`):(a.how!=="srcset"||a.largest)&&r.push({file:f,line:c}):o.push(`line ${c}: ${v(a)}: ${Tt(f)}`))}return{failures:o,embedded:r,unserved:i}}function Zs({html:e,directory:t,tree:s=m(e)}){let{failures:n,embedded:o}=Ne({html:e,directory:t,tree:s});return[...new Set([...n,...At(o,t)])]}function eo({html:e,directory:t,tree:s=m(e)}){let{embedded:n,unserved:o}=Ne({html:e,directory:t,tree:s});return{embedded:n.map(({file:r,line:i,icon:a=!1})=>({file:r,line:i,icon:a})),unserved:o}}function Ut(e,{slug:t,mode:s,directory:n}){let{use:o}=K(e),r=L(e.value);if(!o||!r||!R(r)||Le(e,o,r))return null;let i=/#.*$/.exec(e.value)?.[0]??"";if(s==="preview")return`${Ft(Mt(o,r),t,r)}${i}`;let a=A(n,r);return a&&`${a}${i}`}function _t(e,t,{mode:s,shown:n}){let[o]=t,{node:r,how:i,key:a}=o,c=(h,g="")=>({start:e.startOffset,end:e.endOffset,text:`${a}="${F(h)}"${g}`}),l=s==="preview"?` data-ge-${i}="${F(O(r,i)??"")}"`:"",u=(s==="preview"?[`data-ge-${i}`,`data-rs-${i}`].map(h=>r.sourceCodeLocation.attrs?.[h]).filter(Boolean):[]).map(h=>({start:h.startOffset,end:h.endOffset,text:""}));if(i==="srcset"){if(s==="export"){let g=t.find(T=>T.largest),$=g&&n(g);return $?[c(`${$} ${g.candidates[g.index].descriptor}`.trim())]:[]}let h=new Map(t.map(g=>[g.index,n(g)]));return[...h.values()].some(Boolean)?[c(o.candidates.map((g,$)=>[h.get($)??g.url,g.descriptor].filter(Boolean).join(" ")).join(", "),l),...u]:[]}if(i==="style"){let h=O(r,"style"),g=t.map($=>({...$.css,address:n($)})).filter($=>$.address).sort(($,T)=>T.start-$.start);for(let $ of g)h=`${h.slice(0,$.start)}${$.address}${h.slice($.end)}`;return g.length>0?[c(h)]:[]}let d=n(o);if(!d)return[];if(s==="preview"||K(o).use!=="link")return[c(d,l),...u];let p=L(o.value).slice(7),y=O(r,"download");if(y===void 0)return[c(d,` download="${F(p)}"`)];let b=r.sourceCodeLocation.attrs?.download;return[c(d),...y===""&&b?[{start:b.startOffset,end:b.endOffset,text:`download="${F(p)}"`}]:[]]}function zt(e,t){let s=[],n=0;for(let{start:o,end:r,text:i}of[...t].sort((a,c)=>a.start-c.start))o<n||(s.push(e.slice(n,o),i),n=r);return s.push(e.slice(n)),s.join("")}var to=(e,t,s=m(e))=>W(e,s,t);function so(e,t){let s=[],n=new Map;for(let o of e){let r=t(o);typeof r=="string"&&(o.how==="css"?s.push({start:o.css.offset+o.css.start,end:o.css.offset+o.css.end,text:r}):o.place&&n.set(o.place,[...n.get(o.place)??[],{...o,address:r}]))}for(let[o,r]of n){let[{node:i,how:a,key:c,candidates:l}]=r,f=r[0].address;if(a==="srcset"){let u=new Map(r.map(d=>[d.index,d.address]));f=l.map((d,p)=>[u.get(p)??d.url,d.descriptor].filter(Boolean).join(" ")).join(", ")}else if(a==="style"){f=O(i,"style");for(let{css:u,address:d}of[...r].sort((p,y)=>y.css.start-p.css.start))f=`${f.slice(0,u.start)}${d}${f.slice(u.end)}`}s.push({start:o.startOffset,end:o.endOffset,text:`${c}="${F(f)}"`})}return s}function oo(e,{slug:t,mode:s="export",reportsDirectory:n=Lt}){if(!/assets\//i.test(e.replace(/\sdata-ge-(?:src|href|icon)="[^"]*"/g,"")))return e;let o=m(e),r=ve(e,o),i=Nt(t,n),a=f=>Ut(f,{slug:t,mode:s,directory:i}),c=[],l=new Map;for(let f of W(e,o))if(!Fe(r,f))if(f.how==="css"){let u=a(f),d=f.css.offset;u&&c.push({start:d+f.css.start,end:d+f.css.end,text:u})}else f.place&&l.set(f.place,[...l.get(f.place)??[],f]);for(let[f,u]of l)c.push(..._t(f,u,{mode:s,shown:a}));return zt(e,c)}export{ie as a,es as b,E as c,Be as d,ts as e,Ue as f,_e as g,gs as h,$s as i,Fs as j,Ls as k,Is as l,Bs as m,Zs as n,eo as o,zt as p,to as q,so as r,oo as s};
|