dsh-design-studio 1.4.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +11 -10
- package/README.md +17 -16
- package/THIRD_PARTY_NOTICES.md +108 -0
- package/assets/art/README.md +102 -0
- package/assets/art/brand-mark.webp +0 -0
- package/assets/art/check-clean.webp +0 -0
- package/assets/art/coach-markup.webp +0 -0
- package/assets/art/drop-file.webp +0 -0
- package/assets/art/empty-components.webp +0 -0
- package/assets/art/empty-data.webp +0 -0
- package/assets/art/empty-error.webp +0 -0
- package/assets/art/empty-frames.webp +0 -0
- package/assets/art/empty-history.webp +0 -0
- package/assets/art/empty-market.webp +0 -0
- package/assets/art/empty-notes.webp +0 -0
- package/assets/art/empty-search.webp +0 -0
- package/assets/art/empty-tokens.webp +0 -0
- package/assets/art/empty-works.webp +0 -0
- package/assets/art/guide-icon.webp +0 -0
- package/assets/art/kind-app.webp +0 -0
- package/assets/art/kind-desktop.webp +0 -0
- package/assets/art/kind-diagram.webp +0 -0
- package/assets/art/kind-dshplugin.webp +0 -0
- package/assets/art/kind-email.webp +0 -0
- package/assets/art/kind-embedded.webp +0 -0
- package/assets/art/kind-framed.webp +0 -0
- package/assets/art/kind-miniprogram.webp +0 -0
- package/assets/art/kind-poster.webp +0 -0
- package/assets/art/kind-slides.webp +0 -0
- package/assets/art/kind-tablet.webp +0 -0
- package/assets/art/kind-web.webp +0 -0
- package/assets/art/placeholder-inspire-img.webp +0 -0
- package/assets/art/wait-creating.webp +0 -0
- package/assets/motion/ai-capsule.html +124 -0
- package/assets/motion/ai-glow-input.html +112 -0
- package/assets/motion/balance-odometer.html +112 -0
- package/assets/motion/bottom-sheet.html +149 -0
- package/assets/motion/brightness-pill.html +114 -0
- package/assets/motion/comet-ring.html +95 -0
- package/assets/motion/copy-morph.html +116 -0
- package/assets/motion/cube-grid.html +103 -0
- package/assets/motion/day-night.html +120 -0
- package/assets/motion/dial-knob.html +130 -0
- package/assets/motion/dock-magnify.html +118 -0
- package/assets/motion/download-ring.html +135 -0
- package/assets/motion/expand-card.html +137 -0
- package/assets/motion/flip-card.html +100 -0
- package/assets/motion/hold-pay.html +137 -0
- package/assets/motion/holo-card.html +130 -0
- package/assets/motion/keycap.html +92 -0
- package/assets/motion/like-jelly.html +88 -0
- package/assets/motion/liquid-progress.html +113 -0
- package/assets/motion/liquid-segment.html +127 -0
- package/assets/motion/live-capsule.html +144 -0
- package/assets/motion/marker-highlight.html +94 -0
- package/assets/motion/marquee-logos.html +110 -0
- package/assets/motion/otp-code.html +111 -0
- package/assets/motion/password-eye.html +136 -0
- package/assets/motion/ruler-slider.html +140 -0
- package/assets/motion/search-expand.html +81 -0
- package/assets/motion/send-fly.html +121 -0
- package/assets/motion/skeleton-shine.html +124 -0
- package/assets/motion/star-rate.html +98 -0
- package/assets/motion/success-check.html +114 -0
- package/assets/motion/suggest-chips.html +134 -0
- package/assets/motion/swipe-row.html +126 -0
- package/assets/motion/tabbar-bounce.html +92 -0
- package/assets/motion/tactile-controls.html +89 -0
- package/assets/motion/text-scramble.html +173 -0
- package/assets/motion/toast-stack.html +115 -0
- package/assets/motion/token-stream.html +106 -0
- package/assets/motion/voice-orb.html +144 -0
- package/assets/showcase/alley-noodles-1.webp +0 -0
- package/assets/showcase/alley-noodles-2.webp +0 -0
- package/assets/showcase/alley-noodles-3.webp +0 -0
- package/assets/showcase/autumn-sale-1.webp +0 -0
- package/assets/showcase/bold-folio-1.webp +0 -0
- package/assets/showcase/bold-folio-2.webp +0 -0
- package/assets/showcase/book-club-1.webp +0 -0
- package/assets/showcase/book-club-2.webp +0 -0
- package/assets/showcase/book-club-3.webp +0 -0
- package/assets/showcase/flower-order-1.webp +0 -0
- package/assets/showcase/little-painter-1.webp +0 -0
- package/assets/showcase/little-painter-2.webp +0 -0
- package/assets/showcase/moon-fair-1.webp +0 -0
- package/assets/showcase/nail-booking-1.webp +0 -0
- package/assets/showcase/nail-booking-2.webp +0 -0
- package/assets/showcase/nail-booking-3.webp +0 -0
- package/assets/showcase/night-run-1.webp +0 -0
- package/assets/showcase/paw-diary-1.webp +0 -0
- package/assets/showcase/paw-diary-2.webp +0 -0
- package/assets/showcase/paw-diary-3.webp +0 -0
- package/assets/showcase/pixel-planet-1.webp +0 -0
- package/assets/showcase/pixel-planet-2.webp +0 -0
- package/assets/showcase/pixel-planet-3.webp +0 -0
- package/assets/showcase/pocket-ledger-1.webp +0 -0
- package/assets/showcase/pocket-ledger-2.webp +0 -0
- package/assets/showcase/shiftloom-1.webp +0 -0
- package/assets/showcase/shiftloom-2.webp +0 -0
- package/assets/showcase/slow-breath-1.webp +0 -0
- package/assets/showcase/slow-breath-2.webp +0 -0
- package/assets/showcase/slow-breath-3.webp +0 -0
- package/assets/showcase/slow-trip-1.webp +0 -0
- package/assets/showcase/slow-trip-2.webp +0 -0
- package/assets/showcase/slow-trip-3.webp +0 -0
- package/assets/showcase/slow-weekly-1.webp +0 -0
- package/assets/showcase/stay-confirm-1.webp +0 -0
- package/assets/showcase/stove-recipes-1.webp +0 -0
- package/assets/showcase/stove-recipes-2.webp +0 -0
- package/assets/showcase/strobewatch-1.webp +0 -0
- package/assets/showcase/strobewatch-2.webp +0 -0
- package/assets/showcase/tapeworks-1.webp +0 -0
- package/assets/showcase/tapeworks-2.webp +0 -0
- package/assets/showcase/tea-brand-pitch-1.webp +0 -0
- package/assets/showcase/tea-brand-pitch-2.webp +0 -0
- package/assets/showcase/tea-brand-pitch-3.webp +0 -0
- package/assets/showcase/time-bookshop-1.webp +0 -0
- package/assets/showcase/time-bookshop-2.webp +0 -0
- package/assets/showcase/water-journey-1.webp +0 -0
- package/assets/showcase/water-journey-2.webp +0 -0
- package/assets/showcase/water-journey-3.webp +0 -0
- package/assets/showcase/weekend-go-1.webp +0 -0
- package/assets/showcase/weekend-go-2.webp +0 -0
- package/assets/showcase/weekend-go-3.webp +0 -0
- package/assets/showcase/winter-soup-1.webp +0 -0
- package/assets/showcase/year-review-1.webp +0 -0
- package/assets/showcase/year-review-2.webp +0 -0
- package/assets/showcase/year-review-3.webp +0 -0
- package/lib/annotations.js +1 -1
- package/lib/browser.js +3 -1
- package/lib/bundle.js +8 -3
- package/lib/canvthumb.js +9 -6
- package/lib/client.js +7623 -2788
- package/lib/components.js +4 -2
- package/lib/core.js +763 -133
- package/lib/design-page-settings.js +48 -0
- package/lib/design-scope.js +36 -0
- package/lib/design-transactions.js +259 -0
- package/lib/drop-folder.js +25 -0
- package/lib/edits.js +125 -8
- package/lib/embedded/lvgl_shot.c +133 -0
- package/lib/embedded/qml_shot.py +66 -0
- package/lib/embedded-shot.js +400 -0
- package/lib/embedded-trust.js +76 -0
- package/lib/fonts.js +30 -21
- package/lib/frames.js +23 -23
- package/lib/gallery/css.js +9 -2
- package/lib/gallery/market-routes.js +23 -7
- package/lib/gallery/pack.js +25 -8
- package/lib/gallery/policy.js +6 -4
- package/lib/gallery/routes.js +255 -83
- package/lib/gallery/submit.js +285 -57
- package/lib/gallery/use.js +13 -4
- package/lib/handoff-embedded.js +1182 -0
- package/lib/handoff.js +212 -71
- package/lib/history.js +393 -43
- package/lib/htmlpack.js +35 -14
- package/lib/impl.js +3 -0
- package/lib/index.js +662 -137
- package/lib/inspire.js +73 -26
- package/lib/kinds.js +11 -2
- package/lib/look.js +45 -25
- package/lib/mock.js +41 -4
- package/lib/motion.js +90 -0
- package/lib/page-settings.js +103 -0
- package/lib/picker.js +348 -70
- package/lib/rules.js +85 -0
- package/lib/serve.js +154 -15
- package/lib/showcase.json +22 -0
- package/lib/styles.js +16 -7
- package/lib/system.js +19 -8
- package/lib/tool.js +2 -1
- package/lib/tweaks.js +146 -9
- package/lib/works.js +151 -19
- package/locale/annotations/en.json +2 -2
- package/locale/annotations/zh.json +2 -2
- package/locale/auto/en.json +1 -1
- package/locale/auto/zh.json +1 -1
- package/locale/en.json +1 -1
- package/locale/offline/en.json +1 -1
- package/locale/offline/zh.json +2 -2
- package/locale/tool/zh.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +3 -2
- package/skills/ui-design/SKILL.md +59 -47
- package/skills/ui-design/frames/dsh/frame.json +1 -1
- package/skills/ui-design/references/app.md +29 -2
- package/skills/ui-design/references/components.md +1 -1
- package/skills/ui-design/references/desktop.md +1 -1
- package/skills/ui-design/references/dshplugin.md +12 -12
- package/skills/ui-design/references/embedded.md +40 -0
- package/skills/ui-design/references/frames.md +20 -20
- package/skills/ui-design/references/miniprogram.md +2 -2
- package/skills/ui-design/references/mock.md +16 -0
- package/skills/ui-design/references/poster.md +2 -1
- package/skills/ui-design/references/tweaks.md +17 -0
- package/skills/ui-design/tokens.css +19 -5
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<title>验证码输入</title>
|
|
7
|
+
<script type="application/json" id="meta">{"zh":"验证码输入","en":"OTP Input","cat":"input","desc":"光标在格间跳,数字从下面弹上来,输满四格依次一跳变绿","desc_en":"The caret hops between cells, digits rise in, and the filled cells turn green in turn","needs":"js","play":"press","hint":"输入数字","hint_en":"Type digits","source":null,"prompt":"4 位验证码:四个 52×62 圆角 15px 的格子,间距 10px;一个透明的真输入框盖在上面(maxlength 4、inputmode numeric、one-time-code),粘贴和退格自然可用。聚焦时一圈主色描边加淡光晕带着闪烁光标,用弹簧曲线滑到下一个空格;每输一位,数字从格子下方弹上来(0.6s 弹簧),删除时向上淡出。输满后四格间隔 70ms 依次跳一下,描边和底色换成功色。颜色读 --color-surface / --color-text / --color-line / --color-primary / --color-success;减少动效时不跳不弹,直接显示结果。","prompt_en":"OTP: four 52×62 cells (15px radius, 10px gap) under a transparent input (maxlength 4, inputmode numeric, one-time-code). A --color-primary focus ring with blinking caret springs to the next empty cell; digits rise in (0.6s spring), deletions fade up. Full: cells hop 70ms apart, go --color-success. Reads --color-surface / --color-text / --color-line / --color-primary / --color-success; reduced motion: instant.","id":"otp-code"}</script>
|
|
8
|
+
<style data-stage>
|
|
9
|
+
:root{color-scheme:light;--color-bg:#efede7;--color-surface:#fff;--color-text:#141413;--color-muted:#76756f;--color-line:rgba(20,20,19,.1);--color-primary:#0a84ff;--color-danger:#ff375f;--color-warning:#ffb340;--font-sans:-apple-system,BlinkMacSystemFont,"SF Pro Text","PingFang SC","Microsoft YaHei",system-ui,sans-serif}
|
|
10
|
+
:root[data-theme=dark]{color-scheme:dark;--color-bg:#17171a;--color-surface:#2c2c30;--color-text:#f5f5f4;--color-muted:#8e8d88;--color-line:rgba(255,255,255,.1)}
|
|
11
|
+
html,body{height:100%;margin:0}
|
|
12
|
+
body{display:grid;place-items:center;background:var(--color-bg);font-family:var(--font-sans);-webkit-font-smoothing:antialiased;overflow:hidden;user-select:none;-webkit-user-select:none}
|
|
13
|
+
.paused *{animation-play-state:paused!important}
|
|
14
|
+
.stage-fit{position:absolute;left:50%;top:50%;width:max-content;display:grid;place-items:center;transform:translate(-50%,-50%) scale(var(--fit,1))}
|
|
15
|
+
</style>
|
|
16
|
+
<style data-comp>
|
|
17
|
+
/* 验证码输入 · 一个透明真输入框盖在四格上,格子和光标框由脚本生成。读 --color-surface / --color-text / --color-line / --color-primary / --color-success */
|
|
18
|
+
.c-otp-code{--oc-w:52px;--oc-h:62px;--oc-gap:10px;--oc-acc:var(--color-primary,#0a84ff);--oc-ok:var(--color-success,#30c25a);--oc-spring:linear(0,.07,.245,.475,.716,.931,1.1,1.212,1.267,1.272,1.239,1.184,1.118,1.054,.999,.958,.934,.925,.928,.94,.956,.975,.992,1.005,1.015,1.02,1.021,1.019,1.015,1.01,1.005,1.001,.997,.995,.994,.994,.995,.996,.998,.999,1);position:relative;display:flex;gap:var(--oc-gap);font-family:var(--font-sans,system-ui);-webkit-tap-highlight-color:transparent}
|
|
19
|
+
.c-otp-code .oc-in{position:absolute;left:-6px;top:-6px;width:calc(100% + 12px);height:calc(100% + 12px);margin:0;padding:0;border:0;background:none;opacity:0;color:transparent;caret-color:transparent;font-size:16px;cursor:text;z-index:3;outline:none}
|
|
20
|
+
.c-otp-code .oc-cell{position:relative;width:var(--oc-w);height:var(--oc-h);border-radius:15px;display:grid;place-items:center;overflow:hidden;background:var(--color-surface,#fff);box-shadow:inset 0 1px 0 color-mix(in srgb,var(--color-surface,#fff) 72%,#fff),0 0 0 .5px var(--color-line,rgba(0,0,0,.1)),0 1px 2px rgba(0,0,0,.06),0 10px 22px -10px rgba(0,0,0,.28);transition:box-shadow .35s calc(var(--i)*70ms),background-color .35s calc(var(--i)*70ms)}
|
|
21
|
+
.c-otp-code .oc-cell b{grid-area:1/1;font:600 28px/1 var(--font-sans,system-ui);font-variant-numeric:tabular-nums;letter-spacing:-.02em;color:var(--color-text,#141413);animation:oc-up .62s var(--oc-spring) both}
|
|
22
|
+
.c-otp-code .oc-cell b.out{animation:oc-out .2s cubic-bezier(.4,0,1,1) forwards}
|
|
23
|
+
.c-otp-code .oc-ring{position:absolute;left:0;top:0;width:var(--oc-w);height:var(--oc-h);border-radius:15px;box-shadow:0 0 0 1.5px var(--oc-acc),0 0 0 5px color-mix(in srgb,var(--oc-acc) 16%,transparent);transform:translateX(calc(var(--oc-i,0)*(var(--oc-w) + var(--oc-gap))));opacity:0;pointer-events:none;z-index:2;transition:transform .55s var(--oc-spring),scale .6s var(--oc-spring),opacity .25s}
|
|
24
|
+
.c-otp-code .oc-ring::after{content:"";position:absolute;left:50%;top:50%;width:2px;height:26px;margin:-13px 0 0 -1px;border-radius:2px;background:var(--oc-acc);animation:oc-blink 1.05s steps(1) infinite}
|
|
25
|
+
.c-otp-code.is-focus .oc-ring{opacity:1}
|
|
26
|
+
.c-otp-code.is-press .oc-ring{scale:.92;transition:transform .55s var(--oc-spring),scale .12s,opacity .25s}
|
|
27
|
+
.c-otp-code.is-ok .oc-ring{opacity:0}
|
|
28
|
+
.c-otp-code.is-ok .oc-cell{background:color-mix(in srgb,var(--oc-ok) 9%,var(--color-surface,#fff));box-shadow:inset 0 1px 0 color-mix(in srgb,var(--color-surface,#fff) 72%,#fff),0 0 0 1.5px var(--oc-ok),0 1px 2px rgba(0,0,0,.06),0 12px 24px -12px color-mix(in srgb,var(--oc-ok) 60%,transparent);animation:oc-hop .5s cubic-bezier(.3,1.6,.5,1) calc(var(--i)*70ms) both}
|
|
29
|
+
@keyframes oc-up{from{transform:translateY(40px);opacity:0}}
|
|
30
|
+
@keyframes oc-out{to{transform:translateY(-16px) scale(.8);opacity:0}}
|
|
31
|
+
@keyframes oc-blink{50%{opacity:0}}
|
|
32
|
+
@keyframes oc-hop{0%,100%{transform:none}38%{transform:translateY(-10px)}}
|
|
33
|
+
@media (prefers-reduced-motion:reduce){.c-otp-code *,.c-otp-code .oc-ring::after{animation:none!important;transition-duration:.01ms!important}}
|
|
34
|
+
</style>
|
|
35
|
+
</head>
|
|
36
|
+
<body>
|
|
37
|
+
<div class="stage-fit">
|
|
38
|
+
<div class="c-otp-code" data-comp="otp-code" data-len="4"><input class="oc-in" type="text" inputmode="numeric" autocomplete="one-time-code" maxlength="4" aria-label="验证码"></div>
|
|
39
|
+
</div>
|
|
40
|
+
<script data-comp>
|
|
41
|
+
/* 验证码输入逻辑:输入框的值 → 四格数字(新数字弹上来、删掉的淡出)、光标框位置、输满变绿。一页可放多个。 */
|
|
42
|
+
(() => {
|
|
43
|
+
const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
44
|
+
document.querySelectorAll('.c-otp-code').forEach((el) => {
|
|
45
|
+
const n = +el.dataset.len || 4, inp = el.querySelector('.oc-in')
|
|
46
|
+
el.insertAdjacentHTML('beforeend', Array.from({ length: n }, (_, i) => `<span class="oc-cell" style="--i:${i}"></span>`).join('') + '<span class="oc-ring"></span>')
|
|
47
|
+
const cells = [...el.querySelectorAll('.oc-cell')]
|
|
48
|
+
let shown = ''
|
|
49
|
+
const set = (raw) => {
|
|
50
|
+
const v = String(raw).replace(/\D/g, '').slice(0, n)
|
|
51
|
+
for (let i = 0; i < n; i++) {
|
|
52
|
+
if (v[i] === shown[i]) continue
|
|
53
|
+
const old = cells[i].querySelector('b:not(.out)')
|
|
54
|
+
if (old) { if (reduced) old.remove(); else { old.classList.add('out'); old.addEventListener('animationend', () => old.remove(), { once: true }) } }
|
|
55
|
+
if (v[i]) { const b = document.createElement('b'); b.textContent = v[i]; cells[i].append(b) }
|
|
56
|
+
}
|
|
57
|
+
shown = v; el.style.setProperty('--oc-i', Math.min(v.length, n - 1)); el.classList.toggle('is-ok', v.length === n)
|
|
58
|
+
if (inp.value !== v) inp.value = v
|
|
59
|
+
}
|
|
60
|
+
const end = () => { const k = inp.value.length; inp.setSelectionRange(k, k) } // 光标永远在最后,格子才对得上
|
|
61
|
+
inp.addEventListener('input', () => { el.ocDemo = false; set(inp.value); end() })
|
|
62
|
+
inp.addEventListener('focus', () => { el.classList.add('is-focus'); end() })
|
|
63
|
+
inp.addEventListener('blur', () => el.classList.remove('is-focus'))
|
|
64
|
+
inp.addEventListener('pointerdown', () => el.classList.add('is-press'))
|
|
65
|
+
const up = () => { el.classList.remove('is-press'); requestAnimationFrame(end) }
|
|
66
|
+
addEventListener('pointerup', up); addEventListener('pointercancel', up)
|
|
67
|
+
el.ocSet = (v) => { el.ocDemo = true; set(v) } // 给演示舞台用
|
|
68
|
+
})
|
|
69
|
+
})()
|
|
70
|
+
</script>
|
|
71
|
+
<script data-stage>
|
|
72
|
+
/* 演示舞台:每个组件都一样,只改 DEMO 那一段。组件按 340×212 设计,卡片小了整体等比缩小。 */
|
|
73
|
+
(() => {
|
|
74
|
+
const q = new URLSearchParams(location.search); const root = document.documentElement
|
|
75
|
+
root.dataset.theme = (q.get('theme') || (matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')) === 'dark' ? 'dark' : 'light'
|
|
76
|
+
const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
77
|
+
const el = document.querySelector('.stage-fit > [data-comp]')
|
|
78
|
+
const fit = () => root.style.setProperty('--fit', Math.min(1, innerWidth / 340, innerHeight / 212).toFixed(3))
|
|
79
|
+
fit(); addEventListener('resize', fit)
|
|
80
|
+
let playing = !q.has('still'); let hovering = false; let timers = []
|
|
81
|
+
const later = (fn, ms) => timers.push(setTimeout(() => { if (playing && !hovering) fn() }, ms)) // 演示用的定时器:用户一来就全部作废
|
|
82
|
+
const stop = () => { timers.forEach(clearTimeout); timers = []; DEMO.stop() }
|
|
83
|
+
const go = (ms) => { stop(); if (playing && !hovering && !reduced) later(() => DEMO.loop(later), ms) }
|
|
84
|
+
// ===== 只改这一段 =====
|
|
85
|
+
const inp = el.querySelector('.oc-in'); const CODE = '4821'
|
|
86
|
+
const real = () => document.hasFocus() && document.activeElement === inp // 用户点进来了:不抢
|
|
87
|
+
const DEMO = {
|
|
88
|
+
settle () { el.ocSet('482'); el.classList.add('is-focus') }, // 落定状态:输了三位,光标在第四格
|
|
89
|
+
loop (later) {
|
|
90
|
+
if (real()) return later(() => DEMO.loop(later), 2000)
|
|
91
|
+
el.ocSet(''); el.classList.add('is-focus')
|
|
92
|
+
;[300, 620, 920, 1300].forEach((t, i) => later(() => el.ocSet(CODE.slice(0, i + 1)), t)) // 自己打字
|
|
93
|
+
;[3300, 3420, 3540, 3660].forEach((t, i) => later(() => el.ocSet(CODE.slice(0, 3 - i)), t)) // 一位位退掉
|
|
94
|
+
later(() => { el.classList.remove('is-focus'); later(() => DEMO.loop(later), 1000) }, 3900)
|
|
95
|
+
},
|
|
96
|
+
stop () { if (el.ocDemo) { el.ocSet(''); if (document.activeElement !== inp) el.classList.remove('is-focus') } },
|
|
97
|
+
}
|
|
98
|
+
// =====================
|
|
99
|
+
document.body.addEventListener('pointerenter', () => { hovering = true; stop() })
|
|
100
|
+
document.body.addEventListener('pointerleave', () => { hovering = false; go(1400) })
|
|
101
|
+
addEventListener('message', (e) => {
|
|
102
|
+
const d = e.data; if (!d || typeof d !== 'object') return
|
|
103
|
+
if (d.theme === 'light' || d.theme === 'dark') root.dataset.theme = d.theme
|
|
104
|
+
if (typeof d.ddpPlay === 'boolean') { playing = d.ddpPlay; root.classList.toggle('paused', !playing); if (playing) go(400); else stop() }
|
|
105
|
+
})
|
|
106
|
+
try { parent.postMessage({ ddpMotionReady: 1 }, '*') } catch (e) { /* 单独打开时没有外层 */ }
|
|
107
|
+
if (reduced || q.has('still')) DEMO.settle(); else go(600)
|
|
108
|
+
})()
|
|
109
|
+
</script>
|
|
110
|
+
</body>
|
|
111
|
+
</html>
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<title>眨眼密码</title>
|
|
7
|
+
<script type="application/json" id="meta">{"zh":"眨眼密码","en":"Password Toggle","cat":"input","desc":"眼睛一眨,圆点和明文依次互换","desc_en":"The eye blinks and the dots swap with plain text one by one","needs":"js","play":"press","hint":"点眼睛","hint_en":"Tap the eye","source":null,"prompt":"密码框 268×54 圆角 16px,左锁右眼。圆点层和明文层叠着;点眼睛,眼皮用弹簧从一条线张开,字符从左到右错开 18ms:圆点缩没、字母浮上来,闭眼反过来。光标自绘,跟着当前层宽度滑。下面 4 段强度条用弹簧伸长,颜色依次读 --color-danger / warning / primary / success。减少动效时直接切换。","prompt_en":"Password field 268×54, 16px radius, lock left, eye right. Dot and plain-text layers overlap; tapping the eye springs the eyelid open from a line while characters stagger 18ms left to right: dots shrink, letters float up; closing reverses. A custom caret slides to the active layer width. Four strength bars spring out in --color-danger / --color-warning / --color-primary / --color-success. Reduced motion: instant.","id":"password-eye"}</script>
|
|
8
|
+
<style data-stage>
|
|
9
|
+
:root{color-scheme:light;--color-bg:#efede7;--color-surface:#fff;--color-text:#141413;--color-muted:#76756f;--color-line:rgba(20,20,19,.1);--color-primary:#0a84ff;--color-danger:#ff375f;--color-warning:#ffb340;--font-sans:-apple-system,BlinkMacSystemFont,"SF Pro Text","PingFang SC","Microsoft YaHei",system-ui,sans-serif}
|
|
10
|
+
:root[data-theme=dark]{color-scheme:dark;--color-bg:#17171a;--color-surface:#2c2c30;--color-text:#f5f5f4;--color-muted:#8e8d88;--color-line:rgba(255,255,255,.1)}
|
|
11
|
+
html,body{height:100%;margin:0}
|
|
12
|
+
body{display:grid;place-items:center;background:var(--color-bg);font-family:var(--font-sans);-webkit-font-smoothing:antialiased;overflow:hidden;user-select:none;-webkit-user-select:none}
|
|
13
|
+
.paused *{animation-play-state:paused!important}
|
|
14
|
+
.stage-fit{position:absolute;left:50%;top:50%;width:max-content;display:grid;place-items:center;transform:translate(-50%,-50%) scale(var(--fit,1))}
|
|
15
|
+
</style>
|
|
16
|
+
<style data-comp>
|
|
17
|
+
/* 眨眼密码 · 真密码框透明盖在字符层上。读 --color-surface/text/muted/line/primary/danger/warning/success */
|
|
18
|
+
.c-password-eye{--pe-x:44px;--pe-acc:var(--color-primary,#0a84ff);--pe-c:var(--color-muted,#76756f);--pe-sp:linear(0,.25,.62,.95,1.16,1.23,1.2,1.12,1.04,.98,.95,.95,.97,.99,1.01,1.01,1);--pe-sh:inset 0 1px 0 color-mix(in srgb,var(--color-surface,#fff) 72%,#fff),0 1px 2px rgba(0,0,0,.06),0 12px 26px -12px rgba(0,0,0,.3);display:grid;gap:14px;width:268px;font-family:var(--font-sans,system-ui)}
|
|
19
|
+
.c-password-eye .pe-field{position:relative;height:54px;border-radius:16px;background:var(--color-surface,#fff);box-shadow:var(--pe-sh),0 0 0 .5px var(--color-line,rgba(0,0,0,.1));transition:box-shadow .3s}
|
|
20
|
+
.c-password-eye.is-focus .pe-field{box-shadow:var(--pe-sh),0 0 0 1.5px var(--pe-acc),0 0 0 5px color-mix(in srgb,var(--pe-acc) 15%,transparent)}
|
|
21
|
+
.c-password-eye .pe-lock{position:absolute;left:16px;top:18px;width:18px;height:18px;color:var(--color-muted,#76756f)}
|
|
22
|
+
.c-password-eye .pe-in{position:absolute;left:0;top:0;width:calc(100% - 52px);height:100%;margin:0;padding:0 0 0 var(--pe-x);border:0;box-sizing:border-box;background:none;opacity:0;color:transparent;font-size:16px;cursor:text;outline:none;z-index:2}
|
|
23
|
+
.c-password-eye .pe-txt{position:absolute;left:var(--pe-x);top:15px;height:24px;display:flex;align-items:center;pointer-events:none;white-space:pre}
|
|
24
|
+
.c-password-eye .pe-txt>*{transition:transform .5s var(--pe-sp) calc(var(--k)*18ms),opacity .25s calc(var(--k)*18ms);animation:pe-in .4s var(--pe-sp) both}
|
|
25
|
+
.c-password-eye .pe-txt i{width:7px;height:7px;margin:0 2px;border-radius:50%;background:var(--color-text,#141413)}
|
|
26
|
+
.c-password-eye .pe-txt b{font:500 15px/1 var(--font-sans,system-ui);color:var(--color-text,#141413);opacity:0;transform:translateY(9px) scale(.7)}
|
|
27
|
+
.c-password-eye.is-show .pe-txt i{opacity:0;transform:scale(0)}
|
|
28
|
+
.c-password-eye.is-show .pe-txt b,.c-password-eye.is-show .pe-open{opacity:1;transform:none}
|
|
29
|
+
.c-password-eye .pe-caret{position:absolute;left:calc(var(--pe-x) + 1px);top:16px;width:2px;height:22px;border-radius:2px;background:var(--pe-acc);opacity:0;transform:translateX(var(--pe-cx,0));transition:transform .3s cubic-bezier(.2,.8,.2,1)}
|
|
30
|
+
.c-password-eye.is-focus .pe-caret{opacity:1;animation:pe-blink 1.05s steps(1) infinite}
|
|
31
|
+
.c-password-eye .pe-eye{position:absolute;right:6px;top:6px;width:42px;height:42px;padding:0;border:0;border-radius:12px;display:grid;place-items:center;background:none;color:var(--color-muted,#76756f);cursor:pointer;z-index:3;transition:transform .6s var(--pe-sp),background-color .2s,color .2s}
|
|
32
|
+
.c-password-eye .pe-eye:hover{background:color-mix(in srgb,var(--color-text,#141413) 6%,transparent)}
|
|
33
|
+
.c-password-eye .pe-eye:active,.c-password-eye.is-press .pe-eye{transform:scale(.84);transition:transform .1s}
|
|
34
|
+
.c-password-eye.is-show .pe-eye{color:var(--color-text,#141413)}
|
|
35
|
+
.c-password-eye svg{overflow:visible;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}
|
|
36
|
+
.c-password-eye .pe-eye svg{width:24px}
|
|
37
|
+
.c-password-eye g{transform-box:view-box;transform-origin:12px 12px}
|
|
38
|
+
.c-password-eye .pe-open{opacity:0;transform:scaleY(.08);transition:transform .55s var(--pe-sp),opacity .15s}
|
|
39
|
+
.c-password-eye .pe-open circle{fill:currentColor;stroke:none}
|
|
40
|
+
.c-password-eye .pe-shut{transition:opacity .2s .05s,transform .4s var(--pe-sp)}
|
|
41
|
+
.c-password-eye.is-show .pe-shut{opacity:0;transform:translateY(-3px) scaleY(.6);transition:opacity .1s,transform .3s}
|
|
42
|
+
.c-password-eye .pe-bars{display:grid;grid-template-columns:repeat(4,1fr);gap:6px;padding:0 6px}
|
|
43
|
+
.c-password-eye .pe-bars i{height:4px;border-radius:2px;background:color-mix(in srgb,var(--color-text,#141413) 9%,transparent);overflow:hidden}
|
|
44
|
+
.c-password-eye .pe-bars i::after{content:"";display:block;height:100%;background:var(--pe-c);transform:scaleX(0);transform-origin:left;transition:transform .6s var(--pe-sp) var(--d,0s),background-color .35s}
|
|
45
|
+
.c-password-eye .pe-bars i.on::after{transform:none}
|
|
46
|
+
@keyframes pe-in{from{transform:translateY(10px) scale(.4);opacity:0}}
|
|
47
|
+
@keyframes pe-blink{50%{opacity:0}}
|
|
48
|
+
@media (prefers-reduced-motion:reduce){.c-password-eye *,.c-password-eye .pe-bars i::after{animation:none!important;transition:none!important}}
|
|
49
|
+
</style>
|
|
50
|
+
</head>
|
|
51
|
+
<body>
|
|
52
|
+
<div class="stage-fit">
|
|
53
|
+
<div class="c-password-eye" data-comp="password-eye">
|
|
54
|
+
<div class="pe-field">
|
|
55
|
+
<svg class="pe-lock" viewBox="0 0 24 24" aria-hidden="true"><rect x="4.5" y="10.5" width="15" height="10" rx="3"/><path d="M8 10.5V8a4 4 0 0 1 8 0v2.5"/></svg>
|
|
56
|
+
<input class="pe-in" type="password" autocomplete="new-password" maxlength="13" aria-label="密码">
|
|
57
|
+
<span class="pe-txt" aria-hidden="true"></span><span class="pe-txt" aria-hidden="true"></span><span class="pe-caret"></span>
|
|
58
|
+
<button class="pe-eye" type="button" aria-label="显示密码" aria-pressed="false"><svg viewBox="0 0 24 24" aria-hidden="true"><g class="pe-open"><path d="M2.5 12c2.2-4 5.6-6.2 9.5-6.2s7.3 2.2 9.5 6.2c-2.2 4-5.6 6.2-9.5 6.2S4.7 16 2.5 12z"/><circle cx="12" cy="12" r="3.1"/></g><g class="pe-shut"><path d="M3 10.5c2.4 3.4 5.5 5 9 5s6.6-1.6 9-5M6.3 13.9l-1.5 2.1M12 15.5v2.6M17.7 13.9l1.5 2.1"/></g></svg></button>
|
|
59
|
+
</div>
|
|
60
|
+
<div class="pe-bars"><i></i><i style="--d:50ms"></i><i style="--d:.1s"></i><i style="--d:.15s"></i></div>
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
<script data-comp>
|
|
64
|
+
/* 输入 → 字符格、光标、强度;眼睛切换明文。一页可放多个 */
|
|
65
|
+
(() => {
|
|
66
|
+
const COL = ['', 'var(--color-danger,#ff375f)', 'var(--color-warning,#ffb340)', 'var(--color-primary,#0a84ff)', 'var(--color-success,#30c25a)']
|
|
67
|
+
const score = (v) => v ? Math.min(4, 1 + (v.length >= 8) + (/\d/.test(v) && /[a-z]/i.test(v)) + (/[^a-z0-9]/i.test(v) || (/[a-z]/.test(v) && /[A-Z]/.test(v)))) : 0
|
|
68
|
+
document.querySelectorAll('.c-password-eye').forEach((el) => {
|
|
69
|
+
const inp = el.querySelector('.pe-in'), [dots, plain] = el.querySelectorAll('.pe-txt'), eye = el.querySelector('.pe-eye'), bars = [...el.querySelectorAll('.pe-bars i')]
|
|
70
|
+
let shown = ''
|
|
71
|
+
const set = (raw) => {
|
|
72
|
+
const v = String(raw).slice(0, inp.maxLength > 0 ? inp.maxLength : 13)
|
|
73
|
+
let k = 0; while (k < shown.length && k < v.length && v[k] === shown[k]) k++
|
|
74
|
+
while (dots.children.length > k) { dots.lastChild.remove(); plain.lastChild.remove() }
|
|
75
|
+
for (let i = k; i < v.length; i++) { const d = document.createElement('i'), b = document.createElement('b'); d.style.setProperty('--k', i); b.style.setProperty('--k', i); b.textContent = v[i]; dots.append(d); plain.append(b) }
|
|
76
|
+
shown = v; cx()
|
|
77
|
+
const sc = score(v); bars.forEach((b, i) => b.classList.toggle('on', i < sc)); if (sc) el.style.setProperty('--pe-c', COL[sc])
|
|
78
|
+
if (inp.value !== v) inp.value = v
|
|
79
|
+
}
|
|
80
|
+
const cx = () => el.style.setProperty('--pe-cx', (el.classList.contains('is-show') ? plain : dots).offsetWidth + 'px')
|
|
81
|
+
const show = (on) => { el.classList.toggle('is-show', on); cx(); eye.setAttribute('aria-pressed', on); eye.setAttribute('aria-label', on ? '隐藏密码' : '显示密码') }
|
|
82
|
+
const end = () => inp.setSelectionRange(99, 99)
|
|
83
|
+
inp.addEventListener('input', () => { el.peDemo = false; set(inp.value); end() })
|
|
84
|
+
inp.addEventListener('focus', () => { el.classList.add('is-focus'); end() })
|
|
85
|
+
inp.addEventListener('blur', () => el.classList.remove('is-focus'))
|
|
86
|
+
inp.addEventListener('pointerup', () => requestAnimationFrame(end))
|
|
87
|
+
eye.addEventListener('mousedown', (e) => { if (document.activeElement === inp) e.preventDefault() })
|
|
88
|
+
eye.addEventListener('click', () => show(!el.classList.contains('is-show')))
|
|
89
|
+
el.peSet = (v) => { el.peDemo = true; set(v) }
|
|
90
|
+
el.peShow = show
|
|
91
|
+
})
|
|
92
|
+
})()
|
|
93
|
+
</script>
|
|
94
|
+
<script data-stage>
|
|
95
|
+
/* 演示舞台:每个组件都一样,只改 DEMO 那一段。组件按 340×212 设计,卡片小了整体等比缩小。 */
|
|
96
|
+
(() => {
|
|
97
|
+
const q = new URLSearchParams(location.search); const root = document.documentElement
|
|
98
|
+
root.dataset.theme = (q.get('theme') || (matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')) === 'dark' ? 'dark' : 'light'
|
|
99
|
+
const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
100
|
+
const el = document.querySelector('.stage-fit > [data-comp]')
|
|
101
|
+
const fit = () => root.style.setProperty('--fit', Math.min(1, innerWidth / 340, innerHeight / 212).toFixed(3))
|
|
102
|
+
fit(); addEventListener('resize', fit)
|
|
103
|
+
let playing = !q.has('still'); let hovering = false; let timers = []
|
|
104
|
+
const later = (fn, ms) => timers.push(setTimeout(() => { if (playing && !hovering) fn() }, ms)) // 演示用的定时器:用户一来就全部作废
|
|
105
|
+
const stop = () => { timers.forEach(clearTimeout); timers = []; DEMO.stop() }
|
|
106
|
+
const go = (ms) => { stop(); if (playing && !hovering && !reduced) later(() => DEMO.loop(later), ms) }
|
|
107
|
+
// ===== 只改这一段 =====
|
|
108
|
+
const inp = el.querySelector('.pe-in'); const PW = 'Moss-river9'
|
|
109
|
+
const real = () => document.hasFocus() && document.activeElement === inp
|
|
110
|
+
const tap = (later, on, t) => { later(() => el.classList.add('is-press'), t); later(() => { el.classList.remove('is-press'); el.peShow(on) }, t + 130) }
|
|
111
|
+
const DEMO = {
|
|
112
|
+
settle () { el.peSet(PW); el.peShow(true) }, // 落定:睁眼、满格
|
|
113
|
+
loop (later) {
|
|
114
|
+
if (real()) return later(() => DEMO.loop(later), 2000)
|
|
115
|
+
el.peSet(''); el.peShow(false); el.classList.add('is-focus')
|
|
116
|
+
;[...PW].forEach((c, i) => later(() => el.peSet(PW.slice(0, i + 1)), 200 + i * 100))
|
|
117
|
+
tap(later, true, 1750); tap(later, false, 3900)
|
|
118
|
+
;[...PW].forEach((c, i) => later(() => el.peSet(PW.slice(0, PW.length - 1 - i)), 4900 + i * 40))
|
|
119
|
+
later(() => { el.classList.remove('is-focus'); later(() => DEMO.loop(later), 900) }, 5500)
|
|
120
|
+
},
|
|
121
|
+
stop () { el.classList.remove('is-press'); if (el.peDemo) { el.peSet(''); el.peShow(false); if (document.activeElement !== inp) el.classList.remove('is-focus') } },
|
|
122
|
+
}
|
|
123
|
+
// =====================
|
|
124
|
+
document.body.addEventListener('pointerenter', () => { hovering = true; stop() })
|
|
125
|
+
document.body.addEventListener('pointerleave', () => { hovering = false; go(1400) })
|
|
126
|
+
addEventListener('message', (e) => {
|
|
127
|
+
const d = e.data; if (!d || typeof d !== 'object') return
|
|
128
|
+
if (d.theme === 'light' || d.theme === 'dark') root.dataset.theme = d.theme
|
|
129
|
+
if (typeof d.ddpPlay === 'boolean') { playing = d.ddpPlay; root.classList.toggle('paused', !playing); if (playing) go(400); else stop() }
|
|
130
|
+
})
|
|
131
|
+
try { parent.postMessage({ ddpMotionReady: 1 }, '*') } catch (e) { /* 单独打开时没有外层 */ }
|
|
132
|
+
if (reduced || q.has('still')) DEMO.settle(); else go(600)
|
|
133
|
+
})()
|
|
134
|
+
</script>
|
|
135
|
+
</body>
|
|
136
|
+
</html>
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<title>惯性刻度尺</title>
|
|
7
|
+
<script type="application/json" id="meta">{"zh":"惯性刻度尺","en":"Inertia Ruler","cat":"slider","desc":"左右甩刻度尺,带惯性滑行,松手吸到最近一格","desc_en":"Fling the ruler; it glides with inertia and snaps to the nearest tick","needs":"js","play":"drag","hint":"左右拖","hint_en":"Drag sideways","source":null,"prompt":"刻度尺:上面 46px 大数字加单位,下面 280×68 圆角 18px 的尺窗,两边用遮罩渐隐。一格 8px,每 5 格中刻度、每 10 格长刻度加小数字,刻度用三层渐变画在一条长带上,只平移这条带。按住拖跟手(按卡片缩放换算),越界有橡皮筋阻力;松手按最后 80ms 的速度往前投 0.22 秒、吸到最近一格,再用小步积分弹簧带着初速度落位。中间一根 3px 主色指针。数字变化时上下滚一下。方向键 ±1、Shift ±10。颜色读 --color-surface / --color-text / --color-muted / --color-line / --color-primary。减少动效时直接跳到格上。","prompt_en":"Ruler: 46px number above a 280×68 window (18px radius, faded edges). 8px ticks, mid every 5, long + label every 10: three gradients on one translated strip. Drag, rubber-band ends; release projects last-80ms velocity 0.22s, snaps, lands on a substepped spring. 3px pointer. Arrows ±1, Shift ±10. Reads --color-surface / --color-text / --color-muted / --color-line / --color-primary; reduced motion jumps.","id":"ruler-slider"}</script>
|
|
8
|
+
<style data-stage>
|
|
9
|
+
:root{color-scheme:light;--color-bg:#efede7;--color-surface:#fff;--color-text:#141413;--color-muted:#76756f;--color-line:rgba(20,20,19,.1);--color-primary:#0a84ff;--color-danger:#ff375f;--color-warning:#ffb340;--font-sans:-apple-system,BlinkMacSystemFont,"SF Pro Text","PingFang SC","Microsoft YaHei",system-ui,sans-serif}
|
|
10
|
+
:root[data-theme=dark]{color-scheme:dark;--color-bg:#17171a;--color-surface:#2c2c30;--color-text:#f5f5f4;--color-muted:#8e8d88;--color-line:rgba(255,255,255,.1)}
|
|
11
|
+
html,body{height:100%;margin:0}
|
|
12
|
+
body{display:grid;place-items:center;background:var(--color-bg);font-family:var(--font-sans);-webkit-font-smoothing:antialiased;overflow:hidden;user-select:none;-webkit-user-select:none}
|
|
13
|
+
.paused *{animation-play-state:paused!important}
|
|
14
|
+
.stage-fit{position:absolute;left:50%;top:50%;width:max-content;display:grid;place-items:center;transform:translate(-50%,-50%) scale(var(--fit,1))}
|
|
15
|
+
</style>
|
|
16
|
+
<style data-comp>
|
|
17
|
+
/* 惯性刻度尺 · 刻度画在一条长带上,脚本只平移它。读 --color-surface / --color-text / --color-muted / --color-line / --color-primary */
|
|
18
|
+
.c-ruler-slider{--rs-u:8px;--rs-acc:var(--color-primary,#0a84ff);--rs-t:color-mix(in srgb,var(--color-text,#141413) 28%,transparent);--rs-T:color-mix(in srgb,var(--color-text,#141413) 62%,transparent);display:grid;justify-items:center;gap:14px;width:280px;font-family:var(--font-sans,system-ui);outline:none;touch-action:none;cursor:grab;-webkit-tap-highlight-color:transparent}
|
|
19
|
+
.c-ruler-slider.drag{cursor:grabbing}
|
|
20
|
+
.c-ruler-slider .rs-val{display:flex;align-items:baseline;gap:5px;color:var(--color-text,#141413)}
|
|
21
|
+
.c-ruler-slider .rs-num{height:50px;overflow:hidden;font:600 46px/50px var(--font-sans,system-ui);font-variant-numeric:tabular-nums;letter-spacing:-.03em}
|
|
22
|
+
.c-ruler-slider .rs-num b{display:block;font-weight:inherit}
|
|
23
|
+
.c-ruler-slider .rs-num.up b{animation:rs-up .2s cubic-bezier(.2,.8,.2,1)}
|
|
24
|
+
.c-ruler-slider .rs-num.dn b{animation:rs-dn .2s cubic-bezier(.2,.8,.2,1)}
|
|
25
|
+
.c-ruler-slider .rs-unit{font-size:15px;font-weight:600;color:var(--color-muted,#76756f)}
|
|
26
|
+
.c-ruler-slider .rs-win{position:relative;width:100%;height:68px;border-radius:18px;background:var(--color-surface,#fff);box-shadow:inset 0 1px 0 color-mix(in srgb,var(--color-surface,#fff) 72%,#fff),0 0 0 .5px var(--color-line,rgba(0,0,0,.1)),0 1px 2px rgba(0,0,0,.06),0 14px 30px -12px rgba(0,0,0,.3);overflow:hidden}
|
|
27
|
+
.c-ruler-slider:focus-visible .rs-win{box-shadow:0 0 0 2px var(--rs-acc),0 14px 30px -12px rgba(0,0,0,.3)}
|
|
28
|
+
.c-ruler-slider .rs-mask{position:absolute;inset:0;-webkit-mask:linear-gradient(90deg,transparent,#000 22%,#000 78%,transparent);mask:linear-gradient(90deg,transparent,#000 22%,#000 78%,transparent)}
|
|
29
|
+
.c-ruler-slider .rs-strip{position:absolute;left:50%;top:0;height:100%;margin-left:-1px;background:linear-gradient(90deg,var(--rs-T) 2px,transparent 0) 0 0/calc(var(--rs-u)*10) 30px repeat-x,linear-gradient(90deg,var(--rs-t) 2px,transparent 0) calc(var(--rs-u)*5) 0/calc(var(--rs-u)*10) 21px repeat-x,linear-gradient(90deg,var(--rs-t) 1.5px,transparent 0) 0 0/var(--rs-u) 14px repeat-x;will-change:transform}
|
|
30
|
+
.c-ruler-slider .rs-strip i{position:absolute;top:38px;width:40px;margin-left:-19px;text-align:center;font:600 11px/1 var(--font-sans,system-ui);font-style:normal;font-variant-numeric:tabular-nums;color:var(--color-muted,#76756f)}
|
|
31
|
+
.c-ruler-slider .rs-pin{position:absolute;left:50%;top:0;width:3px;height:40px;margin-left:-1.5px;border-radius:0 0 3px 3px;background:var(--rs-acc);box-shadow:0 0 10px color-mix(in srgb,var(--rs-acc) 55%,transparent);transition:scale .4s cubic-bezier(.3,1.6,.5,1);transform-origin:top}
|
|
32
|
+
.c-ruler-slider.drag .rs-pin{scale:1 1.12}
|
|
33
|
+
@keyframes rs-up{from{transform:translateY(28%);opacity:.4}}
|
|
34
|
+
@keyframes rs-dn{from{transform:translateY(-28%);opacity:.4}}
|
|
35
|
+
@media (prefers-reduced-motion:reduce){.c-ruler-slider *{animation:none!important;transition:none!important}}
|
|
36
|
+
</style>
|
|
37
|
+
</head>
|
|
38
|
+
<body>
|
|
39
|
+
<div class="stage-fit">
|
|
40
|
+
<div class="c-ruler-slider" data-comp="ruler-slider" role="slider" tabindex="0" aria-label="体重" data-min="30" data-max="150" data-value="64" aria-valuemin="30" aria-valuemax="150" aria-valuenow="64">
|
|
41
|
+
<div class="rs-val"><div class="rs-num"><b>64</b></div><span class="rs-unit">kg</span></div>
|
|
42
|
+
<div class="rs-win"><div class="rs-mask"><div class="rs-strip"></div></div><span class="rs-pin"></span></div>
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
<script data-comp>
|
|
46
|
+
/* 刻度尺逻辑:拖 → 跟手(越界橡皮筋);松手 → 按速度投射、吸格,弹簧带初速度落位(小步积分)。一页可放多个。 */
|
|
47
|
+
(() => {
|
|
48
|
+
const U = 8, K = 150, C = 21
|
|
49
|
+
const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
50
|
+
document.querySelectorAll('.c-ruler-slider').forEach((el) => {
|
|
51
|
+
const min = +el.dataset.min || 0, max = +el.dataset.max || 100, hi = (max - min) * U
|
|
52
|
+
const strip = el.querySelector('.rs-strip'), num = el.querySelector('.rs-num')
|
|
53
|
+
strip.style.width = hi + 2 + 'px'
|
|
54
|
+
for (let v = Math.ceil(min / 10) * 10; v <= max; v += 10) strip.insertAdjacentHTML('beforeend', `<i style="left:${(v - min) * U + 1}px">${v}</i>`)
|
|
55
|
+
let val = +el.dataset.value, pos = (val - min) * U, vel = 0, goal = pos, raf = 0, last = 0, drag = null, drag0 = 0
|
|
56
|
+
const clamp = (x) => Math.max(0, Math.min(hi, x))
|
|
57
|
+
const snap = (x) => Math.round(clamp(x) / U) * U
|
|
58
|
+
const paint = () => {
|
|
59
|
+
strip.style.transform = `translateX(${(-pos).toFixed(2)}px)`
|
|
60
|
+
const v = Math.round(clamp(pos) / U) + min
|
|
61
|
+
if (v === val) return
|
|
62
|
+
num.classList.remove('up', 'dn'); void num.offsetWidth; num.classList.add(v > val ? 'up' : 'dn')
|
|
63
|
+
num.firstChild.textContent = v; val = v; el.dataset.value = v; el.setAttribute('aria-valuenow', v)
|
|
64
|
+
}
|
|
65
|
+
const tick = (t) => {
|
|
66
|
+
const dt = Math.min(0.032, (t - (last || t)) / 1000) || 0.016; last = t
|
|
67
|
+
for (let s = 0, n = Math.ceil(dt / 0.002), h = dt / n; s < n; s++) { vel += (-K * (pos - goal) - C * vel) * h; pos += vel * h }
|
|
68
|
+
if (Math.abs(pos - goal) < 0.05 && Math.abs(vel) < 2) { pos = goal; vel = 0; raf = 0; last = 0 } else raf = requestAnimationFrame(tick)
|
|
69
|
+
paint()
|
|
70
|
+
}
|
|
71
|
+
const run = () => { if (reduced) { pos = goal; vel = 0; paint() } else if (!raf) raf = requestAnimationFrame(tick) }
|
|
72
|
+
const fling = (v) => { vel = v; goal = snap(pos + v * 0.22); run() } // 按速度往前投一段再吸格
|
|
73
|
+
const pull = (x) => { const o = x - clamp(x); pos = clamp(x) + o * 0.32; paint() } // 越界 → 橡皮筋
|
|
74
|
+
el.addEventListener('pointerdown', (e) => {
|
|
75
|
+
cancelAnimationFrame(raf); raf = 0; last = 0; el.setPointerCapture(e.pointerId); el.classList.add('drag')
|
|
76
|
+
const r = el.getBoundingClientRect(); drag = { x: e.clientX, p: pos, k: r.width / el.offsetWidth || 1, s: [[e.timeStamp, pos]] }
|
|
77
|
+
})
|
|
78
|
+
el.addEventListener('pointermove', (e) => {
|
|
79
|
+
if (!drag) return
|
|
80
|
+
pull(drag.p - (e.clientX - drag.x) / drag.k); drag.s.push([e.timeStamp, drag.p - (e.clientX - drag.x) / drag.k])
|
|
81
|
+
while (drag.s.length > 2 && e.timeStamp - drag.s[0][0] > 80) drag.s.shift()
|
|
82
|
+
})
|
|
83
|
+
const end = (e) => {
|
|
84
|
+
if (!drag) return; const s = drag.s, a = s[0], b = s[s.length - 1]; drag = null; el.classList.remove('drag')
|
|
85
|
+
const v = b[0] - a[0] > 8 && e.timeStamp - b[0] < 60 ? (b[1] - a[1]) / (b[0] - a[0]) * 1000 : 0
|
|
86
|
+
fling(Math.max(-3000, Math.min(3000, v)))
|
|
87
|
+
}
|
|
88
|
+
el.addEventListener('pointerup', end); el.addEventListener('pointercancel', end)
|
|
89
|
+
el.addEventListener('keydown', (e) => { const d = { ArrowRight: 1, ArrowUp: 1, ArrowLeft: -1, ArrowDown: -1 }[e.key]; if (!d) return; e.preventDefault(); goal = snap(goal + d * (e.shiftKey ? 10 : 1) * U); run() })
|
|
90
|
+
el.rsTo = (v) => { goal = snap((v - min) * U); run() } // 给演示舞台用
|
|
91
|
+
el.rsGrab = () => { cancelAnimationFrame(raf); raf = 0; last = 0; vel = 0; drag0 = pos } // 演示:从当前位置按住
|
|
92
|
+
el.rsPull = (dx) => pull(drag0 + dx)
|
|
93
|
+
el.rsFling = fling
|
|
94
|
+
paint()
|
|
95
|
+
})
|
|
96
|
+
})()
|
|
97
|
+
</script>
|
|
98
|
+
<script data-stage>
|
|
99
|
+
/* 演示舞台:每个组件都一样,只改 DEMO 那一段。组件按 340×212 设计,卡片小了整体等比缩小。 */
|
|
100
|
+
(() => {
|
|
101
|
+
const q = new URLSearchParams(location.search); const root = document.documentElement
|
|
102
|
+
root.dataset.theme = (q.get('theme') || (matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')) === 'dark' ? 'dark' : 'light'
|
|
103
|
+
const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
104
|
+
const el = document.querySelector('.stage-fit > [data-comp]')
|
|
105
|
+
const fit = () => root.style.setProperty('--fit', Math.min(1, innerWidth / 340, innerHeight / 212).toFixed(3))
|
|
106
|
+
fit(); addEventListener('resize', fit)
|
|
107
|
+
let playing = !q.has('still'); let hovering = false; let timers = []
|
|
108
|
+
const later = (fn, ms) => timers.push(setTimeout(() => { if (playing && !hovering) fn() }, ms)) // 演示用的定时器:用户一来就全部作废
|
|
109
|
+
const stop = () => { timers.forEach(clearTimeout); timers = []; DEMO.stop() }
|
|
110
|
+
const go = (ms) => { stop(); if (playing && !hovering && !reduced) later(() => DEMO.loop(later), ms) }
|
|
111
|
+
// ===== 只改这一段 =====
|
|
112
|
+
let raf = 0
|
|
113
|
+
const glide = (to, ms) => { // 假手指:从当前位置按住拖一段(先慢后快),松手带着速度甩出去,滑行后正好吸到 to
|
|
114
|
+
const dx = (to - +el.dataset.value) * 8 / (1 + 440 / ms); const t0 = performance.now(); el.rsGrab()
|
|
115
|
+
const f = (t) => { const k = Math.min(1, (t - t0) / ms); el.rsPull(dx * k * k); el.classList.add('drag'); if (k < 1) raf = requestAnimationFrame(f); else { el.classList.remove('drag'); el.rsFling(dx * 2 / ms * 1000) } }
|
|
116
|
+
raf = requestAnimationFrame(f)
|
|
117
|
+
}
|
|
118
|
+
const DEMO = {
|
|
119
|
+
settle () {}, // 落定状态:64
|
|
120
|
+
loop (later) {
|
|
121
|
+
later(() => glide(86, 520), 250) // 往大甩
|
|
122
|
+
later(() => glide(64, 480), 2500) // 甩回来
|
|
123
|
+
later(() => DEMO.loop(later), 4800)
|
|
124
|
+
},
|
|
125
|
+
stop () { cancelAnimationFrame(raf); raf = 0; if (el.classList.contains('drag')) { el.classList.remove('drag'); el.rsFling(0) } },
|
|
126
|
+
}
|
|
127
|
+
// =====================
|
|
128
|
+
document.body.addEventListener('pointerenter', () => { hovering = true; stop() })
|
|
129
|
+
document.body.addEventListener('pointerleave', () => { hovering = false; go(1400) })
|
|
130
|
+
addEventListener('message', (e) => {
|
|
131
|
+
const d = e.data; if (!d || typeof d !== 'object') return
|
|
132
|
+
if (d.theme === 'light' || d.theme === 'dark') root.dataset.theme = d.theme
|
|
133
|
+
if (typeof d.ddpPlay === 'boolean') { playing = d.ddpPlay; root.classList.toggle('paused', !playing); if (playing) go(400); else stop() }
|
|
134
|
+
})
|
|
135
|
+
try { parent.postMessage({ ddpMotionReady: 1 }, '*') } catch (e) { /* 单独打开时没有外层 */ }
|
|
136
|
+
if (reduced || q.has('still')) DEMO.settle(); else go(600)
|
|
137
|
+
})()
|
|
138
|
+
</script>
|
|
139
|
+
</body>
|
|
140
|
+
</html>
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<title>伸缩搜索框</title>
|
|
7
|
+
<script type="application/json" id="meta">{"zh":"伸缩搜索框","en":"Expandable Search","cat":"input","desc":"圆形放大镜一点就舒展成搜索框,放大镜滚到左边","desc_en":"The round magnifier unrolls into a search field and rolls to the left","needs":"css","play":"press","hint":"点放大镜","hint_en":"Tap the icon","source":null,"prompt":"展开搜索:label 包住输入框和放大镜,纯 CSS。收起时是 52px 的圆,按下缩到 .92;获得焦点(:focus-within)后底板用轻弹簧从中间向两边舒展到 280px(收回用无过冲缓动,免得挤成细条),放大镜一边转一圈一边滚到左边 14px 处,输入框淡入;失焦且没字就收回。底板读 --color-surface,加发丝边和两层阴影;聚焦时加一圈半透明 --color-primary;字读 --color-text / --color-muted。减少动效时直接切换。","prompt_en":"Expand search, pure CSS (label wraps input and icon): a 52px circle, press .92. On :focus-within it springs from center to 280px (.75s linear()), closing with cubic-bezier(.32,.72,0,1), no overshoot. The icon spins once to 14px from the left; input fades in; empty on blur, it closes. Reads --color-surface (hairline, two shadows), --color-primary focus ring, --color-text / --color-muted. Reduced motion: instant.","id":"search-expand"}</script>
|
|
8
|
+
<style data-stage>
|
|
9
|
+
:root{color-scheme:light;--color-bg:#efede7;--color-surface:#fff;--color-text:#141413;--color-muted:#76756f;--color-line:rgba(20,20,19,.1);--color-primary:#0a84ff;--color-danger:#ff375f;--color-warning:#ffb340;--font-sans:-apple-system,BlinkMacSystemFont,"SF Pro Text","PingFang SC","Microsoft YaHei",system-ui,sans-serif}
|
|
10
|
+
:root[data-theme=dark]{color-scheme:dark;--color-bg:#17171a;--color-surface:#2c2c30;--color-text:#f5f5f4;--color-muted:#8e8d88;--color-line:rgba(255,255,255,.1)}
|
|
11
|
+
html,body{height:100%;margin:0}
|
|
12
|
+
body{display:grid;place-items:center;background:var(--color-bg);font-family:var(--font-sans);-webkit-font-smoothing:antialiased;overflow:hidden;user-select:none;-webkit-user-select:none}
|
|
13
|
+
.paused *{animation-play-state:paused!important}
|
|
14
|
+
.stage-fit{position:absolute;left:50%;top:50%;width:max-content;display:grid;place-items:center;transform:translate(-50%,-50%) scale(var(--fit,1))}
|
|
15
|
+
</style>
|
|
16
|
+
<style data-comp>
|
|
17
|
+
/* 伸缩搜索框 · 纯 CSS::focus-within 打开,有字时保持打开。读 --color-surface / --color-text / --color-muted / --color-line / --color-primary */
|
|
18
|
+
.c-search-expand{--se-w:280px;--se-h:52px;--se-acc:var(--color-primary,#0a84ff);--se-sp:linear(0,.25,.62,.95,1.16,1.23,1.2,1.12,1.04,.98,.95,.95,.97,.99,1.01,1.01,1);--se-g:linear(0,.14,.42,.7,.9,1.02,1.07,1.08,1.06,1.03,1.01,1,.995,1);--se-out:cubic-bezier(.32,.72,0,1);--se-sh:inset 0 1px 0 color-mix(in srgb,var(--color-surface,#fff) 72%,#fff),0 0 0 .5px var(--color-line,rgba(0,0,0,.1)),0 1px 2px rgba(0,0,0,.06),0 12px 26px -12px rgba(0,0,0,.3);position:relative;display:block;width:var(--se-w);height:var(--se-h);font-family:var(--font-sans,system-ui);-webkit-tap-highlight-color:transparent}
|
|
19
|
+
.c-search-expand .se-bg{position:absolute;left:50%;top:0;width:var(--se-h);height:100%;border-radius:calc(var(--se-h)/2);background:var(--color-surface,#fff);box-shadow:var(--se-sh);transform:translateX(-50%);transition:width .45s var(--se-out),transform .5s var(--se-sp),box-shadow .3s}
|
|
20
|
+
.c-search-expand .se-ico{position:absolute;left:14px;top:14px;width:24px;height:24px;color:var(--color-text,#141413);transform:translateX(calc(var(--se-w)/2 - 26px));transition:transform .5s var(--se-out),color .3s;pointer-events:none}
|
|
21
|
+
.c-search-expand .se-in{position:absolute;left:calc(50% - var(--se-h)/2);top:0;width:var(--se-h);height:100%;margin:0;padding:0 20px 0 48px;box-sizing:border-box;border:0;border-radius:calc(var(--se-h)/2);background:none;outline:none;font:500 16px/1 var(--font-sans,system-ui);color:var(--color-text,#141413);opacity:0;cursor:pointer;transition:opacity .15s}
|
|
22
|
+
.c-search-expand .se-in::placeholder{color:var(--color-muted,#76756f)}
|
|
23
|
+
.c-search-expand .se-in::-webkit-search-cancel-button{-webkit-appearance:none;appearance:none}
|
|
24
|
+
.c-search-expand:hover .se-bg{transform:translateX(-50%) scale(1.05)}
|
|
25
|
+
.c-search-expand:active .se-bg,.c-search-expand.is-press .se-bg{transform:translateX(-50%) scale(.92);transition:width .45s var(--se-out),transform .1s,box-shadow .3s}
|
|
26
|
+
.c-search-expand:focus-within .se-bg,.c-search-expand.is-open .se-bg,.c-search-expand:has(.se-in:not(:placeholder-shown)) .se-bg{width:100%;transform:translateX(-50%);transition:width .75s var(--se-g),transform .5s var(--se-sp),box-shadow .3s}
|
|
27
|
+
.c-search-expand:focus-within .se-bg,.c-search-expand.is-open .se-bg{box-shadow:var(--se-sh),0 0 0 1.5px color-mix(in srgb,var(--se-acc) 70%,transparent),0 0 0 5px color-mix(in srgb,var(--se-acc) 13%,transparent)}
|
|
28
|
+
.c-search-expand:focus-within .se-ico,.c-search-expand.is-open .se-ico,.c-search-expand:has(.se-in:not(:placeholder-shown)) .se-ico{transform:translateX(0) rotate(-360deg);color:var(--color-muted,#76756f);transition:transform .8s var(--se-g),color .3s}
|
|
29
|
+
.c-search-expand:focus-within .se-in,.c-search-expand.is-open .se-in,.c-search-expand:has(.se-in:not(:placeholder-shown)) .se-in{left:0;width:100%;opacity:1;cursor:text;transition:opacity .3s .18s}
|
|
30
|
+
@media (prefers-reduced-motion:reduce){.c-search-expand *{transition:none!important}}
|
|
31
|
+
</style>
|
|
32
|
+
</head>
|
|
33
|
+
<body>
|
|
34
|
+
<div class="stage-fit">
|
|
35
|
+
<label class="c-search-expand" data-comp="search-expand">
|
|
36
|
+
<span class="se-bg"></span>
|
|
37
|
+
<input class="se-in" type="search" placeholder="搜索" aria-label="搜索" enterkeyhint="search">
|
|
38
|
+
<svg class="se-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" aria-hidden="true"><circle cx="10.5" cy="10.5" r="6.2"/><path d="m15.2 15.2 4.6 4.6"/></svg>
|
|
39
|
+
</label>
|
|
40
|
+
</div>
|
|
41
|
+
<script data-stage>
|
|
42
|
+
/* 演示舞台:每个组件都一样,只改 DEMO 那一段。组件按 340×212 设计,卡片小了整体等比缩小。 */
|
|
43
|
+
(() => {
|
|
44
|
+
const q = new URLSearchParams(location.search); const root = document.documentElement
|
|
45
|
+
root.dataset.theme = (q.get('theme') || (matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')) === 'dark' ? 'dark' : 'light'
|
|
46
|
+
const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
47
|
+
const el = document.querySelector('.stage-fit > [data-comp]')
|
|
48
|
+
const fit = () => root.style.setProperty('--fit', Math.min(1, innerWidth / 340, innerHeight / 212).toFixed(3))
|
|
49
|
+
fit(); addEventListener('resize', fit)
|
|
50
|
+
let playing = !q.has('still'); let hovering = false; let timers = []
|
|
51
|
+
const later = (fn, ms) => timers.push(setTimeout(() => { if (playing && !hovering) fn() }, ms)) // 演示用的定时器:用户一来就全部作废
|
|
52
|
+
const stop = () => { timers.forEach(clearTimeout); timers = []; DEMO.stop() }
|
|
53
|
+
const go = (ms) => { stop(); if (playing && !hovering && !reduced) later(() => DEMO.loop(later), ms) }
|
|
54
|
+
// ===== 只改这一段 =====
|
|
55
|
+
const inp = el.querySelector('.se-in'); const WORD = '晚风小馆'
|
|
56
|
+
const type = (later, t0, gap, back) => [...WORD].forEach((c, i) => later(() => { inp.value = back ? WORD.slice(0, WORD.length - 1 - i) : WORD.slice(0, i + 1) }, t0 + i * gap))
|
|
57
|
+
const DEMO = {
|
|
58
|
+
settle () { el.classList.add('is-open'); inp.value = WORD }, // 落定状态:展开并输了字
|
|
59
|
+
loop (later) {
|
|
60
|
+
if (document.hasFocus() && document.activeElement === inp) return later(() => DEMO.loop(later), 2000) // 用户在用:不抢
|
|
61
|
+
inp.value = ''; el.classList.add('is-press')
|
|
62
|
+
later(() => { el.classList.remove('is-press'); el.classList.add('is-open') }, 160)
|
|
63
|
+
type(later, 700, 200); type(later, 2250, 90, true) // 自己打字,再一个个删掉
|
|
64
|
+
later(() => { el.classList.remove('is-open'); later(() => DEMO.loop(later), 1400) }, 2750)
|
|
65
|
+
},
|
|
66
|
+
stop () { el.classList.remove('is-press', 'is-open'); if (document.activeElement !== inp) inp.value = '' },
|
|
67
|
+
}
|
|
68
|
+
// =====================
|
|
69
|
+
document.body.addEventListener('pointerenter', () => { hovering = true; stop() })
|
|
70
|
+
document.body.addEventListener('pointerleave', () => { hovering = false; go(1400) })
|
|
71
|
+
addEventListener('message', (e) => {
|
|
72
|
+
const d = e.data; if (!d || typeof d !== 'object') return
|
|
73
|
+
if (d.theme === 'light' || d.theme === 'dark') root.dataset.theme = d.theme
|
|
74
|
+
if (typeof d.ddpPlay === 'boolean') { playing = d.ddpPlay; root.classList.toggle('paused', !playing); if (playing) go(400); else stop() }
|
|
75
|
+
})
|
|
76
|
+
try { parent.postMessage({ ddpMotionReady: 1 }, '*') } catch (e) { /* 单独打开时没有外层 */ }
|
|
77
|
+
if (reduced || q.has('still')) DEMO.settle(); else go(600)
|
|
78
|
+
})()
|
|
79
|
+
</script>
|
|
80
|
+
</body>
|
|
81
|
+
</html>
|