dsh-design-studio 2.0.0 → 2.1.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 +2 -1
- package/README.md +2 -1
- package/THIRD_PARTY_NOTICES.md +319 -0
- package/assets/demo.gif +0 -0
- package/assets/hero-sm.jpg +0 -0
- package/assets/motion/ai-capsule.html +4 -2
- package/assets/motion/ai-glow-input.html +4 -2
- package/assets/motion/app-fab.html +130 -0
- package/assets/motion/app-gallery.html +125 -0
- package/assets/motion/app-index.html +138 -0
- package/assets/motion/app-largetitle.html +138 -0
- package/assets/motion/app-onboard.html +141 -0
- package/assets/motion/app-player.html +152 -0
- package/assets/motion/app-popover.html +133 -0
- package/assets/motion/app-rings.html +143 -0
- package/assets/motion/app-searchhist.html +131 -0
- package/assets/motion/app-tabbar.html +148 -0
- package/assets/motion/app-tabs.html +150 -0
- package/assets/motion/app-video.html +136 -0
- package/assets/motion/balance-odometer.html +4 -2
- package/assets/motion/bottom-sheet.html +4 -2
- package/assets/motion/brightness-pill.html +4 -2
- package/assets/motion/chart-area.html +111 -0
- package/assets/motion/chart-bar.html +100 -0
- package/assets/motion/chart-donut.html +145 -0
- package/assets/motion/chart-funnel.html +120 -0
- package/assets/motion/chart-gantt.html +140 -0
- package/assets/motion/chart-gauge.html +126 -0
- package/assets/motion/chart-heat.html +121 -0
- package/assets/motion/chart-kpi.html +110 -0
- package/assets/motion/chart-line.html +154 -0
- package/assets/motion/chart-radar.html +153 -0
- package/assets/motion/chart-rank.html +112 -0
- package/assets/motion/chart-stack.html +107 -0
- package/assets/motion/comet-ring.html +4 -2
- package/assets/motion/copy-morph.html +4 -2
- package/assets/motion/cube-grid.html +4 -2
- package/assets/motion/day-night.html +4 -2
- package/assets/motion/dial-knob.html +4 -2
- package/assets/motion/dock-magnify.html +4 -2
- package/assets/motion/download-ring.html +4 -2
- package/assets/motion/expand-card.html +4 -2
- package/assets/motion/flip-card.html +4 -2
- package/assets/motion/hold-pay.html +4 -2
- package/assets/motion/holo-card.html +4 -2
- package/assets/motion/keycap.html +4 -2
- package/assets/motion/like-jelly.html +4 -2
- package/assets/motion/liquid-progress.html +4 -2
- package/assets/motion/liquid-segment.html +4 -2
- package/assets/motion/live-capsule.html +4 -2
- package/assets/motion/m-actionsheet.html +84 -0
- package/assets/motion/m-address.html +113 -0
- package/assets/motion/m-buybar.html +122 -0
- package/assets/motion/m-calendar.html +135 -0
- package/assets/motion/m-capsule-nav.html +97 -0
- package/assets/motion/m-cart.html +162 -0
- package/assets/motion/m-category.html +154 -0
- package/assets/motion/m-chat.html +125 -0
- package/assets/motion/m-coupon.html +84 -0
- package/assets/motion/m-dialog.html +102 -0
- package/assets/motion/m-empty.html +121 -0
- package/assets/motion/m-filter.html +171 -0
- package/assets/motion/m-goods.html +151 -0
- package/assets/motion/m-grid.html +98 -0
- package/assets/motion/m-login.html +127 -0
- package/assets/motion/m-msglist.html +88 -0
- package/assets/motion/m-order.html +111 -0
- package/assets/motion/m-profile.html +110 -0
- package/assets/motion/m-pull.html +199 -0
- package/assets/motion/m-settings.html +81 -0
- package/assets/motion/m-sku.html +114 -0
- package/assets/motion/m-swiper.html +163 -0
- package/assets/motion/m-timeline.html +109 -0
- package/assets/motion/m-wheel.html +182 -0
- package/assets/motion/marker-highlight.html +4 -2
- package/assets/motion/marquee-logos.html +4 -2
- package/assets/motion/mp-cartbar.html +158 -0
- package/assets/motion/mp-checkin.html +121 -0
- package/assets/motion/mp-form.html +128 -0
- package/assets/motion/mp-group.html +148 -0
- package/assets/motion/mp-invite.html +119 -0
- package/assets/motion/mp-points.html +143 -0
- package/assets/motion/mp-queue.html +136 -0
- package/assets/motion/mp-rate.html +166 -0
- package/assets/motion/mp-seckill.html +140 -0
- package/assets/motion/mp-store.html +137 -0
- package/assets/motion/mp-vip.html +126 -0
- package/assets/motion/mp-wizard.html +174 -0
- package/assets/motion/otp-code.html +7 -4
- package/assets/motion/password-eye.html +4 -2
- package/assets/motion/ruler-slider.html +4 -2
- package/assets/motion/search-expand.html +4 -2
- package/assets/motion/send-fly.html +4 -2
- package/assets/motion/skeleton-shine.html +4 -2
- package/assets/motion/star-rate.html +4 -2
- package/assets/motion/success-check.html +4 -2
- package/assets/motion/suggest-chips.html +4 -2
- package/assets/motion/swipe-row.html +4 -2
- package/assets/motion/tabbar-bounce.html +4 -2
- package/assets/motion/tactile-controls.html +4 -2
- package/assets/motion/text-scramble.html +4 -2
- package/assets/motion/toast-stack.html +4 -2
- package/assets/motion/token-stream.html +4 -2
- package/assets/motion/um-bell.html +106 -0
- package/assets/motion/um-chips.html +132 -0
- package/assets/motion/um-coin.html +119 -0
- package/assets/motion/um-hue.html +128 -0
- package/assets/motion/um-ink-switch.html +129 -0
- package/assets/motion/um-leaf-tabs.html +138 -0
- package/assets/motion/um-plan.html +110 -0
- package/assets/motion/um-radial.html +104 -0
- package/assets/motion/um-stroke-check.html +86 -0
- package/assets/motion/um-swipe-confirm.html +182 -0
- package/assets/motion/um-tide.html +180 -0
- package/assets/motion/voice-orb.html +4 -2
- package/assets/motion/web-404.html +95 -0
- package/assets/motion/web-cmdk.html +167 -0
- package/assets/motion/web-dropdown.html +94 -0
- package/assets/motion/web-faq.html +84 -0
- package/assets/motion/web-footer.html +109 -0
- package/assets/motion/web-hero.html +98 -0
- package/assets/motion/web-navbar.html +149 -0
- package/assets/motion/web-newsletter.html +124 -0
- package/assets/motion/web-pagination.html +132 -0
- package/assets/motion/web-pricing.html +110 -0
- package/assets/motion/web-testimonial.html +129 -0
- package/assets/motion/web-upload.html +160 -0
- package/lib/client.js +76 -17
- package/lib/index.js +6 -2
- package/lib/motion.js +11 -2
- package/package.json +1 -1
|
@@ -0,0 +1,182 @@
|
|
|
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">{"id":"m-wheel","zh":"滚轮选择器","en":"Wheel Picker","cat":"mobile","desc":"三列日期滚轮,上下拖带惯性,松手吸附整格并高亮中间条","desc_en":"Three-column date wheel with momentum drag, snap-to-row physics, and a center highlight bar","needs":"js","play":"drag","hint":"上下拖滚轮","hint_en":"Drag wheels","source":{"name":"WeUI","url":"https://github.com/Tencent/weui/blob/master/src/style/widget/weui-picker/weui-picker.less","license":"MIT","author":"2017 THL A29 Limited (Tencent)"},"prompt":"三列日期滚轮选择器:288×170 圆角 18px 的 --color-surface 面板。顶栏高 36px 显示标题、实时选中日期与主色「确定」;下方 134px 滚轮区放年、月、日三列,每格高 34px,中间一条圆角浅底高亮带,上下两端用遮罩渐隐。日期列随年月给 28–31 天。按住任一列上下拖跟手,越界带 0.3 倍橡皮筋阻尼,松手按末速度向前投射 0.2 秒并以小步积分弹簧吸附到整格,点选项或方向键也可切换。减少动效时直接到位。","prompt_en":"Three-column date wheel picker (288×170, 18px radius, --color-surface): 36px header with live date readout and primary Confirm, plus a 134px wheel area with 34px rows, a rounded center highlight bar and faded top and bottom edges. Days follow year and month; tapping a row selects it. Dragging any column follows pointer with 0.3 rubber-band past ends; release projects velocity 0.2s and lands on a substepped spring. Keyboard arrows work; reduced motion snaps immediately."}</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
|
+
/* 滚轮选择器 改写自 WeUI(MIT,© 2017 THL A29 Limited,https://github.com/Tencent/weui)的 weui-picker.less:多列布局、上下渐隐遮罩与居中圆角高亮条;遮罩改读 --color-surface 适配浅深色,增加手势惯性吸附。
|
|
18
|
+
读 --color-surface / --color-text / --color-muted / --color-line / --color-primary */
|
|
19
|
+
.c-m-wheel{width:288px;height:170px;border-radius:18px;overflow:hidden;display:flex;flex-direction:column;background:var(--color-surface,#fff);box-shadow:0 0 0 .5px var(--color-line,rgba(0,0,0,.1)),0 2px 4px rgba(0,0,0,.05),0 14px 30px -14px rgba(0,0,0,.3);font-family:var(--font-sans,system-ui);-webkit-tap-highlight-color:transparent;color:var(--color-text,#141413)}
|
|
20
|
+
.c-m-wheel .wh-hd{flex:none;height:36px;padding:0 13px;display:flex;align-items:center;justify-content:space-between;border-bottom:.5px solid var(--color-line,rgba(0,0,0,.1))}
|
|
21
|
+
.c-m-wheel .wh-cap{font-size:12px;color:var(--color-muted,#76756f)}
|
|
22
|
+
.c-m-wheel .wh-out{font-size:12.5px;font-weight:600;font-variant-numeric:tabular-nums;transition:color .2s}
|
|
23
|
+
.c-m-wheel .wh-out.is-flash{color:var(--color-primary,#0a84ff)}
|
|
24
|
+
.c-m-wheel .wh-ok{border:0;background:none;padding:2px 4px;font:600 12.5px/1 var(--font-sans,system-ui);color:var(--color-primary,#0a84ff);cursor:pointer;border-radius:6px;transition:transform .16s}
|
|
25
|
+
.c-m-wheel .wh-ok:active{transform:scale(.9)}
|
|
26
|
+
.c-m-wheel .wh-ok:focus-visible{outline:2px solid var(--color-primary,#0a84ff);outline-offset:1px}
|
|
27
|
+
.c-m-wheel .wh-bd{position:relative;flex:1;display:flex;padding:0 8px;overflow:hidden}
|
|
28
|
+
.c-m-wheel .wh-ind{position:absolute;left:10px;right:10px;top:50%;height:34px;margin-top:-17px;border-radius:9px;background:color-mix(in srgb,var(--color-text,#141413) 6.5%,transparent);box-shadow:inset 0 0 0 .5px var(--color-line,rgba(0,0,0,.08));pointer-events:none;z-index:1}
|
|
29
|
+
.c-m-wheel .wh-col{position:relative;flex:1;height:100%;overflow:hidden;touch-action:none;cursor:grab;z-index:2;outline:none;-webkit-mask:linear-gradient(180deg,transparent 10%,rgba(0,0,0,.7) 33%,#000 40%,#000 60%,rgba(0,0,0,.7) 67%,transparent 90%);mask:linear-gradient(180deg,transparent 10%,rgba(0,0,0,.7) 33%,#000 40%,#000 60%,rgba(0,0,0,.7) 67%,transparent 90%)}
|
|
30
|
+
.c-m-wheel .wh-col.is-drag{cursor:grabbing}
|
|
31
|
+
.c-m-wheel .wh-col:focus-visible{box-shadow:inset 0 0 0 1.5px color-mix(in srgb,var(--color-primary,#0a84ff) 60%,transparent);border-radius:8px}
|
|
32
|
+
.c-m-wheel .wh-list{position:absolute;left:0;right:0;top:50%;margin-top:-17px;will-change:transform}
|
|
33
|
+
.c-m-wheel .wh-item{height:34px;line-height:34px;text-align:center;font-size:14px;font-weight:500;font-variant-numeric:tabular-nums;color:var(--color-muted,#76756f);transition:color .15s}
|
|
34
|
+
.c-m-wheel .wh-item.on{color:var(--color-text,#141413);font-weight:650}
|
|
35
|
+
@media (prefers-reduced-motion:reduce){.c-m-wheel *{transition:none!important}}
|
|
36
|
+
</style>
|
|
37
|
+
</head>
|
|
38
|
+
<body>
|
|
39
|
+
<div class="stage-fit">
|
|
40
|
+
<div class="c-m-wheel" data-comp="m-wheel" data-val="2027年 03月 12日">
|
|
41
|
+
<div class="wh-hd"><span class="wh-cap">预约日期</span><strong class="wh-out" aria-live="polite">2027年 03月 12日</strong><button class="wh-ok" type="button">确定</button></div>
|
|
42
|
+
<div class="wh-bd">
|
|
43
|
+
<i class="wh-ind" aria-hidden="true"></i>
|
|
44
|
+
<div class="wh-col" tabindex="0" role="spinbutton" aria-label="年份" data-idx="5"><div class="wh-list" style="transform: translateY(-170px);"><div class="wh-item">2022年</div><div class="wh-item">2023年</div><div class="wh-item">2024年</div><div class="wh-item">2025年</div><div class="wh-item">2026年</div><div class="wh-item on">2027年</div><div class="wh-item">2028年</div><div class="wh-item">2029年</div></div></div>
|
|
45
|
+
<div class="wh-col" tabindex="0" role="spinbutton" aria-label="月份" data-idx="2"><div class="wh-list" style="transform: translateY(-68px);"><div class="wh-item">01月</div><div class="wh-item">02月</div><div class="wh-item on">03月</div><div class="wh-item">04月</div><div class="wh-item">05月</div></div></div>
|
|
46
|
+
<div class="wh-col" tabindex="0" role="spinbutton" aria-label="日期" data-idx="11"><div class="wh-list" style="transform: translateY(-374px);"><div class="wh-item">01日</div><div class="wh-item">02日</div><div class="wh-item">03日</div><div class="wh-item">04日</div><div class="wh-item">05日</div><div class="wh-item">06日</div><div class="wh-item">07日</div><div class="wh-item">08日</div><div class="wh-item">09日</div><div class="wh-item">10日</div><div class="wh-item">11日</div><div class="wh-item on">12日</div><div class="wh-item">13日</div><div class="wh-item">14日</div></div></div>
|
|
47
|
+
</div>
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
50
|
+
<script data-comp>
|
|
51
|
+
/* 滚轮选择器:三列独立拖拽与越界橡皮筋阻尼,松手按速度投射并以小步积分弹簧吸附整格。支持一页多实例。 */
|
|
52
|
+
(() => {
|
|
53
|
+
const H = 34, K = 165, C = 22
|
|
54
|
+
const COLS = [
|
|
55
|
+
Array.from({ length: 9 }, (_, i) => (2022 + i) + '年'),
|
|
56
|
+
Array.from({ length: 12 }, (_, i) => String(i + 1).padStart(2, '0') + '月'),
|
|
57
|
+
Array.from({ length: 31 }, (_, i) => String(i + 1).padStart(2, '0') + '日'),
|
|
58
|
+
]
|
|
59
|
+
const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
60
|
+
document.querySelectorAll('.c-m-wheel').forEach((el) => {
|
|
61
|
+
const out = el.querySelector('.wh-out'), ok = el.querySelector('.wh-ok')
|
|
62
|
+
const colEls = [...el.querySelectorAll('.wh-col')]
|
|
63
|
+
const wheels = colEls.map((col, ci) => {
|
|
64
|
+
const items = COLS[ci], hi = (items.length - 1) * H
|
|
65
|
+
const list = document.createElement('div'); list.className = 'wh-list'
|
|
66
|
+
list.innerHTML = items.map((t, i) => `<div class="wh-item" data-i="${i}">${t}</div>`).join('')
|
|
67
|
+
col.replaceChildren(list)
|
|
68
|
+
const nodes = [...list.children]
|
|
69
|
+
const init = Math.max(0, Math.min(items.length - 1, Number(col.dataset.idx) || 0))
|
|
70
|
+
return { col, list, nodes, items, hi, idx: init, pos: init * H, goal: init * H, vel: 0, raf: 0, last: 0, drag: null, drag0: 0 }
|
|
71
|
+
})
|
|
72
|
+
const syncOut = () => {
|
|
73
|
+
const s = wheels.map((w) => w.items[w.idx]).join(' ')
|
|
74
|
+
out.textContent = s; el.dataset.val = s
|
|
75
|
+
}
|
|
76
|
+
const paint = (w) => {
|
|
77
|
+
w.list.style.transform = `translateY(${(-w.pos).toFixed(2)}px)`
|
|
78
|
+
const i = Math.max(0, Math.min(w.items.length - 1, Math.round(w.pos / H)))
|
|
79
|
+
if (i !== w.idx) { w.idx = i; w.col.dataset.idx = i; w.col.setAttribute('aria-valuetext', w.items[i]); if (w !== wheels[2]) fitDays(); syncOut() }
|
|
80
|
+
w.nodes.forEach((n, j) => { const d = Math.abs(j * H - w.pos) / H; n.classList.toggle('on', j === w.idx); n.style.opacity = d >= 1.55 ? 0 : (1 - Math.max(0, d - 0.45) * 0.55).toFixed(2) })
|
|
81
|
+
}
|
|
82
|
+
const clamp = (w, x) => Math.max(0, Math.min(w.hi, x))
|
|
83
|
+
// 日期列只到当月最后一天;换年月后超出的日子收回到月底
|
|
84
|
+
function fitDays () {
|
|
85
|
+
const [y, m, d] = wheels; const n = new Date(2022 + y.idx, m.idx + 1, 0).getDate()
|
|
86
|
+
d.hi = (n - 1) * H; d.nodes.forEach((node, j) => { node.style.visibility = j < n ? '' : 'hidden' })
|
|
87
|
+
if (d.goal > d.hi) { d.goal = d.hi; run(d) }
|
|
88
|
+
}
|
|
89
|
+
const snap = (w, x) => Math.round(clamp(w, x) / H) * H
|
|
90
|
+
const tick = (w) => (t) => {
|
|
91
|
+
const dt = Math.min(0.032, (t - (w.last || t)) / 1000) || 0.016; w.last = t
|
|
92
|
+
for (let s = 0, n = Math.ceil(dt / 0.002), h = dt / n; s < n; s++) { w.vel += (-K * (w.pos - w.goal) - C * w.vel) * h; w.pos += w.vel * h }
|
|
93
|
+
if (Math.abs(w.pos - w.goal) < 0.05 && Math.abs(w.vel) < 2) { w.pos = w.goal; w.vel = 0; w.raf = 0; w.last = 0 } else w.raf = requestAnimationFrame(tick(w))
|
|
94
|
+
paint(w)
|
|
95
|
+
}
|
|
96
|
+
const run = (w) => { if (reduced) { w.pos = w.goal; w.vel = 0; paint(w) } else if (!w.raf) w.raf = requestAnimationFrame(tick(w)) }
|
|
97
|
+
const fling = (w, v) => { w.vel = v; w.goal = snap(w, w.pos + v * 0.2); run(w) }
|
|
98
|
+
const pull = (w, x) => { const c = clamp(w, x); w.pos = c + (x - c) * 0.3; paint(w) }
|
|
99
|
+
wheels.forEach((w) => {
|
|
100
|
+
w.col.addEventListener('pointerdown', (e) => {
|
|
101
|
+
cancelAnimationFrame(w.raf); w.raf = 0; w.last = 0; w.col.setPointerCapture(e.pointerId); w.col.classList.add('is-drag')
|
|
102
|
+
const r = el.getBoundingClientRect(); w.drag = { y: e.clientY, p: w.pos, k: r.height / el.offsetHeight || 1, moved: false, item: e.target.closest('.wh-item'), s: [[e.timeStamp, w.pos]] }
|
|
103
|
+
})
|
|
104
|
+
w.col.addEventListener('pointermove', (e) => {
|
|
105
|
+
if (!w.drag) return
|
|
106
|
+
const dy = (e.clientY - w.drag.y) / w.drag.k; if (Math.abs(dy) > 3) w.drag.moved = true
|
|
107
|
+
const raw = w.drag.p - dy; pull(w, raw); w.drag.s.push([e.timeStamp, raw])
|
|
108
|
+
while (w.drag.s.length > 2 && e.timeStamp - w.drag.s[0][0] > 80) w.drag.s.shift()
|
|
109
|
+
})
|
|
110
|
+
const end = (e) => {
|
|
111
|
+
if (!w.drag) return
|
|
112
|
+
const d = w.drag, s = d.s, a = s[0], b = s[s.length - 1]; w.drag = null; w.col.classList.remove('is-drag')
|
|
113
|
+
if (!d.moved) {
|
|
114
|
+
if (d.item) { w.goal = clamp(w, Number(d.item.dataset.i) * H); w.vel = 0; return run(w) }
|
|
115
|
+
}
|
|
116
|
+
const v = b[0] - a[0] > 8 && e.timeStamp - b[0] < 70 ? (b[1] - a[1]) / (b[0] - a[0]) * 1000 : 0
|
|
117
|
+
fling(w, Math.max(-2200, Math.min(2200, v)))
|
|
118
|
+
}
|
|
119
|
+
w.col.addEventListener('pointerup', end); w.col.addEventListener('pointercancel', end)
|
|
120
|
+
w.col.addEventListener('keydown', (e) => { const d = { ArrowDown: 1, ArrowUp: -1 }[e.key]; if (!d) return; e.preventDefault(); w.goal = snap(w, w.goal + d * H); w.vel = 0; run(w) })
|
|
121
|
+
paint(w)
|
|
122
|
+
})
|
|
123
|
+
let flashT = 0
|
|
124
|
+
ok.addEventListener('click', () => { clearTimeout(flashT); out.classList.add('is-flash'); flashT = setTimeout(() => out.classList.remove('is-flash'), 450) })
|
|
125
|
+
el.whSet = (arr) => { arr.forEach((idx, ci) => { const w = wheels[ci]; cancelAnimationFrame(w.raf); w.raf = 0; w.last = 0; w.vel = 0; w.pos = w.goal = clamp(w, idx * H); paint(w) }); syncOut() }
|
|
126
|
+
el.whGrab = (ci) => { const w = wheels[ci]; cancelAnimationFrame(w.raf); w.raf = 0; w.last = 0; w.vel = 0; w.drag0 = w.pos; w.col.classList.add('is-drag') }
|
|
127
|
+
el.whPull = (ci, dy) => pull(wheels[ci], wheels[ci].drag0 + dy)
|
|
128
|
+
el.whFling = (ci, v) => { wheels[ci].col.classList.remove('is-drag'); fling(wheels[ci], v) }
|
|
129
|
+
fitDays()
|
|
130
|
+
el.whFreeze = () => { clearTimeout(flashT); out.classList.remove('is-flash'); wheels.forEach((w) => { cancelAnimationFrame(w.raf); w.raf = 0; w.last = 0; w.vel = 0; w.col.classList.remove('is-drag'); w.pos = w.goal = snap(w, w.pos); paint(w) }); syncOut() }
|
|
131
|
+
syncOut()
|
|
132
|
+
})
|
|
133
|
+
})()
|
|
134
|
+
</script>
|
|
135
|
+
<script data-stage>
|
|
136
|
+
/* 演示舞台:每个组件都一样,只改 DEMO 那一段。组件按 340×212 设计,卡片小了整体等比缩小。 */
|
|
137
|
+
(() => {
|
|
138
|
+
const q = new URLSearchParams(location.search); const root = document.documentElement
|
|
139
|
+
root.dataset.theme = (q.get('theme') || (matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')) === 'dark' ? 'dark' : 'light'
|
|
140
|
+
const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
141
|
+
const el = document.querySelector('.stage-fit > [data-comp]')
|
|
142
|
+
// 桌面版里框常常先报 0 宽高、之后变大却不触发 resize:读到 0 不能记下来(会一直缩没),框变化和外层发消息时再算
|
|
143
|
+
const fit = () => { if (innerWidth > 0 && innerHeight > 0) root.style.setProperty('--fit', Math.min(1, innerWidth / 340, innerHeight / 212).toFixed(3)) }
|
|
144
|
+
fit(); addEventListener('resize', fit); addEventListener('load', fit); addEventListener('message', fit)
|
|
145
|
+
if (typeof ResizeObserver === 'function') new ResizeObserver(fit).observe(root)
|
|
146
|
+
let playing = !q.has('still'); let hovering = false; let timers = []
|
|
147
|
+
const later = (fn, ms) => timers.push(setTimeout(() => { if (playing && !hovering) fn() }, ms)) // 演示用的定时器:用户一来就全部作废
|
|
148
|
+
const stop = () => { timers.forEach(clearTimeout); timers = []; DEMO.stop() }
|
|
149
|
+
const go = (ms) => { stop(); if (playing && !hovering && !reduced) later(() => DEMO.loop(later), ms) }
|
|
150
|
+
// ===== 只改这一段 =====
|
|
151
|
+
let raf = 0, activeCol = -1
|
|
152
|
+
const flick = (ci, toIdx, ms) => {
|
|
153
|
+
const cur = Number(el.querySelectorAll('.wh-col')[ci].dataset.idx)
|
|
154
|
+
const dy = (toIdx - cur) * 34 / (1 + 400 / ms); const t0 = performance.now(); activeCol = ci; el.whGrab(ci)
|
|
155
|
+
const f = (t) => { const k = Math.min(1, (t - t0) / ms); el.whPull(ci, dy * k * k); if (k < 1) raf = requestAnimationFrame(f); else { activeCol = -1; el.whFling(ci, dy * 2 / ms * 1000) } }
|
|
156
|
+
raf = requestAnimationFrame(f)
|
|
157
|
+
}
|
|
158
|
+
const DEMO = {
|
|
159
|
+
settle () { el.whSet([5, 2, 11]) },
|
|
160
|
+
loop (later) {
|
|
161
|
+
later(() => flick(1, 5, 460), 400)
|
|
162
|
+
later(() => flick(2, 17, 500), 1700)
|
|
163
|
+
later(() => flick(1, 2, 440), 3200)
|
|
164
|
+
later(() => flick(2, 11, 460), 3900)
|
|
165
|
+
later(() => DEMO.loop(later), 5200)
|
|
166
|
+
},
|
|
167
|
+
stop () { cancelAnimationFrame(raf); raf = 0; activeCol = -1; el.whFreeze() },
|
|
168
|
+
}
|
|
169
|
+
// =====================
|
|
170
|
+
document.body.addEventListener('pointerenter', () => { hovering = true; stop() })
|
|
171
|
+
document.body.addEventListener('pointerleave', () => { hovering = false; go(1400) })
|
|
172
|
+
addEventListener('message', (e) => {
|
|
173
|
+
const d = e.data; if (!d || typeof d !== 'object') return
|
|
174
|
+
if (d.theme === 'light' || d.theme === 'dark') root.dataset.theme = d.theme
|
|
175
|
+
if (typeof d.ddpPlay === 'boolean') { playing = d.ddpPlay; root.classList.toggle('paused', !playing); if (playing) go(400); else stop() }
|
|
176
|
+
})
|
|
177
|
+
try { parent.postMessage({ ddpMotionReady: 1 }, '*') } catch (e) { /* 单独打开时没有外层 */ }
|
|
178
|
+
if (reduced || q.has('still')) DEMO.settle(); else go(600)
|
|
179
|
+
})()
|
|
180
|
+
</script>
|
|
181
|
+
</body>
|
|
182
|
+
</html>
|
|
@@ -60,8 +60,10 @@ body{display:grid;place-items:center;background:var(--color-bg);font-family:var(
|
|
|
60
60
|
root.dataset.theme = (q.get('theme') || (matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')) === 'dark' ? 'dark' : 'light'
|
|
61
61
|
const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
62
62
|
const el = document.querySelector('.stage-fit > [data-comp]')
|
|
63
|
-
|
|
64
|
-
fit()
|
|
63
|
+
// 桌面版里框常常先报 0 宽高、之后变大却不触发 resize:读到 0 不能记下来(会一直缩没),框变化和外层发消息时再算
|
|
64
|
+
const fit = () => { if (innerWidth > 0 && innerHeight > 0) root.style.setProperty('--fit', Math.min(1, innerWidth / 340, innerHeight / 212).toFixed(3)) }
|
|
65
|
+
fit(); addEventListener('resize', fit); addEventListener('load', fit); addEventListener('message', fit)
|
|
66
|
+
if (typeof ResizeObserver === 'function') new ResizeObserver(fit).observe(root)
|
|
65
67
|
let playing = !q.has('still'); let hovering = false; let timers = []
|
|
66
68
|
const later = (fn, ms) => timers.push(setTimeout(() => { if (playing && !hovering) fn() }, ms)) // 演示用的定时器:用户一来就全部作废
|
|
67
69
|
const stop = () => { timers.forEach(clearTimeout); timers = []; DEMO.stop() }
|
|
@@ -81,8 +81,10 @@ body{display:grid;place-items:center;background:var(--color-bg);font-family:var(
|
|
|
81
81
|
root.dataset.theme = (q.get('theme') || (matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')) === 'dark' ? 'dark' : 'light'
|
|
82
82
|
const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
83
83
|
const el = document.querySelector('.stage-fit > [data-comp]')
|
|
84
|
-
|
|
85
|
-
fit()
|
|
84
|
+
// 桌面版里框常常先报 0 宽高、之后变大却不触发 resize:读到 0 不能记下来(会一直缩没),框变化和外层发消息时再算
|
|
85
|
+
const fit = () => { if (innerWidth > 0 && innerHeight > 0) root.style.setProperty('--fit', Math.min(1, innerWidth / 340, innerHeight / 212).toFixed(3)) }
|
|
86
|
+
fit(); addEventListener('resize', fit); addEventListener('load', fit); addEventListener('message', fit)
|
|
87
|
+
if (typeof ResizeObserver === 'function') new ResizeObserver(fit).observe(root)
|
|
86
88
|
let playing = !q.has('still'); let hovering = false; let timers = []
|
|
87
89
|
const later = (fn, ms) => timers.push(setTimeout(() => { if (playing && !hovering) fn() }, ms)) // 演示用的定时器:用户一来就全部作废
|
|
88
90
|
const stop = () => { timers.forEach(clearTimeout); timers = []; DEMO.stop() }
|
|
@@ -0,0 +1,158 @@
|
|
|
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">{"id":"mp-cartbar","zh":"点单购物条","en":"Order Cart Bar","cat":"shop","desc":"底部悬浮点单购物条,点购物袋弹开已选清单并实时加减改总价","desc_en":"Floating order cart bar; tap the bag to open selected items and adjust totals live","needs":"js","play":"press","hint":"点开清单","hint_en":"Toggle bag","source":{"name":"TDesign 零售模板","url":"https://github.com/Tencent/tdesign-miniprogram-starter-retail/blob/main/pages/cart/components/cart-bar/index.wxss","license":"MIT","author":"2021-present TDesign"},"prompt":"点单底部购物条与已选清单:外框 296×168、圆角 18px。底部悬浮 42px 胶囊条改写自 TDesign 零售模板 cart-bar(左带 --color-danger 角标的购物袋图标、中间合计金额与已优惠提示、右 --color-primary「去结算」按钮)。点购物袋从下方 0.3s 滑出半屏已选清单并压暗背景,列出两道餐品与加减步进器,调数量实时联动角标和总价,支持清空与重新点开。","prompt_en":"Ordering cart bar with expandable bag sheet (296x168, 18px radius): floating 42px pill bar adapted from TDesign retail cart-bar with a --color-danger badged bag icon, live total and savings, and --color-primary Checkout pill. Tapping the bag dims the backdrop and slides up the selected items sheet over .3s with +/- steppers that recalculate count and total live."}</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
|
+
/* 点单购物条:底栏总价、优惠提示与去结算按钮层次改写自 TDesign 零售模板(MIT,© 2021-present TDesign,https://github.com/Tencent/tdesign-miniprogram-starter-retail)的 cart-bar;点开已选清单抽屉与步进联动为新做。
|
|
18
|
+
读 --color-surface / --color-text / --color-muted / --color-line / --color-primary / --color-danger */
|
|
19
|
+
.c-mp-cartbar{box-sizing:border-box;position:relative;width:296px;height:168px;border-radius:18px;overflow:hidden;background:var(--color-surface,#fff);box-shadow:0 0 0 .5px var(--color-line,rgba(0,0,0,.1)),0 2px 4px rgba(0,0,0,.05),0 14px 30px -14px rgba(0,0,0,.3);font-family:var(--font-sans,system-ui);-webkit-tap-highlight-color:transparent;color:var(--color-text,#141413)}
|
|
20
|
+
.c-mp-cartbar button{font:inherit;border:0;padding:0;background:none;color:inherit;cursor:pointer}
|
|
21
|
+
.c-mp-cartbar button:focus-visible{outline:2px solid var(--color-primary,#0a84ff);outline-offset:2px}
|
|
22
|
+
.c-mp-cartbar .cb-bg{position:absolute;inset:0;padding:12px 14px;display:grid;align-content:start;gap:9px}
|
|
23
|
+
.c-mp-cartbar .cb-sk{display:flex;align-items:center;gap:10px}
|
|
24
|
+
.c-mp-cartbar .cb-sk i{width:34px;height:34px;border-radius:9px;background:color-mix(in srgb,var(--color-text,#141413) 8%,transparent)}
|
|
25
|
+
.c-mp-cartbar .cb-sk div{flex:1;display:grid;gap:6px}
|
|
26
|
+
.c-mp-cartbar .cb-sk b{height:8px;width:62%;border-radius:4px;background:color-mix(in srgb,var(--color-text,#141413) 11%,transparent)}
|
|
27
|
+
.c-mp-cartbar .cb-sk span{height:6px;width:40%;border-radius:3px;background:color-mix(in srgb,var(--color-text,#141413) 7%,transparent)}
|
|
28
|
+
.c-mp-cartbar .cb-mask{position:absolute;inset:0;background:rgba(0,0,0,.38);opacity:0;pointer-events:none;transition:opacity .26s}
|
|
29
|
+
.c-mp-cartbar.is-open .cb-mask{opacity:1;pointer-events:auto}
|
|
30
|
+
.c-mp-cartbar .cb-sheet{position:absolute;left:0;right:0;bottom:46px;border-radius:14px 14px 0 0;background:var(--color-surface,#fff);box-shadow:0 -6px 18px rgba(0,0,0,.16);padding:6px 12px 7px;transform:translateY(115%);opacity:0;transition:transform .32s cubic-bezier(.3,1.2,.4,1),opacity .22s}
|
|
31
|
+
.c-mp-cartbar.is-open .cb-sheet{transform:none;opacity:1}
|
|
32
|
+
.c-mp-cartbar .cb-shd{display:flex;justify-content:space-between;align-items:center;padding-bottom:4px;border-bottom:.5px solid var(--color-line,rgba(0,0,0,.09));font-size:11px;color:var(--color-muted,#76756f)}
|
|
33
|
+
.c-mp-cartbar .cb-shd b{color:var(--color-text,#141413);font-weight:600}
|
|
34
|
+
.c-mp-cartbar .cb-clr{font-size:11px;color:var(--color-muted,#76756f)}
|
|
35
|
+
.c-mp-cartbar .cb-row{display:flex;align-items:center;gap:8px;padding:4.5px 0}
|
|
36
|
+
.c-mp-cartbar .cb-row+.cb-row{border-top:.5px solid var(--color-line,rgba(0,0,0,.07))}
|
|
37
|
+
.c-mp-cartbar .cb-info{flex:1;min-width:0;display:grid;gap:1px}
|
|
38
|
+
.c-mp-cartbar .cb-info strong{font-size:12px;line-height:14px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
39
|
+
.c-mp-cartbar .cb-info span{font-size:10px;line-height:12px;color:var(--color-muted,#76756f)}
|
|
40
|
+
.c-mp-cartbar .cb-p{font-size:12.5px;font-weight:700;color:var(--color-danger,#ff375f);font-variant-numeric:tabular-nums}
|
|
41
|
+
.c-mp-cartbar .cb-step{display:inline-flex;align-items:center;gap:4px}
|
|
42
|
+
.c-mp-cartbar .cb-step button{width:20px;height:20px;border-radius:50%;display:grid;place-items:center;font-size:14px;line-height:1;transition:transform .16s}
|
|
43
|
+
.c-mp-cartbar .cb-step button:active{transform:scale(.85)}
|
|
44
|
+
.c-mp-cartbar .cb-step [data-d="-1"]{box-shadow:inset 0 0 0 1px var(--color-line,rgba(0,0,0,.2));color:var(--color-text,#141413)}
|
|
45
|
+
.c-mp-cartbar .cb-step [data-d="1"]{background:var(--color-primary,#0a84ff);color:#fff}
|
|
46
|
+
.c-mp-cartbar .cb-step output{min-width:14px;text-align:center;font-size:12px;font-weight:600;font-variant-numeric:tabular-nums}
|
|
47
|
+
.c-mp-cartbar .cb-bar{position:absolute;left:8px;right:8px;bottom:7px;height:42px;padding:0 5px 0 6px;box-sizing:border-box;border-radius:21px;display:flex;align-items:center;gap:8px;background:#1c1c20;color:#fff;box-shadow:0 0 0 .5px rgba(255,255,255,.14),0 6px 16px -6px rgba(0,0,0,.45)}
|
|
48
|
+
.c-mp-cartbar .cb-bag{position:relative;flex:none;width:32px;height:32px;border-radius:50%;display:grid;place-items:center;background:var(--color-primary,#0a84ff);color:#fff;transition:transform .22s cubic-bezier(.3,1.6,.5,1)}
|
|
49
|
+
.c-mp-cartbar .cb-bag:active{transform:scale(.9)}
|
|
50
|
+
.c-mp-cartbar .cb-bag svg{width:16px;height:16px;fill:none;stroke:currentColor;stroke-width:1.9;stroke-linecap:round;stroke-linejoin:round}
|
|
51
|
+
.c-mp-cartbar .cb-bdg{position:absolute;top:-3px;right:-4px;min-width:16px;height:16px;padding:0 4px;box-sizing:border-box;border-radius:8px;display:grid;place-items:center;font-style:normal;font-size:10px;font-weight:700;color:#fff;background:var(--color-danger,#ff375f);font-variant-numeric:tabular-nums}
|
|
52
|
+
.c-mp-cartbar .cb-bag.is-pop .cb-bdg{animation:mp-cartbar-pop .38s cubic-bezier(.3,1.7,.5,1)}
|
|
53
|
+
.c-mp-cartbar .cb-sum{flex:1;min-width:0;display:grid;line-height:1.15;cursor:pointer}
|
|
54
|
+
.c-mp-cartbar .cb-sum strong{font-size:15px;font-weight:700;font-variant-numeric:tabular-nums}
|
|
55
|
+
.c-mp-cartbar .cb-sum span{font-size:9.5px;opacity:.75}
|
|
56
|
+
.c-mp-cartbar .cb-go{flex:none;height:32px;padding:0 14px;border-radius:16px;font-size:12px;font-weight:600;color:#fff;background:var(--color-primary,#0a84ff);transition:transform .18s,opacity .2s}
|
|
57
|
+
.c-mp-cartbar .cb-go:active{transform:scale(.94)}
|
|
58
|
+
@keyframes mp-cartbar-pop{0%{transform:scale(1)}45%{transform:scale(1.36)}100%{transform:scale(1)}}
|
|
59
|
+
@media (prefers-reduced-motion:reduce){.c-mp-cartbar *{animation:none!important;transition:none!important}}
|
|
60
|
+
</style>
|
|
61
|
+
</head>
|
|
62
|
+
<body>
|
|
63
|
+
<div class="stage-fit">
|
|
64
|
+
<div class="c-mp-cartbar is-open" data-comp="mp-cartbar">
|
|
65
|
+
<div class="cb-bg" aria-hidden="true">
|
|
66
|
+
<div class="cb-sk"><i></i><div><b></b><span></span></div></div>
|
|
67
|
+
<div class="cb-sk"><i></i><div><b></b><span></span></div></div>
|
|
68
|
+
<div class="cb-sk"><i></i><div><b></b><span></span></div></div>
|
|
69
|
+
</div>
|
|
70
|
+
<div class="cb-mask"></div>
|
|
71
|
+
<div class="cb-sheet" aria-label="已选商品清单">
|
|
72
|
+
<div class="cb-shd"><b>已选商品</b><button class="cb-clr" type="button">重置</button></div>
|
|
73
|
+
<div class="cb-row" data-price="18"><div class="cb-info"><strong>冷萃咖啡</strong><span>中杯 少冰</span></div><span class="cb-p">¥18</span><div class="cb-step"><button type="button" data-d="-1" aria-label="减一份">−</button><output>1</output><button type="button" data-d="1" aria-label="加一份">+</button></div></div>
|
|
74
|
+
<div class="cb-row" data-price="24"><div class="cb-info"><strong>芝士可颂</strong><span>原味 一枚</span></div><span class="cb-p">¥24</span><div class="cb-step"><button type="button" data-d="-1" aria-label="减一份">−</button><output>1</output><button type="button" data-d="1" aria-label="加一份">+</button></div></div>
|
|
75
|
+
</div>
|
|
76
|
+
<div class="cb-bar">
|
|
77
|
+
<button class="cb-bag" type="button" aria-label="展开已选清单"><svg viewBox="0 0 20 20" aria-hidden="true"><path d="M5 7h10l1 9.5H4zM7.2 7V5.5a2.8 2.8 0 0 1 5.6 0V7"/></svg><i class="cb-bdg">2</i></button>
|
|
78
|
+
<div class="cb-sum"><strong class="cb-tot">¥37</strong><span class="cb-sav">已优惠 ¥5</span></div>
|
|
79
|
+
<button class="cb-go" type="button">去结算</button>
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
<script data-comp>
|
|
84
|
+
/* 点单购物条:点购物袋或遮罩开关已选清单;步进器实时算件数与总价 */
|
|
85
|
+
(() => {
|
|
86
|
+
document.querySelectorAll('.c-mp-cartbar').forEach((el) => {
|
|
87
|
+
const rows = [...el.querySelectorAll('.cb-row')], bag = el.querySelector('.cb-bag'), bdg = el.querySelector('.cb-bdg')
|
|
88
|
+
const tot = el.querySelector('.cb-tot'), sav = el.querySelector('.cb-sav'), go = el.querySelector('.cb-go')
|
|
89
|
+
let nums = [1, 1], open = true
|
|
90
|
+
const paint = (pop) => {
|
|
91
|
+
let c = 0, sum = 0
|
|
92
|
+
rows.forEach((r, i) => {
|
|
93
|
+
r.querySelector('output').textContent = String(nums[i])
|
|
94
|
+
c += nums[i]; sum += nums[i] * Number(r.dataset.price)
|
|
95
|
+
})
|
|
96
|
+
bdg.textContent = String(c); tot.textContent = '¥' + (sum >= 30 ? sum - 5 : sum)
|
|
97
|
+
sav.textContent = sum >= 30 ? '已优惠 ¥5' : (sum > 0 ? '满 30 减 5' : '先选点吃的')
|
|
98
|
+
go.textContent = c > 0 ? '去结算' : '选好了'
|
|
99
|
+
el.classList.toggle('is-open', open)
|
|
100
|
+
if (pop) { bag.classList.remove('is-pop'); void bag.offsetWidth; bag.classList.add('is-pop') }
|
|
101
|
+
}
|
|
102
|
+
el.cbSet = (isOpen, arr) => { open = isOpen; if (arr) nums = arr.slice(); paint(true) }
|
|
103
|
+
el.addEventListener('click', (e) => {
|
|
104
|
+
if (e.target.closest('.cb-bag') || e.target.closest('.cb-sum')) { open = !open; paint(false); return }
|
|
105
|
+
if (e.target.classList.contains('cb-mask')) { open = false; paint(false); return }
|
|
106
|
+
if (e.target.closest('.cb-clr')) { nums = [1, 1]; paint(true); return }
|
|
107
|
+
const b = e.target.closest('[data-d]')
|
|
108
|
+
if (b) {
|
|
109
|
+
const i = rows.indexOf(b.closest('.cb-row'))
|
|
110
|
+
nums[i] = Math.max(0, Math.min(9, nums[i] + Number(b.dataset.d)))
|
|
111
|
+
paint(true)
|
|
112
|
+
} else if (e.target.closest('.cb-go')) { open = !open; paint(false) }
|
|
113
|
+
})
|
|
114
|
+
paint(false)
|
|
115
|
+
})
|
|
116
|
+
})()
|
|
117
|
+
</script>
|
|
118
|
+
<script data-stage>
|
|
119
|
+
/* 演示舞台:每个组件都一样,只改 DEMO 那一段。组件按 340×212 设计,卡片小了整体等比缩小。 */
|
|
120
|
+
(() => {
|
|
121
|
+
const q = new URLSearchParams(location.search); const root = document.documentElement
|
|
122
|
+
root.dataset.theme = (q.get('theme') || (matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')) === 'dark' ? 'dark' : 'light'
|
|
123
|
+
const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
124
|
+
const el = document.querySelector('.stage-fit > [data-comp]')
|
|
125
|
+
// 桌面版里框常常先报 0 宽高、之后变大却不触发 resize:读到 0 不能记下来(会一直缩没),框变化和外层发消息时再算
|
|
126
|
+
const fit = () => { if (innerWidth > 0 && innerHeight > 0) root.style.setProperty('--fit', Math.min(1, innerWidth / 340, innerHeight / 212).toFixed(3)) }
|
|
127
|
+
fit(); addEventListener('resize', fit); addEventListener('load', fit); addEventListener('message', fit)
|
|
128
|
+
if (typeof ResizeObserver === 'function') new ResizeObserver(fit).observe(root)
|
|
129
|
+
let playing = !q.has('still'); let hovering = false; let timers = []
|
|
130
|
+
const later = (fn, ms) => timers.push(setTimeout(() => { if (playing && !hovering) fn() }, ms)) // 演示用的定时器:用户一来就全部作废
|
|
131
|
+
const stop = () => { timers.forEach(clearTimeout); timers = []; DEMO.stop() }
|
|
132
|
+
const go = (ms) => { stop(); if (playing && !hovering && !reduced) later(() => DEMO.loop(later), ms) }
|
|
133
|
+
// ===== 只改这一段 =====
|
|
134
|
+
const DEMO = {
|
|
135
|
+
settle () { el.cbSet(true, [1, 1]) },
|
|
136
|
+
loop (later) {
|
|
137
|
+
el.cbSet(false, [1, 1])
|
|
138
|
+
later(() => el.cbSet(true, [1, 1]), 500)
|
|
139
|
+
later(() => el.cbSet(true, [2, 1]), 1100)
|
|
140
|
+
later(() => el.cbSet(false, [2, 1]), 2500)
|
|
141
|
+
later(() => DEMO.loop(later), 4200)
|
|
142
|
+
},
|
|
143
|
+
stop () {},
|
|
144
|
+
}
|
|
145
|
+
// =====================
|
|
146
|
+
document.body.addEventListener('pointerenter', () => { hovering = true; stop() })
|
|
147
|
+
document.body.addEventListener('pointerleave', () => { hovering = false; go(1400) })
|
|
148
|
+
addEventListener('message', (e) => {
|
|
149
|
+
const d = e.data; if (!d || typeof d !== 'object') return
|
|
150
|
+
if (d.theme === 'light' || d.theme === 'dark') root.dataset.theme = d.theme
|
|
151
|
+
if (typeof d.ddpPlay === 'boolean') { playing = d.ddpPlay; root.classList.toggle('paused', !playing); if (playing) go(400); else stop() }
|
|
152
|
+
})
|
|
153
|
+
try { parent.postMessage({ ddpMotionReady: 1 }, '*') } catch (e) { /* 单独打开时没有外层 */ }
|
|
154
|
+
if (reduced || q.has('still')) DEMO.settle(); else go(600)
|
|
155
|
+
})()
|
|
156
|
+
</script>
|
|
157
|
+
</body>
|
|
158
|
+
</html>
|
|
@@ -0,0 +1,121 @@
|
|
|
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">{"id":"mp-checkin","zh":"签到日历","en":"Check-in Strip","cat":"shop","desc":"七天连续签到条,点一下今天打勾亮起,连续天数往上滚一格","desc_en":"Seven-day check-in strip; tapping marks today done and rolls the streak up","needs":"css","play":"press","hint":"点签到","hint_en":"Check in","source":null,"prompt":"七天连续签到卡片,纯 CSS(label 包 checkbox):宽 298px、圆角 16px。顶部显示「已连续签到」和垂直滚动切换的 3→4 天数,右侧提示今日可得积分;中间 7 列圆角格,前 3 天带 --color-primary 对勾,第 4 天「今天」加描边高亮,第 7 天放 --color-warning 礼盒;底部「立即签到」主色按钮。点击后第 4 天弹亮成实心主色对勾,浮出 +10 提示,按钮变为 --color-success「今日已签到」。","prompt_en":"Seven-day check-in card in pure CSS (label + checkbox), 298px wide, 16px radius. Header displays a streak counter rolling vertically from 3 to 4 days plus a reward pill. Seven daily tiles show 3 done checkmarks, an outlined Today tile, and a Day 7 --color-warning gift. Tapping fills Today in --color-primary with a spring check, floats a +10 tag, and turns the CTA --color-success."}</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(checkbox 控制今日签到、连签天数滚轮与 +10 飘字)。读 --color-surface / --color-text / --color-muted / --color-line / --color-primary / --color-warning / --color-success */
|
|
18
|
+
.c-mp-checkin{box-sizing:border-box;position:relative;display:grid;gap:10px;width:298px;padding:11px 12px 12px;border-radius:16px;cursor:pointer;background:var(--color-surface,#fff);box-shadow:0 0 0 .5px var(--color-line,rgba(0,0,0,.1)),0 2px 4px rgba(0,0,0,.05),0 14px 30px -14px rgba(0,0,0,.3);font-family:var(--font-sans,system-ui);-webkit-tap-highlight-color:transparent;color:var(--color-text,#141413)}
|
|
19
|
+
.c-mp-checkin input{position:absolute;opacity:0;pointer-events:none}
|
|
20
|
+
.c-mp-checkin .ck-hd{display:flex;align-items:center;justify-content:space-between}
|
|
21
|
+
.c-mp-checkin .ck-streak{display:inline-flex;align-items:center;gap:4px;font-size:13px;font-weight:600}
|
|
22
|
+
.c-mp-checkin .ck-num{display:inline-block;height:18px;overflow:hidden;color:var(--color-primary,#0a84ff);font-size:16px;font-weight:700;line-height:18px;font-variant-numeric:tabular-nums}
|
|
23
|
+
.c-mp-checkin .ck-num i{display:block;font-style:normal;transition:transform .42s cubic-bezier(.3,1.5,.5,1)}
|
|
24
|
+
.c-mp-checkin input:checked~.ck-hd .ck-num i{transform:translateY(-18px)}
|
|
25
|
+
.c-mp-checkin .ck-sub{position:relative;padding:2px 8px;border-radius:9px;font-size:10.5px;font-weight:600;color:color-mix(in srgb,var(--color-warning,#ffb340) 68%,var(--color-text,#141413));background:color-mix(in srgb,var(--color-warning,#ffb340) 18%,transparent)}
|
|
26
|
+
.c-mp-checkin .ck-sub::after{content:"今日 +10 分"}
|
|
27
|
+
.c-mp-checkin input:checked~.ck-hd .ck-sub{color:var(--color-success,#30b35a);background:color-mix(in srgb,var(--color-success,#30b35a) 15%,transparent)}
|
|
28
|
+
.c-mp-checkin input:checked~.ck-hd .ck-sub::after{content:"已领 +10 分"}
|
|
29
|
+
.c-mp-checkin .ck-grid{display:grid;grid-template-columns:repeat(7,1fr);gap:5px}
|
|
30
|
+
.c-mp-checkin .ck-day{position:relative;height:56px;border-radius:10px;display:grid;place-content:center;justify-items:center;gap:4px;background:color-mix(in srgb,var(--color-text,#141413) 5%,transparent);transition:background-color .24s,box-shadow .24s,transform .36s cubic-bezier(.3,1.6,.5,1)}
|
|
31
|
+
.c-mp-checkin .ck-day b{font-size:10px;font-weight:600;color:var(--color-muted,#76756f);font-variant-numeric:tabular-nums}
|
|
32
|
+
.c-mp-checkin .ck-day small{font-size:9.5px;color:var(--color-muted,#76756f)}
|
|
33
|
+
.c-mp-checkin .ck-ico{width:22px;height:22px;border-radius:50%;display:grid;place-items:center;font-size:9.5px;font-weight:700;background:color-mix(in srgb,var(--color-text,#141413) 7%,transparent);color:var(--color-muted,#76756f);transition:background-color .24s,color .24s,transform .4s cubic-bezier(.3,1.7,.5,1)}
|
|
34
|
+
.c-mp-checkin .ck-ico svg{width:13px;height:13px;fill:none;stroke:currentColor;stroke-width:2.3;stroke-linecap:round;stroke-linejoin:round}
|
|
35
|
+
.c-mp-checkin .ck-day.is-done{background:color-mix(in srgb,var(--color-primary,#0a84ff) 11%,transparent)}
|
|
36
|
+
.c-mp-checkin .ck-day.is-done .ck-ico{background:var(--color-primary,#0a84ff);color:#fff}
|
|
37
|
+
.c-mp-checkin .ck-day.is-done small{color:var(--color-primary,#0a84ff)}
|
|
38
|
+
.c-mp-checkin .ck-day.is-today{box-shadow:inset 0 0 0 1.5px var(--color-primary,#0a84ff);background:color-mix(in srgb,var(--color-primary,#0a84ff) 8%,transparent)}
|
|
39
|
+
.c-mp-checkin .ck-day.is-today .ck-ico{background:color-mix(in srgb,var(--color-primary,#0a84ff) 16%,transparent);color:var(--color-primary,#0a84ff)}
|
|
40
|
+
.c-mp-checkin .ck-day.is-today small{color:var(--color-primary,#0a84ff);font-weight:600}
|
|
41
|
+
.c-mp-checkin .ck-day.is-today .ck-chk{display:none}
|
|
42
|
+
.c-mp-checkin .ck-day.is-gift{background:color-mix(in srgb,var(--color-warning,#ffb340) 14%,transparent)}
|
|
43
|
+
.c-mp-checkin .ck-day.is-gift .ck-ico{background:var(--color-warning,#ffb340);color:#fff}
|
|
44
|
+
.c-mp-checkin .ck-day.is-gift small{color:color-mix(in srgb,var(--color-warning,#ffb340) 68%,var(--color-text,#141413));font-weight:600}
|
|
45
|
+
.c-mp-checkin .ck-pop{position:absolute;top:-6px;font-size:10px;font-weight:700;color:var(--color-primary,#0a84ff);opacity:0;pointer-events:none}
|
|
46
|
+
.c-mp-checkin input:checked~.ck-grid .ck-day.is-today{background:var(--color-primary,#0a84ff);box-shadow:0 4px 12px -4px color-mix(in srgb,var(--color-primary,#0a84ff) 65%,transparent)}
|
|
47
|
+
.c-mp-checkin input:checked~.ck-grid .ck-day.is-today .ck-ico{background:#fff;color:var(--color-primary,#0a84ff);animation:mp-checkin-pop .45s cubic-bezier(.3,1.7,.5,1)}
|
|
48
|
+
.c-mp-checkin input:checked~.ck-grid .ck-day.is-today .ck-plus{display:none}
|
|
49
|
+
.c-mp-checkin input:checked~.ck-grid .ck-day.is-today .ck-chk{display:block}
|
|
50
|
+
.c-mp-checkin input:checked~.ck-grid .ck-day.is-today small{color:#fff}
|
|
51
|
+
.c-mp-checkin input:checked~.ck-grid .ck-day.is-today .ck-pop{animation:mp-checkin-fly .65s cubic-bezier(.2,.8,.3,1)}
|
|
52
|
+
.c-mp-checkin .ck-cta{height:32px;border-radius:16px;display:grid;place-items:center;font-size:12.5px;font-weight:600;color:#fff;background:var(--color-primary,#0a84ff);transition:background-color .24s,transform .18s}
|
|
53
|
+
.c-mp-checkin .ck-cta::after{content:"立即签到领 10 积分"}
|
|
54
|
+
.c-mp-checkin:active .ck-cta,.c-mp-checkin.is-press .ck-cta{transform:scale(.97)}
|
|
55
|
+
.c-mp-checkin input:checked~.ck-cta{background:var(--color-success,#30b35a)}
|
|
56
|
+
.c-mp-checkin input:checked~.ck-cta::after{content:"今日已签到 明天 +15 积分"}
|
|
57
|
+
.c-mp-checkin input:focus-visible~.ck-cta{outline:2px solid var(--color-primary,#0a84ff);outline-offset:2px}
|
|
58
|
+
@keyframes mp-checkin-pop{0%{transform:scale(.5)}65%{transform:scale(1.18)}100%{transform:scale(1)}}
|
|
59
|
+
@keyframes mp-checkin-fly{0%{opacity:0;transform:translateY(4px)}30%{opacity:1;transform:translateY(-6px)}100%{opacity:0;transform:translateY(-15px)}}
|
|
60
|
+
@media (prefers-reduced-motion:reduce){.c-mp-checkin *{animation:none!important;transition:none!important}}
|
|
61
|
+
</style>
|
|
62
|
+
</head>
|
|
63
|
+
<body>
|
|
64
|
+
<div class="stage-fit">
|
|
65
|
+
<label class="c-mp-checkin" data-comp="mp-checkin">
|
|
66
|
+
<input type="checkbox" checked aria-label="今日签到">
|
|
67
|
+
<span class="ck-hd"><span class="ck-streak">已连续签到<span class="ck-num"><i>3</i><i>4</i></span>天</span><span class="ck-sub"></span></span>
|
|
68
|
+
<span class="ck-grid">
|
|
69
|
+
<span class="ck-day is-done"><span class="ck-ico"><svg viewBox="0 0 16 16"><path d="M3.5 8.5 6.8 11.8 12.8 4.8"/></svg></span><small>1天</small></span>
|
|
70
|
+
<span class="ck-day is-done"><span class="ck-ico"><svg viewBox="0 0 16 16"><path d="M3.5 8.5 6.8 11.8 12.8 4.8"/></svg></span><small>2天</small></span>
|
|
71
|
+
<span class="ck-day is-done"><span class="ck-ico"><svg viewBox="0 0 16 16"><path d="M3.5 8.5 6.8 11.8 12.8 4.8"/></svg></span><small>3天</small></span>
|
|
72
|
+
<span class="ck-day is-today"><span class="ck-pop">+10</span><span class="ck-ico"><b class="ck-plus">+10</b><svg class="ck-chk" viewBox="0 0 16 16"><path d="M3.5 8.5 6.8 11.8 12.8 4.8"/></svg></span><small>今天</small></span>
|
|
73
|
+
<span class="ck-day"><span class="ck-ico">+15</span><small>5天</small></span>
|
|
74
|
+
<span class="ck-day"><span class="ck-ico">+15</span><small>6天</small></span>
|
|
75
|
+
<span class="ck-day is-gift"><span class="ck-ico"><svg viewBox="0 0 16 16"><rect x="3" y="7" width="10" height="6.5" rx="1"/><path d="M2.5 5h11v2h-11zM8 5v8.5M6 5c-1-1.5 0-2.5 2-1 2-1.5 3-.5 2 1"/></svg></span><small>礼盒</small></span>
|
|
76
|
+
</span>
|
|
77
|
+
<span class="ck-cta"></span>
|
|
78
|
+
</label>
|
|
79
|
+
</div>
|
|
80
|
+
<script data-stage>
|
|
81
|
+
/* 演示舞台:每个组件都一样,只改 DEMO 那一段。组件按 340×212 设计,卡片小了整体等比缩小。 */
|
|
82
|
+
(() => {
|
|
83
|
+
const q = new URLSearchParams(location.search); const root = document.documentElement
|
|
84
|
+
root.dataset.theme = (q.get('theme') || (matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')) === 'dark' ? 'dark' : 'light'
|
|
85
|
+
const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
86
|
+
const el = document.querySelector('.stage-fit > [data-comp]')
|
|
87
|
+
// 桌面版里框常常先报 0 宽高、之后变大却不触发 resize:读到 0 不能记下来(会一直缩没),框变化和外层发消息时再算
|
|
88
|
+
const fit = () => { if (innerWidth > 0 && innerHeight > 0) root.style.setProperty('--fit', Math.min(1, innerWidth / 340, innerHeight / 212).toFixed(3)) }
|
|
89
|
+
fit(); addEventListener('resize', fit); addEventListener('load', fit); addEventListener('message', fit)
|
|
90
|
+
if (typeof ResizeObserver === 'function') new ResizeObserver(fit).observe(root)
|
|
91
|
+
let playing = !q.has('still'); let hovering = false; let timers = []
|
|
92
|
+
const later = (fn, ms) => timers.push(setTimeout(() => { if (playing && !hovering) fn() }, ms)) // 演示用的定时器:用户一来就全部作废
|
|
93
|
+
const stop = () => { timers.forEach(clearTimeout); timers = []; DEMO.stop() }
|
|
94
|
+
const go = (ms) => { stop(); if (playing && !hovering && !reduced) later(() => DEMO.loop(later), ms) }
|
|
95
|
+
// ===== 只改这一段 =====
|
|
96
|
+
const box = el.querySelector('input')
|
|
97
|
+
const tap = (later, to) => { el.classList.add('is-press'); later(() => { el.classList.remove('is-press'); box.checked = to }, 120) }
|
|
98
|
+
const DEMO = {
|
|
99
|
+
settle () { box.checked = true },
|
|
100
|
+
loop (later) {
|
|
101
|
+
box.checked = false
|
|
102
|
+
later(() => tap(later, true), 750)
|
|
103
|
+
later(() => tap(later, false), 2550)
|
|
104
|
+
later(() => DEMO.loop(later), 4000)
|
|
105
|
+
},
|
|
106
|
+
stop () { el.classList.remove('is-press') },
|
|
107
|
+
}
|
|
108
|
+
// =====================
|
|
109
|
+
document.body.addEventListener('pointerenter', () => { hovering = true; stop() })
|
|
110
|
+
document.body.addEventListener('pointerleave', () => { hovering = false; go(1400) })
|
|
111
|
+
addEventListener('message', (e) => {
|
|
112
|
+
const d = e.data; if (!d || typeof d !== 'object') return
|
|
113
|
+
if (d.theme === 'light' || d.theme === 'dark') root.dataset.theme = d.theme
|
|
114
|
+
if (typeof d.ddpPlay === 'boolean') { playing = d.ddpPlay; root.classList.toggle('paused', !playing); if (playing) go(400); else stop() }
|
|
115
|
+
})
|
|
116
|
+
try { parent.postMessage({ ddpMotionReady: 1 }, '*') } catch (e) { /* 单独打开时没有外层 */ }
|
|
117
|
+
if (reduced || q.has('still')) DEMO.settle(); else go(600)
|
|
118
|
+
})()
|
|
119
|
+
</script>
|
|
120
|
+
</body>
|
|
121
|
+
</html>
|