dsh-ppt 0.21.1 → 0.23.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/CHANGELOG.md +25 -0
- package/README.en.md +37 -23
- package/README.md +37 -22
- package/docs/COACHING.md +14 -13
- package/docs/DATA.md +8 -8
- package/docs/REFERENCE.en.md +17 -19
- package/docs/REFERENCE.zh.md +16 -18
- package/docs/USAGE.en.md +107 -60
- package/docs/USAGE.md +115 -84
- package/docs/VALIDATION.md +2 -0
- package/docs/VISUAL.md +27 -20
- package/docs/WORKBENCH.md +17 -6
- package/docs/assets/intro/screen-en.webp +0 -0
- package/docs/assets/intro/screen-zh.webp +0 -0
- package/lib/client.js +1286 -52
- package/lib/coaching.d.ts +1 -1
- package/lib/coaching.js +25 -12
- package/lib/config.d.ts +2 -0
- package/lib/config.js +36 -2
- package/lib/execution.d.ts +2 -1
- package/lib/execution.js +21 -1
- package/lib/tools.d.ts +1 -1
- package/lib/tools.js +160 -25
- package/lib/types.d.ts +115 -8
- package/lib/visual.d.ts +3 -1
- package/lib/visual.js +40 -13
- package/lib/workbench-language.js +49 -9
- package/lib/workbench.d.ts +5 -0
- package/lib/workbench.js +603 -12
- package/package.json +8 -3
- package/skills/dsh-ppt/SKILL.md +56 -54
- package/skills/dsh-ppt/package.json +17 -5
- package/skills/dsh-ppt/references/advanced.md +123 -41
- package/skills/dsh-ppt/references/copywriting.md +63 -41
- package/skills/dsh-ppt/references/data.md +83 -36
- package/skills/dsh-ppt/references/syntax.md +157 -28
- package/skills/dsh-ppt/references/themes.md +113 -58
- package/skills/dsh-ppt/references/troubleshooting.md +21 -16
- package/skills/dsh-ppt/scripts/build-deck.mjs +67 -28
- package/skills/dsh-ppt/scripts/deck-absorb.mjs +1338 -0
- package/skills/dsh-ppt/scripts/deck-advanced.mjs +422 -105
- package/skills/dsh-ppt/scripts/deck-core.mjs +572 -717
- package/skills/dsh-ppt/scripts/deck-data-view.mjs +30 -11
- package/skills/dsh-ppt/scripts/deck-data.mjs +35 -5
- package/skills/dsh-ppt/scripts/deck-director.mjs +2057 -0
- package/skills/dsh-ppt/scripts/deck-layouts.mjs +4673 -0
- package/skills/dsh-ppt/scripts/deck-media.mjs +1408 -86
- package/skills/dsh-ppt/scripts/deck-themes.mjs +1854 -0
- package/skills/dsh-ppt/scripts/deck-visual.mjs +133 -31
|
@@ -57,27 +57,46 @@ function initDataView(data, math, chartRenderer) {
|
|
|
57
57
|
for(const id of metric.dependencies){const dependency=byId.get(id);button(dependency.label+' = '+math.format(values[id],dependency,data.language),evidence,()=>open(id));}
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
+
function appendBoundText(parent,text){
|
|
61
|
+
const pattern=/\{\{([A-Za-z][A-Za-z0-9]*)\}\}/g;let end=0;
|
|
62
|
+
for(const match of text.matchAll(pattern)){if(match.index>end)parent.append(document.createTextNode(text.slice(end,match.index)));const metric=byId.get(match[1]);el('button',math.format(values[metric.id],metric,data.language),parent,{type:'button',class:'data-number','data-metric':metric.id,title:L('查看数字出处','Inspect source')});end=match.index+match[0].length;}
|
|
63
|
+
if(end<text.length)parent.append(document.createTextNode(text.slice(end)));
|
|
64
|
+
}
|
|
60
65
|
function fragment(template){
|
|
61
|
-
const result=document.createDocumentFragment(),
|
|
62
|
-
for(const match of template.matchAll(
|
|
63
|
-
|
|
66
|
+
const result=document.createDocumentFragment(),inline=/(\*\*[^*]+\*\*|`[^`]+`|\*[^*\s][^*]*?\*)/g;let end=0;
|
|
67
|
+
for(const match of template.matchAll(inline)){
|
|
68
|
+
if(match.index>end)appendBoundText(result,template.slice(end,match.index));
|
|
69
|
+
const tok=match[0];
|
|
70
|
+
if(tok.startsWith('**')&&tok.endsWith('**'))appendBoundText(el('strong',undefined,result),tok.slice(2,-2));
|
|
71
|
+
else if(tok.startsWith('`')&&tok.endsWith('`'))appendBoundText(el('code',undefined,result,{class:'inline-code'}),tok.slice(1,-1));
|
|
72
|
+
else if(tok.startsWith('*')&&tok.endsWith('*'))appendBoundText(el('em',undefined,result),tok.slice(1,-1));
|
|
73
|
+
else appendBoundText(result,tok);
|
|
74
|
+
end=match.index+tok.length;
|
|
75
|
+
}
|
|
76
|
+
if(end<template.length||template==='')appendBoundText(result,template.slice(end));
|
|
77
|
+
return result;
|
|
64
78
|
}
|
|
65
79
|
function fill(node,template){if(node&&typeof template==='string')node.replaceChildren(fragment(template));}
|
|
66
|
-
function graphFor(template,solved){const graph=structuredClone(template),text=value=>typeof value==='string'?value.replace(/\{\{([A-Za-z][A-Za-z0-9]*)\}\}/g,(_,id)=>math.format(solved[id],byId.get(id),data.language)):value;graph.categories=graph.categories.map(text);graph.series=graph.series.map(s=>({...s,name:text(s.name),values:s.values.map(v=>typeof v==='string'&&/^\{\{[A-Za-z][A-Za-z0-9]*\}\}$/.test(v)?solved[v.slice(2,-2)]:Number(v))}));graph.unit=text(graph.unit);graph.caption=text(graph.caption);
|
|
80
|
+
function graphFor(template,solved){const graph=structuredClone(template),text=value=>typeof value==='string'?value.replace(/\{\{([A-Za-z][A-Za-z0-9]*)\}\}/g,(_,id)=>math.format(solved[id],byId.get(id),data.language)):value;graph.categories=graph.categories.map(text);graph.series=graph.series.map(s=>({...s,name:text(s.name),values:s.values.map(v=>typeof v==='string'&&/^\{\{[A-Za-z][A-Za-z0-9]*\}\}$/.test(v)?solved[v.slice(2,-2)]:Number(v))}));graph.unit=text(graph.unit);graph.caption=text(graph.caption);graph.source=text(graph.source);if(['pie','doughnut','percent-column','percent-bar'].includes(graph.kind)&&(graph.series.some(s=>s.values.some(v=>v<0))||graph.series[0].values.reduce((a,b)=>a+b,0)<=0))throw new Error(L('占比图表数值需非负且总和大于零','Proportional chart values must be non-negative with a positive total'));return graph;}
|
|
67
81
|
function missingNumbers(root){
|
|
68
|
-
const targets=root.querySelectorAll('h1,h2,.statement-title,.quote-text,.subtitle,.quote-attr,.deck-table th,.deck-table td,li,.media-body p,.media-caption');
|
|
69
|
-
const texts=[];for(const target of targets){const walker=document.createTreeWalker(target,NodeFilter.SHOW_TEXT);while(walker.nextNode()){const node=walker.currentNode;if(node.parentElement?.closest('.data-number,svg,.chart-data'))continue;texts.push(node);}}
|
|
82
|
+
const targets=root.querySelectorAll('h1,h2,.statement-title,.quote-text,.subtitle,.quote-attr,.deck-table th,.deck-table td,.harvey-table th,.harvey-table td,li,.media-body p,.media-caption,.media-lead,.media-takeaway,.takeaway-text,.slide-source,.media-source,.kpi-value,.kpi-delta,.card-title,.card-body,.card-stat,.comp-head,.callout-hero,.exec-thesis,.media-card-title,.media-card-body,[data-item-field]');
|
|
83
|
+
const texts=[];for(const target of targets){const walker=document.createTreeWalker(target,NodeFilter.SHOW_TEXT);while(walker.nextNode()){const node=walker.currentNode;if(node.parentElement?.closest('.data-number,svg,.chart-data,.item-badge,.section-index,.folio,.slide-folio'))continue;texts.push(node);}}
|
|
70
84
|
for(const node of new Set(texts)){const pattern=/[-+]?(?:\d{1,3}(?:,\d{3})+(?:\.\d+)?|\d+(?:\.\d+)?|\.\d+)(?:[eE][-+]?\d+)?[%%]?/g,content=node.textContent,matches=[...content.matchAll(pattern)];if(!matches.length)continue;const output=document.createDocumentFragment();let end=0;for(const match of matches){output.append(document.createTextNode(content.slice(end,match.index)));el('button',match[0],output,{type:'button',class:'data-number data-unlinked','data-unlinked':'1',title:L('未关联来源','Source not linked')});end=match.index+match[0].length;}output.append(document.createTextNode(content.slice(end)));node.replaceWith(output);}
|
|
71
85
|
}
|
|
72
86
|
function redraw(){
|
|
73
87
|
for(const slide of data.slides){const root=document.querySelectorAll('.slide')[slide.page-1];if(!root)continue;const template=slide.template;
|
|
74
88
|
fill(root.querySelector('.media-title,h1,h2,.statement-title,.quote-text'),template.title);
|
|
75
|
-
fill(root.querySelector('.subtitle,.quote-attr,.media-body > p'),template.subtitle);fill(root.querySelector('.kicker'),template.kicker);
|
|
76
|
-
|
|
77
|
-
|
|
89
|
+
fill(root.querySelector('.subtitle,.quote-attr,.media-lead,.media-body > p'),template.subtitle);fill(root.querySelector('.kicker:not(.matrix-tag)'),template.kicker);
|
|
90
|
+
fill(root.querySelector('.callout-hero,.exec-thesis'),template.text);
|
|
91
|
+
fill(root.querySelector('.takeaway-text,.media-takeaway'),template.takeaway);
|
|
92
|
+
fill(root.querySelector('.slide-source,.media-source'),template.source);
|
|
93
|
+
if(Array.isArray(template.columns))root.querySelectorAll('[data-col-index]').forEach(col=>fill(col,template.columns[Number(col.dataset.colIndex)]));
|
|
94
|
+
if(template.items)root.querySelectorAll('[data-item-index]').forEach(card=>{const it=template.items[Number(card.dataset.itemIndex)];if(!it)return;for(const f of ['tag','title','text','value','unit','delta'])card.querySelectorAll('[data-item-field="'+f+'"]').forEach(node=>fill(node,it[f]));if(it.bullets)card.querySelectorAll('li').forEach((li,i)=>fill(li,it.bullets[i]));});
|
|
95
|
+
if(template.bullets){const lis=root.querySelectorAll('.bullets-list li,.media-list li,.media-bullets li');(lis.length?lis:!template.items?root.querySelectorAll('li:not([data-item-index])'):[]).forEach((li,i)=>fill(li,template.bullets[i]));}
|
|
96
|
+
if(template.rows)root.querySelectorAll('.deck-table tr,.harvey-table tr').forEach((row,r)=>Array.from(row.children).forEach((cell,c)=>fill(cell,template.rows[r]?.[c])));
|
|
78
97
|
if(template.notes)root.dataset.notes=template.notes.replace(/\{\{([A-Za-z][A-Za-z0-9]*)\}\}/g,(_,id)=>math.format(values[id],byId.get(id),data.language));
|
|
79
|
-
if(template.chart){const graph=graphFor(template.chart,values),area=root.querySelector('.media-chart');if(area)area.innerHTML=chartRenderer(graph,data.theme);fill(root.querySelector('.media-caption'),template.chart.caption);}
|
|
80
|
-
if(slide.chart&&!root.querySelector('.data-chart-trace')){const link=button(L('图表数字来源','Chart sources'),root.querySelector('.media-canvas'),()=>{const id=Object.keys(template.chart||{}).length?[...JSON.stringify(template.chart).matchAll(/\{\{([A-Za-z][A-Za-z0-9]*)\}\}/g)][0]?.[1]:null;open(id,!id);});link.className='data-chart-trace';}
|
|
98
|
+
if(template.chart){const graph=graphFor(template.chart,values),area=root.querySelector('.media-chart');if(area)area.innerHTML=chartRenderer(graph,data.theme);fill(root.querySelector('.media-caption'),template.chart.caption);fill(root.querySelector('.media-source'),template.chart.source||template.source);}
|
|
99
|
+
if(slide.chart&&!root.querySelector('.data-chart-trace')){const link=button(L('图表数字来源','Chart sources'),root.querySelector('.media-canvas')||root,()=>{const id=Object.keys(template.chart||{}).length?[...JSON.stringify(template.chart).matchAll(/\{\{([A-Za-z][A-Za-z0-9]*)\}\}/g)][0]?.[1]:null;open(id,!id);});link.className='data-chart-trace';}
|
|
81
100
|
missingNumbers(root);
|
|
82
101
|
}
|
|
83
102
|
for(const {metric,range,number,formatted}of controls){range.value=String(parameters[metric.id]);number.value=String(parameters[metric.id]);formatted.textContent=' '+math.format(values[metric.id],metric,data.language);}
|
|
@@ -13,7 +13,8 @@ const clone = value => structuredClone(value)
|
|
|
13
13
|
const digest = value => createHash('sha256').update(JSON.stringify(value)).digest('hex')
|
|
14
14
|
const fail = (zh, en) => { throw new Error('dsh-ppt:' + zh + ' / ' + en) }
|
|
15
15
|
const token = /\{\{([A-Za-z][A-Za-z0-9]*)\}\}/g
|
|
16
|
-
const fields = ['title','subtitle','kicker','text','bullets','rows','notes','chart']
|
|
16
|
+
const fields = ['title','subtitle','kicker','text','takeaway','source','bullets','items','columns','rows','notes','chart']
|
|
17
|
+
const itemAliases = ['cards','metrics','steps','columns','quadrants']
|
|
17
18
|
const numericPattern = /[-+]?(?:\d{1,3}(?:,\d{3})+(?:\.\d+)?|\d+(?:\.\d+)?|\.\d+)(?:[eE][-+]?\d+)?[%%]?/g
|
|
18
19
|
export const dataFingerprint = model => digest({ sources: model.sources, metrics: model.metrics.map(({ ast, dependencies, evidence, ...m }) => m) })
|
|
19
20
|
|
|
@@ -119,19 +120,48 @@ function chartTemplate(chart) {
|
|
|
119
120
|
if (!chart || !chart.rows) return clone(chart)
|
|
120
121
|
return { ...chart, rows:undefined,categories:chart.rows.slice(1).map(r=>r[0]),series:chart.rows[0].slice(1).map((name,c)=>({name,values:chart.rows.slice(1).map(r=>r[c+1])})) }
|
|
121
122
|
}
|
|
123
|
+
function resolveItem(item, model) {
|
|
124
|
+
if (typeof item === 'string') return substituteData(item, model)
|
|
125
|
+
if (!item || typeof item !== 'object' || Array.isArray(item)) return item
|
|
126
|
+
const copy = clone(item)
|
|
127
|
+
for (const key of ['tag','badge','step','phase','title','label','heading','name','text','body','description','detail','unit','delta','change']) {
|
|
128
|
+
if (typeof copy[key] === 'string') copy[key] = substituteData(copy[key], model)
|
|
129
|
+
}
|
|
130
|
+
if (typeof copy.value === 'string') copy.value = substituteData(copy.value, model)
|
|
131
|
+
if (Array.isArray(copy.bullets)) copy.bullets = copy.bullets.map(v => typeof v === 'string' ? substituteData(v, model) : v)
|
|
132
|
+
if (Array.isArray(copy.items)) copy.items = copy.items.map(v => resolveItem(v, model))
|
|
133
|
+
return copy
|
|
134
|
+
}
|
|
135
|
+
function liftItemAliases(slide) {
|
|
136
|
+
const copy = { ...slide }
|
|
137
|
+
const preserveStringColumns = copy.layout === 'gantt' || (Array.isArray(copy.columns) && copy.columns.every(c => typeof c === 'string'))
|
|
138
|
+
if (!copy.items) {
|
|
139
|
+
for (const alias of itemAliases) {
|
|
140
|
+
if (alias === 'columns' && preserveStringColumns) continue
|
|
141
|
+
if (Array.isArray(copy[alias])) { copy.items = copy[alias]; break }
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
for (const alias of itemAliases) {
|
|
145
|
+
if (alias === 'columns' && preserveStringColumns) continue
|
|
146
|
+
delete copy[alias]
|
|
147
|
+
}
|
|
148
|
+
return copy
|
|
149
|
+
}
|
|
122
150
|
export function resolveTemplate(template, model) {
|
|
123
|
-
const next=clone(template)
|
|
124
|
-
for (const key of ['title','subtitle','kicker','text','notes']) if(typeof next[key]==='string')next[key]=substituteData(next[key],model)
|
|
151
|
+
const next=liftItemAliases(clone(template))
|
|
152
|
+
for (const key of ['title','subtitle','kicker','text','takeaway','source','notes']) if(typeof next[key]==='string')next[key]=substituteData(next[key],model)
|
|
125
153
|
if(Array.isArray(next.bullets))next.bullets=next.bullets.map(v=>substituteData(v,model))
|
|
154
|
+
if(Array.isArray(next.items))next.items=next.items.map(v=>resolveItem(v,model))
|
|
155
|
+
if(Array.isArray(next.columns))next.columns=next.columns.map(v=>typeof v==='string'?substituteData(v,model):v)
|
|
126
156
|
if(Array.isArray(next.rows))next.rows=next.rows.map(row=>row.map(v=>substituteData(v,model)))
|
|
127
|
-
if(next.chart){next.chart=chartTemplate(next.chart);next.chart.categories=next.chart.categories?.map(v=>substituteData(v,model));next.chart.series=next.chart.series?.map(s=>({...s,name:substituteData(s.name,model),values:s.values.map(v=>substituteData(v,model,true))}));for(const k of ['unit','caption'])if(next.chart[k])next.chart[k]=substituteData(next.chart[k],model)}
|
|
157
|
+
if(next.chart){next.chart=chartTemplate(next.chart);next.chart.categories=next.chart.categories?.map(v=>substituteData(v,model));next.chart.series=next.chart.series?.map(s=>({...s,name:substituteData(s.name,model),values:s.values.map(v=>substituteData(v,model,true))}));for(const k of ['unit','caption','source'])if(next.chart[k])next.chart[k]=substituteData(next.chart[k],model)}
|
|
128
158
|
return next
|
|
129
159
|
}
|
|
130
160
|
function hasBinding(value){return typeof value==='string'?/\{\{[A-Za-z][A-Za-z0-9]*\}\}/.test(value):Array.isArray(value)?value.some(hasBinding):value&&typeof value==='object'?Object.values(value).some(hasBinding):false}
|
|
131
161
|
export function prepareDataSlides(rawSlides, model, normalize, language='zh') {
|
|
132
162
|
return rawSlides.flatMap(raw=>{
|
|
133
163
|
if(raw.dataTemplate && (typeof raw.dataTemplate!=='object'||Array.isArray(raw.dataTemplate)||Object.keys(raw.dataTemplate).some(key=>!fields.includes(key))))fail('数据模板只允许文本、表格和图表字段','Data templates only support text, table and chart fields')
|
|
134
|
-
const original={...raw,...raw.dataTemplate};delete original.dataTemplate
|
|
164
|
+
const original=liftItemAliases({...raw,...raw.dataTemplate});delete original.dataTemplate
|
|
135
165
|
if(original.chart)original.chart=chartTemplate(original.chart)
|
|
136
166
|
const resolved=resolveTemplate(original,model), actual=normalize([resolved],120,language)
|
|
137
167
|
// Normalize text/table templates using the same pagination as real output.
|