@antheo/morph 0.0.0-stage → 0.3.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 +266 -2
- package/SKILL.md +61 -0
- package/dist/ai/cli-provider.d.ts +80 -0
- package/dist/ai/cli-provider.js +250 -0
- package/dist/ai/gate.d.ts +39 -0
- package/dist/ai/gate.js +124 -0
- package/dist/ai/provider.d.ts +36 -0
- package/dist/ai/provider.js +168 -0
- package/dist/ai/repair.d.ts +90 -0
- package/dist/ai/repair.js +172 -0
- package/dist/analyzer/deps.d.ts +30 -0
- package/dist/analyzer/deps.js +265 -0
- package/dist/analyzer/manifest.d.ts +5 -0
- package/dist/analyzer/manifest.js +119 -0
- package/dist/analyzer/parse.d.ts +21 -0
- package/dist/analyzer/parse.js +29 -0
- package/dist/batch-worker.d.ts +16 -0
- package/dist/batch-worker.js +10 -0
- package/dist/batch.d.ts +26 -0
- package/dist/batch.js +227 -0
- package/dist/bridge/index.d.ts +26 -0
- package/dist/bridge/index.js +138 -0
- package/dist/bridge/props.d.ts +56 -0
- package/dist/bridge/props.js +191 -0
- package/dist/bridge/wrappers.d.ts +24 -0
- package/dist/bridge/wrappers.js +276 -0
- package/dist/cli/format.d.ts +7 -0
- package/dist/cli/format.js +30 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +492 -0
- package/dist/fonts/carry.d.ts +34 -0
- package/dist/fonts/carry.js +113 -0
- package/dist/fonts/fallback.d.ts +11 -0
- package/dist/fonts/fallback.js +21 -0
- package/dist/fonts/google.d.ts +65 -0
- package/dist/fonts/google.js +343 -0
- package/dist/fonts/index.d.ts +27 -0
- package/dist/fonts/index.js +48 -0
- package/dist/fonts/local.d.ts +46 -0
- package/dist/fonts/local.js +150 -0
- package/dist/fonts/sfnt.d.ts +19 -0
- package/dist/fonts/sfnt.js +174 -0
- package/dist/fonts/shim.d.ts +14 -0
- package/dist/fonts/shim.js +96 -0
- package/dist/gate.d.ts +105 -0
- package/dist/gate.js +157 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.js +74 -0
- package/dist/ir/annotate.d.ts +16 -0
- package/dist/ir/annotate.js +145 -0
- package/dist/ir/as-child.d.ts +18 -0
- package/dist/ir/as-child.js +239 -0
- package/dist/ir/compounds.d.ts +27 -0
- package/dist/ir/compounds.js +183 -0
- package/dist/ir/contexts.d.ts +26 -0
- package/dist/ir/contexts.js +185 -0
- package/dist/ir/dom.d.ts +11 -0
- package/dist/ir/dom.js +60 -0
- package/dist/ir/effect-returns.d.ts +10 -0
- package/dist/ir/effect-returns.js +25 -0
- package/dist/ir/extract-ui-types.d.ts +33 -0
- package/dist/ir/extract-ui-types.js +224 -0
- package/dist/ir/extract-ui.d.ts +34 -0
- package/dist/ir/extract-ui.js +567 -0
- package/dist/ir/falsy.d.ts +13 -0
- package/dist/ir/falsy.js +66 -0
- package/dist/ir/forward-refs.d.ts +11 -0
- package/dist/ir/forward-refs.js +155 -0
- package/dist/ir/fragment-source.d.ts +4 -0
- package/dist/ir/fragment-source.js +13 -0
- package/dist/ir/fragments.d.ts +32 -0
- package/dist/ir/fragments.js +192 -0
- package/dist/ir/helper-snippets.d.ts +30 -0
- package/dist/ir/helper-snippets.js +550 -0
- package/dist/ir/latest-refs.d.ts +11 -0
- package/dist/ir/latest-refs.js +187 -0
- package/dist/ir/live-args.d.ts +26 -0
- package/dist/ir/live-args.js +335 -0
- package/dist/ir/lower.d.ts +83 -0
- package/dist/ir/lower.js +6016 -0
- package/dist/ir/markup-values.d.ts +16 -0
- package/dist/ir/markup-values.js +188 -0
- package/dist/ir/model.d.ts +605 -0
- package/dist/ir/model.js +1 -0
- package/dist/ir/oracle.d.ts +91 -0
- package/dist/ir/oracle.js +610 -0
- package/dist/ir/radix.d.ts +122 -0
- package/dist/ir/radix.js +344 -0
- package/dist/ir/rename.d.ts +15 -0
- package/dist/ir/rename.js +151 -0
- package/dist/ir/render-props.d.ts +31 -0
- package/dist/ir/render-props.js +67 -0
- package/dist/ir/rewrite.d.ts +44 -0
- package/dist/ir/rewrite.js +381 -0
- package/dist/ir/running-index.d.ts +11 -0
- package/dist/ir/running-index.js +217 -0
- package/dist/ir/snapshots.d.ts +12 -0
- package/dist/ir/snapshots.js +140 -0
- package/dist/ir/style.d.ts +19 -0
- package/dist/ir/style.js +76 -0
- package/dist/ir/types.d.ts +42 -0
- package/dist/ir/types.js +271 -0
- package/dist/ir/walk.d.ts +11 -0
- package/dist/ir/walk.js +18 -0
- package/dist/mcp/server.d.ts +81 -0
- package/dist/mcp/server.js +518 -0
- package/dist/pipeline.d.ts +26 -0
- package/dist/pipeline.js +750 -0
- package/dist/registry/add.d.ts +91 -0
- package/dist/registry/add.js +273 -0
- package/dist/registry/fetch.d.ts +40 -0
- package/dist/registry/fetch.js +186 -0
- package/dist/registry/ip.d.ts +18 -0
- package/dist/registry/ip.js +153 -0
- package/dist/registry/item.d.ts +39 -0
- package/dist/registry/item.js +131 -0
- package/dist/registry/load.d.ts +35 -0
- package/dist/registry/load.js +106 -0
- package/dist/registry/paths.d.ts +8 -0
- package/dist/registry/paths.js +43 -0
- package/dist/registry/publish.d.ts +119 -0
- package/dist/registry/publish.js +439 -0
- package/dist/targets/angular/bank/bank.d.ts +39 -0
- package/dist/targets/angular/bank/bank.js +61 -0
- package/dist/targets/angular/bank/helpers.d.ts +64 -0
- package/dist/targets/angular/bank/helpers.js +246 -0
- package/dist/targets/angular/bank/kept.d.ts +98 -0
- package/dist/targets/angular/bank/kept.js +791 -0
- package/dist/targets/angular/bank/plan-helpers.d.ts +17 -0
- package/dist/targets/angular/bank/plan-helpers.js +286 -0
- package/dist/targets/angular/bank/plan.d.ts +22 -0
- package/dist/targets/angular/bank/plan.js +152 -0
- package/dist/targets/angular/bank/receivers.d.ts +66 -0
- package/dist/targets/angular/bank/receivers.js +293 -0
- package/dist/targets/angular/bank/runtime.d.ts +14 -0
- package/dist/targets/angular/bank/runtime.js +152 -0
- package/dist/targets/angular/controlled.d.ts +7 -0
- package/dist/targets/angular/controlled.js +37 -0
- package/dist/targets/angular/dynamic-tags.d.ts +34 -0
- package/dist/targets/angular/dynamic-tags.js +192 -0
- package/dist/targets/angular/emit.d.ts +41 -0
- package/dist/targets/angular/emit.js +5970 -0
- package/dist/targets/angular/exports.d.ts +48 -0
- package/dist/targets/angular/exports.js +243 -0
- package/dist/targets/angular/helpers.d.ts +15 -0
- package/dist/targets/angular/helpers.js +33 -0
- package/dist/targets/angular/host-boundary.d.ts +5 -0
- package/dist/targets/angular/host-boundary.js +166 -0
- package/dist/targets/angular/host-form.d.ts +150 -0
- package/dist/targets/angular/host-form.js +727 -0
- package/dist/targets/angular/markup-values.d.ts +58 -0
- package/dist/targets/angular/markup-values.js +661 -0
- package/dist/targets/angular/motion-directive.d.ts +12 -0
- package/dist/targets/angular/motion-directive.js +257 -0
- package/dist/targets/angular/motion-hooks.d.ts +73 -0
- package/dist/targets/angular/motion-hooks.js +293 -0
- package/dist/targets/angular/motion-layout.d.ts +14 -0
- package/dist/targets/angular/motion-layout.js +74 -0
- package/dist/targets/angular/motion-templates.d.ts +10 -0
- package/dist/targets/angular/motion-templates.js +65 -0
- package/dist/targets/angular/motion.d.ts +57 -0
- package/dist/targets/angular/motion.js +202 -0
- package/dist/targets/angular/narrowing.d.ts +24 -0
- package/dist/targets/angular/narrowing.js +205 -0
- package/dist/targets/angular/ngc.d.ts +23 -0
- package/dist/targets/angular/ngc.js +134 -0
- package/dist/targets/angular/passed-handle.d.ts +39 -0
- package/dist/targets/angular/passed-handle.js +154 -0
- package/dist/targets/angular/projected.d.ts +9 -0
- package/dist/targets/angular/projected.js +63 -0
- package/dist/targets/angular/radix/cores/alert-dialog.d.ts +13 -0
- package/dist/targets/angular/radix/cores/alert-dialog.js +388 -0
- package/dist/targets/angular/radix/cores/index.d.ts +17 -0
- package/dist/targets/angular/radix/cores/index.js +50 -0
- package/dist/targets/angular/radix/cores/slider.d.ts +8 -0
- package/dist/targets/angular/radix/cores/slider.js +202 -0
- package/dist/targets/angular/radix/index.d.ts +21 -0
- package/dist/targets/angular/radix/index.js +35 -0
- package/dist/targets/angular/radix/packages.d.ts +3 -0
- package/dist/targets/angular/radix/packages.js +558 -0
- package/dist/targets/angular/radix/part.d.ts +236 -0
- package/dist/targets/angular/radix/part.js +71 -0
- package/dist/targets/angular/radix/prepare.d.ts +66 -0
- package/dist/targets/angular/radix/prepare.js +548 -0
- package/dist/targets/angular/radix/template.d.ts +43 -0
- package/dist/targets/angular/radix/template.js +172 -0
- package/dist/targets/angular/refs.d.ts +68 -0
- package/dist/targets/angular/refs.js +443 -0
- package/dist/targets/angular/slots.d.ts +22 -0
- package/dist/targets/angular/slots.js +60 -0
- package/dist/targets/angular/source-types.d.ts +10 -0
- package/dist/targets/angular/source-types.js +45 -0
- package/dist/targets/angular/spread-forward.d.ts +24 -0
- package/dist/targets/angular/spread-forward.js +72 -0
- package/dist/targets/angular/spread.d.ts +32 -0
- package/dist/targets/angular/spread.js +182 -0
- package/dist/targets/angular/svg-hosts.d.ts +25 -0
- package/dist/targets/angular/svg-hosts.js +107 -0
- package/dist/targets/angular/template-expr.d.ts +36 -0
- package/dist/targets/angular/template-expr.js +287 -0
- package/dist/targets/angular/types.d.ts +9 -0
- package/dist/targets/angular/types.js +63 -0
- package/dist/targets/angular/walk.d.ts +11 -0
- package/dist/targets/angular/walk.js +26 -0
- package/dist/targets/react-native/emit.d.ts +14 -0
- package/dist/targets/react-native/emit.js +585 -0
- package/dist/targets/react-native/fidelity.d.ts +5 -0
- package/dist/targets/react-native/fidelity.js +43 -0
- package/dist/targets/react-native/motion.d.ts +10 -0
- package/dist/targets/react-native/motion.js +290 -0
- package/dist/targets/react-native/skia.d.ts +30 -0
- package/dist/targets/react-native/skia.js +358 -0
- package/dist/targets/shared/context.d.ts +47 -0
- package/dist/targets/shared/context.js +195 -0
- package/dist/targets/shared/foreign.d.ts +10 -0
- package/dist/targets/shared/foreign.js +72 -0
- package/dist/targets/shared/fragments.d.ts +21 -0
- package/dist/targets/shared/fragments.js +309 -0
- package/dist/targets/shared/handles.d.ts +65 -0
- package/dist/targets/shared/handles.js +299 -0
- package/dist/targets/shared/inline.d.ts +53 -0
- package/dist/targets/shared/inline.js +524 -0
- package/dist/targets/shared/layout.d.ts +70 -0
- package/dist/targets/shared/layout.js +224 -0
- package/dist/targets/shared/markup.d.ts +26 -0
- package/dist/targets/shared/markup.js +65 -0
- package/dist/targets/shared/module.d.ts +84 -0
- package/dist/targets/shared/module.js +468 -0
- package/dist/targets/shared/motion-hooks.d.ts +37 -0
- package/dist/targets/shared/motion-hooks.js +87 -0
- package/dist/targets/shared/motion-layout.d.ts +70 -0
- package/dist/targets/shared/motion-layout.js +392 -0
- package/dist/targets/shared/portal.d.ts +10 -0
- package/dist/targets/shared/portal.js +23 -0
- package/dist/targets/shared/prop-writes.d.ts +11 -0
- package/dist/targets/shared/prop-writes.js +32 -0
- package/dist/targets/shared/prune.d.ts +54 -0
- package/dist/targets/shared/prune.js +405 -0
- package/dist/targets/shared/react-libs.d.ts +25 -0
- package/dist/targets/shared/react-libs.js +142 -0
- package/dist/targets/shared/react-types.d.ts +16 -0
- package/dist/targets/shared/react-types.js +374 -0
- package/dist/targets/shared/react-values.d.ts +20 -0
- package/dist/targets/shared/react-values.js +145 -0
- package/dist/targets/shared/ref-callback.d.ts +16 -0
- package/dist/targets/shared/ref-callback.js +114 -0
- package/dist/targets/shared/script.d.ts +65 -0
- package/dist/targets/shared/script.js +406 -0
- package/dist/targets/shared/unused.d.ts +12 -0
- package/dist/targets/shared/unused.js +146 -0
- package/dist/targets/svelte/dom-spread.d.ts +27 -0
- package/dist/targets/svelte/dom-spread.js +146 -0
- package/dist/targets/svelte/emit.d.ts +15 -0
- package/dist/targets/svelte/emit.js +3784 -0
- package/dist/targets/svelte/handle-branches.d.ts +22 -0
- package/dist/targets/svelte/handle-branches.js +146 -0
- package/dist/targets/svelte/html-keys.d.ts +9 -0
- package/dist/targets/svelte/html-keys.js +40 -0
- package/dist/targets/svelte/markup-data/data.d.ts +51 -0
- package/dist/targets/svelte/markup-data/data.js +305 -0
- package/dist/targets/svelte/markup-data/helper.d.ts +12 -0
- package/dist/targets/svelte/markup-data/helper.js +81 -0
- package/dist/targets/svelte/markup-data/module-data.d.ts +21 -0
- package/dist/targets/svelte/markup-data/module-data.js +473 -0
- package/dist/targets/svelte/markup-data/sites.d.ts +52 -0
- package/dist/targets/svelte/markup-data/sites.js +303 -0
- package/dist/targets/svelte/motion-layout.d.ts +13 -0
- package/dist/targets/svelte/motion-layout.js +70 -0
- package/dist/targets/svelte/motion-table.d.ts +14 -0
- package/dist/targets/svelte/motion-table.js +308 -0
- package/dist/targets/svelte/motion.d.ts +46 -0
- package/dist/targets/svelte/motion.js +405 -0
- package/dist/targets/svelte/presence.d.ts +71 -0
- package/dist/targets/svelte/presence.js +318 -0
- package/dist/targets/svelte/radix/accordion.d.ts +9 -0
- package/dist/targets/svelte/radix/accordion.js +24 -0
- package/dist/targets/svelte/radix/aspect-ratio.d.ts +6 -0
- package/dist/targets/svelte/radix/aspect-ratio.js +8 -0
- package/dist/targets/svelte/radix/avatar.d.ts +6 -0
- package/dist/targets/svelte/radix/avatar.js +10 -0
- package/dist/targets/svelte/radix/checkbox.d.ts +10 -0
- package/dist/targets/svelte/radix/checkbox.js +24 -0
- package/dist/targets/svelte/radix/collapsible.d.ts +7 -0
- package/dist/targets/svelte/radix/collapsible.js +16 -0
- package/dist/targets/svelte/radix/context-menu.d.ts +8 -0
- package/dist/targets/svelte/radix/context-menu.js +49 -0
- package/dist/targets/svelte/radix/cores/alert-dialog.d.ts +17 -0
- package/dist/targets/svelte/radix/cores/alert-dialog.js +449 -0
- package/dist/targets/svelte/radix/cores/collapsible.d.ts +12 -0
- package/dist/targets/svelte/radix/cores/collapsible.js +214 -0
- package/dist/targets/svelte/radix/cores/core.d.ts +32 -0
- package/dist/targets/svelte/radix/cores/core.js +80 -0
- package/dist/targets/svelte/radix/cores/direction.d.ts +10 -0
- package/dist/targets/svelte/radix/cores/direction.js +64 -0
- package/dist/targets/svelte/radix/cores/index.d.ts +19 -0
- package/dist/targets/svelte/radix/cores/index.js +85 -0
- package/dist/targets/svelte/radix/cores/modal-layer.d.ts +11 -0
- package/dist/targets/svelte/radix/cores/modal-layer.js +244 -0
- package/dist/targets/svelte/radix/cores/presence.d.ts +12 -0
- package/dist/targets/svelte/radix/cores/presence.js +129 -0
- package/dist/targets/svelte/radix/cores/slider-logic.d.ts +10 -0
- package/dist/targets/svelte/radix/cores/slider-logic.js +287 -0
- package/dist/targets/svelte/radix/cores/slider.d.ts +13 -0
- package/dist/targets/svelte/radix/cores/slider.js +267 -0
- package/dist/targets/svelte/radix/dialog.d.ts +8 -0
- package/dist/targets/svelte/radix/dialog.js +20 -0
- package/dist/targets/svelte/radix/dropdown-menu.d.ts +9 -0
- package/dist/targets/svelte/radix/dropdown-menu.js +38 -0
- package/dist/targets/svelte/radix/emit.d.ts +12 -0
- package/dist/targets/svelte/radix/emit.js +1339 -0
- package/dist/targets/svelte/radix/hover-card.d.ts +7 -0
- package/dist/targets/svelte/radix/hover-card.js +22 -0
- package/dist/targets/svelte/radix/index.d.ts +12 -0
- package/dist/targets/svelte/radix/index.js +28 -0
- package/dist/targets/svelte/radix/label.d.ts +3 -0
- package/dist/targets/svelte/radix/label.js +5 -0
- package/dist/targets/svelte/radix/menubar.d.ts +7 -0
- package/dist/targets/svelte/radix/menubar.js +34 -0
- package/dist/targets/svelte/radix/navigation-menu.d.ts +8 -0
- package/dist/targets/svelte/radix/navigation-menu.js +25 -0
- package/dist/targets/svelte/radix/packages.d.ts +34 -0
- package/dist/targets/svelte/radix/packages.js +100 -0
- package/dist/targets/svelte/radix/part.d.ts +161 -0
- package/dist/targets/svelte/radix/part.js +85 -0
- package/dist/targets/svelte/radix/popover.d.ts +7 -0
- package/dist/targets/svelte/radix/popover.js +15 -0
- package/dist/targets/svelte/radix/progress.d.ts +11 -0
- package/dist/targets/svelte/radix/progress.js +27 -0
- package/dist/targets/svelte/radix/radio-group.d.ts +9 -0
- package/dist/targets/svelte/radix/radio-group.js +26 -0
- package/dist/targets/svelte/radix/scroll-area.d.ts +7 -0
- package/dist/targets/svelte/radix/scroll-area.js +19 -0
- package/dist/targets/svelte/radix/select.d.ts +13 -0
- package/dist/targets/svelte/radix/select.js +81 -0
- package/dist/targets/svelte/radix/separator.d.ts +3 -0
- package/dist/targets/svelte/radix/separator.js +5 -0
- package/dist/targets/svelte/radix/slider.d.ts +6 -0
- package/dist/targets/svelte/radix/slider.js +8 -0
- package/dist/targets/svelte/radix/switch.d.ts +6 -0
- package/dist/targets/svelte/radix/switch.js +10 -0
- package/dist/targets/svelte/radix/tabs.d.ts +8 -0
- package/dist/targets/svelte/radix/tabs.js +15 -0
- package/dist/targets/svelte/radix/toggle-group.d.ts +9 -0
- package/dist/targets/svelte/radix/toggle-group.js +17 -0
- package/dist/targets/svelte/radix/toggle.d.ts +6 -0
- package/dist/targets/svelte/radix/toggle.js +9 -0
- package/dist/targets/svelte/radix/tooltip.d.ts +6 -0
- package/dist/targets/svelte/radix/tooltip.js +24 -0
- package/dist/targets/svelte/strip.d.ts +2 -0
- package/dist/targets/svelte/strip.js +5 -0
- package/dist/targets/vue/emit.d.ts +15 -0
- package/dist/targets/vue/emit.js +4092 -0
- package/dist/targets/vue/events.d.ts +11 -0
- package/dist/targets/vue/events.js +13 -0
- package/dist/targets/vue/module-builders.d.ts +28 -0
- package/dist/targets/vue/module-builders.js +258 -0
- package/dist/targets/vue/motion-layout.d.ts +19 -0
- package/dist/targets/vue/motion-layout.js +79 -0
- package/dist/targets/vue/motion.d.ts +12 -0
- package/dist/targets/vue/motion.js +46 -0
- package/dist/targets/vue/radix/accordion.d.ts +3 -0
- package/dist/targets/vue/radix/accordion.js +12 -0
- package/dist/targets/vue/radix/alert-dialog.d.ts +6 -0
- package/dist/targets/vue/radix/alert-dialog.js +18 -0
- package/dist/targets/vue/radix/aspect-ratio.d.ts +6 -0
- package/dist/targets/vue/radix/aspect-ratio.js +8 -0
- package/dist/targets/vue/radix/avatar.d.ts +3 -0
- package/dist/targets/vue/radix/avatar.js +7 -0
- package/dist/targets/vue/radix/checkbox.d.ts +3 -0
- package/dist/targets/vue/radix/checkbox.js +9 -0
- package/dist/targets/vue/radix/collapsible.d.ts +7 -0
- package/dist/targets/vue/radix/collapsible.js +11 -0
- package/dist/targets/vue/radix/context-menu.d.ts +3 -0
- package/dist/targets/vue/radix/context-menu.js +30 -0
- package/dist/targets/vue/radix/dialog.d.ts +3 -0
- package/dist/targets/vue/radix/dialog.js +12 -0
- package/dist/targets/vue/radix/direction.d.ts +7 -0
- package/dist/targets/vue/radix/direction.js +9 -0
- package/dist/targets/vue/radix/dropdown-menu.d.ts +3 -0
- package/dist/targets/vue/radix/dropdown-menu.js +29 -0
- package/dist/targets/vue/radix/hover-card.d.ts +3 -0
- package/dist/targets/vue/radix/hover-card.js +11 -0
- package/dist/targets/vue/radix/index.d.ts +65 -0
- package/dist/targets/vue/radix/index.js +225 -0
- package/dist/targets/vue/radix/label.d.ts +3 -0
- package/dist/targets/vue/radix/label.js +5 -0
- package/dist/targets/vue/radix/menubar.d.ts +6 -0
- package/dist/targets/vue/radix/menubar.js +29 -0
- package/dist/targets/vue/radix/navigation-menu.d.ts +6 -0
- package/dist/targets/vue/radix/navigation-menu.js +21 -0
- package/dist/targets/vue/radix/part.d.ts +41 -0
- package/dist/targets/vue/radix/part.js +46 -0
- package/dist/targets/vue/radix/popover.d.ts +3 -0
- package/dist/targets/vue/radix/popover.js +11 -0
- package/dist/targets/vue/radix/progress.d.ts +3 -0
- package/dist/targets/vue/radix/progress.js +6 -0
- package/dist/targets/vue/radix/radio-group.d.ts +3 -0
- package/dist/targets/vue/radix/radio-group.js +10 -0
- package/dist/targets/vue/radix/scroll-area.d.ts +3 -0
- package/dist/targets/vue/radix/scroll-area.js +11 -0
- package/dist/targets/vue/radix/select.d.ts +3 -0
- package/dist/targets/vue/radix/select.js +29 -0
- package/dist/targets/vue/radix/separator.d.ts +3 -0
- package/dist/targets/vue/radix/separator.js +5 -0
- package/dist/targets/vue/radix/slider.d.ts +3 -0
- package/dist/targets/vue/radix/slider.js +13 -0
- package/dist/targets/vue/radix/switch.d.ts +3 -0
- package/dist/targets/vue/radix/switch.js +9 -0
- package/dist/targets/vue/radix/tabs.d.ts +3 -0
- package/dist/targets/vue/radix/tabs.js +12 -0
- package/dist/targets/vue/radix/toggle-group.d.ts +3 -0
- package/dist/targets/vue/radix/toggle-group.js +10 -0
- package/dist/targets/vue/radix/toggle.d.ts +3 -0
- package/dist/targets/vue/radix/toggle.js +8 -0
- package/dist/targets/vue/radix/tooltip.d.ts +3 -0
- package/dist/targets/vue/radix/tooltip.js +14 -0
- package/dist/targets/vue/render-fn/h.d.ts +52 -0
- package/dist/targets/vue/render-fn/h.js +442 -0
- package/dist/targets/vue/render-fn.d.ts +21 -0
- package/dist/targets/vue/render-fn.js +357 -0
- package/dist/targets/vue/slot.d.ts +9 -0
- package/dist/targets/vue/slot.js +57 -0
- package/dist/typecheck/host.d.ts +45 -0
- package/dist/typecheck/host.js +309 -0
- package/dist/typecheck/index.d.ts +16 -0
- package/dist/typecheck/index.js +17 -0
- package/dist/typecheck/lucide.d.ts +8 -0
- package/dist/typecheck/lucide.js +45 -0
- package/dist/typecheck/sourcemap.d.ts +9 -0
- package/dist/typecheck/sourcemap.js +54 -0
- package/dist/typecheck/svelte.d.ts +9 -0
- package/dist/typecheck/svelte.js +116 -0
- package/dist/typecheck/vue.d.ts +8 -0
- package/dist/typecheck/vue.js +78 -0
- package/dist/types.d.ts +446 -0
- package/dist/types.js +11 -0
- package/dist/utils/cleanup.d.ts +32 -0
- package/dist/utils/cleanup.js +119 -0
- package/dist/utils/errors.d.ts +7 -0
- package/dist/utils/errors.js +15 -0
- package/dist/utils/fs-safe.d.ts +14 -0
- package/dist/utils/fs-safe.js +64 -0
- package/dist/validate.d.ts +16 -0
- package/dist/validate.js +204 -0
- package/dist/verify/auto-steps.d.ts +107 -0
- package/dist/verify/auto-steps.js +471 -0
- package/dist/verify/bundle.d.ts +68 -0
- package/dist/verify/bundle.js +548 -0
- package/dist/verify/diff.d.ts +31 -0
- package/dist/verify/diff.js +133 -0
- package/dist/verify/leaks.d.ts +25 -0
- package/dist/verify/leaks.js +261 -0
- package/dist/verify/link-worker.d.ts +1 -0
- package/dist/verify/link-worker.js +27 -0
- package/dist/verify/runner.d.ts +57 -0
- package/dist/verify/runner.js +867 -0
- package/dist/verify/sandbox.d.ts +40 -0
- package/dist/verify/sandbox.js +496 -0
- package/dist/verify/steps.d.ts +42 -0
- package/dist/verify/steps.js +475 -0
- package/dist/verify/verdict.d.ts +15 -0
- package/dist/verify/verdict.js +19 -0
- package/package.json +118 -4
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FontMetrics } from './sfnt.js';
|
|
2
|
+
/** The overrides of Next.js's adjusted fallback face (next/font's `adjustFontFallback`). */
|
|
3
|
+
export interface FallbackMetrics {
|
|
4
|
+
fallbackFont: string;
|
|
5
|
+
ascentOverride: string;
|
|
6
|
+
descentOverride: string;
|
|
7
|
+
lineGapOverride: string;
|
|
8
|
+
sizeAdjust: string;
|
|
9
|
+
}
|
|
10
|
+
/** Next.js's fallback overrides for a font file, computed as `getFallbackMetricsFromFontFile` computes them. */
|
|
11
|
+
export declare function fallbackMetrics(font: FontMetrics, category: 'serif' | 'sans-serif'): FallbackMetrics;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Next.js's measures of its two fallback system fonts (fontkit on Arial and Times New Roman). */
|
|
2
|
+
const SANS = { name: 'Arial', azAvgWidth: 934.5116279069767, unitsPerEm: 2048 };
|
|
3
|
+
const SERIF = { name: 'Times New Roman', azAvgWidth: 854.3953488372093, unitsPerEm: 2048 };
|
|
4
|
+
/** The characters whose mean advance Next.js takes as a font's average width (letter frequency, spaces for word length). */
|
|
5
|
+
const AVG_CHARACTERS = 'aaabcdeeeefghiijklmnnoopqrrssttuvwxyz ';
|
|
6
|
+
const percent = (value) => `${Math.abs(value * 100).toFixed(2)}%`;
|
|
7
|
+
/** Next.js's fallback overrides for a font file, computed as `getFallbackMetricsFromFontFile` computes them. */
|
|
8
|
+
export function fallbackMetrics(font, category) {
|
|
9
|
+
const fallback = category === 'serif' ? SERIF : SANS;
|
|
10
|
+
const codePoints = [...AVG_CHARACTERS].map((c) => c.codePointAt(0) ?? 0);
|
|
11
|
+
// a font without every one of those characters gets no size adjustment (calcAverageWidth returns undefined)
|
|
12
|
+
const azAvgWidth = codePoints.every((cp) => font.has(cp)) ? codePoints.reduce((sum, cp) => sum + font.advance(cp), 0) / codePoints.length : 0;
|
|
13
|
+
const sizeAdjust = azAvgWidth ? azAvgWidth / font.unitsPerEm / (fallback.azAvgWidth / fallback.unitsPerEm) : 1;
|
|
14
|
+
return {
|
|
15
|
+
fallbackFont: fallback.name,
|
|
16
|
+
ascentOverride: percent(font.ascent / (font.unitsPerEm * sizeAdjust)),
|
|
17
|
+
descentOverride: percent(font.descent / (font.unitsPerEm * sizeAdjust)),
|
|
18
|
+
lineGapOverride: percent(font.lineGap / (font.unitsPerEm * sizeAdjust)),
|
|
19
|
+
sizeAdjust: percent(sizeAdjust),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import type { Project } from '../analyzer/deps.js';
|
|
3
|
+
import type { FontsOptions } from '../types.js';
|
|
4
|
+
import { type Carried } from './local.js';
|
|
5
|
+
import type { FallbackMetrics } from './fallback.js';
|
|
6
|
+
/**
|
|
7
|
+
* next/font/google, carried only behind the `fonts` option: the conversion asks Google Fonts for the CSS Next.js would
|
|
8
|
+
* ask for (the same URL, built from the project's own `next` package data, with the same browser User-Agent Next sends)
|
|
9
|
+
* and for the files that CSS names, and writes them into the output as next/font/local's files are. Nothing is fetched
|
|
10
|
+
* without the option; with it, only https://fonts.googleapis.com (the CSS) and https://fonts.gstatic.com (the files).
|
|
11
|
+
*/
|
|
12
|
+
export type FontsOption = FontsOptions;
|
|
13
|
+
/** The key of one call: the loader and its options as they are at run time. */
|
|
14
|
+
export declare function googleKey(loader: string, options: t.Node | undefined): string;
|
|
15
|
+
/** What a Google font call became under the option, or undefined when the option was not given. */
|
|
16
|
+
export declare function googleCarried(project: Project, key: string): Carried | undefined;
|
|
17
|
+
/** The carried Google font calls of a project root (verify gives React's page the same files). */
|
|
18
|
+
export declare function googleCarriedAt(root: string): Map<string, Carried> | undefined;
|
|
19
|
+
export interface NextFontData {
|
|
20
|
+
families: Record<string, {
|
|
21
|
+
weights: string[];
|
|
22
|
+
styles: string[];
|
|
23
|
+
axes?: {
|
|
24
|
+
tag: string;
|
|
25
|
+
min: number;
|
|
26
|
+
max: number;
|
|
27
|
+
}[];
|
|
28
|
+
subsets: string[];
|
|
29
|
+
}>;
|
|
30
|
+
capsize: Record<string, {
|
|
31
|
+
category: string;
|
|
32
|
+
ascent: number;
|
|
33
|
+
descent: number;
|
|
34
|
+
lineGap: number;
|
|
35
|
+
unitsPerEm: number;
|
|
36
|
+
xWidthAvg: number;
|
|
37
|
+
}>;
|
|
38
|
+
}
|
|
39
|
+
/** Google's font list and the fallback measures, from the project's own `next` package (data files, read as JSON). */
|
|
40
|
+
export declare function nextFontData(root: string): NextFontData | string;
|
|
41
|
+
/** next/font's getFontAxes and getGoogleFontsUrl. */
|
|
42
|
+
export declare function googleUrl(family: string, weights: string[], styles: string[], axes: {
|
|
43
|
+
tag: string;
|
|
44
|
+
min: number;
|
|
45
|
+
max: number;
|
|
46
|
+
}[] | undefined, selected: string[] | undefined, display: string): string | null;
|
|
47
|
+
/** next/font's calculateSizeAdjustValues for a Google family (capsize measures Next ships). */
|
|
48
|
+
export declare function googleFallback(family: string, capsize: NextFontData['capsize']): FallbackMetrics | null;
|
|
49
|
+
/** The most a downloaded stylesheet and a downloaded font file may weigh (Google's are a few KB and under 200 KB). */
|
|
50
|
+
export declare const MAX_CSS_BYTES: number;
|
|
51
|
+
export declare const MAX_FONT_BYTES: number;
|
|
52
|
+
/**
|
|
53
|
+
* Google's CSS answer read as @font-face rules and nothing else: comments are dropped, every declaration must be one a
|
|
54
|
+
* face takes with a value of the form Google writes, and anything else in the text (another rule, an @import, a
|
|
55
|
+
* selector, a url on another host) refuses the whole answer. Returns the faces' declarations in order, or why not.
|
|
56
|
+
*/
|
|
57
|
+
export declare function fontFaces(css: string): [string, string][][] | string;
|
|
58
|
+
/**
|
|
59
|
+
* Fetches, before any file is emitted, every Google font a conversion's files call (module-level consts, as Next.js
|
|
60
|
+
* takes them), so emitting stays synchronous. Only called when the fonts option is given.
|
|
61
|
+
*/
|
|
62
|
+
export declare function prepareGoogleFonts(sources: {
|
|
63
|
+
file: string;
|
|
64
|
+
code: string;
|
|
65
|
+
}[], project: Project, option: FontsOption): Promise<void>;
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { request } from 'node:https';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import * as t from '@babel/types';
|
|
7
|
+
import { parseSource } from '../analyzer/parse.js';
|
|
8
|
+
import { literal } from './local.js';
|
|
9
|
+
import { readFontMetrics } from './sfnt.js';
|
|
10
|
+
/**
|
|
11
|
+
* The User-Agent Next.js sends to Google Fonts (a plain desktop Chrome, nothing that names this machine or this tool):
|
|
12
|
+
* Google picks the file format from it.
|
|
13
|
+
*/
|
|
14
|
+
const USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36';
|
|
15
|
+
const CSS_HOST = 'fonts.googleapis.com';
|
|
16
|
+
const FILE_HOST = 'fonts.gstatic.com';
|
|
17
|
+
const DISPLAY = new Set(['auto', 'block', 'swap', 'fallback']);
|
|
18
|
+
const MIME = { woff2: ['font/woff2', 'woff2'], woff: ['font/woff', 'woff'], ttf: ['font/ttf', 'truetype'], otf: ['font/otf', 'opentype'] };
|
|
19
|
+
/** What each Google font call of a conversion became, by project (compile) and by project root (verify's React page). */
|
|
20
|
+
const byProject = new WeakMap();
|
|
21
|
+
const byRoot = new Map();
|
|
22
|
+
/** The key of one call: the loader and its options as they are at run time. */
|
|
23
|
+
export function googleKey(loader, options) {
|
|
24
|
+
return `${loader}\0${JSON.stringify(options ? literal(options) : undefined)}`;
|
|
25
|
+
}
|
|
26
|
+
/** What a Google font call became under the option, or undefined when the option was not given. */
|
|
27
|
+
export function googleCarried(project, key) {
|
|
28
|
+
return byProject.get(project)?.get(key);
|
|
29
|
+
}
|
|
30
|
+
/** The carried Google font calls of a project root (verify gives React's page the same files). */
|
|
31
|
+
export function googleCarriedAt(root) {
|
|
32
|
+
return byRoot.get(root);
|
|
33
|
+
}
|
|
34
|
+
/** Google's font list and the fallback measures, from the project's own `next` package (data files, read as JSON). */
|
|
35
|
+
export function nextFontData(root) {
|
|
36
|
+
const next = join(root, 'node_modules', 'next');
|
|
37
|
+
const families = join(next, 'dist', 'compiled', '@next', 'font', 'dist', 'google', 'font-data.json');
|
|
38
|
+
const capsize = join(next, 'dist', 'server', 'capsize-font-metrics.json');
|
|
39
|
+
if (!existsSync(families) || !existsSync(capsize))
|
|
40
|
+
return "the project has no installed next package whose Google font data the request is built from";
|
|
41
|
+
return { families: JSON.parse(readFileSync(families, 'utf8')), capsize: JSON.parse(readFileSync(capsize, 'utf8')) };
|
|
42
|
+
}
|
|
43
|
+
/** next/font's getFontAxes and getGoogleFontsUrl. */
|
|
44
|
+
export function googleUrl(family, weights, styles, axes, selected, display) {
|
|
45
|
+
const ital = styles.includes('italic') ? [...(styles.includes('normal') ? ['0'] : []), '1'] : undefined;
|
|
46
|
+
let wght;
|
|
47
|
+
let variableAxes;
|
|
48
|
+
if (weights[0] === 'variable') {
|
|
49
|
+
if (!axes)
|
|
50
|
+
return null;
|
|
51
|
+
for (const { tag, min, max } of axes) {
|
|
52
|
+
if (tag === 'wght')
|
|
53
|
+
wght = [`${min}..${max}`];
|
|
54
|
+
else if (selected?.includes(tag))
|
|
55
|
+
(variableAxes ??= []).push([tag, `${min}..${max}`]);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else
|
|
59
|
+
wght = weights;
|
|
60
|
+
const variants = [];
|
|
61
|
+
if (wght) {
|
|
62
|
+
for (const w of wght) {
|
|
63
|
+
if (!ital)
|
|
64
|
+
variants.push([['wght', w], ...(variableAxes ?? [])]);
|
|
65
|
+
else
|
|
66
|
+
for (const i of ital)
|
|
67
|
+
variants.push([['ital', i], ['wght', w], ...(variableAxes ?? [])]);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else if (variableAxes)
|
|
71
|
+
variants.push([...variableAxes]);
|
|
72
|
+
if (variableAxes) {
|
|
73
|
+
for (const v of variants) {
|
|
74
|
+
v.sort(([a], [b]) => {
|
|
75
|
+
const al = a.charCodeAt(0) > 96;
|
|
76
|
+
const bl = b.charCodeAt(0) > 96;
|
|
77
|
+
if (al && !bl)
|
|
78
|
+
return -1;
|
|
79
|
+
if (bl && !al)
|
|
80
|
+
return 1;
|
|
81
|
+
return a > b ? 1 : -1;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const sortValues = (a, b) => {
|
|
86
|
+
if (a.includes(',') && b.includes(',')) {
|
|
87
|
+
const [ap = '', as = ''] = a.split(',', 2);
|
|
88
|
+
const [bp = '', bs = ''] = b.split(',', 2);
|
|
89
|
+
return ap === bp ? parseInt(as) - parseInt(bs) : parseInt(ap) - parseInt(bp);
|
|
90
|
+
}
|
|
91
|
+
return parseInt(a) - parseInt(b);
|
|
92
|
+
};
|
|
93
|
+
let url = `https://${CSS_HOST}/css2?family=${family.replace(/ /g, '+')}`;
|
|
94
|
+
const first = variants[0];
|
|
95
|
+
if (first)
|
|
96
|
+
url = `${url}:${first.map(([k]) => k).join(',')}@${variants.map((v) => v.map(([, val]) => val).join(',')).sort(sortValues).join(';')}`;
|
|
97
|
+
return `${url}&display=${display}`;
|
|
98
|
+
}
|
|
99
|
+
/** next/font's calculateSizeAdjustValues for a Google family (capsize measures Next ships). */
|
|
100
|
+
export function googleFallback(family, capsize) {
|
|
101
|
+
const formatName = (s) => s.replace(/(?:^\w|[A-Z]|\b\w)/g, (word, index) => (index === 0 ? word.toLowerCase() : word.toUpperCase())).replace(/\s+/g, '');
|
|
102
|
+
const m = capsize[formatName(family)];
|
|
103
|
+
if (!m)
|
|
104
|
+
return null;
|
|
105
|
+
const fallbackName = m.category === 'serif' ? 'Times New Roman' : 'Arial';
|
|
106
|
+
const f = capsize[formatName(fallbackName)];
|
|
107
|
+
if (!f)
|
|
108
|
+
return null;
|
|
109
|
+
const sizeAdjust = m.xWidthAvg ? m.xWidthAvg / m.unitsPerEm / (f.xWidthAvg / f.unitsPerEm) : 1;
|
|
110
|
+
const pct = (v) => `${Math.abs(v * 100).toFixed(2)}%`;
|
|
111
|
+
return { fallbackFont: fallbackName, ascentOverride: pct(m.ascent / (m.unitsPerEm * sizeAdjust)), descentOverride: pct(m.descent / (m.unitsPerEm * sizeAdjust)), lineGapOverride: pct(m.lineGap / (m.unitsPerEm * sizeAdjust)), sizeAdjust: pct(sizeAdjust) };
|
|
112
|
+
}
|
|
113
|
+
/** The most a downloaded stylesheet and a downloaded font file may weigh (Google's are a few KB and under 200 KB). */
|
|
114
|
+
export const MAX_CSS_BYTES = 256 * 1024;
|
|
115
|
+
export const MAX_FONT_BYTES = 2 * 1024 * 1024;
|
|
116
|
+
/**
|
|
117
|
+
* One GET over https to an allowed host, no redirect followed, a plain browser User-Agent and nothing else that names
|
|
118
|
+
* this machine. The answer is kept in the cache under the hash of its URL (never under a name taken from the answer),
|
|
119
|
+
* and refused when it is larger than `maxBytes`, from the cache too.
|
|
120
|
+
*/
|
|
121
|
+
function get(url, host, option, maxBytes) {
|
|
122
|
+
const parsed = new URL(url);
|
|
123
|
+
if (parsed.protocol !== 'https:' || parsed.hostname !== host || parsed.port !== '' || parsed.username || parsed.password)
|
|
124
|
+
return Promise.reject(new Error(`${url} is not on https://${host}`));
|
|
125
|
+
const cacheDir = option.cache ?? join(tmpdir(), 'antheo-morph-fonts');
|
|
126
|
+
const cached = join(cacheDir, createHash('sha256').update(url).digest('hex'));
|
|
127
|
+
const tooLarge = () => new Error(`${url} is larger than ${maxBytes} bytes`);
|
|
128
|
+
if (existsSync(cached)) {
|
|
129
|
+
const body = readFileSync(cached);
|
|
130
|
+
return body.length > maxBytes ? Promise.reject(tooLarge()) : Promise.resolve(body);
|
|
131
|
+
}
|
|
132
|
+
if (option.offline)
|
|
133
|
+
return Promise.reject(new Error(`${url} is not in the font cache and the run is offline`));
|
|
134
|
+
// every URL asked for is logged before it is asked: to the given file, else to requests.log in the cache folder
|
|
135
|
+
const log = option.log ?? join(cacheDir, 'requests.log');
|
|
136
|
+
mkdirSync(cacheDir, { recursive: true });
|
|
137
|
+
appendFileSync(log, `${new Date().toISOString()} GET ${url}\n`);
|
|
138
|
+
return new Promise((resolve, reject) => {
|
|
139
|
+
const req = request(url, { method: 'GET', headers: { 'User-Agent': USER_AGENT }, timeout: 15000 }, (res) => {
|
|
140
|
+
if (res.statusCode !== 200) {
|
|
141
|
+
res.resume();
|
|
142
|
+
reject(new Error(`${url} answered ${res.statusCode}${res.headers.location ? ' (a redirect, not followed)' : ''}`));
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const chunks = [];
|
|
146
|
+
let size = 0;
|
|
147
|
+
res.on('data', (c) => {
|
|
148
|
+
size += c.length;
|
|
149
|
+
if (size > maxBytes) {
|
|
150
|
+
req.destroy(tooLarge());
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
chunks.push(c);
|
|
154
|
+
});
|
|
155
|
+
res.on('end', () => {
|
|
156
|
+
if (size > maxBytes)
|
|
157
|
+
return;
|
|
158
|
+
const body = Buffer.concat(chunks);
|
|
159
|
+
mkdirSync(cacheDir, { recursive: true });
|
|
160
|
+
writeFileSync(cached, body);
|
|
161
|
+
resolve(body);
|
|
162
|
+
});
|
|
163
|
+
res.on('error', reject);
|
|
164
|
+
});
|
|
165
|
+
req.on('timeout', () => req.destroy(new Error(`${url} timed out`)));
|
|
166
|
+
req.on('error', reject);
|
|
167
|
+
req.end();
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/** The first bytes of each font format (TrueType: 0x00010000 or 'true'; OpenType CFF: 'OTTO'). */
|
|
171
|
+
const MAGIC = {
|
|
172
|
+
woff2: [Buffer.from('wOF2', 'latin1')],
|
|
173
|
+
woff: [Buffer.from('wOFF', 'latin1')],
|
|
174
|
+
ttf: [Buffer.from([0, 1, 0, 0]), Buffer.from('true', 'latin1')],
|
|
175
|
+
otf: [Buffer.from('OTTO', 'latin1'), Buffer.from([0, 1, 0, 0])],
|
|
176
|
+
};
|
|
177
|
+
/** The declarations a Google Fonts face may hold, each with the only values it may take. */
|
|
178
|
+
const FACE_VALUES = {
|
|
179
|
+
'font-family': /^'[^'\\;{}]{1,100}'$|^"[^"\\;{}]{1,100}"$/,
|
|
180
|
+
'font-style': /^(normal|italic|oblique(?: -?\d{1,2}(?:\.\d+)?deg){0,2})$/,
|
|
181
|
+
'font-weight': /^\d{1,3}(?: \d{1,3})?$/,
|
|
182
|
+
'font-stretch': /^(normal|\d{1,3}(?:\.\d+)?%(?: \d{1,3}(?:\.\d+)?%)?)$/,
|
|
183
|
+
'font-display': /^(auto|block|swap|fallback)$/,
|
|
184
|
+
src: new RegExp(`^url\\(https://${FILE_HOST.replace(/\./g, '\\.')}/[A-Za-z0-9._/-]{1,300}\\) format\\('(woff2|woff|truetype|opentype)'\\)$`),
|
|
185
|
+
'unicode-range': /^U\+[0-9A-Fa-f?]{1,6}(?:-[0-9A-Fa-f]{1,6})?(?:, ?U\+[0-9A-Fa-f?]{1,6}(?:-[0-9A-Fa-f]{1,6})?){0,400}$/,
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* Google's CSS answer read as @font-face rules and nothing else: comments are dropped, every declaration must be one a
|
|
189
|
+
* face takes with a value of the form Google writes, and anything else in the text (another rule, an @import, a
|
|
190
|
+
* selector, a url on another host) refuses the whole answer. Returns the faces' declarations in order, or why not.
|
|
191
|
+
*/
|
|
192
|
+
export function fontFaces(css) {
|
|
193
|
+
const text = css.replace(/\/\*[^*]*\*\//g, '');
|
|
194
|
+
const faces = [];
|
|
195
|
+
const rest = text.replace(/@font-face\s*\{([^{}]*)\}/g, (_, body) => {
|
|
196
|
+
const face = [];
|
|
197
|
+
for (const raw of body.split(';')) {
|
|
198
|
+
const decl = raw.trim();
|
|
199
|
+
if (!decl)
|
|
200
|
+
continue;
|
|
201
|
+
const colon = decl.indexOf(':');
|
|
202
|
+
const prop = decl.slice(0, colon).trim();
|
|
203
|
+
const value = decl.slice(colon + 1).trim();
|
|
204
|
+
const allowed = colon > 0 ? FACE_VALUES[prop] : undefined;
|
|
205
|
+
if (!allowed?.test(value)) {
|
|
206
|
+
faces.length = 0;
|
|
207
|
+
return '\u0000';
|
|
208
|
+
}
|
|
209
|
+
face.push([prop, value]);
|
|
210
|
+
}
|
|
211
|
+
faces.push(face);
|
|
212
|
+
return '';
|
|
213
|
+
});
|
|
214
|
+
if (rest.includes('\u0000'))
|
|
215
|
+
return 'holds a declaration a font face does not take from Google Fonts';
|
|
216
|
+
if (rest.trim())
|
|
217
|
+
return 'holds something other than @font-face rules';
|
|
218
|
+
if (!faces.length)
|
|
219
|
+
return 'holds no @font-face rule';
|
|
220
|
+
return faces;
|
|
221
|
+
}
|
|
222
|
+
const isRecord = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
223
|
+
const list = (v) => (v === undefined ? [] : typeof v === 'string' ? [v] : Array.isArray(v) && v.every((x) => typeof x === 'string') ? [...new Set(v)] : null);
|
|
224
|
+
/** One Google font call: Next.js's request for it, fetched, as a request the carried module is written from. */
|
|
225
|
+
async function googleRequest(loader, options, data, option) {
|
|
226
|
+
const family = loader.replace(/_/g, ' ');
|
|
227
|
+
const meta = data.families[family];
|
|
228
|
+
if (!meta)
|
|
229
|
+
return { refused: `${family} is not in Google Fonts' list of the project's next package` };
|
|
230
|
+
if (options !== undefined && !isRecord(options))
|
|
231
|
+
return { refused: 'its options are not all literal values' };
|
|
232
|
+
const o = options ?? {};
|
|
233
|
+
const weights = list(o.weight);
|
|
234
|
+
const styles = list(o.style);
|
|
235
|
+
const axes = list(o.axes);
|
|
236
|
+
if (!weights || !styles || !axes)
|
|
237
|
+
return { refused: 'its weight, style or axes are not literal' };
|
|
238
|
+
if (!weights.length) {
|
|
239
|
+
if (!meta.weights.includes('variable'))
|
|
240
|
+
return { refused: `${family} needs a weight` };
|
|
241
|
+
weights.push('variable');
|
|
242
|
+
}
|
|
243
|
+
if (!styles.length)
|
|
244
|
+
styles.push(meta.styles.length === 1 ? (meta.styles[0] ?? 'normal') : 'normal');
|
|
245
|
+
if (weights.some((w) => !meta.weights.includes(w)) || styles.some((s) => !meta.styles.includes(s)))
|
|
246
|
+
return { refused: `a weight or style ${family} does not have` };
|
|
247
|
+
const display = o.display === undefined ? 'swap' : typeof o.display === 'string' ? o.display : '';
|
|
248
|
+
if (!DISPLAY.has(display))
|
|
249
|
+
return { refused: `display ${JSON.stringify(o.display)} depends on when the file arrives, which a carried file does not reproduce` };
|
|
250
|
+
const fallback = list(o.fallback);
|
|
251
|
+
if (!fallback)
|
|
252
|
+
return { refused: 'its fallback is not a list of families' };
|
|
253
|
+
if (o.variable !== undefined && typeof o.variable !== 'string')
|
|
254
|
+
return { refused: 'its variable is not a literal name' };
|
|
255
|
+
const url = googleUrl(family, weights, styles, meta.axes, o.axes === undefined ? undefined : axes, display);
|
|
256
|
+
if (!url)
|
|
257
|
+
return { refused: `${family} has no axes for a variable request` };
|
|
258
|
+
try {
|
|
259
|
+
const faces = fontFaces((await get(url, CSS_HOST, option, MAX_CSS_BYTES)).toString('utf8'));
|
|
260
|
+
if (typeof faces === 'string')
|
|
261
|
+
return { refused: `Google Fonts' CSS for ${family} ${faces}` };
|
|
262
|
+
const urls = [...new Set(faces.flatMap((face) => face.filter(([p]) => p === 'src').map(([, v]) => /^url\(([^)]+)\)/.exec(v)?.[1] ?? '')))];
|
|
263
|
+
if (!urls.length)
|
|
264
|
+
return { refused: `Google Fonts' CSS for ${family} names no file` };
|
|
265
|
+
const files = [];
|
|
266
|
+
const dataUrls = new Map();
|
|
267
|
+
for (const fileUrl of urls) {
|
|
268
|
+
const ext = /\.(woff2|woff|ttf|otf)$/.exec(fileUrl)?.[1];
|
|
269
|
+
const kind = ext ? MIME[ext] : undefined;
|
|
270
|
+
if (!ext || !kind)
|
|
271
|
+
return { refused: `Google Fonts' CSS names ${fileUrl}, not a font file this conversion carries` };
|
|
272
|
+
const bytes = await get(fileUrl, FILE_HOST, option, MAX_FONT_BYTES);
|
|
273
|
+
// a file from the network is embedded only if it is the font its name says: the right signature, and our own
|
|
274
|
+
// sfnt reader can read its metrics
|
|
275
|
+
if (!MAGIC[ext]?.some((m) => bytes.subarray(0, 4).equals(m)) || readFontMetrics(bytes) === null)
|
|
276
|
+
return { refused: `${fileUrl} is not a readable ${ext} font file` };
|
|
277
|
+
files.push({ written: fileUrl, bytes, format: kind[1], mime: kind[0] });
|
|
278
|
+
dataUrls.set(fileUrl, `data:${kind[0]};base64,${bytes.toString('base64')}`);
|
|
279
|
+
}
|
|
280
|
+
// the faces as we rebuild them from the checked declarations, each file as its data URL (never Google's text as is)
|
|
281
|
+
const faceCss = faces.map((face) => `@font-face {\n${face.map(([p, v]) => ` ${p}: ${p === 'src' ? v.replace(/^url\(([^)]+)\)/, (_, u) => `url(${dataUrls.get(u) ?? u})`) : v};`).join('\n')}\n}`).join('\n');
|
|
282
|
+
const adjust = o.adjustFontFallback === false ? null : googleFallback(family, data.capsize);
|
|
283
|
+
return {
|
|
284
|
+
request: {
|
|
285
|
+
files,
|
|
286
|
+
faceCss: faceCss.trim(),
|
|
287
|
+
display,
|
|
288
|
+
declarations: [],
|
|
289
|
+
fallback,
|
|
290
|
+
...(typeof o.variable === 'string' ? { variable: o.variable } : {}),
|
|
291
|
+
...(weights.length === 1 && weights[0] !== 'variable' && weights[0] ? { weight: weights[0] } : {}),
|
|
292
|
+
...(styles.length === 1 && styles[0] ? { style: styles[0] } : {}),
|
|
293
|
+
adjust,
|
|
294
|
+
source: `Google Fonts, ${url}, downloaded at conversion time (the fonts option)`,
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
catch (error) {
|
|
299
|
+
return { refused: `the download failed: ${error instanceof Error ? error.message : String(error)}` };
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Fetches, before any file is emitted, every Google font a conversion's files call (module-level consts, as Next.js
|
|
304
|
+
* takes them), so emitting stays synchronous. Only called when the fonts option is given.
|
|
305
|
+
*/
|
|
306
|
+
export async function prepareGoogleFonts(sources, project, option) {
|
|
307
|
+
const out = new Map();
|
|
308
|
+
byProject.set(project, out);
|
|
309
|
+
byRoot.set(project.root, out);
|
|
310
|
+
let data = null;
|
|
311
|
+
for (const { file, code } of sources) {
|
|
312
|
+
if (!/\.(tsx?|jsx?)$/.test(file) || !code.includes('next/font/google'))
|
|
313
|
+
continue;
|
|
314
|
+
const ast = parseSource(code, file);
|
|
315
|
+
const loaders = new Map();
|
|
316
|
+
for (const s of ast.program.body) {
|
|
317
|
+
if (!t.isImportDeclaration(s) || s.source.value !== 'next/font/google')
|
|
318
|
+
continue;
|
|
319
|
+
for (const sp of s.specifiers)
|
|
320
|
+
if (t.isImportSpecifier(sp))
|
|
321
|
+
loaders.set(sp.local.name, t.isIdentifier(sp.imported) ? sp.imported.name : sp.imported.value);
|
|
322
|
+
}
|
|
323
|
+
for (const s of ast.program.body) {
|
|
324
|
+
const decl = t.isExportNamedDeclaration(s) ? s.declaration : s;
|
|
325
|
+
if (!t.isVariableDeclaration(decl) || decl.kind !== 'const')
|
|
326
|
+
continue;
|
|
327
|
+
for (const d of decl.declarations) {
|
|
328
|
+
if (!t.isCallExpression(d.init) || !t.isIdentifier(d.init.callee))
|
|
329
|
+
continue;
|
|
330
|
+
const loader = loaders.get(d.init.callee.name);
|
|
331
|
+
if (!loader)
|
|
332
|
+
continue;
|
|
333
|
+
const key = googleKey(loader, d.init.arguments[0]);
|
|
334
|
+
if (out.has(key))
|
|
335
|
+
continue;
|
|
336
|
+
data ??= nextFontData(project.root);
|
|
337
|
+
const arg = d.init.arguments[0];
|
|
338
|
+
const options = arg ? literal(arg) : undefined;
|
|
339
|
+
out.set(key, typeof data === 'string' ? { refused: data } : arg && options === undefined ? { refused: 'its options are not all literal values' } : await googleRequest(loader, options, data, option));
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import type { Diagnostic } from '../types.js';
|
|
3
|
+
import type { Project } from '../analyzer/deps.js';
|
|
4
|
+
export { carriedFontFiles } from './carry.js';
|
|
5
|
+
export { prepareGoogleFonts } from './google.js';
|
|
6
|
+
/** What a module statement needs to carry its next/font calls. */
|
|
7
|
+
export interface FontContext {
|
|
8
|
+
diagnostics: Diagnostic[];
|
|
9
|
+
sourceFile: string;
|
|
10
|
+
projectRoot: string;
|
|
11
|
+
/** output path of the file the statement is written to */
|
|
12
|
+
outPath: string;
|
|
13
|
+
/** names the module already binds (the imported font object takes a free one) */
|
|
14
|
+
taken: Set<string>;
|
|
15
|
+
/** the conversion's project: under the fonts option, the Google fonts prepared for it (google.ts) */
|
|
16
|
+
project?: Project;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Carries the next/font/local calls of one module statement whose font files the conversion can reach: each call becomes
|
|
20
|
+
* the font object of a generated module (see carry.ts), imported before the statement. A call that cannot be carried is
|
|
21
|
+
* left as it is, with the reason, for the next-font warning to say. A next/font/google call is carried only when the
|
|
22
|
+
* conversion ran with the fonts option (google.ts downloaded its files first); without it, it is left exactly as before.
|
|
23
|
+
*/
|
|
24
|
+
export declare function carryNextFonts(stmt: t.Statement, nextFonts: Map<string, string>, ctx: FontContext): {
|
|
25
|
+
imports: t.ImportDeclaration[];
|
|
26
|
+
refused: Map<t.Node, string>;
|
|
27
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import { localFontRequest } from './local.js';
|
|
3
|
+
import { carryFont } from './carry.js';
|
|
4
|
+
import { googleCarried, googleKey } from './google.js';
|
|
5
|
+
export { carriedFontFiles } from './carry.js';
|
|
6
|
+
export { prepareGoogleFonts } from './google.js';
|
|
7
|
+
/**
|
|
8
|
+
* Carries the next/font/local calls of one module statement whose font files the conversion can reach: each call becomes
|
|
9
|
+
* the font object of a generated module (see carry.ts), imported before the statement. A call that cannot be carried is
|
|
10
|
+
* left as it is, with the reason, for the next-font warning to say. A next/font/google call is carried only when the
|
|
11
|
+
* conversion ran with the fonts option (google.ts downloaded its files first); without it, it is left exactly as before.
|
|
12
|
+
*/
|
|
13
|
+
export function carryNextFonts(stmt, nextFonts, ctx) {
|
|
14
|
+
const imports = [];
|
|
15
|
+
const refused = new Map();
|
|
16
|
+
const decl = t.isExportNamedDeclaration(stmt) ? stmt.declaration : stmt;
|
|
17
|
+
if (!t.isVariableDeclaration(decl))
|
|
18
|
+
return { imports, refused };
|
|
19
|
+
for (const d of decl.declarations) {
|
|
20
|
+
const call = d.init;
|
|
21
|
+
if (!t.isCallExpression(call) || !t.isIdentifier(call.callee) || !nextFonts.has(call.callee.name) || !t.isIdentifier(d.id))
|
|
22
|
+
continue;
|
|
23
|
+
// next/font/local is the default import ('' imported name); a Google family is named
|
|
24
|
+
const loader = nextFonts.get(call.callee.name) ?? '';
|
|
25
|
+
let carried;
|
|
26
|
+
if (loader !== '') {
|
|
27
|
+
// a Google family: only what the fonts option prepared for this conversion; without it, nothing changes
|
|
28
|
+
const google = ctx.project ? googleCarried(ctx.project, googleKey(loader, call.arguments[0])) : undefined;
|
|
29
|
+
if (!google)
|
|
30
|
+
continue;
|
|
31
|
+
carried = google;
|
|
32
|
+
}
|
|
33
|
+
else
|
|
34
|
+
carried = decl.kind !== 'const' ? { refused: 'Next.js takes a font loader call only as a module-level const' } : localFontRequest(call, ctx.sourceFile, ctx.projectRoot);
|
|
35
|
+
if ('refused' in carried) {
|
|
36
|
+
refused.set(call, carried.refused);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
let name = `${d.id.name}Loaded`;
|
|
40
|
+
for (let i = 2; ctx.taken.has(name); i++)
|
|
41
|
+
name = `${d.id.name}Loaded${i}`;
|
|
42
|
+
ctx.taken.add(name);
|
|
43
|
+
const { importDecl, value } = carryFont(ctx.diagnostics, carried.request, d.id.name, ctx.outPath, name);
|
|
44
|
+
imports.push(importDecl);
|
|
45
|
+
d.init = t.identifier(value.name);
|
|
46
|
+
}
|
|
47
|
+
return { imports, refused };
|
|
48
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import { type FallbackMetrics } from './fallback.js';
|
|
3
|
+
/** One font file of a next/font call, read from where the call names it. */
|
|
4
|
+
export interface FontFile {
|
|
5
|
+
/** the path as the source wrote it (`./Geist-Regular.woff2`) */
|
|
6
|
+
written: string;
|
|
7
|
+
bytes: Buffer;
|
|
8
|
+
/** the @font-face `format()` Next.js writes for its extension */
|
|
9
|
+
format: string;
|
|
10
|
+
mime: string;
|
|
11
|
+
weight?: string;
|
|
12
|
+
style?: string;
|
|
13
|
+
}
|
|
14
|
+
/** What a next/font call asks for, in the terms Next.js's own loader builds its CSS from. */
|
|
15
|
+
export interface FontRequest {
|
|
16
|
+
files: FontFile[];
|
|
17
|
+
display: string;
|
|
18
|
+
/** a `@font-face` declaration the call adds (`declarations`), in order */
|
|
19
|
+
declarations: [string, string][];
|
|
20
|
+
/** families the call lists after its own (`fallback`) */
|
|
21
|
+
fallback: string[];
|
|
22
|
+
/** the CSS variable the call names (`variable`) */
|
|
23
|
+
variable?: string;
|
|
24
|
+
/** the weight and style the font object reports (Next: those of the only file, if there is one) */
|
|
25
|
+
weight?: string;
|
|
26
|
+
style?: string;
|
|
27
|
+
/** Next.js's adjusted fallback face, unless the call turns it off */
|
|
28
|
+
adjust: FallbackMetrics | null;
|
|
29
|
+
/** where the files came from, said in the generated file */
|
|
30
|
+
source: string;
|
|
31
|
+
/** Google Fonts: the @font-face rules Google answered, their files already data URLs (the family is renamed when written) */
|
|
32
|
+
faceCss?: string;
|
|
33
|
+
}
|
|
34
|
+
/** Why a call is not carried (said in the next-font warning), or the call's request. */
|
|
35
|
+
export type Carried = {
|
|
36
|
+
request: FontRequest;
|
|
37
|
+
} | {
|
|
38
|
+
refused: string;
|
|
39
|
+
};
|
|
40
|
+
/** A literal value of a next/font option: strings, numbers, booleans, arrays and objects of them; undefined otherwise. */
|
|
41
|
+
export declare function literal(node: t.Node | null | undefined): unknown;
|
|
42
|
+
/**
|
|
43
|
+
* Reads a `next/font/local` call as Next.js's loader does (`validateLocalFontFunctionCall`): literal options only, each
|
|
44
|
+
* file beside the calling file and inside the project.
|
|
45
|
+
*/
|
|
46
|
+
export declare function localFontRequest(call: t.CallExpression, sourceFile: string, projectRoot: string): Carried;
|