@heycys/gallery 0.2.3 → 0.2.4
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/README.md +1 -1
- package/THIRD-PARTY-NOTICES.md +1 -1
- package/assets/preview/runtime.js +156 -0
- package/assets/preview/shell.html +107 -0
- package/assets/writing-preferences.md +1 -1
- package/browser/editor/components/divider/index.mjs +1 -1
- package/browser/editor/page/annotate/card.mjs +6 -0
- package/browser/editor/page/annotate/index.mjs +22 -2
- package/browser/editor/page/columns/index.mjs +1 -1
- package/browser/editor/page/conflicts.mjs +1 -1
- package/browser/editor/page/drag/index.mjs +1 -1
- package/browser/editor/page/editor.mjs +39 -3
- package/browser/editor/page/focus.mjs +104 -0
- package/browser/editor/page/handle/index.mjs +14 -2
- package/browser/editor/page/links/index.mjs +2 -2
- package/browser/editor/page/quiet.mjs +3 -3
- package/browser/editor/page/resize/index.mjs +1 -1
- package/browser/editor/page/session.mjs +4 -1
- package/browser/editor/page/ui.mjs +1 -1
- package/browser/shared/annotations.mjs +22 -3
- package/browser/shared/block-packs.mjs +13 -4
- package/browser/shared/document-look.mjs +14 -0
- package/browser/shared/drafts.mjs +1 -1
- package/browser/shared/extension-manifest.mjs +40 -12
- package/browser/shared/favorite-merge.mjs +17 -0
- package/browser/shared/favorites.mjs +77 -0
- package/browser/shared/i18n/en.mjs +123 -24
- package/browser/shared/outline-ops.mjs +109 -0
- package/browser/shared/outline.mjs +6 -0
- package/browser/shared/pages.mjs +20 -8
- package/browser/shared/paths.mjs +5 -2
- package/browser/shared/preference-documents.mjs +137 -0
- package/browser/shared/presence.mjs +94 -0
- package/browser/shared/preview-server.mjs +8 -5
- package/browser/shared/qa-levels.mjs +9 -1
- package/browser/shared/session.mjs +4 -0
- package/browser/shared/shipped-blocks.mjs +22 -4
- package/browser/shared/startup.mjs +101 -0
- package/browser/shared/workspace-columns.mjs +1 -1
- package/browser/shared/workspace-look.mjs +21 -8
- package/browser/shared/workspace-registry.mjs +6 -3
- package/browser/shared/workspace.mjs +37 -10
- package/browser/shared/writing-preferences.mjs +2 -42
- package/dist/chunk-25LYSMAE.mjs +2 -0
- package/dist/chunk-2I6ZVC5O.mjs +2 -0
- package/dist/{chunk-M4NRDYI5.mjs → chunk-2MYTOOP6.mjs} +1 -1
- package/dist/chunk-2VNENLER.mjs +2 -0
- package/dist/chunk-3FERXZF5.mjs +4 -0
- package/dist/chunk-3M6SBBGU.mjs +2 -0
- package/dist/chunk-3VCAAF34.mjs +2 -0
- package/dist/{chunk-WD4U6XXT.mjs → chunk-3ZTRLGSA.mjs} +1 -1
- package/dist/chunk-4FRA5AUE.mjs +2 -0
- package/dist/chunk-4LR2QEC2.mjs +4 -0
- package/dist/chunk-56SVJENP.mjs +966 -0
- package/dist/chunk-5CQISL2G.mjs +4 -0
- package/dist/{chunk-RRKJMHNX.mjs → chunk-5I5ZDDWC.mjs} +5 -5
- package/dist/chunk-5IHDLEB4.mjs +10 -0
- package/dist/chunk-5LRDMV7O.mjs +2 -0
- package/dist/chunk-5MVUYRKG.mjs +5 -0
- package/dist/chunk-5TLLIZT7.mjs +2 -0
- package/dist/chunk-6ILJWFYW.mjs +4 -0
- package/dist/chunk-6N25CJ6Y.mjs +3 -0
- package/dist/{chunk-SQ6Y2ZMA.mjs → chunk-7DTINW6U.mjs} +2 -2
- package/dist/chunk-7KWAGKIK.mjs +2 -0
- package/dist/chunk-7WNUOAFK.mjs +2 -0
- package/dist/chunk-7XCRW5RC.mjs +2 -0
- package/dist/{chunk-BYNPEUDS.mjs → chunk-7XSDTILF.mjs} +1 -1
- package/dist/chunk-ABKYFOVR.mjs +2 -0
- package/dist/chunk-AMUF7PUN.mjs +2 -0
- package/dist/{chunk-FJLM7YE7.mjs → chunk-B2EIMERT.mjs} +2 -2
- package/dist/{chunk-QNECWMGR.mjs → chunk-B45IAAU6.mjs} +1 -1
- package/dist/chunk-B6RAGF4R.mjs +2 -0
- package/dist/chunk-BSJKFE7I.mjs +4 -0
- package/dist/chunk-C72EEVLK.mjs +2 -0
- package/dist/chunk-CRAUKZ23.mjs +4 -0
- package/dist/chunk-F4CT35KL.mjs +2 -0
- package/dist/chunk-F63BNJLG.mjs +2 -0
- package/dist/chunk-FBKUPS44.mjs +2 -0
- package/dist/chunk-FL52ZL5Z.mjs +15 -0
- package/dist/chunk-FOZCU4VW.mjs +2 -0
- package/dist/chunk-G5HV7BC3.mjs +2 -0
- package/dist/{chunk-ERLAIBOA.mjs → chunk-GB5SOYQJ.mjs} +2 -2
- package/dist/chunk-GN3SG3IF.mjs +2 -0
- package/dist/{chunk-6QWQXHAV.mjs → chunk-HFTBVEZK.mjs} +1 -1
- package/dist/chunk-IOW5HLRK.mjs +2 -0
- package/dist/chunk-IQ3GJNTI.mjs +6 -0
- package/dist/chunk-K6SPFBUJ.mjs +2 -0
- package/dist/chunk-K7Y7SPTS.mjs +2 -0
- package/dist/chunk-L2IJCEUH.mjs +2 -0
- package/dist/{chunk-GPIWQ4X4.mjs → chunk-L3VT6LM4.mjs} +1 -1
- package/dist/chunk-L4WLQYFC.mjs +5 -0
- package/dist/{chunk-NLDF35P5.mjs → chunk-LAMCAGK6.mjs} +1 -1
- package/dist/chunk-LHGKPMTI.mjs +2 -0
- package/dist/chunk-LJZIYVNA.mjs +3 -0
- package/dist/chunk-LSVCTLS2.mjs +2 -0
- package/dist/chunk-LZY74XTP.mjs +2 -0
- package/dist/chunk-MC4LRSVH.mjs +2 -0
- package/dist/chunk-MCEXN4G5.mjs +2 -0
- package/dist/chunk-MTLAOCFF.mjs +181 -0
- package/dist/chunk-MZ66LN3B.mjs +2 -0
- package/dist/chunk-N5QWJRRI.mjs +2 -0
- package/dist/chunk-NF4MMOUB.mjs +2 -0
- package/dist/chunk-NHJYAJ73.mjs +3 -0
- package/dist/chunk-NRSD7SVY.mjs +2 -0
- package/dist/chunk-NT23I4XW.mjs +2 -0
- package/dist/chunk-NUALABIS.mjs +3 -0
- package/dist/chunk-NW6LAU22.mjs +2 -0
- package/dist/chunk-NWWHDGKF.mjs +5 -0
- package/dist/chunk-OFRCVMSJ.mjs +2 -0
- package/dist/chunk-OKVQQ3CX.mjs +4 -0
- package/dist/chunk-OM24O4KR.mjs +8 -0
- package/dist/{chunk-4B2TB5K2.mjs → chunk-PBMOC7KA.mjs} +2 -2
- package/dist/chunk-PVTCP43W.mjs +2 -0
- package/dist/chunk-Q62HZAJS.mjs +2 -0
- package/dist/chunk-QBJWIR3Q.mjs +2 -0
- package/dist/chunk-QDSEZX7Z.mjs +6 -0
- package/dist/chunk-QR4V4A2Z.mjs +15 -0
- package/dist/{chunk-QVGOPHOF.mjs → chunk-QRLVVZ3R.mjs} +1 -1
- package/dist/chunk-QW3QG67J.mjs +2 -0
- package/dist/chunk-R2T2EVWY.mjs +8 -0
- package/dist/{chunk-JJNHKGTD.mjs → chunk-R5RERE6G.mjs} +1 -1
- package/dist/chunk-RFHEWT3Y.mjs +5 -0
- package/dist/chunk-RS2Z2JQP.mjs +2 -0
- package/dist/chunk-S6YEC4GE.mjs +16 -0
- package/dist/chunk-SHZLMGGW.mjs +2 -0
- package/dist/chunk-TALJQM2O.mjs +2 -0
- package/dist/chunk-TLNJWEFY.mjs +22 -0
- package/dist/{chunk-ZLS2FRS6.mjs → chunk-TQZU7D7C.mjs} +1 -1
- package/dist/chunk-UTKNWYBA.mjs +2 -0
- package/dist/chunk-V3TM3TEN.mjs +2 -0
- package/dist/chunk-V3XROSP5.mjs +7 -0
- package/dist/{chunk-6QBHU4DF.mjs → chunk-V5JTW2LH.mjs} +1 -1
- package/dist/chunk-VAXLSISW.mjs +4 -0
- package/dist/chunk-VBHI3RG6.mjs +2 -0
- package/dist/{chunk-CRDG6EF2.mjs → chunk-VKZJRGDR.mjs} +1 -1
- package/dist/chunk-VZXZM7NS.mjs +2 -0
- package/dist/chunk-WDS6HEPE.mjs +2 -0
- package/dist/chunk-WHGANNEY.mjs +13 -0
- package/dist/chunk-WMJWC4QY.mjs +56 -0
- package/dist/{chunk-UTMAY3WK.mjs → chunk-WWONJJQS.mjs} +1 -1
- package/dist/chunk-X4WNLFIK.mjs +2 -0
- package/dist/chunk-XNNCQROX.mjs +11 -0
- package/dist/chunk-XRYECF23.mjs +170 -0
- package/dist/{chunk-225ALKYI.mjs → chunk-Z4NEXXFK.mjs} +1 -1
- package/dist/{chunk-PKVK6WFC.mjs → chunk-ZFVF2YPV.mjs} +2 -2
- package/dist/chunk-ZM2IX3R2.mjs +2 -0
- package/dist/chunk-ZNGGDUZI.mjs +2 -0
- package/dist/chunk-ZOEJQOKT.mjs +2 -0
- package/dist/cli.mjs +1 -1
- package/dist/server.mjs +1 -1
- package/dist/update-fetch.mjs +1 -1
- package/dist/worker.mjs +1 -1
- package/package.json +1 -1
- package/release.json +3 -3
- package/skill/SKILL.md +54 -148
- package/skill/references/building-blocks.md +4 -4
- package/skill/references/charts-and-figures.md +73 -0
- package/skill/references/extensions.md +47 -4
- package/skill/references/pages-and-data.md +22 -3
- package/skill/references/preference-files.md +7 -0
- package/skill/references/previews.md +17 -0
- package/skill/references/writing-html.md +21 -82
- package/web/assets/index-B4uUluLM.js +15 -0
- package/web/assets/index-C3vHT8sH.css +1 -0
- package/web/index.html +2 -2
- package/dist/chunk-2HS7ZBPU.mjs +0 -2
- package/dist/chunk-3F57LEN5.mjs +0 -2
- package/dist/chunk-4OZWXZE5.mjs +0 -5
- package/dist/chunk-5GK7HS62.mjs +0 -2
- package/dist/chunk-6GV3CBB2.mjs +0 -2
- package/dist/chunk-6NLXUKAY.mjs +0 -4
- package/dist/chunk-6XD6U3QA.mjs +0 -5
- package/dist/chunk-6Y3HYOBM.mjs +0 -2
- package/dist/chunk-7EFHNQ5B.mjs +0 -3
- package/dist/chunk-7M2BQQGZ.mjs +0 -2
- package/dist/chunk-7UZUQQ7Q.mjs +0 -554
- package/dist/chunk-ALZ6ZENZ.mjs +0 -3
- package/dist/chunk-BX5AKINW.mjs +0 -15
- package/dist/chunk-DR73Y2UJ.mjs +0 -3
- package/dist/chunk-EURLTOTZ.mjs +0 -4
- package/dist/chunk-F4ZA6JRZ.mjs +0 -3
- package/dist/chunk-FNCCVGKX.mjs +0 -2
- package/dist/chunk-FOJ3K5Z3.mjs +0 -6
- package/dist/chunk-FQ72LZHB.mjs +0 -2
- package/dist/chunk-G7N7YFVD.mjs +0 -2
- package/dist/chunk-GIRXJBGC.mjs +0 -2
- package/dist/chunk-GKOBB6DH.mjs +0 -2
- package/dist/chunk-GMJD7ID3.mjs +0 -2
- package/dist/chunk-GQJMVSSN.mjs +0 -2
- package/dist/chunk-HX4DLE3J.mjs +0 -10
- package/dist/chunk-IS7N3N6Q.mjs +0 -168
- package/dist/chunk-JEUK3ZO7.mjs +0 -2
- package/dist/chunk-JPG2LBQM.mjs +0 -11
- package/dist/chunk-JYK5WJPM.mjs +0 -2
- package/dist/chunk-KLQP46Y3.mjs +0 -4
- package/dist/chunk-L55NOXBE.mjs +0 -4
- package/dist/chunk-LCB6MARS.mjs +0 -5
- package/dist/chunk-LJLVCU6W.mjs +0 -16
- package/dist/chunk-LMUZQK5O.mjs +0 -2
- package/dist/chunk-NMF3IPYA.mjs +0 -13
- package/dist/chunk-ONKC4BCC.mjs +0 -2
- package/dist/chunk-OU6ZZVBX.mjs +0 -5
- package/dist/chunk-PUOQ65NC.mjs +0 -2
- package/dist/chunk-QJAVCTY7.mjs +0 -2
- package/dist/chunk-QP7BOHE4.mjs +0 -2
- package/dist/chunk-S3SX3COT.mjs +0 -20
- package/dist/chunk-SQ3FQCCN.mjs +0 -8
- package/dist/chunk-T4Y2ZSVX.mjs +0 -4
- package/dist/chunk-TANZRINB.mjs +0 -2
- package/dist/chunk-UGWMMEJ5.mjs +0 -15
- package/dist/chunk-UTF7GBQU.mjs +0 -4
- package/dist/chunk-V4ZHRALW.mjs +0 -170
- package/dist/chunk-XBNFXWAW.mjs +0 -6
- package/dist/chunk-XZV72SQ4.mjs +0 -2
- package/dist/chunk-YFJB534W.mjs +0 -2
- package/dist/chunk-Z6OKLRHC.mjs +0 -2
- package/dist/chunk-ZMHUDYLV.mjs +0 -2
- package/web/assets/index-D8P8uhDW.js +0 -15
- package/web/assets/index-FLb9jCfl.css +0 -1
- /package/dist/{chunk-PAREWQGB.mjs → chunk-NOGQX56R.mjs} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{a,b}from"./chunk-
|
|
2
|
+
import{a,b}from"./chunk-LAMCAGK6.mjs";import"./chunk-VAXLSISW.mjs";import"./chunk-56SVJENP.mjs";import"./chunk-PBMOC7KA.mjs";import"./chunk-BSJKFE7I.mjs";import"./chunk-L4WLQYFC.mjs";import"./chunk-E7656LR7.mjs";import"./chunk-TKWEX4FD.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";export{a as copiedLines,b as run};
|
|
@@ -0,0 +1,2 @@
|
|
|
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{i as m}from"./chunk-TLNJWEFY.mjs";import{g as S}from"./chunk-QR4V4A2Z.mjs";import{p as $}from"./chunk-B2EIMERT.mjs";import{g as x}from"./chunk-VRPVVMRB.mjs";import{workspaceBase as D}from"../browser/shared/service-location.mjs";import N from"node:fs/promises";import c from"node:path";import{editStateDirectory as g,reportsDirectory as h}from"../browser/shared/paths.mjs";import{findPreviewServer as w}from"../browser/shared/preview-server.mjs";import{documentDirectory as j,documentFiles as y,isDocumentSource as O}from"../browser/shared/workspace.mjs";var p=t=>c.resolve(t),T=t=>c.basename(y(c.dirname(t)).json),L={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 b(t,n,o="hand-in",a=3e4){let e=`127.0.0.1:${t.port}`,r;try{r=await fetch(`http://${e}${D(h)}/__gallery/edit/${o}`,{method:"POST",headers:{"Content-Type":"application/json",Origin:`http://${e}`,"X-Gallery-Token":t.token},body:JSON.stringify({slug:n,workspace:h}),signal:AbortSignal.timeout(a)})}catch(l){return l.name==="TimeoutError"?{ok:!1,reason:"timeout"}:null}let i=await r.json().catch(()=>null);return typeof i?.ok!="boolean"||["elsewhere","token","host","origin"].includes(i.reason)?null:i}async function H(t){let n=await w(),o=null,a=[],e=new Map,r=[];for(let i of t){let{html:l,json:u}=y(j(i,h)),s=n?await b(n,i):null;if(s===null&&(o??=m({reportsDirectory:h,stateDirectory:g,finish:$}),s=await o.handIn(i),s.ok&&await o.settleNotes(i)),!s.ok){s.reason!=="missing"&&e.set(i,[`${p(l)} was not handed in: ${L[s.reason]??s.message??s.reason}`]);continue}if(s.repeated?.length){e.set(i,S(s.repeated));continue}r.push(...R(l,s)),s.written&&(s.changes.length&&r.push(...x(l,s.changes,{reread:!1})),s.added&&r.push(...J(l,s.given,s.added)),a.push(p(l))),I(s)&&a.push(p(u))}return{written:a,failures:e,lines:r}}async function W(t){let n=await w();if(n){for(let o of t)if(await b(n,o,"settle")===null)return}}async function X(t,{wait:n=3e4}={}){try{let o=await w(),a=o?await b(o,t,"round",n):null;return a!==null?a.ok?a.ended===!0:null:await m({reportsDirectory:h,stateDirectory:g,finish:$}).beginRound(t)}catch{return null}}async function Y(t){try{let n=m({reportsDirectory:h,stateDirectory:g,finish:$}),{html:o}=y(j(t,h));await n.forgetChanges(t),await n.noteTaken(t,await N.readFile(o,"utf8"))}catch{}}async function q(t){try{await m({reportsDirectory:h,stateDirectory:g,finish:$}).forgetChanges(t)}catch{}}var I=({title:t=null,icon:n=null})=>!!(t&&typeof t.from=="string"&&t.from!==t.to||n&&!n.missing),v=10;function J(t,n,o=n?.length??0,{pending:a=!1}={}){let e=`${o} block${o===1?"":"s"}`;if(a){let i=[`ids ${p(t)}: ${e} without an id yet: the export gives ${o===1?"it":"each"} one`];return o>v?i:[...i,...n.map(({line:l,tag:u})=>` line ${l} ${u}`)]}let r=[`ids ${p(t)}: ${e} given an id`];return!n||o>v?r:[...r,...n.map(({line:i,tag:l,id:u})=>` line ${i} ${l} \u2192 ${u}`)]}function R(t,{title:n=null,icon:o=null}={},{pending:a=!1}={}){let e=p(c.dirname(t)),r=T(t),i=(f,d,k)=>a?`${f} not ${d} yet (${k}): the export writes ${f.includes(" and ")?"them":"it"}`:`${f} written ${d}: ${k}`,l=[],u=c.basename(c.dirname(t)),s=f=>a?`; the page holds the ${f} and ${r} follows it: change it with gallery set ${u} --${f} \u2026 (it writes both), for what is put in ${r} alone is written over by the export`:"";if(n){let f=typeof n.from=="string"&&n.from!==n.to,d=[...n.page?["<title>"]:[],...f?[`${r}'s title`]:[]];d.length&&l.push(`title ${e}: ${i(d.join(" and "),"as its h1 says it",JSON.stringify(n.to))}${f?s("title"):""}`)}return o?.missing?l.push(`icon ${e}: ${r} 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 ${r} (the export leaves ${r}'s as it is)`):o&&l.push(`icon ${e}: ${i(`${r}'s icon`,"as its header has it",o.to===null?"none":JSON.stringify(o.to))}${typeof o.to=="string"&&o.from!==o.to?s("icon"):""}`),l}function z(t,{by:n="\u8FD9\u6B21\u5BFC\u51FA"}={}){let o=t.length===1,a=[...t.filter(e=>O(c.basename(e))).map(e=>c.basename(e)).filter((e,r,i)=>i.indexOf(e)===r).map(e=>`${e}\uFF1A\u5957\u4EF6\u5199\u6CD5\u3001\u5757\u7F16\u53F7`),...t.filter(e=>/^(doc|report)\.json$/.test(c.basename(e))).map(e=>c.basename(e)).filter((e,r,i)=>i.indexOf(e)===r).map(e=>`${e}\uFF1A\u4E0A\u9762\u8BF4\u7684\u6807\u9898\u6216\u56FE\u6807`)];return`\u91CD\u8BFB\uFF1A${t.join("\u3001")}\uFF08\u6539\u4E4B\u524D\u5148\u91CD\u8BFB\uFF1A${n}\u5199\u4E86${o?"\u5B83":"\u5B83\u4EEC"}\u2014\u2014${a.join("\uFF1B")}\uFF09`}export{H as a,W as b,X as c,Y as d,q as e,J as f,R as g,z as h};
|
|
@@ -0,0 +1,11 @@
|
|
|
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 qt,b as Dt}from"./chunk-LJZIYVNA.mjs";import{a as Ot}from"./chunk-UMHUSOPJ.mjs";import{b as Zt,e as ze}from"./chunk-A55HN5OK.mjs";import{listPreferenceDocuments as ae,changePreferenceDocuments as sn,preferenceFile as cn}from"../browser/shared/preference-documents.mjs";import{randomBytes as xt}from"node:crypto";import x from"node:fs/promises";import{serviceLocation as un}from"../browser/shared/service-location.mjs";import k from"node:path";import{writeAtomic as T}from"../browser/shared/files.mjs";import{sendJson as _}from"../browser/shared/http.mjs";import{said as z,saying as Ft}from"../browser/shared/i18n/index.mjs";import{reportsDirectory as ln}from"../browser/shared/paths.mjs";import{moveDocument as fn,outlineAndFile as dn,ownsOutline as wn,placeIn as ut,readOutline as oe,validOutline as se,withOutlineLock as ce,writeHead as mn,writeOutline as pn,writtenAs as kn}from"../browser/shared/outline.mjs";ze();import ct from"node:fs/promises";import bt from"node:path";import{attr as Ke,walk as Ue}from"../browser/shared/html-tree.mjs";import{escapeAttribute as Ve}from"../browser/shared/escape.mjs";import{COMPONENTS_FOLDER as Qe,DOCUMENT_FOLDERS as Xe,SHARED_FOLDERS as Ze,documentFiles as te,packageFolders as qe,readLink as De}from"../browser/shared/workspace.mjs";async function Lt(w,m){let p=await ct.readdir(bt.join(w,m),{withFileTypes:!0});if(!Ze.includes(m))return p.map(({name:h})=>h);let c=m===Qe?new Set(qe(w).map(({id:h})=>h.split("/")[0])):new Set;return p.filter(h=>h.isFile()||Xe.includes(h.name)&&!c.has(h.name)).map(({name:h})=>h)}async function At(w,m,p,c,{names:h=new Map}={}){let b=bt.join(w,m),D=await ct.access(te(b).html).then(()=>!0,()=>!1)?null:await De(b),G=new Set(["",...await Lt(w,m)]);if(await ct.cp(b,p,{recursive:!0,errorOnExist:!0,force:!1,filter:s=>G.has(bt.relative(b,s).split(bt.sep)[0])}),D)return[];let tt=te(p).html,et=await ct.readFile(tt,"utf8"),v=Ot(et),wt=new Map,nt=new Set;Ue(Zt(v.replace(/^\uFEFF/," "),{sourceCodeLocationInfo:!0}),s=>{let J=Ke(s,"data-doc-component");J&&nt.add(J);for(let{name:P,value:$}of s.attrs??[]){let it=s.sourceCodeLocation?.attrs?.[P];if(!it)continue;let S=/^(\.\.\/)([a-z0-9]+(?:-[a-z0-9]+)*)(\/.*)$/.exec($),C=P==="data-doc-id"&&$===m?c:["href","src","poster"].includes(P)&&S&&h.has(S[2])?`../${h.get(S[2])}${S[3]}`:$;C!==$&&wt.set(it.startOffset,{to:it.endOffset,text:`${P}="${Ve(C)}"`})}});let V=[...wt].sort(([s],[J])=>J-s).reduce((s,[J,P])=>s.slice(0,J)+P.text+s.slice(P.to),v);return await ct.writeFile(tt,V),[...nt]}import{storedHead as hn}from"../browser/shared/sidebar-head.mjs";import{changeFavorites as gn,readFavorites as yn}from"../browser/shared/favorites.mjs";import{DOCS as jt,columnWorkspaceId as On,entryWorkspace as bn,entryPattern as ue,isForeign as le,isTop as U,topOf as Q}from"../browser/shared/outline-shape.mjs";import{addDraft as xn,addWorkspace as jn,draftEntry as fe,draftFacts as de,draftOf as X,findDraft as Sn,foreignMarker as vn,projectChoices as Pn,registeredIds as St,workspaceNames as En,workspaceOf as Z}from"../browser/shared/drafts.mjs";import{forgetSnapshot as $t,shownWorkspaces as Nn}from"../browser/shared/workspace-columns.mjs";import{nameStops as In}from"../browser/shared/workspace-name.mjs";import{registerWorkspace as Ln,workspaceId as Rt,workspaceKey as we}from"../browser/shared/workspace-registry.mjs";import{spawn as tn}from"node:child_process";import ee from"node:path";var en=w=>!["","0",void 0].includes(w);function nn(w,{platform:m=process.platform,env:p=process.env}={}){return en(p.GALLERY_NO_BROWSER)?{skip:"GALLERY_NO_BROWSER is set"}:m==="win32"?{command:ee.join(p.SystemRoot||p.windir||"C:\\Windows","explorer.exe"),args:[`/select,"${w}"`],verbatim:!0}:m==="darwin"?{command:"open",args:["-R",w]}:!p.DISPLAY&&!p.WAYLAND_DISPLAY?{skip:"no display here (neither DISPLAY nor WAYLAND_DISPLAY is set)"}:{command:"xdg-open",args:[ee.dirname(w)]}}function ne(w,m){let p=nn(w,m);return p.skip?Promise.resolve({opened:!1,why:p.skip}):new Promise(c=>{let h;try{h=tn(p.command,p.args,{detached:!0,stdio:"ignore",windowsHide:!1,windowsVerbatimArguments:!!p.verbatim})}catch(b){return c({opened:!1,why:b.code??b.message})}h.once("error",b=>c({opened:!1,why:b.code??b.message})),h.once("spawn",()=>{h.unref(),c({opened:!0})})})}import{LINK_FILE as Tt,linkStem as An,linkValue as lt,ownAddress as Jt,readLinkText as Fn}from"../browser/shared/web-links.mjs";import{sameDirectory as ft}from"../browser/shared/preview-server.mjs";import{slugPattern as I}from"../browser/shared/reports.mjs";import{PAGE_SLUG as $n,SHARED_FOLDERS as me,defaultWorkspace as vt,documentDirectory as pe,documentFiles as Pt,ensureWorkspace as Rn,idHolder as Ct,isDocSlug as Mt,keptName as Tn,layoutOf as _t,listTrash as ke,newDocSlug as Et,pageSlug as he,readLink as Gt,slugTaken as Wt,trashIdPattern as ge}from"../browser/shared/workspace.mjs";import{createPage as Jn,headOf as ye,listPages as Oe,newPageSlug as Cn,pageFiles as q,readPageMeta as Yt,renamePage as Mn}from"../browser/shared/pages.mjs";import{editExtension as _n,extensionSource as Gn,listExtensions as Wn}from"../browser/shared/extensions.mjs";import{LOOK as be,effectiveLook as xe,ownLookOf as Yn,updatedOwnLook as Bn,withLookField as Hn}from"../browser/shared/document-look.mjs";import{workspaceLook as dt,writeGlobalLook as zn}from"../browser/shared/workspace-look.mjs";import{findIn as Kn,tidyQuery as Un}from"../browser/shared/search.mjs";import{ALIVE_FOR as rn,cleanReport as an,saveOf as on}from"../browser/shared/presence.mjs";function ie({now:w=Date.now,aliveFor:m=rn}={}){let p=new Map,c=()=>{for(let[h,b]of p)w()-b.seen>m&&p.delete(h)};return{report(h){let b=an(h);if(!b)return{ok:!1};if(b.gone)return p.delete(b.tab),{ok:!0};let N=p.get(b.tab),D=!N||b.touched||N.entry!==b.entry?w():N.used;return p.set(b.tab,{...b,used:D,seen:w()}),c(),{ok:!0}},list(){return c(),[...p.values()].sort((h,b)=>b.used-h.used||b.seen-h.seen)},clear:()=>p.clear(),now:w}}function re(w,m,p){return{tab:w.tab,kind:w.kind,slug:w.entry.replace(/^@/,""),title:w.title,file:m.file??null,workspace:m.workspace??null,visible:w.visible,focused:w.focused,idle:Math.max(0,Math.round((p-w.used)/1e3)),save:on(w.flags),conflicts:w.flags.conflicts,notes:w.notes,caret:w.caret,selection:w.selection}}var Vn=([w,m,p,...c])=>c.length?z("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}\uFF1B{2} \u7B49 {3} \u6761",w,m,p,c.length+3):p!==void 0?z("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}\uFF1B{2}",w,m,p):m!==void 0?z("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}",w,m):z("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}",w),Nt=w=>w==="en"?"en":null,Qn=32*1024*1024;async function H(w,m){for(let p=0;;p++)try{return await x.rename(w,m)}catch(c){if(!["EPERM","EBUSY","EACCES"].includes(c.code))throw c;if(p>=5)break;await new Promise(h=>setTimeout(h,60*(p+1)))}await x.cp(w,m,{recursive:!0,errorOnExist:!0,force:!1}),await x.rm(w,{recursive:!0,force:!0,maxRetries:5})}var Xn=w=>k.resolve(w);function zi({unified:w=!1,edits:m,reports:p,reportsDirectory:c=ln,server:h={kind:"dev",version:null,stop:null},components:b=null,changed:N=()=>{},index:D=null,web:G=null,projects:tt={touch(){},indexOf:async()=>null},presence:et=ie()}){let{trash:v}=_t(c),wt=null,nt=()=>wt??=In(),V=D??Dt({root:c,read:qt(m),draw:(t,e)=>p.words(t,e)}),s=(t,e,n)=>[t,{ok:!1,reason:e,...Ft(n)}],J=t=>x.readFile(t,"utf8").then(JSON.parse).catch(()=>null),P=t=>pe(t,c),$=t=>Pt(P(t)),it=t=>{let e=t.kind==="page",n=t.entry.replace(/^@/,""),i=X(n),r=i?Z(i.ws).root??null:c;if(!r)return{file:null,workspace:null};let a=i?i.slug:n;return{file:k.resolve(e?q(a,r).html:Pt(pe(a,r)).html),workspace:k.resolve(r)}},S=t=>k.join(c,t),C=t=>rt(Pt(S(t)).html),mt=t=>Promise.resolve(m.forgetChanges?.(t)).catch(()=>{}),je=t=>Lt(c,t),Bt=async(t,e,n)=>{await x.mkdir(n,{recursive:!0});let i=[];try{for(let r of t)await H(k.join(e,r),k.join(n,r)),i.push(r)}catch(r){for(let a of i)await H(k.join(n,a),k.join(e,a));throw r}},Se=async(t,e)=>{if(!me.includes(t))return H(S(t),e);await Bt(await je(t),S(t),e),await x.rmdir(S(t)).catch(()=>{})},ve=async(t,e)=>me.includes(t)&&!await C(t)&&(await Promise.all((await x.readdir(e)).map(n=>rt(k.join(S(t),n))))).every(n=>!n),W=async t=>await J(Pt(t).json)??{},R=async(t,e=null)=>{let{title:n=t,description:i="",type:r,instructions:a,icon:o,look:u}=await W(P(t)),l=a===!0?{}:xe(u,e??dt(c));return{slug:t,title:n,description:i,...r?{type:r}:{},...typeof o=="string"&&o?{icon:o}:{},...a===!0?{instructions:!0}:{},...Object.keys(l).length?{look:l}:{}}},pt=async t=>{let e=await Gt(S(t));return e&&{slug:t,title:e.title,description:"",kind:"link",url:e.url,...e.icon?{icon:e.icon}:{},...e.siteIcon?{siteIcon:e.siteIcon}:{}}},Pe=async(t,e,n=[])=>{let i=X(t),r=i&&n.find(({id:B})=>B===i.ws),a=r?.facts.get(i.slug);if(a){let B=k.join(r.root,i.slug);return{slug:t,title:a.title,description:a.description,kind:a.kind==="link"?"link":"draft",workspace:i.ws,...a.icon?{icon:a.icon}:{},...a.kind==="link"?{url:a.url,siteIcon:a.siteIcon}:{},path:a.path,folder:B,root:r.root}}let{ws:o,title:u,description:l,icon:f,path:y,folder:E,root:d,missing:O,kind:g,url:j,siteIcon:F}=await de(t,e);return{slug:t,title:u,description:l,kind:g==="link"?"link":"draft",workspace:o,...g==="link"?{url:j,siteIcon:F}:{},...f?{icon:f}:{},...y?{path:y,folder:E,root:d}:{},...O?{missing:O}:{}}},Ht=async(t,e,n,i,r=null)=>le(t)?Pe(t,n,i):e.includes(t)?await pt(t)??{slug:t,title:t,description:"",kind:"link",url:""}:R(t,r),L=Rt(c),Ee=()=>we(vt())===we(c),Ne=(t,e)=>{let n=t.shown.find(({isDefault:u})=>u)?.id??(Ee()?L:null),i=new Set([...t.drafts.map(u=>X(u)?.ws),...t.groups.map(({workspace:u})=>u),...t.shown.map(({id:u})=>u)].filter(Boolean)),r=new Set(t.groups.filter(({workspace:u,title:l})=>u&&!l).map(({workspace:u})=>u));t.groups.find(({id:u})=>u===jt)?.title||r.add(L),r.delete(n);let a=En(new Set([...i,L]),{ids:new Map([...e,[L,[c]]]),stops:nt(),among:r});tt.touch(new Map([...a].filter(([u])=>u!==L).map(([u,{root:l}])=>[u,l])));let o=Object.fromEntries([...i].map(u=>[u,{...a.get(u)??{missing:Z(u,e).refused??"unknown"},...u===n?{default:!0}:{}}]));return o[L]={...a.get(L),there:!0,self:!0,...L===n?{default:!0}:{}},o},Ie=()=>he(c),Le=async(t,e)=>{let n=await W(P(t));await T($(t).json,`${JSON.stringify({...n,[e]:!0},null,2)}
|
|
3
|
+
`)},rt=t=>x.access(t).then(()=>!0,()=>!1),kt=async(t,{own:e=null}={})=>{let n=new Set((await at()).map(({slug:i})=>i));n.delete(e);for(let i=1;;i++){let r=i===1?t:`${t}-${i}`;if(!Wt(r,c)&&!n.has(r))return r}},It=async t=>{let e=await kt(t.slug,{own:t.slug});return Mt(t.slug)?e===t.slug&&!await Ct(t.slug,c)?e:Et(c):e},Ae=async(t,e)=>{let n=$(t).html,i=await x.readFile(n,"utf8"),r=Ot(i).replace(`data-doc-id="${e}"`,`data-doc-id="${t}"`);r!==i&&await T(n,r)},A=()=>oe(c),Y=async t=>{await pn(c,t),N()},M=t=>ce(c,t);async function ht(t,e="",n=1/0){await M(async()=>{let i=await A();ut(i,t,e,n),await Y(i)})}async function Fe(t,{parent:e="",after:n=null,first:i=!1}={}){await M(async()=>{let r=await A();for(let o of Object.values(r.children))o.includes(t)&&o.splice(o.indexOf(t),1);let a=typeof n=="string"?Object.keys(r.children).find(o=>r.children[o].includes(n)):void 0;a!==void 0?ut(r,t,a,r.children[a].indexOf(n)+1):ut(r,t,typeof e=="string"?e:"",i===!0?0:1/0),await Y(r)})}function $e(t,e){let n=new Set(Object.values(t.children).flat()),i={...t.children};for(let{id:r}of e.groups){if(r===jt)continue;let a=o=>{let u=(e.children[o]??[]).filter(l=>!n.has(l));(U(o)||u.length)&&(i[o]=u),u.forEach(a)};a(Q(r))}return{groups:e.groups,children:i}}function zt(t){return M(async()=>{let e=await A();for(let[n,i]of Object.entries(e.children)){let r=i.indexOf(t);if(!(r<0))return i.splice(r,1,...e.children[t]??[]),delete e.children[t],await Y(e),{parent:n,index:r}}return{parent:"",index:1/0}})}let Re=(t,e)=>V.lines(t,e),Kt=t=>J(k.join(v,t,"entry.json")),at=()=>ke(c),Te=()=>w?[...St()].filter(([t,e])=>t!==L&&e.length===1).map(([t,e])=>({id:t,root:e[0]})):[],Ut=async()=>[...await at(),...(await Promise.all(Te().map(async({id:t,root:e})=>(await ke(e)).map(n=>({...n,id:fe(t,n.id),slug:fe(t,n.slug)}))))).flat()];async function Je(t){let e=await Yt(t,c);if(!e)return s(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762");let n=`${Date.now().toString(36)}-${xt(3).toString("hex")}`;try{await x.mkdir(k.join(v,n),{recursive:!0}),await H(q(t,c).folder,k.join(v,n,"page"))}catch(r){throw await x.rm(k.join(v,n),{recursive:!0,force:!0}).catch(()=>{}),r}let i={id:n,kind:"page",slug:t,title:e.title,at:Date.now(),parent:"",index:-1};return await T(k.join(v,n,"entry.json"),`${JSON.stringify(i,null,2)}
|
|
4
|
+
`),[200,{ok:!0,entry:i}]}async function Ce(t){let e=k.join(v,t.id,"page"),n=await It(t);if(await x.mkdir(_t(c).customPages,{recursive:!0}),await H(e,q(n,c).folder),n!==t.slug){let{html:i}=q(n,c),r=await x.readFile(i,"utf8").catch(()=>null),a=r?.replace(`data-page-id="${t.slug}"`,`data-page-id="${n}"`);r!==null&&a!==r&&await T(i,a)}return await x.rm(k.join(v,t.id),{recursive:!0,force:!0}),[200,{ok:!0,page:await Yt(n,c),entry:{...t,slug:n}}]}async function Me(t){let e=await Gt(S(t));if(!e)return s(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u94FE\u63A5");let n=`${Date.now().toString(36)}-${xt(3).toString("hex")}`,i=await A(),{parent:r,index:a}=await zt(t);try{await x.mkdir(k.join(v,n),{recursive:!0}),await H(S(t),k.join(v,n,"link"))}catch(u){throw await M(()=>Y(i)),await x.rm(k.join(v,n),{recursive:!0,force:!0}).catch(()=>{}),u}let o={id:n,kind:"link",slug:t,title:e.title,at:Date.now(),parent:r,index:Number.isFinite(a)?a:-1};return await T(k.join(v,n,"entry.json"),`${JSON.stringify(o,null,2)}
|
|
5
|
+
`),[200,{ok:!0,entry:o}]}async function _e(t){let e=k.join(v,t.id,"link"),n=await It(t);return await H(e,S(n)),await x.rm(k.join(v,t.id),{recursive:!0,force:!0}),await ht(n,t.parent,t.index<0?1/0:t.index),[200,{ok:!0,report:await pt(n),entry:{...t,slug:n}}]}function Ge(t,{parent:e,after:n,first:i}){let r=o=>U(o)?Object.hasOwn(t.children,o):Object.values(t.children).some(u=>u.includes(o));if(n!=null){let o=Object.keys(t.children).find(u=>t.children[u].includes(n));return o===void 0?{refused:[404,"after","\u627E\u4E0D\u5230\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6761\u76EE"]}:e!=null&&e!==o?{refused:[409,"level","\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6761\u76EE\u4E0D\u5728\u8FD9\u4E00\u5C42"]}:{parent:o,index:t.children[o].indexOf(n)+1}}let a=e??Q(jt);return U(a)&&t.groups.some(o=>o.extension&&Q(o.id)===a)?{refused:[409,"extension","\u6269\u5C55\u7684\u680F\u91CC\u653E\u4E0D\u4E86\u522B\u7684\u6761\u76EE"]}:r(a)?{parent:a,index:i?0:(t.children[a]??[]).length}:{refused:[404,"parent",U(a)?"\u627E\u4E0D\u5230\u8FD9\u4E00\u680F":"\u627E\u4E0D\u5230\u8981\u653E\u5230\u5B83\u4E0B\u9762\u7684\u6761\u76EE"]}}let K=new Map;function We(t){let e=K.get(t);if(e&&Date.now()-e.at<36e5)return e.answer;let n=G?G.frameable(t).catch(()=>({frameable:!0,reason:"unknown"})):Promise.resolve({frameable:!0,reason:"unknown"});return K.size>=500&&K.delete(K.keys().next().value),K.set(t,{at:Date.now(),answer:n}),n.then(i=>{["auth","unknown"].includes(i.reason)&&K.get(t)?.answer===n&&K.delete(t)}),n}function Vt(t,e){return G?.icon?(async()=>{let n=await G.icon(e).catch(()=>null);if(!n)return null;let i=k.join(S(t),Tt),r=await x.readFile(i,"utf8").catch(()=>null),a=r===null?null:Fn(r);if(!a||a.url!==e||a.siteIcon===n)return null;let o=lt({...a,siteIcon:n});return o.refused||!o.value.siteIcon||!await T(i,`${JSON.stringify(o.value,null,2)}
|
|
6
|
+
`,{expect:r})?null:(N(),n)})().catch(()=>null):Promise.resolve(null)}let Qt={preferences:async()=>[200,{ok:!0,items:await ae()}],status:async()=>{let t=et.now(),e=await Promise.all(et.list().map(async n=>re(n,await it(n),t)));return[200,{ok:!0,open:e,last:e[0]??null}]},info:async()=>[200,{ok:!0,version:1,gallery:h.version,token:m.token,commands:[...Object.keys(ot)],server:{pid:process.pid,home:k.resolve(vt()),data:un().data,version:h.version,kind:h.kind,sandbox:h.sandbox}}],async outline(){let{outline:t,others:e}=await dn(c),n=await Ie(),i=[...Object.values(t.children).flat(),...n?[n]:[]],r=St(),a=dt(c),o=async O=>[O,await Ht(O,t.links,r,e,a)],[u,l,f,y]=await Promise.all([Promise.all(i.map(o)),Oe(vt()),Ut(),Wn(c)]),E=y.map(({id:O,file:g,revision:j,title:F,icon:B,entries:gt,count:yt,error:st})=>({id:O,file:g,revision:j,title:F,...B?{icon:B}:{},entries:gt,count:yt,...st?{error:Ft(st)}:{}})),d=await ye(c,l);return[200,{ok:!0,outline:t,instructions:n,reports:Object.fromEntries(u),pages:l,head:d,trash:f,workspaces:Ne(t,r),self:L,shared:!0,extensions:E,sandbox:h.sandbox,favorites:await yn(c)}]},trash:async()=>[200,{ok:!0,entries:await Ut()}],async stats(t){let e=t.get("slug")??"",n=I.test(e)?await V.facts(e).catch(()=>null):null;return n?[200,{ok:!0,edited:n.edited,words:n.words}]:s(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,...b.read()}],async source(t){let e=t.get("slug")??"",n=t.get("kind")==="page";if(!I.test(e))return s(404,"missing",n?"\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762":"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let i=k.resolve(n?q(e,c).html:$(e).html);return await rt(i)?[200,{ok:!0,path:i}]:s(404,"missing",n?"\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762":"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863")},projects:async()=>[200,{ok:!0,workspaces:await Pn(c,{stops:nt()})}],async search(t){let e=Un(t.get("q")??"");if(!e)return[200,{ok:!0,results:[]}];let{children:n,groups:i,links:r}=await A(),a=St(),o=new Map,u=[],l=g=>(n[g]??[]).forEach(j=>{!r.includes(j)&&(!le(j)||X(j))&&u.push(j),l(j)});for(let{id:g}of i)l(Q(g));let f=e.toLowerCase(),y=dt(c),E=new Map(await Promise.all(u.map(async g=>[g,await Ht(g,r,a,void 0,y)]))),d=JSON.stringify([...E].map(([g,{title:j}])=>[g,j])),O=(await Promise.all(u.map(async g=>{let j=X(g),F=j?Z(j.ws,a):null;F&&!F.refused&&!o.has(F.root)&&o.set(F.root,tt.indexOf(F.root,a));let B=F&&!F.refused?await o.get(F.root):null,gt=j?await B?.lines(j.slug,d):await Re(g,d);if(!gt)return null;let yt=String(E.get(g).title).toLowerCase().includes(f),{count:st,hits:He}=Kn(gt,e);return yt||st?{slug:g,title:yt,count:st,hits:He}:null}))).filter(Boolean);return O.sort((g,j)=>Number(j.title)-Number(g.title)||j.count-g.count),[200,{ok:!0,results:O.slice(0,50)}]}},ot={async"preference-edit"(t){try{let e=await sn(t);if(t.action==="rename"){let n=e.items.find(i=>i.id===e.selected);n?.slug&&await m.renameReport(n.slug,n.name)}return N(),[200,{ok:!0,...e}]}catch(e){return s(409,"preferences",e)}},async"extension-edit"({id:t,...e}){let n=await Gn(c,t),i=await ce(n?.root??c,()=>_n(n?.root??c,t,e),{local:!0});return i.ok?(i.written&&N(),[200,{ok:!0}]):s(i.status,i.reason,i.error)},async outline({outline:t,base:e}){return!se(t)||e!==void 0&&!se(e)?s(400,"outline","\u6587\u6863\u76EE\u5F55\u7684\u7ED3\u6784\u4E0D\u5BF9\uFF1A\u6BCF\u4EFD\u6587\u6863\u53EA\u80FD\u51FA\u73B0\u4E00\u6B21"):wn(c,t)?await M(async()=>{let i=await A();return e!==void 0&&!kn(e,i)?!1:(await Y(t.groups?t:$e(t,i)),!0)})?[200,{ok:!0,outline:await A()}]:s(409,"stale","\u6587\u6863\u76EE\u5F55\u521A\u5728\u522B\u5904\u6539\u8FC7"):s(409,"cross-workspace","\u8DE8\u5DE5\u4F5C\u533A\u8BF7\u590D\u5236\uFF0C\u4E0D\u80FD\u53EA\u79FB\u52A8\u76EE\u5F55\u4F4D\u7F6E")},async move({slug:t,parent:e,after:n=null,first:i=!1,workspace:r}){if(typeof r=="string"&&!ft(r,c))return s(409,"elsewhere","\u8FD9\u4E2A\u9884\u89C8\u670D\u52A1\u5668\u7BA1\u7684\u662F\u53E6\u4E00\u4E2A\u76EE\u5F55\u7684\u6587\u6863");let a=f=>typeof f=="string"&&I.test(f),o=f=>a(f)||typeof f=="string"&&/^:[a-z0-9]+(?:-[a-z0-9]+)*$/.test(f);if(!a(t)||e!==void 0&&e!==""&&!o(e)||n!==null&&!a(n)||typeof i!="boolean")return s(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");if((await Promise.all([t,e,n].filter(a).map(f=>W(P(f))))).some(f=>f?.instructions===!0))return s(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 fn(c,t,{parent:e,after:n,first:i});if(l.written&&N(),!l.ok){let[f,y]={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 s(f,l.reason,y)}return[200,{ok:!0,...l,outline:await A()}]},async create({title:t,description:e,parent:n="",after:i=null,first:r=!1,language:a}){let o=typeof t=="string"?t.replace(/\s+/g," ").trim().slice(0,200):"",u=await Et(c);return await mt(u),await p.create(u,o,typeof e=="string"&&e.trim()?e.trim():"\u65B0\u6587\u6863",{lang:Nt(a)}),await Fe(u,{parent:n,after:i,first:r}),[200,{ok:!0,report:await R(u)}]},async instructions({title:t,description:e,language:n,preference:i}){let r=await ae(),a=i?r.find(y=>y.id===i):r[0];if(!a)return s(404,"missing","\u627E\u4E0D\u5230\u5199\u4F5C\u504F\u597D");i=a.id;let o=await he(c,i);if(o)return(await R(o)).title!==a.name&&await m.renameReport(o,a.name),[200,{ok:!0,report:await R(o)}];let u=await kt($n),l=(y,E)=>typeof y=="string"&&y.trim()?y.trim().slice(0,200):E;await p.create(u,a.name,l(e,"Agent \u6BCF\u6B21\u5199\u62A5\u544A\u524D\u90FD\u4F1A\u5148\u8BFB\u7684\u5199\u4F5C\u504F\u597D"),{lang:Nt(n),page:!0}),await Le(u,"instructions");let f=await W(P(u));return await T($(u).json,JSON.stringify({...f,preference:i},null,2)+`
|
|
7
|
+
`),[200,{ok:!0,report:await R(u)}]},async components({id:t,hidden:e,shown:n,disabled:i,unlisted:r,net:a,pack:o,enabled:u}){try{return[200,{ok:!0,...await b.write(o!==void 0?{pack:o,enabled:u}:{id:t,hidden:e,shown:n,disabled:i,unlisted:r,net:a})}]}catch(l){return s(409,"components",l)}},async duplicate({slug:t,suffix:e,untitled:n,as:i,title:r}){if(typeof t!="string"||!I.test(t)||!await C(t))return s(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");if(i!==void 0&&(typeof i!="string"||!I.test(i)||Tn(i))||r!==void 0&&typeof r!="string")return s(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");if(i!==void 0&&(Wt(i,c)||(await at()).some(O=>O.slug===i)||Mt(i)&&await Ct(i,c)))return s(409,"slug","\u8FD9\u4E2A\u6587\u6863\u540D\u5DF2\u7ECF\u6709\u4E86");let a=i??await Et(c);await mt(a),await At(c,t,S(a),a);let{title:o}=await R(t),u=o||(typeof n=="string"&&n.trim()?n.trim().slice(0,50):"\u672A\u547D\u540D\u6587\u6863"),l=typeof r=="string"?r.replace(/\s+/g," ").trim().slice(0,200):"",f=await m.renameReport(a,l||`${u}${typeof e=="string"&&e.length>0&&e.length<=20?e:"\uFF08\u526F\u672C\uFF09"}`),y=await A(),[E,d]=Object.entries(y.children).find(([,O])=>O.includes(t))??["",null];return await ht(a,E,d?d.indexOf(t)+1:1/0),[200,{ok:!0,report:await R(a),notes:f.notes??[]}]},async"copy-from"({sourceWs:t,slug:e,parent:n="",index:i=0,keep:r=!1}){let a=typeof t=="string"?Z(t):{};if(!a.root||t===L||typeof e!="string"||!I.test(e)||typeof n!="string"||!U(n)&&!ue.test(n)||!Number.isInteger(i)||i<0)return s(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");let o=await oe(a.root);if(!Object.values(o.children).some(d=>d.includes(e)))return s(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let u=[],l=d=>{if(!I.test(d)||u.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");u.push(d);for(let O of o.children[d]??[])l(O)};l(e);let f=new Map;for(let d of u){let O=null;if(r===!0&&!Wt(d,c)&&!(await at()).some(g=>g.slug===d)&&!(Mt(d)&&await Ct(d,c))&&(O=d),O===null)do O=await Et(c);while([...f.values()].includes(O));f.set(d,O)}let y=k.join(_t(c).gallery,`copy-${xt(8).toString("hex")}`),E=[];try{await x.mkdir(y,{recursive:!0});for(let d of u)await At(a.root,d,k.join(y,f.get(d)),f.get(d),{names:f});for(let d of u)await mt(f.get(d));return await M(async()=>{let d=await A();if((U(n)?On(d.groups.find(g=>Q(g.id)===n),L):bn(n,L))!==L||(U(n)?!d.groups.some(g=>Q(g.id)===n&&!g.extension):!Object.values(d.children).some(g=>g.includes(n))))throw new Error("\u627E\u4E0D\u5230\u8981\u653E\u5230\u5B83\u4E0B\u9762\u7684\u6587\u6863");for(let g of u){let j=f.get(g);await x.rename(k.join(y,j),S(j)),E.push(S(j))}$t(c),ut(d,f.get(e),n,i);for(let g of u)o.children[g]?.length&&(d.children[f.get(g)]=o.children[g].map(j=>f.get(j)));await Y(d)}),[200,{ok:!0,slug:f.get(e),count:u.length}]}catch(d){for(let O of E)await x.rm(O,{recursive:!0,force:!0});return $t(c),s(409,"copy",d.text?d:d.message)}finally{await x.rm(y,{recursive:!0,force:!0})}},async look({slug:t,look:e,field:n,value:i}){if(typeof t!="string"||!I.test(t)||!await C(t))return s(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");if((await W(P(t)))?.instructions===!0)return s(409,"instructions","\u5199\u4F5C\u504F\u597D\u6CA1\u6709\u5B57\u4F53\u4E0E\u5E03\u5C40");let r=n!==void 0||i!==void 0;if(r?typeof n!="string"||!Object.hasOwn(be,n)||!be[n].includes(i):e!==null&&(typeof e!="object"||Array.isArray(e)))return s(400,"look","\u5B57\u4F53\u4E0E\u5E03\u5C40\u4E0D\u5BF9");let a=$(t).json,o=null;try{o=JSON.parse(await x.readFile(a,"utf8"))}catch{}if(!o||typeof o!="object"||Array.isArray(o))return s(409,"metadata","\u8FD9\u4EFD\u6587\u6863\u7684\u6807\u9898\u548C\u8BF4\u660E\u8BFB\u4E0D\u51FA\u6765");let u=r?{...Yn(o.look),[n]:i}:Bn(o.look,dt(c),e),l=Hn(o,u);return JSON.stringify(l)!==JSON.stringify(o)&&await T(a,`${JSON.stringify(l,null,2)}
|
|
8
|
+
`),[200,{ok:!0,report:await R(t)}]},async looks({slug:t}){if(typeof t!="string"||!I.test(t)||!await C(t))return s(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");if((await W(P(t)))?.instructions===!0)return s(409,"instructions","\u5199\u4F5C\u504F\u597D\u6CA1\u6709\u5B57\u4F53\u4E0E\u5E03\u5C40");let e=await J($(t).json);if(!e||typeof e!="object"||Array.isArray(e))return s(409,"metadata","\u8FD9\u4EFD\u6587\u6863\u7684\u6807\u9898\u548C\u8BF4\u660E\u8BFB\u4E0D\u51FA\u6765");let n=xe(e.look,dt(c));try{await zn(n)}catch(i){return s(409,"look",i)}return N(),[200,{ok:!0,look:n}]},async head({order:t}){let e=hn(t);return e?(await M(()=>mn(c,e)),N(),[200,{ok:!0,head:await ye(c,await Oe(vt()))}]):s(400,"head","\u4FA7\u680F\u5934\u90E8\u7684\u987A\u5E8F\u4E0D\u5BF9")},async"new-page"({title:t,after:e=null,language:n}){let i=typeof t=="string"?t.replace(/\s+/g," ").trim():"";if(!i||i.length>200)return s(400,"title","\u6807\u9898\u4E0D\u80FD\u662F\u7A7A\u7684\uFF0C\u4E5F\u4E0D\u80FD\u8D85\u8FC7 200 \u4E2A\u5B57");if(e!==null&&(typeof e!="string"||!I.test(e)))return s(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");let r=await Cn(c);return await Jn(r,i,{root:c,blank:!0,after:e,...Nt(n)?{lang:Nt(n)}:{}}),N(),[200,{ok:!0,page:await Yt(r,c)}]},async rename({slug:t,title:e,kind:n="document"}){if(typeof t!="string"||!I.test(t))return s(400,"slug","\u6587\u6863\u540D\u4E0D\u5BF9");if(n==="page"){let r;try{r=await Mn(t,e,c)}catch{return s(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}]:s(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762")}let i=await m.renameReport(t,e);return i.ok?[200,{ok:!0,report:await R(t),notes:i.notes}]:s({title:400,missing:404}[i.reason]??409,i.reason,i.message??"\u6539\u540D\u6CA1\u6709\u6210\u529F")},async favorite({add:t=[],remove:e=[]}){let n=r=>Array.isArray(r)&&r.length<=1e3&&r.every(a=>typeof a=="string"&&ue.test(a));if(!n(t)||!n(e))return s(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");if(t.length){let r=new Set(Object.values((await A()).children).flat());if(t.some(a=>!r.has(a)))return s(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863")}let i=await gn(c,{add:t,remove:e});return i.changed&&N(),[200,{ok:!0,...i}]},async trash({slug:t,kind:e="document"}){if(typeof t!="string"||!I.test(t))return s(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");if(e==="page")return Je(t);if(e==="link")return Me(t);if((await W(P(t)))?.instructions===!0)return s(409,"instructions","\u5199\u4F5C\u504F\u597D\u4E0D\u80FD\u79FB\u5230\u56DE\u6536\u533A");if(!await C(t))return s(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let{title:n}=await R(t),i=`${Date.now().toString(36)}-${xt(3).toString("hex")}`,r=await A(),{parent:a,index:o}=await zt(t);try{await x.mkdir(k.join(v,i),{recursive:!0}),await Se(t,k.join(v,i,"report"))}catch(l){throw await M(()=>Y(r)),await x.rm(k.join(v,i),{recursive:!0,force:!0}).catch(()=>{}),l}let u={id:i,kind:"document",slug:t,title:n,at:Date.now(),parent:a,index:Number.isFinite(o)?o:-1};return await T(k.join(v,i,"entry.json"),`${JSON.stringify(u,null,2)}
|
|
9
|
+
`),[200,{ok:!0,entry:u}]},async restore({id:t}){let e=typeof t=="string"&&ge.test(t)?await Kt(t):null;if(!e)return s(404,"missing","\u56DE\u6536\u533A\u91CC\u6CA1\u6709\u8FD9\u4E00\u9879");if(e.kind==="page")return Ce(e);if(e.kind==="link")return _e(e);let n=k.join(v,t,"report"),i=await ve(e.slug,n),r=i?e.slug:await It(e);return i?await Bt(await x.readdir(n),n,S(r)):await H(n,S(r)),r!==e.slug&&await Ae(r,e.slug),await x.rm(k.join(v,t),{recursive:!0,force:!0}),await ht(r,e.parent,e.index<0?1/0:e.index),[200,{ok:!0,report:await R(r),entry:{...e,kind:"document",slug:r}}]},async destroy({id:t}){let e=typeof t=="string"&&ge.test(t)?await Kt(t):null;return e?((e.kind??"document")==="document"&&!await C(e.slug)&&await mt(e.slug),await x.rm(k.join(v,t),{recursive:!0,force:!0}),[200,{ok:!0}]):s(404,"missing","\u56DE\u6536\u533A\u91CC\u6CA1\u6709\u8FD9\u4E00\u9879")},async link({url:t,title:e,icon:n=null,parent:i,after:r=null,first:a=!1},{port:o,wait:u=!1}={}){let l=lt({url:t,title:e,icon:n});if(l.refused)return s(400,l.refused,l.message);if(Jt(l.value.url,o))return s(409,"own","\u8FD9\u662F Gallery \u81EA\u5DF1\u7684\u5730\u5740\uFF0C\u8BF7\u76F4\u63A5\u94FE\u63A5\u6587\u6863");if(i!=null&&typeof i!="string"||r!==null&&typeof r!="string"||typeof a!="boolean")return s(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");let f=await M(async()=>{let E=await A(),d=Ge(E,{parent:i,after:r,first:a||i==null&&r===null});if(d.refused)return d;let O=await kt(An(l.value.title,l.value.url));return await x.mkdir(S(O),{recursive:!0}),await T(k.join(S(O),Tt),`${JSON.stringify(l.value,null,2)}
|
|
10
|
+
`),ut(E,O,d.parent,d.index),await Y(E),{slug:O,parent:d.parent,index:d.index}});if(f.refused)return s(...f.refused);let y=Vt(f.slug,l.value.url);return u&&await y,[200,{ok:!0,link:await pt(f.slug),parent:f.parent,index:f.index,outline:await A()}]},async"link-set"({slug:t,url:e,title:n,icon:i},{port:r,wait:a=!1}={}){let o=typeof t=="string"&&I.test(t)?await Gt(S(t)):null;if(!o)return s(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u94FE\u63A5");let u=e??o.url,l=lt({url:u,title:n??o.title,icon:i===void 0?o.icon??null:i,siteIcon:o.siteIcon??null});if(l.refused)return s(400,l.refused,l.message);let f=l.value.url!==o.url;if(f&&Jt(l.value.url,r))return s(409,"own","\u8FD9\u662F Gallery \u81EA\u5DF1\u7684\u5730\u5740\uFF0C\u8BF7\u76F4\u63A5\u94FE\u63A5\u6587\u6863");if(f&&delete l.value.siteIcon,JSON.stringify(l.value)!==JSON.stringify(o)&&await T(k.join(S(t),Tt),`${JSON.stringify(l.value,null,2)}
|
|
11
|
+
`),f){let y=Vt(t,l.value.url);a&&await y}return[200,{ok:!0,link:await pt(t)}]},async"draft-add"({path:t,confirm:e=!1,after:n=null}){if(h.sandbox)return s(403,"sandbox","\u6C99\u76D2\u53EA\u80FD\u4F7F\u7528\u81EA\u5DF1\u7684\u5DE5\u4F5C\u533A\u3002");let i=await Sn(t),r=typeof n=="string"?n:null;if(i.kind==="missing")return s(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u6587\u4EF6\u6216\u6587\u4EF6\u5939");if(i.kind==="plain")return s(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(i.kind==="nested")return s(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(i.kind==="name")return s(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 a=i.kind==="workspace"?i.root:i.kind==="folder"?null:i.root,o=!a||!Nn(c).some(y=>ft(y.root,a));if(!a){let y=i.kind==="folder"?i.folder:i.parent;if(vn(y))return s(409,"marker",z("{0} \u91CC\u7684 gallery.json \u662F\u522B\u7684\u7A0B\u5E8F\u7684\uFF0C\u4E0D\u80FD\u628A\u5B83\u767B\u8BB0\u6210\u5DE5\u4F5C\u533A",y));if(e!==!0)return[409,{ok:!1,reason:"unregistered",folder:y,...Ft(z("\u4F1A\u628A {0} \u767B\u8BB0\u6210\u4E00\u4E2A\u5DE5\u4F5C\u533A\uFF08\u5728\u91CC\u9762\u653E gallery.json \u548C .gallery/\uFF09",y))}];if(!(await Rn(y)).ours)return s(409,"marker",z("{0} \u91CC\u7684 gallery.json \u662F\u522B\u7684\u7A0B\u5E8F\u7684\uFF0C\u4E0D\u80FD\u628A\u5B83\u767B\u8BB0\u6210\u5DE5\u4F5C\u533A",y));a=y}let u=i.kind==="workspace"||i.kind==="folder";if(ft(a,c))return[200,{ok:!0,kind:u?"workspace":"draft",own:!0,existing:!0,...u?{column:jt}:{entry:i.slug}}];let l=await Ln(a,{force:!0}).catch(()=>"failed"),f=Z(Rt(a));return f.refused==="ambiguous"?s(409,"ambiguous",z("\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,Rt(a))):!f.root||!ft(f.root,a)?l==="temporary"?s(409,"temporary","\u8FD9\u4E2A\u5DE5\u4F5C\u533A\u5728\u7CFB\u7EDF\u7684\u4E34\u65F6\u6587\u4EF6\u5939\u91CC\uFF0C\u4E0D\u80FD\u6DFB\u52A0"):s(409,"registry","\u6CA1\u80FD\u628A\u5B83\u7684\u5DE5\u4F5C\u533A\u8BB0\u8FDB\u672C\u673A\u7684\u767B\u8BB0\u8868"):($t(a),u?[200,{ok:!0,kind:"workspace",...await jn(c,a,{changed:N,after:r})}]:[200,{ok:!0,kind:"draft",...await xn(c,a,i.slug,{changed:N,pick:!0,after:r,fresh:o})}])},async export({slug:t}){if(typeof t!="string"||!I.test(t)||!await rt(P(t)))return s(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let{problems:e=[],file:n,refused:i}=await p.export(t);return i?s(i.reason==="missing"?404:409,i.reason,i.message):e.length?s(422,"check",Vn(e)):[200,{ok:!0,path:Xn(n)}]}},Xt={async frameable({url:t},{port:e}){let n=typeof t=="string"?lt({url:t,title:"-"}):{refused:"url"};return n.refused?s(400,"url","\u8FD9\u4E0D\u662F\u4E00\u4E2A\u7F51\u5740"):Jt(n.value.url,e)?[200,{ok:!0,frameable:!1,reason:"own"}]:[200,{ok:!0,...await We(n.value.url)}]},async reveal({entry:t,ws:e,page:n,preference:i}){let r=St(),a=null;if(typeof i=="string")try{a=await cn(i)}catch{return s(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u6587\u4EF6\u5939")}else typeof n=="string"?a=I.test(n)?q(n,c).folder:null:typeof t=="string"&&X(t)?a=(await de(t,r)).folder:e===L?a=k.resolve(c):typeof e=="string"&&(a=Z(e,r).root??null);return!a||!await rt(a)?s(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u6587\u4EF6\u5939"):[200,{ok:!0,path:a,...await ne(a)}]},async presence(t){return et.report(t).ok?[200,{ok:!0}]:s(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9")},async title({url:t}){let e=typeof t=="string"?lt({url:t,title:"-"}):{refused:"url"};if(e.refused)return s(400,"url","\u8FD9\u4E0D\u662F\u4E00\u4E2A\u7F51\u5740");let n=G?await G.title(e.value.url).catch(()=>""):"",i=typeof n=="string"?n:n?.title,r=["auth","unknown"].includes(n?.reason)?n.reason:void 0;return[200,{ok:!0,title:typeof i=="string"?i.slice(0,200):"",...r?{reason:r}:{}}]}},Ye=new Set(["status"]);function Be(t,e,n){if(t.method==="GET"&&Object.hasOwn(Qt,n)){let r=t.headers.host??"",a=t.socket.localPort;return r!==`127.0.0.1:${a}`&&r!==`localhost:${a}`?_(e,403,{ok:!1,reason:"host"}):Ye.has(n)&&t.headers["x-gallery-token"]!==m.token?_(e,403,{ok:!1,reason:"token"}):Qt[n](new URL(t.url??"/","http://localhost").searchParams).then(([o,u])=>_(e,o,u),o=>_(e,...s(500,"read",o)))}if(t.method==="POST"&&n==="stop")return m.respond(async r=>{let a=await m.check(r);return a.error?a.error:h.kind!=="cli"||typeof h.stop!="function"?s(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",()=>h.stop()),[200,{ok:!0,pid:process.pid}])})(t,e);if(t.method==="POST"&&n==="pack-install")return m.respond(async r=>{let a=await m.check(r,Qn);if(a.error)return a.error;if(!b?.install)return s(404,"unknown");try{return[200,{ok:!0,...b.install(a.body??{})}]}catch(o){if(!o.code)throw o;return s(409,o.code,o)}})(t,e);if(t.method==="POST"&&n==="todo")return(async()=>{let r=await m.check(t);if(r.error)return r.error;let{slug:a,items:o}=r.body??{};return typeof a!="string"||!I.test(a)||!Array.isArray(o)?[400,{ok:!1,reason:"body"}]:!await C(a)||(await W(P(a)))?.instructions===!0?s(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"):m.setTodos(a,o)})().then(([r,a])=>_(e,r,a),r=>_(e,...s(500,"write",r.message)));let i={port:t.socket.localPort};return t.method==="POST"&&Object.hasOwn(ot,n)?m.respond(async r=>{let a=await m.check(r);if(a.error)return a.error;let o=a.body&&typeof a.body=="object"?a.body:{};return typeof o.workspace=="string"&&!ft(o.workspace,c)?s(409,"elsewhere","\u8FD9\u4E2A\u9884\u89C8\u670D\u52A1\u5668\u7BA1\u7684\u662F\u53E6\u4E00\u4E2A\u76EE\u5F55\u7684\u6587\u6863"):ot[n](o,i)})(t,e):t.method==="POST"&&Object.hasOwn(Xt,n)?(async()=>{let r=await m.check(t);return r.error?r.error:Xt[n](r.body&&typeof r.body=="object"?r.body:{},i)})().then(([r,a])=>_(e,r,a),r=>_(e,...s(500,"read",r))):_(e,404,{ok:!1,reason:"unknown"})}return{handle:Be,outline:A,trashEntries:at,place:ht,freeSlug:kt,index:V,run:(t,e,n={})=>Object.hasOwn(ot,t)?ot[t](e??{},{wait:!0,...n}):Promise.resolve(s(404,"unknown","\u6CA1\u6709\u8FD9\u4E2A\u547D\u4EE4"))}}export{ne as a,ie as b,zi as c};
|
|
@@ -0,0 +1,170 @@
|
|
|
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 w}from"./chunk-5TLLIZT7.mjs";import{a as se}from"./chunk-HFTBVEZK.mjs";import{i as D}from"./chunk-5IHDLEB4.mjs";import{e as F,f as W,g as H}from"./chunk-56SVJENP.mjs";import{a as U,b as q,d as K,e as b,f as I,g as V,h as Y,i as X,j as Q,o as Z,r as ee,s as te,t as oe}from"./chunk-BSJKFE7I.mjs";import{a as T,b as r,f as ne}from"./chunk-L4WLQYFC.mjs";import{f as S,j as J,s as L,t as R,v as j}from"./chunk-TKWEX4FD.mjs";import O from"node:fs";import x from"node:path";import{LISTED_BLOCKS as Ne,blocksHidden as je}from"../browser/editor/components/registry.mjs";import{inLanguage as M,told as Ee}from"../browser/shared/i18n/index.mjs";import{PACK_ID as Ae}from"../browser/shared/pack-manifest.mjs";import{readKeys as Ie,writeKey as le}from"../browser/shared/net-keys.mjs";import{HOST as Ce,netHostsOf as de}from"../browser/shared/net-policy.mjs";import{PACKAGE_ID as Ge,SLOT as Pe}from"../browser/shared/components/installed.mjs";import{DEVICE_NAMES as Je,layoutOf as G,PACKAGE_MANIFEST as he,shallowPackages as pe}from"../browser/shared/workspace.mjs";var $e=(e,t,{script:o,flow:a,data:n,page:s})=>`{
|
|
3
|
+
"id": "${e}",
|
|
4
|
+
"apiVersion": 1,
|
|
5
|
+
"version": "0.1.0",
|
|
6
|
+
"name": { "zh": "${t}", "en": "${t}" },
|
|
7
|
+
"description": { "zh": "\u4E00\u4E2A\u53EF\u4EE5\u53CD\u590D\u4F7F\u7528\u7684\u5757", "en": "A block to use again" },
|
|
8
|
+
"words": "${t}",${s?`
|
|
9
|
+
"places": ["page"],
|
|
10
|
+
"card": { "sizes": [[4, 3], [2, 3]], "resize": true },`:""}
|
|
11
|
+
"parts": {
|
|
12
|
+
"title": { "at": ":scope > h3", "edit": "${s?"none":"text"}" }${n?`,
|
|
13
|
+
"items": { "at": ":scope > script", "edit": "data" }`:a?`,
|
|
14
|
+
"body": { "edit": "flow" }`:`,
|
|
15
|
+
"text": { "at": ":scope > p", "edit": "${s?"none":"text"}", "optional": true }`}
|
|
16
|
+
},${o?`
|
|
17
|
+
"runtime": { "generated": [".component-drawn"] },`:""}
|
|
18
|
+
"markdown": "parts"
|
|
19
|
+
}
|
|
20
|
+
`,ae=(e,t,o,{blocks:a,json:n})=>`<div data-doc-component="${e}">
|
|
21
|
+
<h3>${t}</h3>
|
|
22
|
+
${n?` <script type="application/json">${n}</script>`:a?` <div data-doc-slot="body">
|
|
23
|
+
${a.map(s=>` ${s}
|
|
24
|
+
`).join("")} </div>`:` <p>${o}</p>`}
|
|
25
|
+
</div>
|
|
26
|
+
`,be=["<p>\u8FD9\u91CC\u5199\u8FD9\u4E2A\u5757\u5728\u4E00\u4EFD\u6587\u6863\u91CC\u7684\u6837\u5B50\u3002</p>","<ul>"," <li>\u63D2\u69FD\u91CC\u5199\u6587\u6863\u81EA\u5DF1\u7684\u5757</li>"," <li>\u6BB5\u843D\u3001\u5217\u8868\u3001\u8868\u683C\u90FD\u53EF\u4EE5</li>","</ul>"],ve=(e,{flow:t,data:o})=>`/* Every selector starts at the instance, so that nothing here reaches the rest of the page.${t?` Each step is
|
|
27
|
+
a >, so that none reaches into the slot, whose blocks read as the page's.`:""} */
|
|
28
|
+
[data-doc-component="${e}"] { padding: 12px 16px; border: 1px solid var(--doc-border); border-radius: 8px; }
|
|
29
|
+
[data-doc-component="${e}"] > h3 { margin-top: 0; }
|
|
30
|
+
${o?`/* The hidden attribute hides a control whatever display the rules below give it (the kit holds [hidden] over a
|
|
31
|
+
style): the field and the buttons are drawn hidden where nothing is written, an export. */
|
|
32
|
+
[data-doc-component="${e}"] .component-list { margin: 0 0 8px; padding: 0; list-style: none; }
|
|
33
|
+
[data-doc-component="${e}"] .component-list > li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 0; }
|
|
34
|
+
[data-doc-component="${e}"] .component-field { display: block; box-sizing: border-box; width: 100%; padding: 4px 8px; border: 1px solid var(--doc-border); border-radius: 6px; background: transparent; color: inherit; font: inherit; }
|
|
35
|
+
[data-doc-component="${e}"] .component-remove { padding: 0 8px; border: 1px solid var(--doc-border); border-radius: 6px; background: transparent; color: var(--doc-muted); font: inherit; cursor: pointer; }
|
|
36
|
+
`:""}`,xe=(e,t,{script:o,flow:a,data:n,page:s})=>`# ${t}
|
|
37
|
+
|
|
38
|
+
What this block is for, and when ${s?"a custom page":"a document"} uses it rather than a block of Gallery's own.
|
|
39
|
+
|
|
40
|
+
## How to write it
|
|
41
|
+
|
|
42
|
+
Write the element as example.html does: \`gallery block show ${e}\` prints it. Each part, and what goes in it:
|
|
43
|
+
|
|
44
|
+
- the title, its \`h3\`: required${s?", written in the file (a page shows it as written)":""}.
|
|
45
|
+
${n?'- the items, its `<script type="application/json">`: `{"items":[{"text":"\u2026"}]}`, each item a line a reader adds on the block and takes away with its button. Leave the items of a block that is there alone: they are the reader\'s.\n':a?'- the body, its `<div data-doc-slot="body">`: required, the document\'s own blocks, written as anywhere in the document (paragraphs, lists, tables, formulas).\n':"- the text, its `p`: optional.\n"}${s?`
|
|
46
|
+
## On a page
|
|
47
|
+
|
|
48
|
+
A card of a custom page: \`gallery page add <slug> ${e}\` puts one on it, at the first free spot by its size (4 \xD7 3, or 2 \xD7 3), which the user may change by dragging its edge.
|
|
49
|
+
`:""}
|
|
50
|
+
## How it looks
|
|
51
|
+
|
|
52
|
+
What a reader sees of it, and what it shows while it is empty.${n?" Where nothing is written (an export) its field and buttons are not shown.":""}
|
|
53
|
+
${o?`
|
|
54
|
+
## Its script
|
|
55
|
+
|
|
56
|
+
kit.js runs with the rights of a document's own script. What it draws, it draws in what the manifest's \`runtime\` names${a?", outside the slot: it reads the slot and never writes in it":""}.${n?" It reads the items with `context.readJSON` and writes them back with `context.editJSON`, one write for each add or removal (one undo step); `example()` adds an item, by the function the field calls, and works on an empty instance too.":""}
|
|
57
|
+
`:""}`,Se=e=>`// Starts each instance from what the file says, and draws in a node the manifest's runtime names:
|
|
58
|
+
// the kit takes that off an instance before it starts one again, as an undo may put one back.
|
|
59
|
+
DocKit.component({
|
|
60
|
+
id: "${e}",
|
|
61
|
+
on: ["source"],
|
|
62
|
+
mount(host, context) {
|
|
63
|
+
const drawn = document.createElement("div");
|
|
64
|
+
drawn.className = "component-drawn";
|
|
65
|
+
host.append(drawn);
|
|
66
|
+
const draw = () => { drawn.textContent = context.part("title")?.textContent ?? ""; };
|
|
67
|
+
draw();
|
|
68
|
+
return { update: draw };
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
`,Oe=e=>`// A list of lines a reader keeps in this block. Its data part, items, is a script of JSON:
|
|
72
|
+
// {"items":[{"text":"\u2026"}]}. The block draws what it holds on every \`source\` (an undo, an Agent's write,
|
|
73
|
+
// the page coming to edit) and writes only on a reader's gesture: a line typed in the field (DocKit.input:
|
|
74
|
+
// Enter or leaving the field, never while an input method composes) and a press of a line's button, each
|
|
75
|
+
// one context.editJSON, one undo step. A control that writes is drawn only while context.canEdit() and
|
|
76
|
+
// hidden otherwise, as an export needs (the hidden attribute: the kit holds it over any display).
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The items \`data\` holds (context.readJSON's, or the draft context.editJSON hands a change); throws
|
|
80
|
+
* saying why when it is no { "items": [] }, and the block draws nothing over it.
|
|
81
|
+
* @param {any} data
|
|
82
|
+
* @returns {{ text: string }[]}
|
|
83
|
+
*/
|
|
84
|
+
function itemsOf(data) {
|
|
85
|
+
if (data === null || typeof data !== "object" || !Array.isArray(data.items)) throw new Error('its data is no { "items": [] }');
|
|
86
|
+
return data.items;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* One item more, one write: what the field calls once the reader is done with it, and the example too.
|
|
91
|
+
* Whether it was taken.
|
|
92
|
+
* @param {DocComponentContext} context
|
|
93
|
+
* @param {string} text
|
|
94
|
+
*/
|
|
95
|
+
function addItem(context, text) {
|
|
96
|
+
return context.editJSON("items", (data) => {
|
|
97
|
+
itemsOf(data).push({ text });
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The item numbered \`index\` taken away, one write: what a line's button calls. Whether it was taken.
|
|
103
|
+
* @param {DocComponentContext} context
|
|
104
|
+
* @param {number} index
|
|
105
|
+
*/
|
|
106
|
+
function removeItem(context, index) {
|
|
107
|
+
return context.editJSON("items", (data) => {
|
|
108
|
+
itemsOf(data).splice(index, 1);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
DocKit.component({
|
|
113
|
+
id: "${e}",
|
|
114
|
+
on: ["source", "editable"],
|
|
115
|
+
mount(host, context) {
|
|
116
|
+
const drawn = document.createElement("div");
|
|
117
|
+
drawn.className = "component-drawn";
|
|
118
|
+
const list = document.createElement("ul");
|
|
119
|
+
list.className = "component-list";
|
|
120
|
+
const field = document.createElement("input");
|
|
121
|
+
field.className = "component-field";
|
|
122
|
+
field.type = "text";
|
|
123
|
+
field.placeholder = "\u5199\u4E00\u6761\uFF0C\u56DE\u8F66\u6DFB\u52A0";
|
|
124
|
+
drawn.append(list, field);
|
|
125
|
+
host.append(drawn);
|
|
126
|
+
const typed = DocKit.input(field, {
|
|
127
|
+
signal: context.signal,
|
|
128
|
+
commit(value) {
|
|
129
|
+
if (value.trim() && addItem(context, value.trim())) typed.set("");
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
context.listen(list, "click", (event) => {
|
|
133
|
+
const button = event.target instanceof Element ? event.target.closest("button") : null;
|
|
134
|
+
if (button && context.canEdit()) removeItem(context, Number(button.value));
|
|
135
|
+
});
|
|
136
|
+
const draw = () => {
|
|
137
|
+
const data = context.readJSON("items");
|
|
138
|
+
if (data === undefined) return; // no JSON: the instance has failed, and Gallery shows what it holds
|
|
139
|
+
let items;
|
|
140
|
+
try {
|
|
141
|
+
items = itemsOf(data);
|
|
142
|
+
} catch (error) {
|
|
143
|
+
return context.fail(error);
|
|
144
|
+
}
|
|
145
|
+
const writes = context.canEdit();
|
|
146
|
+
list.replaceChildren(...items.map((item, index) => {
|
|
147
|
+
const line = document.createElement("li");
|
|
148
|
+
const words = document.createElement("span");
|
|
149
|
+
words.textContent = item.text;
|
|
150
|
+
const remove = document.createElement("button");
|
|
151
|
+
remove.type = "button";
|
|
152
|
+
remove.className = "component-remove";
|
|
153
|
+
remove.value = String(index);
|
|
154
|
+
remove.textContent = "\u5220\u9664";
|
|
155
|
+
remove.hidden = !writes;
|
|
156
|
+
line.append(words, remove);
|
|
157
|
+
return line;
|
|
158
|
+
}));
|
|
159
|
+
field.hidden = !writes;
|
|
160
|
+
};
|
|
161
|
+
draw();
|
|
162
|
+
return { update: draw };
|
|
163
|
+
},
|
|
164
|
+
example(host, context) {
|
|
165
|
+
addItem(context, "\u53C8\u4E00\u6761");
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
`;function ie(e,{script:t=!1,flow:o=!1,data:a=!1,page:n=!1}={}){let s=e.split("/")[1],i={script:t||a,flow:o,data:a,page:n};return{"component.json":$e(e,s,i),"template.html":ae(e,"\u6807\u9898","\u5199\u5728\u8FD9\u91CC\u3002",{blocks:o&&["<p></p>"],json:a&&'{"items":[]}'}),"example.html":ae(e,"\u4E00\u4E2A\u4F8B\u5B50","\u8FD9\u91CC\u5199\u8FD9\u4E2A\u5757\u5728\u4E00\u4EFD\u6587\u6863\u91CC\u7684\u6837\u5B50\u3002",{blocks:o&&be,json:a&&'{"items":[{"text":"\u7B2C\u4E00\u6761"},{"text":"\u7B2C\u4E8C\u6761"}]}'}),"writing.md":xe(e,s,i),"style.css":ve(e,i),...i.script?{"kit.js":a?Oe(e):Se(e)}:{}}}var N="local";function me(e){let t=e.includes("/")?e:`${N}/${e}`;if(!Ge.test(t))throw new r(`Not a block's id: ${e} (<scope>/<name>, each in lowercase letters, digits and hyphens; a <name> alone is ${N}/<name>).`);let o=t.split("/").find(a=>Je.has(a));if(o)throw new r(`Not a block's id: ${e} (Windows keeps ${o} for a device).`);return t}function Ke(e,t){let o=me(t),a=t.includes("/")?null:b(t);if(!a)return o;let n=S(e);return n.packages.has(o)||n.problems.has(o)||O.existsSync(_(e,o))?o:a.id}var _=(e,t)=>x.join(G(e).components,...t.split("/")),k=e=>e.pack===U?e.name:e.id,B=()=>K().map(k).join(", "),fe=({name:e,file:t})=>`${w(t)} is one level too shallow, and no catalog reads it: a custom block is components/<scope>/<name>/, so move it to components/${N}/${e}/`;function Te(e,t){let o=pe(e).find(({name:s})=>s===t.split("/")[1]),a=I(t)&&b(t);if(a)return`No block ${t} in ${w(G(e).components)}: it is one of Gallery's own, which gallery block add ${k(a)} puts in.`;let n=t.startsWith(`${N}/`)?b(t.slice(N.length+1)):null;return o?fe(o):`No block ${t} in ${w(G(e).components)}: gallery block list says which there are${n?`; Gallery has a block of that name, ${n.id}`:""}.`}function De(e,t,{script:o,flow:a,data:n,page:s,recipe:i}){let l=t.split("/")[0],m=b(t);if(I(t))throw new r(`The scope ${l}/ is kept for Gallery's own blocks: give yours another (${N}/<name>, or a <name> alone)${m?`; gallery block add ${k(m)} puts Gallery's in, and gallery block new <id> --recipe ${k(m)} starts one of yours from it`:""}.`);if(V(e).packs?.[l])throw new r(`The scope ${l}/ is the pack ${l}'s, which gallery block pack install put in (installing it again would not keep a block of yours there): give yours another (${N}/<name>, or a <name> alone).`);let f=i===void 0?null:b(i);if(i!==void 0&&!f)throw new r(`No block of Gallery's own is called ${i}: ${B()||"none"}.`);let h=_(e,t);if(O.existsSync(h)||S(e).problems.has(t)){let d=!O.existsSync(x.join(h,he));console.error(d?`A folder is there with no component.json: ${w(h)}: move it, or give this block another name.`:`Block already exists: ${w(h)}: gallery block show ${t} says what it is; give a new one another name.`),process.exit(1)}let u=f?Z(f,t):ie(t,{script:o,flow:a,data:n,page:s});try{O.mkdirSync(h,{recursive:!0});for(let d of q(Object.keys(u)))O.mkdirSync(x.dirname(x.join(h,d)),{recursive:!0}),O.writeFileSync(x.join(h,d),u[d])}catch(d){if(!d.code)throw d;console.error(`Cannot write ${w(h)} (${d.code}).`),process.exit(1)}if(console.log(`Created ${w(h)}: ${Object.keys(u).join(", ")}`),f){console.log(`Made from Gallery's ${f.id} ${f.version}, every word that named it naming ${t}: change its name, words and description in component.json first (two blocks of one name read alike in "/"), and in the same files what is still ${f.name}'s: preview.svg (the picture the menu shows beside the description, still ${f.name}'s drawing: draw yours or delete it), writing.md (how to write it, still about ${f.name}) and example.html (the instance check runs and show prints, still ${f.name}'s words), then what you came for (references/building-blocks.md has every field and the rules), and run gallery block check ${t}, which passes as it stands now.`);return}let c=o||n;console.log(`\u4E0B\u4E00\u6B65\uFF1Asay in component.json what it is (its name, description and parts), write template.html, what ${s?"a custom page's \u6DFB\u52A0\u81EA\u5B9A\u4E49\u5757 puts on it":'"/" puts in a document'}, and example.html, an instance as a writer would fill it, then writing.md and style.css${c?" and kit.js":""} (references/building-blocks.md has every field and the rules${a?", and Slots what its slot body holds":""}${s?"; references/pages-and-data.md a card's size and settings and what it reads":""}${c?"; references/block-script.md its script and how it writes back":""}), and run gallery block check ${t}, which passes as it stands now.`),n&&console.log("It keeps a list of lines (the part items, a script of JSON on one line, as context.editJSON writes it): kit.js reads it with context.readJSON and writes it with context.editJSON, from a field (DocKit.input) and a button, hidden where nothing is written; example() adds a line by the function the field calls, and works on template.html's empty instance. Rename the part, the fields of its JSON and the controls for what the block keeps."),s?console.log(`It is a custom page's card (places ["page"], a card of two sizes): gallery page add <slug> ${t} puts one on a page, then gallery page try <slug> <card id> <gesture> tries a reader's gesture on it${n?' (--type .component-field "words" --then Enter)':""}; for a document too, put "document" in places.`):n&&console.log(`In a document: write the element as example.html does, then gallery block try <slug> --type .component-field "words" --then Enter tries the field (the part and the class are the scaffold's: rename them with the block).`)}function ze(e,t){let o=b(t);if(!o)throw new r(`No block of Gallery's own is called ${t}: ${B()||"none"} (gallery block list says each).`);let a;try{a=X(e,o)}catch(s){if(s.code!=="changed")throw s;console.error(`${w(s.folder)} was changed after gallery block add put it there (or another hand put it there), so it is not replaced: to keep those changes, make a block of your own from Gallery's with gallery block new <id> --recipe ${k(o)} and move them into it; to take Gallery's ${o.version}, delete the folder and run gallery block add ${k(o)} again.`),process.exit(1)}let n=o.places.includes("document")?`a document can write it now (gallery block show ${o.id} says how)`:"custom pages can place it now";a.did==="same"?console.log(`${o.id} ${o.version} is in already, as Gallery ships it: ${w(a.folder)}`):a.did==="updated"?console.log(`Updated ${o.id} from ${a.from??"an older version"} to ${o.version}: ${w(a.folder)}`):console.log(`Added ${o.id} ${o.version}: ${w(a.folder)}`),a.did!=="same"&&console.log(`It is Gallery's, as it ships: no check or try is needed, and ${n}. Change nothing in its folder, or gallery block add will not update it again: for a block like it of your own, gallery block new <id> --recipe ${k(o)}.`)}var y=({zh:e,en:t})=>e===t?e:`${e} / ${t}`;function Me(e){if(R(e))return null;let t=L(e);return t?J("en",t):"it has no template.html"}var _e={disabled:"disabled by the user: its instances show as they stand, no script and no style"},P=e=>e?.length?` \u8981\u7528\uFF1A${e.join(", ")}`:"";function re(e,{id:t,name:o,version:a,description:n,state:s,needs:i},l){console.log(`${t} ${y(o)}`);let f=(e.settings.packsOff??[]).includes(t.split("/")[0])?`available; its pack ${t.split("/")[0]} is switched off in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868, so no menu or library offers it, and a document can still write it`:l==="document"&&s==="hidden"?"available; not in the document's menus, by the user's switch, and a document can still write it":"available";console.log(` \u7248\u672C\uFF1A${a}\uFF08${f}\uFF09`),console.log(` \u8BF4\u660E\uFF1A${y(n)}`),P(i)&&console.log(P(i));let h=l==="document"&&Me(e.packages.get(t));h&&console.log(` \u6A21\u677F\uFF1Athe menus cannot insert it, and a document can still write it: ${h}`)}var we=e=>K().map(t=>({block:t,state:Y(e,t)})).filter(({block:t,state:o})=>!o.added||o.behind||o.changed&&Q(t.version,o.version));function Be(e){let t=S(e),o=j(t).map(s=>{let i=de(s.needs);return{id:s.id,pack:s.pack,name:s.name,description:s.description,version:s.version,state:s.state,reason:s.reason,places:s.places,needs:s.needs,template:s.template,menu:s.menu,unlisted:s.unlisted,disabled:s.disabled,net:{hosts:i,allowed:s.allowed,on:i.length>0&&i.every(l=>s.allowed.includes(l))}}}),a=we(e).map(({block:s,state:i})=>({id:s.id,add:k(s),title:s.title,version:s.version,places:s.places,added:i.added,workspaceVersion:i.version??null,changed:i.changed})),n=Ne.map(({id:s,name:i,hideable:l})=>({id:s,name:{zh:M("zh",i),en:M("en",i)},hidden:l&&t.settings.hidden.includes(s),hideable:l}));console.log(JSON.stringify({workspace:x.resolve(e),blocks:o,available:a,builtin:n},null,2))}function Fe(e,{json:t=!1}={}){if(t)return Be(e);let o=S(e),a=j(o),n=a.filter(({reason:c})=>c),s=a.filter(({reason:c})=>!c),i=s.filter(({state:c})=>c!=="disabled"),l=i.filter(({places:c})=>c.includes("document")),m=i.filter(({places:c})=>c.includes("page")),f=pe(e),h=we(e),u=je(o.settings.hidden);if(console.log(`\u5DE5\u4F5C\u533A\uFF1A${w(e)}`),s.length+n.length+f.length===0)console.log("No custom blocks yet. A document is written with Gallery's blocks and whole blocks; gallery block add <name> puts one of Gallery's own in (below), and gallery block new <id> starts one when the user wants a block to use again.");else{console.log(l.length?`\u6587\u6863\u91CC\u53EF\u7528 (in documents: ${l.length}; gallery block show <id> says how to write each):`:"\u6587\u6863\u91CC\u53EF\u7528 (in documents): none now.");for(let d of l)re(o,d,"document");console.log(m.length?`\u81EA\u5B9A\u4E49\u9875\u53EF\u7528 (on custom pages: ${m.length}):`:"\u81EA\u5B9A\u4E49\u9875\u53EF\u7528 (on custom pages): none now.");for(let d of m)d.places.includes("document")?console.log(`${d.id} ${y(d.name)} (above: in documents too)`):re(o,d,"page");let c=s.filter(({state:d})=>d==="disabled");c.length+n.length+f.length>0&&console.log("Not to use now:");for(let{id:d,name:p,version:$,state:A}of c)console.log(`${d} ${y(p)} ${$} ${_e[A]}`);for(let{id:d,reason:p,version:$}of n)console.log(`${d}${$?` ${$}`:""} does not load: ${p.en}`);for(let d of f)console.log(fe(d))}h.length&&console.log("Gallery's own blocks, to add as they are (no check or try needed):");for(let{block:c,state:d}of h){let p=c.places.map($=>$==="document"?"documents":"custom pages").join(" and ");console.log(`${c.id} ${y(c.title)} ${c.version} (${p})`),console.log(` \u8BF4\u660E\uFF1A${y(c.description)}`),d.changed?console.log(` the workspace's copy (${d.version??"no version"}) was changed after it was added, so it is not updated: to take Gallery's ${c.version}, delete ${w(_(e,c.id))} and run gallery block add ${k(c)} (to keep the changes, gallery block new <id> --recipe ${k(c)} and move them into it)`):console.log(d.added?` gallery block add ${k(c)} (the workspace has ${d.version??"an older one"}: this updates it)`:` gallery block add ${k(c)}`)}u.length&&console.log(`Built-in blocks the user took out of the document's menus (a document can still write them): ${u.join(", ")}`)}var We=(e,{at:t,edit:o,optional:a,min:n,max:s})=>{let i=[a?"optional":"",n!==void 0?`at least ${n}`:"",s!==void 0?`at most ${s}`:""].filter(Boolean),l=o==="flow"?`${Pe}="${e}"`:t;return` ${e} ${l} ${o==="flow"?"flow (blocks of the document: write any block in it)":o}${i.length?` (${i.join(", ")})`:""}`};function ge(e,t,o){console.log(`${t} ${y(e.name)}`),console.log(` \u7248\u672C\uFF1A${e.version}\uFF08${o}\uFF09`),console.log(` \u8BF4\u660E\uFF1A${y(e.description)}`),console.log(` \u7528\u5728\uFF1A${e.places.map(i=>i==="document"?"documents":"custom pages").join(", ")}`),P(e.needs)&&console.log(P(e.needs)),console.log(` ${w(e.folder)}`);let a=Object.entries(e.parts);console.log(a.length?"Parts (edit text: the user types there; flow: blocks of the document; none, or data: the component's):":"No parts.");for(let[i,l]of a)console.log(We(i,l));let n=D(e,"writing.md")?.trimEnd();console.log(n?`How to write it (writing.md):
|
|
169
|
+
${n}`:"How to write it: the block has no writing.md.");let s=D(e,"example.html")?.trimEnd();console.log(s?`The example (example.html):
|
|
170
|
+
${s}`:"The example: the block has no example.html.")}function He(e,t){let o=S(e),a=o.problems.get(t),n=o.packages.get(t)??(a?.off?a:void 0);if(!n){let l=a?.problem,m=!l&&I(t)?b(t):null;if(m)return Re(m);console.error(l?`${t} does not load: ${J("en",l)}`:Te(e,t)),process.exit(1)}let{state:s}=j(o).find(l=>l.id===t),i={normal:"available",hidden:"available; not in the document's menus, by the user's switch",disabled:"disabled by the user"}[s]??s;ge(n,t,i),console.log("In a document: write the element as the example does, straight in the page or a section, with no data-block-id, which the export gives it.")}async function Le(e,t,o,{remove:a}){let n=Ie(e);if(t===void 0){let s=[...new Set(j(S(e)).flatMap(({needs:m})=>de(m??[])))],i=Object.keys(n).sort();console.log(i.length?`Keys kept (.gallery/keys.json), by host: ${i.join(", ")}.`:"No key kept (.gallery/keys.json holds none).");let l=s.filter(m=>!i.includes(m)).sort();l.length&&console.log(`Hosts the workspace's blocks reach with no key: ${l.join(", ")} (a key is needed only where a block's address names {key}).`);return}if(!Ce.test(t))throw new r(`Not a host a block's needs can name: ${t} (a lowercase name, no scheme, port or path; *. before it for the names under it).`);if(a){if(o!==void 0)throw new r("gallery block key <host> --remove takes no key.");return t in n?(await le(e,t,null),console.log(`Took away the key for ${t}. A block's address that names {key} on it is refused (code "key") until one is kept again.`)):console.log(`No key kept for ${t}: nothing to take away.`)}if(o===void 0)return console.log(t in n?`A key is kept for ${t} (never printed): an address on it that names {key} is fetched with it.`:`No key kept for ${t}: gallery block key ${t} <key> keeps one.`);if(!o.trim()||/[\r\n]/.test(o))throw new r("A key is one line of characters, not empty.");await le(e,t,o),console.log(`Kept the key for ${t} in ${w(G(e).keys)}, which no page, export or cache holds: Gallery writes it where a block's address on ${t} names {key}, as it fetches for the block. Never write the key into a block's files or a page: they are shown and exported.`)}function Re(e){let t=JSON.parse(O.readFileSync(x.join(e.folder,he),"utf8"));ge({name:e.title,description:e.description,version:e.version,places:e.places,needs:t.needs,folder:e.folder,parts:t.parts??{}},e.id,"Gallery's own, not in this workspace yet");let o=e.places.includes("document")?", and a document writes it as the example above does, straight in the page or a section, with no data-block-id, which the export gives it":`, and gallery page add <slug> ${k(e)} puts a card of it on a custom page`;console.log(`Not in this workspace yet: gallery block add ${k(e)} puts it in as it ships (no check, no try)${o}.`)}var ue=e=>M("en",()=>Ee(e))??e.message,z=(e,t)=>t.length?[` ${e}: ${t.join(", ")}`]:[];function Ue(e,t){let o;try{o=ee(e,se(t))}catch(n){if(!n.code)throw n;console.error(`Not installed: ${ue(n)}`),process.exit(1)}let a=o.added.length+o.updated.length+o.same.length+o.kept.length;o.from===null?console.log(`Installed the pack ${o.id} ${o.version} (${y(o.name)}), ${a} block${a===1?"":"s"}: ${w(o.folder)}`):o.did==="updated"?console.log(`Updated the pack ${o.id} from ${o.from??"an older version"} to ${o.version}: ${w(o.folder)}`):console.log(`The pack ${o.id} ${o.version} is in already, as installed: ${w(o.folder)}`);for(let n of[...z("added",o.added),...o.did==="updated"?z("updated",o.updated):[],...z("taken out (not in this version)",o.removed)])console.log(n);o.kept.length&&console.log(` kept as they are, changed since they were installed: ${o.kept.join(", ")} (to take this version's, delete the block's folder and install the pack again)`),o.ownKept&&console.log(" its pack.json was changed since it was installed, and is kept as it is"),console.log(`Its blocks are offered in "/" and \u6DFB\u52A0\u81EA\u5B9A\u4E49\u5757 while its switch in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868 is on (gallery block pack list says each pack's); gallery block list says each block.`)}function C(e,{json:t=!1}={}){let o=oe(e);if(t)return void console.log(JSON.stringify({workspace:x.resolve(e),packs:o},null,2));console.log(`\u5DE5\u4F5C\u533A\uFF1A${w(e)}`);let a={default:"the default pack, where a block made with no pack named goes",official:"Gallery's own",installed:"a pack installed",own:"the workspace's own blocks, no pack.json"};for(let n of o){let s=[n.version?`${n.id} ${n.version}`:n.id,a[n.kind],n.enabled?"on":"off",`${n.blocks} block${n.blocks===1?"":"s"}`,...n.author?[`by ${n.author}`]:[]];console.log(`${y(n.name)} (${s.join(", ")})`),n.description&&console.log(` \u8BF4\u660E\uFF1A${y(n.description)}`),n.problem&&console.log(` its pack.json does not read: ${n.problem.en}`),n.changed.length&&console.log(` changed since it was installed: ${n.changed.join(", ")}${n.newer?` (Gallery's is ${n.newer}, not put over them)`:""}`)}o.every(({kind:n})=>n==="default")&&console.log("No other block packs: gallery block pack install <folder|zip> installs one.")}function qe(e,t){if(!Ae.test(t))throw new r(`Not a pack's id: ${t} (lowercase letters, digits and hyphens: gallery block pack list says each).`);let o;try{o=te(e,t)}catch(a){if(!a.code)throw a;console.error(`Not removed: ${ue(a)}`),process.exit(1)}console.log(`Removed the pack ${o.id}${o.version?` ${o.version}`:""} (${o.blocks.length} block${o.blocks.length===1?"":"s"}): what documents and pages hold of its blocks stays, shown as blocks that are not there.`)}var ce=e=>async(t,o)=>(await import("./chunk-7WNUOAFK.mjs")).packSwitch(t,e,o),E={install:Ue,list:C,remove:qe,on:ce(!0),off:ce(!1)};function Ve(e,t,o,{json:a=!1}={}){if(!t)throw new r("Say what to do with packs: install <folder|zip>, list, remove <pack>, on <pack>, off <pack>.");if(!Object.hasOwn(E,t))throw new r(`No such pack command: ${t} (install, list, remove, on, off).`);if(a&&E[t]!==C)throw new r(`--json goes with pack list, not pack ${t}.`);if(E[t]===C){if(o.length)throw new r("gallery block pack list takes nothing else.");return C(e,{json:a})}if(t==="on"||t==="off"){if(o.length>1)throw new r(`gallery block pack ${t} takes one pack's id: gallery block pack ${t} <pack>.`);return E[t](e,o[0])}if(o.length!==1)throw new r(t==="install"?"gallery block pack install takes one folder or zip: gallery block pack install <folder|zip>.":"gallery block pack remove takes one pack's id: gallery block pack remove <pack>.");return E[t](e,o[0])}var g={new:(e,t,o)=>De(e,t,o),add:ze,list:Fe,show:He,check:async(e,t,{documents:o,elsewhere:a})=>(await import("./chunk-NWWHDGKF.mjs")).checkCommand(e,t,{documents:o,elsewhere:a}),try:async(e,t)=>(await import("./chunk-WDS6HEPE.mjs")).tryCommand(e,t),key:Le,pack:Ve,menu:async(e,t,o)=>(await import("./chunk-7WNUOAFK.mjs")).menuSwitch(e,t,o),net:async(e,t,o)=>(await import("./chunk-7WNUOAFK.mjs")).netSwitch(e,t,o)},Ye=["--press","--drag","--to","--key","--type","--select","--then","--steps"],Xe={"--key":"--key takes a selector and a key: --key <selector> <key> (Enter, Space, ArrowRight, a letter, Shift+Tab).","--type":"--type takes a selector and the words to type: --type <selector> <words> (quoted when they hold a blank).","--select":"--select takes a selector and an option: --select <selector> <value> (the option's value or its words)."};function ke(e){let t=e.indexOf("--"),o=new Set,a={};for(let[n,s]of Object.entries(Xe)){let i=(t===-1?e:e.slice(0,t)).findIndex(f=>f===n||f.startsWith(`${n}=`));if(i===-1)continue;let l=i+(e[i].includes("=")?1:2),m=e[l];if(m===void 0||l===t||T(m)||o.has(l))throw new r(s);o.add(l),a[n]=m}return{argv:e.filter((n,s)=>!o.has(s)),seconds:a}}function kt(e){let{argv:t,seconds:o}=ke(e);return{argv:t,key:o["--key"]??null}}async function yt(e,{workspace:t,command:o,documents:a=t}){try{return await Qe(e,t,a)}catch(n){let s=e.find(i=>!T(i));throw n instanceof r&&s==="try"&&(n.synopsis=W),n instanceof r&&s==="pack"&&(n.synopsis=H),n instanceof r&&(s==="menu"||s==="net")&&(n.synopsis=F(o,s)),n}}async function Qe(e,t,o=t){let{argv:a,seconds:n}=ke(e),{positional:s,options:i,values:l}=ne({options:["--script","--flow","--data","--page","--keep","--documents","--replace","--remove","--json"],values:[...Ye,"--recipe"],argv:a}),m=l.get("--recipe"),f=new Map([...l].filter(([v])=>v!=="--recipe")),[h,u,...c]=s,d=Object.keys(g).join(", ");if(!h)throw new r(`Say what to do: ${d}.`);if(!Object.hasOwn(g,h))throw new r(`No such block command: ${h} (${d}).`);let p=g[h];for(let v of["--script","--flow","--data","--page"])if(i.has(v)&&p!==g.new)throw new r(`${v} goes with new, not ${h}.`);if(i.has("--documents")&&p!==g.check)throw new r(`--documents goes with check, not ${h}.`);if(i.has("--remove")&&p!==g.key)throw new r(`--remove goes with key, not ${h}.`);if(i.has("--json")&&p!==g.list&&p!==g.pack)throw new r(`--json goes with list and pack list, not ${h}.`);if(m!==void 0&&p!==g.new)throw new r(`--recipe goes with new, not ${h}.`);let $=["--script","--flow","--data","--page"].filter(v=>i.has(v));if(m!==void 0&&$.length)throw new r(`--recipe makes a block of what Gallery's ${m} holds: ${$[0]} goes with a new block of none.${$[0]==="--page"&&b(m)?.places.includes("page")?` ${m} already is a card for a custom page (its places hold page): leave --page out.`:""}`);if(i.has("--flow")&&i.has("--data"))throw new r("--flow and --data do not go together: --flow is a slot for blocks of the document's own, --data a list of lines a reader keeps in the block's JSON. Make the one you need with new, and add the other by hand.");if(i.has("--flow")&&i.has("--page"))throw new r("--flow and --page do not go together: a custom page renders no document's blocks, so a block for a page has no slot.");let A=[...f.keys(),...Object.keys(n).filter(v=>!f.has(v)),...i.has("--keep")?["--keep"]:[],...i.has("--replace")?["--replace"]:[]];if(p===g.try)return p(t,{named:s.slice(1),values:f,seconds:n,keep:i.has("--keep"),replace:i.has("--replace")});if(A.length)throw new r(`${A[0]} goes with try, not ${h}.`);if(p===g.list){if(u!==void 0)throw new r(`gallery block ${h} takes nothing else.`);return p(t,{json:i.has("--json")})}if(p===g.pack)return p(t,u,c,{json:i.has("--json")});if(p===g.menu||p===g.net){if(!["on","off"].includes(u)||c.length!==1)throw new r(`gallery block ${h} takes on or off and one block: gallery block ${h} on|off <block>.`);return p(t,u==="on",c[0])}if(p===g.key){if(c.length>1)throw new r("gallery block key takes a host and its key: gallery block key <host> <key>.");return p(t,u,c[0],{remove:i.has("--remove")})}if(p===g.add){if(u===void 0||c.length>0)throw new r(`gallery block add takes one name of Gallery's own blocks: ${B()}.`);return p(t,u)}if(u===void 0||c.length>0)throw new r(`gallery block ${h} takes one id.`);let ye=p===g.show||p===g.check?Ke(t,u):me(u);return p(t,ye,{script:i.has("--script"),flow:i.has("--flow"),data:i.has("--data"),page:i.has("--page"),documents:i.has("--documents"),elsewhere:o,recipe:m})}export{me as a,Ke as b,_ as c,k as d,fe as e,Te as f,y as g,Ye as h,ke as i,kt as j,yt as k};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
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,h,i,j,k,l}from"./chunk-
|
|
2
|
+
import{a,b,c,d,e,f,g,h,i,j,k,l}from"./chunk-TQZU7D7C.mjs";import"./chunk-5IHDLEB4.mjs";import"./chunk-B2EIMERT.mjs";import"./chunk-6ILJWFYW.mjs";import"./chunk-VRPVVMRB.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-W5NPH5UA.mjs";import"./chunk-ECZBLQKK.mjs";import"./chunk-E7656LR7.mjs";import"./chunk-TKWEX4FD.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";export{e as BASELINE_FROM,h as adoptIdless,g as baselineOf,b as blocksOf,k as exportBaselines,j as exportedText,i as hasBaseline,d as packageStamps,c as pageOf,l as previewBaseline,a as rankOf,f as readBaseline};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
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{E as re,J as ae,K as ne,O as ie,P as ce,a as C,b as Q,c as F,g as X,h as Z,n as D,o as ee,r as te,s as se,t as oe}from"./chunk-
|
|
2
|
+
import{E as re,J as ae,K as ne,O as ie,P as ce,a as C,b as Q,c as F,g as X,h as Z,n as D,o as ee,r as te,s as se,t as oe}from"./chunk-WHGANNEY.mjs";import{j as K}from"./chunk-S6YEC4GE.mjs";import{d as le}from"./chunk-NW6LAU22.mjs";import{a as L}from"./chunk-5TLLIZT7.mjs";import{r as q}from"./chunk-OM24O4KR.mjs";import{b as M,d as z,i as J}from"./chunk-LHGKPMTI.mjs";import{b as x,c as T}from"./chunk-PBMOC7KA.mjs";import{b as E}from"./chunk-L4WLQYFC.mjs";import{f as H,j as Y}from"./chunk-TKWEX4FD.mjs";import{b as V,e as pe}from"./chunk-A55HN5OK.mjs";pe();import N from"node:fs/promises";import P from"node:path";import{isInstance as ge}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as me}from"../browser/shared/components/installed.mjs";import{attr as we,walk as $e}from"../browser/shared/html-tree.mjs";import{pageExists as ye,pageFiles as be}from"../browser/shared/pages.mjs";import{layoutOf as Ee}from"../browser/shared/workspace.mjs";var xe="card ids aside",ke="nothing else in page.html changed (card ids aside)",Se=e=>new Promise(s=>setTimeout(s,e)),Te=/^\/__gallery\/pages\/[a-z0-9-]+\/cards$/,de=e=>{let s=null;return $e(V(e,{sourceCodeLocationInfo:!0}),n=>{s??=ge(n)?n:null},{inTemplates:!1}),s},fe=(e,s)=>{let n=s.node.sourceCodeLocation.startTag.endOffset;return{frame:e.slice(s.start,n).replace(/\s+data-[xywh]="[^"]*"/g,""),rest:e.slice(n,s.end)}};function Ce(e,s,n,a){let[o,d]=[x(e).cards,x(s).cards],c=[],t=r=>`card ${r.id}${r.block?` (${r.block})`:""}`,l=r=>["x","y","w","h"].map(i=>`${i} ${we(r.node,`data-${i}`)??"-"}`).join(", ");for(let r of o){let i=d.find(g=>g.id===r.id);if(!i){c.push(`${t(r)} taken out`);continue}let m=r.board!==i.board;(m||l(r)!==l(i))&&c.push(`${t(r)}'s place, ${l(r)}${m?` on ${r.board}`:""} then ${l(i)}${m?` on ${i.board}`:""}`);let[h,p]=[fe(e,r),fe(s,i)];if(h.frame===p.frame&&h.rest===p.rest)continue;if(r.id!==n){c.push(t(r));continue}h.frame!==p.frame&&c.push(`${t(r)}'s own frame (an attribute of its <section> but its place)`);let[f,$]=[D(h.rest,de,a),D(p.rest,de,a)];!f||!$?c.push(`${t(r)}'s instance`):f.outside!==$.outside&&c.push(`${t(r)} itself, outside its data parts (a part edited as text or none, or what its instance holds besides its parts)`)}for(let r of d)o.some(i=>i.id===r.id)||c.push(`a ${t(r)} put in`);let w=(r,i)=>{let m="",h=0;for(let p of[...i].sort((f,$)=>f.start-$.start))m+=r.slice(h,p.start),h=p.end;return(m+r.slice(h)).replace(/\s+/g," ")};return(w(e,o)!==w(s,d)||!c.length)&&c.push("the page's own HTML outside its cards (its head, its style, its header)"),c.join("; ")}function Ie(e,s,{card:n,found:a}){let[o,d]=[T(e).text,T(s).text],t=ee(o,d,l=>x(l).cards.find(w=>w.id===n)?.instance??null,a);return t.outside&&(t.outside={...t.outside,what:Ce(o,d,n,a)}),t}async function Oe(e){try{return await e.waitForSelector("[data-doc-ready]",{timeout:C}).catch(s=>{if(s.name==="TimeoutError")throw s;return e.waitForSelector("[data-doc-ready]",{timeout:C})}),await e.waitForFunction(()=>globalThis.__galleryTryEditable===!0&&!!document.querySelector("script[data-ge-page]"),{timeout:C}),!0}catch(s){if(s.name!=="TimeoutError")throw s;return!1}}function ve(e){return e?.startsWith("stopped")?`the page service refused the board's write (${e.slice(7).trim()||"no reason given"}), and the page showed itself again as the file holds it`:{refused:"the page service refused the board's write: the card was changed or taken out meanwhile (someone else's write of page.html), and the page showed itself again as the file holds it",offline:"the page could not reach the server (offline)",reloading:"the page loaded itself again (page.html or a custom block it holds changed meanwhile, or the page service refused a write)",syncing:`its write took more than ${F/1e3}s to be answered`}[e]}function Ae(e){let s=[],n=new Map;return e.on("request",a=>{if(a.method()!=="POST"||!Te.test(new URL(a.url()).pathname))return;let o={done:!1,status:null,answer:null,failed:null};s.push(o),n.set(a,o)}),e.on("response",a=>{let o=n.get(a.request());o&&(o.status=a.status(),o.done=!0,o.status!==200&&a.json().then(d=>{o.answer=d},()=>{}))}),e.on("requestfailed",a=>{let o=n.get(a);o&&(o.failed=a.failure()?.errorText??"failed",o.done=!0)}),{mark:async()=>s.length,async until(a){let o=Date.now();for(let d=0;;await Se(100)){let c=s.slice(a);if(c.length===0){if(Date.now()-o>Q)return"unchanged";continue}if(c.some(l=>!l.done)){if(d=0,Date.now()-o>F)return"syncing";continue}if(++d<4)continue;if(c.some(l=>l.failed))return"offline";let t=c.find(l=>l.status!==200);return t?t.answer?.refused||t.status===409&&!t.answer?"refused":`stopped ${t.answer?.reason??`HTTP ${t.status}`}`:"saved"}}}}function Re({card:e,found:s}){let n={...s,parts:Object.fromEntries(Object.entries(s.parts).filter(([,a])=>a.edit==="data"))};return{where:{card:e},ready:Oe,saves:Ae,changes:(a,o)=>Ie(a,o,{card:e,found:n}),plain:()=>!1,stayed:ve,outside:"problem",outsideSaid:a=>`card ${e}'s data parts: ${a.what}, where a reader's gesture on the card is to change its data parts alone`,aside:xe,inside:ke,framed:a=>a.closest(".gallery-card")??a}}var Le=e=>` ${e.id} ${e.block??"(no instance)"} x ${e.x}, y ${e.y}, w ${e.w}, h ${e.h}${e.board?` on board ${e.board}`:""}`;async function Ke(e,{named:s,values:n,seconds:a={},keep:o,replace:d=!1}){if(s.length===0)throw new E("Name the page and the card: gallery page try <slug> <card id> and the gesture.");if(s.length===1)throw new E(`Name the card of ${s[0]} to try: gallery page try ${s[0]} <card id> and the gesture (its data-card-id; gallery page check ${s[0]} lists the cards).`);if(s.length>2)throw new E("gallery page try takes a page's slug and a card's id.");let c=await X(n,a,d),[t,l]=s,w=n.has("--steps")?P.resolve(n.get("--steps")):null,r=c?[c]:await Z(w),i=be(t,e);ye(t,e)||(console.error(await le(t,e)),process.exit(1));let m=await N.readFile(i.html,"utf8"),{cards:h}=x(T(m).text),p=h.find(u=>u.id===l);if(!p)throw new E(h.length?`${t} has no card ${l}: its cards are
|
|
3
3
|
${h.map(Le).join(`
|
|
4
|
-
`)}`:`${t} has no card yet: gallery page add ${t} <block> puts one on it.`);let f=P.basename(i.html),$=p.node.sourceCodeLocation?.startLine??null;p.instance||(console.error(`Card ${l} of ${t} (${f}:${$}) holds no instance of a custom block (an element with ${me}): there is nothing on it to try.`),process.exit(1));let g=p.block,_=H(e),k=_.packages.get(g);if(!k){let u=_.problems.get(g);console.error(u?.off?`${g} is turned off in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868: its card says so on the page and runs nothing.`:u?`${g} does not load (${Y("en",u.problem)}), so its card runs nothing: gallery block check ${g} says why.`:`No custom block ${g} in this workspace, so its card runs nothing: gallery block list says which there are${g.startsWith("gallery/")?`, and gallery block add ${g.slice(8)} puts one of Gallery's own in`:""}.`),process.exit(1)}k.places.includes("page")||(console.error(`${g} is a block of documents (its manifest's places has no "page"): on a custom page its card says so and runs nothing, so there is nothing to try there (gallery block try tries it in a document).`),process.exit(1)),console.log(`${g} in card ${l} of ${t}, at ${f}:${$}: ${L(i.html)}`),w&&console.log(`Steps: ${r.length} from ${L(w)}, made one after another in one page`);let S=await q({command:`gallery page try ${t}`});if(!S.ok){console.log(`UNVERIFIED ${t}: ${S.message}`),process.exitCode=3;return}let{pageAloneOf:j}=await import("./chunk-
|
|
4
|
+
`)}`:`${t} has no card yet: gallery page add ${t} <block> puts one on it.`);let f=P.basename(i.html),$=p.node.sourceCodeLocation?.startLine??null;p.instance||(console.error(`Card ${l} of ${t} (${f}:${$}) holds no instance of a custom block (an element with ${me}): there is nothing on it to try.`),process.exit(1));let g=p.block,_=H(e),k=_.packages.get(g);if(!k){let u=_.problems.get(g);console.error(u?.off?`${g} is turned off in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868: its card says so on the page and runs nothing.`:u?`${g} does not load (${Y("en",u.problem)}), so its card runs nothing: gallery block check ${g} says why.`:`No custom block ${g} in this workspace, so its card runs nothing: gallery block list says which there are${g.startsWith("gallery/")?`, and gallery block add ${g.slice(8)} puts one of Gallery's own in`:""}.`),process.exit(1)}k.places.includes("page")||(console.error(`${g} is a block of documents (its manifest's places has no "page"): on a custom page its card says so and runs nothing, so there is nothing to try there (gallery block try tries it in a document).`),process.exit(1)),console.log(`${g} in card ${l} of ${t}, at ${f}:${$}: ${L(i.html)}`),w&&console.log(`Steps: ${r.length} from ${L(w)}, made one after another in one page`);let S=await q({command:`gallery page try ${t}`});if(!S.ok){console.log(`UNVERIFIED ${t}: ${S.message}`),process.exitCode=3;return}let{pageAloneOf:j}=await import("./chunk-K7Y7SPTS.mjs");await oe(e);let B=[],G=async u=>{let b=await te(e,{directory:i.folder,files:i,text:u});return B.push(b.slug),b},I=Re({card:l,found:k});try{let u=o?{slug:t,file:i.html}:await G(m),b=j(S.port,u.slug);console.log(o?`Page: ${b} (the custom page alone, editable: the Agent's own; --keep: what ${re(r)} write stays in ${f}, and every page open on it shows it, the user's too; the server runs on after this command)`:`Page: ${b} (a scratch copy of ${t}, its page alone, editable, made for this trial and gone at its end: ${f} is not written, and no page of the user's shows the trial; the server runs on after this command)`);let O=M();if(!O){console.log(`UNVERIFIED ${t}: no Chrome, Edge or Chromium found (GALLERY_BROWSER=<its executable> picks one), so nothing was tried`),process.exitCode=3;return}let v;try{v=await J({executablePath:O,args:z()})}catch(R){console.log(`UNVERIFIED ${t}: the browser ${O} did not start, twice, each time with a fresh profile (${K(R)}; GALLERY_BROWSER=<its executable> picks another), so nothing was tried`),process.exitCode=3;return}let A=P.join(Ee(e).qa,t,"try");try{await N.rm(A,{recursive:!0,force:!0}),await N.mkdir(A,{recursive:!0});let R=async y=>{if(o)return{address:b,file:u.file};let W=await G(y);return{address:j(S.port,W.slug),file:W.file}},U;try{U=await ae(v.browser,{root:e,address:b,fresh:R,steps:r,keep:o,file:u.file,name:f,line:$,found:k,out:A,host:I})}catch(y){if(y instanceof E&&y.made&&console.log(ce({name:f,steps:r,keep:o,host:I},y.made).join(`
|
|
5
5
|
`)),y.stuck)return ne(t,y,f,o);throw y}let{lines:ue,code:he}=ie({slug:t,name:f,steps:r,keep:o,host:I},U);console.log(ue.join(`
|
|
6
6
|
`)),process.exitCode=he}finally{await v.close()}}finally{for(let u of B)await se(e,u)}}export{xe as a,ke as b,de as c,Ce as d,Ie as e,Ae as f,Re as g,Ke as h};
|
|
@@ -0,0 +1,2 @@
|
|
|
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"./chunk-5L7RYZCL.mjs";import r from"node:fs/promises";import t from"node:path";async function p(n,i){let{build:a}=await import("./chunk-MCEXN4G5.mjs"),{default:o}=await import("./chunk-B45IAAU6.mjs");await a({configFile:!1,root:n,base:"/",publicDir:!1,logLevel:"warn",plugins:[o()],build:{outDir:i,emptyOutDir:!0,rollupOptions:{input:t.join(n,"src","workbench","app","index.html")}}}),await r.rename(t.join(i,"src","workbench","app","index.html"),t.join(i,"index.html"))}export{p as buildWorkbench};
|
|
@@ -0,0 +1,2 @@
|
|
|
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 L,b as M,c as C,d as oe,e as U,f as F,g as J,h as G}from"./chunk-B6RAGF4R.mjs";import{a as B,b as A}from"./chunk-5TLLIZT7.mjs";import{a as se,p as le}from"./chunk-OM24O4KR.mjs";import{b as D,f as te,h as ne}from"./chunk-L4WLQYFC.mjs";import E from"node:fs/promises";import Q from"node:path";import{iconKind as he}from"../browser/shared/emoji/icon-value.mjs";import{ownLookOf as pe}from"../browser/shared/document-look.mjs";import{readFavorites as ie}from"../browser/shared/favorites.mjs";import{descendantsIn as H,parentIn as P}from"../browser/shared/outline.mjs";import{isTop as V,topOf as W}from"../browser/shared/outline-shape.mjs";import{fullAddress as we,namedPlace as ce}from"../browser/shared/page-address.mjs";import{reportsDirectory as x}from"../browser/shared/paths.mjs";import{documentLinks as T,listReportSlugs as $e,roleOf as ye}from"../browser/shared/reports.mjs";import{documentDirectory as ae,documentFiles as de,isSlugName as ke}from"../browser/shared/workspace.mjs";import{isWorkspace as Y,readRegistry as fe,workspaceId as ve,workspaceKey as R}from"../browser/shared/workspace-registry.mjs";import{findPreviewServer as ue}from"../browser/shared/preview-server.mjs";import{workspaceBase as Se}from"../browser/shared/service-location.mjs";import{findIn as Ne,rankReports as K,reportLines as Oe}from"../browser/shared/search.mjs";async function X(t=x){let n=(await $e(t)).filter(ke);return(await Promise.all(n.map(async l=>{let a=ae(l,t),{html:u,json:r}=de(a),d=await E.stat(u).catch(()=>null);if(!d?.isFile()||await ye(a)==="instructions")return null;let c=await E.readFile(r,"utf8").then(JSON.parse).catch(()=>({})),o=s=>typeof s=="string"?s.replace(/\s+/g," ").trim():"";return{slug:l,title:o(c.title)||l,description:o(c.description),edited:d.mtimeMs,file:u}}))).filter(Boolean)}var Z=t=>{let n=new Date(t),i=l=>String(l).padStart(2,"0");return`${n.getFullYear()}-${i(n.getMonth()+1)}-${i(n.getDate())} ${i(n.getHours())}:${i(n.getMinutes())}`},j=t=>`${t} document${t===1?"":"s"}`;async function ge(t,n,i){let l=[...new Set(i.toLowerCase().split(/\s+/).filter(Boolean))],a=new Set(n.map(({slug:r})=>r));return(await Promise.all(t.filter(({slug:r})=>!a.has(r)).map(async r=>{let d=Oe(await E.readFile(r.file,"utf8").catch(()=>"")),c=l.map(o=>Ne(d,o,{most:1})).filter(({count:o})=>o>0);return c.length?{...r,words:c.length,count:c.reduce((o,{count:s})=>o+s,0),hit:c[0].hits[0].text}:null}))).filter(Boolean).sort((r,d)=>d.words-r.words||d.count-r.count||d.edited-r.edited)}async function be(t){let n=await ue({answering:!0,timeout:2e3});return n?`${se}${await le(n.port,{slug:t})}`:`\u63D0\u793A\uFF1AGallery \u6CA1\u5728\u8FD0\u884C\uFF0C\u6240\u4EE5\u8FD8\u6CA1\u6709\u5B8C\u6574\u7684\u5730\u5740\u53EF\u4EE5\u4EA4\u7ED9\u7528\u6237\uFF1Agallery open ${t} --no-browser \u542F\u52A8\u5B83\uFF0C\u5E76\u6253\u51FA \u4EA4\u7ED9\u7528\u6237 \u90A3\u4E00\u884C\u3002`}var _=t=>[...t.documents.values()].filter(n=>typeof n.url=="string"),q=t=>`${t} web link${t===1?"":"s"}`;async function je(t,n){if(t.length>1)throw new D("--tree takes one document at most (its slug, link or address).");let i=await L(),l=new Map(n.map(e=>[e.slug,e])),a=new Map((i.extensions??[]).map(e=>[e.id,e])),u=i.columns.filter(e=>(!e.extension||a.has(e.extension))&&!e.hidden&&!e.away),r=u.length>1?u:null,d=i.children[""]??[],c=null;if(t.length===1){let e=await G(t[0],"--tree",i);if(e.refused){for(let m of await A({reading:!0}))console.log(m);console.error(e.refused),process.exit(1)}c=e.slug,d=[c]}for(let e of await A({reading:!0}))console.log(e);let o=e=>console.log(`${e.title}\u680F\uFF08\u6269\u5C55 ${e.id}\uFF1A${e.error?`\u6761\u76EE\u8BFB\u4E0D\u51FA\u6765\uFF1A${e.error.message}`:`${e.count} \u4E2A\u6761\u76EE`}\uFF1Bgallery extension check ${e.id} \u6253\u51FA\u5B83\u4EEC\uFF09`),s=()=>{for(let e of a.values())o(e)},h=u.filter(e=>!e.extension).flatMap(e=>H(i.children,W(e.id))),w=h.filter(e=>i.documents.get(e)?.url!==void 0).length,$=h.length-w;if($+w===0){console.log('No documents yet: gallery new <slug> "<title>" makes one.'),c===null&&s();return}let y=w?`${j($)} and ${q(w)}`:j($);if(c===null)console.log(`${y}, as the sidebar shows them (one under another indented)${r?", column by column":""}:`);else{let e=H(i.children,c),m=e.some(p=>i.documents.get(p)?.url!==void 0)?`${e.length} ${e.length===1?"entry":"entries"}`:j(e.length);console.log(J(i,c)),console.log(e.length?`${U(i,c)} and the ${m} under it, as the sidebar shows them:`:`${U(i,c)}, with no document under it:`)}let g=(e,m)=>{let{title:p,description:v,icon:N,url:b,draft:f}=i.documents.get(e),S=l.get(e)?.edited,k=oe(i,e),O=b!==void 0?[`\u7F51\u9875\u94FE\u63A5\uFF1A${b}`]:f?[f.missing?"\u522B\u5904\u7684\u5E95\u7A3F\uFF0C\u627E\u4E0D\u5230\u4E86":k?`\u300C${k}\u300D\u7684\u5E95\u7A3F\uFF1A${f.path}`:`\u522B\u5904\u7684\u5E95\u7A3F\uFF1A${f.path}`]:[...k?[`\u300C${k}\u300D\u7684\u6587\u6863`]:[],...v?[`\u8BF4\u660E\uFF1A${v}`]:[],...S?[`\u4E0A\u6B21\u7F16\u8F91\uFF1A${Z(S)}`]:[]];console.log(`${" ".repeat(m)}${e} ${he(N)==="emoji"?`${N} `:""}${p}${O.length?` \uFF08${O.join("\uFF1B")}\uFF09`:""}`);for(let I of i.children[e]??[])g(I,m+1)};if(c!==null||!r){for(let e of d)g(e,0);c===null&&s();return}for(let e of r){if(e.extension){o(a.get(e.extension)),a.delete(e.extension);continue}let m=i.children[W(e.id)]??[];console.log(`${M(e)}\u680F${m.length?"":"\uFF08\u7A7A\uFF09"}`);for(let p of m)g(p,1)}s()}var ee=(t,n,i,l="")=>{let a=we(l,{slug:n},i);return Se(t)?a.replace("/#",`/#~${ve(t)}/`):a},me=async()=>{let t=await ue({answering:!0,timeout:2e3}).catch(()=>null);return t?`http://127.0.0.1:${t.port}`:""};async function xe(t){let n=Q.resolve(x),i=(s,h)=>R(s)===R(h),l=[n,...fe().workspaces.map(({root:s})=>s).filter(s=>!i(s,n))],a=l.filter(Y),u=l.filter(s=>!Y(s)),r=(await Promise.all(a.map(async s=>(await X(s)).map(h=>({...h,root:s}))))).flat(),d=t.join(" ").trim(),c=K(r,d),o=`${a.length} workspace${a.length===1?"":"s"}`;if(console.log(`Searched ${o} of this machine (gallery workspaces lists them; the current one: ${n}).`),r.length===0)console.log(`No documents in ${a.length===1?"it":"any of them"} yet.`);else if(c.length===0)console.log(`No document's title, description or slug in the ${o} holds ${d.split(/\s+/).map(s=>`"${s}"`).join(" or ")}: gallery list --all lists all ${r.length}.`);else{console.log(d?`${c.length} of ${j(r.length)}, the best match first:`:`${j(r.length)}, the one edited last first:`);let s=new Map,h=await me(),w=$=>(s.has($)||s.set($,Promise.all([T($),L($)]).then(([{links:y},g])=>({links:y,tree:g}))),s.get($));for(let{root:$,slug:y,title:g,description:e,edited:m,file:p}of c){let{links:v,tree:N}=await w($);console.log(`\u5DE5\u4F5C\u533A\uFF1A${$}`),console.log(`${y} ${g}`),e&&console.log(` \u8BF4\u660E\uFF1A${e}`),P(N.children,y)&&console.log(` ${J(N,y)}`),console.log(` \u5730\u5740\uFF1A${ee($,y,v,h)}`),console.log(` \u4E0A\u6B21\u7F16\u8F91\uFF1A${Z(m)}`),console.log(` ${B(p)}`)}console.log('\u63D0\u793A\uFF1Aone in another workspace is worked on there: pass its \u5DE5\u4F5C\u533A as --workspace to every command (gallery open <slug> --workspace "<\u5DE5\u4F5C\u533A>" gives its address).')}u.length&&console.log(`\u63D0\u793A\uFF1Anot searched, no longer there (gallery workspaces --forget <path> forgets one, nothing on disk changed): ${u.join(", ")}`)}async function z({slug:t,title:n,description:i,edited:l,file:a},{tree:u,links:r,favorites:d,root:c=x}){let o=await E.readFile(de(ae(t,c)).json,"utf8").then(JSON.parse).catch(()=>({})),s=P(u.children,t),h=s===null?null:C(u,F(u,t));return{slug:t,title:n,icon:u.documents.get(t)?.icon??null,description:i,link:r.get(t)??null,address:ee(c,t,r),path:B(a),parent:s===null||V(s)?null:s,column:h?M(h):null,columnId:h?.id??null,favorite:d.includes(t),look:pe(o?.look),edited:new Date(l).toISOString()}}function re(t,{tree:n,favorites:i}){let{title:l,url:a,icon:u}=n.documents.get(t),r=P(n.children,t),d=r===null?null:C(n,F(n,t));return{slug:t,title:l,url:a,icon:u??null,parent:r===null||V(r)?null:r,column:d?M(d):null,columnId:d?.id??null,favorite:i.includes(t)}}async function Le(t,n,{tree:i}){let l=await L(),{links:a}=await T(),u=await ie(x),r={tree:l,links:a,favorites:u},d=new Map(n.map(e=>[e.slug,e])),c={workspace:Q.resolve(x)};if(i){if(t.length>1)throw new D("--tree takes one document at most (its slug, link or address).");let e=null;if(t.length===1){let f=await G(t[0],"--tree",l);f.refused&&(console.error(f.refused),process.exit(1)),e=new Set([f.slug,...H(l.children,f.slug)])}let m=[],p=[],v=[],N=(f,S)=>{let k=l.documents.get(f);if(e===null||e.has(f))if(k.url!==void 0)p.push({...re(f,r),depth:S});else if(k.draft){let O=P(l.children,f),I=O===null?null:C(l,F(l,f));v.push({entry:f,title:k.title,description:k.description,icon:k.icon??null,workspace:k.draft.ws,path:k.draft.path??null,missing:k.draft.missing??null,parent:O===null||V(O)?null:O,column:I?M(I):null,columnId:I?.id??null,favorite:u.includes(f),depth:S})}else m.push({document:d.get(f),depth:S});for(let O of l.children[f]??[])N(O,S+1)},b=l.columns.filter(f=>!f.extension&&!f.hidden&&!f.away);for(let f of b)for(let S of l.children[W(f.id)]??[])N(S,0);return c.documents=await Promise.all(m.filter(({document:f})=>f).map(async({document:f,depth:S})=>({...await z(f,r),depth:S}))),c.links=p,c.drafts=v,void console.log(JSON.stringify(c,null,2))}let o=t.join(" ").trim(),s=t.length===1?ce(t[0],a):null,h=s&&s.slug!==t[0],w=h?n.filter(({slug:e})=>e===s.slug):K(n,o),$=[...w,...o&&!h?await ge(n,w,o):[]],y=o.toLowerCase().split(/\s+/).filter(Boolean),g=h?[]:_(l).filter(({slug:e,title:m,url:p})=>!y.length||y.some(v=>`${m} ${p} ${e}`.toLowerCase().includes(v))).map(({slug:e})=>e);c.documents=await Promise.all($.map(async e=>({...await z(e,r),...e.hit?{hit:e.hit}:{}}))),c.links=g.map(e=>re(e,r)),console.log(JSON.stringify(c,null,2))}async function Pe(t){let n=Q.resolve(x),i=(o,s)=>R(o)===R(s),l=[n,...fe().workspaces.map(({root:o})=>o).filter(o=>!i(o,n))].filter(Y),a=(await Promise.all(l.map(async o=>(await X(o)).map(s=>({...s,root:o}))))).flat(),u=K(a,t.join(" ").trim()),r=new Map,d=o=>(r.has(o)||r.set(o,Promise.all([T(o),L(o),ie(o)]).then(([{links:s},h,w])=>({links:s,tree:h,favorites:w}))),r.get(o)),c=await Promise.all(u.map(async o=>({workspace:o.root,...await z(o,{...await d(o.root),root:o.root})})));console.log(JSON.stringify({workspace:n,workspaces:l,documents:c},null,2))}async function ze(t){let{positional:n,options:i}=te({options:["--tree","--all","--json"],argv:t});if(i.has("--all")){if(i.has("--tree"))throw new D("--all and --tree go apart: --tree is the current workspace's tree.");return i.has("--json")?Pe(n):xe(n)}let l=await X();if(i.has("--json"))return Le(n,l,{tree:i.has("--tree")});if(i.has("--tree"))return je(n,l);let a=n.join(" ").trim(),{links:u}=await T(),r=n.length===1?ce(n[0],u):null,d=r&&r.slug!==n[0],c=d?l.filter(({slug:g})=>g===r.slug):K(l,a),o=[...c,...a&&!d?await ge(l,c,a):[]],s=await L(),h=a.toLowerCase().split(/\s+/).filter(Boolean),w=d?[]:_(s).filter(({slug:g,title:e,url:m})=>!h.length||h.some(p=>`${e} ${m} ${g}`.toLowerCase().includes(p))),$=n.length===1&&o.length===0&&w.length===0?await ne(n[0]):null;for(let g of await A({reading:!0}))console.log(g);let y=()=>{if(!w.length)return;let g=_(s).length;console.log(a?`${w.length} of ${q(g)} in the sidebar:`:`${q(g)} in the sidebar:`);for(let{slug:e,title:m,url:p}of w)console.log(`${e} ${m}`),console.log(` \u7F51\u9875\u94FE\u63A5\uFF1A${p}`),P(s.children,e)&&console.log(` ${J(s,e)}`)};if($)console.log($);else if(l.length===0)console.log('No documents yet: gallery new <slug> "<title>" makes one.'),y();else if(o.length===0&&w.length===0)console.log(`No document's title, description, slug or text holds ${a.split(/\s+/).map(g=>`"${g}"`).join(" or ")}: gallery list lists all ${l.length}.`);else if(o.length===0)y();else{console.log(a?`${o.length} of ${j(l.length)}, the best match first:`:`${j(l.length)}, the one edited last first:`);let g=await me();for(let{slug:e,title:m,description:p,edited:v,file:N,hit:b}of o)console.log(`${e} ${m}`),p&&console.log(` \u8BF4\u660E\uFF1A${p}`),b&&console.log(` \u6B63\u6587\uFF1A${b}`),P(s.children,e)&&console.log(` ${J(s,e)}`),console.log(` \u5730\u5740\uFF1A${ee(x,e,u,g)}`),console.log(` \u4E0A\u6B21\u7F16\u8F91\uFF1A${Z(v)}`),console.log(` ${B(N)}`);y(),n.length&&o.length===1&&!w.length&&console.log(await be(o[0].slug))}}export{X as a,Z as b,ze as c};
|
|
@@ -0,0 +1,2 @@
|
|
|
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{g as C}from"./chunk-ECZBLQKK.mjs";import{a as B}from"./chunk-E7656LR7.mjs";import N from"node:fs/promises";import U from"node:path";import{checkAnnotations as W,cleanAnchor as K,cleanItem as J,FILE as Q,itemsText as X,markItems as Y,readItems as Z,treeText as L,unknownIds as ee,withoutItems as te}from"../browser/shared/annotations.mjs";import{writeAtomic as ne}from"../browser/shared/files.mjs";import{slugPattern as re}from"../browser/shared/reports.mjs";import{documentDirectory as V,documentFiles as se}from"../browser/shared/workspace.mjs";var ae=600*1e3,ie=600*1e3,oe=120*1e3;function ce(I){let{units:k,boxes:R}=C(I),v=[...k].sort((a,p)=>a.elStart-p.elStart),w=new Map(v.map((a,p)=>[a.id,p])),g=new Map(v.map(a=>[a.id,L(a.node)])),u={h2:null,h3:null,h4:null};return v.map(a=>{let p=[];for(let l=a;l;l=l.parent===null?null:k[l.parent]){let f=R[l.box];if(f?.kind==="panel"&&f.key!==null){let m=k.find(A=>A.kind==="tab"&&A.parent===f.unit&&A.key===f.key);m&&p.unshift({tab:g.get(m.id)})}let y=f?.unit===null||f?.unit===void 0?null:k[f.unit];if(y?.tag==="details"&&f.kind==="details"){let m=y.node.childNodes.find(A=>A.tagName==="summary");m&&p.push({details:L(m)})}}let D=p.find(l=>l.tab)?.tab,j=p.find(l=>l.details)?.details,M=[D,u.h2,u.h3,u.h4,j].filter(Boolean);return a.tag==="h2"?Object.assign(u,{h2:g.get(a.id),h3:null,h4:null}):a.tag==="h3"?Object.assign(u,{h3:g.get(a.id),h4:null}):a.tag==="h4"&&(u.h4=g.get(a.id)),{id:a.blockId,text:g.get(a.id),parent:a.parent===null?null:w.get(a.parent)??null,where:M,heading:/^h[2-4]$/.test(a.tag)}})}function we({reportsDirectory:I,read:k,write:R=ne,dropped:v=()=>{},now:w=Date.now,verify:g=!0}){let u=new Map,a=new Map,p=new Map,D=new Map,j=(e,t)=>{let s=D.get(e);if(s?.text===t)return s.units;let r=ce(t);return D.set(e,{text:t,units:r}),r},M=e=>U.join(V(e,I),Q),l=e=>typeof e=="string"&&re.test(e);async function f(e){let t=await N.readFile(M(e),"utf8").catch(()=>null);return{text:t,items:t===null?[]:Z(t)}}async function y(e,t,s){let r=X(t);return r===s||(r===null?await N.rm(M(e),{force:!0}):await R(M(e),r)),m(r)}let m=e=>e===null?"":B(e),A=e=>{let t=u.get(e)??new Map;for(let[s,r]of t)w()-r>ae&&t.delete(s);return[...t.keys()]},_=(e,t)=>t.forEach(s=>u.get(e)?.delete(s)),E=e=>{let t=p.get(e)??p.set(e,new Map).get(e);for(let[s,r]of t)w()-r>ie&&t.delete(s);return t};async function F(e,{keep:t=null,items:s=null,before:r=void 0}={}){let d=s?{items:s,text:r}:await f(e),h=await k(e).catch(()=>null);if(!h)return{items:d.items,units:[],places:new Map,version:m(d.text),missing:!0};let x=j(e,h.text);if(!g){let n=s?await y(e,d.items,d.text):m(d.text);return{items:d.items,units:x,places:W(d.items,x).places,version:n,missing:!1}}let i=E(e),o=W(d.items,x,{keep:new Set([...i.keys(),t])});for(let n of i.keys())o.waiting.has(n)||i.delete(n);if(o.dropped.length>0){let n=u.get(e)??u.set(e,new Map).get(e);for(let O of o.dropped)n.set(O.id,w())}let c=o.changed||s?await y(e,o.items,d.text):m(d.text);return o.dropped.length>0&&v(e,o.dropped),{items:o.items,units:x,places:o.places,version:c,missing:!1}}let P=e=>{let t=a.get(e);return t&&w()-t.at>oe&&a.delete(e),a.get(e)},S=(e,{items:t,version:s})=>({ok:!0,version:s,items:t,dropped:A(e),...P(e)?{commandRemoved:P(e)}:{}});async function $(e){if(!l(e))return[400,{ok:!1,reason:"body"}];let t=await F(e);return t.missing?[404,{ok:!1,reason:"missing"}]:[200,S(e,t)]}async function T(e,{all:t=!1}={}){if(!l(e))return[400,{ok:!1,reason:"body"}];let s=await F(e);if(s.missing)return[404,{ok:!1,reason:"missing"}];let r=null,d=se(V(e,I));try{r=JSON.parse(await N.readFile(d.json,"utf8"))}catch{}let h=await k(e).catch(()=>null),x=/<h1\b[^>]*>([\s\S]*?)<\/h1>/i.exec(h?.text??"")?.[1]?.replace(/<[^>]*>/g,"").trim(),i=typeof r?.title=="string"&&r.title.trim()?r.title.trim():x||e,o=s.units.some(n=>n.heading),c=s.items.filter(n=>t||!n.done).map(n=>{let O=s.units[s.places.get(n.id)?.at],q=O?.where?.length?O.where:O?.heading?[O.text]:[];return{...t?{id:n.id}:{},where:q,top:o&&q.length===0,blocks:n.anchor.blocks.filter(G=>s.units.some(H=>H.id===G)),whole:n.anchor.kind==="blocks",quote:n.anchor.quote,text:n.text,...t?{done:n.done===!0,created:n.created,updated:n.updated}:{}}});return[200,{ok:!0,title:i,path:U.resolve(d.html),items:c}]}async function b(e){let{slug:t}=e??{};if(!l(t))return[400,{ok:!1,reason:"body"}];if(!await k(t).catch(()=>null))return[404,{ok:!1,reason:"missing"}];let s=await f(t);if(e.anchors&&typeof e.anchors=="object"&&!Array.isArray(e.anchors)){let i=s.items.map(c=>{let n=Object.hasOwn(e.anchors,c.id)?K(e.anchors[c.id]):null;return n&&n.kind===c.anchor.kind?{...c,anchor:n}:c}),o=await y(t,i,s.text);return[200,S(t,{items:i,version:o})]}let r=s.items,d=null,h=null;if(e.put!==void 0){let i=r.find(n=>n.id===e.put?.id),o=J({...e.put,created:i?.created??e.put?.created,done:!1});if(!o)return[400,{ok:!1,reason:"item"}];let c=i?.done&&i.text===o.text?{...o,done:!0}:o;r=i?r.map(n=>n.id===c.id?c:n):[...r,c],d=c.id,i||E(t).set(c.id,w()),_(t,[c.id])}else if(typeof e.remove=="string")r=r.filter(i=>i.id!==e.remove);else if(e.clear===!0)h=r,r=[];else if(Array.isArray(e.done)||Array.isArray(e.undone)||Array.isArray(e.removeIds)||e.removeDone===!0){let i=[e.done,e.undone,e.removeIds].find(Array.isArray)??[];if(!i.every(c=>typeof c=="string"))return[400,{ok:!1,reason:"body"}];let o=ee(r,i);if(o.length>0)return[404,{ok:!1,reason:"ids",ids:o}];Array.isArray(e.done)||Array.isArray(e.undone)?r=Y(r,i,Array.isArray(e.done)):{items:r,removed:h}=te(r,{ids:i,done:e.removeDone===!0})}else if(Array.isArray(e.restore)){let i=new Map(r.map(n=>[n.id,n])),o=e.restore.map(n=>J(n,n?.updated)).filter(n=>n&&!(i.get(n.id)?.updated>n.updated)),c=new Set(o.map(n=>n.id));for(let n of c)i.has(n)||E(t).set(n,w());r=[...r.filter(n=>!c.has(n.id)),...o],_(t,[...c]),a.delete(t)}else return[400,{ok:!1,reason:"body"}];e.put!==void 0&&a.delete(t),e.by==="command"&&h?.length>0&&a.set(t,{at:w(),items:h});let x=await F(t,{keep:d,items:r,before:s.text});return[200,{...S(t,x),...h?{removed:h}:{}}]}async function z(e){if(!l(e))return;let{text:t}=await f(e);t!==null&&await F(e)}return{list:$,copy:e=>T(e),notes:e=>T(e,{all:!0}),change:b,afterWrite:z}}export{we as a};
|
package/dist/cli.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
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}from"./chunk-
|
|
2
|
+
import{a,b,c,d,e,f}from"./chunk-VAXLSISW.mjs";import"./chunk-56SVJENP.mjs";import"./chunk-5L7RYZCL.mjs";export{e as attentionLine,f as main,d as notOurs,b as readCommandLine,c as unwritable,a as versionOf};
|
package/dist/server.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
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 o}from"./chunk-
|
|
2
|
+
import{a as o}from"./chunk-MTLAOCFF.mjs";import"./chunk-5MVUYRKG.mjs";import"./chunk-MZ66LN3B.mjs";import"./chunk-2MYTOOP6.mjs";import"./chunk-LHGKPMTI.mjs";import"./chunk-R5RERE6G.mjs";import"./chunk-2VNENLER.mjs";import"./chunk-HFTBVEZK.mjs";import"./chunk-TLNJWEFY.mjs";import"./chunk-ZOEJQOKT.mjs";import"./chunk-XNNCQROX.mjs";import"./chunk-LJZIYVNA.mjs";import"./chunk-IA4PSIMD.mjs";import"./chunk-QR4V4A2Z.mjs";import"./chunk-ZTHICSSF.mjs";import"./chunk-TQZU7D7C.mjs";import"./chunk-5IHDLEB4.mjs";import"./chunk-B2EIMERT.mjs";import"./chunk-2OHANJ6Q.mjs";import"./chunk-6N25CJ6Y.mjs";import"./chunk-F4CT35KL.mjs";import"./chunk-BFJGHSQN.mjs";import"./chunk-U5XL7D6A.mjs";import"./chunk-6ILJWFYW.mjs";import"./chunk-VRPVVMRB.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-PBMOC7KA.mjs";import"./chunk-BSJKFE7I.mjs";import"./chunk-NOGQX56R.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-W5NPH5UA.mjs";import"./chunk-ECZBLQKK.mjs";import"./chunk-E7656LR7.mjs";import"./chunk-TKWEX4FD.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";var t=process.argv.indexOf("--port"),r=t===-1?Number.NaN:Number(process.argv[t+1]);(!Number.isInteger(r)||r<=0||r>=65536)&&(console.error("Usage: node dist/server.mjs --port <n> (GALLERY_WORKSPACE names the workspace). The gallery command starts it: gallery open."),process.exit(2));try{let{port:e}=await o({port:r});console.log(`[gallery] ${new Date().toISOString()} listening on http://127.0.0.1:${e}/ (pid ${process.pid})`)}catch(e){console.error(`[gallery] could not start on port ${r}: ${e.message}`),process.exit(1)}
|
package/dist/update-fetch.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
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{s as r}from"./chunk-
|
|
2
|
+
import{s as r}from"./chunk-4LR2QEC2.mjs";import"./chunk-Q4UEPUWF.mjs";import"./chunk-5L7RYZCL.mjs";var[e,s]=process.argv.slice(2);try{e&&s&&await r(e,s)}catch{}process.exit(0);
|
package/dist/worker.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
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 P,b as W,c as B,e as H}from"./chunk-
|
|
2
|
+
import{a as P,b as W,c as B,e as H}from"./chunk-5I5ZDDWC.mjs";import"./chunk-2OHANJ6Q.mjs";import"./chunk-6N25CJ6Y.mjs";import"./chunk-F4CT35KL.mjs";import"./chunk-BFJGHSQN.mjs";import"./chunk-U5XL7D6A.mjs";import"./chunk-6ILJWFYW.mjs";import"./chunk-VRPVVMRB.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-W5NPH5UA.mjs";import"./chunk-ECZBLQKK.mjs";import{c as F}from"./chunk-E7656LR7.mjs";import{g as R,i as M}from"./chunk-TKWEX4FD.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";import{parentPort as N}from"node:worker_threads";import{PAGE as U}from"../browser/editor/components/kit.mjs";import{APART as T,clipboardOf as X,tagKind as j,unitClipboard as _,writtenApart as Y}from"../browser/editor/components/registry.mjs";import{WRITERS as h,heldToWords as Z,unitOpening as tt,wordsIn as et}from"../browser/editor/page/clipboard/own/writers.mjs";import{escapeAttribute as v}from"../browser/shared/escape.mjs";import{referencedFile as rt}from"../browser/shared/media.mjs";var nt=/^\s*\\\(([\s\S]*)\\\)\s*$/,ot=" ",st=["script","style","template","noscript",T,U.header,`${U.header} > h1`].join(", ");function it(r,u){let f=globalThis.document.createElement("template");f.innerHTML=r??"";let d=g=>[...g.childNodes].map(n=>{if(n.nodeType===3)return n.data.replace(/ /g," ");if(n.nodeType!==1)return"";if(n.matches(".doc-math-inline")){let i=nt.exec(n.textContent)?.[1];return i!==void 0?i.trim()?`$${i.trim()}$`:"":n.textContent}if(n.localName==="img"){let i=n.getAttribute("src");return i?`)})`:""}if(n.matches("a.doc-link-mention")){let i=(n.querySelector(".doc-link-mention-title")??n).textContent.replace(/\s+/g," ").trim();return n.getAttribute("href")?`[${i||n.getAttribute("href")}](${n.getAttribute("href")})`:i}let l=d(n);if(n.localName==="br")return`
|
|
3
3
|
`;if(!l.trim())return l;let[c,m,p]=[l.match(/^\s*/)[0],l.trim(),l.match(/\s*$/)[0]];switch(n.localName){case"strong":case"b":return`${c}**${m}**${p}`;case"em":case"i":return`${c}*${m}*${p}`;case"s":case"del":case"strike":return`${c}~~${m}~~${p}`;case"code":return`${c}\`${m}\`${p}`;case"a":{let i=n.getAttribute("href")??"";return!i||i.startsWith("#")?l:rt(i)?`${c}[${m}](${u(i,"file",n.getAttribute("download")||D(i))})${p}`:m===i?`${c}${i}${p}`:`${c}[${m}](${i})${p}`}default:return n.classList.contains("doc-tab")?` ${l}`:l}}).join("");return Z(d(f.content).replace(/[ \t]+\n/g,`
|
|
4
4
|
`).trim())}function b(r){if(!r.querySelector(T))return r;let u=r.cloneNode(!0);for(let f of u.querySelectorAll(T))f.remove();return u}var ct=r=>(r?.textContent??"").replace(/\s+/g," ").trim(),D=r=>r.replace(/[?#].*$/,"").split("/").pop(),at=r=>r.replace(/[\\[\]]/g,"\\$&"),ut=/(\d+)/g;async function K(r,{title:u,media:f=g=>g,chart:d=()=>null}){let{UNIT:g,unitsOf:n,serializeInner:l,nestedBlocks:c,isHost:m}=await P(),p=e=>it(e,f),i=e=>{let t=b(e),o=[...t.querySelectorAll("img")];if(o.length===0)return l(t);let s=t.cloneNode(!0);return s.querySelectorAll("img").forEach((a,A)=>a.replaceWith(`\uE000${A}\uE001`)),l(s).replace(ut,(a,A)=>`<img src="${v(o[A].getAttribute("src")??"")}" alt="${v(o[A].getAttribute("alt")??"")}">`)},z=e=>p(i(e)),G=(e,{tables:t=!0}={})=>{let o=b(e);return[...o.querySelectorAll("img[src]")].filter(s=>!s.closest("a.doc-link-mention")&&(t||!o.contains(s.closest("table")))).map(s=>p(s.outerHTML))},x=e=>(j(e)&&!e.matches(g)&&e.setAttribute("data-ge-unit-kind",j(e)),e);function w(e){let t=[],o=null;for(let s of e.childNodes){let a=s.nodeType===1;(a?s.matches(st):s.nodeType!==3)||(a&&(s.matches(g)||F.has(s.localName))?(t.push(x(s)),o=null):(a||o||s.data.trim())&&(o||t.push(o=x(r.createElement("p"))),o.append(s.cloneNode(!0))))}return t}let y=e=>h[_(e).kind].list,C=e=>e.map(t=>t&&`${ot}${t}`);function k(e){let t=[],o=null;for(let s of e){let a=E(s);a.length!==0&&(o!==null&&!(y(o)&&y(s))&&t.push(""),t.push(...a),o=s)}return t}function S(e){let t=[];for(let o of e){let s=E(o);if(s.length===0)continue;let a=y(o);!a&&t.length>0&&t.at(-1)!==""&&t.push(""),!a&&t.length===0&&t.push(""),t.push(...C(s)),a||t.push("")}for(;t.at(-1)==="";)t.pop();return t}function J(e,t=null){let s=n(e).length>0?[]:h.words.exported(e,$,{without:t});return s.length>0?["",...C(s)]:S(w(e).filter(a=>a!==t))}function E(e){let t=_(e);return h[t.kind].exported(e,$,t)}function V(e,t){let o=/^en(?:-|$)/i.test(e.ownerDocument.documentElement.getAttribute("lang")??"");return t?o?"Chart":"\u56FE\u8868":o?"Figure":"\u56FE"}let $={isHost:m,nestedBlocks:c,serializeInner:l,media:f,chart:d,inline:p,own:z,withPictures:i,picturesIn:G,lines:k,held:S,heldIn:J,untitled:V,wordsIn:(e,t,o)=>et(b(e),t,o),plain:ct,unitsOf:w,words:e=>h.words.exported(e,$),packageOf:e=>R().packages.get(e),opening:(e,t)=>tt(e,t,$),writtenAs(e,t){let o=X(e);return h[o.kind].exported(t,$,o)}},I=r.querySelector(".doc-header"),O=I?k(w(I)):[],q=r.querySelector("main"),L=k(q?w(q):[]),Q=Y(r).flatMap(({element:e,clipboard:t})=>["",...h[t.kind].exported(e,$,t)]);return[`# ${u||"Untitled"}`,...O.length?["",...O]:[],...L.length?["",...L]:[],...Q].join(`
|
|
5
5
|
`)}import{saying as lt}from"../browser/shared/i18n/index.mjs";import{referencedFile as pt}from"../browser/shared/media.mjs";var ft=r=>`\0F${r}\0`,mt=r=>`\0C${r}\0`,dt={async markdown({source:r,title:u,pictures:f}){let{document:d}=await W(r),g=[],n=[...d.querySelectorAll("main figure.doc-figure")];return{text:await K(d,{title:u,media:(c,m,p)=>{let i=pt(c);return i?ft(g.push({src:i,kind:m,name:p})-1):c},chart:c=>f&&n.includes(c)?mt(n.indexOf(c)):null}),files:g,charts:n.length,charted:n.map(c=>!!c.querySelector("[data-doc-chart]"))}},import:({uploads:r,scratch:u})=>B(r,u),fill:r=>H(r)};N.on("message",async({id:r,type:u,payload:f})=>{try{M(),N.postMessage({id:r,result:await dt[u](f)})}catch(d){N.postMessage({id:r,error:{...lt(d),stack:d.stack}})}});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heycys/gallery",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Gallery: documents written as HTML by an AI agent, shown and edited in the browser, delivered as one offline file. The gallery command and its local server.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gallery",
|
package/release.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heycys/gallery",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"built": "2026-11-
|
|
3
|
+
"version": "0.2.4",
|
|
4
|
+
"built": "2026-11-11T20:59:16.942Z",
|
|
5
5
|
"stamps": {
|
|
6
|
-
"editor": "
|
|
6
|
+
"editor": "666975d254c7540c",
|
|
7
7
|
"kit": {
|
|
8
8
|
"styles": "fd4d4ec8d57ef8d1",
|
|
9
9
|
"katex-styles": "81d0a0b4dcb41846",
|