@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,32 @@
|
|
|
1
|
+
import type { EmittedFile } from '../../../../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* A Radix package morph writes for Svelte itself (M3, headless cores): Svelte 5 components with Radix's own props
|
|
4
|
+
* (`value` / `defaultValue` / `onValueChange`, `asChild` as bits-ui's `child` snippet, `ref` bindable), strictly typed,
|
|
5
|
+
* importing nothing but Svelte. They are written into the output once per conversion, only when a converted file uses
|
|
6
|
+
* the package: a barrel (`radix-cores.ts`, exporting one namespace per package, as bits-ui exports its parts) and, beside
|
|
7
|
+
* it, a folder of the same name holding each package's files.
|
|
8
|
+
*/
|
|
9
|
+
export interface SvelteCore {
|
|
10
|
+
/** the namespace the barrel exports (`Collapsible`): the emitter imports it as it imports bits-ui's */
|
|
11
|
+
ns: string;
|
|
12
|
+
/** the parts the namespace has (`Root`, `Trigger`), each a component and a `<Part>Props` type */
|
|
13
|
+
parts: readonly string[];
|
|
14
|
+
/** the package's files, by path inside its folder (`Root.svelte`, `index.ts`) */
|
|
15
|
+
files: Readonly<Record<string, string>>;
|
|
16
|
+
/** the package uses the shared Presence (`../presence.ts`) */
|
|
17
|
+
presence?: boolean;
|
|
18
|
+
/** the package uses a framework-free logic file beside the folders (`../slider-logic.ts`) */
|
|
19
|
+
logic?: 'slider' | 'modal-layer';
|
|
20
|
+
/** other cores whose files the package's files import (the slider reads the direction core's context) */
|
|
21
|
+
requires?: readonly string[];
|
|
22
|
+
/** the package's parts take the props of a Slot they are the child of (`slotProps`, merged by ../slot.ts) */
|
|
23
|
+
slot?: boolean;
|
|
24
|
+
/** the CSS custom properties Radix sets on its parts, which the core sets under the same names */
|
|
25
|
+
cssVariables?: readonly string[];
|
|
26
|
+
}
|
|
27
|
+
/** The barrel the Svelte cores are imported from (its folder takes its name without `.ts`). */
|
|
28
|
+
export declare const SVELTE_CORES_FILE = "radix-cores.ts";
|
|
29
|
+
/** Records that a converted file uses this package's core. */
|
|
30
|
+
export declare function useSvelteCore(conversion: object, pkg: string, core: SvelteCore): void;
|
|
31
|
+
/** The barrel and the used packages' files; nothing when no converted file uses a core. */
|
|
32
|
+
export declare function svelteCoreFiles(conversion: object, barrel: string): EmittedFile[];
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { posix } from 'node:path';
|
|
2
|
+
import { PRESENCE_SOURCE } from './presence.js';
|
|
3
|
+
import { SLIDER_LOGIC_SOURCE } from './slider-logic.js';
|
|
4
|
+
import { MODAL_LAYER_SOURCE } from './modal-layer.js';
|
|
5
|
+
/**
|
|
6
|
+
* Radix's Slot merge (`mergeProps` of `@radix-ui/react-slot`, read from its installed source), for a part rendered as the
|
|
7
|
+
* one child of a component's Slot (`<Button asChild><AlertDialog.Cancel /></Button>`): the part's own props win, class
|
|
8
|
+
* names are joined (the Slot's first), styles joined (the part's last), a handler both give runs the part's first,
|
|
9
|
+
* then the Slot's, and aria-describedby lists both.
|
|
10
|
+
*/
|
|
11
|
+
const SLOT_SOURCE = `type Handler = (...args: unknown[]) => unknown;
|
|
12
|
+
|
|
13
|
+
function isHandler(value: unknown): value is Handler {
|
|
14
|
+
return typeof value === 'function';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The props of a Slot (a component's asChild) merged with those of the part it renders as. */
|
|
18
|
+
export function mergeSlot(slot: Record<string, unknown> | undefined, child: Record<string, unknown>): Record<string, unknown> {
|
|
19
|
+
if (!slot) return child;
|
|
20
|
+
const out: Record<string, unknown> = { ...child };
|
|
21
|
+
for (const key of Object.keys(child)) {
|
|
22
|
+
const theirs = slot[key];
|
|
23
|
+
const own = child[key];
|
|
24
|
+
if (/^on/.test(key)) {
|
|
25
|
+
if (isHandler(theirs) && isHandler(own)) {
|
|
26
|
+
out[key] = (...args: unknown[]) => {
|
|
27
|
+
const result = own(...args);
|
|
28
|
+
theirs(...args);
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
} else if (theirs) out[key] = theirs;
|
|
32
|
+
} else if (key === 'style') out[key] = [theirs, own].filter(Boolean).join('; ');
|
|
33
|
+
else if (key === 'class') out[key] = [theirs, own].filter(Boolean).join(' ');
|
|
34
|
+
else if (key === 'aria-describedby') {
|
|
35
|
+
const ids = new Set([own, theirs].flatMap((v) => (typeof v === 'string' ? v.trim().split(/\\s+/) : [])).filter(Boolean));
|
|
36
|
+
out[key] = ids.size ? [...ids].join(' ') : undefined;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return { ...slot, ...out };
|
|
40
|
+
}
|
|
41
|
+
`;
|
|
42
|
+
/** The barrel the Svelte cores are imported from (its folder takes its name without `.ts`). */
|
|
43
|
+
export const SVELTE_CORES_FILE = 'radix-cores.ts';
|
|
44
|
+
/** Per conversion (keyed by its diagnostics list, as the motion helper is): the packages its files use. */
|
|
45
|
+
const used = new WeakMap();
|
|
46
|
+
/** Records that a converted file uses this package's core. */
|
|
47
|
+
export function useSvelteCore(conversion, pkg, core) {
|
|
48
|
+
const set = used.get(conversion) ?? new Map();
|
|
49
|
+
set.set(pkg, core);
|
|
50
|
+
used.set(conversion, set);
|
|
51
|
+
}
|
|
52
|
+
/** The barrel and the used packages' files; nothing when no converted file uses a core. */
|
|
53
|
+
export function svelteCoreFiles(conversion, barrel) {
|
|
54
|
+
const cores = used.get(conversion);
|
|
55
|
+
if (!cores?.size)
|
|
56
|
+
return [];
|
|
57
|
+
const folder = barrel.replace(/\.ts$/, '');
|
|
58
|
+
const name = posix.basename(folder);
|
|
59
|
+
const sorted = [...cores].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
|
|
60
|
+
const out = [
|
|
61
|
+
{
|
|
62
|
+
path: barrel,
|
|
63
|
+
contents: `// Radix's headless parts, written by morph for Svelte 5 (no dependency but Svelte)\n${sorted.map(([pkg, core]) => `export * as ${core.ns} from './${name}/${pkg}/index.js';`).join('\n')}\n`,
|
|
64
|
+
kind: 'module',
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
if (sorted.some(([, core]) => core.presence))
|
|
68
|
+
out.push({ path: `${folder}/presence.ts`, contents: PRESENCE_SOURCE, kind: 'module' });
|
|
69
|
+
if (sorted.some(([, core]) => core.logic === 'slider'))
|
|
70
|
+
out.push({ path: `${folder}/slider-logic.ts`, contents: SLIDER_LOGIC_SOURCE, kind: 'module' });
|
|
71
|
+
if (sorted.some(([, core]) => core.slot))
|
|
72
|
+
out.push({ path: `${folder}/slot.ts`, contents: SLOT_SOURCE, kind: 'module' });
|
|
73
|
+
if (sorted.some(([, core]) => core.logic === 'modal-layer'))
|
|
74
|
+
out.push({ path: `${folder}/modal-layer.ts`, contents: MODAL_LAYER_SOURCE, kind: 'module' });
|
|
75
|
+
for (const [pkg, core] of sorted) {
|
|
76
|
+
for (const [file, contents] of Object.entries(core.files))
|
|
77
|
+
out.push({ path: `${folder}/${pkg}/${file}`, contents, kind: file.endsWith('.svelte') ? 'component' : 'module' });
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SvelteCore } from './core.js';
|
|
2
|
+
/**
|
|
3
|
+
* Radix Direction (`@radix-ui/react-direction`, read from its installed source) as Svelte 5: `Provider` renders no
|
|
4
|
+
* element and gives its `dir` to the parts below it through Svelte's context, without touching the page's direction;
|
|
5
|
+
* `useDirection()` (called while a component starts) reads it as Radix's hook does: the part's own `dir`, else the
|
|
6
|
+
* nearest provider's, else `ltr`. `Consumer` is how morph hands that direction to a bits-ui part that writes it as its
|
|
7
|
+
* root's `dir` attribute (bits-ui's keys follow the root's computed direction): it renders its children snippet with
|
|
8
|
+
* the direction, read where it is rendered, inside the provider.
|
|
9
|
+
*/
|
|
10
|
+
export declare const directionCore: SvelteCore;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Radix Direction (`@radix-ui/react-direction`, read from its installed source) as Svelte 5: `Provider` renders no
|
|
3
|
+
* element and gives its `dir` to the parts below it through Svelte's context, without touching the page's direction;
|
|
4
|
+
* `useDirection()` (called while a component starts) reads it as Radix's hook does: the part's own `dir`, else the
|
|
5
|
+
* nearest provider's, else `ltr`. `Consumer` is how morph hands that direction to a bits-ui part that writes it as its
|
|
6
|
+
* root's `dir` attribute (bits-ui's keys follow the root's computed direction): it renders its children snippet with
|
|
7
|
+
* the direction, read where it is rendered, inside the provider.
|
|
8
|
+
*/
|
|
9
|
+
export const directionCore = {
|
|
10
|
+
ns: 'Direction',
|
|
11
|
+
parts: ['Provider', 'Consumer'],
|
|
12
|
+
files: {
|
|
13
|
+
'context.ts': `import { getContext, setContext } from 'svelte';
|
|
14
|
+
|
|
15
|
+
export type Direction = 'ltr' | 'rtl';
|
|
16
|
+
|
|
17
|
+
const KEY = Symbol('radix-direction');
|
|
18
|
+
|
|
19
|
+
/** A provider's direction, read each time (its dir may change). */
|
|
20
|
+
export function setDirection(read: () => Direction | undefined): void {
|
|
21
|
+
setContext(KEY, read);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Radix's useDirection, called while a component starts: the part's own dir, else the provider's, else ltr. */
|
|
25
|
+
export function useDirection(): (local?: Direction) => Direction {
|
|
26
|
+
const read = getContext<(() => Direction | undefined) | undefined>(KEY);
|
|
27
|
+
return (local) => local || read?.() || 'ltr';
|
|
28
|
+
}
|
|
29
|
+
`,
|
|
30
|
+
'types.ts': `import type { Snippet } from 'svelte';
|
|
31
|
+
import type { Direction } from './context.js';
|
|
32
|
+
|
|
33
|
+
// (Radix types dir as required; given none, its provider gives undefined and its parts fall back to ltr, as here)
|
|
34
|
+
export type ProviderProps = { dir?: Direction; children?: Snippet };
|
|
35
|
+
export type DirectionProviderProps = ProviderProps;
|
|
36
|
+
export type ConsumerProps = { dir?: Direction; children?: Snippet<[{ dir: Direction }]> };
|
|
37
|
+
`,
|
|
38
|
+
'Provider.svelte': `<script lang="ts">
|
|
39
|
+
import { setDirection } from './context.js';
|
|
40
|
+
import type { ProviderProps } from './types.js';
|
|
41
|
+
|
|
42
|
+
let { dir, children }: ProviderProps = $props();
|
|
43
|
+
setDirection(() => dir);
|
|
44
|
+
</script>
|
|
45
|
+
|
|
46
|
+
{@render children?.()}
|
|
47
|
+
`,
|
|
48
|
+
'Consumer.svelte': `<script lang="ts">
|
|
49
|
+
import { useDirection } from './context.js';
|
|
50
|
+
import type { ConsumerProps } from './types.js';
|
|
51
|
+
|
|
52
|
+
let { dir, children }: ConsumerProps = $props();
|
|
53
|
+
const read = useDirection();
|
|
54
|
+
</script>
|
|
55
|
+
|
|
56
|
+
{@render children?.({ dir: read(dir) })}
|
|
57
|
+
`,
|
|
58
|
+
'index.ts': `export { default as Provider, default as DirectionProvider } from './Provider.svelte';
|
|
59
|
+
export { default as Consumer } from './Consumer.svelte';
|
|
60
|
+
export { useDirection, type Direction } from './context.js';
|
|
61
|
+
export type { ProviderProps, DirectionProviderProps, ConsumerProps } from './types.js';
|
|
62
|
+
`,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { BitsPartMap } from '../part.js';
|
|
2
|
+
import type { SvelteCore } from './core.js';
|
|
3
|
+
export { SVELTE_CORES_FILE, svelteCoreFiles, type SvelteCore } from './core.js';
|
|
4
|
+
/** Records that a converted file uses a core, and the cores its files import (SvelteCore.requires). */
|
|
5
|
+
export declare function useSvelteCorePackage(conversion: object, pkg: string): void;
|
|
6
|
+
/** Each Radix package morph writes itself for Svelte: its core and its parts by Radix part name. */
|
|
7
|
+
export declare const SVELTE_CORES: Readonly<Record<string, {
|
|
8
|
+
core: SvelteCore;
|
|
9
|
+
parts: Readonly<Record<string, BitsPartMap>>;
|
|
10
|
+
}>>;
|
|
11
|
+
/**
|
|
12
|
+
* bits-ui parts whose Radix counterpart reads the direction (useDirection) and writes it as its root's `dir`
|
|
13
|
+
* attribute, which bits-ui's keys follow (bits-ui reads the root's computed direction): in a file that renders Radix's
|
|
14
|
+
* DirectionProvider, each is rendered inside the direction core's Consumer and given its direction (see the emitter).
|
|
15
|
+
* Other bits-ui parts whose Radix counterpart reads the direction are said where such a file renders them.
|
|
16
|
+
*/
|
|
17
|
+
export declare const DIRECTION_ROOTS: Readonly<Record<string, string>>;
|
|
18
|
+
/** Radix packages whose parts read the direction (useDirection), read from their installed sources. */
|
|
19
|
+
export declare const READS_DIRECTION: readonly string[];
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { collapsibleCore } from './collapsible.js';
|
|
2
|
+
import { directionCore } from './direction.js';
|
|
3
|
+
import { useSvelteCore } from './core.js';
|
|
4
|
+
import { sliderCore } from './slider.js';
|
|
5
|
+
import { alertDialogCore } from './alert-dialog.js';
|
|
6
|
+
export { SVELTE_CORES_FILE, svelteCoreFiles } from './core.js';
|
|
7
|
+
/** Records that a converted file uses a core, and the cores its files import (SvelteCore.requires). */
|
|
8
|
+
export function useSvelteCorePackage(conversion, pkg) {
|
|
9
|
+
const entry = SVELTE_CORES[pkg];
|
|
10
|
+
if (!entry)
|
|
11
|
+
return;
|
|
12
|
+
useSvelteCore(conversion, pkg, entry.core);
|
|
13
|
+
for (const other of entry.core.requires ?? [])
|
|
14
|
+
useSvelteCorePackage(conversion, other);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A part of a core (see core.ts): Radix's props and callbacks keep their names (the component takes Radix's own API, so
|
|
18
|
+
* nothing is renamed and no state is bound), `asChild` is the `child` snippet, other attributes and DOM events reach the
|
|
19
|
+
* element. `from` names morph, which writes it.
|
|
20
|
+
*/
|
|
21
|
+
function corePart(ns, part, props = [], events = [], element = true) {
|
|
22
|
+
return {
|
|
23
|
+
from: 'morph',
|
|
24
|
+
name: `${ns}.${part}`,
|
|
25
|
+
props: Object.fromEntries(props.map((p) => [p, p])),
|
|
26
|
+
events: Object.fromEntries(events.map((e) => [e, e])),
|
|
27
|
+
element,
|
|
28
|
+
...(element ? { asChild: 'child' } : {}),
|
|
29
|
+
core: true,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** Each Radix package morph writes itself for Svelte: its core and its parts by Radix part name. */
|
|
33
|
+
export const SVELTE_CORES = {
|
|
34
|
+
collapsible: {
|
|
35
|
+
core: collapsibleCore,
|
|
36
|
+
parts: {
|
|
37
|
+
Root: corePart('Collapsible', 'Root', ['open', 'defaultOpen', 'disabled'], ['onOpenChange']),
|
|
38
|
+
Trigger: corePart('Collapsible', 'Trigger'),
|
|
39
|
+
Content: corePart('Collapsible', 'Content', ['forceMount']),
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
direction: {
|
|
43
|
+
core: directionCore,
|
|
44
|
+
parts: { Provider: corePart('Direction', 'Provider', ['dir'], [], false) },
|
|
45
|
+
},
|
|
46
|
+
// (asChild is not taken: the parts' elements are the slider's own, measured and focused by it)
|
|
47
|
+
slider: {
|
|
48
|
+
core: sliderCore,
|
|
49
|
+
parts: {
|
|
50
|
+
Root: noChild(corePart('Slider', 'Root', ['name', 'min', 'max', 'step', 'orientation', 'disabled', 'minStepsBetweenThumbs', 'defaultValue', 'value', 'inverted', 'dir', 'form'], ['onValueChange', 'onValueCommit'])),
|
|
51
|
+
Track: noChild(corePart('Slider', 'Track')),
|
|
52
|
+
Range: noChild(corePart('Slider', 'Range')),
|
|
53
|
+
Thumb: noChild(corePart('Slider', 'Thumb', ['name'])),
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
'alert-dialog': {
|
|
57
|
+
core: alertDialogCore,
|
|
58
|
+
parts: {
|
|
59
|
+
Root: corePart('AlertDialog', 'Root', ['open', 'defaultOpen'], ['onOpenChange'], false),
|
|
60
|
+
Trigger: corePart('AlertDialog', 'Trigger'),
|
|
61
|
+
Portal: corePart('AlertDialog', 'Portal', ['forceMount', 'container'], [], false),
|
|
62
|
+
// (asChild is not taken: the element is the layer's own, moved into the portal and watched by its presence)
|
|
63
|
+
Overlay: noChild(corePart('AlertDialog', 'Overlay', ['forceMount'])),
|
|
64
|
+
Content: noChild(corePart('AlertDialog', 'Content', ['forceMount'], ['onOpenAutoFocus', 'onCloseAutoFocus', 'onEscapeKeyDown'])),
|
|
65
|
+
Title: corePart('AlertDialog', 'Title'),
|
|
66
|
+
Description: corePart('AlertDialog', 'Description'),
|
|
67
|
+
Action: corePart('AlertDialog', 'Action'),
|
|
68
|
+
Cancel: corePart('AlertDialog', 'Cancel'),
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
function noChild(map) {
|
|
73
|
+
const out = { ...map };
|
|
74
|
+
delete out.asChild;
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* bits-ui parts whose Radix counterpart reads the direction (useDirection) and writes it as its root's `dir`
|
|
79
|
+
* attribute, which bits-ui's keys follow (bits-ui reads the root's computed direction): in a file that renders Radix's
|
|
80
|
+
* DirectionProvider, each is rendered inside the direction core's Consumer and given its direction (see the emitter).
|
|
81
|
+
* Other bits-ui parts whose Radix counterpart reads the direction are said where such a file renders them.
|
|
82
|
+
*/
|
|
83
|
+
export const DIRECTION_ROOTS = { 'toggle-group': 'Root', 'radio-group': 'Root' };
|
|
84
|
+
/** Radix packages whose parts read the direction (useDirection), read from their installed sources. */
|
|
85
|
+
export const READS_DIRECTION = ['accordion', 'menubar', 'navigation-menu', 'radio-group', 'scroll-area', 'select', 'slider', 'tabs', 'toggle-group', 'dropdown-menu', 'context-menu'];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What Radix's modal dialog content does while it is mounted, as plain TypeScript with no framework (read from the
|
|
3
|
+
* installed `@radix-ui/react-focus-scope`, `react-dismissable-layer`, `react-focus-guards`, `react-dialog` and
|
|
4
|
+
* `aria-hidden`): written into the output by the Svelte and Angular alert-dialog cores, once per conversion that uses
|
|
5
|
+
* the package. FocusScope (loop, trapped while open): the mount autofocus event, focus kept inside, Tab and Shift+Tab
|
|
6
|
+
* looping between the first and last tabbable elements, the unmount autofocus event on the next task. DismissableLayer:
|
|
7
|
+
* Escape (a capturing keydown on the document) and the body's pointer events turned off while open. FocusGuards: two
|
|
8
|
+
* focusable spans at the body's edges. hideOthers: aria-hidden on the body's other children. RemoveScroll: the body's
|
|
9
|
+
* scroll locked while the overlay is mounted.
|
|
10
|
+
*/
|
|
11
|
+
export declare const MODAL_LAYER_SOURCE = "const AUTOFOCUS_ON_MOUNT = 'focusScope.autoFocusOnMount';\nconst AUTOFOCUS_ON_UNMOUNT = 'focusScope.autoFocusOnUnmount';\n\n/** What the framework gives the layer: the content element and Radix's callbacks, composed with the caller's. */\nexport interface ModalLayerHost {\n readonly container: HTMLElement;\n mountAutoFocus(event: Event): void;\n unmountAutoFocus(event: Event): void;\n escapeKeyDown(event: KeyboardEvent): void;\n}\n\nlet guards: { start: HTMLSpanElement; end: HTMLSpanElement } | null = null;\nlet guardCount = 0;\nlet pointerLayers = 0;\nlet originalPointerEvents = '';\n\nfunction createGuard(): HTMLSpanElement {\n const element = document.createElement('span');\n element.setAttribute('data-radix-focus-guard', '');\n element.tabIndex = 0;\n element.style.outline = 'none';\n element.style.opacity = '0';\n element.style.position = 'fixed';\n element.style.pointerEvents = 'none';\n return element;\n}\n\nfunction focusElement(element: HTMLElement | null | undefined, select = false): void {\n if (!element) return;\n const previous = document.activeElement;\n element.focus({ preventScroll: true });\n if (select && element !== previous && element instanceof HTMLInputElement) element.select();\n}\n\nfunction tabbables(container: HTMLElement): HTMLElement[] {\n const nodes: HTMLElement[] = [];\n const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {\n acceptNode: (node) => {\n if (!(node instanceof HTMLElement)) return NodeFilter.FILTER_SKIP;\n const hiddenInput = node instanceof HTMLInputElement && node.type === 'hidden';\n const disabled = 'disabled' in node && node.disabled === true;\n if (disabled || node.hidden || hiddenInput) return NodeFilter.FILTER_SKIP;\n return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;\n },\n });\n while (walker.nextNode()) if (walker.currentNode instanceof HTMLElement) nodes.push(walker.currentNode);\n return nodes;\n}\n\nfunction visible(elements: HTMLElement[], container: HTMLElement): HTMLElement | undefined {\n const check = typeof container.checkVisibility === 'function' && container.checkVisibility({ checkVisibilityCSS: true });\n for (const element of elements) {\n if (check ? element.checkVisibility({ checkVisibilityCSS: true }) : !hidden(element, container)) return element;\n }\n return undefined;\n}\n\nfunction hidden(node: HTMLElement, upTo: HTMLElement): boolean {\n if (getComputedStyle(node).visibility === 'hidden') return true;\n let current: HTMLElement | null = node;\n while (current) {\n if (current === upTo) return false;\n if (getComputedStyle(current).display === 'none') return true;\n current = current.parentElement;\n }\n return false;\n}\n\nexport class RadixModalLayer {\n private trapped = false;\n private lastFocused: HTMLElement | null = null;\n private previous: Element | null = null;\n private observer: MutationObserver | null = null;\n private hiddenOthers: HTMLElement[] = [];\n private mounted = false;\n\n constructor(private readonly host: ModalLayerHost) {}\n\n private readonly onFocusIn = (event: FocusEvent): void => {\n const target = event.target;\n if (target instanceof HTMLElement && this.host.container.contains(target)) this.lastFocused = target;\n else focusElement(this.lastFocused, true);\n };\n\n private readonly onFocusOut = (event: FocusEvent): void => {\n const related = event.relatedTarget;\n if (related === null) return;\n if (!(related instanceof Node) || !this.host.container.contains(related)) focusElement(this.lastFocused, true);\n };\n\n private readonly onMutations = (mutations: MutationRecord[]): void => {\n if (document.activeElement !== document.body) return;\n for (const mutation of mutations) if (mutation.removedNodes.length > 0) focusElement(this.host.container);\n };\n\n private readonly onEscape = (event: KeyboardEvent): void => {\n if (event.key === 'Escape') this.host.escapeKeyDown(event);\n };\n\n /** The content mounted: Radix's layer, focus scope, guards and hidden siblings start; `open` traps focus. */\n mount(open: boolean): void {\n if (this.mounted) return;\n this.mounted = true;\n const container = this.host.container;\n document.addEventListener('keydown', this.onEscape, { capture: true });\n this.setTrapped(open);\n this.previous = document.activeElement;\n if (!container.contains(this.previous)) {\n const event = new CustomEvent(AUTOFOCUS_ON_MOUNT, { bubbles: false, cancelable: true });\n const listener = (e: Event): void => this.host.mountAutoFocus(e);\n container.addEventListener(AUTOFOCUS_ON_MOUNT, listener);\n container.dispatchEvent(event);\n container.removeEventListener(AUTOFOCUS_ON_MOUNT, listener);\n if (!event.defaultPrevented) {\n const before = document.activeElement;\n for (const candidate of tabbables(container).filter((el) => el.tagName !== 'A')) {\n focusElement(candidate, true);\n if (document.activeElement !== before) break;\n }\n if (document.activeElement === this.previous) focusElement(container);\n }\n }\n if (!guards) guards = { start: createGuard(), end: createGuard() };\n if (document.body.firstElementChild !== guards.start) document.body.insertAdjacentElement('afterbegin', guards.start);\n if (document.body.lastElementChild !== guards.end) document.body.insertAdjacentElement('beforeend', guards.end);\n guardCount++;\n // aria-hidden on what else the body holds (live regions and what holds the content stay)\n for (const child of Array.from(document.body.children)) {\n if (!(child instanceof HTMLElement) || child.contains(container) || child === guards.start || child === guards.end) continue;\n if (child.hasAttribute('aria-live') || child.tagName === 'SCRIPT' || child.getAttribute('aria-hidden') === 'true') continue;\n child.setAttribute('aria-hidden', 'true');\n child.setAttribute('data-aria-hidden', 'true');\n this.hiddenOthers.push(child);\n }\n }\n\n /** Radix traps focus and turns the body's pointer events off while the dialog is open (not while it animates out). */\n setTrapped(open: boolean): void {\n if (open === this.trapped || !this.mounted) return;\n this.trapped = open;\n if (open) {\n document.addEventListener('focusin', this.onFocusIn);\n document.addEventListener('focusout', this.onFocusOut);\n this.observer = new MutationObserver(this.onMutations);\n this.observer.observe(this.host.container, { childList: true, subtree: true });\n if (pointerLayers === 0) {\n originalPointerEvents = document.body.style.pointerEvents;\n document.body.style.pointerEvents = 'none';\n }\n pointerLayers++;\n } else {\n document.removeEventListener('focusin', this.onFocusIn);\n document.removeEventListener('focusout', this.onFocusOut);\n this.observer?.disconnect();\n this.observer = null;\n pointerLayers = Math.max(0, pointerLayers - 1);\n if (pointerLayers === 0) document.body.style.pointerEvents = originalPointerEvents;\n }\n }\n\n /** Whether the body's pointer events are off for this layer (the content then takes them: pointer-events auto). */\n get disablesOutside(): boolean {\n return this.trapped;\n }\n\n /** The content's keydown (after the caller's own): Tab and Shift+Tab loop between its first and last tabbables. */\n keydown(event: KeyboardEvent): void {\n const tab = event.key === 'Tab' && !event.altKey && !event.ctrlKey && !event.metaKey;\n const focused = document.activeElement;\n if (!tab || !focused) return;\n const container = this.host.container;\n const candidates = tabbables(container);\n const first = visible(candidates, container);\n const last = visible([...candidates].reverse(), container);\n if (!first || !last) {\n if (focused === container) event.preventDefault();\n } else if (!event.shiftKey && focused === last) {\n event.preventDefault();\n focusElement(first, true);\n } else if (event.shiftKey && focused === first) {\n event.preventDefault();\n focusElement(last, true);\n }\n }\n\n /** The content left the page: everything stops, and focus returns on the next task (Radix's unmount autofocus). */\n unmount(): void {\n if (!this.mounted) return;\n this.setTrapped(false);\n this.mounted = false;\n document.removeEventListener('keydown', this.onEscape, { capture: true });\n for (const child of this.hiddenOthers) {\n child.removeAttribute('aria-hidden');\n child.removeAttribute('data-aria-hidden');\n }\n this.hiddenOthers = [];\n if (guardCount === 1) {\n guards?.start.remove();\n guards?.end.remove();\n guards = null;\n }\n guardCount = Math.max(0, guardCount - 1);\n const container = this.host.container;\n const previous = this.previous;\n setTimeout(() => {\n const event = new CustomEvent(AUTOFOCUS_ON_UNMOUNT, { bubbles: false, cancelable: true });\n const listener = (e: Event): void => this.host.unmountAutoFocus(e);\n container.addEventListener(AUTOFOCUS_ON_UNMOUNT, listener);\n container.dispatchEvent(event);\n container.removeEventListener(AUTOFOCUS_ON_UNMOUNT, listener);\n if (!event.defaultPrevented) focusElement(previous instanceof HTMLElement ? previous : document.body, true);\n }, 0);\n }\n}\n\nlet scrollLocks = 0;\nlet originalOverflow = '';\n\n/** Radix's RemoveScroll while an overlay is mounted: the body does not scroll (data-scroll-locked, as Radix marks it). */\nexport function lockScroll(): () => void {\n if (scrollLocks === 0) {\n originalOverflow = document.body.style.overflow;\n document.body.setAttribute('data-scroll-locked', '1');\n document.body.style.overflow = 'hidden';\n }\n scrollLocks++;\n return () => {\n scrollLocks = Math.max(0, scrollLocks - 1);\n if (scrollLocks > 0) return;\n document.body.removeAttribute('data-scroll-locked');\n document.body.style.overflow = originalOverflow;\n };\n}\n";
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What Radix's modal dialog content does while it is mounted, as plain TypeScript with no framework (read from the
|
|
3
|
+
* installed `@radix-ui/react-focus-scope`, `react-dismissable-layer`, `react-focus-guards`, `react-dialog` and
|
|
4
|
+
* `aria-hidden`): written into the output by the Svelte and Angular alert-dialog cores, once per conversion that uses
|
|
5
|
+
* the package. FocusScope (loop, trapped while open): the mount autofocus event, focus kept inside, Tab and Shift+Tab
|
|
6
|
+
* looping between the first and last tabbable elements, the unmount autofocus event on the next task. DismissableLayer:
|
|
7
|
+
* Escape (a capturing keydown on the document) and the body's pointer events turned off while open. FocusGuards: two
|
|
8
|
+
* focusable spans at the body's edges. hideOthers: aria-hidden on the body's other children. RemoveScroll: the body's
|
|
9
|
+
* scroll locked while the overlay is mounted.
|
|
10
|
+
*/
|
|
11
|
+
export const MODAL_LAYER_SOURCE = `const AUTOFOCUS_ON_MOUNT = 'focusScope.autoFocusOnMount';
|
|
12
|
+
const AUTOFOCUS_ON_UNMOUNT = 'focusScope.autoFocusOnUnmount';
|
|
13
|
+
|
|
14
|
+
/** What the framework gives the layer: the content element and Radix's callbacks, composed with the caller's. */
|
|
15
|
+
export interface ModalLayerHost {
|
|
16
|
+
readonly container: HTMLElement;
|
|
17
|
+
mountAutoFocus(event: Event): void;
|
|
18
|
+
unmountAutoFocus(event: Event): void;
|
|
19
|
+
escapeKeyDown(event: KeyboardEvent): void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let guards: { start: HTMLSpanElement; end: HTMLSpanElement } | null = null;
|
|
23
|
+
let guardCount = 0;
|
|
24
|
+
let pointerLayers = 0;
|
|
25
|
+
let originalPointerEvents = '';
|
|
26
|
+
|
|
27
|
+
function createGuard(): HTMLSpanElement {
|
|
28
|
+
const element = document.createElement('span');
|
|
29
|
+
element.setAttribute('data-radix-focus-guard', '');
|
|
30
|
+
element.tabIndex = 0;
|
|
31
|
+
element.style.outline = 'none';
|
|
32
|
+
element.style.opacity = '0';
|
|
33
|
+
element.style.position = 'fixed';
|
|
34
|
+
element.style.pointerEvents = 'none';
|
|
35
|
+
return element;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function focusElement(element: HTMLElement | null | undefined, select = false): void {
|
|
39
|
+
if (!element) return;
|
|
40
|
+
const previous = document.activeElement;
|
|
41
|
+
element.focus({ preventScroll: true });
|
|
42
|
+
if (select && element !== previous && element instanceof HTMLInputElement) element.select();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function tabbables(container: HTMLElement): HTMLElement[] {
|
|
46
|
+
const nodes: HTMLElement[] = [];
|
|
47
|
+
const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
|
|
48
|
+
acceptNode: (node) => {
|
|
49
|
+
if (!(node instanceof HTMLElement)) return NodeFilter.FILTER_SKIP;
|
|
50
|
+
const hiddenInput = node instanceof HTMLInputElement && node.type === 'hidden';
|
|
51
|
+
const disabled = 'disabled' in node && node.disabled === true;
|
|
52
|
+
if (disabled || node.hidden || hiddenInput) return NodeFilter.FILTER_SKIP;
|
|
53
|
+
return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
while (walker.nextNode()) if (walker.currentNode instanceof HTMLElement) nodes.push(walker.currentNode);
|
|
57
|
+
return nodes;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function visible(elements: HTMLElement[], container: HTMLElement): HTMLElement | undefined {
|
|
61
|
+
const check = typeof container.checkVisibility === 'function' && container.checkVisibility({ checkVisibilityCSS: true });
|
|
62
|
+
for (const element of elements) {
|
|
63
|
+
if (check ? element.checkVisibility({ checkVisibilityCSS: true }) : !hidden(element, container)) return element;
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function hidden(node: HTMLElement, upTo: HTMLElement): boolean {
|
|
69
|
+
if (getComputedStyle(node).visibility === 'hidden') return true;
|
|
70
|
+
let current: HTMLElement | null = node;
|
|
71
|
+
while (current) {
|
|
72
|
+
if (current === upTo) return false;
|
|
73
|
+
if (getComputedStyle(current).display === 'none') return true;
|
|
74
|
+
current = current.parentElement;
|
|
75
|
+
}
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export class RadixModalLayer {
|
|
80
|
+
private trapped = false;
|
|
81
|
+
private lastFocused: HTMLElement | null = null;
|
|
82
|
+
private previous: Element | null = null;
|
|
83
|
+
private observer: MutationObserver | null = null;
|
|
84
|
+
private hiddenOthers: HTMLElement[] = [];
|
|
85
|
+
private mounted = false;
|
|
86
|
+
|
|
87
|
+
constructor(private readonly host: ModalLayerHost) {}
|
|
88
|
+
|
|
89
|
+
private readonly onFocusIn = (event: FocusEvent): void => {
|
|
90
|
+
const target = event.target;
|
|
91
|
+
if (target instanceof HTMLElement && this.host.container.contains(target)) this.lastFocused = target;
|
|
92
|
+
else focusElement(this.lastFocused, true);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
private readonly onFocusOut = (event: FocusEvent): void => {
|
|
96
|
+
const related = event.relatedTarget;
|
|
97
|
+
if (related === null) return;
|
|
98
|
+
if (!(related instanceof Node) || !this.host.container.contains(related)) focusElement(this.lastFocused, true);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
private readonly onMutations = (mutations: MutationRecord[]): void => {
|
|
102
|
+
if (document.activeElement !== document.body) return;
|
|
103
|
+
for (const mutation of mutations) if (mutation.removedNodes.length > 0) focusElement(this.host.container);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
private readonly onEscape = (event: KeyboardEvent): void => {
|
|
107
|
+
if (event.key === 'Escape') this.host.escapeKeyDown(event);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/** The content mounted: Radix's layer, focus scope, guards and hidden siblings start; \`open\` traps focus. */
|
|
111
|
+
mount(open: boolean): void {
|
|
112
|
+
if (this.mounted) return;
|
|
113
|
+
this.mounted = true;
|
|
114
|
+
const container = this.host.container;
|
|
115
|
+
document.addEventListener('keydown', this.onEscape, { capture: true });
|
|
116
|
+
this.setTrapped(open);
|
|
117
|
+
this.previous = document.activeElement;
|
|
118
|
+
if (!container.contains(this.previous)) {
|
|
119
|
+
const event = new CustomEvent(AUTOFOCUS_ON_MOUNT, { bubbles: false, cancelable: true });
|
|
120
|
+
const listener = (e: Event): void => this.host.mountAutoFocus(e);
|
|
121
|
+
container.addEventListener(AUTOFOCUS_ON_MOUNT, listener);
|
|
122
|
+
container.dispatchEvent(event);
|
|
123
|
+
container.removeEventListener(AUTOFOCUS_ON_MOUNT, listener);
|
|
124
|
+
if (!event.defaultPrevented) {
|
|
125
|
+
const before = document.activeElement;
|
|
126
|
+
for (const candidate of tabbables(container).filter((el) => el.tagName !== 'A')) {
|
|
127
|
+
focusElement(candidate, true);
|
|
128
|
+
if (document.activeElement !== before) break;
|
|
129
|
+
}
|
|
130
|
+
if (document.activeElement === this.previous) focusElement(container);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (!guards) guards = { start: createGuard(), end: createGuard() };
|
|
134
|
+
if (document.body.firstElementChild !== guards.start) document.body.insertAdjacentElement('afterbegin', guards.start);
|
|
135
|
+
if (document.body.lastElementChild !== guards.end) document.body.insertAdjacentElement('beforeend', guards.end);
|
|
136
|
+
guardCount++;
|
|
137
|
+
// aria-hidden on what else the body holds (live regions and what holds the content stay)
|
|
138
|
+
for (const child of Array.from(document.body.children)) {
|
|
139
|
+
if (!(child instanceof HTMLElement) || child.contains(container) || child === guards.start || child === guards.end) continue;
|
|
140
|
+
if (child.hasAttribute('aria-live') || child.tagName === 'SCRIPT' || child.getAttribute('aria-hidden') === 'true') continue;
|
|
141
|
+
child.setAttribute('aria-hidden', 'true');
|
|
142
|
+
child.setAttribute('data-aria-hidden', 'true');
|
|
143
|
+
this.hiddenOthers.push(child);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Radix traps focus and turns the body's pointer events off while the dialog is open (not while it animates out). */
|
|
148
|
+
setTrapped(open: boolean): void {
|
|
149
|
+
if (open === this.trapped || !this.mounted) return;
|
|
150
|
+
this.trapped = open;
|
|
151
|
+
if (open) {
|
|
152
|
+
document.addEventListener('focusin', this.onFocusIn);
|
|
153
|
+
document.addEventListener('focusout', this.onFocusOut);
|
|
154
|
+
this.observer = new MutationObserver(this.onMutations);
|
|
155
|
+
this.observer.observe(this.host.container, { childList: true, subtree: true });
|
|
156
|
+
if (pointerLayers === 0) {
|
|
157
|
+
originalPointerEvents = document.body.style.pointerEvents;
|
|
158
|
+
document.body.style.pointerEvents = 'none';
|
|
159
|
+
}
|
|
160
|
+
pointerLayers++;
|
|
161
|
+
} else {
|
|
162
|
+
document.removeEventListener('focusin', this.onFocusIn);
|
|
163
|
+
document.removeEventListener('focusout', this.onFocusOut);
|
|
164
|
+
this.observer?.disconnect();
|
|
165
|
+
this.observer = null;
|
|
166
|
+
pointerLayers = Math.max(0, pointerLayers - 1);
|
|
167
|
+
if (pointerLayers === 0) document.body.style.pointerEvents = originalPointerEvents;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Whether the body's pointer events are off for this layer (the content then takes them: pointer-events auto). */
|
|
172
|
+
get disablesOutside(): boolean {
|
|
173
|
+
return this.trapped;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** The content's keydown (after the caller's own): Tab and Shift+Tab loop between its first and last tabbables. */
|
|
177
|
+
keydown(event: KeyboardEvent): void {
|
|
178
|
+
const tab = event.key === 'Tab' && !event.altKey && !event.ctrlKey && !event.metaKey;
|
|
179
|
+
const focused = document.activeElement;
|
|
180
|
+
if (!tab || !focused) return;
|
|
181
|
+
const container = this.host.container;
|
|
182
|
+
const candidates = tabbables(container);
|
|
183
|
+
const first = visible(candidates, container);
|
|
184
|
+
const last = visible([...candidates].reverse(), container);
|
|
185
|
+
if (!first || !last) {
|
|
186
|
+
if (focused === container) event.preventDefault();
|
|
187
|
+
} else if (!event.shiftKey && focused === last) {
|
|
188
|
+
event.preventDefault();
|
|
189
|
+
focusElement(first, true);
|
|
190
|
+
} else if (event.shiftKey && focused === first) {
|
|
191
|
+
event.preventDefault();
|
|
192
|
+
focusElement(last, true);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** The content left the page: everything stops, and focus returns on the next task (Radix's unmount autofocus). */
|
|
197
|
+
unmount(): void {
|
|
198
|
+
if (!this.mounted) return;
|
|
199
|
+
this.setTrapped(false);
|
|
200
|
+
this.mounted = false;
|
|
201
|
+
document.removeEventListener('keydown', this.onEscape, { capture: true });
|
|
202
|
+
for (const child of this.hiddenOthers) {
|
|
203
|
+
child.removeAttribute('aria-hidden');
|
|
204
|
+
child.removeAttribute('data-aria-hidden');
|
|
205
|
+
}
|
|
206
|
+
this.hiddenOthers = [];
|
|
207
|
+
if (guardCount === 1) {
|
|
208
|
+
guards?.start.remove();
|
|
209
|
+
guards?.end.remove();
|
|
210
|
+
guards = null;
|
|
211
|
+
}
|
|
212
|
+
guardCount = Math.max(0, guardCount - 1);
|
|
213
|
+
const container = this.host.container;
|
|
214
|
+
const previous = this.previous;
|
|
215
|
+
setTimeout(() => {
|
|
216
|
+
const event = new CustomEvent(AUTOFOCUS_ON_UNMOUNT, { bubbles: false, cancelable: true });
|
|
217
|
+
const listener = (e: Event): void => this.host.unmountAutoFocus(e);
|
|
218
|
+
container.addEventListener(AUTOFOCUS_ON_UNMOUNT, listener);
|
|
219
|
+
container.dispatchEvent(event);
|
|
220
|
+
container.removeEventListener(AUTOFOCUS_ON_UNMOUNT, listener);
|
|
221
|
+
if (!event.defaultPrevented) focusElement(previous instanceof HTMLElement ? previous : document.body, true);
|
|
222
|
+
}, 0);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
let scrollLocks = 0;
|
|
227
|
+
let originalOverflow = '';
|
|
228
|
+
|
|
229
|
+
/** Radix's RemoveScroll while an overlay is mounted: the body does not scroll (data-scroll-locked, as Radix marks it). */
|
|
230
|
+
export function lockScroll(): () => void {
|
|
231
|
+
if (scrollLocks === 0) {
|
|
232
|
+
originalOverflow = document.body.style.overflow;
|
|
233
|
+
document.body.setAttribute('data-scroll-locked', '1');
|
|
234
|
+
document.body.style.overflow = 'hidden';
|
|
235
|
+
}
|
|
236
|
+
scrollLocks++;
|
|
237
|
+
return () => {
|
|
238
|
+
scrollLocks = Math.max(0, scrollLocks - 1);
|
|
239
|
+
if (scrollLocks > 0) return;
|
|
240
|
+
document.body.removeAttribute('data-scroll-locked');
|
|
241
|
+
document.body.style.overflow = originalOverflow;
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
`;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Radix's Presence (`@radix-ui/react-presence`, read from its installed source), as plain TypeScript with no framework:
|
|
3
|
+
* the state machine that keeps a part mounted while its exit animation runs. Written into the output by the Svelte and
|
|
4
|
+
* the Angular cores that need it (collapsible, alert-dialog), once per conversion.
|
|
5
|
+
*
|
|
6
|
+
* Radix: `mounted` --UNMOUNT--> `unmounted`, `mounted` --ANIMATION_OUT--> `unmountSuspended`, `unmountSuspended`
|
|
7
|
+
* --MOUNT--> `mounted` / --ANIMATION_END--> `unmounted`, `unmounted` --MOUNT--> `mounted`. When `present` turns false:
|
|
8
|
+
* no animation (`animation-name: none`) or a `display: none` node unmounts at once; an animation name other than the one
|
|
9
|
+
* the node mounted with (the exit animation the closed state's classes start) suspends the unmount until that animation
|
|
10
|
+
* ends or is cancelled; anything else unmounts.
|
|
11
|
+
*/
|
|
12
|
+
export declare const PRESENCE_SOURCE = "/**\n * Radix's Presence as plain TypeScript: a part stays mounted while its exit animation runs. `update(present)` after the\n * element shows the new state; `attach(node)` when the element mounts (null when it leaves); `destroy()` on unmount.\n */\nexport class RadixPresence {\n private state: 'mounted' | 'unmountSuspended' | 'unmounted';\n private node: HTMLElement | null = null;\n private styles: CSSStyleDeclaration | null = null;\n private prevPresent: boolean;\n private prevAnimationName = 'none';\n private mountAnimationName: string | undefined = undefined;\n private timeout: ReturnType<typeof setTimeout> | undefined = undefined;\n\n constructor(\n present: boolean,\n private readonly changed: (isPresent: boolean) => void,\n ) {\n this.state = present ? 'mounted' : 'unmounted';\n this.prevPresent = present;\n }\n\n /** Whether the part is mounted (shown, or running its exit animation). */\n get isPresent(): boolean {\n return this.state !== 'unmounted';\n }\n\n private send(event: 'MOUNT' | 'UNMOUNT' | 'ANIMATION_OUT' | 'ANIMATION_END'): void {\n const before = this.state;\n let next = before;\n if (before === 'mounted' && event === 'UNMOUNT') next = 'unmounted';\n else if (before === 'mounted' && event === 'ANIMATION_OUT') next = 'unmountSuspended';\n else if (before === 'unmountSuspended' && event === 'MOUNT') next = 'mounted';\n else if (before === 'unmountSuspended' && event === 'ANIMATION_END') next = 'unmounted';\n else if (before === 'unmounted' && event === 'MOUNT') next = 'mounted';\n if (next === before) return;\n this.state = next;\n if (next === 'mounted') {\n this.prevAnimationName = this.mountAnimationName ?? animationName(this.styles);\n this.mountAnimationName = undefined;\n } else this.prevAnimationName = 'none';\n if ((before === 'unmounted') !== (next === 'unmounted')) this.changed(this.isPresent);\n }\n\n /** The present prop changed (or may have): called after the element shows the new state. */\n update(present: boolean): void {\n const wasPresent = this.prevPresent;\n if (wasPresent === present) return;\n const current = animationName(this.styles);\n this.prevPresent = present;\n if (present) {\n this.mountAnimationName = current;\n this.send('MOUNT');\n } else if (current === 'none' || this.styles?.display === 'none') this.send('UNMOUNT');\n else if (wasPresent && this.prevAnimationName !== current) this.send('ANIMATION_OUT');\n else this.send('UNMOUNT');\n }\n\n private readonly onStart = (event: AnimationEvent): void => {\n if (event.target === this.node) this.prevAnimationName = animationName(this.styles);\n };\n\n private readonly onEnd = (event: AnimationEvent): void => {\n const node = this.node;\n if (!node || event.target !== node || !animationName(this.styles).includes(CSS.escape(event.animationName))) return;\n this.send('ANIMATION_END');\n if (this.prevPresent) return;\n // Radix holds the last frame until the node is gone, so it does not flash back to its resting style\n const fill = node.style.animationFillMode;\n node.style.animationFillMode = 'forwards';\n clearTimeout(this.timeout);\n this.timeout = setTimeout(() => {\n if (node.style.animationFillMode === 'forwards') node.style.animationFillMode = fill;\n });\n };\n\n /** The element mounted (or left: null). */\n attach(node: HTMLElement | null): void {\n if (node === this.node) return;\n this.detach();\n this.node = node;\n if (!node) {\n this.styles = null;\n this.send('ANIMATION_END');\n return;\n }\n this.styles = getComputedStyle(node);\n this.mountAnimationName = animationName(this.styles);\n if (this.state === 'mounted') {\n this.prevAnimationName = this.mountAnimationName;\n this.mountAnimationName = undefined;\n }\n node.addEventListener('animationstart', this.onStart);\n node.addEventListener('animationcancel', this.onEnd);\n node.addEventListener('animationend', this.onEnd);\n }\n\n private detach(): void {\n clearTimeout(this.timeout);\n this.timeout = undefined;\n const node = this.node;\n if (!node) return;\n node.removeEventListener('animationstart', this.onStart);\n node.removeEventListener('animationcancel', this.onEnd);\n node.removeEventListener('animationend', this.onEnd);\n }\n\n /** The part is gone: no listener or timer is left. */\n destroy(): void {\n this.detach();\n this.node = null;\n this.styles = null;\n }\n}\n\nfunction animationName(styles: CSSStyleDeclaration | null): string {\n return styles?.animationName || 'none';\n}\n";
|