@project-ava-supernova/core 0.2.176 → 0.2.177
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.
- package/dist/agent/agent.d.ts +3 -0
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.js +36 -11
- package/dist/agent/agent.js.map +1 -1
- package/dist/agent/system-prompt.d.ts +3 -2
- package/dist/agent/system-prompt.d.ts.map +1 -1
- package/dist/agent/system-prompt.js +1356 -1308
- package/dist/agent/system-prompt.js.map +1 -1
- package/dist/auto/aurora-router.d.ts +1 -1
- package/dist/auto/aurora-router.d.ts.map +1 -1
- package/dist/auto/aurora-router.js +4 -1
- package/dist/auto/aurora-router.js.map +1 -1
- package/dist/auto/auto-coordinator.d.ts.map +1 -1
- package/dist/auto/auto-coordinator.js +2 -1
- package/dist/auto/auto-coordinator.js.map +1 -1
- package/dist/auto/longxiang-router.d.ts.map +1 -1
- package/dist/auto/longxiang-router.js +1 -0
- package/dist/auto/longxiang-router.js.map +1 -1
- package/dist/auto/model-router.d.ts.map +1 -1
- package/dist/auto/model-router.js +1 -0
- package/dist/auto/model-router.js.map +1 -1
- package/dist/auto/supernova-router.d.ts.map +1 -1
- package/dist/auto/supernova-router.js +3 -0
- package/dist/auto/supernova-router.js.map +1 -1
- package/dist/auto/task-classifier.d.ts.map +1 -1
- package/dist/auto/task-classifier.js +8 -1
- package/dist/auto/task-classifier.js.map +1 -1
- package/dist/auto/types.d.ts +1 -1
- package/dist/auto/types.d.ts.map +1 -1
- package/dist/brand/brand-kits.d.ts +217 -0
- package/dist/brand/brand-kits.d.ts.map +1 -0
- package/dist/brand/brand-kits.js +681 -0
- package/dist/brand/brand-kits.js.map +1 -0
- package/dist/brand/kit-py.d.ts +7 -0
- package/dist/brand/kit-py.d.ts.map +1 -0
- package/dist/brand/kit-py.js +45 -0
- package/dist/brand/kit-py.js.map +1 -0
- package/dist/config/schema.d.ts +5 -0
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js.map +1 -1
- package/dist/docs/data/tools.d.ts.map +1 -1
- package/dist/docs/data/tools.js +15 -0
- package/dist/docs/data/tools.js.map +1 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/dist/memory/config.d.ts +12 -0
- package/dist/memory/config.d.ts.map +1 -1
- package/dist/memory/config.js +12 -0
- package/dist/memory/config.js.map +1 -1
- package/dist/memory/memory-manager.d.ts +11 -0
- package/dist/memory/memory-manager.d.ts.map +1 -1
- package/dist/memory/memory-manager.js +90 -2
- package/dist/memory/memory-manager.js.map +1 -1
- package/dist/memory/project-brain.d.ts.map +1 -1
- package/dist/memory/project-brain.js +2 -1
- package/dist/memory/project-brain.js.map +1 -1
- package/dist/memory/tfidf.d.ts +10 -0
- package/dist/memory/tfidf.d.ts.map +1 -1
- package/dist/memory/tfidf.js +27 -0
- package/dist/memory/tfidf.js.map +1 -1
- package/dist/social/index.d.ts +48 -0
- package/dist/social/index.d.ts.map +1 -1
- package/dist/social/index.js +19 -0
- package/dist/social/index.js.map +1 -1
- package/dist/tools/blender/build-model.d.ts +52 -0
- package/dist/tools/blender/build-model.d.ts.map +1 -0
- package/dist/tools/blender/build-model.js +426 -0
- package/dist/tools/blender/build-model.js.map +1 -0
- package/dist/tools/blender/find-blender.d.ts +43 -0
- package/dist/tools/blender/find-blender.d.ts.map +1 -0
- package/dist/tools/blender/find-blender.js +154 -0
- package/dist/tools/blender/find-blender.js.map +1 -0
- package/dist/tools/blender/model-brief.d.ts +61 -0
- package/dist/tools/blender/model-brief.d.ts.map +1 -0
- package/dist/tools/blender/model-brief.js +117 -0
- package/dist/tools/blender/model-brief.js.map +1 -0
- package/dist/tools/blender/paths.d.ts +20 -0
- package/dist/tools/blender/paths.d.ts.map +1 -0
- package/dist/tools/blender/paths.js +37 -0
- package/dist/tools/blender/paths.js.map +1 -0
- package/dist/tools/blender/runner-py.d.ts +2 -0
- package/dist/tools/blender/runner-py.d.ts.map +1 -0
- package/dist/tools/blender/runner-py.js +442 -0
- package/dist/tools/blender/runner-py.js.map +1 -0
- package/dist/tools/brief-store.d.ts +25 -0
- package/dist/tools/brief-store.d.ts.map +1 -0
- package/dist/tools/brief-store.js +59 -0
- package/dist/tools/brief-store.js.map +1 -0
- package/dist/tools/check-posts.d.ts.map +1 -1
- package/dist/tools/check-posts.js +21 -3
- package/dist/tools/check-posts.js.map +1 -1
- package/dist/tools/design-checkin.d.ts +28 -0
- package/dist/tools/design-checkin.d.ts.map +1 -0
- package/dist/tools/design-checkin.js +74 -0
- package/dist/tools/design-checkin.js.map +1 -0
- package/dist/tools/design-docs.d.ts +37 -0
- package/dist/tools/design-docs.d.ts.map +1 -0
- package/dist/tools/design-docs.js +367 -0
- package/dist/tools/design-docs.js.map +1 -0
- package/dist/tools/design-fonts.d.ts +54 -0
- package/dist/tools/design-fonts.d.ts.map +1 -0
- package/dist/tools/design-fonts.js +312 -0
- package/dist/tools/design-fonts.js.map +1 -0
- package/dist/tools/design-studio-tools.d.ts +16 -0
- package/dist/tools/design-studio-tools.d.ts.map +1 -1
- package/dist/tools/design-studio-tools.js +288 -43
- package/dist/tools/design-studio-tools.js.map +1 -1
- package/dist/tools/generation-manager.d.ts +1 -1
- package/dist/tools/generation-manager.d.ts.map +1 -1
- package/dist/tools/gimp/build-image.d.ts +152 -0
- package/dist/tools/gimp/build-image.d.ts.map +1 -0
- package/dist/tools/gimp/build-image.js +809 -0
- package/dist/tools/gimp/build-image.js.map +1 -0
- package/dist/tools/gimp/find-gimp.d.ts +32 -0
- package/dist/tools/gimp/find-gimp.d.ts.map +1 -0
- package/dist/tools/gimp/find-gimp.js +149 -0
- package/dist/tools/gimp/find-gimp.js.map +1 -0
- package/dist/tools/gimp/runner-py.d.ts +2 -0
- package/dist/tools/gimp/runner-py.d.ts.map +1 -0
- package/dist/tools/gimp/runner-py.js +723 -0
- package/dist/tools/gimp/runner-py.js.map +1 -0
- package/dist/tools/propose-brief.d.ts.map +1 -1
- package/dist/tools/propose-brief.js +6 -1
- package/dist/tools/propose-brief.js.map +1 -1
- package/dist/tools/review-post.d.ts +25 -0
- package/dist/tools/review-post.d.ts.map +1 -0
- package/dist/tools/review-post.js +63 -0
- package/dist/tools/review-post.js.map +1 -0
- package/dist/tools/tool-registry.d.ts.map +1 -1
- package/dist/tools/tool-registry.js +39 -1
- package/dist/tools/tool-registry.js.map +1 -1
- package/dist/tools/tool-request-words.d.ts +7 -0
- package/dist/tools/tool-request-words.d.ts.map +1 -0
- package/dist/tools/tool-request-words.js +39 -0
- package/dist/tools/tool-request-words.js.map +1 -0
- package/dist/tools/write-post.d.ts.map +1 -1
- package/dist/tools/write-post.js +5 -1
- package/dist/tools/write-post.js.map +1 -1
- package/dist/tools/write-video-post.d.ts.map +1 -1
- package/dist/tools/write-video-post.js +6 -1
- package/dist/tools/write-video-post.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,681 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Brand kits — one home on this computer, read by the extension, the IDE and
|
|
3
|
+
* every tool, with or without the Design Studio open.
|
|
4
|
+
*
|
|
5
|
+
* ~/.ava/brand-kits.json the kits, and which one is active
|
|
6
|
+
* ~/.ava/brand-kits/<kit id>/ real files that belong to a kit (logos)
|
|
7
|
+
*
|
|
8
|
+
* Kits used to live in each app's localStorage, so the extension and the IDE
|
|
9
|
+
* had separate kits, and Ava could only reach them through the open canvas.
|
|
10
|
+
*
|
|
11
|
+
* Moving across never removes anything. A kit an app still holds in its
|
|
12
|
+
* localStorage is copied in the first time this store sees its id, and that
|
|
13
|
+
* copy in the app is left alone. Ids stay in `seen` after a delete, so a kit
|
|
14
|
+
* someone deleted can't return from an old copy.
|
|
15
|
+
*/
|
|
16
|
+
import { existsSync } from 'node:fs';
|
|
17
|
+
import { copyFile, mkdir, readdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
18
|
+
import { basename, dirname, extname, join, resolve, sep } from 'node:path';
|
|
19
|
+
import { randomUUID } from 'node:crypto';
|
|
20
|
+
import { AVA_HOME } from '../core/constants.js';
|
|
21
|
+
import { projectsHome } from '../projects/project-data.js';
|
|
22
|
+
import { MemoryManager } from '../memory/memory-manager.js';
|
|
23
|
+
import { creativeDir, metadataFile } from '../tools/blender/paths.js';
|
|
24
|
+
import { readImageFinals } from '../tools/gimp/build-image.js';
|
|
25
|
+
export const BRAND_KIT_KINDS = [
|
|
26
|
+
{ id: 'game', label: 'Game' }, { id: 'app', label: 'App' }, { id: 'website', label: 'Website' }, { id: 'business', label: 'Business' },
|
|
27
|
+
];
|
|
28
|
+
/** Every kit has these, whatever the project. */
|
|
29
|
+
const CORE_PIECES = [
|
|
30
|
+
{ id: 'colours', label: 'Colours and pairings', room: 'kit' },
|
|
31
|
+
{ id: 'fonts', label: 'Fonts', room: 'kit' },
|
|
32
|
+
{ id: 'image_style', label: 'Image style', room: 'kit' },
|
|
33
|
+
{ id: 'visual_rules', label: 'Visual dos and don\'ts', room: 'kit' },
|
|
34
|
+
{ id: 'voice', label: 'Written voice', room: 'kit' },
|
|
35
|
+
];
|
|
36
|
+
export const BRAND_KIT_PIECES = {
|
|
37
|
+
game: [
|
|
38
|
+
{ id: 'title_logo', label: 'Title logo', room: 'gimp', slot: 'primary' },
|
|
39
|
+
{ id: 'splash', label: 'Splash screen', room: 'gimp' },
|
|
40
|
+
{ id: 'hud_colours', label: 'HUD colours', room: 'kit' },
|
|
41
|
+
{ id: 'ui_fonts', label: 'UI fonts', room: 'kit' },
|
|
42
|
+
{ id: 'icon_style', label: 'Icon style', room: 'gimp' },
|
|
43
|
+
{ id: 'ui_frames', label: 'UI frames', room: 'gimp' },
|
|
44
|
+
{ id: 'world_references', label: 'Character and world references', room: 'kit' },
|
|
45
|
+
],
|
|
46
|
+
app: [
|
|
47
|
+
{ id: 'app_icon', label: 'App icon', room: 'gimp' },
|
|
48
|
+
{ id: 'themes', label: 'Light and dark themes', room: 'kit' },
|
|
49
|
+
{ id: 'interface_type', label: 'Interface fonts', room: 'kit' },
|
|
50
|
+
{ id: 'store_images', label: 'Store images', room: 'gimp' },
|
|
51
|
+
],
|
|
52
|
+
website: [
|
|
53
|
+
{ id: 'logo', label: 'Logo', room: 'gimp', slot: 'primary' },
|
|
54
|
+
{ id: 'favicon', label: 'Favicon', room: 'gimp' },
|
|
55
|
+
{ id: 'web_fonts', label: 'Web fonts', room: 'kit' },
|
|
56
|
+
{ id: 'hero_style', label: 'Hero image style', room: 'gimp' },
|
|
57
|
+
{ id: 'social_images', label: 'Social images', room: 'gimp' },
|
|
58
|
+
],
|
|
59
|
+
business: [
|
|
60
|
+
{ id: 'logo_versions', label: 'Logo versions', room: 'gimp' },
|
|
61
|
+
{ id: 'social_look', label: 'Social look', room: 'gimp' },
|
|
62
|
+
{ id: 'document_style', label: 'Document style', room: 'kit' },
|
|
63
|
+
],
|
|
64
|
+
};
|
|
65
|
+
/** The pieces a kit asks for: its kind's, then the ones every kit has. */
|
|
66
|
+
export const kitPieceDefs = (kind) => [...(kind ? BRAND_KIT_PIECES[kind] : []), ...CORE_PIECES];
|
|
67
|
+
export const brandKitsHome = () => process.env.AVA_BRAND_KITS_DIR || AVA_HOME;
|
|
68
|
+
export const brandKitsFile = () => join(brandKitsHome(), 'brand-kits.json');
|
|
69
|
+
const kitFolder = (id) => join(brandKitsHome(), 'brand-kits', id.replace(/[^\w-]/g, '_'));
|
|
70
|
+
const DEFAULT_PALETTE = { primary: '#a855f7', secondary: '#89b4fa', accent: '#94e2d5', neutral: '#a6adc8', surface: '#110c1a' };
|
|
71
|
+
const EMPTY = () => ({ version: 1, activeId: null, kits: [], seen: [] });
|
|
72
|
+
async function readStore() {
|
|
73
|
+
let raw;
|
|
74
|
+
try {
|
|
75
|
+
raw = await readFile(brandKitsFile(), 'utf-8');
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return EMPTY();
|
|
79
|
+
}
|
|
80
|
+
const parsed = JSON.parse(raw); // a damaged file must stop here, not be overwritten
|
|
81
|
+
return { version: 1, activeId: parsed.activeId ?? null, kits: Array.isArray(parsed.kits) ? parsed.kits : [], seen: Array.isArray(parsed.seen) ? parsed.seen : [] };
|
|
82
|
+
}
|
|
83
|
+
async function writeStore(store) {
|
|
84
|
+
const file = brandKitsFile();
|
|
85
|
+
await mkdir(dirname(file), { recursive: true });
|
|
86
|
+
const tmp = `${file}.${randomUUID()}.tmp`;
|
|
87
|
+
await writeFile(tmp, JSON.stringify(store, null, 2), 'utf-8');
|
|
88
|
+
await rename(tmp, file);
|
|
89
|
+
}
|
|
90
|
+
/** One change at a time in this process, so a tool and a click can't lose each other's edit. */
|
|
91
|
+
let queue = Promise.resolve();
|
|
92
|
+
function change(fn) {
|
|
93
|
+
const run = queue.then(async () => {
|
|
94
|
+
const store = await readStore();
|
|
95
|
+
const out = await fn(store);
|
|
96
|
+
await writeStore(store);
|
|
97
|
+
return out;
|
|
98
|
+
});
|
|
99
|
+
queue = run.catch(() => { });
|
|
100
|
+
return run;
|
|
101
|
+
}
|
|
102
|
+
// ── Logos as real files ──────────────────────────────────────────────────────
|
|
103
|
+
const EXT_FOR_TYPE = { 'image/svg+xml': '.svg', 'image/png': '.png', 'image/jpeg': '.jpg', 'image/webp': '.webp' };
|
|
104
|
+
const TYPE_FOR_EXT = { '.svg': 'image/svg+xml', '.png': 'image/png', '.jpg': 'image/jpeg', '.webp': 'image/webp' };
|
|
105
|
+
/** The picture in a data URL, or null if it's anything else. */
|
|
106
|
+
function pictureFromDataUrl(value) {
|
|
107
|
+
const m = /^data:([\w/+.-]+)(;base64)?,([\s\S]*)$/.exec(value);
|
|
108
|
+
const ext = m && EXT_FOR_TYPE[m[1]];
|
|
109
|
+
if (!m || !ext)
|
|
110
|
+
return null;
|
|
111
|
+
return { ext, bytes: m[2] ? Buffer.from(m[3], 'base64') : Buffer.from(decodeURIComponent(m[3]), 'utf-8') };
|
|
112
|
+
}
|
|
113
|
+
/** A data URL becomes a file in the kit's folder. Anything else is left as it is. */
|
|
114
|
+
async function logoToFile(kitId, slot, value) {
|
|
115
|
+
const picture = pictureFromDataUrl(value);
|
|
116
|
+
if (!picture)
|
|
117
|
+
return value;
|
|
118
|
+
const { ext, bytes } = picture;
|
|
119
|
+
const dir = join(kitFolder(kitId), 'logos');
|
|
120
|
+
await mkdir(dir, { recursive: true });
|
|
121
|
+
const name = `${slot.replace(/\W/g, '')}${ext}`;
|
|
122
|
+
for (const other of Object.values(EXT_FOR_TYPE)) {
|
|
123
|
+
if (other !== ext)
|
|
124
|
+
await rm(join(dir, `${slot.replace(/\W/g, '')}${other}`), { force: true });
|
|
125
|
+
}
|
|
126
|
+
await writeFile(join(dir, name), bytes);
|
|
127
|
+
return `logos/${name}`;
|
|
128
|
+
}
|
|
129
|
+
async function withLogoFiles(kit) {
|
|
130
|
+
if (!kit.logo)
|
|
131
|
+
return kit;
|
|
132
|
+
const logo = {};
|
|
133
|
+
for (const [slot, value] of Object.entries(kit.logo)) {
|
|
134
|
+
if (typeof value === 'string' && value)
|
|
135
|
+
logo[slot] = await logoToFile(kit.id, slot, value);
|
|
136
|
+
}
|
|
137
|
+
return { ...kit, logo };
|
|
138
|
+
}
|
|
139
|
+
/** The absolute path of a kit's logo file, for tools that work with real files. */
|
|
140
|
+
export function brandLogoPath(kit, slot) {
|
|
141
|
+
const value = kit.logo?.[slot];
|
|
142
|
+
if (!value || /^(data:|https?:)/.test(value))
|
|
143
|
+
return null;
|
|
144
|
+
const root = resolve(kitFolder(kit.id));
|
|
145
|
+
const full = resolve(root, value);
|
|
146
|
+
return full.startsWith(root + sep) && existsSync(full) ? full : null;
|
|
147
|
+
}
|
|
148
|
+
async function logoAsDataUrl(kit, slot) {
|
|
149
|
+
const value = kit.logo?.[slot];
|
|
150
|
+
const path = brandLogoPath(kit, slot);
|
|
151
|
+
if (!path)
|
|
152
|
+
return value;
|
|
153
|
+
const type = TYPE_FOR_EXT[extname(path).toLowerCase()];
|
|
154
|
+
return `data:${type};base64,${(await readFile(path)).toString('base64')}`;
|
|
155
|
+
}
|
|
156
|
+
/** Kits as the apps want them: logos ready to show. */
|
|
157
|
+
async function forApps(kits) {
|
|
158
|
+
return Promise.all(kits.map(async (kit) => {
|
|
159
|
+
const fileMap = {};
|
|
160
|
+
for (const piece of Object.values(kit.pieces ?? {})) {
|
|
161
|
+
for (const file of piece.files ?? []) {
|
|
162
|
+
const full = join(kitFolder(kit.id), file);
|
|
163
|
+
if (existsSync(full))
|
|
164
|
+
fileMap[file] = full;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (!kit.logo)
|
|
168
|
+
return { ...kit, fileMap };
|
|
169
|
+
const logo = {};
|
|
170
|
+
for (const slot of Object.keys(kit.logo)) {
|
|
171
|
+
const url = await logoAsDataUrl(kit, slot);
|
|
172
|
+
if (url)
|
|
173
|
+
logo[slot] = url;
|
|
174
|
+
}
|
|
175
|
+
return { ...kit, logo, fileMap };
|
|
176
|
+
}));
|
|
177
|
+
}
|
|
178
|
+
// ── Reading ──────────────────────────────────────────────────────────────────
|
|
179
|
+
export async function listBrandKits() {
|
|
180
|
+
const { kits, activeId } = await readStore();
|
|
181
|
+
const live = kits.filter((k) => k.status !== 'proposed');
|
|
182
|
+
return { kits, activeId: live.some((k) => k.id === activeId) ? activeId : live[0]?.id ?? null };
|
|
183
|
+
}
|
|
184
|
+
/** Their projects folder. A kit links only to projects that live there. */
|
|
185
|
+
async function projectsFolder() {
|
|
186
|
+
if (process.env.AVA_PROJECTS_DIR)
|
|
187
|
+
return process.env.AVA_PROJECTS_DIR;
|
|
188
|
+
let configured;
|
|
189
|
+
try {
|
|
190
|
+
const settings = JSON.parse(await readFile(join(AVA_HOME, 'settings.json'), 'utf-8'));
|
|
191
|
+
configured = settings?.preferences?.projectsHome;
|
|
192
|
+
}
|
|
193
|
+
catch { /* the default folder */ }
|
|
194
|
+
return projectsHome(configured);
|
|
195
|
+
}
|
|
196
|
+
/** The projects a kit can link to: the folders in their projects folder. */
|
|
197
|
+
export async function knownProjects() {
|
|
198
|
+
const root = await projectsFolder();
|
|
199
|
+
const entries = await readdir(root, { withFileTypes: true }).catch(() => []);
|
|
200
|
+
return entries.filter((e) => e.isDirectory() && !e.name.startsWith('.')).map((e) => ({ path: join(root, e.name), name: e.name }))
|
|
201
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
202
|
+
}
|
|
203
|
+
/** A project that a kit can belong to. Anything else isn't a project here, so
|
|
204
|
+
* the kit picked by hand applies, as it does with nothing open. */
|
|
205
|
+
async function inProjectsFolder(project) {
|
|
206
|
+
const key = projectKey(project);
|
|
207
|
+
return (await knownProjects()).some((p) => projectKey(p.path) === key);
|
|
208
|
+
}
|
|
209
|
+
const fontList = (k) => Object.entries(k.fonts ?? {}).filter(([, f]) => f).map(([use, f]) => `${f} (${use})`).join(', ');
|
|
210
|
+
/** The same folder arrives with different capitals and slashes, so paths are
|
|
211
|
+
* compared in one form. The kit keeps the path as it was given, for showing. */
|
|
212
|
+
export function projectKey(path) {
|
|
213
|
+
const full = resolve(path).replace(/\\/g, '/').replace(/\/+$/, '');
|
|
214
|
+
return process.platform === 'win32' ? full.toLowerCase() : full;
|
|
215
|
+
}
|
|
216
|
+
const belongsTo = (kit, key) => (kit.projects ?? []).some((p) => projectKey(p) === key);
|
|
217
|
+
/**
|
|
218
|
+
* Which kit is in use. In a project, only the kit linked to it: a project with
|
|
219
|
+
* none has no kit, rather than borrowing another brand's. With no project open,
|
|
220
|
+
* the active kit.
|
|
221
|
+
*/
|
|
222
|
+
export async function kitForProject(project) {
|
|
223
|
+
const { kits, activeId } = await listBrandKits();
|
|
224
|
+
if (project && await inProjectsFolder(project)) {
|
|
225
|
+
const key = projectKey(project);
|
|
226
|
+
const linked = kits.find((k) => belongsTo(k, key));
|
|
227
|
+
if (linked)
|
|
228
|
+
return { status: 'linked', kit: linked };
|
|
229
|
+
return { status: 'unlinked', kit: null, project, others: kits.filter((k) => k.status !== 'proposed').map((k) => k.name) };
|
|
230
|
+
}
|
|
231
|
+
const active = kits.find((k) => k.id === activeId);
|
|
232
|
+
return active ? { status: 'active', kit: active } : { status: 'none', kit: null };
|
|
233
|
+
}
|
|
234
|
+
/** What the apps show: in a linked project, its kit is the one in use. */
|
|
235
|
+
export async function brandKitsForApps(project) {
|
|
236
|
+
const { kits, activeId } = await listBrandKits();
|
|
237
|
+
const local = project && await inProjectsFolder(project) ? project : null;
|
|
238
|
+
const key = local ? projectKey(local) : null;
|
|
239
|
+
const linked = key ? kits.find((k) => belongsTo(k, key)) : undefined;
|
|
240
|
+
return { kits: await forApps(kits), activeId: linked?.id ?? activeId, project: local && key ? { key, path: local } : null, kinds: BRAND_KIT_KINDS, pieces: BRAND_KIT_PIECES, corePieces: CORE_PIECES, projects: await knownProjects() };
|
|
241
|
+
}
|
|
242
|
+
/** The kit as it goes into a Blender or GIMP script, or null if there is none. */
|
|
243
|
+
export async function kitForScripts(project) {
|
|
244
|
+
const { kit } = await kitForProject(project);
|
|
245
|
+
if (!kit)
|
|
246
|
+
return null;
|
|
247
|
+
const logos = {};
|
|
248
|
+
for (const slot of Object.keys(kit.logo ?? {})) {
|
|
249
|
+
const path = brandLogoPath(kit, slot);
|
|
250
|
+
if (path)
|
|
251
|
+
logos[slot] = path;
|
|
252
|
+
}
|
|
253
|
+
return { name: kit.name, palette: kit.palette, style: kit.styleTags ?? [], logos, fonts: kit.fonts ?? {} };
|
|
254
|
+
}
|
|
255
|
+
// ── Contrast ─────────────────────────────────────────────────────────────────
|
|
256
|
+
const HEX = /^#[0-9a-f]{6}$/i;
|
|
257
|
+
const channel = (v) => { const s = v / 255; return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4; };
|
|
258
|
+
const luminance = (hex) => {
|
|
259
|
+
const [r, g, b] = [1, 3, 5].map((i) => channel(parseInt(hex.slice(i, i + 2), 16)));
|
|
260
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
261
|
+
};
|
|
262
|
+
/** WCAG contrast between two #rrggbb colours, 1 to 21. */
|
|
263
|
+
export function contrastRatio(a, b) {
|
|
264
|
+
const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x);
|
|
265
|
+
return Math.round(((hi + 0.05) / (lo + 0.05)) * 100) / 100;
|
|
266
|
+
}
|
|
267
|
+
/** Pairings with their real contrast: 4.5 is the floor for body text, 3 for large type and marks. */
|
|
268
|
+
export function checkPairings(kit) {
|
|
269
|
+
const colour = (c) => (HEX.test(c) ? c : kit.palette[c]);
|
|
270
|
+
return (kit.pairings ?? []).map((p) => {
|
|
271
|
+
const ink = colour(p.ink);
|
|
272
|
+
const on = colour(p.on);
|
|
273
|
+
if (!ink || !on || !HEX.test(ink) || !HEX.test(on))
|
|
274
|
+
return { ...p, ratio: null, verdict: 'unknown' };
|
|
275
|
+
const ratio = contrastRatio(ink, on);
|
|
276
|
+
return { ...p, ratio, verdict: ratio >= 4.5 ? 'fine' : ratio >= 3 ? 'large only' : 'too low' };
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
/** Where a kit stands: every piece it asks for, with its state. */
|
|
280
|
+
export function kitPieceStates(kit) {
|
|
281
|
+
return kitPieceDefs(kit.kind).map((d) => ({ ...d, state: kit.pieces?.[d.id]?.state ?? 'not_made', note: kit.pieces?.[d.id]?.note, files: kit.pieces?.[d.id]?.files }));
|
|
282
|
+
}
|
|
283
|
+
/** The kit in words, for Ava's context every turn. */
|
|
284
|
+
export function brandKitSummary(found) {
|
|
285
|
+
if (found.status === 'unlinked') {
|
|
286
|
+
return `No brand kit is linked to this project, so there is no kit in use here. ` +
|
|
287
|
+
`${found.others.length ? `Their other kits (${found.others.join(', ')}) belong to other work: never use one by default. ` : ''}` +
|
|
288
|
+
`Before anything brand-bound, ask whether to link one of those or make a new one for this project; link with design_brand_kit once they say. Any brand in your memory for this project is history, not a kit: don't design from it unless they bring it up.`;
|
|
289
|
+
}
|
|
290
|
+
if (found.status === 'none')
|
|
291
|
+
return 'They have no brand kits yet. If this work needs one, offer to make it.';
|
|
292
|
+
const k = found.kit;
|
|
293
|
+
const lines = [
|
|
294
|
+
`"${k.name}"${found.status === 'linked' ? ', linked to this project' : ''}.`,
|
|
295
|
+
k.positioning ? `What it is: ${k.positioning}` : k.tagline ? `Tagline: ${k.tagline}` : '',
|
|
296
|
+
`Colours: ${Object.entries(k.palette).map(([role, hex]) => `${role} ${hex}`).join(', ')}.`,
|
|
297
|
+
k.styleTags?.length ? `Style: ${k.styleTags.join(', ')}.` : '',
|
|
298
|
+
`Logos: ${Object.keys(k.logo ?? {}).join(', ') || 'none yet'}.`,
|
|
299
|
+
fontList(k) ? `Fonts: ${fontList(k)}.` : '',
|
|
300
|
+
k.imageStyle ? `Image style: ${k.imageStyle}` : '',
|
|
301
|
+
k.visualDo?.length ? `Visually always: ${k.visualDo.join('; ')}.` : '',
|
|
302
|
+
k.visualDont?.length ? `Visually never: ${k.visualDont.join('; ')}.` : '',
|
|
303
|
+
...checkPairings(k).map((p) => `Pairing: ${p.ink} on ${p.on}${p.use ? ` for ${p.use}` : ''} — ${p.ratio ?? '?'}:1, ${p.verdict}.`),
|
|
304
|
+
k.kind ? `A ${k.kind} kit. Pieces: ${kitPieceStates(k).map((p) => `${p.label} (${p.state.replace('_', ' ')}; ${p.room === 'gimp' ? 'GIMP room' : p.room === 'blender' ? 'Blender room' : 'Brand Kits'})`).join(', ')}.` : 'This kit has no kind yet: ask them whether it is for a game, an app, a website or a business. Never guess.',
|
|
305
|
+
...kitPieceStates(k).filter((p) => p.note).map((p) => `Notes on ${p.label}: ${p.note}`),
|
|
306
|
+
...kitPieceStates(k).filter((p) => p.files?.length).map((p) => `${p.label} files: ${p.files.map((f) => join(kitFolder(k.id), f)).join(', ')}`),
|
|
307
|
+
k.voice ? `Voice: ${k.voice}` : '',
|
|
308
|
+
k.doRules?.length ? `Always: ${k.doRules.join('; ')}.` : '',
|
|
309
|
+
k.dontRules?.length ? `Never: ${k.dontRules.join('; ')}.` : '',
|
|
310
|
+
`Design from this. The kit is the record, so never copy it into memory. In Blender and GIMP scripts use KIT.colour("primary"), KIT.rgba("primary") in Blender, and KIT.logo("mark") rather than typing colours or paths.`,
|
|
311
|
+
];
|
|
312
|
+
return lines.filter(Boolean).join('\n');
|
|
313
|
+
}
|
|
314
|
+
export async function readBrandKit(id) {
|
|
315
|
+
const { kits, activeId } = await listBrandKits();
|
|
316
|
+
return kits.find((k) => k.id === (id || activeId)) ?? null;
|
|
317
|
+
}
|
|
318
|
+
// ── Changing ─────────────────────────────────────────────────────────────────
|
|
319
|
+
const newId = () => `kit-${Date.now()}-${randomUUID().slice(0, 5)}`;
|
|
320
|
+
function foldFields(kit, f) {
|
|
321
|
+
const name = typeof f.name === 'string' && f.name.trim() ? f.name.trim() : kit.name;
|
|
322
|
+
const given = Object.fromEntries(Object.entries(f).filter(([, v]) => v !== undefined));
|
|
323
|
+
return { ...kit, ...given, name, palette: { ...kit.palette, ...(f.palette ?? {}) }, updatedAt: Date.now() };
|
|
324
|
+
}
|
|
325
|
+
/** A new kit. It does not become active: making a brand shouldn't switch the one
|
|
326
|
+
* you're working in. The very first kit is active, because something has to be. */
|
|
327
|
+
export function createBrandKit(fields) {
|
|
328
|
+
return change((store) => {
|
|
329
|
+
const now = Date.now();
|
|
330
|
+
const kit = foldFields({ id: newId(), name: 'New brand', palette: DEFAULT_PALETTE, styleTags: [], createdAt: now, updatedAt: now }, fields);
|
|
331
|
+
store.kits.push(kit);
|
|
332
|
+
store.seen.push(kit.id);
|
|
333
|
+
store.activeId ??= kit.id;
|
|
334
|
+
return kit;
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
export function updateBrandKit(id, fields) {
|
|
338
|
+
return change((store) => {
|
|
339
|
+
const target = id ?? store.activeId ?? store.kits[0]?.id;
|
|
340
|
+
const i = store.kits.findIndex((k) => k.id === target);
|
|
341
|
+
if (i < 0)
|
|
342
|
+
return null;
|
|
343
|
+
store.kits[i] = foldFields(store.kits[i], fields);
|
|
344
|
+
return store.kits[i];
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
/** Move one piece on: not made, in progress, agreed. */
|
|
348
|
+
export function setBrandPiece(id, piece, state, note) {
|
|
349
|
+
return change((store) => {
|
|
350
|
+
const kit = store.kits.find((k) => k.id === id);
|
|
351
|
+
if (!kit)
|
|
352
|
+
return null;
|
|
353
|
+
kit.pieces = { ...kit.pieces, [piece]: { ...kit.pieces?.[piece], state, ...(note ? { note } : {}) } };
|
|
354
|
+
kit.updatedAt = Date.now();
|
|
355
|
+
return kit;
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
/** A finished file joins the kit: a copy in the kit's own folder, so it survives
|
|
359
|
+
* the work being deleted. The piece is agreed; with a slot, it's that logo too. */
|
|
360
|
+
export function saveFileToKit(id, piece, source, slot, byHand = false) {
|
|
361
|
+
return change(async (store) => {
|
|
362
|
+
const kit = store.kits.find((k) => k.id === id);
|
|
363
|
+
if (!kit || !existsSync(source))
|
|
364
|
+
return null;
|
|
365
|
+
const dir = join(kitFolder(id), 'pieces', piece.replace(/\W/g, '_'));
|
|
366
|
+
await mkdir(dir, { recursive: true });
|
|
367
|
+
const before = kit.pieces?.[piece];
|
|
368
|
+
// Someone choosing a logo is replacing the one there. Everything else
|
|
369
|
+
// collects, and two files can share a name without one losing the other.
|
|
370
|
+
const replaced = byHand && slot ? before?.files ?? [] : [];
|
|
371
|
+
for (const old of replaced)
|
|
372
|
+
await rm(join(kitFolder(id), old), { force: true });
|
|
373
|
+
const name = byHand ? freeName(dir, basename(source)) : basename(source);
|
|
374
|
+
await copyFile(source, join(dir, name));
|
|
375
|
+
const file = `pieces/${piece.replace(/\W/g, '_')}/${name}`;
|
|
376
|
+
const kept = (before?.files ?? []).filter((f) => f !== file && !replaced.includes(f));
|
|
377
|
+
kit.pieces = { ...kit.pieces, [piece]: { ...before, state: 'agreed', files: [...kept, file] } };
|
|
378
|
+
if (slot) {
|
|
379
|
+
const ext = extname(source).toLowerCase().replace('.jpeg', '.jpg');
|
|
380
|
+
if (TYPE_FOR_EXT[ext]) {
|
|
381
|
+
const logos = join(kitFolder(id), 'logos');
|
|
382
|
+
await mkdir(logos, { recursive: true });
|
|
383
|
+
for (const other of Object.keys(TYPE_FOR_EXT))
|
|
384
|
+
if (other !== ext)
|
|
385
|
+
await rm(join(logos, `${slot}${other}`), { force: true });
|
|
386
|
+
await copyFile(source, join(logos, `${slot}${ext}`));
|
|
387
|
+
kit.logo = { ...kit.logo, [slot]: `logos/${slot}${ext}` };
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
kit.updatedAt = Date.now();
|
|
391
|
+
return kit;
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
/** A whole kit from an app's editor, created if it is new. Logos become files. */
|
|
395
|
+
export function saveBrandKit(kit) {
|
|
396
|
+
return change(async (store) => {
|
|
397
|
+
const { fileMap: _shownOnly, ...stored } = kit;
|
|
398
|
+
const next = await withLogoFiles(stored);
|
|
399
|
+
const i = store.kits.findIndex((k) => k.id === kit.id);
|
|
400
|
+
if (i >= 0)
|
|
401
|
+
store.kits[i] = next;
|
|
402
|
+
else
|
|
403
|
+
store.kits.push(next);
|
|
404
|
+
if (!store.seen.includes(kit.id))
|
|
405
|
+
store.seen.push(kit.id);
|
|
406
|
+
store.activeId ??= kit.id;
|
|
407
|
+
return next;
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
/** Ava's proposed kit, or a new version of one. It changes nothing in use until
|
|
411
|
+
* the person agrees it. A kit already agreed can't be proposed over. */
|
|
412
|
+
export function proposeBrandKit(id, fields, reasoning, project) {
|
|
413
|
+
return change((store) => {
|
|
414
|
+
const now = Date.now();
|
|
415
|
+
const i = id ? store.kits.findIndex((k) => k.id === id) : -1;
|
|
416
|
+
if (id && i < 0)
|
|
417
|
+
return { refused: 'There is no kit with that id.' };
|
|
418
|
+
if (i >= 0 && store.kits[i].status !== 'proposed')
|
|
419
|
+
return { refused: 'That kit is agreed. Change it with action "update", after talking it through with them.' };
|
|
420
|
+
const base = i >= 0 ? store.kits[i] : { id: newId(), name: 'New brand', palette: DEFAULT_PALETTE, styleTags: [], createdAt: now, updatedAt: now };
|
|
421
|
+
const kit = { ...foldFields(base, fields), status: 'proposed', reasoning, ...(project ? { proposedFor: project } : {}) };
|
|
422
|
+
if (i >= 0)
|
|
423
|
+
store.kits[i] = kit;
|
|
424
|
+
else {
|
|
425
|
+
store.kits.push(kit);
|
|
426
|
+
store.seen.push(kit.id);
|
|
427
|
+
}
|
|
428
|
+
return kit;
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
/** Their click. The only way a proposed kit goes live: it links to its project,
|
|
432
|
+
* and whatever it already holds counts as agreed. */
|
|
433
|
+
function freeName(dir, name) {
|
|
434
|
+
const ext = extname(name);
|
|
435
|
+
const stem = basename(name, ext);
|
|
436
|
+
let free = name;
|
|
437
|
+
for (let n = 2; existsSync(join(dir, free)); n++)
|
|
438
|
+
free = `${stem}-${n}${ext}`;
|
|
439
|
+
return free;
|
|
440
|
+
}
|
|
441
|
+
/** The piece they're setting, if this kit has it and has been agreed. */
|
|
442
|
+
function pieceToSet(kit, piece) {
|
|
443
|
+
if (!kit || kit.status === 'proposed')
|
|
444
|
+
return null;
|
|
445
|
+
return kitPieceDefs(kit.kind).find((d) => d.id === piece) ?? null;
|
|
446
|
+
}
|
|
447
|
+
/** They chose a picture from their Library for a piece. */
|
|
448
|
+
export async function addPieceFromLibrary(id, piece, source) {
|
|
449
|
+
const def = pieceToSet(await readBrandKit(id), piece);
|
|
450
|
+
const ext = extname(source).toLowerCase().replace('.jpeg', '.jpg');
|
|
451
|
+
if (!def || !isLibraryFile(source) || !TYPE_FOR_EXT[ext])
|
|
452
|
+
return null;
|
|
453
|
+
return saveFileToKit(id, piece, source, def.slot, true);
|
|
454
|
+
}
|
|
455
|
+
/** They uploaded a picture from their computer for a piece. */
|
|
456
|
+
export async function addPieceUpload(id, piece, name, dataUrl) {
|
|
457
|
+
const def = pieceToSet(await readBrandKit(id), piece);
|
|
458
|
+
const picture = pictureFromDataUrl(dataUrl);
|
|
459
|
+
if (!def || !picture)
|
|
460
|
+
return null;
|
|
461
|
+
const stem = basename(name, extname(name)).replace(/[^\w -]/g, '').trim() || 'upload';
|
|
462
|
+
const holding = join(kitFolder(id), `incoming-${randomUUID().slice(0, 8)}`);
|
|
463
|
+
await mkdir(holding, { recursive: true });
|
|
464
|
+
try {
|
|
465
|
+
const file = join(holding, `${stem}${picture.ext}`);
|
|
466
|
+
await writeFile(file, picture.bytes);
|
|
467
|
+
return await saveFileToKit(id, piece, file, def.slot, true);
|
|
468
|
+
}
|
|
469
|
+
finally {
|
|
470
|
+
await rm(holding, { recursive: true, force: true });
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
/** Takes a picture off a piece, or the logo off a logo piece. With nothing left
|
|
474
|
+
* on it the piece is not made. Only the kit's copy goes: the Library keeps its own. */
|
|
475
|
+
export function removePieceFile(id, piece, file) {
|
|
476
|
+
return change(async (store) => {
|
|
477
|
+
const kit = store.kits.find((k) => k.id === id);
|
|
478
|
+
const def = pieceToSet(kit, piece);
|
|
479
|
+
if (!kit || !def)
|
|
480
|
+
return null;
|
|
481
|
+
const before = kit.pieces?.[piece];
|
|
482
|
+
const all = before?.files ?? [];
|
|
483
|
+
const going = def.slot ? all : all.filter((f) => f === file);
|
|
484
|
+
if (!def.slot && !going.length)
|
|
485
|
+
return null;
|
|
486
|
+
for (const old of going)
|
|
487
|
+
await rm(join(kitFolder(id), old), { force: true });
|
|
488
|
+
if (def.slot) {
|
|
489
|
+
const logoFile = brandLogoPath(kit, def.slot);
|
|
490
|
+
if (logoFile)
|
|
491
|
+
await rm(logoFile, { force: true });
|
|
492
|
+
if (kit.logo)
|
|
493
|
+
delete kit.logo[def.slot];
|
|
494
|
+
}
|
|
495
|
+
const files = all.filter((f) => !going.includes(f));
|
|
496
|
+
const state = files.length || before?.note ? before?.state ?? 'not_made' : 'not_made';
|
|
497
|
+
kit.pieces = { ...kit.pieces, [piece]: { ...before, state, files } };
|
|
498
|
+
kit.updatedAt = Date.now();
|
|
499
|
+
return kit;
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
export function agreeBrandKit(id) {
|
|
503
|
+
return change((store) => {
|
|
504
|
+
const kit = store.kits.find((k) => k.id === id);
|
|
505
|
+
if (!kit || kit.status !== 'proposed')
|
|
506
|
+
return null;
|
|
507
|
+
delete kit.status;
|
|
508
|
+
const filled = {
|
|
509
|
+
colours: !!kit.pairings?.length, fonts: !!(kit.fonts?.heading || kit.fonts?.body), image_style: !!kit.imageStyle,
|
|
510
|
+
visual_rules: !!(kit.visualDo?.length || kit.visualDont?.length), voice: !!kit.voice,
|
|
511
|
+
};
|
|
512
|
+
kit.pieces = { ...kit.pieces };
|
|
513
|
+
for (const [piece, done] of Object.entries(filled))
|
|
514
|
+
if (done)
|
|
515
|
+
kit.pieces[piece] = { state: 'agreed' };
|
|
516
|
+
if (kit.proposedFor) {
|
|
517
|
+
const key = projectKey(kit.proposedFor);
|
|
518
|
+
for (const other of store.kits)
|
|
519
|
+
other.projects = other.projects?.filter((p) => projectKey(p) !== key);
|
|
520
|
+
kit.projects = [...(kit.projects ?? []), kit.proposedFor];
|
|
521
|
+
delete kit.proposedFor;
|
|
522
|
+
}
|
|
523
|
+
store.activeId ??= kit.id;
|
|
524
|
+
kit.updatedAt = Date.now();
|
|
525
|
+
return kit;
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
/** Link a kit to a project. A project has one kit, so any other kit lets go of it. */
|
|
529
|
+
export async function linkBrandKit(id, project) {
|
|
530
|
+
if (!(await inProjectsFolder(project)))
|
|
531
|
+
return null;
|
|
532
|
+
return change((store) => {
|
|
533
|
+
const key = projectKey(project);
|
|
534
|
+
const target = store.kits.find((k) => k.id === id);
|
|
535
|
+
if (!target)
|
|
536
|
+
return null;
|
|
537
|
+
for (const k of store.kits) {
|
|
538
|
+
if (belongsTo(k, key)) {
|
|
539
|
+
k.projects = (k.projects ?? []).filter((p) => projectKey(p) !== key);
|
|
540
|
+
k.updatedAt = Date.now();
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
target.projects = [...(target.projects ?? []), project];
|
|
544
|
+
target.updatedAt = Date.now();
|
|
545
|
+
return target;
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
export function unlinkBrandKit(id, project) {
|
|
549
|
+
return change((store) => {
|
|
550
|
+
const key = projectKey(project);
|
|
551
|
+
const target = store.kits.find((k) => k.id === id);
|
|
552
|
+
if (!target)
|
|
553
|
+
return null;
|
|
554
|
+
target.projects = (target.projects ?? []).filter((p) => projectKey(p) !== key);
|
|
555
|
+
target.updatedAt = Date.now();
|
|
556
|
+
return target;
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
export function setActiveBrandKit(id) {
|
|
560
|
+
return change((store) => {
|
|
561
|
+
const kit = store.kits.find((k) => k.id === id) ?? null;
|
|
562
|
+
if (kit)
|
|
563
|
+
store.activeId = id;
|
|
564
|
+
return kit;
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
/** Pictures in the Library to choose from: what's marked final, or a work's main
|
|
568
|
+
* image if nothing is yet. `everything` adds its tests and comparisons. */
|
|
569
|
+
export async function kitLibraryChoices(everything = false) {
|
|
570
|
+
let items = [];
|
|
571
|
+
try {
|
|
572
|
+
const parsed = JSON.parse(await readFile(metadataFile(), 'utf-8'));
|
|
573
|
+
if (Array.isArray(parsed))
|
|
574
|
+
items = parsed;
|
|
575
|
+
}
|
|
576
|
+
catch {
|
|
577
|
+
return [];
|
|
578
|
+
}
|
|
579
|
+
const picture = /\.(png|jpe?g|webp|svg)$/i;
|
|
580
|
+
const out = [];
|
|
581
|
+
for (const it of items) {
|
|
582
|
+
const title = String(it.title || 'Untitled');
|
|
583
|
+
const id = String(it.id ?? '');
|
|
584
|
+
if (it.kind === 'gimp' && typeof it.absoluteFolder === 'string') {
|
|
585
|
+
const folder = it.absoluteFolder;
|
|
586
|
+
const finals = await readImageFinals(id.replace(/^gimp_/, ''));
|
|
587
|
+
const all = Array.isArray(it.files) ? it.files.map(String) : [];
|
|
588
|
+
const files = everything ? [...new Set([...finals, ...all])] : finals.length ? finals : all.filter((f) => !f.includes('/'));
|
|
589
|
+
for (const file of files) {
|
|
590
|
+
if (!picture.test(file) || file === 'preview.png')
|
|
591
|
+
continue;
|
|
592
|
+
out.push({ key: `${id}:${file}`, title: `${title} · ${file.split('/').pop()}`, path: join(folder, file) });
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
else if (typeof it.absolutePath === 'string' && picture.test(it.absolutePath) && existsSync(it.absolutePath)) {
|
|
596
|
+
out.push({ key: id, title, path: it.absolutePath });
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
return out;
|
|
600
|
+
}
|
|
601
|
+
/** Only files in the Library, for a path that came through the app. */
|
|
602
|
+
export function isLibraryFile(path) {
|
|
603
|
+
const root = resolve(creativeDir());
|
|
604
|
+
return resolve(path).startsWith(root + sep);
|
|
605
|
+
}
|
|
606
|
+
/** A file already on this computer becomes one of a kit's logos: a copy, so the
|
|
607
|
+
* kit keeps it even if the original is deleted from the Library. */
|
|
608
|
+
export function setBrandLogoFromFile(id, slot, source) {
|
|
609
|
+
return change(async (store) => {
|
|
610
|
+
const i = store.kits.findIndex((k) => k.id === id);
|
|
611
|
+
const ext = extname(source).toLowerCase().replace('.jpeg', '.jpg');
|
|
612
|
+
if (i < 0 || !TYPE_FOR_EXT[ext] || !existsSync(source))
|
|
613
|
+
return null;
|
|
614
|
+
const dir = join(kitFolder(id), 'logos');
|
|
615
|
+
await mkdir(dir, { recursive: true });
|
|
616
|
+
for (const other of Object.keys(TYPE_FOR_EXT)) {
|
|
617
|
+
if (other !== ext)
|
|
618
|
+
await rm(join(dir, `${slot}${other}`), { force: true });
|
|
619
|
+
}
|
|
620
|
+
await copyFile(source, join(dir, `${slot}${ext}`));
|
|
621
|
+
const piece = kitPieceDefs(store.kits[i].kind).find((d) => d.slot === slot);
|
|
622
|
+
const pieces = piece ? { ...store.kits[i].pieces, [piece.id]: { ...store.kits[i].pieces?.[piece.id], state: 'agreed' } } : store.kits[i].pieces;
|
|
623
|
+
store.kits[i] = { ...store.kits[i], logo: { ...store.kits[i].logo, [slot]: `logos/${slot}${ext}` }, pieces, updatedAt: Date.now() };
|
|
624
|
+
return store.kits[i];
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
/** Delete a kit and its files. Only after the person has asked for it. */
|
|
628
|
+
export async function deleteBrandKit(id) {
|
|
629
|
+
let gone;
|
|
630
|
+
const deleted = await change(async (store) => {
|
|
631
|
+
gone = store.kits.find((k) => k.id === id);
|
|
632
|
+
if (!gone)
|
|
633
|
+
return false;
|
|
634
|
+
store.kits = store.kits.filter((k) => k.id !== id);
|
|
635
|
+
if (store.activeId === id)
|
|
636
|
+
store.activeId = store.kits[0]?.id ?? null;
|
|
637
|
+
await rm(kitFolder(id), { recursive: true, force: true });
|
|
638
|
+
return true;
|
|
639
|
+
});
|
|
640
|
+
if (deleted && gone)
|
|
641
|
+
await forgetBrandKit(gone);
|
|
642
|
+
return deleted;
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* A deleted kit is deleted so they can start again, so what its projects remember
|
|
646
|
+
* about it is archived: still there, but never carried into the next design. The
|
|
647
|
+
* kit is gone either way, so a failure here doesn't undo the delete.
|
|
648
|
+
*/
|
|
649
|
+
async function forgetBrandKit(kit) {
|
|
650
|
+
const name = kit.name.toLowerCase();
|
|
651
|
+
const aboutKit = (content) => {
|
|
652
|
+
const text = content.toLowerCase();
|
|
653
|
+
return text.includes(kit.id.toLowerCase()) || (text.includes('brand kit') && text.includes(name));
|
|
654
|
+
};
|
|
655
|
+
for (const project of kit.projects ?? []) {
|
|
656
|
+
await MemoryManager.archiveInProject(dirname(brandKitsFile()), project, aboutKit).catch(() => 0);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Bring in what an app still holds in localStorage. A kit whose id has been seen
|
|
661
|
+
* is skipped: the store is the truth from then on. Returns how many came in.
|
|
662
|
+
*/
|
|
663
|
+
export function importBrandKits(kits, activeId) {
|
|
664
|
+
return change(async (store) => {
|
|
665
|
+
if (!Array.isArray(kits))
|
|
666
|
+
return 0;
|
|
667
|
+
let added = 0;
|
|
668
|
+
for (const raw of kits) {
|
|
669
|
+
if (!raw || typeof raw.id !== 'string' || !raw.id || store.seen.includes(raw.id))
|
|
670
|
+
continue;
|
|
671
|
+
store.kits.push(await withLogoFiles({ ...raw, styleTags: raw.styleTags ?? [], palette: { ...DEFAULT_PALETTE, ...raw.palette } }));
|
|
672
|
+
store.seen.push(raw.id);
|
|
673
|
+
added++;
|
|
674
|
+
}
|
|
675
|
+
if (!store.kits.some((k) => k.id === store.activeId)) {
|
|
676
|
+
store.activeId = store.kits.find((k) => k.id === activeId)?.id ?? store.kits[0]?.id ?? null;
|
|
677
|
+
}
|
|
678
|
+
return added;
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
//# sourceMappingURL=brand-kits.js.map
|