@iksnerd/blazon 0.0.0-stage → 0.1.0
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 +264 -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-vpzUWoiA.js +13777 -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 +593 -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 +152 -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 +69 -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-BdbihVvH.js +77 -0
- package/dist/ui/assets/index-DluSqfla.css +2 -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 +38 -0
- package/plugins/blazon.print-book/bin/blazon-blazon.print-book./360/237/224/214 +9262 -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,2695 @@
|
|
|
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 pdf_lib = require("pdf-lib");
|
|
28
|
+
/** The plugin cannot do what it was asked; the message is the reason blazon shows. */
|
|
29
|
+
var Cannot = class extends Error {};
|
|
30
|
+
/** The builder of a plugin's findings: `findingFor(NAME)('code', severity, path, message)` is a finding coded `NAME/code`. */
|
|
31
|
+
var findingFor = (name) => (code, severity, path, message) => ({
|
|
32
|
+
code: `${name}/${code}`,
|
|
33
|
+
severity,
|
|
34
|
+
path,
|
|
35
|
+
message
|
|
36
|
+
});
|
|
37
|
+
/** The plugin's name, which blazon's config names it by, and the prefix of its finding codes */
|
|
38
|
+
var NAME = "blazon.brand-deck";
|
|
39
|
+
var MANIFEST = {
|
|
40
|
+
v: 2,
|
|
41
|
+
roles: ["build"],
|
|
42
|
+
title: "Brand deck",
|
|
43
|
+
description: "Draws the brand as a 16:9 PDF deck: logos with their rules, colors, type, the brand book's guideline pages and the favicon set.",
|
|
44
|
+
version: "1.1.0",
|
|
45
|
+
timeout_ms: 6e4,
|
|
46
|
+
env: [
|
|
47
|
+
"BLAZON_CHROME",
|
|
48
|
+
"BLAZON_DECK_FONTS",
|
|
49
|
+
"HOME",
|
|
50
|
+
"TMPDIR"
|
|
51
|
+
]
|
|
52
|
+
};
|
|
53
|
+
var isFolder = (value) => typeof value === "string" && node_fs.default.statSync(value, { throwIfNoEntry: false })?.isDirectory() === true;
|
|
54
|
+
/** The job a build request asks for, or Cannot with the reason. The options are checked later, and wrong ones are findings. */
|
|
55
|
+
function jobFor(text) {
|
|
56
|
+
let request;
|
|
57
|
+
try {
|
|
58
|
+
request = JSON.parse(text);
|
|
59
|
+
} catch {
|
|
60
|
+
throw new Cannot("the request is not JSON");
|
|
61
|
+
}
|
|
62
|
+
if (typeof request !== "object" || request === null || Array.isArray(request)) throw new Cannot("the request is not a JSON object");
|
|
63
|
+
const asked = request;
|
|
64
|
+
if (asked.v !== 1) throw new Cannot("this plugin speaks version 1 of the request");
|
|
65
|
+
if (asked.type !== "build") throw new Cannot("this plugin fills the build role");
|
|
66
|
+
for (const field of ["site_dir", "out_dir"]) if (!isFolder(asked[field])) throw new Cannot(`${field} must name a directory that exists`);
|
|
67
|
+
return {
|
|
68
|
+
siteDir: asked.site_dir,
|
|
69
|
+
outDir: asked.out_dir,
|
|
70
|
+
brand: asked.brand,
|
|
71
|
+
options: asked.options ?? {}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
75
|
+
/** A real number: not a boolean, not a string */
|
|
76
|
+
var isNumber = (value) => typeof value === "number" && Number.isFinite(value);
|
|
77
|
+
/** Python's truthiness for what a sidecar holds: a non-empty list, object or text, a non-zero number */
|
|
78
|
+
var has = (value) => Array.isArray(value) ? value.length > 0 : isObject(value) ? Object.keys(value).length > 0 : typeof value === "number" ? value !== 0 : Boolean(value);
|
|
79
|
+
var FORMAT = "blazon-brand";
|
|
80
|
+
/** Python's repr of a value in the message that names a wrong format: 'x' for text, None for nothing */
|
|
81
|
+
var shown = (value) => typeof value === "string" ? `'${value}'` : value === void 0 || value === null ? "None" : JSON.stringify(value);
|
|
82
|
+
var objects = (value) => Array.isArray(value) ? value.filter(isObject) : [];
|
|
83
|
+
/** The brand when the request holds a blazon brand of a version this deck reads; Cannot otherwise. `source` only names it in the message. */
|
|
84
|
+
function readBrand(raw, source = "the brand in the request") {
|
|
85
|
+
if (!isObject(raw) || raw.format !== "blazon-brand") throw new Cannot(`${source} is not a blazon brand: its format is ${shown(isObject(raw) ? raw.format : void 0)}, not '${FORMAT}'`);
|
|
86
|
+
if (raw.version !== 1) throw new Cannot(`${source} is version ${shown(raw.version)}; this reader understands version 1`);
|
|
87
|
+
const brand = isObject(raw.brand) ? raw.brand : {};
|
|
88
|
+
const theme = isObject(raw.theme) ? raw.theme : {};
|
|
89
|
+
return {
|
|
90
|
+
brand: {
|
|
91
|
+
title: typeof brand.title === "string" ? brand.title : "",
|
|
92
|
+
...typeof brand.description === "string" && brand.description !== "" && { description: brand.description }
|
|
93
|
+
},
|
|
94
|
+
theme: {
|
|
95
|
+
roles: isObject(theme.roles) ? theme.roles : {},
|
|
96
|
+
fonts: Array.isArray(theme.fonts) ? theme.fonts : []
|
|
97
|
+
},
|
|
98
|
+
logo: isObject(raw.logo) ? raw.logo : {},
|
|
99
|
+
tokens: objects(raw.tokens).filter((item) => typeof item.path === "string"),
|
|
100
|
+
groups: objects(raw.groups).filter((item) => typeof item.path === "string"),
|
|
101
|
+
pages: objects(raw.pages).map((page) => ({
|
|
102
|
+
...page,
|
|
103
|
+
title: typeof page.title === "string" ? page.title : "",
|
|
104
|
+
order: isNumber(page.order) ? page.order : 0,
|
|
105
|
+
sections: Array.isArray(page.sections) ? page.sections.filter((id) => typeof id === "string") : [],
|
|
106
|
+
directives: objects(page.directives)
|
|
107
|
+
})),
|
|
108
|
+
assets: objects(raw.assets).filter((item) => typeof item.id === "string" && typeof item.file === "string"),
|
|
109
|
+
categories: objects(raw.categories).filter((item) => typeof item.category === "string")
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/** A dimension {"value": 20, "unit": "px"} in pixels; a rem is 16px */
|
|
113
|
+
function dimensionPx(dimension) {
|
|
114
|
+
if (!isObject(dimension) || !isNumber(dimension.value)) return void 0;
|
|
115
|
+
return dimension.value * (dimension.unit === "rem" ? 16 : 1);
|
|
116
|
+
}
|
|
117
|
+
/** A measure in the artwork's own pixels: a dimension, or {"units": n} of the asset's unit. undefined if unknown. */
|
|
118
|
+
function measurePx(measure, meta) {
|
|
119
|
+
if (!isObject(measure)) return void 0;
|
|
120
|
+
if ("units" in measure) {
|
|
121
|
+
const unit = dimensionPx(meta.unit);
|
|
122
|
+
return isNumber(measure.units) && unit !== void 0 ? measure.units * unit : void 0;
|
|
123
|
+
}
|
|
124
|
+
return dimensionPx(measure);
|
|
125
|
+
}
|
|
126
|
+
var INSTALL_HINT = "install Google Chrome, or set BLAZON_CHROME to a Chrome or Chromium program";
|
|
127
|
+
/**
|
|
128
|
+
* The browser: the program BLAZON_CHROME names, else the Google Chrome installed on this computer. It never downloads one.
|
|
129
|
+
* `what` completes "no browser to ...", such as "print with".
|
|
130
|
+
*/
|
|
131
|
+
async function launchChrome(env, what) {
|
|
132
|
+
const named = env.BLAZON_CHROME;
|
|
133
|
+
if (named) {
|
|
134
|
+
if (!isProgram(named)) throw new Cannot(`no browser to ${what}: BLAZON_CHROME names ${named}, which is not a program; ${INSTALL_HINT}`);
|
|
135
|
+
return playwright_core.chromium.launch({ executablePath: named });
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
return await playwright_core.chromium.launch({ channel: "chrome" });
|
|
139
|
+
} catch {
|
|
140
|
+
throw new Cannot(`no browser to ${what}: ${INSTALL_HINT}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function isProgram(file) {
|
|
144
|
+
try {
|
|
145
|
+
node_fs.default.accessSync(file, node_fs.default.constants.X_OK);
|
|
146
|
+
return node_fs.default.statSync(file).isFile();
|
|
147
|
+
} catch {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/** The browser to draw with: the program BLAZON_CHROME names, else the Google Chrome installed on this computer. */
|
|
152
|
+
var launch = (env) => launchChrome(env, "draw the deck with");
|
|
153
|
+
var PAGE = {
|
|
154
|
+
width: 960,
|
|
155
|
+
height: 540
|
|
156
|
+
};
|
|
157
|
+
var PX_TO_PT = .5;
|
|
158
|
+
var GUIDE_SIZES = [
|
|
159
|
+
12,
|
|
160
|
+
11,
|
|
161
|
+
10
|
|
162
|
+
];
|
|
163
|
+
var GUIDE_PANELS = [
|
|
164
|
+
540,
|
|
165
|
+
450,
|
|
166
|
+
360
|
|
167
|
+
];
|
|
168
|
+
var FONTS_LEAD = 14.3;
|
|
169
|
+
var GUIDE_LEAD = 1.3;
|
|
170
|
+
/** (columns of Do and Don't, traits as one line), the plainest first */
|
|
171
|
+
var GUIDE_FORMS = [
|
|
172
|
+
[1, false],
|
|
173
|
+
[1, true],
|
|
174
|
+
[2, false],
|
|
175
|
+
[2, true]
|
|
176
|
+
];
|
|
177
|
+
/** An integer when the value is whole, so 180.0 reads and compares as 180. */
|
|
178
|
+
function number(value) {
|
|
179
|
+
return Number.isInteger(value) ? value : Math.round(value * 1e3) / 1e3;
|
|
180
|
+
}
|
|
181
|
+
/** `webUsage` and `web-usage` become "Web usage". */
|
|
182
|
+
function humanize(name) {
|
|
183
|
+
const words = name.replace(/(?<=[a-z0-9])(?=[A-Z])/g, " ").replace(/[-_]/g, " ").toLowerCase().split(/\s+/).filter(Boolean);
|
|
184
|
+
if (words.length === 0) return name;
|
|
185
|
+
const joined = words.join(" ");
|
|
186
|
+
return joined.charAt(0).toUpperCase() + joined.slice(1);
|
|
187
|
+
}
|
|
188
|
+
/** (r, g, b, alpha) from #rgb, #rgba, #rrggbb or #rrggbbaa; undefined for any other value. */
|
|
189
|
+
function parseHex(value) {
|
|
190
|
+
const match = /^#([0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.exec(String(value).trim());
|
|
191
|
+
if (!match) return void 0;
|
|
192
|
+
let digits = match[1];
|
|
193
|
+
if (digits.length === 3 || digits.length === 4) digits = [...digits].map((ch) => ch + ch).join("");
|
|
194
|
+
const channels = (digits.match(/../g) ?? []).map((pair) => parseInt(pair, 16));
|
|
195
|
+
return [
|
|
196
|
+
channels[0],
|
|
197
|
+
channels[1],
|
|
198
|
+
channels[2],
|
|
199
|
+
channels.length === 4 ? channels[3] / 255 : 1
|
|
200
|
+
];
|
|
201
|
+
}
|
|
202
|
+
var lastName = (path) => path.slice(path.lastIndexOf(".") + 1);
|
|
203
|
+
var parentOf = (path) => path.slice(0, Math.max(path.lastIndexOf("."), 0));
|
|
204
|
+
var unique = (items) => [...new Set(items)];
|
|
205
|
+
var textOrNull = (value) => typeof value === "string" && value !== "" ? value : null;
|
|
206
|
+
var listOf = (value) => Array.isArray(value) ? value.map(String) : [];
|
|
207
|
+
function sourceLine(source) {
|
|
208
|
+
return isObject(source) && has(source.doc) && has(source.locator) ? `Source: ${String(source.doc)}, ${String(source.locator)}` : null;
|
|
209
|
+
}
|
|
210
|
+
/** Each chunk with its slide title, numbered when there are several. */
|
|
211
|
+
function titled(title, chunks) {
|
|
212
|
+
return chunks.map((chunk, index) => [chunks.length > 1 ? `${title} (${index + 1} of ${chunks.length})` : title, chunk]);
|
|
213
|
+
}
|
|
214
|
+
/** Items over as few slides of at most `count` as that allows, shared as evenly as they divide, in order: seven over slides of six are four and three, never six and one. */
|
|
215
|
+
function balanced(items, count) {
|
|
216
|
+
if (items.length === 0) return [];
|
|
217
|
+
const slides = Math.ceil(items.length / count);
|
|
218
|
+
const base = Math.floor(items.length / slides);
|
|
219
|
+
const extra = items.length % slides;
|
|
220
|
+
const chunks = [];
|
|
221
|
+
let start = 0;
|
|
222
|
+
for (let index = 0; index < slides; index++) {
|
|
223
|
+
const size = base + (index < extra ? 1 : 0);
|
|
224
|
+
chunks.push(items.slice(start, start + size));
|
|
225
|
+
start += size;
|
|
226
|
+
}
|
|
227
|
+
return chunks;
|
|
228
|
+
}
|
|
229
|
+
/** Split items evenly over slides of at most `count`, numbering the titles when there are several. */
|
|
230
|
+
function paged(title, count, items) {
|
|
231
|
+
return titled(title, balanced(items, count));
|
|
232
|
+
}
|
|
233
|
+
function groupNote(brand, path) {
|
|
234
|
+
for (const group of brand.groups) if (group.path === path) return group.description ?? null;
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* A title for each group path: its last name made readable, and where two groups end in the same name, the name before it
|
|
239
|
+
* too ("Hue yellow", "Product yellow"), and the whole path for a group that is still told apart by nothing else.
|
|
240
|
+
*/
|
|
241
|
+
function groupTitles(parents) {
|
|
242
|
+
const titles = /* @__PURE__ */ new Map();
|
|
243
|
+
for (const depth of [1, 2]) {
|
|
244
|
+
const names = new Map(parents.map((parent) => [parent, humanize(parent.split(".").slice(-depth).join(" "))]));
|
|
245
|
+
for (const [parent, name] of names) if (!titles.has(parent) && [...names.values()].filter((other) => other === name).length === 1) titles.set(parent, name);
|
|
246
|
+
}
|
|
247
|
+
return new Map(parents.map((parent) => [parent, titles.get(parent) ?? humanize(parent.split(".").join(" "))]));
|
|
248
|
+
}
|
|
249
|
+
function swatchOf(token) {
|
|
250
|
+
const rgb = parseHex(token.value);
|
|
251
|
+
const print = isObject(token.blazon?.print) ? token.blazon.print : {};
|
|
252
|
+
const value = String(token.value);
|
|
253
|
+
return {
|
|
254
|
+
name: lastName(token.path),
|
|
255
|
+
path: token.path,
|
|
256
|
+
hex: rgb ? value.toUpperCase() : value,
|
|
257
|
+
rgb: rgb ? [
|
|
258
|
+
rgb[0],
|
|
259
|
+
rgb[1],
|
|
260
|
+
rgb[2]
|
|
261
|
+
] : null,
|
|
262
|
+
cmyk: Array.isArray(print.cmyk) ? print.cmyk : null,
|
|
263
|
+
pms: typeof print.pms === "string" ? print.pms : null,
|
|
264
|
+
ral: typeof print.ral === "string" ? print.ral : null,
|
|
265
|
+
description: token.description ?? null
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
/** The lines of values a swatch has under its name and hex: RGB, CMYK, Pantone and RAL, each when it states one. */
|
|
269
|
+
function printLines(swatch) {
|
|
270
|
+
return [
|
|
271
|
+
swatch.rgb,
|
|
272
|
+
swatch.cmyk,
|
|
273
|
+
swatch.pms,
|
|
274
|
+
swatch.ral
|
|
275
|
+
].filter(has).length;
|
|
276
|
+
}
|
|
277
|
+
/** The room a group's row needs on a slide, in points, at the smallest the deck draws it: heading, a low swatch, name and hex, each line of values, and a gap. */
|
|
278
|
+
function groupHeight(group) {
|
|
279
|
+
return 93 + 12 * Math.max(...group.swatches.map(printLines)) + 10;
|
|
280
|
+
}
|
|
281
|
+
function colorsSlideOf(title, groups) {
|
|
282
|
+
return {
|
|
283
|
+
kind: "colors",
|
|
284
|
+
title,
|
|
285
|
+
note: groups.length === 1 ? groups[0].note : null,
|
|
286
|
+
groups,
|
|
287
|
+
swatches: groups.flatMap((group) => group.swatches)
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* The palette in groups, by the parent of each color's path. A group of up to eight is one row that is never split, and up to
|
|
292
|
+
* three groups share a slide in order, as many as the room allows: a group with CMYK, Pantone and RAL values needs more than one
|
|
293
|
+
* with a hex and RGB. A bigger group has slides of its own, eight swatches on each.
|
|
294
|
+
*/
|
|
295
|
+
function paletteSlides(brand) {
|
|
296
|
+
const parents = /* @__PURE__ */ new Map();
|
|
297
|
+
for (const token of brand.tokens) if (token.type === "color" && !has(token.aliasOf)) {
|
|
298
|
+
const parent = parentOf(token.path);
|
|
299
|
+
parents.set(parent, [...parents.get(parent) ?? [], token]);
|
|
300
|
+
}
|
|
301
|
+
const titles = groupTitles([...parents.keys()]);
|
|
302
|
+
const groups = [...parents].map(([parent, tokens]) => ({
|
|
303
|
+
title: titles.get(parent),
|
|
304
|
+
note: groupNote(brand, parent),
|
|
305
|
+
swatches: tokens.map(swatchOf)
|
|
306
|
+
}));
|
|
307
|
+
const slides = [];
|
|
308
|
+
let shared = [];
|
|
309
|
+
const flush = () => {
|
|
310
|
+
if (shared.length > 0) {
|
|
311
|
+
const title = shared.length === 1 ? shared[0].title : shared.length === 2 ? shared.map((group) => group.title).join(" and ") : "Colors";
|
|
312
|
+
slides.push(colorsSlideOf(title, shared));
|
|
313
|
+
}
|
|
314
|
+
shared = [];
|
|
315
|
+
};
|
|
316
|
+
for (const group of groups) {
|
|
317
|
+
const size = group.swatches.length;
|
|
318
|
+
if (size > 8) {
|
|
319
|
+
flush();
|
|
320
|
+
const chunks = [];
|
|
321
|
+
for (let i = 0; i < size; i += 8) chunks.push(group.swatches.slice(i, i + 8));
|
|
322
|
+
for (const [title, chunk] of titled(group.title, chunks)) slides.push(colorsSlideOf(title, [{
|
|
323
|
+
...group,
|
|
324
|
+
swatches: chunk
|
|
325
|
+
}]));
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
if (shared.length > 0 && (shared.length === 3 || shared.reduce((sum, member) => sum + groupHeight(member), 0) + groupHeight(group) > 366)) flush();
|
|
329
|
+
shared.push(group);
|
|
330
|
+
}
|
|
331
|
+
flush();
|
|
332
|
+
return slides;
|
|
333
|
+
}
|
|
334
|
+
function gradientAngle(value) {
|
|
335
|
+
const text = String(value);
|
|
336
|
+
const degrees = /linear-gradient\(\s*(-?[\d.]+)deg/.exec(text);
|
|
337
|
+
if (degrees) return number(Number(degrees[1]));
|
|
338
|
+
const corner = /linear-gradient\(\s*to (top|right|bottom|left)\b/.exec(text);
|
|
339
|
+
return corner ? {
|
|
340
|
+
top: 0,
|
|
341
|
+
right: 90,
|
|
342
|
+
bottom: 180,
|
|
343
|
+
left: 270
|
|
344
|
+
}[corner[1]] : 180;
|
|
345
|
+
}
|
|
346
|
+
function gradientSlides(brand) {
|
|
347
|
+
return paged("Gradients", 6, brand.tokens.filter((token) => token.type === "gradient" && !has(token.aliasOf) && Array.isArray(token.resolvedValue)).map((token) => ({
|
|
348
|
+
name: lastName(token.path),
|
|
349
|
+
path: token.path,
|
|
350
|
+
angle: gradientAngle(token.value),
|
|
351
|
+
stops: token.resolvedValue
|
|
352
|
+
}))).map(([title, chunk]) => ({
|
|
353
|
+
kind: "gradients",
|
|
354
|
+
title,
|
|
355
|
+
gradients: chunk
|
|
356
|
+
}));
|
|
357
|
+
}
|
|
358
|
+
var FAVICON_FILES_PT = 350;
|
|
359
|
+
var FAVICON_SWATCHES_PT = 84;
|
|
360
|
+
function fitsUnderTable(rows, headLines) {
|
|
361
|
+
return 6 + rows * 17 + Math.max(22 + headLines * 14, FAVICON_SWATCHES_PT) <= FAVICON_FILES_PT;
|
|
362
|
+
}
|
|
363
|
+
/** The Favicons part: a slide for each view the plugin drew, the table of its files and the head snippet. A key an older file lacks leaves that slide out. */
|
|
364
|
+
function faviconSlides(favicons) {
|
|
365
|
+
const base = `${favicons.folder}/favicons.json`;
|
|
366
|
+
const notes = {
|
|
367
|
+
tabs: "The favicon in a light and a dark browser tab, with the 16 px and 32 px icons enlarged and drawn pixelated.",
|
|
368
|
+
masks: "The 1024 px master under the iOS and Android masks. Dashed circles: the maskable safe zone (80%) and the Android adaptive safe zone (66 dp).",
|
|
369
|
+
sizes: "The master at the iOS app-icon sizes, 180 px down to 29 px."
|
|
370
|
+
};
|
|
371
|
+
const slides = [];
|
|
372
|
+
for (const view of favicons.views ?? []) {
|
|
373
|
+
let note = notes[view.id] ?? null;
|
|
374
|
+
const adaptive = favicons.adaptive;
|
|
375
|
+
if (view.id === "masks" && adaptive && "symbolReach" in adaptive && note !== null) note += ` The symbol reaches ${(adaptive.symbolReach * 100).toFixed(1)}% of the Android layer's width from its centre; the adaptive safe zone is ${(adaptive.safeRadius * 100).toFixed(1)}%.`;
|
|
376
|
+
slides.push({
|
|
377
|
+
kind: "favicon-view",
|
|
378
|
+
title: view.title,
|
|
379
|
+
base,
|
|
380
|
+
file: view.file,
|
|
381
|
+
width: view.width,
|
|
382
|
+
height: view.height,
|
|
383
|
+
note
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
const head = favicons.head ? favicons.head.split(/\r?\n/).filter((_, i, all) => !(i === all.length - 1 && all[i] === "")) : null;
|
|
387
|
+
const colors = favicons.colors ?? {};
|
|
388
|
+
const rows = favicons.files ?? [];
|
|
389
|
+
const together = rows.length > 0 && head !== null && fitsUnderTable(rows.length, head.length) && head.every((line) => [...line].length <= 70);
|
|
390
|
+
if (rows.length > 0) slides.push({
|
|
391
|
+
kind: "favicon-files",
|
|
392
|
+
title: "Favicon files",
|
|
393
|
+
rows,
|
|
394
|
+
...together ? {
|
|
395
|
+
head,
|
|
396
|
+
colors
|
|
397
|
+
} : {}
|
|
398
|
+
});
|
|
399
|
+
if (head && !together) slides.push({
|
|
400
|
+
kind: "favicon-head",
|
|
401
|
+
title: "Favicon head snippet",
|
|
402
|
+
head,
|
|
403
|
+
colors
|
|
404
|
+
});
|
|
405
|
+
if (slides.length === 0) return slides;
|
|
406
|
+
return [{
|
|
407
|
+
kind: "page",
|
|
408
|
+
title: "Favicons",
|
|
409
|
+
description: "The favicon and app-icon set, drawn from the logo symbol: how it looks in a browser tab and under each platform mask, and the files and tags that ship it.",
|
|
410
|
+
open: []
|
|
411
|
+
}, ...slides];
|
|
412
|
+
}
|
|
413
|
+
/** An asset's sidecar title, or its name made readable. */
|
|
414
|
+
function assetTitle(asset) {
|
|
415
|
+
const title = asset.meta?.title;
|
|
416
|
+
return typeof title === "string" && title !== "" ? title : humanize(asset.name);
|
|
417
|
+
}
|
|
418
|
+
var backgroundOf = (asset) => typeof asset.meta?.background === "string" ? asset.meta.background : "light";
|
|
419
|
+
/** The assets a directive lists: its category, narrowed and ordered by the names it gives */
|
|
420
|
+
function membersOf(brand, directive) {
|
|
421
|
+
const [key, ...names] = directive.args ?? [];
|
|
422
|
+
const members = brand.assets.filter((asset) => asset.category === key);
|
|
423
|
+
if (names.length === 0) return members;
|
|
424
|
+
const byName = new Map(members.map((asset) => [asset.name, asset]));
|
|
425
|
+
return names.flatMap((name) => byName.has(name) ? [byName.get(name)] : []);
|
|
426
|
+
}
|
|
427
|
+
var UNIT_WORDS = ["unit", "units"];
|
|
428
|
+
var pxText = (px) => `${number(px)}px`;
|
|
429
|
+
function sizeText(size) {
|
|
430
|
+
return ["width", "height"].filter((side) => side in size).map((side) => `${side} ${pxText(dimensionPx(size[side]) ?? 0)}`).join(", ");
|
|
431
|
+
}
|
|
432
|
+
/** The (label, text) lines a logo's sidecar states, and its clear space in artwork pixels. `titleOf` names another asset by its id, for the one to use below a size. */
|
|
433
|
+
function logoRules(meta, titleOf = () => void 0) {
|
|
434
|
+
const rules = [];
|
|
435
|
+
let clearPx = null;
|
|
436
|
+
if ("lockup" in meta) rules.push({
|
|
437
|
+
label: "Lockup",
|
|
438
|
+
text: String(meta.lockup)
|
|
439
|
+
});
|
|
440
|
+
if ("clearSpace" in meta) {
|
|
441
|
+
const clear = measurePx(meta.clearSpace, meta);
|
|
442
|
+
const units = isObject(meta.clearSpace) ? meta.clearSpace.units : void 0;
|
|
443
|
+
if (clear !== void 0) {
|
|
444
|
+
clearPx = clear;
|
|
445
|
+
const suffix = isNumber(units) ? ` (${number(units)} ${UNIT_WORDS[units !== 1 ? 1 : 0]})` : "";
|
|
446
|
+
rules.push({
|
|
447
|
+
label: "Clear space",
|
|
448
|
+
text: pxText(clear) + suffix
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
if (isObject(meta.minSize) && has(meta.minSize)) rules.push({
|
|
453
|
+
label: "Minimum size",
|
|
454
|
+
text: sizeText(meta.minSize)
|
|
455
|
+
});
|
|
456
|
+
if (isObject(meta.maxSize) && has(meta.maxSize)) rules.push({
|
|
457
|
+
label: "Maximum size",
|
|
458
|
+
text: sizeText(meta.maxSize)
|
|
459
|
+
});
|
|
460
|
+
const replaced = meta.replacedBelow;
|
|
461
|
+
if (isObject(replaced) && has(replaced)) {
|
|
462
|
+
const by = String(replaced.by);
|
|
463
|
+
rules.push({
|
|
464
|
+
label: "Smaller sizes",
|
|
465
|
+
text: `below ${sizeText(replaced)}, use ${titleOf(by) ?? by}`
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
if (Array.isArray(meta.placement) && meta.placement.length > 0) rules.push({
|
|
469
|
+
label: "Placement",
|
|
470
|
+
text: meta.placement.join(", ")
|
|
471
|
+
});
|
|
472
|
+
const partnership = meta.partnership;
|
|
473
|
+
if (isObject(partnership) && has(partnership)) {
|
|
474
|
+
const parts = [];
|
|
475
|
+
for (const [key, label] of [
|
|
476
|
+
["gap", "gap"],
|
|
477
|
+
["dividerHeight", "divider height"],
|
|
478
|
+
["partnerHeight", "partner height"]
|
|
479
|
+
]) {
|
|
480
|
+
const px = key in partnership ? measurePx(partnership[key], meta) : void 0;
|
|
481
|
+
if (px !== void 0) parts.push(`${label} ${pxText(px)}`);
|
|
482
|
+
}
|
|
483
|
+
if (!("dividerHeight" in partnership)) parts.push("no divider");
|
|
484
|
+
if (parts.length > 0) rules.push({
|
|
485
|
+
label: "Partnership",
|
|
486
|
+
text: parts.join(", ")
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
const initiative = meta.initiative;
|
|
490
|
+
if (isObject(initiative) && typeof initiative.name === "string") {
|
|
491
|
+
const gap = measurePx(initiative.gap, meta);
|
|
492
|
+
const parts = [initiative.position === "below" ? "mark below the logo" : "mark beside the logo"];
|
|
493
|
+
if (gap !== void 0) parts.push(`gap ${pxText(gap)}`);
|
|
494
|
+
rules.push({
|
|
495
|
+
label: "Program",
|
|
496
|
+
text: `${initiative.name}, ${parts.join(", ")}`
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
return {
|
|
500
|
+
rules,
|
|
501
|
+
clearPx
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
function logoSlides(brand, skip = []) {
|
|
505
|
+
const byId = new Map(brand.assets.map((asset) => [asset.id, asset]));
|
|
506
|
+
const titleOf = (id) => byId.has(id) ? assetTitle(byId.get(id)) : void 0;
|
|
507
|
+
const slides = [];
|
|
508
|
+
for (const asset of brand.assets) {
|
|
509
|
+
if (asset.category !== "logos" || skip.includes("logos")) continue;
|
|
510
|
+
const meta = asset.meta ?? {};
|
|
511
|
+
const { rules, clearPx } = logoRules(meta, titleOf);
|
|
512
|
+
slides.push({
|
|
513
|
+
kind: "logo",
|
|
514
|
+
title: assetTitle(asset),
|
|
515
|
+
file: asset.file,
|
|
516
|
+
format: asset.format,
|
|
517
|
+
width: asset.width,
|
|
518
|
+
height: asset.height,
|
|
519
|
+
background: backgroundOf(asset),
|
|
520
|
+
note: textOrNull(meta.description),
|
|
521
|
+
rules,
|
|
522
|
+
clear_space_px: clearPx
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
return slides;
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* The heading each of the page's directives sits under, in the order of page.directives: the nearest heading above it, or the
|
|
529
|
+
* page's title when there is none. The Markdown is read as blazon reads it for the directives (a fence or a code span places none);
|
|
530
|
+
* if what is found there is not the list brand.json carries, no heading is claimed and every directive falls back to the title.
|
|
531
|
+
*/
|
|
532
|
+
function directiveHeadings(page) {
|
|
533
|
+
let text = (page.markdown ?? "").replace(/^(```|~~~)[^\n]*\n[\s\S]*?^\1[^\n]*$/gm, "");
|
|
534
|
+
text = text.replace(/`[^`\n]*`/g, (span) => span.replace("<!--", "<!--"));
|
|
535
|
+
let heading = page.title;
|
|
536
|
+
const found = [];
|
|
537
|
+
const names = [];
|
|
538
|
+
for (const match of text.matchAll(/^#{1,6}[ \t]+(.+?)[ \t]*#*[ \t]*$|<!--\s*blazon:([\w-]+)(?:\s+([^>]*?))?\s*-->/gm)) if (match[2] === void 0) heading = match[1].replace(/\[([^\]]*)\]\([^)]*\)/g, "$1").replace(/`/g, "").replace(/\*/g, "").trim() || heading;
|
|
539
|
+
else {
|
|
540
|
+
names.push([match[2], (match[3] ?? "").split(/\s+/).filter(Boolean)]);
|
|
541
|
+
found.push(heading);
|
|
542
|
+
}
|
|
543
|
+
return names.length === page.directives.length && names.every(([name, args], index) => name === page.directives[index].name && args.join("\0") === (page.directives[index].args ?? []).join("\0")) ? found : page.directives.map(() => page.title);
|
|
544
|
+
}
|
|
545
|
+
/** The area, in points squared, of the smallest picture when pictures of these width/height ratios fill a grid of cols x rows. */
|
|
546
|
+
function gridFit(ratios, cols, rows) {
|
|
547
|
+
const cellW = (PAGE.width - 112 - 16 * (cols - 1)) / cols;
|
|
548
|
+
const cellH = (340 - 14 * (rows - 1)) / rows - 30;
|
|
549
|
+
return Math.min(...ratios.map((ratio) => {
|
|
550
|
+
const width = Math.min(cellW, cellH * ratio);
|
|
551
|
+
return width * width / ratio;
|
|
552
|
+
}));
|
|
553
|
+
}
|
|
554
|
+
/** (cols, rows) of the best grid for pictures of these ratios (the most room for the smallest), and that smallest area. */
|
|
555
|
+
function gridLayouts(ratios) {
|
|
556
|
+
const count = ratios.length;
|
|
557
|
+
let best;
|
|
558
|
+
for (let cols = 1; cols <= Math.min(count, 3); cols++) {
|
|
559
|
+
const option = {
|
|
560
|
+
area: gridFit(ratios, cols, Math.ceil(count / cols)),
|
|
561
|
+
cols
|
|
562
|
+
};
|
|
563
|
+
if (!best || option.area > best.area || option.area === best.area && option.cols < best.cols) best = option;
|
|
564
|
+
}
|
|
565
|
+
return {
|
|
566
|
+
cols: best.cols,
|
|
567
|
+
rows: Math.ceil(count / best.cols),
|
|
568
|
+
area: best.area
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
/** The slides of figures, in their order: as many on each as keep every picture at GRID_MIN_AREA, up to GRID_MAX. The first is titled `title` and the ones after it "(continued)". */
|
|
572
|
+
function gridSlides(title, all) {
|
|
573
|
+
const roomy = (chunk) => chunk.length === 1 || gridLayouts(chunk.map((figure) => figure.ratio)).area >= 16e3;
|
|
574
|
+
const greedy = [];
|
|
575
|
+
for (let rest = all; rest.length > 0;) {
|
|
576
|
+
let count = 1;
|
|
577
|
+
for (let size = Math.min(6, rest.length); size > 1; size--) if (roomy(rest.slice(0, size))) {
|
|
578
|
+
count = size;
|
|
579
|
+
break;
|
|
580
|
+
}
|
|
581
|
+
greedy.push(rest.slice(0, count));
|
|
582
|
+
rest = rest.slice(count);
|
|
583
|
+
}
|
|
584
|
+
const even = greedy.length > 0 ? balanced(all, Math.ceil(all.length / greedy.length)) : [];
|
|
585
|
+
const chunks = even.length === greedy.length && even.every(roomy) ? even : greedy;
|
|
586
|
+
const slides = [];
|
|
587
|
+
for (const here of chunks) {
|
|
588
|
+
const { cols, rows } = gridLayouts(here.map((figure) => figure.ratio));
|
|
589
|
+
slides.push({
|
|
590
|
+
kind: "grid",
|
|
591
|
+
title: slides.length === 0 ? title : `${title} (continued)`,
|
|
592
|
+
cols,
|
|
593
|
+
rows,
|
|
594
|
+
figures: here.map(({ ratio: _ratio, ...figure }) => figure)
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
return slides;
|
|
598
|
+
}
|
|
599
|
+
/** The figures a `blazon:assets` directive lists, in its order. A category in `skip`, a name with no asset and an asset in `drawn` (a set of asset ids, which this adds to) give none. */
|
|
600
|
+
function gridFigures(brand, directive, skip, drawn) {
|
|
601
|
+
const key = directive.args[0];
|
|
602
|
+
if (skip.includes(key)) return [];
|
|
603
|
+
const category = brand.categories.find((candidate) => candidate.category === key);
|
|
604
|
+
const figures = [];
|
|
605
|
+
for (const asset of membersOf(brand, directive)) {
|
|
606
|
+
if (drawn.has(asset.id)) continue;
|
|
607
|
+
drawn.add(asset.id);
|
|
608
|
+
const { width, height } = asset;
|
|
609
|
+
figures.push({
|
|
610
|
+
title: assetTitle(asset),
|
|
611
|
+
file: asset.file,
|
|
612
|
+
format: asset.format,
|
|
613
|
+
width,
|
|
614
|
+
height,
|
|
615
|
+
background: backgroundOf(asset),
|
|
616
|
+
local: category?.local,
|
|
617
|
+
ratio: isNumber(width) && isNumber(height) && width > 0 && height > 0 ? width / height : 1
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
return figures;
|
|
621
|
+
}
|
|
622
|
+
/** Python's round(): halves go to the even neighbour */
|
|
623
|
+
function roundHalfEven(value) {
|
|
624
|
+
const floor = Math.floor(value);
|
|
625
|
+
if (value - floor === .5) return floor % 2 === 0 ? floor : floor + 1;
|
|
626
|
+
return Math.round(value);
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* What an asset slide's text draws: ([(role, x, y, text)], height). y is the baseline, downward from the top of the text. A list
|
|
630
|
+
* item is one op, role `bullet`, at the baseline of its first line, with its lines joined by a newline. The
|
|
631
|
+
* description, the traits (a list, or with `line` one line of them, wrapped, joined by dots), then Do and Don't, stacked or
|
|
632
|
+
* (columns 2) side by side when both are there.
|
|
633
|
+
*/
|
|
634
|
+
function guideOps(content, size, width, columns, wrap, line = false) {
|
|
635
|
+
const lead = size * GUIDE_LEAD;
|
|
636
|
+
const ops = [];
|
|
637
|
+
let y = 4;
|
|
638
|
+
const block = (items, x, top, room, label) => {
|
|
639
|
+
let at = top;
|
|
640
|
+
if (label) {
|
|
641
|
+
ops.push([
|
|
642
|
+
"label",
|
|
643
|
+
x,
|
|
644
|
+
at + 12,
|
|
645
|
+
label
|
|
646
|
+
]);
|
|
647
|
+
at += 18;
|
|
648
|
+
}
|
|
649
|
+
for (const item of items) {
|
|
650
|
+
const lines = wrap(item, size, room - 12);
|
|
651
|
+
ops.push([
|
|
652
|
+
"bullet",
|
|
653
|
+
x + 12,
|
|
654
|
+
at + size,
|
|
655
|
+
lines.join("\n")
|
|
656
|
+
]);
|
|
657
|
+
at += lines.length * lead + 3;
|
|
658
|
+
}
|
|
659
|
+
return at + 8;
|
|
660
|
+
};
|
|
661
|
+
if (content.description) {
|
|
662
|
+
const lines = wrap(content.description, size, width);
|
|
663
|
+
lines.forEach((text, n) => ops.push([
|
|
664
|
+
"text",
|
|
665
|
+
0,
|
|
666
|
+
y + size + n * lead,
|
|
667
|
+
text
|
|
668
|
+
]));
|
|
669
|
+
y += lines.length * lead + 8;
|
|
670
|
+
}
|
|
671
|
+
if (content.traits.length > 0 && line) {
|
|
672
|
+
const lines = wrap(content.traits.join(" · "), size, width);
|
|
673
|
+
lines.forEach((text, n) => ops.push([
|
|
674
|
+
"item",
|
|
675
|
+
0,
|
|
676
|
+
y + size + n * lead,
|
|
677
|
+
text
|
|
678
|
+
]));
|
|
679
|
+
y += lines.length * lead + 8;
|
|
680
|
+
} else if (content.traits.length > 0) y = block(content.traits, 0, y, width);
|
|
681
|
+
if (columns === 2 && content.do.length > 0 && content.dont.length > 0) {
|
|
682
|
+
const half = (width - 24) / 2;
|
|
683
|
+
y = Math.max(block(content.do, 0, y, half, "Do"), block(content.dont, half + 24, y, half, "Don't"));
|
|
684
|
+
} else for (const [label, key] of [["Do", "do"], ["Don't", "dont"]]) if (content[key].length > 0) y = block(content[key], 0, y, width, label);
|
|
685
|
+
return {
|
|
686
|
+
ops,
|
|
687
|
+
height: Math.max(y - 8, 0)
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
/** The lines of an asset slide's source at this width, and the height they take below the text: none when it has no source. */
|
|
691
|
+
function sourceRoom(slide, width, wrap) {
|
|
692
|
+
const lines = slide.source ? wrap(slide.source, 10, width) : [];
|
|
693
|
+
return {
|
|
694
|
+
lines,
|
|
695
|
+
height: lines.length * 13 + (lines.length > 0 ? 8 : 0)
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
/** (x, width) of the text beside a panel `panel` points wide, or across the slide when there is no panel. */
|
|
699
|
+
function guideGeometry(panel) {
|
|
700
|
+
if (panel === null) return {
|
|
701
|
+
x: 56,
|
|
702
|
+
width: PAGE.width - 112
|
|
703
|
+
};
|
|
704
|
+
const x = 56 + panel + 32;
|
|
705
|
+
return {
|
|
706
|
+
x,
|
|
707
|
+
width: PAGE.width - 56 - x
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* The (panel width, point size) an asset slide is tried at, best first: the largest size at each width from the widest panel
|
|
712
|
+
* down, then the next size. A panel narrower than its image needs is no narrower than the image (a tall image gives the text
|
|
713
|
+
* room by it), but the first is always the standard panel, so a slide that fits as it always did is drawn as it always was.
|
|
714
|
+
*/
|
|
715
|
+
function guideCandidates(slide) {
|
|
716
|
+
const hug = slide.width && slide.height ? Math.max(200, roundHalfEven(48 + 292 * slide.width / slide.height)) : void 0;
|
|
717
|
+
const candidates = [];
|
|
718
|
+
for (const size of GUIDE_SIZES) GUIDE_PANELS.forEach((panel, index) => {
|
|
719
|
+
const candidate = [index > 0 && hug !== void 0 ? Math.min(panel, hug) : panel, size];
|
|
720
|
+
if (!candidates.some(([p, s]) => p === candidate[0] && s === candidate[1])) candidates.push(candidate);
|
|
721
|
+
});
|
|
722
|
+
return candidates;
|
|
723
|
+
}
|
|
724
|
+
var contentOf = (slide) => ({
|
|
725
|
+
description: slide.description,
|
|
726
|
+
traits: slide.traits,
|
|
727
|
+
do: slide.do,
|
|
728
|
+
dont: slide.dont
|
|
729
|
+
});
|
|
730
|
+
var emptyContent = () => ({
|
|
731
|
+
description: null,
|
|
732
|
+
traits: [],
|
|
733
|
+
do: [],
|
|
734
|
+
dont: []
|
|
735
|
+
});
|
|
736
|
+
/** [placed, rest] of one paragraph in `room` points: all of it when it fits, else nothing when it can wait for a fresh slide (`whole`: it would fit one), else as many lines as fit, the rest to follow. */
|
|
737
|
+
function takeText(text, size, width, room, wrap, whole) {
|
|
738
|
+
const lines = wrap(text, size, width);
|
|
739
|
+
const lead = size * GUIDE_LEAD;
|
|
740
|
+
if (lines.length * lead <= room) return [text, null];
|
|
741
|
+
if (whole) return [null, text];
|
|
742
|
+
const count = Math.floor(room / lead);
|
|
743
|
+
return [lines.slice(0, Math.max(count, 0)).join(" ") || null, lines.slice(Math.max(count, 0)).join(" ")];
|
|
744
|
+
}
|
|
745
|
+
/** [placed, rest] of a list in `room` points. An item that does not fit waits for the next slide, with the ones after it; one taller than a whole slide (`pageRoom`) is split between its lines. */
|
|
746
|
+
function takeItems(items, size, width, room, wrap, pageRoom) {
|
|
747
|
+
const placed = [];
|
|
748
|
+
let used = 0;
|
|
749
|
+
for (let index = 0; index < items.length; index++) {
|
|
750
|
+
const item = items[index];
|
|
751
|
+
const height = wrap(item, size, width - 12).length * size * GUIDE_LEAD + 3;
|
|
752
|
+
if (used + height <= room) {
|
|
753
|
+
placed.push(item);
|
|
754
|
+
used += height;
|
|
755
|
+
continue;
|
|
756
|
+
}
|
|
757
|
+
const [first, rest] = takeText(item, size, width - 12, room - used - 3, wrap, height <= pageRoom);
|
|
758
|
+
if (first) placed.push(first);
|
|
759
|
+
return [placed, [...rest ? [rest] : [], ...items.slice(index + 1)]];
|
|
760
|
+
}
|
|
761
|
+
return [placed, []];
|
|
762
|
+
}
|
|
763
|
+
/**
|
|
764
|
+
* [placed, rest, traits as a list] of an asset slide's text on one slide with `room` points for it. The description first,
|
|
765
|
+
* the traits as one line, then Do and Don't side by side; what does not fit is `rest`, for the next slide. Do and Don't stay
|
|
766
|
+
* together: unless both fit here, they wait for a slide of their own (`fresh`), where each list is cut between its items if it
|
|
767
|
+
* must be. `pageRoom` is what a list has on a slide of its own.
|
|
768
|
+
*/
|
|
769
|
+
function fillPage(content, size, width, room, pageRoom, wrap, fresh) {
|
|
770
|
+
const placed = emptyContent();
|
|
771
|
+
const rest = emptyContent();
|
|
772
|
+
let asList = false;
|
|
773
|
+
if (content.description) [placed.description, rest.description] = takeText(content.description, size, width, room - 4, wrap, false);
|
|
774
|
+
if (content.traits.length > 0 && !rest.description) {
|
|
775
|
+
if (guideOps({
|
|
776
|
+
...placed,
|
|
777
|
+
traits: content.traits
|
|
778
|
+
}, size, width, 2, wrap, true).height + 4 <= room) placed.traits = content.traits;
|
|
779
|
+
else if (fresh && !placed.description) {
|
|
780
|
+
[placed.traits, rest.traits] = takeItems(content.traits, size, width, room - 4, wrap, pageRoom);
|
|
781
|
+
asList = true;
|
|
782
|
+
} else rest.traits = content.traits;
|
|
783
|
+
} else rest.traits = content.traits;
|
|
784
|
+
if (rest.description || rest.traits.length > 0) {
|
|
785
|
+
rest.do = content.do;
|
|
786
|
+
rest.dont = content.dont;
|
|
787
|
+
return [
|
|
788
|
+
placed,
|
|
789
|
+
rest,
|
|
790
|
+
asList
|
|
791
|
+
];
|
|
792
|
+
}
|
|
793
|
+
if (guideOps({
|
|
794
|
+
...placed,
|
|
795
|
+
do: content.do,
|
|
796
|
+
dont: content.dont
|
|
797
|
+
}, size, width, 2, wrap, !asList).height + 4 <= room) {
|
|
798
|
+
placed.do = content.do;
|
|
799
|
+
placed.dont = content.dont;
|
|
800
|
+
return [
|
|
801
|
+
placed,
|
|
802
|
+
rest,
|
|
803
|
+
asList
|
|
804
|
+
];
|
|
805
|
+
}
|
|
806
|
+
if (!fresh) {
|
|
807
|
+
rest.do = content.do;
|
|
808
|
+
rest.dont = content.dont;
|
|
809
|
+
return [
|
|
810
|
+
placed,
|
|
811
|
+
rest,
|
|
812
|
+
asList
|
|
813
|
+
];
|
|
814
|
+
}
|
|
815
|
+
const column = content.do.length > 0 && content.dont.length > 0 ? (width - 24) / 2 : width;
|
|
816
|
+
const left = room - guideOps(placed, size, width, 2, wrap, !asList).height - 8;
|
|
817
|
+
for (const key of ["do", "dont"]) if (content[key].length > 0) [placed[key], rest[key]] = takeItems(content[key], size, column, left - 18, wrap, pageRoom);
|
|
818
|
+
return [
|
|
819
|
+
placed,
|
|
820
|
+
rest,
|
|
821
|
+
asList
|
|
822
|
+
];
|
|
823
|
+
}
|
|
824
|
+
/**
|
|
825
|
+
* The slides of one asset: one when its text fits beside the image at a legible size, else the widest room the image can
|
|
826
|
+
* give and, for what still does not fit, slides titled "(continued)" with the text across the whole slide. No text is dropped.
|
|
827
|
+
*/
|
|
828
|
+
function fitted(slide, wrap) {
|
|
829
|
+
const candidates = guideCandidates(slide);
|
|
830
|
+
for (const [panel, size] of candidates) {
|
|
831
|
+
const { width } = guideGeometry(panel);
|
|
832
|
+
const room = 340 - sourceRoom(slide, width, wrap).height;
|
|
833
|
+
for (const [columns, line] of GUIDE_FORMS) {
|
|
834
|
+
if (columns === 2 && (width - 24) / 2 < 200) continue;
|
|
835
|
+
if (guideOps(contentOf(slide), size, width, columns, wrap, line).height + 4 <= room) return [{
|
|
836
|
+
...slide,
|
|
837
|
+
layout: {
|
|
838
|
+
panel,
|
|
839
|
+
size,
|
|
840
|
+
columns,
|
|
841
|
+
traits: line ? "line" : "list"
|
|
842
|
+
}
|
|
843
|
+
}];
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
const pageRoom = 340 - sourceRoom(slide, PAGE.width - 112, wrap).height - 8 - 18;
|
|
847
|
+
const slides = [];
|
|
848
|
+
let content = contentOf(slide);
|
|
849
|
+
const panel = Math.min(...candidates.filter(([, size]) => size === GUIDE_SIZES[0]).map(([p]) => p));
|
|
850
|
+
const size = GUIDE_SIZES[0];
|
|
851
|
+
for (;;) {
|
|
852
|
+
const first = slides.length === 0;
|
|
853
|
+
const here = first ? [panel, size] : [null, GUIDE_SIZES[0]];
|
|
854
|
+
const { width } = guideGeometry(here[0]);
|
|
855
|
+
const room = 340 - sourceRoom(slide, width, wrap).height;
|
|
856
|
+
const [placed, rest, asList] = fillPage(content, here[1], width, room, pageRoom, wrap, !first);
|
|
857
|
+
content = rest;
|
|
858
|
+
slides.push({
|
|
859
|
+
...slide,
|
|
860
|
+
...placed,
|
|
861
|
+
title: first ? slide.title : `${slide.title} (continued)`,
|
|
862
|
+
layout: {
|
|
863
|
+
panel: here[0],
|
|
864
|
+
size: here[1],
|
|
865
|
+
columns: 2,
|
|
866
|
+
traits: asList ? "list" : "line"
|
|
867
|
+
}
|
|
868
|
+
});
|
|
869
|
+
if (!(content.description || content.traits.length > 0 || content.do.length > 0 || content.dont.length > 0)) return slides;
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* The slides of one `blazon:section` directive: each listed asset with what its sidecar says. A category in `skip` draws nothing.
|
|
874
|
+
* With `wrap` (the deck's way of breaking text into lines) each slide is fitted: it has its layout, and an asset whose text does
|
|
875
|
+
* not fit one slide is followed by slides that continue it.
|
|
876
|
+
*/
|
|
877
|
+
function sectionDirectiveSlides(brand, directive, wrap, skip) {
|
|
878
|
+
const key = directive.args[0];
|
|
879
|
+
if (skip.includes(key)) return [];
|
|
880
|
+
const category = brand.categories.find((candidate) => candidate.category === key);
|
|
881
|
+
const slides = [];
|
|
882
|
+
for (const asset of membersOf(brand, directive)) {
|
|
883
|
+
const meta = asset.meta ?? {};
|
|
884
|
+
const slide = {
|
|
885
|
+
kind: "guideline",
|
|
886
|
+
title: assetTitle(asset),
|
|
887
|
+
file: asset.file,
|
|
888
|
+
format: asset.format,
|
|
889
|
+
width: asset.width,
|
|
890
|
+
height: asset.height,
|
|
891
|
+
background: backgroundOf(asset),
|
|
892
|
+
description: textOrNull(meta.description),
|
|
893
|
+
traits: listOf(meta.traits),
|
|
894
|
+
do: listOf(meta.do),
|
|
895
|
+
dont: listOf(meta.dont),
|
|
896
|
+
source: sourceLine(meta.source),
|
|
897
|
+
local: category?.local
|
|
898
|
+
};
|
|
899
|
+
slides.push(...wrap ? fitted(slide, wrap) : [slide]);
|
|
900
|
+
}
|
|
901
|
+
return slides;
|
|
902
|
+
}
|
|
903
|
+
/**
|
|
904
|
+
* The asset slides of a page, in the order of its directives: a slide for each asset of a `blazon:section`, and grid slides for
|
|
905
|
+
* the assets of a `blazon:assets`, which share a slide with the directives next to them under the same heading. An asset a section
|
|
906
|
+
* of the page draws is not drawn again in a grid of it (its slide says more), nor one an earlier grid of the page drew.
|
|
907
|
+
*/
|
|
908
|
+
function pageSlides(brand, page, wrap, skip) {
|
|
909
|
+
const drawn = new Set(page.directives.filter((directive) => directive.name === "section" && has(directive.args) && !skip.includes(directive.args[0])).flatMap((directive) => membersOf(brand, directive).map((asset) => asset.id)));
|
|
910
|
+
const headings = page.directives.some((directive) => directive.name === "assets") ? directiveHeadings(page) : [];
|
|
911
|
+
const slides = [];
|
|
912
|
+
let run = [];
|
|
913
|
+
let runTitle;
|
|
914
|
+
const flush = () => {
|
|
915
|
+
if (run.length > 0) slides.push(...gridSlides(runTitle, run));
|
|
916
|
+
run = [];
|
|
917
|
+
};
|
|
918
|
+
page.directives.forEach((directive, index) => {
|
|
919
|
+
if (!has(directive.args) || directive.name !== "section" && directive.name !== "assets") return;
|
|
920
|
+
if (directive.name === "section") {
|
|
921
|
+
flush();
|
|
922
|
+
slides.push(...sectionDirectiveSlides(brand, directive, wrap, skip));
|
|
923
|
+
return;
|
|
924
|
+
}
|
|
925
|
+
if (headings[index] !== runTitle) flush();
|
|
926
|
+
runTitle = headings[index];
|
|
927
|
+
run.push(...gridFigures(brand, directive, skip, drawn));
|
|
928
|
+
});
|
|
929
|
+
flush();
|
|
930
|
+
return slides;
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* What the guidelines leave open in each category the page's `blazon:section` directives name, once for each, in the order
|
|
934
|
+
* the page first names them. It is a fact about the category, whatever assets the directive lists. A category in `skip` leaves
|
|
935
|
+
* nothing open here: it is not in the deck.
|
|
936
|
+
*/
|
|
937
|
+
function openLists(brand, page, skip) {
|
|
938
|
+
const lists = [];
|
|
939
|
+
const seen = /* @__PURE__ */ new Set();
|
|
940
|
+
for (const directive of page.directives) {
|
|
941
|
+
const key = directive.name === "section" && has(directive.args) ? directive.args[0] : void 0;
|
|
942
|
+
const category = brand.categories.find((candidate) => candidate.category === key);
|
|
943
|
+
if (key !== void 0 && category && has(category.notSpecified) && !seen.has(key) && !skip.includes(key)) {
|
|
944
|
+
seen.add(key);
|
|
945
|
+
lists.push({
|
|
946
|
+
title: category.label || humanize(key),
|
|
947
|
+
items: category.notSpecified,
|
|
948
|
+
source: sourceLine(category.source)
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
return lists;
|
|
953
|
+
}
|
|
954
|
+
/** The size a type sample is drawn at: half its pixel size, so large enough to read and no larger than a slide allows. */
|
|
955
|
+
function samplePt(sizePx) {
|
|
956
|
+
return Math.min(Math.max((sizePx || 16) * PX_TO_PT, 14), 54);
|
|
957
|
+
}
|
|
958
|
+
function sampleRowHeight(sizePx) {
|
|
959
|
+
return samplePt(sizePx) * 1.3 + 22;
|
|
960
|
+
}
|
|
961
|
+
/**
|
|
962
|
+
* The styles split over as few slides as their rows' heights need, and over those slides as evenly as the heights allow: the smallest
|
|
963
|
+
* height a slide may fill that still needs no more slides than filling each to the brim would. Order is kept.
|
|
964
|
+
*/
|
|
965
|
+
function packedByHeight(styles) {
|
|
966
|
+
const room = PAGE.height - 130 - 70;
|
|
967
|
+
const heights = styles.map((style) => sampleRowHeight(style.size_px));
|
|
968
|
+
const pack = (limit) => {
|
|
969
|
+
const chunks = [];
|
|
970
|
+
let used = limit;
|
|
971
|
+
styles.forEach((style, index) => {
|
|
972
|
+
if (used + heights[index] > limit) {
|
|
973
|
+
chunks.push([]);
|
|
974
|
+
used = 0;
|
|
975
|
+
}
|
|
976
|
+
chunks.at(-1).push(style);
|
|
977
|
+
used += heights[index];
|
|
978
|
+
});
|
|
979
|
+
return chunks;
|
|
980
|
+
};
|
|
981
|
+
const slides = pack(room).length;
|
|
982
|
+
let low = Math.max(0, ...heights);
|
|
983
|
+
let high = room;
|
|
984
|
+
for (let round = 0; round < 40; round++) {
|
|
985
|
+
const middle = (low + high) / 2;
|
|
986
|
+
if (pack(middle).length <= slides) high = middle;
|
|
987
|
+
else low = middle;
|
|
988
|
+
}
|
|
989
|
+
return pack(high);
|
|
990
|
+
}
|
|
991
|
+
/** What is said under a family's name, a paragraph each, in the order the slide draws them. */
|
|
992
|
+
var familyText = (family) => [
|
|
993
|
+
family.stack,
|
|
994
|
+
family.description,
|
|
995
|
+
family.web_font
|
|
996
|
+
].filter((text) => Boolean(text));
|
|
997
|
+
/**
|
|
998
|
+
* (from this family's name to the next one's, from its name to the baseline of its last line) in points, as the slide draws it: each
|
|
999
|
+
* paragraph under the name is at most two lines. Without `wrap` a letter is half the size wide, as an unmeasured width is.
|
|
1000
|
+
*/
|
|
1001
|
+
function familyDrop(family, wrap) {
|
|
1002
|
+
const lines = familyText(family).map((text) => Math.min(2, wrap ? wrap(text, 11, 800).length : Math.ceil([...text].length * 11 * .5 / 800)));
|
|
1003
|
+
const below = 22 + lines.reduce((sum, count) => sum + count * FONTS_LEAD, 0) + 2 * Math.max(lines.length - 1, 0);
|
|
1004
|
+
return [below + 34, below - FONTS_LEAD];
|
|
1005
|
+
}
|
|
1006
|
+
/** The families over as few slides as keep each family's last line above the note under them, and that note above BODY_BOTTOM. Order is kept; a family is never split, and when the slides can share the families evenly, they do (never three and a lone one). */
|
|
1007
|
+
function packedFamilies(families, wrap) {
|
|
1008
|
+
const floor = 96;
|
|
1009
|
+
const fits = (chunk) => {
|
|
1010
|
+
let top = 380;
|
|
1011
|
+
for (const [index, family] of chunk.entries()) {
|
|
1012
|
+
const [drop, last] = familyDrop(family, wrap);
|
|
1013
|
+
if (top - last < floor) return false;
|
|
1014
|
+
if (index < chunk.length - 1) top -= drop;
|
|
1015
|
+
}
|
|
1016
|
+
return true;
|
|
1017
|
+
};
|
|
1018
|
+
const chunks = [];
|
|
1019
|
+
for (const family of families) {
|
|
1020
|
+
const here = chunks.at(-1);
|
|
1021
|
+
if (here && fits([...here, family])) here.push(family);
|
|
1022
|
+
else chunks.push([family]);
|
|
1023
|
+
}
|
|
1024
|
+
const even = chunks.length > 1 ? balanced(families, Math.ceil(families.length / chunks.length)) : [];
|
|
1025
|
+
return even.length === chunks.length && even.every(fits) ? even : chunks;
|
|
1026
|
+
}
|
|
1027
|
+
/** A font size in px: a px dimension, or a rem as 16px. undefined for any other unit. */
|
|
1028
|
+
function sizePx(dimension) {
|
|
1029
|
+
if (!isObject(dimension) || !isNumber(dimension.value)) return void 0;
|
|
1030
|
+
if (dimension.unit === "px") return dimension.value;
|
|
1031
|
+
if (dimension.unit === "rem") return dimension.value * 16;
|
|
1032
|
+
}
|
|
1033
|
+
var firstFamily = (family) => Array.isArray(family) && family.length > 0 ? String(family[0]) : typeof family === "string" ? family : null;
|
|
1034
|
+
function typographySlides(brand, wrap) {
|
|
1035
|
+
const slides = [];
|
|
1036
|
+
const families = [];
|
|
1037
|
+
for (const token of brand.tokens) {
|
|
1038
|
+
if (token.type !== "fontFamily" || has(token.aliasOf)) continue;
|
|
1039
|
+
const resolved = token.resolvedValue;
|
|
1040
|
+
const family = {
|
|
1041
|
+
name: Array.isArray(resolved) ? String(resolved[0]) : String(resolved).split(",")[0].replace(/^["'\s]+|["'\s]+$/g, ""),
|
|
1042
|
+
path: token.path,
|
|
1043
|
+
stack: String(token.value),
|
|
1044
|
+
description: token.description ?? null
|
|
1045
|
+
};
|
|
1046
|
+
const webFont = token.blazon?.webFont;
|
|
1047
|
+
if (webFont !== void 0 && webFont !== null) family.web_font = typeof webFont === "string" ? webFont : "Not loadable on the web";
|
|
1048
|
+
families.push(family);
|
|
1049
|
+
}
|
|
1050
|
+
for (const [title, chunk] of titled("Typefaces", packedFamilies(families, wrap))) slides.push({
|
|
1051
|
+
kind: "fonts",
|
|
1052
|
+
title,
|
|
1053
|
+
families: chunk
|
|
1054
|
+
});
|
|
1055
|
+
const styles = [];
|
|
1056
|
+
for (const token of brand.tokens) {
|
|
1057
|
+
if (token.type !== "typography" || has(token.aliasOf) || !isObject(token.resolvedValue)) continue;
|
|
1058
|
+
const parts = token.resolvedValue;
|
|
1059
|
+
const spacing = parts.letterSpacing;
|
|
1060
|
+
const px = sizePx(parts.fontSize);
|
|
1061
|
+
const segments = token.path.split(".").slice(1);
|
|
1062
|
+
const names = segments.length > 0 ? segments : token.path.split(".");
|
|
1063
|
+
styles.push({
|
|
1064
|
+
name: humanize(names.join("-")),
|
|
1065
|
+
path: token.path,
|
|
1066
|
+
family: firstFamily(parts.fontFamily),
|
|
1067
|
+
size_px: px !== void 0 ? number(px) : null,
|
|
1068
|
+
weight: parts.fontWeight ?? null,
|
|
1069
|
+
line_height: parts.lineHeight ?? null,
|
|
1070
|
+
letter_spacing: isObject(spacing) && isNumber(spacing.value) ? `${number(spacing.value)}${String(spacing.unit)}` : null
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
for (const [title, chunk] of titled("Type scale", packedByHeight(styles))) slides.push({
|
|
1074
|
+
kind: "type-scale",
|
|
1075
|
+
title,
|
|
1076
|
+
styles: chunk
|
|
1077
|
+
});
|
|
1078
|
+
return slides;
|
|
1079
|
+
}
|
|
1080
|
+
function coverSlide(brand) {
|
|
1081
|
+
const logo = brand.logo;
|
|
1082
|
+
const chosen = logo.onLight ? {
|
|
1083
|
+
file: logo.onLight,
|
|
1084
|
+
background: "light"
|
|
1085
|
+
} : logo.onDark ? {
|
|
1086
|
+
file: logo.onDark,
|
|
1087
|
+
background: "dark"
|
|
1088
|
+
} : null;
|
|
1089
|
+
return {
|
|
1090
|
+
kind: "cover",
|
|
1091
|
+
title: brand.brand.title,
|
|
1092
|
+
subtitle: brand.brand.description ?? null,
|
|
1093
|
+
logo: chosen
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
/**
|
|
1097
|
+
* The slides of the deck, as data. Page numbers in the contents are 1-based. `wrap` is the deck's way of breaking text into
|
|
1098
|
+
* lines: with it an asset's text is fitted to its slide, and a long one continues on further slides, so the contents can number
|
|
1099
|
+
* them. `skip` names asset categories to leave out; an experimental or reference category (brand.json `categories[].experimental` and
|
|
1100
|
+
* `categories[].reference`) is always left out, because the deck presents the identity and neither an exploration nor material kept for comparison is it.
|
|
1101
|
+
*
|
|
1102
|
+
* The deck follows the brand book. Each page is a part: a divider, the token slides of the sections the page is for (the
|
|
1103
|
+
* first page of a section takes them), then the assets its `blazon:section` directives list (a slide each) and its `blazon:assets`
|
|
1104
|
+
* directives (grids). Token slides no page takes come last, in parts of their own, so a brand with no pages is a deck of Logo,
|
|
1105
|
+
* Colors and Typography.
|
|
1106
|
+
*/
|
|
1107
|
+
function plan(brand, favicons = null, wrap, skipped = []) {
|
|
1108
|
+
const skip = [...skipped, ...brand.categories.filter((category) => category.experimental === true || category.reference === true).map((category) => category.category)];
|
|
1109
|
+
const tokenSlides = {
|
|
1110
|
+
logo: ["Logo", logoSlides(brand, skip)],
|
|
1111
|
+
color: ["Colors", [...paletteSlides(brand), ...gradientSlides(brand)]],
|
|
1112
|
+
typography: ["Typography", typographySlides(brand, wrap)]
|
|
1113
|
+
};
|
|
1114
|
+
const parts = [];
|
|
1115
|
+
const taken = /* @__PURE__ */ new Set();
|
|
1116
|
+
for (const page of [...brand.pages].sort((a, b) => a.order - b.order)) {
|
|
1117
|
+
const slides = [{
|
|
1118
|
+
kind: "page",
|
|
1119
|
+
title: page.title,
|
|
1120
|
+
description: textOrNull(page.meta?.description),
|
|
1121
|
+
open: openLists(brand, page, skip)
|
|
1122
|
+
}];
|
|
1123
|
+
for (const sectionId of page.sections) if (Object.hasOwn(tokenSlides, sectionId) && !taken.has(sectionId)) {
|
|
1124
|
+
taken.add(sectionId);
|
|
1125
|
+
slides.push(...tokenSlides[sectionId][1]);
|
|
1126
|
+
}
|
|
1127
|
+
parts.push([page.title, [...slides, ...pageSlides(brand, page, wrap, skip)]]);
|
|
1128
|
+
}
|
|
1129
|
+
for (const [sectionId, [title, slides]] of Object.entries(tokenSlides)) if (!taken.has(sectionId) && slides.length > 0) parts.push([title, slides]);
|
|
1130
|
+
const favicon = favicons ? faviconSlides(favicons) : [];
|
|
1131
|
+
if (favicon.length > 0) parts.push(["Favicons", favicon]);
|
|
1132
|
+
const items = [];
|
|
1133
|
+
let at = 3;
|
|
1134
|
+
for (const [title, slides] of parts) {
|
|
1135
|
+
items.push({
|
|
1136
|
+
title,
|
|
1137
|
+
page: at
|
|
1138
|
+
});
|
|
1139
|
+
at += slides.length;
|
|
1140
|
+
}
|
|
1141
|
+
return [
|
|
1142
|
+
coverSlide(brand),
|
|
1143
|
+
{
|
|
1144
|
+
kind: "contents",
|
|
1145
|
+
title: "Contents",
|
|
1146
|
+
items
|
|
1147
|
+
},
|
|
1148
|
+
...parts.flatMap(([, slides]) => slides)
|
|
1149
|
+
];
|
|
1150
|
+
}
|
|
1151
|
+
/** The asset categories a deck can leave out: the ones the brand has assets or a description for. */
|
|
1152
|
+
function skippable(brand) {
|
|
1153
|
+
return unique([...brand.assets.map((asset) => asset.category), ...brand.categories.map((category) => category.category)]).sort();
|
|
1154
|
+
}
|
|
1155
|
+
/** The names in `skip` that are no asset category of this brand, in the order given, once each. */
|
|
1156
|
+
function unknownSkips(brand, skip) {
|
|
1157
|
+
const known = new Set(skippable(brand));
|
|
1158
|
+
return unique(skip.filter((name) => !known.has(name)));
|
|
1159
|
+
}
|
|
1160
|
+
var finding = findingFor(NAME);
|
|
1161
|
+
var warn = (code, path, message) => finding(code, "warning", path, message);
|
|
1162
|
+
/**
|
|
1163
|
+
* The asset categories to leave out, and the findings about the options. The plugin's only option is `skip`, a list of category
|
|
1164
|
+
* names. An option that is wrong is a warning and is left out, and the deck is drawn: a typo must not cost the whole book.
|
|
1165
|
+
*/
|
|
1166
|
+
function readOptions(options, brand) {
|
|
1167
|
+
const findings = [];
|
|
1168
|
+
if (!isObject(options)) {
|
|
1169
|
+
findings.push(warn("option-invalid", "options", "options must be an object; the deck is drawn with none"));
|
|
1170
|
+
return {
|
|
1171
|
+
skip: [],
|
|
1172
|
+
findings
|
|
1173
|
+
};
|
|
1174
|
+
}
|
|
1175
|
+
for (const key of Object.keys(options)) if (key !== "skip") findings.push(warn("option-unknown", `options.${key}`, `unknown option "${key}"; the deck reads only "skip"`));
|
|
1176
|
+
const names = options.skip ?? [];
|
|
1177
|
+
if (!Array.isArray(names) || names.some((name) => typeof name !== "string")) {
|
|
1178
|
+
if ("skip" in options) findings.push(warn("option-invalid", "options.skip", "skip must be a list of asset category names, such as [\"favicons-supplied\"]; nothing is left out"));
|
|
1179
|
+
return {
|
|
1180
|
+
skip: [],
|
|
1181
|
+
findings
|
|
1182
|
+
};
|
|
1183
|
+
}
|
|
1184
|
+
const unknown = unknownSkips(brand, names);
|
|
1185
|
+
for (const name of unknown) findings.push(warn("skip-unknown", "options.skip", `"${name}" is no asset category of this brand, so nothing is left out for it (the categories are ${skippable(brand).join(", ") || "none"})`));
|
|
1186
|
+
return {
|
|
1187
|
+
skip: [...new Set(names)].filter((name) => !unknown.includes(name)),
|
|
1188
|
+
findings
|
|
1189
|
+
};
|
|
1190
|
+
}
|
|
1191
|
+
/** A file the deck needs cannot be read; the message names it. */
|
|
1192
|
+
var DeckError = class extends Error {};
|
|
1193
|
+
/**
|
|
1194
|
+
* Throws a DeckError for a favicons.json whose parts are not the shapes the slides read, so a hand-edited or damaged file is an
|
|
1195
|
+
* error naming it and not a failure from the middle of the drawing. A part a file lacks is not an error (an older file); a part
|
|
1196
|
+
* that is there must be right.
|
|
1197
|
+
*/
|
|
1198
|
+
function checkShape(file, data) {
|
|
1199
|
+
const fail = (message) => {
|
|
1200
|
+
throw new DeckError(`${file} ${message}`);
|
|
1201
|
+
};
|
|
1202
|
+
const views = data.views ?? [];
|
|
1203
|
+
if (!Array.isArray(views)) fail("has views that are not a list");
|
|
1204
|
+
views.forEach((view, index) => {
|
|
1205
|
+
const where = `view ${index + 1}`;
|
|
1206
|
+
if (!isObject(view)) return fail(`has a ${where} that is not an object`);
|
|
1207
|
+
for (const key of [
|
|
1208
|
+
"id",
|
|
1209
|
+
"title",
|
|
1210
|
+
"file"
|
|
1211
|
+
]) if (typeof view[key] !== "string" || view[key] === "") fail(`has a ${where} with no ${key}`);
|
|
1212
|
+
const name = view.file;
|
|
1213
|
+
if (name === "." || name === ".." || node_path.default.basename(name) !== name || name.includes("\\") || node_path.default.posix.basename(name) !== name) fail("names a file outside its own folder");
|
|
1214
|
+
for (const key of ["width", "height"]) if (!isNumber(view[key]) || view[key] <= 0) fail(`has a ${where} with no ${key} (a number above 0)`);
|
|
1215
|
+
});
|
|
1216
|
+
const files = data.files ?? [];
|
|
1217
|
+
if (!Array.isArray(files) || files.some((row) => !isObject(row) || [
|
|
1218
|
+
"file",
|
|
1219
|
+
"size",
|
|
1220
|
+
"use"
|
|
1221
|
+
].some((key) => typeof row[key] !== "string"))) fail("has files that are not a list of {file, size, use}");
|
|
1222
|
+
if ("head" in data && typeof data.head !== "string") fail("has a head that is not text");
|
|
1223
|
+
if ("colors" in data && !isObject(data.colors)) fail("has colors that are not an object");
|
|
1224
|
+
const adaptive = data.adaptive;
|
|
1225
|
+
if (adaptive !== void 0 && adaptive !== null && (!isObject(adaptive) || !isNumber(adaptive.symbolReach) || !isNumber(adaptive.safeRadius))) fail("has an adaptive part without a symbolReach and a safeRadius (numbers)");
|
|
1226
|
+
}
|
|
1227
|
+
/**
|
|
1228
|
+
* favicons.json in the plugin's folder with `folder` added, or null when there is none (no plugin ran, or it did not finish).
|
|
1229
|
+
* A file that is there but cannot be used is a DeckError, and one that is not about this brand's symbol is said through `warn`.
|
|
1230
|
+
*/
|
|
1231
|
+
function readFavicons(folder, brand, warn = () => {}) {
|
|
1232
|
+
const file = node_path.default.join(folder, "favicons.json");
|
|
1233
|
+
if (!node_fs.default.statSync(file, { throwIfNoEntry: false })?.isFile()) return null;
|
|
1234
|
+
let data;
|
|
1235
|
+
try {
|
|
1236
|
+
data = JSON.parse(node_fs.default.readFileSync(file, "utf-8"));
|
|
1237
|
+
} catch (error) {
|
|
1238
|
+
throw new DeckError(`cannot read ${file}: ${error.message}`);
|
|
1239
|
+
}
|
|
1240
|
+
if (!isObject(data) || data.format !== "blazon-favicons" || data.version !== 1) throw new DeckError(`${file} is not a favicons.json this deck reads (format blazon-favicons, version 1)`);
|
|
1241
|
+
checkShape(file, data);
|
|
1242
|
+
if (typeof data.symbol !== "string" || !brand.assets.some((asset) => asset.id === data.symbol)) {
|
|
1243
|
+
warn(`favicons not drawn: ${file} is for the symbol ${String(data.symbol)}, which this brand does not have`);
|
|
1244
|
+
return null;
|
|
1245
|
+
}
|
|
1246
|
+
return {
|
|
1247
|
+
...data,
|
|
1248
|
+
folder
|
|
1249
|
+
};
|
|
1250
|
+
}
|
|
1251
|
+
var FONT_FILES = [
|
|
1252
|
+
".ttf",
|
|
1253
|
+
".otf",
|
|
1254
|
+
".ttc"
|
|
1255
|
+
];
|
|
1256
|
+
var SFNT_MAGIC = [
|
|
1257
|
+
"\0\0\0",
|
|
1258
|
+
"true",
|
|
1259
|
+
"OTTO"
|
|
1260
|
+
];
|
|
1261
|
+
var WEIGHT_WORDS = {
|
|
1262
|
+
normal: 400,
|
|
1263
|
+
regular: 400,
|
|
1264
|
+
bold: 700,
|
|
1265
|
+
bolder: 700,
|
|
1266
|
+
lighter: 300
|
|
1267
|
+
};
|
|
1268
|
+
/** A family name as a key: "Space Grotesk", "space grotesk" and "SpaceGrotesk" are one family. */
|
|
1269
|
+
var familyKey = (name) => String(name).toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
1270
|
+
/** The folders named in an environment variable, separated as a PATH is. */
|
|
1271
|
+
var fontFolders = (value) => (value ?? "").split(node_path.default.delimiter).filter((folder) => folder !== "");
|
|
1272
|
+
/** A CSS font weight as a number: 600, "600", "bold"; anything else is a regular. */
|
|
1273
|
+
function weightOf(value) {
|
|
1274
|
+
if (typeof value === "number") return Math.trunc(value);
|
|
1275
|
+
const text = String(value ?? "").trim().toLowerCase();
|
|
1276
|
+
return /^\d+$/.test(text) ? Number(text) : WEIGHT_WORDS[text] ?? 400;
|
|
1277
|
+
}
|
|
1278
|
+
/** What the deck needs to know of a font file: its family, style and weight, or why the file cannot be used. */
|
|
1279
|
+
function readFont(data) {
|
|
1280
|
+
const notFont = { why: "not a font file" };
|
|
1281
|
+
const magic = data.subarray(0, 4).toString("latin1");
|
|
1282
|
+
if (magic === "ttcf") return { why: "a font collection, which holds several fonts in one file" };
|
|
1283
|
+
if (data.length < 12 || !SFNT_MAGIC.includes(magic)) return notFont;
|
|
1284
|
+
try {
|
|
1285
|
+
const count = data.readUInt16BE(4);
|
|
1286
|
+
const tables = /* @__PURE__ */ new Map();
|
|
1287
|
+
for (let index = 0; index < count; index++) {
|
|
1288
|
+
const at = 12 + 16 * index;
|
|
1289
|
+
const tag = data.subarray(at, at + 4).toString("latin1");
|
|
1290
|
+
const offset = data.readUInt32BE(at + 8);
|
|
1291
|
+
const length = data.readUInt32BE(at + 12);
|
|
1292
|
+
tables.set(tag, data.subarray(offset, offset + length));
|
|
1293
|
+
}
|
|
1294
|
+
const nameTable = tables.get("name");
|
|
1295
|
+
const os2 = tables.get("OS/2");
|
|
1296
|
+
if (!nameTable || !os2) return notFont;
|
|
1297
|
+
if (tables.has("fvar")) return { why: "a variable font, whose axes the deck cannot set: give static files" };
|
|
1298
|
+
const names = /* @__PURE__ */ new Map();
|
|
1299
|
+
const records = nameTable.readUInt16BE(2);
|
|
1300
|
+
const strings = nameTable.readUInt16BE(4);
|
|
1301
|
+
for (let index = 0; index < records; index++) {
|
|
1302
|
+
const at = 6 + 12 * index;
|
|
1303
|
+
const platform = nameTable.readUInt16BE(at);
|
|
1304
|
+
const nameId = nameTable.readUInt16BE(at + 6);
|
|
1305
|
+
const length = nameTable.readUInt16BE(at + 8);
|
|
1306
|
+
const offset = nameTable.readUInt16BE(at + 10);
|
|
1307
|
+
const raw = nameTable.subarray(strings + offset, strings + offset + length);
|
|
1308
|
+
const text = platform === 0 || platform === 3 ? Buffer.from(raw).swap16().toString("utf16le") : raw.toString("latin1");
|
|
1309
|
+
if (!names.has(nameId) || platform === 3) names.set(nameId, text);
|
|
1310
|
+
}
|
|
1311
|
+
const weight = os2.readUInt16BE(4);
|
|
1312
|
+
const fsType = os2.readUInt16BE(8);
|
|
1313
|
+
const fsSelection = os2.readUInt16BE(62);
|
|
1314
|
+
const family = (names.get(16) || names.get(1) || "").trim();
|
|
1315
|
+
const style = names.get(17) || names.get(2) || "Regular";
|
|
1316
|
+
if (!family) return notFont;
|
|
1317
|
+
if (fsType & 2) return { why: "its license forbids embedding" };
|
|
1318
|
+
if (fsType & 256) return { why: "its license forbids subsetting, which embedding needs" };
|
|
1319
|
+
if (fsSelection & 1 || /italic|oblique/i.test(style)) return { why: "an italic face: the deck sets upright text" };
|
|
1320
|
+
return { font: {
|
|
1321
|
+
family,
|
|
1322
|
+
style,
|
|
1323
|
+
weight: weight || WEIGHT_WORDS[style.toLowerCase()] || 400
|
|
1324
|
+
} };
|
|
1325
|
+
} catch {
|
|
1326
|
+
return notFont;
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
/**
|
|
1330
|
+
* The brand's own fonts, found in folders and in the config by what each font says it is (its family and weight), not by its file
|
|
1331
|
+
* name. Files that cannot be used are listed with the reason, and the deck sets that text in Helvetica.
|
|
1332
|
+
*/
|
|
1333
|
+
var FontTable = class FontTable {
|
|
1334
|
+
names = /* @__PURE__ */ new Map();
|
|
1335
|
+
entries = /* @__PURE__ */ new Map();
|
|
1336
|
+
used = /* @__PURE__ */ new Map();
|
|
1337
|
+
skipped = [];
|
|
1338
|
+
static scan(folders) {
|
|
1339
|
+
const table = new FontTable();
|
|
1340
|
+
const files = [];
|
|
1341
|
+
for (const folder of folders) {
|
|
1342
|
+
if (!node_fs.default.statSync(folder, { throwIfNoEntry: false })?.isDirectory()) throw new DeckError(`font folder ${folder} does not exist`);
|
|
1343
|
+
const walk = (dir) => {
|
|
1344
|
+
for (const item of node_fs.default.readdirSync(dir, { withFileTypes: true })) {
|
|
1345
|
+
const full = node_path.default.join(dir, item.name);
|
|
1346
|
+
if (item.isDirectory()) walk(full);
|
|
1347
|
+
else if (item.isFile() && FONT_FILES.includes(node_path.default.extname(item.name).toLowerCase())) files.push(full);
|
|
1348
|
+
}
|
|
1349
|
+
};
|
|
1350
|
+
walk(folder);
|
|
1351
|
+
}
|
|
1352
|
+
for (const file of files.sort()) {
|
|
1353
|
+
let data;
|
|
1354
|
+
try {
|
|
1355
|
+
data = node_fs.default.readFileSync(file);
|
|
1356
|
+
} catch (error) {
|
|
1357
|
+
table.skipped.push([file, error.message]);
|
|
1358
|
+
continue;
|
|
1359
|
+
}
|
|
1360
|
+
table.add(readFont(data), file, node_path.default.extname(file).toLowerCase() === ".otf" ? "font/otf" : "font/ttf", () => data);
|
|
1361
|
+
}
|
|
1362
|
+
return table;
|
|
1363
|
+
}
|
|
1364
|
+
add(read, label, mime, bytes) {
|
|
1365
|
+
if ("why" in read) {
|
|
1366
|
+
this.skipped.push([label, read.why]);
|
|
1367
|
+
return;
|
|
1368
|
+
}
|
|
1369
|
+
const { font } = read;
|
|
1370
|
+
const key = familyKey(font.family);
|
|
1371
|
+
const known = this.entries.get(key) ?? /* @__PURE__ */ new Map();
|
|
1372
|
+
this.entries.set(key, known);
|
|
1373
|
+
const same = known.get(font.weight);
|
|
1374
|
+
if (same) {
|
|
1375
|
+
this.skipped.push([label, `a duplicate of ${same.label}`]);
|
|
1376
|
+
return;
|
|
1377
|
+
}
|
|
1378
|
+
known.set(font.weight, {
|
|
1379
|
+
family: font.family,
|
|
1380
|
+
label,
|
|
1381
|
+
mime,
|
|
1382
|
+
bytes
|
|
1383
|
+
});
|
|
1384
|
+
if (!this.names.has(key)) this.names.set(key, font.family);
|
|
1385
|
+
}
|
|
1386
|
+
/**
|
|
1387
|
+
* The fonts a project's `fonts` config embeds in brand.json: `data:text/css;base64,` stylesheets with one @font-face each. A TrueType or
|
|
1388
|
+
* OpenType font is known by what the file says, as a font in a folder is; a .woff or .woff2 cannot be read here, so it is known by
|
|
1389
|
+
* the family and weight the config declared. A stylesheet that is a web address is never fetched.
|
|
1390
|
+
*/
|
|
1391
|
+
addSheets(sheets) {
|
|
1392
|
+
for (const sheet of sheets) {
|
|
1393
|
+
if (typeof sheet !== "string" || !sheet.startsWith("data:text/css;base64,")) continue;
|
|
1394
|
+
const css = Buffer.from(sheet.slice(21), "base64").toString("utf-8");
|
|
1395
|
+
for (const block of css.matchAll(/@font-face\s*\{([^}]*)\}/g)) {
|
|
1396
|
+
const rule = block[1];
|
|
1397
|
+
const family = /font-family:\s*"([^"]*)"/.exec(rule)?.[1];
|
|
1398
|
+
const source = /url\(data:font\/([a-z0-9]+);base64,([A-Za-z0-9+/=]*)\)/.exec(rule);
|
|
1399
|
+
if (!family || !source) continue;
|
|
1400
|
+
const [, kind, base64] = source;
|
|
1401
|
+
const data = Buffer.from(base64, "base64");
|
|
1402
|
+
const label = `${family} from the config`;
|
|
1403
|
+
if (kind === "ttf" || kind === "otf") this.add(readFont(data), label, `font/${kind}`, () => data);
|
|
1404
|
+
else if (kind === "woff" || kind === "woff2") {
|
|
1405
|
+
const declared = /font-weight:\s*([^;]+)/.exec(rule)?.[1];
|
|
1406
|
+
const italic = /font-style:\s*(italic|oblique)/.test(rule);
|
|
1407
|
+
this.add(italic ? { why: "an italic face: the deck sets upright text" } : { font: {
|
|
1408
|
+
family,
|
|
1409
|
+
style: "Regular",
|
|
1410
|
+
weight: weightOf(declared?.trim().split(/\s+/)[0])
|
|
1411
|
+
} }, label, `font/${kind}`, () => data);
|
|
1412
|
+
} else this.skipped.push([label, `a .${kind} file, which the deck cannot use: give a .ttf, .otf, .woff or .woff2 file`]);
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
families() {
|
|
1417
|
+
return [...this.names.values()];
|
|
1418
|
+
}
|
|
1419
|
+
has(family) {
|
|
1420
|
+
return this.entries.has(familyKey(family));
|
|
1421
|
+
}
|
|
1422
|
+
weights(family) {
|
|
1423
|
+
return [...this.entries.get(familyKey(family))?.keys() ?? []].sort((a, b) => a - b);
|
|
1424
|
+
}
|
|
1425
|
+
/** The weight of this family that is nearest `weight`; a tie goes to the heavier. undefined if the family has no file. */
|
|
1426
|
+
nearest(family, weight) {
|
|
1427
|
+
const available = this.weights(family);
|
|
1428
|
+
const wanted = weightOf(weight);
|
|
1429
|
+
let best;
|
|
1430
|
+
for (const have of available) if (best === void 0 || Math.abs(have - wanted) < Math.abs(best - wanted) || Math.abs(have - wanted) === Math.abs(best - wanted) && have > best) best = have;
|
|
1431
|
+
return best;
|
|
1432
|
+
}
|
|
1433
|
+
/** The face to set text in: this family at the nearest weight, or undefined. */
|
|
1434
|
+
face(family, weight) {
|
|
1435
|
+
const have = this.nearest(family, weight);
|
|
1436
|
+
if (have === void 0) return void 0;
|
|
1437
|
+
const id = `${familyKey(family)}-${have}`;
|
|
1438
|
+
if (!this.used.has(id)) this.used.set(id, {
|
|
1439
|
+
css: `brand-${id}`,
|
|
1440
|
+
weight: have,
|
|
1441
|
+
id,
|
|
1442
|
+
entry: this.entries.get(familyKey(family)).get(have)
|
|
1443
|
+
});
|
|
1444
|
+
const { css, weight: w } = this.used.get(id);
|
|
1445
|
+
return {
|
|
1446
|
+
css,
|
|
1447
|
+
weight: w,
|
|
1448
|
+
id
|
|
1449
|
+
};
|
|
1450
|
+
}
|
|
1451
|
+
/** The @font-face rules of the faces the deck used, naming each by `url(<base>/<id>)` */
|
|
1452
|
+
rules(base) {
|
|
1453
|
+
return [...this.used.values()].map((face) => `@font-face{font-family:"${face.css}";font-weight:${face.weight};src:url(${base}/${face.id})}`).join("\n");
|
|
1454
|
+
}
|
|
1455
|
+
/** The bytes and media type of a face the deck used */
|
|
1456
|
+
file(id) {
|
|
1457
|
+
const face = this.used.get(id);
|
|
1458
|
+
return face && {
|
|
1459
|
+
mime: face.entry.mime,
|
|
1460
|
+
bytes: face.entry.bytes()
|
|
1461
|
+
};
|
|
1462
|
+
}
|
|
1463
|
+
/** The footnote that says which of the brand's families are set in their own fonts and which are not. */
|
|
1464
|
+
note(families) {
|
|
1465
|
+
if (this.entries.size === 0) return "Shown in Helvetica: the typeface itself is not embedded in this file.";
|
|
1466
|
+
const once = /* @__PURE__ */ new Map();
|
|
1467
|
+
for (const family of families) if (!once.has(familyKey(family))) once.set(familyKey(family), family);
|
|
1468
|
+
const named = [...once.values()];
|
|
1469
|
+
const embedded = named.filter((family) => this.has(family));
|
|
1470
|
+
const fallback = named.filter((family) => !this.has(family));
|
|
1471
|
+
const parts = [];
|
|
1472
|
+
if (embedded.length > 0) parts.push(`Set in ${embedded.join(", ")}, embedded from the font files given.`);
|
|
1473
|
+
if (fallback.length > 0) parts.push(`${fallback.join(", ")}: no font file given, shown in Helvetica.`);
|
|
1474
|
+
return parts.join(" ");
|
|
1475
|
+
}
|
|
1476
|
+
};
|
|
1477
|
+
/**
|
|
1478
|
+
* The two families a deck sets its own text in: the display family, of the largest text style, and the body family, of the
|
|
1479
|
+
* style nearest 16 pixels, each with its weight. A style with no family is not considered.
|
|
1480
|
+
*/
|
|
1481
|
+
function brandFaces(brand) {
|
|
1482
|
+
const styles = [];
|
|
1483
|
+
for (const token of brand.tokens) {
|
|
1484
|
+
const parts = token.resolvedValue;
|
|
1485
|
+
if (token.type !== "typography" || has(token.aliasOf) || !isObject(parts)) continue;
|
|
1486
|
+
const raw = parts.fontFamily;
|
|
1487
|
+
const family = Array.isArray(raw) && raw.length > 0 ? raw[0] : typeof raw === "string" && raw !== "" ? raw : void 0;
|
|
1488
|
+
const px = sizePx(parts.fontSize);
|
|
1489
|
+
if (typeof family === "string" && family !== "" && px !== void 0 && isNumber(px)) styles.push({
|
|
1490
|
+
family,
|
|
1491
|
+
weight: weightOf(parts.fontWeight),
|
|
1492
|
+
px
|
|
1493
|
+
});
|
|
1494
|
+
}
|
|
1495
|
+
if (styles.length === 0) return {
|
|
1496
|
+
display: null,
|
|
1497
|
+
body: null
|
|
1498
|
+
};
|
|
1499
|
+
let display = styles[0];
|
|
1500
|
+
for (const style of styles) if (style.px > display.px) display = style;
|
|
1501
|
+
let body = styles[0];
|
|
1502
|
+
for (const style of styles) if (Math.abs(style.px - 16) < Math.abs(body.px - 16)) body = style;
|
|
1503
|
+
return {
|
|
1504
|
+
display: [display.family, display.weight],
|
|
1505
|
+
body: [body.family, body.weight]
|
|
1506
|
+
};
|
|
1507
|
+
}
|
|
1508
|
+
var startsWith = (bytes, ...codes) => codes.every((code, index) => bytes[index] === code);
|
|
1509
|
+
/** The media type of an image by what its first bytes say: a browser draws an SVG only when it is served as one */
|
|
1510
|
+
function mimeOf(bytes, ref) {
|
|
1511
|
+
const head = bytes.subarray(0, 512).toString("utf-8").trimStart();
|
|
1512
|
+
if (ref.toLowerCase().endsWith(".svg") || ref.startsWith("data:image/svg") || /^(<\?xml|<svg[\s>])/.test(head)) return "image/svg+xml";
|
|
1513
|
+
if (startsWith(bytes, 137, 80, 78, 71)) return "image/png";
|
|
1514
|
+
if (startsWith(bytes, 255, 216, 255)) return "image/jpeg";
|
|
1515
|
+
if (startsWith(bytes, 71, 73, 70, 56)) return "image/gif";
|
|
1516
|
+
if (startsWith(bytes, 82, 73, 70, 70) && bytes.subarray(8, 12).toString("latin1") === "WEBP") return "image/webp";
|
|
1517
|
+
if (bytes.subarray(4, 12).toString("latin1").startsWith("ftypavif")) return "image/avif";
|
|
1518
|
+
}
|
|
1519
|
+
/** The size of an SVG in its own units: its width and height, else its viewBox. undefined when it has neither or is no SVG. */
|
|
1520
|
+
function svgSize(text) {
|
|
1521
|
+
const tag = /<svg\b[^>]*>/i.exec(text)?.[0];
|
|
1522
|
+
if (!tag) return void 0;
|
|
1523
|
+
const attribute = (name) => new RegExp(`\\s${name}\\s*=\\s*["']([^"']*)["']`, "i").exec(tag)?.[1];
|
|
1524
|
+
const length = (value) => {
|
|
1525
|
+
const match = value === void 0 ? null : /^\s*([\d.]+)\s*(px|pt)?\s*$/.exec(value);
|
|
1526
|
+
return match ? Number(match[1]) * (match[2] === "pt" ? 4 / 3 : 1) : void 0;
|
|
1527
|
+
};
|
|
1528
|
+
const width = length(attribute("width"));
|
|
1529
|
+
const height = length(attribute("height"));
|
|
1530
|
+
if (width && height) return {
|
|
1531
|
+
width,
|
|
1532
|
+
height
|
|
1533
|
+
};
|
|
1534
|
+
const box = attribute("viewBox")?.trim().split(/[\s,]+/).map(Number);
|
|
1535
|
+
return box && box.length === 4 && box[2] > 0 && box[3] > 0 ? {
|
|
1536
|
+
width: box[2],
|
|
1537
|
+
height: box[3]
|
|
1538
|
+
} : void 0;
|
|
1539
|
+
}
|
|
1540
|
+
/** What a reader says went wrong with a file, as the Python deck's message did: the file's name and the system's reason */
|
|
1541
|
+
var reasonOf = (error) => error.message ?? String(error);
|
|
1542
|
+
/** Reads the images the slides name: from beside brand.json (the site), from the favicons folder, or from a data: URI. Each is served once. */
|
|
1543
|
+
var Images = class {
|
|
1544
|
+
measure;
|
|
1545
|
+
byKey = /* @__PURE__ */ new Map();
|
|
1546
|
+
byUrl = /* @__PURE__ */ new Map();
|
|
1547
|
+
constructor(measure) {
|
|
1548
|
+
this.measure = measure;
|
|
1549
|
+
}
|
|
1550
|
+
/** `ref` read from inside `root`, or throws a DeckError that names it */
|
|
1551
|
+
load(ref, root) {
|
|
1552
|
+
const key = `${root}\0${ref}`;
|
|
1553
|
+
const cached = this.byKey.get(key);
|
|
1554
|
+
if (cached) return this.sized(cached, ref);
|
|
1555
|
+
const bytes = this.read(ref, root);
|
|
1556
|
+
const mime = mimeOf(bytes, ref);
|
|
1557
|
+
if (!mime) throw new DeckError(`cannot read ${ref}: not an image the deck can draw (PNG, JPEG, GIF, WebP, AVIF or SVG)`);
|
|
1558
|
+
let size = {
|
|
1559
|
+
width: 1,
|
|
1560
|
+
height: 1
|
|
1561
|
+
};
|
|
1562
|
+
if (mime === "image/svg+xml") {
|
|
1563
|
+
const found = svgSize(bytes.toString("utf-8"));
|
|
1564
|
+
if (!found) throw new DeckError(`cannot read ${ref}: not a readable SVG`);
|
|
1565
|
+
size = found;
|
|
1566
|
+
}
|
|
1567
|
+
const served = {
|
|
1568
|
+
url: `/img/${this.byKey.size}`,
|
|
1569
|
+
mime,
|
|
1570
|
+
bytes,
|
|
1571
|
+
...size
|
|
1572
|
+
};
|
|
1573
|
+
if (mime === "image/svg+xml") this.measure.setNatural(served.url, size);
|
|
1574
|
+
this.byKey.set(key, served);
|
|
1575
|
+
this.byUrl.set(served.url, served);
|
|
1576
|
+
return this.sized(served, ref);
|
|
1577
|
+
}
|
|
1578
|
+
sized(served, ref) {
|
|
1579
|
+
const found = this.measure.natural(served.url);
|
|
1580
|
+
if (found === null) throw new DeckError(`cannot read ${ref}: the browser cannot draw this image`);
|
|
1581
|
+
return found ? {
|
|
1582
|
+
...served,
|
|
1583
|
+
width: found.width,
|
|
1584
|
+
height: found.height
|
|
1585
|
+
} : served;
|
|
1586
|
+
}
|
|
1587
|
+
read(ref, root) {
|
|
1588
|
+
try {
|
|
1589
|
+
if (ref.startsWith("data:")) {
|
|
1590
|
+
const [header = "", payload = ""] = [ref.slice(0, ref.indexOf(",")), ref.slice(ref.indexOf(",") + 1)];
|
|
1591
|
+
return header.includes(";base64") ? Buffer.from(payload, "base64") : Buffer.from(decodeURIComponent(payload), "binary");
|
|
1592
|
+
}
|
|
1593
|
+
const base = node_fs.default.realpathSync(root);
|
|
1594
|
+
const file = node_fs.default.realpathSync(node_path.default.resolve(base, ref));
|
|
1595
|
+
if (file !== base && !file.startsWith(base + node_path.default.sep)) throw new Error("is outside the folder it is read from");
|
|
1596
|
+
return node_fs.default.readFileSync(file);
|
|
1597
|
+
} catch (error) {
|
|
1598
|
+
throw new DeckError(`cannot read ${ref.startsWith("data:") ? "the embedded logo" : ref}: ${reasonOf(error)}`);
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
/** The image served at a URL, for the route that answers the browser */
|
|
1602
|
+
file(url) {
|
|
1603
|
+
return this.byUrl.get(url);
|
|
1604
|
+
}
|
|
1605
|
+
};
|
|
1606
|
+
var PT_PER_PX = .75;
|
|
1607
|
+
var Measure = class {
|
|
1608
|
+
widths = /* @__PURE__ */ new Map();
|
|
1609
|
+
sizes = /* @__PURE__ */ new Map();
|
|
1610
|
+
askedText = /* @__PURE__ */ new Map();
|
|
1611
|
+
askedImages = /* @__PURE__ */ new Set();
|
|
1612
|
+
/** The width in points of `text` set in `spec` at `size` points; an estimate (half the size a letter) until the browser has measured it */
|
|
1613
|
+
width(spec, size, text) {
|
|
1614
|
+
const key = `${spec.italic ? "i" : "n"}|${spec.weight}|${spec.family}|${size}|${text}`;
|
|
1615
|
+
const known = this.widths.get(key);
|
|
1616
|
+
if (known !== void 0) return known;
|
|
1617
|
+
this.askedText.set(key, [
|
|
1618
|
+
spec,
|
|
1619
|
+
size,
|
|
1620
|
+
text
|
|
1621
|
+
]);
|
|
1622
|
+
return [...text].length * size * .5;
|
|
1623
|
+
}
|
|
1624
|
+
/** The size of an image in its own pixels: undefined until measured, null when the browser cannot read it */
|
|
1625
|
+
natural(url) {
|
|
1626
|
+
const known = this.sizes.get(url);
|
|
1627
|
+
if (known === void 0) this.askedImages.add(url);
|
|
1628
|
+
return known;
|
|
1629
|
+
}
|
|
1630
|
+
/** Records the size of an image that needs no browser to read (an SVG's own width and height) */
|
|
1631
|
+
setNatural(url, size) {
|
|
1632
|
+
this.sizes.set(url, size);
|
|
1633
|
+
this.askedImages.delete(url);
|
|
1634
|
+
}
|
|
1635
|
+
get settled() {
|
|
1636
|
+
return this.askedText.size === 0 && this.askedImages.size === 0;
|
|
1637
|
+
}
|
|
1638
|
+
/** Asks the browser the questions layout could not answer. `page` has the deck's fonts and serves its images. */
|
|
1639
|
+
async fill(page, origin, skipImages = /* @__PURE__ */ new Set()) {
|
|
1640
|
+
const texts = [...this.askedText];
|
|
1641
|
+
const images = [...this.askedImages].filter((url) => !skipImages.has(url));
|
|
1642
|
+
this.askedText = /* @__PURE__ */ new Map();
|
|
1643
|
+
this.askedImages = /* @__PURE__ */ new Set();
|
|
1644
|
+
const jobs = texts.map(([key, [spec, size, text]]) => ({
|
|
1645
|
+
key,
|
|
1646
|
+
font: `${spec.italic ? "italic " : ""}${spec.weight} ${size * 4 / 3}px ${spec.family}`,
|
|
1647
|
+
text
|
|
1648
|
+
}));
|
|
1649
|
+
const answer = await page.evaluate(async ({ jobs: asked, images: urls, origin: base }) => {
|
|
1650
|
+
await Promise.all([...new Set(asked.map((job) => job.font))].map((font) => document.fonts.load(font).catch(() => [])));
|
|
1651
|
+
const context = document.createElement("canvas").getContext("2d");
|
|
1652
|
+
return {
|
|
1653
|
+
widths: asked.map((job) => {
|
|
1654
|
+
context.font = job.font;
|
|
1655
|
+
return [job.key, context.measureText(job.text).width];
|
|
1656
|
+
}),
|
|
1657
|
+
sizes: await Promise.all(urls.map(async (url) => {
|
|
1658
|
+
const image = new Image();
|
|
1659
|
+
image.src = `${base}${url}`;
|
|
1660
|
+
try {
|
|
1661
|
+
await image.decode();
|
|
1662
|
+
return [url, {
|
|
1663
|
+
width: image.naturalWidth,
|
|
1664
|
+
height: image.naturalHeight
|
|
1665
|
+
}];
|
|
1666
|
+
} catch {
|
|
1667
|
+
return [url, null];
|
|
1668
|
+
}
|
|
1669
|
+
}))
|
|
1670
|
+
};
|
|
1671
|
+
}, {
|
|
1672
|
+
jobs,
|
|
1673
|
+
images,
|
|
1674
|
+
origin
|
|
1675
|
+
});
|
|
1676
|
+
for (const [key, px] of answer.widths) this.widths.set(key, px * PT_PER_PX);
|
|
1677
|
+
for (const [url, size] of answer.sizes) this.sizes.set(url, size);
|
|
1678
|
+
}
|
|
1679
|
+
};
|
|
1680
|
+
/** Python's reportlab `simpleSplit`, on the browser's widths: paragraphs split at line breaks, words at spaces, and a word wider than the line cut by letters */
|
|
1681
|
+
function wrapText(measure, spec, text, size, maxWidth) {
|
|
1682
|
+
const out = [];
|
|
1683
|
+
const space = measure.width(spec, size, " ");
|
|
1684
|
+
for (const paragraph of text.split(/\r\n|\n|\r/)) {
|
|
1685
|
+
const words = paragraph.split(/\s+/).filter(Boolean);
|
|
1686
|
+
if (words.length === 0) {
|
|
1687
|
+
out.push("");
|
|
1688
|
+
continue;
|
|
1689
|
+
}
|
|
1690
|
+
let line = "";
|
|
1691
|
+
let used = 0;
|
|
1692
|
+
const push = () => {
|
|
1693
|
+
if (line !== "") out.push(line);
|
|
1694
|
+
line = "";
|
|
1695
|
+
used = 0;
|
|
1696
|
+
};
|
|
1697
|
+
for (const word of words) {
|
|
1698
|
+
let rest = word;
|
|
1699
|
+
let wide = measure.width(spec, size, rest);
|
|
1700
|
+
while (wide > maxWidth && [...rest].length > 1) {
|
|
1701
|
+
push();
|
|
1702
|
+
const letters = [...rest];
|
|
1703
|
+
let take = letters.length - 1;
|
|
1704
|
+
while (take > 1 && measure.width(spec, size, letters.slice(0, take).join("")) > maxWidth) take--;
|
|
1705
|
+
out.push(letters.slice(0, take).join(""));
|
|
1706
|
+
rest = letters.slice(take).join("");
|
|
1707
|
+
wide = measure.width(spec, size, rest);
|
|
1708
|
+
}
|
|
1709
|
+
if (line !== "" && used + space + wide > maxWidth) push();
|
|
1710
|
+
line = line === "" ? rest : `${line} ${rest}`;
|
|
1711
|
+
used = line === rest ? wide : used + space + wide;
|
|
1712
|
+
}
|
|
1713
|
+
push();
|
|
1714
|
+
}
|
|
1715
|
+
return out.length > 0 ? out : [""];
|
|
1716
|
+
}
|
|
1717
|
+
/** The text, cut with "..." when it is wider than `width` */
|
|
1718
|
+
function fitText(measure, spec, text, size, width) {
|
|
1719
|
+
if (measure.width(spec, size, text) <= width) return text;
|
|
1720
|
+
let cut = [...text];
|
|
1721
|
+
while (cut.length > 0 && measure.width(spec, size, `${cut.join("")}...`) > width) cut = cut.slice(0, -1);
|
|
1722
|
+
return `${cut.join("").trimEnd()}...`;
|
|
1723
|
+
}
|
|
1724
|
+
var FALLBACK = "Helvetica, Arial, 'Liberation Sans', sans-serif";
|
|
1725
|
+
var MONO = "Courier, 'Courier New', 'Liberation Mono', monospace";
|
|
1726
|
+
var PW = PAGE.width;
|
|
1727
|
+
var PH = PAGE.height;
|
|
1728
|
+
var escape = (text) => text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
1729
|
+
var fmt = (value) => String(Math.round(value * 100) / 100);
|
|
1730
|
+
var css = ([r, g, b, a]) => a < 1 ? `rgb(${r} ${g} ${b} / ${fmt(a)})` : `rgb(${r} ${g} ${b})`;
|
|
1731
|
+
function paletteOf(brand) {
|
|
1732
|
+
const roles = brand.theme.roles;
|
|
1733
|
+
const role = (name, fallback) => {
|
|
1734
|
+
const found = parseHex(typeof roles[name] === "string" ? roles[name] : "");
|
|
1735
|
+
return found ? [
|
|
1736
|
+
found[0],
|
|
1737
|
+
found[1],
|
|
1738
|
+
found[2],
|
|
1739
|
+
1
|
|
1740
|
+
] : parseHex(fallback);
|
|
1741
|
+
};
|
|
1742
|
+
return {
|
|
1743
|
+
ink: role("text", "#111111"),
|
|
1744
|
+
muted: role("muted", "#555555"),
|
|
1745
|
+
accent: role("accent", "#2563EB"),
|
|
1746
|
+
border: role("border", "#CCCCCC"),
|
|
1747
|
+
dark: role("inverse", "#111111"),
|
|
1748
|
+
light: role("background", "#FFFFFF"),
|
|
1749
|
+
onDark: role("inverseText", "#FFFFFF")
|
|
1750
|
+
};
|
|
1751
|
+
}
|
|
1752
|
+
/** The fallback faces, which the browser finds on the computer */
|
|
1753
|
+
var fallback = (weight, extra = {}) => ({
|
|
1754
|
+
family: FALLBACK,
|
|
1755
|
+
weight,
|
|
1756
|
+
...extra
|
|
1757
|
+
});
|
|
1758
|
+
var specOf = (face) => ({
|
|
1759
|
+
family: `'${face.css}', ${FALLBACK}`,
|
|
1760
|
+
weight: face.weight
|
|
1761
|
+
});
|
|
1762
|
+
/** The first `maxLines` of `lines`, the last ending in "..." when some were left out */
|
|
1763
|
+
function clip(lines, maxLines) {
|
|
1764
|
+
if (maxLines === void 0 || lines.length <= maxLines) return lines;
|
|
1765
|
+
const kept = lines.slice(0, maxLines);
|
|
1766
|
+
kept[kept.length - 1] = `${kept[kept.length - 1].trimEnd()}...`;
|
|
1767
|
+
return kept;
|
|
1768
|
+
}
|
|
1769
|
+
var Canvas = class {
|
|
1770
|
+
r;
|
|
1771
|
+
colors;
|
|
1772
|
+
faces;
|
|
1773
|
+
body = [];
|
|
1774
|
+
fg;
|
|
1775
|
+
background = [
|
|
1776
|
+
255,
|
|
1777
|
+
255,
|
|
1778
|
+
255,
|
|
1779
|
+
1
|
|
1780
|
+
];
|
|
1781
|
+
page = 0;
|
|
1782
|
+
/** Measuring a slide: nothing is drawn, so the code that draws it says how tall it is */
|
|
1783
|
+
dry = false;
|
|
1784
|
+
/** A list was cut short ("+N more") in the slide being drawn or measured */
|
|
1785
|
+
cut = false;
|
|
1786
|
+
/** The slides drawn so far, as HTML */
|
|
1787
|
+
sections = [];
|
|
1788
|
+
constructor(r) {
|
|
1789
|
+
this.r = r;
|
|
1790
|
+
this.colors = paletteOf(r.brand);
|
|
1791
|
+
const wanted = brandFaces(r.brand);
|
|
1792
|
+
const pick = (face, weight, plain) => {
|
|
1793
|
+
const found = face ? r.table.face(face[0], weight ?? face[1]) : void 0;
|
|
1794
|
+
return found ? specOf(found) : plain;
|
|
1795
|
+
};
|
|
1796
|
+
this.faces = {
|
|
1797
|
+
text: pick(wanted.body, 400, fallback(400)),
|
|
1798
|
+
bold: pick(wanted.body, 700, fallback(700)),
|
|
1799
|
+
title: pick(wanted.display, null, fallback(700))
|
|
1800
|
+
};
|
|
1801
|
+
}
|
|
1802
|
+
spec(font) {
|
|
1803
|
+
if (typeof font !== "string") return font;
|
|
1804
|
+
switch (font) {
|
|
1805
|
+
case "Helvetica": return this.faces.text;
|
|
1806
|
+
case "Helvetica-Bold": return this.faces.bold;
|
|
1807
|
+
case "Title": return this.faces.title;
|
|
1808
|
+
case "Helvetica-Oblique": return fallback(400, { italic: true });
|
|
1809
|
+
case "!Helvetica": return fallback(400);
|
|
1810
|
+
case "!Helvetica-Bold": return fallback(700);
|
|
1811
|
+
case "!Courier": return {
|
|
1812
|
+
family: MONO,
|
|
1813
|
+
weight: 400
|
|
1814
|
+
};
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
/** The face of one of the brand's families at a weight, or undefined when no font file was given for it */
|
|
1818
|
+
own(family, weight) {
|
|
1819
|
+
const found = family ? this.r.table.face(family, weight) : void 0;
|
|
1820
|
+
return found && specOf(found);
|
|
1821
|
+
}
|
|
1822
|
+
width(font, size, text) {
|
|
1823
|
+
return this.r.measure.width(this.spec(font), size, text);
|
|
1824
|
+
}
|
|
1825
|
+
/** The lines `text` is drawn in at this size within `width`: what the layout of a slide measures with */
|
|
1826
|
+
wrap = (text, size, width) => wrapText(this.r.measure, this.faces.text, text, size, width);
|
|
1827
|
+
lines(text, font, size, width) {
|
|
1828
|
+
return wrapText(this.r.measure, this.spec(font), text, size, width);
|
|
1829
|
+
}
|
|
1830
|
+
fit(text, font, size, width) {
|
|
1831
|
+
return fitText(this.r.measure, this.spec(font), text, size, width);
|
|
1832
|
+
}
|
|
1833
|
+
put(html) {
|
|
1834
|
+
this.body.push(html);
|
|
1835
|
+
}
|
|
1836
|
+
text(x, y, string, font = "Helvetica", size = 12, { color = this.colors.ink, align = "left" } = {}) {
|
|
1837
|
+
if (this.dry) return;
|
|
1838
|
+
const spec = this.spec(font);
|
|
1839
|
+
const place = align === "right" ? `right:${fmt(PW - x)}pt` : `left:${fmt(x)}pt${align === "center" ? ";transform:translateX(-50%)" : ""}`;
|
|
1840
|
+
this.put(`<div class="t" style="${place};top:${fmt(PH - y - 200)}pt;font-family:${spec.family};font-weight:${spec.weight};font-size:${size}pt;color:${css(color)}${spec.italic ? ";font-style:italic" : ""}"><i></i>${escape(string)}</div>`);
|
|
1841
|
+
}
|
|
1842
|
+
/**
|
|
1843
|
+
* One list item: its `lines` (already broken for the width) in one block of text, so the browser hangs a wrapped line under the
|
|
1844
|
+
* text and not under the bullet, which is the list's own marker in the margin (`list-style`) and not a character of the text.
|
|
1845
|
+
* (x, y) is the left edge of the text and the baseline of the first line; each line after it is `leading` lower.
|
|
1846
|
+
*/
|
|
1847
|
+
bullet(x, y, lines, font = "Helvetica", size = 12, { color = this.colors.ink, marker = color, leading = size * GUIDE_LEAD } = {}) {
|
|
1848
|
+
if (this.dry || lines.length === 0) return;
|
|
1849
|
+
const spec = this.spec(font);
|
|
1850
|
+
this.put(`<ul class="l" style="left:${fmt(x)}pt;top:${fmt(PH - y - 200)}pt;font-family:${spec.family};font-weight:${spec.weight};font-size:${size}pt;line-height:${fmt(leading)}pt;color:${css(color)};--m:${css(marker)}"><li><i></i>${escape(lines.join("\n"))}</li></ul>`);
|
|
1851
|
+
}
|
|
1852
|
+
/** A note that may be long, wrapped to `width` and drawn upward from its last line's baseline at `bottom`, so it stays clear of the footer. */
|
|
1853
|
+
note(x, bottom, string, width, color) {
|
|
1854
|
+
const lines = this.lines(string, "Helvetica", 10, width);
|
|
1855
|
+
[...lines].reverse().forEach((line, n) => this.text(x, bottom + n * 13, line, "Helvetica", 10, { color: color ?? this.colors.muted }));
|
|
1856
|
+
return bottom + lines.length * 13;
|
|
1857
|
+
}
|
|
1858
|
+
/** Wrapped text from y downward; returns the y below it. With `align`, x is the left edge, the centre or the right edge. */
|
|
1859
|
+
paragraph(x, y, string, width, { font = "Helvetica", size = 12, color, leading, maxLines, align = "left" } = {}) {
|
|
1860
|
+
const lines = clip(this.lines(string, font, size, width), maxLines);
|
|
1861
|
+
const step = leading ?? size * 1.3;
|
|
1862
|
+
let at = y;
|
|
1863
|
+
for (const line of lines) {
|
|
1864
|
+
this.text(x, at, line, font, size, {
|
|
1865
|
+
color,
|
|
1866
|
+
align
|
|
1867
|
+
});
|
|
1868
|
+
at -= step;
|
|
1869
|
+
}
|
|
1870
|
+
return at;
|
|
1871
|
+
}
|
|
1872
|
+
/** A box with its bottom left corner at (x, y): filled, stroked with a 1 point line centred on its edge, or both. A stroke is drawn as an SVG rectangle, so the browser does not snap it to its pixels. */
|
|
1873
|
+
rect(x, y, w, h, { fill, stroke } = {}) {
|
|
1874
|
+
const place = `left:${fmt(x)}pt;top:${fmt(PH - y - h)}pt;width:${fmt(w)}pt;height:${fmt(h)}pt`;
|
|
1875
|
+
if (stroke) {
|
|
1876
|
+
const inside = fill === void 0 || typeof fill === "string" ? "none" : css(fill);
|
|
1877
|
+
this.put(`<svg class="r" style="${place};overflow:visible" viewBox="0 0 ${fmt(w)} ${fmt(h)}"><rect width="${fmt(w)}" height="${fmt(h)}" fill="${inside}" stroke="${css(stroke)}" stroke-width="1"/></svg>`);
|
|
1878
|
+
return;
|
|
1879
|
+
}
|
|
1880
|
+
const fillStyle = fill === void 0 ? "" : `background:${typeof fill === "string" ? fill : css(fill)}`;
|
|
1881
|
+
this.put(`<div class="r" style="${place};${fillStyle}"></div>`);
|
|
1882
|
+
}
|
|
1883
|
+
dashed(x, y, w, h, stroke) {
|
|
1884
|
+
this.put(`<svg class="r" style="left:${fmt(x)}pt;top:${fmt(PH - y - h)}pt;width:${fmt(w)}pt;height:${fmt(h)}pt;overflow:visible" viewBox="0 0 ${fmt(w)} ${fmt(h)}"><rect width="${fmt(w)}" height="${fmt(h)}" fill="none" stroke="${css(stroke)}" stroke-width="1" stroke-dasharray="4 3"/></svg>`);
|
|
1885
|
+
}
|
|
1886
|
+
line(x1, y, x2) {
|
|
1887
|
+
this.put(`<div class="r" style="left:${fmt(x1)}pt;top:${fmt(PH - y - .5)}pt;width:${fmt(x2 - x1)}pt;height:0;border-top:1pt solid ${css(this.colors.border)}"></div>`);
|
|
1888
|
+
}
|
|
1889
|
+
picture(url, x, y, w, h) {
|
|
1890
|
+
this.put(`<img class="r" src="${url}" style="left:${fmt(x)}pt;top:${fmt(PH - y - h)}pt;width:${fmt(w)}pt;height:${fmt(h)}pt" alt="">`);
|
|
1891
|
+
}
|
|
1892
|
+
/** An image read from the site, or from `root`: it is drawn by `draw(x, y, w, h)`, and is `width` x `height` in its own pixels */
|
|
1893
|
+
image(ref, root = this.r.siteDir) {
|
|
1894
|
+
const served = this.r.images.load(ref, root);
|
|
1895
|
+
return {
|
|
1896
|
+
draw: (x, y, w, h) => this.picture(served.url, x, y, w, h),
|
|
1897
|
+
width: served.width,
|
|
1898
|
+
height: served.height
|
|
1899
|
+
};
|
|
1900
|
+
}
|
|
1901
|
+
begin(title, dark = false) {
|
|
1902
|
+
this.page += 1;
|
|
1903
|
+
this.body = [];
|
|
1904
|
+
this.fg = dark ? this.colors.onDark : this.colors.ink;
|
|
1905
|
+
this.background = dark ? this.colors.dark : this.colors.light;
|
|
1906
|
+
this.rect(56, PH - 48, 40, 4, { fill: this.colors.accent });
|
|
1907
|
+
if (title) this.text(56, PH - 84, title, "Title", 28, { color: this.fg });
|
|
1908
|
+
this.text(56, 26, this.r.brand.brand.title, "Helvetica", 10, { color: this.fg });
|
|
1909
|
+
this.text(PW - 56, 26, String(this.page), "Helvetica", 10, {
|
|
1910
|
+
color: this.fg,
|
|
1911
|
+
align: "right"
|
|
1912
|
+
});
|
|
1913
|
+
}
|
|
1914
|
+
end() {
|
|
1915
|
+
this.sections.push(`<section class="s" style="background:${css(this.background)}">${this.body.join("")}</section>`);
|
|
1916
|
+
}
|
|
1917
|
+
};
|
|
1918
|
+
/** The swatches of one or more groups. One group is drawn roomy, and a slide of several groups smaller, a heading each: the height of a row is what the slide has left divided by the rows it needs. */
|
|
1919
|
+
function drawColors(p, slide) {
|
|
1920
|
+
p.begin(slide.title);
|
|
1921
|
+
const { groups } = slide;
|
|
1922
|
+
let top = PH - 112;
|
|
1923
|
+
if (groups.length === 1 && slide.note) top = p.paragraph(56, top, slide.note, 760, {
|
|
1924
|
+
size: 12,
|
|
1925
|
+
color: p.colors.muted,
|
|
1926
|
+
maxLines: 2
|
|
1927
|
+
}) - 6;
|
|
1928
|
+
const cols = Math.max(4, ...groups.map((group) => group.swatches.length));
|
|
1929
|
+
const gap = 12;
|
|
1930
|
+
const width = (PW - 112 - gap * (cols - 1)) / cols;
|
|
1931
|
+
const heading = groups.length === 1 ? 0 : 26;
|
|
1932
|
+
const rowH = Math.min(190, (top - 62 - heading * groups.length) / groups.length);
|
|
1933
|
+
const full = rowH >= 150;
|
|
1934
|
+
const lines = Math.max(...groups.flatMap((group) => group.swatches.map(printLines)));
|
|
1935
|
+
const below = 31 + (full ? Math.max(3, lines) * 14 + 28 : 12 * lines) + 10;
|
|
1936
|
+
const swatchH = Math.min(78, Math.max(28, rowH - below));
|
|
1937
|
+
let y = top;
|
|
1938
|
+
for (const group of groups) {
|
|
1939
|
+
if (heading) {
|
|
1940
|
+
p.text(56, y - 14, group.title, "Helvetica-Bold", 13, { color: p.fg });
|
|
1941
|
+
if (group.note) p.text(206, y - 14, p.fit(group.note, "Helvetica", 10, PW - 112 - 150), "Helvetica", 10, { color: p.colors.muted });
|
|
1942
|
+
y -= heading;
|
|
1943
|
+
}
|
|
1944
|
+
group.swatches.forEach((swatch, index) => drawSwatch(p, 56 + index * (width + gap), y, width, swatchH, swatch, full));
|
|
1945
|
+
y -= rowH;
|
|
1946
|
+
}
|
|
1947
|
+
p.end();
|
|
1948
|
+
}
|
|
1949
|
+
/** One color: the swatch, then its name, hex and print values. `full` has room for each on a line and a description. */
|
|
1950
|
+
function drawSwatch(p, x, top, width, height, swatch, full) {
|
|
1951
|
+
const y = top - height;
|
|
1952
|
+
const rgb = parseHex(swatch.hex);
|
|
1953
|
+
p.rect(x, y, width, height, {
|
|
1954
|
+
stroke: p.colors.border,
|
|
1955
|
+
...rgb && { fill: rgb }
|
|
1956
|
+
});
|
|
1957
|
+
p.text(x, y - 16, swatch.name, "Helvetica-Bold", full ? 13 : 12, { color: p.fg });
|
|
1958
|
+
p.text(x, y - 31, swatch.hex, "Helvetica", full ? 12 : 10, { color: p.fg });
|
|
1959
|
+
const lines = [];
|
|
1960
|
+
if (swatch.rgb) lines.push(`RGB ${swatch.rgb.join(" ")}`);
|
|
1961
|
+
if (swatch.cmyk && swatch.cmyk.length > 0) lines.push(`CMYK ${swatch.cmyk.join(" ")}`);
|
|
1962
|
+
if (swatch.pms) lines.push(`PMS ${swatch.pms}`);
|
|
1963
|
+
if (swatch.ral) lines.push(`RAL ${swatch.ral}`);
|
|
1964
|
+
const [size, step] = full ? [11, 14] : [10, 12];
|
|
1965
|
+
let lineY = y - 31;
|
|
1966
|
+
for (const line of lines) {
|
|
1967
|
+
lineY -= step;
|
|
1968
|
+
p.text(x, lineY, p.fit(line, "Helvetica", size, width), "Helvetica", size, { color: p.colors.muted });
|
|
1969
|
+
}
|
|
1970
|
+
if (swatch.description && full) p.paragraph(x, lineY - 14, swatch.description, width, {
|
|
1971
|
+
size: 10,
|
|
1972
|
+
color: p.colors.muted,
|
|
1973
|
+
maxLines: 2
|
|
1974
|
+
});
|
|
1975
|
+
}
|
|
1976
|
+
function drawGradients(p, slide) {
|
|
1977
|
+
p.begin(slide.title);
|
|
1978
|
+
const [cols, gap, height] = [
|
|
1979
|
+
3,
|
|
1980
|
+
20,
|
|
1981
|
+
110
|
|
1982
|
+
];
|
|
1983
|
+
const width = (PW - 112 - gap * (cols - 1)) / cols;
|
|
1984
|
+
slide.gradients.forEach((gradient, index) => {
|
|
1985
|
+
const x = 56 + index % cols * (width + gap);
|
|
1986
|
+
const y = PH - 112 - height - Math.floor(index / cols) * 190;
|
|
1987
|
+
const stops = gradient.stops.map((stop) => {
|
|
1988
|
+
const rgb = parseHex(stop.color) ?? [
|
|
1989
|
+
128,
|
|
1990
|
+
128,
|
|
1991
|
+
128,
|
|
1992
|
+
1
|
|
1993
|
+
];
|
|
1994
|
+
return `rgb(${rgb[0]} ${rgb[1]} ${rgb[2]}) ${fmt(stop.position * 100)}%`;
|
|
1995
|
+
});
|
|
1996
|
+
p.rect(x, y, width, height, { fill: `linear-gradient(${gradient.angle}deg, ${stops.join(", ")})` });
|
|
1997
|
+
p.text(x, y - 18, gradient.name, "Helvetica-Bold", 13, { color: p.fg });
|
|
1998
|
+
const described = gradient.stops.map((stop) => `${stop.color.toUpperCase()} ${number(stop.position * 100)}%`).join(", ");
|
|
1999
|
+
p.paragraph(x, y - 34, `${number(gradient.angle)} deg: ${described}`, width, {
|
|
2000
|
+
size: 10,
|
|
2001
|
+
color: p.colors.muted,
|
|
2002
|
+
maxLines: 3
|
|
2003
|
+
});
|
|
2004
|
+
});
|
|
2005
|
+
p.end();
|
|
2006
|
+
}
|
|
2007
|
+
function drawCover(p, slide) {
|
|
2008
|
+
const { logo } = slide;
|
|
2009
|
+
const dark = logo?.background === "dark";
|
|
2010
|
+
p.begin(null, dark);
|
|
2011
|
+
p.rect(0, 0, 18, PH, { fill: p.colors.accent });
|
|
2012
|
+
if (logo) {
|
|
2013
|
+
const { draw, width, height } = p.image(logo.file);
|
|
2014
|
+
const scale = Math.min(220 / width, 56 / height);
|
|
2015
|
+
draw(64, PH - 64 - height * scale, width * scale, height * scale);
|
|
2016
|
+
}
|
|
2017
|
+
const y = p.paragraph(64, 300, slide.title, 760, {
|
|
2018
|
+
font: "Title",
|
|
2019
|
+
size: 54,
|
|
2020
|
+
color: p.fg,
|
|
2021
|
+
leading: 62,
|
|
2022
|
+
maxLines: 3
|
|
2023
|
+
});
|
|
2024
|
+
if (slide.subtitle) p.paragraph(64, y - 12, slide.subtitle, 640, {
|
|
2025
|
+
size: 20,
|
|
2026
|
+
color: dark ? p.fg : p.colors.muted,
|
|
2027
|
+
maxLines: 4
|
|
2028
|
+
});
|
|
2029
|
+
p.end();
|
|
2030
|
+
}
|
|
2031
|
+
/** A few parts are drawn large on one line each; many are drawn smaller in columns, so every part is on the slide. */
|
|
2032
|
+
function drawContents(p, slide) {
|
|
2033
|
+
p.begin(slide.title);
|
|
2034
|
+
const { items } = slide;
|
|
2035
|
+
const [size, step, rows] = items.length > 7 ? [
|
|
2036
|
+
14,
|
|
2037
|
+
34,
|
|
2038
|
+
9
|
|
2039
|
+
] : [
|
|
2040
|
+
24,
|
|
2041
|
+
52,
|
|
2042
|
+
items.length || 1
|
|
2043
|
+
];
|
|
2044
|
+
const columns = items.length > 0 ? Math.ceil(items.length / rows) : 1;
|
|
2045
|
+
const gap = 28;
|
|
2046
|
+
const width = (PW - 112 - gap * (columns - 1)) / columns;
|
|
2047
|
+
items.forEach((item, index) => {
|
|
2048
|
+
const x = 56 + Math.floor(index / rows) * (width + gap);
|
|
2049
|
+
const y = 360 - index % rows * step;
|
|
2050
|
+
p.text(x, y, p.fit(item.title, "Helvetica-Bold", size, width - 44), "Helvetica-Bold", size, { color: p.fg });
|
|
2051
|
+
p.text(x + width, y, String(item.page), "Helvetica", size, {
|
|
2052
|
+
color: p.colors.muted,
|
|
2053
|
+
align: "right"
|
|
2054
|
+
});
|
|
2055
|
+
p.line(x, y - 10, x + width);
|
|
2056
|
+
});
|
|
2057
|
+
p.end();
|
|
2058
|
+
}
|
|
2059
|
+
/**
|
|
2060
|
+
* A page of the brand book: its title and its description on the dark ground, and below them what its categories' guidelines leave open,
|
|
2061
|
+
* as far as there is room above the footer. A page with lists of what is left open starts higher, as much higher as it takes (up to
|
|
2062
|
+
* DIVIDER_TOP_MAX) for none of them to be cut: the slide is measured first, without drawing, then drawn.
|
|
2063
|
+
*/
|
|
2064
|
+
function drawDivider(p, slide) {
|
|
2065
|
+
let top = slide.open.length > 0 ? 340 : 300;
|
|
2066
|
+
if (slide.open.length > 0) {
|
|
2067
|
+
p.dry = true;
|
|
2068
|
+
try {
|
|
2069
|
+
while (top < 420 && dividerBody(p, slide, top)) top += 10;
|
|
2070
|
+
} finally {
|
|
2071
|
+
p.dry = false;
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
p.begin(null, true);
|
|
2075
|
+
dividerBody(p, slide, top);
|
|
2076
|
+
p.end();
|
|
2077
|
+
}
|
|
2078
|
+
/** A divider's title, description and lists with the title at `top`; true if a list was cut short. */
|
|
2079
|
+
function dividerBody(p, slide, top) {
|
|
2080
|
+
p.cut = false;
|
|
2081
|
+
let y = p.paragraph(56, top, slide.title, 760, {
|
|
2082
|
+
font: "Title",
|
|
2083
|
+
size: 44,
|
|
2084
|
+
color: p.fg,
|
|
2085
|
+
leading: 52,
|
|
2086
|
+
maxLines: 3
|
|
2087
|
+
});
|
|
2088
|
+
if (slide.description) y = p.paragraph(56, y - 10, slide.description, 700, {
|
|
2089
|
+
size: 18,
|
|
2090
|
+
color: p.fg,
|
|
2091
|
+
maxLines: 5
|
|
2092
|
+
});
|
|
2093
|
+
y -= 28;
|
|
2094
|
+
for (const [position, category] of slide.open.entries()) {
|
|
2095
|
+
if (y < 122) {
|
|
2096
|
+
p.text(56, y, `+${slide.open.length - position} more`, "Helvetica", 12, { color: p.fg });
|
|
2097
|
+
p.cut = true;
|
|
2098
|
+
break;
|
|
2099
|
+
}
|
|
2100
|
+
p.text(56, y, `Not specified: ${category.title}`, "Helvetica-Bold", 12, { color: p.fg });
|
|
2101
|
+
const source = category.source ? p.lines(category.source, "Helvetica", 10, 700) : [];
|
|
2102
|
+
const extra = Math.max(source.length - 1, 0) * 13;
|
|
2103
|
+
y = drawBullets(p, 56, y - 8, category.items, 700, 62 + extra, 12, p.fg);
|
|
2104
|
+
source.forEach((line, n) => p.text(56, y - 10 - n * 13, line, "Helvetica", 10, { color: p.fg }));
|
|
2105
|
+
y -= (source.length > 0 ? 14 + extra : 0) + 18;
|
|
2106
|
+
}
|
|
2107
|
+
return p.cut;
|
|
2108
|
+
}
|
|
2109
|
+
/** A list from y downward that stops above `floor` and says how many items it left out; returns the y below it. */
|
|
2110
|
+
function drawBullets(p, x, y, items, width, floor, size = 12, color) {
|
|
2111
|
+
const leading = size * 1.3;
|
|
2112
|
+
let at = y;
|
|
2113
|
+
for (const [index, item] of items.entries()) {
|
|
2114
|
+
const all = p.lines(item, "Helvetica", size, width - 12);
|
|
2115
|
+
const lines = all.slice(0, 3);
|
|
2116
|
+
const rest = items.length - index;
|
|
2117
|
+
if (at - lines.length * leading < floor + (rest > 1 ? leading : 0)) {
|
|
2118
|
+
p.text(x, at - size, `+${rest} more`, "Helvetica", size, { color: color ?? p.colors.muted });
|
|
2119
|
+
p.cut = true;
|
|
2120
|
+
return at - leading;
|
|
2121
|
+
}
|
|
2122
|
+
p.bullet(x + 12, at - size, clip(all, 3), "Helvetica", size, {
|
|
2123
|
+
color,
|
|
2124
|
+
marker: color ?? p.colors.muted,
|
|
2125
|
+
leading
|
|
2126
|
+
});
|
|
2127
|
+
at -= lines.length * leading + 3;
|
|
2128
|
+
}
|
|
2129
|
+
return at;
|
|
2130
|
+
}
|
|
2131
|
+
/** A view the favicons plugin drew: its image across the slide, and what it shows. */
|
|
2132
|
+
function drawFaviconView(p, slide) {
|
|
2133
|
+
p.begin(slide.title);
|
|
2134
|
+
const { draw, width: naturalW, height: naturalH } = p.image(slide.file, node_path.default.dirname(slide.base));
|
|
2135
|
+
const width = PW - 112;
|
|
2136
|
+
const height = width * (slide.height || naturalH) / (slide.width || naturalW);
|
|
2137
|
+
const top = PH - 110;
|
|
2138
|
+
draw(56, top - height, width, height);
|
|
2139
|
+
p.rect(56, top - height, width, height, { stroke: p.colors.border });
|
|
2140
|
+
if (slide.note) p.paragraph(56, top - height - 24, slide.note, width, {
|
|
2141
|
+
size: 12,
|
|
2142
|
+
color: p.colors.muted,
|
|
2143
|
+
maxLines: 4
|
|
2144
|
+
});
|
|
2145
|
+
p.end();
|
|
2146
|
+
}
|
|
2147
|
+
/** The table of the set's files: file, size, use; the head snippet and the set's colours under it when the plan put them there. */
|
|
2148
|
+
function drawFaviconFiles(p, slide) {
|
|
2149
|
+
p.begin(slide.title);
|
|
2150
|
+
const columns = [
|
|
2151
|
+
56,
|
|
2152
|
+
286,
|
|
2153
|
+
436
|
|
2154
|
+
];
|
|
2155
|
+
const right = PW - 56;
|
|
2156
|
+
const pitch = slide.head ? 17 : 22;
|
|
2157
|
+
let y = PH - 120;
|
|
2158
|
+
[
|
|
2159
|
+
"File",
|
|
2160
|
+
"Size",
|
|
2161
|
+
"Use"
|
|
2162
|
+
].forEach((label, index) => p.text(columns[index], y, label, "Helvetica-Bold", 11, { color: p.fg }));
|
|
2163
|
+
p.line(56, y - 6, right);
|
|
2164
|
+
for (const row of slide.rows) {
|
|
2165
|
+
y -= pitch;
|
|
2166
|
+
if (y < 62) break;
|
|
2167
|
+
p.text(columns[0], y, p.fit(row.file, "Helvetica", 10, 220), "Helvetica", 10, { color: p.fg });
|
|
2168
|
+
p.text(columns[1], y, p.fit(row.size, "Helvetica", 10, 140), "Helvetica", 10, { color: p.colors.muted });
|
|
2169
|
+
p.text(columns[2], y, p.fit(row.use, "Helvetica", 10, right - columns[2]), "Helvetica", 10, { color: p.colors.muted });
|
|
2170
|
+
}
|
|
2171
|
+
if (slide.head) {
|
|
2172
|
+
y -= 22;
|
|
2173
|
+
p.text(56, y, "Head snippet", "Helvetica-Bold", 11, { color: p.fg });
|
|
2174
|
+
drawFaviconSwatches(p, slide.colors ?? {}, {
|
|
2175
|
+
x: 486,
|
|
2176
|
+
top: y + 4,
|
|
2177
|
+
columns: 2,
|
|
2178
|
+
pitch: 42
|
|
2179
|
+
});
|
|
2180
|
+
for (const line of slide.head) {
|
|
2181
|
+
y -= 14;
|
|
2182
|
+
p.text(56, y, p.fit(line, "!Courier", 10, 420), "!Courier", 10, { color: p.fg });
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
p.end();
|
|
2186
|
+
}
|
|
2187
|
+
/** The tags to paste into <head>, and the colors the set is drawn in. */
|
|
2188
|
+
function drawFaviconHead(p, slide) {
|
|
2189
|
+
p.begin(slide.title);
|
|
2190
|
+
let y = PH - 124;
|
|
2191
|
+
for (const line of slide.head) {
|
|
2192
|
+
p.text(56, y, p.fit(line, "!Courier", 11, PW - 112), "!Courier", 11, { color: p.fg });
|
|
2193
|
+
y -= 18;
|
|
2194
|
+
}
|
|
2195
|
+
drawFaviconSwatches(p, slide.colors);
|
|
2196
|
+
p.end();
|
|
2197
|
+
}
|
|
2198
|
+
/** The set's colours as small swatches: in one row near the foot, or, given a `grid`, in rows of `columns` from `top` down. */
|
|
2199
|
+
function drawFaviconSwatches(p, colors, grid) {
|
|
2200
|
+
let index = 0;
|
|
2201
|
+
for (const label of [
|
|
2202
|
+
"ground",
|
|
2203
|
+
"ink",
|
|
2204
|
+
"favicon",
|
|
2205
|
+
"themeColor"
|
|
2206
|
+
]) {
|
|
2207
|
+
const rgb = parseHex(colors[label] ?? "");
|
|
2208
|
+
if (!rgb) continue;
|
|
2209
|
+
const x = (grid?.x ?? 56) + (grid ? index % grid.columns : index) * 150;
|
|
2210
|
+
const y = grid ? grid.top - 28 - Math.floor(index / grid.columns) * grid.pitch : 80;
|
|
2211
|
+
p.rect(x, y, 28, 28, {
|
|
2212
|
+
fill: [
|
|
2213
|
+
rgb[0],
|
|
2214
|
+
rgb[1],
|
|
2215
|
+
rgb[2],
|
|
2216
|
+
1
|
|
2217
|
+
],
|
|
2218
|
+
stroke: p.colors.border
|
|
2219
|
+
});
|
|
2220
|
+
p.text(x + 36, y + 18, humanize(label), "Helvetica-Bold", 10, { color: p.fg });
|
|
2221
|
+
p.text(x + 36, y + 4, colors[label], "Helvetica", 10, { color: p.colors.muted });
|
|
2222
|
+
index += 1;
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
/** The figures of a `blazon:assets` directive: each picture fitted, not cropped, into its cell and sitting on the row's baseline, its title centred under it. A picture on a dark ground is drawn on the dark colour, as in an asset's panel. */
|
|
2226
|
+
function drawGrid(p, slide) {
|
|
2227
|
+
p.begin(slide.title);
|
|
2228
|
+
const { cols, rows } = slide;
|
|
2229
|
+
const cellW = (PW - 112 - 16 * (cols - 1)) / cols;
|
|
2230
|
+
const cellH = (340 - 14 * (rows - 1)) / rows;
|
|
2231
|
+
slide.figures.forEach((figure, index) => {
|
|
2232
|
+
const x = 56 + index % cols * (cellW + 16);
|
|
2233
|
+
const bottom = 410 - Math.floor(index / cols) * (cellH + 14) - cellH + 30;
|
|
2234
|
+
const area = cellH - 30;
|
|
2235
|
+
const dark = figure.background === "dark";
|
|
2236
|
+
let draw;
|
|
2237
|
+
let naturalW;
|
|
2238
|
+
let naturalH;
|
|
2239
|
+
try {
|
|
2240
|
+
({draw, width: naturalW, height: naturalH} = p.image(figure.file));
|
|
2241
|
+
} catch (error) {
|
|
2242
|
+
if (!(error instanceof DeckError) || !figure.local) throw error;
|
|
2243
|
+
[naturalW, naturalH] = [figure.width || 1, figure.height || 1];
|
|
2244
|
+
}
|
|
2245
|
+
const artW = figure.width || naturalW;
|
|
2246
|
+
const artH = figure.height || naturalH;
|
|
2247
|
+
const scale = Math.min(cellW / artW, area / artH);
|
|
2248
|
+
const [w, h] = [artW * scale, artH * scale];
|
|
2249
|
+
const left = x + (cellW - w) / 2;
|
|
2250
|
+
p.rect(left, bottom, w, h, { fill: dark ? p.colors.dark : p.colors.light });
|
|
2251
|
+
if (draw) draw(left, bottom, w, h);
|
|
2252
|
+
p.rect(left, bottom, w, h, { stroke: p.colors.border });
|
|
2253
|
+
if (!draw && figure.local) p.paragraph(left + 8, bottom + h - 16, figure.local, w - 16, {
|
|
2254
|
+
size: 10,
|
|
2255
|
+
color: dark ? p.colors.onDark : p.colors.muted,
|
|
2256
|
+
maxLines: Math.max(1, Math.floor((h - 8) / 13))
|
|
2257
|
+
});
|
|
2258
|
+
p.paragraph(x + cellW / 2, bottom - 14, figure.title, cellW, {
|
|
2259
|
+
font: "Helvetica-Bold",
|
|
2260
|
+
size: 10,
|
|
2261
|
+
color: p.fg,
|
|
2262
|
+
leading: 12,
|
|
2263
|
+
maxLines: 2,
|
|
2264
|
+
align: "center"
|
|
2265
|
+
});
|
|
2266
|
+
});
|
|
2267
|
+
p.end();
|
|
2268
|
+
}
|
|
2269
|
+
/** An asset a `blazon:section` directive lists: its image on the left, what its sidecar says on the right. The plan fitted the text to the slide (`layout`); a slide that carries none is fitted here, with the slides that continue it. */
|
|
2270
|
+
function drawGuideline(p, slide) {
|
|
2271
|
+
if (!slide.layout) {
|
|
2272
|
+
for (const part of fitted(slide, p.wrap)) drawGuideline(p, part);
|
|
2273
|
+
return;
|
|
2274
|
+
}
|
|
2275
|
+
const { layout } = slide;
|
|
2276
|
+
p.begin(slide.title);
|
|
2277
|
+
if (layout.panel) drawPanel(p, slide, layout.panel, slide.background === "dark");
|
|
2278
|
+
const { x: rx, width: rw } = guideGeometry(layout.panel);
|
|
2279
|
+
const { lines } = sourceRoom(slide, rw, p.wrap);
|
|
2280
|
+
const { ops } = guideOps(slide, layout.size, rw, layout.columns, p.wrap, layout.traits === "line");
|
|
2281
|
+
for (const [role, x, y, text] of ops) {
|
|
2282
|
+
if (role === "bullet") {
|
|
2283
|
+
p.bullet(rx + x, 410 - y, text.split("\n"), "Helvetica", layout.size, { marker: p.colors.muted });
|
|
2284
|
+
continue;
|
|
2285
|
+
}
|
|
2286
|
+
const [font, size, color] = role === "label" ? [
|
|
2287
|
+
"Helvetica-Bold",
|
|
2288
|
+
11,
|
|
2289
|
+
p.fg
|
|
2290
|
+
] : role === "item" ? [
|
|
2291
|
+
"Helvetica",
|
|
2292
|
+
layout.size,
|
|
2293
|
+
void 0
|
|
2294
|
+
] : [
|
|
2295
|
+
"Helvetica",
|
|
2296
|
+
layout.size,
|
|
2297
|
+
p.colors.muted
|
|
2298
|
+
];
|
|
2299
|
+
p.text(rx + x, 410 - y, text, font, size, { color });
|
|
2300
|
+
}
|
|
2301
|
+
if (lines.length > 0 && slide.source) p.note(rx, 70, slide.source, rw);
|
|
2302
|
+
p.end();
|
|
2303
|
+
}
|
|
2304
|
+
/** The box the image of an asset slide is drawn in, with the image fitted into it. */
|
|
2305
|
+
function drawPanel(p, slide, width, dark) {
|
|
2306
|
+
const [px, py, pw, ph] = [
|
|
2307
|
+
56,
|
|
2308
|
+
70,
|
|
2309
|
+
width,
|
|
2310
|
+
340
|
|
2311
|
+
];
|
|
2312
|
+
p.rect(px, py, pw, ph, { fill: dark ? p.colors.dark : p.colors.light });
|
|
2313
|
+
try {
|
|
2314
|
+
const { draw, width: naturalW, height: naturalH } = p.image(slide.file);
|
|
2315
|
+
const artW = slide.width || naturalW;
|
|
2316
|
+
const artH = slide.height || naturalH;
|
|
2317
|
+
const scale = Math.min((pw - 48) / artW, (ph - 48) / artH);
|
|
2318
|
+
draw(px + (pw - artW * scale) / 2, py + (ph - artH * scale) / 2, artW * scale, artH * scale);
|
|
2319
|
+
p.rect(px, py, pw, ph, { stroke: p.colors.border });
|
|
2320
|
+
} catch (error) {
|
|
2321
|
+
if (!(error instanceof DeckError) || !slide.local) throw error;
|
|
2322
|
+
p.rect(px, py, pw, ph, { stroke: p.colors.border });
|
|
2323
|
+
p.paragraph(px + 24, py + ph - 36, slide.local, pw - 48, {
|
|
2324
|
+
size: 13,
|
|
2325
|
+
color: dark ? p.colors.onDark : p.colors.muted,
|
|
2326
|
+
maxLines: 8
|
|
2327
|
+
});
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
function drawLogo(p, slide) {
|
|
2331
|
+
const dark = slide.background === "dark";
|
|
2332
|
+
p.begin(slide.title);
|
|
2333
|
+
const [px, py, pw, ph] = [
|
|
2334
|
+
56,
|
|
2335
|
+
70,
|
|
2336
|
+
540,
|
|
2337
|
+
340
|
|
2338
|
+
];
|
|
2339
|
+
p.rect(px, py, pw, ph, { fill: dark ? p.colors.dark : p.colors.light });
|
|
2340
|
+
p.rect(px, py, pw, ph, { stroke: p.colors.border });
|
|
2341
|
+
const { draw, width: naturalW, height: naturalH } = p.image(slide.file);
|
|
2342
|
+
const artW = slide.width || naturalW;
|
|
2343
|
+
const artH = slide.height || naturalH;
|
|
2344
|
+
const clear = slide.clear_space_px || 0;
|
|
2345
|
+
const scale = Math.min((pw - 48) / (artW + 2 * clear), (ph - 48) / (artH + 2 * clear));
|
|
2346
|
+
const [w, h] = [artW * scale, artH * scale];
|
|
2347
|
+
const [x, y] = [px + (pw - w) / 2, py + (ph - h) / 2];
|
|
2348
|
+
draw(x, y, w, h);
|
|
2349
|
+
if (clear) {
|
|
2350
|
+
const gap = clear * scale;
|
|
2351
|
+
p.dashed(x - gap, y - gap, w + 2 * gap, h + 2 * gap, p.colors.accent);
|
|
2352
|
+
}
|
|
2353
|
+
const rx = px + pw + 32;
|
|
2354
|
+
const rw = PW - 56 - rx;
|
|
2355
|
+
let ry = py + ph;
|
|
2356
|
+
if (slide.note) ry = p.paragraph(rx, ry - 14, slide.note, rw, {
|
|
2357
|
+
size: 12,
|
|
2358
|
+
color: p.colors.muted,
|
|
2359
|
+
maxLines: 5
|
|
2360
|
+
}) - 10;
|
|
2361
|
+
for (const rule of slide.rules) {
|
|
2362
|
+
p.text(rx, ry - 14, rule.label, "Helvetica-Bold", 11, { color: p.fg });
|
|
2363
|
+
ry = p.paragraph(rx, ry - 30, rule.text, rw, {
|
|
2364
|
+
size: 11,
|
|
2365
|
+
color: p.colors.muted,
|
|
2366
|
+
maxLines: 3
|
|
2367
|
+
}) - 6;
|
|
2368
|
+
}
|
|
2369
|
+
if (clear) p.text(rx, py, "Dashed line: the clear space, kept free around the logo.", "Helvetica", 10, { color: p.colors.muted });
|
|
2370
|
+
p.end();
|
|
2371
|
+
}
|
|
2372
|
+
function drawFonts(p, slide) {
|
|
2373
|
+
p.begin(slide.title);
|
|
2374
|
+
let y = 380;
|
|
2375
|
+
for (const family of slide.families) {
|
|
2376
|
+
p.text(56, y, family.name, p.own(family.name, 400) ?? "!Helvetica-Bold", 38, { color: p.fg });
|
|
2377
|
+
let at = y - 22;
|
|
2378
|
+
const say = (text, font) => {
|
|
2379
|
+
at = p.paragraph(56, at, text, 800, {
|
|
2380
|
+
font,
|
|
2381
|
+
size: 11,
|
|
2382
|
+
color: p.colors.muted,
|
|
2383
|
+
maxLines: 2
|
|
2384
|
+
}) - 2;
|
|
2385
|
+
};
|
|
2386
|
+
say(family.stack, "Helvetica");
|
|
2387
|
+
if (family.description) say(family.description, "Helvetica");
|
|
2388
|
+
if (family.web_font) say(family.web_font, "Helvetica-Oblique");
|
|
2389
|
+
y -= familyDrop(family, p.wrap)[0];
|
|
2390
|
+
}
|
|
2391
|
+
p.note(56, 62, p.r.table.note(slide.families.map((family) => family.name)), PW - 112);
|
|
2392
|
+
p.end();
|
|
2393
|
+
}
|
|
2394
|
+
function drawTypeScale(p, slide) {
|
|
2395
|
+
p.begin(slide.title);
|
|
2396
|
+
let y = PH - 130;
|
|
2397
|
+
for (const style of slide.styles) {
|
|
2398
|
+
const pt = samplePt(style.size_px);
|
|
2399
|
+
const bold = typeof style.weight === "number" && style.weight >= 600 || style.weight === "bold" || style.weight === "semibold";
|
|
2400
|
+
const own = p.own(style.family, style.weight);
|
|
2401
|
+
p.text(56, y - pt * .8, style.name, own ?? (bold ? "!Helvetica-Bold" : "!Helvetica"), pt, { color: p.fg });
|
|
2402
|
+
const facts = [style.family || "no family", style.size_px !== null ? `${number(style.size_px)}px` : "no size"];
|
|
2403
|
+
if (style.line_height !== null) facts[1] += ` / ${String(style.line_height)}`;
|
|
2404
|
+
if (style.weight !== null) facts.push(`weight ${String(style.weight)}`);
|
|
2405
|
+
if (style.letter_spacing) facts.push(`tracking ${style.letter_spacing}`);
|
|
2406
|
+
p.text(PW - 56, y - pt * .8, facts.join(", "), "Helvetica", 10, {
|
|
2407
|
+
color: p.colors.muted,
|
|
2408
|
+
align: "right"
|
|
2409
|
+
});
|
|
2410
|
+
y -= pt * 1.3 + 22;
|
|
2411
|
+
}
|
|
2412
|
+
const families = [...new Set(slide.styles.flatMap((style) => style.family ? [style.family] : []))];
|
|
2413
|
+
const note = families.some((family) => p.r.table.has(family)) ? `Samples are drawn at half their pixel size, 14pt at least; the real size is on each line. ${p.r.table.note(families)}` : `Samples are drawn at half their pixel size, 14pt at least, and set in Helvetica; the typeface and the real size are on each line.`;
|
|
2414
|
+
p.note(56, 62, note, PW - 112);
|
|
2415
|
+
p.end();
|
|
2416
|
+
}
|
|
2417
|
+
var Painter = class extends Canvas {
|
|
2418
|
+
draw(slide) {
|
|
2419
|
+
switch (slide.kind) {
|
|
2420
|
+
case "cover": return drawCover(this, slide);
|
|
2421
|
+
case "contents": return drawContents(this, slide);
|
|
2422
|
+
case "colors": return drawColors(this, slide);
|
|
2423
|
+
case "gradients": return drawGradients(this, slide);
|
|
2424
|
+
case "fonts": return drawFonts(this, slide);
|
|
2425
|
+
case "type-scale": return drawTypeScale(this, slide);
|
|
2426
|
+
case "logo": return drawLogo(this, slide);
|
|
2427
|
+
case "page": return drawDivider(this, slide);
|
|
2428
|
+
case "guideline": return drawGuideline(this, slide);
|
|
2429
|
+
case "grid": return drawGrid(this, slide);
|
|
2430
|
+
case "favicon-view": return drawFaviconView(this, slide);
|
|
2431
|
+
case "favicon-files": return drawFaviconFiles(this, slide);
|
|
2432
|
+
case "favicon-head": return drawFaviconHead(this, slide);
|
|
2433
|
+
}
|
|
2434
|
+
}
|
|
2435
|
+
};
|
|
2436
|
+
var ORIGIN = "http://deck.local";
|
|
2437
|
+
var MAX_PASSES = 12;
|
|
2438
|
+
var RESOURCE_SECONDS = 20;
|
|
2439
|
+
var STYLE = `@page{size:${PAGE.width}pt ${PAGE.height}pt;margin:0}
|
|
2440
|
+
html,body{margin:0;padding:0}
|
|
2441
|
+
*{box-sizing:border-box}
|
|
2442
|
+
.s{position:relative;width:${PAGE.width}pt;height:${PAGE.height}pt;overflow:hidden;break-after:page}
|
|
2443
|
+
.s:last-child{break-after:auto}
|
|
2444
|
+
.t{position:absolute;white-space:pre;line-height:normal;font-variant-ligatures:none}
|
|
2445
|
+
.t i{display:inline-block;width:0;height:200pt}
|
|
2446
|
+
.r{position:absolute;display:block}
|
|
2447
|
+
.l{position:absolute;margin:0;padding:0;list-style:disc outside;white-space:pre;font-variant-ligatures:none}
|
|
2448
|
+
.l li::marker{color:var(--m)}
|
|
2449
|
+
.l i{display:inline-block;width:0;height:200pt}`;
|
|
2450
|
+
async function serveFrom(page, answer) {
|
|
2451
|
+
await page.route(`${ORIGIN}/**`, (route) => {
|
|
2452
|
+
const found = answer(new URL(route.request().url()).pathname);
|
|
2453
|
+
return found ? route.fulfill({
|
|
2454
|
+
contentType: found.type,
|
|
2455
|
+
body: found.body
|
|
2456
|
+
}) : route.fulfill({
|
|
2457
|
+
status: 404,
|
|
2458
|
+
body: ""
|
|
2459
|
+
});
|
|
2460
|
+
});
|
|
2461
|
+
}
|
|
2462
|
+
/** Draws every slide of the brand. The browser is the caller's to close. */
|
|
2463
|
+
async function drawDeck(browser, drawing) {
|
|
2464
|
+
const { brand, table } = drawing;
|
|
2465
|
+
const context = await browser.newContext({ viewport: {
|
|
2466
|
+
width: 1280,
|
|
2467
|
+
height: 720
|
|
2468
|
+
} });
|
|
2469
|
+
await context.addInitScript("globalThis.__name = (fn) => fn;");
|
|
2470
|
+
try {
|
|
2471
|
+
const measure = new Measure();
|
|
2472
|
+
const images = new Images(measure);
|
|
2473
|
+
const pages = {
|
|
2474
|
+
deck: "",
|
|
2475
|
+
probe: ""
|
|
2476
|
+
};
|
|
2477
|
+
const answer = (path) => {
|
|
2478
|
+
if (path === "/deck.html") return {
|
|
2479
|
+
type: "text/html; charset=utf-8",
|
|
2480
|
+
body: pages.deck
|
|
2481
|
+
};
|
|
2482
|
+
if (path === "/probe.html") return {
|
|
2483
|
+
type: "text/html; charset=utf-8",
|
|
2484
|
+
body: pages.probe
|
|
2485
|
+
};
|
|
2486
|
+
const image = path.startsWith("/img/") ? images.file(path) : void 0;
|
|
2487
|
+
if (image) return {
|
|
2488
|
+
type: image.mime,
|
|
2489
|
+
body: image.bytes
|
|
2490
|
+
};
|
|
2491
|
+
const font = path.startsWith("/fonts/") ? table.file(path.slice(7)) : void 0;
|
|
2492
|
+
return font && {
|
|
2493
|
+
type: font.mime,
|
|
2494
|
+
body: font.bytes
|
|
2495
|
+
};
|
|
2496
|
+
};
|
|
2497
|
+
const probe = await context.newPage();
|
|
2498
|
+
probe.setDefaultTimeout(RESOURCE_SECONDS * 1e3);
|
|
2499
|
+
await serveFrom(probe, answer);
|
|
2500
|
+
let probeRules;
|
|
2501
|
+
let slides = [];
|
|
2502
|
+
let sections = [];
|
|
2503
|
+
for (let pass = 1;; pass++) {
|
|
2504
|
+
const painter = new Painter({
|
|
2505
|
+
brand,
|
|
2506
|
+
measure,
|
|
2507
|
+
images,
|
|
2508
|
+
table,
|
|
2509
|
+
siteDir: drawing.siteDir
|
|
2510
|
+
});
|
|
2511
|
+
slides = plan(brand, drawing.favicons, painter.wrap, drawing.skip);
|
|
2512
|
+
for (const slide of slides) painter.draw(slide);
|
|
2513
|
+
sections = painter.sections;
|
|
2514
|
+
if (measure.settled) break;
|
|
2515
|
+
if (pass === MAX_PASSES) throw new Error(`the layout did not settle in ${MAX_PASSES} passes`);
|
|
2516
|
+
const rules = table.rules("/fonts");
|
|
2517
|
+
if (rules !== probeRules) {
|
|
2518
|
+
pages.probe = `<!doctype html><meta charset="utf-8"><style>${rules}</style><body>`;
|
|
2519
|
+
await probe.goto(`${ORIGIN}/probe.html`, { waitUntil: "load" });
|
|
2520
|
+
probeRules = rules;
|
|
2521
|
+
}
|
|
2522
|
+
await measure.fill(probe, ORIGIN);
|
|
2523
|
+
}
|
|
2524
|
+
await probe.close();
|
|
2525
|
+
pages.deck = `<!doctype html><meta charset="utf-8"><title>${brand.brand.title.replace(/</g, "<")}</title><style>${table.rules("/fonts")}\n${STYLE}</style><body>${sections.join("")}`;
|
|
2526
|
+
const page = await context.newPage();
|
|
2527
|
+
page.setDefaultTimeout(RESOURCE_SECONDS * 1e3);
|
|
2528
|
+
await serveFrom(page, answer);
|
|
2529
|
+
await page.goto(`${ORIGIN}/deck.html`, { waitUntil: "load" });
|
|
2530
|
+
await page.evaluate(async () => {
|
|
2531
|
+
await document.fonts.ready;
|
|
2532
|
+
await Promise.all([...document.images].map((image) => image.decode().catch(() => void 0)));
|
|
2533
|
+
});
|
|
2534
|
+
const printed = await page.pdf({
|
|
2535
|
+
width: `${PAGE.width * 4 / 3}px`,
|
|
2536
|
+
height: `${PAGE.height * 4 / 3}px`,
|
|
2537
|
+
printBackground: true,
|
|
2538
|
+
preferCSSPageSize: true
|
|
2539
|
+
});
|
|
2540
|
+
const pdf = await pdf_lib.PDFDocument.load(printed);
|
|
2541
|
+
const count = pdf.getPageCount();
|
|
2542
|
+
pdf.setTitle(brand.brand.title);
|
|
2543
|
+
pdf.setCreator("blazon.brand-deck");
|
|
2544
|
+
pdf.setProducer("blazon.brand-deck");
|
|
2545
|
+
pdf.setCreationDate(/* @__PURE__ */ new Date(0));
|
|
2546
|
+
pdf.setModificationDate(/* @__PURE__ */ new Date(0));
|
|
2547
|
+
return {
|
|
2548
|
+
pdf: Buffer.from(await pdf.save({ useObjectStreams: false })),
|
|
2549
|
+
slides,
|
|
2550
|
+
pages: count
|
|
2551
|
+
};
|
|
2552
|
+
} finally {
|
|
2553
|
+
await context.close();
|
|
2554
|
+
}
|
|
2555
|
+
}
|
|
2556
|
+
var say = (line) => void process.stderr.write(`${line}\n`);
|
|
2557
|
+
/** The fonts the brand's own text can be set in: the folders given and named by BLAZON_DECK_FONTS, then the config's */
|
|
2558
|
+
function fontsFor(brand, folders) {
|
|
2559
|
+
const table = FontTable.scan(folders);
|
|
2560
|
+
table.addSheets(brand.theme.fonts);
|
|
2561
|
+
for (const [file, why] of table.skipped) say(`font not used: ${file}: ${why}`);
|
|
2562
|
+
return table;
|
|
2563
|
+
}
|
|
2564
|
+
async function draw(brand, siteDir, favicons, table, skip) {
|
|
2565
|
+
const browser = await launch(process.env);
|
|
2566
|
+
try {
|
|
2567
|
+
return await drawDeck(browser, {
|
|
2568
|
+
brand,
|
|
2569
|
+
siteDir,
|
|
2570
|
+
favicons,
|
|
2571
|
+
table,
|
|
2572
|
+
skip
|
|
2573
|
+
});
|
|
2574
|
+
} finally {
|
|
2575
|
+
await browser.close();
|
|
2576
|
+
}
|
|
2577
|
+
}
|
|
2578
|
+
/** Written once, whole, after the browser is done: a call that ends earlier leaves nothing behind */
|
|
2579
|
+
function write(file, pdf) {
|
|
2580
|
+
node_fs.default.writeFileSync(`${file}.part`, pdf);
|
|
2581
|
+
node_fs.default.renameSync(`${file}.part`, file);
|
|
2582
|
+
}
|
|
2583
|
+
async function build(text) {
|
|
2584
|
+
const job = jobFor(text);
|
|
2585
|
+
const brand = readBrand(job.brand);
|
|
2586
|
+
const table = fontsFor(brand, fontFolders(process.env.BLAZON_DECK_FONTS));
|
|
2587
|
+
const { skip, findings } = readOptions(job.options, brand);
|
|
2588
|
+
for (const [file, why] of table.skipped) findings.push({
|
|
2589
|
+
code: `${NAME}/font-not-used`,
|
|
2590
|
+
severity: "warning",
|
|
2591
|
+
path: file,
|
|
2592
|
+
message: `the font file is not used: ${why}`
|
|
2593
|
+
});
|
|
2594
|
+
const favicons = readFavicons(node_path.default.join(node_path.default.dirname(node_path.default.resolve(job.outDir)), "blazon.favicons"), brand, (message) => {
|
|
2595
|
+
say(message);
|
|
2596
|
+
findings.push({
|
|
2597
|
+
code: `${NAME}/favicons-not-drawn`,
|
|
2598
|
+
severity: "warning",
|
|
2599
|
+
path: "blazon.favicons/favicons.json",
|
|
2600
|
+
message
|
|
2601
|
+
});
|
|
2602
|
+
});
|
|
2603
|
+
const deck = await draw(brand, job.siteDir, favicons, table, skip);
|
|
2604
|
+
if (deck.pages !== deck.slides.length) findings.push({
|
|
2605
|
+
code: `${NAME}/page-count`,
|
|
2606
|
+
severity: "warning",
|
|
2607
|
+
path: "brand-deck.pdf",
|
|
2608
|
+
message: `the deck planned ${deck.slides.length} slides, and the PDF has ${deck.pages} pages`
|
|
2609
|
+
});
|
|
2610
|
+
write(node_path.default.join(job.outDir, "brand-deck.pdf"), deck.pdf);
|
|
2611
|
+
return { findings };
|
|
2612
|
+
}
|
|
2613
|
+
var USAGE = "usage: blazon-blazon.brand-deck BRAND.json [-o deck.pdf] [--favicons DIR] [--skip CATEGORY]... [--fonts DIR]...";
|
|
2614
|
+
/** The command line. Exit 0 on success; 1 when a file the deck needs cannot be read (nothing is written); 2 when the input is not a blazon brand, or is not given. */
|
|
2615
|
+
async function cli(args) {
|
|
2616
|
+
let brandFile;
|
|
2617
|
+
let output = "brand-deck.pdf";
|
|
2618
|
+
let favicons;
|
|
2619
|
+
const skip = [];
|
|
2620
|
+
const fonts = [];
|
|
2621
|
+
for (let i = 0; i < args.length; i++) {
|
|
2622
|
+
const arg = args[i];
|
|
2623
|
+
const flag = (names) => names.includes(arg) ? args[++i] ?? "" : void 0;
|
|
2624
|
+
const value = flag(["-o", "--output"]) ?? flag(["--favicons"]) ?? flag(["--skip"]) ?? flag(["--fonts"]);
|
|
2625
|
+
if (value !== void 0) {
|
|
2626
|
+
if (value === "") {
|
|
2627
|
+
say(`${arg} needs a value\n${USAGE}`);
|
|
2628
|
+
return 2;
|
|
2629
|
+
}
|
|
2630
|
+
if (arg === "-o" || arg === "--output") output = value;
|
|
2631
|
+
else if (arg === "--favicons") favicons = value;
|
|
2632
|
+
else if (arg === "--skip") skip.push(value);
|
|
2633
|
+
else fonts.push(value);
|
|
2634
|
+
} else if (arg.startsWith("-")) {
|
|
2635
|
+
say(`${arg} is not an option\n${USAGE}`);
|
|
2636
|
+
return 2;
|
|
2637
|
+
} else if (brandFile === void 0) brandFile = arg;
|
|
2638
|
+
else {
|
|
2639
|
+
say(`more than one brand.json: ${brandFile} and ${arg}\n${USAGE}`);
|
|
2640
|
+
return 2;
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
if (brandFile === void 0) {
|
|
2644
|
+
say(USAGE);
|
|
2645
|
+
return 2;
|
|
2646
|
+
}
|
|
2647
|
+
const folders = [...fonts, ...fontFolders(process.env.BLAZON_DECK_FONTS)];
|
|
2648
|
+
for (const folder of folders) if (!node_fs.default.statSync(folder, { throwIfNoEntry: false })?.isDirectory()) {
|
|
2649
|
+
say(`font folder ${folder} does not exist`);
|
|
2650
|
+
return 2;
|
|
2651
|
+
}
|
|
2652
|
+
let brand;
|
|
2653
|
+
try {
|
|
2654
|
+
brand = readBrand(JSON.parse(node_fs.default.readFileSync(brandFile, "utf-8")), brandFile);
|
|
2655
|
+
} catch (error) {
|
|
2656
|
+
say(error instanceof Cannot ? error.message : `cannot read ${brandFile}: ${error.message}`);
|
|
2657
|
+
return 2;
|
|
2658
|
+
}
|
|
2659
|
+
const { skip: left, findings } = readOptions({ skip }, brand);
|
|
2660
|
+
for (const finding of findings) say(finding.message);
|
|
2661
|
+
try {
|
|
2662
|
+
const table = fontsFor(brand, folders);
|
|
2663
|
+
const deck = await draw(brand, node_path.default.dirname(node_path.default.resolve(brandFile)), favicons ? readFavicons(favicons, brand, say) : null, table, left);
|
|
2664
|
+
write(output, deck.pdf);
|
|
2665
|
+
process.stdout.write(`wrote ${output} (${deck.slides.length} slides)\n`);
|
|
2666
|
+
return 0;
|
|
2667
|
+
} catch (error) {
|
|
2668
|
+
if (!(error instanceof DeckError || error instanceof Cannot)) throw error;
|
|
2669
|
+
say(error.message);
|
|
2670
|
+
return 1;
|
|
2671
|
+
}
|
|
2672
|
+
}
|
|
2673
|
+
async function main(argv) {
|
|
2674
|
+
if (argv[0] === "--blazon-manifest") {
|
|
2675
|
+
process.stdout.write(`${JSON.stringify(MANIFEST)}\n`);
|
|
2676
|
+
return 0;
|
|
2677
|
+
}
|
|
2678
|
+
if (argv.length > 0) try {
|
|
2679
|
+
return await cli(argv);
|
|
2680
|
+
} catch (error) {
|
|
2681
|
+
say(`the browser could not draw the deck: ${String(error.message ?? error).split("\n")[0]}`);
|
|
2682
|
+
return 1;
|
|
2683
|
+
}
|
|
2684
|
+
try {
|
|
2685
|
+
process.stdout.write(`${JSON.stringify(await build(node_fs.default.readFileSync(0, "utf-8")))}\n`);
|
|
2686
|
+
return 0;
|
|
2687
|
+
} catch (error) {
|
|
2688
|
+
const reason = error instanceof Cannot || error instanceof DeckError ? error.message : `the browser could not draw the deck: ${String(error.message ?? error).split("\n")[0].slice(0, 500)}`;
|
|
2689
|
+
process.stdout.write(`${reason}\n`);
|
|
2690
|
+
return 2;
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
main(process.argv.slice(2)).then((code) => {
|
|
2694
|
+
process.exitCode = code;
|
|
2695
|
+
});
|