@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
|
@@ -0,0 +1,565 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Pictures of HTML pages through a browser already on the machine:
|
|
5
|
+
* the project's Playwright, else a Chrome or Chromium. Each browser runs as
|
|
6
|
+
* its own process group with its own temp folder, time bound and stop.
|
|
7
|
+
* @input the project (its folder and its require), and each page's .html,
|
|
8
|
+
* picture .png, color mode and, optionally, its window and the parts whose
|
|
9
|
+
* sizes it measures
|
|
10
|
+
* @output each picture taken, with what the browser measured in it, or why
|
|
11
|
+
* none was, with the facts a caller words its own advice from
|
|
12
|
+
* @position used by `astryx experimental export --pictures`
|
|
13
|
+
* (api/render/_adapter.mjs);
|
|
14
|
+
* runs the picture scripts in foundation/render (picture-playwright.mjs,
|
|
15
|
+
* picture-chrome.mjs)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import * as fs from 'node:fs';
|
|
19
|
+
import * as path from 'node:path';
|
|
20
|
+
import {spawn} from 'node:child_process';
|
|
21
|
+
import * as os from 'node:os';
|
|
22
|
+
import {fileURLToPath} from 'node:url';
|
|
23
|
+
import {createRequire} from 'node:module';
|
|
24
|
+
import {PICTURE_TAKEN} from '../render/picture-window.mjs';
|
|
25
|
+
import {FONT_PROBE_PREFIX} from '../render/font-probe.mjs';
|
|
26
|
+
import {CUT_SHORT_PREFIX} from '../render/cut-short.mjs';
|
|
27
|
+
import {LOW_CONTRAST_PREFIX} from '../render/drawn-contrast.mjs';
|
|
28
|
+
import {PART_BOXES_PREFIX} from '../render/part-boxes.mjs';
|
|
29
|
+
|
|
30
|
+
/** The script that takes one picture through the project's Playwright. */
|
|
31
|
+
const PLAYWRIGHT_PICTURE = fileURLToPath(
|
|
32
|
+
new URL('../render/picture-playwright.mjs', import.meta.url),
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
/** The script that takes one picture through a Chrome or Chromium. */
|
|
36
|
+
const CHROME_PICTURE = fileURLToPath(
|
|
37
|
+
new URL('../render/picture-chrome.mjs', import.meta.url),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
/** How long a stopped browser may take to close before it is killed. */
|
|
41
|
+
const STOP_GRACE_MS = 5_000;
|
|
42
|
+
|
|
43
|
+
/** The signals that stop a picture run, the terminal closing among them. */
|
|
44
|
+
const STOP_SIGNALS = /** @type {const} */ (['SIGINT', 'SIGTERM', 'SIGHUP']);
|
|
45
|
+
|
|
46
|
+
/** How long a browser may take for one picture before it is stopped. */
|
|
47
|
+
const BROWSER_BOUND_MS = 60_000;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* What the pictures of one run share: the browsers that failed or hung,
|
|
51
|
+
* each with its reason, so a later picture does not wait on them again.
|
|
52
|
+
* @typedef {{failed: Map<string, string>}} PictureRun
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/** A new picture run. @returns {PictureRun} */
|
|
56
|
+
export function newPictureRun() {
|
|
57
|
+
return {failed: new Map()};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** The time a batch adds to its browser's bound for each page after the first. */
|
|
61
|
+
const PAGE_BOUND_MS = 20_000;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* One picture of {@link takePictures}: taken, with its PNG and what was
|
|
65
|
+
* measured in it; a run that ended with a stated reason; or the first not
|
|
66
|
+
* taken, with the facts its caller words its advice from.
|
|
67
|
+
* @typedef {{ok: true, png: string, notes: string[], boxes?: Record<string, Array<[number, number]>>, cutShort?: Array<{part: string | null, text: string, whole: boolean, broken?: boolean, overlaps?: boolean}>, lowContrast?: Array<{part: string, text: string, ratio: number, fg: string, bg: string}>} | {ok: false, reason: string, stopped?: string} | {ok: false, failed: string[], pwFound: boolean, pwMissing: boolean, chrome: string | null}} TakenPicture
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Whole-page PNGs of HTML files, all with one browser: a Playwright the
|
|
72
|
+
* project has installed, else a Chrome or Chromium found on the machine.
|
|
73
|
+
* One browser start for the whole batch, a few pages drawn at once, so a
|
|
74
|
+
* run of many pictures costs about one start. Each browser gets its own
|
|
75
|
+
* time bound, and the next one the pictures still to take when one fails
|
|
76
|
+
* or hangs. A result for each picture, in order, up to the first that was
|
|
77
|
+
* not taken. A taken picture has its `png` path, its `notes` (why an
|
|
78
|
+
* earlier browser did not take it, and the fonts this machine draws in
|
|
79
|
+
* place of a stack) and what the browser's script measured in the page:
|
|
80
|
+
* the text drawn cut short (`cutShort`), the text too faint to read
|
|
81
|
+
* (`lowContrast`) and each asked part's drawn sizes (`boxes`), each absent
|
|
82
|
+
* when nothing was measured. A run that was stopped, or that could not
|
|
83
|
+
* make its temp folder, ends with a result that says so in `reason`.
|
|
84
|
+
* Otherwise the first picture not taken ends the list with what the caller
|
|
85
|
+
* needs to word its own advice: each browser's reason (`failed`), whether
|
|
86
|
+
* a Playwright was found (`pwFound`) and whether it had no browser of its
|
|
87
|
+
* own (`pwMissing`), and the Chrome found, if any (`chrome`).
|
|
88
|
+
* @param {{cwd: string, req?: NodeJS.Require, from?: string}} at the
|
|
89
|
+
* project: its folder, whose path no reason shows, and the require that
|
|
90
|
+
* finds its Playwright (`req`), or a file whose folder it resolves from
|
|
91
|
+
* (`from`)
|
|
92
|
+
* @param {Array<{html: string, png: string, mode: 'light' | 'dark', boxes?: string[], window?: {width: number, height: number, mobile?: boolean}}>} jobs
|
|
93
|
+
* absolute paths; `boxes`: parts whose drawn sizes the picture measures;
|
|
94
|
+
* a job's `window` replaces the default window (picture-window.mjs), such
|
|
95
|
+
* as a phone's
|
|
96
|
+
* @param {PictureRun} [run] what earlier pictures of the same run learned:
|
|
97
|
+
* a browser that failed or hung there is not tried again
|
|
98
|
+
* @returns {Promise<TakenPicture[]>}
|
|
99
|
+
*/
|
|
100
|
+
export async function takePictures(at, jobs, run = newPictureRun()) {
|
|
101
|
+
const req =
|
|
102
|
+
at.req ?? createRequire(at.from ?? path.join(at.cwd, 'package.json'));
|
|
103
|
+
/** @type {TakenPicture[]} */
|
|
104
|
+
const results = [];
|
|
105
|
+
if (!jobs.length) return results;
|
|
106
|
+
/** What was tried and why it could not take the picture. @type {string[]} */
|
|
107
|
+
const failed = [...run.failed.values()];
|
|
108
|
+
/** Whether a Playwright was found without its own browser installed. */
|
|
109
|
+
let pwMissing = false;
|
|
110
|
+
/** Whether a Playwright was found at all. */
|
|
111
|
+
let pwFound = false;
|
|
112
|
+
/** A line with no path of this machine. @param {string} line */
|
|
113
|
+
const local = line => line.split(at.cwd).join('.');
|
|
114
|
+
/**
|
|
115
|
+
* Why a browser did not take the picture: Playwright's first line names
|
|
116
|
+
* only the call ("browserType.launch: Target … closed"); the cause, such
|
|
117
|
+
* as a missing library, is in a later line, so that line comes too.
|
|
118
|
+
* Chrome's startup warnings (dbus, GPU) are not a cause.
|
|
119
|
+
* @param {string} text
|
|
120
|
+
*/
|
|
121
|
+
const causeOf = text => {
|
|
122
|
+
const lines = String(text ?? '')
|
|
123
|
+
.split('\n')
|
|
124
|
+
.map(l => l.replace(/^[\s=<>-]+/, '').trim())
|
|
125
|
+
.filter(Boolean);
|
|
126
|
+
const head =
|
|
127
|
+
meaningfulLine(lines.join('\n')) || 'it stopped with no message';
|
|
128
|
+
const rest = lines
|
|
129
|
+
.slice(lines.indexOf(head) + 1)
|
|
130
|
+
.find(l =>
|
|
131
|
+
/error|cannot|can't|missing|not found|while loading|no such|failed|denied/i.test(
|
|
132
|
+
l,
|
|
133
|
+
),
|
|
134
|
+
);
|
|
135
|
+
return local(rest ? `${head} (${rest})` : head);
|
|
136
|
+
};
|
|
137
|
+
/** The browsers to try, in order: each a picture script and its first argument. */
|
|
138
|
+
/** @type {Array<{who: string, script: string, first: string}>} */
|
|
139
|
+
const tries = [];
|
|
140
|
+
for (const pkg of ['playwright', 'playwright-core']) {
|
|
141
|
+
try {
|
|
142
|
+
const entry = req.resolve(pkg);
|
|
143
|
+
pwFound = true;
|
|
144
|
+
tries.push({
|
|
145
|
+
who: `${pkg}'s own browser`,
|
|
146
|
+
script: PLAYWRIGHT_PICTURE,
|
|
147
|
+
first: entry,
|
|
148
|
+
});
|
|
149
|
+
break;
|
|
150
|
+
} catch {
|
|
151
|
+
// Not installed here.
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const chrome = chromeBinary();
|
|
155
|
+
if (chrome) tries.push({who: chrome, script: CHROME_PICTURE, first: chrome});
|
|
156
|
+
for (const t of tries) {
|
|
157
|
+
if (run.failed.has(t.who)) continue;
|
|
158
|
+
const rest = jobs.slice(results.length);
|
|
159
|
+
const r = await runBrowser(
|
|
160
|
+
t.script,
|
|
161
|
+
[t.first, JSON.stringify(rest)],
|
|
162
|
+
BROWSER_BOUND_MS + (rest.length - 1) * PAGE_BOUND_MS,
|
|
163
|
+
{drop: rest.map(j => j.png)},
|
|
164
|
+
);
|
|
165
|
+
if (r.stoppedBy) {
|
|
166
|
+
results.push({
|
|
167
|
+
ok: false,
|
|
168
|
+
stopped: r.stoppedBy,
|
|
169
|
+
reason: `the pictures were stopped (${r.stoppedBy}) before the browser finished`,
|
|
170
|
+
});
|
|
171
|
+
return results;
|
|
172
|
+
}
|
|
173
|
+
if (r.noTemp) {
|
|
174
|
+
results.push({
|
|
175
|
+
ok: false,
|
|
176
|
+
reason: `no browser was started: the system temp folder cannot be written (${r.noTemp}), and a browser needs a profile folder of its own there; fix the temp folder (TMPDIR), then run the command again`,
|
|
177
|
+
});
|
|
178
|
+
return results;
|
|
179
|
+
}
|
|
180
|
+
// Each picture's own lines, by its place in this browser's share.
|
|
181
|
+
/** @type {Map<number, string[]>} */
|
|
182
|
+
const said = new Map();
|
|
183
|
+
for (const line of String(r.stdout ?? '').split('\n')) {
|
|
184
|
+
const tab = line.indexOf('\t');
|
|
185
|
+
const i = Number(line.slice(0, tab));
|
|
186
|
+
if (tab < 1 || !Number.isInteger(i)) continue;
|
|
187
|
+
said.set(i, [...(said.get(i) ?? []), line.slice(tab + 1)]);
|
|
188
|
+
}
|
|
189
|
+
// The pictures it took whole, in order, up to the first it did not.
|
|
190
|
+
for (const [i, job] of rest.entries()) {
|
|
191
|
+
const lines = said.get(i) ?? [];
|
|
192
|
+
if (!lines.includes(PICTURE_TAKEN) || !fs.existsSync(job.png)) break;
|
|
193
|
+
const out = lines.join('\n');
|
|
194
|
+
results.push({
|
|
195
|
+
ok: true,
|
|
196
|
+
png: job.png,
|
|
197
|
+
notes: [
|
|
198
|
+
...(failed.length
|
|
199
|
+
? [`the picture was taken with ${t.who}; ${failed.join('; ')}`]
|
|
200
|
+
: []),
|
|
201
|
+
...pictureFontNotes(out),
|
|
202
|
+
],
|
|
203
|
+
...measuredCutShort(out),
|
|
204
|
+
...measuredLowContrast(out),
|
|
205
|
+
...measuredBoxes(out),
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
if (results.length === jobs.length) return results;
|
|
209
|
+
// A share it did not finish is the next browser's.
|
|
210
|
+
for (const job of jobs.slice(results.length))
|
|
211
|
+
fs.rmSync(job.png, {force: true});
|
|
212
|
+
const text = r.error ? String(r.error.message) : r.stderr;
|
|
213
|
+
if (
|
|
214
|
+
t.script === PLAYWRIGHT_PICTURE &&
|
|
215
|
+
/Executable doesn't exist|playwright install/i.test(text)
|
|
216
|
+
)
|
|
217
|
+
pwMissing = true;
|
|
218
|
+
const why = r.timedOut
|
|
219
|
+
? `${t.who} did not finish within ${(BROWSER_BOUND_MS + (rest.length - 1) * PAGE_BOUND_MS) / 1000} seconds, so it was stopped`
|
|
220
|
+
: `${t.who} could not take it: ${causeOf(text || (r.status === 0 ? 'it stopped before every picture was taken' : ''))}`;
|
|
221
|
+
run.failed.set(t.who, why);
|
|
222
|
+
failed.push(why);
|
|
223
|
+
}
|
|
224
|
+
results.push({ok: false, failed, pwFound, pwMissing, chrome});
|
|
225
|
+
return results;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** The generic families any font of a common kind stands in for. */
|
|
229
|
+
const PLAIN_GENERICS = ['sans-serif', 'system-ui', 'ui-sans-serif'];
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* What a picture shows in place of a font stack: a role whose stack ends in
|
|
233
|
+
* a generic of a kind (serif, monospace, cursive) and none of whose named
|
|
234
|
+
* families this machine has is drawn in this machine's font for that
|
|
235
|
+
* generic, which may be of another kind (a system with no serif font draws
|
|
236
|
+
* serif in a sans-serif one). A stack that ends in sans-serif falls back
|
|
237
|
+
* to a font of its own kind, so it is not named.
|
|
238
|
+
* @param {string} stdout what the picture script printed
|
|
239
|
+
* @returns {string[]}
|
|
240
|
+
*/
|
|
241
|
+
export function pictureFontNotes(stdout) {
|
|
242
|
+
const line = stdout.split('\n').find(l => l.startsWith(FONT_PROBE_PREFIX));
|
|
243
|
+
if (!line) return [];
|
|
244
|
+
/** @type {Record<string, {stack: string[], shown: string | null} | null>} */
|
|
245
|
+
let probe;
|
|
246
|
+
try {
|
|
247
|
+
probe = JSON.parse(line.slice(FONT_PROBE_PREFIX.length));
|
|
248
|
+
} catch {
|
|
249
|
+
return [];
|
|
250
|
+
}
|
|
251
|
+
/** @type {string[]} */
|
|
252
|
+
const out = [];
|
|
253
|
+
for (const [role, label] of /** @type {const} */ ([
|
|
254
|
+
['heading', 'headings'],
|
|
255
|
+
['body', 'body text'],
|
|
256
|
+
])) {
|
|
257
|
+
const r = probe?.[role];
|
|
258
|
+
const generic = r?.stack.at(-1)?.toLowerCase();
|
|
259
|
+
if (!r?.shown || !generic || PLAIN_GENERICS.includes(generic)) continue;
|
|
260
|
+
const named = r.stack.slice(0, -1);
|
|
261
|
+
const drawn = r.shown.toLowerCase();
|
|
262
|
+
if (!named.length || named.some(f => f.toLowerCase() === drawn)) continue;
|
|
263
|
+
out.push(
|
|
264
|
+
`this machine has none of ${named.join(', ')}, so the pictures draw the ${label} in ${r.shown}, its font for ${generic}; a system with ${named[0]} shows them as set (an open font with its package installed shows everywhere, the pictures included)`,
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
return out;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* The text a picture script measured cut short, from the line it prints
|
|
272
|
+
* after `CUT_SHORT_PREFIX`; nothing when it printed none that reads.
|
|
273
|
+
* @param {string} stdout what the picture script printed
|
|
274
|
+
* @returns {{cutShort?: Array<{part: string | null, text: string, whole: boolean, broken?: boolean, overlaps?: boolean}>}}
|
|
275
|
+
*/
|
|
276
|
+
function measuredCutShort(stdout) {
|
|
277
|
+
const line = stdout.split('\n').find(l => l.startsWith(CUT_SHORT_PREFIX));
|
|
278
|
+
if (!line) return {};
|
|
279
|
+
/** @type {unknown} */
|
|
280
|
+
let found;
|
|
281
|
+
try {
|
|
282
|
+
found = JSON.parse(line.slice(CUT_SHORT_PREFIX.length));
|
|
283
|
+
} catch {
|
|
284
|
+
return {};
|
|
285
|
+
}
|
|
286
|
+
if (!Array.isArray(found)) return {};
|
|
287
|
+
return {
|
|
288
|
+
cutShort: found
|
|
289
|
+
.filter(x => x && typeof x.text === 'string')
|
|
290
|
+
.map(x => ({
|
|
291
|
+
part: typeof x.part === 'string' ? x.part : null,
|
|
292
|
+
text: x.text,
|
|
293
|
+
whole: x.whole === true,
|
|
294
|
+
...(x.broken === true ? {broken: true} : {}),
|
|
295
|
+
...(x.overlaps === true ? {overlaps: true} : {}),
|
|
296
|
+
})),
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* The text a picture script measured too faint to read, from the line it
|
|
302
|
+
* prints after `LOW_CONTRAST_PREFIX`; nothing when it printed none that
|
|
303
|
+
* reads.
|
|
304
|
+
* @param {string} stdout what the picture script printed
|
|
305
|
+
* @returns {{lowContrast?: Array<{part: string, text: string, ratio: number, fg: string, bg: string}>}}
|
|
306
|
+
*/
|
|
307
|
+
function measuredLowContrast(stdout) {
|
|
308
|
+
const line = stdout.split('\n').find(l => l.startsWith(LOW_CONTRAST_PREFIX));
|
|
309
|
+
if (!line) return {};
|
|
310
|
+
/** @type {unknown} */
|
|
311
|
+
let found;
|
|
312
|
+
try {
|
|
313
|
+
found = JSON.parse(line.slice(LOW_CONTRAST_PREFIX.length));
|
|
314
|
+
} catch {
|
|
315
|
+
return {};
|
|
316
|
+
}
|
|
317
|
+
if (!Array.isArray(found)) return {};
|
|
318
|
+
return {
|
|
319
|
+
lowContrast: found.filter(
|
|
320
|
+
x =>
|
|
321
|
+
x &&
|
|
322
|
+
typeof x.part === 'string' &&
|
|
323
|
+
typeof x.text === 'string' &&
|
|
324
|
+
typeof x.ratio === 'number' &&
|
|
325
|
+
/^#[0-9a-f]{6}$/.test(String(x.fg)) &&
|
|
326
|
+
/^#[0-9a-f]{6}$/.test(String(x.bg)),
|
|
327
|
+
),
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* The part sizes a picture script measured, from the line it prints after
|
|
333
|
+
* `PART_BOXES_PREFIX`; nothing when it printed none that reads.
|
|
334
|
+
* @param {string} stdout what the picture script printed
|
|
335
|
+
* @returns {{boxes?: Record<string, Array<[number, number]>>}}
|
|
336
|
+
*/
|
|
337
|
+
function measuredBoxes(stdout) {
|
|
338
|
+
const line = stdout.split('\n').find(l => l.startsWith(PART_BOXES_PREFIX));
|
|
339
|
+
if (!line) return {};
|
|
340
|
+
/** @type {unknown} */
|
|
341
|
+
let found;
|
|
342
|
+
try {
|
|
343
|
+
found = JSON.parse(line.slice(PART_BOXES_PREFIX.length));
|
|
344
|
+
} catch {
|
|
345
|
+
return {};
|
|
346
|
+
}
|
|
347
|
+
if (!found || typeof found !== 'object' || Array.isArray(found)) return {};
|
|
348
|
+
/** @type {Record<string, Array<[number, number]>>} */
|
|
349
|
+
const boxes = {};
|
|
350
|
+
for (const [part, list] of Object.entries(found))
|
|
351
|
+
if (Array.isArray(list))
|
|
352
|
+
boxes[part] = list.filter(
|
|
353
|
+
(/** @type {unknown} */ b) =>
|
|
354
|
+
Array.isArray(b) &&
|
|
355
|
+
b.length === 2 &&
|
|
356
|
+
b.every(n => typeof n === 'number'),
|
|
357
|
+
);
|
|
358
|
+
return {boxes};
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/** A Chrome or Chromium on this machine, at a usual place or on PATH. */
|
|
362
|
+
function chromeBinary() {
|
|
363
|
+
const names = [
|
|
364
|
+
'google-chrome',
|
|
365
|
+
'google-chrome-stable',
|
|
366
|
+
'chromium',
|
|
367
|
+
'chromium-browser',
|
|
368
|
+
'chrome',
|
|
369
|
+
];
|
|
370
|
+
const fixed = [
|
|
371
|
+
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
|
372
|
+
'/Applications/Chromium.app/Contents/MacOS/Chromium',
|
|
373
|
+
'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
|
|
374
|
+
'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
|
|
375
|
+
];
|
|
376
|
+
// Only a file that runs: a folder or a file with no execute permission
|
|
377
|
+
// by a browser's name is passed over, and the search goes on.
|
|
378
|
+
/** @param {string} f */
|
|
379
|
+
const runs = f => {
|
|
380
|
+
try {
|
|
381
|
+
if (!fs.statSync(f).isFile()) return false;
|
|
382
|
+
if (process.platform !== 'win32') fs.accessSync(f, fs.constants.X_OK);
|
|
383
|
+
return true;
|
|
384
|
+
} catch {
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
for (const f of fixed) if (runs(f)) return f;
|
|
389
|
+
for (const dir of (process.env.PATH ?? '').split(path.delimiter)) {
|
|
390
|
+
for (const n of names) {
|
|
391
|
+
const f = path.join(dir, n);
|
|
392
|
+
if (dir && runs(f)) return f;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return null;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Run a picture script (one browser, one picture) as its own process group,
|
|
400
|
+
* without blocking this process. The one owner of every browser run:
|
|
401
|
+
* - a temp folder of its own (TMPDIR, TMP, TEMP), where the browser keeps
|
|
402
|
+
* its profile; with none to make, nothing runs (`noTemp`);
|
|
403
|
+
* - a time bound (`timedOut`);
|
|
404
|
+
* - a stop (SIGINT, SIGTERM, SIGHUP) that reaches the run stops it
|
|
405
|
+
* (`stoppedBy`), then ends this process as the stop would have.
|
|
406
|
+
* A stop or the bound asks the whole group to close, waits for it (killing
|
|
407
|
+
* it past a short grace), then removes the temp folder and the `drop` files
|
|
408
|
+
* (a picture part a stopped run leaves); a run that ends on its own removes
|
|
409
|
+
* the temp folder only, and gives what the script wrote on its standard
|
|
410
|
+
* output (`stdout`: what it measured in the page).
|
|
411
|
+
* @param {string} script a picture script
|
|
412
|
+
* @param {string[]} args
|
|
413
|
+
* @param {number} [bound] milliseconds before the run is stopped
|
|
414
|
+
* @param {{drop?: string[]}} [opts]
|
|
415
|
+
* @returns {Promise<{status: number | null, signal: string | null, stderr: string, stdout?: string, error?: Error, stoppedBy?: string, timedOut?: boolean, noTemp?: string}>}
|
|
416
|
+
*/
|
|
417
|
+
export function runBrowser(script, args, bound = BROWSER_BOUND_MS, opts = {}) {
|
|
418
|
+
const drop = opts.drop ?? [];
|
|
419
|
+
/** @type {string} */
|
|
420
|
+
let temp;
|
|
421
|
+
try {
|
|
422
|
+
temp = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-browser-'));
|
|
423
|
+
} catch (e) {
|
|
424
|
+
return Promise.resolve({
|
|
425
|
+
status: null,
|
|
426
|
+
signal: null,
|
|
427
|
+
stderr: '',
|
|
428
|
+
noTemp: String(/** @type {any} */ (e)?.code ?? e),
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
return new Promise(resolve => {
|
|
432
|
+
let stderr = '';
|
|
433
|
+
let stdout = '';
|
|
434
|
+
const posix = process.platform !== 'win32';
|
|
435
|
+
const child = spawn(process.execPath, [script, ...args], {
|
|
436
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
437
|
+
env: {...process.env, TMPDIR: temp, TMP: temp, TEMP: temp},
|
|
438
|
+
// A group of its own, so a stop reaches the browser it starts too.
|
|
439
|
+
detached: posix,
|
|
440
|
+
});
|
|
441
|
+
/** @param {NodeJS.Signals} sig */
|
|
442
|
+
const signalAll = sig => {
|
|
443
|
+
try {
|
|
444
|
+
if (posix && child.pid) process.kill(-child.pid, sig);
|
|
445
|
+
else child.kill(sig);
|
|
446
|
+
} catch {
|
|
447
|
+
// Gone already.
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
const closed = new Promise(done => child.once('close', done));
|
|
451
|
+
/** @param {string[]} files */
|
|
452
|
+
const remove = files => {
|
|
453
|
+
for (const f of files)
|
|
454
|
+
try {
|
|
455
|
+
fs.rmSync(f, {recursive: true, force: true});
|
|
456
|
+
} catch {
|
|
457
|
+
// Gone already.
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
/** The temp folder goes on every way out; `drop` only with a stop. */
|
|
461
|
+
const clean = () => remove([temp]);
|
|
462
|
+
/** Close the group (killed past the grace), then clean up. */
|
|
463
|
+
const finish = async () => {
|
|
464
|
+
signalAll('SIGTERM');
|
|
465
|
+
const grace = new Promise(done =>
|
|
466
|
+
setTimeout(done, STOP_GRACE_MS).unref(),
|
|
467
|
+
);
|
|
468
|
+
if ((await Promise.race([closed.then(() => true), grace])) !== true) {
|
|
469
|
+
signalAll('SIGKILL');
|
|
470
|
+
await closed;
|
|
471
|
+
}
|
|
472
|
+
remove([temp, ...drop]);
|
|
473
|
+
};
|
|
474
|
+
// This process ending some other way: the group is killed, and the temp
|
|
475
|
+
// folder and the unfinished files removed, as far as an exit allows.
|
|
476
|
+
const onExit = () => {
|
|
477
|
+
signalAll('SIGKILL');
|
|
478
|
+
remove([temp, ...drop]);
|
|
479
|
+
};
|
|
480
|
+
process.once('exit', onExit);
|
|
481
|
+
child.stderr?.setEncoding('utf8');
|
|
482
|
+
child.stderr?.on('data', d => {
|
|
483
|
+
if (stderr.length < 8000) stderr += d;
|
|
484
|
+
});
|
|
485
|
+
child.stdout?.setEncoding('utf8');
|
|
486
|
+
child.stdout?.on('data', d => {
|
|
487
|
+
// Room for every line the script prints: the fonts, and the text cut
|
|
488
|
+
// short on a page of every component.
|
|
489
|
+
if (stdout.length < 64_000) stdout += d;
|
|
490
|
+
});
|
|
491
|
+
/** Set once the run is being stopped (bound, signal): it ends there. */
|
|
492
|
+
let stopping = false;
|
|
493
|
+
let settled = false;
|
|
494
|
+
/** @param {Awaited<ReturnType<typeof runBrowser>>} out */
|
|
495
|
+
const settle = out => {
|
|
496
|
+
if (settled) return;
|
|
497
|
+
settled = true;
|
|
498
|
+
clearTimeout(timer);
|
|
499
|
+
process.removeListener('exit', onExit);
|
|
500
|
+
for (const sig of STOP_SIGNALS) process.removeListener(sig, onStop);
|
|
501
|
+
resolve(out);
|
|
502
|
+
};
|
|
503
|
+
const timer = setTimeout(() => {
|
|
504
|
+
stopping = true;
|
|
505
|
+
void finish().then(() =>
|
|
506
|
+
settle({status: null, signal: null, stderr, timedOut: true}),
|
|
507
|
+
);
|
|
508
|
+
}, bound);
|
|
509
|
+
/** @param {NodeJS.Signals} sig */
|
|
510
|
+
const onStop = async sig => {
|
|
511
|
+
stopping = true;
|
|
512
|
+
for (const s of STOP_SIGNALS) process.removeListener(s, onStop);
|
|
513
|
+
// A second stop during the grace does not wait for it: the group is
|
|
514
|
+
// killed and the files removed at once, then the process ends.
|
|
515
|
+
/** @param {NodeJS.Signals} again */
|
|
516
|
+
const onAgain = again => {
|
|
517
|
+
for (const s of STOP_SIGNALS) process.removeListener(s, onAgain);
|
|
518
|
+
signalAll('SIGKILL');
|
|
519
|
+
remove([temp, ...drop]);
|
|
520
|
+
if (process.listenerCount(again) === 0)
|
|
521
|
+
process.kill(process.pid, again);
|
|
522
|
+
};
|
|
523
|
+
for (const s of STOP_SIGNALS) process.once(s, onAgain);
|
|
524
|
+
await finish();
|
|
525
|
+
for (const s of STOP_SIGNALS) process.removeListener(s, onAgain);
|
|
526
|
+
settle({status: null, signal: null, stderr, stoppedBy: sig});
|
|
527
|
+
// Nothing else listening: the stop ends this process, as it would
|
|
528
|
+
// have without this listener.
|
|
529
|
+
if (process.listenerCount(sig) === 0) process.kill(process.pid, sig);
|
|
530
|
+
};
|
|
531
|
+
for (const sig of STOP_SIGNALS) process.once(sig, onStop);
|
|
532
|
+
child.once('error', error => {
|
|
533
|
+
clean();
|
|
534
|
+
settle({status: null, signal: null, stderr, error});
|
|
535
|
+
});
|
|
536
|
+
child.once('close', (status, signal) => {
|
|
537
|
+
if (stopping) return;
|
|
538
|
+
clean();
|
|
539
|
+
settle({status, signal, stderr, stdout});
|
|
540
|
+
});
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* The first stderr line that says something about the picture: Chrome's
|
|
546
|
+
* startup warnings (dbus, GPU, sandbox notices) come first on Linux and
|
|
547
|
+
* say nothing about why no picture was written.
|
|
548
|
+
* @param {string} text
|
|
549
|
+
*/
|
|
550
|
+
export function meaningfulLine(text) {
|
|
551
|
+
const lines = String(text ?? '')
|
|
552
|
+
.split(/\r?\n/)
|
|
553
|
+
.map(l => l.trim())
|
|
554
|
+
.filter(Boolean);
|
|
555
|
+
return (
|
|
556
|
+
lines.find(
|
|
557
|
+
l =>
|
|
558
|
+
!/dbus|bus\.cc|gpu_|gl_|sandbox|fontconfig|crashpad|DevTools listening|WARNING:/i.test(
|
|
559
|
+
l,
|
|
560
|
+
),
|
|
561
|
+
) ??
|
|
562
|
+
lines[0] ??
|
|
563
|
+
''
|
|
564
|
+
);
|
|
565
|
+
}
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
* @input a lock folder and the work to run under it
|
|
10
10
|
* @output the work's result; the lock is released on the way out, also on
|
|
11
11
|
* Ctrl-C, and only when it is still this run's own
|
|
12
|
-
* @position foundation/release —
|
|
12
|
+
* @position foundation/release — `stillHolds` is read by
|
|
13
|
+
* api/integration/add-helpers.mjs.
|
|
13
14
|
*/
|
|
14
15
|
|
|
15
16
|
import * as fs from 'node:fs';
|
|
@@ -142,7 +143,7 @@ export async function withFolderLock(
|
|
|
142
143
|
// computer whose processes this run cannot check).
|
|
143
144
|
for (let waited = 0; !tryLock(lockDir, {leased: true}); waited += 50) {
|
|
144
145
|
// The release cache's own judge of silence (what this process saw of
|
|
145
|
-
// the record), with
|
|
146
|
+
// the record), with a shorter window. The lock is judged by
|
|
146
147
|
// its identity on disk, so the one moved aside is the one judged.
|
|
147
148
|
const judged = lockIdentity(lockDir);
|
|
148
149
|
if (
|
|
@@ -40,8 +40,8 @@ export function cutShortText(): Array<{
|
|
|
40
40
|
* (`flex-shrink: 0` on it, the line the editor offers) draws it whole;
|
|
41
41
|
* `CUT_SHORT_PREFIX`, the line prefix a picture script prints it after.
|
|
42
42
|
* @position run by picture-chrome.mjs and picture-playwright.mjs once the
|
|
43
|
-
* page is drawn as the picture shows it; read back by `
|
|
44
|
-
*
|
|
43
|
+
* page is drawn as the picture shows it; read back by `takePictures` in
|
|
44
|
+
* foundation/pictures/pictures.mjs from the script's stdout
|
|
45
45
|
*/
|
|
46
46
|
/** The line prefix a picture script prints the measurement after. */
|
|
47
47
|
export const CUT_SHORT_PREFIX: "astryx-cut-short:";
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
* (`flex-shrink: 0` on it, the line the editor offers) draws it whole;
|
|
12
12
|
* `CUT_SHORT_PREFIX`, the line prefix a picture script prints it after.
|
|
13
13
|
* @position run by picture-chrome.mjs and picture-playwright.mjs once the
|
|
14
|
-
* page is drawn as the picture shows it; read back by `
|
|
15
|
-
*
|
|
14
|
+
* page is drawn as the picture shows it; read back by `takePictures` in
|
|
15
|
+
* foundation/pictures/pictures.mjs from the script's stdout
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
/* global document, getComputedStyle, HTMLElement -- cutShortText runs in the page */
|
|
@@ -33,8 +33,8 @@ export function lowContrastText(): Array<{
|
|
|
33
33
|
* two colors as drawn; `LOW_CONTRAST_PREFIX`, the line prefix a picture
|
|
34
34
|
* script prints it after.
|
|
35
35
|
* @position run by picture-chrome.mjs and picture-playwright.mjs once the
|
|
36
|
-
* page is drawn as the picture shows it; read back by `
|
|
37
|
-
*
|
|
36
|
+
* page is drawn as the picture shows it; read back by `takePictures` in
|
|
37
|
+
* foundation/pictures/pictures.mjs from the script's stdout
|
|
38
38
|
*/
|
|
39
39
|
/** The line prefix a picture script prints the measurement after. */
|
|
40
40
|
export const LOW_CONTRAST_PREFIX: "astryx-low-contrast:";
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
* two colors as drawn; `LOW_CONTRAST_PREFIX`, the line prefix a picture
|
|
10
10
|
* script prints it after.
|
|
11
11
|
* @position run by picture-chrome.mjs and picture-playwright.mjs once the
|
|
12
|
-
* page is drawn as the picture shows it; read back by `
|
|
13
|
-
*
|
|
12
|
+
* page is drawn as the picture shows it; read back by `takePictures` in
|
|
13
|
+
* foundation/pictures/pictures.mjs from the script's stdout
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
/* global document, getComputedStyle -- lowContrastText runs in the page */
|
|
@@ -20,8 +20,8 @@ export function probeFonts(send: (method: string, params?: Record<string, unknow
|
|
|
20
20
|
* result after.
|
|
21
21
|
* @position Run by the picture scripts (picture-chrome.mjs,
|
|
22
22
|
* picture-playwright.mjs) after the picture is taken; read by
|
|
23
|
-
* `
|
|
24
|
-
* machine has none of the families for.
|
|
23
|
+
* `pictureFontNotes` in foundation/pictures/pictures.mjs, which names a
|
|
24
|
+
* stack this machine has none of the families for.
|
|
25
25
|
*/
|
|
26
26
|
/** The line prefix a picture script prints the probe's result after. */
|
|
27
27
|
export const FONT_PROBE_PREFIX: "astryx-fonts:";
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
* result after.
|
|
10
10
|
* @position Run by the picture scripts (picture-chrome.mjs,
|
|
11
11
|
* picture-playwright.mjs) after the picture is taken; read by
|
|
12
|
-
* `
|
|
13
|
-
* machine has none of the families for.
|
|
12
|
+
* `pictureFontNotes` in foundation/pictures/pictures.mjs, which names a
|
|
13
|
+
* stack this machine has none of the families for.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
/** The line prefix a picture script prints the probe's result after. */
|
|
@@ -18,8 +18,7 @@
|
|
|
18
18
|
* {@link layerPlaceholder} gives through the global the worker installs, and
|
|
19
19
|
* the worker puts the part there, drawn, with each overlay it opened after it.
|
|
20
20
|
*
|
|
21
|
-
* @position foundation/render — used by page-worker.mjs
|
|
22
|
-
* theme editor writes (_catalog.mjs)
|
|
21
|
+
* @position foundation/render — used by page-worker.mjs
|
|
23
22
|
*/
|
|
24
23
|
|
|
25
24
|
import {desktopMatches} from './picture-window.mjs';
|