@heycys/gallery 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/THIRD-PARTY-NOTICES.md +1 -1
- package/browser/editor/page/annotate/index.mjs +3 -2
- package/browser/editor/page/board/index.mjs +2 -1
- package/browser/editor/page/board/settings.mjs +2 -1
- package/browser/editor/page/core.mjs +3 -2
- package/browser/editor/page/custom-page.mjs +4 -3
- package/browser/editor/page/editor.mjs +9 -5
- package/browser/editor/page/emoji-picker/support.mjs +3 -2
- package/browser/editor/page/links/index.mjs +1 -12
- package/browser/editor/page/links/pages.mjs +3 -2
- package/browser/editor/page/outline/folds.mjs +3 -0
- package/browser/editor/page/post.mjs +2 -1
- package/browser/editor/page/present-links.mjs +4 -3
- package/browser/editor/page/present-shell.mjs +3 -58
- package/browser/editor/page/session.mjs +3 -37
- package/browser/editor/page/storage.mjs +5 -5
- package/browser/shared/component-catalog.mjs +2 -2
- package/browser/shared/drafts.mjs +26 -51
- package/browser/shared/emoji/icon-value.mjs +2 -1
- package/browser/shared/extension-manifest.mjs +90 -0
- package/browser/shared/extensions.mjs +26 -16
- package/browser/shared/http.mjs +1 -1
- package/browser/shared/i18n/en.mjs +46 -15
- package/browser/shared/media.mjs +2 -1
- package/browser/shared/outline.mjs +11 -51
- package/browser/shared/page-address.mjs +8 -15
- package/browser/shared/paths.mjs +2 -1
- package/browser/shared/preferences.mjs +3 -1
- package/browser/shared/preview-server.mjs +51 -63
- package/browser/shared/service-location.mjs +18 -0
- package/browser/shared/session.mjs +3 -6
- package/browser/shared/workspace-address.mjs +19 -0
- package/browser/shared/workspace-columns.mjs +1 -2
- package/browser/shared/workspace-registry.mjs +6 -40
- package/browser/shared/workspace.mjs +3 -6
- package/browser/shared/writing-preferences.mjs +6 -4
- package/dist/{chunk-BYSF5UMM.mjs → chunk-236JJXWY.mjs} +2 -2
- package/dist/{chunk-3A5I2GJK.mjs → chunk-2KAVXMKG.mjs} +1 -1
- package/dist/chunk-2T4PZQEP.mjs +2 -0
- package/dist/{chunk-SAHS56QM.mjs → chunk-3SKOU6OZ.mjs} +1 -1
- package/dist/{chunk-S2Y7VI4H.mjs → chunk-3XZOA7AH.mjs} +2 -2
- package/dist/{chunk-MKTX5PGV.mjs → chunk-43B75J5T.mjs} +1 -1
- package/dist/{chunk-VKSRM7EY.mjs → chunk-4B2TB5K2.mjs} +1 -1
- package/dist/{chunk-LV24RY2E.mjs → chunk-4K5KC6V2.mjs} +1 -1
- package/dist/{chunk-SOD23RGL.mjs → chunk-4KUO7R2M.mjs} +8 -8
- package/dist/chunk-4SNV4HA5.mjs +2 -0
- package/dist/chunk-53XDTHTG.mjs +4 -0
- package/dist/chunk-5XV3YYLG.mjs +2 -0
- package/dist/{chunk-VNUWREXU.mjs → chunk-65NTKF4N.mjs} +1 -1
- package/dist/chunk-6GV3CBB2.mjs +2 -0
- package/dist/{chunk-DH6GMDNN.mjs → chunk-6L6V7YR2.mjs} +1 -1
- package/dist/{chunk-TOE6DPLH.mjs → chunk-6NLXUKAY.mjs} +1 -1
- package/dist/chunk-6Q7ASAXJ.mjs +3 -0
- package/dist/{chunk-ZCP7BTOZ.mjs → chunk-6QBHU4DF.mjs} +1 -1
- package/dist/{chunk-QXVNUASA.mjs → chunk-6QWQXHAV.mjs} +1 -1
- package/dist/chunk-6XD6U3QA.mjs +5 -0
- package/dist/{chunk-36FIRJIF.mjs → chunk-742D2WWJ.mjs} +2 -2
- package/dist/{chunk-7M7UPWU6.mjs → chunk-7EFHNQ5B.mjs} +1 -1
- package/dist/{chunk-JI6T3A4Y.mjs → chunk-7ISBBDJR.mjs} +1 -1
- package/dist/{chunk-2GKGEVMR.mjs → chunk-7UZUQQ7Q.mjs} +25 -24
- package/dist/{chunk-VPVOAJ7X.mjs → chunk-AGDILNWB.mjs} +1 -1
- package/dist/{chunk-5IIH335D.mjs → chunk-ALZ6ZENZ.mjs} +1 -1
- package/dist/{chunk-G4YP7GVC.mjs → chunk-BFJGHSQN.mjs} +1 -1
- package/dist/chunk-BLNQUR5R.mjs +168 -0
- package/dist/chunk-BMX3VUHY.mjs +2 -0
- package/dist/chunk-BN7M3IN7.mjs +8 -0
- package/dist/{chunk-AMDGVDNV.mjs → chunk-BQNTTFPL.mjs} +1 -1
- package/dist/chunk-C257H6IA.mjs +2 -0
- package/dist/{chunk-74RPP2M2.mjs → chunk-C564NU2H.mjs} +1 -1
- package/dist/chunk-CHQU37CA.mjs +2 -0
- package/dist/{chunk-WCWYNFDF.mjs → chunk-E4IHAIJ7.mjs} +1 -1
- package/dist/{chunk-7XDYK3UC.mjs → chunk-E7656LR7.mjs} +1 -1
- package/dist/{chunk-KFZBYDIS.mjs → chunk-ECZBLQKK.mjs} +1 -1
- package/dist/{chunk-PAFSFVYB.mjs → chunk-ERE2BXYV.mjs} +1 -1
- package/dist/{chunk-ZEY2RLBT.mjs → chunk-ERLAIBOA.mjs} +2 -2
- package/dist/chunk-FFV733MA.mjs +2 -0
- package/dist/{chunk-CZ5KJSGK.mjs → chunk-GJJRBGMY.mjs} +1 -1
- package/dist/{chunk-VA3KAQZD.mjs → chunk-GKOBB6DH.mjs} +1 -1
- package/dist/chunk-GMJD7ID3.mjs +2 -0
- package/dist/{chunk-QZ35UAB4.mjs → chunk-GRAXKKG4.mjs} +1 -1
- package/dist/{chunk-2RKIHJI2.mjs → chunk-HYMEEXKN.mjs} +1 -1
- package/dist/{chunk-DKR7LFIY.mjs → chunk-IA2SIEJQ.mjs} +1 -1
- package/dist/{chunk-QK3VISCA.mjs → chunk-IA4PSIMD.mjs} +1 -1
- package/dist/chunk-JPG2LBQM.mjs +11 -0
- package/dist/{chunk-VGTMLQWZ.mjs → chunk-JXXHAXYH.mjs} +1 -1
- package/dist/{chunk-5MEXZ2UF.mjs → chunk-K3JKPFL5.mjs} +1 -1
- package/dist/{chunk-LE44MD3O.mjs → chunk-KLQP46Y3.mjs} +1 -1
- package/dist/{chunk-NAGMRVW4.mjs → chunk-LKX55H76.mjs} +1 -1
- package/dist/chunk-LMUZQK5O.mjs +2 -0
- package/dist/{chunk-CG3UHDKH.mjs → chunk-M4NRDYI5.mjs} +1 -1
- package/dist/{chunk-HM4E43VM.mjs → chunk-MAFIGVXY.mjs} +1 -1
- package/dist/{chunk-4DNHHJSL.mjs → chunk-MKIBJTJZ.mjs} +1 -1
- package/dist/{chunk-L7W624FD.mjs → chunk-MNWJ4EZY.mjs} +1 -1
- package/dist/{chunk-FXQBADMN.mjs → chunk-NHP66IWR.mjs} +1 -1
- package/dist/{chunk-YBB5LWZK.mjs → chunk-OEIJLMPI.mjs} +1 -1
- package/dist/{chunk-NWRZXELO.mjs → chunk-PAREWQGB.mjs} +1 -1
- package/dist/{chunk-7N2LPG33.mjs → chunk-PDZR3L3C.mjs} +1 -1
- package/dist/{chunk-YFJU3O7G.mjs → chunk-PLB7L22J.mjs} +1 -1
- package/dist/{chunk-4AMTKWDO.mjs → chunk-PUOQ65NC.mjs} +1 -1
- package/dist/chunk-Q4MS6OFC.mjs +2 -0
- package/dist/{chunk-3OFXMN6N.mjs → chunk-Q7P3Q5YX.mjs} +1 -1
- package/dist/{chunk-6MPKCH3P.mjs → chunk-QNECWMGR.mjs} +1 -1
- package/dist/{chunk-HBAUKKQH.mjs → chunk-QP7BOHE4.mjs} +1 -1
- package/dist/chunk-QVGOPHOF.mjs +2 -0
- package/dist/{chunk-NFABH3QW.mjs → chunk-RRKJMHNX.mjs} +2 -2
- package/dist/chunk-S3SX3COT.mjs +20 -0
- package/dist/{chunk-ZO7SFB2E.mjs → chunk-SQ6Y2ZMA.mjs} +2 -2
- package/dist/{chunk-VG5JEIUQ.mjs → chunk-TKWEX4FD.mjs} +2 -2
- package/dist/{chunk-CCSGFCLZ.mjs → chunk-U3SSPL4K.mjs} +1 -1
- package/dist/{chunk-DHB7UZ7F.mjs → chunk-U5XL7D6A.mjs} +1 -1
- package/dist/{chunk-CPS4SRPF.mjs → chunk-ULXSPX5H.mjs} +2 -2
- package/dist/{chunk-JXLSHVJ2.mjs → chunk-UMHUSOPJ.mjs} +1 -1
- package/dist/chunk-USIHBCSW.mjs +15 -0
- package/dist/{chunk-GWOYMENX.mjs → chunk-V6XZ4VIR.mjs} +1 -1
- package/dist/{chunk-AFGUR7SY.mjs → chunk-VPMRP2TL.mjs} +1 -1
- package/dist/{chunk-WTEGUPFG.mjs → chunk-VRPVVMRB.mjs} +1 -1
- package/dist/chunk-VZ2RQ3AM.mjs +2 -0
- package/dist/{chunk-XKOHV4H6.mjs → chunk-W5NPH5UA.mjs} +1 -1
- package/dist/chunk-WFGPMCTZ.mjs +4 -0
- package/dist/chunk-XZCFPKGO.mjs +2 -0
- package/dist/{chunk-QJ3TFJLQ.mjs → chunk-Y34NR5JL.mjs} +1 -1
- package/dist/{chunk-V5JRSGZF.mjs → chunk-YN37ZDLW.mjs} +1 -1
- package/dist/chunk-ZFGMJVJC.mjs +2 -0
- package/dist/{chunk-KH24LWAT.mjs → chunk-ZTHICSSF.mjs} +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/server.mjs +1 -1
- package/dist/worker.mjs +1 -1
- package/kit/math.js +1 -1
- package/kit/runtime.js +12 -2
- package/kit/state.js +2 -0
- package/kit/ui.js +5 -1
- package/package.json +1 -1
- package/release.json +7 -7
- package/skill/SKILL.md +13 -13
- package/skill/references/building-blocks.md +1 -1
- package/skill/references/extensions.md +45 -9
- package/web/assets/{index-xP0uw3a0.css → index-FLb9jCfl.css} +1 -1
- package/web/assets/index-czjrXVjf.js +15 -0
- package/web/index.html +2 -2
- package/dist/chunk-46ACXOU5.mjs +0 -2
- package/dist/chunk-5DPABPBI.mjs +0 -2
- package/dist/chunk-5L26JUYA.mjs +0 -2
- package/dist/chunk-AEMVZYZQ.mjs +0 -166
- package/dist/chunk-ASAXY2DJ.mjs +0 -2
- package/dist/chunk-DAMVDXR3.mjs +0 -2
- package/dist/chunk-DLFZJJEE.mjs +0 -2
- package/dist/chunk-EKNHM3P4.mjs +0 -2
- package/dist/chunk-FCK6NXON.mjs +0 -3
- package/dist/chunk-FX42XU6J.mjs +0 -2
- package/dist/chunk-HATA2W7X.mjs +0 -2
- package/dist/chunk-JJNRIFND.mjs +0 -8
- package/dist/chunk-JL6R4FG4.mjs +0 -4
- package/dist/chunk-KUILYI7H.mjs +0 -4
- package/dist/chunk-NIW7F7LU.mjs +0 -4
- package/dist/chunk-OU3S466R.mjs +0 -20
- package/dist/chunk-QCEATQC4.mjs +0 -2
- package/dist/chunk-TDWJKOLN.mjs +0 -2
- package/dist/chunk-UGO5N3EI.mjs +0 -15
- package/dist/chunk-XMKHCUI6.mjs +0 -15
- package/dist/chunk-XQRUG4G3.mjs +0 -2
- package/dist/chunk-YPPJVDQI.mjs +0 -2
- package/dist/chunk-ZANMKAWS.mjs +0 -2
- package/web/assets/index-BHC5ZOMh.js +0 -15
- /package/dist/{chunk-N3DSBH5S.mjs → chunk-A55HN5OK.mjs} +0 -0
- /package/dist/{chunk-KNZJT4ET.mjs → chunk-QAIHRH3I.mjs} +0 -0
- /package/dist/{chunk-ZW2A6GBW.mjs → chunk-QR6A54KJ.mjs} +0 -0
- /package/dist/{chunk-74UW7QSL.mjs → chunk-UH4SIXTR.mjs} +0 -0
- /package/dist/{chunk-EKGYYOSP.mjs → chunk-W7XHE4CT.mjs} +0 -0
- /package/dist/{chunk-5MMN3N5J.mjs → chunk-YEY3RSFQ.mjs} +0 -0
package/web/index.html
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
6
|
<title>Gallery</title>
|
|
7
7
|
<link rel="icon" href="data:," />
|
|
8
|
-
<script type="module" crossorigin src="/assets/index-
|
|
9
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-czjrXVjf.js"></script>
|
|
9
|
+
<link rel="stylesheet" crossorigin href="/assets/index-FLb9jCfl.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body class="preload">
|
|
12
12
|
<div id="root"></div>
|
package/dist/chunk-46ACXOU5.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{a,b}from"./chunk-FX42XU6J.mjs";import"./chunk-KUILYI7H.mjs";import"./chunk-2GKGEVMR.mjs";import"./chunk-VKSRM7EY.mjs";import"./chunk-LE44MD3O.mjs";import"./chunk-4OZWXZE5.mjs";import"./chunk-7XDYK3UC.mjs";import"./chunk-VG5JEIUQ.mjs";import"./chunk-N3DSBH5S.mjs";import"./chunk-5L7RYZCL.mjs";export{a as copiedLines,b as run};
|
package/dist/chunk-5DPABPBI.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{a,b}from"./chunk-DKR7LFIY.mjs";import"./chunk-3A5I2GJK.mjs";import"./chunk-XQRUG4G3.mjs";import"./chunk-OU3S466R.mjs";import"./chunk-QK3VISCA.mjs";import"./chunk-F4ZA6JRZ.mjs";import"./chunk-7M2BQQGZ.mjs";import"./chunk-TOE6DPLH.mjs";import"./chunk-WTEGUPFG.mjs";import"./chunk-4OZWXZE5.mjs";import"./chunk-XMKHCUI6.mjs";import"./chunk-SAHS56QM.mjs";import"./chunk-KH24LWAT.mjs";import"./chunk-YFJU3O7G.mjs";import"./chunk-NWRZXELO.mjs";import"./chunk-G4YP7GVC.mjs";import"./chunk-DHB7UZ7F.mjs";import"./chunk-2RKIHJI2.mjs";import"./chunk-JXLSHVJ2.mjs";import"./chunk-XKOHV4H6.mjs";import"./chunk-KFZBYDIS.mjs";import"./chunk-7XDYK3UC.mjs";import"./chunk-VG5JEIUQ.mjs";import"./chunk-N3DSBH5S.mjs";import"./chunk-5L7RYZCL.mjs";export{a as noDocuments,b as run};
|
package/dist/chunk-5L26JUYA.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{g as v,h as X}from"./chunk-S2Y7VI4H.mjs";import{a as C,b as B,d as z,g as W,i as J,j as K}from"./chunk-JJNRIFND.mjs";import{a as w}from"./chunk-JEUK3ZO7.mjs";import{f as G}from"./chunk-2GKGEVMR.mjs";import{h as F,i as H}from"./chunk-VKSRM7EY.mjs";import{a as R,e as P,f as Y}from"./chunk-LE44MD3O.mjs";import{a as U,b as d,f as q}from"./chunk-4OZWXZE5.mjs";import{f as L}from"./chunk-VG5JEIUQ.mjs";import{editStateDirectory as re,reportsDirectory as Z}from"../browser/shared/paths.mjs";import{FIRST_BOARD as le,HOME as D,createPage as ce,listPages as de,pageExists as ee,pageFiles as O,pageSlugRefused as te,pagesSettings as he,readPageMeta as ge}from"../browser/shared/pages.mjs";import{findPreviewServer as se}from"../browser/shared/preview-server.mjs";var M=(e,t)=>`${W(e)}#@${t}`,pe=(e,t)=>`http://127.0.0.1:${e}/pages/${t}`,fe="The default home page (\u9996\u9875, slug home) is not made yet: Gallery makes it, with its own cards, when its server first starts in this workspace. gallery open --no-browser starts it: run that once, then gallery page list again.";async function oe(e){return H()||ee(D,e)||he(e).homeMade||await te(D,e)?null:fe}async function ne(e,t){return(e===D?await oe(t):null)??`No custom page "${e}": ${w(O(e,t).html)} does not exist (gallery page list lists those there are).`}async function ae(e){return(await se({reportsDirectory:e,answering:!0,timeout:2e3}))?.port??null}async function we(e,[t,o,...i]){if(!t||!o?.trim()||i.length)throw new d("Name the slug and the title, the title quoted when it has spaces.");let n=await te(t,e);n&&(console.error(n),process.exit(1));let s=await ce(t,o,{root:e});console.log(`Created ${w(s.html)} and page.json`),console.log(`It is listed in the workbench's sidebar, last among the rows under \u65B0\u5EFA and \u641C\u7D22 (the user may drag it elsewhere), and shows one empty board (data-board-id="main"): use it, or write the page as you like.`);let a=await ae(e),r=`write page.html: a board of cards (each <section class="gallery-card" data-card-id="\u2026" data-x data-y data-w data-h> around one custom block's instance; gallery page add places one), or any HTML, CSS and script of your own (references/pages-and-data.md)`,c="at the end tell them where it is in the sidebar (under \u65B0\u5EFA and \u641C\u7D22, its title)";a?(console.log(`Next: send the user the address on the last line now, in a message of its own (the page is theirs to watch as its cards arrive); ${r}; ${c}.`),console.log(`${C}${M(a,t)}`)):console.log(`Next: run gallery page open ${t} --no-browser now (it starts the server) and send the user the address on its \u4EA4\u7ED9\u7528\u6237 line, in a message of its own, before you write any card (the page is theirs to watch as its cards arrive); then ${r}; ${c}.`)}async function me(e,t){if(t.length)throw new d("gallery page list takes nothing else.");let o=await de(e);console.log(`\u5DE5\u4F5C\u533A\uFF1A${w(e)}`);let i=await oe(e);o.length===0&&!i?console.log('No custom pages yet: gallery page new <slug> "<\u6807\u9898>" makes one.'):o.length>0&&console.log(`Custom pages, in the sidebar's order (${o.length}):`);let n=o.length?await ae(e):null;for(let{slug:s,title:a,icon:r}of o)console.log(`- ${s} ${r?`${r} `:""}${a}`),console.log(` \u5730\u5740\uFF1A${n?M(n,s):`/#@${s}`} ${w(O(s,e).html)}`);i&&console.log(i)}async function ue(e,[t,...o],i){if(!t||o.length)throw new d("gallery page open takes one page's slug.");await ge(t,e)||(console.error(await ne(t,e)),process.exit(1)),console.log(`\u5DE5\u4F5C\u533A\uFF1A${w(e)}`);let s=await J({command:`gallery page open ${t}`});s.ok||(console.error(s.message),process.exit(1));let a=[K(s),`${B}${pe(s.port,t)}`,`${C}${M(s.port,t)}`];for(let r of a)console.log(r);console.log(await z(a,i))}async function Q(e,t,o){let i=`127.0.0.1:${e.port}`;try{let n=await fetch(`http://${i}/__gallery/pages/${t}/cards`,{method:"POST",headers:{"Content-Type":"application/json",Origin:`http://${i}`,"X-Gallery-Token":e.token},body:JSON.stringify({...o,workspace:Z}),signal:AbortSignal.timeout(3e4)}),s=await n.json().catch(()=>null);return!s||["elsewhere","token","host","origin","unknown","method"].includes(s.reason)?null:[n.status,s]}catch{return null}}var $e=8e3,b={places:e=>`${e} is a block of documents (its manifest's places has no "page"): it does not go on a custom page.`,disabled:e=>`${e} is turned off (\u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868 \u505C\u7528): nothing of it loads, on a page or in a document.`,missing:e=>`No custom block ${e} in this workspace: gallery block list lists them.`,template:e=>`${e} has no template.html a new card can be made of (gallery block check ${e} says why).`,board:(e,t)=>`No board "${t}" on this page: its <div class="gallery-board" data-board-id="\u2026">s are the ones there are.`,cells:()=>"--x, --y, --w and --h are whole numbers (x and y from 0, w and h from 1).",busy:()=>"page.html was written again and again meanwhile: run this again.",size:()=>"page.html would grow past 1,000,000 bytes.",values:(e,t,o)=>`${e}'s setting ${o?`"${o}" `:""}does not take that value (a text of 10,000 characters at most, a number, a date, one of a select's options, a switch's true or false).`,settings:e=>`${e} has no settings, or a card of it no settings part: --set goes with a block whose manifest has some.`};function ye(e){let t=e.indexOf("--"),o=[],i=[];for(let n=0;n<e.length;n++){let s=e[n];if(t!==-1&&n>=t)i.push(s);else if(s==="--set"||s.startsWith("--set=")){let a=s==="--set"?e[n+1]:s.slice(6);s==="--set"&&(n+=1);let r=a?.indexOf("=")??-1;if(a===void 0||r<1)throw new d("--set takes a setting's key and its value: --set <key>=<value> (--set city=\u4E0A\u6D77).");o.push([a.slice(0,r),a.slice(r+1)])}else i.push(s)}return{argv:i,given:o}}var V=new Map([["true",!0],["yes",!0],["on",!0],["1",!0],["false",!1],["no",!1],["off",!1],["0",!1]]);function be(e,t){let o=t.settings??[],i=()=>o.length?`its settings are ${o.map(({key:s,label:a})=>`${s} (${a?.en??a?.zh??s})`).join(", ")}`:"it has no settings",n={};for(let[s,a]of e){let r=o.find(c=>c.key===s);if(!r)throw new d(`${t.id} has no setting "${s}": ${i()}.`);if(Object.hasOwn(n,s))throw new d(`--set ${s} is given twice.`);if(r.type==="number"){if(a.trim()!==""&&!Number.isFinite(Number(a)))throw new d(`The setting ${s} of ${t.id} is a number: --set ${s}=<number>, or --set ${s}= for none.`);n[s]=a.trim()===""?null:Number(a)}else if(r.type==="switch"){if(!V.has(a.trim().toLowerCase()))throw new d(`The setting ${s} of ${t.id} is a switch: --set ${s}=true or --set ${s}=false.`);n[s]=V.get(a.trim().toLowerCase())}else if(r.type==="select"){if(!r.options.includes(a))throw new d(`The setting ${s} of ${t.id} is one of ${r.options.join(", ")}: --set ${s}=<one of them>.`);n[s]=a}else if(r.type==="date"){if(a!==""&&!/^\d{4}-\d{2}-\d{2}$/.test(a))throw new d(`The setting ${s} of ${t.id} is a date, written YYYY-MM-DD: --set ${s}=2027-02-06.`);n[s]=a}else n[s]=a}return n}function ke(e,t){let o=t&&typeof t=="object"&&!Array.isArray(t)?t:{};return(e.settings??[]).filter(i=>i.required&&i.type!=="switch").filter(({key:i,default:n})=>{let s=Object.hasOwn(o,i)?o[i]:n;return s==null||typeof s=="string"&&s.trim()===""}).map(({key:i,label:n})=>({key:i,label:n?.en??n?.zh??i,zh:n?.zh??null}))}async function xe(e,[t,o,...i],n,s,a,r=[]){if(!t||!o||i.length)throw new d("gallery page add takes a page's slug and a block's id (gallery block list lists them).");let c={};for(let l of["x","y","w","h"]){let g=s.get(`--${l}`);if(g!==void 0){if(!/^\d+$/.test(g)||(l==="w"||l==="h")&&Number(g)<1)throw new d(b.cells());c[l]=Number(g)}}if(c.x===void 0!=(c.y===void 0))throw new d("--x and --y go together: a place is both.");ee(t,e)||(console.error(await ne(t,e)),process.exit(1));let k=o.includes("/")?null:P(o),h=o.includes("/")?o:k?k.id:o,m=L(e),u=m.packages.get(h);if(!u){let l=Y(h)?P(h):null;m.settings.disabled.includes(h)?console.error(b.disabled(h)):console.error(l?`${h} is one of Gallery's own blocks, not yet in this workspace: gallery block add ${l.pack===R?l.name:l.id} puts it in; then run this again.`:m.problems.has(h)?`${h} does not load (gallery block check ${h} says why).`:b.missing(h)),process.exit(1)}u.places.includes("page")||(console.error(b.places(h)),process.exit(1));let p=s.get("--board"),y=r.length?be(r,u):null,N={op:"add",block:h,...p?{board:p}:{},...c,...y?{settings:y}:{},agent:!0},j=await se({reportsDirectory:e}),x=j?await Q(j,t,N):null;for(let l=0;x?.[1]?.reason==="missing"&&l<$e/250;l++)await new Promise(g=>setTimeout(g,250)),x=await Q(j,t,N);let[ie,f]=x??await F({root:e,stateDirectory:re,catalog:()=>m}).apply(t,N);if(!f?.ok){let l=f?.reason;console.error(b[l]?.(h,p??le,f?.message)??`Not added (${ie}: ${l??"no answer"}${f?.message?`: ${f.message}`:""}).`),process.exit(1)}let $=f.cards.find(l=>l.id===f.card),I=(f.pushed??[]).map(l=>f.cards.find(g=>g.id===l)).filter(Boolean);console.log(`Added a card of ${h} to ${w(O(t,e).html)}${x?" (through the workspace's running server: an open page shows it at once)":""}:`),console.log(` data-card-id="${$.id}" on board ${$.board}: x ${$.x}, y ${$.y}, w ${$.w}, h ${$.h}${f.measure?" (its block gives no height: 2 cells, --h sets another)":""}`),I.length&&console.log(` Pushed down under it, as it met them: ${I.map(l=>`${l.id} (y ${l.y})`).join(", ")}; no card moved up.`),y&&console.log(` Settings written with it: ${Object.entries(y).map(([l,g])=>`${l}=${JSON.stringify(g)}`).join(", ")}`),console.log(y?"The rest of its data is as the block's template writes it, in the card's instance: write it there if it is to hold something else, leaving every other card as it is.":"Its data is as the block's template writes it, in the card's instance: write it there if it is to hold something else, leaving every other card as it is.");let S=ke(u,{...y??{}});if(S.length){let l=S.map(({key:g,label:T,zh:E})=>`${g} (${E&&E!==T?`${T}, ${E}`:T})`).join(", ");console.log(`${h} needs its setting ${l} before the card shows anything, and this card has none: ask the user for it, or take it from what the workspace says (\u5199\u4F5C\u504F\u597D, the documents) and tell them in the handoff which you did. Give it with the add (${S.map(({key:g})=>`--set ${g}=<value>`).join(" ")}); for this card, write it in its settings part of ${w(O(t,e).html)} (the <script type="application/json"> of data-card-id="${$.id}": {"${S[0].key}":"\u2026"}), re-reading the page right before, or the user fills it in on the card (the grip at its top right \u203A \u8BBE\u7F6E\u2026).`)}}var _={new:we,list:me,open:ue,add:xe,try:async(e,t,o,i,n)=>(await import("./chunk-HATA2W7X.mjs")).pageTryCommand(e,{named:t,values:i,seconds:n,keep:o.has("--keep"),replace:o.has("--replace")}),check:async(e,t)=>(await import("./chunk-CPS4SRPF.mjs")).pageCheckCommand(e,t)},A=["--board","--x","--y","--w","--h"];async function Ie(e){try{return await Se(e)}catch(t){throw t instanceof d&&e.find(o=>!U(o))==="try"&&(t.synopsis=G),t}}async function Se(e){let{argv:t,seconds:o}=X(e),{argv:i,given:n}=ye(t),{positional:s,options:a,values:r}=q({options:["--no-browser","--keep","--replace"],values:[...A,...v],argv:i}),[c,...k]=s,h=Object.keys(_).join(", ");if(!c)throw new d(`Say what to do: ${h}.`);if(!Object.hasOwn(_,c))throw new d(`No such page command: ${c} (${h}).`);if(a.has("--no-browser")&&c!=="open")throw new d(`--no-browser goes with open, not ${c}.`);let m=[...v.filter(p=>r.has(p)),...Object.keys(o).filter(p=>!r.has(p)),...a.has("--keep")?["--keep"]:[],...a.has("--replace")?["--replace"]:[]];if(m.length&&c!=="try")throw new d(`${m[0]} goes with try, not ${c}.`);let u=A.filter(p=>r.has(p));if(u.length&&c!=="add")throw new d(`${u.join(", ")} go with add, not ${c}.`);if(n.length&&c!=="add")throw new d(`--set goes with add, not ${c}.`);return _[c](Z,k,a,new Map([...r].filter(([p])=>c==="try"?v.includes(p):A.includes(p))),o,n)}export{M as a,pe as b,fe as c,ne as d,ye as e,be as f,ke as g,Ie as h};
|
package/dist/chunk-AEMVZYZQ.mjs
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{a as Rn}from"./chunk-DR73Y2UJ.mjs";import{b as Tn}from"./chunk-CG3UHDKH.mjs";import{a as jn,i as _n,j as Pn}from"./chunk-4AMTKWDO.mjs";import{a as On,b as Cn}from"./chunk-QXVNUASA.mjs";import{k as Ge}from"./chunk-FCK6NXON.mjs";import{h as vn}from"./chunk-OU3S466R.mjs";import{a as $n}from"./chunk-CZ5KJSGK.mjs";import{a as En}from"./chunk-UGO5N3EI.mjs";import{a as Sn,b as bn}from"./chunk-5IIH335D.mjs";import{a as xn}from"./chunk-2OHANJ6Q.mjs";import{a as hn,b as Ke,d as gn,e as wn,f as yn,g as kn}from"./chunk-7M2BQQGZ.mjs";import{b as pt,e as Yt,g as ht,h as Xt,j as Vt,k as Zt}from"./chunk-VKSRM7EY.mjs";import{a as Wt,d as Mt,e as Ut,f as Bt,k as zt,l as Ht,m as Gt,r as Kt,t as ut,u as Jt}from"./chunk-LE44MD3O.mjs";import{b as sn,c as cn,d as je,e as ln,f as dn,g as He,i as fn,m as mn,p as un,q as pn}from"./chunk-XMKHCUI6.mjs";import{d as rn,e as Fe,f as Be,g as gt,h as an,k as ze}from"./chunk-YFJU3O7G.mjs";import{b as Qt,c as qt}from"./chunk-NWRZXELO.mjs";import{i as tn,j as nn,k as on}from"./chunk-G4YP7GVC.mjs";import{d as en}from"./chunk-DHB7UZ7F.mjs";import{a as Ne}from"./chunk-7XDYK3UC.mjs";import{c as ft,g as ae,j as At,k as Dt,p as Lt,q as It,v as Nt,w as mt}from"./chunk-VG5JEIUQ.mjs";import ct from"node:fs";import ms from"node:fs/promises";import us from"node:http";import{editStateDirectory as ps,kitPublicDirectory as hs,release as gs,releaseFile as lt,reportsDirectory as Te,vendorDirectory as ws,workbenchDirectory as ys}from"../browser/shared/paths.mjs";import{serve as Go}from"../browser/shared/http.mjs";import{ensureWorkspace as ks,layoutOf as vs}from"../browser/shared/workspace.mjs";import ge from"node:fs/promises";import H from"node:path";import{assetFile as Vo,referencedFile as Fn}from"../browser/shared/media.mjs";import{pageAssetAddress as Zo}from"../browser/shared/pages.mjs";function wt(e,n){if(!/assets\//i.test(e))return e;let t=nn(e,r=>Fn(r)!==null);return tn(e,on(t,r=>{let s=Fn(r.value);return Vo(s)?`${Zo(n,s)}${/[?#].*$/.exec(r.value.trim())?.[0]??""}`:null}))}function An(e,{reportsDirectory:n,kit:t,slug:r=null}={}){let{html:s,packages:f}=dn(r?wt(e,r):e,{reportsDirectory:n,kit:t,page:!0});return{html:s,packages:f}}import{Z as Qo}from"../browser/shared/layers.mjs";import{escapeMarkup as yt}from"../browser/shared/escape.mjs";import{layoutNotesScript as qo}from"../browser/shared/qa-levels.mjs";var Je=30,er=`
|
|
3
|
-
[data-doc-dev].doc-checks { position: fixed; z-index: ${Qo.checks}; left: 12px; bottom: 12px; max-width: min(520px, calc(100vw - 24px));
|
|
4
|
-
font: 13px/1.5 system-ui, sans-serif; color: light-dark(#37352f, #e3e2e0); }
|
|
5
|
-
[data-doc-dev].doc-checks[hidden] { display: none; }
|
|
6
|
-
[data-doc-dev].doc-checks > summary { display: inline-flex; gap: 6px; align-items: center; padding: 4px 10px; border-radius: 999px; cursor: pointer;
|
|
7
|
-
list-style: none; color: light-dark(#a1352b, #f19c92); background: light-dark(#fce9e7, #3b2321);
|
|
8
|
-
box-shadow: 0 0 0 1px light-dark(rgb(161 53 43 / 18%), rgb(241 156 146 / 22%)); user-select: none; }
|
|
9
|
-
[data-doc-dev].doc-checks > summary::-webkit-details-marker { display: none; }
|
|
10
|
-
[data-doc-dev].doc-checks > div { margin-top: 6px; padding: 8px 12px; max-height: 50vh; overflow: auto; border-radius: 10px;
|
|
11
|
-
background: light-dark(#ffffff, #252525); box-shadow: 0 0 0 1px light-dark(rgb(42 28 0 / 7%), #383836), 0 20px 24px light-dark(rgb(25 25 25 / 5%), rgb(0 0 0 / 20%)); }
|
|
12
|
-
[data-doc-dev].doc-checks ul { margin: 0; padding-left: 18px; }
|
|
13
|
-
[data-doc-dev].doc-checks li { margin: 2px 0; overflow-wrap: anywhere; }
|
|
14
|
-
[data-doc-dev].doc-checks p { margin: 6px 0 0; color: light-dark(#787774, #9b9a97); }
|
|
15
|
-
[data-doc-dev].doc-checks .doc-checks-live:not(:first-child) { margin-top: 8px; }
|
|
16
|
-
@media print { [data-doc-dev].doc-checks { display: none; } }`,tr=`(() => {
|
|
17
|
-
document.currentScript.remove();
|
|
18
|
-
${qo()}
|
|
19
|
-
const panel = document.querySelector("details.doc-checks[data-doc-dev]");
|
|
20
|
-
if (!panel) return;
|
|
21
|
-
const failures = Number(panel.dataset.failures) || 0;
|
|
22
|
-
const live = panel.querySelector(".doc-checks-live ul");
|
|
23
|
-
// The note's words in the UI's language (the root's data-ge-language).
|
|
24
|
-
const english = document.documentElement.getAttribute("data-ge-language") === "en";
|
|
25
|
-
const WORDS = english
|
|
26
|
-
? { card: "Chart card", table: "Table", named: (kind, name) => kind + " \u201C" + name + "\u201D", first: (name) => "Table (first column \u201C" + name + "\u201D)", colon: ": ",
|
|
27
|
-
failing: (count) => "Checks failed \xB7 " + count, more: (count) => count + " more", all: (slug) => "gallery check " + slug + " runs every check (TypeScript too)." }
|
|
28
|
-
: { card: "\u56FE\u8868\u5361\u7247", table: "\u8868\u683C", named: (kind, name) => kind + "\u300C" + name + "\u300D", first: (name) => "\u8868\u683C\uFF08\u9996\u5217\u300C" + name + "\u300D\uFF09", colon: "\uFF1A",
|
|
29
|
-
failing: (count) => "\u68C0\u67E5\u672A\u901A\u8FC7 \xB7 " + count + " \u9879", more: (count) => "\u8FD8\u6709 " + count + " \u9879", all: (slug) => "gallery check " + slug + " \u8DD1\u5168\u90E8\u68C0\u67E5\uFF08\u542B TypeScript\uFF09\u3002" };
|
|
30
|
-
const more = panel.querySelector("[data-more]");
|
|
31
|
-
if (more) more.textContent = WORDS.more(more.dataset.more);
|
|
32
|
-
const all = panel.querySelector("[data-all]");
|
|
33
|
-
if (all) all.textContent = WORDS.all(all.dataset.all);
|
|
34
|
-
const tidy = (node) => (node?.textContent ?? "").replace(/\\s+/g, " ").trim().slice(0, 40);
|
|
35
|
-
const what = (host) => {
|
|
36
|
-
const card = host.closest("figure");
|
|
37
|
-
const title = card?.querySelector(":scope > h3, :scope > figcaption");
|
|
38
|
-
const table = host.closest(".doc-table-wrap, table");
|
|
39
|
-
const caption = table?.querySelector("caption");
|
|
40
|
-
const header = table?.querySelector("th");
|
|
41
|
-
return title ? WORDS.named(WORDS.card, tidy(title)) : card ? WORDS.card : caption && tidy(caption) ? WORDS.named(WORDS.table, tidy(caption)) : header ? WORDS.first(tidy(header)) : host.localName;
|
|
42
|
-
};
|
|
43
|
-
// A chart that drew nothing says why in its card (the kit's line, in the same language): that line, else the note in words.
|
|
44
|
-
const said = (host, name, note) => (name === "data-missing" && tidy(host.querySelector(".doc-chart-message"))) || noteInWords(note, { english });
|
|
45
|
-
let shown = "";
|
|
46
|
-
let frame = 0;
|
|
47
|
-
const draw = () => {
|
|
48
|
-
frame = 0;
|
|
49
|
-
const notes = [...document.querySelectorAll("[data-doc-layout]")].filter((host) => !host.closest("[data-doc-dev]"))
|
|
50
|
-
.flatMap((host) => layoutNotesOf(host.getAttribute("data-doc-layout"), document.documentElement.clientWidth)
|
|
51
|
-
.filter(({ level }) => level === "fail")
|
|
52
|
-
.map(({ note, name }) => ({ line: what(host) + WORDS.colon + said(host, name, note), note })));
|
|
53
|
-
const key = notes.map(({ line }) => line).join("\\n");
|
|
54
|
-
if (key === shown) return;
|
|
55
|
-
shown = key;
|
|
56
|
-
live.replaceChildren(...notes.map(({ line, note }) => Object.assign(document.createElement("li"), { textContent: line, title: note })));
|
|
57
|
-
live.parentElement.hidden = notes.length === 0;
|
|
58
|
-
const failing = failures + notes.length;
|
|
59
|
-
panel.querySelector("summary").textContent = failing ? WORDS.failing(failing) : "";
|
|
60
|
-
panel.hidden = failing === 0;
|
|
61
|
-
};
|
|
62
|
-
const later = (records) => {
|
|
63
|
-
if (!globalThis.document?.defaultView) return; // the page is gone
|
|
64
|
-
if (!frame && records.some((record) => !record.target.closest?.("[data-doc-dev]"))) frame = requestAnimationFrame(draw);
|
|
65
|
-
};
|
|
66
|
-
new MutationObserver(later).observe(document.documentElement, { subtree: true, childList: true, attributes: true, attributeFilter: ["data-doc-layout"] });
|
|
67
|
-
addEventListener("resize", () => { if (!frame) frame = requestAnimationFrame(draw); });
|
|
68
|
-
draw();
|
|
69
|
-
})();`;function Dn(e,n,t={},{directory:r}={}){let s=fn({slug:e,html:n,metadata:t,...r?{directory:r}:{}}),f=s.slice(0,Je).map(p=>`<li>${yt(p)}</li>`).join(""),a=s.length>Je?`<p data-more="${s.length-Je}">\u8FD8\u6709 ${s.length-Je} \u9879</p>`:"",m=s.length?`<ul>${f}</ul>${a}<p data-all="${yt(e)}">gallery check ${yt(e)} \u8DD1\u5168\u90E8\u68C0\u67E5\uFF08\u542B TypeScript\uFF09\u3002</p>`:"";return`<details class="doc-checks" data-doc-dev data-failures="${s.length}"${s.length?"":" hidden"}><summary>${s.length?`\u68C0\u67E5\u672A\u901A\u8FC7 \xB7 ${s.length} \u9879`:""}</summary><div>${m}<div class="doc-checks-live" hidden><ul></ul></div></div><style>${er}</style></details>
|
|
70
|
-
<script data-doc-dev>${tr}</script>`}import{browserDirectory as Ea,editStateDirectory as Oa,kitSourceDirectory as Lo,release as Ca,reportsDirectory as D}from"../browser/shared/paths.mjs";import{FRAMED_BY as ja,sendJson as $o,serve as Tt,serveFound as De}from"../browser/shared/http.mjs";import{languageScript as So}from"../browser/shared/i18n/index.mjs";import{announcePreviewServer as _a,galleryVersion as Pa,sameDirectory as Ta}from"../browser/shared/preview-server.mjs";import{registerQuietly as Ra}from"../browser/shared/workspace-registry.mjs";import{lookWord as bo}from"../browser/shared/document-look.mjs";import{documentLook as Eo,ownLookAt as Fa}from"../browser/shared/workspace-look.mjs";import{slugPattern as Io}from"../browser/shared/reports.mjs";import{ATTRIBUTE as at,PACKAGE_ID as Aa}from"../browser/shared/components/installed.mjs";import{COMPONENTS_FOLDER as Oo,DOCUMENT_FOLDERS as Co,EXTENSIONS_FOLDER as Da,PAGES_FOLDER as La,WORKSPACE_FILE as st,defaultWorkspace as Ia,documentDirectory as _t,documentFiles as Na,isDocumentFile as Wa,isDocumentSource as jo,isSlugName as No,layoutOf as Rt}from"../browser/shared/workspace.mjs";import{PAGE_FILES as _o,homeCardsNew as Ma,isBlankPage as Ua,isPageFile as Ba,pageFiles as Po,pageHintShown as za,pageMetaNow as Ha,pageVersion as To}from"../browser/shared/pages.mjs";import{LINK_FILE as Ga}from"../browser/shared/web-links.mjs";import{SIDEBAR_FILE as ot}from"../browser/shared/extension-sidebar.mjs";import{extensionColumnIds as Ro}from"../browser/shared/extensions.mjs";import{isExtensionId as Ka}from"../browser/shared/outline-shape.mjs";import{createHash as hr,randomBytes as gr}from"node:crypto";import Q from"node:fs";import kt from"node:os";import he from"node:path";import{Transform as wr}from"node:stream";import{pipeline as yr}from"node:stream/promises";import{exportSourceOf as kr}from"../browser/shared/export-wrap.mjs";import{writeAtomic as vt}from"../browser/shared/files.mjs";import{sendJson as J}from"../browser/shared/http.mjs";import{said as xt,saying as vr}from"../browser/shared/i18n/index.mjs";import{IMPORT_LIMIT as Mn}from"../browser/shared/import-types.mjs";import{mediaUrl as xr}from"../browser/shared/media.mjs";import{fullAddress as $r}from"../browser/shared/page-address.mjs";import{documentLinks as Un,slugPattern as Bn}from"../browser/shared/reports.mjs";import{documentDirectory as Sr,documentFiles as zn,newDocSlug as br,pageSlug as Er}from"../browser/shared/workspace.mjs";import{readWritingPreferences as Or,saysAnything as Cr,unshownLines as jr}from"../browser/shared/writing-preferences.mjs";import Ln from"node:fs/promises";import lr from"node:path";import{Worker as nr}from"node:worker_threads";import{refusal as or,said as rr}from"../browser/shared/i18n/index.mjs";var ar=6e4,me=null,sr=0,Ye=0,_e=new Map;function ir(){me=new nr(new URL("./worker.mjs",import.meta.url)),me.on("message",({id:n,result:t,error:r})=>{let s=_e.get(n);s&&(_e.delete(n),r?s.reject(Object.assign(new Error(r.message),r)):s.resolve(t),_e.size===0&&(me?.unref(),cr()))});let e=n=>{for(let t of _e.values())t.reject(n);_e.clear(),me=null};me.on("error",e),me.on("exit",n=>e(or(rr("\u8F6C\u6362\u8FDB\u7A0B\u610F\u5916\u9000\u51FA\uFF08{0}\uFF09",n))))}function cr(){clearTimeout(Ye),Ye=setTimeout(()=>{if(_e.size===0&&me){let e=me;me=null,e.removeAllListeners("exit"),e.terminate()}},ar),Ye.unref?.()}function ve(e,n){clearTimeout(Ye),me||ir();let t=++sr;return new Promise((r,s)=>{_e.set(t,{resolve:r,reject:s}),me.ref(),me.postMessage({id:t,type:e,payload:n})})}import{pageLanguage as dr}from"../browser/shared/components/page.mjs";function Xe(e){return String(e??"").replace(/[\\/:*?"<>|\u0000-\u001f\u007f]/g," ").replace(/\s+/g," ").trim().slice(0,100).trim()||"Untitled"}function Ve(e,n){let t=e.lastIndexOf("."),[r,s]=t>0?[e.slice(0,t),e.slice(t)]:[e,""];for(let f=0;;f+=1){let a=f===0?e:`${r} ${f}${s}`;if(!n.has(a.toLowerCase()))return n.add(a.toLowerCase()),a}}function Ze(e,n){let t=e.split("/").slice(0,-1),r=n.split("/"),s=0;for(;s<t.length&&s<r.length-1&&t[s]===r[s];)s+=1;return[...t.slice(s).map(()=>".."),...r.slice(s)].map(a=>a===".."?a:encodeURIComponent(a).replace(/\(/g,"%28").replace(/\)/g,"%29")).join("/")}import{documentDirectory as fr,documentFiles as mr}from"../browser/shared/workspace.mjs";var In={markdown:"md",html:"html",pdf:"pdf"},ur={markdown:"text/markdown; charset=utf-8",html:"text/html; charset=utf-8",pdf:"application/pdf"},pr=e=>typeof e=="number"&&e>.1&&e<2;function Nn(e){let{format:n,content:t="everything",subpages:r=!1,folders:s=!0,paper:f="A4",scale:a=1}=e??{};return Object.hasOwn(In,n)&&["everything","no_files"].includes(t)&&typeof r=="boolean"&&typeof s=="boolean"&&["A4","A3","Letter","Legal","Tabloid"].includes(f)&&pr(a)}async function Wn(e,n,t){let{format:r,content:s="everything",subpages:f=!1,folders:a=!0,paper:m="A4",scale:c=1}=n,p=In[r],b=s==="everything",w=[],v=new Map,u=x=>v.get(x)??v.set(x,new Set).get(x),d=async(x,C)=>{let B=await t.titleOf(x),G=Ve(`${Xe(B)}.${p}`,u(C)),z=C?`${C}/${G}`:G,L=a?z.slice(0,-(p.length+1)):"";if(w.push({slug:x,title:B,file:z,folder:L,files:C?`${C}/assets`:"assets"}),f)for(let se of await t.childrenOf(x))await d(se,L)};await d(e,"");let{links:E}=await t.links(),$=(x,C)=>cn(C,x.slug,B=>{let G=r==="pdf"?null:w.find(z=>z.slug===B)?.file??null;return G&&Ze(x.file,G)},{blocks:r!=="markdown",links:E}),k=[],Y=[];for(let x of w)if(r==="markdown"){await t.check(x.slug);let C=fr(x.slug,t.reportsDirectory),B=je(await Ln.readFile(mr(C).html,"utf8"),{slug:x.slug,mode:"words",reportsDirectory:t.reportsDirectory}),G=$(x,B),z=b&&!!jn(),{text:L,files:se,charts:re,charted:U}=await ve("markdown",{source:G,title:x.title,pictures:z}),K=L,ce=new Map;if(se.forEach(({src:h,name:g},j)=>{ce.has(h)||(ce.set(h,`${x.files}/${Ve(Xe(g),u(x.files))}`),b&&Y.push({from:lr.join(C,h),name:ce.get(h)}));let _=ce.get(h);K=K.replace(`\0F${j}\0`,()=>Ze(x.file,_))}),z&&re>0&&K.includes("\0C")){let h=await Pn(await t.offline(x.slug,{files:!0})).catch(()=>[]);K=K.replace(/^.*\u0000C(\d+)\u0000.*$/gm,(g,j)=>{let _=h[Number(j)];if(!_)return"\0gone\0";let T=`${x.files}/${Ve(dr(G)==="en"?U[Number(j)]?"Chart.png":"Figure.png":U[Number(j)]?"\u56FE\u8868.png":"\u56FE.png",u(x.files))}`;return k.push({name:T,data:_,later:!0}),g.replace(`\0C${j}\0`,()=>Ze(x.file,T))}).replace(/\n*\u0000gone\u0000\n*/g,`
|
|
71
|
-
|
|
72
|
-
`).replace(/^\n+|\n+$/g,"")}k.push({name:x.file,data:K})}else r==="html"?k.push({name:x.file,data:$(x,await t.offline(x.slug,{files:b}))}):k.push({name:x.file,data:await _n($(x,await t.offline(x.slug,{files:b})),{paper:m,scale:c})});for(let x of Y){let C=await Ln.readFile(x.from).catch(()=>null);C&&k.push({name:x.name,data:C})}let M=[...k.filter(x=>!x.later&&w.some(C=>C.file===x.name)),...k.filter(x=>x.later||!w.some(C=>C.file===x.name))];return M.length===1?{name:M[0].name,type:ur[r],data:Buffer.isBuffer(M[0].data)?M[0].data:Buffer.from(M[0].data,"utf8")}:{name:`${Xe(w[0].title)}.zip`,type:"application/zip",data:xn(M)}}var _r=3600*1e3,$t=new Set,Hn=!1,Pr=e=>{$t.add(e),!Hn&&(Hn=!0,process.once("exit",()=>{for(let n of $t)try{Q.rmSync(n,{recursive:!0,force:!0})}catch{}}))},Tr=/^u-[a-f0-9]{16}$/;function Gn({edits:e,workspace:n,reports:t,reportsDirectory:r,offline:s}){let f=null,a=()=>f??=Q.promises.mkdtemp(he.join(kt.tmpdir(),"gallery-uploads-")).then(h=>(Pr(h),h)),m=new Map,c=(h,g,j)=>[h,{ok:!1,reason:g,...vr(j)}],p=h=>Q.promises.access(h).then(()=>!0,()=>!1),b=h=>Sr(h,r),w=h=>zn(b(h)),v=async h=>{try{return JSON.parse(await Q.promises.readFile(w(h).json,"utf8")).title||h}catch{return h}};function u(h){if(h.method!=="POST")return[405,{ok:!1,reason:"method"}];let g=h.headers.host??"",j=h.socket.localPort;return g!==`127.0.0.1:${j}`&&g!==`localhost:${j}`?[403,{ok:!1,reason:"host"}]:h.headers.origin!==`http://${g}`?[403,{ok:!1,reason:"origin"}]:h.headers["x-gallery-token"]!==e.token?[403,{ok:!1,reason:"token"}]:/^application\/octet-stream\b/i.test(h.headers["content-type"]??"")?Number(h.headers["content-length"]??0)>Mn?c(413,"size","\u6587\u4EF6\u592A\u5927\uFF08\u6700\u591A 5GB\uFF09"):null:[415,{ok:!1,reason:"type"}]}async function d(){for(let[h,g]of m)Date.now()-g.at<_r||(m.delete(h),await Q.promises.rm(g.file,{force:!0}).catch(()=>{}))}async function E(h,g){let j=u(h);if(j)return h.resume(),J(g,...j);let _=new URL(h.url,"http://localhost").searchParams.get("name")?.replace(/[\u0000-\u001f]/g,"").trim()??"";if(!_||_.length>255)return h.resume(),J(g,...c(400,"name","\u6587\u4EF6\u540D\u4E0D\u5BF9"));await d();let T=`u-${gr(8).toString("hex")}`,P=he.join(await a(),T),N=0,A=new wr({transform(I,Z,X){N+=I.length,X(N>Mn?Object.assign(new Error("too-large"),{reason:"size"}):null,I)}});try{await yr(h,A,Q.createWriteStream(P))}catch(I){return await Q.promises.rm(P,{force:!0}).catch(()=>{}),I.reason==="size"?J(g,...c(413,"size","\u6587\u4EF6\u592A\u5927\uFF08\u6700\u591A 5GB\uFF09")):J(g,...c(400,"body","\u6587\u4EF6\u6CA1\u6709\u4F20\u5B8C"))}return m.set(T,{file:P,name:_,at:Date.now()}),J(g,200,{ok:!0,id:T})}async function $(h,g){let j=await e.check(h);if(j.error)return J(g,...j.error);let{slug:_,options:T}=j.body??{};if(typeof _!="string"||!Bn.test(_)||!await p(w(_).html))return J(g,...c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"));if(!Nn(T))return J(g,...c(400,"options","\u5BFC\u51FA\u9009\u9879\u4E0D\u5BF9"));try{let P=await s(),N=new Map,A=R=>(N.has(R)||N.set(R,e.handIn(R,{reader:!0}).then(W=>{if(!W.ok)throw Object.assign(new Error(W.message??W.reason),{reason:W.reason});if(W.repeated.length)throw Object.assign(new Error("check"),{reason:"check",slug:R,failures:He(W.repeated)})})),N.get(R)),I=new Map,Z={reportsDirectory:r,titleOf:v,childrenOf:async R=>{let{children:W,links:ee=[]}=await n.outline(),te=we=>(W[we]??[]).flatMap(ye=>ee.includes(ye)||ye.startsWith("~")?te(ye):[ye]);return te(R)},links:()=>Un(r),offline:async(R,W)=>{await A(R);let ee=await P(R,W),te=T.format==="markdown"?null:kr(ee);return te&&I.set(R,te),ee},check:async R=>(await A(R),P.check(R))},{name:X,type:V,data:q}=await Wn(_,T,Z);I.size&&await(await Ge([...I.keys()])).keep([...I.keys()],I),g.writeHead(200,{"Content-Type":V,"Content-Length":q.length,"Content-Disposition":`attachment; filename*=UTF-8''${encodeURIComponent(X)}`,"X-File-Name":encodeURIComponent(X),"Cache-Control":"no-store"}),g.end(q)}catch(P){if(P.reason==="check"){let N=await v(P.slug),A=P.component?xt("\u300C{0}\u300D\u91CC\u7684\u7EC4\u4EF6 {1} \u6709\u9519\u8BEF\uFF0C\u6CA1\u6709\u751F\u6210\u6587\u4EF6\uFF1A\u53EF\u4EE5\u8BA9 AI \u68C0\u67E5\u8FD9\u4EFD\u6587\u6863\u5E76\u4FEE\u597D",N,P.component):P.failures.length>1?xt("\u300C{0}\u300D\u6CA1\u6709\u901A\u8FC7\u5BFC\u51FA\u524D\u7684\u68C0\u67E5\uFF0C\u6CA1\u6709\u751F\u6210\u6587\u4EF6\uFF1A{1}\uFF08\u5171 {2} \u5904\uFF1A\u53EF\u4EE5\u8BA9 AI \u68C0\u67E5\u8FD9\u4EFD\u6587\u6863\uFF0C\u5217\u51FA\u5168\u90E8\u5E76\u4FEE\u597D\uFF09",N,P.failures[0],P.failures.length):xt("\u300C{0}\u300D\u6CA1\u6709\u901A\u8FC7\u5BFC\u51FA\u524D\u7684\u68C0\u67E5\uFF0C\u6CA1\u6709\u751F\u6210\u6587\u4EF6\uFF1A{1}",N,P.failures[0]);return J(g,...c(422,"check",A))}J(g,...c(P.reason==="browser"?422:P.reason==="busy"?409:P.reason==="missing"?404:500,P.reason??"export",P))}}async function k(h,g){let j=await e.check(h);if(j.error)return J(g,...j.error);let{slug:_}=j.body??{},T=(await e.readTaken(_,{wait:0}))?.text??null;if(T===null)return J(g,...c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"));let P=`http://${h.headers.host}`,{named:N}=await Un(r),A=sn(je(T,{slug:_,mode:"words",reportsDirectory:r}),_,V=>V.slug&&$r(P,V,N),N),{text:I,files:Z}=await ve("markdown",{source:A,title:await v(_),pictures:!1}),X=I.replace(/\u0000F(\d+)\u0000/g,(V,q)=>{let{src:R,kind:W}=Z[Number(q)];return encodeURI(`${P}${xr(W==="image"?"asset":"file",_,R)}`)});return J(g,200,{ok:!0,text:X})}let Y=async h=>{let g=await e.readTaken(h,{wait:0});return{source:g?.text??"",version:g?.version??null}},M=async(h,g=null)=>{let{source:j,version:_}=g??await Y(h),T="\u5199\u4F5C\u504F\u597D",{text:P,files:N}=await ve("markdown",{source:j,title:T,pictures:!1}),A=P.split(`
|
|
73
|
-
`).slice(1).join(`
|
|
74
|
-
`).replace(/^[\s>]*(?:```.*|\d+\.|- \[x\])/gm,"").replace(/<\/?aside>/g,"");if(!/[\p{L}\p{N}]|\u0000F\d+\u0000/u.test(A))return{markdown:`# ${T}
|
|
75
|
-
`,empty:!0,version:_};let I=he.relative(r,b(h)).split(he.sep).join("/");return{markdown:`${P.replace(/\u0000F(\d+)\u0000/g,(Z,X)=>encodeURI(`${I}/${N[Number(X)].src}`))}
|
|
76
|
-
`,empty:!1,version:_}},x=h=>w(h).json,C=async h=>{try{let g=JSON.parse(await Q.promises.readFile(x(h),"utf8"));return g&&typeof g=="object"?g:null}catch{return null}},B=h=>hr("sha256").update(h).digest("hex").slice(0,16);async function G(h,g,j,_){let T=await C(h);if(!T||j===null)return;let{synced:P,...N}=T,A={file:B(g),page:j,unshown:_},I=T.madeSame;P===void 0&&I?.file===A.file&&I?.page===A.page&&JSON.stringify(I?.unshown)===JSON.stringify(_)||await vt(x(h),`${JSON.stringify({...N,madeSame:A},null,2)}
|
|
77
|
-
`)}async function z(h,g){let j=await Q.promises.mkdtemp(he.join(kt.tmpdir(),"gallery-preferences-"));try{let T=(await ve("import",{uploads:[{file:g,name:"preferences.md"}],scratch:j})).pages[0]??{nodes:[],raws:[],files:[],icon:null,lang:null},P=b(h),N=await C(h)??{},A=zn(P).html,I=await Q.promises.readFile(A,"utf8").catch(()=>""),Z=/<html\b[^>]*\slang="([^"]*)"/i.exec(I)?.[1]??null,{html:X}=await qt(h,N.title||"\u5199\u4F5C\u504F\u597D",N.description||"",{blank:!0,lang:Z}),V=typeof N.icon=="string"&&N.icon?N.icon:null,q=await ve("fill",{source:X,nodes:T.nodes,icon:V,raws:T.raws,lang:T.lang});T.files.length&&await Q.promises.mkdir(he.join(P,"assets"),{recursive:!0});for(let{from:W,name:ee}of T.files){let te=he.join(P,"assets",ee);await p(te)||await Q.promises.copyFile(W,te)}let R=await Q.promises.readFile(A,"utf8").catch(()=>null);R!==null&&e.keepVersion?.(h,R),await vt(A,ze(q))}finally{await Q.promises.rm(j,{recursive:!0,force:!0}).catch(()=>{})}}async function L(h,g){let j=await e.check(h);if(j.error)return J(g,...j.error);let _=j.body?.opening===!0,T=await Er(r);if(!T)return J(g,...c(404,"missing","\u8FD8\u6CA1\u6709\u5199\u4F5C\u504F\u597D"));let P=null,N=(A,I)=>[200,{ok:!0,path:he.resolve(P),remade:A,unshown:I}];return e.respond(async()=>{let A;({file:P,text:A}=await Or(r));let I=await Y(T),Z=(await C(T))?.madeSame??null,X=Z===null||Z.page===I.version,V=Z!==null&&X&&Z.file===B(A);if(_&&V&&Array.isArray(Z.unshown))return N(!1,Z.unshown);let[q,R,W,ee]=[A,"",I.version,!1];if(_&&!X)await z(T,P),{markdown:R,version:W}=await M(T),ee=!0;else{let we=await M(T,I),ye=A.trim()===we.markdown.trim()||we.empty&&!Cr(A);R=we.markdown,_?!ye&&!V&&(await z(T,P),{markdown:R,version:W}=await M(T),ee=!0):ye||(await vt(P,we.markdown),q=we.markdown)}let te=jr(q,R);return await G(T,q,W,te),N(ee,te)})(h,g)}async function se(h,g){let j=await e.check(h);if(j.error)return J(g,...j.error);let{uploads:_,parent:T="",from:P,language:N}=j.body??{},A={said:typeof P=="string"&&P.includes("{0}")&&P.length<=60?P:"\u5BFC\u5165\u81EA {0}",lang:N==="en"?"en":null};if(!Array.isArray(_)||_.length===0||_.length>1e3||!_.every(R=>typeof R=="string"&&Tr.test(R)))return J(g,...c(400,"body"));let I=_.map(R=>m.get(R)).filter(Boolean);if(I.length!==_.length)return J(g,...c(410,"gone","\u4E0A\u4F20\u7684\u6587\u4EF6\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u5BFC\u5165"));for(let R of _)m.delete(R);let Z=typeof T=="string"&&Bn.test(T)&&await p(he.join(r,T))?T:"",X=await Q.promises.mkdtemp(he.join(kt.tmpdir(),"gallery-import-")),V=()=>Promise.all([Q.promises.rm(X,{recursive:!0,force:!0}),...I.map(({file:R})=>Q.promises.rm(R,{force:!0}))]).catch(()=>{}),q;try{q=await ve("import",{uploads:I.map(({file:R,name:W})=>({file:R,name:W})),scratch:X})}catch(R){return await V(),J(g,...c(500,"convert",R))}return e.respond(async()=>{try{let{made:R,top:W}=await $n(q.pages,{create:t.create,slugOf:()=>br(r),folderOf:b,fill:ee=>ve("fill",ee),place:n.place,under:Z,...A});return[200,{ok:!0,pages:R.length,reports:W,skipped:q.skipped,missing:re(q.pages)}]}finally{await V()}})(h,g)}let re=h=>[...new Set(h.flatMap(function g(j){return[...(j.notes??[]).filter(_=>_.kind==="picture-missing").map(_=>_.name),...j.children.flatMap(g)]}))],U={export:$,markdown:k,upload:E,import:se,preferences:L};function K(h,g,j){return Object.hasOwn(U,j)?U[j](h,g).catch(_=>{g.headersSent||J(g,...c(500,"transfer",_))}):J(g,404,{ok:!1,reason:"unknown"})}async function ce(){let h=f;f=null,m.clear();let g=await h?.catch(()=>null);g&&($t.delete(g),await Q.promises.rm(g,{recursive:!0,force:!0}).catch(()=>{}))}return{handle:K,close:ce}}import{FACT_KINDS as Ja,QUERY_ROUTE as Ya,WORKSPACE_GLOBAL as Xa}from"../browser/shared/workspace-query.mjs";function Kn({settled:e,tell:n,delay:t=120,recheck:r=1e3}){let s=new Map,f=(a,m=t)=>{clearTimeout(s.get(a));let c=setTimeout(async()=>{let p=await e(a).catch(()=>({source:null,held:!1,wait:0}));if(s.get(a)===c){if(p.held)return f(a,Math.min(Math.max(p.wait,50),r));if(p.wait>0)return f(a,p.wait);await n(a,p)}},m);s.set(a,c)};return f}import xe from"node:fs";import Ee from"node:path";import{isExtensionId as Rr}from"../browser/shared/outline-shape.mjs";import{DOCUMENT_FOLDERS as Jn,isSlugName as St,layoutOf as Yn}from"../browser/shared/workspace.mjs";function Fr(e,n=!1,t=!1){let{components:r,gallery:s,preferencesPage:f,customPages:a,extensions:m}=Yn(e),c=(u,d)=>{try{return xe.readdirSync(u,{withFileTypes:!0}).filter(E=>E.isDirectory()&&d(E.name)).map(E=>Ee.join(u,E.name))}catch{return[]}},p=c(m,u=>Rr(u)&&!Jn.includes(u));if(n){let u=Ee.dirname(e);for(;!xe.existsSync(u)&&Ee.dirname(u)!==u;)u=Ee.dirname(u);return[u,e,...t?[s]:[],m,...p].filter(d=>xe.existsSync(d))}let b=[...c(e,u=>St(u)),...c(f,u=>St(u))],w=u=>[u,...c(u,d=>!d.startsWith(".")).flatMap(w)],v=c(a,u=>St(u)&&!Jn.includes(u));return[...new Set([e,...[s,f,a,m].filter(u=>xe.existsSync(u)),...v,...p,...b,...b.map(u=>Ee.join(u,"assets")).filter(u=>xe.existsSync(u)),...xe.existsSync(r)?w(r):[]])]}function Qe(e,n,{folders:t=process.platform==="linux",extensionsOnly:r=!1,outline:s=!1}={}){let f=bt(e),a=(v,u)=>{!(s&&u===Yn(e).outline)&&(f(u)||Ee.basename(u).startsWith("."))||xe.stat(u,(E,$)=>{if(E)return n(E.code==="ENOENT"?"unlink":"change",u);let k=$.isDirectory();n(v==="rename"?k?"addDir":"add":k?"addDir":"change",u)})},m=()=>{};if(!t&&!r)try{let v=xe.watch(e,{recursive:!0},(u,d)=>d?a(u,Ee.join(e,d.toString())):n("reset",e));return v.on("error",m),{close:()=>v.close()}}catch(v){if(v.code!=="ERR_FEATURE_UNAVAILABLE_ON_PLATFORM")throw v}let c=new Map,p=null,b=()=>{let v=new Set(Fr(e,r,s));for(let[u,d]of c)v.has(u)||(d.close(),c.delete(u));for(let u of v)if(!c.has(u))try{let d=xe.watch(u,(E,$)=>{if(!$)return n("reset",u);E==="rename"&&w(),a(E,Ee.join(u,$.toString()))});d.on("error",m),c.set(u,d)}catch{}},w=()=>{p??=setTimeout(()=>{p=null,b()},50)};return b(),{close(){clearTimeout(p);for(let v of c.values())v.close();c.clear()},get folders(){return[...c.keys()]}}}import Ar from"node:fs/promises";import{packageScript as Dr}from"../browser/shared/export-wrap.mjs";import{serveFound as Lr}from"../browser/shared/http.mjs";import{extensionOf as Ir,mediaTypeOf as Nr}from"../browser/shared/media.mjs";var Wr="/__gallery/components/",Mr=/^\/__gallery\/components\/([a-z0-9][a-z0-9-]*\/[a-z0-9][a-z0-9-]*)\/(.+)$/,Ur={js:"text/javascript; charset=utf-8",mjs:"text/javascript; charset=utf-8",css:"text/css; charset=utf-8",wasm:"application/wasm"};async function Xn(e,n,t,{root:r}){if(!e.startsWith(Wr))return!1;let[,s,f]=Mr.exec(e)??[],a=s?ae(r).packages.get(s):null,m=a?.files.includes(f)?Lt(a,f):null,c=m?await Ar.readFile(m).catch(()=>null):null,p=c&&f==="kit.js"?Buffer.from(Dr(c.toString("utf8").replace(/^\uFEFF/,""))):c,b=p&&n===a.stamp&&n===It(a);return Lr(t,p,{type:p?Ur[Ir(f)]??Nr(f):void 0,headers:{"X-Content-Type-Options":"nosniff","Cache-Control":b?"max-age=31536000, immutable":"no-store"}}),!0}import{BLOCK_ICON as Br}from"../browser/editor/components/icons.mjs";import{LISTED_BLOCKS as Vn}from"../browser/editor/components/registry.mjs";import{PACKAGE_ID as zr}from"../browser/shared/components/installed.mjs";import{netHostsOf as Zn}from"../browser/shared/net-policy.mjs";import{inLanguage as Qn,refusal as qe,said as Oe}from"../browser/shared/i18n/index.mjs";function qn({root:e,taken:n}){let t=()=>{let a=ae(e);return{packages:Nt(a).map(m=>{let c=Bt(m.id)?Ut(m.id):null;return{...m,newer:c?zt(e,c):null,...c?{addAs:c.pack===Wt?c.name:c.id}:{}}}),packs:ut(e,{settings:a.settings}),packageIcon:Br,blocks:Vn.map(({id:m,name:c,icon:p,hideable:b})=>({id:m,name:{zh:Qn("zh",c),en:Qn("en",c)},icon:p,hidden:b&&a.settings.hidden.includes(m),hideable:b})),problem:Dt(a)}},r=({id:a,hidden:m,shown:c,disabled:p,unlisted:b,net:w})=>{if(![m,c,p,b,w].every(u=>u===void 0||typeof u=="boolean"))return Oe("\u5F00\u5173\u7684\u503C\u4E0D\u5BF9");let v=Vn.find(u=>u.id===a);return v?p!==void 0||c!==void 0||b!==void 0||w!==void 0?Oe("\u5185\u7F6E\u5757\u53EA\u80FD\u9690\u85CF\uFF0C\u4E0D\u80FD\u505C\u7528"):m&&!v.hideable?Oe("\u8FD9\u4E2A\u5757\u4E0D\u80FD\u9690\u85CF"):null:typeof a=="string"&&zr.test(a)?w&&Zn(ae(e).packages.get(a)?.needs).length===0?Oe("\u8FD9\u4E2A\u5757\u4E0D\u8054\u7F51"):null:Oe("\u6CA1\u6709\u8FD9\u4E2A\u7EC4\u4EF6")};return{read:t,write:async a=>{if(a?.pack!==void 0){let{pack:w,enabled:v}=a;if(typeof v!="boolean")throw qe(Oe("\u5F00\u5173\u7684\u503C\u4E0D\u5BF9"));if(typeof w!="string"||!ut(e,{settings:ae(e).settings}).some(({id:u})=>u===w))throw qe(Oe("\u6CA1\u6709\u8FD9\u4E2A\u5757\u5305"));return await ft(e,{pack:w,enabled:v}),n(),t()}let m=r(a);if(m)throw qe(m);let{net:c,...p}=a,b=c===void 0?void 0:c?Zn(ae(e).packages.get(a.id)?.needs):[];return await ft(e,{...p,...b?{net:b}:{}}),n(),t()},install:({path:a,zip:m}={})=>{let c=typeof m=="string"?Cn(Buffer.from(m,"base64")):typeof a=="string"&&a.trim()?On(a):null;if(!c)throw qe(Oe("\u7C98\u8D34\u5757\u5305\u7684\u6587\u4EF6\u5939\u6216 zip \u7684\u8DEF\u5F84"),{code:"path"});let p=Kt(e,c);return n(),{...t(),installed:p}}}}import Hr from"node:path";import{exportsDirectory as Gr}from"../browser/shared/paths.mjs";async function eo(e,n,{workspace:t=null}={}){let r=Hr.join(Gr,`${n}.html`),s=await Ge([n]),f=await e.handInReport(n,{reader:!0});if(!f.ok)return{problems:[],refused:{reason:f.reason,message:f.message},file:r};if(f.repeated.length)return{problems:He(f.repeated),file:r};let{exported:a,failures:m}=await pn([n],{workspace:t});return await s.keep(a.map(c=>c.slug)),{problems:m.get(n)??[],file:r}}import to from"node:fs/promises";import no from"node:path";import{MEDIA_ROUTES as oo,assetFile as Kr,extensionOf as Jr,imageFile as Yr,mediaTypeOf as Xr}from"../browser/shared/media.mjs";import{serveFound as ro}from"../browser/shared/http.mjs";import{slugPattern as ao}from"../browser/shared/reports.mjs";import{pageFiles as Vr}from"../browser/shared/pages.mjs";import{documentDirectory as Zr}from"../browser/shared/workspace.mjs";var Et={asset:e=>({"Content-Type":Xr(e),"Cache-Control":"no-cache"}),file:()=>({"Content-Type":"application/octet-stream","Content-Disposition":"attachment","X-Content-Type-Options":"nosniff","Cache-Control":"no-cache"}),embed:e=>/\.pdf$/i.test(e)?{"Content-Type":"application/pdf","X-Content-Type-Options":"nosniff","Cache-Control":"no-cache"}:{"Content-Type":"text/html; charset=utf-8","Content-Security-Policy":"sandbox allow-scripts allow-popups allow-forms allow-modals","X-Content-Type-Options":"nosniff","Cache-Control":"no-cache"}},Qr=new RegExp(`^/__gallery/edit/(${Object.keys(oo).join("|")})/([^/]+)/(assets/[^/]+)$`);async function so(e,n,{reportsDirectory:t}){let[,r,s,f]=Qr.exec(e)??[];if(!r)return!1;let a=ao.test(s)&&oo[r](f)?await to.readFile(no.join(Zr(s,t),f)).catch(()=>null):null;return ro(n,a,{headers:Et[r](f)}),!0}var qr={css:"text/css; charset=utf-8",js:"text/javascript; charset=utf-8",mjs:"text/javascript; charset=utf-8"},ea=/^\/pages\/([^/]+)\/(assets\/[^/]+)$/;async function io(e,n,{reportsDirectory:t}){let[,r,s]=ea.exec(e)??[];if(!r)return!1;let f=ao.test(r)&&Kr(s)?await to.readFile(no.join(Vr(r,t).folder,s)).catch(()=>null):null,a=qr[Jr(s??"")];return ro(n,f,{headers:a?{"Content-Type":a,"X-Content-Type-Options":"nosniff","Cache-Control":"no-cache"}:(Yr(s)?Et.asset:Et.file)(s)}),!0}import ta from"node:dns";import{sendJson as Ae}from"../browser/shared/http.mjs";import{createNetCache as na,dataOf as oa}from"../browser/shared/net-cache.mjs";import{readKeys as ra}from"../browser/shared/net-keys.mjs";import{addressKind as tt,addressOf as go,hostIn as co,keptHere as lo,keyIn as fo,mapsHere as aa,netHostsOf as sa,proxyHere as ia,withKey as ca}from"../browser/shared/net-policy.mjs";import{galleryVersion as la}from"../browser/shared/preview-server.mjs";var et=512*1024,da=6e4,mo=20,uo=5,po=1e4,fa=16*1024,ma=new Set([301,302,303,307,308]),ua=/^(?:application\/(?:[\w.-]+\+)?json|text\/[\w.+-]+)$/i,$e=(e,n={})=>({ok:!1,code:e,...n}),oe=(e,n={},t)=>Object.assign(new Error(e),{refusal:$e(e,n),...t===void 0?{}:{detail:t}});function pa(e,n){let t;try{t=new URL(e,n)}catch{return{code:"url",why:"a redirect to an address that does not parse"}}let r=go(t.href);return r.code?{code:"url",why:`a redirect to ${t.host?`${t.protocol}//${t.host}`:t.protocol}: ${r.why}`}:r}function ho(e,n){let t=[...new Set([n,encodeURIComponent(n)])].filter(Boolean),r=s=>typeof s=="string"?t.reduce((f,a)=>f.split(a).join("{key}"),s):s;return Object.fromEntries(Object.entries(e).map(([s,f])=>[s,r(f)]))}var ha=e=>ta.promises.lookup(e,{all:!0,verbatim:!0}),Ot=e=>URL.parse(e)?.host||"?",Ct=e=>tt(e)==="fake-ip"?"an address a fake-ip proxy's DNS gives":"an address of this computer or of a private network";async function ga(e,{resolve:n,proxy:t}){let r=e.hostname,s=ia(t),f=d=>{let E=tt(d);return E==="public"||E==="fake-ip"&&s},a=r.replace(/^\[|\]$/g,"");if(tt(a)!=="none"){if(f(a))return{address:a};throw oe("private",{host:r,address:a,why:`${a} is ${Ct(a)}`})}let m;try{m=(await n(r)).map(d=>typeof d=="string"?d:d.address)}catch(d){throw oe("offline",{why:`${r} did not resolve (${d.code??d.message})`})}if(m.length===0)throw oe("offline",{why:`${r} did not resolve`});let c=m.filter(d=>!f(d));if(c.length===0)return{address:m[0]};let p=c.filter(d=>!aa(d)),b=p.length?p:c,w=b.find(d=>!d.includes(":"))??b[0],v=`${r} resolved to ${w}, ${Ct(w)}`,u=lo(r)?"and its name is one kept for this computer (localhost)":t?s?e.protocol!=="https:"?"and an http address is never handed to a proxy by its name (no TLS to check the site)":p.length?"and a private network's address is never handed to a proxy by its name (that network's own machines are there)":null:"and the proxy it goes through is not on this computer":"and no proxy of this computer goes between to reach it by its name";if(u===null)return{address:null,resolved:w,said:v};throw oe("private",{host:r,address:w,why:`${v}, ${u}`},s||!t||lo(r)?void 0:`${v}, and the proxy it goes through (${Ot(t)}) is not on this computer`)}var wa=({resolve:e=ha,proxyFor:n=hn,connect:t,ca:r}={})=>async(s,{headers:f,signal:a})=>{let m=await n(s.href),c=await ga(s,{resolve:e,proxy:m}),{address:p}=c,b={...t?{connect:t}:{},...r?{ca:r}:{}};try{return await Ke(s,{address:p,proxy:m,headers:f,signal:a,...b})}catch(w){if(!(m&&w.proxyFailed&&(p!==null||w.code==="ECONNREFUSED")))throw p===null&&!a?.aborted?oe("offline",{why:`${c.said}, and no site the proxy of this computer reached by its name proved to be it`},`${c.said}, handed by its name to the proxy (${Ot(m)}): ${w.code??w.message}`):w;let v=d=>`and the proxy of this computer that would reach it${d?` (${Ot(m)})`:""} is not running`,u=p===null?c.said:`${s.hostname.replace(/^\[|\]$/g,"")===p?p:`${s.hostname} resolved to ${p}`}, ${Ct(p)}`;if(p===null||tt(p)!=="public")throw oe("private",{host:s.hostname,address:p??c.resolved,why:`${u}, ${v(!1)}`},`${u}, ${v(!0)}`);return Ke(s,{address:p,proxy:null,headers:f,signal:a,...b})}},wo=e=>(n,{headers:t,signal:r})=>Ke(new URL(`http://127.0.0.1:${e}/${n.protocol.slice(0,-1)}/${n.host}${n.pathname}${n.search}`),{address:"127.0.0.1",headers:t,signal:r});async function ya(e){let n=0,t=[];for await(let r of e){if(n+=r.length,n>fa)throw Object.assign(new Error("too-large"),{status:413});t.push(r)}return JSON.parse(Buffer.concat(t).toString("utf8"))}function ka(e,n){let t=/;\s*charset="?([^";]+)"?/i.exec(n)?.[1];try{return new TextDecoder(t||"utf-8").decode(e)}catch{return new TextDecoder("utf-8").decode(e)}}function yo({root:e,catalog:n=()=>ae(e),hop:t=null,now:r=Date.now,cache:s=na(e),log:f=()=>{}}){let a=t??wa(),m=new Map,c=d=>{let E=r(),$=(m.get(d)??[]).filter(k=>E-k<6e4);return $.length>=mo?(m.set(d,$),!1):(m.set(d,[...$,E]),!0)},p={accept:"application/json, text/plain;q=0.9, text/*;q=0.8","user-agent":`Gallery/${la} (a custom block's card)`};async function b(d,{hosts:E,allowed:$,key:k}){let Y=AbortSignal.timeout(po),M=d;for(let x=0;;x++){let C;try{C=await a(k===void 0?M:new URL(ca(M.href,k)),{headers:p,signal:Y})}catch(L){throw L.refusal?L:oe("offline",{why:Y.aborted?`no answer within ${po/1e3} s`:String(L.code??L.message)})}if(ma.has(C.status)&&C.headers.get("location")){if(C.body?.cancel().catch(()=>{}),x>=uo)throw oe("status",{status:C.status,why:`more than ${uo} redirects`});let L=pa(C.headers.get("location"),M);if(L.code)throw oe("url",{why:L.why});let se=co(L.url.hostname,E);if(!se)throw oe("host",{host:L.url.hostname,why:`a redirect to ${L.url.hostname}, which the block's needs do not name`});if(!$.includes(se))throw oe("consent",{hosts:E.filter(re=>!$.includes(re))});M=L.url,k=fo(M.href)?k:void 0;continue}if(C.status<200||C.status>299)throw C.body?.cancel().catch(()=>{}),oe("status",{status:C.status});let B=C.headers.get("content-type")??"",G=B.split(";")[0].trim();if(G&&!ua.test(G))throw C.body?.cancel().catch(()=>{}),oe("type",{type:G});if(Number(C.headers.get("content-length"))>et)throw C.body?.cancel().catch(()=>{}),oe("too-large",{limit:et});let z;try{z=C.body?await gn(C,et):Buffer.alloc(0)}catch(L){throw oe("offline",{why:String(L.code??L.message)})}if(z===null)throw oe("too-large",{limit:et});return{type:G||"text/plain",text:ka(z,B)}}}let w=(d,E,$)=>{let k=oa(d,E);return k===void 0?$e("type",{why:"the answer is no JSON"}):{ok:!0,data:k,at:d.at,cached:$}};async function v(d){let{block:E,url:$,as:k="json",doc:Y=null}=d??{},M=typeof E=="string"?n().packages.get(E):null;if(!M)return $e("missing",{why:"no custom block of that id loads in this workspace"});let x=sa(M.needs);if(k!=="json"&&k!=="text")return $e("url",{why:'as is "json" or "text"'});let C=go($);if(C.code)return $e("url",{why:C.why});let{url:B}=C,G=co(B.hostname,x);if(!G)return $e("host",{host:B.hostname,why:x.length?`its needs name ${x.join(", ")}`:"its needs name no host of the net"});let z=n().settings.net?.[E]??[];if(!z.includes(G))return $e("consent",{hosts:x.filter(U=>!z.includes(U))});let L;if(fo(B.href)){let U=ra(e);if(L=U[B.hostname]??U[G],L===void 0)return $e("key",{host:B.hostname})}let se=B.href,re=s.get(se);if(s.used(se,Y,k),re&&r()-Date.parse(re.at)<da)return w(re,k,!0);if(!c(E))return re?w(re,k,!0):$e("rate",{why:`more than ${mo} fetches in a minute`});try{let{type:U,text:K}=await b(B,{hosts:x,allowed:z,key:L});return w(s.put(se,{type:U,text:K,at:new Date(r()).toISOString()}),k,!1)}catch(U){if(!U.refusal)throw U;if(re&&U.refusal.code!=="consent")return w(re,k,!0);let K=L===void 0?U.refusal:ho(U.refusal,L),ce=U.detail===void 0?K.why:L===void 0?U.detail:ho({why:U.detail},L).why;return(K.code!=="offline"||U.detail!==void 0)&&f(`${E}: ${B.hostname} refused (${K.code}${ce?`: ${ce}`:""})`),K}}async function u(d,E){if(d.method!=="POST")return Ae(E,405,{ok:!1,reason:"method"});if(d.headers.origin!==`http://${d.headers.host}`)return Ae(E,403,{ok:!1,reason:"origin"});if(!/^application\/json\b/i.test(d.headers["content-type"]??""))return Ae(E,415,{ok:!1,reason:"type"});let $;try{$=await ya(d)}catch(k){return Ae(E,k.status??400,{ok:!1,reason:"body"})}try{return Ae(E,200,await v($))}catch(k){return Ae(E,500,{ok:!1,code:"offline",why:k.message})}}return{handle:u,answer:v,cache:s}}function ko({max:e=20}={}){let n=new Map;return{get(t,r,s){let f=`${t} ${r}`,a=n.get(f);return!a||a.text!==s?null:(n.delete(f),n.set(f,a),a.page)},set(t,r,s,f){let a=`${t} ${r}`;for(n.delete(a),n.set(a,{slug:t,text:s,page:f});n.size>e;)n.delete(n.keys().next().value)},clear(){n.clear()},forget(t){for(let[r,s]of n)s.slug===t&&n.delete(r)},get size(){return n.size}}}import{createHash as va}from"node:crypto";import{readFileSync as xa}from"node:fs";import vo from"node:fs/promises";import $a from"node:path";import{release as Sa,releaseFile as ba}from"../browser/shared/paths.mjs";async function nt(e){let n=await Promise.all(e.map(r=>vo.stat(r).then(({mtimeMs:s,size:f})=>`${s} ${f}`,()=>"none"))),t=va("sha256");return e.forEach((r,s)=>t.update(`${r}\0${n[s]}
|
|
78
|
-
`)),t.digest("hex").slice(0,16)}function xo(e,n){let t=null,r=async()=>(await Promise.all(e.map(async s=>(await vo.readdir(s,{recursive:!0,withFileTypes:!0}).catch(()=>[])).filter(a=>a.isFile()).map(a=>$a.join(a.parentPath,a.name))))).flat().filter(n).sort();return{files:()=>t??=r(),changed:()=>{t=null}}}var jt=Sa?JSON.parse(xa(ba,"utf8")).stamps:null;var it=Io.source.slice(1,-1),Va=new RegExp(`^/generated/(${it})\\.html$`),Za=new RegExp(`^/(${it})/(?:doc|report)\\.html$`),Qa=new RegExp(`^/pages/(${it})$`),qa=new RegExp(`^/__gallery/pages/(${it})/(cards|library|hint)$`),Ft="/__gallery/events",Pe=Ea,Wo=/^\/__gallery\/edit\/(v\/[a-f0-9]{16}\/)?src\/((?:shared(?:\/components|\/emoji|\/i18n)?\/|editor\/(?:page|components)(?:\/[a-z]+(?:-[a-z]+)*){0,2}\/(?!files?\.mjs))[a-z]+(?:-[a-z]+)*\.mjs)$/,es=/^\/__gallery\/edit\/(?:v\/[a-f0-9]{16}\/)?src\/(shared\/emoji\/data\/[a-z]+(?:-[a-z]+)*\.(json|bin))$/,rt=[H.join(Pe,"editor","page"),H.join(Pe,"editor","components"),H.join(Pe,"shared")],ts=e=>Wo.test(`/__gallery/edit/src/${H.relative(Pe,e).split(H.sep).join("/")}`);var ns=[Lo,H.join(Pe,"shared","components")],ll=[Lo,...rt],We={"Cache-Control":"no-store"},Fo={"Cache-Control":"max-age=31536000, immutable"},Pt=(e,n,t)=>Tt(e,{type:n,headers:{...We,...ja},body:t});function os(e){let n=e.headers?.host??"",t=e.socket?.localPort;return!!t&&(n===`127.0.0.1:${t}`||n===`localhost:${t}`)}function rs(e){if(e.method!=="GET"&&e.method!=="HEAD")return null;let n=e.socket?.localPort;if(!n||e.headers?.host!==`localhost:${n}`)return null;let t=new URL(e.url||"/","http://localhost");return t.pathname==="/"||t.pathname==="/index.html"?`http://127.0.0.1:${n}${t.pathname}${t.search}`:null}var Mo=`window.addEventListener("doc-net-fetch", (event) => {
|
|
79
|
-
event.preventDefault();
|
|
80
|
-
event.detail.answer(fetch("/__gallery/net", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(event.detail.ask) }).then((response) => response.json()));
|
|
81
|
-
});`,Uo=`let lost = false;
|
|
82
|
-
events.onerror = () => { lost = true; };
|
|
83
|
-
events.onopen = () => {
|
|
84
|
-
if (!lost) return;
|
|
85
|
-
lost = false;
|
|
86
|
-
for (const kind of ${JSON.stringify(Ja)}) window.dispatchEvent(new CustomEvent("doc-workspace-change", { detail: kind }));
|
|
87
|
-
};`,as=(e,n,t)=>`<script>
|
|
88
|
-
(() => {
|
|
89
|
-
document.currentScript.remove();
|
|
90
|
-
${Mo}
|
|
91
|
-
const solo = new URLSearchParams(location.search).has("solo");
|
|
92
|
-
let catalog = "${t}";
|
|
93
|
-
const holds = (ids) => document.querySelector(ids === undefined ? "[${at}]" : ids.split(",").map((id) => '[${at}="' + id + '"]').join());
|
|
94
|
-
const events = new EventSource("${Ft}?slug=${e}");
|
|
95
|
-
${Uo}
|
|
96
|
-
events.onmessage = (event) => {
|
|
97
|
-
const [kind, next, ids, more, consents, unlisted, packs] = event.data.split(" ");
|
|
98
|
-
if (kind === "notes") return void window.dispatchEvent(new CustomEvent("doc-annotations-changed", { detail: { version: next ?? "" } }));
|
|
99
|
-
if (kind === "changes") return void window.dispatchEvent(new CustomEvent("doc-changes-changed", { detail: { stamp: next ?? "" } }));
|
|
100
|
-
if (kind === "look") return void window.dispatchEvent(new CustomEvent("doc-look-request", { detail: { look: Object.fromEntries(new URLSearchParams(next ?? "")), from: "file" } }));
|
|
101
|
-
if (kind === "settings") return void window.dispatchEvent(new CustomEvent("doc-settings-changed", { detail: { hidden: next ? next.split(",") : [], disabled: ids ? ids.split(",") : [], shown: more ? more.split(",") : [], net: consents ? consents.split(",") : [], unlisted: unlisted ? unlisted.split(",") : [], packsOff: packs ? packs.split(",") : [] } }));
|
|
102
|
-
if (kind === "data") return void window.dispatchEvent(new CustomEvent("doc-workspace-change", { detail: next ?? "" }));
|
|
103
|
-
if (kind !== "report" && kind !== "assets" && kind !== "components") return;
|
|
104
|
-
if (kind === "components") {
|
|
105
|
-
if (document.readyState === "loading") return void document.addEventListener("DOMContentLoaded", () => events.onmessage(event), { once: true });
|
|
106
|
-
if (solo || next === catalog) return;
|
|
107
|
-
catalog = next;
|
|
108
|
-
if (!holds(ids)) return void window.dispatchEvent(new CustomEvent("doc-catalog-changed", { detail: { ids: ids === undefined ? null : ids.split(",").filter(Boolean) } }));
|
|
109
|
-
}
|
|
110
|
-
if (window.__galleryEditBusy) {
|
|
111
|
-
window.dispatchEvent(new CustomEvent({ report: "doc-source-changed", assets: "doc-assets-changed", components: "doc-components-changed" }[kind], { detail: { version: next ?? null } }));
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
if (kind === "report" && next === "${n}") return;
|
|
115
|
-
if (window.__galleryEditReload) return window.__galleryEditReload(); // in a workbench: swapped in, no reload seen
|
|
116
|
-
location.reload();
|
|
117
|
-
};
|
|
118
|
-
})();
|
|
119
|
-
</script>`,ss=(e,n,t)=>`<script>
|
|
120
|
-
(() => {
|
|
121
|
-
document.currentScript.remove();
|
|
122
|
-
${Mo}
|
|
123
|
-
let catalog = "${t}";
|
|
124
|
-
const holds = (ids) => {
|
|
125
|
-
const named = ids === undefined ? "[${at}]" : ids.split(",").filter(Boolean).map((id) => '[${at}="' + id + '"]').join() || ":not(*)";
|
|
126
|
-
return Boolean(document.querySelector(named)) || [...document.querySelectorAll("template[data-ge-held]")].some((held) => held.content.querySelector(named));
|
|
127
|
-
};
|
|
128
|
-
const again = () => (window.__galleryEditReload ? window.__galleryEditReload() : location.reload());
|
|
129
|
-
const events = new EventSource("${Ft}?page=${e}");
|
|
130
|
-
${Uo}
|
|
131
|
-
events.onmessage = (event) => {
|
|
132
|
-
const [kind, next, ids, more, consents, unlisted, packs] = event.data.split(" ");
|
|
133
|
-
if (kind === "page") return void (window.__galleryPageChanged ? window.__galleryPageChanged(next) : next !== "${n}" && again());
|
|
134
|
-
if (kind === "assets") return void again();
|
|
135
|
-
if (kind === "settings") return void window.dispatchEvent(new CustomEvent("doc-settings-changed", { detail: { hidden: next ? next.split(",") : [], disabled: ids ? ids.split(",") : [], shown: more ? more.split(",") : [], net: consents ? consents.split(",") : [], unlisted: unlisted ? unlisted.split(",") : [], packsOff: packs ? packs.split(",") : [] } }));
|
|
136
|
-
if (kind === "data") return void window.dispatchEvent(new CustomEvent("doc-workspace-change", { detail: next ?? "" }));
|
|
137
|
-
if (kind !== "components") return;
|
|
138
|
-
if (document.readyState === "loading") return void document.addEventListener("DOMContentLoaded", () => events.onmessage(event), { once: true });
|
|
139
|
-
if (next === catalog) return;
|
|
140
|
-
catalog = next;
|
|
141
|
-
if (holds(ids)) again();
|
|
142
|
-
};
|
|
143
|
-
})();
|
|
144
|
-
</script>`;function Ao(e,n){let t=H.relative(e,n).split(H.sep);if(t[0]===".."||H.isAbsolute(t[0])||t[0]==="")return null;if(t.length===1&&t[0]===st)return{slug:null,name:st,packages:!0};let r=c=>process.platform==="win32"?c.toLowerCase():c;if(r(t[0])===Da&&t.length>=2&&Ka(t[1])&&!Co.includes(t[1])){let c=t.slice(2);return c.some(p=>p.startsWith("."))?null:{extension:t[1],name:c.length===1?c[0]:null}}if(r(t[0])===La&&t.length>=2&&No(t[1])&&!Co.includes(t[1])){let c=t.slice(2);return c.some(p=>p.startsWith("."))?null:{page:t[1],name:c.length===1?c[0]:null}}let s=t[0]===".gallery"&&t[1]==="pages"&&t.length>=3,[f,...a]=s?t.slice(2):t,m=!s&&r(f)===Oo;return!(m||Io.test(f))||f==="exports"||a.some(c=>c.startsWith("."))?null:{slug:m?Oo:f,name:a.length===1?a[0]:null,...m?{packages:m}:{}}}function bt(e){let n=w=>process.platform==="win32"?H.resolve(w).toLowerCase():H.resolve(w),{gallery:t,preferencesPage:r,exports:s,extensions:f}=Rt(e),[a,m,c,p]=[n(t),n(r),n(s),n(f)],b=(w,v)=>w===v||w.startsWith(v+H.sep);return w=>{let v=n(w);return b(v,p)&&v!==p&&v.slice(p.length+1).split(H.sep).some((u,d)=>d>0&&(u==="node_modules"||u===".git"))?!0:b(v,a)&&v!==a&&!b(v,m)||b(v,c)}}var Do=`<script data-doc-dev>document.currentScript.remove(); globalThis.${Xa} = ${JSON.stringify(Ya)};</script>`,ue=(e,n,t)=>new RegExp(`</${n}>`,"i").test(e)?e.replace(new RegExp(`</${n}>`,"i"),()=>` ${t}
|
|
145
|
-
</${n}>`):`${e}
|
|
146
|
-
${t}`;function Bo({stateDirectory:e=Oa,logger:n=console,kind:t="dev",workbenchPage:r=null,closeServer:s=async()=>{},exit:f=()=>process.exit(0)}={}){let a=new Set,m=(o,i="",l="report")=>{for(let S of a)(!o||S.slug===o)&&S.response.write(`data: ${o?`${l} ${i}`:"assets"}
|
|
147
|
-
|
|
148
|
-
`)},c=(o,i)=>{for(let l of a)l.page===o&&l.response.write(`data: page ${i}
|
|
149
|
-
|
|
150
|
-
`)},p=!1,b=o=>{p||=o,A("workspace",()=>{let i=p;p=!1;for(let l of a)l.workspace&&(i||!l.ownOnly)&&l.response.write(`data: workspace ${Date.now()}
|
|
151
|
-
|
|
152
|
-
`)})},w=()=>b(!0),v=()=>b(!1),u=o=>m(o,String(Date.now()),"changes"),d=vn({stateDirectory:e,finish:ze,log:o=>n.info?.(`[gallery] ${o}`),onChanges:u}),E=(o,i,l,{lang:S=null,page:F=!1}={})=>Qt(o,i,l,{blank:!0,lang:S,page:F}),$=e?Rn({file:H.join(e,"activity.json")}):null,k=bn({root:D,read:Sn(d),activity:$,draw:(o,i)=>je(o,{slug:i,mode:"words",reportsDirectory:D})}),Y=new Set,M=o=>{for(let i of o)Y.add(i);Y.size!==0&&A("data",()=>{let i=[...Y];Y.clear();for(let l of a)if(l.slug||l.page)for(let S of i)l.response.write(`data: data ${S}
|
|
153
|
-
|
|
154
|
-
`)})},x=o=>H.resolve(H.dirname(_t(o,D)))===H.resolve(D),C=null,B=null,G=()=>B??=(async()=>{for(let o of a)o.response.end();a.clear(),await Promise.race([s().catch(()=>{}),new Promise(o=>setTimeout(o,3e3))]),await $?.close(),await C?.().catch(()=>{}),await L.close(),z.close(),f()})(),z=En({server:{kind:t,version:Pa,stop:G},edits:d,reports:{create:E,export:o=>eo(d,o,{workspace:i=>k.snapshot(i)}),words:(o,i)=>je(o,{slug:i,mode:"words",reportsDirectory:D})},components:qn({root:D,taken:()=>V.taken()}),changed:w,relayed:v,index:k,web:{frameable:wn,title:yn,icon:o=>kn(o)}}),L=Gn({edits:d,workspace:z,reports:{create:E},reportsDirectory:D,offline:o=>un({...o,workspace:i=>k.snapshot(i)})}),se=yo({root:D,hop:process.env.GALLERY_TEST_NET?wo(Number(process.env.GALLERY_TEST_NET)):null,log:o=>n.info?.(`[gallery] ${o}`)}),re=Xt({root:D,edits:d,stateDirectory:e,catalogTaken:()=>V.taken(),log:o=>n.info?.(`[gallery] ${o}`),shown:wt}),U=(o,i,{present:l=!1,editorModule:S,kit:F}={})=>{let y=i,ie="",ne="",fe=!0;try{l||({html:y,snippet:ie,head:ne}=d.preview(o,i,{editor:S,kitTags:le=>an(le,F)}))}catch(le){fe=!1,n.warn(`[gallery] text editing unavailable for ${o}: ${le.message}`)}if({html:y}=ln(y,{slug:o,mode:"preview",kit:F}),y=ue(y,"head",as(o,Ne(i),ae(D).stamp)),y=ue(y,"head",`<script data-doc-dev>${So()}</script>`),y=ue(y,"head",Do),ne&&(y=ue(y,"head",ne)),l)return{html:ue(y,"head",`<style data-doc-present>.doc-display { display: none !important; }</style>
|
|
155
|
-
<script type="module" src="/__gallery/edit/src/editor/page/present-links.mjs" data-doc-dev></script>`),whole:fe};let ke="";try{ke=Dn(o,i)}catch(le){fe=!1,n.warn(`[gallery] checks unavailable for ${o}: ${le.message}`)}return ke&&(y=ue(y,"body",ke)),{html:ie?ue(y,"body",ie):y,whole:fe}},K=ko(),ce=xo(rt,ts),h=o=>{let i=_t(o,D);return[i,H.join(i,"assets")]},g=()=>jt?.editor??ce.files().then(nt),j=o=>jt?.kit?.[o.id]??nt([gt(o)]),_=async(o,i,{present:l})=>{let[S,F,y]=await Promise.all([l?"":g(),Promise.all(Fe.map(j)),nt(h(o))]),ie=[l?"present":S,...F,y,ae(D).stamp,`look:${bo(Eo(o,D))}`].join(" "),ne=K.get(o,ie,i);if(ne!==null)return l||d.opened(i),ne;let fe=new Map(Fe.map((pe,Ce)=>[pe,F[Ce]])),ke=l?void 0:`/__gallery/edit/v/${S}/src/editor/page/editor.mjs`,{html:le,whole:de}=U(o,i,{present:l,editorModule:ke,kit:pe=>`${Be(pe)}?v=${fe.get(pe)}`});return de&&K.set(o,ie,i,le),le},T=async o=>{let i=Po(o,D),[l,S]=await Promise.all([ge.readFile(i.html,"utf8").catch(()=>null),ge.readFile(i.json,"utf8").catch(()=>"")]);if(l===null)return null;let[F,y]=await Promise.all([g(),Promise.all(Fe.map(j))]),ie=new Map(Fe.map((O,be)=>[O,y[be]])),ne=ae(D),fe=To(l,S),ke=Yt(l,{blockOf:O=>ht(ne,O)}),le=Object.fromEntries([...new Set(pt(l).cards.map(({block:O})=>O).filter(Boolean))].map(O=>[O,ht(ne,O)])),{html:de}=An(ke,{reportsDirectory:D,slug:o,kit:O=>`${Be(O)}?v=${ie.get(O)}`}),pe=Ha(o,D),Ce=za(o,D),Re=pe?.defaultCards===!0,Me=Ua(l),Ue=O=>ne.packages.get(O)?.name??Mt().find(be=>be.id===O)?.title??null,Se=Re?Ma(D,pt(l).cards.map(({block:O})=>O)).map(O=>({block:O,name:Ue(O)})):[],Ie=JSON.stringify({slug:o,title:pe?.title??o,token:d.token,version:fe,blocks:le,...Ce?{hint:Ce}:{},...Re?{defaults:Re}:{},...Se.length?{news:Se}:{},...Me?{blank:Me}:{}}).replace(/</g,"\\u003c");return de=ue(de,"head",`<script type="application/json" data-ge-page data-doc-dev>${Ie}</script>`),de=ue(de,"head",ss(o,fe,ne.stamp)),de=ue(de,"head",`<script data-doc-dev>${So()}</script>`),de=ue(de,"head",Do),ue(de,"head",`<script type="module" src="/__gallery/edit/v/${F}/src/editor/page/custom-page.mjs" data-doc-dev></script>`)};async function P(o,i,l){try{if(!os(o))return $o(i,403,{ok:!1,reason:"host"});let S=rs(o);if(S)return Tt(i,{status:302,headers:{Location:S,...We}});let F=new URL(o.url||"/","http://localhost"),y=decodeURI(F.pathname);if(y===Ft){i.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-store",Connection:"keep-alive"}),i.write(`retry: 3000
|
|
156
|
-
|
|
157
|
-
`);let O={slug:F.searchParams.get("slug"),page:F.searchParams.get("page"),workspace:F.searchParams.has("workspace"),ownOnly:F.searchParams.get("workspace")==="own",response:i};a.add(O);let{stamp:be,settings:Xo}=ae(D);i.write(`data: components ${be}
|
|
158
|
-
|
|
159
|
-
`),i.write(`data: ${mt(Xo)}
|
|
160
|
-
|
|
161
|
-
`),o.on("close",()=>a.delete(O));return}if(y==="/__gallery/net")return se.handle(o,i);if(y==="/__gallery/edit/commit")return d.commit(o,i);if(y==="/__gallery/edit/reverted")return d.reverted(o,i);if(y==="/__gallery/edit/hand-in")return d.handInRequest(o,i);if(y==="/__gallery/edit/settle")return d.settleRequest(o,i);if(y==="/__gallery/edit/round")return d.roundRequest(o,i);if(y==="/__gallery/edit/upload")return d.upload(o,i);if(y==="/__gallery/edit/unfurl")return d.unfurl(o,i);if(y==="/__gallery/edit/emoji-library"){if(o.method==="POST")return d.addEmoji(o,i);let[O,be]=await d.listEmojis();return $o(i,O,be)}if(y==="/__gallery/edit/icon"){let O=en({value:F.searchParams.get("value")??"",slug:F.searchParams.get("slug"),tab:F.searchParams.has("tab")});return De(i,O?.body,{type:O?.type,headers:{"Cache-Control":"max-age=31536000, immutable"}})}if(await so(y,i,{reportsDirectory:D})||await io(y,i,{reportsDirectory:D})||await Xn(y,F.searchParams.get("v"),i,{root:D}))return;let ie=y.match(/^\/__gallery\/edit\/emoji-library\/([^/]+)$/)?.[1];if(ie){let O=await d.readEmoji(ie);return De(i,O?.body,{type:O?.type,headers:{"Cache-Control":"no-cache"}})}if(y==="/__gallery/edit/frameable")return d.frameable(o,i);if(y==="/__gallery/edit/annotations")return d.annotations(o,i);if(y==="/__gallery/edit/changes")return d.changes(o,i);let ne=y.match(/^\/__gallery\/transfer\/([a-z]+)$/)?.[1];if(ne)return L.handle(o,i,ne);let[,fe,ke]=y.match(qa)??[];if(fe)return re.handle(o,i,fe,ke);let le=y.match(/^\/__gallery\/workspace\/([a-z]+(?:-[a-z]+)*)$/)?.[1];if(le)return z.handle(o,i,le);let[,de,pe]=y.match(Wo)??[];if(pe){let O=await ge.readFile(H.join(Pe,pe),"utf8").catch(()=>null);return De(i,O,{type:"text/javascript; charset=utf-8",headers:de?Fo:We})}let Ce=F.searchParams.has("v")&&Fe.find(O=>Be(O)===y);if(Ce){let O=await ge.readFile(gt(Ce)).catch(()=>null);return De(i,O,{type:y.endsWith(".css")?"text/css; charset=utf-8":"text/javascript; charset=utf-8",headers:Fo})}if(y==="/__gallery/edit/mhchem.js"){let O=await ge.readFile(rn).catch(()=>null);return De(i,O,{type:"text/javascript; charset=utf-8",headers:We})}let[,Re,Me]=y.match(es)??[];if(Re){let O=await ge.readFile(H.join(Pe,Re)).catch(()=>null);return De(i,O,{type:Me==="json"?"application/json; charset=utf-8":"application/octet-stream",headers:{"Cache-Control":"max-age=86400"}})}if(r&&(y==="/"||y==="/index.html"))return Pt(i,"text/html; charset=utf-8",await r(F.pathname,o));let Ue=y.match(Qa)?.[1];if(Ue){let O=await T(Ue);return O===null?l():Pt(i,"text/html; charset=utf-8",O)}let Se=y.match(Va)?.[1];if(!Se){let O=y.match(Za)?.[1];return No(O)&&await ge.access(Na(_t(O,D)).html).then(()=>!0,()=>!1)?Tt(i,{status:302,headers:{Location:`/generated/${O}.html${F.search}`,...We}}):l()}let Ie=await d.readTaken(Se);if(Ie===null)return l();F.searchParams.has("present")||d.noteTaken(Se,Ie.source).then(O=>O&&u(Se),()=>{}),Pt(i,"text/html; charset=utf-8",await _(Se,Ie.text,{present:F.searchParams.has("present")}))}catch(S){l(S)}}let N=new Map,A=(o,i)=>{clearTimeout(N.get(o)),N.set(o,setTimeout(i,120))},I=o=>{Fa(o,D).reads&&m(o,bo(Eo(o,D)),"look")},Z=Kn({settled:d.settled,async tell(o,i){let l=await d.read(o,i.source).catch(S=>(n.error(`[gallery] ${o}: ${S.message}`),{version:Ne(i.source??"")}));if(m(o,l?.version??Ne("")),x(o)){let S=d.writerOf(o,i.source)??"agent";k.changed(o,{source:i.source??null,text:l?.text??null,by:S}).then(M,F=>n.error(`[gallery] ${o}: its facts not read: ${F.message}`))}d.noteTaken(o,i.source).then(S=>S&&u(o),S=>n.error(`[gallery] ${o}: the Agent's changes not kept: ${S.message}`)),d.checkAnnotations(o).catch(S=>n.error(`[gallery] ${o}: annotations not checked: ${S.message}`))}}),X=({id:o,problem:i,off:l})=>l||n.warn(`[gallery] custom block ${o} does not load: ${At("en",i)}`),V=Tn({root:D,tell({stamp:o,problems:i,settings:l},S){for(let F of S)i.has(F)&&X(i.get(F));for(let{response:F}of a)F.write(`data: components ${o} ${S.filter(y=>Aa.test(y)).join(",")}
|
|
162
|
-
|
|
163
|
-
`),F.write(`data: ${mt(l)}
|
|
164
|
-
|
|
165
|
-
`)}});for(let o of ae(D).problems.values())X(o);k.start().then(o=>o>0&&M(["activity"]));let q=bt(D),R=Ro(D).then(o=>o.join("/"),()=>""),W=!1,ee=o=>{W||=o===ot,A("extensions",async()=>{let i=W;W=!1;let l=await R;R=Ro(D).then(S=>S.join("/"),()=>l),(i||await R!==l)&&w()})},te=Ia(),we=Rt(te).extensions,ye=Qe(te,(o,i)=>{if(Ta(i,Rt(te).outline)){w();return}let l=H.relative(i,we);if(o==="reset"||l===""||!l.startsWith("..")&&!H.isAbsolute(l)){ee(ot);return}let S=Ao(te,i);S?.extension&&(S.name===ot||S.name===null)&&ee(S.name)},{extensionsOnly:!0,outline:!0}),dt=(o,i)=>!Ca&&i.some(l=>o.startsWith(l+H.sep));function Ko(o,i){if(o==="reset"){K.clear(),ce.changed(),V.changed(),w();return}if(q(i))return;let l=Ao(D,i);if(l?.page){let{page:S,name:F}=l;F&&Ba(F)&&A(`page:${S}`,async()=>{let y=Po(S,D),[ie,ne]=await Promise.all([ge.readFile(y.html,"utf8").catch(()=>null),ge.readFile(y.json,"utf8").catch(()=>"")]);ie!==null&&c(S,To(ie,ne))}),(F===_o.json||F===_o.html&&/^(add|unlink)$/.test(o)||F===null&&/^(add|unlink)Dir$/.test(o))&&w();return}if(l?.extension){(l.name===ot||l.name===null)&&ee(l.name);return}if(l?.packages&&V.changed(),l?.name===st&&l.slug===null&&A("look:*",()=>new Set([...a].map(({slug:S})=>S).filter(Boolean)).forEach(I)),l?.name===st&&l.slug===null&&w(),l?.slug&&!(l.name&&Wa(l.name))&&K.forget(l.slug),l&&(/^(doc|report)\.json$/.test(l.name??"")||/^(add|unlink)Dir$/.test(o)&&l.name===null)&&K.clear(),l?.slug&&!l.packages&&l.name===null&&/^(add|unlink)Dir$/.test(o)&&x(l.slug)&&(k.forget(l.slug),M(["todos","recent","stats"])),l?.slug&&!(l.packages&&l.name===null)&&(/^(doc|report)\.json$/.test(l.name??"")||/^(add|unlink)Dir$/.test(o)&&l.name===null||/^(add|unlink)$/.test(o)&&jo(l.name??""))&&w(),l?.slug&&!l.packages&&l.name===Ga&&w(),/^(add|unlink)(Dir)?$/.test(o)&&dt(i,rt)&&ce.changed(),l?.name&&(jo(l.name)||/^(doc|report)\.json$/.test(l.name))){if(Z(l.slug),/^(doc|report)\.json$/.test(l.name)){let{slug:S}=l;A(`look:${S}`,()=>I(S))}}else if(l?.name==="annotations.json"){let{slug:S}=l;A(`notes:${S}`,async()=>{let F=await ge.readFile(i,"utf8").catch(()=>null);m(S,F===null?"":Ne(F),"notes")})}else dt(i,ns)?A("kit",async()=>{try{await mn({fresh:!0}),m()}catch(S){n.error(`[gallery] shared kit rebuild failed: ${S.message}`)}}):dt(i,rt)&&A("editor",()=>m())}async function Jo(o){C=await _a({reportsDirectory:D,port:o,token:d.token,kind:t}),await Ra(D)}async function Yo(){ye?.close();for(let o of N.values())clearTimeout(o);V.close(),await $?.close(),await C?.().catch(()=>{}),C=null,await L.close(),z.close()}return{handle:P,changed:Ko,listening:Jo,close:Yo,stop:G,edits:d,get listeners(){return a.size}}}import is from"node:fs/promises";import Le from"node:path";import{FRAMED_BY as cs,serve as zo}from"../browser/shared/http.mjs";var ls={".html":"text/html; charset=utf-8",".js":"text/javascript; charset=utf-8",".mjs":"text/javascript; charset=utf-8",".css":"text/css; charset=utf-8",".json":"application/json; charset=utf-8",".map":"application/json; charset=utf-8",".svg":"image/svg+xml",".png":"image/png",".ico":"image/x-icon",".woff2":"font/woff2",".woff":"font/woff",".ttf":"font/ttf",".txt":"text/plain; charset=utf-8"},ds=e=>ls[Le.extname(e).toLowerCase()]??"application/octet-stream";function fs(e,n){if(/%(?:2f|5c|00)/i.test(n)||/[\\\0]/.test(n))return null;let t;try{t=decodeURIComponent(n)}catch{return null}let r=t.split("/");if(r.some(a=>a===""||a==="."||a===".."||/[\\\0:]/.test(a)))return null;let s=Le.resolve(e,...r),f=Le.relative(e,s);return f&&!f.startsWith("..")&&!Le.isAbsolute(f)?s:null}async function Ho(e,n,{web:t,kit:r,vendor:s}){if(e.method!=="GET"&&e.method!=="HEAD")return!1;let f=new URL(e.url||"/","http://localhost").pathname,a=null,m=null;if(f==="/"||f==="/index.html"){if(!t)return!1;[a,m]=[Le.join(t,"index.html"),{"Cache-Control":"no-store",...cs}]}else{let b=[["/assets/",t&&Le.join(t,"assets"),"max-age=31536000, immutable"],["/kit/",r,"no-cache"],["/vendor/",s,"no-cache"]].find(([w,v])=>v&&f.startsWith(w));if(!b)return!1;a=fs(b[1],f.slice(b[0].length)),m={"Cache-Control":b[2]}}let c=a?await is.readFile(a).catch(()=>null):null;return c?(zo(n,{type:ds(a),headers:{...m,"X-Content-Type-Options":"nosniff"},body:e.method==="HEAD"?void 0:c}),!0):(zo(n,{status:404}),!0)}async function Cl({port:e,web:n=ys,kind:t=process.env.GALLERY_SERVER_KIND==="dev"?"dev":"cli",stateDirectory:r=ps,exit:s=(c=0)=>process.exit(c),watch:f=!0,signals:a=!0,log:m=console}={}){await ks(Te),await Jt(Te,{log:$=>m.log(`[gallery] ${new Date().toISOString()} ${$}`)}),Gt(Te,$=>m.log(`[gallery] ${new Date().toISOString()} ${$}`)),Ht(Te);let c=await Vt(Te,{stateDirectory:r});c.did==="made"?m.log(`[gallery] ${new Date().toISOString()} the default home page made: ${c.file} (${c.cards.length} cards)`):c.did==="failed"&&m.warn(`[gallery] ${new Date().toISOString()} ${Zt(c)}`);let p=null,b=null,w=null,v=vs(Te),u=async()=>{b?.close(),w&&ct.unwatchFile(lt,w),await ms.writeFile(v.lastPortFile,`${e}
|
|
166
|
-
`).catch(()=>{}),await new Promise($=>{p.close(()=>$()),p.closeAllConnections()})},E=Bo({stateDirectory:r,logger:{info:$=>m.log($),warn:$=>m.warn($),error:$=>m.error($)},kind:t,closeServer:u,exit:()=>s(0)});if(p=us.createServer(($,k)=>{E.handle($,k,async Y=>{if(Y){m.error(`[gallery] ${$.method} ${$.url}: ${Y.stack??Y.message}`),k.headersSent?k.end():Go(k,{status:500});return}try{if(await Ho($,k,{web:n,kit:hs,vendor:ws}))return}catch(M){m.error(`[gallery] ${$.url}: ${M.message}`)}k.headersSent||Go(k,{status:404})})}),p.keepAliveTimeout=5e3,await new Promise(($,k)=>{p.once("error",k),p.listen(e,"127.0.0.1",()=>{p.off("error",k),$()})}),e=p.address().port,await E.listening(e),f&&(b=Qe(Te,E.changed)),gs){let $=ct.readFileSync(lt,"utf8");w=()=>{let k=null;try{k=ct.readFileSync(lt,"utf8")}catch{}k!==$&&(m.log("[gallery] The package was replaced (another version installed): this server stops; the next gallery command starts the new one."),E.stop())},ct.watchFile(lt,{interval:3e3,persistent:!1},w)}if(a)for(let $ of["SIGINT","SIGTERM","SIGHUP"])process.once($,()=>E.stop());return{server:p,port:e,routes:E,async close(){await u(),await E.close()}}}export{Cl as a};
|
package/dist/chunk-ASAXY2DJ.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{a as D,b as M}from"./chunk-HBAUKKQH.mjs";import{c as v,d as j}from"./chunk-KUILYI7H.mjs";import{b as k,f as A}from"./chunk-4OZWXZE5.mjs";import L from"node:fs/promises";import y from"node:path";import{readAnnouncement as _}from"../browser/shared/preview-server.mjs";import{nameProblem as B,nameStops as b,ownName as K,workspaceLabels as Q,workspaceName as x,writeWorkspaceName as R}from"../browser/shared/workspace-name.mjs";import{forgetWorkspace as U,isTemporary as q,isWorkspace as C,isWorkspaceId as z,readRegistry as F,registerQuietly as W,registerWorkspace as G,SCAN_DEPTH as P,SCAN_LIMIT as J,scanForWorkspaces as V,workspaceId as X,workspaceKey as l}from"../browser/shared/workspace-registry.mjs";import{defaultWorkspace as Y,documentsFolder as T,ensureWorkspace as Z,layoutOf as ee}from"../browser/shared/workspace.mjs";import{clashingIds as oe}from"../browser/shared/drafts.mjs";var $=(o,r)=>`${o} ${r}${o===1?"":"s"}`,I=(o,r)=>l(o)===l(r);function se(o){if(K(o)||I(o,Y()))return null;let{name:r}=x(o,{stops:b()});return`\u5DE5\u4F5C\u533A\u540D\u5B57\uFF1A\u6CA1\u6709\uFF08\u522B\u5904\u6309\u6587\u4EF6\u5939\u53EB\u5B83"${r}"\uFF09\uFF1B\u8FD9\u4E2A\u5DE5\u4F5C\u533A\u662F\u4E3A\u4E00\u4E2A\u9879\u76EE\u5EFA\u7684\uFF0C\u5C31\u7528 gallery workspaces --name "<\u9879\u76EE\u540D>" \u5199\u4E0A\u9879\u76EE\u540D`}async function re(o,r){let c=B(r);if(c)throw new k(c);try{let{ours:t,reads:i}=await Z(o);t||(console.error(j(o,i)),process.exit(1))}catch(t){if(!t.code)throw t;console.error(v(o,t.code)),process.exit(1)}let s;try{s=await R(o,r)}catch(t){console.error(t.code?v(o,t.code):t.message),process.exit(1)}await W(o),console.log(`\u5DE5\u4F5C\u533A\uFF1A${o}`),console.log(`\u540D\u5B57\uFF1A${s.name} (in ${ee(o).marker}${s.before&&s.before!==s.name?`; it was "${s.before}"`:""}): the sidebar and gallery workspaces call it so.`)}async function te(o,r){let c=await U(o);c.length||(console.error(`No registered workspace is ${z(o)?o:y.resolve(o)}: gallery workspaces lists them, with their paths and ws- ids.`),process.exit(1));for(let s of c)console.log(`Forgot ${s} (only the registry changed: nothing on disk).${I(s,r)?" It is the current workspace: the next command run in it registers it again.":""}`)}async function ne(o){let r=y.resolve(o??T());await L.stat(r).then(n=>n.isDirectory(),()=>!1)||(console.error(`No such folder: ${r} (--scan names a folder to look in).`),process.exit(1));let c=new Set(F().workspaces.map(({root:n})=>l(n))),{found:s,read:t,cut:i}=await V(r);console.log(`Scanned ${r}, ${P} levels down (${$(t,"folder")}): ${s.length?`${$(s.length,"workspace")}.`:"no workspace."}`);let f=b();for(let n of s){let{name:h}=x(n,{stops:f});if(c.has(l(n))){await W(n),console.log(` \u5DF2\u767B\u8BB0\uFF1A${n}\uFF08${h}\uFF09`);continue}let g;try{g=await G(n)}catch(m){console.log(` \u6CA1\u80FD\u767B\u8BB0\uFF08${m.code??m.message}\uFF09\uFF1A${n}`);continue}console.log(g==="temporary"?` \u4E0D\u767B\u8BB0\uFF08\u5728\u7CFB\u7EDF\u7684\u4E34\u65F6\u6587\u4EF6\u5939\u91CC\uFF09\uFF1A${n}`:` \u65B0\u767B\u8BB0\uFF1A${n}\uFF08${h}\uFF09`)}i&&console.log(`Stopped after ${$(J,"folder")}: gallery workspaces --scan <a folder further down> looks at the rest.`),s.length&&console.log("gallery workspaces lists them; gallery list <words> --all searches their documents.")}async function ae(o){let r=C(o),c=q(o);r&&await W(o);let s=F().workspaces,t=[o,...s.map(({root:e})=>e).filter(e=>!I(e,o))],i=new Map(s.map(({root:e,seen:a})=>[l(e),Date.parse(a)])),f=T(),n=b({documents:f}),h=await Promise.all(t.map(async e=>{let a=C(e),w=a?await D(e):[],p=a?await _({reportsDirectory:e}):null;return{root:e,there:a,count:w.length,edited:w.reduce((d,{edited:u})=>Math.max(d,u),0),port:p?.port??null,named:{root:e,...x(e,{stops:n})}}})),[g,...m]=h;m.sort((e,a)=>a.there-e.there||a.edited-e.edited||(i.get(l(a.root))??0)-(i.get(l(e.root))??0));let N=[g,...m],E=new Map(Q(N.map(({named:e})=>e)).map(e=>[l(e.root),e])),O=s.length;console.log(`${$(O,"workspace")} on this machine's registry; the current one first (*):`);for(let e of N){let{name:a,own:w,above:p}=E.get(l(e.root)),d=e===g,u=[...w||!e.there?[]:["\u6CA1\u6709\u8D77\u540D\uFF1A\u7528\u7684\u662F\u6587\u4EF6\u5939\u7684\u540D\u5B57"],...e.there?[]:[d?"\u8FD8\u6CA1\u6709\u5EFA":"\u4E0D\u5728\u4E86\uFF1A\u6587\u4EF6\u5939\u6216\u5B83\u7684 gallery.json \u627E\u4E0D\u5230\u4E86"],...d&&e.there&&c?["\u5728\u7CFB\u7EDF\u7684\u4E34\u65F6\u6587\u4EF6\u5939\u91CC\uFF1A\u4E0D\u767B\u8BB0"]:[]],H=p?y.isAbsolute(p)?`\uFF08${p}\uFF09`:`\uFF08\u4E0A\u4E00\u7EA7\uFF1A${p}\uFF09`:"";console.log(`${d?"*":" "} ${a}${H} ${X(e.root)}${u.length?` \uFF08${u.join("\uFF1B")}\uFF09`:""}`),console.log(` \u8DEF\u5F84\uFF1A${e.root}`),e.there&&console.log(` \u6587\u6863\uFF1A${e.count?`${e.count} \u7BC7\uFF1B\u4E0A\u6B21\u7F16\u8F91\uFF1A${M(e.edited)}`:"\u6CA1\u6709"}`),e.port&&console.log(` \u670D\u52A1\uFF1Ahttp://127.0.0.1:${e.port}/`)}for(let{id:e,roots:a}of oe())console.log(`${e} \u662F ${a.length} \u4E2A\u767B\u8BB0\u7684\u5DE5\u4F5C\u533A\u5171\u7528\u7684\u7F16\u53F7\uFF08${a.join("\u3001")}\uFF09\uFF1A\u4FA7\u8FB9\u680F\u91CC\u5B83\u4EEC\u7684\u5E95\u7A3F\u90FD\u627E\u4E0D\u5230\uFF1Bgallery workspaces --forget <\u8DEF\u5F84> \u53BB\u6389\u5176\u4E2D\u4E00\u4E2A`);let S=r?se(o):null;S&&console.log(S),m.some(({there:e})=>!e)&&console.log("One no longer there stays registered (a drive may come back): gallery workspaces --forget <\u8DEF\u5F84> takes it off, nothing on disk changed."),O<=1&&console.log(`gallery workspaces --scan registers the workspaces already on this machine (in the Documents folder, ${P} levels down; or --scan <folder>).`),console.log("gallery list <words> --all searches the documents of them all; every command takes --workspace <\u8DEF\u5F84> to work in one.")}async function ue(o,r){let{positional:c,options:s,values:t}=A({options:["--scan"],values:["--name","--forget"],argv:o});if([s.has("--scan"),t.has("--name"),t.has("--forget")].filter(Boolean).length>1)throw new k("One of --scan, --name and --forget at a time.");if(c.length>(s.has("--scan")?1:0))throw new k(s.has("--scan")?"--scan takes one folder at most.":"gallery workspaces names no folder: --scan <folder> looks in one, --workspace <dir> names the current workspace.");let f=y.resolve(r.workspace);return t.has("--name")?re(f,t.get("--name")):t.has("--forget")?te(t.get("--forget"),f):s.has("--scan")?ne(c[0]):ae(f)}export{se as a,ue as b};
|
package/dist/chunk-DAMVDXR3.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{a,b,c,d,e,f,g,h}from"./chunk-5L26JUYA.mjs";import"./chunk-S2Y7VI4H.mjs";import"./chunk-JJNRIFND.mjs";import"./chunk-JEUK3ZO7.mjs";import"./chunk-QXVNUASA.mjs";import"./chunk-2OHANJ6Q.mjs";import"./chunk-2GKGEVMR.mjs";import"./chunk-VKSRM7EY.mjs";import"./chunk-LE44MD3O.mjs";import"./chunk-4OZWXZE5.mjs";import"./chunk-SAHS56QM.mjs";import"./chunk-YFJU3O7G.mjs";import"./chunk-2RKIHJI2.mjs";import"./chunk-7XDYK3UC.mjs";import"./chunk-VG5JEIUQ.mjs";import"./chunk-N3DSBH5S.mjs";import"./chunk-5L7RYZCL.mjs";export{c as HOME_NOT_MADE,g as emptyRequiredOf,d as missingPageSaid,a as pageAddressOf,b as pageAloneOf,h as run,e as setsOf,f as settingsGiven};
|
package/dist/chunk-DLFZJJEE.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{a}from"./chunk-AEMVZYZQ.mjs";import"./chunk-DR73Y2UJ.mjs";import"./chunk-CG3UHDKH.mjs";import"./chunk-4AMTKWDO.mjs";import"./chunk-QXVNUASA.mjs";import"./chunk-FCK6NXON.mjs";import"./chunk-OU3S466R.mjs";import"./chunk-CZ5KJSGK.mjs";import"./chunk-UGO5N3EI.mjs";import"./chunk-5IIH335D.mjs";import"./chunk-QK3VISCA.mjs";import"./chunk-2OHANJ6Q.mjs";import"./chunk-F4ZA6JRZ.mjs";import"./chunk-7M2BQQGZ.mjs";import"./chunk-TOE6DPLH.mjs";import"./chunk-WTEGUPFG.mjs";import"./chunk-VKSRM7EY.mjs";import"./chunk-LE44MD3O.mjs";import"./chunk-XMKHCUI6.mjs";import"./chunk-SAHS56QM.mjs";import"./chunk-KH24LWAT.mjs";import"./chunk-YFJU3O7G.mjs";import"./chunk-NWRZXELO.mjs";import"./chunk-G4YP7GVC.mjs";import"./chunk-DHB7UZ7F.mjs";import"./chunk-2RKIHJI2.mjs";import"./chunk-JXLSHVJ2.mjs";import"./chunk-XKOHV4H6.mjs";import"./chunk-KFZBYDIS.mjs";import"./chunk-7XDYK3UC.mjs";import"./chunk-VG5JEIUQ.mjs";import"./chunk-N3DSBH5S.mjs";import"./chunk-5L7RYZCL.mjs";export{a as startProductionServer};
|
package/dist/chunk-EKNHM3P4.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{b as n,f as i}from"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";import{reportsDirectory as r}from"../browser/shared/paths.mjs";import{answerOf as a,readAnnouncement as d,stopServer as l}from"../browser/shared/preview-server.mjs";async function m(p){let{positional:s}=i({argv:p});if(s.length>0)throw new n(`gallery stop takes no arguments: ${s[0]}`);let o=await d({reportsDirectory:r}),t=o?await a(o,r,1e4):"no";if(t==="no")return void console.log(`No Gallery server runs for ${r}.`);t==="busy"&&(console.error(`The Gallery server on port ${o.port} (pid ${o.pid}) took the request and gave no answer in 10s: it is busy or stuck. Run gallery stop again in a while, or end process ${o.pid} yourself.`),process.exit(1)),o.kind==="dev"&&(console.error(`This workspace's server is npm run dev's (port ${o.port}, pid ${o.pid}): stop it where it runs.`),process.exit(1));let e=await l(o);e.ok||(console.error(e.message),process.exit(1)),console.log(`Stopped the server on port ${o.port} (pid ${o.pid})${e.killed?": it did not stop by itself in 10s, so its process was ended":""}.`)}export{m as run};
|
package/dist/chunk-FCK6NXON.mjs
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{b as E}from"./chunk-WTEGUPFG.mjs";import{g as M}from"./chunk-SAHS56QM.mjs";import{a as O}from"./chunk-2RKIHJI2.mjs";import{e as I,j as S}from"./chunk-KFZBYDIS.mjs";import d from"node:fs/promises";import b from"node:path";import{isInstance as T}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as _}from"../browser/shared/components/installed.mjs";import{exportSourceOf as q}from"../browser/shared/export-wrap.mjs";import{sha256 as w}from"../browser/shared/files.mjs";import{attr as g,hasClass as y}from"../browser/shared/html-tree.mjs";import{editStateDirectory as F,exportsDirectory as z,qaDirectory as G,reportsDirectory as H}from"../browser/shared/paths.mjs";import{documentDirectory as K,documentFiles as Q}from"../browser/shared/workspace.mjs";function V(t,e=null){return t.tagName==="figure"&&y(t,"doc-figure")||t.tagName==="div"&&(y(t,"doc-code")||y(t,"doc-diff"))||e===D||T(t)||y(t,"doc-flow")||y(t,"doc-sheet-shell")||g(t,"data-doc-sheets")!==void 0?0:t.tagName==="figure"||y(t,"doc-columns")?1:y(t,"doc-table-wrap")?2:3}function X(t){let e=new Map,n=new Map;for(let i of I(t).units)i.blockId&&!n.has(i.blockId)&&n.set(i.blockId,i.kind);let a=new Map,r=new Map,o=new Map,f=i=>!!i.tagName&&g(i,"data-block-id")!==void 0,u=(i,c)=>{if(i.nodeName==="#text")return i.value;if(!i.tagName||i.tagName==="template")return"";let s=g(i,"data-doc-chart-data")?.trim();s&&a.get(c).push(s);let l=g(i,"data-doc-chart-source")?.trim();l&&!r.has(l)&&r.set(l,c);let h=i.attrs.map(({name:k,value:N})=>`${k}="${N}"`).sort().join(" ");return`<${i.tagName} ${h}>${(i.childNodes??[]).map(k=>f(k)?"":u(k,c)).join("")}</${i.tagName}>`},m=(i,c)=>{for(let s of i.childNodes??[]){if(!s.tagName||s.tagName==="template")continue;let l=g(s,"data-block-id"),h=c;if(l!==void 0&&!e.has(l)){let k=[s.tagName,...(g(s,"class")??"").split(/\s+/).filter(Boolean).slice(0,1)].join("."),N=o.get(c)??0;o.set(c,N+1),a.set(l,[]);let v=V(s,n.get(l)),x=s.sourceCodeLocation,U=x?(x.endOffset??x.startTag?.endOffset??x.startOffset)-x.startOffset:0,B=u(s,l).replace(R," ");e.set(l,{hash:w(B).slice(0,16),bare:w(B.replace(`data-block-id="${l}"`,"")).slice(0,16),rank:v,card:v<3,whole:n.get(l)===D,figure:n.get(l)===tt,tag:k,parent:c,at:N,size:U,package:T(s)?g(s,_)??null:null}),h=l}m(s,h)}};m(O(t),null);let p=new Map([...e].map(([i,{hash:c,bare:s}])=>[i,{hash:c,bare:s}]));for(let[i,c]of a){let s=c.map(l=>p.get(r.get(l))).filter(Boolean);s.length&&(e.get(i).hash=w([p.get(i).hash,...s.map(({hash:l})=>l)].join("|")).slice(0,16),e.get(i).bare=w([p.get(i).bare,...s.map(({bare:l})=>l)].join("|")).slice(0,16))}return e}function Y(t){let e=[],n=a=>{for(let r of a.childNodes??[])if(!(!r.tagName||r.tagName==="template"||g(r,"data-block-id")!==void 0))if(r.tagName==="script"||r.tagName==="style"){let o=r.attrs.map(({name:f,value:u})=>`${f}="${u}"`).sort().join(" ");e.push(`<${r.tagName} ${o}>${(r.childNodes??[]).map(f=>f.value??"").join("")}`.replace(R," "))}else n(r)};return n(O(t)),e.length?w(e.join("|")).slice(0,16):""}var Z=t=>Object.fromEntries(M(t).map(({id:e,stamp:n})=>[e,n])),D="block",tt="figure",R=/[ \t\n\f\r]+/g,et=["export","preview"];function st(t){if(t==null)return null;try{let{blocks:e,places:n,moved:a,unseen:r,from:o,time:f,idless:u,page:m,packages:p}=JSON.parse(t)??{};if(!e||typeof e!="object"||Array.isArray(e))return null;let i=n&&typeof n=="object"&&!Array.isArray(n)?n:{},c=s=>Array.isArray(s)?s.filter(l=>typeof l=="string"):[];return{blocks:Object.fromEntries(Object.entries(e).filter(([,s])=>typeof s=="string")),places:Object.fromEntries(Object.entries(i).filter(([,s])=>Array.isArray(s)&&s.length===2&&(s[0]===null||typeof s[0]=="string")&&Number.isInteger(s[1]))),moved:c(a),unseen:c(r),...et.includes(o)?{from:o,time:Number.isFinite(f)?f:null}:{},...c(u).length?{idless:c(u)}:{},...typeof m=="string"?{page:m}:{},...p&&typeof p=="object"&&!Array.isArray(p)?{packages:Object.fromEntries(Object.entries(p).filter(([,s])=>typeof s=="string"))}:{}}}catch{return null}}var $="ge-idless-";function nt(t,{from:e,time:n}){let a=0,{text:r}=S(E(t).text,()=>`${$}${a++}`),o=Z(r),f={blocks:{},places:{},moved:[],unseen:[],from:e,time:n,page:Y(r),...Object.keys(o).length?{packages:o}:{}},u=[];for(let[m,{hash:p,bare:i,card:c,parent:s,at:l}]of X(r)){if(m.startsWith($)){u.push(i);continue}f.blocks[m]=p,s?.startsWith($)||(f.places[m]=[s,l]),c&&f.unseen.push(m)}return u.length?{...f,idless:u}:f}function yt(t,e){if(!e?.idless?.length)return e;let n=new Map;for(let o of e.idless)n.set(o,(n.get(o)??0)+1);let a={...e,blocks:{...e.blocks},unseen:[...e.unseen]};for(let[o,{hash:f,bare:u,card:m}]of t)Object.hasOwn(e.blocks,o)||!n.get(u)||(n.set(u,n.get(u)-1),a.blocks[o]=f,m&&a.unseen.push(o));let r=[...n].flatMap(([o,f])=>Array(f).fill(o));return r.length?a.idless=r:delete a.idless,a}var at=/<[^>]*\sdata-doc-placeholder\b/,j=t=>b.join(G,t),L=t=>b.join(j(t),"blocks.json"),P=t=>b.join(j(t),"exported.html");async function W(t){return st(await d.readFile(L(t),"utf8").catch(()=>null))!==null}async function C(t,e,n){let a=async c=>d.readFile(c).then(s=>({bytes:s,file:c}),()=>null),r=await a(P(t)),o=[r];if(e){let c=e.slice(0,16),s=b.join(F,"history",t),l=await d.readdir(s).catch(()=>[]);o.push(...await Promise.all(l.filter(h=>h.endsWith(`-${c}.html`)).map(h=>a(b.join(s,h))))),o.push(await a(b.join(F,"snapshots",`${c}.html`)))}let f=r?(await d.stat(r.file).catch(()=>null))?.mtimeMs??null:null,m=!(r&&e&&n!==null&&f!==null&&f>n&&w(r.bytes)!==e)&&e&&o.find(c=>c&&w(c.bytes)===e),p=m||r;if(!p)return null;let i=m&&n!==null?n:p===r?f??n:(await d.stat(p.file).catch(()=>null))?.mtimeMs??n;return{text:p.bytes.toString("utf8"),time:i??null}}async function A(t){let e=b.join(z,`${t}.html`),[n,a]=await Promise.all([d.readFile(e,"utf8").catch(()=>null),d.stat(e).catch(()=>null)]);return n===null||!a?null:{said:q(n),time:a.mtimeMs}}async function J(t,e,n){if(at.test(e))return!1;let a=nt(e,n);return!Object.keys(a.blocks).length&&!a.idless?!1:(await d.mkdir(j(t),{recursive:!0}),await d.writeFile(L(t),`${JSON.stringify(a)}
|
|
3
|
-
`),!0)}async function bt(t){let e=new Map(await Promise.all(t.map(async a=>[a,await A(a).catch(()=>null)])));return{keep:async(a,r=null)=>{for(let o of a)try{if(!await W(o)){let m=e.get(o),p=await C(o,m?.said??null,m?.time??null);p&&await J(o,p.text,{from:"export",time:p.time})}let[f,u]=await Promise.all([d.readFile(Q(K(o,H)).html),r?{said:r.get(o)??null}:A(o)]);u?.said&&w(f)===u.said&&(await d.mkdir(j(o),{recursive:!0}),await d.writeFile(P(o),f))}catch{}}}}async function kt(t,e){try{if(await W(t))return!1;let n=await A(t),a=await C(t,n?.said??null,n?.time??null);return await J(t,a?.text??e,a?{from:"export",time:a.time}:{from:"preview",time:Date.now()})}catch{return!1}}export{V as a,X as b,Y as c,Z as d,et as e,st as f,nt as g,yt as h,W as i,C as j,bt as k,kt as l};
|
package/dist/chunk-FX42XU6J.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{c as i,d as u}from"./chunk-KUILYI7H.mjs";import{j as f,k as p}from"./chunk-VKSRM7EY.mjs";import{u as c}from"./chunk-LE44MD3O.mjs";import{b as d,f as h}from"./chunk-4OZWXZE5.mjs";import w from"node:fs/promises";import y from"node:path";import{reportsDirectory as b}from"../browser/shared/paths.mjs";import{sameDirectory as x}from"../browser/shared/preview-server.mjs";import{copyOldDocuments as j,ensureWorkspace as v,layoutOf as D}from"../browser/shared/workspace.mjs";import{nameProblem as G,writeWorkspaceName as N}from"../browser/shared/workspace-name.mjs";import{registerQuietly as O}from"../browser/shared/workspace-registry.mjs";var g=(o,t)=>`${o} ${t}${o===1?"":"s"}`;function C(o,t,r){let{preferences:s}=D(r);return[o.copied.length?`Copied ${g(o.copied.length,"document")} from ${t}: ${o.copied.join(", ")}`:`Copied no documents from ${t}.`,...o.skipped.length?[`Skipped (the slug is taken here, or the folder's name is no slug): ${o.skipped.join(", ")}`]:[],...o.kept.length?[`Left behind (a name a workspace keeps for itself, for its custom blocks here, which no new document takes): ${o.kept.join(", ")}`]:[],...o.preferences==="copied"?[`\u5199\u4F5C\u504F\u597D\uFF1Acopied (${s})`]:o.preferences==="kept"?[`\u5199\u4F5C\u504F\u597D\uFF1Akept the workspace's (${s}); the old one was not copied`]:[],...o.outline?[`Sidebar order: ${o.outline}`]:[],...o.page?[`\u5199\u4F5C\u504F\u597D's page: ${o.page==="copied"?"copied":"kept the workspace's"}`]:[],...o.emoji?[`Emoji library: ${o.emoji} added`]:[],...o.history?[`Recent versions: ${g(o.history,"document")}`]:[],...o.packages.length?[`Custom blocks: ${o.packages.join(", ")}`]:[]]}async function U(o){let{values:t}=h({values:["--from","--name"],argv:o}),r=b,s=t.get("--name"),l=s===void 0?null:G(s);if(l)throw new d(l);let m;try{let{made:e,ours:n,reads:k}=await v(r);n||(console.error(u(r,k)),process.exit(1)),m=e}catch(e){if(!e.code)throw e;console.error(i(r,e.code)),process.exit(1)}if(console.log(`\u5DE5\u4F5C\u533A\uFF1A${r}\uFF08${m?"\u65B0\u5EFA":"\u5DF2\u6709"}\uFF09`),s!==void 0)try{let e=await N(r,s);console.log(`\u540D\u5B57\uFF1A${e.name}${e.before&&e.before!==e.name?` (it was "${e.before}")`:""}`)}catch(e){console.error(e.code?i(r,e.code):e.message),process.exit(1)}if(await O(r),t.has("--from")){let e=y.resolve(t.get("--from"));await w.stat(e).then(n=>n.isDirectory(),()=>!1)||(console.error(`No such folder: ${e} (--from names an older Gallery's reports/ folder).`),process.exit(1)),x(e,r)&&(console.error(`${e} is this workspace: --from names another folder (an older Gallery's reports/).`),process.exit(1));for(let n of C(await j({from:e,to:r}),e,r))console.log(n)}let $=await c(r);for(let e of $.packs)e.failed?console.warn(`\u5757\u5305\uFF1AGallery's pack ${e.id} was not installed (${e.failed}); a later start tries again.`):e.first&&console.log(`\u5757\u5305\uFF1A${e.name.zh} (${e.id} ${e.version}, ${e.added.length+e.same.length+e.updated.length} blocks)${e.id==="gallery-soft"?", switched off: \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868 turns it on":""}`);let a=await f(r);a.did==="made"?console.log(`\u9996\u9875\uFF1A${a.file} (the home page, its cards Gallery's today and note; the workbench opens it first)`):a.did==="failed"&&console.warn(`\u9996\u9875\uFF1A${p(a)}`),console.log('Next: gallery new <slug> "<title>" makes a document; gallery open opens the workbench.')}export{C as a,U as b};
|
package/dist/chunk-HATA2W7X.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{a,b,c,d,e,f,g,h}from"./chunk-BYSF5UMM.mjs";import"./chunk-3OFXMN6N.mjs";import"./chunk-SOD23RGL.mjs";import"./chunk-4DNHHJSL.mjs";import"./chunk-342HXE3Q.mjs";import"./chunk-3A5I2GJK.mjs";import"./chunk-5L26JUYA.mjs";import"./chunk-S2Y7VI4H.mjs";import"./chunk-XQRUG4G3.mjs";import"./chunk-JJNRIFND.mjs";import"./chunk-JEUK3ZO7.mjs";import"./chunk-CG3UHDKH.mjs";import"./chunk-4AMTKWDO.mjs";import"./chunk-QXVNUASA.mjs";import"./chunk-FCK6NXON.mjs";import"./chunk-OU3S466R.mjs";import"./chunk-QK3VISCA.mjs";import"./chunk-2OHANJ6Q.mjs";import"./chunk-F4ZA6JRZ.mjs";import"./chunk-7M2BQQGZ.mjs";import"./chunk-TOE6DPLH.mjs";import"./chunk-WTEGUPFG.mjs";import"./chunk-2GKGEVMR.mjs";import"./chunk-VKSRM7EY.mjs";import"./chunk-LE44MD3O.mjs";import"./chunk-4OZWXZE5.mjs";import"./chunk-XMKHCUI6.mjs";import"./chunk-SAHS56QM.mjs";import"./chunk-KH24LWAT.mjs";import"./chunk-YFJU3O7G.mjs";import"./chunk-NWRZXELO.mjs";import"./chunk-G4YP7GVC.mjs";import"./chunk-DHB7UZ7F.mjs";import"./chunk-2RKIHJI2.mjs";import"./chunk-JXLSHVJ2.mjs";import"./chunk-XKOHV4H6.mjs";import"./chunk-KFZBYDIS.mjs";import"./chunk-7XDYK3UC.mjs";import"./chunk-VG5JEIUQ.mjs";import"./chunk-N3DSBH5S.mjs";import"./chunk-5L7RYZCL.mjs";export{a as PAGE_ASIDE,b as PAGE_INSIDE_ALONE,e as cardChangesOf,c as firstInstance,d as outsideWhat,g as pageHost,f as pageSaves,h as pageTryCommand};
|
package/dist/chunk-JJNRIFND.mjs
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{spawn as J}from"node:child_process";import P from"node:fs";import m from"node:fs/promises";import Q from"node:os";import k from"node:path";import{escapeMarkup as X}from"../browser/shared/escape.mjs";import{spawn as C}from"node:child_process";import{existsSync as H,readFileSync as M}from"node:fs";import w from"node:path";var V=e=>!["","0",void 0].includes(e),z=(e,r)=>(r.PATH??"").split(w.delimiter).some(t=>t&&H(w.join(t,e))),U=()=>{try{return process.platform==="linux"&&/microsoft/i.test(M("/proc/version","utf8"))}catch{return!1}};function K(e,{platform:r=process.platform,env:t=process.env,wsl:s=U()}={}){let n=encodeURI(e);return V(t.GALLERY_NO_BROWSER)?{skip:"GALLERY_NO_BROWSER is set"}:r==="win32"?{command:w.join(t.SystemRoot||t.windir||"C:\\Windows","System32","rundll32.exe"),args:["url.dll,FileProtocolHandler",n]}:r==="darwin"?{command:"open",args:[n]}:s?{command:"cmd.exe",args:["/c","start",'""',n.replace(/[&^]/g,"^$&")]}:!t.DISPLAY&&!t.WAYLAND_DISPLAY?{skip:"no display here (neither DISPLAY nor WAYLAND_DISPLAY is set)"}:z("xdg-open",t)?{command:"xdg-open",args:[n]}:{skip:"xdg-open is not installed"}}var q="Opened it in the default browser (if that is not Chrome or Edge, open the address there to edit).",T=e=>e.opened?q:`Not opened in a browser: ${e.why}.`;async function O(e,r){let t=K(e,r);return t.skip?{opened:!1,why:t.skip}:new Promise(s=>{let n;try{n=C(t.command,t.args,{detached:!0,stdio:"ignore",windowsHide:!0})}catch(o){return s({opened:!1,why:`${w.basename(t.command)} did not start (${o.code??o.message})`})}n.once("error",o=>s({opened:!1,why:`${w.basename(t.command)} did not start (${o.code??o.message})`})),n.once("spawn",()=>{n.unref(),s({opened:!0})})})}import{packageRoot as Z,previewLogFile as f,projectRoot as G,release as I,reportsDirectory as h}from"../browser/shared/paths.mjs";import{fullAddress as ee}from"../browser/shared/page-address.mjs";import{findPreviewServer as te,galleryVersion as F,portIsFree as re,previewServerFor as ne,readAnnouncement as oe}from"../browser/shared/preview-server.mjs";import{documentLinks as se}from"../browser/shared/reports.mjs";import{documentDirectory as ie,documentFiles as ae,layoutOf as ce}from"../browser/shared/workspace.mjs";var $="\u4EA4\u7ED9\u7528\u6237\uFF08\u73B0\u5728\u5C31\u628A\u8FD9\u4E2A\u5730\u5740\u7ED9\u7528\u6237\uFF1B\u7528 Chrome \u6216 Edge \u6253\u5F00\uFF09\uFF1A",le="Agent \u81EA\u7528\uFF08\u53EA\u6709\u6587\u6863\u9875\uFF0C\u4E0D\u4EA4\u7ED9\u7528\u6237\uFF09\uFF1A",de=e=>`send the user ${e} now, in a message of its own, before any other step; then `;function Ve(e,r){let t=e.at(-1)??"";return`Next: ${t.startsWith($)?de(t.slice($.length)):""}${r}`}async function ze(e,r){let t=e.at(-1)??"";return t.startsWith($)?r.has("--no-browser")?"Not opened in a browser (--no-browser).":T(await O(t.slice($.length))):null}var D="GALLERY_NO_PREVIEW",pe=e=>!["","0",void 0].includes(e),Ue=e=>e.has("--no-preview")||pe(process.env[D]),ue=4317,fe=20,me=(e=process.env)=>{let r=Number(e.GALLERY_PORT);return Number.isInteger(r)&&r>0&&r<65536?r:ue},we=6e4,he=5*1024*1024,$e=k.join(G,"node_modules","vite","bin","vite.js"),ye=k.join(Z,"dist","server.mjs"),ge=e=>new Promise(r=>setTimeout(r,e)),A={reportsDirectory:h},Y=ce(h),R=(e,r)=>`http://127.0.0.1:${e}/generated/${r}.html`,ve=(e,r)=>`${R(e,r)}?agent`,j=e=>`http://127.0.0.1:${e}/`,xe=(e,r)=>se().then(({links:t})=>t,()=>null).then(t=>ee(`http://127.0.0.1:${e}`,r,t));async function ke({first:e=me(),count:r=fe}={}){let t=Number((await m.readFile(Y.lastPortFile,"utf8").catch(()=>"")).trim()),s=Array.from({length:Math.max(0,r)},(n,o)=>e+o);return Number.isInteger(t)&&t>0&&t<65536?[t,...s.filter(n=>n!==t)]:s}async function Le(){return await m.mkdir(k.dirname(f),{recursive:!0}),await m.stat(f).then(r=>r.size,()=>0)>he&&await m.rename(f,`${f}.1`).catch(()=>{}),P.openSync(f,"a")}async function Se(e,r){if(!I){let{writeSharedAssets:p}=await import("./chunk-DH6GMDNN.mjs");await p()}let t=await Le();P.writeSync(t,`
|
|
3
|
-
[${new Date().toISOString()}] ${r}: Gallery ${F} on 127.0.0.1:${e} for ${h}
|
|
4
|
-
`);let[s,n]=I?[[ye,"--port",String(e)],Q.homedir()]:[[$e,"--host","127.0.0.1","--port",String(e),"--strictPort"],G],o=J(process.execPath,s,{cwd:n,env:{...process.env,GALLERY_WORKSPACE:k.resolve(h),GALLERY_SERVER_KIND:"cli"},detached:!0,stdio:["ignore",t,t],windowsHide:!0});return P.closeSync(t),o.unref(),o}async function be({slug:e=null,command:r=`gallery open${e?` ${e}`:""}`,ports:t=null,starting:s=we,baseline:n=!1}={}){let o=()=>!0;if(e){let a=ae(ie(e,h)),c=await m.readFile(a.html,"utf8").catch(()=>null);if(c===null)return{ok:!1,reason:"missing",message:`No document "${e}": ${a.html} does not exist (gallery new ${e} "<\u6807\u9898>" makes one; gallery list lists those there are).`};n&&await import("./chunk-5MEXZ2UF.mjs").then(({previewBaseline:x})=>x(e,c));let i=await m.readFile(a.json,"utf8").then(JSON.parse).catch(()=>({})),v=[/<title>([^<]*)<\/title>/i.exec(c)?.[1]?.trim(),typeof i.title=="string"?i.title.trim():""].filter(Boolean);o=x=>v.length===0||v.some(_=>x.includes(_)||x.includes(X(_)))}let p=t??await ke(),L=p.length?`${Math.min(...p)} to ${Math.max(...p)}`:"none",S=`gallery open${e?` ${e}`:""}`,E=async(a,c=[])=>{let i=await ne({...A,ports:p.slice(a),start:v=>Se(v,r)});return i.busy?.newer?{failed:{ok:!1,reason:"newer",message:`A newer Gallery (${i.busy.version}) serves this workspace (port ${i.busy.port}, pid ${i.busy.pid}) and gave no answer in 10s; this is Gallery ${F}. Update this one (npm i -g @heycys/gallery@latest), or run ${S} again in a while.`}}:i.busy?{failed:{ok:!1,reason:"busy",message:`This workspace's Gallery server (port ${i.busy.port}, pid ${i.busy.pid}) took the request and gave no answer in 10s: it is busy or stuck. Run ${S} again in a while, or stop that process first (gallery stop): a second server of this workspace is not started beside it.`}}:i.stuck?{failed:{ok:!1,reason:"stuck",message:`An older Gallery's server serves this workspace and did not stop: ${i.stuck.message}`}}:i.port===null?{failed:{ok:!1,reason:"ports",message:`No server of this workspace runs, and no port from ${L} is free to start one on: stop a server on one of them (or name another first port: GALLERY_PORT=<n>), then run ${S}.`}}:{...i,passed:[...c,...i.passed]}},u=await E(0);if(u.failed)return u.failed;let{port:l,started:d,passed:b,replaced:W}=u,y=u.running??null,N=Date.now()+s,g="",B=async()=>{if(e){let c=await fetch(`${R(l,e)}?present`,{signal:AbortSignal.timeout(5e3)}).catch(()=>null),i=c?.ok?await c.text():"";return g=c?i?`HTTP ${c.status} without the title`:`HTTP ${c.status}`:"no answer",!!(i&&o(i))}let a=await fetch(`http://127.0.0.1:${l}/__gallery/workspace/info`,{signal:AbortSignal.timeout(5e3)}).catch(()=>null);return g=a?`HTTP ${a.status}`:"no answer",!!a?.ok};for(;;await ge(300)){if(Date.now()>N)return{ok:!1,reason:"timeout",message:`${e?R(l,e):j(l)} did not answer${e?" with the document's title":""} in ${s/1e3}s (${g})${d?`; the server's output is in ${f}`:""}.`};if(d){let a=await te({...A,answering:!0});if(a&&a.pid!==d.pid){if(d.exitCode===null)try{process.kill(d.pid)}catch{}({port:l}=a),y={pid:a.pid,kind:(await oe(A))?.kind??"cli",version:null},d=null;continue}if(!a&&d.exitCode===null){g="the server started has not announced itself yet";continue}if(!a){if(!await re(l)){if(u=await E(p.indexOf(l)+1,[...b,`${l} (taken by another program while the server started)`]),u.failed)return u.failed;({port:l,started:d,passed:b}=u),y=u.running??null,N=Date.now()+s;continue}let c=await m.readFile(f,"utf8").catch(()=>"");return{ok:!1,reason:"stopped",message:`The Gallery server on port ${l} stopped (exit ${d.exitCode}). Its last words (${f}):
|
|
5
|
-
${c.split(`
|
|
6
|
-
`).slice(-15).join(`
|
|
7
|
-
`)}`}}}if(await B())break}return await m.writeFile(Y.lastPortFile,`${l}
|
|
8
|
-
`).catch(()=>{}),{ok:!0,port:l,pid:d?.pid??y?.pid??null,kind:y?.kind??"cli",started:!!d,replaced:W??null,passed:b}}var Ae=e=>e.length<2?e.join(""):`${e.slice(0,-1).join(", ")} and ${e.at(-1)}`;function Pe({port:e,pid:r,kind:t,started:s,replaced:n,passed:o=[]}){let p=[`pid ${r}`,...t==="dev"?["npm run dev's"]:[],...s?[`started now${o.length?`, after passing over ${Ae(o)}`:""}`]:[],...n?[`it replaced Gallery ${n.version??"an older version"}'s server, pid ${n.pid}`]:[]],L=s?`; its log: ${f}`:"";return`This workspace's Gallery server runs on port ${e} (${p.join(", ")}${L}). This command is done; the server runs on after it (nothing to wait for or keep running).`}async function Re(e,r,t=null){return[Pe(r),...e?[`${le}${ve(r.port,e)}`]:[],`${$}${e?await xe(r.port,{slug:e,block:t}):j(r.port)}`]}async function Ke(e,{skipped:r,command:t,ports:s=null}){let n=`gallery open ${e} starts it and prints the address to give the user`;if(r)return[`Preview: not started (--no-preview or ${D}): ${n}.`];let o=await be({slug:e,command:t,ports:s});return o.ok?Re(e,o):[`Preview: not started: ${o.message}`,`When that is fixed, ${n}.`]}export{$ as a,le as b,Ve as c,ze as d,Ue as e,ve as f,j as g,ke as h,be as i,Pe as j,Re as k,Ke as l};
|
package/dist/chunk-JL6R4FG4.mjs
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{b as i,f as a}from"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";import u from"node:path";import d from"node:fs/promises";import{SIDEBAR_FILE as g,readSidebarText as b}from"../browser/shared/extension-sidebar.mjs";import{extensionSource as k,listExtensions as v,readExtension as N}from"../browser/shared/extensions.mjs";import{isExtensionId as x}from"../browser/shared/outline-shape.mjs";import{withOutlineLock as E}from"../browser/shared/outline.mjs";import{reportsDirectory as c}from"../browser/shared/paths.mjs";import{defaultWorkspace as y,ensureWorkspace as S,layoutOf as f}from"../browser/shared/workspace.mjs";var w=n=>`${n} ${n===1?"entry":"entries"}`;function I(n){if(n.length>0)throw new i("list takes nothing: gallery extension check <id> reads one.");return v(c,{all:!0}).then(t=>{if(console.log(`Public columns: ${f(y()).extensions} (gallery extension new <id> "<title>"; --local for this project).`),t.length===0){console.log(`No extensions visible from ${c}. Use gallery extension new <id> "<title>" (references/extensions.md says how to fill its entries).`);return}console.log(`${t.length} extension${t.length===1?"":"s"} visible from ${c}:`);for(let o of t){let e=o.missing?`no ${g}: it gives the sidebar no column`:o.error?`\u6761\u76EE\u8BFB\u4E0D\u51FA\u6765\uFF1A${o.error.message}`:`${o.title}, ${w(o.count)}${o.notes.length?`, ${o.notes.length} note${o.notes.length===1?"":"s"}`:""}`;console.log(` ${o.id} ${e}`),console.log(` ${o.file}`)}console.log("gallery extension check <id> prints what the sidebar shows of one.")})}function p(n,t,o=[]){for(let e of n){let s=e.url?e.url:"(no address: a click opens and closes what is under it)";o.push(`${" ".repeat(t)}${e.id} ${e.icon?`${e.icon} `:""}${e.title} ${s}`),p(e.children??[],t+1,o)}return o}async function A(n){if(n.length!==1)throw new i("Name one extension: gallery extension check <id>.");let[t]=n;if(!x(t))throw new i(`Not an extension's id: ${t} (its folder's name under extensions/: lowercase letters, digits and dashes, 48 at most).`);let o=await k(c,t);o||(console.error(`No extension "${t}" visible from ${c}: gallery extension list shows them.`),process.exit(1));let e=await N(o.root,t),s=o.file;e.missing&&(console.error(`FAIL ${s}: there is no ${g}; the folder gives the sidebar no column until it has one (references/extensions.md says how it is written).`),process.exit(1)),e.error&&(console.error(`FAIL ${s}: ${e.error.message}`),console.error(`The sidebar shows the column "${e.title}" with one row: \u6761\u76EE\u8BFB\u4E0D\u51FA\u6765\uFF1A${e.error.message}`),process.exit(1)),console.log(`The sidebar shows the column ${e.title}${e.icon?` (${e.icon})`:""}, ${w(e.count)}, in the order the file gives (an entry with an address opens it beside the sidebar, one without opens and closes what is under it):`),console.log(e.title);for(let r of p(e.entries,1))console.log(r);for(let r of e.notes)console.log(`note: ${r.message}`);console.log(`OK ${t}: ${w(e.count)} (${s})`)}async function L(n,t){if(n.length!==2||!x(n[0]))throw new i('Use gallery extension new <id> "<title>" [--local].');let[o,e]=n,s=b(JSON.stringify({title:e,entries:[]}));if(s.error)throw new i(s.error.message);let r=t?c:y();if(!(await S(r)).ours)throw new i(`Not a Gallery workspace: ${r}`);let $=u.join(f(r).extensions,o),h=u.join($,g);await E(r,async()=>{for(let l of[f(r).extensions,$]){await d.mkdir(l,{recursive:!0});let m=await d.lstat(l);if(!m.isDirectory()||m.isSymbolicLink())throw new i(`Not an ordinary directory: ${l}`)}try{await d.writeFile(h,JSON.stringify({title:s.sidebar.title,entries:[]},null,2)+`
|
|
3
|
-
`,{flag:"wx"})}catch(l){throw l.code==="EEXIST"?new i(`Already exists: ${h}. Read and edit this file instead.`):l}}),console.log(`Created ${t?"project":"public"} extension ${o}
|
|
4
|
-
${h}`)}async function B(n){let[t,...o]=n;if(t==="new"){let{positional:e,options:s}=a({argv:o,options:["--local"]});return L(e,s.has("--local"))}if(t==="list"){let{positional:e}=a({argv:o});return I(e)}if(t==="check"){let{positional:e}=a({argv:o});return A(e)}throw new i(t?`No such action: extension ${t} (new, list, check).`:"Say what to do: gallery extension new <id> <title>, list or check <id>.")}export{B as run};
|
package/dist/chunk-KUILYI7H.mjs
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{a as w,b as k,c as f,g as u}from"./chunk-2GKGEVMR.mjs";import{readFileSync as x,realpathSync as E}from"node:fs";import p from"node:path";import{fileURLToPath as $}from"node:url";var S=p.dirname($(import.meta.url));function v(t=S){for(let e=t;;e=p.dirname(e)){try{let a=JSON.parse(x(p.join(e,"package.json"),"utf8"));if(a.name==="@heycys/gallery")return a.version}catch{}if(p.dirname(e)===e)return"0.0.0"}}var O={init:()=>import("./chunk-46ACXOU5.mjs"),new:()=>import("./chunk-QCEATQC4.mjs"),import:()=>import("./chunk-VNUWREXU.mjs"),open:()=>import("./chunk-L7W624FD.mjs"),serve:()=>import("./chunk-NIW7F7LU.mjs"),stop:()=>import("./chunk-EKNHM3P4.mjs"),check:()=>import("./chunk-5DPABPBI.mjs"),export:()=>import("./chunk-WCWYNFDF.mjs"),qa:()=>import("./chunk-AFGUR7SY.mjs"),list:()=>import("./chunk-6MPKCH3P.mjs"),workspaces:()=>import("./chunk-PAFSFVYB.mjs"),move:()=>import("./chunk-VA3KAQZD.mjs"),set:()=>import("./chunk-7M7UPWU6.mjs"),link:()=>import("./chunk-ZANMKAWS.mjs"),extension:()=>import("./chunk-JL6R4FG4.mjs"),block:()=>import("./chunk-YBB5LWZK.mjs"),page:()=>import("./chunk-DAMVDXR3.mjs"),skill:()=>import("./chunk-VGTMLQWZ.mjs")},j=new Set(["stop","init","skill","workspaces"]),N=(t,e)=>`${t.split(`
|
|
3
|
-
`)[0]} (gallery ${e?`${e} --help`:"help"} says more)`,g=t=>/^--.|^-[A-Za-z]/.test(t);function A(t){let e=t.indexOf("--"),a=e===-1?t:t.slice(0,e),h=e===-1?[]:t.slice(e),n=[],s=null;for(let r=0;r<a.length;r++){let o=a[r];if(o==="--workspace"||o.startsWith("--workspace=")){let c=o.includes("=")?o.slice(o.indexOf("=")+1):r+1<a.length&&!g(a[r+1])?a[++r]:"";if(!c)return{error:"--workspace takes a folder: --workspace <dir>",usage:u};if(s!==null&&p.resolve(s)!==p.resolve(c))return{error:`Two workspaces named: ${s} and ${c}.`,usage:u};s=c;continue}n.push(o)}if(n[0]==="--version"||n[0]==="-v"||n[0]==="-V")return n.length===1&&h.length===0?{version:!0}:{error:"--version takes nothing else.",usage:u};if(n.length===0||n[0]==="help"||n[0]==="--help"||n[0]==="-h"){let r=n[0]==="help"?n[1]:void 0;return r===void 0?{help:u}:Object.hasOwn(f,r)?{help:f[r]}:{error:`No such command: ${r} (${w.join(", ")}).`,usage:u}}let[d,...m]=n,l=k[d]??d;if(!Object.hasOwn(O,l))return{error:g(l)?`Unknown option: ${l} (the command comes first: gallery <command> [options]).`:`No such command: ${l} (${w.join(", ")}).`,usage:u};let i=[...m,...h];if(m.some(r=>r==="--help"||r==="-h"))return{help:f[l]};if(l==="init"){let r=new Set(["--from","--name"]),o=[];for(let c=0;c<m.length;c++)r.has(m[c])?c++:g(m[c])||o.push(m[c]);if(o.push(...h.slice(1)),o.length>1)return{error:"Name one folder at most.",usage:f.init,command:l};if(o.length===1){if(s!==null&&p.resolve(s)!==p.resolve(o[0]))return{error:`Two workspaces named: ${o[0]} and --workspace ${s}.`,usage:f.init,command:l};s=o[0]}}return{command:l,argv:i,flag:s}}var L=(t,e)=>`Cannot write the workspace ${t} (${e}): allow Gallery to write there, or pass --workspace <a folder you may write>.`,G=(t,e=!0)=>e?`${p.join(t,"gallery.json")} is not Gallery's (another program's file of that name): pass --workspace <another folder> for Gallery's documents.`:`${p.join(t,"gallery.json")} does not read as JSON: mend the file, or pass --workspace <another folder> for Gallery's documents.`;async function b(t=process.argv.slice(2)){process.stdout.on("error",i=>{throw i.code==="EPIPE"&&process.exit(process.exitCode??0),i});let e=A(t);if(e.version){let i=v();console.log(i);try{let{versionNotes:r}=await import("./chunk-TANZRINB.mjs");for(let o of r(i))console.log(o)}catch{}return}if(e.help)return void console.log(e.help);e.error&&(console.error(`${e.error}
|
|
4
|
-
${N(e.usage,e.command)}`),process.exit(2));let{command:a,flag:h}=e,{findWorkspace:n}=await import("../browser/shared/workspace.mjs"),s=n({flag:h});if(process.env.GALLERY_WORKSPACE=s.root,!j.has(a)){let{ensureWorkspace:i}=await import("../browser/shared/workspace.mjs");try{let{ours:o,reads:c}=await i(s.root);o||(console.error(G(s.root,c)),process.exit(1))}catch(o){if(!o.code)throw o;console.error(L(s.root,o.code)),process.exit(1)}let{registerQuietly:r}=await import("../browser/shared/workspace-registry.mjs");await r(s.root)}let{UsageError:d,usageFailureText:m}=await import("./chunk-GPIWQ4X4.mjs"),l=await O[a]();try{await l.run(e.argv,{command:a,workspace:s.root,how:s.how,version:v()})}catch(i){if(!(i instanceof d))throw i;console.error(m(f[a],i.message,i.synopsis)),process.exit(2)}}var y=t=>{try{return E.native(t)}catch{return null}};process.argv[1]&&y(process.argv[1])===y($(import.meta.url))&&b();export{v as a,A as b,L as c,G as d,b as e};
|
package/dist/chunk-NIW7F7LU.mjs
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{g as n,h as g}from"./chunk-JJNRIFND.mjs";import{b as m,f as d}from"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";import{spawn as P}from"node:child_process";import h from"node:fs/promises";import R from"node:path";import{projectRoot as v,release as k,reportsDirectory as t}from"../browser/shared/paths.mjs";import{answerOf as S,findPreviewServer as x,portIsFree as E,readAnnouncement as G}from"../browser/shared/preview-server.mjs";import{layoutOf as $}from"../browser/shared/workspace.mjs";var b=a=>new Promise(s=>setTimeout(s,a));async function O(a){let{positional:s,values:l}=d({values:["--port"],argv:a});if(s.length>0)throw new m(`gallery serve takes no arguments: ${s[0]}`);let o=l.has("--port")?Number(l.get("--port")):null;if(o!==null&&!(Number.isInteger(o)&&o>0&&o<65536))throw new m(`--port takes a port number: ${l.get("--port")}`);let i=await G({reportsDirectory:t}),f=i?await S(i,t,1e4):"no";f!=="no"&&(console.error(`This workspace's Gallery server runs already: ${n(i.port)} (pid ${i.pid}${f==="busy"?", not answering now":""}). gallery stop stops it; one server serves a workspace.`),process.exit(1));let r=null;if(o!==null)await E(o)||(console.error(`Port ${o} is taken: name another (--port), or leave it out for the first free one.`),process.exit(1)),r=o;else{for(let e of await g())if(await E(e)){r=e;break}r===null&&(console.error("No port from 4317 is free: name one (--port <n>)."),process.exit(1))}if(k){process.env.GALLERY_SERVER_KIND="cli";let{startProductionServer:e}=await import("./chunk-DLFZJJEE.mjs");await e({port:r,kind:"cli"}),await h.writeFile($(t).lastPortFile,`${r}
|
|
3
|
-
`).catch(()=>{}),console.log(`Gallery serves ${t} at ${n(r)} (Chrome or Edge). Ctrl+C stops it.`);return}let{writeSharedAssets:y}=await import("./chunk-DH6GMDNN.mjs");await y();let c=P(process.execPath,[R.join(v,"node_modules","vite","bin","vite.js"),"--host","127.0.0.1","--port",String(r),"--strictPort"],{cwd:v,env:{...process.env,GALLERY_WORKSPACE:t,GALLERY_SERVER_KIND:"cli"},stdio:"inherit"});for(let e of["SIGINT","SIGTERM"])process.on(e,()=>c.kill(e));let w=new Promise(e=>c.once("exit",(u,p)=>e(u??(p?1:0))));for(;;){let e=await Promise.race([w.then(p=>({code:p})),b(300).then(()=>null)]);if(e&&process.exit(e.code),(await x({reportsDirectory:t,answering:!0,timeout:2e3}))?.pid===c.pid)break}await h.writeFile($(t).lastPortFile,`${r}
|
|
4
|
-
`).catch(()=>{}),console.log(`Gallery serves ${t} at ${n(r)} (Chrome or Edge). Ctrl+C stops it.`),process.exit(await w)}export{O as run};
|