Skip to content

chuspeeism/dashi-ppt-skill / skills/dashi-ppt

dashi-ppt

Flagged

制作 PPT、演示文稿、幻灯片、汇报材料时使用。Dashi PPT 基于预置视觉主题组合页面,生成可离线打开、可在浏览器编辑的 HTML 演示,支持导出 PPTX / PDF 文件。

FileKindSize
.gitignoreother173 B
README.mdmarkdown3.9 KB
SKILL.mdskill md25.4 KB
agents/openai.yamlconfig292 B
assets/skill/dashi-ppt-favicon.pngbinary2.0 KB
assets/skill/dashi-ppt-small.pngbinary895 B
assets/skill/dashi-ppt.pngbinary12.6 KB
assets/skill/theme-style-grid.pngbinary2.1 MB
project/.npmrcother40 B
project/assets/skill/dashi-ppt-favicon.pngbinary2.0 KB
project/assets/social-icons/bilibili.svgother7.9 KB
project/assets/social-icons/douyin.svgother4.7 KB
project/assets/social-icons/github.svgother1.3 KB
project/assets/social-icons/redbook.svgother3.5 KB
project/assets/template-swiss.htmlother465.5 KB
project/assets/ui-icons/sidebar.svgother1.3 KB
project/assets/unicorn/automations_remix_scene.jsonconfig42.9 KB
project/assets/unicorn/goey_balls_remix_scene.jsonconfig14.2 KB
project/assets/unicorn/media/blue_noise_med.pngbinary206.4 KB
project/assets/unicorn/media/font_atlas.pngbinary64.6 KB
project/assets/unicorn/moving_into_remix_scene.jsonconfig67.8 KB
project/assets/unicorn/tech_background_remix_scene.jsonconfig52.2 KB
project/distribution-source.jsonconfig517 B
project/i18n/zh-en.jsonconfig574.5 KB
project/layout-manifest.jsonconfig3.4 MB
project/npmrc.templateother40 B
project/package-lock.jsonmanifest21.8 KB
project/package.jsonmanifest1.2 KB
project/packages/html-deck-to-pptx/LICENSEother1.6 KB
project/packages/html-deck-to-pptx/README.mdmarkdown2.2 KB
project/packages/html-deck-to-pptx/index.mjsscript719 B
project/packages/html-deck-to-pptx/package.jsonmanifest840 B
project/packages/html-deck-to-pptx/src/editable.mjsscript143 B
project/packages/html-deck-to-pptx/src/screenshot.mjsscript147 B
project/scripts/chrome-path.mjsscript6.1 KB
project/scripts/command-paths.mjsscript334 B
project/scripts/ensure-registry.mjsscript2.1 KB
project/scripts/export-pptx.mjsscript6.4 KB
project/scripts/goal-scaffold.mjsscript31.3 KB
project/scripts/inspect-layout.mjsscript2.1 KB
project/scripts/layout-query.mjsscript3.4 KB
project/scripts/media-formats.mjsscript1.3 KB
project/scripts/openssl-path.mjsscript2.2 KB
project/scripts/persist-deck-state.mjsscript6.7 KB
project/scripts/preview-export-auth.mjsscript1.0 KB
project/scripts/preview-freshness.mjsscript6.2 KB
project/scripts/preview-path.mjsscript569 B
project/scripts/preview/ensure-tmpdir.mjsscript3.4 KB
project/scripts/preview/export-routes.mjsscript24.2 KB
project/scripts/preview/launch-export-browser.mjsscript2.5 KB
project/scripts/preview/mime.mjsscript671 B
project/scripts/preview/network.mjsscript799 B
project/scripts/preview/static-serve.mjsscript1.2 KB
project/scripts/preview/tls.mjsscript2.7 KB
project/scripts/render-goal-deck.jsxother2.5 KB
project/scripts/scrub-local-paths.mjsscript898 B
project/scripts/serve-preview-https.mjsscript10.7 KB
project/scripts/skill-workflow-utils.mjsscript1.4 KB
project/scripts/stage-media.mjsexecutablescript14.7 KB
project/scripts/start-preview-server.mjsscript16.1 KB
project/scripts/validate-goal-copy.mjsscript25.4 KB
project/scripts/validate-goal-spec.mjsscript80.7 KB
project/scripts/validate-swiss-deck.mjsscript34.1 KB
project/scripts/workflow-telemetry.mjsscript6.1 KB
project/scripts/workflow/copy-contract.mjsscript19.2 KB
project/scripts/workflow/inspect-fillplan.mjsscript70.6 KB
project/scripts/workflow/layout-allocation.mjsscript8.5 KB
project/scripts/workflow/layout-query.mjsscript64.4 KB
project/scripts/workflow/media-slots.mjsscript15.8 KB
project/scripts/workflow/theme-registry.mjsscript16.1 KB
project/scripts/write-safe-props.mjsscript17.7 KB
project/src/accepted-themes.mjsscript570 B
project/src/components/bespoke/BespokeSlide.jsxother32.0 KB
project/src/components/bespoke/theme-profiles.mjsscript11.5 KB
project/src/components/index.jsxother71 B
project/src/components/shell/SlideShell.jsxother1.5 KB
project/src/components/shell/index.jsxother47 B
project/src/components/themes/canonical-metadata.mjsscript4.6 KB
project/src/components/themes/chart-safety.mjsscript1.9 KB
project/src/components/themes/client-runtime.jsxother57.9 KB
project/src/components/themes/decorative-overrides.mjsscript859 B
project/src/components/themes/generated-metadata.jsscript4.4 MB
project/src/components/themes/index.jsxother2.8 KB
project/src/components/themes/runtime-build.mjsscript7.3 KB
project/src/components/themes/runtime-helpers.jsxother6.2 KB
project/src/components/themes/theme-registry-codegen.mjsscript7.2 KB
project/src/components/themes/theme01/metadata.jsscript363.9 KB
project/src/components/themes/theme01/source/slides/theme.jsscript5.6 KB
project/src/components/themes/theme02/metadata.jsscript384.6 KB
project/src/components/themes/theme02/overrides.jsscript114 B
project/src/components/themes/theme02/source/src/gxnTheme.jsscript19.6 KB
project/src/components/themes/theme03/metadata.jsscript512.5 KB
project/src/components/themes/theme03/overrides.jsscript1.2 KB
project/src/components/themes/theme03/source/assets/3d/01.pngbinary635.1 KB
project/src/components/themes/theme03/source/assets/3d/02.pngbinary865.2 KB
project/src/components/themes/theme03/source/assets/3d/03.pngbinary921.8 KB
project/src/components/themes/theme03/source/assets/3d/04.pngbinary1.1 MB
project/src/components/themes/theme03/source/assets/3d/05.pngbinary920.3 KB
project/src/components/themes/theme03/source/assets/3d/06.pngbinary1.2 MB
project/src/components/themes/theme03/source/assets/3d/07.pngbinary1.6 MB
project/src/components/themes/theme03/source/assets/3d/08.pngbinary1.4 MB
project/src/components/themes/theme03/source/assets/3d/09.pngbinary1.9 MB
project/src/components/themes/theme03/source/assets/3d/10.pngbinary1.4 MB
project/src/components/themes/theme03/source/assets/3d/11.pngbinary1.6 MB
project/src/components/themes/theme03/source/assets/3d/12.pngbinary1.8 MB
project/src/components/themes/theme03/source/src/icons.jsscript799 B
project/src/components/themes/theme03/source/src/preset3d.jsscript119 B
project/src/components/themes/theme03/source/src/presetBase.jsscript3.4 KB
project/src/components/themes/theme03/source/src/registry.jsscript22.3 KB
project/src/components/themes/theme03/source/src/slides/safeProps.jsscript504 B
project/src/components/themes/theme03/source/src/theme.cssother5.4 KB
project/src/components/themes/theme03/source/src/theme.jsscript3.0 KB
project/src/components/themes/theme04/TEXT_CONTROL_POLICY.mdmarkdown344 B
project/src/components/themes/theme04/metadata.jsscript324.4 KB
project/src/components/themes/theme04/overrides.jsscript118 B
project/src/components/themes/theme04/source/image-slot.jsscript41.0 KB
project/src/components/themes/theme05/metadata.jsscript492.0 KB
project/src/components/themes/theme05/source/styles/exc-covers.cssother9.6 KB
project/src/components/themes/theme05/source/styles/pulse-deck.cssother288.9 KB
project/src/components/themes/theme06/metadata.jsscript331.7 KB
project/src/components/themes/theme07/metadata.jsscript319.6 KB
project/src/components/themes/theme07/source/src/theme.jsscript2.9 KB
project/src/components/themes/theme08/metadata.jsscript366.7 KB
project/src/components/themes/theme08/source/image-slot.jsscript45 B
project/src/components/themes/theme09/metadata.jsscript378.4 KB
project/src/components/themes/theme10/metadata.jsscript294.2 KB
project/src/components/themes/theme11/metadata.jsscript399.9 KB
project/src/components/themes/theme12/metadata.jsscript311.7 KB
project/src/components/themes/theme12/source/src/index.jsscript23.1 KB
project/src/components/themes/theme12/source/src/swTheme.jsscript2.3 KB
project/src/components/themes/unicorn-background.jsxother2.0 KB
project/src/control-naming.mjsscript17.2 KB
project/src/deckComposer.jsxother18.8 KB
project/src/generated-metadata-writer.mjsscript722 B
project/src/i18n-core.mjsscript2.3 KB
project/src/i18n.mjsscript1.8 KB
project/src/metadata-serialize.mjsscript6.1 KB
project/src/options.jsxother1.5 KB
project/src/prop-contract-core.mjsscript70.1 KB
project/src/propContracts.jsxother658 B
project/src/react-shim.jsscript51 B
project/src/renderDeck.jsxother14.0 KB
project/src/runtime-assets.mjsscript1.7 KB
project/src/types.d.tsscript1.7 KB
project/src/variant-contract.mjsscript28.8 KB
project/src/variant-materializer.mjsscript9.0 KB
project/src/view-model/context.jsxother382 B
project/src/view-model/index.jsxother26.0 KB
project/src/view-model/schema-v2-canonical.mjsscript471 B
references/examples/annual-review.jsonconfig14.9 KB
references/examples/portfolio.jsonconfig13.1 KB
references/goal-spec.schema.jsonconfig9.9 KB
references/layout-roles.mdmarkdown1.7 KB
references/options.mdmarkdown7.5 KB
scripts/check_latest_version.mjsexecutablescript3.1 KB
scripts/render_goal_deck.ps1script4.5 KB
scripts/render_goal_deck.shexecutablescript2.3 KB

project/scripts/goal-scaffold.mjs

View on GitHub
#!/usr/bin/env node
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import path from 'node:path';
import {
  compactJson,
  isCoverCandidate,
  isCoverLikeLayout,
  inspectLayout,
  listLayouts,
  parseArgs,
} from './skill-workflow-utils.mjs';
import {
  hashSeed,
  listLayoutsForContentPacks,
  materializeTemplateProjection,
} from './workflow/layout-query.mjs';
import { allocateDeckLayouts } from './workflow/layout-allocation.mjs';
import {
  beginWorkflowStage,
  workflowRunIdForScaffold,
  workflowTelemetryPath,
} from './workflow-telemetry.mjs';
import {
  BESPOKE_CHART_POINT_LIMIT,
  BESPOKE_LIST_ITEM_LIMIT,
  classifyPageIntent,
  normalizePageContentPack,
  pageContentProjectionItems,
} from '../src/variant-contract.mjs';
import { validateGoalSpec } from './validate-goal-spec.mjs';

const BESPOKE_VARIANT_ID = 'v4';
const BESPOKE_MEDIA_LIMITS = { statement: 0, metric: 0, ledger: 0, chart: 4, media: 8 };
let lastAllocationDiagnostics = null;
let lastGenerationMetrics = null;

// 相对路径按调用方目录解析:npm run(含 --prefix)会把脚本 cwd 切到项目根,INIT_CWD 才是用户所在目录。
const CALLER_CWD = process.env.INIT_CWD || process.cwd();

const DEFAULT_BODY_ROLES = [
  'statement',
  'breakdown',
  'context',
  'metrics',
  'comparison',
  'distribution',
  'relationship',
  'case',
  'image',
  'trend',
  'process',
  'risks',
  'actions',
  'result',
];

const BODY_ROLES = new Set([
  ...DEFAULT_BODY_ROLES,
  'transition',
  'observation',
  'ambient',
  'team',
]);

const args = parseArgs(process.argv.slice(2));

if (args.help || args.h) {
  printUsage();
  process.exit(0);
}

const contentPlanArg = args.contentPlan || args['content-plan'];
const scaffoldOut = typeof args.out === 'string' && args.out.trim()
  ? path.resolve(CALLER_CWD, args.out)
  : null;
const scaffoldRunId = contentPlanArg && scaffoldOut
  ? workflowRunIdForScaffold(scaffoldOut)
  : null;
const scaffoldTelemetry = scaffoldRunId
  ? beginWorkflowStage({
      goalPath: scaffoldOut,
      telemetryFile: workflowTelemetryPath(scaffoldOut),
      runId: scaffoldRunId,
      stage: 'scaffold',
    })
  : null;

try {
  run();
  scaffoldTelemetry?.finish({ ok: true, metrics: lastGenerationMetrics });
} catch (error) {
  scaffoldTelemetry?.finish({ ok: false, error });
  console.error(error.message);
  process.exit(1);
}

function run() {
  const title = String(args.title || '').trim() || 'PPT';
  const goal = String(args.goal || '').trim() || title;
  const themePack = String(args.theme || args.themePack || '').trim();
  const pageCount = Math.max(1, Math.min(50, Number(args.pages || args.pageCount || args['page-count']) || 0));
  const chunkSize = Number(args.chunkSize || args['chunk-size']) || 0;
  const layoutVariantsArg = args.layoutVariants ?? args['layout-variants'];
  const layoutVariants = layoutVariantsArg === undefined ? 3 : Number(layoutVariantsArg);
  const out = String(args.out || '').trim();
  const mediaIntent = parseMediaIntent(args);
  const contentPlan = contentPlanArg ? readContentPlan(contentPlanArg, pageCount) : null;

  if (!themePack) throw new Error('Missing --theme <themePack>');
  if (!pageCount) throw new Error('Missing --pages <n>');
  if (!out) throw new Error('Missing --out <goal.json>');
  if (layoutVariantsArg === true || ![1, 3].includes(layoutVariants)) {
    throw new Error('--layout-variants must be 1 or 3');
  }
  if (contentPlan && layoutVariants !== 3) {
    throw new Error('--content-plan requires --layout-variants 3');
  }
  if (!contentPlan && layoutVariants === 3) {
    throw new Error('--layout-variants 3 requires --content-plan <PageContentPack JSON>');
  }

  const { roles, explicit: rolesExplicit } = contentPlan
    ? { roles: [], explicit: false }
    : parseRoles(args.roles, Math.max(0, pageCount - 2));
  // 选页 seed:同分候选随机打散,让不同用户/不同次 scaffold 的骨架不再成片雷同;
  // --seed 显式传入时可复现同一份骨架。
  const seed = args.seed !== undefined && args.seed !== true ? String(args.seed) : String(Math.floor(Math.random() * 0xffffffff));
  const slides = buildSlides({
    themePack,
    pageCount,
    roles,
    rolesExplicit,
    mediaIntent,
    seed,
    layoutVariants,
    contentPlan,
  });
  const spec = {
    ...(layoutVariants === 3
      ? {
          schemaVersion: 2,
          variantOutputMode: 'comparison',
        }
      : {}),
    title,
    goal,
    themePack,
    pageCount,
    randomSeed: seed,
    ...(scaffoldRunId ? { workflowRunId: scaffoldRunId } : {}),
    slides,
  };
  const errors = validateGoalSpec(spec, contentPlan ? {} : {
    allowUnfilledMediaIntent: true,
    allowUnfilledBespoke: true,
    allowUnfilledContent: true,
  });
  if (errors.length) throw new Error(`Scaffold failed goal spec validation:\n- ${errors.join('\n- ')}`);

  writeJson(out, spec);
  const fillPlanOut = writeFillPlan(out, spec);
  writeChunks(out, spec, chunkSize);
  process.stdout.write(compactJson({
    out: path.resolve(CALLER_CWD, out),
    fillPlanOut,
    themePack,
    pageCount,
    layoutVariants,
    slideCount: slides.length,
    chunkSize: chunkSize || null,
    ...(lastAllocationDiagnostics ? { allocation: lastAllocationDiagnostics } : {}),
  }));
}

function buildSlides({
  themePack,
  pageCount,
  roles,
  rolesExplicit,
  mediaIntent,
  seed = null,
  layoutVariants = 3,
  contentPlan = null,
}) {
  if (contentPlan) {
    return buildContentPlanSlides({ themePack, contentPlan, seed });
  }
  if (layoutVariants !== 1) throw new Error('Schema v2 scaffolding requires --content-plan');
  const used = new Set();
  let mediaAssigned = false;
  const slides = Array.from({ length: pageCount }, (_, index) => {
    const isCover = index === 0;
    const isClosing = pageCount > 1 && index === pageCount - 1;
    const isBody = !isCover && !isClosing;
    const bodyIndex = index - 1;
    const useMediaIntent = Boolean(mediaIntent && !mediaAssigned && isBody);
    let role = isCover
      ? 'cover'
      : isClosing
        ? 'closing'
        : rolesExplicit
          ? roles[bodyIndex]
          : roles[bodyIndex % roles.length];
    if (useMediaIntent) role = 'image';

    const layout = pickLayout({
      themePack,
      role,
      used,
      body: !isCover,
      mediaIntent: useMediaIntent ? mediaIntent : null,
      seed: `${seed}:slide-${index + 1}`,
    });
    used.add(layout);
    if (useMediaIntent) mediaAssigned = true;
    return {
      layout,
      props: {},
      ...(useMediaIntent ? { [mediaIntent.field]: mediaIntent.value } : {}),
    };
  });
  if (mediaIntent && !mediaAssigned) {
    throw new Error(`No body slide available for ${mediaIntent.field}; use --pages 3 or more`);
  }
  return slides;
}


function buildContentPlanSlides({ themePack, contentPlan, seed }) {
  const bespokeFamilies = planBespokeFamilies(contentPlan);
  const bespokeVariants = contentPlan.map((page, pageIndex) => buildCanonicalBespoke(
    page.presentation,
    { pageIndex, family: bespokeFamilies[pageIndex], logicalId: page.id },
  ));
  const candidateMatrix = listLayoutsForContentPacks({
    theme: themePack,
    pages: contentPlan,
    limit: 50,
    seed,
  });
  const descriptors = contentPlan.map((page, pageIndex) => {
    const wantsCover = classifyPageIntent(page.presentation.pageIntent) === 'cover';
    const coverCandidates = candidateMatrix[pageIndex].filter(item => isCoverCandidate(item.layout));
    const bodyCandidates = candidateMatrix[pageIndex].filter(item => !isCoverCandidate(item.layout) && !isCoverLikeLayout(item.layout));
    const candidates = wantsCover && supportsThreeTemplateCompositions(coverCandidates)
      ? coverCandidates
      : bodyCandidates;
    if (candidates.length < 3) {
      throw new Error(`PageContentPack ${page.id} has ${candidates.length} compatible template layouts in ${themePack}; required 3`);
    }
    return { ...page, candidates };
  });
  const { assignments, diagnostics } = allocateDeckLayouts(
    descriptors.map(item => item.candidates),
    seed,
  );
  lastAllocationDiagnostics = diagnostics;
  lastGenerationMetrics = {
    planningPasses: 1,
    layoutQueryPasses: 1,
    projectionPlansEvaluated: candidateMatrix.reduce((sum, candidates) => sum + candidates.length, 0),
    allocationPasses: 1,
    materializationPasses: 1,
    materializedVariants: descriptors.length * 3,
    pageCount: descriptors.length,
  };
  return descriptors.map((page, pageIndex) => ({
    id: page.id,
    content: { presentation: page.presentation },
    selectedVariant: 'v1',
    variants: [
      ...assignments[pageIndex].map((candidate, variantIndex) => {
        const projection = materializeTemplateProjection(candidate, page.presentation, variantIndex);
        return {
          id: `v${variantIndex + 1}`,
          kind: 'template',
          layout: candidate.layout,
          contentMap: projection.contentMap,
          projection: {
            chartMode: projection.projectionPlan.chartMode,
            contentPaths: projection.contentPaths,
            projectedItemIds: projection.projectedItemIds,
            chartBindings: projection.chartBindings,
            structure: projection.structure,
          },
        };
      }),
      bespokeVariants[pageIndex],
    ],
  }));
}

function supportsThreeTemplateCompositions(candidates) {
  return candidates.length >= 3 && new Set(candidates.map(item => (
    item.structureFingerprint?.composition || item.layout
  ))).size >= 3;
}

function buildCanonicalBespoke(presentation, options = {}) {
  const chartData = presentation.chartData || [];
  if (chartData.length > BESPOKE_CHART_POINT_LIMIT) throw new Error(`Bespoke slide ${options.logicalId || 'unknown'} has ${chartData.length} chart points; limit=${BESPOKE_CHART_POINT_LIMIT}`);
  assertBespokeFamilyCapacity(presentation, options.family, options.logicalId);
  return buildBespokeFamily(presentation, options);
}

function planBespokeFamilies(contentPlan) {
  const counts = new Map();
  let previous = null;
  return contentPlan.map(({ presentation }) => {
    const eligible = eligibleBespokeFamilies(presentation);
    const family = eligible
      .map((value, index) => ({ value, index }))
      .sort((left, right) => (
        Number(left.value === previous) - Number(right.value === previous)
        || (counts.get(left.value) || 0) - (counts.get(right.value) || 0)
        || left.index - right.index
      ))[0].value;
    counts.set(family, (counts.get(family) || 0) + 1);
    previous = family;
    return family;
  });
}

function eligibleBespokeFamilies(presentation) {
  if (presentation.chartData?.length) return ['chart'];
  if (presentation.media?.length) return ['media'];
  const items = pageContentProjectionItems(presentation);
  if (!items.length) return ['statement'];
  const valued = items.filter(item => item.hasValue);
  return [
    ...(valued.length ? ['metric'] : []),
    'statement',
    'ledger',
  ];
}

function assertBespokeFamilyCapacity(presentation, family, logicalId) {
  const mediaCount = presentation.media?.length || 0;
  const limit = BESPOKE_MEDIA_LIMITS[family];
  if (limit == null) throw new Error(`Bespoke slide ${logicalId || 'unknown'} has unknown family "${family}"`);
  if (mediaCount > limit) throw new Error(`Bespoke slide ${logicalId || 'unknown'} family ${family} supports at most ${limit} media items; received ${mediaCount}`);
}

function buildBespokeFamily(presentation, { pageIndex = 0, family = 'ledger', logicalId } = {}) {
  const items = pageContentProjectionItems(presentation);
  const metricItems = family === 'metric' ? items.filter(item => item.hasValue).slice(0, 2) : [];
  const metricIds = new Set(metricItems.map(item => item.id));
  const itemIds = new Set(items.map(item => item.id));
  const factSourceItems = selectBespokeListItems(items.filter(item => !metricIds.has(item.id)), logicalId);
  const chartFactItems = family === 'chart' ? [] : (presentation.chartData || []).filter(item => !itemIds.has(item.id));
  const factCount = factSourceItems.length + chartFactItems.length;
  const compositionIndex = pageIndex % 3;
  const mirror = pageIndex % 2 === 1;
  const prefix = `bespoke-${family}`;
  const text = (slot, grid, role = 'body') => ({ id: `${prefix}-${slot}`, type: 'text', grid, role });
  const elements = [];
  if (family === 'statement') {
    const statementColumn = mirror ? 4 : 1;
    elements.push(
      text('kicker', { column: mirror ? 9 : 1, row: 1, width: 4, height: 1 }, 'kicker'),
      text('title', { column: statementColumn, row: 2, width: 8, height: 1 }, 'title'),
      { id: `${prefix}-core`, type: 'quote', grid: { column: statementColumn, row: 3, width: mirror || factCount ? 9 : 12, height: 5 } },
    );
    if (factCount) elements.push({ id: `${prefix}-facts`, type: 'list', grid: { column: mirror ? 1 : 10, row: 3, width: 3, height: 5 }, ordered: true });
  } else if (family === 'metric') {
    const heroColumn = mirror ? 6 : 1;
    const sideColumn = mirror ? 1 : 8;
    elements.push(
      text('kicker', { column: 1, row: 1, width: 3, height: 1 }, 'kicker'),
      text('title', { column: 4, row: 1, width: 9, height: 1 }, 'title'),
      text('core', { column: 1, row: 2, width: 8, height: 1 }, 'subtitle'),
      text('summary', { column: 9, row: 2, width: 4, height: 1 }, 'caption'),
    );
    metricItems.forEach((_, index) => elements.push({
      id: `${prefix}-value-${index + 1}`,
      type: 'metric',
      grid: index === 0
        ? { column: heroColumn, row: 3, width: 7, height: 5 }
        : { column: sideColumn, row: 3, width: 5, height: 2 },
      tone: index === 0 ? 'inverse' : 'accent',
    }));
    if (factCount) elements.push({ id: `${prefix}-facts`, type: 'list', grid: { column: sideColumn, row: metricItems.length > 1 ? 5 : 3, width: 5, height: metricItems.length > 1 ? 3 : 5 }, ordered: true });
  } else if (family === 'chart') {
    const media = presentation.media || [];
    if (compositionIndex === 0) {
      const chartColumn = mirror ? 5 : 1;
      const factsColumn = mirror ? 1 : 9;
      elements.push(
        text('kicker', { column: 1, row: 1, width: 3, height: 1 }, 'kicker'),
        text('title', { column: 4, row: 1, width: 9, height: 1 }, 'title'),
        text('core', { column: 1, row: 2, width: 8, height: 1 }, 'subtitle'),
        text('summary', { column: 9, row: 2, width: 4, height: 1 }, 'caption'),
        { id: `${prefix}-plot`, type: 'chart', grid: { column: chartColumn, row: 3, width: factCount ? 8 : 12, height: media.length ? 4 : 6 }, chartType: 'bar', showValues: true },
      );
      if (factCount) elements.push({ id: `${prefix}-facts`, type: 'list', grid: { column: factsColumn, row: 3, width: 4, height: media.length ? 4 : 6 }, ordered: true });
      addHorizontalMedia(elements, prefix, media, 0, { column: 1, row: 7, width: 12, height: 2 });
    } else if (compositionIndex === 1) {
      elements.push(
        text('kicker', { column: 1, row: 1, width: 4, height: 1 }, 'kicker'),
        text('title', { column: 1, row: 2, width: 4, height: 2 }, 'title'),
        text('core', { column: 1, row: 4, width: 4, height: 2 }, 'subtitle'),
        text('summary', { column: 1, row: 6, width: 4, height: 1 }, 'caption'),
        { id: `${prefix}-plot`, type: 'chart', grid: { column: 5, row: 1, width: 8, height: media.length ? 6 : 8 }, chartType: 'line', showValues: true },
      );
      if (factCount) elements.push({ id: `${prefix}-facts`, type: 'list', grid: { column: 1, row: 7, width: 4, height: 2 }, ordered: true });
      addHorizontalMedia(elements, prefix, media, 0, { column: 5, row: 7, width: 8, height: 2 });
    } else {
      elements.push(
        text('kicker', { column: 1, row: 1, width: 3, height: 1 }, 'kicker'),
        text('title', { column: 4, row: 1, width: 9, height: 1 }, 'title'),
        text('core', { column: 1, row: 2, width: 7, height: 1 }, 'subtitle'),
        text('summary', { column: 8, row: 2, width: 5, height: 1 }, 'caption'),
        { id: `${prefix}-plot`, type: 'chart', grid: { column: 1, row: 3, width: 12, height: factCount || media.length ? 4 : 6 }, chartType: 'line', showValues: true },
      );
      if (factCount) elements.push({ id: `${prefix}-facts`, type: 'list', grid: { column: 1, row: 7, width: media.length ? 4 : 12, height: 2 }, ordered: true });
      addHorizontalMedia(elements, prefix, media, 0, { column: factCount ? 5 : 1, row: 7, width: factCount ? 8 : 12, height: 2 });
    }
  } else if (family === 'media') {
    const media = presentation.media || [];
    if (compositionIndex === 0) {
      const mediaColumn = mirror ? 1 : 6;
      const textColumn = mirror ? 8 : 1;
      elements.push(
        text('kicker', { column: textColumn, row: 1, width: 5, height: 1 }, 'kicker'),
        text('title', { column: textColumn, row: 2, width: 5, height: 2 }, 'title'),
        text('core', { column: textColumn, row: 4, width: 5, height: 2 }, 'subtitle'),
        text('summary', { column: textColumn, row: 6, width: 5, height: 1 }, 'caption'),
      );
      if (factCount) elements.push({ id: `${prefix}-facts`, type: 'list', grid: { column: textColumn, row: 7, width: 5, height: 2 }, ordered: true });
      addVerticalMedia(elements, prefix, media, { column: mediaColumn, row: 1, width: 7, height: 8 });
    } else if (compositionIndex === 1) {
      elements.push(
        text('kicker', { column: 1, row: 1, width: 4, height: 1 }, 'kicker'),
        text('title', { column: 1, row: 2, width: 4, height: 2 }, 'title'),
        text('core', { column: 1, row: 4, width: 4, height: 2 }, 'subtitle'),
        text('summary', { column: 1, row: 6, width: 4, height: 1 }, 'caption'),
        { id: `${prefix}-media-1`, type: 'media', grid: { column: 5, row: 1, width: 8, height: media.length > 1 ? 6 : 8 }, fit: 'cover' },
      );
      if (factCount) elements.push({ id: `${prefix}-facts`, type: 'list', grid: { column: 1, row: 7, width: 4, height: 2 }, ordered: true });
      addHorizontalMedia(elements, prefix, media, 1, { column: 5, row: 7, width: 8, height: 2 });
    } else {
      elements.push(
        text('kicker', { column: 1, row: 1, width: 3, height: 1 }, 'kicker'),
        text('title', { column: 4, row: 1, width: 9, height: 1 }, 'title'),
        text('core', { column: 1, row: 2, width: 7, height: 1 }, 'subtitle'),
        text('summary', { column: 8, row: 2, width: 5, height: 1 }, 'caption'),
      );
      if (factCount) elements.push({ id: `${prefix}-facts`, type: 'list', grid: { column: 1, row: 3, width: 3, height: 6 }, ordered: true });
      addMediaGrid(elements, prefix, media, { column: factCount ? 4 : 1, row: 3, width: factCount ? 9 : 12, height: 6 });
    }
  } else {
    const coreColumn = mirror ? 6 : 1;
    const summaryColumn = mirror ? 1 : 8;
    elements.push(
      text('kicker', { column: mirror ? 10 : 1, row: 1, width: 3, height: 1 }, 'kicker'),
      text('title', { column: mirror ? 1 : 4, row: 1, width: 9, height: 1 }, 'title'),
      text('core', { column: coreColumn, row: 2, width: 7, height: 1 }, 'subtitle'),
      text('summary', { column: summaryColumn, row: 2, width: 5, height: 1 }, 'caption'),
      { id: `${prefix}-facts`, type: 'list', grid: { column: 1, row: 3, width: 12, height: 6 }, ordered: true },
    );
  }

  const contentMap = {};
  elements.forEach((element, index) => {
    if (element.id === `${prefix}-kicker`) contentMap[`elements[${index}].text`] = 'presentation.pageIntent';
    if (element.id === `${prefix}-title`) contentMap[`elements[${index}].text`] = 'presentation.title.short';
    if (element.id === `${prefix}-core`) contentMap[`elements[${index}].${element.type === 'quote' ? 'quote' : 'text'}`] = 'presentation.coreMessage';
    if (element.id === `${prefix}-summary`) contentMap[`elements[${index}].text`] = 'presentation.summary.short';
    if (element.type === 'quote' && element.id === `${prefix}-core`) contentMap[`elements[${index}].attribution`] = 'presentation.summary.short';
  });
  const itemBindings = [];
  metricItems.forEach((item, index) => {
    const elementIndex = elements.findIndex(element => element.id === `${prefix}-value-${index + 1}`);
    if (elementIndex >= 0) itemBindings.push({ id: item.id, target: `elements[${elementIndex}]` });
  });
  const factsIndex = elements.findIndex(element => element.id === `${prefix}-facts`);
  if (factsIndex >= 0) factSourceItems.forEach((item, index) => itemBindings.push({ id: item.id, target: `elements[${factsIndex}].items[${index}]` }));
  const chartBindings = factsIndex < 0 ? [] : chartFactItems.map((item, index) => ({
    mode: 'summary',
    sourceIds: [item.id],
    target: `elements[${factsIndex}].items[${factSourceItems.length + index}]`,
  }));
  const chartIndex = elements.findIndex(element => element.id === `${prefix}-plot`);
  if (chartIndex >= 0) (presentation.chartData || []).forEach((item, index) => chartBindings.push({
    mode: 'point',
    sourceIds: [item.id],
    target: `elements[${chartIndex}].data[${index}]`,
  }));
  const mediaBindings = [];
  elements.forEach((element, index) => {
    if (element.type === 'media') mediaBindings.push({ sourceIndex: mediaBindings.length, target: `elements[${index}]` });
  });
  if (mediaBindings.length !== (presentation.media?.length || 0)) {
    throw new Error(`Bespoke slide ${logicalId || 'unknown'} family ${family} did not define every media binding`);
  }
  return {
    id: BESPOKE_VARIANT_ID,
    kind: 'bespoke',
    adjustable: false,
    composition: {
      designIntent: {
        objective: '呈现单页核心信息',
        audience: '当前演示文稿受众',
        narrativeRole: '推进单页叙事',
        emphasis: '突出内容层级与证据关系',
        rationale: `${family}-${compositionIndex + 1} 结构投影`,
      },
      background: 'default',
      elements,
    },
    projection: { itemBindings, chartBindings, mediaBindings },
    contentMap,
  };
}

function addHorizontalMedia(elements, prefix, media, startIndex, area) {
  const count = Math.max(0, media.length - startIndex);
  if (!count) return;
  const width = Math.max(1, Math.floor(area.width / count));
  media.slice(startIndex).forEach((_, offset) => elements.push({
    id: `${prefix}-media-${startIndex + offset + 1}`,
    type: 'media',
    grid: { column: area.column + offset * width, row: area.row, width: offset === count - 1 ? area.width - offset * width : width, height: area.height },
    fit: 'cover',
  }));
}

function addVerticalMedia(elements, prefix, media, area) {
  const height = Math.max(1, Math.floor(area.height / Math.max(1, media.length)));
  media.forEach((_, index) => elements.push({
    id: `${prefix}-media-${index + 1}`,
    type: 'media',
    grid: { column: area.column, row: area.row + index * height, width: area.width, height: index === media.length - 1 ? area.height - index * height : height },
    fit: 'cover',
  }));
}

function addMediaGrid(elements, prefix, media, area) {
  const columns = media.length <= 2 ? Math.max(1, media.length) : media.length <= 4 ? 2 : 4;
  const rows = Math.max(1, Math.ceil(media.length / columns));
  const width = Math.max(1, Math.floor(area.width / columns));
  const height = Math.max(1, Math.floor(area.height / rows));
  media.forEach((_, index) => {
    const columnIndex = index % columns;
    const rowIndex = Math.floor(index / columns);
    elements.push({
      id: `${prefix}-media-${index + 1}`,
      type: 'media',
      grid: {
        column: area.column + columnIndex * width,
        row: area.row + rowIndex * height,
        width: columnIndex === columns - 1 ? area.width - columnIndex * width : width,
        height: rowIndex === rows - 1 ? area.height - rowIndex * height : height,
      },
      fit: 'cover',
    });
  });
}

function selectBespokeListItems(items, logicalId) {
  const pinnedCount = items.filter(item => item.pinned).length;
  if (pinnedCount > BESPOKE_LIST_ITEM_LIMIT) {
    throw new Error(`Bespoke slide ${logicalId || 'unknown'} has ${pinnedCount} list-bound pinned facts; limit=${BESPOKE_LIST_ITEM_LIMIT}`);
  }
  let optionalSlots = BESPOKE_LIST_ITEM_LIMIT - pinnedCount;
  return items.filter(item => item.pinned || optionalSlots-- > 0);
}

function readContentPlan(file, expectedCount) {
  if (file === true) throw new Error('--content-plan requires a JSON file');
  const resolved = path.resolve(CALLER_CWD, String(file));
  const parsed = JSON.parse(readFileSync(resolved, 'utf8'));
  const pages = Array.isArray(parsed) ? parsed : parsed?.pages;
  if (!Array.isArray(pages)) throw new Error('--content-plan must contain an array or {pages:[...]}');
  if (pages.length !== expectedCount) {
    throw new Error(`--content-plan must contain exactly ${expectedCount} pages, found ${pages.length}`);
  }
  const ids = new Set();
  return pages.map((entry, index) => {
    const source = entry?.presentation || entry;
    let presentation;
    try {
      presentation = normalizePageContentPack(source);
    } catch (error) {
      throw new Error(`content plan page ${index + 1}: ${error.message}`);
    }
    const id = String(entry?.id || '').trim();
    if (!id) throw new Error(`content plan page ${index + 1}: stable id is required`);
    if (ids.has(id)) throw new Error(`content plan contains duplicate logical page id "${id}"`);
    ids.add(id);
    return { id, presentation };
  });
}

function pickLayout({ themePack, role, used, body, mediaIntent = null, seed = null }) {
  const mediaQuery = mediaIntent ? mediaIntentQuery(mediaIntent) : {};
  const roleCandidates = listLayouts({ theme: themePack, role, ...mediaQuery, limit: 80, seed });
  const fallbackCandidates = listLayouts({ theme: themePack, ...mediaQuery, limit: 200, seed });
  const seen = new Set();
  const candidates = [...roleCandidates, ...fallbackCandidates]
    .map(item => item.layout)
    .filter(Boolean)
    .filter(layout => {
      if (seen.has(layout)) return false;
      seen.add(layout);
      return true;
    })
    .filter(layout => !used.has(layout))
    .filter(layout => (
      body
        ? !isCoverCandidate(layout) && !isCoverLikeLayout(layout)
        : isCoverCandidate(layout)
    ));
  if (!candidates.length) throw new Error(`No unused ${body ? 'body' : 'cover'} layout available for role "${role}" in ${themePack}`);
  // 从前 5 名合格候选里 seeded 随机挑:打分只有一两个精确命中时,永远取第一会让
  // 不同用户的骨架在这些 role 上完全一致;候选都已通过过滤(均"符合"),前几名之间
  // 的分差只是相关性排序,随机采样是多样性与相关性的折衷。
  const pool = candidates.slice(0, 5);
  const layout = pool[hashSeed(`${seed}:${role}:${used.size}`) % pool.length];
  return layout;
}

function parseMediaIntent(args) {
  const plannedImages = mediaIntentCount(args['planned-images'] ?? args.plannedImages);
  if (plannedImages) return { field: 'plannedImages', value: plannedImages, count: plannedImages };
  if (args['image-gen'] === true || args.imageGen === true) return { field: 'imageGen', value: true, count: 1 };
  if (args['needs-visual'] === true || args.needsVisual === true) return { field: 'needsVisual', value: true, count: 1 };
  return null;
}

function mediaIntentQuery(intent) {
  if (!intent) return {};
  if (intent.field === 'plannedImages') return { plannedImages: intent.count, mediaCount: intent.count };
  if (intent.field === 'imageGen') return { imageGen: true, mediaCount: intent.count };
  if (intent.field === 'needsVisual') return { needsVisual: true, mediaCount: intent.count };
  return {};
}

function mediaIntentCount(value) {
  if (value === true) return 1;
  const count = Number(value);
  if (Number.isFinite(count) && count > 0) return Math.round(count);
  return 0;
}

function parseRoles(value, expectedCount) {
  if (value === undefined) {
    return { roles: DEFAULT_BODY_ROLES, explicit: false };
  }
  if (value === true) throw new Error('Missing value for --roles');
  const roles = String(value)
    .split(',')
    .map(item => item.trim());
  if (roles.some(role => !role)) {
    throw new Error('--roles must be a comma-separated sequence without empty entries');
  }
  const structural = roles.filter(role => role === 'cover' || role === 'closing');
  if (structural.length) {
    throw new Error(`--roles only accepts body roles; cover and closing are automatic (received ${structural.join(', ')})`);
  }
  const unknown = [...new Set(roles.filter(role => !BODY_ROLES.has(role)))];
  if (unknown.length) {
    throw new Error(`Unknown --roles value(s): ${unknown.join(', ')}. Allowed body roles: ${[...BODY_ROLES].join(', ')}`);
  }
  if (roles.length !== expectedCount) {
    throw new Error(
      `--roles must provide exactly ${expectedCount} body roles for the requested page count; `
      + `cover and closing are automatic (received ${roles.length})`,
    );
  }
  return { roles, explicit: true };
}

function writeChunks(out, spec, chunkSize) {
  if (!Number.isFinite(chunkSize) || chunkSize <= 0) return;
  const size = Math.max(1, Math.round(chunkSize));
  const total = Math.ceil(spec.slides.length / size);
  const parsed = path.parse(out);
  for (let index = 0; index < total; index += 1) {
    const start = index * size;
    const end = Math.min(spec.slides.length, start + size);
    const chunkPath = path.join(parsed.dir, `${parsed.name}.part-${String(index + 1).padStart(2, '0')}.json`);
    const chunkSpec = {
      ...(spec.schemaVersion != null ? { schemaVersion: spec.schemaVersion } : {}),
      ...(spec.variantOutputMode ? { variantOutputMode: spec.variantOutputMode } : {}),
      title: spec.title,
      goal: spec.goal,
      themePack: spec.themePack,
      pageCount: spec.pageCount,
      ...(spec.randomSeed != null ? { randomSeed: spec.randomSeed } : {}),
      part: {
        index: index + 1,
        total,
        startSlide: start + 1,
        endSlide: end,
      },
      slides: spec.slides.slice(start, end),
    };
    writeJson(chunkPath, chunkSpec);
    writeFillPlan(chunkPath, chunkSpec);
  }
}

function writeJson(file, value) {
  const target = path.resolve(CALLER_CWD, file);
  mkdirSync(path.dirname(target), { recursive: true });
  writeFileSync(target, compactJson(value));
}

function writeFillPlan(goalPath, spec) {
  const out = fillPlanPath(goalPath);
  writeJson(out, {
    goal: path.resolve(CALLER_CWD, goalPath),
    themePack: spec.themePack,
    slideCount: spec.slides.length,
    ...(spec.part ? { part: spec.part } : {}),
    slides: spec.slides.map((slide, index) => ({
      slide: (spec.part?.startSlide || 1) + index,
      ...(Array.isArray(slide.variants)
        ? {
            selectedVariant: slide.selectedVariant,
            variants: slide.variants.map(item => inspectFillPlan(item)),
          }
        : inspectFillPlan(slide)),
    })),
  });
  return path.resolve(CALLER_CWD, out);
}

function fillPlanPath(goalPath) {
  const parsed = path.parse(goalPath);
  return path.join(parsed.dir, `${parsed.name}.fill-plan.json`);
}

function inspectFillPlan(slide) {
  if (slide?.kind === 'bespoke') {
    return {
      id: slide.id || BESPOKE_VARIANT_ID,
      kind: 'bespoke',
      adjustable: false,
      designTask: {
        status: 'generated',
        instruction: '保留 scaffold 生成的 composition 结构与 projection bindings;业务值只修改 slide.content.presentation,不写回 composition。',
      },
    };
  }
  const inspected = inspectLayout(slide.layout, { compact: true });
  return {
    ...(slide.id ? { id: slide.id } : {}),
    ...(slide.kind ? { kind: slide.kind } : {}),
    layout: slide.layout,
    label: inspected?.label || null,
    roles: inspected?.roles || [],
    fillPlan: inspected?.fillPlan || null,
  };
}

function printUsage() {
  console.error('Usage: node scripts/goal-scaffold.mjs --title <title> --goal <goal> --theme <themeXX> --pages <n> --out output/<deck>/goal.json [--layout-variants 1|3] [--roles <one-body-role-per-page>] [--content-plan <pages.json>] [--chunk-size 5]');
}
canvas-designanthropics/skillsCreate beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
docxanthropics/skillsUse this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
pdfanthropics/skillsUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
pptxanthropics/skillsUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill.Stars: 198kUpdated Claude CodeCodexVerifiedInstall