@astryxdesign/cli 0.7.17-canary.g5a3fd39 → 0.7.17-canary.g5cf5d69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -63
- package/api/build/_adapter.d.mts +51 -0
- package/api/build/_adapter.mjs +122 -6
- package/api/build/build.doc.mjs +1 -1
- package/api/build/build.mjs +23 -14
- package/api/build/build.type.d.mts +1 -1
- package/api/build/build.type.mjs +3 -3
- package/api/build/help/help.d.mts +15 -14
- package/api/build/help/help.mjs +62 -3
- package/api/build/kit/answer.mjs +2 -3
- package/api/build/kit/signals.d.mts +10 -0
- package/api/build/kit/signals.mjs +15 -2
- package/api/component/detail/blocks/blocks.mjs +2 -1
- package/api/discover/_adapter.d.mts +57 -6
- package/api/discover/_adapter.mjs +278 -49
- package/api/discover/_catalog-view.d.mts +7 -0
- package/api/discover/_catalog-view.mjs +10 -1
- package/api/discover/detail/detail.d.mts +3 -2
- package/api/discover/detail/detail.mjs +3 -2
- package/api/discover/detail/doc/doc.mjs +1 -1
- package/api/discover/discover.d.mts +24 -0
- package/api/discover/discover.doc.mjs +1 -1
- package/api/discover/discover.mjs +146 -25
- package/api/discover/discover.type.d.mts +6 -4
- package/api/discover/discover.type.mjs +6 -4
- package/api/discover/search/search.d.mts +22 -0
- package/api/discover/search/search.mjs +290 -70
- package/api/docs/_entry-names.mjs +4 -3
- package/api/doctor/_adapter.d.mts +43 -3
- package/api/doctor/_adapter.mjs +142 -18
- package/api/doctor/built-checks.d.mts +30 -3
- package/api/doctor/built-checks.mjs +132 -5
- package/api/doctor/doctor.d.mts +93 -6
- package/api/doctor/doctor.doc.mjs +2 -2
- package/api/doctor/doctor.mjs +524 -33
- package/api/doctor/doctor.type.d.mts +2 -1
- package/api/doctor/doctor.type.mjs +2 -1
- package/api/doctor/theme-checks.d.mts +19 -0
- package/api/doctor/theme-checks.mjs +74 -6
- package/api/hook/hook.type.d.mts +1 -1
- package/api/hook/hook.type.mjs +1 -1
- package/api/hook/list/list.mjs +11 -7
- package/api/icon/_adapter.d.mts +2 -1
- package/api/icon/_adapter.mjs +10 -15
- package/api/icon/_records.d.mts +3 -1
- package/api/icon/_records.mjs +30 -3
- package/api/icon/exportIconIndex.doc.mjs +1 -1
- package/api/icon/icon.doc.mjs +3 -3
- package/api/icon/icon.type.d.mts +32 -1
- package/api/icon/icon.type.mjs +19 -3
- package/api/icon/list/list.mjs +4 -1
- package/api/icon/rankIconIndex.doc.mjs +1 -1
- package/api/icon/search/icon-index.mjs +18 -8
- package/api/icon/search/search.d.mts +26 -3
- package/api/icon/search/search.mjs +155 -9
- package/api/init/_adapter.d.mts +14 -0
- package/api/init/_adapter.mjs +26 -4
- package/api/init/init.d.mts +1 -1
- package/api/init/init.doc.mjs +2 -2
- package/api/init/init.mjs +1 -1
- package/api/init/init.type.d.mts +29 -1
- package/api/init/init.type.mjs +14 -1
- package/api/init/run/run.d.mts +11 -1
- package/api/init/run/run.mjs +84 -5
- package/api/integration/_adapter.d.mts +5 -4
- package/api/integration/_adapter.mjs +7 -5
- package/api/integration/integrationCheck.doc.mjs +1 -1
- package/api/integration/pack-check.mjs +8 -9
- package/api/integration/validate-integration.d.mts +1 -1
- package/api/integration/validate-integration.mjs +26 -24
- package/api/integration/validate-integration.type.d.mts +5 -2
- package/api/integration/validate-integration.type.mjs +5 -2
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/render/_adapter.d.mts +4 -2
- package/api/render/_adapter.mjs +62 -21
- package/api/render/render.doc.mjs +8 -5
- package/api/render/render.mjs +1 -1
- package/api/render/render.type.d.mts +2 -0
- package/api/render/render.type.mjs +2 -0
- package/api/search/ORDERING.md +2 -2
- package/api/search/_candidate-score.d.mts +3 -0
- package/api/search/_candidate-score.mjs +36 -3
- package/api/search/_gather-docs.mjs +29 -2
- package/api/search/_gather-templates.mjs +2 -1
- package/api/search/_main-searcher.mjs +13 -0
- package/api/search/_named-keywords.d.mts +2 -1
- package/api/search/_named-keywords.mjs +48 -6
- package/api/search/_order.d.mts +36 -1
- package/api/search/_order.mjs +141 -3
- package/api/swizzle/list/list.mjs +8 -1
- package/api/swizzle/swizzle.type.d.mts +1 -1
- package/api/swizzle/swizzle.type.mjs +1 -1
- package/api/template/copy/copy.mjs +3 -4
- package/api/template/list/list.mjs +2 -1
- package/api/template/show/show.mjs +2 -1
- package/api/template/skeleton/skeleton.mjs +2 -1
- package/api/template/template.doc.mjs +1 -1
- package/api/template/template.mjs +19 -1
- package/api/template/template.type.d.mts +1 -0
- package/api/template/template.type.mjs +2 -1
- package/api/theme/_adapter.d.mts +1 -0
- package/api/theme/_adapter.mjs +3 -5
- package/api/theme/_app-provider.d.mts +42 -0
- package/api/theme/_app-provider.mjs +61 -27
- package/api/theme/build/build.d.mts +4 -10
- package/api/theme/build/build.mjs +165 -116
- package/api/theme/build/input-fields.d.mts +9 -0
- package/api/theme/build/input-fields.mjs +155 -16
- package/api/theme/build/radius-values.d.mts +18 -0
- package/api/theme/build/radius-values.mjs +76 -0
- package/api/theme/build/typography-values.mjs +7 -23
- package/api/theme/build/written-values.d.mts +18 -0
- package/api/theme/build/written-values.mjs +107 -31
- package/api/theme/eject/eject.mjs +6 -1
- package/api/theme/palette/generate/generator.mjs +24 -0
- package/api/theme/theme.type.d.mts +4 -2
- package/api/theme/theme.type.mjs +3 -2
- package/api/theme/themeBuild.doc.mjs +2 -2
- package/api/theme/themeEject.doc.mjs +1 -1
- package/api/theme-edit/_catalog.d.mts +40 -0
- package/api/theme-edit/_catalog.mjs +100 -22
- package/api/theme-edit/_check.mjs +213 -43
- package/api/theme-edit/_color.d.mts +14 -0
- package/api/theme-edit/_color.mjs +22 -0
- package/api/theme-edit/_compiler.mjs +52 -0
- package/api/theme-edit/_context.d.mts +20 -2
- package/api/theme-edit/_context.mjs +157 -29
- package/api/theme-edit/_edit.mjs +426 -58
- package/api/theme-edit/_how-question.d.mts +14 -0
- package/api/theme-edit/_how-question.mjs +1541 -127
- package/api/theme-edit/_how.mjs +43 -0
- package/api/theme-edit/_missed.mjs +107 -27
- package/api/theme-edit/_normal.d.mts +18 -4
- package/api/theme-edit/_normal.mjs +84 -3
- package/api/theme-edit/_palette.d.mts +9 -0
- package/api/theme-edit/_palette.mjs +158 -33
- package/api/theme-edit/_part-words.mjs +16 -3
- package/api/theme-edit/_parts.d.mts +8 -0
- package/api/theme-edit/_parts.mjs +120 -36
- package/api/theme-edit/_png.d.mts +24 -0
- package/api/theme-edit/_png.mjs +99 -0
- package/api/theme-edit/_preview-app.d.mts +16 -0
- package/api/theme-edit/_preview-app.mjs +52 -18
- package/api/theme-edit/_preview.d.mts +44 -26
- package/api/theme-edit/_preview.mjs +255 -67
- package/api/theme-edit/_project.d.mts +12 -1
- package/api/theme-edit/_project.mjs +16 -1
- package/api/theme-edit/_settings.d.mts +116 -0
- package/api/theme-edit/_settings.mjs +1197 -58
- package/api/theme-edit/_tables.d.mts +16 -0
- package/api/theme-edit/_tables.mjs +34 -4
- package/api/theme-edit/theme-edit.type.d.mts +15 -2
- package/api/theme-edit/theme-edit.type.mjs +8 -6
- package/api/upgrade/_adapter.d.mts +46 -7
- package/api/upgrade/_adapter.mjs +110 -15
- package/api/upgrade/registry/registry.d.mts +6 -3
- package/api/upgrade/registry/registry.mjs +21 -6
- package/api/upgrade/run/run.mjs +23 -11
- package/api/upgrade/upgrade.doc.mjs +4 -3
- package/assets/component-list.generated.json +1 -1
- package/assets/docs/tree/agent-guidance.doc.mjs +3 -2
- package/assets/docs/tree/checks.doc.mjs +2 -2
- package/assets/docs/tree/host-entry.doc.mjs +4 -0
- package/assets/docs/tree/icon-definitions.doc.mjs +3 -3
- package/assets/docs/tree/icon-sets.doc.mjs +6 -6
- package/assets/docs/tree/problems.doc.mjs +3 -3
- package/assets/docs/tree/render-pages.doc.mjs +17 -3
- package/assets/docs/tree/share-a-page.doc.mjs +5 -5
- package/assets/docs/tree/short-and-findable.doc.mjs +3 -3
- package/assets/docs/tree/troubleshooting.doc.mjs +8 -0
- package/assets/docs/tree/updates.doc.mjs +1 -1
- package/assets/docs/tree/versioning.doc.mjs +1 -1
- package/assets/docs/working-with-ai.doc.mjs +40 -5
- package/assets/docs-routes.generated.json +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/icons/installed-icon-set.doc.mjs +30 -0
- package/assets/search-catalog.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/Avatar/AvatarInteractive.tsx +6 -1
- package/assets/templates/blocks/components/CodeBlock/CodeBlockTerminal.tsx +1 -1
- package/assets/templates/blocks/components/LinkProvider/LinkProviderCustomLink.tsx +3 -1
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat/page.tsx +6 -2
- package/assets/templates/pages/ai-chat-landing/page.tsx +1 -1
- package/assets/templates/pages/blank/page.tsx +4 -2
- package/assets/templates/pages/canvas-editor/page.tsx +3 -1
- package/assets/templates/pages/centered-hero/page.tsx +1 -1
- package/assets/templates/pages/checkout-wizard/page.tsx +1 -1
- package/assets/templates/pages/classic-gallery/page.tsx +1 -1
- package/assets/templates/pages/contact-form/page.tsx +2 -2
- package/assets/templates/pages/course-detail/page.tsx +1 -1
- package/assets/templates/pages/dashboard/page.tsx +24 -8
- package/assets/templates/pages/dashboard-alert-rail/page.tsx +4 -2
- package/assets/templates/pages/dashboard-cohort-funnel/page.tsx +7 -3
- package/assets/templates/pages/dashboard-comparison/page.tsx +5 -2
- package/assets/templates/pages/dashboard-composition/page.tsx +10 -4
- package/assets/templates/pages/dashboard-progress/page.tsx +6 -3
- package/assets/templates/pages/dashboard-scorecard/page.tsx +17 -8
- package/assets/templates/pages/detail-page/page.tsx +22 -5
- package/assets/templates/pages/documentation/page.tsx +4 -2
- package/assets/templates/pages/documentation-design/page.tsx +5 -2
- package/assets/templates/pages/documentation-technical/page.tsx +4 -2
- package/assets/templates/pages/editor/page.tsx +28 -9
- package/assets/templates/pages/file-explorer/page.tsx +3 -1
- package/assets/templates/pages/form-two-column/page.tsx +1 -1
- package/assets/templates/pages/form-wizard/page.tsx +1 -1
- package/assets/templates/pages/form-wizard-dialog/page.tsx +3 -1
- package/assets/templates/pages/form-wizard-inline/page.tsx +1 -1
- package/assets/templates/pages/form-wizard-vertical/page.tsx +1 -1
- package/assets/templates/pages/gallery-hero/page.tsx +1 -1
- package/assets/templates/pages/ide/page.tsx +7 -2
- package/assets/templates/pages/kanban-board/page.tsx +10 -4
- package/assets/templates/pages/library/page.tsx +31 -61
- package/assets/templates/pages/login/page.tsx +4 -2
- package/assets/templates/pages/login-card/page.tsx +4 -2
- package/assets/templates/pages/login-split/page.tsx +3 -2
- package/assets/templates/pages/login-sso/page.tsx +4 -4
- package/assets/templates/pages/mixed-gallery/page.tsx +1 -1
- package/assets/templates/pages/payment-form/page.tsx +1 -1
- package/assets/templates/pages/product-detail/page.tsx +16 -4
- package/assets/templates/pages/product-gallery/page.tsx +1 -1
- package/assets/templates/pages/settings/page.tsx +10 -4
- package/assets/templates/pages/settings-dialog/page.tsx +5 -6
- package/assets/templates/pages/settings-sidebar/page.tsx +39 -13
- package/assets/templates/pages/side-gallery/page.tsx +1 -1
- package/assets/templates/pages/table/page.tsx +2 -2
- package/assets/templates/pages/table-filter/page.tsx +21 -6
- package/assets/templates/pages/table-grouped/page.tsx +23 -2
- package/assets/templates/pages/table-inbox/page.tsx +82 -32
- package/assets/templates/pages/theme-showcase/page.tsx +3 -2
- package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +12 -12
- package/assets/templates/themes/butter/butterTheme.ts +197 -4
- package/assets/templates/themes/chocolate/chocolateTheme.ts +72 -8
- package/assets/templates/themes/gothic/gothicPaletteRefs.generated.ts +3 -3
- package/assets/templates/themes/gothic/gothicTheme.ts +114 -4
- package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +8 -8
- package/assets/templates/themes/matcha/matchaTheme.ts +48 -12
- package/assets/templates/themes/neutral/neutralTheme.ts +29 -0
- package/assets/templates/themes/stone/stonePaletteRefs.generated.ts +2 -2
- package/assets/templates/themes/stone/stoneTheme.ts +69 -0
- package/assets/templates/themes/y2k/y2kPaletteRefs.generated.ts +9 -9
- package/assets/templates/themes/y2k/y2kTheme.ts +249 -14
- package/authoring/codemod/parse.d.mts +0 -36
- package/authoring/codemod/parse.mjs +62 -41
- package/authoring/config/config.doc.mjs +1 -1
- package/authoring/config/parse.d.mts +0 -47
- package/authoring/config/parse.mjs +128 -103
- package/authoring/config/type.ts +4 -3
- package/authoring/debug/parse.d.mts +2 -2
- package/authoring/discover/parse.d.mts +2 -2
- package/authoring/discover/parse.mjs +52 -38
- package/authoring/discover/type.ts +2 -1
- package/authoring/doctypes/_schema.d.mts +834 -950
- package/authoring/doctypes/_schema.mjs +863 -825
- package/authoring/doctypes/command/parse.mjs +2 -2
- package/authoring/doctypes/component/parse.mjs +2 -2
- package/authoring/doctypes/enum/parse.mjs +2 -2
- package/authoring/doctypes/hook/parse.mjs +2 -2
- package/authoring/doctypes/icon-definition/icon-definition.doc.mjs +1 -1
- package/authoring/doctypes/icon-definition/parse.d.mts +0 -24
- package/authoring/doctypes/icon-definition/parse.mjs +59 -43
- package/authoring/doctypes/icon-set/parse.d.mts +0 -75
- package/authoring/doctypes/icon-set/parse.mjs +239 -210
- package/authoring/doctypes/legacy.mjs +3 -3
- package/authoring/doctypes/namespace/parse.mjs +2 -2
- package/authoring/doctypes/reference/parse.mjs +2 -2
- package/authoring/doctypes/schema/parse.mjs +2 -2
- package/authoring/doctypes/template/parse.d.mts +0 -101
- package/authoring/doctypes/template/parse.mjs +131 -106
- package/authoring/doctypes/theme/parse.d.mts +0 -23
- package/authoring/doctypes/theme/parse.mjs +52 -36
- package/authoring/gap-report/parse.d.mts +1 -1
- package/authoring/integration/integration.doc.mjs +8 -0
- package/authoring/integration/schema.d.mts +14 -3
- package/authoring/integration/schema.mjs +20 -2
- package/authoring/integration/type.ts +14 -0
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/build.mjs +27 -13
- package/clients/cli/commands/component.mjs +14 -3
- package/clients/cli/commands/discover.doc.mjs +2 -2
- package/clients/cli/commands/discover.mjs +20 -3
- package/clients/cli/commands/docs.doc.mjs +11 -9
- package/clients/cli/commands/docs.mjs +50 -21
- package/clients/cli/commands/experimental/icon.mjs +330 -227
- package/clients/cli/commands/experimental/render.mjs +16 -1
- package/clients/cli/commands/experimental/theme.mjs +42 -17
- package/clients/cli/commands/experimental-icon-add.doc.mjs +1 -1
- package/clients/cli/commands/experimental-icon-map.doc.mjs +4 -1
- package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +4 -1
- package/clients/cli/commands/experimental-icon-new-set.doc.mjs +4 -1
- package/clients/cli/commands/experimental-icon-use.doc.mjs +1 -1
- package/clients/cli/commands/experimental-icon.doc.mjs +1 -1
- package/clients/cli/commands/experimental-render.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
- package/clients/cli/commands/init.doc.mjs +36 -24
- package/clients/cli/commands/integration-check.doc.mjs +1 -1
- package/clients/cli/commands/mcp.doc.mjs +53 -0
- package/clients/cli/commands/mcp.mjs +51 -0
- package/clients/cli/commands/search.mjs +46 -9
- package/clients/cli/commands/template.mjs +3 -2
- package/clients/cli/commands/theme-build.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +12 -2
- package/clients/cli/commands/upgrade.doc.mjs +3 -2
- package/clients/cli/commands.generated.json +1 -1
- package/clients/cli/formatters/index.mjs +52 -6
- package/clients/cli/index.mjs +23 -17
- package/clients/cli/lib/base-gate.mjs +37 -5
- package/clients/cli/lib/define-command.mjs +82 -4
- package/clients/cli/lib/json-shim.mjs +61 -4
- package/clients/cli/lib/manifest.mjs +9 -1
- package/clients/cli/lib/mcp-server.mjs +286 -0
- package/clients/cli/lib/mcp-tools.mjs +405 -0
- package/clients/cli/lib/other-cli-words.mjs +99 -0
- package/clients/cli/lib/stray-option.mjs +27 -1
- package/clients/cli/lib/unknown-command.mjs +326 -11
- package/clients/cli/manifest.generated.json +1 -1
- package/clients/cli/run.mjs +1 -1
- package/foundation/agent-docs/agent-docs.d.mts +49 -1
- package/foundation/agent-docs/agent-docs.mjs +108 -7
- package/foundation/agent-docs/computer-agent-text.mjs +1 -1
- package/foundation/bases/core.d.mts +1 -1
- package/foundation/bases/core.mjs +3 -3
- package/foundation/bases/resolve.d.mts +4 -8
- package/foundation/bases/resolve.mjs +15 -21
- package/foundation/bases/state.d.mts +15 -9
- package/foundation/bases/state.mjs +33 -6
- package/foundation/config/project.d.mts +5 -4
- package/foundation/config/project.mjs +33 -17
- package/foundation/discovery/component-discovery.mjs +15 -28
- package/foundation/discovery/icon-imports.d.mts +66 -0
- package/foundation/discovery/icon-imports.mjs +225 -0
- package/foundation/discovery/icon-ranking.d.mts +12 -2
- package/foundation/discovery/icon-ranking.mjs +197 -10
- package/foundation/discovery/icon-set-checks.mjs +2 -1
- package/foundation/discovery/icon-set-discovery.d.mts +28 -0
- package/foundation/discovery/icon-set-discovery.mjs +42 -0
- package/foundation/discovery/icon-set-writer.d.mts +2 -11
- package/foundation/discovery/icon-set-writer.mjs +3 -29
- package/foundation/discovery/module-exports.d.mts +1 -1
- package/foundation/discovery/module-exports.mjs +136 -33
- package/foundation/discovery/name-roots.d.mts +5 -0
- package/foundation/discovery/name-roots.mjs +11 -0
- package/foundation/discovery/runner-allowlist.d.mts +1 -0
- package/foundation/discovery/runner-allowlist.mjs +2 -0
- package/foundation/discovery/runner-commands.mjs +1 -0
- package/foundation/discovery/template-adapter.d.mts +1 -1
- package/foundation/discovery/template-destination.d.mts +14 -6
- package/foundation/discovery/template-destination.mjs +42 -8
- package/foundation/discovery/template-icons.d.mts +45 -2
- package/foundation/discovery/template-icons.mjs +26 -54
- package/foundation/discovery/template-needs.d.mts +28 -2
- package/foundation/discovery/template-needs.mjs +92 -11
- package/foundation/discovery/theme-discovery.d.mts +8 -0
- package/foundation/discovery/theme-discovery.mjs +23 -6
- package/foundation/discovery/theme-imports.mjs +2 -4
- package/foundation/doc-compiler/parse-readable.mjs +4 -3
- package/foundation/doc-compiler/stored-docs.d.mts +13 -0
- package/foundation/doc-compiler/stored-docs.mjs +74 -3
- package/foundation/env/cli-command.d.mts +68 -10
- package/foundation/env/cli-command.mjs +116 -22
- package/foundation/env/project-scope.d.mts +9 -0
- package/foundation/env/project-scope.mjs +28 -2
- package/foundation/fs/gather-cache.d.mts +23 -0
- package/foundation/fs/gather-cache.mjs +94 -2
- package/foundation/fs/module-loader.d.mts +3 -1
- package/foundation/fs/module-loader.mjs +85 -5
- package/foundation/fs/read-record.mjs +9 -5
- package/foundation/identity/package-names.d.mts +18 -0
- package/foundation/identity/package-names.mjs +19 -0
- package/foundation/identity/providers.mjs +3 -2
- package/foundation/integrations/icon-features.d.mts +63 -0
- package/foundation/integrations/icon-features.mjs +54 -0
- package/foundation/integrations/integrations.d.mts +13 -1
- package/foundation/integrations/integrations.mjs +47 -6
- package/foundation/integrations/pack-state.d.mts +21 -0
- package/foundation/integrations/pack-state.mjs +42 -19
- package/foundation/integrations/validate-contributions.d.mts +11 -3
- package/foundation/integrations/validate-contributions.mjs +51 -13
- package/foundation/release/cache.d.mts +13 -1
- package/foundation/release/cache.mjs +94 -14
- package/foundation/release/notices.d.mts +15 -0
- package/foundation/release/notices.mjs +111 -7
- package/foundation/release/project.d.mts +3 -4
- package/foundation/release/project.mjs +5 -6
- package/foundation/render/client-bundle.d.mts +126 -0
- package/foundation/render/client-bundle.mjs +565 -0
- package/foundation/render/cut-short.d.mts +7 -1
- package/foundation/render/cut-short.mjs +46 -6
- package/foundation/render/embedded-imports.d.mts +4 -3
- package/foundation/render/embedded-imports.mjs +13 -8
- package/foundation/render/esbuild-dependency.d.mts +14 -0
- package/foundation/render/esbuild-dependency.mjs +41 -0
- package/foundation/render/file-header.mjs +5 -4
- package/foundation/render/page-worker.mjs +562 -86
- package/foundation/render/picture-chrome.mjs +54 -29
- package/foundation/render/picture-playwright.mjs +78 -42
- package/foundation/render/picture-window.d.mts +33 -0
- package/foundation/render/picture-window.mjs +78 -0
- package/foundation/render/render-page.d.mts +55 -4
- package/foundation/render/render-page.mjs +199 -28
- package/foundation/render/restore-folder.d.mts +13 -0
- package/foundation/render/restore-folder.mjs +30 -0
- package/foundation/render/served-packages.d.mts +2 -1
- package/foundation/render/served-packages.mjs +5 -3
- package/foundation/render/ts-paths.d.mts +11 -0
- package/foundation/render/ts-paths.mjs +27 -2
- package/foundation/render/value-uses.d.mts +43 -0
- package/foundation/render/value-uses.mjs +110 -0
- package/foundation/response/error-codes.d.mts +2 -1
- package/foundation/response/error-codes.doc.mjs +7 -1
- package/foundation/response/error-codes.mjs +10 -2
- package/foundation/response/response-types.doc.mjs +12 -12
- package/foundation/runtime/package-root.d.mts +8 -0
- package/foundation/runtime/package-root.mjs +20 -0
- package/foundation/suggest/other-command.d.mts +11 -0
- package/foundation/suggest/other-command.mjs +1 -1
- package/foundation/text/icon-id.d.mts +20 -0
- package/foundation/text/icon-id.mjs +40 -0
- package/foundation/text/icon-set-next.d.mts +25 -0
- package/foundation/text/icon-set-next.mjs +29 -0
- package/foundation/xle/browser.d.mts +2 -2
- package/package.json +7 -6
|
@@ -0,0 +1,565 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file The page's script in a rendered file: the page's modules and the
|
|
5
|
+
* modules they use, bundled by esbuild (a dependency of the CLI, loaded only
|
|
6
|
+
* here) into one script that draws the page in the browser over its server
|
|
7
|
+
* markup, so state, effects and event handlers work. No network, no `eval`,
|
|
8
|
+
* no other file.
|
|
9
|
+
* @input The page's entry file, esbuild, and how the server compiled and
|
|
10
|
+
* resolved the page's modules
|
|
11
|
+
* @output One script's text, safe inside an HTML `<script>` element
|
|
12
|
+
* @position foundation/render — used by page-worker.mjs
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import * as fs from 'node:fs';
|
|
16
|
+
import {builtinModules} from 'node:module';
|
|
17
|
+
import * as path from 'node:path';
|
|
18
|
+
import {stripVTControlCharacters} from 'node:util';
|
|
19
|
+
import vm from 'node:vm';
|
|
20
|
+
import {SOURCE_TYPE} from './source-block.mjs';
|
|
21
|
+
|
|
22
|
+
/** The id of the element that holds the page's markup in a rendered file. */
|
|
23
|
+
export const ROOT_ID = 'astryx-render-root';
|
|
24
|
+
|
|
25
|
+
/** The module the page's script reads a carried file from. */
|
|
26
|
+
export const CARRIED_MODULE = 'astryx:carried';
|
|
27
|
+
|
|
28
|
+
/** An address that leaves the file: another site, mail or a phone call. */
|
|
29
|
+
export const LINK_OUT = /^(https?:|mailto:|tel:|\/\/)/i;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* What the file does so that the page works in a viewer's sandboxed frame as
|
|
33
|
+
* it works in an app. A link out of the file opens in a new tab, since the
|
|
34
|
+
* frame cannot follow it; a link the page handles itself (it cancels the
|
|
35
|
+
* click) or gives a target keeps its way. A form submits through its submit
|
|
36
|
+
* event: the file cancels the browser's own submission and fires the event
|
|
37
|
+
* itself, since a frame that blocks form submission never fires it, and a
|
|
38
|
+
* file has no server to send a form to; a form whose action is another
|
|
39
|
+
* site's address submits as the browser submits it. Enter in a form's only text field
|
|
40
|
+
* submits a form with no submit button, as a browser does; with a button,
|
|
41
|
+
* the browser clicks it.
|
|
42
|
+
*/
|
|
43
|
+
export const IN_A_VIEWER = `{
|
|
44
|
+
const out = ${LINK_OUT};
|
|
45
|
+
const typed = /^(text|search|url|tel|email|password|date|month|week|time|datetime-local|number)$/;
|
|
46
|
+
const elsewhere = (form, submitter) =>
|
|
47
|
+
out.test(((submitter && submitter.getAttribute('formaction')) ?? form.getAttribute('action') ?? '').trim());
|
|
48
|
+
const submit = (form, submitter) => {
|
|
49
|
+
if (!form.noValidate && !(submitter && submitter.formNoValidate) && !form.reportValidity()) return;
|
|
50
|
+
form.dispatchEvent(typeof SubmitEvent === 'function'
|
|
51
|
+
? new SubmitEvent('submit', {bubbles: true, cancelable: true, submitter})
|
|
52
|
+
: new Event('submit', {bubbles: true, cancelable: true}));
|
|
53
|
+
};
|
|
54
|
+
document.addEventListener('click', event => {
|
|
55
|
+
if (event.defaultPrevented || !(event.target instanceof Element)) return;
|
|
56
|
+
const link = event.target.closest('a[href]');
|
|
57
|
+
if (link) {
|
|
58
|
+
if (!link.hasAttribute('target') && out.test(link.getAttribute('href').trim())) {
|
|
59
|
+
link.target = '_blank';
|
|
60
|
+
link.rel = [...new Set([...link.rel.split(/\\s+/).filter(Boolean), 'noopener', 'noreferrer'])].join(' ');
|
|
61
|
+
}
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const button = event.target.closest('button, input');
|
|
65
|
+
if (!button || !button.form || (button.type !== 'submit' && button.type !== 'image')) return;
|
|
66
|
+
if (elsewhere(button.form, button)) return;
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
submit(button.form, button);
|
|
69
|
+
});
|
|
70
|
+
document.addEventListener('keydown', event => {
|
|
71
|
+
const field = event.target;
|
|
72
|
+
if (event.key !== 'Enter' || event.defaultPrevented || event.isComposing) return;
|
|
73
|
+
if (!(field instanceof HTMLInputElement) || !field.form || !typed.test(field.type)) return;
|
|
74
|
+
const controls = [...field.form.elements];
|
|
75
|
+
if (controls.some(c => c.type === 'submit' || c.type === 'image')) return;
|
|
76
|
+
if (controls.filter(c => c instanceof HTMLInputElement && typed.test(c.type)).length !== 1) return;
|
|
77
|
+
if (elsewhere(field.form, null)) return;
|
|
78
|
+
event.preventDefault();
|
|
79
|
+
submit(field.form, null);
|
|
80
|
+
});
|
|
81
|
+
}`;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Storage for a page in a viewer that blocks it. A frame without
|
|
85
|
+
* allow-same-origin has an opaque origin, where touching `localStorage` or
|
|
86
|
+
* `sessionStorage` throws. Then the page gets an in-memory storage for each
|
|
87
|
+
* one that acts as the browser's does: its methods, and its items read,
|
|
88
|
+
* written, listed and deleted as properties (`localStorage.theme`,
|
|
89
|
+
* `Object.keys(localStorage)`). What it saves lasts until the page closes.
|
|
90
|
+
* A file opened from disk or on a real origin keeps its real storage. This
|
|
91
|
+
* runs as the script's first module, before any of the page's own modules.
|
|
92
|
+
*/
|
|
93
|
+
export const VIEWER_STORAGE = `for (const name of ['localStorage', 'sessionStorage']) {
|
|
94
|
+
let usable = true;
|
|
95
|
+
try {
|
|
96
|
+
window[name].getItem('');
|
|
97
|
+
} catch {
|
|
98
|
+
usable = false;
|
|
99
|
+
}
|
|
100
|
+
if (usable) continue;
|
|
101
|
+
const items = new Map();
|
|
102
|
+
const methods = {
|
|
103
|
+
get length() {
|
|
104
|
+
return items.size;
|
|
105
|
+
},
|
|
106
|
+
key: index => [...items.keys()][index] ?? null,
|
|
107
|
+
getItem: key => (items.has(String(key)) ? items.get(String(key)) : null),
|
|
108
|
+
setItem: (key, value) => {
|
|
109
|
+
items.set(String(key), String(value));
|
|
110
|
+
},
|
|
111
|
+
removeItem: key => {
|
|
112
|
+
items.delete(String(key));
|
|
113
|
+
},
|
|
114
|
+
clear: () => {
|
|
115
|
+
items.clear();
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
const storage = new Proxy(methods, {
|
|
119
|
+
get: (target, key, receiver) =>
|
|
120
|
+
key in target || typeof key !== 'string' ? Reflect.get(target, key, receiver) : items.get(key),
|
|
121
|
+
set: (target, key, value) => {
|
|
122
|
+
if (typeof key === 'string' && !(key in target)) items.set(key, String(value));
|
|
123
|
+
return true;
|
|
124
|
+
},
|
|
125
|
+
has: (target, key) => (typeof key === 'string' && items.has(key)) || key in target,
|
|
126
|
+
deleteProperty: (target, key) => {
|
|
127
|
+
if (typeof key === 'string' && !(key in target)) items.delete(key);
|
|
128
|
+
return true;
|
|
129
|
+
},
|
|
130
|
+
ownKeys: () => [...items.keys()],
|
|
131
|
+
getOwnPropertyDescriptor: (target, key) =>
|
|
132
|
+
typeof key === 'string' && items.has(key)
|
|
133
|
+
? {value: items.get(key), writable: true, enumerable: true, configurable: true}
|
|
134
|
+
: undefined,
|
|
135
|
+
});
|
|
136
|
+
try {
|
|
137
|
+
Object.defineProperty(window, name, {configurable: true, enumerable: true, get: () => storage});
|
|
138
|
+
} catch {
|
|
139
|
+
// A window that refuses the property keeps the storage it has.
|
|
140
|
+
}
|
|
141
|
+
}`;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Copying for a page in a viewer that blocks the Clipboard API. It falls
|
|
145
|
+
* back to the copy command where Core's clipboard hook does: when the frame's
|
|
146
|
+
* permissions policy refuses clipboard-write, when `writeText` refuses the
|
|
147
|
+
* write (NotAllowedError), and also when the frame leaves `navigator.clipboard`
|
|
148
|
+
* out or `writeText` throws at once. The copy command runs only in a click or
|
|
149
|
+
* a key press, as in the hook. A write that resolves copied the text; a
|
|
150
|
+
* failed fallback rejects with the browser's own refusal, or NotAllowedError,
|
|
151
|
+
* so the page's own error path runs. `readText` rejects with NotAllowedError,
|
|
152
|
+
* as a browser does. The hook's helpers are private to Core and run only in
|
|
153
|
+
* pages that use the hook; this runs in the file's script before any of the
|
|
154
|
+
* page's modules, for every page.
|
|
155
|
+
*/
|
|
156
|
+
export const VIEWER_CLIPBOARD = `{
|
|
157
|
+
const refused = message => new DOMException(message, 'NotAllowedError');
|
|
158
|
+
const copy = text =>
|
|
159
|
+
new Promise((resolve, reject) => {
|
|
160
|
+
if (navigator.userActivation?.isActive === false) {
|
|
161
|
+
reject(refused('The copy command runs only in a click or a key press.'));
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
let written = false;
|
|
165
|
+
const write = event => {
|
|
166
|
+
if (event.clipboardData == null) return;
|
|
167
|
+
event.clipboardData.setData('text/plain', String(text));
|
|
168
|
+
event.preventDefault();
|
|
169
|
+
event.stopImmediatePropagation();
|
|
170
|
+
written = true;
|
|
171
|
+
};
|
|
172
|
+
window.addEventListener('copy', write, true);
|
|
173
|
+
let copied = false;
|
|
174
|
+
try {
|
|
175
|
+
copied = document.execCommand('copy');
|
|
176
|
+
} catch {
|
|
177
|
+
copied = false;
|
|
178
|
+
} finally {
|
|
179
|
+
window.removeEventListener('copy', write, true);
|
|
180
|
+
}
|
|
181
|
+
if (copied && written) resolve();
|
|
182
|
+
else reject(refused('The browser did not copy the text.'));
|
|
183
|
+
});
|
|
184
|
+
const policy = document.permissionsPolicy ?? document.featurePolicy;
|
|
185
|
+
const writeAllowed = () =>
|
|
186
|
+
typeof policy?.allowsFeature === 'function' ? policy.allowsFeature('clipboard-write') : true;
|
|
187
|
+
const clipboard = navigator.clipboard;
|
|
188
|
+
if (clipboard == null) {
|
|
189
|
+
const fallback = {
|
|
190
|
+
writeText: copy,
|
|
191
|
+
readText: () => Promise.reject(refused('This frame does not let a page read the clipboard.')),
|
|
192
|
+
};
|
|
193
|
+
try {
|
|
194
|
+
Object.defineProperty(navigator, 'clipboard', {configurable: true, enumerable: true, get: () => fallback});
|
|
195
|
+
} catch {
|
|
196
|
+
// A navigator that refuses the property keeps what it has.
|
|
197
|
+
}
|
|
198
|
+
} else if (typeof clipboard.writeText === 'function') {
|
|
199
|
+
const writeText = clipboard.writeText;
|
|
200
|
+
try {
|
|
201
|
+
clipboard.writeText = function (text) {
|
|
202
|
+
if (!writeAllowed()) return copy(text);
|
|
203
|
+
let asked;
|
|
204
|
+
try {
|
|
205
|
+
asked = writeText.call(this, text);
|
|
206
|
+
} catch {
|
|
207
|
+
return copy(text);
|
|
208
|
+
}
|
|
209
|
+
return Promise.resolve(asked).catch(error =>
|
|
210
|
+
error instanceof DOMException && error.name === 'NotAllowedError'
|
|
211
|
+
? copy(text).catch(() => Promise.reject(error))
|
|
212
|
+
: Promise.reject(error),
|
|
213
|
+
);
|
|
214
|
+
};
|
|
215
|
+
} catch {
|
|
216
|
+
// A clipboard that refuses the property keeps its own writeText.
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}`;
|
|
220
|
+
|
|
221
|
+
/** The namespace of the module that fills in what a viewer's frame blocks: storage and the clipboard. */
|
|
222
|
+
const VIEWER = 'astryx-viewer';
|
|
223
|
+
const PAGE = 'astryx-page';
|
|
224
|
+
|
|
225
|
+
/** The namespace of the module that mounts the page. */
|
|
226
|
+
const MOUNT = 'astryx-mount';
|
|
227
|
+
|
|
228
|
+
/** An import of a module that is part of Node. */
|
|
229
|
+
const NODE_MODULE = new RegExp(
|
|
230
|
+
`^(node:.*|(${builtinModules.filter(name => !name.startsWith('_')).map(escapeRegExp).join('|')})(/.*)?)$`,
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* An import of one of `names`, or of a file inside one.
|
|
235
|
+
* @param {string[]} names
|
|
236
|
+
*/
|
|
237
|
+
const packageFilter = names => new RegExp(`^(${names.map(escapeRegExp).join('|')})(/.*)?$`);
|
|
238
|
+
|
|
239
|
+
/** @param {string} text */
|
|
240
|
+
function escapeRegExp(text) {
|
|
241
|
+
return text.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&');
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* The file an esbuild message names: a page file is named with its
|
|
246
|
+
* namespace (`astryx-page:/…/page.tsx`), and the mount is the render's own,
|
|
247
|
+
* so it names none.
|
|
248
|
+
* @param {string} file
|
|
249
|
+
* @returns {string | null}
|
|
250
|
+
*/
|
|
251
|
+
function locatedFile(file) {
|
|
252
|
+
if (file.startsWith(`${MOUNT}:`)) return null;
|
|
253
|
+
if (file.startsWith(`${PAGE}:`)) return file.slice(PAGE.length + 1);
|
|
254
|
+
return path.resolve(file);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** @param {string} file */
|
|
258
|
+
const loaderFor = file =>
|
|
259
|
+
/\.[cm]?tsx$/.test(file) ? 'tsx' : /\.[cm]?ts$/.test(file) ? 'ts' : 'jsx';
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Reads a carried file from the page's embedded source, once, by its
|
|
263
|
+
* SHA-256, as a data: URI with the `prefix` it needs (`data:image/png;base64`).
|
|
264
|
+
*/
|
|
265
|
+
const CARRIED_SOURCE = `let files;
|
|
266
|
+
export function carried(sha256, prefix) {
|
|
267
|
+
if (files === undefined) {
|
|
268
|
+
files = new Map();
|
|
269
|
+
// The CLI writes its source block last, as readSourceBlock reads it.
|
|
270
|
+
const blocks = document.querySelectorAll('script[type="${SOURCE_TYPE}"]');
|
|
271
|
+
const block = blocks[blocks.length - 1];
|
|
272
|
+
for (const file of block ? JSON.parse(block.textContent).files : []) files.set(file.sha256, file.base64);
|
|
273
|
+
}
|
|
274
|
+
return prefix + ',' + (files.get(sha256) ?? '');
|
|
275
|
+
}
|
|
276
|
+
`;
|
|
277
|
+
|
|
278
|
+
/** Files a package may import for their address; the page's own are inlined before esbuild sees them. */
|
|
279
|
+
const ASSET_LOADERS = Object.fromEntries(
|
|
280
|
+
[
|
|
281
|
+
'.png',
|
|
282
|
+
'.jpg',
|
|
283
|
+
'.jpeg',
|
|
284
|
+
'.gif',
|
|
285
|
+
'.webp',
|
|
286
|
+
'.avif',
|
|
287
|
+
'.svg',
|
|
288
|
+
'.ico',
|
|
289
|
+
'.woff',
|
|
290
|
+
'.woff2',
|
|
291
|
+
'.ttf',
|
|
292
|
+
'.otf',
|
|
293
|
+
'.mp3',
|
|
294
|
+
'.mp4',
|
|
295
|
+
'.webm',
|
|
296
|
+
].map(ext => [ext, /** @type {const} */ ('dataurl')]),
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Why the page's script cannot run in one file.
|
|
301
|
+
*/
|
|
302
|
+
export class BundleError extends Error {
|
|
303
|
+
/**
|
|
304
|
+
* @param {string} message
|
|
305
|
+
* @param {Record<string, unknown>} [detail]
|
|
306
|
+
* @param {unknown} [compile] the error of one of the page's own files that
|
|
307
|
+
* does not compile, which the render reports as a static import's
|
|
308
|
+
* @param {{source: string, line: number, names: string[], module?: string}} [missingExport]
|
|
309
|
+
* a named import or a package subpath that its module does not export:
|
|
310
|
+
* the page's file that imports it, the line, the names and the module
|
|
311
|
+
*/
|
|
312
|
+
constructor(message, detail = {}, compile = undefined, missingExport = undefined) {
|
|
313
|
+
super(message);
|
|
314
|
+
this.detail = detail;
|
|
315
|
+
this.compile = compile;
|
|
316
|
+
this.missingExport = missingExport;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Text that runs the same as `code` and cannot end its `<script>` element or
|
|
322
|
+
* be read as the render's embedded source. `</script` and `<!--` only appear
|
|
323
|
+
* in strings, template literals and regular expressions, where `\x3C` is the
|
|
324
|
+
* same `<`.
|
|
325
|
+
* @param {string} code
|
|
326
|
+
*/
|
|
327
|
+
export function scriptSafe(code) {
|
|
328
|
+
return code
|
|
329
|
+
.replace(/<(?=\/script)/gi, '\\x3C')
|
|
330
|
+
.replace(/<!--/g, '\\x3C!--')
|
|
331
|
+
.replace(/x-astryx-source/g, 'x-astryx\\x2dsource');
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Build the page's script.
|
|
336
|
+
* @param {{
|
|
337
|
+
* esbuild: any,
|
|
338
|
+
* entry: string,
|
|
339
|
+
* source: (file: string) => {contents: string, loader: 'tsx' | 'ts' | 'jsx'} | null,
|
|
340
|
+
* isPageFile: (file: string) => boolean,
|
|
341
|
+
* resolveFile: (name: string, dir: string) => string | null,
|
|
342
|
+
* packageDir: (name: string, importerDir: string) => string | null,
|
|
343
|
+
* builtin: (name: string) => boolean,
|
|
344
|
+
* describe: (file: string) => string,
|
|
345
|
+
* oneCopy?: string[],
|
|
346
|
+
* }} options
|
|
347
|
+
* `source` compiles one of the page's own files as the server compiled it
|
|
348
|
+
* (null for any other file, which esbuild loads); `isPageFile` tells the
|
|
349
|
+
* files `source` compiles (the page's own, and a module outside
|
|
350
|
+
* node_modules that the project's path aliases reach), which alone go
|
|
351
|
+
* through the build's plugin; `resolveFile` finds a relative import of one of them with
|
|
352
|
+
* the extensions the server tries; `packageDir`
|
|
353
|
+
* names the folder a package import resolves from when it must come from
|
|
354
|
+
* the copy the server loaded (React outside a project), else null;
|
|
355
|
+
* `builtin` tells a Node built-in; `describe` names a file for a message;
|
|
356
|
+
* `oneCopy` names the packages every module, a package's too, takes from
|
|
357
|
+
* the one copy `packageDir` names (React outside a project).
|
|
358
|
+
* @returns {Promise<{code: string, modules: number}>}
|
|
359
|
+
*/
|
|
360
|
+
export async function bundleForBrowser({
|
|
361
|
+
esbuild,
|
|
362
|
+
entry,
|
|
363
|
+
source,
|
|
364
|
+
isPageFile,
|
|
365
|
+
resolveFile,
|
|
366
|
+
packageDir,
|
|
367
|
+
builtin,
|
|
368
|
+
describe,
|
|
369
|
+
oneCopy = [],
|
|
370
|
+
}) {
|
|
371
|
+
// A page whose script throws, in render or in an effect (a cookie write in
|
|
372
|
+
// a frame that blocks cookies, say), keeps its first paint: React would
|
|
373
|
+
// empty the root.
|
|
374
|
+
const mount =
|
|
375
|
+
`import 'astryx:viewer';import {Component, createElement} from 'react';import {createRoot} from 'react-dom/client';import Page from ${JSON.stringify(entry)};` +
|
|
376
|
+
`${IN_A_VIEWER}` +
|
|
377
|
+
`const root = document.getElementById(${JSON.stringify(ROOT_ID)});const painted = root.innerHTML;` +
|
|
378
|
+
`class FirstPaint extends Component {constructor(props) {super(props);this.state = {failed: false};}` +
|
|
379
|
+
`static getDerivedStateFromError() {return {failed: true};}` +
|
|
380
|
+
`render() {return this.state.failed ? createElement('div', {style: {display: 'contents'}, dangerouslySetInnerHTML: {__html: painted}}) : this.props.children;}}` +
|
|
381
|
+
`createRoot(root).render(createElement(FirstPaint, null, createElement(Page)));`;
|
|
382
|
+
// Only the page's own files and the mount go through this plugin: esbuild
|
|
383
|
+
// resolves and loads every package file itself, which keeps the build fast.
|
|
384
|
+
// A package file comes back here only for an import every module must take
|
|
385
|
+
// from one copy (`oneCopy`) or for a Node module, which is refused.
|
|
386
|
+
/** @param {any} args */
|
|
387
|
+
const resolveImport = async args => {
|
|
388
|
+
if (args.pluginData?.astryx) return undefined;
|
|
389
|
+
const name = args.path.split('?')[0];
|
|
390
|
+
if (name.startsWith('.') || path.isAbsolute(name)) {
|
|
391
|
+
const file = resolveFile(name, args.resolveDir);
|
|
392
|
+
if (!file) return undefined;
|
|
393
|
+
return isPageFile(file) ? {path: file, namespace: PAGE} : {path: file};
|
|
394
|
+
}
|
|
395
|
+
const resolveDir = packageDir(name, args.resolveDir) ?? args.resolveDir;
|
|
396
|
+
// A package can map a Node module for the browser (`"browser": {"fs":
|
|
397
|
+
// false}`), and an installed package can stand in for one (`events`),
|
|
398
|
+
// so a Node module is refused only when nothing resolves it.
|
|
399
|
+
const found = await build.resolve(name, {
|
|
400
|
+
kind: args.kind,
|
|
401
|
+
resolveDir,
|
|
402
|
+
importer: args.importer,
|
|
403
|
+
pluginData: {astryx: true},
|
|
404
|
+
});
|
|
405
|
+
// A module a package maps to `false` comes back with no namespace:
|
|
406
|
+
// esbuild's own resolution gives it as an empty module.
|
|
407
|
+
if (found.errors.length === 0) {
|
|
408
|
+
if (found.namespace === '') return undefined;
|
|
409
|
+
return found.namespace === 'file' && isPageFile(found.path)
|
|
410
|
+
? {...found, namespace: PAGE}
|
|
411
|
+
: found;
|
|
412
|
+
}
|
|
413
|
+
if (builtin(name)) {
|
|
414
|
+
return {
|
|
415
|
+
errors: [
|
|
416
|
+
{
|
|
417
|
+
text: `${describe(args.importer && args.namespace !== MOUNT ? args.importer : entry)} loads ${name}, which is part of Node and not of a browser.`,
|
|
418
|
+
},
|
|
419
|
+
],
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
return {errors: found.errors};
|
|
423
|
+
};
|
|
424
|
+
/** @type {any} */
|
|
425
|
+
let build;
|
|
426
|
+
/** @type {any} */
|
|
427
|
+
const plugin = {
|
|
428
|
+
name: 'astryx-page',
|
|
429
|
+
setup(/** @type {any} */ setupBuild) {
|
|
430
|
+
build = setupBuild;
|
|
431
|
+
// An image the page imports comes from the embedded source, which
|
|
432
|
+
// carries it already, so the script holds no copy of its own.
|
|
433
|
+
build.onResolve({filter: /^astryx:carried$/}, () => ({
|
|
434
|
+
path: 'carried',
|
|
435
|
+
namespace: 'astryx-carried',
|
|
436
|
+
}));
|
|
437
|
+
build.onLoad({filter: /.*/, namespace: 'astryx-carried'}, () => ({
|
|
438
|
+
contents: CARRIED_SOURCE,
|
|
439
|
+
loader: 'js',
|
|
440
|
+
}));
|
|
441
|
+
build.onResolve({filter: /^astryx:mount$/}, () => ({path: 'mount', namespace: MOUNT}));
|
|
442
|
+
build.onResolve({filter: /^astryx:viewer$/, namespace: MOUNT}, () => ({path: 'viewer', namespace: VIEWER}));
|
|
443
|
+
build.onLoad({filter: /.*/, namespace: VIEWER}, () => ({contents: `${VIEWER_STORAGE}\n${VIEWER_CLIPBOARD}`, loader: 'js'}));
|
|
444
|
+
build.onLoad({filter: /.*/, namespace: MOUNT}, () => ({
|
|
445
|
+
contents: mount,
|
|
446
|
+
loader: 'js',
|
|
447
|
+
resolveDir: path.dirname(entry),
|
|
448
|
+
}));
|
|
449
|
+
build.onResolve({filter: /.*/, namespace: MOUNT}, resolveImport);
|
|
450
|
+
build.onResolve({filter: /.*/, namespace: PAGE}, resolveImport);
|
|
451
|
+
if (oneCopy.length > 0) {
|
|
452
|
+
build.onResolve({filter: packageFilter(oneCopy)}, resolveImport);
|
|
453
|
+
}
|
|
454
|
+
build.onResolve({filter: NODE_MODULE}, resolveImport);
|
|
455
|
+
build.onLoad({filter: /.*/, namespace: PAGE}, (/** @type {any} */ args) => {
|
|
456
|
+
const resolveDir = path.dirname(args.path);
|
|
457
|
+
// Stylesheets are already in the page.
|
|
458
|
+
if (/\.(css|scss|sass|less)$/i.test(args.path)) return {contents: '', loader: 'js'};
|
|
459
|
+
if (/\.json$/i.test(args.path)) {
|
|
460
|
+
return {contents: fs.readFileSync(args.path), loader: 'json', resolveDir};
|
|
461
|
+
}
|
|
462
|
+
const asset = ASSET_LOADERS[path.extname(args.path).toLowerCase()];
|
|
463
|
+
if (asset) return {contents: fs.readFileSync(args.path), loader: asset, resolveDir};
|
|
464
|
+
try {
|
|
465
|
+
const compiled = source(args.path);
|
|
466
|
+
return compiled
|
|
467
|
+
? {...compiled, resolveDir}
|
|
468
|
+
: {contents: fs.readFileSync(args.path), loader: loaderFor(args.path), resolveDir};
|
|
469
|
+
} catch (e) {
|
|
470
|
+
// A page file that does not compile, such as one the page loads
|
|
471
|
+
// lazily: the render reports it as a static import's.
|
|
472
|
+
return {errors: [{text: describe(args.path), detail: {compile: e}}]};
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
// A package's own stylesheet import adds nothing to the script.
|
|
476
|
+
build.onLoad({filter: /\.(css|scss|sass|less)$/i}, () => ({
|
|
477
|
+
contents: '',
|
|
478
|
+
loader: 'js',
|
|
479
|
+
}));
|
|
480
|
+
},
|
|
481
|
+
};
|
|
482
|
+
/** @type {any} */
|
|
483
|
+
let result;
|
|
484
|
+
try {
|
|
485
|
+
result = await esbuild.build({
|
|
486
|
+
entryPoints: ['astryx:mount'],
|
|
487
|
+
bundle: true,
|
|
488
|
+
write: false,
|
|
489
|
+
metafile: true,
|
|
490
|
+
format: 'iife',
|
|
491
|
+
platform: 'browser',
|
|
492
|
+
// Browsers that viewers run; syntax newer than this, such as a class
|
|
493
|
+
// decorator, is lowered.
|
|
494
|
+
target: 'es2022',
|
|
495
|
+
minify: true,
|
|
496
|
+
charset: 'ascii',
|
|
497
|
+
legalComments: 'eof',
|
|
498
|
+
jsx: 'automatic',
|
|
499
|
+
define: {'process.env.NODE_ENV': '"production"'},
|
|
500
|
+
loader: ASSET_LOADERS,
|
|
501
|
+
logLevel: 'silent',
|
|
502
|
+
plugins: [plugin],
|
|
503
|
+
});
|
|
504
|
+
} catch (e) {
|
|
505
|
+
const first = /** @type {any} */ (e)?.errors?.[0];
|
|
506
|
+
if (!first) throw e;
|
|
507
|
+
if (first.detail?.compile) {
|
|
508
|
+
throw new BundleError(first.text, {}, first.detail.compile);
|
|
509
|
+
}
|
|
510
|
+
const located = first.location?.file ? locatedFile(first.location.file) : null;
|
|
511
|
+
// A named import its module does not export, in one of the page's own
|
|
512
|
+
// files: refused as a build refuses it. The worker names the file and
|
|
513
|
+
// the module, as for the same import on the server.
|
|
514
|
+
const noExport = /^No matching export in "[^"]+" for import "([^"]+)"$/.exec(first.text);
|
|
515
|
+
if (noExport && located && isPageFile(located)) {
|
|
516
|
+
throw new BundleError(first.text, {}, undefined, {
|
|
517
|
+
source: located,
|
|
518
|
+
line: first.location.line,
|
|
519
|
+
names: [noExport[1]],
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
// A package subpath the package's `exports` do not list, likewise.
|
|
523
|
+
const notes = (first.notes ?? []).map((/** @type {any} */ note) => note.text).join('\n');
|
|
524
|
+
const unexported = /^Could not resolve "[^"]+"$/.test(first.text)
|
|
525
|
+
? /The path "([^"]+)" is not exported by package "([^"]+)"/.exec(notes)
|
|
526
|
+
: null;
|
|
527
|
+
if (unexported && located && isPageFile(located)) {
|
|
528
|
+
throw new BundleError(first.text, {}, undefined, {
|
|
529
|
+
source: located,
|
|
530
|
+
line: first.location.line,
|
|
531
|
+
names: [unexported[1]],
|
|
532
|
+
module: unexported[2],
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
const where = located ? `${describe(located)}:${first.location.line}: ` : '';
|
|
536
|
+
// A message that leads with a file's absolute path names it as the page does.
|
|
537
|
+
const text = stripVTControlCharacters(first.text).replace(
|
|
538
|
+
/^(\S+): /,
|
|
539
|
+
(lead, file) => (path.isAbsolute(file) ? `${describe(file)}: ` : lead),
|
|
540
|
+
);
|
|
541
|
+
throw new BundleError(
|
|
542
|
+
`The page's script cannot be built for the browser: ${where}${text}`,
|
|
543
|
+
{
|
|
544
|
+
...(located ? {module: describe(located), line: first.location.line} : {}),
|
|
545
|
+
},
|
|
546
|
+
);
|
|
547
|
+
} finally {
|
|
548
|
+
esbuild.stop?.();
|
|
549
|
+
}
|
|
550
|
+
const code = scriptSafe(result.outputFiles[0].text);
|
|
551
|
+
try {
|
|
552
|
+
// Parsed here, so a script that would not run never reaches the file.
|
|
553
|
+
new vm.Script(code, {filename: 'page-script.js'});
|
|
554
|
+
} catch (e) {
|
|
555
|
+
throw new BundleError(
|
|
556
|
+
`The page's script could not be written safely into the file: ${/** @type {Error} */ (e).message}`,
|
|
557
|
+
);
|
|
558
|
+
}
|
|
559
|
+
// The modules the script holds: those esbuild kept any of.
|
|
560
|
+
const output = Object.values(result.metafile?.outputs ?? {})[0];
|
|
561
|
+
const modules = Object.values(output?.inputs ?? {}).filter(
|
|
562
|
+
(/** @type {any} */ input) => input.bytesInOutput > 0,
|
|
563
|
+
).length;
|
|
564
|
+
return {code, modules};
|
|
565
|
+
}
|
|
@@ -11,19 +11,25 @@
|
|
|
11
11
|
* or null. `whole` says whether the text is drawn whole once every element
|
|
12
12
|
* of that part keeps its width (`flex-shrink: 0`), measured by applying it
|
|
13
13
|
* in the page and taking it back.
|
|
14
|
+
* A word drawn broken across lines inside it ("Headi" then "ng": a box
|
|
15
|
+
* narrower than the word) comes back too, the word as its `text`, with
|
|
16
|
+
* `broken`; a word broken where it may break (at a hyphen, a slash, a soft
|
|
17
|
+
* hyphen) is not counted.
|
|
14
18
|
* Runs in the page: it uses nothing from outside its own body.
|
|
15
|
-
* @returns {Array<{part: string | null, text: string, whole: boolean}>}
|
|
19
|
+
* @returns {Array<{part: string | null, text: string, whole: boolean, broken?: boolean}>}
|
|
16
20
|
*/
|
|
17
21
|
export function cutShortText(): Array<{
|
|
18
22
|
part: string | null;
|
|
19
23
|
text: string;
|
|
20
24
|
whole: boolean;
|
|
25
|
+
broken?: boolean;
|
|
21
26
|
}>;
|
|
22
27
|
/**
|
|
23
28
|
* @file The text a picture's page draws cut short, measured in the page.
|
|
24
29
|
* @input None: `cutShortText` runs in the page the picture is taken of.
|
|
25
30
|
* @output `cutShortText`: each text the browser draws cut short (an ellipsis
|
|
26
31
|
* or a line clamp, or text drawn past the side of a box that clips it),
|
|
32
|
+
* and each word it breaks across two lines inside the word (`broken`),
|
|
27
33
|
* with the part it sits in and whether keeping that part's width
|
|
28
34
|
* (`flex-shrink: 0` on it, the line the editor offers) draws it whole;
|
|
29
35
|
* `CUT_SHORT_PREFIX`, the line prefix a picture script prints it after.
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* @input None: `cutShortText` runs in the page the picture is taken of.
|
|
6
6
|
* @output `cutShortText`: each text the browser draws cut short (an ellipsis
|
|
7
7
|
* or a line clamp, or text drawn past the side of a box that clips it),
|
|
8
|
+
* and each word it breaks across two lines inside the word (`broken`),
|
|
8
9
|
* with the part it sits in and whether keeping that part's width
|
|
9
10
|
* (`flex-shrink: 0` on it, the line the editor offers) draws it whole;
|
|
10
11
|
* `CUT_SHORT_PREFIX`, the line prefix a picture script prints it after.
|
|
@@ -28,8 +29,12 @@ export const CUT_SHORT_PREFIX = 'astryx-cut-short:';
|
|
|
28
29
|
* or null. `whole` says whether the text is drawn whole once every element
|
|
29
30
|
* of that part keeps its width (`flex-shrink: 0`), measured by applying it
|
|
30
31
|
* in the page and taking it back.
|
|
32
|
+
* A word drawn broken across lines inside it ("Headi" then "ng": a box
|
|
33
|
+
* narrower than the word) comes back too, the word as its `text`, with
|
|
34
|
+
* `broken`; a word broken where it may break (at a hyphen, a slash, a soft
|
|
35
|
+
* hyphen) is not counted.
|
|
31
36
|
* Runs in the page: it uses nothing from outside its own body.
|
|
32
|
-
* @returns {Array<{part: string | null, text: string, whole: boolean}>}
|
|
37
|
+
* @returns {Array<{part: string | null, text: string, whole: boolean, broken?: boolean}>}
|
|
33
38
|
*/
|
|
34
39
|
export function cutShortText() {
|
|
35
40
|
/** @param {Element} el */
|
|
@@ -92,13 +97,43 @@ export function cutShortText() {
|
|
|
92
97
|
};
|
|
93
98
|
/** @param {HTMLElement} el */
|
|
94
99
|
const cutShort = el => ellipsized(el) || clipped(el);
|
|
95
|
-
/**
|
|
100
|
+
/**
|
|
101
|
+
* The words of an element's own text drawn on more than one line: the
|
|
102
|
+
* boxes of a word's letters sit on lines with different tops.
|
|
103
|
+
* @param {HTMLElement} el
|
|
104
|
+
* @returns {string[]}
|
|
105
|
+
*/
|
|
106
|
+
const brokenWords = el => {
|
|
107
|
+
/** @type {string[]} */
|
|
108
|
+
const out = [];
|
|
109
|
+
for (const n of el.childNodes) {
|
|
110
|
+
if (n.nodeType !== 3) continue;
|
|
111
|
+
const s = n.textContent ?? '';
|
|
112
|
+
for (const m of s.matchAll(/\S+/g)) {
|
|
113
|
+
const word = m[0];
|
|
114
|
+
if (word.length < 3 || /[-/\u00AD\u200B\u2010-\u2014]/.test(word))
|
|
115
|
+
continue;
|
|
116
|
+
const range = document.createRange();
|
|
117
|
+
range.setStart(n, m.index ?? 0);
|
|
118
|
+
range.setEnd(n, (m.index ?? 0) + word.length);
|
|
119
|
+
const tops = [...range.getClientRects()]
|
|
120
|
+
.filter(r => r.width > 0 && r.height > 0)
|
|
121
|
+
.map(r => Math.round(r.top));
|
|
122
|
+
if (tops.some(t => Math.abs(t - tops[0]) > 2)) out.push(word);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return out;
|
|
126
|
+
};
|
|
127
|
+
/** @type {Array<{el: HTMLElement, part: string | null, text: string, broken?: boolean}>} */
|
|
96
128
|
const found = [];
|
|
97
129
|
for (const el of document.body.querySelectorAll('*')) {
|
|
98
130
|
if (!(el instanceof HTMLElement)) continue;
|
|
99
131
|
const text = (el.textContent ?? '').replace(/\s+/g, ' ').trim();
|
|
100
|
-
if (text
|
|
101
|
-
|
|
132
|
+
if (!text || !drawn(el)) continue;
|
|
133
|
+
if (cutShort(el)) found.push({el, part: partOf(el), text});
|
|
134
|
+
else
|
|
135
|
+
for (const word of brokenWords(el))
|
|
136
|
+
found.push({el, part: partOf(el), text: word, broken: true});
|
|
102
137
|
}
|
|
103
138
|
/** Whether each text is whole with its part's width kept. @type {Map<string | null, boolean>} */
|
|
104
139
|
const whole = new Map();
|
|
@@ -112,13 +147,18 @@ export function cutShortText() {
|
|
|
112
147
|
document.head.append(keep);
|
|
113
148
|
whole.set(
|
|
114
149
|
part,
|
|
115
|
-
found
|
|
150
|
+
found
|
|
151
|
+
.filter(f => f.part === part)
|
|
152
|
+
.every(f =>
|
|
153
|
+
f.broken ? !brokenWords(f.el).includes(f.text) : !cutShort(f.el),
|
|
154
|
+
),
|
|
116
155
|
);
|
|
117
156
|
keep.remove();
|
|
118
157
|
}
|
|
119
|
-
return found.map(({part, text}) => ({
|
|
158
|
+
return found.map(({part, text, broken}) => ({
|
|
120
159
|
part,
|
|
121
160
|
text,
|
|
122
161
|
whole: whole.get(part) ?? false,
|
|
162
|
+
...(broken ? {broken: true} : {}),
|
|
123
163
|
}));
|
|
124
164
|
}
|