@zyro-sec/ui 1.0.1 → 1.0.3
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/AGENTS.md +29 -29
- package/LICENSE +21 -21
- package/bunfig.toml +2 -2
- package/package.json +76 -2
- package/perf/motion.bench.ts +14 -14
- package/perf/motion.ts +16 -16
- package/script/build-oc2-v2-overrides.ts +38 -38
- package/script/colors.txt +288 -288
- package/script/generate-spinner.ts +121 -121
- package/script/pack.ts +5 -5
- package/script/tailwind.ts +24 -24
- package/src/actions/button/button.css +346 -346
- package/src/actions/button/button.stories.tsx +158 -158
- package/src/actions/button/button.tsx +56 -56
- package/src/actions/icon-button/icon-button.css +128 -128
- package/src/actions/icon-button/icon-button.stories.tsx +122 -122
- package/src/actions/icon-button/icon-button.tsx +46 -46
- package/src/actions/split-button/split-button.css +99 -99
- package/src/actions/split-button/split-button.stories.tsx +59 -59
- package/src/actions/split-button/split-button.tsx +51 -51
- package/src/actions/submit.css +81 -81
- package/src/assets/favicon/favicon-v3.svg +6 -6
- package/src/assets/favicon/favicon.svg +6 -6
- package/src/assets/favicon/site.webmanifest +24 -24
- package/src/assets/icons/app/android-studio.svg +369 -369
- package/src/assets/icons/app/antigravity.svg +97 -97
- package/src/assets/icons/app/cursor.svg +16 -16
- package/src/assets/icons/app/file-explorer.svg +20 -20
- package/src/assets/icons/app/ghostty.svg +13 -13
- package/src/assets/icons/app/iterm2.svg +13 -13
- package/src/assets/icons/app/powershell.svg +14 -14
- package/src/assets/icons/app/sublimetext.svg +17 -17
- package/src/assets/icons/app/vscode.svg +39 -39
- package/src/assets/icons/app/windows-terminal.svg +6 -6
- package/src/assets/icons/app/zed-dark.svg +15 -15
- package/src/assets/icons/app/zed.svg +15 -15
- package/src/assets/icons/file-types/auto_light.svg +12 -12
- package/src/assets/icons/file-types/cursor.svg +1 -1
- package/src/assets/icons/file-types/cursor_light.svg +1 -1
- package/src/assets/icons/file-types/drone_light.svg +4 -4
- package/src/assets/icons/file-types/folder-admin-open.svg +6 -6
- package/src/assets/icons/file-types/folder-admin.svg +6 -6
- package/src/assets/icons/file-types/folder-circleci-open.svg +7 -7
- package/src/assets/icons/file-types/folder-circleci.svg +7 -7
- package/src/assets/icons/file-types/folder-flow-open.svg +6 -6
- package/src/assets/icons/file-types/folder-flow.svg +6 -6
- package/src/assets/icons/file-types/folder-gh-workflows-open.svg +6 -6
- package/src/assets/icons/file-types/folder-gh-workflows.svg +6 -6
- package/src/assets/icons/file-types/folder-github-open.svg +6 -6
- package/src/assets/icons/file-types/folder-github.svg +6 -6
- package/src/assets/icons/file-types/folder-intellij-open.svg +39 -39
- package/src/assets/icons/file-types/folder-intellij.svg +39 -39
- package/src/assets/icons/file-types/folder-macos-open.svg +6 -6
- package/src/assets/icons/file-types/folder-macos.svg +6 -6
- package/src/assets/icons/file-types/folder-next-open.svg +6 -6
- package/src/assets/icons/file-types/folder-next.svg +6 -6
- package/src/assets/icons/file-types/folder-nuxt-open.svg +6 -6
- package/src/assets/icons/file-types/folder-nuxt.svg +6 -6
- package/src/assets/icons/file-types/folder-open.svg +5 -5
- package/src/assets/icons/file-types/folder-scripts-open.svg +6 -6
- package/src/assets/icons/file-types/folder-scripts.svg +6 -6
- package/src/assets/icons/file-types/folder-target-open.svg +10 -10
- package/src/assets/icons/file-types/folder-target.svg +10 -10
- package/src/assets/icons/file-types/folder-turborepo-open.svg +15 -15
- package/src/assets/icons/file-types/folder-turborepo.svg +15 -15
- package/src/assets/icons/file-types/folder-vercel-open.svg +5 -5
- package/src/assets/icons/file-types/folder-vercel.svg +5 -5
- package/src/assets/icons/file-types/folder.svg +5 -5
- package/src/assets/icons/file-types/go_gopher.svg +35 -35
- package/src/assets/icons/file-types/nano-staged_light.svg +4 -4
- package/src/assets/icons/file-types/opa.svg +9 -9
- package/src/assets/icons/file-types/quarto.svg +5 -5
- package/src/assets/icons/file-types/rome.svg +6 -6
- package/src/assets/icons/file-types/stitches_light.svg +10 -10
- package/src/assets/icons/file-types/stylelint_light.svg +13 -13
- package/src/assets/icons/file-types/unocss.svg +5 -5
- package/src/assets/icons/file-types/vlang.svg +6 -6
- package/src/assets/icons/provider/302ai.svg +6 -6
- package/src/assets/icons/provider/abacus.svg +14 -14
- package/src/assets/icons/provider/aihubmix.svg +3 -3
- package/src/assets/icons/provider/alibaba-cn.svg +3 -3
- package/src/assets/icons/provider/alibaba-coding-plan-cn.svg +3 -3
- package/src/assets/icons/provider/alibaba-coding-plan.svg +3 -3
- package/src/assets/icons/provider/alibaba.svg +3 -3
- package/src/assets/icons/provider/amazon-bedrock.svg +3 -3
- package/src/assets/icons/provider/anthropic.svg +2 -2
- package/src/assets/icons/provider/azure-cognitive-services.svg +24 -24
- package/src/assets/icons/provider/azure.svg +3 -3
- package/src/assets/icons/provider/bailing.svg +3 -3
- package/src/assets/icons/provider/baseten.svg +3 -3
- package/src/assets/icons/provider/berget.svg +2 -2
- package/src/assets/icons/provider/cerebras.svg +4 -4
- package/src/assets/icons/provider/chutes.svg +24 -24
- package/src/assets/icons/provider/clarifai.svg +24 -24
- package/src/assets/icons/provider/claude-agent.svg +3 -3
- package/src/assets/icons/provider/cloudferro-sherlock.svg +4 -4
- package/src/assets/icons/provider/cloudflare-ai-gateway.svg +4 -4
- package/src/assets/icons/provider/cloudflare-workers-ai.svg +4 -4
- package/src/assets/icons/provider/cohere.svg +5 -5
- package/src/assets/icons/provider/cortecs.svg +24 -24
- package/src/assets/icons/provider/deepinfra.svg +4 -4
- package/src/assets/icons/provider/deepseek.svg +3 -3
- package/src/assets/icons/provider/digitalocean.svg +6 -6
- package/src/assets/icons/provider/dinference.svg +1 -1
- package/src/assets/icons/provider/drun.svg +8 -8
- package/src/assets/icons/provider/evroc.svg +2 -2
- package/src/assets/icons/provider/fastrouter.svg +3 -3
- package/src/assets/icons/provider/fireworks-ai.svg +3 -3
- package/src/assets/icons/provider/firmware.svg +18 -18
- package/src/assets/icons/provider/friendli.svg +3 -3
- package/src/assets/icons/provider/github-copilot.svg +3 -3
- package/src/assets/icons/provider/github-models.svg +3 -3
- package/src/assets/icons/provider/gitlab.svg +3 -3
- package/src/assets/icons/provider/google-vertex-anthropic.svg +24 -24
- package/src/assets/icons/provider/google-vertex.svg +10 -10
- package/src/assets/icons/provider/google.svg +3 -3
- package/src/assets/icons/provider/groq.svg +3 -3
- package/src/assets/icons/provider/helicone.svg +6 -6
- package/src/assets/icons/provider/huggingface.svg +3 -3
- package/src/assets/icons/provider/iflowcn.svg +3 -3
- package/src/assets/icons/provider/inception.svg +4 -4
- package/src/assets/icons/provider/inference.svg +3 -3
- package/src/assets/icons/provider/io-net.svg +5 -5
- package/src/assets/icons/provider/jiekou.svg +4 -4
- package/src/assets/icons/provider/kilo.svg +4 -4
- package/src/assets/icons/provider/kimi-for-coding.svg +3 -3
- package/src/assets/icons/provider/kuae-cloud-coding-plan.svg +3 -3
- package/src/assets/icons/provider/llama.svg +3 -3
- package/src/assets/icons/provider/lmstudio.svg +24 -24
- package/src/assets/icons/provider/lucidquery.svg +3 -3
- package/src/assets/icons/provider/meganova.svg +3 -3
- package/src/assets/icons/provider/meituan.svg +6 -6
- package/src/assets/icons/provider/meta.svg +3 -3
- package/src/assets/icons/provider/minimax-cn-coding-plan.svg +24 -24
- package/src/assets/icons/provider/minimax-cn.svg +3 -3
- package/src/assets/icons/provider/minimax-coding-plan.svg +24 -24
- package/src/assets/icons/provider/minimax.svg +3 -3
- package/src/assets/icons/provider/mistral.svg +3 -3
- package/src/assets/icons/provider/moark.svg +3 -3
- package/src/assets/icons/provider/modelscope.svg +5 -5
- package/src/assets/icons/provider/moonshotai-cn.svg +3 -3
- package/src/assets/icons/provider/moonshotai.svg +3 -3
- package/src/assets/icons/provider/morph.svg +24 -24
- package/src/assets/icons/provider/nano-gpt.svg +2 -2
- package/src/assets/icons/provider/nebius.svg +4 -4
- package/src/assets/icons/provider/nova.svg +3 -3
- package/src/assets/icons/provider/novita-ai.svg +10 -10
- package/src/assets/icons/provider/nvidia.svg +3 -3
- package/src/assets/icons/provider/ollama-cloud.svg +7 -7
- package/src/assets/icons/provider/openai.svg +3 -3
- package/src/assets/icons/provider/opencode-go.svg +3 -3
- package/src/assets/icons/provider/opencode.svg +3 -3
- package/src/assets/icons/provider/openrouter.svg +3 -3
- package/src/assets/icons/provider/ovhcloud.svg +3 -3
- package/src/assets/icons/provider/perplexity-agent.svg +3 -3
- package/src/assets/icons/provider/perplexity.svg +3 -3
- package/src/assets/icons/provider/poe.svg +7 -7
- package/src/assets/icons/provider/privatemode-ai.svg +4 -4
- package/src/assets/icons/provider/qihang-ai.svg +8 -8
- package/src/assets/icons/provider/qiniu-ai.svg +7 -7
- package/src/assets/icons/provider/reflection.svg +3 -3
- package/src/assets/icons/provider/requesty.svg +24 -24
- package/src/assets/icons/provider/sap-ai-core.svg +24 -24
- package/src/assets/icons/provider/scaleway.svg +5 -5
- package/src/assets/icons/provider/siliconflow-cn.svg +3 -3
- package/src/assets/icons/provider/siliconflow.svg +3 -3
- package/src/assets/icons/provider/stackit.svg +4 -4
- package/src/assets/icons/provider/stepfun.svg +16 -16
- package/src/assets/icons/provider/submodel.svg +3 -3
- package/src/assets/icons/provider/synthetic.svg +24 -24
- package/src/assets/icons/provider/tencent-coding-plan.svg +5 -5
- package/src/assets/icons/provider/tencent.svg +3 -3
- package/src/assets/icons/provider/thinkingmachines.svg +3 -3
- package/src/assets/icons/provider/togetherai.svg +4 -4
- package/src/assets/icons/provider/upstage.svg +24 -24
- package/src/assets/icons/provider/v0.svg +3 -3
- package/src/assets/icons/provider/venice.svg +4 -4
- package/src/assets/icons/provider/vercel.svg +3 -3
- package/src/assets/icons/provider/vivgrid.svg +4 -4
- package/src/assets/icons/provider/vultr.svg +6 -6
- package/src/assets/icons/provider/wandb.svg +24 -24
- package/src/assets/icons/provider/xai.svg +3 -3
- package/src/assets/icons/provider/xiaomi.svg +3 -3
- package/src/assets/icons/provider/zai-coding-plan.svg +3 -3
- package/src/assets/icons/provider/zai.svg +3 -3
- package/src/assets/icons/provider/zenmux.svg +4 -4
- package/src/assets/icons/provider/zhipuai-coding-plan.svg +3 -3
- package/src/assets/icons/provider/zhipuai.svg +3 -3
- package/src/components/animated-number-machine.ts +214 -214
- package/src/components/animated-number.css +110 -110
- package/src/components/animated-number.stories.tsx +35 -35
- package/src/components/animated-number.tsx +202 -202
- package/src/components/app-icon.css +5 -5
- package/src/components/app-icon.stories.tsx +73 -73
- package/src/components/app-icon.tsx +89 -89
- package/src/components/app-icons/sprite.svg +114 -114
- package/src/components/app-icons/types.ts +22 -22
- package/src/components/card.css +94 -94
- package/src/components/card.stories.tsx +101 -101
- package/src/components/card.tsx +145 -145
- package/src/components/collapsible.css +139 -139
- package/src/components/collapsible.stories.tsx +76 -76
- package/src/components/collapsible.tsx +62 -62
- package/src/components/context-menu.css +134 -134
- package/src/components/context-menu.stories.tsx +150 -150
- package/src/components/context-menu.tsx +342 -342
- package/src/components/diagram-preview.css +95 -95
- package/src/components/diagram-preview.stories.tsx +62 -62
- package/src/components/diagram-preview.tsx +332 -332
- package/src/components/dock-surface.css +30 -30
- package/src/components/dock-surface.stories.tsx +26 -26
- package/src/components/dock-surface.tsx +40 -40
- package/src/components/document-surface.css +37 -37
- package/src/components/document-surface.stories.tsx +42 -42
- package/src/components/document-surface.tsx +6 -6
- package/src/components/error-details.css +41 -41
- package/src/components/error-details.stories.tsx +72 -72
- package/src/components/error-details.tsx +13 -13
- package/src/components/favicon.stories.tsx +49 -49
- package/src/components/favicon.tsx +13 -13
- package/src/components/file-icon-machine.ts +78 -78
- package/src/components/file-icon.css +6 -6
- package/src/components/file-icon.stories.tsx +93 -93
- package/src/components/file-icon.tsx +186 -186
- package/src/components/file-icons/choose-icon-name.ts +574 -574
- package/src/components/file-icons/sprite.svg +11707 -11707
- package/src/components/file-icons/types.ts +1095 -1095
- package/src/components/font.stories.tsx +48 -48
- package/src/components/font.tsx +1 -1
- package/src/components/hover-card.css +61 -61
- package/src/components/hover-card.stories.tsx +79 -79
- package/src/components/hover-card.tsx +32 -32
- package/src/components/image-flight-machine.ts +247 -247
- package/src/components/image-flight.ts +161 -161
- package/src/components/image-preview.css +202 -202
- package/src/components/image-preview.stories.tsx +392 -392
- package/src/components/image-preview.tsx +908 -908
- package/src/components/image-zoom-machine.ts +191 -191
- package/src/components/image-zoom.ts +124 -124
- package/src/components/list.css +331 -331
- package/src/components/list.stories.tsx +221 -221
- package/src/components/list.tsx +322 -322
- package/src/components/logo.css +4 -4
- package/src/components/logo.stories.tsx +62 -62
- package/src/components/logo.tsx +62 -62
- package/src/components/menu-scroll.css +70 -70
- package/src/components/menu-scroll.stories.tsx +73 -73
- package/src/components/menu-scroll.tsx +202 -202
- package/src/components/motion-spring.tsx +65 -65
- package/src/components/popover-machine.ts +198 -198
- package/src/components/popover.css +66 -66
- package/src/components/popover.stories.tsx +84 -84
- package/src/components/popover.tsx +234 -234
- package/src/components/preview-controls.css +28 -28
- package/src/components/preview-controls.stories.tsx +40 -40
- package/src/components/preview-controls.tsx +53 -53
- package/src/components/progress.css +63 -63
- package/src/components/progress.stories.tsx +69 -69
- package/src/components/progress.tsx +39 -39
- package/src/components/provider-icon.css +5 -5
- package/src/components/provider-icon.stories.tsx +75 -75
- package/src/components/provider-icon.tsx +31 -31
- package/src/components/provider-icons/sprite.svg +1131 -1131
- package/src/components/provider-icons/types.ts +111 -111
- package/src/components/resize-handle-machine.ts +174 -174
- package/src/components/resize-handle.css +81 -81
- package/src/components/resize-handle.stories.tsx +81 -81
- package/src/components/resize-handle.tsx +164 -164
- package/src/components/rolling-number.css +24 -24
- package/src/components/rolling-number.stories.tsx +23 -23
- package/src/components/rolling-number.tsx +135 -135
- package/src/components/scroll-view-machine.ts +244 -244
- package/src/components/scroll-view.css +99 -99
- package/src/components/scroll-view.stories.tsx +68 -68
- package/src/components/scroll-view.tsx +653 -653
- package/src/components/spinner-frames.css +6 -6
- package/src/components/spinner-radar.ts +150 -150
- package/src/components/spinner.css +38 -38
- package/src/components/spinner.stories.tsx +40 -40
- package/src/components/spinner.tsx +43 -43
- package/src/components/sticky-accordion-header.css +11 -11
- package/src/components/sticky-accordion-header.stories.tsx +64 -64
- package/src/components/sticky-accordion-header.tsx +18 -18
- package/src/components/text-field-machine.ts +102 -102
- package/src/components/text-field.css +134 -134
- package/src/components/text-field.stories.tsx +132 -132
- package/src/components/text-field.tsx +196 -196
- package/src/components/text-reveal-machine.ts +184 -184
- package/src/components/text-reveal.css +150 -150
- package/src/components/text-reveal.stories.tsx +363 -363
- package/src/components/text-reveal.tsx +165 -165
- package/src/components/text-strikethrough.css +27 -27
- package/src/components/text-strikethrough.stories.tsx +296 -296
- package/src/components/text-strikethrough.tsx +92 -92
- package/src/components/thinking-heading.stories.tsx +900 -900
- package/src/components/truncated-text.css +25 -25
- package/src/components/truncated-text.stories.tsx +37 -37
- package/src/components/truncated-text.tsx +30 -30
- package/src/components/typewriter-machine.ts +134 -134
- package/src/components/typewriter.css +14 -14
- package/src/components/typewriter.stories.tsx +51 -51
- package/src/components/typewriter.tsx +70 -70
- package/src/context/dialog-machine.ts +281 -281
- package/src/context/dialog.tsx +376 -376
- package/src/context/file.tsx +11 -11
- package/src/context/focus-rescue.tsx +230 -230
- package/src/context/helper.tsx +43 -43
- package/src/context/highlight-theme.tsx +66 -66
- package/src/context/i18n.tsx +144 -144
- package/src/context/index.ts +7 -7
- package/src/context/marked-base.tsx +67 -67
- package/src/context/marked-parser.tsx +154 -154
- package/src/context/overlay-focus.tsx +90 -90
- package/src/custom-elements.d.ts +17 -17
- package/src/data-display/accordion/accordion.css +130 -130
- package/src/data-display/accordion/accordion.stories.tsx +76 -76
- package/src/data-display/accordion/accordion.tsx +106 -106
- package/src/data-display/avatar/avatar.css +70 -70
- package/src/data-display/avatar/avatar.stories.tsx +48 -48
- package/src/data-display/avatar/avatar.tsx +63 -63
- package/src/data-display/badge/badge.css +63 -63
- package/src/data-display/badge/badge.stories.tsx +75 -75
- package/src/data-display/badge/badge.tsx +26 -26
- package/src/data-display/diff-changes/diff-changes.css +47 -47
- package/src/data-display/diff-changes/diff-changes.stories.tsx +63 -63
- package/src/data-display/diff-changes/diff-changes.tsx +43 -43
- package/src/data-display/keybind/keybind.css +84 -84
- package/src/data-display/keybind/keybind.stories.tsx +77 -77
- package/src/data-display/keybind/keybind.tsx +31 -31
- package/src/data-display/line-comment/line-comment.css +341 -341
- package/src/data-display/line-comment/line-comment.stories.tsx +288 -288
- package/src/data-display/line-comment/line-comment.tsx +554 -554
- package/src/data-display/line-comment/machine.ts +400 -400
- package/src/data-display/line-comment/quote-check.svg +3 -3
- package/src/data-display/project-avatar/animation-machine.ts +182 -182
- package/src/data-display/project-avatar/animation.ts +133 -133
- package/src/data-display/project-avatar/generated.ts +225 -225
- package/src/data-display/project-avatar/procedural-craft.ts +1079 -1079
- package/src/data-display/project-avatar/procedural-kit.ts +244 -244
- package/src/data-display/project-avatar/procedural-machine.ts +924 -924
- package/src/data-display/project-avatar/procedural-world.ts +1542 -1542
- package/src/data-display/project-avatar/procedural.ts +1563 -1563
- package/src/data-display/project-avatar/project-avatar.css +189 -189
- package/src/data-display/project-avatar/project-avatar.stories.tsx +102 -102
- package/src/data-display/project-avatar/project-avatar.tsx +246 -246
- package/src/data-display/project-avatar/project-icon-styles.stories.tsx +772 -772
- package/src/feedback/activity-ring/activity-ring.css +5 -5
- package/src/feedback/activity-ring/activity-ring.stories.tsx +20 -20
- package/src/feedback/activity-ring/activity-ring.tsx +15 -15
- package/src/feedback/loader/loader.css +32 -32
- package/src/feedback/loader/loader.stories.tsx +44 -44
- package/src/feedback/loader/loader.tsx +34 -34
- package/src/feedback/progress-circle/progress-circle.css +28 -28
- package/src/feedback/progress-circle/progress-circle.stories.tsx +56 -56
- package/src/feedback/progress-circle/progress-circle.tsx +64 -64
- package/src/feedback/toast/description.ts +10 -10
- package/src/feedback/toast/machine.ts +115 -115
- package/src/feedback/toast/toast.css +234 -234
- package/src/feedback/toast/toast.stories.tsx +186 -186
- package/src/feedback/toast/toast.tsx +317 -317
- package/src/forms/checkbox/checkbox-compact.css +170 -170
- package/src/forms/checkbox/checkbox.css +125 -125
- package/src/forms/checkbox/checkbox.stories.tsx +104 -104
- package/src/forms/checkbox/checkbox.tsx +119 -119
- package/src/forms/field/field.css +94 -94
- package/src/forms/field/field.stories.tsx +129 -129
- package/src/forms/field/field.tsx +271 -271
- package/src/forms/inline-input/inline-input.css +16 -16
- package/src/forms/inline-input/inline-input.stories.tsx +37 -37
- package/src/forms/inline-input/inline-input.tsx +26 -26
- package/src/forms/radio/radio.css +218 -218
- package/src/forms/radio/radio.stories.tsx +145 -145
- package/src/forms/radio/radio.tsx +95 -95
- package/src/forms/redirect-paste/redirect-paste.stories.tsx +101 -101
- package/src/forms/redirect-paste/redirect-paste.tsx +92 -92
- package/src/forms/search-list/navigation.ts +54 -54
- package/src/forms/search-list/search-list.css +249 -249
- package/src/forms/search-list/search-list.stories.tsx +108 -108
- package/src/forms/search-list/search-list.tsx +463 -463
- package/src/forms/select/machine.ts +81 -81
- package/src/forms/select/select.css +312 -312
- package/src/forms/select/select.stories.tsx +208 -208
- package/src/forms/select/select.tsx +281 -281
- package/src/forms/switch/switch.css +281 -281
- package/src/forms/switch/switch.stories.tsx +97 -97
- package/src/forms/switch/switch.tsx +35 -35
- package/src/forms/text-input/text-input.css +229 -229
- package/src/forms/text-input/text-input.stories.tsx +220 -220
- package/src/forms/text-input/text-input.tsx +115 -115
- package/src/forms/textarea/textarea.css +103 -103
- package/src/forms/textarea/textarea.stories.tsx +137 -137
- package/src/forms/textarea/textarea.tsx +33 -33
- package/src/forms/typeahead/controller.ts +59 -59
- package/src/forms/typeahead/machine.ts +253 -253
- package/src/forms/typeahead/typeahead.stories.tsx +113 -113
- package/src/forms/typeahead/typeahead.tsx +239 -239
- package/src/hooks/auto-scroll-machine.ts +261 -261
- package/src/hooks/create-auto-scroll.tsx +196 -196
- package/src/hooks/index.ts +5 -5
- package/src/hooks/list-machine.ts +359 -359
- package/src/hooks/spin-phase.ts +116 -116
- package/src/hooks/use-filtered-list.tsx +132 -132
- package/src/i18n/am.ts +384 -384
- package/src/i18n/ar.ts +547 -547
- package/src/i18n/az.ts +386 -386
- package/src/i18n/bg.ts +386 -386
- package/src/i18n/bn.ts +393 -393
- package/src/i18n/br.ts +444 -444
- package/src/i18n/bs.ts +445 -445
- package/src/i18n/ca.ts +423 -423
- package/src/i18n/cs.ts +457 -457
- package/src/i18n/da.ts +407 -407
- package/src/i18n/de.ts +414 -414
- package/src/i18n/dv.ts +395 -395
- package/src/i18n/dz.ts +393 -393
- package/src/i18n/el.ts +388 -388
- package/src/i18n/en.ts +433 -433
- package/src/i18n/es.ts +443 -443
- package/src/i18n/et.ts +386 -386
- package/src/i18n/fa.ts +388 -388
- package/src/i18n/fi.ts +388 -388
- package/src/i18n/fo.ts +388 -388
- package/src/i18n/fr.ts +447 -447
- package/src/i18n/he.ts +422 -422
- package/src/i18n/hi.ts +392 -392
- package/src/i18n/hr.ts +422 -422
- package/src/i18n/hu.ts +388 -388
- package/src/i18n/hy.ts +389 -389
- package/src/i18n/id.ts +411 -411
- package/src/i18n/is.ts +388 -388
- package/src/i18n/it.ts +425 -425
- package/src/i18n/ja.ts +406 -406
- package/src/i18n/ka.ts +388 -388
- package/src/i18n/km.ts +389 -389
- package/src/i18n/ko.ts +408 -408
- package/src/i18n/lo.ts +387 -387
- package/src/i18n/lt.ts +457 -457
- package/src/i18n/lv.ts +421 -421
- package/src/i18n/mk.ts +387 -387
- package/src/i18n/mn.ts +386 -386
- package/src/i18n/ms.ts +389 -389
- package/src/i18n/my.ts +389 -389
- package/src/i18n/ne.ts +393 -393
- package/src/i18n/nl.ts +388 -388
- package/src/i18n/no.ts +413 -413
- package/src/i18n/pa.ts +394 -394
- package/src/i18n/pl.ts +476 -476
- package/src/i18n/ro.ts +423 -423
- package/src/i18n/ru.ts +475 -475
- package/src/i18n/si.ts +390 -390
- package/src/i18n/sk.ts +457 -457
- package/src/i18n/sl.ts +457 -457
- package/src/i18n/sq.ts +387 -387
- package/src/i18n/sr.ts +422 -422
- package/src/i18n/sv.ts +388 -388
- package/src/i18n/tg.ts +390 -390
- package/src/i18n/th.ts +407 -407
- package/src/i18n/tk.ts +386 -386
- package/src/i18n/tr.ts +412 -412
- package/src/i18n/uk.ts +480 -480
- package/src/i18n/ur.ts +394 -394
- package/src/i18n/uz.ts +390 -390
- package/src/i18n/vi.ts +387 -387
- package/src/i18n/zh.ts +408 -408
- package/src/i18n/zht.ts +408 -408
- package/src/icons/catalog.ts +638 -638
- package/src/icons/icon/icon.css +3 -3
- package/src/icons/icon/icon.stories.tsx +131 -131
- package/src/icons/icon/icon.tsx +106 -106
- package/src/icons/registry.ts +217 -217
- package/src/layout/divider/divider.css +11 -11
- package/src/layout/divider/divider.stories.tsx +38 -38
- package/src/layout/divider/divider.tsx +21 -21
- package/src/motion/README.md +113 -113
- package/src/motion/index.ts +13 -13
- package/src/motion/loop.ts +139 -139
- package/src/motion/reduced.ts +66 -66
- package/src/motion/slider.ts +45 -45
- package/src/motion/solid.ts +309 -309
- package/src/motion/spring.ts +125 -125
- package/src/motion/velocity.ts +46 -46
- package/src/motion/waapi.ts +89 -89
- package/src/motion-tuning-features.ts +161 -161
- package/src/motion-tuning-fields.ts +42 -42
- package/src/motion-tuning.ts +323 -323
- package/src/navigation/menu/machine.ts +109 -109
- package/src/navigation/menu/menu.css +313 -313
- package/src/navigation/menu/menu.stories.tsx +328 -328
- package/src/navigation/menu/menu.tsx +600 -600
- package/src/navigation/menu/submenu-machine.ts +67 -67
- package/src/navigation/segmented-control/machine.ts +72 -72
- package/src/navigation/segmented-control/segmented-control.css +113 -113
- package/src/navigation/segmented-control/segmented-control.stories.tsx +115 -115
- package/src/navigation/segmented-control/segmented-control.tsx +396 -396
- package/src/navigation/tab-state-indicator.stories.tsx +24 -24
- package/src/navigation/tab-state-indicator.tsx +38 -38
- package/src/navigation/tabs/tabs-current.css +244 -244
- package/src/navigation/tabs/tabs.css +676 -676
- package/src/navigation/tabs/tabs.stories.tsx +193 -193
- package/src/navigation/tabs/tabs.tsx +212 -212
- package/src/overlays/dialog/dialog.css +194 -194
- package/src/overlays/dialog/dialog.stories.tsx +365 -365
- package/src/overlays/dialog/dialog.tsx +192 -192
- package/src/overlays/mcp-sign-in/machine.ts +343 -343
- package/src/overlays/mcp-sign-in/mcp-sign-in.ts +159 -159
- package/src/overlays/tooltip/machine.ts +312 -312
- package/src/overlays/tooltip/tooltip.css +102 -102
- package/src/overlays/tooltip/tooltip.stories.tsx +155 -155
- package/src/overlays/tooltip/tooltip.tsx +290 -290
- package/src/storybook/fixtures.ts +51 -51
- package/src/storybook/scaffold.tsx +65 -65
- package/src/styles/animations.css +13 -13
- package/src/styles/base.css +441 -441
- package/src/styles/blue-tokens.stories.tsx +215 -215
- package/src/styles/colors.css +772 -772
- package/src/styles/file-tree.css +285 -285
- package/src/styles/index.css +42 -42
- package/src/styles/scrollbar.css +79 -79
- package/src/styles/tailwind/colors.css +288 -288
- package/src/styles/tailwind/index.css +113 -113
- package/src/styles/tailwind/utilities.css +17 -17
- package/src/styles/theme.css +640 -640
- package/src/styles/tokens/colors.css +172 -172
- package/src/styles/tokens/index.css +2 -2
- package/src/styles/tokens/theme.css +522 -522
- package/src/styles/utilities.css +93 -93
- package/src/theme/color.ts +290 -290
- package/src/theme/context.tsx +361 -361
- package/src/theme/desktop-theme.schema.json +168 -168
- package/src/theme/index.ts +35 -35
- package/src/theme/machine.ts +508 -508
- package/src/theme/resolve.ts +561 -561
- package/src/theme/themes/amoled.json +49 -49
- package/src/theme/themes/aura.json +51 -51
- package/src/theme/themes/ayu.json +51 -51
- package/src/theme/themes/carbonfox.json +53 -53
- package/src/theme/themes/catppuccin-frappe.json +65 -65
- package/src/theme/themes/catppuccin-macchiato.json +65 -65
- package/src/theme/themes/catppuccin.json +45 -45
- package/src/theme/themes/cobalt2.json +87 -87
- package/src/theme/themes/cursor.json +91 -91
- package/src/theme/themes/dracula.json +49 -49
- package/src/theme/themes/everforest.json +89 -89
- package/src/theme/themes/flexoki.json +86 -86
- package/src/theme/themes/github.json +85 -85
- package/src/theme/themes/gruvbox.json +45 -45
- package/src/theme/themes/kanagawa.json +89 -89
- package/src/theme/themes/lucent-orng.json +87 -87
- package/src/theme/themes/material.json +87 -87
- package/src/theme/themes/matrix.json +113 -113
- package/src/theme/themes/mercury.json +86 -86
- package/src/theme/themes/monokai.json +49 -49
- package/src/theme/themes/nightowl.json +46 -46
- package/src/theme/themes/nord.json +46 -46
- package/src/theme/themes/oc-2.json +509 -509
- package/src/theme/themes/one-dark.json +89 -89
- package/src/theme/themes/onedarkpro.json +45 -45
- package/src/theme/themes/orng.json +87 -87
- package/src/theme/themes/osaka-jade.json +88 -88
- package/src/theme/themes/palenight.json +85 -85
- package/src/theme/themes/rosepine.json +85 -85
- package/src/theme/themes/shadesofpurple.json +51 -51
- package/src/theme/themes/solarized.json +49 -49
- package/src/theme/themes/synthwave84.json +87 -87
- package/src/theme/themes/tokyonight.json +47 -47
- package/src/theme/themes/vercel.json +90 -90
- package/src/theme/themes/vesper.json +51 -51
- package/src/theme/themes/zenburn.json +87 -87
- package/src/theme/types.ts +75 -75
- package/src/theme/v2/avatar.ts +48 -48
- package/src/theme/v2/default-primitives.ts +114 -114
- package/src/theme/v2/foreground.ts +69 -69
- package/src/theme/v2/mapping.ts +180 -180
- package/src/theme/v2/resolve.ts +163 -163
- package/src/typography/slash/slash.css +14 -14
- package/src/typography/slash/slash.stories.tsx +26 -26
- package/src/typography/slash/slash.tsx +16 -16
- package/src/typography/text-shimmer/machine.ts +90 -90
- package/src/typography/text-shimmer/text-shimmer.css +152 -152
- package/src/typography/text-shimmer/text-shimmer.stories.tsx +64 -64
- package/src/typography/text-shimmer/text-shimmer.tsx +81 -81
- package/src/typography/wordmark/wordmark.stories.tsx +19 -19
- package/src/typography/wordmark/wordmark.tsx +73 -73
- package/test/solid-jsx.ts +20 -20
- package/tsconfig.build.json +14 -14
- package/tsconfig.json +23 -23
- package/vite.config.ts +61 -61
- package/src/components/animated-number-machine.test.ts +0 -140
- package/src/components/file-icon-machine.test.ts +0 -52
- package/src/components/image-flight-machine.test.ts +0 -184
- package/src/components/image-flight.test.ts +0 -173
- package/src/components/image-zoom-machine.test.ts +0 -154
- package/src/components/image-zoom.test.ts +0 -96
- package/src/components/popover-machine.test.ts +0 -150
- package/src/components/resize-handle-machine.test.ts +0 -164
- package/src/components/scroll-view-machine.test.ts +0 -141
- package/src/components/scroll-view.test.ts +0 -114
- package/src/components/spinner-radar.test.ts +0 -61
- package/src/components/text-field-machine.test.ts +0 -99
- package/src/components/text-reveal-machine.test.ts +0 -157
- package/src/components/typewriter-machine.test.ts +0 -177
- package/src/context/dialog-machine.test.ts +0 -295
- package/src/context/i18n.test.ts +0 -89
- package/src/context/marked-base.test.ts +0 -75
- package/src/context/marked-parser.test.ts +0 -167
- package/src/context/marked-regression.test.ts +0 -12
- package/src/data-display/line-comment/machine.test.ts +0 -385
- package/src/data-display/project-avatar/animation-machine.test.ts +0 -134
- package/src/data-display/project-avatar/generated.test.ts +0 -50
- package/src/data-display/project-avatar/procedural.test.ts +0 -16
- package/src/data-display/project-avatar/project-avatar.test.ts +0 -21
- package/src/feedback/toast/description.test.ts +0 -20
- package/src/feedback/toast/machine.test.ts +0 -106
- package/src/forms/search-list/navigation.test.ts +0 -40
- package/src/forms/select/machine.test.ts +0 -105
- package/src/forms/typeahead/machine.test.ts +0 -143
- package/src/hooks/auto-scroll-machine.test.ts +0 -212
- package/src/hooks/list-machine.test.ts +0 -263
- package/src/hooks/spin-phase.test.ts +0 -32
- package/src/hooks/use-filtered-list.test.ts +0 -41
- package/src/motion/core.test.ts +0 -328
- package/src/motion-tuning-features.test.ts +0 -129
- package/src/motion-tuning.test.ts +0 -68
- package/src/navigation/menu/machine.test.ts +0 -85
- package/src/navigation/menu/submenu-machine.test.ts +0 -71
- package/src/navigation/segmented-control/segmented-control.test.ts +0 -123
- package/src/overlays/mcp-sign-in/machine.test.ts +0 -215
- package/src/overlays/tooltip/machine.test.ts +0 -214
- package/src/theme/machine.test.ts +0 -498
- package/src/theme/v2/resolve.test.ts +0 -120
- package/src/typography/text-shimmer/machine.test.ts +0 -117
|
@@ -1,908 +1,908 @@
|
|
|
1
|
-
import { Dialog as Kobalte, useDialogContext } from "@kobalte/core/dialog"
|
|
2
|
-
import { makeEventListener } from "@solid-primitives/event-listener"
|
|
3
|
-
import { createResizeObserver } from "@solid-primitives/resize-observer"
|
|
4
|
-
import { createEffect, createMemo, createSignal, on, onCleanup, Show, untrack } from "solid-js"
|
|
5
|
-
import { createStore } from "solid-js/store"
|
|
6
|
-
import { useDialogLayer } from "../context/dialog"
|
|
7
|
-
import { useI18n } from "../context/i18n"
|
|
8
|
-
import { Button } from "@zyro-sec/ui/button"
|
|
9
|
-
import { Icon } from "@zyro-sec/ui/icon"
|
|
10
|
-
import { IconButton } from "@zyro-sec/ui/icon-button"
|
|
11
|
-
import { frameLoop, prefersReducedMotion, Spring, type DurationOptions } from "../motion"
|
|
12
|
-
import {
|
|
13
|
-
createFlight,
|
|
14
|
-
elementFrame,
|
|
15
|
-
FLIGHT_SPRING,
|
|
16
|
-
flightStyle,
|
|
17
|
-
intersect,
|
|
18
|
-
KICK,
|
|
19
|
-
type Box,
|
|
20
|
-
type FlightFrame,
|
|
21
|
-
} from "./image-flight"
|
|
22
|
-
import {
|
|
23
|
-
DECODE_TIMEOUT_MS,
|
|
24
|
-
INITIAL_PREVIEW_FLIGHT_STATE,
|
|
25
|
-
selectAwaitingReveal,
|
|
26
|
-
selectDecodeCurrent,
|
|
27
|
-
selectFlightFading,
|
|
28
|
-
selectFlightInteractive,
|
|
29
|
-
selectFlightStage,
|
|
30
|
-
selectVideoAtRest,
|
|
31
|
-
transitionPreviewFlight,
|
|
32
|
-
type PreviewFlightEffect,
|
|
33
|
-
type PreviewFlightEvent,
|
|
34
|
-
} from "./image-flight-machine"
|
|
35
|
-
import {
|
|
36
|
-
clampAxis,
|
|
37
|
-
clampView,
|
|
38
|
-
detailScale,
|
|
39
|
-
FIT_VIEW,
|
|
40
|
-
maxScale,
|
|
41
|
-
panBy,
|
|
42
|
-
viewBox,
|
|
43
|
-
wheelPixels,
|
|
44
|
-
wheelZoomFactor,
|
|
45
|
-
zoomAt,
|
|
46
|
-
zoomShortcut,
|
|
47
|
-
type ZoomView,
|
|
48
|
-
} from "./image-zoom"
|
|
49
|
-
import {
|
|
50
|
-
INITIAL_PREVIEW_ZOOM_STATE,
|
|
51
|
-
selectDragging,
|
|
52
|
-
selectPanPointer,
|
|
53
|
-
transitionPreviewZoom,
|
|
54
|
-
type PanTarget,
|
|
55
|
-
type PreviewZoomEffect,
|
|
56
|
-
type PreviewZoomEvent,
|
|
57
|
-
} from "./image-zoom-machine"
|
|
58
|
-
|
|
59
|
-
export interface ImagePreviewProps {
|
|
60
|
-
src: string
|
|
61
|
-
alt?: string
|
|
62
|
-
/** The image on the page that the preview grows out of and shrinks back into. */
|
|
63
|
-
origin?: HTMLElement
|
|
64
|
-
/**
|
|
65
|
-
* A video on the page to show instead of the image. The preview borrows this element, so it keeps playing as it
|
|
66
|
-
* flies out of its place and back, and returns it once the close lands.
|
|
67
|
-
*/
|
|
68
|
-
video?: HTMLVideoElement
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const STEP = Math.SQRT2
|
|
72
|
-
|
|
73
|
-
// How far up from its bottom edge a video keeps its own controls, whose drag scrubs rather than pans.
|
|
74
|
-
const CONTROLS = 56
|
|
75
|
-
|
|
76
|
-
// Without a flight (reduced motion, or no thumbnail to fly to), the preview only fades.
|
|
77
|
-
const fade = { duration: 0.15, bounce: 0 }
|
|
78
|
-
|
|
79
|
-
// How long the dialog stays mounted after a close starts, in milliseconds: the flight lands and hands the image back
|
|
80
|
-
// to the page well within this.
|
|
81
|
-
const EXIT_DURATION_MS = Math.max(FLIGHT_SPRING.duration, fade.duration) * 3200
|
|
82
|
-
|
|
83
|
-
const CENTER = { x: 0, y: 0 }
|
|
84
|
-
|
|
85
|
-
const SETTLED: PreviewFlightEvent = Object.freeze({ type: "motion.settled" })
|
|
86
|
-
|
|
87
|
-
// Previews closing at once, such as one still flying home under the next, share the body's closing mark.
|
|
88
|
-
let closingPreviews = 0
|
|
89
|
-
|
|
90
|
-
export function ImagePreview(props: ImagePreviewProps) {
|
|
91
|
-
const i18n = useI18n()
|
|
92
|
-
const dialog = useDialogContext()
|
|
93
|
-
const layer = useDialogLayer()
|
|
94
|
-
let root!: HTMLDivElement
|
|
95
|
-
let scrim!: HTMLDivElement
|
|
96
|
-
let content!: HTMLDivElement
|
|
97
|
-
let viewport!: HTMLDivElement
|
|
98
|
-
// For a video, an empty canvas of its size: the box it fits to in the window.
|
|
99
|
-
let image!: HTMLImageElement | HTMLCanvasElement
|
|
100
|
-
let standIn: HTMLImageElement | undefined
|
|
101
|
-
// Where a borrowed video was on the page, holding its size until it comes back.
|
|
102
|
-
let holder: HTMLElement | undefined
|
|
103
|
-
let surface!: HTMLDivElement
|
|
104
|
-
let edge!: HTMLDivElement
|
|
105
|
-
let close: HTMLButtonElement | undefined
|
|
106
|
-
|
|
107
|
-
// Nothing shows until the image has loaded and the preview knows where it lands; while flying, a stand-in image and
|
|
108
|
-
// its shadow travel above the dialog in place of the real one.
|
|
109
|
-
const [flight, setFlight] = createSignal(INITIAL_PREVIEW_FLIGHT_STATE)
|
|
110
|
-
const [zoom, setZoom] = createSignal(INITIAL_PREVIEW_ZOOM_STATE)
|
|
111
|
-
// What the view shows the controls and the stylesheet, written only when it changes rather than on every frame.
|
|
112
|
-
const [shown, setShown] = createStore({ zoomed: false, ownsEscape: false, level: 100 })
|
|
113
|
-
|
|
114
|
-
// The flight under way: where the stand-in is laid out (the flight only transforms and clips it) and the springs.
|
|
115
|
-
let course: { at: Box; flight: ReturnType<typeof createFlight> } | undefined
|
|
116
|
-
let flightJob: (() => void) | undefined
|
|
117
|
-
let decodeTimer: ReturnType<typeof setTimeout> | undefined
|
|
118
|
-
|
|
119
|
-
const dim = Spring.fromDuration(0, FLIGHT_SPRING)
|
|
120
|
-
// Once a close lands, the stand-in fades out over the image the page shows again, so whatever the page draws over
|
|
121
|
-
// its own image (a fade under a sticky bar, say) comes in softly instead of in one frame.
|
|
122
|
-
const veil = Spring.fromDuration(1, FLIGHT_SPRING)
|
|
123
|
-
|
|
124
|
-
// How far the flight has lifted off the page, as last painted: the origin's outline fades out as it rises.
|
|
125
|
-
let lift = 0
|
|
126
|
-
|
|
127
|
-
// The view: each spring's value is what shows, and its target is where an eased zoom is heading, so repeated steps
|
|
128
|
-
// build on the destination rather than the frame in flight. Scale and offsets ride springs of one shape, so the point
|
|
129
|
-
// under the pointer stays put; a new target mid-glide keeps the velocity it has.
|
|
130
|
-
const scaleSpring = Spring.fromDuration(1, FLIGHT_SPRING)
|
|
131
|
-
const xSpring = Spring.fromDuration(0, FLIGHT_SPRING)
|
|
132
|
-
const ySpring = Spring.fromDuration(0, FLIGHT_SPRING)
|
|
133
|
-
let glideJob: (() => void) | undefined
|
|
134
|
-
// Where the pan under way last saw its pointer.
|
|
135
|
-
const cursor = { x: 0, y: 0 }
|
|
136
|
-
|
|
137
|
-
// Measured when the preview lays out rather than on every move or frame. A video zooms inside its own frame, so its
|
|
138
|
-
// controls stay where they are; an image zooms out across the window.
|
|
139
|
-
const natural = { width: 0, height: 0 }
|
|
140
|
-
const bounds = { width: 0, height: 0, viewportWidth: 0, viewportHeight: 0, maxScale: 1 }
|
|
141
|
-
let fitRatio = 1
|
|
142
|
-
|
|
143
|
-
// Reused on every pointer move of a pan.
|
|
144
|
-
const followEvent = { type: "follow" as const, zoomed: false }
|
|
145
|
-
const movedEvent = { type: "pointer.moved" as const, pointerId: 0 }
|
|
146
|
-
|
|
147
|
-
const percent = createMemo(() => new Intl.NumberFormat(i18n.locale(), { style: "percent", maximumFractionDigits: 0 }))
|
|
148
|
-
|
|
149
|
-
const dispatchFlight = (event: PreviewFlightEvent) => {
|
|
150
|
-
const prev = untrack(flight)
|
|
151
|
-
const next = transitionPreviewFlight(prev, event)
|
|
152
|
-
|
|
153
|
-
if (next.state !== prev) setFlight(next.state)
|
|
154
|
-
next.effects.forEach(runFlight)
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const runFlight = (effect: PreviewFlightEffect) => {
|
|
158
|
-
if (effect.type === "decode.start") return decode(effect.attempt)
|
|
159
|
-
|
|
160
|
-
if (effect.type === "decode.cancel") return clearTimeout(decodeTimer)
|
|
161
|
-
|
|
162
|
-
if (effect.type === "video.borrow") return borrow()
|
|
163
|
-
|
|
164
|
-
if (effect.type === "video.return") return giveBack()
|
|
165
|
-
|
|
166
|
-
if (effect.type === "origin.hide") return home()?.setAttribute("data-image-preview-origin", "")
|
|
167
|
-
|
|
168
|
-
if (effect.type === "origin.show") return home()?.removeAttribute("data-image-preview-origin")
|
|
169
|
-
|
|
170
|
-
if (effect.type === "open.flight") {
|
|
171
|
-
dimTo(1, FLIGHT_SPRING)
|
|
172
|
-
const next = createFlight(effect.from)
|
|
173
|
-
next.to(restFrame(), KICK.open, FLIGHT_SPRING)
|
|
174
|
-
course = { at: place(fitted()), flight: next }
|
|
175
|
-
paint()
|
|
176
|
-
|
|
177
|
-
return run()
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if (effect.type === "open.fade") {
|
|
181
|
-
dimTo(1, fade)
|
|
182
|
-
|
|
183
|
-
if (props.video) place(fitted())
|
|
184
|
-
paint()
|
|
185
|
-
|
|
186
|
-
return run()
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (effect.type === "close.flight") {
|
|
190
|
-
dimTo(0, FLIGHT_SPRING)
|
|
191
|
-
|
|
192
|
-
if (!effect.turn) course = { at: place(fitted()), flight: createFlight(restFrame()) }
|
|
193
|
-
course?.flight.to(effect.to, KICK.close, FLIGHT_SPRING)
|
|
194
|
-
paint()
|
|
195
|
-
|
|
196
|
-
return run()
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
if (effect.type === "close.veil") {
|
|
200
|
-
veil.omega = (2 * Math.PI) / (FLIGHT_SPRING.duration * 0.75)
|
|
201
|
-
veil.set(0)
|
|
202
|
-
|
|
203
|
-
return
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if (effect.type === "close.fade") {
|
|
207
|
-
course = undefined
|
|
208
|
-
dimTo(0, fade)
|
|
209
|
-
|
|
210
|
-
return run()
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
if (effect.type === "zoom.fit") return ease(FIT_VIEW)
|
|
214
|
-
|
|
215
|
-
if (effect.type === "zoom.settle") return follow(scaleSpring.value, xSpring.value, ySpring.value)
|
|
216
|
-
|
|
217
|
-
// See image-preview.css: the body takes clicks again while the closing flight holds the dialog mounted.
|
|
218
|
-
if (effect.type === "body.closing.acquire") {
|
|
219
|
-
closingPreviews++
|
|
220
|
-
document.body.setAttribute("data-image-preview-closing", "")
|
|
221
|
-
|
|
222
|
-
return
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
if (effect.type === "body.closing.release") {
|
|
226
|
-
closingPreviews--
|
|
227
|
-
|
|
228
|
-
if (!closingPreviews) document.body.removeAttribute("data-image-preview-closing")
|
|
229
|
-
|
|
230
|
-
return
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
flightJob?.()
|
|
234
|
-
flightJob = undefined
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
const dispatchZoom = (event: PreviewZoomEvent) => {
|
|
238
|
-
const prev = untrack(zoom)
|
|
239
|
-
const next = transitionPreviewZoom(prev, event)
|
|
240
|
-
|
|
241
|
-
if (next.state !== prev) setZoom(next.state)
|
|
242
|
-
next.effects.forEach(runZoom)
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
const runZoom = (effect: PreviewZoomEffect) => {
|
|
246
|
-
if (effect.type === "pointer.capture") return panElement(effect.target).setPointerCapture(effect.pointerId)
|
|
247
|
-
|
|
248
|
-
if (effect.type === "pointer.release") {
|
|
249
|
-
const element = panElement(effect.target)
|
|
250
|
-
|
|
251
|
-
if (element.hasPointerCapture(effect.pointerId)) element.releasePointerCapture(effect.pointerId)
|
|
252
|
-
|
|
253
|
-
return
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
if (effect.type === "glide.loop.start") {
|
|
257
|
-
glideJob = frameLoop.add((dt) => {
|
|
258
|
-
scaleSpring.step(dt)
|
|
259
|
-
xSpring.step(dt)
|
|
260
|
-
ySpring.step(dt)
|
|
261
|
-
paintZoom()
|
|
262
|
-
|
|
263
|
-
if (!scaleSpring.resting || !xSpring.resting || !ySpring.resting) return true
|
|
264
|
-
dispatchZoom({ type: "glide.settled", zoomed: scaleSpring.value > 1 })
|
|
265
|
-
|
|
266
|
-
return false
|
|
267
|
-
})
|
|
268
|
-
|
|
269
|
-
return
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
if (effect.type === "glide.loop.stop") {
|
|
273
|
-
glideJob?.()
|
|
274
|
-
glideJob = undefined
|
|
275
|
-
|
|
276
|
-
return
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
if (effect.type === "video.suppress-click") return suppressVideoClick()
|
|
280
|
-
|
|
281
|
-
dialog.close()
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
// Writes the view to the DOM. A frame allocates nothing but the style string, and touches Solid state only when
|
|
285
|
-
// the zoom level's rounded percent or whether the image is zoomed changes.
|
|
286
|
-
const paintZoom = () => {
|
|
287
|
-
const scale = scaleSpring.value
|
|
288
|
-
|
|
289
|
-
if (props.video) {
|
|
290
|
-
props.video.style.setProperty("object-view-box", viewBox(scale, xSpring.value, ySpring.value, bounds, natural))
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
if (!props.video) image.style.transform = `translate(${xSpring.value}px, ${ySpring.value}px) scale(${scale})`
|
|
294
|
-
const level = Math.round(scale * fitRatio * 100)
|
|
295
|
-
|
|
296
|
-
if (shown.zoomed !== scale > 1) setShown("zoomed", scale > 1)
|
|
297
|
-
|
|
298
|
-
if (shown.level !== level) setShown("level", level)
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
const view = (): ZoomView => ({ scale: scaleSpring.value, x: xSpring.value, y: ySpring.value })
|
|
302
|
-
const goal = (): ZoomView => ({ scale: scaleSpring.target, x: xSpring.target, y: ySpring.target })
|
|
303
|
-
|
|
304
|
-
const own = (scale: number) => {
|
|
305
|
-
if (shown.ownsEscape !== scale > 1) setShown("ownsEscape", scale > 1)
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// Pinch, wheel and drag follow the hand directly and take over from an eased zoom mid-flight.
|
|
309
|
-
const follow = (scale: number, x: number, y: number) => {
|
|
310
|
-
followEvent.zoomed = scale > 1
|
|
311
|
-
dispatchZoom(followEvent)
|
|
312
|
-
scaleSpring.snap(scale)
|
|
313
|
-
xSpring.snap(x)
|
|
314
|
-
ySpring.snap(y)
|
|
315
|
-
own(scale)
|
|
316
|
-
paintZoom()
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
const ease = (target: ZoomView) => {
|
|
320
|
-
if (prefersReducedMotion()) return follow(target.scale, target.x, target.y)
|
|
321
|
-
scaleSpring.set(target.scale)
|
|
322
|
-
xSpring.set(target.x)
|
|
323
|
-
ySpring.set(target.y)
|
|
324
|
-
own(target.scale)
|
|
325
|
-
dispatchZoom({ type: "glide.start" })
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
const step = (factor: number) => {
|
|
329
|
-
const target = goal()
|
|
330
|
-
ease(zoomAt(target, target.scale * factor, CENTER, bounds))
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
// Kobalte keeps the content mounted while an exit animation runs; the dialog stack waits for the flight too.
|
|
334
|
-
layer?.setExitDuration(EXIT_DURATION_MS)
|
|
335
|
-
|
|
336
|
-
const decode = (attempt: number) => {
|
|
337
|
-
clearTimeout(decodeTimer)
|
|
338
|
-
decodeTimer = setTimeout(() => decoded(attempt), DECODE_TIMEOUT_MS)
|
|
339
|
-
|
|
340
|
-
if (!(image instanceof HTMLImageElement)) return
|
|
341
|
-
void Promise.all([image.decode(), standIn?.decode()])
|
|
342
|
-
.catch(() => undefined)
|
|
343
|
-
.then(() => decoded(attempt))
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
// Measuring where the origin shows is not free, so a decode the preview no longer waits for skips it.
|
|
347
|
-
const decoded = (attempt: number) => {
|
|
348
|
-
if (!selectDecodeCurrent(untrack(flight), attempt)) return
|
|
349
|
-
dispatchFlight({ type: "decode.ready", attempt, origin: originFrame() })
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
const dimTo = (target: number, spring: DurationOptions) => {
|
|
353
|
-
dim.omega = (2 * Math.PI) / spring.duration
|
|
354
|
-
dim.zeta = 1 - spring.bounce
|
|
355
|
-
dim.set(target)
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
// One job on the shared frame loop steps the flight and the backdrop together and writes them straight to the DOM.
|
|
359
|
-
const run = () => {
|
|
360
|
-
flightJob ??= frameLoop.add((dt) => {
|
|
361
|
-
const flying = course?.flight.step(dt)
|
|
362
|
-
dim.step(dt)
|
|
363
|
-
veil.step(dt)
|
|
364
|
-
paint()
|
|
365
|
-
|
|
366
|
-
// The real image takes over only once the panel holding it is fully opaque, so its brightness doesn't step.
|
|
367
|
-
if (course && !flying && dim.resting) {
|
|
368
|
-
course = undefined
|
|
369
|
-
dispatchFlight(SETTLED)
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
if (course || !dim.resting || !veil.resting) return true
|
|
373
|
-
flightJob = undefined
|
|
374
|
-
dispatchFlight(SETTLED)
|
|
375
|
-
|
|
376
|
-
return false
|
|
377
|
-
})
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// The image flies as a stand-in over the preview; a video flies itself and stays where it lands.
|
|
381
|
-
const flyer = () => (props.video ? holder && props.video : standIn)
|
|
382
|
-
|
|
383
|
-
const paint = () => {
|
|
384
|
-
const flying = flyer()
|
|
385
|
-
// Without a flight (reduced motion, or nothing on the page to fly to) the preview only fades with the backdrop.
|
|
386
|
-
const plain = selectFlightFading(untrack(flight))
|
|
387
|
-
scrim.style.opacity = String(dim.value)
|
|
388
|
-
surface.style.opacity = course ? "1" : "0"
|
|
389
|
-
|
|
390
|
-
if (flying) flying.style.opacity = String(plain ? dim.value : veil.value)
|
|
391
|
-
|
|
392
|
-
if (course) {
|
|
393
|
-
const frame = course.flight.frame()
|
|
394
|
-
const style = flightStyle(course.at, frame)
|
|
395
|
-
|
|
396
|
-
if (flying) {
|
|
397
|
-
flying.style.transform = style.transform
|
|
398
|
-
flying.style.clipPath = style.clipPath
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
// The shadow and the outline are leaf boxes, so sizing them every frame stays cheap; scaling them instead would
|
|
402
|
-
// stretch their corners and shadow.
|
|
403
|
-
layout(surface, frame.surface, frame.surfaceRadius)
|
|
404
|
-
surface.style.setProperty("--image-preview-lift", String(frame.lift))
|
|
405
|
-
layout(edge, frame.clip, frame.radius)
|
|
406
|
-
lift = frame.lift
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
// Flying, the controls arrive as the image lifts; without a flight they fade with the backdrop.
|
|
410
|
-
content.style.opacity = String(plain ? dim.value : course ? lift ** 2 : dim.value ** 2)
|
|
411
|
-
edge.style.opacity = String((1 - lift) * veil.value)
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
const place = (box: Box) => {
|
|
415
|
-
const flying = flyer()
|
|
416
|
-
|
|
417
|
-
if (!flying) return box
|
|
418
|
-
flying.style.left = `${box.x}px`
|
|
419
|
-
flying.style.top = `${box.y}px`
|
|
420
|
-
flying.style.width = `${box.width}px`
|
|
421
|
-
flying.style.height = `${box.height}px`
|
|
422
|
-
|
|
423
|
-
return box
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
// Moves the video into the preview, leaving a box of its size in its place to fly back to.
|
|
427
|
-
const borrow = () => {
|
|
428
|
-
const video = props.video
|
|
429
|
-
|
|
430
|
-
if (!video) return
|
|
431
|
-
const rect = video.getBoundingClientRect()
|
|
432
|
-
holder = document.createElement("div")
|
|
433
|
-
Object.assign(holder.style, {
|
|
434
|
-
flex: "none",
|
|
435
|
-
width: `${rect.width}px`,
|
|
436
|
-
height: `${rect.height}px`,
|
|
437
|
-
borderRadius: getComputedStyle(video).borderTopLeftRadius,
|
|
438
|
-
})
|
|
439
|
-
video.before(holder)
|
|
440
|
-
root.moveBefore(video, null)
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
const giveBack = () => {
|
|
444
|
-
const video = props.video
|
|
445
|
-
|
|
446
|
-
if (!video || !holder) return
|
|
447
|
-
|
|
448
|
-
// A page that closed under the preview, such as its tab, has nowhere to take the video back: let it go.
|
|
449
|
-
if (holder.isConnected && holder.parentElement) holder.parentElement.moveBefore(video, holder)
|
|
450
|
-
else dispose(video)
|
|
451
|
-
holder.remove()
|
|
452
|
-
holder = undefined
|
|
453
|
-
;["left", "top", "width", "height", "opacity", "transform", "clip-path", "object-view-box"].forEach((property) =>
|
|
454
|
-
video.style.removeProperty(property),
|
|
455
|
-
)
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
// The image as shown now, zoomed and panned and cropped to the viewport. There is no panel: the image is the surface.
|
|
459
|
-
const restFrame = (): FlightFrame => {
|
|
460
|
-
const shownBox = image.getBoundingClientRect()
|
|
461
|
-
const clip = intersect(shownBox, viewport.getBoundingClientRect())
|
|
462
|
-
const cropped = clip.width < shownBox.width - 0.5 || clip.height < shownBox.height - 0.5
|
|
463
|
-
|
|
464
|
-
const radius = cropped
|
|
465
|
-
? 0
|
|
466
|
-
: parseFloat(getComputedStyle(image).borderTopLeftRadius) * (props.video ? 1 : scaleSpring.value)
|
|
467
|
-
|
|
468
|
-
return { image: shownBox, clip, radius, surface: clip, surfaceRadius: radius, lift: 1 }
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
// The origin's frame, cropped to the part the page shows, or nothing when it is gone, out of sight, or motion is
|
|
472
|
-
// reduced.
|
|
473
|
-
const originFrame = () => {
|
|
474
|
-
const origin = home()
|
|
475
|
-
|
|
476
|
-
if (prefersReducedMotion() || !origin?.isConnected || !natural.width) return
|
|
477
|
-
const rect = origin.getBoundingClientRect()
|
|
478
|
-
|
|
479
|
-
if (!rect.width || !rect.height) return
|
|
480
|
-
// The dialog stack portals the preview with its overlay; both sit over the page it looks through.
|
|
481
|
-
const visible = visibleBox(origin, root.closest("[data-dialog-layer]")?.parentElement ?? root)
|
|
482
|
-
|
|
483
|
-
if (!visible) return
|
|
484
|
-
const style = getComputedStyle(origin)
|
|
485
|
-
// An image's outline is often an overlay, since an inset shadow does not paint over an <img>. A video brings its
|
|
486
|
-
// own.
|
|
487
|
-
edge.style.boxShadow = props.video
|
|
488
|
-
? "none"
|
|
489
|
-
: ([style.boxShadow, getComputedStyle(origin, "::after").boxShadow].find((shadow) => shadow !== "none") ?? "none")
|
|
490
|
-
|
|
491
|
-
return elementFrame(rect, natural, style.objectFit, parseFloat(style.borderTopLeftRadius) || 0, visible)
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
// The image's fitted layout box, wherever zoom has moved it. A video zooms inside its box, which stays put.
|
|
495
|
-
const fitted = (): Box => {
|
|
496
|
-
const shownBox = image.getBoundingClientRect()
|
|
497
|
-
const x = props.video ? 0 : xSpring.value
|
|
498
|
-
const y = props.video ? 0 : ySpring.value
|
|
499
|
-
|
|
500
|
-
return {
|
|
501
|
-
x: shownBox.x + shownBox.width / 2 - x - image.offsetWidth / 2,
|
|
502
|
-
y: shownBox.y + shownBox.height / 2 - y - image.offsetHeight / 2,
|
|
503
|
-
width: image.offsetWidth,
|
|
504
|
-
height: image.offsetHeight,
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
const home = () => holder ?? props.origin ?? props.video
|
|
509
|
-
const panElement = (target: PanTarget) => (target === "video" && props.video ? props.video : viewport)
|
|
510
|
-
|
|
511
|
-
const suppressVideoClick = () => {
|
|
512
|
-
const video = props.video
|
|
513
|
-
|
|
514
|
-
if (!video) return
|
|
515
|
-
|
|
516
|
-
const swallow = (event: MouseEvent) => {
|
|
517
|
-
event.preventDefault()
|
|
518
|
-
event.stopImmediatePropagation()
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
// The click follows its pointerup in the same task; one that never comes must not swallow a later one.
|
|
522
|
-
video.addEventListener("click", swallow, { capture: true, once: true })
|
|
523
|
-
setTimeout(() => video.removeEventListener("click", swallow, { capture: true }))
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
onCleanup(() => {
|
|
527
|
-
dispatchFlight({ type: "disposed" })
|
|
528
|
-
dispatchZoom({ type: "disposed" })
|
|
529
|
-
})
|
|
530
|
-
|
|
531
|
-
const closing = () => (layer ? layer.closing() : !dialog.isOpen())
|
|
532
|
-
|
|
533
|
-
createEffect(
|
|
534
|
-
on(closing, (value) => {
|
|
535
|
-
if (value) dispatchFlight({ type: "close.started", origin: originFrame() })
|
|
536
|
-
}),
|
|
537
|
-
)
|
|
538
|
-
|
|
539
|
-
// From the center of the box zoom is measured in: the window's for an image, the frame's for a video.
|
|
540
|
-
const point = (event: MouseEvent) => {
|
|
541
|
-
const rect = (props.video ? image : viewport).getBoundingClientRect()
|
|
542
|
-
|
|
543
|
-
return { x: event.clientX - rect.left - rect.width / 2, y: event.clientY - rect.top - rect.height / 2 }
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
const measure = () => {
|
|
547
|
-
natural.width = image instanceof HTMLImageElement ? image.naturalWidth : image.width
|
|
548
|
-
natural.height = image instanceof HTMLImageElement ? image.naturalHeight : image.height
|
|
549
|
-
|
|
550
|
-
if (!natural.width || !image.offsetWidth) return
|
|
551
|
-
bounds.width = image.offsetWidth
|
|
552
|
-
bounds.height = image.offsetHeight
|
|
553
|
-
bounds.viewportWidth = props.video ? image.offsetWidth : viewport.clientWidth
|
|
554
|
-
bounds.viewportHeight = props.video ? image.offsetHeight : viewport.clientHeight
|
|
555
|
-
fitRatio = bounds.width / natural.width
|
|
556
|
-
bounds.maxScale = maxScale(fitRatio)
|
|
557
|
-
const next = clampView(view(), bounds)
|
|
558
|
-
follow(next.scale, next.x, next.y)
|
|
559
|
-
|
|
560
|
-
if (!props.video) return
|
|
561
|
-
|
|
562
|
-
// A video is ready as soon as the preview has laid out its box.
|
|
563
|
-
if (selectAwaitingReveal(untrack(flight))) return dispatchFlight({ type: "video.ready", origin: originFrame() })
|
|
564
|
-
|
|
565
|
-
if (selectVideoAtRest(untrack(flight))) place(fitted())
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
createResizeObserver(() => [viewport, image], measure)
|
|
569
|
-
|
|
570
|
-
createEffect(
|
|
571
|
-
on(
|
|
572
|
-
() => props.src,
|
|
573
|
-
() => {
|
|
574
|
-
dispatchFlight({ type: "src.changed" })
|
|
575
|
-
follow(FIT_VIEW.scale, FIT_VIEW.x, FIT_VIEW.y)
|
|
576
|
-
},
|
|
577
|
-
{ defer: true },
|
|
578
|
-
),
|
|
579
|
-
)
|
|
580
|
-
|
|
581
|
-
const interactive = () => selectFlightInteractive(untrack(flight))
|
|
582
|
-
|
|
583
|
-
const detail = (event: MouseEvent) => {
|
|
584
|
-
if (!interactive()) return
|
|
585
|
-
|
|
586
|
-
if (scaleSpring.target > 1) return ease(FIT_VIEW)
|
|
587
|
-
ease(zoomAt(goal(), detailScale(fitRatio), point(event), bounds))
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
const press = (event: PointerEvent, target: PanTarget | "content", onBackdrop: boolean) => {
|
|
591
|
-
if (!interactive()) return
|
|
592
|
-
dispatchZoom({
|
|
593
|
-
type: "pointer.down",
|
|
594
|
-
pointerId: event.pointerId,
|
|
595
|
-
button: event.button,
|
|
596
|
-
target,
|
|
597
|
-
onBackdrop,
|
|
598
|
-
zoomed: scaleSpring.value > 1,
|
|
599
|
-
})
|
|
600
|
-
|
|
601
|
-
if (!selectPanPointer(untrack(zoom), event.pointerId)) return
|
|
602
|
-
event.preventDefault()
|
|
603
|
-
cursor.x = event.clientX
|
|
604
|
-
cursor.y = event.clientY
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
// The hot path of a pan: no layout reads, and no Solid writes once the pan has moved.
|
|
608
|
-
const pan = (event: PointerEvent) => {
|
|
609
|
-
if (!selectPanPointer(untrack(zoom), event.pointerId)) return
|
|
610
|
-
|
|
611
|
-
// The button came up without a pointerup reaching the preview, so this is a hover, not a drag.
|
|
612
|
-
if ((event.buttons & 1) === 0) return dispatchZoom({ type: "pointer.cancel", pointerId: event.pointerId })
|
|
613
|
-
const dx = event.clientX - cursor.x
|
|
614
|
-
const dy = event.clientY - cursor.y
|
|
615
|
-
|
|
616
|
-
if (dx === 0 && dy === 0) return
|
|
617
|
-
cursor.x = event.clientX
|
|
618
|
-
cursor.y = event.clientY
|
|
619
|
-
movedEvent.pointerId = event.pointerId
|
|
620
|
-
dispatchZoom(movedEvent)
|
|
621
|
-
const scale = scaleSpring.value
|
|
622
|
-
follow(
|
|
623
|
-
scale,
|
|
624
|
-
clampAxis(xSpring.value + dx, bounds.width * scale, bounds.viewportWidth),
|
|
625
|
-
clampAxis(ySpring.value + dy, bounds.height * scale, bounds.viewportHeight),
|
|
626
|
-
)
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
const release = (event: PointerEvent) => dispatchZoom({ type: "pointer.up", pointerId: event.pointerId })
|
|
630
|
-
const cancel = (event: PointerEvent) => dispatchZoom({ type: "pointer.cancel", pointerId: event.pointerId })
|
|
631
|
-
|
|
632
|
-
if (props.video) {
|
|
633
|
-
const video = props.video
|
|
634
|
-
makeEventListener(video, "pointerdown", (event: PointerEvent) => {
|
|
635
|
-
if (event.clientY < video.getBoundingClientRect().bottom - CONTROLS) press(event, "video", false)
|
|
636
|
-
})
|
|
637
|
-
makeEventListener(video, "pointermove", pan)
|
|
638
|
-
makeEventListener(video, "pointerup", release)
|
|
639
|
-
makeEventListener(video, "pointercancel", cancel)
|
|
640
|
-
makeEventListener(video, "lostpointercapture", cancel)
|
|
641
|
-
makeEventListener(video, "dblclick", detail)
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
// The preview owns zoom gestures while it is open: the page behind must neither scroll nor zoom the whole window.
|
|
645
|
-
makeEventListener(
|
|
646
|
-
window,
|
|
647
|
-
"wheel",
|
|
648
|
-
(event: WheelEvent) => {
|
|
649
|
-
if (!interactive()) return
|
|
650
|
-
const inside = event.target instanceof Node && (viewport.contains(event.target) || event.target === props.video)
|
|
651
|
-
|
|
652
|
-
const pinch = event.ctrlKey || event.metaKey
|
|
653
|
-
|
|
654
|
-
if (!inside && !pinch) return
|
|
655
|
-
event.preventDefault()
|
|
656
|
-
event.stopPropagation()
|
|
657
|
-
|
|
658
|
-
if (!inside) return
|
|
659
|
-
const current = view()
|
|
660
|
-
|
|
661
|
-
const next = pinch
|
|
662
|
-
? zoomAt(current, current.scale * wheelZoomFactor(wheelPixels(event, event.deltaY)), point(event), bounds)
|
|
663
|
-
: panBy(current, wheelPan(event), bounds)
|
|
664
|
-
|
|
665
|
-
follow(next.scale, next.x, next.y)
|
|
666
|
-
},
|
|
667
|
-
{ passive: false, capture: true },
|
|
668
|
-
)
|
|
669
|
-
|
|
670
|
-
// Captured ahead of the desktop shell, which zooms the whole window on the same shortcuts.
|
|
671
|
-
makeEventListener(
|
|
672
|
-
window,
|
|
673
|
-
"keydown",
|
|
674
|
-
(event: KeyboardEvent) => {
|
|
675
|
-
if (!interactive()) return
|
|
676
|
-
const bare = !event.metaKey && !event.ctrlKey && !event.altKey
|
|
677
|
-
|
|
678
|
-
if (bare && event.key === " " && props.video) {
|
|
679
|
-
event.preventDefault()
|
|
680
|
-
event.stopPropagation()
|
|
681
|
-
|
|
682
|
-
if (props.video.paused) return void props.video.play().catch(() => undefined)
|
|
683
|
-
|
|
684
|
-
return props.video.pause()
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
const action = bare ? (event.key === "0" ? "fit" : undefined) : event.altKey ? undefined : zoomShortcut(event.key)
|
|
688
|
-
|
|
689
|
-
if (!action) return
|
|
690
|
-
event.preventDefault()
|
|
691
|
-
event.stopPropagation()
|
|
692
|
-
|
|
693
|
-
if (action === "fit") return ease(FIT_VIEW)
|
|
694
|
-
step(action === "in" ? STEP : 1 / STEP)
|
|
695
|
-
},
|
|
696
|
-
{ capture: true },
|
|
697
|
-
)
|
|
698
|
-
|
|
699
|
-
return (
|
|
700
|
-
<div
|
|
701
|
-
ref={root}
|
|
702
|
-
data-component="image-preview"
|
|
703
|
-
data-stage={selectFlightStage(flight())}
|
|
704
|
-
// Zoomed in, the first Escape zooms back out; the dialog stack leaves it to the preview.
|
|
705
|
-
data-owns-escape={shown.ownsEscape ? "" : undefined}
|
|
706
|
-
style={{ "--image-preview-exit": `${EXIT_DURATION_MS}ms` }}
|
|
707
|
-
>
|
|
708
|
-
<div ref={scrim} data-slot="image-preview-scrim" />
|
|
709
|
-
<Kobalte.Content
|
|
710
|
-
ref={content}
|
|
711
|
-
data-slot="image-preview-content"
|
|
712
|
-
onOpenAutoFocus={(event) => {
|
|
713
|
-
// Open with focus on Close, as before, rather than on the zoom controls that precede it.
|
|
714
|
-
event.preventDefault()
|
|
715
|
-
close?.focus()
|
|
716
|
-
}}
|
|
717
|
-
onEscapeKeyDown={(event) => {
|
|
718
|
-
if (scaleSpring.target <= 1) return
|
|
719
|
-
event.preventDefault()
|
|
720
|
-
ease(FIT_VIEW)
|
|
721
|
-
}}
|
|
722
|
-
// A borrowed video sits over the preview rather than in it; using its controls keeps the preview open.
|
|
723
|
-
onInteractOutside={(event) => {
|
|
724
|
-
if (props.video && event.target === props.video) event.preventDefault()
|
|
725
|
-
}}
|
|
726
|
-
onPointerDown={(event: PointerEvent) => {
|
|
727
|
-
const target = event.target
|
|
728
|
-
const body = target instanceof Node && viewport.contains(target)
|
|
729
|
-
press(event, body ? "viewport" : "content", target === content || target === viewport)
|
|
730
|
-
}}
|
|
731
|
-
// The preview fills the window, so a click on the backdrop around the image lands here rather than outside.
|
|
732
|
-
onClick={(event: MouseEvent) =>
|
|
733
|
-
dispatchZoom({
|
|
734
|
-
type: "backdrop.click",
|
|
735
|
-
onBackdrop: event.target === content || event.target === viewport,
|
|
736
|
-
})
|
|
737
|
-
}
|
|
738
|
-
>
|
|
739
|
-
<div
|
|
740
|
-
ref={viewport}
|
|
741
|
-
data-slot="image-preview-body"
|
|
742
|
-
data-zoomed={shown.zoomed ? "" : undefined}
|
|
743
|
-
data-dragging={selectDragging(zoom()) ? "" : undefined}
|
|
744
|
-
onDblClick={detail}
|
|
745
|
-
onPointerMove={pan}
|
|
746
|
-
onPointerUp={release}
|
|
747
|
-
onPointerCancel={cancel}
|
|
748
|
-
onLostPointerCapture={cancel}
|
|
749
|
-
>
|
|
750
|
-
<Show
|
|
751
|
-
when={props.video}
|
|
752
|
-
fallback={
|
|
753
|
-
<img
|
|
754
|
-
ref={(element) => (image = element)}
|
|
755
|
-
src={props.src}
|
|
756
|
-
alt={props.alt ?? i18n.t("ui.imagePreview.alt")}
|
|
757
|
-
data-slot="image-preview-image"
|
|
758
|
-
draggable={false}
|
|
759
|
-
onLoad={() => {
|
|
760
|
-
measure()
|
|
761
|
-
dispatchFlight({ type: "image.loaded" })
|
|
762
|
-
}}
|
|
763
|
-
onError={() => dispatchFlight({ type: "image.failed" })}
|
|
764
|
-
/>
|
|
765
|
-
}
|
|
766
|
-
>
|
|
767
|
-
{(video) => (
|
|
768
|
-
<canvas
|
|
769
|
-
ref={(element) => (image = element)}
|
|
770
|
-
data-slot="image-preview-image"
|
|
771
|
-
width={video().videoWidth}
|
|
772
|
-
height={video().videoHeight}
|
|
773
|
-
/>
|
|
774
|
-
)}
|
|
775
|
-
</Show>
|
|
776
|
-
</div>
|
|
777
|
-
<div data-slot="image-preview-controls">
|
|
778
|
-
<IconButton
|
|
779
|
-
data-slot="image-preview-zoom-out"
|
|
780
|
-
icon={<Icon name="minus" />}
|
|
781
|
-
variant="ghost"
|
|
782
|
-
aria-label={i18n.t("ui.imagePreview.zoomOut")}
|
|
783
|
-
onClick={() => step(1 / STEP)}
|
|
784
|
-
/>
|
|
785
|
-
<Button
|
|
786
|
-
data-slot="image-preview-zoom-level"
|
|
787
|
-
variant="ghost-muted"
|
|
788
|
-
size="small"
|
|
789
|
-
aria-label={i18n.t("ui.imagePreview.zoomToFit")}
|
|
790
|
-
title={i18n.t("ui.imagePreview.zoomToFit")}
|
|
791
|
-
onClick={() => ease(FIT_VIEW)}
|
|
792
|
-
>
|
|
793
|
-
{percent().format(shown.level / 100)}
|
|
794
|
-
</Button>
|
|
795
|
-
<IconButton
|
|
796
|
-
data-slot="image-preview-zoom-in"
|
|
797
|
-
icon={<Icon name="plus" />}
|
|
798
|
-
variant="ghost"
|
|
799
|
-
aria-label={i18n.t("ui.imagePreview.zoomIn")}
|
|
800
|
-
onClick={() => step(STEP)}
|
|
801
|
-
/>
|
|
802
|
-
<div data-slot="image-preview-divider" />
|
|
803
|
-
<Kobalte.CloseButton
|
|
804
|
-
ref={close}
|
|
805
|
-
data-slot="image-preview-close"
|
|
806
|
-
as={IconButton}
|
|
807
|
-
icon={<Icon name="close" />}
|
|
808
|
-
variant="ghost"
|
|
809
|
-
aria-label={i18n.t("ui.common.close")}
|
|
810
|
-
/>
|
|
811
|
-
</div>
|
|
812
|
-
</Kobalte.Content>
|
|
813
|
-
<div data-slot="image-preview-surface" ref={surface} />
|
|
814
|
-
<Show when={!props.video}>
|
|
815
|
-
<img data-slot="image-preview-flight" src={props.src} alt="" aria-hidden="true" ref={standIn} />
|
|
816
|
-
</Show>
|
|
817
|
-
<div data-slot="image-preview-edge" ref={edge} />
|
|
818
|
-
</div>
|
|
819
|
-
)
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
// The part of `origin` the page under `preview` shows: inside its clipping ancestors and the window, and clear of
|
|
823
|
-
// anything drawn over its top or bottom, such as a sticky title bar. Nothing when none of it shows.
|
|
824
|
-
function visibleBox(origin: HTMLElement, preview: Element): Box | undefined {
|
|
825
|
-
const clipped = ancestors(origin).reduce(
|
|
826
|
-
(box: Box, element) => {
|
|
827
|
-
const style = getComputedStyle(element)
|
|
828
|
-
|
|
829
|
-
if (style.overflowX === "visible" && style.overflowY === "visible") return box
|
|
830
|
-
|
|
831
|
-
return intersect(box, element.getBoundingClientRect())
|
|
832
|
-
},
|
|
833
|
-
intersect(origin.getBoundingClientRect(), { x: 0, y: 0, width: window.innerWidth, height: window.innerHeight }),
|
|
834
|
-
)
|
|
835
|
-
|
|
836
|
-
const rows = Math.floor(clipped.height)
|
|
837
|
-
|
|
838
|
-
if (!clipped.width || rows < 1) return
|
|
839
|
-
const x = clipped.x + clipped.width / 2
|
|
840
|
-
|
|
841
|
-
// The origin is hidden while the preview flies, so the page shows it where the topmost element under the preview
|
|
842
|
-
// holds it.
|
|
843
|
-
const shows = (y: number) =>
|
|
844
|
-
document
|
|
845
|
-
.elementsFromPoint(x, y)
|
|
846
|
-
.find((element) => !preview.contains(element))
|
|
847
|
-
?.contains(origin) ?? false
|
|
848
|
-
|
|
849
|
-
const top = covered(rows, (row) => shows(clipped.y + row + 0.5))
|
|
850
|
-
|
|
851
|
-
if (top === rows) return
|
|
852
|
-
const bottom = covered(rows - top, (row) => shows(clipped.y + clipped.height - row - 0.5))
|
|
853
|
-
|
|
854
|
-
return { x: clipped.x, y: clipped.y + top, width: clipped.width, height: clipped.height - top - bottom }
|
|
855
|
-
}
|
|
856
|
-
|
|
857
|
-
function ancestors(element: HTMLElement) {
|
|
858
|
-
const list: HTMLElement[] = []
|
|
859
|
-
|
|
860
|
-
for (let parent = element.parentElement; parent; parent = parent.parentElement) list.push(parent)
|
|
861
|
-
|
|
862
|
-
return list
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
// How many of `rows`, counted in from an edge, are covered before the first that shows; a covering bar is one piece.
|
|
866
|
-
function covered(rows: number, shows: (row: number) => boolean) {
|
|
867
|
-
let low = 0
|
|
868
|
-
let high = rows
|
|
869
|
-
|
|
870
|
-
while (low < high) {
|
|
871
|
-
const middle = Math.floor((low + high) / 2)
|
|
872
|
-
|
|
873
|
-
if (shows(middle)) {
|
|
874
|
-
high = middle
|
|
875
|
-
continue
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
low = middle + 1
|
|
879
|
-
}
|
|
880
|
-
|
|
881
|
-
return low
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
function dispose(video: HTMLVideoElement) {
|
|
885
|
-
video.pause()
|
|
886
|
-
video.remove()
|
|
887
|
-
video.removeAttribute("src")
|
|
888
|
-
video.srcObject = null
|
|
889
|
-
video.load()
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
function layout(element: HTMLElement, frame: Box, radius: number) {
|
|
893
|
-
element.style.left = `${frame.x}px`
|
|
894
|
-
element.style.top = `${frame.y}px`
|
|
895
|
-
element.style.width = `${frame.width}px`
|
|
896
|
-
element.style.height = `${frame.height}px`
|
|
897
|
-
element.style.borderRadius = `${radius}px`
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
// A plain wheel pans; Shift turns a vertical wheel sideways.
|
|
901
|
-
function wheelPan(event: WheelEvent) {
|
|
902
|
-
const horizontal = event.shiftKey && event.deltaX === 0
|
|
903
|
-
|
|
904
|
-
return {
|
|
905
|
-
x: -wheelPixels(event, horizontal ? event.deltaY : event.deltaX),
|
|
906
|
-
y: horizontal ? 0 : -wheelPixels(event, event.deltaY),
|
|
907
|
-
}
|
|
908
|
-
}
|
|
1
|
+
import { Dialog as Kobalte, useDialogContext } from "@kobalte/core/dialog"
|
|
2
|
+
import { makeEventListener } from "@solid-primitives/event-listener"
|
|
3
|
+
import { createResizeObserver } from "@solid-primitives/resize-observer"
|
|
4
|
+
import { createEffect, createMemo, createSignal, on, onCleanup, Show, untrack } from "solid-js"
|
|
5
|
+
import { createStore } from "solid-js/store"
|
|
6
|
+
import { useDialogLayer } from "../context/dialog"
|
|
7
|
+
import { useI18n } from "../context/i18n"
|
|
8
|
+
import { Button } from "@zyro-sec/ui/button"
|
|
9
|
+
import { Icon } from "@zyro-sec/ui/icon"
|
|
10
|
+
import { IconButton } from "@zyro-sec/ui/icon-button"
|
|
11
|
+
import { frameLoop, prefersReducedMotion, Spring, type DurationOptions } from "../motion"
|
|
12
|
+
import {
|
|
13
|
+
createFlight,
|
|
14
|
+
elementFrame,
|
|
15
|
+
FLIGHT_SPRING,
|
|
16
|
+
flightStyle,
|
|
17
|
+
intersect,
|
|
18
|
+
KICK,
|
|
19
|
+
type Box,
|
|
20
|
+
type FlightFrame,
|
|
21
|
+
} from "./image-flight"
|
|
22
|
+
import {
|
|
23
|
+
DECODE_TIMEOUT_MS,
|
|
24
|
+
INITIAL_PREVIEW_FLIGHT_STATE,
|
|
25
|
+
selectAwaitingReveal,
|
|
26
|
+
selectDecodeCurrent,
|
|
27
|
+
selectFlightFading,
|
|
28
|
+
selectFlightInteractive,
|
|
29
|
+
selectFlightStage,
|
|
30
|
+
selectVideoAtRest,
|
|
31
|
+
transitionPreviewFlight,
|
|
32
|
+
type PreviewFlightEffect,
|
|
33
|
+
type PreviewFlightEvent,
|
|
34
|
+
} from "./image-flight-machine"
|
|
35
|
+
import {
|
|
36
|
+
clampAxis,
|
|
37
|
+
clampView,
|
|
38
|
+
detailScale,
|
|
39
|
+
FIT_VIEW,
|
|
40
|
+
maxScale,
|
|
41
|
+
panBy,
|
|
42
|
+
viewBox,
|
|
43
|
+
wheelPixels,
|
|
44
|
+
wheelZoomFactor,
|
|
45
|
+
zoomAt,
|
|
46
|
+
zoomShortcut,
|
|
47
|
+
type ZoomView,
|
|
48
|
+
} from "./image-zoom"
|
|
49
|
+
import {
|
|
50
|
+
INITIAL_PREVIEW_ZOOM_STATE,
|
|
51
|
+
selectDragging,
|
|
52
|
+
selectPanPointer,
|
|
53
|
+
transitionPreviewZoom,
|
|
54
|
+
type PanTarget,
|
|
55
|
+
type PreviewZoomEffect,
|
|
56
|
+
type PreviewZoomEvent,
|
|
57
|
+
} from "./image-zoom-machine"
|
|
58
|
+
|
|
59
|
+
export interface ImagePreviewProps {
|
|
60
|
+
src: string
|
|
61
|
+
alt?: string
|
|
62
|
+
/** The image on the page that the preview grows out of and shrinks back into. */
|
|
63
|
+
origin?: HTMLElement
|
|
64
|
+
/**
|
|
65
|
+
* A video on the page to show instead of the image. The preview borrows this element, so it keeps playing as it
|
|
66
|
+
* flies out of its place and back, and returns it once the close lands.
|
|
67
|
+
*/
|
|
68
|
+
video?: HTMLVideoElement
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const STEP = Math.SQRT2
|
|
72
|
+
|
|
73
|
+
// How far up from its bottom edge a video keeps its own controls, whose drag scrubs rather than pans.
|
|
74
|
+
const CONTROLS = 56
|
|
75
|
+
|
|
76
|
+
// Without a flight (reduced motion, or no thumbnail to fly to), the preview only fades.
|
|
77
|
+
const fade = { duration: 0.15, bounce: 0 }
|
|
78
|
+
|
|
79
|
+
// How long the dialog stays mounted after a close starts, in milliseconds: the flight lands and hands the image back
|
|
80
|
+
// to the page well within this.
|
|
81
|
+
const EXIT_DURATION_MS = Math.max(FLIGHT_SPRING.duration, fade.duration) * 3200
|
|
82
|
+
|
|
83
|
+
const CENTER = { x: 0, y: 0 }
|
|
84
|
+
|
|
85
|
+
const SETTLED: PreviewFlightEvent = Object.freeze({ type: "motion.settled" })
|
|
86
|
+
|
|
87
|
+
// Previews closing at once, such as one still flying home under the next, share the body's closing mark.
|
|
88
|
+
let closingPreviews = 0
|
|
89
|
+
|
|
90
|
+
export function ImagePreview(props: ImagePreviewProps) {
|
|
91
|
+
const i18n = useI18n()
|
|
92
|
+
const dialog = useDialogContext()
|
|
93
|
+
const layer = useDialogLayer()
|
|
94
|
+
let root!: HTMLDivElement
|
|
95
|
+
let scrim!: HTMLDivElement
|
|
96
|
+
let content!: HTMLDivElement
|
|
97
|
+
let viewport!: HTMLDivElement
|
|
98
|
+
// For a video, an empty canvas of its size: the box it fits to in the window.
|
|
99
|
+
let image!: HTMLImageElement | HTMLCanvasElement
|
|
100
|
+
let standIn: HTMLImageElement | undefined
|
|
101
|
+
// Where a borrowed video was on the page, holding its size until it comes back.
|
|
102
|
+
let holder: HTMLElement | undefined
|
|
103
|
+
let surface!: HTMLDivElement
|
|
104
|
+
let edge!: HTMLDivElement
|
|
105
|
+
let close: HTMLButtonElement | undefined
|
|
106
|
+
|
|
107
|
+
// Nothing shows until the image has loaded and the preview knows where it lands; while flying, a stand-in image and
|
|
108
|
+
// its shadow travel above the dialog in place of the real one.
|
|
109
|
+
const [flight, setFlight] = createSignal(INITIAL_PREVIEW_FLIGHT_STATE)
|
|
110
|
+
const [zoom, setZoom] = createSignal(INITIAL_PREVIEW_ZOOM_STATE)
|
|
111
|
+
// What the view shows the controls and the stylesheet, written only when it changes rather than on every frame.
|
|
112
|
+
const [shown, setShown] = createStore({ zoomed: false, ownsEscape: false, level: 100 })
|
|
113
|
+
|
|
114
|
+
// The flight under way: where the stand-in is laid out (the flight only transforms and clips it) and the springs.
|
|
115
|
+
let course: { at: Box; flight: ReturnType<typeof createFlight> } | undefined
|
|
116
|
+
let flightJob: (() => void) | undefined
|
|
117
|
+
let decodeTimer: ReturnType<typeof setTimeout> | undefined
|
|
118
|
+
|
|
119
|
+
const dim = Spring.fromDuration(0, FLIGHT_SPRING)
|
|
120
|
+
// Once a close lands, the stand-in fades out over the image the page shows again, so whatever the page draws over
|
|
121
|
+
// its own image (a fade under a sticky bar, say) comes in softly instead of in one frame.
|
|
122
|
+
const veil = Spring.fromDuration(1, FLIGHT_SPRING)
|
|
123
|
+
|
|
124
|
+
// How far the flight has lifted off the page, as last painted: the origin's outline fades out as it rises.
|
|
125
|
+
let lift = 0
|
|
126
|
+
|
|
127
|
+
// The view: each spring's value is what shows, and its target is where an eased zoom is heading, so repeated steps
|
|
128
|
+
// build on the destination rather than the frame in flight. Scale and offsets ride springs of one shape, so the point
|
|
129
|
+
// under the pointer stays put; a new target mid-glide keeps the velocity it has.
|
|
130
|
+
const scaleSpring = Spring.fromDuration(1, FLIGHT_SPRING)
|
|
131
|
+
const xSpring = Spring.fromDuration(0, FLIGHT_SPRING)
|
|
132
|
+
const ySpring = Spring.fromDuration(0, FLIGHT_SPRING)
|
|
133
|
+
let glideJob: (() => void) | undefined
|
|
134
|
+
// Where the pan under way last saw its pointer.
|
|
135
|
+
const cursor = { x: 0, y: 0 }
|
|
136
|
+
|
|
137
|
+
// Measured when the preview lays out rather than on every move or frame. A video zooms inside its own frame, so its
|
|
138
|
+
// controls stay where they are; an image zooms out across the window.
|
|
139
|
+
const natural = { width: 0, height: 0 }
|
|
140
|
+
const bounds = { width: 0, height: 0, viewportWidth: 0, viewportHeight: 0, maxScale: 1 }
|
|
141
|
+
let fitRatio = 1
|
|
142
|
+
|
|
143
|
+
// Reused on every pointer move of a pan.
|
|
144
|
+
const followEvent = { type: "follow" as const, zoomed: false }
|
|
145
|
+
const movedEvent = { type: "pointer.moved" as const, pointerId: 0 }
|
|
146
|
+
|
|
147
|
+
const percent = createMemo(() => new Intl.NumberFormat(i18n.locale(), { style: "percent", maximumFractionDigits: 0 }))
|
|
148
|
+
|
|
149
|
+
const dispatchFlight = (event: PreviewFlightEvent) => {
|
|
150
|
+
const prev = untrack(flight)
|
|
151
|
+
const next = transitionPreviewFlight(prev, event)
|
|
152
|
+
|
|
153
|
+
if (next.state !== prev) setFlight(next.state)
|
|
154
|
+
next.effects.forEach(runFlight)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const runFlight = (effect: PreviewFlightEffect) => {
|
|
158
|
+
if (effect.type === "decode.start") return decode(effect.attempt)
|
|
159
|
+
|
|
160
|
+
if (effect.type === "decode.cancel") return clearTimeout(decodeTimer)
|
|
161
|
+
|
|
162
|
+
if (effect.type === "video.borrow") return borrow()
|
|
163
|
+
|
|
164
|
+
if (effect.type === "video.return") return giveBack()
|
|
165
|
+
|
|
166
|
+
if (effect.type === "origin.hide") return home()?.setAttribute("data-image-preview-origin", "")
|
|
167
|
+
|
|
168
|
+
if (effect.type === "origin.show") return home()?.removeAttribute("data-image-preview-origin")
|
|
169
|
+
|
|
170
|
+
if (effect.type === "open.flight") {
|
|
171
|
+
dimTo(1, FLIGHT_SPRING)
|
|
172
|
+
const next = createFlight(effect.from)
|
|
173
|
+
next.to(restFrame(), KICK.open, FLIGHT_SPRING)
|
|
174
|
+
course = { at: place(fitted()), flight: next }
|
|
175
|
+
paint()
|
|
176
|
+
|
|
177
|
+
return run()
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (effect.type === "open.fade") {
|
|
181
|
+
dimTo(1, fade)
|
|
182
|
+
|
|
183
|
+
if (props.video) place(fitted())
|
|
184
|
+
paint()
|
|
185
|
+
|
|
186
|
+
return run()
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (effect.type === "close.flight") {
|
|
190
|
+
dimTo(0, FLIGHT_SPRING)
|
|
191
|
+
|
|
192
|
+
if (!effect.turn) course = { at: place(fitted()), flight: createFlight(restFrame()) }
|
|
193
|
+
course?.flight.to(effect.to, KICK.close, FLIGHT_SPRING)
|
|
194
|
+
paint()
|
|
195
|
+
|
|
196
|
+
return run()
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (effect.type === "close.veil") {
|
|
200
|
+
veil.omega = (2 * Math.PI) / (FLIGHT_SPRING.duration * 0.75)
|
|
201
|
+
veil.set(0)
|
|
202
|
+
|
|
203
|
+
return
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (effect.type === "close.fade") {
|
|
207
|
+
course = undefined
|
|
208
|
+
dimTo(0, fade)
|
|
209
|
+
|
|
210
|
+
return run()
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (effect.type === "zoom.fit") return ease(FIT_VIEW)
|
|
214
|
+
|
|
215
|
+
if (effect.type === "zoom.settle") return follow(scaleSpring.value, xSpring.value, ySpring.value)
|
|
216
|
+
|
|
217
|
+
// See image-preview.css: the body takes clicks again while the closing flight holds the dialog mounted.
|
|
218
|
+
if (effect.type === "body.closing.acquire") {
|
|
219
|
+
closingPreviews++
|
|
220
|
+
document.body.setAttribute("data-image-preview-closing", "")
|
|
221
|
+
|
|
222
|
+
return
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (effect.type === "body.closing.release") {
|
|
226
|
+
closingPreviews--
|
|
227
|
+
|
|
228
|
+
if (!closingPreviews) document.body.removeAttribute("data-image-preview-closing")
|
|
229
|
+
|
|
230
|
+
return
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
flightJob?.()
|
|
234
|
+
flightJob = undefined
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const dispatchZoom = (event: PreviewZoomEvent) => {
|
|
238
|
+
const prev = untrack(zoom)
|
|
239
|
+
const next = transitionPreviewZoom(prev, event)
|
|
240
|
+
|
|
241
|
+
if (next.state !== prev) setZoom(next.state)
|
|
242
|
+
next.effects.forEach(runZoom)
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const runZoom = (effect: PreviewZoomEffect) => {
|
|
246
|
+
if (effect.type === "pointer.capture") return panElement(effect.target).setPointerCapture(effect.pointerId)
|
|
247
|
+
|
|
248
|
+
if (effect.type === "pointer.release") {
|
|
249
|
+
const element = panElement(effect.target)
|
|
250
|
+
|
|
251
|
+
if (element.hasPointerCapture(effect.pointerId)) element.releasePointerCapture(effect.pointerId)
|
|
252
|
+
|
|
253
|
+
return
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (effect.type === "glide.loop.start") {
|
|
257
|
+
glideJob = frameLoop.add((dt) => {
|
|
258
|
+
scaleSpring.step(dt)
|
|
259
|
+
xSpring.step(dt)
|
|
260
|
+
ySpring.step(dt)
|
|
261
|
+
paintZoom()
|
|
262
|
+
|
|
263
|
+
if (!scaleSpring.resting || !xSpring.resting || !ySpring.resting) return true
|
|
264
|
+
dispatchZoom({ type: "glide.settled", zoomed: scaleSpring.value > 1 })
|
|
265
|
+
|
|
266
|
+
return false
|
|
267
|
+
})
|
|
268
|
+
|
|
269
|
+
return
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (effect.type === "glide.loop.stop") {
|
|
273
|
+
glideJob?.()
|
|
274
|
+
glideJob = undefined
|
|
275
|
+
|
|
276
|
+
return
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (effect.type === "video.suppress-click") return suppressVideoClick()
|
|
280
|
+
|
|
281
|
+
dialog.close()
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// Writes the view to the DOM. A frame allocates nothing but the style string, and touches Solid state only when
|
|
285
|
+
// the zoom level's rounded percent or whether the image is zoomed changes.
|
|
286
|
+
const paintZoom = () => {
|
|
287
|
+
const scale = scaleSpring.value
|
|
288
|
+
|
|
289
|
+
if (props.video) {
|
|
290
|
+
props.video.style.setProperty("object-view-box", viewBox(scale, xSpring.value, ySpring.value, bounds, natural))
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (!props.video) image.style.transform = `translate(${xSpring.value}px, ${ySpring.value}px) scale(${scale})`
|
|
294
|
+
const level = Math.round(scale * fitRatio * 100)
|
|
295
|
+
|
|
296
|
+
if (shown.zoomed !== scale > 1) setShown("zoomed", scale > 1)
|
|
297
|
+
|
|
298
|
+
if (shown.level !== level) setShown("level", level)
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const view = (): ZoomView => ({ scale: scaleSpring.value, x: xSpring.value, y: ySpring.value })
|
|
302
|
+
const goal = (): ZoomView => ({ scale: scaleSpring.target, x: xSpring.target, y: ySpring.target })
|
|
303
|
+
|
|
304
|
+
const own = (scale: number) => {
|
|
305
|
+
if (shown.ownsEscape !== scale > 1) setShown("ownsEscape", scale > 1)
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Pinch, wheel and drag follow the hand directly and take over from an eased zoom mid-flight.
|
|
309
|
+
const follow = (scale: number, x: number, y: number) => {
|
|
310
|
+
followEvent.zoomed = scale > 1
|
|
311
|
+
dispatchZoom(followEvent)
|
|
312
|
+
scaleSpring.snap(scale)
|
|
313
|
+
xSpring.snap(x)
|
|
314
|
+
ySpring.snap(y)
|
|
315
|
+
own(scale)
|
|
316
|
+
paintZoom()
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const ease = (target: ZoomView) => {
|
|
320
|
+
if (prefersReducedMotion()) return follow(target.scale, target.x, target.y)
|
|
321
|
+
scaleSpring.set(target.scale)
|
|
322
|
+
xSpring.set(target.x)
|
|
323
|
+
ySpring.set(target.y)
|
|
324
|
+
own(target.scale)
|
|
325
|
+
dispatchZoom({ type: "glide.start" })
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const step = (factor: number) => {
|
|
329
|
+
const target = goal()
|
|
330
|
+
ease(zoomAt(target, target.scale * factor, CENTER, bounds))
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// Kobalte keeps the content mounted while an exit animation runs; the dialog stack waits for the flight too.
|
|
334
|
+
layer?.setExitDuration(EXIT_DURATION_MS)
|
|
335
|
+
|
|
336
|
+
const decode = (attempt: number) => {
|
|
337
|
+
clearTimeout(decodeTimer)
|
|
338
|
+
decodeTimer = setTimeout(() => decoded(attempt), DECODE_TIMEOUT_MS)
|
|
339
|
+
|
|
340
|
+
if (!(image instanceof HTMLImageElement)) return
|
|
341
|
+
void Promise.all([image.decode(), standIn?.decode()])
|
|
342
|
+
.catch(() => undefined)
|
|
343
|
+
.then(() => decoded(attempt))
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// Measuring where the origin shows is not free, so a decode the preview no longer waits for skips it.
|
|
347
|
+
const decoded = (attempt: number) => {
|
|
348
|
+
if (!selectDecodeCurrent(untrack(flight), attempt)) return
|
|
349
|
+
dispatchFlight({ type: "decode.ready", attempt, origin: originFrame() })
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const dimTo = (target: number, spring: DurationOptions) => {
|
|
353
|
+
dim.omega = (2 * Math.PI) / spring.duration
|
|
354
|
+
dim.zeta = 1 - spring.bounce
|
|
355
|
+
dim.set(target)
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// One job on the shared frame loop steps the flight and the backdrop together and writes them straight to the DOM.
|
|
359
|
+
const run = () => {
|
|
360
|
+
flightJob ??= frameLoop.add((dt) => {
|
|
361
|
+
const flying = course?.flight.step(dt)
|
|
362
|
+
dim.step(dt)
|
|
363
|
+
veil.step(dt)
|
|
364
|
+
paint()
|
|
365
|
+
|
|
366
|
+
// The real image takes over only once the panel holding it is fully opaque, so its brightness doesn't step.
|
|
367
|
+
if (course && !flying && dim.resting) {
|
|
368
|
+
course = undefined
|
|
369
|
+
dispatchFlight(SETTLED)
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
if (course || !dim.resting || !veil.resting) return true
|
|
373
|
+
flightJob = undefined
|
|
374
|
+
dispatchFlight(SETTLED)
|
|
375
|
+
|
|
376
|
+
return false
|
|
377
|
+
})
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// The image flies as a stand-in over the preview; a video flies itself and stays where it lands.
|
|
381
|
+
const flyer = () => (props.video ? holder && props.video : standIn)
|
|
382
|
+
|
|
383
|
+
const paint = () => {
|
|
384
|
+
const flying = flyer()
|
|
385
|
+
// Without a flight (reduced motion, or nothing on the page to fly to) the preview only fades with the backdrop.
|
|
386
|
+
const plain = selectFlightFading(untrack(flight))
|
|
387
|
+
scrim.style.opacity = String(dim.value)
|
|
388
|
+
surface.style.opacity = course ? "1" : "0"
|
|
389
|
+
|
|
390
|
+
if (flying) flying.style.opacity = String(plain ? dim.value : veil.value)
|
|
391
|
+
|
|
392
|
+
if (course) {
|
|
393
|
+
const frame = course.flight.frame()
|
|
394
|
+
const style = flightStyle(course.at, frame)
|
|
395
|
+
|
|
396
|
+
if (flying) {
|
|
397
|
+
flying.style.transform = style.transform
|
|
398
|
+
flying.style.clipPath = style.clipPath
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// The shadow and the outline are leaf boxes, so sizing them every frame stays cheap; scaling them instead would
|
|
402
|
+
// stretch their corners and shadow.
|
|
403
|
+
layout(surface, frame.surface, frame.surfaceRadius)
|
|
404
|
+
surface.style.setProperty("--image-preview-lift", String(frame.lift))
|
|
405
|
+
layout(edge, frame.clip, frame.radius)
|
|
406
|
+
lift = frame.lift
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// Flying, the controls arrive as the image lifts; without a flight they fade with the backdrop.
|
|
410
|
+
content.style.opacity = String(plain ? dim.value : course ? lift ** 2 : dim.value ** 2)
|
|
411
|
+
edge.style.opacity = String((1 - lift) * veil.value)
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const place = (box: Box) => {
|
|
415
|
+
const flying = flyer()
|
|
416
|
+
|
|
417
|
+
if (!flying) return box
|
|
418
|
+
flying.style.left = `${box.x}px`
|
|
419
|
+
flying.style.top = `${box.y}px`
|
|
420
|
+
flying.style.width = `${box.width}px`
|
|
421
|
+
flying.style.height = `${box.height}px`
|
|
422
|
+
|
|
423
|
+
return box
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// Moves the video into the preview, leaving a box of its size in its place to fly back to.
|
|
427
|
+
const borrow = () => {
|
|
428
|
+
const video = props.video
|
|
429
|
+
|
|
430
|
+
if (!video) return
|
|
431
|
+
const rect = video.getBoundingClientRect()
|
|
432
|
+
holder = document.createElement("div")
|
|
433
|
+
Object.assign(holder.style, {
|
|
434
|
+
flex: "none",
|
|
435
|
+
width: `${rect.width}px`,
|
|
436
|
+
height: `${rect.height}px`,
|
|
437
|
+
borderRadius: getComputedStyle(video).borderTopLeftRadius,
|
|
438
|
+
})
|
|
439
|
+
video.before(holder)
|
|
440
|
+
root.moveBefore(video, null)
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
const giveBack = () => {
|
|
444
|
+
const video = props.video
|
|
445
|
+
|
|
446
|
+
if (!video || !holder) return
|
|
447
|
+
|
|
448
|
+
// A page that closed under the preview, such as its tab, has nowhere to take the video back: let it go.
|
|
449
|
+
if (holder.isConnected && holder.parentElement) holder.parentElement.moveBefore(video, holder)
|
|
450
|
+
else dispose(video)
|
|
451
|
+
holder.remove()
|
|
452
|
+
holder = undefined
|
|
453
|
+
;["left", "top", "width", "height", "opacity", "transform", "clip-path", "object-view-box"].forEach((property) =>
|
|
454
|
+
video.style.removeProperty(property),
|
|
455
|
+
)
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// The image as shown now, zoomed and panned and cropped to the viewport. There is no panel: the image is the surface.
|
|
459
|
+
const restFrame = (): FlightFrame => {
|
|
460
|
+
const shownBox = image.getBoundingClientRect()
|
|
461
|
+
const clip = intersect(shownBox, viewport.getBoundingClientRect())
|
|
462
|
+
const cropped = clip.width < shownBox.width - 0.5 || clip.height < shownBox.height - 0.5
|
|
463
|
+
|
|
464
|
+
const radius = cropped
|
|
465
|
+
? 0
|
|
466
|
+
: parseFloat(getComputedStyle(image).borderTopLeftRadius) * (props.video ? 1 : scaleSpring.value)
|
|
467
|
+
|
|
468
|
+
return { image: shownBox, clip, radius, surface: clip, surfaceRadius: radius, lift: 1 }
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// The origin's frame, cropped to the part the page shows, or nothing when it is gone, out of sight, or motion is
|
|
472
|
+
// reduced.
|
|
473
|
+
const originFrame = () => {
|
|
474
|
+
const origin = home()
|
|
475
|
+
|
|
476
|
+
if (prefersReducedMotion() || !origin?.isConnected || !natural.width) return
|
|
477
|
+
const rect = origin.getBoundingClientRect()
|
|
478
|
+
|
|
479
|
+
if (!rect.width || !rect.height) return
|
|
480
|
+
// The dialog stack portals the preview with its overlay; both sit over the page it looks through.
|
|
481
|
+
const visible = visibleBox(origin, root.closest("[data-dialog-layer]")?.parentElement ?? root)
|
|
482
|
+
|
|
483
|
+
if (!visible) return
|
|
484
|
+
const style = getComputedStyle(origin)
|
|
485
|
+
// An image's outline is often an overlay, since an inset shadow does not paint over an <img>. A video brings its
|
|
486
|
+
// own.
|
|
487
|
+
edge.style.boxShadow = props.video
|
|
488
|
+
? "none"
|
|
489
|
+
: ([style.boxShadow, getComputedStyle(origin, "::after").boxShadow].find((shadow) => shadow !== "none") ?? "none")
|
|
490
|
+
|
|
491
|
+
return elementFrame(rect, natural, style.objectFit, parseFloat(style.borderTopLeftRadius) || 0, visible)
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// The image's fitted layout box, wherever zoom has moved it. A video zooms inside its box, which stays put.
|
|
495
|
+
const fitted = (): Box => {
|
|
496
|
+
const shownBox = image.getBoundingClientRect()
|
|
497
|
+
const x = props.video ? 0 : xSpring.value
|
|
498
|
+
const y = props.video ? 0 : ySpring.value
|
|
499
|
+
|
|
500
|
+
return {
|
|
501
|
+
x: shownBox.x + shownBox.width / 2 - x - image.offsetWidth / 2,
|
|
502
|
+
y: shownBox.y + shownBox.height / 2 - y - image.offsetHeight / 2,
|
|
503
|
+
width: image.offsetWidth,
|
|
504
|
+
height: image.offsetHeight,
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
const home = () => holder ?? props.origin ?? props.video
|
|
509
|
+
const panElement = (target: PanTarget) => (target === "video" && props.video ? props.video : viewport)
|
|
510
|
+
|
|
511
|
+
const suppressVideoClick = () => {
|
|
512
|
+
const video = props.video
|
|
513
|
+
|
|
514
|
+
if (!video) return
|
|
515
|
+
|
|
516
|
+
const swallow = (event: MouseEvent) => {
|
|
517
|
+
event.preventDefault()
|
|
518
|
+
event.stopImmediatePropagation()
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// The click follows its pointerup in the same task; one that never comes must not swallow a later one.
|
|
522
|
+
video.addEventListener("click", swallow, { capture: true, once: true })
|
|
523
|
+
setTimeout(() => video.removeEventListener("click", swallow, { capture: true }))
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
onCleanup(() => {
|
|
527
|
+
dispatchFlight({ type: "disposed" })
|
|
528
|
+
dispatchZoom({ type: "disposed" })
|
|
529
|
+
})
|
|
530
|
+
|
|
531
|
+
const closing = () => (layer ? layer.closing() : !dialog.isOpen())
|
|
532
|
+
|
|
533
|
+
createEffect(
|
|
534
|
+
on(closing, (value) => {
|
|
535
|
+
if (value) dispatchFlight({ type: "close.started", origin: originFrame() })
|
|
536
|
+
}),
|
|
537
|
+
)
|
|
538
|
+
|
|
539
|
+
// From the center of the box zoom is measured in: the window's for an image, the frame's for a video.
|
|
540
|
+
const point = (event: MouseEvent) => {
|
|
541
|
+
const rect = (props.video ? image : viewport).getBoundingClientRect()
|
|
542
|
+
|
|
543
|
+
return { x: event.clientX - rect.left - rect.width / 2, y: event.clientY - rect.top - rect.height / 2 }
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
const measure = () => {
|
|
547
|
+
natural.width = image instanceof HTMLImageElement ? image.naturalWidth : image.width
|
|
548
|
+
natural.height = image instanceof HTMLImageElement ? image.naturalHeight : image.height
|
|
549
|
+
|
|
550
|
+
if (!natural.width || !image.offsetWidth) return
|
|
551
|
+
bounds.width = image.offsetWidth
|
|
552
|
+
bounds.height = image.offsetHeight
|
|
553
|
+
bounds.viewportWidth = props.video ? image.offsetWidth : viewport.clientWidth
|
|
554
|
+
bounds.viewportHeight = props.video ? image.offsetHeight : viewport.clientHeight
|
|
555
|
+
fitRatio = bounds.width / natural.width
|
|
556
|
+
bounds.maxScale = maxScale(fitRatio)
|
|
557
|
+
const next = clampView(view(), bounds)
|
|
558
|
+
follow(next.scale, next.x, next.y)
|
|
559
|
+
|
|
560
|
+
if (!props.video) return
|
|
561
|
+
|
|
562
|
+
// A video is ready as soon as the preview has laid out its box.
|
|
563
|
+
if (selectAwaitingReveal(untrack(flight))) return dispatchFlight({ type: "video.ready", origin: originFrame() })
|
|
564
|
+
|
|
565
|
+
if (selectVideoAtRest(untrack(flight))) place(fitted())
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
createResizeObserver(() => [viewport, image], measure)
|
|
569
|
+
|
|
570
|
+
createEffect(
|
|
571
|
+
on(
|
|
572
|
+
() => props.src,
|
|
573
|
+
() => {
|
|
574
|
+
dispatchFlight({ type: "src.changed" })
|
|
575
|
+
follow(FIT_VIEW.scale, FIT_VIEW.x, FIT_VIEW.y)
|
|
576
|
+
},
|
|
577
|
+
{ defer: true },
|
|
578
|
+
),
|
|
579
|
+
)
|
|
580
|
+
|
|
581
|
+
const interactive = () => selectFlightInteractive(untrack(flight))
|
|
582
|
+
|
|
583
|
+
const detail = (event: MouseEvent) => {
|
|
584
|
+
if (!interactive()) return
|
|
585
|
+
|
|
586
|
+
if (scaleSpring.target > 1) return ease(FIT_VIEW)
|
|
587
|
+
ease(zoomAt(goal(), detailScale(fitRatio), point(event), bounds))
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
const press = (event: PointerEvent, target: PanTarget | "content", onBackdrop: boolean) => {
|
|
591
|
+
if (!interactive()) return
|
|
592
|
+
dispatchZoom({
|
|
593
|
+
type: "pointer.down",
|
|
594
|
+
pointerId: event.pointerId,
|
|
595
|
+
button: event.button,
|
|
596
|
+
target,
|
|
597
|
+
onBackdrop,
|
|
598
|
+
zoomed: scaleSpring.value > 1,
|
|
599
|
+
})
|
|
600
|
+
|
|
601
|
+
if (!selectPanPointer(untrack(zoom), event.pointerId)) return
|
|
602
|
+
event.preventDefault()
|
|
603
|
+
cursor.x = event.clientX
|
|
604
|
+
cursor.y = event.clientY
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
// The hot path of a pan: no layout reads, and no Solid writes once the pan has moved.
|
|
608
|
+
const pan = (event: PointerEvent) => {
|
|
609
|
+
if (!selectPanPointer(untrack(zoom), event.pointerId)) return
|
|
610
|
+
|
|
611
|
+
// The button came up without a pointerup reaching the preview, so this is a hover, not a drag.
|
|
612
|
+
if ((event.buttons & 1) === 0) return dispatchZoom({ type: "pointer.cancel", pointerId: event.pointerId })
|
|
613
|
+
const dx = event.clientX - cursor.x
|
|
614
|
+
const dy = event.clientY - cursor.y
|
|
615
|
+
|
|
616
|
+
if (dx === 0 && dy === 0) return
|
|
617
|
+
cursor.x = event.clientX
|
|
618
|
+
cursor.y = event.clientY
|
|
619
|
+
movedEvent.pointerId = event.pointerId
|
|
620
|
+
dispatchZoom(movedEvent)
|
|
621
|
+
const scale = scaleSpring.value
|
|
622
|
+
follow(
|
|
623
|
+
scale,
|
|
624
|
+
clampAxis(xSpring.value + dx, bounds.width * scale, bounds.viewportWidth),
|
|
625
|
+
clampAxis(ySpring.value + dy, bounds.height * scale, bounds.viewportHeight),
|
|
626
|
+
)
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
const release = (event: PointerEvent) => dispatchZoom({ type: "pointer.up", pointerId: event.pointerId })
|
|
630
|
+
const cancel = (event: PointerEvent) => dispatchZoom({ type: "pointer.cancel", pointerId: event.pointerId })
|
|
631
|
+
|
|
632
|
+
if (props.video) {
|
|
633
|
+
const video = props.video
|
|
634
|
+
makeEventListener(video, "pointerdown", (event: PointerEvent) => {
|
|
635
|
+
if (event.clientY < video.getBoundingClientRect().bottom - CONTROLS) press(event, "video", false)
|
|
636
|
+
})
|
|
637
|
+
makeEventListener(video, "pointermove", pan)
|
|
638
|
+
makeEventListener(video, "pointerup", release)
|
|
639
|
+
makeEventListener(video, "pointercancel", cancel)
|
|
640
|
+
makeEventListener(video, "lostpointercapture", cancel)
|
|
641
|
+
makeEventListener(video, "dblclick", detail)
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// The preview owns zoom gestures while it is open: the page behind must neither scroll nor zoom the whole window.
|
|
645
|
+
makeEventListener(
|
|
646
|
+
window,
|
|
647
|
+
"wheel",
|
|
648
|
+
(event: WheelEvent) => {
|
|
649
|
+
if (!interactive()) return
|
|
650
|
+
const inside = event.target instanceof Node && (viewport.contains(event.target) || event.target === props.video)
|
|
651
|
+
|
|
652
|
+
const pinch = event.ctrlKey || event.metaKey
|
|
653
|
+
|
|
654
|
+
if (!inside && !pinch) return
|
|
655
|
+
event.preventDefault()
|
|
656
|
+
event.stopPropagation()
|
|
657
|
+
|
|
658
|
+
if (!inside) return
|
|
659
|
+
const current = view()
|
|
660
|
+
|
|
661
|
+
const next = pinch
|
|
662
|
+
? zoomAt(current, current.scale * wheelZoomFactor(wheelPixels(event, event.deltaY)), point(event), bounds)
|
|
663
|
+
: panBy(current, wheelPan(event), bounds)
|
|
664
|
+
|
|
665
|
+
follow(next.scale, next.x, next.y)
|
|
666
|
+
},
|
|
667
|
+
{ passive: false, capture: true },
|
|
668
|
+
)
|
|
669
|
+
|
|
670
|
+
// Captured ahead of the desktop shell, which zooms the whole window on the same shortcuts.
|
|
671
|
+
makeEventListener(
|
|
672
|
+
window,
|
|
673
|
+
"keydown",
|
|
674
|
+
(event: KeyboardEvent) => {
|
|
675
|
+
if (!interactive()) return
|
|
676
|
+
const bare = !event.metaKey && !event.ctrlKey && !event.altKey
|
|
677
|
+
|
|
678
|
+
if (bare && event.key === " " && props.video) {
|
|
679
|
+
event.preventDefault()
|
|
680
|
+
event.stopPropagation()
|
|
681
|
+
|
|
682
|
+
if (props.video.paused) return void props.video.play().catch(() => undefined)
|
|
683
|
+
|
|
684
|
+
return props.video.pause()
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
const action = bare ? (event.key === "0" ? "fit" : undefined) : event.altKey ? undefined : zoomShortcut(event.key)
|
|
688
|
+
|
|
689
|
+
if (!action) return
|
|
690
|
+
event.preventDefault()
|
|
691
|
+
event.stopPropagation()
|
|
692
|
+
|
|
693
|
+
if (action === "fit") return ease(FIT_VIEW)
|
|
694
|
+
step(action === "in" ? STEP : 1 / STEP)
|
|
695
|
+
},
|
|
696
|
+
{ capture: true },
|
|
697
|
+
)
|
|
698
|
+
|
|
699
|
+
return (
|
|
700
|
+
<div
|
|
701
|
+
ref={root}
|
|
702
|
+
data-component="image-preview"
|
|
703
|
+
data-stage={selectFlightStage(flight())}
|
|
704
|
+
// Zoomed in, the first Escape zooms back out; the dialog stack leaves it to the preview.
|
|
705
|
+
data-owns-escape={shown.ownsEscape ? "" : undefined}
|
|
706
|
+
style={{ "--image-preview-exit": `${EXIT_DURATION_MS}ms` }}
|
|
707
|
+
>
|
|
708
|
+
<div ref={scrim} data-slot="image-preview-scrim" />
|
|
709
|
+
<Kobalte.Content
|
|
710
|
+
ref={content}
|
|
711
|
+
data-slot="image-preview-content"
|
|
712
|
+
onOpenAutoFocus={(event) => {
|
|
713
|
+
// Open with focus on Close, as before, rather than on the zoom controls that precede it.
|
|
714
|
+
event.preventDefault()
|
|
715
|
+
close?.focus()
|
|
716
|
+
}}
|
|
717
|
+
onEscapeKeyDown={(event) => {
|
|
718
|
+
if (scaleSpring.target <= 1) return
|
|
719
|
+
event.preventDefault()
|
|
720
|
+
ease(FIT_VIEW)
|
|
721
|
+
}}
|
|
722
|
+
// A borrowed video sits over the preview rather than in it; using its controls keeps the preview open.
|
|
723
|
+
onInteractOutside={(event) => {
|
|
724
|
+
if (props.video && event.target === props.video) event.preventDefault()
|
|
725
|
+
}}
|
|
726
|
+
onPointerDown={(event: PointerEvent) => {
|
|
727
|
+
const target = event.target
|
|
728
|
+
const body = target instanceof Node && viewport.contains(target)
|
|
729
|
+
press(event, body ? "viewport" : "content", target === content || target === viewport)
|
|
730
|
+
}}
|
|
731
|
+
// The preview fills the window, so a click on the backdrop around the image lands here rather than outside.
|
|
732
|
+
onClick={(event: MouseEvent) =>
|
|
733
|
+
dispatchZoom({
|
|
734
|
+
type: "backdrop.click",
|
|
735
|
+
onBackdrop: event.target === content || event.target === viewport,
|
|
736
|
+
})
|
|
737
|
+
}
|
|
738
|
+
>
|
|
739
|
+
<div
|
|
740
|
+
ref={viewport}
|
|
741
|
+
data-slot="image-preview-body"
|
|
742
|
+
data-zoomed={shown.zoomed ? "" : undefined}
|
|
743
|
+
data-dragging={selectDragging(zoom()) ? "" : undefined}
|
|
744
|
+
onDblClick={detail}
|
|
745
|
+
onPointerMove={pan}
|
|
746
|
+
onPointerUp={release}
|
|
747
|
+
onPointerCancel={cancel}
|
|
748
|
+
onLostPointerCapture={cancel}
|
|
749
|
+
>
|
|
750
|
+
<Show
|
|
751
|
+
when={props.video}
|
|
752
|
+
fallback={
|
|
753
|
+
<img
|
|
754
|
+
ref={(element) => (image = element)}
|
|
755
|
+
src={props.src}
|
|
756
|
+
alt={props.alt ?? i18n.t("ui.imagePreview.alt")}
|
|
757
|
+
data-slot="image-preview-image"
|
|
758
|
+
draggable={false}
|
|
759
|
+
onLoad={() => {
|
|
760
|
+
measure()
|
|
761
|
+
dispatchFlight({ type: "image.loaded" })
|
|
762
|
+
}}
|
|
763
|
+
onError={() => dispatchFlight({ type: "image.failed" })}
|
|
764
|
+
/>
|
|
765
|
+
}
|
|
766
|
+
>
|
|
767
|
+
{(video) => (
|
|
768
|
+
<canvas
|
|
769
|
+
ref={(element) => (image = element)}
|
|
770
|
+
data-slot="image-preview-image"
|
|
771
|
+
width={video().videoWidth}
|
|
772
|
+
height={video().videoHeight}
|
|
773
|
+
/>
|
|
774
|
+
)}
|
|
775
|
+
</Show>
|
|
776
|
+
</div>
|
|
777
|
+
<div data-slot="image-preview-controls">
|
|
778
|
+
<IconButton
|
|
779
|
+
data-slot="image-preview-zoom-out"
|
|
780
|
+
icon={<Icon name="minus" />}
|
|
781
|
+
variant="ghost"
|
|
782
|
+
aria-label={i18n.t("ui.imagePreview.zoomOut")}
|
|
783
|
+
onClick={() => step(1 / STEP)}
|
|
784
|
+
/>
|
|
785
|
+
<Button
|
|
786
|
+
data-slot="image-preview-zoom-level"
|
|
787
|
+
variant="ghost-muted"
|
|
788
|
+
size="small"
|
|
789
|
+
aria-label={i18n.t("ui.imagePreview.zoomToFit")}
|
|
790
|
+
title={i18n.t("ui.imagePreview.zoomToFit")}
|
|
791
|
+
onClick={() => ease(FIT_VIEW)}
|
|
792
|
+
>
|
|
793
|
+
{percent().format(shown.level / 100)}
|
|
794
|
+
</Button>
|
|
795
|
+
<IconButton
|
|
796
|
+
data-slot="image-preview-zoom-in"
|
|
797
|
+
icon={<Icon name="plus" />}
|
|
798
|
+
variant="ghost"
|
|
799
|
+
aria-label={i18n.t("ui.imagePreview.zoomIn")}
|
|
800
|
+
onClick={() => step(STEP)}
|
|
801
|
+
/>
|
|
802
|
+
<div data-slot="image-preview-divider" />
|
|
803
|
+
<Kobalte.CloseButton
|
|
804
|
+
ref={close}
|
|
805
|
+
data-slot="image-preview-close"
|
|
806
|
+
as={IconButton}
|
|
807
|
+
icon={<Icon name="close" />}
|
|
808
|
+
variant="ghost"
|
|
809
|
+
aria-label={i18n.t("ui.common.close")}
|
|
810
|
+
/>
|
|
811
|
+
</div>
|
|
812
|
+
</Kobalte.Content>
|
|
813
|
+
<div data-slot="image-preview-surface" ref={surface} />
|
|
814
|
+
<Show when={!props.video}>
|
|
815
|
+
<img data-slot="image-preview-flight" src={props.src} alt="" aria-hidden="true" ref={standIn} />
|
|
816
|
+
</Show>
|
|
817
|
+
<div data-slot="image-preview-edge" ref={edge} />
|
|
818
|
+
</div>
|
|
819
|
+
)
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
// The part of `origin` the page under `preview` shows: inside its clipping ancestors and the window, and clear of
|
|
823
|
+
// anything drawn over its top or bottom, such as a sticky title bar. Nothing when none of it shows.
|
|
824
|
+
function visibleBox(origin: HTMLElement, preview: Element): Box | undefined {
|
|
825
|
+
const clipped = ancestors(origin).reduce(
|
|
826
|
+
(box: Box, element) => {
|
|
827
|
+
const style = getComputedStyle(element)
|
|
828
|
+
|
|
829
|
+
if (style.overflowX === "visible" && style.overflowY === "visible") return box
|
|
830
|
+
|
|
831
|
+
return intersect(box, element.getBoundingClientRect())
|
|
832
|
+
},
|
|
833
|
+
intersect(origin.getBoundingClientRect(), { x: 0, y: 0, width: window.innerWidth, height: window.innerHeight }),
|
|
834
|
+
)
|
|
835
|
+
|
|
836
|
+
const rows = Math.floor(clipped.height)
|
|
837
|
+
|
|
838
|
+
if (!clipped.width || rows < 1) return
|
|
839
|
+
const x = clipped.x + clipped.width / 2
|
|
840
|
+
|
|
841
|
+
// The origin is hidden while the preview flies, so the page shows it where the topmost element under the preview
|
|
842
|
+
// holds it.
|
|
843
|
+
const shows = (y: number) =>
|
|
844
|
+
document
|
|
845
|
+
.elementsFromPoint(x, y)
|
|
846
|
+
.find((element) => !preview.contains(element))
|
|
847
|
+
?.contains(origin) ?? false
|
|
848
|
+
|
|
849
|
+
const top = covered(rows, (row) => shows(clipped.y + row + 0.5))
|
|
850
|
+
|
|
851
|
+
if (top === rows) return
|
|
852
|
+
const bottom = covered(rows - top, (row) => shows(clipped.y + clipped.height - row - 0.5))
|
|
853
|
+
|
|
854
|
+
return { x: clipped.x, y: clipped.y + top, width: clipped.width, height: clipped.height - top - bottom }
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
function ancestors(element: HTMLElement) {
|
|
858
|
+
const list: HTMLElement[] = []
|
|
859
|
+
|
|
860
|
+
for (let parent = element.parentElement; parent; parent = parent.parentElement) list.push(parent)
|
|
861
|
+
|
|
862
|
+
return list
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
// How many of `rows`, counted in from an edge, are covered before the first that shows; a covering bar is one piece.
|
|
866
|
+
function covered(rows: number, shows: (row: number) => boolean) {
|
|
867
|
+
let low = 0
|
|
868
|
+
let high = rows
|
|
869
|
+
|
|
870
|
+
while (low < high) {
|
|
871
|
+
const middle = Math.floor((low + high) / 2)
|
|
872
|
+
|
|
873
|
+
if (shows(middle)) {
|
|
874
|
+
high = middle
|
|
875
|
+
continue
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
low = middle + 1
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
return low
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
function dispose(video: HTMLVideoElement) {
|
|
885
|
+
video.pause()
|
|
886
|
+
video.remove()
|
|
887
|
+
video.removeAttribute("src")
|
|
888
|
+
video.srcObject = null
|
|
889
|
+
video.load()
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
function layout(element: HTMLElement, frame: Box, radius: number) {
|
|
893
|
+
element.style.left = `${frame.x}px`
|
|
894
|
+
element.style.top = `${frame.y}px`
|
|
895
|
+
element.style.width = `${frame.width}px`
|
|
896
|
+
element.style.height = `${frame.height}px`
|
|
897
|
+
element.style.borderRadius = `${radius}px`
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
// A plain wheel pans; Shift turns a vertical wheel sideways.
|
|
901
|
+
function wheelPan(event: WheelEvent) {
|
|
902
|
+
const horizontal = event.shiftKey && event.deltaX === 0
|
|
903
|
+
|
|
904
|
+
return {
|
|
905
|
+
x: -wheelPixels(event, horizontal ? event.deltaY : event.deltaX),
|
|
906
|
+
y: horizontal ? 0 : -wheelPixels(event, event.deltaY),
|
|
907
|
+
}
|
|
908
|
+
}
|