@iksnerd/blazon 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +259 -2
- package/THIRD-PARTY-NOTICES.md +60 -0
- package/bin/blazon.js +4 -0
- package/dist/builder/site-builder.d.ts +10 -0
- package/dist/builder/site-builder.d.ts.map +1 -0
- package/dist/chunks/site-builder-CPfjBOmR.js +13804 -0
- package/dist/cli/commands/approvals.d.ts +8 -0
- package/dist/cli/commands/approvals.d.ts.map +1 -0
- package/dist/cli/commands/build.d.ts +8 -0
- package/dist/cli/commands/build.d.ts.map +1 -0
- package/dist/cli/commands/check.d.ts +33 -0
- package/dist/cli/commands/check.d.ts.map +1 -0
- package/dist/cli/commands/cwd.d.ts +14 -0
- package/dist/cli/commands/cwd.d.ts.map +1 -0
- package/dist/cli/commands/dev.d.ts +5 -0
- package/dist/cli/commands/dev.d.ts.map +1 -0
- package/dist/cli/commands/doctor.d.ts +34 -0
- package/dist/cli/commands/doctor.d.ts.map +1 -0
- package/dist/cli/commands/drift.d.ts +11 -0
- package/dist/cli/commands/drift.d.ts.map +1 -0
- package/dist/cli/commands/explain.d.ts +5 -0
- package/dist/cli/commands/explain.d.ts.map +1 -0
- package/dist/cli/commands/init.d.ts +46 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/mcp-check.d.ts +57 -0
- package/dist/cli/commands/mcp-check.d.ts.map +1 -0
- package/dist/cli/commands/mcp.d.ts +13 -0
- package/dist/cli/commands/mcp.d.ts.map +1 -0
- package/dist/cli/commands/pin.d.ts +7 -0
- package/dist/cli/commands/pin.d.ts.map +1 -0
- package/dist/cli/commands/plugin.d.ts +32 -0
- package/dist/cli/commands/plugin.d.ts.map +1 -0
- package/dist/cli/commands/preview.d.ts +5 -0
- package/dist/cli/commands/preview.d.ts.map +1 -0
- package/dist/cli/commands/tokens.d.ts +5 -0
- package/dist/cli/commands/tokens.d.ts.map +1 -0
- package/dist/cli/errors.d.ts +53 -0
- package/dist/cli/errors.d.ts.map +1 -0
- package/dist/cli/handlers/brand.d.ts +7 -0
- package/dist/cli/handlers/brand.d.ts.map +1 -0
- package/dist/cli/handlers/can.d.ts +7 -0
- package/dist/cli/handlers/can.d.ts.map +1 -0
- package/dist/cli/handlers/fonts.d.ts +4 -0
- package/dist/cli/handlers/fonts.d.ts.map +1 -0
- package/dist/cli/handlers/get.d.ts +7 -0
- package/dist/cli/handlers/get.d.ts.map +1 -0
- package/dist/cli/handlers/index.d.ts +8 -0
- package/dist/cli/handlers/index.d.ts.map +1 -0
- package/dist/cli/handlers/list.d.ts +7 -0
- package/dist/cli/handlers/list.d.ts.map +1 -0
- package/dist/cli/handlers/logo.d.ts +4 -0
- package/dist/cli/handlers/logo.d.ts.map +1 -0
- package/dist/cli/handlers/rules.d.ts +10 -0
- package/dist/cli/handlers/rules.d.ts.map +1 -0
- package/dist/cli/handlers/types.d.ts +17 -0
- package/dist/cli/handlers/types.d.ts.map +1 -0
- package/dist/cli/help.d.ts +18 -0
- package/dist/cli/help.d.ts.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +3850 -0
- package/dist/cli/init-flow.d.ts +24 -0
- package/dist/cli/init-flow.d.ts.map +1 -0
- package/dist/cli/init-ui.d.ts +20 -0
- package/dist/cli/init-ui.d.ts.map +1 -0
- package/dist/cli/json.d.ts +18 -0
- package/dist/cli/json.d.ts.map +1 -0
- package/dist/cli/operations.d.ts +11 -0
- package/dist/cli/operations.d.ts.map +1 -0
- package/dist/cli/options.d.ts +8 -0
- package/dist/cli/options.d.ts.map +1 -0
- package/dist/cli/project.d.ts +8 -0
- package/dist/cli/project.d.ts.map +1 -0
- package/dist/cli/read.d.ts +13 -0
- package/dist/cli/read.d.ts.map +1 -0
- package/dist/cli/where.d.ts +10 -0
- package/dist/cli/where.d.ts.map +1 -0
- package/dist/core/assets/categories.d.ts +47 -0
- package/dist/core/assets/categories.d.ts.map +1 -0
- package/dist/core/assets/fields.d.ts +12 -0
- package/dist/core/assets/fields.d.ts.map +1 -0
- package/dist/core/assets/image-size.d.ts +10 -0
- package/dist/core/assets/image-size.d.ts.map +1 -0
- package/dist/core/assets/measure.d.ts +22 -0
- package/dist/core/assets/measure.d.ts.map +1 -0
- package/dist/core/assets/scanner.d.ts +26 -0
- package/dist/core/assets/scanner.d.ts.map +1 -0
- package/dist/core/assets/sidecar.d.ts +22 -0
- package/dist/core/assets/sidecar.d.ts.map +1 -0
- package/dist/core/blazon-pin.d.ts +36 -0
- package/dist/core/blazon-pin.d.ts.map +1 -0
- package/dist/core/brand/export.d.ts +128 -0
- package/dist/core/brand/export.d.ts.map +1 -0
- package/dist/core/brand/schema.d.ts +1000 -0
- package/dist/core/brand/schema.d.ts.map +1 -0
- package/dist/core/brand-theme.d.ts +16 -0
- package/dist/core/brand-theme.d.ts.map +1 -0
- package/dist/core/checker/approvals.d.ts +15 -0
- package/dist/core/checker/approvals.d.ts.map +1 -0
- package/dist/core/checker/cascade.d.ts +8 -0
- package/dist/core/checker/cascade.d.ts.map +1 -0
- package/dist/core/checker/catalogue.d.ts +609 -0
- package/dist/core/checker/catalogue.d.ts.map +1 -0
- package/dist/core/checker/contrast.d.ts +30 -0
- package/dist/core/checker/contrast.d.ts.map +1 -0
- package/dist/core/checker/duplicates.d.ts +3 -0
- package/dist/core/checker/duplicates.d.ts.map +1 -0
- package/dist/core/checker/fixes.d.ts +6 -0
- package/dist/core/checker/fixes.d.ts.map +1 -0
- package/dist/core/checker/font-meta.d.ts +8 -0
- package/dist/core/checker/font-meta.d.ts.map +1 -0
- package/dist/core/checker/index.d.ts +23 -0
- package/dist/core/checker/index.d.ts.map +1 -0
- package/dist/core/checker/location.d.ts +7 -0
- package/dist/core/checker/location.d.ts.map +1 -0
- package/dist/core/checker/logo-rules.d.ts +19 -0
- package/dist/core/checker/logo-rules.d.ts.map +1 -0
- package/dist/core/checker/logo-surfaces.d.ts +7 -0
- package/dist/core/checker/logo-surfaces.d.ts.map +1 -0
- package/dist/core/checker/page-tokens.d.ts +5 -0
- package/dist/core/checker/page-tokens.d.ts.map +1 -0
- package/dist/core/checker/print.d.ts +9 -0
- package/dist/core/checker/print.d.ts.map +1 -0
- package/dist/core/checker/proportion.d.ts +3 -0
- package/dist/core/checker/proportion.d.ts.map +1 -0
- package/dist/core/checker/review.d.ts +40 -0
- package/dist/core/checker/review.d.ts.map +1 -0
- package/dist/core/checker/source.d.ts +4 -0
- package/dist/core/checker/source.d.ts.map +1 -0
- package/dist/core/checker/spdx.d.ts +8 -0
- package/dist/core/checker/spdx.d.ts.map +1 -0
- package/dist/core/checker/tier.d.ts +3 -0
- package/dist/core/checker/tier.d.ts.map +1 -0
- package/dist/core/checker/usage.d.ts +4 -0
- package/dist/core/checker/usage.d.ts.map +1 -0
- package/dist/core/checker/variables.d.ts +8 -0
- package/dist/core/checker/variables.d.ts.map +1 -0
- package/dist/core/colors.d.ts +10 -0
- package/dist/core/colors.d.ts.map +1 -0
- package/dist/core/config/defaults.d.ts +3 -0
- package/dist/core/config/defaults.d.ts.map +1 -0
- package/dist/core/config/index.d.ts +15 -0
- package/dist/core/config/index.d.ts.map +1 -0
- package/dist/core/config/validate.d.ts +21 -0
- package/dist/core/config/validate.d.ts.map +1 -0
- package/dist/core/config/vocabulary.d.ts +10 -0
- package/dist/core/config/vocabulary.d.ts.map +1 -0
- package/dist/core/confine.d.ts +25 -0
- package/dist/core/confine.d.ts.map +1 -0
- package/dist/core/docs/directives.d.ts +161 -0
- package/dist/core/docs/directives.d.ts.map +1 -0
- package/dist/core/docs/parser.d.ts +7 -0
- package/dist/core/docs/parser.d.ts.map +1 -0
- package/dist/core/docs/sections.d.ts +11 -0
- package/dist/core/docs/sections.d.ts.map +1 -0
- package/dist/core/drift/compare.d.ts +30 -0
- package/dist/core/drift/compare.d.ts.map +1 -0
- package/dist/core/drift/read.d.ts +22 -0
- package/dist/core/drift/read.d.ts.map +1 -0
- package/dist/core/email-signature.d.ts +35 -0
- package/dist/core/email-signature.d.ts.map +1 -0
- package/dist/core/emit.d.ts +22 -0
- package/dist/core/emit.d.ts.map +1 -0
- package/dist/core/fonts.d.ts +43 -0
- package/dist/core/fonts.d.ts.map +1 -0
- package/dist/core/icons/icon-sets.d.ts +22 -0
- package/dist/core/icons/icon-sets.d.ts.map +1 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/init/answers.d.ts +45 -0
- package/dist/core/init/answers.d.ts.map +1 -0
- package/dist/core/init/from-site/apply.d.ts +7 -0
- package/dist/core/init/from-site/apply.d.ts.map +1 -0
- package/dist/core/init/from-site/clean-colors.d.ts +21 -0
- package/dist/core/init/from-site/clean-colors.d.ts.map +1 -0
- package/dist/core/init/from-site/colors.d.ts +10 -0
- package/dist/core/init/from-site/colors.d.ts.map +1 -0
- package/dist/core/init/from-site/context.d.ts +24 -0
- package/dist/core/init/from-site/context.d.ts.map +1 -0
- package/dist/core/init/from-site/fonts.d.ts +10 -0
- package/dist/core/init/from-site/fonts.d.ts.map +1 -0
- package/dist/core/init/from-site/html.d.ts +10 -0
- package/dist/core/init/from-site/html.d.ts.map +1 -0
- package/dist/core/init/from-site/index.d.ts +6 -0
- package/dist/core/init/from-site/index.d.ts.map +1 -0
- package/dist/core/init/from-site/inspect.d.ts +4 -0
- package/dist/core/init/from-site/inspect.d.ts.map +1 -0
- package/dist/core/init/from-site/logo.d.ts +20 -0
- package/dist/core/init/from-site/logo.d.ts.map +1 -0
- package/dist/core/init/from-site/sections/colors.d.ts +4 -0
- package/dist/core/init/from-site/sections/colors.d.ts.map +1 -0
- package/dist/core/init/from-site/sections/config.d.ts +10 -0
- package/dist/core/init/from-site/sections/config.d.ts.map +1 -0
- package/dist/core/init/from-site/sections/directives.d.ts +3 -0
- package/dist/core/init/from-site/sections/directives.d.ts.map +1 -0
- package/dist/core/init/from-site/sections/fonts.d.ts +8 -0
- package/dist/core/init/from-site/sections/fonts.d.ts.map +1 -0
- package/dist/core/init/from-site/sections/intro.d.ts +4 -0
- package/dist/core/init/from-site/sections/intro.d.ts.map +1 -0
- package/dist/core/init/from-site/sections/logo.d.ts +9 -0
- package/dist/core/init/from-site/sections/logo.d.ts.map +1 -0
- package/dist/core/init/from-site/sections/placeholder.d.ts +5 -0
- package/dist/core/init/from-site/sections/placeholder.d.ts.map +1 -0
- package/dist/core/init/from-site/tree.d.ts +14 -0
- package/dist/core/init/from-site/tree.d.ts.map +1 -0
- package/dist/core/init/from-site/types.d.ts +37 -0
- package/dist/core/init/from-site/types.d.ts.map +1 -0
- package/dist/core/init/palette.d.ts +34 -0
- package/dist/core/init/palette.d.ts.map +1 -0
- package/dist/core/init/prompts.d.ts +78 -0
- package/dist/core/init/prompts.d.ts.map +1 -0
- package/dist/core/init/shared/google-fonts.d.ts +4 -0
- package/dist/core/init/shared/google-fonts.d.ts.map +1 -0
- package/dist/core/init/shared/hex.d.ts +6 -0
- package/dist/core/init/shared/hex.d.ts.map +1 -0
- package/dist/core/init/shared/svg.d.ts +3 -0
- package/dist/core/init/shared/svg.d.ts.map +1 -0
- package/dist/core/init/vocabulary.d.ts +42 -0
- package/dist/core/init/vocabulary.d.ts.map +1 -0
- package/dist/core/inputs.d.ts +25 -0
- package/dist/core/inputs.d.ts.map +1 -0
- package/dist/core/logo/lockup.d.ts +54 -0
- package/dist/core/logo/lockup.d.ts.map +1 -0
- package/dist/core/logo.d.ts +23 -0
- package/dist/core/logo.d.ts.map +1 -0
- package/dist/core/mcp-config.d.ts +65 -0
- package/dist/core/mcp-config.d.ts.map +1 -0
- package/dist/core/operations/check.d.ts +8 -0
- package/dist/core/operations/check.d.ts.map +1 -0
- package/dist/core/operations/index.d.ts +7 -0
- package/dist/core/operations/index.d.ts.map +1 -0
- package/dist/core/operations/limits.d.ts +6 -0
- package/dist/core/operations/limits.d.ts.map +1 -0
- package/dist/core/operations/list.d.ts +8 -0
- package/dist/core/operations/list.d.ts.map +1 -0
- package/dist/core/operations/project.d.ts +10 -0
- package/dist/core/operations/project.d.ts.map +1 -0
- package/dist/core/operations/types.d.ts +96 -0
- package/dist/core/operations/types.d.ts.map +1 -0
- package/dist/core/operations/validate.d.ts +4 -0
- package/dist/core/operations/validate.d.ts.map +1 -0
- package/dist/core/order.d.ts +9 -0
- package/dist/core/order.d.ts.map +1 -0
- package/dist/core/outputs.d.ts +22 -0
- package/dist/core/outputs.d.ts.map +1 -0
- package/dist/core/package-name.d.ts +3 -0
- package/dist/core/package-name.d.ts.map +1 -0
- package/dist/core/package-root.d.ts +3 -0
- package/dist/core/package-root.d.ts.map +1 -0
- package/dist/core/plugin-name.d.ts +27 -0
- package/dist/core/plugin-name.d.ts.map +1 -0
- package/dist/core/preflight.d.ts +10 -0
- package/dist/core/preflight.d.ts.map +1 -0
- package/dist/core/read/can.d.ts +44 -0
- package/dist/core/read/can.d.ts.map +1 -0
- package/dist/core/read/fonts.d.ts +47 -0
- package/dist/core/read/fonts.d.ts.map +1 -0
- package/dist/core/read/index.d.ts +8 -0
- package/dist/core/read/index.d.ts.map +1 -0
- package/dist/core/read/list.d.ts +28 -0
- package/dist/core/read/list.d.ts.map +1 -0
- package/dist/core/read/logo.d.ts +34 -0
- package/dist/core/read/logo.d.ts.map +1 -0
- package/dist/core/read/lookup.d.ts +9 -0
- package/dist/core/read/lookup.d.ts.map +1 -0
- package/dist/core/read/rules.d.ts +80 -0
- package/dist/core/read/rules.d.ts.map +1 -0
- package/dist/core/read/token.d.ts +46 -0
- package/dist/core/read/token.d.ts.map +1 -0
- package/dist/core/shipped-names.d.ts +9 -0
- package/dist/core/shipped-names.d.ts.map +1 -0
- package/dist/core/starter.d.ts +31 -0
- package/dist/core/starter.d.ts.map +1 -0
- package/dist/core/suggest.d.ts +7 -0
- package/dist/core/suggest.d.ts.map +1 -0
- package/dist/core/tokens/alias.d.ts +18 -0
- package/dist/core/tokens/alias.d.ts.map +1 -0
- package/dist/core/tokens/contexts.d.ts +10 -0
- package/dist/core/tokens/contexts.d.ts.map +1 -0
- package/dist/core/tokens/formatters/css.d.ts +15 -0
- package/dist/core/tokens/formatters/css.d.ts.map +1 -0
- package/dist/core/tokens/formatters/json.d.ts +4 -0
- package/dist/core/tokens/formatters/json.d.ts.map +1 -0
- package/dist/core/tokens/formatters/tailwind.d.ts +37 -0
- package/dist/core/tokens/formatters/tailwind.d.ts.map +1 -0
- package/dist/core/tokens/formatters/ts.d.ts +6 -0
- package/dist/core/tokens/formatters/ts.d.ts.map +1 -0
- package/dist/core/tokens/groups.d.ts +44 -0
- package/dist/core/tokens/groups.d.ts.map +1 -0
- package/dist/core/tokens/key-lines.d.ts +8 -0
- package/dist/core/tokens/key-lines.d.ts.map +1 -0
- package/dist/core/tokens/load.d.ts +12 -0
- package/dist/core/tokens/load.d.ts.map +1 -0
- package/dist/core/tokens/merge.d.ts +17 -0
- package/dist/core/tokens/merge.d.ts.map +1 -0
- package/dist/core/tokens/names.d.ts +5 -0
- package/dist/core/tokens/names.d.ts.map +1 -0
- package/dist/core/tokens/resolve.d.ts +8 -0
- package/dist/core/tokens/resolve.d.ts.map +1 -0
- package/dist/core/tokens/resolver/compile.d.ts +17 -0
- package/dist/core/tokens/resolver/compile.d.ts.map +1 -0
- package/dist/core/tokens/resolver/inputs.d.ts +7 -0
- package/dist/core/tokens/resolver/inputs.d.ts.map +1 -0
- package/dist/core/tokens/resolver/parse.d.ts +34 -0
- package/dist/core/tokens/resolver/parse.d.ts.map +1 -0
- package/dist/core/tokens/resolver/sources.d.ts +17 -0
- package/dist/core/tokens/resolver/sources.d.ts.map +1 -0
- package/dist/core/tokens/shadcn.d.ts +43 -0
- package/dist/core/tokens/shadcn.d.ts.map +1 -0
- package/dist/core/tokens/theme.d.ts +17 -0
- package/dist/core/tokens/theme.d.ts.map +1 -0
- package/dist/core/tokens/values/color.d.ts +2 -0
- package/dist/core/tokens/values/color.d.ts.map +1 -0
- package/dist/core/tokens/values/composite.d.ts +7 -0
- package/dist/core/tokens/values/composite.d.ts.map +1 -0
- package/dist/core/tokens/values/font.d.ts +3 -0
- package/dist/core/tokens/values/font.d.ts.map +1 -0
- package/dist/core/tokens/values/index.d.ts +9 -0
- package/dist/core/tokens/values/index.d.ts.map +1 -0
- package/dist/core/tokens/values/shared.d.ts +5 -0
- package/dist/core/tokens/values/shared.d.ts.map +1 -0
- package/dist/core/tokens/values/simple.d.ts +3 -0
- package/dist/core/tokens/values/simple.d.ts.map +1 -0
- package/dist/core/tokens/values/units.d.ts +3 -0
- package/dist/core/tokens/values/units.d.ts.map +1 -0
- package/dist/core/tokens/walk.d.ts +30 -0
- package/dist/core/tokens/walk.d.ts.map +1 -0
- package/dist/core/version.d.ts +3 -0
- package/dist/core/version.d.ts.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/plugins/host/admit.d.ts +35 -0
- package/dist/plugins/host/admit.d.ts.map +1 -0
- package/dist/plugins/host/call.d.ts +59 -0
- package/dist/plugins/host/call.d.ts.map +1 -0
- package/dist/plugins/host/check.d.ts +54 -0
- package/dist/plugins/host/check.d.ts.map +1 -0
- package/dist/plugins/host/scrub.d.ts +17 -0
- package/dist/plugins/host/scrub.d.ts.map +1 -0
- package/dist/plugins/index.d.ts +14 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/pins/interpreter.d.ts +49 -0
- package/dist/plugins/pins/interpreter.d.ts.map +1 -0
- package/dist/plugins/pins/lock.d.ts +47 -0
- package/dist/plugins/pins/lock.d.ts.map +1 -0
- package/dist/plugins/pins/pin.d.ts +65 -0
- package/dist/plugins/pins/pin.d.ts.map +1 -0
- package/dist/plugins/pins/shipped.d.ts +40 -0
- package/dist/plugins/pins/shipped.d.ts.map +1 -0
- package/dist/plugins/roles/breaker.d.ts +18 -0
- package/dist/plugins/roles/breaker.d.ts.map +1 -0
- package/dist/plugins/roles/check-cases.d.ts +4 -0
- package/dist/plugins/roles/check-cases.d.ts.map +1 -0
- package/dist/plugins/roles/dev.d.ts +35 -0
- package/dist/plugins/roles/dev.d.ts.map +1 -0
- package/dist/plugins/roles/fixes.d.ts +24 -0
- package/dist/plugins/roles/fixes.d.ts.map +1 -0
- package/dist/plugins/roles/gate.d.ts +26 -0
- package/dist/plugins/roles/gate.d.ts.map +1 -0
- package/dist/plugins/roles/integrate.d.ts +12 -0
- package/dist/plugins/roles/integrate.d.ts.map +1 -0
- package/dist/plugins/roles/roles.d.ts +73 -0
- package/dist/plugins/roles/roles.d.ts.map +1 -0
- package/dist/plugins/wire/environment.d.ts +9 -0
- package/dist/plugins/wire/environment.d.ts.map +1 -0
- package/dist/plugins/wire/forms.d.ts +13 -0
- package/dist/plugins/wire/forms.d.ts.map +1 -0
- package/dist/plugins/wire/limits.d.ts +11 -0
- package/dist/plugins/wire/limits.d.ts.map +1 -0
- package/dist/plugins/wire/manifest.d.ts +31 -0
- package/dist/plugins/wire/manifest.d.ts.map +1 -0
- package/dist/plugins/wire/profile.d.ts +36 -0
- package/dist/plugins/wire/profile.d.ts.map +1 -0
- package/dist/plugins/wire/text.d.ts +14 -0
- package/dist/plugins/wire/text.d.ts.map +1 -0
- package/dist/server/assets.d.ts +13 -0
- package/dist/server/assets.d.ts.map +1 -0
- package/dist/server/coalesce.d.ts +12 -0
- package/dist/server/coalesce.d.ts.map +1 -0
- package/dist/server/data-script.d.ts +8 -0
- package/dist/server/data-script.d.ts.map +1 -0
- package/dist/server/dev-server.d.ts +34 -0
- package/dist/server/dev-server.d.ts.map +1 -0
- package/dist/server/editor-guard.d.ts +13 -0
- package/dist/server/editor-guard.d.ts.map +1 -0
- package/dist/server/error-reporter.d.ts +11 -0
- package/dist/server/error-reporter.d.ts.map +1 -0
- package/dist/server/icon-sets.d.ts +9 -0
- package/dist/server/icon-sets.d.ts.map +1 -0
- package/dist/server/plugin.d.ts +4 -0
- package/dist/server/plugin.d.ts.map +1 -0
- package/dist/server/preview-guard.d.ts +11 -0
- package/dist/server/preview-guard.d.ts.map +1 -0
- package/dist/types/assets.d.ts +130 -0
- package/dist/types/assets.d.ts.map +1 -0
- package/dist/types/catalog.d.ts +95 -0
- package/dist/types/catalog.d.ts.map +1 -0
- package/dist/types/config.d.ts +97 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/data.d.ts +38 -0
- package/dist/types/data.d.ts.map +1 -0
- package/dist/types/docs.d.ts +47 -0
- package/dist/types/docs.d.ts.map +1 -0
- package/dist/types/findings.d.ts +18 -0
- package/dist/types/findings.d.ts.map +1 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/parsed.d.ts +86 -0
- package/dist/types/parsed.d.ts.map +1 -0
- package/dist/types/theme.d.ts +19 -0
- package/dist/types/theme.d.ts.map +1 -0
- package/dist/types/tokens.d.ts +101 -0
- package/dist/types/tokens.d.ts.map +1 -0
- package/dist/ui/assets/geist-OFL.txt +93 -0
- package/dist/ui/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
- package/dist/ui/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
- package/dist/ui/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/dist/ui/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/dist/ui/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
- package/dist/ui/assets/index-D0WCUmtA.css +2 -0
- package/dist/ui/assets/index-DhSc0Zxv.js +75 -0
- package/dist/ui/index.html +14 -0
- package/package.json +151 -4
- package/plugins/blazon.brand-deck/README.md +38 -0
- package/plugins/blazon.brand-deck/bin/blazon-blazon.brand-deck./360/237/224/214 +2695 -0
- package/plugins/blazon.brand-deck/package.json +3 -0
- package/plugins/blazon.copy/README.md +29 -0
- package/plugins/blazon.copy/bin/blazon-blazon.copy./360/237/224/214 +438 -0
- package/plugins/blazon.copy/package.json +3 -0
- package/plugins/blazon.favicons/README.md +13 -0
- package/plugins/blazon.favicons/bin/blazon-blazon.favicons./360/237/224/214 +8816 -0
- package/plugins/blazon.favicons/package.json +3 -0
- package/plugins/blazon.logo-geometry/README.md +5 -0
- package/plugins/blazon.logo-geometry/bin/blazon-blazon.logo-geometry./360/237/224/214 +1522 -0
- package/plugins/blazon.logo-geometry/package.json +3 -0
- package/plugins/blazon.logo-kit/README.md +5 -0
- package/plugins/blazon.logo-kit/bin/blazon-blazon.logo-kit./360/237/224/214 +617 -0
- package/plugins/blazon.logo-kit/package.json +3 -0
- package/plugins/blazon.office-template/README.md +29 -0
- package/plugins/blazon.office-template/bin/blazon-blazon.office-template./360/237/224/214 +1788 -0
- package/plugins/blazon.office-template/package.json +3 -0
- package/plugins/blazon.platform-tokens/README.md +22 -0
- package/plugins/blazon.platform-tokens/bin/blazon-blazon.platform-tokens./360/237/224/214 +8418 -0
- package/plugins/blazon.platform-tokens/package.json +3 -0
- package/plugins/blazon.press-kit/README.md +17 -0
- package/plugins/blazon.press-kit/bin/blazon-blazon.press-kit./360/237/224/214 +897 -0
- package/plugins/blazon.press-kit/package.json +3 -0
- package/plugins/blazon.print-book/README.md +40 -0
- package/plugins/blazon.print-book/bin/blazon-blazon.print-book./360/237/224/214 +9268 -0
- package/plugins/blazon.print-book/package.json +3 -0
- package/plugins/blazon.social-cards/README.md +5 -0
- package/plugins/blazon.social-cards/bin/blazon-blazon.social-cards./360/237/224/214 +1165 -0
- package/plugins/blazon.social-cards/package.json +3 -0
- package/plugins/shipped.lock +75 -0
- package/template/AGENTS.md +55 -0
- package/template/CLAUDE.md +1 -0
- package/template/assets/backgrounds/aurora.json +5 -0
- package/template/assets/backgrounds/aurora.svg +39 -0
- package/template/assets/construction/blazon-mark.json +9 -0
- package/template/assets/construction/blazon-mark.svg +54 -0
- package/template/assets/icons/arrow-right.json +5 -0
- package/template/assets/icons/arrow-right.svg +1 -0
- package/template/assets/icons/check.json +5 -0
- package/template/assets/icons/check.svg +1 -0
- package/template/assets/icons/download.json +5 -0
- package/template/assets/icons/download.svg +1 -0
- package/template/assets/icons/file.json +5 -0
- package/template/assets/icons/file.svg +1 -0
- package/template/assets/icons/token.json +5 -0
- package/template/assets/icons/token.svg +1 -0
- package/template/assets/icons/warning.json +5 -0
- package/template/assets/icons/warning.svg +1 -0
- package/template/assets/logos/blazon-bone.json +6 -0
- package/template/assets/logos/blazon-bone.svg +1 -0
- package/template/assets/logos/blazon-graphite.json +6 -0
- package/template/assets/logos/blazon-graphite.svg +1 -0
- package/template/assets/logos/blazon-mark.json +6 -0
- package/template/assets/logos/blazon-mark.svg +1 -0
- package/template/blazon.json +104 -0
- package/template/blazon.resolver.json +46 -0
- package/template/docs/01-principles.md +47 -0
- package/template/docs/02-logo.md +43 -0
- package/template/docs/03-color.md +79 -0
- package/template/docs/04-type.md +36 -0
- package/template/docs/05-form.md +80 -0
- package/template/docs/06-layout.md +28 -0
- package/template/docs/07-icons.md +22 -0
- package/template/docs/08-diagrams.md +20 -0
- package/template/docs/09-social.md +21 -0
- package/template/docs/10-applications.md +20 -0
- package/template/docs/11-voice.md +74 -0
- package/template/docs/12-web.md +167 -0
- package/template/fonts/IBMPlexMono-Regular-latin.woff2 +0 -0
- package/template/fonts/IBMPlexMono-SemiBold-latin.woff2 +0 -0
- package/template/fonts/OFL.txt +93 -0
- package/template/tokens/colors.json +257 -0
- package/template/tokens/form.json +199 -0
- package/template/tokens/social.json +26 -0
- package/template/tokens/spacing.json +65 -0
- package/template/tokens/theme/dark.json +121 -0
- package/template/tokens/typography.json +233 -0
|
@@ -0,0 +1,1165 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
let node_fs = require("node:fs");
|
|
23
|
+
node_fs = __toESM(node_fs, 1);
|
|
24
|
+
let node_path = require("node:path");
|
|
25
|
+
node_path = __toESM(node_path, 1);
|
|
26
|
+
let playwright_core = require("playwright-core");
|
|
27
|
+
let node_http = require("node:http");
|
|
28
|
+
node_http = __toESM(node_http, 1);
|
|
29
|
+
/** Text must reach this ratio against the picture (WCAG AA for normal text) */
|
|
30
|
+
var MIN_CONTRAST = 4.5;
|
|
31
|
+
/** Logo pixels at least this opaque (0 to 255) count as the logo; the soft edge of the artwork does not */
|
|
32
|
+
var LOGO_INK = 200;
|
|
33
|
+
/** The strongest scrim the plugin draws: past this the picture is not the picture any more */
|
|
34
|
+
var MAX_SCRIM = .75;
|
|
35
|
+
var SCRIM_STEP = .05;
|
|
36
|
+
/** The share of the worst pixels the measure looks past, so one stray pixel does not decide a card */
|
|
37
|
+
var TAIL = .02;
|
|
38
|
+
/** A color as red, green and blue from 0 to 255: `#rgb`, `#rrggbb`, `#rrggbbaa` (the alpha is ignored) or `rgb(…)`. Undefined for anything else. */
|
|
39
|
+
function parseColor(css) {
|
|
40
|
+
const text = css.trim();
|
|
41
|
+
const hex = /^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(text)?.[1];
|
|
42
|
+
if (hex) {
|
|
43
|
+
const full = hex.length === 3 ? [...hex].map((c) => c + c).join("") : hex;
|
|
44
|
+
return [
|
|
45
|
+
parseInt(full.slice(0, 2), 16),
|
|
46
|
+
parseInt(full.slice(2, 4), 16),
|
|
47
|
+
parseInt(full.slice(4, 6), 16)
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
const rgb = /^rgba?\(\s*(\d+(?:\.\d+)?)[,\s]+(\d+(?:\.\d+)?)[,\s]+(\d+(?:\.\d+)?)/i.exec(text);
|
|
51
|
+
return rgb ? [
|
|
52
|
+
Number(rgb[1]),
|
|
53
|
+
Number(rgb[2]),
|
|
54
|
+
Number(rgb[3])
|
|
55
|
+
] : void 0;
|
|
56
|
+
}
|
|
57
|
+
/** WCAG relative luminance */
|
|
58
|
+
function luminance([r, g, b]) {
|
|
59
|
+
const lin = (v) => {
|
|
60
|
+
const s = v / 255;
|
|
61
|
+
return s <= .03928 ? s / 12.92 : ((s + .055) / 1.055) ** 2.4;
|
|
62
|
+
};
|
|
63
|
+
return .2126 * lin(r) + .7152 * lin(g) + .0722 * lin(b);
|
|
64
|
+
}
|
|
65
|
+
/** WCAG contrast ratio, from 1 to 21 */
|
|
66
|
+
function ratio(a, b) {
|
|
67
|
+
const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x);
|
|
68
|
+
return (hi + .05) / (lo + .05);
|
|
69
|
+
}
|
|
70
|
+
/** A pixel under a scrim of `alpha`, blended in sRGB as a browser does */
|
|
71
|
+
function blend(pixel, scrim, alpha) {
|
|
72
|
+
return [
|
|
73
|
+
0,
|
|
74
|
+
1,
|
|
75
|
+
2
|
|
76
|
+
].map((i) => Math.round(pixel[i] * (1 - alpha) + scrim[i] * alpha));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The contrast of `text` against flat `pixels` ([r, g, b, r, g, b, …]) under a scrim of `alpha`: the ratio at the worst
|
|
80
|
+
* `tail` share of them, so a card is judged by its hardest spot and not by its average.
|
|
81
|
+
*/
|
|
82
|
+
function worstRatio(pixels, text, alpha, scrim, tail = TAIL) {
|
|
83
|
+
const ratios = [];
|
|
84
|
+
for (let i = 0; i + 2 < pixels.length; i += 3) ratios.push(ratio(text, blend([
|
|
85
|
+
pixels[i],
|
|
86
|
+
pixels[i + 1],
|
|
87
|
+
pixels[i + 2]
|
|
88
|
+
], scrim, alpha)));
|
|
89
|
+
if (ratios.length === 0) return 21;
|
|
90
|
+
ratios.sort((a, b) => a - b);
|
|
91
|
+
return ratios[Math.min(ratios.length - 1, Math.floor(ratios.length * tail))];
|
|
92
|
+
}
|
|
93
|
+
/** The weakest scrim, in steps of 0.05 and no stronger than MAX_SCRIM, that brings `text` to MIN_CONTRAST; else the strongest, not ok. */
|
|
94
|
+
function solveScrim(pixels, text, scrim) {
|
|
95
|
+
const steps = Math.round(MAX_SCRIM / SCRIM_STEP);
|
|
96
|
+
let last = {
|
|
97
|
+
alpha: 0,
|
|
98
|
+
ratio: 0,
|
|
99
|
+
ok: false
|
|
100
|
+
};
|
|
101
|
+
for (let i = 0; i <= steps; i++) {
|
|
102
|
+
const alpha = Math.round(i * SCRIM_STEP * 100) / 100;
|
|
103
|
+
last = {
|
|
104
|
+
alpha,
|
|
105
|
+
ratio: worstRatio(pixels, text, alpha, scrim),
|
|
106
|
+
ok: false
|
|
107
|
+
};
|
|
108
|
+
last.ok = last.ratio >= MIN_CONTRAST;
|
|
109
|
+
if (last.ok) return last;
|
|
110
|
+
}
|
|
111
|
+
return last;
|
|
112
|
+
}
|
|
113
|
+
/** Which candidate text color to use: the one that is ok with the weakest scrim (the first on a tie), else the one that gets closest. */
|
|
114
|
+
function chooseText(pixels, candidates, scrim) {
|
|
115
|
+
const solved = candidates.map((text, index) => ({
|
|
116
|
+
...solveScrim(pixels, text, scrim),
|
|
117
|
+
index
|
|
118
|
+
}));
|
|
119
|
+
return solved.filter((s) => s.ok).sort((a, b) => a.alpha - b.alpha || a.index - b.index)[0] ?? [...solved].sort((a, b) => b.ratio - a.ratio || a.index - b.index)[0];
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The contrast of a logo against the picture under it, at the worst `tail` share of its pixels. `logo` is the artwork alone
|
|
123
|
+
* ([r, g, b, a, …]) and `under` the picture beneath it ([r, g, b, …]), pixel for pixel; only the logo's solid pixels count.
|
|
124
|
+
*/
|
|
125
|
+
function logoRatio(logo, under, tail = TAIL) {
|
|
126
|
+
const ratios = [];
|
|
127
|
+
for (let i = 0; i < logo.length / 4 && i * 3 + 2 < under.length; i++) {
|
|
128
|
+
if (logo[i * 4 + 3] < LOGO_INK) continue;
|
|
129
|
+
ratios.push(ratio([
|
|
130
|
+
logo[i * 4],
|
|
131
|
+
logo[i * 4 + 1],
|
|
132
|
+
logo[i * 4 + 2]
|
|
133
|
+
], [
|
|
134
|
+
under[i * 3],
|
|
135
|
+
under[i * 3 + 1],
|
|
136
|
+
under[i * 3 + 2]
|
|
137
|
+
]));
|
|
138
|
+
}
|
|
139
|
+
if (ratios.length === 0) return 21;
|
|
140
|
+
ratios.sort((a, b) => a - b);
|
|
141
|
+
return ratios[Math.min(ratios.length - 1, Math.floor(ratios.length * tail))];
|
|
142
|
+
}
|
|
143
|
+
/** Which of the measured logos to use: the one with the higher contrast, the first on a tie. */
|
|
144
|
+
function bestLogo(measured) {
|
|
145
|
+
return measured.reduce((best, m) => m.ratio > best.ratio ? m : best);
|
|
146
|
+
}
|
|
147
|
+
/** What the findings may take on the wire, in bytes. The limit is 65,536; the rest is the envelope, the summary finding and a newline, with room to spare. */
|
|
148
|
+
var FINDINGS_BUDGET = 6e4;
|
|
149
|
+
var RANK = {
|
|
150
|
+
error: 0,
|
|
151
|
+
warning: 1,
|
|
152
|
+
info: 2
|
|
153
|
+
};
|
|
154
|
+
var rank = (severity) => RANK[severity] ?? 3;
|
|
155
|
+
var wire = (finding) => Buffer.byteLength(JSON.stringify(finding), "utf-8") + 1;
|
|
156
|
+
/**
|
|
157
|
+
* The findings as they are when they fit. When they do not, the first ones that fit, errors before warnings before notes and each
|
|
158
|
+
* group in the order it was found, then one `<name>/findings-left-out` warning that says how many are not shown. The summary is a
|
|
159
|
+
* warning so that it never hides that there were errors: the errors come first, and a run with any error is already failed.
|
|
160
|
+
*/
|
|
161
|
+
function boundFindings$1(findings, name) {
|
|
162
|
+
let size = 0;
|
|
163
|
+
for (const finding of findings) size += wire(finding);
|
|
164
|
+
if (size <= 6e4) return findings;
|
|
165
|
+
const ordered = [...findings].sort((a, b) => rank(a.severity) - rank(b.severity));
|
|
166
|
+
const kept = [];
|
|
167
|
+
size = 0;
|
|
168
|
+
for (const finding of ordered) {
|
|
169
|
+
if (size + wire(finding) > 6e4) break;
|
|
170
|
+
size += wire(finding);
|
|
171
|
+
kept.push(finding);
|
|
172
|
+
}
|
|
173
|
+
const left = ordered.length - kept.length;
|
|
174
|
+
kept.push({
|
|
175
|
+
code: `${name}/findings-left-out`,
|
|
176
|
+
severity: "warning",
|
|
177
|
+
path: "findings",
|
|
178
|
+
message: `${left} more findings are not shown, because the answer would not fit the ${FINDINGS_BUDGET.toLocaleString("en-US")} bytes a plugin may print; fix the ones above and run again`
|
|
179
|
+
});
|
|
180
|
+
return kept;
|
|
181
|
+
}
|
|
182
|
+
/** The plugin cannot do what it was asked; the message is the reason blazon shows. */
|
|
183
|
+
var Cannot = class extends Error {};
|
|
184
|
+
/** The builder of a plugin's findings: `findingFor(NAME)('code', severity, path, message)` is a finding coded `NAME/code`. */
|
|
185
|
+
var findingFor = (name) => (code, severity, path, message) => ({
|
|
186
|
+
code: `${name}/${code}`,
|
|
187
|
+
severity,
|
|
188
|
+
path,
|
|
189
|
+
message
|
|
190
|
+
});
|
|
191
|
+
var isObject$2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
192
|
+
/** The brand.json a plugin reads: the object when its format and version are the ones this reader understands, Cannot otherwise (RFC 0001: a reader checks both before it interprets anything). */
|
|
193
|
+
function requireBrand(raw) {
|
|
194
|
+
const shown = (value) => JSON.stringify(value) ?? "nothing";
|
|
195
|
+
if (!isObject$2(raw) || raw.format !== "blazon-brand") throw new Cannot(`the brand in the request is not a blazon brand: its format is ${shown(isObject$2(raw) ? raw.format : void 0)}, not "blazon-brand"`);
|
|
196
|
+
if (raw.version !== 1) throw new Cannot(`the brand in the request is version ${shown(raw.version)}; this reader understands version 1`);
|
|
197
|
+
return raw;
|
|
198
|
+
}
|
|
199
|
+
/** The request as an object of version 1, or Cannot with the reason. Its role and folders are for the plugin to check. */
|
|
200
|
+
function readRequest(text) {
|
|
201
|
+
let request;
|
|
202
|
+
try {
|
|
203
|
+
request = JSON.parse(text);
|
|
204
|
+
} catch {
|
|
205
|
+
throw new Cannot("the request is not JSON");
|
|
206
|
+
}
|
|
207
|
+
if (!isObject$2(request)) throw new Cannot("the request is not a JSON object");
|
|
208
|
+
if (request.v !== 1) throw new Cannot(`the request is version ${JSON.stringify(request.v)}; this plugin speaks version 1`);
|
|
209
|
+
return request;
|
|
210
|
+
}
|
|
211
|
+
/** The build request in `text`, or Cannot with the reason: version 1, the build role, a site_dir with an index.html and an out_dir that is a folder. The brand and options are not checked here. */
|
|
212
|
+
function buildJob(text) {
|
|
213
|
+
const request = readRequest(text);
|
|
214
|
+
if (request.type !== "build") throw new Cannot(`the request is for the ${String(request.type)} role; this plugin is a build plugin`);
|
|
215
|
+
const { site_dir: siteDir, out_dir: outDir } = request;
|
|
216
|
+
if (typeof siteDir !== "string" || !node_fs.default.existsSync(node_path.default.join(siteDir, "index.html"))) throw new Cannot("site_dir has no index.html");
|
|
217
|
+
if (typeof outDir !== "string" || !node_fs.default.statSync(outDir, { throwIfNoEntry: false })?.isDirectory()) throw new Cannot("out_dir is not a folder");
|
|
218
|
+
return {
|
|
219
|
+
siteDir,
|
|
220
|
+
outDir,
|
|
221
|
+
brand: request.brand ?? {},
|
|
222
|
+
options: request.options ?? {}
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/** A non-empty string (not only whitespace), or undefined. */
|
|
226
|
+
var text = (value) => typeof value === "string" && value.trim() !== "" ? value : void 0;
|
|
227
|
+
/** The files brand.json names as the logo for a light and for a dark surface. */
|
|
228
|
+
function readLogo(root) {
|
|
229
|
+
const logo = isObject$2(root.logo) ? root.logo : {};
|
|
230
|
+
return {
|
|
231
|
+
onLight: text(logo.onLight),
|
|
232
|
+
onDark: text(logo.onDark)
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
var isObject$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
236
|
+
var list = (value) => Array.isArray(value) ? value : [];
|
|
237
|
+
/** A dimension's px: `{ value, unit }` from the resolved token, or a CSS length such as "96px" or "2rem". */
|
|
238
|
+
function px(value) {
|
|
239
|
+
if (isObject$1(value) && typeof value.value === "number") return value.unit === "rem" ? value.value * 16 : value.value;
|
|
240
|
+
if (typeof value === "string") {
|
|
241
|
+
const match = /^(-?\d+(?:\.\d+)?)(px|rem)?$/.exec(value.trim());
|
|
242
|
+
if (match) return Number(match[1]) * (match[2] === "rem" ? 16 : 1);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
var EMPTY_DISPLAY = {
|
|
246
|
+
start: 96,
|
|
247
|
+
floor: 40,
|
|
248
|
+
family: "sans-serif",
|
|
249
|
+
weight: 700,
|
|
250
|
+
lineHeight: 1,
|
|
251
|
+
letterSpacing: "0em"
|
|
252
|
+
};
|
|
253
|
+
function readBrand(brand) {
|
|
254
|
+
const root = requireBrand(brand);
|
|
255
|
+
const theme = isObject$1(root.theme) ? root.theme : {};
|
|
256
|
+
const roles = isObject$1(theme.roles) ? theme.roles : {};
|
|
257
|
+
const tokens = /* @__PURE__ */ new Map();
|
|
258
|
+
for (const item of list(root.tokens)) {
|
|
259
|
+
if (!isObject$1(item) || typeof item.path !== "string") continue;
|
|
260
|
+
tokens.set(item.path, {
|
|
261
|
+
type: text(item.type) ?? "",
|
|
262
|
+
value: String(item.value ?? ""),
|
|
263
|
+
resolved: item.resolvedValue,
|
|
264
|
+
...isObject$1(item.parts) && { parts: item.parts }
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
const groups = /* @__PURE__ */ new Map();
|
|
268
|
+
for (const [path, token] of tokens) {
|
|
269
|
+
const match = /^social\.format\.([^.]+)\.(width|height|margin|columns)$/.exec(path);
|
|
270
|
+
if (!match) continue;
|
|
271
|
+
const value = match[2] === "columns" ? Number(token.resolved) : px(token.resolved);
|
|
272
|
+
if (typeof value === "number" && Number.isFinite(value) && value > 0) groups.set(match[1], {
|
|
273
|
+
...groups.get(match[1]),
|
|
274
|
+
[match[2]]: value
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
const formats = /* @__PURE__ */ new Map();
|
|
278
|
+
for (const [name, g] of groups) {
|
|
279
|
+
if (g.width === void 0 || g.height === void 0) continue;
|
|
280
|
+
formats.set(name, {
|
|
281
|
+
width: g.width,
|
|
282
|
+
height: g.height,
|
|
283
|
+
margin: g.margin ?? Math.round(Math.min(g.width, g.height) * .05),
|
|
284
|
+
columns: Number.isInteger(g.columns) ? g.columns : 6
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
const displayFamily = text(roles.fontDisplay);
|
|
288
|
+
const typed = [...tokens.values()].flatMap((token) => token.type === "typography" && token.parts && px(token.parts.fontSize) !== void 0 ? [token.parts] : []);
|
|
289
|
+
const family = displayFamily ?? (typed.length > 0 ? text([...typed].sort((a, b) => px(b.fontSize) - px(a.fontSize))[0].fontFamily) : void 0);
|
|
290
|
+
const inFamily = typed.filter((parts) => text(parts.fontFamily) === family).sort((a, b) => px(b.fontSize) - px(a.fontSize));
|
|
291
|
+
const largest = inFamily[0];
|
|
292
|
+
const display = largest ? {
|
|
293
|
+
start: px(largest.fontSize),
|
|
294
|
+
floor: Math.max(20, px(inFamily.at(-1).fontSize)),
|
|
295
|
+
family: family ?? EMPTY_DISPLAY.family,
|
|
296
|
+
weight: typeof largest.fontWeight === "number" ? largest.fontWeight : EMPTY_DISPLAY.weight,
|
|
297
|
+
lineHeight: typeof largest.lineHeight === "number" ? largest.lineHeight : EMPTY_DISPLAY.lineHeight,
|
|
298
|
+
letterSpacing: text(largest.letterSpacing) ?? EMPTY_DISPLAY.letterSpacing
|
|
299
|
+
} : {
|
|
300
|
+
...EMPTY_DISPLAY,
|
|
301
|
+
...family && { family }
|
|
302
|
+
};
|
|
303
|
+
if (display.floor >= display.start) display.floor = Math.max(20, Math.round(display.start / 2));
|
|
304
|
+
const assets = /* @__PURE__ */ new Map();
|
|
305
|
+
for (const item of list(root.assets)) {
|
|
306
|
+
if (!isObject$1(item) || typeof item.id !== "string" || typeof item.file !== "string") continue;
|
|
307
|
+
assets.set(item.id, {
|
|
308
|
+
id: item.id,
|
|
309
|
+
category: text(item.category) ?? "",
|
|
310
|
+
file: item.file,
|
|
311
|
+
format: text(item.format) ?? "",
|
|
312
|
+
...typeof item.width === "number" && { width: item.width },
|
|
313
|
+
...typeof item.height === "number" && { height: item.height },
|
|
314
|
+
...isObject$1(item.meta) && { meta: item.meta }
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
return {
|
|
318
|
+
formats,
|
|
319
|
+
display,
|
|
320
|
+
bodyFamily: text(roles.fontBody) ?? "sans-serif",
|
|
321
|
+
colors: {
|
|
322
|
+
inverse: text(roles.inverse),
|
|
323
|
+
inverseText: text(roles.inverseText),
|
|
324
|
+
text: text(roles.text),
|
|
325
|
+
accent: text(roles.accent)
|
|
326
|
+
},
|
|
327
|
+
fonts: list(theme.fonts).filter((url) => typeof url === "string" && /^(https?:\/\/|data:text\/css[;,])/.test(url)),
|
|
328
|
+
tokens,
|
|
329
|
+
assets,
|
|
330
|
+
logo: readLogo(root)
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
/** A token's color, when it is a color token the plugin can read. */
|
|
334
|
+
function colorOf(brand, path) {
|
|
335
|
+
const token = path === void 0 ? void 0 : brand.tokens.get(path);
|
|
336
|
+
return token?.type === "color" ? parseColor(token.value) : void 0;
|
|
337
|
+
}
|
|
338
|
+
/** The plugin's name, which blazon's config names it by, and the prefix of its finding codes */
|
|
339
|
+
var NAME = "blazon.social-cards";
|
|
340
|
+
var MANIFEST = {
|
|
341
|
+
v: 2,
|
|
342
|
+
roles: ["build"],
|
|
343
|
+
title: "Social cards",
|
|
344
|
+
description: "Draws marketing images (PNG) from the brand's tokens, logo and a background you already have, and checks the text and the logo on each.",
|
|
345
|
+
version: "1.0.0",
|
|
346
|
+
timeout_ms: 6e4,
|
|
347
|
+
env: [
|
|
348
|
+
"BLAZON_CHROME",
|
|
349
|
+
"HOME",
|
|
350
|
+
"TMPDIR"
|
|
351
|
+
]
|
|
352
|
+
};
|
|
353
|
+
/** The job a build request asks for, or Cannot with the reason. The options are checked later, and wrong ones are findings. */
|
|
354
|
+
function jobFor(text) {
|
|
355
|
+
return buildJob(text);
|
|
356
|
+
}
|
|
357
|
+
var boundFindings = (findings) => boundFindings$1(findings, NAME);
|
|
358
|
+
var INSTALL_HINT = "install Google Chrome, or set BLAZON_CHROME to a Chrome or Chromium program";
|
|
359
|
+
/**
|
|
360
|
+
* The browser: the program BLAZON_CHROME names, else the Google Chrome installed on this computer. It never downloads one.
|
|
361
|
+
* `what` completes "no browser to ...", such as "print with".
|
|
362
|
+
*/
|
|
363
|
+
async function launchChrome(env, what) {
|
|
364
|
+
const named = env.BLAZON_CHROME;
|
|
365
|
+
if (named) {
|
|
366
|
+
if (!isProgram(named)) throw new Cannot(`no browser to ${what}: BLAZON_CHROME names ${named}, which is not a program; ${INSTALL_HINT}`);
|
|
367
|
+
return playwright_core.chromium.launch({ executablePath: named });
|
|
368
|
+
}
|
|
369
|
+
try {
|
|
370
|
+
return await playwright_core.chromium.launch({ channel: "chrome" });
|
|
371
|
+
} catch {
|
|
372
|
+
throw new Cannot(`no browser to ${what}: ${INSTALL_HINT}`);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
function isProgram(file) {
|
|
376
|
+
try {
|
|
377
|
+
node_fs.default.accessSync(file, node_fs.default.constants.X_OK);
|
|
378
|
+
return node_fs.default.statSync(file).isFile();
|
|
379
|
+
} catch {
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
/** The browser to draw with: the program BLAZON_CHROME names, else the Google Chrome installed on this computer. */
|
|
384
|
+
var launch = (env) => launchChrome(env, "draw the cards with");
|
|
385
|
+
var plugin = findingFor(NAME);
|
|
386
|
+
var finding = (code, severity, id, message) => plugin(code, severity, `${id}.png`, `card "${id}": ${message}`);
|
|
387
|
+
var contrastFinding = (id, ratio, alpha) => finding("card-text-contrast", "error", id, `the headline is ${ratio.toFixed(1)}:1 against the picture even with the strongest scrim (${alpha}), under ${MIN_CONTRAST}:1`);
|
|
388
|
+
var logoContrastFinding = (id, ratio) => finding("card-logo-contrast", "error", id, `the logo is ${ratio.toFixed(1)}:1 against the picture under it, under 3:1; use a logo variant made for that surface (logo.onLight, logo.onDark), move the logo with anchor or logoCorner, or pick another background`);
|
|
389
|
+
var logoWidthFinding = (id, asked, least) => finding("card-logo-width-clamped", "warning", id, `logoWidth asks for a logo ${Number(asked.toFixed(1))}px wide, under the ${Math.round(least)}px its minSize allows; it is drawn at ${Math.round(least)}px`);
|
|
390
|
+
var overflowFinding = (id, floor) => finding("card-text-overflow", "error", id, `the headline does not fit the safe area at ${floor}px, the smallest type step; shorten it or use a larger format`);
|
|
391
|
+
/** What is wrong with the background image of a card: a generated one nobody has reviewed, and one too small for the format. */
|
|
392
|
+
function backgroundFindings(id, asset, format) {
|
|
393
|
+
const found = [];
|
|
394
|
+
const meta = asset.meta ?? {};
|
|
395
|
+
const review = typeof meta.review === "object" && meta.review !== null ? meta.review.status : void 0;
|
|
396
|
+
if (meta.generated && review !== "ok") {
|
|
397
|
+
const why = review === void 0 ? "it has no review" : `review.status is ${JSON.stringify(review)}, not "ok"`;
|
|
398
|
+
found.push(finding("card-background-generated-unreviewed", "error", id, `the background ${asset.id} is generated and has not been reviewed (${why})`));
|
|
399
|
+
}
|
|
400
|
+
if (asset.format !== "svg" && asset.width && asset.height) {
|
|
401
|
+
const scale = Math.max(format.width / asset.width, format.height / asset.height);
|
|
402
|
+
if (scale > 1) found.push(finding("card-background-small", "warning", id, `the background ${asset.id} is ${asset.width} x ${asset.height} px and the card needs ${format.width} x ${format.height} px, so it is enlarged ${scale.toFixed(1)} times`));
|
|
403
|
+
}
|
|
404
|
+
return found;
|
|
405
|
+
}
|
|
406
|
+
var CORNERS = [
|
|
407
|
+
"top-left",
|
|
408
|
+
"top-right",
|
|
409
|
+
"bottom-left",
|
|
410
|
+
"bottom-right"
|
|
411
|
+
];
|
|
412
|
+
/** A logo is this share of the card's width when its sidecar sets no larger minimum */
|
|
413
|
+
var LOGO_SHARE = .14;
|
|
414
|
+
/**
|
|
415
|
+
* Where the logo goes and how big it is: in the first corner its sidecar lists (top left without one), inside the margin,
|
|
416
|
+
* no smaller than its `minSize` in card px. Its `clearSpace` is stated in the artwork's own pixels (or in its `unit`), so it
|
|
417
|
+
* grows with the logo. `ask` is the card's own choice: a `width` (px, or a share of the shorter side such as "22%") replaces the 14%
|
|
418
|
+
* but never goes under the minimum, and a `corner` replaces the sidecar's and the text edge's.
|
|
419
|
+
*/
|
|
420
|
+
function planLogo(format, artwork, meta, textEdge, ask = {}) {
|
|
421
|
+
const aspect = artwork.height / artwork.width;
|
|
422
|
+
const minWidth = px(meta?.minSize?.width) ?? 0;
|
|
423
|
+
const minHeight = px(meta?.minSize?.height) ?? 0;
|
|
424
|
+
const least = Math.max(minWidth, minHeight / aspect);
|
|
425
|
+
const asked = ask.width === void 0 ? void 0 : typeof ask.width === "number" ? ask.width : Math.min(format.width, format.height) * Number.parseFloat(ask.width) / 100;
|
|
426
|
+
const width = Math.min(format.width, Math.round(asked === void 0 ? Math.max(least, format.width * LOGO_SHARE) : Math.max(least, asked)));
|
|
427
|
+
const clamped = typeof ask.width === "number" && Math.round(ask.width) < Math.round(least);
|
|
428
|
+
const height = Math.round(width * aspect);
|
|
429
|
+
const listed = (meta?.placement ?? []).filter((c) => CORNERS.includes(c));
|
|
430
|
+
const first = listed[0] ?? "top-left";
|
|
431
|
+
const mirrored = `${first.startsWith("top") ? "bottom" : "top"}-${first.endsWith("left") ? "left" : "right"}`;
|
|
432
|
+
const corner = ask.corner ?? (textEdge === void 0 || first.startsWith(textEdge === "top" ? "bottom" : "top") ? first : listed.find((c) => c.startsWith(textEdge === "top" ? "bottom" : "top")) ?? mirrored);
|
|
433
|
+
const x = corner.endsWith("left") ? format.margin : format.width - format.margin - width;
|
|
434
|
+
const y = corner.startsWith("top") ? format.margin : format.height - format.margin - height;
|
|
435
|
+
const space = meta?.clearSpace;
|
|
436
|
+
let inArtwork;
|
|
437
|
+
if (typeof space === "object" && space !== null && "units" in space && typeof space.units === "number") inArtwork = space.units * (px(meta?.unit) ?? artwork.height / 2);
|
|
438
|
+
else inArtwork = px(space);
|
|
439
|
+
const clearSpace = inArtwork === void 0 ? Math.round(height / 2) : inArtwork * (width / artwork.width);
|
|
440
|
+
return {
|
|
441
|
+
corner,
|
|
442
|
+
rect: {
|
|
443
|
+
x,
|
|
444
|
+
y,
|
|
445
|
+
width,
|
|
446
|
+
height
|
|
447
|
+
},
|
|
448
|
+
clearSpace,
|
|
449
|
+
...clamped && { clampedFrom: ask.width }
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
var inflate = (r, by) => ({
|
|
453
|
+
x: r.x - by,
|
|
454
|
+
y: r.y - by,
|
|
455
|
+
width: r.width + 2 * by,
|
|
456
|
+
height: r.height + 2 * by
|
|
457
|
+
});
|
|
458
|
+
var within = (inner, outer, slack = .5) => inner.x >= outer.x - slack && inner.y >= outer.y - slack && inner.x + inner.width <= outer.x + outer.width + slack && inner.y + inner.height <= outer.y + outer.height + slack;
|
|
459
|
+
var overlaps = (a, b) => a.x < b.x + b.width && b.x < a.x + a.width && a.y < b.y + b.height && b.y < a.y + a.height;
|
|
460
|
+
/** The logo as drawn: it must be in the safe area, its clear space must stay on the card, and the text must stay out of that space. */
|
|
461
|
+
function logoFinding(id, drawn) {
|
|
462
|
+
if (!within(drawn.logo, drawn.safe)) return finding("card-logo-clear-space", "error", id, "the logo leaves the safe area; use a larger format, a smaller logoWidth, or a smaller minimum size for the logo");
|
|
463
|
+
const space = inflate(drawn.logo, drawn.clearSpace);
|
|
464
|
+
if (!within(space, drawn.card)) return finding("card-logo-clear-space", "error", id, `the logo's clear space (${Math.round(drawn.clearSpace)}px) reaches past the edge of the card; widen social.format margin to at least that`);
|
|
465
|
+
if (overlaps(space, drawn.text) && drawn.shared) return finding("card-text-logo-overlap", "error", id, `the text hangs from the same edge as the logo and is inside the logo's clear space (${Math.round(drawn.clearSpace)}px); put the logo in a corner on the other side of the text, make the logo narrower, or shorten the headline`);
|
|
466
|
+
if (overlaps(space, drawn.text)) return finding("card-logo-clear-space", "error", id, `the text is inside the logo's clear space (${Math.round(drawn.clearSpace)}px); shorten it`);
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* The named zones. "avatar" is where the profile photo of a LinkedIn or X cover sits: the bottom left quarter of the width by
|
|
470
|
+
* half of the height. Those numbers are a convention of those platforms, not a rule of blazon's, and a platform may change them.
|
|
471
|
+
*/
|
|
472
|
+
var KEEP_CLEAR_ZONES = { avatar: {
|
|
473
|
+
x: 0,
|
|
474
|
+
y: 50,
|
|
475
|
+
width: 25,
|
|
476
|
+
height: 50
|
|
477
|
+
} };
|
|
478
|
+
/**
|
|
479
|
+
* How far `box` reaches into `zone`, in px: the smaller of the overlap's width and height, so a box that only grazes a corner
|
|
480
|
+
* counts as little as it intrudes. 0 when they are apart or only touch.
|
|
481
|
+
*/
|
|
482
|
+
function intrusion(box, zone) {
|
|
483
|
+
const across = Math.min(box.x + box.width, zone.x + zone.width) - Math.max(box.x, zone.x);
|
|
484
|
+
const down = Math.min(box.y + box.height, zone.y + zone.height) - Math.max(box.y, zone.y);
|
|
485
|
+
return Math.max(0, Math.min(across, down));
|
|
486
|
+
}
|
|
487
|
+
var zoneName = (zone) => `${zone.name ? `"${zone.name}" ` : ""}(x ${zone.x}%, y ${zone.y}%, ${zone.width}% by ${zone.height}%)`;
|
|
488
|
+
/**
|
|
489
|
+
* The text and the logo against the zones the card keeps clear, in px of the card. `lines` are the boxes of the rendered lines of
|
|
490
|
+
* the headline (and the accent rule above it) and of the subline, `logo` the logo's own box, not its clear space. One finding for
|
|
491
|
+
* each part and zone it reaches more than `KEEP_CLEAR_SLACK` px into, with the deepest reach.
|
|
492
|
+
*/
|
|
493
|
+
function keepClearFindings(id, drawn) {
|
|
494
|
+
const found = [];
|
|
495
|
+
for (const zone of drawn.zones) {
|
|
496
|
+
const px = {
|
|
497
|
+
x: zone.x * drawn.card.width / 100,
|
|
498
|
+
y: zone.y * drawn.card.height / 100,
|
|
499
|
+
width: zone.width * drawn.card.width / 100,
|
|
500
|
+
height: zone.height * drawn.card.height / 100
|
|
501
|
+
};
|
|
502
|
+
const reach = (boxes) => Math.max(0, ...boxes.map((box) => intrusion(box, px)));
|
|
503
|
+
for (const part of ["headline", "subline"]) {
|
|
504
|
+
const depth = reach(drawn.lines[part]);
|
|
505
|
+
if (depth > 2) found.push(finding("card-text-keep-clear", "error", id, `the ${part} reaches ${Math.round(depth)}px into the area kept clear ${zoneName(zone)}; shorten it, narrow the text, or move it with anchor and align`));
|
|
506
|
+
}
|
|
507
|
+
const depth = drawn.logo ? reach([drawn.logo]) : 0;
|
|
508
|
+
if (depth > 2) found.push(finding("card-logo-keep-clear", "error", id, `the logo reaches ${Math.round(depth)}px into the area kept clear ${zoneName(zone)}; move it with logoCorner, or make it narrower with logoWidth (not below the logo's minSize)`));
|
|
509
|
+
}
|
|
510
|
+
return found;
|
|
511
|
+
}
|
|
512
|
+
var OPTION_KEYS = ["cards", "scale"];
|
|
513
|
+
var CARD_KEYS = [
|
|
514
|
+
"id",
|
|
515
|
+
"format",
|
|
516
|
+
"background",
|
|
517
|
+
"headline",
|
|
518
|
+
"subline",
|
|
519
|
+
"logo",
|
|
520
|
+
"textColor",
|
|
521
|
+
"align",
|
|
522
|
+
"anchor",
|
|
523
|
+
"logoWidth",
|
|
524
|
+
"logoCorner",
|
|
525
|
+
"keepClear"
|
|
526
|
+
];
|
|
527
|
+
/** A share of the shorter side: more than 0 and at most 100 */
|
|
528
|
+
var PERCENT = /^(\d+(?:\.\d+)?)%$/;
|
|
529
|
+
var ID = /^[a-z0-9][a-z0-9_-]{0,63}$/i;
|
|
530
|
+
var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
531
|
+
var RECT_KEYS = [
|
|
532
|
+
"x",
|
|
533
|
+
"y",
|
|
534
|
+
"width",
|
|
535
|
+
"height"
|
|
536
|
+
];
|
|
537
|
+
var isZoneName = (value) => typeof value === "string" && Object.hasOwn(KEEP_CLEAR_ZONES, value);
|
|
538
|
+
var invalid = (path, message) => ({
|
|
539
|
+
code: `${NAME}/card-option-invalid`,
|
|
540
|
+
severity: "error",
|
|
541
|
+
path,
|
|
542
|
+
message
|
|
543
|
+
});
|
|
544
|
+
/** What is wrong with one `keepClear` entry: a named zone, or a rectangle in percent of the card that lies inside the card. */
|
|
545
|
+
function keepClearProblem(entry) {
|
|
546
|
+
const zones = Object.keys(KEEP_CLEAR_ZONES).join(", ");
|
|
547
|
+
if (isZoneName(entry)) return void 0;
|
|
548
|
+
if (typeof entry === "string") return `${JSON.stringify(entry)} is not a named zone (${zones})`;
|
|
549
|
+
if (!isObject(entry)) return `must be a named zone (${zones}) or { x, y, width, height }`;
|
|
550
|
+
for (const key of Object.keys(entry)) if (!RECT_KEYS.includes(key)) return `has the unknown key "${key}"`;
|
|
551
|
+
for (const key of RECT_KEYS) {
|
|
552
|
+
const value = entry[key];
|
|
553
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return `needs ${key} as a number of percent`;
|
|
554
|
+
if (value < 0 || value > 100) return `${key} is ${value}, outside 0 to 100`;
|
|
555
|
+
}
|
|
556
|
+
const { x, y, width, height } = entry;
|
|
557
|
+
if (width <= 0 || height <= 0) return "needs a width and a height above 0";
|
|
558
|
+
if (x + width > 100 || y + height > 100) return `reaches past the card (x + width is ${x + width}, y + height is ${y + height}, at most 100)`;
|
|
559
|
+
}
|
|
560
|
+
/** A checked `keepClear` entry as the card keeps it: a named zone becomes its numbers and keeps its name for the message */
|
|
561
|
+
var zoneOf = (entry) => typeof entry === "string" ? {
|
|
562
|
+
name: entry,
|
|
563
|
+
...KEEP_CLEAR_ZONES[entry]
|
|
564
|
+
} : {
|
|
565
|
+
x: entry.x,
|
|
566
|
+
y: entry.y,
|
|
567
|
+
width: entry.width,
|
|
568
|
+
height: entry.height
|
|
569
|
+
};
|
|
570
|
+
/**
|
|
571
|
+
* The cards the options ask for, and a `card-option-invalid` finding for each thing wrong. A card with anything wrong in it
|
|
572
|
+
* is left out; wrong options as a whole leave out every card. Nothing here throws: the options are the person's, not the request's.
|
|
573
|
+
*/
|
|
574
|
+
function parseOptions(options, known) {
|
|
575
|
+
if (!isObject(options)) return {
|
|
576
|
+
cards: [],
|
|
577
|
+
scale: 1,
|
|
578
|
+
findings: [invalid("options", "options must be an object")]
|
|
579
|
+
};
|
|
580
|
+
const top = [];
|
|
581
|
+
for (const key of Object.keys(options)) if (!OPTION_KEYS.includes(key)) top.push(invalid("options", `unknown option "${key}": the options are ${OPTION_KEYS.join(" and ")}`));
|
|
582
|
+
const scale = options.scale === void 0 ? 1 : options.scale;
|
|
583
|
+
if (scale !== 1 && scale !== 2) top.push(invalid("options", "scale must be 1 or 2"));
|
|
584
|
+
if (!Array.isArray(options.cards) || options.cards.length === 0) top.push(invalid("options", "cards must be a non-empty list"));
|
|
585
|
+
if (top.length > 0 || !Array.isArray(options.cards)) return {
|
|
586
|
+
cards: [],
|
|
587
|
+
scale: 1,
|
|
588
|
+
findings: top
|
|
589
|
+
};
|
|
590
|
+
const cards = [];
|
|
591
|
+
const findings = [];
|
|
592
|
+
const seen = /* @__PURE__ */ new Set();
|
|
593
|
+
options.cards.forEach((raw, index) => {
|
|
594
|
+
const n = index + 1;
|
|
595
|
+
if (!isObject(raw)) {
|
|
596
|
+
findings.push(invalid(`cards[${n}]`, `card ${n} must be an object`));
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
const id = typeof raw.id === "string" && ID.test(raw.id) ? raw.id : void 0;
|
|
600
|
+
const at = id ?? `cards[${n}]`;
|
|
601
|
+
const problems = [];
|
|
602
|
+
for (const key of Object.keys(raw)) if (!CARD_KEYS.includes(key)) problems.push(`unknown key "${key}"`);
|
|
603
|
+
if (id === void 0) problems.push("id must be letters, digits, \"-\" or \"_\" (at most 64), because it names the file");
|
|
604
|
+
else if (seen.has(id)) problems.push(`id "${id}" is used twice`);
|
|
605
|
+
if (raw.format === void 0) problems.push("format is required");
|
|
606
|
+
else if (typeof raw.format !== "string" || !known.formats.has(raw.format)) problems.push(`format ${JSON.stringify(raw.format)} is not a group under social.format (${[...known.formats].join(", ") || "none"})`);
|
|
607
|
+
if (typeof raw.background !== "string" || !known.backgrounds.has(raw.background)) problems.push(`background ${JSON.stringify(raw.background)} is not an asset or a color or gradient token`);
|
|
608
|
+
if (typeof raw.headline !== "string" || raw.headline.trim() === "") problems.push("headline must be a non-empty string");
|
|
609
|
+
if (raw.subline !== void 0 && typeof raw.subline !== "string") problems.push("subline must be a string");
|
|
610
|
+
if (raw.logo !== void 0 && raw.logo !== "auto" && raw.logo !== "light" && raw.logo !== "dark") problems.push("logo must be auto, light or dark");
|
|
611
|
+
if (raw.align !== void 0 && raw.align !== "left" && raw.align !== "center") problems.push("align must be left or center");
|
|
612
|
+
if (raw.anchor !== void 0 && raw.anchor !== "top" && raw.anchor !== "bottom") problems.push("anchor must be top or bottom");
|
|
613
|
+
if (raw.logoWidth !== void 0) {
|
|
614
|
+
const share = typeof raw.logoWidth === "string" ? PERCENT.exec(raw.logoWidth) : null;
|
|
615
|
+
if (!(typeof raw.logoWidth === "number" && Number.isFinite(raw.logoWidth) && raw.logoWidth > 0) && !(share && Number(share[1]) > 0 && Number(share[1]) <= 100)) problems.push("logoWidth must be a number of px above 0, or a percentage of the shorter side above 0% and up to 100% such as \"22%\"");
|
|
616
|
+
}
|
|
617
|
+
if (raw.logoCorner !== void 0 && !CORNERS.includes(raw.logoCorner)) problems.push(`logoCorner must be ${CORNERS.join(", ")}`);
|
|
618
|
+
if (raw.keepClear !== void 0) {
|
|
619
|
+
if (!Array.isArray(raw.keepClear)) problems.push("keepClear must be a list of named zones and { x, y, width, height } rectangles, in percent of the card");
|
|
620
|
+
else raw.keepClear.forEach((entry, at) => {
|
|
621
|
+
const problem = keepClearProblem(entry);
|
|
622
|
+
if (problem) problems.push(`keepClear[${at + 1}] ${problem}`);
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
if (raw.textColor !== void 0 && (typeof raw.textColor !== "string" || !known.colors.has(raw.textColor))) problems.push(`textColor ${JSON.stringify(raw.textColor)} is not a color token`);
|
|
626
|
+
if (problems.length > 0) {
|
|
627
|
+
for (const problem of problems) findings.push(invalid(at, `card ${n}: ${problem}`));
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
seen.add(id);
|
|
631
|
+
cards.push({
|
|
632
|
+
id,
|
|
633
|
+
format: raw.format,
|
|
634
|
+
background: raw.background,
|
|
635
|
+
headline: raw.headline.trim(),
|
|
636
|
+
...raw.subline !== void 0 && raw.subline !== "" && { subline: raw.subline.trim() },
|
|
637
|
+
logo: raw.logo ?? "auto",
|
|
638
|
+
...raw.textColor !== void 0 && { textColor: raw.textColor },
|
|
639
|
+
align: raw.align ?? "left",
|
|
640
|
+
...raw.anchor !== void 0 && { anchor: raw.anchor },
|
|
641
|
+
...raw.logoWidth !== void 0 && { logoWidth: raw.logoWidth },
|
|
642
|
+
...raw.logoCorner !== void 0 && { logoCorner: raw.logoCorner },
|
|
643
|
+
...Array.isArray(raw.keepClear) && raw.keepClear.length > 0 && { keepClear: raw.keepClear.map(zoneOf) }
|
|
644
|
+
});
|
|
645
|
+
});
|
|
646
|
+
return {
|
|
647
|
+
cards,
|
|
648
|
+
scale,
|
|
649
|
+
findings
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
var TYPES = {
|
|
653
|
+
".html": "text/html; charset=utf-8",
|
|
654
|
+
".js": "text/javascript",
|
|
655
|
+
".mjs": "text/javascript",
|
|
656
|
+
".css": "text/css",
|
|
657
|
+
".json": "application/json",
|
|
658
|
+
".svg": "image/svg+xml",
|
|
659
|
+
".png": "image/png",
|
|
660
|
+
".jpg": "image/jpeg",
|
|
661
|
+
".jpeg": "image/jpeg",
|
|
662
|
+
".gif": "image/gif",
|
|
663
|
+
".webp": "image/webp",
|
|
664
|
+
".avif": "image/avif",
|
|
665
|
+
".woff": "font/woff",
|
|
666
|
+
".woff2": "font/woff2",
|
|
667
|
+
".ttf": "font/ttf",
|
|
668
|
+
".pdf": "application/pdf"
|
|
669
|
+
};
|
|
670
|
+
/** A built site served on 127.0.0.1 and a free port, for the length of one print. Only files inside `root` are served. */
|
|
671
|
+
async function serve(root) {
|
|
672
|
+
const base = node_fs.default.realpathSync(root);
|
|
673
|
+
const server = node_http.default.createServer((req, res) => {
|
|
674
|
+
let pathname;
|
|
675
|
+
try {
|
|
676
|
+
pathname = decodeURIComponent(new URL(req.url ?? "/", "http://localhost").pathname);
|
|
677
|
+
} catch {
|
|
678
|
+
res.writeHead(400).end();
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
const file = node_path.default.join(base, pathname === "/" ? "index.html" : pathname);
|
|
682
|
+
const real = node_fs.default.existsSync(file) ? node_fs.default.realpathSync(file) : "";
|
|
683
|
+
if (!real.startsWith(base + node_path.default.sep) || !node_fs.default.statSync(real).isFile()) {
|
|
684
|
+
res.writeHead(404).end();
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
687
|
+
res.writeHead(200, { "content-type": TYPES[node_path.default.extname(real).toLowerCase()] ?? "application/octet-stream" });
|
|
688
|
+
node_fs.default.createReadStream(real).pipe(res);
|
|
689
|
+
});
|
|
690
|
+
await new Promise((done) => server.listen(0, "127.0.0.1", done));
|
|
691
|
+
const { port } = server.address();
|
|
692
|
+
return {
|
|
693
|
+
origin: `http://127.0.0.1:${port}`,
|
|
694
|
+
close: () => new Promise((done) => server.close(() => done()))
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
var FACTOR = .92;
|
|
698
|
+
/** Type sizes from `start` down to `floor`, each 8% smaller than the one before, the last exactly the floor. */
|
|
699
|
+
function typeSteps(start, floor) {
|
|
700
|
+
const steps = [Math.round(start)];
|
|
701
|
+
for (let size = Math.round(start * FACTOR); size > floor; size = Math.min(size - 1, Math.round(size * FACTOR))) if (size < steps.at(-1)) steps.push(size);
|
|
702
|
+
if (steps.at(-1) > floor) steps.push(Math.round(floor));
|
|
703
|
+
return steps;
|
|
704
|
+
}
|
|
705
|
+
/** The first (largest) step at which the text fits, or the floor with `fits: false` when none does. */
|
|
706
|
+
async function fitHeadline(steps, fits) {
|
|
707
|
+
for (const size of steps) if (await fits(size)) return {
|
|
708
|
+
size,
|
|
709
|
+
fits: true
|
|
710
|
+
};
|
|
711
|
+
return {
|
|
712
|
+
size: steps.at(-1),
|
|
713
|
+
fits: false
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
/** The room between the text and the edge of the scrim's full strength, and how far the scrim fades out past it */
|
|
717
|
+
var SCRIM_PAD = 24;
|
|
718
|
+
var SCRIM_RAMP = .35;
|
|
719
|
+
/** Characters that could end the style or the attribute they sit in: a value from brand.json is the brand's, but it is not trusted to be inert. */
|
|
720
|
+
var css = (value) => value.replace(/[<>{};"\\]/g, "");
|
|
721
|
+
var html = (value) => value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
722
|
+
var subSize = (size) => Math.max(16, Math.round(size * .3));
|
|
723
|
+
/** The width of the text block: five sixths of the safe width on a six-column card, so a headline leaves a column free. */
|
|
724
|
+
function measure(format, align) {
|
|
725
|
+
const safe = format.width - 2 * format.margin;
|
|
726
|
+
return align === "center" || format.columns < 3 ? safe : Math.round(safe * (format.columns - 1) / format.columns);
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* How far the text must stay in from each side when the logo is on the edge the text hangs from: the logo's width and its clear
|
|
730
|
+
* space. Text that starts at the left stops short of a logo on the right; centered text keeps its centre and gives up that room
|
|
731
|
+
* on both sides. A logo on the side the text starts from cannot be made room for: it is left to `card-text-logo-overlap`.
|
|
732
|
+
*/
|
|
733
|
+
function logoInset(align, anchor, plan) {
|
|
734
|
+
const none = {
|
|
735
|
+
left: 0,
|
|
736
|
+
right: 0
|
|
737
|
+
};
|
|
738
|
+
if (!plan.corner.startsWith(anchor)) return none;
|
|
739
|
+
const room = Math.ceil(plan.rect.width + plan.clearSpace);
|
|
740
|
+
if (align === "center") return {
|
|
741
|
+
left: room,
|
|
742
|
+
right: room
|
|
743
|
+
};
|
|
744
|
+
return plan.corner.endsWith("right") ? {
|
|
745
|
+
left: 0,
|
|
746
|
+
right: room
|
|
747
|
+
} : none;
|
|
748
|
+
}
|
|
749
|
+
/** The strongest part of the scrim reaches `extent` px from the edge the text hangs from, then fades out over a third of the card. */
|
|
750
|
+
function scrimExtent(format, anchor, block) {
|
|
751
|
+
return Math.round(anchor === "bottom" ? format.height - block.y + SCRIM_PAD : block.y + block.height + SCRIM_PAD);
|
|
752
|
+
}
|
|
753
|
+
/** The scrim as a CSS gradient: the brand's inverse color at `alpha` out to `extent`, then fading out. `none` when there is none. */
|
|
754
|
+
function scrimGradient(look) {
|
|
755
|
+
if (!look.scrim || look.scrim.alpha <= 0) return "none";
|
|
756
|
+
const { rgb, alpha, extent } = look.scrim;
|
|
757
|
+
const at = (a) => `rgba(${rgb.join(",")},${+a.toFixed(3)})`;
|
|
758
|
+
const ramp = Math.round(look.format.height * SCRIM_RAMP);
|
|
759
|
+
return `linear-gradient(${look.anchor === "bottom" ? "to top" : "to bottom"}, ${at(alpha)} 0, ${at(alpha)} ${extent}px, ${at(alpha * .45)} ${extent + Math.round(ramp / 2)}px, ${at(0)} ${extent + ramp}px)`;
|
|
760
|
+
}
|
|
761
|
+
function pageHtml(look) {
|
|
762
|
+
const { format, card, display } = look;
|
|
763
|
+
const center = card.align === "center";
|
|
764
|
+
const inset = look.inset ?? {
|
|
765
|
+
left: 0,
|
|
766
|
+
right: 0
|
|
767
|
+
};
|
|
768
|
+
const safe = format.width - 2 * format.margin;
|
|
769
|
+
return `<!doctype html>
|
|
770
|
+
<html><head><meta charset="utf-8"><title>${html(card.id)}</title>
|
|
771
|
+
${look.fonts.map((href) => `<link rel="stylesheet" href="${html(href)}">`).join("\n")}
|
|
772
|
+
<style>
|
|
773
|
+
html, body { margin: 0; background: ${css(look.ground)} }
|
|
774
|
+
#card { position: relative; width: ${format.width}px; height: ${format.height}px; overflow: hidden; background: ${css(look.ground)}; --h: ${look.size}px; --s: ${subSize(look.size)}px }
|
|
775
|
+
#picture, #scrim { position: absolute; inset: 0 }
|
|
776
|
+
#picture { background: ${css(look.background)} }
|
|
777
|
+
#scrim { background: ${scrimGradient(look)} }
|
|
778
|
+
#text { position: absolute; ${look.anchor}: ${format.margin}px; left: ${format.margin + inset.left}px; width: ${Math.min(measure(format, card.align), safe - inset.left - inset.right)}px; ${center ? `right: ${format.margin + inset.right}px;` : ""}
|
|
779
|
+
text-align: ${card.align}; color: ${css(look.textColor)}; display: flex; flex-direction: column; align-items: ${center ? "center" : "flex-start"} }
|
|
780
|
+
#rule { width: 56px; height: 6px; background: ${css(look.accent)}; margin-bottom: ${Math.round(look.size * .28)}px }
|
|
781
|
+
h1 { margin: 0; font: ${display.weight} var(--h) / ${display.lineHeight} ${css(display.family)}; letter-spacing: ${css(display.letterSpacing)}; text-wrap: balance; overflow-wrap: normal; width: 100% }
|
|
782
|
+
p { margin: ${Math.round(look.size * .22)}px 0 0; font: 400 var(--s) / 1.4 ${css(look.bodyFamily)}; width: 100%; overflow-wrap: normal }
|
|
783
|
+
#logo { position: absolute; display: block }
|
|
784
|
+
</style></head>
|
|
785
|
+
<body>
|
|
786
|
+
<div id="card">
|
|
787
|
+
<div id="picture"></div>
|
|
788
|
+
<div id="scrim"></div>
|
|
789
|
+
<div id="text"><div id="rule"></div><h1 id="headline">${html(card.headline)}</h1>${card.subline ? `<p id="subline">${html(card.subline)}</p>` : ""}</div>
|
|
790
|
+
${look.logo ? `<img id="logo" alt="" src="${html(encodeURI(look.logo.src))}" style="left:${look.logo.rect.x}px;top:${look.logo.rect.y}px;width:${look.logo.rect.width}px;height:${look.logo.rect.height}px">` : ""}
|
|
791
|
+
</div>
|
|
792
|
+
</body></html>
|
|
793
|
+
`;
|
|
794
|
+
}
|
|
795
|
+
var CARD_PATH = "/__card.html";
|
|
796
|
+
var FONT_SECONDS = 8;
|
|
797
|
+
var logoOf = (brand, which) => {
|
|
798
|
+
const src = brand.logo[which];
|
|
799
|
+
return src === void 0 ? void 0 : {
|
|
800
|
+
src,
|
|
801
|
+
asset: [...brand.assets.values()].find((asset) => asset.file === src)
|
|
802
|
+
};
|
|
803
|
+
};
|
|
804
|
+
var dark = "#1E1F21";
|
|
805
|
+
/** Draws every card; the browser is the caller's to close. */
|
|
806
|
+
async function drawCards(browser, job, brand, cards, scale) {
|
|
807
|
+
const site = await serve(job.siteDir);
|
|
808
|
+
try {
|
|
809
|
+
const drawn = [];
|
|
810
|
+
for (const card of cards) drawn.push(await drawCard(browser, site.origin, brand, card, scale));
|
|
811
|
+
return drawn;
|
|
812
|
+
} finally {
|
|
813
|
+
await site.close();
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
async function open(browser, origin, html, size, scale) {
|
|
817
|
+
const context = await browser.newContext({
|
|
818
|
+
viewport: size,
|
|
819
|
+
deviceScaleFactor: scale
|
|
820
|
+
});
|
|
821
|
+
await context.addInitScript("globalThis.__name = (fn) => fn;");
|
|
822
|
+
const page = await context.newPage();
|
|
823
|
+
page.setDefaultTimeout(2e4);
|
|
824
|
+
await page.route(`**${CARD_PATH}`, (route) => route.fulfill({
|
|
825
|
+
contentType: "text/html; charset=utf-8",
|
|
826
|
+
body: html
|
|
827
|
+
}));
|
|
828
|
+
await page.goto(`${origin}${CARD_PATH}`, {
|
|
829
|
+
waitUntil: "load",
|
|
830
|
+
timeout: 25e3
|
|
831
|
+
}).catch(async () => {
|
|
832
|
+
await page.goto(`${origin}${CARD_PATH}`, { waitUntil: "domcontentloaded" });
|
|
833
|
+
});
|
|
834
|
+
await page.evaluate(async (seconds) => {
|
|
835
|
+
await Promise.race([document.fonts.ready, new Promise((done) => setTimeout(done, seconds * 1e3))]);
|
|
836
|
+
}, FONT_SECONDS);
|
|
837
|
+
return {
|
|
838
|
+
context,
|
|
839
|
+
page
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
/** The boxes the card is checked on, from the DOM: the text itself (line boxes, not the block), the block, and the logo.
|
|
843
|
+
* `lines` are the boxes of each rendered line of the headline and of the subline; the accent rule above the headline counts as part of it. */
|
|
844
|
+
async function boxes(page) {
|
|
845
|
+
return page.evaluate(() => {
|
|
846
|
+
const rectOf = (r) => ({
|
|
847
|
+
x: r.x,
|
|
848
|
+
y: r.y,
|
|
849
|
+
width: r.width,
|
|
850
|
+
height: r.height
|
|
851
|
+
});
|
|
852
|
+
const lines = {
|
|
853
|
+
headline: [],
|
|
854
|
+
subline: []
|
|
855
|
+
};
|
|
856
|
+
const range = document.createRange();
|
|
857
|
+
let left = Infinity, top = Infinity, right = -Infinity, bottom = -Infinity;
|
|
858
|
+
for (const id of ["headline", "subline"]) {
|
|
859
|
+
const element = document.getElementById(id);
|
|
860
|
+
if (!element) continue;
|
|
861
|
+
range.selectNodeContents(element);
|
|
862
|
+
for (const r of Array.from(range.getClientRects())) {
|
|
863
|
+
lines[id].push(rectOf(r));
|
|
864
|
+
left = Math.min(left, r.left);
|
|
865
|
+
top = Math.min(top, r.top);
|
|
866
|
+
right = Math.max(right, r.right);
|
|
867
|
+
bottom = Math.max(bottom, r.bottom);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
const headline = document.getElementById("headline");
|
|
871
|
+
const subline = document.getElementById("subline");
|
|
872
|
+
const logo = document.getElementById("logo");
|
|
873
|
+
lines.headline.push(rectOf(document.getElementById("rule").getBoundingClientRect()));
|
|
874
|
+
const block = document.getElementById("text").getBoundingClientRect();
|
|
875
|
+
return {
|
|
876
|
+
text: {
|
|
877
|
+
x: left,
|
|
878
|
+
y: top,
|
|
879
|
+
width: right - left,
|
|
880
|
+
height: bottom - top
|
|
881
|
+
},
|
|
882
|
+
block: rectOf(block),
|
|
883
|
+
lines,
|
|
884
|
+
...logo && { logo: rectOf(logo.getBoundingClientRect()) },
|
|
885
|
+
fits: headline.scrollWidth <= headline.clientWidth + 1 && (!subline || subline.scrollWidth <= subline.clientWidth + 1)
|
|
886
|
+
};
|
|
887
|
+
});
|
|
888
|
+
}
|
|
889
|
+
/** The picture under a box as flat [r, g, b, …] pixels, at most about 20,000 of them, with `hide` hidden. */
|
|
890
|
+
async function pixelsUnder(page, box, hide) {
|
|
891
|
+
await page.addStyleTag({ content: `${hide.map((id) => `#${id}`).join(",")} { visibility: hidden !important }` });
|
|
892
|
+
const x = Math.max(0, Math.floor(box.x));
|
|
893
|
+
const y = Math.max(0, Math.floor(box.y));
|
|
894
|
+
const shot = await page.screenshot({
|
|
895
|
+
type: "png",
|
|
896
|
+
clip: {
|
|
897
|
+
x,
|
|
898
|
+
y,
|
|
899
|
+
width: Math.max(1, Math.ceil(box.x + box.width) - x),
|
|
900
|
+
height: Math.max(1, Math.ceil(box.y + box.height) - y)
|
|
901
|
+
}
|
|
902
|
+
});
|
|
903
|
+
const pixels = await page.evaluate(async (base64) => {
|
|
904
|
+
const image = new Image();
|
|
905
|
+
image.src = `data:image/png;base64,${base64}`;
|
|
906
|
+
await image.decode();
|
|
907
|
+
const canvas = document.createElement("canvas");
|
|
908
|
+
canvas.width = image.width;
|
|
909
|
+
canvas.height = image.height;
|
|
910
|
+
const context = canvas.getContext("2d");
|
|
911
|
+
context.drawImage(image, 0, 0);
|
|
912
|
+
const data = context.getImageData(0, 0, canvas.width, canvas.height).data;
|
|
913
|
+
const count = data.length / 4;
|
|
914
|
+
const stride = Math.max(1, Math.ceil(count / 2e4));
|
|
915
|
+
const out = [];
|
|
916
|
+
for (let i = 0; i < count; i += stride) out.push(data[i * 4], data[i * 4 + 1], data[i * 4 + 2]);
|
|
917
|
+
return out;
|
|
918
|
+
}, shot.toString("base64"));
|
|
919
|
+
await page.evaluate(() => document.querySelectorAll("style").forEach((style) => {
|
|
920
|
+
if (style.textContent?.includes("visibility: hidden !important")) style.remove();
|
|
921
|
+
}));
|
|
922
|
+
return pixels;
|
|
923
|
+
}
|
|
924
|
+
async function drawCard(browser, origin, brand, card, scale) {
|
|
925
|
+
const format = brand.formats.get(card.format);
|
|
926
|
+
const findings = [];
|
|
927
|
+
const size = {
|
|
928
|
+
width: format.width,
|
|
929
|
+
height: format.height
|
|
930
|
+
};
|
|
931
|
+
const asset = brand.assets.get(card.background);
|
|
932
|
+
const token = brand.tokens.get(card.background);
|
|
933
|
+
if (asset) findings.push(...backgroundFindings(card.id, asset, format));
|
|
934
|
+
const background = asset ? `url(${encodeURI(asset.file).replace(/[()]/g, (c) => `%${c.charCodeAt(0).toString(16)}`)}) center / cover no-repeat` : token?.value ?? dark;
|
|
935
|
+
const light = logoOf(brand, "onLight");
|
|
936
|
+
const onDark = logoOf(brand, "onDark");
|
|
937
|
+
const reference = onDark ?? light;
|
|
938
|
+
const artwork = {
|
|
939
|
+
width: Number(reference?.asset?.width) || 4,
|
|
940
|
+
height: Number(reference?.asset?.height) || 1
|
|
941
|
+
};
|
|
942
|
+
const plan = reference ? planLogo(format, artwork, reference.asset?.meta ?? void 0, card.anchor, {
|
|
943
|
+
...card.logoWidth !== void 0 && { width: card.logoWidth },
|
|
944
|
+
...card.logoCorner !== void 0 && { corner: card.logoCorner }
|
|
945
|
+
}) : void 0;
|
|
946
|
+
if (plan?.clampedFrom !== void 0) findings.push(logoWidthFinding(card.id, plan.clampedFrom, plan.rect.width));
|
|
947
|
+
const anchor = card.anchor ?? (plan?.corner.startsWith("top") ? "bottom" : plan ? "top" : "bottom");
|
|
948
|
+
const shared = plan !== void 0 && plan.corner.startsWith(anchor);
|
|
949
|
+
const inset = plan ? logoInset(card.align, anchor, plan) : void 0;
|
|
950
|
+
const room = format.height - 2 * format.margin - (plan && !shared ? plan.rect.height + plan.clearSpace : 0);
|
|
951
|
+
const base = {
|
|
952
|
+
format,
|
|
953
|
+
card,
|
|
954
|
+
display: brand.display,
|
|
955
|
+
bodyFamily: brand.bodyFamily,
|
|
956
|
+
fonts: brand.fonts,
|
|
957
|
+
background,
|
|
958
|
+
ground: brand.colors.inverse ?? dark,
|
|
959
|
+
textColor: brand.colors.inverseText ?? "#FFFFFF",
|
|
960
|
+
accent: brand.colors.accent ?? brand.colors.inverseText ?? "#FFFFFF",
|
|
961
|
+
size: brand.display.start,
|
|
962
|
+
anchor,
|
|
963
|
+
maxHeight: room,
|
|
964
|
+
...inset && { inset }
|
|
965
|
+
};
|
|
966
|
+
const probe = await open(browser, origin, pageHtml(base), size, 1);
|
|
967
|
+
let look;
|
|
968
|
+
try {
|
|
969
|
+
const fit = await fitHeadline(typeSteps(brand.display.start, brand.display.floor), async (px) => {
|
|
970
|
+
await probe.page.evaluate(([h, s]) => {
|
|
971
|
+
const card = document.getElementById("card");
|
|
972
|
+
card.style.setProperty("--h", `${h}px`);
|
|
973
|
+
card.style.setProperty("--s", `${s}px`);
|
|
974
|
+
}, [px, subSize(px)]);
|
|
975
|
+
const found = await boxes(probe.page);
|
|
976
|
+
return found.fits && found.block.height <= room + .5;
|
|
977
|
+
});
|
|
978
|
+
if (!fit.fits) findings.push(overflowFinding(card.id, brand.display.floor));
|
|
979
|
+
const placed = await boxes(probe.page);
|
|
980
|
+
const under = await pixelsUnder(probe.page, placed.text, ["text"]);
|
|
981
|
+
const scrimColor = parseColor(brand.colors.inverse ?? dark) ?? [
|
|
982
|
+
30,
|
|
983
|
+
31,
|
|
984
|
+
33
|
|
985
|
+
];
|
|
986
|
+
const named = card.textColor === void 0 ? void 0 : colorOf(brand, card.textColor);
|
|
987
|
+
const candidates = named ? [named] : [brand.colors.inverseText, brand.colors.text].flatMap((c) => c ? [parseColor(c)] : []).filter((c) => c !== void 0);
|
|
988
|
+
if (candidates.length === 0) candidates.push([
|
|
989
|
+
255,
|
|
990
|
+
255,
|
|
991
|
+
255
|
|
992
|
+
]);
|
|
993
|
+
const chosen = chooseText(under, candidates, scrimColor);
|
|
994
|
+
if (!chosen.ok) findings.push(contrastFinding(card.id, chosen.ratio, chosen.alpha));
|
|
995
|
+
const text = candidates[chosen.index];
|
|
996
|
+
const extent = scrimExtent(format, anchor, placed.block);
|
|
997
|
+
look = {
|
|
998
|
+
...base,
|
|
999
|
+
size: fit.size,
|
|
1000
|
+
textColor: `rgb(${text.join(",")})`,
|
|
1001
|
+
scrim: {
|
|
1002
|
+
rgb: scrimColor,
|
|
1003
|
+
alpha: chosen.alpha,
|
|
1004
|
+
extent
|
|
1005
|
+
}
|
|
1006
|
+
};
|
|
1007
|
+
if (plan) {
|
|
1008
|
+
const chosenLogo = await chooseLogo(probe, look, plan, card, light, onDark);
|
|
1009
|
+
if (chosenLogo.ratio < 3) findings.push(logoContrastFinding(card.id, chosenLogo.ratio));
|
|
1010
|
+
look = {
|
|
1011
|
+
...look,
|
|
1012
|
+
logo: {
|
|
1013
|
+
src: chosenLogo.src,
|
|
1014
|
+
rect: plan.rect
|
|
1015
|
+
}
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
1018
|
+
} finally {
|
|
1019
|
+
await probe.context.close();
|
|
1020
|
+
}
|
|
1021
|
+
const files = /* @__PURE__ */ new Map();
|
|
1022
|
+
const html = pageHtml(look);
|
|
1023
|
+
for (const factor of scale === 2 ? [1, 2] : [1]) {
|
|
1024
|
+
const { context, page } = await open(browser, origin, html, size, factor);
|
|
1025
|
+
try {
|
|
1026
|
+
if (factor === 1 && (plan || card.keepClear)) {
|
|
1027
|
+
const found = await boxes(page);
|
|
1028
|
+
if (plan) {
|
|
1029
|
+
const problem = logoFinding(card.id, {
|
|
1030
|
+
logo: found.logo ?? plan.rect,
|
|
1031
|
+
clearSpace: plan.clearSpace,
|
|
1032
|
+
text: found.text,
|
|
1033
|
+
safe: {
|
|
1034
|
+
x: format.margin,
|
|
1035
|
+
y: format.margin,
|
|
1036
|
+
width: format.width - 2 * format.margin,
|
|
1037
|
+
height: format.height - 2 * format.margin
|
|
1038
|
+
},
|
|
1039
|
+
card: {
|
|
1040
|
+
x: 0,
|
|
1041
|
+
y: 0,
|
|
1042
|
+
width: format.width,
|
|
1043
|
+
height: format.height
|
|
1044
|
+
},
|
|
1045
|
+
shared
|
|
1046
|
+
});
|
|
1047
|
+
if (problem) findings.push(problem);
|
|
1048
|
+
}
|
|
1049
|
+
if (card.keepClear) findings.push(...keepClearFindings(card.id, {
|
|
1050
|
+
card: size,
|
|
1051
|
+
zones: card.keepClear,
|
|
1052
|
+
lines: found.lines,
|
|
1053
|
+
...found.logo && { logo: found.logo }
|
|
1054
|
+
}));
|
|
1055
|
+
}
|
|
1056
|
+
files.set(factor === 1 ? `${card.id}.png` : `${card.id}@2x.png`, await page.screenshot({
|
|
1057
|
+
type: "png",
|
|
1058
|
+
clip: {
|
|
1059
|
+
x: 0,
|
|
1060
|
+
y: 0,
|
|
1061
|
+
...size
|
|
1062
|
+
}
|
|
1063
|
+
}));
|
|
1064
|
+
} finally {
|
|
1065
|
+
await context.close();
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
return {
|
|
1069
|
+
id: card.id,
|
|
1070
|
+
files,
|
|
1071
|
+
findings
|
|
1072
|
+
};
|
|
1073
|
+
}
|
|
1074
|
+
/** The contrast of a logo file against the picture under its box, with the scrim on: its own pixels, drawn alone, against the picture without it. */
|
|
1075
|
+
async function measureLogo(probe, plan, logo) {
|
|
1076
|
+
const under = await pixelsUnder(probe.page, plan.rect, ["text", "logo"]);
|
|
1077
|
+
return logoRatio(await probe.page.evaluate(async ([src, width, height]) => {
|
|
1078
|
+
const image = new Image();
|
|
1079
|
+
image.src = src;
|
|
1080
|
+
await image.decode();
|
|
1081
|
+
const canvas = document.createElement("canvas");
|
|
1082
|
+
canvas.width = width;
|
|
1083
|
+
canvas.height = height;
|
|
1084
|
+
const context = canvas.getContext("2d");
|
|
1085
|
+
context.drawImage(image, 0, 0, width, height);
|
|
1086
|
+
const data = context.getImageData(0, 0, canvas.width, canvas.height).data;
|
|
1087
|
+
const stride = Math.max(1, Math.ceil(data.length / 4 / 2e4));
|
|
1088
|
+
const out = [];
|
|
1089
|
+
for (let i = 0; i < data.length / 4; i += stride) out.push(data[i * 4], data[i * 4 + 1], data[i * 4 + 2], data[i * 4 + 3]);
|
|
1090
|
+
return out;
|
|
1091
|
+
}, [
|
|
1092
|
+
encodeURI(logo.src),
|
|
1093
|
+
plan.rect.width,
|
|
1094
|
+
plan.rect.height
|
|
1095
|
+
]), under);
|
|
1096
|
+
}
|
|
1097
|
+
/**
|
|
1098
|
+
* The logo for the surface the card shows under it, with its contrast there: the one asked for by `light` or `dark`, else the
|
|
1099
|
+
* better of the two by that same measure. A single logo is measured too.
|
|
1100
|
+
*/
|
|
1101
|
+
async function chooseLogo(probe, look, plan, card, onLight, onDark) {
|
|
1102
|
+
await probe.page.evaluate(([gradient]) => {
|
|
1103
|
+
document.getElementById("scrim").style.background = gradient;
|
|
1104
|
+
}, [scrimGradient(look)]);
|
|
1105
|
+
const asked = card.logo === "light" ? onLight : card.logo === "dark" ? onDark : void 0;
|
|
1106
|
+
const candidates = asked ? [asked] : [onDark, onLight].filter((logo) => logo !== void 0);
|
|
1107
|
+
const measured = [];
|
|
1108
|
+
for (const logo of candidates) measured.push({
|
|
1109
|
+
...logo,
|
|
1110
|
+
ratio: await measureLogo(probe, plan, logo)
|
|
1111
|
+
});
|
|
1112
|
+
return bestLogo(measured);
|
|
1113
|
+
}
|
|
1114
|
+
var IMAGES = /* @__PURE__ */ new Set([
|
|
1115
|
+
"svg",
|
|
1116
|
+
"png",
|
|
1117
|
+
"jpg",
|
|
1118
|
+
"gif",
|
|
1119
|
+
"webp",
|
|
1120
|
+
"avif"
|
|
1121
|
+
]);
|
|
1122
|
+
/** What the options may name: the formats, the image assets and color or gradient tokens as backgrounds, the color tokens. */
|
|
1123
|
+
function knownOf(brand) {
|
|
1124
|
+
const tokens = [...brand.tokens];
|
|
1125
|
+
return {
|
|
1126
|
+
formats: new Set(brand.formats.keys()),
|
|
1127
|
+
backgrounds: /* @__PURE__ */ new Set([...[...brand.assets.values()].filter((asset) => IMAGES.has(asset.format)).map((asset) => asset.id), ...tokens.filter(([, token]) => token.type === "color" || token.type === "gradient").map(([name]) => name)]),
|
|
1128
|
+
colors: new Set(tokens.filter(([, token]) => token.type === "color").map(([name]) => name))
|
|
1129
|
+
};
|
|
1130
|
+
}
|
|
1131
|
+
async function build(text) {
|
|
1132
|
+
const job = jobFor(text);
|
|
1133
|
+
const brand = readBrand(job.brand);
|
|
1134
|
+
const { cards, scale, findings } = parseOptions(job.options, knownOf(brand));
|
|
1135
|
+
if (cards.length === 0) return { findings: boundFindings(findings) };
|
|
1136
|
+
const browser = await launch(process.env);
|
|
1137
|
+
let drawn;
|
|
1138
|
+
try {
|
|
1139
|
+
drawn = await drawCards(browser, job, brand, cards, scale);
|
|
1140
|
+
} finally {
|
|
1141
|
+
await browser.close();
|
|
1142
|
+
}
|
|
1143
|
+
for (const card of drawn) {
|
|
1144
|
+
for (const [name, png] of card.files) node_fs.default.writeFileSync(node_path.default.join(job.outDir, name), png);
|
|
1145
|
+
findings.push(...card.findings);
|
|
1146
|
+
}
|
|
1147
|
+
return { findings: boundFindings(findings) };
|
|
1148
|
+
}
|
|
1149
|
+
async function main(argv) {
|
|
1150
|
+
if (argv[0] === "--blazon-manifest") {
|
|
1151
|
+
process.stdout.write(`${JSON.stringify(MANIFEST)}\n`);
|
|
1152
|
+
return 0;
|
|
1153
|
+
}
|
|
1154
|
+
try {
|
|
1155
|
+
process.stdout.write(`${JSON.stringify(await build(node_fs.default.readFileSync(0, "utf-8")))}\n`);
|
|
1156
|
+
return 0;
|
|
1157
|
+
} catch (error) {
|
|
1158
|
+
const reason = error instanceof Cannot ? error.message : `the browser could not draw the cards: ${String(error.message ?? error).split("\n")[0].slice(0, 500)}`;
|
|
1159
|
+
process.stdout.write(`${reason}\n`);
|
|
1160
|
+
return 2;
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
main(process.argv.slice(2)).then((code) => {
|
|
1164
|
+
process.exitCode = code;
|
|
1165
|
+
});
|