@heycys/gallery 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/THIRD-PARTY-NOTICES.md +2 -2
- package/browser/editor/components/align.mjs +58 -0
- package/browser/editor/components/code/index.mjs +1 -1
- package/browser/editor/components/embed/page.mjs +1 -1
- package/browser/editor/components/file/page.mjs +4 -4
- package/browser/editor/components/heading/index.mjs +7 -6
- package/browser/editor/components/icons.mjs +3 -0
- package/browser/editor/components/image/index.mjs +2 -0
- package/browser/editor/components/image/page.mjs +172 -90
- package/browser/editor/components/installed/index.mjs +6 -2
- package/browser/editor/components/installed/page.mjs +80 -13
- package/browser/editor/components/media/icons.mjs +13 -8
- package/browser/editor/components/media/page.mjs +5 -3
- package/browser/editor/components/media/toolbar.mjs +12 -3
- package/browser/editor/components/paragraph/index.mjs +4 -3
- package/browser/editor/components/registry.mjs +17 -5
- package/browser/editor/components/table/index.mjs +4 -2
- package/browser/editor/page/after/index.mjs +288 -0
- package/browser/editor/page/align.mjs +91 -0
- package/browser/editor/page/beside.mjs +5 -6
- package/browser/editor/page/block-menu/index.mjs +6 -3
- package/browser/editor/page/blocks.mjs +3 -1
- package/browser/editor/page/board/hint.mjs +64 -27
- package/browser/editor/page/board/index.mjs +160 -71
- package/browser/editor/page/board/motion.mjs +177 -0
- package/browser/editor/page/board/settings.mjs +4 -3
- package/browser/editor/page/clipboard/index.mjs +10 -3
- package/browser/editor/page/clipboard/own/blocks.mjs +3 -4
- package/browser/editor/page/clipboard/own/describe.mjs +6 -2
- package/browser/editor/page/commit.mjs +2 -2
- package/browser/editor/page/core.mjs +3 -1
- package/browser/editor/page/custom-page.mjs +15 -11
- package/browser/editor/page/editor.mjs +31 -14
- package/browser/editor/page/history.mjs +19 -4
- package/browser/editor/page/insert/index.mjs +20 -22
- package/browser/editor/page/menu.mjs +15 -7
- package/browser/editor/page/page-objects.mjs +3 -7
- package/browser/editor/page/present-links.mjs +5 -4
- package/browser/editor/page/present-shell.mjs +63 -0
- package/browser/editor/page/selection/index.mjs +10 -2
- package/browser/editor/page/table/binding.mjs +87 -0
- package/browser/editor/page/table/icons.mjs +0 -2
- package/browser/editor/page/table/index.mjs +10 -14
- package/browser/editor/page/table/views.mjs +5 -52
- package/browser/editor/page/table/widths.mjs +82 -10
- package/browser/editor/page/typing/index.mjs +44 -12
- package/browser/editor/page/typing/leave.mjs +19 -5
- package/browser/shared/block-packs.mjs +23 -8
- package/browser/shared/component-catalog.mjs +15 -8
- package/browser/shared/component-source.mjs +3 -1
- package/browser/shared/components/heading.mjs +2 -1
- package/browser/shared/components/installed.mjs +1 -1
- package/browser/shared/components/page.mjs +2 -0
- package/browser/shared/components/paragraph.mjs +8 -1
- package/browser/shared/components/table.mjs +1 -0
- package/browser/shared/emoji/line-icons.mjs +37 -0
- package/browser/shared/http.mjs +9 -0
- package/browser/shared/i18n/en.mjs +40 -17
- package/browser/shared/outline.mjs +30 -2
- package/browser/shared/pack-manifest.mjs +12 -1
- package/browser/shared/pages.mjs +169 -57
- package/browser/shared/pinyin.mjs +92 -0
- package/browser/shared/present-step.mjs +17 -0
- package/browser/shared/sidebar-head.mjs +70 -0
- package/browser/shared/web-links.mjs +5 -0
- package/dist/chunk-2OHANJ6Q.mjs +2 -0
- package/dist/{chunk-QOUEFUCH.mjs → chunk-3MBRL2PM.mjs} +1 -1
- package/dist/{chunk-NWR2LT5B.mjs → chunk-4OKWZY5E.mjs} +1 -1
- package/dist/{chunk-RMECZA2K.mjs → chunk-5K44HLTZ.mjs} +1 -1
- package/dist/{chunk-NFMCP2HI.mjs → chunk-5XA2ZBAE.mjs} +2 -2
- package/dist/{chunk-OUUP3WKT.mjs → chunk-67N2QJYT.mjs} +1 -1
- package/dist/chunk-6KBYRA2C.mjs +2 -0
- package/dist/{chunk-SX4LJYT6.mjs → chunk-6N3PX4XX.mjs} +1 -1
- package/dist/{chunk-RFDZXFJF.mjs → chunk-7JDX4E65.mjs} +1 -1
- package/dist/chunk-7M2BQQGZ.mjs +2 -0
- package/dist/{chunk-ZUNVAXLH.mjs → chunk-7OG26PGF.mjs} +1 -1
- package/dist/{chunk-B4P2CM2J.mjs → chunk-AHN3NFKJ.mjs} +1 -1
- package/dist/chunk-ALZ6ZENZ.mjs +3 -0
- package/dist/{chunk-UGWYKHBL.mjs → chunk-AR5D57ZD.mjs} +2 -2
- package/dist/{chunk-W3BGBJQW.mjs → chunk-BFJGHSQN.mjs} +1 -1
- package/dist/{chunk-HLYV7RIH.mjs → chunk-CMA72MAG.mjs} +1 -1
- package/dist/{chunk-D4CKRD3V.mjs → chunk-DAZL73VK.mjs} +2 -2
- package/dist/{chunk-6VTU6KEO.mjs → chunk-DJISHPUL.mjs} +1 -1
- package/dist/{chunk-BPL64HGA.mjs → chunk-EAIFITAV.mjs} +1 -1
- package/dist/chunk-EP25HDAJ.mjs +2 -0
- package/dist/{chunk-6EZ7FNIK.mjs → chunk-F4ZA6JRZ.mjs} +1 -1
- package/dist/{chunk-3KJHLHUO.mjs → chunk-F6HVDZR4.mjs} +1 -1
- package/dist/{chunk-3NJACR4W.mjs → chunk-FDMAXMQA.mjs} +1 -1
- package/dist/chunk-FETSREUN.mjs +5 -0
- package/dist/{chunk-RKPWLGZ3.mjs → chunk-GHOYKMQ3.mjs} +1 -1
- package/dist/chunk-HDWTZ763.mjs +12 -0
- package/dist/{chunk-VTKNEYT3.mjs → chunk-HPOI4ZX7.mjs} +1 -1
- package/dist/{chunk-OW5NWPOJ.mjs → chunk-HXG7EOPJ.mjs} +1 -1
- package/dist/{chunk-V6RIYQZZ.mjs → chunk-ITOH5EGO.mjs} +1 -1
- package/dist/{chunk-ZWPMCK7P.mjs → chunk-IV64FFI4.mjs} +1 -1
- package/dist/chunk-J43Z6LSS.mjs +2 -0
- package/dist/chunk-J5PUIV3Y.mjs +4 -0
- package/dist/{chunk-KTKHRC6H.mjs → chunk-JA7G53PC.mjs} +1 -1
- package/dist/{chunk-NWFBE2YA.mjs → chunk-JLTZF4LA.mjs} +1 -1
- package/dist/{chunk-GY3FAUVM.mjs → chunk-JZT7I2OJ.mjs} +1 -1
- package/dist/{chunk-QKXMPUXC.mjs → chunk-K5XATEOO.mjs} +1 -1
- package/dist/chunk-L2SUIS5S.mjs +2 -0
- package/dist/{chunk-TEZAWDSQ.mjs → chunk-LM4XFQHZ.mjs} +1 -1
- package/dist/{chunk-5ZJA7CXT.mjs → chunk-MN7BZL4R.mjs} +1 -1
- package/dist/chunk-MTYYHM2G.mjs +15 -0
- package/dist/{chunk-HMYTM3GT.mjs → chunk-MXUBKDRO.mjs} +1 -1
- package/dist/{chunk-MHW7ZKOU.mjs → chunk-OEXWRJME.mjs} +1 -1
- package/dist/{chunk-CRJEG7MT.mjs → chunk-OFHXGWOX.mjs} +1 -1
- package/dist/chunk-ORID3AE7.mjs +166 -0
- package/dist/{chunk-32ZUEFZ7.mjs → chunk-PGDE24N5.mjs} +1 -1
- package/dist/{chunk-UNOYVIYR.mjs → chunk-POTA2FV4.mjs} +1 -1
- package/dist/{chunk-N7AZZLGT.mjs → chunk-QE5RG76S.mjs} +18 -17
- package/dist/{chunk-N76HWBA3.mjs → chunk-R2ZDLJYT.mjs} +1 -1
- package/dist/chunk-SWUTTZCN.mjs +2 -0
- package/dist/{chunk-POQSE4C2.mjs → chunk-TR7TWGHB.mjs} +1 -1
- package/dist/chunk-U5XL7D6A.mjs +3 -0
- package/dist/{chunk-PVER7LSC.mjs → chunk-U7NZI6N4.mjs} +2 -2
- package/dist/{chunk-Q47PLKIJ.mjs → chunk-UGWMMEJ5.mjs} +1 -1
- package/dist/chunk-UJQJKNGK.mjs +2 -0
- package/dist/chunk-UYVCQK3H.mjs +22 -0
- package/dist/{chunk-FJYN7RTH.mjs → chunk-VFX2KNHP.mjs} +1 -1
- package/dist/{chunk-UBBRTJ2R.mjs → chunk-VS7JIGJW.mjs} +1 -1
- package/dist/{chunk-NVRNLK25.mjs → chunk-W7665ZEC.mjs} +2 -2
- package/dist/{chunk-NG375ILQ.mjs → chunk-WQDQWCX5.mjs} +1 -1
- package/dist/chunk-YLPSMDIS.mjs +5 -0
- package/dist/{chunk-VXACTLO3.mjs → chunk-YNAWBAYN.mjs} +1 -1
- package/dist/{chunk-ZB4H7ZN4.mjs → chunk-YROX2O22.mjs} +1 -1
- package/dist/{chunk-YQGT4AB2.mjs → chunk-ZDLPUOAG.mjs} +1 -1
- package/dist/chunk-ZQS6H473.mjs +16 -0
- package/dist/{chunk-OJKMINIU.mjs → chunk-ZWWC4KLF.mjs} +15 -15
- package/dist/cli.mjs +1 -1
- package/dist/server.mjs +1 -1
- package/dist/worker.mjs +1 -1
- package/kit/board.css +5 -5
- package/kit/code.js +15 -15
- package/kit/report.css +120 -41
- package/kit/runtime.js +45 -7
- package/kit/tables.js +2 -0
- package/kit/ui.js +2 -0
- package/package.json +1 -1
- package/packs/gallery/chart-view/kit.js +3 -3
- package/packs/gallery/chart-view/writing.md +1 -1
- package/packs/gallery/countdown/component.json +1 -1
- package/packs/gallery/countdown/kit.js +89 -29
- package/packs/gallery/countdown/preview.svg +1 -1
- package/packs/gallery/countdown/style.css +88 -100
- package/packs/gallery/countdown/writing.md +2 -2
- package/packs/gallery/habit/component.json +3 -3
- package/packs/gallery/habit/kit.js +114 -75
- package/packs/gallery/habit/preview.svg +1 -1
- package/packs/gallery/habit/style.css +133 -205
- package/packs/gallery/habit/writing.md +2 -2
- package/packs/gallery/heatmap/component.json +2 -2
- package/packs/gallery/heatmap/kit.js +335 -173
- package/packs/gallery/heatmap/preview.svg +1 -1
- package/packs/gallery/heatmap/style.css +158 -170
- package/packs/gallery/heatmap/writing.md +2 -2
- package/packs/gallery/kanban/kit.js +3 -3
- package/packs/gallery/kanban/writing.md +1 -1
- package/packs/gallery/metric/kit.js +3 -3
- package/packs/gallery/metric/writing.md +1 -1
- package/packs/gallery/note/component.json +3 -3
- package/packs/gallery/note/kit.js +40 -13
- package/packs/gallery/note/preview.svg +1 -1
- package/packs/gallery/note/style.css +51 -30
- package/packs/gallery/note/writing.md +2 -2
- package/packs/gallery/recent/component.json +2 -2
- package/packs/gallery/recent/kit.js +141 -86
- package/packs/gallery/recent/preview.svg +1 -1
- package/packs/gallery/recent/style.css +53 -126
- package/packs/gallery/recent/writing.md +2 -2
- package/packs/gallery/static/component.json +2 -2
- package/packs/gallery/static/preview.svg +1 -1
- package/packs/gallery/static/style.css +99 -66
- package/packs/gallery/static/writing.md +2 -2
- package/packs/gallery/stats/component.json +3 -3
- package/packs/gallery/stats/kit.js +253 -72
- package/packs/gallery/stats/preview.svg +1 -1
- package/packs/gallery/stats/style.css +64 -142
- package/packs/gallery/stats/writing.md +2 -2
- package/packs/gallery/today/component.json +2 -2
- package/packs/gallery/today/kit.js +62 -27
- package/packs/gallery/today/preview.svg +1 -1
- package/packs/gallery/today/style.css +101 -72
- package/packs/gallery/today/writing.md +2 -2
- package/packs/gallery/todos/component.json +1 -1
- package/packs/gallery/todos/kit.js +218 -71
- package/packs/gallery/todos/preview.svg +1 -1
- package/packs/gallery/todos/style.css +170 -223
- package/packs/gallery/todos/writing.md +1 -1
- package/packs/gallery/weather/component.json +2 -2
- package/packs/gallery/weather/kit.js +165 -90
- package/packs/gallery/weather/preview.svg +1 -1
- package/packs/gallery/weather/style.css +100 -218
- package/packs/gallery/weather/writing.md +1 -1
- package/packs/gallery-soft/countdown/component.json +18 -0
- package/packs/gallery-soft/countdown/example.html +3 -0
- package/packs/gallery-soft/countdown/kit.js +206 -0
- package/packs/gallery-soft/countdown/preview.svg +1 -0
- package/packs/gallery-soft/countdown/style.css +211 -0
- package/packs/gallery-soft/countdown/template.html +3 -0
- package/packs/gallery-soft/countdown/writing.md +24 -0
- package/packs/gallery-soft/habit/component.json +14 -0
- package/packs/gallery-soft/habit/example.html +3 -0
- package/packs/gallery-soft/habit/kit.js +366 -0
- package/packs/gallery-soft/habit/preview.svg +1 -0
- package/packs/gallery-soft/habit/style.css +251 -0
- package/packs/gallery-soft/habit/template.html +3 -0
- package/packs/gallery-soft/habit/writing.md +23 -0
- package/packs/gallery-soft/heatmap/component.json +18 -0
- package/packs/gallery-soft/heatmap/example.html +3 -0
- package/packs/gallery-soft/heatmap/kit.js +498 -0
- package/packs/gallery-soft/heatmap/preview.svg +1 -0
- package/packs/gallery-soft/heatmap/style.css +181 -0
- package/packs/gallery-soft/heatmap/template.html +3 -0
- package/packs/gallery-soft/heatmap/writing.md +23 -0
- package/packs/gallery-soft/note/component.json +14 -0
- package/packs/gallery-soft/note/example.html +3 -0
- package/packs/gallery-soft/note/kit.js +162 -0
- package/packs/gallery-soft/note/preview.svg +1 -0
- package/packs/gallery-soft/note/style.css +148 -0
- package/packs/gallery-soft/note/template.html +3 -0
- package/packs/gallery-soft/note/writing.md +20 -0
- package/packs/gallery-soft/recent/component.json +13 -0
- package/packs/gallery-soft/recent/example.html +1 -0
- package/packs/gallery-soft/recent/kit.js +335 -0
- package/packs/gallery-soft/recent/preview.svg +1 -0
- package/packs/gallery-soft/recent/style.css +160 -0
- package/packs/gallery-soft/recent/template.html +1 -0
- package/packs/gallery-soft/recent/writing.md +17 -0
- package/packs/gallery-soft/static/component.json +13 -0
- package/packs/gallery-soft/static/example.html +12 -0
- package/packs/gallery-soft/static/preview.svg +1 -0
- package/packs/gallery-soft/static/style.css +186 -0
- package/packs/gallery-soft/static/template.html +1 -0
- package/packs/gallery-soft/static/writing.md +20 -0
- package/packs/gallery-soft/stats/component.json +13 -0
- package/packs/gallery-soft/stats/example.html +1 -0
- package/packs/gallery-soft/stats/kit.js +341 -0
- package/packs/gallery-soft/stats/preview.svg +1 -0
- package/packs/gallery-soft/stats/style.css +119 -0
- package/packs/gallery-soft/stats/template.html +1 -0
- package/packs/gallery-soft/stats/writing.md +13 -0
- package/packs/gallery-soft/today/component.json +12 -0
- package/packs/gallery-soft/today/example.html +1 -0
- package/packs/gallery-soft/today/kit.js +222 -0
- package/packs/gallery-soft/today/preview.svg +1 -0
- package/packs/gallery-soft/today/style.css +178 -0
- package/packs/gallery-soft/today/template.html +1 -0
- package/packs/gallery-soft/today/writing.md +16 -0
- package/packs/gallery-soft/todos/component.json +19 -0
- package/packs/gallery-soft/todos/example.html +3 -0
- package/packs/gallery-soft/todos/kit.js +527 -0
- package/packs/gallery-soft/todos/preview.svg +1 -0
- package/packs/gallery-soft/todos/style.css +212 -0
- package/packs/gallery-soft/todos/template.html +3 -0
- package/packs/gallery-soft/todos/writing.md +32 -0
- package/packs/gallery-soft/weather/component.json +19 -0
- package/packs/gallery-soft/weather/example.html +3 -0
- package/packs/gallery-soft/weather/kit.js +411 -0
- package/packs/gallery-soft/weather/preview.svg +1 -0
- package/packs/gallery-soft/weather/style.css +185 -0
- package/packs/gallery-soft/weather/template.html +3 -0
- package/packs/gallery-soft/weather/writing.md +28 -0
- package/release.json +9 -9
- package/skill/SKILL.md +12 -12
- package/skill/references/building-blocks.md +4 -4
- package/skill/references/pages-and-data.md +13 -9
- package/skill/references/writing-html.md +2 -0
- package/web/assets/index-BM_K-Auu.css +1 -0
- package/web/assets/index-DRslOBiv.js +15 -0
- package/web/index.html +2 -2
- package/dist/chunk-2NRBY6AJ.mjs +0 -2
- package/dist/chunk-35NQ4PLQ.mjs +0 -2
- package/dist/chunk-4AV456RQ.mjs +0 -2
- package/dist/chunk-5XYHDBJ5.mjs +0 -2
- package/dist/chunk-6A53MZYZ.mjs +0 -2
- package/dist/chunk-6EXH3ORZ.mjs +0 -166
- package/dist/chunk-BVEFGE4B.mjs +0 -2
- package/dist/chunk-D4EURAX4.mjs +0 -4
- package/dist/chunk-DQCE7TJY.mjs +0 -5
- package/dist/chunk-FWNRPMCJ.mjs +0 -12
- package/dist/chunk-FWW4CSAZ.mjs +0 -2
- package/dist/chunk-JVHHHGEA.mjs +0 -3
- package/dist/chunk-PZDLJJTJ.mjs +0 -3
- package/dist/chunk-SXHBYZST.mjs +0 -16
- package/dist/chunk-UFNYFFKO.mjs +0 -20
- package/dist/chunk-UKSHDZZ6.mjs +0 -2
- package/dist/chunk-VJPFVNNW.mjs +0 -15
- package/dist/chunk-VS3ZMVGX.mjs +0 -5
- package/web/assets/index-BK2e_07w.js +0 -13
- package/web/assets/index-CWFI83mF.css +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{d as a,e as b,f as c,g as d}from"./chunk-
|
|
2
|
+
import{d as a,e as b,f as c,g as d}from"./chunk-R2ZDLJYT.mjs";import"./chunk-VFX2KNHP.mjs";import"./chunk-VS7JIGJW.mjs";import"./chunk-HDWTZ763.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";export{a as commitEdits,c as revertedParts,d as revertedTexts,b as revertedUnits};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
+
import{a}from"./chunk-ORID3AE7.mjs";import"./chunk-DR73Y2UJ.mjs";import"./chunk-JLTZF4LA.mjs";import"./chunk-PUOQ65NC.mjs";import"./chunk-7OG26PGF.mjs";import"./chunk-DJISHPUL.mjs";import"./chunk-ZWWC4KLF.mjs";import"./chunk-AHN3NFKJ.mjs";import"./chunk-MTYYHM2G.mjs";import"./chunk-ALZ6ZENZ.mjs";import"./chunk-IA4PSIMD.mjs";import"./chunk-2OHANJ6Q.mjs";import"./chunk-F4ZA6JRZ.mjs";import"./chunk-7M2BQQGZ.mjs";import"./chunk-ITOH5EGO.mjs";import"./chunk-ZQS6H473.mjs";import"./chunk-UYVCQK3H.mjs";import"./chunk-J5PUIV3Y.mjs";import"./chunk-MXUBKDRO.mjs";import"./chunk-HXG7EOPJ.mjs";import"./chunk-ZTHICSSF.mjs";import"./chunk-6N3PX4XX.mjs";import"./chunk-PAREWQGB.mjs";import"./chunk-BFJGHSQN.mjs";import"./chunk-U5XL7D6A.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-R2ZDLJYT.mjs";import"./chunk-VFX2KNHP.mjs";import"./chunk-VS7JIGJW.mjs";import"./chunk-HDWTZ763.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";export{a as startProductionServer};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{a,b,c}from"./chunk-
|
|
2
|
+
import{a,b,c}from"./chunk-YROX2O22.mjs";import"./chunk-5XA2ZBAE.mjs";import"./chunk-JA7G53PC.mjs";import"./chunk-YI43RG4P.mjs";import"./chunk-NAMN3RAF.mjs";import"./chunk-JEUK3ZO7.mjs";import"./chunk-GHOYKMQ3.mjs";import"./chunk-QE5RG76S.mjs";import"./chunk-4OZWXZE5.mjs";import"./chunk-PAREWQGB.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";export{a as DEFAULT_DESCRIPTION,c as run,b as slugRefused};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{a,b}from"./chunk-
|
|
2
|
+
import{a,b}from"./chunk-JA7G53PC.mjs";import"./chunk-YI43RG4P.mjs";import"./chunk-NAMN3RAF.mjs";import"./chunk-JEUK3ZO7.mjs";import"./chunk-GHOYKMQ3.mjs";import"./chunk-QE5RG76S.mjs";import"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";export{a as nameHint,b as run};
|
|
@@ -0,0 +1,15 @@
|
|
|
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 Dt,b as qt}from"./chunk-ALZ6ZENZ.mjs";import{a as Zt}from"./chunk-UMHUSOPJ.mjs";import{randomBytes as _t}from"node:crypto";import b from"node:fs/promises";import g from"node:path";import{writeAtomic as G}from"../browser/shared/files.mjs";import{sendJson as H}from"../browser/shared/http.mjs";import{said as tt,saying as Tt}from"../browser/shared/i18n/index.mjs";import{reportsDirectory as Ge}from"../browser/shared/paths.mjs";import{moveDocument as Ye,outlineAndFile as We,placeIn as vt,readOutline as He,validOutline as ae,withOutlineLock as Me,writeHead as Be,writeOutline as Ve,writtenAs as Ue}from"../browser/shared/outline.mjs";import{storedHead as Ke}from"../browser/shared/sidebar-head.mjs";import{DOCS as xt,isForeign as ie,isTop as Et,topOf as At}from"../browser/shared/outline-shape.mjs";import{addDraft as se,addWorkspace as ze,draftEntry as ut,draftFacts as ce,draftOf as Ct,findDraft as Xe,foreignMarker as Qe,projectChoices as Ze,registeredIds as le,workspaceNames as De,workspaceOf as M}from"../browser/shared/drafts.mjs";import{forgetSnapshot as nt,shownWorkspaces as qe}from"../browser/shared/workspace-columns.mjs";import{nameStops as tn}from"../browser/shared/workspace-name.mjs";import{registerWorkspace as en,workspaceId as Pt,workspaceKey as ue}from"../browser/shared/workspace-registry.mjs";import{spawn as ne}from"node:child_process";import xe from"node:http";import Ee from"node:os";import Rt from"node:path";import{NO_DEFAULT_TREE as Ae}from"../browser/shared/drafts.mjs";import{said as te}from"../browser/shared/i18n/index.mjs";import{packageRoot as Pe}from"../browser/shared/paths.mjs";import{answerOf as ee,compareVersions as Le,galleryVersion as Ne,readAnnouncement as $t}from"../browser/shared/preview-server.mjs";import{isWorkspace as Ie,readRegistry as $e,workspaceId as Re,workspaceKey as St}from"../browser/shared/workspace-registry.mjs";var bt={rename:{to:"workspace",fields:["slug","title"]},create:{to:"workspace",fields:["title","description","language"]},trash:{to:"workspace",fields:["slug"]},restore:{to:"workspace",fields:["id"]},duplicate:{to:"workspace",fields:["slug","suffix","untitled"]},look:{to:"workspace",fields:["slug","look"]},looks:{to:"workspace",fields:["slug"]},markdown:{to:"transfer",fields:["slug"]},import:{to:"transfer",fields:["uploads","parent","from","language"]},annotations:{to:"edit",fields:["slug","restore"]},export:{to:"transfer",fields:["slug","options"],file:"out",timeout:6e5},upload:{to:"transfer",fields:[],query:["name"],file:"in",timeout:36e5}},_e=["content-type","content-length","content-disposition","x-file-name","cache-control"],Te=9e4,Ce=m=>!["","0",void 0].includes(m);function Fe(m,{platform:x=process.platform,env:l=process.env}={}){return Ce(l.GALLERY_NO_BROWSER)?{skip:"GALLERY_NO_BROWSER is set"}:x==="win32"?{command:Rt.join(l.SystemRoot||l.windir||"C:\\Windows","explorer.exe"),args:[`/select,"${m}"`],verbatim:!0}:x==="darwin"?{command:"open",args:["-R",m]}:!l.DISPLAY&&!l.WAYLAND_DISPLAY?{skip:"no display here (neither DISPLAY nor WAYLAND_DISPLAY is set)"}:{command:"xdg-open",args:[Rt.dirname(m)]}}function re(m,x){let l=Fe(m,x);return l.skip?Promise.resolve({opened:!1,why:l.skip}):new Promise($=>{let _;try{_=ne(l.command,l.args,{detached:!0,stdio:"ignore",windowsHide:!1,windowsVerbatimArguments:!!l.verbatim})}catch(N){return $({opened:!1,why:N.code??N.message})}_.once("error",N=>$({opened:!1,why:N.code??N.message})),_.once("spawn",()=>{_.unref(),$({opened:!0})})})}function Je(m){let x=/^http:\/\/127\.0\.0\.1:(\d{1,5})$/.exec(String(m??"")),l=x?Number(x[1]):0;return l>0&&l<65536?l:null}function oe({root:m,changed:x=()=>{},log:l=()=>{},gallery:$=Rt.join(Pe,"bin","gallery.mjs")}){let _=St(m),N=new Map;function Nt(p){let d={...process.env,[Ae]:"1",GALLERY_NO_UPDATE_CHECK:"1"};return delete d.GALLERY_WORKSPACE,delete d.GALLERY_SERVER_KIND,d.GALLERY_VITE_CACHE_DIR&&(d.GALLERY_VITE_CACHE_DIR=`${d.GALLERY_VITE_CACHE_DIR}-${Re(p)}`),new Promise(S=>{let h=[],j;try{j=ne(process.execPath,[$,"--workspace",p,"open","--no-browser"],{cwd:Ee.homedir(),env:d,stdio:["ignore","pipe","pipe"],windowsHide:!0})}catch(P){return S({ok:!1,message:P.message})}j.stdout.on("data",P=>h.push(String(P))),j.stderr.on("data",P=>h.push(String(P)));let v=setTimeout(()=>j.kill(),Te);j.once("error",P=>{clearTimeout(v),S({ok:!1,message:P.message})}),j.once("exit",P=>{clearTimeout(v);let w=h.join("").trim().split(/\r?\n/).filter(Boolean);S(P===0?{ok:!0}:{ok:!1,message:w.slice(-3).join(" ")||`gallery open ended with ${P}`})})})}async function mt(p){let d=await $t({reportsDirectory:p});return!d||await ee(d,p,5e3)!=="yes"||d.kind!=="dev"&&Le(d.version,Ne)<0?null:{port:d.port,token:d.token,pid:d.pid}}async function Y(p,{start:d=!0}={}){if(St(p)===_)return{refused:"self",message:"\u8FD9\u662F\u5F53\u524D\u7684\u5DE5\u4F5C\u533A"};if(!Ie(p))return{refused:"workspace",message:te("\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A{0} \u4E0D\u5728\u4E86",p)};let S=await mt(p);if(S||!d)return S??{refused:"start",message:"\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u5728\u8FD0\u884C"};let h=St(p);N.has(h)||(l(`starting the server of ${p}`),N.set(h,Nt(p).finally(()=>N.delete(h))));let j=await N.get(h);return await mt(p)??{refused:"start",message:j.ok?"\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u56DE\u7B54":te("\u6CA1\u80FD\u542F\u52A8\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\uFF1A{0}",j.message)}}let pt=(p,d,S,h)=>{let j=bt[d],v=Object.fromEntries(j.fields.filter(w=>S?.[w]!==void 0).map(w=>[w,S[w]])),P=new URLSearchParams((j.query??[]).filter(w=>h?.[w]!==void 0).map(w=>[w,String(h[w])]));return{fields:v,host:`127.0.0.1:${p.port}`,path:`/__gallery/${j.to}/${d}${P.size?`?${P}`:""}`}};async function E(p,d,S){if(!Object.hasOwn(bt,d)||bt[d].file)return[404,{ok:!1,reason:"unknown",message:"\u8FD9\u4E2A\u547D\u4EE4\u4E0D\u80FD\u8F6C\u7ED9\u522B\u7684\u5DE5\u4F5C\u533A"}];let h=await Y(p);if(h.refused)return[409,{ok:!1,reason:h.refused,message:h.message}];let{fields:j,host:v,path:P}=pt(h,d,S);try{let w=await fetch(`http://${v}${P}`,{method:"POST",headers:{"Content-Type":"application/json",Origin:`http://${v}`,"X-Gallery-Token":h.token},body:JSON.stringify(j),signal:AbortSignal.timeout(3e4)}),V=await w.json().catch(()=>null);return V&&typeof V.ok=="boolean"?[w.status,V]:[502,{ok:!1,reason:"answer",message:"\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u7ED9\u51FA\u7ED3\u679C"}]}catch{return[502,{ok:!1,reason:"answer",message:"\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u56DE\u7B54"}]}}async function F(p,d,{body:S={},query:h={},request:j=null,response:v}){let P=bt[d];if(!P?.file)return[404,{ok:!1,reason:"unknown",message:"\u8FD9\u4E2A\u547D\u4EE4\u4E0D\u80FD\u8F6C\u7ED9\u522B\u7684\u5DE5\u4F5C\u533A"}];let w=await Y(p);if(w.refused)return[409,{ok:!1,reason:w.refused,message:w.message}];let{fields:V,host:Z,path:J}=pt(w,d,S,h);return new Promise(it=>{let W={Origin:`http://${Z}`,"X-Gallery-Token":w.token},U=P.file==="out"?Buffer.from(JSON.stringify(V)):null;U?Object.assign(W,{"Content-Type":"application/json","Content-Length":U.length}):Object.assign(W,{"Content-Type":"application/octet-stream",...j.headers["content-length"]?{"Content-Length":j.headers["content-length"]}:{}});let st=[502,{ok:!1,reason:"answer",message:"\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u56DE\u7B54"}],K=xe.request({host:"127.0.0.1",port:w.port,path:J,method:"POST",headers:W,timeout:P.timeout},L=>{v.writeHead(L.statusCode??502,Object.fromEntries(_e.filter(C=>L.headers[C]!==void 0).map(C=>[C,L.headers[C]]))),L.pipe(v),L.once("end",()=>it(null)),L.once("error",()=>{v.destroy(),it(null)})});K.once("timeout",()=>K.destroy()),K.once("error",()=>{v.headersSent?(v.destroy(),it(null)):it(st)}),v.once("close",()=>{v.writableEnded||K.destroy()}),U?K.end(U):j.pipe(K)})}let kt=new Map;async function ht(p){let d=Je(p);if(d===null)return!1;let S=kt.get(d);if(S&&Date.now()-S.at<6e4)return S.answer;let h=(async()=>{for(let{root:j}of $e().workspaces){let v=await $t({reportsDirectory:j});if(v?.port===d&&await ee(v,j,3e3)==="yes")return!0}return!1})();return kt.set(d,{at:Date.now(),answer:h}),h}let B=new Map,c=new Map,ot=new Set,X=!1;async function Q(p,d,S){let h=new AbortController,j={controller:h,port:S.port};c.set(p,j);try{let v=await fetch(`http://127.0.0.1:${S.port}/__gallery/events?workspace=own`,{signal:h.signal});if(!v.ok||!v.body)return;ot.has(p)&&x(d),ot.add(p);let P=new TextDecoder,w="";for await(let V of v.body){w+=P.decode(V,{stream:!0});for(let Z=w.indexOf(`
|
|
3
|
+
|
|
4
|
+
`);Z>=0;Z=w.indexOf(`
|
|
5
|
+
|
|
6
|
+
`)){let J=w.slice(0,Z);w=w.slice(Z+2),/^data: workspace /m.test(J)&&x(d)}}}catch{}finally{c.get(p)===j&&c.delete(p)}}async function A(){for(let[p,d]of c)B.has(p)||d.controller.abort();for(let[p,d]of B){if(X||c.has(p)||St(d)===_)continue;let S=await $t({reportsDirectory:d});S&&!c.has(p)&&!X&&Q(p,d,S)}}let T=Promise.resolve(),at=setInterval(()=>{T=T.then(A).catch(()=>{})},3e3);at.unref();function gt(p){B.clear();for(let[d,S]of p)S&&B.set(d,S);T=T.then(A).catch(()=>{})}function yt(){X=!0,clearInterval(at);for(let{controller:p}of c.values())p.abort();c.clear()}return{serverOf:Y,forward:E,relay:F,shellVouched:ht,follow:gt,close:yt,get following(){return[...c.keys()]}}}import{LINK_FILE as Ft,linkStem as nn,linkValue as ft,ownAddress as Jt,readLinkText as rn}from"../browser/shared/web-links.mjs";import{sameDirectory as rt}from"../browser/shared/preview-server.mjs";import{listReportSlugs as on,slugPattern as I}from"../browser/shared/reports.mjs";import{COMPONENTS_FOLDER as an,DOCUMENT_FOLDERS as sn,PAGE_SLUG as cn,SHARED_FOLDERS as Gt,defaultWorkspace as ln,documentDirectory as un,documentFiles as dt,ensureWorkspace as fn,idHolder as dn,isDocSlug as wn,layoutOf as fe,listTrash as mn,newDocSlug as Yt,packageFolders as pn,pageSlug as kn,readLink as Wt,slugTaken as hn,trashIdPattern as de}from"../browser/shared/workspace.mjs";import{createPage as gn,headOf as we,listPages as yn,newPageSlug as On,pageFiles as wt,readPageMeta as Ht,renamePage as jn}from"../browser/shared/pages.mjs";import{listExtensions as Sn}from"../browser/shared/extensions.mjs";import{effectiveLook as Mt,ownLookFor as bn,ownLookOf as vn,sameLook as xn,withLookField as me}from"../browser/shared/document-look.mjs";import{workspaceLook as Bt,writeWorkspaceLook as En}from"../browser/shared/workspace-look.mjs";import{findIn as An,tidyQuery as Pn}from"../browser/shared/search.mjs";var Ln=([m,x,l,...$])=>$.length?tt("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}\uFF1B{2} \u7B49 {3} \u6761",m,x,l,$.length+3):l!==void 0?tt("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}\uFF1B{2}",m,x,l):x!==void 0?tt("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}",m,x):tt("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}",m),Lt=m=>m==="en"?"en":null,Nn=32*1024*1024;async function q(m,x){for(let l=0;;l++)try{return await b.rename(m,x)}catch($){if(!["EPERM","EBUSY","EACCES"].includes($.code))throw $;if(l>=5)break;await new Promise(_=>setTimeout(_,60*(l+1)))}await b.cp(m,x,{recursive:!0,errorOnExist:!0,force:!1}),await b.rm(m,{recursive:!0,force:!0,maxRetries:5})}var In=m=>g.resolve(m);function pr({edits:m,reports:x,reportsDirectory:l=Ge,server:$={kind:"dev",version:null,stop:null},components:_=null,changed:N=()=>{},relayed:Nt=N,index:mt=null,web:Y=null,elsewhere:pt=null}){let{trash:E}=fe(l),F=pt??oe({root:l,changed:t=>{t&&nt(t),Nt()}}),kt=null,ht=()=>kt??=tn(),B=mt??qt({root:l,read:Dt(m),draw:(t,e)=>x.words(t,e)}),c=(t,e,n)=>[t,{ok:!1,reason:e,...Tt(n)}],ot=t=>b.readFile(t,"utf8").then(JSON.parse).catch(()=>null),X=t=>un(t,l),Q=t=>dt(X(t)),A=t=>g.join(l,t),T=t=>W(dt(A(t)).html),at=t=>Promise.resolve(m.forgetChanges?.(t)).catch(()=>{}),gt=async t=>{let e=await b.readdir(A(t),{withFileTypes:!0});if(!Gt.includes(t))return e.map(({name:r})=>r);let n=t===an?new Set(pn(l).map(({id:r})=>r.split("/")[0])):new Set;return e.filter(r=>r.isFile()||sn.includes(r.name)&&!n.has(r.name)).map(({name:r})=>r)},yt=async(t,e,n)=>{await b.mkdir(n,{recursive:!0});let r=[];try{for(let o of t)await q(g.join(e,o),g.join(n,o)),r.push(o)}catch(o){for(let a of r)await q(g.join(n,a),g.join(e,a));throw o}},p=async(t,e)=>{if(!Gt.includes(t))return q(A(t),e);await yt(await gt(t),A(t),e),await b.rmdir(A(t)).catch(()=>{})},d=async(t,e)=>Gt.includes(t)&&!await T(t)&&(await Promise.all((await b.readdir(e)).map(n=>W(g.join(A(t),n))))).every(n=>!n),S=async t=>await ot(dt(t).json)??{},h=async t=>{let{title:e=t,description:n="",type:r,instructions:o,icon:a,look:i}=await S(X(t)),s=o===!0?{}:Mt(i,Bt(l));return{slug:t,title:e,description:n,...r?{type:r}:{},...typeof a=="string"&&a?{icon:a}:{},...o===!0?{instructions:!0}:{},...Object.keys(s).length?{look:s}:{}}},j=async t=>{let e=await Wt(A(t));return e&&{slug:t,title:e.title,description:"",kind:"link",url:e.url,...e.icon?{icon:e.icon}:{},...e.siteIcon?{siteIcon:e.siteIcon}:{}}},v=async(t,e,n=[])=>{let r=Ct(t),o=r&&n.find(({id:z})=>z===r.ws),a=o?.facts.get(r.slug);if(a){let z=g.join(o.root,r.slug);return{slug:t,title:a.title,description:a.description,kind:"draft",workspace:r.ws,...a.icon?{icon:a.icon}:{},path:a.path,folder:z,root:o.root}}let{ws:i,title:s,description:u,icon:f,path:k,folder:O,root:y,missing:R}=await ce(t,e);return{slug:t,title:s,description:u,kind:"draft",workspace:i,...f?{icon:f}:{},...k?{path:k,folder:O,root:y}:{},...R?{missing:R}:{}}},P=async(t,e,n,r)=>ie(t)?v(t,n,r):e.includes(t)?await j(t)??{slug:t,title:t,description:"",kind:"link",url:""}:h(t),w=Pt(l),V=()=>ue(ln())===ue(l),Z=(t,e)=>{let n=t.shown.find(({isDefault:s})=>s)?.id??(V()?w:null),r=new Set([...t.drafts.map(s=>Ct(s)?.ws),...t.groups.map(({workspace:s})=>s),...t.shown.map(({id:s})=>s)].filter(Boolean)),o=new Set(t.groups.filter(({workspace:s,title:u})=>s&&!u).map(({workspace:s})=>s));t.groups.find(({id:s})=>s===xt)?.title||o.add(w),o.delete(n);let a=De(new Set([...r,w]),{ids:new Map([...e,[w,[l]]]),stops:ht(),among:o});F.follow(new Map([...a].filter(([s])=>s!==w).map(([s,{root:u}])=>[s,u])));let i=Object.fromEntries([...r].map(s=>[s,{...a.get(s)??{missing:M(s,e).refused??"unknown"},...s===n?{default:!0}:{}}]));return i[w]={...a.get(w),there:!0,self:!0,...w===n?{default:!0}:{}},i},J=()=>kn(l),it=async(t,e)=>{let n=await S(X(t));await G(Q(t).json,`${JSON.stringify({...n,[e]:!0},null,2)}
|
|
7
|
+
`)},W=t=>b.access(t).then(()=>!0,()=>!1),U=async(t,{own:e=null}={})=>{let n=new Set((await ct()).map(({slug:r})=>r));n.delete(e);for(let r=1;;r++){let o=r===1?t:`${t}-${r}`;if(!hn(o,l)&&!n.has(o))return o}},st=async t=>{let e=await U(t.slug,{own:t.slug});return wn(t.slug)?e===t.slug&&!await dn(t.slug,l)?e:Yt(l):e},K=async(t,e)=>{let n=Q(t).html,r=await b.readFile(n,"utf8"),o=Zt(r).replace(`data-doc-id="${e}"`,`data-doc-id="${t}"`);o!==r&&await G(n,o)},L=()=>He(l),C=async t=>{await Ve(l,t),N()},D=t=>Me(l,t);async function Ot(t,e="",n=1/0){await D(async()=>{let r=await L();vt(r,t,e,n),await C(r)})}async function jt(t,{parent:e="",after:n=null,first:r=!1}={}){await D(async()=>{let o=await L();for(let i of Object.values(o.children))i.includes(t)&&i.splice(i.indexOf(t),1);let a=typeof n=="string"?Object.keys(o.children).find(i=>o.children[i].includes(n)):void 0;a!==void 0?vt(o,t,a,o.children[a].indexOf(n)+1):vt(o,t,typeof e=="string"?e:"",r===!0?0:1/0),await C(o)})}function pe(t,e){let n=new Set(Object.values(t.children).flat()),r={...t.children};for(let{id:o}of e.groups){if(o===xt)continue;let a=i=>{let s=(e.children[i]??[]).filter(u=>!n.has(u));(Et(i)||s.length)&&(r[i]=s),s.forEach(a)};a(At(o))}return{groups:e.groups,children:r}}function Vt(t){return D(async()=>{let e=await L();for(let[n,r]of Object.entries(e.children)){let o=r.indexOf(t);if(!(o<0))return r.splice(o,1,...e.children[t]??[]),delete e.children[t],await C(e),{parent:n,index:o}}return{parent:"",index:1/0}})}let ke=(t,e)=>B.lines(t,e),Ut=t=>ot(g.join(E,t,"entry.json")),ct=()=>mn(l);async function he(t){let e=await Ht(t,l);if(!e)return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762");let n=`${Date.now().toString(36)}-${_t(3).toString("hex")}`;try{await b.mkdir(g.join(E,n),{recursive:!0}),await q(wt(t,l).folder,g.join(E,n,"page"))}catch(o){throw await b.rm(g.join(E,n),{recursive:!0,force:!0}).catch(()=>{}),o}let r={id:n,kind:"page",slug:t,title:e.title,at:Date.now(),parent:"",index:-1};return await G(g.join(E,n,"entry.json"),`${JSON.stringify(r,null,2)}
|
|
8
|
+
`),[200,{ok:!0,entry:r}]}async function ge(t){let e=g.join(E,t.id,"page"),n=await st(t);if(await b.mkdir(fe(l).customPages,{recursive:!0}),await q(e,wt(n,l).folder),n!==t.slug){let{html:r}=wt(n,l),o=await b.readFile(r,"utf8").catch(()=>null),a=o?.replace(`data-page-id="${t.slug}"`,`data-page-id="${n}"`);o!==null&&a!==o&&await G(r,a)}return await b.rm(g.join(E,t.id),{recursive:!0,force:!0}),[200,{ok:!0,page:await Ht(n,l),entry:{...t,slug:n}}]}async function ye(t){let e=await Wt(A(t));if(!e)return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u94FE\u63A5");let n=`${Date.now().toString(36)}-${_t(3).toString("hex")}`,r=await L(),{parent:o,index:a}=await Vt(t);try{await b.mkdir(g.join(E,n),{recursive:!0}),await q(A(t),g.join(E,n,"link"))}catch(s){throw await D(()=>C(r)),await b.rm(g.join(E,n),{recursive:!0,force:!0}).catch(()=>{}),s}let i={id:n,kind:"link",slug:t,title:e.title,at:Date.now(),parent:o,index:Number.isFinite(a)?a:-1};return await G(g.join(E,n,"entry.json"),`${JSON.stringify(i,null,2)}
|
|
9
|
+
`),[200,{ok:!0,entry:i}]}async function Oe(t){let e=g.join(E,t.id,"link"),n=await st(t);return await q(e,A(n)),await b.rm(g.join(E,t.id),{recursive:!0,force:!0}),await Ot(n,t.parent,t.index<0?1/0:t.index),[200,{ok:!0,report:await j(n),entry:{...t,slug:n}}]}function je(t,{parent:e,after:n,first:r}){let o=i=>Et(i)?Object.hasOwn(t.children,i):Object.values(t.children).some(s=>s.includes(i));if(n!=null){let i=Object.keys(t.children).find(s=>t.children[s].includes(n));return i===void 0?{refused:[404,"after","\u627E\u4E0D\u5230\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6761\u76EE"]}:e!=null&&e!==i?{refused:[409,"level","\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6761\u76EE\u4E0D\u5728\u8FD9\u4E00\u5C42"]}:{parent:i,index:t.children[i].indexOf(n)+1}}let a=e??At(xt);return Et(a)&&t.groups.some(i=>i.extension&&At(i.id)===a)?{refused:[409,"extension","\u6269\u5C55\u7684\u680F\u91CC\u653E\u4E0D\u4E86\u522B\u7684\u6761\u76EE"]}:o(a)?{parent:a,index:r?0:(t.children[a]??[]).length}:{refused:[404,"parent",Et(a)?"\u627E\u4E0D\u5230\u8FD9\u4E00\u680F":"\u627E\u4E0D\u5230\u8981\u653E\u5230\u5B83\u4E0B\u9762\u7684\u6761\u76EE"]}}let et=new Map;function Se(t){let e=et.get(t);if(e&&Date.now()-e.at<36e5)return e.answer;let n=Y?Y.frameable(t).catch(()=>({frameable:!0,reason:"unknown"})):Promise.resolve({frameable:!0,reason:"unknown"});return et.size>=500&&et.delete(et.keys().next().value),et.set(t,{at:Date.now(),answer:n}),n.then(r=>{["auth","unknown"].includes(r.reason)&&et.get(t)?.answer===n&&et.delete(t)}),n}function Kt(t,e){return Y?.icon?(async()=>{let n=await Y.icon(e).catch(()=>null);if(!n)return null;let r=g.join(A(t),Ft),o=await b.readFile(r,"utf8").catch(()=>null),a=o===null?null:rn(o);if(!a||a.url!==e||a.siteIcon===n)return null;let i=ft({...a,siteIcon:n});return i.refused||!i.value.siteIcon||!await G(r,`${JSON.stringify(i.value,null,2)}
|
|
10
|
+
`,{expect:o})?null:(N(),n)})().catch(()=>null):Promise.resolve(null)}let zt={info:async()=>[200,{ok:!0,version:1,gallery:$.version,token:m.token,commands:[...Object.keys(lt)],server:{pid:process.pid,workspace:g.resolve(l),kind:$.kind}}],async outline(){let{outline:t,others:e}=await We(l),n=await J(),r=[...Object.values(t.children).flat(),...n?[n]:[]],o=le(),a=async y=>[y,await P(y,t.links,o,e)],[i,s,u,f]=await Promise.all([Promise.all(r.map(a)),yn(l),ct(),Sn(l)]),k=f.map(({id:y,title:R,icon:z,entries:It,count:ve,error:Qt})=>({id:y,title:R,...z?{icon:z}:{},entries:It,count:ve,...Qt?{error:Tt(Qt)}:{}})),O=await we(l,s);return[200,{ok:!0,outline:t,instructions:n,reports:Object.fromEntries(i),pages:s,head:O,trash:u,workspaces:Z(t,o),self:w,extensions:k}]},trash:async()=>[200,{ok:!0,entries:await ct()}],async stats(t){let e=t.get("slug")??"",n=I.test(e)?await B.facts(e).catch(()=>null):null;return n?[200,{ok:!0,edited:n.edited,words:n.words}]:c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863")},async query(t){let e;try{e=JSON.parse(t.get("options")??"{}")}catch{return[400,{ok:!1,reason:"options",message:"options is JSON"}]}return B.query(t.get("kind")??"",e,{doc:t.get("doc")})},components:async()=>[200,{ok:!0,..._.read()}],async source(t){let e=t.get("slug")??"",n=t.get("kind")==="page";if(!I.test(e))return c(404,"missing",n?"\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762":"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let r=g.resolve(n?wt(e,l).html:Q(e).html);return await W(r)?[200,{ok:!0,path:r}]:c(404,"missing",n?"\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762":"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863")},projects:async()=>[200,{ok:!0,workspaces:await Ze(l,{stops:ht()})}],shell:async t=>[200,{ok:!0,shell:await F.shellVouched(t.get("origin"))}],async search(t){let e=Pn(t.get("q")??"");if(!e)return[200,{ok:!0,results:[]}];let{children:n,groups:r,links:o}=await L(),a=[],i=O=>(n[O]??[]).forEach(y=>{!o.includes(y)&&!ie(y)&&a.push(y),i(y)});for(let{id:O}of r)i(At(O));let s=e.toLowerCase(),u=new Map(await Promise.all(a.map(async O=>[O,await h(O)]))),f=JSON.stringify([...u].map(([O,{title:y}])=>[O,y])),k=(await Promise.all(a.map(async O=>{let y=await ke(O,f);if(!y)return null;let R=String(u.get(O).title).toLowerCase().includes(s),{count:z,hits:It}=An(y,e);return R||z?{slug:O,title:R,count:z,hits:It}:null}))).filter(Boolean);return k.sort((O,y)=>Number(y.title)-Number(O.title)||y.count-O.count),[200,{ok:!0,results:k.slice(0,50)}]}},lt={async outline({outline:t,base:e}){return!ae(t)||e!==void 0&&!ae(e)?c(400,"outline","\u6587\u6863\u76EE\u5F55\u7684\u7ED3\u6784\u4E0D\u5BF9\uFF1A\u6BCF\u4EFD\u6587\u6863\u53EA\u80FD\u51FA\u73B0\u4E00\u6B21"):await D(async()=>{let r=await L();return e!==void 0&&!Ue(e,r)?!1:(await C(t.groups?t:pe(t,r)),!0)})?[200,{ok:!0,outline:await L()}]:c(409,"stale","\u6587\u6863\u76EE\u5F55\u521A\u5728\u522B\u5904\u6539\u8FC7")},async move({slug:t,parent:e,after:n=null,first:r=!1,workspace:o}){if(typeof o=="string"&&!rt(o,l))return c(409,"elsewhere","\u8FD9\u4E2A\u9884\u89C8\u670D\u52A1\u5668\u7BA1\u7684\u662F\u53E6\u4E00\u4E2A\u76EE\u5F55\u7684\u6587\u6863");let a=u=>typeof u=="string"&&I.test(u);if(!a(t)||e!==void 0&&e!==""&&!a(e)||n!==null&&!a(n)||typeof r!="boolean")return c(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");let i=await J();if(i!==null&&[t,e,n].includes(i))return c(409,"instructions","\u5199\u4F5C\u504F\u597D\u4E0D\u5728\u6587\u6863\u76EE\u5F55\u91CC\uFF0C\u4E0D\u80FD\u79FB\u52A8\uFF0C\u4E0B\u9762\u4E5F\u4E0D\u80FD\u653E\u6587\u6863");let s=await Ye(l,t,{parent:e,after:n,first:r});if(s.written&&N(),!s.ok){let[u,f]={missing:[404,"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"],parent:[404,"\u627E\u4E0D\u5230\u8981\u653E\u5230\u5B83\u4E0B\u9762\u7684\u6587\u6863"],after:[404,"\u627E\u4E0D\u5230\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6587\u6863"],level:[409,"\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6587\u6863\u4E0D\u5728\u8FD9\u4E00\u5C42"],itself:[409,"\u6587\u6863\u4E0D\u80FD\u653E\u5728\u5B83\u81EA\u5DF1\u540E\u9762"],inside:[409,"\u6587\u6863\u4E0D\u80FD\u79FB\u5230\u5B83\u81EA\u5DF1\u6216\u5B83\u4E0B\u9762\u7684\u6587\u6863\u4E0B\u9762"]}[s.reason];return c(u,s.reason,f)}return[200,{ok:!0,...s,outline:await L()}]},async create({title:t,description:e,parent:n="",after:r=null,first:o=!1,language:a}){let i=typeof t=="string"?t.replace(/\s+/g," ").trim().slice(0,200):"",s=await Yt(l);return await at(s),await x.create(s,i,typeof e=="string"&&e.trim()?e.trim():"\u65B0\u6587\u6863",{lang:Lt(a)}),await jt(s,{parent:n,after:r,first:o}),[200,{ok:!0,report:await h(s)}]},async instructions({title:t,description:e,language:n}){let r=await J();if(r)return[200,{ok:!0,report:await h(r)}];let o=await U(cn),a=(i,s)=>typeof i=="string"&&i.trim()?i.trim().slice(0,200):s;return await x.create(o,a(t,"\u5199\u4F5C\u504F\u597D"),a(e,"Agent \u6BCF\u6B21\u5199\u62A5\u544A\u524D\u90FD\u4F1A\u5148\u8BFB\u7684\u5199\u4F5C\u504F\u597D"),{lang:Lt(n),page:!0}),await it(o,"instructions"),[200,{ok:!0,report:await h(o)}]},async components({id:t,hidden:e,shown:n,disabled:r,unlisted:o,net:a,pack:i,enabled:s}){try{return[200,{ok:!0,...await _.write(i!==void 0?{pack:i,enabled:s}:{id:t,hidden:e,shown:n,disabled:r,unlisted:o,net:a})}]}catch(u){return c(409,"components",u)}},async duplicate({slug:t,suffix:e,untitled:n}){if(typeof t!="string"||!I.test(t)||!await T(t))return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let r=await Yt(l);await at(r);let o=new Set(["",...await gt(t)]);await b.cp(A(t),A(r),{recursive:!0,errorOnExist:!0,filter:O=>o.has(g.relative(A(t),O).split(g.sep)[0])}),await K(r,t);let{title:a}=await h(t),i=a||(typeof n=="string"&&n.trim()?n.trim().slice(0,50):"\u672A\u547D\u540D\u6587\u6863"),s=await m.renameReport(r,`${i}${typeof e=="string"&&e.length>0&&e.length<=20?e:"\uFF08\u526F\u672C\uFF09"}`),u=await L(),[f,k]=Object.entries(u.children).find(([,O])=>O.includes(t))??["",null];return await Ot(r,f,k?k.indexOf(t)+1:1/0),[200,{ok:!0,report:await h(r),notes:s.notes??[]}]},async look({slug:t,look:e}){if(typeof t!="string"||!I.test(t)||!await T(t))return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");if(t===await J())return c(409,"instructions","\u5199\u4F5C\u504F\u597D\u6CA1\u6709\u5B57\u4F53\u4E0E\u5E03\u5C40");if(e!==null&&(typeof e!="object"||Array.isArray(e)))return c(400,"look","\u5B57\u4F53\u4E0E\u5E03\u5C40\u4E0D\u5BF9");let n=Q(t).json,r=null;try{r=JSON.parse(await b.readFile(n,"utf8"))}catch{}if(!r||typeof r!="object"||Array.isArray(r))return c(409,"metadata","\u8FD9\u4EFD\u6587\u6863\u7684\u6807\u9898\u548C\u8BF4\u660E\u8BFB\u4E0D\u51FA\u6765");let o=me(r,bn(e,Bt(l)));return JSON.stringify(o)!==JSON.stringify(r)&&await G(n,`${JSON.stringify(o,null,2)}
|
|
11
|
+
`),[200,{ok:!0,report:await h(t)}]},async looks({slug:t}){if(typeof t!="string"||!I.test(t)||!await T(t))return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let e=await J();if(t===e)return c(409,"instructions","\u5199\u4F5C\u504F\u597D\u6CA1\u6709\u5B57\u4F53\u4E0E\u5E03\u5C40");let n=await ot(Q(t).json);if(!n||typeof n!="object"||Array.isArray(n))return c(409,"metadata","\u8FD9\u4EFD\u6587\u6863\u7684\u6807\u9898\u548C\u8BF4\u660E\u8BFB\u4E0D\u51FA\u6765");let r=Bt(l),o=Mt(n.look,r);try{await En(l,o)}catch(u){return c(409,"workspace",u)}let a=0,i=(await on(l)).filter(u=>u!==e).map(u=>({json:Q(u).json,self:u===t})),s=(await ct()).filter(({kind:u})=>u==="document").map(({id:u})=>({json:dt(g.join(E,u,"report")).json,self:!1}));for(let{json:u,self:f}of[...i,...s])for(let k=0;k<3;k++){let O=await b.readFile(u,"utf8").catch(()=>null),y=null;try{y=JSON.parse(O??"")}catch{}if(!y||typeof y!="object"||Array.isArray(y)||!Object.hasOwn(y,"look")||y.instructions===!0)break;let R=await G(u,`${JSON.stringify(me(y,{}),null,2)}
|
|
12
|
+
`,{expect:O}).catch(()=>null);if(R===null)break;if(R){!f&&Object.keys(vn(y.look)).length>0&&!xn(Mt(y.look,r),o)&&a++;break}}return[200,{ok:!0,look:o,replaced:a,report:await h(t)}]},async head({order:t}){let e=Ke(t);return e?(await D(()=>Be(l,e)),N(),[200,{ok:!0,head:await we(l)}]):c(400,"head","\u4FA7\u680F\u5934\u90E8\u7684\u987A\u5E8F\u4E0D\u5BF9")},async"new-page"({title:t,after:e=null,language:n}){let r=typeof t=="string"?t.replace(/\s+/g," ").trim():"";if(!r||r.length>200)return c(400,"title","\u6807\u9898\u4E0D\u80FD\u662F\u7A7A\u7684\uFF0C\u4E5F\u4E0D\u80FD\u8D85\u8FC7 200 \u4E2A\u5B57");if(e!==null&&(typeof e!="string"||!I.test(e)))return c(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");let o=await On(l);return await gn(o,r,{root:l,blank:!0,after:e,...Lt(n)?{lang:Lt(n)}:{}}),N(),[200,{ok:!0,page:await Ht(o,l)}]},async rename({slug:t,title:e,kind:n="document"}){if(typeof t!="string"||!I.test(t))return c(400,"slug","\u6587\u6863\u540D\u4E0D\u5BF9");if(n==="page"){let o;try{o=await jn(t,e,l)}catch{return c(400,"title","\u6807\u9898\u4E0D\u80FD\u662F\u7A7A\u7684\uFF0C\u4E5F\u4E0D\u80FD\u8D85\u8FC7 200 \u4E2A\u5B57")}return o?[200,{ok:!0,page:o}]:c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762")}let r=await m.renameReport(t,e);return r.ok?[200,{ok:!0,report:await h(t),notes:r.notes}]:c({title:400,missing:404}[r.reason]??409,r.reason,r.message??"\u6539\u540D\u6CA1\u6709\u6210\u529F")},async trash({slug:t,kind:e="document"}){if(typeof t!="string"||!I.test(t))return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");if(e==="page")return he(t);if(e==="link")return ye(t);if(t===await J())return c(409,"instructions","\u5199\u4F5C\u504F\u597D\u4E0D\u80FD\u79FB\u5230\u56DE\u6536\u533A");if(!await T(t))return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let{title:n}=await h(t),r=`${Date.now().toString(36)}-${_t(3).toString("hex")}`,o=await L(),{parent:a,index:i}=await Vt(t);try{await b.mkdir(g.join(E,r),{recursive:!0}),await p(t,g.join(E,r,"report"))}catch(u){throw await D(()=>C(o)),await b.rm(g.join(E,r),{recursive:!0,force:!0}).catch(()=>{}),u}let s={id:r,kind:"document",slug:t,title:n,at:Date.now(),parent:a,index:Number.isFinite(i)?i:-1};return await G(g.join(E,r,"entry.json"),`${JSON.stringify(s,null,2)}
|
|
13
|
+
`),[200,{ok:!0,entry:s}]},async restore({id:t}){let e=typeof t=="string"&&de.test(t)?await Ut(t):null;if(!e)return c(404,"missing","\u56DE\u6536\u533A\u91CC\u6CA1\u6709\u8FD9\u4E00\u9879");if(e.kind==="page")return ge(e);if(e.kind==="link")return Oe(e);let n=g.join(E,t,"report"),r=await d(e.slug,n),o=r?e.slug:await st(e);return r?await yt(await b.readdir(n),n,A(o)):await q(n,A(o)),o!==e.slug&&await K(o,e.slug),await b.rm(g.join(E,t),{recursive:!0,force:!0}),await Ot(o,e.parent,e.index<0?1/0:e.index),[200,{ok:!0,report:await h(o),entry:{...e,kind:"document",slug:o}}]},async destroy({id:t}){let e=typeof t=="string"&&de.test(t)?await Ut(t):null;return e?((e.kind??"document")==="document"&&!await T(e.slug)&&await at(e.slug),await b.rm(g.join(E,t),{recursive:!0,force:!0}),[200,{ok:!0}]):c(404,"missing","\u56DE\u6536\u533A\u91CC\u6CA1\u6709\u8FD9\u4E00\u9879")},async link({url:t,title:e,icon:n=null,parent:r,after:o=null,first:a=!1},{port:i,wait:s=!1}={}){let u=ft({url:t,title:e,icon:n});if(u.refused)return c(400,u.refused,u.message);if(Jt(u.value.url,i))return c(409,"own","\u8FD9\u662F Gallery \u81EA\u5DF1\u7684\u5730\u5740\uFF0C\u8BF7\u76F4\u63A5\u94FE\u63A5\u6587\u6863");if(r!=null&&typeof r!="string"||o!==null&&typeof o!="string"||typeof a!="boolean")return c(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");let f=await D(async()=>{let O=await L(),y=je(O,{parent:r,after:o,first:a||r==null&&o===null});if(y.refused)return y;let R=await U(nn(u.value.title,u.value.url));return await b.mkdir(A(R),{recursive:!0}),await G(g.join(A(R),Ft),`${JSON.stringify(u.value,null,2)}
|
|
14
|
+
`),vt(O,R,y.parent,y.index),await C(O),{slug:R,parent:y.parent,index:y.index}});if(f.refused)return c(...f.refused);let k=Kt(f.slug,u.value.url);return s&&await k,[200,{ok:!0,link:await j(f.slug),parent:f.parent,index:f.index,outline:await L()}]},async"link-set"({slug:t,url:e,title:n,icon:r},{port:o,wait:a=!1}={}){let i=typeof t=="string"&&I.test(t)?await Wt(A(t)):null;if(!i)return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u94FE\u63A5");let s=e??i.url,u=ft({url:s,title:n??i.title,icon:r===void 0?i.icon??null:r,siteIcon:i.siteIcon??null});if(u.refused)return c(400,u.refused,u.message);let f=u.value.url!==i.url;if(f&&Jt(u.value.url,o))return c(409,"own","\u8FD9\u662F Gallery \u81EA\u5DF1\u7684\u5730\u5740\uFF0C\u8BF7\u76F4\u63A5\u94FE\u63A5\u6587\u6863");if(f&&delete u.value.siteIcon,JSON.stringify(u.value)!==JSON.stringify(i)&&await G(g.join(A(t),Ft),`${JSON.stringify(u.value,null,2)}
|
|
15
|
+
`),f){let k=Kt(t,u.value.url);a&&await k}return[200,{ok:!0,link:await j(t)}]},async"draft-add"({path:t,confirm:e=!1,after:n=null}){let r=await Xe(t),o=typeof n=="string"?n:null;if(r.kind==="missing")return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u6587\u4EF6\u6216\u6587\u4EF6\u5939");if(r.kind==="plain")return c(409,"plain","\u8FD9\u4E0D\u662F Gallery \u7684\u5E95\u7A3F\u6216\u5DE5\u4F5C\u533A\uFF0C\u53EF\u4EE5\u7528\u300C\u5BFC\u5165\u300D\u628A\u6587\u4EF6\u590D\u5236\u8FDB\u6765");if(r.kind==="nested")return c(409,"nested","\u8FD9\u4EFD\u5E95\u7A3F\u4E0D\u5728\u5B83\u5DE5\u4F5C\u533A\u7684\u7B2C\u4E00\u5C42\uFF08\u5728\u56DE\u6536\u533A\u91CC\uFF0C\u6216\u662F\u5199\u4F5C\u504F\u597D\uFF09\uFF0C\u4E0D\u80FD\u6DFB\u52A0");if(r.kind==="name")return c(409,"name","\u8FD9\u4E2A\u6587\u4EF6\u5939\u7684\u540D\u5B57\u4E0D\u662F Gallery \u6587\u6863\u7684\u5199\u6CD5\uFF08\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u8FDE\u5B57\u7B26\uFF09\uFF0C\u4E0D\u80FD\u6DFB\u52A0");let a=r.kind==="workspace"?r.root:r.kind==="folder"?null:r.root,i=!a||!qe(l).some(k=>rt(k.root,a));if(!a){let k=r.kind==="folder"?r.folder:r.parent;if(Qe(k))return c(409,"marker",tt("{0} \u91CC\u7684 gallery.json \u662F\u522B\u7684\u7A0B\u5E8F\u7684\uFF0C\u4E0D\u80FD\u628A\u5B83\u767B\u8BB0\u6210\u5DE5\u4F5C\u533A",k));if(e!==!0)return[409,{ok:!1,reason:"unregistered",folder:k,...Tt(tt("\u4F1A\u628A {0} \u767B\u8BB0\u6210\u4E00\u4E2A\u5DE5\u4F5C\u533A\uFF08\u5728\u91CC\u9762\u653E gallery.json \u548C .gallery/\uFF09",k))}];if(!(await fn(k)).ours)return c(409,"marker",tt("{0} \u91CC\u7684 gallery.json \u662F\u522B\u7684\u7A0B\u5E8F\u7684\uFF0C\u4E0D\u80FD\u628A\u5B83\u767B\u8BB0\u6210\u5DE5\u4F5C\u533A",k));a=k}let s=r.kind==="workspace"||r.kind==="folder";if(rt(a,l))return[200,{ok:!0,kind:s?"workspace":"draft",own:!0,existing:!0,...s?{column:xt}:{entry:r.slug}}];let u=await en(a,{force:!0}).catch(()=>"failed"),f=M(Pt(a));return f.refused==="ambiguous"?c(409,"ambiguous",tt("\u672C\u673A\u767B\u8BB0\u7684 {0} \u4E2A\u5DE5\u4F5C\u533A\u7F16\u53F7\u76F8\u540C\uFF08{1}\uFF09\uFF0C\u5148\u7528 gallery workspaces --forget \u53BB\u6389\u5176\u4E2D\u4E00\u4E2A",f.roots.length,Pt(a))):!f.root||!rt(f.root,a)?u==="temporary"?c(409,"temporary","\u8FD9\u4E2A\u5DE5\u4F5C\u533A\u5728\u7CFB\u7EDF\u7684\u4E34\u65F6\u6587\u4EF6\u5939\u91CC\uFF0C\u4E0D\u80FD\u6DFB\u52A0"):c(409,"registry","\u6CA1\u80FD\u628A\u5B83\u7684\u5DE5\u4F5C\u533A\u8BB0\u8FDB\u672C\u673A\u7684\u767B\u8BB0\u8868"):(nt(a),s?[200,{ok:!0,kind:"workspace",...await ze(l,a,{changed:N,after:o})}]:[200,{ok:!0,kind:"draft",...await se(l,a,r.slug,{changed:N,pick:!0,after:o,fresh:i})}])},async"draft-join"({root:t,slug:e}){if(typeof t!="string"||typeof e!="string"||!I.test(e))return c(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");if(rt(t,l))return c(409,"own","\u8FD9\u662F\u5F53\u524D\u7684\u5DE5\u4F5C\u533A");let n=M(Pt(t));return!n.root||!rt(n.root,t)?c(409,"registry","\u8FD9\u4E2A\u5DE5\u4F5C\u533A\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC"):await W(dt(g.join(t,e)).html)?(nt(t),[200,{ok:!0,...await se(l,t,e,{changed:N})}]):c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863")},async export({slug:t}){if(typeof t!="string"||!I.test(t)||!await W(X(t)))return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let{problems:e=[],file:n,refused:r}=await x.export(t);return r?c(r.reason==="missing"?404:409,r.reason,r.message):e.length?c(422,"check",Ln(e)):[200,{ok:!0,path:In(n)}]}},Xt={async frameable({url:t},{port:e}){let n=typeof t=="string"?ft({url:t,title:"-"}):{refused:"url"};return n.refused?c(400,"url","\u8FD9\u4E0D\u662F\u4E00\u4E2A\u7F51\u5740"):Jt(n.value.url,e)?[200,{ok:!0,frameable:!1,reason:"own"}]:[200,{ok:!0,...await Se(n.value.url)}]},async elsewhere({ws:t}){let e=typeof t=="string"?M(t):{refused:"unknown"};if(e.refused)return c(409,e.refused,e.refused==="ambiguous"?"\u672C\u673A\u767B\u8BB0\u7684\u5DE5\u4F5C\u533A\u91CC\u6709\u4E24\u4E2A\u7528\u7684\u662F\u540C\u4E00\u4E2A\u7F16\u53F7\uFF0C\u5148\u7528 gallery workspaces --forget \u53BB\u6389\u5176\u4E2D\u4E00\u4E2A":"\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A\u5B83\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC");let n=await F.serverOf(e.root);return n.refused?c(409,n.refused,n.message):[200,{ok:!0,origin:`http://127.0.0.1:${n.port}`}]},async"draft-command"({ws:t,name:e,...n}){let r=typeof t=="string"?M(t):{refused:"unknown"};if(r.refused)return c(409,r.refused,"\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A\u5B83\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC");let o=await F.forward(r.root,e,n);return o[1]?.ok&&nt(r.root),o},async"draft-duplicate"({ws:t,slug:e,suffix:n,untitled:r}){if(t===w)return c(409,"self","\u8FD9\u662F\u5F53\u524D\u7684\u5DE5\u4F5C\u533A");let o=typeof t=="string"?M(t):{refused:"unknown"};if(o.refused)return c(409,o.refused,"\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A\u5B83\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC");let[a,i]=await F.forward(o.root,"duplicate",{slug:e,suffix:n,untitled:r});if(!i?.ok)return[a,i];let s=i.report?.slug;if(typeof s!="string"||!I.test(s))return c(502,"answer","\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u7ED9\u51FA\u7ED3\u679C");let u=ut(t,s);return nt(o.root),await jt(u,{after:ut(t,e)}),[200,{ok:!0,entry:u,report:{...i.report,slug:u,kind:"draft",workspace:t}}]},async"draft-import"({ws:t,uploads:e,parent:n="",from:r,language:o}){if(t===w)return c(409,"self","\u8FD9\u662F\u5F53\u524D\u7684\u5DE5\u4F5C\u533A");let a=typeof t=="string"?M(t):{refused:"unknown"};if(a.refused)return c(409,a.refused,"\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A\u5B83\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC");let[i,s]=await F.forward(a.root,"import",{uploads:e,parent:n,from:r,language:o});if(!s?.ok)return[i,s];nt(a.root);let u=(Array.isArray(s.reports)?s.reports:[]).filter(k=>typeof k=="string"&&I.test(k)).map(k=>ut(t,k)),f=typeof n=="string"&&I.test(n)?ut(t,n):null;if(f&&u.length&&Object.values((await L()).children).some(k=>k.includes(f)))for(let k of u)await jt(k,{parent:f});return[200,{...s,reports:u}]},async"draft-create"({ws:t,title:e,description:n,language:r,parent:o="",after:a=null,first:i=!1}){if(t===w)return c(409,"self","\u8FD9\u662F\u5F53\u524D\u7684\u5DE5\u4F5C\u533A");let s=typeof t=="string"?M(t):{refused:"unknown"};if(s.refused)return c(409,s.refused,"\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A\u5B83\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC");let[u,f]=await F.forward(s.root,"create",{title:e,description:n,language:r});if(!f?.ok)return[u,f];let k=f.report?.slug;if(typeof k!="string"||!I.test(k))return c(502,"answer","\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u7ED9\u51FA\u7ED3\u679C");let O=ut(t,k);return nt(s.root),await jt(O,{parent:o,after:a,first:i}),[200,{ok:!0,entry:O,report:{...f.report,slug:O,kind:"draft",workspace:t}}]},async reveal({entry:t,ws:e,page:n}){let r=le(),o=null;return typeof n=="string"?o=I.test(n)?wt(n,l).folder:null:typeof t=="string"&&Ct(t)?o=(await ce(t,r)).folder:e===w?o=g.resolve(l):typeof e=="string"&&(o=M(e,r).root??null),!o||!await W(o)?c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u6587\u4EF6\u5939"):[200,{ok:!0,path:o,...await re(o)}]},async title({url:t}){let e=typeof t=="string"?ft({url:t,title:"-"}):{refused:"url"};if(e.refused)return c(400,"url","\u8FD9\u4E0D\u662F\u4E00\u4E2A\u7F51\u5740");let n=Y?await Y.title(e.value.url).catch(()=>""):"",r=typeof n=="string"?n:n?.title,o=["auth","unknown"].includes(n?.reason)?n.reason:void 0;return[200,{ok:!0,title:typeof r=="string"?r.slice(0,200):"",...o?{reason:o}:{}}]}};function be(t,e,n){if(t.method==="GET"&&Object.hasOwn(zt,n)){let o=t.headers.host??"",a=t.socket.localPort;return o!==`127.0.0.1:${a}`&&o!==`localhost:${a}`?H(e,403,{ok:!1,reason:"host"}):zt[n](new URL(t.url??"/","http://localhost").searchParams).then(([i,s])=>H(e,i,s),i=>H(e,...c(500,"read",i)))}if(t.method==="POST"&&n==="stop")return m.respond(async o=>{let a=await m.check(o);return a.error?a.error:$.kind!=="cli"||typeof $.stop!="function"?c(409,"dev","\u8FD9\u662F npm run dev \u7684\u670D\u52A1\u5668\uFF1A\u5728\u8FD0\u884C\u5B83\u7684\u5730\u65B9\u505C\u6B62\u5B83"):(e.once("finish",()=>$.stop()),[200,{ok:!0,pid:process.pid}])})(t,e);if(t.method==="POST"&&n==="pack-install")return m.respond(async o=>{let a=await m.check(o,Nn);if(a.error)return a.error;if(!_?.install)return c(404,"unknown");try{return[200,{ok:!0,..._.install(a.body??{})}]}catch(i){if(!i.code)throw i;return c(409,i.code,i)}})(t,e);if(t.method==="POST"&&n==="todo")return(async()=>{let o=await m.check(t);if(o.error)return o.error;let{slug:a,items:i}=o.body??{};return typeof a!="string"||!I.test(a)||!Array.isArray(i)?[400,{ok:!1,reason:"body"}]:!await T(a)||a===await J()?c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"):m.setTodos(a,i)})().then(([o,a])=>H(e,o,a),o=>H(e,...c(500,"write",o.message)));if(t.method==="POST"&&(n==="draft-export"||n==="draft-upload"))return(async()=>{let o=n==="draft-upload",a=new URL(t.url??"/","http://localhost").searchParams,i={};if(o){let f=m.checkHeaders(t);if(f)return f;if(!/^application\/octet-stream\b/i.test(t.headers["content-type"]??""))return[415,{ok:!1,reason:"type"}]}else{let f=await m.check(t);if(f.error)return f.error;i=f.body&&typeof f.body=="object"?f.body:{}}let s=o?a.get("ws"):i.ws,u=typeof s=="string"?M(s):{refused:"unknown"};return u.refused?c(409,u.refused,"\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A\u5B83\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC"):s===w?c(409,"self","\u8FD9\u662F\u5F53\u524D\u7684\u5DE5\u4F5C\u533A"):F.relay(u.root,o?"upload":"export",{body:i,query:{name:a.get("name")??void 0},request:t,response:e})})().then(o=>{o&&(t.resume(),H(e,...o))},o=>{t.resume(),e.headersSent?e.destroy():H(e,...c(500,"read",o))});let r={port:t.socket.localPort};return t.method==="POST"&&Object.hasOwn(lt,n)?m.respond(async o=>{let a=await m.check(o);if(a.error)return a.error;let i=a.body&&typeof a.body=="object"?a.body:{};return typeof i.workspace=="string"&&!rt(i.workspace,l)?c(409,"elsewhere","\u8FD9\u4E2A\u9884\u89C8\u670D\u52A1\u5668\u7BA1\u7684\u662F\u53E6\u4E00\u4E2A\u76EE\u5F55\u7684\u6587\u6863"):lt[n](i,r)})(t,e):t.method==="POST"&&Object.hasOwn(Xt,n)?(async()=>{let o=await m.check(t);return o.error?o.error:Xt[n](o.body&&typeof o.body=="object"?o.body:{},r)})().then(([o,a])=>H(e,o,a),o=>H(e,...c(500,"read",o))):H(e,404,{ok:!1,reason:"unknown"})}return{handle:be,outline:L,trashEntries:ct,place:Ot,freeSlug:U,index:B,run:(t,e,n={})=>Object.hasOwn(lt,t)?lt[t](e??{},{wait:!0,...n}):Promise.resolve(c(404,"unknown","\u6CA1\u6709\u8FD9\u4E2A\u547D\u4EE4")),close:()=>F.close()}}export{pr as a};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{a as ke,b as X,c as Q,f as ye,g as L,h as xe,i as tt,l as Se,m as Ne}from"./chunk-
|
|
2
|
+
import{a as ke,b as X,c as Q,f as ye,g as L,h as xe,i as tt,l as Se,m as Ne}from"./chunk-HXG7EOPJ.mjs";import{a as $t}from"./chunk-ZTHICSSF.mjs";import{b as fe,c as wt,e as K,f as he,i as ue,j as pe,m as me,n as ge,o as $e,p as we,q as be,r as bt}from"./chunk-6N3PX4XX.mjs";import{a as mt}from"./chunk-PAREWQGB.mjs";import{a as oe,b as se,c as ne,d as ie,e as ae,f as re,g as ce,h as le,l as de}from"./chunk-BFJGHSQN.mjs";import{b as gt,c as Xt,d as Qt,e as te,g as ee}from"./chunk-U5XL7D6A.mjs";import{a as w,b as Yt,c as qt}from"./chunk-HYMEEXKN.mjs";import{g as E,j as Jt,l as Vt,m as Zt}from"./chunk-HDWTZ763.mjs";import{existsSync as yo,readFileSync as yi,readdirSync as xi}from"node:fs";import S from"node:fs/promises";import N from"node:path";function ve(t){if(!t||!Array.isArray(t.lines))throw new Error("diff: lines must be an array.");t.lines.forEach(e=>{if(!e||!["added","removed","unchanged"].includes(e.type)||typeof e.content!="string"||/[\r\n]/.test(e.content))throw new Error("diff: each line needs a valid type and single-line content.");if(e.lineNumber!=null&&(!Number.isInteger(e.lineNumber)||e.lineNumber<1))throw new Error("diff: lineNumber must be a positive integer.")})}import{BODY as yt,isInstance as Bo}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as Ho}from"../browser/shared/components/installed.mjs";import{attr as F,elementsOf as Oe,hasClass as Ko,walk as xt}from"../browser/shared/html-tree.mjs";import{CHART_DATA as Go,CHART_KEY as Jo,CHART_SOURCE as C,VIEW_FROM as et,cellWords as Vo,rowsReading as Ee,tableRows as Zo}from"../browser/shared/table-chart.mjs";var Yo=t=>t.tagName==="script"&&(F(t,"type")??"").trim().toLowerCase()==="application/json",Te=t=>t.nodeName==="#text"?t.value:(t.childNodes??[]).map(Te).join("");function qo(t){let e=t;for(;e&&e.tagName!=="figure";)e=e.parentNode;let s=e?Oe(e).find(o=>/^h[2-4]$/.test(o.tagName)):null;return s?Vo(Te(s)):""}function Le(t,e,s=w(t)){let o=[];return xt(s,n=>{let i=e(n);if(i===void 0||!n.sourceCodeLocation)return;let r=n.childNodes.find(Yo);o.push({type:i,line:n.sourceCodeLocation.startLine,text:r?r.childNodes.map(c=>c.value??"").join(""):null,source:F(n,Go),tag:n.tagName,holder:n.parentNode?.tagName,title:qo(n)})},yt),o}var Xo=t=>t.tagName==="ol"&&F(t,"data-doc-chart")==="flow",ot=(t,e)=>Le(t,s=>Xo(s)?void 0:F(s,"data-doc-chart"),e),Qo=t=>Le(t,e=>Ko(e,"doc-diff")?"diff":void 0);function G(t){let e=new Map;return xt(t,s=>{let o=F(s,C);if(o===void 0||!s.sourceCodeLocation)return;(e.get(o)??e.set(o,[]).get(o)).push({line:s.sourceCodeLocation.startLine,offset:s.sourceCodeLocation.startOffset,table:Oe(s).find(i=>i.tagName==="table")??null})},{...yt,inTemplates:!1}),e}function St(t,e){let s=e.get(t)??[];if(s.length===0)return{error:`no table's frame carries ${C}="${t}", so the chart has nothing to draw: put the table back, or delete the card`};if(s.length>1)return{error:`${s.length} tables carry ${C}="${t}" (lines ${s.map(({line:c})=>c).join(", ")}): a key names one table (the chart draws the first); take it off the copies`};let[{line:o,table:n}]=s;if(!n)return{error:`the frame carrying ${C}="${t}" (line ${o}) holds no table`};let i=$t(n),r=Zo(i);return r.error?{error:`its table (line ${o}) ${r.error}`}:{...r,line:o,cells:i}}function Nt(t){let e=[t,...L(t).filter(({files:n})=>n.includes("kit.js")).map(n=>tt(n,"kit.js")??"")].join(`
|
|
3
3
|
`),s=new Set([...e.matchAll(/DocCharts\.define\(\s*(["'`])([a-z][a-z0-9-]*)\1/g)].map(n=>n[2])),o=new Set([...e.matchAll(/DocCharts\.define\(\s*(["'`])([^"'`\n]*)\1/g)].map(n=>n[2]).filter(n=>!s.has(n)));return{defined:s,misnamed:o}}function vt(t){let e=w(t),s=[],{defined:o,misnamed:n}=Nt(t),i=null;for(let{type:r,line:c,text:l,source:a,tag:d,holder:f}of ot(t,e)){let u=`data-doc-chart="${r}" (line ${c})`;if(d==="table"){s.push(f==="figure"?`${u} is on a table inside a <figure>: the chart's card is a figure of its own, so write the table outside it, its <caption> the chart's title`:`${u} is on a table the tools leave as written (inside a whole block, an element with a class of the document's own, a cell): a chart is drawn from a table outside one`);continue}if(n.has(r)){s.push(`${u}: the document's script defines "${r}" with DocCharts.define, which refuses that name: a chart type's name is lowercase letters, digits and hyphens, a letter first ("interval", "ci-plot"); rename it in both places`);continue}if(!o.has(r)){s.push(`${u}: the document's script does not define "${r}": define it once in the document's <script> with DocCharts.define("${r}", ({ host, data, tokens, width, height }) => { \u2026 }) (references/writing-html.md, "Figures and charts")`);continue}if(a!==void 0){if(l!==null){s.push(`${u}: a chart drawn from a table takes its data from the table: take its <script type="application/json"> out`);continue}let h=St(a,i??=G(e));h.error&&s.push(`${u}: ${h.error}`);continue}if(l===null){s.push(`${u} needs its data in a <script type="application/json"> child`);continue}try{JSON.parse(l)}catch(h){s.push(`${u}: its data is not valid JSON (${h.message})`)}}s.push(...Ce(e,i??=G(e)).failures);for(let{line:r,text:c}of Qo(t)){if(c===null)continue;let l=`.doc-diff (line ${r})`;try{ve(JSON.parse(c))}catch(a){s.push(`${l}: ${a instanceof SyntaxError?`its options are not valid JSON (${a.message})`:a.message}`)}}return s}function Ae(t,{written:e=t}={}){let s=w(t),o=[],{defined:n}=Nt(t),i=null,r=null;for(let{type:c,line:l,text:a,source:d,title:f,tag:u}of ot(t,s)){if(d===void 0||u==="table"||a!==null||!n.has(c))continue;let h=`data-doc-chart="${c}" (line ${l})`;if(!f){r??=new Set(e===t?[]:ot(e).map(k=>k.source).filter(k=>k!==void 0));let b=e!==t&&!r.has(d);o.push(`${h}: this chart card has no title: ${b?"write a <caption> on its table (the one with data-doc-chart), which becomes the card's h3":"write an h3 in the card's figure, before the chart"}`)}let m=St(d,i??=G(s));if(m.error)continue;let{blank:p,twice:g}=Ee(m.cells,m.data);p&&o.push(`${h}: its table's header (line ${m.line}) has a cell with no words, so that column's values are keyed "" in data: write the column's name there`),g.length>0&&o.push(`${h}: its table's header (line ${m.line}) names ${g.map(b=>`"${b}"`).join(", ")} twice, so data keeps the later column's value under it: give each column a name of its own`)}return o.push(...Ce(s,i??=G(s)).notes),o}var kt=500;function Ce(t,e){let s=[],o=[],n=E().packages;return xt(t,i=>{let r=F(i,et);if(r===void 0||!i.sourceCodeLocation)return;let c=F(i,Ho),l=`${c??i.tagName} (line ${i.sourceCodeLocation.startLine})`;if(!Bo(i))return void s.push(`<${i.tagName}> (line ${i.sourceCodeLocation.startLine}) carries ${et}="${r}", which only a view of a table carries: an instance of a custom block (<div data-doc-component="<scope>/<name>">) whose block's needs hold "tables"; take it off`);if(!Jo.test(r))return void s.push(`${l}: ${et}="${r}" is no key: a letter, then letters, digits, "_" or "-", 32 at most, as the table's frame writes it in ${C}`);let a=e.get(r)??[];if(a.length===0)return void s.push(`${l}: no table's frame carries ${C}="${r}", so the view has no table to read: put the table back, or delete the view`);if(a.length>1)return void s.push(`${l}: ${a.length} tables carry ${C}="${r}" (lines ${a.map(({line:g})=>g).join(", ")}): a key names one table (the view reads the first); take it off the copies`);let[{line:d,offset:f,table:u}]=a;if(!u)return void s.push(`${l}: the frame carrying ${C}="${r}" (line ${d}) holds no table`);i.sourceCodeLocation.startOffset<f&&o.push(`${l} stands before the table it reads (${C}="${r}", line ${d}): it works there, but each block's writing.md writes the table first and the view after it, as its example does: move the view below the table, unless the document is meant to open on it`);let h=n.get(c)?.needs;h&&!h.includes("tables")&&o.push(`${l} carries ${et}="${r}", but its block's needs hold no "tables", so it reads no table: add "tables" to needs in its component.json, or take the key off`);let m=$t(u);m.merged&&o.push(`${l}: its table (line ${d}) has merged cells, which no view reads, so the view shows nothing of it: write each value in its own cell`);let p=m.names?m.rows.length:Math.max(0,m.rows.length-1);p>kt&&o.push(`${l}: its table (line ${d}) has ${p} rows: every view of a table reads it again as it is typed in, and past ${kt} rows that slows typing in it; split it, or keep what a view shows to ${kt} rows`)},yt),{failures:s,notes:o}}function ze(t){let e=w(t),s=[],o=[],{defined:n}=Nt(t),i=null,r=(c,l)=>`${c} ${l}${c===1?"":"s"}`;for(let{type:c,line:l,text:a,source:d,tag:f}of ot(t,e)){if(d===void 0||f==="table"||a!==null||!n.has(c))continue;let u=St(d,i??=G(e));if(u.error)continue;let{rows:h,columns:m,foot:p,extra:g}=Ee(u.cells,u.data),b=`data-doc-chart="${c}" (line ${l})`,k=[r(h,"row")];for(let{name:x,numbers:v,words:T,empty:H}of m){let R=v+T+H,q=v===R&&R>0?"numbers":T===R&&R>0?"words":[v&&r(v,"number"),T&&`${T} as words`,H&&`${H} empty (null)`].filter(Boolean).join(", ")||"no rows";k.push(`"${x}": ${q}`),v>0&&T>0&&o.push(`${b}: its table's column "${x}" (line ${u.line}) reads as numbers in ${r(v,"row")} and as words in ${T}: write each of its cells as one number (an empty cell, "\u2014" or "n/a" for none: null in data), or, for a column of words, data-sort-type="text" on its header cell`)}p>0&&o.push(`${b}: its table's <tfoot> (line ${u.line}) holds ${r(p,"row")} the chart leaves out, and a table with a <tfoot> has no table tools in the preview: keep a total out of a table you chart and say it in the text`),g>0&&o.push(`${b}: ${r(g,"row")} of its table (line ${u.line}) ${g===1?"has":"have"} cells past the header, which the chart does not read: give each column a header cell`),s.push(`${c} (line ${l}) reads its table (line ${u.line}): ${k.join("; ")}`)}return{readings:s,notes:o}}import{BODY as Si,componentOf as Ni,matchesNode as xo}from"../browser/shared/components/index.mjs";import{FLOW as vi}from"../browser/shared/components/list.mjs";import{attr as O,elementsOf as So,walk as M}from"../browser/shared/html-tree.mjs";import{GLYPH_SETS as Oi,ICON_COLORS as No,glyphOf as Ei,glyphValue as Ti,iconKind as Ut,iconMarkup as Li,iconValueOf as Ai}from"../browser/shared/emoji/icon-value.mjs";import ts from"node:vm";import{LINE_START as it,lineStart as es}from"../browser/shared/code-lines.mjs";import{BODY as Me,COMPONENTS as os,FLOWS as ss,instanceSlots as ns,instancesOf as is,isInstance as _,isSlot as Pe,matchesNode as P,ownSlots as as,partOf as Lt,vocabulary as rs}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as A,INSTANCE as cs,PACKAGE_ID as at,SCHEMA as Ot,SLOT as z,schemaAhead as ls}from"../browser/shared/components/installed.mjs";import{packageScript as ds}from"../browser/shared/export-wrap.mjs";import{asDocName as fs,kitNamespace as hs}from"../browser/shared/old-names.mjs";import{shortSheets as us}from"../browser/shared/components/sheets.mjs";import{attr as y,curlyQuoted as ps,hasClass as ms,walk as J}from"../browser/shared/html-tree.mjs";var{authoring:nt,runtime:Ie}=rs(),gs="input, select, textarea, button, details, table",rt=t=>t.sourceCodeLocation?.startLine,$=t=>rt(t)?` (line ${rt(t)})`:"";function je(t){let e=(o,n)=>{let i=Array.from({length:n.length+1},(r,c)=>c);for(let r=1;r<=o.length;r++){let c=i[0];i[0]=r;for(let l=1;l<=n.length;l++){let a=i[l];i[l]=Math.min(i[l]+1,i[l-1]+1,c+(o[r-1]===n[l-1]?0:1)),c=a}}return i[n.length]},[s]=[...nt.keys()].filter(o=>o.startsWith(t.slice(0,7))).map(o=>[o,e(t,o)]).sort((o,n)=>o[1]-n[1]);return s&&s[1]<=3?` (${s[0]}?)`:""}function $s(t,e,s){let{part:o,property:n,min:i}=t.shares,r=new RegExp(`(?:^|;)\\s*${n}\\s*:\\s*([^;]*)`),c=s.map(f=>r.exec(y(f,"style")??"")?.[1].trim()??null),l=c.filter(f=>f!==null);if(l.length===0)return[];let a=`${t.id}${$(e)}`;return l.length<c.length?[`${a}: ${n} on ${l.length} of its ${c.length} ${o}: write it on every one of them, or on none (equal widths)`]:l.map(Number).some(f=>!Number.isFinite(f)||f<i-1e-9||f>1)?[`${a}: ${n} is a share of the row, a number from ${Math.round(i*1e3)/1e3} to 1 (${l.join(", ")})`]:[]}var st={"doc-dialog-header":'a detail card has no header: its content region (<div class="doc-dialog-content">) stands alone in its panel',"doc-dialog-title":"a detail card's title is an ordinary heading (<h3>), first in its content region","doc-dialog-close":"a detail card has no close button: Esc and a press outside it close it","data-doc-dialog-close":"a detail card has no close button: Esc and a press outside it close it","doc-section-header":"a section's title is a plain heading (<h2>) with an ordinary paragraph below it for the line that says what the section is: no <div> goes around them","doc-grid":'a card row is now columns: <div class="doc-columns"> holding one <div class="doc-column"> per card',"doc-grid-3":'a card row is now columns: <div class="doc-columns"> holding three <div class="doc-column">',"doc-lede":`write the line under the title as a paragraph of the header (an ordinary <p>), or as small text, <p class="doc-note"): the header's lines read as the body's paragraphs`,"doc-source":`write the line under the title as a plain paragraph of the header (an ordinary <p>), or as small text (<p class="doc-note">): the header's lines read as the body's paragraphs`,"doc-prose":"write the text straight in its flow (the page, a Sheet panel, a section, a panel, a column\u2026): it reads the same there","doc-prose-h1":"write an h1","doc-prose-h2":"write an h2","doc-prose-h3":"write an h3","doc-prose-h4":"write an h4","doc-state-grid":'put the groups side by side in columns (<div class="doc-columns">)',"doc-state-group":"write the group's title as a heading and its controls as blocks of their own in a column","doc-state-status":'write the line as small text, <p class="doc-note">',"doc-code-block":'a code block is <div class="doc-code"> holding its title (<div class="doc-code-title">) and the <pre><code>',"doc-code-card":'a code block is <div class="doc-code"> holding its title and its <pre>; a diff is <div class="doc-diff">',"doc-code-header":'write the title as <div class="doc-code-title">: the kit draws the rest of the header',"data-doc-diff":'a diff is <div class="doc-diff"> holding its title and its options as JSON (sdk/doc-code.d.ts)',"data-doc-diff-stats":"the kit shows a diff's counts in its header: remove it","doc-code--wrap":"a code block wraps its long lines by itself: remove it (doc-code--nowrap scrolls them instead)"},ws={[it]:'write it on its <div class="doc-code">',"data-start":`write ${it} on its <div class="doc-code">`,"data-line-numbers":'write it on its <div class="doc-code">',"data-folded-lines":'write it on its <div class="doc-code">',"data-title":'write the title in its <div class="doc-code-title">',"data-wrap":'for long lines that scroll, write class="doc-code doc-code--nowrap" on its <div class="doc-code">'};function bs(t){let e=[],s=t.tagName==="pre"?t.parentNode:t.tagName==="code"&&t.parentNode?.tagName==="pre"?t.parentNode.parentNode:null;if(s?.tagName&&P(s,".doc-code"))for(let[n,i]of Object.entries(ws))y(t,n)!==void 0&&e.push(`${n}${$(t)} on the <${t.tagName}> of a code block does nothing: ${i}`);let o=t.tagName==="div"&&P(t,".doc-code")?y(t,it):void 0;return o!==void 0&&es(o)===null&&e.push(`${it}="${o}"${$(t)}: the number of a code block's first line is a whole number from 1`),e}var Re=ss.join(", "),ks=t=>P(t.parentNode,Re)||t.parentNode?.tagName==="div"&&!y(t.parentNode,"class")&&P(t.parentNode.parentNode,Re);function ys(t,e){let s=[];J(e,n=>s.push(...ps(t,n)));let o=n=>n.replace(/=(\s*)[“”]/,'=$1"').replace(/[“”]$/,'"');return s.map(({written:n,line:i},r)=>r===0?`line ${i}: attribute ${n} uses curly quotes (U+201C/U+201D), which HTML reads as part of the value: write straight quotes, ${o(n)}; an editor keeping a file's \u201C\u2026\u201D style may change them`:`line ${i}: attribute ${n} uses curly quotes too: write ${o(n)}`)}var Fe={details:"write a plain <details> without the class (its <summary>, then what it holds): the export makes it the kit's"},xs="write a <section> of no attribute straight in it for each tab, starting with its heading (<h2>\u2013<h4>), the tab's name, the rest its blocks, and nothing else: the export makes the kit's tabs",Ss='a bookmark written the short way is a paragraph in a flow holding only <a class="doc-bookmark" href="https://\u2026">its title</a> (a title attribute its description, nothing else on it, words alone in it): the export makes the card';function Ue(t){let e=[];return J(t,s=>{y(s,A)!==void 0&&e.push(s)},Me),e}var Ns=t=>{let e=t.parentNode;for(;e&&!(_(e)||Pe(e));)e=e.parentNode;return e??null};function vs(t,e){let s=[];return J(t,o=>{let n=y(o,z);if(n===void 0)return;if(_(o))return void s.push(`${z}="${n}"${$(o)} on the instance itself: a slot is an element inside it`);if(!Pe(o))return void s.push(`${z}${$(o)} on a <${o.tagName}>: a slot is a block-level <div> or <section>`);let i=Ns(o),r=i&&_(i)?e?.get(y(i,A)):null;if(!i||!_(i)||r&&We(i,r,o))return void s.push(`${z}="${n}"${$(o)} stands outside any instance's own markup: a slot is a part of a component package's instance, written in its template`);y(o,"data-block-id")!==void 0&&s.push(`${z}="${n}"${$(o)}: a slot is no block: it carries no data-block-id`)}),s}var Os=(t,e)=>{for(let s=e.parentNode;s;s=s.parentNode)if(s===t)return!0;return!1},We=(t,e,s)=>Object.values(e.parts??{}).filter(({edit:o})=>o==="text"||o==="data").some(({at:o})=>Lt(t,o).some(n=>Os(n,s))),_e=(t,e)=>as(t).filter(s=>!We(t,e,s)),Es=t=>t.flatMap(e=>_(e)?at.test(y(e,A))?[]:[`${A}="${y(e,A)}"${$(e)} names no custom block: write <scope>/<name>, the id of a custom block of the workspace's components/ folder`]:[`${A}${$(e)} on a <${e.tagName}>: an instance of a component is a block-level <div> or <section>`]);function Be(t){let e=Ue(t).filter(o=>_(o)&&at.test(y(o,A))),s=e.length>0?E():null;return e.flatMap(o=>{let n=y(o,A),i=s.packages.get(n);if(i&&!ls(y(o,Ot),i.schema))return[];if(i)return[`line ${rt(o)}: <${o.tagName} ${A}="${n}">: ${Ot}="${y(o,Ot)}" is past the ${i.schema??1} its package's manifest reads (schema): nothing can write it back, and the block shows read-only until the package reads it`];let r=s.problems.get(n)?.problem,c=r?`package ${n} does not load (${Jt("en",r)})`:`no package ${n} in this workspace (components/${n}/component.json)`;return[`line ${rt(o)}: <${o.tagName} ${A}="${n}">: ${c}: the block shows what it holds, read-only, and moves, copies and deletes whole`]})}function Et(t,e){let s=[];for(let{name:o,value:n}of t.attrs){if(st[o]&&!nt.has(o)){s.push(`${o}${$(t)} is gone: ${st[o]}`);continue}if(o.startsWith("data-doc-")&&!nt.has(o)&&s.push(Ie.has(o)?`${o}${$(t)} is the kit's to set: remove it`:`${o}${$(t)} is no attribute of the kit's${je(o)}`),o==="class"){for(let i of n.split(/\s+/).filter(e))if(!nt.has(i)){if(st[i]){s.push(`class ${i}${$(t)} is gone: ${st[i]}`);continue}s.push(Ie.has(i)?`class ${i}${$(t)} is the kit's to set: remove it`:`class ${i}${$(t)} is no class of the kit's${je(fs(i))}: give a class of the document's own a name of its own (not doc-\u2026)`)}}}return s}var De=t=>t.startsWith("doc-");function Ts(t){try{return new ts.Script(ds(t),{filename:"kit.js"}),null}catch(e){let s=/^kit\.js:(\d+)/.exec(e.stack??"")?.[1];return{message:e.message,line:s?Number(s):null}}}var Tt=new Map;function Ls(t){if(!t.files.includes("kit.js"))return null;if(Tt.get(t.folder)?.stamp!==t.stamp){let e=tt(t,"kit.js"),s=e===null?null:Ts(e),o=e===null?`${t.id}: its kit.js cannot be read`:s&&`${t.id}: its kit.js does not run: ${s.message}${s.line?` (line ${s.line})`:""}`;Tt.set(t.folder,{stamp:t.stamp,failure:o})}return Tt.get(t.folder).failure}function At(t,e=w(t),s=null){let o=ys(t,e),n=Ue(e);o.push(...Es(n));let i=n.length>0?s??E():null,r=i?[...i.packages.values()]:[];i&&o.push(...L(t,i,e).map(Ls).filter(Boolean));for(let a of[...os,...r].filter(d=>d.match&&(d.parts||d.pairs)))for(let d of is(e,a)){if(a.empty&&!(d.childNodes??[]).some(h=>h.tagName||h.nodeName==="#text"&&h.value.trim()))continue;let f=a.id==="sheets"?us(d):null;if(f){o.push(`${a.id}${$(d)} has no tabs and is no short form: ${f.why??"it stands where no block does (in a whole block or a figure)"}; ${xs}`);continue}if(Fe[a.id]&&Object.values(a.parts??{}).some(h=>Lt(d,h.at).length<(h.optional?0:h.min??1))){o.push(`${a.id}${$(d)} carries the kit's class without the kit's parts: ${Fe[a.id]}`);continue}let u={};for(let[h,m]of Object.entries(a.parts??{})){if(m.edit==="flow"&&at.test(a.id)){let b=_e(d,a).filter(k=>y(k,z)===h);b.length===0&&!m.optional&&o.push(`${a.id}${$(d)} has no ${h} (${z}="${h}")`);for(let k of b.slice(1))o.push(`${a.id}${$(k)}: slot "${h}" twice`);u[h]=b.slice(0,1);continue}u[h]=Lt(d,m.at);let p=m.optional?0:m.min??1,g=m.max??1/0;u[h].length<p?o.push(`${a.id}${$(d)} has ${u[h].length===0?"no":`${u[h].length} of`} ${h} (${m.at.replace(":scope > ","")})${u[h].length>0?`, at least ${p}`:""}`):u[h].length>g&&o.push(`${a.id}${$(d)} has ${u[h].length} of ${h}, at most ${g}`)}if(a.only){let h=new Set(a.only.flatMap(m=>u[m]));for(let m of(d.childNodes??[]).filter(p=>p.tagName&&!h.has(p)))o.push(`${a.id}${$(d)} holds a <${m.tagName}>${$(m)}: only its ${a.only.join(", ")} (${a.only.map(p=>a.parts[p].at.replace(":scope > ","")).join(", ")}) go in it`)}if(a.shares&&o.push(...$s(a,d,u[a.shares.part])),at.test(a.id)){let h=Object.entries(a.parts??{}).filter(([,m])=>m.edit==="flow").map(([m])=>m);for(let m of _e(d,a).filter(p=>!h.includes(y(p,z))))o.push(`${a.id}${$(m)}: slot "${y(m,z)}" is no part of its manifest edited as flow`)}for(let{a:h,attrA:m,b:p,attrB:g}of a.pairs??[]){let b=u[h].map(x=>y(x,m)),k=u[p].map(x=>y(x,g));for(let x of new Set(b.filter((v,T)=>b.indexOf(v)!==T)))o.push(`${a.id}${$(d)}: ${h} "${x}" twice`);for(let x of b.filter(v=>!k.includes(v)))o.push(`${a.id}${$(d)}: ${h.replace(/s$/,"")} "${x}" has no ${p.replace(/s$/,"")} (${g}="${x}")`);for(let x of k.filter(v=>!b.includes(v)))o.push(`${a.id}${$(d)}: ${p.replace(/s$/,"")} "${x}" has no ${h.replace(/s$/,"")} (${m}="${x}")`)}}o.push(...vs(e,i?.packages));let c=new Set,l=[];J(e,a=>{if(_(a)){let u=new Set(ns(a));o.push(...Et(a,De)),J(a,h=>o.push(...Et(h,De)),{stop:h=>u.has(h)});return}a.tagName==="pre"&&ks(a)&&o.push(`<pre>${$(a)} straight in the text: a code block is <div class="doc-code"> holding its title (<div class="doc-code-title">) and the <pre>`),o.push(...bs(a)),a.tagName==="a"&&ms(a,"doc-bookmark")&&o.push(`<a class="doc-bookmark">${$(a)} is no bookmark: ${Ss}`),o.push(...Et(a,hs));let d=y(a,"data-doc-bind");d!==void 0&&(d.trim()?P(a,gs)?a.tagName==="button"&&y(a,"value")===void 0?o.push(`data-doc-bind${$(a)} on a button without a value: give it the value a click chooses`):c.add(d.trim()):o.push(`data-doc-bind${$(a)} on a ${a.tagName}: only inputs, selects, textareas, buttons with a value, details and tables hold a key`):o.push(`data-doc-bind${$(a)} names no key`));let f=y(a,"data-doc-show");f!==void 0&&l.push([a,f])},Me);for(let[a,d]of l){let f=d.split(":")[0].trim();!f||!d.includes(":")?o.push(`data-doc-show="${d}"${$(a)}: write key:value`):c.has(f)||o.push(`data-doc-show="${d}"${$(a)}: nothing binds "${f}" (data-doc-bind="${f}")`)}return o.push(...Rs(t,e)),o}var As=/(?<![\\$])\$(?=[^\s$])([^$]*?[^\s$\\])\$(?![$\d])/g,Cs=/(?:(?<![A-Za-z0-9_])[A-Za-z]|[)\]}])_[A-Za-z0-9{]/,zs=t=>/[\\^]/.test(t)||!t.startsWith("{")&&Cs.test(t),Is=new Set(["head","code","pre","kbd","samp","script","style","template","textarea","noscript","svg","math","title","iframe","object"]),js=`.doc-math-inline, .doc-math-block, .doc-code, .doc-diff, [data-doc-math-dollar], [data-doc-chart], ${cs}`;function Rs(t,e){let s=[],o=n=>{for(let i of n.childNodes??[])if(i.nodeName==="#text"&&i.sourceCodeLocation&&i.value.includes("$")){let{startOffset:r,endOffset:c}=i.sourceCodeLocation;for(let l of t.slice(r,c).matchAll(As)){if(!zs(l[1]))continue;let a=l[1].replace(/\s+/g," "),d=a.length>60?`${a.slice(0,59)}\u2026`:a;s.push(`line ${qt(t,r+l.index)}: $${d}$ is not drawn as a formula (single dollars are off: they are money): write \\(${d}\\)`)}}else i.tagName&&!Is.has(i.tagName)&&!P(i,js)&&o(i)};return o(e),s}import V from"node:fs";import W from"node:path";import{COLOR_NAMES as Ks}from"../browser/shared/colors.mjs";import{FOLD_DOTS as Gs}from"../browser/shared/code-folds.mjs";import{kitPublicDirectory as Js,kitSourceDirectory as Vs,release as Zs}from"../browser/shared/paths.mjs";import{FLOW_LABEL as Ua}from"../browser/shared/components/list.mjs";var Fs={"code-title":{zh:"\u4EE3\u7801\u5757",en:"Code"},"plain-text":{zh:"\u7EAF\u6587\u672C",en:"Plain text"},"fold-code":{zh:"\u6298\u53E0\u6216\u5C55\u5F00\u4EE3\u7801\u5757",en:"Collapse or expand the code block"},"copy-code":{zh:"\u590D\u5236\u4EE3\u7801",en:"Copy code"},copied:{zh:"\u5DF2\u590D\u5236",en:"Copied"},wrap:{zh:"\u81EA\u52A8\u6362\u884C",en:"Wrap lines"},"no-wrap":{zh:"\u53D6\u6D88\u81EA\u52A8\u6362\u884C",en:"Stop wrapping lines"},fold:{zh:"\u6298\u53E0",en:"Collapse"},unfold:{zh:"\u5C55\u5F00",en:"Expand"},line:{zh:"\u7B2C {0} \u884C",en:"Line {0}"},lines:{zh:"\u7B2C {0}\u2013{1} \u884C",en:"Lines {0}\u2013{1}"},"diff-counts":{zh:"\u65B0\u589E {0} \u884C\uFF0C\u5220\u9664 {1} \u884C",en:"Lines added: {0}, removed: {1}"}};var He="data-ge-language",_s={"code-title":"--doc-word-code-title"};function Ds(t,e,s,...o){let n=t[s];if(!n)throw new Error(`The kit has no word "${s}" here (src/render/kit/words.js).`);let i=n[e]??n.zh;return o.length===0?i:i.replace(/\{(\d+)\}/g,(r,c)=>c<o.length?String(o[c]):r)}var Ms=`:root[${He}="en"], :root:not([${He}])[lang|="en" i]`;function Ke(){let t=e=>Object.entries(_s).map(([s,o])=>`${o}: ${JSON.stringify(Ds(Fs,e,s))};`).join(" ");return`:root { ${t("zh")} }
|
|
4
4
|
${Ms} { ${t("en")} }`}import{LOOK as Ct,LOOK_ATTRIBUTES as Ps,SERIF_FONT as Ge,SIZE_FACTOR as Us,SPACING as Ws,WIDTH as zt}from"../browser/shared/document-look.mjs";var Je=[["--doc-body-font-size","--doc-body-line-height"],["--doc-small-font-size","--doc-small-line-height"],["--doc-note-font-size","--doc-note-line-height"],["--doc-title-font-size","--doc-title-line-height"],["--doc-h1-font-size","--doc-h1-line-height"],["--doc-h2-font-size","--doc-h2-line-height"],["--doc-h3-font-size","--doc-h3-line-height"],["--doc-h4-font-size","--doc-h4-line-height"],["--doc-card-title-font-size","--doc-card-title-line-height"],["--doc-table-font-size","--doc-table-line-height"]],Bs=["--doc-component-gap","--doc-block-gap","--doc-media-gap","--doc-paragraph-gap","--doc-group-gap","--doc-list-gap"],It="--doc-content-max-width";function Hs(t){let e=new Map;for(let[,s,o]of String(t).matchAll(/^\s*(--doc-[a-z0-9-]+):\s*([^;]+);/gm))e.has(s)||e.set(s,o.trim());return e}var ct=t=>`${Math.round(t)}px`;function lt(t,{size:e="default",spacing:s="default",width:o="default"}={}){let n=a=>{let d=/^(-?[0-9.]+)px$/.exec(t.get(a)??"");if(!d)throw new Error(`src/render/kit/styles/tokens.css: ${a} is no length in px (src/render/look-css.mjs reads it)`);return Number(d[1])},i=Us[e],{leading:r,gaps:c}=Ws[s],l={};if(e!=="default"||s!=="default")for(let[a,d]of Je){let f=n(a)*i;e!=="default"&&(l[a]=ct(f)),l[d]=ct(Math.round(f)+(n(d)-n(a))*i*r)}if(s!=="default"){for(let a of Bs)l[a]=ct(n(a)*c);l["--doc-space"]=String(c)}if(o!=="default"){if(n(It)!==zt.default)throw new Error(`src/render/kit/styles/tokens.css: ${It} is not \u9ED8\u8BA4 \u6B63\u6587\u5BBD\u5EA6's ${zt.default}px (src/shared/document-look.mjs WIDTH)`);l[It]=ct(zt[o])}return l}var U=(t,e)=>`${t} { ${Object.entries(e).map(([s,o])=>`${s}: ${o};`).join(" ")} }`,D=(t,e)=>`[${Ps[t]}="${e}"]`;function Ve(t){let e=Hs(t),s=e.get("--doc-font");if(!s)throw new Error("src/render/kit/styles/tokens.css: no --doc-font (src/render/look-css.mjs keeps it as --doc-sans-font)");let o=[U(`:root${D("font","serif")}`,{"--doc-sans-font":s,"--doc-font":Ge}),U(`:root${D("font","mixed")}`,{"--doc-heading-font":Ge})],[,...n]=Ct.size,[,...i]=Ct.spacing,[,...r]=Ct.width;for(let c of n)o.push(U(`:root${D("size",c)}`,lt(e,{size:c})));for(let c of i)o.push(U(`:root${D("spacing",c)}`,lt(e,{spacing:c})));for(let c of r)o.push(U(`:root${D("width",c)}`,lt(e,{width:c})));for(let c of n)for(let l of i){let a=lt(e,{size:c,spacing:l});o.push(U(`:root${D("size",c)}${D("spacing",l)}`,Object.fromEntries(Je.map(([,d])=>[d,a[d]]))))}return o.join(`
|
|
5
5
|
`)}var Ze=Object.fromEntries(K.filter(t=>t.file).map(t=>[t.file,t.build])),tr=Object.keys(Ze),Z=t=>W.join(Vs,t),Ys=(t,e,s)=>({entryPoints:[Z(t)],bundle:!0,write:!1,format:"iife",platform:"browser",target:"es2022",...typeof e=="function"?e():e,...s}),qs=t=>{let e=Ze[t];if(!e)throw new Error(`src/render/kit-build.mjs: no kit file "${t}"`);return e},dt=new Map;function Xs(t,e){let s=[...e.matchAll(/^@import\s+"\.\/([a-z0-9-]+\.css)";\s*$/gm)].map(i=>i[1]),o=V.readdirSync(W.dirname(Z(t))).filter(i=>i.endsWith(".css")&&i!==W.basename(t)),n=[...o.filter(i=>!s.includes(i)).map(i=>`${i} is not listed`),...s.filter((i,r)=>!o.includes(i)||s.indexOf(i)!==r).map(i=>`${i} is listed but missing, or listed twice`)];if(n.length>0)throw new Error(`src/render/kit/${t}: ${n.join("; ")}`);return s.map(i=>W.join(W.dirname(t),i))}var Qs=t=>t.replace(/@(text|highlight)-colors\b/g,(e,s)=>Ks.map(o=>`.doc-${s}-${o}`).join(", ")),tn=t=>{let e=Qs(t.join(`
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{a as m,b as u,c as f,d}from"./chunk-
|
|
2
|
+
import{a as m,b as u,c as f,d}from"./chunk-EAIFITAV.mjs";import{b as p}from"./chunk-67N2QJYT.mjs";import{j as n}from"./chunk-4OZWXZE5.mjs";import{l as i,t as a,w as c}from"./chunk-MXUBKDRO.mjs";import{reportsDirectory as g}from"../browser/shared/paths.mjs";import{documentDirectory as $,documentFiles as y}from"../browser/shared/workspace.mjs";var k=()=>`No documents in ${g} yet: gallery new <slug> "<title>" makes one.`;async function A(w){let{slugs:e,options:h}=await n({options:["--allow-failures"],argv:w,noneIsAll:!0});e.length===0&&(console.error(k()),process.exit(1)),await p(e),await f(e),await d(e);let{reports:r,failures:t}=await i(e,{prepare:m()}),s=r.filter(o=>!t.has(o.slug));for(let o of s)console.log(`OK ${o.slug}`);for(let o of e)y($(o,g)).both&&console.log(`note ${o}: both doc.html and report.html: report.html is not read`);a(r),u(r);let l=s.length+t.size;console.log(`Checked ${l} document${l===1?"":"s"}: ${s.length} passed, ${t.size} failed.`),await c(t,{allow:h.has("--allow-failures")})}export{k as a,A as b};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
|
|
2
|
-
import{A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"./chunk-
|
|
2
|
+
import{A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"./chunk-7JDX4E65.mjs";import"./chunk-3MBRL2PM.mjs";import"./chunk-HPOI4ZX7.mjs";import"./chunk-342HXE3Q.mjs";import"./chunk-EAIFITAV.mjs";import"./chunk-67N2QJYT.mjs";import"./chunk-5XA2ZBAE.mjs";import"./chunk-JEUK3ZO7.mjs";import"./chunk-JLTZF4LA.mjs";import"./chunk-PUOQ65NC.mjs";import"./chunk-DJISHPUL.mjs";import"./chunk-ZWWC4KLF.mjs";import"./chunk-IA4PSIMD.mjs";import"./chunk-F4ZA6JRZ.mjs";import"./chunk-7M2BQQGZ.mjs";import"./chunk-ITOH5EGO.mjs";import"./chunk-ZQS6H473.mjs";import"./chunk-4OZWXZE5.mjs";import"./chunk-MXUBKDRO.mjs";import"./chunk-HXG7EOPJ.mjs";import"./chunk-ZTHICSSF.mjs";import"./chunk-6N3PX4XX.mjs";import"./chunk-PAREWQGB.mjs";import"./chunk-BFJGHSQN.mjs";import"./chunk-U5XL7D6A.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-R2ZDLJYT.mjs";import"./chunk-VFX2KNHP.mjs";import"./chunk-VS7JIGJW.mjs";import"./chunk-HDWTZ763.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";export{b as BEGIN,e as GESTURES,M as INSIDE_ALONE,N as OPEN_IT,a as READY,c as SAVING,L as TRY_LINES,m as asShown,o as changesOf,k as chosenInstance,z as cutOffSaid,D as documentHost,y as dragPath,x as drawn,s as dropScratch,t as dropStale,v as fallbackSaid,g as gestureOf,i as instancesIn,d as keysOf,B as listen,P as madeSaid,A as nothingSaid,n as partsOf,j as placeSaid,r as scratchCopy,f as stepOf,E as stepsCalled,h as stepsOf,K as stoppedTrial,C as takenAgain,u as takenBy,q as toldBy,J as trial,O as trialSaid,Q as tryCommand,w as untilTaken,l as withoutIds,F as wordsDiffer,G as wordsIn,p as writtenLines,I as writtenOtherwise,H as writtenWords};
|
|
@@ -0,0 +1,166 @@
|
|
|
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 jn}from"./chunk-DR73Y2UJ.mjs";import{b as Cn}from"./chunk-JLTZF4LA.mjs";import{a as bn,i as En,j as On}from"./chunk-PUOQ65NC.mjs";import{a as $n,b as Sn}from"./chunk-7OG26PGF.mjs";import{k as Ge}from"./chunk-DJISHPUL.mjs";import{h as gn}from"./chunk-ZWWC4KLF.mjs";import{a as yn}from"./chunk-AHN3NFKJ.mjs";import{a as xn}from"./chunk-MTYYHM2G.mjs";import{a as kn,b as vn}from"./chunk-ALZ6ZENZ.mjs";import{a as wn}from"./chunk-2OHANJ6Q.mjs";import{a as fn,b as Ke,d as mn,e as un,f as pn,g as hn}from"./chunk-7M2BQQGZ.mjs";import{b as ft,e as Ht,g as mt,h as Gt,j as Kt,k as Jt}from"./chunk-UYVCQK3H.mjs";import{a as Dt,d as Lt,e as It,f as Nt,k as Mt,l as Wt,m as Ut,r as Bt,t as dt,u as zt}from"./chunk-J5PUIV3Y.mjs";import{b as nn,c as on,d as Oe,e as rn,f as an,g as He,i as sn,m as cn,p as ln,q as dn}from"./chunk-MXUBKDRO.mjs";import{d as en,e as Re,f as Be,g as ut,h as tn,k as ze}from"./chunk-6N3PX4XX.mjs";import{b as Yt,c as Xt}from"./chunk-PAREWQGB.mjs";import{i as Zt,j as Qt,k as qt}from"./chunk-BFJGHSQN.mjs";import{d as Vt}from"./chunk-U5XL7D6A.mjs";import{a as Ie}from"./chunk-VS7JIGJW.mjs";import{c as ct,g as re,j as Pt,k as Tt,p as Rt,q as Ft,v as At,w as lt}from"./chunk-HDWTZ763.mjs";import st from"node:fs";import is from"node:fs/promises";import cs from"node:http";import{editStateDirectory as ls,kitPublicDirectory as ds,release as fs,releaseFile as it,reportsDirectory as Pe,vendorDirectory as ms,workbenchDirectory as us}from"../browser/shared/paths.mjs";import{serve as Uo}from"../browser/shared/http.mjs";import{ensureWorkspace as ps,layoutOf as hs}from"../browser/shared/workspace.mjs";import ge from"node:fs/promises";import J from"node:path";import{assetFile as Ho,referencedFile as _n}from"../browser/shared/media.mjs";import{pageAssetAddress as Go}from"../browser/shared/pages.mjs";function pt(e,n){if(!/assets\//i.test(e))return e;let t=Qt(e,a=>_n(a)!==null);return Zt(e,qt(t,a=>{let s=_n(a.value);return Ho(s)?`${Go(n,s)}${/[?#].*$/.exec(a.value.trim())?.[0]??""}`:null}))}function Pn(e,{reportsDirectory:n,kit:t,slug:a=null}={}){let{html:s,packages:f}=an(a?pt(e,a):e,{reportsDirectory:n,kit:t,page:!0});return{html:s,packages:f}}import{Z as Ko}from"../browser/shared/layers.mjs";import{escapeMarkup as ht}from"../browser/shared/escape.mjs";import{layoutNotesScript as Jo}from"../browser/shared/qa-levels.mjs";var Je=30,Yo=`
|
|
3
|
+
[data-doc-dev].doc-checks { position: fixed; z-index: ${Ko.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; } }`,Xo=`(() => {
|
|
17
|
+
document.currentScript.remove();
|
|
18
|
+
${Jo()}
|
|
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 Tn(e,n,t={},{directory:a}={}){let s=sn({slug:e,html:n,metadata:t,...a?{directory:a}:{}}),f=s.slice(0,Je).map(h=>`<li>${ht(h)}</li>`).join(""),r=s.length>Je?`<p data-more="${s.length-Je}">\u8FD8\u6709 ${s.length-Je} \u9879</p>`:"",m=s.length?`<ul>${f}</ul>${r}<p data-all="${ht(e)}">gallery check ${ht(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>${Yo}</style></details>
|
|
70
|
+
<script data-doc-dev>${Xo}</script>`}import{browserDirectory as wa,editStateDirectory as ya,kitSourceDirectory as Po,release as ka,reportsDirectory as D}from"../browser/shared/paths.mjs";import{FRAMED_BY as va,sendJson as go,serve as Ot,serveFound as Ae}from"../browser/shared/http.mjs";import{languageScript as wo}from"../browser/shared/i18n/index.mjs";import{announcePreviewServer as xa,galleryVersion as $a}from"../browser/shared/preview-server.mjs";import{registerQuietly as Sa}from"../browser/shared/workspace-registry.mjs";import{lookWord as yo}from"../browser/shared/document-look.mjs";import{documentLook as ko,ownLookAt as ba}from"../browser/shared/workspace-look.mjs";import{slugPattern as To}from"../browser/shared/reports.mjs";import{ATTRIBUTE as ot,PACKAGE_ID as Ea}from"../browser/shared/components/installed.mjs";import{COMPONENTS_FOLDER as vo,DOCUMENT_FOLDERS as xo,EXTENSIONS_FOLDER as Oa,PAGES_FOLDER as Ca,WORKSPACE_FILE as rt,documentDirectory as bt,documentFiles as ja,isDocumentFile as _a,isDocumentSource as $o,isSlugName as Ro,layoutOf as Pa}from"../browser/shared/workspace.mjs";import{PAGE_FILES as So,homeCardsNew as Ta,isBlankPage as Ra,isPageFile as Fa,pageFiles as bo,pageHintShown as Aa,pageMetaNow as Da,pageVersion as Eo}from"../browser/shared/pages.mjs";import{LINK_FILE as La}from"../browser/shared/web-links.mjs";import{SIDEBAR_FILE as Oo}from"../browser/shared/extension-sidebar.mjs";import{extensionColumnIds as Co}from"../browser/shared/extensions.mjs";import{isExtensionId as Ia}from"../browser/shared/outline-shape.mjs";import{createHash as lr,randomBytes as dr}from"node:crypto";import Q from"node:fs";import gt from"node:os";import he from"node:path";import{Transform as fr}from"node:stream";import{pipeline as mr}from"node:stream/promises";import{exportSourceOf as ur}from"../browser/shared/export-wrap.mjs";import{writeAtomic as wt}from"../browser/shared/files.mjs";import{sendJson as K}from"../browser/shared/http.mjs";import{said as yt,saying as pr}from"../browser/shared/i18n/index.mjs";import{IMPORT_LIMIT as Ln}from"../browser/shared/import-types.mjs";import{mediaUrl as hr}from"../browser/shared/media.mjs";import{fullAddress as gr}from"../browser/shared/page-address.mjs";import{documentLinks as In,slugPattern as Nn}from"../browser/shared/reports.mjs";import{documentDirectory as wr,documentFiles as Mn,newDocSlug as yr,pageSlug as kr}from"../browser/shared/workspace.mjs";import{readWritingPreferences as vr,saysAnything as xr,unshownLines as $r}from"../browser/shared/writing-preferences.mjs";import Rn from"node:fs/promises";import or from"node:path";import{Worker as Vo}from"node:worker_threads";import{refusal as Zo,said as Qo}from"../browser/shared/i18n/index.mjs";var qo=6e4,me=null,er=0,Ye=0,Ce=new Map;function tr(){me=new Vo(new URL("./worker.mjs",import.meta.url)),me.on("message",({id:n,result:t,error:a})=>{let s=Ce.get(n);s&&(Ce.delete(n),a?s.reject(Object.assign(new Error(a.message),a)):s.resolve(t),Ce.size===0&&(me?.unref(),nr()))});let e=n=>{for(let t of Ce.values())t.reject(n);Ce.clear(),me=null};me.on("error",e),me.on("exit",n=>e(Zo(Qo("\u8F6C\u6362\u8FDB\u7A0B\u610F\u5916\u9000\u51FA\uFF08{0}\uFF09",n))))}function nr(){clearTimeout(Ye),Ye=setTimeout(()=>{if(Ce.size===0&&me){let e=me;me=null,e.removeAllListeners("exit"),e.terminate()}},qo),Ye.unref?.()}function ve(e,n){clearTimeout(Ye),me||tr();let t=++er;return new Promise((a,s)=>{Ce.set(t,{resolve:a,reject:s}),me.ref(),me.postMessage({id:t,type:e,payload:n})})}import{pageLanguage as rr}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("."),[a,s]=t>0?[e.slice(0,t),e.slice(t)]:[e,""];for(let f=0;;f+=1){let r=f===0?e:`${a} ${f}${s}`;if(!n.has(r.toLowerCase()))return n.add(r.toLowerCase()),r}}function Ze(e,n){let t=e.split("/").slice(0,-1),a=n.split("/"),s=0;for(;s<t.length&&s<a.length-1&&t[s]===a[s];)s+=1;return[...t.slice(s).map(()=>".."),...a.slice(s)].map(r=>r===".."?r:encodeURIComponent(r).replace(/\(/g,"%28").replace(/\)/g,"%29")).join("/")}import{documentDirectory as ar,documentFiles as sr}from"../browser/shared/workspace.mjs";var Fn={markdown:"md",html:"html",pdf:"pdf"},ir={markdown:"text/markdown; charset=utf-8",html:"text/html; charset=utf-8",pdf:"application/pdf"},cr=e=>typeof e=="number"&&e>.1&&e<2;function An(e){let{format:n,content:t="everything",subpages:a=!1,folders:s=!0,paper:f="A4",scale:r=1}=e??{};return Object.hasOwn(Fn,n)&&["everything","no_files"].includes(t)&&typeof a=="boolean"&&typeof s=="boolean"&&["A4","A3","Letter","Legal","Tabloid"].includes(f)&&cr(r)}async function Dn(e,n,t){let{format:a,content:s="everything",subpages:f=!1,folders:r=!0,paper:m="A4",scale:l=1}=n,h=Fn[a],w=s==="everything",i=[],k=new Map,R=v=>k.get(v)??k.set(v,new Set).get(v),u=async(v,b)=>{let B=await t.titleOf(v),H=Ve(`${Xe(B)}.${h}`,R(b)),z=b?`${b}/${H}`:H,L=r?z.slice(0,-(h.length+1)):"";if(i.push({slug:v,title:B,file:z,folder:L,files:b?`${b}/assets`:"assets"}),f)for(let ae of await t.childrenOf(v))await u(ae,L)};await u(e,"");let{links:F}=await t.links(),S=(v,b)=>on(b,v.slug,B=>{let H=a==="pdf"?null:i.find(z=>z.slug===B)?.file??null;return H&&Ze(v.file,H)},{blocks:a!=="markdown",links:F}),x=[],Y=[];for(let v of i)if(a==="markdown"){await t.check(v.slug);let b=ar(v.slug,t.reportsDirectory),B=Oe(await Rn.readFile(sr(b).html,"utf8"),{slug:v.slug,mode:"words",reportsDirectory:t.reportsDirectory}),H=S(v,B),z=w&&!!bn(),{text:L,files:ae,charts:ne,charted:U}=await ve("markdown",{source:H,title:v.title,pictures:z}),G=L,ce=new Map;if(ae.forEach(({src:p,name:g},E)=>{ce.has(p)||(ce.set(p,`${v.files}/${Ve(Xe(g),R(v.files))}`),w&&Y.push({from:or.join(b,p),name:ce.get(p)}));let C=ce.get(p);G=G.replace(`\0F${E}\0`,()=>Ze(v.file,C))}),z&&ne>0&&G.includes("\0C")){let p=await On(await t.offline(v.slug,{files:!0})).catch(()=>[]);G=G.replace(/^.*\u0000C(\d+)\u0000.*$/gm,(g,E)=>{let C=p[Number(E)];if(!C)return"\0gone\0";let _=`${v.files}/${Ve(rr(H)==="en"?U[Number(E)]?"Chart.png":"Figure.png":U[Number(E)]?"\u56FE\u8868.png":"\u56FE.png",R(v.files))}`;return x.push({name:_,data:C,later:!0}),g.replace(`\0C${E}\0`,()=>Ze(v.file,_))}).replace(/\n*\u0000gone\u0000\n*/g,`
|
|
71
|
+
|
|
72
|
+
`).replace(/^\n+|\n+$/g,"")}x.push({name:v.file,data:G})}else a==="html"?x.push({name:v.file,data:S(v,await t.offline(v.slug,{files:w}))}):x.push({name:v.file,data:await En(S(v,await t.offline(v.slug,{files:w})),{paper:m,scale:l})});for(let v of Y){let b=await Rn.readFile(v.from).catch(()=>null);b&&x.push({name:v.name,data:b})}let W=[...x.filter(v=>!v.later&&i.some(b=>b.file===v.name)),...x.filter(v=>v.later||!i.some(b=>b.file===v.name))];return W.length===1?{name:W[0].name,type:ir[a],data:Buffer.isBuffer(W[0].data)?W[0].data:Buffer.from(W[0].data,"utf8")}:{name:`${Xe(i[0].title)}.zip`,type:"application/zip",data:wn(W)}}var Sr=3600*1e3,kt=new Set,Wn=!1,br=e=>{kt.add(e),!Wn&&(Wn=!0,process.once("exit",()=>{for(let n of kt)try{Q.rmSync(n,{recursive:!0,force:!0})}catch{}}))},Er=/^u-[a-f0-9]{16}$/;function Un({edits:e,workspace:n,reports:t,reportsDirectory:a,offline:s}){let f=null,r=()=>f??=Q.promises.mkdtemp(he.join(gt.tmpdir(),"gallery-uploads-")).then(p=>(br(p),p)),m=new Map,l=(p,g,E)=>[p,{ok:!1,reason:g,...pr(E)}],h=p=>Q.promises.access(p).then(()=>!0,()=>!1),w=p=>wr(p,a),i=p=>Mn(w(p)),k=async p=>{try{return JSON.parse(await Q.promises.readFile(i(p).json,"utf8")).title||p}catch{return p}};function R(p){if(p.method!=="POST")return[405,{ok:!1,reason:"method"}];let g=p.headers.host??"",E=p.socket.localPort;return g!==`127.0.0.1:${E}`&&g!==`localhost:${E}`?[403,{ok:!1,reason:"host"}]:p.headers.origin!==`http://${g}`?[403,{ok:!1,reason:"origin"}]:p.headers["x-gallery-token"]!==e.token?[403,{ok:!1,reason:"token"}]:/^application\/octet-stream\b/i.test(p.headers["content-type"]??"")?Number(p.headers["content-length"]??0)>Ln?l(413,"size","\u6587\u4EF6\u592A\u5927\uFF08\u6700\u591A 5GB\uFF09"):null:[415,{ok:!1,reason:"type"}]}async function u(){for(let[p,g]of m)Date.now()-g.at<Sr||(m.delete(p),await Q.promises.rm(g.file,{force:!0}).catch(()=>{}))}async function F(p,g){let E=R(p);if(E)return p.resume(),K(g,...E);let C=new URL(p.url,"http://localhost").searchParams.get("name")?.replace(/[\u0000-\u001f]/g,"").trim()??"";if(!C||C.length>255)return p.resume(),K(g,...l(400,"name","\u6587\u4EF6\u540D\u4E0D\u5BF9"));await u();let _=`u-${dr(8).toString("hex")}`,j=he.join(await r(),_),N=0,A=new fr({transform(I,Z,X){N+=I.length,X(N>Ln?Object.assign(new Error("too-large"),{reason:"size"}):null,I)}});try{await mr(p,A,Q.createWriteStream(j))}catch(I){return await Q.promises.rm(j,{force:!0}).catch(()=>{}),I.reason==="size"?K(g,...l(413,"size","\u6587\u4EF6\u592A\u5927\uFF08\u6700\u591A 5GB\uFF09")):K(g,...l(400,"body","\u6587\u4EF6\u6CA1\u6709\u4F20\u5B8C"))}return m.set(_,{file:j,name:C,at:Date.now()}),K(g,200,{ok:!0,id:_})}async function S(p,g){let E=await e.check(p);if(E.error)return K(g,...E.error);let{slug:C,options:_}=E.body??{};if(typeof C!="string"||!Nn.test(C)||!await h(i(C).html))return K(g,...l(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"));if(!An(_))return K(g,...l(400,"options","\u5BFC\u51FA\u9009\u9879\u4E0D\u5BF9"));try{let j=await s(),N=new Map,A=P=>(N.has(P)||N.set(P,e.handIn(P,{reader:!0}).then(M=>{if(!M.ok)throw Object.assign(new Error(M.message??M.reason),{reason:M.reason});if(M.repeated.length)throw Object.assign(new Error("check"),{reason:"check",slug:P,failures:He(M.repeated)})})),N.get(P)),I=new Map,Z={reportsDirectory:a,titleOf:k,childrenOf:async P=>{let{children:M,links:se=[]}=await n.outline(),oe=we=>(M[we]??[]).flatMap(ye=>se.includes(ye)||ye.startsWith("~")?oe(ye):[ye]);return oe(P)},links:()=>In(a),offline:async(P,M)=>{await A(P);let se=await j(P,M),oe=_.format==="markdown"?null:ur(se);return oe&&I.set(P,oe),se},check:async P=>(await A(P),j.check(P))},{name:X,type:V,data:q}=await Dn(C,_,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(j){if(j.reason==="check"){let N=await k(j.slug),A=j.component?yt("\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,j.component):j.failures.length>1?yt("\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,j.failures[0],j.failures.length):yt("\u300C{0}\u300D\u6CA1\u6709\u901A\u8FC7\u5BFC\u51FA\u524D\u7684\u68C0\u67E5\uFF0C\u6CA1\u6709\u751F\u6210\u6587\u4EF6\uFF1A{1}",N,j.failures[0]);return K(g,...l(422,"check",A))}K(g,...l(j.reason==="browser"?422:j.reason==="busy"?409:j.reason==="missing"?404:500,j.reason??"export",j))}}async function x(p,g){let E=await e.check(p);if(E.error)return K(g,...E.error);let{slug:C}=E.body??{},_=(await e.readTaken(C,{wait:0}))?.text??null;if(_===null)return K(g,...l(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"));let j=`http://${p.headers.host}`,{named:N}=await In(a),A=nn(Oe(_,{slug:C,mode:"words",reportsDirectory:a}),C,V=>V.slug&&gr(j,V,N),N),{text:I,files:Z}=await ve("markdown",{source:A,title:await k(C),pictures:!1}),X=I.replace(/\u0000F(\d+)\u0000/g,(V,q)=>{let{src:P,kind:M}=Z[Number(q)];return encodeURI(`${j}${hr(M==="image"?"asset":"file",C,P)}`)});return K(g,200,{ok:!0,text:X})}let Y=async p=>{let g=await e.readTaken(p,{wait:0});return{source:g?.text??"",version:g?.version??null}},W=async(p,g=null)=>{let{source:E,version:C}=g??await Y(p),_="\u5199\u4F5C\u504F\u597D",{text:j,files:N}=await ve("markdown",{source:E,title:_,pictures:!1}),A=j.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:`# ${_}
|
|
75
|
+
`,empty:!0,version:C};let I=he.relative(a,w(p)).split(he.sep).join("/");return{markdown:`${j.replace(/\u0000F(\d+)\u0000/g,(Z,X)=>encodeURI(`${I}/${N[Number(X)].src}`))}
|
|
76
|
+
`,empty:!1,version:C}},v=p=>i(p).json,b=async p=>{try{let g=JSON.parse(await Q.promises.readFile(v(p),"utf8"));return g&&typeof g=="object"?g:null}catch{return null}},B=p=>lr("sha256").update(p).digest("hex").slice(0,16);async function H(p,g,E,C){let _=await b(p);if(!_||E===null)return;let{synced:j,...N}=_,A={file:B(g),page:E,unshown:C},I=_.madeSame;j===void 0&&I?.file===A.file&&I?.page===A.page&&JSON.stringify(I?.unshown)===JSON.stringify(C)||await wt(v(p),`${JSON.stringify({...N,madeSame:A},null,2)}
|
|
77
|
+
`)}async function z(p,g){let E=await Q.promises.mkdtemp(he.join(gt.tmpdir(),"gallery-preferences-"));try{let _=(await ve("import",{uploads:[{file:g,name:"preferences.md"}],scratch:E})).pages[0]??{nodes:[],raws:[],files:[],icon:null,lang:null},j=w(p),N=await b(p)??{},A=Mn(j).html,I=await Q.promises.readFile(A,"utf8").catch(()=>""),Z=/<html\b[^>]*\slang="([^"]*)"/i.exec(I)?.[1]??null,{html:X}=await Xt(p,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:_.nodes,icon:V,raws:_.raws,lang:_.lang});_.files.length&&await Q.promises.mkdir(he.join(j,"assets"),{recursive:!0});for(let{from:M,name:se}of _.files){let oe=he.join(j,"assets",se);await h(oe)||await Q.promises.copyFile(M,oe)}let P=await Q.promises.readFile(A,"utf8").catch(()=>null);P!==null&&e.keepVersion?.(p,P),await wt(A,ze(q))}finally{await Q.promises.rm(E,{recursive:!0,force:!0}).catch(()=>{})}}async function L(p,g){let E=await e.check(p);if(E.error)return K(g,...E.error);let C=E.body?.opening===!0,_=await kr(a);if(!_)return K(g,...l(404,"missing","\u8FD8\u6CA1\u6709\u5199\u4F5C\u504F\u597D"));let j=null,N=(A,I)=>[200,{ok:!0,path:he.resolve(j),remade:A,unshown:I}];return e.respond(async()=>{let A;({file:j,text:A}=await vr(a));let I=await Y(_),Z=(await b(_))?.madeSame??null,X=Z===null||Z.page===I.version,V=Z!==null&&X&&Z.file===B(A);if(C&&V&&Array.isArray(Z.unshown))return N(!1,Z.unshown);let[q,P,M,se]=[A,"",I.version,!1];if(C&&!X)await z(_,j),{markdown:P,version:M}=await W(_),se=!0;else{let we=await W(_,I),ye=A.trim()===we.markdown.trim()||we.empty&&!xr(A);P=we.markdown,C?!ye&&!V&&(await z(_,j),{markdown:P,version:M}=await W(_),se=!0):ye||(await wt(j,we.markdown),q=we.markdown)}let oe=$r(q,P);return await H(_,q,M,oe),N(se,oe)})(p,g)}async function ae(p,g){let E=await e.check(p);if(E.error)return K(g,...E.error);let{uploads:C,parent:_="",from:j,language:N}=E.body??{},A={said:typeof j=="string"&&j.includes("{0}")&&j.length<=60?j:"\u5BFC\u5165\u81EA {0}",lang:N==="en"?"en":null};if(!Array.isArray(C)||C.length===0||C.length>1e3||!C.every(P=>typeof P=="string"&&Er.test(P)))return K(g,...l(400,"body"));let I=C.map(P=>m.get(P)).filter(Boolean);if(I.length!==C.length)return K(g,...l(410,"gone","\u4E0A\u4F20\u7684\u6587\u4EF6\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u5BFC\u5165"));for(let P of C)m.delete(P);let Z=typeof _=="string"&&Nn.test(_)&&await h(he.join(a,_))?_:"",X=await Q.promises.mkdtemp(he.join(gt.tmpdir(),"gallery-import-")),V=()=>Promise.all([Q.promises.rm(X,{recursive:!0,force:!0}),...I.map(({file:P})=>Q.promises.rm(P,{force:!0}))]).catch(()=>{}),q;try{q=await ve("import",{uploads:I.map(({file:P,name:M})=>({file:P,name:M})),scratch:X})}catch(P){return await V(),K(g,...l(500,"convert",P))}return e.respond(async()=>{try{let{made:P,top:M}=await yn(q.pages,{create:t.create,slugOf:()=>yr(a),folderOf:w,fill:se=>ve("fill",se),place:n.place,under:Z,...A});return[200,{ok:!0,pages:P.length,reports:M,skipped:q.skipped,missing:ne(q.pages)}]}finally{await V()}})(p,g)}let ne=p=>[...new Set(p.flatMap(function g(E){return[...(E.notes??[]).filter(C=>C.kind==="picture-missing").map(C=>C.name),...E.children.flatMap(g)]}))],U={export:S,markdown:x,upload:F,import:ae,preferences:L};function G(p,g,E){return Object.hasOwn(U,E)?U[E](p,g).catch(C=>{g.headersSent||K(g,...l(500,"transfer",C))}):K(g,404,{ok:!1,reason:"unknown"})}async function ce(){let p=f;f=null,m.clear();let g=await p?.catch(()=>null);g&&(kt.delete(g),await Q.promises.rm(g,{recursive:!0,force:!0}).catch(()=>{}))}return{handle:G,close:ce}}import{FACT_KINDS as Na,QUERY_ROUTE as Ma,WORKSPACE_GLOBAL as Wa}from"../browser/shared/workspace-query.mjs";function Bn({settled:e,tell:n,delay:t=120,recheck:a=1e3}){let s=new Map,f=(r,m=t)=>{clearTimeout(s.get(r));let l=setTimeout(async()=>{let h=await e(r).catch(()=>({source:null,held:!1,wait:0}));if(s.get(r)===l){if(h.held)return f(r,Math.min(Math.max(h.wait,50),a));if(h.wait>0)return f(r,h.wait);await n(r,h)}},m);s.set(r,l)};return f}import Or from"node:fs/promises";import{packageScript as Cr}from"../browser/shared/export-wrap.mjs";import{serveFound as jr}from"../browser/shared/http.mjs";import{extensionOf as _r,mediaTypeOf as Pr}from"../browser/shared/media.mjs";var Tr="/__gallery/components/",Rr=/^\/__gallery\/components\/([a-z0-9][a-z0-9-]*\/[a-z0-9][a-z0-9-]*)\/(.+)$/,Fr={js:"text/javascript; charset=utf-8",mjs:"text/javascript; charset=utf-8",css:"text/css; charset=utf-8",wasm:"application/wasm"};async function zn(e,n,t,{root:a}){if(!e.startsWith(Tr))return!1;let[,s,f]=Rr.exec(e)??[],r=s?re(a).packages.get(s):null,m=r?.files.includes(f)?Rt(r,f):null,l=m?await Or.readFile(m).catch(()=>null):null,h=l&&f==="kit.js"?Buffer.from(Cr(l.toString("utf8").replace(/^\uFEFF/,""))):l,w=h&&n===r.stamp&&n===Ft(r);return jr(t,h,{type:h?Fr[_r(f)]??Pr(f):void 0,headers:{"X-Content-Type-Options":"nosniff","Cache-Control":w?"max-age=31536000, immutable":"no-store"}}),!0}import{BLOCK_ICON as Ar}from"../browser/editor/components/icons.mjs";import{LISTED_BLOCKS as Hn}from"../browser/editor/components/registry.mjs";import{PACKAGE_ID as Dr}from"../browser/shared/components/installed.mjs";import{netHostsOf as Gn}from"../browser/shared/net-policy.mjs";import{inLanguage as Kn,refusal as Qe,said as be}from"../browser/shared/i18n/index.mjs";function Jn({root:e,taken:n}){let t=()=>{let r=re(e);return{packages:At(r).map(m=>{let l=Nt(m.id)?It(m.id):null;return{...m,newer:l?Mt(e,l):null,...l?{addAs:l.pack===Dt?l.name:l.id}:{}}}),packs:dt(e,{settings:r.settings}),packageIcon:Ar,blocks:Hn.map(({id:m,name:l,icon:h,hideable:w})=>({id:m,name:{zh:Kn("zh",l),en:Kn("en",l)},icon:h,hidden:w&&r.settings.hidden.includes(m),hideable:w})),problem:Tt(r)}},a=({id:r,hidden:m,shown:l,disabled:h,unlisted:w,net:i})=>{if(![m,l,h,w,i].every(R=>R===void 0||typeof R=="boolean"))return be("\u5F00\u5173\u7684\u503C\u4E0D\u5BF9");let k=Hn.find(R=>R.id===r);return k?h!==void 0||l!==void 0||w!==void 0||i!==void 0?be("\u5185\u7F6E\u5757\u53EA\u80FD\u9690\u85CF\uFF0C\u4E0D\u80FD\u505C\u7528"):m&&!k.hideable?be("\u8FD9\u4E2A\u5757\u4E0D\u80FD\u9690\u85CF"):null:typeof r=="string"&&Dr.test(r)?i&&Gn(re(e).packages.get(r)?.needs).length===0?be("\u8FD9\u4E2A\u5757\u4E0D\u8054\u7F51"):null:be("\u6CA1\u6709\u8FD9\u4E2A\u7EC4\u4EF6")};return{read:t,write:async r=>{if(r?.pack!==void 0){let{pack:i,enabled:k}=r;if(typeof k!="boolean")throw Qe(be("\u5F00\u5173\u7684\u503C\u4E0D\u5BF9"));if(typeof i!="string"||!dt(e,{settings:re(e).settings}).some(({id:R})=>R===i))throw Qe(be("\u6CA1\u6709\u8FD9\u4E2A\u5757\u5305"));return await ct(e,{pack:i,enabled:k}),n(),t()}let m=a(r);if(m)throw Qe(m);let{net:l,...h}=r,w=l===void 0?void 0:l?Gn(re(e).packages.get(r.id)?.needs):[];return await ct(e,{...h,...w?{net:w}:{}}),n(),t()},install:({path:r,zip:m}={})=>{let l=typeof m=="string"?Sn(Buffer.from(m,"base64")):typeof r=="string"&&r.trim()?$n(r):null;if(!l)throw Qe(be("\u7C98\u8D34\u5757\u5305\u7684\u6587\u4EF6\u5939\u6216 zip \u7684\u8DEF\u5F84"),{code:"path"});let h=Bt(e,l);return n(),{...t(),installed:h}}}}import Lr from"node:path";import{exportsDirectory as Ir}from"../browser/shared/paths.mjs";async function Yn(e,n,{workspace:t=null}={}){let a=Lr.join(Ir,`${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:a};if(f.repeated.length)return{problems:He(f.repeated),file:a};let{exported:r,failures:m}=await dn([n],{workspace:t});return await s.keep(r.map(l=>l.slug)),{problems:m.get(n)??[],file:a}}import Xn from"node:fs/promises";import Vn from"node:path";import{MEDIA_ROUTES as Zn,assetFile as Nr,extensionOf as Mr,imageFile as Wr,mediaTypeOf as Ur}from"../browser/shared/media.mjs";import{serveFound as Qn}from"../browser/shared/http.mjs";import{slugPattern as qn}from"../browser/shared/reports.mjs";import{pageFiles as Br}from"../browser/shared/pages.mjs";import{documentDirectory as zr}from"../browser/shared/workspace.mjs";var vt={asset:e=>({"Content-Type":Ur(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"}},Hr=new RegExp(`^/__gallery/edit/(${Object.keys(Zn).join("|")})/([^/]+)/(assets/[^/]+)$`);async function eo(e,n,{reportsDirectory:t}){let[,a,s,f]=Hr.exec(e)??[];if(!a)return!1;let r=qn.test(s)&&Zn[a](f)?await Xn.readFile(Vn.join(zr(s,t),f)).catch(()=>null):null;return Qn(n,r,{headers:vt[a](f)}),!0}var Gr={css:"text/css; charset=utf-8",js:"text/javascript; charset=utf-8",mjs:"text/javascript; charset=utf-8"},Kr=/^\/pages\/([^/]+)\/(assets\/[^/]+)$/;async function to(e,n,{reportsDirectory:t}){let[,a,s]=Kr.exec(e)??[];if(!a)return!1;let f=qn.test(a)&&Nr(s)?await Xn.readFile(Vn.join(Br(a,t).folder,s)).catch(()=>null):null,r=Gr[Mr(s??"")];return Qn(n,f,{headers:r?{"Content-Type":r,"X-Content-Type-Options":"nosniff","Cache-Control":"no-cache"}:(Wr(s)?vt.asset:vt.file)(s)}),!0}import Jr from"node:dns";import{sendJson as Fe}from"../browser/shared/http.mjs";import{createNetCache as Yr,dataOf as Xr}from"../browser/shared/net-cache.mjs";import{readKeys as Vr}from"../browser/shared/net-keys.mjs";import{addressKind as et,addressOf as lo,hostIn as no,keptHere as oo,keyIn as ro,mapsHere as Zr,netHostsOf as Qr,proxyHere as qr,withKey as ea}from"../browser/shared/net-policy.mjs";import{galleryVersion as ta}from"../browser/shared/preview-server.mjs";var qe=512*1024,na=6e4,ao=20,so=5,io=1e4,oa=16*1024,ra=new Set([301,302,303,307,308]),aa=/^(?:application\/(?:[\w.-]+\+)?json|text\/[\w.+-]+)$/i,xe=(e,n={})=>({ok:!1,code:e,...n}),te=(e,n={},t)=>Object.assign(new Error(e),{refusal:xe(e,n),...t===void 0?{}:{detail:t}});function sa(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 a=lo(t.href);return a.code?{code:"url",why:`a redirect to ${t.host?`${t.protocol}//${t.host}`:t.protocol}: ${a.why}`}:a}function co(e,n){let t=[...new Set([n,encodeURIComponent(n)])].filter(Boolean),a=s=>typeof s=="string"?t.reduce((f,r)=>f.split(r).join("{key}"),s):s;return Object.fromEntries(Object.entries(e).map(([s,f])=>[s,a(f)]))}var ia=e=>Jr.promises.lookup(e,{all:!0,verbatim:!0}),xt=e=>URL.parse(e)?.host||"?",$t=e=>et(e)==="fake-ip"?"an address a fake-ip proxy's DNS gives":"an address of this computer or of a private network";async function ca(e,{resolve:n,proxy:t}){let a=e.hostname,s=qr(t),f=u=>{let F=et(u);return F==="public"||F==="fake-ip"&&s},r=a.replace(/^\[|\]$/g,"");if(et(r)!=="none"){if(f(r))return{address:r};throw te("private",{host:a,address:r,why:`${r} is ${$t(r)}`})}let m;try{m=(await n(a)).map(u=>typeof u=="string"?u:u.address)}catch(u){throw te("offline",{why:`${a} did not resolve (${u.code??u.message})`})}if(m.length===0)throw te("offline",{why:`${a} did not resolve`});let l=m.filter(u=>!f(u));if(l.length===0)return{address:m[0]};let h=l.filter(u=>!Zr(u)),w=h.length?h:l,i=w.find(u=>!u.includes(":"))??w[0],k=`${a} resolved to ${i}, ${$t(i)}`,R=oo(a)?"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)":h.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(R===null)return{address:null,resolved:i,said:k};throw te("private",{host:a,address:i,why:`${k}, ${R}`},s||!t||oo(a)?void 0:`${k}, and the proxy it goes through (${xt(t)}) is not on this computer`)}var la=({resolve:e=ia,proxyFor:n=fn,connect:t,ca:a}={})=>async(s,{headers:f,signal:r})=>{let m=await n(s.href),l=await ca(s,{resolve:e,proxy:m}),{address:h}=l,w={...t?{connect:t}:{},...a?{ca:a}:{}};try{return await Ke(s,{address:h,proxy:m,headers:f,signal:r,...w})}catch(i){if(!(m&&i.proxyFailed&&(h!==null||i.code==="ECONNREFUSED")))throw h===null&&!r?.aborted?te("offline",{why:`${l.said}, and no site the proxy of this computer reached by its name proved to be it`},`${l.said}, handed by its name to the proxy (${xt(m)}): ${i.code??i.message}`):i;let k=u=>`and the proxy of this computer that would reach it${u?` (${xt(m)})`:""} is not running`,R=h===null?l.said:`${s.hostname.replace(/^\[|\]$/g,"")===h?h:`${s.hostname} resolved to ${h}`}, ${$t(h)}`;if(h===null||et(h)!=="public")throw te("private",{host:s.hostname,address:h??l.resolved,why:`${R}, ${k(!1)}`},`${R}, ${k(!0)}`);return Ke(s,{address:h,proxy:null,headers:f,signal:r,...w})}},fo=e=>(n,{headers:t,signal:a})=>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:a});async function da(e){let n=0,t=[];for await(let a of e){if(n+=a.length,n>oa)throw Object.assign(new Error("too-large"),{status:413});t.push(a)}return JSON.parse(Buffer.concat(t).toString("utf8"))}function fa(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 mo({root:e,catalog:n=()=>re(e),hop:t=null,now:a=Date.now,cache:s=Yr(e),log:f=()=>{}}){let r=t??la(),m=new Map,l=u=>{let F=a(),S=(m.get(u)??[]).filter(x=>F-x<6e4);return S.length>=ao?(m.set(u,S),!1):(m.set(u,[...S,F]),!0)},h={accept:"application/json, text/plain;q=0.9, text/*;q=0.8","user-agent":`Gallery/${ta} (a custom block's card)`};async function w(u,{hosts:F,allowed:S,key:x}){let Y=AbortSignal.timeout(io),W=u;for(let v=0;;v++){let b;try{b=await r(x===void 0?W:new URL(ea(W.href,x)),{headers:h,signal:Y})}catch(L){throw L.refusal?L:te("offline",{why:Y.aborted?`no answer within ${io/1e3} s`:String(L.code??L.message)})}if(ra.has(b.status)&&b.headers.get("location")){if(b.body?.cancel().catch(()=>{}),v>=so)throw te("status",{status:b.status,why:`more than ${so} redirects`});let L=sa(b.headers.get("location"),W);if(L.code)throw te("url",{why:L.why});let ae=no(L.url.hostname,F);if(!ae)throw te("host",{host:L.url.hostname,why:`a redirect to ${L.url.hostname}, which the block's needs do not name`});if(!S.includes(ae))throw te("consent",{hosts:F.filter(ne=>!S.includes(ne))});W=L.url,x=ro(W.href)?x:void 0;continue}if(b.status<200||b.status>299)throw b.body?.cancel().catch(()=>{}),te("status",{status:b.status});let B=b.headers.get("content-type")??"",H=B.split(";")[0].trim();if(H&&!aa.test(H))throw b.body?.cancel().catch(()=>{}),te("type",{type:H});if(Number(b.headers.get("content-length"))>qe)throw b.body?.cancel().catch(()=>{}),te("too-large",{limit:qe});let z;try{z=b.body?await mn(b,qe):Buffer.alloc(0)}catch(L){throw te("offline",{why:String(L.code??L.message)})}if(z===null)throw te("too-large",{limit:qe});return{type:H||"text/plain",text:fa(z,B)}}}let i=(u,F,S)=>{let x=Xr(u,F);return x===void 0?xe("type",{why:"the answer is no JSON"}):{ok:!0,data:x,at:u.at,cached:S}};async function k(u){let{block:F,url:S,as:x="json",doc:Y=null}=u??{},W=typeof F=="string"?n().packages.get(F):null;if(!W)return xe("missing",{why:"no custom block of that id loads in this workspace"});let v=Qr(W.needs);if(x!=="json"&&x!=="text")return xe("url",{why:'as is "json" or "text"'});let b=lo(S);if(b.code)return xe("url",{why:b.why});let{url:B}=b,H=no(B.hostname,v);if(!H)return xe("host",{host:B.hostname,why:v.length?`its needs name ${v.join(", ")}`:"its needs name no host of the net"});let z=n().settings.net?.[F]??[];if(!z.includes(H))return xe("consent",{hosts:v.filter(U=>!z.includes(U))});let L;if(ro(B.href)){let U=Vr(e);if(L=U[B.hostname]??U[H],L===void 0)return xe("key",{host:B.hostname})}let ae=B.href,ne=s.get(ae);if(s.used(ae,Y,x),ne&&a()-Date.parse(ne.at)<na)return i(ne,x,!0);if(!l(F))return ne?i(ne,x,!0):xe("rate",{why:`more than ${ao} fetches in a minute`});try{let{type:U,text:G}=await w(B,{hosts:v,allowed:z,key:L});return i(s.put(ae,{type:U,text:G,at:new Date(a()).toISOString()}),x,!1)}catch(U){if(!U.refusal)throw U;if(ne&&U.refusal.code!=="consent")return i(ne,x,!0);let G=L===void 0?U.refusal:co(U.refusal,L),ce=U.detail===void 0?G.why:L===void 0?U.detail:co({why:U.detail},L).why;return(G.code!=="offline"||U.detail!==void 0)&&f(`${F}: ${B.hostname} refused (${G.code}${ce?`: ${ce}`:""})`),G}}async function R(u,F){if(u.method!=="POST")return Fe(F,405,{ok:!1,reason:"method"});if(u.headers.origin!==`http://${u.headers.host}`)return Fe(F,403,{ok:!1,reason:"origin"});if(!/^application\/json\b/i.test(u.headers["content-type"]??""))return Fe(F,415,{ok:!1,reason:"type"});let S;try{S=await da(u)}catch(x){return Fe(F,x.status??400,{ok:!1,reason:"body"})}try{return Fe(F,200,await k(S))}catch(x){return Fe(F,500,{ok:!1,code:"offline",why:x.message})}}return{handle:R,answer:k,cache:s}}function uo({max:e=20}={}){let n=new Map;return{get(t,a,s){let f=`${t} ${a}`,r=n.get(f);return!r||r.text!==s?null:(n.delete(f),n.set(f,r),r.page)},set(t,a,s,f){let r=`${t} ${a}`;for(n.delete(r),n.set(r,{slug:t,text:s,page:f});n.size>e;)n.delete(n.keys().next().value)},clear(){n.clear()},forget(t){for(let[a,s]of n)s.slug===t&&n.delete(a)},get size(){return n.size}}}import{createHash as ma}from"node:crypto";import{readFileSync as ua}from"node:fs";import po from"node:fs/promises";import pa from"node:path";import{release as ha,releaseFile as ga}from"../browser/shared/paths.mjs";async function tt(e){let n=await Promise.all(e.map(a=>po.stat(a).then(({mtimeMs:s,size:f})=>`${s} ${f}`,()=>"none"))),t=ma("sha256");return e.forEach((a,s)=>t.update(`${a}\0${n[s]}
|
|
78
|
+
`)),t.digest("hex").slice(0,16)}function ho(e,n){let t=null,a=async()=>(await Promise.all(e.map(async s=>(await po.readdir(s,{recursive:!0,withFileTypes:!0}).catch(()=>[])).filter(r=>r.isFile()).map(r=>pa.join(r.parentPath,r.name))))).flat().filter(n).sort();return{files:()=>t??=a(),changed:()=>{t=null}}}var St=ha?JSON.parse(ua(ga,"utf8")).stamps:null;var at=To.source.slice(1,-1),Ua=new RegExp(`^/generated/(${at})\\.html$`),Ba=new RegExp(`^/(${at})/(?:doc|report)\\.html$`),za=new RegExp(`^/pages/(${at})$`),Ha=new RegExp(`^/__gallery/pages/(${at})/(cards|library|hint)$`),Ct="/__gallery/events",je=wa,Fo=/^\/__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)$/,Ga=/^\/__gallery\/edit\/(?:v\/[a-f0-9]{16}\/)?src\/(shared\/emoji\/data\/[a-z]+(?:-[a-z]+)*\.(json|bin))$/,nt=[J.join(je,"editor","page"),J.join(je,"editor","components"),J.join(je,"shared")],Ka=e=>Fo.test(`/__gallery/edit/src/${J.relative(je,e).split(J.sep).join("/")}`);var Ja=[Po,J.join(je,"shared","components")],Zc=[Po,...nt],Ne={"Cache-Control":"no-store"},jo={"Cache-Control":"max-age=31536000, immutable"},Et=(e,n,t)=>Ot(e,{type:n,headers:{...Ne,...va},body:t});function Ya(e){let n=e.headers?.host??"",t=e.socket?.localPort;return!!t&&(n===`127.0.0.1:${t}`||n===`localhost:${t}`)}function Xa(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 Ao=`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
|
+
});`,Do=`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(Na)}) window.dispatchEvent(new CustomEvent("doc-workspace-change", { detail: kind }));
|
|
87
|
+
};`,Va=(e,n,t)=>`<script>
|
|
88
|
+
(() => {
|
|
89
|
+
document.currentScript.remove();
|
|
90
|
+
${Ao}
|
|
91
|
+
const solo = new URLSearchParams(location.search).has("solo");
|
|
92
|
+
let catalog = "${t}";
|
|
93
|
+
const holds = (ids) => document.querySelector(ids === undefined ? "[${ot}]" : ids.split(",").map((id) => '[${ot}="' + id + '"]').join());
|
|
94
|
+
const events = new EventSource("${Ct}?slug=${e}");
|
|
95
|
+
${Do}
|
|
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>`,Za=(e,n,t)=>`<script>
|
|
120
|
+
(() => {
|
|
121
|
+
document.currentScript.remove();
|
|
122
|
+
${Ao}
|
|
123
|
+
let catalog = "${t}";
|
|
124
|
+
const holds = (ids) => {
|
|
125
|
+
const named = ids === undefined ? "[${ot}]" : ids.split(",").filter(Boolean).map((id) => '[${ot}="' + 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("${Ct}?page=${e}");
|
|
130
|
+
${Do}
|
|
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 Qa(e,n){let t=J.relative(e,n).split(J.sep);if(t[0]===".."||J.isAbsolute(t[0])||t[0]==="")return null;if(t.length===1&&t[0]===rt)return{slug:null,name:rt,packages:!0};let a=l=>process.platform==="win32"?l.toLowerCase():l;if(a(t[0])===Oa&&t.length>=2&&Ia(t[1])&&!xo.includes(t[1])){let l=t.slice(2);return l.some(h=>h.startsWith("."))?null:{extension:t[1],name:l.length===1?l[0]:null}}if(a(t[0])===Ca&&t.length>=2&&Ro(t[1])&&!xo.includes(t[1])){let l=t.slice(2);return l.some(h=>h.startsWith("."))?null:{page:t[1],name:l.length===1?l[0]:null}}let s=t[0]===".gallery"&&t[1]==="pages"&&t.length>=3,[f,...r]=s?t.slice(2):t,m=!s&&a(f)===vo;return!(m||To.test(f))||f==="exports"||r.some(l=>l.startsWith("."))?null:{slug:m?vo:f,name:r.length===1?r[0]:null,...m?{packages:m}:{}}}function jt(e){let n=i=>process.platform==="win32"?J.resolve(i).toLowerCase():J.resolve(i),{gallery:t,preferencesPage:a,exports:s,extensions:f}=Pa(e),[r,m,l,h]=[n(t),n(a),n(s),n(f)],w=(i,k)=>i===k||i.startsWith(k+J.sep);return i=>{let k=n(i);return w(k,h)&&k!==h&&k.slice(h.length+1).split(J.sep).some((R,u)=>u>0&&(R==="node_modules"||R===".git"))?!0:w(k,r)&&k!==r&&!w(k,m)||w(k,l)}}var _o=`<script data-doc-dev>document.currentScript.remove(); globalThis.${Wa} = ${JSON.stringify(Ma)};</script>`,ue=(e,n,t)=>new RegExp(`</${n}>`,"i").test(e)?e.replace(new RegExp(`</${n}>`,"i"),()=>` ${t}
|
|
145
|
+
</${n}>`):`${e}
|
|
146
|
+
${t}`;function Lo({stateDirectory:e=ya,logger:n=console,kind:t="dev",workbenchPage:a=null,closeServer:s=async()=>{},exit:f=()=>process.exit(0)}={}){let r=new Set,m=(o,c="",d="report")=>{for(let O of r)(!o||O.slug===o)&&O.response.write(`data: ${o?`${d} ${c}`:"assets"}
|
|
147
|
+
|
|
148
|
+
`)},l=(o,c)=>{for(let d of r)d.page===o&&d.response.write(`data: page ${c}
|
|
149
|
+
|
|
150
|
+
`)},h=!1,w=o=>{h||=o,A("workspace",()=>{let c=h;h=!1;for(let d of r)d.workspace&&(c||!d.ownOnly)&&d.response.write(`data: workspace ${Date.now()}
|
|
151
|
+
|
|
152
|
+
`)})},i=()=>w(!0),k=()=>w(!1),R=o=>m(o,String(Date.now()),"changes"),u=gn({stateDirectory:e,finish:ze,log:o=>n.info?.(`[gallery] ${o}`),onChanges:R}),F=(o,c,d,{lang:O=null,page:T=!1}={})=>Yt(o,c,d,{blank:!0,lang:O,page:T}),S=e?jn({file:J.join(e,"activity.json")}):null,x=vn({root:D,read:kn(u),activity:S,draw:(o,c)=>Oe(o,{slug:c,mode:"words",reportsDirectory:D})}),Y=new Set,W=o=>{for(let c of o)Y.add(c);Y.size!==0&&A("data",()=>{let c=[...Y];Y.clear();for(let d of r)if(d.slug||d.page)for(let O of c)d.response.write(`data: data ${O}
|
|
153
|
+
|
|
154
|
+
`)})},v=o=>J.resolve(J.dirname(bt(o,D)))===J.resolve(D),b=null,B=null,H=()=>B??=(async()=>{for(let o of r)o.response.end();r.clear(),await Promise.race([s().catch(()=>{}),new Promise(o=>setTimeout(o,3e3))]),await S?.close(),await b?.().catch(()=>{}),await L.close(),z.close(),f()})(),z=xn({server:{kind:t,version:$a,stop:H},edits:u,reports:{create:F,export:o=>Yn(u,o,{workspace:c=>x.snapshot(c)}),words:(o,c)=>Oe(o,{slug:c,mode:"words",reportsDirectory:D})},components:Jn({root:D,taken:()=>V.taken()}),changed:i,relayed:k,index:x,web:{frameable:un,title:pn,icon:o=>hn(o)}}),L=Un({edits:u,workspace:z,reports:{create:F},reportsDirectory:D,offline:o=>ln({...o,workspace:c=>x.snapshot(c)})}),ae=mo({root:D,hop:process.env.GALLERY_TEST_NET?fo(Number(process.env.GALLERY_TEST_NET)):null,log:o=>n.info?.(`[gallery] ${o}`)}),ne=Gt({root:D,edits:u,stateDirectory:e,catalogTaken:()=>V.taken(),log:o=>n.info?.(`[gallery] ${o}`),shown:pt}),U=(o,c,{present:d=!1,editorModule:O,kit:T}={})=>{let y=c,ie="",ee="",fe=!0;try{d||({html:y,snippet:ie,head:ee}=u.preview(o,c,{editor:O,kitTags:le=>tn(le,T)}))}catch(le){fe=!1,n.warn(`[gallery] text editing unavailable for ${o}: ${le.message}`)}if({html:y}=rn(y,{slug:o,mode:"preview",kit:T}),y=ue(y,"head",Va(o,Ie(c),re(D).stamp)),y=ue(y,"head",`<script data-doc-dev>${wo()}</script>`),y=ue(y,"head",_o),ee&&(y=ue(y,"head",ee)),d)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=Tn(o,c)}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}},G=uo(),ce=ho(nt,Ka),p=o=>{let c=bt(o,D);return[c,J.join(c,"assets")]},g=()=>St?.editor??ce.files().then(tt),E=o=>St?.kit?.[o.id]??tt([ut(o)]),C=async(o,c,{present:d})=>{let[O,T,y]=await Promise.all([d?"":g(),Promise.all(Re.map(E)),tt(p(o))]),ie=[d?"present":O,...T,y,re(D).stamp,`look:${yo(ko(o,D))}`].join(" "),ee=G.get(o,ie,c);if(ee!==null)return d||u.opened(c),ee;let fe=new Map(Re.map((pe,Ee)=>[pe,T[Ee]])),ke=d?void 0:`/__gallery/edit/v/${O}/src/editor/page/editor.mjs`,{html:le,whole:de}=U(o,c,{present:d,editorModule:ke,kit:pe=>`${Be(pe)}?v=${fe.get(pe)}`});return de&&G.set(o,ie,c,le),le},_=async o=>{let c=bo(o,D),[d,O]=await Promise.all([ge.readFile(c.html,"utf8").catch(()=>null),ge.readFile(c.json,"utf8").catch(()=>"")]);if(d===null)return null;let[T,y]=await Promise.all([g(),Promise.all(Re.map(E))]),ie=new Map(Re.map(($,Se)=>[$,y[Se]])),ee=re(D),fe=Eo(d,O),ke=Ht(d,{blockOf:$=>mt(ee,$)}),le=Object.fromEntries([...new Set(ft(d).cards.map(({block:$})=>$).filter(Boolean))].map($=>[$,mt(ee,$)])),{html:de}=Pn(ke,{reportsDirectory:D,slug:o,kit:$=>`${Be($)}?v=${ie.get($)}`}),pe=Da(o,D),Ee=Aa(o,D),Te=pe?.defaultCards===!0,We=Ra(d),Ue=$=>ee.packages.get($)?.name??Lt().find(Se=>Se.id===$)?.title??null,$e=Te?Ta(D,ft(d).cards.map(({block:$})=>$)).map($=>({block:$,name:Ue($)})):[],Le=JSON.stringify({slug:o,title:pe?.title??o,token:u.token,version:fe,blocks:le,...Ee?{hint:Ee}:{},...Te?{defaults:Te}:{},...$e.length?{news:$e}:{},...We?{blank:We}:{}}).replace(/</g,"\\u003c");return de=ue(de,"head",`<script type="application/json" data-ge-page data-doc-dev>${Le}</script>`),de=ue(de,"head",Za(o,fe,ee.stamp)),de=ue(de,"head",`<script data-doc-dev>${wo()}</script>`),de=ue(de,"head",_o),ue(de,"head",`<script type="module" src="/__gallery/edit/v/${T}/src/editor/page/custom-page.mjs" data-doc-dev></script>`)};async function j(o,c,d){try{if(!Ya(o))return go(c,403,{ok:!1,reason:"host"});let O=Xa(o);if(O)return Ot(c,{status:302,headers:{Location:O,...Ne}});let T=new URL(o.url||"/","http://localhost"),y=decodeURI(T.pathname);if(y===Ct){c.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-store",Connection:"keep-alive"}),c.write(`retry: 3000
|
|
156
|
+
|
|
157
|
+
`);let $={slug:T.searchParams.get("slug"),page:T.searchParams.get("page"),workspace:T.searchParams.has("workspace"),ownOnly:T.searchParams.get("workspace")==="own",response:c};r.add($);let{stamp:Se,settings:zo}=re(D);c.write(`data: components ${Se}
|
|
158
|
+
|
|
159
|
+
`),c.write(`data: ${lt(zo)}
|
|
160
|
+
|
|
161
|
+
`),o.on("close",()=>r.delete($));return}if(y==="/__gallery/net")return ae.handle(o,c);if(y==="/__gallery/edit/commit")return u.commit(o,c);if(y==="/__gallery/edit/reverted")return u.reverted(o,c);if(y==="/__gallery/edit/hand-in")return u.handInRequest(o,c);if(y==="/__gallery/edit/settle")return u.settleRequest(o,c);if(y==="/__gallery/edit/round")return u.roundRequest(o,c);if(y==="/__gallery/edit/upload")return u.upload(o,c);if(y==="/__gallery/edit/unfurl")return u.unfurl(o,c);if(y==="/__gallery/edit/emoji-library"){if(o.method==="POST")return u.addEmoji(o,c);let[$,Se]=await u.listEmojis();return go(c,$,Se)}if(y==="/__gallery/edit/icon"){let $=Vt({value:T.searchParams.get("value")??"",slug:T.searchParams.get("slug"),tab:T.searchParams.has("tab")});return Ae(c,$?.body,{type:$?.type,headers:{"Cache-Control":"max-age=31536000, immutable"}})}if(await eo(y,c,{reportsDirectory:D})||await to(y,c,{reportsDirectory:D})||await zn(y,T.searchParams.get("v"),c,{root:D}))return;let ie=y.match(/^\/__gallery\/edit\/emoji-library\/([^/]+)$/)?.[1];if(ie){let $=await u.readEmoji(ie);return Ae(c,$?.body,{type:$?.type,headers:{"Cache-Control":"no-cache"}})}if(y==="/__gallery/edit/frameable")return u.frameable(o,c);if(y==="/__gallery/edit/annotations")return u.annotations(o,c);if(y==="/__gallery/edit/changes")return u.changes(o,c);let ee=y.match(/^\/__gallery\/transfer\/([a-z]+)$/)?.[1];if(ee)return L.handle(o,c,ee);let[,fe,ke]=y.match(Ha)??[];if(fe)return ne.handle(o,c,fe,ke);let le=y.match(/^\/__gallery\/workspace\/([a-z]+(?:-[a-z]+)*)$/)?.[1];if(le)return z.handle(o,c,le);let[,de,pe]=y.match(Fo)??[];if(pe){let $=await ge.readFile(J.join(je,pe),"utf8").catch(()=>null);return Ae(c,$,{type:"text/javascript; charset=utf-8",headers:de?jo:Ne})}let Ee=T.searchParams.has("v")&&Re.find($=>Be($)===y);if(Ee){let $=await ge.readFile(ut(Ee)).catch(()=>null);return Ae(c,$,{type:y.endsWith(".css")?"text/css; charset=utf-8":"text/javascript; charset=utf-8",headers:jo})}if(y==="/__gallery/edit/mhchem.js"){let $=await ge.readFile(en).catch(()=>null);return Ae(c,$,{type:"text/javascript; charset=utf-8",headers:Ne})}let[,Te,We]=y.match(Ga)??[];if(Te){let $=await ge.readFile(J.join(je,Te)).catch(()=>null);return Ae(c,$,{type:We==="json"?"application/json; charset=utf-8":"application/octet-stream",headers:{"Cache-Control":"max-age=86400"}})}if(a&&(y==="/"||y==="/index.html"))return Et(c,"text/html; charset=utf-8",await a(T.pathname,o));let Ue=y.match(za)?.[1];if(Ue){let $=await _(Ue);return $===null?d():Et(c,"text/html; charset=utf-8",$)}let $e=y.match(Ua)?.[1];if(!$e){let $=y.match(Ba)?.[1];return Ro($)&&await ge.access(ja(bt($,D)).html).then(()=>!0,()=>!1)?Ot(c,{status:302,headers:{Location:`/generated/${$}.html${T.search}`,...Ne}}):d()}let Le=await u.readTaken($e);if(Le===null)return d();T.searchParams.has("present")||u.noteTaken($e,Le.source).then($=>$&&R($e),()=>{}),Et(c,"text/html; charset=utf-8",await C($e,Le.text,{present:T.searchParams.has("present")}))}catch(O){d(O)}}let N=new Map,A=(o,c)=>{clearTimeout(N.get(o)),N.set(o,setTimeout(c,120))},I=o=>{ba(o,D).reads&&m(o,yo(ko(o,D)),"look")},Z=Bn({settled:u.settled,async tell(o,c){let d=await u.read(o,c.source).catch(O=>(n.error(`[gallery] ${o}: ${O.message}`),{version:Ie(c.source??"")}));if(m(o,d?.version??Ie("")),v(o)){let O=u.writerOf(o,c.source)??"agent";x.changed(o,{source:c.source??null,text:d?.text??null,by:O}).then(W,T=>n.error(`[gallery] ${o}: its facts not read: ${T.message}`))}u.noteTaken(o,c.source).then(O=>O&&R(o),O=>n.error(`[gallery] ${o}: the Agent's changes not kept: ${O.message}`)),u.checkAnnotations(o).catch(O=>n.error(`[gallery] ${o}: annotations not checked: ${O.message}`))}}),X=({id:o,problem:c,off:d})=>d||n.warn(`[gallery] custom block ${o} does not load: ${Pt("en",c)}`),V=Cn({root:D,tell({stamp:o,problems:c,settings:d},O){for(let T of O)c.has(T)&&X(c.get(T));for(let{response:T}of r)T.write(`data: components ${o} ${O.filter(y=>Ea.test(y)).join(",")}
|
|
162
|
+
|
|
163
|
+
`),T.write(`data: ${lt(d)}
|
|
164
|
+
|
|
165
|
+
`)}});for(let o of re(D).problems.values())X(o);x.start().then(o=>o>0&&W(["activity"]));let q=jt(D),P=Co(D).then(o=>o.join("/"),()=>""),M=!1,se=o=>{M||=o===Oo,A("extensions",async()=>{let c=M;M=!1;let d=await P;P=Co(D).then(O=>O.join("/"),()=>d),(c||await P!==d)&&i()})},oe=(o,c)=>!ka&&c.some(d=>o.startsWith(d+J.sep));function we(o,c){if(o==="reset"){G.clear(),ce.changed(),V.changed(),i();return}if(q(c))return;let d=Qa(D,c);if(d?.page){let{page:O,name:T}=d;T&&Fa(T)&&A(`page:${O}`,async()=>{let y=bo(O,D),[ie,ee]=await Promise.all([ge.readFile(y.html,"utf8").catch(()=>null),ge.readFile(y.json,"utf8").catch(()=>"")]);ie!==null&&l(O,Eo(ie,ee))}),(T===So.json||T===So.html&&/^(add|unlink)$/.test(o)||T===null&&/^(add|unlink)Dir$/.test(o))&&i();return}if(d?.extension){(d.name===Oo||d.name===null)&&se(d.name);return}if(d?.packages&&V.changed(),d?.name===rt&&d.slug===null&&A("look:*",()=>new Set([...r].map(({slug:O})=>O).filter(Boolean)).forEach(I)),d?.name===rt&&d.slug===null&&i(),d?.slug&&!(d.name&&_a(d.name))&&G.forget(d.slug),d&&(/^(doc|report)\.json$/.test(d.name??"")||/^(add|unlink)Dir$/.test(o)&&d.name===null)&&G.clear(),d?.slug&&!d.packages&&d.name===null&&/^(add|unlink)Dir$/.test(o)&&v(d.slug)&&(x.forget(d.slug),W(["todos","recent","stats"])),d?.slug&&!(d.packages&&d.name===null)&&(/^(doc|report)\.json$/.test(d.name??"")||/^(add|unlink)Dir$/.test(o)&&d.name===null||/^(add|unlink)$/.test(o)&&$o(d.name??""))&&i(),d?.slug&&!d.packages&&d.name===La&&i(),/^(add|unlink)(Dir)?$/.test(o)&&oe(c,nt)&&ce.changed(),d?.name&&($o(d.name)||/^(doc|report)\.json$/.test(d.name))){if(Z(d.slug),/^(doc|report)\.json$/.test(d.name)){let{slug:O}=d;A(`look:${O}`,()=>I(O))}}else if(d?.name==="annotations.json"){let{slug:O}=d;A(`notes:${O}`,async()=>{let T=await ge.readFile(c,"utf8").catch(()=>null);m(O,T===null?"":Ie(T),"notes")})}else oe(c,Ja)?A("kit",async()=>{try{await cn({fresh:!0}),m()}catch(O){n.error(`[gallery] shared kit rebuild failed: ${O.message}`)}}):oe(c,nt)&&A("editor",()=>m())}async function ye(o){b=await xa({reportsDirectory:D,port:o,token:u.token,kind:t}),await Sa(D)}async function Bo(){for(let o of N.values())clearTimeout(o);V.close(),await S?.close(),await b?.().catch(()=>{}),b=null,await L.close(),z.close()}return{handle:j,changed:we,listening:ye,close:Bo,stop:H,edits:u,get listeners(){return r.size}}}import qa from"node:fs/promises";import De from"node:path";import{FRAMED_BY as es,serve as Io}from"../browser/shared/http.mjs";var ts={".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"},ns=e=>ts[De.extname(e).toLowerCase()]??"application/octet-stream";function os(e,n){if(/%(?:2f|5c|00)/i.test(n)||/[\\\0]/.test(n))return null;let t;try{t=decodeURIComponent(n)}catch{return null}let a=t.split("/");if(a.some(r=>r===""||r==="."||r===".."||/[\\\0:]/.test(r)))return null;let s=De.resolve(e,...a),f=De.relative(e,s);return f&&!f.startsWith("..")&&!De.isAbsolute(f)?s:null}async function No(e,n,{web:t,kit:a,vendor:s}){if(e.method!=="GET"&&e.method!=="HEAD")return!1;let f=new URL(e.url||"/","http://localhost").pathname,r=null,m=null;if(f==="/"||f==="/index.html"){if(!t)return!1;[r,m]=[De.join(t,"index.html"),{"Cache-Control":"no-store",...es}]}else{let w=[["/assets/",t&&De.join(t,"assets"),"max-age=31536000, immutable"],["/kit/",a,"no-cache"],["/vendor/",s,"no-cache"]].find(([i,k])=>k&&f.startsWith(i));if(!w)return!1;r=os(w[1],f.slice(w[0].length)),m={"Cache-Control":w[2]}}let l=r?await qa.readFile(r).catch(()=>null):null;return l?(Io(n,{type:ns(r),headers:{...m,"X-Content-Type-Options":"nosniff"},body:e.method==="HEAD"?void 0:l}),!0):(Io(n,{status:404}),!0)}import _e from"node:fs";import Me from"node:path";import{isExtensionId as rs}from"../browser/shared/outline-shape.mjs";import{DOCUMENT_FOLDERS as Mo,isSlugName as _t,layoutOf as as}from"../browser/shared/workspace.mjs";function ss(e){let{components:n,gallery:t,preferencesPage:a,customPages:s,extensions:f}=as(e),r=(i,k)=>{try{return _e.readdirSync(i,{withFileTypes:!0}).filter(R=>R.isDirectory()&&k(R.name)).map(R=>Me.join(i,R.name))}catch{return[]}},m=[...r(e,i=>_t(i)),...r(a,i=>_t(i))],l=i=>[i,...r(i,k=>!k.startsWith(".")).flatMap(l)],h=r(s,i=>_t(i)&&!Mo.includes(i)),w=r(f,i=>rs(i)&&!Mo.includes(i));return[...new Set([e,...[t,a,s,f].filter(i=>_e.existsSync(i)),...h,...w,...m,...m.map(i=>Me.join(i,"assets")).filter(i=>_e.existsSync(i)),..._e.existsSync(n)?l(n):[]])]}function Wo(e,n,{folders:t=process.platform==="linux"}={}){let a=jt(e),s=(w,i)=>{a(i)||Me.basename(i).startsWith(".")||_e.stat(i,(k,R)=>{if(k)return n(k.code==="ENOENT"?"unlink":"change",i);let u=R.isDirectory();n(w==="rename"?u?"addDir":"add":u?"addDir":"change",i)})},f=()=>{};if(!t)try{let w=_e.watch(e,{recursive:!0},(i,k)=>k?s(i,Me.join(e,k.toString())):n("reset",e));return w.on("error",f),{close:()=>w.close()}}catch(w){if(w.code!=="ERR_FEATURE_UNAVAILABLE_ON_PLATFORM")throw w}let r=new Map,m=null,l=()=>{let w=new Set(ss(e));for(let[i,k]of r)w.has(i)||(k.close(),r.delete(i));for(let i of w)if(!r.has(i))try{let k=_e.watch(i,(R,u)=>{if(!u)return n("reset",i);R==="rename"&&h(),s(R,Me.join(i,u.toString()))});k.on("error",f),r.set(i,k)}catch{}},h=()=>{m??=setTimeout(()=>{m=null,l()},50)};return l(),{close(){clearTimeout(m);for(let w of r.values())w.close();r.clear()},get folders(){return[...r.keys()]}}}async function xl({port:e,web:n=us,kind:t=process.env.GALLERY_SERVER_KIND==="dev"?"dev":"cli",stateDirectory:a=ls,exit:s=(l=0)=>process.exit(l),watch:f=!0,signals:r=!0,log:m=console}={}){await ps(Pe),await zt(Pe,{log:S=>m.log(`[gallery] ${new Date().toISOString()} ${S}`)}),Ut(Pe,S=>m.log(`[gallery] ${new Date().toISOString()} ${S}`)),Wt(Pe);let l=await Kt(Pe,{stateDirectory:a});l.did==="made"?m.log(`[gallery] ${new Date().toISOString()} the default home page made: ${l.file} (${l.cards.length} cards)`):l.did==="failed"&&m.warn(`[gallery] ${new Date().toISOString()} ${Jt(l)}`);let h=null,w=null,i=null,k=hs(Pe),R=async()=>{w?.close(),i&&st.unwatchFile(it,i),await is.writeFile(k.lastPortFile,`${e}
|
|
166
|
+
`).catch(()=>{}),await new Promise(S=>{h.close(()=>S()),h.closeAllConnections()})},F=Lo({stateDirectory:a,logger:{info:S=>m.log(S),warn:S=>m.warn(S),error:S=>m.error(S)},kind:t,closeServer:R,exit:()=>s(0)});if(h=cs.createServer((S,x)=>{F.handle(S,x,async Y=>{if(Y){m.error(`[gallery] ${S.method} ${S.url}: ${Y.stack??Y.message}`),x.headersSent?x.end():Uo(x,{status:500});return}try{if(await No(S,x,{web:n,kit:ds,vendor:ms}))return}catch(W){m.error(`[gallery] ${S.url}: ${W.message}`)}x.headersSent||Uo(x,{status:404})})}),h.keepAliveTimeout=5e3,await new Promise((S,x)=>{h.once("error",x),h.listen(e,"127.0.0.1",()=>{h.off("error",x),S()})}),e=h.address().port,await F.listening(e),f&&(w=Wo(Pe,F.changed)),fs){let S=st.readFileSync(it,"utf8");i=()=>{let x=null;try{x=st.readFileSync(it,"utf8")}catch{}x!==S&&(m.log("[gallery] The package was replaced (another version installed): this server stops; the next gallery command starts the new one."),F.stop())},st.watchFile(it,{interval:3e3,persistent:!1},i)}if(r)for(let S of["SIGINT","SIGTERM","SIGHUP"])process.once(S,()=>F.stop());return{server:h,port:e,routes:F,async close(){await R(),await F.close()}}}export{xl as a};
|