@astryxdesign/cli 0.7.18-canary.gfacee17 → 0.7.18
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 +185 -19
- package/README.md +19 -19
- package/api/component/_adapter.d.mts +2 -1
- package/api/component/_adapter.mjs +2 -1
- package/api/docs/_adapter.d.mts +6 -5
- package/api/docs/_adapter.mjs +36 -5
- package/api/doctor/_adapter.d.mts +6 -3
- package/api/doctor/_adapter.mjs +13 -5
- package/api/doctor/doctor.mjs +5 -5
- package/api/doctor/font-packages.d.mts +36 -0
- package/api/doctor/font-packages.mjs +124 -0
- package/api/doctor/theme-checks.mjs +110 -49
- package/api/experimental.d.mts +0 -2
- package/api/experimental.mjs +0 -12
- package/api/icon/_adapter.d.mts +2 -2
- package/api/icon/_adapter.mjs +6 -2
- package/api/icon/_authoring.mjs +22 -13
- package/api/icon/_default-look.mjs +15 -15
- package/api/icon/add/add.mjs +14 -9
- package/api/icon/icon.doc.mjs +7 -7
- package/api/icon/icon.type.d.mts +33 -33
- package/api/icon/icon.type.mjs +45 -45
- package/api/icon/iconAdd.doc.mjs +9 -10
- package/api/icon/iconMap.doc.mjs +11 -12
- package/api/icon/iconNewDefinition.doc.mjs +8 -8
- package/api/icon/iconNewSet.doc.mjs +5 -5
- package/api/icon/map/map.mjs +7 -7
- package/api/icon/use/use.mjs +4 -4
- package/api/init/run/run.mjs +0 -1
- package/api/integration/add-helpers.mjs +1 -1
- package/api/integration/validate-integration.type.d.mts +6 -6
- package/api/integration/validate-integration.type.mjs +6 -6
- package/api/render/_adapter.d.mts +5 -3
- package/api/render/_adapter.mjs +64 -4
- package/api/render/render.doc.mjs +9 -2
- package/api/render/render.mjs +5 -2
- package/api/render/render.type.d.mts +17 -0
- package/api/render/render.type.mjs +10 -0
- package/api/search/ORDERING.md +1 -1
- package/api/search/_candidate-score.mjs +20 -0
- package/api/search/_words.d.mts +8 -0
- package/api/search/_words.mjs +15 -0
- package/api/template/template.type.d.mts +2 -2
- package/api/template/template.type.mjs +2 -2
- package/api/theme/_adapter.mjs +19 -11
- package/api/theme/build/build.d.mts +19 -51
- package/api/theme/build/build.mjs +195 -189
- package/api/theme/build/font-warning.d.mts +19 -2
- package/api/theme/build/font-warning.mjs +46 -5
- package/api/theme/generateTonalPalette.doc.mjs +1 -1
- package/api/theme/palette/generate/derive-look.mjs +108 -37
- package/api/theme/palette/generate/mapping.mjs +2 -0
- package/api/theme/template/template.d.mts +0 -17
- package/api/theme/template/template.mjs +1 -42
- package/api/theme/theme.type.d.mts +5 -4
- package/api/theme/theme.type.mjs +5 -4
- package/api/theme/themePaletteGenerate.doc.mjs +1 -1
- package/api/theme/themeRemove.doc.mjs +1 -1
- package/assets/codemods/transforms/v0.7.0/preserve-bottom-sheet-content-padding.mjs +3 -1
- package/assets/component-list.generated.json +1 -1
- package/assets/discover/official-packages.json +26 -2
- package/assets/docs/author-a-theme.doc.mjs +6 -5
- package/assets/docs/browser-support.doc.mjs +1 -0
- package/assets/docs/icons.doc.mjs +8 -7
- package/assets/docs/motion.doc.mjs +46 -0
- package/assets/docs/theme.doc.dense.mjs +6 -17
- package/assets/docs/theme.doc.mjs +6 -16
- package/assets/docs/theme.doc.zh.mjs +6 -16
- package/assets/docs/tree/ci-and-containers.doc.mjs +1 -1
- package/assets/docs/tree/data-colors-in-renderers.doc.mjs +400 -0
- package/assets/docs/tree/font-setup.doc.mjs +30 -0
- package/assets/docs/tree/icon-sets.doc.mjs +2 -2
- package/assets/docs/tree/share-a-page.doc.mjs +1 -1
- package/assets/docs/tree/template-icons.doc.mjs +3 -3
- package/assets/docs/tree/tokens-color.doc.mjs +5 -0
- package/assets/docs/tree/tokens.doc.mjs +4 -3
- package/assets/docs/tree/updates.doc.mjs +1 -1
- package/assets/docs/tree/visualization.doc.mjs +30 -0
- package/assets/docs-routes.generated.json +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/icons/definitions/drag.doc.mjs +1 -0
- package/assets/search-catalog.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/Card/SelectableCardElevated.doc.mjs +1 -1
- package/assets/templates/blocks/components/Card/SelectableCardElevated.tsx +20 -10
- package/assets/templates/blocks/components/Card/SelectableCardShowcase.doc.mjs +1 -1
- package/assets/templates/blocks/components/Card/SelectableCardShowcase.tsx +36 -16
- package/assets/templates/blocks/components/ChatComposerInput/ChatComposerInputMentionTrigger.tsx +6 -0
- package/assets/templates/blocks/components/ChatComposerInput/ChatComposerInputMultipleTriggers.tsx +6 -0
- package/assets/templates/blocks/components/Hooks/useIndicatorFocusRingHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useIndicatorFocusRingHookUsage.tsx +63 -0
- package/assets/templates/blocks/components/Hooks/useLongPressHookUsage.doc.mjs +29 -0
- package/assets/templates/blocks/components/Hooks/useLongPressHookUsage.tsx +237 -0
- package/assets/templates/blocks/components/SideNav/SideNavShowcase.tsx +10 -72
- package/assets/templates/blocks/components/SideNav/SideNavWithHeaderMenu.doc.mjs +1 -1
- package/assets/templates/blocks/components/SideNav/SideNavWithHeaderMenu.tsx +7 -7
- package/assets/templates/blocks/components/Table/TableCustomRowTable.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/TableCustomRowTable.tsx +96 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat-landing/page.tsx +4 -0
- package/assets/templates/pages/dashboard-scorecard/page.tsx +26 -7
- package/assets/templates/pages/editor/page.tsx +13 -3
- package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +2 -2
- package/assets/templates/themes/butter/butterTheme.ts +12 -10
- package/assets/templates/themes/butter/icons.tsx +2 -0
- package/assets/templates/themes/chocolate/chocolateTheme.ts +1 -0
- package/assets/templates/themes/chocolate/icons.tsx +2 -0
- package/assets/templates/themes/gothic/gothicPaletteRefs.generated.ts +1 -1
- package/assets/templates/themes/gothic/gothicTheme.ts +1 -0
- package/assets/templates/themes/gothic/icons.tsx +2 -0
- package/assets/templates/themes/matcha/icons.tsx +2 -0
- package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +2 -2
- package/assets/templates/themes/matcha/matchaTheme.ts +1 -0
- package/assets/templates/themes/neutral/icons.tsx +2 -0
- package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +2 -2
- package/assets/templates/themes/neutral/neutralTheme.ts +1 -0
- package/assets/templates/themes/stone/icons.tsx +2 -0
- package/assets/templates/themes/stone/stonePaletteRefs.generated.ts +1 -1
- package/assets/templates/themes/stone/stoneTheme.ts +1 -0
- package/assets/templates/themes/y2k/icons.tsx +2 -0
- package/assets/templates/themes/y2k/y2kTheme.ts +1 -0
- package/assets/theme.template.ts +9 -5
- package/authoring/config/parse.mjs +1 -1
- package/authoring/doctypes/base/type.ts +2 -3
- package/authoring/doctypes/component/component.doc.mjs +1 -1
- package/authoring/doctypes/icon-set/icon-names.mjs +1 -0
- package/authoring/integration/integration.doc.mjs +1 -1
- package/authoring/integration/type.ts +1 -1
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/doctor.mjs +2 -2
- package/clients/cli/commands/experimental/export.mjs +2 -1
- package/clients/cli/commands/experimental/icon.mjs +17 -17
- package/clients/cli/commands/experimental/index.mjs +0 -5
- package/clients/cli/commands/experimental/render-output.mjs +9 -0
- package/clients/cli/commands/experimental-export.doc.mjs +6 -0
- package/clients/cli/commands/experimental-icon-add.doc.mjs +8 -8
- package/clients/cli/commands/experimental-icon-map.doc.mjs +6 -6
- package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +6 -6
- package/clients/cli/commands/experimental-icon-new-set.doc.mjs +3 -3
- package/clients/cli/commands/experimental-icon-use.doc.mjs +1 -1
- package/clients/cli/commands/experimental-icon.doc.mjs +6 -6
- package/clients/cli/commands/experimental.doc.mjs +2 -6
- package/clients/cli/commands/template.mjs +1 -1
- package/clients/cli/commands/theme-build.doc.mjs +8 -1
- package/clients/cli/commands/theme-palette-generate.doc.mjs +1 -1
- package/clients/cli/commands/theme-remove.doc.mjs +1 -1
- package/clients/cli/commands/theme.doc.mjs +1 -11
- package/clients/cli/commands/theme.mjs +110 -475
- package/clients/cli/commands.generated.json +1 -1
- package/clients/cli/index.mjs +4 -34
- package/clients/cli/lib/base-gate.mjs +2 -3
- package/clients/cli/lib/cli-error.mjs +8 -72
- package/clients/cli/lib/define-command.mjs +0 -19
- package/clients/cli/lib/json-shim.mjs +11 -633
- package/clients/cli/lib/manifest.mjs +0 -4
- package/clients/cli/lib/stray-option.mjs +1 -2
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/color/css-color.mjs +2 -3
- package/foundation/discovery/app-layout.d.mts +13 -0
- package/foundation/discovery/app-layout.mjs +35 -0
- package/foundation/discovery/cli-self-docs.mjs +4 -4
- package/foundation/discovery/fixture-refs.d.mts +51 -0
- package/foundation/discovery/fixture-refs.mjs +351 -0
- package/foundation/discovery/icon-definition-discovery.mjs +7 -7
- package/foundation/discovery/icon-ranking.mjs +2 -2
- package/foundation/discovery/icon-set-checks.mjs +6 -6
- package/foundation/discovery/icon-set-discovery.mjs +2 -2
- package/foundation/discovery/icon-set-writer.d.mts +24 -7
- package/foundation/discovery/icon-set-writer.mjs +75 -31
- package/foundation/discovery/static-descriptor.d.mts +49 -0
- package/foundation/discovery/static-descriptor.mjs +548 -0
- package/foundation/discovery/template-adapter.d.mts +0 -47
- package/foundation/discovery/template-adapter.mjs +1 -333
- package/foundation/discovery/theme-discovery.d.mts +6 -47
- package/foundation/discovery/theme-discovery.mjs +15 -537
- package/foundation/doc-compiler/bundle.mjs +2 -2
- package/foundation/doc-compiler/import.mjs +1 -1
- package/foundation/env/user-dirs.d.mts +5 -2
- package/foundation/env/user-dirs.mjs +12 -5
- package/foundation/fonts/next-font.d.mts +26 -0
- package/foundation/fonts/next-font.mjs +149 -0
- package/foundation/fs/empty-folder.mjs +2 -2
- package/foundation/fs/read-record.mjs +11 -4
- package/foundation/pictures/pictures.d.mts +152 -0
- package/foundation/pictures/pictures.mjs +565 -0
- package/foundation/release/folder-lock.mjs +3 -2
- package/foundation/render/cut-short.d.mts +2 -2
- package/foundation/render/cut-short.mjs +2 -2
- package/foundation/render/drawn-contrast.d.mts +2 -2
- package/foundation/render/drawn-contrast.mjs +2 -2
- package/foundation/render/font-probe.d.mts +2 -2
- package/foundation/render/font-probe.mjs +2 -2
- package/foundation/render/layers.mjs +1 -2
- package/foundation/render/package-resolve-hooks.d.mts +25 -5
- package/foundation/render/package-resolve-hooks.mjs +77 -14
- package/foundation/render/page-worker.mjs +24 -12
- package/foundation/render/part-boxes.d.mts +2 -3
- package/foundation/render/part-boxes.mjs +2 -3
- package/foundation/render/picture-chrome.mjs +18 -15
- package/foundation/render/picture-playwright.mjs +10 -7
- package/foundation/render/picture-window.d.mts +13 -0
- package/foundation/render/picture-window.mjs +31 -0
- package/foundation/render/render-page.d.mts +1 -1
- package/foundation/render/render-page.mjs +4 -5
- package/foundation/render/single-copy-hooks.d.mts +2 -0
- package/foundation/render/single-copy-hooks.mjs +2 -0
- package/foundation/response/error-codes.doc.mjs +14 -14
- package/foundation/response/error-codes.mjs +13 -13
- package/foundation/response/response-types.doc.mjs +8 -69
- package/foundation/runtime/css-tree.mjs +2 -2
- package/foundation/runtime/word-table.d.mts +1 -1
- package/foundation/runtime/word-table.mjs +1 -1
- package/foundation/suggest/other-command.d.mts +52 -15
- package/foundation/suggest/other-command.mjs +168 -45
- package/foundation/text/suggest-order.d.mts +7 -0
- package/foundation/text/suggest-order.mjs +1 -1
- package/package.json +7 -8
- package/api/theme-edit/_adapter.d.mts +0 -228
- package/api/theme-edit/_adapter.mjs +0 -2025
- package/api/theme-edit/_catalog.d.mts +0 -172
- package/api/theme-edit/_catalog.mjs +0 -806
- package/api/theme-edit/_check.d.mts +0 -391
- package/api/theme-edit/_check.mjs +0 -9370
- package/api/theme-edit/_color.d.mts +0 -135
- package/api/theme-edit/_color.mjs +0 -480
- package/api/theme-edit/_compiler.d.mts +0 -77
- package/api/theme-edit/_compiler.mjs +0 -1053
- package/api/theme-edit/_context.d.mts +0 -399
- package/api/theme-edit/_context.mjs +0 -1778
- package/api/theme-edit/_css.d.mts +0 -169
- package/api/theme-edit/_css.mjs +0 -1167
- package/api/theme-edit/_edit.d.mts +0 -167
- package/api/theme-edit/_edit.mjs +0 -11220
- package/api/theme-edit/_how-commands.d.mts +0 -315
- package/api/theme-edit/_how-commands.mjs +0 -1664
- package/api/theme-edit/_how-question.d.mts +0 -341
- package/api/theme-edit/_how-question.mjs +0 -33291
- package/api/theme-edit/_how-sides.d.mts +0 -22
- package/api/theme-edit/_how-sides.mjs +0 -173
- package/api/theme-edit/_how-steps.d.mts +0 -42
- package/api/theme-edit/_how-steps.mjs +0 -208
- package/api/theme-edit/_how-values.d.mts +0 -29
- package/api/theme-edit/_how-values.mjs +0 -111
- package/api/theme-edit/_how-words.d.mts +0 -15
- package/api/theme-edit/_how-words.mjs +0 -239
- package/api/theme-edit/_how.d.mts +0 -55
- package/api/theme-edit/_how.mjs +0 -2388
- package/api/theme-edit/_importers.d.mts +0 -38
- package/api/theme-edit/_importers.mjs +0 -188
- package/api/theme-edit/_marks.d.mts +0 -39
- package/api/theme-edit/_marks.mjs +0 -67
- package/api/theme-edit/_missed.d.mts +0 -56
- package/api/theme-edit/_missed.mjs +0 -1128
- package/api/theme-edit/_name-rule.d.mts +0 -11
- package/api/theme-edit/_name-rule.mjs +0 -12
- package/api/theme-edit/_normal.d.mts +0 -365
- package/api/theme-edit/_normal.mjs +0 -1978
- package/api/theme-edit/_overview.d.mts +0 -9
- package/api/theme-edit/_overview.mjs +0 -293
- package/api/theme-edit/_palette.d.mts +0 -616
- package/api/theme-edit/_palette.mjs +0 -2776
- package/api/theme-edit/_part-pieces.d.mts +0 -54
- package/api/theme-edit/_part-pieces.mjs +0 -179
- package/api/theme-edit/_part-words.d.mts +0 -39
- package/api/theme-edit/_part-words.mjs +0 -242
- package/api/theme-edit/_parts.d.mts +0 -402
- package/api/theme-edit/_parts.mjs +0 -2294
- package/api/theme-edit/_picture-traits.d.mts +0 -259
- package/api/theme-edit/_picture-traits.mjs +0 -1030
- package/api/theme-edit/_png.d.mts +0 -94
- package/api/theme-edit/_png.mjs +0 -479
- package/api/theme-edit/_preview-app.d.mts +0 -172
- package/api/theme-edit/_preview-app.mjs +0 -6430
- package/api/theme-edit/_preview.d.mts +0 -549
- package/api/theme-edit/_preview.mjs +0 -3264
- package/api/theme-edit/_project.d.mts +0 -207
- package/api/theme-edit/_project.mjs +0 -643
- package/api/theme-edit/_resolved.d.mts +0 -46
- package/api/theme-edit/_resolved.mjs +0 -800
- package/api/theme-edit/_set-line.d.mts +0 -29
- package/api/theme-edit/_set-line.mjs +0 -100
- package/api/theme-edit/_settings.d.mts +0 -2426
- package/api/theme-edit/_settings.mjs +0 -18435
- package/api/theme-edit/_tables.d.mts +0 -227
- package/api/theme-edit/_tables.mjs +0 -1128
- package/api/theme-edit/_text-looks.d.mts +0 -78
- package/api/theme-edit/_text-looks.mjs +0 -376
- package/api/theme-edit/_vet.d.mts +0 -50
- package/api/theme-edit/_vet.mjs +0 -166
- package/api/theme-edit/how/how.d.mts +0 -17
- package/api/theme-edit/how/how.mjs +0 -28
- package/api/theme-edit/new/new.d.mts +0 -11
- package/api/theme-edit/new/new.mjs +0 -22
- package/api/theme-edit/preview-add/preview-add.d.mts +0 -14
- package/api/theme-edit/preview-add/preview-add.mjs +0 -25
- package/api/theme-edit/preview-app/preview-app.d.mts +0 -13
- package/api/theme-edit/preview-app/preview-app.mjs +0 -24
- package/api/theme-edit/preview-list/preview-list.d.mts +0 -10
- package/api/theme-edit/preview-list/preview-list.mjs +0 -21
- package/api/theme-edit/preview-remove/preview-remove.d.mts +0 -12
- package/api/theme-edit/preview-remove/preview-remove.mjs +0 -23
- package/api/theme-edit/set/set.d.mts +0 -13
- package/api/theme-edit/set/set.mjs +0 -24
- package/api/theme-edit/show/show.d.mts +0 -13
- package/api/theme-edit/show/show.mjs +0 -24
- package/api/theme-edit/theme-edit.d.mts +0 -12
- package/api/theme-edit/theme-edit.mjs +0 -36
- package/api/theme-edit/theme-edit.type.d.mts +0 -730
- package/api/theme-edit/theme-edit.type.mjs +0 -342
- package/api/theme-edit/themeEditHow.doc.d.mts +0 -6
- package/api/theme-edit/themeEditHow.doc.mjs +0 -105
- package/api/theme-edit/themeEditNew.doc.d.mts +0 -5
- package/api/theme-edit/themeEditNew.doc.mjs +0 -112
- package/api/theme-edit/themeEditPreviewAdd.doc.d.mts +0 -6
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +0 -121
- package/api/theme-edit/themeEditPreviewApp.doc.d.mts +0 -6
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +0 -87
- package/api/theme-edit/themeEditPreviewList.doc.d.mts +0 -6
- package/api/theme-edit/themeEditPreviewList.doc.mjs +0 -62
- package/api/theme-edit/themeEditPreviewRemove.doc.d.mts +0 -6
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +0 -96
- package/api/theme-edit/themeEditSet.doc.d.mts +0 -6
- package/api/theme-edit/themeEditSet.doc.mjs +0 -175
- package/api/theme-edit/themeEditShow.doc.d.mts +0 -6
- package/api/theme-edit/themeEditShow.doc.mjs +0 -118
- package/api/theme-edit/themeEditUndo.doc.d.mts +0 -6
- package/api/theme-edit/themeEditUndo.doc.mjs +0 -133
- package/api/theme-edit/undo/undo.d.mts +0 -13
- package/api/theme-edit/undo/undo.mjs +0 -24
- package/assets/preview-app/README.md +0 -6
- package/assets/preview-app/css.d.ts +0 -5
- package/assets/preview-app/gitignore +0 -4
- package/assets/preview-app/next.config.mjs +0 -12
- package/assets/preview-app/package.json +0 -24
- package/assets/preview-app/src/app/globals.css +0 -6
- package/assets/preview-app/src/app/layout.tsx +0 -21
- package/assets/preview-app/src/app/page.tsx +0 -94
- package/assets/preview-app/src/app/providers.tsx +0 -16
- package/assets/preview-app/tsconfig.json +0 -27
- package/clients/cli/commands/experimental/theme.mjs +0 -2990
- package/clients/cli/commands/experimental-theme-add.doc.mjs +0 -80
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +0 -98
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +0 -196
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +0 -174
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +0 -139
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +0 -77
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +0 -105
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +0 -49
- package/clients/cli/commands/experimental-theme-eject.doc.mjs +0 -72
- package/clients/cli/commands/experimental-theme-list.doc.mjs +0 -49
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +0 -88
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +0 -61
- package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +0 -48
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +0 -59
- package/clients/cli/commands/experimental-theme-preview.doc.mjs +0 -41
- package/clients/cli/commands/experimental-theme-remove.doc.mjs +0 -57
- package/clients/cli/commands/experimental-theme-targets.doc.mjs +0 -62
- package/clients/cli/commands/experimental-theme-template.doc.mjs +0 -63
- package/clients/cli/commands/experimental-theme-use.doc.mjs +0 -57
- package/clients/cli/commands/experimental-theme.doc.mjs +0 -60
- package/foundation/fonts/fontsource-families.generated.d.mts +0 -5
- package/foundation/fonts/fontsource-families.generated.mjs +0 -2110
|
@@ -1,1778 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @file What every theme-edit operation shares: the project check, the
|
|
5
|
-
* loaded project with its part data and compiler, pictures, font
|
|
6
|
-
* notes, the styles a change wrote, and the preview after a change.
|
|
7
|
-
*
|
|
8
|
-
* @position api/theme-edit — imported only by the adapter's operation helpers
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import {createHash} from 'node:crypto';
|
|
12
|
-
import * as fs from 'node:fs';
|
|
13
|
-
import {createRequire} from 'node:module';
|
|
14
|
-
import * as path from 'node:path';
|
|
15
|
-
import {pathToFileURL} from 'node:url';
|
|
16
|
-
import {AstryxError} from '../error.mjs';
|
|
17
|
-
import {
|
|
18
|
-
EDITOR_STAMP,
|
|
19
|
-
withPngText,
|
|
20
|
-
decodePng,
|
|
21
|
-
encodePng,
|
|
22
|
-
cutTall,
|
|
23
|
-
} from './_png.mjs';
|
|
24
|
-
import {
|
|
25
|
-
findDeclaredWorkspaceRoot,
|
|
26
|
-
findNodeModulesPackage,
|
|
27
|
-
homeFolder,
|
|
28
|
-
} from '../../foundation/fs/paths.mjs';
|
|
29
|
-
import {
|
|
30
|
-
detectPackageManager,
|
|
31
|
-
quoteCommandArgument,
|
|
32
|
-
} from '../../foundation/env/package-manager.mjs';
|
|
33
|
-
import {
|
|
34
|
-
CLOSEST_OPEN_FONT,
|
|
35
|
-
FONT_ROLES,
|
|
36
|
-
FONTS,
|
|
37
|
-
OPEN_FONTS,
|
|
38
|
-
appleFaceGeneric,
|
|
39
|
-
isDesktopFamily,
|
|
40
|
-
oneSystemOf,
|
|
41
|
-
P,
|
|
42
|
-
SYSTEM_FONTS,
|
|
43
|
-
} from './_tables.mjs';
|
|
44
|
-
import {makeCompiler} from './_compiler.mjs';
|
|
45
|
-
import {openProject, installLine, refusePlugAndPlay} from './_project.mjs';
|
|
46
|
-
import {addCensusStates, partData} from './_parts.mjs';
|
|
47
|
-
import {writeWhole} from './_palette.mjs';
|
|
48
|
-
import {
|
|
49
|
-
assetRef,
|
|
50
|
-
CSS_URL,
|
|
51
|
-
cssUrlRef,
|
|
52
|
-
} from '../../foundation/render/render-page.mjs';
|
|
53
|
-
import {MAX_ASSET_BYTES} from '../../foundation/render/assets.mjs';
|
|
54
|
-
import {typoNear} from './_normal.mjs';
|
|
55
|
-
import {
|
|
56
|
-
fontOf,
|
|
57
|
-
ownTokenEntries,
|
|
58
|
-
builtFontFamilies,
|
|
59
|
-
builtFontWeights,
|
|
60
|
-
fontPackages,
|
|
61
|
-
fontsourceSuggestion,
|
|
62
|
-
modesOf,
|
|
63
|
-
refuse,
|
|
64
|
-
editorWrote,
|
|
65
|
-
editorRecorded,
|
|
66
|
-
recordWritten,
|
|
67
|
-
themeFiles,
|
|
68
|
-
refuseThemesNotFolder,
|
|
69
|
-
shown,
|
|
70
|
-
OPEN_SECTION,
|
|
71
|
-
} from './_settings.mjs';
|
|
72
|
-
import {
|
|
73
|
-
SHOWCASE_GROUPS,
|
|
74
|
-
copyFontsCss,
|
|
75
|
-
fontPackageSheets,
|
|
76
|
-
fontPackageWeights,
|
|
77
|
-
shownWeight,
|
|
78
|
-
baseFontsSheet,
|
|
79
|
-
newPictureRun,
|
|
80
|
-
renderPreview,
|
|
81
|
-
renderSheet,
|
|
82
|
-
screenshots,
|
|
83
|
-
pageInTheWay,
|
|
84
|
-
inTheWayPhrase,
|
|
85
|
-
} from './_preview.mjs';
|
|
86
|
-
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
87
|
-
import {
|
|
88
|
-
customPropertyValues,
|
|
89
|
-
fontKey,
|
|
90
|
-
importedFontFamilies,
|
|
91
|
-
} from '../../foundation/fonts/font-stylesheet.mjs';
|
|
92
|
-
import {
|
|
93
|
-
hasGenericFamily,
|
|
94
|
-
namedFontFamilies,
|
|
95
|
-
} from '../theme/build/font-warning.mjs';
|
|
96
|
-
|
|
97
|
-
const E = ERROR_CODES;
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Refuse outside a project: a theme is written into an app, and every check
|
|
101
|
-
* reads the app's own Core.
|
|
102
|
-
* @param {string} cwd
|
|
103
|
-
*/
|
|
104
|
-
export function requireProject(cwd) {
|
|
105
|
-
// One rule: the app is the nearest folder at or above cwd whose
|
|
106
|
-
// package.json lists @astryxdesign/core.
|
|
107
|
-
const app = coreApp(cwd);
|
|
108
|
-
if (!app) refuseNoApp(cwd);
|
|
109
|
-
refusePlugAndPlay(app);
|
|
110
|
-
if (findNodeModulesPackage(app, '@astryxdesign/core')) return;
|
|
111
|
-
// The app lists Core but it is not installed.
|
|
112
|
-
throw new AstryxError(
|
|
113
|
-
`${path.relative(path.resolve(cwd), app) || 'This app'}'s package.json lists @astryxdesign/core, but it is not installed. astryx experimental theme checks every change against the installed Core: install the app's packages, then run the command again. Nothing was written.`,
|
|
114
|
-
[{name: installAll(app), reason: 'do this first, in the app'}],
|
|
115
|
-
E.ERR_PROJECT_REQUIRED,
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* The project, its part data and the compiler. When the components cannot
|
|
121
|
-
* be rendered, the part data is empty and `unchecked` says why: changes are
|
|
122
|
-
* then saved without the checks that need it, and say so.
|
|
123
|
-
* @param {string} cwd
|
|
124
|
-
*/
|
|
125
|
-
export async function context(cwd) {
|
|
126
|
-
requireProject(cwd);
|
|
127
|
-
refuseThemesNotFolder(cwd);
|
|
128
|
-
const project = await openProject(cwd);
|
|
129
|
-
/** @type {import('./_parts.mjs').PartData} */
|
|
130
|
-
let parts;
|
|
131
|
-
/** @type {string | null} */
|
|
132
|
-
let unchecked = null;
|
|
133
|
-
/** @type {string | null} the render error's code */
|
|
134
|
-
let uncheckedCode = null;
|
|
135
|
-
try {
|
|
136
|
-
parts = await partData(project);
|
|
137
|
-
addCensusStates(project, parts);
|
|
138
|
-
} catch (e) {
|
|
139
|
-
if (!isRenderFailure(e)) throw e;
|
|
140
|
-
unchecked = renderCause(project, /** @type {Error} */ (e).message);
|
|
141
|
-
uncheckedCode = /** @type {any} */ (e).code ?? null;
|
|
142
|
-
parts = {
|
|
143
|
-
censusKey: '',
|
|
144
|
-
coreKey: project.coreKey,
|
|
145
|
-
map: {},
|
|
146
|
-
pairs: [],
|
|
147
|
-
rendered: 0,
|
|
148
|
-
items: 0,
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
return {
|
|
152
|
-
project,
|
|
153
|
-
C: makeCompiler(project, parts),
|
|
154
|
-
parts,
|
|
155
|
-
unchecked,
|
|
156
|
-
uncheckedCode,
|
|
157
|
-
derived: await derivedVars(project.coreDir),
|
|
158
|
-
/**
|
|
159
|
-
* The pictures the running command takes after its build (its --png),
|
|
160
|
-
* so the build names as removed only the ones it does not take again.
|
|
161
|
-
* @type {{sheet: string | null} | null}
|
|
162
|
-
*/
|
|
163
|
-
takesPictures: null,
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Core's registry of the variables a part's plain border-radius or padding
|
|
169
|
-
* also writes (a card's inner corners), or empty on a Core without it.
|
|
170
|
-
* @param {string} coreDir
|
|
171
|
-
* @returns {Promise<Record<string, Array<{property: string, vars?: string[], replaces?: boolean, expand?: string, corners?: boolean}>>>}
|
|
172
|
-
*/
|
|
173
|
-
async function derivedVars(coreDir) {
|
|
174
|
-
const file = path.join(coreDir, 'dist', 'theme', 'derivedVarRegistry.js');
|
|
175
|
-
if (!fs.existsSync(file)) return {};
|
|
176
|
-
try {
|
|
177
|
-
const mod = await import(pathToFileURL(file).href);
|
|
178
|
-
return mod.derivedVarRegistry ?? {};
|
|
179
|
-
} catch {
|
|
180
|
-
return {};
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/** @param {unknown} e */
|
|
185
|
-
const isRenderFailure = e =>
|
|
186
|
-
e instanceof AstryxError &&
|
|
187
|
-
(e.code === E.ERR_RENDER_FAILED ||
|
|
188
|
-
e.code === E.ERR_RENDER_MISSING_DEPENDENCY ||
|
|
189
|
-
e.code === E.ERR_RENDER_ASSET_TOO_LARGE);
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* The app a folder belongs to: the nearest folder at or above it whose
|
|
193
|
-
* package.json lists @astryxdesign/core (dependencies, devDependencies or
|
|
194
|
-
* peerDependencies), never the home folder; null when there is none.
|
|
195
|
-
* @param {string} cwd
|
|
196
|
-
* @returns {string | null}
|
|
197
|
-
*/
|
|
198
|
-
export function coreApp(cwd) {
|
|
199
|
-
const home = homeFolder();
|
|
200
|
-
let dir = path.resolve(cwd);
|
|
201
|
-
// An installed package is never the app: resume above the outermost
|
|
202
|
-
// node_modules.
|
|
203
|
-
const nm = dir.split(path.sep).indexOf('node_modules');
|
|
204
|
-
if (nm > 0) dir = dir.split(path.sep).slice(0, nm).join(path.sep) || path.sep;
|
|
205
|
-
// A repository below the home folder is its own project: the home folder
|
|
206
|
-
// is the app only when the search did not come up out of another repo.
|
|
207
|
-
let crossedRepo = false;
|
|
208
|
-
for (;;) {
|
|
209
|
-
const listsCore = usesCore(readJson(path.join(dir, 'package.json')));
|
|
210
|
-
if (home && dir === home) return listsCore && !crossedRepo ? dir : null;
|
|
211
|
-
if (listsCore) return dir;
|
|
212
|
-
if (fs.existsSync(path.join(dir, '.git'))) crossedRepo = true;
|
|
213
|
-
const up = path.dirname(dir);
|
|
214
|
-
if (up === dir) return null;
|
|
215
|
-
dir = up;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* The command that installs an app's packages, in its package manager.
|
|
221
|
-
* @param {string} dir
|
|
222
|
-
*/
|
|
223
|
-
function installAll(dir) {
|
|
224
|
-
const pm = detectPackageManager(dir);
|
|
225
|
-
return pm === 'npm' || pm === 'npx' ? 'npm install' : `${pm} install`;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Refuse a folder no app above lists Core for: say where Core resolves
|
|
230
|
-
* from (when it does) and, inside a workspace, name the folders below its
|
|
231
|
-
* root whose package.json lists Core, each with the `cd` to run from.
|
|
232
|
-
* @param {string} cwd
|
|
233
|
-
* @returns {never}
|
|
234
|
-
*/
|
|
235
|
-
function refuseNoApp(cwd) {
|
|
236
|
-
const start = path.resolve(cwd);
|
|
237
|
-
// A repository inside a home-folder app (a submodule, a vendored clone) is
|
|
238
|
-
// its own project: name the app above instead of claiming there is none.
|
|
239
|
-
const home = homeFolder();
|
|
240
|
-
if (
|
|
241
|
-
home &&
|
|
242
|
-
!path.relative(home, start).startsWith('..') &&
|
|
243
|
-
usesCore(readJson(path.join(home, 'package.json')))
|
|
244
|
-
) {
|
|
245
|
-
const rel = path.relative(start, home) || '.';
|
|
246
|
-
throw new AstryxError(
|
|
247
|
-
`This folder is inside its own repository, below the app at ${rel} (your home folder): the theme editor does not reach out of a repository into an app around it. Run the command from the app. Nothing was written.`,
|
|
248
|
-
[
|
|
249
|
-
{
|
|
250
|
-
name: `cd ${quoteCommandArgument(rel)}`,
|
|
251
|
-
reason: 'run the command from the app',
|
|
252
|
-
},
|
|
253
|
-
],
|
|
254
|
-
E.ERR_PROJECT_REQUIRED,
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
// Where Core resolves from: the nearest node_modules above that holds it.
|
|
258
|
-
const resolved =
|
|
259
|
-
findNodeModulesPackage(start, '@astryxdesign/core')?.packageDir ?? null;
|
|
260
|
-
const root = findDeclaredWorkspaceRoot(start);
|
|
261
|
-
const where = resolved
|
|
262
|
-
? ` @astryxdesign/core resolves from ${path.relative(start, resolved) || '.'}, but the theme editor needs the app's package.json to list it.`
|
|
263
|
-
: '';
|
|
264
|
-
if (root) {
|
|
265
|
-
const apps = appsBelow(root)
|
|
266
|
-
.map(a => path.relative(start, a) || '.')
|
|
267
|
-
.sort();
|
|
268
|
-
throw new AstryxError(
|
|
269
|
-
`${path.relative(start, root) || 'This folder'} is a workspace root${root === start ? '' : ` (${path.relative(root, start)} is not an app that uses @astryxdesign/core)`}, not an app: a theme belongs in an app whose package.json lists @astryxdesign/core.${where}${apps.length ? ` The workspace's apps that use it: ${apps.join(', ')}.` : ''} Run the command from the app that uses it. Nothing was written.`,
|
|
270
|
-
apps.slice(0, 4).map(a => ({
|
|
271
|
-
name: `cd ${quoteCommandArgument(a.startsWith('-') ? `./${a}` : a)}`,
|
|
272
|
-
reason: 'run the command from this app',
|
|
273
|
-
})),
|
|
274
|
-
E.ERR_PROJECT_REQUIRED,
|
|
275
|
-
);
|
|
276
|
-
}
|
|
277
|
-
if (fs.existsSync(path.join(start, 'package.json')) || resolved)
|
|
278
|
-
throw new AstryxError(
|
|
279
|
-
`${fs.existsSync(path.join(start, 'package.json')) ? '@astryxdesign/core is not installed in this app (package.json here does not use it).' : 'No package.json at or above this folder lists @astryxdesign/core.'}${where} astryx experimental theme checks every change against the installed Core: install it, or run the command from the package that uses it. Nothing was written.`,
|
|
280
|
-
[
|
|
281
|
-
{
|
|
282
|
-
name: installLine(start, ['@astryxdesign/core']),
|
|
283
|
-
reason: 'do this first',
|
|
284
|
-
},
|
|
285
|
-
],
|
|
286
|
-
E.ERR_PROJECT_REQUIRED,
|
|
287
|
-
);
|
|
288
|
-
throw new AstryxError(
|
|
289
|
-
'No package.json found. astryx experimental theme works inside an app project, which it writes the theme into and whose installed Core it checks every change against. Nothing was written.',
|
|
290
|
-
[
|
|
291
|
-
{
|
|
292
|
-
name: 'npm init -y',
|
|
293
|
-
reason: 'make a package.json here, then install @astryxdesign/core',
|
|
294
|
-
},
|
|
295
|
-
],
|
|
296
|
-
E.ERR_PROJECT_REQUIRED,
|
|
297
|
-
);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* The folders below a workspace root, up to three levels deep (node_modules
|
|
302
|
-
* and dot folders skipped), whose package.json lists Core.
|
|
303
|
-
* @param {string} root
|
|
304
|
-
* @returns {string[]}
|
|
305
|
-
*/
|
|
306
|
-
function appsBelow(root) {
|
|
307
|
-
/** @type {string[]} */
|
|
308
|
-
const out = [];
|
|
309
|
-
/** @param {string} dir @param {number} depth */
|
|
310
|
-
const walk = (dir, depth) => {
|
|
311
|
-
if (depth > 6) return;
|
|
312
|
-
/** @type {fs.Dirent[]} */
|
|
313
|
-
let entries;
|
|
314
|
-
try {
|
|
315
|
-
entries = fs.readdirSync(dir, {withFileTypes: true});
|
|
316
|
-
} catch {
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
for (const e of entries) {
|
|
320
|
-
if (
|
|
321
|
-
!e.isDirectory() ||
|
|
322
|
-
e.name === 'node_modules' ||
|
|
323
|
-
e.name.startsWith('.')
|
|
324
|
-
)
|
|
325
|
-
continue;
|
|
326
|
-
const sub = path.join(dir, e.name);
|
|
327
|
-
if (usesCore(readJson(path.join(sub, 'package.json')))) out.push(sub);
|
|
328
|
-
walk(sub, depth + 1);
|
|
329
|
-
}
|
|
330
|
-
};
|
|
331
|
-
walk(root, 1);
|
|
332
|
-
return out;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/** @param {string} file */
|
|
336
|
-
function readJson(file) {
|
|
337
|
-
try {
|
|
338
|
-
return JSON.parse(fs.readFileSync(file, 'utf8').replace(/^\uFEFF/, ''));
|
|
339
|
-
} catch {
|
|
340
|
-
return null;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/** Whether a package.json lists @astryxdesign/core itself. */
|
|
345
|
-
function usesCore(/** @type {any} */ json) {
|
|
346
|
-
if (!json || typeof json !== 'object') return false;
|
|
347
|
-
return ['dependencies', 'devDependencies', 'peerDependencies'].some(
|
|
348
|
-
k =>
|
|
349
|
-
json[k] != null &&
|
|
350
|
-
typeof json[k] === 'object' &&
|
|
351
|
-
!Array.isArray(json[k]) &&
|
|
352
|
-
Object.prototype.hasOwnProperty.call(json[k], '@astryxdesign/core'),
|
|
353
|
-
);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
/**
|
|
357
|
-
* Why the components did not render, with the likely cause: two copies of
|
|
358
|
-
* React (the app's and the one Core resolves) break every hook.
|
|
359
|
-
* @param {import('./_project.mjs').ThemeProject} project
|
|
360
|
-
* @param {string} message
|
|
361
|
-
*/
|
|
362
|
-
export function renderCause(project, message) {
|
|
363
|
-
const two = reactCopies(project);
|
|
364
|
-
return two
|
|
365
|
-
? `${message} The likely cause: two copies of React, the app's (${two.app}) and the one Core resolves (${two.core}). Make Core resolve the app's React.`
|
|
366
|
-
: message;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
/**
|
|
370
|
-
* The two copies of React a render saw, when the app's and the one Core
|
|
371
|
-
* resolves differ; else null.
|
|
372
|
-
* @param {import('./_project.mjs').ThemeProject} project
|
|
373
|
-
* @returns {{app: string, core: string} | null}
|
|
374
|
-
*/
|
|
375
|
-
export function reactCopies(project) {
|
|
376
|
-
/** @param {(id: string) => string} resolve */
|
|
377
|
-
const reactOf = resolve => {
|
|
378
|
-
try {
|
|
379
|
-
return fs.realpathSync(path.dirname(resolve('react/package.json')));
|
|
380
|
-
} catch {
|
|
381
|
-
return null;
|
|
382
|
-
}
|
|
383
|
-
};
|
|
384
|
-
const app = reactOf(project.req.resolve);
|
|
385
|
-
let core = null;
|
|
386
|
-
try {
|
|
387
|
-
// Core's exports keep its package.json private: its folder is found by
|
|
388
|
-
// walking up from the entry the app resolves.
|
|
389
|
-
let dir = path.dirname(project.req.resolve('@astryxdesign/core'));
|
|
390
|
-
while (!fs.existsSync(path.join(dir, 'package.json'))) {
|
|
391
|
-
const up = path.dirname(dir);
|
|
392
|
-
if (up === dir) throw new Error('no package.json');
|
|
393
|
-
dir = up;
|
|
394
|
-
}
|
|
395
|
-
core = reactOf(createRequire(path.join(dir, 'package.json')).resolve);
|
|
396
|
-
} catch {
|
|
397
|
-
// No Core package file: nothing to compare.
|
|
398
|
-
}
|
|
399
|
-
return app && core && app !== core ? {app, core} : null;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
/**
|
|
403
|
-
* The "saved, not checked" report of a change, or null when it was checked.
|
|
404
|
-
* @param {string | null} cause
|
|
405
|
-
*/
|
|
406
|
-
const notChecked = cause =>
|
|
407
|
-
cause ? {code: E.ERR_THEME_NOT_CHECKED, cause} : null;
|
|
408
|
-
|
|
409
|
-
/** The sample page, as a note about its pictures names it. */
|
|
410
|
-
export const SAMPLE_PAGE_NAME = 'the sample page';
|
|
411
|
-
|
|
412
|
-
/**
|
|
413
|
-
* Text one page's pictures draw cut short in one part, as the browser
|
|
414
|
-
* measured it: the page and its picture, the part (null when the text sits
|
|
415
|
-
* in none), its texts, the one mode it was cut in when only one was, and
|
|
416
|
-
* whether every text is drawn whole once the part keeps its width
|
|
417
|
-
* (`flex-shrink: 0`, applied in the page and measured). `broken`: the
|
|
418
|
-
* texts are words drawn broken across two lines inside the word, not cut.
|
|
419
|
-
* `overlaps`: the texts run past their own box over a neighbor's text.
|
|
420
|
-
* @typedef {{page: string, file: string, part: string | null, texts: string[], only: 'light' | 'dark' | null, whole: boolean, broken?: boolean, overlaps?: boolean}} CutShort
|
|
421
|
-
*/
|
|
422
|
-
|
|
423
|
-
/** The texts named, the first six and how many more. @param {string[]} texts */
|
|
424
|
-
const someTexts = texts =>
|
|
425
|
-
`${texts
|
|
426
|
-
.slice(0, 6)
|
|
427
|
-
.map(t => JSON.stringify(t))
|
|
428
|
-
.join(', ')}${texts.length > 6 ? `, and ${texts.length - 6} more` : ''}`;
|
|
429
|
-
|
|
430
|
-
/**
|
|
431
|
-
* The note for text a page's pictures draw cut short.
|
|
432
|
-
* @param {CutShort} c
|
|
433
|
-
*/
|
|
434
|
-
export function cutShortNote(c) {
|
|
435
|
-
const n = c.texts.length;
|
|
436
|
-
const what = c.part
|
|
437
|
-
? `${c.part} label${n === 1 ? '' : 's'}`
|
|
438
|
-
: `text${n === 1 ? '' : 's'}`;
|
|
439
|
-
if (c.overlaps)
|
|
440
|
-
return `${c.page} (${c.file}) draws ${n} ${what} over the text beside ${n === 1 ? 'it' : 'them'}${c.only ? ` in ${c.only} mode only` : ''} (${someTexts(c.texts)}); the text is wider than the space ${c.part ? `the ${c.part}` : 'its box'} gives it`;
|
|
441
|
-
if (c.broken)
|
|
442
|
-
return `${c.page} (${c.file}) breaks ${n} word${n === 1 ? '' : 's'} across lines inside the word${c.part ? ` in the ${c.part}` : ''}${c.only ? ` in ${c.only} mode only` : ''} (${someTexts(c.texts)}); the word is wider than the space ${c.part ? `the ${c.part}` : 'its box'} has`;
|
|
443
|
-
return `${c.page} (${c.file}) draws ${n} ${what} cut short${c.only ? ` in ${c.only} mode only` : ''} (${someTexts(c.texts)}); the text no longer fits ${c.part ? `the ${c.part}` : 'its box'}`;
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
/**
|
|
447
|
-
* The problem for text a page's pictures draw cut short, with the line that
|
|
448
|
-
* keeps it whole: the part keeps its width (`flex-shrink 0` on it), offered
|
|
449
|
-
* only when the browser measured every text whole with it; else no line,
|
|
450
|
-
* and that the line was measured and does not.
|
|
451
|
-
* @param {import('./_settings.mjs').Ctx} ctx
|
|
452
|
-
* @param {string} slug
|
|
453
|
-
* @param {CutShort} c
|
|
454
|
-
* @returns {{problem: string, fix: string | null}}
|
|
455
|
-
*/
|
|
456
|
-
export function cutShortProblem(ctx, slug, c) {
|
|
457
|
-
const label = c.part ? `${c.part} labels` : 'text';
|
|
458
|
-
const problem = c.overlaps
|
|
459
|
-
? `${label} drawn over the text beside them in ${c.page}'s pictures (${c.file}${c.only ? `, ${c.only} mode` : ''}): ${someTexts(c.texts)}`
|
|
460
|
-
: c.broken
|
|
461
|
-
? `words broken across lines inside the word${c.part ? ` in the ${c.part}` : ''} in ${c.page}'s pictures (${c.file}${c.only ? `, ${c.only} mode` : ''}): ${someTexts(c.texts)}`
|
|
462
|
-
: `${label} cut short in ${c.page}'s pictures (${c.file}${c.only ? `, ${c.only} mode` : ''}): ${someTexts(c.texts)}`;
|
|
463
|
-
if (c.part && c.whole && ctx.project.target.has(c.part))
|
|
464
|
-
return {problem, fix: `${P} set ${slug} flex-shrink 0 --on ${c.part}`};
|
|
465
|
-
return {
|
|
466
|
-
problem: c.part
|
|
467
|
-
? `${problem}; keeping the ${c.part}'s width (flex-shrink 0) was measured and does not draw them whole there, so no one line fixes it`
|
|
468
|
-
: problem,
|
|
469
|
-
fix: null,
|
|
470
|
-
};
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
/**
|
|
474
|
-
* Text a picture draws too faint to read, as the browser measured it: the
|
|
475
|
-
* part it sits in, its text, the mode, its ratio and its two colors, and
|
|
476
|
-
* the page (`page`, null for a sheet) and picture it is on.
|
|
477
|
-
* @typedef {{page: string | null, file: string, part: string, text: string, mode: 'light' | 'dark', ratio: number, fg: string, bg: string}} LowContrast
|
|
478
|
-
*/
|
|
479
|
-
|
|
480
|
-
/**
|
|
481
|
-
* Pictures of HTML files, on request. A shot with a `name` is a page laid
|
|
482
|
-
* out so its text fits in the base theme (the sample page): the text its
|
|
483
|
-
* pictures draw cut short, as the browser measured it, comes back in
|
|
484
|
-
* `cutShort`, one entry for each part on each page ({@link cutShortNote},
|
|
485
|
-
* {@link cutShortProblem}). The sheets (the open
|
|
486
|
-
* states among them) have no name: their cells are narrow, and the full
|
|
487
|
-
* sheet cuts long labels short in every theme, so from a sheet only text
|
|
488
|
-
* drawn over the text beside it comes back.
|
|
489
|
-
* @param {import('./_project.mjs').ThemeProject} project
|
|
490
|
-
* @param {Array<{html: string, png: string, name?: string, most?: number}>} shots
|
|
491
|
-
* `most`: the tallest the page's picture may be; a taller one is cut into
|
|
492
|
-
* pictures that tall, in order ({@link pagesOfPicture})
|
|
493
|
-
* @param {Array<'light' | 'dark'>} modes
|
|
494
|
-
* Every picture also measures the text it draws too faint to read
|
|
495
|
-
* (`lowContrast`): one entry for each part, text, pair of colors and mode,
|
|
496
|
-
* with the page it is on.
|
|
497
|
-
* @returns {Promise<{files: string[], problem: string | null, cutShort: CutShort[], lowContrast: LowContrast[]}>}
|
|
498
|
-
*/
|
|
499
|
-
export async function pictures(project, shots, modes) {
|
|
500
|
-
/** @type {string[]} */
|
|
501
|
-
const files = [];
|
|
502
|
-
/** @type {Map<string, LowContrast>} */
|
|
503
|
-
const faint = new Map();
|
|
504
|
-
const faintNotes = () => [...faint.values()];
|
|
505
|
-
/**
|
|
506
|
-
* The text drawn cut short, by page, then by part: its texts, the modes
|
|
507
|
-
* it was drawn so in, whether keeping the part's width draws every one
|
|
508
|
-
* whole, and the page's picture.
|
|
509
|
-
* Keyed by part, and apart for words broken across lines and for text drawn over its neighbor.
|
|
510
|
-
* @type {Map<string, {label: string, file: string, parts: Map<string, {part: string, broken: boolean, overlaps: boolean, texts: Set<string>, modes: Set<'light' | 'dark'>, whole: boolean}>}>}
|
|
511
|
-
*/
|
|
512
|
-
const cut = new Map();
|
|
513
|
-
/** One entry for each part on each page, from what was measured. */
|
|
514
|
-
const cutShortNotes = () =>
|
|
515
|
-
[...cut].flatMap(([, page]) =>
|
|
516
|
-
[...page.parts.values()].map(
|
|
517
|
-
({part, broken, overlaps, texts, modes: drawnIn, whole}) =>
|
|
518
|
-
/** @type {CutShort} */ ({
|
|
519
|
-
page: page.label,
|
|
520
|
-
file: page.file,
|
|
521
|
-
part: part || null,
|
|
522
|
-
texts: [...texts],
|
|
523
|
-
only:
|
|
524
|
-
modes.length > 1 && drawnIn.size === 1 ? [...drawnIn][0] : null,
|
|
525
|
-
whole,
|
|
526
|
-
...(broken ? {broken: true} : {}),
|
|
527
|
-
...(overlaps ? {overlaps: true} : {}),
|
|
528
|
-
}),
|
|
529
|
-
),
|
|
530
|
-
);
|
|
531
|
-
/** What a later browser's success says of an earlier one. @type {string[]} */
|
|
532
|
-
const notes = [];
|
|
533
|
-
/** One run for every picture: a browser that failed is not tried again. */
|
|
534
|
-
const run = newPictureRun();
|
|
535
|
-
/** @param {string} png @param {'light' | 'dark'} m */
|
|
536
|
-
const outOf = (png, m) =>
|
|
537
|
-
modes.length > 1 && m === 'dark' ? png.replace(/\.png$/, '-dark.png') : png;
|
|
538
|
-
/** The theme a picture's folder is, when it is a theme folder. @param {string} out */
|
|
539
|
-
const themeOf = out => {
|
|
540
|
-
const slug = path.basename(path.dirname(out));
|
|
541
|
-
return path.resolve(path.dirname(out)) ===
|
|
542
|
-
path.resolve(themeFiles(project.cwd, slug).dir)
|
|
543
|
-
? slug
|
|
544
|
-
: null;
|
|
545
|
-
};
|
|
546
|
-
/** A link at a path, whether or not what it points to is there. @param {string} p */
|
|
547
|
-
const isLink = p => {
|
|
548
|
-
try {
|
|
549
|
-
return Boolean(
|
|
550
|
-
fs.lstatSync(p, {throwIfNoEntry: false})?.isSymbolicLink(),
|
|
551
|
-
);
|
|
552
|
-
} catch {
|
|
553
|
-
return false;
|
|
554
|
-
}
|
|
555
|
-
};
|
|
556
|
-
// A picture is written only over a picture the editor took, unchanged
|
|
557
|
-
// since: a file of the user's by that name (a screenshot of the same
|
|
558
|
-
// size included) blocks every picture, and is named. A link at a
|
|
559
|
-
// picture's name (to a file or to nothing) is never written through or
|
|
560
|
-
// replaced: that one picture is skipped and named, the others are taken.
|
|
561
|
-
const blocked = shots
|
|
562
|
-
.flatMap(({png}) => modes.map(m => outOf(png, m)))
|
|
563
|
-
.filter(out => {
|
|
564
|
-
const slug = themeOf(out);
|
|
565
|
-
return (
|
|
566
|
-
Boolean(slug) &&
|
|
567
|
-
!isLink(out) &&
|
|
568
|
-
fs.existsSync(out) &&
|
|
569
|
-
!editorWrote(project.cwd, /** @type {string} */ (slug), out)
|
|
570
|
-
);
|
|
571
|
-
});
|
|
572
|
-
// The record of the editor's pictures is a plain file, or none yet.
|
|
573
|
-
// Something else at its name (a pipe, a folder) is left as it is and
|
|
574
|
-
// named, and no picture is taken: a picture the record cannot hold would
|
|
575
|
-
// read as a file of yours on the next run.
|
|
576
|
-
for (const slug of new Set(shots.map(s => themeOf(s.png)))) {
|
|
577
|
-
if (!slug) continue;
|
|
578
|
-
const record = themeFiles(project.cwd, slug).pictures;
|
|
579
|
-
const st = fs.lstatSync(record, {throwIfNoEntry: false});
|
|
580
|
-
if (st && !st.isFile())
|
|
581
|
-
return {
|
|
582
|
-
files,
|
|
583
|
-
cutShort: [],
|
|
584
|
-
lowContrast: [],
|
|
585
|
-
problem: `${inTheWayPhrase(path.relative(project.cwd, record), st.isSymbolicLink() ? 'link' : st.isDirectory() ? 'folder' : 'other', "the record of the editor's pictures")}, so no picture was taken and it is left as it is; move ${st.isSymbolicLink() ? 'the link' : 'it'}, then run the command again`,
|
|
586
|
-
};
|
|
587
|
-
}
|
|
588
|
-
/** Pictures skipped for a link at their name. @type {string[]} */
|
|
589
|
-
const linked = [];
|
|
590
|
-
if (blocked.length)
|
|
591
|
-
return {
|
|
592
|
-
files,
|
|
593
|
-
cutShort: [],
|
|
594
|
-
lowContrast: [],
|
|
595
|
-
problem: `${blocked.map(f => path.relative(project.cwd, f)).join(', ')} ${blocked.length === 1 ? 'is a file' : 'are files'} the editor did not write (or changed since it did), so no picture was taken and ${blocked.length === 1 ? 'it is' : 'they are'} left as ${blocked.length === 1 ? 'it is' : 'they are'}`,
|
|
596
|
-
};
|
|
597
|
-
/** The pictures to take, each with where it goes. @type {Array<{html: string, out: string, part: string, m: 'light' | 'dark', name?: string, most?: number}>} */
|
|
598
|
-
const jobs = [];
|
|
599
|
-
for (const {html, png, name, most} of shots) {
|
|
600
|
-
for (const m of modes) {
|
|
601
|
-
const out = outOf(png, m);
|
|
602
|
-
if (isLink(out)) {
|
|
603
|
-
linked.push(out);
|
|
604
|
-
continue;
|
|
605
|
-
}
|
|
606
|
-
// Taken under a name of its own and moved into place once whole: a
|
|
607
|
-
// run stopped while the browser runs leaves no picture at the real
|
|
608
|
-
// name (one the next run would read as a file of yours). A part left
|
|
609
|
-
// by a run stopped before is cleared.
|
|
610
|
-
const part = path.join(
|
|
611
|
-
path.dirname(out),
|
|
612
|
-
`.${path.basename(out, '.png')}.part-${process.pid}.png`,
|
|
613
|
-
);
|
|
614
|
-
for (const n of fs.existsSync(path.dirname(out))
|
|
615
|
-
? fs.readdirSync(path.dirname(out))
|
|
616
|
-
: [])
|
|
617
|
-
if (n.startsWith(`.${path.basename(out, '.png')}.part-`)) {
|
|
618
|
-
// Only a file is a part: a folder by that name is left alone.
|
|
619
|
-
const p = path.join(path.dirname(out), n);
|
|
620
|
-
try {
|
|
621
|
-
if (fs.lstatSync(p).isFile()) fs.rmSync(p, {force: true});
|
|
622
|
-
} catch {
|
|
623
|
-
// Gone already.
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
// A folder (or anything else) where this run's part goes: no
|
|
627
|
-
// picture, the path named, never a crash after a saved change.
|
|
628
|
-
if (fs.existsSync(part) && !fs.lstatSync(part).isFile())
|
|
629
|
-
return {
|
|
630
|
-
files,
|
|
631
|
-
cutShort: cutShortNotes(),
|
|
632
|
-
lowContrast: faintNotes(),
|
|
633
|
-
problem: `${path.relative(project.cwd, part)} is a folder, where --png writes a picture before moving it into place, so no picture was taken; move it out of ${path.relative(project.cwd, path.dirname(out))}/`,
|
|
634
|
-
};
|
|
635
|
-
// A folder it cannot write gets no picture: named before the browser
|
|
636
|
-
// starts, never read as a browser that failed.
|
|
637
|
-
try {
|
|
638
|
-
fs.accessSync(path.dirname(out), fs.constants.W_OK);
|
|
639
|
-
} catch (e) {
|
|
640
|
-
return {
|
|
641
|
-
files,
|
|
642
|
-
cutShort: cutShortNotes(),
|
|
643
|
-
lowContrast: faintNotes(),
|
|
644
|
-
problem: `${path.relative(project.cwd, path.dirname(out))}/ cannot be written (${/** @type {any} */ (e)?.code ?? 'no access'}), so no picture was taken; fix its permissions, then run the command again`,
|
|
645
|
-
};
|
|
646
|
-
}
|
|
647
|
-
jobs.push({html, out, part, m, name, most});
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
// Every picture with one browser, then each put in place in order.
|
|
651
|
-
const results = await screenshots(
|
|
652
|
-
project,
|
|
653
|
-
jobs.map(j => ({html: j.html, png: j.part, mode: j.m})),
|
|
654
|
-
run,
|
|
655
|
-
);
|
|
656
|
-
for (const [i, {out, part, m, name, most}] of jobs.entries()) {
|
|
657
|
-
{
|
|
658
|
-
const r = results[i];
|
|
659
|
-
if (!r?.ok) {
|
|
660
|
-
for (const j of jobs.slice(i)) fs.rmSync(j.part, {force: true});
|
|
661
|
-
// Said for the whole run: the pictures taken before this one stand,
|
|
662
|
-
// and this one and every one after it were not taken.
|
|
663
|
-
const all = shots.flatMap(s => modes.map(mm => outOf(s.png, mm)));
|
|
664
|
-
const missed = all
|
|
665
|
-
.slice(all.indexOf(out))
|
|
666
|
-
.map(f => path.relative(project.cwd, f).split(path.sep).join('/'));
|
|
667
|
-
return {
|
|
668
|
-
files,
|
|
669
|
-
cutShort: cutShortNotes(),
|
|
670
|
-
lowContrast: faintNotes(),
|
|
671
|
-
problem: files.length
|
|
672
|
-
? `${files.join(', ')} ${files.length === 1 ? 'was' : 'were'} taken, but ${missed.join(', ')} ${missed.length === 1 ? 'was' : 'were'} not: ${r?.reason ?? 'the browser stopped first'}`
|
|
673
|
-
: `No picture was taken: ${r?.reason ?? 'the browser stopped first'}`,
|
|
674
|
-
};
|
|
675
|
-
}
|
|
676
|
-
try {
|
|
677
|
-
fs.renameSync(part, out);
|
|
678
|
-
} catch (e) {
|
|
679
|
-
for (const j of jobs.slice(i)) fs.rmSync(j.part, {force: true});
|
|
680
|
-
return {
|
|
681
|
-
files,
|
|
682
|
-
cutShort: cutShortNotes(),
|
|
683
|
-
lowContrast: faintNotes(),
|
|
684
|
-
problem: `the picture could not be moved into ${path.relative(project.cwd, out)} (${/** @type {any} */ (e)?.code ?? e})`,
|
|
685
|
-
};
|
|
686
|
-
}
|
|
687
|
-
r.file = path.relative(project.cwd, out).split(path.sep).join('/');
|
|
688
|
-
files.push(r.file);
|
|
689
|
-
/** The pictures this one became: itself, or the pieces it is cut into. */
|
|
690
|
-
let pieces = [r.file];
|
|
691
|
-
// A picture in a theme folder is recorded as the editor's, so a later
|
|
692
|
-
// change removes it and never a picture of the user's.
|
|
693
|
-
const slug = themeOf(out);
|
|
694
|
-
if (slug) {
|
|
695
|
-
// Stamped with the editor's mark and the theme, then recorded.
|
|
696
|
-
try {
|
|
697
|
-
fs.writeFileSync(
|
|
698
|
-
out,
|
|
699
|
-
withPngText(fs.readFileSync(out), EDITOR_STAMP, slug),
|
|
700
|
-
);
|
|
701
|
-
} catch {
|
|
702
|
-
// An unstamped picture is still recorded below.
|
|
703
|
-
}
|
|
704
|
-
recordWritten(project.cwd, slug, [out]);
|
|
705
|
-
if (most) {
|
|
706
|
-
const cut = pagesOfPicture(project.cwd, slug, out, most);
|
|
707
|
-
if (cut.problem) notes.push(cut.problem);
|
|
708
|
-
else if (cut.files.length) {
|
|
709
|
-
files.pop();
|
|
710
|
-
files.push(...cut.files);
|
|
711
|
-
r.file = cut.files[0];
|
|
712
|
-
pieces = cut.files;
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
for (const n of r.notes ?? []) if (!notes.includes(n)) notes.push(n);
|
|
717
|
-
for (const x of r.lowContrast ?? []) {
|
|
718
|
-
const key = `${name ?? r.file}\u0000${x.part}\u0000${x.text}\u0000${x.fg}\u0000${x.bg}\u0000${m}`;
|
|
719
|
-
if (!faint.has(key))
|
|
720
|
-
faint.set(key, {
|
|
721
|
-
page: name ?? null,
|
|
722
|
-
file: r.file,
|
|
723
|
-
part: x.part,
|
|
724
|
-
text: x.text,
|
|
725
|
-
mode: m,
|
|
726
|
-
ratio: x.ratio,
|
|
727
|
-
fg: x.fg,
|
|
728
|
-
bg: x.bg,
|
|
729
|
-
});
|
|
730
|
-
}
|
|
731
|
-
// What the browser measured, kept by page and part; nothing when its
|
|
732
|
-
// script measured nothing. A sheet's narrow cells cut long labels in
|
|
733
|
-
// every theme, so a sheet keeps only text drawn over its neighbor.
|
|
734
|
-
const measured = (r.cutShort ?? []).filter(c => name || c.overlaps);
|
|
735
|
-
if (measured.length) {
|
|
736
|
-
// Each sheet is its own page: its pictures (one per mode, or the
|
|
737
|
-
// pieces a tall one is cut into) are named by the first of them.
|
|
738
|
-
const key = name ?? `\0${out.replace(/-dark\.png$/, '.png')}`;
|
|
739
|
-
const shownFile =
|
|
740
|
-
pieces.length > 1
|
|
741
|
-
? `${pieces[0]} to ${path.basename(pieces[pieces.length - 1])}`
|
|
742
|
-
: r.file;
|
|
743
|
-
const page = cut.get(key) ?? {
|
|
744
|
-
label: name ?? 'the sheet',
|
|
745
|
-
file: shownFile,
|
|
746
|
-
parts: new Map(),
|
|
747
|
-
};
|
|
748
|
-
cut.set(key, page);
|
|
749
|
-
for (const {part, text, whole, broken, overlaps} of measured) {
|
|
750
|
-
const key = `${part ?? ''}${broken ? '\0broken' : ''}${overlaps ? '\0overlaps' : ''}`;
|
|
751
|
-
const at = page.parts.get(key) ?? {
|
|
752
|
-
part: part ?? '',
|
|
753
|
-
broken: Boolean(broken),
|
|
754
|
-
overlaps: Boolean(overlaps),
|
|
755
|
-
texts: new Set(),
|
|
756
|
-
modes: new Set(),
|
|
757
|
-
whole: true,
|
|
758
|
-
};
|
|
759
|
-
page.parts.set(key, at);
|
|
760
|
-
at.texts.add(text);
|
|
761
|
-
at.modes.add(m);
|
|
762
|
-
at.whole &&= whole;
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
if (linked.length) {
|
|
768
|
-
const rels = linked.map(f =>
|
|
769
|
-
path.relative(project.cwd, f).split(path.sep).join('/'),
|
|
770
|
-
);
|
|
771
|
-
const target = (/** @type {string} */ f) => {
|
|
772
|
-
try {
|
|
773
|
-
const to = fs.readlinkSync(f);
|
|
774
|
-
return fs.existsSync(f)
|
|
775
|
-
? ` (to ${to})`
|
|
776
|
-
: ` (to ${to}, which does not exist)`;
|
|
777
|
-
} catch {
|
|
778
|
-
return '';
|
|
779
|
-
}
|
|
780
|
-
};
|
|
781
|
-
notes.unshift(
|
|
782
|
-
`${linked.map((f, i) => `${rels[i]}${target(f)}`).join(', ')} ${linked.length === 1 ? 'is a link' : 'are links'}, and a picture is never written through or over a link, so ${linked.length === 1 ? 'that picture was' : 'those pictures were'} not taken${files.length ? `; ${files.join(', ')} ${files.length === 1 ? 'was' : 'were'} taken` : ''}`,
|
|
783
|
-
);
|
|
784
|
-
}
|
|
785
|
-
return {
|
|
786
|
-
files,
|
|
787
|
-
// Pictures were taken; a note says why an earlier browser did not, and
|
|
788
|
-
// which pictures a link at their name kept out.
|
|
789
|
-
problem: notes.join('; ') || null,
|
|
790
|
-
cutShort: cutShortNotes(),
|
|
791
|
-
lowContrast: faintNotes(),
|
|
792
|
-
};
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
/**
|
|
796
|
-
* A picture taller than `most` cut into pictures at most that tall, in
|
|
797
|
-
* order (`sheet-inputs-1.png`, `-2` …), each cut where the page shows
|
|
798
|
-
* between two parts ({@link cutTall}), stamped and recorded as the
|
|
799
|
-
* editor's, the tall one removed; pictures cut from it before and no
|
|
800
|
-
* longer made are removed too. A file of yours at a cut picture's name is
|
|
801
|
-
* never written over: the tall picture stays, and the note names it.
|
|
802
|
-
* @param {string} cwd
|
|
803
|
-
* @param {string} slug
|
|
804
|
-
* @param {string} out the picture just taken
|
|
805
|
-
* @param {number} most
|
|
806
|
-
* @returns {{files: string[], problem: string | null}} the pictures, as
|
|
807
|
-
* shown, when it was cut; none when it fits
|
|
808
|
-
*/
|
|
809
|
-
function pagesOfPicture(cwd, slug, out, most) {
|
|
810
|
-
const dir = path.dirname(out);
|
|
811
|
-
const base = path.basename(out, '.png');
|
|
812
|
-
const rel = (/** @type {string} */ f) =>
|
|
813
|
-
path.relative(cwd, f).split(path.sep).join('/');
|
|
814
|
-
let pieces;
|
|
815
|
-
try {
|
|
816
|
-
pieces = cutTall(decodePng(fs.readFileSync(out)), most);
|
|
817
|
-
} catch {
|
|
818
|
-
return {files: [], problem: null};
|
|
819
|
-
}
|
|
820
|
-
const named = new RegExp(
|
|
821
|
-
`^${base.replace(/[^a-z0-9-]/gi, '\\$&')}-(\\d+)\\.png$`,
|
|
822
|
-
);
|
|
823
|
-
const before = (fs.existsSync(dir) ? fs.readdirSync(dir) : [])
|
|
824
|
-
.filter(n => named.test(n))
|
|
825
|
-
.map(n => path.join(dir, n));
|
|
826
|
-
const mine = before.filter(f => !editorRecorded(cwd, slug, f));
|
|
827
|
-
const names =
|
|
828
|
-
pieces.length > 1
|
|
829
|
-
? pieces.map((_, i) => path.join(dir, `${base}-${i + 1}.png`))
|
|
830
|
-
: [];
|
|
831
|
-
const inWay = mine.filter(f => names.includes(f));
|
|
832
|
-
if (inWay.length)
|
|
833
|
-
return {
|
|
834
|
-
files: [],
|
|
835
|
-
problem: `${inWay.map(rel).join(', ')} ${inWay.length === 1 ? 'is a file' : 'are files'} the editor did not write, so ${rel(out)} was not cut into pictures of at most ${most}px and stays whole`,
|
|
836
|
-
};
|
|
837
|
-
for (const f of before) if (!mine.includes(f)) fs.rmSync(f, {force: true});
|
|
838
|
-
if (!names.length) return {files: [], problem: null};
|
|
839
|
-
pieces.forEach((pic, i) =>
|
|
840
|
-
writeWhole(names[i], withPngText(encodePng(pic), EDITOR_STAMP, slug)),
|
|
841
|
-
);
|
|
842
|
-
recordWritten(cwd, slug, names);
|
|
843
|
-
fs.rmSync(out, {force: true});
|
|
844
|
-
return {files: names.map(rel), problem: null};
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
/**
|
|
848
|
-
* The families the theme's build writes that no package loads: not a
|
|
849
|
-
* system or desktop font, not loaded by a font stylesheet the app copy
|
|
850
|
-
* imports (the base's fonts included), and none of `packages` (the font
|
|
851
|
-
* packages that load it where the fonts go: the project's, or a new app's).
|
|
852
|
-
* @param {import('./_settings.mjs').Ctx} ctx
|
|
853
|
-
* @param {import('./_settings.mjs').ThemeData} data
|
|
854
|
-
* @param {Array<{family: string}>} packages
|
|
855
|
-
* @returns {string[]}
|
|
856
|
-
*/
|
|
857
|
-
export function familiesNothingLoads(ctx, data, packages) {
|
|
858
|
-
const built = builtFontFamilies(ctx, data.name);
|
|
859
|
-
/** @type {Set<string>} */
|
|
860
|
-
const loaded = new Set();
|
|
861
|
-
for (const spec of copyFontsCss(ctx, data.name, data))
|
|
862
|
-
for (const f of importedFontFamilies(spec, ctx.project.cwd)) loaded.add(f);
|
|
863
|
-
return [...(built?.values() ?? [])].filter(family => {
|
|
864
|
-
const key = fontKey(family);
|
|
865
|
-
return !(
|
|
866
|
-
loaded.has(key) ||
|
|
867
|
-
packages.some(x => fontKey(x.family) === key) ||
|
|
868
|
-
isDesktopFamily(family) ||
|
|
869
|
-
oneSystemOf(family) ||
|
|
870
|
-
appleFaceGeneric(family)
|
|
871
|
-
);
|
|
872
|
-
});
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
/**
|
|
876
|
-
* What the previews (preview.html, sheet.html and their pictures) cannot
|
|
877
|
-
* show of the images and files the theme's built stylesheet names: a
|
|
878
|
-
* remote file (a page opened from disk loads no network), a file that is
|
|
879
|
-
* not there, one that is not a regular file, and one too large to carry.
|
|
880
|
-
* Read from the built stylesheet with the renderer's own reader, so a
|
|
881
|
-
* preview rendered before says it too.
|
|
882
|
-
* @param {import('./_settings.mjs').Ctx} ctx
|
|
883
|
-
* @param {string} slug
|
|
884
|
-
* @returns {string[]}
|
|
885
|
-
*/
|
|
886
|
-
export function themeImageNotes(ctx, slug) {
|
|
887
|
-
const file = themeFiles(ctx.project.cwd, slug).css;
|
|
888
|
-
/** @type {string} */
|
|
889
|
-
let css;
|
|
890
|
-
try {
|
|
891
|
-
css = fs.readFileSync(file, 'utf8');
|
|
892
|
-
} catch {
|
|
893
|
-
return [];
|
|
894
|
-
}
|
|
895
|
-
const at = {dir: path.dirname(file), root: ctx.project.cwd};
|
|
896
|
-
const where = shown(ctx.project.cwd, at.dir);
|
|
897
|
-
/** @type {Map<string, string>} */
|
|
898
|
-
const notes = new Map();
|
|
899
|
-
for (const m of css.matchAll(new RegExp(CSS_URL.source, 'g'))) {
|
|
900
|
-
const named = assetRef(cssUrlRef(m), at);
|
|
901
|
-
if (!named || notes.has(named.ref)) continue;
|
|
902
|
-
if (named.kind === 'remote')
|
|
903
|
-
notes.set(
|
|
904
|
-
named.ref,
|
|
905
|
-
`${named.ref} is loaded from the network: the app loads it, but the previews (preview.html, sheet.html and their pictures) cannot, and show the theme without it.`,
|
|
906
|
-
);
|
|
907
|
-
else if (named.kind === 'missing')
|
|
908
|
-
notes.set(
|
|
909
|
-
named.ref,
|
|
910
|
-
named.ref.startsWith('/')
|
|
911
|
-
? `${named.ref} was not found in ${shown(ctx.project.cwd, path.join(at.root, 'public'))}/, where a path from the site's root is read, so neither the previews nor the app show it.`
|
|
912
|
-
: `${named.ref} was not found beside the theme (${where}/), so neither the previews nor the app show it.`,
|
|
913
|
-
);
|
|
914
|
-
else if (named.kind === 'not-file')
|
|
915
|
-
notes.set(
|
|
916
|
-
named.ref,
|
|
917
|
-
`${named.ref} is not a regular file (a pipe, a device or a folder), so the previews do not read it and show the theme without it.`,
|
|
918
|
-
);
|
|
919
|
-
else if (named.kind === 'unreadable')
|
|
920
|
-
notes.set(
|
|
921
|
-
named.ref,
|
|
922
|
-
`${shown(ctx.project.cwd, named.file)} cannot be read (no permission), so the previews show the theme without it; make it readable (chmod u+r) to show it.`,
|
|
923
|
-
);
|
|
924
|
-
else {
|
|
925
|
-
const bytes = fs.statSync(named.file).size;
|
|
926
|
-
if (bytes > MAX_ASSET_BYTES)
|
|
927
|
-
notes.set(
|
|
928
|
-
named.ref,
|
|
929
|
-
`${shown(ctx.project.cwd, named.file)} is ${(bytes / 1048576).toFixed(1)} MB, more than the ${MAX_ASSET_BYTES / 1048576} MB a preview page carries per file; a smaller copy shows in the previews too.`,
|
|
930
|
-
);
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
return [...notes.values()];
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
/**
|
|
937
|
-
* The open fonts a set's families name whose package is not installed, each
|
|
938
|
-
* with the line that installs it: until then the pictures and the app draw
|
|
939
|
-
* the next font in the stack.
|
|
940
|
-
* @param {import('./_settings.mjs').Ctx} ctx
|
|
941
|
-
* @param {import('./_settings.mjs').ThemeData} data
|
|
942
|
-
* @returns {Array<{family: string, run: string[]}>}
|
|
943
|
-
*/
|
|
944
|
-
export function fontsNotLoaded(ctx, data) {
|
|
945
|
-
return fontPackages(ctx, data)
|
|
946
|
-
.filter(p => !p.installed)
|
|
947
|
-
.map(p => ({
|
|
948
|
-
family: p.family,
|
|
949
|
-
run: [installLine(ctx.project.cwd, [p.pkg])],
|
|
950
|
-
}));
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
/**
|
|
954
|
-
* Font notes for the families the theme builds: the import line for an
|
|
955
|
-
* open font, the install line when its package is missing, and a warning
|
|
956
|
-
* for a family no package loads, naming the closest open font.
|
|
957
|
-
* @param {import('./_settings.mjs').Ctx} ctx
|
|
958
|
-
* @param {import('./_settings.mjs').ThemeData} data
|
|
959
|
-
* @returns {string[]}
|
|
960
|
-
*/
|
|
961
|
-
export function fontNotes(ctx, data) {
|
|
962
|
-
/** @type {string[]} */
|
|
963
|
-
const notes = [];
|
|
964
|
-
const packages = fontPackages(ctx, data);
|
|
965
|
-
// A family nothing loads, with the Fontsource package that would load
|
|
966
|
-
// it, when Fontsource's naming gives one.
|
|
967
|
-
/** @param {string} family */
|
|
968
|
-
const unloadedNote = family => {
|
|
969
|
-
const s = fontsourceSuggestion(family);
|
|
970
|
-
return `"${family}" is not a system font and no package loads it: the app must load it, or it falls back.${s ? ` ${s.known ? '' : 'If Fontsource publishes it, '}${installLine(ctx.project.cwd, [s.pkg])} installs its package, which the previews and the app copy then load.` : ''}`;
|
|
971
|
-
};
|
|
972
|
-
for (const {pkg, family, installed} of packages) {
|
|
973
|
-
const fallbacks =
|
|
974
|
-
Object.values(OPEN_FONTS).find(f => f.pkg === pkg)?.fallbacks ?? '';
|
|
975
|
-
const near = /monospace/.test(fallbacks)
|
|
976
|
-
? 'mono'
|
|
977
|
-
: /serif/.test(fallbacks.replace('sans-serif', ''))
|
|
978
|
-
? 'serif'
|
|
979
|
-
: 'system';
|
|
980
|
-
notes.push(
|
|
981
|
-
installed
|
|
982
|
-
? `${family} is installed (${pkg}), so the previews and the app copy load it, a stylesheet for each face the theme's weights show: ${fontPackageSheets(
|
|
983
|
-
ctx,
|
|
984
|
-
data.name,
|
|
985
|
-
pkg,
|
|
986
|
-
)
|
|
987
|
-
.map(x => `import '${x}';`)
|
|
988
|
-
.join(' ')}`
|
|
989
|
-
: `${family} is not installed, so it does not load: the previews and the app show the next font in the stack. Install it: ${installLine(ctx.project.cwd, [pkg])}. Then the preview imports it on the next set or show, and the app imports it once: import '${pkg}'; Until then, the closest font that needs no install is ${near}: ${P} set ${data.name} font ${near}`,
|
|
990
|
-
);
|
|
991
|
-
}
|
|
992
|
-
// A family the editor's own presets lead with, where the preset gets no
|
|
993
|
-
// note (Comic Sans MS, of comic), is no more a font to load typed by name.
|
|
994
|
-
const presetFamily = (/** @type {string} */ family) => {
|
|
995
|
-
const f = family.replace(/["']/g, '').trim().toLowerCase();
|
|
996
|
-
// A one-system font keeps its note, preset or not.
|
|
997
|
-
if (oneSystemOf(family.replace(/["']/g, '').trim())) return false;
|
|
998
|
-
return Object.entries(FONTS).some(
|
|
999
|
-
([k, [first]]) =>
|
|
1000
|
-
(SYSTEM_FONTS.includes(k) || k === 'comic' || k === 'rounded') &&
|
|
1001
|
-
first.replace(/["']/g, '').trim().toLowerCase() === f,
|
|
1002
|
-
);
|
|
1003
|
-
};
|
|
1004
|
-
// A font setting whose family the build no longer uses (the theme's own
|
|
1005
|
-
// source sets every place it went) gets no note: nothing shows it.
|
|
1006
|
-
const built = builtFontFamilies(ctx, data.name);
|
|
1007
|
-
// The families the base's own font stylesheet loads from a remote sheet:
|
|
1008
|
-
// named once below, as the app shows them, never as fonts nothing loads.
|
|
1009
|
-
const base = baseFontsSheet(ctx, data);
|
|
1010
|
-
const baseLoads = new Set(
|
|
1011
|
-
base?.remote.length ? base.families.map(f => fontKey(f)) : [],
|
|
1012
|
-
);
|
|
1013
|
-
for (const s of data.settings) {
|
|
1014
|
-
if (
|
|
1015
|
-
s.thing !== 'font' ||
|
|
1016
|
-
(built &&
|
|
1017
|
-
!built.has(
|
|
1018
|
-
fontOf(s.value).family.replace(/["']/g, '').trim().toLowerCase(),
|
|
1019
|
-
)) ||
|
|
1020
|
-
SYSTEM_FONTS.includes(s.value) ||
|
|
1021
|
-
isDesktopFamily(fontOf(s.value).family.replace(/["']/g, '')) ||
|
|
1022
|
-
OPEN_FONTS[s.value] ||
|
|
1023
|
-
fontOf(s.value).pkg ||
|
|
1024
|
-
packages.some(x => x.of === s) ||
|
|
1025
|
-
s.value === 'rounded' ||
|
|
1026
|
-
s.value === 'comic' ||
|
|
1027
|
-
presetFamily(fontOf(s.value).family) ||
|
|
1028
|
-
baseLoads.has(fontKey(fontOf(s.value).family))
|
|
1029
|
-
)
|
|
1030
|
-
continue;
|
|
1031
|
-
const family = fontOf(s.value).family.replace(/["']/g, '').toLowerCase();
|
|
1032
|
-
const near = CLOSEST_OPEN_FONT[family];
|
|
1033
|
-
const named = fontOf(s.value).family.replace(/^["']|["']$/g, '');
|
|
1034
|
-
const system = oneSystemOf(named);
|
|
1035
|
-
const on = s.on ? ` --on ${s.on}` : '';
|
|
1036
|
-
const generic = appleFaceGeneric(named);
|
|
1037
|
-
if (generic) {
|
|
1038
|
-
// Apple systems reach their interface faces only by a generic.
|
|
1039
|
-
const {fallbacks} = fontOf(s.value);
|
|
1040
|
-
const next = fallbacks.split(',')[0]?.trim() || 'system-ui';
|
|
1041
|
-
// The generic once: a stack that already holds it keeps one.
|
|
1042
|
-
const value = [
|
|
1043
|
-
...new Set(
|
|
1044
|
-
[generic, ...fallbacks.split(',')].map(f => f.trim()).filter(Boolean),
|
|
1045
|
-
),
|
|
1046
|
-
].join(', ');
|
|
1047
|
-
notes.push(
|
|
1048
|
-
`"${named}" is an Apple interface face, which browsers do not reach by its name, so every system shows the next font in the stack (${next}). Apple systems show it for ${generic}: ${P} set ${data.name} font ${quoteCommandArgument(value)}${on}`,
|
|
1049
|
-
);
|
|
1050
|
-
continue;
|
|
1051
|
-
}
|
|
1052
|
-
if (system) {
|
|
1053
|
-
// A system font, on one system: the others show the next font.
|
|
1054
|
-
const next =
|
|
1055
|
-
fontOf(s.value).fallbacks.split(',')[0]?.trim() || 'system-ui';
|
|
1056
|
-
notes.push(
|
|
1057
|
-
/^(-apple-system|blinkmacsystemfont)$/.test(family)
|
|
1058
|
-
? `"${named}" names the interface font of ${system}, and only there: other systems show the next font in the stack (${next}). The system preset gives each system its own interface font: ${P} set ${data.name} font system${on}`
|
|
1059
|
-
: `"${named}" ships only on ${system}: other systems show the next font in the stack (${next}).${near ? ` The closest open font, which loads everywhere, is ${near}: ${P} set ${data.name} font ${near}${on}` : ''}`,
|
|
1060
|
-
);
|
|
1061
|
-
continue;
|
|
1062
|
-
}
|
|
1063
|
-
notes.push(
|
|
1064
|
-
`${unloadedNote(named)}${near ? ` The closest open font is ${near}: ${P} set ${data.name} font ${near}${s.on ? ` --on ${s.on}` : ''}` : ''}`,
|
|
1065
|
-
);
|
|
1066
|
-
}
|
|
1067
|
-
// Every other family the build writes that nothing loads (a part's own
|
|
1068
|
-
// font, a font token, a family the theme's own source sets) is named
|
|
1069
|
-
// once, with the package that would load it: the same built families
|
|
1070
|
-
// the app copy and the previews load fonts for.
|
|
1071
|
-
const dialFamilies = new Set(
|
|
1072
|
-
data.settings
|
|
1073
|
-
.filter(s => s.thing === 'font')
|
|
1074
|
-
.map(s => fontKey(fontOf(s.value).family)),
|
|
1075
|
-
);
|
|
1076
|
-
// A base family the app loads from a remote stylesheet (a Google Fonts
|
|
1077
|
-
// import in the base's fonts.css) is not in the static previews: a page
|
|
1078
|
-
// opened from disk cannot load a remote stylesheet. Unless an installed
|
|
1079
|
-
// package loads it, the previews and pictures show the next font.
|
|
1080
|
-
if (base?.remote.length)
|
|
1081
|
-
for (const family of base.families) {
|
|
1082
|
-
if (built && !built.has(family.toLowerCase())) continue;
|
|
1083
|
-
if (
|
|
1084
|
-
packages.some(x => x.installed && fontKey(x.family) === fontKey(family))
|
|
1085
|
-
)
|
|
1086
|
-
continue;
|
|
1087
|
-
const s = fontsourceSuggestion(family);
|
|
1088
|
-
notes.push(
|
|
1089
|
-
`"${family}" comes from ${base.spec}, which loads it from ${new URL(base.remote[0], 'https://x').host}: the app shows it, but the previews (preview.html, sheet.html and their pictures) cannot load a remote stylesheet and show the next font in the stack.${s ? ` ${installLine(ctx.project.cwd, [s.pkg])} installs a copy the previews load too.` : ''}`,
|
|
1090
|
-
);
|
|
1091
|
-
}
|
|
1092
|
-
notes.push(...baseWeightNotes(ctx, data));
|
|
1093
|
-
for (const family of familiesNothingLoads(ctx, data, packages)) {
|
|
1094
|
-
if (dialFamilies.has(fontKey(family)) || baseLoads.has(fontKey(family)))
|
|
1095
|
-
continue;
|
|
1096
|
-
notes.push(unloadedNote(family));
|
|
1097
|
-
}
|
|
1098
|
-
notes.push(...loneFamilyNotes(ctx, data));
|
|
1099
|
-
return notes;
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1102
|
-
/** What each font role's family token sets, for a note. */
|
|
1103
|
-
const ROLE_TEXT = /** @type {Record<string, string>} */ ({
|
|
1104
|
-
body: 'body text uses',
|
|
1105
|
-
heading: 'headings use',
|
|
1106
|
-
code: 'code uses',
|
|
1107
|
-
});
|
|
1108
|
-
|
|
1109
|
-
/**
|
|
1110
|
-
* A note for each font role the theme's build gives one family and no
|
|
1111
|
-
* fallback at all (`--font-family-heading: Lora`, as Core builds a heading
|
|
1112
|
-
* family given no fallbacks of its own, or an exact token set so): text in
|
|
1113
|
-
* it has no font while that one loads, or if it is missing. The way to a
|
|
1114
|
-
* list is named where the family came from: the setting, run with a list
|
|
1115
|
-
* (the family's own open-font fallbacks, else the font dial's), or the
|
|
1116
|
-
* theme's own source.
|
|
1117
|
-
* @param {import('./_settings.mjs').Ctx} ctx
|
|
1118
|
-
* @param {import('./_settings.mjs').ThemeData} data
|
|
1119
|
-
* @returns {string[]}
|
|
1120
|
-
*/
|
|
1121
|
-
export function loneFamilyNotes(ctx, data) {
|
|
1122
|
-
/** @type {string} */
|
|
1123
|
-
let css;
|
|
1124
|
-
try {
|
|
1125
|
-
css = fs.readFileSync(themeFiles(ctx.project.cwd, data.name).css, 'utf8');
|
|
1126
|
-
} catch {
|
|
1127
|
-
return [];
|
|
1128
|
-
}
|
|
1129
|
-
/** @type {string[]} */
|
|
1130
|
-
const notes = [];
|
|
1131
|
-
const own = customPropertyValues(css);
|
|
1132
|
-
for (const role of Object.keys(ROLE_TEXT)) {
|
|
1133
|
-
const token = `--font-family-${role}`;
|
|
1134
|
-
const value = own.get(token)?.at(-1);
|
|
1135
|
-
if (!value || /var\(/i.test(value) || hasGenericFamily(value)) continue;
|
|
1136
|
-
const named = namedFontFamilies(value);
|
|
1137
|
-
if (named.length !== 1) continue;
|
|
1138
|
-
const family = named[0].replace(/^["']|["']$/g, '');
|
|
1139
|
-
const fallbacks =
|
|
1140
|
-
Object.values(OPEN_FONTS).find(f => fontKey(f.family) === fontKey(family))
|
|
1141
|
-
?.fallbacks ?? fontOf(family).fallbacks;
|
|
1142
|
-
const list = `${value.trim()}, ${fallbacks}`;
|
|
1143
|
-
const setting = data.settings.find(
|
|
1144
|
-
s => s.source === 'token' && s.thing === token && !s.on && !s.when,
|
|
1145
|
-
);
|
|
1146
|
-
const typography = ownTokenEntries(ctx.project.cwd, data.name).some(
|
|
1147
|
-
e => e.kind === 'typography' && e.key === `${role}.family`,
|
|
1148
|
-
);
|
|
1149
|
-
const fix = setting
|
|
1150
|
-
? `give a list: ${P} set ${data.name} ${token} ${quoteCommandArgument(list)}`
|
|
1151
|
-
: typography
|
|
1152
|
-
? `give typography.${role} its fallbacks in themes/${data.name}/${data.name}.theme.ts (such as fallbacks: '${fallbacks}')`
|
|
1153
|
-
: `give ${token} a list in themes/${data.name}/${data.name}.theme.ts (such as '${list}')`;
|
|
1154
|
-
notes.push(
|
|
1155
|
-
`${ROLE_TEXT[role]} only ${family}, with no fallback while it loads or if it is missing; to fall back, ${fix}`,
|
|
1156
|
-
);
|
|
1157
|
-
}
|
|
1158
|
-
return notes;
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
|
-
/**
|
|
1162
|
-
* A note for each weight the theme uses that a stylesheet loading one of
|
|
1163
|
-
* its families has no face for (it shows as the face CSS font matching
|
|
1164
|
-
* picks): the base theme's font stylesheet, unless an installed package
|
|
1165
|
-
* loads that family, and each installed font package with a stylesheet per
|
|
1166
|
-
* weight.
|
|
1167
|
-
* @param {import('./_settings.mjs').Ctx} ctx
|
|
1168
|
-
* @param {import('./_settings.mjs').ThemeData} data
|
|
1169
|
-
* @returns {string[]}
|
|
1170
|
-
*/
|
|
1171
|
-
export function baseWeightNotes(ctx, data) {
|
|
1172
|
-
/** @type {string[]} */
|
|
1173
|
-
const notes = [];
|
|
1174
|
-
const built = builtFontFamilies(ctx, data.name);
|
|
1175
|
-
const packages = fontPackages(ctx, data);
|
|
1176
|
-
/**
|
|
1177
|
-
* @param {string} family @param {string} by what loads it
|
|
1178
|
-
* @param {number[]} faces the weights it loads @param {string} fix
|
|
1179
|
-
*/
|
|
1180
|
-
const gap = (family, by, faces, fix) => {
|
|
1181
|
-
// The weights text in this family uses: those set beside it, and the
|
|
1182
|
-
// ones every text reads (never a weight only another family uses).
|
|
1183
|
-
const used = builtFontWeights(ctx, data.name, family) ?? [];
|
|
1184
|
-
const missing = used.filter(w => !faces.includes(w));
|
|
1185
|
-
if (missing.length)
|
|
1186
|
-
notes.push(
|
|
1187
|
-
`${family} is loaded by ${by} at ${faces.join(', ')} only, so ${missing.map(w => `${w} shows as ${shownWeight(w, faces)}`).join(', ')}${fix}`,
|
|
1188
|
-
);
|
|
1189
|
-
};
|
|
1190
|
-
const base = baseFontsSheet(ctx, data);
|
|
1191
|
-
for (const [family, faces] of base?.weights ?? []) {
|
|
1192
|
-
if (built && !built.has(family.toLowerCase())) continue;
|
|
1193
|
-
if (
|
|
1194
|
-
packages.some(x => x.installed && fontKey(x.family) === fontKey(family))
|
|
1195
|
-
)
|
|
1196
|
-
continue;
|
|
1197
|
-
const s = fontsourceSuggestion(family);
|
|
1198
|
-
gap(
|
|
1199
|
-
family,
|
|
1200
|
-
/** @type {{spec: string}} */ (base).spec,
|
|
1201
|
-
faces,
|
|
1202
|
-
s
|
|
1203
|
-
? `; ${installLine(ctx.project.cwd, [s.pkg])} loads every weight of it`
|
|
1204
|
-
: '',
|
|
1205
|
-
);
|
|
1206
|
-
}
|
|
1207
|
-
for (const {pkg, family, installed} of packages) {
|
|
1208
|
-
if (!installed || (built && !built.has(family.toLowerCase()))) continue;
|
|
1209
|
-
const faces = fontPackageWeights(ctx, pkg);
|
|
1210
|
-
if (faces) gap(family, pkg, faces, '');
|
|
1211
|
-
}
|
|
1212
|
-
return notes;
|
|
1213
|
-
}
|
|
1214
|
-
|
|
1215
|
-
/**
|
|
1216
|
-
* What a change did to part styles (component settings), one line each.
|
|
1217
|
-
* @param {any} before
|
|
1218
|
-
* @param {any} after
|
|
1219
|
-
* @param {any} [base] the base theme, whose own values a write that repeats them does not change
|
|
1220
|
-
* @param {(target: string, prop: string) => string | null} [drawn] the value Core itself writes for a part's property, as written (a token reference: `var(--radius-full)`), when it is the same at rest and in every state; a write of that same value repeats it and is not listed
|
|
1221
|
-
* @returns {string[]}
|
|
1222
|
-
*/
|
|
1223
|
-
export function styledChanges(before, after, base, drawn) {
|
|
1224
|
-
/** @type {string[]} */
|
|
1225
|
-
const out = [];
|
|
1226
|
-
/** A value as CSS reads it, for comparing. @param {any} v */
|
|
1227
|
-
const plain = v =>
|
|
1228
|
-
(Array.isArray(v) && v.length === 2
|
|
1229
|
-
? `light-dark(${v[0]}, ${v[1]})`
|
|
1230
|
-
: String(v ?? '')
|
|
1231
|
-
)
|
|
1232
|
-
.replace(/\s+/g, ' ')
|
|
1233
|
-
.trim()
|
|
1234
|
-
.toLowerCase();
|
|
1235
|
-
const a = before?.components ?? {};
|
|
1236
|
-
const b = after?.components ?? {};
|
|
1237
|
-
for (const target of new Set([...Object.keys(a), ...Object.keys(b)])) {
|
|
1238
|
-
for (const key of new Set([
|
|
1239
|
-
...Object.keys(a[target] ?? {}),
|
|
1240
|
-
...Object.keys(b[target] ?? {}),
|
|
1241
|
-
])) {
|
|
1242
|
-
const x = a[target]?.[key] ?? {};
|
|
1243
|
-
const y = b[target]?.[key] ?? {};
|
|
1244
|
-
/** @param {string} p */
|
|
1245
|
-
const cssName = p =>
|
|
1246
|
-
p.startsWith('--')
|
|
1247
|
-
? p
|
|
1248
|
-
: p.replace(/[A-Z]/g, c => `-${c.toLowerCase()}`);
|
|
1249
|
-
for (const prop of new Set([...Object.keys(x), ...Object.keys(y)])) {
|
|
1250
|
-
if (JSON.stringify(x[prop]) === JSON.stringify(y[prop])) continue;
|
|
1251
|
-
const shown = base?.components?.[target]?.[key]?.[prop];
|
|
1252
|
-
/**
|
|
1253
|
-
* Whether a write only repeats what the base theme already shows
|
|
1254
|
-
* there, which changes nothing.
|
|
1255
|
-
* @param {any} was @param {any} now @param {any} baseValue
|
|
1256
|
-
*/
|
|
1257
|
-
const repeatsBase = (was, now, baseValue) =>
|
|
1258
|
-
was === undefined &&
|
|
1259
|
-
baseValue !== undefined &&
|
|
1260
|
-
typeof baseValue !== 'object' &&
|
|
1261
|
-
plain(baseValue) === plain(now);
|
|
1262
|
-
const where = `${target}${key === 'base' ? '' : ` ${key}`}`;
|
|
1263
|
-
// A block (a state, `:hover`, a mode block, a state inside a mode
|
|
1264
|
-
// block) lists each property it changes, under its path.
|
|
1265
|
-
/**
|
|
1266
|
-
* @param {string} path @param {any} xs @param {any} ys @param {any} shownIn
|
|
1267
|
-
*/
|
|
1268
|
-
const blockLines = (path, xs, ys, shownIn) => {
|
|
1269
|
-
for (const p of new Set([
|
|
1270
|
-
...Object.keys(xs ?? {}),
|
|
1271
|
-
...Object.keys(ys ?? {}),
|
|
1272
|
-
])) {
|
|
1273
|
-
const was = xs?.[p];
|
|
1274
|
-
const now = ys?.[p];
|
|
1275
|
-
if (JSON.stringify(was) === JSON.stringify(now)) continue;
|
|
1276
|
-
if (
|
|
1277
|
-
(now && typeof now === 'object') ||
|
|
1278
|
-
(was && typeof was === 'object')
|
|
1279
|
-
) {
|
|
1280
|
-
blockLines(`${path} ${p}`, was ?? {}, now ?? {}, shownIn?.[p]);
|
|
1281
|
-
continue;
|
|
1282
|
-
}
|
|
1283
|
-
if (repeatsBase(was, now, shownIn?.[p])) continue;
|
|
1284
|
-
out.push(
|
|
1285
|
-
`${where} ${path}: ${cssName(p)} ${now === undefined ? '(removed)' : String(now)}`,
|
|
1286
|
-
);
|
|
1287
|
-
}
|
|
1288
|
-
};
|
|
1289
|
-
if (
|
|
1290
|
-
(y[prop] && typeof y[prop] === 'object') ||
|
|
1291
|
-
(x[prop] && typeof x[prop] === 'object')
|
|
1292
|
-
) {
|
|
1293
|
-
blockLines(prop, x[prop] ?? {}, y[prop] ?? {}, shown);
|
|
1294
|
-
continue;
|
|
1295
|
-
}
|
|
1296
|
-
if (repeatsBase(x[prop], y[prop], shown)) continue;
|
|
1297
|
-
// (A part's plain rule that writes what Core draws there already.)
|
|
1298
|
-
if (
|
|
1299
|
-
key === 'base' &&
|
|
1300
|
-
x[prop] === undefined &&
|
|
1301
|
-
shown === undefined &&
|
|
1302
|
-
typeof y[prop] !== 'object' &&
|
|
1303
|
-
drawn &&
|
|
1304
|
-
repeatsBase(undefined, y[prop], drawn(target, cssName(prop)))
|
|
1305
|
-
)
|
|
1306
|
-
continue;
|
|
1307
|
-
out.push(
|
|
1308
|
-
`${where}: ${cssName(prop)} ${y[prop] === undefined ? '(removed)' : typeof y[prop] === 'string' ? y[prop] : JSON.stringify(y[prop])}`,
|
|
1309
|
-
);
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
|
-
}
|
|
1313
|
-
const ta = JSON.stringify(before?.typography ?? {});
|
|
1314
|
-
const tb = JSON.stringify(after?.typography ?? {});
|
|
1315
|
-
if (ta !== tb) {
|
|
1316
|
-
for (const role of FONT_ROLES) {
|
|
1317
|
-
const x = after?.typography?.[role];
|
|
1318
|
-
if (
|
|
1319
|
-
JSON.stringify(before?.typography?.[role] ?? null) !==
|
|
1320
|
-
JSON.stringify(x ?? null)
|
|
1321
|
-
)
|
|
1322
|
-
out.push(
|
|
1323
|
-
`typography ${role}: ${
|
|
1324
|
-
x
|
|
1325
|
-
? Object.entries(x)
|
|
1326
|
-
.map(
|
|
1327
|
-
([k, v]) =>
|
|
1328
|
-
`${k} ${
|
|
1329
|
-
v && typeof v === 'object'
|
|
1330
|
-
? Object.entries(v)
|
|
1331
|
-
.map(([a, b]) => `${a}: ${b}`)
|
|
1332
|
-
.join(', ')
|
|
1333
|
-
: v
|
|
1334
|
-
}`,
|
|
1335
|
-
)
|
|
1336
|
-
.join('; ')
|
|
1337
|
-
: '(removed)'
|
|
1338
|
-
}`,
|
|
1339
|
-
);
|
|
1340
|
-
}
|
|
1341
|
-
if (
|
|
1342
|
-
JSON.stringify(before?.typography?.scale ?? null) !==
|
|
1343
|
-
JSON.stringify(after?.typography?.scale ?? null)
|
|
1344
|
-
)
|
|
1345
|
-
out.push(
|
|
1346
|
-
`typography scale: base ${after?.typography?.scale?.base ?? 'default'}`,
|
|
1347
|
-
);
|
|
1348
|
-
}
|
|
1349
|
-
return out;
|
|
1350
|
-
}
|
|
1351
|
-
|
|
1352
|
-
/**
|
|
1353
|
-
* The line that says which pictures to open after a run that took them:
|
|
1354
|
-
* each family of components' first ({@link familyPages}), then the pages
|
|
1355
|
-
* section's (the sample app and each page template, cut between pages),
|
|
1356
|
-
* then the sample page's and the open states' (every menu, tooltip, popover
|
|
1357
|
-
* and list drawn open), of the mode shown first (light when the theme has
|
|
1358
|
-
* both). Null when this run took none of them.
|
|
1359
|
-
* @param {string[]} files the pictures taken, as shown (`themes/t/preview.png`)
|
|
1360
|
-
* @returns {string | null}
|
|
1361
|
-
*/
|
|
1362
|
-
export function lookAtPictures(files) {
|
|
1363
|
-
/** @param {string} name */
|
|
1364
|
-
const one = name =>
|
|
1365
|
-
files.find(f => path.basename(f) === `${name}.png`) ??
|
|
1366
|
-
files.find(f => path.basename(f) === `${name}-dark.png`);
|
|
1367
|
-
const preview = one('preview');
|
|
1368
|
-
const open = one(`sheet-${OPEN_SECTION}`);
|
|
1369
|
-
// A family's picture, or the pictures cut from it, in order.
|
|
1370
|
-
/** @param {string} g @param {string} dark */
|
|
1371
|
-
const cuts = (g, dark) =>
|
|
1372
|
-
files.filter(f =>
|
|
1373
|
-
new RegExp(`^sheet-${g}${dark}(?:-\\d+)?\\.png$`).test(path.basename(f)),
|
|
1374
|
-
);
|
|
1375
|
-
/** @param {string} g */
|
|
1376
|
-
const pictured = g => (cuts(g, '').length ? cuts(g, '') : cuts(g, '-dark'));
|
|
1377
|
-
const families = FAMILY_SECTIONS.flatMap(pictured);
|
|
1378
|
-
const pages = pictured('pages');
|
|
1379
|
-
if (!preview && !open && !families.length && !pages.length) return null;
|
|
1380
|
-
const dark =
|
|
1381
|
-
files.some(f => /-dark\.png$/.test(f)) &&
|
|
1382
|
-
files.some(f => /(?<!-dark)\.png$/.test(f));
|
|
1383
|
-
return `open ${[
|
|
1384
|
-
// A family's own picture reads whole; the full sheet does not.
|
|
1385
|
-
...(families.length
|
|
1386
|
-
? [`${families.join(', ')} (one family of components each)`]
|
|
1387
|
-
: []),
|
|
1388
|
-
...(pages.length
|
|
1389
|
-
? [`${pages.join(', ')} (the sample app and each page template)`]
|
|
1390
|
-
: []),
|
|
1391
|
-
...(preview
|
|
1392
|
-
? [
|
|
1393
|
-
`${preview} (the sample page, a tooltip, a menu and a list drawn open below it)`,
|
|
1394
|
-
]
|
|
1395
|
-
: []),
|
|
1396
|
-
...(open
|
|
1397
|
-
? [
|
|
1398
|
-
`${open} (each control at rest, hovered, focused and pressed at its top, then every menu, tooltip, popover and list, drawn open)`,
|
|
1399
|
-
]
|
|
1400
|
-
: []),
|
|
1401
|
-
].join(' and ')}${dark ? '; the -dark pictures show the dark mode' : ''}`;
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
/**
|
|
1405
|
-
* The page of the theme's open states (every menu, tooltip, popover and
|
|
1406
|
-
* list drawn open: the overlays section of the sheet), made and stamped
|
|
1407
|
-
* with the build it shows, and where its picture goes. The sample page
|
|
1408
|
-
* (preview.png) has no overlay open, and the full sheet is too tall to
|
|
1409
|
-
* read whole, so `--png` takes this picture beside the sample page's.
|
|
1410
|
-
* @param {import('./_settings.mjs').Ctx} ctx
|
|
1411
|
-
* @param {string} slug
|
|
1412
|
-
* @param {import('./_settings.mjs').ThemeData} data
|
|
1413
|
-
* @returns {Promise<{html: string, png: string} | {problem: string}>} the
|
|
1414
|
-
* page and its picture, or why neither is made: something of yours at the
|
|
1415
|
-
* page's name (a file the editor did not write, a link, a folder) is never
|
|
1416
|
-
* written over, as a picture of yours is not
|
|
1417
|
-
*/
|
|
1418
|
-
export async function openStatesPage(ctx, slug, data) {
|
|
1419
|
-
const f = themeFiles(ctx.project.cwd, slug);
|
|
1420
|
-
const html = path.join(f.dir, `sheet-${OPEN_SECTION}.html`);
|
|
1421
|
-
const png = path.join(f.dir, `sheet-${OPEN_SECTION}.png`);
|
|
1422
|
-
const shownHtml = shown(ctx.project.cwd, html);
|
|
1423
|
-
const skipped = `so ${shown(ctx.project.cwd, png)} (the open states) was not taken`;
|
|
1424
|
-
const inWay = pageInTheWay(html);
|
|
1425
|
-
if (inWay)
|
|
1426
|
-
return {
|
|
1427
|
-
problem: `${inTheWayPhrase(shownHtml, inWay, 'the open states page')}, ${skipped}; move ${inWay === 'link' ? 'the link' : 'it'}, then run ${P} show ${slug} --png`,
|
|
1428
|
-
};
|
|
1429
|
-
await renderSheet(ctx, slug, data, {group: OPEN_SECTION});
|
|
1430
|
-
stampSheet(html, slug, ctx.project.cwd);
|
|
1431
|
-
return {html, png};
|
|
1432
|
-
}
|
|
1433
|
-
|
|
1434
|
-
/**
|
|
1435
|
-
* The tallest a family's or the pages section's picture is: a reader fits a
|
|
1436
|
-
* picture to its width, and a taller one comes out too small to read, so it
|
|
1437
|
-
* is cut into pictures this tall (`sheet-inputs-1.png`, `-2` …;
|
|
1438
|
-
* `sheet-pages-1.png` …).
|
|
1439
|
-
*/
|
|
1440
|
-
export const FAMILY_PICTURE_HEIGHT = 1600;
|
|
1441
|
-
|
|
1442
|
-
/**
|
|
1443
|
-
* The family `show --png` pictures when the theme's settings set no part of
|
|
1444
|
-
* its own (a fresh theme, or only theme-wide settings): the buttons, an
|
|
1445
|
-
* overview of the theme's controls beside the sample page.
|
|
1446
|
-
*/
|
|
1447
|
-
export const FAMILY_OVERVIEW = 'actions';
|
|
1448
|
-
|
|
1449
|
-
/**
|
|
1450
|
-
* The families of components with a picture of their own beside the full
|
|
1451
|
-
* sheet, which is too tall to read whole: each section of the sheet but the
|
|
1452
|
-
* overlays (the open states page shows them) and the pages (the sample page
|
|
1453
|
-
* is preview.png).
|
|
1454
|
-
*/
|
|
1455
|
-
export const FAMILY_SECTIONS = Object.freeze(
|
|
1456
|
-
SHOWCASE_GROUPS.filter(g => g !== OPEN_SECTION && g !== 'pages'),
|
|
1457
|
-
);
|
|
1458
|
-
|
|
1459
|
-
/**
|
|
1460
|
-
* The errors of a folder that cannot be written (no permission, read-only,
|
|
1461
|
-
* full): a page the pictures need that cannot be written there is the
|
|
1462
|
-
* pictures' problem, which the picture run names, never a refusal of the
|
|
1463
|
-
* command.
|
|
1464
|
-
*/
|
|
1465
|
-
export const UNWRITABLE = Object.freeze(['EACCES', 'EPERM', 'EROFS', 'ENOSPC']);
|
|
1466
|
-
|
|
1467
|
-
/**
|
|
1468
|
-
* One page for each family of components ({@link FAMILY_SECTIONS}), cut
|
|
1469
|
-
* from the full sheet just made, so each shows its family as the sheet
|
|
1470
|
-
* does, with no render of its own: the sheet's head and bar, then that
|
|
1471
|
-
* family's section. Each is written where `show --section <family>` writes
|
|
1472
|
-
* that family's sheet, and stamped with the build it shows. Something of
|
|
1473
|
-
* yours at a family page's name is never written over: that page is left
|
|
1474
|
-
* out and named.
|
|
1475
|
-
* @param {string} sheet the full sheet, as written
|
|
1476
|
-
* @param {string} slug
|
|
1477
|
-
* @param {string} cwd
|
|
1478
|
-
* @param {readonly string[]} [only] the families to make; every one by default
|
|
1479
|
-
* @returns {{pages: Array<{html: string, png: string, family: string}>, problems: string[]}}
|
|
1480
|
-
*/
|
|
1481
|
-
export function familyPages(sheet, slug, cwd, only = FAMILY_SECTIONS) {
|
|
1482
|
-
/** @type {Array<{html: string, png: string, family: string}>} */
|
|
1483
|
-
const pages = [];
|
|
1484
|
-
/** @type {string[]} */
|
|
1485
|
-
const problems = [];
|
|
1486
|
-
const text = fs.readFileSync(sheet, 'utf8').replace(SHEET_STAMP, '');
|
|
1487
|
-
// Each section of the sheet starts with its own marker, in order, and
|
|
1488
|
-
// holds no section of its own: one ends where the next starts, and the
|
|
1489
|
-
// last at the last section close.
|
|
1490
|
-
const starts = [
|
|
1491
|
-
...text.matchAll(
|
|
1492
|
-
/<section\b[^>]*\sclass="[^"]*\bcs-family-([a-z-]+)\b[^"]*"[^>]*>/g,
|
|
1493
|
-
),
|
|
1494
|
-
].map(m => ({family: m[1], at: /** @type {number} */ (m.index)}));
|
|
1495
|
-
const close = text.lastIndexOf('</section>');
|
|
1496
|
-
if (!starts.length || close < 0) return {pages, problems};
|
|
1497
|
-
const end = close + '</section>'.length;
|
|
1498
|
-
const before = text.slice(0, starts[0].at);
|
|
1499
|
-
const after = text.slice(end);
|
|
1500
|
-
for (const [i, {family, at}] of starts.entries()) {
|
|
1501
|
-
if (!FAMILY_SECTIONS.includes(family) || !only.includes(family)) continue;
|
|
1502
|
-
const html = path.join(path.dirname(sheet), `sheet-${family}.html`);
|
|
1503
|
-
const png = path.join(path.dirname(sheet), `sheet-${family}.png`);
|
|
1504
|
-
const inWay = pageInTheWay(html);
|
|
1505
|
-
if (inWay) {
|
|
1506
|
-
problems.push(
|
|
1507
|
-
`${inTheWayPhrase(shown(cwd, html), inWay, `the ${family} sheet`)}, so ${shown(cwd, png)} was not taken; move ${inWay === 'link' ? 'the link' : 'it'}, then run ${P} show ${slug} --png`,
|
|
1508
|
-
);
|
|
1509
|
-
continue;
|
|
1510
|
-
}
|
|
1511
|
-
const head = before
|
|
1512
|
-
.replace('class="cs-page"', `class="cs-page cs-section-${family}"`)
|
|
1513
|
-
.replace(
|
|
1514
|
-
`<strong>${slug}: every component</strong>`,
|
|
1515
|
-
`<strong>${slug}: every component (${family})</strong>`,
|
|
1516
|
-
);
|
|
1517
|
-
try {
|
|
1518
|
-
writeWhole(
|
|
1519
|
-
html,
|
|
1520
|
-
`${head}${text.slice(at, starts[i + 1]?.at ?? end)}${after}`,
|
|
1521
|
-
);
|
|
1522
|
-
stampSheet(html, slug, cwd);
|
|
1523
|
-
} catch (e) {
|
|
1524
|
-
// A theme folder it cannot write: no family page, and the picture
|
|
1525
|
-
// run names the folder.
|
|
1526
|
-
if (UNWRITABLE.includes(/** @type {any} */ (e)?.code)) break;
|
|
1527
|
-
throw e;
|
|
1528
|
-
}
|
|
1529
|
-
pages.push({html, png, family});
|
|
1530
|
-
}
|
|
1531
|
-
return {pages, problems};
|
|
1532
|
-
}
|
|
1533
|
-
|
|
1534
|
-
/**
|
|
1535
|
-
* Previews after a change: the sample page always; on request, pictures of
|
|
1536
|
-
* it and of the open states ({@link openStatesPage}).
|
|
1537
|
-
* @param {import('./_settings.mjs').Ctx} ctx
|
|
1538
|
-
* @param {string} slug
|
|
1539
|
-
* @param {import('./_settings.mjs').ThemeData} data
|
|
1540
|
-
* @param {boolean} png
|
|
1541
|
-
*/
|
|
1542
|
-
export async function previewAfter(ctx, slug, data, png) {
|
|
1543
|
-
/** @type {string | null} */
|
|
1544
|
-
let preview = null;
|
|
1545
|
-
let cause = ctx.unchecked ?? null;
|
|
1546
|
-
const f0 = themeFiles(ctx.project.cwd, slug);
|
|
1547
|
-
// Something of yours at preview.html (a file, a link, a pipe) is left as
|
|
1548
|
-
// it is: the sample page is not made, so the change is not rendered,
|
|
1549
|
-
// which the result says. (A folder there is named by the write that
|
|
1550
|
-
// fails, below.)
|
|
1551
|
-
const inWay = pageInTheWay(f0.preview);
|
|
1552
|
-
const previewInWay =
|
|
1553
|
-
inWay === 'file' || inWay === 'link' || inWay === 'other' ? inWay : null;
|
|
1554
|
-
if (previewInWay)
|
|
1555
|
-
cause ??= `${inTheWayPhrase(shown(ctx.project.cwd, f0.preview), previewInWay, 'the sample page')}, so the sample page was not made and the change was not rendered; move ${previewInWay === 'link' ? 'the link' : 'it'}, then run ${P} show ${slug}`;
|
|
1556
|
-
else
|
|
1557
|
-
try {
|
|
1558
|
-
preview = await renderPreview(ctx, slug, data);
|
|
1559
|
-
} catch (e) {
|
|
1560
|
-
// The change is already saved: any failure here leaves it unchecked.
|
|
1561
|
-
const code = /** @type {any} */ (e)?.code;
|
|
1562
|
-
cause ??= isRenderFailure(e)
|
|
1563
|
-
? renderCause(ctx.project, /** @type {Error} */ (e).message)
|
|
1564
|
-
: ['ENOSPC', 'EACCES', 'EPERM', 'EROFS', 'EIO'].includes(code)
|
|
1565
|
-
? `preview.html could not be written (${code === 'ENOSPC' ? 'the disk is full' : code}), so it still shows the theme as it was`
|
|
1566
|
-
: // A folder (or another thing) where preview.html goes: the page
|
|
1567
|
-
// was rendered, and could not be written there.
|
|
1568
|
-
code === ERROR_CODES.ERR_WRITE_FAILED ||
|
|
1569
|
-
(fs.existsSync(f0.preview) && !fs.statSync(f0.preview).isFile())
|
|
1570
|
-
? `preview.html could not be written (${shown(ctx.project.cwd, f0.preview)} is ${fs.existsSync(f0.preview) && fs.statSync(f0.preview).isDirectory() ? 'a folder' : 'in the way'}; move it, then run ${P} show ${slug}), so it still shows the theme as it was`
|
|
1571
|
-
: `checking it failed: ${e instanceof Error ? e.message : String(e)}`;
|
|
1572
|
-
}
|
|
1573
|
-
const f = themeFiles(ctx.project.cwd, slug);
|
|
1574
|
-
/**
|
|
1575
|
-
* The pages photographed: the sample page, and with it the open states.
|
|
1576
|
-
* @type {Array<{html: string, png: string, name?: string}>}
|
|
1577
|
-
*/
|
|
1578
|
-
const shotPages = [
|
|
1579
|
-
{html: f.preview, png: f.previewPng, name: SAMPLE_PAGE_NAME},
|
|
1580
|
-
];
|
|
1581
|
-
/** Why the open states were not taken, said with the pictures. @type {string | null} */
|
|
1582
|
-
let openProblem = null;
|
|
1583
|
-
// Made before the sections are judged, so it is current, never marked.
|
|
1584
|
-
if (png && preview) {
|
|
1585
|
-
const open = await openStatesPage(ctx, slug, data).catch(e => {
|
|
1586
|
-
if (/** @type {any} */ (e)?.lockLost) throw e;
|
|
1587
|
-
return {
|
|
1588
|
-
problem: `the open states page could not be made (${e instanceof Error ? e.message.split('\n')[0] : String(e)}), so ${shown(ctx.project.cwd, path.join(f.dir, `sheet-${OPEN_SECTION}.png`))} was not taken`,
|
|
1589
|
-
};
|
|
1590
|
-
});
|
|
1591
|
-
if ('problem' in open) openProblem = open.problem;
|
|
1592
|
-
else shotPages.push(open);
|
|
1593
|
-
}
|
|
1594
|
-
// The sheet of every component is made by show only: after a change it
|
|
1595
|
-
// says, at its top, that it shows the theme as it was.
|
|
1596
|
-
const sheetStale = markSheetStale(f.sheet, slug, ctx.project.cwd);
|
|
1597
|
-
// Section sheets the editor made (they carry its stamp) go out of date the
|
|
1598
|
-
// same way; any other file is left as it is.
|
|
1599
|
-
const sectionsStale = (
|
|
1600
|
-
fs.existsSync(f.dir) ? fs.readdirSync(f.dir) : []
|
|
1601
|
-
).filter(n => {
|
|
1602
|
-
if (!/^sheet-[a-z-]+\.html$/.test(n)) return false;
|
|
1603
|
-
return markSheetStale(path.join(f.dir, n), slug, ctx.project.cwd);
|
|
1604
|
-
});
|
|
1605
|
-
const shots =
|
|
1606
|
-
png && preview
|
|
1607
|
-
? await pictures(ctx.project, shotPages, modesOf(data))
|
|
1608
|
-
: {files: [], problem: null, cutShort: []};
|
|
1609
|
-
return {
|
|
1610
|
-
preview,
|
|
1611
|
-
pictures: shots.files,
|
|
1612
|
-
// Text the sample page's pictures draw cut short: a note and a problem
|
|
1613
|
-
// of the change.
|
|
1614
|
-
cutShort: shots.cutShort,
|
|
1615
|
-
pictureProblem:
|
|
1616
|
-
[openProblem, shots.problem].filter(Boolean).join('; ') || null,
|
|
1617
|
-
notChecked: notChecked(cause),
|
|
1618
|
-
...(sheetStale && !sectionsStale.length
|
|
1619
|
-
? {
|
|
1620
|
-
sheetStale: `sheet.html shows ${slug} as it was before this change; ${P} show ${slug} makes it again`,
|
|
1621
|
-
}
|
|
1622
|
-
: sectionsStale.length
|
|
1623
|
-
? {
|
|
1624
|
-
sheetStale: `${[...(sheetStale ? ['sheet.html'] : []), ...sectionsStale].join(', ')} show ${slug} as it was before this change; ${[
|
|
1625
|
-
...(sheetStale
|
|
1626
|
-
? [`${P} show ${slug} makes sheet.html again`]
|
|
1627
|
-
: []),
|
|
1628
|
-
...sectionsStale.map(
|
|
1629
|
-
n =>
|
|
1630
|
-
`${P} show ${slug} --section ${n.replace(/^sheet-|\.html$/g, '')} makes ${n} again`,
|
|
1631
|
-
),
|
|
1632
|
-
].join(', ')}`,
|
|
1633
|
-
}
|
|
1634
|
-
: {}),
|
|
1635
|
-
};
|
|
1636
|
-
}
|
|
1637
|
-
|
|
1638
|
-
const STALE_MARK = '<!-- astryx: sheet older than the theme -->';
|
|
1639
|
-
|
|
1640
|
-
/** The build a full sheet was made from, recorded in the sheet. */
|
|
1641
|
-
const SHEET_STAMP = /<!-- astryx: sheet of build ([0-9a-f]{16}) -->/;
|
|
1642
|
-
|
|
1643
|
-
/** @param {string} s */
|
|
1644
|
-
const escapeForRegExp = s => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1645
|
-
|
|
1646
|
-
/**
|
|
1647
|
-
* A hash of a theme's built stylesheet and module, or null when either is
|
|
1648
|
-
* missing.
|
|
1649
|
-
* @param {string} cwd
|
|
1650
|
-
* @param {string} slug
|
|
1651
|
-
*/
|
|
1652
|
-
function buildHash(cwd, slug) {
|
|
1653
|
-
const f = themeFiles(cwd, slug);
|
|
1654
|
-
try {
|
|
1655
|
-
return createHash('sha256')
|
|
1656
|
-
.update(fs.readFileSync(f.css))
|
|
1657
|
-
.update('\0')
|
|
1658
|
-
.update(fs.readFileSync(f.js))
|
|
1659
|
-
.digest('hex')
|
|
1660
|
-
.slice(0, 16);
|
|
1661
|
-
} catch {
|
|
1662
|
-
return null;
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
|
|
1666
|
-
/**
|
|
1667
|
-
* Record in a freshly made full sheet the build it shows.
|
|
1668
|
-
* @param {string} file
|
|
1669
|
-
* @param {string} slug
|
|
1670
|
-
* @param {string} cwd
|
|
1671
|
-
*/
|
|
1672
|
-
export function stampSheet(file, slug, cwd) {
|
|
1673
|
-
const hash = buildHash(cwd, slug);
|
|
1674
|
-
if (!hash) return;
|
|
1675
|
-
try {
|
|
1676
|
-
const html = fs.readFileSync(file, 'utf8').replace(SHEET_STAMP, '');
|
|
1677
|
-
// At the end: a comment before the doctype would put the page in
|
|
1678
|
-
// quirks mode.
|
|
1679
|
-
writeWhole(
|
|
1680
|
-
file,
|
|
1681
|
-
`${html.trimEnd()}\n<!-- astryx: sheet of build ${hash} -->\n`,
|
|
1682
|
-
);
|
|
1683
|
-
} catch (e) {
|
|
1684
|
-
if (/** @type {any} */ (e)?.lockLost) throw e;
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
|
-
|
|
1688
|
-
/**
|
|
1689
|
-
* Put a notice at the top of a sheet the last change made out of date
|
|
1690
|
-
* (once), or take it off a sheet made from the build there is now.
|
|
1691
|
-
* Returns whether the sheet is out of date.
|
|
1692
|
-
* @param {string} file
|
|
1693
|
-
* @param {string} slug
|
|
1694
|
-
* @param {string} cwd
|
|
1695
|
-
*/
|
|
1696
|
-
function markSheetStale(file, slug, cwd) {
|
|
1697
|
-
// Only the editor's own sheet: a file of yours there is never written.
|
|
1698
|
-
if (pageInTheWay(file) != null) return false;
|
|
1699
|
-
let html;
|
|
1700
|
-
try {
|
|
1701
|
-
html = fs.readFileSync(file, 'utf8');
|
|
1702
|
-
} catch {
|
|
1703
|
-
return false;
|
|
1704
|
-
}
|
|
1705
|
-
// A sheet made from the build there is now (a change, then its undo)
|
|
1706
|
-
// shows the theme as it is: no banner, and the result says nothing.
|
|
1707
|
-
const made = SHEET_STAMP.exec(html)?.[1];
|
|
1708
|
-
if (made && made === buildHash(cwd, slug)) {
|
|
1709
|
-
if (html.includes(STALE_MARK)) {
|
|
1710
|
-
const clean = html.replace(
|
|
1711
|
-
new RegExp(`${escapeForRegExp(STALE_MARK)}<div[^>]*>[\\s\\S]*?</div>`),
|
|
1712
|
-
'',
|
|
1713
|
-
);
|
|
1714
|
-
try {
|
|
1715
|
-
writeWhole(file, clean);
|
|
1716
|
-
} catch (e) {
|
|
1717
|
-
if (/** @type {any} */ (e)?.lockLost) throw e;
|
|
1718
|
-
}
|
|
1719
|
-
}
|
|
1720
|
-
return false;
|
|
1721
|
-
}
|
|
1722
|
-
if (html.includes(STALE_MARK)) return true;
|
|
1723
|
-
// A section's sheet is made again by its own show.
|
|
1724
|
-
const section = /^sheet-([a-z-]+)\.html$/.exec(path.basename(file))?.[1];
|
|
1725
|
-
const again = `${P} show ${slug}${section ? ` --section ${section}` : ''}`;
|
|
1726
|
-
const banner = `${STALE_MARK}<div style="position:sticky;top:0;z-index:9999;padding:8px 12px;background:#fff3cd;color:#3d2c00;font:14px system-ui,sans-serif;border-bottom:1px solid #e0c870">This sheet shows ${slug} as it was before the last change. Run ${again} to make it again.</div>`;
|
|
1727
|
-
const at = html.search(/<body[^>]*>/i);
|
|
1728
|
-
const next =
|
|
1729
|
-
at < 0 ? banner + html : html.replace(/<body[^>]*>/i, m => `${m}${banner}`);
|
|
1730
|
-
try {
|
|
1731
|
-
// Fenced like every editor write under the theme lock.
|
|
1732
|
-
writeWhole(file, next);
|
|
1733
|
-
} catch (e) {
|
|
1734
|
-
if (/** @type {any} */ (e)?.lockLost) throw e;
|
|
1735
|
-
// Read-only: the note in the result still says so.
|
|
1736
|
-
}
|
|
1737
|
-
return true;
|
|
1738
|
-
}
|
|
1739
|
-
|
|
1740
|
-
/**
|
|
1741
|
-
* The section of the sheet, in lower case, or undefined; a refusal for one
|
|
1742
|
-
* that is not a section.
|
|
1743
|
-
* @param {string | undefined} section
|
|
1744
|
-
* @param {string} [theme] the theme the suggestions name
|
|
1745
|
-
* @param {string} [rest] the command's other options as typed (` --png`):
|
|
1746
|
-
* the offered command keeps them, with only the section fixed
|
|
1747
|
-
* @returns {string | undefined}
|
|
1748
|
-
*/
|
|
1749
|
-
export function checkSection(section, theme = 'my', rest = '') {
|
|
1750
|
-
// A section is offered only when one is within a typo of what was typed;
|
|
1751
|
-
// otherwise the way on is the whole sheet (show with no --section), with
|
|
1752
|
-
// the sections listed in the message. An option where the section
|
|
1753
|
-
// belongs (`--section --png`) was read as its value: it stays an option.
|
|
1754
|
-
const eaten =
|
|
1755
|
-
typeof section === 'string' && /^--[a-z][a-z-]*$/.test(section.trim())
|
|
1756
|
-
? ` ${section.trim()}`
|
|
1757
|
-
: '';
|
|
1758
|
-
const show = `${P} show ${theme}${rest}${rest.includes(eaten) ? '' : eaten}`;
|
|
1759
|
-
if (section === '')
|
|
1760
|
-
refuse(
|
|
1761
|
-
E.ERR_MISSING_ARGUMENT,
|
|
1762
|
-
`--section was given no value; it takes ${SHOWCASE_GROUPS.join(', ')}, and show with no --section makes the whole sheet.`,
|
|
1763
|
-
{run: [show]},
|
|
1764
|
-
);
|
|
1765
|
-
const s = section?.toLowerCase();
|
|
1766
|
-
if (s != null && !SHOWCASE_GROUPS.includes(s)) {
|
|
1767
|
-
const near = SHOWCASE_GROUPS.filter(g => typoNear(s, g));
|
|
1768
|
-
refuse(
|
|
1769
|
-
E.ERR_INVALID_ARGUMENT,
|
|
1770
|
-
`--section takes ${SHOWCASE_GROUPS.join(', ')}, not "${section}"${near.length ? '' : '; show with no --section makes the whole sheet'}.`,
|
|
1771
|
-
{
|
|
1772
|
-
didYouMean: near,
|
|
1773
|
-
run: [near.length === 1 ? `${show} --section ${near[0]}` : show],
|
|
1774
|
-
},
|
|
1775
|
-
);
|
|
1776
|
-
}
|
|
1777
|
-
return s;
|
|
1778
|
-
}
|