dsh-design-studio 1.5.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +6 -5
- package/README.md +7 -6
- package/THIRD_PARTY_NOTICES.md +108 -0
- package/assets/art/README.md +102 -0
- package/assets/art/brand-mark.webp +0 -0
- package/assets/art/check-clean.webp +0 -0
- package/assets/art/coach-markup.webp +0 -0
- package/assets/art/drop-file.webp +0 -0
- package/assets/art/empty-components.webp +0 -0
- package/assets/art/empty-data.webp +0 -0
- package/assets/art/empty-error.webp +0 -0
- package/assets/art/empty-frames.webp +0 -0
- package/assets/art/empty-history.webp +0 -0
- package/assets/art/empty-market.webp +0 -0
- package/assets/art/empty-notes.webp +0 -0
- package/assets/art/empty-search.webp +0 -0
- package/assets/art/empty-tokens.webp +0 -0
- package/assets/art/empty-works.webp +0 -0
- package/assets/art/guide-icon.webp +0 -0
- package/assets/art/kind-app.webp +0 -0
- package/assets/art/kind-desktop.webp +0 -0
- package/assets/art/kind-diagram.webp +0 -0
- package/assets/art/kind-dshplugin.webp +0 -0
- package/assets/art/kind-email.webp +0 -0
- package/assets/art/kind-embedded.webp +0 -0
- package/assets/art/kind-framed.webp +0 -0
- package/assets/art/kind-miniprogram.webp +0 -0
- package/assets/art/kind-poster.webp +0 -0
- package/assets/art/kind-slides.webp +0 -0
- package/assets/art/kind-tablet.webp +0 -0
- package/assets/art/kind-web.webp +0 -0
- package/assets/art/placeholder-inspire-img.webp +0 -0
- package/assets/art/wait-creating.webp +0 -0
- package/assets/motion/ai-capsule.html +124 -0
- package/assets/motion/ai-glow-input.html +112 -0
- package/assets/motion/balance-odometer.html +112 -0
- package/assets/motion/bottom-sheet.html +149 -0
- package/assets/motion/brightness-pill.html +114 -0
- package/assets/motion/comet-ring.html +95 -0
- package/assets/motion/copy-morph.html +116 -0
- package/assets/motion/cube-grid.html +103 -0
- package/assets/motion/day-night.html +120 -0
- package/assets/motion/dial-knob.html +130 -0
- package/assets/motion/dock-magnify.html +118 -0
- package/assets/motion/download-ring.html +135 -0
- package/assets/motion/expand-card.html +137 -0
- package/assets/motion/flip-card.html +100 -0
- package/assets/motion/hold-pay.html +137 -0
- package/assets/motion/holo-card.html +130 -0
- package/assets/motion/keycap.html +92 -0
- package/assets/motion/like-jelly.html +88 -0
- package/assets/motion/liquid-progress.html +113 -0
- package/assets/motion/liquid-segment.html +127 -0
- package/assets/motion/live-capsule.html +144 -0
- package/assets/motion/marker-highlight.html +94 -0
- package/assets/motion/marquee-logos.html +110 -0
- package/assets/motion/otp-code.html +111 -0
- package/assets/motion/password-eye.html +136 -0
- package/assets/motion/ruler-slider.html +140 -0
- package/assets/motion/search-expand.html +81 -0
- package/assets/motion/send-fly.html +121 -0
- package/assets/motion/skeleton-shine.html +124 -0
- package/assets/motion/star-rate.html +98 -0
- package/assets/motion/success-check.html +114 -0
- package/assets/motion/suggest-chips.html +134 -0
- package/assets/motion/swipe-row.html +126 -0
- package/assets/motion/tabbar-bounce.html +92 -0
- package/assets/motion/tactile-controls.html +89 -0
- package/assets/motion/text-scramble.html +173 -0
- package/assets/motion/toast-stack.html +115 -0
- package/assets/motion/token-stream.html +106 -0
- package/assets/motion/voice-orb.html +144 -0
- package/assets/showcase/alley-noodles-1.webp +0 -0
- package/assets/showcase/alley-noodles-2.webp +0 -0
- package/assets/showcase/alley-noodles-3.webp +0 -0
- package/assets/showcase/autumn-sale-1.webp +0 -0
- package/assets/showcase/bold-folio-1.webp +0 -0
- package/assets/showcase/bold-folio-2.webp +0 -0
- package/assets/showcase/book-club-1.webp +0 -0
- package/assets/showcase/book-club-2.webp +0 -0
- package/assets/showcase/book-club-3.webp +0 -0
- package/assets/showcase/flower-order-1.webp +0 -0
- package/assets/showcase/little-painter-1.webp +0 -0
- package/assets/showcase/little-painter-2.webp +0 -0
- package/assets/showcase/moon-fair-1.webp +0 -0
- package/assets/showcase/nail-booking-1.webp +0 -0
- package/assets/showcase/nail-booking-2.webp +0 -0
- package/assets/showcase/nail-booking-3.webp +0 -0
- package/assets/showcase/night-run-1.webp +0 -0
- package/assets/showcase/paw-diary-1.webp +0 -0
- package/assets/showcase/paw-diary-2.webp +0 -0
- package/assets/showcase/paw-diary-3.webp +0 -0
- package/assets/showcase/pixel-planet-1.webp +0 -0
- package/assets/showcase/pixel-planet-2.webp +0 -0
- package/assets/showcase/pixel-planet-3.webp +0 -0
- package/assets/showcase/pocket-ledger-1.webp +0 -0
- package/assets/showcase/pocket-ledger-2.webp +0 -0
- package/assets/showcase/shiftloom-1.webp +0 -0
- package/assets/showcase/shiftloom-2.webp +0 -0
- package/assets/showcase/slow-breath-1.webp +0 -0
- package/assets/showcase/slow-breath-2.webp +0 -0
- package/assets/showcase/slow-breath-3.webp +0 -0
- package/assets/showcase/slow-trip-1.webp +0 -0
- package/assets/showcase/slow-trip-2.webp +0 -0
- package/assets/showcase/slow-trip-3.webp +0 -0
- package/assets/showcase/slow-weekly-1.webp +0 -0
- package/assets/showcase/stay-confirm-1.webp +0 -0
- package/assets/showcase/stove-recipes-1.webp +0 -0
- package/assets/showcase/stove-recipes-2.webp +0 -0
- package/assets/showcase/strobewatch-1.webp +0 -0
- package/assets/showcase/strobewatch-2.webp +0 -0
- package/assets/showcase/tapeworks-1.webp +0 -0
- package/assets/showcase/tapeworks-2.webp +0 -0
- package/assets/showcase/tea-brand-pitch-1.webp +0 -0
- package/assets/showcase/tea-brand-pitch-2.webp +0 -0
- package/assets/showcase/tea-brand-pitch-3.webp +0 -0
- package/assets/showcase/time-bookshop-1.webp +0 -0
- package/assets/showcase/time-bookshop-2.webp +0 -0
- package/assets/showcase/water-journey-1.webp +0 -0
- package/assets/showcase/water-journey-2.webp +0 -0
- package/assets/showcase/water-journey-3.webp +0 -0
- package/assets/showcase/weekend-go-1.webp +0 -0
- package/assets/showcase/weekend-go-2.webp +0 -0
- package/assets/showcase/weekend-go-3.webp +0 -0
- package/assets/showcase/winter-soup-1.webp +0 -0
- package/assets/showcase/year-review-1.webp +0 -0
- package/assets/showcase/year-review-2.webp +0 -0
- package/assets/showcase/year-review-3.webp +0 -0
- package/lib/browser.js +3 -1
- package/lib/bundle.js +8 -3
- package/lib/canvthumb.js +9 -6
- package/lib/client.js +7427 -2624
- package/lib/components.js +4 -2
- package/lib/core.js +762 -132
- package/lib/design-page-settings.js +48 -0
- package/lib/design-scope.js +36 -0
- package/lib/design-transactions.js +259 -0
- package/lib/drop-folder.js +25 -0
- package/lib/edits.js +125 -8
- package/lib/embedded/lvgl_shot.c +133 -0
- package/lib/embedded/qml_shot.py +66 -0
- package/lib/embedded-shot.js +400 -0
- package/lib/embedded-trust.js +76 -0
- package/lib/fonts.js +30 -21
- package/lib/frames.js +23 -23
- package/lib/gallery/css.js +9 -2
- package/lib/gallery/market-routes.js +23 -7
- package/lib/gallery/pack.js +25 -8
- package/lib/gallery/policy.js +6 -4
- package/lib/gallery/routes.js +255 -83
- package/lib/gallery/submit.js +285 -57
- package/lib/gallery/use.js +13 -4
- package/lib/handoff-embedded.js +1182 -0
- package/lib/handoff.js +212 -71
- package/lib/history.js +393 -43
- package/lib/htmlpack.js +34 -13
- package/lib/impl.js +3 -0
- package/lib/index.js +661 -136
- package/lib/inspire.js +73 -26
- package/lib/kinds.js +11 -2
- package/lib/look.js +45 -25
- package/lib/mock.js +41 -4
- package/lib/motion.js +90 -0
- package/lib/page-settings.js +103 -0
- package/lib/picker.js +348 -70
- package/lib/rules.js +85 -0
- package/lib/serve.js +154 -15
- package/lib/showcase.json +22 -0
- package/lib/styles.js +16 -7
- package/lib/system.js +19 -8
- package/lib/tool.js +2 -1
- package/lib/tweaks.js +146 -9
- package/lib/works.js +151 -19
- package/locale/auto/en.json +1 -1
- package/locale/auto/zh.json +1 -1
- package/locale/en.json +1 -1
- package/locale/offline/en.json +1 -1
- package/locale/offline/zh.json +2 -2
- package/locale/zh.json +1 -1
- package/package.json +3 -2
- package/skills/ui-design/SKILL.md +56 -46
- package/skills/ui-design/frames/dsh/frame.json +1 -1
- package/skills/ui-design/references/app.md +29 -2
- package/skills/ui-design/references/components.md +1 -1
- package/skills/ui-design/references/desktop.md +1 -1
- package/skills/ui-design/references/dshplugin.md +12 -12
- package/skills/ui-design/references/embedded.md +40 -0
- package/skills/ui-design/references/frames.md +20 -20
- package/skills/ui-design/references/miniprogram.md +2 -2
- package/skills/ui-design/references/mock.md +16 -0
- package/skills/ui-design/references/poster.md +2 -1
- package/skills/ui-design/references/tweaks.md +17 -0
- package/skills/ui-design/tokens.css +19 -5
package/lib/tweaks.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import fs from 'node:fs'
|
|
17
17
|
import path from 'node:path'
|
|
18
18
|
import { allScreens } from './core.js'
|
|
19
|
+
import { collect, designWriteScope } from './history.js'
|
|
19
20
|
import { parseColor, hexOf } from './system.js'
|
|
20
21
|
import { FONT_DIR, fontBlockIds, fontPrefix, firstFamily, libFontOf, libIdsNamed, stripFontBlock, syncFontBlock } from './fonts.js'
|
|
21
22
|
|
|
@@ -195,7 +196,7 @@ const ROOTISH = /(^|,)\s*(:root|html)\s*(,|$)/i
|
|
|
195
196
|
* nested 为假:顶层的全改(同一个变量写了几遍时生效的是最后一处,只改第一处等于没改);
|
|
196
197
|
* nested 为真:只改 @media 等里面的第一处(整个设计目录都没有顶层声明时才用)
|
|
197
198
|
*/
|
|
198
|
-
export function setVarDecl(css, name, value, nested = false) {
|
|
199
|
+
export function setVarDecl(css, name, value, nested = false, keepAlias = false) {
|
|
199
200
|
const m0 = mask(css)
|
|
200
201
|
// 只认一条声明的开头(前面是 { ; } 加空白):--other--r、别的变量值里的「--r:」都不算;值到 ; } ! 为止
|
|
201
202
|
const re = new RegExp(`(?<=[{};]\\s*)(${escRe(name)}\\s*:\\s*)([^;{}!]*?)(\\s*(?:;|}|!))`, 'g')
|
|
@@ -203,6 +204,8 @@ export function setVarDecl(css, name, value, nested = false) {
|
|
|
203
204
|
for (const m of m0.matchAll(re)) {
|
|
204
205
|
const b = blockAt(m0, m.index)
|
|
205
206
|
if (!b || !ROOTISH.test(b.selector) || (b.depth === 1) === nested) continue
|
|
207
|
+
if (keepAlias && /var\(/i.test(m[2])) continue // 试穿:引用了别的变量的(var(--brand)、0 2px 8px var(--c))是有意的关系,不改成定值
|
|
208
|
+
if (keepAlias && !b.selector.split(',').every((x) => /^\s*(:root|html)\s*$/i.test(x))) continue // 试穿:和别的选择器写在一起的(html, .checkout)是那块区域单独的配色,不动
|
|
206
209
|
hits.push(m)
|
|
207
210
|
if (nested) break
|
|
208
211
|
}
|
|
@@ -274,6 +277,28 @@ function cssFiles(root, realRoot = '') {
|
|
|
274
277
|
return [...css, ...allScreens(root)].filter((rel) => ownFile(root, realRoot, rel))
|
|
275
278
|
}
|
|
276
279
|
|
|
280
|
+
/**
|
|
281
|
+
* 试穿风格(2.0)只写进页面真正用的那几份公共样式表:相对路径(可以在子目录里),.css、设计目录里自己的普通文件(不跟软链接)。
|
|
282
|
+
* 别的屏自己 <style> 里的同名变量、别的样式表都不动。不合格的丢掉
|
|
283
|
+
*/
|
|
284
|
+
export function onlyCss(root, realRoot, list, max = 8) {
|
|
285
|
+
if (!Array.isArray(list)) return null
|
|
286
|
+
const out = []
|
|
287
|
+
for (const x of list.slice(0, max)) {
|
|
288
|
+
const rel = String(x || '').replace(/\\/g, '/').replace(/^\/+/, '')
|
|
289
|
+
if (!rel || !/\.css$/i.test(rel) || rel.split('/').some((p) => !p || p === '.' || p === '..' || p.startsWith('.'))) continue
|
|
290
|
+
const abs = path.join(root, rel)
|
|
291
|
+
try {
|
|
292
|
+
if (!fs.lstatSync(abs).isFile()) continue
|
|
293
|
+
const real = fs.realpathSync(abs)
|
|
294
|
+
if (!real.startsWith(realRoot + path.sep)) continue
|
|
295
|
+
// 路上的每一层也不能是软链接(realpath 已经在里面,再看一眼文件自己不是链接就够了)
|
|
296
|
+
} catch { continue }
|
|
297
|
+
if (!out.includes(rel)) out.push(rel)
|
|
298
|
+
}
|
|
299
|
+
return out
|
|
300
|
+
}
|
|
301
|
+
|
|
277
302
|
/** 外观面板里直接改的设计变量:{ '--名字': 值 } → [[名字, 值]](名字、值都要老实:值里不能有 ; { } < 换行) */
|
|
278
303
|
export function cleanVars(vars) {
|
|
279
304
|
if (!vars || typeof vars !== 'object' || Array.isArray(vars)) return []
|
|
@@ -292,7 +317,7 @@ export function cleanVars(vars) {
|
|
|
292
317
|
* CSS 变量改样式里的默认值,属性写到每屏的 <html> 上,tweaks.json 的 value 跟着改。
|
|
293
318
|
* @returns { ok, changed: [{ id, label, from, to }], files: [相对路径], missed: [{ id, label }] }(missed:样式里找不到这个变量的默认值)
|
|
294
319
|
*/
|
|
295
|
-
export function applyTweaks(root, values, vars) {
|
|
320
|
+
export function applyTweaks(root, values, vars, opts = {}) {
|
|
296
321
|
const r0 = readTweaks(root)
|
|
297
322
|
const hasTw = !!(r0 && r0.list.length && values && Object.keys(values).length)
|
|
298
323
|
const varList = cleanVars(vars)
|
|
@@ -308,16 +333,30 @@ export function applyTweaks(root, values, vars) {
|
|
|
308
333
|
const arr = raw ? (Array.isArray(raw) ? raw : raw.tweaks) : []
|
|
309
334
|
const texts = new Map()
|
|
310
335
|
const read = (rel) => (texts.has(rel) ? texts.get(rel) : fs.readFileSync(path.join(root, rel), 'utf8'))
|
|
336
|
+
// opts.where:试穿风格 { 变量: 页面上它生效的那条声明所在的公共样式表 }——每个变量只写自己那份,
|
|
337
|
+
// 别的样式表里的同名声明(别的屏用的)、引用别的变量的声明都不动;没给就照旧全找
|
|
338
|
+
let where = null
|
|
339
|
+
if (opts.where && typeof opts.where === 'object' && !Array.isArray(opts.where)) {
|
|
340
|
+
// 只写进得了版本记录的(和存版本用同一份清单:层数、跳过的目录、软链接目录、文件太多都一样算):写了就得撤得回
|
|
341
|
+
const kept = collect(root) || {}
|
|
342
|
+
const ok = new Set((onlyCss(root, realRoot, [...new Set(Object.values(opts.where).map(String))]) || []).filter((r) => Object.hasOwn(kept, r)))
|
|
343
|
+
where = new Map()
|
|
344
|
+
for (const [name, rel] of Object.entries(opts.where)) {
|
|
345
|
+
const r = String(rel || '').replace(/\\/g, '/').replace(/^\/+/, '')
|
|
346
|
+
if (ok.has(r)) where.set(name, r)
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
const files = (name) => (where ? (where.has(name) ? [where.get(name)] : []) : cssFiles(root, realRoot))
|
|
311
350
|
const changed = []
|
|
312
351
|
const missed = []
|
|
313
352
|
// 先把所有文件里顶层的声明都改掉(哪份样式后加载就是哪份生效,全改才稳);一处都没有再退到 @media 里的第一处
|
|
314
353
|
const writeVar = (name, value) => {
|
|
315
|
-
for (const nested of [false, true]) {
|
|
354
|
+
for (const nested of where ? [false] : [false, true]) {
|
|
316
355
|
let done = false
|
|
317
|
-
for (const rel of
|
|
356
|
+
for (const rel of files(name)) {
|
|
318
357
|
let t
|
|
319
358
|
try { t = read(rel) } catch { continue }
|
|
320
|
-
const next = /\.html?$/i.test(rel) ? setVarInHtml(t, name, value, nested) : setVarDecl(t, name, value, nested)
|
|
359
|
+
const next = /\.html?$/i.test(rel) ? setVarInHtml(t, name, value, nested) : setVarDecl(t, name, value, nested, !!where)
|
|
321
360
|
if (next === null) continue
|
|
322
361
|
texts.set(rel, next)
|
|
323
362
|
done = true
|
|
@@ -358,7 +397,13 @@ export function applyTweaks(root, values, vars) {
|
|
|
358
397
|
}
|
|
359
398
|
if (!changed.length) return { ok: true, changed, files: [], missed }
|
|
360
399
|
if (twChanged) texts.set(TWEAKS_FILE, JSON.stringify(raw, null, 2) + '\n')
|
|
361
|
-
|
|
400
|
+
const scope = designWriteScope.getStore()
|
|
401
|
+
if (scope && (scope.root !== root || !scope.verify([...texts.keys()]))) return { ok: false, reason: 'backup' }
|
|
402
|
+
if (texts.size) opts.beforeWrite?.()
|
|
403
|
+
for (const [rel, t] of texts) {
|
|
404
|
+
if (scope?.put) scope.put(rel, t)
|
|
405
|
+
else fs.writeFileSync(path.join(root, rel), t)
|
|
406
|
+
}
|
|
362
407
|
return { ok: true, changed, files: [...texts.keys()], missed }
|
|
363
408
|
}
|
|
364
409
|
|
|
@@ -370,6 +415,7 @@ export function applyTweaks(root, values, vars) {
|
|
|
370
415
|
*/
|
|
371
416
|
export function designTexts(root) {
|
|
372
417
|
const out = []
|
|
418
|
+
const scope = designWriteScope.getStore()
|
|
373
419
|
let n = 0
|
|
374
420
|
const walk = (dir, rel, depth) => {
|
|
375
421
|
let list
|
|
@@ -382,7 +428,7 @@ export function designTexts(root) {
|
|
|
382
428
|
if (n >= 300) { out.partial = true; continue }
|
|
383
429
|
n++
|
|
384
430
|
try {
|
|
385
|
-
const t = fs.readFileSync(path.join(dir, d.name), 'utf8')
|
|
431
|
+
const t = (scope?.read && scope.root === root ? scope.read(r)?.toString('utf8') || '' : fs.readFileSync(path.join(dir, d.name), 'utf8'))
|
|
386
432
|
if (t.length > MAX_FILE) out.partial = true
|
|
387
433
|
out.push([r, t.slice(0, MAX_FILE)])
|
|
388
434
|
} catch { out.partial = true }
|
|
@@ -419,14 +465,16 @@ export function syncFonts(root, rels, add, index, { drop = [] } = {}) {
|
|
|
419
465
|
if (!index) return []
|
|
420
466
|
let realRoot
|
|
421
467
|
try { realRoot = fs.realpathSync(root) } catch { return [] }
|
|
468
|
+
const scope = designWriteScope.getStore()
|
|
422
469
|
const out = []
|
|
423
470
|
for (const rel of rels) {
|
|
424
471
|
if (!/\.(css|html?)$/i.test(rel) || !ownFile(root, realRoot, rel)) continue
|
|
425
472
|
let t
|
|
426
|
-
try { t = fs.readFileSync(path.join(root, rel), 'utf8') } catch { continue }
|
|
473
|
+
try { t = (scope?.read ? scope.read(rel)?.toString('utf8') || '' : fs.readFileSync(path.join(root, rel), 'utf8')) } catch { continue }
|
|
427
474
|
const next = syncFontBlock(t, add, index, { prefix: fontPrefix(rel), isHtml: /\.html?$/i.test(rel), drop })
|
|
428
475
|
if (next === null) continue
|
|
429
|
-
|
|
476
|
+
if (scope?.put) scope.put(rel, next)
|
|
477
|
+
else fs.writeFileSync(path.join(root, rel), next)
|
|
430
478
|
out.push(rel)
|
|
431
479
|
}
|
|
432
480
|
return out
|
|
@@ -525,3 +573,92 @@ export function lintTweaks(root) {
|
|
|
525
573
|
}
|
|
526
574
|
return out
|
|
527
575
|
}
|
|
576
|
+
|
|
577
|
+
// ── 换风格之后:页面里还写死了多少颜色(2.0 试穿风格) ──────────────────────────────
|
|
578
|
+
|
|
579
|
+
// 只数管颜色的属性(阴影、滤镜里的半透明黑不算:换风格不指望它们跟着变)
|
|
580
|
+
const COLOR_PROP = /^(color|background|background-color|border|border-(top|right|bottom|left|block|inline)(-(start|end))?(-color)?|border-color|outline|outline-color|fill|stroke|text-decoration|text-decoration-color|caret-color|accent-color|column-rule|column-rule-color)$/i
|
|
581
|
+
// 写死的颜色:#hex、rgb()/hsl() 这些函数、CSS 颜色名(tomato、navy …;transparent、currentColor 不算)
|
|
582
|
+
const NAMED = 'lightgoldenrodyellow|mediumspringgreen|mediumaquamarine|mediumslateblue|mediumturquoise|mediumvioletred|blanchedalmond|cornflowerblue|darkolivegreen|lightslategray|lightslategrey|lightsteelblue|mediumseagreen|darkgoldenrod|darkslateblue|darkslategray|darkslategrey|darkturquoise|lavenderblush|lightseagreen|palegoldenrod|paleturquoise|palevioletred|rebeccapurple|antiquewhite|darkseagreen|lemonchiffon|lightskyblue|mediumorchid|mediumpurple|midnightblue|darkmagenta|deepskyblue|floralwhite|forestgreen|greenyellow|lightsalmon|lightyellow|navajowhite|saddlebrown|springgreen|yellowgreen|aquamarine|blueviolet|chartreuse|darkorange|darkorchid|darksalmon|darkviolet|dodgerblue|ghostwhite|lightcoral|lightgreen|mediumblue|papayawhip|powderblue|sandybrown|whitesmoke|aliceblue|burlywood|cadetblue|chocolate|darkgreen|darkkhaki|firebrick|gainsboro|goldenrod|indianred|lawngreen|lightblue|lightcyan|lightgray|lightgrey|lightpink|limegreen|mintcream|mistyrose|olivedrab|orangered|palegreen|peachpuff|rosybrown|royalblue|slateblue|slategray|slategrey|steelblue|turquoise|cornsilk|darkblue|darkcyan|darkgray|darkgrey|deeppink|honeydew|lavender|moccasin|seagreen|seashell|crimson|darkred|dimgray|dimgrey|fuchsia|hotpink|magenta|oldlace|skyblue|thistle|bisque|indigo|maroon|orange|orchid|purple|salmon|sienna|silver|tomato|violet|yellow|azure|beige|black|brown|coral|green|ivory|khaki|linen|olive|wheat|white|aqua|blue|cyan|gold|gray|grey|lime|navy|peru|pink|plum|snow|teal|red|tan'
|
|
583
|
+
const LITERAL = new RegExp(`#[0-9a-f]{3,8}\\b|\\b(?:rgba?|hsla?|hwb|oklch|oklab|lab|lch)\\([^()]*\\)|(?<![\\w-])(?:${NAMED})(?![\\w-])`, 'gi')
|
|
584
|
+
// 半透明的纯黑、纯白(遮罩、压暗)不算
|
|
585
|
+
const OVERLAY = /^(?:rgba?|hsla?)\(\s*(?:0\s*,\s*0\s*,\s*0|255\s*,\s*255\s*,\s*255|0\s+0\s+0|255\s+255\s+255|0\s*,\s*0%\s*,\s*0%|0\s*,\s*0%\s*,\s*100%)\s*[,/]\s*(?:0?\.\d+|\d{1,2}%)\s*\)$/i
|
|
586
|
+
const MAX_SCAN = 2 * 1024 * 1024
|
|
587
|
+
|
|
588
|
+
/** 一段声明里写死的颜色数:var(…)(含后备值)、url(…) 里的不算 */
|
|
589
|
+
function literalsIn(decls) {
|
|
590
|
+
let n = 0
|
|
591
|
+
for (const m of String(decls).matchAll(/(?:^|[;{\s])([a-z-]+)\s*:\s*([^;{}]+)/gi)) {
|
|
592
|
+
if (!COLOR_PROP.test(m[1])) continue
|
|
593
|
+
let v = m[2]
|
|
594
|
+
for (let i = 0; i < 4 && /var\(|url\(/i.test(v); i++) v = v.replace(/(?:var|url)\([^()]*(?:\([^()]*\)[^()]*)*\)/gi, ' ')
|
|
595
|
+
for (const x of v.matchAll(LITERAL)) if (!OVERLAY.test(x[0])) n++
|
|
596
|
+
}
|
|
597
|
+
return n
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
/** CSS 文本(注释去掉)里写死的颜色数:自定义变量的声明(--x: #fff)本身就是变量,不算 */
|
|
601
|
+
function literalsInCss(css) {
|
|
602
|
+
return literalsIn(String(css).replace(/\/\*[\s\S]*?\*\//g, ' ').replace(/--[\w-]+\s*:[^;{}]*/g, ' '))
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* 设计目录里写死的颜色:.css 文件、每屏 <style> 和 style="" 里管颜色的属性(SVG 图标、脚本里的不算)。
|
|
607
|
+
* 返回 { n, files: [{ file, n }](多的在前,最多 8 个), dark: 有没有深色版的变量(试穿只换浅色那套) }
|
|
608
|
+
*/
|
|
609
|
+
export function hardColors(root) {
|
|
610
|
+
let realRoot
|
|
611
|
+
try { realRoot = fs.realpathSync(root) } catch { return { n: 0, files: [], dark: false } }
|
|
612
|
+
let comps = []
|
|
613
|
+
try {
|
|
614
|
+
const cdir = path.join(root, 'components')
|
|
615
|
+
if (fs.lstatSync(cdir).isDirectory() && path.dirname(fs.realpathSync(cdir)) === realRoot) {
|
|
616
|
+
comps = fs.readdirSync(cdir).filter((n) => /\.html?$/i.test(n) && fs.lstatSync(path.join(cdir, n)).isFile()).map((n) => 'components/' + n)
|
|
617
|
+
}
|
|
618
|
+
} catch { comps = [] }
|
|
619
|
+
// 每屏 <link> 进来的子目录样式表(styles/tokens.css 这种)也数:和保存试穿认的是同一个边界(目录里、不是软链接、不是点开头的)
|
|
620
|
+
const base = cssFiles(root, realRoot)
|
|
621
|
+
const linked = new Set()
|
|
622
|
+
for (const rel of base) {
|
|
623
|
+
if (!/\.html?$/i.test(rel)) continue
|
|
624
|
+
let text = ''
|
|
625
|
+
try { if (fs.statSync(path.join(root, rel)).size <= MAX_SCAN) text = fs.readFileSync(path.join(root, rel), 'utf8') } catch { continue }
|
|
626
|
+
for (const m of text.replace(/<!--[\s\S]*?-->/g, ' ').matchAll(/<link\b[^>]*>/gi)) {
|
|
627
|
+
if (!/\brel\s*=\s*["']?[^"'>]*\bstylesheet\b/i.test(m[0])) continue
|
|
628
|
+
const h = /\bhref\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i.exec(m[0])
|
|
629
|
+
const href = h ? (h[1] ?? h[2] ?? h[3] ?? '').trim().split(/[?#]/)[0] : ''
|
|
630
|
+
if (!href || /^[a-z][a-z0-9+.-]*:|^\/\//i.test(href)) continue
|
|
631
|
+
let r = ''
|
|
632
|
+
try { r = decodeURIComponent(href) } catch { continue }
|
|
633
|
+
r = href.startsWith('/') ? r.replace(/^\/+/, '') : path.posix.join(path.posix.dirname(rel), r)
|
|
634
|
+
if (!r.startsWith('../')) linked.add(path.posix.normalize(r))
|
|
635
|
+
}
|
|
636
|
+
if (linked.size >= 100) break
|
|
637
|
+
}
|
|
638
|
+
const subCss = (onlyCss(root, realRoot, [...linked], 100) || []).filter((r) => !base.includes(r))
|
|
639
|
+
const files = []
|
|
640
|
+
let n = 0
|
|
641
|
+
let dark = false
|
|
642
|
+
for (const rel of [...new Set([...base, ...subCss, ...comps])].slice(0, 200)) {
|
|
643
|
+
let text
|
|
644
|
+
try {
|
|
645
|
+
if (fs.statSync(path.join(root, rel)).size > MAX_SCAN) continue
|
|
646
|
+
text = fs.readFileSync(path.join(root, rel), 'utf8')
|
|
647
|
+
} catch { continue }
|
|
648
|
+
let k = 0
|
|
649
|
+
if (/\.css$/i.test(rel)) {
|
|
650
|
+
k = literalsInCss(text)
|
|
651
|
+
if (/\[data-theme\s*=\s*["']?dark|prefers-color-scheme\s*:\s*dark/i.test(text)) dark = true
|
|
652
|
+
} else {
|
|
653
|
+
const html = text.replace(/<!--[\s\S]*?-->/g, ' ').replace(/<script\b[\s\S]*?<\/script\s*>/gi, ' ').replace(/<svg\b[\s\S]*?<\/svg\s*>/gi, ' ')
|
|
654
|
+
for (const m of html.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style\s*>/gi)) {
|
|
655
|
+
k += literalsInCss(m[1])
|
|
656
|
+
if (/\[data-theme\s*=\s*["']?dark|prefers-color-scheme\s*:\s*dark/i.test(m[1])) dark = true
|
|
657
|
+
}
|
|
658
|
+
for (const m of html.matchAll(/\sstyle\s*=\s*(?:"([^"]*)"|'([^']*)')/gi)) k += literalsIn(';' + (m[1] ?? m[2] ?? '').replace(/"/g, '"'))
|
|
659
|
+
}
|
|
660
|
+
if (k) { files.push({ file: rel, n: k }); n += k }
|
|
661
|
+
}
|
|
662
|
+
files.sort((a, b) => b.n - a.n)
|
|
663
|
+
return { n, files: files.slice(0, 8), dark }
|
|
664
|
+
}
|
package/lib/works.js
CHANGED
|
@@ -17,6 +17,7 @@ import crypto from 'node:crypto'
|
|
|
17
17
|
import fs from 'node:fs'
|
|
18
18
|
import os from 'node:os'
|
|
19
19
|
import path from 'node:path'
|
|
20
|
+
import { directoryId, fileId } from './design-scope.js'
|
|
20
21
|
|
|
21
22
|
/** 一套装好的设计系统最多记多少个旧页面哈希(去重后;只有退回旧版、或就地更新时才会加) */
|
|
22
23
|
export const PAST_MAX = 4000
|
|
@@ -50,7 +51,7 @@ function realOf(p) {
|
|
|
50
51
|
return path.resolve(p)
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
export function createLibrary({ dir = LIBRARY_DIR, log = () => {} } = {}) {
|
|
54
|
+
export function createLibrary({ dir = LIBRARY_DIR, log = () => {}, beforeMove = () => {} } = {}) {
|
|
54
55
|
const file = path.join(dir, 'works.json')
|
|
55
56
|
let cache = null
|
|
56
57
|
let cacheKey = ''
|
|
@@ -75,6 +76,15 @@ export function createLibrary({ dir = LIBRARY_DIR, log = () => {} } = {}) {
|
|
|
75
76
|
try { fs.copyFileSync(file, `${file}.bad-${Date.now()}`) } catch { /* 算了 */ }
|
|
76
77
|
}
|
|
77
78
|
}
|
|
79
|
+
let upgraded = false
|
|
80
|
+
for (const w of data.works) {
|
|
81
|
+
if (w.designId && w.workId) continue
|
|
82
|
+
w.scope = w.file ? 'file' : 'directory'
|
|
83
|
+
w.designId ||= w.file ? fileId(realOf(w.file)) : directoryId(path.resolve(w.dir))
|
|
84
|
+
w.workId ||= w.designId.split('-').at(-1)
|
|
85
|
+
upgraded = true
|
|
86
|
+
}
|
|
87
|
+
if (upgraded) { save(data); return cache }
|
|
78
88
|
cache = data
|
|
79
89
|
cacheKey = key
|
|
80
90
|
hashSet = null
|
|
@@ -123,6 +133,66 @@ export function createLibrary({ dir = LIBRARY_DIR, log = () => {} } = {}) {
|
|
|
123
133
|
return hashSet.size > 0 && hashSet.has(sha256(buf))
|
|
124
134
|
}
|
|
125
135
|
|
|
136
|
+
/**
|
|
137
|
+
* 2.0 项目规矩:这套设计(按目录)的 rules.md 是不是别人的设计带来的、原样没改(buf = 现在的内容,没有给 null)。
|
|
138
|
+
* 只比这套自己记下的(别的设计里一模一样的字不算)。新装的落地时记了 rules.md 的哈希(包里没有记空串);
|
|
139
|
+
* 旧版本装的没记过:2.0 之前没有项目规矩,第一次看到时目录里已有的 rules.md 只可能是包里带的(或市场更新写的),
|
|
140
|
+
* 补记它的哈希;那时没有就记空串,以后用户写的都算用户的。设计系统更新前那几版的也算(pastHashes)
|
|
141
|
+
*/
|
|
142
|
+
function rulesFromPackage(root, buf) {
|
|
143
|
+
const w = get(root)
|
|
144
|
+
if (!w || (w.trust !== 'market' && w.trust !== 'zip')) {
|
|
145
|
+
// 没登记成导入的、却带着导入来源(导入的设计整个复制了一份、拿到别的电脑上;设计系统 system.json 记着市场来源):
|
|
146
|
+
// 核对不了是不是原样,规矩先当模板作者的;用户在右侧栏存过这一版就算采纳(adoptRules)。自己从头做的设计没有来源记录,算用户的
|
|
147
|
+
if (!buf) return false
|
|
148
|
+
if (w && mineOf(w).includes(sha256(buf))) return false
|
|
149
|
+
return importedFrom(root)
|
|
150
|
+
}
|
|
151
|
+
const key = Object.keys(w.hashes || {}).find((k) => /^rules\.md$/i.test(k))
|
|
152
|
+
let rec = key ? w.hashes[key] : null
|
|
153
|
+
if (rec === null) {
|
|
154
|
+
let cur = null
|
|
155
|
+
try { cur = fs.readFileSync(path.join(root, 'rules.md')) } catch { /* 没有 */ }
|
|
156
|
+
rec = cur ? sha256(cur) : ''
|
|
157
|
+
put(root, { hashes: { ...(w.hashes || {}), 'rules.md': rec } })
|
|
158
|
+
}
|
|
159
|
+
if (!buf) return false
|
|
160
|
+
const h = sha256(buf)
|
|
161
|
+
return (!!rec && rec === h) || (Array.isArray(w.pastHashes) && w.pastHashes.flat().includes(h))
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** 用户采纳过的几版规矩的哈希(旧数据是一个字符串) */
|
|
165
|
+
function mineOf(w) {
|
|
166
|
+
const m = w && w.rulesMine
|
|
167
|
+
return Array.isArray(m) ? m : typeof m === 'string' && m ? [m] : []
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* 目录里写着从哪导入的吗:design.json 的 from(导入时写的)、system.json 的 market(装设计系统时写的)。
|
|
172
|
+
* 带 BOM 的也认;文件在、却解析不了的,看原文里有没有这个键(宁可当模板的,别把作者的话当用户要求)
|
|
173
|
+
*/
|
|
174
|
+
function importedFrom(root) {
|
|
175
|
+
const obj = (f, k) => {
|
|
176
|
+
let raw
|
|
177
|
+
try { raw = fs.readFileSync(path.join(root, f), 'utf8').replace(/^\uFEFF/, '') } catch { return false }
|
|
178
|
+
try { const m = JSON.parse(raw); return !!m && typeof m[k] === 'object' && m[k] !== null && !Array.isArray(m[k]) } catch { return new RegExp(`"${k}"\\s*:\\s*\\{`).test(raw) }
|
|
179
|
+
}
|
|
180
|
+
return obj('design.json', 'from') || obj('system.json', 'market')
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** 用户在右侧栏存了这套的规矩:记下这一版(带导入来源的副本,存过的那版算用户采纳的) */
|
|
184
|
+
function adoptRules(root) {
|
|
185
|
+
let buf = null
|
|
186
|
+
try { buf = fs.readFileSync(path.join(root, 'rules.md')) } catch { /* 清空了 */ }
|
|
187
|
+
const w = get(root)
|
|
188
|
+
if (w && (w.trust === 'market' || w.trust === 'zip')) return // 登记过的导入按落地时的哈希认,改过就是用户的
|
|
189
|
+
if (!buf) return // 清空了:下次有人写的规矩照样先看来源
|
|
190
|
+
const h = sha256(buf)
|
|
191
|
+
const mine = mineOf(w).filter((x) => x !== h)
|
|
192
|
+
// 存过的每一版都记着(最多 50 版):从版本里退回自己存过的旧版,还认得是自己的
|
|
193
|
+
put(root, { rulesMine: [...mine, h].slice(-50) })
|
|
194
|
+
}
|
|
195
|
+
|
|
126
196
|
/** 这个目录(或它里面)是别人做的设计吗(SVG 当页面打开时也加规矩) */
|
|
127
197
|
function strictRoot(root) {
|
|
128
198
|
index()
|
|
@@ -161,7 +231,7 @@ export function createLibrary({ dir = LIBRARY_DIR, log = () => {} } = {}) {
|
|
|
161
231
|
/** 找一套(按目录) */
|
|
162
232
|
function get(d) {
|
|
163
233
|
const r = realOf(d)
|
|
164
|
-
return load().works.find((w)
|
|
234
|
+
return load().works.find(w => w.file ? realOf(w.file) === r : realOf(w.dir) === r) || null
|
|
165
235
|
}
|
|
166
236
|
|
|
167
237
|
/** 记一套(有就合并):别人做的要带 trust 和 hashes */
|
|
@@ -169,9 +239,10 @@ export function createLibrary({ dir = LIBRARY_DIR, log = () => {} } = {}) {
|
|
|
169
239
|
const data = load()
|
|
170
240
|
const r = realOf(d)
|
|
171
241
|
const now = Date.now()
|
|
172
|
-
let w = data.works.find((x)
|
|
242
|
+
let w = data.works.find(x => x.file ? realOf(x.file) === r : realOf(x.dir) === r)
|
|
173
243
|
if (!w) {
|
|
174
|
-
|
|
244
|
+
const designId = newId(data.works, directoryId(r))
|
|
245
|
+
w = { dir: path.resolve(d), designId, workId: designId.split('-').at(-1), scope: 'directory', added: now }
|
|
175
246
|
data.works.push(w)
|
|
176
247
|
}
|
|
177
248
|
for (const [k, v] of Object.entries(info || {})) {
|
|
@@ -183,6 +254,35 @@ export function createLibrary({ dir = LIBRARY_DIR, log = () => {} } = {}) {
|
|
|
183
254
|
return w
|
|
184
255
|
}
|
|
185
256
|
|
|
257
|
+
const newId = (works, preferred) => works.some(w => w.designId === preferred)
|
|
258
|
+
? preferred.split('-')[0] + '-' + crypto.randomBytes(8).toString('hex') : preferred
|
|
259
|
+
|
|
260
|
+
function resolveTarget(target, { restore = false } = {}) {
|
|
261
|
+
if (target.kind !== 'file') return target
|
|
262
|
+
const r = realOf(target.root)
|
|
263
|
+
const file = target.file ? path.join(r, path.basename(target.file)) : ''
|
|
264
|
+
const records = load().works
|
|
265
|
+
const byCurrent = w => w.file ? !target.directory && file && realOf(w.file) === file : target.directory && realOf(w.dir) === r
|
|
266
|
+
const byAlias = w => restore && w.aliases?.includes(w.file ? file : r) && (w.file ? !target.directory : target.directory)
|
|
267
|
+
const legacyMarket = restore && !target.scope && !target.designId && file && records.find(w =>
|
|
268
|
+
!w.file && w.trust === 'market' && realOf(w.dir) === r && Object.hasOwn(w.hashes || {}, path.basename(file)))
|
|
269
|
+
const w = records.find(w => w.designId === target.designId) || legacyMarket || records.find(byCurrent) || records.find(byAlias)
|
|
270
|
+
if (!w) {
|
|
271
|
+
const preferred = target.directory ? directoryId(r) : fileId(file)
|
|
272
|
+
return { ...target, designId: newId(records, preferred) }
|
|
273
|
+
}
|
|
274
|
+
const root = realOf(w.dir) === r ? path.resolve(target.root) : w.dir
|
|
275
|
+
let entry = file && path.join(root, path.basename(file))
|
|
276
|
+
if (w.file) entry = path.join(root, path.basename(w.file))
|
|
277
|
+
else if (!entry || !fs.existsSync(entry)) {
|
|
278
|
+
let list
|
|
279
|
+
try { list = fs.readdirSync(root, { withFileTypes: true }) } catch { list = [] }
|
|
280
|
+
const first = list.find(d => d.isFile() && /^[^._].*\.html?$/i.test(d.name))
|
|
281
|
+
entry = first ? path.join(root, first.name) : ''
|
|
282
|
+
}
|
|
283
|
+
return { ...target, root, file: entry, directory: !w.file, designId: w.designId }
|
|
284
|
+
}
|
|
285
|
+
|
|
186
286
|
/** 移出列表:只藏起来(不动文件夹;别人做的那份信任记录要留着,不然藏起来的设计就按普通预览了) */
|
|
187
287
|
function hide(d) {
|
|
188
288
|
const w = get(d)
|
|
@@ -198,26 +298,30 @@ export function createLibrary({ dir = LIBRARY_DIR, log = () => {} } = {}) {
|
|
|
198
298
|
*/
|
|
199
299
|
function sync(saved, { home = os.homedir() } = {}) {
|
|
200
300
|
const data = load()
|
|
201
|
-
const byReal = new Map(data.works.map((w) => [realOf(w.dir), w]))
|
|
202
301
|
const homeReal = realOf(home)
|
|
203
302
|
let changed = false
|
|
204
303
|
for (const rec of Object.values(saved || {})) {
|
|
205
|
-
const t = rec
|
|
206
|
-
if (
|
|
304
|
+
const t = rec?.target
|
|
305
|
+
if (t?.kind !== 'file' || typeof t.root !== 'string') continue
|
|
207
306
|
if (!(rec.design || rec.source === 'tool' || rec.source === 'user')) continue
|
|
208
307
|
const r = realOf(t.root)
|
|
209
308
|
if (r === homeReal || path.dirname(r) === r) continue
|
|
210
309
|
const at = Number(rec.at) || 0
|
|
211
|
-
|
|
310
|
+
const directory = t.directory || (!t.scope && !t.designId)
|
|
311
|
+
const location = directory ? r : t.file && realOf(t.file)
|
|
312
|
+
if (!location) continue
|
|
313
|
+
const sameLocation = w => directory ? !w.file && realOf(w.dir) === r : w.file && realOf(w.file) === location
|
|
314
|
+
let w = data.works.find(w => t.designId && w.designId === t.designId) || data.works.find(sameLocation)
|
|
315
|
+
if (!w && !t.designId) w = data.works.find(w => w.aliases?.includes(location))
|
|
212
316
|
if (!w) {
|
|
213
|
-
try { if (!fs.statSync(r).isDirectory()) continue } catch { continue }
|
|
214
|
-
|
|
317
|
+
try { if (directory ? !fs.statSync(r).isDirectory() : !fs.statSync(location).isFile()) continue } catch { continue }
|
|
318
|
+
const designId = t.designId || newId(data.works, directory ? directoryId(r) : fileId(location))
|
|
319
|
+
w = { dir: r, ...(directory ? {} : { file: location }), designId, workId: designId.split('-').at(-1),
|
|
320
|
+
scope: directory ? 'directory' : 'file', added: at || Date.now(), seen: at, ...(rec.kind ? { kind: rec.kind } : {}) }
|
|
215
321
|
data.works.push(w)
|
|
216
|
-
byReal.set(r, w)
|
|
217
322
|
changed = true
|
|
218
323
|
continue
|
|
219
324
|
}
|
|
220
|
-
// 最近看到的时间一分钟内不重复写(每次切屏、换视图都会记一次)
|
|
221
325
|
if (at > (w.seen || 0) + 60000 || (w.hidden && at > (w.hiddenAt || 0))) {
|
|
222
326
|
w.seen = at
|
|
223
327
|
if (rec.kind && !w.kind) w.kind = rec.kind
|
|
@@ -233,17 +337,45 @@ export function createLibrary({ dir = LIBRARY_DIR, log = () => {} } = {}) {
|
|
|
233
337
|
function move(from, to) {
|
|
234
338
|
const data = load()
|
|
235
339
|
const r = realOf(from)
|
|
236
|
-
const
|
|
237
|
-
if (
|
|
340
|
+
const i = data.works.findIndex(x => realOf(x.file || x.dir) === r)
|
|
341
|
+
if (i < 0) return null
|
|
342
|
+
const previous = data.works[i]
|
|
238
343
|
const t = realOf(to)
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
344
|
+
const stat = (p) => {
|
|
345
|
+
try { return fs.statSync(p, { bigint: true }) } catch { return null }
|
|
346
|
+
}
|
|
347
|
+
const target = stat(t)
|
|
348
|
+
const occupied = data.works.some((other, j) => {
|
|
349
|
+
if (j === i) return false
|
|
350
|
+
if (!!other.file !== !!previous.file) return false
|
|
351
|
+
const otherDir = realOf(other.file || other.dir)
|
|
352
|
+
if (otherDir === t) return true
|
|
353
|
+
// 在不区分大小写的卷上,realpath 仍可能保留调用者提供的拼写。
|
|
354
|
+
if (!target?.ino) return false
|
|
355
|
+
const otherStat = stat(otherDir)
|
|
356
|
+
return otherStat?.dev === target.dev && otherStat.ino === target.ino
|
|
357
|
+
})
|
|
358
|
+
if (occupied) {
|
|
359
|
+
throw Object.assign(new Error('所选目录已有作品,请重新选择。'), { code: 'workDestinationConflict' })
|
|
360
|
+
}
|
|
361
|
+
beforeMove(previous, t)
|
|
362
|
+
const w = { ...previous, dir: previous.file ? path.dirname(path.resolve(to)) : path.resolve(to), ...(previous.file ? { file: path.resolve(to) } : {}),
|
|
363
|
+
aliases: [...new Set([...(previous.aliases || []), r])].filter(alias => alias !== t), updated: Date.now() }
|
|
242
364
|
delete w.hidden
|
|
243
365
|
delete w.hiddenAt
|
|
244
|
-
|
|
366
|
+
const works = data.works.slice()
|
|
367
|
+
works[i] = w
|
|
368
|
+
save({ ...data, works })
|
|
245
369
|
return w
|
|
246
370
|
}
|
|
247
371
|
|
|
248
|
-
|
|
372
|
+
function stagePast(root, hashes) {
|
|
373
|
+
if (!hashes.length) return
|
|
374
|
+
const w = get(root)
|
|
375
|
+
const previous = w?.pastHashes
|
|
376
|
+
if (!addPast(root, hashes)) return
|
|
377
|
+
return () => put(root, { pastHashes: previous })
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
return { resolveTarget, stagePast, strictHtml, rulesFromPackage, adoptRules, strictRoot, strictVersions, trustRev, addPast, get, put, hide, move, sync, list: () => load().works.slice(), file }
|
|
249
381
|
}
|
package/locale/auto/en.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Open previews automatically",
|
|
4
|
-
"description": "When the model writes a design HTML file or starts a dev server, the Design Studio sidebar opens the preview on its own. Turned off, the
|
|
4
|
+
"description": "When the model writes a design HTML file or starts a dev server, the Design Studio sidebar opens the preview on its own. Turned off, the home page only shows a \"Just written: …\" note with a Preview button."
|
|
5
5
|
}
|
|
6
6
|
}
|
package/locale/auto/zh.json
CHANGED
package/locale/en.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Design Studio",
|
|
4
|
-
"description": "A design workbench in the right sidebar: web, app, mini program and poster screens generate on a canvas inside device frames; click an element or annotate it to have the model change it, open existing HTML pages to keep working on them, drag sliders to tweak design tokens across every screen, compare and roll back versions, extract a brand's design system from a website, turn a design into React / Vue / HTML code and diff it pixel by pixel,
|
|
4
|
+
"description": "A design workbench in the right sidebar: web, app, mini program and poster screens generate on a canvas inside device frames; click an element or annotate it to have the model change it, open existing HTML pages to keep working on them, drag sliders to tweak design tokens across every screen, compare and roll back versions, extract a brand's design system from a website, turn a design into React / Vue / HTML code and diff it pixel by pixel, set a viewport for each page, check multiple devices, reuse templates, reference images and brand systems from the asset library, and export images, PDF, PowerPoint, HTML or editable packages.",
|
|
5
5
|
"detail": "README.en.md"
|
|
6
6
|
}
|
|
7
7
|
}
|
package/locale/offline/en.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Design library offline",
|
|
4
|
-
"description": "When on, the library
|
|
4
|
+
"description": "When on, the asset library uses no network and shows only designs already downloaded; your designs and Favorites still work. When off, the Gallery only downloads designs from npm mirrors (npmmirror, Tencent Cloud, Huawei Cloud, npmjs); nothing is uploaded or tracked."
|
|
5
5
|
}
|
|
6
6
|
}
|
package/locale/offline/zh.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
|
-
"title": "
|
|
4
|
-
"description": "
|
|
3
|
+
"title": "素材库不联网",
|
|
4
|
+
"description": "打开后,素材库不访问任何网址,只显示已经下载过的;「我的」里的设计和收藏照常用。关着时市场只从 npm 镜像(npmmirror、腾讯云、华为云、npmjs)下载设计,不上传任何东西,也不统计。"
|
|
5
5
|
}
|
|
6
6
|
}
|
package/locale/zh.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "设计工作台",
|
|
4
|
-
"description": "右侧栏的设计工作台:网页、App、小程序、海报一屏屏生成在画布上,套好设备框;点一下元素或用标注圈出来就让模型改那里,已有的 HTML 页面也能打开接着改;拖滑块微调设计变量全屏一起变,版本能对比回退;能从网站提取品牌设计系统,也能把设计转成 React / Vue / HTML
|
|
4
|
+
"description": "右侧栏的设计工作台:网页、App、小程序、海报一屏屏生成在画布上,套好设备框;点一下元素或用标注圈出来就让模型改那里,已有的 HTML 页面也能打开接着改;拖滑块微调设计变量全屏一起变,版本能对比回退;能从网站提取品牌设计系统,也能把设计转成 React / Vue / HTML 代码并逐像素对比;可逐屏设置画幅,用多设备检查适配效果,从素材库复用模板、参考图和品牌设计系统,导出图片、PDF、PPT、HTML 或设计包。",
|
|
5
5
|
"detail": "README.md"
|
|
6
6
|
}
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-design-studio",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test --test-concurrency=1 test/*.mjs"
|
|
@@ -54,8 +54,9 @@
|
|
|
54
54
|
"cordis.patch.yml",
|
|
55
55
|
"README.md",
|
|
56
56
|
"README.en.md",
|
|
57
|
+
"assets/art/*.webp",
|
|
57
58
|
"assets/hero-sm.jpg",
|
|
58
|
-
"assets/demo.gif",
|
|
59
|
+
"assets/demo.gif", "assets/showcase", "assets/motion", "THIRD_PARTY_NOTICES.md",
|
|
59
60
|
"gallery-seed"
|
|
60
61
|
],
|
|
61
62
|
"icon": "./icon.svg",
|