@astryxdesign/cli 0.7.17-canary.gffd1c8e → 0.7.17
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/CHANGELOG.md +1877 -0
- package/README.md +90 -85
- package/api/build/_adapter.d.mts +51 -0
- package/api/build/_adapter.mjs +133 -8
- package/api/build/build.doc.mjs +3 -3
- package/api/build/build.mjs +1 -1
- package/api/build/build.type.d.mts +1 -1
- package/api/build/build.type.mjs +2 -2
- package/api/build/help/help.d.mts +15 -14
- package/api/build/help/help.mjs +65 -6
- package/api/build/kit/kit.mjs +1 -1
- package/api/build/kit/start.mjs +1 -1
- package/api/component/_adapter.d.mts +28 -4
- package/api/component/_adapter.mjs +79 -45
- package/api/component/component.d.mts +1 -1
- package/api/component/component.mjs +18 -7
- package/api/component/detail/blocks/blocks.mjs +1 -2
- package/api/component/detail/showcase/showcase.mjs +19 -8
- package/api/discover/_adapter.d.mts +68 -5
- package/api/discover/_adapter.mjs +311 -63
- package/api/discover/_catalog-view.d.mts +22 -0
- package/api/discover/_catalog-view.mjs +30 -1
- package/api/discover/_icon-set-coverage.d.mts +22 -0
- package/api/discover/_icon-set-coverage.mjs +32 -0
- package/api/discover/detail/detail.d.mts +6 -3
- package/api/discover/detail/detail.mjs +14 -6
- package/api/discover/detail/doc/doc.mjs +1 -1
- package/api/discover/detail/item/item.d.mts +11 -1
- package/api/discover/detail/item/item.mjs +29 -8
- package/api/discover/discover.d.mts +36 -0
- package/api/discover/discover.doc.mjs +1 -1
- package/api/discover/discover.mjs +205 -28
- package/api/discover/discover.type.d.mts +33 -7
- package/api/discover/discover.type.mjs +21 -7
- package/api/discover/search/search.d.mts +22 -0
- package/api/discover/search/search.mjs +293 -70
- package/api/docs/_adapter.d.mts +92 -1
- package/api/docs/_adapter.mjs +264 -14
- package/api/docs/docs.d.mts +4 -2
- package/api/docs/docs.doc.mjs +10 -0
- package/api/docs/docs.mjs +25 -5
- package/api/docs/docs.type.d.mts +48 -0
- package/api/docs/docs.type.mjs +26 -0
- package/api/docs/skills/skills.d.mts +51 -0
- package/api/docs/skills/skills.mjs +216 -0
- package/api/doctor/_adapter.d.mts +254 -9
- package/api/doctor/_adapter.mjs +1228 -50
- package/api/doctor/built-checks.d.mts +39 -3
- package/api/doctor/built-checks.mjs +203 -7
- package/api/doctor/doctor.d.mts +205 -4
- package/api/doctor/doctor.doc.mjs +4 -4
- package/api/doctor/doctor.mjs +962 -22
- package/api/doctor/doctor.type.d.mts +6 -1
- package/api/doctor/doctor.type.mjs +3 -1
- package/api/doctor/theme-checks.d.mts +20 -1
- package/api/doctor/theme-checks.mjs +280 -8
- package/api/error.d.mts +12 -1
- package/api/error.mjs +18 -6
- package/api/icon/_adapter.d.mts +11 -1
- package/api/icon/_adapter.mjs +22 -1
- package/api/icon/_authoring.mjs +21 -7
- package/api/icon/add/add.mjs +1 -1
- package/api/icon/definitions/definitions.mjs +19 -8
- package/api/icon/icon.doc.mjs +3 -3
- package/api/icon/icon.type.d.mts +49 -2
- package/api/icon/icon.type.mjs +23 -4
- package/api/icon/iconMap.doc.mjs +2 -2
- package/api/icon/list/list.mjs +4 -5
- package/api/icon/map/map.mjs +13 -4
- package/api/icon/search/icon-index.mjs +4 -1
- package/api/icon/search/search.d.mts +28 -7
- package/api/icon/search/search.mjs +177 -26
- package/api/init/_adapter.d.mts +87 -3
- package/api/init/_adapter.mjs +264 -16
- package/api/init/init.d.mts +2 -2
- package/api/init/init.doc.mjs +29 -5
- package/api/init/init.mjs +149 -10
- package/api/init/init.type.d.mts +75 -9
- package/api/init/init.type.mjs +32 -4
- package/api/init/remove/remove.d.mts +7 -4
- package/api/init/remove/remove.mjs +124 -26
- package/api/init/run/run.d.mts +38 -3
- package/api/init/run/run.mjs +366 -39
- package/api/integration/_adapter.d.mts +16 -0
- package/api/integration/_adapter.mjs +45 -1
- package/api/integration/integrationCheck.doc.mjs +1 -1
- package/api/integration/pack-check.d.mts +2 -1
- package/api/integration/pack-check.mjs +10 -18
- package/api/integration/validate-integration.d.mts +5 -2
- package/api/integration/validate-integration.mjs +81 -14
- package/api/integration/validate-integration.type.d.mts +9 -4
- package/api/integration/validate-integration.type.mjs +9 -4
- package/api/integration/validateIntegration.doc.mjs +4 -2
- package/api/render/_adapter.d.mts +6 -2
- package/api/render/_adapter.mjs +301 -51
- package/api/render/render.doc.d.mts +1 -1
- package/api/render/render.doc.mjs +20 -10
- package/api/render/render.mjs +16 -13
- package/api/render/render.type.d.mts +57 -10
- package/api/render/render.type.mjs +26 -13
- package/api/search/ORDERING.md +3 -3
- package/api/search/_adapter.d.mts +31 -0
- package/api/search/_adapter.mjs +107 -15
- package/api/search/_candidate-score.d.mts +12 -4
- package/api/search/_candidate-score.mjs +94 -16
- package/api/search/_cards.json +4 -1
- package/api/search/_entries.d.mts +8 -3
- package/api/search/_entries.mjs +109 -12
- package/api/search/_fit-order.d.mts +8 -4
- package/api/search/_fit-order.mjs +35 -7
- package/api/search/_gather-docs.mjs +71 -28
- package/api/search/_gather-templates.mjs +7 -2
- package/api/search/_icons.d.mts +50 -0
- package/api/search/_icons.mjs +85 -0
- package/api/search/_lexical.d.mts +14 -1
- package/api/search/_lexical.mjs +240 -12
- package/api/search/_main-searcher.mjs +1 -1
- package/api/search/_named-keywords.d.mts +6 -3
- package/api/search/_named-keywords.mjs +70 -19
- package/api/search/_order.d.mts +27 -12
- package/api/search/_order.mjs +132 -51
- package/api/search/_result.d.mts +30 -0
- package/api/search/_result.mjs +38 -0
- package/api/search/_score.d.mts +20 -6
- package/api/search/_score.mjs +96 -16
- package/api/search/_titles.d.mts +14 -0
- package/api/search/_titles.mjs +16 -3
- package/api/search/_words.d.mts +8 -0
- package/api/search/_words.mjs +26 -1
- package/api/search/search-index.mjs +23 -12
- package/api/search/search.d.mts +3 -1
- package/api/search/search.doc.mjs +5 -4
- package/api/search/search.mjs +69 -26
- package/api/search/search.type.d.mts +55 -1
- package/api/search/search.type.mjs +35 -1
- package/api/swizzle/_adapter.d.mts +1 -1
- package/api/swizzle/_adapter.mjs +1 -5
- package/api/swizzle/_moduleGraph.d.mts +0 -6
- package/api/swizzle/_moduleGraph.mjs +0 -12
- package/api/swizzle/copy/copy.mjs +1 -1
- package/api/template/_adapter.d.mts +46 -0
- package/api/template/_adapter.mjs +198 -2
- package/api/template/cdn/cdn.mjs +5 -3
- package/api/template/copy/copy.d.mts +12 -2
- package/api/template/copy/copy.mjs +95 -21
- package/api/template/list/list.mjs +1 -2
- package/api/template/show/show.d.mts +10 -3
- package/api/template/show/show.mjs +17 -6
- package/api/template/skeleton/skeleton.mjs +1 -2
- package/api/template/template.doc.mjs +3 -3
- package/api/template/template.mjs +37 -7
- package/api/template/template.type.d.mts +3 -0
- package/api/template/template.type.mjs +5 -2
- package/api/theme/_adapter.d.mts +28 -2
- package/api/theme/_adapter.mjs +675 -17
- package/api/theme/_app-provider.d.mts +42 -0
- package/api/theme/_app-provider.mjs +61 -27
- package/api/theme/_shared-source.d.mts +33 -0
- package/api/theme/_shared-source.mjs +348 -0
- package/api/theme/add/add.d.mts +3 -0
- package/api/theme/add/add.mjs +21 -4
- package/api/theme/build/build.d.mts +57 -30
- package/api/theme/build/build.mjs +403 -441
- package/api/theme/build/core-interception.d.mts +10 -0
- package/api/theme/build/core-interception.mjs +24 -0
- package/api/theme/build/family.mjs +4 -2
- package/api/theme/build/import-specifier.d.mts +14 -0
- package/api/theme/build/import-specifier.mjs +36 -0
- package/api/theme/build/null-values.d.mts +22 -0
- package/api/theme/build/null-values.mjs +110 -21
- package/api/theme/build/self-contained.mjs +32 -11
- package/api/theme/build/setting-effects.d.mts +254 -0
- package/api/theme/build/setting-effects.mjs +1065 -0
- package/api/theme/build/style-keys.d.mts +33 -0
- package/api/theme/build/style-keys.mjs +154 -0
- package/api/theme/build/theme-object.d.mts +47 -0
- package/api/theme/build/theme-object.mjs +144 -0
- package/api/theme/eject/eject.mjs +6 -1
- package/api/theme/palette/generate/color.d.mts +41 -9
- package/api/theme/palette/generate/color.mjs +108 -39
- package/api/theme/palette/generate/generate.mjs +10 -0
- package/api/theme/palette/generate/generator.d.mts +45 -27
- package/api/theme/palette/generate/generator.mjs +330 -156
- package/api/theme/palette/generate/mapping.d.mts +456 -0
- package/api/theme/palette/generate/mapping.mjs +1903 -0
- package/api/theme/palette/generate/newer-recipe.d.mts +28 -0
- package/api/theme/palette/generate/newer-recipe.mjs +87 -0
- package/api/theme/palette/generate/types.d.mts +270 -0
- package/api/theme/palette/generate/types.mjs +123 -0
- package/api/theme/theme.d.mts +25 -4
- package/api/theme/theme.mjs +55 -5
- package/api/theme/theme.type.d.mts +71 -2
- package/api/theme/theme.type.mjs +37 -5
- package/api/theme/themeAdd.doc.mjs +3 -2
- package/api/theme/themeBuild.doc.mjs +3 -3
- package/api/theme/themeEject.doc.mjs +1 -1
- package/api/theme/themeRemove.doc.mjs +1 -1
- package/api/theme/themeTargets.doc.mjs +1 -1
- package/api/theme-edit/_catalog.mjs +1 -1
- package/api/theme-edit/_check.mjs +129 -45
- package/api/theme-edit/_color.d.mts +2 -74
- package/api/theme-edit/_color.mjs +33 -869
- package/api/theme-edit/_context.d.mts +3 -1
- package/api/theme-edit/_context.mjs +16 -3
- package/api/theme-edit/_css.d.mts +4 -35
- package/api/theme-edit/_css.mjs +10 -91
- package/api/theme-edit/_edit.mjs +244 -32
- package/api/theme-edit/_how-question.d.mts +1 -0
- package/api/theme-edit/_how-question.mjs +1188 -52
- package/api/theme-edit/_how.mjs +19 -3
- package/api/theme-edit/_missed.d.mts +2 -1
- package/api/theme-edit/_missed.mjs +21 -2
- package/api/theme-edit/_normal.d.mts +5 -2
- package/api/theme-edit/_normal.mjs +11 -1
- package/api/theme-edit/_palette.d.mts +26 -75
- package/api/theme-edit/_palette.mjs +242 -1384
- package/api/theme-edit/_part-words.mjs +13 -3
- package/api/theme-edit/_parts.d.mts +8 -2
- package/api/theme-edit/_parts.mjs +56 -11
- package/api/theme-edit/_preview-app.d.mts +16 -0
- package/api/theme-edit/_preview-app.mjs +47 -15
- package/api/theme-edit/_preview.mjs +49 -22
- package/api/theme-edit/_project.d.mts +14 -2
- package/api/theme-edit/_project.mjs +25 -3
- package/api/theme-edit/_settings.d.mts +3 -2
- package/api/theme-edit/_settings.mjs +166 -45
- package/api/theme-edit/_tables.d.mts +3 -11
- package/api/theme-edit/_tables.mjs +21 -33
- package/api/theme-edit/theme-edit.type.d.mts +7 -1
- package/api/theme-edit/theme-edit.type.mjs +3 -2
- package/api/upgrade/_adapter.d.mts +38 -0
- package/api/upgrade/_adapter.mjs +274 -3
- package/api/upgrade/run/run.mjs +4 -0
- package/api/upgrade/upgrade.mjs +1 -1
- package/api/upgrade/upgrade.type.d.mts +46 -7
- package/api/upgrade/upgrade.type.mjs +24 -9
- package/assets/codemods/registry.mjs +1 -0
- package/assets/codemods/transforms/next/index.mjs +1 -11
- package/assets/codemods/transforms/v0.7.17/index.mjs +28 -0
- package/assets/codemods/transforms/v0.7.17/migrate-item-swipe-actions-to-swipe.mjs +2160 -0
- package/assets/codemods/transforms/v0.7.17/preserve-chat-radius.mjs +515 -0
- package/assets/component-list.generated.json +1 -1
- package/assets/discover/official-packages.json +72 -0
- package/assets/docs/author-a-theme.doc.mjs +7 -4
- package/assets/docs/getting-started.doc.mjs +1 -1
- package/assets/docs/principles.doc.dense.mjs +1 -1
- package/assets/docs/principles.doc.mjs +1 -1
- package/assets/docs/principles.doc.zh.mjs +1 -1
- package/assets/docs/styling-overview.doc.mjs +5 -1
- package/assets/docs/tree/agent-guidance.doc.mjs +33 -2
- package/assets/docs/tree/check-the-props.doc.mjs +1 -1
- package/assets/docs/tree/checks.doc.mjs +1 -1
- package/assets/docs/tree/computer-integrations.doc.mjs +1 -1
- package/assets/docs/tree/doc-syntax.doc.mjs +1 -1
- package/assets/docs/tree/export-pages.doc.mjs +164 -0
- package/assets/docs/tree/fonts-and-assets.doc.mjs +1 -1
- package/assets/docs/tree/host-entry.doc.mjs +4 -0
- package/assets/docs/tree/i18n-library-integration.doc.mjs +7 -3
- package/assets/docs/tree/icon-sets.doc.mjs +85 -9
- package/assets/docs/tree/layout.doc.mjs +16 -5
- package/assets/docs/tree/problems.doc.mjs +2 -2
- package/assets/docs/tree/responsive.doc.mjs +2 -2
- package/assets/docs/tree/scaffold.doc.mjs +1 -0
- package/assets/docs/tree/share-a-page.doc.mjs +14 -16
- package/assets/docs/tree/skill-places.doc.mjs +91 -0
- package/assets/docs/tree/styling.doc.mjs +41 -3
- package/assets/docs/tree/template-grading-rubric.doc.mjs +1 -1
- package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
- package/assets/docs/tree/tokens-and-setup.doc.mjs +2 -4
- package/assets/docs/tree/tokens-color.doc.mjs +2 -2
- package/assets/docs/tree/tokens-radius.doc.mjs +1 -1
- package/assets/docs/tree/tokens.doc.mjs +32 -0
- package/assets/docs/tree/troubleshooting.doc.mjs +8 -0
- package/assets/docs/tree/typography.doc.mjs +31 -2
- package/assets/docs/use-a-theme.doc.mjs +4 -0
- package/assets/docs/working-with-ai.doc.mjs +4 -4
- package/assets/docs-routes.generated.json +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/icons/definitions/alert.doc.mjs +9 -0
- package/assets/icons/definitions/alignBottom.doc.mjs +1 -0
- package/assets/icons/definitions/alignCenter.doc.mjs +1 -0
- package/assets/icons/definitions/alignEnd.doc.mjs +1 -0
- package/assets/icons/definitions/alignJustify.doc.mjs +1 -0
- package/assets/icons/definitions/alignMiddle.doc.mjs +1 -0
- package/assets/icons/definitions/alignStart.doc.mjs +1 -0
- package/assets/icons/definitions/alignTop.doc.mjs +1 -0
- package/assets/icons/definitions/arrowDown.doc.mjs +1 -0
- package/assets/icons/definitions/arrowLeft.doc.mjs +1 -0
- package/assets/icons/definitions/arrowRight.doc.mjs +1 -0
- package/assets/icons/definitions/arrowUp.doc.mjs +1 -0
- package/assets/icons/definitions/arrowsUpDown.doc.mjs +1 -0
- package/assets/icons/definitions/bank.doc.mjs +1 -0
- package/assets/icons/definitions/block.doc.mjs +9 -0
- package/assets/icons/definitions/bold.doc.mjs +1 -0
- package/assets/icons/definitions/bookmark.doc.mjs +1 -0
- package/assets/icons/definitions/bookmarkAdd.doc.mjs +1 -0
- package/assets/icons/definitions/cart.doc.mjs +1 -0
- package/assets/icons/definitions/channel.doc.mjs +9 -0
- package/assets/icons/definitions/check.doc.mjs +1 -0
- package/assets/icons/definitions/checkDouble.doc.mjs +1 -0
- package/assets/icons/definitions/checklist.doc.mjs +9 -0
- package/assets/icons/definitions/chevronDown.doc.mjs +1 -0
- package/assets/icons/definitions/chevronLeft.doc.mjs +1 -0
- package/assets/icons/definitions/chevronRight.doc.mjs +1 -0
- package/assets/icons/definitions/chevronUp.doc.mjs +1 -0
- package/assets/icons/definitions/chevronsLeft.doc.mjs +1 -0
- package/assets/icons/definitions/chevronsRight.doc.mjs +1 -0
- package/assets/icons/definitions/clipboard.doc.mjs +1 -0
- package/assets/icons/definitions/cloud.doc.mjs +1 -1
- package/assets/icons/definitions/collapse.doc.mjs +1 -0
- package/assets/icons/definitions/columnSettings.doc.mjs +9 -0
- package/assets/icons/definitions/compose.doc.mjs +1 -0
- package/assets/icons/definitions/conversation.doc.mjs +1 -0
- package/assets/icons/definitions/copy.doc.mjs +1 -0
- package/assets/icons/definitions/copyText.doc.mjs +9 -0
- package/assets/icons/definitions/cornerRadius.doc.mjs +1 -0
- package/assets/icons/definitions/create.doc.mjs +9 -0
- package/assets/icons/definitions/creditCard.doc.mjs +1 -0
- package/assets/icons/definitions/currency.doc.mjs +9 -0
- package/assets/icons/definitions/cut.doc.mjs +1 -0
- package/assets/icons/definitions/desktop.doc.mjs +1 -0
- package/assets/icons/definitions/discount.doc.mjs +1 -0
- package/assets/icons/definitions/document.doc.mjs +1 -0
- package/assets/icons/definitions/documentSearch.doc.mjs +1 -0
- package/assets/icons/definitions/download.doc.mjs +1 -0
- package/assets/icons/definitions/error.doc.mjs +1 -0
- package/assets/icons/definitions/exitFullScreen.doc.mjs +16 -0
- package/assets/icons/definitions/expand.doc.mjs +1 -0
- package/assets/icons/definitions/eye.doc.mjs +1 -0
- package/assets/icons/definitions/eyeSlash.doc.mjs +1 -0
- package/assets/icons/definitions/file.doc.mjs +1 -0
- package/assets/icons/definitions/flipHorizontal.doc.mjs +1 -0
- package/assets/icons/definitions/flipVertical.doc.mjs +1 -0
- package/assets/icons/definitions/folder.doc.mjs +1 -0
- package/assets/icons/definitions/folderAdd.doc.mjs +1 -0
- package/assets/icons/definitions/fullScreen.doc.mjs +16 -0
- package/assets/icons/definitions/globe.doc.mjs +1 -1
- package/assets/icons/definitions/groupRows.doc.mjs +9 -0
- package/assets/icons/definitions/halftone.doc.mjs +9 -0
- package/assets/icons/definitions/help.doc.mjs +9 -0
- package/assets/icons/definitions/house.doc.mjs +9 -0
- package/assets/icons/definitions/info.doc.mjs +1 -0
- package/assets/icons/definitions/italic.doc.mjs +1 -0
- package/assets/icons/definitions/listView.doc.mjs +9 -0
- package/assets/icons/definitions/lock.doc.mjs +1 -0
- package/assets/icons/definitions/lowercase.doc.mjs +1 -0
- package/assets/icons/definitions/mail.doc.mjs +1 -1
- package/assets/icons/definitions/media.doc.mjs +9 -0
- package/assets/icons/definitions/message.doc.mjs +2 -1
- package/assets/icons/definitions/mobile.doc.mjs +1 -0
- package/assets/icons/definitions/money.doc.mjs +1 -0
- package/assets/icons/definitions/moon.doc.mjs +1 -0
- package/assets/icons/definitions/moveToFolder.doc.mjs +9 -0
- package/assets/icons/definitions/notification.doc.mjs +1 -0
- package/assets/icons/definitions/notificationActive.doc.mjs +1 -0
- package/assets/icons/definitions/notificationOff.doc.mjs +1 -0
- package/assets/icons/definitions/paddingHorizontal.doc.mjs +1 -0
- package/assets/icons/definitions/paddingPerSide.doc.mjs +1 -0
- package/assets/icons/definitions/paddingVertical.doc.mjs +1 -0
- package/assets/icons/definitions/panelBottom.doc.mjs +1 -0
- package/assets/icons/definitions/panelLeft.doc.mjs +1 -0
- package/assets/icons/definitions/panelRight.doc.mjs +1 -0
- package/assets/icons/definitions/paste.doc.mjs +9 -0
- package/assets/icons/definitions/pause.doc.mjs +1 -0
- package/assets/icons/definitions/play.doc.mjs +1 -0
- package/assets/icons/definitions/radiusPerCorner.doc.mjs +1 -0
- package/assets/icons/definitions/redo.doc.mjs +1 -0
- package/assets/icons/definitions/review.doc.mjs +9 -0
- package/assets/icons/definitions/rotate.doc.mjs +1 -0
- package/assets/icons/definitions/rotateCounterclockwise.doc.mjs +1 -0
- package/assets/icons/definitions/scale.doc.mjs +1 -2
- package/assets/icons/definitions/schedule.doc.mjs +9 -0
- package/assets/icons/definitions/search.doc.mjs +1 -0
- package/assets/icons/definitions/send.doc.mjs +1 -0
- package/assets/icons/definitions/shoppingBag.doc.mjs +1 -0
- package/assets/icons/definitions/signal.doc.mjs +9 -0
- package/assets/icons/definitions/stop.doc.mjs +1 -0
- package/assets/icons/definitions/strikethrough.doc.mjs +1 -0
- package/assets/icons/definitions/success.doc.mjs +1 -0
- package/assets/icons/definitions/sun.doc.mjs +1 -0
- package/assets/icons/definitions/tablet.doc.mjs +1 -0
- package/assets/icons/definitions/team.doc.mjs +9 -0
- package/assets/icons/definitions/textCase.doc.mjs +2 -1
- package/assets/icons/definitions/textRegular.doc.mjs +1 -0
- package/assets/icons/definitions/thumbsDown.doc.mjs +1 -0
- package/assets/icons/definitions/thumbsUp.doc.mjs +1 -0
- package/assets/icons/definitions/transfer.doc.mjs +1 -0
- package/assets/icons/definitions/trendDown.doc.mjs +1 -0
- package/assets/icons/definitions/trendUp.doc.mjs +1 -0
- package/assets/icons/definitions/underline.doc.mjs +1 -0
- package/assets/icons/definitions/undo.doc.mjs +1 -0
- package/assets/icons/definitions/unlock.doc.mjs +1 -0
- package/assets/icons/definitions/upload.doc.mjs +1 -0
- package/assets/icons/definitions/uppercase.doc.mjs +1 -0
- package/assets/icons/definitions/user.doc.mjs +1 -0
- package/assets/icons/definitions/userAdd.doc.mjs +1 -0
- package/assets/icons/definitions/userCircle.doc.mjs +1 -0
- package/assets/icons/definitions/userRemove.doc.mjs +1 -0
- package/assets/icons/definitions/users.doc.mjs +1 -0
- package/assets/icons/definitions/verified.doc.mjs +9 -0
- package/assets/icons/definitions/wallet.doc.mjs +1 -0
- package/assets/icons/definitions/warning.doc.mjs +1 -0
- package/assets/icons/definitions/wrench.doc.mjs +1 -1
- package/assets/icons/template-icons.json +661 -0
- package/assets/search-catalog.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/AppShell/AppShellShowcase.doc.mjs +0 -7
- package/assets/templates/blocks/components/AppShell/AppShellShowcase.tsx +8 -10
- package/assets/templates/blocks/components/AppShell/AppShellSideNavOnly.doc.mjs +0 -8
- package/assets/templates/blocks/components/AppShell/AppShellSideNavOnly.tsx +10 -8
- package/assets/templates/blocks/components/AppShell/AppShellTopNavOnly.doc.mjs +0 -1
- package/assets/templates/blocks/components/AppShell/AppShellTopNavOnly.tsx +4 -2
- package/assets/templates/blocks/components/AppShell/AppShellTopNavWithSideNav.doc.mjs +0 -8
- package/assets/templates/blocks/components/AppShell/AppShellTopNavWithSideNav.tsx +10 -8
- package/assets/templates/blocks/components/AppShell/AppShellWithBanner.doc.mjs +0 -8
- package/assets/templates/blocks/components/AppShell/AppShellWithBanner.tsx +10 -8
- package/assets/templates/blocks/components/AspectRatio/AspectRatioImageGallery.tsx +1 -1
- package/assets/templates/blocks/components/AspectRatio/AspectRatioWidescreen.tsx +1 -1
- package/assets/templates/blocks/components/AspectRatio/AspectRatioWithSkeleton.tsx +1 -1
- package/assets/templates/blocks/components/Avatar/AvatarInteractive.tsx +6 -1
- package/assets/templates/blocks/components/Avatar/AvatarShowcase.tsx +1 -1
- package/assets/templates/blocks/components/Avatar/AvatarTooltip.tsx +1 -1
- package/assets/templates/blocks/components/Avatar/AvatarWithStatus.tsx +1 -1
- package/assets/templates/blocks/components/AvatarStatusDot/AvatarStatusDotShowcase.tsx +1 -1
- package/assets/templates/blocks/components/AvatarStatusDot/AvatarStatusDotVariants.tsx +1 -1
- package/assets/templates/blocks/components/Badge/BadgeShowcase.tsx +2 -2
- package/assets/templates/blocks/components/Banner/BannerCollapsibleContent.tsx +14 -1
- package/assets/templates/blocks/components/Banner/BannerSectionVariant.tsx +10 -1
- package/assets/templates/blocks/components/Banner/BannerWithActionButton.tsx +25 -3
- package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadCustomSearch.doc.mjs +0 -1
- package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadCustomSearch.tsx +2 -2
- package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadMenu.doc.mjs +0 -1
- package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadMenu.tsx +1 -1
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSnapPoints.doc.mjs +0 -8
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSnapPoints.tsx +5 -5
- package/assets/templates/blocks/components/BreadcrumbItem/BreadcrumbItemShowcase.doc.mjs +0 -1
- package/assets/templates/blocks/components/BreadcrumbItem/BreadcrumbItemShowcase.tsx +1 -1
- package/assets/templates/blocks/components/Breadcrumbs/BreadcrumbsDeepHierarchy.doc.mjs +0 -1
- package/assets/templates/blocks/components/Breadcrumbs/BreadcrumbsDeepHierarchy.tsx +1 -1
- package/assets/templates/blocks/components/Breadcrumbs/BreadcrumbsWithIcons.doc.mjs +0 -1
- package/assets/templates/blocks/components/Breadcrumbs/BreadcrumbsWithIcons.tsx +2 -2
- package/assets/templates/blocks/components/Button/ButtonFloating.doc.mjs +0 -1
- package/assets/templates/blocks/components/Button/ButtonFloating.tsx +25 -2
- package/assets/templates/blocks/components/Button/ButtonShowcase.tsx +42 -4
- package/assets/templates/blocks/components/Button/ButtonSizeVariants.tsx +24 -2
- package/assets/templates/blocks/components/Button/ButtonVariants.tsx +28 -1
- package/assets/templates/blocks/components/Button/ButtonWithEndSlot.tsx +9 -0
- package/assets/templates/blocks/components/Button/ButtonWithIcon.doc.mjs +0 -6
- package/assets/templates/blocks/components/Button/ButtonWithIcon.tsx +35 -9
- package/assets/templates/blocks/components/ButtonGroup/ButtonGroupBasic.tsx +20 -3
- package/assets/templates/blocks/components/ButtonGroup/ButtonGroupFloating.tsx +16 -3
- package/assets/templates/blocks/components/ButtonGroup/ButtonGroupShowcase.doc.mjs +0 -6
- package/assets/templates/blocks/components/ButtonGroup/ButtonGroupShowcase.tsx +37 -8
- package/assets/templates/blocks/components/Center/CenterHorizontal.doc.mjs +0 -8
- package/assets/templates/blocks/components/Center/CenterHorizontal.tsx +23 -5
- package/assets/templates/blocks/components/Center/CenterInsideACard.doc.mjs +0 -1
- package/assets/templates/blocks/components/Center/CenterInsideACard.tsx +1 -1
- package/assets/templates/blocks/components/ChatComposer/ChatComposerFlat.doc.mjs +0 -5
- package/assets/templates/blocks/components/ChatComposer/ChatComposerFlat.tsx +8 -3
- package/assets/templates/blocks/components/ChatComposer/ChatComposerFooterActions.doc.mjs +0 -5
- package/assets/templates/blocks/components/ChatComposer/ChatComposerFooterActions.tsx +8 -3
- package/assets/templates/blocks/components/ChatComposer/ChatComposerFullFeatured.doc.mjs +0 -7
- package/assets/templates/blocks/components/ChatComposer/ChatComposerFullFeatured.tsx +10 -7
- package/assets/templates/blocks/components/ChatComposerDrawer/ChatComposerDrawerShowcase.doc.mjs +0 -1
- package/assets/templates/blocks/components/ChatComposerDrawer/ChatComposerDrawerShowcase.tsx +2 -2
- package/assets/templates/blocks/components/ChatComposerDrawer/ChatComposerDrawerWithProgress.doc.mjs +0 -1
- package/assets/templates/blocks/components/ChatComposerDrawer/ChatComposerDrawerWithProgress.tsx +3 -3
- package/assets/templates/blocks/components/ChatMessageMetadata/ChatMessageMetadataFooter.doc.mjs +0 -6
- package/assets/templates/blocks/components/ChatMessageMetadata/ChatMessageMetadataFooter.tsx +9 -9
- package/assets/templates/blocks/components/ChatMessageMetadata/ChatMessageMetadataShowcase.doc.mjs +0 -6
- package/assets/templates/blocks/components/ChatMessageMetadata/ChatMessageMetadataShowcase.tsx +10 -10
- package/assets/templates/blocks/components/ChatSendButton/ChatSendButtonCustomIcon.doc.mjs +0 -6
- package/assets/templates/blocks/components/ChatSendButton/ChatSendButtonCustomIcon.tsx +8 -5
- package/assets/templates/blocks/components/ChatSendButton/ChatSendButtonShowcase.doc.mjs +0 -1
- package/assets/templates/blocks/components/ChatSendButton/ChatSendButtonShowcase.tsx +1 -1
- package/assets/templates/blocks/components/ChatSystemMessage/ChatSystemMessageStatusUpdates.doc.mjs +0 -5
- package/assets/templates/blocks/components/ChatSystemMessage/ChatSystemMessageStatusUpdates.tsx +7 -7
- package/assets/templates/blocks/components/ChatSystemMessage/ChatSystemMessageWithIcon.doc.mjs +0 -6
- package/assets/templates/blocks/components/ChatSystemMessage/ChatSystemMessageWithIcon.tsx +7 -7
- package/assets/templates/blocks/components/ContextMenu/ContextMenuBottomSheet.doc.mjs +0 -6
- package/assets/templates/blocks/components/ContextMenu/ContextMenuBottomSheet.tsx +7 -7
- package/assets/templates/blocks/components/DropdownMenu/DropdownMenuBottomSheet.doc.mjs +0 -6
- package/assets/templates/blocks/components/DropdownMenu/DropdownMenuBottomSheet.tsx +7 -7
- package/assets/templates/blocks/components/DropdownMenu/DropdownMenuNoChevron.doc.mjs +0 -1
- package/assets/templates/blocks/components/DropdownMenu/DropdownMenuNoChevron.tsx +2 -2
- package/assets/templates/blocks/components/EmptyState/EmptyStateActions.doc.mjs +0 -1
- package/assets/templates/blocks/components/EmptyState/EmptyStateActions.tsx +2 -2
- package/assets/templates/blocks/components/EmptyState/EmptyStateCompact.doc.mjs +0 -1
- package/assets/templates/blocks/components/EmptyState/EmptyStateCompact.tsx +1 -1
- package/assets/templates/blocks/components/EmptyState/EmptyStateContainer.doc.mjs +0 -1
- package/assets/templates/blocks/components/EmptyState/EmptyStateContainer.tsx +2 -2
- package/assets/templates/blocks/components/EmptyState/EmptyStateShowcase.doc.mjs +0 -1
- package/assets/templates/blocks/components/EmptyState/EmptyStateShowcase.tsx +2 -2
- package/assets/templates/blocks/components/Grid/GridShowcase.tsx +1 -1
- package/assets/templates/blocks/components/GridSpan/GridSpanColumns.tsx +1 -1
- package/assets/templates/blocks/components/GridSpan/GridSpanShowcase.tsx +1 -1
- package/assets/templates/blocks/components/Heading/HeadingTruncation.tsx +3 -2
- package/assets/templates/blocks/components/Hooks/useClipboardHookUsage.tsx +1 -1
- package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.doc.mjs +0 -1
- package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.tsx +38 -19
- package/assets/templates/blocks/components/Hooks/useGridFocusHookUsage.tsx +6 -6
- package/assets/templates/blocks/components/Hooks/useHotkeysHookUsage.tsx +1 -1
- package/assets/templates/blocks/components/Hooks/useInputContainerHookUsage.doc.mjs +0 -1
- package/assets/templates/blocks/components/Hooks/useInputContainerHookUsage.tsx +2 -2
- package/assets/templates/blocks/components/Hooks/useKeyboardHintHookUsage.doc.mjs +0 -1
- package/assets/templates/blocks/components/Hooks/useKeyboardHintHookUsage.tsx +2 -2
- package/assets/templates/blocks/components/Hooks/useListFocusHookUsage.tsx +8 -1
- package/assets/templates/blocks/components/Hooks/useOverflowHookUsage.tsx +17 -6
- package/assets/templates/blocks/components/Hooks/useStreamingTextHookUsage.tsx +1 -1
- package/assets/templates/blocks/components/Hooks/useTreeFocusHookUsage.doc.mjs +0 -1
- package/assets/templates/blocks/components/Hooks/useTreeFocusHookUsage.tsx +1 -1
- package/assets/templates/blocks/components/HoverCard/HoverCardInteractiveContent.doc.mjs +0 -1
- package/assets/templates/blocks/components/HoverCard/HoverCardInteractiveContent.tsx +1 -1
- package/assets/templates/blocks/components/HoverCard/HoverCardProfileHoverCard.doc.mjs +0 -1
- package/assets/templates/blocks/components/HoverCard/HoverCardProfileHoverCard.tsx +1 -1
- package/assets/templates/blocks/components/Icon/useIconHookUsage.doc.mjs +0 -5
- package/assets/templates/blocks/components/Icon/useIconHookUsage.tsx +7 -7
- package/assets/templates/blocks/components/IconButton/IconButtonActionBar.tsx +11 -0
- package/assets/templates/blocks/components/IconButton/IconButtonFloating.doc.mjs +0 -1
- package/assets/templates/blocks/components/IconButton/IconButtonFloating.tsx +25 -2
- package/assets/templates/blocks/components/IconButton/IconButtonShowcase.tsx +3 -0
- package/assets/templates/blocks/components/IconButton/IconButtonTooltipIconButton.tsx +5 -0
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider02Overrides.doc.mjs +3 -3
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider02Overrides.tsx +36 -13
- package/assets/templates/blocks/components/Item/ItemDocumentTabs.doc.mjs +0 -1
- package/assets/templates/blocks/components/Item/ItemDocumentTabs.tsx +4 -4
- package/assets/templates/blocks/components/Item/ItemShowcase.doc.mjs +0 -1
- package/assets/templates/blocks/components/Item/ItemShowcase.tsx +7 -3
- package/assets/templates/blocks/components/Layout/LayoutBasicCardLayout.tsx +14 -2
- package/assets/templates/blocks/components/Layout/LayoutContentWidth.tsx +14 -2
- package/assets/templates/blocks/components/Layout/LayoutFullBleedContent.tsx +8 -1
- package/assets/templates/blocks/components/Layout/LayoutShowcase.tsx +8 -1
- package/assets/templates/blocks/components/Layout/LayoutSidebarLayout.tsx +14 -2
- package/assets/templates/blocks/components/LinkProvider/LinkProviderCustomLink.tsx +3 -1
- package/assets/templates/blocks/components/Markdown/MarkdownShowcase.tsx +1 -1
- package/assets/templates/blocks/components/MediaTheme/MediaThemeImageOverlay.tsx +18 -4
- package/assets/templates/blocks/components/MediaTheme/MediaThemeLightScrim.tsx +11 -3
- package/assets/templates/blocks/components/MediaTheme/MediaThemeShowcase.tsx +27 -5
- package/assets/templates/blocks/components/MobileNav/MobileNavBasicMobileNav.doc.mjs +0 -7
- package/assets/templates/blocks/components/MobileNav/MobileNavBasicMobileNav.tsx +5 -9
- package/assets/templates/blocks/components/MobileNav/MobileNavEndSideMobileNav.doc.mjs +0 -1
- package/assets/templates/blocks/components/MobileNav/MobileNavEndSideMobileNav.tsx +2 -2
- package/assets/templates/blocks/components/MobileNav/MobileNavWithoutTitleMobileNav.doc.mjs +0 -1
- package/assets/templates/blocks/components/MobileNav/MobileNavWithoutTitleMobileNav.tsx +1 -1
- package/assets/templates/blocks/components/MoreMenu/MoreMenuBottomSheet.doc.mjs +0 -6
- package/assets/templates/blocks/components/MoreMenu/MoreMenuBottomSheet.tsx +15 -15
- package/assets/templates/blocks/components/MoreMenu/MoreMenuWithDividers.doc.mjs +0 -5
- package/assets/templates/blocks/components/MoreMenu/MoreMenuWithDividers.tsx +4 -8
- package/assets/templates/blocks/components/MoreMenu/MoreMenuWithSections.doc.mjs +0 -5
- package/assets/templates/blocks/components/MoreMenu/MoreMenuWithSections.tsx +4 -8
- package/assets/templates/blocks/components/MultiSelector/useMultiComboboxHookUsage.doc.mjs +0 -1
- package/assets/templates/blocks/components/MultiSelector/useMultiComboboxHookUsage.tsx +1 -1
- package/assets/templates/blocks/components/OverflowList/OverflowListCappedToolbar.tsx +38 -2
- package/assets/templates/blocks/components/OverflowList/OverflowListCollapseFromStartList.tsx +17 -5
- package/assets/templates/blocks/components/OverflowList/OverflowListOverflowDropdownActions.tsx +46 -7
- package/assets/templates/blocks/components/OverflowList/OverflowListShowcase.tsx +45 -5
- package/assets/templates/blocks/components/Overlay/OverlayHoverReveal.tsx +14 -1
- package/assets/templates/blocks/components/Overlay/OverlayShowcase.tsx +10 -1
- package/assets/templates/blocks/components/Overlay/useOverlayHookUsage.tsx +12 -1
- package/assets/templates/blocks/components/Pagination/PaginationDotsCarousel.doc.mjs +0 -1
- package/assets/templates/blocks/components/Pagination/PaginationDotsCarousel.tsx +1 -1
- package/assets/templates/blocks/components/Popover/PopoverBottomSheetAlternative.doc.mjs +0 -1
- package/assets/templates/blocks/components/Popover/PopoverBottomSheetAlternative.tsx +1 -1
- package/assets/templates/blocks/components/Resizable/ResizableShowcase.tsx +12 -2
- package/assets/templates/blocks/components/Resizable/ResizableSidebar.tsx +1 -1
- package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaInlineRail.tsx +1 -1
- package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaOverscrollChaining.tsx +1 -1
- package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaShowcase.tsx +1 -1
- package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaStickyGroupHeaders.tsx +1 -1
- package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaStickyPassthrough.tsx +1 -1
- package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaTwoAxisBoard.tsx +1 -1
- package/assets/templates/blocks/components/Section/SectionWashHighlight.doc.mjs +0 -1
- package/assets/templates/blocks/components/Section/SectionWashHighlight.tsx +10 -2
- package/assets/templates/blocks/components/Selector/SelectorOptionDescriptions.doc.mjs +0 -1
- package/assets/templates/blocks/components/Selector/SelectorOptionDescriptions.tsx +3 -3
- package/assets/templates/blocks/components/SelectorOption/SelectorOptionShowcase.doc.mjs +0 -1
- package/assets/templates/blocks/components/SelectorOption/SelectorOptionShowcase.tsx +1 -1
- package/assets/templates/blocks/components/Stack/StackAlignment.tsx +50 -6
- package/assets/templates/blocks/components/Stack/StackDirections.tsx +1 -1
- package/assets/templates/blocks/components/Stack/StackFillItem.tsx +10 -1
- package/assets/templates/blocks/components/Step/StepContent.tsx +13 -4
- package/assets/templates/blocks/components/Step/StepIndicator.tsx +3 -2
- package/assets/templates/blocks/components/Step/StepShowcase.tsx +1 -1
- package/assets/templates/blocks/components/Step/StepStates.tsx +3 -2
- package/assets/templates/blocks/components/Stepper/StepperCustomContent.tsx +18 -14
- package/assets/templates/blocks/components/Stepper/StepperOnTrackHorizontal.tsx +1 -1
- package/assets/templates/blocks/components/Table/TableInCard.tsx +1 -1
- package/assets/templates/blocks/components/Table/TableShowcase.tsx +1 -1
- package/assets/templates/blocks/components/TextArea/TextAreaWithIcon.doc.mjs +0 -1
- package/assets/templates/blocks/components/TextArea/TextAreaWithIcon.tsx +2 -2
- package/assets/templates/blocks/components/TextInput/TextInputIcon.doc.mjs +0 -1
- package/assets/templates/blocks/components/TextInput/TextInputIcon.tsx +3 -7
- package/assets/templates/blocks/components/TextInput/TextInputSearch.doc.mjs +0 -1
- package/assets/templates/blocks/components/TextInput/TextInputSearch.tsx +3 -3
- package/assets/templates/blocks/components/Theme/ThemeApply.tsx +8 -1
- package/assets/templates/blocks/components/Theme/ThemeNested.tsx +11 -1
- package/assets/templates/blocks/components/Theme/ThemeShowcase.tsx +26 -3
- package/assets/templates/blocks/components/Theme/ThemeSwitcher.tsx +8 -1
- package/assets/templates/blocks/components/ToggleButton/ToggleButtonColor.doc.mjs +0 -11
- package/assets/templates/blocks/components/ToggleButton/ToggleButtonColor.tsx +5 -5
- package/assets/templates/blocks/components/ToggleButton/ToggleButtonGroup.doc.mjs +0 -9
- package/assets/templates/blocks/components/ToggleButton/ToggleButtonGroup.tsx +5 -9
- package/assets/templates/blocks/components/ToggleButton/ToggleButtonIconSwap.doc.mjs +0 -6
- package/assets/templates/blocks/components/ToggleButton/ToggleButtonIconSwap.tsx +6 -6
- package/assets/templates/blocks/components/ToggleButton/ToggleButtonLabel.doc.mjs +0 -6
- package/assets/templates/blocks/components/ToggleButton/ToggleButtonLabel.tsx +3 -3
- package/assets/templates/blocks/components/ToggleButton/ToggleButtonShowcase.doc.mjs +0 -6
- package/assets/templates/blocks/components/ToggleButton/ToggleButtonShowcase.tsx +6 -6
- package/assets/templates/blocks/components/ToggleButton/ToggleButtonStates.doc.mjs +0 -1
- package/assets/templates/blocks/components/ToggleButton/ToggleButtonStates.tsx +2 -2
- package/assets/templates/blocks/components/Token/TokenIcon.doc.mjs +0 -6
- package/assets/templates/blocks/components/Token/TokenIcon.tsx +3 -3
- package/assets/templates/blocks/components/Token/TokenShowcase.doc.mjs +0 -1
- package/assets/templates/blocks/components/Token/TokenShowcase.tsx +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +14 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.doc.mjs +0 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx +2 -2
- package/assets/templates/blocks/components/Toolbar/ToolbarBulkActions.doc.mjs +0 -1
- package/assets/templates/blocks/components/Toolbar/ToolbarBulkActions.tsx +36 -3
- package/assets/templates/blocks/components/Toolbar/ToolbarCardHeader.doc.mjs +0 -1
- package/assets/templates/blocks/components/Toolbar/ToolbarCardHeader.tsx +4 -3
- package/assets/templates/blocks/components/Toolbar/ToolbarSizes.doc.mjs +0 -1
- package/assets/templates/blocks/components/Toolbar/ToolbarSizes.tsx +3 -3
- package/assets/templates/blocks/components/Toolbar/ToolbarTableFilter.doc.mjs +0 -1
- package/assets/templates/blocks/components/Toolbar/ToolbarTableFilter.tsx +8 -3
- package/assets/templates/blocks/components/Toolbar/ToolbarThreeSlot.doc.mjs +0 -1
- package/assets/templates/blocks/components/Toolbar/ToolbarThreeSlot.tsx +6 -2
- package/assets/templates/blocks/components/Toolbar/ToolbarWithTabs.doc.mjs +0 -1
- package/assets/templates/blocks/components/Toolbar/ToolbarWithTabs.tsx +11 -2
- package/assets/templates/blocks/components/Tooltip/TooltipActionBarTooltips.tsx +33 -3
- package/assets/templates/blocks/components/TopNav/TopNavCenteredNavigation.doc.mjs +0 -1
- package/assets/templates/blocks/components/TopNav/TopNavCenteredNavigation.tsx +2 -2
- package/assets/templates/blocks/components/TopNav/TopNavEnterpriseDashboard.doc.mjs +0 -6
- package/assets/templates/blocks/components/TopNav/TopNavEnterpriseDashboard.tsx +7 -7
- package/assets/templates/blocks/components/TopNav/TopNavHoverMenu.doc.mjs +0 -8
- package/assets/templates/blocks/components/TopNav/TopNavHoverMenu.tsx +14 -9
- package/assets/templates/blocks/components/TopNav/TopNavMegaMenu.doc.mjs +0 -8
- package/assets/templates/blocks/components/TopNav/TopNavMegaMenu.tsx +11 -11
- package/assets/templates/blocks/components/TopNav/TopNavMultipleDropdowns.doc.mjs +0 -5
- package/assets/templates/blocks/components/TopNav/TopNavMultipleDropdowns.tsx +4 -8
- package/assets/templates/blocks/components/TopNav/TopNavShowcase.doc.mjs +0 -5
- package/assets/templates/blocks/components/TopNav/TopNavShowcase.tsx +8 -4
- package/assets/templates/blocks/components/TopNav/TopNavWithLogo.doc.mjs +0 -1
- package/assets/templates/blocks/components/TopNav/TopNavWithLogo.tsx +7 -2
- package/assets/templates/blocks/components/TopNavItem/TopNavItemShowcase.tsx +1 -1
- package/assets/templates/blocks/components/TopNavMegaMenu/TopNavMegaMenuBasic.doc.mjs +0 -1
- package/assets/templates/blocks/components/TopNavMegaMenu/TopNavMegaMenuBasic.tsx +4 -4
- package/assets/templates/blocks/components/TopNavMegaMenu/TopNavMegaMenuShowcase.doc.mjs +0 -7
- package/assets/templates/blocks/components/TopNavMegaMenu/TopNavMegaMenuShowcase.tsx +12 -12
- package/assets/templates/blocks/components/TopNavMegaMenuItem/TopNavMegaMenuItemBasic.doc.mjs +0 -1
- package/assets/templates/blocks/components/TopNavMegaMenuItem/TopNavMegaMenuItemBasic.tsx +2 -2
- package/assets/templates/blocks/components/TopNavMenu/TopNavMenuBasic.doc.mjs +0 -1
- package/assets/templates/blocks/components/TopNavMenu/TopNavMenuBasic.tsx +4 -4
- package/assets/templates/blocks/components/TopNavMenu/TopNavMenuShowcase.doc.mjs +0 -6
- package/assets/templates/blocks/components/TopNavMenu/TopNavMenuShowcase.tsx +11 -8
- package/assets/templates/blocks/components/TreeList/TreeListFileTreeWithIcons.doc.mjs +0 -1
- package/assets/templates/blocks/components/TreeList/TreeListFileTreeWithIcons.tsx +4 -4
- package/assets/templates/blocks/components/TreeList/TreeListInteractiveSettings.doc.mjs +0 -1
- package/assets/templates/blocks/components/TreeList/TreeListInteractiveSettings.tsx +6 -3
- package/assets/templates/blocks/components/Typeahead/TypeaheadSearchField.doc.mjs +0 -1
- package/assets/templates/blocks/components/Typeahead/TypeaheadSearchField.tsx +2 -2
- package/assets/templates/blocks/components/VisuallyHidden/VisuallyHiddenShowcase.doc.mjs +0 -6
- package/assets/templates/blocks/components/VisuallyHidden/VisuallyHiddenShowcase.tsx +30 -7
- package/assets/templates/blocks/components/VisuallyHidden/VisuallyHiddenSupplementaryContext.doc.mjs +0 -1
- package/assets/templates/blocks/components/VisuallyHidden/VisuallyHiddenSupplementaryContext.tsx +4 -1
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat/page.tsx +19 -15
- package/assets/templates/pages/ai-chat/template.doc.mjs +0 -9
- package/assets/templates/pages/ai-chat-landing/page.tsx +16 -16
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +0 -11
- package/assets/templates/pages/blank/page.tsx +4 -2
- package/assets/templates/pages/canvas-editor/page.tsx +200 -110
- package/assets/templates/pages/canvas-editor/template.doc.mjs +0 -46
- package/assets/templates/pages/centered-hero/page.tsx +2 -2
- package/assets/templates/pages/centered-hero/template.doc.mjs +0 -1
- package/assets/templates/pages/checkout-wizard/page.tsx +31 -18
- package/assets/templates/pages/checkout-wizard/template.doc.mjs +0 -7
- package/assets/templates/pages/classic-gallery/page.tsx +1 -1
- package/assets/templates/pages/contact-form/page.tsx +15 -10
- package/assets/templates/pages/contact-form/template.doc.mjs +0 -5
- package/assets/templates/pages/course-detail/page.tsx +10 -10
- package/assets/templates/pages/course-detail/template.doc.mjs +0 -11
- package/assets/templates/pages/dashboard/page.tsx +13 -11
- package/assets/templates/pages/dashboard/template.doc.mjs +0 -6
- package/assets/templates/pages/dashboard-alert-rail/page.tsx +12 -12
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +0 -8
- package/assets/templates/pages/dashboard-cohort-funnel/page.tsx +7 -13
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +0 -7
- package/assets/templates/pages/dashboard-comparison/page.tsx +12 -10
- package/assets/templates/pages/dashboard-comparison/template.doc.mjs +0 -8
- package/assets/templates/pages/dashboard-composition/page.tsx +30 -19
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +0 -1
- package/assets/templates/pages/dashboard-progress/page.tsx +101 -108
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +0 -7
- package/assets/templates/pages/dashboard-scorecard/page.tsx +61 -33
- package/assets/templates/pages/dashboard-scorecard/template.doc.mjs +0 -7
- package/assets/templates/pages/detail-page/page.tsx +28 -11
- package/assets/templates/pages/detail-page/template.doc.mjs +0 -10
- package/assets/templates/pages/documentation/page.tsx +11 -4
- package/assets/templates/pages/documentation-design/page.tsx +39 -12
- package/assets/templates/pages/documentation-design/template.doc.mjs +0 -5
- package/assets/templates/pages/documentation-technical/page.tsx +8 -6
- package/assets/templates/pages/documentation-technical/template.doc.mjs +0 -5
- package/assets/templates/pages/editor/page.tsx +70 -48
- package/assets/templates/pages/editor/template.doc.mjs +0 -26
- package/assets/templates/pages/file-explorer/page.tsx +19 -19
- package/assets/templates/pages/file-explorer/template.doc.mjs +0 -15
- package/assets/templates/pages/form-two-column/page.tsx +1 -1
- package/assets/templates/pages/form-wizard/page.tsx +12 -5
- package/assets/templates/pages/form-wizard-dialog/page.tsx +6 -2
- package/assets/templates/pages/form-wizard-inline/page.tsx +16 -12
- package/assets/templates/pages/form-wizard-inline/template.doc.mjs +0 -6
- package/assets/templates/pages/form-wizard-vertical/page.tsx +21 -24
- package/assets/templates/pages/form-wizard-vertical/template.doc.mjs +0 -13
- package/assets/templates/pages/gallery-hero/page.tsx +2 -2
- package/assets/templates/pages/gallery-hero/template.doc.mjs +0 -1
- package/assets/templates/pages/ide/page.tsx +12 -7
- package/assets/templates/pages/ide/template.doc.mjs +0 -5
- package/assets/templates/pages/incident-console/page.tsx +4 -4
- package/assets/templates/pages/incident-console/template.doc.mjs +0 -1
- package/assets/templates/pages/kanban-board/page.tsx +128 -47
- package/assets/templates/pages/kanban-board/template.doc.mjs +0 -11
- package/assets/templates/pages/library/page.tsx +34 -64
- package/assets/templates/pages/library/template.doc.mjs +0 -1
- package/assets/templates/pages/login/page.tsx +6 -4
- package/assets/templates/pages/login/template.doc.mjs +0 -1
- package/assets/templates/pages/login-card/page.tsx +6 -4
- package/assets/templates/pages/login-card/template.doc.mjs +0 -1
- package/assets/templates/pages/login-split/page.tsx +6 -5
- package/assets/templates/pages/login-split/template.doc.mjs +0 -1
- package/assets/templates/pages/login-sso/page.tsx +6 -6
- package/assets/templates/pages/login-sso/template.doc.mjs +0 -1
- package/assets/templates/pages/messaging-shell/page.tsx +14 -14
- package/assets/templates/pages/messaging-shell/template.doc.mjs +0 -9
- package/assets/templates/pages/mixed-gallery/page.tsx +1 -1
- package/assets/templates/pages/payment-form/page.tsx +50 -29
- package/assets/templates/pages/payment-form/template.doc.mjs +0 -6
- package/assets/templates/pages/product-detail/page.tsx +21 -9
- package/assets/templates/pages/product-detail/template.doc.mjs +0 -1
- package/assets/templates/pages/product-gallery/page.tsx +3 -3
- package/assets/templates/pages/product-gallery/template.doc.mjs +0 -1
- package/assets/templates/pages/settings/page.tsx +35 -14
- package/assets/templates/pages/settings/template.doc.mjs +0 -1
- package/assets/templates/pages/settings-dialog/page.tsx +96 -93
- package/assets/templates/pages/settings-dialog/template.doc.mjs +0 -53
- package/assets/templates/pages/settings-sidebar/page.tsx +74 -36
- package/assets/templates/pages/settings-sidebar/template.doc.mjs +0 -16
- package/assets/templates/pages/shell-nav/page.tsx +32 -20
- package/assets/templates/pages/shell-nav/template.doc.mjs +0 -6
- package/assets/templates/pages/shell-side-nav/page.tsx +23 -22
- package/assets/templates/pages/shell-side-nav/template.doc.mjs +0 -11
- package/assets/templates/pages/shell-top-nav/page.tsx +13 -13
- package/assets/templates/pages/shell-top-nav/template.doc.mjs +0 -19
- package/assets/templates/pages/side-gallery/page.tsx +5 -2
- package/assets/templates/pages/table/page.tsx +21 -21
- package/assets/templates/pages/table/template.doc.mjs +0 -10
- package/assets/templates/pages/table-collapsible/page.tsx +8 -8
- package/assets/templates/pages/table-collapsible/template.doc.mjs +0 -6
- package/assets/templates/pages/table-comparison/page.tsx +23 -23
- package/assets/templates/pages/table-comparison/template.doc.mjs +0 -14
- package/assets/templates/pages/table-filter/page.tsx +75 -47
- package/assets/templates/pages/table-filter/template.doc.mjs +0 -19
- package/assets/templates/pages/table-grouped/page.tsx +16 -15
- package/assets/templates/pages/table-grouped/template.doc.mjs +0 -11
- package/assets/templates/pages/table-inbox/page.tsx +65 -33
- package/assets/templates/pages/table-inbox/template.doc.mjs +0 -17
- package/assets/templates/pages/table-page/page.tsx +3 -6
- package/assets/templates/pages/table-page/template.doc.mjs +0 -1
- package/assets/templates/pages/table-tree/page.tsx +35 -35
- package/assets/templates/pages/table-tree/template.doc.mjs +0 -15
- package/assets/templates/pages/theme-showcase/page.tsx +48 -43
- package/assets/templates/pages/theme-showcase/template.doc.mjs +0 -19
- package/assets/templates/pages/work-item-detail/page.tsx +60 -33
- package/assets/templates/pages/work-item-detail/template.doc.mjs +0 -12
- package/assets/templates/themes/butter/butterTheme.ts +50 -9
- package/assets/templates/themes/chocolate/chocolateTheme.ts +13 -6
- package/assets/templates/themes/gothic/gothicTheme.ts +14 -2
- package/assets/templates/themes/matcha/matchaTheme.ts +10 -2
- package/assets/templates/themes/neutral/neutralTheme.ts +16 -0
- package/assets/templates/themes/stone/stonePaletteRefs.generated.ts +1 -1
- package/assets/templates/themes/stone/stoneTheme.ts +32 -10
- package/assets/templates/themes/y2k/y2kTheme.ts +11 -3
- package/assets/theme.template.ts +17 -7
- package/authoring/config/config.doc.mjs +8 -1
- package/authoring/config/parse.mjs +15 -0
- package/authoring/config/skill-places.d.mts +23 -0
- package/authoring/config/skill-places.mjs +35 -0
- package/authoring/config/type.ts +16 -0
- package/authoring/debug/parse.d.mts +1 -1
- package/authoring/debug/type.ts +4 -0
- package/authoring/discover/parse.d.mts +2 -1
- package/authoring/discover/parse.mjs +73 -38
- package/authoring/discover/type.ts +9 -2
- package/authoring/doctypes/_schema.d.mts +36 -16
- package/authoring/doctypes/_schema.mjs +29 -0
- package/authoring/doctypes/base/type.ts +19 -0
- package/authoring/doctypes/command/command.doc.mjs +6 -0
- package/authoring/doctypes/command/type.ts +7 -0
- package/authoring/doctypes/component/component.doc.mjs +1 -1
- package/authoring/doctypes/icon-definition/icon-definition.doc.mjs +16 -0
- package/authoring/doctypes/icon-definition/parse.mjs +12 -0
- package/authoring/doctypes/icon-definition/type.ts +18 -0
- package/authoring/doctypes/reference/reference.doc.mjs +13 -0
- package/authoring/doctypes/reference/skill.d.mts +29 -0
- package/authoring/doctypes/reference/skill.mjs +56 -0
- package/authoring/doctypes/reference/type.ts +19 -0
- package/authoring/gap-report/parse.d.mts +1 -1
- package/authoring/integration/integration.doc.mjs +8 -0
- package/authoring/integration/schema.d.mts +21 -3
- package/authoring/integration/schema.mjs +25 -5
- package/authoring/integration/type.ts +14 -0
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/build.doc.mjs +1 -1
- package/clients/cli/commands/build.mjs +11 -11
- package/clients/cli/commands/component.doc.mjs +3 -1
- package/clients/cli/commands/component.mjs +7 -3
- package/clients/cli/commands/discover.doc.mjs +2 -2
- package/clients/cli/commands/discover.mjs +108 -8
- package/clients/cli/commands/docs.doc.mjs +7 -2
- package/clients/cli/commands/docs.mjs +64 -172
- package/clients/cli/commands/doctor-integration-validate.doc.mjs +4 -2
- package/clients/cli/commands/doctor.doc.mjs +3 -1
- package/clients/cli/commands/doctor.mjs +16 -3
- package/clients/cli/commands/experimental/export.mjs +64 -0
- package/clients/cli/commands/experimental/icon.mjs +67 -12
- package/clients/cli/commands/experimental/import.mjs +70 -0
- package/clients/cli/commands/experimental/index.mjs +152 -13
- package/clients/cli/commands/experimental/render-output.mjs +242 -0
- package/clients/cli/commands/experimental/theme.mjs +34 -13
- package/clients/cli/commands/experimental-export.doc.mjs +73 -0
- package/clients/cli/commands/experimental-icon.doc.mjs +1 -1
- package/clients/cli/commands/experimental-import.doc.mjs +53 -0
- package/clients/cli/commands/experimental-theme-add.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +6 -1
- package/clients/cli/commands/experimental-theme.doc.mjs +1 -1
- package/clients/cli/commands/experimental.doc.mjs +4 -4
- package/clients/cli/commands/init.doc.mjs +34 -14
- package/clients/cli/commands/integration-check.doc.mjs +1 -1
- package/clients/cli/commands/mcp.doc.mjs +5 -1
- package/clients/cli/commands/search.mjs +68 -7
- package/clients/cli/commands/template.doc.mjs +14 -5
- package/clients/cli/commands/template.mjs +18 -0
- package/clients/cli/commands/theme-add.doc.mjs +6 -2
- package/clients/cli/commands/theme-remove.doc.mjs +1 -1
- package/clients/cli/commands/theme-targets.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +76 -5
- package/clients/cli/commands/upgrade.doc.mjs +2 -1
- package/clients/cli/commands.generated.json +1 -1
- package/clients/cli/index.mjs +30 -31
- package/clients/cli/lib/cli-error.mjs +20 -10
- package/clients/cli/lib/component-format.mjs +167 -74
- package/clients/cli/lib/define-command.mjs +10 -0
- package/clients/cli/lib/hook-format.mjs +28 -24
- package/clients/cli/lib/json-shim.mjs +9 -3
- package/clients/cli/lib/mcp-tools.mjs +8 -2
- package/clients/cli/lib/other-cli-words.mjs +99 -0
- package/clients/cli/lib/renamed-commands.mjs +21 -0
- package/clients/cli/lib/root-args.mjs +10 -3
- package/clients/cli/lib/stray-option.mjs +79 -1
- package/clients/cli/lib/unknown-command.mjs +406 -13
- package/clients/cli/manifest.generated.json +1 -1
- package/clients/cli/run.mjs +27 -0
- package/foundation/agent-docs/agent-doc-state.d.mts +20 -2
- package/foundation/agent-docs/agent-doc-state.mjs +71 -4
- package/foundation/agent-docs/agent-docs.d.mts +43 -4
- package/foundation/agent-docs/agent-docs.mjs +54 -5
- package/foundation/agent-docs/computer-agent-text.d.mts +28 -14
- package/foundation/agent-docs/computer-agent-text.mjs +85 -172
- package/foundation/agent-docs/folder-scope.d.mts +51 -0
- package/foundation/agent-docs/folder-scope.mjs +86 -0
- package/foundation/agent-docs/managed-skill-file.d.mts +115 -0
- package/foundation/agent-docs/managed-skill-file.mjs +224 -0
- package/foundation/agent-docs/skill-place-files.d.mts +119 -0
- package/foundation/agent-docs/skill-place-files.mjs +374 -0
- package/foundation/agent-docs/skill-places.d.mts +139 -0
- package/foundation/agent-docs/skill-places.mjs +321 -0
- package/foundation/color/css-color.d.mts +150 -0
- package/foundation/color/css-color.mjs +960 -0
- package/foundation/config/config-path.d.mts +2 -2
- package/foundation/config/config-path.mjs +5 -6
- package/foundation/config/config-writer.d.mts +5 -1
- package/foundation/config/config-writer.mjs +20 -4
- package/foundation/config/project.d.mts +3 -1
- package/foundation/config/project.mjs +8 -5
- package/foundation/config/theme-state.d.mts +13 -0
- package/foundation/config/theme-state.mjs +28 -0
- package/foundation/debug/event.d.mts +2 -1
- package/foundation/debug/event.mjs +2 -1
- package/foundation/discovery/button-actions.d.mts +220 -0
- package/foundation/discovery/button-actions.mjs +1527 -0
- package/foundation/discovery/cli-self-docs.d.mts +7 -0
- package/foundation/discovery/cli-self-docs.mjs +67 -6
- package/foundation/discovery/color-modes.d.mts +14 -0
- package/foundation/discovery/color-modes.mjs +53 -0
- package/foundation/discovery/command-pointers.d.mts +21 -4
- package/foundation/discovery/command-pointers.mjs +25 -4
- package/foundation/discovery/component-discovery.d.mts +10 -0
- package/foundation/discovery/component-discovery.mjs +99 -43
- package/foundation/discovery/component-replacement.d.mts +8 -0
- package/foundation/discovery/component-replacement.mjs +13 -0
- package/foundation/discovery/core-augmentation-points.d.mts +90 -0
- package/foundation/discovery/core-augmentation-points.mjs +1030 -0
- package/foundation/discovery/core-component-views.d.mts +15 -0
- package/foundation/discovery/core-component-views.mjs +176 -0
- package/foundation/discovery/core-elements.d.mts +29 -0
- package/foundation/discovery/core-elements.mjs +57 -0
- package/foundation/discovery/core-prop-types.d.mts +65 -0
- package/foundation/discovery/core-prop-types.mjs +221 -0
- package/foundation/discovery/core-props.d.mts +33 -0
- package/foundation/discovery/core-props.mjs +64 -0
- package/foundation/discovery/doc-types.d.mts +10 -42
- package/foundation/discovery/doc-types.mjs +26 -7
- package/foundation/discovery/docs-discovery.d.mts +33 -2
- package/foundation/discovery/docs-discovery.mjs +149 -72
- package/foundation/discovery/docs-section-key.d.mts +21 -1
- package/foundation/discovery/docs-section-key.mjs +57 -19
- package/foundation/discovery/hook-discovery.d.mts +2 -0
- package/foundation/discovery/hook-discovery.mjs +6 -5
- package/foundation/discovery/icon-definition-discovery.d.mts +155 -3
- package/foundation/discovery/icon-definition-discovery.mjs +197 -5
- package/foundation/discovery/icon-imports.d.mts +66 -0
- package/foundation/discovery/icon-imports.mjs +225 -0
- package/foundation/discovery/icon-ranking.d.mts +108 -4
- package/foundation/discovery/icon-ranking.mjs +277 -70
- package/foundation/discovery/icon-set-checks.d.mts +2 -0
- package/foundation/discovery/icon-set-checks.mjs +16 -2
- package/foundation/discovery/icon-set-discovery.d.mts +42 -2
- package/foundation/discovery/icon-set-discovery.mjs +85 -23
- package/foundation/discovery/icon-set-writer.d.mts +7 -2
- package/foundation/discovery/icon-set-writer.mjs +86 -7
- package/foundation/discovery/integration-skills.d.mts +62 -0
- package/foundation/discovery/integration-skills.mjs +116 -0
- package/foundation/discovery/module-exports.d.mts +8 -0
- package/foundation/discovery/module-exports.mjs +20 -21
- package/foundation/discovery/package-exports.d.mts +22 -0
- package/foundation/discovery/package-exports.mjs +44 -3
- package/foundation/discovery/project-typescript.d.mts +5 -1
- package/foundation/discovery/project-typescript.mjs +8 -2
- package/foundation/discovery/prop-drift.d.mts +16 -0
- package/foundation/discovery/prop-drift.mjs +154 -3
- package/foundation/discovery/replacement-aliases.d.mts +51 -0
- package/foundation/discovery/replacement-aliases.mjs +95 -0
- package/foundation/discovery/runner-allowlist.d.mts +1 -1
- package/foundation/discovery/runner-allowlist.mjs +1 -1
- package/foundation/discovery/stored-component-list.mjs +34 -2
- package/foundation/discovery/template-adapter.d.mts +26 -0
- package/foundation/discovery/template-adapter.mjs +221 -10
- package/foundation/discovery/template-destination.d.mts +14 -6
- package/foundation/discovery/template-destination.mjs +42 -8
- package/foundation/discovery/template-icon-meanings.d.mts +7 -2
- package/foundation/discovery/template-icon-meanings.mjs +52 -12
- package/foundation/discovery/template-icons.d.mts +44 -1
- package/foundation/discovery/template-icons.mjs +60 -63
- package/foundation/discovery/template-needs.d.mts +17 -8
- package/foundation/discovery/template-needs.mjs +119 -31
- package/foundation/discovery/template-placeholders.d.mts +149 -0
- package/foundation/discovery/template-placeholders.mjs +463 -0
- package/foundation/discovery/template-source-tree.d.mts +6 -3
- package/foundation/discovery/template-source-tree.mjs +8 -5
- package/foundation/discovery/theme-discovery.d.mts +8 -0
- package/foundation/discovery/theme-discovery.mjs +23 -6
- package/foundation/discovery/theme-imports.d.mts +1 -3
- package/foundation/discovery/theme-imports.mjs +5 -30
- package/foundation/doc-compiler/compile.mjs +6 -8
- package/foundation/doc-compiler/doc-syntax.d.mts +25 -1
- package/foundation/doc-compiler/doc-syntax.mjs +85 -10
- package/foundation/doc-compiler/doc-text.d.mts +52 -0
- package/foundation/doc-compiler/doc-text.mjs +176 -0
- package/foundation/doc-compiler/links.d.mts +8 -2
- package/foundation/doc-compiler/links.mjs +27 -6
- package/foundation/doc-compiler/read.d.mts +1 -1
- package/foundation/doc-compiler/stored-docs.d.mts +14 -3
- package/foundation/doc-compiler/stored-docs.mjs +12 -6
- package/foundation/env/cli-command.d.mts +68 -10
- package/foundation/env/cli-command.mjs +116 -22
- package/foundation/env/package-manager.d.mts +33 -2
- package/foundation/env/package-manager.mjs +68 -6
- package/foundation/env/user-dirs.d.mts +14 -0
- package/foundation/env/user-dirs.mjs +34 -1
- package/foundation/env/user-settings.d.mts +15 -0
- package/foundation/env/user-settings.mjs +56 -2
- package/foundation/fonts/font-stylesheet.d.mts +11 -0
- package/foundation/fonts/font-stylesheet.mjs +62 -7
- package/foundation/fs/cache-eviction.d.mts +7 -5
- package/foundation/fs/cache-eviction.mjs +20 -13
- package/foundation/fs/empty-folder.d.mts +12 -0
- package/foundation/fs/empty-folder.mjs +30 -0
- package/foundation/fs/file-protection.d.mts +11 -0
- package/foundation/fs/file-protection.mjs +49 -3
- package/foundation/fs/gather-cache.d.mts +14 -7
- package/foundation/fs/gather-cache.mjs +163 -67
- package/foundation/fs/import-url.d.mts +7 -5
- package/foundation/fs/import-url.mjs +7 -5
- package/foundation/fs/jiti-cache.d.mts +47 -26
- package/foundation/fs/jiti-cache.mjs +222 -130
- package/foundation/fs/loaded-files.d.mts +15 -1
- package/foundation/fs/loaded-files.mjs +40 -3
- package/foundation/fs/module-loader.d.mts +3 -1
- package/foundation/fs/module-loader.mjs +85 -5
- package/foundation/fs/path-safety.d.mts +1 -0
- package/foundation/fs/path-safety.mjs +2 -0
- package/foundation/fs/relative-specifier.d.mts +10 -0
- package/foundation/fs/relative-specifier.mjs +28 -0
- package/foundation/integrations/computer-integrations.mjs +11 -10
- package/foundation/integrations/icon-features.d.mts +1 -1
- package/foundation/integrations/icon-features.mjs +1 -1
- package/foundation/integrations/integration-warnings.d.mts +10 -0
- package/foundation/integrations/integration-warnings.mjs +12 -3
- package/foundation/integrations/integrations.d.mts +16 -2
- package/foundation/integrations/integrations.mjs +50 -8
- package/foundation/integrations/may-have-integrations.mjs +7 -6
- package/foundation/integrations/provider-resolution.mjs +19 -2
- package/foundation/integrations/validate-contributions.d.mts +4 -0
- package/foundation/integrations/validate-contributions.mjs +24 -0
- package/foundation/release/agent-text-worker.mjs +33 -1
- package/foundation/release/cache.d.mts +48 -3
- package/foundation/release/cache.mjs +196 -20
- package/foundation/release/choose.d.mts +5 -2
- package/foundation/release/choose.mjs +54 -4
- package/foundation/release/global-state.mjs +10 -2
- package/foundation/release/handoff.mjs +7 -1
- package/foundation/release/notices.d.mts +97 -9
- package/foundation/release/notices.mjs +381 -56
- package/foundation/release/project.d.mts +21 -4
- package/foundation/release/project.mjs +74 -42
- package/foundation/release/run-context.d.mts +6 -0
- package/foundation/release/run-context.mjs +9 -0
- package/foundation/render/assets.d.mts +7 -0
- package/foundation/render/assets.mjs +30 -17
- package/foundation/render/charts.d.mts +11 -10
- package/foundation/render/charts.mjs +112 -1
- package/foundation/render/class-alias.d.mts +23 -0
- package/foundation/render/class-alias.mjs +333 -0
- package/foundation/render/client-bundle.d.mts +183 -0
- package/foundation/render/client-bundle.mjs +1026 -0
- package/foundation/render/component-map.mjs +1 -1
- package/foundation/render/css-cut.d.mts +26 -0
- package/foundation/render/css-cut.mjs +344 -2
- package/foundation/render/dropped-text.d.mts +43 -0
- package/foundation/render/dropped-text.mjs +90 -0
- package/foundation/render/embedded-files.d.mts +24 -1
- package/foundation/render/embedded-files.mjs +41 -4
- package/foundation/render/embedded-imports.d.mts +72 -12
- package/foundation/render/embedded-imports.mjs +206 -70
- package/foundation/render/esbuild-dependency.d.mts +14 -0
- package/foundation/render/esbuild-dependency.mjs +41 -0
- package/foundation/render/file-header.d.mts +7 -2
- package/foundation/render/file-header.mjs +19 -10
- package/foundation/render/html-reader.d.mts +36 -17
- package/foundation/render/html-reader.mjs +239 -32
- package/foundation/render/image-attributes.d.mts +25 -0
- package/foundation/render/image-attributes.mjs +33 -0
- package/foundation/render/markup-edits.mjs +1 -1
- package/foundation/render/package-resolve-hooks.d.mts +54 -0
- package/foundation/render/package-resolve-hooks.mjs +144 -0
- package/foundation/render/page-host.mjs +1 -1
- package/foundation/render/page-worker.mjs +1307 -107
- package/foundation/render/picture-chrome.mjs +13 -1
- package/foundation/render/picture-playwright.mjs +13 -0
- package/foundation/render/picture-window.d.mts +18 -5
- package/foundation/render/picture-window.mjs +211 -19
- package/foundation/render/rebuild.mjs +2 -2
- package/foundation/render/remote-images.d.mts +83 -0
- package/foundation/render/remote-images.mjs +384 -0
- package/foundation/render/render-page.d.mts +214 -6
- package/foundation/render/render-page.mjs +1673 -163
- package/foundation/render/restore-folder.d.mts +13 -0
- package/foundation/render/restore-folder.mjs +30 -0
- package/foundation/render/served-packages.d.mts +14 -1
- package/foundation/render/served-packages.mjs +50 -6
- package/foundation/render/share-checks.d.mts +35 -0
- package/foundation/render/share-checks.mjs +95 -0
- package/foundation/render/source-block.d.mts +14 -3
- package/foundation/render/source-block.mjs +44 -9
- package/foundation/render/srcset.d.mts +32 -0
- package/foundation/render/srcset.mjs +64 -0
- package/foundation/render/ts-paths.d.mts +52 -1
- package/foundation/render/ts-paths.mjs +114 -4
- 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 +16 -10
- package/foundation/response/error-codes.mjs +19 -8
- package/foundation/response/json.d.mts +0 -15
- package/foundation/response/json.mjs +1 -51
- package/foundation/response/response-types.doc.mjs +24 -13
- package/foundation/runtime/css-tree.d.mts +16 -0
- package/foundation/runtime/css-tree.mjs +46 -3
- package/foundation/runtime/lazy-dependencies.d.mts +7 -0
- package/foundation/runtime/lazy-dependencies.mjs +25 -3
- package/foundation/runtime/locked-versions.d.mts +4 -2
- package/foundation/runtime/locked-versions.mjs +18 -10
- package/foundation/runtime/package-root.d.mts +25 -0
- package/foundation/runtime/package-root.mjs +48 -0
- package/foundation/runtime/word-table.d.mts +18 -0
- package/foundation/runtime/word-table.mjs +33 -0
- package/foundation/suggest/other-command.d.mts +23 -0
- package/foundation/suggest/other-command.mjs +49 -5
- package/foundation/text/default-variant.d.mts +20 -0
- package/foundation/text/default-variant.mjs +24 -0
- package/foundation/text/definition-coverage.d.mts +21 -0
- package/foundation/text/definition-coverage.mjs +20 -0
- package/foundation/text/icon-set-next.d.mts +11 -10
- package/foundation/text/icon-set-next.mjs +19 -11
- package/foundation/text/string-utils.mjs +14 -41
- package/foundation/text/suggest-order.d.mts +10 -4
- package/foundation/text/suggest-order.mjs +20 -13
- package/package.json +8 -6
- package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +0 -394
- package/assets/docs/tree/render-pages.doc.mjs +0 -135
- package/clients/cli/commands/experimental/render.mjs +0 -154
- package/clients/cli/commands/experimental-render.doc.mjs +0 -73
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @file `astryx experimental
|
|
4
|
+
* @file `astryx experimental export`, forward: one page module to ONE
|
|
5
5
|
* self-contained static HTML file. The page renders on the server with the
|
|
6
6
|
* project's own React and Astryx components; its own StyleX compiles in
|
|
7
7
|
* memory; Core's stylesheets are cut to the rules the markup uses; local
|
|
8
|
-
* images become data: URIs
|
|
9
|
-
*
|
|
8
|
+
* images become data: URIs, and so do the https images the page names,
|
|
9
|
+
* fetched once while it renders (remote-images.mjs); and the page's source
|
|
10
|
+
* rides along so `--reverse` can give it back exactly.
|
|
10
11
|
*
|
|
11
|
-
* The file needs no network and
|
|
12
|
-
*
|
|
12
|
+
* The file needs no network, and it carries the page's script, which draws
|
|
13
|
+
* the live page over the markup, so it works inside a sandboxed frame that
|
|
14
|
+
* allows scripts under a strict content security policy. Its colors follow
|
|
13
15
|
* `color-scheme` (and a `data-theme` of `light` or `dark` on the root), since
|
|
14
16
|
* Astryx tokens use light-dark().
|
|
15
17
|
*
|
|
@@ -21,8 +23,12 @@ import * as os from 'node:os';
|
|
|
21
23
|
import * as path from 'node:path';
|
|
22
24
|
import {fork, spawnSync} from 'node:child_process';
|
|
23
25
|
import {builtinModules} from 'node:module';
|
|
24
|
-
import {fileURLToPath} from 'node:url';
|
|
26
|
+
import {fileURLToPath, pathToFileURL} from 'node:url';
|
|
27
|
+
import {NOT_AN_IMAGE, showsImage} from './image-attributes.mjs';
|
|
28
|
+
import {formatSrcset, parseSrcset} from './srcset.mjs';
|
|
29
|
+
import * as vm from 'node:vm';
|
|
25
30
|
import postcss from 'postcss';
|
|
31
|
+
import {importUrl} from '../fs/import-url.mjs';
|
|
26
32
|
import {
|
|
27
33
|
assetDataUri,
|
|
28
34
|
isAssetBytes,
|
|
@@ -30,18 +36,29 @@ import {
|
|
|
30
36
|
MAX_ASSET_BYTES,
|
|
31
37
|
RenderAssetError,
|
|
32
38
|
} from './assets.mjs';
|
|
33
|
-
import {classesIn, cutCss, layerOrderOf} from './css-cut.mjs';
|
|
39
|
+
import {classesIn, cutCss, cutFontFaces, layerOrderOf} from './css-cut.mjs';
|
|
40
|
+
import {aliasClasses} from './class-alias.mjs';
|
|
34
41
|
import {asParsed, formatFor, sha256, sourceBlock} from './source-block.mjs';
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
42
|
+
import {LINK_OUT, ROOT_ID, compactSource, imageSinks} from './client-bundle.mjs';
|
|
43
|
+
import {remoteImages} from './remote-images.mjs';
|
|
44
|
+
import {ESBUILD_MISSING, findEsbuild} from './esbuild-dependency.mjs';
|
|
45
|
+
import {carriedNameFor, embeddedPathProblem} from './embedded-files.mjs';
|
|
46
|
+
import {scanHtml, VOID} from './html-reader.mjs';
|
|
37
47
|
import {removeOnStop} from '../fs/stop-cleanup.mjs';
|
|
38
|
-
import {aliasOnly, assetRefsOf} from './embedded-imports.mjs';
|
|
39
|
-
import {
|
|
40
|
-
import {
|
|
48
|
+
import {aliasOnly, assetRefsOf, fileNamed} from './embedded-imports.mjs';
|
|
49
|
+
import {babelParser} from '../runtime/lazy-dependencies.mjs';
|
|
50
|
+
import {isServedPackage, packageOf as specPackageOf, resolveServed} from './served-packages.mjs';
|
|
51
|
+
import {CHART_CSS, smallSvgText} from './charts.mjs';
|
|
41
52
|
import {HOST_EXIT} from './host-exit.mjs';
|
|
42
53
|
import {endNote, headerNote} from './file-header.mjs';
|
|
43
54
|
import {textRuns} from './markup-edits.mjs';
|
|
55
|
+
import {childrenReader, dropperOf} from './dropped-text.mjs';
|
|
44
56
|
import {findNodeModulesPackage, isInside} from '../fs/paths.mjs';
|
|
57
|
+
import {packageOf} from '../doc-compiler/source.mjs';
|
|
58
|
+
import {declaredColorModes} from '../discovery/color-modes.mjs';
|
|
59
|
+
import {alphaOf, parseColor, relativeLuminance} from '../color/css-color.mjs';
|
|
60
|
+
import {installedPackageOf} from './package-resolve-hooks.mjs';
|
|
61
|
+
import {moduleExportSource, resolvePackageModule} from '../discovery/module-exports.mjs';
|
|
45
62
|
|
|
46
63
|
/** How long one page may take to render before it is stopped. */
|
|
47
64
|
export const RENDER_TIMEOUT_MS = 60_000;
|
|
@@ -50,7 +67,7 @@ export {MODULE_EXTENSIONS, PAGE_EXTENSIONS} from './embedded-files.mjs';
|
|
|
50
67
|
|
|
51
68
|
/**
|
|
52
69
|
* @typedef {object} RenderWarning
|
|
53
|
-
* @property {'dropped-children' | 'remote-asset' | 'missing-asset' | 'page-output' | 'page-script' | 'no-astryx-styles' | 'chart-size' | 'screen-query' | 'not-embedded' | 'node-crash'} code - What kind of problem.
|
|
70
|
+
* @property {'dropped-children' | 'unknown-prop-value' | 'remote-asset' | 'missing-asset' | 'page-output' | 'page-script' | 'no-astryx-styles' | 'chart-size' | 'screen-query' | 'not-embedded' | 'not-carried' | 'node-crash'} code - What kind of problem.
|
|
54
71
|
* @property {string} message - What happened and what to do, in one sentence.
|
|
55
72
|
*/
|
|
56
73
|
|
|
@@ -62,9 +79,15 @@ export {MODULE_EXTENSIONS, PAGE_EXTENSIONS} from './embedded-files.mjs';
|
|
|
62
79
|
* @property {number} classes - Distinct class names in the markup.
|
|
63
80
|
* @property {number} cssBytes - Bytes of inlined CSS.
|
|
64
81
|
* @property {number} markupBytes - Bytes of rendered markup.
|
|
82
|
+
* @property {number} sourceBytes - Bytes of the embedded source block.
|
|
65
83
|
* @property {number} images - Local files inlined as data: URIs.
|
|
66
84
|
* @property {RenderWarning[]} warnings
|
|
85
|
+
* @property {string[]} [notCarried] - Files the page uses that the file does not carry, so experimental import cannot give them back (each also has a warning); present only when there are some.
|
|
86
|
+
* @property {{component: string, prop: string, value: string, file: string, line: number}[]} [propValues] - Each string the page's own files give a Core component's prop, for the caller to check against the component's docs.
|
|
67
87
|
* @property {{name: string, dir: string}[]} fromSet - Packages that came from the package set the CLI runs from, not the page's folder.
|
|
88
|
+
* @property {number} [scriptBytes] - Bytes of the page's script; none in a markup-only render.
|
|
89
|
+
* @property {number} [scriptModules] - The modules the page's script holds; none in a markup-only render.
|
|
90
|
+
* @property {{fetched: string[], failed: {url: string, reason: string}[]}} [remoteImages] - The https images the page names: each address fetched into the file, and each one left as the page wrote it, with why. Present when the page names a remote image and the render writes a file.
|
|
68
91
|
*/
|
|
69
92
|
|
|
70
93
|
/** An error carrying a render error code. */
|
|
@@ -135,6 +158,29 @@ function carryScopeOf(dir, cwd) {
|
|
|
135
158
|
return cwd && (dir === cwd || isInside(dir, cwd)) ? cwd : dir;
|
|
136
159
|
}
|
|
137
160
|
|
|
161
|
+
/**
|
|
162
|
+
* The folder whose `public/` holds the files a `/` path names: the page's
|
|
163
|
+
* project, when it holds `public/`. Else the nearest folder at or above the
|
|
164
|
+
* page's that holds `public/`, inside the folder whose files the page
|
|
165
|
+
* carries (a site that shares its project with others). Else the project's
|
|
166
|
+
* folder, else the page's.
|
|
167
|
+
* @param {string} dir the page's folder
|
|
168
|
+
* @param {string} scope the folder whose files the page carries
|
|
169
|
+
*/
|
|
170
|
+
function siteRootOf(dir, scope) {
|
|
171
|
+
/** @param {string} d */
|
|
172
|
+
const holdsPublic = d =>
|
|
173
|
+
fs.statSync(path.join(d, 'public'), {throwIfNoEntry: false})?.isDirectory() === true;
|
|
174
|
+
const project = projectOf(dir);
|
|
175
|
+
if (project && holdsPublic(project)) return project;
|
|
176
|
+
for (let d = dir; d === scope || isInside(d, scope); d = path.dirname(d)) {
|
|
177
|
+
if (holdsPublic(d)) return d;
|
|
178
|
+
// The walk ends at the scope; at the filesystem root, dirname is the root.
|
|
179
|
+
if (d === scope || path.dirname(d) === d) break;
|
|
180
|
+
}
|
|
181
|
+
return project ?? dir;
|
|
182
|
+
}
|
|
183
|
+
|
|
138
184
|
/** @param {string} s */
|
|
139
185
|
const escapeHtml = s =>
|
|
140
186
|
s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
@@ -149,19 +195,30 @@ const escapeHtml = s =>
|
|
|
149
195
|
* @param {string} markup
|
|
150
196
|
*/
|
|
151
197
|
function rootThemeAttrs(markup) {
|
|
198
|
+
const attrs = rootThemeElement(markup);
|
|
199
|
+
if (!attrs) return '';
|
|
200
|
+
return ['data-astryx-theme', 'data-theme']
|
|
201
|
+
.filter(a => attrs.has(a))
|
|
202
|
+
.map(
|
|
203
|
+
a =>
|
|
204
|
+
` ${a}="${escapeHtml(String(attrs.get(a))).replace(/"/g, '"')}"`,
|
|
205
|
+
)
|
|
206
|
+
.join('');
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* The attributes of the outermost element a theme marks: the root Theme's
|
|
211
|
+
* own. Null for a page with no theme.
|
|
212
|
+
* @param {string} markup
|
|
213
|
+
* @returns {Map<string, string> | null}
|
|
214
|
+
*/
|
|
215
|
+
function rootThemeElement(markup) {
|
|
152
216
|
for (const t of scanHtml(markup)) {
|
|
153
217
|
if (t.kind !== 'start') continue;
|
|
154
|
-
const attrs = new Map(t.attrs);
|
|
155
|
-
if (
|
|
156
|
-
return ['data-astryx-theme', 'data-theme']
|
|
157
|
-
.filter(a => attrs.has(a))
|
|
158
|
-
.map(
|
|
159
|
-
a =>
|
|
160
|
-
` ${a}="${escapeHtml(String(attrs.get(a))).replace(/"/g, '"')}"`,
|
|
161
|
-
)
|
|
162
|
-
.join('');
|
|
218
|
+
const attrs = new Map(t.attrs.map(([name, value]) => /** @type {[string, string]} */ ([name, value])));
|
|
219
|
+
if (attrs.has('data-astryx-theme')) return attrs;
|
|
163
220
|
}
|
|
164
|
-
return
|
|
221
|
+
return null;
|
|
165
222
|
}
|
|
166
223
|
|
|
167
224
|
/** @param {string} s */
|
|
@@ -179,7 +236,7 @@ const decodeAttr = s =>
|
|
|
179
236
|
* @param {string} params
|
|
180
237
|
* @returns {{url: string, layer: string | null, supports: string | null, media: string} | null}
|
|
181
238
|
*/
|
|
182
|
-
function importParams(params) {
|
|
239
|
+
export function importParams(params) {
|
|
183
240
|
const m =
|
|
184
241
|
/^\s*(?:url\(\s*(['"]?)([\s\S]*?)\1\s*\)|(['"])([\s\S]*?)\3)\s*([\s\S]*)$/.exec(
|
|
185
242
|
params,
|
|
@@ -205,6 +262,148 @@ function importParams(params) {
|
|
|
205
262
|
return {url: m[2] ?? m[4] ?? '', layer, supports, media: rest.trim()};
|
|
206
263
|
}
|
|
207
264
|
|
|
265
|
+
/**
|
|
266
|
+
* Where a stylesheet's `@import` of `url` leads, read the way a render inlines
|
|
267
|
+
* it: a relative one from the importing sheet's folder, a package one
|
|
268
|
+
* (`@scope/pkg/x.css`) by Node resolution from the importing sheet.
|
|
269
|
+
* @param {string} url the import's address, as written
|
|
270
|
+
* @param {string} file the importing stylesheet's path
|
|
271
|
+
* @param {ServedSet | null} served
|
|
272
|
+
* @returns {{kind: 'remote'} | {kind: 'preprocessed'} | {kind: 'missing'} | {kind: 'sheet', target: string, fromPackage: boolean}}
|
|
273
|
+
*/
|
|
274
|
+
function resolveImport(url, file, served) {
|
|
275
|
+
if (/^([a-z]+:)?\/\//i.test(url)) return {kind: 'remote'};
|
|
276
|
+
if (/\.(scss|sass|less)$/i.test(url)) return {kind: 'preprocessed'};
|
|
277
|
+
const relative = path.resolve(path.dirname(file), url);
|
|
278
|
+
if (/^\.{1,2}\//.test(url) || fs.existsSync(relative)) {
|
|
279
|
+
return fs.existsSync(relative)
|
|
280
|
+
? {kind: 'sheet', target: relative, fromPackage: false}
|
|
281
|
+
: {kind: 'missing'};
|
|
282
|
+
}
|
|
283
|
+
const target = resolveServed(url.replace(/^~/, ''), file, served);
|
|
284
|
+
return target ? {kind: 'sheet', target, fromPackage: true} : {kind: 'missing'};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Whether one of the stylesheets a page brings in is an Astryx package's, or
|
|
289
|
+
* reaches one through its `@import`s, followed as {@link expandImports}
|
|
290
|
+
* follows them. A stylesheet counts by the package that holds its file, as a
|
|
291
|
+
* module counts in the page's script; an import that resolves to no file
|
|
292
|
+
* counts by the package it names.
|
|
293
|
+
* @param {string[]} files the page's own stylesheets and the package
|
|
294
|
+
* stylesheets its script imports
|
|
295
|
+
* @param {ServedSet | null} served
|
|
296
|
+
* @returns {boolean}
|
|
297
|
+
*/
|
|
298
|
+
function reachesAstryxSheet(files, served) {
|
|
299
|
+
/** @type {Set<string>} */
|
|
300
|
+
const seen = new Set();
|
|
301
|
+
/** @param {string} file @returns {boolean} */
|
|
302
|
+
const visit = file => {
|
|
303
|
+
if (seen.has(file)) return false;
|
|
304
|
+
seen.add(file);
|
|
305
|
+
if (packageOf(file).startsWith('@astryxdesign/')) return true;
|
|
306
|
+
/** @type {import('postcss').Root} */
|
|
307
|
+
let root;
|
|
308
|
+
try {
|
|
309
|
+
const css = fs.readFileSync(file, 'utf8');
|
|
310
|
+
if (!/@import/i.test(css)) return false;
|
|
311
|
+
root = postcss.parse(css, {from: file});
|
|
312
|
+
} catch {
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
let found = false;
|
|
316
|
+
root.walkAtRules(/^import$/i, rule => {
|
|
317
|
+
const url = importParams(rule.params)?.url;
|
|
318
|
+
if (found || !url) return;
|
|
319
|
+
const to = resolveImport(url, file, served);
|
|
320
|
+
if (to.kind === 'sheet') found = visit(to.target);
|
|
321
|
+
else if (to.kind === 'missing') found = /^@astryxdesign\//.test(url.replace(/^~/, ''));
|
|
322
|
+
});
|
|
323
|
+
return found;
|
|
324
|
+
};
|
|
325
|
+
return files.some(visit);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* A stylesheet's text as an `@import` brings it in: inside the import's
|
|
330
|
+
* `supports()`, media and `layer()` conditions.
|
|
331
|
+
* @param {{layer: string | null, supports: string | null, media: string}} parsed
|
|
332
|
+
* the import's parts, as {@link importParams} reads them
|
|
333
|
+
* @param {string} css
|
|
334
|
+
* @returns {string}
|
|
335
|
+
*/
|
|
336
|
+
function underImportConditions(parsed, css) {
|
|
337
|
+
let inner = css;
|
|
338
|
+
if (parsed.supports)
|
|
339
|
+
inner = `@supports (${parsed.supports.replace(/^\((.*)\)$/s, '$1')}){${inner}}`;
|
|
340
|
+
if (parsed.media) inner = `@media ${parsed.media}{${inner}}`;
|
|
341
|
+
if (parsed.layer !== null)
|
|
342
|
+
inner = `@layer${parsed.layer ? ` ${parsed.layer}` : ''}{${inner}}`;
|
|
343
|
+
return inner;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* The stylesheets a page brings in, with every stylesheet their `@import`s
|
|
348
|
+
* reach, followed as {@link expandImports} follows them: each one's file and
|
|
349
|
+
* text, and for a package's stylesheet the package and the file that names
|
|
350
|
+
* it.
|
|
351
|
+
* @param {(ThemeSheet & {css: string})[]} sheets
|
|
352
|
+
* @param {ServedSet | null} served
|
|
353
|
+
* @returns {(ThemeSheet & {css: string})[]}
|
|
354
|
+
*/
|
|
355
|
+
function sheetsWithImports(sheets, served) {
|
|
356
|
+
/** @type {(ThemeSheet & {css: string})[]} */
|
|
357
|
+
const out = [];
|
|
358
|
+
/** @type {Set<string>} */
|
|
359
|
+
const seen = new Set();
|
|
360
|
+
/**
|
|
361
|
+
* @param {ThemeSheet & {css: string}} sheet its own text
|
|
362
|
+
* @param {(css: string) => string} scope wraps a text in every condition
|
|
363
|
+
* of the `@import` chain that brought the sheet in
|
|
364
|
+
*/
|
|
365
|
+
const visit = (sheet, scope) => {
|
|
366
|
+
if (seen.has(sheet.file)) return;
|
|
367
|
+
seen.add(sheet.file);
|
|
368
|
+
out.push({...sheet, css: scope(sheet.css)});
|
|
369
|
+
if (!/@import/i.test(sheet.css)) return;
|
|
370
|
+
/** @type {import('postcss').Root} */
|
|
371
|
+
let root;
|
|
372
|
+
try {
|
|
373
|
+
root = postcss.parse(sheet.css, {from: sheet.file});
|
|
374
|
+
} catch {
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
root.walkAtRules(/^import$/i, rule => {
|
|
378
|
+
const parsed = importParams(rule.params);
|
|
379
|
+
const url = parsed?.url;
|
|
380
|
+
if (!parsed || !url) return;
|
|
381
|
+
const to = resolveImport(url, sheet.file, served);
|
|
382
|
+
if (to.kind !== 'sheet') return;
|
|
383
|
+
/** @type {string} */
|
|
384
|
+
let css;
|
|
385
|
+
try {
|
|
386
|
+
css = fs.readFileSync(to.target, 'utf8');
|
|
387
|
+
} catch {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
// Each import's conditions scope the sheet's rules, inside those of
|
|
391
|
+
// the imports before it, as the file inlines them: a sheet imported
|
|
392
|
+
// for one scheme, at any depth, counts as such.
|
|
393
|
+
/** @param {string} text */
|
|
394
|
+
const inner = text => scope(underImportConditions(parsed, text));
|
|
395
|
+
visit(
|
|
396
|
+
to.fromPackage
|
|
397
|
+
? {file: to.target, css, pkg: specPackageOf(url.replace(/^~/, '')), from: sheet.file}
|
|
398
|
+
: {file: to.target, css},
|
|
399
|
+
inner,
|
|
400
|
+
);
|
|
401
|
+
});
|
|
402
|
+
};
|
|
403
|
+
for (const sheet of sheets) visit(sheet, text => text);
|
|
404
|
+
return out;
|
|
405
|
+
}
|
|
406
|
+
|
|
208
407
|
/**
|
|
209
408
|
* Inline a stylesheet's own `@import`s, so a stylesheet pulled in that way is
|
|
210
409
|
* part of the file: a relative one from the importing sheet's folder
|
|
@@ -216,7 +415,9 @@ function importParams(params) {
|
|
|
216
415
|
* cut.
|
|
217
416
|
* @param {string} file the stylesheet's own path
|
|
218
417
|
* @param {string} css its text
|
|
219
|
-
* @param {{warnings: RenderWarning[], carried: Set<string>, included: Set<string>, packageSheets: string[], served: ServedSet | null, seen?: Set<string>}} ctx
|
|
418
|
+
* @param {{warnings: RenderWarning[], carried: Set<string>, importers: Map<string, Set<string>>, included: Set<string>, packageSheets: string[], served: ServedSet | null, seen?: Set<string>}} ctx
|
|
419
|
+
* `importers`: each project stylesheet an `@import` names, with every
|
|
420
|
+
* sheet that imports it
|
|
220
421
|
* `included`: stylesheet files already in the page (Core's, say), never
|
|
221
422
|
* inlined twice; `packageSheets`: package stylesheets this pulled in
|
|
222
423
|
* @returns {string}
|
|
@@ -235,7 +436,8 @@ function expandImports(file, css, ctx) {
|
|
|
235
436
|
const parsed = importParams(rule.params);
|
|
236
437
|
if (!parsed || !parsed.url) return;
|
|
237
438
|
const {url} = parsed;
|
|
238
|
-
|
|
439
|
+
const to = resolveImport(url, file, ctx.served);
|
|
440
|
+
if (to.kind === 'remote') {
|
|
239
441
|
ctx.warnings.push({
|
|
240
442
|
code: 'remote-asset',
|
|
241
443
|
message: `${path.basename(file)} imports ${url}, which a sandboxed page cannot load, so it is left out; save it beside the stylesheet and import it instead.`,
|
|
@@ -243,7 +445,7 @@ function expandImports(file, css, ctx) {
|
|
|
243
445
|
rule.remove();
|
|
244
446
|
return;
|
|
245
447
|
}
|
|
246
|
-
if (
|
|
448
|
+
if (to.kind === 'preprocessed') {
|
|
247
449
|
ctx.warnings.push({
|
|
248
450
|
code: 'missing-asset',
|
|
249
451
|
message: `${path.basename(file)} imports ${url}, a Sass or Less stylesheet, which a render does not compile, so its styles are missing.`,
|
|
@@ -251,17 +453,7 @@ function expandImports(file, css, ctx) {
|
|
|
251
453
|
rule.remove();
|
|
252
454
|
return;
|
|
253
455
|
}
|
|
254
|
-
|
|
255
|
-
/** @type {string | null} */
|
|
256
|
-
let target;
|
|
257
|
-
let fromPackage = false;
|
|
258
|
-
if (/^\.{1,2}\//.test(url) || fs.existsSync(relative)) {
|
|
259
|
-
target = fs.existsSync(relative) ? relative : null;
|
|
260
|
-
} else {
|
|
261
|
-
target = resolveServed(url.replace(/^~/, ''), file, ctx.served);
|
|
262
|
-
fromPackage = target !== null;
|
|
263
|
-
}
|
|
264
|
-
if (!target) {
|
|
456
|
+
if (to.kind === 'missing') {
|
|
265
457
|
ctx.warnings.push({
|
|
266
458
|
code: 'missing-asset',
|
|
267
459
|
message: `${path.basename(file)} imports ${url}, which was not found, so its styles are missing.`,
|
|
@@ -269,6 +461,8 @@ function expandImports(file, css, ctx) {
|
|
|
269
461
|
rule.remove();
|
|
270
462
|
return;
|
|
271
463
|
}
|
|
464
|
+
const {target, fromPackage} = to;
|
|
465
|
+
if (!fromPackage) ctx.importers.set(target, (ctx.importers.get(target) ?? new Set()).add(file));
|
|
272
466
|
if (seen.has(target) || ctx.included.has(target)) {
|
|
273
467
|
rule.remove();
|
|
274
468
|
return;
|
|
@@ -292,11 +486,7 @@ function expandImports(file, css, ctx) {
|
|
|
292
486
|
return `url(${q}${rebased.startsWith('.') ? rebased : `./${rebased}`}${q})`;
|
|
293
487
|
});
|
|
294
488
|
// The import's conditions still scope what it brings in.
|
|
295
|
-
|
|
296
|
-
inner = `@supports (${parsed.supports.replace(/^\((.*)\)$/s, '$1')}){${inner}}`;
|
|
297
|
-
if (parsed.media) inner = `@media ${parsed.media}{${inner}}`;
|
|
298
|
-
if (parsed.layer !== null)
|
|
299
|
-
inner = `@layer${parsed.layer ? ` ${parsed.layer}` : ''}{${inner}}`;
|
|
489
|
+
inner = underImportConditions(parsed, inner);
|
|
300
490
|
try {
|
|
301
491
|
rule.replaceWith(postcss.parse(inner, {from}).nodes);
|
|
302
492
|
} catch (e) {
|
|
@@ -670,7 +860,7 @@ export function awaitHost(host, {timeoutMs, withoutSegmenter, stateFile}) {
|
|
|
670
860
|
/**
|
|
671
861
|
* Run the page. When this Node crashes in Intl.Segmenter, run it once more
|
|
672
862
|
* without Intl.Segmenter and say so in a warning.
|
|
673
|
-
* @param {{entry: string, root: string, scope: string, served: ServedSet | null, openLayers?: boolean}} input
|
|
863
|
+
* @param {{entry: string, root: string, scope: string, served: ServedSet | null, openLayers?: boolean, buildScript?: boolean, esbuild?: string}} input
|
|
674
864
|
* @param {number} timeoutMs
|
|
675
865
|
* @param {RenderWarning[]} warnings
|
|
676
866
|
*/
|
|
@@ -690,6 +880,258 @@ async function runPage(input, timeoutMs, warnings) {
|
|
|
690
880
|
return again;
|
|
691
881
|
}
|
|
692
882
|
|
|
883
|
+
/**
|
|
884
|
+
* The markup with each link out of the file opening in a new tab, as the
|
|
885
|
+
* file's script opens it once it runs (client-bundle.mjs): a viewer's frame
|
|
886
|
+
* cannot follow a link out. A link that names its own target keeps it.
|
|
887
|
+
* @param {string} markup the page's server markup
|
|
888
|
+
* @returns {string}
|
|
889
|
+
*/
|
|
890
|
+
export function linksOpenNewTabs(markup) {
|
|
891
|
+
return markup.replace(/<a\b([^>]*)>/g, (tag, /** @type {string} */ attrs) => {
|
|
892
|
+
const href = /\shref="([^"]*)"/.exec(attrs)?.[1];
|
|
893
|
+
if (href === undefined || /\starget="/.test(attrs) || !LINK_OUT.test(href.trim())) return tag;
|
|
894
|
+
const rel = /\srel="([^"]*)"/.exec(attrs);
|
|
895
|
+
const rels = new Set([...(rel ? rel[1].split(/\s+/).filter(Boolean) : []), 'noopener', 'noreferrer']);
|
|
896
|
+
return `<a${rel ? attrs.replace(rel[0], '') : attrs} target="_blank" rel="${[...rels].join(' ')}">`;
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
/**
|
|
901
|
+
* The markup without `autofocus`. The file's script owns focus once it draws
|
|
902
|
+
* the page, as the app does. A viewer's cross-origin frame blocks focus that
|
|
903
|
+
* markup asks for, and logs an error.
|
|
904
|
+
* @param {string} markup the page's server markup
|
|
905
|
+
* @returns {string}
|
|
906
|
+
*/
|
|
907
|
+
export function withoutAutofocus(markup) {
|
|
908
|
+
let out = '';
|
|
909
|
+
let at = 0;
|
|
910
|
+
for (const token of scanHtml(markup)) {
|
|
911
|
+
if (token.kind !== 'start') continue;
|
|
912
|
+
for (const [name, , start, end] of token.attrs) {
|
|
913
|
+
if (name !== 'autofocus') continue;
|
|
914
|
+
// The attribute goes with the spaces before it; the reader names
|
|
915
|
+
// where its text starts and ends, so every other attribute stays as
|
|
916
|
+
// written.
|
|
917
|
+
// Not when a `/` follows: `<input title=x/>` would read as title="x/".
|
|
918
|
+
let from = start;
|
|
919
|
+
if (markup[end] !== '/') {
|
|
920
|
+
while (from > token.start && /[\t\n\f\r ]/.test(markup[from - 1])) from--;
|
|
921
|
+
}
|
|
922
|
+
out += markup.slice(at, from);
|
|
923
|
+
at = end;
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
return at === 0 ? markup : out + markup.slice(at);
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
/**
|
|
930
|
+
* The render's own attribute on a first-paint element whose `src`, `srcset`
|
|
931
|
+
* or `poster` it carries: each attribute with the number of its value
|
|
932
|
+
* (`src:0 srcset:1`), so the page's script reads the value there
|
|
933
|
+
* ({@link withCarriedPaths}). Only the file's markup has it, never the page's
|
|
934
|
+
* source.
|
|
935
|
+
*/
|
|
936
|
+
export const CARRY_ATTR = 'data-astryx-carried';
|
|
937
|
+
|
|
938
|
+
/** The name the script reads the markup's carried values from. */
|
|
939
|
+
const CARRIED_VALUES = '__astryxCarried';
|
|
940
|
+
|
|
941
|
+
/** The script's reader of one candidate of a carried `srcset`, by its place. */
|
|
942
|
+
const CARRIED_CANDIDATE = '__astryxCandidate';
|
|
943
|
+
|
|
944
|
+
/**
|
|
945
|
+
* The script's first statement: each value the markup carries, read from the
|
|
946
|
+
* first paint by its number before the script draws the page again.
|
|
947
|
+
*/
|
|
948
|
+
const CARRIED_PRELUDE =
|
|
949
|
+
`var ${CARRIED_VALUES}=(()=>{const v=[];for(const e of document.querySelectorAll('[${CARRY_ATTR}]'))` +
|
|
950
|
+
`for(const c of e.getAttribute('${CARRY_ATTR}').split(' ')){const [a,i]=c.split(':');v[+i]??=e.getAttribute(a)}return v})();`;
|
|
951
|
+
|
|
952
|
+
/**
|
|
953
|
+
* The page's script with each string the markup's rewrite replaced (an
|
|
954
|
+
* image's `src`, `poster` or `srcset`, as the page wrote it) read from the
|
|
955
|
+
* markup, which carries the same data, so the page the script draws shows
|
|
956
|
+
* what the first paint showed and the file holds that data once. A read
|
|
957
|
+
* replaces only a whole string token of the script whose value is exactly
|
|
958
|
+
* that path, found with a JavaScript parser. Every other place the path
|
|
959
|
+
* appears keeps the data itself: a longer string that holds it (inner HTML,
|
|
960
|
+
* a CSS `url()`), a value no first-paint element carries (an image the page
|
|
961
|
+
* shows only later), an object key, or a template a tag reads. A script the
|
|
962
|
+
* parser cannot read, or that would not parse with the reads, keeps the data
|
|
963
|
+
* everywhere.
|
|
964
|
+
* @param {string} script
|
|
965
|
+
* @param {Map<string, string>} rewrites
|
|
966
|
+
* @param {Map<string, number>} carried each value the first paint carries, with
|
|
967
|
+
* the number its mark gives it
|
|
968
|
+
* @param {Set<string>} [srcsets] the carried values a `srcset` marks: only
|
|
969
|
+
* their candidates are read by place
|
|
970
|
+
* @param {Map<string, string>} [painted] what each value became in the first
|
|
971
|
+
* paint (default `rewrites`): a whole value is read only where the script's
|
|
972
|
+
* value is the same, so a srcset that lists an https candidate, which the
|
|
973
|
+
* script keeps as written, is never read whole
|
|
974
|
+
* @param {boolean} [strict] the script is a module script, so it parses in
|
|
975
|
+
* strict mode
|
|
976
|
+
* @returns {string}
|
|
977
|
+
*/
|
|
978
|
+
export function withCarriedPaths(script, rewrites, carried, srcsets = new Set(), painted = rewrites, strict = false) {
|
|
979
|
+
const inline = inlineCarried(script, rewrites);
|
|
980
|
+
const tokens = carriedTokens(script, rewrites, carried, srcsets, painted);
|
|
981
|
+
if (tokens.length === 0) return inline;
|
|
982
|
+
// Each token to read becomes a mark no script holds (the script is built
|
|
983
|
+
// ASCII-only, so it never holds a raw private-use character), so the text
|
|
984
|
+
// pass below writes the data everywhere else; then each mark becomes its read.
|
|
985
|
+
let marked = '';
|
|
986
|
+
let at = 0;
|
|
987
|
+
for (const token of tokens) {
|
|
988
|
+
marked += `${script.slice(at, token.start)}\uE000${Array.isArray(token.index) ? token.index.join('.') : token.index}\uE001`;
|
|
989
|
+
at = token.end;
|
|
990
|
+
}
|
|
991
|
+
marked += script.slice(at);
|
|
992
|
+
const candidates = tokens.some(token => Array.isArray(token.index));
|
|
993
|
+
const read =
|
|
994
|
+
CARRIED_PRELUDE +
|
|
995
|
+
(candidates ? `var ${CARRIED_CANDIDATE}=(i,k)=>(${compactSource(parseSrcset)})(${CARRIED_VALUES}[i]??'')[k]?.url;` : '') +
|
|
996
|
+
inlineCarried(marked, rewrites).replace(/\uE000(\d+)(?:\.(\d+))?\uE001/g, (_, i, k, offset, all) =>
|
|
997
|
+
`${/[\w$]/.test(all[offset - 1] ?? '') ? ' ' : ''}${k === undefined ? `${CARRIED_VALUES}[${i}]` : `${CARRIED_CANDIDATE}(${i},${k})`}`,
|
|
998
|
+
);
|
|
999
|
+
try {
|
|
1000
|
+
// A module script parses in strict mode, so the reads must too.
|
|
1001
|
+
new vm.Script(strict ? `"use strict";${read}` : read);
|
|
1002
|
+
return read;
|
|
1003
|
+
} catch {
|
|
1004
|
+
return inline;
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
/**
|
|
1009
|
+
* The string tokens of the script whose value is exactly a path the first
|
|
1010
|
+
* paint carries, where a read can stand: not an object key, not a template a
|
|
1011
|
+
* tag reads, not text the page shows (`children`). In script order.
|
|
1012
|
+
* @param {string} script
|
|
1013
|
+
* @param {Map<string, string>} rewrites
|
|
1014
|
+
* @param {Map<string, number>} carried
|
|
1015
|
+
* @param {Set<string>} srcsets the carried values a `srcset` marks
|
|
1016
|
+
* @param {Map<string, string>} painted what each value became in the first paint
|
|
1017
|
+
* @returns {{start: number, end: number, index: number | [number, number]}[]}
|
|
1018
|
+
*/
|
|
1019
|
+
function carriedTokens(script, rewrites, carried, srcsets, painted) {
|
|
1020
|
+
/** @type {Map<string, number | [number, number]>} */
|
|
1021
|
+
const indexOf = new Map();
|
|
1022
|
+
/** @param {string} value */
|
|
1023
|
+
const quoted = value => !/["'`\\\n]/.test(value) && ['"', "'", '`'].some(q => script.includes(`${q}${value}${q}`));
|
|
1024
|
+
for (const [was] of rewrites) {
|
|
1025
|
+
const index = carried.get(was);
|
|
1026
|
+
if (index !== undefined && painted.get(was) === rewrites.get(was) && quoted(was)) indexOf.set(was, index);
|
|
1027
|
+
}
|
|
1028
|
+
// A local path the script names that a carried srcset lists
|
|
1029
|
+
// (`${a} 1x, ${b} 2x` built in code): read that candidate.
|
|
1030
|
+
for (const [, i, written] of carriedSrcsets(carried, srcsets, rewrites)) {
|
|
1031
|
+
written.forEach(({url}, k) => {
|
|
1032
|
+
if (!indexOf.has(url) && rewrites.has(url) && !/^(https?:)?\/\//i.test(url) && quoted(url)) indexOf.set(url, [i, k]);
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
if (indexOf.size === 0) return [];
|
|
1036
|
+
/** @type {any} */
|
|
1037
|
+
let ast;
|
|
1038
|
+
try {
|
|
1039
|
+
ast = babelParser().parse(script, {sourceType: 'script', errorRecovery: false});
|
|
1040
|
+
} catch {
|
|
1041
|
+
return [];
|
|
1042
|
+
}
|
|
1043
|
+
/** @type {{start: number, end: number, index: number | [number, number]}[]} */
|
|
1044
|
+
const found = [];
|
|
1045
|
+
/** @param {any} node @param {any} parent */
|
|
1046
|
+
const visit = (node, parent) => {
|
|
1047
|
+
if (node === null || typeof node !== 'object') return;
|
|
1048
|
+
if (Array.isArray(node)) {
|
|
1049
|
+
for (const child of node) visit(child, parent);
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
if (typeof node.type !== 'string') return;
|
|
1053
|
+
/** @type {string | undefined} */
|
|
1054
|
+
let value;
|
|
1055
|
+
if (node.type === 'StringLiteral') value = node.value;
|
|
1056
|
+
else if (node.type === 'TemplateLiteral' && node.expressions.length === 0 && parent?.type !== 'TaggedTemplateExpression') value = node.quasis[0]?.value?.cooked;
|
|
1057
|
+
if (value !== undefined && indexOf.has(value)) {
|
|
1058
|
+
const key = KEYED.has(parent?.type) && parent.key === node;
|
|
1059
|
+
const shown = parent?.type === 'ObjectProperty' && parent.value === node && !parent.computed && (parent.key?.name ?? parent.key?.value) === 'children';
|
|
1060
|
+
if (!key && !shown) found.push({start: node.start, end: node.end, index: /** @type {number | [number, number]} */ (indexOf.get(value))});
|
|
1061
|
+
}
|
|
1062
|
+
for (const k of Object.keys(node)) {
|
|
1063
|
+
if (k === 'loc' || k === 'start' || k === 'end' || k === 'extra' || k === 'leadingComments' || k === 'trailingComments') continue;
|
|
1064
|
+
visit(node[k], node);
|
|
1065
|
+
}
|
|
1066
|
+
};
|
|
1067
|
+
try {
|
|
1068
|
+
visit(ast.program, null);
|
|
1069
|
+
} catch {
|
|
1070
|
+
// A script nested too deep to walk keeps its inline data.
|
|
1071
|
+
return [];
|
|
1072
|
+
}
|
|
1073
|
+
return found.sort((a, b) => a.start - b.start);
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
/** The nodes whose `key` names a member: a string there is a name, not a value. */
|
|
1077
|
+
const KEYED = new Set(['ObjectProperty', 'ObjectMethod', 'ClassProperty', 'ClassMethod', 'ClassPrivateProperty', 'ClassAccessorProperty']);
|
|
1078
|
+
|
|
1079
|
+
/**
|
|
1080
|
+
* The script with each string that is exactly a path the markup's rewrite
|
|
1081
|
+
* replaced written as the same data, and each CSS url() that names it too.
|
|
1082
|
+
* Text the page shows (`children: "./photo.png"`) stays as written.
|
|
1083
|
+
* @param {string} script
|
|
1084
|
+
* @param {Map<string, string>} rewrites
|
|
1085
|
+
* @returns {string}
|
|
1086
|
+
*/
|
|
1087
|
+
function inlineCarried(script, rewrites) {
|
|
1088
|
+
let out = script;
|
|
1089
|
+
for (const [was, now] of rewrites) {
|
|
1090
|
+
if (/["'`\\\n<]/.test(now) || /["'`\\\n]/.test(was)) continue;
|
|
1091
|
+
for (const quote of ['"', "'", '`']) {
|
|
1092
|
+
const literal = `${quote}${was}${quote}`;
|
|
1093
|
+
out = out
|
|
1094
|
+
.split(literal)
|
|
1095
|
+
.map((part, i, parts) =>
|
|
1096
|
+
i === parts.length - 1 ? part : /\bchildren:\s*$/.test(part) ? `${part}${literal}` : `${part}${quote}${now}${quote}`,
|
|
1097
|
+
)
|
|
1098
|
+
.join('');
|
|
1099
|
+
}
|
|
1100
|
+
// A CSS url() in a style the script sets (`backgroundImage:
|
|
1101
|
+
// "url(./bg.png)"`) names the same file. A data: URI with no space,
|
|
1102
|
+
// quote or parenthesis needs no quotes in url().
|
|
1103
|
+
if (/[\s()]/.test(now)) continue;
|
|
1104
|
+
for (const form of [`url(${was})`, `url("${was}")`, `url('${was}')`]) {
|
|
1105
|
+
out = out.split(form).join(`url(${now})`);
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
return out;
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
/**
|
|
1112
|
+
* A call of the script's `carried(sha256, prefix)`, which reads an image from
|
|
1113
|
+
* the embedded source. It starts only where a name starts, so a long run of
|
|
1114
|
+
* name characters (a large string in the page) is read once, not once per
|
|
1115
|
+
* character.
|
|
1116
|
+
*/
|
|
1117
|
+
const CARRIED_CALL = /(?<![\w$])[A-Za-z_$][\w$]*\((["'])([0-9a-f]{64})\1,\s*(["'])(data:[^"']*;base64)\3\)/g;
|
|
1118
|
+
|
|
1119
|
+
/**
|
|
1120
|
+
* The script with each image the embedded source does not carry written in
|
|
1121
|
+
* as its data: URI (`uriOf` gives it), so the image still shows once the
|
|
1122
|
+
* script draws the page.
|
|
1123
|
+
* @param {string} script
|
|
1124
|
+
* @param {Set<string>} carried the SHA-256 of each file the source carries
|
|
1125
|
+
* @param {(sha256: string, prefix: string) => string | null} uriOf
|
|
1126
|
+
*/
|
|
1127
|
+
export function withUncarriedImages(script, carried, uriOf) {
|
|
1128
|
+
return script.replace(CARRIED_CALL, (call, _q, sha, _p, prefix) => {
|
|
1129
|
+
if (carried.has(sha)) return call;
|
|
1130
|
+
const uri = uriOf(sha, prefix);
|
|
1131
|
+
return uri === null ? call : JSON.stringify(uri);
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
|
|
693
1135
|
/**
|
|
694
1136
|
* The warning for a page rendered without Intl.Segmenter.
|
|
695
1137
|
* @returns {RenderWarning}
|
|
@@ -718,6 +1160,31 @@ export function cssUrlRef(m) {
|
|
|
718
1160
|
return m.groups?.dq ?? m.groups?.sq ?? m.groups?.bare ?? '';
|
|
719
1161
|
}
|
|
720
1162
|
|
|
1163
|
+
/** The rel values of a `<link>` the browser fetches its href for. */
|
|
1164
|
+
const FETCHING_RELS = new Set([
|
|
1165
|
+
'stylesheet',
|
|
1166
|
+
'icon',
|
|
1167
|
+
'apple-touch-icon',
|
|
1168
|
+
'mask-icon',
|
|
1169
|
+
'manifest',
|
|
1170
|
+
'preload',
|
|
1171
|
+
'modulepreload',
|
|
1172
|
+
'prefetch',
|
|
1173
|
+
]);
|
|
1174
|
+
|
|
1175
|
+
/**
|
|
1176
|
+
* A reference that loads nothing when the file opens: inline data, a
|
|
1177
|
+
* fragment, or a scheme that names no file (about:, mailto:, tel:,
|
|
1178
|
+
* javascript:).
|
|
1179
|
+
*/
|
|
1180
|
+
const NOT_A_LOAD = /^(data:|blob:|#|about:|mailto:|tel:|javascript:)/i;
|
|
1181
|
+
|
|
1182
|
+
/**
|
|
1183
|
+
* Whether a reference, as written, makes the browser load something.
|
|
1184
|
+
* @param {string} ref
|
|
1185
|
+
*/
|
|
1186
|
+
export const isLoad = ref => ref.trim() !== '' && !NOT_A_LOAD.test(ref.trim());
|
|
1187
|
+
|
|
721
1188
|
/**
|
|
722
1189
|
* What a local file reference of a page or stylesheet names: nothing to
|
|
723
1190
|
* inline (inline data, a fragment, a non-asset path), a remote file, a file
|
|
@@ -726,32 +1193,29 @@ export function cssUrlRef(m) {
|
|
|
726
1193
|
* and for callers that say what a page will not show.
|
|
727
1194
|
* @param {string} ref as written in src, poster or url()
|
|
728
1195
|
* @param {{dir: string, root: string}} at the folder it is relative to,
|
|
729
|
-
* and the
|
|
1196
|
+
* and the site's root, whose `public/` holds the files `/` paths name
|
|
730
1197
|
* A reference is URL text: it names the file its percent-escapes decode to
|
|
731
1198
|
* (`a%20b.png` is "a b.png"), as a browser and the app's bundler read it.
|
|
732
1199
|
* A file that cannot be read (no permission) is `unreadable`.
|
|
733
|
-
*
|
|
1200
|
+
* A remote file's `url` is the whole address the page wrote, its query too.
|
|
1201
|
+
* @returns {null | {kind: 'remote', ref: string, url: string} | {kind: 'missing', ref: string} | {kind: 'not-file' | 'unreadable' | 'file', ref: string, file: string}}
|
|
734
1202
|
*/
|
|
735
1203
|
export function assetRef(ref, at) {
|
|
736
1204
|
const clean = decodeAttr(ref).trim().split(/[?#]/)[0];
|
|
737
1205
|
if (!clean) return null;
|
|
738
|
-
if (
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
/** @type {string} */
|
|
742
|
-
let named;
|
|
743
|
-
try {
|
|
744
|
-
named = decodeURIComponent(clean);
|
|
745
|
-
} catch {
|
|
746
|
-
// A % that starts no escape is the character itself.
|
|
747
|
-
named = clean;
|
|
748
|
-
}
|
|
1206
|
+
if (NOT_A_LOAD.test(clean)) return null;
|
|
1207
|
+
if (/^(https?:)?\/\//i.test(clean)) return {kind: 'remote', ref: clean, url: decodeAttr(ref).trim()};
|
|
1208
|
+
const named = fileNamed(clean);
|
|
749
1209
|
if (!isAssetPath(named)) return null;
|
|
750
|
-
const
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
1210
|
+
const publicDir = path.join(at.root, 'public');
|
|
1211
|
+
const found = named.startsWith('/')
|
|
1212
|
+
? path.join(publicDir, named)
|
|
1213
|
+
: path.resolve(at.dir, named);
|
|
1214
|
+
// A `/` path is served from public/ only; one that climbs out of it names
|
|
1215
|
+
// no file of the site.
|
|
1216
|
+
if (named.startsWith('/') && !isInside(found, publicDir))
|
|
1217
|
+
return {kind: 'missing', ref: clean};
|
|
1218
|
+
if (!fs.existsSync(found)) return {kind: 'missing', ref: clean};
|
|
755
1219
|
/** @type {fs.Stats | undefined} */
|
|
756
1220
|
let st;
|
|
757
1221
|
try {
|
|
@@ -768,28 +1232,50 @@ export function assetRef(ref, at) {
|
|
|
768
1232
|
return {kind: 'file', ref: clean, file: found};
|
|
769
1233
|
}
|
|
770
1234
|
|
|
1235
|
+
/**
|
|
1236
|
+
* The public/ folder a `/` path is read from, as a path from the page's
|
|
1237
|
+
* folder (`public/`, `../../public/`), whichever file names it: the page or
|
|
1238
|
+
* a stylesheet in another folder.
|
|
1239
|
+
* @param {{dir: string, root: string, pageDir?: string}} at
|
|
1240
|
+
*/
|
|
1241
|
+
function publicFolderOf(at) {
|
|
1242
|
+
const rel = path.relative(at.pageDir ?? at.dir, path.join(at.root, 'public')).split(path.sep).join('/');
|
|
1243
|
+
return `${rel}/`;
|
|
1244
|
+
}
|
|
1245
|
+
|
|
771
1246
|
/**
|
|
772
1247
|
* Inline local images (src, srcset, poster and CSS url()) as data: URIs. A
|
|
773
1248
|
* link (`href`) loads nothing, so it is left alone.
|
|
774
1249
|
* @param {string} text markup or CSS
|
|
775
1250
|
* @param {'html' | 'css'} kind
|
|
776
|
-
* @param {{dir: string, root: string, warnings: RenderWarning[], counted: Set<string>, localAssets: Set<string>, leaveLargeStyleAssets?: boolean}} ctx
|
|
1251
|
+
* @param {{dir: string, pageDir?: string, root: string, warnings: RenderWarning[], counted: Set<string>, localAssets: Set<string>, leaveLargeStyleAssets?: boolean, rewrites?: Map<string, string>, carried?: Map<string, number>, srcsets?: Set<string>, remote?: Map<string, import('./remote-images.mjs').RemoteImage>}} ctx
|
|
777
1252
|
* `leaveLargeStyleAssets`: a stylesheet's file too large to inline is left
|
|
778
|
-
* as it is and named, as a missing one is, rather than refused
|
|
1253
|
+
* as it is and named, as a missing one is, rather than refused;
|
|
1254
|
+
* `rewrites`: each attribute value the markup's rewrite replaced, as the
|
|
1255
|
+
* page wrote it, with what it became; `carried`: gets each one the markup
|
|
1256
|
+
* numbers for the page's script (none in a markup-only render); `remote`: the remote images fetched
|
|
1257
|
+
* for this render, by the address the page wrote
|
|
779
1258
|
*/
|
|
780
1259
|
function inlineAssets(text, kind, ctx) {
|
|
781
|
-
/** @param {string} ref */
|
|
782
|
-
const resolveRef = ref => {
|
|
1260
|
+
/** @param {string} ref @param {AssetPlace} [place] */
|
|
1261
|
+
const resolveRef = (ref, place) => {
|
|
783
1262
|
const named = assetRef(ref, ctx);
|
|
784
1263
|
if (!named) return null;
|
|
785
1264
|
const clean = named.ref;
|
|
786
1265
|
if (named.kind === 'remote') {
|
|
787
|
-
|
|
1266
|
+
// The fetched images go only where an element shows an image, or in a
|
|
1267
|
+
// CSS `url()`: a frame's or a video's `src` keeps its address.
|
|
1268
|
+
const shows = !place || showsImage(place.tag, place.attr);
|
|
1269
|
+
const fetched = shows ? ctx.remote?.get(named.url) : undefined;
|
|
1270
|
+
if (fetched && 'uri' in fetched) return fetched.uri;
|
|
1271
|
+
// Keyed by the whole address, as the later-drawn pass keys it, so one
|
|
1272
|
+
// image gets one warning.
|
|
1273
|
+
const key = `remote:${named.url}`;
|
|
788
1274
|
if (!ctx.counted.has(key)) {
|
|
789
1275
|
ctx.counted.add(key);
|
|
790
1276
|
ctx.warnings.push({
|
|
791
1277
|
code: 'remote-asset',
|
|
792
|
-
message: `${
|
|
1278
|
+
message: `${named.url} is loaded from the network, which a sandboxed page cannot reach; save it beside the page and import it instead.${fetched ? ` The render could not fetch it: ${fetched.reason}.` : ''}`,
|
|
793
1279
|
});
|
|
794
1280
|
}
|
|
795
1281
|
return null;
|
|
@@ -802,7 +1288,9 @@ function inlineAssets(text, kind, ctx) {
|
|
|
802
1288
|
code: 'missing-asset',
|
|
803
1289
|
message:
|
|
804
1290
|
named.kind === 'missing'
|
|
805
|
-
?
|
|
1291
|
+
? clean.startsWith('/')
|
|
1292
|
+
? `${clean} was not found in ${publicFolderOf(ctx)}, where a path from the site's root is read, so it is left as is and will not show.`
|
|
1293
|
+
: `${clean} was not found next to the page, so it is left as is and will not show.`
|
|
806
1294
|
: named.kind === 'unreadable'
|
|
807
1295
|
? `${clean} cannot be read (no permission), so it is left as is and will not show.`
|
|
808
1296
|
: `${clean} is not a regular file (a pipe, a device or a folder), so it is not read and will not show.`,
|
|
@@ -830,40 +1318,426 @@ function inlineAssets(text, kind, ctx) {
|
|
|
830
1318
|
return null;
|
|
831
1319
|
}
|
|
832
1320
|
ctx.counted.add(`file:${found}`);
|
|
833
|
-
|
|
834
|
-
if (!clean.startsWith('/')) ctx.localAssets.add(found);
|
|
1321
|
+
ctx.localAssets.add(found);
|
|
835
1322
|
return assetDataUri(found);
|
|
836
1323
|
};
|
|
837
|
-
|
|
838
|
-
|
|
1324
|
+
return rewriteRefs(text, kind, resolveRef, ctx.rewrites, ctx.carried, ctx.srcsets);
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
/**
|
|
1328
|
+
* Where markup names a file: an element's name and the attribute's, in lower
|
|
1329
|
+
* case. A CSS `url()` has none.
|
|
1330
|
+
* @typedef {{tag: string, attr: string}} AssetPlace
|
|
1331
|
+
*/
|
|
1332
|
+
|
|
1333
|
+
/**
|
|
1334
|
+
* Where the first paint holds an https image's data, for the image sinks to
|
|
1335
|
+
* read: the marked value that is the address, or else a marked `srcset` that
|
|
1336
|
+
* lists it, with the candidate's place there.
|
|
1337
|
+
* @param {string} url
|
|
1338
|
+
* @param {Map<string, number> | undefined} carried
|
|
1339
|
+
* @param {Map<string, [number, number]>} listed each address a marked
|
|
1340
|
+
* `srcset` lists, with its mark and place ({@link listedCandidates})
|
|
1341
|
+
* @returns {[string, number] | [string, number, number] | null}
|
|
1342
|
+
*/
|
|
1343
|
+
function firstPaintRead(url, carried, listed) {
|
|
1344
|
+
if (!carried) return null;
|
|
1345
|
+
const mark = carried.get(url);
|
|
1346
|
+
if (mark !== undefined) return [url, mark];
|
|
1347
|
+
const place = listed.get(url);
|
|
1348
|
+
return place ? [url, ...place] : null;
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
/**
|
|
1352
|
+
* Each address a marked `srcset` lists, with that srcset's mark and the
|
|
1353
|
+
* candidate's place in it: the first such place, read once per render.
|
|
1354
|
+
* @param {Map<string, number> | undefined} carried
|
|
1355
|
+
* @param {Set<string>} srcsets the carried values a `srcset` marks
|
|
1356
|
+
* @param {Map<string, string>} rewrites
|
|
1357
|
+
* @returns {Map<string, [number, number]>}
|
|
1358
|
+
*/
|
|
1359
|
+
function listedCandidates(carried, srcsets, rewrites) {
|
|
1360
|
+
/** @type {Map<string, [number, number]>} */
|
|
1361
|
+
const listed = new Map();
|
|
1362
|
+
if (!carried) return listed;
|
|
1363
|
+
for (const [, i, written] of carriedSrcsets(carried, srcsets, rewrites)) {
|
|
1364
|
+
written.forEach(({url}, k) => {
|
|
1365
|
+
if (!listed.has(url)) listed.set(url, [i, k]);
|
|
1366
|
+
});
|
|
1367
|
+
}
|
|
1368
|
+
return listed;
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
/**
|
|
1372
|
+
* Each marked `srcset` value whose data lists the same number of candidates
|
|
1373
|
+
* as the page wrote, with its mark: only such a value can give one
|
|
1374
|
+
* candidate's data by its place. A `src` or `poster` that holds a comma and
|
|
1375
|
+
* a space is one address, never a list.
|
|
1376
|
+
* @param {Map<string, number>} carried
|
|
1377
|
+
* @param {Set<string>} srcsets the carried values a `srcset` marks
|
|
1378
|
+
* @param {Map<string, string>} rewrites
|
|
1379
|
+
* @returns {Array<[string, number, import('./srcset.mjs').SrcsetCandidate[]]>}
|
|
1380
|
+
*/
|
|
1381
|
+
function carriedSrcsets(carried, srcsets, rewrites) {
|
|
1382
|
+
/** @type {Array<[string, number, import('./srcset.mjs').SrcsetCandidate[]]>} */
|
|
1383
|
+
const lists = [];
|
|
1384
|
+
for (const [was, i] of carried) {
|
|
1385
|
+
const now = rewrites.get(was);
|
|
1386
|
+
if (!srcsets.has(was) || now === undefined) continue;
|
|
1387
|
+
const written = parseSrcset(was);
|
|
1388
|
+
if (parseSrcset(now).length === written.length) lists.push([was, i, written]);
|
|
1389
|
+
}
|
|
1390
|
+
return lists;
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
/** Elements whose content a browser running scripts builds no image of. */
|
|
1394
|
+
const UNBUILT = new Set(['noscript', 'template', 'select']);
|
|
1395
|
+
|
|
1396
|
+
/**
|
|
1397
|
+
* Where `text` holds markup a browser running scripts never makes elements
|
|
1398
|
+
* of, as [start, end] pairs: a comment (a bogus one too), a CDATA section,
|
|
1399
|
+
* the text of a raw-text element (`<textarea>`, `<iframe>`, `<xmp>` and the
|
|
1400
|
+
* others the scanner names, everything after `<plaintext>`), and each
|
|
1401
|
+
* outermost `<noscript>`, `<template>` or `<select>` (whose content Firefox's
|
|
1402
|
+
* parser drops), which runs to its own close tag past any nested in it. The
|
|
1403
|
+
* pieces are the HTML scanner's own.
|
|
1404
|
+
* @param {string} text
|
|
1405
|
+
* @returns {[number, number][]}
|
|
1406
|
+
*/
|
|
1407
|
+
function unread(text) {
|
|
1408
|
+
/** @type {[number, number][]} */
|
|
1409
|
+
const ranges = [];
|
|
1410
|
+
/** @type {string[]} */
|
|
1411
|
+
const open = [];
|
|
1412
|
+
let start = 0;
|
|
1413
|
+
for (const piece of scanHtml(text)) {
|
|
1414
|
+
if (open.length === 0 && (piece.kind === 'comment' || piece.kind === 'cdata' || piece.kind === 'raw')) {
|
|
1415
|
+
// A `<![CDATA[` the scanner reads as a bogus comment (outside a foreign
|
|
1416
|
+
// root it tracks) can still be CDATA in a browser: range it to `]]>`.
|
|
1417
|
+
const cdata = piece.kind === 'comment' && text.startsWith('<![CDATA[', piece.start);
|
|
1418
|
+
const close = cdata ? text.indexOf(']]>', piece.start + 9) : -1;
|
|
1419
|
+
ranges.push([piece.start, cdata ? (close < 0 ? text.length : close + 3) : piece.end]);
|
|
1420
|
+
continue;
|
|
1421
|
+
}
|
|
1422
|
+
if ((piece.kind !== 'start' && piece.kind !== 'end') || !UNBUILT.has(piece.tag)) continue;
|
|
1423
|
+
if (piece.kind === 'start') {
|
|
1424
|
+
if (piece.selfClosing) continue;
|
|
1425
|
+
if (open.length === 0) start = piece.start;
|
|
1426
|
+
open.push(piece.tag);
|
|
1427
|
+
continue;
|
|
1428
|
+
}
|
|
1429
|
+
const at = open.lastIndexOf(piece.tag);
|
|
1430
|
+
if (at === -1) continue;
|
|
1431
|
+
open.length = at;
|
|
1432
|
+
if (open.length === 0) ranges.push([start, piece.end]);
|
|
1433
|
+
}
|
|
1434
|
+
if (open.length > 0) ranges.push([start, text.length]);
|
|
1435
|
+
const off = offScript(text);
|
|
1436
|
+
if (off >= 0) ranges.push([off, text.length]);
|
|
1437
|
+
return ranges;
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1440
|
+
/** The tags a serializer writes inside a `<select>`. */
|
|
1441
|
+
const SELECT_CONTENT = new Set(['option', 'optgroup', 'hr']);
|
|
1442
|
+
|
|
1443
|
+
/**
|
|
1444
|
+
* Where `text` first holds a shape a serializer such as React's never writes,
|
|
1445
|
+
* or -1: an end tag that does not close the element open last, CDATA, a
|
|
1446
|
+
* bogus comment, a comment holding `--!>` (which also ends one), a
|
|
1447
|
+
* self-closing HTML tag that is not void, `<plaintext>`, `<frameset>`, a
|
|
1448
|
+
* start tag inside a `<select>` other than option, optgroup or hr, or a
|
|
1449
|
+
* `<noscript>` that a browser running scripts ends elsewhere: it reads the
|
|
1450
|
+
* content as text up to the first `</noscript`, where the scanner reads
|
|
1451
|
+
* markup. Up to that point the scanner and a browser agree on the
|
|
1452
|
+
* elements; past it they may not, so nothing after it marks a carried
|
|
1453
|
+
* value, and each image there keeps its own copy in the script. A gap in
|
|
1454
|
+
* the scanner then costs bytes, never a missing picture.
|
|
1455
|
+
* @param {string} text
|
|
1456
|
+
* @returns {number}
|
|
1457
|
+
*/
|
|
1458
|
+
function offScript(text) {
|
|
1459
|
+
/** @type {string[]} */
|
|
1460
|
+
const open = [];
|
|
1461
|
+
/** Each open `<noscript>`: where it starts, and where a browser ends it. @type {{start: number, end: number}[]} */
|
|
1462
|
+
const noscripts = [];
|
|
1463
|
+
const NOSCRIPT_END = /<\/noscript[\t\n\f\r />]/gi;
|
|
1464
|
+
for (const piece of scanHtml(text)) {
|
|
1465
|
+
const outer = noscripts[0];
|
|
1466
|
+
if (outer && piece.start > outer.end) return outer.start;
|
|
1467
|
+
const written = text.slice(piece.start, piece.end);
|
|
1468
|
+
if (piece.kind === 'cdata' || (piece.kind === 'comment' && (!written.startsWith('<!--') || written.includes('--!>')))) return piece.start;
|
|
1469
|
+
if (piece.kind === 'start') {
|
|
1470
|
+
if (piece.tag === 'plaintext' || piece.tag === 'frameset') return piece.start;
|
|
1471
|
+
if (open.includes('select') && !SELECT_CONTENT.has(piece.tag)) return piece.start;
|
|
1472
|
+
if (VOID.has(piece.tag)) continue;
|
|
1473
|
+
if (written.endsWith('/>') && !piece.selfClosing) return piece.start;
|
|
1474
|
+
if (!piece.selfClosing) open.push(piece.tag);
|
|
1475
|
+
if (piece.tag === 'noscript' && !piece.selfClosing) {
|
|
1476
|
+
NOSCRIPT_END.lastIndex = piece.end;
|
|
1477
|
+
const close = NOSCRIPT_END.exec(text);
|
|
1478
|
+
noscripts.push({start: piece.start, end: close ? close.index : text.length});
|
|
1479
|
+
}
|
|
1480
|
+
} else if (piece.kind === 'end') {
|
|
1481
|
+
if (open[open.length - 1] !== piece.tag) return piece.start;
|
|
1482
|
+
open.pop();
|
|
1483
|
+
if (piece.tag === 'noscript') {
|
|
1484
|
+
const own = /** @type {{start: number, end: number}} */ (noscripts.pop());
|
|
1485
|
+
// A browser running scripts ends the outermost one at its first `</noscript`.
|
|
1486
|
+
if (noscripts.length === 0 && piece.start !== own.end) return own.start;
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
return -1;
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
|
|
1494
|
+
/**
|
|
1495
|
+
* Each reference a page's markup or stylesheet loads, read once for every
|
|
1496
|
+
* caller: the render inlines them, and the checks on a written file name
|
|
1497
|
+
* every one it left. In markup: src, poster and srcset attributes, and url() in
|
|
1498
|
+
* style attributes, each read within its own element; in a stylesheet: url().
|
|
1499
|
+
* `resolve` gets each reference as written, with the element and attribute
|
|
1500
|
+
* that hold it in markup, and returns what replaces it, or null to keep it.
|
|
1501
|
+
* @param {string} text markup or CSS
|
|
1502
|
+
* @param {'html' | 'css'} kind
|
|
1503
|
+
* @param {(ref: string, place?: AssetPlace) => string | null} resolve
|
|
1504
|
+
* @param {Map<string, string>} [rewrites] gets each attribute value replaced,
|
|
1505
|
+
* as the page wrote it, with what it became
|
|
1506
|
+
* @param {Map<string, number>} [marked] number each replaced value in the
|
|
1507
|
+
* markup ({@link CARRY_ATTR}), so the page's script reads it there, and
|
|
1508
|
+
* add it to this map with its number
|
|
1509
|
+
* @param {Set<string>} [srcsets] gets each marked value a `srcset` holds
|
|
1510
|
+
* @returns {string} the text with the replacements made
|
|
1511
|
+
*/
|
|
1512
|
+
export function rewriteRefs(text, kind, resolve, rewrites, marked, srcsets) {
|
|
1513
|
+
/**
|
|
1514
|
+
* What each replaced value became, for the marks the first paint gets.
|
|
1515
|
+
* @type {Map<string, string[]>}
|
|
1516
|
+
*/
|
|
1517
|
+
const became = new Map();
|
|
1518
|
+
/**
|
|
1519
|
+
* Record a replaced value.
|
|
1520
|
+
* @param {string} was
|
|
1521
|
+
* @param {string} now
|
|
1522
|
+
*/
|
|
1523
|
+
const carry = (was, now) => {
|
|
1524
|
+
if (!rewrites) return;
|
|
1525
|
+
// The last rewrite of a value is the one the script reads, as without
|
|
1526
|
+
// marks; an element that shows an earlier one is not marked.
|
|
1527
|
+
rewrites.set(was, now);
|
|
1528
|
+
became.set(now, [...(became.get(now) ?? []), was]);
|
|
1529
|
+
};
|
|
1530
|
+
/**
|
|
1531
|
+
* @param {string} value
|
|
1532
|
+
* @param {boolean} [record] keep each rewrite, for a style the script sets
|
|
1533
|
+
*/
|
|
1534
|
+
const urls = (value, record = false) =>
|
|
839
1535
|
value.replace(new RegExp(CSS_URL.source, 'g'), (whole, ...rest) => {
|
|
840
|
-
const
|
|
841
|
-
|
|
842
|
-
);
|
|
1536
|
+
const ref = cssUrlRef(/** @type {any} */ ({groups: rest.at(-1)}));
|
|
1537
|
+
const uri = resolve(ref);
|
|
1538
|
+
if (uri && record && ref) rewrites?.set(ref, uri);
|
|
843
1539
|
return uri ? `url("${uri}")` : whole;
|
|
844
1540
|
});
|
|
845
1541
|
if (kind === 'css') return urls(text);
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
1542
|
+
/**
|
|
1543
|
+
* @param {string} attrs one element's attributes
|
|
1544
|
+
* @param {string} tag the element's name, in lower case
|
|
1545
|
+
*/
|
|
1546
|
+
const mapAttributes = (attrs, tag) =>
|
|
1547
|
+
attrs
|
|
1548
|
+
// React writes `srcSet` as it is spelled in JSX; HTML reads attribute
|
|
1549
|
+
// names in any case.
|
|
1550
|
+
.replace(/\s(src|poster)="([^"]*)"/gi, (whole, attr, ref) => {
|
|
1551
|
+
const uri = resolve(ref, {tag, attr: attr.toLowerCase()});
|
|
1552
|
+
if (uri) carry(decodeAttr(ref), uri);
|
|
1553
|
+
return uri ? ` ${attr}="${uri}"` : whole;
|
|
1554
|
+
})
|
|
1555
|
+
.replace(/\s(srcset)="([^"]*)"/gi, (whole, attr, set) => {
|
|
1556
|
+
const written = decodeAttr(set);
|
|
1557
|
+
let carried = false;
|
|
1558
|
+
const candidates = parseSrcset(written).map(({url, descriptor}) => {
|
|
1559
|
+
const uri = resolve(url, {tag, attr: 'srcset'});
|
|
1560
|
+
if (uri) carried = true;
|
|
1561
|
+
return {url: uri ?? url, descriptor};
|
|
858
1562
|
});
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
1563
|
+
if (!carried) return whole;
|
|
1564
|
+
const rewritten = formatSrcset(candidates);
|
|
1565
|
+
carry(written, rewritten);
|
|
1566
|
+
return ` ${attr}="${rewritten.replace(/"/g, '"')}"`;
|
|
1567
|
+
})
|
|
1568
|
+
.replace(/\sstyle="([^"]*)"/g, (whole, style) => {
|
|
1569
|
+
// The attribute holds escaped text: rewrite the CSS it means, then
|
|
1570
|
+
// escape it again, so a data: URI's quotes cannot end the attribute.
|
|
1571
|
+
const css = urls(decodeAttr(style), true);
|
|
1572
|
+
return ` style="${css.replace(/&/g, '&').replace(/"/g, '"')}"`;
|
|
1573
|
+
});
|
|
1574
|
+
// Each element by itself, so a reference knows the element it is in. A
|
|
1575
|
+
// quoted value may hold a `>`, which does not end the tag.
|
|
1576
|
+
const written = text.replace(/<([a-zA-Z][\w-]*)\b((?:[^>"']|"[^"]*"|'[^']*')*)>/g, (tagText, name, attrs) => {
|
|
1577
|
+
const mapped = mapAttributes(attrs, name.toLowerCase());
|
|
1578
|
+
return mapped === attrs ? tagText : `<${name}${mapped}>`;
|
|
1579
|
+
});
|
|
1580
|
+
return marked && rewrites && became.size > 0 ? withCarryMarks(written, became, rewrites, marked, srcsets ?? new Set()) : written;
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
/** The elements whose `src`, `srcset` or `poster` is an image the page shows. */
|
|
1584
|
+
const IMAGE_TAGS = new Set(['img', 'source', 'input', 'video']);
|
|
1585
|
+
|
|
1586
|
+
/**
|
|
1587
|
+
* The markup with each element a browser builds that shows a replaced value
|
|
1588
|
+
* marked ({@link CARRY_ATTR}) with that value's number, once per element,
|
|
1589
|
+
* after its last attribute. Only the first attribute of each name on a real
|
|
1590
|
+
* `img`, `source`, `input` or `video` start tag counts, outside the ranges
|
|
1591
|
+
* {@link unread} names; the pieces are the HTML scanner's own.
|
|
1592
|
+
* @param {string} text
|
|
1593
|
+
* @param {Map<string, string[]>} became what each value became, and the
|
|
1594
|
+
* values written that became it
|
|
1595
|
+
* @param {Map<string, string>} rewrites
|
|
1596
|
+
* @param {Map<string, number>} marked gets each marked value, with its number
|
|
1597
|
+
* @param {Set<string>} srcsets gets each marked value a `srcset` holds
|
|
1598
|
+
* @returns {string}
|
|
1599
|
+
*/
|
|
1600
|
+
function withCarryMarks(text, became, rewrites, marked, srcsets) {
|
|
1601
|
+
const ranges = unread(text);
|
|
1602
|
+
/** @type {Array<[number, string]>} */
|
|
1603
|
+
const inserts = [];
|
|
1604
|
+
for (const piece of scanHtml(text)) {
|
|
1605
|
+
if (piece.kind !== 'start' || !IMAGE_TAGS.has(piece.tag) || piece.attrs.length === 0) continue;
|
|
1606
|
+
if (ranges.some(([from, to]) => piece.start > from && piece.start < to)) continue;
|
|
1607
|
+
/** @type {string[]} */
|
|
1608
|
+
const marks = [];
|
|
1609
|
+
const seen = new Set();
|
|
1610
|
+
for (const [name, value] of piece.attrs) {
|
|
1611
|
+
if (seen.has(name)) continue;
|
|
1612
|
+
seen.add(name);
|
|
1613
|
+
if (name !== 'src' && name !== 'srcset' && name !== 'poster') continue;
|
|
1614
|
+
const now = decodeAttr(value);
|
|
1615
|
+
for (const was of became.get(now) ?? []) {
|
|
1616
|
+
if (rewrites.get(was) !== now) continue;
|
|
1617
|
+
// The number stays the value's own, whatever later leaves the rewrites.
|
|
1618
|
+
if (!marked.has(was)) marked.set(was, [...rewrites.keys()].indexOf(was));
|
|
1619
|
+
if (name === 'srcset') srcsets.add(was);
|
|
1620
|
+
marks.push(`${name}:${marked.get(was)}`);
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
if (marks.length > 0) inserts.push([/** @type {[string, string, number, number]} */ (piece.attrs.at(-1))[3], ` ${CARRY_ATTR}="${[...new Set(marks)].join(' ')}"`]);
|
|
1624
|
+
}
|
|
1625
|
+
let out = '';
|
|
1626
|
+
let at = 0;
|
|
1627
|
+
for (const [where, mark] of inserts) {
|
|
1628
|
+
out += text.slice(at, where) + mark;
|
|
1629
|
+
at = where;
|
|
1630
|
+
}
|
|
1631
|
+
return out + text.slice(at);
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
/**
|
|
1635
|
+
* The remote addresses markup or CSS names where an image goes, as the page
|
|
1636
|
+
* wrote them: where an element shows an image (showsImage), and `url()` in a
|
|
1637
|
+
* `style` attribute or a stylesheet, except an address that names a font,
|
|
1638
|
+
* media or a document.
|
|
1639
|
+
* @param {string} text
|
|
1640
|
+
* @param {'html' | 'css'} kind
|
|
1641
|
+
* @param {{dir: string, root: string}} at
|
|
1642
|
+
* @returns {Set<string>}
|
|
1643
|
+
*/
|
|
1644
|
+
function remoteRefsIn(text, kind, at) {
|
|
1645
|
+
/** @type {Set<string>} */
|
|
1646
|
+
const found = new Set();
|
|
1647
|
+
/** @param {string} ref @param {AssetPlace} [place] */
|
|
1648
|
+
const take = (ref, place) => {
|
|
1649
|
+
if (place && !showsImage(place.tag, place.attr)) return null;
|
|
1650
|
+
const named = assetRef(ref, at);
|
|
1651
|
+
if (named?.kind === 'remote' && !NOT_AN_IMAGE.test(named.ref)) found.add(named.url);
|
|
1652
|
+
return null;
|
|
1653
|
+
};
|
|
1654
|
+
rewriteRefs(text, kind, take);
|
|
1655
|
+
return found;
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
/**
|
|
1659
|
+
* The function Core's naming module builds a part's class with, from the Core
|
|
1660
|
+
* the page uses, so the namespace comes from Core and not from the CLI. Null
|
|
1661
|
+
* when the page has no Core, or its Core has no naming module that loads.
|
|
1662
|
+
* @param {string} entry
|
|
1663
|
+
* @param {ServedSet | null} served
|
|
1664
|
+
* @returns {Promise<((part: string) => string) | null>}
|
|
1665
|
+
*/
|
|
1666
|
+
async function coreClassNamer(entry, served) {
|
|
1667
|
+
const file = resolveServed('@astryxdesign/core/naming', entry, served);
|
|
1668
|
+
if (!file) return null;
|
|
1669
|
+
try {
|
|
1670
|
+
const {stableClassName} = await importUrl(pathToFileURL(file).href);
|
|
1671
|
+
return typeof stableClassName === 'function' ? stableClassName : null;
|
|
1672
|
+
} catch {
|
|
1673
|
+
// A Core whose naming module does not load keeps the cut as before.
|
|
1674
|
+
return null;
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
/**
|
|
1679
|
+
* What a page's markup loads that the render does not carry, each once
|
|
1680
|
+
* (a reference that loads nothing, NOT_A_LOAD, aside): the href of a link
|
|
1681
|
+
* with a rel the browser fetches (FETCHING_RELS), the src or data of
|
|
1682
|
+
* iframe, object and embed elements, the href or xlink:href of SVG image,
|
|
1683
|
+
* use and feImage elements,
|
|
1684
|
+
* the url(), CSS import rules and image-set() strings of style elements, and
|
|
1685
|
+
* the image-set() strings of style attributes. The render warns about each,
|
|
1686
|
+
* and the checks on a written file name every one of them.
|
|
1687
|
+
* @param {string} markup
|
|
1688
|
+
* @returns {Array<{tag: string, ref: string}>}
|
|
1689
|
+
*/
|
|
1690
|
+
export function embeddedLoads(markup) {
|
|
1691
|
+
/** @type {Array<{tag: string, ref: string}>} */
|
|
1692
|
+
const loads = [];
|
|
1693
|
+
/** @type {Set<string>} */
|
|
1694
|
+
const seen = new Set();
|
|
1695
|
+
/** @param {string} tag @param {string} ref */
|
|
1696
|
+
const add = (tag, ref) => {
|
|
1697
|
+
const key = `${tag} ${ref}`;
|
|
1698
|
+
if (!ref || NOT_A_LOAD.test(ref.trim()) || seen.has(key)) return;
|
|
1699
|
+
seen.add(key);
|
|
1700
|
+
loads.push({tag, ref});
|
|
1701
|
+
};
|
|
1702
|
+
/** The strings an image-set() names, which url() does not cover. @param {string} tag @param {string} css */
|
|
1703
|
+
const imageSets = (tag, css) => {
|
|
1704
|
+
for (const [, inner] of css.matchAll(/(?:-webkit-)?image-set\(([^()]*(?:\([^()]*\)[^()]*)*)\)/gi)) {
|
|
1705
|
+
for (const m of inner.matchAll(/(?<![\w(])(["'])([^"']*)\1/g)) add(tag, m[2]);
|
|
1706
|
+
}
|
|
1707
|
+
};
|
|
1708
|
+
/** @param {string} css */
|
|
1709
|
+
const styleSheet = css => {
|
|
1710
|
+
for (const m of css.matchAll(/@import\s+([^;]+);?/gi)) add('style', importParams(m[1])?.url ?? '');
|
|
1711
|
+
for (const m of css.matchAll(new RegExp(CSS_URL.source, 'g'))) add('style', cssUrlRef(m));
|
|
1712
|
+
imageSets('style', css);
|
|
1713
|
+
};
|
|
1714
|
+
let inStyle = false;
|
|
1715
|
+
// Tags and attributes are read as a browser reads them (scanHtml): an
|
|
1716
|
+
// attribute's place in the tag does not matter.
|
|
1717
|
+
for (const token of scanHtml(markup)) {
|
|
1718
|
+
if (token.kind === 'raw') {
|
|
1719
|
+
if (inStyle) styleSheet(markup.slice(token.start, token.end));
|
|
1720
|
+
continue;
|
|
1721
|
+
}
|
|
1722
|
+
if (token.kind !== 'start') continue;
|
|
1723
|
+
inStyle = token.tag === 'style';
|
|
1724
|
+
const attrs = new Map(token.attrs.map(([name, value]) => [name, decodeAttr(value)]));
|
|
1725
|
+
const style = attrs.get('style');
|
|
1726
|
+
if (style) imageSets(token.tag, style);
|
|
1727
|
+
if (token.tag === 'link') {
|
|
1728
|
+
// A link loads only for a rel the browser fetches; a canonical or
|
|
1729
|
+
// author link names a page and loads nothing.
|
|
1730
|
+
const rels = (attrs.get('rel') ?? '').toLowerCase().split(/\s+/);
|
|
1731
|
+
if (rels.some(r => FETCHING_RELS.has(r))) add('link', attrs.get('href') ?? '');
|
|
1732
|
+
} else if (token.tag === 'iframe' || token.tag === 'embed') {
|
|
1733
|
+
add(token.tag, attrs.get('src') ?? '');
|
|
1734
|
+
} else if (token.tag === 'object') {
|
|
1735
|
+
add(token.tag, attrs.get('data') ?? '');
|
|
1736
|
+
} else if (token.tag === 'image' || token.tag === 'use' || token.tag === 'feimage') {
|
|
1737
|
+
add(token.tag, attrs.get('href') ?? attrs.get('xlink:href') ?? '');
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
return loads;
|
|
867
1741
|
}
|
|
868
1742
|
|
|
869
1743
|
/**
|
|
@@ -895,10 +1769,208 @@ function installedVersion(name, dir, setDirs) {
|
|
|
895
1769
|
const SCHEME_CSS =
|
|
896
1770
|
':root{color-scheme:light dark}:root[data-theme="light"]{color-scheme:light}:root[data-theme="dark"]{color-scheme:dark}';
|
|
897
1771
|
|
|
1772
|
+
/** The tokens that set a page's own surface and text colors. */
|
|
1773
|
+
const PAGE_COLOR_TOKEN = /^--color-(background-(body|surface)|text-primary)$/;
|
|
1774
|
+
|
|
1775
|
+
/** A page color token that sets the page's background, not its text. */
|
|
1776
|
+
const BACKGROUND_TOKEN = /^--color-background-/;
|
|
1777
|
+
|
|
1778
|
+
/**
|
|
1779
|
+
* A condition that applies a rule in one scheme only: a
|
|
1780
|
+
* `prefers-color-scheme` query (`not` forms included), a `data-theme` or
|
|
1781
|
+
* scheme attribute, or a `.light`/`.dark` class, in a selector or an
|
|
1782
|
+
* at-rule around it.
|
|
1783
|
+
*/
|
|
1784
|
+
const MODE_CONDITION = /prefers-color-scheme|\[data-(?:theme|astryx-scheme)="(?:light|dark)"\]|\.(?:light|dark)(?![\w-])/;
|
|
1785
|
+
|
|
1786
|
+
/**
|
|
1787
|
+
* A selector or condition without its `:not(...)` groups.
|
|
1788
|
+
* @param {string} text
|
|
1789
|
+
*/
|
|
1790
|
+
const withoutNegations = text => text.replace(/:not\((?:[^()]|\([^()]*\))*\)/g, '');
|
|
1791
|
+
|
|
1792
|
+
/**
|
|
1793
|
+
* A stylesheet with every `data-*` attribute selector written one way,
|
|
1794
|
+
* `[data-x="v"]`, however it was quoted (`[data-x='v']`, `[data-x=v]`)
|
|
1795
|
+
* or flagged (`[data-x="V" i]`).
|
|
1796
|
+
* @param {string} text
|
|
1797
|
+
*/
|
|
1798
|
+
const withQuotedAttributes = text =>
|
|
1799
|
+
text.replace(/\[\s*(data-[\w-]+)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s\]'"]+))\s*(?:([iIsS])\s*)?\]/g, (_, attr, dq, sq, bare, flag) => {
|
|
1800
|
+
const value = dq ?? sq ?? bare;
|
|
1801
|
+
// A value matches case-sensitively unless the `i` flag says otherwise.
|
|
1802
|
+
return `[${attr}="${flag === 'i' || flag === 'I' ? value.toLowerCase() : value}"]`;
|
|
1803
|
+
});
|
|
1804
|
+
|
|
1805
|
+
/**
|
|
1806
|
+
* The one color mode the page's root theme draws in, or null when it draws
|
|
1807
|
+
* in both (or the page has no theme). The theme module's `colorModes`
|
|
1808
|
+
* export says it when the module has one. Else the page and text colors the
|
|
1809
|
+
* stylesheets the page imports set on the theme's root say it: a light page with
|
|
1810
|
+
* dark text draws in light only, a dark page with light text in dark only.
|
|
1811
|
+
* A theme that sets neither (its fonts, its accent), sets a `light-dark()`
|
|
1812
|
+
* color, one the color reader cannot fix (a `var()`) or a translucent
|
|
1813
|
+
* page color, or sets any page or text color under a light or dark condition,
|
|
1814
|
+
* draws in both, as the reader's scheme decides.
|
|
1815
|
+
* @param {string} markup
|
|
1816
|
+
* @param {'light' | 'dark' | 'both' | null} declared the theme module's
|
|
1817
|
+
* `colorModes`, as {@link declaredColorModes} reads it
|
|
1818
|
+
* @param {string[]} sheets the text of the stylesheets the page imports
|
|
1819
|
+
* @returns {'light' | 'dark' | null}
|
|
1820
|
+
*/
|
|
1821
|
+
export function oneColorModeOf(markup, declared, sheets) {
|
|
1822
|
+
if (declared === 'light' || declared === 'dark') return declared;
|
|
1823
|
+
if (declared === 'both') return null;
|
|
1824
|
+
const name = rootThemeElement(markup)?.get('data-astryx-theme');
|
|
1825
|
+
if (!name) return null;
|
|
1826
|
+
const root = `[data-astryx-theme="${name}"]`;
|
|
1827
|
+
/** @type {{background: boolean, value: string}[]} */
|
|
1828
|
+
const colors = [];
|
|
1829
|
+
let conditional = false;
|
|
1830
|
+
for (const sheet of sheets) {
|
|
1831
|
+
const text = withQuotedAttributes(sheet);
|
|
1832
|
+
if (!text.includes(root)) continue;
|
|
1833
|
+
/** @type {any} */
|
|
1834
|
+
let tree;
|
|
1835
|
+
try {
|
|
1836
|
+
tree = postcss.parse(text);
|
|
1837
|
+
} catch {
|
|
1838
|
+
return null;
|
|
1839
|
+
}
|
|
1840
|
+
tree.walkDecls(PAGE_COLOR_TOKEN, (/** @type {any} */ decl) => {
|
|
1841
|
+
/** The selectors and at-rule conditions around the declaration. */
|
|
1842
|
+
const contexts = [];
|
|
1843
|
+
for (let at = decl.parent; at && at.type !== 'root'; at = at.parent) {
|
|
1844
|
+
contexts.push(at.type === 'rule' ? at.selector : `@${at.name} ${at.params}`);
|
|
1845
|
+
}
|
|
1846
|
+
// A media surface fixes its own mode; it says nothing of the theme's. A
|
|
1847
|
+
// rule that only keeps out of media surfaces (`:not(… [data-astryx-media]
|
|
1848
|
+
// …)`) still counts.
|
|
1849
|
+
if (contexts.some(context => withoutNegations(context).includes('data-astryx-media'))) return;
|
|
1850
|
+
// A page color set for one scheme only, anywhere in the theme's sheet,
|
|
1851
|
+
// makes the theme follow the viewer.
|
|
1852
|
+
if (contexts.some(context => MODE_CONDITION.test(context))) {
|
|
1853
|
+
conditional = true;
|
|
1854
|
+
return;
|
|
1855
|
+
}
|
|
1856
|
+
const rule = decl.parent;
|
|
1857
|
+
if (rule?.type !== 'rule' || contexts.slice(1).some(context => !context.startsWith('@'))) return;
|
|
1858
|
+
const selector = rule.selector.trim();
|
|
1859
|
+
// Only the theme's own root sets the page's colors: its attribute, or
|
|
1860
|
+
// `:scope` in an @scope that starts there (its `to (...)` limit names
|
|
1861
|
+
// no root).
|
|
1862
|
+
const scope =
|
|
1863
|
+
rule.parent?.type === 'atrule' && rule.parent.name === 'scope'
|
|
1864
|
+
? rule.parent.params.split(/\)\s*to\s*\(/)[0].replace(/^\s*\(\s*|\s*\)\s*$/g, '')
|
|
1865
|
+
: null;
|
|
1866
|
+
if (selector === root || (selector === ':scope' && scope === root)) {
|
|
1867
|
+
colors.push({background: BACKGROUND_TOKEN.test(decl.prop), value: decl.value});
|
|
1868
|
+
}
|
|
1869
|
+
});
|
|
1870
|
+
}
|
|
1871
|
+
if (conditional || colors.length === 0) return null;
|
|
1872
|
+
/** @type {Set<'light' | 'dark'>} */
|
|
1873
|
+
const modes = new Set();
|
|
1874
|
+
for (const {background, value} of colors) {
|
|
1875
|
+
const rgb = parseColor(value);
|
|
1876
|
+
// A color the reader cannot fix (a var(), light-dark()), or a page color
|
|
1877
|
+
// that shows what is behind it, leaves the reader's scheme to decide.
|
|
1878
|
+
// Text is light or dark by its own color, whatever its alpha.
|
|
1879
|
+
if (!rgb || (background && alphaOf(value) < 1)) return null;
|
|
1880
|
+
const lightColor = relativeLuminance(rgb) > 0.18;
|
|
1881
|
+
// A light page, or dark text, is a light theme's.
|
|
1882
|
+
modes.add(background === lightColor ? 'light' : 'dark');
|
|
1883
|
+
}
|
|
1884
|
+
return modes.size === 1 ? [...modes][0] : null;
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1887
|
+
/**
|
|
1888
|
+
* A stylesheet the page imports: its file, and for a package's stylesheet
|
|
1889
|
+
* the package name and the file that imports it.
|
|
1890
|
+
* @typedef {{file: string, pkg?: string, from?: string}} ThemeSheet
|
|
1891
|
+
*/
|
|
1892
|
+
|
|
1893
|
+
/**
|
|
1894
|
+
* The `colorModes` the module of the page's root theme declares, read
|
|
1895
|
+
* without running it. The module sits beside the theme's stylesheet: a
|
|
1896
|
+
* package's entry (or its `./built` entry) when the page imports the
|
|
1897
|
+
* package's stylesheet, or a module with the stylesheet's name beside it.
|
|
1898
|
+
* Only a module that names the root theme counts.
|
|
1899
|
+
* @param {string} markup
|
|
1900
|
+
* @param {ThemeSheet[]} sheets the stylesheets the page imports
|
|
1901
|
+
* @param {(specifier: string, from: string) => string | null} resolve the
|
|
1902
|
+
* module file a bare specifier names from a file
|
|
1903
|
+
* @returns {'light' | 'dark' | 'both' | null}
|
|
1904
|
+
*/
|
|
1905
|
+
function rootThemeColorModes(markup, sheets, resolve) {
|
|
1906
|
+
const name = rootThemeElement(markup)?.get('data-astryx-theme');
|
|
1907
|
+
if (!name) return null;
|
|
1908
|
+
/** @type {Set<string>} */
|
|
1909
|
+
const candidates = new Set();
|
|
1910
|
+
for (const {file, pkg, from} of sheets) {
|
|
1911
|
+
const base = file.replace(/\.css$/i, '');
|
|
1912
|
+
for (const ext of ['.js', '.mjs', '.ts', '.tsx']) candidates.add(base + ext);
|
|
1913
|
+
// The package by the name the page imports it as, as `theme add` finds
|
|
1914
|
+
// it (a linked package's real path holds no node_modules); else the
|
|
1915
|
+
// installed package folder that holds the file.
|
|
1916
|
+
let pkgName = pkg ?? null;
|
|
1917
|
+
let at = from ?? file;
|
|
1918
|
+
if (!pkgName) {
|
|
1919
|
+
const pkgDir = installedPackageOf(file);
|
|
1920
|
+
if (!pkgDir) continue;
|
|
1921
|
+
try {
|
|
1922
|
+
pkgName = JSON.parse(fs.readFileSync(path.join(pkgDir, 'package.json'), 'utf8'))?.name ?? null;
|
|
1923
|
+
} catch {
|
|
1924
|
+
continue;
|
|
1925
|
+
}
|
|
1926
|
+
at = file;
|
|
1927
|
+
}
|
|
1928
|
+
if (typeof pkgName !== 'string' || pkgName === '@astryxdesign/core') continue;
|
|
1929
|
+
// The built entry first, which `theme add` reads and which carries the
|
|
1930
|
+
// export, then the package's own.
|
|
1931
|
+
for (const specifier of [`${pkgName}/built`, pkgName]) {
|
|
1932
|
+
const target = resolve(specifier, at);
|
|
1933
|
+
if (target) candidates.add(target);
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
const named = new RegExp(`name:\\s*["']${name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}["']`);
|
|
1937
|
+
for (const file of candidates) {
|
|
1938
|
+
if (!isFileAt(file)) continue;
|
|
1939
|
+
// The module must hold the root theme: its name, as a built theme
|
|
1940
|
+
// writes it, in the module or in the file its colorModes come from.
|
|
1941
|
+
const holds = [file, moduleExportSource(file, 'colorModes')].some(f => {
|
|
1942
|
+
if (!f) return false;
|
|
1943
|
+
try {
|
|
1944
|
+
return named.test(fs.readFileSync(f, 'utf8'));
|
|
1945
|
+
} catch {
|
|
1946
|
+
return false;
|
|
1947
|
+
}
|
|
1948
|
+
});
|
|
1949
|
+
if (!holds) continue;
|
|
1950
|
+
// A module that holds the theme but declares no modes (a package's
|
|
1951
|
+
// source entry, beside its built one that does) leaves the next to say.
|
|
1952
|
+
const declared = declaredColorModes(file);
|
|
1953
|
+
if (declared !== null) return declared;
|
|
1954
|
+
}
|
|
1955
|
+
return null;
|
|
1956
|
+
}
|
|
1957
|
+
|
|
1958
|
+
/**
|
|
1959
|
+
* The page's scheme rules. A page that draws in one mode keeps that scheme
|
|
1960
|
+
* whatever the viewer's, and paints the theme's own page color on the
|
|
1961
|
+
* document, so a viewer of the other scheme never shows its own canvas
|
|
1962
|
+
* behind the theme's text. It adds no specificity: a page's own unlayered
|
|
1963
|
+
* `html` rule still wins, but a rule inside `@layer` does not.
|
|
1964
|
+
* @param {'light' | 'dark' | null} mode
|
|
1965
|
+
*/
|
|
1966
|
+
function schemeCssFor(mode) {
|
|
1967
|
+
return mode ? `:where(:root){color-scheme:${mode};background-color:var(--color-background-body)}` : SCHEME_CSS;
|
|
1968
|
+
}
|
|
1969
|
+
|
|
898
1970
|
/**
|
|
899
1971
|
* Render a page module to one self-contained HTML file.
|
|
900
1972
|
* @param {string} entry absolute path of the page module
|
|
901
|
-
* @param {{title?: string, timeoutMs?: number, version?: string, served?: ServedSet | null, output?: string, cwd?: string, openLayers?: boolean, leaveLargeStyleAssets?: boolean}} [options]
|
|
1973
|
+
* @param {{title?: string, timeoutMs?: number, version?: string, served?: ServedSet | null, output?: string, cwd?: string, openLayers?: boolean, leaveLargeStyleAssets?: boolean, markupOnly?: boolean, esbuildFrom?: string, remoteImages?: Parameters<typeof remoteImages>[0], cutFontFaces?: boolean, keepClassNames?: boolean}} [options]
|
|
902
1974
|
* `served`: the Core of the package set the CLI runs from, for the packages
|
|
903
1975
|
* the page's folder has no copy of; `output`: the file the HTML goes to;
|
|
904
1976
|
* `cwd`: the current folder, whose files are the page's own outside a
|
|
@@ -909,20 +1981,49 @@ const SCHEME_CSS =
|
|
|
909
1981
|
* names such files itself). With `output`, the file describes itself: notes at its top and end name
|
|
910
1982
|
* what made it and the commands that give the page back and render it
|
|
911
1983
|
* again, and its embedded source records the CLI version, the packages
|
|
912
|
-
* the page rendered with, and the markup as rendered.
|
|
1984
|
+
* the page rendered with, and the markup as rendered. The file also
|
|
1985
|
+
* carries the page's script (client-bundle.mjs): it draws the page over
|
|
1986
|
+
* its markup in the browser, so the page's controls work. The markup sits
|
|
1987
|
+
* in one element the script draws into, and the stylesheet keeps the rules
|
|
1988
|
+
* any of the page's modules can use, not only the markup's. esbuild, a
|
|
1989
|
+
* dependency of the CLI, builds the script (`esbuildFrom`: the folder it
|
|
1990
|
+
* resolves from); a page whose script cannot be built fails the render.
|
|
1991
|
+
* `keepClassNames` keeps every class of the first paint as written,
|
|
1992
|
+
* for a caller that styles the markup with its own copy of the styles.
|
|
1993
|
+
* `markupOnly` renders the markup and its styles without the script, for a
|
|
1994
|
+
* caller that shows the markup itself (the theme editor); it writes no file
|
|
1995
|
+
* and reaches no network. The render fetches each https image the page
|
|
1996
|
+
* names, once, so the file carries it (remote-images.mjs; `remoteImages`:
|
|
1997
|
+
* the fetch and its time limits, for tests).
|
|
1998
|
+
* `cutFontFaces` drops each font face that no character in the page, its
|
|
1999
|
+
* stylesheet or its script reaches (css-cut.mjs), for a file whose text is
|
|
2000
|
+
* known (export); a page a person types into keeps every face.
|
|
913
2001
|
* @returns {Promise<RenderedPage>}
|
|
914
2002
|
*/
|
|
915
2003
|
export async function renderPage(entry, options = {}) {
|
|
916
2004
|
const dir = path.dirname(entry);
|
|
917
|
-
// The project's folder, else the page's: where its tsconfig.json
|
|
918
|
-
//
|
|
2005
|
+
// The project's folder, else the page's: where its tsconfig.json is read
|
|
2006
|
+
// and paths in messages start.
|
|
919
2007
|
const root = projectOf(dir) ?? dir;
|
|
920
2008
|
const scope = carryScopeOf(dir, options.cwd);
|
|
2009
|
+
// Where a `/` path's public/ folder is.
|
|
2010
|
+
const site = siteRootOf(dir, scope);
|
|
921
2011
|
const served = options.served ?? null;
|
|
922
2012
|
/** @type {RenderWarning[]} */
|
|
923
2013
|
const warnings = [];
|
|
2014
|
+
/** @type {string | undefined} */
|
|
2015
|
+
let esbuild;
|
|
2016
|
+
if (!options.markupOnly) {
|
|
2017
|
+
esbuild = findEsbuild(options.esbuildFrom) ?? undefined;
|
|
2018
|
+
if (!esbuild) {
|
|
2019
|
+
throw new RenderError(
|
|
2020
|
+
'ERR_RENDER_MISSING_DEPENDENCY',
|
|
2021
|
+
`The render builds the page's script, but ${ESBUILD_MISSING}; nothing was written.`,
|
|
2022
|
+
);
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
924
2025
|
const message = await runPage(
|
|
925
|
-
{entry, root, scope, served, openLayers: options.openLayers === true},
|
|
2026
|
+
{entry, root, scope, served, openLayers: options.openLayers === true, buildScript: esbuild !== undefined, esbuild},
|
|
926
2027
|
options.timeoutMs ?? RENDER_TIMEOUT_MS,
|
|
927
2028
|
warnings,
|
|
928
2029
|
);
|
|
@@ -934,7 +2035,7 @@ export async function renderPage(entry, options = {}) {
|
|
|
934
2035
|
);
|
|
935
2036
|
}
|
|
936
2037
|
/** @type {string} */
|
|
937
|
-
let markup = message.markup;
|
|
2038
|
+
let markup = withoutAutofocus(linksOpenNewTabs(message.markup));
|
|
938
2039
|
|
|
939
2040
|
// Stylesheets: Core's reset and components, plus each official package's
|
|
940
2041
|
// own stylesheet the page imports from.
|
|
@@ -944,6 +2045,8 @@ export async function renderPage(entry, options = {}) {
|
|
|
944
2045
|
const sheetText = [];
|
|
945
2046
|
/** Each stylesheet's own file, so its url()s resolve from its folder. @type {string[]} */
|
|
946
2047
|
const sheetFiles = [];
|
|
2048
|
+
/** Whether each stylesheet is Core's or an official package's (`@astryxdesign/*`). @type {boolean[]} */
|
|
2049
|
+
const sheetIsAstryx = [];
|
|
947
2050
|
/** @param {string} spec */
|
|
948
2051
|
const addSheet = spec => {
|
|
949
2052
|
try {
|
|
@@ -952,6 +2055,7 @@ export async function renderPage(entry, options = {}) {
|
|
|
952
2055
|
sheets.push(spec);
|
|
953
2056
|
sheetText.push(fs.readFileSync(file, 'utf8'));
|
|
954
2057
|
sheetFiles.push(file);
|
|
2058
|
+
sheetIsAstryx.push(true);
|
|
955
2059
|
return true;
|
|
956
2060
|
} catch {
|
|
957
2061
|
return false;
|
|
@@ -959,17 +2063,29 @@ export async function renderPage(entry, options = {}) {
|
|
|
959
2063
|
};
|
|
960
2064
|
const hasCore = addSheet('@astryxdesign/core/reset.css');
|
|
961
2065
|
if (hasCore) addSheet('@astryxdesign/core/astryx.css');
|
|
2066
|
+
/** The package stylesheets the page's modules import. @type {string[]} */
|
|
2067
|
+
const scriptSheets = [];
|
|
2068
|
+
let scriptNamesAstryx = false;
|
|
2069
|
+
/** The text of the stylesheets the page imports itself: its theme's, and its own. @type {string[]} */
|
|
2070
|
+
const themeSheets = [];
|
|
2071
|
+
/** Those package stylesheets: each file, and the package and importer it came by. @type {ThemeSheet[]} */
|
|
2072
|
+
const themeSheetFiles = [];
|
|
962
2073
|
// Package stylesheets the page imports itself, such as a theme's.
|
|
963
2074
|
for (const {spec, from} of /** @type {{spec: string, from: string}[]} */ (
|
|
964
2075
|
message.packageCss ?? []
|
|
965
2076
|
)) {
|
|
966
|
-
if (sheets.includes(spec)) continue;
|
|
967
2077
|
const file = resolveServed(spec, from, served);
|
|
2078
|
+
if (file) scriptSheets.push(file);
|
|
2079
|
+
else if (spec.startsWith('@astryxdesign/')) scriptNamesAstryx = true;
|
|
2080
|
+
if (sheets.includes(spec)) continue;
|
|
968
2081
|
try {
|
|
969
2082
|
if (!file) throw new Error('not found');
|
|
970
2083
|
sheets.push(spec);
|
|
971
2084
|
sheetText.push(fs.readFileSync(file, 'utf8'));
|
|
972
2085
|
sheetFiles.push(file);
|
|
2086
|
+
themeSheets.push(/** @type {string} */ (sheetText.at(-1)));
|
|
2087
|
+
themeSheetFiles.push({file, pkg: specPackageOf(spec), from});
|
|
2088
|
+
sheetIsAstryx.push(spec.startsWith('@astryxdesign/'));
|
|
973
2089
|
} catch {
|
|
974
2090
|
warnings.push({
|
|
975
2091
|
code: 'missing-asset',
|
|
@@ -992,18 +2108,71 @@ export async function renderPage(entry, options = {}) {
|
|
|
992
2108
|
});
|
|
993
2109
|
}
|
|
994
2110
|
|
|
2111
|
+
// A page that uses nothing from Astryx is not what the command makes: its
|
|
2112
|
+
// own app's build shares it. Its script's module graph (local components,
|
|
2113
|
+
// re-exports and lazy imports included) and the stylesheets it brings in
|
|
2114
|
+
// decide, before any stylesheet is expanded, any asset inlined, any image
|
|
2115
|
+
// fetched or anything written. A markup-only render builds no script and
|
|
2116
|
+
// is not checked.
|
|
2117
|
+
const ownSheets = /** @type {{file: string}[]} */ (message.importedCss ?? []).map(({file}) => file);
|
|
2118
|
+
if (
|
|
2119
|
+
message.astryx === false &&
|
|
2120
|
+
!scriptNamesAstryx &&
|
|
2121
|
+
!reachesAstryxSheet([...ownSheets, ...scriptSheets], served)
|
|
2122
|
+
) {
|
|
2123
|
+
throw new RenderError(
|
|
2124
|
+
'ERR_RENDER_NOT_ASTRYX',
|
|
2125
|
+
`${path.basename(entry)} uses no Astryx components or styles; \`astryx experimental export\` only writes pages built with Astryx. Don't add Astryx to this app to export it: share the page with the app's own build instead (for a Vite app, a single-file build); nothing was written.`,
|
|
2126
|
+
);
|
|
2127
|
+
}
|
|
2128
|
+
|
|
2129
|
+
// The https images the page names, fetched once so the file carries them.
|
|
2130
|
+
// A markup-only render reaches no network.
|
|
2131
|
+
const remote = options.markupOnly ? null : remoteImages(options.remoteImages);
|
|
995
2132
|
const ctx = {
|
|
996
2133
|
dir,
|
|
997
|
-
|
|
2134
|
+
// A stylesheet's own folder replaces `dir` for its url()s; a warning
|
|
2135
|
+
// still names folders from the page's.
|
|
2136
|
+
pageDir: dir,
|
|
2137
|
+
root: site,
|
|
998
2138
|
warnings,
|
|
999
2139
|
counted: new Set(),
|
|
1000
2140
|
localAssets: /** @type {Set<string>} */ (new Set()),
|
|
1001
2141
|
leaveLargeStyleAssets: options.leaveLargeStyleAssets === true,
|
|
2142
|
+
rewrites: /** @type {Map<string, string>} */ (new Map()),
|
|
2143
|
+
// The page's script reads the data the markup carries; a markup-only
|
|
2144
|
+
// render has no script.
|
|
2145
|
+
carried: options.markupOnly ? undefined : /** @type {Map<string, number>} */ (new Map()),
|
|
2146
|
+
srcsets: /** @type {Set<string>} */ (new Set()),
|
|
2147
|
+
remote: remote?.results,
|
|
2148
|
+
};
|
|
2149
|
+
/**
|
|
2150
|
+
* Inline what `text` names, after fetching the remote images it names that
|
|
2151
|
+
* no earlier text named.
|
|
2152
|
+
* @param {string} text
|
|
2153
|
+
* @param {'html' | 'css'} kind
|
|
2154
|
+
* @param {typeof ctx} at
|
|
2155
|
+
*/
|
|
2156
|
+
const inlineWithRemote = async (text, kind, at) => {
|
|
2157
|
+
if (remote) await remote.get(remoteRefsIn(text, kind, at));
|
|
2158
|
+
return inlineAssets(text, kind, at);
|
|
1002
2159
|
};
|
|
1003
2160
|
/** Stylesheets pulled in by another's `@import`. @type {Set<string>} */
|
|
1004
2161
|
const carriedCss = new Set();
|
|
2162
|
+
/** Each project stylesheet an `@import` names, with every sheet that imports it. @type {Map<string, Set<string>>} */
|
|
2163
|
+
const cssImporters = new Map();
|
|
2164
|
+
// The images the markup, the page's own CSS and its literals name are
|
|
2165
|
+
// asked for together, so a machine with no network waits for one answer
|
|
2166
|
+
// window, not one per text.
|
|
2167
|
+
if (remote) {
|
|
2168
|
+
await remote.get([
|
|
2169
|
+
...remoteRefsIn(markup, 'html', ctx),
|
|
2170
|
+
...(message.css ? remoteRefsIn(message.css, 'css', ctx) : []),
|
|
2171
|
+
...(typeof message.script === 'string' ? /** @type {string[]} */ (message.remoteLiterals ?? []) : []),
|
|
2172
|
+
]);
|
|
2173
|
+
}
|
|
1005
2174
|
try {
|
|
1006
|
-
markup =
|
|
2175
|
+
markup = await inlineWithRemote(markup, 'html', ctx);
|
|
1007
2176
|
// React adds `<link rel="preload">` hints for images it renders; in one
|
|
1008
2177
|
// static file they only fetch from the network, so they go.
|
|
1009
2178
|
markup = markup.replace(/<link rel="preload"[^>]*\/?>/g, '');
|
|
@@ -1016,13 +2185,10 @@ export async function renderPage(entry, options = {}) {
|
|
|
1016
2185
|
'The page renders a <script> element. A sandboxed viewer blocks it, and anywhere else it runs when the file is opened; remove it from the page.',
|
|
1017
2186
|
});
|
|
1018
2187
|
}
|
|
1019
|
-
for (const
|
|
1020
|
-
/<(link|iframe|object|embed)\b[^>]*?\s(?:href|src|data)="([^"]*)"/gi,
|
|
1021
|
-
)) {
|
|
1022
|
-
if (/^(data:|#)/i.test(m[2])) continue;
|
|
2188
|
+
for (const {tag, ref} of embeddedLoads(markup)) {
|
|
1023
2189
|
warnings.push({
|
|
1024
2190
|
code: 'remote-asset',
|
|
1025
|
-
message: `The page renders a <${
|
|
2191
|
+
message: `The page renders a <${tag}> that loads ${ref}, which a sandboxed page cannot reach and which loads from outside the file; remove it from the page.`,
|
|
1026
2192
|
});
|
|
1027
2193
|
}
|
|
1028
2194
|
} catch (e) {
|
|
@@ -1032,44 +2198,105 @@ export async function renderPage(entry, options = {}) {
|
|
|
1032
2198
|
throw e;
|
|
1033
2199
|
}
|
|
1034
2200
|
const used = classesIn(markup);
|
|
2201
|
+
/** The page's script; none in a markup-only render. @type {string | null} */
|
|
2202
|
+
const script = typeof message.script === 'string' ? message.script : null;
|
|
2203
|
+
const scriptIsModule = script !== null && message.scriptIsModule === true;
|
|
2204
|
+
// https images the page's files name as literals that the first paint may
|
|
2205
|
+
// not show (the next view, a feed after a click): fetched the same way, so
|
|
2206
|
+
// the script draws them from the same carried data.
|
|
2207
|
+
if (remote && script !== null) {
|
|
2208
|
+
const literals = /** @type {string[]} */ (message.remoteLiterals ?? []);
|
|
2209
|
+
const namedOnly = new Set(/** @type {string[]} */ (message.remoteNamedOnly ?? []));
|
|
2210
|
+
await remote.get(literals);
|
|
2211
|
+
for (const url of literals) {
|
|
2212
|
+
const fetched = remote.results.get(url);
|
|
2213
|
+
if (!fetched || 'uri' in fetched) continue;
|
|
2214
|
+
// An address that counts only by a name (`imageUploadUrl`, an object's
|
|
2215
|
+
// `src`) can be an API's or a player's: when its server answers with
|
|
2216
|
+
// another type (JSON, a page), the result lists it, with no warning.
|
|
2217
|
+
// Any other later-drawn address warns, as in the first paint.
|
|
2218
|
+
if (fetched.answered && namedOnly.has(url)) continue;
|
|
2219
|
+
const key = `remote:${url}`;
|
|
2220
|
+
if (ctx.counted.has(key)) continue;
|
|
2221
|
+
ctx.counted.add(key);
|
|
2222
|
+
warnings.push({
|
|
2223
|
+
code: 'remote-asset',
|
|
2224
|
+
message: `${url}, which the page's code names as an image, is loaded from the network when the script draws it, which a sandboxed page cannot reach; save it beside the page and import it instead. The render could not fetch it: ${fetched.reason}.`,
|
|
2225
|
+
});
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
/** Built addresses named in a warning already. @type {Set<string>} */
|
|
2229
|
+
const builtNamed = new Set();
|
|
2230
|
+
for (const built of /** @type {{text: string, file: string, line: number}[]} */ (message.builtRemote ?? [])) {
|
|
2231
|
+
const where = `${path.relative(dir, built.file).split(path.sep).join('/')}:${built.line}`;
|
|
2232
|
+
if (builtNamed.has(`${where} ${built.text}`)) continue;
|
|
2233
|
+
builtNamed.add(`${where} ${built.text}`);
|
|
2234
|
+
warnings.push({
|
|
2235
|
+
code: 'remote-asset',
|
|
2236
|
+
message: `${built.text} (${where}) builds an image address in code, so the render cannot carry it: the file asks the network for it when the script draws it. Write the address whole, or save the image beside the page and import it.`,
|
|
2237
|
+
});
|
|
2238
|
+
}
|
|
2239
|
+
// The script draws what the markup does not show yet (a menu as it opens,
|
|
2240
|
+
// the next tab), so the rules every class name it holds needs stay too.
|
|
2241
|
+
// Core builds a part's class at run time from the part's name
|
|
2242
|
+
// (`banner-icon` -> `astryx-banner-icon`), so each name also keeps the
|
|
2243
|
+
// class Core's naming module makes from it.
|
|
2244
|
+
const tokens = script?.match(/[A-Za-z_][\w-]*/g) ?? [];
|
|
2245
|
+
const coreClass = script ? await coreClassNamer(entry, served) : null;
|
|
2246
|
+
const kept = script
|
|
2247
|
+
? new Set([...used, ...tokens, ...(coreClass ? tokens.map(coreClass) : [])])
|
|
2248
|
+
: used;
|
|
1035
2249
|
// A page that draws elements in a state (hovered, focused, pressed) marks
|
|
1036
2250
|
// them; its stylesheet then applies those states' rules to them too.
|
|
1037
2251
|
const states = markup.includes(' data-astryx-state="');
|
|
1038
2252
|
const layerOrder = sheetText.map(layerOrderOf).find(Boolean) ?? '';
|
|
1039
2253
|
let css = layerOrder;
|
|
2254
|
+
/** The classes the kept rules of Core's and the official packages' stylesheets name: only these take an alias. @type {Set<string>} */
|
|
2255
|
+
const packageClasses = new Set();
|
|
1040
2256
|
try {
|
|
1041
2257
|
// A stylesheet's url()s are relative to the stylesheet, not the page: a
|
|
1042
2258
|
// theme's font, or an image beside an imported stylesheet.
|
|
1043
2259
|
const included = new Set(sheetFiles);
|
|
1044
2260
|
/** @type {string[]} */
|
|
1045
2261
|
const packageSheets = [];
|
|
1046
|
-
/**
|
|
2262
|
+
/**
|
|
2263
|
+
* A stylesheet's rules cut to the page, with its own imports expanded,
|
|
2264
|
+
* and the warnings that expanding them gave.
|
|
2265
|
+
* @param {string} file @param {string} text
|
|
2266
|
+
* @returns {{file: string, cut: string, expandWarnings: RenderWarning[]}}
|
|
2267
|
+
*/
|
|
1047
2268
|
const sheet = (file, text) => {
|
|
2269
|
+
/** @type {RenderWarning[]} */
|
|
2270
|
+
const expandWarnings = [];
|
|
1048
2271
|
try {
|
|
1049
2272
|
const own = expandImports(file, text, {
|
|
1050
|
-
warnings,
|
|
2273
|
+
warnings: expandWarnings,
|
|
1051
2274
|
carried: carriedCss,
|
|
2275
|
+
importers: cssImporters,
|
|
1052
2276
|
included,
|
|
1053
2277
|
packageSheets,
|
|
1054
2278
|
served,
|
|
1055
2279
|
});
|
|
1056
|
-
return
|
|
1057
|
-
...ctx,
|
|
1058
|
-
dir: path.dirname(file),
|
|
1059
|
-
});
|
|
2280
|
+
return {file, cut: cutCss(own, kept, {states}), expandWarnings};
|
|
1060
2281
|
} catch (e) {
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
/** @type {any} */ (e)?.reason ??
|
|
1064
|
-
(e instanceof Error ? e.message : String(e));
|
|
1065
|
-
throw new RenderError(
|
|
1066
|
-
'ERR_RENDER_COMPILE',
|
|
1067
|
-
`${path.relative(dir, file).split(path.sep).join('/')} is not valid CSS: ${reason}`,
|
|
1068
|
-
);
|
|
2282
|
+
warnings.push(...expandWarnings);
|
|
2283
|
+
throw invalidSheet(e, file);
|
|
1069
2284
|
}
|
|
1070
2285
|
};
|
|
1071
|
-
|
|
1072
|
-
|
|
2286
|
+
/** @param {unknown} e @param {string} file */
|
|
2287
|
+
const invalidSheet = (e, file) => {
|
|
2288
|
+
if (e instanceof RenderAssetError || e instanceof RenderError) return e;
|
|
2289
|
+
const reason =
|
|
2290
|
+
/** @type {any} */ (e)?.reason ??
|
|
2291
|
+
(e instanceof Error ? e.message : String(e));
|
|
2292
|
+
return new RenderError(
|
|
2293
|
+
'ERR_RENDER_COMPILE',
|
|
2294
|
+
`${path.relative(dir, file).split(path.sep).join('/')} is not valid CSS: ${reason}`,
|
|
2295
|
+
);
|
|
2296
|
+
};
|
|
2297
|
+
const parts = sheetText.map((text, i) => sheet(sheetFiles[i], text));
|
|
2298
|
+
parts.forEach(({cut}, i) => {
|
|
2299
|
+
if (sheetIsAstryx[i]) for (const m of cut.matchAll(/\.(-?[_a-zA-Z][\w-]*)/g)) packageClasses.add(m[1]);
|
|
1073
2300
|
});
|
|
1074
2301
|
for (const {
|
|
1075
2302
|
file,
|
|
@@ -1077,11 +2304,31 @@ export async function renderPage(entry, options = {}) {
|
|
|
1077
2304
|
} of /** @type {{file: string, css: string}[]} */ (
|
|
1078
2305
|
message.importedCss ?? []
|
|
1079
2306
|
)) {
|
|
1080
|
-
|
|
2307
|
+
parts.push(sheet(file, text));
|
|
2308
|
+
}
|
|
2309
|
+
// The font faces the page draws with are known from the whole
|
|
2310
|
+
// stylesheet, the markup and the script; the cut runs before the files
|
|
2311
|
+
// are read, so a face it drops is never read, counted or warned about.
|
|
2312
|
+
const stylesheet = [...parts.map(part => part.cut), message.css ?? ''].join(
|
|
2313
|
+
'\n',
|
|
2314
|
+
);
|
|
2315
|
+
const drawn = markup + (script ?? '');
|
|
2316
|
+
for (const {file, cut, expandWarnings} of parts) {
|
|
2317
|
+
warnings.push(...expandWarnings);
|
|
2318
|
+
try {
|
|
2319
|
+
css += await inlineWithRemote(
|
|
2320
|
+
options.cutFontFaces ? cutFontFaces(cut, drawn, stylesheet) : cut,
|
|
2321
|
+
'css',
|
|
2322
|
+
{...ctx, dir: path.dirname(file)},
|
|
2323
|
+
);
|
|
2324
|
+
} catch (e) {
|
|
2325
|
+
throw invalidSheet(e, file);
|
|
2326
|
+
}
|
|
1081
2327
|
}
|
|
1082
2328
|
for (const spec of packageSheets)
|
|
1083
2329
|
if (!sheets.includes(spec)) sheets.push(spec);
|
|
1084
|
-
if (message.css) css +=
|
|
2330
|
+
if (message.css) css += await inlineWithRemote(message.css, 'css', ctx);
|
|
2331
|
+
remote?.done();
|
|
1085
2332
|
} catch (e) {
|
|
1086
2333
|
const err = /** @type {any} */ (e);
|
|
1087
2334
|
if (err instanceof RenderAssetError)
|
|
@@ -1102,6 +2349,10 @@ export async function renderPage(entry, options = {}) {
|
|
|
1102
2349
|
.replace(/'|'/g, "'")
|
|
1103
2350
|
.replace(/ /g, ' ')
|
|
1104
2351
|
.replace(/\s+/g, ' ');
|
|
2352
|
+
// The components' own docs say which one drops a missing text; they are
|
|
2353
|
+
// read only when a text is missing.
|
|
2354
|
+
/** @type {((entry: import('./dropped-text.mjs').ChainEntry) => Promise<boolean | null>) | null} */
|
|
2355
|
+
let takesChildren = null;
|
|
1105
2356
|
for (const t of /** @type {any[]} */ (message.texts ?? [])) {
|
|
1106
2357
|
if (t.hidden || t.text.length < 2 || plainText.includes(t.text)) continue;
|
|
1107
2358
|
// The code around it ran: other text from the same function rendered.
|
|
@@ -1109,13 +2360,32 @@ export async function renderPage(entry, options = {}) {
|
|
|
1109
2360
|
message.fnTexts?.[t.fn] ?? []
|
|
1110
2361
|
).filter(o => o !== t.text);
|
|
1111
2362
|
if (!around.some(o => plainText.includes(o))) continue;
|
|
2363
|
+
takesChildren ??= childrenReader(
|
|
2364
|
+
/** @type {{name: string, dir: string}[]} */ (message.fromSet ?? []).find(
|
|
2365
|
+
p => p.name === '@astryxdesign/core',
|
|
2366
|
+
)?.dir ??
|
|
2367
|
+
findNodeModulesPackage(dir, '@astryxdesign/core')?.packageDir ??
|
|
2368
|
+
null,
|
|
2369
|
+
);
|
|
2370
|
+
const dropper = await dropperOf(t.chain ?? [], takesChildren);
|
|
2371
|
+
// Its own component takes children: a later paint shows the text.
|
|
2372
|
+
if (dropper === null) continue;
|
|
2373
|
+
const shown = t.text.length > 60 ? `${t.text.slice(0, 57)}...` : t.text;
|
|
2374
|
+
const where =
|
|
2375
|
+
t.file && t.file !== entry
|
|
2376
|
+
? ` of ${path.relative(dir, t.file).split(path.sep).join('/')}`
|
|
2377
|
+
: '';
|
|
1112
2378
|
warnings.push({
|
|
1113
2379
|
code: 'dropped-children',
|
|
1114
|
-
message:
|
|
2380
|
+
message: dropper
|
|
2381
|
+
? `<${dropper.component}> on line ${dropper.line}${where} did not render the text "${shown}" it was given; ${dropper.name} takes no children, so pass the text through one of its props (astryx component ${dropper.name}).`
|
|
2382
|
+
: `<${t.component}> on line ${t.line}${where} did not render the text "${shown}" it was given; it takes that text through a prop (often label=), so check its props.`,
|
|
1115
2383
|
});
|
|
1116
2384
|
}
|
|
1117
|
-
//
|
|
1118
|
-
//
|
|
2385
|
+
// A media query the page asks in JavaScript gets its server answer in the
|
|
2386
|
+
// markup. The file paints that answer first and asks again when its script
|
|
2387
|
+
// runs; a viewer that blocks scripts keeps the server answer, and so does
|
|
2388
|
+
// a markup-only render.
|
|
1119
2389
|
const screenQueries = [
|
|
1120
2390
|
...new Set(
|
|
1121
2391
|
/** @type {{call: string}[]} */ (message.screenQueries ?? []).map(
|
|
@@ -1126,11 +2396,14 @@ export async function renderPage(entry, options = {}) {
|
|
|
1126
2396
|
if (screenQueries.length > 0) {
|
|
1127
2397
|
warnings.push({
|
|
1128
2398
|
code: 'screen-query',
|
|
1129
|
-
message:
|
|
2399
|
+
message: script
|
|
2400
|
+
? `The page asks ${screenQueries.join(', ')} in JavaScript: this file paints the server answer first and asks again when its script runs, and a viewer that blocks scripts keeps the server answer. To fit every screen from the first paint, fold the layout with CSS: Grid columns={{minWidth}}, or a StyleX @media or @container style.`
|
|
2401
|
+
: `The page asks ${screenQueries.join(', ')} in JavaScript, which this file never runs: readers on every screen get its server answer, so fold the layout with CSS: Grid columns={{minWidth}}, or a StyleX @media or @container style.`,
|
|
1130
2402
|
});
|
|
1131
2403
|
}
|
|
1132
2404
|
// A chart the render did not draw is an empty box: a ResponsiveContainer
|
|
1133
|
-
// holds only its sizing box, and a chart of fixed size an empty wrapper.
|
|
2405
|
+
// holds only its sizing box, and a chart of fixed size an empty wrapper. The
|
|
2406
|
+
// file's script draws it when it runs.
|
|
1134
2407
|
const blankCharts =
|
|
1135
2408
|
(
|
|
1136
2409
|
markup.match(
|
|
@@ -1143,7 +2416,17 @@ export async function renderPage(entry, options = {}) {
|
|
|
1143
2416
|
if (blankCharts > 0) {
|
|
1144
2417
|
warnings.push({
|
|
1145
2418
|
code: 'chart-size',
|
|
1146
|
-
message:
|
|
2419
|
+
message: script
|
|
2420
|
+
? `${blankCharts === 1 ? 'A chart' : `${blankCharts} charts`} could not be drawn without a browser, so the file paints ${blankCharts === 1 ? 'it' : 'them'} empty and its script draws ${blankCharts === 1 ? 'it' : 'them'} when it runs; a viewer that blocks scripts keeps ${blankCharts === 1 ? 'it' : 'them'} empty. The render draws a chart into the markup only when a module of the page (not an installed package) imports the chart, and its ResponsiveContainer, from recharts by name (\`import {LineChart} from 'recharts'\`).`
|
|
2421
|
+
: `${blankCharts === 1 ? 'A chart' : `${blankCharts} charts`} could not be drawn without a browser, so ${blankCharts === 1 ? 'it is' : 'they are'} empty here: the render draws a chart only when a module of the page (not an installed package) imports the chart, and its ResponsiveContainer, from recharts by name (\`import {LineChart} from 'recharts'\`).`,
|
|
2422
|
+
});
|
|
2423
|
+
}
|
|
2424
|
+
// Text inside a drawing that scales to its box shrinks with it on a phone.
|
|
2425
|
+
const smallText = smallSvgText(markup);
|
|
2426
|
+
if (smallText) {
|
|
2427
|
+
warnings.push({
|
|
2428
|
+
code: 'chart-size',
|
|
2429
|
+
message: `${smallText.count === 1 ? 'An SVG drawing scales' : `${smallText.count} SVG drawings scale`} to fit ${smallText.count === 1 ? 'its' : 'their'} box with text inside, so on a 375 px phone that text shows at about ${smallText.px} px. Put the labels in HTML beside the drawing, or draw the chart with recharts in a ResponsiveContainer, which keeps its text size.`,
|
|
1147
2430
|
});
|
|
1148
2431
|
}
|
|
1149
2432
|
if (message.chartsAlone) {
|
|
@@ -1158,7 +2441,9 @@ export async function renderPage(entry, options = {}) {
|
|
|
1158
2441
|
const why = causes[message.chartsAlone] ?? causes.error;
|
|
1159
2442
|
warnings.push({
|
|
1160
2443
|
code: 'chart-size',
|
|
1161
|
-
message:
|
|
2444
|
+
message: script
|
|
2445
|
+
? `${why}, so each chart was drawn by itself for the first paint, as the first render gave it: until the file's script draws the page again, a custom tick, label or shape in a chart sees React context defaults, not the values the page provides.`
|
|
2446
|
+
: `${why}, so each chart was drawn by itself, as the first render gave it: a custom tick, label or shape in a chart sees React context defaults, not the values the page provides.`,
|
|
1162
2447
|
});
|
|
1163
2448
|
}
|
|
1164
2449
|
for (const sheet of /** @type {string[]} */ (message.skippedCss ?? [])) {
|
|
@@ -1181,12 +2466,41 @@ export async function renderPage(entry, options = {}) {
|
|
|
1181
2466
|
// Images and fonts the page or a stylesheet names by a relative path
|
|
1182
2467
|
// (`<img src="./logo.png">`, `url(./bg.png)`) are carried too, so the page
|
|
1183
2468
|
// comes back with them; a package's own files are not.
|
|
2469
|
+
/**
|
|
2470
|
+
* Local files the page uses that the file cannot carry: a module, a
|
|
2471
|
+
* stylesheet or an image from outside the folder it carries from, which no
|
|
2472
|
+
* reverse writes, and a Sass or Less stylesheet. A package's own files
|
|
2473
|
+
* are not the page's.
|
|
2474
|
+
* @type {string[]}
|
|
2475
|
+
*/
|
|
2476
|
+
const uncarried = [...(/** @type {string[]} */ (message.uncarried ?? []))];
|
|
2477
|
+
// With a package that node_modules links into the carried folder, a sheet
|
|
2478
|
+
// another pulls in is carried only when a carried sheet imports it: the
|
|
2479
|
+
// linked package's own stylesheets are the package's (the worker carries
|
|
2480
|
+
// only the files the page reaches by a path).
|
|
2481
|
+
const linkedRoots = /** @type {string[]} */ (message.linkedRoots ?? []);
|
|
2482
|
+
/** @type {Set<string>} */
|
|
2483
|
+
const importedByCarried = new Set();
|
|
2484
|
+
if (linkedRoots.length > 0) {
|
|
2485
|
+
for (let grew = true; grew; ) {
|
|
2486
|
+
grew = false;
|
|
2487
|
+
for (const [sheet, from] of cssImporters) {
|
|
2488
|
+
if (importedByCarried.has(sheet)) continue;
|
|
2489
|
+
if ([...from].some(f => files.includes(f) || importedByCarried.has(f))) {
|
|
2490
|
+
importedByCarried.add(sheet);
|
|
2491
|
+
grew = true;
|
|
2492
|
+
}
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
}
|
|
1184
2496
|
for (const sheet of carriedCss) {
|
|
1185
|
-
if (
|
|
1186
|
-
!isInside(sheet, scope) ||
|
|
1187
|
-
path.relative(scope, sheet).split(path.sep).includes('node_modules')
|
|
1188
|
-
)
|
|
2497
|
+
if (path.relative(scope, sheet).split(path.sep).includes('node_modules'))
|
|
1189
2498
|
continue;
|
|
2499
|
+
if (linkedRoots.length > 0 && !importedByCarried.has(sheet)) continue;
|
|
2500
|
+
if (!isInside(sheet, scope)) {
|
|
2501
|
+
if (!uncarried.includes(sheet)) uncarried.push(sheet);
|
|
2502
|
+
continue;
|
|
2503
|
+
}
|
|
1190
2504
|
if (!files.includes(sheet)) files.push(sheet);
|
|
1191
2505
|
}
|
|
1192
2506
|
/** Assets named in a warning already, so each is named once. @type {Set<string>} */
|
|
@@ -1199,18 +2513,19 @@ export async function renderPage(entry, options = {}) {
|
|
|
1199
2513
|
* @param {string} how how the page uses it, for the warning
|
|
1200
2514
|
*/
|
|
1201
2515
|
const carryAsset = (asset, how) => {
|
|
1202
|
-
if (
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
2516
|
+
if (path.relative(scope, asset).split(path.sep).includes('node_modules'))
|
|
2517
|
+
return;
|
|
2518
|
+
if (!isInside(asset, scope)) {
|
|
2519
|
+
if (isFileAt(asset) && !uncarried.includes(asset)) uncarried.push(asset);
|
|
1206
2520
|
return;
|
|
2521
|
+
}
|
|
1207
2522
|
if (files.includes(asset) || notCarried.has(asset)) return;
|
|
1208
2523
|
/** @param {string} why */
|
|
1209
2524
|
const leaveOut = why => {
|
|
1210
2525
|
notCarried.add(asset);
|
|
1211
2526
|
warnings.push({
|
|
1212
2527
|
code: 'not-embedded',
|
|
1213
|
-
message: `${path.relative(dir, asset).split(path.sep).join('/')} is ${how} but not carried in the file: ${why}, so
|
|
2528
|
+
message: `${path.relative(dir, asset).split(path.sep).join('/')} is ${how} but not carried in the file: ${why}, so experimental import cannot give it back.`,
|
|
1214
2529
|
});
|
|
1215
2530
|
};
|
|
1216
2531
|
/** @type {Buffer} */
|
|
@@ -1253,6 +2568,9 @@ export async function renderPage(entry, options = {}) {
|
|
|
1253
2568
|
path.relative(named, f).split(path.sep).join('/'),
|
|
1254
2569
|
)),
|
|
1255
2570
|
);
|
|
2571
|
+
// A linked package's modules the file does not carry may still name images
|
|
2572
|
+
// the script draws later: those images are carried and shown the same way.
|
|
2573
|
+
carriedText.push(...(/** @type {string[]} */ (message.linkedModules ?? [])));
|
|
1256
2574
|
for (const file of carriedText) {
|
|
1257
2575
|
let text;
|
|
1258
2576
|
try {
|
|
@@ -1260,17 +2578,87 @@ export async function renderPage(entry, options = {}) {
|
|
|
1260
2578
|
} catch {
|
|
1261
2579
|
continue;
|
|
1262
2580
|
}
|
|
1263
|
-
for (const ref of assetRefsOf(text, file)) {
|
|
1264
|
-
const
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
);
|
|
2581
|
+
for (const {written: ref, file: name} of assetRefsOf(text, file)) {
|
|
2582
|
+
const how = `named in ${path.relative(dir, file).split(path.sep).join('/')}`;
|
|
2583
|
+
/** @param {string} f */
|
|
2584
|
+
const local = f => isInside(f, named) && isFileAt(f);
|
|
2585
|
+
/** The file the string names in the browser: a path from the site's root, or, for a relative string, from the page's folder (the file's address), not the module's. @type {string | null} */
|
|
2586
|
+
let shown;
|
|
2587
|
+
if (ref.startsWith('/')) {
|
|
2588
|
+
const found = assetRef(ref, {dir, root: site});
|
|
2589
|
+
shown = found?.kind === 'file' ? found.file : null;
|
|
2590
|
+
} else {
|
|
2591
|
+
// The file the module names beside it, which a restore lays out
|
|
2592
|
+
// where the module's own folder finds it.
|
|
2593
|
+
const beside = path.resolve(path.dirname(file), name);
|
|
2594
|
+
if (local(beside)) carryAsset(beside, how);
|
|
2595
|
+
// A stylesheet's url() is its own folder's file, which its inlined
|
|
2596
|
+
// rules already carry; only a module's string reaches the script.
|
|
2597
|
+
if (/\.css$/i.test(file)) continue;
|
|
2598
|
+
shown = path.resolve(dir, name);
|
|
2599
|
+
if (!local(shown)) shown = null;
|
|
2600
|
+
}
|
|
2601
|
+
if (!shown) continue;
|
|
2602
|
+
carryAsset(shown, how);
|
|
2603
|
+
// An image the page draws only later (the next view, a row below the
|
|
2604
|
+
// fold) shows from that file's carried data once the script draws it,
|
|
2605
|
+
// as the first paint shows the images it draws. The same string in two
|
|
2606
|
+
// folders names one file in the browser, so it gets one file's data.
|
|
2607
|
+
if (files.includes(shown) && !ctx.rewrites.has(ref)) {
|
|
2608
|
+
ctx.rewrites.set(ref, assetDataUri(shown));
|
|
1271
2609
|
}
|
|
1272
2610
|
}
|
|
1273
2611
|
}
|
|
2612
|
+
// The script draws the page again with the paths the page wrote, so each
|
|
2613
|
+
// carried image keeps showing, the first paint's and the ones drawn later.
|
|
2614
|
+
// A local path becomes its data in the script. An https address stays as
|
|
2615
|
+
// the page wrote it: the file's script gives the carried data where the
|
|
2616
|
+
// browser takes an image's address (imageSinks), so a link, a text or the
|
|
2617
|
+
// URL API still reads the page's own address.
|
|
2618
|
+
// A remote address is one the render fetches: https, or one with no
|
|
2619
|
+
// scheme (`//cdn.example.com/a.png`).
|
|
2620
|
+
const remoteAddress = (/** @type {string} */ url) => /^(https?:)?\/\//i.test(url.trim());
|
|
2621
|
+
/** @type {Map<string, string>} */
|
|
2622
|
+
const localRewrites = new Map();
|
|
2623
|
+
for (const [was, now] of ctx.rewrites) {
|
|
2624
|
+
// A value is read as a `srcset` only when it lists a remote candidate:
|
|
2625
|
+
// a local name may hold a comma and a space (`./Logo, dark.png`).
|
|
2626
|
+
const written = /\s/.test(was.trim()) ? parseSrcset(was) : null;
|
|
2627
|
+
if (!written?.some(candidate => remoteAddress(candidate.url))) {
|
|
2628
|
+
if (!remoteAddress(was)) localRewrites.set(was, now);
|
|
2629
|
+
continue;
|
|
2630
|
+
}
|
|
2631
|
+
// A `srcset` keeps its remote candidates as written.
|
|
2632
|
+
const carried = parseSrcset(now);
|
|
2633
|
+
if (written.length !== carried.length) continue;
|
|
2634
|
+
const mixed = written.map((candidate, i) => (remoteAddress(candidate.url) ? candidate : carried[i]));
|
|
2635
|
+
if (mixed.some((candidate, i) => candidate !== written[i])) localRewrites.set(was, formatSrcset(mixed));
|
|
2636
|
+
}
|
|
2637
|
+
// An https image the first paint shows and marks: the sink reads its data
|
|
2638
|
+
// from that element, so the script holds no second copy of it.
|
|
2639
|
+
/** @type {[string, string][]} */
|
|
2640
|
+
const sinks = [];
|
|
2641
|
+
/** @type {Array<[string, number] | [string, number, number]>} */
|
|
2642
|
+
const reads = [];
|
|
2643
|
+
const listed = listedCandidates(ctx.carried, ctx.srcsets, ctx.rewrites);
|
|
2644
|
+
for (const [url, fetched] of remote?.results ?? []) {
|
|
2645
|
+
if (!('uri' in fetched)) continue;
|
|
2646
|
+
const read = firstPaintRead(url, ctx.carried, listed);
|
|
2647
|
+
if (read) reads.push(read);
|
|
2648
|
+
else sinks.push([url, fetched.uri]);
|
|
2649
|
+
}
|
|
2650
|
+
let pageScriptText = script === null ? null : withCarriedPaths(script, localRewrites, ctx.carried ?? new Map(), ctx.srcsets, ctx.rewrites, scriptIsModule);
|
|
2651
|
+
// The values the first paint carries are read once, before the sinks and
|
|
2652
|
+
// the page's script that use them.
|
|
2653
|
+
let prelude = reads.length > 0 ? CARRIED_PRELUDE : '';
|
|
2654
|
+
if (pageScriptText?.startsWith(CARRIED_PRELUDE)) {
|
|
2655
|
+
prelude = CARRIED_PRELUDE;
|
|
2656
|
+
pageScriptText = pageScriptText.slice(CARRIED_PRELUDE.length);
|
|
2657
|
+
}
|
|
2658
|
+
const drawn =
|
|
2659
|
+
pageScriptText === null
|
|
2660
|
+
? null
|
|
2661
|
+
: prelude + (sinks.length + reads.length > 0 ? imageSinks(sinks, reads, CARRIED_VALUES) : '') + pageScriptText;
|
|
1274
2662
|
// Paths are kept relative to the folder that holds every file: the page's
|
|
1275
2663
|
// folder, or an ancestor when the page imports from above it, but never one
|
|
1276
2664
|
// from which the page's own path holds a name a reverse refuses (a
|
|
@@ -1295,17 +2683,58 @@ export async function renderPage(entry, options = {}) {
|
|
|
1295
2683
|
const ordered = [entry, ...files.filter(f => f !== entry)];
|
|
1296
2684
|
/** @type {{path: string, bytes: Buffer}[]} */
|
|
1297
2685
|
const embedded = [];
|
|
2686
|
+
/**
|
|
2687
|
+
* Files the page uses that the file does not carry, so --reverse cannot
|
|
2688
|
+
* give them back: the note and the result name each one.
|
|
2689
|
+
* @type {string[]}
|
|
2690
|
+
*/
|
|
2691
|
+
const leftOut = [];
|
|
1298
2692
|
for (const f of ordered) {
|
|
1299
2693
|
const rel = path.relative(base, f).split(path.sep).join('/');
|
|
1300
|
-
|
|
2694
|
+
const problem = f === entry ? null : embeddedPathProblem(rel);
|
|
2695
|
+
if (problem) leftOut.push(rel);
|
|
2696
|
+
if (problem?.toolConfig) {
|
|
2697
|
+
const fix = carriedNameFor(rel);
|
|
2698
|
+
warnings.push({
|
|
2699
|
+
code: 'not-carried',
|
|
2700
|
+
message:
|
|
2701
|
+
fix.action === 'rename'
|
|
2702
|
+
? `${rel} is not carried: its name reads as a tool's configuration, which experimental import never writes. The page shows it, but experimental import cannot give it back. If it holds the page's data, rename it, such as ${fix.name}, to carry it. If a tool reads it, move the values the page reads into a file of its own, such as page-data.json.`
|
|
2703
|
+
: `${rel} is not carried: it is a tool's configuration, which experimental import never writes. The page shows what it reads from it, but experimental import cannot give it back. Move the values the page reads into a file of its own, such as ${fix.name}, to carry them.`,
|
|
2704
|
+
});
|
|
2705
|
+
continue;
|
|
2706
|
+
}
|
|
2707
|
+
if (problem) {
|
|
1301
2708
|
warnings.push({
|
|
1302
2709
|
code: 'not-embedded',
|
|
1303
|
-
message: `${rel} is not carried in the file (a rendered page carries the page and the local modules, stylesheets, JSON files and images it imports, but never project or tool configuration, or a file a test, story or benchmark runner would run), so
|
|
2710
|
+
message: `${rel} is not carried in the file (a rendered page carries the page and the local modules, stylesheets, JSON files and images it imports, but never project or tool configuration, or a file a test, story or benchmark runner would run), so experimental import cannot give it back.`,
|
|
1304
2711
|
});
|
|
1305
2712
|
continue;
|
|
1306
2713
|
}
|
|
1307
2714
|
embedded.push({path: rel, bytes: fs.readFileSync(f)});
|
|
1308
2715
|
}
|
|
2716
|
+
for (const asset of notCarried) {
|
|
2717
|
+
leftOut.push(path.relative(base, asset).split(path.sep).join('/'));
|
|
2718
|
+
}
|
|
2719
|
+
// In a project, a render carries from the project's folder wherever it
|
|
2720
|
+
// runs, so only moving the file inside it carries it.
|
|
2721
|
+
const inProject = projectOf(dir) !== null;
|
|
2722
|
+
for (const f of uncarried) {
|
|
2723
|
+
// A file the render carries (a JSON file, stylesheet or image from above
|
|
2724
|
+
// the page's folder widens the folder it carries from) is not left out.
|
|
2725
|
+
if (files.includes(f)) continue;
|
|
2726
|
+
const rel = path.relative(base, f).split(path.sep).join('/');
|
|
2727
|
+
if (leftOut.includes(rel)) continue;
|
|
2728
|
+
leftOut.push(rel);
|
|
2729
|
+
// A Sass or Less stylesheet already has its missing-asset warning.
|
|
2730
|
+
if (/\.(scss|sass|less)$/i.test(f)) continue;
|
|
2731
|
+
warnings.push({
|
|
2732
|
+
code: 'not-embedded',
|
|
2733
|
+
message: inProject
|
|
2734
|
+
? `${rel} is not carried: it is outside the project's folder, which a render carries from, and experimental import writes nothing outside it. The page shows it, but experimental import cannot give it back. Move it inside the project's folder.`
|
|
2735
|
+
: `${rel} is not carried: it is outside the folder the render carries from, and experimental import writes nothing outside it. The page shows it, but experimental import cannot give it back. Render from a folder that holds it, or move it into the page's folder.`,
|
|
2736
|
+
});
|
|
2737
|
+
}
|
|
1309
2738
|
const heading = /<h1\b[^>]*>([\s\S]*?)<\/h1>/i
|
|
1310
2739
|
.exec(markup)?.[1]
|
|
1311
2740
|
?.replace(/<[^>]*>/g, '')
|
|
@@ -1316,8 +2745,69 @@ export async function renderPage(entry, options = {}) {
|
|
|
1316
2745
|
? decodeAttr(heading)
|
|
1317
2746
|
: path.basename(entry).replace(/\.[^.]+$/, ''));
|
|
1318
2747
|
const generator = `<meta name="generator" content="Astryx${options.version ? ` ${escapeHtml(options.version)}` : ''}">`;
|
|
1319
|
-
const
|
|
2748
|
+
const importedSheets = /** @type {{file: string, css: string}[]} */ (message.importedCss ?? []);
|
|
2749
|
+
// The theme editor shows each mode itself, so its markup-only pages keep
|
|
2750
|
+
// both schemes; a written file shows the theme's one mode.
|
|
2751
|
+
// The theme's stylesheet may come through the page's own CSS, by an
|
|
2752
|
+
// `@import` that the file inlines.
|
|
2753
|
+
const modeSheets = options.markupOnly
|
|
2754
|
+
? []
|
|
2755
|
+
: sheetsWithImports(
|
|
2756
|
+
[
|
|
2757
|
+
...themeSheetFiles.map((sheet, i) => ({...sheet, css: themeSheets[i]})),
|
|
2758
|
+
...importedSheets.map(sheet => ({file: sheet.file, css: sheet.css})),
|
|
2759
|
+
],
|
|
2760
|
+
served,
|
|
2761
|
+
);
|
|
2762
|
+
const mode = options.markupOnly ? null : oneColorModeOf(
|
|
2763
|
+
markup,
|
|
2764
|
+
rootThemeColorModes(markup, modeSheets, (specifier, from) => {
|
|
2765
|
+
try {
|
|
2766
|
+
return resolveServed(specifier, from, served) ?? resolvePackageModule(specifier, from);
|
|
2767
|
+
} catch {
|
|
2768
|
+
return resolvePackageModule(specifier, from);
|
|
2769
|
+
}
|
|
2770
|
+
}),
|
|
2771
|
+
modeSheets.map(sheet => sheet.css),
|
|
2772
|
+
);
|
|
2773
|
+
const drawsCharts = markup.includes('class="recharts-responsive-container"');
|
|
2774
|
+
// A page that repeats an element repeats its StyleX class list: the first
|
|
2775
|
+
// paint names each such list by one alias class (class-alias.mjs). The
|
|
2776
|
+
// script draws its own elements with StyleX's classes.
|
|
2777
|
+
if (script && !options.keepClassNames) ({markup, css} = aliasClasses(markup, css, packageClasses, new Set(tokens)));
|
|
2778
|
+
const style = `<style>${schemeCssFor(mode)}${script ? `#${ROOT_ID}{display:contents}` : ''}${drawsCharts ? CHART_CSS : ''}${css}</style>`;
|
|
2779
|
+
// With a script, the markup sits in the one element the script draws into,
|
|
2780
|
+
// which takes no box of its own.
|
|
2781
|
+
const body = script ? `<div id="${ROOT_ID}">${markup}</div>` : markup;
|
|
2782
|
+
// An image the embedded source leaves out (under a dot-folder, say) keeps
|
|
2783
|
+
// its own data: URI in the script.
|
|
2784
|
+
const carriedSha = new Set(embedded.map(e => sha256(e.bytes)));
|
|
2785
|
+
/** @type {Map<string, Buffer>} */
|
|
2786
|
+
const imageBytes = new Map();
|
|
2787
|
+
for (const f of files) {
|
|
2788
|
+
if (!isAssetPath(f)) continue;
|
|
2789
|
+
try {
|
|
2790
|
+
const bytes = fs.readFileSync(f);
|
|
2791
|
+
imageBytes.set(sha256(bytes), bytes);
|
|
2792
|
+
} catch {
|
|
2793
|
+
// A file that went away since the page imported it stays as written.
|
|
2794
|
+
}
|
|
2795
|
+
}
|
|
2796
|
+
const pageScript =
|
|
2797
|
+
drawn === null
|
|
2798
|
+
? null
|
|
2799
|
+
: withUncarriedImages(drawn, carriedSha, (sha, prefix) => {
|
|
2800
|
+
const bytes = imageBytes.get(sha);
|
|
2801
|
+
return bytes ? `${prefix},${bytes.toString('base64')}` : null;
|
|
2802
|
+
});
|
|
2803
|
+
// A module script runs once the document is parsed, so a browser that
|
|
2804
|
+
// reaches it before its first paint paints the markup first. A classic
|
|
2805
|
+
// script at the end of the body would run before that paint on a page small
|
|
2806
|
+
// enough to arrive at once. A script that would not run the same in strict
|
|
2807
|
+
// mode (a CommonJS package that does not ask for it) stays classic.
|
|
2808
|
+
const scriptTag = pageScript ? `<script${scriptIsModule ? ' type="module"' : ''}>${pageScript}</script>\n` : '';
|
|
1320
2809
|
let html;
|
|
2810
|
+
let block;
|
|
1321
2811
|
if (options.output) {
|
|
1322
2812
|
// The charset and generator metas come first: a browser reads the
|
|
1323
2813
|
// charset only from the first 1024 bytes, and a CLI decides whether a
|
|
@@ -1351,6 +2841,7 @@ export async function renderPage(entry, options = {}) {
|
|
|
1351
2841
|
: embedded[0].path,
|
|
1352
2842
|
restored: `${file.replace(/\.[^.]+$/, '')}-restored/${embedded[0].path}`,
|
|
1353
2843
|
files: embedded.map(f => f.path),
|
|
2844
|
+
notCarried: leftOut,
|
|
1354
2845
|
packages,
|
|
1355
2846
|
install: Object.entries(packages)
|
|
1356
2847
|
.filter(([name]) => !isServedPackage(name, []))
|
|
@@ -1373,34 +2864,48 @@ export async function renderPage(entry, options = {}) {
|
|
|
1373
2864
|
const rel = carried.get(path.resolve(named));
|
|
1374
2865
|
if (rel && aliasOnly(spec)) aliases[spec] = rel;
|
|
1375
2866
|
}
|
|
2867
|
+
// The public/ folder the render read `/` paths from, when the file
|
|
2868
|
+
// carries files from it, so a reverse expects them there and not in
|
|
2869
|
+
// another public/ the tree holds.
|
|
2870
|
+
const publicRel = path.relative(base, path.join(site, 'public')).split(path.sep).join('/');
|
|
2871
|
+
const publicDir =
|
|
2872
|
+
publicRel && !publicRel.startsWith('..') && !path.isAbsolute(publicRel) &&
|
|
2873
|
+
embedded.some(f => f.path.startsWith(`${publicRel}/`))
|
|
2874
|
+
? publicRel
|
|
2875
|
+
: null;
|
|
1376
2876
|
const record = {
|
|
1377
2877
|
...(facts.cli ? {cli: facts.cli} : {}),
|
|
1378
2878
|
page: facts.page,
|
|
1379
2879
|
...(options.title === undefined ? {} : {title: options.title}),
|
|
1380
2880
|
packages,
|
|
1381
2881
|
...(Object.keys(aliases).length > 0 ? {aliases} : {}),
|
|
2882
|
+
...(leftOut.length > 0 ? {notCarried: leftOut} : {}),
|
|
2883
|
+
...(publicDir ? {publicDir} : {}),
|
|
1382
2884
|
markup: {
|
|
1383
|
-
sha256: sha256(asParsed(
|
|
2885
|
+
sha256: sha256(asParsed(body)),
|
|
1384
2886
|
style: sha256(asParsed(style)),
|
|
1385
2887
|
text: Buffer.from(
|
|
1386
|
-
JSON.stringify({title, runs: textRuns(
|
|
2888
|
+
JSON.stringify({title, runs: textRuns(body)}),
|
|
1387
2889
|
).toString('base64'),
|
|
1388
2890
|
},
|
|
1389
2891
|
};
|
|
2892
|
+
block = sourceBlock(path.basename(entry), embedded, record);
|
|
1390
2893
|
html =
|
|
1391
2894
|
`<!doctype html><html lang="en"${rootThemeAttrs(markup)}><head><meta charset="utf-8">${generator}\n${headerNote(facts)}\n` +
|
|
1392
2895
|
'<meta name="viewport" content="width=device-width,initial-scale=1">' +
|
|
1393
|
-
|
|
1394
|
-
`<title>${escapeHtml(title)}</title>${style}</head><body>${
|
|
1395
|
-
`${
|
|
2896
|
+
`<meta name="color-scheme" content="${mode ?? 'light dark'}">` +
|
|
2897
|
+
`<title>${escapeHtml(title)}</title>${style}</head><body>${body}` +
|
|
2898
|
+
`${block}\n${endNote(facts)}\n${scriptTag}</body></html>\n`;
|
|
1396
2899
|
} else {
|
|
2900
|
+
block = sourceBlock(path.basename(entry), embedded);
|
|
1397
2901
|
html =
|
|
1398
2902
|
`<!doctype html><html lang="en"${rootThemeAttrs(markup)}><head><meta charset="utf-8">` +
|
|
1399
2903
|
'<meta name="viewport" content="width=device-width,initial-scale=1">' +
|
|
1400
|
-
|
|
1401
|
-
`${generator}<title>${escapeHtml(title)}</title>${style}</head><body>${
|
|
1402
|
-
`${
|
|
2904
|
+
`<meta name="color-scheme" content="${mode ?? 'light dark'}">` +
|
|
2905
|
+
`${generator}<title>${escapeHtml(title)}</title>${style}</head><body>${body}` +
|
|
2906
|
+
`${block}${scriptTag}</body></html>\n`;
|
|
1403
2907
|
}
|
|
2908
|
+
const remoteSummary = remote?.summary();
|
|
1404
2909
|
return {
|
|
1405
2910
|
html,
|
|
1406
2911
|
files: embedded.map(f => f.path),
|
|
@@ -1408,6 +2913,7 @@ export async function renderPage(entry, options = {}) {
|
|
|
1408
2913
|
classes: used.size,
|
|
1409
2914
|
cssBytes: Buffer.byteLength(css),
|
|
1410
2915
|
markupBytes: Buffer.byteLength(markup),
|
|
2916
|
+
sourceBytes: Buffer.byteLength(block),
|
|
1411
2917
|
images: new Set([
|
|
1412
2918
|
...[...ctx.counted]
|
|
1413
2919
|
.filter(k => k.startsWith('file:'))
|
|
@@ -1415,6 +2921,10 @@ export async function renderPage(entry, options = {}) {
|
|
|
1415
2921
|
...(message.assets ?? []),
|
|
1416
2922
|
]).size,
|
|
1417
2923
|
warnings,
|
|
2924
|
+
...(leftOut.length > 0 ? {notCarried: leftOut} : {}),
|
|
2925
|
+
propValues: message.propValues ?? [],
|
|
1418
2926
|
fromSet: message.fromSet ?? [],
|
|
2927
|
+
...(pageScript ? {scriptBytes: Buffer.byteLength(pageScript), scriptModules: message.scriptModules ?? 0} : {}),
|
|
2928
|
+
...(remoteSummary && remoteSummary.fetched.length + remoteSummary.failed.length > 0 ? {remoteImages: remoteSummary} : {}),
|
|
1419
2929
|
};
|
|
1420
2930
|
}
|