@zyncat/ui 0.11.0 → 0.13.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/README.md +135 -40
- package/dist/alert.css +126 -121
- package/dist/alert.js +12 -14
- package/dist/alert.js.map +1 -1
- package/dist/avatar-group.js.map +1 -1
- package/dist/avatar.css +179 -174
- package/dist/avatar.js.map +1 -1
- package/dist/badge.css +166 -160
- package/dist/badge.js +1 -1
- package/dist/button.css +272 -246
- package/dist/button.js +1 -1
- package/dist/checkbox.css +158 -153
- package/dist/checkbox.js +2 -2
- package/dist/{chunk-AMFGY56I.js → chunk-227ZW4V7.js} +40 -32
- package/dist/chunk-227ZW4V7.js.map +1 -0
- package/dist/{chunk-2ERBBFZS.js → chunk-3MPF7FZV.js} +2 -2
- package/dist/chunk-3MPF7FZV.js.map +1 -0
- package/dist/{chunk-AIQXS2XY.js → chunk-43M6GQ4Q.js} +86 -79
- package/dist/chunk-43M6GQ4Q.js.map +1 -0
- package/dist/{chunk-7SZCJ7WI.js → chunk-45R4Z5XN.js} +3 -3
- package/dist/chunk-45R4Z5XN.js.map +1 -0
- package/dist/{chunk-I4XQ4PV2.js → chunk-4BSHB7R3.js} +9 -7
- package/dist/chunk-4BSHB7R3.js.map +1 -0
- package/dist/{chunk-YGGCQNNU.js → chunk-4C5RZXBT.js} +33 -34
- package/dist/chunk-4C5RZXBT.js.map +1 -0
- package/dist/{chunk-2QWJ6FAX.js → chunk-5PZ43DCG.js} +31 -15
- package/dist/chunk-5PZ43DCG.js.map +1 -0
- package/dist/{chunk-S5ZTZANS.js → chunk-7IZJERGA.js} +35 -12
- package/dist/chunk-7IZJERGA.js.map +1 -0
- package/dist/{chunk-DKVUPFQR.js → chunk-A5WTZACK.js} +22 -12
- package/dist/chunk-A5WTZACK.js.map +1 -0
- package/dist/{chunk-64UU4LGU.js → chunk-AADAJL7D.js} +3 -3
- package/dist/{chunk-64UU4LGU.js.map → chunk-AADAJL7D.js.map} +1 -1
- package/dist/{chunk-XJQQQJAO.js → chunk-CF4QHO4N.js} +21 -11
- package/dist/chunk-CF4QHO4N.js.map +1 -0
- package/dist/{chunk-WM5J5TDI.js → chunk-CNWTIMIP.js} +13 -17
- package/dist/chunk-CNWTIMIP.js.map +1 -0
- package/dist/{chunk-NGTA34V2.js → chunk-DDRSMHN4.js} +16 -10
- package/dist/chunk-DDRSMHN4.js.map +1 -0
- package/dist/{chunk-VTJTGVZZ.js → chunk-DMX2F6B4.js} +2 -2
- package/dist/chunk-DMX2F6B4.js.map +1 -0
- package/dist/{chunk-3SBCBYB7.js → chunk-EAI4POPB.js} +2 -2
- package/dist/{chunk-3SBCBYB7.js.map → chunk-EAI4POPB.js.map} +1 -1
- package/dist/{chunk-Y7AJQVWJ.js → chunk-EF6RPXU7.js} +17 -15
- package/dist/chunk-EF6RPXU7.js.map +1 -0
- package/dist/{chunk-WFHRAKN3.js → chunk-FONOS5RN.js} +14 -15
- package/dist/chunk-FONOS5RN.js.map +1 -0
- package/dist/{chunk-PMECHR3A.js → chunk-FQEHSKEI.js} +2 -2
- package/dist/chunk-FQEHSKEI.js.map +1 -0
- package/dist/chunk-HDSFWZ7L.js +12 -0
- package/dist/chunk-HDSFWZ7L.js.map +1 -0
- package/dist/{chunk-2F5PITAO.js → chunk-HY5MPISE.js} +2 -2
- package/dist/chunk-HY5MPISE.js.map +1 -0
- package/dist/{chunk-QDK66S4G.js → chunk-I45AU6KH.js} +3 -3
- package/dist/chunk-I45AU6KH.js.map +1 -0
- package/dist/{chunk-YGCVWGUG.js → chunk-IJS7TPGV.js} +153 -46
- package/dist/chunk-IJS7TPGV.js.map +1 -0
- package/dist/{chunk-62P3KD57.js → chunk-IUQAUBVM.js} +18 -11
- package/dist/chunk-IUQAUBVM.js.map +1 -0
- package/dist/chunk-JY6A2ZJZ.js +44 -0
- package/dist/chunk-JY6A2ZJZ.js.map +1 -0
- package/dist/{chunk-XWUWYSCT.js → chunk-M43IOM5C.js} +20 -10
- package/dist/chunk-M43IOM5C.js.map +1 -0
- package/dist/{chunk-S7B34VGN.js → chunk-OWNMRMPN.js} +3 -3
- package/dist/{chunk-S7B34VGN.js.map → chunk-OWNMRMPN.js.map} +1 -1
- package/dist/chunk-RFRE4WKX.js +22 -0
- package/dist/chunk-RFRE4WKX.js.map +1 -0
- package/dist/{chunk-NNXJCLTV.js → chunk-RJFGWJ4W.js} +2 -2
- package/dist/chunk-RJFGWJ4W.js.map +1 -0
- package/dist/{chunk-NEF5XAHG.js → chunk-TUTXXC3W.js} +4 -4
- package/dist/chunk-TUTXXC3W.js.map +1 -0
- package/dist/chunk-TVYH4AN7.js +70 -0
- package/dist/chunk-TVYH4AN7.js.map +1 -0
- package/dist/{chunk-U4MHX3KH.js → chunk-VAXCXZ53.js} +33 -12
- package/dist/chunk-VAXCXZ53.js.map +1 -0
- package/dist/chunk-XNIYSAMJ.js +52 -0
- package/dist/chunk-XNIYSAMJ.js.map +1 -0
- package/dist/{chunk-CONSWNIV.js → chunk-Y2YA7QRF.js} +6 -6
- package/dist/chunk-Y2YA7QRF.js.map +1 -0
- package/dist/cli.js +1828 -0
- package/dist/collapse.css +70 -61
- package/dist/collapse.js +2 -2
- package/dist/confetti.css +45 -0
- package/dist/confetti.js +540 -0
- package/dist/confetti.js.map +1 -0
- package/dist/count-badge.js +3 -3
- package/dist/count-badge.js.map +1 -1
- package/dist/date-field.js +24 -19
- package/dist/date-field.js.map +1 -1
- package/dist/date-picker.css +563 -559
- package/dist/date-range-field.js +58 -41
- package/dist/date-range-field.js.map +1 -1
- package/dist/datetime-field.js +24 -19
- package/dist/datetime-field.js.map +1 -1
- package/dist/dialog.css +176 -172
- package/dist/dialog.js +30 -19
- package/dist/dialog.js.map +1 -1
- package/dist/digit-strip.css +65 -0
- package/dist/dropdown.css +65 -0
- package/dist/dropdown.js +350 -0
- package/dist/dropdown.js.map +1 -0
- package/dist/emoji-picker.js +713 -0
- package/dist/emoji-picker.js.map +1 -0
- package/dist/facebook-feed.css +880 -0
- package/dist/facebook-feed.js +697 -0
- package/dist/facebook-feed.js.map +1 -0
- package/dist/flow-field.css +49 -0
- package/dist/flow-field.js +269 -0
- package/dist/flow-field.js.map +1 -0
- package/dist/glide.js +3 -3
- package/dist/icon.css +34 -30
- package/dist/input.css +296 -318
- package/dist/instagram-feed.css +378 -0
- package/dist/instagram-feed.js +272 -0
- package/dist/instagram-feed.js.map +1 -0
- package/dist/lens.css +119 -0
- package/dist/lens.js +307 -0
- package/dist/lens.js.map +1 -0
- package/dist/mcp.js +379 -181
- package/dist/menu-surface.css +127 -0
- package/dist/modal.css +11 -7
- package/dist/modal.js +24 -17
- package/dist/modal.js.map +1 -1
- package/dist/morphing-text.css +84 -0
- package/dist/morphing-text.js +256 -0
- package/dist/morphing-text.js.map +1 -0
- package/dist/motion-devtools.css +237 -233
- package/dist/motion-devtools.js +7 -6
- package/dist/motion-devtools.js.map +1 -1
- package/dist/motion-tokens.js +1 -1
- package/dist/multi-select.js +20 -17
- package/dist/multi-select.js.map +1 -1
- package/dist/number-field.js +11 -7
- package/dist/number-field.js.map +1 -1
- package/dist/odometer.css +58 -59
- package/dist/odometer.js +109 -0
- package/dist/odometer.js.map +1 -0
- package/dist/otp-field.js.map +1 -1
- package/dist/overlay.css +24 -20
- package/dist/pagination.css +42 -38
- package/dist/pagination.js +6 -12
- package/dist/pagination.js.map +1 -1
- package/dist/popover.css +69 -65
- package/dist/popover.js +12 -10
- package/dist/radio-group.css +275 -276
- package/dist/radio-group.js +70 -95
- package/dist/radio-group.js.map +1 -1
- package/dist/select.css +291 -386
- package/dist/select.js +18 -15
- package/dist/select.js.map +1 -1
- package/dist/sheet.css +47 -23
- package/dist/sheet.js +11 -10
- package/dist/status-badge.js +3 -3
- package/dist/status-badge.js.map +1 -1
- package/dist/styles.css +221 -0
- package/dist/support-rail.css +421 -0
- package/dist/support-rail.js +243 -0
- package/dist/support-rail.js.map +1 -0
- package/dist/table.css +333 -323
- package/dist/table.js +32 -21
- package/dist/table.js.map +1 -1
- package/dist/tabs.css +163 -156
- package/dist/tabs.js +26 -20
- package/dist/tabs.js.map +1 -1
- package/dist/tag.css +209 -231
- package/dist/tag.js +11 -10
- package/dist/tag.js.map +1 -1
- package/dist/text-field.js +7 -67
- package/dist/text-field.js.map +1 -1
- package/dist/textarea.css +205 -211
- package/dist/textarea.js +12 -12
- package/dist/textarea.js.map +1 -1
- package/dist/theme.js +69 -0
- package/dist/theme.js.map +1 -0
- package/dist/tiktok.css +662 -0
- package/dist/tiktok.js +494 -0
- package/dist/tiktok.js.map +1 -0
- package/dist/time-field.js +6 -6
- package/dist/time-field.js.map +1 -1
- package/dist/toast.css +237 -233
- package/dist/toast.js +43 -47
- package/dist/toast.js.map +1 -1
- package/dist/toggle-tag.js +1 -1
- package/dist/toggle-tag.js.map +1 -1
- package/dist/toggle.css +139 -135
- package/dist/toggle.js.map +1 -1
- package/dist/tooltip.css +79 -78
- package/dist/tooltip.js +50 -60
- package/dist/tooltip.js.map +1 -1
- package/dist/trigger.css +13 -0
- package/dist/{alert.d.ts → types/components/composites/alert/Alert.d.ts} +13 -15
- package/dist/{date-field.d.ts → types/components/composites/date-picker/DateField.d.ts} +4 -10
- package/dist/types/components/composites/date-picker/DateRangeField.d.ts +21 -0
- package/dist/{datetime-field.d.ts → types/components/composites/date-picker/DateTimeField.d.ts} +4 -10
- package/dist/{time-field.d.ts → types/components/composites/date-picker/TimeField.d.ts} +5 -11
- package/dist/types/components/composites/date-picker/calendar-panel.d.ts +16 -0
- package/dist/types/components/composites/date-picker/date-utils.d.ts +12 -0
- package/dist/types/components/composites/date-picker/field-shell.d.ts +46 -0
- package/dist/types/components/composites/date-picker/range-panel.d.ts +24 -0
- package/dist/types/components/composites/date-picker/time-core.d.ts +14 -0
- package/dist/types/components/composites/date-picker/use-day-focus.d.ts +2 -0
- package/dist/{dialog.d.ts → types/components/composites/dialog/Dialog.d.ts} +10 -11
- package/dist/types/components/composites/dropdown/Dropdown.d.ts +37 -0
- package/dist/types/components/composites/dropdown/menu-panel.d.ts +7 -0
- package/dist/types/components/composites/dropdown/types.d.ts +71 -0
- package/dist/types/components/composites/emoji-picker/EmojiPickerPanel.d.ts +45 -0
- package/dist/types/components/composites/emoji-picker/category-icons.d.ts +9 -0
- package/dist/types/components/composites/emoji-picker/data.d.ts +33 -0
- package/dist/types/components/composites/emoji-picker/dom.d.ts +19 -0
- package/dist/types/components/composites/emoji-picker/getEmojiUrl.d.ts +2 -0
- package/dist/types/components/composites/emoji-picker/navigation.d.ts +7 -0
- package/dist/types/components/composites/emoji-picker/picker.d.ts +20 -0
- package/dist/types/components/composites/emoji-picker/react/category-bar.d.ts +6 -0
- package/dist/types/components/composites/emoji-picker/react/useEmojiPicker.d.ts +50 -0
- package/dist/types/components/composites/emoji-picker/scaffold.d.ts +8 -0
- package/dist/types/components/composites/emoji-picker/search.d.ts +1 -0
- package/dist/types/components/composites/emoji-picker/types.d.ts +13 -0
- package/dist/{modal.d.ts → types/components/composites/modal/Modal.d.ts} +10 -11
- package/dist/{pagination.d.ts → types/components/composites/pagination/Pagination.d.ts} +5 -8
- package/dist/{popover.d.ts → types/components/composites/popover/Popover.d.ts} +11 -14
- package/dist/{multi-select.d.ts → types/components/composites/select/MultiSelect.d.ts} +12 -11
- package/dist/{select.d.ts → types/components/composites/select/Select.d.ts} +16 -14
- package/dist/types/components/composites/select/core/index.d.ts +4 -0
- package/dist/types/components/composites/select/core/menu.d.ts +13 -0
- package/dist/types/components/composites/select/core/panel.d.ts +18 -0
- package/dist/types/components/composites/select/core/trigger.d.ts +16 -0
- package/dist/{types-SGMShK7R.d.ts → types/components/composites/select/core/types.d.ts} +13 -6
- package/dist/types/components/composites/select/core/use-listbox.d.ts +42 -0
- package/dist/{sheet.d.ts → types/components/composites/sheet/Sheet.d.ts} +10 -11
- package/dist/types/components/composites/sheet/use-sheet-drag.d.ts +13 -0
- package/dist/{table.d.ts → types/components/composites/table/Table.d.ts} +12 -12
- package/dist/{tabs.d.ts → types/components/composites/tabs/Tabs.d.ts} +13 -13
- package/dist/types/components/composites/toast/Toast.d.ts +10 -0
- package/dist/{toast-store.d.ts → types/components/composites/toast/toast-store.d.ts} +12 -14
- package/dist/{tooltip.d.ts → types/components/composites/tooltip/Tooltip.d.ts} +6 -10
- package/dist/types/components/composites/tooltip/tooltip-host.d.ts +1 -0
- package/dist/types/components/composites/tooltip/tooltip-store.d.ts +29 -0
- package/dist/types/components/compound/support-rail/SupportRail.d.ts +41 -0
- package/dist/types/components/dev/MotionDevtools.d.ts +24 -0
- package/dist/types/components/dev/slowmo-engine.d.ts +27 -0
- package/dist/types/components/expressive/confetti/Confetti.d.ts +43 -0
- package/dist/types/components/expressive/facebook-feed/FacebookFeed.d.ts +73 -0
- package/dist/types/components/expressive/facebook-feed/chrome.d.ts +30 -0
- package/dist/types/components/expressive/facebook-feed/icons.d.ts +21 -0
- package/dist/types/components/expressive/facebook-feed/post.d.ts +25 -0
- package/dist/types/components/expressive/facebook-feed/reel.d.ts +26 -0
- package/dist/types/components/expressive/facebook-feed/story.d.ts +20 -0
- package/dist/types/components/expressive/flow-field/FlowField.d.ts +23 -0
- package/dist/types/components/expressive/instagram-feed/InstagramFeed.d.ts +59 -0
- package/dist/types/components/expressive/lens/Lens.d.ts +23 -0
- package/dist/types/components/expressive/morphing-text/MorphingText.d.ts +21 -0
- package/dist/types/components/expressive/odometer/Odometer.d.ts +21 -0
- package/dist/types/components/expressive/tiktok/TikTok.d.ts +85 -0
- package/dist/types/components/expressive/tiktok/glyphs.d.ts +40 -0
- package/dist/types/components/expressive/typing-lines/TypingLines.d.ts +25 -0
- package/dist/types/components/expressive/weight-field/WeightField.d.ts +19 -0
- package/dist/types/components/expressive/youtube/YouTube.d.ts +73 -0
- package/dist/types/components/expressive/youtube/format.d.ts +2 -0
- package/dist/types/components/expressive/youtube/glyphs.d.ts +16 -0
- package/dist/types/components/expressive/youtube/media.d.ts +8 -0
- package/dist/types/components/expressive/youtube/post.d.ts +19 -0
- package/dist/types/components/expressive/youtube/short.d.ts +18 -0
- package/dist/types/components/expressive/youtube/video.d.ts +14 -0
- package/dist/types/components/internal/collection/collection.d.ts +19 -0
- package/dist/types/components/internal/glass/glint.d.ts +1 -0
- package/dist/types/components/internal/hooks/use-controllable.d.ts +1 -0
- package/dist/types/components/internal/hooks/use-media-query.d.ts +1 -0
- package/dist/types/components/internal/hooks/use-scroll-edges.d.ts +10 -0
- package/dist/types/components/internal/hooks/use-typeahead.d.ts +5 -0
- package/dist/types/components/internal/icon/Icon.d.ts +33 -0
- package/dist/types/components/internal/icon/IconSlot.d.ts +7 -0
- package/dist/types/components/internal/menu/menu-row.d.ts +11 -0
- package/dist/types/components/internal/overlay/focus.d.ts +8 -0
- package/dist/types/components/internal/overlay/layer.d.ts +38 -0
- package/dist/types/components/internal/overlay/modal.d.ts +18 -0
- package/dist/types/components/internal/overlay/position.d.ts +14 -0
- package/dist/types/components/internal/support/types.d.ts +15 -0
- package/dist/types/components/internal/utils/activation.d.ts +23 -0
- package/dist/types/components/internal/utils/cx.d.ts +1 -0
- package/dist/types/components/internal/utils/token-px.d.ts +1 -0
- package/dist/{avatar.d.ts → types/components/primitives/avatar/Avatar.d.ts} +10 -12
- package/dist/{avatar-group.d.ts → types/components/primitives/avatar/AvatarGroup.d.ts} +7 -9
- package/dist/{badge.d.ts → types/components/primitives/badge/Badge.d.ts} +8 -10
- package/dist/types/components/primitives/badge/CountBadge.d.ts +8 -0
- package/dist/types/components/primitives/badge/StatusBadge.d.ts +15 -0
- package/dist/types/components/primitives/badge/digit-strip.d.ts +5 -0
- package/dist/{button.d.ts → types/components/primitives/button/Button.d.ts} +6 -8
- package/dist/{checkbox.d.ts → types/components/primitives/checkbox/Checkbox.d.ts} +6 -8
- package/dist/types/components/primitives/checkbox/check-glyph.d.ts +6 -0
- package/dist/{collapse.d.ts → types/components/primitives/collapse/Collapse.d.ts} +12 -13
- package/dist/types/components/primitives/collapse/collapse.typecheck.d.ts +2 -0
- package/dist/{number-field.d.ts → types/components/primitives/input/NumberField.d.ts} +7 -9
- package/dist/{otp-field.d.ts → types/components/primitives/input/OtpField.d.ts} +6 -8
- package/dist/{text-field.d.ts → types/components/primitives/input/TextField.d.ts} +7 -9
- package/dist/types/components/primitives/input/field-chrome.d.ts +45 -0
- package/dist/{radio-group.d.ts → types/components/primitives/radio-group/RadioGroup.d.ts} +8 -10
- package/dist/{tag.d.ts → types/components/primitives/tag/Tag.d.ts} +9 -12
- package/dist/{toggle-tag.d.ts → types/components/primitives/tag/ToggleTag.d.ts} +7 -8
- package/dist/{textarea.d.ts → types/components/primitives/textarea/Textarea.d.ts} +7 -9
- package/dist/{toggle.d.ts → types/components/primitives/toggle/Toggle.d.ts} +6 -8
- package/dist/{dom-props-C0jrllBw.d.ts → types/dom-props.d.ts} +1 -3
- package/dist/types/engine/animate.d.ts +30 -0
- package/dist/types/engine/drag.d.ts +17 -0
- package/dist/types/engine/ease.d.ts +15 -0
- package/dist/types/engine/flip.d.ts +18 -0
- package/dist/types/engine/index.d.ts +4 -0
- package/dist/types/engine/loop.d.ts +9 -0
- package/dist/types/motion/element.d.ts +17 -0
- package/dist/types/motion/flip.d.ts +4 -0
- package/dist/types/motion/glide.d.ts +11 -0
- package/dist/types/motion/motion-timing.d.ts +16 -0
- package/dist/types/motion/presence-context.d.ts +11 -0
- package/dist/types/motion/presence.d.ts +12 -0
- package/dist/types/motion/presets.d.ts +6 -0
- package/dist/{timing-7JA_zQHP.d.ts → types/motion/timing.d.ts} +9 -9
- package/dist/types/motion/use-motion.d.ts +17 -0
- package/dist/types/tokens/component-styles.generated.d.ts +262 -0
- package/dist/{motion-scale-Canq4stZ.d.ts → types/tokens/motion-scale.d.ts} +4 -4
- package/dist/{motion-tokens.d.ts → types/tokens/motion-tokens.d.ts} +9 -9
- package/dist/types/tokens/theme-tokens.generated.d.ts +1249 -0
- package/dist/types/tokens/theme.d.ts +12 -0
- package/dist/typing-lines.css +92 -0
- package/dist/typing-lines.js +139 -0
- package/dist/typing-lines.js.map +1 -0
- package/dist/weight-field.css +84 -0
- package/dist/weight-field.js +17 -0
- package/dist/weight-field.js.map +1 -0
- package/dist/youtube.css +611 -0
- package/dist/youtube.js +814 -0
- package/dist/youtube.js.map +1 -0
- package/package.json +155 -49
- package/skills/zyncat-ui/SKILL.md +95 -0
- package/skills/zyncat-ui/references/components.md +85 -0
- package/skills/zyncat-ui/references/recipes.md +171 -0
- package/skills/zyncat-ui/references/theming.md +83 -0
- package/src/components/composites/alert/Alert.tsx +13 -11
- package/src/components/composites/alert/Alert.usage.md +15 -0
- package/src/components/composites/alert/alert.css +126 -121
- package/src/components/composites/date-picker/DateField.tsx +7 -2
- package/src/components/composites/date-picker/DateField.usage.md +10 -0
- package/src/components/composites/date-picker/DateRangeField.tsx +18 -16
- package/src/components/composites/date-picker/DateRangeField.usage.md +10 -0
- package/src/components/composites/date-picker/DateTimeField.tsx +10 -5
- package/src/components/composites/date-picker/DateTimeField.usage.md +12 -0
- package/src/components/composites/date-picker/TimeField.tsx +3 -1
- package/src/components/composites/date-picker/TimeField.usage.md +12 -0
- package/src/components/composites/date-picker/calendar-panel.tsx +15 -10
- package/src/components/composites/date-picker/date-picker.css +563 -559
- package/src/components/composites/date-picker/field-shell.tsx +9 -3
- package/src/components/composites/date-picker/range-panel.tsx +23 -8
- package/src/components/composites/date-picker/time-core.tsx +2 -0
- package/src/components/composites/dialog/Dialog.tsx +30 -15
- package/src/components/composites/dialog/Dialog.usage.md +17 -0
- package/src/components/composites/dialog/dialog.css +176 -172
- package/src/components/composites/dropdown/Dropdown.tsx +184 -0
- package/src/components/composites/dropdown/Dropdown.usage.md +19 -0
- package/src/components/composites/dropdown/dropdown.css +65 -0
- package/src/components/composites/dropdown/menu-panel.tsx +255 -0
- package/src/components/composites/dropdown/types.ts +95 -0
- package/src/components/composites/emoji-picker/EmojiPickerPanel.tsx +153 -0
- package/src/components/composites/emoji-picker/EmojiPickerPanel.usage.md +26 -0
- package/src/components/composites/emoji-picker/category-icons.ts +29 -0
- package/src/components/composites/emoji-picker/data.ts +83 -0
- package/src/components/composites/emoji-picker/dom.ts +79 -0
- package/src/components/composites/emoji-picker/getEmojiUrl.ts +17 -0
- package/src/components/composites/emoji-picker/navigation.ts +86 -0
- package/src/components/composites/emoji-picker/picker.ts +169 -0
- package/src/components/composites/emoji-picker/react/category-bar.tsx +77 -0
- package/src/components/composites/emoji-picker/react/useEmojiPicker.ts +139 -0
- package/src/components/composites/emoji-picker/scaffold.ts +74 -0
- package/src/components/composites/emoji-picker/search.ts +79 -0
- package/src/components/composites/emoji-picker/styles.css +221 -0
- package/src/components/composites/emoji-picker/types.ts +14 -0
- package/src/components/composites/modal/Modal.tsx +24 -13
- package/src/components/composites/modal/Modal.usage.md +24 -0
- package/src/components/composites/modal/modal.css +11 -7
- package/src/components/composites/pagination/Pagination.tsx +6 -11
- package/src/components/composites/pagination/Pagination.usage.md +12 -0
- package/src/components/composites/pagination/pagination.css +42 -38
- package/src/components/composites/popover/Popover.tsx +22 -7
- package/src/components/composites/popover/Popover.usage.md +15 -0
- package/src/components/composites/popover/popover.css +69 -65
- package/src/components/composites/select/MultiSelect.tsx +13 -5
- package/src/components/composites/select/MultiSelect.usage.md +12 -0
- package/src/components/composites/select/Select.tsx +23 -7
- package/src/components/composites/select/Select.usage.md +20 -0
- package/src/components/composites/select/core/index.ts +1 -1
- package/src/components/composites/select/core/menu.tsx +8 -6
- package/src/components/composites/select/core/panel.tsx +25 -26
- package/src/components/composites/select/core/trigger.tsx +36 -24
- package/src/components/composites/select/core/types.ts +17 -15
- package/src/components/composites/select/core/use-listbox.ts +22 -21
- package/src/components/composites/select/select.css +291 -386
- package/src/components/composites/sheet/Sheet.tsx +28 -18
- package/src/components/composites/sheet/Sheet.usage.md +15 -0
- package/src/components/composites/sheet/sheet.css +47 -23
- package/src/components/composites/sheet/use-sheet-drag.ts +19 -15
- package/src/components/composites/table/Table.tsx +17 -6
- package/src/components/composites/table/Table.usage.md +19 -0
- package/src/components/composites/table/table.css +333 -323
- package/src/components/composites/tabs/Tabs.tsx +31 -23
- package/src/components/composites/tabs/Tabs.usage.md +13 -0
- package/src/components/composites/tabs/tabs.css +163 -156
- package/src/components/composites/toast/Toast.tsx +48 -51
- package/src/components/composites/toast/Toast.usage.md +23 -0
- package/src/components/composites/toast/toast-store.usage.md +16 -0
- package/src/components/composites/toast/toast.css +237 -233
- package/src/components/composites/tooltip/Tooltip.tsx +13 -8
- package/src/components/composites/tooltip/Tooltip.usage.md +14 -0
- package/src/components/composites/tooltip/tooltip-host.tsx +29 -61
- package/src/components/composites/tooltip/tooltip-store.ts +10 -0
- package/src/components/composites/tooltip/tooltip.css +79 -78
- package/src/components/compound/support-rail/SupportRail.tsx +343 -0
- package/src/components/compound/support-rail/SupportRail.usage.md +18 -0
- package/src/components/compound/support-rail/support-rail.css +421 -0
- package/src/components/dev/MotionDevtools.tsx +3 -1
- package/src/components/dev/MotionDevtools.usage.md +16 -0
- package/src/components/dev/motion-devtools.css +237 -233
- package/src/components/expressive/confetti/Confetti.tsx +727 -0
- package/src/components/expressive/confetti/Confetti.usage.md +18 -0
- package/src/components/expressive/confetti/confetti.css +45 -0
- package/src/components/expressive/facebook-feed/FacebookFeed.tsx +200 -0
- package/src/components/expressive/facebook-feed/FacebookFeed.usage.md +18 -0
- package/src/components/expressive/facebook-feed/chrome.tsx +120 -0
- package/src/components/expressive/facebook-feed/facebook-feed.css +880 -0
- package/src/components/expressive/facebook-feed/icons.tsx +145 -0
- package/src/components/expressive/facebook-feed/post.tsx +213 -0
- package/src/components/expressive/facebook-feed/reel.tsx +199 -0
- package/src/components/expressive/facebook-feed/story.tsx +132 -0
- package/src/components/expressive/flow-field/FlowField.tsx +348 -0
- package/src/components/expressive/flow-field/FlowField.usage.md +19 -0
- package/src/components/expressive/flow-field/flow-field.css +49 -0
- package/src/components/expressive/instagram-feed/InstagramFeed.tsx +374 -0
- package/src/components/expressive/instagram-feed/InstagramFeed.usage.md +18 -0
- package/src/components/expressive/instagram-feed/instagram-feed.css +378 -0
- package/src/components/expressive/lens/Lens.tsx +415 -0
- package/src/components/expressive/lens/Lens.usage.md +20 -0
- package/src/components/expressive/lens/lens.css +119 -0
- package/src/components/expressive/morphing-text/MorphingText.tsx +328 -0
- package/src/components/expressive/morphing-text/MorphingText.usage.md +19 -0
- package/src/components/expressive/morphing-text/morphing-text.css +84 -0
- package/src/components/expressive/odometer/Odometer.tsx +158 -0
- package/src/components/expressive/odometer/Odometer.usage.md +17 -0
- package/src/components/expressive/odometer/odometer.css +61 -0
- package/src/components/expressive/tiktok/TikTok.tsx +542 -0
- package/src/components/expressive/tiktok/TikTok.usage.md +17 -0
- package/src/components/expressive/tiktok/glyphs.tsx +163 -0
- package/src/components/expressive/tiktok/tiktok.css +662 -0
- package/src/components/expressive/typing-lines/TypingLines.tsx +0 -0
- package/src/components/expressive/typing-lines/TypingLines.usage.md +17 -0
- package/src/components/expressive/typing-lines/typing-lines.css +92 -0
- package/src/components/expressive/weight-field/WeightField.tsx +41 -0
- package/src/components/expressive/weight-field/WeightField.usage.md +20 -0
- package/src/components/expressive/weight-field/weight-field.css +84 -0
- package/src/components/expressive/youtube/YouTube.tsx +192 -0
- package/src/components/expressive/youtube/YouTube.usage.md +18 -0
- package/src/components/expressive/youtube/format.ts +22 -0
- package/src/components/expressive/youtube/glyphs.tsx +235 -0
- package/src/components/expressive/youtube/media.tsx +18 -0
- package/src/components/expressive/youtube/post.tsx +282 -0
- package/src/components/expressive/youtube/short.tsx +212 -0
- package/src/components/expressive/youtube/video.tsx +75 -0
- package/src/components/expressive/youtube/youtube.css +611 -0
- package/src/components/internal/collection/collection.ts +44 -0
- package/src/components/internal/glass/glass.css +88 -84
- package/src/components/internal/hooks/use-media-query.ts +20 -0
- package/src/components/internal/hooks/use-typeahead.ts +28 -0
- package/src/components/internal/icon/Icon.tsx +2 -0
- package/src/components/internal/icon/IconSlot.tsx +2 -0
- package/src/components/internal/icon/icon.css +34 -30
- package/src/components/internal/menu/menu-row.tsx +34 -0
- package/src/components/internal/menu/menu-surface.css +127 -0
- package/src/components/internal/overlay/focus.ts +26 -10
- package/src/components/internal/overlay/layer.tsx +50 -9
- package/src/components/internal/overlay/modal.tsx +14 -12
- package/src/components/internal/overlay/overlay.css +24 -20
- package/src/components/internal/overlay/position.ts +19 -9
- package/src/components/internal/overlay/trigger.css +13 -0
- package/src/components/internal/support/types.ts +16 -0
- package/src/components/internal/utils/activation.ts +78 -0
- package/src/components/primitives/avatar/Avatar.tsx +2 -0
- package/src/components/primitives/avatar/Avatar.usage.md +12 -0
- package/src/components/primitives/avatar/AvatarGroup.tsx +3 -1
- package/src/components/primitives/avatar/AvatarGroup.usage.md +15 -0
- package/src/components/primitives/avatar/avatar.css +179 -174
- package/src/components/primitives/badge/Badge.tsx +3 -1
- package/src/components/primitives/badge/Badge.usage.md +14 -0
- package/src/components/primitives/badge/CountBadge.tsx +2 -2
- package/src/components/primitives/badge/CountBadge.usage.md +13 -0
- package/src/components/primitives/badge/StatusBadge.tsx +3 -1
- package/src/components/primitives/badge/StatusBadge.usage.md +14 -0
- package/src/components/primitives/badge/badge.css +166 -160
- package/src/components/primitives/badge/digit-strip.css +65 -0
- package/src/components/primitives/badge/{odometer.tsx → digit-strip.tsx} +3 -3
- package/src/components/primitives/button/Button.tsx +2 -0
- package/src/components/primitives/button/Button.usage.md +14 -0
- package/src/components/primitives/button/button.css +272 -246
- package/src/components/primitives/checkbox/Checkbox.tsx +3 -1
- package/src/components/primitives/checkbox/Checkbox.usage.md +12 -0
- package/src/components/primitives/checkbox/check-glyph.tsx +1 -0
- package/src/components/primitives/checkbox/checkbox.css +158 -153
- package/src/components/primitives/collapse/Collapse.tsx +3 -1
- package/src/components/primitives/collapse/Collapse.usage.md +17 -0
- package/src/components/primitives/collapse/collapse.css +70 -61
- package/src/components/primitives/collapse/collapse.typecheck.tsx +2 -0
- package/src/components/primitives/input/NumberField.tsx +18 -5
- package/src/components/primitives/input/NumberField.usage.md +12 -0
- package/src/components/primitives/input/OtpField.tsx +2 -0
- package/src/components/primitives/input/OtpField.usage.md +12 -0
- package/src/components/primitives/input/TextField.tsx +16 -4
- package/src/components/primitives/input/TextField.usage.md +13 -0
- package/src/components/primitives/input/field-chrome.tsx +11 -2
- package/src/components/primitives/input/input.css +296 -318
- package/src/components/primitives/radio-group/RadioGroup.tsx +20 -44
- package/src/components/primitives/radio-group/RadioGroup.usage.md +13 -0
- package/src/components/primitives/radio-group/radio-group.css +275 -276
- package/src/components/primitives/tag/Tag.tsx +10 -6
- package/src/components/primitives/tag/Tag.usage.md +14 -0
- package/src/components/primitives/tag/ToggleTag.tsx +4 -2
- package/src/components/primitives/tag/ToggleTag.usage.md +14 -0
- package/src/components/primitives/tag/tag.css +209 -231
- package/src/components/primitives/textarea/Textarea.tsx +17 -7
- package/src/components/primitives/textarea/Textarea.usage.md +12 -0
- package/src/components/primitives/textarea/textarea.css +205 -211
- package/src/components/primitives/toggle/Toggle.tsx +3 -1
- package/src/components/primitives/toggle/Toggle.usage.md +12 -0
- package/src/components/primitives/toggle/toggle.css +139 -135
- package/src/engine/animate.ts +40 -13
- package/src/engine/ease.ts +1 -0
- package/src/engine/flip.ts +32 -15
- package/src/engine/index.ts +2 -1
- package/src/engine/loop.ts +97 -0
- package/src/mcp/server.ts +315 -218
- package/src/motion/element.tsx +1 -0
- package/src/motion/flip.ts +29 -10
- package/src/motion/glide.tsx +11 -14
- package/src/motion/glide.usage.md +15 -0
- package/src/motion/motion-timing.ts +3 -3
- package/src/motion/presence.tsx +12 -5
- package/src/motion/presets.ts +13 -0
- package/src/motion/timing.ts +1 -0
- package/src/motion/use-motion.ts +16 -3
- package/src/styles.css +5 -0
- package/src/tokens/avatar.css +20 -16
- package/src/tokens/color.css +67 -56
- package/src/tokens/component-styles.generated.ts +270 -0
- package/src/tokens/elevation.css +28 -17
- package/src/tokens/fonts.css +1 -1
- package/src/tokens/glass.css +19 -15
- package/src/tokens/icons.css +8 -4
- package/src/tokens/layers.css +9 -4
- package/src/tokens/motion-scale.ts +4 -0
- package/src/tokens/motion-tokens.ts +42 -12
- package/src/tokens/motion-tokens.usage.md +16 -0
- package/src/tokens/motion.css +63 -45
- package/src/tokens/radius.css +12 -8
- package/src/tokens/semantic.css +62 -54
- package/src/tokens/spacing.css +25 -21
- package/src/tokens/theme-tokens.generated.ts +1278 -0
- package/src/tokens/theme.tsx +83 -0
- package/src/tokens/theme.usage.md +36 -0
- package/src/tokens/typography.css +53 -49
- package/dist/chunk-2ERBBFZS.js.map +0 -1
- package/dist/chunk-2F5PITAO.js.map +0 -1
- package/dist/chunk-2QWJ6FAX.js.map +0 -1
- package/dist/chunk-62P3KD57.js.map +0 -1
- package/dist/chunk-7SZCJ7WI.js.map +0 -1
- package/dist/chunk-AIQXS2XY.js.map +0 -1
- package/dist/chunk-AMFGY56I.js.map +0 -1
- package/dist/chunk-CONSWNIV.js.map +0 -1
- package/dist/chunk-DKVUPFQR.js.map +0 -1
- package/dist/chunk-I4XQ4PV2.js.map +0 -1
- package/dist/chunk-NEF5XAHG.js.map +0 -1
- package/dist/chunk-NGTA34V2.js.map +0 -1
- package/dist/chunk-NNXJCLTV.js.map +0 -1
- package/dist/chunk-PMECHR3A.js.map +0 -1
- package/dist/chunk-QDK66S4G.js.map +0 -1
- package/dist/chunk-S5ZTZANS.js.map +0 -1
- package/dist/chunk-U4MHX3KH.js.map +0 -1
- package/dist/chunk-VTJTGVZZ.js.map +0 -1
- package/dist/chunk-WFHRAKN3.js.map +0 -1
- package/dist/chunk-WM5J5TDI.js.map +0 -1
- package/dist/chunk-XJQQQJAO.js.map +0 -1
- package/dist/chunk-XWUWYSCT.js.map +0 -1
- package/dist/chunk-Y7AJQVWJ.js.map +0 -1
- package/dist/chunk-YGCVWGUG.js.map +0 -1
- package/dist/chunk-YGGCQNNU.js.map +0 -1
- package/dist/count-badge.d.ts +0 -13
- package/dist/date-range-field.d.ts +0 -33
- package/dist/field-chrome-CMPOQSLs.d.ts +0 -28
- package/dist/field-shell-Cuda-feL.d.ts +0 -24
- package/dist/glide.d.ts +0 -15
- package/dist/motion-devtools.d.ts +0 -51
- package/dist/status-badge.d.ts +0 -19
- package/dist/toast.d.ts +0 -12
- package/llms.txt +0 -220
- package/src/components/primitives/badge/odometer.css +0 -62
|
@@ -0,0 +1,727 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import './confetti.css';
|
|
4
|
+
|
|
5
|
+
import { useEffect, useImperativeHandle, useRef, useSyncExternalStore, type HTMLAttributes, type Ref } from 'react';
|
|
6
|
+
import { createPortal } from 'react-dom';
|
|
7
|
+
|
|
8
|
+
import type { DataAttributes } from '../../../dom-props';
|
|
9
|
+
import { loop, type Playback } from '../../../engine';
|
|
10
|
+
import type { ConfettiStyle } from '../../../tokens/component-styles.generated';
|
|
11
|
+
import { cx } from '../../internal/utils/cx';
|
|
12
|
+
|
|
13
|
+
const TAU = Math.PI * 2;
|
|
14
|
+
const MS_PER_SECOND = 1000;
|
|
15
|
+
const subscribeToNothing = () => () => {};
|
|
16
|
+
|
|
17
|
+
const MAX_PIECES = 520;
|
|
18
|
+
const MIN_COUNT = 1;
|
|
19
|
+
const DEFAULT_COUNT = 170;
|
|
20
|
+
const DEFAULT_DURATION = 0.15;
|
|
21
|
+
const MAX_DURATION = 10;
|
|
22
|
+
const EMISSION_EASE = 1.8;
|
|
23
|
+
const PIXEL_RATIO_CAP = 2;
|
|
24
|
+
|
|
25
|
+
const PAPER_SLOTS = 5;
|
|
26
|
+
const DEFAULT_WEIGHT = 1;
|
|
27
|
+
const PAPER_KEYS = Array.from({ length: PAPER_SLOTS }, (_, i) => `--confetti-paper-${i + 1}`);
|
|
28
|
+
const REVERSE_KEYS = Array.from({ length: PAPER_SLOTS }, (_, i) => `--confetti-reverse-${i + 1}`);
|
|
29
|
+
const SHEEN_KEYS = Array.from({ length: PAPER_SLOTS }, (_, i) => `--confetti-sheen-${i + 1}`);
|
|
30
|
+
const WEIGHTS_KEY = '--confetti-weights';
|
|
31
|
+
|
|
32
|
+
const SCALE_REFERENCE = 700;
|
|
33
|
+
const SCALE_MIN = 0.72;
|
|
34
|
+
const SCALE_MAX = 1.6;
|
|
35
|
+
|
|
36
|
+
const DEPTH_NEAR = 2;
|
|
37
|
+
const DEPTH_FAR_SHARE = 0.34;
|
|
38
|
+
const DEPTH_MID_SHARE = 0.6;
|
|
39
|
+
const DEPTH_SIZE = [0.62, 0.88, 1.16];
|
|
40
|
+
const DEPTH_ALPHA = [0.52, 0.8, 1];
|
|
41
|
+
const DEPTH_GRAVITY = [0.86, 1, 1.13];
|
|
42
|
+
const DEPTH_DRAG = [1.14, 1, 0.9];
|
|
43
|
+
|
|
44
|
+
const GRAVITY = 1020;
|
|
45
|
+
const DRAG = 0.03;
|
|
46
|
+
const DRAG_SOFTENING = 265;
|
|
47
|
+
const AREA_EDGE_ON = 0.14;
|
|
48
|
+
const AREA_SWING = 0.86;
|
|
49
|
+
const LIFT_MIN = 1.5;
|
|
50
|
+
const LIFT_RANGE = 1.4;
|
|
51
|
+
const LIFT_SPEED_CAP = 300;
|
|
52
|
+
const PACE_FLOOR = 0.001;
|
|
53
|
+
const SPIN_RANGE = 7;
|
|
54
|
+
const SPIN_JITTER = 0.5;
|
|
55
|
+
const FLIP_MIN = 3.2;
|
|
56
|
+
const FLIP_RANGE = 6;
|
|
57
|
+
const FLIP_SPEED_COUPLING = 0.0016;
|
|
58
|
+
const ALIGN_RATE = 4.5;
|
|
59
|
+
const LIFE_MIN = 4.6;
|
|
60
|
+
const LIFE_RANGE = 2.8;
|
|
61
|
+
const FADE_IN = 0.09;
|
|
62
|
+
const FADE_OUT = 0.42;
|
|
63
|
+
const CULL_BELOW = 90;
|
|
64
|
+
const CULL_SIDE = 260;
|
|
65
|
+
|
|
66
|
+
const FLAKE_SHARE = 0.4;
|
|
67
|
+
const CURL_SHARE = 0.62;
|
|
68
|
+
const RIBBON_SHARE = 0.82;
|
|
69
|
+
|
|
70
|
+
const FLAKE_WIDTH_MIN = 7;
|
|
71
|
+
const FLAKE_WIDTH_RANGE = 6;
|
|
72
|
+
const FLAKE_HEIGHT_MIN = 9;
|
|
73
|
+
const FLAKE_HEIGHT_RANGE = 7;
|
|
74
|
+
const FLAKE_HEIGHT_FLOOR = 0.7;
|
|
75
|
+
const FLAKE_CORNER_MAX = 1.7;
|
|
76
|
+
|
|
77
|
+
const CURL_RADIUS_MIN = 5;
|
|
78
|
+
const CURL_RADIUS_RANGE = 5;
|
|
79
|
+
const CURL_STROKE_MIN = 2.2;
|
|
80
|
+
const CURL_STROKE_RANGE = 1.3;
|
|
81
|
+
const CURL_SWEEP_MIN = 2.1;
|
|
82
|
+
const CURL_SWEEP_RANGE = 2.1;
|
|
83
|
+
const CURL_HEIGHT_FLOOR = 0.5;
|
|
84
|
+
|
|
85
|
+
const RIBBON_SEGMENTS = 8;
|
|
86
|
+
const RIBBON_LENGTH_MIN = 26;
|
|
87
|
+
const RIBBON_LENGTH_RANGE = 26;
|
|
88
|
+
const RIBBON_WAVE_MIN = 3.4;
|
|
89
|
+
const RIBBON_WAVE_RANGE = 5;
|
|
90
|
+
const RIBBON_WIDTH_MIN = 4.4;
|
|
91
|
+
const RIBBON_WIDTH_RANGE = 3;
|
|
92
|
+
const RIBBON_FREQUENCY_MIN = 0.8;
|
|
93
|
+
const RIBBON_FREQUENCY_RANGE = 0.8;
|
|
94
|
+
const RIBBON_TWIST_MIN = 4;
|
|
95
|
+
const RIBBON_TWIST_RANGE = 4.5;
|
|
96
|
+
const RIBBON_EDGE_ON = 0.16;
|
|
97
|
+
|
|
98
|
+
const SEQUIN_RADIUS_MIN = 1.5;
|
|
99
|
+
const SEQUIN_RADIUS_RANGE = 1.2;
|
|
100
|
+
const SEQUIN_GLINT_SHARE = 0.45;
|
|
101
|
+
const SEQUIN_GLINT_EDGE = 0.74;
|
|
102
|
+
const SEQUIN_GLINT_REACH = 3.4;
|
|
103
|
+
const SEQUIN_GLINT_STROKE = 0.9;
|
|
104
|
+
const SEQUIN_FACE_BASE = 0.75;
|
|
105
|
+
const SEQUIN_FACE_RANGE = 0.25;
|
|
106
|
+
|
|
107
|
+
const SPECULAR_EDGE = 0.15;
|
|
108
|
+
const ALPHA_FLOOR = 0.01;
|
|
109
|
+
const STREAK_SPEED = 430;
|
|
110
|
+
const STREAK_ALPHA = 0.16;
|
|
111
|
+
const STREAK_REACH = 0.014;
|
|
112
|
+
const STREAK_WIDTH = 0.42;
|
|
113
|
+
const STREAK_STROKE_FLOOR = 1;
|
|
114
|
+
|
|
115
|
+
const SIDE_ANGLE_LEFT = -0.92;
|
|
116
|
+
const SIDE_ANGLE_RIGHT = -2.22;
|
|
117
|
+
const SIDE_SPREAD = 0.6;
|
|
118
|
+
const SIDE_SPEED_MIN = 1270;
|
|
119
|
+
const SIDE_SPEED_RANGE = 440;
|
|
120
|
+
const SIDE_INSET = 20;
|
|
121
|
+
const SIDE_JITTER = 14;
|
|
122
|
+
const SIDE_HEIGHT = 0.66;
|
|
123
|
+
const SIDE_BAND = 0.15;
|
|
124
|
+
|
|
125
|
+
const TOP_ANGLE = Math.PI / 2;
|
|
126
|
+
const TOP_SPREAD = 0.56;
|
|
127
|
+
const TOP_SPEED_MIN = 70;
|
|
128
|
+
const TOP_SPEED_RANGE = 150;
|
|
129
|
+
const TOP_OVERSCAN = 0.04;
|
|
130
|
+
const TOP_RISE = 46;
|
|
131
|
+
const TOP_RISE_JITTER = 80;
|
|
132
|
+
const TOP_DRIFT = 30;
|
|
133
|
+
const TOP_DRIFT_RATE = 0.62;
|
|
134
|
+
|
|
135
|
+
const CORNER_ANGLE_LEFT = -1.27;
|
|
136
|
+
const CORNER_ANGLE_RIGHT = -1.87;
|
|
137
|
+
const CORNER_SPREAD = 0.44;
|
|
138
|
+
const CORNER_SPEED_MIN = 1180;
|
|
139
|
+
const CORNER_SPEED_RANGE = 430;
|
|
140
|
+
const CORNER_INSET = 0.035;
|
|
141
|
+
const CORNER_JITTER = 14;
|
|
142
|
+
const CORNER_LAUNCH = 14;
|
|
143
|
+
const CORNER_LAUNCH_JITTER = 12;
|
|
144
|
+
|
|
145
|
+
const VIEWPORT_CLASS = 'confetti--viewport';
|
|
146
|
+
|
|
147
|
+
export type ConfettiEmitter = 'sides' | 'top' | 'corners';
|
|
148
|
+
export type ConfettiField = 'container' | 'viewport';
|
|
149
|
+
|
|
150
|
+
type Shape = 'flake' | 'curl' | 'ribbon' | 'sequin';
|
|
151
|
+
|
|
152
|
+
interface Piece {
|
|
153
|
+
x: number;
|
|
154
|
+
y: number;
|
|
155
|
+
vx: number;
|
|
156
|
+
vy: number;
|
|
157
|
+
depth: number;
|
|
158
|
+
alpha: number;
|
|
159
|
+
gravity: number;
|
|
160
|
+
drag: number;
|
|
161
|
+
lift: number;
|
|
162
|
+
drift: number;
|
|
163
|
+
shape: Shape;
|
|
164
|
+
slot: number;
|
|
165
|
+
spin: number;
|
|
166
|
+
spinRate: number;
|
|
167
|
+
flip: number;
|
|
168
|
+
flipRate: number;
|
|
169
|
+
wave: number;
|
|
170
|
+
age: number;
|
|
171
|
+
life: number;
|
|
172
|
+
fade: number;
|
|
173
|
+
pace: number;
|
|
174
|
+
aligned: boolean;
|
|
175
|
+
width: number;
|
|
176
|
+
height: number;
|
|
177
|
+
radius: number;
|
|
178
|
+
stroke: number;
|
|
179
|
+
sweepFrom: number;
|
|
180
|
+
sweep: number;
|
|
181
|
+
length: number;
|
|
182
|
+
amplitude: number;
|
|
183
|
+
frequency: number;
|
|
184
|
+
twist: number;
|
|
185
|
+
glint: boolean;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
interface Run {
|
|
189
|
+
emitter: ConfettiEmitter;
|
|
190
|
+
total: number;
|
|
191
|
+
sent: number;
|
|
192
|
+
elapsed: number;
|
|
193
|
+
span: number;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
interface Palette {
|
|
197
|
+
key: string;
|
|
198
|
+
front: string[];
|
|
199
|
+
reverse: string[];
|
|
200
|
+
sheen: string[];
|
|
201
|
+
weights: number[];
|
|
202
|
+
total: number;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
interface Stage {
|
|
206
|
+
canvas: HTMLCanvasElement;
|
|
207
|
+
ctx: CanvasRenderingContext2D;
|
|
208
|
+
width: number;
|
|
209
|
+
height: number;
|
|
210
|
+
size: number;
|
|
211
|
+
pieces: Piece[];
|
|
212
|
+
runs: Run[];
|
|
213
|
+
clock: number;
|
|
214
|
+
palette: Palette;
|
|
215
|
+
playback: Playback | null;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
interface Seat {
|
|
219
|
+
x: number;
|
|
220
|
+
y: number;
|
|
221
|
+
angle: number;
|
|
222
|
+
speed: number;
|
|
223
|
+
drift: number;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const clamp = (v: number, min: number, max: number) => (v < min ? min : v > max ? max : v);
|
|
227
|
+
|
|
228
|
+
const pieceCount = (value: number) =>
|
|
229
|
+
Number.isFinite(value) ? Math.round(clamp(value, MIN_COUNT, MAX_PIECES)) : DEFAULT_COUNT;
|
|
230
|
+
|
|
231
|
+
const emitterSpan = (value: number) => (Number.isFinite(value) && value > 0 ? Math.min(value, MAX_DURATION) : 0);
|
|
232
|
+
|
|
233
|
+
function readPalette(canvas: HTMLCanvasElement, cached: Palette | null): Palette {
|
|
234
|
+
const computed = getComputedStyle(canvas);
|
|
235
|
+
const key = [...PAPER_KEYS, ...REVERSE_KEYS, ...SHEEN_KEYS, WEIGHTS_KEY]
|
|
236
|
+
.map((name) => computed.getPropertyValue(name).trim())
|
|
237
|
+
.join('|');
|
|
238
|
+
if (cached && cached.key === key) return cached;
|
|
239
|
+
|
|
240
|
+
const resolveColor = (name: string) => {
|
|
241
|
+
canvas.style.color = `var(${name})`;
|
|
242
|
+
return getComputedStyle(canvas).color;
|
|
243
|
+
};
|
|
244
|
+
const front = PAPER_KEYS.map(resolveColor);
|
|
245
|
+
const reverse = REVERSE_KEYS.map(resolveColor);
|
|
246
|
+
const sheen = SHEEN_KEYS.map(resolveColor);
|
|
247
|
+
canvas.style.color = '';
|
|
248
|
+
|
|
249
|
+
const parsed = computed.getPropertyValue(WEIGHTS_KEY).trim().split(/\s+/).filter(Boolean).map(Number);
|
|
250
|
+
const weights: number[] = [];
|
|
251
|
+
let total = 0;
|
|
252
|
+
for (let i = 0; i < PAPER_SLOTS; i++) {
|
|
253
|
+
const value = parsed[i];
|
|
254
|
+
const weight = Number.isFinite(value) && value >= 0 ? value : DEFAULT_WEIGHT;
|
|
255
|
+
weights.push(weight);
|
|
256
|
+
total += weight;
|
|
257
|
+
}
|
|
258
|
+
if (total <= 0) {
|
|
259
|
+
weights.fill(DEFAULT_WEIGHT);
|
|
260
|
+
total = PAPER_SLOTS * DEFAULT_WEIGHT;
|
|
261
|
+
}
|
|
262
|
+
return { key, front, reverse, sheen, weights, total };
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function pickSlot(palette: Palette) {
|
|
266
|
+
let roll = Math.random() * palette.total;
|
|
267
|
+
for (let i = 0; i < palette.weights.length; i++) {
|
|
268
|
+
if (roll < palette.weights[i]) return i;
|
|
269
|
+
roll -= palette.weights[i];
|
|
270
|
+
}
|
|
271
|
+
return 0;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function seat(emitter: ConfettiEmitter, width: number, height: number): Seat {
|
|
275
|
+
if (emitter === 'top') {
|
|
276
|
+
return {
|
|
277
|
+
x: -width * TOP_OVERSCAN + Math.random() * width * (1 + TOP_OVERSCAN * 2),
|
|
278
|
+
y: -TOP_RISE - Math.random() * TOP_RISE_JITTER,
|
|
279
|
+
angle: TOP_ANGLE + (Math.random() - 0.5) * TOP_SPREAD,
|
|
280
|
+
speed: TOP_SPEED_MIN + Math.random() * TOP_SPEED_RANGE,
|
|
281
|
+
drift: TOP_DRIFT,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
const left = Math.random() < 0.5;
|
|
285
|
+
if (emitter === 'corners') {
|
|
286
|
+
return {
|
|
287
|
+
x: (left ? width * CORNER_INSET : width * (1 - CORNER_INSET)) + (Math.random() - 0.5) * CORNER_JITTER,
|
|
288
|
+
y: height + CORNER_LAUNCH + Math.random() * CORNER_LAUNCH_JITTER,
|
|
289
|
+
angle: (left ? CORNER_ANGLE_LEFT : CORNER_ANGLE_RIGHT) + (Math.random() - 0.5) * CORNER_SPREAD,
|
|
290
|
+
speed: CORNER_SPEED_MIN + Math.random() * CORNER_SPEED_RANGE,
|
|
291
|
+
drift: 0,
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
return {
|
|
295
|
+
x: left ? -SIDE_INSET - Math.random() * SIDE_JITTER : width + SIDE_INSET + Math.random() * SIDE_JITTER,
|
|
296
|
+
y: height * SIDE_HEIGHT + (Math.random() - 0.5) * height * SIDE_BAND,
|
|
297
|
+
angle: (left ? SIDE_ANGLE_LEFT : SIDE_ANGLE_RIGHT) + (Math.random() - 0.5) * SIDE_SPREAD,
|
|
298
|
+
speed: SIDE_SPEED_MIN + Math.random() * SIDE_SPEED_RANGE,
|
|
299
|
+
drift: 0,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function cut(stage: Stage, emitter: ConfettiEmitter, palette: Palette): Piece {
|
|
304
|
+
const spot = seat(emitter, stage.width, stage.height);
|
|
305
|
+
const speed = spot.speed * stage.size;
|
|
306
|
+
const depthRoll = Math.random();
|
|
307
|
+
const depth = depthRoll < DEPTH_FAR_SHARE ? 0 : depthRoll < DEPTH_MID_SHARE ? 1 : DEPTH_NEAR;
|
|
308
|
+
const size = DEPTH_SIZE[depth] * stage.size;
|
|
309
|
+
const shapeRoll = Math.random();
|
|
310
|
+
const shape: Shape =
|
|
311
|
+
shapeRoll < FLAKE_SHARE
|
|
312
|
+
? 'flake'
|
|
313
|
+
: shapeRoll < CURL_SHARE
|
|
314
|
+
? 'curl'
|
|
315
|
+
: shapeRoll < RIBBON_SHARE
|
|
316
|
+
? 'ribbon'
|
|
317
|
+
: 'sequin';
|
|
318
|
+
const piece: Piece = {
|
|
319
|
+
x: spot.x,
|
|
320
|
+
y: spot.y,
|
|
321
|
+
vx: Math.cos(spot.angle) * speed,
|
|
322
|
+
vy: Math.sin(spot.angle) * speed,
|
|
323
|
+
depth,
|
|
324
|
+
alpha: DEPTH_ALPHA[depth],
|
|
325
|
+
gravity: GRAVITY * DEPTH_GRAVITY[depth],
|
|
326
|
+
drag: DRAG * DEPTH_DRAG[depth],
|
|
327
|
+
lift: LIFT_MIN + Math.random() * LIFT_RANGE,
|
|
328
|
+
drift: spot.drift,
|
|
329
|
+
shape,
|
|
330
|
+
slot: pickSlot(palette),
|
|
331
|
+
spin: Math.random() * TAU,
|
|
332
|
+
spinRate: (Math.random() - 0.5) * SPIN_RANGE,
|
|
333
|
+
flip: Math.random() * TAU,
|
|
334
|
+
flipRate: (FLIP_MIN + Math.random() * FLIP_RANGE) * (Math.random() < 0.5 ? -1 : 1),
|
|
335
|
+
wave: Math.random() * TAU,
|
|
336
|
+
age: 0,
|
|
337
|
+
life: LIFE_MIN + Math.random() * LIFE_RANGE,
|
|
338
|
+
fade: 0,
|
|
339
|
+
pace: speed,
|
|
340
|
+
aligned: shape === 'ribbon',
|
|
341
|
+
width: 0,
|
|
342
|
+
height: 0,
|
|
343
|
+
radius: 0,
|
|
344
|
+
stroke: 0,
|
|
345
|
+
sweepFrom: 0,
|
|
346
|
+
sweep: 0,
|
|
347
|
+
length: 0,
|
|
348
|
+
amplitude: 0,
|
|
349
|
+
frequency: 0,
|
|
350
|
+
twist: 0,
|
|
351
|
+
glint: false,
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
if (shape === 'flake') {
|
|
355
|
+
piece.width = (FLAKE_WIDTH_MIN + Math.random() * FLAKE_WIDTH_RANGE) * size;
|
|
356
|
+
piece.height = (FLAKE_HEIGHT_MIN + Math.random() * FLAKE_HEIGHT_RANGE) * size;
|
|
357
|
+
} else if (shape === 'curl') {
|
|
358
|
+
piece.radius = (CURL_RADIUS_MIN + Math.random() * CURL_RADIUS_RANGE) * size;
|
|
359
|
+
piece.stroke = (CURL_STROKE_MIN + Math.random() * CURL_STROKE_RANGE) * size;
|
|
360
|
+
piece.sweepFrom = Math.random() * TAU;
|
|
361
|
+
piece.sweep = CURL_SWEEP_MIN + Math.random() * CURL_SWEEP_RANGE;
|
|
362
|
+
piece.width = piece.radius * 2;
|
|
363
|
+
} else if (shape === 'ribbon') {
|
|
364
|
+
piece.length = (RIBBON_LENGTH_MIN + Math.random() * RIBBON_LENGTH_RANGE) * size;
|
|
365
|
+
piece.amplitude = (RIBBON_WAVE_MIN + Math.random() * RIBBON_WAVE_RANGE) * size;
|
|
366
|
+
piece.width = (RIBBON_WIDTH_MIN + Math.random() * RIBBON_WIDTH_RANGE) * size;
|
|
367
|
+
piece.height = piece.width;
|
|
368
|
+
piece.frequency = RIBBON_FREQUENCY_MIN + Math.random() * RIBBON_FREQUENCY_RANGE;
|
|
369
|
+
piece.twist = RIBBON_TWIST_MIN + Math.random() * RIBBON_TWIST_RANGE;
|
|
370
|
+
piece.spin = Math.atan2(piece.vy, piece.vx);
|
|
371
|
+
} else {
|
|
372
|
+
piece.radius = (SEQUIN_RADIUS_MIN + Math.random() * SEQUIN_RADIUS_RANGE) * size;
|
|
373
|
+
piece.width = piece.radius * 2;
|
|
374
|
+
piece.glint = Math.random() < SEQUIN_GLINT_SHARE;
|
|
375
|
+
}
|
|
376
|
+
return piece;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function emit(stage: Stage, dt: number, palette: Palette) {
|
|
380
|
+
const runs = stage.runs;
|
|
381
|
+
for (let i = runs.length - 1; i >= 0; i--) {
|
|
382
|
+
const run = runs[i];
|
|
383
|
+
run.elapsed += dt;
|
|
384
|
+
const send = () => {
|
|
385
|
+
if (stage.pieces.length >= MAX_PIECES) stage.pieces.shift();
|
|
386
|
+
stage.pieces.push(cut(stage, run.emitter, palette));
|
|
387
|
+
run.sent++;
|
|
388
|
+
};
|
|
389
|
+
if (run.span <= 0) {
|
|
390
|
+
while (run.sent < run.total) send();
|
|
391
|
+
} else {
|
|
392
|
+
while (run.sent < run.total && run.elapsed >= run.span * Math.pow(run.sent / run.total, EMISSION_EASE)) send();
|
|
393
|
+
}
|
|
394
|
+
if (run.sent >= run.total) runs.splice(i, 1);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function advance(stage: Stage, dt: number) {
|
|
399
|
+
const pieces = stage.pieces;
|
|
400
|
+
const drift = Math.sin(stage.clock * TOP_DRIFT_RATE);
|
|
401
|
+
for (let i = pieces.length - 1; i >= 0; i--) {
|
|
402
|
+
const piece = pieces[i];
|
|
403
|
+
piece.age += dt;
|
|
404
|
+
const pace = Math.max(PACE_FLOOR, Math.hypot(piece.vx, piece.vy));
|
|
405
|
+
piece.pace = pace;
|
|
406
|
+
const area = AREA_EDGE_ON + AREA_SWING * Math.abs(Math.cos(piece.flip));
|
|
407
|
+
const resistance = (piece.drag * area) / (1 + (pace / DRAG_SOFTENING) * (pace / DRAG_SOFTENING));
|
|
408
|
+
const lift = piece.lift * area * Math.sin(piece.flip) * Math.min(pace, LIFT_SPEED_CAP);
|
|
409
|
+
const ax = -resistance * piece.vx * pace + drift * piece.drift + (-piece.vy / pace) * lift;
|
|
410
|
+
const ay = -resistance * piece.vy * pace + piece.gravity + (piece.vx / pace) * lift;
|
|
411
|
+
piece.vx += ax * dt;
|
|
412
|
+
piece.vy += ay * dt;
|
|
413
|
+
piece.x += piece.vx * dt;
|
|
414
|
+
piece.y += piece.vy * dt;
|
|
415
|
+
piece.spinRate += (Math.random() - 0.5) * SPIN_JITTER * dt;
|
|
416
|
+
if (piece.aligned) {
|
|
417
|
+
const want = Math.atan2(piece.vy, piece.vx);
|
|
418
|
+
piece.spin += (((want - piece.spin + Math.PI * 3) % TAU) - Math.PI) * Math.min(1, ALIGN_RATE * dt);
|
|
419
|
+
} else {
|
|
420
|
+
piece.spin += piece.spinRate * dt;
|
|
421
|
+
}
|
|
422
|
+
piece.flip += (piece.flipRate + Math.sign(piece.flipRate) * pace * FLIP_SPEED_COUPLING) * dt;
|
|
423
|
+
piece.fade = Math.min(1, piece.age / FADE_IN) * Math.min(1, (piece.life - piece.age) / FADE_OUT);
|
|
424
|
+
const gone =
|
|
425
|
+
piece.age >= piece.life ||
|
|
426
|
+
piece.y > stage.height + CULL_BELOW ||
|
|
427
|
+
piece.x < -CULL_SIDE ||
|
|
428
|
+
piece.x > stage.width + CULL_SIDE;
|
|
429
|
+
if (gone) pieces.splice(i, 1);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function drawFlake(ctx: CanvasRenderingContext2D, piece: Piece, tone: string) {
|
|
434
|
+
const face = Math.abs(Math.cos(piece.flip));
|
|
435
|
+
const height = Math.max(FLAKE_HEIGHT_FLOOR, piece.height * face);
|
|
436
|
+
ctx.fillStyle = tone;
|
|
437
|
+
ctx.beginPath();
|
|
438
|
+
ctx.roundRect(-piece.width / 2, -height / 2, piece.width, height, Math.min(FLAKE_CORNER_MAX, height / 2));
|
|
439
|
+
ctx.fill();
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function drawCurl(ctx: CanvasRenderingContext2D, piece: Piece, tone: string) {
|
|
443
|
+
const face = Math.abs(Math.cos(piece.flip));
|
|
444
|
+
ctx.strokeStyle = tone;
|
|
445
|
+
ctx.lineWidth = piece.stroke;
|
|
446
|
+
ctx.beginPath();
|
|
447
|
+
ctx.ellipse(
|
|
448
|
+
0,
|
|
449
|
+
0,
|
|
450
|
+
piece.radius,
|
|
451
|
+
Math.max(CURL_HEIGHT_FLOOR, piece.radius * face),
|
|
452
|
+
0,
|
|
453
|
+
piece.sweepFrom,
|
|
454
|
+
piece.sweepFrom + piece.sweep,
|
|
455
|
+
);
|
|
456
|
+
ctx.stroke();
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
function drawRibbon(ctx: CanvasRenderingContext2D, piece: Piece, palette: Palette) {
|
|
460
|
+
const half = piece.width * 0.5;
|
|
461
|
+
for (let s = 0; s < RIBBON_SEGMENTS; s++) {
|
|
462
|
+
const from = s / RIBBON_SEGMENTS;
|
|
463
|
+
const to = (s + 1) / RIBBON_SEGMENTS;
|
|
464
|
+
const x0 = (from - 0.5) * piece.length;
|
|
465
|
+
const x1 = (to - 0.5) * piece.length;
|
|
466
|
+
const y0 = piece.amplitude * Math.sin(from * piece.frequency * TAU + piece.wave);
|
|
467
|
+
const y1 = piece.amplitude * Math.sin(to * piece.frequency * TAU + piece.wave);
|
|
468
|
+
const twist0 = Math.cos(from * piece.twist + piece.flip);
|
|
469
|
+
const twist1 = Math.cos(to * piece.twist + piece.flip);
|
|
470
|
+
const w0 = half * Math.abs(twist0);
|
|
471
|
+
const w1 = half * Math.abs(twist1);
|
|
472
|
+
const edge = (Math.abs(twist0) + Math.abs(twist1)) * 0.5;
|
|
473
|
+
ctx.fillStyle =
|
|
474
|
+
edge < RIBBON_EDGE_ON
|
|
475
|
+
? palette.sheen[piece.slot]
|
|
476
|
+
: twist0 + twist1 >= 0
|
|
477
|
+
? palette.front[piece.slot]
|
|
478
|
+
: palette.reverse[piece.slot];
|
|
479
|
+
ctx.beginPath();
|
|
480
|
+
ctx.moveTo(x0, y0 - w0);
|
|
481
|
+
ctx.lineTo(x1, y1 - w1);
|
|
482
|
+
ctx.lineTo(x1, y1 + w1);
|
|
483
|
+
ctx.lineTo(x0, y0 + w0);
|
|
484
|
+
ctx.closePath();
|
|
485
|
+
ctx.fill();
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
function drawSequin(ctx: CanvasRenderingContext2D, piece: Piece, palette: Palette) {
|
|
490
|
+
const face = Math.abs(Math.cos(piece.flip));
|
|
491
|
+
ctx.fillStyle = palette.front[piece.slot];
|
|
492
|
+
ctx.beginPath();
|
|
493
|
+
ctx.arc(0, 0, piece.radius * (SEQUIN_FACE_BASE + SEQUIN_FACE_RANGE * face), 0, TAU);
|
|
494
|
+
ctx.fill();
|
|
495
|
+
if (!piece.glint || face <= SEQUIN_GLINT_EDGE) return;
|
|
496
|
+
const reach = (piece.radius * SEQUIN_GLINT_REACH * (face - SEQUIN_GLINT_EDGE)) / (1 - SEQUIN_GLINT_EDGE);
|
|
497
|
+
ctx.strokeStyle = palette.sheen[piece.slot];
|
|
498
|
+
ctx.lineWidth = SEQUIN_GLINT_STROKE;
|
|
499
|
+
ctx.beginPath();
|
|
500
|
+
ctx.moveTo(-reach, 0);
|
|
501
|
+
ctx.lineTo(reach, 0);
|
|
502
|
+
ctx.moveTo(0, -reach);
|
|
503
|
+
ctx.lineTo(0, reach);
|
|
504
|
+
ctx.stroke();
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
function paint(stage: Stage) {
|
|
508
|
+
const ctx = stage.ctx;
|
|
509
|
+
ctx.clearRect(0, 0, stage.width, stage.height);
|
|
510
|
+
const palette = stage.palette;
|
|
511
|
+
ctx.lineCap = 'round';
|
|
512
|
+
for (const piece of stage.pieces) {
|
|
513
|
+
const facing = Math.cos(piece.flip);
|
|
514
|
+
const face = Math.abs(facing);
|
|
515
|
+
const alpha = piece.alpha * piece.fade;
|
|
516
|
+
if (alpha <= ALPHA_FLOOR) continue;
|
|
517
|
+
|
|
518
|
+
if (piece.depth === DEPTH_NEAR && piece.pace > STREAK_SPEED && piece.shape !== 'sequin') {
|
|
519
|
+
ctx.globalAlpha = alpha * STREAK_ALPHA;
|
|
520
|
+
ctx.strokeStyle = palette.front[piece.slot];
|
|
521
|
+
ctx.lineWidth = Math.max(STREAK_STROKE_FLOOR, piece.width * STREAK_WIDTH);
|
|
522
|
+
ctx.beginPath();
|
|
523
|
+
ctx.moveTo(piece.x, piece.y);
|
|
524
|
+
ctx.lineTo(piece.x - piece.vx * STREAK_REACH, piece.y - piece.vy * STREAK_REACH);
|
|
525
|
+
ctx.stroke();
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
ctx.globalAlpha = alpha;
|
|
529
|
+
ctx.save();
|
|
530
|
+
ctx.translate(piece.x, piece.y);
|
|
531
|
+
ctx.rotate(piece.spin);
|
|
532
|
+
const tone =
|
|
533
|
+
face < SPECULAR_EDGE
|
|
534
|
+
? palette.sheen[piece.slot]
|
|
535
|
+
: facing > 0
|
|
536
|
+
? palette.front[piece.slot]
|
|
537
|
+
: palette.reverse[piece.slot];
|
|
538
|
+
if (piece.shape === 'flake') drawFlake(ctx, piece, tone);
|
|
539
|
+
else if (piece.shape === 'curl') drawCurl(ctx, piece, tone);
|
|
540
|
+
else if (piece.shape === 'ribbon') drawRibbon(ctx, piece, palette);
|
|
541
|
+
else drawSequin(ctx, piece, palette);
|
|
542
|
+
ctx.restore();
|
|
543
|
+
}
|
|
544
|
+
ctx.globalAlpha = 1;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
function fit(stage: Stage) {
|
|
548
|
+
const box = stage.canvas.getBoundingClientRect();
|
|
549
|
+
if (!box.width || !box.height) return;
|
|
550
|
+
stage.width = box.width;
|
|
551
|
+
stage.height = box.height;
|
|
552
|
+
stage.size = clamp(Math.sqrt(box.width * box.height) / SCALE_REFERENCE, SCALE_MIN, SCALE_MAX);
|
|
553
|
+
const ratio = Math.min(PIXEL_RATIO_CAP, window.devicePixelRatio || 1);
|
|
554
|
+
const width = Math.round(box.width * ratio);
|
|
555
|
+
const height = Math.round(box.height * ratio);
|
|
556
|
+
if (stage.canvas.width !== width || stage.canvas.height !== height) {
|
|
557
|
+
stage.canvas.width = width;
|
|
558
|
+
stage.canvas.height = height;
|
|
559
|
+
}
|
|
560
|
+
stage.ctx.setTransform(ratio, 0, 0, ratio, 0, 0);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
function halt(stage: Stage) {
|
|
564
|
+
stage.pieces.length = 0;
|
|
565
|
+
stage.runs.length = 0;
|
|
566
|
+
stage.clock = 0;
|
|
567
|
+
stage.ctx.clearRect(0, 0, stage.width, stage.height);
|
|
568
|
+
stage.playback?.stop();
|
|
569
|
+
stage.playback = null;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
export interface ConfettiFireOptions {
|
|
573
|
+
/** Pieces this burst sends, clamped to 1-520. Falls back to the `count` prop. */
|
|
574
|
+
count?: number;
|
|
575
|
+
/** Seconds this burst's emitter stays open, clamped to 0-10. Falls back to the `duration` prop. */
|
|
576
|
+
duration?: number;
|
|
577
|
+
/** Emitter geometry for this burst. Falls back to the `emitter` prop. */
|
|
578
|
+
emitter?: ConfettiEmitter;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
export interface ConfettiHandle {
|
|
582
|
+
/** Sends one burst. Bursts coexist - firing again while pieces are still airborne adds to the field rather than replacing it. */
|
|
583
|
+
fire: (options?: ConfettiFireOptions) => void;
|
|
584
|
+
/** Empties the field and stops the simulation immediately. */
|
|
585
|
+
clear: () => void;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
export interface ConfettiOwnProps {
|
|
589
|
+
/** Where pieces are launched from: two side cannons, a full-width fall, or two floor-corner cannons. @default 'sides' */
|
|
590
|
+
emitter?: ConfettiEmitter;
|
|
591
|
+
/** Pieces one fire sends, clamped to 1-520. The field itself holds 520; beyond that the oldest piece is retired. @default 170 */
|
|
592
|
+
count?: number;
|
|
593
|
+
/** Seconds the emitter stays open, clamped to 0-10. Pieces leave front-loaded inside that window, so 0.15 reads as one shove and 2.5 as a burst that tapers into a fall. @default 0.15 */
|
|
594
|
+
duration?: number;
|
|
595
|
+
/** Multiplies the simulation rate; sampled live on every frame. @default 1 */
|
|
596
|
+
speed?: number;
|
|
597
|
+
/** `container` fills the nearest positioned ancestor; `viewport` portals the canvas to the body and pins it to the window above the toast layer, so a transformed ancestor cannot trap it. Switching field remounts the canvas and drops pieces in flight. @default 'container' */
|
|
598
|
+
field?: ConfettiField;
|
|
599
|
+
/** Imperative handle - call `fire()` on it to send a burst, `clear()` to empty the field. */
|
|
600
|
+
ref?: Ref<ConfettiHandle>;
|
|
601
|
+
/** Extra class(es) merged onto the canvas. */
|
|
602
|
+
className?: string;
|
|
603
|
+
/** Inline styles merged onto the canvas. */
|
|
604
|
+
style?: ConfettiStyle;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
export interface ConfettiProps extends ConfettiOwnProps {
|
|
608
|
+
/** Standard <canvas> attributes (aria-*, data-*, title, ...) forwarded to the canvas. */
|
|
609
|
+
htmlProps?: Omit<HTMLAttributes<HTMLCanvasElement>, keyof ConfettiOwnProps> & DataAttributes;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
export function Confetti({
|
|
613
|
+
emitter = 'sides',
|
|
614
|
+
count = DEFAULT_COUNT,
|
|
615
|
+
duration = DEFAULT_DURATION,
|
|
616
|
+
speed = 1,
|
|
617
|
+
field = 'container',
|
|
618
|
+
ref,
|
|
619
|
+
className = '',
|
|
620
|
+
style,
|
|
621
|
+
htmlProps,
|
|
622
|
+
}: ConfettiProps) {
|
|
623
|
+
const canvasRef = useRef<HTMLCanvasElement>(null);
|
|
624
|
+
const stageRef = useRef<Stage | null>(null);
|
|
625
|
+
const settingsRef = useRef({ emitter, count, duration, speed });
|
|
626
|
+
const hydrated = useSyncExternalStore(
|
|
627
|
+
subscribeToNothing,
|
|
628
|
+
() => true,
|
|
629
|
+
() => false,
|
|
630
|
+
);
|
|
631
|
+
|
|
632
|
+
useEffect(() => {
|
|
633
|
+
settingsRef.current = { emitter, count, duration, speed };
|
|
634
|
+
}, [emitter, count, duration, speed]);
|
|
635
|
+
|
|
636
|
+
useEffect(() => {
|
|
637
|
+
const canvas = canvasRef.current;
|
|
638
|
+
const ctx = canvas?.getContext('2d');
|
|
639
|
+
if (!canvas || !ctx) return;
|
|
640
|
+
|
|
641
|
+
const stage: Stage = {
|
|
642
|
+
canvas,
|
|
643
|
+
ctx,
|
|
644
|
+
width: 0,
|
|
645
|
+
height: 0,
|
|
646
|
+
size: 1,
|
|
647
|
+
pieces: [],
|
|
648
|
+
runs: [],
|
|
649
|
+
clock: 0,
|
|
650
|
+
palette: readPalette(canvas, null),
|
|
651
|
+
playback: null,
|
|
652
|
+
};
|
|
653
|
+
stageRef.current = stage;
|
|
654
|
+
fit(stage);
|
|
655
|
+
|
|
656
|
+
const resizes = new ResizeObserver(() => fit(stage));
|
|
657
|
+
resizes.observe(canvas);
|
|
658
|
+
|
|
659
|
+
return () => {
|
|
660
|
+
resizes.disconnect();
|
|
661
|
+
stage.playback?.stop();
|
|
662
|
+
stage.playback = null;
|
|
663
|
+
stageRef.current = null;
|
|
664
|
+
};
|
|
665
|
+
}, [field, hydrated]);
|
|
666
|
+
|
|
667
|
+
useImperativeHandle(
|
|
668
|
+
ref,
|
|
669
|
+
() => ({
|
|
670
|
+
fire(options?: ConfettiFireOptions) {
|
|
671
|
+
const stage = stageRef.current;
|
|
672
|
+
if (!stage) return;
|
|
673
|
+
fit(stage);
|
|
674
|
+
if (!stage.width || !stage.height) return;
|
|
675
|
+
const settings = settingsRef.current;
|
|
676
|
+
stage.palette = readPalette(stage.canvas, stage.palette);
|
|
677
|
+
stage.runs.push({
|
|
678
|
+
emitter: options?.emitter ?? settings.emitter,
|
|
679
|
+
total: pieceCount(options?.count ?? settings.count),
|
|
680
|
+
sent: 0,
|
|
681
|
+
elapsed: 0,
|
|
682
|
+
span: emitterSpan(options?.duration ?? settings.duration),
|
|
683
|
+
});
|
|
684
|
+
if (stage.playback) return;
|
|
685
|
+
let inert = false;
|
|
686
|
+
const playback = loop(
|
|
687
|
+
(_k, dt) => {
|
|
688
|
+
const step = dt / MS_PER_SECOND;
|
|
689
|
+
stage.clock += step;
|
|
690
|
+
emit(stage, step, stage.palette);
|
|
691
|
+
advance(stage, step);
|
|
692
|
+
paint(stage);
|
|
693
|
+
if (!stage.pieces.length && !stage.runs.length) halt(stage);
|
|
694
|
+
},
|
|
695
|
+
{
|
|
696
|
+
el: stage.canvas,
|
|
697
|
+
speed: () => settingsRef.current.speed,
|
|
698
|
+
snap: () => {
|
|
699
|
+
inert = true;
|
|
700
|
+
halt(stage);
|
|
701
|
+
},
|
|
702
|
+
},
|
|
703
|
+
);
|
|
704
|
+
stage.playback = inert ? null : playback;
|
|
705
|
+
},
|
|
706
|
+
clear() {
|
|
707
|
+
const stage = stageRef.current;
|
|
708
|
+
if (stage) halt(stage);
|
|
709
|
+
},
|
|
710
|
+
}),
|
|
711
|
+
[],
|
|
712
|
+
);
|
|
713
|
+
|
|
714
|
+
const canvas = (
|
|
715
|
+
<canvas
|
|
716
|
+
ref={canvasRef}
|
|
717
|
+
className={cx('confetti', field === 'viewport' && VIEWPORT_CLASS, className)}
|
|
718
|
+
style={style}
|
|
719
|
+
aria-hidden="true"
|
|
720
|
+
{...htmlProps}
|
|
721
|
+
/>
|
|
722
|
+
);
|
|
723
|
+
|
|
724
|
+
if (field !== 'viewport') return canvas;
|
|
725
|
+
if (!hydrated) return null;
|
|
726
|
+
return createPortal(canvas, document.body);
|
|
727
|
+
}
|