dsh-design-studio 0.28.0 → 0.29.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 -2
- package/README.md +2 -2
- package/cordis.patch.yml +1 -1
- package/lib/client.js +212 -53
- package/lib/core.js +346 -28
- package/lib/edits.js +69 -0
- package/lib/handoff.js +19 -4
- package/lib/htmlpack.js +1 -1
- package/lib/index.js +177 -21
- package/lib/picker.js +48 -3
- package/package.json +1 -1
- package/skills/ui-design/SKILL.md +1 -1
package/README.en.md
CHANGED
|
@@ -38,11 +38,11 @@ If DSH can't reach the npm registry, it falls back to a mirror in China. To upda
|
|
|
38
38
|
## What it does
|
|
39
39
|
|
|
40
40
|
- **Pick from three directions:** three different first screens side by side, then the full set in the one you pick. Any single screen can also get two alternative takes.
|
|
41
|
-
- **Click to edit:** click an element or drag over an area, and a small chip lands in the input (hover it for details); just add how to change it. Markup, style changes, style cards and check lists land as chips too, not walls of text. The model still gets the full location and styles. Changed spots flash in the preview. You can also draw circles, arrows and notes right on the page and hand the marked-up screenshot to the model, or copy it to paste elsewhere.
|
|
41
|
+
- **Click to edit:** click an element or drag over an area, and a small chip lands in the input (hover it for details); just add how to change it. Markup, style changes, style cards and check lists land as chips too, not walls of text. The model still gets the full location and styles. Changed spots flash in the preview. You can also draw circles, arrows and notes right on the page and hand the marked-up screenshot to the model, or copy it to paste elsewhere. Adjust style can apply a change to every screen at once, and when you edit a design by hand in the sidebar, the model is told before its next step so it won't undo your edits.
|
|
42
42
|
- **Open what you have:** click "Browse…" on the empty page to pick an HTML file, or drop an HTML file or folder onto the sidebar (desktop app); you can also type a path or a dev-server port.
|
|
43
43
|
- **Design check:** one click finds overflowing text, low contrast, small tap targets and tiny text, marked right on the page. In Design mode the model also checks its own work and fixes what it finds.
|
|
44
44
|
- **Versions and compare:** every turn is saved; drag a slider to compare, and go back to any version.
|
|
45
|
-
- **Export and phone preview:** showcase images, PDF and PowerPoint (links between screens still work), or a clickable HTML demo that opens with a double-click (device frame included, ready to send to a client), or share it as a temporary public link (beta; opens in WeChat or any browser, closes after 2 hours); scan a QR code to see it on your phone at real size. Slides and posters larger than the default canvas now use the page's real size. You can also set it by adding `WIDTHxHEIGHT` after the type, for example `<meta name="dsh-design" content="slides 1440x810">`. Export options let you pick the page size (16:9, 4:3, A3 landscape or custom), what each page shows (one screen, full page or a set height) and two screens per page. If anything would be cut off, you get a checklist first, with a one-click fix that fits the canvas to the content.
|
|
45
|
+
- **Export and phone preview:** showcase images, PDF and PowerPoint (links between screens still work), or a clickable HTML demo that opens with a double-click (device frame included, ready to send to a client), or share it as a temporary public link (beta; opens in WeChat or any browser, closes after 2 hours); designs with hundreds of screens export in full (up to 1000); scan a QR code to see it on your phone at real size. Slides and posters larger than the default canvas now use the page's real size. You can also set it by adding `WIDTHxHEIGHT` after the type, for example `<meta name="dsh-design" content="slides 1440x810">`. Export options let you pick the page size (16:9, 4:3, A3 landscape or custom), what each page shows (one screen, full page or a set height) and two screens per page. If anything would be cut off, you get a checklist first, with a one-click fix that fits the canvas to the content.
|
|
46
46
|
- **Diagrams:** mind maps, technical route charts (the kind in grant proposals and theses), product roadmaps and system architecture diagrams. Lines, branches and arrows are laid out for you and re-flow when you change text or add nodes; colors follow the design style, and a high-resolution PNG or PDF export drops straight into Word or PowerPoint. For grant-proposal and final-report frameworks, the model first lists how the parts relate (which problem maps to which task) for you to confirm, then draws labelled arrows between the blocks, in a bold 3D-gradient "proposal" style by default or after a reference image you give it.
|
|
47
47
|
- **DSH plugins:** design a plugin inside the real DSH desktop frame (left sidebar entry, settings section, session tab or right sidebar panel, in light and dark). Only the plugin area is designed, so you see exactly how it looks once installed; the design check warns if the frame gets changed.
|
|
48
48
|
- **Design library and gallery:** everything you've designed, plus saved references and styles, lives in the Library. Browse templates, design systems and style cards others shared, and "Start from this" copies one for you to keep editing. Share your own with "Share to the gallery": it's checked, zipped and submitted on a web page, and listed once reviewed. The gallery catalog comes from npm mirrors and is used only when its signature and checksums match; to keep it offline, turn on "Design library offline" on the Plugins page.
|
package/README.md
CHANGED
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
## 能做什么
|
|
39
39
|
|
|
40
40
|
- **三个方向挑着做**:先出三个风格不同的首屏并排比,挑中再做全套;单独一屏也能「再出两版」。
|
|
41
|
-
-
|
|
41
|
+
- **点一下就改**:点元素或框一块区域,输入框里出现一个小标签(悬停看详情),你只要补一句怎么改;标注、调样式、风格、体检清单这些放进输入框的也都是小标签,不再是一大段字;发出去模型拿到完整的位置和样式。改过的地方在预览里闪一下。也能直接在页面上画圈、画箭头、写字,拼成一张图交给模型,或者复制下来贴到别处。调样式可以「各屏一起改」;你在右侧栏亲手改过的地方,模型下一步会先知道,不会改回去。
|
|
42
42
|
- **打开已有的页面**:首页输入框左边的「+」→「打开已有的 HTML…」选一个,或把 HTML 文件 / 文件夹拖进右侧栏就能预览(桌面版);也能输路径或开发服务器端口。
|
|
43
43
|
- **设计体检**:一键查文字溢出、对比度不够、按钮太小、字太小,问题直接标在页面上;模型做完也会自己查一遍再改。
|
|
44
44
|
- **版本和对比**:每轮自动存一版,左右拖动对比,随时回到任意一版。
|
|
45
|
-
- **导出和手机上看**:导出展示图、PDF、PPT(屏和屏之间的跳转照样能点),或一个双击就能开的 HTML 演示(带外壳、点得动,发给客户直接看),也能临时发个公网链接(实验,微信里点开就能看,2
|
|
45
|
+
- **导出和手机上看**:导出展示图、PDF、PPT(屏和屏之间的跳转照样能点),或一个双击就能开的 HTML 演示(带外壳、点得动,发给客户直接看),也能临时发个公网链接(实验,微信里点开就能看,2 小时自动关),几百屏的设计也全部导出(最多 1000 屏);扫码在手机上按真机尺寸看。页面比默认画幅大的幻灯片、海报,画幅自动跟页面走;也可以在类型后面跟 `宽x高` 指定,比如 `<meta name="dsh-design" content="slides 1440x810">`。导出选项里可以选版面(16:9、4:3、A3 横向、自定义)、每页取景(一屏、整页、指定高度)和每页拼 2 屏;有内容会被裁时,导出前先给一张清单,可以一键按内容改画幅。
|
|
46
46
|
- **图表**:思维导图、技术路线图(申报书、开题报告那种)、产品路线图、系统架构图。连线、分叉、箭头自动排好,改字、加节点自己重排;配色跟着设计风格走,导出高清 PNG 或 PDF 贴进 Word / PPT。申报书、结题报告的框架图先帮你理清「哪个问题对应哪项内容」请你确认再画,版块之间画出带关系词的箭头;默认是立体渐变的「申报书炫酷样式」,也能照你给的参考图画。
|
|
47
47
|
- **DSH 插件**:给 DSH 做插件界面时,四周直接套上 DSH 桌面端的外框(左侧栏入口、设置分区、会话标签页、右侧栏面板四个位置,浅色、深色都有),只设计插件那一块,一眼看出装进 DSH 是什么样;外框被改了体检会提醒。
|
|
48
48
|
- **设计库和设计市场**:以前做过的设计、收的参考图和风格都在「设计库」里;市场里逛大家分享的模板、设计系统和风格卡,点「用这个开始」复制一份接着改。自己做的点「分享到设计市场」,查过打成 zip,在网页里交上去,审过就上架。市场目录从 npm 镜像取,签了名、核对过才用;不想让它联网,在插件页打开「设计库不联网」。
|
package/cordis.patch.yml
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
config:
|
|
38
38
|
prefix: |-
|
|
39
39
|
You are a design agent powered by the {{model}} model. You design user interfaces and visuals — web pages, app and tablet screens, WeChat mini programs, posters and social images, slides, emails, components, and diagrams (mind maps, technical routes, roadmaps, architecture) — and build them as real HTML/CSS, or inside the user's front-end project.
|
|
40
|
-
Before designing, load the ui-design skill and follow its process and self-check list. For a new design, first ask the two or three questions that matter and show three clearly different directions of one key screen, as the skill describes, unless the user asked you to just build it. Once the first HTML file is written, or a dev server is up, call preview_page so the user can watch the design live in the Design Studio sidebar; later edits refresh on their own. After writing or changing screens, call check_design to measure them at real sizes and fix what it lists, and call look_design to see real screenshots for the visual pass; do not build your own inspection pages, servers or browser screenshots. Stop after at most three measure-and-fix rounds and tell the user what is left. When a message starts with an element or region the user selected in the preview, or with a design-check list, change exactly those parts in the source. If the user points you at their own website or project as the brand to follow, call extract_design_system; when the ui-design skill names a default design system, build new designs on its tokens.css and components.css. When a message asks to turn the design into real code, call handoff_design, follow its HANDOFF.md, and after each screen call compare_design until it matches. If the user only wants an answer shown as a page (a comparison, table, checklist, chart or calculator) and the show_page tool is available, call show_page instead of this design process.
|
|
40
|
+
Before designing, load the ui-design skill and follow its process and self-check list. For a new design, first ask the two or three questions that matter and show three clearly different directions of one key screen, as the skill describes, unless the user asked you to just build it. Once the first HTML file is written, or a dev server is up, call preview_page so the user can watch the design live in the Design Studio sidebar; later edits refresh on their own. After writing or changing screens, call check_design to measure them at real sizes and fix what it lists, and call look_design to see real screenshots for the visual pass; do not build your own inspection pages, servers or browser screenshots. Stop after at most three measure-and-fix rounds and tell the user what is left. When a message starts with an element or region the user selected in the preview, or with a design-check list, change exactly those parts in the source. The user can also edit the design by hand in the sidebar (styles, text, sliders, restoring a version), so re-read the current files before changing a screen or building it into code instead of relying on what you wrote earlier. If the user points you at their own website or project as the brand to follow, call extract_design_system; when the ui-design skill names a default design system, build new designs on its tokens.css and components.css. When a message asks to turn the design into real code, call handoff_design, follow its HANDOFF.md, and after each screen call compare_design until it matches. If the user only wants an answer shown as a page (a comparison, table, checklist, chart or calculator) and the show_page tool is available, call show_page instead of this design process.
|
|
41
41
|
- id: agent-instructions
|
|
42
42
|
name: '@deepseek-ai/dsh-agent-instructions'
|
|
43
43
|
config:
|
package/lib/client.js
CHANGED
|
@@ -221,6 +221,9 @@ window.__ModuleLoader__.load({
|
|
|
221
221
|
xoFail: '{n} 屏没量到,结果可能不全',
|
|
222
222
|
xoAgain: '重新检查',
|
|
223
223
|
xoGone: '设计换了,这次导出取消了',
|
|
224
|
+
xoJobGone: '导出中断了(等太久或 DSH 重启过),请重新导出',
|
|
225
|
+
styleMoved: '设计换了,这次调的样式没保存',
|
|
226
|
+
xoCut: '一次最多导出 1000 屏,最后 {n} 屏没导出',
|
|
224
227
|
xoResize: '按内容改画幅({size})',
|
|
225
228
|
xoFull: '取景改成整页',
|
|
226
229
|
xoLayout: '版面',
|
|
@@ -336,6 +339,8 @@ window.__ModuleLoader__.load({
|
|
|
336
339
|
ckItem: '{i}. {type}:{where}{text} — {detail}',
|
|
337
340
|
ckQuote: '「{text}」',
|
|
338
341
|
exporting: '正在导出…',
|
|
342
|
+
exportingN: '正在截图 {i}/{n}…',
|
|
343
|
+
xoCheckingN: '先检查一遍有没有内容被裁 {i}/{n}…',
|
|
339
344
|
exported: '已导出 {name}',
|
|
340
345
|
exportedCopied: '已导出 {name},也复制到剪贴板了',
|
|
341
346
|
exportFail: '导出失败:{msg}',
|
|
@@ -451,6 +456,11 @@ window.__ModuleLoader__.load({
|
|
|
451
456
|
styleNoWrite: '开发服务器的页面不能直接保存,发到对话让模型改',
|
|
452
457
|
styleBusyTip: '模型在干活,等它停了再保存',
|
|
453
458
|
styleSaved: '样式已保存到 {file}',
|
|
459
|
+
styleShare: '各屏一起改',
|
|
460
|
+
styleShareAt: '写进 {file} 的 {sel}',
|
|
461
|
+
styleShareTip: '用这条样式的元素都跟着变(这一屏有 {n} 处);不勾就只改选中的这一个',
|
|
462
|
+
styleSavedRule: '已写进 {file} 的 {sel},各屏一起变',
|
|
463
|
+
styleSavedOthers: '已写进 {file} 的 {sel};另有 {n} 屏的这个元素之前单独保存过,还是那时的值',
|
|
454
464
|
styleMiss: '源码里没找到这个元素(可能是脚本生成的),改成发到对话',
|
|
455
465
|
styleN: '改了 {n} 项',
|
|
456
466
|
styleAskText: '〔调样式〕{name}({sel}):{list}。{rules}把这些写进它的样式规则({where};能用设计变量就用设计变量),别写成行内 style。\n',
|
|
@@ -537,6 +547,7 @@ window.__ModuleLoader__.load({
|
|
|
537
547
|
pubDlCancel: '取消下载',
|
|
538
548
|
pubGone: '设计换了(或者现在看的不是本地文件),没有生成。确认要放的是这套设计再点一次。',
|
|
539
549
|
pubScreens: '会放出这 {n} 屏:{names}。之后新加的屏不会自动放出去。',
|
|
550
|
+
pubMoreNames: '…等',
|
|
540
551
|
pubShared: '放出去的是这 {n} 屏:{names}',
|
|
541
552
|
pubBrokenShort: '对方现在打不开',
|
|
542
553
|
pubBroken: '对方现在打开会看到「暂时打不开」:{why}。改好后对方刷新就行,也可以先停止分享。',
|
|
@@ -1203,6 +1214,9 @@ window.__ModuleLoader__.load({
|
|
|
1203
1214
|
xoFail: '{n} screen(s) could not be measured, so this may be incomplete',
|
|
1204
1215
|
xoAgain: 'Check again',
|
|
1205
1216
|
xoGone: 'The design changed, so this export was cancelled',
|
|
1217
|
+
xoJobGone: 'The export was interrupted (it waited too long or DSH restarted). Please export again',
|
|
1218
|
+
styleMoved: 'The design changed, so these style tweaks were not saved',
|
|
1219
|
+
xoCut: 'At most 1000 screens per export; the last {n} were left out',
|
|
1206
1220
|
xoResize: 'Fit canvas to content ({size})',
|
|
1207
1221
|
xoFull: 'Switch to full page',
|
|
1208
1222
|
xoLayout: 'Page size',
|
|
@@ -1318,6 +1332,8 @@ window.__ModuleLoader__.load({
|
|
|
1318
1332
|
ckItem: '{i}. {type}: {where}{text} — {detail}',
|
|
1319
1333
|
ckQuote: ' "{text}"',
|
|
1320
1334
|
exporting: 'Exporting…',
|
|
1335
|
+
exportingN: 'Capturing {i}/{n}…',
|
|
1336
|
+
xoCheckingN: 'Checking for cut-off content {i}/{n}…',
|
|
1321
1337
|
exported: 'Exported {name}',
|
|
1322
1338
|
exportedCopied: 'Exported {name} and copied it',
|
|
1323
1339
|
exportFail: 'Export failed: {msg}',
|
|
@@ -1433,6 +1449,11 @@ window.__ModuleLoader__.load({
|
|
|
1433
1449
|
styleNoWrite: 'Dev-server pages cannot be saved here; send it to the chat',
|
|
1434
1450
|
styleBusyTip: 'The model is working; save when it stops',
|
|
1435
1451
|
styleSaved: 'Style saved to {file}',
|
|
1452
|
+
styleShare: 'Change it on every screen',
|
|
1453
|
+
styleShareAt: 'into {sel} in {file}',
|
|
1454
|
+
styleShareTip: 'Everything using this rule changes too ({n} on this screen). Untick to change only the selected element',
|
|
1455
|
+
styleSavedRule: 'Saved into {sel} in {file}; every screen changes',
|
|
1456
|
+
styleSavedOthers: 'Saved into {sel} in {file}. On {n} other screens this element was saved on its own before and keeps that value',
|
|
1436
1457
|
styleMiss: 'Could not find this element in the source (maybe a script made it); sending it to the chat instead',
|
|
1437
1458
|
styleN: '{n} changed',
|
|
1438
1459
|
styleAskText: '[Style] {name} ({sel}): {list}. {rules}Put it in its stylesheet rule ({where}), using design tokens where you can, not an inline style.\n',
|
|
@@ -1519,6 +1540,7 @@ window.__ModuleLoader__.load({
|
|
|
1519
1540
|
pubDlCancel: 'Cancel download',
|
|
1520
1541
|
pubGone: 'The design changed (or this isn\'t a local file), so no link was created. Check it\'s the right design and try again.',
|
|
1521
1542
|
pubScreens: 'Shares these {n} screens: {names}. Screens added later are not shared automatically.',
|
|
1543
|
+
pubMoreNames: ' and more',
|
|
1522
1544
|
pubShared: 'Sharing these {n} screens: {names}',
|
|
1523
1545
|
pubBrokenShort: 'Visitors can\'t open it now',
|
|
1524
1546
|
pubBroken: 'Visitors currently see "Not available": {why}. Once fixed they can just refresh, or you can stop sharing.',
|
|
@@ -2469,6 +2491,10 @@ window.__ModuleLoader__.load({
|
|
|
2469
2491
|
.ddp-style .seg button.on{background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);box-shadow:0 1px 2px rgba(0,0,0,.14)}
|
|
2470
2492
|
.ddp-style .note{margin-top:6px;font-size:11px;line-height:16px;color:var(--dsw-alias-label-tertiary)}
|
|
2471
2493
|
.ddp-style .cnt{padding:0 14px 6px;font-size:11px;color:var(--dsw-alias-label-tertiary)}
|
|
2494
|
+
.ddp-style label.share{align-items:center;margin:0;padding:0 14px 8px;gap:6px;cursor:pointer}
|
|
2495
|
+
.ddp-style label.share input{margin:0;accent-color:${ACCENT};cursor:pointer}
|
|
2496
|
+
.ddp-style label.share span{flex:none;color:var(--dsw-alias-label-primary)}
|
|
2497
|
+
.ddp-style label.share em{flex:1;min-width:0;max-width:none}
|
|
2472
2498
|
.ddp-styles{display:grid;grid-template-columns:repeat(auto-fill,minmax(92px,1fr));gap:10px 8px}
|
|
2473
2499
|
.ddp-sc{display:flex;flex-direction:column;gap:5px;min-width:0;padding:0;border:0;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;text-align:left;cursor:pointer}
|
|
2474
2500
|
.ddp-sc .pv{position:relative;display:block;height:74px;border-radius:10px;overflow:hidden;container-type:inline-size;box-shadow:0 0 0 .5px rgba(127,127,127,.35);transition:transform .15s ${EASE},box-shadow .15s}
|
|
@@ -7206,7 +7232,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
7206
7232
|
* 拖的时候页面上先看效果(还没写进文件);设计变量列成小块,点一个就用 var(--x)。
|
|
7207
7233
|
* write:{ ok, tip } 能不能写回文件(开发服务器、模型在干活时不能)
|
|
7208
7234
|
*/
|
|
7209
|
-
function StylePanel({ t, sty, tokens, write, onSet, onReset, onAsk, onSave, onClose }) {
|
|
7235
|
+
function StylePanel({ t, sty, tokens, write, onSet, onReset, onAsk, onSave, onShare, onClose }) {
|
|
7210
7236
|
// 刚复制过哪一行:{ key, ok, v },1.5 秒后按钮字换回「复制」;没复制上的提示留着,换了元素才清
|
|
7211
7237
|
const [copied, setCopied] = useState(null)
|
|
7212
7238
|
const copyTimer = useRef(0)
|
|
@@ -7261,6 +7287,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
7261
7287
|
}
|
|
7262
7288
|
const w = Math.min(700, Math.max(400, Math.round(parseInt(cur('font-weight'), 10) / 100) * 100 || 400))
|
|
7263
7289
|
const n = Object.keys(sty.live).length
|
|
7290
|
+
const share = shareRule(sty)
|
|
7264
7291
|
return box(
|
|
7265
7292
|
h('p', { className: 'who', title: `${sty.name} · ${sty.selector}` }, ...(() => { const e = elemLabel(t, sty.name, sty.text); return [h('b', null, e.role), e.text ? h('span', null, `「${e.text}」`) : null] })()),
|
|
7266
7293
|
h('div', { className: 'bd' },
|
|
@@ -7275,6 +7302,9 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
7275
7302
|
slider('stylePadX', ['padding-left', 'padding-right'], 48, 'space'),
|
|
7276
7303
|
sty.layout ? slider('styleGap', ['gap'], 48, 'space') : null),
|
|
7277
7304
|
n ? h('div', { className: 'cnt' }, t('styleN', { n: styleChanges(t, sty).length })) : null,
|
|
7305
|
+
n && write.ok && share ? h('label', { className: 'share', title: t('styleShareTip', { n: share.cnt || 1 }) },
|
|
7306
|
+
h('input', { type: 'checkbox', checked: shareOn(sty), onChange: (e) => onShare(e.target.checked) }),
|
|
7307
|
+
h('span', null, t('styleShare')), h('em', null, t('styleShareAt', ruleName(share)))) : null,
|
|
7278
7308
|
n ? h('footer', { className: 'row' },
|
|
7279
7309
|
h('button', { onClick: onReset }, h('span', null, t('styleReset'))),
|
|
7280
7310
|
h('button', { onClick: onAsk, title: t('styleAskTip') }, h('span', null, t('styleAsk'))),
|
|
@@ -7811,7 +7841,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
7811
7841
|
* 公网链接(#27,实验):把整套 HTML 演示临时放到公网上(cloudflared 临时通道),给链接和二维码。
|
|
7812
7842
|
* 开之前先说清楚是公网可见;没装 cloudflared 的先请人下载;连上了显示还剩多久、打开过几次
|
|
7813
7843
|
*/
|
|
7814
|
-
function PubPanel({ t, sid, body, brief, onCopy, onClose }) {
|
|
7844
|
+
function PubPanel({ t, sid, body, fresh, brief, onCopy, onClose }) {
|
|
7815
7845
|
const [res, setRes] = useState(null)
|
|
7816
7846
|
const [err, setErr] = useState('')
|
|
7817
7847
|
const [busy, setBusy] = useState(false)
|
|
@@ -7862,7 +7892,8 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
7862
7892
|
}, [tk])
|
|
7863
7893
|
const start = () => {
|
|
7864
7894
|
setBusy(true)
|
|
7865
|
-
|
|
7895
|
+
// 屏多时先问一遍全部屏(收起来的改了名、刚加的),再按最新的放出去
|
|
7896
|
+
Promise.resolve(fresh ? fresh() : body()).then((b) => send({ session: sid, on: true, ...b })).then((d) => {
|
|
7866
7897
|
if (!d.on && d.error === 'no-cloudflared' && !d.tool) return download()
|
|
7867
7898
|
}).catch((e) => setErr(e.message)).finally(() => setBusy(false))
|
|
7868
7899
|
}
|
|
@@ -7878,7 +7909,8 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
7878
7909
|
const shotList = (() => {
|
|
7879
7910
|
const list = (body().screens || []).map((x) => x.label || x.key)
|
|
7880
7911
|
if (!list.length) return ''
|
|
7881
|
-
|
|
7912
|
+
// 几百屏的设计(#29):只列前 12 个名字
|
|
7913
|
+
return t('pubScreens', { n: list.length, names: list.slice(0, 12).join(t('sep')) + (list.length > 12 ? t('pubMoreNames') : '') })
|
|
7882
7914
|
})()
|
|
7883
7915
|
const errText = (r) => (r.error === 'tooBig' ? t('pubTooBig') : r.error === 'noScreens' ? t('pubNoScreens') : t('pubFail', { msg: r.message || r.error || '' }))
|
|
7884
7916
|
// 接口拒了(点生成的那一刻换了设计、或者现在看的不是本地文件):别说成「没连上 Cloudflare」
|
|
@@ -8512,10 +8544,12 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
8512
8544
|
const first = firstRun.current
|
|
8513
8545
|
firstRun.current = false
|
|
8514
8546
|
// 页面刚改过:等它重新载入再量
|
|
8547
|
+
// tok:换了画幅 / 屏 / 文件时这一遍作废(几百屏量一遍要好一会,别排在导出前面空跑)
|
|
8548
|
+
const tok = { off: false }
|
|
8515
8549
|
const timer = setTimeout(() => {
|
|
8516
|
-
measure().then((l) => { if (!off) setList(l) }, () => { if (!off) setList([{ failed: true }]) })
|
|
8550
|
+
measure(tok).then((l) => { if (!off) setList(l) }, () => { if (!off) setList([{ failed: true }]) })
|
|
8517
8551
|
}, first ? 0 : 900)
|
|
8518
|
-
return () => { off = true; clearTimeout(timer) }
|
|
8552
|
+
return () => { off = true; tok.off = true; clearTimeout(timer) }
|
|
8519
8553
|
}, [size.join('x'), screens, rev, again])
|
|
8520
8554
|
const limit = opts.fit === 'page' ? Infinity : opts.fit === 'height' && fitHOk(opts.fitH) ? +opts.fitH : 0
|
|
8521
8555
|
const rep = list ? precheckOf(list, kind, limit) : null
|
|
@@ -9266,8 +9300,28 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
9266
9300
|
// ── 导出图片(从预览面板里拆出来的:只用传进来的,不碰面板自己的状态)──────────────
|
|
9267
9301
|
// x:这一次画面的值(会话、状态、类型、画幅、几屏…)、几个 ref(各屏接口、背后挂的那批、设计序号)和面板里共用的 apiOf / targetKey
|
|
9268
9302
|
// onWarn:预检发现会被裁时打开导出选项
|
|
9303
|
+
/**
|
|
9304
|
+
* 导出用的全部屏(#29):服务端给的那份(list,已排好序,见 hidden 路由),右侧栏挂着的那几屏用它自己的(带画面信息),
|
|
9305
|
+
* 别的(收起来的、刚加还没轮询到的)用 list 里的。list 空 = 没收起来的,就是显示的这些
|
|
9306
|
+
*/
|
|
9307
|
+
function everyOf(shown, list) {
|
|
9308
|
+
if (!list || !list.length) return shown
|
|
9309
|
+
const by = new Map(shown.map((sc) => [sc.key, sc]))
|
|
9310
|
+
return list.map((x) => by.get(x.key) || x)
|
|
9311
|
+
}
|
|
9312
|
+
|
|
9269
9313
|
function makeExporter(x) {
|
|
9270
9314
|
const { sid, st, kind, size, dark, meta, tokens, t, say, canvas, focus, sel, shown, ik, labelOf, infoOf, fileTarget, ver, apis, designNow, designSeq, ghostApis, ghostBatch, ghostQueue, setBackFrames, warned, onWarn, apiOf, targetKey, tops, tweak, webFit } = x
|
|
9315
|
+
// 导出用的全部屏(#29):屏多过上限时右侧栏只显示最新的 60 屏,收起来的那些接在前面;没收起来就是显示的这些
|
|
9316
|
+
let every = x.every || shown
|
|
9317
|
+
// 导出前再问一次收起来的是哪些(不用缓存:右侧栏刚加了屏、收起来的改了名,都还没轮询到)
|
|
9318
|
+
let cutN = 0 // 超过 1000 屏(MAX_PAGES):后面这么多屏没导出,提示里说
|
|
9319
|
+
const loadEvery = async () => {
|
|
9320
|
+
if (!x.loadHidden) return every
|
|
9321
|
+
try { const r = await x.loadHidden(true); every = everyOf(shown, r.list); cutN = r.cut || 0 } catch (e) { console.warn('[dsh-design-studio] 取收起来的屏失败', e) }
|
|
9322
|
+
return every
|
|
9323
|
+
}
|
|
9324
|
+
const cutTail = () => (cutN ? ' · ' + t('xoCut', { n: cutN }) : '')
|
|
9271
9325
|
// 截一屏:图片和它的 CSS 尺寸(PDF / PPT 按这个定页面大小)
|
|
9272
9326
|
// 这次导出截到的 AI 示意图(文件名去重):每种导出结束的提示里都带一句「上线前换成真实照片」
|
|
9273
9327
|
const aiTail = (ai) => (ai && ai.size ? ' · ' + t('xoAi', { n: ai.size }) : '')
|
|
@@ -9289,15 +9343,16 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
9289
9343
|
}
|
|
9290
9344
|
|
|
9291
9345
|
// 单看时只挂着正在看的那屏;要所有屏(PDF、PPT、拼图、预检)时按画幅大小在背后挂上,用完就撤
|
|
9292
|
-
|
|
9293
|
-
|
|
9346
|
+
// pool:从哪几屏里挂(默认全部屏;拼展示图只用显示的那些)
|
|
9347
|
+
const withFrames = async (fn, only, pool = every) => {
|
|
9348
|
+
if (!only && ((canvas && pool.length <= LIVE_MAX) || pool.length < 2)) return fn(apis.current)
|
|
9294
9349
|
// 网页单看时铺满右侧栏,和画幅不一样宽,都在背后重挂(开了「按画幅显示」也照这样挂,只是多挂一次、慢一点,结果一样);别的类型正在看的那屏直接用(滚动位置、打开的弹窗都还在)
|
|
9295
9350
|
// 画布屏多的时候镜头一动画布上的屏就会撤,也都在背后挂
|
|
9296
9351
|
const stamp = designSeq.current
|
|
9297
9352
|
const run = async () => {
|
|
9298
9353
|
if (designSeq.current !== stamp) throw new Error('designChanged') // 排队的时候换了设计
|
|
9299
9354
|
// 轮到了才算要挂哪些:排队时前台可能已经换了一屏
|
|
9300
|
-
const list = only || (canvas || kind === 'web' ?
|
|
9355
|
+
const list = only || (canvas || kind === 'web' ? pool : pool.filter((sc) => !apis.current.has(ik(sc))))
|
|
9301
9356
|
const back = new Set(list.map(ik))
|
|
9302
9357
|
const place = new Map(list.map((sc, i) => [ik(sc), i]))
|
|
9303
9358
|
// 屏多的时候分批挂:只挂轮到的这一批,别几十个一起跑
|
|
@@ -9317,11 +9372,12 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
9317
9372
|
ghostQueue.current = job.catch(() => {})
|
|
9318
9373
|
return job
|
|
9319
9374
|
}
|
|
9320
|
-
const measureAll = async (map) => {
|
|
9375
|
+
const measureAll = async (map, tok) => {
|
|
9321
9376
|
const stamp = designSeq.current
|
|
9322
9377
|
const list = []
|
|
9323
|
-
for (const sc of
|
|
9324
|
-
if (designSeq.current !== stamp) break //
|
|
9378
|
+
for (const [i, sc] of every.entries()) {
|
|
9379
|
+
if (designSeq.current !== stamp || (tok && tok.off)) break // 设计换了 / 选项面板这一遍作废:别再等旧的屏
|
|
9380
|
+
if (every.length > LIVE_MAX) say(t('xoCheckingN', { i: i + 1, n: every.length }))
|
|
9325
9381
|
try { const api = await apiOf(sc, map); list.push(await api.measure()) } catch (e) { console.warn('[dsh-design-studio] 量页面失败', sc.key, e); list.push({ failed: true }) }
|
|
9326
9382
|
}
|
|
9327
9383
|
return list
|
|
@@ -9343,13 +9399,15 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
9343
9399
|
const long = fit === 'page' || fit === 'height' || (!fit && mode === 'pdf' && (kind === 'web' || kind === 'email'))
|
|
9344
9400
|
const maxH = fit === 'height' ? Number(opts.fitH) || 0 : 0
|
|
9345
9401
|
let deadN = 0
|
|
9402
|
+
await loadEvery()
|
|
9403
|
+
if (gone()) { say(t('xoGone')); return }
|
|
9346
9404
|
await withFrames(async (map) => {
|
|
9347
9405
|
// 从菜单直接点:先量一遍,有内容会被裁就先给看清单(同样的结果只拦一次)
|
|
9348
9406
|
if (!opts) {
|
|
9349
9407
|
const seen = await measureAll(map)
|
|
9350
9408
|
const rep = precheckOf(seen, kind, long ? Infinity : 0)
|
|
9351
9409
|
deadN = rep.dead
|
|
9352
|
-
const sig = rep.over || rep.long || rep.moved ? [design,
|
|
9410
|
+
const sig = rep.over || rep.long || rep.moved ? [design, every.map(ik).join(','), size.join('x'), long ? 1 : 0, seen.map((m) => (m.failed ? '-' : `${m.pageW}x${m.pageH}`)).join(',')].join('|') : ''
|
|
9353
9411
|
if (sig && warned.current !== sig) {
|
|
9354
9412
|
warned.current = sig
|
|
9355
9413
|
say(t('xoWarn'))
|
|
@@ -9357,44 +9415,56 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
9357
9415
|
return
|
|
9358
9416
|
}
|
|
9359
9417
|
}
|
|
9360
|
-
|
|
9361
|
-
|
|
9362
|
-
|
|
9363
|
-
|
|
9364
|
-
|
|
9365
|
-
|
|
9366
|
-
|
|
9367
|
-
|
|
9368
|
-
|
|
9369
|
-
|
|
9370
|
-
|
|
9371
|
-
|
|
9372
|
-
|
|
9373
|
-
|
|
9374
|
-
|
|
9375
|
-
|
|
9376
|
-
|
|
9377
|
-
|
|
9418
|
+
// 截一批传一批(#29:几百屏的截图攒在一起一次传不动),最后一批带上 done,服务端再拼。
|
|
9419
|
+
// 原型里的跳转写目标屏的 key:服务端拼的时候换成第几页,PDF / PPT 里点了能跳过去
|
|
9420
|
+
const job = Math.random().toString(36).slice(2, 10) + Date.now().toString(36)
|
|
9421
|
+
let batch = []
|
|
9422
|
+
let n = 0
|
|
9423
|
+
const titles = []
|
|
9424
|
+
// at:之前传了几页(服务端核对,中途 job 过期 / 丢了一批就整份报错,不拿半截拼)
|
|
9425
|
+
let sent = 0
|
|
9426
|
+
const flush = async (last) => { const b = batch; batch = []; const r = await post('doc', { session: sid, job, pages: b, at: sent, ...last }); sent += b.length; return r }
|
|
9427
|
+
const cancel = () => post('doc', { session: sid, job, cancel: true }).catch(() => {})
|
|
9428
|
+
try {
|
|
9429
|
+
for (const [i, sc] of every.entries()) {
|
|
9430
|
+
if (gone()) break
|
|
9431
|
+
if (every.length > LIVE_MAX) say(t('exportingN', { i: i + 1, n: every.length }))
|
|
9432
|
+
try {
|
|
9433
|
+
const r = await captureOf(sc, long, map, maxH, aiShot)
|
|
9434
|
+
const cut = maxH && r.h > maxH
|
|
9435
|
+
const title = exportTitle(sc, r)
|
|
9436
|
+
batch.push({ jpg: await jpegB64(cut ? cropImg(r.img, r.h, maxH) : r.img), w: r.w, h: cut ? maxH : r.h, title, key: sc.key, links: r.links.map((l) => ({ x: l.x, y: l.y, w: l.w, h: l.h, key: keyOfPath(l.path, fileTarget) })) })
|
|
9437
|
+
titles.push(title)
|
|
9438
|
+
n++
|
|
9439
|
+
} catch (e) { console.warn('[dsh-design-studio] 截图失败', sc.key, e) }
|
|
9440
|
+
if (batch.length >= 20) await flush({})
|
|
9441
|
+
}
|
|
9442
|
+
} catch (e) { cancel(); throw e } // 传某一批失败:服务端攒着的那些马上清掉
|
|
9443
|
+
if (gone()) { cancel(); say(t('xoGone')); return }
|
|
9444
|
+
if (!n) throw new Error('no screens')
|
|
9445
|
+
const sp = splitTitles(titles)
|
|
9378
9446
|
const folder = st && st.target && st.target.kind === 'file' ? String(st.target.file).split(/[\\/]/).slice(-2, -1)[0] : ''
|
|
9379
9447
|
const title = sp.brand || folder || st.label || ''
|
|
9380
9448
|
const layout = opts ? (opts.layout === 'custom' ? opts.custom.trim() : opts.layout === 'auto' ? '' : opts.layout) : ''
|
|
9381
9449
|
const cols = opts && opts.cols === 2 ? 2 : 1
|
|
9382
|
-
|
|
9450
|
+
let r
|
|
9451
|
+
try { r = await flush({ done: true, format: mode, name: prefix + (title || 'design') + suffix, title, bg: hexOf(pickColors(tokens).bg), layout, cols, target: targetKey }) } catch (e) { cancel(); throw e }
|
|
9383
9452
|
const file = String(r.path || '').split(/[\\/]/).pop()
|
|
9384
|
-
const miss =
|
|
9385
|
-
const sheets = Math.ceil(
|
|
9386
|
-
say((miss ? t('exportedDocMiss', { name: file, n: sheets, miss }) : t('exportedDoc', { name: file, n: sheets })) + (deadN ? ' · ' + t('xoDead', { n: deadN }) : '') + aiTail(aiShot), { label: t('reveal'), run: () => post('reveal', { path: r.path }).catch(() => {}) })
|
|
9453
|
+
const miss = every.length - n
|
|
9454
|
+
const sheets = Math.ceil(n / cols)
|
|
9455
|
+
say((miss ? t('exportedDocMiss', { name: file, n: sheets, miss }) : t('exportedDoc', { name: file, n: sheets })) + (deadN ? ' · ' + t('xoDead', { n: deadN }) : '') + cutTail() + aiTail(aiShot), { label: t('reveal'), run: () => post('reveal', { path: r.path }).catch(() => {}) })
|
|
9387
9456
|
})
|
|
9388
9457
|
return
|
|
9389
9458
|
}
|
|
9390
9459
|
if (mode === 'show') {
|
|
9391
9460
|
const shots = []
|
|
9461
|
+
// 展示图只拼右侧栏显示的这些(几百屏拼一张看不清)
|
|
9392
9462
|
await withFrames(async (map) => {
|
|
9393
9463
|
for (const sc of shown) {
|
|
9394
9464
|
if (gone()) break
|
|
9395
9465
|
try { const c = await captureOf(sc, false, map, 0, aiShot); shots.push({ img: c.img, top: c.top, title: exportTitle(sc, c) }) } catch (e) { console.warn('[dsh-design-studio] 截图失败', sc.key, e) }
|
|
9396
9466
|
}
|
|
9397
|
-
})
|
|
9467
|
+
}, undefined, shown)
|
|
9398
9468
|
if (gone()) { say(t('xoGone')); return }
|
|
9399
9469
|
if (!shots.length) throw new Error('no screens')
|
|
9400
9470
|
const sp = splitTitles(shots.map((x) => x.title))
|
|
@@ -9432,7 +9502,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
9432
9502
|
await saveImage(base + (mode === 'long' ? '-full' : mode === 'raw' && FRAMED[kind] ? '-plain' : ''), await canvasBlob(c), aiShot)
|
|
9433
9503
|
}
|
|
9434
9504
|
} catch (e) {
|
|
9435
|
-
say(e.message === 'designChanged' ? t('xoGone') : t('exportFail', { msg: e.message }))
|
|
9505
|
+
say(e.message === 'designChanged' ? t('xoGone') : e.message === 'jobGone' ? t('xoJobGone') : t('exportFail', { msg: e.message }))
|
|
9436
9506
|
}
|
|
9437
9507
|
}
|
|
9438
9508
|
// 整套 HTML 演示(#26):服务端把每屏连同样式、图片、图标打进一个 .html,不截图(几秒出来)。
|
|
@@ -9441,7 +9511,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
9441
9511
|
const htmlBody = () => {
|
|
9442
9512
|
const list = []
|
|
9443
9513
|
const seen = new Set()
|
|
9444
|
-
for (const sc of
|
|
9514
|
+
for (const sc of every) { // 看旧版本时就是那一版的几屏(都带 v);屏多时连收起来的(#29)
|
|
9445
9515
|
if (seen.has(sc.key)) continue
|
|
9446
9516
|
seen.add(sc.key)
|
|
9447
9517
|
list.push(sc)
|
|
@@ -9462,17 +9532,18 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
9462
9532
|
if (!fileTarget) return
|
|
9463
9533
|
say(t('exporting'))
|
|
9464
9534
|
try {
|
|
9535
|
+
await loadEvery()
|
|
9465
9536
|
const b = htmlBody()
|
|
9466
9537
|
const r = await post('htmlpack', { session: sid, ...b, name: (ver ? `v${ver.n}-` : '') + (b.title || 'design') + (dark ? '-dark' : '') })
|
|
9467
9538
|
const file = String(r.path || '').split(/[\\/]/).pop()
|
|
9468
9539
|
const miss = Array.isArray(r.missing) ? r.missing.length : 0
|
|
9469
|
-
say((miss ? t('exportedHtmlMiss', { name: file, n: r.count, miss }) : t('exportedHtml', { name: file, n: r.count })) + (r.ai ? ' · ' + t('xoAi', { n: r.ai }) : ''), { label: t('reveal'), run: () => post('reveal', { path: r.path }).catch(() => {}) })
|
|
9540
|
+
say((miss ? t('exportedHtmlMiss', { name: file, n: r.count, miss }) : t('exportedHtml', { name: file, n: r.count })) + cutTail() + (r.ai ? ' · ' + t('xoAi', { n: r.ai }) : ''), { label: t('reveal'), run: () => post('reveal', { path: r.path }).catch(() => {}) })
|
|
9470
9541
|
} catch (e) {
|
|
9471
9542
|
const m = String((e && e.message) || '')
|
|
9472
9543
|
say(m === 'designChanged' || m === 'not-file' ? t('xoGone') : m === 'tooBig' ? t('htmlTooBig') : m === 'noScreens' ? t('htmlNoScreens') : t('exportFail', { msg: m }))
|
|
9473
9544
|
}
|
|
9474
9545
|
}
|
|
9475
|
-
return { withFrames, measureAll, exportShots, exportHtml, htmlBody }
|
|
9546
|
+
return { withFrames, measureAll, exportShots, exportHtml, htmlBody, loadEvery }
|
|
9476
9547
|
}
|
|
9477
9548
|
|
|
9478
9549
|
// ── 画笔标注(从预览面板里拆出来的):台面上看得到的几屏截图拼好、叠上画的,存进 refs/ 交给模型,或者复制
|
|
@@ -9721,12 +9792,56 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
9721
9792
|
|
|
9722
9793
|
// ── 调样式(从预览面板里拆出来的):点一个元素,面板里拖滑块先在页面上看效果;写回文件 = 并进它在源码里的 style 属性
|
|
9723
9794
|
// x:这一次画面的值;开关调样式、Esc 收起留在面板里
|
|
9795
|
+
/**
|
|
9796
|
+
* 调样式「各屏一起改」写进哪条规则:改的几项由同一条外链 .css 规则决定(没有规则管的那几项一起写进去),
|
|
9797
|
+
* 选择器里得有元素自己的 class(见 picker 的 sharedOf);不行给 null(只改这一处)
|
|
9798
|
+
*/
|
|
9799
|
+
function shareRule(sty) {
|
|
9800
|
+
if (!sty || !sty.rules) return null
|
|
9801
|
+
let r0 = null
|
|
9802
|
+
for (const k of Object.keys(sty.live || {})) {
|
|
9803
|
+
const r = sty.rules[k]
|
|
9804
|
+
if (!r || !r.sel) continue // 没有规则管(继承来的 / 只写在行内):跟着写进那条规则
|
|
9805
|
+
if (!r.href || !r.cls || r.maybe) return null
|
|
9806
|
+
if (r0 && (r0.href !== r.href || r0.sel !== r.sel || r0.n !== r.n)) return null
|
|
9807
|
+
r0 = r0 || r
|
|
9808
|
+
}
|
|
9809
|
+
if (!r0) return null
|
|
9810
|
+
try { if (!/\.css$/i.test(new URL(r0.href).pathname)) return null } catch { return null }
|
|
9811
|
+
return r0
|
|
9812
|
+
}
|
|
9813
|
+
/**
|
|
9814
|
+
* 默认:这条规则只管和选中的同一种元素、而且各屏(收起来的也算)带这个 class 的也都是同一种(服务端核对过,见 sharecheck)才勾上;
|
|
9815
|
+
* 「.btn」这种好几种按钮共用的、还没核对完的,默认只改这一个
|
|
9816
|
+
*/
|
|
9817
|
+
const shareOn = (sty) => {
|
|
9818
|
+
if (sty && typeof sty.shared === 'boolean') return sty.shared
|
|
9819
|
+
const r = shareRule(sty)
|
|
9820
|
+
return !!(r && r.uni && sty.shareSeen && sty.shareSeen[r.cls] === true)
|
|
9821
|
+
}
|
|
9822
|
+
/** 面板上怎么说这条规则:文件名、选择器 */
|
|
9823
|
+
function ruleName(r) {
|
|
9824
|
+
let file = ''
|
|
9825
|
+
try { file = decodeURIComponent(new URL(r.href).pathname.split('/').pop() || '') } catch { file = '' }
|
|
9826
|
+
return { file, sel: String(r.sel || '') }
|
|
9827
|
+
}
|
|
9828
|
+
|
|
9724
9829
|
function makeStyleEdit(x) {
|
|
9725
|
-
const { sid, stRef, fileTarget, canvas, setSel, sty, setSty, insert, say, t } = x
|
|
9830
|
+
const { sid, stRef, fileTarget, targetKey, canvas, setSel, sty, setSty, insert, say, t } = x
|
|
9726
9831
|
const onStylePick = (sc, p) => {
|
|
9727
9832
|
if (canvas) setSel(sc.key)
|
|
9728
9833
|
const pg = pageOf(sc, p.href)
|
|
9729
|
-
|
|
9834
|
+
const rules = p.rules && typeof p.rules === 'object' ? p.rules : {}
|
|
9835
|
+
setSty({ key: pg.key, url: pg.url, name: p.name, selector: p.selector, text: p.text, loc: p.loc, base: p.css || {}, vars: p.vars || {}, rules, gradient: !!p.gradient, layout: !!p.layout, live: {}, shareSeen: {} })
|
|
9836
|
+
// 各屏一起改默认勾不勾:问服务端各屏带这个 class 的是不是都同一种(问到之前不勾)
|
|
9837
|
+
if (!fileTarget) return
|
|
9838
|
+
const seen = new Map()
|
|
9839
|
+
for (const r of Object.values(rules)) if (r && r.cls && r.uni && r.sig && r.href && !seen.has(r.cls)) seen.set(r.cls, r.sig)
|
|
9840
|
+
for (const [cls, sig] of seen) {
|
|
9841
|
+
post('sharecheck', { session: sid, cls, sig }).then((d) => {
|
|
9842
|
+
setSty((c) => (c && c.key === pg.key && c.selector === p.selector ? { ...c, shareSeen: { ...c.shareSeen, [cls]: !!(d && d.same) } } : c))
|
|
9843
|
+
}, () => {})
|
|
9844
|
+
}
|
|
9730
9845
|
}
|
|
9731
9846
|
const setStyleProp = (patch) => setSty((c) => (c ? { ...c, live: { ...c.live, ...patch } } : c))
|
|
9732
9847
|
// 交给模型:先问服务端那几条规则在源码第几行(本地文件才有;问不到就只写文件名)
|
|
@@ -9748,15 +9863,35 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
9748
9863
|
if (!s0 || !Object.keys(s0.live).length) return
|
|
9749
9864
|
if (!fileTarget) return askStyle()
|
|
9750
9865
|
const saved = s0.live
|
|
9751
|
-
|
|
9752
|
-
|
|
9753
|
-
|
|
9754
|
-
|
|
9755
|
-
|
|
9756
|
-
|
|
9757
|
-
|
|
9866
|
+
const tk = targetKey // 点保存时是哪套设计:两次保存(规则不行退回行内)都带上,中途换了设计服务端就不写
|
|
9867
|
+
// src:写完以后这几项由谁决定(行内 / 那条规则)、带不带 !important。面板不重新选也照这个算下一次(不然还按旧的带不带 !important)
|
|
9868
|
+
const done = (r, msg, src) => {
|
|
9869
|
+
say(msg)
|
|
9870
|
+
// 写进去的算「原样」了;写的时候又拖过的留着
|
|
9871
|
+
setSty((c) => (c && c.key === s0.key && c.selector === s0.selector
|
|
9872
|
+
? {
|
|
9873
|
+
...c, base: { ...c.base, ...saved }, live: Object.fromEntries(Object.entries(c.live).filter(([k, v]) => saved[k] !== v)),
|
|
9874
|
+
rules: Object.fromEntries(Object.entries(c.rules || {}).map(([k, v]) => [k, v && k in saved ? src(k, v) : v])),
|
|
9875
|
+
} : c))
|
|
9876
|
+
}
|
|
9877
|
+
// 现在生效的值带 !important(规则的,或上次照规则写进行内的):写行内也得带,不然白写(预览里 picker 也是这么带的)
|
|
9878
|
+
const imp = Object.keys(saved).filter((k) => s0.rules && s0.rules[k] && s0.rules[k].imp)
|
|
9879
|
+
const inline = () => post('style', { session: sid, target: tk, key: s0.key, loc: s0.loc, css: saved, name: s0.name, ...(imp.length ? { imp } : {}) }).then((r) => {
|
|
9880
|
+
if (r && r.ok) done(r, t('styleSaved', { file: r.file }), (k, v) => ({ ...v, inline: true, imp: imp.includes(k) }))
|
|
9881
|
+
else if (r && r.reason === 'busy') say(t('styleBusyTip'))
|
|
9882
|
+
else if (r && r.reason === 'moved') say(t('styleMoved'))
|
|
9758
9883
|
else { say(t('styleMiss')); askStyle() }
|
|
9759
9884
|
}, () => askStyle())
|
|
9885
|
+
// 各屏一起改:写进那条共用的规则;规则对不上(文件刚被改过、外框的样式表)就退回只改这一处
|
|
9886
|
+
const rule = shareOn(s0) ? shareRule(s0) : null
|
|
9887
|
+
if (!rule) return inline()
|
|
9888
|
+
const at = ruleName(rule)
|
|
9889
|
+
post('style', { session: sid, target: tk, key: s0.key, loc: s0.loc, css: saved, name: s0.name, rule: { href: rule.href, sel: rule.sel, n: rule.n, cls: rule.cls } }).then((r) => {
|
|
9890
|
+
if (r && r.ok) done(r, r.others ? t('styleSavedOthers', { file: r.file || at.file, sel: at.sel, n: r.others }) : t('styleSavedRule', { file: r.file || at.file, sel: at.sel }), (k, v) => ({ ...v, sel: rule.sel, href: rule.href, n: rule.n, cls: rule.cls, inline: false, imp: Array.isArray(r.imp) && r.imp.includes(k) }))
|
|
9891
|
+
else if (r && r.reason === 'busy') say(t('styleBusyTip'))
|
|
9892
|
+
else if (r && r.reason === 'moved') say(t('styleMoved'))
|
|
9893
|
+
else inline()
|
|
9894
|
+
}, () => inline())
|
|
9760
9895
|
}
|
|
9761
9896
|
return { onStylePick, setStyleProp, askStyle, saveStyle }
|
|
9762
9897
|
}
|
|
@@ -10402,7 +10537,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
10402
10537
|
}
|
|
10403
10538
|
useEffect(() => { if (!styleEdit) setSty(null) }, [styleEdit])
|
|
10404
10539
|
// 调样式:选中、预览、交给模型、写回(makeStyleEdit)
|
|
10405
|
-
const { onStylePick, setStyleProp, askStyle, saveStyle } = makeStyleEdit({ sid, stRef, fileTarget, canvas, setSel, sty, setSty, insert, say, t })
|
|
10540
|
+
const { onStylePick, setStyleProp, askStyle, saveStyle } = makeStyleEdit({ sid, stRef, fileTarget, targetKey, canvas, setSel, sty, setSty, insert, say, t })
|
|
10406
10541
|
useEffect(() => {
|
|
10407
10542
|
if (!styleEdit) return undefined
|
|
10408
10543
|
const onKey = (e) => { if (e.key === 'Escape' && !overlayUp()) setStyleEdit(false) }
|
|
@@ -10591,7 +10726,29 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
10591
10726
|
}
|
|
10592
10727
|
// ── 导出图片(makeExporter)──
|
|
10593
10728
|
// 在和做出来的比:导出的「这一屏」是比的那屏,画布没挂着(别的屏在背后挂)
|
|
10594
|
-
|
|
10729
|
+
// 屏多过上限(#29):右侧栏只显示最新的 60 屏,导出 PDF / PPT / 整套 HTML 要连收起来的一起(按顺序排在前面)
|
|
10730
|
+
const hidSig = fileTarget && !ver && st && st.hidden ? `${targetKey}|${st.hidden}|${screens.map((x) => x.key).join(',')}` : ''
|
|
10731
|
+
const [hid, setHid] = useState({ sig: '', list: [] })
|
|
10732
|
+
// force:导出 / 开公网链接前用,不认缓存(收起来的屏改了名、刚加了屏,hidSig 看不出来)
|
|
10733
|
+
// 没收起来的设计导出前也问一下(force):刚加了第 61 屏,右侧栏还没轮询到
|
|
10734
|
+
const loadHidden = async (force) => {
|
|
10735
|
+
if (!hidSig && !(force && fileTarget && !ver)) return { list: [] }
|
|
10736
|
+
if (!force && hid.sig === hidSig) return hid
|
|
10737
|
+
const r = await post('hidden', { session: sid })
|
|
10738
|
+
const ok = r && r.target === targetKey
|
|
10739
|
+
const got = { sig: hidSig, list: ok ? (r.list || []).map((x) => ({ key: x.key, url: `${origin}/${encodeURIComponent(x.key)}`, label: x.title || x.key.replace(/\.html?$/i, '') })) : [], cut: ok ? Number(r.cut) || 0 : 0 }
|
|
10740
|
+
if (hidSig) setHid(got)
|
|
10741
|
+
return got
|
|
10742
|
+
}
|
|
10743
|
+
// 目录里的文件改了(改名、加屏):歇 2 秒再问一遍(生成的时候文件一直在变,别每次都问);第一次马上问
|
|
10744
|
+
const hidRev = hidSig ? `${hidSig}|${st ? st.rev : 0}` : ''
|
|
10745
|
+
useEffect(() => {
|
|
10746
|
+
if (!hidRev) return
|
|
10747
|
+
const tm = setTimeout(() => { loadHidden(true).catch(() => {}) }, hid.sig === hidSig ? 2000 : 0)
|
|
10748
|
+
return () => clearTimeout(tm)
|
|
10749
|
+
}, [hidRev])
|
|
10750
|
+
const every = hidSig && hid.sig === hidSig ? everyOf(shown, hid.list) : shown
|
|
10751
|
+
const { withFrames, measureAll, exportShots, exportHtml, htmlBody, loadEvery } = makeExporter({ apiOf, targetKey, sid, st, kind, size, dark, meta, tokens, t, say, canvas: canvas && !implSc, focus: implSc ? implSc.key : focus, sel, shown, every, loadHidden, ik, labelOf, infoOf, fileTarget, ver, apis, designNow, designSeq, ghostApis, ghostBatch, ghostQueue, setBackFrames, warned, tops, tweak, webFit,
|
|
10595
10752
|
onWarn: () => { if (pane !== 'export') openPane('export') } })
|
|
10596
10753
|
const designId = JSON.stringify([sid, targetKey, ver ? ver.n : 0])
|
|
10597
10754
|
if (designNow.current !== designId) { designNow.current = designId; designSeq.current++ }
|
|
@@ -11214,7 +11371,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
11214
11371
|
return h(ZipIssues, { t, issues: zipIssues, onClose: () => { setPane(''); setZipIssues(null) } })
|
|
11215
11372
|
}
|
|
11216
11373
|
if (pane === 'export') {
|
|
11217
|
-
return h(ExportPanel, { t, kind, size, opts: xo, setOpts: setXo, screens:
|
|
11374
|
+
return h(ExportPanel, { t, kind, size, opts: xo, setOpts: setXo, screens: every.map(ik).join('|'), rev: `${st ? st.rev : 0}|${reloadSeq}|${loadTick}`, measure: async (tok) => { await loadEvery(); return tok && tok.off ? [] : withFrames((map) => (tok && tok.off ? [] : measureAll(map, tok))) }, onResize: (s) => change({ size: s }), onExport: (format) => doExport(format, undefined, xo), onClose: () => setPane('') })
|
|
11218
11375
|
}
|
|
11219
11376
|
if (pane === 'handoff') {
|
|
11220
11377
|
return h(HandoffPanel, { t, sid, root: fileTarget ? st.target.root : '', fileTarget, count: screens.length, cur: implSc ? implSc.key : (curScreen && curScreen.key) || focus, onGo: doHandoff, onSay: say, onClose: () => setPane('') })
|
|
@@ -11538,6 +11695,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
11538
11695
|
onReset: () => setSty((c) => (c ? { ...c, live: {} } : c)),
|
|
11539
11696
|
onAsk: askStyle,
|
|
11540
11697
|
onSave: saveStyle,
|
|
11698
|
+
onShare: (on) => setSty((c) => (c ? { ...c, shared: on } : c)),
|
|
11541
11699
|
onClose: () => setStyleEdit(false),
|
|
11542
11700
|
}) : null,
|
|
11543
11701
|
panel ? h(LookPanel, {
|
|
@@ -11587,6 +11745,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
11587
11745
|
t,
|
|
11588
11746
|
sid,
|
|
11589
11747
|
body: htmlBody,
|
|
11748
|
+
fresh: async () => { await loadEvery(); return htmlBody() },
|
|
11590
11749
|
brief: st && st.pub,
|
|
11591
11750
|
onCopy: (link) => { navigator.clipboard.writeText(link).then(() => say(t('pubCopied'))).catch(() => say(link)) },
|
|
11592
11751
|
onClose: () => setPubP(false),
|
|
@@ -11755,7 +11914,7 @@ ${Object.entries(CHIP_ICON).map(([k, d]) => `[data-composer-chip="${chipSrc(k)}"
|
|
|
11755
11914
|
// 注意:这里是客户端**服务名**(短的),不是包名
|
|
11756
11915
|
exports.inject = INJECT
|
|
11757
11916
|
// 测试用
|
|
11758
|
-
exports._test = { makeDemoNav, implLayout, implAwayUrl, KIND_LIST, KIND_KEY, KIND_SIZE, META_ALIAS, FIXED, SHOW_COLS, FRAME, ASK_EX, ASK_KINDS, KIND_ICON: I, pollGap, webFitOf, precheckOf, fitCanvas, layoutOk, fitHOk, autoSize, pulseStep, MarketDetail, dragKind, droppedOf, pickInfo, pickLabel, pickRanges, pickRule, chipOf, chipRanges, makeT, ZH, EN, formatCheck, formatTweaks, markHit, markPath, STYLES, formatStyle, accentUse, autoStyle, styleLook, padInsert, pageOf, pxOf, styleChanges, formatStyleAsk, takesOf, formatCheckTool, poller, frameOf, paletteOf, formatRef, layoutRow, keyOfPath, flowsOf, flowLines, flowMarks, formatPick, whereOf, parseMeta, sizeOf, layoutGrid, fitCam, nearestLive, LIVE_MAX, tokenKind, formatToken, splitTitles, pickColors, hhmm, formatTpl, formatPrep, styleFromTokens, myStyleOf, isZipFile }
|
|
11917
|
+
exports._test = { makeDemoNav, implLayout, implAwayUrl, KIND_LIST, KIND_KEY, KIND_SIZE, META_ALIAS, FIXED, SHOW_COLS, FRAME, ASK_EX, ASK_KINDS, KIND_ICON: I, pollGap, webFitOf, precheckOf, fitCanvas, layoutOk, fitHOk, autoSize, pulseStep, MarketDetail, dragKind, droppedOf, pickInfo, pickLabel, pickRanges, pickRule, chipOf, chipRanges, makeT, ZH, EN, formatCheck, formatTweaks, markHit, markPath, STYLES, formatStyle, accentUse, autoStyle, styleLook, padInsert, pageOf, pxOf, styleChanges, formatStyleAsk, everyOf, shareOn, takesOf, formatCheckTool, poller, frameOf, paletteOf, formatRef, layoutRow, keyOfPath, flowsOf, flowLines, flowMarks, formatPick, whereOf, parseMeta, sizeOf, layoutGrid, fitCam, nearestLive, LIVE_MAX, tokenKind, formatToken, splitTitles, pickColors, hhmm, formatTpl, formatPrep, styleFromTokens, myStyleOf, isZipFile }
|
|
11759
11918
|
return module.exports
|
|
11760
11919
|
},
|
|
11761
11920
|
})
|