dsh-design-studio 0.26.0 → 0.28.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.
@@ -0,0 +1,693 @@
1
+ /**
2
+ * 导出「整套 HTML 演示」(#26):所有屏打成一个 .html,发给别人双击就能在浏览器里看、点得动、带外壳。
3
+ * 不联网、不用 AI,几秒出来。
4
+ *
5
+ * 每屏用 bundle.js 打成一整份(样式、脚本、图片、图标雪碧图都内联,和远程看同一套),塞进播放器页面;
6
+ * 播放器只把正在看的那屏放进沙盒 iframe 的 srcdoc。几屏共用的大图(AI 示意图、字体)只存一份。
7
+ * 屏里的跳转(<a href="detail.html">、data-href、onclick="location.href=…"、脚本跳转)由每屏带的小脚本
8
+ * 告诉播放器换屏,和设计台里「试用」一样;站外链接开新标签页。
9
+ *
10
+ * 外壳的尺寸(FRAME / CAP / LIGHTS / WINBTN)和认跳转的写法(LINK_SEL / LINK_JS)和 client.js、picker.js 是同一份数,
11
+ * 测试里逐项比着,改一边另一边会报。
12
+ */
13
+
14
+ import crypto from 'node:crypto'
15
+ import { bundle, strictMeta } from './bundle.js'
16
+ import { defang } from './serve.js'
17
+
18
+ /** 每屏的 <base>:一个不存在的地址(.invalid 不会被解析),屏里的相对链接都落在它下面,小脚本据此认出「站内跳转」 */
19
+ export const PACK_ORIGIN = 'https://ddp-pack.invalid'
20
+ export const PACK_MAX = 150 * 1024 * 1024 // 整个文件的上限(字符数):再大浏览器打开就很慢了
21
+ export const PACK_SCREENS = 60 // 和画布的屏数上限一样
22
+ const ASSET_MIN = 2048 // 这么长以上的 data: 地址单独存一份(几屏共用的只存一次)
23
+
24
+ // ── 和 client.js 同一份数(测试比着)────────────────────────────────────────
25
+ export const FRAME = {
26
+ web: { pad: 0, top: 34, r: 10, ir: 0 },
27
+ app: { pad: 11, top: 0, r: 55, ir: 44, island: 11 },
28
+ miniprogram: { pad: 11, top: 0, r: 55, ir: 44, island: 11, capsule: 1 },
29
+ tablet: { pad: 14, top: 0, r: 34, ir: 21 },
30
+ desktop: { pad: 0, top: 0, r: 12, ir: 12, win: 1 },
31
+ poster: { pad: 0, top: 0, r: 6, ir: 6 },
32
+ slides: { pad: 0, top: 0, r: 8, ir: 8 },
33
+ email: { pad: 0, top: 0, r: 10, ir: 10 },
34
+ diagram: { pad: 0, top: 0, r: 8, ir: 8 },
35
+ dshplugin: { pad: 0, top: 0, r: 10, ir: 10 },
36
+ framed: { pad: 0, top: 0, r: 10, ir: 10 },
37
+ }
38
+ export const CAP = { top: 48, right: 7, w: 87, h: 32 }
39
+ export const LIGHTS = { x: 20, y: 20, d: 12, gap: 8 }
40
+ export const WINBTN = { w: 46, h: 32 }
41
+ /** 有外壳可开关的类型(手机、平板、桌面软件、网页浏览器框) */
42
+ export const FRAMED = { app: 1, miniprogram: 1, tablet: 1, desktop: 1, web: 1 }
43
+ /** 画幅定死的类型:放映时可以放大铺满(幻灯片、海报) */
44
+ export const FIXED = { poster: 1, slides: 1, diagram: 1, dshplugin: 1, framed: 1 }
45
+
46
+ // ── 和 picker.js 同一份(测试比着):哪些元素点了会跳页 ─────────────────────────
47
+ export const LINK_SEL = 'a[href], [data-href], [data-to], [onclick]'
48
+ export const LINK_JS = /(?:location(?:\.href)?\s*=\s*|location\.(?:assign|replace)\(\s*)['"]([^'"]+)['"]/
49
+
50
+ /** 某个大小的外框:矮的手机没有灵动岛(和 client.js 的 frameOf 一样) */
51
+ export function frameOf(kind, w, h) {
52
+ const f = FRAME[kind] || FRAME.web
53
+ return f.island && w && h / w < 1.9 ? { ...f, island: 0 } : f
54
+ }
55
+
56
+ /** JSON 放进 <script type="application/json">:< 和两个行分隔符转义,</script> 断不了它 */
57
+ const jsonTag = (v) => JSON.stringify(v).replace(/</g, '\\u003c').replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029')
58
+ const escHtml = (s) => String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;')
59
+
60
+ /**
61
+ * 每屏最前面:沙盒里的页面(不透明的源)一碰 localStorage / sessionStorage 就报错,
62
+ * 换成存在内存里的一份;存的东西告诉播放器,换到别的屏时带过去(登录页存的名字,下一屏读得到)。
63
+ * 初始内容由播放器在放进 iframe 前替换 STORE 那个记号
64
+ */
65
+ function storeShim(D) {
66
+ const send = (area, op, k, v) => { try { parent.postMessage({ ddpPack: 1, type: 'store', area, op, k, v }, '*') } catch { /* 没有外层 */ } }
67
+ const make = (area) => {
68
+ const m = new Map(Object.entries((D && D[area]) || {}))
69
+ const api = {
70
+ getItem: (k) => (m.has(String(k)) ? m.get(String(k)) : null),
71
+ setItem: (k, v) => { m.set(String(k), String(v)); send(area, 'set', String(k), String(v)) },
72
+ removeItem: (k) => { m.delete(String(k)); send(area, 'del', String(k)) },
73
+ clear: () => { m.clear(); send(area, 'clear') },
74
+ key: (i) => [...m.keys()][i] ?? null,
75
+ }
76
+ // localStorage.theme = 'dark'、localStorage.theme 这种写法也认
77
+ return new Proxy(api, {
78
+ get: (o, p) => (p === 'length' ? m.size : typeof p === 'symbol' || Object.hasOwn(o, p) ? o[p] : m.has(p) ? m.get(p) : undefined),
79
+ set: (o, p, v) => { if (typeof p === 'string') api.setItem(p, v); return true },
80
+ deleteProperty: (o, p) => { if (typeof p === 'string') api.removeItem(p); return true },
81
+ has: (o, p) => Object.hasOwn(o, p) || m.has(p),
82
+ ownKeys: () => [...m.keys()],
83
+ getOwnPropertyDescriptor: (o, p) => (m.has(p) ? { value: m.get(p), enumerable: true, configurable: true, writable: true } : undefined),
84
+ })
85
+ }
86
+ for (const [name, area] of [['localStorage', 'l'], ['sessionStorage', 's']]) {
87
+ let broken = false
88
+ try { void window[name].length } catch { broken = true }
89
+ if (broken) { try { Object.defineProperty(window, name, { value: make(area), configurable: true }) } catch { /* 改不了就算了 */ } }
90
+ }
91
+ }
92
+
93
+ /**
94
+ * 每屏最前面(页面脚本跑之前就装好):点了跳到别的屏 → 告诉播放器换屏;页内锚点自己滚;站外链接开新标签页。
95
+ * 和 picker.js 里「试用 / 远程看」的拦法一样(LINK_SEL、LINK_JS 同一份);再加上调节滑块的值、不画滚动条
96
+ */
97
+ function navScript(C) {
98
+ const SEL = C.sel
99
+ const JS = new RegExp(C.js)
100
+ const post = (m) => { try { parent.postMessage({ ddpPack: 1, ...m }, '*') } catch { /* 没有外层 */ } }
101
+ const here = () => new URL(document.baseURI)
102
+ const style = (css) => { const s = document.createElement('style'); s.textContent = css; (document.head || document.documentElement).appendChild(s) }
103
+ style('*{scrollbar-width:none}*::-webkit-scrollbar{display:none}')
104
+
105
+ // 调节滑块调过、还没存进文件的值(和 picker 的 applyTweak 一样写在 <html> 上)
106
+ const de = document.documentElement
107
+ for (const [k, v] of Object.entries((C.tweak && C.tweak.vars) || {})) { try { de.style.setProperty(k, String(v), 'important') } catch { /* 不认的值 */ } }
108
+ 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 { /* 不认的名字 */ } }
109
+
110
+ /** 这个地址是不是跳到演示包里的别的屏:{ path, hash };同一页(只有锚点)给 { same, hash };站外给 { out } */
111
+ const where = (raw) => {
112
+ raw = String(raw || '').trim()
113
+ if (!raw || /^(javascript|mailto|tel|sms|data|blob):/i.test(raw)) return null
114
+ let u
115
+ try { u = new URL(raw, document.baseURI) } catch { return null }
116
+ if (u.origin !== C.origin) return /^https?:$/.test(u.protocol) ? { out: u.href } : null
117
+ // href="#"(「全部」)的 u.hash 是空串:记成 '#',和「同一页、没锚点」(导航栏里指着本页)分开
118
+ if (u.pathname === here().pathname) return { same: true, hash: u.hash || (/#$/.test(u.href) ? '#' : '') }
119
+ let p = u.pathname
120
+ try { p = decodeURIComponent(p) } catch { /* 原样 */ }
121
+ return { path: p, hash: u.hash }
122
+ }
123
+ const rawOf = (el) => {
124
+ let raw = el.getAttribute('href') || el.getAttribute('data-href') || el.getAttribute('data-to') || ''
125
+ if (!raw && el.hasAttribute('onclick')) { const m = JS.exec(el.getAttribute('onclick') || ''); if (m) raw = m[1] }
126
+ return raw
127
+ }
128
+ // 页内锚点:照常改这一页的 #(页面里按 # 换内容的写法照样能用);<base> 指着别处,不能让链接自己跳
129
+ const jumpTo = (hash) => {
130
+ hash = String(hash || '')
131
+ if (hash && hash !== '#' && location.hash !== hash) { location.hash = hash; return }
132
+ // 点过「待配送」#tab2 再点「全部」href="#":清掉旧的 #(按 hashchange 换内容的页面回到默认),浏览器自己滚回顶上
133
+ if (hash === '#' && location.hash) { location.hash = ''; return }
134
+ let id = hash.replace(/^#/, '')
135
+ try { id = decodeURIComponent(id) } catch { /* 原样 */ }
136
+ const t = id ? document.getElementById(id) || document.getElementsByName(id)[0] : null
137
+ if (t) t.scrollIntoView({ block: 'start' })
138
+ else if (!id || id === 'top') scrollTo({ top: 0 })
139
+ }
140
+ const go = (w, e) => {
141
+ if (!w) return false
142
+ if (w.out) {
143
+ const a = e && e.target && e.target.closest ? e.target.closest('a[href]') : null
144
+ if (a && a.target && a.target !== '_self') return false // 本来就开新窗口:随它(沙盒放行了弹窗)
145
+ window.open(w.out, '_blank', 'noopener')
146
+ return true
147
+ }
148
+ if (w.same) { jumpTo(w.hash); return true }
149
+ post({ type: 'nav', path: w.path, hash: w.hash })
150
+ return true
151
+ }
152
+
153
+ // 跳到别的屏、站外。自己做的屏(收得到 navigate):<a href> 让浏览器照常跳,下面的 navigate 按最终地址接住——
154
+ // 页面自己的点击处理先跑完(「去结算」先存购物车、点的时候才改 href),拦了默认行为就不跳,和真浏览器一样;
155
+ // 地址只写在 onclick 里的(onclick="if (!同意) {…; return} location.href='x'"),页面真跳了 navigate 也接住;
156
+ // data-href / data-to 没有原生跳转:事件派发完(页面 stopPropagation 了也算)按那时的地址补一次。
157
+ // 收不到 navigate 的(别人做的屏不同源、很旧的浏览器):照设计台「试用」,点的那一下就拦(页面自己的点击处理就不跑了)
158
+ // 有 navigation 对象不等于发 navigate(文档源不透明时按规范不发,currentEntry 是 null):那种照老办法
159
+ const hasNav = !!(window.navigation && navigation.currentEntry && typeof navigation.addEventListener === 'function')
160
+ const early = !!C.strict || !hasNav
161
+ let pending = null
162
+ addEventListener('click', (e) => {
163
+ pending = null
164
+ // 冒泡那个排到页面在 window 上的点击监听后面(这一次点击里):页面「确定要离开吗」拦了,我们就不开外网
165
+ removeEventListener('click', after); addEventListener('click', after)
166
+ if (e.button !== 0) return
167
+ const el = e.target && e.target.closest ? e.target.closest(SEL) : null
168
+ if (!el) return
169
+ const a = el.closest('a[href], area[href]')
170
+ // 新窗口打开(target="_blank"、按着 ⌘ / Ctrl / Shift 点)指着包里别的屏:新窗口里开不了,还是在这儿换屏
171
+ const newWin = a && ((a.target && a.target !== '_self') || e.metaKey || e.ctrlKey || e.shiftKey)
172
+ if (!early && !newWin) {
173
+ if (a || (!el.getAttribute('data-href') && !el.getAttribute('data-to'))) return
174
+ // 只补「事件传到了 el」的:卡片(data-href)里的「收藏」按钮自己 stopPropagation,就是不想连带打开卡片
175
+ const mine = { el, e, reached: false }
176
+ const mark = () => { mine.reached = true }
177
+ el.addEventListener('click', mark, { once: true })
178
+ pending = mine
179
+ setTimeout(() => {
180
+ el.removeEventListener('click', mark)
181
+ if (pending === mine) { pending = null; if (mine.reached) finish(mine) }
182
+ }, 0)
183
+ return
184
+ }
185
+ const w = where(rawOf(el))
186
+ if (!w || w.same) return // 本页锚点(href="#"、"#tab2"):页面自己的点击处理照跑,见下面
187
+ if (w.out && (!a || newWin)) return // 外网:新窗口的随它开(沙盒放行了弹窗);data-href / onclick 指着外网的交给 navigate
188
+ if (go(w, e)) { e.preventDefault(); e.stopPropagation() }
189
+ }, true)
190
+ const finish = ({ el, e }) => {
191
+ if (e.defaultPrevented) return
192
+ const w = where(el.getAttribute('data-href') || el.getAttribute('data-to') || '')
193
+ if (!w || w.out) return // 外网:页面自己跳了由 navigate 接住
194
+ if (w.same) { if (w.hash && w.hash !== '#') jumpTo(w.hash); return } // data-href="#" 占位:不动
195
+ go(w, e)
196
+ }
197
+ // 页面自己处理完、没拦默认行为(每次点击都排到 window 上最后一个):
198
+ // 本页锚点(收不到 navigate 时)替它滚过去(<base> 指着别处,链接自己跳就离开这一屏了);收得到 navigate 的让浏览器照常跳,
199
+ // 由 navigate 按最终地址接住(href="#" 占位、点的时候页面才改成别的屏);
200
+ // 本页锚点要开新窗口的(页脚 <a href="#" target="_blank">、按着 ⌘ 点 #tab2):新窗口里是假地址,留在这儿滚
201
+ // 外网链接(没写 target)在点击里就开新标签页:放到 navigate 回调里开,Safari 可能当成弹窗拦掉
202
+ const after = (e) => {
203
+ if (e.defaultPrevented || e.button !== 0) return
204
+ const a = e.target && e.target.closest ? e.target.closest('a[href], area[href]') : null
205
+ const w = a ? where(a.getAttribute('href')) : null
206
+ if (!w) return
207
+ const newWin = (a.target && a.target !== '_self') || e.metaKey || e.ctrlKey || e.shiftKey
208
+ if (w.same && (early || newWin)) { e.preventDefault(); jumpTo(w.hash) }
209
+ else if (w.out && !early && !newWin) { e.preventDefault(); window.open(w.out, '_blank', 'noopener') }
210
+ }
211
+
212
+ // 脚本里跳页(location.href = 'x.html'、表单提交):有 Navigation API 的浏览器(Chrome、Edge、新的 Safari / Firefox)也拦下来
213
+ if (hasNav) {
214
+ navigation.addEventListener('navigate', (e) => {
215
+ if (!e.cancelable || e.navigationType === 'traverse' || e.downloadRequest) return
216
+ const dest = (e.destination && e.destination.url) || ''
217
+ // 没写 action 的表单(搜索框按回车)交给这一页自己(about:srcdoc?…):留在这一屏,不然这屏就没了
218
+ if (!e.hashChange && /^about:srcdoc/i.test(dest) && (e.formData || /^about:srcdoc\?/i.test(dest))) { e.preventDefault(); return }
219
+ const w = where(dest)
220
+ if (!w) return
221
+ e.preventDefault()
222
+ pending = null // 点击里页面自己跳了:冒泡那边不再换一次
223
+ if (w.out && e.formData) return // 往外网交表单:不交
224
+ go(w)
225
+ })
226
+ }
227
+
228
+ // 播放器让滚到某个锚点(从别的屏跳过来带着 #xx)
229
+ addEventListener('message', (e) => {
230
+ if (e.source !== parent) return
231
+ const d = e.data
232
+ if (d && d.ddpPack === 1 && d.type === 'jump') jumpTo(d.hash)
233
+ })
234
+
235
+ // ← → 换屏(点进页面以后键盘在页面里):页面自己没用、也不是在输入框里才交给播放器。
236
+ // PageUp / PageDown 在能滚的页面里是往下看:只有画幅定死的(幻灯片、海报…)才拿来换屏
237
+ const KEYS = C.pages ? /^(ArrowLeft|ArrowRight|PageUp|PageDown)$/ : /^(ArrowLeft|ArrowRight)$/
238
+ addEventListener('keydown', (e) => {
239
+ if (e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey || !KEYS.test(e.key)) return
240
+ const t = e.target
241
+ if (t && (t.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))) return
242
+ post({ type: 'key', key: e.key })
243
+ })
244
+ }
245
+
246
+ /**
247
+ * 每屏最后(样式表都读进来了):深浅色按导出那一刻右侧栏的样子定死,不跟看的人电脑的深浅色走。
248
+ * dark:右侧栏开着「深色」——和 picker 的 setDark 一样,<html> 上三种写法都打上,深色的媒体条件当成立
249
+ * media:没开「深色」,但右侧栏当时就是深色环境(页面跟着系统变深)——深色的媒体条件当成立
250
+ * light:浅色环境——浅色的当成立、深色的当不成立,对方电脑是深色也照浅色显示
251
+ * 只改媒体条件里 prefers-color-scheme 那一项(「深色且窄屏」这种别的条件照旧),样式的先后不动
252
+ */
253
+ function schemeScript(mode) {
254
+ const de = document.documentElement
255
+ if (mode === 'dark') {
256
+ de.setAttribute('data-theme', 'dark')
257
+ de.setAttribute('data-mode', 'dark')
258
+ de.classList.add('dark')
259
+ }
260
+ const dark = mode !== 'light'
261
+ const YES = '(min-width: 0px)'
262
+ const NO = '(min-width: 99999px)'
263
+ const fix = (ml) => {
264
+ try {
265
+ const t = ml && ml.mediaText
266
+ if (t && /prefers-color-scheme/i.test(t)) ml.mediaText = t.replace(/\(\s*prefers-color-scheme\s*:\s*(dark|light)\s*\)/gi, (m, v) => ((v.toLowerCase() === 'dark') === dark ? YES : NO))
267
+ } catch { /* 改不了 */ }
268
+ }
269
+ const walk = (list) => {
270
+ for (const r of list) {
271
+ if (r.media) fix(r.media)
272
+ if (r.cssRules) { try { walk(r.cssRules) } catch { /* 读不了 */ } }
273
+ }
274
+ }
275
+ for (const sh of document.styleSheets) {
276
+ fix(sh.media) // <style media="(prefers-color-scheme: dark)">
277
+ try { walk(sh.cssRules) } catch { /* 读不了 */ }
278
+ }
279
+ // 表单控件、滚动区的底色:开着「深色」、浅色环境都定死;深色环境只在页面自己声明了支持深色时定
280
+ let cs = mode === 'light' ? 'light' : mode === 'dark' ? 'dark' : ''
281
+ // 页面自己声明的:CSS 的 color-scheme,没写(normal)再看 <meta name="color-scheme">
282
+ let own = getComputedStyle(de).colorScheme || ''
283
+ if (!own || own === 'normal') { const m = document.querySelector('meta[name="color-scheme" i]'); own = (m && m.getAttribute('content')) || '' }
284
+ if (mode === 'media' && /dark/.test(own)) cs = 'dark'
285
+ if (mode === 'light' && /dark/.test(own) && !/light/.test(own)) cs = '' // 页面只做了深色(color-scheme: dark):控件照它的深色
286
+ if (cs) {
287
+ const s = document.createElement('style')
288
+ s.textContent = `:root{color-scheme:${cs}}`
289
+ ;(document.head || de).appendChild(s)
290
+ }
291
+ }
292
+
293
+ /** 播放器(外面那层):换屏、外壳、缩放、全屏;数据都在页面里的 JSON 里 */
294
+ function player() {
295
+ const $ = (id) => document.getElementById(id)
296
+ const C = JSON.parse($('ddp-cfg').textContent)
297
+ const T = C.strings
298
+ const N = C.screens.length
299
+ const cache = new Map()
300
+ const assetRe = new RegExp(C.token + '(\\d+)_', 'g')
301
+ const assets = new Map()
302
+ const asset = (i) => {
303
+ if (!assets.has(i)) { const el = $('ddp-a-' + i); assets.set(i, el ? JSON.parse(el.textContent) : '') }
304
+ return assets.get(i)
305
+ }
306
+ const store = { l: {}, s: {} }
307
+ const htmlOf = (i) => {
308
+ if (!cache.has(i)) {
309
+ cache.set(i, JSON.parse($('ddp-s-' + i).textContent).replace(assetRe, (m, n) => asset(Number(n))))
310
+ if (cache.size > 8) cache.delete(cache.keys().next().value) // 屏多、图大:只留最近放过的几屏
311
+ }
312
+ // 存储的初始内容:每次放进去都是当时的(上一屏刚存的这一屏读得到)
313
+ return cache.get(i).replace(C.storeMark, () => JSON.stringify(store).replace(/</g, '\\u003c'))
314
+ }
315
+ let shell = !!C.shellDefault
316
+ // 看的人开关过外壳就记着(每份演示自己记:别的演示点过不影响这份导出时定的默认)
317
+ const SHELL_KEY = 'ddp-pack-shell-' + C.token // 每份演示自己记(直接双击打开的本地文件共用一份 localStorage)
318
+ try { const v = localStorage.getItem(SHELL_KEY); if (C.framed && (v === '1' || v === '0')) shell = v === '1' } catch { /* 存不了 */ }
319
+ let cur = -1
320
+ let seq = 0
321
+ let pendingHash = ''
322
+ const stage = $('stage')
323
+ const bar = $('bar')
324
+ const sel = $('sel')
325
+ const count = $('count')
326
+ const toast = $('toast')
327
+
328
+ C.screens.forEach((s, i) => { const o = document.createElement('option'); o.value = String(i); o.textContent = `${i + 1}. ${s.label}`; sel.appendChild(o) })
329
+ if (!C.framed) $('shell').hidden = true
330
+ if (N < 2) { $('prev').hidden = true; $('next').hidden = true; sel.disabled = true }
331
+ if (!document.fullscreenEnabled) $('full').hidden = true
332
+
333
+ // 小屏幕看手机的设计(在手机上打开):不套外壳、铺满,工具条收成顶上正中一个小按钮
334
+ // (放在页面假状态栏那条上:那里没有能点的东西;底栏、右下角都是 App 自己的导航)
335
+ const compact = () => (C.kind === 'app' || C.kind === 'miniprogram') && innerWidth <= 600
336
+ // 网页不开外壳:铺满窗口(和设计台单看一样,宽度跟着窗口)
337
+ const fills = () => compact() || (C.kind === 'web' && !shell)
338
+
339
+ let toastTimer = 0
340
+ const say = (msg) => { toast.textContent = msg; toast.hidden = false; clearTimeout(toastTimer); toastTimer = setTimeout(() => { toast.hidden = true }, 2600) }
341
+
342
+ const svg = (tag, attrs, kids = []) => {
343
+ const el = document.createElementNS('http://www.w3.org/2000/svg', tag)
344
+ for (const [k, v] of Object.entries(attrs)) el.setAttribute(k, String(v))
345
+ for (const c of kids) el.appendChild(c)
346
+ return el
347
+ }
348
+ const capsule = (f, white) => {
349
+ const { w, h } = C.cap
350
+ const el = svg('svg', { class: 'cap' + (white ? ' w' : ''), viewBox: `0 0 ${w} ${h}`, 'aria-hidden': 'true' }, [
351
+ svg('rect', { class: 'pl', x: 0.25, y: 0.25, width: w - 0.5, height: h - 0.5, rx: h / 2 - 0.25 }),
352
+ svg('circle', { cx: 20.5, cy: 16, r: 2.2 }), svg('circle', { cx: 28, cy: 16, r: 3.1 }), svg('circle', { cx: 35.5, cy: 16, r: 2.2 }),
353
+ svg('path', { class: 'sp', d: 'M43.5 9v14' }),
354
+ svg('circle', { class: 'rg', cx: 65, cy: 16, r: 7.5 }), svg('circle', { cx: 65, cy: 16, r: 2.6 }),
355
+ ])
356
+ el.style.top = (f.pad || 0) + C.cap.top + 'px'
357
+ el.style.right = (f.pad || 0) + C.cap.right + 'px'
358
+ return el
359
+ }
360
+ const winCtl = (white) => {
361
+ if (C.os === 'win') {
362
+ const { w: W, h: H } = C.winbtn
363
+ const el = svg('svg', { class: 'win' + (white ? ' w' : ''), viewBox: `0 0 ${W * 3} ${H}`, 'aria-hidden': 'true' }, [
364
+ svg('path', { class: 'x', d: `M${W / 2 - 5} ${H / 2 + 0.5}h10` }),
365
+ svg('rect', { class: 'x', x: W * 1.5 - 4.5, y: H / 2 - 4.5, width: 9, height: 9, rx: 1 }),
366
+ svg('path', { class: 'x', d: `M${W * 2.5 - 5} ${H / 2 - 5}l10 10M${W * 2.5 + 5} ${H / 2 - 5}l-10 10` }),
367
+ ])
368
+ Object.assign(el.style, { top: '0px', right: '0px', width: W * 3 + 'px', height: H + 'px' })
369
+ return el
370
+ }
371
+ const { x, y, d, gap } = C.lights
372
+ const el = svg('svg', { class: 'win', viewBox: `0 0 ${d * 3 + gap * 2} ${d}`, 'aria-hidden': 'true' },
373
+ ['#FF5F57', '#FEBC2E', '#28C840'].map((c, i) => svg('circle', { cx: d / 2 + i * (d + gap), cy: d / 2, r: d / 2 - 0.25, fill: c, stroke: 'rgba(0,0,0,.12)', 'stroke-width': 0.5 })))
374
+ Object.assign(el.style, { left: x + 'px', top: y + 'px', width: d * 3 + gap * 2 + 'px', height: d + 'px' })
375
+ return el
376
+ }
377
+
378
+ let dev = null
379
+ let vp = null
380
+ let box = null
381
+ let deco = [] // 跟着这一屏变的外壳零件(胶囊、窗口按钮的深浅)
382
+ /** 搭外框:开关外壳、手机上横竖转换时重搭(里面的 iframe 也重放);换屏只换 iframe */
383
+ function build() {
384
+ const fill = fills()
385
+ document.body.classList.toggle('compact', compact())
386
+ const f = fill || (C.framed && !shell) ? { pad: 0, top: 0, r: 0, ir: 0 } : C.frame
387
+ stage.textContent = ''
388
+ box = document.createElement('div')
389
+ box.className = 'fit' + (fill ? ' all' : '')
390
+ dev = document.createElement('div')
391
+ dev.className = `dev k-${C.kind}` + (fill ? ' fill' : '') + (C.framed && !shell && !fill ? ' bare' : '')
392
+ if (!fill) Object.assign(dev.style, { width: C.w + f.pad * 2 + 'px', height: C.h + f.pad * 2 + f.top + 'px', borderRadius: f.r + 'px' })
393
+ dev.dataset.pad = String(f.pad || 0)
394
+ if (f.top) {
395
+ const ch = document.createElement('div')
396
+ ch.className = 'chrome'
397
+ ch.style.height = f.top + 'px'
398
+ ch.innerHTML = '<i></i><i></i><i></i><span></span>'
399
+ dev.appendChild(ch)
400
+ }
401
+ vp = document.createElement('div')
402
+ vp.className = 'vp' + (C.dark ? ' dk' : '')
403
+ if (!fill) Object.assign(vp.style, { left: f.pad + 'px', top: f.pad + f.top + 'px', width: C.w + 'px', height: C.h + 'px', borderRadius: f.ir + 'px' })
404
+ dev.appendChild(vp)
405
+ if (f.island) { const is = document.createElement('div'); is.className = 'island'; is.style.top = (f.pad || 0) + f.island + 'px'; dev.appendChild(is) }
406
+ dev._f = f
407
+ deco = []
408
+ box.appendChild(dev)
409
+ stage.appendChild(box)
410
+ fit()
411
+ $('shell').setAttribute('aria-pressed', shell ? 'true' : 'false')
412
+ }
413
+ /** 外壳上跟着这一屏的:浏览器栏里的标题、胶囊 / 窗口按钮(顶栏深色时画白的) */
414
+ function decorate() {
415
+ const s = C.screens[cur]
416
+ const f = dev._f
417
+ const sp = dev.querySelector('.chrome span')
418
+ if (sp) sp.textContent = s.label
419
+ for (const d of deco) d.remove()
420
+ deco = []
421
+ if (f.capsule) deco.push(capsule(f, !!s.top))
422
+ if (f.win) deco.push(winCtl(!!s.top))
423
+ for (const d of deco) dev.appendChild(d)
424
+ }
425
+ /** 按窗口大小缩放:手机、网页、平板最大到原大;画幅定死的(幻灯片、海报)可以放大铺满 */
426
+ function fit() {
427
+ if (!dev || dev.classList.contains('fill')) return
428
+ const W = dev.offsetWidth, H = dev.offsetHeight
429
+ const r = stage.getBoundingClientRect()
430
+ const pad = r.width < 600 ? 12 : 32
431
+ let z = Math.min((r.width - pad * 2) / W, (r.height - pad * 2) / H)
432
+ if (!C.fixed) z = Math.min(z, 1)
433
+ z = Math.max(0.05, z)
434
+ Object.assign(box.style, { width: W * z + 'px', height: H * z + 'px' })
435
+ dev.style.transform = `scale(${z})`
436
+ }
437
+
438
+ /** 放一屏:新 iframe 在后面载好了再换上来(不白一下) */
439
+ function show(i, hash = '') {
440
+ const me = ++seq
441
+ const s = C.screens[i]
442
+ const fr = document.createElement('iframe')
443
+ fr.className = 'nx'
444
+ fr.title = s.label
445
+ // 自己做的屏和播放器同源(allow-same-origin):不同源(不透明)的文档里浏览器不发 navigate 事件,
446
+ // 脚本里 location.href = 'x.html' 就拦不住、整屏跳到假地址的报错页。别人做的屏页面脚本本来就跑不了(CSP),只给 allow-scripts
447
+ fr.setAttribute('sandbox', s.strict ? 'allow-scripts' : 'allow-scripts allow-same-origin allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox')
448
+ fr.setAttribute('referrerpolicy', 'no-referrer')
449
+ fr.style.colorScheme = C.dark ? 'dark' : 'light'
450
+ let done = false
451
+ const swap = () => {
452
+ if (done || me !== seq || !fr.isConnected) return
453
+ done = true
454
+ fr.classList.remove('nx')
455
+ for (const old of [...vp.querySelectorAll('iframe')]) if (old !== fr) setTimeout(() => old.remove(), 160)
456
+ if (hash) setTimeout(() => { try { fr.contentWindow.postMessage({ ddpPack: 1, type: 'jump', hash }, '*') } catch { /* 已经换掉了 */ } }, 60)
457
+ }
458
+ fr.addEventListener('load', swap)
459
+ setTimeout(swap, 2500) // 页面里有载不完的东西:别一直等
460
+ fr.srcdoc = htmlOf(i)
461
+ vp.appendChild(fr)
462
+ }
463
+
464
+ const indexOfHash = () => {
465
+ let h = ''
466
+ try { h = decodeURIComponent(location.hash.replace(/^#/, '')) } catch { h = '' }
467
+ const k = h ? C.screens.findIndex((s) => s.key === h) : -1
468
+ return k >= 0 ? k : 0
469
+ }
470
+ function render() {
471
+ const i = indexOfHash()
472
+ if (i === cur && dev) return
473
+ cur = i
474
+ sel.value = String(i)
475
+ count.textContent = T.of.replace('{i}', String(i + 1)).replace('{n}', String(N))
476
+ $('prev').disabled = i === 0
477
+ $('next').disabled = i === N - 1
478
+ const s = C.screens[i]
479
+ document.title = C.title && C.title !== s.label ? `${s.label} · ${C.title}` : s.label
480
+ if (!dev) build()
481
+ decorate()
482
+ const hash = pendingHash
483
+ pendingHash = ''
484
+ show(i, hash)
485
+ }
486
+ /** 外框重搭(开关外壳、横竖屏换了):当前这屏重放 */
487
+ const rebuild = () => { build(); decorate(); show(cur) }
488
+ const go = (i, hash = '') => {
489
+ if (i < 0 || i >= N) return
490
+ if (i === cur) { if (hash) { const fr = vp && [...vp.querySelectorAll('iframe:not(.nx)')].pop(); if (fr) fr.contentWindow.postMessage({ ddpPack: 1, type: 'jump', hash }, '*') } return }
491
+ pendingHash = hash
492
+ location.hash = '#' + encodeURIComponent(C.screens[i].key)
493
+ }
494
+ const keyOf = (p) => { let k = String(p || '').replace(/^\/+/, ''); if (!k || k.endsWith('/')) k += 'index.html'; return k }
495
+
496
+ addEventListener('message', (e) => {
497
+ const d = e.data
498
+ if (!d || d.ddpPack !== 1 || !vp || ![...vp.querySelectorAll('iframe')].some((f) => f.contentWindow === e.source)) return
499
+ if (d.type === 'nav') {
500
+ const k = keyOf(d.path)
501
+ let i = C.screens.findIndex((s) => s.key === k)
502
+ if (i < 0) i = C.screens.findIndex((s) => s.key === k + '.html')
503
+ 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')) {
506
+ const m = store[d.area]
507
+ if (d.op === 'set') m[String(d.k)] = String(d.v)
508
+ else if (d.op === 'del') delete m[String(d.k)]
509
+ else if (d.op === 'clear') store[d.area] = {}
510
+ } else if (d.type === 'key') key(d.key)
511
+ })
512
+ const key = (k) => {
513
+ if (k === 'ArrowLeft' || k === 'PageUp') go(cur - 1)
514
+ else if (k === 'ArrowRight' || k === 'PageDown') go(cur + 1)
515
+ }
516
+ addEventListener('keydown', (e) => {
517
+ if (e.altKey || e.ctrlKey || e.metaKey || e.target === sel) return
518
+ if (/^(ArrowLeft|ArrowRight|PageUp|PageDown)$/.test(e.key)) { e.preventDefault(); key(e.key) }
519
+ })
520
+ $('prev').addEventListener('click', () => go(cur - 1))
521
+ $('next').addEventListener('click', () => go(cur + 1))
522
+ sel.addEventListener('change', () => { document.body.classList.remove('open'); go(Number(sel.value)) })
523
+ $('shell').addEventListener('click', () => {
524
+ shell = !shell
525
+ try { localStorage.setItem(SHELL_KEY, shell ? '1' : '0') } catch { /* 存不了 */ }
526
+ rebuild()
527
+ })
528
+ $('full').addEventListener('click', () => {
529
+ if (document.fullscreenElement) document.exitFullscreen().catch(() => {})
530
+ else document.documentElement.requestFullscreen().catch(() => {})
531
+ })
532
+ $('menu').addEventListener('click', () => document.body.classList.toggle('open'))
533
+ document.addEventListener('fullscreenchange', () => { $('full').textContent = document.fullscreenElement ? T.exitFull : T.full })
534
+ let wasCompact = compact()
535
+ addEventListener('resize', () => {
536
+ if (compact() !== wasCompact) { wasCompact = compact(); rebuild() } else fit()
537
+ })
538
+ addEventListener('hashchange', render)
539
+ bar.hidden = false // 先把工具条放出来再量舞台(不然第一次缩放按没有工具条的高度算)
540
+ render()
541
+ }
542
+
543
+ 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' },
546
+ }
547
+
548
+ const CSS = `
549
+ :root{--stage:#e8e9ed;--bar:#fbfbfc;--fg:#1d1d22;--mute:#6b6b74;--line:rgba(0,0,0,.09);--btn:#f0f0f3;--btn-h:#e4e4e9;--acc:#4d6bfe;color-scheme:light}
550
+ @media (prefers-color-scheme:dark){:root{--stage:#141417;--bar:#1d1d21;--fg:#ececf1;--mute:#9a9aa6;--line:rgba(255,255,255,.08);--btn:#29292f;--btn-h:#33333a;color-scheme:dark}}
551
+ *{box-sizing:border-box}
552
+ [hidden]{display:none!important}
553
+ html,body{margin:0;height:100%;overflow:hidden}
554
+ body{background:var(--stage);color:var(--fg);font:14px/1.4 -apple-system,BlinkMacSystemFont,"PingFang SC","Microsoft YaHei","Segoe UI",sans-serif;display:flex;flex-direction:column}
555
+ #bar{flex:none;display:flex;align-items:center;gap:8px;height:48px;padding:0 max(14px,env(safe-area-inset-right)) 0 max(14px,env(safe-area-inset-left));background:var(--bar);border-bottom:1px solid var(--line)}
556
+ #bar .ttl{flex:1 1 0;min-width:0;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
557
+ #bar .mid{flex:none;display:flex;align-items:center;gap:6px}
558
+ #bar .end{flex:1 1 0;display:flex;justify-content:flex-end;gap:6px;min-width:0}
559
+ #bar button,#bar select{height:30px;border:0;border-radius:8px;background:var(--btn);color:var(--fg);font:inherit;font-size:13px;padding:0 11px;cursor:pointer}
560
+ #bar button:hover:not(:disabled),#bar select:hover{background:var(--btn-h)}
561
+ #bar button:disabled{opacity:.4;cursor:default}
562
+ #bar button:focus-visible,#bar select:focus-visible{outline:2px solid var(--acc);outline-offset:1px}
563
+ #bar .arw{width:30px;padding:0;font-size:16px;line-height:30px}
564
+ #bar select{max-width:min(42vw,280px);padding-right:8px}
565
+ #count{color:var(--mute);font-size:12px;font-variant-numeric:tabular-nums;min-width:44px;text-align:center}
566
+ #shell[aria-pressed=true]{background:var(--acc);color:#fff}
567
+ #stage{flex:1;min-height:0;position:relative;display:flex;align-items:center;justify-content:center;overflow:hidden}
568
+ .fit{position:relative;flex:none}
569
+ .dev{position:absolute;left:0;top:0;transform-origin:0 0;background:#fff;box-shadow:0 0 0 .5px rgba(0,0,0,.14),0 18px 48px rgba(0,0,0,.2)}
570
+ .dev.fill{position:absolute;inset:0;box-shadow:none;border-radius:0}
571
+ .dev.k-app,.dev.k-miniprogram,.dev.k-tablet{background:#0e0e12;box-shadow:inset 0 0 0 1.5px #2b2b33,0 0 0 1px rgba(0,0,0,.45),0 24px 60px rgba(0,0,0,.3)}
572
+ .dev.bare,.dev.fill.k-app,.dev.fill.k-miniprogram,.dev.fill.k-tablet{background:#fff;box-shadow:0 0 0 .5px rgba(0,0,0,.14),0 18px 48px rgba(0,0,0,.2)}
573
+ .dev.fill.k-app,.dev.fill.k-miniprogram,.dev.fill.k-tablet{box-shadow:none}
574
+ .dev.k-desktop{box-shadow:0 0 0 .5px rgba(0,0,0,.3),0 22px 60px rgba(0,0,0,.28)}
575
+ .dev.fill.k-desktop{box-shadow:none}
576
+ .fit.all{position:absolute;inset:0}
577
+ .vp{position:absolute;overflow:hidden;background:#fff;isolation:isolate}
578
+ .dev.fill .vp{inset:0}
579
+ .vp.dk{background:#111}
580
+ .vp iframe{position:absolute;inset:0;width:100%;height:100%;border:0;display:block;background:transparent;transition:opacity .15s}
581
+ .vp iframe.nx{opacity:0;pointer-events:none}
582
+ .chrome{position:absolute;left:0;right:0;top:0;display:flex;align-items:center;gap:7px;padding:0 13px;background:#ebebef;border-bottom:1px solid rgba(0,0,0,.07);border-radius:inherit;border-bottom-left-radius:0;border-bottom-right-radius:0;overflow:hidden}
583
+ .chrome i{width:11px;height:11px;border-radius:50%;background:#ff5f57;flex:none}
584
+ .chrome i:nth-child(2){background:#febc2e}
585
+ .chrome i:nth-child(3){background:#28c840}
586
+ .chrome span{flex:1;min-width:0;margin:0 60px 0 18px;height:20px;border-radius:6px;background:rgba(0,0,0,.05);color:#6b6b74;font:12px/20px -apple-system,BlinkMacSystemFont,"PingFang SC",sans-serif;text-align:center;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
587
+ .island{position:absolute;left:50%;width:118px;height:34px;margin-left:-59px;border-radius:20px;background:#000;z-index:4;pointer-events:none}
588
+ .cap{position:absolute;width:87px;height:32px;z-index:4;pointer-events:none;overflow:visible;fill:#000}
589
+ .cap .pl{fill:rgba(255,255,255,.6);stroke:rgba(0,0,0,.08);stroke-width:.5}
590
+ .cap .sp{stroke:rgba(0,0,0,.15);stroke-width:.5}
591
+ .cap .rg{fill:none;stroke:#000;stroke-width:2}
592
+ .cap.w{fill:#fff}
593
+ .cap.w .pl{fill:rgba(0,0,0,.15);stroke:rgba(255,255,255,.25)}
594
+ .cap.w .sp{stroke:rgba(255,255,255,.25)}
595
+ .cap.w .rg{stroke:#fff}
596
+ .win{position:absolute;z-index:4;pointer-events:none;overflow:visible}
597
+ .win .x{fill:none;stroke:#1f1f1f;stroke-width:1}
598
+ .win.w .x{stroke:#fff}
599
+ #toast{position:fixed;left:50%;bottom:calc(24px + env(safe-area-inset-bottom));transform:translateX(-50%);max-width:calc(100% - 32px);padding:9px 14px;border-radius:10px;background:rgba(20,20,24,.92);color:#fff;font-size:13px;z-index:20;box-shadow:0 6px 24px rgba(0,0,0,.25)}
600
+ #menu{display:none}
601
+ body.compact #bar{position:fixed;left:8px;right:8px;top:calc(34px + env(safe-area-inset-top));bottom:auto;height:auto;flex-wrap:wrap;padding:10px;border-radius:14px;border:1px solid var(--line);box-shadow:0 10px 40px rgba(0,0,0,.25);z-index:15;display:none}
602
+ body.compact.open #bar{display:flex}
603
+ body.compact #bar .ttl{flex-basis:100%}
604
+ body.compact #bar .mid{flex:1 1 100%;min-width:0}
605
+ body.compact #shell{display:none}
606
+ body.compact #bar select{flex:1;min-width:0;max-width:none;text-overflow:ellipsis}
607
+ body.compact #bar .arw,body.compact #count{flex:none}
608
+ body.compact #bar .end{flex:none;margin-left:auto}
609
+ body.compact #menu{display:block;position:fixed;left:50%;top:calc(4px + env(safe-area-inset-top));transform:translateX(-50%);width:64px;height:24px;padding:0;border-radius:12px;border:0;background:rgba(20,20,24,.5);color:#fff;font-size:13px;line-height:24px;z-index:16;backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px)}
610
+ @media (max-width:560px){#bar .ttl{display:none}#bar .end{flex:none}}
611
+ `
612
+
613
+ /**
614
+ * 打一份演示包。
615
+ * screens:[{ key, label, top }](top:顶栏是深色,外壳上的胶囊 / 窗口按钮画白的)
616
+ * dark:右侧栏开着「深色」;scheme:右侧栏当时的系统深浅色('dark' / 'light'),没开「深色」时页面按它显示
617
+ * read(rel):设计目录里的文件(Buffer,读不到 null);strictOf(page):这屏是不是别人做的(加硬规矩:只跑我们的脚本)
618
+ * 回 { html, missing: [没读到的屏], count }
619
+ */
620
+ export function buildPack({ screens, read, strictOf = () => false, kind, w, h, os = '', dark = false, scheme = 'light', tweak = null, title = '', lang = 'zh', fit = false }) {
621
+ kind = FRAME[kind] ? kind : 'web'
622
+ const S = STRINGS[lang === 'en' ? 'en' : 'zh']
623
+ const token = 'ddpA' + crypto.randomBytes(5).toString('hex') + '_'
624
+ const storeMark = `/*ddpS${token}*/null`
625
+ const nonce = crypto.randomBytes(16).toString('base64')
626
+ 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
+ const script = (src, strict) => `<script${strict ? ` nonce="${nonce}"` : ''}>${src.replace(/<\/(script)/gi, '<\\/$1').replace(/<!--/g, '<\\!--')}</script>`
628
+ const shimSrc = `(${storeShim})(${storeMark});`
629
+ const navSrc = (strict) => `(${navScript})(${JSON.stringify({ ...navCfg, strict })});`
630
+ const mode = dark ? 'dark' : scheme === 'dark' ? 'media' : 'light'
631
+ const schemeSrc = `(${schemeScript})(${JSON.stringify(mode)});`
632
+
633
+ const assets = []
634
+ const index = new Map()
635
+ const parts = []
636
+ const list = []
637
+ const missing = []
638
+ let total = 0
639
+ for (const s of screens.slice(0, PACK_SCREENS)) {
640
+ const page = read(s.key)
641
+ if (!page) { missing.push(s.key); continue }
642
+ const strict = !!strictOf(page)
643
+ const text = page.toString('utf8').replace(/^/, '')
644
+ const base = PACK_ORIGIN + '/' + s.key.split('/').map(encodeURIComponent).join('/')
645
+ let out = bundle(strict ? defang(text) : text, {
646
+ key: s.key,
647
+ read,
648
+ base,
649
+ lead: (strict ? strictMeta(nonce) : '') + script(shimSrc + navSrc(strict), strict),
650
+ tail: script(schemeSrc, strict),
651
+ })
652
+ // 大的 data: 地址(图片、字体、脚本)挪出来单独存,几屏共用的只存一份
653
+ out = out.replace(/data:[a-z0-9.+-]+\/[a-z0-9.+-]+(?:;[a-z0-9.+=-]+)*;base64,[A-Za-z0-9+/]+={0,2}/gi, (m) => {
654
+ if (m.length < ASSET_MIN) return m
655
+ let i = index.get(m)
656
+ if (i === undefined) { i = assets.length; assets.push(m); index.set(m, i); total += m.length }
657
+ return token + i + '_'
658
+ })
659
+ total += out.length
660
+ if (total > PACK_MAX) { const e = new Error('tooBig'); e.code = 'tooBig'; throw e }
661
+ parts.push(`<script type="application/json" id="ddp-s-${list.length}">${jsonTag(out)}</script>`)
662
+ list.push({ key: s.key, label: String(s.label || s.key).slice(0, 80), top: !!s.top, ...(strict ? { strict: true } : null) })
663
+ }
664
+ if (!list.length) { const e = new Error('noScreens'); e.code = 'noScreens'; throw e }
665
+
666
+ const f = frameOf(kind, w, h)
667
+ const cfg = {
668
+ kind, w, h, os: os === 'win' ? 'win' : '', dark: !!dark || scheme === 'dark', title: String(title || '').slice(0, 120),
669
+ frame: f, cap: CAP, lights: LIGHTS, winbtn: WINBTN,
670
+ framed: !!FRAMED[kind], fixed: !!FIXED[kind],
671
+ // 网页默认不套浏览器框(铺满窗口),右侧栏开着「按画幅显示」的照它套着;手机、平板、桌面软件默认套着
672
+ shellDefault: !!FRAMED[kind] && (kind !== 'web' || !!fit),
673
+ screens: list, token, storeMark, strings: S,
674
+ }
675
+ const docTitle = cfg.title || list[0].label
676
+ const html = '<!doctype html>\n'
677
+ + `<html lang="${lang === 'en' ? 'en' : 'zh-CN'}"><head><meta charset="utf-8">`
678
+ + '<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">'
679
+ + `<meta name="generator" content="DSH Design Studio"><title>${escHtml(docTitle)}</title><style>${CSS}</style></head><body>`
680
+ + `<header id="bar" hidden><div class="ttl">${escHtml(cfg.title)}</div>`
681
+ + `<div class="mid"><button id="prev" class="arw" type="button" title="${escHtml(S.prev)} (←)" aria-label="${escHtml(S.prev)}">‹</button>`
682
+ + `<select id="sel" aria-label="${escHtml(S.screens)}"></select>`
683
+ + `<button id="next" class="arw" type="button" title="${escHtml(S.next)} (→)" aria-label="${escHtml(S.next)}">›</button><span id="count"></span></div>`
684
+ + `<div class="end"><button id="shell" type="button" aria-pressed="false" title="${escHtml(S.shellTip)}">${escHtml(S.shell)}</button>`
685
+ + `<button id="full" type="button">${escHtml(S.full)}</button></div></header>`
686
+ + `<main id="stage"></main><button id="menu" type="button" aria-label="${escHtml(S.menu)}">•••</button><div id="toast" role="status" hidden></div>`
687
+ + `<script type="application/json" id="ddp-cfg">${jsonTag(cfg)}</script>`
688
+ + parts.join('')
689
+ + assets.map((a, i) => `<script type="application/json" id="ddp-a-${i}">${jsonTag(a)}</script>`).join('')
690
+ + `<script>(${player})()</script>`
691
+ + '</body></html>\n'
692
+ return { html, missing, count: list.length }
693
+ }