Files
openmotion/studio/src/motion/templateGuideFacts.ts
open-design-crew[bot] 1e7e1861f5 [OPEND-5412] feat(studio): improve template details and handoff (#584)
* feat(studio): refine template details and project handoff

* feat(tracking): measure template handoff and enable approved details

* test(studio): align handoff and related preview regressions

* fix(tracking): link editable handoff intent to operation results

* fix(studio): preserve and unblock template creation recovery

* Preserve template handoff requirements in every locale

* fix(studio): keep guide return and short brand previews usable

* test(browser): make brand story selection deterministic

---------

Co-authored-by: qiqi <qiqi@qiqideMBP.lan>
2026-11-19 12:13:33 +08:00

16 lines
902 B
TypeScript

export type TemplateGuideFacts = { palette: string[]; editableDemo: boolean };
/** Read authored guide metadata, never invent a palette from a catalogue color category. */
export function templateGuideFacts(source: string): TemplateGuideFacts {
const document = new DOMParser().parseFromString(source, 'text/html');
const palette = [...new Set([...document.querySelectorAll('.palette [data-color]')]
.map(node => node.getAttribute('data-color') ?? '').filter(value => /^#[0-9a-f]{6}$/i.test(value)))].slice(0, 8);
const editableDemo = [...document.querySelectorAll('[data-demo]')].some(node => {
try {
const demo = JSON.parse(node.getAttribute('data-demo') ?? '{}');
return Array.isArray(demo.params) && demo.params.some((param: { type?: string }) => param.type === 'text' || param.type === 'color');
} catch { return false; }
});
return { palette, editableDemo };
}