@neatico/visual-core 0.14.3 → 0.14.26

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.
@@ -4,31 +4,106 @@ exports.DESIGN_SAMPLE_LOCALES = void 0;
4
4
  exports.validateDesignBlueprint = validateDesignBlueprint;
5
5
  exports.blueprintFitsContent = blueprintFitsContent;
6
6
  const content_js_1 = require("./content.js");
7
- exports.DESIGN_SAMPLE_LOCALES = ['en-US', 'zh-CH', 'ja-JP', 'de-DE', 'fr-FR', 'es-ES', 'pt-PT'];
7
+ exports.DESIGN_SAMPLE_LOCALES = [
8
+ "en-US",
9
+ "zh-CH",
10
+ "ja-JP",
11
+ "de-DE",
12
+ "fr-FR",
13
+ "es-ES",
14
+ "pt-PT",
15
+ ];
8
16
  function validateDesignBlueprint(raw) {
9
17
  const v = raw;
10
- if (!v || v.version !== 2 || typeof v.id !== 'string' || !/^[a-z][a-z0-9-]{0,79}$/.test(v.id))
11
- throw new Error('DESIGN_BLUEPRINT_ID');
12
- const kinds = ['paragraph', 'steps', 'features', 'comparison', 'code', 'parameters', 'quote', 'chart', 'image'];
13
- if (!Array.isArray(v.kinds) || !v.kinds.length || v.kinds.length > 9 || v.kinds.some(k => !kinds.includes(k)))
14
- throw new Error('DESIGN_BLUEPRINT_KINDS');
15
- if (!v.labels || typeof v.labels !== 'object' || Array.isArray(v.labels) || typeof v.labels.en !== 'string' || !v.labels.en.trim() || Object.entries(v.labels).some(([key, value]) => !/^[a-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/.test(key) || typeof value !== 'string' || !value.trim() || value.length > 120))
16
- throw new Error('DESIGN_BLUEPRINT_LABELS');
17
- if (!Array.isArray(v.ratios) || !v.ratios.length || v.ratios.length > 8 || v.ratios.some(n => !Number.isFinite(n) || n < .25 || n > 4))
18
- throw new Error('DESIGN_BLUEPRINT_RATIOS');
19
- const number = (n, min, max) => { if (typeof n !== 'number' || !Number.isFinite(n) || n < min || n > max)
20
- throw new Error('DESIGN_BLUEPRINT_RANGE'); return n; };
18
+ if (!v ||
19
+ v.version !== 2 ||
20
+ typeof v.id !== "string" ||
21
+ !/^[a-z][a-z0-9-]{0,79}$/.test(v.id))
22
+ throw new Error("DESIGN_BLUEPRINT_ID");
23
+ const kinds = [
24
+ "paragraph",
25
+ "steps",
26
+ "features",
27
+ "comparison",
28
+ "code",
29
+ "parameters",
30
+ "quote",
31
+ "chart",
32
+ "image",
33
+ ];
34
+ if (!Array.isArray(v.kinds) ||
35
+ !v.kinds.length ||
36
+ v.kinds.length > 9 ||
37
+ v.kinds.some((k) => !kinds.includes(k)))
38
+ throw new Error("DESIGN_BLUEPRINT_KINDS");
39
+ if (!v.labels ||
40
+ typeof v.labels !== "object" ||
41
+ Array.isArray(v.labels) ||
42
+ typeof v.labels.en !== "string" ||
43
+ !v.labels.en.trim() ||
44
+ Object.entries(v.labels).some(([key, value]) => !/^[a-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/.test(key) ||
45
+ typeof value !== "string" ||
46
+ !value.trim() ||
47
+ value.length > 120))
48
+ throw new Error("DESIGN_BLUEPRINT_LABELS");
49
+ if (!Array.isArray(v.ratios) ||
50
+ !v.ratios.length ||
51
+ v.ratios.length > 8 ||
52
+ v.ratios.some((n) => !Number.isFinite(n) || n < 0.25 || n > 4))
53
+ throw new Error("DESIGN_BLUEPRINT_RATIOS");
54
+ const number = (n, min, max) => {
55
+ if (typeof n !== "number" || !Number.isFinite(n) || n < min || n > max)
56
+ throw new Error("DESIGN_BLUEPRINT_RANGE");
57
+ return n;
58
+ };
21
59
  const c = v.capacity, l = v.layout;
22
60
  if (!c || !l)
23
- throw new Error('DESIGN_BLUEPRINT_MISSING');
24
- if (!['stack', 'split', 'editorial'].includes(l.mode) || !['none', 'panels', 'bands'].includes(l.surface) || !['none', 'rail', 'rule'].includes(l.accent))
25
- throw new Error('DESIGN_BLUEPRINT_LAYOUT');
61
+ throw new Error("DESIGN_BLUEPRINT_MISSING");
62
+ if (!["stack", "split", "editorial"].includes(l.mode) ||
63
+ !["none", "panels", "bands"].includes(l.surface) ||
64
+ !["none", "rail", "rule"].includes(l.accent))
65
+ throw new Error("DESIGN_BLUEPRINT_LAYOUT");
26
66
  const maxEntries = number(c.maxEntries, 1, 20), maxBlocks = number(c.maxBlocks, 1, 8), columns = number(l.columns, 1, 4);
27
67
  if (![maxEntries, maxBlocks, columns].every(Number.isInteger))
28
- throw new Error('DESIGN_BLUEPRINT_INTEGER');
29
- return { version: 2, id: v.id, labels: { ...v.labels }, kinds: [...new Set(v.kinds)], ratios: [...new Set(v.ratios)], capacity: { maxCharacters: number(c.maxCharacters, 40, 20000), maxEntries, maxBlocks }, layout: { mode: l.mode, margin: number(l.margin, 32, 80), gap: number(l.gap, 12, 40), titleScale: number(l.titleScale, .8, 1.15), bodyScale: number(l.bodyScale, .9, 1.15), columns, surface: l.surface, accent: l.accent } };
68
+ throw new Error("DESIGN_BLUEPRINT_INTEGER");
69
+ return {
70
+ version: 2,
71
+ id: v.id,
72
+ labels: { ...v.labels },
73
+ kinds: [...new Set(v.kinds)],
74
+ ratios: [...new Set(v.ratios)],
75
+ capacity: {
76
+ maxCharacters: number(c.maxCharacters, 40, 20000),
77
+ maxEntries,
78
+ maxBlocks,
79
+ },
80
+ layout: {
81
+ mode: l.mode,
82
+ margin: number(l.margin, 32, 80),
83
+ gap: number(l.gap, 12, 40),
84
+ titleScale: number(l.titleScale, 0.8, 1.15),
85
+ bodyScale: number(l.bodyScale, 0.9, 1.15),
86
+ columns,
87
+ surface: l.surface,
88
+ accent: l.accent,
89
+ },
90
+ };
30
91
  }
31
92
  function blueprintFitsContent(blueprint, page, ratio) {
32
- const entries = page.blocks.reduce((sum, b) => sum + ('entries' in b ? b.entries.length : 'columns' in b ? b.columns.length : 'rows' in b ? b.rows.length : 'values' in b ? b.values.length : 0), 0);
33
- return blueprint.ratios.some(r => Math.abs(r - ratio) < .001) && page.blocks.length <= blueprint.capacity.maxBlocks && page.blocks.every(b => blueprint.kinds.includes(b.kind)) && page.blocks.flatMap(content_js_1.contentBlockText).join('').length <= blueprint.capacity.maxCharacters && entries <= blueprint.capacity.maxEntries;
93
+ const entries = page.blocks.reduce((sum, b) => sum +
94
+ ("entries" in b
95
+ ? b.entries.length
96
+ : "columns" in b
97
+ ? b.columns.length
98
+ : "rows" in b
99
+ ? b.rows.length
100
+ : "values" in b
101
+ ? b.values.length
102
+ : 0), 0);
103
+ return (blueprint.ratios.some((r) => Math.abs(r - ratio) < 0.001) &&
104
+ page.blocks.length <= blueprint.capacity.maxBlocks &&
105
+ page.blocks.every((b) => blueprint.kinds.includes(b.kind)) &&
106
+ page.blocks.flatMap(content_js_1.contentBlockText).join("").length <=
107
+ blueprint.capacity.maxCharacters &&
108
+ entries <= blueprint.capacity.maxEntries);
34
109
  }