dsh-ppt 0.32.0 → 0.33.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.
@@ -124,6 +124,16 @@ import {
124
124
  renderProChartSlideBodyHtml,
125
125
  PRO_CHARTS_CSS,
126
126
  } from './deck-charts-pro.mjs'
127
+ import {
128
+ INFOGRAPHIC_LAYOUTS,
129
+ computeMapModel,
130
+ computeIsometricModel,
131
+ generateVisualBrief,
132
+ normalizeImageBrief,
133
+ renderInfographicSlideBodyPptx,
134
+ renderInfographicSlideBodyHtml,
135
+ INFOGRAPHICS_CSS,
136
+ } from './deck-infographics.mjs'
127
137
 
128
138
  export {
129
139
  CANVAS_IN,
@@ -190,6 +200,12 @@ export {
190
200
  computeHeatmapModel,
191
201
  SHOWCASE_CSS,
192
202
  PRO_CHARTS_CSS,
203
+ INFOGRAPHIC_LAYOUTS,
204
+ computeMapModel,
205
+ computeIsometricModel,
206
+ generateVisualBrief,
207
+ normalizeImageBrief,
208
+ INFOGRAPHICS_CSS,
193
209
  }
194
210
 
195
211
  export const CORE_LAYOUTS = new Set([
@@ -221,6 +237,8 @@ export const CORE_LAYOUTS = new Set([
221
237
  'radar',
222
238
  'dumbbell',
223
239
  'heatmap',
240
+ 'map',
241
+ 'isometric',
224
242
  'table',
225
243
  'closing',
226
244
  ])
@@ -235,6 +253,13 @@ export const LAYOUT_ALIASES = Object.freeze({
235
253
  spider: { layout: 'radar' },
236
254
  slope: { layout: 'dumbbell' },
237
255
  'heat-matrix': { layout: 'heatmap' },
256
+ 'world-map': { layout: 'map', variant: 'world' },
257
+ 'china-map': { layout: 'map', variant: 'china' },
258
+ 'geo-map': { layout: 'map' },
259
+ 'iso-stack': { layout: 'isometric', variant: 'stack' },
260
+ 'iso-layers': { layout: 'isometric', variant: 'stack' },
261
+ '3d-stack': { layout: 'isometric', variant: 'stack' },
262
+ 'iso-pillars': { layout: 'isometric', variant: 'pillars' },
238
263
  'kpi-grid': { layout: 'kpi', variant: 'grid' },
239
264
  scorecard: { layout: 'kpi', variant: 'grid' },
240
265
  bento: { layout: 'cards', variant: 'bento' },
@@ -910,6 +935,21 @@ export function renderCoreSlidePptx(slide, index, total, theme, langAttr, manife
910
935
  return shapes.join('')
911
936
  }
912
937
 
938
+ const infographicShapes = renderInfographicSlideBodyPptx(slide, {
939
+ theme,
940
+ langAttr,
941
+ chromeCfg,
942
+ nextId,
943
+ bodyTopY,
944
+ bodyBottomY,
945
+ bodyH,
946
+ })
947
+ if (infographicShapes !== null) {
948
+ shapes.push(infographicShapes)
949
+ shapes.push(renderSlideChromePptx(slide, index, total, theme, langAttr, manifest, nextId))
950
+ return shapes.join('')
951
+ }
952
+
913
953
  const diagramShapes = renderDiagramSlideBodyPptx(slide, {
914
954
  theme,
915
955
  langAttr,
@@ -2095,6 +2135,7 @@ export function renderCoreSlideHtml(slide, index, total, ui, langId, manifest =
2095
2135
  let inner = ''
2096
2136
  const showcaseHtml = renderShowcaseSlideBodyHtml(slide, { theme, langId, manifest })
2097
2137
  const proChartHtml = renderProChartSlideBodyHtml(slide, { theme, langId, manifest })
2138
+ const infographicHtml = renderInfographicSlideBodyHtml(slide, { theme, langId, manifest })
2098
2139
  const diagramHtml = renderDiagramSlideBodyHtml(slide, { theme, langId, chromeStyle })
2099
2140
 
2100
2141
  if (layout === 'cover') {
@@ -2181,6 +2222,8 @@ export function renderCoreSlideHtml(slide, index, total, ui, langId, manifest =
2181
2222
  inner = renderHeader() + showcaseHtml
2182
2223
  } else if (proChartHtml !== null) {
2183
2224
  inner = renderHeader() + proChartHtml
2225
+ } else if (infographicHtml !== null) {
2226
+ inner = renderHeader() + infographicHtml
2184
2227
  } else if (diagramHtml !== null) {
2185
2228
  inner = renderHeader(layout === 'harvey' ? ui.tableKicker : '') + diagramHtml
2186
2229
  } else if (layout === 'table' && (slide.tableStyle || slide.visual?.tableStyle) === 'harvey') {
@@ -2542,6 +2585,7 @@ math.deck-math.is-inline{font-size:1.06em;vertical-align:middle}
2542
2585
  ${AESTHETIC_STUDIO_CSS}
2543
2586
  ${SHOWCASE_CSS}
2544
2587
  ${PRO_CHARTS_CSS}
2588
+ ${INFOGRAPHICS_CSS}
2545
2589
  ${DIAGRAMS_CSS}
2546
2590
  ${CHROME_CSS}
2547
2591
  ${MERMAID_CSS}
@@ -2,6 +2,7 @@
2
2
  import { resolveChromeStyle } from './deck-themes.mjs'
3
3
  import { getChromeConfig, computeBadgePillWidth, roundRectAdj } from './deck-layouts.mjs'
4
4
  import { resolveActiveTaste } from './deck-taste.mjs'
5
+ import { renderImageBriefPlaceholderPptx, renderImageBriefPlaceholderHtml } from './deck-infographics.mjs'
5
6
 
6
7
  export const MEDIA_LAYOUTS = new Set(['image', 'image-left', 'image-right', 'chart', 'chart-split'])
7
8
  export const CHART_KINDS = Object.freeze([
@@ -253,6 +254,8 @@ export function normalizeChart(input, page = 1) {
253
254
  }
254
255
  }
255
256
 
257
+ const FOCAL_POINTS = new Set(['center', 'top', 'bottom', 'left', 'right'])
258
+
256
259
  function normalizeSingleImage(raw, fallbackAlt, page, defaultFit = 'contain') {
257
260
  const image = typeof raw === 'string' ? { src: raw } : raw
258
261
  if (!image || typeof image !== 'object' || (!image.src && !image.assetId)) {
@@ -262,11 +265,16 @@ function normalizeSingleImage(raw, fallbackAlt, page, defaultFit = 'contain') {
262
265
  if (!['contain', 'cover'].includes(fit)) {
263
266
  throw new Error(`dsh-ppt:第 ${page} 页 image.fit 仅支持 contain / cover`)
264
267
  }
268
+ const rawFocal = image.focalPoint !== undefined ? String(image.focalPoint).trim().toLowerCase() : ''
269
+ if (rawFocal && !FOCAL_POINTS.has(rawFocal)) {
270
+ throw new Error(`dsh-ppt:第 ${page} 页 image.focalPoint 仅支持 center / top / bottom / left / right`)
271
+ }
265
272
  return {
266
273
  ...(image.src ? { src: String(image.src) } : {}),
267
274
  ...(image.assetId ? { assetId: String(image.assetId) } : {}),
268
275
  alt: String(image.alt ?? fallbackAlt ?? ''),
269
276
  fit,
277
+ ...(rawFocal ? { focalPoint: rawFocal } : {}),
270
278
  ...(image.caption ? { caption: String(image.caption) } : {}),
271
279
  }
272
280
  }
@@ -323,6 +331,13 @@ export function normalizeMediaSlide(source, normalized, index) {
323
331
  }
324
332
  }
325
333
 
334
+ if (!source.image && normalized.imageBrief) {
335
+ return {
336
+ ...normalized,
337
+ ...extras,
338
+ }
339
+ }
340
+
326
341
  return {
327
342
  ...normalized,
328
343
  ...extras,
@@ -898,12 +913,19 @@ export function renderMediaHtml(slide, manifest, theme) {
898
913
  boxes.gallery.forEach((gBox, idx) => {
899
914
  const img = slide.images[idx]
900
915
  const asset = manifest.assets?.[img?.assetId]
901
- body += `<figure class="media-image media-image--framed" style="${position(gBox)}"><img src="${esc(asset?.data ?? '')}" alt="${esc(img?.alt)}" style="object-fit:${img?.fit || 'cover'}"/>${img?.caption ? `<figcaption>${esc(img.caption)}</figcaption>` : ''}</figure>`
916
+ const posCss = img?.focalPoint && img.focalPoint !== 'center' ? `;object-position:${img.focalPoint === 'top' ? 'center top' : img.focalPoint === 'bottom' ? 'center bottom' : img.focalPoint === 'left' ? 'left center' : 'right center'}` : ''
917
+ body += `<figure class="media-image media-image--framed" style="${position(gBox)}"><img src="${esc(asset?.data ?? '')}" alt="${esc(img?.alt)}" style="object-fit:${img?.fit || 'cover'}${posCss}"/>${img?.caption ? `<figcaption>${esc(img.caption)}</figcaption>` : ''}</figure>`
902
918
  })
919
+ } else if (!slide.image && slide.imageBrief) {
920
+ body += `<div class="media-image media-image--brief" style="${position(boxes.image)}">${renderImageBriefPlaceholderHtml(slide, theme, langEn)}</div>`
903
921
  } else {
904
922
  const image = slide.image, asset = manifest.assets?.[image?.assetId]
905
923
  const frameClass = variant === 'split-bleed' || variant === 'full-bleed' ? 'media-image--bleed' : 'media-image--framed'
906
- body += `<figure class="media-image ${frameClass}" style="${position(boxes.image)}"><img src="${esc(asset?.data ?? '')}" alt="${esc(image?.alt)}" style="object-fit:${image?.fit || 'contain'}"/></figure>`
924
+ const posCss = image?.focalPoint && image.focalPoint !== 'center' ? `;object-position:${image.focalPoint === 'top' ? 'center top' : image.focalPoint === 'bottom' ? 'center bottom' : image.focalPoint === 'left' ? 'left center' : 'right center'}` : ''
925
+ body += `<figure class="media-image ${frameClass}" style="${position(boxes.image)}"><img src="${esc(asset?.data ?? '')}" alt="${esc(image?.alt)}" style="object-fit:${image?.fit || 'contain'}${posCss}"/></figure>`
926
+ if (variant === 'full-bleed') {
927
+ body += `<div class="media-bleed-scrim" aria-hidden="true"></div>`
928
+ }
907
929
  }
908
930
  if (boxes.body) {
909
931
  const lead = slide.subtitle ? `<p class="media-lead">${formatInlineHtml(slide.subtitle)}</p>` : ''
@@ -1342,17 +1364,26 @@ export function renderMediaPptxShapes(slide, index, theme, langId = 'zh-CN', fon
1342
1364
  shapes.push(spText('Kicker', boxes.kicker, [paraRich(slide.kicker.toUpperCase(), { size: 1100, color: accentText, bold: true, spc: 140 })], { ins: [0, 0, 0, 0] }))
1343
1365
  }
1344
1366
  if (variant === 'full-bleed') {
1345
- const scrim = boxEmu({ x: 0.45, y: 5.15, w: 11.2, h: 1.75 })
1346
- shapes.push(spRect('Title Scrim', scrim, theme.dark ? '#090B10' : '#FFFFFF', hairline, 9525, 3500))
1367
+ const scrim = boxEmu({ x: 0, y: 3.9, w: CANVAS.w, h: 3.6 })
1368
+ shapes.push(
1369
+ `<p:sp><p:nvSpPr><p:cNvPr id="${allocId()}" name="Title Scrim"/><p:cNvSpPr/><p:nvPr/></p:nvSpPr>` +
1370
+ `<p:spPr><a:xfrm><a:off x="${scrim.x}" y="${scrim.y}"/><a:ext cx="${scrim.w}" cy="${scrim.h}"/></a:xfrm>` +
1371
+ `<a:prstGeom prst="rect"><a:avLst/></a:prstGeom>` +
1372
+ `<a:gradFill><a:gsLst><a:gs pos="0"><a:srgbClr val="060B16"><a:alpha val="0"/></a:srgbClr></a:gs><a:gs pos="48000"><a:srgbClr val="060B16"><a:alpha val="62000"/></a:srgbClr></a:gs><a:gs pos="100000"><a:srgbClr val="060B16"><a:alpha val="88000"/></a:srgbClr></a:gs></a:gsLst><a:lin ang="5400000" scaled="1"/></a:gradFill>` +
1373
+ `<a:ln><a:noFill/></a:ln></p:spPr><p:txBody><a:bodyPr/><a:lstStyle/><a:p/></p:txBody></p:sp>`
1374
+ )
1347
1375
  }
1348
- shapes.push(spText('Title', boxes.title, [paraRich(slide.title || '', { size: titlePt * 100, color: fg, bold: true, latin: headingFont, ea: headingEa, linePct: 118000 })], { anchor: 'ctr', ins: [0, 0, 0, 0] }))
1376
+ const titleColor = variant === 'full-bleed' ? '#F8FAFC' : fg
1377
+ shapes.push(spText('Title', boxes.title, [paraRich(slide.title || '', { size: titlePt * 100, color: titleColor, bold: true, latin: headingFont, ea: headingEa, linePct: 118000 })], { anchor: 'ctr', ins: [0, 0, 0, 0] }))
1349
1378
  if (!isBleed) {
1350
1379
  shapes.push(spLine('Header rule', toEmu(0.65), toEmu(1.56), toEmu(12.68), toEmu(1.56), hairline, 9525, 'solid'))
1351
1380
  }
1352
1381
  }
1353
1382
 
1354
- // Framed matte container behind non-bleed images
1355
- if (['image', 'image-left', 'image-right'].includes(slide.layout) && !isBleed) {
1383
+ // Framed matte container behind non-bleed images (or editorial Visual Brief slot when awaiting an image)
1384
+ if (['image', 'image-left', 'image-right'].includes(slide.layout) && !slide.image && slide.imageBrief) {
1385
+ shapes.push(renderImageBriefPlaceholderPptx(slide, boxes.image, theme, langId, allocId))
1386
+ } else if (['image', 'image-left', 'image-right'].includes(slide.layout) && !isBleed) {
1356
1387
  if (Array.isArray(boxes.gallery) && Array.isArray(slide.images) && slide.images.length > 1) {
1357
1388
  boxes.gallery.forEach((gBox, gIdx) => {
1358
1389
  const pad = 0.06
@@ -1573,7 +1604,9 @@ export const MEDIA_CSS = `
1573
1604
  .media-kicker,.media-title,.media-image,.media-body,.media-chart,.media-caption,.media-takeaway{position:absolute;margin:0;max-width:none;box-sizing:border-box}
1574
1605
  .media-kicker{font-size:1.05cqw;line-height:1.2;margin:0}
1575
1606
  .media-title{font-size:2.95cqw;font-weight:750;line-height:1.18;letter-spacing:-.015em;display:flex;align-items:center;overflow-wrap:anywhere}
1576
- .media-title--bleed{background:color-mix(in srgb, var(--bg) 88%, transparent);backdrop-filter:blur(10px);padding:1.1cqw 1.6cqw;border-radius:12px;border:1px solid color-mix(in srgb, var(--muted) 32%, transparent);z-index:2}
1607
+ .media-title--bleed{color:#F8FAFC;text-shadow:0 2px 14px rgba(0,0,0,.45);padding:.4cqw 0;z-index:3}
1608
+ .media-bleed-scrim{position:absolute;left:0;right:0;bottom:0;height:48%;background:linear-gradient(180deg,rgba(6,11,22,0) 0%,rgba(6,11,22,.62) 48%,rgba(6,11,22,.88) 100%);pointer-events:none;z-index:2}
1609
+ .media-image--brief{overflow:visible;padding:0;border:0;background:transparent}
1577
1610
  .media-image{overflow:hidden}
1578
1611
  .media-image--framed{border-radius:12px;background:var(--surface1,var(--panel));border:1px solid var(--hairline,color-mix(in srgb, var(--muted) 28%, transparent));padding:.45cqw}
1579
1612
  .media-image--framed img{border-radius:8px}
@@ -0,0 +1,18 @@
1
+ /** Replace workspace metadata only after its complete new JSON is written. */
2
+ import { lstatSync, mkdirSync, writeFileSync, renameSync, unlinkSync } from 'node:fs'
3
+ import { dirname } from 'node:path'
4
+ import { randomUUID } from 'node:crypto'
5
+
6
+ export function writeWorkspaceJson(file, value) {
7
+ const existing = lstatSync(file, { throwIfNoEntry: false })
8
+ if (existing && (!existing.isFile() || existing.isSymbolicLink())) throw new Error('dsh-ppt:存储文件不是普通文件,已保留原文件')
9
+ const bytes = JSON.stringify(value, null, 2) + '\n'
10
+ const temporary = file + '.tmp-' + randomUUID()
11
+ mkdirSync(dirname(file), { recursive: true })
12
+ try {
13
+ writeFileSync(temporary, bytes, { flag: 'wx', mode: 0o600 })
14
+ renameSync(temporary, file)
15
+ } finally {
16
+ try { unlinkSync(temporary) } catch (error) { if (error.code !== 'ENOENT') throw error }
17
+ }
18
+ }
@@ -8,8 +8,9 @@
8
8
  * 零外部运行时依赖,仅使用 Node 内置模块。
9
9
  */
10
10
 
11
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
12
- import { dirname, join, resolve } from 'node:path'
11
+ import { existsSync, readFileSync } from 'node:fs'
12
+ import { join, resolve } from 'node:path'
13
+ import { writeWorkspaceJson } from './deck-store.mjs'
13
14
 
14
15
  export const CARD_MATERIALS = Object.freeze(['solid', 'frameless', 'glass', 'editorial-rule'])
15
16
  export const COVER_VARIANTS = Object.freeze([
@@ -282,11 +283,13 @@ export function sanitizeCustomTasteRecipe(raw) {
282
283
  /**
283
284
  * 读取工作区持久化的用户品味配方库(.dsh-ppt/taste-recipes.json)。
284
285
  */
285
- export function loadWorkspaceTasteRecipes(cwd = process.cwd()) {
286
+ function readWorkspaceTasteRecipes(cwd, strict = false) {
286
287
  const storePath = resolve(cwd, '.dsh-ppt', 'taste-recipes.json')
287
288
  if (!existsSync(storePath)) return {}
288
289
  try {
289
290
  const parsed = JSON.parse(readFileSync(storePath, 'utf8'))
291
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) throw new Error('Invalid taste store')
292
+ if (Object.hasOwn(parsed, 'recipes') && (!parsed.recipes || typeof parsed.recipes !== 'object' || Array.isArray(parsed.recipes))) throw new Error('Invalid taste recipes')
290
293
  const rawMap = parsed && typeof parsed === 'object' && !Array.isArray(parsed)
291
294
  ? (parsed.recipes && typeof parsed.recipes === 'object' ? parsed.recipes : parsed)
292
295
  : {}
@@ -296,11 +299,14 @@ export function loadWorkspaceTasteRecipes(cwd = process.cwd()) {
296
299
  if (clean) out[clean.id.toLowerCase()] = clean
297
300
  }
298
301
  return out
299
- } catch {
302
+ } catch (error) {
303
+ if (strict) throw new Error('dsh-ppt:品味配方库格式无效或无法读取,已保留原文件,请备份并修复后重试', { cause: error })
300
304
  return {}
301
305
  }
302
306
  }
303
307
 
308
+ export function loadWorkspaceTasteRecipes(cwd = process.cwd()) { return readWorkspaceTasteRecipes(cwd) }
309
+
304
310
  /**
305
311
  * 将从优质 .pptx 吸收提炼的品味配方持久化到工作区(.dsh-ppt/taste-recipes.json),供后续所有新稿一键复用。
306
312
  */
@@ -308,13 +314,12 @@ export function saveWorkspaceTasteRecipe(recipe, cwd = process.cwd()) {
308
314
  const clean = sanitizeCustomTasteRecipe(recipe)
309
315
  if (!clean) throw new Error('dsh-ppt:无效的品味配方对象')
310
316
  const storePath = resolve(cwd, '.dsh-ppt', 'taste-recipes.json')
311
- const existing = loadWorkspaceTasteRecipes(cwd)
317
+ const existing = readWorkspaceTasteRecipes(cwd, true)
312
318
  existing[clean.id.toLowerCase()] = {
313
319
  ...clean,
314
320
  absorbedAt: clean.absorbedAt || new Date().toISOString(),
315
321
  }
316
- mkdirSync(dirname(storePath), { recursive: true })
317
- writeFileSync(storePath, JSON.stringify({ version: 1, recipes: existing }, null, 2) + '\n', 'utf8')
322
+ writeWorkspaceJson(storePath, { version: 1, recipes: existing })
318
323
  return { path: storePath, recipe: existing[clean.id.toLowerCase()], totalSaved: Object.keys(existing).length }
319
324
  }
320
325