chuspeeism/dashi-ppt-skill / skills/dashi-ppt
dashi-ppt
Flagged制作 PPT、演示文稿、幻灯片、汇报材料时使用。Dashi PPT 基于预置视觉主题组合页面,生成可离线打开、可在浏览器编辑的 HTML 演示,支持导出 PPTX / PDF 文件。
project/scripts/validate-swiss-deck.mjs
View on GitHub#!/usr/bin/env node
import { existsSync, readFileSync } from 'node:fs';
import path from 'node:path';
import {
LOCAL_OUTPUT_ASSET_ROOTS,
REQUIRED_OUTPUT_ASSETS,
} from '../src/runtime-assets.mjs';
// 相对路径按调用方目录解析:npm run(含 --prefix)会把脚本 cwd 切到项目根,INIT_CWD 才是用户所在目录。
const CALLER_CWD = process.env.INIT_CWD || process.cwd();
const fileArg = process.argv[2];
const allowExperimental = process.argv.includes('--allow-experimental');
if (!fileArg) {
console.error('Usage: node scripts/validate-swiss-deck.mjs <index.html> [--allow-experimental]');
process.exit(2);
}
const file = path.resolve(CALLER_CWD, fileArg);
const html = readFileSync(file, 'utf8');
const htmlForSlides = html.replace(/<!--[\s\S]*?-->/g, '');
const errors = [];
const warnings = [];
const normalizedFile = file.replace(/\\/g, '/');
const isSwissTemplateShell = normalizedFile.endsWith('assets/template-swiss.html');
const deckDir = path.dirname(file);
if (!isSwissTemplateShell) {
const referencedAssets = collectLocalAssetRefs(html);
const runtimeFile = path.join(deckDir, 'assets/imported-theme-runtime.js');
if (existsSync(runtimeFile)) {
collectLocalAssetRefs(readFileSync(runtimeFile, 'utf8')).forEach(asset => referencedAssets.add(asset));
}
for (const asset of REQUIRED_OUTPUT_ASSETS) referencedAssets.add(asset);
[...referencedAssets].sort().forEach(asset => {
if (!existsSync(path.join(deckDir, asset))) {
errors.push(`Deck output is missing local asset file: ${asset}`);
}
});
}
function collectLocalAssetRefs(source) {
const refs = new Set();
for (const content of collectSourceVariants(source)) {
collectAttributeAssetRefs(content, refs);
collectCssUrlAssetRefs(content, refs);
collectStringAssetRefs(content, refs);
}
return refs;
}
function collectSourceVariants(source) {
const raw = String(source || '');
const variants = new Set([raw]);
variants.add(decodeHtmlEntities(raw));
for (const variant of [...variants]) {
variants.add(variant.replaceAll('\\/', '/'));
}
return variants;
}
function collectAttributeAssetRefs(source, refs) {
const attrRe = /\b(src|href|poster|srcset)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/gi;
let match;
while ((match = attrRe.exec(source))) {
const attr = match[1].toLowerCase();
const value = match[2] ?? match[3] ?? match[4] ?? '';
const candidates = attr === 'srcset' ? splitSrcset(value) : [value];
candidates.forEach(candidate => addLocalAssetRef(refs, candidate));
}
}
function collectCssUrlAssetRefs(source, refs) {
const urlRe = /url\(\s*["']?([^"')]+)["']?\s*\)/gi;
let match;
while ((match = urlRe.exec(source))) {
addLocalAssetRef(refs, match[1]);
}
}
function collectStringAssetRefs(source, refs) {
const stringRe = /(?:^|["'`(,;:\s=])((?:\.\/|\/)?(?:assets|images|uploads)\/[^"'`<>)\s\\]+?\.(?:png|jpe?g|webp|gif|svg|mp4|mov|json|js|css|wasm|woff2?|ttf|otf|ico))(?:[?#][^"'`<>)\s\\]*)?/gi;
let match;
while ((match = stringRe.exec(source))) {
addLocalAssetRef(refs, match[1]);
}
}
function splitSrcset(value) {
return String(value || '')
.split(',')
.map(item => item.trim().split(/\s+/)[0])
.filter(Boolean);
}
function addLocalAssetRef(refs, value) {
const ref = normalizeLocalAssetRef(value);
if (ref) refs.add(ref);
}
function normalizeLocalAssetRef(ref) {
let value = decodeHtmlEntities(String(ref || '').trim()).replaceAll('\\/', '/');
if (!value || /^(?:data:|blob:|https?:|mailto:|tel:|javascript:|about:|file:|#)/i.test(value)) return null;
if (value.startsWith('//')) return null;
if (value.includes('${') || value.includes('{{')) return null;
value = value.split(/[?#]/)[0].trim();
if (!value) return null;
try {
value = decodeURIComponent(value);
} catch {}
value = value.replace(/^\/+/, '');
while (value.startsWith('./')) value = value.slice(2);
if (!LOCAL_OUTPUT_ASSET_ROOTS.some(root => value.startsWith(`${root}/`))) return null;
if (value.split('/').some(part => !part || part === '..')) return null;
return value;
}
function decodeHtmlEntities(value) {
return value
.replaceAll('&', '&')
.replaceAll('"', '"')
.replaceAll(''', "'")
.replaceAll('<', '<')
.replaceAll('>', '>');
}
const manifestFile = 'layout-manifest.json';
const optionsFile = 'src/options.jsx';
const registeredLayouts = [
...(existsSync(manifestFile)
? Object.values(JSON.parse(readFileSync(manifestFile, 'utf8')).layouts || {}).map((layout) => layout.dataLayout).filter(Boolean)
: []),
...(existsSync(optionsFile)
? [...readFileSync(optionsFile, 'utf8').matchAll(/dataLayout:\s*'([^']+)'/g)].map((match) => match[1])
: []),
];
const allowedLayouts = new Set(registeredLayouts.length ? registeredLayouts : ['SANDBOX']);
const slideRe = /<section\b[^>]*class="[^"]*\bslide\b[^"]*"[^>]*>[\s\S]*?<\/section>/g;
const slides = [...htmlForSlides.matchAll(slideRe)].map((m, idx) => ({ idx: idx + 1, html: m[0], tag: m[0].match(/<section\b[^>]*>/)?.[0] ?? '' }));
if (!slides.length && !isSwissTemplateShell) {
errors.push('No <section class="slide"> pages found.');
}
if (html.includes('#deck .slide') || /\b\w*deck\w*\.querySelectorAll\(['"]\.slide/.test(html)) {
errors.push('Deck runtime uses descendant .slide selectors. Use only #deck direct children so imported theme internals cannot be treated as pages.');
}
const downloadBlobStart = html.indexOf('function downloadBlob');
const downloadBlobEnd = downloadBlobStart >= 0 ? html.indexOf('function releaseRetainedDownloadUrls', downloadBlobStart) : -1;
const downloadBlobSource = downloadBlobStart >= 0 && downloadBlobEnd > downloadBlobStart
? html.slice(downloadBlobStart, downloadBlobEnd)
: '';
if (downloadBlobSource.includes('URL.revokeObjectURL')) {
errors.push('Deck export download revokes blob URLs inside downloadBlob. Keep blob URLs alive until page unload so LAN downloads can finish.');
}
if (/\.writeFile\s*\(\s*\{\s*fileName:/.test(html)) {
errors.push('Deck export uses library writeFile download. Generate a blob and pass it through downloadBlob so LAN downloads can finish.');
}
const pdfExportStart = html.indexOf('window.__exportDeckPdf =');
const pdfExportEnd = pdfExportStart >= 0 ? html.indexOf('window.__exportDeckPptx', pdfExportStart) : -1;
const pdfExportSource = pdfExportStart >= 0 && pdfExportEnd > pdfExportStart
? html.slice(pdfExportStart, pdfExportEnd)
: '';
if (!/\/api\/export-pdf/.test(pdfExportSource) || !/startServerExportDownload\s*\(/.test(pdfExportSource)) {
errors.push('PDF export must use the local screenshot PDF service and trigger a browser download.');
}
if (/runBrowserPrint\s*\(|window\.print\s*\(/.test(pdfExportSource)) {
errors.push('PDF export must not use the browser print flow as its default path.');
}
if (!/buildPdfExportSnapshot/.test(pdfExportSource)) {
errors.push('PDF export must send the current deck state to the screenshot PDF service.');
}
const htmlExportStart = html.indexOf('window.__exportDeckHtml =');
const htmlExportEnd = htmlExportStart >= 0 ? html.indexOf('async function materializeExportSlides', htmlExportStart) : -1;
const htmlExportSource = htmlExportStart >= 0 && htmlExportEnd > htmlExportStart
? html.slice(htmlExportStart, htmlExportEnd)
: '';
const htmlExportMaterializeIndex = htmlExportSource.indexOf('materializeExportSlides');
const htmlExportCloneIndex = htmlExportSource.indexOf('cloneNode');
if (htmlExportMaterializeIndex < 0 || htmlExportCloneIndex < 0 || htmlExportMaterializeIndex > htmlExportCloneIndex) {
errors.push('HTML export must render every visible runtime slide before cloning the page.');
}
if (!/serializeHtmlExportClone\s*\(/.test(htmlExportSource) || !/function collectHtmlExportLocalMediaRefs\(/.test(html)) {
errors.push('HTML export must inline local image/video assets into the single exported HTML file.');
}
if (!/materializeHtmlExportViewModel/.test(html) || !/\.\.\.\(state\.props\?\.\[id\]\s*\|\|\s*\{\}\)/.test(html)) {
errors.push('HTML export must preserve current right-panel props in the embedded deck view model.');
}
const htmlPrepareStart = html.indexOf('async function prepareSimpleHtmlExportClone');
const htmlPrepareEnd = htmlPrepareStart >= 0 ? html.indexOf('function materializeHtmlExportViewModel', htmlPrepareStart) : -1;
const htmlPrepareSource = htmlPrepareStart >= 0 && htmlPrepareEnd > htmlPrepareStart
? html.slice(htmlPrepareStart, htmlPrepareEnd)
: '';
const removedInteractiveExportNodes = [
'#deck-topbar',
'#deck-page-pager',
'#slide-rail',
'#preview-panel',
'#preview-panel-collapse',
'#image-picker-input',
'#media-picker-input',
].filter((selector) => htmlPrepareSource.includes(`querySelector('${selector}')?.remove()`));
if (removedInteractiveExportNodes.length) {
errors.push(`HTML export must keep the editable shell and media inputs: ${removedInteractiveExportNodes.join(', ')}.`);
}
if (/classList\.remove\([^)]*preview-panel-open|classList\.remove\([^)]*editor-panels-collapsed/.test(htmlPrepareSource)) {
errors.push('HTML export must preserve the current editor panel state instead of forcing a partial shell.');
}
if (!html.includes('deck-export-cancel')) {
errors.push('Deck export overlay is missing a cancel button.');
}
const previewPanelStart = html.indexOf('<aside id="preview-panel"');
const previewPanelEnd = previewPanelStart >= 0 ? html.indexOf('</aside>', previewPanelStart) : -1;
const previewPanelSource = previewPanelStart >= 0 && previewPanelEnd > previewPanelStart
? html.slice(previewPanelStart, previewPanelEnd)
: '';
const previewActionsIndex = previewPanelSource.indexOf('class="preview-actions"');
const previewAuthorIndex = previewPanelSource.indexOf('class="preview-author"');
const previewAuthorSource = previewAuthorIndex >= 0
? previewPanelSource.slice(previewAuthorIndex, previewActionsIndex > previewAuthorIndex ? previewActionsIndex : undefined)
: '';
if (!previewPanelSource) {
errors.push('Preview console is missing the preview-panel container.');
} else if (previewAuthorIndex < 0 || !previewAuthorSource.includes('@大师的AI小灶')) {
errors.push('Preview console footer must show @大师的AI小灶 author info above the action buttons.');
} else {
if (previewActionsIndex >= 0 && previewAuthorIndex > previewActionsIndex) {
errors.push('Preview console author info must be placed above the footer action buttons.');
}
const requiredSocialLinks = [
['github', 'GitHub', 'assets/social-icons/github.svg'],
['douyin', '抖音', 'assets/social-icons/douyin.svg'],
['xiaohongshu', '小红书', 'assets/social-icons/redbook.svg'],
['bilibili', 'Bilibili', 'assets/social-icons/bilibili.svg'],
];
const missingSocialLinks = requiredSocialLinks
.filter(([platform, , icon]) => !new RegExp(`<a\\b(?=[^>]*data-platform="${platform}")(?=[^>]*href="[^"]+")[^>]*>[\\s\\S]*?<img\\b(?=[^>]*data-social-icon="${platform}")(?=[^>]*src="${icon}")`).test(previewAuthorSource))
.map(([, label]) => label);
if (missingSocialLinks.length) {
errors.push(`Preview console author info must include local SVG asset icon links for: ${missingSocialLinks.join(', ')}.`);
}
const socialAnchors = [...previewAuthorSource.matchAll(/<a\b([^>]*)data-platform="([^"]+)"([^>]*)>([\s\S]*?)<\/a>/g)];
for (const [, beforeAttrs, platform, afterAttrs, body] of socialAnchors) {
const text = body.replace(/<svg\b[\s\S]*?<\/svg>/g, '').replace(/<img\b[^>]*>/g, '').replace(/<[^>]+>/g, '').trim();
if (text) {
errors.push(`Preview console ${platform} social link must be icon-only, without visible text.`);
}
const attrs = `${beforeAttrs} ${afterAttrs}`;
if (!/\b(?:aria-label|title)=/.test(attrs)) {
errors.push(`Preview console ${platform} social link must keep an accessible label.`);
}
}
// 无查询参数的裸 profile URL:xsec_token 是小红书分享链路的高熵反爬参数,直接访问
// profile 不需要它;带上会被安全扫描(Snyk W008)判为泄露凭证。
const expectedXiaohongshuHref = 'https://www.xiaohongshu.com/user/profile/62e0c2bb000000001501408c';
const xiaohongshuAnchor = socialAnchors.find(([, , platform]) => platform === 'xiaohongshu');
const xiaohongshuAttrs = xiaohongshuAnchor ? `${xiaohongshuAnchor[1]} ${xiaohongshuAnchor[3]}` : '';
const xiaohongshuHref = xiaohongshuAttrs.match(/\bhref="([^"]+)"/)?.[1] || '';
if (xiaohongshuHref && xiaohongshuHref !== expectedXiaohongshuHref) {
errors.push('Preview console 小红书 href must match the exact profile URL.');
}
}
if (!/function isPointInsideDeckStage\(/.test(html)) {
errors.push('Deck right-click handling must use a stage hit test so the black border keeps the browser default context menu.');
}
if (/deck\.addEventListener\(['"]contextmenu['"],\s*\w+\s*=>\s*\w+\.preventDefault\(\)\s*\)/.test(html)) {
errors.push('Deck contextmenu handler blocks the whole deck without checking the PPT content stage.');
}
if (!/contextmenu[\s\S]{0,500}isPointInsideDeckStage|isPointInsideDeckStage[\s\S]{0,500}contextmenu/.test(html)) {
errors.push('Deck contextmenu handler must check isPointInsideDeckStage before preventing the browser menu.');
}
const overviewThumbStart = html.indexOf('function renderOverviewThumb');
const overviewThumbEnd = overviewThumbStart >= 0 ? html.indexOf('function scheduleOverviewThumbQueue', overviewThumbStart) : -1;
const overviewThumbSource = overviewThumbStart >= 0 && overviewThumbEnd > overviewThumbStart
? html.slice(overviewThumbStart, overviewThumbEnd)
: '';
const overviewDomPreviewStart = html.indexOf('function createOverviewDomPreview');
const overviewDomPreviewEnd = overviewDomPreviewStart >= 0 ? html.indexOf('function getOverviewPreviewCost', overviewDomPreviewStart) : -1;
const overviewDomPreviewSource = overviewDomPreviewStart >= 0 && overviewDomPreviewEnd > overviewDomPreviewStart
? html.slice(overviewDomPreviewStart, overviewDomPreviewEnd)
: '';
const overviewSourceSizeStart = html.indexOf('function getOverviewSourceSize');
const overviewSourceSizeEnd = overviewSourceSizeStart >= 0 ? html.indexOf('function fitOverviewThumb', overviewSourceSizeStart) : -1;
const overviewSourceSizeSource = overviewSourceSizeStart >= 0 && overviewSourceSizeEnd > overviewSourceSizeStart
? html.slice(overviewSourceSizeStart, overviewSourceSizeEnd)
: '';
if (!/renderOverviewThumbDomPreview/.test(overviewThumbSource) || !/rememberOverviewThumbFromDom/.test(html)) {
errors.push('Overview thumbnails must use the controlled DOM clone thumbnail path with stable cache reuse.');
}
if (!/function uniquifySvgCloneIds\(/.test(html)
|| !/rewriteSvgUrlRefs[\s\S]{0,120}url\\\(/.test(html)
|| !/attr\.name === 'xlink:href'/.test(html)) {
errors.push('Cloned slide DOM must rewrite SVG ids and url(#id) references so thumbnails and transitions do not shadow the live slide defs.');
}
if (!/querySelectorAll\?\.\(['"]style['"]\)/.test(html)
|| !/node\.textContent\s*=\s*next/.test(html)) {
errors.push('SVG id clone rewriting must also update url(#id) references inside style tags.');
}
if (!/function isDuplicatedRuntimeSlide\(/.test(html)
|| !/function uniquifyDuplicatedRuntimeSlideSvgIds\(/.test(html)
|| !/function ensureRuntimeSlideRendered\([\s\S]{0,700}uniquifyDuplicatedRuntimeSlideSvgIds\(slide\)/.test(html)
|| !/clone\.dataset\.duplicatedSlide\s*=\s*['"]true['"]/.test(html)) {
errors.push('Duplicated imported-theme slides must uniquify SVG defs after runtime render, not only before cloning.');
}
if (!/cloneNode\(true\)/.test(overviewDomPreviewSource)
|| !/querySelectorAll\(['"]script,style,template,noscript['"]\)/.test(overviewDomPreviewSource)
|| !/querySelectorAll\(['"]iframe,video['"]\)/.test(overviewDomPreviewSource)
|| !/style\.animation\s*=\s*['"]none['"]/.test(overviewDomPreviewSource)
|| !/style\.transition\s*=\s*['"]none['"]/.test(overviewDomPreviewSource)
|| !/contain:layout paint style/.test(overviewDomPreviewSource)) {
errors.push('Overview DOM clone thumbnails must be clipped, staticized, animation-free, and paint-contained.');
}
if (!/cloneNode\(true\)[\s\S]{0,180}uniquifySvgCloneIds\([^,]+,\s*['"]overview['"]/.test(overviewDomPreviewSource)
|| !/rememberOverviewThumbFromDom[\s\S]{0,260}uniquifySvgCloneIds\([^,]+,\s*['"]overview-cache['"]/.test(html)
|| !/restoreOverviewThumb[\s\S]{0,280}uniquifySvgCloneIds\([^,]+,\s*['"]overview-restore['"]/.test(html)) {
errors.push('Overview thumbnail clones and cached restores must uniquify SVG defs before they are inserted back into the document.');
}
if (/visualSlots|textSlots|fillText\s*\(|foreignObject|makeOverviewThumbSvg/.test(overviewDomPreviewSource)) {
errors.push('Overview thumbnail main path must not synthesize summary cards or use SVG foreignObject.');
}
if (/Math\.min\(\s*deckW\s*\|\|\s*innerWidth\s*,\s*960\s*\)/.test(overviewSourceSizeSource)
|| !/width\s*:\s*1920/.test(overviewSourceSizeSource)
|| !/height\s*:\s*1080/.test(overviewSourceSizeSource)
|| !/--deck-scale:1/.test(overviewDomPreviewSource)
|| !/overviewSourceWidth/.test(overviewDomPreviewSource)) {
errors.push('Overview DOM clone thumbnails must use the full 1920x1080 source canvas instead of a cropped viewport-sized source.');
}
const commitSlideStart = html.indexOf('function commitSlideIndex');
const commitSlideEnd = commitSlideStart >= 0 ? html.indexOf('function go', commitSlideStart) : -1;
const commitSlideSource = commitSlideStart >= 0 && commitSlideEnd > commitSlideStart
? html.slice(commitSlideStart, commitSlideEnd)
: '';
const goStart = html.indexOf('function go');
const goEnd = goStart >= 0 ? html.indexOf('function moveSlide', goStart) : -1;
const goSource = goStart >= 0 && goEnd > goStart
? html.slice(goStart, goEnd)
: '';
if (!/function prepareSlideForTransition\(/.test(html) || !/function preloadAdjacentSlides\(/.test(html)) {
errors.push('Page transitions must prepare/preload target slides before animating so first-time pages do not enter as blank frames.');
}
const transitionCallIndex = goSource.indexOf('window.__playPageTransition');
const prepareCallIndex = goSource.indexOf('prepareSlideForTransition(nextSlide');
if (transitionCallIndex >= 0 && (prepareCallIndex < 0 || prepareCallIndex > transitionCallIndex)) {
errors.push('go() must call prepareSlideForTransition(nextSlide) before starting __playPageTransition.');
}
const activeRenderIndex = commitSlideSource.indexOf('ensureRuntimeSlideRendered(el)');
const adjacentPreloadIndex = commitSlideSource.indexOf('preloadAdjacentSlides(idx');
if (adjacentPreloadIndex < 0 || (activeRenderIndex >= 0 && adjacentPreloadIndex < activeRenderIndex)) {
errors.push('commitSlideIndex() must preload adjacent slides after the active slide is rendered.');
}
if (!/theme05_page048/.test(goSource)) {
errors.push('theme05 page 48 must skip global page transition on entry to avoid its abnormal full-page scale animation.');
}
if (/theme06_page048/.test(goSource)) {
errors.push('Page transition skip still targets theme06_page048; JAD-94 scope is theme05_page048.');
}
// JAD-94 invariant: theme05 PulseMeter disables its own internal motion (not just
// the global page transition). The check reads the component source in the dev repo;
// in an installed skill (JAD-203) the readable source is stripped and the invariant
// is baked into the prebuilt theme05 runtime bundle, so fall back to that. Only if
// neither source nor a prebuilt bundle exists do we skip (never scan the deck HTML,
// which would false-fail every installed-rendered deck).
const pulseMeterFile = 'src/components/themes/theme05/source/components/esm/PulseMeter.jsx';
const pulseMeterPrebuilt = [
'dist/theme-runtime/theme05.module.mjs',
'project/dist/theme-runtime/theme05.module.mjs',
].find(p => existsSync(p));
let pulseMeterSource = null;
if (existsSync(pulseMeterFile)) pulseMeterSource = readFileSync(pulseMeterFile, 'utf8');
else if (pulseMeterPrebuilt) pulseMeterSource = readFileSync(pulseMeterPrebuilt, 'utf8');
if (pulseMeterSource !== null) {
// Tolerate minified CSS (optional whitespace around ':' and combined selectors).
const noMotion = /pulse-meter--no-motion/.test(pulseMeterSource);
const noTransition = /pulse-meter--no-motion[\s\S]{0,500}transition\s*:\s*none\s*!important/.test(pulseMeterSource);
const noAnimation = /pulse-meter--no-motion[\s\S]{0,500}animation\s*:\s*none\s*!important/.test(pulseMeterSource);
if (!noMotion || !noTransition || !noAnimation) {
errors.push('theme05 page 48 must disable its internal component motion, not only the global page transition.');
}
}
const transitionRuntimeStart = html.indexOf('window.__playPageTransition = function');
const transitionRuntimeEnd = transitionRuntimeStart >= 0 ? html.indexOf('</script>', transitionRuntimeStart) : -1;
const transitionRuntimeSource = transitionRuntimeStart >= 0 && transitionRuntimeEnd > transitionRuntimeStart
? html.slice(transitionRuntimeStart, transitionRuntimeEnd)
: '';
if (!/function prepareTransitionClone\(/.test(html) || !/data-transition-role/.test(html) || !/animation-play-state\s*:\s*paused/i.test(html)) {
errors.push('Page transition target clone must be prepared in the slide entrance initial state instead of the completed state.');
}
if (/next\.classList\.add\(['"]active['"]\)[\s\S]{0,260}next\.removeAttribute\(['"]data-deck-active['"]\)/.test(transitionRuntimeSource)) {
errors.push('Page transition target clone removes data-deck-active directly, which shows entrance-animation completed state and can cause B→A→B.');
}
if (!/prepareTransitionClone\(\s*nextSlide\s*,\s*['"]next['"]/.test(transitionRuntimeSource)) {
errors.push('__playPageTransition must build the target clone through prepareTransitionClone(nextSlide, "next").');
}
if (!/prepareTransitionClone[\s\S]{0,220}uniquifySvgCloneIds\(\s*clone\s*,\s*`transition-\$\{role\}`\s*\)/.test(html)) {
errors.push('Page transition clones must uniquify SVG defs so cloned slides cannot shadow the live slide visual effects.');
}
if (!/function startTransitionSlideEnter\(/.test(html) || !/__transitionEnteredSlide/.test(html)) {
errors.push('Page transition lifecycle must start the real target slide entrance animation during the transition and remember it for commit.');
}
if (!/data-enter-motion/.test(html) || !/page-transition-stage\[data-enter-motion=["']running["']\]/.test(html)) {
errors.push('Page transition target clone must release its paused entrance animation at the scheduled transition midpoint.');
}
if (!/\.add\(\s*startTargetEnter\s*,\s*0\.[23]/.test(transitionRuntimeSource)) {
errors.push('liquidMorph must start target slide entrance motion around the transition midpoint, not only after commit.');
}
if (!/transitionEntered[\s\S]{0,500}__playSlide/.test(commitSlideSource) || !/!transitionEntered/.test(commitSlideSource)) {
errors.push('commitSlideIndex() must not replay target slide entrance animation after it already started during page transition.');
}
const overviewBuildStart = html.indexOf('function buildOverview');
const overviewBuildEnd = overviewBuildStart >= 0 ? html.indexOf('function refreshRailCatalog', overviewBuildStart) : -1;
const overviewBuildSource = overviewBuildStart >= 0 && overviewBuildEnd > overviewBuildStart
? html.slice(overviewBuildStart, overviewBuildEnd)
: '';
const overviewDropStart = html.indexOf("grid.addEventListener('drop'");
const overviewDropEnd = overviewDropStart >= 0 ? html.indexOf("});", overviewDropStart) : -1;
const overviewDropSource = overviewDropStart >= 0 && overviewDropEnd > overviewDropStart
? html.slice(overviewDropStart, overviewDropEnd)
: '';
const overviewDropSlotStart = html.indexOf('function getOverviewDropSlot');
const overviewDropSlotEnd = overviewDropSlotStart >= 0 ? html.indexOf('function showOverviewDropMarker', overviewDropSlotStart) : -1;
const overviewDropSlotSource = overviewDropSlotStart >= 0 && overviewDropSlotEnd > overviewDropSlotStart
? html.slice(overviewDropSlotStart, overviewDropSlotEnd)
: '';
const overviewScheduleStart = html.indexOf('function scheduleOverviewThumbQueue');
const overviewScheduleEnd = overviewScheduleStart >= 0 ? html.indexOf('function queueOverviewThumb', overviewScheduleStart) : -1;
const overviewScheduleSource = overviewScheduleStart >= 0 && overviewScheduleEnd > overviewScheduleStart
? html.slice(overviewScheduleStart, overviewScheduleEnd)
: '';
const overviewFallbackStart = html.indexOf('function renderOverviewThumbFallback');
const overviewFallbackEnd = overviewFallbackStart >= 0 ? html.indexOf('async function renderOverviewThumb', overviewFallbackStart) : -1;
const overviewFallbackSource = overviewFallbackStart >= 0 && overviewFallbackEnd > overviewFallbackStart
? html.slice(overviewFallbackStart, overviewFallbackEnd)
: '';
const overviewCacheKeyStart = html.indexOf('function getOverviewThumbCacheKey');
const overviewCacheKeyEnd = overviewCacheKeyStart >= 0 ? html.indexOf('function markOverviewThumbDirty', overviewCacheKeyStart) : -1;
const overviewCacheKeySource = overviewCacheKeyStart >= 0 && overviewCacheKeyEnd > overviewCacheKeyStart
? html.slice(overviewCacheKeyStart, overviewCacheKeyEnd)
: '';
const overviewDragOverStart = html.indexOf("grid.addEventListener('dragover'");
const overviewDragOverEnd = overviewDragOverStart >= 0 ? html.indexOf("});", overviewDragOverStart) : -1;
const overviewDragOverSource = overviewDragOverStart >= 0 && overviewDragOverEnd > overviewDragOverStart
? html.slice(overviewDragOverStart, overviewDragOverEnd)
: '';
if (!/OVERVIEW_CARD_WIDTH/.test(html) || !/className\s*=\s*['"]rail-grid['"]/.test(overviewBuildSource) || !/grid-template-columns:1fr/.test(overviewBuildSource)) {
errors.push('Slide rail must use fixed-size vertical thumbnail cards instead of the old full-screen overview grid.');
}
if (!/data-rail-card/.test(html) && !/dataset\.railCard/.test(html)) {
errors.push('Slide rail cards must be represented as first-class catalog items.');
}
if (!/data-overview-frame/.test(html) || !/data-overview-label/.test(html) || !/data-rail-frame/.test(html)) {
errors.push('Slide rail cards must keep the selected border outside the thumbnail and move page numbers below the image.');
}
if (/position:absolute;left:0;bottom:0/.test(overviewBuildSource)) {
errors.push('Overview page number label is still overlaid on the thumbnail image.');
}
if (/ov\.appendChild\(createOverviewProgress/.test(overviewBuildSource)) {
errors.push('Slide rail must not show the old sticky overview progress bar.');
}
if (/buildOverview\(/.test(overviewDropSource) || !/applyOverviewReorderLocally/.test(html)) {
errors.push('Overview drag/drop reorder must update the overview DOM locally instead of rebuilding the whole overview.');
}
if (/best\.before\s*\?\s*best\.rect\.left\s*:\s*best\.rect\.right/.test(overviewDropSlotSource)
|| !/kind:\s*['"]horizontal['"]/.test(overviewDropSlotSource)
|| !/previous\.bottom\s*\+\s*next\.top/.test(overviewDropSlotSource)) {
errors.push('Slide rail drop marker must sit horizontally between vertical cards.');
}
if (!/overviewBuiltSignature/.test(html) || !/refreshOverviewCards/.test(html)) {
errors.push('Overview should reuse its existing DOM on reopen and refresh lightweight state instead of rebuilding every time.');
}
if (/queueAllOverviewThumbs\(\)/.test(overviewBuildSource) || /queueAllOverviewThumbs\(\)/.test(html)) {
errors.push('Overview must not enqueue all thumbnails on open; only visible and nearby cards should be prioritized.');
}
if (!/overviewThumbRunId/.test(html) || !/cancelOverviewThumbQueue\(/.test(html)) {
errors.push('Overview thumbnail generation must have a cancellation token so stale background work can be abandoned.');
}
if (!/time-sliced/.test(overviewScheduleSource) || /timeRemaining\s*:\s*\(\)\s*=>\s*16/.test(overviewScheduleSource) || /requestIdleCallback/.test(overviewScheduleSource) || /Promise\.allSettled\(tasks\)/.test(html) || /count\s*<\s*2/.test(html)) {
errors.push('Overview thumbnail queue must use an honest time-sliced deferred queue, not fake idle deadlines or concurrent browser captures.');
}
if (!/queueNearbyOverviewThumbs\(/.test(html) || !/OVERVIEW_THUMB_NEAR_MARGIN/.test(html)) {
errors.push('Overview should queue visible thumbnails and a small nearby buffer instead of the full deck.');
}
if (!/pauseOverviewThumbs\(\)[\s\S]{0,300}overviewDragFrom/.test(overviewBuildSource) || !/pauseOverviewThumbs\(\)[\s\S]{0,260}go\(targetIndex/.test(overviewBuildSource)) {
errors.push('Slide rail drag and page click interactions must pause thumbnail generation before user interaction work.');
}
if (!/deckMode/.test(html) || !/body\.dataset\.mode/.test(html) || /window\.__toggleOverview\s*=|function\s+(openOverview|closeOverview|toggleOverview)\b|overview-on|var\s+overviewOn|let\s+overviewOn|const\s+overviewOn/.test(html)) {
errors.push('Deck UI must expose only edit/present modes and must not keep the legacy overview mode path.');
}
if (!/window\.__getOverviewPerfState\s*=/.test(html) || !/window\.__resetOverviewPerfMarks\s*=/.test(html)) {
errors.push('Overview performance validation needs window.__getOverviewPerfState and window.__resetOverviewPerfMarks debug APIs.');
}
if (!/overviewPerfMarks/.test(html) || !/captures/.test(html) || !/layoutReads/.test(html) || !/drops/.test(html)) {
errors.push('Overview performance marks must record captures, layout reads, and drop phases for executable validation.');
}
if (!/overviewThumbPauseUntil/.test(html) || !/function deferOverviewThumbs\(/.test(html)) {
errors.push('Overview thumbnail queue must expose an interaction deferral window through overviewThumbPauseUntil and deferOverviewThumbs().');
}
if (/requestIdleCallback[\s\S]{0,160}\{\s*timeout\s*:/.test(overviewScheduleSource)) {
errors.push('Overview thumbnail queue must not use requestIdleCallback timeout to force screenshot work during interaction windows.');
}
if (/cloneNode\(true\)/.test(overviewFallbackSource) && /overviewRendered\s*=\s*['"]true['"]/.test(overviewFallbackSource)) {
errors.push('Overview thumbnail fallback must not mark an unsanitized raw DOM clone as rendered.');
}
if (!/budgetMs/.test(overviewScheduleSource) || !/sliceStartAt/.test(overviewScheduleSource) || !/overviewThumbPauseUntil/.test(overviewScheduleSource)) {
errors.push('Overview thumbnail queue must enforce a time-sliced budget and the interaction pause window before thumbnail work.');
}
if (!/activeThemePack/.test(overviewCacheKeySource) || !/(getSlideVmId|dataset\.vmSlideId)/.test(overviewCacheKeySource) || !/OVERVIEW_THUMB_WIDTH/.test(overviewCacheKeySource) || !/OVERVIEW_THUMB_HEIGHT/.test(overviewCacheKeySource)) {
errors.push('Overview thumbnail cache key must include theme pack, stable slide id, and thumbnail size.');
}
// revision 不进 key(旧图先上屏、后台刷新),但过期判定机制必须存在。
if (!/getOverviewThumbRevision/.test(html) || !/bumpOverviewThumbRevision/.test(html)) {
errors.push('Overview thumbnail staleness must be tracked via thumb revisions (getOverviewThumbRevision/bumpOverviewThumbRevision).');
}
if (/getOverviewSlideKey\(slide\)/.test(overviewCacheKeySource) || /overview-\s*\+/.test(overviewCacheKeySource)) {
errors.push('Overview thumbnail cache key must not depend on runtime overview-N ids or card creation order.');
}
if (!/overviewDragRects/.test(html) || !/recordOverviewLayoutRead/.test(html)) {
errors.push('Overview drag must cache card rects at dragstart and record layout reads for performance validation.');
}
if (/getOverviewDropSlot\(e,\s*grid\)/.test(overviewDragOverSource) && /getBoundingClientRect/.test(overviewDropSlotSource)) {
errors.push('Overview dragover must use cached card rects instead of reading every card layout on each event.');
}
if (!/requestAnimationFrame/.test(overviewDragOverSource) || !/overviewDragOverQueued/.test(html)) {
errors.push('Overview dragover must be throttled with requestAnimationFrame.');
}
if (!/scheduleOverviewDeckCommit/.test(html)) {
errors.push('Overview drop must update the overview DOM first and schedule the real deck order commit later.');
}
if (/moveCatalogSlide\(/.test(overviewDropSource) && overviewDropSource.indexOf('moveCatalogSlide(') < overviewDropSource.indexOf('applyOverviewReorderLocally')) {
errors.push('Overview drop currently commits real deck order before local overview DOM update.');
}
slides.forEach((slide) => {
const layout = slide.tag.match(/\bdata-layout="([^"]+)"/)?.[1];
if (!layout) {
errors.push(`Slide ${slide.idx}: missing data-layout.`);
} else if (!allowedLayouts.has(layout)) {
errors.push(`Slide ${slide.idx}: data-layout="${layout}" is not registered in the project layout registry.`);
}
if (!allowExperimental && /\bdata-layout="P2[34]\b|Swiss Image Split|Swiss Evidence Grid|swiss-img-split|swiss-img-grid/.test(slide.html)) {
errors.push(`Slide ${slide.idx}: uses experimental P23/P24 image structure. Use S22 or S15/S16 image-grid adaptations instead.`);
}
const isMagazine = /^A\d{2}$/.test(layout);
const isStatement = isMagazine || layout === 'S03' || layout === 'S09' || layout === 'S10' || layout === 'SWISS-COVER-ASCII' || layout === 'SWISS-CLOSING-ASCII';
const topChunk = slide.html.slice(0, 1800);
const isSwissLayout = isMagazine || /^S\d{2}$/.test(layout) || /^SWISS-/.test(layout);
const isImportedThemeLayout = /^THEME\d{2}-\d{3}$/.test(layout || '');
if (isSwissLayout && !isStatement && /text-align\s*:\s*center/i.test(topChunk)) {
errors.push(`Slide ${slide.idx}: top title area contains text-align:center. Swiss body titles should stay left aligned.`);
}
if (isSwissLayout && !isStatement && /align-self\s*:\s*center/i.test(topChunk) && /<h[12]\b/i.test(topChunk)) {
errors.push(`Slide ${slide.idx}: top heading appears vertically/centrally aligned. Use the original left-top title skeleton.`);
}
if (isSwissLayout && !isStatement && /grid-template-columns\s*:\s*[0-9.]+fr\s+[0-9.]+fr/i.test(topChunk) && /<h[12]\b/i.test(topChunk)) {
warnings.push(`Slide ${slide.idx}: heading inside a custom fr/fr grid. Confirm this is copied from the original Sxx skeleton, not a centered title hack.`);
}
if (!isImportedThemeLayout && /<svg\b[\s\S]*?<text\b/i.test(slide.html)) {
errors.push(`Slide ${slide.idx}: SVG contains visible <text>. Put labels in HTML grid/captions, keep SVG for geometry only.`);
}
});
if (warnings.length) {
console.warn('Warnings:');
for (const warning of warnings) console.warn(`- ${warning}`);
}
if (errors.length) {
console.error('Swiss deck validation failed:');
for (const error of errors) console.error(`- ${error}`);
process.exit(1);
}
console.log(`Swiss deck validation passed: ${slides.length} slide(s).`);
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| 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: 198k | Updated | Claude CodeCodex | Verified | Install |
| 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: 198k | Updated | Claude CodeCodex | Verified | Install |
| 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: 198k | Updated | Claude CodeCodex | Verified | Install |
| 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: 198k | Updated | Claude CodeCodex | Verified | Install |