@heycys/gallery 0.2.1 → 0.2.2
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 +1 -1
- package/browser/editor/page/annotate/index.mjs +3 -2
- package/browser/editor/page/board/index.mjs +2 -1
- package/browser/editor/page/board/settings.mjs +2 -1
- package/browser/editor/page/core.mjs +3 -2
- package/browser/editor/page/custom-page.mjs +4 -3
- package/browser/editor/page/editor.mjs +9 -5
- package/browser/editor/page/emoji-picker/support.mjs +3 -2
- package/browser/editor/page/links/index.mjs +1 -12
- package/browser/editor/page/links/pages.mjs +3 -2
- package/browser/editor/page/outline/folds.mjs +3 -0
- package/browser/editor/page/post.mjs +2 -1
- package/browser/editor/page/present-links.mjs +4 -3
- package/browser/editor/page/present-shell.mjs +3 -58
- package/browser/editor/page/session.mjs +3 -37
- package/browser/editor/page/storage.mjs +5 -5
- package/browser/shared/component-catalog.mjs +2 -2
- package/browser/shared/drafts.mjs +26 -51
- package/browser/shared/emoji/icon-value.mjs +2 -1
- package/browser/shared/extension-manifest.mjs +90 -0
- package/browser/shared/extensions.mjs +26 -16
- package/browser/shared/http.mjs +1 -1
- package/browser/shared/i18n/en.mjs +46 -15
- package/browser/shared/media.mjs +2 -1
- package/browser/shared/outline.mjs +11 -51
- package/browser/shared/page-address.mjs +8 -15
- package/browser/shared/paths.mjs +2 -1
- package/browser/shared/preferences.mjs +3 -1
- package/browser/shared/preview-server.mjs +51 -63
- package/browser/shared/service-location.mjs +18 -0
- package/browser/shared/session.mjs +3 -6
- package/browser/shared/workspace-address.mjs +19 -0
- package/browser/shared/workspace-columns.mjs +1 -2
- package/browser/shared/workspace-registry.mjs +6 -40
- package/browser/shared/workspace.mjs +3 -6
- package/browser/shared/writing-preferences.mjs +6 -4
- package/dist/{chunk-BYSF5UMM.mjs → chunk-236JJXWY.mjs} +2 -2
- package/dist/{chunk-3A5I2GJK.mjs → chunk-2KAVXMKG.mjs} +1 -1
- package/dist/chunk-2T4PZQEP.mjs +2 -0
- package/dist/{chunk-SAHS56QM.mjs → chunk-3SKOU6OZ.mjs} +1 -1
- package/dist/{chunk-S2Y7VI4H.mjs → chunk-3XZOA7AH.mjs} +2 -2
- package/dist/{chunk-MKTX5PGV.mjs → chunk-43B75J5T.mjs} +1 -1
- package/dist/{chunk-VKSRM7EY.mjs → chunk-4B2TB5K2.mjs} +1 -1
- package/dist/{chunk-LV24RY2E.mjs → chunk-4K5KC6V2.mjs} +1 -1
- package/dist/{chunk-SOD23RGL.mjs → chunk-4KUO7R2M.mjs} +8 -8
- package/dist/chunk-4SNV4HA5.mjs +2 -0
- package/dist/chunk-53XDTHTG.mjs +4 -0
- package/dist/chunk-5XV3YYLG.mjs +2 -0
- package/dist/{chunk-VNUWREXU.mjs → chunk-65NTKF4N.mjs} +1 -1
- package/dist/chunk-6GV3CBB2.mjs +2 -0
- package/dist/{chunk-DH6GMDNN.mjs → chunk-6L6V7YR2.mjs} +1 -1
- package/dist/{chunk-TOE6DPLH.mjs → chunk-6NLXUKAY.mjs} +1 -1
- package/dist/chunk-6Q7ASAXJ.mjs +3 -0
- package/dist/{chunk-ZCP7BTOZ.mjs → chunk-6QBHU4DF.mjs} +1 -1
- package/dist/{chunk-QXVNUASA.mjs → chunk-6QWQXHAV.mjs} +1 -1
- package/dist/chunk-6XD6U3QA.mjs +5 -0
- package/dist/{chunk-36FIRJIF.mjs → chunk-742D2WWJ.mjs} +2 -2
- package/dist/{chunk-7M7UPWU6.mjs → chunk-7EFHNQ5B.mjs} +1 -1
- package/dist/{chunk-JI6T3A4Y.mjs → chunk-7ISBBDJR.mjs} +1 -1
- package/dist/{chunk-2GKGEVMR.mjs → chunk-7UZUQQ7Q.mjs} +25 -24
- package/dist/{chunk-VPVOAJ7X.mjs → chunk-AGDILNWB.mjs} +1 -1
- package/dist/{chunk-5IIH335D.mjs → chunk-ALZ6ZENZ.mjs} +1 -1
- package/dist/{chunk-G4YP7GVC.mjs → chunk-BFJGHSQN.mjs} +1 -1
- package/dist/chunk-BLNQUR5R.mjs +168 -0
- package/dist/chunk-BMX3VUHY.mjs +2 -0
- package/dist/chunk-BN7M3IN7.mjs +8 -0
- package/dist/{chunk-AMDGVDNV.mjs → chunk-BQNTTFPL.mjs} +1 -1
- package/dist/chunk-C257H6IA.mjs +2 -0
- package/dist/{chunk-74RPP2M2.mjs → chunk-C564NU2H.mjs} +1 -1
- package/dist/chunk-CHQU37CA.mjs +2 -0
- package/dist/{chunk-WCWYNFDF.mjs → chunk-E4IHAIJ7.mjs} +1 -1
- package/dist/{chunk-7XDYK3UC.mjs → chunk-E7656LR7.mjs} +1 -1
- package/dist/{chunk-KFZBYDIS.mjs → chunk-ECZBLQKK.mjs} +1 -1
- package/dist/{chunk-PAFSFVYB.mjs → chunk-ERE2BXYV.mjs} +1 -1
- package/dist/{chunk-ZEY2RLBT.mjs → chunk-ERLAIBOA.mjs} +2 -2
- package/dist/chunk-FFV733MA.mjs +2 -0
- package/dist/{chunk-CZ5KJSGK.mjs → chunk-GJJRBGMY.mjs} +1 -1
- package/dist/{chunk-VA3KAQZD.mjs → chunk-GKOBB6DH.mjs} +1 -1
- package/dist/chunk-GMJD7ID3.mjs +2 -0
- package/dist/{chunk-QZ35UAB4.mjs → chunk-GRAXKKG4.mjs} +1 -1
- package/dist/{chunk-2RKIHJI2.mjs → chunk-HYMEEXKN.mjs} +1 -1
- package/dist/{chunk-DKR7LFIY.mjs → chunk-IA2SIEJQ.mjs} +1 -1
- package/dist/{chunk-QK3VISCA.mjs → chunk-IA4PSIMD.mjs} +1 -1
- package/dist/chunk-JPG2LBQM.mjs +11 -0
- package/dist/{chunk-VGTMLQWZ.mjs → chunk-JXXHAXYH.mjs} +1 -1
- package/dist/{chunk-5MEXZ2UF.mjs → chunk-K3JKPFL5.mjs} +1 -1
- package/dist/{chunk-LE44MD3O.mjs → chunk-KLQP46Y3.mjs} +1 -1
- package/dist/{chunk-NAGMRVW4.mjs → chunk-LKX55H76.mjs} +1 -1
- package/dist/chunk-LMUZQK5O.mjs +2 -0
- package/dist/{chunk-CG3UHDKH.mjs → chunk-M4NRDYI5.mjs} +1 -1
- package/dist/{chunk-HM4E43VM.mjs → chunk-MAFIGVXY.mjs} +1 -1
- package/dist/{chunk-4DNHHJSL.mjs → chunk-MKIBJTJZ.mjs} +1 -1
- package/dist/{chunk-L7W624FD.mjs → chunk-MNWJ4EZY.mjs} +1 -1
- package/dist/{chunk-FXQBADMN.mjs → chunk-NHP66IWR.mjs} +1 -1
- package/dist/{chunk-YBB5LWZK.mjs → chunk-OEIJLMPI.mjs} +1 -1
- package/dist/{chunk-NWRZXELO.mjs → chunk-PAREWQGB.mjs} +1 -1
- package/dist/{chunk-7N2LPG33.mjs → chunk-PDZR3L3C.mjs} +1 -1
- package/dist/{chunk-YFJU3O7G.mjs → chunk-PLB7L22J.mjs} +1 -1
- package/dist/{chunk-4AMTKWDO.mjs → chunk-PUOQ65NC.mjs} +1 -1
- package/dist/chunk-Q4MS6OFC.mjs +2 -0
- package/dist/{chunk-3OFXMN6N.mjs → chunk-Q7P3Q5YX.mjs} +1 -1
- package/dist/{chunk-6MPKCH3P.mjs → chunk-QNECWMGR.mjs} +1 -1
- package/dist/{chunk-HBAUKKQH.mjs → chunk-QP7BOHE4.mjs} +1 -1
- package/dist/chunk-QVGOPHOF.mjs +2 -0
- package/dist/{chunk-NFABH3QW.mjs → chunk-RRKJMHNX.mjs} +2 -2
- package/dist/chunk-S3SX3COT.mjs +20 -0
- package/dist/{chunk-ZO7SFB2E.mjs → chunk-SQ6Y2ZMA.mjs} +2 -2
- package/dist/{chunk-VG5JEIUQ.mjs → chunk-TKWEX4FD.mjs} +2 -2
- package/dist/{chunk-CCSGFCLZ.mjs → chunk-U3SSPL4K.mjs} +1 -1
- package/dist/{chunk-DHB7UZ7F.mjs → chunk-U5XL7D6A.mjs} +1 -1
- package/dist/{chunk-CPS4SRPF.mjs → chunk-ULXSPX5H.mjs} +2 -2
- package/dist/{chunk-JXLSHVJ2.mjs → chunk-UMHUSOPJ.mjs} +1 -1
- package/dist/chunk-USIHBCSW.mjs +15 -0
- package/dist/{chunk-GWOYMENX.mjs → chunk-V6XZ4VIR.mjs} +1 -1
- package/dist/{chunk-AFGUR7SY.mjs → chunk-VPMRP2TL.mjs} +1 -1
- package/dist/{chunk-WTEGUPFG.mjs → chunk-VRPVVMRB.mjs} +1 -1
- package/dist/chunk-VZ2RQ3AM.mjs +2 -0
- package/dist/{chunk-XKOHV4H6.mjs → chunk-W5NPH5UA.mjs} +1 -1
- package/dist/chunk-WFGPMCTZ.mjs +4 -0
- package/dist/chunk-XZCFPKGO.mjs +2 -0
- package/dist/{chunk-QJ3TFJLQ.mjs → chunk-Y34NR5JL.mjs} +1 -1
- package/dist/{chunk-V5JRSGZF.mjs → chunk-YN37ZDLW.mjs} +1 -1
- package/dist/chunk-ZFGMJVJC.mjs +2 -0
- package/dist/{chunk-KH24LWAT.mjs → chunk-ZTHICSSF.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 +1 -1
- package/kit/runtime.js +12 -2
- package/kit/state.js +2 -0
- package/kit/ui.js +5 -1
- package/package.json +1 -1
- package/release.json +7 -7
- package/skill/SKILL.md +13 -13
- package/skill/references/building-blocks.md +1 -1
- package/skill/references/extensions.md +45 -9
- package/web/assets/{index-xP0uw3a0.css → index-FLb9jCfl.css} +1 -1
- package/web/assets/index-czjrXVjf.js +15 -0
- package/web/index.html +2 -2
- package/dist/chunk-46ACXOU5.mjs +0 -2
- package/dist/chunk-5DPABPBI.mjs +0 -2
- package/dist/chunk-5L26JUYA.mjs +0 -2
- package/dist/chunk-AEMVZYZQ.mjs +0 -166
- package/dist/chunk-ASAXY2DJ.mjs +0 -2
- package/dist/chunk-DAMVDXR3.mjs +0 -2
- package/dist/chunk-DLFZJJEE.mjs +0 -2
- package/dist/chunk-EKNHM3P4.mjs +0 -2
- package/dist/chunk-FCK6NXON.mjs +0 -3
- package/dist/chunk-FX42XU6J.mjs +0 -2
- package/dist/chunk-HATA2W7X.mjs +0 -2
- package/dist/chunk-JJNRIFND.mjs +0 -8
- package/dist/chunk-JL6R4FG4.mjs +0 -4
- package/dist/chunk-KUILYI7H.mjs +0 -4
- package/dist/chunk-NIW7F7LU.mjs +0 -4
- package/dist/chunk-OU3S466R.mjs +0 -20
- package/dist/chunk-QCEATQC4.mjs +0 -2
- package/dist/chunk-TDWJKOLN.mjs +0 -2
- package/dist/chunk-UGO5N3EI.mjs +0 -15
- package/dist/chunk-XMKHCUI6.mjs +0 -15
- package/dist/chunk-XQRUG4G3.mjs +0 -2
- package/dist/chunk-YPPJVDQI.mjs +0 -2
- package/dist/chunk-ZANMKAWS.mjs +0 -2
- package/web/assets/index-BHC5ZOMh.js +0 -15
- /package/dist/{chunk-N3DSBH5S.mjs → chunk-A55HN5OK.mjs} +0 -0
- /package/dist/{chunk-KNZJT4ET.mjs → chunk-QAIHRH3I.mjs} +0 -0
- /package/dist/{chunk-ZW2A6GBW.mjs → chunk-QR6A54KJ.mjs} +0 -0
- /package/dist/{chunk-74UW7QSL.mjs → chunk-UH4SIXTR.mjs} +0 -0
- /package/dist/{chunk-EKGYYOSP.mjs → chunk-W7XHE4CT.mjs} +0 -0
- /package/dist/{chunk-5MMN3N5J.mjs → chunk-YEY3RSFQ.mjs} +0 -0
package/dist/chunk-OU3S466R.mjs
DELETED
|
@@ -1,20 +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 Re,b as Ie}from"./chunk-QK3VISCA.mjs";import{b as Ee}from"./chunk-F4ZA6JRZ.mjs";import{a as ge,b as Me,c as pt,d as Ae,e as Ne,f as Te}from"./chunk-TOE6DPLH.mjs";import{b as ve,c as Oe,e as je,g as Ht}from"./chunk-WTEGUPFG.mjs";import{a as pe}from"./chunk-JXLSHVJ2.mjs";import{a as ke,d as be,e as $e,f as xe,g as Se}from"./chunk-XKOHV4H6.mjs";import{e as we,f as he,g as ye,h as Ct}from"./chunk-KFZBYDIS.mjs";import{a as _,m as me}from"./chunk-7XDYK3UC.mjs";import{g as ue,u as de}from"./chunk-VG5JEIUQ.mjs";var On=3e4,jn=12e4,Mn=1500,De=1e4,Fe=l=>l.reduce((i,{key:w,tag:u})=>i.set(`${w}
|
|
3
|
-
${u}`,(i.get(`${w}
|
|
4
|
-
${u}`)??0)+1),new Map);function Pe({now:l=Date.now,hold:i=On,limit:w=jn,quiet:u=Mn}={}){let k=new Map,d=new Map,O=new Map,h=new Map,c=new Map;return{wrote(p,b){h.set(p,_(b))},judge(p,{source:b,mtime:I}){if(b===null)return k.delete(p),O.delete(p),{held:!1,signs:[],wait:0,own:!1};let N=_(b),$=c.get(p)?.hash===N?c.get(p).signs:null;$||($=Me(b),c.set(p,{hash:N,signs:$}));let Z=l(),W=(J,Q=!1)=>(k.delete(p),d.set(p,Fe($)),O.set(p,b),{held:!1,signs:[],wait:J,own:Q});if(h.get(p)===N)return W(0,!0);let L=d.get(p)??new Map,H=Fe($);if([...H].some(([J,Q])=>Q>(L.get(J)??0))){let J=Math.min(I,Z),Q=k.get(p)??J;k.set(p,Q);let st=Math.min(i-(Z-J),w-(Z-Q));if(st>0)return{held:!0,signs:$.filter(({key:s,tag:g})=>H.get(`${s}
|
|
5
|
-
${g}`)>(L.get(`${s}
|
|
6
|
-
${g}`)??0)),wait:st,own:!1,taken:O.get(p)}}return W(Math.min(u,Math.max(0,u-(Z-I))))}}}import{createHmac as tr,randomBytes as qt}from"node:crypto";import{existsSync as er,mkdirSync as nr,readFileSync as rr,writeFileSync as or}from"node:fs";import z from"node:fs/promises";import P from"node:path";import{FILE as ar}from"../browser/shared/annotations.mjs";import{escapeTyped as sr}from"../browser/shared/escape.mjs";import{writeAtomic as Ft}from"../browser/shared/files.mjs";import{sendJson as C}from"../browser/shared/http.mjs";import{REQUEST_ID as Qt}from"../browser/shared/ids.mjs";import{UPLOAD_REQUEST_LIMIT as ir}from"../browser/shared/media.mjs";import{reportsDirectory as cr}from"../browser/shared/paths.mjs";import{sameDirectory as fr}from"../browser/shared/preview-server.mjs";import{slugPattern as rt}from"../browser/shared/reports.mjs";import{TODO_MOST as lr}from"../browser/shared/workspace-query.mjs";import{documentDirectory as ur,documentFiles as Mt,isDocumentSource as dr}from"../browser/shared/workspace.mjs";import zt from"node:fs/promises";import Je from"node:path";import{checkAnnotations as An,cleanAnchor as Nn,cleanItem as _e,FILE as Tn,itemsText as En,readItems as Rn,treeText as Le}from"../browser/shared/annotations.mjs";import{writeAtomic as In}from"../browser/shared/files.mjs";import{slugPattern as Fn}from"../browser/shared/reports.mjs";import{documentDirectory as Ue,documentFiles as Dn}from"../browser/shared/workspace.mjs";var Pn=600*1e3,Jn=600*1e3;function _n(l){let{units:i,boxes:w}=ye(l),u=[...i].sort((h,c)=>h.elStart-c.elStart),k=new Map(u.map((h,c)=>[h.id,c])),d=new Map(u.map(h=>[h.id,Le(h.node)])),O={h2:null,h3:null,h4:null};return u.map(h=>{let c=[];for(let N=h;N;N=N.parent===null?null:i[N.parent]){let $=w[N.box];if($?.kind==="panel"&&$.key!==null){let W=i.find(L=>L.kind==="tab"&&L.parent===$.unit&&L.key===$.key);W&&c.unshift({tab:d.get(W.id)})}let Z=$?.unit===null||$?.unit===void 0?null:i[$.unit];if(Z?.tag==="details"&&$.kind==="details"){let W=Z.node.childNodes.find(L=>L.tagName==="summary");W&&c.push({details:Le(W)})}}let p=c.find(N=>N.tab)?.tab,b=c.find(N=>N.details)?.details,I=[p,O.h2,O.h3,O.h4,b].filter(Boolean);return h.tag==="h2"?Object.assign(O,{h2:d.get(h.id),h3:null,h4:null}):h.tag==="h3"?Object.assign(O,{h3:d.get(h.id),h4:null}):h.tag==="h4"&&(O.h4=d.get(h.id)),{id:h.blockId,text:d.get(h.id),parent:h.parent===null?null:k.get(h.parent)??null,where:I,heading:/^h[2-4]$/.test(h.tag)}})}function We({reportsDirectory:l,read:i,write:w=In,dropped:u=()=>{},now:k=Date.now}){let d=new Map,O=new Map,h=new Map,c=(s,g)=>{let r=h.get(s);if(r?.text===g)return r.units;let a=_n(g);return h.set(s,{text:g,units:a}),a},p=s=>Je.join(Ue(s,l),Tn),b=s=>typeof s=="string"&&Fn.test(s);async function I(s){let g=await zt.readFile(p(s),"utf8").catch(()=>null);return{text:g,items:g===null?[]:Rn(g)}}async function N(s,g,r){let a=En(g);return a===r||(a===null?await zt.rm(p(s),{force:!0}):await w(p(s),a)),$(a)}let $=s=>s===null?"":_(s),Z=s=>{let g=d.get(s)??new Map;for(let[r,a]of g)k()-a>Pn&&g.delete(r);return[...g.keys()]},W=(s,g)=>g.forEach(r=>d.get(s)?.delete(r)),L=s=>{let g=O.get(s)??O.set(s,new Map).get(s);for(let[r,a]of g)k()-a>Jn&&g.delete(r);return g};async function H(s,{keep:g=null,items:r=null,before:a=void 0}={}){let S=r?{items:r,text:a}:await I(s),v=await i(s).catch(()=>null);if(!v)return{items:S.items,units:[],places:new Map,version:$(S.text),missing:!0};let D=c(s,v.text),T=L(s),x=An(S.items,D,{keep:new Set([...T.keys(),g])});for(let M of T.keys())x.waiting.has(M)||T.delete(M);if(x.dropped.length>0){let M=d.get(s)??d.set(s,new Map).get(s);for(let ot of x.dropped)M.set(ot.id,k())}let A=x.changed||r?await N(s,x.items,S.text):$(S.text);return x.dropped.length>0&&u(s,x.dropped),{items:x.items,units:D,places:x.places,version:A,missing:!1}}let F=(s,{items:g,version:r})=>({ok:!0,version:r,items:g,dropped:Z(s)});async function J(s){if(!b(s))return[400,{ok:!1,reason:"body"}];let g=await H(s);return g.missing?[404,{ok:!1,reason:"missing"}]:[200,F(s,g)]}async function Q(s){if(!b(s))return[400,{ok:!1,reason:"body"}];let g=await H(s);if(g.missing)return[404,{ok:!1,reason:"missing"}];let r=null,a=Dn(Ue(s,l));try{r=JSON.parse(await zt.readFile(a.json,"utf8"))}catch{}let S=await i(s).catch(()=>null),v=/<h1\b[^>]*>([\s\S]*?)<\/h1>/i.exec(S?.text??"")?.[1]?.replace(/<[^>]*>/g,"").trim(),D=typeof r?.title=="string"&&r.title.trim()?r.title.trim():v||s,T=g.units.some(A=>A.heading),x=g.items.map(A=>{let M=g.units[g.places.get(A.id)?.at],ot=M?.where?.length?M.where:M?.heading?[M.text]:[];return{where:ot,top:T&&ot.length===0,blocks:A.anchor.blocks.filter(B=>g.units.some(nt=>nt.id===B)),whole:A.anchor.kind==="blocks",quote:A.anchor.quote,text:A.text}});return[200,{ok:!0,title:D,path:Je.resolve(a.html),items:x}]}async function st(s){let{slug:g}=s??{};if(!b(g))return[400,{ok:!1,reason:"body"}];if(!await i(g).catch(()=>null))return[404,{ok:!1,reason:"missing"}];let r=await I(g);if(s.anchors&&typeof s.anchors=="object"&&!Array.isArray(s.anchors)){let T=r.items.map(A=>{let M=Object.hasOwn(s.anchors,A.id)?Nn(s.anchors[A.id]):null;return M&&M.kind===A.anchor.kind?{...A,anchor:M}:A}),x=await N(g,T,r.text);return[200,F(g,{items:T,version:x})]}let a=r.items,S=null,v=null;if(s.put!==void 0){let T=a.find(A=>A.id===s.put?.id),x=_e({...s.put,created:T?.created??s.put?.created});if(!x)return[400,{ok:!1,reason:"item"}];a=T?a.map(A=>A.id===x.id?x:A):[...a,x],S=x.id,T||L(g).set(x.id,k()),W(g,[x.id])}else if(typeof s.remove=="string")a=a.filter(T=>T.id!==s.remove);else if(s.clear===!0)v=a,a=[];else if(Array.isArray(s.restore)){let T=new Map(a.map(M=>[M.id,M])),x=s.restore.map(M=>_e(M,M?.updated)).filter(M=>M&&!(T.get(M.id)?.updated>M.updated)),A=new Set(x.map(M=>M.id));for(let M of A)T.has(M)||L(g).set(M,k());a=[...a.filter(M=>!A.has(M.id)),...x],W(g,[...A])}else return[400,{ok:!1,reason:"body"}];let D=await H(g,{keep:S,items:a,before:r.text});return[200,{...F(g,D),...v?{removed:v}:{}}]}async function q(s){if(!b(s))return;let{text:g}=await I(s);g!==null&&await H(s)}return{list:J,copy:Q,change:st,afterWrite:q}}import wt from"node:fs/promises";import ht from"node:path";import{writeAtomic as Be}from"../browser/shared/files.mjs";import{slugPattern as Gt}from"../browser/shared/reports.mjs";var It=1,Ot={seen:"seen.html",base:"base.html",state:"state.json"},Ln=4,Un=1800*1e3;function Ye({stateDirectory:l=null,shown:i,folderOf:w,isPage:u=()=>!1,log:k=null,now:d=Date.now,quiet:O=Un}){let h=new Map,c=r=>ht.join(l,"changes",r),p=Promise.resolve(),b=r=>{let a=p.then(r);return p=a.catch(S=>k?.(`changes: ${S.message}`)),a};async function I(r){if(!l)return h.get(r)?.state??null;try{let a=JSON.parse(await wt.readFile(ht.join(c(r),Ot.state),"utf8"));return a?.v===It&&typeof a.seen=="string"?a:null}catch{return null}}async function N(r,a){return l?wt.readFile(ht.join(c(r),Ot[a]),"utf8").catch(()=>null):h.get(r)?.[a]??null}async function $(r,a,S={}){if(!l){let v=h.get(r)??{};h.set(r,{...v,...S,state:a});return}await wt.mkdir(c(r),{recursive:!0});for(let[v,D]of Object.entries(S))D===null?await wt.rm(ht.join(c(r),Ot[v]),{force:!0}):await Be(ht.join(c(r),Ot[v]),D);await Be(ht.join(c(r),Ot.state),`${JSON.stringify(a)}
|
|
7
|
-
`)}async function Z(r){h.delete(r),l&&await wt.rm(c(r),{recursive:!0,force:!0,maxRetries:3})}let W=async r=>Math.round((await wt.stat(w(r)).catch(()=>null))?.birthtimeMs??0),L=r=>r?.base?`${r.since}|${r.writes}`:null,H=r=>Number.isFinite(r?.draft)&&d()-r.draft<O?r.draft:null,F=(r,a,S,v=H(r))=>[{v:It,born:r?.born??0,seen:a,...v===null?{}:{draft:v}},{seen:S,base:null}];async function J(r){let a=await I(r);if(!a)return null;let S=await W(r);return a.born&&S&&a.born!==S?(await Z(r),null):a}async function Q(r,a){if(typeof a!="string"||!Gt.test(r)||u(r))return!1;let S=_(a),v=await J(r);if(!v)return await $(r,{v:It,born:await W(r),seen:S},{seen:a}),!1;if(v.seen===S)return!1;let D=await N(r,"seen"),T=new Date(d()).toISOString();if(D===null)return await $(r,...F(v,S,a)),!1;let x=i(D),A=i(a);if(!v.base){if(!pt(x,A))return await $(r,...F(v,S,a)),!1;if(H(v)!==null||Ae(x))return await $(r,...F(v,S,a,d())),!1;let{draft:B,...nt}=v;return await $(r,{...nt,seen:S,base:_(x),since:T,at:T,writes:1},{seen:a,base:x}),!0}let M=await N(r,"base");if(M===null||!pt(M,A))return await $(r,...F(v,S,a)),!0;let ot=pt(x,A)!==null;return await $(r,{...v,seen:S,...ot?{at:T,writes:v.writes+1}:{}},{seen:a}),ot}async function st(r,a,S,v){if(!Gt.test(r)||u(r))return!1;let D=await J(r),T=_(a);if(!D?.base)return await $(r,...F(D??{born:await W(r)},T,a,v?null:H(D))),!1;let x=await N(r,"base");if(x!==null&&S)try{x=S(x)}catch(A){k?.(`changes: ${r}: the baseline did not take the edit (${A.message})`)}return x===null||!pt(x,i(a))?(await $(r,...F(D,T,a)),!0):(await $(r,{...D,seen:T,base:_(x)},{seen:a,base:x}),!1)}async function q(r,a){if(!Gt.test(r)||u(r))return{ended:!1,moved:!1};let S=typeof a=="string"?await Q(r,a):!1,v=await J(r);if(v?.draft===void 0)return{ended:!1,moved:S};let{draft:D,...T}=v;return await $(r,T),{ended:H(v)!==null,moved:S}}let s=new Map;async function g(r,a){await Q(r,a);let S=i(a),v=_(S),D=await J(r);if(!D?.base)return{pending:!1,version:v};let T=`${r} ${D.base} ${v}`,x=s.get(T);if(x===void 0){let A=await N(r,"base");for(x=A===null?null:pt(A,S),s.set(T,x);s.size>Ln;)s.delete(s.keys().next().value)}return x?{pending:!0,version:v,stamp:L(D),since:D.since,writes:D.writes,...x}:{pending:!1,version:v}}return{look:(r,a)=>b(()=>Q(r,a)),wrote:(r,a,S=null,{reader:v=!1}={})=>b(()=>st(r,a,S,v)),endDraft:(r,a=null)=>b(()=>q(r,a)),read:(r,a)=>b(()=>g(r,a)),stamp:r=>b(async()=>L(await J(r))),snapshot:r=>b(async()=>{let a=await J(r);return a?{state:a,seen:await N(r,"seen"),base:await N(r,"base")}:null}),clear:r=>b(async()=>{let a=await J(r);a?.base&&await $(r,{v:It,born:a.born,seen:a.seen},{base:null})}),restore:(r,a)=>b(async()=>{a?.state&&await $(r,a.state,{seen:a.seen,base:a.base})}),forget:r=>b(()=>Z(r)),idle:()=>b(async()=>{})}}import{randomBytes as Wn}from"node:crypto";import ct from"node:fs/promises";import yt from"node:path";import{FILE as Bn,readItems as Yn}from"../browser/shared/annotations.mjs";import{writeAtomic as Zn}from"../browser/shared/files.mjs";import{documentDirectory as Cn}from"../browser/shared/workspace.mjs";var Hn=20,He=/^\d{8}T\d{6}Z-[a-f0-9]{8}\.json$/,Ze=80,ze=({stateDirectory:l,slug:i})=>yt.join(l,"dropped-annotations",i),Ge=l=>({id:l.id,text:l.text,quote:l.anchor?.quote??"",kind:l.anchor?.kind??"text"});async function Ke({stateDirectory:l,reportsDirectory:i,slug:w,time:u,items:k}){let d=ze({stateDirectory:l,reportsDirectory:i,slug:w});await ct.mkdir(d,{recursive:!0});let O=u.replace(/[-:]/g,"").replace(/\.\d+Z$/,"Z");await Zn(yt.join(d,`${O}-${Wn(4).toString("hex")}.json`),JSON.stringify({time:u,items:k}));let h=(await ct.readdir(d)).filter(c=>He.test(c)).sort();await Promise.all(h.slice(0,Math.max(0,h.length-Hn)).map(c=>ct.rm(yt.join(d,c),{force:!0})))}async function qr({stateDirectory:l,reportsDirectory:i,slug:w}){let u=ze({stateDirectory:l,reportsDirectory:i,slug:w}),k=(await ct.readdir(u).catch(()=>[])).filter(h=>He.test(h)).sort();if(k.length===0)return[];let d=new Set(Yn(await ct.readFile(yt.join(Cn(w,i),Bn),"utf8").catch(()=>"")).map(h=>h.id)),O=[];for(let h of k){let c=yt.join(u,h);try{let p=JSON.parse(await ct.readFile(c,"utf8")),b=Array.isArray(p?.items)?p.items.filter(I=>typeof I?.id=="string"&&!d.has(I.id)):[];typeof p?.time=="string"&&b.length&&O.push({time:p.time,items:b})}catch{}await ct.rm(c,{force:!0}).catch(()=>{})}return O}var zn=(l,i=new Date)=>{let w=new Date(l),u=d=>String(d).padStart(2,"0"),k=`${u(w.getHours())}:${u(w.getMinutes())}`;return w.toDateString()===i.toDateString()?k:`${w.getFullYear()}-${u(w.getMonth()+1)}-${u(w.getDate())} ${k}`},Ce=l=>{let i=String(l??"").replace(/\s+/g," ").trim();return JSON.stringify(i.length>Ze?`${i.slice(0,Ze-1)}\u2026`:i)};function Kt(l,{time:i=null,items:w},{today:u=new Date}={}){let k=yt.resolve(l),d=`${w.length} \u6279\u6CE8 (annotation${w.length===1?"":"s"})`;return[`annotations ${k}: ${i?`at ${zn(i,u)}, `:""}Gallery deleted ${d} whose words are gone from the document (rewritten or deleted):`,...w.map(({id:O,text:h,quote:c,kind:p})=>` ${O} ${Ce(h)} on ${p==="blocks"?"the blocks ":""}${Ce(c)}`)]}function Xr(l,i,{today:w=new Date}={}){return i.length?[...i.flatMap(u=>Kt(l,u,{today:w}))," they were the reader's: say in your hand-off which your edit carried out and which you left, and never write them back"]:[]}import{randomBytes as Gn}from"node:crypto";import gt from"node:fs/promises";import jt from"node:path";import{writeAtomic as Kn}from"../browser/shared/files.mjs";var Qn=20,Qe=/^\d{8}T\d{6}Z-[a-f0-9]{8}\.json$/,Ve=({stateDirectory:l,slug:i})=>jt.join(l,"rewrites",i);async function qe({stateDirectory:l,reportsDirectory:i,slug:w,time:u,changes:k}){let d=Ve({stateDirectory:l,reportsDirectory:i,slug:w});await gt.mkdir(d,{recursive:!0});let O=u.replace(/[-:]/g,"").replace(/\.\d+Z$/,"Z");await Kn(jt.join(d,`${O}-${Gn(4).toString("hex")}.json`),JSON.stringify({time:u,changes:k}));let h=(await gt.readdir(d)).filter(c=>Qe.test(c)).sort();await Promise.all(h.slice(0,Math.max(0,h.length-Qn)).map(c=>gt.rm(jt.join(d,c),{force:!0})))}async function Xe({stateDirectory:l,reportsDirectory:i,slug:w}){let u=Ve({stateDirectory:l,reportsDirectory:i,slug:w}),k=(await gt.readdir(u).catch(()=>[])).filter(O=>Qe.test(O)).sort(),d=[];for(let O of k){let h=jt.join(u,O);try{let c=JSON.parse(await gt.readFile(h,"utf8"));typeof c?.time=="string"&&Array.isArray(c.changes)&&d.push(c)}catch{}await gt.rm(h,{force:!0}).catch(()=>{})}return d}var Vn=(l,i=new Date)=>{let w=new Date(l),u=d=>String(d).padStart(2,"0"),k=`${u(w.getHours())}:${u(w.getMinutes())}`;return w.toDateString()===i.toDateString()?k:`${w.getFullYear()}-${u(w.getMonth()+1)}-${u(w.getDate())} ${k}`};function ao(l,i,{today:w=new Date}={}){if(!i.length)return[];let u=jt.resolve(l),k=[];for(let{time:d,changes:O}of i){let h=[];for(let{line:c,rule:p,key:b}of[...O].sort((I,N)=>I.line-N.line)){let I=`line ${c} ${p}${b?` ${b}`:""}`;h.includes(I)||h.push(I)}k.push(`preview ${u}: at ${Vn(d,w)}, when the reader edited the page, the preview wrote your natural HTML as the kit's markup: ${h.join(", ")}`),k.push(...O.filter(c=>c.note).map(({line:c,rule:p,note:b})=>` line ${c}, ${p}: ${b}`))}return k.push(" re-read the file before editing it (those lines are the file's as you had left it)"),k}import{todoRef as qn}from"../browser/shared/workspace-query.mjs";var Xn=(l,i)=>l.length===i.length&&l.every((w,u)=>w===i[u]);function tn(l,i,w,u){let k=Ie(i),d=Re(w,{at:!0}),O=null,h=c=>(O??=we(w).units).find(p=>p.elStart===c)??null;return u.map(c=>{let p=qn(c?.ref);if(!p||p.slug!==l||typeof c.done!="boolean")return{reason:"ref"};let b=p.block?d.find(N=>N.block===p.block)??null:null;if(b&&b.text!==p.text)return{reason:"changed"};if(!b){let N=d.filter($=>$.text===p.text&&Xn($.path,p.path));if(p.version===k)b=N.find($=>$.nth===p.nth)??null;else{if(N.length>1)return{reason:"ambiguous"};b=N[0]??null}}if(!b)return{reason:"changed"};let I=h(b.at);return I?{unit:I,done:b.done,want:c.done}:{reason:"locked"}})}function en(l,i){let w=new Map,u=i.map(c=>{if(!c.unit)return!1;let p=w.has(c.unit.id)?w.get(c.unit.id):c.done;return w.set(c.unit.id,c.want),p!==c.want}),k=new Map;for(let c of i)c.unit&&w.get(c.unit.id)!==c.done&&k.set(c.unit.id,c);if(k.size===0)return{commit:null,changed:u};let d=[],O=[],h=new Map;for(let[c,p]of k){let b=`todo${d.length}`,I=p.unit.blockId?{key:b,id:p.unit.blockId}:{key:b,open:c,hash:me(l,p.unit)};d.push({key:b,unit:I,attribute:"data-checked",value:w.get(c)?"":null}),O.push(I),h.set(c,b)}return{commit:{units:d,touch:O,keys:h},changed:u}}import{EMPTY_STYLE as mr,emptyWordsScript as pr,showEmpty as wr}from"../browser/editor/components/placeholder.mjs";import{TOKENS as hr}from"../browser/editor/page/look.mjs";import{MARGIN_STYLE as yr,earlyMarginScript as gr}from"../browser/editor/page/margin.mjs";var Vt=/^[a-f0-9]{16}$/,Xt=2*1024*1024,kr=ir,nn=50,rn=/^\d{8}T\d{6}Z-[a-f0-9]{16}\.html$/,br=30,on=3,an=200,ft="\u6587\u4EF6\u4E00\u518D\u88AB\u4FEE\u6539\uFF08\u4F8B\u5982 AI \u6B63\u5728\u5199\u5165\uFF09\uFF0C\u7A0D\u540E\u518D\u540C\u6B65",$r="\u8FD9\u6B21\u7684\u4FEE\u6539\u592A\u5927\uFF0C\u4E00\u6B21\u5B58\u4E0D\u4E0B",xr=250,lt=Symbol("again"),Sr="/__gallery/edit/src/editor/page/editor.mjs",vr=l=>new Promise(i=>setTimeout(i,l));function Or(l,i=Xt){return new Promise((w,u)=>{let k=[],d=0;l.on("data",O=>{d+=O.length,d>i?k.length=0:k.push(O)}),l.on("end",()=>d>i?u(new Error("too-large")):w(Buffer.concat(k).toString("utf8"))),l.on("error",u)})}function jr(l){if(!l)return qt(16).toString("hex");let i=P.join(l,"token");try{let u=rr(i,"utf8").trim();if(/^[a-f0-9]{32}$/.test(u))return u}catch{}let w=qt(16).toString("hex");try{nr(l,{recursive:!0,mode:448}),or(i,w,{mode:384})}catch{}return w}function Wo({reportsDirectory:l=cr,stateDirectory:i=null,write:w=Ft,ids:u=!0,finish:k=p=>p,log:d=null,settling:O={},reviewing:h={},onChanges:c=()=>{}}={}){let p=jr(i),b=Pe(O),I=O.wait??De,N=new Map,$=async(t,n,e,o="reader")=>{let f=await w(t,n,e);if(f!==!1&&dr(P.basename(t))){let y=P.basename(P.dirname(t));b.wrote(y,n),N.set(y,{hash:_(n),by:o})}return f},Z=t=>ur(t,l),W=t=>Mt(Z(t)).html,L=new Map,H=i&&P.join(i,"snapshots"),F=Promise.resolve(),J=Promise.resolve(),Q=async(t,n,e,{by:o="time"}={})=>{let f=(await z.readdir(t)).filter(m=>n.test(m));if(f.length<=e)return;let y=o==="name"?f.sort():(await Promise.all(f.map(async m=>({name:m,time:(await z.stat(P.join(t,m))).mtimeMs})))).sort((m,j)=>m.time-j.time).map(({name:m})=>m);await Promise.all(y.slice(0,y.length-e).map(m=>z.rm(P.join(t,m),{force:!0})))},st=(t,n)=>{H&&(F=F.then(async()=>{let e=P.join(H,`${t}.html`),o=new Date;try{await z.utimes(e,o,o);return}catch{}await z.mkdir(H,{recursive:!0}),await Ft(e,n),await Q(H,/^[a-f0-9]{16}\.html$/,nn)}).catch(()=>{}))},q=(t,n)=>{i&&(F=F.then(async()=>{let e=P.join(i,"history",t),o=_(n);if(await z.mkdir(e,{recursive:!0}),(await z.readdir(e)).filter(m=>rn.test(m)).sort().at(-1)?.endsWith(`-${o}.html`))return;let y=new Date().toISOString().replace(/[-:]/g,"").replace(/\.\d+Z$/,"Z");await Ft(P.join(e,`${y}-${o}.html`),n),await Q(e,rn,br,{by:"name"})}).catch(()=>{}))},s=new Map,g=t=>i&&P.join(i,"receipts",t),r=(t,n,e,o)=>{for(s.set(`${t} ${n}`,{digest:e,answer:o});s.size>an*4;)s.delete(s.keys().next().value);let f=g(t);f&&(F=F.then(async()=>{await z.mkdir(f,{recursive:!0}),await Ft(P.join(f,`${n}.json`),JSON.stringify({digest:e,answer:o})),await Q(f,{test:y=>y.endsWith(".json")&&Qt.test(y.slice(0,-5))},an)}).catch(()=>{}))},a=async(t,n)=>{let e=s.get(`${t} ${n}`);if(e)return e;let o=g(t);if(!o)return null;await F;try{let f=JSON.parse(await z.readFile(P.join(o,`${n}.json`),"utf8"));return typeof f?.digest=="string"&&f.answer?.ok?f:null}catch{return null}},S=new Map,v=(t,n)=>{let e=new Date().toISOString();if(!i)return void S.set(t,[...S.get(t)??[],{time:e,changes:n}].slice(-20));F=F.then(()=>qe({stateDirectory:i,reportsDirectory:l,slug:t,time:e,changes:n})).catch(()=>{})},D=async t=>{if(!i){let n=S.get(t)??[];return S.delete(t),n}return await F,Xe({stateDirectory:i,reportsDirectory:l,slug:t})},T=(t,n)=>{for(L.delete(t),L.set(t,n);L.size>nn;)L.delete(L.keys().next().value);st(t,n)},x=async t=>{if(L.has(t))return L.get(t);if(!H||!Vt.test(t))return null;await F;let n=await z.readFile(P.join(H,`${t}.html`),"utf8").catch(()=>null);return n===null||_(n)!==t?null:(T(t,n),n)},A=new Map,M=t=>{let n=A.get(t);if(n)return n;let e=ve(t,{finish:k});for(A.set(t,e);A.size>8;)A.delete(A.keys().next().value);return e},ot=P.join(P.resolve(l),".gallery","pages"),B=Ye({...h,stateDirectory:i,shown:t=>M(t).text,folderOf:Z,log:d,isPage:t=>P.resolve(Z(t)).startsWith(ot+P.sep)}),nt=(t,n)=>n.then(e=>{e&&c(t)},e=>d?.(`${t}: the Agent's changes not kept (${e.message})`));async function Dt(t,n=void 0){if(typeof t!="string"||!rt.test(t))return null;let e=W(t),o=n!==void 0?n:await z.readFile(e,"utf8").catch(()=>null);if(o===null)return null;let{text:f,changes:y}=M(o);return{file:e,source:o,text:f,version:_(f),changes:y}}async function it(t){if(typeof t!="string"||!rt.test(t))return{source:null,held:!1,signs:[],wait:0,own:!1};let n=W(t),e=await z.readFile(n,"utf8").catch(()=>null),o=(await z.stat(n).catch(()=>null))?.mtimeMs??0;return{source:e,...b.judge(t,{source:e,mtime:o})}}async function kt(t,n=Date.now()+I){for(;;){let e=await it(t);if(!e.held||Date.now()>=n)return e;await vr(Math.max(0,Math.min(xr,n-Date.now())))}}async function Pt(t,{wait:n=I}={}){let e=await kt(t,Date.now()+n),o=await Dt(t,e.held&&e.taken!==void 0?e.taken:e.source);return o&&{...o,held:e.held===!0}}function sn(t,n,{editor:e=Sr,kitTags:o=()=>[]}={}){let{html:f,map:y}=ge(n);T(y.version,n);let m=ue(l),j=de(m).map(({assets:Y,...X})=>({...X,kit:o(Y)})),E=`<script type="application/json" id="doc-edit-map" data-doc-dev>${JSON.stringify({slug:t,token:p,...y,components:j,hidden:m.settings.hidden}).replace(/</g,"\\u003c")}</script>
|
|
8
|
-
<script data-doc-dev>document.currentScript.remove(); import(${JSON.stringify(e)});</script>`,U=`<style data-doc-dev>.doc-display { display: none; }</style>
|
|
9
|
-
<style data-doc-dev data-ge-palette>${hr}</style>
|
|
10
|
-
<style data-doc-dev>${mr}</style>
|
|
11
|
-
<script data-doc-dev>${pr()}</script>
|
|
12
|
-
<script data-doc-dev>document.currentScript.remove(); document.documentElement.setAttribute("data-ge-order", "file");</script>
|
|
13
|
-
<style data-doc-dev data-ge-margin-style>${yr}</style>
|
|
14
|
-
<script data-doc-dev>document.currentScript.remove(); ${gr(t,{notes:er(P.join(Z(t),ar))})}</script>`;return{html:wr(f),snippet:E,head:U}}let cn=t=>T(_(t),t);function te(t){if(t.method!=="POST")return[405,{ok:!1,reason:"method"}];let n=t.headers.host??"",e=t.socket.localPort;return n!==`127.0.0.1:${e}`&&n!==`localhost:${e}`?[403,{ok:!1,reason:"host"}]:t.headers.origin!==`http://${n}`?[403,{ok:!1,reason:"origin"}]:t.headers["x-gallery-token"]!==p?[403,{ok:!1,reason:"token"}]:null}async function ut(t,n=Xt){let e=te(t);if(e)return{error:e};if(!/^application\/json\b/i.test(t.headers["content-type"]??""))return{error:[415,{ok:!1,reason:"type"}]};try{return{body:JSON.parse(await Or(t,n))}}catch(o){return{error:o.message==="too-large"?[413,{ok:!1,reason:"body",message:$r}]:[400,{ok:!1,reason:"body"}]}}}async function Jt(t,n){let{slug:e,opening:o,known:f=null,texts:y=[],units:m=[],touch:j=[],pageIds:R=null,request:E=null,agent:U=!1}=t;if(typeof e!="string"||!rt.test(e)||![y,m,j].every(Array.isArray))return[400,{ok:!1,reason:"body"}];if(E!==null&&(typeof E!="string"||!Qt.test(E)))return[400,{ok:!1,reason:"body"}];let Y=E===null?null:_(JSON.stringify([o??null,y,m,j])),X=await ee(t);if(X)return X;let G=et=>(E!==null&&r(e,E,Y,et),[200,et]),K=W(e),tt=typeof o=="string"&&Vt.test(o)?await x(o):null,V=et=>tr("sha256",p).update(`${e}
|
|
15
|
-
${et}`).digest("hex").slice(0,32);for(let et=1;;et++){let{source:at,held:Tt}=await it(e);if(at===null)return[404,{ok:!1,reason:"missing"}];if(Tt)return Date.now()<n?lt:[409,{ok:!1,reason:"busy",message:ft}];nt(e,B.look(e,at));let{text:vt,changes:Zt}=M(at),se=[],Et=be({current:vt,opening:tt,texts:y,units:m,touch:j,ids:u?()=>{let Rt=typeof u=="function"?u():Ct();return se.push(Rt),Rt}:!1,seal:V,pageIds:R}),{title:ie,icon:ce,...fe}=Et,mt=Et.text===vt?vt:k(Et.text);mt!==Et.text&&(fe.version=_(mt));let le={...fe,foreign:typeof f=="string"&&_(vt)!==f};if(mt===vt)return G({ok:!0,...le,wrote:!1,notes:[]});if(q(e,at),!await $(K,mt,{expect:at},U===!0?"agent":"reader")){if(et===on)return[409,{ok:!1,reason:"busy",message:ft}];continue}q(e,mt),nt(e,B.wrote(e,mt,Rt=>{let vn=0;return Ne(Rt,{opening:tt,texts:y,units:m,touch:j,pageIds:R,seal:V,ids:u?()=>se[vn++]??(typeof u=="function"?u():Ct()):!1})},{reader:U!==!0})),Zt.length&&(d&&d(Ht(K,Zt).join(`
|
|
16
|
-
`)),v(e,Zt));let Sn=[...ie?await At(P.dirname(K),ie):[],...ce!==void 0?await _t(P.dirname(K),ce):[]];return G({ok:!0,...le,wrote:!0,notes:Sn})}}async function fn(t,n){return typeof t!="string"||!rt.test(t)?[404,{ok:!1,reason:"missing",message:"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"}]:!Array.isArray(n)||n.length===0||n.length>lr?[400,{ok:!1,reason:"body"}]:Lt({slug:t},async(e,o)=>{let{source:f,held:y}=await it(t);if(f===null)return[404,{ok:!1,reason:"missing",message:"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"}];if(y)return Date.now()<o?lt:[409,{ok:!1,reason:"busy",message:ft}];let{text:m}=M(f),j=tn(t,f,m,n),{commit:R,changed:E}=en(m,j),U=j.map((V,et)=>V.reason?{ok:!1,reason:V.reason}:{ok:!0,changed:E[et],block:V.unit.blockId??null});if(!R)return[200,{ok:!0,results:U,wrote:!1}];let Y=_(m);T(Y,m);let X=await Jt({slug:t,opening:Y,units:R.units,touch:R.touch},o);if(X===lt)return lt;let[G,K]=X;if(!K.ok)return[G,K];let tt=new Map((K.units??[]).map(V=>[V.key,V]));return[200,{ok:!0,wrote:K.wrote===!0,results:U.map((V,et)=>{if(!V.ok)return V;let at=R.keys.get(j[et].unit.id);if(at===void 0)return V;let Tt=tt.get(at);return Tt?.status!=="applied"?{ok:!1,reason:Tt?.reason==="ambiguous"?"ambiguous":"changed"}:{...V,block:K.ids?.[at]??V.block}})}]})}async function ee({slug:t,opening:n,texts:e=[],units:o=[],touch:f=[],request:y=null}){if(typeof t!="string"||!rt.test(t)||typeof y!="string"||!Qt.test(y)||![e,o,f].every(Array.isArray))return null;let m=await a(t,y);return m?m.digest===_(JSON.stringify([n??null,e,o,f]))?[200,{...m.answer,again:!0}]:[409,{ok:!1,reason:"request",message:"\u540C\u4E00\u6B21\u4FDD\u5B58\u7684\u5185\u5BB9\u4E0D\u4E00\u81F4"}]:null}async function ln(t,n){let{slug:e,opening:o,texts:f=[],units:y=[],instances:m=[],pageIds:j=null}=t;if(typeof e!="string"||!rt.test(e)||!Array.isArray(f)||!Array.isArray(y)||!Array.isArray(m))return[400,{ok:!1,reason:"body"}];let{source:R,held:E}=await it(e);if(E)return Date.now()<n?lt:[409,{ok:!1,reason:"busy",message:ft}];let U=await Dt(e,R);if(U===null)return[404,{ok:!1,reason:"missing"}];let{text:Y,version:X}=U,G=typeof o=="string"&&Vt.test(o)?await x(o):null;return[200,{ok:!0,version:X,reverted:Se({current:Y,opening:G,texts:f,pageIds:j}),units:$e({current:Y,units:y}),parts:xe({current:Y,instances:m,pageIds:j})}]}let un=600*1e3,bt=new Map;async function ne(t,n){let e=Z(t),o=null;try{o=JSON.parse(await z.readFile(Mt(e).json,"utf8"))}catch{}let{title:f,icon:y}=je(n,o);f&&typeof o?.title=="string"&&o.title!==f.to&&await At(e,{from:o.title,to:f.to,synced:!0}),y&&!y.missing&&await _t(e,y.to)}async function dn(t,n){let{slug:e,action:o,stamp:f=null,undo:y=null}=t;if(typeof e!="string"||!rt.test(e)||!["accept","revert","undo"].includes(o))return[400,{ok:!1,reason:"body"}];let m=W(e),{source:j,held:R}=await it(e);if(j===null)return[404,{ok:!1,reason:"missing"}];if(R)return Date.now()<n?lt:[409,{ok:!1,reason:"busy",message:ft}];if(o==="undo"){for(let[K,tt]of bt)Date.now()-tt.at>un&&bt.delete(K);let G=typeof y=="string"?bt.get(y):null;return!G||G.slug!==e?[404,{ok:!1,reason:"gone",message:"\u64A4\u9500\u5DF2\u7ECF\u8FC7\u671F"}]:j!==G.after?[409,{ok:!1,reason:"moved-on",message:"\u64A4\u56DE\u4E4B\u540E\u6587\u6863\u53C8\u6539\u8FC7\u4E86\uFF0C\u6CA1\u6CD5\u64A4\u9500"}]:(q(e,j),await $(m,G.before,{expect:j})?(q(e,G.before),bt.delete(y),await ne(e,G.before),await B.restore(e,G.saved),await B.wrote(e,G.before),c(e),[200,{ok:!0,version:_(M(G.before).text)}]):[409,{ok:!1,reason:"busy",message:ft}])}await B.look(e,j);let E=await B.snapshot(e),U=E?.state?.base?`${E.state.since}|${E.state.writes}`:null;if(U===null)return[200,{ok:!0,none:!0}];if(U!==f)return[409,{ok:!1,reason:"changed",message:"Agent \u521A\u521A\u53C8\u6539\u4E86\u6587\u6863\uFF0C\u518D\u770B\u4E00\u773C"}];if(o==="accept")return await B.clear(e),c(e),[200,{ok:!0}];let Y=E.base;if(q(e,j),!await $(m,Y,{expect:j}))return[409,{ok:!1,reason:"busy",message:ft}];q(e,Y),await ne(e,Y);let X=qt(8).toString("hex");return bt.set(X,{slug:e,before:j,after:Y,saved:E,at:Date.now()}),await B.clear(e),await B.wrote(e,Y),c(e),[200,{ok:!0,version:_(M(Y).text),undo:X}]}async function mn(t,n){let e=await ut(t);if(e.error)return C(n,...e.error);let o=e.body??{};try{if(o.action!=="read")return C(n,...await Lt(o,dn));if(typeof o.slug!="string"||!rt.test(o.slug))return C(n,400,{ok:!1,reason:"body"});let f=await Pt(o.slug,{wait:0});return f===null?C(n,404,{ok:!1,reason:"missing"}):C(n,200,{ok:!0,...await B.read(o.slug,f.source)})}catch(f){return C(n,500,{ok:!1,reason:"write",message:f.message})}}async function At(t,{from:n,to:e,synced:o}){let f=["\u6807\u9898\u5DF2\u66F4\u65B0",...o?[]:["\u5355\u72EC\u6253\u5F00\u6216\u5BFC\u51FA\u65F6\u7684\u9875\u9762\u540D\u79F0\u539F\u672C\u5C31\u548C\u6807\u9898\u4E0D\u540C\uFF0C\u6CA1\u6709\u8DDF\u7740\u6539"]],y=Mt(t).json,m=await z.readFile(y,"utf8").catch(()=>""),j=null;try{j=JSON.parse(m)}catch{}if(j?.title!==n)return[...f,"\u641C\u7D22\u548C\u4FA7\u680F\u91CC\uFF08\u6CA1\u6253\u5F00\u8FD9\u4EFD\u6587\u6863\u65F6\uFF09\u7684\u6587\u6863\u540D\u539F\u672C\u5C31\u548C\u6807\u9898\u4E0D\u540C\uFF0C\u6CA1\u6709\u8DDF\u7740\u6539"];let R=new RegExp(`("title"\\s*:\\s*)${JSON.stringify(n).replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}`),E=R.test(m)?m.replace(R,(U,Y)=>Y+JSON.stringify(e)):`${JSON.stringify({...j,title:e},null,2)}
|
|
17
|
-
`;try{await $(y,E)}catch(U){return d?.(`${P.basename(y)}'s title was not written (${U.code??U.message}): ${y}`),[...f,"\u641C\u7D22\u548C\u4FA7\u680F\u91CC\uFF08\u6CA1\u6253\u5F00\u8FD9\u4EFD\u6587\u6863\u65F6\uFF09\u7684\u6587\u6863\u540D\u6CA1\u80FD\u8DDF\u7740\u6539"]}return f}async function _t(t,n){let e=Mt(t).json,o=null;try{o=JSON.parse(await z.readFile(e,"utf8"))}catch{}if(!o||typeof o!="object")return d?.(`${P.basename(e)} could not be read, so its icon was not written: ${e}`),["\u9875\u9762\u56FE\u6807\u5DF2\u66F4\u6362\uFF0C\u4F46\u641C\u7D22\u548C\u4FA7\u680F\u91CC\uFF08\u6CA1\u6253\u5F00\u8FD9\u4EFD\u6587\u6863\u65F6\uFF09\u7684\u56FE\u6807\u6CA1\u80FD\u8DDF\u7740\u6362"];if((o.icon??null)===n)return[];let{icon:f,...y}=o,m=n===null?y:{...y,icon:n};try{await $(e,`${JSON.stringify(m,null,2)}
|
|
18
|
-
`)}catch(j){return d?.(`${P.basename(e)}'s icon was not written (${j.code??j.message}): ${e}`),["\u9875\u9762\u56FE\u6807\u5DF2\u66F4\u6362\uFF0C\u4F46\u641C\u7D22\u548C\u4FA7\u680F\u91CC\uFF08\u6CA1\u6253\u5F00\u8FD9\u4EFD\u6587\u6863\u65F6\uFF09\u7684\u56FE\u6807\u6CA1\u80FD\u8DDF\u7740\u6362"]}return[]}async function pn(t,n){let e=typeof n=="string"?n.replace(/\s+/g," ").trim():"";if(!e)return{ok:!1,reason:"title",message:"\u6807\u9898\u4E0D\u80FD\u4E3A\u7A7A"};let o=W(t),f=await z.readFile(o,"utf8").catch(()=>null);if(f===null)return{ok:!1,reason:"missing"};nt(t,B.look(t,f));let y=pe(f),m=he(y).find(E=>E.kind==="title");if(!m)return{ok:!1,reason:"no-title",message:"\u8FD9\u4EFD\u6587\u6863\u6CA1\u6709\u6807\u9898"};let j=sr(e),R=ke({current:y,edits:[{id:m.id,parts:[{keep:!0,html:j}]}],ids:u});return R.ok?R.text!==f&&!await $(o,R.text,{expect:f})?{ok:!1,reason:"changed-again"}:(R.text!==f&&nt(t,B.wrote(t,R.text,E=>Te(E,j))),{ok:!0,title:e,notes:R.title?await At(P.dirname(o),R.title):[]}):{ok:!1,reason:"conflict"}}let $t=t=>(n,e)=>{let o=J.then(()=>t(n));return J=o.catch(()=>{}),o.then(([f,y])=>C(e,f,y),f=>C(e,500,{ok:!1,reason:"write",message:f.message}))},re=(t,{early:n=null}={})=>async(e,o)=>{let f=await ut(e);if(f.error)return C(o,...f.error);let y=f.body??{};try{let m=n&&await n(y);return m?C(o,...m):C(o,...await Lt(y,t))}catch(m){return C(o,500,{ok:!1,reason:"write",message:m.message})}};async function Lt(t,n){let e=Date.now()+I;for(;;){await kt(t.slug,e);let o=J.then(()=>n(t,e));J=o.catch(()=>{});let f=await o;if(f!==lt)return f}}async function Ut(t,{reader:n=!1}={}){if(typeof t!="string"||!rt.test(t))return{ok:!1,reason:"missing",message:"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"};let e=Z(t),{html:o,json:f}=Mt(e);for(let y=1;;y++){let{source:m,held:j}=n?await it(t):{source:await z.readFile(o,"utf8").catch(()=>null),held:!1};if(m===null)return{ok:!1,reason:"missing",message:"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"};if(j)return{ok:!1,reason:"busy",message:"\u6587\u4EF6\u4E00\u518D\u88AB\u4FEE\u6539\uFF08\u4F8B\u5982 AI \u6B63\u5728\u5199\u5165\uFF09\uFF0C\u6CA1\u6709\u5199\u5165"};nt(t,B.look(t,m));let R=null;try{R=JSON.parse(await z.readFile(f,"utf8"))}catch{}let{text:E,changes:U,added:Y,given:X,repeated:G,title:K,icon:tt}=Oe(m,{finish:k,next:typeof u=="function"?u:void 0,metadata:R});if(E!==m){if(q(t,m),!await $(o,E,{expect:m},n?"reader":"agent")){if(y===on)return{ok:!1,reason:"busy",message:"\u6587\u4EF6\u4E00\u518D\u88AB\u4FEE\u6539\uFF08\u4F8B\u5982 AI \u6B63\u5728\u5199\u5165\uFF09\uFF0C\u6CA1\u6709\u5199\u5165"};continue}q(t,E),nt(t,B.wrote(t,E)),n&&U.length&&(d&&d(Ht(o,U).join(`
|
|
19
|
-
`)),v(t,U))}return K&&typeof R?.title=="string"&&R.title!==K.to&&await At(e,{from:R.title,to:K.to,synced:K.page}),tt&&!tt.missing&&await _t(e,tt.to),{ok:!0,changes:E===m?[]:U,added:E===m?0:Y,given:E===m?[]:X,repeated:G,written:E!==m,title:K,icon:tt}}}let wn=async(t,{reader:n=!1}={})=>{n&&await kt(t);let e=J.then(()=>Ut(t,{reader:n}));return J=e.catch(()=>{}),e};async function Wt(t){let n=await ut(t);if(n.error)return{refused:n.error};let{slug:e,workspace:o}=n.body??{};return typeof e!="string"||!rt.test(e)||typeof o!="string"?{refused:[400,{ok:!1,reason:"body"}]}:fr(o,l)?{slug:e}:{refused:[409,{ok:!1,reason:"elsewhere",message:"\u8FD9\u4E2A\u9884\u89C8\u670D\u52A1\u5668\u7BA1\u7684\u662F\u53E6\u4E00\u4E2A\u76EE\u5F55\u7684\u6587\u6863"}]}}async function hn(t,n){try{let e=J.then(async()=>{let{slug:y,refused:m}=await Wt(t);if(m)return{answer:m};let j=await Ut(y);return{slug:j.ok?y:null,answer:[j.ok?200:j.reason==="missing"?404:409,j]}});J=e.catch(()=>{});let{slug:o,answer:f}=await e;return o&&await Yt(o),C(n,...f)}catch(e){return C(n,500,{ok:!1,reason:"write",message:e.message})}}async function yn(t){let{slug:n,refused:e}=await Wt(t);return e||(await Yt(n),[200,{ok:!0}])}async function oe(t){let{source:n}=await kt(t),{ended:e,moved:o}=await B.endDraft(t,n);return o&&c(t),e}async function gn(t){let{slug:n,refused:e}=await Wt(t);return e||[200,{ok:!0,ended:await oe(n)}]}let dt=Ee({reportsDirectory:l}),xt=We({reportsDirectory:l,read:t=>Pt(t,{wait:0}),write:$,dropped:(t,n)=>{let e=n.map(Ge);d&&d(Kt(P.join(Z(t),"annotations.json"),{items:e}).join(`
|
|
20
|
-
`)),i&&(F=F.then(()=>Ke({stateDirectory:i,reportsDirectory:l,slug:t,time:new Date().toISOString(),items:e})).catch(()=>{}))}}),ae=Promise.resolve(),Bt=t=>{let n=ae.then(t);return ae=n.catch(()=>{}),n},kn=t=>(n,e)=>Bt(()=>t(n)).then(([o,f])=>C(e,o,f),o=>C(e,500,{ok:!1,reason:"write",message:o.message})),bn=300,St=new Map;async function Yt(t){let n=St.get(t);n&&(clearTimeout(n.timer),St.delete(t));let e=Bt(()=>xt.afterWrite(t));n&&e.then(n.resolve,n.reject),await e.catch(o=>d?.(`${t}: annotations not checked: ${o.message}`)),await F}let $n=t=>{let n=t.headers.host??"",e=t.socket.localPort;return n!==`127.0.0.1:${e}`&&n!==`localhost:${e}`?[403,{ok:!1,reason:"host"}]:t.headers["x-gallery-token"]!==p?[403,{ok:!1,reason:"token"}]:null};async function xn(t){if(t.method==="GET"){let e=$n(t);if(e)return e;let o=new URL(t.url??"/","http://localhost").searchParams;return o.get("as")==="copy"?xt.copy(o.get("slug")):xt.list(o.get("slug"))}let n=await ut(t);return n.error??xt.change(n.body)}let Nt=(t,n=Xt)=>async e=>{let o=await ut(e,n);return o.error??t(o.body)};return{token:p,preview:sn,opened:cn,check:ut,checkHeaders:te,upload:$t(Nt(dt.upload,kr)),addEmoji:$t(Nt(dt.addEmoji)),unfurl:$t(Nt(dt.unfurl)),annotations:kn(xn),checkAnnotations(t){let n=St.get(t);return n||(n={timer:0},n.done=new Promise((e,o)=>Object.assign(n,{resolve:e,reject:o})),St.set(t,n)),clearTimeout(n.timer),n.timer=setTimeout(()=>{St.delete(t),Bt(()=>xt.afterWrite(t)).then(n.resolve,n.reject)},bn),n.done},frameable:$t(Nt(dt.frameable)),listEmojis:dt.listEmojis,readEmoji:dt.readEmoji,respond:$t,keepVersion:q,renameReport:pn,read:Dt,settled:it,writerOf:(t,n)=>typeof n=="string"&&N.get(t)?.hash===_(n)?N.get(t).by:null,whenTaken:kt,readTaken:Pt,takeRewrites:D,handIn:wn,handInReport:Ut,handInRequest:hn,settleRequest:(t,n)=>yn(t).then(([e,o])=>C(n,e,o),e=>C(n,500,{ok:!1,reason:"write",message:e.message})),settleNotes:Yt,roundRequest:(t,n)=>gn(t).then(([e,o])=>C(n,e,o),e=>C(n,500,{ok:!1,reason:"write",message:e.message})),beginRound:oe,commit:re(Jt,{early:ee}),handleCommit:Jt,setTodos:fn,reverted:re(ln),changes:mn,noteTaken:(t,n)=>B.look(t,n),forgetChanges:t=>B.forget(t),stored:async()=>{await B.idle(),await F}}}export{qr as a,Xr as b,Xe as c,ao as d,On as e,jn as f,Mn as g,Wo as h};
|
package/dist/chunk-QCEATQC4.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,c}from"./chunk-7N2LPG33.mjs";import"./chunk-JJNRIFND.mjs";import"./chunk-ASAXY2DJ.mjs";import"./chunk-HBAUKKQH.mjs";import"./chunk-YPPJVDQI.mjs";import"./chunk-JEUK3ZO7.mjs";import"./chunk-KUILYI7H.mjs";import"./chunk-2GKGEVMR.mjs";import"./chunk-4OZWXZE5.mjs";import"./chunk-NWRZXELO.mjs";import"./chunk-JXLSHVJ2.mjs";import"./chunk-N3DSBH5S.mjs";import"./chunk-5L7RYZCL.mjs";export{a as DEFAULT_DESCRIPTION,c as run,b as slugRefused};
|
package/dist/chunk-TDWJKOLN.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,c,d,e,f,g}from"./chunk-XQRUG4G3.mjs";import"./chunk-OU3S466R.mjs";import"./chunk-QK3VISCA.mjs";import"./chunk-F4ZA6JRZ.mjs";import"./chunk-7M2BQQGZ.mjs";import"./chunk-TOE6DPLH.mjs";import"./chunk-WTEGUPFG.mjs";import"./chunk-XMKHCUI6.mjs";import"./chunk-SAHS56QM.mjs";import"./chunk-KH24LWAT.mjs";import"./chunk-YFJU3O7G.mjs";import"./chunk-NWRZXELO.mjs";import"./chunk-G4YP7GVC.mjs";import"./chunk-DHB7UZ7F.mjs";import"./chunk-2RKIHJI2.mjs";import"./chunk-JXLSHVJ2.mjs";import"./chunk-XKOHV4H6.mjs";import"./chunk-KFZBYDIS.mjs";import"./chunk-7XDYK3UC.mjs";import"./chunk-VG5JEIUQ.mjs";import"./chunk-N3DSBH5S.mjs";import"./chunk-5L7RYZCL.mjs";export{a as handInReports,e as idLines,f as inStepLines,d as noteNew,b as previewSettled,g as rereadLine,c as roundBegins};
|
package/dist/chunk-UGO5N3EI.mjs
DELETED
|
@@ -1,15 +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 se}from"./chunk-5IIH335D.mjs";import{a as It}from"./chunk-JXLSHVJ2.mjs";import{f as Wt}from"./chunk-VG5JEIUQ.mjs";import{b as ie,e as Ce}from"./chunk-N3DSBH5S.mjs";import{randomBytes as _t}from"node:crypto";import j from"node:fs/promises";import g from"node:path";import{writeAtomic as z}from"../browser/shared/files.mjs";import{sendJson as Q}from"../browser/shared/http.mjs";import{said as rt,saying as Ut}from"../browser/shared/i18n/index.mjs";import{reportsDirectory as an}from"../browser/shared/paths.mjs";import{moveDocument as sn,outlineAndFile as cn,ownsOutline as ln,sharedOutline as me,placeIn as jt,readOutline as pe,validOutline as ke,withOutlineLock as he,writeHead as un,writeOutline as fn,writtenAs as dn}from"../browser/shared/outline.mjs";Ce();import Ot from"node:fs/promises";import Nt from"node:path";import{attr as Fe,walk as Je}from"../browser/shared/html-tree.mjs";import{escapeAttribute as Ge}from"../browser/shared/escape.mjs";import{COMPONENTS_FOLDER as Me,DOCUMENT_FOLDERS as We,SHARED_FOLDERS as Ye,documentFiles as ce,packageFolders as He,readLink as Be}from"../browser/shared/workspace.mjs";async function Yt(w,b){let c=await Ot.readdir(Nt.join(w,b),{withFileTypes:!0});if(!Ye.includes(b))return c.map(({name:A})=>A);let _=b===Me?new Set(He(w).map(({id:A})=>A.split("/")[0])):new Set;return c.filter(A=>A.isFile()||We.includes(A.name)&&!_.has(A.name)).map(({name:A})=>A)}async function Ht(w,b,c,_,{names:A=new Map}={}){let L=Nt.join(w,b),wt=await Ot.access(ce(L).html).then(()=>!0,()=>!1)?null:await Be(L),B=new Set(["",...await Yt(w,b)]);if(await Ot.cp(L,c,{recursive:!0,errorOnExist:!0,force:!1,filter:a=>B.has(Nt.relative(L,a).split(Nt.sep)[0])}),wt)return[];let st=ce(c).html,N=await Ot.readFile(st,"utf8"),G=It(N),ct=new Map,lt=new Set;Je(ie(G.replace(/^\uFEFF/," "),{sourceCodeLocationInfo:!0}),a=>{let M=Fe(a,"data-doc-component");M&<.add(M);for(let{name:J,value:W}of a.attrs??[]){let I=a.sourceCodeLocation?.attrs?.[J];if(!I)continue;let F=/^(\.\.\/)([a-z0-9]+(?:-[a-z0-9]+)*)(\/.*)$/.exec(W),Z=J==="data-doc-id"&&W===b?_:["href","src","poster"].includes(J)&&F&&A.has(F[2])?`../${A.get(F[2])}${F[3]}`:W;Z!==W&&ct.set(I.startOffset,{to:I.endOffset,text:`${J}="${Ge(Z)}"`})}});let V=[...ct].sort(([a],[M])=>M-a).reduce((a,[M,J])=>a.slice(0,M)+J.text+a.slice(J.to),G);return await Ot.writeFile(st,V),[...lt]}import{storedHead as wn}from"../browser/shared/sidebar-head.mjs";import{DOCS as Tt,columnWorkspaceId as mn,entryWorkspace as pn,entryPattern as kn,isForeign as ge,isTop as ft,topOf as pt}from"../browser/shared/outline-shape.mjs";import{addDraft as ye,addWorkspace as hn,draftEntry as bt,draftFacts as Oe,draftOf as Kt,findDraft as gn,foreignMarker as yn,projectChoices as On,registeredIds as je,workspaceNames as jn,workspaceOf as X}from"../browser/shared/drafts.mjs";import{forgetSnapshot as nt,shownWorkspaces as bn}from"../browser/shared/workspace-columns.mjs";import{nameStops as Sn}from"../browser/shared/workspace-name.mjs";import{registerWorkspace as vn,workspaceId as Ct,workspaceKey as be}from"../browser/shared/workspace-registry.mjs";import{spawn as fe}from"node:child_process";import Ve from"node:http";import Ue from"node:os";import Vt from"node:path";import{NO_DEFAULT_TREE as Ke}from"../browser/shared/drafts.mjs";import{said as le}from"../browser/shared/i18n/index.mjs";import{packageRoot as ze}from"../browser/shared/paths.mjs";import{answerOf as ue,compareVersions as Xe,galleryVersion as Qe,readAnnouncement as Bt}from"../browser/shared/preview-server.mjs";import{isWorkspace as Ze,readRegistry as De,workspaceId as qe,workspaceKey as $t}from"../browser/shared/workspace-registry.mjs";var Rt={rename:{to:"workspace",fields:["slug","title"]},create:{to:"workspace",fields:["title","description","language"]},trash:{to:"workspace",fields:["slug","kind"]},"link-set":{to:"workspace",fields:["slug","url","title","icon"]},"copy-from":{to:"workspace",fields:["sourceWs","slug","parent","index"]},link:{to:"workspace",fields:["url","title","parent","first"]},restore:{to:"workspace",fields:["id"]},duplicate:{to:"workspace",fields:["slug","suffix","untitled"]},look:{to:"workspace",fields:["slug","look"]},looks:{to:"workspace",fields:["slug"]},markdown:{to:"transfer",fields:["slug"]},import:{to:"transfer",fields:["uploads","parent","from","language"]},annotations:{to:"edit",fields:["slug","restore"]},export:{to:"transfer",fields:["slug","options"],file:"out",timeout:6e5},upload:{to:"transfer",fields:[],query:["name"],file:"in",timeout:36e5}},tn=["content-type","content-length","content-disposition","x-file-name","cache-control"],en=9e4,nn=w=>!["","0",void 0].includes(w);function rn(w,{platform:b=process.platform,env:c=process.env}={}){return nn(c.GALLERY_NO_BROWSER)?{skip:"GALLERY_NO_BROWSER is set"}:b==="win32"?{command:Vt.join(c.SystemRoot||c.windir||"C:\\Windows","explorer.exe"),args:[`/select,"${w}"`],verbatim:!0}:b==="darwin"?{command:"open",args:["-R",w]}:!c.DISPLAY&&!c.WAYLAND_DISPLAY?{skip:"no display here (neither DISPLAY nor WAYLAND_DISPLAY is set)"}:{command:"xdg-open",args:[Vt.dirname(w)]}}function de(w,b){let c=rn(w,b);return c.skip?Promise.resolve({opened:!1,why:c.skip}):new Promise(_=>{let A;try{A=fe(c.command,c.args,{detached:!0,stdio:"ignore",windowsHide:!1,windowsVerbatimArguments:!!c.verbatim})}catch(L){return _({opened:!1,why:L.code??L.message})}A.once("error",L=>_({opened:!1,why:L.code??L.message})),A.once("spawn",()=>{A.unref(),_({opened:!0})})})}function on(w){let b=/^http:\/\/127\.0\.0\.1:(\d{1,5})$/.exec(String(w??"")),c=b?Number(b[1]):0;return c>0&&c<65536?c:null}function we({root:w,changed:b=()=>{},log:c=()=>{},gallery:_=Vt.join(ze,"bin","gallery.mjs")}){let A=$t(w),L=new Map;function Et(y){let k={...process.env,[Ke]:"1",GALLERY_NO_UPDATE_CHECK:"1"};return delete k.GALLERY_WORKSPACE,delete k.GALLERY_SERVER_KIND,k.GALLERY_VITE_CACHE_DIR&&(k.GALLERY_VITE_CACHE_DIR=`${k.GALLERY_VITE_CACHE_DIR}-${qe(y)}`),new Promise(v=>{let O=[],S;try{S=fe(process.execPath,[_,"--workspace",y,"open","--no-browser"],{cwd:Ue.homedir(),env:k,stdio:["ignore","pipe","pipe"],windowsHide:!0})}catch($){return v({ok:!1,message:$.message})}S.stdout.on("data",$=>O.push(String($))),S.stderr.on("data",$=>O.push(String($)));let P=setTimeout(()=>S.kill(),en);S.once("error",$=>{clearTimeout(P),v({ok:!1,message:$.message})}),S.once("exit",$=>{clearTimeout(P);let m=O.join("").trim().split(/\r?\n/).filter(Boolean);v($===0?{ok:!0}:{ok:!1,message:m.slice(-3).join(" ")||`gallery open ended with ${$}`})})})}async function wt(y){let k=await Bt({reportsDirectory:y});return!k||await ue(k,y,5e3)!=="yes"||k.kind!=="dev"&&Xe(k.version,Qe)<0?null:{port:k.port,token:k.token,pid:k.pid}}async function B(y,{start:k=!0}={}){if($t(y)===A)return{refused:"self",message:"\u8FD9\u662F\u5F53\u524D\u7684\u5DE5\u4F5C\u533A"};if(!Ze(y))return{refused:"workspace",message:le("\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A{0} \u4E0D\u5728\u4E86",y)};let v=await wt(y);if(v||!k)return v??{refused:"start",message:"\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u5728\u8FD0\u884C"};let O=$t(y);L.has(O)||(c(`starting the server of ${y}`),L.set(O,Et(y).finally(()=>L.delete(O))));let S=await L.get(O);return await wt(y)??{refused:"start",message:S.ok?"\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u56DE\u7B54":le("\u6CA1\u80FD\u542F\u52A8\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\uFF1A{0}",S.message)}}let st=(y,k,v,O)=>{let S=Rt[k],P=Object.fromEntries(S.fields.filter(m=>v?.[m]!==void 0).map(m=>[m,v[m]]));k==="trash"&&P.kind!=="link"&&delete P.kind;let $=new URLSearchParams((S.query??[]).filter(m=>O?.[m]!==void 0).map(m=>[m,String(O[m])]));return{fields:P,host:`127.0.0.1:${y.port}`,path:`/__gallery/${S.to}/${k}${$.size?`?${$}`:""}`}};async function N(y,k,v){if(!Object.hasOwn(Rt,k)||Rt[k].file)return[404,{ok:!1,reason:"unknown",message:"\u8FD9\u4E2A\u547D\u4EE4\u4E0D\u80FD\u8F6C\u7ED9\u522B\u7684\u5DE5\u4F5C\u533A"}];let O=await B(y);if(O.refused)return[409,{ok:!1,reason:O.refused,message:O.message}];let{fields:S,host:P,path:$}=st(O,k,v);try{let m=await fetch(`http://${P}${$}`,{method:"POST",headers:{"Content-Type":"application/json",Origin:`http://${P}`,"X-Gallery-Token":O.token},body:JSON.stringify(S),signal:AbortSignal.timeout(3e4)}),D=await m.json().catch(()=>null);return D&&typeof D.ok=="boolean"?[m.status,D]:[502,{ok:!1,reason:"answer",message:"\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u7ED9\u51FA\u7ED3\u679C"}]}catch{return[502,{ok:!1,reason:"answer",message:"\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u56DE\u7B54"}]}}async function G(y,k,{body:v={},query:O={},request:S=null,response:P}){let $=Rt[k];if(!$?.file)return[404,{ok:!1,reason:"unknown",message:"\u8FD9\u4E2A\u547D\u4EE4\u4E0D\u80FD\u8F6C\u7ED9\u522B\u7684\u5DE5\u4F5C\u533A"}];let m=await B(y);if(m.refused)return[409,{ok:!1,reason:m.refused,message:m.message}];let{fields:D,host:ot,path:U}=st(m,k,v,O);return new Promise(mt=>{let K={Origin:`http://${ot}`,"X-Gallery-Token":m.token},q=$.file==="out"?Buffer.from(JSON.stringify(D)):null;q?Object.assign(K,{"Content-Type":"application/json","Content-Length":q.length}):Object.assign(K,{"Content-Type":"application/octet-stream",...S.headers["content-length"]?{"Content-Length":S.headers["content-length"]}:{}});let kt=[502,{ok:!1,reason:"answer",message:"\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u56DE\u7B54"}],it=Ve.request({host:"127.0.0.1",port:m.port,path:U,method:"POST",headers:K,timeout:$.timeout},R=>{P.writeHead(R.statusCode??502,Object.fromEntries(tn.filter(Y=>R.headers[Y]!==void 0).map(Y=>[Y,R.headers[Y]]))),R.pipe(P),R.once("end",()=>mt(null)),R.once("error",()=>{P.destroy(),mt(null)})});it.once("timeout",()=>it.destroy()),it.once("error",()=>{P.headersSent?(P.destroy(),mt(null)):mt(kt)}),P.once("close",()=>{P.writableEnded||it.destroy()}),q?it.end(q):S.pipe(it)})}let ct=new Map;async function lt(y){let k=on(y);if(k===null)return!1;let v=ct.get(k);if(v&&Date.now()-v.at<6e4)return v.answer;let O=(async()=>{for(let{root:S}of De().workspaces){let P=await Bt({reportsDirectory:S});if(P?.port===k&&await ue(P,S,3e3)==="yes")return!0}return!1})();return ct.set(k,{at:Date.now(),answer:O}),O}let V=new Map,a=new Map,M=new Set,J=!1;async function W(y,k,v){let O=new AbortController,S={controller:O,port:v.port};a.set(y,S);try{let P=await fetch(`http://127.0.0.1:${v.port}/__gallery/events?workspace=own`,{signal:O.signal});if(!P.ok||!P.body)return;M.has(y)&&b(k),M.add(y);let $=new TextDecoder,m="";for await(let D of P.body){m+=$.decode(D,{stream:!0});for(let ot=m.indexOf(`
|
|
3
|
-
|
|
4
|
-
`);ot>=0;ot=m.indexOf(`
|
|
5
|
-
|
|
6
|
-
`)){let U=m.slice(0,ot);m=m.slice(ot+2),/^data: workspace /m.test(U)&&b(k)}}}catch{}finally{a.get(y)===S&&a.delete(y)}}async function I(){for(let[y,k]of a)V.has(y)||k.controller.abort();for(let[y,k]of V){if(J||a.has(y)||$t(k)===A)continue;let v=await Bt({reportsDirectory:k});v&&!a.has(y)&&!J&&W(y,k,v)}}let F=Promise.resolve(),Z=setInterval(()=>{F=F.then(I).catch(()=>{})},3e3);Z.unref();function Mt(y){V.clear();for(let[k,v]of y)v&&V.set(k,v);F=F.then(I).catch(()=>{})}function At(){J=!0,clearInterval(Z);for(let{controller:y}of a.values())y.abort();a.clear()}return{serverOf:B,forward:N,relay:G,shellVouched:lt,follow:Mt,close:At,get following(){return[...a.keys()]}}}import{LINK_FILE as zt,linkStem as xn,linkValue as St,ownAddress as Xt,readLinkText as En}from"../browser/shared/web-links.mjs";import{sameDirectory as dt}from"../browser/shared/preview-server.mjs";import{listReportSlugs as An,slugPattern as T}from"../browser/shared/reports.mjs";import{PAGE_SLUG as Pn,SHARED_FOLDERS as Se,defaultWorkspace as Ln,documentDirectory as In,documentFiles as vt,ensureWorkspace as Nn,idHolder as $n,isDocSlug as Rn,layoutOf as Ft,listTrash as _n,newDocSlug as Jt,pageSlug as Tn,readLink as Qt,slugTaken as Cn,trashIdPattern as ve}from"../browser/shared/workspace.mjs";import{createPage as Fn,headOf as xe,listPages as Jn,newPageSlug as Gn,pageFiles as xt,readPageMeta as Zt,renamePage as Mn}from"../browser/shared/pages.mjs";import{editExtension as Wn,extensionSource as Yn,listExtensions as Hn}from"../browser/shared/extensions.mjs";import{effectiveLook as Dt,ownLookFor as Bn,ownLookOf as Vn,sameLook as Un,withLookField as Ee}from"../browser/shared/document-look.mjs";import{workspaceLook as qt,writeWorkspaceLook as Kn}from"../browser/shared/workspace-look.mjs";import{findIn as zn,tidyQuery as Xn}from"../browser/shared/search.mjs";var Qn=([w,b,c,..._])=>_.length?rt("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}\uFF1B{2} \u7B49 {3} \u6761",w,b,c,_.length+3):c!==void 0?rt("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}\uFF1B{2}",w,b,c):b!==void 0?rt("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}",w,b):rt("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}",w),Gt=w=>w==="en"?"en":null,Zn=32*1024*1024;async function at(w,b){for(let c=0;;c++)try{return await j.rename(w,b)}catch(_){if(!["EPERM","EBUSY","EACCES"].includes(_.code))throw _;if(c>=5)break;await new Promise(A=>setTimeout(A,60*(c+1)))}await j.cp(w,b,{recursive:!0,errorOnExist:!0,force:!1}),await j.rm(w,{recursive:!0,force:!0,maxRetries:5})}var Dn=w=>g.resolve(w);function Ur({edits:w,reports:b,reportsDirectory:c=an,server:_={kind:"dev",version:null,stop:null},components:A=null,changed:L=()=>{},relayed:Et=L,index:wt=null,web:B=null,elsewhere:st=null}){let{trash:N}=Ft(c),G=st??we({root:c,changed:t=>{t&&nt(t),Et()}}),ct=null,lt=()=>ct??=Sn(),V=wt??se({root:c,read:ae(w),draw:(t,e)=>b.words(t,e)}),a=(t,e,n)=>[t,{ok:!1,reason:e,...Ut(n)}],M=t=>j.readFile(t,"utf8").then(JSON.parse).catch(()=>null),J=t=>In(t,c),W=t=>vt(J(t)),I=t=>g.join(c,t),F=t=>K(vt(I(t)).html),Z=t=>Promise.resolve(w.forgetChanges?.(t)).catch(()=>{}),Mt=t=>Yt(c,t),At=async(t,e,n)=>{await j.mkdir(n,{recursive:!0});let o=[];try{for(let r of t)await at(g.join(e,r),g.join(n,r)),o.push(r)}catch(r){for(let i of o)await at(g.join(n,i),g.join(e,i));throw r}},y=async(t,e)=>{if(!Se.includes(t))return at(I(t),e);await At(await Mt(t),I(t),e),await j.rmdir(I(t)).catch(()=>{})},k=async(t,e)=>Se.includes(t)&&!await F(t)&&(await Promise.all((await j.readdir(e)).map(n=>K(g.join(I(t),n))))).every(n=>!n),v=async t=>await M(vt(t).json)??{},O=async t=>{let{title:e=t,description:n="",type:o,instructions:r,icon:i,look:s}=await v(J(t)),l=r===!0?{}:Dt(s,qt(c));return{slug:t,title:e,description:n,...o?{type:o}:{},...typeof i=="string"&&i?{icon:i}:{},...r===!0?{instructions:!0}:{},...Object.keys(l).length?{look:l}:{}}},S=async t=>{let e=await Qt(I(t));return e&&{slug:t,title:e.title,description:"",kind:"link",url:e.url,...e.icon?{icon:e.icon}:{},...e.siteIcon?{siteIcon:e.siteIcon}:{}}},P=async(t,e,n=[])=>{let o=Kt(t),r=o&&n.find(({id:et})=>et===o.ws),i=r?.facts.get(o.slug);if(i){let et=g.join(r.root,o.slug);return{slug:t,title:i.title,description:i.description,kind:i.kind==="link"?"link":"draft",workspace:o.ws,...i.icon?{icon:i.icon}:{},...i.kind==="link"?{url:i.url,siteIcon:i.siteIcon}:{},path:i.path,folder:et,root:r.root}}let{ws:s,title:l,description:u,icon:f,path:h,folder:d,root:p,missing:x,kind:H,url:E,siteIcon:C}=await Oe(t,e);return{slug:t,title:l,description:u,kind:H==="link"?"link":"draft",workspace:s,...H==="link"?{url:E,siteIcon:C}:{},...f?{icon:f}:{},...h?{path:h,folder:d,root:p}:{},...x?{missing:x}:{}}},$=async(t,e,n,o)=>ge(t)?P(t,n,o):e.includes(t)?await S(t)??{slug:t,title:t,description:"",kind:"link",url:""}:O(t),m=Ct(c),D=()=>be(Ln())===be(c),ot=(t,e)=>{let n=t.shown.find(({isDefault:l})=>l)?.id??(D()?m:null),o=new Set([...t.drafts.map(l=>Kt(l)?.ws),...t.groups.map(({workspace:l})=>l),...t.shown.map(({id:l})=>l)].filter(Boolean)),r=new Set(t.groups.filter(({workspace:l,title:u})=>l&&!u).map(({workspace:l})=>l));t.groups.find(({id:l})=>l===Tt)?.title||r.add(m),r.delete(n);let i=jn(new Set([...o,m]),{ids:new Map([...e,[m,[c]]]),stops:lt(),among:r});G.follow(new Map([...i].filter(([l])=>l!==m).map(([l,{root:u}])=>[l,u])));let s=Object.fromEntries([...o].map(l=>[l,{...i.get(l)??{missing:X(l,e).refused??"unknown"},...l===n?{default:!0}:{}}]));return s[m]={...i.get(m),there:!0,self:!0,...m===n?{default:!0}:{}},s},U=()=>Tn(c),mt=async(t,e)=>{let n=await v(J(t));await z(W(t).json,`${JSON.stringify({...n,[e]:!0},null,2)}
|
|
7
|
-
`)},K=t=>j.access(t).then(()=>!0,()=>!1),q=async(t,{own:e=null}={})=>{let n=new Set((await ht()).map(({slug:o})=>o));n.delete(e);for(let o=1;;o++){let r=o===1?t:`${t}-${o}`;if(!Cn(r,c)&&!n.has(r))return r}},kt=async t=>{let e=await q(t.slug,{own:t.slug});return Rn(t.slug)?e===t.slug&&!await $n(t.slug,c)?e:Jt(c):e},it=async(t,e)=>{let n=W(t).html,o=await j.readFile(n,"utf8"),r=It(o).replace(`data-doc-id="${e}"`,`data-doc-id="${t}"`);r!==o&&await z(n,r)},R=()=>pe(c),Y=async t=>{await fn(c,t),L()},tt=t=>he(c,t);async function Pt(t,e="",n=1/0){await tt(async()=>{let o=await R();jt(o,t,e,n),await Y(o)})}async function Lt(t,{parent:e="",after:n=null,first:o=!1}={}){await tt(async()=>{let r=await R();for(let s of Object.values(r.children))s.includes(t)&&s.splice(s.indexOf(t),1);let i=typeof n=="string"?Object.keys(r.children).find(s=>r.children[s].includes(n)):void 0;i!==void 0?jt(r,t,i,r.children[i].indexOf(n)+1):jt(r,t,typeof e=="string"?e:"",o===!0?0:1/0),await Y(r)})}function Ae(t,e){let n=new Set(Object.values(t.children).flat()),o={...t.children};for(let{id:r}of e.groups){if(r===Tt)continue;let i=s=>{let l=(e.children[s]??[]).filter(u=>!n.has(u));(ft(s)||l.length)&&(o[s]=l),l.forEach(i)};i(pt(r))}return{groups:e.groups,children:o}}function te(t){return tt(async()=>{let e=await R();for(let[n,o]of Object.entries(e.children)){let r=o.indexOf(t);if(!(r<0))return o.splice(r,1,...e.children[t]??[]),delete e.children[t],await Y(e),{parent:n,index:r}}return{parent:"",index:1/0}})}let Pe=(t,e)=>V.lines(t,e),ee=t=>M(g.join(N,t,"entry.json")),ht=()=>_n(c);async function Le(t){let e=await Zt(t,c);if(!e)return a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762");let n=`${Date.now().toString(36)}-${_t(3).toString("hex")}`;try{await j.mkdir(g.join(N,n),{recursive:!0}),await at(xt(t,c).folder,g.join(N,n,"page"))}catch(r){throw await j.rm(g.join(N,n),{recursive:!0,force:!0}).catch(()=>{}),r}let o={id:n,kind:"page",slug:t,title:e.title,at:Date.now(),parent:"",index:-1};return await z(g.join(N,n,"entry.json"),`${JSON.stringify(o,null,2)}
|
|
8
|
-
`),[200,{ok:!0,entry:o}]}async function Ie(t){let e=g.join(N,t.id,"page"),n=await kt(t);if(await j.mkdir(Ft(c).customPages,{recursive:!0}),await at(e,xt(n,c).folder),n!==t.slug){let{html:o}=xt(n,c),r=await j.readFile(o,"utf8").catch(()=>null),i=r?.replace(`data-page-id="${t.slug}"`,`data-page-id="${n}"`);r!==null&&i!==r&&await z(o,i)}return await j.rm(g.join(N,t.id),{recursive:!0,force:!0}),[200,{ok:!0,page:await Zt(n,c),entry:{...t,slug:n}}]}async function Ne(t){let e=await Qt(I(t));if(!e)return a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u94FE\u63A5");let n=`${Date.now().toString(36)}-${_t(3).toString("hex")}`,o=await R(),{parent:r,index:i}=await te(t);try{await j.mkdir(g.join(N,n),{recursive:!0}),await at(I(t),g.join(N,n,"link"))}catch(l){throw await tt(()=>Y(o)),await j.rm(g.join(N,n),{recursive:!0,force:!0}).catch(()=>{}),l}let s={id:n,kind:"link",slug:t,title:e.title,at:Date.now(),parent:r,index:Number.isFinite(i)?i:-1};return await z(g.join(N,n,"entry.json"),`${JSON.stringify(s,null,2)}
|
|
9
|
-
`),[200,{ok:!0,entry:s}]}async function $e(t){let e=g.join(N,t.id,"link"),n=await kt(t);return await at(e,I(n)),await j.rm(g.join(N,t.id),{recursive:!0,force:!0}),await Pt(n,t.parent,t.index<0?1/0:t.index),[200,{ok:!0,report:await S(n),entry:{...t,slug:n}}]}function Re(t,{parent:e,after:n,first:o}){let r=s=>ft(s)?Object.hasOwn(t.children,s):Object.values(t.children).some(l=>l.includes(s));if(n!=null){let s=Object.keys(t.children).find(l=>t.children[l].includes(n));return s===void 0?{refused:[404,"after","\u627E\u4E0D\u5230\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6761\u76EE"]}:e!=null&&e!==s?{refused:[409,"level","\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6761\u76EE\u4E0D\u5728\u8FD9\u4E00\u5C42"]}:{parent:s,index:t.children[s].indexOf(n)+1}}let i=e??pt(Tt);return ft(i)&&t.groups.some(s=>s.extension&&pt(s.id)===i)?{refused:[409,"extension","\u6269\u5C55\u7684\u680F\u91CC\u653E\u4E0D\u4E86\u522B\u7684\u6761\u76EE"]}:r(i)?{parent:i,index:o?0:(t.children[i]??[]).length}:{refused:[404,"parent",ft(i)?"\u627E\u4E0D\u5230\u8FD9\u4E00\u680F":"\u627E\u4E0D\u5230\u8981\u653E\u5230\u5B83\u4E0B\u9762\u7684\u6761\u76EE"]}}let ut=new Map;function _e(t){let e=ut.get(t);if(e&&Date.now()-e.at<36e5)return e.answer;let n=B?B.frameable(t).catch(()=>({frameable:!0,reason:"unknown"})):Promise.resolve({frameable:!0,reason:"unknown"});return ut.size>=500&&ut.delete(ut.keys().next().value),ut.set(t,{at:Date.now(),answer:n}),n.then(o=>{["auth","unknown"].includes(o.reason)&&ut.get(t)?.answer===n&&ut.delete(t)}),n}function ne(t,e){return B?.icon?(async()=>{let n=await B.icon(e).catch(()=>null);if(!n)return null;let o=g.join(I(t),zt),r=await j.readFile(o,"utf8").catch(()=>null),i=r===null?null:En(r);if(!i||i.url!==e||i.siteIcon===n)return null;let s=St({...i,siteIcon:n});return s.refused||!s.value.siteIcon||!await z(o,`${JSON.stringify(s.value,null,2)}
|
|
10
|
-
`,{expect:r})?null:(L(),n)})().catch(()=>null):Promise.resolve(null)}let re={info:async()=>[200,{ok:!0,version:1,gallery:_.version,token:w.token,commands:[...Object.keys(gt)],server:{pid:process.pid,workspace:g.resolve(c),kind:_.kind}}],async outline(){let{outline:t,others:e}=await cn(c),n=await U(),o=[...Object.values(t.children).flat(),...n?[n]:[]],r=je(),i=async p=>[p,await $(p,t.links,r,e)],[s,l,u,f]=await Promise.all([Promise.all(o.map(i)),Jn(c),ht(),Hn(c)]),h=f.map(({id:p,file:x,title:H,icon:E,entries:C,count:et,error:yt})=>({id:p,file:x,title:H,...E?{icon:E}:{},entries:C,count:et,...yt?{error:Ut(yt)}:{}})),d=await xe(c,l);return[200,{ok:!0,outline:t,instructions:n,reports:Object.fromEntries(s),pages:l,head:d,trash:u,workspaces:ot(t,r),self:m,shared:me(c),extensions:h}]},trash:async()=>[200,{ok:!0,entries:await ht()}],async stats(t){let e=t.get("slug")??"",n=T.test(e)?await V.facts(e).catch(()=>null):null;return n?[200,{ok:!0,edited:n.edited,words:n.words}]:a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863")},async query(t){let e;try{e=JSON.parse(t.get("options")??"{}")}catch{return[400,{ok:!1,reason:"options",message:"options is JSON"}]}return V.query(t.get("kind")??"",e,{doc:t.get("doc")})},components:async()=>[200,{ok:!0,...A.read()}],async source(t){let e=t.get("slug")??"",n=t.get("kind")==="page";if(!T.test(e))return a(404,"missing",n?"\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762":"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let o=g.resolve(n?xt(e,c).html:W(e).html);return await K(o)?[200,{ok:!0,path:o}]:a(404,"missing",n?"\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762":"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863")},projects:async()=>[200,{ok:!0,workspaces:await On(c,{stops:lt()})}],shell:async t=>[200,{ok:!0,shell:await G.shellVouched(t.get("origin"))}],async search(t){let e=Xn(t.get("q")??"");if(!e)return[200,{ok:!0,results:[]}];let{children:n,groups:o,links:r}=await R(),i=[],s=d=>(n[d]??[]).forEach(p=>{!r.includes(p)&&!ge(p)&&i.push(p),s(p)});for(let{id:d}of o)s(pt(d));let l=e.toLowerCase(),u=new Map(await Promise.all(i.map(async d=>[d,await O(d)]))),f=JSON.stringify([...u].map(([d,{title:p}])=>[d,p])),h=(await Promise.all(i.map(async d=>{let p=await Pe(d,f);if(!p)return null;let x=String(u.get(d).title).toLowerCase().includes(l),{count:H,hits:E}=zn(p,e);return x||H?{slug:d,title:x,count:H,hits:E}:null}))).filter(Boolean);return h.sort((d,p)=>Number(p.title)-Number(d.title)||p.count-d.count),[200,{ok:!0,results:h.slice(0,50)}]}},gt={async"extension-edit"({id:t,...e}){let n=await Yn(c,t),o=await he(n?.root??c,()=>Wn(n?.root??c,t,e),{local:!0});return o.ok?(o.written&&L(),[200,{ok:!0}]):a(o.status,o.reason,o.error)},async outline({outline:t,base:e}){return!ke(t)||e!==void 0&&!ke(e)?a(400,"outline","\u6587\u6863\u76EE\u5F55\u7684\u7ED3\u6784\u4E0D\u5BF9\uFF1A\u6BCF\u4EFD\u6587\u6863\u53EA\u80FD\u51FA\u73B0\u4E00\u6B21"):me(c)&&!ln(c,t)?a(409,"cross-workspace","\u8DE8\u5DE5\u4F5C\u533A\u8BF7\u590D\u5236\uFF0C\u4E0D\u80FD\u53EA\u79FB\u52A8\u76EE\u5F55\u4F4D\u7F6E"):await tt(async()=>{let o=await R();return e!==void 0&&!dn(e,o)?!1:(await Y(t.groups?t:Ae(t,o)),!0)})?[200,{ok:!0,outline:await R()}]:a(409,"stale","\u6587\u6863\u76EE\u5F55\u521A\u5728\u522B\u5904\u6539\u8FC7")},async move({slug:t,parent:e,after:n=null,first:o=!1,workspace:r}){if(typeof r=="string"&&!dt(r,c))return a(409,"elsewhere","\u8FD9\u4E2A\u9884\u89C8\u670D\u52A1\u5668\u7BA1\u7684\u662F\u53E6\u4E00\u4E2A\u76EE\u5F55\u7684\u6587\u6863");let i=u=>typeof u=="string"&&T.test(u);if(!i(t)||e!==void 0&&e!==""&&!i(e)||n!==null&&!i(n)||typeof o!="boolean")return a(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");let s=await U();if(s!==null&&[t,e,n].includes(s))return a(409,"instructions","\u5199\u4F5C\u504F\u597D\u4E0D\u5728\u6587\u6863\u76EE\u5F55\u91CC\uFF0C\u4E0D\u80FD\u79FB\u52A8\uFF0C\u4E0B\u9762\u4E5F\u4E0D\u80FD\u653E\u6587\u6863");let l=await sn(c,t,{parent:e,after:n,first:o});if(l.written&&L(),!l.ok){let[u,f]={missing:[404,"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"],parent:[404,"\u627E\u4E0D\u5230\u8981\u653E\u5230\u5B83\u4E0B\u9762\u7684\u6587\u6863"],after:[404,"\u627E\u4E0D\u5230\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6587\u6863"],level:[409,"\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6587\u6863\u4E0D\u5728\u8FD9\u4E00\u5C42"],itself:[409,"\u6587\u6863\u4E0D\u80FD\u653E\u5728\u5B83\u81EA\u5DF1\u540E\u9762"],inside:[409,"\u6587\u6863\u4E0D\u80FD\u79FB\u5230\u5B83\u81EA\u5DF1\u6216\u5B83\u4E0B\u9762\u7684\u6587\u6863\u4E0B\u9762"],"cross-workspace":[409,"\u8DE8\u5DE5\u4F5C\u533A\u8BF7\u590D\u5236\uFF0C\u4E0D\u80FD\u53EA\u79FB\u52A8\u76EE\u5F55\u4F4D\u7F6E"]}[l.reason];return a(u,l.reason,f)}return[200,{ok:!0,...l,outline:await R()}]},async create({title:t,description:e,parent:n="",after:o=null,first:r=!1,language:i}){let s=typeof t=="string"?t.replace(/\s+/g," ").trim().slice(0,200):"",l=await Jt(c);return await Z(l),await b.create(l,s,typeof e=="string"&&e.trim()?e.trim():"\u65B0\u6587\u6863",{lang:Gt(i)}),await Lt(l,{parent:n,after:o,first:r}),[200,{ok:!0,report:await O(l)}]},async instructions({title:t,description:e,language:n}){let o=await U();if(o)return[200,{ok:!0,report:await O(o)}];let r=await q(Pn),i=(s,l)=>typeof s=="string"&&s.trim()?s.trim().slice(0,200):l;return await b.create(r,i(t,"\u5199\u4F5C\u504F\u597D"),i(e,"Agent \u6BCF\u6B21\u5199\u62A5\u544A\u524D\u90FD\u4F1A\u5148\u8BFB\u7684\u5199\u4F5C\u504F\u597D"),{lang:Gt(n),page:!0}),await mt(r,"instructions"),[200,{ok:!0,report:await O(r)}]},async components({id:t,hidden:e,shown:n,disabled:o,unlisted:r,net:i,pack:s,enabled:l}){try{return[200,{ok:!0,...await A.write(s!==void 0?{pack:s,enabled:l}:{id:t,hidden:e,shown:n,disabled:o,unlisted:r,net:i})}]}catch(u){return a(409,"components",u)}},async duplicate({slug:t,suffix:e,untitled:n}){if(typeof t!="string"||!T.test(t)||!await F(t))return a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let o=await Jt(c);await Z(o),await Ht(c,t,I(o),o);let{title:r}=await O(t),i=r||(typeof n=="string"&&n.trim()?n.trim().slice(0,50):"\u672A\u547D\u540D\u6587\u6863"),s=await w.renameReport(o,`${i}${typeof e=="string"&&e.length>0&&e.length<=20?e:"\uFF08\u526F\u672C\uFF09"}`),l=await R(),[u,f]=Object.entries(l.children).find(([,h])=>h.includes(t))??["",null];return await Pt(o,u,f?f.indexOf(t)+1:1/0),[200,{ok:!0,report:await O(o),notes:s.notes??[]}]},async"copy-from"({sourceWs:t,slug:e,parent:n="",index:o=0}){let r=typeof t=="string"?X(t):{};if(!r.root||t===m||typeof e!="string"||!T.test(e)||typeof n!="string"||!ft(n)&&!kn.test(n)||!Number.isInteger(o)||o<0)return a(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");let i=await pe(r.root);if(!Object.values(i.children).some(d=>d.includes(e)))return a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let s=[],l=d=>{if(!T.test(d)||s.includes(d))throw new Error("\u6587\u6863\u76EE\u5F55\u7684\u7ED3\u6784\u4E0D\u5BF9\uFF1A\u6BCF\u4EFD\u6587\u6863\u53EA\u80FD\u51FA\u73B0\u4E00\u6B21");s.push(d);for(let p of i.children[d]??[])l(p)};l(e);let u=new Map;for(let d of s){let p;do p=await Jt(c);while([...u.values()].includes(p));u.set(d,p)}let f=g.join(Ft(c).gallery,`copy-${_t(8).toString("hex")}`),h=[];try{await j.mkdir(f,{recursive:!0});let d=new Set;for(let x of s)for(let H of await Ht(r.root,x,g.join(f,u.get(x)),u.get(x),{names:u}))d.add(H);let p=[];if(d.size){let x=Wt(r.root),H=Wt(c);for(let E of d){let C=x.packages.get(E),et=H.packages.get(E);if(!C||et&&et.stamp!==C.stamp||H.problems.has(E))throw Object.assign(new Error,rt("\u81EA\u5B9A\u4E49\u5757 {0} \u7F3A\u5931\u6216\u7248\u672C\u51B2\u7A81\uFF0C\u672A\u590D\u5236",E));if(et)continue;let yt=g.join(f,"packages",...E.split("/"));await j.cp(C.folder,yt,{recursive:!0,force:!1,errorOnExist:!0}),p.push({staged:yt,to:g.join(Ft(c).components,...E.split("/"))})}}return await tt(async()=>{let x=await R();if((ft(n)?mn(x.groups.find(E=>pt(E.id)===n),m):pn(n,m))!==m||(ft(n)?!x.groups.some(E=>pt(E.id)===n&&!E.extension):!Object.values(x.children).some(E=>E.includes(n))))throw new Error("\u627E\u4E0D\u5230\u8981\u653E\u5230\u5B83\u4E0B\u9762\u7684\u6587\u6863");for(let{staged:E,to:C}of p){if(await K(C))throw new Error("\u6587\u6863\u76EE\u5F55\u521A\u5728\u522B\u5904\u6539\u8FC7");await j.mkdir(g.dirname(C),{recursive:!0}),await j.rename(E,C),h.push(C)}for(let E of s){let C=u.get(E);await j.rename(g.join(f,C),I(C)),h.push(I(C))}nt(c),jt(x,u.get(e),n,o);for(let E of s)i.children[E]?.length&&(x.children[u.get(E)]=i.children[E].map(C=>u.get(C)));await Y(x)}),[200,{ok:!0,slug:u.get(e),count:s.length}]}catch(d){for(let p of h)await j.rm(p,{recursive:!0,force:!0});return nt(c),a(409,"copy",d.text?d:d.message)}finally{await j.rm(f,{recursive:!0,force:!0})}},async look({slug:t,look:e}){if(typeof t!="string"||!T.test(t)||!await F(t))return a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");if(t===await U())return a(409,"instructions","\u5199\u4F5C\u504F\u597D\u6CA1\u6709\u5B57\u4F53\u4E0E\u5E03\u5C40");if(e!==null&&(typeof e!="object"||Array.isArray(e)))return a(400,"look","\u5B57\u4F53\u4E0E\u5E03\u5C40\u4E0D\u5BF9");let n=W(t).json,o=null;try{o=JSON.parse(await j.readFile(n,"utf8"))}catch{}if(!o||typeof o!="object"||Array.isArray(o))return a(409,"metadata","\u8FD9\u4EFD\u6587\u6863\u7684\u6807\u9898\u548C\u8BF4\u660E\u8BFB\u4E0D\u51FA\u6765");let r=Ee(o,Bn(e,qt(c)));return JSON.stringify(r)!==JSON.stringify(o)&&await z(n,`${JSON.stringify(r,null,2)}
|
|
11
|
-
`),[200,{ok:!0,report:await O(t)}]},async looks({slug:t}){if(typeof t!="string"||!T.test(t)||!await F(t))return a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let e=await U();if(t===e)return a(409,"instructions","\u5199\u4F5C\u504F\u597D\u6CA1\u6709\u5B57\u4F53\u4E0E\u5E03\u5C40");let n=await M(W(t).json);if(!n||typeof n!="object"||Array.isArray(n))return a(409,"metadata","\u8FD9\u4EFD\u6587\u6863\u7684\u6807\u9898\u548C\u8BF4\u660E\u8BFB\u4E0D\u51FA\u6765");let o=qt(c),r=Dt(n.look,o);try{await Kn(c,r)}catch(u){return a(409,"workspace",u)}let i=0,s=(await An(c)).filter(u=>u!==e).map(u=>({json:W(u).json,self:u===t})),l=(await ht()).filter(({kind:u})=>u==="document").map(({id:u})=>({json:vt(g.join(N,u,"report")).json,self:!1}));for(let{json:u,self:f}of[...s,...l])for(let h=0;h<3;h++){let d=await j.readFile(u,"utf8").catch(()=>null),p=null;try{p=JSON.parse(d??"")}catch{}if(!p||typeof p!="object"||Array.isArray(p)||!Object.hasOwn(p,"look")||p.instructions===!0)break;let x=await z(u,`${JSON.stringify(Ee(p,{}),null,2)}
|
|
12
|
-
`,{expect:d}).catch(()=>null);if(x===null)break;if(x){!f&&Object.keys(Vn(p.look)).length>0&&!Un(Dt(p.look,o),r)&&i++;break}}return[200,{ok:!0,look:r,replaced:i,report:await O(t)}]},async head({order:t}){let e=wn(t);return e?(await tt(()=>un(c,e)),L(),[200,{ok:!0,head:await xe(c)}]):a(400,"head","\u4FA7\u680F\u5934\u90E8\u7684\u987A\u5E8F\u4E0D\u5BF9")},async"new-page"({title:t,after:e=null,language:n}){let o=typeof t=="string"?t.replace(/\s+/g," ").trim():"";if(!o||o.length>200)return a(400,"title","\u6807\u9898\u4E0D\u80FD\u662F\u7A7A\u7684\uFF0C\u4E5F\u4E0D\u80FD\u8D85\u8FC7 200 \u4E2A\u5B57");if(e!==null&&(typeof e!="string"||!T.test(e)))return a(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");let r=await Gn(c);return await Fn(r,o,{root:c,blank:!0,after:e,...Gt(n)?{lang:Gt(n)}:{}}),L(),[200,{ok:!0,page:await Zt(r,c)}]},async rename({slug:t,title:e,kind:n="document"}){if(typeof t!="string"||!T.test(t))return a(400,"slug","\u6587\u6863\u540D\u4E0D\u5BF9");if(n==="page"){let r;try{r=await Mn(t,e,c)}catch{return a(400,"title","\u6807\u9898\u4E0D\u80FD\u662F\u7A7A\u7684\uFF0C\u4E5F\u4E0D\u80FD\u8D85\u8FC7 200 \u4E2A\u5B57")}return r?[200,{ok:!0,page:r}]:a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762")}let o=await w.renameReport(t,e);return o.ok?[200,{ok:!0,report:await O(t),notes:o.notes}]:a({title:400,missing:404}[o.reason]??409,o.reason,o.message??"\u6539\u540D\u6CA1\u6709\u6210\u529F")},async trash({slug:t,kind:e="document"}){if(typeof t!="string"||!T.test(t))return a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");if(e==="page")return Le(t);if(e==="link")return Ne(t);if(t===await U())return a(409,"instructions","\u5199\u4F5C\u504F\u597D\u4E0D\u80FD\u79FB\u5230\u56DE\u6536\u533A");if(!await F(t))return a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let{title:n}=await O(t),o=`${Date.now().toString(36)}-${_t(3).toString("hex")}`,r=await R(),{parent:i,index:s}=await te(t);try{await j.mkdir(g.join(N,o),{recursive:!0}),await y(t,g.join(N,o,"report"))}catch(u){throw await tt(()=>Y(r)),await j.rm(g.join(N,o),{recursive:!0,force:!0}).catch(()=>{}),u}let l={id:o,kind:"document",slug:t,title:n,at:Date.now(),parent:i,index:Number.isFinite(s)?s:-1};return await z(g.join(N,o,"entry.json"),`${JSON.stringify(l,null,2)}
|
|
13
|
-
`),[200,{ok:!0,entry:l}]},async restore({id:t}){let e=typeof t=="string"&&ve.test(t)?await ee(t):null;if(!e)return a(404,"missing","\u56DE\u6536\u533A\u91CC\u6CA1\u6709\u8FD9\u4E00\u9879");if(e.kind==="page")return Ie(e);if(e.kind==="link")return $e(e);let n=g.join(N,t,"report"),o=await k(e.slug,n),r=o?e.slug:await kt(e);return o?await At(await j.readdir(n),n,I(r)):await at(n,I(r)),r!==e.slug&&await it(r,e.slug),await j.rm(g.join(N,t),{recursive:!0,force:!0}),await Pt(r,e.parent,e.index<0?1/0:e.index),[200,{ok:!0,report:await O(r),entry:{...e,kind:"document",slug:r}}]},async destroy({id:t}){let e=typeof t=="string"&&ve.test(t)?await ee(t):null;return e?((e.kind??"document")==="document"&&!await F(e.slug)&&await Z(e.slug),await j.rm(g.join(N,t),{recursive:!0,force:!0}),[200,{ok:!0}]):a(404,"missing","\u56DE\u6536\u533A\u91CC\u6CA1\u6709\u8FD9\u4E00\u9879")},async link({url:t,title:e,icon:n=null,parent:o,after:r=null,first:i=!1},{port:s,wait:l=!1}={}){let u=St({url:t,title:e,icon:n});if(u.refused)return a(400,u.refused,u.message);if(Xt(u.value.url,s))return a(409,"own","\u8FD9\u662F Gallery \u81EA\u5DF1\u7684\u5730\u5740\uFF0C\u8BF7\u76F4\u63A5\u94FE\u63A5\u6587\u6863");if(o!=null&&typeof o!="string"||r!==null&&typeof r!="string"||typeof i!="boolean")return a(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");let f=await tt(async()=>{let d=await R(),p=Re(d,{parent:o,after:r,first:i||o==null&&r===null});if(p.refused)return p;let x=await q(xn(u.value.title,u.value.url));return await j.mkdir(I(x),{recursive:!0}),await z(g.join(I(x),zt),`${JSON.stringify(u.value,null,2)}
|
|
14
|
-
`),jt(d,x,p.parent,p.index),await Y(d),{slug:x,parent:p.parent,index:p.index}});if(f.refused)return a(...f.refused);let h=ne(f.slug,u.value.url);return l&&await h,[200,{ok:!0,link:await S(f.slug),parent:f.parent,index:f.index,outline:await R()}]},async"link-set"({slug:t,url:e,title:n,icon:o},{port:r,wait:i=!1}={}){let s=typeof t=="string"&&T.test(t)?await Qt(I(t)):null;if(!s)return a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u94FE\u63A5");let l=e??s.url,u=St({url:l,title:n??s.title,icon:o===void 0?s.icon??null:o,siteIcon:s.siteIcon??null});if(u.refused)return a(400,u.refused,u.message);let f=u.value.url!==s.url;if(f&&Xt(u.value.url,r))return a(409,"own","\u8FD9\u662F Gallery \u81EA\u5DF1\u7684\u5730\u5740\uFF0C\u8BF7\u76F4\u63A5\u94FE\u63A5\u6587\u6863");if(f&&delete u.value.siteIcon,JSON.stringify(u.value)!==JSON.stringify(s)&&await z(g.join(I(t),zt),`${JSON.stringify(u.value,null,2)}
|
|
15
|
-
`),f){let h=ne(t,u.value.url);i&&await h}return[200,{ok:!0,link:await S(t)}]},async"draft-add"({path:t,confirm:e=!1,after:n=null}){let o=await gn(t),r=typeof n=="string"?n:null;if(o.kind==="missing")return a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u6587\u4EF6\u6216\u6587\u4EF6\u5939");if(o.kind==="plain")return a(409,"plain","\u8FD9\u4E0D\u662F Gallery \u7684\u5E95\u7A3F\u6216\u5DE5\u4F5C\u533A\uFF0C\u53EF\u4EE5\u7528\u300C\u5BFC\u5165\u300D\u628A\u6587\u4EF6\u590D\u5236\u8FDB\u6765");if(o.kind==="nested")return a(409,"nested","\u8FD9\u4EFD\u5E95\u7A3F\u4E0D\u5728\u5B83\u5DE5\u4F5C\u533A\u7684\u7B2C\u4E00\u5C42\uFF08\u5728\u56DE\u6536\u533A\u91CC\uFF0C\u6216\u662F\u5199\u4F5C\u504F\u597D\uFF09\uFF0C\u4E0D\u80FD\u6DFB\u52A0");if(o.kind==="name")return a(409,"name","\u8FD9\u4E2A\u6587\u4EF6\u5939\u7684\u540D\u5B57\u4E0D\u662F Gallery \u6587\u6863\u7684\u5199\u6CD5\uFF08\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u8FDE\u5B57\u7B26\uFF09\uFF0C\u4E0D\u80FD\u6DFB\u52A0");let i=o.kind==="workspace"?o.root:o.kind==="folder"?null:o.root,s=!i||!bn(c).some(h=>dt(h.root,i));if(!i){let h=o.kind==="folder"?o.folder:o.parent;if(yn(h))return a(409,"marker",rt("{0} \u91CC\u7684 gallery.json \u662F\u522B\u7684\u7A0B\u5E8F\u7684\uFF0C\u4E0D\u80FD\u628A\u5B83\u767B\u8BB0\u6210\u5DE5\u4F5C\u533A",h));if(e!==!0)return[409,{ok:!1,reason:"unregistered",folder:h,...Ut(rt("\u4F1A\u628A {0} \u767B\u8BB0\u6210\u4E00\u4E2A\u5DE5\u4F5C\u533A\uFF08\u5728\u91CC\u9762\u653E gallery.json \u548C .gallery/\uFF09",h))}];if(!(await Nn(h)).ours)return a(409,"marker",rt("{0} \u91CC\u7684 gallery.json \u662F\u522B\u7684\u7A0B\u5E8F\u7684\uFF0C\u4E0D\u80FD\u628A\u5B83\u767B\u8BB0\u6210\u5DE5\u4F5C\u533A",h));i=h}let l=o.kind==="workspace"||o.kind==="folder";if(dt(i,c))return[200,{ok:!0,kind:l?"workspace":"draft",own:!0,existing:!0,...l?{column:Tt}:{entry:o.slug}}];let u=await vn(i,{force:!0}).catch(()=>"failed"),f=X(Ct(i));return f.refused==="ambiguous"?a(409,"ambiguous",rt("\u672C\u673A\u767B\u8BB0\u7684 {0} \u4E2A\u5DE5\u4F5C\u533A\u7F16\u53F7\u76F8\u540C\uFF08{1}\uFF09\uFF0C\u5148\u7528 gallery workspaces --forget \u53BB\u6389\u5176\u4E2D\u4E00\u4E2A",f.roots.length,Ct(i))):!f.root||!dt(f.root,i)?u==="temporary"?a(409,"temporary","\u8FD9\u4E2A\u5DE5\u4F5C\u533A\u5728\u7CFB\u7EDF\u7684\u4E34\u65F6\u6587\u4EF6\u5939\u91CC\uFF0C\u4E0D\u80FD\u6DFB\u52A0"):a(409,"registry","\u6CA1\u80FD\u628A\u5B83\u7684\u5DE5\u4F5C\u533A\u8BB0\u8FDB\u672C\u673A\u7684\u767B\u8BB0\u8868"):(nt(i),l?[200,{ok:!0,kind:"workspace",...await hn(c,i,{changed:L,after:r})}]:[200,{ok:!0,kind:"draft",...await ye(c,i,o.slug,{changed:L,pick:!0,after:r,fresh:s})}])},async"draft-join"({root:t,slug:e}){if(typeof t!="string"||typeof e!="string"||!T.test(e))return a(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");if(dt(t,c))return a(409,"own","\u8FD9\u662F\u5F53\u524D\u7684\u5DE5\u4F5C\u533A");let n=X(Ct(t));return!n.root||!dt(n.root,t)?a(409,"registry","\u8FD9\u4E2A\u5DE5\u4F5C\u533A\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC"):await K(vt(g.join(t,e)).html)?(nt(t),[200,{ok:!0,...await ye(c,t,e,{changed:L})}]):a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863")},async export({slug:t}){if(typeof t!="string"||!T.test(t)||!await K(J(t)))return a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let{problems:e=[],file:n,refused:o}=await b.export(t);return o?a(o.reason==="missing"?404:409,o.reason,o.message):e.length?a(422,"check",Qn(e)):[200,{ok:!0,path:Dn(n)}]}},oe={async frameable({url:t},{port:e}){let n=typeof t=="string"?St({url:t,title:"-"}):{refused:"url"};return n.refused?a(400,"url","\u8FD9\u4E0D\u662F\u4E00\u4E2A\u7F51\u5740"):Xt(n.value.url,e)?[200,{ok:!0,frameable:!1,reason:"own"}]:[200,{ok:!0,...await _e(n.value.url)}]},async elsewhere({ws:t}){let e=typeof t=="string"?X(t):{refused:"unknown"};if(e.refused)return a(409,e.refused,e.refused==="ambiguous"?"\u672C\u673A\u767B\u8BB0\u7684\u5DE5\u4F5C\u533A\u91CC\u6709\u4E24\u4E2A\u7528\u7684\u662F\u540C\u4E00\u4E2A\u7F16\u53F7\uFF0C\u5148\u7528 gallery workspaces --forget \u53BB\u6389\u5176\u4E2D\u4E00\u4E2A":"\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A\u5B83\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC");let n=await G.serverOf(e.root);return n.refused?a(409,n.refused,n.message):[200,{ok:!0,origin:`http://127.0.0.1:${n.port}`}]},async"draft-command"({ws:t,name:e,...n}){let o=typeof t=="string"?X(t):{refused:"unknown"};if(o.refused)return a(409,o.refused,"\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A\u5B83\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC");let r=await G.forward(o.root,e,n);return r[1]?.ok&&nt(o.root),r},async"draft-duplicate"({ws:t,slug:e,suffix:n,untitled:o}){if(t===m)return a(409,"self","\u8FD9\u662F\u5F53\u524D\u7684\u5DE5\u4F5C\u533A");let r=typeof t=="string"?X(t):{refused:"unknown"};if(r.refused)return a(409,r.refused,"\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A\u5B83\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC");let[i,s]=await G.forward(r.root,"duplicate",{slug:e,suffix:n,untitled:o});if(!s?.ok)return[i,s];let l=s.report?.slug;if(typeof l!="string"||!T.test(l))return a(502,"answer","\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u7ED9\u51FA\u7ED3\u679C");let u=bt(t,l);return nt(r.root),await Lt(u,{after:bt(t,e)}),[200,{ok:!0,entry:u,report:{...s.report,slug:u,kind:"draft",workspace:t}}]},async"draft-import"({ws:t,uploads:e,parent:n="",from:o,language:r}){if(t===m)return a(409,"self","\u8FD9\u662F\u5F53\u524D\u7684\u5DE5\u4F5C\u533A");let i=typeof t=="string"?X(t):{refused:"unknown"};if(i.refused)return a(409,i.refused,"\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A\u5B83\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC");let[s,l]=await G.forward(i.root,"import",{uploads:e,parent:n,from:o,language:r});if(!l?.ok)return[s,l];nt(i.root);let u=(Array.isArray(l.reports)?l.reports:[]).filter(h=>typeof h=="string"&&T.test(h)).map(h=>bt(t,h)),f=typeof n=="string"&&T.test(n)?bt(t,n):null;if(f&&u.length&&Object.values((await R()).children).some(h=>h.includes(f)))for(let h of u)await Lt(h,{parent:f});return[200,{...l,reports:u}]},async"draft-create"({ws:t,title:e,description:n,language:o,parent:r="",after:i=null,first:s=!1}){if(t===m)return a(409,"self","\u8FD9\u662F\u5F53\u524D\u7684\u5DE5\u4F5C\u533A");let l=typeof t=="string"?X(t):{refused:"unknown"};if(l.refused)return a(409,l.refused,"\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A\u5B83\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC");let[u,f]=await G.forward(l.root,"create",{title:e,description:n,language:o});if(!f?.ok)return[u,f];let h=f.report?.slug;if(typeof h!="string"||!T.test(h))return a(502,"answer","\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u7ED9\u51FA\u7ED3\u679C");let d=bt(t,h);return nt(l.root),await Lt(d,{parent:r,after:i,first:s}),[200,{ok:!0,entry:d,report:{...f.report,slug:d,kind:"draft",workspace:t}}]},async reveal({entry:t,ws:e,page:n}){let o=je(),r=null;return typeof n=="string"?r=T.test(n)?xt(n,c).folder:null:typeof t=="string"&&Kt(t)?r=(await Oe(t,o)).folder:e===m?r=g.resolve(c):typeof e=="string"&&(r=X(e,o).root??null),!r||!await K(r)?a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u6587\u4EF6\u5939"):[200,{ok:!0,path:r,...await de(r)}]},async title({url:t}){let e=typeof t=="string"?St({url:t,title:"-"}):{refused:"url"};if(e.refused)return a(400,"url","\u8FD9\u4E0D\u662F\u4E00\u4E2A\u7F51\u5740");let n=B?await B.title(e.value.url).catch(()=>""):"",o=typeof n=="string"?n:n?.title,r=["auth","unknown"].includes(n?.reason)?n.reason:void 0;return[200,{ok:!0,title:typeof o=="string"?o.slice(0,200):"",...r?{reason:r}:{}}]}};function Te(t,e,n){if(t.method==="GET"&&Object.hasOwn(re,n)){let r=t.headers.host??"",i=t.socket.localPort;return r!==`127.0.0.1:${i}`&&r!==`localhost:${i}`?Q(e,403,{ok:!1,reason:"host"}):re[n](new URL(t.url??"/","http://localhost").searchParams).then(([s,l])=>Q(e,s,l),s=>Q(e,...a(500,"read",s)))}if(t.method==="POST"&&n==="stop")return w.respond(async r=>{let i=await w.check(r);return i.error?i.error:_.kind!=="cli"||typeof _.stop!="function"?a(409,"dev","\u8FD9\u662F npm run dev \u7684\u670D\u52A1\u5668\uFF1A\u5728\u8FD0\u884C\u5B83\u7684\u5730\u65B9\u505C\u6B62\u5B83"):(e.once("finish",()=>_.stop()),[200,{ok:!0,pid:process.pid}])})(t,e);if(t.method==="POST"&&n==="pack-install")return w.respond(async r=>{let i=await w.check(r,Zn);if(i.error)return i.error;if(!A?.install)return a(404,"unknown");try{return[200,{ok:!0,...A.install(i.body??{})}]}catch(s){if(!s.code)throw s;return a(409,s.code,s)}})(t,e);if(t.method==="POST"&&n==="todo")return(async()=>{let r=await w.check(t);if(r.error)return r.error;let{slug:i,items:s}=r.body??{};return typeof i!="string"||!T.test(i)||!Array.isArray(s)?[400,{ok:!1,reason:"body"}]:!await F(i)||i===await U()?a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"):w.setTodos(i,s)})().then(([r,i])=>Q(e,r,i),r=>Q(e,...a(500,"write",r.message)));if(t.method==="POST"&&(n==="draft-export"||n==="draft-upload"))return(async()=>{let r=n==="draft-upload",i=new URL(t.url??"/","http://localhost").searchParams,s={};if(r){let f=w.checkHeaders(t);if(f)return f;if(!/^application\/octet-stream\b/i.test(t.headers["content-type"]??""))return[415,{ok:!1,reason:"type"}]}else{let f=await w.check(t);if(f.error)return f.error;s=f.body&&typeof f.body=="object"?f.body:{}}let l=r?i.get("ws"):s.ws,u=typeof l=="string"?X(l):{refused:"unknown"};return u.refused?a(409,u.refused,"\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A\u5B83\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC"):l===m?a(409,"self","\u8FD9\u662F\u5F53\u524D\u7684\u5DE5\u4F5C\u533A"):G.relay(u.root,r?"upload":"export",{body:s,query:{name:i.get("name")??void 0},request:t,response:e})})().then(r=>{r&&(t.resume(),Q(e,...r))},r=>{t.resume(),e.headersSent?e.destroy():Q(e,...a(500,"read",r))});let o={port:t.socket.localPort};return t.method==="POST"&&Object.hasOwn(gt,n)?w.respond(async r=>{let i=await w.check(r);if(i.error)return i.error;let s=i.body&&typeof i.body=="object"?i.body:{};return typeof s.workspace=="string"&&!dt(s.workspace,c)?a(409,"elsewhere","\u8FD9\u4E2A\u9884\u89C8\u670D\u52A1\u5668\u7BA1\u7684\u662F\u53E6\u4E00\u4E2A\u76EE\u5F55\u7684\u6587\u6863"):gt[n](s,o)})(t,e):t.method==="POST"&&Object.hasOwn(oe,n)?(async()=>{let r=await w.check(t);return r.error?r.error:oe[n](r.body&&typeof r.body=="object"?r.body:{},o)})().then(([r,i])=>Q(e,r,i),r=>Q(e,...a(500,"read",r))):Q(e,404,{ok:!1,reason:"unknown"})}return{handle:Te,outline:R,trashEntries:ht,place:Pt,freeSlug:q,index:V,run:(t,e,n={})=>Object.hasOwn(gt,t)?gt[t](e??{},{wait:!0,...n}):Promise.resolve(a(404,"unknown","\u6CA1\u6709\u8FD9\u4E2A\u547D\u4EE4")),close:()=>G.close()}}export{Ur as a};
|
package/dist/chunk-XMKHCUI6.mjs
DELETED
|
@@ -1,15 +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 ke,b as X,c as Q,f as ye,g as L,h as xe,i as tt,l as Se,m as Ne}from"./chunk-SAHS56QM.mjs";import{a as $t}from"./chunk-KH24LWAT.mjs";import{b as fe,c as wt,e as K,f as he,i as ue,j as pe,m as me,n as ge,o as $e,p as we,q as be,r as bt}from"./chunk-YFJU3O7G.mjs";import{a as mt}from"./chunk-NWRZXELO.mjs";import{a as oe,b as se,c as ne,d as ie,e as ae,f as re,g as ce,h as le,l as de}from"./chunk-G4YP7GVC.mjs";import{b as gt,c as Xt,d as Qt,e as te,g as ee}from"./chunk-DHB7UZ7F.mjs";import{a as w,b as Yt,c as qt}from"./chunk-2RKIHJI2.mjs";import{g as E,j as Jt,l as Vt,m as Zt}from"./chunk-VG5JEIUQ.mjs";import{existsSync as yo,readFileSync as yi,readdirSync as xi}from"node:fs";import S from"node:fs/promises";import N from"node:path";function ve(t){if(!t||!Array.isArray(t.lines))throw new Error("diff: lines must be an array.");t.lines.forEach(e=>{if(!e||!["added","removed","unchanged"].includes(e.type)||typeof e.content!="string"||/[\r\n]/.test(e.content))throw new Error("diff: each line needs a valid type and single-line content.");if(e.lineNumber!=null&&(!Number.isInteger(e.lineNumber)||e.lineNumber<1))throw new Error("diff: lineNumber must be a positive integer.")})}import{BODY as yt,isInstance as Bo}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as Ho}from"../browser/shared/components/installed.mjs";import{attr as F,elementsOf as Oe,hasClass as Ko,walk as xt}from"../browser/shared/html-tree.mjs";import{CHART_DATA as Go,CHART_KEY as Jo,CHART_SOURCE as C,VIEW_FROM as et,cellWords as Vo,rowsReading as Ee,tableRows as Zo}from"../browser/shared/table-chart.mjs";var Yo=t=>t.tagName==="script"&&(F(t,"type")??"").trim().toLowerCase()==="application/json",Te=t=>t.nodeName==="#text"?t.value:(t.childNodes??[]).map(Te).join("");function qo(t){let e=t;for(;e&&e.tagName!=="figure";)e=e.parentNode;let s=e?Oe(e).find(o=>/^h[2-4]$/.test(o.tagName)):null;return s?Vo(Te(s)):""}function Le(t,e,s=w(t)){let o=[];return xt(s,n=>{let i=e(n);if(i===void 0||!n.sourceCodeLocation)return;let r=n.childNodes.find(Yo);o.push({type:i,line:n.sourceCodeLocation.startLine,text:r?r.childNodes.map(c=>c.value??"").join(""):null,source:F(n,Go),tag:n.tagName,holder:n.parentNode?.tagName,title:qo(n)})},yt),o}var Xo=t=>t.tagName==="ol"&&F(t,"data-doc-chart")==="flow",ot=(t,e)=>Le(t,s=>Xo(s)?void 0:F(s,"data-doc-chart"),e),Qo=t=>Le(t,e=>Ko(e,"doc-diff")?"diff":void 0);function G(t){let e=new Map;return xt(t,s=>{let o=F(s,C);if(o===void 0||!s.sourceCodeLocation)return;(e.get(o)??e.set(o,[]).get(o)).push({line:s.sourceCodeLocation.startLine,offset:s.sourceCodeLocation.startOffset,table:Oe(s).find(i=>i.tagName==="table")??null})},{...yt,inTemplates:!1}),e}function St(t,e){let s=e.get(t)??[];if(s.length===0)return{error:`no table's frame carries ${C}="${t}", so the chart has nothing to draw: put the table back, or delete the card`};if(s.length>1)return{error:`${s.length} tables carry ${C}="${t}" (lines ${s.map(({line:c})=>c).join(", ")}): a key names one table (the chart draws the first); take it off the copies`};let[{line:o,table:n}]=s;if(!n)return{error:`the frame carrying ${C}="${t}" (line ${o}) holds no table`};let i=$t(n),r=Zo(i);return r.error?{error:`its table (line ${o}) ${r.error}`}:{...r,line:o,cells:i}}function Nt(t){let e=[t,...L(t).filter(({files:n})=>n.includes("kit.js")).map(n=>tt(n,"kit.js")??"")].join(`
|
|
3
|
-
`),s=new Set([...e.matchAll(/DocCharts\.define\(\s*(["'`])([a-z][a-z0-9-]*)\1/g)].map(n=>n[2])),o=new Set([...e.matchAll(/DocCharts\.define\(\s*(["'`])([^"'`\n]*)\1/g)].map(n=>n[2]).filter(n=>!s.has(n)));return{defined:s,misnamed:o}}function vt(t){let e=w(t),s=[],{defined:o,misnamed:n}=Nt(t),i=null;for(let{type:r,line:c,text:l,source:a,tag:d,holder:f}of ot(t,e)){let u=`data-doc-chart="${r}" (line ${c})`;if(d==="table"){s.push(f==="figure"?`${u} 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`:`${u} 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(n.has(r)){s.push(`${u}: the document's script defines "${r}" 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(!o.has(r)){s.push(`${u}: the document's script does not define "${r}": define it once in the document's <script> with DocCharts.define("${r}", ({ host, data, tokens, width, height }) => { \u2026 }) (references/writing-html.md, "Figures and charts")`);continue}if(a!==void 0){if(l!==null){s.push(`${u}: a chart drawn from a table takes its data from the table: take its <script type="application/json"> out`);continue}let h=St(a,i??=G(e));h.error&&s.push(`${u}: ${h.error}`);continue}if(l===null){s.push(`${u} needs its data in a <script type="application/json"> child`);continue}try{JSON.parse(l)}catch(h){s.push(`${u}: its data is not valid JSON (${h.message})`)}}s.push(...Ce(e,i??=G(e)).failures);for(let{line:r,text:c}of Qo(t)){if(c===null)continue;let l=`.doc-diff (line ${r})`;try{ve(JSON.parse(c))}catch(a){s.push(`${l}: ${a instanceof SyntaxError?`its options are not valid JSON (${a.message})`:a.message}`)}}return s}function Ae(t,{written:e=t}={}){let s=w(t),o=[],{defined:n}=Nt(t),i=null,r=null;for(let{type:c,line:l,text:a,source:d,title:f,tag:u}of ot(t,s)){if(d===void 0||u==="table"||a!==null||!n.has(c))continue;let h=`data-doc-chart="${c}" (line ${l})`;if(!f){r??=new Set(e===t?[]:ot(e).map(k=>k.source).filter(k=>k!==void 0));let b=e!==t&&!r.has(d);o.push(`${h}: this chart card has no title: ${b?"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 m=St(d,i??=G(s));if(m.error)continue;let{blank:p,twice:g}=Ee(m.cells,m.data);p&&o.push(`${h}: its table's header (line ${m.line}) has a cell with no words, so that column's values are keyed "" in data: write the column's name there`),g.length>0&&o.push(`${h}: its table's header (line ${m.line}) names ${g.map(b=>`"${b}"`).join(", ")} twice, so data keeps the later column's value under it: give each column a name of its own`)}return o.push(...Ce(s,i??=G(s)).notes),o}var kt=500;function Ce(t,e){let s=[],o=[],n=E().packages;return xt(t,i=>{let r=F(i,et);if(r===void 0||!i.sourceCodeLocation)return;let c=F(i,Ho),l=`${c??i.tagName} (line ${i.sourceCodeLocation.startLine})`;if(!Bo(i))return void s.push(`<${i.tagName}> (line ${i.sourceCodeLocation.startLine}) carries ${et}="${r}", which only a view of a table carries: an instance of a custom block (<div data-doc-component="<scope>/<name>">) whose block's needs hold "tables"; take it off`);if(!Jo.test(r))return void s.push(`${l}: ${et}="${r}" is no key: a letter, then letters, digits, "_" or "-", 32 at most, as the table's frame writes it in ${C}`);let a=e.get(r)??[];if(a.length===0)return void s.push(`${l}: no table's frame carries ${C}="${r}", so the view has no table to read: put the table back, or delete the view`);if(a.length>1)return void s.push(`${l}: ${a.length} tables carry ${C}="${r}" (lines ${a.map(({line:g})=>g).join(", ")}): a key names one table (the view reads the first); take it off the copies`);let[{line:d,offset:f,table:u}]=a;if(!u)return void s.push(`${l}: the frame carrying ${C}="${r}" (line ${d}) holds no table`);i.sourceCodeLocation.startOffset<f&&o.push(`${l} stands before the table it reads (${C}="${r}", line ${d}): it works there, but each block's writing.md writes the table first and the view after it, as its example does: move the view below the table, unless the document is meant to open on it`);let h=n.get(c)?.needs;h&&!h.includes("tables")&&o.push(`${l} carries ${et}="${r}", but its block's needs hold no "tables", so it reads no table: add "tables" to needs in its component.json, or take the key off`);let m=$t(u);m.merged&&o.push(`${l}: its table (line ${d}) has merged cells, which no view reads, so the view shows nothing of it: write each value in its own cell`);let p=m.names?m.rows.length:Math.max(0,m.rows.length-1);p>kt&&o.push(`${l}: its table (line ${d}) has ${p} rows: every view of a table reads it again as it is typed in, and past ${kt} rows that slows typing in it; split it, or keep what a view shows to ${kt} rows`)},yt),{failures:s,notes:o}}function ze(t){let e=w(t),s=[],o=[],{defined:n}=Nt(t),i=null,r=(c,l)=>`${c} ${l}${c===1?"":"s"}`;for(let{type:c,line:l,text:a,source:d,tag:f}of ot(t,e)){if(d===void 0||f==="table"||a!==null||!n.has(c))continue;let u=St(d,i??=G(e));if(u.error)continue;let{rows:h,columns:m,foot:p,extra:g}=Ee(u.cells,u.data),b=`data-doc-chart="${c}" (line ${l})`,k=[r(h,"row")];for(let{name:x,numbers:v,words:T,empty:H}of m){let R=v+T+H,q=v===R&&R>0?"numbers":T===R&&R>0?"words":[v&&r(v,"number"),T&&`${T} as words`,H&&`${H} empty (null)`].filter(Boolean).join(", ")||"no rows";k.push(`"${x}": ${q}`),v>0&&T>0&&o.push(`${b}: its table's column "${x}" (line ${u.line}) reads as numbers in ${r(v,"row")} and as words in ${T}: 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`)}p>0&&o.push(`${b}: its table's <tfoot> (line ${u.line}) holds ${r(p,"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`),g>0&&o.push(`${b}: ${r(g,"row")} of its table (line ${u.line}) ${g===1?"has":"have"} cells past the header, which the chart does not read: give each column a header cell`),s.push(`${c} (line ${l}) reads its table (line ${u.line}): ${k.join("; ")}`)}return{readings:s,notes:o}}import{BODY as Si,componentOf as Ni,matchesNode as xo}from"../browser/shared/components/index.mjs";import{FLOW as vi}from"../browser/shared/components/list.mjs";import{attr as O,elementsOf as So,walk as M}from"../browser/shared/html-tree.mjs";import{GLYPH_SETS as Oi,ICON_COLORS as No,glyphOf as Ei,glyphValue as Ti,iconKind as Ut,iconMarkup as Li,iconValueOf as Ai}from"../browser/shared/emoji/icon-value.mjs";import ts from"node:vm";import{LINE_START as it,lineStart as es}from"../browser/shared/code-lines.mjs";import{BODY as Me,COMPONENTS as os,FLOWS as ss,instanceSlots as ns,instancesOf as is,isInstance as _,isSlot as Pe,matchesNode as P,ownSlots as as,partOf as Lt,vocabulary as rs}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as A,INSTANCE as cs,PACKAGE_ID as at,SCHEMA as Ot,SLOT as z,schemaAhead as ls}from"../browser/shared/components/installed.mjs";import{packageScript as ds}from"../browser/shared/export-wrap.mjs";import{asDocName as fs,kitNamespace as hs}from"../browser/shared/old-names.mjs";import{shortSheets as us}from"../browser/shared/components/sheets.mjs";import{attr as y,curlyQuoted as ps,hasClass as ms,walk as J}from"../browser/shared/html-tree.mjs";var{authoring:nt,runtime:Ie}=rs(),gs="input, select, textarea, button, details, table",rt=t=>t.sourceCodeLocation?.startLine,$=t=>rt(t)?` (line ${rt(t)})`:"";function je(t){let e=(o,n)=>{let i=Array.from({length:n.length+1},(r,c)=>c);for(let r=1;r<=o.length;r++){let c=i[0];i[0]=r;for(let l=1;l<=n.length;l++){let a=i[l];i[l]=Math.min(i[l]+1,i[l-1]+1,c+(o[r-1]===n[l-1]?0:1)),c=a}}return i[n.length]},[s]=[...nt.keys()].filter(o=>o.startsWith(t.slice(0,7))).map(o=>[o,e(t,o)]).sort((o,n)=>o[1]-n[1]);return s&&s[1]<=3?` (${s[0]}?)`:""}function $s(t,e,s){let{part:o,property:n,min:i}=t.shares,r=new RegExp(`(?:^|;)\\s*${n}\\s*:\\s*([^;]*)`),c=s.map(f=>r.exec(y(f,"style")??"")?.[1].trim()??null),l=c.filter(f=>f!==null);if(l.length===0)return[];let a=`${t.id}${$(e)}`;return l.length<c.length?[`${a}: ${n} on ${l.length} of its ${c.length} ${o}: write it on every one of them, or on none (equal widths)`]:l.map(Number).some(f=>!Number.isFinite(f)||f<i-1e-9||f>1)?[`${a}: ${n} is a share of the row, a number from ${Math.round(i*1e3)/1e3} to 1 (${l.join(", ")})`]:[]}var st={"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)"},ws={[it]:'write it on its <div class="doc-code">',"data-start":`write ${it} 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 bs(t){let e=[],s=t.tagName==="pre"?t.parentNode:t.tagName==="code"&&t.parentNode?.tagName==="pre"?t.parentNode.parentNode:null;if(s?.tagName&&P(s,".doc-code"))for(let[n,i]of Object.entries(ws))y(t,n)!==void 0&&e.push(`${n}${$(t)} on the <${t.tagName}> of a code block does nothing: ${i}`);let o=t.tagName==="div"&&P(t,".doc-code")?y(t,it):void 0;return o!==void 0&&es(o)===null&&e.push(`${it}="${o}"${$(t)}: the number of a code block's first line is a whole number from 1`),e}var Re=ss.join(", "),ks=t=>P(t.parentNode,Re)||t.parentNode?.tagName==="div"&&!y(t.parentNode,"class")&&P(t.parentNode.parentNode,Re);function ys(t,e){let s=[];J(e,n=>s.push(...ps(t,n)));let o=n=>n.replace(/=(\s*)[“”]/,'=$1"').replace(/[“”]$/,'"');return s.map(({written:n,line:i},r)=>r===0?`line ${i}: attribute ${n} uses curly quotes (U+201C/U+201D), which HTML reads as part of the value: write straight quotes, ${o(n)}; an editor keeping a file's \u201C\u2026\u201D style may change them`:`line ${i}: attribute ${n} uses curly quotes too: write ${o(n)}`)}var Fe={details:"write a plain <details> without the class (its <summary>, then what it holds): the export makes it the kit's"},xs="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",Ss='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 Ue(t){let e=[];return J(t,s=>{y(s,A)!==void 0&&e.push(s)},Me),e}var Ns=t=>{let e=t.parentNode;for(;e&&!(_(e)||Pe(e));)e=e.parentNode;return e??null};function vs(t,e){let s=[];return J(t,o=>{let n=y(o,z);if(n===void 0)return;if(_(o))return void s.push(`${z}="${n}"${$(o)} on the instance itself: a slot is an element inside it`);if(!Pe(o))return void s.push(`${z}${$(o)} on a <${o.tagName}>: a slot is a block-level <div> or <section>`);let i=Ns(o),r=i&&_(i)?e?.get(y(i,A)):null;if(!i||!_(i)||r&&We(i,r,o))return void s.push(`${z}="${n}"${$(o)} stands outside any instance's own markup: a slot is a part of a component package's instance, written in its template`);y(o,"data-block-id")!==void 0&&s.push(`${z}="${n}"${$(o)}: a slot is no block: it carries no data-block-id`)}),s}var Os=(t,e)=>{for(let s=e.parentNode;s;s=s.parentNode)if(s===t)return!0;return!1},We=(t,e,s)=>Object.values(e.parts??{}).filter(({edit:o})=>o==="text"||o==="data").some(({at:o})=>Lt(t,o).some(n=>Os(n,s))),_e=(t,e)=>as(t).filter(s=>!We(t,e,s)),Es=t=>t.flatMap(e=>_(e)?at.test(y(e,A))?[]:[`${A}="${y(e,A)}"${$(e)} names no custom block: write <scope>/<name>, the id of a custom block of the workspace's components/ folder`]:[`${A}${$(e)} on a <${e.tagName}>: an instance of a component is a block-level <div> or <section>`]);function Be(t){let e=Ue(t).filter(o=>_(o)&&at.test(y(o,A))),s=e.length>0?E():null;return e.flatMap(o=>{let n=y(o,A),i=s.packages.get(n);if(i&&!ls(y(o,Ot),i.schema))return[];if(i)return[`line ${rt(o)}: <${o.tagName} ${A}="${n}">: ${Ot}="${y(o,Ot)}" 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 r=s.problems.get(n)?.problem,c=r?`package ${n} does not load (${Jt("en",r)})`:`no package ${n} in this workspace (components/${n}/component.json)`;return[`line ${rt(o)}: <${o.tagName} ${A}="${n}">: ${c}: the block shows what it holds, read-only, and moves, copies and deletes whole`]})}function Et(t,e){let s=[];for(let{name:o,value:n}of t.attrs){if(st[o]&&!nt.has(o)){s.push(`${o}${$(t)} is gone: ${st[o]}`);continue}if(o.startsWith("data-doc-")&&!nt.has(o)&&s.push(Ie.has(o)?`${o}${$(t)} is the kit's to set: remove it`:`${o}${$(t)} is no attribute of the kit's${je(o)}`),o==="class"){for(let i of n.split(/\s+/).filter(e))if(!nt.has(i)){if(st[i]){s.push(`class ${i}${$(t)} is gone: ${st[i]}`);continue}s.push(Ie.has(i)?`class ${i}${$(t)} is the kit's to set: remove it`:`class ${i}${$(t)} is no class of the kit's${je(fs(i))}: give a class of the document's own a name of its own (not doc-\u2026)`)}}}return s}var De=t=>t.startsWith("doc-");function Ts(t){try{return new ts.Script(ds(t),{filename:"kit.js"}),null}catch(e){let s=/^kit\.js:(\d+)/.exec(e.stack??"")?.[1];return{message:e.message,line:s?Number(s):null}}}var Tt=new Map;function Ls(t){if(!t.files.includes("kit.js"))return null;if(Tt.get(t.folder)?.stamp!==t.stamp){let e=tt(t,"kit.js"),s=e===null?null:Ts(e),o=e===null?`${t.id}: its kit.js cannot be read`:s&&`${t.id}: its kit.js does not run: ${s.message}${s.line?` (line ${s.line})`:""}`;Tt.set(t.folder,{stamp:t.stamp,failure:o})}return Tt.get(t.folder).failure}function At(t,e=w(t),s=null){let o=ys(t,e),n=Ue(e);o.push(...Es(n));let i=n.length>0?s??E():null,r=i?[...i.packages.values()]:[];i&&o.push(...L(t,i,e).map(Ls).filter(Boolean));for(let a of[...os,...r].filter(d=>d.match&&(d.parts||d.pairs)))for(let d of is(e,a)){if(a.empty&&!(d.childNodes??[]).some(h=>h.tagName||h.nodeName==="#text"&&h.value.trim()))continue;let f=a.id==="sheets"?us(d):null;if(f){o.push(`${a.id}${$(d)} has no tabs and is no short form: ${f.why??"it stands where no block does (in a whole block or a figure)"}; ${xs}`);continue}if(Fe[a.id]&&Object.values(a.parts??{}).some(h=>Lt(d,h.at).length<(h.optional?0:h.min??1))){o.push(`${a.id}${$(d)} carries the kit's class without the kit's parts: ${Fe[a.id]}`);continue}let u={};for(let[h,m]of Object.entries(a.parts??{})){if(m.edit==="flow"&&at.test(a.id)){let b=_e(d,a).filter(k=>y(k,z)===h);b.length===0&&!m.optional&&o.push(`${a.id}${$(d)} has no ${h} (${z}="${h}")`);for(let k of b.slice(1))o.push(`${a.id}${$(k)}: slot "${h}" twice`);u[h]=b.slice(0,1);continue}u[h]=Lt(d,m.at);let p=m.optional?0:m.min??1,g=m.max??1/0;u[h].length<p?o.push(`${a.id}${$(d)} has ${u[h].length===0?"no":`${u[h].length} of`} ${h} (${m.at.replace(":scope > ","")})${u[h].length>0?`, at least ${p}`:""}`):u[h].length>g&&o.push(`${a.id}${$(d)} has ${u[h].length} of ${h}, at most ${g}`)}if(a.only){let h=new Set(a.only.flatMap(m=>u[m]));for(let m of(d.childNodes??[]).filter(p=>p.tagName&&!h.has(p)))o.push(`${a.id}${$(d)} holds a <${m.tagName}>${$(m)}: only its ${a.only.join(", ")} (${a.only.map(p=>a.parts[p].at.replace(":scope > ","")).join(", ")}) go in it`)}if(a.shares&&o.push(...$s(a,d,u[a.shares.part])),at.test(a.id)){let h=Object.entries(a.parts??{}).filter(([,m])=>m.edit==="flow").map(([m])=>m);for(let m of _e(d,a).filter(p=>!h.includes(y(p,z))))o.push(`${a.id}${$(m)}: slot "${y(m,z)}" is no part of its manifest edited as flow`)}for(let{a:h,attrA:m,b:p,attrB:g}of a.pairs??[]){let b=u[h].map(x=>y(x,m)),k=u[p].map(x=>y(x,g));for(let x of new Set(b.filter((v,T)=>b.indexOf(v)!==T)))o.push(`${a.id}${$(d)}: ${h} "${x}" twice`);for(let x of b.filter(v=>!k.includes(v)))o.push(`${a.id}${$(d)}: ${h.replace(/s$/,"")} "${x}" has no ${p.replace(/s$/,"")} (${g}="${x}")`);for(let x of k.filter(v=>!b.includes(v)))o.push(`${a.id}${$(d)}: ${p.replace(/s$/,"")} "${x}" has no ${h.replace(/s$/,"")} (${m}="${x}")`)}}o.push(...vs(e,i?.packages));let c=new Set,l=[];J(e,a=>{if(_(a)){let u=new Set(ns(a));o.push(...Et(a,De)),J(a,h=>o.push(...Et(h,De)),{stop:h=>u.has(h)});return}a.tagName==="pre"&&ks(a)&&o.push(`<pre>${$(a)} straight in the text: a code block is <div class="doc-code"> holding its title (<div class="doc-code-title">) and the <pre>`),o.push(...bs(a)),a.tagName==="a"&&ms(a,"doc-bookmark")&&o.push(`<a class="doc-bookmark">${$(a)} is no bookmark: ${Ss}`),o.push(...Et(a,hs));let d=y(a,"data-doc-bind");d!==void 0&&(d.trim()?P(a,gs)?a.tagName==="button"&&y(a,"value")===void 0?o.push(`data-doc-bind${$(a)} on a button without a value: give it the value a click chooses`):c.add(d.trim()):o.push(`data-doc-bind${$(a)} on a ${a.tagName}: only inputs, selects, textareas, buttons with a value, details and tables hold a key`):o.push(`data-doc-bind${$(a)} names no key`));let f=y(a,"data-doc-show");f!==void 0&&l.push([a,f])},Me);for(let[a,d]of l){let f=d.split(":")[0].trim();!f||!d.includes(":")?o.push(`data-doc-show="${d}"${$(a)}: write key:value`):c.has(f)||o.push(`data-doc-show="${d}"${$(a)}: nothing binds "${f}" (data-doc-bind="${f}")`)}return o.push(...Rs(t,e)),o}var As=/(?<![\\$])\$(?=[^\s$])([^$]*?[^\s$\\])\$(?![$\d])/g,Cs=/(?:(?<![A-Za-z0-9_])[A-Za-z]|[)\]}])_[A-Za-z0-9{]/,zs=t=>/[\\^]/.test(t)||!t.startsWith("{")&&Cs.test(t),Is=new Set(["head","code","pre","kbd","samp","script","style","template","textarea","noscript","svg","math","title","iframe","object"]),js=`.doc-math-inline, .doc-math-block, .doc-code, .doc-diff, [data-doc-math-dollar], [data-doc-chart], ${cs}`;function Rs(t,e){let s=[],o=n=>{for(let i of n.childNodes??[])if(i.nodeName==="#text"&&i.sourceCodeLocation&&i.value.includes("$")){let{startOffset:r,endOffset:c}=i.sourceCodeLocation;for(let l of t.slice(r,c).matchAll(As)){if(!zs(l[1]))continue;let a=l[1].replace(/\s+/g," "),d=a.length>60?`${a.slice(0,59)}\u2026`:a;s.push(`line ${qt(t,r+l.index)}: $${d}$ is not drawn as a formula (single dollars are off: they are money): write \\(${d}\\)`)}}else i.tagName&&!Is.has(i.tagName)&&!P(i,js)&&o(i)};return o(e),s}import V from"node:fs";import W from"node:path";import{COLOR_NAMES as Ks}from"../browser/shared/colors.mjs";import{FOLD_DOTS as Gs}from"../browser/shared/code-folds.mjs";import{kitPublicDirectory as Js,kitSourceDirectory as Vs,release as Zs}from"../browser/shared/paths.mjs";import{FLOW_LABEL as Ua}from"../browser/shared/components/list.mjs";var Fs={"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 He="data-ge-language",_s={"code-title":"--doc-word-code-title"};function Ds(t,e,s,...o){let n=t[s];if(!n)throw new Error(`The kit has no word "${s}" here (src/render/kit/words.js).`);let i=n[e]??n.zh;return o.length===0?i:i.replace(/\{(\d+)\}/g,(r,c)=>c<o.length?String(o[c]):r)}var Ms=`:root[${He}="en"], :root:not([${He}])[lang|="en" i]`;function Ke(){let t=e=>Object.entries(_s).map(([s,o])=>`${o}: ${JSON.stringify(Ds(Fs,e,s))};`).join(" ");return`:root { ${t("zh")} }
|
|
4
|
-
${Ms} { ${t("en")} }`}import{LOOK as Ct,LOOK_ATTRIBUTES as Ps,SERIF_FONT as Ge,SIZE_FACTOR as Us,SPACING as Ws,WIDTH as zt}from"../browser/shared/document-look.mjs";var Je=[["--doc-body-font-size","--doc-body-line-height"],["--doc-small-font-size","--doc-small-line-height"],["--doc-note-font-size","--doc-note-line-height"],["--doc-title-font-size","--doc-title-line-height"],["--doc-h1-font-size","--doc-h1-line-height"],["--doc-h2-font-size","--doc-h2-line-height"],["--doc-h3-font-size","--doc-h3-line-height"],["--doc-h4-font-size","--doc-h4-line-height"],["--doc-card-title-font-size","--doc-card-title-line-height"],["--doc-table-font-size","--doc-table-line-height"]],Bs=["--doc-component-gap","--doc-block-gap","--doc-media-gap","--doc-paragraph-gap","--doc-group-gap","--doc-list-gap"],It="--doc-content-max-width";function Hs(t){let e=new Map;for(let[,s,o]of String(t).matchAll(/^\s*(--doc-[a-z0-9-]+):\s*([^;]+);/gm))e.has(s)||e.set(s,o.trim());return e}var ct=t=>`${Math.round(t)}px`;function lt(t,{size:e="default",spacing:s="default",width:o="default"}={}){let n=a=>{let d=/^(-?[0-9.]+)px$/.exec(t.get(a)??"");if(!d)throw new Error(`src/render/kit/styles/tokens.css: ${a} is no length in px (src/render/look-css.mjs reads it)`);return Number(d[1])},i=Us[e],{leading:r,gaps:c}=Ws[s],l={};if(e!=="default"||s!=="default")for(let[a,d]of Je){let f=n(a)*i;e!=="default"&&(l[a]=ct(f)),l[d]=ct(Math.round(f)+(n(d)-n(a))*i*r)}if(s!=="default"){for(let a of Bs)l[a]=ct(n(a)*c);l["--doc-space"]=String(c)}if(o!=="default"){if(n(It)!==zt.default)throw new Error(`src/render/kit/styles/tokens.css: ${It} is not \u9ED8\u8BA4 \u6B63\u6587\u5BBD\u5EA6's ${zt.default}px (src/shared/document-look.mjs WIDTH)`);l[It]=ct(zt[o])}return l}var U=(t,e)=>`${t} { ${Object.entries(e).map(([s,o])=>`${s}: ${o};`).join(" ")} }`,D=(t,e)=>`[${Ps[t]}="${e}"]`;function Ve(t){let e=Hs(t),s=e.get("--doc-font");if(!s)throw new Error("src/render/kit/styles/tokens.css: no --doc-font (src/render/look-css.mjs keeps it as --doc-sans-font)");let o=[U(`:root${D("font","serif")}`,{"--doc-sans-font":s,"--doc-font":Ge}),U(`:root${D("font","mixed")}`,{"--doc-heading-font":Ge})],[,...n]=Ct.size,[,...i]=Ct.spacing,[,...r]=Ct.width;for(let c of n)o.push(U(`:root${D("size",c)}`,lt(e,{size:c})));for(let c of i)o.push(U(`:root${D("spacing",c)}`,lt(e,{spacing:c})));for(let c of r)o.push(U(`:root${D("width",c)}`,lt(e,{width:c})));for(let c of n)for(let l of i){let a=lt(e,{size:c,spacing:l});o.push(U(`:root${D("size",c)}${D("spacing",l)}`,Object.fromEntries(Je.map(([,d])=>[d,a[d]]))))}return o.join(`
|
|
5
|
-
`)}var Ze=Object.fromEntries(K.filter(t=>t.file).map(t=>[t.file,t.build])),tr=Object.keys(Ze),Z=t=>W.join(Vs,t),Ys=(t,e,s)=>({entryPoints:[Z(t)],bundle:!0,write:!1,format:"iife",platform:"browser",target:"es2022",...typeof e=="function"?e():e,...s}),qs=t=>{let e=Ze[t];if(!e)throw new Error(`src/render/kit-build.mjs: no kit file "${t}"`);return e},dt=new Map;function Xs(t,e){let s=[...e.matchAll(/^@import\s+"\.\/([a-z0-9-]+\.css)";\s*$/gm)].map(i=>i[1]),o=V.readdirSync(W.dirname(Z(t))).filter(i=>i.endsWith(".css")&&i!==W.basename(t)),n=[...o.filter(i=>!s.includes(i)).map(i=>`${i} is not listed`),...s.filter((i,r)=>!o.includes(i)||s.indexOf(i)!==r).map(i=>`${i} is listed but missing, or listed twice`)];if(n.length>0)throw new Error(`src/render/kit/${t}: ${n.join("; ")}`);return s.map(i=>W.join(W.dirname(t),i))}var Qs=t=>t.replace(/@(text|highlight)-colors\b/g,(e,s)=>Ks.map(o=>`.doc-${s}-${o}`).join(", ")),tn=t=>{let e=Qs(t.join(`
|
|
6
|
-
`)).replaceAll("@fold-dots",Gs).replace(/^@kit-words;$/m,()=>Ke());return e.replace(/^@kit-look;$/m,()=>Ve(e))};function jt(t,{fresh:e=!1}={}){let s=qs(t);if(Zs)return V.promises.readFile(W.join(Js,t),"utf8");if(s.read)return V.promises.readFile(Z(s.read),"utf8");if(s.styles)return V.promises.readFile(Z(s.styles),"utf8").then(o=>Promise.all(Xs(s.styles,o).map(n=>V.promises.readFile(Z(n),"utf8")))).then(tn);if(e||!dt.has(t)){let o=fe(Ys(s.bundle,s.options)).then(n=>n.outputFiles[0].text);o.catch(()=>dt.delete(t)),dt.set(t,o)}return dt.get(t)}import{kitNamespace as en}from"../browser/shared/old-names.mjs";import{attr as Rt,hasClass as ht}from"../browser/shared/html-tree.mjs";var Ye=t=>t.tagName==="section"&&ht(t,"doc-section"),on=new Set(["section","header","footer","nav","script","style","template","dialog","link","meta"]),sn=t=>!on.has(t.tagName),ft=t=>t.nodeName==="#text"?t.value:(t.childNodes??[]).map(ft).join("");function Xe(t,e=[]){for(let s of t.childNodes??[])s.tagName&&((s.tagName==="main"&&ht(s,"doc-page")||Rt(s,"data-doc-sheet")!==void 0)&&e.push(s),Xe(s.tagName==="template"?s.content:s,e));return e}var nn=/^(p|li|h[1-4]|blockquote|ul|ol)$/,Qe=["doc-summary","doc-panel","doc-note","doc-callout"],an=t=>nn.test(t.tagName)||Qe.some(e=>ht(t,e)),rn=new Set(["none","auto","100%","inherit","initial","unset","revert"]),qe=t=>[...t.matchAll(/(?:^|[;{\s])(?:max-)?width\s*:\s*([^;}]+)/gi)].some(([,e])=>!rn.has(e.replace(/!important/i,"").trim().toLowerCase())),cn=t=>{let e=t.trim().split(/\s*[\s>+~]\s*/).at(-1)??"",s=/^(p|li|h[1-4]|blockquote|ul|ol)\b/.test(e)||Qe.some(n=>e.includes(`.${n}`)),o=[...t.matchAll(/\.([\w-]+)/g)].some(([,n])=>!en(n))||t.includes("#");return s&&!o};function ln(t){let e=[],s=(o,n)=>{for(let i of o.childNodes??[]){if(!i.tagName)continue;let r=n||i.tagName==="main"&&ht(i,"doc-page");if(r&&an(i)&&qe(Rt(i,"style")??"")&&e.push(`<${i.tagName}> with style="${Rt(i,"style").trim()}"`),i.tagName==="style"){let c=ft(i).replace(/\/\*[\s\S]*?\*\//g,"");for(let[,l,a]of c.matchAll(/([^{}]+)\{([^{}]*)\}/g))if(qe(a))for(let d of l.split(","))cn(d)&&e.push(`"${d.trim()}" in the document's style`)}s(i.tagName==="template"?i.content:i,r)}};return s(t,!1),e}function to(t,{written:e=t}={}){let s=[],o=w(t),n=ln(o);n.length>0&&s.push(`body text given a width of its own (${n.slice(0,3).join("; ")}${n.length>3?`; ${n.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 Xe(o)){let r=i.childNodes.filter(c=>c.tagName);r.forEach((c,l)=>{if(!Ye(c))return;let a=l+1;for(;a<r.length&&sn(r[a]);)a++;let d=r.slice(l+1,a);if(d.length===0||!Ye(r[a]??{})||/^h[1-4]$/.test(d[0].tagName))return;let f=c.childNodes.map(g=>g.tagName?g:null).filter(Boolean).map(ft).find(g=>g.trim())?.replace(/\s+/g," ").trim().slice(0,40)??"",[u]=d,h=ft(u).replace(/\s+/g," ").trim(),m=`<${u.tagName}>${h?` "${h.length>30?`${h.slice(0,30)}\u2026`:h}"`:""}`,p=u.sourceCodeLocation?.startLine;s.push(`${d.length} block${d.length===1?"":"s"} of body text right after the section "${f}" stand outside it${p?` (line ${p})`:""}, ${d.length===1?`the ${m}`:`the first a ${m}`}, between two sections, with no heading of their own: fine if meant, otherwise they belong inside that section`)})}return s.push(...Ae(t,{written:e})),s}import{attr as eo,hasClass as dn}from"../browser/shared/html-tree.mjs";var oo="Write instead where it came from, in words, or a path relative to materials/ (materials/data.csv)",fn=new Set(["script","style","template","noscript","textarea","pre","code","kbd","samp","var"]),hn=["doc-math-inline","doc-math-block"],un=/\\\([\s\S]*?\\\)|\\\[[\s\S]*?\\\]|\$\$[\s\S]*?\$\$/g,pn=/(?<!\\)\$(?:\\[\s\S]|[^\\$])+\$/g,mn=/[\s"'<>|()[\]{};,。;:、!?()《》「」『』“”‘’【】]/u,gn=/[^\s"'<>|()[\]{};,。;:、!?()《》「」『』“”‘’【】]+/gu,io=/^[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/u,$n=/\.[A-Za-z0-9]{1,8}$/,wn=[/(?<![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],bn=/(?:^|[\\/])(?:AppData|scratchpad)(?=[\\/]|$)/i,kn=/^(?:[A-Za-z]:|[\\/]|%[A-Za-z]+%)[\s\S]*[\\/](?:temp|tmp)(?=[\\/])/i,yn=t=>t.includes("://")&&!/^file:/i.test(t),so=12;function no(t,e){let s=e;for(;s<t.length&&!mn.test(t[s])&&!(io.test(t[s])&&$n.test(t.slice(e,s)));)s++;return t.slice(e,s).replace(/[.,;:!?]+$/,"")}function xn(t,e=!1){let s=c=>c.replace(/[^\n]/g," "),o=t.replace(un,s),n=e?o.replace(pn,s):o,i=[],r=(c,l)=>i.some(a=>a.at<=c+l.length&&c<=a.at+a.path.length);for(let c of wn)for(let l of n.matchAll(c)){let a=no(n,l.index);a.length>=l[0].length+2&&!r(l.index,a)&&i.push({at:l.index,path:a})}for(let c of n.matchAll(gn)){let l=c.index;for(;l<c.index+c[0].length&&io.test(n[l]);)l++;let a=no(n,l);/[\\/]/.test(a)&&(bn.test(a)||kn.test(a))&&!yn(a)&&!r(l,a)&&i.push({at:l,path:a})}return i.sort((c,l)=>c.at-l.at)}function ao(t,e=w(t)){let s=[],o=(r,c)=>{for(let l of r.childNodes??[])if(l.nodeName==="#text"){if(!l.sourceCodeLocation)continue;for(let{at:a,path:d}of xn(l.value,c))s.push({line:l.sourceCodeLocation.startLine+(l.value.slice(0,a).match(/\n/g)?.length??0),path:d})}else l.tagName&&!fn.has(l.tagName)&&eo(l,"hidden")===void 0&&!hn.some(a=>dn(l,a))&&o(l,c||eo(l,"data-doc-math-dollar")!==void 0)};o(e,!1);let n=s.slice(0,so).map(({line:r,path:c})=>`line ${r}: "${c.length>80?`${c.slice(0,77)}\u2026`:c}" is a path of this machine in the text a reader reads: a reader on another machine cannot open it. ${oo}`),i=s.slice(so);return i.length>0&&n.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:r})=>r)).size===1?"":"s"} ${[...new Set(i.map(({line:r})=>r))].join(", ")}. ${oo}`),n}import{elementsOf as ro}from"../browser/shared/html-tree.mjs";import{netSnapshot as Sn}from"../browser/shared/net-cache.mjs";import{hostIn as Nn,netHostsOf as vn}from"../browser/shared/net-policy.mjs";var On=(t,e)=>`<script type="application/json" data-doc-snapshot data-at="${e}">${JSON.stringify(t).replace(/</g,"\\u003c")}</script>`,Ft=t=>t.some(({needs:e})=>Array.isArray(e)&&e.includes("workspace"));function co(t,{slug:e,packages:s,root:o,at:n=new Date,workspace:i=null}){let r=s.flatMap(({needs:f})=>vn(f)),c=r.length===0?null:Sn(o,e,f=>{try{return Nn(new URL(f).hostname,r)!==null}catch{return!1}}),l={...i&&Ft(s)?i:{},...c?{net:c}:{}};if(Object.keys(l).length===0)return t;let a=ro(ro(w(t)).find(f=>f.tagName==="html")??{}).find(f=>f.tagName==="head"),d=a?.sourceCodeLocation?.endTag?.startOffset??a?.sourceCodeLocation?.startTag?.endOffset;return d===void 0?t:`${t.slice(0,d)} ${On(l,n.toISOString())}
|
|
7
|
-
${t.slice(d)}`}import{MENTION as En,MENTION_ICON as Tn}from"../browser/shared/components/mention.mjs";import{escapeAttribute as Ln}from"../browser/shared/escape.mjs";import{attr as lo,elementsOf as An,hasClass as fo,walk as Cn}from"../browser/shared/html-tree.mjs";import{addressOn as zn,decoded as In,fromFile as jn,hosted as Rn,pageAddress as Fn,workbenchHash as _n}from"../browser/shared/page-address.mjs";function Dn(t,e,s){let o=jn(t,e),n=zn(o,s);return n||Rn(t)?n:Fn(o)??(_n(o)===null?null:{slug:null,block:null})}function Mn(t,e,s,o){let n=w(t),i=new Set,r=[];Cn(n,a=>{let d=lo(a,"data-block-id");d!==void 0&&i.add(d),a.tagName==="a"&&lo(a,"href")!==void 0&&a.sourceCodeLocation?.startTag&&r.push(a)});let c=new Map,l=({startOffset:a,endOffset:d})=>c.set(a,[d,""]);for(let a of r){let{prefix:d,value:f}=a.attrs.find(({name:k})=>k==="href"),u=f.startsWith("#")?In(f.slice(1)):null,h=u===null?f&&Dn(f,e,o):i.has(u)?{slug:e,block:u}:null;if(!h)continue;let m=s(h,f);if(m===f)continue;let{attrs:p,startTag:g,endTag:b}=a.sourceCodeLocation;if(m===null)l(g),b&&l(b),fo(a,En)&&An(a).filter(k=>fo(k,Tn)).forEach(k=>l(k.sourceCodeLocation));else{let k=d?`${d}:href`:"href";c.set(p[k].startOffset,[p[k].endOffset,`${k}="${Ln(m)}"`])}}return[...c].sort(([a],[d])=>d-a).reduce((a,[d,[f,u]])=>`${a.slice(0,d)}${u}${a.slice(f)}`,t)}function ho(t,e,s,{blocks:o=!0,links:n}){return Mn(t,e,({slug:i,block:r})=>{let c=s(i);if(c===null)return null;if(!r||!o)return i===e&&r?null:c;let l=`#${encodeURIComponent(r)}`;return i===e?l:`${c}${l}`},n)}import ut from"node:fs";import Pn from"node:path";import{extensionOf as Un,imageFile as Wn,mediaTypeOf as Bn}from"../browser/shared/media.mjs";var Mt=1024*1024,Hn=Mt,po=2400,_t=2e3,Kn=.25,Gn=new Set(["png","gif"]),uo=.75;function Jn(t){if(t.length<16||t.toString("latin1",0,4)!=="RIFF"||t.toString("latin1",8,12)!=="WEBP")return!1;for(let e=12;e+8<=t.length;){let s=t.toString("latin1",e,e+4);if(s==="VP8L")return!0;if(s==="VP8 "||s==="ANMF")return!1;let o=t.readUInt32LE(e+4);e+=8+o+o%2}return!1}function Vn(t){let e=(s,o)=>s+o<=t.length;if(e(0,24)&&t.readUInt32BE(0)===2303741511&&t.toString("latin1",12,16)==="IHDR")return{width:t.readUInt32BE(16),height:t.readUInt32BE(20)};if(e(0,10)&&/^GIF8[79]a$/.test(t.toString("latin1",0,6)))return{width:t.readUInt16LE(6),height:t.readUInt16LE(8)};if(e(0,4)&&t[0]===255&&t[1]===216){for(let s=2;e(s,4);){if(t[s]!==255)return null;let o=t[s+1];if(o===255){s+=1;continue}if(o===216||o===1||o>=208&&o<=215){s+=2;continue}if(o>=192&&o<=207&&![196,200,204].includes(o))return e(s,9)?{width:t.readUInt16BE(s+7),height:t.readUInt16BE(s+5)}:null;if(o===217||o===218)return null;s+=2+t.readUInt16BE(s+2)}return null}if(e(0,30)&&t.toString("latin1",0,4)==="RIFF"&&t.toString("latin1",8,12)==="WEBP"){let s=t.toString("latin1",12,16);if(s==="VP8 ")return{width:t.readUInt16LE(26)&16383,height:t.readUInt16LE(28)&16383};if(s==="VP8L"){let o=t.readUInt32LE(21);return{width:(o&16383)+1,height:(o>>>14&16383)+1}}return s==="VP8X"?{width:t.readUIntLE(24,3)+1,height:t.readUIntLE(27,3)+1}:null}if(e(0,12)&&t.toString("latin1",4,8)==="ftyp"&&/avi[fs]/.test(t.toString("latin1",8,Math.min(t.length,t.readUInt32BE(0))))){let s=null;for(let o=t.indexOf("ispe",0,"latin1");o>=0&&e(o,16);o=t.indexOf("ispe",o+4,"latin1")){let n={width:t.readUInt32BE(o+8),height:t.readUInt32BE(o+12)};(!s||n.width*n.height>s.width*s.height)&&(s=n)}return s}return null}var Zn=Mt;function Yn(t){let e;try{e=ut.openSync(t,"r");let{size:s}=ut.fstatSync(e),o=Buffer.alloc(Math.min(s,Zn));return ut.readSync(e,o,0,o.length,0),{length:s,head:o}}catch{return null}finally{e!==void 0&&ut.closeSync(e)}}var j=t=>`${Math.max(.1,t/Mt).toFixed(1)} MB`;function qn({bytes:t,width:e,height:s,extension:o,lossless:n}){let i=Math.max(e,s),r=Math.min(1,_t/i),c=Math.min(t,e*s*r*r*Kn);if(i>po){if(!n)return c<=t*uo?` \u2014 a ${_t}px copy would be about ${j(c)}`:"";let l=t*r*r;return` \u2014 a ${_t}px copy would be about ${j(l)}${o==="png"&&c<l/2?`, or ${j(c)} as a JPEG (for a photograph)`:""}`}return!n&&c<=t*uo?` \u2014 written again as a JPEG of quality about 82, it would be about ${j(c)}`:o==="png"&&c<t/2?` \u2014 as a JPEG (for a photograph) it would be about ${j(c)}`:""}var Dt=t=>t===2?"twice":`${t} times`;function mo({html:t,directory:e,tree:s=w(t)}){let{embedded:o,unserved:n}=le({html:t,directory:e,tree:s}),i=new Map,r=(l,a,d,f=!1)=>{let u=i.get(l)??i.set(l,{at:[],shows:0,served:d}).get(l);u.at.push(a),f||(u.shows+=1)};for(let{file:l,line:a,icon:d}of o)Wn(l)&&r(l,a,!0,d);for(let{file:l,line:a}of n)Bn(l).startsWith("image/")&&r(l,a,!1);let c=[];for(let[l,{at:a,shows:d,served:f}]of[...i].sort(([,u],[,h])=>Math.min(...u.at)-Math.min(...h.at))){let u=Yn(Pn.join(e,l));if(!u)continue;let{length:h,head:m}=u,p=Vn(m),g=p?Math.max(p.width,p.height):0,b=h>Hn||g>po,k=f&&d>1;if(!b&&!k)continue;let x=[...new Set(a)],v=`line${x.length===1?"":"s"} ${x.length>1?`${x.slice(0,-1).join(", ")} and ${x.at(-1)}`:x[0]}`,T=k?`shown ${Dt(d)}: the export embeds it ${Dt(d)}; show it once and refer back to it in words`:"";if(!b){c.push(`${l} (${v}): ${T} (${j(Math.ceil(h/3)*4*d)} as data: URLs)`);continue}let H=a.length===1||!f?"":`, ${Dt(a.length)}`,R=f?a.length:1,q=`${j(Math.ceil(h/3)*4*R)} as ${R===1?"a data: URL":"data: URLs"}`,Uo=p?`, ${p.width}\xD7${p.height}px`:"",Kt=Un(l),Gt=p?qn({bytes:h,...p,extension:Kt,lossless:Gn.has(Kt)||Jn(m)}):"",Wo=f?`the export embeds it as it is${H}, ${q}${Gt}`:`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, ${q}${Gt}: copy it in at the size the page needs`;c.push(`${l} (${v}): ${j(h)}${Uo}; ${Wo}${T?`; ${T}`:""}`)}return c}import{COMPONENTS as ui}from"../browser/shared/components/index.mjs";import{withLook as pi}from"../browser/shared/document-look.mjs";import{reportsDirectory as mi}from"../browser/shared/paths.mjs";import{documentLook as gi}from"../browser/shared/workspace-look.mjs";import go from"node:fs";import{MENTION as $o,MENTION_ICON as wo}from"../browser/shared/components/mention.mjs";import{escapeAttribute as Xn,escapeText as Qn}from"../browser/shared/escape.mjs";import{iconUrl as ti,validIcon as ei}from"../browser/shared/emoji/icon-value.mjs";import{attr as oi,hasClass as si,walk as ni}from"../browser/shared/html-tree.mjs";import{fromFile as ii,isFileLink as ai,pageAddress as ri}from"../browser/shared/page-address.mjs";import{reportsDirectory as ci}from"../browser/shared/paths.mjs";import{documentDirectory as li,documentFiles as di}from"../browser/shared/workspace.mjs";function fi(t,e){let{html:s,json:o}=di(li(t,e));if(!go.existsSync(s))return null;try{let{title:n,icon:i}=JSON.parse(go.readFileSync(o,"utf8"));return{title:n,icon:i}}catch{return{}}}function hi(t,e,s,o){if(s==="words"||typeof t!="string"||!ei(t))return null;if(s==="preview")return ti(t,e,{tab:!0});let n=Qt({value:t,slug:e,tab:!0,reportsDirectory:o});return n&&`data:${n.type};base64,${n.body.toString("base64")}`}function bo(t,{slug:e,mode:s="export",reportsDirectory:o=ci}){if(!t.includes($o))return t;let n=new Map,i=c=>(n.has(c)||n.set(c,fi(c,o)),n.get(c)),r=new Map;return ni(w(t),c=>{let l=c.tagName==="a"&&si(c,$o)?oi(c,"href"):void 0,{startTag:a,endTag:d}=c.sourceCodeLocation??{};if(!l||!ai(l)||!a||!d)return;let f=ri(ii(l,e))?.slug;if(!f)return;let u=i(f);if(!u)r.set(a.endOffset-1,[a.endOffset-1," data-doc-gone"]);else if(u.title){let h=hi(u.icon,f,s,o);r.set(a.endOffset,[d.startOffset,`${h?`<img class="${wo}" src="${Xn(h)}" alt="">`:`<span class="${wo}"></span>`}${Qn(u.title)}`])}}),[...r].sort(([c],[l])=>l-c).reduce((c,[l,[a,d]])=>`${c.slice(0,l)}${d}${c.slice(a)}`,t)}var $i=/<script\b[^>]*\bdata-doc-kit="runtime"[^>]*><\/script>/;function wi(t,e,s){let o=Vt(e).filter(({id:n})=>!s.some(i=>i.id===n)).map(Zt).join(" ");return o?t.replace($i,n=>`${n}
|
|
8
|
-
<script data-doc-dev>${o}</script>`):t}var ko=/(<title\b[^>]*>)\s*(<\/title>)/i;function bi(t){if(!ko.test(t))return t;let e=/^en\b/i.test(/<html\b[^>]*\slang=["']?([^"'\s>]*)/i.exec(t)?.[1]??"");return t.replace(ko,(s,o,n)=>`${o}${e?"Untitled":"\u672A\u547D\u540D\u6587\u6863"}${n}`)}function Pt(t,{slug:e,mode:s="export",files:o=!0,reportsDirectory:n,kit:i}){let{html:r,removed:c}=ki(t,{reportsDirectory:n,kit:i,describe:s==="preview"}),l={slug:e,mode:s,...n?{reportsDirectory:n}:{}},a=te(pi(r,gi(e,n??mi)),l),d=o?de(oe(ne(ae(a,l),l),l),l):a;return{html:bi(bo(d,l)),removed:c}}function ki(t,{reportsDirectory:e,kit:s,page:o=!1,describe:n=!1}){let i=E(e),r=L(t,i),{html:c,removed:l,used:a}=ue(t,[...ui,...r]),d=xe(pe(c,{used:a,page:o,...s?{href:s}:{}}),r);return{html:n?wi(d,i,r):d,removed:l,packages:r}}import{exportsDirectory as Wt,generatedDirectory as Y,kitPublicDirectory as Ci,release as zi,reportsDirectory as I,vendorDirectory as Ii}from"../browser/shared/paths.mjs";import{referencedFile as ji}from"../browser/shared/media.mjs";import{decoded as Ri,fromFile as Fi,hashAddress as _i,hosted as Co,pageAddress as Di,workbenchHash as Mi}from"../browser/shared/page-address.mjs";import{pageLinks as Pi}from"../browser/shared/page-links.mjs";import{documentLinks as Ui,listReportSlugs as Wi}from"../browser/shared/reports.mjs";import{documentDirectory as B,documentFiles as Ht}from"../browser/shared/workspace.mjs";import{sha256 as pt}from"../browser/shared/files.mjs";import{EXPORT_CSP as Bi,GENERATOR as Hi,isolateUmd as Ki,packagesMeta as Gi,sourceMeta as Ji}from"../browser/shared/export-wrap.mjs";var vo=/__REPORT_[A-Z_]+__/,Oo=1e6,Eo=t=>t.length>1?`${t.slice(0,-1).join(", ")} and ${t.at(-1)}`:`${t[0]}`;function Vi(t){return t.map(({id:e,lines:s,columns:o})=>{let n=new Set(s).size<s.length,i=s.map((r,c)=>n?`${r}:${o[c]}`:`${r}`);return`data-block-id repeats: "${e}" on lines ${Eo(i)}${n?" (line:column)":""}; each id names one block: remove it from the copy, which needs none (the later ${i.length>2?`ones, lines ${Eo(i.slice(1))}`:`one, line ${i[1]}`}, unless the copy went before its original)`})}var Zi=({slug:t,htmlPath:e,metadataPath:s})=>{let o=e?{html:e,json:s??e.replace(/\.html$/,".json")}:Ht(B(t,I));return{htmlName:N.basename(o.html),jsonName:N.basename(o.json)}};function Yi({slug:t,html:e,metadata:s,htmlPath:o,metadataPath:n,tree:i=w(e)}){let r=[],{htmlName:c,jsonName:l}=Zi({slug:t,htmlPath:o,metadataPath:n}),a=/<h1\b[^>]*\bclass="[^"]*\bdoc-title\b[^"]*"[^>]*>\s*<\/h1>/i.test(e),d=[[/<meta\s+name=["']viewport["']/i,"missing viewport metadata"],[a?/<title>\s*<\/title>|<title>[^<]+<\/title>/i:/<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,g]of d)p.test(e)||r.push(g);let f=Buffer.byteLength(e);f>Oo&&r.push(`the document's editable source is ${f.toLocaleString("en-US")} bytes, over the ${Oo.toLocaleString("en-US")}-byte limit: aggregate or sample the embedded data, or split the document`),vo.test(e)&&r.push(`${c} still contains a starter placeholder such as __REPORT_TITLE__`);for(let[p,g]of Object.entries(s))typeof g=="string"&&vo.test(g)&&r.push(`${l} "${p}" is still a starter placeholder such as __REPORT_TITLE__`);/<[a-z][^>]*\sdata-doc-placeholder\b/i.test(e)&&r.push("starter placeholder content ([data-doc-placeholder]) is still present; replace it with the document's content");let u=new Map;M(i,p=>{let g=O(p,"data-block-id"),b=p.sourceCodeLocation?.attrs?.["data-block-id"]??p.sourceCodeLocation;g!==void 0&&u.set(g,[...u.get(g)??[],{line:b?.startLine,column:b?.startCol}])});let h=[...u].filter(([,p])=>p.length>1);r.push(...Vi(h.map(([p,g])=>({id:p,lines:g.map(({line:b})=>b),columns:g.map(({column:b})=>b)}))));let m=null;if(M(i,p=>{!m&&p.tagName==="main"&&(m=p)},{inTemplates:!1}),m){let p=O(m,"data-doc-id");p===void 0?r.push(`main.doc-page needs data-doc-id="${t}"`):p!==t&&r.push(`main[data-doc-id] is "${p}": it must be the document's slug "${t}"`)}return r}var zo=t=>So(So(t).find(e=>e.tagName==="html")??{}).find(e=>e.tagName==="head")?.sourceCodeLocation?.startTag?.endOffset,Bt=new Set(["localStorage","sessionStorage"]);function Io(t){let e=[],s=[];return M(t,o=>{o.tagName==="script"&&O(o,"src")!==void 0&&e.push(O(o,"src")),(o.tagName==="link"?(O(o,"rel")??"").toLowerCase().split(/\s+/):[]).includes("stylesheet")&&O(o,"href")!==void 0&&s.push(O(o,"href"))}),{scripts:e,styles:s}}function jo({slug:t,html:e,directory:s=B(t,I),tree:o=w(e),uses:n=Q(e,X,{tree:o}),catalog:i}){let r=[];zo(o)===void 0&&r.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 c=[];M(o,d=>{if(["script","link","img"].includes(d.tagName))for(let f of["src","href"]){let u=O(d,f)?.trim();u&&/^https?:\/\//i.test(u)&&c.push(u)}}),c.length>0&&r.push(`external resources are not portable: ${c.join(", ")}`);for(let{name:d,how:f,line:u,where:h}of n){if(!X.has(d))continue;let m={call:`calls ${d}(\u2026)`,new:`creates new ${d}(\u2026)`}[f]??`uses ${d}`;r.push(`line ${u}: ${h} ${m}: embed its data (inline JSON, DocState); the export blocks the network`)}let{scripts:l,styles:a}=Io(o);for(let d of l)we.has(d)||r.push(`unsupported script dependency ${d}`);for(let d of a)be.has(d)||r.push(`unsupported stylesheet dependency ${d}`);return r.push(...re({html:e,directory:s,tree:o}),...ie({html:e,directory:s,tree:o}),...se({html:e,directory:s,tree:o}),...ce({html:e,directory:s,tree:o})),r.push(...Se(L(e,i,o))),[...new Set(r)]}var qi=[[/\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 Xi({html:t,tree:e=w(t),uses:s=Q(t,Bt,{tree:e})}){let o=ke(t,e),n=[...me(t,e),...ge(t,e)];for(let[i,r]of qi)i.test(o)&&n.push(`${o.match(i)[0].replace(/\s*\($/,"")} is gone: ${r}`);for(let{name:i,line:r,where:c}of s)Bt.has(i)&&n.push(`line ${r}: ${c} uses ${i}: use DocState instead of direct browser storage`);return[...new Set(n)]}var Qi=(t,e)=>e.childNodes.find(s=>s.tagName||s.nodeName==="#text"&&s.value.trim())===t,ta=t=>xo(t,Ni("highlight").match)||t.tagName==="li"&&xo(t.parentNode,`ol.${vi}`),ea=`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 ${No.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 ${No.join(", ")}); or a picture of the document's folder, <div class="doc-icon"><img src="assets/logo.png" alt=""></div>`,Ro=t=>t.nodeName==="#text"?t.value:(t.childNodes??[]).map(Ro).join("");function To(t,e,s){let o=e.sourceCodeLocation?.attrs?.[s],n=o?t.slice(o.startOffset,o.endOffset):`${s}="${O(e,s)??""}"`;return n.length>72?`${n.slice(0,71)}\u2026`:n}function oa(t,e){let s=O(e,"data-icon");if(s!==void 0)return{held:To(t,e,"data-icon"),meant:Ut(s)==="glyph"?s:null};let o=null;if(M(e,i=>{o??=["img","svg"].includes(i.tagName)?i:null}),o?.tagName==="img"){let i=O(o,"src");return{held:`<img ${To(t,o,"src")}>`,meant:Ut(i)==="image"?i:null}}if(o)return{held:"an <svg>"};let n=Ro(e).replace(/\s+/g," ").trim();return{held:n?`"${n.slice(0,40)}"`:"nothing"}}function sa({set:t,name:e,color:s}){let o=Oi.find(r=>r!==t);if(gt(o).includes(e))return`; "${e}" is ${o==="tabler"?"Tabler":"MingCute"}'s: ${Ti(o,e,s)}`;let n=e.split("-").filter(r=>r.length>=3),i=gt(t).filter(r=>r.split("-").some(c=>n.includes(c))).slice(0,6);return i.length>0?`; names of its set near it: ${i.join(", ")}`:""}function na({html:t,tree:e=w(t)}){let{all:s,own:o}=ee(e),n=[],i=r=>r.sourceCodeLocation?.startLine;o.length>1&&n.push(`line ${i(o[1])}: ${o.length} page icons (.doc-icon) in the header (the first at line ${i(o[0])}): a document has one, right before its title`);for(let r of s){let c=i(r),l=r.parentNode;!o.includes(r)&&!(ta(l)&&Qi(r,l))&&n.push(`line ${c}: 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 a=Ai(Yt(t,r)),{held:d,meant:f}=a?{}:oa(t,r);f?n.push(`line ${c}: an icon (.doc-icon) holds ${d}, an icon a page reads only in double quotes: write ${Li(f)}`):a?Ut(a)==="glyph"&&!Xt(a)&&n.push(`line ${c}: the icon ${a} 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)${sa(Ei(a))}`):n.push(`line ${c}: an icon (.doc-icon) holds no icon (it holds ${d}): ${ea}`)}return[...new Set(n)]}function Fo(t){let e=w(t.html),s={...t,tree:e,uses:Q(t.html,new Set([...X,...Bt]),{tree:e})};return[...Yi(s),...At(t.html,e),...Xi(s),...na(s),...jo(s)]}function ia(t){let e=new Map(t.map(n=>[n.slug,[...Fo(n),...vt(n.html)]])),s=new Map(t.map(n=>[N.resolve(n.htmlPath),n.slug])),o=new Map(t.map(n=>[N.resolve(n.htmlPath),n]));for(let n of t)n.scriptNotes=[];if(t.length>0)for(let{htmlPath:n,text:i,typeOnly:r,note:c}of ye(t)){if(r){o.get(n)?.scriptNotes.push(c);continue}let l=n?[s.get(n)]:[...e.keys()];for(let a of l)e.get(a).push(n?i:`${i} (shared SDK declaration)`)}for(let[n,i]of e)i.length===0&&e.delete(n);return e}async function Ic(t=[],{prepare:e=null}={}){let{reports:s,failures:o}=await mt(t,{prepare:e});for(let n of s){let i=[...Fo(n),...vt(n.html)];i.length&&o.set(n.slug,i)}return o}async function aa(t=[],{prepare:e=null}={}){let{reports:s,failures:o}=await mt(t,{prepare:e});for(let[n,i]of ia(s))o.set(n,i);return{reports:s,failures:o}}async function ra({fresh:t=!1,kit:e=Ci,vendor:s=Ii}={}){if(zi)return;let o=K.map(r=>[r,r.file?jt(r.file,{fresh:t}):bt(r)]);await S.mkdir(e,{recursive:!0});let n=N.join(s,"katex","fonts");await S.mkdir(n,{recursive:!0});let i=(await S.readdir(wt)).filter(r=>r.endsWith(".woff2"));await Promise.all(i.map(r=>S.copyFile(N.join(wt,r),N.join(n,r)))),await Promise.all(o.map(async([r,c])=>S.writeFile(r.file?N.join(e,r.file):N.join(s,...r.vendor.path.split("/").slice(2)),await c)))}async function ca(t,e){let s=await S.readdir(t).catch(()=>[]);await Promise.all(s.filter(o=>o.endsWith(".html")&&!e.has(o.slice(0,-5))).map(o=>S.rm(N.join(t,o),{force:!0})))}async function la(t){let e=N.join(Y,"reports.json"),s=await S.readFile(e,"utf8").then(JSON.parse,()=>[]),o=new Map(Array.isArray(s)?s.map(i=>[i.slug,i]):[]);for(let{entry:i}of t)o.set(i.slug,i);let n=[];for(let[i,r]of[...o].sort(([c],[l])=>c.localeCompare(l))){let c=N.join(Y,`${i}.html`);await S.stat(c).then(()=>!0,()=>!1)&&n.push(r)}await S.writeFile(e,`${JSON.stringify(n,null,2)}
|
|
9
|
-
`)}async function da(t=[],{prepare:e=null}={}){let{reports:s,failures:o}=await aa(t,{prepare:e});await ra(),await S.mkdir(Y,{recursive:!0}),await ca(Y,new Set(await Wi()));let n=[];for(let i of s){let r=`${i.slug}.html`,c=N.join(Y,r);if(o.has(i.slug)){await S.rm(c,{force:!0});continue}let{html:l,removed:a}=Pt(i.html,{slug:i.slug});await S.writeFile(c,l),n.push({report:i,html:l,removed:a,entry:{slug:i.slug,...i.metadata,preview:`/generated/${r}`,sourceSha256:pt(i.html),outputSha256:pt(l)}})}return await la(n),{built:n,failures:o}}var fa=t=>t.replace(/<\/script/gi,"<\\/script");async function _o(){return new Map(await Promise.all(K.map(async t=>{let e=await(t.file?jt(t.file):bt(t,{inline:!0}));return he(t).endsWith(".css")||(e=fa(e)),[t.id,t.umd?Ki(e):e]})))}function ha(t,e,s=null,o=[]){let n=zo(w(e));if(n===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=s?`
|
|
10
|
-
${Ji(s)}${o.length>0?`
|
|
11
|
-
${Gi(o)}`:""}`:"";return`${e.slice(0,n)}
|
|
12
|
-
<meta name="generator" content="${Hi}">
|
|
13
|
-
<meta http-equiv="Content-Security-Policy" content="${Bi}">${i}${e.slice(n)}`}function Do(t,e,s,o=null,n=E(),i=I,r=null){let c=L(e,n);e=co(ha(t,e,o,c),{slug:t,packages:c,root:i,workspace:r}),e=$e(Ne(e,n),({id:d,element:f,attribute:u})=>{let h=s.get(d);if(typeof h!="string")throw new Error(`${t}: no inline source for the asset "${d}" (loadInlineSources in src/render/pipeline.mjs)`);return`<${f} ${u}="${d}-inline">${h}</${f}>`});let{scripts:l,styles:a}=Io(w(e));if(l.length+a.length>0)throw new Error(`${t}: export still contains a linked script or stylesheet`);return e}async function Lo(t,e=I,{components:s=!0}={}){let o=B(t,e),n=await S.readFile(Ht(o).html),i=n.toString("utf8"),r=w(i),c=s?E(e):{packages:new Map},l=[...s?At(i,r,c):[],...jo({slug:t,html:i,directory:o,tree:r,catalog:c})];if(l.length>0){let a=L(i,c,r).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,...a?{component:a}:{}})}return{html:i,sha256:pt(n)}}async function jc({directory:t=I,workspace:e=null}={}){let s=await _o(),o=async(n,{files:i=!0}={})=>{let r=await Lo(n,t),c=Pt(r.html,{slug:n,files:i,reportsDirectory:t}).html,l=E(t);return Do(n,c,s,r.sha256,l,t,await Mo(e,n,c,l))};return o.check=async n=>{await Lo(n,t,{components:!1})},o}async function Mo(t,e,s,o){return typeof t!="function"||!Ft(L(s,o))?null:await t(e).catch(()=>null)??null}async function Rc(t=[],{prepare:e=null,workspace:s=null}={}){let{built:o,failures:n}=await da(t,{prepare:e}),i=await _o();await S.mkdir(Wt,{recursive:!0});let r=new Set(o.map(({report:a})=>a.slug)),{links:c}=await Ui(),l=[];for(let{report:a,html:d}of o)try{let f=ho(d,a.slug,h=>r.has(h)?`${h}.html`:null,{links:c}),u=Do(a.slug,f,i,a.fileSha256,E(),I,await Mo(s,a.slug,f,E()));await S.writeFile(N.join(Wt,`${a.slug}.html`),u),l.push({slug:a.slug,bytes:Buffer.byteLength(u),sha256:pt(u)})}catch(f){n.set(a.slug,[f.message])}return{built:o,exported:l,failures:n}}function Ao(t){let e=new Set;return M(t,s=>{for(let o of["id","data-block-id"])O(s,o)!==void 0&&e.add(O(s,o))}),e}function ua(t,e,s){if(Co(t)||/^(?:[a-z][a-z0-9+.-]*:|\/)/i.test(t)||ji(t))return!1;let{pathname:o}=new URL(e);return!o.startsWith(`/${s}/`)||o.endsWith(".html")}function pa({slug:t,tree:e,directory:s}){let o=[],n=Ao(e),i=s===B(N.basename(s),I)?I:N.dirname(s),r=new Map([[t,n]]),c=d=>{if(!r.has(d)){let f=Ht(B(d,i));r.set(d,yo(f.html)?Ao(w(yi(f.html,"utf8"))):null)}return r.get(d)},l=null,a=(d,f)=>f===null?Di(d):_i(f,l??=Pi((yo(i)?xi(i):[]).map(u=>({slug:u}))));return M(e,d=>{let f=d.tagName==="a"?O(d,"href"):void 0;if(!f||f==="#"||f==="#top")return;let u=d.sourceCodeLocation?.startLine;if(f.startsWith("#")){n.has(Ri(f.slice(1)))||o.push(`the link to ${f} (line ${u}) names no block or element of this document`);return}let h=Fi(f,t),m=Mi(h),p=a(h,m);(p?!c(p.slug):m!==null)?Co(f)||o.push(`the link to ${f} (line ${u}) names a document that is not there: gallery list has the slugs`):p?.block&&!c(p.slug).has(p.block)?o.push(`the link to ${f} (line ${u}) names a block document ${p.slug} does not hold`):h&&!p&&ua(f,h,t)&&o.push(`the link to ${f} (line ${u}) leads to no document: a link to one is ../<slug>/doc.html, gallery list has the slugs`)},Si),o}function Po({slug:t,html:e,directory:s=B(t,I),written:o=e,scriptNotes:n=[]}){let i=w(e),r=ze(e);return{fix:[...ao(e,i),...mo({html:e,directory:s,tree:i})],notes:[...to(e,{written:o}),...Be(i),...pa({slug:t,tree:i,directory:s}),...r.notes,...n],readings:r.readings}}function Fc(t){let{fix:e,notes:s}=Po(t);return[...e,...s]}function _c(t){let e=t.map(s=>[s.slug,Po(s)]);for(let[s,{fix:o}]of e)for(let n of o)console.log(`fix ${s}: ${n}`);for(let[s,{notes:o}]of e)for(let n of o)console.log(`note ${s}: ${n}`);for(let[s,{readings:o}]of e)for(let n of o)console.log(`chart ${s}: ${n}`)}async function ma(t,{exportNote:e=!1}={}){for(let[s,o]of t){console.error(`
|
|
14
|
-
FAIL ${s}: ${o.length} problem${o.length===1?"":"s"}`);for(let i of o)console.error(` - ${i}`);let n=N.join(Wt,`${s}.html`);e&&await S.stat(n).then(()=>!0,()=>!1)&&console.error(` ${n} was not updated; it still holds an earlier export.`)}}function ga(t,{above:e=!1,allow:s=process.argv.includes("--allow-failures")}={}){t.size!==0&&(console.error(`
|
|
15
|
-
${t.size} document${t.size===1?"":"s"} failed: ${[...t.keys()].join(", ")}${e?" (the failures are listed first, above)":""}`),s||(process.exitCode=1))}async function Dc(t,{exportNote:e=!1,allow:s}={}){await ma(t,{exportNote:e}),ga(t,{allow:s})}export{Ts as a,Mn as b,ho as c,bo as d,Pt as e,ki as f,Vi as g,jo as h,Fo as i,ia as j,Ic as k,aa as l,ra as m,da as n,ha as o,jc as p,Rc as q,Po as r,Fc as s,_c as t,ma as u,ga as v,Dc as w};
|
package/dist/chunk-XQRUG4G3.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{h as p}from"./chunk-OU3S466R.mjs";import{g as k}from"./chunk-WTEGUPFG.mjs";import{g as b}from"./chunk-XMKHCUI6.mjs";import{k as d}from"./chunk-YFJU3O7G.mjs";import v from"node:fs/promises";import h from"node:path";import{editStateDirectory as m,reportsDirectory as f}from"../browser/shared/paths.mjs";import{findPreviewServer as $}from"../browser/shared/preview-server.mjs";import{documentDirectory as S,documentFiles as g,isDocumentSource as j}from"../browser/shared/workspace.mjs";var u=e=>h.resolve(e),D=e=>h.basename(g(h.dirname(e)).json),N={busy:"it kept changing while it was being written (an Agent writing it?); nothing written. Run the export again.",timeout:"the workspace's Gallery server did not answer in 30s; nothing written. Run the export again."};async function w(e,n,o="hand-in",l=3e4){let t=`127.0.0.1:${e.port}`,s;try{s=await fetch(`http://${t}/__gallery/edit/${o}`,{method:"POST",headers:{"Content-Type":"application/json",Origin:`http://${t}`,"X-Gallery-Token":e.token},body:JSON.stringify({slug:n,workspace:f}),signal:AbortSignal.timeout(l)})}catch(a){return a.name==="TimeoutError"?{ok:!1,reason:"timeout"}:null}let i=await s.json().catch(()=>null);return typeof i?.ok!="boolean"||["elsewhere","token","host","origin"].includes(i.reason)?null:i}async function P(e){let n=await $({reportsDirectory:f}),o=null,l=[],t=new Map,s=[];for(let i of e){let{html:a,json:c}=g(S(i,f)),r=n?await w(n,i):null;if(r===null&&(o??=p({reportsDirectory:f,stateDirectory:m,finish:d}),r=await o.handIn(i),r.ok&&await o.settleNotes(i)),!r.ok){r.reason!=="missing"&&t.set(i,[`${u(a)} was not handed in: ${N[r.reason]??r.message??r.reason}`]);continue}if(r.repeated?.length){t.set(i,b(r.repeated));continue}s.push(...L(a,r)),r.written&&(r.changes.length&&s.push(...k(a,r.changes,{reread:!1})),r.added&&s.push(...T(a,r.given,r.added)),l.push(u(a))),O(r)&&l.push(u(c))}return{written:l,failures:t,lines:s}}async function _(e){let n=await $({reportsDirectory:f});if(n){for(let o of e)if(await w(n,o,"settle")===null)return}}async function C(e,{wait:n=3e4}={}){try{let o=await $({reportsDirectory:f}),l=o?await w(o,e,"round",n):null;return l!==null?l.ok?l.ended===!0:null:await p({reportsDirectory:f,stateDirectory:m,finish:d}).beginRound(e)}catch{return null}}async function H(e){try{let n=p({reportsDirectory:f,stateDirectory:m,finish:d}),{html:o}=g(S(e,f));await n.noteTaken(e,await v.readFile(o,"utf8"))}catch{}}var O=({title:e=null,icon:n=null})=>!!(e&&typeof e.from=="string"&&e.from!==e.to||n&&!n.missing),x=10;function T(e,n,o=n?.length??0,{pending:l=!1}={}){let t=`${o} block${o===1?"":"s"}`;if(l){let i=[`ids ${u(e)}: ${t} without an id yet: the export gives ${o===1?"it":"each"} one`];return o>x?i:[...i,...n.map(({line:a,tag:c})=>` line ${a} ${c}`)]}let s=[`ids ${u(e)}: ${t} given an id`];return!n||o>x?s:[...s,...n.map(({line:i,tag:a,id:c})=>` line ${i} ${a} \u2192 ${c}`)]}function L(e,{title:n=null,icon:o=null}={},{pending:l=!1}={}){let t=u(h.dirname(e)),s=D(e),i=(c,r,y)=>l?`${c} not ${r} yet (${y}): the export writes ${c.includes(" and ")?"them":"it"}`:`${c} written ${r}: ${y}`,a=[];if(n){let c=[...n.page?["<title>"]:[],...typeof n.from=="string"&&n.from!==n.to?[`${s}'s title`]:[]];c.length&&a.push(`title ${t}: ${i(c.join(" and "),"as its h1 says it",JSON.stringify(n.to))}`)}return o?.missing?a.push(`icon ${t}: ${s} has the icon ${JSON.stringify(o.from)} and the page's header none: write it there (<div class="doc-icon">\u2026</div> before the h1) or take "icon" out of ${s} (the export leaves ${s}'s as it is)`):o&&a.push(`icon ${t}: ${i(`${s}'s icon`,"as its header has it",o.to===null?"none":JSON.stringify(o.to))}`),a}function K(e,{by:n="this export"}={}){let o=e.length===1,l=[...e.filter(t=>j(h.basename(t))).map(t=>h.basename(t)).filter((t,s,i)=>i.indexOf(t)===s).map(t=>`${t}: the kit's markup, block ids`),...e.filter(t=>/^(doc|report)\.json$/.test(h.basename(t))).map(t=>h.basename(t)).filter((t,s,i)=>i.indexOf(t)===s).map(t=>`${t}: the title or icon said above`)];return`Re-read ${e.join(", ")} before editing ${o?"it":"them"}: ${n} wrote ${o?"it":"them"} (${l.join("; ")}).`}export{P as a,_ as b,C as c,H as d,T as e,L as f,K as g};
|
package/dist/chunk-YPPJVDQI.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 g,i as S}from"./chunk-4OZWXZE5.mjs";import _ from"node:fs/promises";import{listExtensions as I}from"../browser/shared/extensions.mjs";import{ancestorsIn as C,moveDocument as M,outlineAndFile as P}from"../browser/shared/outline.mjs";import{DOCS as k,groupOfTop as A,isForeign as b,isTop as G,topIn as J,topOf as U}from"../browser/shared/outline-shape.mjs";import{draftFacts as q,draftOf as z,registeredIds as B,workspaceNames as K}from"../browser/shared/drafts.mjs";import{reportsDirectory as u}from"../browser/shared/paths.mjs";import{findPreviewServer as R}from"../browser/shared/preview-server.mjs";import{roleOf as W}from"../browser/shared/reports.mjs";import{nameStops as X,workspaceName as H}from"../browser/shared/workspace-name.mjs";import{workspaceKey as w}from"../browser/shared/workspace-registry.mjs";import{defaultWorkspace as Q,documentDirectory as y,documentFiles as V,pageSlug as Y,readLink as Z}from"../browser/shared/workspace.mjs";async function we(e=u,{others:t=w(e)===w(u)}={}){let{outline:{children:n,groups:o,links:s,shown:i},others:c}=await P(e,{others:t}),m=ee(e,o,i),a=new Set(i.map(({id:r})=>r)),p=o.map(r=>({...r,name:m.get(r.id)??null,...t&&r.workspace&&!a.has(r.workspace)?{away:!0}:{}})),$=p.filter(r=>!r.extension),F=await I(e),x=Object.values(n).flat(),N=r=>typeof r=="string"?r.replace(/\s+/g," ").trim():"",j=x.some(b)?B():null,E=new Map(await Promise.all(x.map(async r=>{if(b(r)){let d=z(r),O=c.find(({id:L})=>L===d?.ws)?.facts.get(d.slug),f=O?{...O,missing:null}:await q(r,j);return[r,{slug:r,title:f.title,description:f.description,icon:f.icon,...f.url?{url:f.url}:{},draft:{path:f.path,missing:f.missing,ws:d?.ws??null}}]}if(s.includes(r)){let d=await Z(y(r,e));return[r,{slug:r,title:d?.title??r,description:"",icon:d?.icon??null,url:d?.url??""}]}let h=await _.readFile(V(y(r,e)).json,"utf8").then(JSON.parse).catch(()=>({}));return[r,{slug:r,title:N(h?.title)||r,description:N(h?.description),icon:typeof h?.icon=="string"?h.icon:null}]})));return{children:n,groups:$,columns:p,extensions:F,documents:E}}function ee(e,t,n=[]){let o=w(Q()),s=new Set(t.map(({workspace:a})=>a).filter(Boolean)),i=X(),c=s.size?K(s,{stops:i}):new Map,m=new Map;for(let a of t)if(a.id===k)m.set(a.id,w(e)===o?"\u9ED8\u8BA4\u6587\u6863":H(e,{stops:i}).name);else if(a.workspace){let p=n.find(({id:$})=>$===a.workspace);m.set(a.id,p?.isDefault?"\u9ED8\u8BA4\u6587\u6863":c.get(a.workspace)?.name??a.workspace)}else a.role==="links"&&m.set(a.id,"\u94FE\u63A5");return m}var v=e=>e?.title??e?.name??(e?.id===k?"\u6587\u6863":e?.role==="links"?"\u94FE\u63A5":e?"\u672A\u547D\u540D\u680F":"\u6587\u6863"),T=(e,t)=>e.groups?.find(({id:n})=>n===A(t));function $e(e,t){let n=e.documents.get(t);if(!n||n.url!==void 0)return null;let o=D(e,t),s=n.draft?.ws??null,i=s?e.groups.find(c=>c.workspace===s):e.groups.find(c=>c.id===k);return i&&U(i.id)===o?null:i?i.hidden?i.name??s:v(i):s}var l=({documents:e},t)=>`${t} (${e.get(t)?.title??t})`,D=(e,t)=>J(e.children,t)??"";function ge(e,t){let n=C(e.children,t).map(i=>l(e,i)),o=D(e,t),s=[...o===""?[]:[`${v(T(e,o))}\u680F`],...n];return`\u4F4D\u7F6E\uFF1A${s.length?s.join(" \u203A "):"\u9876\u5C42"}`}async function ye(e,t,n){let{slug:o}=await S(e);if(o===await Y(u))return{refused:`${e} is the \u5199\u4F5C\u504F\u597D page, which the sidebar lists apart: it moves nowhere and holds no documents (${t}).`};if(!n.documents.has(o)){let s=y(o,u);return{refused:await W(s)==="instructions"?`${e} is the \u5199\u4F5C\u504F\u597D page, which the sidebar lists apart: it moves nowhere and holds no documents (${t}).`:`No document "${e}" (${t}): gallery list --tree shows the documents and where they are.`}}return{slug:o}}var te={"cross-workspace":()=>"Not moved: copying to another workspace requires confirmation in Gallery; the original stays in its workspace.",missing:(e,t)=>`No document "${t}" in the sidebar's tree: gallery list --tree shows them.`,parent:(e,t,{parent:n})=>`No document "${n}" to put ${l(e,t)} under: gallery list --tree shows them.`,after:(e,t,{after:n})=>`No document "${n}" to put ${l(e,t)} after: gallery list --tree shows them.`,level:(e,t,{parent:n,after:o})=>`${l(e,o)} is not under ${n?l(e,n):"the top level"}: --after names a document at the level it goes to.`,itself:(e,t)=>`${l(e,t)} cannot go after itself.`,inside:(e,t,{parent:n,after:o})=>n===void 0&&o?`${l(e,t)} cannot go after ${l(e,o)}, which is under it.`:`${l(e,t)} cannot go under ${n===t?"itself":`${l(e,n)}, which is under it`}.`,instructions:(e,t)=>"The \u5199\u4F5C\u504F\u597D page is listed apart: it moves nowhere and holds no documents."},ke=(e,t,n,o={})=>(te[n]??((s,i,{message:c})=>`Not moved: ${c??n}.`))(e,t,o);async function ne(e,t,n="move"){let o=`127.0.0.1:${e.port}`;try{let i=await(await fetch(`http://${o}/__gallery/workspace/${n}`,{method:"POST",headers:{"Content-Type":"application/json",Origin:`http://${o}`,"X-Gallery-Token":e.token},body:JSON.stringify({...t,workspace:u}),signal:AbortSignal.timeout(3e4)})).json().catch(()=>null);return typeof i?.ok!="boolean"||["elsewhere","token","host","origin","unknown"].includes(i.reason)?null:i}catch{return null}}async function ve(e,{parent:t=void 0,after:n=null,first:o=!1}={}){let s=await R({reportsDirectory:u}),i={slug:e,...t!==void 0?{parent:t}:{},after:n,first:o},c=s?await ne(s,i):null;return c||M(u,e,{parent:t,after:n,first:o})}function xe(e,{parent:t,index:n}){let o=e.children[t]??[],s=t===""?"at the top level":G(t)?`at the top of the ${v(T(e,t))} column`:`under ${l(e,t)}`;return o.length===1?`${s}, the only ${o.some(i=>e.documents.get(i)?.url!==void 0)?"entry":"document"} there`:n===0?`${s}, first`:`${s}, right after ${l(e,o[n-1])}${n===o.length-1?", last":""}`}function Ne(e,t,{top:n=!0}={}){let o=e.get("--under"),s=e.get("--after");if(o!==void 0&&t.has("--top"))throw new g("--under and --top are two places: give one.");if(s!==void 0&&t.has("--first"))throw new g("--after and --first are two places: give one.");return{under:o,top:n&&t.has("--top"),after:s,first:t.has("--first")}}export{we as a,v as b,$e as c,l as d,ge as e,ye as f,ke as g,ne as h,ve as i,xe as j,Ne as k};
|
package/dist/chunk-ZANMKAWS.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 h,b as v,d as p,e as j,h as I,j as A}from"./chunk-YPPJVDQI.mjs";import{a as O}from"./chunk-JEUK3ZO7.mjs";import{a as E}from"./chunk-UGO5N3EI.mjs";import"./chunk-5IIH335D.mjs";import"./chunk-QK3VISCA.mjs";import{g as C}from"./chunk-7M2BQQGZ.mjs";import{b as i,f as g,i as y}from"./chunk-4OZWXZE5.mjs";import"./chunk-KH24LWAT.mjs";import"./chunk-JXLSHVJ2.mjs";import"./chunk-VG5JEIUQ.mjs";import"./chunk-N3DSBH5S.mjs";import"./chunk-5L7RYZCL.mjs";import D from"node:path";import{pageLinks as F,pageOfLink as J}from"../browser/shared/page-links.mjs";import{reportsDirectory as x}from"../browser/shared/paths.mjs";import{findPreviewServer as K}from"../browser/shared/preview-server.mjs";import{topOf as M}from"../browser/shared/outline-shape.mjs";import{LINK_FILE as U,linkAddress as P,linkIcon as T}from"../browser/shared/web-links.mjs";var $=t=>t.replace(/\s+/g," ").trim(),k=t=>t==null?"none":JSON.stringify(t);async function L(t,e){let n=await K({reportsDirectory:x}),o=n?await I(n,e,t):null;if(o)return o;let[,s]=await E({edits:{},reports:{},reportsDirectory:x,web:{icon:a=>C(a)}}).run(t,e);return s}function _(t,e){let n=[...t.documents.values()].filter(({url:a})=>a!==void 0),o=J(F(n),e.replace(/^.*#/,""));return o?{slug:o,link:t.documents.get(o)}:{refused:t.documents.get(e)?`${p(t,e)} is a document, not a web link: gallery set changes a document.`:`No web link "${e}": gallery list --tree shows the sidebar's entries.`}}var W=(t,e)=>t.groups.find(n=>[v(n),n.id].some(o=>o.toLowerCase()===$(e).toLowerCase()))??null;async function B(t,e,n){if(t.length!==2)throw new i('Name the address and the name: gallery link add <url> "<name>".');let[o,s]=t,a=P(o);if(a.refused)throw new i(`Not an address a web link takes: ${o} (${{url:"no address",scheme:"http or https only",long:"2048 characters at most"}[a.refused]}).`);if(!$(s))throw new i("The name is never empty.");let d=n.get("--column"),u=n.get("--under"),l=n.get("--after"),c=n.get("--icon");if(d!==void 0&&u!==void 0)throw new i("--column and --under are two places: give one.");if(l!==void 0&&e.has("--first"))throw new i("--after and --first are two places: give one.");if(c!==void 0&&!T(c))throw new i(`Not an icon a web link takes: ${c} (an emoji, or an icon of the \u56FE\u6807 tab as /icons/<name>_<color>.svg).`);let f=await h(),w;if(d!==void 0){let S=W(f,d);S||(console.error(`No column "${d}" in the sidebar (${f.groups.map(v).join(", ")}): nothing added.`),process.exit(1)),w=M(S.id)}u!==void 0&&(w=(await y(u)).slug);let r=l===void 0?null:(await y(l)).slug,q=e.has("--first")||u===void 0&&r===null,m=await L("link",{url:a.url,title:$(s),...c?{icon:c}:{},...w!==void 0?{parent:w}:{},after:r,first:q});m?.ok||(console.error(`Not added: ${m?.message??m?.reason??"no answer"}.`),process.exit(1));let b=await h(),{slug:N,url:z}=m.link;console.log(`Added the web link ${p(b,N)}: ${z}`),console.log(`Placed it ${A(b,{parent:m.parent,index:m.index})}.`),console.log(j(b,N)),console.log(`It is ${O(D.join(x,N,U))}; the workbench shows the page beside the sidebar (a site that refuses frames: \u5728\u6D4F\u89C8\u5668\u4E2D\u6253\u5F00).`)}async function G(t,e){if(t.length!==1)throw new i("Name one web link, then what to set: --url, --title, --icon.");if(!["--url","--title","--icon"].some(r=>e.has(r)))throw new i('Say what to set: --url <address>, --title "<name>", --icon <emoji|none>.');let n=e.has("--title")?$(e.get("--title")):void 0;if(n==="")throw new i("--title takes the words of the name: a web link's name is never empty.");let o;if(e.has("--url")){let r=P(e.get("--url"));if(r.refused)throw new i(`Not an address a web link takes: ${e.get("--url")}.`);o=r.url}let s;if(e.has("--icon")){let r=e.get("--icon").trim();if(r!=="none"&&!T(r))throw new i(`Not an icon a web link takes: ${r} (an emoji, none, or an icon of the \u56FE\u6807 tab).`);s=r==="none"?null:r}let a=await h(),d=_(a,t[0]);d.refused&&(console.error(d.refused),process.exit(1));let{slug:u,link:l}=d,c=await L("link-set",{slug:u,...o!==void 0?{url:o}:{},...n!==void 0?{title:n}:{},...s!==void 0?{icon:s}:{}});c?.ok||(console.error(`Not set: ${c?.message??c?.reason??"no answer"}.`),process.exit(1));let f=c.link,w=[...n!==void 0&&n!==l.title?[` title: ${k(l.title)} \u2192 ${k(f.title)}`]:[],...o!==void 0&&f.url!==l.url?[` url: ${l.url} \u2192 ${f.url}`]:[],...s!==void 0&&(f.icon??null)!==(l.icon??null)?[` icon: ${k(l.icon)} \u2192 ${k(f.icon??null)}`]:[]];if(!w.length)return void console.log(`Nothing to change: ${u} has ${e.size===1?"that already":"those already"}.`);console.log(`Set the web link ${u}:`);for(let r of w)console.log(r)}async function H(t){if(t.length!==1)throw new i("Name one web link to move to the trash.");let e=await h(),n=_(e,t[0]);n.refused&&(console.error(n.refused),process.exit(1));let o=await L("trash",{slug:n.slug,kind:"link"});o?.ok||(console.error(`Not moved to the trash: ${o?.message??o?.reason??"no answer"}.`),process.exit(1)),console.log(`Moved the web link ${p(e,n.slug)} to the trash: the workbench's \u8BBE\u7F6E \u203A \u56DE\u6536\u533A restores it where it was.`)}async function se(t){let[e,...n]=t;if(e==="add"){let{positional:o,options:s,values:a}=g({options:["--first"],values:["--column","--under","--after","--icon"],argv:n});return B(o,s,a)}if(e==="set"){let{positional:o,values:s}=g({values:["--url","--title","--icon"],argv:n});return G(o,s)}if(e==="remove"){let{positional:o}=g({argv:n});return H(o)}throw new i(e?`No such action: link ${e} (add, set, remove).`:"Say what to do: gallery link add, set or remove.")}export{se as run};
|