@heycys/gallery 0.1.2 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/THIRD-PARTY-NOTICES.md +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/icon/page.mjs +6 -4
- package/browser/editor/components/icons.mjs +5 -2
- 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/import/read.mjs +20 -2
- 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/document-copy.mjs +43 -0
- package/browser/shared/drafts.mjs +10 -3
- package/browser/shared/emoji/icon-value.mjs +2 -2
- package/browser/shared/emoji/line-icons.mjs +37 -0
- package/browser/shared/extensions.mjs +83 -7
- package/browser/shared/http.mjs +9 -0
- package/browser/shared/i18n/en.mjs +50 -17
- package/browser/shared/outline-shape.mjs +6 -0
- package/browser/shared/outline.mjs +165 -12
- 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/browser/shared/workspace-columns.mjs +11 -7
- package/dist/{chunk-N7AZZLGT.mjs → chunk-2GKGEVMR.mjs} +29 -24
- package/dist/chunk-2OHANJ6Q.mjs +2 -0
- package/dist/{chunk-HYMEEXKN.mjs → chunk-2RKIHJI2.mjs} +1 -1
- package/dist/{chunk-742D2WWJ.mjs → chunk-36FIRJIF.mjs} +2 -2
- package/dist/{chunk-BPL64HGA.mjs → chunk-3A5I2GJK.mjs} +1 -1
- package/dist/{chunk-RFDZXFJF.mjs → chunk-3OFXMN6N.mjs} +1 -1
- package/dist/chunk-46ACXOU5.mjs +2 -0
- package/dist/{chunk-PUOQ65NC.mjs → chunk-4AMTKWDO.mjs} +1 -1
- package/dist/{chunk-VTKNEYT3.mjs → chunk-4DNHHJSL.mjs} +1 -1
- package/dist/chunk-5DPABPBI.mjs +2 -0
- package/dist/chunk-5IIH335D.mjs +3 -0
- package/dist/chunk-5L26JUYA.mjs +2 -0
- package/dist/{chunk-3NJACR4W.mjs → chunk-5MEXZ2UF.mjs} +1 -1
- package/dist/{chunk-ZHEHPMBK.mjs → chunk-6MPKCH3P.mjs} +1 -1
- package/dist/{chunk-C564NU2H.mjs → chunk-74RPP2M2.mjs} +1 -1
- package/dist/chunk-7M2BQQGZ.mjs +2 -0
- package/dist/{chunk-VXACTLO3.mjs → chunk-7M7UPWU6.mjs} +1 -1
- package/dist/{chunk-ZB4H7ZN4.mjs → chunk-7N2LPG33.mjs} +1 -1
- package/dist/{chunk-UBBRTJ2R.mjs → chunk-7XDYK3UC.mjs} +1 -1
- package/dist/chunk-AEMVZYZQ.mjs +166 -0
- package/dist/{chunk-POQSE4C2.mjs → chunk-AFGUR7SY.mjs} +1 -1
- package/dist/{chunk-QKXMPUXC.mjs → chunk-AMDGVDNV.mjs} +1 -1
- package/dist/{chunk-KTKHRC6H.mjs → chunk-ASAXY2DJ.mjs} +1 -1
- package/dist/{chunk-NVRNLK25.mjs → chunk-BYSF5UMM.mjs} +2 -2
- package/dist/{chunk-U3SSPL4K.mjs → chunk-CCSGFCLZ.mjs} +1 -1
- package/dist/{chunk-NWFBE2YA.mjs → chunk-CG3UHDKH.mjs} +1 -1
- package/dist/chunk-CPS4SRPF.mjs +5 -0
- package/dist/{chunk-B4P2CM2J.mjs → chunk-CZ5KJSGK.mjs} +1 -1
- package/dist/chunk-DAMVDXR3.mjs +2 -0
- package/dist/{chunk-NG375ILQ.mjs → chunk-DH6GMDNN.mjs} +1 -1
- package/dist/chunk-DHB7UZ7F.mjs +3 -0
- package/dist/{chunk-MHW7ZKOU.mjs → chunk-DKR7LFIY.mjs} +1 -1
- package/dist/chunk-DLFZJJEE.mjs +2 -0
- package/dist/{chunk-6EZ7FNIK.mjs → chunk-F4ZA6JRZ.mjs} +1 -1
- package/dist/{chunk-6VTU6KEO.mjs → chunk-FCK6NXON.mjs} +1 -1
- package/dist/{chunk-ZWPMCK7P.mjs → chunk-FX42XU6J.mjs} +1 -1
- package/dist/chunk-FXQBADMN.mjs +5 -0
- package/dist/{chunk-W3BGBJQW.mjs → chunk-G4YP7GVC.mjs} +1 -1
- package/dist/{chunk-V6XZ4VIR.mjs → chunk-GWOYMENX.mjs} +1 -1
- package/dist/chunk-HATA2W7X.mjs +2 -0
- package/dist/{chunk-YI43RG4P.mjs → chunk-HBAUKKQH.mjs} +1 -1
- package/dist/{chunk-MAFIGVXY.mjs → chunk-HM4E43VM.mjs} +1 -1
- package/dist/{chunk-CRJEG7MT.mjs → chunk-JI6T3A4Y.mjs} +1 -1
- package/dist/{chunk-NFMCP2HI.mjs → chunk-JJNRIFND.mjs} +2 -2
- package/dist/chunk-JL6R4FG4.mjs +4 -0
- package/dist/{chunk-UMHUSOPJ.mjs → chunk-JXLSHVJ2.mjs} +1 -1
- package/dist/{chunk-FJYN7RTH.mjs → chunk-KFZBYDIS.mjs} +1 -1
- package/dist/{chunk-ZTHICSSF.mjs → chunk-KH24LWAT.mjs} +1 -1
- package/dist/{chunk-RKPWLGZ3.mjs → chunk-KUILYI7H.mjs} +1 -1
- package/dist/{chunk-RMECZA2K.mjs → chunk-L7W624FD.mjs} +1 -1
- package/dist/chunk-LE44MD3O.mjs +4 -0
- package/dist/{chunk-4K5KC6V2.mjs → chunk-LV24RY2E.mjs} +1 -1
- package/dist/{chunk-43B75J5T.mjs → chunk-MKTX5PGV.mjs} +1 -1
- package/dist/{chunk-LKX55H76.mjs → chunk-NAGMRVW4.mjs} +1 -1
- package/dist/{chunk-D4CKRD3V.mjs → chunk-NFABH3QW.mjs} +2 -2
- package/dist/{chunk-PVER7LSC.mjs → chunk-NIW7F7LU.mjs} +2 -2
- package/dist/{chunk-PAREWQGB.mjs → chunk-NWRZXELO.mjs} +1 -1
- package/dist/{chunk-OJKMINIU.mjs → chunk-OU3S466R.mjs} +15 -15
- package/dist/{chunk-5ZJA7CXT.mjs → chunk-PAFSFVYB.mjs} +1 -1
- package/dist/chunk-QCEATQC4.mjs +2 -0
- package/dist/{chunk-Y34NR5JL.mjs → chunk-QJ3TFJLQ.mjs} +1 -1
- package/dist/{chunk-IA4PSIMD.mjs → chunk-QK3VISCA.mjs} +1 -1
- package/dist/{chunk-ZUNVAXLH.mjs → chunk-QXVNUASA.mjs} +1 -1
- package/dist/{chunk-GRAXKKG4.mjs → chunk-QZ35UAB4.mjs} +1 -1
- package/dist/{chunk-UGWYKHBL.mjs → chunk-S2Y7VI4H.mjs} +2 -2
- package/dist/{chunk-OW5NWPOJ.mjs → chunk-SAHS56QM.mjs} +1 -1
- package/dist/{chunk-QOUEFUCH.mjs → chunk-SOD23RGL.mjs} +1 -1
- package/dist/chunk-TDWJKOLN.mjs +2 -0
- package/dist/{chunk-V6RIYQZZ.mjs → chunk-TOE6DPLH.mjs} +1 -1
- package/dist/chunk-UGO5N3EI.mjs +15 -0
- package/dist/{chunk-Q47PLKIJ.mjs → chunk-UGWMMEJ5.mjs} +1 -1
- package/dist/{chunk-NWR2LT5B.mjs → chunk-V5JRSGZF.mjs} +1 -1
- package/dist/{chunk-BZ5RAF7L.mjs → chunk-VA3KAQZD.mjs} +1 -1
- package/dist/chunk-VG5JEIUQ.mjs +12 -0
- package/dist/{chunk-UNOYVIYR.mjs → chunk-VGTMLQWZ.mjs} +1 -1
- package/dist/chunk-VKSRM7EY.mjs +22 -0
- package/dist/{chunk-YQGT4AB2.mjs → chunk-VNUWREXU.mjs} +1 -1
- package/dist/{chunk-AGDILNWB.mjs → chunk-VPVOAJ7X.mjs} +1 -1
- package/dist/{chunk-HLYV7RIH.mjs → chunk-WCWYNFDF.mjs} +1 -1
- package/dist/chunk-WTEGUPFG.mjs +16 -0
- package/dist/{chunk-N76HWBA3.mjs → chunk-XKOHV4H6.mjs} +1 -1
- package/dist/{chunk-HMYTM3GT.mjs → chunk-XMKHCUI6.mjs} +1 -1
- package/dist/{chunk-OUUP3WKT.mjs → chunk-XQRUG4G3.mjs} +1 -1
- package/dist/{chunk-32ZUEFZ7.mjs → chunk-YBB5LWZK.mjs} +1 -1
- package/dist/{chunk-SX4LJYT6.mjs → chunk-YFJU3O7G.mjs} +1 -1
- package/dist/chunk-YPPJVDQI.mjs +2 -0
- package/dist/chunk-ZANMKAWS.mjs +2 -0
- package/dist/{chunk-6QBHU4DF.mjs → chunk-ZCP7BTOZ.mjs} +1 -1
- package/dist/{chunk-ERLAIBOA.mjs → chunk-ZEY2RLBT.mjs} +2 -2
- package/dist/{chunk-SQ6Y2ZMA.mjs → chunk-ZO7SFB2E.mjs} +2 -2
- 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/math.js +1 -1
- package/kit/report.css +123 -44
- 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 +10 -10
- package/skill/SKILL.md +15 -14
- package/skill/references/building-blocks.md +4 -4
- package/skill/references/extensions.md +11 -7
- package/skill/references/pages-and-data.md +13 -9
- package/skill/references/writing-html.md +2 -0
- package/web/assets/index-BHC5ZOMh.js +15 -0
- package/web/assets/index-xP0uw3a0.css +1 -0
- package/web/index.html +2 -2
- package/dist/chunk-2NRBY6AJ.mjs +0 -2
- package/dist/chunk-35NQ4PLQ.mjs +0 -2
- package/dist/chunk-3KJHLHUO.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-GY3FAUVM.mjs +0 -2
- package/dist/chunk-JVHHHGEA.mjs +0 -3
- package/dist/chunk-L7UP52JO.mjs +0 -2
- package/dist/chunk-NAMN3RAF.mjs +0 -2
- package/dist/chunk-PZDLJJTJ.mjs +0 -3
- package/dist/chunk-SXHBYZST.mjs +0 -16
- package/dist/chunk-TEZAWDSQ.mjs +0 -2
- 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
- /package/dist/{chunk-YEY3RSFQ.mjs → chunk-5MMN3N5J.mjs} +0 -0
- /package/dist/{chunk-UH4SIXTR.mjs → chunk-74UW7QSL.mjs} +0 -0
- /package/dist/{chunk-W7XHE4CT.mjs → chunk-EKGYYOSP.mjs} +0 -0
- /package/dist/{chunk-QAIHRH3I.mjs → chunk-KNZJT4ET.mjs} +0 -0
- /package/dist/{chunk-A55HN5OK.mjs → chunk-N3DSBH5S.mjs} +0 -0
- /package/dist/{chunk-QR6A54KJ.mjs → chunk-ZW2A6GBW.mjs} +0 -0
|
@@ -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{refusal as ct,said as at}from"../browser/shared/i18n/index.mjs";import{SITE_ICON_BYTES as it,SITE_ICON_TYPES as lt,loginTitle as ut}from"../browser/shared/web-links.mjs";import $ from"node:http";import z from"node:https";import Y from"node:net";import S from"node:tls";import P from"node:zlib";import{Readable as B}from"node:stream";import{execFile as j}from"node:child_process";import{promisify as M}from"node:util";var A=M(j),X=/^(localhost|127\.|10\.|192\.168\.|172\.(1[6-9]|2\d|3[01])\.|\[?::1\]?$|0\.0\.0\.0)/i;function K(t,e){let n=t.toLowerCase();for(let r of e){let o=r.trim().toLowerCase();if(!o)continue;if(o==="*")return!0;if(o==="<local>"){if(!n.includes("."))return!0;continue}if(o.includes("*")){if(new RegExp(`^${o.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*")}$`).test(n))return!0;continue}let s=o.replace(/^\./,"").replace(/:\d+$/,"");if(n===s||n.endsWith(`.${s}`))return!0}return!1}var N=t=>/^[a-z]+:\/\//i.test(t)?t:`http://${t}`;function V(t=process.env){let e=t.HTTPS_PROXY||t.https_proxy||t.HTTP_PROXY||t.http_proxy||t.ALL_PROXY||t.all_proxy;return e?{url:N(e),bypass:(t.NO_PROXY||t.no_proxy||"").split(",")}:null}async function J(){let{stdout:t}=await A("reg",["query","HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"],{windowsHide:!0,timeout:3e3}),e=o=>new RegExp(`^\\s*${o}\\s+REG_\\w+\\s+(.*)$`,"mi").exec(t)?.[1]?.trim();if(Number.parseInt(e("ProxyEnable")||"0",16)!==1)return null;let n=e("ProxyServer");if(!n)return null;let r=n;if(n.includes("=")){let o=Object.fromEntries(n.split(";").map(s=>s.split("=").map(c=>c.trim())));if(r=o.https||o.http,!r)return null}return{url:N(r),bypass:(e("ProxyOverride")||"").split(";")}}async function Q(){let{stdout:t}=await A("scutil",["--proxy"],{timeout:3e3}),e=r=>new RegExp(`\\b${r}\\s*:\\s*(\\S+)`).exec(t)?.[1];if(e("HTTPSEnable")!=="1"||!e("HTTPSProxy"))return null;let n=[...t.matchAll(/^\s*\d+\s*:\s*(\S+)\s*$/gm)].map(r=>r[1]);return{url:`http://${e("HTTPSProxy")}:${e("HTTPSPort")||80}`,bypass:n}}var C=null,I=0;async function Z(){let t=V();if(t)return t;if(C!==null&&Date.now()-I<3e4)return C||null;let e=null;try{process.platform==="win32"?e=await J():process.platform==="darwin"&&(e=await Q())}catch{e=null}return C=e||!1,I=Date.now(),e}async function tt(t){let e;try{e=new URL(t).hostname}catch{return null}if(X.test(e))return null;let n=await Z();return n&&!K(e,n.bypass)&&/^http:/i.test(n.url)?n.url:null}var R=t=>t.username?{"proxy-authorization":`Basic ${Buffer.from(`${decodeURIComponent(t.username)}:${decodeURIComponent(t.password)}`).toString("base64")}`}:{};function _(t,e,n,r){return new Promise((o,s)=>{let c=$.request({host:t.hostname,port:t.port||80,method:"CONNECT",path:`${e}:${n}`,headers:{host:`${e}:${n}`,...R(t)},signal:r});c.once("connect",(a,l)=>{a.statusCode===200?o(l):(l.destroy(),s(Object.assign(new Error(`the proxy answered ${a.statusCode}`),{proxyAnswered:a.statusCode})))}),c.once("error",s),c.end()})}function et(t,{method:e,headers:n,signal:r},o){let s=new URL(t),c=new URL(o),a={"accept-encoding":"gzip, deflate, br",...n};return new Promise((l,i)=>{let u=f=>{f.once("response",l),f.once("error",i),f.end()};if(s.protocol==="http:"){u($.request({host:c.hostname,port:c.port||80,method:e,path:s.href,headers:{...a,host:s.host,...R(c)},signal:r}));return}_(c,s.hostname,s.port||443,r).then(f=>{u(z.request(s,{method:e,headers:{...a,host:s.host},defaultPort:443,signal:r,createConnection:()=>S.connect({socket:f,servername:s.hostname,ALPNProtocols:["http/1.1"]})}))},i)})}function T(t,e){let n=new Headers;for(let[l,i]of Object.entries(t.headers))n.set(l,Array.isArray(i)?i.join(", "):String(i));let r=(t.headers["content-encoding"]||"").toLowerCase(),o={gzip:P.createGunzip,"x-gzip":P.createGunzip,deflate:P.createInflate,br:P.createBrotliDecompress}[r],s=o?t.pipe(o()):t;o&&(t.on("error",l=>s.destroy(l)),n.delete("content-encoding"),n.delete("content-length"));let c=[101,204,205,304].includes(t.statusCode);c&&t.resume();let a=new Response(c?null:B.toWeb(s),{status:t.statusCode,statusText:t.statusMessage,headers:n});return Object.defineProperty(a,"url",{value:e}),a}async function nt(t,{method:e="GET",headers:n={},signal:r}={},o){for(let s=0;;s++){let c=await et(t,{method:e,headers:n,signal:r},o),a=c.headers.location;if([301,302,303,307,308].includes(c.statusCode)&&a&&s<10){c.resume(),t=new URL(a,t).href,c.statusCode===303&&(e="GET");continue}return T(c,t)}}var v=t=>t.includes(":")?`[${t}]`:t,ot=t=>/^[\d.]+$/.test(t)||t.includes(":");function Pt(t,{address:e,proxy:n=null,headers:r={},signal:o,connect:s=(a,l)=>Y.connect({host:a,port:l}),ca:c=null}){let a=Number(t.port)||(t.protocol==="https:"?443:80),l=e===null;if(l&&!(n&&t.protocol==="https:"))return Promise.reject(new Error("fetchPinned: only an https address is handed to a proxy by its name"));let i=ot(t.hostname)?void 0:t.hostname,u={"accept-encoding":"gzip, deflate, br",...r,host:t.host},f=`${t.pathname}${t.search}`,L=l||c?[...S.rootCertificates,...c?[c]:[]]:null,b=d=>S.connect({socket:d,servername:i,ALPNProtocols:["http/1.1"],...L?{ca:L}:{},...l?{rejectUnauthorized:!0}:{}}),F=d=>new Promise((x,m)=>{if(o?.aborted)return d.destroy(),m(o.reason);let h=b(d),g=()=>h.destroy(o.reason);o?.addEventListener("abort",g,{once:!0}),h.on("error",p=>{o?.removeEventListener("abort",g),m(p)}),h.once("close",()=>m(new Error("the connection closed before TLS was done"))),h.once("secureConnect",()=>{if(o?.removeEventListener("abort",g),l&&!h.authorized){let p=Object.assign(new Error(`the certificate failed (${h.authorizationError})`),{code:String(h.authorizationError)});return h.destroy(),m(p)}x(h)})});return new Promise((d,x)=>{let m=p=>{let w=(t.protocol==="https:"?z:$).request({method:"GET",signal:o,...p});w.once("response",D=>d(T(D,t.href))),w.once("error",x),w.end()};if(!n){m({host:e,port:a,path:f,headers:u,createConnection:()=>t.protocol==="https:"?b(s(e,a)):s(e,a)});return}let h=new URL(n),g=p=>x(p?.proxyAnswered||o?.aborted?p:Object.assign(p??new Error("the proxy was not reached"),{proxyFailed:!0}));if(t.protocol==="http:"){let p=$.request({host:h.hostname,port:h.port||80,method:"GET",path:`http://${v(e)}:${a}${f}`,headers:{...u,...R(h)},agent:!1,signal:o});p.once("response",w=>d(T(w,t.href))),p.once("error",g),p.end();return}_(h,l?t.hostname:v(e),a,o).then(p=>F(p).then(w=>m({host:l?t.hostname:e,port:a,path:f,headers:u,createConnection:()=>w}),x),g)})}async function rt(t,e={}){let n=await tt(t);if(n)try{return await nt(t,e,n)}catch(r){if(e.signal?.aborted)throw r}return fetch(t,e)}var st="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0 Safari/537.36";async function y(t,{timeout:e=1e4,accept:n="*/*",headers:r={},unreachable:o="\u6253\u4E0D\u5F00\u8FD9\u4E2A\u7F51\u9875",protocols:s=["http:","https:"]}={}){let c;try{c=new URL(t)}catch{throw Object.assign(new Error("\u4E0D\u662F\u7F51\u5740"),{reason:"url"})}if(!s.includes(c.protocol))throw Object.assign(new Error("\u53EA\u652F\u6301 http(s) \u7F51\u5740"),{reason:"url"});return rt(c,{redirect:"follow",signal:AbortSignal.timeout(e),headers:{"user-agent":st,accept:n,...r}}).catch(()=>{throw Object.assign(new Error(o),{reason:"download"})})}async function E(t,e){let n=t.body.getReader(),r=[],o=0;for(;;){let{done:s,value:c}=await n.read();if(s)break;if(r.push(Buffer.from(c)),o+=c.length,o>=e){n.cancel().catch(()=>{});break}}return Buffer.concat(r)}async function O(t,e){let n=await E(t,e+1);return n.length<=e?n:null}var ft={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:" "},H=t=>t.replace(/&(#x[0-9a-f]+|#\d+|\w+);/gi,(e,n)=>{if(n[0]==="#"){let r=n[1]==="x"||n[1]==="X"?parseInt(n.slice(2),16):Number(n.slice(1));return Number.isFinite(r)&&r>0&&r<=1114111?String.fromCodePoint(r):e}return ft[n.toLowerCase()]??e}),U=t=>H(String(t??"")).replace(/\s+/g," ").trim();function pt(t){let e={};for(let n of t.matchAll(/([\w:-]+)\s*=\s*("([^"]*)"|'([^']*)'|([^\s>]+))/g))e[n[1].toLowerCase()]=n[3]??n[4]??n[5]??"";return e}function k(t,e){let n=/charset=([\w-]+)/i.exec(e??"")?.[1];n||(n=/<meta[^>]+charset=["']?([\w-]+)/i.exec(t.subarray(0,4096).toString("latin1"))?.[1]);try{return new TextDecoder(n||"utf-8").decode(t)}catch{return new TextDecoder("utf-8").decode(t)}}function q(t,e){let n=t.search(/<\/head>/i),r=n>0?t.slice(0,n):t.slice(0,3e5),o={},s=[];for(let[i]of r.matchAll(/<(meta|link)\b[^>]*>/gi)){let u=pt(i);if(/^<meta/i.test(i)){let f=(u.property||u.name||u.itemprop||"").toLowerCase();f&&u.content!==void 0&&!(f in o)&&(o[f]=u.content)}else u.rel&&u.href&&/(^|\s)(icon|shortcut icon|apple-touch-icon)(\s|$)/i.test(u.rel)&&s.push({rel:u.rel.toLowerCase(),href:u.href})}let c=i=>{try{return i?new URL(H(i),e).href:null}catch{return null}},a=/<title[^>]*>([\s\S]*?)<\/title>/i.exec(r)?.[1],l=s.find(i=>/(^|\s)icon(\s|$)/.test(i.rel))??s.find(i=>i.rel.includes("icon"));return{title:U(o["og:title"]||o["twitter:title"]||a||"").slice(0,300),description:U(o["og:description"]||o["twitter:description"]||o.description||"").slice(0,600),icon:c(l?.href)||c("/favicon.ico"),cover:c(o["og:image"]||o["og:image:url"]||o["og:image:secure_url"]||o["twitter:image"]||o["twitter:image:src"])}}async function ht(t){if(!t)return null;try{let e=await y(t,{timeout:8e3,accept:"image/*,*/*;q=0.5",protocols:["http:","https:","data:"]}),n=(e.headers.get("content-type")??"").split(";")[0].trim();if(!e.ok||!/^image\//.test(n))return null;let r=await O(e,5*1024*1024);return r?.length?r:null}catch{return null}}async function Rt(t){try{let e=await y(t,{timeout:8e3,accept:"text/html,*/*;q=0.8"});if(e.body?.cancel().catch(()=>{}),[401,403].includes(e.status)||W(e.url))return{frameable:!0,reason:"auth"};if(!e.ok)return{frameable:!0,reason:"unknown"};let n=(e.headers.get("x-frame-options")??"").toLowerCase(),r=(e.headers.get("content-security-policy")??"").split(",").map(o=>/(?:^|;)\s*frame-ancestors\s+([^;]*)/i.exec(o)?.[1]?.trim().toLowerCase()).filter(o=>o!==void 0);return r.length?r.some(o=>o==="'none'"||o==="'self'")?{frameable:!1,reason:"frame-ancestors"}:{frameable:!0,...r.every(o=>o==="*")?{}:{reason:"unknown"}}:n.split(",").some(o=>/^(deny|sameorigin)$/.test(o.trim()))?{frameable:!1,reason:"x-frame-options"}:{frameable:!0}}catch(e){return e.reason==="url"?{frameable:!1,reason:"url"}:{frameable:!0,reason:"unknown"}}}function W(t){try{let e=new URL(t);return/^(?:login|signin|passport|sso)\./i.test(e.hostname)||/\/(?:login|signin|sign-in|oauth2\/challenge)(?:[/.]|$)/i.test(e.pathname)}catch{return!1}}async function Ot(t){try{let e=await y(t,{accept:"text/html,application/xhtml+xml;q=0.9,*/*;q=0.8",headers:{"accept-language":"zh-CN,zh;q=0.9,en;q=0.8"}});if([401,403].includes(e.status)||W(e.url))return e.body?.cancel().catch(()=>{}),{title:"",reason:"auth"};let n=e.headers.get("content-type")??"";if(!e.ok||!/html|xml/i.test(n))return e.body?.cancel().catch(()=>{}),{title:"",reason:"unknown"};let r=q(k(await E(e,1.5*1024*1024),n),e.url||t).title;return ut(r)?{title:"",reason:"auth"}:{title:r.slice(0,200)}}catch{return{title:"",reason:"unknown"}}}function dt(t){let e=t.subarray(0,16);return e[0]===137&&e.toString("latin1",1,4)==="PNG"?"image/png":e[0]===0&&e[1]===0&&e[2]===1&&e[3]===0?"image/x-icon":e.toString("latin1",0,3)==="GIF"?"image/gif":e[0]===255&&e[1]===216&&e[2]===255?"image/jpeg":e.toString("latin1",0,4)==="RIFF"&&e.toString("latin1",8,12)==="WEBP"?"image/webp":/^\s*(<\?xml[^>]*>\s*)?<svg[\s>]/i.test(t.subarray(0,512).toString("utf8"))?"image/svg+xml":null}async function G(t,e){if(!t||e<=0)return null;try{let n=await y(t,{timeout:e,accept:"image/*,*/*;q=0.5",protocols:["http:","https:","data:"]});if(!n.ok)return n.body?.cancel().catch(()=>{}),null;let r=(n.headers.get("content-type")??"").split(";")[0].trim().toLowerCase(),o=await O(n,it);if(!o?.length)return null;let s=lt.includes(r)?r:dt(o);return s?`data:${s};base64,${o.toString("base64")}`:null}catch{return null}}async function kt(t,{timeout:e=4e3,env:n=process.env}={}){if(n.GALLERY_SITE_ICON==="off")return null;if(n.GALLERY_SITE_ICON==="local"){let i="";try{i=new URL(t).hostname.replace(/^\[|\]$/g,"")}catch{}if(!/^(127\.\d+\.\d+\.\d+|localhost|::1)$/i.test(i))return null}let r=Date.now()+e,o=()=>r-Date.now(),s=t,c=null;try{let i=await y(t,{timeout:o(),accept:"text/html,application/xhtml+xml;q=0.9,*/*;q=0.8"});s=i.url||t;let u=i.headers.get("content-type")??"";i.ok&&/html|xml/i.test(u)?c=q(k(await E(i,512*1024),u),s).icon:i.body?.cancel().catch(()=>{})}catch{return null}let a=null;try{a=new URL("/favicon.ico",s).href}catch{}return await G(c,o())??(c!==a?G(a,o()):null)}async function qt(t,e,{icon:n=!0,cover:r=!0}={}){let o=await y(t,{accept:"text/html,application/xhtml+xml;q=0.9,*/*;q=0.8",headers:{"accept-language":"zh-CN,zh;q=0.9,en;q=0.8"}}),s=o.url||new URL(t).href,c=o.headers.get("content-type")??"";if(!o.ok)throw ct(at("\u7F51\u9875\u8FD4\u56DE {0}",o.status),{reason:"download"});if(!/html|xml/i.test(c))return o.body?.cancel().catch(()=>{}),{url:s,title:"",description:"",icon:null,cover:null};let a=q(k(await E(o,1.5*1024*1024),c),s),l=async(f,L)=>{let b=await ht(f);try{return b?await e(b,L):null}catch{return null}},[i,u]=await Promise.all([n?l(a.icon,"bookmark-icon"):null,r?l(a.cover,"bookmark-cover"):null]);return{url:s,title:a.title,description:a.description,icon:i,cover:u}}export{tt as a,Pt as b,y as c,O as d,Rt as e,Ot as f,kt as g,qt as h};
|
|
@@ -1,3 +1,3 @@
|
|
|
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}from"./chunk-JEUK3ZO7.mjs";import"./chunk-
|
|
2
|
+
import{a}from"./chunk-JEUK3ZO7.mjs";import"./chunk-TOE6DPLH.mjs";import{f as D}from"./chunk-WTEGUPFG.mjs";import{b as d,f as J,i as k}from"./chunk-4OZWXZE5.mjs";import{c as F}from"./chunk-DHB7UZ7F.mjs";import"./chunk-2RKIHJI2.mjs";import{a as A}from"./chunk-JXLSHVJ2.mjs";import"./chunk-XKOHV4H6.mjs";import"./chunk-KFZBYDIS.mjs";import"./chunk-7XDYK3UC.mjs";import"./chunk-VG5JEIUQ.mjs";import"./chunk-N3DSBH5S.mjs";import"./chunk-5L7RYZCL.mjs";import{existsSync as E}from"node:fs";import R from"node:fs/promises";import m from"node:path";import{iconKind as q}from"../browser/shared/emoji/icon-value.mjs";import{writeAtomic as z}from"../browser/shared/files.mjs";import{reportsDirectory as C}from"../browser/shared/paths.mjs";import{roleOf as M}from"../browser/shared/reports.mjs";import{documentDirectory as P,documentFiles as T,pageSlug as U}from"../browser/shared/workspace.mjs";var K=o=>o.replace(/\s+/g," ").trim(),_=o=>o.replace(/^[a-z]:\/(?:[^/]+\/)*?(?=icons\/(?:tabler\/)?[^/]+$)/i,"/"),h=o=>o===null?"none":JSON.stringify(o);async function ie(o){let{positional:u,values:c}=J({values:["--title","--icon","--description"],argv:o});if(u.length!==1)throw new d("Name one document, then what to set: --title, --icon, --description.");if(!["--title","--icon","--description"].some(e=>c.has(e)))throw new d('Say what to set: --title "<title>", --icon <emoji|none|\u2026>, --description "<text>".');let n=c.has("--title")?K(c.get("--title")):void 0,p=c.has("--description")?K(c.get("--description")):void 0;if(n==="")throw new d("--title takes the words of the title: a document's title is never empty.");if(p==="")throw new d("--description takes words: a document's description is never empty.");let t;if(c.has("--icon")){let e=_(c.get("--icon").trim()),f=e==="none"?"none":q(e);if(!f||/["<>&]/.test(e))throw new d(`Not a page icon: ${e} (an emoji, none, an icon of the \u56FE\u6807 tab as /icons/<name>_<color>.svg, or a picture of the document's assets/).`);if(f==="glyph"&&!F(e))throw new d(`No such icon of the \u56FE\u6807 tab: ${e}.`);t=f==="none"?null:e}let{slug:w}=await k(u[0]),$=P(w,C);(w===await U(C)||await M($)==="instructions")&&(console.error(`${u[0]} is the \u5199\u4F5C\u504F\u597D page: only the user changes it.`),process.exit(1));let{html:r,json:s}=T($);E(r)||(console.error(`No document "${u[0]}": ${a(r)} does not exist (gallery list lists those there are).`),process.exit(1)),t&&q(t)==="image"&&!E(m.join($,...t.split("/")))&&(console.error(`No picture ${t} in ${a($)}: put it in its assets/ first.`),process.exit(1));let i;try{if(i=JSON.parse(await R.readFile(s,"utf8")),!i||typeof i!="object"||Array.isArray(i))throw new Error("not an object")}catch(e){console.error(`${a(s)} does not read (${e.code??e.message}): mend it first.`),process.exit(1)}let b=null,N=!1;for(let e=1;n!==void 0||t!==void 0;e++){let f=await R.readFile(r,"utf8"),v=A(f),y=D(v,{title:n,icon:t});if(y.missing&&(console.error(`${a(r)} has no title to ${n!==void 0?"set":"put the icon before"}: write it as an h1.doc-title in the page's header (writing-html.md, "The page").`),process.exit(1)),b=y.before,y.text===v)break;if(await z(r,y.text,{expect:f})){N=!0;break}e===3&&(console.error(`${a(r)} kept changing while it was being written (the page saving, or an Agent writing it?): nothing written. Run gallery set again.`),process.exit(1))}let l={...i};n!==void 0&&(l.title=n),p!==void 0&&(l.description=p),t===null?delete l.icon:t!==void 0&&(l.icon=t);let x=JSON.stringify(l)!==JSON.stringify(i);x&&await z(s,`${JSON.stringify(l,null,2)}
|
|
3
3
|
`);let S=m.basename(r),g=[];n!==void 0&&g.push(` title: ${h(b.title)} \u2192 ${h(n)} (${S}'s h1 and <title>, ${m.basename(s)})`),t!==void 0&&g.push(` icon: ${h(b.icon)} \u2192 ${h(t)} (${S}'s header, ${m.basename(s)})`),p!==void 0&&g.push(` description: ${h(typeof i.description=="string"?i.description:null)} \u2192 ${h(p)} (${m.basename(s)})`);let j=[...N?[a(r)]:[],...x?[a(s)]:[]];if(j.length===0){console.log(`Nothing to change: ${w} has ${g.length===1?"that already":"those already"}.`);return}console.log(`Set ${w}:`);for(let e of g)console.log(e);let O=j.length===1;console.log(`Re-read ${j.join(", ")} before editing ${O?"it":"them"}: gallery set wrote ${O?"it":"them"} (${[...N?[`${S}: its header`]:[],...x?[`${m.basename(s)}: ${["title","icon","description"].filter(e=>JSON.stringify(l[e])!==JSON.stringify(i[e])).join(", ")}`]:[]].join("; ")}).`)}export{ie as run};
|
|
@@ -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{c as O,d as P,e as b,l as C}from"./chunk-
|
|
2
|
+
import{c as O,d as P,e as b,l as C}from"./chunk-JJNRIFND.mjs";import{a as q}from"./chunk-ASAXY2DJ.mjs";import{a as u,f as S,g as w,i as E,j as I,k as H}from"./chunk-YPPJVDQI.mjs";import{a as h,b as R}from"./chunk-JEUK3ZO7.mjs";import{b as D,f as L,g as T}from"./chunk-4OZWXZE5.mjs";import{b as N}from"./chunk-NWRZXELO.mjs";import{existsSync as g}from"node:fs";import i from"node:path";import{reportsDirectory as c}from"../browser/shared/paths.mjs";import{idHolder as z,isDocSlug as B,keptName as G,layoutOf as A,listTrash as J}from"../browser/shared/workspace.mjs";import{parentIn as K}from"../browser/shared/outline.mjs";import{joinDefaultTree as Q,joinedLine as V}from"../browser/shared/drafts.mjs";var W="\u65B0\u6587\u6863";async function F(t,n=c){if(G(t))return`"${t}" is a name the workspace keeps for itself: choose another slug.`;if(g(i.join(A(n).preferencesPage,t)))return`"${t}" is the \u5199\u4F5C\u504F\u597D page's slug: choose another slug.`;if(g(i.join(A(n).customPages,t)))return`"${t}" is a custom page's slug (documents and custom pages share one set of names: gallery page list lists them): choose another slug.`;if(g(i.join(n,t)))return`Document already exists: ${h(i.join(n,t))}`;if((await J(n)).some(r=>r.slug===t))return`"${t}" is the slug of something in the trash: choose another slug.`;if(B(t)){let r=await z(t,n);if(r)return`"${t}" would have the page id (${t.slice(4)}) of "${r}" in this workspace, and two documents may not share an address: choose another slug.`}return null}async function fe(t){let{positional:n,options:r,values:U}=L({options:["--no-preview","--no-browser","--first"],values:["--under","--after"],argv:t}),[e,y,$=W]=n;if(n.length<2||n.length>3||!e||!y?.trim()||!$.trim())throw new D("Name the slug and the title (then a description, if you choose one), each quoted when it has spaces.");T(e);let s=H(U,r,{top:!1}),x=await F(e);x&&(console.error(x),process.exit(1));let M=s.under!==void 0||s.after!==void 0||s.first,l=null;if(M){let o=await u(),a=async(X,_)=>{let p=await S(X,_,o);return p.refused&&(console.error(`${p.refused} Nothing made.`),process.exit(1)),p.slug},f=s.under!==void 0?await a(s.under,"--under"):void 0,d=s.after!==void 0?await a(s.after,"--after"):null;d!==null&&f!==void 0&&K(o.children,d)!==f&&(console.error(`${w(o,e,"level",{parent:f,after:d})} Nothing made.`),process.exit(1)),l={parent:f,after:d,first:s.first}}try{await N(e,y,$)}catch(o){if(o.code!=="EEXIST")throw o;console.error(await F(e)??`Document already exists: ${h(i.join(c,e))}`),process.exit(1)}if(await import("./chunk-TDWJKOLN.mjs").then(({noteNew:o})=>o(e)),console.log(`Created ${h(i.join(c,e,"doc.html"))} and doc.json`),l){let o=await E(e,l),a=await u();o.ok?console.log(`Placed it ${I(a,o)}.`):(console.log(`Not placed (${w(a,e,o.reason,{...l,message:o.message})}): it is at the top level, last; gallery move ${e} puts it where it goes.`),process.exitCode=1)}let v=V(await Q(c,e));v&&console.log(v);for(let o of await R())console.log(o);let j=q(c);j&&console.log(j);let m=await C(e,{skipped:b(r),command:`gallery new ${e}`});console.log(O(m,"replace the starter section with the document's skeleton (each section's heading) as soon as you can outline it, then write it a section at a time, as ordinary HTML, so that the user watches it grow (gallery check fails while the starter section remains).")),console.log(`Hand in: gallery export ${e}, then gallery qa ${e}`);let k=await P(m,r);k&&console.log(k);for(let o of m)console.log(o)}export{W as a,F as b,fe as c};
|
|
@@ -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{g as St,r as nt,t as Ct}from"./chunk-FWNRPMCJ.mjs";import{a as Lt,b as st,c as z,e as vt}from"./chunk-A55HN5OK.mjs";import{createHash as Ee}from"node:crypto";import{BLOCK_LEVEL as ot}from"../browser/shared/html-tree.mjs";var wt=t=>Ee("sha256").update(t).digest("hex").slice(0,16),M=t=>t.nodeName==="#text"&&!t.value.trim();function at(t,e){for(let s of t.childNodes??[]){if(s.tagName===e)return s;let o=s.tagName&&at(s,e);if(o)return o}return null}import{ATTRIBUTES as an,BOX_CLASSES as on,COMPONENT_ATTRIBUTES as rn,COMPONENT_CLASSES as cn,GROUPING as ln,IDENTITY as R,TOGGLES as fn,UNIT_KINDS as dn}from"../browser/editor/components/registry.mjs";import{attr as I,hasClass as kt}from"../browser/shared/html-tree.mjs";import{idsNamed as un}from"../browser/shared/copy-ids.mjs";import{DIALOG as pn,PAGE as mn,SECTION as gn,SHEETS as K,TABLE as Le}from"../browser/editor/components/kit.mjs";import{matchesNode as q,partOf as bt}from"../browser/shared/components/index.mjs";import{escapeMarkup as V}from"../browser/shared/escape.mjs";import{imageFile as Ae}from"../browser/shared/media.mjs";import{emptyFigure as Ie}from"../browser/editor/components/media/write.mjs";var _e=t=>typeof t=="string"&&t.length<=2e3&&/^https?:\/\/[^\s"<>]+$/.test(t),Et=(t,e)=>typeof t=="string"&&t.length<=e&&!/[\u0000-\u001f]/.test(t),At=t=>t.href===""&&!t.title&&!t.description&&!t.icon&&!t.cover&&t.caption==="",It=t=>t==null||Ae(t),_t={bookmark:{check:(t,{validLeaf:e})=>At(t)||_e(t.href)&&Et(t.title,300)&&Et(t.description??"",600)&&It(t.icon)&&It(t.cover)&&typeof t.caption=="string"&&(t.caption===""||e({tag:"figcaption"},t.caption)),write(t,e){if(At(t))return Ie("bookmark",e);let s=t.title.trim()||new URL(t.href).hostname,o=[`<span class="doc-bookmark-title">${V(s)}</span>`,t.description?`<span class="doc-bookmark-description">${V(t.description)}</span>`:"",`<span class="doc-bookmark-url">${t.icon?`<img class="doc-bookmark-icon" src="${t.icon}" alt="">`:""}<span class="doc-bookmark-href">${V(t.href)}</span></span>`].join(""),n=t.cover?`<span class="doc-bookmark-cover"><img src="${t.cover}" alt=""></span>`:"",a=`<a class="doc-bookmark-card" href="${V(t.href)}" target="_blank" rel="noopener noreferrer"><span class="doc-bookmark-text">${o}</span>${n}</a>`;return e.block(`<figure class="doc-bookmark"${e.id}>`,[a,`<figcaption>${t.caption}</figcaption>`],"</figure>")}}};import{BLOCK_TYPES as Be,sizeValue as Me}from"../browser/editor/components/registry.mjs";import{LINE_START as Mt,lineStart as je}from"../browser/shared/code-lines.mjs";import{hasClass as Bt}from"../browser/shared/html-tree.mjs";import{CODE_HEIGHT as rt,FOLDED_LINES as jt,validFolded as Re,validLanguage as De}from"../browser/editor/components/code/index.mjs";var ze=(t,e,s,o,n="",a="",r="",i="")=>`<div class="${t.className}"${s?` data-language="${s}"`:""}${i?` ${Mt}="${i}"`:""}${r?` ${jt}="${r}"`:""}${o?` style="${rt}: ${o}"`:""}${n}><div class="doc-code-title">${a}</div><pre><code>${e}</code></pre></div>`,Ue=(t,e)=>t==="data-language"||t===jt||t===Mt||t==="style"&&new RegExp(`^\\s*${rt}\\s*:[^;]*;?\\s*$`).test(e??""),We=t=>typeof t=="string"&&t.length<=200&&!/[<>\n]|&(?!(amp|lt|gt|quot|#39);)/.test(t),Fe=t=>(t.language===void 0||De(t.language))&&(t.folded===void 0||Re(t.folded))&&(t.height===void 0||Me("code",rt,t.height)===t.height)&&(t.title===void 0||We(t.title))&&(t.lineStart===void 0||typeof t.lineStart=="string"&&String(je(t.lineStart))===t.lineStart);function Ke(t){let{node:e}=t;if(t.tag!=="div"||t.nested||!Bt(e,Be.code.className))return!1;let s=(n,a)=>{let r=n.childNodes??[],i=r.filter(f=>f.tagName);return i.length===a.length&&i.every((f,l)=>f.tagName===a[l])&&r.every(f=>f.tagName||!(f.value??"").trim())?i:null},o=s(e,["div","pre"]);return!!o&&Bt(o[0],"doc-code-title")&&!!s(o[1],["code"])}var Rt={code:{fields:["language","folded","height","title","lineStart"],check:Fe,leaf:(t,e,s)=>ze(t,e.html,e.language,e.height,s,e.title,e.folded,e.lineStart),written:Ke,attribute:Ue}};import{sizeValue as He}from"../browser/editor/components/registry.mjs";import{MIN_COLUMNS as Pe,RATIO as Dt}from"../browser/editor/components/columns/index.mjs";var zt={columns:{check:t=>t.children.length>=Pe&&t.children.every(e=>e.type==="column")},column:{check:t=>t.ratio===void 0||He("column",Dt,t.ratio)===t.ratio,write(t,e){let s=t.ratio===void 0?"":` style="${Dt}: ${t.ratio}"`;return e.block(`<div class="doc-column"${s}${e.id}>`,e.children(e.inner),"</div>")}}};var Ut={details:{empty:!0,check:(t,{validLeaf:e})=>t.title===""||e({tag:"span"},t.title),write(t,e){let s=e.inner===null?null:e.inner+e.step,o=e.block('<div class="doc-details-content">',e.children(s),"</div>",e.inner,s),n=t.classes?.length?` ${t.classes.join(" ")}`:"";return e.block(`<details class="doc-details${n}"${e.id}>`,[`<summary><span class="doc-details-summary-label">${t.title}</span></summary>`,t.children.length>0?o:'<div class="doc-details-content"></div>'],"</details>")}}};var Wt={dialog:{empty:!0,check(t,{usedIds:e}){return typeof t.id!="string"||!/^[A-Za-z][\w-]{0,63}$/.test(t.id)||e.has(t.id)?!1:(e.add(t.id),!0)},write(t,e){let s=t.children.length>0?e.block('<div class="doc-dialog-content">',e.children(e.deep(3)),"</div>",e.deep(2),e.deep(3)):'<div class="doc-dialog-content"></div>',o=e.block('<div class="doc-dialog-panel">',[s],"</div>",e.deep(1),e.deep(2));return e.block(`<dialog class="doc-dialog" id="${t.id}">`,[o],"</dialog>")}}};import{escapeAttribute as Ge}from"../browser/shared/escape.mjs";import{embedFile as Ft}from"../browser/shared/media.mjs";import{emptyFigure as qe}from"../browser/editor/components/media/write.mjs";import{FILE_SANDBOX as Ve,WEB_SANDBOX as Xe}from"../browser/editor/components/embed/index.mjs";var Ye=t=>typeof t=="string"&&t.length<=2e3&&/^https:\/\/[^\s"<>]+$/.test(t),Kt=t=>t.src===""&&t.height===void 0&&t.caption==="",Ht={embed:{check:(t,{validLeaf:e})=>Kt(t)||(Ye(t.src)||Ft(t.src))&&(t.height===void 0||/^\d{2,4}px$/.test(t.height))&&typeof t.caption=="string"&&(t.caption===""||e({tag:"figcaption"},t.caption)),write(t,e){if(Kt(t))return qe("embed",e);let s=Ft(t.src),o=s?/\.pdf$/i.test(t.src)?"":` sandbox="${Ve}"`:` sandbox="${Xe}" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen`,n=`<iframe class="doc-embed-frame" src="${Ge(t.src)}"${o} loading="lazy"></iframe>`,a=t.height?` style="--doc-embed-height: ${t.height}"`:"";return e.block(`<figure class="doc-embed${s?" doc-embed--file":""}"${a}${e.id}>`,[n,`<figcaption>${t.caption}</figcaption>`],"</figure>")}}};import{escapeMarkup as Pt}from"../browser/shared/escape.mjs";import{assetFile as Ze}from"../browser/shared/media.mjs";import{emptyFigure as Je}from"../browser/editor/components/media/write.mjs";var Gt=t=>t.href===""&&t.name===""&&t.size===void 0&&t.caption==="",Qe=t=>typeof t=="string"&&t.trim()!==""&&t.length<=120&&!/[\u0000-\u001f<>:"/\\|?*]/.test(t),qt={file:{check:(t,{validLeaf:e})=>Gt(t)||Ze(t.href)&&Qe(t.name)&&(t.size===void 0||/^\d+(\.\d)? (B|KiB|MiB|GiB)$/.test(t.size))&&typeof t.caption=="string"&&(t.caption===""||e({tag:"figcaption"},t.caption)),write(t,e){if(Gt(t))return Je("file",e);let s=t.size?`<span class="doc-file-size">${t.size}</span>`:"",o=`<a class="doc-file-link" href="${t.href}" download="${Pt(t.name)}"><span class="doc-file-name">${Pt(t.name)}</span>${s}</a>`;return e.block(`<figure class="doc-file"${e.id}>`,[o,`<figcaption>${t.caption}</figcaption>`],"</figure>")}}};import{FLOW as ts,FLOW_DIRECTION as Vt,FLOW_RATIO as Xt}from"../browser/editor/components/flowchart/index.mjs";import{START as es,validDirection as Yt,validStart as ss}from"../browser/editor/components/list/index.mjs";import{sizeValue as ns,TOGGLES as as}from"../browser/editor/components/registry.mjs";var Zt={flowchart:{check:t=>(t.start===void 0||ss(t.start))&&(t.direction===void 0||Yt(t.direction))&&t.children.length>0,write:(t,e)=>e.block(`<ol class="${ts}"${t.start?` ${es}="${t.start}"`:""}${t.direction?` ${Vt}="${t.direction}"`:""}${e.id}>`,e.children(e.inner),"</ol>")},step:{check:t=>(t.classes===void 0||Array.isArray(t.classes)&&new Set(t.classes).size===t.classes.length&&t.classes.every(e=>(as.step??[]).includes(e)))&&(t.ratio===void 0||ns("step",Xt,t.ratio)===t.ratio)&&(t.direction===void 0||Yt(t.direction))&&t.children.length>0,write(t,e){let s=t.classes?.length?` class="${t.classes.join(" ")}"`:"",o=t.direction?` ${Vt}="${t.direction}"`:"",n=t.ratio===void 0?"":` style="${Xt}: ${t.ratio}"`;return e.block(`<li${s}${o}${n}${e.id}>`,e.children(e.inner),"</li>")}}};import{SPAN as os,SPAN_SIZE as Jt,imageFile as Qt}from"../browser/shared/media.mjs";import{emptyFigure as rs}from"../browser/editor/components/media/write.mjs";var is=/^\d{1,3}(\.\d{1,3})?( \d{1,3}(\.\d{1,3})?){3}$/,te=t=>t.src===""&&t.caption===""&&t.span===void 0&&t.original===void 0&&t.classes===void 0,cs=t=>typeof t=="number"&&Number.isFinite(t)&&t>=Jt.min&&t<=Jt.max,ee={image:{check:(t,{validLeaf:e})=>te(t)||Qt(t.src)&&typeof t.caption=="string"&&(t.caption===""||e({tag:"figcaption"},t.caption))&&(t.span===void 0||cs(t.span))&&(t.original===void 0||Qt(t.original)&&typeof t.crop=="string"&&is.test(t.crop)),write(t,e){if(te(t))return rs("image",e);let s=["doc-image",...t.classes??[]].join(" "),o=t.span===void 0?"":` style="${os}: ${Math.round(t.span*1e3)/1e3}"`,n=t.original===void 0?"":` data-original="${t.original}" data-crop="${t.crop}"`;return e.block(`<figure class="${s}"${o}${e.id}>`,[`<img src="${t.src}" alt=""${n}>`,`<figcaption>${t.caption}</figcaption>`],"</figure>")}}};vt();import{heldByNode as ls,instanceSlots as fs,isInstance as lt,isSlot as ds,ownSlots as us,partOf as ft}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as G,DATA_MOST as ps,NO_TEXT as ms,PACKAGE_ID as se,SCHEMA as ne,SLOT as ae,fitsDataScript as gs,isDataScript as hs,noDataPart as $s,refusedInCopy as Ns,refusedInData as Os,schemaAhead as oe}from"../browser/shared/components/installed.mjs";import{attr as B,walk as re}from"../browser/shared/html-tree.mjs";import{CHART_KEY as bs,VIEW_FROM as it}from"../browser/shared/table-chart.mjs";var P=(t,e)=>{for(let s=t.parentNode;s;s=s.parentNode)if(s===e)return!0;return!1},xs=t=>{let e=t.parentNode;for(;e&&!lt(e);)e=e.parentNode;return e??null},dt=(t,e)=>xs(t)===e&&ls(t)===e&&!ds(t);function ct(t,e){let o=Object.entries(e.get(B(t,G))?.parts??{}).filter(([,{edit:n}])=>n==="data").map(([n,{at:a}])=>[n,ft(t,a).find(r=>r.sourceCodeLocation&&!lt(r)&&dt(r,t))]).filter(([,n])=>n);return o.filter(([,n],a)=>!o.some(([,r],i)=>P(n,r)||r===n&&i<a))}var ys=new Set(["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"]),ks="http://www.w3.org/1999/xhtml",Ts=t=>(t.content??t).childNodes;function ie(t,e,s,o){let n=s;for(let a of Ts(t)){let r=a.sourceCodeLocation;if(r?.startOffset!==n)return!1;if(a.tagName){let{startTag:i,endTag:f}=r,l=ys.has(a.tagName)||a.namespaceURI!==ks&&e.startsWith("/>",r.endOffset-2);if(f?!ie(a,e,i.endOffset,f.startOffset):!l)return!1}n=r.endOffset}return n===o}function Ls(t,e,s){if(e.tagName==="script")return hs(e.tagName,e.attrs)&&gs(s);if($s(e.tagName))return!1;let{startTag:o,endTag:n}=e.sourceCodeLocation,a=t.slice(o.startOffset,o.endOffset),r=`${a}${s}${t.slice(n.startOffset,n.endOffset)}`,[i,...f]=z(e.parentNode,r,{sourceCodeLocationInfo:!0}).childNodes;if(f.length>0||i?.tagName!==e.tagName||i.sourceCodeLocation?.endOffset!==r.length||!i.sourceCodeLocation.endTag||!ie(i,r,a.length,a.length+s.length))return!1;let l=!1;return re(i,m=>{l||=Os(m.tagName,m.attrs)}),!l}var vs=(t,e)=>Object.values(e.get(B(t,G))?.parts??{}).filter(({edit:s})=>s==="text"||s==="data").flatMap(({at:s})=>ft(t,s).filter(o=>dt(o,t))),ce={installed:{slots(t,e){let s=vs(t,e);return fs(t).filter(o=>!s.some(n=>P(o,n)))},boxes(t,e){return this.slots(t,e).map(s=>({element:s,kind:"slot",key:B(s,ae)}))},textParts(t,e){let s=e.get(B(t,G));if(oe(B(t,ne),s?.schema))return[];let o=Object.values(s?.parts??{}).filter(({edit:r})=>r==="text"),n=ct(t,e).map(([,r])=>r),a=[...new Set(o.flatMap(({at:r})=>ft(t,r)))].filter(r=>r.sourceCodeLocation&&!lt(r)&&!ms.has(r.tagName)&&dt(r,t)).filter(r=>!n.some(i=>i===r||P(r,i)||P(i,r)));return a.filter(r=>!a.some(i=>P(r,i))).map(r=>({kind:"installed",part:r}))},source({package:t,html:e,children:s,boxKeys:o,from:n},{packages:a,written:r}){if(typeof t!="string"||!se.test(t))return null;let i=s!==void 0;if(i&&!(Array.isArray(s)&&Array.isArray(o)&&o.length===s.length)||n!=null&&(typeof n!="string"||!bs.test(n)))return null;let f=e===void 0?a.has(t)?Ct(a.get(t)):null:e,l=typeof f=="string"?nt(f,t):null;if(l&&(typeof n=="string"||n===null&&B(l.root,it)!==void 0)&&(l.root.attrs=[...l.root.attrs.filter(({name:L})=>L!==it),...n===null?[]:[{name:it,value:n}]],l=nt(Lt(l.root),t)),!l)return null;let m=us(l.root),u=L=>!L.childNodes.every(N=>N.nodeName==="#text"&&!N.value.trim());if((e!==void 0||!i)&&m.some(u)||i&&!o.every(L=>m.some(N=>B(N,ae)===L)))return null;if(e!==void 0){let L=!1;if(re({childNodes:[l.root]},N=>{L||=Ns(N.tagName,N.attrs)}),L)return null}let v=m.map(L=>L.sourceCodeLocation).sort((L,N)=>N.startOffset-L.startOffset).reduce((L,{startTag:N,endTag:b})=>L.slice(0,N.endOffset)+L.slice(b.startOffset),l.markup);return r(i?v:l.markup)},unwritten:({package:t,html:e},{packages:s})=>e===void 0&&se.test(t)&&!s.has(t)?"no-package":"invalid",definition:(t,e)=>e.get(B(t,G))?.definition,dataOf(t,e,s){let o=ct(e,s).filter(([,n])=>n.sourceCodeLocation.endTag);return o.length>0?Object.fromEntries(o.map(([n,a])=>[n,t.slice(a.sourceCodeLocation.startTag.endOffset,a.sourceCodeLocation.endTag.startOffset)])):null},rewrite(t,e,s,{packages:o}){let n=new Map(ct(e,o)),a=Object.keys(s),r=a.map(f=>s[f]);if(oe(B(e,ne),o.get(B(e,G))?.schema)||a.length===0||!r.every(f=>typeof f=="string")||!a.every(f=>n.has(f))||r.reduce((f,l)=>f+Buffer.byteLength(l),0)>ps||!a.every(f=>n.get(f).sourceCodeLocation.endTag&&Ls(t,n.get(f),s[f])))return null;let i=t.includes(`\r
|
|
2
|
+
import{g as St,r as nt,t as Ct}from"./chunk-VG5JEIUQ.mjs";import{a as Lt,b as st,c as z,e as vt}from"./chunk-N3DSBH5S.mjs";import{createHash as Ee}from"node:crypto";import{BLOCK_LEVEL as ot}from"../browser/shared/html-tree.mjs";var wt=t=>Ee("sha256").update(t).digest("hex").slice(0,16),M=t=>t.nodeName==="#text"&&!t.value.trim();function at(t,e){for(let s of t.childNodes??[]){if(s.tagName===e)return s;let o=s.tagName&&at(s,e);if(o)return o}return null}import{ATTRIBUTES as an,BOX_CLASSES as on,COMPONENT_ATTRIBUTES as rn,COMPONENT_CLASSES as cn,GROUPING as ln,IDENTITY as R,TOGGLES as fn,UNIT_KINDS as dn}from"../browser/editor/components/registry.mjs";import{attr as I,hasClass as kt}from"../browser/shared/html-tree.mjs";import{idsNamed as un}from"../browser/shared/copy-ids.mjs";import{DIALOG as pn,PAGE as mn,SECTION as gn,SHEETS as K,TABLE as Le}from"../browser/editor/components/kit.mjs";import{matchesNode as q,partOf as bt}from"../browser/shared/components/index.mjs";import{escapeMarkup as V}from"../browser/shared/escape.mjs";import{imageFile as Ae}from"../browser/shared/media.mjs";import{emptyFigure as Ie}from"../browser/editor/components/media/write.mjs";var _e=t=>typeof t=="string"&&t.length<=2e3&&/^https?:\/\/[^\s"<>]+$/.test(t),Et=(t,e)=>typeof t=="string"&&t.length<=e&&!/[\u0000-\u001f]/.test(t),At=t=>t.href===""&&!t.title&&!t.description&&!t.icon&&!t.cover&&t.caption==="",It=t=>t==null||Ae(t),_t={bookmark:{check:(t,{validLeaf:e})=>At(t)||_e(t.href)&&Et(t.title,300)&&Et(t.description??"",600)&&It(t.icon)&&It(t.cover)&&typeof t.caption=="string"&&(t.caption===""||e({tag:"figcaption"},t.caption)),write(t,e){if(At(t))return Ie("bookmark",e);let s=t.title.trim()||new URL(t.href).hostname,o=[`<span class="doc-bookmark-title">${V(s)}</span>`,t.description?`<span class="doc-bookmark-description">${V(t.description)}</span>`:"",`<span class="doc-bookmark-url">${t.icon?`<img class="doc-bookmark-icon" src="${t.icon}" alt="">`:""}<span class="doc-bookmark-href">${V(t.href)}</span></span>`].join(""),n=t.cover?`<span class="doc-bookmark-cover"><img src="${t.cover}" alt=""></span>`:"",a=`<a class="doc-bookmark-card" href="${V(t.href)}" target="_blank" rel="noopener noreferrer"><span class="doc-bookmark-text">${o}</span>${n}</a>`;return e.block(`<figure class="doc-bookmark"${e.id}>`,[a,`<figcaption>${t.caption}</figcaption>`],"</figure>")}}};import{BLOCK_TYPES as Be,sizeValue as Me}from"../browser/editor/components/registry.mjs";import{LINE_START as Mt,lineStart as je}from"../browser/shared/code-lines.mjs";import{hasClass as Bt}from"../browser/shared/html-tree.mjs";import{CODE_HEIGHT as rt,FOLDED_LINES as jt,validFolded as Re,validLanguage as De}from"../browser/editor/components/code/index.mjs";var ze=(t,e,s,o,n="",a="",r="",i="")=>`<div class="${t.className}"${s?` data-language="${s}"`:""}${i?` ${Mt}="${i}"`:""}${r?` ${jt}="${r}"`:""}${o?` style="${rt}: ${o}"`:""}${n}><div class="doc-code-title">${a}</div><pre><code>${e}</code></pre></div>`,Ue=(t,e)=>t==="data-language"||t===jt||t===Mt||t==="style"&&new RegExp(`^\\s*${rt}\\s*:[^;]*;?\\s*$`).test(e??""),We=t=>typeof t=="string"&&t.length<=200&&!/[<>\n]|&(?!(amp|lt|gt|quot|#39);)/.test(t),Fe=t=>(t.language===void 0||De(t.language))&&(t.folded===void 0||Re(t.folded))&&(t.height===void 0||Me("code",rt,t.height)===t.height)&&(t.title===void 0||We(t.title))&&(t.lineStart===void 0||typeof t.lineStart=="string"&&String(je(t.lineStart))===t.lineStart);function Ke(t){let{node:e}=t;if(t.tag!=="div"||t.nested||!Bt(e,Be.code.className))return!1;let s=(n,a)=>{let r=n.childNodes??[],i=r.filter(f=>f.tagName);return i.length===a.length&&i.every((f,l)=>f.tagName===a[l])&&r.every(f=>f.tagName||!(f.value??"").trim())?i:null},o=s(e,["div","pre"]);return!!o&&Bt(o[0],"doc-code-title")&&!!s(o[1],["code"])}var Rt={code:{fields:["language","folded","height","title","lineStart"],check:Fe,leaf:(t,e,s)=>ze(t,e.html,e.language,e.height,s,e.title,e.folded,e.lineStart),written:Ke,attribute:Ue}};import{sizeValue as He}from"../browser/editor/components/registry.mjs";import{MIN_COLUMNS as Pe,RATIO as Dt}from"../browser/editor/components/columns/index.mjs";var zt={columns:{check:t=>t.children.length>=Pe&&t.children.every(e=>e.type==="column")},column:{check:t=>t.ratio===void 0||He("column",Dt,t.ratio)===t.ratio,write(t,e){let s=t.ratio===void 0?"":` style="${Dt}: ${t.ratio}"`;return e.block(`<div class="doc-column"${s}${e.id}>`,e.children(e.inner),"</div>")}}};var Ut={details:{empty:!0,check:(t,{validLeaf:e})=>t.title===""||e({tag:"span"},t.title),write(t,e){let s=e.inner===null?null:e.inner+e.step,o=e.block('<div class="doc-details-content">',e.children(s),"</div>",e.inner,s),n=t.classes?.length?` ${t.classes.join(" ")}`:"";return e.block(`<details class="doc-details${n}"${e.id}>`,[`<summary><span class="doc-details-summary-label">${t.title}</span></summary>`,t.children.length>0?o:'<div class="doc-details-content"></div>'],"</details>")}}};var Wt={dialog:{empty:!0,check(t,{usedIds:e}){return typeof t.id!="string"||!/^[A-Za-z][\w-]{0,63}$/.test(t.id)||e.has(t.id)?!1:(e.add(t.id),!0)},write(t,e){let s=t.children.length>0?e.block('<div class="doc-dialog-content">',e.children(e.deep(3)),"</div>",e.deep(2),e.deep(3)):'<div class="doc-dialog-content"></div>',o=e.block('<div class="doc-dialog-panel">',[s],"</div>",e.deep(1),e.deep(2));return e.block(`<dialog class="doc-dialog" id="${t.id}">`,[o],"</dialog>")}}};import{escapeAttribute as Ge}from"../browser/shared/escape.mjs";import{embedFile as Ft}from"../browser/shared/media.mjs";import{emptyFigure as qe}from"../browser/editor/components/media/write.mjs";import{FILE_SANDBOX as Ve,WEB_SANDBOX as Xe}from"../browser/editor/components/embed/index.mjs";var Ye=t=>typeof t=="string"&&t.length<=2e3&&/^https:\/\/[^\s"<>]+$/.test(t),Kt=t=>t.src===""&&t.height===void 0&&t.caption==="",Ht={embed:{check:(t,{validLeaf:e})=>Kt(t)||(Ye(t.src)||Ft(t.src))&&(t.height===void 0||/^\d{2,4}px$/.test(t.height))&&typeof t.caption=="string"&&(t.caption===""||e({tag:"figcaption"},t.caption)),write(t,e){if(Kt(t))return qe("embed",e);let s=Ft(t.src),o=s?/\.pdf$/i.test(t.src)?"":` sandbox="${Ve}"`:` sandbox="${Xe}" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen`,n=`<iframe class="doc-embed-frame" src="${Ge(t.src)}"${o} loading="lazy"></iframe>`,a=t.height?` style="--doc-embed-height: ${t.height}"`:"";return e.block(`<figure class="doc-embed${s?" doc-embed--file":""}"${a}${e.id}>`,[n,`<figcaption>${t.caption}</figcaption>`],"</figure>")}}};import{escapeMarkup as Pt}from"../browser/shared/escape.mjs";import{assetFile as Ze}from"../browser/shared/media.mjs";import{emptyFigure as Je}from"../browser/editor/components/media/write.mjs";var Gt=t=>t.href===""&&t.name===""&&t.size===void 0&&t.caption==="",Qe=t=>typeof t=="string"&&t.trim()!==""&&t.length<=120&&!/[\u0000-\u001f<>:"/\\|?*]/.test(t),qt={file:{check:(t,{validLeaf:e})=>Gt(t)||Ze(t.href)&&Qe(t.name)&&(t.size===void 0||/^\d+(\.\d)? (B|KiB|MiB|GiB)$/.test(t.size))&&typeof t.caption=="string"&&(t.caption===""||e({tag:"figcaption"},t.caption)),write(t,e){if(Gt(t))return Je("file",e);let s=t.size?`<span class="doc-file-size">${t.size}</span>`:"",o=`<a class="doc-file-link" href="${t.href}" download="${Pt(t.name)}"><span class="doc-file-name">${Pt(t.name)}</span>${s}</a>`;return e.block(`<figure class="doc-file"${e.id}>`,[o,`<figcaption>${t.caption}</figcaption>`],"</figure>")}}};import{FLOW as ts,FLOW_DIRECTION as Vt,FLOW_RATIO as Xt}from"../browser/editor/components/flowchart/index.mjs";import{START as es,validDirection as Yt,validStart as ss}from"../browser/editor/components/list/index.mjs";import{sizeValue as ns,TOGGLES as as}from"../browser/editor/components/registry.mjs";var Zt={flowchart:{check:t=>(t.start===void 0||ss(t.start))&&(t.direction===void 0||Yt(t.direction))&&t.children.length>0,write:(t,e)=>e.block(`<ol class="${ts}"${t.start?` ${es}="${t.start}"`:""}${t.direction?` ${Vt}="${t.direction}"`:""}${e.id}>`,e.children(e.inner),"</ol>")},step:{check:t=>(t.classes===void 0||Array.isArray(t.classes)&&new Set(t.classes).size===t.classes.length&&t.classes.every(e=>(as.step??[]).includes(e)))&&(t.ratio===void 0||ns("step",Xt,t.ratio)===t.ratio)&&(t.direction===void 0||Yt(t.direction))&&t.children.length>0,write(t,e){let s=t.classes?.length?` class="${t.classes.join(" ")}"`:"",o=t.direction?` ${Vt}="${t.direction}"`:"",n=t.ratio===void 0?"":` style="${Xt}: ${t.ratio}"`;return e.block(`<li${s}${o}${n}${e.id}>`,e.children(e.inner),"</li>")}}};import{SPAN as os,SPAN_SIZE as Jt,imageFile as Qt}from"../browser/shared/media.mjs";import{emptyFigure as rs}from"../browser/editor/components/media/write.mjs";var is=/^\d{1,3}(\.\d{1,3})?( \d{1,3}(\.\d{1,3})?){3}$/,te=t=>t.src===""&&t.caption===""&&t.span===void 0&&t.original===void 0&&t.classes===void 0,cs=t=>typeof t=="number"&&Number.isFinite(t)&&t>=Jt.min&&t<=Jt.max,ee={image:{check:(t,{validLeaf:e})=>te(t)||Qt(t.src)&&typeof t.caption=="string"&&(t.caption===""||e({tag:"figcaption"},t.caption))&&(t.span===void 0||cs(t.span))&&(t.original===void 0||Qt(t.original)&&typeof t.crop=="string"&&is.test(t.crop)),write(t,e){if(te(t))return rs("image",e);let s=["doc-image",...t.classes??[]].join(" "),o=t.span===void 0?"":` style="${os}: ${Math.round(t.span*1e3)/1e3}"`,n=t.original===void 0?"":` data-original="${t.original}" data-crop="${t.crop}"`;return e.block(`<figure class="${s}"${o}${e.id}>`,[`<img src="${t.src}" alt=""${n}>`,`<figcaption>${t.caption}</figcaption>`],"</figure>")}}};vt();import{heldByNode as ls,instanceSlots as fs,isInstance as lt,isSlot as ds,ownSlots as us,partOf as ft}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as G,DATA_MOST as ps,NO_TEXT as ms,PACKAGE_ID as se,SCHEMA as ne,SLOT as ae,fitsDataScript as gs,isDataScript as hs,noDataPart as $s,refusedInCopy as Ns,refusedInData as Os,schemaAhead as oe}from"../browser/shared/components/installed.mjs";import{attr as B,walk as re}from"../browser/shared/html-tree.mjs";import{CHART_KEY as bs,VIEW_FROM as it}from"../browser/shared/table-chart.mjs";var P=(t,e)=>{for(let s=t.parentNode;s;s=s.parentNode)if(s===e)return!0;return!1},xs=t=>{let e=t.parentNode;for(;e&&!lt(e);)e=e.parentNode;return e??null},dt=(t,e)=>xs(t)===e&&ls(t)===e&&!ds(t);function ct(t,e){let o=Object.entries(e.get(B(t,G))?.parts??{}).filter(([,{edit:n}])=>n==="data").map(([n,{at:a}])=>[n,ft(t,a).find(r=>r.sourceCodeLocation&&!lt(r)&&dt(r,t))]).filter(([,n])=>n);return o.filter(([,n],a)=>!o.some(([,r],i)=>P(n,r)||r===n&&i<a))}var ys=new Set(["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"]),ks="http://www.w3.org/1999/xhtml",Ts=t=>(t.content??t).childNodes;function ie(t,e,s,o){let n=s;for(let a of Ts(t)){let r=a.sourceCodeLocation;if(r?.startOffset!==n)return!1;if(a.tagName){let{startTag:i,endTag:f}=r,l=ys.has(a.tagName)||a.namespaceURI!==ks&&e.startsWith("/>",r.endOffset-2);if(f?!ie(a,e,i.endOffset,f.startOffset):!l)return!1}n=r.endOffset}return n===o}function Ls(t,e,s){if(e.tagName==="script")return hs(e.tagName,e.attrs)&&gs(s);if($s(e.tagName))return!1;let{startTag:o,endTag:n}=e.sourceCodeLocation,a=t.slice(o.startOffset,o.endOffset),r=`${a}${s}${t.slice(n.startOffset,n.endOffset)}`,[i,...f]=z(e.parentNode,r,{sourceCodeLocationInfo:!0}).childNodes;if(f.length>0||i?.tagName!==e.tagName||i.sourceCodeLocation?.endOffset!==r.length||!i.sourceCodeLocation.endTag||!ie(i,r,a.length,a.length+s.length))return!1;let l=!1;return re(i,m=>{l||=Os(m.tagName,m.attrs)}),!l}var vs=(t,e)=>Object.values(e.get(B(t,G))?.parts??{}).filter(({edit:s})=>s==="text"||s==="data").flatMap(({at:s})=>ft(t,s).filter(o=>dt(o,t))),ce={installed:{slots(t,e){let s=vs(t,e);return fs(t).filter(o=>!s.some(n=>P(o,n)))},boxes(t,e){return this.slots(t,e).map(s=>({element:s,kind:"slot",key:B(s,ae)}))},textParts(t,e){let s=e.get(B(t,G));if(oe(B(t,ne),s?.schema))return[];let o=Object.values(s?.parts??{}).filter(({edit:r})=>r==="text"),n=ct(t,e).map(([,r])=>r),a=[...new Set(o.flatMap(({at:r})=>ft(t,r)))].filter(r=>r.sourceCodeLocation&&!lt(r)&&!ms.has(r.tagName)&&dt(r,t)).filter(r=>!n.some(i=>i===r||P(r,i)||P(i,r)));return a.filter(r=>!a.some(i=>P(r,i))).map(r=>({kind:"installed",part:r}))},source({package:t,html:e,children:s,boxKeys:o,from:n},{packages:a,written:r}){if(typeof t!="string"||!se.test(t))return null;let i=s!==void 0;if(i&&!(Array.isArray(s)&&Array.isArray(o)&&o.length===s.length)||n!=null&&(typeof n!="string"||!bs.test(n)))return null;let f=e===void 0?a.has(t)?Ct(a.get(t)):null:e,l=typeof f=="string"?nt(f,t):null;if(l&&(typeof n=="string"||n===null&&B(l.root,it)!==void 0)&&(l.root.attrs=[...l.root.attrs.filter(({name:L})=>L!==it),...n===null?[]:[{name:it,value:n}]],l=nt(Lt(l.root),t)),!l)return null;let m=us(l.root),u=L=>!L.childNodes.every(N=>N.nodeName==="#text"&&!N.value.trim());if((e!==void 0||!i)&&m.some(u)||i&&!o.every(L=>m.some(N=>B(N,ae)===L)))return null;if(e!==void 0){let L=!1;if(re({childNodes:[l.root]},N=>{L||=Ns(N.tagName,N.attrs)}),L)return null}let v=m.map(L=>L.sourceCodeLocation).sort((L,N)=>N.startOffset-L.startOffset).reduce((L,{startTag:N,endTag:b})=>L.slice(0,N.endOffset)+L.slice(b.startOffset),l.markup);return r(i?v:l.markup)},unwritten:({package:t,html:e},{packages:s})=>e===void 0&&se.test(t)&&!s.has(t)?"no-package":"invalid",definition:(t,e)=>e.get(B(t,G))?.definition,dataOf(t,e,s){let o=ct(e,s).filter(([,n])=>n.sourceCodeLocation.endTag);return o.length>0?Object.fromEntries(o.map(([n,a])=>[n,t.slice(a.sourceCodeLocation.startTag.endOffset,a.sourceCodeLocation.endTag.startOffset)])):null},rewrite(t,e,s,{packages:o}){let n=new Map(ct(e,o)),a=Object.keys(s),r=a.map(f=>s[f]);if(oe(B(e,ne),o.get(B(e,G))?.schema)||a.length===0||!r.every(f=>typeof f=="string")||!a.every(f=>n.has(f))||r.reduce((f,l)=>f+Buffer.byteLength(l),0)>ps||!a.every(f=>n.get(f).sourceCodeLocation.endTag&&Ls(t,n.get(f),s[f])))return null;let i=t.includes(`\r
|
|
3
3
|
`)?`\r
|
|
4
4
|
`:`
|
|
5
5
|
`;return a.map(f=>{let{startTag:l,endTag:m}=n.get(f).sourceCodeLocation;return{start:l.endOffset,end:m.startOffset,text:s[f].replace(/\r?\n/g,i)}})}}};vt();import{IDENTITY as Ss}from"../browser/editor/components/registry.mjs";import{SHEETS as X,TABLE as le}from"../browser/editor/components/kit.mjs";import{escapeAttribute as Y,escapeText as ut}from"../browser/shared/escape.mjs";import{isInstance as Cs,matchesNode as pt}from"../browser/shared/components/index.mjs";import{attr as j}from"../browser/shared/html-tree.mjs";import{CHART_SOURCE as fe,TABLE_READERS as ws}from"../browser/shared/table-chart.mjs";import{freshPrefix as Es,referencedIds as As,rewrite as Is}from"../browser/shared/copy-ids.mjs";var de=(t={})=>Object.entries(t).map(([e,s])=>s===""?` ${e}`:` ${e}="${Y(String(s))}"`).join(""),ue=(t,e)=>t[e-1]==="/"?e-1:e;function Z(t,e,s){let o=e;for(;o>0&&/\s/.test(t[o-1]);)o--;return{start:o,end:s}}function Sa(t){let e=s=>s.nodeName==="#text"?s.value:(s.childNodes??[]).map(e).join("");return e(z(t)).replace(/\s+/g," ").trim()}function Ca(t,{from:e,to:s}){let n=pe(st(t,{sourceCodeLocationInfo:!0}))?.sourceCodeLocation;if(!n?.endTag)return null;let a=t.slice(n.startTag.endOffset,n.endTag.startOffset);if(!e)return a.trim()===""?{start:n.startTag.endOffset,end:n.endTag.startOffset,text:ut(s)}:null;let r=ut(e),i=a.indexOf(r);if(i<0||a.indexOf(r,i+1)>=0)return null;let f=n.startTag.endOffset+i;return{start:f,end:f+r.length,text:ut(s)}}function pe(t){for(let e of t.childNodes??[]){if(e.tagName==="title")return e;if(e.tagName==="body")continue;let s=e.tagName&&pe(e);if(s)return s}return null}function _s(t){let e=[],s=0,o=null,n=0;for(let a=0;a<t.length;a++){let r=t[a];if(r==="&"){let i=/^&(#\d+|#x[\da-f]+|[a-z]\w*);/i.exec(t.slice(a));i&&(a+=i[0].length-1)}else o?r===o?o=null:r==="\\"&&a++:r==='"'||r==="'"?o=r:r==="("?s++:r===")"?s=Math.max(0,s-1):r===";"&&s===0&&(e.push(t.slice(n,a)),n=a+1)}return e.push(t.slice(n)),e.map(a=>a.trim()).filter(Boolean)}function ht(t,e){let s=_s(t);for(let[o,n]of e){let a=s.findIndex(r=>r.slice(0,r.indexOf(":")).trim()===o);n===null?a>=0&&s.splice(a,1):a>=0?s[a]=`${o}: ${n}`:s.push(`${o}: ${n}`)}return s.join("; ")}var Bs=new Set(["pre","textarea","script","style"]);function wa(t){if(typeof t!="string"||!t.trim())return null;let s=z(t,{sourceCodeLocationInfo:!0}).childNodes.filter(f=>f.nodeName!=="#comment"&&!(f.nodeName==="#text"&&!f.value.trim())),[o,n]=s;if(s.length===2&&o.tagName==="button"&&pt(o,X.tab)&&n.tagName&&n.sourceCodeLocation?.endTag&&j(o,X.tabKey)&&j(n,X.panelKey)===j(o,X.tabKey)){let f=o.sourceCodeLocation.endOffset;return{element:o,source:t.slice(0,f),panel:t.slice(f).replace(/^\s+/,""),kind:"tab"}}let a=s.at(-1),r=s.length===2?s[0]:null;if(!a?.tagName||!a.sourceCodeLocation?.startTag||s.length>2||r&&!(r.tagName&&pt(r,le.lead)&&pt(a,le.frame)))return null;let i=W(a);return{element:a,source:t,kind:i}}function Ms(t){let e=[],s=o=>{for(let n of o.childNodes??[]){if(!n.tagName)continue;let a=j(n,"id");a&&e.push(a),s(n.tagName==="template"?n.content:n)}};return s(st(t)),e}var Ea=(t,e)=>`${mt(t.slice(e.start,e.end),U(t,e.start),"")}
|
|
@@ -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 Rn}from"./chunk-DR73Y2UJ.mjs";import{b as Tn}from"./chunk-CG3UHDKH.mjs";import{a as jn,i as _n,j as Pn}from"./chunk-4AMTKWDO.mjs";import{a as On,b as Cn}from"./chunk-QXVNUASA.mjs";import{k as Ge}from"./chunk-FCK6NXON.mjs";import{h as vn}from"./chunk-OU3S466R.mjs";import{a as $n}from"./chunk-CZ5KJSGK.mjs";import{a as En}from"./chunk-UGO5N3EI.mjs";import{a as Sn,b as bn}from"./chunk-5IIH335D.mjs";import{a as xn}from"./chunk-2OHANJ6Q.mjs";import{a as hn,b as Ke,d as gn,e as wn,f as yn,g as kn}from"./chunk-7M2BQQGZ.mjs";import{b as pt,e as Yt,g as ht,h as Xt,j as Vt,k as Zt}from"./chunk-VKSRM7EY.mjs";import{a as Wt,d as Mt,e as Ut,f as Bt,k as zt,l as Ht,m as Gt,r as Kt,t as ut,u as Jt}from"./chunk-LE44MD3O.mjs";import{b as sn,c as cn,d as je,e as ln,f as dn,g as He,i as fn,m as mn,p as un,q as pn}from"./chunk-XMKHCUI6.mjs";import{d as rn,e as Fe,f as Be,g as gt,h as an,k as ze}from"./chunk-YFJU3O7G.mjs";import{b as Qt,c as qt}from"./chunk-NWRZXELO.mjs";import{i as tn,j as nn,k as on}from"./chunk-G4YP7GVC.mjs";import{d as en}from"./chunk-DHB7UZ7F.mjs";import{a as Ne}from"./chunk-7XDYK3UC.mjs";import{c as ft,g as ae,j as At,k as Dt,p as Lt,q as It,v as Nt,w as mt}from"./chunk-VG5JEIUQ.mjs";import ct from"node:fs";import ms from"node:fs/promises";import us from"node:http";import{editStateDirectory as ps,kitPublicDirectory as hs,release as gs,releaseFile as lt,reportsDirectory as Te,vendorDirectory as ws,workbenchDirectory as ys}from"../browser/shared/paths.mjs";import{serve as Go}from"../browser/shared/http.mjs";import{ensureWorkspace as ks,layoutOf as vs}from"../browser/shared/workspace.mjs";import ge from"node:fs/promises";import H from"node:path";import{assetFile as Vo,referencedFile as Fn}from"../browser/shared/media.mjs";import{pageAssetAddress as Zo}from"../browser/shared/pages.mjs";function wt(e,n){if(!/assets\//i.test(e))return e;let t=nn(e,r=>Fn(r)!==null);return tn(e,on(t,r=>{let s=Fn(r.value);return Vo(s)?`${Zo(n,s)}${/[?#].*$/.exec(r.value.trim())?.[0]??""}`:null}))}function An(e,{reportsDirectory:n,kit:t,slug:r=null}={}){let{html:s,packages:f}=dn(r?wt(e,r):e,{reportsDirectory:n,kit:t,page:!0});return{html:s,packages:f}}import{Z as Qo}from"../browser/shared/layers.mjs";import{escapeMarkup as yt}from"../browser/shared/escape.mjs";import{layoutNotesScript as qo}from"../browser/shared/qa-levels.mjs";var Je=30,er=`
|
|
3
|
+
[data-doc-dev].doc-checks { position: fixed; z-index: ${Qo.checks}; left: 12px; bottom: 12px; max-width: min(520px, calc(100vw - 24px));
|
|
4
|
+
font: 13px/1.5 system-ui, sans-serif; color: light-dark(#37352f, #e3e2e0); }
|
|
5
|
+
[data-doc-dev].doc-checks[hidden] { display: none; }
|
|
6
|
+
[data-doc-dev].doc-checks > summary { display: inline-flex; gap: 6px; align-items: center; padding: 4px 10px; border-radius: 999px; cursor: pointer;
|
|
7
|
+
list-style: none; color: light-dark(#a1352b, #f19c92); background: light-dark(#fce9e7, #3b2321);
|
|
8
|
+
box-shadow: 0 0 0 1px light-dark(rgb(161 53 43 / 18%), rgb(241 156 146 / 22%)); user-select: none; }
|
|
9
|
+
[data-doc-dev].doc-checks > summary::-webkit-details-marker { display: none; }
|
|
10
|
+
[data-doc-dev].doc-checks > div { margin-top: 6px; padding: 8px 12px; max-height: 50vh; overflow: auto; border-radius: 10px;
|
|
11
|
+
background: light-dark(#ffffff, #252525); box-shadow: 0 0 0 1px light-dark(rgb(42 28 0 / 7%), #383836), 0 20px 24px light-dark(rgb(25 25 25 / 5%), rgb(0 0 0 / 20%)); }
|
|
12
|
+
[data-doc-dev].doc-checks ul { margin: 0; padding-left: 18px; }
|
|
13
|
+
[data-doc-dev].doc-checks li { margin: 2px 0; overflow-wrap: anywhere; }
|
|
14
|
+
[data-doc-dev].doc-checks p { margin: 6px 0 0; color: light-dark(#787774, #9b9a97); }
|
|
15
|
+
[data-doc-dev].doc-checks .doc-checks-live:not(:first-child) { margin-top: 8px; }
|
|
16
|
+
@media print { [data-doc-dev].doc-checks { display: none; } }`,tr=`(() => {
|
|
17
|
+
document.currentScript.remove();
|
|
18
|
+
${qo()}
|
|
19
|
+
const panel = document.querySelector("details.doc-checks[data-doc-dev]");
|
|
20
|
+
if (!panel) return;
|
|
21
|
+
const failures = Number(panel.dataset.failures) || 0;
|
|
22
|
+
const live = panel.querySelector(".doc-checks-live ul");
|
|
23
|
+
// The note's words in the UI's language (the root's data-ge-language).
|
|
24
|
+
const english = document.documentElement.getAttribute("data-ge-language") === "en";
|
|
25
|
+
const WORDS = english
|
|
26
|
+
? { card: "Chart card", table: "Table", named: (kind, name) => kind + " \u201C" + name + "\u201D", first: (name) => "Table (first column \u201C" + name + "\u201D)", colon: ": ",
|
|
27
|
+
failing: (count) => "Checks failed \xB7 " + count, more: (count) => count + " more", all: (slug) => "gallery check " + slug + " runs every check (TypeScript too)." }
|
|
28
|
+
: { card: "\u56FE\u8868\u5361\u7247", table: "\u8868\u683C", named: (kind, name) => kind + "\u300C" + name + "\u300D", first: (name) => "\u8868\u683C\uFF08\u9996\u5217\u300C" + name + "\u300D\uFF09", colon: "\uFF1A",
|
|
29
|
+
failing: (count) => "\u68C0\u67E5\u672A\u901A\u8FC7 \xB7 " + count + " \u9879", more: (count) => "\u8FD8\u6709 " + count + " \u9879", all: (slug) => "gallery check " + slug + " \u8DD1\u5168\u90E8\u68C0\u67E5\uFF08\u542B TypeScript\uFF09\u3002" };
|
|
30
|
+
const more = panel.querySelector("[data-more]");
|
|
31
|
+
if (more) more.textContent = WORDS.more(more.dataset.more);
|
|
32
|
+
const all = panel.querySelector("[data-all]");
|
|
33
|
+
if (all) all.textContent = WORDS.all(all.dataset.all);
|
|
34
|
+
const tidy = (node) => (node?.textContent ?? "").replace(/\\s+/g, " ").trim().slice(0, 40);
|
|
35
|
+
const what = (host) => {
|
|
36
|
+
const card = host.closest("figure");
|
|
37
|
+
const title = card?.querySelector(":scope > h3, :scope > figcaption");
|
|
38
|
+
const table = host.closest(".doc-table-wrap, table");
|
|
39
|
+
const caption = table?.querySelector("caption");
|
|
40
|
+
const header = table?.querySelector("th");
|
|
41
|
+
return title ? WORDS.named(WORDS.card, tidy(title)) : card ? WORDS.card : caption && tidy(caption) ? WORDS.named(WORDS.table, tidy(caption)) : header ? WORDS.first(tidy(header)) : host.localName;
|
|
42
|
+
};
|
|
43
|
+
// A chart that drew nothing says why in its card (the kit's line, in the same language): that line, else the note in words.
|
|
44
|
+
const said = (host, name, note) => (name === "data-missing" && tidy(host.querySelector(".doc-chart-message"))) || noteInWords(note, { english });
|
|
45
|
+
let shown = "";
|
|
46
|
+
let frame = 0;
|
|
47
|
+
const draw = () => {
|
|
48
|
+
frame = 0;
|
|
49
|
+
const notes = [...document.querySelectorAll("[data-doc-layout]")].filter((host) => !host.closest("[data-doc-dev]"))
|
|
50
|
+
.flatMap((host) => layoutNotesOf(host.getAttribute("data-doc-layout"), document.documentElement.clientWidth)
|
|
51
|
+
.filter(({ level }) => level === "fail")
|
|
52
|
+
.map(({ note, name }) => ({ line: what(host) + WORDS.colon + said(host, name, note), note })));
|
|
53
|
+
const key = notes.map(({ line }) => line).join("\\n");
|
|
54
|
+
if (key === shown) return;
|
|
55
|
+
shown = key;
|
|
56
|
+
live.replaceChildren(...notes.map(({ line, note }) => Object.assign(document.createElement("li"), { textContent: line, title: note })));
|
|
57
|
+
live.parentElement.hidden = notes.length === 0;
|
|
58
|
+
const failing = failures + notes.length;
|
|
59
|
+
panel.querySelector("summary").textContent = failing ? WORDS.failing(failing) : "";
|
|
60
|
+
panel.hidden = failing === 0;
|
|
61
|
+
};
|
|
62
|
+
const later = (records) => {
|
|
63
|
+
if (!globalThis.document?.defaultView) return; // the page is gone
|
|
64
|
+
if (!frame && records.some((record) => !record.target.closest?.("[data-doc-dev]"))) frame = requestAnimationFrame(draw);
|
|
65
|
+
};
|
|
66
|
+
new MutationObserver(later).observe(document.documentElement, { subtree: true, childList: true, attributes: true, attributeFilter: ["data-doc-layout"] });
|
|
67
|
+
addEventListener("resize", () => { if (!frame) frame = requestAnimationFrame(draw); });
|
|
68
|
+
draw();
|
|
69
|
+
})();`;function Dn(e,n,t={},{directory:r}={}){let s=fn({slug:e,html:n,metadata:t,...r?{directory:r}:{}}),f=s.slice(0,Je).map(p=>`<li>${yt(p)}</li>`).join(""),a=s.length>Je?`<p data-more="${s.length-Je}">\u8FD8\u6709 ${s.length-Je} \u9879</p>`:"",m=s.length?`<ul>${f}</ul>${a}<p data-all="${yt(e)}">gallery check ${yt(e)} \u8DD1\u5168\u90E8\u68C0\u67E5\uFF08\u542B TypeScript\uFF09\u3002</p>`:"";return`<details class="doc-checks" data-doc-dev data-failures="${s.length}"${s.length?"":" hidden"}><summary>${s.length?`\u68C0\u67E5\u672A\u901A\u8FC7 \xB7 ${s.length} \u9879`:""}</summary><div>${m}<div class="doc-checks-live" hidden><ul></ul></div></div><style>${er}</style></details>
|
|
70
|
+
<script data-doc-dev>${tr}</script>`}import{browserDirectory as Ea,editStateDirectory as Oa,kitSourceDirectory as Lo,release as Ca,reportsDirectory as D}from"../browser/shared/paths.mjs";import{FRAMED_BY as ja,sendJson as $o,serve as Tt,serveFound as De}from"../browser/shared/http.mjs";import{languageScript as So}from"../browser/shared/i18n/index.mjs";import{announcePreviewServer as _a,galleryVersion as Pa,sameDirectory as Ta}from"../browser/shared/preview-server.mjs";import{registerQuietly as Ra}from"../browser/shared/workspace-registry.mjs";import{lookWord as bo}from"../browser/shared/document-look.mjs";import{documentLook as Eo,ownLookAt as Fa}from"../browser/shared/workspace-look.mjs";import{slugPattern as Io}from"../browser/shared/reports.mjs";import{ATTRIBUTE as at,PACKAGE_ID as Aa}from"../browser/shared/components/installed.mjs";import{COMPONENTS_FOLDER as Oo,DOCUMENT_FOLDERS as Co,EXTENSIONS_FOLDER as Da,PAGES_FOLDER as La,WORKSPACE_FILE as st,defaultWorkspace as Ia,documentDirectory as _t,documentFiles as Na,isDocumentFile as Wa,isDocumentSource as jo,isSlugName as No,layoutOf as Rt}from"../browser/shared/workspace.mjs";import{PAGE_FILES as _o,homeCardsNew as Ma,isBlankPage as Ua,isPageFile as Ba,pageFiles as Po,pageHintShown as za,pageMetaNow as Ha,pageVersion as To}from"../browser/shared/pages.mjs";import{LINK_FILE as Ga}from"../browser/shared/web-links.mjs";import{SIDEBAR_FILE as ot}from"../browser/shared/extension-sidebar.mjs";import{extensionColumnIds as Ro}from"../browser/shared/extensions.mjs";import{isExtensionId as Ka}from"../browser/shared/outline-shape.mjs";import{createHash as hr,randomBytes as gr}from"node:crypto";import Q from"node:fs";import kt from"node:os";import he from"node:path";import{Transform as wr}from"node:stream";import{pipeline as yr}from"node:stream/promises";import{exportSourceOf as kr}from"../browser/shared/export-wrap.mjs";import{writeAtomic as vt}from"../browser/shared/files.mjs";import{sendJson as J}from"../browser/shared/http.mjs";import{said as xt,saying as vr}from"../browser/shared/i18n/index.mjs";import{IMPORT_LIMIT as Mn}from"../browser/shared/import-types.mjs";import{mediaUrl as xr}from"../browser/shared/media.mjs";import{fullAddress as $r}from"../browser/shared/page-address.mjs";import{documentLinks as Un,slugPattern as Bn}from"../browser/shared/reports.mjs";import{documentDirectory as Sr,documentFiles as zn,newDocSlug as br,pageSlug as Er}from"../browser/shared/workspace.mjs";import{readWritingPreferences as Or,saysAnything as Cr,unshownLines as jr}from"../browser/shared/writing-preferences.mjs";import Ln from"node:fs/promises";import lr from"node:path";import{Worker as nr}from"node:worker_threads";import{refusal as or,said as rr}from"../browser/shared/i18n/index.mjs";var ar=6e4,me=null,sr=0,Ye=0,_e=new Map;function ir(){me=new nr(new URL("./worker.mjs",import.meta.url)),me.on("message",({id:n,result:t,error:r})=>{let s=_e.get(n);s&&(_e.delete(n),r?s.reject(Object.assign(new Error(r.message),r)):s.resolve(t),_e.size===0&&(me?.unref(),cr()))});let e=n=>{for(let t of _e.values())t.reject(n);_e.clear(),me=null};me.on("error",e),me.on("exit",n=>e(or(rr("\u8F6C\u6362\u8FDB\u7A0B\u610F\u5916\u9000\u51FA\uFF08{0}\uFF09",n))))}function cr(){clearTimeout(Ye),Ye=setTimeout(()=>{if(_e.size===0&&me){let e=me;me=null,e.removeAllListeners("exit"),e.terminate()}},ar),Ye.unref?.()}function ve(e,n){clearTimeout(Ye),me||ir();let t=++sr;return new Promise((r,s)=>{_e.set(t,{resolve:r,reject:s}),me.ref(),me.postMessage({id:t,type:e,payload:n})})}import{pageLanguage as dr}from"../browser/shared/components/page.mjs";function Xe(e){return String(e??"").replace(/[\\/:*?"<>|\u0000-\u001f\u007f]/g," ").replace(/\s+/g," ").trim().slice(0,100).trim()||"Untitled"}function Ve(e,n){let t=e.lastIndexOf("."),[r,s]=t>0?[e.slice(0,t),e.slice(t)]:[e,""];for(let f=0;;f+=1){let a=f===0?e:`${r} ${f}${s}`;if(!n.has(a.toLowerCase()))return n.add(a.toLowerCase()),a}}function Ze(e,n){let t=e.split("/").slice(0,-1),r=n.split("/"),s=0;for(;s<t.length&&s<r.length-1&&t[s]===r[s];)s+=1;return[...t.slice(s).map(()=>".."),...r.slice(s)].map(a=>a===".."?a:encodeURIComponent(a).replace(/\(/g,"%28").replace(/\)/g,"%29")).join("/")}import{documentDirectory as fr,documentFiles as mr}from"../browser/shared/workspace.mjs";var In={markdown:"md",html:"html",pdf:"pdf"},ur={markdown:"text/markdown; charset=utf-8",html:"text/html; charset=utf-8",pdf:"application/pdf"},pr=e=>typeof e=="number"&&e>.1&&e<2;function Nn(e){let{format:n,content:t="everything",subpages:r=!1,folders:s=!0,paper:f="A4",scale:a=1}=e??{};return Object.hasOwn(In,n)&&["everything","no_files"].includes(t)&&typeof r=="boolean"&&typeof s=="boolean"&&["A4","A3","Letter","Legal","Tabloid"].includes(f)&&pr(a)}async function Wn(e,n,t){let{format:r,content:s="everything",subpages:f=!1,folders:a=!0,paper:m="A4",scale:c=1}=n,p=In[r],b=s==="everything",w=[],v=new Map,u=x=>v.get(x)??v.set(x,new Set).get(x),d=async(x,C)=>{let B=await t.titleOf(x),G=Ve(`${Xe(B)}.${p}`,u(C)),z=C?`${C}/${G}`:G,L=a?z.slice(0,-(p.length+1)):"";if(w.push({slug:x,title:B,file:z,folder:L,files:C?`${C}/assets`:"assets"}),f)for(let se of await t.childrenOf(x))await d(se,L)};await d(e,"");let{links:E}=await t.links(),$=(x,C)=>cn(C,x.slug,B=>{let G=r==="pdf"?null:w.find(z=>z.slug===B)?.file??null;return G&&Ze(x.file,G)},{blocks:r!=="markdown",links:E}),k=[],Y=[];for(let x of w)if(r==="markdown"){await t.check(x.slug);let C=fr(x.slug,t.reportsDirectory),B=je(await Ln.readFile(mr(C).html,"utf8"),{slug:x.slug,mode:"words",reportsDirectory:t.reportsDirectory}),G=$(x,B),z=b&&!!jn(),{text:L,files:se,charts:re,charted:U}=await ve("markdown",{source:G,title:x.title,pictures:z}),K=L,ce=new Map;if(se.forEach(({src:h,name:g},j)=>{ce.has(h)||(ce.set(h,`${x.files}/${Ve(Xe(g),u(x.files))}`),b&&Y.push({from:lr.join(C,h),name:ce.get(h)}));let _=ce.get(h);K=K.replace(`\0F${j}\0`,()=>Ze(x.file,_))}),z&&re>0&&K.includes("\0C")){let h=await Pn(await t.offline(x.slug,{files:!0})).catch(()=>[]);K=K.replace(/^.*\u0000C(\d+)\u0000.*$/gm,(g,j)=>{let _=h[Number(j)];if(!_)return"\0gone\0";let T=`${x.files}/${Ve(dr(G)==="en"?U[Number(j)]?"Chart.png":"Figure.png":U[Number(j)]?"\u56FE\u8868.png":"\u56FE.png",u(x.files))}`;return k.push({name:T,data:_,later:!0}),g.replace(`\0C${j}\0`,()=>Ze(x.file,T))}).replace(/\n*\u0000gone\u0000\n*/g,`
|
|
71
|
+
|
|
72
|
+
`).replace(/^\n+|\n+$/g,"")}k.push({name:x.file,data:K})}else r==="html"?k.push({name:x.file,data:$(x,await t.offline(x.slug,{files:b}))}):k.push({name:x.file,data:await _n($(x,await t.offline(x.slug,{files:b})),{paper:m,scale:c})});for(let x of Y){let C=await Ln.readFile(x.from).catch(()=>null);C&&k.push({name:x.name,data:C})}let M=[...k.filter(x=>!x.later&&w.some(C=>C.file===x.name)),...k.filter(x=>x.later||!w.some(C=>C.file===x.name))];return M.length===1?{name:M[0].name,type:ur[r],data:Buffer.isBuffer(M[0].data)?M[0].data:Buffer.from(M[0].data,"utf8")}:{name:`${Xe(w[0].title)}.zip`,type:"application/zip",data:xn(M)}}var _r=3600*1e3,$t=new Set,Hn=!1,Pr=e=>{$t.add(e),!Hn&&(Hn=!0,process.once("exit",()=>{for(let n of $t)try{Q.rmSync(n,{recursive:!0,force:!0})}catch{}}))},Tr=/^u-[a-f0-9]{16}$/;function Gn({edits:e,workspace:n,reports:t,reportsDirectory:r,offline:s}){let f=null,a=()=>f??=Q.promises.mkdtemp(he.join(kt.tmpdir(),"gallery-uploads-")).then(h=>(Pr(h),h)),m=new Map,c=(h,g,j)=>[h,{ok:!1,reason:g,...vr(j)}],p=h=>Q.promises.access(h).then(()=>!0,()=>!1),b=h=>Sr(h,r),w=h=>zn(b(h)),v=async h=>{try{return JSON.parse(await Q.promises.readFile(w(h).json,"utf8")).title||h}catch{return h}};function u(h){if(h.method!=="POST")return[405,{ok:!1,reason:"method"}];let g=h.headers.host??"",j=h.socket.localPort;return g!==`127.0.0.1:${j}`&&g!==`localhost:${j}`?[403,{ok:!1,reason:"host"}]:h.headers.origin!==`http://${g}`?[403,{ok:!1,reason:"origin"}]:h.headers["x-gallery-token"]!==e.token?[403,{ok:!1,reason:"token"}]:/^application\/octet-stream\b/i.test(h.headers["content-type"]??"")?Number(h.headers["content-length"]??0)>Mn?c(413,"size","\u6587\u4EF6\u592A\u5927\uFF08\u6700\u591A 5GB\uFF09"):null:[415,{ok:!1,reason:"type"}]}async function d(){for(let[h,g]of m)Date.now()-g.at<_r||(m.delete(h),await Q.promises.rm(g.file,{force:!0}).catch(()=>{}))}async function E(h,g){let j=u(h);if(j)return h.resume(),J(g,...j);let _=new URL(h.url,"http://localhost").searchParams.get("name")?.replace(/[\u0000-\u001f]/g,"").trim()??"";if(!_||_.length>255)return h.resume(),J(g,...c(400,"name","\u6587\u4EF6\u540D\u4E0D\u5BF9"));await d();let T=`u-${gr(8).toString("hex")}`,P=he.join(await a(),T),N=0,A=new wr({transform(I,Z,X){N+=I.length,X(N>Mn?Object.assign(new Error("too-large"),{reason:"size"}):null,I)}});try{await yr(h,A,Q.createWriteStream(P))}catch(I){return await Q.promises.rm(P,{force:!0}).catch(()=>{}),I.reason==="size"?J(g,...c(413,"size","\u6587\u4EF6\u592A\u5927\uFF08\u6700\u591A 5GB\uFF09")):J(g,...c(400,"body","\u6587\u4EF6\u6CA1\u6709\u4F20\u5B8C"))}return m.set(T,{file:P,name:_,at:Date.now()}),J(g,200,{ok:!0,id:T})}async function $(h,g){let j=await e.check(h);if(j.error)return J(g,...j.error);let{slug:_,options:T}=j.body??{};if(typeof _!="string"||!Bn.test(_)||!await p(w(_).html))return J(g,...c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"));if(!Nn(T))return J(g,...c(400,"options","\u5BFC\u51FA\u9009\u9879\u4E0D\u5BF9"));try{let P=await s(),N=new Map,A=R=>(N.has(R)||N.set(R,e.handIn(R,{reader:!0}).then(W=>{if(!W.ok)throw Object.assign(new Error(W.message??W.reason),{reason:W.reason});if(W.repeated.length)throw Object.assign(new Error("check"),{reason:"check",slug:R,failures:He(W.repeated)})})),N.get(R)),I=new Map,Z={reportsDirectory:r,titleOf:v,childrenOf:async R=>{let{children:W,links:ee=[]}=await n.outline(),te=we=>(W[we]??[]).flatMap(ye=>ee.includes(ye)||ye.startsWith("~")?te(ye):[ye]);return te(R)},links:()=>Un(r),offline:async(R,W)=>{await A(R);let ee=await P(R,W),te=T.format==="markdown"?null:kr(ee);return te&&I.set(R,te),ee},check:async R=>(await A(R),P.check(R))},{name:X,type:V,data:q}=await Wn(_,T,Z);I.size&&await(await Ge([...I.keys()])).keep([...I.keys()],I),g.writeHead(200,{"Content-Type":V,"Content-Length":q.length,"Content-Disposition":`attachment; filename*=UTF-8''${encodeURIComponent(X)}`,"X-File-Name":encodeURIComponent(X),"Cache-Control":"no-store"}),g.end(q)}catch(P){if(P.reason==="check"){let N=await v(P.slug),A=P.component?xt("\u300C{0}\u300D\u91CC\u7684\u7EC4\u4EF6 {1} \u6709\u9519\u8BEF\uFF0C\u6CA1\u6709\u751F\u6210\u6587\u4EF6\uFF1A\u53EF\u4EE5\u8BA9 AI \u68C0\u67E5\u8FD9\u4EFD\u6587\u6863\u5E76\u4FEE\u597D",N,P.component):P.failures.length>1?xt("\u300C{0}\u300D\u6CA1\u6709\u901A\u8FC7\u5BFC\u51FA\u524D\u7684\u68C0\u67E5\uFF0C\u6CA1\u6709\u751F\u6210\u6587\u4EF6\uFF1A{1}\uFF08\u5171 {2} \u5904\uFF1A\u53EF\u4EE5\u8BA9 AI \u68C0\u67E5\u8FD9\u4EFD\u6587\u6863\uFF0C\u5217\u51FA\u5168\u90E8\u5E76\u4FEE\u597D\uFF09",N,P.failures[0],P.failures.length):xt("\u300C{0}\u300D\u6CA1\u6709\u901A\u8FC7\u5BFC\u51FA\u524D\u7684\u68C0\u67E5\uFF0C\u6CA1\u6709\u751F\u6210\u6587\u4EF6\uFF1A{1}",N,P.failures[0]);return J(g,...c(422,"check",A))}J(g,...c(P.reason==="browser"?422:P.reason==="busy"?409:P.reason==="missing"?404:500,P.reason??"export",P))}}async function k(h,g){let j=await e.check(h);if(j.error)return J(g,...j.error);let{slug:_}=j.body??{},T=(await e.readTaken(_,{wait:0}))?.text??null;if(T===null)return J(g,...c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"));let P=`http://${h.headers.host}`,{named:N}=await Un(r),A=sn(je(T,{slug:_,mode:"words",reportsDirectory:r}),_,V=>V.slug&&$r(P,V,N),N),{text:I,files:Z}=await ve("markdown",{source:A,title:await v(_),pictures:!1}),X=I.replace(/\u0000F(\d+)\u0000/g,(V,q)=>{let{src:R,kind:W}=Z[Number(q)];return encodeURI(`${P}${xr(W==="image"?"asset":"file",_,R)}`)});return J(g,200,{ok:!0,text:X})}let Y=async h=>{let g=await e.readTaken(h,{wait:0});return{source:g?.text??"",version:g?.version??null}},M=async(h,g=null)=>{let{source:j,version:_}=g??await Y(h),T="\u5199\u4F5C\u504F\u597D",{text:P,files:N}=await ve("markdown",{source:j,title:T,pictures:!1}),A=P.split(`
|
|
73
|
+
`).slice(1).join(`
|
|
74
|
+
`).replace(/^[\s>]*(?:```.*|\d+\.|- \[x\])/gm,"").replace(/<\/?aside>/g,"");if(!/[\p{L}\p{N}]|\u0000F\d+\u0000/u.test(A))return{markdown:`# ${T}
|
|
75
|
+
`,empty:!0,version:_};let I=he.relative(r,b(h)).split(he.sep).join("/");return{markdown:`${P.replace(/\u0000F(\d+)\u0000/g,(Z,X)=>encodeURI(`${I}/${N[Number(X)].src}`))}
|
|
76
|
+
`,empty:!1,version:_}},x=h=>w(h).json,C=async h=>{try{let g=JSON.parse(await Q.promises.readFile(x(h),"utf8"));return g&&typeof g=="object"?g:null}catch{return null}},B=h=>hr("sha256").update(h).digest("hex").slice(0,16);async function G(h,g,j,_){let T=await C(h);if(!T||j===null)return;let{synced:P,...N}=T,A={file:B(g),page:j,unshown:_},I=T.madeSame;P===void 0&&I?.file===A.file&&I?.page===A.page&&JSON.stringify(I?.unshown)===JSON.stringify(_)||await vt(x(h),`${JSON.stringify({...N,madeSame:A},null,2)}
|
|
77
|
+
`)}async function z(h,g){let j=await Q.promises.mkdtemp(he.join(kt.tmpdir(),"gallery-preferences-"));try{let T=(await ve("import",{uploads:[{file:g,name:"preferences.md"}],scratch:j})).pages[0]??{nodes:[],raws:[],files:[],icon:null,lang:null},P=b(h),N=await C(h)??{},A=zn(P).html,I=await Q.promises.readFile(A,"utf8").catch(()=>""),Z=/<html\b[^>]*\slang="([^"]*)"/i.exec(I)?.[1]??null,{html:X}=await qt(h,N.title||"\u5199\u4F5C\u504F\u597D",N.description||"",{blank:!0,lang:Z}),V=typeof N.icon=="string"&&N.icon?N.icon:null,q=await ve("fill",{source:X,nodes:T.nodes,icon:V,raws:T.raws,lang:T.lang});T.files.length&&await Q.promises.mkdir(he.join(P,"assets"),{recursive:!0});for(let{from:W,name:ee}of T.files){let te=he.join(P,"assets",ee);await p(te)||await Q.promises.copyFile(W,te)}let R=await Q.promises.readFile(A,"utf8").catch(()=>null);R!==null&&e.keepVersion?.(h,R),await vt(A,ze(q))}finally{await Q.promises.rm(j,{recursive:!0,force:!0}).catch(()=>{})}}async function L(h,g){let j=await e.check(h);if(j.error)return J(g,...j.error);let _=j.body?.opening===!0,T=await Er(r);if(!T)return J(g,...c(404,"missing","\u8FD8\u6CA1\u6709\u5199\u4F5C\u504F\u597D"));let P=null,N=(A,I)=>[200,{ok:!0,path:he.resolve(P),remade:A,unshown:I}];return e.respond(async()=>{let A;({file:P,text:A}=await Or(r));let I=await Y(T),Z=(await C(T))?.madeSame??null,X=Z===null||Z.page===I.version,V=Z!==null&&X&&Z.file===B(A);if(_&&V&&Array.isArray(Z.unshown))return N(!1,Z.unshown);let[q,R,W,ee]=[A,"",I.version,!1];if(_&&!X)await z(T,P),{markdown:R,version:W}=await M(T),ee=!0;else{let we=await M(T,I),ye=A.trim()===we.markdown.trim()||we.empty&&!Cr(A);R=we.markdown,_?!ye&&!V&&(await z(T,P),{markdown:R,version:W}=await M(T),ee=!0):ye||(await vt(P,we.markdown),q=we.markdown)}let te=jr(q,R);return await G(T,q,W,te),N(ee,te)})(h,g)}async function se(h,g){let j=await e.check(h);if(j.error)return J(g,...j.error);let{uploads:_,parent:T="",from:P,language:N}=j.body??{},A={said:typeof P=="string"&&P.includes("{0}")&&P.length<=60?P:"\u5BFC\u5165\u81EA {0}",lang:N==="en"?"en":null};if(!Array.isArray(_)||_.length===0||_.length>1e3||!_.every(R=>typeof R=="string"&&Tr.test(R)))return J(g,...c(400,"body"));let I=_.map(R=>m.get(R)).filter(Boolean);if(I.length!==_.length)return J(g,...c(410,"gone","\u4E0A\u4F20\u7684\u6587\u4EF6\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u5BFC\u5165"));for(let R of _)m.delete(R);let Z=typeof T=="string"&&Bn.test(T)&&await p(he.join(r,T))?T:"",X=await Q.promises.mkdtemp(he.join(kt.tmpdir(),"gallery-import-")),V=()=>Promise.all([Q.promises.rm(X,{recursive:!0,force:!0}),...I.map(({file:R})=>Q.promises.rm(R,{force:!0}))]).catch(()=>{}),q;try{q=await ve("import",{uploads:I.map(({file:R,name:W})=>({file:R,name:W})),scratch:X})}catch(R){return await V(),J(g,...c(500,"convert",R))}return e.respond(async()=>{try{let{made:R,top:W}=await $n(q.pages,{create:t.create,slugOf:()=>br(r),folderOf:b,fill:ee=>ve("fill",ee),place:n.place,under:Z,...A});return[200,{ok:!0,pages:R.length,reports:W,skipped:q.skipped,missing:re(q.pages)}]}finally{await V()}})(h,g)}let re=h=>[...new Set(h.flatMap(function g(j){return[...(j.notes??[]).filter(_=>_.kind==="picture-missing").map(_=>_.name),...j.children.flatMap(g)]}))],U={export:$,markdown:k,upload:E,import:se,preferences:L};function K(h,g,j){return Object.hasOwn(U,j)?U[j](h,g).catch(_=>{g.headersSent||J(g,...c(500,"transfer",_))}):J(g,404,{ok:!1,reason:"unknown"})}async function ce(){let h=f;f=null,m.clear();let g=await h?.catch(()=>null);g&&($t.delete(g),await Q.promises.rm(g,{recursive:!0,force:!0}).catch(()=>{}))}return{handle:K,close:ce}}import{FACT_KINDS as Ja,QUERY_ROUTE as Ya,WORKSPACE_GLOBAL as Xa}from"../browser/shared/workspace-query.mjs";function Kn({settled:e,tell:n,delay:t=120,recheck:r=1e3}){let s=new Map,f=(a,m=t)=>{clearTimeout(s.get(a));let c=setTimeout(async()=>{let p=await e(a).catch(()=>({source:null,held:!1,wait:0}));if(s.get(a)===c){if(p.held)return f(a,Math.min(Math.max(p.wait,50),r));if(p.wait>0)return f(a,p.wait);await n(a,p)}},m);s.set(a,c)};return f}import xe from"node:fs";import Ee from"node:path";import{isExtensionId as Rr}from"../browser/shared/outline-shape.mjs";import{DOCUMENT_FOLDERS as Jn,isSlugName as St,layoutOf as Yn}from"../browser/shared/workspace.mjs";function Fr(e,n=!1,t=!1){let{components:r,gallery:s,preferencesPage:f,customPages:a,extensions:m}=Yn(e),c=(u,d)=>{try{return xe.readdirSync(u,{withFileTypes:!0}).filter(E=>E.isDirectory()&&d(E.name)).map(E=>Ee.join(u,E.name))}catch{return[]}},p=c(m,u=>Rr(u)&&!Jn.includes(u));if(n){let u=Ee.dirname(e);for(;!xe.existsSync(u)&&Ee.dirname(u)!==u;)u=Ee.dirname(u);return[u,e,...t?[s]:[],m,...p].filter(d=>xe.existsSync(d))}let b=[...c(e,u=>St(u)),...c(f,u=>St(u))],w=u=>[u,...c(u,d=>!d.startsWith(".")).flatMap(w)],v=c(a,u=>St(u)&&!Jn.includes(u));return[...new Set([e,...[s,f,a,m].filter(u=>xe.existsSync(u)),...v,...p,...b,...b.map(u=>Ee.join(u,"assets")).filter(u=>xe.existsSync(u)),...xe.existsSync(r)?w(r):[]])]}function Qe(e,n,{folders:t=process.platform==="linux",extensionsOnly:r=!1,outline:s=!1}={}){let f=bt(e),a=(v,u)=>{!(s&&u===Yn(e).outline)&&(f(u)||Ee.basename(u).startsWith("."))||xe.stat(u,(E,$)=>{if(E)return n(E.code==="ENOENT"?"unlink":"change",u);let k=$.isDirectory();n(v==="rename"?k?"addDir":"add":k?"addDir":"change",u)})},m=()=>{};if(!t&&!r)try{let v=xe.watch(e,{recursive:!0},(u,d)=>d?a(u,Ee.join(e,d.toString())):n("reset",e));return v.on("error",m),{close:()=>v.close()}}catch(v){if(v.code!=="ERR_FEATURE_UNAVAILABLE_ON_PLATFORM")throw v}let c=new Map,p=null,b=()=>{let v=new Set(Fr(e,r,s));for(let[u,d]of c)v.has(u)||(d.close(),c.delete(u));for(let u of v)if(!c.has(u))try{let d=xe.watch(u,(E,$)=>{if(!$)return n("reset",u);E==="rename"&&w(),a(E,Ee.join(u,$.toString()))});d.on("error",m),c.set(u,d)}catch{}},w=()=>{p??=setTimeout(()=>{p=null,b()},50)};return b(),{close(){clearTimeout(p);for(let v of c.values())v.close();c.clear()},get folders(){return[...c.keys()]}}}import Ar from"node:fs/promises";import{packageScript as Dr}from"../browser/shared/export-wrap.mjs";import{serveFound as Lr}from"../browser/shared/http.mjs";import{extensionOf as Ir,mediaTypeOf as Nr}from"../browser/shared/media.mjs";var Wr="/__gallery/components/",Mr=/^\/__gallery\/components\/([a-z0-9][a-z0-9-]*\/[a-z0-9][a-z0-9-]*)\/(.+)$/,Ur={js:"text/javascript; charset=utf-8",mjs:"text/javascript; charset=utf-8",css:"text/css; charset=utf-8",wasm:"application/wasm"};async function Xn(e,n,t,{root:r}){if(!e.startsWith(Wr))return!1;let[,s,f]=Mr.exec(e)??[],a=s?ae(r).packages.get(s):null,m=a?.files.includes(f)?Lt(a,f):null,c=m?await Ar.readFile(m).catch(()=>null):null,p=c&&f==="kit.js"?Buffer.from(Dr(c.toString("utf8").replace(/^\uFEFF/,""))):c,b=p&&n===a.stamp&&n===It(a);return Lr(t,p,{type:p?Ur[Ir(f)]??Nr(f):void 0,headers:{"X-Content-Type-Options":"nosniff","Cache-Control":b?"max-age=31536000, immutable":"no-store"}}),!0}import{BLOCK_ICON as Br}from"../browser/editor/components/icons.mjs";import{LISTED_BLOCKS as Vn}from"../browser/editor/components/registry.mjs";import{PACKAGE_ID as zr}from"../browser/shared/components/installed.mjs";import{netHostsOf as Zn}from"../browser/shared/net-policy.mjs";import{inLanguage as Qn,refusal as qe,said as Oe}from"../browser/shared/i18n/index.mjs";function qn({root:e,taken:n}){let t=()=>{let a=ae(e);return{packages:Nt(a).map(m=>{let c=Bt(m.id)?Ut(m.id):null;return{...m,newer:c?zt(e,c):null,...c?{addAs:c.pack===Wt?c.name:c.id}:{}}}),packs:ut(e,{settings:a.settings}),packageIcon:Br,blocks:Vn.map(({id:m,name:c,icon:p,hideable:b})=>({id:m,name:{zh:Qn("zh",c),en:Qn("en",c)},icon:p,hidden:b&&a.settings.hidden.includes(m),hideable:b})),problem:Dt(a)}},r=({id:a,hidden:m,shown:c,disabled:p,unlisted:b,net:w})=>{if(![m,c,p,b,w].every(u=>u===void 0||typeof u=="boolean"))return Oe("\u5F00\u5173\u7684\u503C\u4E0D\u5BF9");let v=Vn.find(u=>u.id===a);return v?p!==void 0||c!==void 0||b!==void 0||w!==void 0?Oe("\u5185\u7F6E\u5757\u53EA\u80FD\u9690\u85CF\uFF0C\u4E0D\u80FD\u505C\u7528"):m&&!v.hideable?Oe("\u8FD9\u4E2A\u5757\u4E0D\u80FD\u9690\u85CF"):null:typeof a=="string"&&zr.test(a)?w&&Zn(ae(e).packages.get(a)?.needs).length===0?Oe("\u8FD9\u4E2A\u5757\u4E0D\u8054\u7F51"):null:Oe("\u6CA1\u6709\u8FD9\u4E2A\u7EC4\u4EF6")};return{read:t,write:async a=>{if(a?.pack!==void 0){let{pack:w,enabled:v}=a;if(typeof v!="boolean")throw qe(Oe("\u5F00\u5173\u7684\u503C\u4E0D\u5BF9"));if(typeof w!="string"||!ut(e,{settings:ae(e).settings}).some(({id:u})=>u===w))throw qe(Oe("\u6CA1\u6709\u8FD9\u4E2A\u5757\u5305"));return await ft(e,{pack:w,enabled:v}),n(),t()}let m=r(a);if(m)throw qe(m);let{net:c,...p}=a,b=c===void 0?void 0:c?Zn(ae(e).packages.get(a.id)?.needs):[];return await ft(e,{...p,...b?{net:b}:{}}),n(),t()},install:({path:a,zip:m}={})=>{let c=typeof m=="string"?Cn(Buffer.from(m,"base64")):typeof a=="string"&&a.trim()?On(a):null;if(!c)throw qe(Oe("\u7C98\u8D34\u5757\u5305\u7684\u6587\u4EF6\u5939\u6216 zip \u7684\u8DEF\u5F84"),{code:"path"});let p=Kt(e,c);return n(),{...t(),installed:p}}}}import Hr from"node:path";import{exportsDirectory as Gr}from"../browser/shared/paths.mjs";async function eo(e,n,{workspace:t=null}={}){let r=Hr.join(Gr,`${n}.html`),s=await Ge([n]),f=await e.handInReport(n,{reader:!0});if(!f.ok)return{problems:[],refused:{reason:f.reason,message:f.message},file:r};if(f.repeated.length)return{problems:He(f.repeated),file:r};let{exported:a,failures:m}=await pn([n],{workspace:t});return await s.keep(a.map(c=>c.slug)),{problems:m.get(n)??[],file:r}}import to from"node:fs/promises";import no from"node:path";import{MEDIA_ROUTES as oo,assetFile as Kr,extensionOf as Jr,imageFile as Yr,mediaTypeOf as Xr}from"../browser/shared/media.mjs";import{serveFound as ro}from"../browser/shared/http.mjs";import{slugPattern as ao}from"../browser/shared/reports.mjs";import{pageFiles as Vr}from"../browser/shared/pages.mjs";import{documentDirectory as Zr}from"../browser/shared/workspace.mjs";var Et={asset:e=>({"Content-Type":Xr(e),"Cache-Control":"no-cache"}),file:()=>({"Content-Type":"application/octet-stream","Content-Disposition":"attachment","X-Content-Type-Options":"nosniff","Cache-Control":"no-cache"}),embed:e=>/\.pdf$/i.test(e)?{"Content-Type":"application/pdf","X-Content-Type-Options":"nosniff","Cache-Control":"no-cache"}:{"Content-Type":"text/html; charset=utf-8","Content-Security-Policy":"sandbox allow-scripts allow-popups allow-forms allow-modals","X-Content-Type-Options":"nosniff","Cache-Control":"no-cache"}},Qr=new RegExp(`^/__gallery/edit/(${Object.keys(oo).join("|")})/([^/]+)/(assets/[^/]+)$`);async function so(e,n,{reportsDirectory:t}){let[,r,s,f]=Qr.exec(e)??[];if(!r)return!1;let a=ao.test(s)&&oo[r](f)?await to.readFile(no.join(Zr(s,t),f)).catch(()=>null):null;return ro(n,a,{headers:Et[r](f)}),!0}var qr={css:"text/css; charset=utf-8",js:"text/javascript; charset=utf-8",mjs:"text/javascript; charset=utf-8"},ea=/^\/pages\/([^/]+)\/(assets\/[^/]+)$/;async function io(e,n,{reportsDirectory:t}){let[,r,s]=ea.exec(e)??[];if(!r)return!1;let f=ao.test(r)&&Kr(s)?await to.readFile(no.join(Vr(r,t).folder,s)).catch(()=>null):null,a=qr[Jr(s??"")];return ro(n,f,{headers:a?{"Content-Type":a,"X-Content-Type-Options":"nosniff","Cache-Control":"no-cache"}:(Yr(s)?Et.asset:Et.file)(s)}),!0}import ta from"node:dns";import{sendJson as Ae}from"../browser/shared/http.mjs";import{createNetCache as na,dataOf as oa}from"../browser/shared/net-cache.mjs";import{readKeys as ra}from"../browser/shared/net-keys.mjs";import{addressKind as tt,addressOf as go,hostIn as co,keptHere as lo,keyIn as fo,mapsHere as aa,netHostsOf as sa,proxyHere as ia,withKey as ca}from"../browser/shared/net-policy.mjs";import{galleryVersion as la}from"../browser/shared/preview-server.mjs";var et=512*1024,da=6e4,mo=20,uo=5,po=1e4,fa=16*1024,ma=new Set([301,302,303,307,308]),ua=/^(?:application\/(?:[\w.-]+\+)?json|text\/[\w.+-]+)$/i,$e=(e,n={})=>({ok:!1,code:e,...n}),oe=(e,n={},t)=>Object.assign(new Error(e),{refusal:$e(e,n),...t===void 0?{}:{detail:t}});function pa(e,n){let t;try{t=new URL(e,n)}catch{return{code:"url",why:"a redirect to an address that does not parse"}}let r=go(t.href);return r.code?{code:"url",why:`a redirect to ${t.host?`${t.protocol}//${t.host}`:t.protocol}: ${r.why}`}:r}function ho(e,n){let t=[...new Set([n,encodeURIComponent(n)])].filter(Boolean),r=s=>typeof s=="string"?t.reduce((f,a)=>f.split(a).join("{key}"),s):s;return Object.fromEntries(Object.entries(e).map(([s,f])=>[s,r(f)]))}var ha=e=>ta.promises.lookup(e,{all:!0,verbatim:!0}),Ot=e=>URL.parse(e)?.host||"?",Ct=e=>tt(e)==="fake-ip"?"an address a fake-ip proxy's DNS gives":"an address of this computer or of a private network";async function ga(e,{resolve:n,proxy:t}){let r=e.hostname,s=ia(t),f=d=>{let E=tt(d);return E==="public"||E==="fake-ip"&&s},a=r.replace(/^\[|\]$/g,"");if(tt(a)!=="none"){if(f(a))return{address:a};throw oe("private",{host:r,address:a,why:`${a} is ${Ct(a)}`})}let m;try{m=(await n(r)).map(d=>typeof d=="string"?d:d.address)}catch(d){throw oe("offline",{why:`${r} did not resolve (${d.code??d.message})`})}if(m.length===0)throw oe("offline",{why:`${r} did not resolve`});let c=m.filter(d=>!f(d));if(c.length===0)return{address:m[0]};let p=c.filter(d=>!aa(d)),b=p.length?p:c,w=b.find(d=>!d.includes(":"))??b[0],v=`${r} resolved to ${w}, ${Ct(w)}`,u=lo(r)?"and its name is one kept for this computer (localhost)":t?s?e.protocol!=="https:"?"and an http address is never handed to a proxy by its name (no TLS to check the site)":p.length?"and a private network's address is never handed to a proxy by its name (that network's own machines are there)":null:"and the proxy it goes through is not on this computer":"and no proxy of this computer goes between to reach it by its name";if(u===null)return{address:null,resolved:w,said:v};throw oe("private",{host:r,address:w,why:`${v}, ${u}`},s||!t||lo(r)?void 0:`${v}, and the proxy it goes through (${Ot(t)}) is not on this computer`)}var wa=({resolve:e=ha,proxyFor:n=hn,connect:t,ca:r}={})=>async(s,{headers:f,signal:a})=>{let m=await n(s.href),c=await ga(s,{resolve:e,proxy:m}),{address:p}=c,b={...t?{connect:t}:{},...r?{ca:r}:{}};try{return await Ke(s,{address:p,proxy:m,headers:f,signal:a,...b})}catch(w){if(!(m&&w.proxyFailed&&(p!==null||w.code==="ECONNREFUSED")))throw p===null&&!a?.aborted?oe("offline",{why:`${c.said}, and no site the proxy of this computer reached by its name proved to be it`},`${c.said}, handed by its name to the proxy (${Ot(m)}): ${w.code??w.message}`):w;let v=d=>`and the proxy of this computer that would reach it${d?` (${Ot(m)})`:""} is not running`,u=p===null?c.said:`${s.hostname.replace(/^\[|\]$/g,"")===p?p:`${s.hostname} resolved to ${p}`}, ${Ct(p)}`;if(p===null||tt(p)!=="public")throw oe("private",{host:s.hostname,address:p??c.resolved,why:`${u}, ${v(!1)}`},`${u}, ${v(!0)}`);return Ke(s,{address:p,proxy:null,headers:f,signal:a,...b})}},wo=e=>(n,{headers:t,signal:r})=>Ke(new URL(`http://127.0.0.1:${e}/${n.protocol.slice(0,-1)}/${n.host}${n.pathname}${n.search}`),{address:"127.0.0.1",headers:t,signal:r});async function ya(e){let n=0,t=[];for await(let r of e){if(n+=r.length,n>fa)throw Object.assign(new Error("too-large"),{status:413});t.push(r)}return JSON.parse(Buffer.concat(t).toString("utf8"))}function ka(e,n){let t=/;\s*charset="?([^";]+)"?/i.exec(n)?.[1];try{return new TextDecoder(t||"utf-8").decode(e)}catch{return new TextDecoder("utf-8").decode(e)}}function yo({root:e,catalog:n=()=>ae(e),hop:t=null,now:r=Date.now,cache:s=na(e),log:f=()=>{}}){let a=t??wa(),m=new Map,c=d=>{let E=r(),$=(m.get(d)??[]).filter(k=>E-k<6e4);return $.length>=mo?(m.set(d,$),!1):(m.set(d,[...$,E]),!0)},p={accept:"application/json, text/plain;q=0.9, text/*;q=0.8","user-agent":`Gallery/${la} (a custom block's card)`};async function b(d,{hosts:E,allowed:$,key:k}){let Y=AbortSignal.timeout(po),M=d;for(let x=0;;x++){let C;try{C=await a(k===void 0?M:new URL(ca(M.href,k)),{headers:p,signal:Y})}catch(L){throw L.refusal?L:oe("offline",{why:Y.aborted?`no answer within ${po/1e3} s`:String(L.code??L.message)})}if(ma.has(C.status)&&C.headers.get("location")){if(C.body?.cancel().catch(()=>{}),x>=uo)throw oe("status",{status:C.status,why:`more than ${uo} redirects`});let L=pa(C.headers.get("location"),M);if(L.code)throw oe("url",{why:L.why});let se=co(L.url.hostname,E);if(!se)throw oe("host",{host:L.url.hostname,why:`a redirect to ${L.url.hostname}, which the block's needs do not name`});if(!$.includes(se))throw oe("consent",{hosts:E.filter(re=>!$.includes(re))});M=L.url,k=fo(M.href)?k:void 0;continue}if(C.status<200||C.status>299)throw C.body?.cancel().catch(()=>{}),oe("status",{status:C.status});let B=C.headers.get("content-type")??"",G=B.split(";")[0].trim();if(G&&!ua.test(G))throw C.body?.cancel().catch(()=>{}),oe("type",{type:G});if(Number(C.headers.get("content-length"))>et)throw C.body?.cancel().catch(()=>{}),oe("too-large",{limit:et});let z;try{z=C.body?await gn(C,et):Buffer.alloc(0)}catch(L){throw oe("offline",{why:String(L.code??L.message)})}if(z===null)throw oe("too-large",{limit:et});return{type:G||"text/plain",text:ka(z,B)}}}let w=(d,E,$)=>{let k=oa(d,E);return k===void 0?$e("type",{why:"the answer is no JSON"}):{ok:!0,data:k,at:d.at,cached:$}};async function v(d){let{block:E,url:$,as:k="json",doc:Y=null}=d??{},M=typeof E=="string"?n().packages.get(E):null;if(!M)return $e("missing",{why:"no custom block of that id loads in this workspace"});let x=sa(M.needs);if(k!=="json"&&k!=="text")return $e("url",{why:'as is "json" or "text"'});let C=go($);if(C.code)return $e("url",{why:C.why});let{url:B}=C,G=co(B.hostname,x);if(!G)return $e("host",{host:B.hostname,why:x.length?`its needs name ${x.join(", ")}`:"its needs name no host of the net"});let z=n().settings.net?.[E]??[];if(!z.includes(G))return $e("consent",{hosts:x.filter(U=>!z.includes(U))});let L;if(fo(B.href)){let U=ra(e);if(L=U[B.hostname]??U[G],L===void 0)return $e("key",{host:B.hostname})}let se=B.href,re=s.get(se);if(s.used(se,Y,k),re&&r()-Date.parse(re.at)<da)return w(re,k,!0);if(!c(E))return re?w(re,k,!0):$e("rate",{why:`more than ${mo} fetches in a minute`});try{let{type:U,text:K}=await b(B,{hosts:x,allowed:z,key:L});return w(s.put(se,{type:U,text:K,at:new Date(r()).toISOString()}),k,!1)}catch(U){if(!U.refusal)throw U;if(re&&U.refusal.code!=="consent")return w(re,k,!0);let K=L===void 0?U.refusal:ho(U.refusal,L),ce=U.detail===void 0?K.why:L===void 0?U.detail:ho({why:U.detail},L).why;return(K.code!=="offline"||U.detail!==void 0)&&f(`${E}: ${B.hostname} refused (${K.code}${ce?`: ${ce}`:""})`),K}}async function u(d,E){if(d.method!=="POST")return Ae(E,405,{ok:!1,reason:"method"});if(d.headers.origin!==`http://${d.headers.host}`)return Ae(E,403,{ok:!1,reason:"origin"});if(!/^application\/json\b/i.test(d.headers["content-type"]??""))return Ae(E,415,{ok:!1,reason:"type"});let $;try{$=await ya(d)}catch(k){return Ae(E,k.status??400,{ok:!1,reason:"body"})}try{return Ae(E,200,await v($))}catch(k){return Ae(E,500,{ok:!1,code:"offline",why:k.message})}}return{handle:u,answer:v,cache:s}}function ko({max:e=20}={}){let n=new Map;return{get(t,r,s){let f=`${t} ${r}`,a=n.get(f);return!a||a.text!==s?null:(n.delete(f),n.set(f,a),a.page)},set(t,r,s,f){let a=`${t} ${r}`;for(n.delete(a),n.set(a,{slug:t,text:s,page:f});n.size>e;)n.delete(n.keys().next().value)},clear(){n.clear()},forget(t){for(let[r,s]of n)s.slug===t&&n.delete(r)},get size(){return n.size}}}import{createHash as va}from"node:crypto";import{readFileSync as xa}from"node:fs";import vo from"node:fs/promises";import $a from"node:path";import{release as Sa,releaseFile as ba}from"../browser/shared/paths.mjs";async function nt(e){let n=await Promise.all(e.map(r=>vo.stat(r).then(({mtimeMs:s,size:f})=>`${s} ${f}`,()=>"none"))),t=va("sha256");return e.forEach((r,s)=>t.update(`${r}\0${n[s]}
|
|
78
|
+
`)),t.digest("hex").slice(0,16)}function xo(e,n){let t=null,r=async()=>(await Promise.all(e.map(async s=>(await vo.readdir(s,{recursive:!0,withFileTypes:!0}).catch(()=>[])).filter(a=>a.isFile()).map(a=>$a.join(a.parentPath,a.name))))).flat().filter(n).sort();return{files:()=>t??=r(),changed:()=>{t=null}}}var jt=Sa?JSON.parse(xa(ba,"utf8")).stamps:null;var it=Io.source.slice(1,-1),Va=new RegExp(`^/generated/(${it})\\.html$`),Za=new RegExp(`^/(${it})/(?:doc|report)\\.html$`),Qa=new RegExp(`^/pages/(${it})$`),qa=new RegExp(`^/__gallery/pages/(${it})/(cards|library|hint)$`),Ft="/__gallery/events",Pe=Ea,Wo=/^\/__gallery\/edit\/(v\/[a-f0-9]{16}\/)?src\/((?:shared(?:\/components|\/emoji|\/i18n)?\/|editor\/(?:page|components)(?:\/[a-z]+(?:-[a-z]+)*){0,2}\/(?!files?\.mjs))[a-z]+(?:-[a-z]+)*\.mjs)$/,es=/^\/__gallery\/edit\/(?:v\/[a-f0-9]{16}\/)?src\/(shared\/emoji\/data\/[a-z]+(?:-[a-z]+)*\.(json|bin))$/,rt=[H.join(Pe,"editor","page"),H.join(Pe,"editor","components"),H.join(Pe,"shared")],ts=e=>Wo.test(`/__gallery/edit/src/${H.relative(Pe,e).split(H.sep).join("/")}`);var ns=[Lo,H.join(Pe,"shared","components")],ll=[Lo,...rt],We={"Cache-Control":"no-store"},Fo={"Cache-Control":"max-age=31536000, immutable"},Pt=(e,n,t)=>Tt(e,{type:n,headers:{...We,...ja},body:t});function os(e){let n=e.headers?.host??"",t=e.socket?.localPort;return!!t&&(n===`127.0.0.1:${t}`||n===`localhost:${t}`)}function rs(e){if(e.method!=="GET"&&e.method!=="HEAD")return null;let n=e.socket?.localPort;if(!n||e.headers?.host!==`localhost:${n}`)return null;let t=new URL(e.url||"/","http://localhost");return t.pathname==="/"||t.pathname==="/index.html"?`http://127.0.0.1:${n}${t.pathname}${t.search}`:null}var Mo=`window.addEventListener("doc-net-fetch", (event) => {
|
|
79
|
+
event.preventDefault();
|
|
80
|
+
event.detail.answer(fetch("/__gallery/net", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(event.detail.ask) }).then((response) => response.json()));
|
|
81
|
+
});`,Uo=`let lost = false;
|
|
82
|
+
events.onerror = () => { lost = true; };
|
|
83
|
+
events.onopen = () => {
|
|
84
|
+
if (!lost) return;
|
|
85
|
+
lost = false;
|
|
86
|
+
for (const kind of ${JSON.stringify(Ja)}) window.dispatchEvent(new CustomEvent("doc-workspace-change", { detail: kind }));
|
|
87
|
+
};`,as=(e,n,t)=>`<script>
|
|
88
|
+
(() => {
|
|
89
|
+
document.currentScript.remove();
|
|
90
|
+
${Mo}
|
|
91
|
+
const solo = new URLSearchParams(location.search).has("solo");
|
|
92
|
+
let catalog = "${t}";
|
|
93
|
+
const holds = (ids) => document.querySelector(ids === undefined ? "[${at}]" : ids.split(",").map((id) => '[${at}="' + id + '"]').join());
|
|
94
|
+
const events = new EventSource("${Ft}?slug=${e}");
|
|
95
|
+
${Uo}
|
|
96
|
+
events.onmessage = (event) => {
|
|
97
|
+
const [kind, next, ids, more, consents, unlisted, packs] = event.data.split(" ");
|
|
98
|
+
if (kind === "notes") return void window.dispatchEvent(new CustomEvent("doc-annotations-changed", { detail: { version: next ?? "" } }));
|
|
99
|
+
if (kind === "changes") return void window.dispatchEvent(new CustomEvent("doc-changes-changed", { detail: { stamp: next ?? "" } }));
|
|
100
|
+
if (kind === "look") return void window.dispatchEvent(new CustomEvent("doc-look-request", { detail: { look: Object.fromEntries(new URLSearchParams(next ?? "")), from: "file" } }));
|
|
101
|
+
if (kind === "settings") return void window.dispatchEvent(new CustomEvent("doc-settings-changed", { detail: { hidden: next ? next.split(",") : [], disabled: ids ? ids.split(",") : [], shown: more ? more.split(",") : [], net: consents ? consents.split(",") : [], unlisted: unlisted ? unlisted.split(",") : [], packsOff: packs ? packs.split(",") : [] } }));
|
|
102
|
+
if (kind === "data") return void window.dispatchEvent(new CustomEvent("doc-workspace-change", { detail: next ?? "" }));
|
|
103
|
+
if (kind !== "report" && kind !== "assets" && kind !== "components") return;
|
|
104
|
+
if (kind === "components") {
|
|
105
|
+
if (document.readyState === "loading") return void document.addEventListener("DOMContentLoaded", () => events.onmessage(event), { once: true });
|
|
106
|
+
if (solo || next === catalog) return;
|
|
107
|
+
catalog = next;
|
|
108
|
+
if (!holds(ids)) return void window.dispatchEvent(new CustomEvent("doc-catalog-changed", { detail: { ids: ids === undefined ? null : ids.split(",").filter(Boolean) } }));
|
|
109
|
+
}
|
|
110
|
+
if (window.__galleryEditBusy) {
|
|
111
|
+
window.dispatchEvent(new CustomEvent({ report: "doc-source-changed", assets: "doc-assets-changed", components: "doc-components-changed" }[kind], { detail: { version: next ?? null } }));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (kind === "report" && next === "${n}") return;
|
|
115
|
+
if (window.__galleryEditReload) return window.__galleryEditReload(); // in a workbench: swapped in, no reload seen
|
|
116
|
+
location.reload();
|
|
117
|
+
};
|
|
118
|
+
})();
|
|
119
|
+
</script>`,ss=(e,n,t)=>`<script>
|
|
120
|
+
(() => {
|
|
121
|
+
document.currentScript.remove();
|
|
122
|
+
${Mo}
|
|
123
|
+
let catalog = "${t}";
|
|
124
|
+
const holds = (ids) => {
|
|
125
|
+
const named = ids === undefined ? "[${at}]" : ids.split(",").filter(Boolean).map((id) => '[${at}="' + id + '"]').join() || ":not(*)";
|
|
126
|
+
return Boolean(document.querySelector(named)) || [...document.querySelectorAll("template[data-ge-held]")].some((held) => held.content.querySelector(named));
|
|
127
|
+
};
|
|
128
|
+
const again = () => (window.__galleryEditReload ? window.__galleryEditReload() : location.reload());
|
|
129
|
+
const events = new EventSource("${Ft}?page=${e}");
|
|
130
|
+
${Uo}
|
|
131
|
+
events.onmessage = (event) => {
|
|
132
|
+
const [kind, next, ids, more, consents, unlisted, packs] = event.data.split(" ");
|
|
133
|
+
if (kind === "page") return void (window.__galleryPageChanged ? window.__galleryPageChanged(next) : next !== "${n}" && again());
|
|
134
|
+
if (kind === "assets") return void again();
|
|
135
|
+
if (kind === "settings") return void window.dispatchEvent(new CustomEvent("doc-settings-changed", { detail: { hidden: next ? next.split(",") : [], disabled: ids ? ids.split(",") : [], shown: more ? more.split(",") : [], net: consents ? consents.split(",") : [], unlisted: unlisted ? unlisted.split(",") : [], packsOff: packs ? packs.split(",") : [] } }));
|
|
136
|
+
if (kind === "data") return void window.dispatchEvent(new CustomEvent("doc-workspace-change", { detail: next ?? "" }));
|
|
137
|
+
if (kind !== "components") return;
|
|
138
|
+
if (document.readyState === "loading") return void document.addEventListener("DOMContentLoaded", () => events.onmessage(event), { once: true });
|
|
139
|
+
if (next === catalog) return;
|
|
140
|
+
catalog = next;
|
|
141
|
+
if (holds(ids)) again();
|
|
142
|
+
};
|
|
143
|
+
})();
|
|
144
|
+
</script>`;function Ao(e,n){let t=H.relative(e,n).split(H.sep);if(t[0]===".."||H.isAbsolute(t[0])||t[0]==="")return null;if(t.length===1&&t[0]===st)return{slug:null,name:st,packages:!0};let r=c=>process.platform==="win32"?c.toLowerCase():c;if(r(t[0])===Da&&t.length>=2&&Ka(t[1])&&!Co.includes(t[1])){let c=t.slice(2);return c.some(p=>p.startsWith("."))?null:{extension:t[1],name:c.length===1?c[0]:null}}if(r(t[0])===La&&t.length>=2&&No(t[1])&&!Co.includes(t[1])){let c=t.slice(2);return c.some(p=>p.startsWith("."))?null:{page:t[1],name:c.length===1?c[0]:null}}let s=t[0]===".gallery"&&t[1]==="pages"&&t.length>=3,[f,...a]=s?t.slice(2):t,m=!s&&r(f)===Oo;return!(m||Io.test(f))||f==="exports"||a.some(c=>c.startsWith("."))?null:{slug:m?Oo:f,name:a.length===1?a[0]:null,...m?{packages:m}:{}}}function bt(e){let n=w=>process.platform==="win32"?H.resolve(w).toLowerCase():H.resolve(w),{gallery:t,preferencesPage:r,exports:s,extensions:f}=Rt(e),[a,m,c,p]=[n(t),n(r),n(s),n(f)],b=(w,v)=>w===v||w.startsWith(v+H.sep);return w=>{let v=n(w);return b(v,p)&&v!==p&&v.slice(p.length+1).split(H.sep).some((u,d)=>d>0&&(u==="node_modules"||u===".git"))?!0:b(v,a)&&v!==a&&!b(v,m)||b(v,c)}}var Do=`<script data-doc-dev>document.currentScript.remove(); globalThis.${Xa} = ${JSON.stringify(Ya)};</script>`,ue=(e,n,t)=>new RegExp(`</${n}>`,"i").test(e)?e.replace(new RegExp(`</${n}>`,"i"),()=>` ${t}
|
|
145
|
+
</${n}>`):`${e}
|
|
146
|
+
${t}`;function Bo({stateDirectory:e=Oa,logger:n=console,kind:t="dev",workbenchPage:r=null,closeServer:s=async()=>{},exit:f=()=>process.exit(0)}={}){let a=new Set,m=(o,i="",l="report")=>{for(let S of a)(!o||S.slug===o)&&S.response.write(`data: ${o?`${l} ${i}`:"assets"}
|
|
147
|
+
|
|
148
|
+
`)},c=(o,i)=>{for(let l of a)l.page===o&&l.response.write(`data: page ${i}
|
|
149
|
+
|
|
150
|
+
`)},p=!1,b=o=>{p||=o,A("workspace",()=>{let i=p;p=!1;for(let l of a)l.workspace&&(i||!l.ownOnly)&&l.response.write(`data: workspace ${Date.now()}
|
|
151
|
+
|
|
152
|
+
`)})},w=()=>b(!0),v=()=>b(!1),u=o=>m(o,String(Date.now()),"changes"),d=vn({stateDirectory:e,finish:ze,log:o=>n.info?.(`[gallery] ${o}`),onChanges:u}),E=(o,i,l,{lang:S=null,page:F=!1}={})=>Qt(o,i,l,{blank:!0,lang:S,page:F}),$=e?Rn({file:H.join(e,"activity.json")}):null,k=bn({root:D,read:Sn(d),activity:$,draw:(o,i)=>je(o,{slug:i,mode:"words",reportsDirectory:D})}),Y=new Set,M=o=>{for(let i of o)Y.add(i);Y.size!==0&&A("data",()=>{let i=[...Y];Y.clear();for(let l of a)if(l.slug||l.page)for(let S of i)l.response.write(`data: data ${S}
|
|
153
|
+
|
|
154
|
+
`)})},x=o=>H.resolve(H.dirname(_t(o,D)))===H.resolve(D),C=null,B=null,G=()=>B??=(async()=>{for(let o of a)o.response.end();a.clear(),await Promise.race([s().catch(()=>{}),new Promise(o=>setTimeout(o,3e3))]),await $?.close(),await C?.().catch(()=>{}),await L.close(),z.close(),f()})(),z=En({server:{kind:t,version:Pa,stop:G},edits:d,reports:{create:E,export:o=>eo(d,o,{workspace:i=>k.snapshot(i)}),words:(o,i)=>je(o,{slug:i,mode:"words",reportsDirectory:D})},components:qn({root:D,taken:()=>V.taken()}),changed:w,relayed:v,index:k,web:{frameable:wn,title:yn,icon:o=>kn(o)}}),L=Gn({edits:d,workspace:z,reports:{create:E},reportsDirectory:D,offline:o=>un({...o,workspace:i=>k.snapshot(i)})}),se=yo({root:D,hop:process.env.GALLERY_TEST_NET?wo(Number(process.env.GALLERY_TEST_NET)):null,log:o=>n.info?.(`[gallery] ${o}`)}),re=Xt({root:D,edits:d,stateDirectory:e,catalogTaken:()=>V.taken(),log:o=>n.info?.(`[gallery] ${o}`),shown:wt}),U=(o,i,{present:l=!1,editorModule:S,kit:F}={})=>{let y=i,ie="",ne="",fe=!0;try{l||({html:y,snippet:ie,head:ne}=d.preview(o,i,{editor:S,kitTags:le=>an(le,F)}))}catch(le){fe=!1,n.warn(`[gallery] text editing unavailable for ${o}: ${le.message}`)}if({html:y}=ln(y,{slug:o,mode:"preview",kit:F}),y=ue(y,"head",as(o,Ne(i),ae(D).stamp)),y=ue(y,"head",`<script data-doc-dev>${So()}</script>`),y=ue(y,"head",Do),ne&&(y=ue(y,"head",ne)),l)return{html:ue(y,"head",`<style data-doc-present>.doc-display { display: none !important; }</style>
|
|
155
|
+
<script type="module" src="/__gallery/edit/src/editor/page/present-links.mjs" data-doc-dev></script>`),whole:fe};let ke="";try{ke=Dn(o,i)}catch(le){fe=!1,n.warn(`[gallery] checks unavailable for ${o}: ${le.message}`)}return ke&&(y=ue(y,"body",ke)),{html:ie?ue(y,"body",ie):y,whole:fe}},K=ko(),ce=xo(rt,ts),h=o=>{let i=_t(o,D);return[i,H.join(i,"assets")]},g=()=>jt?.editor??ce.files().then(nt),j=o=>jt?.kit?.[o.id]??nt([gt(o)]),_=async(o,i,{present:l})=>{let[S,F,y]=await Promise.all([l?"":g(),Promise.all(Fe.map(j)),nt(h(o))]),ie=[l?"present":S,...F,y,ae(D).stamp,`look:${bo(Eo(o,D))}`].join(" "),ne=K.get(o,ie,i);if(ne!==null)return l||d.opened(i),ne;let fe=new Map(Fe.map((pe,Ce)=>[pe,F[Ce]])),ke=l?void 0:`/__gallery/edit/v/${S}/src/editor/page/editor.mjs`,{html:le,whole:de}=U(o,i,{present:l,editorModule:ke,kit:pe=>`${Be(pe)}?v=${fe.get(pe)}`});return de&&K.set(o,ie,i,le),le},T=async o=>{let i=Po(o,D),[l,S]=await Promise.all([ge.readFile(i.html,"utf8").catch(()=>null),ge.readFile(i.json,"utf8").catch(()=>"")]);if(l===null)return null;let[F,y]=await Promise.all([g(),Promise.all(Fe.map(j))]),ie=new Map(Fe.map((O,be)=>[O,y[be]])),ne=ae(D),fe=To(l,S),ke=Yt(l,{blockOf:O=>ht(ne,O)}),le=Object.fromEntries([...new Set(pt(l).cards.map(({block:O})=>O).filter(Boolean))].map(O=>[O,ht(ne,O)])),{html:de}=An(ke,{reportsDirectory:D,slug:o,kit:O=>`${Be(O)}?v=${ie.get(O)}`}),pe=Ha(o,D),Ce=za(o,D),Re=pe?.defaultCards===!0,Me=Ua(l),Ue=O=>ne.packages.get(O)?.name??Mt().find(be=>be.id===O)?.title??null,Se=Re?Ma(D,pt(l).cards.map(({block:O})=>O)).map(O=>({block:O,name:Ue(O)})):[],Ie=JSON.stringify({slug:o,title:pe?.title??o,token:d.token,version:fe,blocks:le,...Ce?{hint:Ce}:{},...Re?{defaults:Re}:{},...Se.length?{news:Se}:{},...Me?{blank:Me}:{}}).replace(/</g,"\\u003c");return de=ue(de,"head",`<script type="application/json" data-ge-page data-doc-dev>${Ie}</script>`),de=ue(de,"head",ss(o,fe,ne.stamp)),de=ue(de,"head",`<script data-doc-dev>${So()}</script>`),de=ue(de,"head",Do),ue(de,"head",`<script type="module" src="/__gallery/edit/v/${F}/src/editor/page/custom-page.mjs" data-doc-dev></script>`)};async function P(o,i,l){try{if(!os(o))return $o(i,403,{ok:!1,reason:"host"});let S=rs(o);if(S)return Tt(i,{status:302,headers:{Location:S,...We}});let F=new URL(o.url||"/","http://localhost"),y=decodeURI(F.pathname);if(y===Ft){i.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-store",Connection:"keep-alive"}),i.write(`retry: 3000
|
|
156
|
+
|
|
157
|
+
`);let O={slug:F.searchParams.get("slug"),page:F.searchParams.get("page"),workspace:F.searchParams.has("workspace"),ownOnly:F.searchParams.get("workspace")==="own",response:i};a.add(O);let{stamp:be,settings:Xo}=ae(D);i.write(`data: components ${be}
|
|
158
|
+
|
|
159
|
+
`),i.write(`data: ${mt(Xo)}
|
|
160
|
+
|
|
161
|
+
`),o.on("close",()=>a.delete(O));return}if(y==="/__gallery/net")return se.handle(o,i);if(y==="/__gallery/edit/commit")return d.commit(o,i);if(y==="/__gallery/edit/reverted")return d.reverted(o,i);if(y==="/__gallery/edit/hand-in")return d.handInRequest(o,i);if(y==="/__gallery/edit/settle")return d.settleRequest(o,i);if(y==="/__gallery/edit/round")return d.roundRequest(o,i);if(y==="/__gallery/edit/upload")return d.upload(o,i);if(y==="/__gallery/edit/unfurl")return d.unfurl(o,i);if(y==="/__gallery/edit/emoji-library"){if(o.method==="POST")return d.addEmoji(o,i);let[O,be]=await d.listEmojis();return $o(i,O,be)}if(y==="/__gallery/edit/icon"){let O=en({value:F.searchParams.get("value")??"",slug:F.searchParams.get("slug"),tab:F.searchParams.has("tab")});return De(i,O?.body,{type:O?.type,headers:{"Cache-Control":"max-age=31536000, immutable"}})}if(await so(y,i,{reportsDirectory:D})||await io(y,i,{reportsDirectory:D})||await Xn(y,F.searchParams.get("v"),i,{root:D}))return;let ie=y.match(/^\/__gallery\/edit\/emoji-library\/([^/]+)$/)?.[1];if(ie){let O=await d.readEmoji(ie);return De(i,O?.body,{type:O?.type,headers:{"Cache-Control":"no-cache"}})}if(y==="/__gallery/edit/frameable")return d.frameable(o,i);if(y==="/__gallery/edit/annotations")return d.annotations(o,i);if(y==="/__gallery/edit/changes")return d.changes(o,i);let ne=y.match(/^\/__gallery\/transfer\/([a-z]+)$/)?.[1];if(ne)return L.handle(o,i,ne);let[,fe,ke]=y.match(qa)??[];if(fe)return re.handle(o,i,fe,ke);let le=y.match(/^\/__gallery\/workspace\/([a-z]+(?:-[a-z]+)*)$/)?.[1];if(le)return z.handle(o,i,le);let[,de,pe]=y.match(Wo)??[];if(pe){let O=await ge.readFile(H.join(Pe,pe),"utf8").catch(()=>null);return De(i,O,{type:"text/javascript; charset=utf-8",headers:de?Fo:We})}let Ce=F.searchParams.has("v")&&Fe.find(O=>Be(O)===y);if(Ce){let O=await ge.readFile(gt(Ce)).catch(()=>null);return De(i,O,{type:y.endsWith(".css")?"text/css; charset=utf-8":"text/javascript; charset=utf-8",headers:Fo})}if(y==="/__gallery/edit/mhchem.js"){let O=await ge.readFile(rn).catch(()=>null);return De(i,O,{type:"text/javascript; charset=utf-8",headers:We})}let[,Re,Me]=y.match(es)??[];if(Re){let O=await ge.readFile(H.join(Pe,Re)).catch(()=>null);return De(i,O,{type:Me==="json"?"application/json; charset=utf-8":"application/octet-stream",headers:{"Cache-Control":"max-age=86400"}})}if(r&&(y==="/"||y==="/index.html"))return Pt(i,"text/html; charset=utf-8",await r(F.pathname,o));let Ue=y.match(Qa)?.[1];if(Ue){let O=await T(Ue);return O===null?l():Pt(i,"text/html; charset=utf-8",O)}let Se=y.match(Va)?.[1];if(!Se){let O=y.match(Za)?.[1];return No(O)&&await ge.access(Na(_t(O,D)).html).then(()=>!0,()=>!1)?Tt(i,{status:302,headers:{Location:`/generated/${O}.html${F.search}`,...We}}):l()}let Ie=await d.readTaken(Se);if(Ie===null)return l();F.searchParams.has("present")||d.noteTaken(Se,Ie.source).then(O=>O&&u(Se),()=>{}),Pt(i,"text/html; charset=utf-8",await _(Se,Ie.text,{present:F.searchParams.has("present")}))}catch(S){l(S)}}let N=new Map,A=(o,i)=>{clearTimeout(N.get(o)),N.set(o,setTimeout(i,120))},I=o=>{Fa(o,D).reads&&m(o,bo(Eo(o,D)),"look")},Z=Kn({settled:d.settled,async tell(o,i){let l=await d.read(o,i.source).catch(S=>(n.error(`[gallery] ${o}: ${S.message}`),{version:Ne(i.source??"")}));if(m(o,l?.version??Ne("")),x(o)){let S=d.writerOf(o,i.source)??"agent";k.changed(o,{source:i.source??null,text:l?.text??null,by:S}).then(M,F=>n.error(`[gallery] ${o}: its facts not read: ${F.message}`))}d.noteTaken(o,i.source).then(S=>S&&u(o),S=>n.error(`[gallery] ${o}: the Agent's changes not kept: ${S.message}`)),d.checkAnnotations(o).catch(S=>n.error(`[gallery] ${o}: annotations not checked: ${S.message}`))}}),X=({id:o,problem:i,off:l})=>l||n.warn(`[gallery] custom block ${o} does not load: ${At("en",i)}`),V=Tn({root:D,tell({stamp:o,problems:i,settings:l},S){for(let F of S)i.has(F)&&X(i.get(F));for(let{response:F}of a)F.write(`data: components ${o} ${S.filter(y=>Aa.test(y)).join(",")}
|
|
162
|
+
|
|
163
|
+
`),F.write(`data: ${mt(l)}
|
|
164
|
+
|
|
165
|
+
`)}});for(let o of ae(D).problems.values())X(o);k.start().then(o=>o>0&&M(["activity"]));let q=bt(D),R=Ro(D).then(o=>o.join("/"),()=>""),W=!1,ee=o=>{W||=o===ot,A("extensions",async()=>{let i=W;W=!1;let l=await R;R=Ro(D).then(S=>S.join("/"),()=>l),(i||await R!==l)&&w()})},te=Ia(),we=Rt(te).extensions,ye=Qe(te,(o,i)=>{if(Ta(i,Rt(te).outline)){w();return}let l=H.relative(i,we);if(o==="reset"||l===""||!l.startsWith("..")&&!H.isAbsolute(l)){ee(ot);return}let S=Ao(te,i);S?.extension&&(S.name===ot||S.name===null)&&ee(S.name)},{extensionsOnly:!0,outline:!0}),dt=(o,i)=>!Ca&&i.some(l=>o.startsWith(l+H.sep));function Ko(o,i){if(o==="reset"){K.clear(),ce.changed(),V.changed(),w();return}if(q(i))return;let l=Ao(D,i);if(l?.page){let{page:S,name:F}=l;F&&Ba(F)&&A(`page:${S}`,async()=>{let y=Po(S,D),[ie,ne]=await Promise.all([ge.readFile(y.html,"utf8").catch(()=>null),ge.readFile(y.json,"utf8").catch(()=>"")]);ie!==null&&c(S,To(ie,ne))}),(F===_o.json||F===_o.html&&/^(add|unlink)$/.test(o)||F===null&&/^(add|unlink)Dir$/.test(o))&&w();return}if(l?.extension){(l.name===ot||l.name===null)&&ee(l.name);return}if(l?.packages&&V.changed(),l?.name===st&&l.slug===null&&A("look:*",()=>new Set([...a].map(({slug:S})=>S).filter(Boolean)).forEach(I)),l?.name===st&&l.slug===null&&w(),l?.slug&&!(l.name&&Wa(l.name))&&K.forget(l.slug),l&&(/^(doc|report)\.json$/.test(l.name??"")||/^(add|unlink)Dir$/.test(o)&&l.name===null)&&K.clear(),l?.slug&&!l.packages&&l.name===null&&/^(add|unlink)Dir$/.test(o)&&x(l.slug)&&(k.forget(l.slug),M(["todos","recent","stats"])),l?.slug&&!(l.packages&&l.name===null)&&(/^(doc|report)\.json$/.test(l.name??"")||/^(add|unlink)Dir$/.test(o)&&l.name===null||/^(add|unlink)$/.test(o)&&jo(l.name??""))&&w(),l?.slug&&!l.packages&&l.name===Ga&&w(),/^(add|unlink)(Dir)?$/.test(o)&&dt(i,rt)&&ce.changed(),l?.name&&(jo(l.name)||/^(doc|report)\.json$/.test(l.name))){if(Z(l.slug),/^(doc|report)\.json$/.test(l.name)){let{slug:S}=l;A(`look:${S}`,()=>I(S))}}else if(l?.name==="annotations.json"){let{slug:S}=l;A(`notes:${S}`,async()=>{let F=await ge.readFile(i,"utf8").catch(()=>null);m(S,F===null?"":Ne(F),"notes")})}else dt(i,ns)?A("kit",async()=>{try{await mn({fresh:!0}),m()}catch(S){n.error(`[gallery] shared kit rebuild failed: ${S.message}`)}}):dt(i,rt)&&A("editor",()=>m())}async function Jo(o){C=await _a({reportsDirectory:D,port:o,token:d.token,kind:t}),await Ra(D)}async function Yo(){ye?.close();for(let o of N.values())clearTimeout(o);V.close(),await $?.close(),await C?.().catch(()=>{}),C=null,await L.close(),z.close()}return{handle:P,changed:Ko,listening:Jo,close:Yo,stop:G,edits:d,get listeners(){return a.size}}}import is from"node:fs/promises";import Le from"node:path";import{FRAMED_BY as cs,serve as zo}from"../browser/shared/http.mjs";var ls={".html":"text/html; charset=utf-8",".js":"text/javascript; charset=utf-8",".mjs":"text/javascript; charset=utf-8",".css":"text/css; charset=utf-8",".json":"application/json; charset=utf-8",".map":"application/json; charset=utf-8",".svg":"image/svg+xml",".png":"image/png",".ico":"image/x-icon",".woff2":"font/woff2",".woff":"font/woff",".ttf":"font/ttf",".txt":"text/plain; charset=utf-8"},ds=e=>ls[Le.extname(e).toLowerCase()]??"application/octet-stream";function fs(e,n){if(/%(?:2f|5c|00)/i.test(n)||/[\\\0]/.test(n))return null;let t;try{t=decodeURIComponent(n)}catch{return null}let r=t.split("/");if(r.some(a=>a===""||a==="."||a===".."||/[\\\0:]/.test(a)))return null;let s=Le.resolve(e,...r),f=Le.relative(e,s);return f&&!f.startsWith("..")&&!Le.isAbsolute(f)?s:null}async function Ho(e,n,{web:t,kit:r,vendor:s}){if(e.method!=="GET"&&e.method!=="HEAD")return!1;let f=new URL(e.url||"/","http://localhost").pathname,a=null,m=null;if(f==="/"||f==="/index.html"){if(!t)return!1;[a,m]=[Le.join(t,"index.html"),{"Cache-Control":"no-store",...cs}]}else{let b=[["/assets/",t&&Le.join(t,"assets"),"max-age=31536000, immutable"],["/kit/",r,"no-cache"],["/vendor/",s,"no-cache"]].find(([w,v])=>v&&f.startsWith(w));if(!b)return!1;a=fs(b[1],f.slice(b[0].length)),m={"Cache-Control":b[2]}}let c=a?await is.readFile(a).catch(()=>null):null;return c?(zo(n,{type:ds(a),headers:{...m,"X-Content-Type-Options":"nosniff"},body:e.method==="HEAD"?void 0:c}),!0):(zo(n,{status:404}),!0)}async function Cl({port:e,web:n=ys,kind:t=process.env.GALLERY_SERVER_KIND==="dev"?"dev":"cli",stateDirectory:r=ps,exit:s=(c=0)=>process.exit(c),watch:f=!0,signals:a=!0,log:m=console}={}){await ks(Te),await Jt(Te,{log:$=>m.log(`[gallery] ${new Date().toISOString()} ${$}`)}),Gt(Te,$=>m.log(`[gallery] ${new Date().toISOString()} ${$}`)),Ht(Te);let c=await Vt(Te,{stateDirectory:r});c.did==="made"?m.log(`[gallery] ${new Date().toISOString()} the default home page made: ${c.file} (${c.cards.length} cards)`):c.did==="failed"&&m.warn(`[gallery] ${new Date().toISOString()} ${Zt(c)}`);let p=null,b=null,w=null,v=vs(Te),u=async()=>{b?.close(),w&&ct.unwatchFile(lt,w),await ms.writeFile(v.lastPortFile,`${e}
|
|
166
|
+
`).catch(()=>{}),await new Promise($=>{p.close(()=>$()),p.closeAllConnections()})},E=Bo({stateDirectory:r,logger:{info:$=>m.log($),warn:$=>m.warn($),error:$=>m.error($)},kind:t,closeServer:u,exit:()=>s(0)});if(p=us.createServer(($,k)=>{E.handle($,k,async Y=>{if(Y){m.error(`[gallery] ${$.method} ${$.url}: ${Y.stack??Y.message}`),k.headersSent?k.end():Go(k,{status:500});return}try{if(await Ho($,k,{web:n,kit:hs,vendor:ws}))return}catch(M){m.error(`[gallery] ${$.url}: ${M.message}`)}k.headersSent||Go(k,{status:404})})}),p.keepAliveTimeout=5e3,await new Promise(($,k)=>{p.once("error",k),p.listen(e,"127.0.0.1",()=>{p.off("error",k),$()})}),e=p.address().port,await E.listening(e),f&&(b=Qe(Te,E.changed)),gs){let $=ct.readFileSync(lt,"utf8");w=()=>{let k=null;try{k=ct.readFileSync(lt,"utf8")}catch{}k!==$&&(m.log("[gallery] The package was replaced (another version installed): this server stops; the next gallery command starts the new one."),E.stop())},ct.watchFile(lt,{interval:3e3,persistent:!1},w)}if(a)for(let $ of["SIGINT","SIGTERM","SIGHUP"])process.once($,()=>E.stop());return{server:p,port:e,routes:E,async close(){await u(),await E.close()}}}export{Cl as a};
|
|
@@ -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{$ as ha,A as I,B as J,C as K,D as L,E as M,F as N,G as O,H as P,I as Q,J as R,K as S,L as T,M as U,N as V,O as W,P as X,Q as Y,R as Z,S as _,T as $,U as aa,V as ba,W as ca,X as da,Y as ea,Z as fa,_ as ga,a as i,aa as ia,b as j,ba as ja,c as k,ca as ka,d as l,e as m,f as n,g as o,h as p,i as q,j as r,k as s,l as t,m as u,n as v,o as w,p as x,q as y,r as z,s as A,t as B,u as C,v as D,w as E,x as F,y as G,z as H}from"./chunk-
|
|
2
|
+
import{$ as ha,A as I,B as J,C as K,D as L,E as M,F as N,G as O,H as P,I as Q,J as R,K as S,L as T,M as U,N as V,O as W,P as X,Q as Y,R as Z,S as _,T as $,U as aa,V as ba,W as ca,X as da,Y as ea,Z as fa,_ as ga,a as i,aa as ia,b as j,ba as ja,c as k,ca as ka,d as l,e as m,f as n,g as o,h as p,i as q,j as r,k as s,l as t,m as u,n as v,o as w,p as x,q as y,r as z,s as A,t as B,u as C,v as D,w as E,x as F,y as G,z as H}from"./chunk-4DNHHJSL.mjs";import"./chunk-342HXE3Q.mjs";import"./chunk-3A5I2GJK.mjs";import"./chunk-XQRUG4G3.mjs";import"./chunk-4AMTKWDO.mjs";import{a,b,c,f as d,g as e,h as f,k as g,l as h}from"./chunk-FCK6NXON.mjs";import"./chunk-OU3S466R.mjs";import"./chunk-QK3VISCA.mjs";import"./chunk-F4ZA6JRZ.mjs";import"./chunk-7M2BQQGZ.mjs";import"./chunk-TOE6DPLH.mjs";import"./chunk-WTEGUPFG.mjs";import"./chunk-4OZWXZE5.mjs";import"./chunk-XMKHCUI6.mjs";import"./chunk-SAHS56QM.mjs";import"./chunk-KH24LWAT.mjs";import"./chunk-YFJU3O7G.mjs";import"./chunk-NWRZXELO.mjs";import"./chunk-G4YP7GVC.mjs";import"./chunk-DHB7UZ7F.mjs";import"./chunk-2RKIHJI2.mjs";import"./chunk-JXLSHVJ2.mjs";import"./chunk-XKOHV4H6.mjs";import"./chunk-KFZBYDIS.mjs";import"./chunk-7XDYK3UC.mjs";import"./chunk-VG5JEIUQ.mjs";import"./chunk-N3DSBH5S.mjs";import"./chunk-5L7RYZCL.mjs";export{_ as ADVICE,t as BLOCK_PICTURES,$ as CODE_SIDEWAYS,X as HAND_OVER,u as INK_MARGIN,i as KINDS,j as LEVELS,k as LOOKS,Y as LOOK_YOURSELF,W as MORE_PICTURES,M as MOSTLY_CHANGED,y as MOVED_PART,x as MOVED_WHOLE,w as NEIGHBOUR_EDGE,p as PICTURED_INFO,ca as SCROLLS,v as SCROLL_FRAMES,s as SCROLL_SLACK,ba as WARNED,l as WIDE,m as WIDTHS,f as adoptIdless,aa as adviceOf,e as baselineOf,L as baselineSaid,b as blocksOf,N as blocksToPicture,da as describeLooks,S as disclosuresSaid,g as exportBaselines,G as exportOf,ga as exportingFirst,Q as findingKey,q as findingLevel,O as inkOf,P as inventory,n as layoutNotesOf,o as levelOf,R as lookAt,J as missedWidths,V as morePictures,H as movedBlocks,z as movedClips,ha as namedBlocks,I as nextBaseline,ea as notPicturedLine,c as pageOf,r as picturedAt,T as picturesSaid,D as placeOf,h as previewBaseline,a as rankOf,d as readBaseline,ka as run,K as seenOf,C as sourceIndex,F as staleExport,Z as startFailure,E as timeOf,ia as unknownBlocks,ja as unknownBlocksSaid,U as unopenedSaid,A as urlName,fa as verdictOf,B as wordsOf};
|
|
@@ -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-XKOHV4H6.mjs";import"./chunk-KFZBYDIS.mjs";import"./chunk-7XDYK3UC.mjs";import"./chunk-VG5JEIUQ.mjs";import"./chunk-N3DSBH5S.mjs";import"./chunk-5L7RYZCL.mjs";export{a as commitEdits,c as revertedParts,d as revertedTexts,b as revertedUnits};
|
|
@@ -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 D,b as M}from"./chunk-
|
|
2
|
+
import{a as D,b as M}from"./chunk-HBAUKKQH.mjs";import{c as v,d as j}from"./chunk-KUILYI7H.mjs";import{b as k,f as A}from"./chunk-4OZWXZE5.mjs";import L from"node:fs/promises";import y from"node:path";import{readAnnouncement as _}from"../browser/shared/preview-server.mjs";import{nameProblem as B,nameStops as b,ownName as K,workspaceLabels as Q,workspaceName as x,writeWorkspaceName as R}from"../browser/shared/workspace-name.mjs";import{forgetWorkspace as U,isTemporary as q,isWorkspace as C,isWorkspaceId as z,readRegistry as F,registerQuietly as W,registerWorkspace as G,SCAN_DEPTH as P,SCAN_LIMIT as J,scanForWorkspaces as V,workspaceId as X,workspaceKey as l}from"../browser/shared/workspace-registry.mjs";import{defaultWorkspace as Y,documentsFolder as T,ensureWorkspace as Z,layoutOf as ee}from"../browser/shared/workspace.mjs";import{clashingIds as oe}from"../browser/shared/drafts.mjs";var $=(o,r)=>`${o} ${r}${o===1?"":"s"}`,I=(o,r)=>l(o)===l(r);function se(o){if(K(o)||I(o,Y()))return null;let{name:r}=x(o,{stops:b()});return`\u5DE5\u4F5C\u533A\u540D\u5B57\uFF1A\u6CA1\u6709\uFF08\u522B\u5904\u6309\u6587\u4EF6\u5939\u53EB\u5B83"${r}"\uFF09\uFF1B\u8FD9\u4E2A\u5DE5\u4F5C\u533A\u662F\u4E3A\u4E00\u4E2A\u9879\u76EE\u5EFA\u7684\uFF0C\u5C31\u7528 gallery workspaces --name "<\u9879\u76EE\u540D>" \u5199\u4E0A\u9879\u76EE\u540D`}async function re(o,r){let c=B(r);if(c)throw new k(c);try{let{ours:t,reads:i}=await Z(o);t||(console.error(j(o,i)),process.exit(1))}catch(t){if(!t.code)throw t;console.error(v(o,t.code)),process.exit(1)}let s;try{s=await R(o,r)}catch(t){console.error(t.code?v(o,t.code):t.message),process.exit(1)}await W(o),console.log(`\u5DE5\u4F5C\u533A\uFF1A${o}`),console.log(`\u540D\u5B57\uFF1A${s.name} (in ${ee(o).marker}${s.before&&s.before!==s.name?`; it was "${s.before}"`:""}): the sidebar and gallery workspaces call it so.`)}async function te(o,r){let c=await U(o);c.length||(console.error(`No registered workspace is ${z(o)?o:y.resolve(o)}: gallery workspaces lists them, with their paths and ws- ids.`),process.exit(1));for(let s of c)console.log(`Forgot ${s} (only the registry changed: nothing on disk).${I(s,r)?" It is the current workspace: the next command run in it registers it again.":""}`)}async function ne(o){let r=y.resolve(o??T());await L.stat(r).then(n=>n.isDirectory(),()=>!1)||(console.error(`No such folder: ${r} (--scan names a folder to look in).`),process.exit(1));let c=new Set(F().workspaces.map(({root:n})=>l(n))),{found:s,read:t,cut:i}=await V(r);console.log(`Scanned ${r}, ${P} levels down (${$(t,"folder")}): ${s.length?`${$(s.length,"workspace")}.`:"no workspace."}`);let f=b();for(let n of s){let{name:h}=x(n,{stops:f});if(c.has(l(n))){await W(n),console.log(` \u5DF2\u767B\u8BB0\uFF1A${n}\uFF08${h}\uFF09`);continue}let g;try{g=await G(n)}catch(m){console.log(` \u6CA1\u80FD\u767B\u8BB0\uFF08${m.code??m.message}\uFF09\uFF1A${n}`);continue}console.log(g==="temporary"?` \u4E0D\u767B\u8BB0\uFF08\u5728\u7CFB\u7EDF\u7684\u4E34\u65F6\u6587\u4EF6\u5939\u91CC\uFF09\uFF1A${n}`:` \u65B0\u767B\u8BB0\uFF1A${n}\uFF08${h}\uFF09`)}i&&console.log(`Stopped after ${$(J,"folder")}: gallery workspaces --scan <a folder further down> looks at the rest.`),s.length&&console.log("gallery workspaces lists them; gallery list <words> --all searches their documents.")}async function ae(o){let r=C(o),c=q(o);r&&await W(o);let s=F().workspaces,t=[o,...s.map(({root:e})=>e).filter(e=>!I(e,o))],i=new Map(s.map(({root:e,seen:a})=>[l(e),Date.parse(a)])),f=T(),n=b({documents:f}),h=await Promise.all(t.map(async e=>{let a=C(e),w=a?await D(e):[],p=a?await _({reportsDirectory:e}):null;return{root:e,there:a,count:w.length,edited:w.reduce((d,{edited:u})=>Math.max(d,u),0),port:p?.port??null,named:{root:e,...x(e,{stops:n})}}})),[g,...m]=h;m.sort((e,a)=>a.there-e.there||a.edited-e.edited||(i.get(l(a.root))??0)-(i.get(l(e.root))??0));let N=[g,...m],E=new Map(Q(N.map(({named:e})=>e)).map(e=>[l(e.root),e])),O=s.length;console.log(`${$(O,"workspace")} on this machine's registry; the current one first (*):`);for(let e of N){let{name:a,own:w,above:p}=E.get(l(e.root)),d=e===g,u=[...w||!e.there?[]:["\u6CA1\u6709\u8D77\u540D\uFF1A\u7528\u7684\u662F\u6587\u4EF6\u5939\u7684\u540D\u5B57"],...e.there?[]:[d?"\u8FD8\u6CA1\u6709\u5EFA":"\u4E0D\u5728\u4E86\uFF1A\u6587\u4EF6\u5939\u6216\u5B83\u7684 gallery.json \u627E\u4E0D\u5230\u4E86"],...d&&e.there&&c?["\u5728\u7CFB\u7EDF\u7684\u4E34\u65F6\u6587\u4EF6\u5939\u91CC\uFF1A\u4E0D\u767B\u8BB0"]:[]],H=p?y.isAbsolute(p)?`\uFF08${p}\uFF09`:`\uFF08\u4E0A\u4E00\u7EA7\uFF1A${p}\uFF09`:"";console.log(`${d?"*":" "} ${a}${H} ${X(e.root)}${u.length?` \uFF08${u.join("\uFF1B")}\uFF09`:""}`),console.log(` \u8DEF\u5F84\uFF1A${e.root}`),e.there&&console.log(` \u6587\u6863\uFF1A${e.count?`${e.count} \u7BC7\uFF1B\u4E0A\u6B21\u7F16\u8F91\uFF1A${M(e.edited)}`:"\u6CA1\u6709"}`),e.port&&console.log(` \u670D\u52A1\uFF1Ahttp://127.0.0.1:${e.port}/`)}for(let{id:e,roots:a}of oe())console.log(`${e} \u662F ${a.length} \u4E2A\u767B\u8BB0\u7684\u5DE5\u4F5C\u533A\u5171\u7528\u7684\u7F16\u53F7\uFF08${a.join("\u3001")}\uFF09\uFF1A\u4FA7\u8FB9\u680F\u91CC\u5B83\u4EEC\u7684\u5E95\u7A3F\u90FD\u627E\u4E0D\u5230\uFF1Bgallery workspaces --forget <\u8DEF\u5F84> \u53BB\u6389\u5176\u4E2D\u4E00\u4E2A`);let S=r?se(o):null;S&&console.log(S),m.some(({there:e})=>!e)&&console.log("One no longer there stays registered (a drive may come back): gallery workspaces --forget <\u8DEF\u5F84> takes it off, nothing on disk changed."),O<=1&&console.log(`gallery workspaces --scan registers the workspaces already on this machine (in the Documents folder, ${P} levels down; or --scan <folder>).`),console.log("gallery list <words> --all searches the documents of them all; every command takes --workspace <\u8DEF\u5F84> to work in one.")}async function ue(o,r){let{positional:c,options:s,values:t}=A({options:["--scan"],values:["--name","--forget"],argv:o});if([s.has("--scan"),t.has("--name"),t.has("--forget")].filter(Boolean).length>1)throw new k("One of --scan, --name and --forget at a time.");if(c.length>(s.has("--scan")?1:0))throw new k(s.has("--scan")?"--scan takes one folder at most.":"gallery workspaces names no folder: --scan <folder> looks in one, --workspace <dir> names the current workspace.");let f=y.resolve(r.workspace);return t.has("--name")?re(f,t.get("--name")):t.has("--forget")?te(t.get("--forget"),f):s.has("--scan")?ne(c[0]):ae(f)}export{se as a,ue as b};
|