dsh-design-studio 1.0.2 → 1.2.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 -0
- package/README.md +2 -0
- package/lib/browser.js +4 -1
- package/lib/bundle.js +46 -0
- package/lib/canvthumb.js +5 -3
- package/lib/client.js +726 -90
- package/lib/core.js +7 -0
- package/lib/drift.js +222 -0
- package/lib/gallery/pack.js +4 -2
- package/lib/handoff.js +61 -0
- package/lib/htmlpack.js +146 -36
- package/lib/index.js +154 -18
- package/lib/look.js +28 -8
- package/lib/mock.js +793 -0
- package/lib/picker.js +142 -16
- package/lib/serve.js +47 -9
- package/lib/states.js +148 -0
- package/package.json +1 -1
- package/skills/ui-design/SKILL.md +19 -2
package/lib/htmlpack.js
CHANGED
|
@@ -12,8 +12,10 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import crypto from 'node:crypto'
|
|
15
|
-
import { bundle, strictMeta } from './bundle.js'
|
|
15
|
+
import { bundle, dataAssets, strictMeta } from './bundle.js'
|
|
16
16
|
import { defang } from './serve.js'
|
|
17
|
+
import { followsMock, statesOfHtml } from './states.js'
|
|
18
|
+
import { MOCK_FILE, mockExpr, mockOfBuf, mockRuntime } from './mock.js'
|
|
17
19
|
|
|
18
20
|
/** 每屏的 <base>:一个不存在的地址(.invalid 不会被解析),屏里的相对链接都落在它下面,小脚本据此认出「站内跳转」 */
|
|
19
21
|
export const PACK_ORIGIN = 'https://ddp-pack.invalid'
|
|
@@ -88,13 +90,16 @@ function storeShim(D) {
|
|
|
88
90
|
try { void window[name].length } catch { broken = true }
|
|
89
91
|
if (broken) { try { Object.defineProperty(window, name, { value: make(area), configurable: true }) } catch { /* 改不了就算了 */ } }
|
|
90
92
|
}
|
|
93
|
+
// 模拟数据(#30):自己做的屏(和播放器同源、有真的 localStorage)和别人做的屏(沙盒、只有替身)存的地方不一样,
|
|
94
|
+
// 换屏会读不到上一屏改的。演示里的模拟数据一律存播放器手上这一份
|
|
95
|
+
try { Object.defineProperty(window, '__ddpMockStore', { value: make('m'), configurable: true }) } catch { /* 改不了就算了 */ }
|
|
91
96
|
}
|
|
92
97
|
|
|
93
98
|
/**
|
|
94
99
|
* 每屏最前面(页面脚本跑之前就装好):点了跳到别的屏 → 告诉播放器换屏;页内锚点自己滚;站外链接开新标签页。
|
|
95
100
|
* 和 picker.js 里「试用 / 远程看」的拦法一样(LINK_SEL、LINK_JS 同一份);再加上调节滑块的值、不画滚动条
|
|
96
101
|
*/
|
|
97
|
-
function navScript(C) {
|
|
102
|
+
function navScript(C, ST) {
|
|
98
103
|
const SEL = C.sel
|
|
99
104
|
const JS = new RegExp(C.js)
|
|
100
105
|
const post = (m) => { try { parent.postMessage({ ddpPack: 1, ...m }, '*') } catch { /* 没有外层 */ } }
|
|
@@ -106,6 +111,21 @@ function navScript(C) {
|
|
|
106
111
|
const de = document.documentElement
|
|
107
112
|
for (const [k, v] of Object.entries((C.tweak && C.tweak.vars) || {})) { try { de.style.setProperty(k, String(v), 'important') } catch { /* 不认的值 */ } }
|
|
108
113
|
for (const [k, v] of Object.entries((C.tweak && C.tweak.attrs) || {})) { try { if (v == null || v === false) de.removeAttribute(k); else de.setAttribute(k, String(v)) } catch { /* 不认的名字 */ } }
|
|
114
|
+
// 一页多状态(#30):播放器放这一屏时给的状态(order.html?state=paid)写在 <html data-state> 上
|
|
115
|
+
const STATE_RE = /^[A-Za-z0-9_-]{1,32}$/
|
|
116
|
+
/** 这页 <meta name="dsh-states"> 里写了哪几个状态(不到两个当没写) */
|
|
117
|
+
const declared = () => {
|
|
118
|
+
const m = document.querySelector('meta[name=dsh-states]')
|
|
119
|
+
const out = []
|
|
120
|
+
for (const part of String((m && m.getAttribute('content')) || '').split(/[,,;;\n]+/)) {
|
|
121
|
+
const x = /^\s*([A-Za-z0-9_-]{1,32})/.exec(part)
|
|
122
|
+
if (x && !out.includes(x[1])) out.push(x[1])
|
|
123
|
+
}
|
|
124
|
+
return out.length >= 2 ? out : []
|
|
125
|
+
}
|
|
126
|
+
// 播放器只在这屏写了这个状态时才给(老页面自己拿 ?state= 当参数的给 '',完全不碰 data-state)
|
|
127
|
+
if (typeof ST === 'string' && STATE_RE.test(ST)) { de.setAttribute('data-state', ST); window.__dshState = ST } // 模拟数据认它:状态跟着数据走的页,这一屏临时当成这个状态
|
|
128
|
+
const stateOf = (u) => { const v = u.searchParams.get('state') || ''; return STATE_RE.test(v) ? v : '' }
|
|
109
129
|
|
|
110
130
|
/** 这个地址是不是跳到演示包里的别的屏:{ path, hash };同一页(只有锚点)给 { same, hash };站外给 { out } */
|
|
111
131
|
const where = (raw) => {
|
|
@@ -114,23 +134,38 @@ function navScript(C) {
|
|
|
114
134
|
let u
|
|
115
135
|
try { u = new URL(raw, document.baseURI) } catch { return null }
|
|
116
136
|
if (u.origin !== C.origin) return /^https?:$/.test(u.protocol) ? { out: u.href } : null
|
|
117
|
-
|
|
118
|
-
if (u.pathname === here().pathname) return { same: true, hash: u.hash || (/#$/.test(u.href) ? '#' : '') }
|
|
137
|
+
let state = stateOf(u)
|
|
119
138
|
let p = u.pathname
|
|
120
139
|
try { p = decodeURIComponent(p) } catch { /* 原样 */ }
|
|
121
|
-
|
|
140
|
+
// href="#"(「全部」)的 u.hash 是空串:记成 '#',和「同一页、没锚点」(导航栏里指着本页)分开。同一页换个状态(?state=paid)算跳
|
|
141
|
+
// 在别的状态里(地址带了状态进来的)点指着本页、不带状态也不带锚点的链接(href="order.html")= 回默认状态,也算跳
|
|
142
|
+
// 同一页换个这页没写的状态(老页面自己拿 ?state= 当参数):和以前一样当本页链接
|
|
143
|
+
const cur = de.getAttribute('data-state') || ''
|
|
144
|
+
const raw0 = state
|
|
145
|
+
if (u.pathname === here().pathname && state && !declared().includes(state)) state = ''
|
|
146
|
+
// 回默认状态只认什么参数都不带的(?page=2 是页面自己的参数);已经在默认状态(播放器给的 ST 是空的)就不用回
|
|
147
|
+
// 状态跟着模拟数据走的屏:播放器点名过状态(哪怕是第一个),不带状态的本页链接 = 去掉点名、回到跟着数据
|
|
148
|
+
const follow = !!document.querySelector('meta[name="dsh-states"][data-mock]')
|
|
149
|
+
const named = typeof ST === 'string' && ST && declared().includes(ST) && (follow || (ST === cur && ST !== declared()[0]))
|
|
150
|
+
if (u.pathname === here().pathname && (state ? state === cur : raw0 || u.search || u.hash || /#$/.test(u.href) || !named)) return { same: true, hash: u.hash || (/#$/.test(u.href) ? '#' : '') }
|
|
151
|
+
return { path: p, hash: u.hash, state }
|
|
122
152
|
}
|
|
123
153
|
const rawOf = (el) => {
|
|
124
154
|
let raw = el.getAttribute('href') || el.getAttribute('data-href') || el.getAttribute('data-to') || ''
|
|
125
155
|
if (!raw && el.hasAttribute('onclick')) { const m = JS.exec(el.getAttribute('onclick') || ''); if (m) raw = m[1] }
|
|
126
156
|
return raw
|
|
127
157
|
}
|
|
128
|
-
// 页内锚点:照常改这一页的 #(页面里按 # 换内容的写法照样能用);<base>
|
|
158
|
+
// 页内锚点:照常改这一页的 #(页面里按 # 换内容的写法照样能用);<base> 指着别处,不能让链接自己跳。
|
|
159
|
+
// 换掉当前这条浏览器历史、不多记(#30):演示包的历史只记换屏、换状态,「返回」一下就回上一屏(不然第一下只是清掉锚点)
|
|
160
|
+
const setHash = (hash) => {
|
|
161
|
+
try { location.replace(location.href.replace(/#.*$/, '') + (hash || '#')); return } catch { /* 换不了:照常改 # */ }
|
|
162
|
+
location.hash = hash
|
|
163
|
+
}
|
|
129
164
|
const jumpTo = (hash) => {
|
|
130
165
|
hash = String(hash || '')
|
|
131
|
-
if (hash && hash !== '#' && location.hash !== hash) {
|
|
166
|
+
if (hash && hash !== '#' && location.hash !== hash) { setHash(hash); return }
|
|
132
167
|
// 点过「待配送」#tab2 再点「全部」href="#":清掉旧的 #(按 hashchange 换内容的页面回到默认),浏览器自己滚回顶上
|
|
133
|
-
if (hash === '#' && location.hash) {
|
|
168
|
+
if (hash === '#' && location.hash) { setHash(''); return }
|
|
134
169
|
let id = hash.replace(/^#/, '')
|
|
135
170
|
try { id = decodeURIComponent(id) } catch { /* 原样 */ }
|
|
136
171
|
const t = id ? document.getElementById(id) || document.getElementsByName(id)[0] : null
|
|
@@ -146,10 +181,21 @@ function navScript(C) {
|
|
|
146
181
|
return true
|
|
147
182
|
}
|
|
148
183
|
if (w.same) { jumpTo(w.hash); return true }
|
|
149
|
-
post({ type: 'nav', path: w.path, hash: w.hash })
|
|
184
|
+
post({ type: 'nav', path: w.path, hash: w.hash, state: w.state || '' })
|
|
150
185
|
return true
|
|
151
186
|
}
|
|
152
187
|
|
|
188
|
+
// 返回(data-back):按看的人走过的路退一步,没得退(直接打开的这屏)才去它写的地方。点的那一下就拦(不等页面自己跳)
|
|
189
|
+
addEventListener('click', (e) => {
|
|
190
|
+
if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return
|
|
191
|
+
const el = e.target && e.target.closest ? e.target.closest('[data-back]') : null
|
|
192
|
+
if (!el) return
|
|
193
|
+
const w = where(rawOf(el))
|
|
194
|
+
e.preventDefault()
|
|
195
|
+
e.stopImmediatePropagation() // 同在 window 上的跳屏监听(别人做的屏、旧浏览器那条路)别再换一次
|
|
196
|
+
post({ type: 'nav', back: true, path: w && w.path ? w.path : '', hash: (w && w.hash) || '', state: (w && w.state) || '' })
|
|
197
|
+
}, true)
|
|
198
|
+
|
|
153
199
|
// 跳到别的屏、站外。自己做的屏(收得到 navigate):<a href> 让浏览器照常跳,下面的 navigate 按最终地址接住——
|
|
154
200
|
// 页面自己的点击处理先跑完(「去结算」先存购物车、点的时候才改 href),拦了默认行为就不跳,和真浏览器一样;
|
|
155
201
|
// 地址只写在 onclick 里的(onclick="if (!同意) {…; return} location.href='x'"),页面真跳了 navigate 也接住;
|
|
@@ -303,22 +349,30 @@ function player() {
|
|
|
303
349
|
if (!assets.has(i)) { const el = $('ddp-a-' + i); assets.set(i, el ? JSON.parse(el.textContent) : '') }
|
|
304
350
|
return assets.get(i)
|
|
305
351
|
}
|
|
306
|
-
const store = { l: {}, s: {} }
|
|
307
|
-
const htmlOf = (i) => {
|
|
352
|
+
const store = { l: {}, s: {}, m: {} }
|
|
353
|
+
const htmlOf = (i, state = '') => {
|
|
308
354
|
if (!cache.has(i)) {
|
|
309
355
|
cache.set(i, JSON.parse($('ddp-s-' + i).textContent).replace(assetRe, (m, n) => asset(Number(n))))
|
|
310
356
|
if (cache.size > 8) cache.delete(cache.keys().next().value) // 屏多、图大:只留最近放过的几屏
|
|
311
357
|
}
|
|
312
|
-
//
|
|
313
|
-
|
|
358
|
+
// 存储的初始内容:每次放进去都是当时的(上一屏刚存的这一屏读得到);状态(#30)也是放的时候才定
|
|
359
|
+
let out = cache.get(i).replace(C.storeMark, () => JSON.stringify(store).replace(/</g, '\\u003c'))
|
|
360
|
+
// 模拟数据(#30):整套只存一份,放进 iframe 时才填进这屏
|
|
361
|
+
const js = (v) => JSON.stringify(v).replace(/</g, '\\u003c').replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029')
|
|
362
|
+
if (C.mockMark) out = out.split(C.mockMark).join(js(C.mock || {}))
|
|
363
|
+
if (C.mockAMark) out = out.split(C.mockAMark).join(js(C.mockAssets || null))
|
|
364
|
+
const ok = /^[A-Za-z0-9_-]{1,32}$/.test(state) && (C.screens[i].states || []).includes(state) // 这屏写了的状态才设
|
|
365
|
+
return C.stateMark ? out.split(C.stateMark).join(JSON.stringify(ok ? state : '')) : out
|
|
314
366
|
}
|
|
315
367
|
let shell = !!C.shellDefault
|
|
316
368
|
// 看的人开关过外壳就记着(每份演示自己记:别的演示点过不影响这份导出时定的默认)
|
|
317
369
|
const SHELL_KEY = 'ddp-pack-shell-' + C.token // 每份演示自己记(直接双击打开的本地文件共用一份 localStorage)
|
|
318
370
|
try { const v = localStorage.getItem(SHELL_KEY); if (C.framed && (v === '1' || v === '0')) shell = v === '1' } catch { /* 存不了 */ }
|
|
319
371
|
let cur = -1
|
|
372
|
+
let curState = ''
|
|
320
373
|
let seq = 0
|
|
321
374
|
let pendingHash = ''
|
|
375
|
+
const trail = [] // 看的人在演示里走过的路(地址的 # 部分):返回(data-back)按它退一步
|
|
322
376
|
const stage = $('stage')
|
|
323
377
|
const bar = $('bar')
|
|
324
378
|
const sel = $('sel')
|
|
@@ -436,7 +490,7 @@ function player() {
|
|
|
436
490
|
}
|
|
437
491
|
|
|
438
492
|
/** 放一屏:新 iframe 在后面载好了再换上来(不白一下) */
|
|
439
|
-
function show(i, hash = '') {
|
|
493
|
+
function show(i, hash = '', state = '') {
|
|
440
494
|
const me = ++seq
|
|
441
495
|
const s = C.screens[i]
|
|
442
496
|
const fr = document.createElement('iframe')
|
|
@@ -457,20 +511,38 @@ function player() {
|
|
|
457
511
|
}
|
|
458
512
|
fr.addEventListener('load', swap)
|
|
459
513
|
setTimeout(swap, 2500) // 页面里有载不完的东西:别一直等
|
|
460
|
-
fr.srcdoc = htmlOf(i)
|
|
514
|
+
fr.srcdoc = htmlOf(i, state)
|
|
461
515
|
vp.appendChild(fr)
|
|
462
516
|
}
|
|
463
517
|
|
|
464
|
-
|
|
518
|
+
/** 地址的 # 部分 → 第几屏、哪个状态(#order.html?state=paid) */
|
|
519
|
+
const posOfHash = () => {
|
|
465
520
|
let h = ''
|
|
466
521
|
try { h = decodeURIComponent(location.hash.replace(/^#/, '')) } catch { h = '' }
|
|
467
|
-
const
|
|
468
|
-
|
|
522
|
+
const m = /^(.*)\?state=([A-Za-z0-9_-]{1,32})$/.exec(h)
|
|
523
|
+
const k = h ? C.screens.findIndex((s) => s.key === (m ? m[1] : h)) : -1
|
|
524
|
+
return k >= 0 ? { i: k, state: m ? normState(k, m[2]) : '' } : { i: 0, state: '' }
|
|
469
525
|
}
|
|
526
|
+
// 默认状态写不写都是同一屏(order.html 和 order.html?state=default):统一成不写,返回的路才对得上。
|
|
527
|
+
// 状态跟着模拟数据走的屏除外:不写是数据里那个,点名第一个要留着
|
|
528
|
+
const normState = (i, state) => (state && !(C.screens[i].states && C.screens[i].states[0] === state && !C.screens[i].follow) ? state : '')
|
|
529
|
+
const hashOf = (i, state) => '#' + encodeURIComponent(C.screens[i].key) + (normState(i, state) ? '?state=' + state : '')
|
|
530
|
+
// 走到第几步,记在这一条浏览器历史记录上:页面里的「返回」(data-back)有得退就是浏览器后退一步,
|
|
531
|
+
// 和浏览器自己的后退、前进是同一份路(后退再前进也对得上)。记不了的(沙盒不给改历史)照老办法按 trail 退
|
|
532
|
+
const depthOf = () => { try { const s = history.state; return s && typeof s.ddpPos === 'number' ? s.ddpPos : -1 } catch { return -1 } }
|
|
533
|
+
const tag = (n) => { try { history.replaceState({ ...(history.state && typeof history.state === 'object' ? history.state : {}), ddpPos: n }, ''); return depthOf() === n } catch { return false } }
|
|
534
|
+
let depth = Math.max(0, depthOf())
|
|
535
|
+
const tagged = tag(depth)
|
|
470
536
|
function render() {
|
|
471
|
-
const i =
|
|
472
|
-
if (
|
|
537
|
+
const { i, state } = posOfHash()
|
|
538
|
+
if (tagged) {
|
|
539
|
+
const n = depthOf()
|
|
540
|
+
if (n >= 0) depth = n // 浏览器后退 / 前进回到记过的那一步
|
|
541
|
+
else { depth += 1; tag(depth) } // 新走的一步
|
|
542
|
+
} else if (trail.length && trail[trail.length - 1] === hashOf(i, state)) trail.pop() // 浏览器后退回到了上一步
|
|
543
|
+
if (i === cur && state === curState && dev) return
|
|
473
544
|
cur = i
|
|
545
|
+
curState = state
|
|
474
546
|
sel.value = String(i)
|
|
475
547
|
count.textContent = T.of.replace('{i}', String(i + 1)).replace('{n}', String(N))
|
|
476
548
|
$('prev').disabled = i === 0
|
|
@@ -481,28 +553,35 @@ function player() {
|
|
|
481
553
|
decorate()
|
|
482
554
|
const hash = pendingHash
|
|
483
555
|
pendingHash = ''
|
|
484
|
-
show(i, hash)
|
|
556
|
+
show(i, hash, state)
|
|
485
557
|
}
|
|
486
558
|
/** 外框重搭(开关外壳、横竖屏换了):当前这屏重放 */
|
|
487
|
-
const rebuild = () => { build(); decorate(); show(cur) }
|
|
488
|
-
const go = (i, hash = '') => {
|
|
559
|
+
const rebuild = () => { build(); decorate(); show(cur, '', curState) }
|
|
560
|
+
const go = (i, hash = '', state = '') => {
|
|
489
561
|
if (i < 0 || i >= N) return
|
|
490
|
-
|
|
562
|
+
state = normState(i, state)
|
|
563
|
+
if (i === cur && state === curState) { if (hash) { const fr = vp && [...vp.querySelectorAll('iframe:not(.nx)')].pop(); if (fr) fr.contentWindow.postMessage({ ddpPack: 1, type: 'jump', hash }, '*') } return }
|
|
564
|
+
if (cur >= 0) { trail.push(hashOf(cur, curState)); if (trail.length > 30) trail.shift() }
|
|
491
565
|
pendingHash = hash
|
|
492
|
-
location.hash =
|
|
566
|
+
location.hash = hashOf(i, state)
|
|
493
567
|
}
|
|
494
568
|
const keyOf = (p) => { let k = String(p || '').replace(/^\/+/, ''); if (!k || k.endsWith('/')) k += 'index.html'; return k }
|
|
495
569
|
|
|
496
570
|
addEventListener('message', (e) => {
|
|
497
571
|
const d = e.data
|
|
498
572
|
if (!d || d.ddpPack !== 1 || !vp || ![...vp.querySelectorAll('iframe')].some((f) => f.contentWindow === e.source)) return
|
|
499
|
-
if (d.type === 'nav') {
|
|
573
|
+
if (d.type === 'nav' && d.back === true && (tagged ? depth > 0 : trail.length)) {
|
|
574
|
+
if (tagged) history.back()
|
|
575
|
+
else location.hash = trail.pop()
|
|
576
|
+
} else if (d.type === 'nav' && d.back === true && !d.path) {
|
|
577
|
+
// 没得退、也没写去哪:不动
|
|
578
|
+
} else if (d.type === 'nav') {
|
|
500
579
|
const k = keyOf(d.path)
|
|
501
580
|
let i = C.screens.findIndex((s) => s.key === k)
|
|
502
581
|
if (i < 0) i = C.screens.findIndex((s) => s.key === k + '.html')
|
|
503
582
|
if (i < 0) say(T.notIn.replace('{p}', k))
|
|
504
|
-
else go(i, typeof d.hash === 'string' ? d.hash : '')
|
|
505
|
-
} else if (d.type === 'store' && (d.area === 'l' || d.area === 's')) {
|
|
583
|
+
else go(i, typeof d.hash === 'string' ? d.hash : '', typeof d.state === 'string' && /^[A-Za-z0-9_-]{1,32}$/.test(d.state) ? d.state : '')
|
|
584
|
+
} else if (d.type === 'store' && (d.area === 'l' || d.area === 's' || d.area === 'm')) {
|
|
506
585
|
const m = store[d.area]
|
|
507
586
|
if (d.op === 'set') m[String(d.k)] = String(d.v)
|
|
508
587
|
else if (d.op === 'del') delete m[String(d.k)]
|
|
@@ -530,6 +609,20 @@ function player() {
|
|
|
530
609
|
else document.documentElement.requestFullscreen().catch(() => {})
|
|
531
610
|
})
|
|
532
611
|
$('menu').addEventListener('click', () => document.body.classList.toggle('open'))
|
|
612
|
+
// 重置演示数据(有模拟数据才有这个按钮):演示里点过、填过的都回到开始,当前这屏重放一遍
|
|
613
|
+
if (C.mockMark) {
|
|
614
|
+
const rs = $('mreset')
|
|
615
|
+
rs.hidden = false
|
|
616
|
+
rs.addEventListener('click', () => {
|
|
617
|
+
const pfx = 'dsh-mock:' + C.mockScope + ':'
|
|
618
|
+
try { for (let i = localStorage.length - 1; i >= 0; i--) { const k = localStorage.key(i); if (k && k.startsWith(pfx)) localStorage.removeItem(k) } } catch { /* 存不了 */ }
|
|
619
|
+
for (const k of Object.keys(store.l)) if (k.startsWith(pfx)) delete store.l[k]
|
|
620
|
+
store.m = {}
|
|
621
|
+
document.body.classList.remove('open')
|
|
622
|
+
if (cur >= 0) show(cur, '', curState)
|
|
623
|
+
say(T.resetDone)
|
|
624
|
+
})
|
|
625
|
+
}
|
|
533
626
|
document.addEventListener('fullscreenchange', () => { $('full').textContent = document.fullscreenElement ? T.exitFull : T.full })
|
|
534
627
|
let wasCompact = compact()
|
|
535
628
|
addEventListener('resize', () => {
|
|
@@ -541,8 +634,8 @@ function player() {
|
|
|
541
634
|
}
|
|
542
635
|
|
|
543
636
|
const STRINGS = {
|
|
544
|
-
zh: { prev: '上一屏', next: '下一屏', shell: '外壳', shellTip: '套上手机 / 浏览器外壳', full: '全屏', exitFull: '退出全屏', of: '{i} / {n}', notIn: '这一屏不在演示里:{p}', menu: '换屏', screens: '选屏' },
|
|
545
|
-
en: { prev: 'Previous', next: 'Next', shell: 'Device frame', shellTip: 'Show the phone / browser frame', full: 'Full screen', exitFull: 'Exit full screen', of: '{i} / {n}', notIn: 'This screen isn\'t in the demo: {p}', menu: 'Screens', screens: 'Pick a screen' },
|
|
637
|
+
zh: { prev: '上一屏', next: '下一屏', shell: '外壳', shellTip: '套上手机 / 浏览器外壳', full: '全屏', exitFull: '退出全屏', of: '{i} / {n}', notIn: '这一屏不在演示里:{p}', menu: '换屏', screens: '选屏', reset: '重置数据', resetTip: '演示里点过、填过的都回到开始', resetDone: '数据回到开始了' },
|
|
638
|
+
en: { prev: 'Previous', next: 'Next', shell: 'Device frame', shellTip: 'Show the phone / browser frame', full: 'Full screen', exitFull: 'Exit full screen', of: '{i} / {n}', notIn: 'This screen isn\'t in the demo: {p}', menu: 'Screens', screens: 'Pick a screen', reset: 'Reset data', resetTip: 'Undo everything tapped and typed in this demo', resetDone: 'Data is back to the start' },
|
|
546
639
|
}
|
|
547
640
|
|
|
548
641
|
const CSS = `
|
|
@@ -617,7 +710,7 @@ body.compact #menu{display:block;position:fixed;left:50%;top:calc(4px + env(safe
|
|
|
617
710
|
* read(rel):设计目录里的文件(Buffer,读不到 null);strictOf(page):这屏是不是别人做的(加硬规矩:只跑我们的脚本)
|
|
618
711
|
* 回 { html, missing: [没读到的屏], count }
|
|
619
712
|
*/
|
|
620
|
-
export function buildPack({ screens, read, strictOf = () => false, kind, w, h, os = '', dark = false, scheme = 'light', tweak = null, title = '', lang = 'zh', fit = false }) {
|
|
713
|
+
export function buildPack({ screens, read, bigOf = null, strictOf = () => false, kind, w, h, os = '', dark = false, scheme = 'light', tweak = null, title = '', lang = 'zh', fit = false }) {
|
|
621
714
|
kind = FRAME[kind] ? kind : 'web'
|
|
622
715
|
const S = STRINGS[lang === 'en' ? 'en' : 'zh']
|
|
623
716
|
const token = 'ddpA' + crypto.randomBytes(5).toString('hex') + '_'
|
|
@@ -626,7 +719,21 @@ export function buildPack({ screens, read, strictOf = () => false, kind, w, h, o
|
|
|
626
719
|
const navCfg = { origin: PACK_ORIGIN, sel: LINK_SEL, js: LINK_JS.source, pages: !!FIXED[kind], tweak: tweak && typeof tweak === 'object' ? { vars: tweak.vars || {}, attrs: tweak.attrs || {} } : null }
|
|
627
720
|
const script = (src, strict) => `<script${strict ? ` nonce="${nonce}"` : ''}>${src.replace(/<\/(script)/gi, '<\\/$1').replace(/<!--/g, '<\\!--')}</script>`
|
|
628
721
|
const shimSrc = `(${storeShim})(${storeMark});`
|
|
629
|
-
const
|
|
722
|
+
const stateMark = `/*ddpT${token}*/''` // 放一屏时换成这屏的状态(#30)
|
|
723
|
+
const navSrc = (strict) => `(${navScript})(${JSON.stringify({ ...navCfg, strict })}, ${stateMark});`
|
|
724
|
+
// 模拟数据(#30):设计目录里有 mock.json 就每屏放运行时(在存储替身后面、跳屏监听前面:点了又改数据又跳屏的先存好),
|
|
725
|
+
// 数据本身整套只放一份在播放器的配置里,放一屏时填进记号那里
|
|
726
|
+
const mk = mockOfBuf(read(MOCK_FILE), !!(bigOf && bigOf(MOCK_FILE)))
|
|
727
|
+
// mock.json 太大没读:导出来的演示点了不会变——报错不导出(不悄悄给一个丢了数据的演示)
|
|
728
|
+
if (mk && /^big/.test(mk.fp)) { const e = new Error('mockTooBig'); e.code = 'mockTooBig'; throw e }
|
|
729
|
+
const mockMark = mk ? `/*ddpM${token}*/null` : ''
|
|
730
|
+
const mockScope = token.slice(0, -1)
|
|
731
|
+
const mockAMark = mk ? `/*ddpMA${token}*/null` : ''
|
|
732
|
+
const mockSrc = mk ? `(${mockRuntime})(${mockExpr},${JSON.stringify({ v: mk.fp, scope: mockScope, err: mk.err })},${mockMark},${mockAMark});` : ''
|
|
733
|
+
// 数据里写的本地图片(头像、商品图):演示是单个文件,没有设计目录可读——换成 data: 地址的表,整套只放一份
|
|
734
|
+
const mockOver = []
|
|
735
|
+
const mockAssets = mk ? dataAssets(mk.data, read, 60 * 1024 * 1024, mockOver, bigOf) : null
|
|
736
|
+
if (mockOver.length) { const e = new Error('imgTooBig'); e.code = 'imgTooBig'; throw e } // 数据里绑的图换不下:不悄悄留成坏图
|
|
630
737
|
const mode = dark ? 'dark' : scheme === 'dark' ? 'media' : 'light'
|
|
631
738
|
const schemeSrc = `(${schemeScript})(${JSON.stringify(mode)});`
|
|
632
739
|
|
|
@@ -635,7 +742,7 @@ export function buildPack({ screens, read, strictOf = () => false, kind, w, h, o
|
|
|
635
742
|
const parts = []
|
|
636
743
|
const list = []
|
|
637
744
|
const missing = []
|
|
638
|
-
let total = 0
|
|
745
|
+
let total = mk ? JSON.stringify(mk.data).length + JSON.stringify(mockAssets).length : 0
|
|
639
746
|
for (const s of screens.slice(0, PACK_SCREENS)) {
|
|
640
747
|
const page = read(s.key)
|
|
641
748
|
if (!page) { missing.push(s.key); continue }
|
|
@@ -646,7 +753,7 @@ export function buildPack({ screens, read, strictOf = () => false, kind, w, h, o
|
|
|
646
753
|
key: s.key,
|
|
647
754
|
read,
|
|
648
755
|
base,
|
|
649
|
-
lead: (strict ? strictMeta(nonce) : '') + script(shimSrc + navSrc(strict), strict),
|
|
756
|
+
lead: (strict ? strictMeta(nonce) : '') + script(shimSrc + mockSrc + navSrc(strict), strict),
|
|
650
757
|
tail: script(schemeSrc, strict),
|
|
651
758
|
})
|
|
652
759
|
// 大的 data: 地址(图片、字体、脚本)挪出来单独存,几屏共用的只存一份
|
|
@@ -659,7 +766,8 @@ export function buildPack({ screens, read, strictOf = () => false, kind, w, h, o
|
|
|
659
766
|
total += out.length
|
|
660
767
|
if (total > PACK_MAX) { const e = new Error('tooBig'); e.code = 'tooBig'; throw e }
|
|
661
768
|
parts.push(`<script type="application/json" id="ddp-s-${list.length}">${jsonTag(out)}</script>`)
|
|
662
|
-
|
|
769
|
+
const states = statesOfHtml(text).map((x) => x.name) // 这屏写了哪几个状态(#30):放这屏时只设写了的
|
|
770
|
+
list.push({ key: s.key, label: String(s.label || s.key).slice(0, 80), top: !!s.top, ...(strict ? { strict: true } : null), ...(states.length ? { states } : null), ...(states.length && mk && followsMock(text) ? { follow: true } : null) })
|
|
663
771
|
}
|
|
664
772
|
if (!list.length) { const e = new Error('noScreens'); e.code = 'noScreens'; throw e }
|
|
665
773
|
|
|
@@ -670,7 +778,8 @@ export function buildPack({ screens, read, strictOf = () => false, kind, w, h, o
|
|
|
670
778
|
framed: !!FRAMED[kind], fixed: !!FIXED[kind],
|
|
671
779
|
// 网页默认不套浏览器框(铺满窗口),右侧栏开着「按画幅显示」的照它套着;手机、平板、桌面软件默认套着
|
|
672
780
|
shellDefault: !!FRAMED[kind] && (kind !== 'web' || !!fit),
|
|
673
|
-
screens: list, token, storeMark, strings: S,
|
|
781
|
+
screens: list, token, storeMark, stateMark, strings: S,
|
|
782
|
+
...(mk ? { mockMark, mockAMark, mockScope, mock: mk.data, mockAssets } : null),
|
|
674
783
|
}
|
|
675
784
|
const docTitle = cfg.title || list[0].label
|
|
676
785
|
const html = '<!doctype html>\n'
|
|
@@ -682,6 +791,7 @@ export function buildPack({ screens, read, strictOf = () => false, kind, w, h, o
|
|
|
682
791
|
+ `<select id="sel" aria-label="${escHtml(S.screens)}"></select>`
|
|
683
792
|
+ `<button id="next" class="arw" type="button" title="${escHtml(S.next)} (→)" aria-label="${escHtml(S.next)}">›</button><span id="count"></span></div>`
|
|
684
793
|
+ `<div class="end"><button id="shell" type="button" aria-pressed="false" title="${escHtml(S.shellTip)}">${escHtml(S.shell)}</button>`
|
|
794
|
+
+ `<button id="mreset" type="button" hidden title="${escHtml(S.resetTip)}">${escHtml(S.reset)}</button>`
|
|
685
795
|
+ `<button id="full" type="button">${escHtml(S.full)}</button></div></header>`
|
|
686
796
|
+ `<main id="stage"></main><button id="menu" type="button" aria-label="${escHtml(S.menu)}">•••</button><div id="toast" role="status" hidden></div>`
|
|
687
797
|
+ `<script type="application/json" id="ddp-cfg">${jsonTag(cfg)}</script>`
|