返回 CodeWhale
brand.template.js
根目录 / vendor / codewhale-design / figma / brand.template.js
1 const apply = typeof APPLY_BRAND !== 'undefined' && APPLY_BRAND === true;
2 const page = figma.root.children.find(node => node.id === '267:8');
3 if (!page) throw Error('Whale page identity changed');
4 await figma.setCurrentPageAsync(page);
5 const character = await figma.getNodeByIdAsync('269:8');
6 if (!character || character.type !== 'COMPONENT' || character.parent?.id !== page.id) throw Error('Inspect existing character master');
7 const characterName = 'Codewhale/Character legacy mark';
8 if (!['Codewhale/Mark', characterName].includes(character.name)) throw Error('Character master was edited; reconcile before renaming');
9 const matches = page.children.filter(node => node.name === 'Codewhale/Logo monochrome');
10 if (matches.length > 1 || (matches.length && matches[0].type !== 'COMPONENT_SET')) throw Error('Ambiguous existing logo family');
11 const prior = matches[0];
12 const unfinished = page.children.filter(node => node.name.startsWith('CW7930 pending monochrome'));
13 if (unfinished.length) return { blocked: true, unfinishedNodeIds: unfinished.map(node => node.id), safeToRetryWithoutCanvasRead: false, mutatedNodeIds: [], createdNodeIds: [] };
14 if (!apply) return { dryRun: true, pageId: page.id, existingCharacterId: character.id, rename: { before: character.name, after: characterName }, officialLogoId: prior?.id ?? null, sourceHash: CW_BRAND.sourceHash, proposedVariants: ['Surface=Light', 'Surface=Dark'], preservedNodeIds: ['269:9','269:18','269:45','269:52','269:59','269:63'], createdNodeIds: [], mutatedNodeIds: [] };
15 const createdNodeIds = [];
16 const mutatedNodeIds = [];
17 let logo = prior;
18 try {
19 if (!logo) {
20 const variants = [];
21 for (const [surface, svg] of [['Light', CW_BRAND.light], ['Dark', CW_BRAND.dark]]) {
22 const component = figma.createComponent();
23 createdNodeIds.push(component.id);
24 page.appendChild(component);
25 component.name = 'CW7930 pending monochrome ' + surface;
26 component.fills = [];
27 const art = figma.createNodeFromSvg(svg);
28 component.appendChild(art);
29 component.resize(art.width, art.height);
30 art.x = 0; art.y = 0;
31 component.description = 'Official monochrome C-curl from whale/source/mark.svg. Original source paths; not the blue character. Source ' + CW_BRAND.sourceHash;
32 variants.push(component);
33 createdNodeIds.push(art.id, ...art.findAll().map(node => node.id));
34 }
35 logo = figma.combineAsVariants(variants, page);
36 createdNodeIds.push(logo.id);
37 logo.name = 'CW7930 pending monochrome family';
38 variants[0].name = 'Surface=Light';
39 variants[1].name = 'Surface=Dark';
40 logo.fills = [];
41 logo.description = 'Official logo; black on light, near-white on dark. The existing blue character remains separate and retains its instances.';
42 variants[0].x = 24; variants[0].y = 24;
43 variants[1].x = variants[0].width + 48; variants[1].y = 24;
44 logo.resize(variants[0].width + variants[1].width + 72, Math.max(...variants.map(node => node.height)) + 48);
45 logo.x = Math.max(0, ...page.children.filter(node => node.id !== logo.id).map(node => node.x + node.width)) + 160;
46 logo.y = 80;
47 logo.name = 'Codewhale/Logo monochrome';
48 }
49 if (character.name !== characterName) { character.name = characterName; mutatedNodeIds.push(character.id); }
50 } catch (error) {
51 return { failed: true, error: String(error), pageId: page.id, createdNodeIds, mutatedNodeIds, safeToRetryWithoutCanvasRead: false };
52 }
53 return { dryRun: false, pageId: page.id, logoId: logo.id, characterId: character.id, createdNodeIds, mutatedNodeIds, preservedBlueArtwork: true, existingGeometryChanged: false, instancesDetached: false, needsVisualReview: true };
54
54 lines JAVASCRIPT