fancy-ui-vue 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (292) hide show
  1. package/PORTING.md +123 -2
  2. package/README.md +15 -13
  3. package/dist/components/accordion/Accordion.vue.d.ts +44 -0
  4. package/dist/components/accordion/Accordion.vue.js +88 -0
  5. package/dist/components/accordion/Accordion.vue2.js +4 -0
  6. package/dist/components/accordion/AccordionContent.vue.d.ts +25 -0
  7. package/dist/components/accordion/AccordionContent.vue.js +42 -0
  8. package/dist/components/accordion/AccordionContent.vue2.js +4 -0
  9. package/dist/components/accordion/AccordionItem.vue.d.ts +21 -0
  10. package/dist/components/accordion/AccordionItem.vue.js +66 -0
  11. package/dist/components/accordion/AccordionItem.vue2.js +4 -0
  12. package/dist/components/accordion/AccordionTrigger.vue.d.ts +24 -0
  13. package/dist/components/accordion/AccordionTrigger.vue.js +83 -0
  14. package/dist/components/accordion/AccordionTrigger.vue2.js +4 -0
  15. package/dist/components/accordion/accordion-core.d.ts +35 -0
  16. package/dist/components/accordion/accordion-core.js +44 -0
  17. package/dist/components/accordion/index.d.ts +11 -0
  18. package/dist/components/accordion/types.d.ts +45 -0
  19. package/dist/components/accordion/types.js +7 -0
  20. package/dist/components/alert-dialog/AlertDialog.vue.js +22 -3
  21. package/dist/components/animated-testimonials/AnimatedTestimonials.vue.js +3 -3
  22. package/dist/components/apple-card-carousel/AppleCard.vue.js +1 -1
  23. package/dist/components/autocomplete/Autocomplete.vue.js +1 -1
  24. package/dist/components/autocomplete/Autocomplete.vue2.js +22 -15
  25. package/dist/components/avatar/Avatar.vue.d.ts +27 -0
  26. package/dist/components/avatar/Avatar.vue.js +119 -0
  27. package/dist/components/avatar/Avatar.vue2.js +4 -0
  28. package/dist/components/avatar/avatar-core.d.ts +40 -0
  29. package/dist/components/avatar/avatar-core.js +57 -0
  30. package/dist/components/avatar/index.d.ts +2 -0
  31. package/dist/components/badge/Badge.vue.d.ts +21 -0
  32. package/dist/components/badge/Badge.vue.js +46 -0
  33. package/dist/components/badge/Badge.vue2.js +4 -0
  34. package/dist/components/badge/index.d.ts +2 -0
  35. package/dist/components/bento-grid/BentoFrame.vue.js +1 -1
  36. package/dist/components/bento-grid/BentoFrame.vue2.js +6 -5
  37. package/dist/components/bento-grid/BentoGrid.vue.js +1 -1
  38. package/dist/components/bento-grid/BentoGrid.vue2.js +12 -12
  39. package/dist/components/bento-grid/BentoGridCard.vue.js +6 -5
  40. package/dist/components/bento-grid/BentoGridItem.vue.js +6 -5
  41. package/dist/components/bg-falling-stars/FallingStarsBg.vue.d.ts +1 -1
  42. package/dist/components/bg-falling-stars/FallingStarsBg.vue.js +1 -1
  43. package/dist/components/bg-falling-stars/bg-falling-stars-core.d.ts +1 -1
  44. package/dist/components/bg-falling-stars/bg-falling-stars-core.js +47 -12
  45. package/dist/components/book/Book.vue.js +8 -9
  46. package/dist/components/book/BookDescription.vue.js +6 -5
  47. package/dist/components/book/BookHeader.vue.js +6 -5
  48. package/dist/components/book/BookTitle.vue.js +6 -5
  49. package/dist/components/box-reveal/BoxReveal.vue.js +6 -5
  50. package/dist/components/button/Button.vue.d.ts +6 -4
  51. package/dist/components/button/Button.vue.js +1 -1
  52. package/dist/components/button/Button.vue2.js +50 -22
  53. package/dist/components/card-3d/CardContainer.vue.js +1 -1
  54. package/dist/components/card-3d/CardItem.vue.js +1 -1
  55. package/dist/components/card-spotlight/CardSpotlight.vue.js +1 -1
  56. package/dist/components/chat-message/ChatMessageAction.vue.d.ts +4 -2
  57. package/dist/components/chat-message/ChatMessageAction.vue.js +4 -2
  58. package/dist/components/checkbox/Checkbox.vue.d.ts +2 -0
  59. package/dist/components/checkbox/Checkbox.vue.js +1 -1
  60. package/dist/components/checkbox/Checkbox.vue2.js +17 -7
  61. package/dist/components/collapsible/Collapsible.vue.d.ts +31 -0
  62. package/dist/components/collapsible/Collapsible.vue.js +60 -0
  63. package/dist/components/collapsible/Collapsible.vue2.js +4 -0
  64. package/dist/components/collapsible/CollapsibleContent.vue.d.ts +26 -0
  65. package/dist/components/collapsible/CollapsibleContent.vue.js +81 -0
  66. package/dist/components/collapsible/CollapsibleContent.vue2.js +4 -0
  67. package/dist/components/collapsible/CollapsibleTrigger.vue.d.ts +21 -0
  68. package/dist/components/collapsible/CollapsibleTrigger.vue.js +57 -0
  69. package/dist/components/collapsible/CollapsibleTrigger.vue2.js +4 -0
  70. package/dist/components/collapsible/collapsible-core.d.ts +47 -0
  71. package/dist/components/collapsible/collapsible-core.js +40 -0
  72. package/dist/components/collapsible/index.d.ts +8 -0
  73. package/dist/components/collapsible/types.d.ts +24 -0
  74. package/dist/components/collapsible/types.js +5 -0
  75. package/dist/components/combobox/Combobox.vue.js +1 -1
  76. package/dist/components/combobox/Combobox.vue2.js +24 -16
  77. package/dist/components/command-menu/CommandMenu.vue.d.ts +5 -0
  78. package/dist/components/command-menu/CommandMenu.vue.js +1 -1
  79. package/dist/components/command-menu/CommandMenu.vue2.js +5 -2
  80. package/dist/components/compare/Compare.vue.d.ts +15 -5
  81. package/dist/components/compare/Compare.vue.js +1 -1
  82. package/dist/components/compare/Compare.vue2.js +28 -13
  83. package/dist/components/composer/ComposerInput.vue.js +1 -1
  84. package/dist/components/composer/ComposerInput.vue2.js +11 -11
  85. package/dist/components/composer/ComposerModelPicker.vue.d.ts +4 -0
  86. package/dist/components/composer/ComposerModelPicker.vue.js +1 -1
  87. package/dist/components/composer/ComposerModelPicker.vue2.js +29 -15
  88. package/dist/components/composer/ComposerSubmit.vue.d.ts +2 -0
  89. package/dist/components/composer/ComposerSubmit.vue.js +16 -15
  90. package/dist/components/confetti/ConfettiButton.vue.d.ts +9 -2
  91. package/dist/components/confetti/ConfettiButton.vue.js +24 -6
  92. package/dist/components/container-text-flip/ContainerTextFlip.vue.js +1 -1
  93. package/dist/components/container-text-flip/ContainerTextFlip.vue2.js +12 -13
  94. package/dist/components/copy-button/CopyButton.vue.d.ts +5 -0
  95. package/dist/components/copy-button/CopyButton.vue.js +1 -1
  96. package/dist/components/copy-button/CopyButton.vue2.js +72 -11
  97. package/dist/components/datamosh-transition/DatamoshTransition.vue.d.ts +6 -2
  98. package/dist/components/datamosh-transition/DatamoshTransition.vue.js +7 -4
  99. package/dist/components/date-picker/DatePicker.vue.js +1 -1
  100. package/dist/components/date-picker/DatePicker.vue2.js +27 -21
  101. package/dist/components/dialog/Dialog.vue.js +20 -1
  102. package/dist/components/dialog/DialogSurface.vue.js +1 -1
  103. package/dist/components/dialog/DialogSurface.vue2.js +5 -2
  104. package/dist/components/dialog/types.d.ts +2 -0
  105. package/dist/components/direction-aware-hover/DirectionAwareHover.vue.js +1 -1
  106. package/dist/components/direction-aware-hover/DirectionAwareHover.vue2.js +9 -7
  107. package/dist/components/displacement-text/DisplacementText.vue.d.ts +4 -1
  108. package/dist/components/displacement-text/DisplacementText.vue.js +38 -11
  109. package/dist/components/displacement-text/displacement-text-core.d.ts +94 -4
  110. package/dist/components/displacement-text/displacement-text-core.js +287 -97
  111. package/dist/components/drawer/Drawer.vue.d.ts +5 -0
  112. package/dist/components/drawer/Drawer.vue.js +1 -1
  113. package/dist/components/drawer/Drawer.vue2.js +5 -2
  114. package/dist/components/dropdown-menu/DropdownMenuContent.vue.js +2 -1
  115. package/dist/components/dropdown-menu/DropdownMenuItem.vue.d.ts +4 -0
  116. package/dist/components/dropdown-menu/DropdownMenuItem.vue.js +17 -10
  117. package/dist/components/dropdown-menu/DropdownMenuSubTrigger.vue.d.ts +8 -0
  118. package/dist/components/dropdown-menu/DropdownMenuSubTrigger.vue.js +28 -13
  119. package/dist/components/dropdown-menu/DropdownMenuTrigger.vue.d.ts +4 -0
  120. package/dist/components/dropdown-menu/DropdownMenuTrigger.vue.js +1 -1
  121. package/dist/components/dropdown-menu/DropdownMenuTrigger.vue2.js +20 -10
  122. package/dist/components/editorial-engine/EditorialEngine.vue.js +1 -1
  123. package/dist/components/editorial-engine/engine.js +13 -0
  124. package/dist/components/file-upload/FileUpload.vue.d.ts +2 -0
  125. package/dist/components/file-upload/FileUpload.vue.js +1 -1
  126. package/dist/components/file-upload/FileUpload.vue2.js +20 -10
  127. package/dist/components/fireworks-hdr/FireworksHdr.vue.js +2 -2
  128. package/dist/components/flickering-grid/FlickeringGrid.vue.d.ts +1 -1
  129. package/dist/components/flickering-grid/FlickeringGrid.vue.js +1 -1
  130. package/dist/components/flickering-grid/flickering-grid-core.d.ts +1 -1
  131. package/dist/components/flickering-grid/flickering-grid-core.js +51 -9
  132. package/dist/components/flip-card/FlipCard.vue.d.ts +3 -1
  133. package/dist/components/flip-card/FlipCard.vue.js +1 -1
  134. package/dist/components/flip-card/FlipCard.vue2.js +5 -3
  135. package/dist/components/fluid-cursor/FluidCursor.vue.js +37 -9
  136. package/dist/components/fluid-cursor/fluid-cursor-core.js +3 -3
  137. package/dist/components/fluid-cursor/webgpu-engine.js +3 -3
  138. package/dist/components/focus/Focus.vue.js +1 -1
  139. package/dist/components/focus/Focus.vue2.js +2 -2
  140. package/dist/components/follow-button/FollowButton.vue.d.ts +69 -0
  141. package/dist/components/follow-button/FollowButton.vue.js +7 -0
  142. package/dist/components/follow-button/FollowButton.vue2.js +239 -0
  143. package/dist/components/follow-button/follow-core.d.ts +83 -0
  144. package/dist/components/follow-button/follow-core.js +92 -0
  145. package/dist/components/follow-button/index.d.ts +2 -0
  146. package/dist/components/frosted-glass/FrostedGlass.vue.js +1 -1
  147. package/dist/components/glare-card/GlareCard.vue.js +1 -1
  148. package/dist/components/glare-card/GlareCard.vue2.js +4 -4
  149. package/dist/components/glowing-effect/GlowingEffect.vue.js +3 -3
  150. package/dist/components/glowing-effect/glowing-effect-core.js +4 -1
  151. package/dist/components/gradient-button/GradientButton.vue.d.ts +6 -4
  152. package/dist/components/gradient-button/GradientButton.vue.js +1 -1
  153. package/dist/components/gradient-button/GradientButton.vue2.js +13 -3
  154. package/dist/components/icon-button/IconButton.vue.d.ts +6 -4
  155. package/dist/components/icon-button/IconButton.vue.js +11 -8
  156. package/dist/components/image-trail-cursor/ImageTrailCursor.vue.js +17 -7
  157. package/dist/components/image-trail-cursor/trail-variants.js +3 -6
  158. package/dist/components/inline-citation/InlineCitation.vue.js +1 -1
  159. package/dist/components/inline-citation/InlineCitation.vue2.js +20 -14
  160. package/dist/components/input/Input.vue.js +1 -1
  161. package/dist/components/input/Input.vue2.js +18 -8
  162. package/dist/components/interactive-grid-pattern/InteractiveGridPattern.vue.js +1 -1
  163. package/dist/components/interactive-grid-pattern/InteractiveGridPattern.vue2.js +1 -1
  164. package/dist/components/interactive-hover-button/InteractiveHoverButton.vue.d.ts +6 -3
  165. package/dist/components/interactive-hover-button/InteractiveHoverButton.vue.js +1 -1
  166. package/dist/components/interactive-hover-button/InteractiveHoverButton.vue2.js +12 -2
  167. package/dist/components/letter-pullup/LetterPullup.vue.js +4 -4
  168. package/dist/components/line-hover-link/LineHoverLink.vue.js +1 -1
  169. package/dist/components/line-hover-link/LineHoverLink.vue2.js +5 -6
  170. package/dist/components/link/Link.vue.d.ts +4 -2
  171. package/dist/components/link/Link.vue.js +1 -1
  172. package/dist/components/link/Link.vue2.js +11 -8
  173. package/dist/components/mosaic-glow/MosaicGlow.vue.d.ts +6 -0
  174. package/dist/components/mosaic-glow/MosaicGlow.vue.js +53 -9
  175. package/dist/components/mosaic-glow/mosaic-glow-core.d.ts +30 -0
  176. package/dist/components/mosaic-glow/mosaic-glow-core.js +27 -0
  177. package/dist/components/mosaic-glow/mosaic-glow-hdr.d.ts +24 -0
  178. package/dist/components/mosaic-glow/mosaic-glow-hdr.js +200 -0
  179. package/dist/components/navbar/NavbarLink.vue.d.ts +4 -2
  180. package/dist/components/navbar/NavbarLink.vue.js +1 -1
  181. package/dist/components/navbar/NavbarLink.vue2.js +16 -13
  182. package/dist/components/navigation-menu/NavigationMenu.vue.js +6 -3
  183. package/dist/components/navigation-menu/NavigationMenuLink.vue.js +1 -1
  184. package/dist/components/navigation-menu/NavigationMenuLink.vue2.js +8 -8
  185. package/dist/components/navigation-menu/NavigationMenuTrigger.vue.d.ts +15 -0
  186. package/dist/components/navigation-menu/NavigationMenuTrigger.vue.js +1 -1
  187. package/dist/components/navigation-menu/NavigationMenuTrigger.vue2.js +36 -15
  188. package/dist/components/neon-border/NeonBorder.vue.js +1 -1
  189. package/dist/components/neon-border/NeonBorder.vue2.js +10 -11
  190. package/dist/components/number-input/NumberInput.vue.js +1 -1
  191. package/dist/components/number-input/NumberInput.vue2.js +22 -12
  192. package/dist/components/password-input/PasswordInput.vue.js +1 -1
  193. package/dist/components/password-input/PasswordInput.vue2.js +18 -11
  194. package/dist/components/pixel-loader/PixelLoader.vue.js +1 -1
  195. package/dist/components/pixel-loader/PixelLoader.vue2.js +6 -6
  196. package/dist/components/popover/Popover.vue.d.ts +4 -0
  197. package/dist/components/popover/Popover.vue.js +1 -1
  198. package/dist/components/popover/Popover.vue2.js +8 -6
  199. package/dist/components/popover/PopoverContent.vue.js +6 -2
  200. package/dist/components/pulse-beam/PulseBeam.vue.d.ts +6 -2
  201. package/dist/components/pulse-beam/PulseBeam.vue.js +1 -1
  202. package/dist/components/pulse-beam/PulseBeam.vue2.js +7 -4
  203. package/dist/components/radio-group/RadioGroup.vue.js +12 -11
  204. package/dist/components/radio-group/RadioGroupItem.vue.d.ts +2 -0
  205. package/dist/components/radio-group/RadioGroupItem.vue.js +1 -1
  206. package/dist/components/radio-group/RadioGroupItem.vue2.js +20 -7
  207. package/dist/components/rainbow-button/RainbowButton.vue.d.ts +11 -2
  208. package/dist/components/rainbow-button/RainbowButton.vue.js +1 -1
  209. package/dist/components/rainbow-button/RainbowButton.vue2.js +35 -18
  210. package/dist/components/ripple-button/RippleButton.vue.d.ts +6 -4
  211. package/dist/components/ripple-button/RippleButton.vue.js +1 -1
  212. package/dist/components/ripple-button/RippleButton.vue2.js +10 -5
  213. package/dist/components/search-input/SearchInput.vue.js +1 -1
  214. package/dist/components/search-input/SearchInput.vue2.js +19 -9
  215. package/dist/components/select/Select.vue.d.ts +1 -1
  216. package/dist/components/select/Select.vue.js +1 -1
  217. package/dist/components/select/Select.vue2.js +25 -17
  218. package/dist/components/sheet/Sheet.vue.d.ts +5 -0
  219. package/dist/components/sheet/Sheet.vue.js +5 -2
  220. package/dist/components/shimmer-button/ShimmerButton.vue.d.ts +2 -2
  221. package/dist/components/shimmer-button/ShimmerButton.vue.js +1 -1
  222. package/dist/components/shimmer-button/ShimmerButton.vue2.js +14 -6
  223. package/dist/components/sidebar/SidebarItem.vue.d.ts +4 -2
  224. package/dist/components/sidebar/SidebarItem.vue.js +1 -1
  225. package/dist/components/sidebar/SidebarItem.vue2.js +4 -2
  226. package/dist/components/slider/Slider.vue.d.ts +4 -0
  227. package/dist/components/slider/Slider.vue.js +1 -1
  228. package/dist/components/slider/Slider.vue2.js +20 -8
  229. package/dist/components/sources/SourcesTrigger.vue.js +1 -1
  230. package/dist/components/sources/SourcesTrigger.vue2.js +11 -11
  231. package/dist/components/sparkles/sparkles-core.d.ts +1 -1
  232. package/dist/components/sparkles/sparkles-core.js +36 -2
  233. package/dist/components/switch/Switch.vue.d.ts +2 -0
  234. package/dist/components/switch/Switch.vue.js +1 -1
  235. package/dist/components/switch/Switch.vue2.js +16 -6
  236. package/dist/components/tabs/TabsTrigger.vue.d.ts +6 -0
  237. package/dist/components/tabs/TabsTrigger.vue.js +1 -1
  238. package/dist/components/tabs/TabsTrigger.vue2.js +28 -15
  239. package/dist/components/terminal-block/TerminalBlock.vue.js +1 -1
  240. package/dist/components/terminal-block/TerminalBlock.vue2.js +10 -9
  241. package/dist/components/text-reveal-card/TextRevealCard.vue.js +1 -2
  242. package/dist/components/textarea/Textarea.vue.js +1 -1
  243. package/dist/components/textarea/Textarea.vue2.js +19 -12
  244. package/dist/components/tick-nav/TickNav.vue.d.ts +71 -0
  245. package/dist/components/tick-nav/TickNav.vue.js +7 -0
  246. package/dist/components/tick-nav/TickNav.vue2.js +285 -0
  247. package/dist/components/tick-nav/index.d.ts +3 -0
  248. package/dist/components/tick-nav/tick-nav-core.d.ts +102 -0
  249. package/dist/components/tick-nav/tick-nav-core.js +398 -0
  250. package/dist/components/tick-nav/tick-nav-hdr.d.ts +60 -0
  251. package/dist/components/tick-nav/tick-nav-hdr.js +284 -0
  252. package/dist/components/tick-nav/types.d.ts +13 -0
  253. package/dist/components/time-picker/TimePicker.vue.js +1 -1
  254. package/dist/components/time-picker/TimePicker.vue2.js +25 -17
  255. package/dist/components/toast/Toast.vue.js +1 -1
  256. package/dist/components/toast/Toast.vue2.js +16 -4
  257. package/dist/components/toast/index.d.ts +1 -1
  258. package/dist/components/toast/store.d.ts +23 -0
  259. package/dist/components/toast/store.js +35 -7
  260. package/dist/components/toggle/Toggle.vue.d.ts +12 -0
  261. package/dist/components/toggle/Toggle.vue.js +1 -1
  262. package/dist/components/toggle/Toggle.vue2.js +27 -11
  263. package/dist/components/toggle-group/ToggleGroup.vue.d.ts +11 -0
  264. package/dist/components/toggle-group/ToggleGroup.vue.js +1 -1
  265. package/dist/components/toggle-group/ToggleGroup.vue2.js +16 -3
  266. package/dist/components/toggle-group/ToggleGroupItem.vue.d.ts +6 -0
  267. package/dist/components/toggle-group/ToggleGroupItem.vue.js +1 -1
  268. package/dist/components/toggle-group/ToggleGroupItem.vue2.js +27 -14
  269. package/dist/components/tooltip/Tooltip.vue.js +13 -0
  270. package/dist/components/typing-indicator/TypingIndicator.vue.js +1 -1
  271. package/dist/components/typing-indicator/TypingIndicator.vue2.js +7 -6
  272. package/dist/index.d.ts +6 -0
  273. package/dist/index.js +440 -413
  274. package/dist/internals/anchor-position.js +3 -0
  275. package/dist/internals/call-listener.d.ts +11 -0
  276. package/dist/internals/call-listener.js +31 -0
  277. package/dist/internals/dismissable.d.ts +17 -0
  278. package/dist/internals/dismissable.js +44 -1
  279. package/dist/internals/env.d.ts +1 -0
  280. package/dist/internals/env.js +11 -0
  281. package/dist/internals/focus-trap.js +29 -4
  282. package/dist/internals/merge-ids.d.ts +6 -0
  283. package/dist/internals/merge-ids.js +11 -0
  284. package/dist/internals/motion/presence-core.d.ts +1 -1
  285. package/dist/sound/engine.js +23 -9
  286. package/dist/sound/themes.d.ts +4 -3
  287. package/dist/sound/themes.js +49 -211
  288. package/dist/sound/types.d.ts +9 -1
  289. package/dist/sound/types.js +2 -2
  290. package/dist/styles.css +974 -571
  291. package/package.json +2 -2
  292. package/tailwind.css +9 -9
@@ -6,7 +6,8 @@ import type { HTMLAttributes } from "vue";
6
6
  * The text is rasterized to a 2048x2048 canvas and uploaded as a texture; a
7
7
  * vertex shader offsets each vertex's `z` by its distance to a `uDisplacement`
8
8
  * uniform, which a raycast against an invisible hit-plane updates on every
9
- * `pointermove`.
9
+ * `pointermove`. With reduced motion preferred, without WebGL, or after a lost
10
+ * GPU context, the real text is shown instead, styled like the resting frame.
10
11
  */
11
12
  export interface DisplacementTextProps {
12
13
  /** Text to display */
@@ -21,6 +22,8 @@ export interface DisplacementTextProps {
21
22
  lightColor?: string;
22
23
  /** Text color in dark mode */
23
24
  darkColor?: string;
25
+ /** Upper bound for the renderer's device pixel ratio */
26
+ maxDpr?: number;
24
27
  /** Additional CSS classes */
25
28
  class?: HTMLAttributes["class"];
26
29
  }
@@ -1,6 +1,6 @@
1
- import { defineComponent, useTemplateRef, watch, onMounted, onBeforeUnmount, createElementBlock, openBlock, normalizeClass, unref } from "vue";
1
+ import { defineComponent, useTemplateRef, ref, computed, watch, onMounted, onBeforeUnmount, createElementBlock, openBlock, normalizeClass, unref, createCommentVNode, normalizeStyle, createElementVNode, toDisplayString } from "vue";
2
2
  import { cn } from "../../utils.js";
3
- import { createDisplacementText } from "./displacement-text-core.js";
3
+ import { DEFAULT_MAX_DPR, staticTextStyle, STATIC_LAYER_STYLE, mountDisplacementText } from "./displacement-text-core.js";
4
4
  const _hoisted_1 = ["aria-label"];
5
5
  const _sfc_main = /* @__PURE__ */ defineComponent({
6
6
  ...{ name: "DisplacementText", inheritAttrs: false },
@@ -12,11 +12,15 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
12
12
  color: {},
13
13
  lightColor: { default: "#000000" },
14
14
  darkColor: { default: "#ffffff" },
15
+ maxDpr: { default: () => DEFAULT_MAX_DPR },
15
16
  class: { type: [Boolean, null, String, Object, Array], default: "" }
16
17
  },
17
18
  setup(__props) {
18
19
  const containerRef = useTemplateRef("container");
19
- let engine = null;
20
+ let controller = null;
21
+ const mode = ref("static");
22
+ const textColor = ref(__props.color ?? __props.lightColor);
23
+ const staticStyle = computed(() => staticTextStyle({ fontSize: __props.fontSize, font: __props.font }, textColor.value));
20
24
  function safely(run) {
21
25
  try {
22
26
  return run();
@@ -25,23 +29,37 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
25
29
  }
26
30
  }
27
31
  watch(
28
- () => ({ text: __props.text, fontSize: __props.fontSize, font: __props.font, color: __props.color, lightColor: __props.lightColor, darkColor: __props.darkColor }),
32
+ () => ({ text: __props.text, fontSize: __props.fontSize, font: __props.font, color: __props.color, lightColor: __props.lightColor, darkColor: __props.darkColor, maxDpr: __props.maxDpr }),
29
33
  (next) => {
30
- if (!engine) return;
31
- safely(() => engine?.setOptions(next));
34
+ safely(() => controller?.setOptions(next));
32
35
  },
33
36
  { flush: "post" }
34
37
  );
35
38
  onMounted(() => {
36
39
  const container = containerRef.value;
37
40
  if (!container) return;
38
- engine = safely(
39
- () => createDisplacementText({ container }, { text: __props.text, fontSize: __props.fontSize, font: __props.font, color: __props.color, lightColor: __props.lightColor, darkColor: __props.darkColor })
41
+ controller = safely(
42
+ () => mountDisplacementText(
43
+ { container },
44
+ {
45
+ text: __props.text,
46
+ fontSize: __props.fontSize,
47
+ font: __props.font,
48
+ color: __props.color,
49
+ lightColor: __props.lightColor,
50
+ darkColor: __props.darkColor,
51
+ maxDpr: __props.maxDpr,
52
+ onChange: (state) => {
53
+ mode.value = state.mode;
54
+ textColor.value = state.color;
55
+ }
56
+ }
57
+ )
40
58
  );
41
59
  });
42
60
  onBeforeUnmount(() => {
43
- engine?.destroy();
44
- engine = null;
61
+ controller?.destroy();
62
+ controller = null;
45
63
  });
46
64
  return (_ctx, _cache) => {
47
65
  return openBlock(), createElementBlock("div", {
@@ -49,7 +67,16 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
49
67
  class: normalizeClass(unref(cn)("relative h-[400px] w-full", __props.class)),
50
68
  role: "img",
51
69
  "aria-label": __props.text
52
- }, null, 10, _hoisted_1);
70
+ }, [
71
+ mode.value === "static" ? (openBlock(), createElementBlock("div", {
72
+ key: 0,
73
+ style: normalizeStyle(unref(STATIC_LAYER_STYLE))
74
+ }, [
75
+ createElementVNode("span", {
76
+ style: normalizeStyle(staticStyle.value)
77
+ }, toDisplayString(__props.text), 5)
78
+ ], 4)) : createCommentVNode("", true)
79
+ ], 10, _hoisted_1);
53
80
  };
54
81
  }
55
82
  });
@@ -3,8 +3,20 @@ export interface DisplacementTextElements {
3
3
  /** Host the renderer canvas is appended to; also the pointer/raycast surface. */
4
4
  container: HTMLElement;
5
5
  }
6
+ /** Read once, when the engine is created — changing them later has no effect. */
6
7
  export interface DisplacementTextInitOptions {
8
+ /**
9
+ * Called once if the GPU drops the WebGL context. By then the engine has
10
+ * already stopped its loop and released every resource; it stays dead.
11
+ */
12
+ onContextLost?: () => void;
7
13
  }
14
+ /**
15
+ * Every key here is live, and none of them rebuilds the scene: the text keys and
16
+ * the colours re-rasterize the texture in place, `color` going from set to unset
17
+ * (or back) only starts/stops the theme observer, and `maxDpr` re-applies the
18
+ * pixel ratio to the existing renderer.
19
+ */
8
20
  export interface DisplacementTextLiveOptions {
9
21
  /** Text to display */
10
22
  text?: string;
@@ -18,20 +30,98 @@ export interface DisplacementTextLiveOptions {
18
30
  lightColor?: string;
19
31
  /** Text color in dark mode */
20
32
  darkColor?: string;
33
+ /** Upper bound for the renderer's device pixel ratio (default 2). */
34
+ maxDpr?: number;
21
35
  }
22
36
  export interface DisplacementTextEngine {
23
- /** Any changed key rebuilds the scene, exactly as the wrapper's `$effect` re-run did. */
37
+ /** Applies only the keys that changed; never rebuilds the scene. */
24
38
  setOptions(next: Partial<DisplacementTextLiveOptions>): void;
25
39
  resize(): void;
26
40
  destroy(): void;
27
41
  }
42
+ /** Default ceiling for the renderer's pixel ratio. */
43
+ export declare const DEFAULT_MAX_DPR = 2;
44
+ export declare const REDUCED_MOTION_QUERY = "(prefers-reduced-motion: reduce)";
45
+ /**
46
+ * How the resting frame looks on screen, as a CSS transform. The camera sits at
47
+ * (0, -10, 5) looking at the origin, so the plane is seen tilted: screen x is
48
+ * world x and screen y is world y times 5/√125 (= 1/√5). The plane itself is
49
+ * turned 45° about z, which reads as a counter-clockwise turn on screen.
50
+ */
51
+ export declare const STATIC_TEXT_TRANSFORM: string;
52
+ /** Inline style for the layer that holds the static text (a size container filling the host). */
53
+ export declare const STATIC_LAYER_STYLE: {
54
+ readonly position: "absolute";
55
+ readonly inset: "0";
56
+ readonly display: "flex";
57
+ readonly alignItems: "center";
58
+ readonly justifyContent: "center";
59
+ readonly containerType: "size";
60
+ readonly overflow: "hidden";
61
+ };
62
+ /** Inline style for the static text: the real string, laid out like the resting frame. */
63
+ export declare function staticTextStyle(options: {
64
+ fontSize?: number;
65
+ font?: string;
66
+ }, color: string): {
67
+ fontFamily: string;
68
+ fontSize: string;
69
+ fontWeight: string;
70
+ color: string;
71
+ lineHeight: string;
72
+ whiteSpace: string;
73
+ transform: string;
74
+ };
75
+ /** `min(deviceRatio, maxDpr)`; a missing device ratio counts as 1, an unusable cap as the default. */
76
+ export declare function resolvePixelRatio(deviceRatio: number | undefined, maxDpr: number | undefined): number;
77
+ /** The colour on screen: the fixed one, else the theme's. Light when there is no document. */
78
+ export declare function resolveTextColor(options: {
79
+ color?: string;
80
+ lightColor?: string;
81
+ darkColor?: string;
82
+ }): string;
83
+ /**
84
+ * Whether a WebGL2 context (what the renderer needs) can be created here. The
85
+ * probe context is released straight away so it does not count against the
86
+ * browser's limit of live contexts.
87
+ */
88
+ export declare function canCreateWebGLContext(): boolean;
28
89
  /** Rasterize `t` centred on a square canvas and upload it as a texture. */
29
90
  export declare function createTextTexture(t: string, size: number, f: string, c: string): THREE.Texture;
30
91
  /**
31
92
  * Build the three.js scene inside `container` and drive it.
32
93
  *
33
- * Returns `null` when the host reports a zero height — the guard the wrapper's
34
- * effect already had. WebGL availability is not probed: `THREE.WebGLRenderer`
35
- * throws on a context-less browser here exactly as it did inside the effect.
94
+ * A host that reports no size is drawn as a 1x1 box until the next resize.
95
+ * Returns `null` when the renderer cannot get a WebGL context (three throws) or
96
+ * when building the scene throws; in both cases nothing is left appended to the
97
+ * host and nothing stays allocated, the WebGL context included.
36
98
  */
37
99
  export declare function createDisplacementText(elements: DisplacementTextElements, options: DisplacementTextInitOptions & DisplacementTextLiveOptions): DisplacementTextEngine | null;
100
+ export type DisplacementTextMode = "static" | "webgl";
101
+ export interface DisplacementTextState {
102
+ /** `static`: the wrapper shows the real text; `webgl`: the canvas is live. */
103
+ mode: DisplacementTextMode;
104
+ /** The colour the text resolves to right now (theme-aware unless `color` is fixed). */
105
+ color: string;
106
+ }
107
+ export interface DisplacementTextControllerOptions extends DisplacementTextLiveOptions {
108
+ /** Read once at mount: called with every state change (and once with the initial state). */
109
+ onChange: (state: DisplacementTextState) => void;
110
+ }
111
+ export interface DisplacementTextController {
112
+ setOptions(next: Partial<DisplacementTextLiveOptions>): void;
113
+ resize(): void;
114
+ destroy(): void;
115
+ }
116
+ /**
117
+ * Owns the engine's lifecycle for a mounted wrapper:
118
+ *
119
+ * - while `prefers-reduced-motion: reduce` matches, no engine exists — no loop,
120
+ * no GL context — and the state is `static`; a live change of the preference
121
+ * destroys or creates the engine without remounting the wrapper;
122
+ * - the engine is only created once a WebGL2 context is known to be obtainable,
123
+ * and a context loss drops to `static` for the rest of the mount;
124
+ * - the resolved text colour is reported (and follows the theme) so the static
125
+ * text matches what the canvas would draw.
126
+ */
127
+ export declare function mountDisplacementText(elements: DisplacementTextElements, options: DisplacementTextControllerOptions): DisplacementTextController;
@@ -5,13 +5,62 @@ const DEFAULTS = {
5
5
  font: "Inter, sans-serif",
6
6
  color: void 0,
7
7
  lightColor: "#000000",
8
- darkColor: "#ffffff"
8
+ darkColor: "#ffffff",
9
+ maxDpr: void 0
9
10
  };
11
+ const DEFAULT_MAX_DPR = 2;
12
+ const REDUCED_MOTION_QUERY = "(prefers-reduced-motion: reduce)";
10
13
  const TEXTURE_SIZE = 2048;
11
14
  const CAMERA_DISTANCE = 8;
12
15
  const PLANE_SIZE = 15;
13
16
  const PLANE_SEGMENTS = 100;
14
17
  const HIT_PLANE_SIZE = 500;
18
+ const STATIC_TEXT_TRANSFORM = `scaleY(${1 / Math.sqrt(5)}) rotate(-45deg)`;
19
+ function staticFontSize(fontSize) {
20
+ return `calc(${fontSize * PLANE_SIZE / TEXTURE_SIZE / (2 * CAMERA_DISTANCE)} * 100cqh)`;
21
+ }
22
+ const STATIC_LAYER_STYLE = {
23
+ position: "absolute",
24
+ inset: "0",
25
+ display: "flex",
26
+ alignItems: "center",
27
+ justifyContent: "center",
28
+ containerType: "size",
29
+ overflow: "hidden"
30
+ };
31
+ function staticTextStyle(options, color) {
32
+ return {
33
+ fontFamily: options.font ?? DEFAULTS.font,
34
+ fontSize: staticFontSize(options.fontSize ?? DEFAULTS.fontSize),
35
+ fontWeight: "bold",
36
+ color,
37
+ lineHeight: "1",
38
+ whiteSpace: "nowrap",
39
+ transform: STATIC_TEXT_TRANSFORM
40
+ };
41
+ }
42
+ function resolvePixelRatio(deviceRatio, maxDpr) {
43
+ const cap = maxDpr !== void 0 && Number.isFinite(maxDpr) && maxDpr > 0 ? maxDpr : DEFAULT_MAX_DPR;
44
+ const device = deviceRatio && Number.isFinite(deviceRatio) && deviceRatio > 0 ? deviceRatio : 1;
45
+ return Math.min(device, cap);
46
+ }
47
+ function resolveTextColor(options) {
48
+ if (options.color) return options.color;
49
+ const dark = typeof document !== "undefined" && document.documentElement.classList.contains("dark");
50
+ return dark ? options.darkColor ?? DEFAULTS.darkColor : options.lightColor ?? DEFAULTS.lightColor;
51
+ }
52
+ function canCreateWebGLContext() {
53
+ if (typeof document === "undefined") return false;
54
+ try {
55
+ const probe = document.createElement("canvas");
56
+ const gl = probe.getContext("webgl2");
57
+ if (!gl) return false;
58
+ gl.getExtension("WEBGL_lose_context")?.loseContext();
59
+ return true;
60
+ } catch {
61
+ return false;
62
+ }
63
+ }
15
64
  const vertexShader = `
16
65
  varying vec2 vUv;
17
66
  uniform vec3 uDisplacement;
@@ -63,23 +112,46 @@ function createTextTexture(t, size, f, c) {
63
112
  texture.needsUpdate = true;
64
113
  return texture;
65
114
  }
66
- const LIVE_KEYS = ["text", "fontSize", "font", "color", "lightColor", "darkColor"];
115
+ const LIVE_KEYS = [
116
+ "text",
117
+ "fontSize",
118
+ "font",
119
+ "color",
120
+ "lightColor",
121
+ "darkColor",
122
+ "maxDpr"
123
+ ];
67
124
  function createDisplacementText(elements, options) {
68
125
  const { container } = elements;
69
- let opts = { ...DEFAULTS, ...options };
70
- let destroyed = false;
71
- let teardown = null;
72
- let doResize = null;
73
- function build() {
74
- const rect = container.getBoundingClientRect();
75
- const width = rect.width || 1;
76
- const height = rect.height || 1;
77
- if (height === 0) return false;
78
- const { text, fontSize, font, color, lightColor, darkColor } = opts;
79
- const scene = new THREE.Scene();
126
+ const { onContextLost } = options;
127
+ let opts = { ...DEFAULTS };
128
+ for (const key of LIVE_KEYS) {
129
+ if (options[key] !== void 0) opts[key] = options[key];
130
+ }
131
+ const rect = container.getBoundingClientRect();
132
+ const width = rect.width || 1;
133
+ const height = rect.height || 1;
134
+ let renderer;
135
+ try {
136
+ renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
137
+ } catch {
138
+ return null;
139
+ }
140
+ const built = [renderer];
141
+ let scene;
142
+ let camera;
143
+ let geometry;
144
+ let currentColor;
145
+ let textTexture;
146
+ let shaderMaterial;
147
+ let hitGeometry;
148
+ let hitMaterial;
149
+ let hitPlane;
150
+ try {
151
+ scene = new THREE.Scene();
80
152
  scene.background = null;
81
153
  const aspect = width / height;
82
- const camera = new THREE.OrthographicCamera(
154
+ camera = new THREE.OrthographicCamera(
83
155
  -CAMERA_DISTANCE * aspect,
84
156
  CAMERA_DISTANCE * aspect,
85
157
  CAMERA_DISTANCE,
@@ -89,23 +161,17 @@ function createDisplacementText(elements, options) {
89
161
  );
90
162
  camera.position.set(0, -10, 5);
91
163
  camera.lookAt(0, 0, 0);
92
- const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
93
164
  renderer.setClearColor(0, 0);
94
- renderer.setPixelRatio(window.devicePixelRatio);
165
+ renderer.setPixelRatio(resolvePixelRatio(window.devicePixelRatio, opts.maxDpr));
95
166
  renderer.setSize(width, height, false);
96
167
  renderer.domElement.style.width = "100%";
97
168
  renderer.domElement.style.height = "100%";
98
- container.appendChild(renderer.domElement);
99
- const geometry = new THREE.PlaneGeometry(
100
- PLANE_SIZE,
101
- PLANE_SIZE,
102
- PLANE_SEGMENTS,
103
- PLANE_SEGMENTS
104
- );
105
- const getActiveColor = () => color || (document.documentElement.classList.contains("dark") ? darkColor : lightColor);
106
- let currentColor = getActiveColor();
107
- let textTexture = createTextTexture(text, fontSize, font, currentColor);
108
- const shaderMaterial = new THREE.ShaderMaterial({
169
+ geometry = new THREE.PlaneGeometry(PLANE_SIZE, PLANE_SIZE, PLANE_SEGMENTS, PLANE_SEGMENTS);
170
+ built.push(geometry);
171
+ currentColor = resolveTextColor(opts);
172
+ textTexture = createTextTexture(opts.text, opts.fontSize, opts.font, currentColor);
173
+ built.push(textTexture);
174
+ shaderMaterial = new THREE.ShaderMaterial({
109
175
  uniforms: {
110
176
  uTexture: { value: textTexture },
111
177
  uDisplacement: { value: new THREE.Vector3(0, 0, 0) }
@@ -116,99 +182,223 @@ function createDisplacementText(elements, options) {
116
182
  depthWrite: false,
117
183
  side: THREE.DoubleSide
118
184
  });
185
+ built.push(shaderMaterial);
119
186
  const plane = new THREE.Mesh(geometry, shaderMaterial);
120
187
  plane.rotation.z = Math.PI / 4;
121
188
  scene.add(plane);
122
- const hitGeometry = new THREE.PlaneGeometry(HIT_PLANE_SIZE, HIT_PLANE_SIZE);
123
- const hitMaterial = new THREE.MeshBasicMaterial({ transparent: true, opacity: 0 });
124
- const hitPlane = new THREE.Mesh(hitGeometry, hitMaterial);
189
+ hitGeometry = new THREE.PlaneGeometry(HIT_PLANE_SIZE, HIT_PLANE_SIZE);
190
+ built.push(hitGeometry);
191
+ hitMaterial = new THREE.MeshBasicMaterial({ transparent: true, opacity: 0 });
192
+ built.push(hitMaterial);
193
+ hitPlane = new THREE.Mesh(hitGeometry, hitMaterial);
125
194
  scene.add(hitPlane);
126
- const raycaster = new THREE.Raycaster();
127
- const pointer = new THREE.Vector2();
128
- const onPointerMove = (e) => {
129
- const bounds = container.getBoundingClientRect();
130
- pointer.x = (e.clientX - bounds.left) / bounds.width * 2 - 1;
131
- pointer.y = -((e.clientY - bounds.top) / bounds.height) * 2 + 1;
132
- raycaster.setFromCamera(pointer, camera);
133
- const [hit] = raycaster.intersectObject(hitPlane);
134
- if (hit) shaderMaterial.uniforms.uDisplacement.value.copy(hit.point);
135
- };
136
- container.addEventListener("pointermove", onPointerMove);
137
- const handleResize = () => {
138
- const r = container.getBoundingClientRect();
139
- if (r.height === 0) return;
140
- const a = r.width / r.height;
141
- camera.left = -CAMERA_DISTANCE * a;
142
- camera.right = CAMERA_DISTANCE * a;
143
- camera.updateProjectionMatrix();
144
- renderer.setSize(r.width, r.height, false);
145
- };
146
- window.addEventListener("resize", handleResize);
147
- let animationId = 0;
148
- const animate = () => {
149
- animationId = requestAnimationFrame(animate);
150
- renderer.render(scene, camera);
151
- };
152
- animate();
153
- const observer = new MutationObserver(() => {
154
- const next = getActiveColor();
155
- if (next !== currentColor) {
156
- const tex = createTextTexture(text, fontSize, font, next);
157
- shaderMaterial.uniforms.uTexture.value = tex;
158
- textTexture.dispose();
159
- textTexture = tex;
160
- currentColor = next;
161
- }
162
- });
163
- if (!color)
195
+ } catch {
196
+ renderer.forceContextLoss();
197
+ for (const item of built) item.dispose();
198
+ return null;
199
+ }
200
+ container.appendChild(renderer.domElement);
201
+ const raycaster = new THREE.Raycaster();
202
+ const pointer = new THREE.Vector2();
203
+ function retexture(nextColor) {
204
+ const tex = createTextTexture(opts.text, opts.fontSize, opts.font, nextColor);
205
+ shaderMaterial.uniforms.uTexture.value = tex;
206
+ textTexture.dispose();
207
+ textTexture = tex;
208
+ currentColor = nextColor;
209
+ }
210
+ const onPointerMove = (e) => {
211
+ const bounds = container.getBoundingClientRect();
212
+ pointer.x = (e.clientX - bounds.left) / bounds.width * 2 - 1;
213
+ pointer.y = -((e.clientY - bounds.top) / bounds.height) * 2 + 1;
214
+ raycaster.setFromCamera(pointer, camera);
215
+ const [hit] = raycaster.intersectObject(hitPlane);
216
+ if (hit) shaderMaterial.uniforms.uDisplacement.value.copy(hit.point);
217
+ };
218
+ container.addEventListener("pointermove", onPointerMove);
219
+ const handleResize = () => {
220
+ const r = container.getBoundingClientRect();
221
+ if (r.height === 0) return;
222
+ const a = r.width / r.height;
223
+ camera.left = -CAMERA_DISTANCE * a;
224
+ camera.right = CAMERA_DISTANCE * a;
225
+ camera.updateProjectionMatrix();
226
+ renderer.setSize(r.width, r.height, false);
227
+ };
228
+ window.addEventListener("resize", handleResize);
229
+ let animationId = 0;
230
+ const animate = () => {
231
+ animationId = requestAnimationFrame(animate);
232
+ renderer.render(scene, camera);
233
+ };
234
+ animate();
235
+ const observer = new MutationObserver(() => {
236
+ const next = resolveTextColor(opts);
237
+ if (next !== currentColor) retexture(next);
238
+ });
239
+ let observing = false;
240
+ function syncObserver() {
241
+ const want = !opts.color;
242
+ if (want === observing) return;
243
+ observing = want;
244
+ if (want)
164
245
  observer.observe(document.documentElement, {
165
246
  attributes: true,
166
247
  attributeFilter: ["class"]
167
248
  });
168
- doResize = handleResize;
169
- teardown = () => {
170
- window.removeEventListener("resize", handleResize);
171
- container.removeEventListener("pointermove", onPointerMove);
172
- cancelAnimationFrame(animationId);
173
- observer.disconnect();
174
- if (renderer.domElement.parentNode === container) container.removeChild(renderer.domElement);
175
- renderer.dispose();
176
- textTexture.dispose();
177
- geometry.dispose();
178
- shaderMaterial.dispose();
179
- hitGeometry.dispose();
180
- hitMaterial.dispose();
181
- };
182
- return true;
249
+ else observer.disconnect();
183
250
  }
184
- if (!build()) return null;
185
- function teardownCurrent() {
186
- const fn = teardown;
187
- teardown = null;
188
- doResize = null;
189
- fn?.();
251
+ syncObserver();
252
+ const onContextLostEvent = (event) => {
253
+ event.preventDefault();
254
+ release(true);
255
+ onContextLost?.();
256
+ };
257
+ renderer.domElement.addEventListener("webglcontextlost", onContextLostEvent, false);
258
+ let released = false;
259
+ function release(contextAlreadyLost = false) {
260
+ if (released) return;
261
+ released = true;
262
+ renderer.domElement.removeEventListener("webglcontextlost", onContextLostEvent);
263
+ window.removeEventListener("resize", handleResize);
264
+ container.removeEventListener("pointermove", onPointerMove);
265
+ cancelAnimationFrame(animationId);
266
+ if (observing) observer.disconnect();
267
+ observing = false;
268
+ if (renderer.domElement.parentNode === container) container.removeChild(renderer.domElement);
269
+ if (!contextAlreadyLost) renderer.forceContextLoss();
270
+ renderer.dispose();
271
+ textTexture.dispose();
272
+ geometry.dispose();
273
+ shaderMaterial.dispose();
274
+ hitGeometry.dispose();
275
+ hitMaterial.dispose();
190
276
  }
191
277
  return {
192
278
  setOptions(next) {
193
- if (destroyed) return;
194
- const merged = { ...opts, ...next };
195
- if (LIVE_KEYS.every((k) => merged[k] === opts[k])) return;
279
+ if (released) return;
280
+ const prev = opts;
281
+ const merged = { ...opts };
282
+ for (const key of LIVE_KEYS) {
283
+ if (key in next) merged[key] = next[key];
284
+ }
285
+ for (const key of LIVE_KEYS) {
286
+ if (merged[key] === void 0 && key !== "color" && key !== "maxDpr")
287
+ merged[key] = DEFAULTS[key];
288
+ }
289
+ if (LIVE_KEYS.every((k) => merged[k] === prev[k])) return;
196
290
  opts = merged;
197
- teardownCurrent();
198
- build();
291
+ if (merged.maxDpr !== prev.maxDpr) {
292
+ renderer.setPixelRatio(resolvePixelRatio(window.devicePixelRatio, merged.maxDpr));
293
+ handleResize();
294
+ }
295
+ syncObserver();
296
+ const nextColor = resolveTextColor(merged);
297
+ if (nextColor !== currentColor || merged.text !== prev.text || merged.fontSize !== prev.fontSize || merged.font !== prev.font)
298
+ retexture(nextColor);
299
+ },
300
+ resize() {
301
+ if (released) return;
302
+ handleResize();
303
+ },
304
+ destroy() {
305
+ release();
306
+ }
307
+ };
308
+ }
309
+ function mountDisplacementText(elements, options) {
310
+ const { onChange } = options;
311
+ let opts = {};
312
+ for (const key of LIVE_KEYS) opts[key] = options[key];
313
+ let engine = null;
314
+ let contextLost = false;
315
+ let destroyed = false;
316
+ let state = { mode: "static", color: resolveTextColor(opts) };
317
+ function publish(next) {
318
+ if (next.mode === state.mode && next.color === state.color) return;
319
+ state = next;
320
+ onChange(state);
321
+ }
322
+ const mql = typeof window !== "undefined" && typeof window.matchMedia === "function" ? window.matchMedia(REDUCED_MOTION_QUERY) : null;
323
+ function start() {
324
+ if (engine || contextLost || destroyed || mql?.matches) return;
325
+ if (!canCreateWebGLContext()) return;
326
+ try {
327
+ engine = createDisplacementText(elements, {
328
+ ...opts,
329
+ onContextLost() {
330
+ engine = null;
331
+ contextLost = true;
332
+ publish({ ...state, mode: "static" });
333
+ }
334
+ });
335
+ } catch {
336
+ engine = null;
337
+ }
338
+ if (engine) publish({ ...state, mode: "webgl" });
339
+ }
340
+ function stop() {
341
+ const current = engine;
342
+ engine = null;
343
+ current?.destroy();
344
+ publish({ ...state, mode: "static" });
345
+ }
346
+ const onMotionChange = (event) => {
347
+ if (destroyed) return;
348
+ if (event.matches) stop();
349
+ else start();
350
+ };
351
+ mql?.addEventListener("change", onMotionChange);
352
+ const themeObserver = typeof MutationObserver !== "undefined" ? new MutationObserver(() => publish({ ...state, color: resolveTextColor(opts) })) : null;
353
+ let watchingTheme = false;
354
+ function syncThemeObserver() {
355
+ const want = !opts.color && themeObserver !== null;
356
+ if (want === watchingTheme) return;
357
+ watchingTheme = want;
358
+ if (want)
359
+ themeObserver?.observe(document.documentElement, {
360
+ attributes: true,
361
+ attributeFilter: ["class"]
362
+ });
363
+ else themeObserver?.disconnect();
364
+ }
365
+ onChange(state);
366
+ syncThemeObserver();
367
+ start();
368
+ return {
369
+ setOptions(next) {
370
+ if (destroyed) return;
371
+ opts = { ...opts, ...next };
372
+ syncThemeObserver();
373
+ publish({ ...state, color: resolveTextColor(opts) });
374
+ engine?.setOptions(next);
199
375
  },
200
376
  resize() {
201
377
  if (destroyed) return;
202
- doResize?.();
378
+ engine?.resize();
203
379
  },
204
380
  destroy() {
205
381
  if (destroyed) return;
206
382
  destroyed = true;
207
- teardownCurrent();
383
+ mql?.removeEventListener("change", onMotionChange);
384
+ if (watchingTheme) themeObserver?.disconnect();
385
+ watchingTheme = false;
386
+ const current = engine;
387
+ engine = null;
388
+ current?.destroy();
208
389
  }
209
390
  };
210
391
  }
211
392
  export {
393
+ DEFAULT_MAX_DPR,
394
+ REDUCED_MOTION_QUERY,
395
+ STATIC_LAYER_STYLE,
396
+ STATIC_TEXT_TRANSFORM,
397
+ canCreateWebGLContext,
212
398
  createDisplacementText,
213
- createTextTexture
399
+ createTextTexture,
400
+ mountDisplacementText,
401
+ resolvePixelRatio,
402
+ resolveTextColor,
403
+ staticTextStyle
214
404
  };