cinematic-core 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Pushkar Verma
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,154 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * ProjectSpec — the single source of truth for a cinematic-web project.
5
+ * Written to cinematic.json at the project root by `cinematic-web create` and `cinematic-web think`.
6
+ */
7
+ declare const ProjectSpecSchema: z.ZodObject<{
8
+ /** Human-readable brand name. E.g. "Nura Health" */
9
+ brand: z.ZodString;
10
+ /** One-line purpose statement. E.g. "Precision longevity medicine powered by biological data." */
11
+ purpose: z.ZodString;
12
+ /** ID of the selected design preset. Must match a folder in presets/. */
13
+ presetId: z.ZodString;
14
+ /** Three key value propositions — become Feature card copy. */
15
+ valueProps: z.ZodTuple<[z.ZodString, z.ZodString, z.ZodString], null>;
16
+ /** Primary call-to-action text. E.g. "Book a consultation" */
17
+ cta: z.ZodString;
18
+ /** Free-text special requests / custom features. */
19
+ notes: z.ZodDefault<z.ZodString>;
20
+ /** Stream B: paths to generated product documents (optional). */
21
+ prd: z.ZodOptional<z.ZodObject<{
22
+ path: z.ZodString;
23
+ }, "strip", z.ZodTypeAny, {
24
+ path: string;
25
+ }, {
26
+ path: string;
27
+ }>>;
28
+ ux: z.ZodOptional<z.ZodObject<{
29
+ path: z.ZodString;
30
+ }, "strip", z.ZodTypeAny, {
31
+ path: string;
32
+ }, {
33
+ path: string;
34
+ }>>;
35
+ mvp: z.ZodOptional<z.ZodObject<{
36
+ path: z.ZodString;
37
+ }, "strip", z.ZodTypeAny, {
38
+ path: string;
39
+ }, {
40
+ path: string;
41
+ }>>;
42
+ /** Reference website URL provided by user (content context only, not design). */
43
+ referenceUrl: z.ZodOptional<z.ZodString>;
44
+ }, "strip", z.ZodTypeAny, {
45
+ brand: string;
46
+ purpose: string;
47
+ presetId: string;
48
+ valueProps: [string, string, string];
49
+ cta: string;
50
+ notes: string;
51
+ prd?: {
52
+ path: string;
53
+ } | undefined;
54
+ ux?: {
55
+ path: string;
56
+ } | undefined;
57
+ mvp?: {
58
+ path: string;
59
+ } | undefined;
60
+ referenceUrl?: string | undefined;
61
+ }, {
62
+ brand: string;
63
+ purpose: string;
64
+ presetId: string;
65
+ valueProps: [string, string, string];
66
+ cta: string;
67
+ notes?: string | undefined;
68
+ prd?: {
69
+ path: string;
70
+ } | undefined;
71
+ ux?: {
72
+ path: string;
73
+ } | undefined;
74
+ mvp?: {
75
+ path: string;
76
+ } | undefined;
77
+ referenceUrl?: string | undefined;
78
+ }>;
79
+ type ProjectSpec = z.infer<typeof ProjectSpecSchema>;
80
+
81
+ /**
82
+ * A fully parsed preset.json — design tokens for one aesthetic direction.
83
+ */
84
+ interface Preset {
85
+ id: string;
86
+ name: string;
87
+ label: string;
88
+ template: 'base-react' | 'three-fiber';
89
+ identity: string;
90
+ palette: {
91
+ primary: string;
92
+ accent: string;
93
+ background: string;
94
+ dark: string;
95
+ primaryLabel: string;
96
+ accentLabel: string;
97
+ backgroundLabel: string;
98
+ darkLabel: string;
99
+ };
100
+ typography: {
101
+ heading: string[];
102
+ drama?: string;
103
+ body?: string;
104
+ data?: string;
105
+ headingTracking?: string;
106
+ dramaStyle?: string;
107
+ microCopy?: string;
108
+ };
109
+ googleFonts: string;
110
+ imageMood: string;
111
+ unsplashQuery: string;
112
+ unsplashPhotoId?: string;
113
+ heroLinePattern: {
114
+ part1: string;
115
+ part1Style: string;
116
+ part2: string;
117
+ part2Style: string;
118
+ };
119
+ dependencies?: Record<string, string>;
120
+ promptFile?: string;
121
+ notes?: string;
122
+ }
123
+ /**
124
+ * Load all presets from the `presets/` directory.
125
+ * Results are cached after the first call.
126
+ */
127
+ declare function loadPresetRegistry(presetsDir?: string): Map<string, Preset>;
128
+ /**
129
+ * Get a single preset by ID. Returns undefined if not found.
130
+ */
131
+ declare function getPreset(id: string, presetsDir?: string): Preset | undefined;
132
+ /**
133
+ * Get all presets as an array, sorted by id for deterministic output.
134
+ */
135
+ declare function listPresets(presetsDir?: string): Preset[];
136
+ /** Clear the in-memory cache (useful in tests). */
137
+ declare function clearPresetCache(): void;
138
+
139
+ /**
140
+ * token-replace — simple mustache-style `{{x.y}}` substitution.
141
+ *
142
+ * Resolves dotted paths against a flat or nested object.
143
+ * Unknown tokens are left as-is (no silent erasure).
144
+ *
145
+ * @example
146
+ * tokenReplace('Hello {{brand}}!', { brand: 'Nura Health' })
147
+ * // → 'Hello Nura Health!'
148
+ *
149
+ * tokenReplace('Color: {{palette.primary}}', { palette: { primary: '#2E4036' } })
150
+ * // → 'Color: #2E4036'
151
+ */
152
+ declare function tokenReplace(content: string, data: Record<string, unknown>): string;
153
+
154
+ export { type Preset, type ProjectSpec, ProjectSpecSchema, clearPresetCache, getPreset, listPresets, loadPresetRegistry, tokenReplace };
package/dist/index.js ADDED
@@ -0,0 +1,93 @@
1
+ // src/spec-schema.ts
2
+ import { z } from "zod";
3
+ var ProjectSpecSchema = z.object({
4
+ /** Human-readable brand name. E.g. "Nura Health" */
5
+ brand: z.string().min(1),
6
+ /** One-line purpose statement. E.g. "Precision longevity medicine powered by biological data." */
7
+ purpose: z.string().min(1),
8
+ /** ID of the selected design preset. Must match a folder in presets/. */
9
+ presetId: z.string().min(1),
10
+ /** Three key value propositions — become Feature card copy. */
11
+ valueProps: z.tuple([z.string(), z.string(), z.string()]),
12
+ /** Primary call-to-action text. E.g. "Book a consultation" */
13
+ cta: z.string().min(1),
14
+ /** Free-text special requests / custom features. */
15
+ notes: z.string().default(""),
16
+ /** Stream B: paths to generated product documents (optional). */
17
+ prd: z.object({ path: z.string() }).optional(),
18
+ ux: z.object({ path: z.string() }).optional(),
19
+ mvp: z.object({ path: z.string() }).optional(),
20
+ /** Reference website URL provided by user (content context only, not design). */
21
+ referenceUrl: z.string().url().optional()
22
+ });
23
+
24
+ // src/presets.ts
25
+ import { readFileSync, readdirSync, existsSync } from "fs";
26
+ import { join, resolve } from "path";
27
+ import { fileURLToPath } from "url";
28
+ var REPO_ROOT = resolve(fileURLToPath(import.meta.url), "..", "..", "..", "..");
29
+ var _registry = null;
30
+ function loadPresetRegistry(presetsDir) {
31
+ if (_registry !== null) return _registry;
32
+ const dir = presetsDir ?? join(REPO_ROOT, "presets");
33
+ _registry = /* @__PURE__ */ new Map();
34
+ if (!existsSync(dir)) {
35
+ return _registry;
36
+ }
37
+ const entries = readdirSync(dir, { withFileTypes: true });
38
+ for (const entry of entries) {
39
+ if (!entry.isDirectory()) continue;
40
+ const jsonPath = join(dir, entry.name, "preset.json");
41
+ if (!existsSync(jsonPath)) continue;
42
+ try {
43
+ const raw = readFileSync(jsonPath, "utf-8");
44
+ const preset = JSON.parse(raw);
45
+ _registry.set(preset.id, preset);
46
+ } catch {
47
+ }
48
+ }
49
+ return _registry;
50
+ }
51
+ function getPreset(id, presetsDir) {
52
+ return loadPresetRegistry(presetsDir).get(id);
53
+ }
54
+ function listPresets(presetsDir) {
55
+ return [...loadPresetRegistry(presetsDir).values()].sort(
56
+ (a, b) => a.id.localeCompare(b.id)
57
+ );
58
+ }
59
+ function clearPresetCache() {
60
+ _registry = null;
61
+ }
62
+
63
+ // src/token-replace.ts
64
+ function tokenReplace(content, data) {
65
+ return content.replace(/\{\{([\w.\-]+)\}\}/g, (match, path) => {
66
+ const value = resolvePath(data, path);
67
+ if (value === void 0 || value === null) return match;
68
+ return String(value);
69
+ });
70
+ }
71
+ function resolvePath(obj, path) {
72
+ if (Object.prototype.hasOwnProperty.call(obj, path)) {
73
+ return obj[path];
74
+ }
75
+ const parts = path.split(".");
76
+ let current = obj;
77
+ for (const part of parts) {
78
+ if (current === null || current === void 0 || typeof current !== "object") {
79
+ return void 0;
80
+ }
81
+ current = current[part];
82
+ }
83
+ return current;
84
+ }
85
+ export {
86
+ ProjectSpecSchema,
87
+ clearPresetCache,
88
+ getPreset,
89
+ listPresets,
90
+ loadPresetRegistry,
91
+ tokenReplace
92
+ };
93
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/spec-schema.ts","../src/presets.ts","../src/token-replace.ts"],"sourcesContent":["import { z } from 'zod'\n\n/**\n * ProjectSpec — the single source of truth for a cinematic-web project.\n * Written to cinematic.json at the project root by `cinematic-web create` and `cinematic-web think`.\n */\nexport const ProjectSpecSchema = z.object({\n /** Human-readable brand name. E.g. \"Nura Health\" */\n brand: z.string().min(1),\n\n /** One-line purpose statement. E.g. \"Precision longevity medicine powered by biological data.\" */\n purpose: z.string().min(1),\n\n /** ID of the selected design preset. Must match a folder in presets/. */\n presetId: z.string().min(1),\n\n /** Three key value propositions — become Feature card copy. */\n valueProps: z.tuple([z.string(), z.string(), z.string()]),\n\n /** Primary call-to-action text. E.g. \"Book a consultation\" */\n cta: z.string().min(1),\n\n /** Free-text special requests / custom features. */\n notes: z.string().default(''),\n\n /** Stream B: paths to generated product documents (optional). */\n prd: z.object({ path: z.string() }).optional(),\n ux: z.object({ path: z.string() }).optional(),\n mvp: z.object({ path: z.string() }).optional(),\n\n /** Reference website URL provided by user (content context only, not design). */\n referenceUrl: z.string().url().optional(),\n})\n\nexport type ProjectSpec = z.infer<typeof ProjectSpecSchema>\n","import { readFileSync, readdirSync, existsSync } from 'node:fs'\nimport { join, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\n// Resolve the monorepo root from the bundled dist file.\n// packages/core/dist/index.js → 4 levels up → repo root\nconst REPO_ROOT = resolve(fileURLToPath(import.meta.url), '..', '..', '..', '..')\n\n/**\n * A fully parsed preset.json — design tokens for one aesthetic direction.\n */\nexport interface Preset {\n id: string\n name: string\n label: string\n template: 'base-react' | 'three-fiber'\n identity: string\n palette: {\n primary: string\n accent: string\n background: string\n dark: string\n primaryLabel: string\n accentLabel: string\n backgroundLabel: string\n darkLabel: string\n }\n typography: {\n heading: string[]\n drama?: string\n body?: string\n data?: string\n headingTracking?: string\n dramaStyle?: string\n microCopy?: string\n }\n googleFonts: string\n imageMood: string\n unsplashQuery: string\n unsplashPhotoId?: string\n heroLinePattern: {\n part1: string\n part1Style: string\n part2: string\n part2Style: string\n }\n dependencies?: Record<string, string>\n promptFile?: string\n notes?: string\n}\n\nlet _registry: Map<string, Preset> | null = null\n\n/**\n * Load all presets from the `presets/` directory.\n * Results are cached after the first call.\n */\nexport function loadPresetRegistry(presetsDir?: string): Map<string, Preset> {\n if (_registry !== null) return _registry\n\n const dir = presetsDir ?? join(REPO_ROOT, 'presets')\n _registry = new Map()\n\n if (!existsSync(dir)) {\n return _registry\n }\n\n const entries = readdirSync(dir, { withFileTypes: true })\n for (const entry of entries) {\n if (!entry.isDirectory()) continue\n const jsonPath = join(dir, entry.name, 'preset.json')\n if (!existsSync(jsonPath)) continue\n\n try {\n const raw = readFileSync(jsonPath, 'utf-8')\n const preset = JSON.parse(raw) as Preset\n _registry.set(preset.id, preset)\n } catch {\n // Skip malformed preset.json silently — CLI will warn separately\n }\n }\n\n return _registry\n}\n\n/**\n * Get a single preset by ID. Returns undefined if not found.\n */\nexport function getPreset(id: string, presetsDir?: string): Preset | undefined {\n return loadPresetRegistry(presetsDir).get(id)\n}\n\n/**\n * Get all presets as an array, sorted by id for deterministic output.\n */\nexport function listPresets(presetsDir?: string): Preset[] {\n return [...loadPresetRegistry(presetsDir).values()].sort((a, b) =>\n a.id.localeCompare(b.id)\n )\n}\n\n/** Clear the in-memory cache (useful in tests). */\nexport function clearPresetCache(): void {\n _registry = null\n}\n","/**\n * token-replace — simple mustache-style `{{x.y}}` substitution.\n *\n * Resolves dotted paths against a flat or nested object.\n * Unknown tokens are left as-is (no silent erasure).\n *\n * @example\n * tokenReplace('Hello {{brand}}!', { brand: 'Nura Health' })\n * // → 'Hello Nura Health!'\n *\n * tokenReplace('Color: {{palette.primary}}', { palette: { primary: '#2E4036' } })\n * // → 'Color: #2E4036'\n */\nexport function tokenReplace(content: string, data: Record<string, unknown>): string {\n return content.replace(/\\{\\{([\\w.\\-]+)\\}\\}/g, (match, path: string) => {\n const value = resolvePath(data, path)\n if (value === undefined || value === null) return match\n return String(value)\n })\n}\n\nfunction resolvePath(obj: Record<string, unknown>, path: string): unknown {\n // Try the flat dotted key first (e.g. { 'palette.primary': '#2E4036' })\n if (Object.prototype.hasOwnProperty.call(obj, path)) {\n return obj[path]\n }\n // Fall back to nested traversal (e.g. { palette: { primary: '#2E4036' } })\n const parts = path.split('.')\n let current: unknown = obj\n for (const part of parts) {\n if (current === null || current === undefined || typeof current !== 'object') {\n return undefined\n }\n current = (current as Record<string, unknown>)[part]\n }\n return current\n}\n"],"mappings":";AAAA,SAAS,SAAS;AAMX,IAAM,oBAAoB,EAAE,OAAO;AAAA;AAAA,EAExC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA;AAAA,EAGvB,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA;AAAA,EAGzB,UAA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U,IAAI,OAAO,IAAI,MAAM;AAAA,IACjC,QAAQ;AAAA,IAER;AAAA,EACF;AAEA,SAAO;AACT;AAKO,SAAS,UAAU,IAAY,YAAyC;AAC7E,SAAO,mBAAmB,UAAU,EAAE,IAAI,EAAE;AAC9C;AAKO,SAAS,YAAY,YAA+B;AACzD,SAAO,CAAC,GAAG,mBAAmB,UAAU,EAAE,OAAO,CAAC,EAAE;AAAA,IAAK,CAAC,GAAG,MAC3D,EAAE,GAAG,cAAc,EAAE,EAAE;AAAA,EACzB;AACF;AAGO,SAAS,mBAAyB;AACvC,cAAY;AACd;;;AC3FO,SAAS,aAAa,SAAiB,MAAuC;AACnF,SAAO,QAAQ,QAAQ,uBAAuB,CAAC,OAAO,SAAiB;AACrE,UAAM,QAAQ,YAAY,MAAM,IAAI;AACpC,QAAI,UAAU,UAAa,UAAU,KAAM,QAAO;AAClD,WAAO,OAAO,KAAK;AAAA,EACrB,CAAC;AACH;AAEA,SAAS,YAAY,KAA8B,MAAuB;AAExE,MAAI,OAAO,UAAU,eAAe,KAAK,KAAK,IAAI,GAAG;AACnD,WAAO,IAAI,IAAI;AAAA,EACjB;AAEA,QAAM,QAAQ,KAAK,MAAM,GAAG;AAC5B,MAAI,UAAmB;AACvB,aAAW,QAAQ,OAAO;AACxB,QAAI,YAAY,QAAQ,YAAY,UAAa,OAAO,YAAY,UAAU;AAC5E,aAAO;AAAA,IACT;AACA,cAAW,QAAoC,IAAI;AAAA,EACrD;AACA,SAAO;AACT;","names":[]}
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "cinematic-core",
3
+ "version": "0.1.0",
4
+ "description": "Shared core for cinematic-web: preset registry, project spec schema, token replacement",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "dependencies": {
19
+ "zod": "^3.23.0"
20
+ },
21
+ "devDependencies": {
22
+ "tsup": "^8.0.0",
23
+ "typescript": "^5.4.0"
24
+ },
25
+ "scripts": {
26
+ "build": "tsup",
27
+ "dev": "tsup --watch",
28
+ "type-check": "tsc --noEmit"
29
+ }
30
+ }