@vite-hub/ui 0.6.1 → 0.8.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 +106 -46
- package/dist/AttachmentTitle-BWw0ck0T.js +110 -0
- package/dist/BubbleContent-B1a4e3vE.js +45 -0
- package/dist/Chat-CuSthJVg.js +112 -0
- package/dist/ChatMessage-CFQs0v4N.js +94 -0
- package/dist/CodeBlockContent-BjXJm8lO.js +92 -0
- package/dist/CodeBlockTitle-DIu8Ef3V.js +99 -0
- package/dist/CommentRow-XY3FNp30.js +86 -0
- package/dist/CopyButton-Bs6DT-Z8.js +188 -0
- package/dist/Markdown-Da5t-931.js +70 -0
- package/dist/MarkdownCodeBlock-BWDLOWPO.js +127 -0
- package/dist/MarkdownImage-CJN3myt4.js +111 -0
- package/dist/MessageHeader-CJ9eBHSS.js +61 -0
- package/dist/MessageParts-CyJLG34y.js +57 -0
- package/dist/MessageScrollerViewport-BaTlWLki.js +142 -0
- package/dist/MorphText-B6MWdeIv.js +36 -0
- package/dist/RollNumber-CnF52zJM.js +49 -0
- package/dist/SwapIcon-CUIq1TU5.js +67 -0
- package/dist/TraceTitle-Cp0y7RRD.js +133 -0
- package/dist/agent-session-2j2gbGpp.js +875 -0
- package/dist/agent-session-BwZSMi4S.d.ts +312 -0
- package/dist/appendItems-hQ4aBd9Q.js +4047 -0
- package/dist/attachment-BllgHx9Q.d.ts +124 -0
- package/dist/attachment-DQMJNfj0.js +35 -0
- package/dist/avatar-stack-Bj1xUkzY.d.ts +4 -0
- package/dist/avatar-stack-CoLlsmwJ.js +72 -0
- package/dist/bubble-D3M2_InY.js +32 -0
- package/dist/bubble-DmplVxLr.d.ts +64 -0
- package/dist/chat-DWdyMSuj.d.ts +13 -0
- package/dist/chat-message-QLHnX_ED.d.ts +11 -0
- package/dist/chat-session-BOj5L3Ey.d.ts +29 -0
- package/dist/chat-session-cxUzvwdj.js +43 -0
- package/dist/choices-input-DqgXl5a-.d.ts +97 -0
- package/dist/{vue-d2Td6uu2.js → client-BG-oCUtv-5i4sRwXP.js} +4156 -4156
- package/dist/code-block-BqOEVWPh.d.ts +182 -0
- package/dist/code-block-CMERLfew.js +14 -0
- package/dist/code-view-26RY6dX8.js +137 -0
- package/dist/code-view-D8yYdFUc.d.ts +184 -0
- package/dist/{comment-composer-DmDM3XYP.d.ts → comment-composer-CsVOvG9j.d.ts} +6 -6
- package/dist/{comment-composer-X7vJKh5b.js → comment-composer-D_mcH3Ts.js} +175 -37
- package/dist/{comment-layer-KnnVfdRV.d.ts → comment-layer-C3xmg-0_.d.ts} +14 -5
- package/dist/comment-layer-Ci6ipGi2.js +1206 -0
- package/dist/{comment-panel-DoLDOw3E.d.ts → comment-panel-DxN21VoY.d.ts} +24 -17
- package/dist/comment-selection-bar-B_bchB2O.d.ts +33 -0
- package/dist/comment-selection-bar-DZAtiRZ9.js +144 -0
- package/dist/{comment-thread-DPV2kqA4.d.ts → comment-thread-BmsqcjVQ.d.ts} +9 -8
- package/dist/{comment-thread-jqPx6aJ8.js → comment-thread-BzOZVqF2.js} +74 -49
- package/dist/comments-BU8cTt5o.d.ts +50 -0
- package/dist/{comments-9MDSNm-9.js → comments-BaSrroRV.js} +32 -4
- package/dist/{comments-OWjNidkP.d.ts → comments-ZfV6IZs8.d.ts} +9 -2
- package/dist/components-B_2Q0dJ3.js +269 -0
- package/dist/{config-LRonN53j.js → config-BDQYUjjp.js} +10 -29
- package/dist/{config-COSdO-ay.d.ts → config-JmsTI7gs.d.ts} +20 -33
- package/dist/connection-status-BVSH2ZVo.js +72 -0
- package/dist/connection-status-g62BTn44.d.ts +37 -0
- package/dist/copy-button-CRiXUFsl.d.ts +17 -0
- package/dist/device-frame-BW6IjB6P.d.ts +78 -0
- package/dist/device-frame-DDWoyB-G.js +515 -0
- package/dist/diffs-BTKaVnsb.d.ts +272 -0
- package/dist/diffs.d.ts +3 -0
- package/dist/{pierre-code-view-C49BVDrc.js → diffs.js} +147 -4223
- package/dist/drop-field-C0bXv1J-.d.ts +35 -0
- package/dist/drop-field-DeIvKoJs.js +77 -0
- package/dist/editor-BsOTjnnN.d.ts +540 -0
- package/dist/{markdown-editor-D1irG9Xl.js → editor-hXea1i46.js} +833 -106
- package/dist/editor.d.ts +2 -0
- package/dist/editor.js +3 -0
- package/dist/element-BpjNQvZ0.js +6 -0
- package/dist/{file-tree-CRFIdtzw.js → file-tree-B4JKbp4r.js} +19 -18
- package/dist/{file-tree-DOtkeBaq.d.ts → file-tree-BdnKA6UA.d.ts} +33 -8
- package/dist/file-tree-DDSIafDn.d.ts +22 -0
- package/dist/file-tree-DS5shGSL.js +46 -0
- package/dist/file-tree.d.ts +2 -0
- package/dist/file-tree.js +1 -0
- package/dist/files-cuVXzWlx.js +30 -0
- package/dist/filter-search-C9e6sGij.d.ts +28 -0
- package/dist/filter-search-COZsoRiR.js +73 -0
- package/dist/formatCSSVariablePrefix-DLS1Ed1_.js +5 -0
- package/dist/headless-2IcUWHMq.d.ts +51 -0
- package/dist/headless.d.ts +7 -4
- package/dist/headless.js +5 -3
- package/dist/highlight.d.ts +2 -0
- package/dist/highlight.js +1 -0
- package/dist/{highlights-C2AbEdDI.js → highlights-8Al0-h-v.js} +3 -2
- package/dist/{hold-to-delete-BSMrpE-i.d.ts → hold-to-delete-CQc1JaG_.d.ts} +7 -0
- package/dist/{hold-to-delete-Cludb56v.js → hold-to-delete-D1Vy40w5.js} +138 -20
- package/dist/hold-to-delete-DazElJT2.js +85 -0
- package/dist/hold-to-delete-ksBE7wxc.d.ts +58 -0
- package/dist/index-CffOzibW.d.ts +77 -0
- package/dist/{index-B2cbt3py.d.ts → index-D3-uYBqH.d.ts} +1 -1
- package/dist/index.d.ts +165 -52
- package/dist/index.js +126 -670
- package/dist/markdown-BLALLOc0.d.ts +45 -0
- package/dist/{parts/components/markdown-renderer.d.ts → markdown-DkDxdpMU.d.ts} +10 -7
- package/dist/{markdown-renderer-DMyYKeil.js → markdown-_0HhbsOo.js} +125 -127
- package/dist/markdown-editor.d.ts +51 -98
- package/dist/markdown-editor.js +70 -3
- package/dist/markdown.d.ts +2 -0
- package/dist/markdown.js +1 -0
- package/dist/marker-CvcWZ3Zp.d.ts +59 -0
- package/dist/marker-DNL6QR3L.js +63 -0
- package/dist/message-BwivYIEl.js +13 -0
- package/dist/message-DEq4K5cQ.d.ts +72 -0
- package/dist/message-parts-B1BZFVKe.d.ts +3 -0
- package/dist/message-parts-CG3gNWn8.d.ts +11 -0
- package/dist/message-parts.d.ts +2 -0
- package/dist/message-parts.js +1 -0
- package/dist/message-scroller-D7AvM31v.d.ts +41 -0
- package/dist/motion/core.d.ts +4 -4
- package/dist/motion/core.js +5 -11
- package/dist/motion-BH6ShUam.d.ts +12 -0
- package/dist/{install-C4LwcJda.js → motion-BhARaNBB.js} +1 -1
- package/dist/{effects-C1zYpSpg.js → motion-core-JZZiPKEk.js} +1829 -120
- package/dist/{motion-core-Dh20n5Se.d.ts → motion-core-gfsTPLbh.d.ts} +35 -74
- package/dist/motion-list-9vD1hSS0.js +49 -0
- package/dist/motion.d.ts +5 -14
- package/dist/motion.js +6 -13
- package/dist/nuxt-ui-D3Qda35W.js +22 -0
- package/dist/nuxt.d.ts +9 -5
- package/dist/nuxt.js +28 -33
- package/dist/parts/components/agent-session.d.ts +2 -295
- package/dist/parts/components/agent-session.js +1 -659
- package/dist/parts/components/attachment.d.ts +2 -85
- package/dist/parts/components/attachment.js +3 -72
- package/dist/parts/components/avatar-stack.d.ts +3 -2
- package/dist/parts/components/avatar-stack.js +1 -60
- package/dist/parts/components/bubble.d.ts +2 -69
- package/dist/parts/components/bubble.js +3 -52
- package/dist/parts/components/chat-message.d.ts +3 -25
- package/dist/parts/components/chat-message.js +1 -50
- package/dist/parts/components/chat-session.d.ts +2 -26
- package/dist/parts/components/chat-session.js +1 -37
- package/dist/parts/components/chat.d.ts +3 -52
- package/dist/parts/components/chat.js +1 -105
- package/dist/parts/components/code-block.d.ts +2 -102
- package/dist/parts/components/code-block.js +4 -109
- package/dist/parts/components/code-view.d.ts +3 -268
- package/dist/parts/components/code-view.js +1 -1
- package/dist/parts/components/comment-composer.d.ts +1 -1
- package/dist/parts/components/comment-composer.js +1 -1
- package/dist/parts/components/comment-layer.d.ts +1 -1
- package/dist/parts/components/comment-layer.js +1 -634
- package/dist/parts/components/comment-panel.d.ts +2 -2
- package/dist/parts/components/comment-panel.js +22 -16
- package/dist/parts/components/comment-selection-bar.d.ts +2 -2
- package/dist/parts/components/comment-selection-bar.js +1 -116
- package/dist/parts/components/comment-thread.d.ts +1 -1
- package/dist/parts/components/comment-thread.js +1 -3
- package/dist/parts/components/comments.d.ts +8 -9
- package/dist/parts/components/comments.js +5 -9
- package/dist/parts/components/connection-status.d.ts +2 -36
- package/dist/parts/components/connection-status.js +1 -64
- package/dist/parts/components/copy-button.d.ts +3 -126
- package/dist/parts/components/copy-button.js +1 -226
- package/dist/parts/components/device-frame.d.ts +2 -128
- package/dist/parts/components/device-frame.js +1 -470
- package/dist/parts/components/drop-field.d.ts +2 -67
- package/dist/parts/components/drop-field.js +1 -76
- package/dist/parts/components/file-tree.d.ts +3 -2
- package/dist/parts/components/file-tree.js +3 -1
- package/dist/parts/components/filter-search.d.ts +2 -45
- package/dist/parts/components/filter-search.js +1 -57
- package/dist/parts/components/hold-to-delete.d.ts +2 -80
- package/dist/parts/components/hold-to-delete.js +1 -75
- package/dist/parts/components/markdown.d.ts +3 -45
- package/dist/parts/components/markdown.js +1 -46
- package/dist/parts/components/marker.d.ts +2 -32
- package/dist/parts/components/marker.js +1 -22
- package/dist/parts/components/message-parts.d.ts +3 -25
- package/dist/parts/components/message-parts.js +1 -45
- package/dist/parts/components/message.d.ts +2 -32
- package/dist/parts/components/message.js +3 -22
- package/dist/parts/components/motion-list.d.ts +2 -40
- package/dist/parts/components/motion-list.js +1 -41
- package/dist/parts/components/motion.d.ts +5 -118
- package/dist/parts/components/motion.js +5 -163
- package/dist/parts/components/patch-parsers.d.ts +1 -1
- package/dist/parts/components/progress.d.ts +2 -39
- package/dist/parts/components/progress.js +1 -53
- package/dist/parts/components/prompt-input.d.ts +2 -134
- package/dist/parts/components/prompt-input.js +1 -253
- package/dist/parts/components/relative-time.d.ts +2 -71
- package/dist/parts/components/relative-time.js +1 -1
- package/dist/parts/components/status.d.ts +2 -58
- package/dist/parts/components/status.js +1 -47
- package/dist/parts/components/sync-status.d.ts +2 -22
- package/dist/parts/components/sync-status.js +1 -48
- package/dist/parts/components/tool-list.d.ts +2 -28
- package/dist/parts/components/tool-list.js +1 -118
- package/dist/parts/components/trace-run.d.ts +2 -25
- package/dist/parts/components/trace-run.js +1 -89
- package/dist/parts/components/trace.d.ts +2 -59
- package/dist/parts/components/trace.js +1 -76
- package/dist/parts/composables/attachments.js +75 -1
- package/dist/parts/headless/choices-input.d.ts +2 -2
- package/dist/parts/headless/choices-input.js +49 -37
- package/dist/parts/headless/comments.d.ts +1 -1
- package/dist/parts/headless/comments.js +1 -1
- package/dist/parts/headless/message-scroller.d.ts +2 -2
- package/dist/parts/headless/message-scroller.js +211 -309
- package/dist/parts/headless/relative-time.d.ts +2 -0
- package/dist/parts/headless/relative-time.js +1 -0
- package/dist/parts/workspace/browser-support-notice.d.ts +1 -1
- package/dist/parts/workspace/browser-support-notice.js +6 -5
- package/dist/parts/workspace/connect-panel.js +1 -1
- package/dist/parts/workspace/runners/web-container.js +2 -2
- package/dist/parts/workspace/workspace-bar.d.ts +1 -1
- package/dist/parts/workspace/workspace-bar.js +1 -1
- package/dist/parts/workspace/workspace-boot-status.d.ts +1 -1
- package/dist/parts/workspace/workspace-boot-status.js +1 -206
- package/dist/parts/workspace/workspace-editor-head.d.ts +1 -1
- package/dist/parts/workspace/workspace-editor-head.js +1 -1
- package/dist/parts/workspace/workspace-editor.d.ts +2 -2
- package/dist/parts/workspace/workspace-examples.js +1 -1
- package/dist/parts/workspace/workspace-file-tree.d.ts +1 -1
- package/dist/parts/workspace/workspace-file-tree.js +3 -2
- package/dist/parts/workspace/workspace-guide.d.ts +1 -1
- package/dist/parts/workspace/workspace-guide.js +1 -1
- package/dist/parts/workspace/workspace-preview.d.ts +1 -1
- package/dist/parts/workspace/workspace-preview.js +14 -12
- package/dist/parts/workspace/workspace-shell.d.ts +1 -1
- package/dist/parts/workspace/workspace-shell.js +11 -11
- package/dist/parts/workspace/workspace-sidebar.d.ts +2 -2
- package/dist/parts/workspace/workspace-sidebar.js +2 -2
- package/dist/parts/workspace/workspace-start.d.ts +1 -1
- package/dist/parts/workspace/workspace-start.js +1 -1
- package/dist/parts/workspace/workspace-steps.js +1 -1
- package/dist/parts/workspace/workspace.d.ts +3 -3
- package/dist/parts/workspace/workspace.js +5 -5
- package/dist/press-BuEC-XvZ.d.ts +83 -0
- package/dist/progress-8P8RLYMy.js +47 -0
- package/dist/progress-Ch0fA-bf.d.ts +8 -0
- package/dist/prompt-input-CRXEJBAK.js +412 -0
- package/dist/prompt-input-j4OFTF5p.d.ts +116 -0
- package/dist/relative-time-BnJfjeEm.js +131 -0
- package/dist/relative-time-BuP-Gvzn.d.ts +43 -0
- package/dist/{relative-time-DJnw45tr.js → relative-time-Dz2DR4eb.js} +64 -114
- package/dist/relative-time-grHFu1kY.d.ts +11 -0
- package/dist/{ring-GaJsg32c.js → ring-B0nZBnU0.js} +1 -2
- package/dist/runtime/nuxt-plugin.js +2 -5
- package/dist/{shiki-CbfEu_Az.js → shiki-CxzM_xNo.js} +3 -2
- package/dist/stand-ins-CuKM1UH1.js +339 -0
- package/dist/status-B2Yhrwv8.js +67 -0
- package/dist/status-ySiRa-8O.d.ts +38 -0
- package/dist/{stream-tokenizer-ByC3l0HQ.js → stream-tokenizer-BsjV6wxW.js} +1 -1
- package/dist/styles.css +4348 -3410
- package/dist/sync-status-B29eG_n-.js +59 -0
- package/dist/sync-status-D4KdGO6y.d.ts +35 -0
- package/dist/theme.css +3 -0
- package/dist/theme.d.ts +14 -0
- package/dist/theme.js +19 -8
- package/dist/{themes-DKugPHlg.js → themes-B0_ioVT0.js} +1 -1
- package/dist/tool-list-DDaCqpR6.js +209 -0
- package/dist/tool-list-DMRPM0Yi.d.ts +50 -0
- package/dist/trace-KCBvOsw_.d.ts +113 -0
- package/dist/trace-run-Dk962P5a.d.ts +49 -0
- package/dist/trace-run-nh6FIsl6.js +202 -0
- package/dist/{opt-out-D66l60sg.js → tween-1W-LlKk9.js} +65 -2
- package/dist/types-CMU8Vmew.d.ts +71 -0
- package/dist/types-CTk3aNb5.d.ts +15 -0
- package/dist/types-D0a3i4Fw.d.ts +21 -0
- package/dist/types-DTecvcsZ.d.ts +35 -0
- package/dist/types-D_BWab7g.d.ts +75 -0
- package/dist/types-RHaQ4gj1.d.ts +27 -0
- package/dist/ui-components-CKQAPI-W.js +7 -0
- package/dist/unwrapDefault-CExq-4rm.js +5 -0
- package/dist/utils-hi9-xROt.js +37 -0
- package/dist/vite.d.ts +0 -1
- package/dist/vite.js +8 -14
- package/dist/{vue-vUGpdMct.js → vue-BdA18K5-.js} +1 -1
- package/dist/workspace-boot-status-CyGlJS06.js +216 -0
- package/dist/{workspace-shell-ChCwWPyv.d.ts → workspace-shell-B4A7CINd.d.ts} +1 -1
- package/dist/workspace.d.ts +1 -1
- package/dist/workspace.js +1 -2
- package/package.json +46 -15
- package/dist/announce-B0DLwflT.js +0 -31
- package/dist/attachments-DgwoQZKY.js +0 -88
- package/dist/avatar-stack-C0IKwj6g.d.ts +0 -57
- package/dist/choices-input-BUf-QqGj.d.ts +0 -92
- package/dist/code-view-Cg4nyTNA.js +0 -172
- package/dist/comment-attachments-DAzUbRmJ.js +0 -23
- package/dist/comment-list-ncwaCSVX.d.ts +0 -60
- package/dist/comment-person-D_IyIjXo.js +0 -39
- package/dist/comment-pin-hBJFiSYW.d.ts +0 -66
- package/dist/comment-row-DPMWI5Z0.js +0 -38
- package/dist/comment-selection-bar-CVuS-FNL.d.ts +0 -40
- package/dist/comment-send-CUkL3TbZ.js +0 -275
- package/dist/comment-send-MmxFsOQf.d.ts +0 -23
- package/dist/comment-send.css +0 -267
- package/dist/comment-status-nsCdrRk_.js +0 -20
- package/dist/drop-field-CNZgwFVO.js +0 -162
- package/dist/editor-Dmk3k6f6.js +0 -620
- package/dist/format-CPipR1FP.js +0 -19
- package/dist/handlers-CnbkvXjX.js +0 -181
- package/dist/icon-XZaCUZTG.d.ts +0 -29
- package/dist/image-preview-BKVUtfwQ.js +0 -104
- package/dist/index-B_PSX-5h.d.ts +0 -69
- package/dist/list-DUTAo0uC.js +0 -270
- package/dist/markdown-editor-B7gD60tp.d.ts +0 -189
- package/dist/message-scroller-BZqS63IX.d.ts +0 -173
- package/dist/nuxt-ui-7ByUrymx.js +0 -43
- package/dist/parts/components/comment-list.d.ts +0 -2
- package/dist/parts/components/comment-list.js +0 -173
- package/dist/parts/components/comment-pin.d.ts +0 -2
- package/dist/parts/components/comment-pin.js +0 -74
- package/dist/parts/components/comment-send.d.ts +0 -2
- package/dist/parts/components/comment-send.js +0 -1
- package/dist/parts/components/markdown-editor.d.ts +0 -2
- package/dist/parts/components/markdown-editor.js +0 -1
- package/dist/parts/components/markdown-renderer.js +0 -1
- package/dist/payload-text-DQNRbJY5.js +0 -31
- package/dist/progress-DL9k-ERG.js +0 -265
- package/dist/registry-DAIjCjWd.js +0 -77
- package/dist/slot-part-BWHvQ3mK.js +0 -25
- package/dist/text-gacox6bp.js +0 -822
- package/dist/travel-BliEidau.js +0 -180
- package/dist/tween-Dv3IIIQG.js +0 -61
- package/dist/types-Ceh7h7NT.d.ts +0 -31
- package/dist/visual-copy-CHHBfJ6O.js +0 -14
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
import {
|
|
3
|
-
import { a as
|
|
4
|
-
import { a as isOwnNode, c as own } from "./ring-GaJsg32c.js";
|
|
1
|
+
import { a as tween, c as createSpring, f as springs, h as prefersReducedMotion, i as playTween, l as getMotionSlowFactor, m as onReducedMotionChange, n as easeIn, o as isMotionOff, r as easeOut, t as cubicBezier, u as onEachFrame } from "./tween-1W-LlKk9.js";
|
|
2
|
+
import { a as defineOwnEffect, c as motionEffectRegistrations, d as otherMotionLayer, f as writeMotionStyle, l as motionStateAttributes, n as visualCopy, o as handOffMotionEffects, r as claimMotionLayer, s as listMotionEffects, u as onMotionEffectsChange } from "./hold-to-delete-D1Vy40w5.js";
|
|
3
|
+
import { a as isOwnNode, c as own, i as glyphNode, l as reduced, n as frameOf$2, o as motionSkipped, r as glyphMotionSkipped, s as openFrame, u as setText } from "./ring-B0nZBnU0.js";
|
|
5
4
|
// src/motion/effects/divider.ts
|
|
6
5
|
const springBack = {
|
|
7
6
|
stiffness: 500,
|
|
8
7
|
damping: 14
|
|
9
8
|
};
|
|
10
|
-
const reach = 60;
|
|
9
|
+
const reach$1 = 60;
|
|
11
10
|
const inset = 40;
|
|
12
|
-
const svgNamespace$
|
|
11
|
+
const svgNamespace$2 = "http://www.w3.org/2000/svg";
|
|
13
12
|
const rekaDragAttribute = "data-resize-handle-active";
|
|
14
13
|
const bends = /* @__PURE__ */ new WeakMap();
|
|
15
14
|
function axisOf$1(handle, rect) {
|
|
@@ -42,7 +41,7 @@ function lineOf(handle, axis) {
|
|
|
42
41
|
width: 1
|
|
43
42
|
};
|
|
44
43
|
}
|
|
45
|
-
function draw$
|
|
44
|
+
function draw$5(bend, amount) {
|
|
46
45
|
const { handle, axis, line } = bend;
|
|
47
46
|
if (Math.abs(amount) < .5 && !bend.spring.active) {
|
|
48
47
|
bend.lane?.svg.remove();
|
|
@@ -51,11 +50,11 @@ function draw$4(bend, amount) {
|
|
|
51
50
|
return;
|
|
52
51
|
}
|
|
53
52
|
if (!bend.lane) {
|
|
54
|
-
const svg = document.createElementNS(svgNamespace$
|
|
53
|
+
const svg = document.createElementNS(svgNamespace$2, "svg");
|
|
55
54
|
svg.setAttribute("aria-hidden", "true");
|
|
56
55
|
svg.dataset.motion = "bend";
|
|
57
56
|
svg.style.cssText = "position:absolute;left:0;top:0;width:1px;height:1px;overflow:visible;pointer-events:none;z-index:1";
|
|
58
|
-
const path = document.createElementNS(svgNamespace$
|
|
57
|
+
const path = document.createElementNS(svgNamespace$2, "path");
|
|
59
58
|
path.setAttribute("fill", "none");
|
|
60
59
|
path.style.stroke = line.color;
|
|
61
60
|
path.style.strokeWidth = `${line.width}px`;
|
|
@@ -121,7 +120,7 @@ const divider = {
|
|
|
121
120
|
axis,
|
|
122
121
|
line: lineOf(handle, axis),
|
|
123
122
|
at: across(event),
|
|
124
|
-
spring: createSpring(0, (value) => draw$
|
|
123
|
+
spring: createSpring(0, (value) => draw$5(current, value), springBack)
|
|
125
124
|
};
|
|
126
125
|
bend = current;
|
|
127
126
|
bends.set(handle, bend);
|
|
@@ -136,7 +135,7 @@ const divider = {
|
|
|
136
135
|
const zoom = handle.offsetHeight ? box.height / handle.offsetHeight || 1 : 1;
|
|
137
136
|
const over = (along(pointer) - grab - center(box)) / zoom;
|
|
138
137
|
active.at = across(pointer);
|
|
139
|
-
active.spring.set(Math.abs(over) < 1 ? 0 : over / (1 + Math.abs(over) / reach));
|
|
138
|
+
active.spring.set(Math.abs(over) < 1 ? 0 : over / (1 + Math.abs(over) / reach$1));
|
|
140
139
|
};
|
|
141
140
|
return {
|
|
142
141
|
move(next) {
|
|
@@ -566,6 +565,152 @@ function pinGhost(ghost, rect) {
|
|
|
566
565
|
function after(ms, callback) {
|
|
567
566
|
return window.setTimeout(callback, ms * getMotionSlowFactor());
|
|
568
567
|
}
|
|
568
|
+
// src/motion/effects/icon-shape.ts
|
|
569
|
+
const svgNamespace$1 = "http://www.w3.org/2000/svg";
|
|
570
|
+
const geometry = /* @__PURE__ */ new Map([
|
|
571
|
+
["path", ["d"]],
|
|
572
|
+
["line", [
|
|
573
|
+
"x1",
|
|
574
|
+
"y1",
|
|
575
|
+
"x2",
|
|
576
|
+
"y2"
|
|
577
|
+
]],
|
|
578
|
+
["polyline", ["points"]],
|
|
579
|
+
["polygon", ["points"]],
|
|
580
|
+
["circle", [
|
|
581
|
+
"cx",
|
|
582
|
+
"cy",
|
|
583
|
+
"r"
|
|
584
|
+
]],
|
|
585
|
+
["ellipse", [
|
|
586
|
+
"cx",
|
|
587
|
+
"cy",
|
|
588
|
+
"rx",
|
|
589
|
+
"ry"
|
|
590
|
+
]],
|
|
591
|
+
["rect", [
|
|
592
|
+
"x",
|
|
593
|
+
"y",
|
|
594
|
+
"width",
|
|
595
|
+
"height",
|
|
596
|
+
"rx",
|
|
597
|
+
"ry"
|
|
598
|
+
]]
|
|
599
|
+
]);
|
|
600
|
+
const shapeSelector = [...geometry.keys()].join(", ");
|
|
601
|
+
/** The icons inside an element: inline `<svg>` elements, and Iconify CSS icons. */
|
|
602
|
+
function findIcons(element) {
|
|
603
|
+
const icons = [];
|
|
604
|
+
for (const node of element.querySelectorAll("svg, .iconify")) {
|
|
605
|
+
if (node instanceof SVGSVGElement && node.parentElement?.closest("svg")) continue;
|
|
606
|
+
if (node instanceof SVGSVGElement || cssIconSource(node)) icons.push(node);
|
|
607
|
+
}
|
|
608
|
+
return icons;
|
|
609
|
+
}
|
|
610
|
+
function cssIconSource(element) {
|
|
611
|
+
const value = getComputedStyle(element).getPropertyValue("--svg").trim();
|
|
612
|
+
const url = /^url\(\s*(["']?)(.*)\1\s*\)$/s.exec(value)?.[2];
|
|
613
|
+
if (!url?.startsWith("data:image/svg+xml")) return;
|
|
614
|
+
const comma = url.indexOf(",");
|
|
615
|
+
const data = url.slice(comma + 1);
|
|
616
|
+
try {
|
|
617
|
+
return url.slice(0, comma).endsWith(";base64") ? atob(data) : decodeURIComponent(data);
|
|
618
|
+
} catch {
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
function editor(shapes) {
|
|
623
|
+
const originals = /* @__PURE__ */ new Map();
|
|
624
|
+
return {
|
|
625
|
+
set(shape, name, value) {
|
|
626
|
+
let kept = originals.get(shape);
|
|
627
|
+
if (!kept) originals.set(shape, kept = /* @__PURE__ */ new Map());
|
|
628
|
+
if (!kept.has(name)) kept.set(name, shape.getAttribute(name));
|
|
629
|
+
shape.setAttribute(name, value);
|
|
630
|
+
},
|
|
631
|
+
putBack() {
|
|
632
|
+
for (const [shape, kept] of originals) for (const [name, value] of kept) if (value === null) shape.removeAttribute(name);
|
|
633
|
+
else shape.setAttribute(name, value);
|
|
634
|
+
originals.clear();
|
|
635
|
+
},
|
|
636
|
+
shapes
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
/** The shapes of an icon from `findIcons`, or undefined when it has none. */
|
|
640
|
+
function iconShape(icon) {
|
|
641
|
+
if (icon instanceof SVGSVGElement) {
|
|
642
|
+
const { set, putBack, shapes } = editor([...icon.querySelectorAll(shapeSelector)]);
|
|
643
|
+
if (!shapes.length) return;
|
|
644
|
+
return {
|
|
645
|
+
shapes,
|
|
646
|
+
set,
|
|
647
|
+
commit() {},
|
|
648
|
+
restore: putBack,
|
|
649
|
+
measure: (read) => read(shapes)
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
const source = cssIconSource(icon);
|
|
653
|
+
if (!source) return;
|
|
654
|
+
const svg = new DOMParser().parseFromString(source, "image/svg+xml").documentElement;
|
|
655
|
+
if (!(svg instanceof SVGSVGElement)) return;
|
|
656
|
+
if (svg.matches("[style], [class], [transform]")) return;
|
|
657
|
+
const copies = [];
|
|
658
|
+
const originals = [];
|
|
659
|
+
for (const child of svg.children) {
|
|
660
|
+
const attributes = geometry.get(child.localName);
|
|
661
|
+
if (!attributes || !(child instanceof SVGGeometryElement) || child.childElementCount || child.matches("[style], [class], [transform]")) return;
|
|
662
|
+
const copy = document.createElementNS(svgNamespace$1, child.localName);
|
|
663
|
+
if (!(copy instanceof SVGGeometryElement)) return;
|
|
664
|
+
for (const name of attributes) {
|
|
665
|
+
const value = child.getAttribute(name);
|
|
666
|
+
if (value !== null) copy.setAttribute(name, value);
|
|
667
|
+
}
|
|
668
|
+
copies.push(copy);
|
|
669
|
+
originals.push(child);
|
|
670
|
+
}
|
|
671
|
+
if (!copies.length) return;
|
|
672
|
+
const { set, putBack, shapes } = editor(originals);
|
|
673
|
+
const readMask = () => ({
|
|
674
|
+
value: icon.style.getPropertyValue("--svg"),
|
|
675
|
+
priority: icon.style.getPropertyPriority("--svg")
|
|
676
|
+
});
|
|
677
|
+
const original = readMask();
|
|
678
|
+
let written;
|
|
679
|
+
const matchesMask = (expected) => {
|
|
680
|
+
const current = readMask();
|
|
681
|
+
return expected.value === current.value && expected.priority === current.priority;
|
|
682
|
+
};
|
|
683
|
+
return {
|
|
684
|
+
shapes,
|
|
685
|
+
set,
|
|
686
|
+
commit() {
|
|
687
|
+
if (!matchesMask(written ?? original)) return;
|
|
688
|
+
icon.style.setProperty("--svg", `url("data:image/svg+xml,${encodeURIComponent(new XMLSerializer().serializeToString(svg))}")`, original.priority);
|
|
689
|
+
written = readMask();
|
|
690
|
+
},
|
|
691
|
+
restore() {
|
|
692
|
+
putBack();
|
|
693
|
+
if (written && matchesMask(written)) {
|
|
694
|
+
const { value, priority } = original;
|
|
695
|
+
if (value) icon.style.setProperty("--svg", value, priority);
|
|
696
|
+
else icon.style.removeProperty("--svg");
|
|
697
|
+
}
|
|
698
|
+
written = void 0;
|
|
699
|
+
},
|
|
700
|
+
measure(read) {
|
|
701
|
+
const host = document.createElementNS(svgNamespace$1, "svg");
|
|
702
|
+
host.setAttribute("aria-hidden", "true");
|
|
703
|
+
host.style.cssText = "position:absolute;width:0;height:0;overflow:hidden;visibility:hidden";
|
|
704
|
+
host.append(...copies);
|
|
705
|
+
document.body.append(host);
|
|
706
|
+
try {
|
|
707
|
+
return read(copies);
|
|
708
|
+
} finally {
|
|
709
|
+
host.remove();
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
};
|
|
713
|
+
}
|
|
569
714
|
// src/motion/effects/check.ts
|
|
570
715
|
const checks = /* @__PURE__ */ new WeakMap();
|
|
571
716
|
function isOn$1(value) {
|
|
@@ -589,7 +734,7 @@ function keepGhost(check) {
|
|
|
589
734
|
check.ghost = ghost;
|
|
590
735
|
bind(check, findIcons(ghost)[0], ghost);
|
|
591
736
|
}
|
|
592
|
-
function draw$
|
|
737
|
+
function draw$4(check, value) {
|
|
593
738
|
keepGhost(check);
|
|
594
739
|
const drawn = Math.min(1, Math.max(0, value));
|
|
595
740
|
if (check.icon && !check.reduced) {
|
|
@@ -617,7 +762,7 @@ function checkOf(element, wasOn) {
|
|
|
617
762
|
const check = {
|
|
618
763
|
element,
|
|
619
764
|
drawn: createSpring(wasOn ? 1 : 0, (value) => {
|
|
620
|
-
if (check.drawn.active) draw$
|
|
765
|
+
if (check.drawn.active) draw$4(check, value);
|
|
621
766
|
else finish$1(check);
|
|
622
767
|
}),
|
|
623
768
|
icon: void 0,
|
|
@@ -654,7 +799,7 @@ const check = {
|
|
|
654
799
|
check.indicator = icon && childOf(element, icon);
|
|
655
800
|
if (isOn$1(oldValue)) check.drawn.set(0);
|
|
656
801
|
if (!bind(check, icon, check.reduced ? styleable(check.indicator) : void 0)) return;
|
|
657
|
-
draw$
|
|
802
|
+
draw$4(check, check.drawn.value);
|
|
658
803
|
check.drawn.to(1, options);
|
|
659
804
|
return;
|
|
660
805
|
}
|
|
@@ -667,7 +812,7 @@ const check = {
|
|
|
667
812
|
if (icon) check.indicator = childOf(element, icon);
|
|
668
813
|
if (!bind(check, icon, check.reduced ? styleable(check.indicator) : void 0) && !check.indicator) return;
|
|
669
814
|
check.drawn.to(0, options);
|
|
670
|
-
draw$
|
|
815
|
+
draw$4(check, check.drawn.value);
|
|
671
816
|
}
|
|
672
817
|
};
|
|
673
818
|
// src/motion/effects/disclosure.ts
|
|
@@ -699,7 +844,7 @@ function matrixDegrees(value) {
|
|
|
699
844
|
return Math.atan2(b, a) * 180 / Math.PI;
|
|
700
845
|
}
|
|
701
846
|
/** The angle that the stylesheet draws the icon at now, without what the effect wrote, split into its two sources. */
|
|
702
|
-
function measure$
|
|
847
|
+
function measure$3(icon) {
|
|
703
848
|
const written = icon.style.getPropertyValue("rotate");
|
|
704
849
|
if (written) icon.style.removeProperty("rotate");
|
|
705
850
|
const style = getComputedStyle(icon);
|
|
@@ -753,7 +898,7 @@ const disclosure = {
|
|
|
753
898
|
for (const icon of icons(trigger)) {
|
|
754
899
|
if (isMotionOff(icon) || transitionsTurn(icon)) continue;
|
|
755
900
|
const spring = turns.get(icon)?.spring;
|
|
756
|
-
angles.set(icon, spring?.active ? spring.target * quarter : measure$
|
|
901
|
+
angles.set(icon, spring?.active ? spring.target * quarter : measure$3(icon).total);
|
|
757
902
|
}
|
|
758
903
|
if (!angles.size) return;
|
|
759
904
|
pending$1.set(owner, angles);
|
|
@@ -781,7 +926,7 @@ const disclosure = {
|
|
|
781
926
|
}
|
|
782
927
|
const turn = turnOf(icon);
|
|
783
928
|
const from = turn.spring.active ? turn.spring.value * quarter : sampled;
|
|
784
|
-
const { total, base } = measure$
|
|
929
|
+
const { total, base } = measure$3(icon);
|
|
785
930
|
turn.base = base;
|
|
786
931
|
if (Math.abs(total - from) < .5) {
|
|
787
932
|
if (turn.spring.active) turn.spring.set(total / quarter);
|
|
@@ -889,6 +1034,522 @@ const jelly = {
|
|
|
889
1034
|
batch.set(element.parentElement, siblings);
|
|
890
1035
|
}
|
|
891
1036
|
};
|
|
1037
|
+
// src/motion/helpers/icon.ts
|
|
1038
|
+
const exit = {
|
|
1039
|
+
duration: 200,
|
|
1040
|
+
travel: 12,
|
|
1041
|
+
scale: .6,
|
|
1042
|
+
blur: 2
|
|
1043
|
+
};
|
|
1044
|
+
const enterBlur = {
|
|
1045
|
+
duration: 260,
|
|
1046
|
+
delay: 40,
|
|
1047
|
+
scale: .5,
|
|
1048
|
+
blur: 3,
|
|
1049
|
+
ease: cubicBezier(.3, 1.5, .5, 1)
|
|
1050
|
+
};
|
|
1051
|
+
const enterSlide = {
|
|
1052
|
+
duration: 260,
|
|
1053
|
+
delay: 80,
|
|
1054
|
+
travel: 10,
|
|
1055
|
+
ease: cubicBezier(.2, .8, .2, 1)
|
|
1056
|
+
};
|
|
1057
|
+
const draw$3 = {
|
|
1058
|
+
duration: 340,
|
|
1059
|
+
spinner: 420,
|
|
1060
|
+
delay: 120,
|
|
1061
|
+
ease: cubicBezier(.6, 0, .2, 1)
|
|
1062
|
+
};
|
|
1063
|
+
const crossfade$5 = 150;
|
|
1064
|
+
const directions = {
|
|
1065
|
+
left: [-1, 0],
|
|
1066
|
+
right: [1, 0],
|
|
1067
|
+
up: [0, -1],
|
|
1068
|
+
down: [0, 1]
|
|
1069
|
+
};
|
|
1070
|
+
const states = /* @__PURE__ */ new WeakMap();
|
|
1071
|
+
const positioned = /* @__PURE__ */ new WeakMap();
|
|
1072
|
+
function stateOf(icon) {
|
|
1073
|
+
let state = states.get(icon);
|
|
1074
|
+
if (!state) {
|
|
1075
|
+
state = {
|
|
1076
|
+
shown: 1,
|
|
1077
|
+
leaving: false
|
|
1078
|
+
};
|
|
1079
|
+
states.set(icon, state);
|
|
1080
|
+
}
|
|
1081
|
+
return state;
|
|
1082
|
+
}
|
|
1083
|
+
function styled(icon) {
|
|
1084
|
+
return icon instanceof HTMLElement || icon instanceof SVGElement;
|
|
1085
|
+
}
|
|
1086
|
+
function strokes(icon) {
|
|
1087
|
+
const svg = icon instanceof SVGSVGElement ? icon : icon.querySelector("svg");
|
|
1088
|
+
const shape = svg ? iconShape(svg) : void 0;
|
|
1089
|
+
const parts = shape?.shapes.filter((part) => getComputedStyle(part).stroke !== "none") ?? [];
|
|
1090
|
+
return shape && parts.length ? {
|
|
1091
|
+
shape,
|
|
1092
|
+
parts
|
|
1093
|
+
} : void 0;
|
|
1094
|
+
}
|
|
1095
|
+
function saveStyle(style, property) {
|
|
1096
|
+
const value = style.getPropertyValue(property);
|
|
1097
|
+
const priority = style.getPropertyPriority(property);
|
|
1098
|
+
return () => {
|
|
1099
|
+
if (value) style.setProperty(property, value, priority);
|
|
1100
|
+
else style.removeProperty(property);
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
function paintIcon(icon, state, values) {
|
|
1104
|
+
if (!styled(icon)) return;
|
|
1105
|
+
const styles = state.styles ??= /* @__PURE__ */ new Map();
|
|
1106
|
+
for (const [property, value] of Object.entries(values)) {
|
|
1107
|
+
if (!styles.has(property)) styles.set(property, saveStyle(icon.style, property));
|
|
1108
|
+
icon.style.setProperty(property, value);
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
function clear$1(state) {
|
|
1112
|
+
state.stroke?.restore();
|
|
1113
|
+
state.stroke = void 0;
|
|
1114
|
+
for (const restore of state.styles?.values() ?? []) restore();
|
|
1115
|
+
state.styles = void 0;
|
|
1116
|
+
}
|
|
1117
|
+
function stopIcon(icon) {
|
|
1118
|
+
const state = states.get(icon);
|
|
1119
|
+
if (!state) return;
|
|
1120
|
+
state.fade?.stop();
|
|
1121
|
+
clear$1(state);
|
|
1122
|
+
state.restorePlacement?.();
|
|
1123
|
+
states.delete(icon);
|
|
1124
|
+
}
|
|
1125
|
+
function leave$4(icon, kind, reducedMotion, done) {
|
|
1126
|
+
const state = stateOf(icon);
|
|
1127
|
+
state.fade?.stop();
|
|
1128
|
+
clear$1(state);
|
|
1129
|
+
state.leaving = true;
|
|
1130
|
+
const [x, y] = kind === "blur" ? [0, 0] : directions[kind];
|
|
1131
|
+
state.fade = tween(state.shown, 0, {
|
|
1132
|
+
duration: reducedMotion ? crossfade$5 : exit.duration,
|
|
1133
|
+
ease: reducedMotion ? easeOut : easeIn
|
|
1134
|
+
}, (value) => {
|
|
1135
|
+
state.shown = value;
|
|
1136
|
+
const gone = 1 - value;
|
|
1137
|
+
paintIcon(icon, state, {
|
|
1138
|
+
opacity: String(value),
|
|
1139
|
+
...reducedMotion ? {} : kind === "blur" ? {
|
|
1140
|
+
filter: `blur(${(exit.blur * gone).toFixed(2)}px)`,
|
|
1141
|
+
scale: String(1 - (1 - exit.scale) * gone)
|
|
1142
|
+
} : { translate: `${x * exit.travel * gone}px ${y * exit.travel * gone}px` }
|
|
1143
|
+
});
|
|
1144
|
+
}, () => {
|
|
1145
|
+
state.fade = void 0;
|
|
1146
|
+
done();
|
|
1147
|
+
});
|
|
1148
|
+
}
|
|
1149
|
+
function come(icon, kind, reducedMotion, from) {
|
|
1150
|
+
const state = stateOf(icon);
|
|
1151
|
+
state.fade?.stop();
|
|
1152
|
+
state.restorePlacement?.();
|
|
1153
|
+
state.restorePlacement = void 0;
|
|
1154
|
+
state.leaving = false;
|
|
1155
|
+
clear$1(state);
|
|
1156
|
+
const stroke = kind === "draw" && !reducedMotion ? strokes(icon) : void 0;
|
|
1157
|
+
state.stroke = stroke?.shape;
|
|
1158
|
+
const finish = () => {
|
|
1159
|
+
state.fade = void 0;
|
|
1160
|
+
state.shown = 1;
|
|
1161
|
+
clear$1(state);
|
|
1162
|
+
};
|
|
1163
|
+
if (reducedMotion) {
|
|
1164
|
+
state.fade = tween(from, 1, {
|
|
1165
|
+
duration: crossfade$5,
|
|
1166
|
+
ease: easeOut
|
|
1167
|
+
}, (value) => {
|
|
1168
|
+
state.shown = value;
|
|
1169
|
+
paintIcon(icon, state, { opacity: String(value) });
|
|
1170
|
+
}, finish);
|
|
1171
|
+
return;
|
|
1172
|
+
}
|
|
1173
|
+
if (stroke) {
|
|
1174
|
+
const { shape, parts } = stroke;
|
|
1175
|
+
for (const part of parts) {
|
|
1176
|
+
shape.set(part, "pathLength", "1");
|
|
1177
|
+
shape.set(part, "stroke-dasharray", "1");
|
|
1178
|
+
shape.set(part, "stroke-dashoffset", "1");
|
|
1179
|
+
}
|
|
1180
|
+
shape.commit();
|
|
1181
|
+
const spins = icon.matches(".animate-spin") || !!icon.querySelector(".animate-spin");
|
|
1182
|
+
state.shown = 1;
|
|
1183
|
+
state.fade = tween(1, 0, {
|
|
1184
|
+
duration: spins ? draw$3.spinner : draw$3.duration,
|
|
1185
|
+
delay: draw$3.delay,
|
|
1186
|
+
ease: draw$3.ease
|
|
1187
|
+
}, (value) => {
|
|
1188
|
+
for (const part of parts) shape.set(part, "stroke-dashoffset", String(value));
|
|
1189
|
+
shape.commit();
|
|
1190
|
+
}, finish);
|
|
1191
|
+
return;
|
|
1192
|
+
}
|
|
1193
|
+
const effective = kind === "draw" ? "blur" : kind;
|
|
1194
|
+
if (effective === "blur") {
|
|
1195
|
+
state.fade = tween(from, 1, {
|
|
1196
|
+
duration: enterBlur.duration,
|
|
1197
|
+
delay: from ? 0 : enterBlur.delay,
|
|
1198
|
+
ease: enterBlur.ease
|
|
1199
|
+
}, (value) => {
|
|
1200
|
+
state.shown = Math.min(1, value);
|
|
1201
|
+
const gone = 1 - value;
|
|
1202
|
+
paintIcon(icon, state, {
|
|
1203
|
+
opacity: String(Math.min(1, Math.max(0, value))),
|
|
1204
|
+
filter: `blur(${Math.max(0, enterBlur.blur * gone).toFixed(2)}px)`,
|
|
1205
|
+
scale: String(1 - (1 - enterBlur.scale) * gone)
|
|
1206
|
+
});
|
|
1207
|
+
}, finish);
|
|
1208
|
+
return;
|
|
1209
|
+
}
|
|
1210
|
+
const [x, y] = directions[effective];
|
|
1211
|
+
state.fade = tween(from, 1, {
|
|
1212
|
+
duration: enterSlide.duration,
|
|
1213
|
+
delay: from ? 0 : enterSlide.delay,
|
|
1214
|
+
ease: enterSlide.ease
|
|
1215
|
+
}, (value) => {
|
|
1216
|
+
state.shown = value;
|
|
1217
|
+
const gone = 1 - value;
|
|
1218
|
+
paintIcon(icon, state, {
|
|
1219
|
+
opacity: String(Math.min(1, value)),
|
|
1220
|
+
translate: `${-x * enterSlide.travel * gone}px ${-y * enterSlide.travel * gone}px`
|
|
1221
|
+
});
|
|
1222
|
+
}, finish);
|
|
1223
|
+
}
|
|
1224
|
+
/**
|
|
1225
|
+
* Swaps the icon in `container` for `icon`, as rule 5 of docs/design/motion.md asks: the old icon blurs out, or leaves in
|
|
1226
|
+
* the direction it points, while the new one comes in, and a spinner or a check draws its stroke. `icon` may already be
|
|
1227
|
+
* a child of `container`, as when a framework renders it; else the helper appends it. Every other icon in the container
|
|
1228
|
+
* leaves, and is removed when it is gone.
|
|
1229
|
+
*
|
|
1230
|
+
* Call it again at any time: an icon that is still coming in leaves from where it is. Under reduced motion the icons
|
|
1231
|
+
* crossfade in 150ms. Inside `data-motion="none"` the old icons go at once.
|
|
1232
|
+
*/
|
|
1233
|
+
function swapIcon(container, icon, options = {}) {
|
|
1234
|
+
const remove = options.onRemove ?? ((old) => old.remove());
|
|
1235
|
+
if (icon.parentNode !== container) container.append(icon);
|
|
1236
|
+
const known = states.get(icon);
|
|
1237
|
+
const others = [...container.children].filter((child) => child !== icon && !states.get(child)?.leaving);
|
|
1238
|
+
const leavingNow = [...container.children].filter((child) => child !== icon && states.get(child)?.leaving);
|
|
1239
|
+
if (motionSkipped(container)) {
|
|
1240
|
+
for (const old of [...others, ...leavingNow]) {
|
|
1241
|
+
stopIcon(old);
|
|
1242
|
+
remove(old);
|
|
1243
|
+
}
|
|
1244
|
+
stopIcon(icon);
|
|
1245
|
+
return;
|
|
1246
|
+
}
|
|
1247
|
+
if (!others.length && (known ? !known.leaving : !leavingNow.length)) {
|
|
1248
|
+
stateOf(icon);
|
|
1249
|
+
return;
|
|
1250
|
+
}
|
|
1251
|
+
const placed = others.map((old) => ({
|
|
1252
|
+
old,
|
|
1253
|
+
at: offsetIn(container, old)
|
|
1254
|
+
}));
|
|
1255
|
+
for (const { old, at } of placed) leaveIcon(container, old, at, options.exit ?? "blur", remove);
|
|
1256
|
+
enterIcon(icon, options.enter, known ? known.shown : 0);
|
|
1257
|
+
}
|
|
1258
|
+
/**
|
|
1259
|
+
* Takes `old` out of the flow at `at`, a place in the padding box of `container`, and plays its exit. `remove` runs when
|
|
1260
|
+
* it is gone. The label effect of the layer uses it for a copy of the icon that Vue already replaced.
|
|
1261
|
+
*/
|
|
1262
|
+
function leaveIcon(container, old, at, exit, remove) {
|
|
1263
|
+
const reducedMotion = reduced();
|
|
1264
|
+
let position = positioned.get(container);
|
|
1265
|
+
if (!position && getComputedStyle(container).position === "static") {
|
|
1266
|
+
position = {
|
|
1267
|
+
exits: 0,
|
|
1268
|
+
restore: saveStyle(container.style, "position")
|
|
1269
|
+
};
|
|
1270
|
+
positioned.set(container, position);
|
|
1271
|
+
container.style.position = "relative";
|
|
1272
|
+
}
|
|
1273
|
+
if (position) position.exits++;
|
|
1274
|
+
const restores = [];
|
|
1275
|
+
if (styled(old)) {
|
|
1276
|
+
const placement = {
|
|
1277
|
+
position: "absolute",
|
|
1278
|
+
left: `${at.left}px`,
|
|
1279
|
+
top: `${at.top}px`,
|
|
1280
|
+
"pointer-events": "none",
|
|
1281
|
+
"margin-top": "0",
|
|
1282
|
+
"margin-right": "0",
|
|
1283
|
+
"margin-bottom": "0",
|
|
1284
|
+
"margin-left": "0"
|
|
1285
|
+
};
|
|
1286
|
+
for (const [property, value] of Object.entries(placement)) {
|
|
1287
|
+
restores.push(saveStyle(old.style, property));
|
|
1288
|
+
old.style.setProperty(property, value);
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
const hidden = old.getAttribute("aria-hidden");
|
|
1292
|
+
old.setAttribute("aria-hidden", "true");
|
|
1293
|
+
stateOf(old).restorePlacement = () => {
|
|
1294
|
+
for (const restore of restores) restore();
|
|
1295
|
+
if (hidden === null) old.removeAttribute("aria-hidden");
|
|
1296
|
+
else old.setAttribute("aria-hidden", hidden);
|
|
1297
|
+
if (position && --position.exits === 0) {
|
|
1298
|
+
position.restore();
|
|
1299
|
+
positioned.delete(container);
|
|
1300
|
+
}
|
|
1301
|
+
};
|
|
1302
|
+
leave$4(old, exit, reducedMotion, () => {
|
|
1303
|
+
stopIcon(old);
|
|
1304
|
+
remove(old);
|
|
1305
|
+
});
|
|
1306
|
+
}
|
|
1307
|
+
/** Plays the entrance of `icon` from `from` (0 for a new icon). The default draws a spinning icon and blurs in others. */
|
|
1308
|
+
function enterIcon(icon, enter, from) {
|
|
1309
|
+
const spins = icon.matches(".animate-spin") || !!icon.querySelector(".animate-spin");
|
|
1310
|
+
come(icon, enter ?? (spins ? "draw" : "blur"), reduced(), from);
|
|
1311
|
+
}
|
|
1312
|
+
/**
|
|
1313
|
+
* Where `child` sits in the padding box of `container`, in layout pixels. An SVG has no `offsetLeft`, and a press may
|
|
1314
|
+
* scale the button around both, so it divides the distance on screen by that scale.
|
|
1315
|
+
*/
|
|
1316
|
+
function offsetIn(container, child) {
|
|
1317
|
+
const outer = container.getBoundingClientRect();
|
|
1318
|
+
const inner = child.getBoundingClientRect();
|
|
1319
|
+
const scale = container.offsetWidth ? outer.width / container.offsetWidth : 1;
|
|
1320
|
+
return {
|
|
1321
|
+
left: (inner.left - outer.left) / (scale || 1) - container.clientLeft,
|
|
1322
|
+
top: (inner.top - outer.top) / (scale || 1) - container.clientTop
|
|
1323
|
+
};
|
|
1324
|
+
}
|
|
1325
|
+
// src/motion/helpers/text.ts
|
|
1326
|
+
/** Splits a change of label into the shared start, the old letters after it, and the new letters after it. */
|
|
1327
|
+
function diffText(from, to) {
|
|
1328
|
+
const a = [...from];
|
|
1329
|
+
const b = [...to];
|
|
1330
|
+
let index = 0;
|
|
1331
|
+
while (index < a.length && index < b.length && a[index] === b[index]) index++;
|
|
1332
|
+
return {
|
|
1333
|
+
kept: a.slice(0, index).join(""),
|
|
1334
|
+
gone: a.slice(index).join(""),
|
|
1335
|
+
typed: b.slice(index).join("")
|
|
1336
|
+
};
|
|
1337
|
+
}
|
|
1338
|
+
const blur$1 = 6;
|
|
1339
|
+
const leave$3 = {
|
|
1340
|
+
duration: 200,
|
|
1341
|
+
stagger: 30,
|
|
1342
|
+
spread: 120
|
|
1343
|
+
};
|
|
1344
|
+
const type = {
|
|
1345
|
+
duration: 240,
|
|
1346
|
+
lead: 30,
|
|
1347
|
+
stagger: 55,
|
|
1348
|
+
spread: 240
|
|
1349
|
+
};
|
|
1350
|
+
function staggerOf(gap, spread, count) {
|
|
1351
|
+
return count > 1 ? Math.min(gap, spread / (count - 1)) : gap;
|
|
1352
|
+
}
|
|
1353
|
+
const crossfade$4 = 150;
|
|
1354
|
+
const morphs = /* @__PURE__ */ new WeakMap();
|
|
1355
|
+
/** The text that the element shows or moves to, when a morph runs on it. */
|
|
1356
|
+
function morphTarget(element) {
|
|
1357
|
+
return morphs.get(element)?.text;
|
|
1358
|
+
}
|
|
1359
|
+
function paint$1(letter, value, reducedMotion) {
|
|
1360
|
+
letter.shown = value;
|
|
1361
|
+
writeMotionStyle(letter.node, {
|
|
1362
|
+
opacity: value >= 1 ? null : String(value),
|
|
1363
|
+
filter: reducedMotion || value >= 1 ? null : `blur(${(blur$1 * (1 - value)).toFixed(2)}px)`
|
|
1364
|
+
});
|
|
1365
|
+
}
|
|
1366
|
+
function letterNode(char) {
|
|
1367
|
+
return glyphNode(char);
|
|
1368
|
+
}
|
|
1369
|
+
function finishIfIdle$1(element, morph) {
|
|
1370
|
+
if (morphs.get(element) !== morph) return;
|
|
1371
|
+
if (morph.leaving.size || morph.timers.size || morph.frame.width.active || morph.letters.some((letter) => letter.fade || letter.waiting)) return;
|
|
1372
|
+
morphs.delete(element);
|
|
1373
|
+
morph.frame.collapse(morph.text);
|
|
1374
|
+
}
|
|
1375
|
+
function stopAll(morph) {
|
|
1376
|
+
for (const timer of morph.timers) clearTimeout(timer);
|
|
1377
|
+
morph.timers.clear();
|
|
1378
|
+
for (const letter of [...morph.letters, ...morph.leaving]) letter.fade?.stop();
|
|
1379
|
+
}
|
|
1380
|
+
function discardMorph(element) {
|
|
1381
|
+
const current = morphs.get(element);
|
|
1382
|
+
if (!current) return;
|
|
1383
|
+
stopAll(current);
|
|
1384
|
+
morphs.delete(element);
|
|
1385
|
+
current.frame.discard();
|
|
1386
|
+
}
|
|
1387
|
+
/**
|
|
1388
|
+
* Changes the text of `element` letter by letter, as rule 4 of docs/design/motion.md asks: the letters that the old and
|
|
1389
|
+
* new text share at the start stay, the other old letters blur out where they are, and the new letters type in one at
|
|
1390
|
+
* a time with a short blur. The width of the element follows the letters with a spring and never jumps.
|
|
1391
|
+
*
|
|
1392
|
+
* Call it again at any time: a new text continues from the letters on screen. The element keeps the final text for
|
|
1393
|
+
* screen readers during the morph, and holds plain text again when it ends. Under reduced motion the two texts
|
|
1394
|
+
* crossfade in 150ms. Inside `data-motion="none"`, or when the element has no layout, it sets the text at once.
|
|
1395
|
+
*
|
|
1396
|
+
* Give it an element of its own with no padding, such as the label `<span>` of a button.
|
|
1397
|
+
*/
|
|
1398
|
+
function morphText(element, text) {
|
|
1399
|
+
morph(element, text, void 0);
|
|
1400
|
+
}
|
|
1401
|
+
function hasLayout(element) {
|
|
1402
|
+
let node = element;
|
|
1403
|
+
while (node) {
|
|
1404
|
+
if (node.getClientRects().length) return true;
|
|
1405
|
+
if (getComputedStyle(node).display !== "contents") return false;
|
|
1406
|
+
const root = node.getRootNode();
|
|
1407
|
+
node = node.parentElement ?? (root instanceof ShadowRoot ? root.host : null);
|
|
1408
|
+
}
|
|
1409
|
+
return false;
|
|
1410
|
+
}
|
|
1411
|
+
/**
|
|
1412
|
+
* The morph of `morphText`. `from` is the text that the element showed before, when the app already wrote the new text
|
|
1413
|
+
* into the element, as Vue does with the label of a button.
|
|
1414
|
+
*/
|
|
1415
|
+
function morph(element, text, from) {
|
|
1416
|
+
let current = morphs.get(element);
|
|
1417
|
+
const before = current?.text ?? from ?? element.textContent ?? "";
|
|
1418
|
+
if (!current && before === text || glyphMotionSkipped(element) || !hasLayout(element)) {
|
|
1419
|
+
if (current) {
|
|
1420
|
+
stopAll(current);
|
|
1421
|
+
morphs.delete(element);
|
|
1422
|
+
}
|
|
1423
|
+
setText(element, text);
|
|
1424
|
+
return;
|
|
1425
|
+
}
|
|
1426
|
+
const reducedMotion = reduced();
|
|
1427
|
+
if (!current) {
|
|
1428
|
+
const frame = frameOf$2(element) ?? openFrame(element, "inline", () => {
|
|
1429
|
+
const running = morphs.get(element);
|
|
1430
|
+
if (running) finishIfIdle$1(element, running);
|
|
1431
|
+
});
|
|
1432
|
+
const letters = [...before].map((char) => ({
|
|
1433
|
+
node: letterNode(char),
|
|
1434
|
+
char,
|
|
1435
|
+
shown: 1,
|
|
1436
|
+
waiting: false
|
|
1437
|
+
}));
|
|
1438
|
+
frame.holder.append(...letters.map((letter) => letter.node));
|
|
1439
|
+
frame.width.set(frame.natural());
|
|
1440
|
+
current = {
|
|
1441
|
+
frame,
|
|
1442
|
+
text: before,
|
|
1443
|
+
letters,
|
|
1444
|
+
leaving: /* @__PURE__ */ new Set(),
|
|
1445
|
+
timers: /* @__PURE__ */ new Set()
|
|
1446
|
+
};
|
|
1447
|
+
morphs.set(element, current);
|
|
1448
|
+
}
|
|
1449
|
+
const state = current;
|
|
1450
|
+
const width = state.frame.width;
|
|
1451
|
+
state.frame.restore();
|
|
1452
|
+
for (const timer of state.timers) clearTimeout(timer);
|
|
1453
|
+
state.timers.clear();
|
|
1454
|
+
state.text = text;
|
|
1455
|
+
state.frame.name(text);
|
|
1456
|
+
if (reducedMotion) {
|
|
1457
|
+
leaveLetters(state, state.letters, true);
|
|
1458
|
+
state.letters = [...text].map((char) => {
|
|
1459
|
+
const letter = {
|
|
1460
|
+
node: letterNode(char),
|
|
1461
|
+
char,
|
|
1462
|
+
shown: 0,
|
|
1463
|
+
waiting: false
|
|
1464
|
+
};
|
|
1465
|
+
paint$1(letter, 0, true);
|
|
1466
|
+
state.frame.holder.append(letter.node);
|
|
1467
|
+
return letter;
|
|
1468
|
+
});
|
|
1469
|
+
width.set(state.frame.natural());
|
|
1470
|
+
for (const letter of state.letters) fadeIn(element, state, letter, 0, crossfade$4, true);
|
|
1471
|
+
return;
|
|
1472
|
+
}
|
|
1473
|
+
const diff = diffText(state.letters.map((letter) => letter.char).join(""), text);
|
|
1474
|
+
const keptCount = [...diff.kept].length;
|
|
1475
|
+
const kept = state.letters.slice(0, keptCount);
|
|
1476
|
+
leaveLetters(state, state.letters.slice(keptCount), false);
|
|
1477
|
+
const typing = [...kept.filter((letter) => letter.waiting), ...[...diff.typed].map((char) => {
|
|
1478
|
+
const letter = {
|
|
1479
|
+
node: letterNode(char),
|
|
1480
|
+
char,
|
|
1481
|
+
shown: 0,
|
|
1482
|
+
waiting: true
|
|
1483
|
+
};
|
|
1484
|
+
paint$1(letter, 0, false);
|
|
1485
|
+
state.frame.holder.append(letter.node);
|
|
1486
|
+
return letter;
|
|
1487
|
+
})];
|
|
1488
|
+
state.letters = [...kept, ...typing.filter((letter) => !kept.includes(letter))];
|
|
1489
|
+
const end = state.frame.natural();
|
|
1490
|
+
if (!typing.length) {
|
|
1491
|
+
width.to(end);
|
|
1492
|
+
return;
|
|
1493
|
+
}
|
|
1494
|
+
const start = width.value;
|
|
1495
|
+
let step = end - typing.reduce((sum, letter) => sum + letter.node.offsetWidth, 0);
|
|
1496
|
+
const slow = getMotionSlowFactor();
|
|
1497
|
+
const stagger = staggerOf(type.stagger, type.spread, typing.length);
|
|
1498
|
+
typing.forEach((letter, index) => {
|
|
1499
|
+
step += letter.node.offsetWidth;
|
|
1500
|
+
const target = index === typing.length - 1 ? end : Math.max(step, index === 0 ? Math.min(start, end) : 0);
|
|
1501
|
+
const timer = setTimeout(() => {
|
|
1502
|
+
state.timers.delete(timer);
|
|
1503
|
+
letter.waiting = false;
|
|
1504
|
+
width.to(target);
|
|
1505
|
+
fadeIn(element, state, letter, letter.shown, type.duration, false);
|
|
1506
|
+
}, (type.lead + index * stagger) * slow);
|
|
1507
|
+
state.timers.add(timer);
|
|
1508
|
+
});
|
|
1509
|
+
}
|
|
1510
|
+
function fadeIn(element, state, letter, from, duration, reducedMotion) {
|
|
1511
|
+
letter.fade?.stop();
|
|
1512
|
+
letter.fade = tween(from, 1, {
|
|
1513
|
+
duration,
|
|
1514
|
+
ease: easeOut
|
|
1515
|
+
}, (value) => paint$1(letter, value, reducedMotion), () => {
|
|
1516
|
+
letter.fade = void 0;
|
|
1517
|
+
paint$1(letter, 1, reducedMotion);
|
|
1518
|
+
finishIfIdle$1(element, state);
|
|
1519
|
+
});
|
|
1520
|
+
}
|
|
1521
|
+
function leaveLetters(state, letters, reducedMotion) {
|
|
1522
|
+
const element = state.frame.element;
|
|
1523
|
+
const placed = letters.map((letter) => ({
|
|
1524
|
+
letter,
|
|
1525
|
+
left: letter.node.offsetLeft,
|
|
1526
|
+
top: letter.node.offsetTop
|
|
1527
|
+
}));
|
|
1528
|
+
const stagger = staggerOf(leave$3.stagger, leave$3.spread, placed.length);
|
|
1529
|
+
let order = 0;
|
|
1530
|
+
for (const { letter, left, top } of placed) {
|
|
1531
|
+
letter.fade?.stop();
|
|
1532
|
+
letter.fade = void 0;
|
|
1533
|
+
if (letter.waiting || letter.shown <= 0) {
|
|
1534
|
+
letter.node.remove();
|
|
1535
|
+
continue;
|
|
1536
|
+
}
|
|
1537
|
+
letter.node.style.position = "absolute";
|
|
1538
|
+
letter.node.style.left = `${left}px`;
|
|
1539
|
+
letter.node.style.top = `${top}px`;
|
|
1540
|
+
state.leaving.add(letter);
|
|
1541
|
+
letter.fade = tween(letter.shown, 0, {
|
|
1542
|
+
duration: reducedMotion ? crossfade$4 : leave$3.duration,
|
|
1543
|
+
delay: reducedMotion ? 0 : order++ * stagger,
|
|
1544
|
+
ease: reducedMotion ? easeOut : easeIn
|
|
1545
|
+
}, (value) => paint$1(letter, value, reducedMotion), () => {
|
|
1546
|
+
letter.fade = void 0;
|
|
1547
|
+
letter.node.remove();
|
|
1548
|
+
state.leaving.delete(letter);
|
|
1549
|
+
finishIfIdle$1(element, state);
|
|
1550
|
+
});
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
892
1553
|
// src/motion/effects/label.ts
|
|
893
1554
|
const controls = ":is(button, a, [role=button])";
|
|
894
1555
|
/**
|
|
@@ -952,12 +1613,12 @@ const buttonIcon = {
|
|
|
952
1613
|
}
|
|
953
1614
|
};
|
|
954
1615
|
// src/motion/effects/leave.ts
|
|
955
|
-
const fold = {
|
|
1616
|
+
const fold$1 = {
|
|
956
1617
|
stiffness: 260,
|
|
957
1618
|
damping: 28
|
|
958
1619
|
};
|
|
959
|
-
const slotScale = .9;
|
|
960
|
-
const crossfade$
|
|
1620
|
+
const slotScale$1 = .9;
|
|
1621
|
+
const crossfade$3 = .15;
|
|
961
1622
|
const leaving = /* @__PURE__ */ new WeakMap();
|
|
962
1623
|
function stop(element) {
|
|
963
1624
|
const entry = leaving.get(element);
|
|
@@ -990,19 +1651,19 @@ const leave$2 = {
|
|
|
990
1651
|
const reduced = prefersReducedMotion();
|
|
991
1652
|
const spring = createSpring(1, (progress) => {
|
|
992
1653
|
writeMotionStyle(ghost, {
|
|
993
|
-
scale: reduced ? null : (slotScale + .09999999999999998 * progress).toFixed(4),
|
|
1654
|
+
scale: reduced ? null : (slotScale$1 + .09999999999999998 * progress).toFixed(4),
|
|
994
1655
|
opacity: Math.max(0, progress).toFixed(3)
|
|
995
1656
|
});
|
|
996
1657
|
if (progress < .02) {
|
|
997
1658
|
spring.stop();
|
|
998
1659
|
ghost.remove();
|
|
999
1660
|
}
|
|
1000
|
-
}, fold);
|
|
1661
|
+
}, fold$1);
|
|
1001
1662
|
leaving.set(element, {
|
|
1002
1663
|
ghost,
|
|
1003
1664
|
spring
|
|
1004
1665
|
});
|
|
1005
|
-
spring.to(0, reduced ? { tween: crossfade$
|
|
1666
|
+
spring.to(0, reduced ? { tween: crossfade$3 } : { preset: fold$1 });
|
|
1006
1667
|
}
|
|
1007
1668
|
};
|
|
1008
1669
|
// src/motion/effects/panel.ts
|
|
@@ -1124,8 +1785,9 @@ const up = {
|
|
|
1124
1785
|
damping: 14
|
|
1125
1786
|
};
|
|
1126
1787
|
/**
|
|
1127
|
-
* Everything a person presses: native controls
|
|
1128
|
-
*
|
|
1788
|
+
* Everything a person presses: native controls, the roles of docs/design/motion.md, and elements with
|
|
1789
|
+
* `data-motion-press`, when they are enabled. The press mode then picks which of them squash. A switch is not squashed:
|
|
1790
|
+
* the switch effect grows its knob instead.
|
|
1129
1791
|
*/
|
|
1130
1792
|
const pressSelector = `:is(button, a[href], summary, input:is([type=button], [type=submit], [type=reset], [type=checkbox], [type=radio]), ${[
|
|
1131
1793
|
"button",
|
|
@@ -1137,21 +1799,58 @@ const pressSelector = `:is(button, a[href], summary, input:is([type=button], [ty
|
|
|
1137
1799
|
"menuitemcheckbox",
|
|
1138
1800
|
"option",
|
|
1139
1801
|
"checkbox"
|
|
1140
|
-
].map((role) => `[role=${role}]`).join(", ")}):not(:disabled, [aria-disabled="true"], [role=switch])`;
|
|
1802
|
+
].map((role) => `[role=${role}]`).join(", ")}, [data-motion-press]:not([data-motion-press=none])):not(:disabled, [aria-disabled="true"], [role=switch])`;
|
|
1141
1803
|
const iconSelector = "svg, img, .iconify, [data-slot=icon], [data-slot$=Icon], [data-slot=swap-icon]";
|
|
1804
|
+
const nativeButton = ":is(button, input:is([type=button], [type=submit], [type=reset])):is(:not([role]), [role=button])";
|
|
1805
|
+
const pressModeKey = Symbol.for("vite-hub.motion.press-mode");
|
|
1806
|
+
/**
|
|
1807
|
+
* Sets the press mode of every copy of the motion layer on the page. The first copy that installs runs the press for
|
|
1808
|
+
* all of them, so the mode is on the global object.
|
|
1809
|
+
*/
|
|
1810
|
+
function setMotionPressMode(mode) {
|
|
1811
|
+
Reflect.set(globalThis, pressModeKey, mode);
|
|
1812
|
+
}
|
|
1813
|
+
function pressMode() {
|
|
1814
|
+
const mode = Reflect.get(globalThis, pressModeKey);
|
|
1815
|
+
return mode === "opt-in" || mode === "all" ? mode : "buttons";
|
|
1816
|
+
}
|
|
1142
1817
|
const pressed = /* @__PURE__ */ new WeakMap();
|
|
1143
1818
|
/** How much a control of this height squashes: 3% from 40px high, 4% from 32px, and 5% below. */
|
|
1144
1819
|
const amountFor = (height) => height >= 40 ? .03 : height >= 32 ? .04 : .05;
|
|
1820
|
+
const wholeAmount = (element) => Math.min(amountFor(element.offsetHeight), 6 / Math.max(element.offsetWidth, element.offsetHeight));
|
|
1821
|
+
function pressChoice(element, event) {
|
|
1822
|
+
for (const node of event.composedPath()) {
|
|
1823
|
+
if (!(node instanceof Element)) continue;
|
|
1824
|
+
const choice = node.getAttribute("data-motion-press");
|
|
1825
|
+
if (choice === "none") return choice;
|
|
1826
|
+
if (node === element && choice !== null) return choice;
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
function squashesByDefault(element) {
|
|
1830
|
+
const mode = pressMode();
|
|
1831
|
+
if (mode !== "buttons") return mode === "all";
|
|
1832
|
+
return element.matches(nativeButton) && element.offsetHeight < 48 && element.offsetWidth <= 4 * element.offsetHeight;
|
|
1833
|
+
}
|
|
1145
1834
|
/**
|
|
1146
1835
|
* How much a press squashes, from the prototype: an icon-only control squashes its icon by 15%, and a control squashes
|
|
1147
1836
|
* by its height. A control that another element draws, such as the mark of the folded page pill, names that element
|
|
1148
1837
|
* with `data-motion-press-target`, a selector that `closest()` finds from the control. Then that element squashes.
|
|
1838
|
+
* `data-motion-press="icon"` squashes the first icon in the element. Nothing squashes when the press does not apply.
|
|
1149
1839
|
*/
|
|
1150
|
-
function squash(element) {
|
|
1840
|
+
function squash(element, choice) {
|
|
1841
|
+
if (choice === "none") return void 0;
|
|
1842
|
+
if (choice === "icon") {
|
|
1843
|
+
const icon = element.querySelector(iconSelector);
|
|
1844
|
+
return icon instanceof HTMLElement || icon instanceof SVGElement ? {
|
|
1845
|
+
target: icon,
|
|
1846
|
+
amount: .15
|
|
1847
|
+
} : void 0;
|
|
1848
|
+
}
|
|
1849
|
+
if (choice === void 0 && !squashesByDefault(element)) return void 0;
|
|
1151
1850
|
const drawnBy = element.dataset.motionPressTarget ? element.closest(element.dataset.motionPressTarget) : null;
|
|
1152
1851
|
if (drawnBy instanceof HTMLElement) return {
|
|
1153
1852
|
target: drawnBy,
|
|
1154
|
-
amount:
|
|
1853
|
+
amount: wholeAmount(drawnBy)
|
|
1155
1854
|
};
|
|
1156
1855
|
const icon = element.firstElementChild;
|
|
1157
1856
|
if (element.childElementCount === 1 && !element.textContent?.trim() && (icon instanceof HTMLElement || icon instanceof SVGElement) && icon.matches(iconSelector)) return {
|
|
@@ -1160,7 +1859,7 @@ function squash(element) {
|
|
|
1160
1859
|
};
|
|
1161
1860
|
return {
|
|
1162
1861
|
target: element,
|
|
1163
|
-
amount:
|
|
1862
|
+
amount: wholeAmount(element)
|
|
1164
1863
|
};
|
|
1165
1864
|
}
|
|
1166
1865
|
/**
|
|
@@ -1180,12 +1879,15 @@ const press = {
|
|
|
1180
1879
|
name: "press",
|
|
1181
1880
|
selector: pressSelector,
|
|
1182
1881
|
press(element, event) {
|
|
1183
|
-
|
|
1882
|
+
if (!("pointerId" in event)) return;
|
|
1883
|
+
const squashed = squash(element, pressChoice(element, event));
|
|
1884
|
+
if (!squashed) return;
|
|
1885
|
+
const { target, amount } = squashed;
|
|
1184
1886
|
const style = getComputedStyle(target);
|
|
1185
1887
|
if (transitionsScale(style) || style.display === "contents") return;
|
|
1186
1888
|
if (style.display === "inline" && target === element && !(element instanceof HTMLInputElement)) return;
|
|
1187
1889
|
let bounds;
|
|
1188
|
-
if (target === element
|
|
1890
|
+
if (target === element) {
|
|
1189
1891
|
bounds = element.getBoundingClientRect();
|
|
1190
1892
|
if (nearEdge(bounds, event, amount)) return;
|
|
1191
1893
|
}
|
|
@@ -1247,9 +1949,6 @@ const indicatorItem = `${byRole}, [aria-selected], [aria-checked], [data-checked
|
|
|
1247
1949
|
].map((value) => `[data-state=${value}]`).join(", ")}`;
|
|
1248
1950
|
const ownIndicator = "[data-motion-indicator], [data-slot=indicator]";
|
|
1249
1951
|
const groupIndicator = `${ownIndicator}, [data-slot$="-indicator"]`;
|
|
1250
|
-
const stretchPerSpeed$1 = .09;
|
|
1251
|
-
const stretchMax$1 = .55;
|
|
1252
|
-
const thinning = .25;
|
|
1253
1952
|
const flights = /* @__PURE__ */ new WeakMap();
|
|
1254
1953
|
const pending = /* @__PURE__ */ new Map();
|
|
1255
1954
|
const observedItems = /* @__PURE__ */ new WeakSet();
|
|
@@ -1281,10 +1980,6 @@ function frameOf(group) {
|
|
|
1281
1980
|
k: group.offsetWidth ? rect.width / group.offsetWidth : 1
|
|
1282
1981
|
};
|
|
1283
1982
|
}
|
|
1284
|
-
/**
|
|
1285
|
-
* The layout box of an element relative to the group, in CSS pixels. The size comes from layout and the center from the
|
|
1286
|
-
* screen, so a press that scales an item around its center does not change it.
|
|
1287
|
-
*/
|
|
1288
1983
|
function boxOf(element, frame) {
|
|
1289
1984
|
const rect = element.getBoundingClientRect();
|
|
1290
1985
|
const width = element.offsetWidth || rect.width / frame.k;
|
|
@@ -1296,19 +1991,10 @@ function boxOf(element, frame) {
|
|
|
1296
1991
|
height
|
|
1297
1992
|
};
|
|
1298
1993
|
}
|
|
1299
|
-
/** The indicator of `item`: its own one, or the one of the group that is in no item. */
|
|
1300
1994
|
function indicatorOf(group, item) {
|
|
1301
1995
|
for (const candidate of item.querySelectorAll(ownIndicator)) if (candidate.closest(anyGroup) === group && indicatorOwner(group, candidate) === item) return candidate;
|
|
1302
1996
|
for (const candidate of group.querySelectorAll(groupIndicator)) if (candidate.closest(anyGroup) === group && !indicatorOwner(group, candidate)) return candidate;
|
|
1303
1997
|
}
|
|
1304
|
-
function innerBounds(group) {
|
|
1305
|
-
const style = getComputedStyle(group);
|
|
1306
|
-
const left = group.clientLeft + Number.parseFloat(style.paddingLeft);
|
|
1307
|
-
const top = group.clientTop + Number.parseFloat(style.paddingTop);
|
|
1308
|
-
const right = group.clientLeft + group.clientWidth - Number.parseFloat(style.paddingRight);
|
|
1309
|
-
const bottom = group.clientTop + group.clientHeight - Number.parseFloat(style.paddingBottom);
|
|
1310
|
-
return [[left, right], [top, bottom]];
|
|
1311
|
-
}
|
|
1312
1998
|
function pixels(value, size) {
|
|
1313
1999
|
return value.endsWith("%") ? Number.parseFloat(value) / 100 * size : Number.parseFloat(value) || 0;
|
|
1314
2000
|
}
|
|
@@ -1324,7 +2010,6 @@ function measureRest$1(flight) {
|
|
|
1324
2010
|
flight.translate = [pixels(tx, flight.rest.width), pixels(ty, flight.rest.height)];
|
|
1325
2011
|
flight.origin = [pixels(ox, flight.rest.width), pixels(oy, flight.rest.height)];
|
|
1326
2012
|
}
|
|
1327
|
-
/** The box of the indicator at rest in `to`, moved and resized to sit the same way in `from`. */
|
|
1328
2013
|
function mapBox(rest, to, from) {
|
|
1329
2014
|
const sx = to.width ? from.width / to.width : 1;
|
|
1330
2015
|
const sy = to.height ? from.height / to.height : 1;
|
|
@@ -1335,7 +2020,7 @@ function mapBox(rest, to, from) {
|
|
|
1335
2020
|
height: rest.height * sy
|
|
1336
2021
|
};
|
|
1337
2022
|
}
|
|
1338
|
-
function moving(flight) {
|
|
2023
|
+
function moving$1(flight) {
|
|
1339
2024
|
return !!flight && (flight.x.active || flight.y.active || flight.width.active || flight.height.active);
|
|
1340
2025
|
}
|
|
1341
2026
|
function queue(flight) {
|
|
@@ -1346,25 +2031,10 @@ function queue(flight) {
|
|
|
1346
2031
|
render(flight);
|
|
1347
2032
|
});
|
|
1348
2033
|
}
|
|
1349
|
-
/**
|
|
1350
|
-
* One axis of the box in flight: its start and size, longer by `along` of its size toward where it moves, thinner by a
|
|
1351
|
-
* quarter of `across`, and kept inside `bounds` or the place at rest.
|
|
1352
|
-
*/
|
|
1353
|
-
function stretch(start, size, velocity, along, across, bounds, restStart, restSize) {
|
|
1354
|
-
const extra = along * size;
|
|
1355
|
-
const low = Math.min(bounds[0], restStart, start);
|
|
1356
|
-
const high = Math.max(bounds[1], restStart + restSize, start + size);
|
|
1357
|
-
let from = velocity < 0 ? Math.max(low, start - extra) : start;
|
|
1358
|
-
let to = velocity < 0 ? start + size : Math.min(high, start + size + extra);
|
|
1359
|
-
const thin = (to - from) * across * thinning / 2;
|
|
1360
|
-
from += thin;
|
|
1361
|
-
to -= thin;
|
|
1362
|
-
return [from, to - from];
|
|
1363
|
-
}
|
|
1364
2034
|
function render(flight) {
|
|
1365
2035
|
if (!flight.ready) return;
|
|
1366
|
-
const { element, rest, translate, origin, x, y, width, height
|
|
1367
|
-
if (!moving(flight)) {
|
|
2036
|
+
const { element, rest, translate, origin, x, y, width, height } = flight;
|
|
2037
|
+
if (!moving$1(flight)) {
|
|
1368
2038
|
writeMotionStyle(element, {
|
|
1369
2039
|
translate: null,
|
|
1370
2040
|
scale: null
|
|
@@ -1372,14 +2042,10 @@ function render(flight) {
|
|
|
1372
2042
|
land(flight);
|
|
1373
2043
|
return;
|
|
1374
2044
|
}
|
|
1375
|
-
const
|
|
1376
|
-
const
|
|
1377
|
-
const
|
|
1378
|
-
const
|
|
1379
|
-
const scaleX = rest.width ? boxWidth / rest.width : 1;
|
|
1380
|
-
const scaleY = rest.height ? boxHeight / rest.height : 1;
|
|
1381
|
-
const tx = left - (rest.x - translate[0]) - origin[0] * (1 - scaleX);
|
|
1382
|
-
const ty = top - (rest.y - translate[1]) - origin[1] * (1 - scaleY);
|
|
2045
|
+
const scaleX = rest.width ? width.value / rest.width : 1;
|
|
2046
|
+
const scaleY = rest.height ? height.value / rest.height : 1;
|
|
2047
|
+
const tx = x.value - (rest.x - translate[0]) - origin[0] * (1 - scaleX);
|
|
2048
|
+
const ty = y.value - (rest.y - translate[1]) - origin[1] * (1 - scaleY);
|
|
1383
2049
|
writeMotionStyle(element, {
|
|
1384
2050
|
translate: `${tx}px ${ty}px`,
|
|
1385
2051
|
scale: `${scaleX} ${scaleY}`
|
|
@@ -1387,7 +2053,7 @@ function render(flight) {
|
|
|
1387
2053
|
}
|
|
1388
2054
|
function fly(group, element, from, to, copyOf) {
|
|
1389
2055
|
const previous = flights.get(group);
|
|
1390
|
-
const wasMoving = moving(previous);
|
|
2056
|
+
const wasMoving = moving$1(previous);
|
|
1391
2057
|
if (previous && previous.element !== element) {
|
|
1392
2058
|
writeMotionStyle(previous.element, {
|
|
1393
2059
|
translate: null,
|
|
@@ -1407,20 +2073,17 @@ function fly(group, element, from, to, copyOf) {
|
|
|
1407
2073
|
},
|
|
1408
2074
|
translate: [0, 0],
|
|
1409
2075
|
origin: [0, 0],
|
|
1410
|
-
span: [1, 1],
|
|
1411
|
-
bounds: [[0, 0], [0, 0]],
|
|
1412
2076
|
queued: false,
|
|
1413
|
-
x: createSpring(0, () => queue(flight), springs.
|
|
1414
|
-
y: createSpring(0, () => queue(flight), springs.
|
|
1415
|
-
width: createSpring(0, () => queue(flight), springs.
|
|
1416
|
-
height: createSpring(0, () => queue(flight), springs.
|
|
2077
|
+
x: createSpring(0, () => queue(flight), springs.glide),
|
|
2078
|
+
y: createSpring(0, () => queue(flight), springs.glide),
|
|
2079
|
+
width: createSpring(0, () => queue(flight), springs.glide),
|
|
2080
|
+
height: createSpring(0, () => queue(flight), springs.glide)
|
|
1417
2081
|
};
|
|
1418
2082
|
flights.set(group, flight);
|
|
1419
2083
|
flight.ready = false;
|
|
1420
2084
|
flight.element = element;
|
|
1421
2085
|
flight.copyOf = copyOf;
|
|
1422
2086
|
measureRest$1(flight);
|
|
1423
|
-
flight.bounds = innerBounds(group);
|
|
1424
2087
|
const { rest } = flight;
|
|
1425
2088
|
if (!rest.width || !rest.height || !wasMoving && !from) {
|
|
1426
2089
|
flight.ready = true;
|
|
@@ -1434,11 +2097,15 @@ function fly(group, element, from, to, copyOf) {
|
|
|
1434
2097
|
flight.width.set(start.width);
|
|
1435
2098
|
flight.height.set(start.height);
|
|
1436
2099
|
}
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
2100
|
+
for (const [spring, target] of [
|
|
2101
|
+
[flight.x, rest.x],
|
|
2102
|
+
[flight.y, rest.y],
|
|
2103
|
+
[flight.width, rest.width],
|
|
2104
|
+
[flight.height, rest.height]
|
|
2105
|
+
]) {
|
|
2106
|
+
spring.stop();
|
|
2107
|
+
spring.to(target);
|
|
2108
|
+
}
|
|
1442
2109
|
flight.ready = true;
|
|
1443
2110
|
render(flight);
|
|
1444
2111
|
}
|
|
@@ -1479,7 +2146,6 @@ function adoptSheet(node) {
|
|
|
1479
2146
|
if (!root.adoptedStyleSheets.includes(sheet)) root.adoptedStyleSheets = [...root.adoptedStyleSheets, sheet];
|
|
1480
2147
|
}
|
|
1481
2148
|
const clear = /^transparent$|^rgba\((?:[^,]+,){3}\s*0(?:\.0+)?\)$|\/\s*0(?:\.0+)?%?\s*\)$/;
|
|
1482
|
-
/** A copy of the look that `to` has and `from` does not, behind the items, or nothing when they look the same. */
|
|
1483
2149
|
function copyLook(group, from, to) {
|
|
1484
2150
|
finishLook(from);
|
|
1485
2151
|
finishLook(to);
|
|
@@ -1569,7 +2235,7 @@ function move(group, from, to) {
|
|
|
1569
2235
|
const indicator = indicatorOf(group, to);
|
|
1570
2236
|
if (indicator) return isMotionOff(indicator) ? cancelFlight(group) : fly(group, indicator, from, to);
|
|
1571
2237
|
const previous = flights.get(group);
|
|
1572
|
-
const source = from ?? (moving(previous) ? previous?.copyOf : void 0);
|
|
2238
|
+
const source = from ?? (moving$1(previous) ? previous?.copyOf : void 0);
|
|
1573
2239
|
if (!source) return;
|
|
1574
2240
|
const look = copyLook(group, source, to);
|
|
1575
2241
|
if (!look) return;
|
|
@@ -1657,7 +2323,7 @@ function along$1(rect, axis) {
|
|
|
1657
2323
|
size: rect.height
|
|
1658
2324
|
};
|
|
1659
2325
|
}
|
|
1660
|
-
function measure$
|
|
2326
|
+
function measure$2(motion) {
|
|
1661
2327
|
const { thumb, track, axis } = motion;
|
|
1662
2328
|
motion.zoom = zoomOf(track);
|
|
1663
2329
|
const shown = along$1(rectOf(thumb, motion), axis);
|
|
@@ -1728,7 +2394,7 @@ function start$1(thumb, value) {
|
|
|
1728
2394
|
tail: createSpring(0, () => draw$2(motion), trail),
|
|
1729
2395
|
ownTranslate: split(thumb.style.translate)
|
|
1730
2396
|
};
|
|
1731
|
-
motion.layout = measure$
|
|
2397
|
+
motion.layout = measure$2(motion);
|
|
1732
2398
|
motion.position.set(motion.layout);
|
|
1733
2399
|
motions.set(thumb, motion);
|
|
1734
2400
|
return motion;
|
|
@@ -1871,7 +2537,7 @@ function follow(thumb, value, from, to) {
|
|
|
1871
2537
|
const existing = motions.get(thumb);
|
|
1872
2538
|
const motion = existing ?? start$1(thumb, value);
|
|
1873
2539
|
if (!motion) return;
|
|
1874
|
-
const next = measure$
|
|
2540
|
+
const next = measure$2(motion);
|
|
1875
2541
|
if (!existing) {
|
|
1876
2542
|
const was = from === void 0 || to === void 0 ? void 0 : previousCenter(motion, value, from, to);
|
|
1877
2543
|
motion.position.set(was ?? next);
|
|
@@ -1947,7 +2613,7 @@ const slider = {
|
|
|
1947
2613
|
}
|
|
1948
2614
|
};
|
|
1949
2615
|
// src/motion/effects/switch.ts
|
|
1950
|
-
const travel = {
|
|
2616
|
+
const travel$2 = {
|
|
1951
2617
|
stiffness: 300,
|
|
1952
2618
|
damping: 24
|
|
1953
2619
|
};
|
|
@@ -1975,7 +2641,7 @@ function isOn(value) {
|
|
|
1975
2641
|
return value === "true";
|
|
1976
2642
|
}
|
|
1977
2643
|
/** Reads where the stylesheet puts the knob in the current state, without what the effect wrote. */
|
|
1978
|
-
function measure(element, knob) {
|
|
2644
|
+
function measure$1(element, knob) {
|
|
1979
2645
|
writeMotionStyle(knob, {
|
|
1980
2646
|
translate: null,
|
|
1981
2647
|
scale: null
|
|
@@ -2061,7 +2727,7 @@ function knobOf(element, wasOn) {
|
|
|
2061
2727
|
position: createSpring(value, (position, velocity) => {
|
|
2062
2728
|
state.velocity = velocity;
|
|
2063
2729
|
redraw();
|
|
2064
|
-
}, travel),
|
|
2730
|
+
}, travel$2),
|
|
2065
2731
|
velocity: 0,
|
|
2066
2732
|
size: createSpring(value, redraw, size),
|
|
2067
2733
|
press: createSpring(0, redraw, pressSpring),
|
|
@@ -2073,7 +2739,7 @@ function knobOf(element, wasOn) {
|
|
|
2073
2739
|
}
|
|
2074
2740
|
/** Measures the state that the stylesheet draws now and keeps it as the rest of that state. */
|
|
2075
2741
|
function remeasure(element, state, on) {
|
|
2076
|
-
const { rest, translate, width, height } = measure(element, state.knob);
|
|
2742
|
+
const { rest, translate, width, height } = measure$1(element, state.knob);
|
|
2077
2743
|
state.rest[on ? 1 : 0] = rest;
|
|
2078
2744
|
state.now = {
|
|
2079
2745
|
on,
|
|
@@ -2115,7 +2781,7 @@ const switchKnob = {
|
|
|
2115
2781
|
}
|
|
2116
2782
|
};
|
|
2117
2783
|
// src/motion/effects/toast.ts
|
|
2118
|
-
const crossfade$
|
|
2784
|
+
const crossfade$2 = .15;
|
|
2119
2785
|
const lists = /* @__PURE__ */ new WeakMap();
|
|
2120
2786
|
const fixed = (element) => !!element && getComputedStyle(element).position === "fixed";
|
|
2121
2787
|
function isToast(element) {
|
|
@@ -2242,7 +2908,7 @@ function leave$1(list, element) {
|
|
|
2242
2908
|
writeMotionStyle(ghost, { opacity: String(value) });
|
|
2243
2909
|
if (!fade.active && value === 0) ghost.remove();
|
|
2244
2910
|
});
|
|
2245
|
-
fade.to(0, { tween: crossfade$
|
|
2911
|
+
fade.to(0, { tween: crossfade$2 });
|
|
2246
2912
|
} else {
|
|
2247
2913
|
const { axis, distance: target } = exitOf(rect, swipeDirection ?? direction);
|
|
2248
2914
|
const spring = createSpring(0, (value) => {
|
|
@@ -2311,7 +2977,7 @@ const toast = {
|
|
|
2311
2977
|
const fade = createSpring(0, () => write(element, item.x, item.y, fade));
|
|
2312
2978
|
item.fade = fade;
|
|
2313
2979
|
fade.set(0);
|
|
2314
|
-
fade.to(1, { tween: crossfade$
|
|
2980
|
+
fade.to(1, { tween: crossfade$2 });
|
|
2315
2981
|
} else {
|
|
2316
2982
|
item.y.set(pastEdge(rect));
|
|
2317
2983
|
item.y.to(0);
|
|
@@ -2333,15 +2999,24 @@ const widen = {
|
|
|
2333
2999
|
damping: 32
|
|
2334
3000
|
};
|
|
2335
3001
|
const narrow = 30;
|
|
2336
|
-
const widenAfter = 120;
|
|
2337
|
-
const labelAfterRise = 70;
|
|
2338
3002
|
const labelAfterSlide = 40;
|
|
2339
|
-
const
|
|
2340
|
-
|
|
2341
|
-
|
|
3003
|
+
const tipPace = {
|
|
3004
|
+
widenAfter: 120,
|
|
3005
|
+
labelAfterRise: 70,
|
|
3006
|
+
labelIn: .24,
|
|
3007
|
+
sinkAfter: 90,
|
|
3008
|
+
goneAfter: 520
|
|
3009
|
+
};
|
|
3010
|
+
const appearPace = {
|
|
3011
|
+
widenAfter: 60,
|
|
3012
|
+
labelAfterRise: 40,
|
|
3013
|
+
labelIn: .18,
|
|
3014
|
+
sinkAfter: 50,
|
|
3015
|
+
goneAfter: 320
|
|
3016
|
+
};
|
|
2342
3017
|
const labelOutOnSlide = .15;
|
|
2343
3018
|
const labelOutOnLeave = .14;
|
|
2344
|
-
const crossfade = .15;
|
|
3019
|
+
const crossfade$1 = .15;
|
|
2345
3020
|
const tips = /* @__PURE__ */ new WeakMap();
|
|
2346
3021
|
const openTips = /* @__PURE__ */ new Set();
|
|
2347
3022
|
const exitBoxes = /* @__PURE__ */ new Set();
|
|
@@ -2489,15 +3164,18 @@ function draw(box) {
|
|
|
2489
3164
|
});
|
|
2490
3165
|
}
|
|
2491
3166
|
}
|
|
2492
|
-
function
|
|
2493
|
-
|
|
3167
|
+
function moving(box) {
|
|
3168
|
+
return box.holding || box.timers.size > 0 || [
|
|
2494
3169
|
box.x,
|
|
2495
3170
|
box.y,
|
|
2496
3171
|
box.width,
|
|
2497
3172
|
box.label,
|
|
2498
3173
|
box.fade,
|
|
2499
3174
|
box.old?.spring
|
|
2500
|
-
].some((spring) => spring?.active)
|
|
3175
|
+
].some((spring) => spring?.active);
|
|
3176
|
+
}
|
|
3177
|
+
function settle(box) {
|
|
3178
|
+
if (moving(box)) return;
|
|
2501
3179
|
box.old?.element.remove();
|
|
2502
3180
|
box.old = void 0;
|
|
2503
3181
|
writeMotionStyle(box.element, {
|
|
@@ -2540,6 +3218,9 @@ function createBox(element, rest, trigger) {
|
|
|
2540
3218
|
box.fade = createSpring(1, frame);
|
|
2541
3219
|
return box;
|
|
2542
3220
|
}
|
|
3221
|
+
function paceOf(box) {
|
|
3222
|
+
return box.handoff ? tipPace : appearPace;
|
|
3223
|
+
}
|
|
2543
3224
|
function later(box, ms, step) {
|
|
2544
3225
|
const timer = after(ms, () => {
|
|
2545
3226
|
box.timers.delete(timer);
|
|
@@ -2642,7 +3323,7 @@ function start(element, tip) {
|
|
|
2642
3323
|
if (from) leaveGhost(from, true);
|
|
2643
3324
|
box.fade.set(0);
|
|
2644
3325
|
box.holding = false;
|
|
2645
|
-
box.fade.to(1, { tween: crossfade });
|
|
3326
|
+
box.fade.to(1, { tween: crossfade$1 });
|
|
2646
3327
|
return;
|
|
2647
3328
|
}
|
|
2648
3329
|
if (from) {
|
|
@@ -2671,7 +3352,7 @@ function start(element, tip) {
|
|
|
2671
3352
|
preset: widen,
|
|
2672
3353
|
velocity: values.width[1]
|
|
2673
3354
|
});
|
|
2674
|
-
later(box, labelAfterSlide, () => box.label.to(1, { tween: labelIn }));
|
|
3355
|
+
later(box, labelAfterSlide, () => box.label.to(1, { tween: tipPace.labelIn }));
|
|
2675
3356
|
box.holding = false;
|
|
2676
3357
|
draw(box);
|
|
2677
3358
|
return;
|
|
@@ -2681,9 +3362,10 @@ function start(element, tip) {
|
|
|
2681
3362
|
box.label.set(0);
|
|
2682
3363
|
draw(box);
|
|
2683
3364
|
along(box).to(vertical(box.side) ? rest.top + rest.height / 2 : rest.left + rest.width / 2, { preset: rise });
|
|
2684
|
-
|
|
3365
|
+
const pace = paceOf(box);
|
|
3366
|
+
later(box, pace.widenAfter, () => {
|
|
2685
3367
|
box.width.to(rest.width, { preset: widen });
|
|
2686
|
-
later(box, labelAfterRise, () => box.label.to(1, { tween: labelIn }));
|
|
3368
|
+
later(box, pace.labelAfterRise, () => box.label.to(1, { tween: pace.labelIn }));
|
|
2687
3369
|
});
|
|
2688
3370
|
box.holding = false;
|
|
2689
3371
|
}
|
|
@@ -2692,18 +3374,19 @@ function leaveGhost(box, reduced) {
|
|
|
2692
3374
|
box.holding = false;
|
|
2693
3375
|
if (reduced) {
|
|
2694
3376
|
box.done = () => removeGhost(box);
|
|
2695
|
-
box.fade.to(0, { tween: crossfade });
|
|
3377
|
+
box.fade.to(0, { tween: crossfade$1 });
|
|
2696
3378
|
return;
|
|
2697
3379
|
}
|
|
2698
3380
|
if (box.handoff) handoff = box;
|
|
2699
3381
|
if (box.old) box.old.spring.to(0, { tween: labelOutOnLeave });
|
|
2700
3382
|
box.label.to(0, { tween: labelOutOnLeave });
|
|
2701
3383
|
box.width.to(Math.min(narrow, box.rest.width), { preset: widen });
|
|
2702
|
-
|
|
3384
|
+
const pace = paceOf(box);
|
|
3385
|
+
later(box, pace.sinkAfter, () => {
|
|
2703
3386
|
if (handoff === box) handoff = void 0;
|
|
2704
3387
|
along(box).to(hiddenCenter(box), { preset: rise });
|
|
2705
3388
|
});
|
|
2706
|
-
later(box, goneAfter, () => removeGhost(box));
|
|
3389
|
+
later(box, pace.goneAfter, () => removeGhost(box));
|
|
2707
3390
|
}
|
|
2708
3391
|
function leave(element, tip) {
|
|
2709
3392
|
if (!tip.open) return;
|
|
@@ -2846,7 +3529,9 @@ function checkMoves() {
|
|
|
2846
3529
|
if (!tip || !box) continue;
|
|
2847
3530
|
const rest = measureRest(element);
|
|
2848
3531
|
const text = labelText(box);
|
|
2849
|
-
|
|
3532
|
+
const moved = Math.abs(rest.left - box.rest.left) > 1 || Math.abs(rest.top - box.rest.top) > 1 || Math.abs(rest.width - box.rest.width) > 1;
|
|
3533
|
+
const resized = (moved || Math.abs(rest.height - box.rest.height) > 1) && !box.handoff && !moving(box) && Math.abs(rest.left + rest.width / 2 - (box.rest.left + box.rest.width / 2)) <= 1 && Math.abs(rest.top - box.rest.top) <= 1;
|
|
3534
|
+
if (!moved && !resized && text === tip.text) continue;
|
|
2850
3535
|
const old = text === tip.text ? [] : tip.label;
|
|
2851
3536
|
tip.trigger = findTrigger(element) ?? tip.trigger;
|
|
2852
3537
|
const triggerRect = tip.trigger?.getBoundingClientRect();
|
|
@@ -2855,7 +3540,7 @@ function checkMoves() {
|
|
|
2855
3540
|
box.rest = rest;
|
|
2856
3541
|
box.side = sideOf(element, rest, triggerRect);
|
|
2857
3542
|
box.edge = edgeOf(box.side, rest, triggerRect);
|
|
2858
|
-
if (prefersReducedMotion()) {
|
|
3543
|
+
if (prefersReducedMotion() || resized) {
|
|
2859
3544
|
box.x.set(rest.left + rest.width / 2);
|
|
2860
3545
|
box.y.set(rest.top + rest.height / 2);
|
|
2861
3546
|
box.width.set(rest.width);
|
|
@@ -2869,7 +3554,7 @@ function checkMoves() {
|
|
|
2869
3554
|
box.old?.element.remove();
|
|
2870
3555
|
blurOutOld(box, old, box.label.value);
|
|
2871
3556
|
box.label.set(0);
|
|
2872
|
-
later(box, labelAfterSlide, () => box.label.to(1, { tween: labelIn }));
|
|
3557
|
+
later(box, labelAfterSlide, () => box.label.to(1, { tween: paceOf(box).labelIn }));
|
|
2873
3558
|
}
|
|
2874
3559
|
}
|
|
2875
3560
|
}
|
|
@@ -2959,4 +3644,1028 @@ const motionEffects = [
|
|
|
2959
3644
|
leave$2,
|
|
2960
3645
|
panel
|
|
2961
3646
|
];
|
|
2962
|
-
|
|
3647
|
+
// src/motion/helpers/number.ts
|
|
3648
|
+
const travel$1 = 1;
|
|
3649
|
+
const blur = 2;
|
|
3650
|
+
const out = {
|
|
3651
|
+
duration: 240,
|
|
3652
|
+
ease: easeIn
|
|
3653
|
+
};
|
|
3654
|
+
const into = {
|
|
3655
|
+
duration: 380,
|
|
3656
|
+
delay: 60,
|
|
3657
|
+
ease: cubicBezier(.3, 1.4, .5, 1)
|
|
3658
|
+
};
|
|
3659
|
+
const crossfade = 150;
|
|
3660
|
+
const rolls = /* @__PURE__ */ new WeakMap();
|
|
3661
|
+
const values = /* @__PURE__ */ new WeakMap();
|
|
3662
|
+
function glyph(char) {
|
|
3663
|
+
const node = glyphNode(char);
|
|
3664
|
+
node.style.gridArea = "1 / 1";
|
|
3665
|
+
return {
|
|
3666
|
+
node,
|
|
3667
|
+
shown: 1
|
|
3668
|
+
};
|
|
3669
|
+
}
|
|
3670
|
+
function column(char) {
|
|
3671
|
+
const node = own(document.createElement("span"));
|
|
3672
|
+
node.style.cssText = "display:inline-grid;overflow:hidden;justify-items:center";
|
|
3673
|
+
const current = char ? glyph(char) : void 0;
|
|
3674
|
+
if (current) node.append(current.node);
|
|
3675
|
+
return {
|
|
3676
|
+
node,
|
|
3677
|
+
char,
|
|
3678
|
+
current,
|
|
3679
|
+
leaving: /* @__PURE__ */ new Set()
|
|
3680
|
+
};
|
|
3681
|
+
}
|
|
3682
|
+
function paint(item, value, direction, reducedMotion) {
|
|
3683
|
+
item.shown = value;
|
|
3684
|
+
const gone = 1 - value;
|
|
3685
|
+
writeMotionStyle(item.node, {
|
|
3686
|
+
opacity: value >= 1 ? null : String(Math.max(0, value)),
|
|
3687
|
+
filter: reducedMotion || value >= 1 ? null : `blur(${Math.max(0, blur * gone).toFixed(2)}px)`,
|
|
3688
|
+
scale: reducedMotion || value === 1 ? null : String(1 - .44999999999999996 * gone),
|
|
3689
|
+
translate: reducedMotion || value === 1 ? null : `0 ${(direction * travel$1 * gone).toFixed(3)}em`
|
|
3690
|
+
});
|
|
3691
|
+
}
|
|
3692
|
+
function idle(roll) {
|
|
3693
|
+
return !roll.frame.width.active && roll.columns.every((item) => !item.leaving.size && !item.current?.fade);
|
|
3694
|
+
}
|
|
3695
|
+
function finishIfIdle(element, roll) {
|
|
3696
|
+
if (rolls.get(element) !== roll || !idle(roll)) return;
|
|
3697
|
+
rolls.delete(element);
|
|
3698
|
+
roll.frame.collapse(roll.text);
|
|
3699
|
+
}
|
|
3700
|
+
/**
|
|
3701
|
+
* Rolls the number in `element` to `value`, as rule 6 of docs/design/motion.md asks: only the digits that change roll,
|
|
3702
|
+
* up when the number grows and down when it shrinks. The width of the element follows with a spring. `format` turns the
|
|
3703
|
+
* number into its text, such as `n => n.toLocaleString()`. The default is `String`.
|
|
3704
|
+
*
|
|
3705
|
+
* Call it again at any time: a digit that is still rolling in rolls out from where it is. The element keeps the final
|
|
3706
|
+
* text for screen readers, and holds plain text again when the roll ends. Under reduced motion the changed digits
|
|
3707
|
+
* crossfade in 150ms. Inside `data-motion="none"`, or before the element is on the page, it sets the text at once.
|
|
3708
|
+
*/
|
|
3709
|
+
function rollNumber(element, value, format = String) {
|
|
3710
|
+
const text = format(value);
|
|
3711
|
+
let roll = rolls.get(element);
|
|
3712
|
+
const before = roll?.text ?? element.textContent ?? "";
|
|
3713
|
+
const previous = roll?.value ?? values.get(element) ?? parseCount(before);
|
|
3714
|
+
values.set(element, value);
|
|
3715
|
+
if (previous === void 0 || !roll && before === text || glyphMotionSkipped(element)) {
|
|
3716
|
+
if (roll) {
|
|
3717
|
+
for (const item of roll.columns) for (const g of [item.current, ...item.leaving]) g?.fade?.stop();
|
|
3718
|
+
rolls.delete(element);
|
|
3719
|
+
}
|
|
3720
|
+
setText(element, text);
|
|
3721
|
+
return;
|
|
3722
|
+
}
|
|
3723
|
+
const direction = value > previous ? 1 : value < previous ? -1 : 0;
|
|
3724
|
+
const reducedMotion = reduced();
|
|
3725
|
+
if (!roll) {
|
|
3726
|
+
const frame = frameOf$2(element) ?? openFrame(element, "end", () => {
|
|
3727
|
+
const running = rolls.get(element);
|
|
3728
|
+
if (running) finishIfIdle(element, running);
|
|
3729
|
+
});
|
|
3730
|
+
const columns = [...before].map(column);
|
|
3731
|
+
frame.holder.append(...columns.map((item) => item.node));
|
|
3732
|
+
frame.width.set(frame.natural());
|
|
3733
|
+
roll = {
|
|
3734
|
+
frame,
|
|
3735
|
+
text: before,
|
|
3736
|
+
value: previous,
|
|
3737
|
+
columns
|
|
3738
|
+
};
|
|
3739
|
+
rolls.set(element, roll);
|
|
3740
|
+
}
|
|
3741
|
+
const state = roll;
|
|
3742
|
+
state.frame.restore();
|
|
3743
|
+
state.text = text;
|
|
3744
|
+
state.value = value;
|
|
3745
|
+
state.frame.name(text);
|
|
3746
|
+
const chars = [...text];
|
|
3747
|
+
const count = Math.max(chars.length, state.columns.length);
|
|
3748
|
+
while (state.columns.length < count) {
|
|
3749
|
+
const added = column("");
|
|
3750
|
+
state.frame.holder.prepend(added.node);
|
|
3751
|
+
state.columns.unshift(added);
|
|
3752
|
+
}
|
|
3753
|
+
const offset = count - chars.length;
|
|
3754
|
+
state.columns.forEach((item, index) => {
|
|
3755
|
+
const next = chars[index - offset] ?? "";
|
|
3756
|
+
if (next === item.char) return;
|
|
3757
|
+
item.char = next;
|
|
3758
|
+
const old = item.current;
|
|
3759
|
+
if (old) {
|
|
3760
|
+
old.fade?.stop();
|
|
3761
|
+
item.leaving.add(old);
|
|
3762
|
+
old.fade = tween(old.shown, 0, reducedMotion ? {
|
|
3763
|
+
duration: crossfade,
|
|
3764
|
+
ease: easeOut
|
|
3765
|
+
} : out, (v) => paint(old, v, -direction, reducedMotion), () => {
|
|
3766
|
+
old.fade = void 0;
|
|
3767
|
+
old.node.remove();
|
|
3768
|
+
item.leaving.delete(old);
|
|
3769
|
+
settleColumns(element, state);
|
|
3770
|
+
});
|
|
3771
|
+
}
|
|
3772
|
+
item.current = void 0;
|
|
3773
|
+
if (!next) return;
|
|
3774
|
+
const incoming = glyph(next);
|
|
3775
|
+
item.current = incoming;
|
|
3776
|
+
item.node.append(incoming.node);
|
|
3777
|
+
paint(incoming, 0, direction, reducedMotion);
|
|
3778
|
+
incoming.fade = tween(0, 1, reducedMotion ? {
|
|
3779
|
+
duration: crossfade,
|
|
3780
|
+
ease: easeOut
|
|
3781
|
+
} : into, (v) => paint(incoming, v, direction, reducedMotion), () => {
|
|
3782
|
+
incoming.fade = void 0;
|
|
3783
|
+
paint(incoming, 1, direction, reducedMotion);
|
|
3784
|
+
settleColumns(element, state);
|
|
3785
|
+
});
|
|
3786
|
+
});
|
|
3787
|
+
const width = state.frame.width;
|
|
3788
|
+
const leavingColumns = state.columns.filter((item) => !item.char);
|
|
3789
|
+
for (const item of leavingColumns) item.node.style.display = "none";
|
|
3790
|
+
const end = state.frame.natural();
|
|
3791
|
+
for (const item of leavingColumns) item.node.style.display = "inline-grid";
|
|
3792
|
+
if (reducedMotion) width.set(end);
|
|
3793
|
+
else width.to(end);
|
|
3794
|
+
}
|
|
3795
|
+
function parseCount(text) {
|
|
3796
|
+
const digits = text.replace(/[^\d.-]/g, "");
|
|
3797
|
+
const value = digits ? Number(digits) : NaN;
|
|
3798
|
+
return Number.isFinite(value) ? value : void 0;
|
|
3799
|
+
}
|
|
3800
|
+
function settleColumns(element, roll) {
|
|
3801
|
+
if (rolls.get(element) !== roll) return;
|
|
3802
|
+
roll.columns = roll.columns.filter((item) => {
|
|
3803
|
+
if (item.char || item.leaving.size) return true;
|
|
3804
|
+
item.node.remove();
|
|
3805
|
+
return false;
|
|
3806
|
+
});
|
|
3807
|
+
finishIfIdle(element, roll);
|
|
3808
|
+
}
|
|
3809
|
+
// src/motion/helpers/shake.ts
|
|
3810
|
+
const duration = .4;
|
|
3811
|
+
const step = cubicBezier(.36, .07, .19, .97);
|
|
3812
|
+
const frames = [
|
|
3813
|
+
[0, 0],
|
|
3814
|
+
[.1, -1],
|
|
3815
|
+
[.2, 3],
|
|
3816
|
+
[.3, -5],
|
|
3817
|
+
[.4, 5],
|
|
3818
|
+
[.5, -5],
|
|
3819
|
+
[.6, 5],
|
|
3820
|
+
[.7, -5],
|
|
3821
|
+
[.8, 3],
|
|
3822
|
+
[.9, -1],
|
|
3823
|
+
[1, 0]
|
|
3824
|
+
];
|
|
3825
|
+
const shaking = /* @__PURE__ */ new WeakMap();
|
|
3826
|
+
/** The offset in pixels at `progress` of the shake: each step between two frames runs on the curve. */
|
|
3827
|
+
function shakeOffset(progress) {
|
|
3828
|
+
const index = Math.max(0, frames.findIndex(([at]) => at >= progress) - 1);
|
|
3829
|
+
const [fromAt, from] = frames[index];
|
|
3830
|
+
const [toAt, to] = frames[index + 1] ?? frames[index];
|
|
3831
|
+
const local = toAt > fromAt ? (progress - fromAt) / (toAt - fromAt) : 1;
|
|
3832
|
+
return from + (to - from) * step(Math.min(1, Math.max(0, local)));
|
|
3833
|
+
}
|
|
3834
|
+
/**
|
|
3835
|
+
* Shakes `element` from side to side once, when it refuses an action but keeps what the person wrote, such as a comment
|
|
3836
|
+
* box that Esc did not close. A second call starts the shake again. Under reduced motion and inside
|
|
3837
|
+
* `data-motion="none"` it does nothing: show the refusal with a color instead.
|
|
3838
|
+
*/
|
|
3839
|
+
function shake(element) {
|
|
3840
|
+
shaking.get(element)?.();
|
|
3841
|
+
if (motionSkipped(element) || reduced()) return;
|
|
3842
|
+
const timeline = playTween(duration, (progress) => writeMotionStyle(element, { translate: progress >= 1 ? null : `${shakeOffset(progress).toFixed(2)}px 0` }));
|
|
3843
|
+
const stop = () => {
|
|
3844
|
+
timeline.stop();
|
|
3845
|
+
shaking.delete(element);
|
|
3846
|
+
writeMotionStyle(element, { translate: null });
|
|
3847
|
+
};
|
|
3848
|
+
shaking.set(element, stop);
|
|
3849
|
+
timeline.done.then((completed) => completed && stop());
|
|
3850
|
+
}
|
|
3851
|
+
// src/motion/helpers/travel.ts
|
|
3852
|
+
/**
|
|
3853
|
+
* The offset that draws a box `rest` as the box `box`, when the scale turns around the point `origin` of the screen.
|
|
3854
|
+
* The layer writes the separate `translate` and `scale` properties, which apply around the same point as the element's
|
|
3855
|
+
* own transform, so the element can keep a transform of its own.
|
|
3856
|
+
*/
|
|
3857
|
+
function travelOffset(rest, origin, box) {
|
|
3858
|
+
const scaleX = rest.width ? box.width / rest.width : 1;
|
|
3859
|
+
const scaleY = rest.height ? box.height / rest.height : 1;
|
|
3860
|
+
return {
|
|
3861
|
+
x: box.left - origin.x - scaleX * (rest.left - origin.x),
|
|
3862
|
+
y: box.top - origin.y - scaleY * (rest.top - origin.y),
|
|
3863
|
+
scaleX,
|
|
3864
|
+
scaleY
|
|
3865
|
+
};
|
|
3866
|
+
}
|
|
3867
|
+
const running = /* @__PURE__ */ new WeakMap();
|
|
3868
|
+
const keys = [
|
|
3869
|
+
"left",
|
|
3870
|
+
"top",
|
|
3871
|
+
"width",
|
|
3872
|
+
"height"
|
|
3873
|
+
];
|
|
3874
|
+
/** The element's box with nothing of the travel written, and the point of the screen that its scale turns around. */
|
|
3875
|
+
function measure(element) {
|
|
3876
|
+
const { translate, scale } = element.style;
|
|
3877
|
+
writeMotionStyle(element, {
|
|
3878
|
+
translate: null,
|
|
3879
|
+
scale: null
|
|
3880
|
+
});
|
|
3881
|
+
const box = element.getBoundingClientRect();
|
|
3882
|
+
writeMotionStyle(element, { scale: "0.5" });
|
|
3883
|
+
const half = element.getBoundingClientRect();
|
|
3884
|
+
writeMotionStyle(element, { translate: "100px 100px" });
|
|
3885
|
+
const shifted = element.getBoundingClientRect();
|
|
3886
|
+
writeMotionStyle(element, {
|
|
3887
|
+
translate,
|
|
3888
|
+
scale
|
|
3889
|
+
});
|
|
3890
|
+
return {
|
|
3891
|
+
box,
|
|
3892
|
+
origin: {
|
|
3893
|
+
x: 2 * half.left - box.left,
|
|
3894
|
+
y: 2 * half.top - box.top
|
|
3895
|
+
},
|
|
3896
|
+
pixels: {
|
|
3897
|
+
x: (shifted.left - half.left) / 100 || 1,
|
|
3898
|
+
y: (shifted.top - half.top) / 100 || 1
|
|
3899
|
+
}
|
|
3900
|
+
};
|
|
3901
|
+
}
|
|
3902
|
+
/**
|
|
3903
|
+
* Rule 8 for a thing that moves to a new place: a picture that opens larger from where it is in the page, and goes back
|
|
3904
|
+
* there when it closes. The element travels from `from` to its own place, or from where it is to `to`, on a spring for
|
|
3905
|
+
* each of its position and its size, and keeps its speed when a new travel starts in the middle of one.
|
|
3906
|
+
*
|
|
3907
|
+
* The page lays the element out at its new place first; the travel only draws it on the way there, with `translate`
|
|
3908
|
+
* and `scale`. Under reduced motion and inside `data-motion="none"` a new travel leaves the element at its own place,
|
|
3909
|
+
* and `done` is false. If reduced motion turns on during a travel, it lands at once.
|
|
3910
|
+
*/
|
|
3911
|
+
function travel(element, options) {
|
|
3912
|
+
const previous = running.get(element);
|
|
3913
|
+
if (motionSkipped(element) || reduced()) {
|
|
3914
|
+
previous?.stop();
|
|
3915
|
+
return {
|
|
3916
|
+
done: Promise.resolve(false),
|
|
3917
|
+
stop() {}
|
|
3918
|
+
};
|
|
3919
|
+
}
|
|
3920
|
+
const { box, origin, pixels } = measure(element);
|
|
3921
|
+
const target = options.to ?? box;
|
|
3922
|
+
const preset = options.preset ?? springs.snappy;
|
|
3923
|
+
let finish;
|
|
3924
|
+
const done = new Promise((resolve) => {
|
|
3925
|
+
finish = resolve;
|
|
3926
|
+
});
|
|
3927
|
+
const draw = () => {
|
|
3928
|
+
if (running.get(element) !== motion) return;
|
|
3929
|
+
const offset = travelOffset(box, origin, {
|
|
3930
|
+
left: parts.left.value,
|
|
3931
|
+
top: parts.top.value,
|
|
3932
|
+
width: parts.width.value,
|
|
3933
|
+
height: parts.height.value
|
|
3934
|
+
});
|
|
3935
|
+
writeMotionStyle(element, {
|
|
3936
|
+
translate: `${offset.x / pixels.x}px ${offset.y / pixels.y}px`,
|
|
3937
|
+
scale: `${offset.scaleX} ${offset.scaleY}`
|
|
3938
|
+
});
|
|
3939
|
+
if (keys.some((key) => parts[key].active)) return;
|
|
3940
|
+
unwatch();
|
|
3941
|
+
if (!options.to) {
|
|
3942
|
+
running.delete(element);
|
|
3943
|
+
writeMotionStyle(element, {
|
|
3944
|
+
translate: null,
|
|
3945
|
+
scale: null
|
|
3946
|
+
});
|
|
3947
|
+
}
|
|
3948
|
+
finish(true);
|
|
3949
|
+
};
|
|
3950
|
+
const spring = (key) => createSpring(options.from?.[key] ?? previous?.parts[key].value ?? box[key], draw, preset);
|
|
3951
|
+
const parts = {
|
|
3952
|
+
left: spring("left"),
|
|
3953
|
+
top: spring("top"),
|
|
3954
|
+
width: spring("width"),
|
|
3955
|
+
height: spring("height")
|
|
3956
|
+
};
|
|
3957
|
+
const velocity = keys.map((key) => previous?.parts[key].velocity ?? 0);
|
|
3958
|
+
const unwatch = onReducedMotionChange((isReduced) => {
|
|
3959
|
+
if (isReduced) for (const key of keys) parts[key].set(target[key]);
|
|
3960
|
+
});
|
|
3961
|
+
const motion = {
|
|
3962
|
+
parts,
|
|
3963
|
+
stop() {
|
|
3964
|
+
if (running.get(element) !== motion) return;
|
|
3965
|
+
unwatch();
|
|
3966
|
+
for (const key of keys) parts[key].stop();
|
|
3967
|
+
running.delete(element);
|
|
3968
|
+
writeMotionStyle(element, {
|
|
3969
|
+
translate: null,
|
|
3970
|
+
scale: null
|
|
3971
|
+
});
|
|
3972
|
+
finish(false);
|
|
3973
|
+
}
|
|
3974
|
+
};
|
|
3975
|
+
previous?.stop();
|
|
3976
|
+
running.set(element, motion);
|
|
3977
|
+
keys.forEach((key, index) => parts[key].to(target[key], { velocity: velocity[index] }));
|
|
3978
|
+
draw();
|
|
3979
|
+
return {
|
|
3980
|
+
done,
|
|
3981
|
+
stop: motion.stop
|
|
3982
|
+
};
|
|
3983
|
+
}
|
|
3984
|
+
// src/motion/list.ts
|
|
3985
|
+
const grow = {
|
|
3986
|
+
stiffness: 380,
|
|
3987
|
+
damping: 26
|
|
3988
|
+
};
|
|
3989
|
+
const fold = {
|
|
3990
|
+
stiffness: 260,
|
|
3991
|
+
damping: 28
|
|
3992
|
+
};
|
|
3993
|
+
const slotScale = .9;
|
|
3994
|
+
const leaveDuration = .32;
|
|
3995
|
+
const leaveEasing = cubicBezier(.5, 0, .75, 0);
|
|
3996
|
+
const ghostAttribute = "data-motion-ghost";
|
|
3997
|
+
const center = (rect) => ({
|
|
3998
|
+
x: rect.left + rect.width / 2,
|
|
3999
|
+
y: rect.top + rect.height / 2
|
|
4000
|
+
});
|
|
4001
|
+
function onScreen(rect) {
|
|
4002
|
+
return rect.bottom > 0 && rect.right > 0 && rect.top < innerHeight && rect.left < innerWidth && rect.width + rect.height > 0;
|
|
4003
|
+
}
|
|
4004
|
+
function defaultItems(container) {
|
|
4005
|
+
return [...container.children].filter((child) => child instanceof HTMLElement && !child.hasAttribute(ghostAttribute));
|
|
4006
|
+
}
|
|
4007
|
+
/**
|
|
4008
|
+
* The list mover of docs/design/motion.md: "Items are added, removed, or reordered". It is FLIP with the springs of the
|
|
4009
|
+
* motion layer. Call `measure()` before a change and `play()` after it.
|
|
4010
|
+
*
|
|
4011
|
+
* Neighbors spring to their new place and keep their speed when a second change comes before they settle. A new item
|
|
4012
|
+
* grows from its origin, such as the row it duplicates, or from its slot. A removed item folds away, or leaves toward
|
|
4013
|
+
* `target`. Items that are off screen before and after the change do not move, so a long list costs one read per item.
|
|
4014
|
+
* Under reduced motion nothing travels: a new item and a removed item cross-fade in 150ms. Inside `data-motion="none"`
|
|
4015
|
+
* nothing moves.
|
|
4016
|
+
*/
|
|
4017
|
+
function createMotionList(container, options = {}) {
|
|
4018
|
+
const items = options.items ?? defaultItems;
|
|
4019
|
+
const motions = /* @__PURE__ */ new Map();
|
|
4020
|
+
const ghosts = /* @__PURE__ */ new Set();
|
|
4021
|
+
let snapshot = /* @__PURE__ */ new Map();
|
|
4022
|
+
let starting = false;
|
|
4023
|
+
function offset(motion) {
|
|
4024
|
+
if (!motion) return {
|
|
4025
|
+
x: 0,
|
|
4026
|
+
y: 0
|
|
4027
|
+
};
|
|
4028
|
+
const rest = 1 - motion.grow.value;
|
|
4029
|
+
return {
|
|
4030
|
+
x: motion.x.value + motion.from.x * rest,
|
|
4031
|
+
y: motion.y.value + motion.from.y * rest
|
|
4032
|
+
};
|
|
4033
|
+
}
|
|
4034
|
+
function write(element, motion) {
|
|
4035
|
+
const { x, y, grow, from } = motion;
|
|
4036
|
+
if (!x.active && !y.active && !grow.active && x.value === 0 && y.value === 0 && grow.value === 1) {
|
|
4037
|
+
writeMotionStyle(element, {
|
|
4038
|
+
translate: null,
|
|
4039
|
+
scale: null,
|
|
4040
|
+
opacity: null
|
|
4041
|
+
});
|
|
4042
|
+
if (!starting) motions.delete(element);
|
|
4043
|
+
return;
|
|
4044
|
+
}
|
|
4045
|
+
const { x: dx, y: dy } = offset(motion);
|
|
4046
|
+
const scale = from.scale + (1 - from.scale) * grow.value;
|
|
4047
|
+
writeMotionStyle(element, {
|
|
4048
|
+
translate: dx || dy ? `${dx.toFixed(2)}px ${dy.toFixed(2)}px` : null,
|
|
4049
|
+
scale: scale === 1 ? null : scale.toFixed(4),
|
|
4050
|
+
opacity: grow.value >= 1 ? null : Math.max(0, Math.min(1, grow.value)).toFixed(3)
|
|
4051
|
+
});
|
|
4052
|
+
}
|
|
4053
|
+
function motionOf(element) {
|
|
4054
|
+
let motion = motions.get(element);
|
|
4055
|
+
if (motion) return motion;
|
|
4056
|
+
const draw = () => motion && write(element, motion);
|
|
4057
|
+
motion = {
|
|
4058
|
+
x: createSpring(0, draw, springs.snappy),
|
|
4059
|
+
y: createSpring(0, draw, springs.snappy),
|
|
4060
|
+
grow: createSpring(1, draw, grow),
|
|
4061
|
+
from: {
|
|
4062
|
+
x: 0,
|
|
4063
|
+
y: 0,
|
|
4064
|
+
scale: 1
|
|
4065
|
+
}
|
|
4066
|
+
};
|
|
4067
|
+
motions.set(element, motion);
|
|
4068
|
+
return motion;
|
|
4069
|
+
}
|
|
4070
|
+
function stopItem(element) {
|
|
4071
|
+
const motion = motions.get(element);
|
|
4072
|
+
if (!motion) return;
|
|
4073
|
+
motions.delete(element);
|
|
4074
|
+
motion.x.stop();
|
|
4075
|
+
motion.y.stop();
|
|
4076
|
+
motion.grow.stop();
|
|
4077
|
+
writeMotionStyle(element, {
|
|
4078
|
+
translate: null,
|
|
4079
|
+
scale: null,
|
|
4080
|
+
opacity: null
|
|
4081
|
+
});
|
|
4082
|
+
}
|
|
4083
|
+
function travel(spring, from) {
|
|
4084
|
+
const velocity = spring.velocity;
|
|
4085
|
+
spring.set(from);
|
|
4086
|
+
spring.to(0, {
|
|
4087
|
+
preset: springs.snappy,
|
|
4088
|
+
velocity
|
|
4089
|
+
});
|
|
4090
|
+
}
|
|
4091
|
+
function leave(element, before, target) {
|
|
4092
|
+
if (!onScreen(before)) return;
|
|
4093
|
+
const box = container.getBoundingClientRect();
|
|
4094
|
+
if (getComputedStyle(container).position === "static") container.style.position = "relative";
|
|
4095
|
+
const ghost = visualCopy(element);
|
|
4096
|
+
ghost.setAttribute(ghostAttribute, "");
|
|
4097
|
+
Object.assign(ghost.style, {
|
|
4098
|
+
boxSizing: "border-box",
|
|
4099
|
+
height: `${before.height}px`,
|
|
4100
|
+
left: `${before.left - box.left - container.clientLeft + container.scrollLeft}px`,
|
|
4101
|
+
margin: "0",
|
|
4102
|
+
pointerEvents: "none",
|
|
4103
|
+
position: "absolute",
|
|
4104
|
+
top: `${before.top - box.top - container.clientTop + container.scrollTop}px`,
|
|
4105
|
+
width: `${before.width}px`
|
|
4106
|
+
});
|
|
4107
|
+
writeMotionStyle(ghost, {
|
|
4108
|
+
translate: null,
|
|
4109
|
+
scale: null,
|
|
4110
|
+
opacity: null,
|
|
4111
|
+
filter: null
|
|
4112
|
+
});
|
|
4113
|
+
container.append(ghost);
|
|
4114
|
+
const entry = {
|
|
4115
|
+
element: ghost,
|
|
4116
|
+
stop: () => {}
|
|
4117
|
+
};
|
|
4118
|
+
const end = () => {
|
|
4119
|
+
entry.stop();
|
|
4120
|
+
ghost.remove();
|
|
4121
|
+
ghosts.delete(entry);
|
|
4122
|
+
};
|
|
4123
|
+
ghosts.add(entry);
|
|
4124
|
+
if (prefersReducedMotion()) {
|
|
4125
|
+
const tween = playTween(.15, (p) => writeMotionStyle(ghost, { opacity: (1 - p).toFixed(3) }));
|
|
4126
|
+
entry.stop = tween.stop;
|
|
4127
|
+
tween.done.then(end);
|
|
4128
|
+
return;
|
|
4129
|
+
}
|
|
4130
|
+
if (target) {
|
|
4131
|
+
const to = center(target.getBoundingClientRect());
|
|
4132
|
+
const from = center(before);
|
|
4133
|
+
const tween = playTween(leaveDuration, (p) => {
|
|
4134
|
+
writeMotionStyle(ghost, {
|
|
4135
|
+
translate: `${((to.x - from.x) * p).toFixed(2)}px ${((to.y - from.y) * p).toFixed(2)}px`,
|
|
4136
|
+
scale: (1 - .8 * p).toFixed(4),
|
|
4137
|
+
opacity: (1 - p).toFixed(3),
|
|
4138
|
+
filter: p > 0 ? `blur(${(3 * p).toFixed(2)}px)` : null
|
|
4139
|
+
});
|
|
4140
|
+
}, leaveEasing);
|
|
4141
|
+
entry.stop = tween.stop;
|
|
4142
|
+
tween.done.then(end);
|
|
4143
|
+
return;
|
|
4144
|
+
}
|
|
4145
|
+
const spring = createSpring(1, (value) => {
|
|
4146
|
+
writeMotionStyle(ghost, {
|
|
4147
|
+
scale: (slotScale + .09999999999999998 * value).toFixed(4),
|
|
4148
|
+
opacity: Math.max(0, value).toFixed(3)
|
|
4149
|
+
});
|
|
4150
|
+
if (value < .02) end();
|
|
4151
|
+
}, fold);
|
|
4152
|
+
entry.stop = () => spring.stop();
|
|
4153
|
+
spring.to(0);
|
|
4154
|
+
}
|
|
4155
|
+
return {
|
|
4156
|
+
measure() {
|
|
4157
|
+
snapshot = /* @__PURE__ */ new Map();
|
|
4158
|
+
for (const element of items(container)) {
|
|
4159
|
+
const rect = element.getBoundingClientRect();
|
|
4160
|
+
if (!rect.width && !rect.height) continue;
|
|
4161
|
+
const now = center(rect);
|
|
4162
|
+
const shift = offset(motions.get(element));
|
|
4163
|
+
snapshot.set(element, {
|
|
4164
|
+
x: now.x - shift.x,
|
|
4165
|
+
y: now.y - shift.y,
|
|
4166
|
+
rect
|
|
4167
|
+
});
|
|
4168
|
+
}
|
|
4169
|
+
},
|
|
4170
|
+
play(play = {}) {
|
|
4171
|
+
const before = snapshot;
|
|
4172
|
+
snapshot = /* @__PURE__ */ new Map();
|
|
4173
|
+
const off = isMotionOff(container);
|
|
4174
|
+
const current = items(container);
|
|
4175
|
+
const present = new Set(current);
|
|
4176
|
+
const reads = current.map((element) => {
|
|
4177
|
+
const rect = element.getBoundingClientRect();
|
|
4178
|
+
const shift = offset(motions.get(element));
|
|
4179
|
+
const now = center(rect);
|
|
4180
|
+
return {
|
|
4181
|
+
element,
|
|
4182
|
+
rect,
|
|
4183
|
+
layout: {
|
|
4184
|
+
x: now.x - shift.x,
|
|
4185
|
+
y: now.y - shift.y
|
|
4186
|
+
}
|
|
4187
|
+
};
|
|
4188
|
+
});
|
|
4189
|
+
const origins = reads.map(({ element }) => {
|
|
4190
|
+
if (before.has(element) || !play.origin) return void 0;
|
|
4191
|
+
return (typeof play.origin === "function" ? play.origin(element) : play.origin)?.getBoundingClientRect();
|
|
4192
|
+
});
|
|
4193
|
+
for (const [element, { rect }] of before) {
|
|
4194
|
+
if (present.has(element)) continue;
|
|
4195
|
+
stopItem(element);
|
|
4196
|
+
if (!off && !options.movesOnly && !element.hasAttribute("data-motion-leaving")) leave(element, rect, play.target);
|
|
4197
|
+
}
|
|
4198
|
+
starting = true;
|
|
4199
|
+
reads.forEach(({ element, rect, layout }, index) => {
|
|
4200
|
+
if (off) return stopItem(element);
|
|
4201
|
+
const old = before.get(element);
|
|
4202
|
+
if (old) {
|
|
4203
|
+
const dx = old.x - layout.x;
|
|
4204
|
+
const dy = old.y - layout.y;
|
|
4205
|
+
if (Math.abs(dx) < .5 && Math.abs(dy) < .5) return;
|
|
4206
|
+
if (!onScreen(old.rect) && !onScreen(rect)) return stopItem(element);
|
|
4207
|
+
const motion = motionOf(element);
|
|
4208
|
+
travel(motion.x, motion.x.value + dx);
|
|
4209
|
+
travel(motion.y, motion.y.value + dy);
|
|
4210
|
+
return;
|
|
4211
|
+
}
|
|
4212
|
+
if (!onScreen(rect) || options.movesOnly) return;
|
|
4213
|
+
const motion = motionOf(element);
|
|
4214
|
+
const origin = origins[index];
|
|
4215
|
+
if (prefersReducedMotion()) motion.from = {
|
|
4216
|
+
x: 0,
|
|
4217
|
+
y: 0,
|
|
4218
|
+
scale: 1
|
|
4219
|
+
};
|
|
4220
|
+
else if (origin) {
|
|
4221
|
+
const start = center(origin);
|
|
4222
|
+
const scale = Math.min(1, Math.max(.2, Math.min(origin.width / (rect.width || 1), origin.height / (rect.height || 1))));
|
|
4223
|
+
motion.from = {
|
|
4224
|
+
x: start.x - layout.x,
|
|
4225
|
+
y: start.y - layout.y,
|
|
4226
|
+
scale
|
|
4227
|
+
};
|
|
4228
|
+
} else motion.from = {
|
|
4229
|
+
x: 0,
|
|
4230
|
+
y: 0,
|
|
4231
|
+
scale: slotScale
|
|
4232
|
+
};
|
|
4233
|
+
motion.grow.set(0);
|
|
4234
|
+
motion.grow.to(1, prefersReducedMotion() ? { tween: .15 } : { preset: grow });
|
|
4235
|
+
});
|
|
4236
|
+
starting = false;
|
|
4237
|
+
},
|
|
4238
|
+
destroy() {
|
|
4239
|
+
for (const element of motions.keys()) stopItem(element);
|
|
4240
|
+
for (const ghost of ghosts) {
|
|
4241
|
+
ghost.stop();
|
|
4242
|
+
ghost.element.remove();
|
|
4243
|
+
}
|
|
4244
|
+
ghosts.clear();
|
|
4245
|
+
snapshot = /* @__PURE__ */ new Map();
|
|
4246
|
+
}
|
|
4247
|
+
};
|
|
4248
|
+
}
|
|
4249
|
+
// src/motion/progress.ts
|
|
4250
|
+
const svgNs = "http://www.w3.org/2000/svg";
|
|
4251
|
+
const height = 8;
|
|
4252
|
+
const rail = 2;
|
|
4253
|
+
const bar = 4;
|
|
4254
|
+
const bulge = 4;
|
|
4255
|
+
const headWidth = 10;
|
|
4256
|
+
const waveWidth = 36;
|
|
4257
|
+
const waveSpeed = 260;
|
|
4258
|
+
const settleRate = 3;
|
|
4259
|
+
const tickEasing = cubicBezier(.6, 0, .2, 1);
|
|
4260
|
+
const tickPath = "M5 12.5l4.5 4.5L19 7.5";
|
|
4261
|
+
function svg(tag, attributes) {
|
|
4262
|
+
const element = document.createElementNS(svgNs, tag);
|
|
4263
|
+
for (const [name, value] of Object.entries(attributes)) element.setAttribute(name, value);
|
|
4264
|
+
return element;
|
|
4265
|
+
}
|
|
4266
|
+
function line(x0, x1, thickness) {
|
|
4267
|
+
const y = height / 2;
|
|
4268
|
+
const top = [];
|
|
4269
|
+
const bottom = [];
|
|
4270
|
+
for (let x = x0; x <= x1 + .01; x += 1.5) {
|
|
4271
|
+
const half = thickness(Math.min(x, x1)) / 2;
|
|
4272
|
+
top.push(`${Math.min(x, x1).toFixed(2)} ${(y - half).toFixed(2)}`);
|
|
4273
|
+
bottom.unshift(`${Math.min(x, x1).toFixed(2)} ${(y + half).toFixed(2)}`);
|
|
4274
|
+
}
|
|
4275
|
+
if (!top.length) return "";
|
|
4276
|
+
const end = thickness(x1) / 2;
|
|
4277
|
+
const start = thickness(x0) / 2;
|
|
4278
|
+
return `M${top.join("L")}A${end.toFixed(2)} ${end.toFixed(2)} 0 0 1 ${bottom[0]}L${bottom.join("L")}A${start.toFixed(2)} ${start.toFixed(2)} 0 0 1 ${top[0]}Z`;
|
|
4279
|
+
}
|
|
4280
|
+
/**
|
|
4281
|
+
* The progress helper of docs/design/motion.md: "Work runs". It draws into `host`: a bar with a head while it fills, a
|
|
4282
|
+
* wave while it processes with no known total, and a dot that draws into a check when the work is done.
|
|
4283
|
+
*
|
|
4284
|
+
* The host gets `role="progressbar"` with `aria-valuenow` from 0 to 100, no `aria-valuenow` during the wave, and
|
|
4285
|
+
* `data-phase`. The bar uses `currentColor`, and the rail `--vh-progress-rail` or the Nuxt UI accented border color.
|
|
4286
|
+
* Under reduced motion the bar jumps to its value, there is no head or wave, and the check cross-fades in 150ms. Inside
|
|
4287
|
+
* `data-motion="none"` the bar jumps and the check shows at once.
|
|
4288
|
+
*/
|
|
4289
|
+
function createProgress(host, options = {}) {
|
|
4290
|
+
const chart = svg("svg", {
|
|
4291
|
+
"aria-hidden": "true",
|
|
4292
|
+
"data-part": "bar",
|
|
4293
|
+
height: String(height),
|
|
4294
|
+
preserveAspectRatio: "none"
|
|
4295
|
+
});
|
|
4296
|
+
const railPath = svg("path", {
|
|
4297
|
+
"data-part": "rail",
|
|
4298
|
+
fill: "var(--vh-progress-rail, var(--ui-border-accented, color-mix(in oklch, currentColor 20%, transparent)))"
|
|
4299
|
+
});
|
|
4300
|
+
const fillPath = svg("path", {
|
|
4301
|
+
"data-part": "fill",
|
|
4302
|
+
fill: "currentColor"
|
|
4303
|
+
});
|
|
4304
|
+
chart.append(railPath, fillPath);
|
|
4305
|
+
const check = svg("svg", {
|
|
4306
|
+
"aria-hidden": "true",
|
|
4307
|
+
"data-part": "check",
|
|
4308
|
+
fill: "none",
|
|
4309
|
+
stroke: "currentColor",
|
|
4310
|
+
"stroke-linecap": "round",
|
|
4311
|
+
"stroke-linejoin": "round",
|
|
4312
|
+
"stroke-width": "2",
|
|
4313
|
+
viewBox: "0 0 24 24"
|
|
4314
|
+
});
|
|
4315
|
+
const dot = svg("circle", {
|
|
4316
|
+
cx: "12",
|
|
4317
|
+
cy: "12",
|
|
4318
|
+
fill: "currentColor",
|
|
4319
|
+
r: "0",
|
|
4320
|
+
stroke: "none"
|
|
4321
|
+
});
|
|
4322
|
+
const tick = svg("path", {
|
|
4323
|
+
d: tickPath,
|
|
4324
|
+
pathLength: "1",
|
|
4325
|
+
"stroke-dasharray": "1",
|
|
4326
|
+
"stroke-dashoffset": "1"
|
|
4327
|
+
});
|
|
4328
|
+
check.append(dot, tick);
|
|
4329
|
+
Object.assign(chart.style, {
|
|
4330
|
+
display: "block",
|
|
4331
|
+
flex: "1 1 auto",
|
|
4332
|
+
minWidth: "0",
|
|
4333
|
+
overflow: "visible",
|
|
4334
|
+
width: "100%"
|
|
4335
|
+
});
|
|
4336
|
+
Object.assign(check.style, {
|
|
4337
|
+
flex: "none",
|
|
4338
|
+
height: "18px",
|
|
4339
|
+
width: "18px"
|
|
4340
|
+
});
|
|
4341
|
+
if (!host.style.display) Object.assign(host.style, {
|
|
4342
|
+
alignItems: "center",
|
|
4343
|
+
display: "flex",
|
|
4344
|
+
gap: "8px"
|
|
4345
|
+
});
|
|
4346
|
+
host.append(chart, check);
|
|
4347
|
+
host.setAttribute("role", "progressbar");
|
|
4348
|
+
host.setAttribute("aria-valuemin", "0");
|
|
4349
|
+
host.setAttribute("aria-valuemax", "100");
|
|
4350
|
+
if (options.label && !host.hasAttribute("aria-label")) host.setAttribute("aria-label", options.label);
|
|
4351
|
+
let phase = "idle";
|
|
4352
|
+
let width = chart.clientWidth;
|
|
4353
|
+
let wave = -40;
|
|
4354
|
+
let flat = 0;
|
|
4355
|
+
let stopWave;
|
|
4356
|
+
let stopTimeline = [];
|
|
4357
|
+
const still = () => prefersReducedMotion() || isMotionOff(host);
|
|
4358
|
+
const end = createSpring(0, () => draw(), springs.snappy);
|
|
4359
|
+
function draw() {
|
|
4360
|
+
width = chart.clientWidth || width;
|
|
4361
|
+
chart.setAttribute("viewBox", `0 0 ${Math.max(1, width)} ${height}`);
|
|
4362
|
+
const x0 = 2;
|
|
4363
|
+
const x1 = Math.max(x0, width - 2);
|
|
4364
|
+
railPath.setAttribute("d", line(x0, x1, () => rail));
|
|
4365
|
+
const shape = still() ? 0 : 1 - flat;
|
|
4366
|
+
if (phase === "wave" || phase === "done" && flat < 1 && stopWave) {
|
|
4367
|
+
fillPath.setAttribute("d", line(x0, x1, (x) => bar + bulge * shape * Math.exp(-(((x - wave) / waveWidth) ** 2))));
|
|
4368
|
+
return;
|
|
4369
|
+
}
|
|
4370
|
+
const head = x0 + (x1 - x0) * Math.max(0, Math.min(1, end.value));
|
|
4371
|
+
fillPath.setAttribute("d", phase === "idle" ? "" : line(x0, Math.max(x0, head), (x) => bar + bulge * shape * Math.exp(-(((x - head + headWidth) / headWidth) ** 2))));
|
|
4372
|
+
}
|
|
4373
|
+
function setPhase(next) {
|
|
4374
|
+
phase = next;
|
|
4375
|
+
host.dataset.phase = next;
|
|
4376
|
+
host.setAttribute("aria-busy", String(next === "fill" || next === "wave"));
|
|
4377
|
+
}
|
|
4378
|
+
function stopAll() {
|
|
4379
|
+
stopWave?.();
|
|
4380
|
+
stopWave = void 0;
|
|
4381
|
+
for (const stop of stopTimeline) stop();
|
|
4382
|
+
stopTimeline = [];
|
|
4383
|
+
}
|
|
4384
|
+
function startWave() {
|
|
4385
|
+
if (stopWave || still()) return;
|
|
4386
|
+
wave = -40;
|
|
4387
|
+
stopWave = onEachFrame((seconds) => {
|
|
4388
|
+
if (phase === "done") {
|
|
4389
|
+
flat = Math.min(1, flat + seconds * settleRate);
|
|
4390
|
+
wave += waveSpeed * seconds;
|
|
4391
|
+
draw();
|
|
4392
|
+
if (flat < 1) return true;
|
|
4393
|
+
end.set(1);
|
|
4394
|
+
stopWave = void 0;
|
|
4395
|
+
draw();
|
|
4396
|
+
drawCheck();
|
|
4397
|
+
return false;
|
|
4398
|
+
}
|
|
4399
|
+
wave = -40 + (wave + 40 + waveSpeed * seconds) % (width + 80);
|
|
4400
|
+
draw();
|
|
4401
|
+
return true;
|
|
4402
|
+
});
|
|
4403
|
+
}
|
|
4404
|
+
function clearCheck() {
|
|
4405
|
+
dot.setAttribute("r", "0");
|
|
4406
|
+
tick.setAttribute("stroke-dashoffset", "1");
|
|
4407
|
+
check.style.opacity = "";
|
|
4408
|
+
}
|
|
4409
|
+
function drawCheck() {
|
|
4410
|
+
if (isMotionOff(host)) {
|
|
4411
|
+
tick.setAttribute("stroke-dashoffset", "0");
|
|
4412
|
+
return;
|
|
4413
|
+
}
|
|
4414
|
+
if (prefersReducedMotion()) {
|
|
4415
|
+
check.style.opacity = "0";
|
|
4416
|
+
tick.setAttribute("stroke-dashoffset", "0");
|
|
4417
|
+
const fade = playTween(.15, (p) => check.style.opacity = p.toFixed(3));
|
|
4418
|
+
stopTimeline.push(fade.stop);
|
|
4419
|
+
return;
|
|
4420
|
+
}
|
|
4421
|
+
const grow = playTween(.32, (p) => {
|
|
4422
|
+
dot.setAttribute("r", (p <= .5 ? 7 * p : 3.5 - 3 * (p - .5)).toFixed(3));
|
|
4423
|
+
}, easeOut);
|
|
4424
|
+
stopTimeline.push(grow.stop);
|
|
4425
|
+
grow.done.then((completed) => {
|
|
4426
|
+
if (!completed) return;
|
|
4427
|
+
const shrink = playTween(.12, (p) => dot.setAttribute("r", (2 - 2 * p).toFixed(3)));
|
|
4428
|
+
const draw = playTween(.32, (p) => tick.setAttribute("stroke-dashoffset", (1 - p).toFixed(4)), tickEasing);
|
|
4429
|
+
stopTimeline.push(shrink.stop, draw.stop);
|
|
4430
|
+
});
|
|
4431
|
+
}
|
|
4432
|
+
function settleFill() {
|
|
4433
|
+
if (still()) {
|
|
4434
|
+
flat = 1;
|
|
4435
|
+
draw();
|
|
4436
|
+
drawCheck();
|
|
4437
|
+
return;
|
|
4438
|
+
}
|
|
4439
|
+
const wait = onEachFrame(() => {
|
|
4440
|
+
if (end.active) return true;
|
|
4441
|
+
const flatten = playTween(1 / settleRate, (p) => {
|
|
4442
|
+
flat = p;
|
|
4443
|
+
draw();
|
|
4444
|
+
});
|
|
4445
|
+
stopTimeline.push(flatten.stop);
|
|
4446
|
+
flatten.done.then((completed) => completed && drawCheck());
|
|
4447
|
+
return false;
|
|
4448
|
+
});
|
|
4449
|
+
stopTimeline.push(wait);
|
|
4450
|
+
}
|
|
4451
|
+
const resize = typeof ResizeObserver === "function" ? new ResizeObserver(() => draw()) : void 0;
|
|
4452
|
+
resize?.observe(chart);
|
|
4453
|
+
setPhase("idle");
|
|
4454
|
+
draw();
|
|
4455
|
+
return {
|
|
4456
|
+
get phase() {
|
|
4457
|
+
return phase;
|
|
4458
|
+
},
|
|
4459
|
+
set(value) {
|
|
4460
|
+
if (phase === "done") {
|
|
4461
|
+
stopAll();
|
|
4462
|
+
clearCheck();
|
|
4463
|
+
flat = 0;
|
|
4464
|
+
}
|
|
4465
|
+
if (value === null) {
|
|
4466
|
+
host.removeAttribute("aria-valuenow");
|
|
4467
|
+
setPhase("wave");
|
|
4468
|
+
startWave();
|
|
4469
|
+
draw();
|
|
4470
|
+
return;
|
|
4471
|
+
}
|
|
4472
|
+
const fraction = Math.max(0, Math.min(1, value));
|
|
4473
|
+
host.setAttribute("aria-valuenow", String(Math.round(fraction * 100)));
|
|
4474
|
+
if (phase === "wave") {
|
|
4475
|
+
stopWave?.();
|
|
4476
|
+
stopWave = void 0;
|
|
4477
|
+
}
|
|
4478
|
+
if (phase !== "fill") setPhase("fill");
|
|
4479
|
+
if (still()) end.set(fraction);
|
|
4480
|
+
else end.to(fraction);
|
|
4481
|
+
},
|
|
4482
|
+
done() {
|
|
4483
|
+
if (phase === "done") return;
|
|
4484
|
+
host.setAttribute("aria-valuenow", "100");
|
|
4485
|
+
const fromWave = phase === "wave" && stopWave !== void 0;
|
|
4486
|
+
setPhase("done");
|
|
4487
|
+
flat = 0;
|
|
4488
|
+
if (fromWave) return;
|
|
4489
|
+
if (still()) end.set(1);
|
|
4490
|
+
else end.to(1);
|
|
4491
|
+
settleFill();
|
|
4492
|
+
},
|
|
4493
|
+
reset() {
|
|
4494
|
+
stopAll();
|
|
4495
|
+
clearCheck();
|
|
4496
|
+
flat = 0;
|
|
4497
|
+
end.set(0);
|
|
4498
|
+
host.setAttribute("aria-valuenow", "0");
|
|
4499
|
+
setPhase("idle");
|
|
4500
|
+
draw();
|
|
4501
|
+
},
|
|
4502
|
+
destroy() {
|
|
4503
|
+
stopAll();
|
|
4504
|
+
end.stop();
|
|
4505
|
+
resize?.disconnect();
|
|
4506
|
+
chart.remove();
|
|
4507
|
+
check.remove();
|
|
4508
|
+
}
|
|
4509
|
+
};
|
|
4510
|
+
}
|
|
4511
|
+
// src/motion/drop-field.ts
|
|
4512
|
+
const gap = 14;
|
|
4513
|
+
const reach = 110;
|
|
4514
|
+
const lean = 3;
|
|
4515
|
+
const powerRate = .15;
|
|
4516
|
+
const dotRate = .2;
|
|
4517
|
+
const carriesFiles = (event) => [...event.dataTransfer?.types ?? []].includes("Files");
|
|
4518
|
+
const rate = (perFrame, seconds) => 1 - (1 - perFrame) ** (seconds * 60);
|
|
4519
|
+
/**
|
|
4520
|
+
* The drop field of docs/design/motion.md: "Files are dragged in". A grid of dots behind the content of `surface` leans
|
|
4521
|
+
* toward the dragged file and rests again when it leaves or drops. It wraps the native file drop of `field`: the drag
|
|
4522
|
+
* events, `dropEffect`, and `onFiles`. A click or a key that opens a file picker stays with the field's own controls.
|
|
4523
|
+
*
|
|
4524
|
+
* The dots use `--vh-drop-dot`, or the text color of the surface. Under reduced motion and inside `data-motion="none"`
|
|
4525
|
+
* the dots stay still; `data-over` still marks the field, so its colors change.
|
|
4526
|
+
*/
|
|
4527
|
+
function createDropField(field, options = {}) {
|
|
4528
|
+
const surface = options.surface ?? field;
|
|
4529
|
+
const accepts = options.accepts ?? carriesFiles;
|
|
4530
|
+
const canvas = document.createElement("canvas");
|
|
4531
|
+
canvas.dataset.part = "dots";
|
|
4532
|
+
canvas.setAttribute("aria-hidden", "true");
|
|
4533
|
+
Object.assign(canvas.style, {
|
|
4534
|
+
height: "100%",
|
|
4535
|
+
inset: "0",
|
|
4536
|
+
pointerEvents: "none",
|
|
4537
|
+
position: "absolute",
|
|
4538
|
+
width: "100%",
|
|
4539
|
+
zIndex: "-1"
|
|
4540
|
+
});
|
|
4541
|
+
if (getComputedStyle(surface).position === "static") surface.style.position = "relative";
|
|
4542
|
+
surface.style.isolation = "isolate";
|
|
4543
|
+
surface.prepend(canvas);
|
|
4544
|
+
const context = canvas.getContext("2d");
|
|
4545
|
+
let dots = [];
|
|
4546
|
+
let pointer = {
|
|
4547
|
+
x: -999,
|
|
4548
|
+
y: -999
|
|
4549
|
+
};
|
|
4550
|
+
let over = false;
|
|
4551
|
+
let depth = 0;
|
|
4552
|
+
let power = 0;
|
|
4553
|
+
let stop;
|
|
4554
|
+
const still = () => prefersReducedMotion() || isMotionOff(surface);
|
|
4555
|
+
function build() {
|
|
4556
|
+
dots = [];
|
|
4557
|
+
for (let y = 10; y < surface.clientHeight; y += gap) for (let x = 10; x < surface.clientWidth; x += gap) dots.push({
|
|
4558
|
+
x,
|
|
4559
|
+
y,
|
|
4560
|
+
pull: 0
|
|
4561
|
+
});
|
|
4562
|
+
}
|
|
4563
|
+
function draw(seconds) {
|
|
4564
|
+
if (!context) return false;
|
|
4565
|
+
const ratio = devicePixelRatio || 1;
|
|
4566
|
+
const width = surface.clientWidth;
|
|
4567
|
+
const height = surface.clientHeight;
|
|
4568
|
+
if (canvas.width !== Math.round(width * ratio) || canvas.height !== Math.round(height * ratio)) {
|
|
4569
|
+
canvas.width = Math.round(width * ratio);
|
|
4570
|
+
canvas.height = Math.round(height * ratio);
|
|
4571
|
+
}
|
|
4572
|
+
context.setTransform(ratio, 0, 0, ratio, 0, 0);
|
|
4573
|
+
context.clearRect(0, 0, width, height);
|
|
4574
|
+
const style = getComputedStyle(surface);
|
|
4575
|
+
context.fillStyle = style.getPropertyValue("--vh-drop-dot").trim() || style.color;
|
|
4576
|
+
const target = over ? 1 : 0;
|
|
4577
|
+
const quiet = still();
|
|
4578
|
+
power += (target - power) * rate(powerRate, seconds);
|
|
4579
|
+
let moving = false;
|
|
4580
|
+
for (const dot of dots) {
|
|
4581
|
+
const distance = Math.hypot(dot.x - pointer.x, dot.y - pointer.y);
|
|
4582
|
+
const want = quiet ? 0 : power * Math.max(0, 1 - distance / reach) ** 2;
|
|
4583
|
+
dot.pull += (want - dot.pull) * rate(dotRate, seconds);
|
|
4584
|
+
if (Math.abs(want - dot.pull) > .002) moving = true;
|
|
4585
|
+
const shift = quiet ? 0 : dot.pull * lean;
|
|
4586
|
+
const angle = Math.atan2(pointer.y - dot.y, pointer.x - dot.x);
|
|
4587
|
+
context.globalAlpha = .16 + dot.pull * .7;
|
|
4588
|
+
context.beginPath();
|
|
4589
|
+
context.arc(dot.x + Math.cos(angle) * shift, dot.y + Math.sin(angle) * shift, .9 + dot.pull * 1.9, 0, Math.PI * 2);
|
|
4590
|
+
context.fill();
|
|
4591
|
+
}
|
|
4592
|
+
context.globalAlpha = 1;
|
|
4593
|
+
return moving || Math.abs(power - target) > .01;
|
|
4594
|
+
}
|
|
4595
|
+
function kick() {
|
|
4596
|
+
if (stop) return;
|
|
4597
|
+
stop = onEachFrame((seconds) => {
|
|
4598
|
+
if (draw(seconds)) return true;
|
|
4599
|
+
stop = void 0;
|
|
4600
|
+
return false;
|
|
4601
|
+
});
|
|
4602
|
+
}
|
|
4603
|
+
function setOver(next) {
|
|
4604
|
+
if (next === over) return;
|
|
4605
|
+
over = next;
|
|
4606
|
+
if (next) field.dataset.over = "";
|
|
4607
|
+
else delete field.dataset.over;
|
|
4608
|
+
kick();
|
|
4609
|
+
}
|
|
4610
|
+
function locate(event) {
|
|
4611
|
+
const box = surface.getBoundingClientRect();
|
|
4612
|
+
pointer = {
|
|
4613
|
+
x: event.clientX - box.left,
|
|
4614
|
+
y: event.clientY - box.top
|
|
4615
|
+
};
|
|
4616
|
+
}
|
|
4617
|
+
const onEnter = (event) => {
|
|
4618
|
+
if (!accepts(event)) return;
|
|
4619
|
+
event.preventDefault();
|
|
4620
|
+
depth++;
|
|
4621
|
+
locate(event);
|
|
4622
|
+
setOver(true);
|
|
4623
|
+
};
|
|
4624
|
+
const onOver = (event) => {
|
|
4625
|
+
if (!accepts(event)) return;
|
|
4626
|
+
event.preventDefault();
|
|
4627
|
+
if (event.dataTransfer) event.dataTransfer.dropEffect = "copy";
|
|
4628
|
+
locate(event);
|
|
4629
|
+
setOver(true);
|
|
4630
|
+
kick();
|
|
4631
|
+
};
|
|
4632
|
+
const onLeave = (event) => {
|
|
4633
|
+
if (!accepts(event)) return;
|
|
4634
|
+
depth = Math.max(0, depth - 1);
|
|
4635
|
+
if (!depth) setOver(false);
|
|
4636
|
+
};
|
|
4637
|
+
const onDrop = (event) => {
|
|
4638
|
+
if (!accepts(event)) return;
|
|
4639
|
+
event.preventDefault();
|
|
4640
|
+
depth = 0;
|
|
4641
|
+
setOver(false);
|
|
4642
|
+
options.onFiles?.([...event.dataTransfer?.files ?? []], event);
|
|
4643
|
+
};
|
|
4644
|
+
field.addEventListener("dragenter", onEnter);
|
|
4645
|
+
field.addEventListener("dragover", onOver);
|
|
4646
|
+
field.addEventListener("dragleave", onLeave);
|
|
4647
|
+
field.addEventListener("drop", onDrop);
|
|
4648
|
+
const resize = typeof ResizeObserver === "function" ? new ResizeObserver(() => {
|
|
4649
|
+
build();
|
|
4650
|
+
draw(0);
|
|
4651
|
+
}) : void 0;
|
|
4652
|
+
resize?.observe(surface);
|
|
4653
|
+
build();
|
|
4654
|
+
draw(0);
|
|
4655
|
+
return {
|
|
4656
|
+
get over() {
|
|
4657
|
+
return over;
|
|
4658
|
+
},
|
|
4659
|
+
destroy() {
|
|
4660
|
+
stop?.();
|
|
4661
|
+
resize?.disconnect();
|
|
4662
|
+
field.removeEventListener("dragenter", onEnter);
|
|
4663
|
+
field.removeEventListener("dragover", onOver);
|
|
4664
|
+
field.removeEventListener("dragleave", onLeave);
|
|
4665
|
+
field.removeEventListener("drop", onDrop);
|
|
4666
|
+
delete field.dataset.over;
|
|
4667
|
+
canvas.remove();
|
|
4668
|
+
}
|
|
4669
|
+
};
|
|
4670
|
+
}
|
|
4671
|
+
export { disclosure as C, divider as E, jelly as S, installMotion as T, leave$2 as _, shake as a, morphText as b, appear as c, switchKnob as d, slider as f, panel as g, setMotionPressMode as h, travel as i, tooltip as l, press as m, createProgress as n, rollNumber as o, select as p, createMotionList as r, motionEffects as s, createDropField as t, toast as u, buttonIcon as v, check as w, swapIcon as x, label as y };
|