@ohos-ports/stacksjs-stx 0.2.287-beta.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.md +21 -0
- package/README.md +1042 -0
- package/dist/a11y.d.ts +256 -0
- package/dist/a11y.js +671 -0
- package/dist/analytics.d.ts +40 -0
- package/dist/analytics.js +159 -0
- package/dist/analyzer.d.ts +68 -0
- package/dist/analyzer.js +240 -0
- package/dist/animation.d.ts +123 -0
- package/dist/animation.js +688 -0
- package/dist/app-shell.d.ts +76 -0
- package/dist/app-shell.js +209 -0
- package/dist/app.d.ts +65 -0
- package/dist/app.js +79 -0
- package/dist/appearance-bootstrap.d.ts +54 -0
- package/dist/appearance-bootstrap.js +92 -0
- package/dist/asset-roots.d.ts +32 -0
- package/dist/asset-roots.js +7 -0
- package/dist/assets.d.ts +21 -0
- package/dist/assets.js +155 -0
- package/dist/ast.d.ts +265 -0
- package/dist/ast.js +630 -0
- package/dist/async-components.d.ts +123 -0
- package/dist/async-components.js +428 -0
- package/dist/auth.d.ts +13 -0
- package/dist/auth.js +12 -0
- package/dist/broadcasting.d.ts +77 -0
- package/dist/broadcasting.js +103 -0
- package/dist/browser-composables.d.ts +348 -0
- package/dist/browser-composables.js +606 -0
- package/dist/browser-core-imports.d.ts +12 -0
- package/dist/browser-core-imports.js +28 -0
- package/dist/build-assets.d.ts +32 -0
- package/dist/build-assets.js +29 -0
- package/dist/build-externalize-repeated.d.ts +34 -0
- package/dist/build-externalize-repeated.js +101 -0
- package/dist/build-externalize.d.ts +73 -0
- package/dist/build-externalize.js +80 -0
- package/dist/build-id.d.ts +57 -0
- package/dist/build-id.js +25 -0
- package/dist/build-message.d.ts +81 -0
- package/dist/build-message.js +65 -0
- package/dist/build-mode-detector.d.ts +26 -0
- package/dist/build-mode-detector.js +50 -0
- package/dist/build-optimizer.d.ts +101 -0
- package/dist/build-optimizer.js +433 -0
- package/dist/build-views.d.ts +56 -0
- package/dist/build-views.js +180 -0
- package/dist/build.d.ts +31 -0
- package/dist/build.js +34 -0
- package/dist/builtins/attrs.d.ts +49 -0
- package/dist/builtins/attrs.js +39 -0
- package/dist/builtins/drawer.d.ts +24 -0
- package/dist/builtins/drawer.js +37 -0
- package/dist/builtins/escape.d.ts +12 -0
- package/dist/builtins/escape.js +3 -0
- package/dist/builtins/icon.d.ts +45 -0
- package/dist/builtins/icon.js +100 -0
- package/dist/builtins/image-delivery.d.ts +16 -0
- package/dist/builtins/image-delivery.js +115 -0
- package/dist/builtins/image-placeholder.d.ts +78 -0
- package/dist/builtins/image-placeholder.js +137 -0
- package/dist/builtins/index.d.ts +26 -0
- package/dist/builtins/index.js +34 -0
- package/dist/builtins/modal.d.ts +26 -0
- package/dist/builtins/modal.js +38 -0
- package/dist/builtins/safe-image.d.ts +44 -0
- package/dist/builtins/safe-image.js +45 -0
- package/dist/builtins/stx-image.d.ts +29 -0
- package/dist/builtins/stx-image.js +222 -0
- package/dist/builtins/stx-link.d.ts +11 -0
- package/dist/builtins/stx-link.js +35 -0
- package/dist/builtins/stx-loading-indicator.d.ts +13 -0
- package/dist/builtins/stx-loading-indicator.js +35 -0
- package/dist/builtins/suspense.d.ts +30 -0
- package/dist/builtins/suspense.js +24 -0
- package/dist/builtins/toast.d.ts +19 -0
- package/dist/builtins/toast.js +42 -0
- package/dist/builtins/tooltip.d.ts +18 -0
- package/dist/builtins/tooltip.js +106 -0
- package/dist/builtins/transition-group.d.ts +27 -0
- package/dist/builtins/transition-group.js +22 -0
- package/dist/bun-shim.js +496 -0
- package/dist/bundle-analyzer/collector.d.ts +66 -0
- package/dist/bundle-analyzer/collector.js +233 -0
- package/dist/bundle-analyzer/index.d.ts +98 -0
- package/dist/bundle-analyzer/index.js +82 -0
- package/dist/bundle-analyzer/report.d.ts +39 -0
- package/dist/bundle-analyzer/report.js +318 -0
- package/dist/bundle-analyzer/treemap.d.ts +19 -0
- package/dist/bundle-analyzer/treemap.js +594 -0
- package/dist/bundle-analyzer.js +499 -0
- package/dist/caching.d.ts +69 -0
- package/dist/caching.js +135 -0
- package/dist/chunk-0y46fbkx.js +3 -0
- package/dist/chunk-122tyfre.js +2 -0
- package/dist/chunk-19nfvxfw.js +43 -0
- package/dist/chunk-1kah92n2.js +3 -0
- package/dist/chunk-1kms3b9d.js +2 -0
- package/dist/chunk-1q4y74mh.js +1194 -0
- package/dist/chunk-248e84r1.js +4 -0
- package/dist/chunk-24ps8kft.js +2 -0
- package/dist/chunk-2et5hxfv.js +2 -0
- package/dist/chunk-2r1rd8f0.js +2 -0
- package/dist/chunk-2tk1zkrz.js +2 -0
- package/dist/chunk-38ejahd9.js +3 -0
- package/dist/chunk-3zv4wz87.js +2 -0
- package/dist/chunk-4122k1bh.js +2 -0
- package/dist/chunk-45az9zht.js +2 -0
- package/dist/chunk-4qr85f07.js +2 -0
- package/dist/chunk-4ww3znrr.js +15 -0
- package/dist/chunk-54st8g2j.js +397 -0
- package/dist/chunk-58f0mthg.js +3 -0
- package/dist/chunk-5a19dhx5.js +2 -0
- package/dist/chunk-5kk8gsj2.js +3 -0
- package/dist/chunk-5w1e3yxs.js +499 -0
- package/dist/chunk-6gdycmxr.js +2 -0
- package/dist/chunk-6hmnaza7.js +4473 -0
- package/dist/chunk-71t0yan0.js +5 -0
- package/dist/chunk-74cv4ta1.js +3 -0
- package/dist/chunk-74v15e8z.js +2 -0
- package/dist/chunk-7b329e5v.js +3 -0
- package/dist/chunk-7q9mwh4v.js +84 -0
- package/dist/chunk-866y9d8b.js +8169 -0
- package/dist/chunk-8fwerspy.js +2 -0
- package/dist/chunk-8mjdpr94.js +147 -0
- package/dist/chunk-92mj1t26.js +60 -0
- package/dist/chunk-9b22663r.js +2 -0
- package/dist/chunk-9hjdgm4d.js +2 -0
- package/dist/chunk-9n0gvfrg.js +4 -0
- package/dist/chunk-9wr7zcad.js +18 -0
- package/dist/chunk-9y0g8kzt.js +358 -0
- package/dist/chunk-a0nfbmeh.js +3 -0
- package/dist/chunk-acn1b56m.js +1280 -0
- package/dist/chunk-awkq3xfx.js +2 -0
- package/dist/chunk-b6ej2fdf.js +1814 -0
- package/dist/chunk-b8rrnqry.js +2 -0
- package/dist/chunk-bfqfs07m.js +3022 -0
- package/dist/chunk-bs6kapy7.js +2 -0
- package/dist/chunk-btav940g.js +2 -0
- package/dist/chunk-bz820epz.js +3 -0
- package/dist/chunk-ccspd3mc.js +2 -0
- package/dist/chunk-csbgwaa5.js +2 -0
- package/dist/chunk-d8t4sjsp.js +2 -0
- package/dist/chunk-dap191q2.js +2 -0
- package/dist/chunk-de7fye10.js +4 -0
- package/dist/chunk-dgrt76d2.js +2 -0
- package/dist/chunk-dhh5q7qt.js +3 -0
- package/dist/chunk-dsffsqnt.js +2 -0
- package/dist/chunk-dtq7y5ym.js +2 -0
- package/dist/chunk-fed3xsp9.js +3 -0
- package/dist/chunk-ferav3bw.js +19 -0
- package/dist/chunk-fvhm8psm.js +3 -0
- package/dist/chunk-g4vpzv6b.js +2 -0
- package/dist/chunk-g9csmj0s.js +2 -0
- package/dist/chunk-gtcrpmz1.js +2 -0
- package/dist/chunk-h4xh8cms.js +4 -0
- package/dist/chunk-h8yqsz9m.js +2 -0
- package/dist/chunk-hcq5dw7a.js +2 -0
- package/dist/chunk-hm0xha6c.js +12 -0
- package/dist/chunk-hpybjwwf.js +8 -0
- package/dist/chunk-jegt35zh.js +2 -0
- package/dist/chunk-jr3jp3ev.js +8 -0
- package/dist/chunk-k56rjjc0.js +24 -0
- package/dist/chunk-kdh37tp8.js +194 -0
- package/dist/chunk-kxzb4et3.js +29 -0
- package/dist/chunk-mf4n3x1j.js +14 -0
- package/dist/chunk-mkd9kjgb.js +3 -0
- package/dist/chunk-mxfh1nxg.js +2 -0
- package/dist/chunk-n3ggrhb3.js +3 -0
- package/dist/chunk-nkb3scg6.js +8 -0
- package/dist/chunk-nnd4wq8j.js +231 -0
- package/dist/chunk-nsp1cw38.js +11 -0
- package/dist/chunk-nx5qkm8k.js +30 -0
- package/dist/chunk-p3242nck.js +2 -0
- package/dist/chunk-p98kfh94.js +2 -0
- package/dist/chunk-pkaabd8h.js +3 -0
- package/dist/chunk-pzm13sdc.js +3 -0
- package/dist/chunk-q4p5k2p3.js +2 -0
- package/dist/chunk-q9n5swx7.js +3 -0
- package/dist/chunk-qc1f74ek.js +3 -0
- package/dist/chunk-qpyjak7z.js +2 -0
- package/dist/chunk-qr82je1m.js +22 -0
- package/dist/chunk-qy73j6m4.js +288 -0
- package/dist/chunk-qzkhpsam.js +505 -0
- package/dist/chunk-r3ayvdz3.js +2 -0
- package/dist/chunk-r7r66978.js +2 -0
- package/dist/chunk-rbb7dvja.js +30 -0
- package/dist/chunk-refwkt87.js +71 -0
- package/dist/chunk-rj4kajww.js +2 -0
- package/dist/chunk-rp4rjjmf.js +2 -0
- package/dist/chunk-se0p17c2.js +898 -0
- package/dist/chunk-sj9pmene.js +2 -0
- package/dist/chunk-sscwkffs.js +2 -0
- package/dist/chunk-svpqxn2c.js +2 -0
- package/dist/chunk-t6nseeb9.js +351 -0
- package/dist/chunk-t8y1ggdy.js +2 -0
- package/dist/chunk-tndhnk9e.js +2 -0
- package/dist/chunk-v5e1gxwm.js +3 -0
- package/dist/chunk-vqxmxgaj.js +4 -0
- package/dist/chunk-vrrax298.js +2 -0
- package/dist/chunk-w3ycm4na.js +3 -0
- package/dist/chunk-wcm80anz.js +321 -0
- package/dist/chunk-wrzwgkbx.js +22 -0
- package/dist/chunk-x650vjcp.js +302 -0
- package/dist/chunk-xgnc1wy6.js +116 -0
- package/dist/chunk-xpp135ad.js +11 -0
- package/dist/chunk-xttsqmkm.js +216 -0
- package/dist/chunk-y11cxbxd.js +3757 -0
- package/dist/chunk-y7m2dpd3.js +341 -0
- package/dist/chunk-y98jsjqq.js +2 -0
- package/dist/chunk-ya386h70.js +2 -0
- package/dist/chunk-ydrz60kr.js +2 -0
- package/dist/chunk-ypmqf7tm.js +4 -0
- package/dist/chunk-z4jhj5e5.js +28 -0
- package/dist/chunk-zg75gjns.js +2 -0
- package/dist/chunk-zqqx1qaj.js +2 -0
- package/dist/cli-flags.d.ts +34 -0
- package/dist/cli-flags.js +20 -0
- package/dist/cli.js +174 -0
- package/dist/client/directive.d.ts +17 -0
- package/dist/client/directive.js +14 -0
- package/dist/client/index.d.ts +7 -0
- package/dist/client/index.js +2 -0
- package/dist/client-helpers.d.ts +317 -0
- package/dist/client-helpers.js +312 -0
- package/dist/client-script-bundler.d.ts +103 -0
- package/dist/client-script-bundler.js +390 -0
- package/dist/client-script.d.ts +215 -0
- package/dist/client-script.js +865 -0
- package/dist/client.d.ts +21 -0
- package/dist/client.js +73 -0
- package/dist/codemod.d.ts +33 -0
- package/dist/codemod.js +244 -0
- package/dist/color-mode-boot.d.ts +92 -0
- package/dist/color-mode-boot.js +72 -0
- package/dist/component-client-factories.d.ts +33 -0
- package/dist/component-client-factories.js +77 -0
- package/dist/component-hmr.d.ts +107 -0
- package/dist/component-hmr.js +585 -0
- package/dist/component-library.d.ts +38 -0
- package/dist/component-library.js +994 -0
- package/dist/component-processing.d.ts +198 -0
- package/dist/component-processing.js +677 -0
- package/dist/component-registry.d.ts +127 -0
- package/dist/component-registry.js +90 -0
- package/dist/component-renderer.d.ts +52 -0
- package/dist/component-renderer.js +790 -0
- package/dist/components/StxImage.stx +12 -0
- package/dist/components/StxLink.stx +18 -0
- package/dist/components.d.ts +28 -0
- package/dist/components.js +213 -0
- package/dist/composable-loader.d.ts +62 -0
- package/dist/composable-loader.js +190 -0
- package/dist/composables/index.d.ts +417 -0
- package/dist/composables/index.js +222 -0
- package/dist/composables/use-battery.d.ts +46 -0
- package/dist/composables/use-battery.js +101 -0
- package/dist/composables/use-broadcast-channel.d.ts +59 -0
- package/dist/composables/use-broadcast-channel.js +80 -0
- package/dist/composables/use-channel.d.ts +67 -0
- package/dist/composables/use-channel.js +124 -0
- package/dist/composables/use-clipboard.d.ts +30 -0
- package/dist/composables/use-clipboard.js +90 -0
- package/dist/composables/use-color-mode.d.ts +67 -0
- package/dist/composables/use-color-mode.js +152 -0
- package/dist/composables/use-cookie.d.ts +59 -0
- package/dist/composables/use-cookie.js +86 -0
- package/dist/composables/use-device-orientation.d.ts +116 -0
- package/dist/composables/use-device-orientation.js +181 -0
- package/dist/composables/use-event-listener.d.ts +35 -0
- package/dist/composables/use-event-listener.js +27 -0
- package/dist/composables/use-event-source.d.ts +90 -0
- package/dist/composables/use-event-source.js +166 -0
- package/dist/composables/use-eye-dropper.d.ts +117 -0
- package/dist/composables/use-eye-dropper.js +142 -0
- package/dist/composables/use-fetch.d.ts +59 -0
- package/dist/composables/use-fetch.js +273 -0
- package/dist/composables/use-form.d.ts +91 -0
- package/dist/composables/use-form.js +112 -0
- package/dist/composables/use-fullscreen.d.ts +47 -0
- package/dist/composables/use-fullscreen.js +110 -0
- package/dist/composables/use-geolocation.d.ts +62 -0
- package/dist/composables/use-geolocation.js +101 -0
- package/dist/composables/use-idle.d.ts +102 -0
- package/dist/composables/use-idle.js +182 -0
- package/dist/composables/use-intersection-observer.d.ts +83 -0
- package/dist/composables/use-intersection-observer.js +168 -0
- package/dist/composables/use-keyboard.d.ts +100 -0
- package/dist/composables/use-keyboard.js +224 -0
- package/dist/composables/use-media-query.d.ts +56 -0
- package/dist/composables/use-media-query.js +62 -0
- package/dist/composables/use-meta.d.ts +35 -0
- package/dist/composables/use-meta.js +48 -0
- package/dist/composables/use-mouse.d.ts +65 -0
- package/dist/composables/use-mouse.js +286 -0
- package/dist/composables/use-mutation-observer.d.ts +101 -0
- package/dist/composables/use-mutation-observer.js +129 -0
- package/dist/composables/use-network.d.ts +40 -0
- package/dist/composables/use-network.js +85 -0
- package/dist/composables/use-notification.d.ts +98 -0
- package/dist/composables/use-notification.js +94 -0
- package/dist/composables/use-permissions.d.ts +119 -0
- package/dist/composables/use-permissions.js +132 -0
- package/dist/composables/use-query.d.ts +48 -0
- package/dist/composables/use-query.js +0 -0
- package/dist/composables/use-resize-observer.d.ts +60 -0
- package/dist/composables/use-resize-observer.js +157 -0
- package/dist/composables/use-router.d.ts +80 -0
- package/dist/composables/use-router.js +105 -0
- package/dist/composables/use-scroll-lock.d.ts +13 -0
- package/dist/composables/use-scroll-lock.js +55 -0
- package/dist/composables/use-share.d.ts +74 -0
- package/dist/composables/use-share.js +104 -0
- package/dist/composables/use-speech.d.ts +117 -0
- package/dist/composables/use-speech.js +294 -0
- package/dist/composables/use-storage.d.ts +69 -0
- package/dist/composables/use-storage.js +196 -0
- package/dist/composables/use-text-selection.d.ts +121 -0
- package/dist/composables/use-text-selection.js +205 -0
- package/dist/composables/use-timer.d.ts +92 -0
- package/dist/composables/use-timer.js +193 -0
- package/dist/composables/use-utilities.d.ts +103 -0
- package/dist/composables/use-utilities.js +176 -0
- package/dist/composables/use-wake-lock.d.ts +85 -0
- package/dist/composables/use-wake-lock.js +122 -0
- package/dist/composables/use-websocket.d.ts +70 -0
- package/dist/composables/use-websocket.js +165 -0
- package/dist/composables/use-window.d.ts +84 -0
- package/dist/composables/use-window.js +163 -0
- package/dist/composables.d.ts +287 -0
- package/dist/composables.js +562 -0
- package/dist/composition-api.d.ts +197 -0
- package/dist/composition-api.js +199 -0
- package/dist/compression.d.ts +30 -0
- package/dist/compression.js +107 -0
- package/dist/computed.d.ts +138 -0
- package/dist/computed.js +382 -0
- package/dist/conditionals.d.ts +48 -0
- package/dist/conditionals.js +626 -0
- package/dist/config.d.ts +77 -0
- package/dist/config.js +828 -0
- package/dist/cookie-serialize.d.ts +40 -0
- package/dist/cookie-serialize.js +18 -0
- package/dist/craft-bridge.d.ts +525 -0
- package/dist/craft-bridge.js +511 -0
- package/dist/craft-compiler.d.ts +245 -0
- package/dist/craft-compiler.js +810 -0
- package/dist/craft-components.d.ts +739 -0
- package/dist/craft-components.js +1074 -0
- package/dist/craft-entry.d.ts +6 -0
- package/dist/craft-entry.js +9 -0
- package/dist/craft-ssr.d.ts +147 -0
- package/dist/craft-ssr.js +559 -0
- package/dist/craft.js +9 -0
- package/dist/csp.d.ts +295 -0
- package/dist/csp.js +220 -0
- package/dist/csrf.d.ts +38 -0
- package/dist/csrf.js +38 -0
- package/dist/custom-directives.d.ts +5 -0
- package/dist/custom-directives.js +136 -0
- package/dist/database.d.ts +391 -0
- package/dist/database.js +5 -0
- package/dist/defer.d.ts +28 -0
- package/dist/defer.js +156 -0
- package/dist/deploy/config-generators.d.ts +75 -0
- package/dist/deploy/config-generators.js +214 -0
- package/dist/deploy/index.d.ts +88 -0
- package/dist/deploy/index.js +203 -0
- package/dist/deploy/netlify.d.ts +109 -0
- package/dist/deploy/netlify.js +167 -0
- package/dist/desktop.d.ts +16 -0
- package/dist/desktop.js +1 -0
- package/dist/dev-server/index.d.ts +22 -0
- package/dist/dev-server/index.js +7 -0
- package/dist/dev-server/keyboard-shortcuts.d.ts +34 -0
- package/dist/dev-server/keyboard-shortcuts.js +81 -0
- package/dist/dev-server/native-window.d.ts +59 -0
- package/dist/dev-server/native-window.js +91 -0
- package/dist/dev-server/port-utils.d.ts +27 -0
- package/dist/dev-server/port-utils.js +40 -0
- package/dist/dev-server/serve-app.d.ts +15 -0
- package/dist/dev-server/serve-app.js +727 -0
- package/dist/dev-server/serve-file.d.ts +3 -0
- package/dist/dev-server/serve-file.js +443 -0
- package/dist/dev-server/serve-markdown.d.ts +3 -0
- package/dist/dev-server/serve-markdown.js +284 -0
- package/dist/dev-server/serve-multi.d.ts +5 -0
- package/dist/dev-server/serve-multi.js +596 -0
- package/dist/dev-server/terminal-colors.d.ts +56 -0
- package/dist/dev-server/terminal-colors.js +45 -0
- package/dist/dev-server/theme-selector.d.ts +32 -0
- package/dist/dev-server/theme-selector.js +111 -0
- package/dist/dev-server/ts-css.d.ts +108 -0
- package/dist/dev-server/ts-css.js +438 -0
- package/dist/dev-server/types.d.ts +99 -0
- package/dist/dev-server/types.js +43 -0
- package/dist/dev-server.d.ts +6 -0
- package/dist/dev-server.js +4 -0
- package/dist/devtools.d.ts +182 -0
- package/dist/devtools.js +593 -0
- package/dist/directive-api.d.ts +154 -0
- package/dist/directive-api.js +355 -0
- package/dist/docs.d.ts +56 -0
- package/dist/docs.js +567 -0
- package/dist/doctor.d.ts +29 -0
- package/dist/doctor.js +123 -0
- package/dist/document-shell.d.ts +218 -0
- package/dist/document-shell.js +338 -0
- package/dist/dynamic-components.d.ts +23 -0
- package/dist/dynamic-components.js +197 -0
- package/dist/edge-runtime.d.ts +193 -0
- package/dist/edge-runtime.js +525 -0
- package/dist/env.d.ts +3 -0
- package/dist/env.js +9 -0
- package/dist/error-boundaries.d.ts +78 -0
- package/dist/error-boundaries.js +281 -0
- package/dist/error-handling.d.ts +14 -0
- package/dist/error-handling.js +1 -0
- package/dist/errors/codes.d.ts +92 -0
- package/dist/errors/codes.js +97 -0
- package/dist/errors/formatter.d.ts +84 -0
- package/dist/errors/formatter.js +196 -0
- package/dist/errors/index.d.ts +12 -0
- package/dist/errors/index.js +44 -0
- package/dist/errors/logger.d.ts +135 -0
- package/dist/errors/logger.js +250 -0
- package/dist/errors/sanitizer.d.ts +73 -0
- package/dist/errors/sanitizer.js +181 -0
- package/dist/errors/types.d.ts +92 -0
- package/dist/errors/types.js +86 -0
- package/dist/events.d.ts +145 -0
- package/dist/events.js +396 -0
- package/dist/expressions.d.ts +180 -0
- package/dist/expressions.js +719 -0
- package/dist/find-body-tag.d.ts +50 -0
- package/dist/find-body-tag.js +57 -0
- package/dist/formatter.d.ts +19 -0
- package/dist/formatter.js +265 -0
- package/dist/forms-validation.d.ts +189 -0
- package/dist/forms-validation.js +421 -0
- package/dist/forms.d.ts +224 -0
- package/dist/forms.js +729 -0
- package/dist/fragment-container.d.ts +57 -0
- package/dist/fragment-container.js +123 -0
- package/dist/framework-composables.d.ts +73 -0
- package/dist/framework-composables.js +126 -0
- package/dist/head-injection.d.ts +61 -0
- package/dist/head-injection.js +28 -0
- package/dist/head.d.ts +282 -0
- package/dist/head.js +231 -0
- package/dist/heatmap.d.ts +206 -0
- package/dist/heatmap.js +566 -0
- package/dist/hot-reload.d.ts +87 -0
- package/dist/hot-reload.js +373 -0
- package/dist/html-masking.d.ts +125 -0
- package/dist/html-masking.js +196 -0
- package/dist/hydration-runtime.d.ts +44 -0
- package/dist/hydration-runtime.js +195 -0
- package/dist/hydration.d.ts +135 -0
- package/dist/hydration.js +654 -0
- package/dist/i18n.d.ts +342 -0
- package/dist/i18n.js +678 -0
- package/dist/image-optimization/auto-sibling.d.ts +42 -0
- package/dist/image-optimization/auto-sibling.js +88 -0
- package/dist/image-optimization/build-plugin.d.ts +54 -0
- package/dist/image-optimization/build-plugin.js +241 -0
- package/dist/image-optimization/component.d.ts +46 -0
- package/dist/image-optimization/component.js +244 -0
- package/dist/image-optimization/directive.d.ts +30 -0
- package/dist/image-optimization/directive.js +203 -0
- package/dist/image-optimization/index.d.ts +156 -0
- package/dist/image-optimization/index.js +54 -0
- package/dist/image-optimization/processor.d.ts +140 -0
- package/dist/image-optimization/processor.js +262 -0
- package/dist/image-optimization/serve.d.ts +54 -0
- package/dist/image-optimization/serve.js +102 -0
- package/dist/import-rebase.d.ts +16 -0
- package/dist/import-rebase.js +16 -0
- package/dist/imported-signals.d.ts +43 -0
- package/dist/imported-signals.js +35 -0
- package/dist/includes.d.ts +171 -0
- package/dist/includes.js +764 -0
- package/dist/index.d.ts +365 -0
- package/dist/index.js +202 -0
- package/dist/init.d.ts +39 -0
- package/dist/init.js +505 -0
- package/dist/inline-assets.d.ts +28 -0
- package/dist/inline-assets.js +82 -0
- package/dist/interactive.d.ts +14 -0
- package/dist/interactive.js +383 -0
- package/dist/internal-markdown.d.ts +22 -0
- package/dist/internal-markdown.js +141 -0
- package/dist/island-chunking.d.ts +48 -0
- package/dist/island-chunking.js +52 -0
- package/dist/isolated-build.d.ts +12 -0
- package/dist/isolated-build.js +18 -0
- package/dist/js-ts.d.ts +10 -0
- package/dist/js-ts.js +60 -0
- package/dist/jsx-runtime.d.ts +92 -0
- package/dist/jsx-runtime.js +289 -0
- package/dist/keep-alive.d.ts +108 -0
- package/dist/keep-alive.js +421 -0
- package/dist/layout-types.d.ts +45 -0
- package/dist/layout-types.js +56 -0
- package/dist/lazy-loader.d.ts +90 -0
- package/dist/lazy-loader.js +245 -0
- package/dist/lazy-module.d.ts +11 -0
- package/dist/lazy-module.js +18 -0
- package/dist/loading-indicator.d.ts +50 -0
- package/dist/loading-indicator.js +322 -0
- package/dist/loops.d.ts +91 -0
- package/dist/loops.js +690 -0
- package/dist/manifest.d.ts +41 -0
- package/dist/manifest.js +31 -0
- package/dist/markdown-view.d.ts +25 -0
- package/dist/markdown-view.js +39 -0
- package/dist/markdown.d.ts +10 -0
- package/dist/markdown.js +68 -0
- package/dist/media/client/blur-up.d.ts +66 -0
- package/dist/media/client/blur-up.js +217 -0
- package/dist/media/client/index.d.ts +93 -0
- package/dist/media/client/index.js +53 -0
- package/dist/media/client/lazy-load.d.ts +74 -0
- package/dist/media/client/lazy-load.js +283 -0
- package/dist/media/client/upload-handler.d.ts +80 -0
- package/dist/media/client/upload-handler.js +354 -0
- package/dist/media/image/component.d.ts +60 -0
- package/dist/media/image/component.js +574 -0
- package/dist/media/image/directive.d.ts +23 -0
- package/dist/media/image/directive.js +160 -0
- package/dist/media/image/editing.d.ts +212 -0
- package/dist/media/image/editing.js +193 -0
- package/dist/media/image/index.d.ts +142 -0
- package/dist/media/image/index.js +80 -0
- package/dist/media/image/placeholder.d.ts +89 -0
- package/dist/media/image/placeholder.js +188 -0
- package/dist/media/image/processor/cache.d.ts +53 -0
- package/dist/media/image/processor/cache.js +51 -0
- package/dist/media/image/processor/index.d.ts +11 -0
- package/dist/media/image/processor/index.js +3 -0
- package/dist/media/image/processor/optimizer.d.ts +24 -0
- package/dist/media/image/processor/optimizer.js +202 -0
- package/dist/media/image/processor/responsive.d.ts +28 -0
- package/dist/media/image/processor/responsive.js +162 -0
- package/dist/media/image/srcset.d.ts +157 -0
- package/dist/media/image/srcset.js +194 -0
- package/dist/media/index.d.ts +331 -0
- package/dist/media/index.js +198 -0
- package/dist/media/manager/embed.d.ts +25 -0
- package/dist/media/manager/embed.js +253 -0
- package/dist/media/protected/component.d.ts +33 -0
- package/dist/media/protected/component.js +235 -0
- package/dist/media/protected/index.d.ts +47 -0
- package/dist/media/protected/index.js +20 -0
- package/dist/media/protected/signature.d.ts +72 -0
- package/dist/media/protected/signature.js +205 -0
- package/dist/media/shared/cache.d.ts +76 -0
- package/dist/media/shared/cache.js +132 -0
- package/dist/media/shared/hash.d.ts +31 -0
- package/dist/media/shared/hash.js +35 -0
- package/dist/media/shared/index.d.ts +7 -0
- package/dist/media/shared/index.js +2 -0
- package/dist/media/types.d.ts +1477 -0
- package/dist/media/types.js +0 -0
- package/dist/media/upload/component.d.ts +9 -0
- package/dist/media/upload/component.js +320 -0
- package/dist/media/upload/index.d.ts +8 -0
- package/dist/media/upload/index.js +1 -0
- package/dist/media/video/directive.d.ts +23 -0
- package/dist/media/video/directive.js +142 -0
- package/dist/media/video/index.d.ts +76 -0
- package/dist/media/video/index.js +583 -0
- package/dist/media/video/processor/cache.d.ts +55 -0
- package/dist/media/video/processor/cache.js +52 -0
- package/dist/media/video/processor/index.d.ts +12 -0
- package/dist/media/video/processor/index.js +4 -0
- package/dist/media/video/processor/streaming.d.ts +26 -0
- package/dist/media/video/processor/streaming.js +197 -0
- package/dist/media/video/processor/thumbnail.d.ts +35 -0
- package/dist/media/video/processor/thumbnail.js +134 -0
- package/dist/media/video/processor/transcoder.d.ts +19 -0
- package/dist/media/video/processor/transcoder.js +283 -0
- package/dist/menubar.d.ts +65 -0
- package/dist/menubar.js +99 -0
- package/dist/method-spoofing.d.ts +20 -0
- package/dist/method-spoofing.js +17 -0
- package/dist/middleware.d.ts +112 -0
- package/dist/middleware.js +40 -0
- package/dist/misc-directives.d.ts +55 -0
- package/dist/misc-directives.js +328 -0
- package/dist/native-build.d.ts +88 -0
- package/dist/native-build.js +575 -0
- package/dist/owned-routes.d.ts +42 -0
- package/dist/owned-routes.js +26 -0
- package/dist/page-action.d.ts +73 -0
- package/dist/page-action.js +91 -0
- package/dist/page-meta.d.ts +38 -0
- package/dist/page-meta.js +16 -0
- package/dist/page-response.d.ts +120 -0
- package/dist/page-response.js +117 -0
- package/dist/parser/directive-parser.d.ts +119 -0
- package/dist/parser/directive-parser.js +249 -0
- package/dist/parser/expression-parser.d.ts +58 -0
- package/dist/parser/expression-parser.js +358 -0
- package/dist/parser/index.d.ts +13 -0
- package/dist/parser/index.js +23 -0
- package/dist/parser/tokenizer.d.ts +77 -0
- package/dist/parser/tokenizer.js +534 -0
- package/dist/partial-hydration.d.ts +123 -0
- package/dist/partial-hydration.js +427 -0
- package/dist/performance-utils.d.ts +318 -0
- package/dist/performance-utils.js +466 -0
- package/dist/placeholder.d.ts +54 -0
- package/dist/placeholder.js +35 -0
- package/dist/plugin-system.d.ts +301 -0
- package/dist/plugin-system.js +214 -0
- package/dist/plugin.d.ts +3 -0
- package/dist/plugin.js +174 -0
- package/dist/precompiler.d.ts +43 -0
- package/dist/precompiler.js +670 -0
- package/dist/process.d.ts +16 -0
- package/dist/process.js +879 -0
- package/dist/production-build.d.ts +163 -0
- package/dist/production-build.js +596 -0
- package/dist/production-builder.d.ts +42 -0
- package/dist/production-builder.js +146 -0
- package/dist/production-server.d.ts +19 -0
- package/dist/production-server.js +208 -0
- package/dist/prop-sentinels.d.ts +31 -0
- package/dist/prop-sentinels.js +7 -0
- package/dist/props.d.ts +216 -0
- package/dist/props.js +224 -0
- package/dist/public-env.d.ts +29 -0
- package/dist/public-env.js +19 -0
- package/dist/pwa/audit.d.ts +42 -0
- package/dist/pwa/audit.js +255 -0
- package/dist/pwa/directives.d.ts +38 -0
- package/dist/pwa/directives.js +332 -0
- package/dist/pwa/icons.d.ts +42 -0
- package/dist/pwa/icons.js +109 -0
- package/dist/pwa/index.d.ts +104 -0
- package/dist/pwa/index.js +47 -0
- package/dist/pwa/inject.d.ts +32 -0
- package/dist/pwa/inject.js +102 -0
- package/dist/pwa/manifest.d.ts +104 -0
- package/dist/pwa/manifest.js +186 -0
- package/dist/pwa/offline.d.ts +8 -0
- package/dist/pwa/offline.js +259 -0
- package/dist/pwa/precache.d.ts +35 -0
- package/dist/pwa/precache.js +116 -0
- package/dist/pwa/service-worker.d.ts +33 -0
- package/dist/pwa/service-worker.js +860 -0
- package/dist/pwa/workbox-strategies.d.ts +100 -0
- package/dist/pwa/workbox-strategies.js +167 -0
- package/dist/pwa/workbox.d.ts +51 -0
- package/dist/pwa/workbox.js +382 -0
- package/dist/pwa.d.ts +52 -0
- package/dist/pwa.js +236 -0
- package/dist/reactive-bindings.d.ts +47 -0
- package/dist/reactive-bindings.js +268 -0
- package/dist/reactive-tracking.d.ts +81 -0
- package/dist/reactive-tracking.js +49 -0
- package/dist/reactive.d.ts +117 -0
- package/dist/reactive.js +593 -0
- package/dist/reactivity.d.ts +206 -0
- package/dist/reactivity.js +574 -0
- package/dist/release.d.ts +1 -0
- package/dist/release.js +1 -0
- package/dist/render-memo.d.ts +40 -0
- package/dist/render-memo.js +33 -0
- package/dist/render.d.ts +54 -0
- package/dist/render.js +153 -0
- package/dist/resolve-stx-targets.d.ts +49 -0
- package/dist/resolve-stx-targets.js +38 -0
- package/dist/route-middleware.d.ts +2 -0
- package/dist/route-middleware.js +17 -0
- package/dist/route-types.d.ts +134 -0
- package/dist/route-types.js +24 -0
- package/dist/router.d.ts +9 -0
- package/dist/router.js +9 -0
- package/dist/routes.d.ts +6 -0
- package/dist/routes.js +14 -0
- package/dist/runtime-globals.d.ts +236 -0
- package/dist/runtime-globals.js +230 -0
- package/dist/runtime-injection.d.ts +113 -0
- package/dist/runtime-injection.js +156 -0
- package/dist/runtime.d.ts +140 -0
- package/dist/runtime.js +94 -0
- package/dist/safe-evaluator.d.ts +165 -0
- package/dist/safe-evaluator.js +461 -0
- package/dist/scaffolding.d.ts +113 -0
- package/dist/scaffolding.js +897 -0
- package/dist/screenshot.d.ts +22 -0
- package/dist/screenshot.js +100 -0
- package/dist/script-classifier.d.ts +41 -0
- package/dist/script-classifier.js +51 -0
- package/dist/script-emit.d.ts +50 -0
- package/dist/script-emit.js +11 -0
- package/dist/script-json.d.ts +36 -0
- package/dist/script-json.js +6 -0
- package/dist/script-validation.d.ts +26 -0
- package/dist/script-validation.js +179 -0
- package/dist/seo.d.ts +225 -0
- package/dist/seo.js +486 -0
- package/dist/serve.d.ts +44 -0
- package/dist/serve.js +233 -0
- package/dist/server-bindings.d.ts +39 -0
- package/dist/server-bindings.js +171 -0
- package/dist/server-components.d.ts +138 -0
- package/dist/server-components.js +427 -0
- package/dist/sfc-template.d.ts +17 -0
- package/dist/sfc-template.js +32 -0
- package/dist/signal-processing.d.ts +222 -0
- package/dist/signal-processing.js +1081 -0
- package/dist/signals-api.d.ts +459 -0
- package/dist/signals-api.js +172 -0
- package/dist/signals.d.ts +41 -0
- package/dist/signals.js +8233 -0
- package/dist/site-builder/build.d.ts +18 -0
- package/dist/site-builder/build.js +252 -0
- package/dist/site-builder/i18n.d.ts +104 -0
- package/dist/site-builder/i18n.js +150 -0
- package/dist/site-builder/index.d.ts +27 -0
- package/dist/site-builder/index.js +16 -0
- package/dist/site-builder/robots.d.ts +2 -0
- package/dist/site-builder/robots.js +26 -0
- package/dist/site-builder/router.d.ts +10 -0
- package/dist/site-builder/router.js +27 -0
- package/dist/site-builder/seo.d.ts +8 -0
- package/dist/site-builder/seo.js +67 -0
- package/dist/site-builder/sitemap.d.ts +10 -0
- package/dist/site-builder/sitemap.js +26 -0
- package/dist/site-builder/theme.d.ts +12 -0
- package/dist/site-builder/theme.js +38 -0
- package/dist/site-builder/types.d.ts +74 -0
- package/dist/site-builder/types.js +0 -0
- package/dist/site-url.d.ts +46 -0
- package/dist/site-url.js +70 -0
- package/dist/slots.d.ts +129 -0
- package/dist/slots.js +286 -0
- package/dist/source-maps.d.ts +98 -0
- package/dist/source-maps.js +350 -0
- package/dist/source-signature.d.ts +45 -0
- package/dist/source-signature.js +20 -0
- package/dist/spa-nav.d.ts +49 -0
- package/dist/spa-nav.js +12 -0
- package/dist/spa-shell.d.ts +21 -0
- package/dist/spa-shell.js +34 -0
- package/dist/ssg.d.ts +357 -0
- package/dist/ssg.js +94 -0
- package/dist/ssr.d.ts +116 -0
- package/dist/ssr.js +339 -0
- package/dist/state-dir.d.ts +36 -0
- package/dist/state-dir.js +22 -0
- package/dist/state-management.d.ts +299 -0
- package/dist/state-management.js +519 -0
- package/dist/store-imports.d.ts +47 -0
- package/dist/store-imports.js +16 -0
- package/dist/store-loader.d.ts +15 -0
- package/dist/store-loader.js +111 -0
- package/dist/stores-client.d.ts +70 -0
- package/dist/stores-client.js +132 -0
- package/dist/story/addons.d.ts +123 -0
- package/dist/story/addons.js +261 -0
- package/dist/story/analytics.d.ts +163 -0
- package/dist/story/analytics.js +235 -0
- package/dist/story/auto-stories.d.ts +38 -0
- package/dist/story/auto-stories.js +158 -0
- package/dist/story/bookmarks.d.ts +102 -0
- package/dist/story/bookmarks.js +277 -0
- package/dist/story/bun-test.d.ts +45 -0
- package/dist/story/bun-test.js +102 -0
- package/dist/story/cli.d.ts +132 -0
- package/dist/story/cli.js +155 -0
- package/dist/story/collect/analyzer.d.ts +33 -0
- package/dist/story/collect/analyzer.js +305 -0
- package/dist/story/collect/index.d.ts +31 -0
- package/dist/story/collect/index.js +27 -0
- package/dist/story/collect/parser.d.ts +17 -0
- package/dist/story/collect/parser.js +129 -0
- package/dist/story/collect/scanner.d.ts +17 -0
- package/dist/story/collect/scanner.js +101 -0
- package/dist/story/collect/tree.d.ts +24 -0
- package/dist/story/collect/tree.js +110 -0
- package/dist/story/commands/build.d.ts +19 -0
- package/dist/story/commands/build.js +172 -0
- package/dist/story/commands/dev.d.ts +23 -0
- package/dist/story/commands/dev.js +78 -0
- package/dist/story/commands/index.d.ts +9 -0
- package/dist/story/commands/index.js +3 -0
- package/dist/story/commands/preview.d.ts +21 -0
- package/dist/story/commands/preview.js +56 -0
- package/dist/story/compiled-output.d.ts +27 -0
- package/dist/story/compiled-output.js +151 -0
- package/dist/story/composition.d.ts +47 -0
- package/dist/story/composition.js +261 -0
- package/dist/story/config-watcher.d.ts +33 -0
- package/dist/story/config-watcher.js +67 -0
- package/dist/story/config.d.ts +29 -0
- package/dist/story/config.js +64 -0
- package/dist/story/context.d.ts +27 -0
- package/dist/story/context.js +27 -0
- package/dist/story/controls/index.d.ts +54 -0
- package/dist/story/controls/index.js +320 -0
- package/dist/story/desktop-preview.d.ts +34 -0
- package/dist/story/desktop-preview.js +105 -0
- package/dist/story/docs-generator.d.ts +30 -0
- package/dist/story/docs-generator.js +187 -0
- package/dist/story/errors.d.ts +47 -0
- package/dist/story/errors.js +239 -0
- package/dist/story/figma-export.d.ts +169 -0
- package/dist/story/figma-export.js +224 -0
- package/dist/story/generator.d.ts +21 -0
- package/dist/story/generator.js +165 -0
- package/dist/story/hmr.d.ts +62 -0
- package/dist/story/hmr.js +131 -0
- package/dist/story/hot-swap.d.ts +46 -0
- package/dist/story/hot-swap.js +207 -0
- package/dist/story/index.d.ts +99 -0
- package/dist/story/index.js +49 -0
- package/dist/story/interactions.d.ts +53 -0
- package/dist/story/interactions.js +225 -0
- package/dist/story/keyboard-shortcuts.d.ts +39 -0
- package/dist/story/keyboard-shortcuts.js +345 -0
- package/dist/story/output.d.ts +115 -0
- package/dist/story/output.js +153 -0
- package/dist/story/performance.d.ts +129 -0
- package/dist/story/performance.js +252 -0
- package/dist/story/presets.d.ts +123 -0
- package/dist/story/presets.js +289 -0
- package/dist/story/props-validation.d.ts +45 -0
- package/dist/story/props-validation.js +215 -0
- package/dist/story/renderer.d.ts +69 -0
- package/dist/story/renderer.js +209 -0
- package/dist/story/search-index.d.ts +47 -0
- package/dist/story/search-index.js +106 -0
- package/dist/story/search.d.ts +56 -0
- package/dist/story/search.js +140 -0
- package/dist/story/server.d.ts +31 -0
- package/dist/story/server.js +965 -0
- package/dist/story/setup.d.ts +56 -0
- package/dist/story/setup.js +78 -0
- package/dist/story/snapshots.d.ts +65 -0
- package/dist/story/snapshots.js +171 -0
- package/dist/story/testing.d.ts +83 -0
- package/dist/story/testing.js +164 -0
- package/dist/story/theme.d.ts +68 -0
- package/dist/story/theme.js +170 -0
- package/dist/story/ts-css.d.ts +29 -0
- package/dist/story/ts-css.js +189 -0
- package/dist/story/types.d.ts +342 -0
- package/dist/story/types.js +0 -0
- package/dist/story/ui/code-panel.d.ts +43 -0
- package/dist/story/ui/code-panel.js +175 -0
- package/dist/story/ui/controls-panel.d.ts +25 -0
- package/dist/story/ui/controls-panel.js +168 -0
- package/dist/story/ui/index.d.ts +8 -0
- package/dist/story/ui/index.js +4 -0
- package/dist/story/ui/navigation.d.ts +55 -0
- package/dist/story/ui/navigation.js +250 -0
- package/dist/story/ui/preview.d.ts +46 -0
- package/dist/story/ui/preview.js +251 -0
- package/dist/story/visual-testing.d.ts +45 -0
- package/dist/story/visual-testing.js +248 -0
- package/dist/streaming.d.ts +238 -0
- package/dist/streaming.js +537 -0
- package/dist/strict-lint.d.ts +52 -0
- package/dist/strict-lint.js +269 -0
- package/dist/strip-literals.d.ts +40 -0
- package/dist/strip-literals.js +149 -0
- package/dist/stx-virtual-ts.d.ts +358 -0
- package/dist/stx-virtual-ts.js +670 -0
- package/dist/stx.d.ts +924 -0
- package/dist/style-scoping.d.ts +42 -0
- package/dist/style-scoping.js +82 -0
- package/dist/suspense.d.ts +98 -0
- package/dist/suspense.js +398 -0
- package/dist/teleport.d.ts +31 -0
- package/dist/teleport.js +109 -0
- package/dist/template-compiler.d.ts +33 -0
- package/dist/template-compiler.js +68 -0
- package/dist/template-hydrator.d.ts +28 -0
- package/dist/template-hydrator.js +95 -0
- package/dist/template-tag-balance.d.ts +32 -0
- package/dist/template-tag-balance.js +93 -0
- package/dist/testing.d.ts +330 -0
- package/dist/testing.js +588 -0
- package/dist/theme-tokens.d.ts +88 -0
- package/dist/theme-tokens.js +71 -0
- package/dist/transitions.d.ts +99 -0
- package/dist/transitions.js +443 -0
- package/dist/ts-css-config.d.ts +71 -0
- package/dist/ts-css-config.js +44 -0
- package/dist/type-checker.d.ts +85 -0
- package/dist/type-checker.js +581 -0
- package/dist/typecheck.d.ts +70 -0
- package/dist/typecheck.js +365 -0
- package/dist/types/component-types.d.ts +248 -0
- package/dist/types/component-types.js +0 -0
- package/dist/types/config-types.d.ts +938 -0
- package/dist/types/config-types.js +0 -0
- package/dist/types/context-types.d.ts +122 -0
- package/dist/types/context-types.js +0 -0
- package/dist/types/csp-types.d.ts +83 -0
- package/dist/types/csp-types.js +0 -0
- package/dist/types/directive-types.d.ts +315 -0
- package/dist/types/directive-types.js +3 -0
- package/dist/types/index.d.ts +20 -0
- package/dist/types/index.js +1 -0
- package/dist/types/pwa-types.d.ts +338 -0
- package/dist/types/pwa-types.js +0 -0
- package/dist/types.d.ts +27 -0
- package/dist/types.js +1 -0
- package/dist/typescript-templates.d.ts +156 -0
- package/dist/typescript-templates.js +386 -0
- package/dist/unresolved-identifiers.d.ts +52 -0
- package/dist/unresolved-identifiers.js +148 -0
- package/dist/utils.d.ts +112 -0
- package/dist/utils.js +1170 -0
- package/dist/validator.d.ts +80 -0
- package/dist/validator.js +171 -0
- package/dist/variable-extractor.d.ts +142 -0
- package/dist/variable-extractor.js +1306 -0
- package/dist/view-composers.d.ts +171 -0
- package/dist/view-composers.js +29 -0
- package/dist/virtual-scrolling.d.ts +127 -0
- package/dist/virtual-scrolling.js +454 -0
- package/dist/visual-editor.d.ts +185 -0
- package/dist/visual-editor.js +735 -0
- package/dist/visual-testing.d.ts +135 -0
- package/dist/visual-testing.js +126 -0
- package/dist/vue-template.d.ts +39 -0
- package/dist/vue-template.js +476 -0
- package/dist/web-components/css-scoping.d.ts +64 -0
- package/dist/web-components/css-scoping.js +210 -0
- package/dist/web-components/index.d.ts +29 -0
- package/dist/web-components/index.js +13 -0
- package/dist/web-components/reactive-generator.d.ts +72 -0
- package/dist/web-components/reactive-generator.js +484 -0
- package/dist/web-components.d.ts +253 -0
- package/dist/web-components.js +1466 -0
- package/dist/x-element.d.ts +42 -0
- package/dist/x-element.js +301 -0
- package/package.json +107 -0
- package/stx.d.ts +924 -0
|
@@ -0,0 +1,1466 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { ErrorCodes, inlineError } from "./error-handling.js";
|
|
4
|
+
import { fileExists, resolveTemplatePath } from "./utils.js";
|
|
5
|
+
export async function buildWebComponents(options, dependencies) {
|
|
6
|
+
if (!options.webComponents?.enabled)
|
|
7
|
+
return [];
|
|
8
|
+
const webComponents = options.webComponents.components || [], builtComponents = [];
|
|
9
|
+
if (webComponents.length > 0) {
|
|
10
|
+
if (options.debug)
|
|
11
|
+
console.log(`Building ${webComponents.length} web components...`);
|
|
12
|
+
for (const component of webComponents)
|
|
13
|
+
try {
|
|
14
|
+
const outputPath = await buildWebComponent(component, options, dependencies);
|
|
15
|
+
if (outputPath)
|
|
16
|
+
builtComponents.push(outputPath);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.error(`Error building web component ${component.name}:`, error);
|
|
19
|
+
if (options.debug)
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return builtComponents;
|
|
24
|
+
}
|
|
25
|
+
async function buildWebComponent(component, options, dependencies) {
|
|
26
|
+
const { name, file, tag, extends: baseElement } = component;
|
|
27
|
+
if (!name || !file || !tag) {
|
|
28
|
+
console.error("Invalid web component configuration, missing required fields:", component);
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
let filePath = null;
|
|
32
|
+
if (path.isAbsolute(file) && await fileExists(file))
|
|
33
|
+
filePath = file;
|
|
34
|
+
else if (options.componentsDir) {
|
|
35
|
+
const componentsPath = path.join(options.componentsDir, file);
|
|
36
|
+
if (await fileExists(componentsPath))
|
|
37
|
+
filePath = componentsPath;
|
|
38
|
+
}
|
|
39
|
+
if (!filePath)
|
|
40
|
+
filePath = await resolveTemplatePath(file, process.cwd(), options, dependencies);
|
|
41
|
+
if (!filePath) {
|
|
42
|
+
console.error(`Web component source file not found: ${file}`);
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
const source = await Bun.file(filePath).text();
|
|
46
|
+
dependencies.add(filePath);
|
|
47
|
+
const isTypeScript = (component.outputFormat || "js") === "ts", webComponentCode = isTypeScript ? generateWebComponentCodeTypeScript({
|
|
48
|
+
name,
|
|
49
|
+
tag,
|
|
50
|
+
baseElement,
|
|
51
|
+
source,
|
|
52
|
+
shadowDOM: component.shadowDOM ?? !0,
|
|
53
|
+
template: component.template ?? !0,
|
|
54
|
+
styleSource: component.styleSource,
|
|
55
|
+
attributes: component.attributes || [],
|
|
56
|
+
attributeTypes: component.attributeTypes || {}
|
|
57
|
+
}) : generateWebComponentCode({
|
|
58
|
+
name,
|
|
59
|
+
tag,
|
|
60
|
+
baseElement,
|
|
61
|
+
source,
|
|
62
|
+
shadowDOM: component.shadowDOM ?? !0,
|
|
63
|
+
template: component.template ?? !0,
|
|
64
|
+
styleSource: component.styleSource,
|
|
65
|
+
attributes: component.attributes || []
|
|
66
|
+
}), outputDir = options.webComponents?.outputDir || "dist/web-components";
|
|
67
|
+
await fs.promises.mkdir(outputDir, { recursive: !0 });
|
|
68
|
+
const extension = isTypeScript ? "ts" : "js", outputFile = path.join(outputDir, `${tag}.${extension}`);
|
|
69
|
+
await Bun.write(outputFile, webComponentCode);
|
|
70
|
+
if (options.debug)
|
|
71
|
+
console.log(`Built web component ${name} -> ${outputFile}`);
|
|
72
|
+
return outputFile;
|
|
73
|
+
}
|
|
74
|
+
function generateWebComponentCode(options) {
|
|
75
|
+
const {
|
|
76
|
+
name,
|
|
77
|
+
tag,
|
|
78
|
+
baseElement = "HTMLElement",
|
|
79
|
+
source,
|
|
80
|
+
shadowDOM,
|
|
81
|
+
template,
|
|
82
|
+
styleSource,
|
|
83
|
+
attributes = []
|
|
84
|
+
} = options;
|
|
85
|
+
let htmlContent = source.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, "").trim();
|
|
86
|
+
if (!shadowDOM) {
|
|
87
|
+
htmlContent = htmlContent.replace(/<slot\s+name=["']([^"']+)["']\s*>([\s\S]*?)<\/slot>/gi, '<div data-slot="$1">$2</div>');
|
|
88
|
+
htmlContent = htmlContent.replace(/<slot\s+name=["']([^"']+)["']\s*\/>/gi, '<div data-slot="$1"></div>');
|
|
89
|
+
htmlContent = htmlContent.replace(/<slot\s*>([\s\S]*?)<\/slot>/gi, "<div data-default-slot>$1</div>");
|
|
90
|
+
htmlContent = htmlContent.replace(/<slot\s*\/>/gi, "<div data-default-slot></div>");
|
|
91
|
+
}
|
|
92
|
+
let styles = "";
|
|
93
|
+
if (styleSource)
|
|
94
|
+
styles = `<link rel="stylesheet" href="${styleSource}">`;
|
|
95
|
+
return `/**
|
|
96
|
+
* ${name} Web Component
|
|
97
|
+
* Auto-generated from stx component
|
|
98
|
+
*/
|
|
99
|
+
class ${name.replace(/\W/g, "")} extends ${baseElement} {
|
|
100
|
+
constructor() {
|
|
101
|
+
super()
|
|
102
|
+
this._initialized = false
|
|
103
|
+
${shadowDOM ? "" : "this._slotContent = []"}
|
|
104
|
+
${shadowDOM ? 'this.attachShadow({ mode: "open" })' : ""}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
${template ? `
|
|
108
|
+
_createTemplate() {
|
|
109
|
+
const template = document.createElement('template')
|
|
110
|
+
template.innerHTML = \`${styles}${htmlContent}\`
|
|
111
|
+
${shadowDOM ? "this.shadowRoot.appendChild(template.content.cloneNode(true))" : "this.appendChild(template.content.cloneNode(true))"}
|
|
112
|
+
this._processSlots()
|
|
113
|
+
}
|
|
114
|
+
` : `
|
|
115
|
+
_render() {
|
|
116
|
+
${shadowDOM ? "this.shadowRoot.innerHTML" : "this.innerHTML"} = \`${styles}${htmlContent}\`
|
|
117
|
+
this._processSlots()
|
|
118
|
+
}
|
|
119
|
+
`}
|
|
120
|
+
|
|
121
|
+
_processSlots() {
|
|
122
|
+
${shadowDOM ? `// Shadow DOM handles slot assignment automatically
|
|
123
|
+
// Listen for slot changes if needed
|
|
124
|
+
const slots = this.shadowRoot.querySelectorAll('slot')
|
|
125
|
+
slots.forEach(slot => {
|
|
126
|
+
slot.addEventListener('slotchange', (e) => {
|
|
127
|
+
const assignedNodes = slot.assignedNodes()
|
|
128
|
+
this.dispatchEvent(new CustomEvent('slot-changed', {
|
|
129
|
+
detail: { slotName: slot.name || 'default', assignedNodes }
|
|
130
|
+
}))
|
|
131
|
+
})
|
|
132
|
+
})` : `// Manual slot processing for non-shadow DOM mode
|
|
133
|
+
const slots = this.querySelectorAll('[data-slot]')
|
|
134
|
+
|
|
135
|
+
// Process named slots
|
|
136
|
+
slots.forEach(slotEl => {
|
|
137
|
+
const slotName = slotEl.getAttribute('data-slot')
|
|
138
|
+
const slottedContent = this._slotContent.filter(
|
|
139
|
+
node => node.nodeType === Node.ELEMENT_NODE && node.getAttribute('slot') === slotName
|
|
140
|
+
)
|
|
141
|
+
if (slottedContent.length > 0) {
|
|
142
|
+
slotEl.innerHTML = ''
|
|
143
|
+
slottedContent.forEach(content => slotEl.appendChild(content))
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
// Process default slot
|
|
148
|
+
const defaultSlot = this.querySelector('[data-slot=""]') || this.querySelector('[data-default-slot]')
|
|
149
|
+
if (defaultSlot) {
|
|
150
|
+
const unslottedContent = this._slotContent.filter(
|
|
151
|
+
node => node.nodeType !== Node.ELEMENT_NODE || !node.hasAttribute('slot')
|
|
152
|
+
)
|
|
153
|
+
if (unslottedContent.length > 0) {
|
|
154
|
+
defaultSlot.innerHTML = ''
|
|
155
|
+
unslottedContent.forEach(content => defaultSlot.appendChild(content))
|
|
156
|
+
}
|
|
157
|
+
}`}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
${attributes.length > 0 ? `
|
|
161
|
+
static get observedAttributes() {
|
|
162
|
+
return [${attributes.map((attr) => `'${attr}'`).join(", ")}]
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
166
|
+
if (oldValue !== newValue) {
|
|
167
|
+
this[name] = newValue
|
|
168
|
+
${template ? "" : "if (this._initialized) this._render()"}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
` : ""}
|
|
172
|
+
|
|
173
|
+
connectedCallback() {
|
|
174
|
+
if (this._initialized) return
|
|
175
|
+
${shadowDOM ? "" : "this._slotContent = Array.from(this.childNodes)"}
|
|
176
|
+
this._initialized = true
|
|
177
|
+
${template ? "this._createTemplate()" : "this._render()"}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
disconnectedCallback() {
|
|
181
|
+
// Component removed from the DOM
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Register the web component
|
|
186
|
+
customElements.define('${tag}', ${name.replace(/\W/g, "")})
|
|
187
|
+
`;
|
|
188
|
+
}
|
|
189
|
+
function generateWebComponentCodeTypeScript(options) {
|
|
190
|
+
const {
|
|
191
|
+
name,
|
|
192
|
+
tag,
|
|
193
|
+
baseElement = "HTMLElement",
|
|
194
|
+
source,
|
|
195
|
+
shadowDOM,
|
|
196
|
+
template,
|
|
197
|
+
styleSource,
|
|
198
|
+
attributes = [],
|
|
199
|
+
attributeTypes = {}
|
|
200
|
+
} = options, className = name.replace(/\W/g, "");
|
|
201
|
+
let htmlContent = source.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, "").trim();
|
|
202
|
+
if (!shadowDOM) {
|
|
203
|
+
htmlContent = htmlContent.replace(/<slot\s+name=["']([^"']+)["']\s*>([\s\S]*?)<\/slot>/gi, '<div data-slot="$1">$2</div>');
|
|
204
|
+
htmlContent = htmlContent.replace(/<slot\s+name=["']([^"']+)["']\s*\/>/gi, '<div data-slot="$1"></div>');
|
|
205
|
+
htmlContent = htmlContent.replace(/<slot\s*>([\s\S]*?)<\/slot>/gi, "<div data-default-slot>$1</div>");
|
|
206
|
+
htmlContent = htmlContent.replace(/<slot\s*\/>/gi, "<div data-default-slot></div>");
|
|
207
|
+
}
|
|
208
|
+
htmlContent = htmlContent.replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
|
|
209
|
+
const styles = styleSource ? `<link rel="stylesheet" href="${styleSource}">` : "", getTypeScriptType = (attr) => {
|
|
210
|
+
switch (attributeTypes[attr]) {
|
|
211
|
+
case "number":
|
|
212
|
+
return "number";
|
|
213
|
+
case "boolean":
|
|
214
|
+
return "boolean";
|
|
215
|
+
case "object":
|
|
216
|
+
return "Record<string, unknown>";
|
|
217
|
+
default:
|
|
218
|
+
return "string";
|
|
219
|
+
}
|
|
220
|
+
}, toCamelCase = (str) => str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()), propertyDeclarations = attributes.map((attr) => ` private _${toCamelCase(attr)}: ${getTypeScriptType(attr)} | null = null;`).join(`
|
|
221
|
+
`), gettersSetters = attributes.map((attr) => {
|
|
222
|
+
const type = getTypeScriptType(attr), camelCase = toCamelCase(attr);
|
|
223
|
+
return `
|
|
224
|
+
get ${camelCase}(): ${type} | null {
|
|
225
|
+
return this._${camelCase};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
set ${camelCase}(value: ${type} | null) {
|
|
229
|
+
this._${camelCase} = value;
|
|
230
|
+
if (value !== null) {
|
|
231
|
+
this.setAttribute('${attr}', String(value));
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
this.removeAttribute('${attr}');
|
|
235
|
+
}
|
|
236
|
+
}`;
|
|
237
|
+
}).join(`
|
|
238
|
+
`), propsInterface = attributes.length > 0 ? `/**
|
|
239
|
+
* Props interface for ${name}
|
|
240
|
+
*/
|
|
241
|
+
export interface ${className}Props {
|
|
242
|
+
${attributes.map((attr) => {
|
|
243
|
+
const type = getTypeScriptType(attr);
|
|
244
|
+
return ` ${toCamelCase(attr)}?: ${type};`;
|
|
245
|
+
}).join(`
|
|
246
|
+
`)}
|
|
247
|
+
}
|
|
248
|
+
` : "", observedAttributesCode = attributes.length > 0 ? `
|
|
249
|
+
static get observedAttributes(): string[] {
|
|
250
|
+
return [${attributes.map((attr) => `'${attr}'`).join(", ")}];
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void {
|
|
254
|
+
if (oldValue !== newValue) {
|
|
255
|
+
const camelCase = name.replace(/-([a-z])/g, (_: string, letter: string) => letter.toUpperCase());
|
|
256
|
+
(this as unknown as Record<string, unknown>)[\`_\${camelCase}\`] = this._parseAttributeValue(name, newValue);
|
|
257
|
+
${template ? "" : "if (this._initialized) this._render();"}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
private _parseAttributeValue(name: string, value: string | null): unknown {
|
|
262
|
+
if (value === null) return null;
|
|
263
|
+
const typeMap: Record<string, string> = ${JSON.stringify(attributeTypes)};
|
|
264
|
+
const type = typeMap[name] || 'string';
|
|
265
|
+
switch (type) {
|
|
266
|
+
case 'number': return Number(value);
|
|
267
|
+
case 'boolean': return value !== 'false' && value !== '0';
|
|
268
|
+
case 'object': try { return JSON.parse(value); }
|
|
269
|
+
catch { return value; }
|
|
270
|
+
default: return value;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
` : "", templateMethod = template ? `
|
|
274
|
+
private _createTemplate(): void {
|
|
275
|
+
const template = document.createElement('template');
|
|
276
|
+
template.innerHTML = \`${styles}${htmlContent}\`;
|
|
277
|
+
${shadowDOM ? "this.shadowRoot!.appendChild(template.content.cloneNode(true));" : "this.appendChild(template.content.cloneNode(true));"}
|
|
278
|
+
this._processSlots();
|
|
279
|
+
}` : `
|
|
280
|
+
private _render(): void {
|
|
281
|
+
${shadowDOM ? "this.shadowRoot!.innerHTML" : "this.innerHTML"} = \`${styles}${htmlContent}\`;
|
|
282
|
+
this._processSlots();
|
|
283
|
+
}`;
|
|
284
|
+
return `/**
|
|
285
|
+
* ${name} Web Component
|
|
286
|
+
* Auto-generated from stx component (TypeScript)
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* \`\`\`html
|
|
290
|
+
* <${tag}></${tag}>
|
|
291
|
+
* \`\`\`
|
|
292
|
+
*/
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Detail type for slot-changed event
|
|
296
|
+
*/
|
|
297
|
+
interface SlotChangeDetail {
|
|
298
|
+
slotName: string;
|
|
299
|
+
assignedNodes: Node[];
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
${propsInterface}
|
|
303
|
+
/**
|
|
304
|
+
* ${name} custom element class
|
|
305
|
+
* @customElement ${tag}
|
|
306
|
+
*/
|
|
307
|
+
export class ${className} extends ${baseElement} {
|
|
308
|
+
${propertyDeclarations}
|
|
309
|
+
private _initialized = false;
|
|
310
|
+
${shadowDOM ? "" : "private _slotContent: Node[] = [];"}
|
|
311
|
+
|
|
312
|
+
constructor() {
|
|
313
|
+
super();
|
|
314
|
+
${shadowDOM ? 'this.attachShadow({ mode: "open" });' : ""}
|
|
315
|
+
}
|
|
316
|
+
${templateMethod}
|
|
317
|
+
${shadowDOM ? `
|
|
318
|
+
private _processSlots(): void {
|
|
319
|
+
const slots = this.shadowRoot!.querySelectorAll('slot');
|
|
320
|
+
slots.forEach((slot) => {
|
|
321
|
+
slot.addEventListener('slotchange', () => {
|
|
322
|
+
const assignedNodes = (slot as HTMLSlotElement).assignedNodes();
|
|
323
|
+
this.dispatchEvent(new CustomEvent<SlotChangeDetail>('slot-changed', {
|
|
324
|
+
detail: { slotName: slot.getAttribute('name') || 'default', assignedNodes }
|
|
325
|
+
}));
|
|
326
|
+
});
|
|
327
|
+
});
|
|
328
|
+
}` : `
|
|
329
|
+
private _processSlots(): void {
|
|
330
|
+
const slots = this.querySelectorAll('[data-slot]');
|
|
331
|
+
slots.forEach((slotEl) => {
|
|
332
|
+
const slotName = slotEl.getAttribute('data-slot');
|
|
333
|
+
if (slotName) {
|
|
334
|
+
const slottedContent = this._slotContent.filter(
|
|
335
|
+
node => node.nodeType === Node.ELEMENT_NODE && (node as Element).getAttribute('slot') === slotName
|
|
336
|
+
);
|
|
337
|
+
if (slottedContent.length > 0) {
|
|
338
|
+
slotEl.innerHTML = '';
|
|
339
|
+
slottedContent.forEach(content => slotEl.appendChild(content));
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
const defaultSlot = this.querySelector('[data-slot=""]') || this.querySelector('[data-default-slot]');
|
|
344
|
+
if (defaultSlot) {
|
|
345
|
+
const unslottedContent = this._slotContent.filter(
|
|
346
|
+
node => node.nodeType !== Node.ELEMENT_NODE || !(node as Element).hasAttribute('slot')
|
|
347
|
+
);
|
|
348
|
+
if (unslottedContent.length > 0) {
|
|
349
|
+
defaultSlot.innerHTML = '';
|
|
350
|
+
unslottedContent.forEach(content => defaultSlot.appendChild(content));
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}`}
|
|
354
|
+
${observedAttributesCode}
|
|
355
|
+
${gettersSetters}
|
|
356
|
+
|
|
357
|
+
connectedCallback(): void {
|
|
358
|
+
if (this._initialized) return;
|
|
359
|
+
${shadowDOM ? "" : "this._slotContent = Array.from(this.childNodes);"}
|
|
360
|
+
this._initialized = true;
|
|
361
|
+
${template ? "this._createTemplate();" : "this._render();"}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
disconnectedCallback(): void {
|
|
365
|
+
// Component removed from the DOM
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
adoptedCallback(): void {
|
|
369
|
+
// Component moved to a new document
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// Type augmentation for HTMLElementTagNameMap
|
|
374
|
+
declare global {
|
|
375
|
+
interface HTMLElementTagNameMap {
|
|
376
|
+
'${tag}': ${className};
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// Register the web component
|
|
381
|
+
customElements.define('${tag}', ${className});
|
|
382
|
+
`;
|
|
383
|
+
}
|
|
384
|
+
const defaultCssScopingConfig = {
|
|
385
|
+
strategy: "attribute",
|
|
386
|
+
attributeName: "data-v",
|
|
387
|
+
preserveOriginal: !0
|
|
388
|
+
};
|
|
389
|
+
export function generateScopeId(componentName) {
|
|
390
|
+
const hash = componentName.split("").reduce((acc, char) => (acc << 5) - acc + char.charCodeAt(0) | 0, 0);
|
|
391
|
+
return Math.abs(hash).toString(36).slice(0, 8);
|
|
392
|
+
}
|
|
393
|
+
export function scopeCSS(css, componentTag, config = {}) {
|
|
394
|
+
const mergedConfig = { ...defaultCssScopingConfig, ...config }, scopeId = generateScopeId(componentTag);
|
|
395
|
+
switch (mergedConfig.strategy) {
|
|
396
|
+
case "shadow":
|
|
397
|
+
return css;
|
|
398
|
+
case "prefix":
|
|
399
|
+
return scopeCSSWithPrefix(css, mergedConfig.prefix || componentTag, mergedConfig.preserveOriginal);
|
|
400
|
+
case "attribute":
|
|
401
|
+
return scopeCSSWithAttribute(css, scopeId, mergedConfig.attributeName || "data-v", mergedConfig.preserveOriginal);
|
|
402
|
+
case "bem":
|
|
403
|
+
return scopeCSSWithBEM(css, componentTag, mergedConfig.preserveOriginal);
|
|
404
|
+
default:
|
|
405
|
+
return css;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
function scopeCSSWithAttribute(css, scopeId, attributeName, preserveOriginal) {
|
|
409
|
+
const scopeAttr = `[${attributeName}-${scopeId}]`;
|
|
410
|
+
return css.replace(/([.#]?[\w-]+|\*)\s*(\{|,)/g, (match, selector, delimiter) => {
|
|
411
|
+
if (selector.startsWith("@"))
|
|
412
|
+
return match;
|
|
413
|
+
if (/^(?::root|:host|html|body)$/i.test(selector))
|
|
414
|
+
return match;
|
|
415
|
+
return `${preserveOriginal ? `${selector}${scopeAttr}` : `${selector}${scopeAttr}`}${delimiter}`;
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
function scopeCSSWithPrefix(css, prefix, preserveOriginal) {
|
|
419
|
+
return css.replace(/\.([a-z_][\w-]*)/gi, (match, className) => {
|
|
420
|
+
if (className.startsWith(prefix))
|
|
421
|
+
return match;
|
|
422
|
+
const scopedClass = `${prefix}__${className}`;
|
|
423
|
+
return preserveOriginal ? `.${scopedClass}` : `.${scopedClass}`;
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
function scopeCSSWithBEM(css, componentName, preserveOriginal) {
|
|
427
|
+
const block = componentName.replace(/[^a-z0-9]/gi, "-");
|
|
428
|
+
return css.replace(/\.([a-z_][\w-]*)/gi, (match, className) => {
|
|
429
|
+
if (className.includes("__") || className.includes("--")) {
|
|
430
|
+
if (!className.startsWith(block))
|
|
431
|
+
return `.${block}__${className}`;
|
|
432
|
+
return match;
|
|
433
|
+
}
|
|
434
|
+
const scopedClass = `${block}__${className}`;
|
|
435
|
+
return preserveOriginal ? `.${scopedClass}` : `.${scopedClass}`;
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
export function scopeHTML(html, componentTag, config = {}) {
|
|
439
|
+
const mergedConfig = { ...defaultCssScopingConfig, ...config };
|
|
440
|
+
if (mergedConfig.strategy === "shadow")
|
|
441
|
+
return html;
|
|
442
|
+
if (mergedConfig.strategy === "attribute") {
|
|
443
|
+
const scopeId = generateScopeId(componentTag), scopeAttr = `${mergedConfig.attributeName || "data-v"}-${scopeId}`;
|
|
444
|
+
return html.replace(/<([a-z][a-z0-9-]*)([^>]*)>/gi, (match, tag, attrs) => {
|
|
445
|
+
if (/^(?:script|style|!--)$/i.test(tag))
|
|
446
|
+
return match;
|
|
447
|
+
const isSelfClosing = attrs.trimEnd().endsWith("/"), cleanAttrs = isSelfClosing ? attrs.slice(0, -1) : attrs;
|
|
448
|
+
return `<${tag}${cleanAttrs} ${scopeAttr}${isSelfClosing ? "/" : ""}>`;
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
if (mergedConfig.strategy === "prefix" || mergedConfig.strategy === "bem") {
|
|
452
|
+
const prefix = mergedConfig.strategy === "bem" ? componentTag.replace(/[^a-z0-9]/gi, "-") : mergedConfig.prefix || componentTag;
|
|
453
|
+
return html.replace(/\bclass\s*=\s*["']([^"']+)["']/gi, (match, classes) => {
|
|
454
|
+
return `class="${classes.split(/\s+/).map((cls) => {
|
|
455
|
+
if (!cls)
|
|
456
|
+
return cls;
|
|
457
|
+
if (cls.startsWith(prefix))
|
|
458
|
+
return cls;
|
|
459
|
+
return `${prefix}__${cls}`;
|
|
460
|
+
}).join(" ")}"`;
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
return html;
|
|
464
|
+
}
|
|
465
|
+
export function getScopeAttribute(componentTag, config = {}) {
|
|
466
|
+
const mergedConfig = { ...defaultCssScopingConfig, ...config }, scopeId = generateScopeId(componentTag);
|
|
467
|
+
return `${mergedConfig.attributeName || "data-v"}-${scopeId}`;
|
|
468
|
+
}
|
|
469
|
+
export function extractAndScopeStyles(html, componentTag, config = {}) {
|
|
470
|
+
let extractedCSS = "";
|
|
471
|
+
const htmlWithoutStyles = html.replace(/<style([^>]*)>([\s\S]*?)<\/style>/gi, (_match, attrs, cssContent) => {
|
|
472
|
+
if (/\bscoped\b/i.test(attrs) || config.strategy !== "shadow")
|
|
473
|
+
extractedCSS += `${scopeCSS(cssContent, componentTag, config)}
|
|
474
|
+
`;
|
|
475
|
+
else
|
|
476
|
+
extractedCSS += `${cssContent}
|
|
477
|
+
`;
|
|
478
|
+
return "";
|
|
479
|
+
});
|
|
480
|
+
return {
|
|
481
|
+
html: scopeHTML(htmlWithoutStyles, componentTag, config),
|
|
482
|
+
css: extractedCSS.trim()
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
function camelToKebab(str) {
|
|
486
|
+
return str.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
487
|
+
}
|
|
488
|
+
function _kebabToCamel(str) {
|
|
489
|
+
return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
490
|
+
}
|
|
491
|
+
export function generateReactiveWebComponent(config) {
|
|
492
|
+
const {
|
|
493
|
+
name,
|
|
494
|
+
tag,
|
|
495
|
+
baseElement = "HTMLElement",
|
|
496
|
+
template,
|
|
497
|
+
styles = "",
|
|
498
|
+
shadowDOM = !0,
|
|
499
|
+
properties = {},
|
|
500
|
+
lifecycle = {},
|
|
501
|
+
events = {},
|
|
502
|
+
methods = {},
|
|
503
|
+
state = {}
|
|
504
|
+
} = config, className = name.replace(/\W/g, ""), propertyNames = Object.keys(properties), observedAttributes = propertyNames.filter((prop) => properties[prop].attribute !== !1).map((prop) => properties[prop].attribute || camelToKebab(prop)), propertyDeclarations = propertyNames.map((prop) => {
|
|
505
|
+
const def = properties[prop], defaultValue = def.default !== void 0 ? JSON.stringify(def.default) : def.type === "string" ? '""' : def.type === "number" ? "0" : def.type === "boolean" ? "false" : def.type === "array" ? "[]" : "{}";
|
|
506
|
+
return ` this._${prop} = ${defaultValue};`;
|
|
507
|
+
}).join(`
|
|
508
|
+
`), propertyAccessors = propertyNames.map((prop) => {
|
|
509
|
+
const def = properties[prop], attrName = def.attribute !== !1 ? def.attribute || camelToKebab(prop) : null, reflectCode = def.reflect && attrName ? `
|
|
510
|
+
if (value !== null && value !== undefined) {
|
|
511
|
+
${def.type === "boolean" ? `if (value) { this.setAttribute('${attrName}', ''); }
|
|
512
|
+
else { this.removeAttribute('${attrName}'); }` : `this.setAttribute('${attrName}', ${def.type === "object" || def.type === "array" ? "JSON.stringify(value)" : "String(value)"});`}
|
|
513
|
+
}
|
|
514
|
+
else {
|
|
515
|
+
this.removeAttribute('${attrName}');
|
|
516
|
+
}` : "", observerCode = def.observer ? `this.${def.observer}(value, oldValue);` : "", renderCode = def.render !== !1 ? "this._scheduleRender();" : "";
|
|
517
|
+
return `
|
|
518
|
+
get ${prop}() {
|
|
519
|
+
return this._${prop};
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
set ${prop}(value) {
|
|
523
|
+
const oldValue = this._${prop};
|
|
524
|
+
if (oldValue === value) return;
|
|
525
|
+
this._${prop} = value;${reflectCode}
|
|
526
|
+
${observerCode}
|
|
527
|
+
${renderCode}
|
|
528
|
+
this.dispatchEvent(new CustomEvent('${prop}-changed', {
|
|
529
|
+
detail: { value, oldValue },
|
|
530
|
+
bubbles: true
|
|
531
|
+
}));
|
|
532
|
+
}`;
|
|
533
|
+
}).join(`
|
|
534
|
+
`), attributeChangedCode = observedAttributes.length > 0 ? `
|
|
535
|
+
static get observedAttributes() {
|
|
536
|
+
return [${observedAttributes.map((a) => `'${a}'`).join(", ")}];
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
540
|
+
if (oldValue === newValue) return;
|
|
541
|
+
const propName = this._attrToProp[name];
|
|
542
|
+
if (propName) {
|
|
543
|
+
const propDef = this._propertyDefs[propName];
|
|
544
|
+
this[propName] = this._deserializeAttribute(newValue, propDef.type);
|
|
545
|
+
}
|
|
546
|
+
${lifecycle.attributeChanged || ""}
|
|
547
|
+
}` : "", eventBindings = Object.entries(events).map(([event, handler]) => {
|
|
548
|
+
return `this._root.addEventListener('${event}', (e) => { ${handler} });`;
|
|
549
|
+
}).join(`
|
|
550
|
+
`), methodDefinitions = Object.entries(methods).map(([methodName, body]) => {
|
|
551
|
+
return `
|
|
552
|
+
${methodName}() {
|
|
553
|
+
${body}
|
|
554
|
+
}`;
|
|
555
|
+
}).join(`
|
|
556
|
+
`), propertyDefsMap = JSON.stringify(Object.fromEntries(propertyNames.map((prop) => [prop, properties[prop]]))), attrToPropMap = JSON.stringify(Object.fromEntries(propertyNames.filter((prop) => properties[prop].attribute !== !1).map((prop) => [properties[prop].attribute || camelToKebab(prop), prop]))), escapedTemplate = template.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${"), escapedStyles = styles.replace(/\\/g, "\\\\").replace(/`/g, "\\`");
|
|
557
|
+
return `/**
|
|
558
|
+
* ${name} - Reactive Web Component
|
|
559
|
+
* Auto-generated with reactive properties and lifecycle management
|
|
560
|
+
*
|
|
561
|
+
* @customElement ${tag}
|
|
562
|
+
*/
|
|
563
|
+
class ${className} extends ${baseElement} {
|
|
564
|
+
// Property definitions
|
|
565
|
+
_propertyDefs = ${propertyDefsMap};
|
|
566
|
+
_attrToProp = ${attrToPropMap};
|
|
567
|
+
|
|
568
|
+
// Internal state
|
|
569
|
+
_state = ${JSON.stringify(state)};
|
|
570
|
+
_renderPending = false;
|
|
571
|
+
_isConnected = false;
|
|
572
|
+
|
|
573
|
+
constructor() {
|
|
574
|
+
super();
|
|
575
|
+
${shadowDOM ? 'this.attachShadow({ mode: "open" });' : ""}
|
|
576
|
+
this._root = ${shadowDOM ? "this.shadowRoot" : "this"};
|
|
577
|
+
|
|
578
|
+
// Initialize properties with defaults
|
|
579
|
+
${propertyDeclarations}
|
|
580
|
+
|
|
581
|
+
// Initial render
|
|
582
|
+
this._render();
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// =========================================================================
|
|
586
|
+
// Reactive Properties
|
|
587
|
+
// =========================================================================
|
|
588
|
+
${propertyAccessors}
|
|
589
|
+
|
|
590
|
+
// =========================================================================
|
|
591
|
+
// State Management
|
|
592
|
+
// =========================================================================
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Get current internal state
|
|
596
|
+
*/
|
|
597
|
+
get state() {
|
|
598
|
+
return { ...this._state };
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Update internal state and trigger re-render
|
|
603
|
+
* @param {Object} updates - State updates to merge
|
|
604
|
+
*/
|
|
605
|
+
setState(updates) {
|
|
606
|
+
const oldState = { ...this._state };
|
|
607
|
+
this._state = { ...this._state, ...updates };
|
|
608
|
+
this._scheduleRender();
|
|
609
|
+
this.dispatchEvent(new CustomEvent('state-changed', {
|
|
610
|
+
detail: { state: this._state, oldState },
|
|
611
|
+
bubbles: true
|
|
612
|
+
}));
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// =========================================================================
|
|
616
|
+
// Rendering
|
|
617
|
+
// =========================================================================
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* Schedule a render on the next animation frame (batched)
|
|
621
|
+
*/
|
|
622
|
+
_scheduleRender() {
|
|
623
|
+
if (this._renderPending) return;
|
|
624
|
+
this._renderPending = true;
|
|
625
|
+
requestAnimationFrame(() => {
|
|
626
|
+
this._renderPending = false;
|
|
627
|
+
this._render();
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Render the component template
|
|
633
|
+
*/
|
|
634
|
+
_render() {
|
|
635
|
+
const template = \`${escapedStyles ? `<style>${escapedStyles}</style>` : ""}${escapedTemplate}\`;
|
|
636
|
+
|
|
637
|
+
// Interpolate template with property values
|
|
638
|
+
const rendered = template.replace(/\\{\\{\\s*(\\w+)\\s*\\}\\}/g, (match, propName) => {
|
|
639
|
+
if (propName in this) {
|
|
640
|
+
const value = this[propName];
|
|
641
|
+
if (value === null || value === undefined) return '';
|
|
642
|
+
if (typeof value === 'object') return JSON.stringify(value);
|
|
643
|
+
return String(value);
|
|
644
|
+
}
|
|
645
|
+
if (propName in this._state) {
|
|
646
|
+
const value = this._state[propName];
|
|
647
|
+
if (value === null || value === undefined) return '';
|
|
648
|
+
if (typeof value === 'object') return JSON.stringify(value);
|
|
649
|
+
return String(value);
|
|
650
|
+
}
|
|
651
|
+
return match;
|
|
652
|
+
});
|
|
653
|
+
|
|
654
|
+
this._root.innerHTML = rendered;
|
|
655
|
+
this._bindEvents();
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* Bind event handlers after render
|
|
660
|
+
*/
|
|
661
|
+
_bindEvents() {
|
|
662
|
+
${eventBindings}
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
// =========================================================================
|
|
666
|
+
// Attribute Handling
|
|
667
|
+
// =========================================================================
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* Deserialize attribute value to property type
|
|
671
|
+
*/
|
|
672
|
+
_deserializeAttribute(value, type) {
|
|
673
|
+
if (value === null) return null;
|
|
674
|
+
switch (type) {
|
|
675
|
+
case 'number': return Number(value);
|
|
676
|
+
case 'boolean': return value !== null && value !== 'false' && value !== '0';
|
|
677
|
+
case 'object':
|
|
678
|
+
case 'array':
|
|
679
|
+
try { return JSON.parse(value); }
|
|
680
|
+
catch { return type === 'array' ? [] : {}; }
|
|
681
|
+
default: return value;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
${attributeChangedCode}
|
|
686
|
+
|
|
687
|
+
// =========================================================================
|
|
688
|
+
// Lifecycle
|
|
689
|
+
// =========================================================================
|
|
690
|
+
|
|
691
|
+
connectedCallback() {
|
|
692
|
+
this._isConnected = true;
|
|
693
|
+
${lifecycle.connected || "// Component connected to DOM"}
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
disconnectedCallback() {
|
|
697
|
+
this._isConnected = false;
|
|
698
|
+
${lifecycle.disconnected || "// Component disconnected from DOM"}
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
adoptedCallback() {
|
|
702
|
+
${lifecycle.adopted || "// Component moved to new document"}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
// =========================================================================
|
|
706
|
+
// Custom Methods
|
|
707
|
+
// =========================================================================
|
|
708
|
+
${methodDefinitions}
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// Register the custom element
|
|
712
|
+
customElements.define('${tag}', ${className});
|
|
713
|
+
|
|
714
|
+
// Export for module usage
|
|
715
|
+
export { ${className} };
|
|
716
|
+
export default ${className};
|
|
717
|
+
`;
|
|
718
|
+
}
|
|
719
|
+
export function generateReactiveWebComponentTS(config) {
|
|
720
|
+
const {
|
|
721
|
+
name,
|
|
722
|
+
tag,
|
|
723
|
+
baseElement = "HTMLElement",
|
|
724
|
+
template,
|
|
725
|
+
styles = "",
|
|
726
|
+
shadowDOM = !0,
|
|
727
|
+
properties = {},
|
|
728
|
+
lifecycle = {},
|
|
729
|
+
events = {},
|
|
730
|
+
methods = {},
|
|
731
|
+
state = {}
|
|
732
|
+
} = config, className = name.replace(/\W/g, ""), propertyNames = Object.keys(properties), observedAttributes = propertyNames.filter((prop) => properties[prop].attribute !== !1).map((prop) => properties[prop].attribute || camelToKebab(prop)), getTypeScriptType = (type) => {
|
|
733
|
+
switch (type) {
|
|
734
|
+
case "string":
|
|
735
|
+
return "string";
|
|
736
|
+
case "number":
|
|
737
|
+
return "number";
|
|
738
|
+
case "boolean":
|
|
739
|
+
return "boolean";
|
|
740
|
+
case "object":
|
|
741
|
+
return "Record<string, unknown>";
|
|
742
|
+
case "array":
|
|
743
|
+
return "unknown[]";
|
|
744
|
+
default:
|
|
745
|
+
return "unknown";
|
|
746
|
+
}
|
|
747
|
+
}, propsInterface = propertyNames.length > 0 ? `
|
|
748
|
+
/**
|
|
749
|
+
* Props interface for ${name}
|
|
750
|
+
*/
|
|
751
|
+
export interface ${className}Props {
|
|
752
|
+
${propertyNames.map((prop) => ` ${prop}?: ${getTypeScriptType(properties[prop].type)};`).join(`
|
|
753
|
+
`)}
|
|
754
|
+
}
|
|
755
|
+
` : "", stateInterface = Object.keys(state).length > 0 ? `
|
|
756
|
+
/**
|
|
757
|
+
* State interface for ${name}
|
|
758
|
+
*/
|
|
759
|
+
export interface ${className}State {
|
|
760
|
+
${Object.entries(state).map(([key, value]) => ` ${key}: ${typeof value};`).join(`
|
|
761
|
+
`)}
|
|
762
|
+
}
|
|
763
|
+
` : `
|
|
764
|
+
export interface ${className}State {
|
|
765
|
+
[key: string]: unknown;
|
|
766
|
+
}
|
|
767
|
+
`, propertyDeclarations = propertyNames.map((prop) => {
|
|
768
|
+
const def = properties[prop], tsType = getTypeScriptType(def.type);
|
|
769
|
+
return ` private _${prop}: ${tsType};`;
|
|
770
|
+
}).join(`
|
|
771
|
+
`), propertyAccessors = propertyNames.map((prop) => {
|
|
772
|
+
const def = properties[prop], tsType = getTypeScriptType(def.type), attrName = def.attribute !== !1 ? def.attribute || camelToKebab(prop) : null, defaultValue = def.default !== void 0 ? JSON.stringify(def.default) : def.type === "string" ? '""' : def.type === "number" ? "0" : def.type === "boolean" ? "false" : def.type === "array" ? "[]" : "{}", reflectCode = def.reflect && attrName ? `
|
|
773
|
+
if (value !== null && value !== undefined) {
|
|
774
|
+
${def.type === "boolean" ? `if (value) { this.setAttribute('${attrName}', ''); }
|
|
775
|
+
else { this.removeAttribute('${attrName}'); }` : `this.setAttribute('${attrName}', ${def.type === "object" || def.type === "array" ? "JSON.stringify(value)" : "String(value)"});`}
|
|
776
|
+
}
|
|
777
|
+
else {
|
|
778
|
+
this.removeAttribute('${attrName}');
|
|
779
|
+
}` : "", observerCode = def.observer ? `this.${def.observer}(value, oldValue);` : "", renderCode = def.render !== !1 ? "this._scheduleRender();" : "";
|
|
780
|
+
return `
|
|
781
|
+
get ${prop}(): ${tsType} {
|
|
782
|
+
return this._${prop};
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
set ${prop}(value: ${tsType}) {
|
|
786
|
+
const oldValue = this._${prop};
|
|
787
|
+
if (oldValue === value) return;
|
|
788
|
+
this._${prop} = value;${reflectCode}
|
|
789
|
+
${observerCode}
|
|
790
|
+
${renderCode}
|
|
791
|
+
this.dispatchEvent(new CustomEvent('${prop}-changed', {
|
|
792
|
+
detail: { value, oldValue },
|
|
793
|
+
bubbles: true
|
|
794
|
+
}));
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
// Property default: ${defaultValue}`;
|
|
798
|
+
}).join(`
|
|
799
|
+
`), attributeChangedCode = observedAttributes.length > 0 ? `
|
|
800
|
+
static get observedAttributes(): string[] {
|
|
801
|
+
return [${observedAttributes.map((a) => `'${a}'`).join(", ")}];
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void {
|
|
805
|
+
if (oldValue === newValue) return;
|
|
806
|
+
const propName = this._attrToProp[name];
|
|
807
|
+
if (propName) {
|
|
808
|
+
const propDef = this._propertyDefs[propName];
|
|
809
|
+
(this as unknown as Record<string, unknown>)[propName] = this._deserializeAttribute(newValue, propDef.type);
|
|
810
|
+
}
|
|
811
|
+
${lifecycle.attributeChanged || ""}
|
|
812
|
+
}` : "", eventBindings = Object.entries(events).map(([event, handler]) => {
|
|
813
|
+
return `this._root.addEventListener('${event}', (e: Event) => { ${handler} });`;
|
|
814
|
+
}).join(`
|
|
815
|
+
`), methodDefinitions = Object.entries(methods).map(([methodName, body]) => {
|
|
816
|
+
return `
|
|
817
|
+
${methodName}(): void {
|
|
818
|
+
${body}
|
|
819
|
+
}`;
|
|
820
|
+
}).join(`
|
|
821
|
+
`), escapedTemplate = template.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${"), escapedStyles = styles.replace(/\\/g, "\\\\").replace(/`/g, "\\`");
|
|
822
|
+
return `/**
|
|
823
|
+
* ${name} - Reactive Web Component (TypeScript)
|
|
824
|
+
* Auto-generated with reactive properties and lifecycle management
|
|
825
|
+
*
|
|
826
|
+
* @customElement ${tag}
|
|
827
|
+
*/
|
|
828
|
+
|
|
829
|
+
${propsInterface}
|
|
830
|
+
${stateInterface}
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* Property definition type
|
|
834
|
+
*/
|
|
835
|
+
interface PropertyDefinition {
|
|
836
|
+
type: 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
837
|
+
default?: unknown;
|
|
838
|
+
reflect?: boolean;
|
|
839
|
+
attribute?: string | false;
|
|
840
|
+
observer?: string;
|
|
841
|
+
render?: boolean;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
/**
|
|
845
|
+
* ${name} custom element
|
|
846
|
+
*/
|
|
847
|
+
export class ${className} extends ${baseElement} {
|
|
848
|
+
// Property definitions
|
|
849
|
+
private _propertyDefs: Record<string, PropertyDefinition> = ${JSON.stringify(properties)};
|
|
850
|
+
private _attrToProp: Record<string, string> = ${JSON.stringify(Object.fromEntries(propertyNames.filter((prop) => properties[prop].attribute !== !1).map((prop) => [properties[prop].attribute || camelToKebab(prop), prop])))};
|
|
851
|
+
|
|
852
|
+
// Internal state
|
|
853
|
+
private _state: ${className}State = ${JSON.stringify(state)};
|
|
854
|
+
private _renderPending = false;
|
|
855
|
+
private _isConnected = false;
|
|
856
|
+
private _root: ShadowRoot | HTMLElement;
|
|
857
|
+
|
|
858
|
+
// Property backing fields
|
|
859
|
+
${propertyDeclarations}
|
|
860
|
+
|
|
861
|
+
constructor() {
|
|
862
|
+
super();
|
|
863
|
+
${shadowDOM ? 'this.attachShadow({ mode: "open" });' : ""}
|
|
864
|
+
this._root = ${shadowDOM ? "this.shadowRoot!" : "this"};
|
|
865
|
+
|
|
866
|
+
// Initialize properties with defaults
|
|
867
|
+
${propertyNames.map((prop) => {
|
|
868
|
+
const def = properties[prop], defaultValue = def.default !== void 0 ? JSON.stringify(def.default) : def.type === "string" ? '""' : def.type === "number" ? "0" : def.type === "boolean" ? "false" : def.type === "array" ? "[]" : "{}";
|
|
869
|
+
return ` this._${prop} = ${defaultValue};`;
|
|
870
|
+
}).join(`
|
|
871
|
+
`)}
|
|
872
|
+
|
|
873
|
+
// Initial render
|
|
874
|
+
this._render();
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
// =========================================================================
|
|
878
|
+
// Reactive Properties
|
|
879
|
+
// =========================================================================
|
|
880
|
+
${propertyAccessors}
|
|
881
|
+
|
|
882
|
+
// =========================================================================
|
|
883
|
+
// State Management
|
|
884
|
+
// =========================================================================
|
|
885
|
+
|
|
886
|
+
/**
|
|
887
|
+
* Get current internal state
|
|
888
|
+
*/
|
|
889
|
+
get state(): ${className}State {
|
|
890
|
+
return { ...this._state };
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* Update internal state and trigger re-render
|
|
895
|
+
*/
|
|
896
|
+
setState(updates: Partial<${className}State>): void {
|
|
897
|
+
const oldState = { ...this._state };
|
|
898
|
+
this._state = { ...this._state, ...updates };
|
|
899
|
+
this._scheduleRender();
|
|
900
|
+
this.dispatchEvent(new CustomEvent('state-changed', {
|
|
901
|
+
detail: { state: this._state, oldState },
|
|
902
|
+
bubbles: true
|
|
903
|
+
}));
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
// =========================================================================
|
|
907
|
+
// Rendering
|
|
908
|
+
// =========================================================================
|
|
909
|
+
|
|
910
|
+
/**
|
|
911
|
+
* Schedule a render on the next animation frame (batched)
|
|
912
|
+
*/
|
|
913
|
+
private _scheduleRender(): void {
|
|
914
|
+
if (this._renderPending) return;
|
|
915
|
+
this._renderPending = true;
|
|
916
|
+
requestAnimationFrame(() => {
|
|
917
|
+
this._renderPending = false;
|
|
918
|
+
this._render();
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
/**
|
|
923
|
+
* Render the component template
|
|
924
|
+
*/
|
|
925
|
+
private _render(): void {
|
|
926
|
+
const template = \`${escapedStyles ? `<style>${escapedStyles}</style>` : ""}${escapedTemplate}\`;
|
|
927
|
+
|
|
928
|
+
// Interpolate template with property values
|
|
929
|
+
const rendered = template.replace(/\\{\\{\\s*(\\w+)\\s*\\}\\}/g, (match, propName) => {
|
|
930
|
+
if (propName in this) {
|
|
931
|
+
const value = (this as unknown as Record<string, unknown>)[propName];
|
|
932
|
+
if (value === null || value === undefined) return '';
|
|
933
|
+
if (typeof value === 'object') return JSON.stringify(value);
|
|
934
|
+
return String(value);
|
|
935
|
+
}
|
|
936
|
+
if (propName in this._state) {
|
|
937
|
+
const value = this._state[propName as keyof ${className}State];
|
|
938
|
+
if (value === null || value === undefined) return '';
|
|
939
|
+
if (typeof value === 'object') return JSON.stringify(value);
|
|
940
|
+
return String(value);
|
|
941
|
+
}
|
|
942
|
+
return match;
|
|
943
|
+
});
|
|
944
|
+
|
|
945
|
+
this._root.innerHTML = rendered;
|
|
946
|
+
this._bindEvents();
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
/**
|
|
950
|
+
* Bind event handlers after render
|
|
951
|
+
*/
|
|
952
|
+
private _bindEvents(): void {
|
|
953
|
+
${eventBindings}
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
// =========================================================================
|
|
957
|
+
// Attribute Handling
|
|
958
|
+
// =========================================================================
|
|
959
|
+
|
|
960
|
+
/**
|
|
961
|
+
* Deserialize attribute value to property type
|
|
962
|
+
*/
|
|
963
|
+
private _deserializeAttribute(value: string | null, type: string): unknown {
|
|
964
|
+
if (value === null) return null;
|
|
965
|
+
switch (type) {
|
|
966
|
+
case 'number': return Number(value);
|
|
967
|
+
case 'boolean': return value !== null && value !== 'false' && value !== '0';
|
|
968
|
+
case 'object':
|
|
969
|
+
case 'array':
|
|
970
|
+
try { return JSON.parse(value); }
|
|
971
|
+
catch { return type === 'array' ? [] : {}; }
|
|
972
|
+
default: return value;
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
${attributeChangedCode}
|
|
977
|
+
|
|
978
|
+
// =========================================================================
|
|
979
|
+
// Lifecycle
|
|
980
|
+
// =========================================================================
|
|
981
|
+
|
|
982
|
+
connectedCallback(): void {
|
|
983
|
+
this._isConnected = true;
|
|
984
|
+
${lifecycle.connected || "// Component connected to DOM"}
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
disconnectedCallback(): void {
|
|
988
|
+
this._isConnected = false;
|
|
989
|
+
${lifecycle.disconnected || "// Component disconnected from DOM"}
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
adoptedCallback(): void {
|
|
993
|
+
${lifecycle.adopted || "// Component moved to new document"}
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
// =========================================================================
|
|
997
|
+
// Custom Methods
|
|
998
|
+
// =========================================================================
|
|
999
|
+
${methodDefinitions}
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
// Type augmentation for HTMLElementTagNameMap
|
|
1003
|
+
declare global {
|
|
1004
|
+
interface HTMLElementTagNameMap {
|
|
1005
|
+
'${tag}': ${className};
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
// Register the custom element
|
|
1010
|
+
customElements.define('${tag}', ${className});
|
|
1011
|
+
|
|
1012
|
+
export default ${className};
|
|
1013
|
+
`;
|
|
1014
|
+
}
|
|
1015
|
+
export function generateReactiveMixin() {
|
|
1016
|
+
return `/**
|
|
1017
|
+
* ReactiveElement Mixin
|
|
1018
|
+
* Adds reactive properties and lifecycle management to web components
|
|
1019
|
+
*/
|
|
1020
|
+
const ReactiveElement = (Base) => class extends Base {
|
|
1021
|
+
static get observedAttributes() {
|
|
1022
|
+
const props = this.properties || {};
|
|
1023
|
+
return Object.keys(props)
|
|
1024
|
+
.filter(prop => props[prop].attribute !== false)
|
|
1025
|
+
.map(prop => props[prop].attribute || prop.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase());
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
constructor() {
|
|
1029
|
+
super();
|
|
1030
|
+
this._state = {};
|
|
1031
|
+
this._renderPending = false;
|
|
1032
|
+
this._propertyValues = new Map();
|
|
1033
|
+
this._initializeProperties();
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
_initializeProperties() {
|
|
1037
|
+
const props = this.constructor.properties || {};
|
|
1038
|
+
for (const [name, def] of Object.entries(props)) {
|
|
1039
|
+
// Set default value
|
|
1040
|
+
if (def.default !== undefined) {
|
|
1041
|
+
this._propertyValues.set(name, def.default);
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
// Define getter/setter
|
|
1045
|
+
Object.defineProperty(this, name, {
|
|
1046
|
+
get: () => this._propertyValues.get(name),
|
|
1047
|
+
set: (value) => {
|
|
1048
|
+
const oldValue = this._propertyValues.get(name);
|
|
1049
|
+
if (oldValue === value) return;
|
|
1050
|
+
this._propertyValues.set(name, value);
|
|
1051
|
+
|
|
1052
|
+
// Reflect to attribute
|
|
1053
|
+
if (def.reflect) {
|
|
1054
|
+
const attrName = def.attribute || name.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
|
|
1055
|
+
if (def.type === 'boolean') {
|
|
1056
|
+
value ? this.setAttribute(attrName, '') : this.removeAttribute(attrName);
|
|
1057
|
+
}
|
|
1058
|
+
else {
|
|
1059
|
+
this.setAttribute(attrName, def.type === 'object' ? JSON.stringify(value) : String(value));
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
// Call observer
|
|
1064
|
+
if (def.observer && typeof this[def.observer] === 'function') {
|
|
1065
|
+
this[def.observer](value, oldValue);
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
// Schedule render
|
|
1069
|
+
if (def.render !== false) {
|
|
1070
|
+
this._scheduleRender();
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
// Dispatch event
|
|
1074
|
+
this.dispatchEvent(new CustomEvent(\`\${name}-changed\`, {
|
|
1075
|
+
detail: { value, oldValue },
|
|
1076
|
+
bubbles: true
|
|
1077
|
+
}));
|
|
1078
|
+
},
|
|
1079
|
+
enumerable: true,
|
|
1080
|
+
configurable: true
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
1086
|
+
if (oldValue === newValue) return;
|
|
1087
|
+
const props = this.constructor.properties || {};
|
|
1088
|
+
const propName = Object.keys(props).find(p =>
|
|
1089
|
+
(props[p].attribute || p.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase()) === name
|
|
1090
|
+
);
|
|
1091
|
+
if (propName) {
|
|
1092
|
+
const def = props[propName];
|
|
1093
|
+
this[propName] = this._deserialize(newValue, def.type);
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
_deserialize(value, type) {
|
|
1098
|
+
if (value === null) return null;
|
|
1099
|
+
switch (type) {
|
|
1100
|
+
case 'number': return Number(value);
|
|
1101
|
+
case 'boolean': return value !== null && value !== 'false';
|
|
1102
|
+
case 'object':
|
|
1103
|
+
case 'array':
|
|
1104
|
+
try { return JSON.parse(value); }
|
|
1105
|
+
catch { return type === 'array' ? [] : {}; }
|
|
1106
|
+
default: return value;
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
get state() {
|
|
1111
|
+
return { ...this._state };
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
setState(updates) {
|
|
1115
|
+
const oldState = { ...this._state };
|
|
1116
|
+
this._state = { ...this._state, ...updates };
|
|
1117
|
+
this._scheduleRender();
|
|
1118
|
+
this.dispatchEvent(new CustomEvent('state-changed', {
|
|
1119
|
+
detail: { state: this._state, oldState },
|
|
1120
|
+
bubbles: true
|
|
1121
|
+
}));
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
_scheduleRender() {
|
|
1125
|
+
if (this._renderPending) return;
|
|
1126
|
+
this._renderPending = true;
|
|
1127
|
+
requestAnimationFrame(() => {
|
|
1128
|
+
this._renderPending = false;
|
|
1129
|
+
if (typeof this.render === 'function') {
|
|
1130
|
+
this.render();
|
|
1131
|
+
}
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
};
|
|
1135
|
+
|
|
1136
|
+
export { ReactiveElement };
|
|
1137
|
+
export default ReactiveElement;
|
|
1138
|
+
`;
|
|
1139
|
+
}
|
|
1140
|
+
export function generateReactiveRuntime() {
|
|
1141
|
+
return `/**
|
|
1142
|
+
* stx Reactive Web Components Runtime
|
|
1143
|
+
* Provides base classes and utilities for reactive web components
|
|
1144
|
+
*/
|
|
1145
|
+
(function(global) {
|
|
1146
|
+
'use strict';
|
|
1147
|
+
|
|
1148
|
+
/**
|
|
1149
|
+
* Base class for reactive web components
|
|
1150
|
+
*/
|
|
1151
|
+
class StxElement extends HTMLElement {
|
|
1152
|
+
static get observedAttributes() {
|
|
1153
|
+
const props = this.properties || {};
|
|
1154
|
+
return Object.keys(props)
|
|
1155
|
+
.filter(prop => props[prop].attribute !== false)
|
|
1156
|
+
.map(prop => props[prop].attribute || toKebabCase(prop));
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
constructor() {
|
|
1160
|
+
super();
|
|
1161
|
+
this._state = {};
|
|
1162
|
+
this._renderPending = false;
|
|
1163
|
+
this._props = new Map();
|
|
1164
|
+
this._setupShadowDOM();
|
|
1165
|
+
this._initProperties();
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
_setupShadowDOM() {
|
|
1169
|
+
if (this.constructor.useShadowDOM !== false) {
|
|
1170
|
+
this.attachShadow({ mode: 'open' });
|
|
1171
|
+
this._root = this.shadowRoot;
|
|
1172
|
+
}
|
|
1173
|
+
else {
|
|
1174
|
+
this._root = this;
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
_initProperties() {
|
|
1179
|
+
const props = this.constructor.properties || {};
|
|
1180
|
+
for (const [name, def] of Object.entries(props)) {
|
|
1181
|
+
let value = def.default;
|
|
1182
|
+
this._props.set(name, value);
|
|
1183
|
+
|
|
1184
|
+
Object.defineProperty(this, name, {
|
|
1185
|
+
get: () => this._props.get(name),
|
|
1186
|
+
set: (newValue) => this._setProperty(name, newValue, def),
|
|
1187
|
+
enumerable: true
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
_setProperty(name, value, def) {
|
|
1193
|
+
const oldValue = this._props.get(name);
|
|
1194
|
+
if (oldValue === value) return;
|
|
1195
|
+
|
|
1196
|
+
this._props.set(name, value);
|
|
1197
|
+
|
|
1198
|
+
if (def.reflect && def.attribute !== false) {
|
|
1199
|
+
this._reflectToAttribute(name, value, def);
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
if (def.observer && this[def.observer]) {
|
|
1203
|
+
this[def.observer](value, oldValue);
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
if (def.render !== false) {
|
|
1207
|
+
this.requestUpdate();
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
this.dispatchEvent(new CustomEvent(name + '-changed', {
|
|
1211
|
+
detail: { value, oldValue },
|
|
1212
|
+
bubbles: true,
|
|
1213
|
+
composed: true
|
|
1214
|
+
}));
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
_reflectToAttribute(name, value, def) {
|
|
1218
|
+
const attrName = def.attribute || toKebabCase(name);
|
|
1219
|
+
if (value == null || (def.type === 'boolean' && !value)) {
|
|
1220
|
+
this.removeAttribute(attrName);
|
|
1221
|
+
}
|
|
1222
|
+
else if (def.type === 'boolean') {
|
|
1223
|
+
this.setAttribute(attrName, '');
|
|
1224
|
+
}
|
|
1225
|
+
else if (def.type === 'object' || def.type === 'array') {
|
|
1226
|
+
this.setAttribute(attrName, JSON.stringify(value));
|
|
1227
|
+
}
|
|
1228
|
+
else {
|
|
1229
|
+
this.setAttribute(attrName, String(value));
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
1234
|
+
if (oldValue === newValue) return;
|
|
1235
|
+
const props = this.constructor.properties || {};
|
|
1236
|
+
const propName = Object.keys(props).find(p => {
|
|
1237
|
+
const def = props[p];
|
|
1238
|
+
return (def.attribute || toKebabCase(p)) === name;
|
|
1239
|
+
});
|
|
1240
|
+
|
|
1241
|
+
if (propName) {
|
|
1242
|
+
const def = props[propName];
|
|
1243
|
+
this[propName] = deserialize(newValue, def.type);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
get state() {
|
|
1248
|
+
return { ...this._state };
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
setState(updates) {
|
|
1252
|
+
const oldState = { ...this._state };
|
|
1253
|
+
Object.assign(this._state, updates);
|
|
1254
|
+
this.requestUpdate();
|
|
1255
|
+
this.dispatchEvent(new CustomEvent('state-changed', {
|
|
1256
|
+
detail: { state: this._state, oldState },
|
|
1257
|
+
bubbles: true
|
|
1258
|
+
}));
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
requestUpdate() {
|
|
1262
|
+
if (this._renderPending) return;
|
|
1263
|
+
this._renderPending = true;
|
|
1264
|
+
requestAnimationFrame(() => {
|
|
1265
|
+
this._renderPending = false;
|
|
1266
|
+
this.update();
|
|
1267
|
+
});
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
update() {
|
|
1271
|
+
if (this.render) {
|
|
1272
|
+
const content = this.render();
|
|
1273
|
+
if (typeof content === 'string') {
|
|
1274
|
+
this._root.innerHTML = content;
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
connectedCallback() {
|
|
1280
|
+
this.update();
|
|
1281
|
+
if (this.connected) this.connected();
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
disconnectedCallback() {
|
|
1285
|
+
if (this.disconnected) this.disconnected();
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
adoptedCallback() {
|
|
1289
|
+
if (this.adopted) this.adopted();
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
// Template helper
|
|
1293
|
+
html(strings, ...values) {
|
|
1294
|
+
return strings.reduce((result, str, i) => {
|
|
1295
|
+
let value = values[i] || '';
|
|
1296
|
+
if (Array.isArray(value)) value = value.join('');
|
|
1297
|
+
if (typeof value === 'object') value = JSON.stringify(value);
|
|
1298
|
+
return result + str + value;
|
|
1299
|
+
}, '');
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
// Utility functions
|
|
1304
|
+
function toKebabCase(str) {
|
|
1305
|
+
return str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
function deserialize(value, type) {
|
|
1309
|
+
if (value === null) return null;
|
|
1310
|
+
switch (type) {
|
|
1311
|
+
case 'number': return Number(value);
|
|
1312
|
+
case 'boolean': return value !== null && value !== 'false' && value !== '0';
|
|
1313
|
+
case 'object':
|
|
1314
|
+
case 'array':
|
|
1315
|
+
try { return JSON.parse(value); }
|
|
1316
|
+
catch { return type === 'array' ? [] : {}; }
|
|
1317
|
+
default: return value;
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
// Export to global
|
|
1322
|
+
global.StxElement = StxElement;
|
|
1323
|
+
global.stxComponents = global.stxComponents || {};
|
|
1324
|
+
|
|
1325
|
+
// Helper to define components
|
|
1326
|
+
global.defineStxComponent = function(tag, config) {
|
|
1327
|
+
const { properties, template, styles, methods, ...options } = config;
|
|
1328
|
+
|
|
1329
|
+
class Component extends StxElement {
|
|
1330
|
+
static get properties() { return properties || {}; }
|
|
1331
|
+
static get useShadowDOM() { return options.shadowDOM !== false; }
|
|
1332
|
+
|
|
1333
|
+
render() {
|
|
1334
|
+
let html = template || '';
|
|
1335
|
+
// Simple interpolation
|
|
1336
|
+
html = html.replace(/\\{\\{\\s*(\\w+)\\s*\\}\\}/g, (match, key) => {
|
|
1337
|
+
if (key in this) return this[key] ?? '';
|
|
1338
|
+
if (key in this._state) return this._state[key] ?? '';
|
|
1339
|
+
return match;
|
|
1340
|
+
});
|
|
1341
|
+
return (styles ? '<style>' + styles + '</style>' : '') + html;
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
// Add methods
|
|
1346
|
+
if (methods) {
|
|
1347
|
+
for (const [name, fn] of Object.entries(methods)) {
|
|
1348
|
+
Component.prototype[name] = fn;
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
customElements.define(tag, Component);
|
|
1353
|
+
global.stxComponents[tag] = Component;
|
|
1354
|
+
return Component;
|
|
1355
|
+
};
|
|
1356
|
+
|
|
1357
|
+
})(typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : this);
|
|
1358
|
+
`;
|
|
1359
|
+
}
|
|
1360
|
+
export function parseSFCComponent(source, defaultTag) {
|
|
1361
|
+
const scriptMatch = source.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i), scriptContent = scriptMatch ? scriptMatch[1].trim() : "";
|
|
1362
|
+
let tag = defaultTag, props = [], shadowDOM = !0;
|
|
1363
|
+
if (scriptContent) {
|
|
1364
|
+
const exportMatch = scriptContent.match(/export\s+default\s+({[\s\S]*})/);
|
|
1365
|
+
if (exportMatch)
|
|
1366
|
+
try {
|
|
1367
|
+
const configStr = exportMatch[1], tagMatch = configStr.match(/tag\s*:\s*['"`]([^'"`]+)['"`]/);
|
|
1368
|
+
if (tagMatch)
|
|
1369
|
+
tag = tagMatch[1];
|
|
1370
|
+
const propsMatch = configStr.match(/props\s*:\s*\[([\s\S]*?)\]/);
|
|
1371
|
+
if (propsMatch)
|
|
1372
|
+
props = propsMatch[1].split(",").map((p) => p.trim().replace(/['"`]/g, "")).filter((p) => p.length > 0);
|
|
1373
|
+
const shadowMatch = configStr.match(/shadowDOM\s*:\s*(true|false)/);
|
|
1374
|
+
if (shadowMatch)
|
|
1375
|
+
shadowDOM = shadowMatch[1] === "true";
|
|
1376
|
+
} catch {}
|
|
1377
|
+
}
|
|
1378
|
+
const templateMatch = source.match(/<template\b(?![^>]*\bid\s*=)[^>]*>([\s\S]*?)<\/template>/i), template = templateMatch ? templateMatch[1].trim() : "", styleMatch = source.match(/<style\b[^>]*>([\s\S]*?)<\/style>/i), styles = styleMatch ? styleMatch[1].trim() : "";
|
|
1379
|
+
return {
|
|
1380
|
+
tag,
|
|
1381
|
+
props,
|
|
1382
|
+
template,
|
|
1383
|
+
styles,
|
|
1384
|
+
script: scriptContent,
|
|
1385
|
+
shadowDOM
|
|
1386
|
+
};
|
|
1387
|
+
}
|
|
1388
|
+
export function generateSFCWebComponent(parsed) {
|
|
1389
|
+
const { tag, props, template, styles, shadowDOM } = parsed, className = tag.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(""), escapedTemplate = template.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${"), escapedStyles = styles.replace(/\\/g, "\\\\").replace(/`/g, "\\`"), observedAttrs = props.map((p) => `'${p}'`).join(", "), propertyAccessors = props.map((prop) => `
|
|
1390
|
+
get ${prop}() {
|
|
1391
|
+
return this.getAttribute('${prop}') || '';
|
|
1392
|
+
}
|
|
1393
|
+
set ${prop}(value) {
|
|
1394
|
+
if (value) {
|
|
1395
|
+
this.setAttribute('${prop}', value);
|
|
1396
|
+
}
|
|
1397
|
+
else {
|
|
1398
|
+
this.removeAttribute('${prop}');
|
|
1399
|
+
}
|
|
1400
|
+
}`).join(`
|
|
1401
|
+
`);
|
|
1402
|
+
return `/**
|
|
1403
|
+
* ${className} Web Component
|
|
1404
|
+
* Auto-generated from SFC
|
|
1405
|
+
*/
|
|
1406
|
+
class ${className} extends HTMLElement {
|
|
1407
|
+
constructor() {
|
|
1408
|
+
super();
|
|
1409
|
+
${shadowDOM ? "this.attachShadow({ mode: 'open' });" : ""}
|
|
1410
|
+
this._render();
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
static get observedAttributes() {
|
|
1414
|
+
return [${observedAttrs}];
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
1418
|
+
if (oldValue !== newValue) {
|
|
1419
|
+
this._render();
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
${propertyAccessors}
|
|
1423
|
+
|
|
1424
|
+
_render() {
|
|
1425
|
+
const template = \`${escapedStyles ? `<style>${escapedStyles}</style>` : ""}${escapedTemplate}\`;
|
|
1426
|
+
|
|
1427
|
+
// Interpolate {{ prop }} with attribute values
|
|
1428
|
+
const rendered = template.replace(/\\{\\{\\s*(\\w+)\\s*\\}\\}/g, (match, prop) => {
|
|
1429
|
+
return this.getAttribute(prop) || '';
|
|
1430
|
+
});
|
|
1431
|
+
|
|
1432
|
+
${shadowDOM ? "this.shadowRoot.innerHTML = rendered;" : "this.innerHTML = rendered;"}
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
connectedCallback() {
|
|
1436
|
+
this._render();
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1440
|
+
customElements.define('${tag}', ${className});
|
|
1441
|
+
`;
|
|
1442
|
+
}
|
|
1443
|
+
export async function webComponentDirectiveHandler(content, params, context, filePath) {
|
|
1444
|
+
if (params.length < 1)
|
|
1445
|
+
return inlineError("WebComponent", "@webcomponent directive requires at least the tag name parameter", ErrorCodes.INVALID_DIRECTIVE_SYNTAX);
|
|
1446
|
+
const tagName = params[0].replace(/['"]/g, ""), componentsDir = (context.__stx_options || {}).componentsDir || "components", possiblePaths = path.isAbsolute(componentsDir) ? [
|
|
1447
|
+
path.join(componentsDir, `${tagName}.stx`),
|
|
1448
|
+
path.join(path.dirname(filePath), `${tagName}.stx`)
|
|
1449
|
+
] : [
|
|
1450
|
+
path.join(path.dirname(filePath), componentsDir, `${tagName}.stx`),
|
|
1451
|
+
path.join(process.cwd(), componentsDir, `${tagName}.stx`),
|
|
1452
|
+
path.join(path.dirname(filePath), `${tagName}.stx`)
|
|
1453
|
+
];
|
|
1454
|
+
let componentSource = null;
|
|
1455
|
+
for (const componentPath of possiblePaths)
|
|
1456
|
+
if (await fileExists(componentPath)) {
|
|
1457
|
+
componentSource = await Bun.file(componentPath).text();
|
|
1458
|
+
break;
|
|
1459
|
+
}
|
|
1460
|
+
if (!componentSource)
|
|
1461
|
+
return inlineError("WebComponent", `Component file not found: ${tagName}.stx`, ErrorCodes.FILE_NOT_FOUND);
|
|
1462
|
+
const parsed = parseSFCComponent(componentSource, tagName);
|
|
1463
|
+
return `<script type="module">
|
|
1464
|
+
${generateSFCWebComponent(parsed)}
|
|
1465
|
+
</script>`;
|
|
1466
|
+
}
|