@guilhermebkel/scenec 0.2.0 → 0.2.1

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.
Files changed (165) hide show
  1. package/README.md +22 -12
  2. package/dist/Adapters/FontAdapter.js +5 -1
  3. package/dist/Commands/BestCommand.d.ts +11 -0
  4. package/dist/Commands/BestCommand.js +73 -0
  5. package/dist/Commands/RenderCommand.d.ts +2 -0
  6. package/dist/Commands/RenderCommand.js +7 -0
  7. package/dist/Modules/BestModule.d.ts +41 -0
  8. package/dist/Modules/BestModule.js +159 -0
  9. package/dist/Modules/CompilationModule.d.ts +5 -0
  10. package/dist/Modules/CompilationModule.js +92 -19
  11. package/dist/Modules/CritiqueModule.d.ts +3 -0
  12. package/dist/Modules/CritiqueModule.js +60 -5
  13. package/dist/Protocols/AssetProtocol.d.ts +6 -1
  14. package/dist/Protocols/AssetProtocol.js +17 -1
  15. package/dist/Protocols/CommandProtocol.d.ts +2 -0
  16. package/dist/Protocols/CompilationProtocol.d.ts +27 -1
  17. package/dist/Protocols/CritiqueProtocol.d.ts +17 -1
  18. package/dist/Protocols/CritiqueProtocol.js +11 -1
  19. package/dist/Protocols/KitProtocol.d.ts +8 -2
  20. package/dist/Protocols/KitProtocol.js +8 -2
  21. package/dist/Protocols/PersonProtocol.d.ts +4 -0
  22. package/dist/Protocols/PersonProtocol.js +2 -0
  23. package/dist/Protocols/SceneProtocol.d.ts +204 -5
  24. package/dist/Protocols/SceneProtocol.js +60 -7
  25. package/dist/Resources/Assets/BaseAsset.d.ts +1 -0
  26. package/dist/Resources/Assets/BaseAsset.js +1 -0
  27. package/dist/Resources/Assets/BigPlantAsset.js +8 -1
  28. package/dist/Resources/Assets/BlackboardAsset.d.ts +11 -0
  29. package/dist/Resources/Assets/BlackboardAsset.js +20 -0
  30. package/dist/Resources/Assets/BushAsset.js +1 -1
  31. package/dist/Resources/Assets/ChairAsset.d.ts +5 -0
  32. package/dist/Resources/Assets/ChairAsset.js +23 -0
  33. package/dist/Resources/Assets/ChatBubbleAsset.d.ts +11 -0
  34. package/dist/Resources/Assets/ChatBubbleAsset.js +18 -0
  35. package/dist/Resources/Assets/CloudAsset.js +3 -1
  36. package/dist/Resources/Assets/ConfettiAsset.d.ts +10 -0
  37. package/dist/Resources/Assets/ConfettiAsset.js +18 -0
  38. package/dist/Resources/Assets/CursorAsset.d.ts +11 -0
  39. package/dist/Resources/Assets/CursorAsset.js +17 -0
  40. package/dist/Resources/Assets/DeskAsset.js +7 -2
  41. package/dist/Resources/Assets/FirstAidKitAsset.d.ts +10 -0
  42. package/dist/Resources/Assets/FirstAidKitAsset.js +19 -0
  43. package/dist/Resources/Assets/GlobeAsset.d.ts +10 -0
  44. package/dist/Resources/Assets/GlobeAsset.js +18 -0
  45. package/dist/Resources/Assets/HouseAsset.js +22 -6
  46. package/dist/Resources/Assets/LaptopAsset.js +5 -1
  47. package/dist/Resources/Assets/PlantAsset.js +1 -1
  48. package/dist/Resources/Assets/PodiumAsset.d.ts +11 -0
  49. package/dist/Resources/Assets/PodiumAsset.js +20 -0
  50. package/dist/Resources/Assets/RefrigeratorAsset.d.ts +11 -0
  51. package/dist/Resources/Assets/RefrigeratorAsset.js +21 -0
  52. package/dist/Resources/Assets/SinkAsset.d.ts +11 -0
  53. package/dist/Resources/Assets/SinkAsset.js +21 -0
  54. package/dist/Resources/Assets/SofaAsset.d.ts +5 -0
  55. package/dist/Resources/Assets/SofaAsset.js +30 -2
  56. package/dist/Resources/Assets/StarsAsset.d.ts +6 -0
  57. package/dist/Resources/Assets/StarsAsset.js +37 -24
  58. package/dist/Resources/Assets/StethoscopeAsset.d.ts +10 -0
  59. package/dist/Resources/Assets/StethoscopeAsset.js +18 -0
  60. package/dist/Resources/Assets/StoveAsset.d.ts +11 -0
  61. package/dist/Resources/Assets/StoveAsset.js +20 -0
  62. package/dist/Resources/Assets/ToggleAsset.d.ts +11 -0
  63. package/dist/Resources/Assets/ToggleAsset.js +21 -0
  64. package/dist/Resources/Assets/TreeAsset.d.ts +5 -0
  65. package/dist/Resources/Assets/TreeAsset.js +32 -7
  66. package/dist/Resources/Assets/WaterCoolerAsset.d.ts +11 -0
  67. package/dist/Resources/Assets/WaterCoolerAsset.js +20 -0
  68. package/dist/Resources/Assets/WhiteboardAsset.d.ts +10 -0
  69. package/dist/Resources/Assets/WhiteboardAsset.js +18 -0
  70. package/dist/Resources/Kits/BaseKit.d.ts +2 -1
  71. package/dist/Resources/Kits/BaseKit.js +1 -0
  72. package/dist/Resources/Kits/ClayKit.d.ts +9 -0
  73. package/dist/Resources/Kits/ClayKit.js +11 -0
  74. package/dist/Resources/Kits/DuotoneKit.d.ts +16 -0
  75. package/dist/Resources/Kits/DuotoneKit.js +18 -0
  76. package/dist/Resources/Kits/IsometricKit.d.ts +8 -0
  77. package/dist/Resources/Kits/IsometricKit.js +10 -0
  78. package/dist/Resources/Kits/OutlineKit.d.ts +3 -0
  79. package/dist/Resources/Kits/OutlineKit.js +1 -1
  80. package/dist/Resources/Kits/PaperKit.d.ts +2 -0
  81. package/dist/Resources/Kits/PaperKit.js +1 -0
  82. package/dist/Resources/Kits/PosterKit.d.ts +14 -0
  83. package/dist/Resources/Kits/PosterKit.js +16 -0
  84. package/dist/Resources/Kits/SketchKit.d.ts +2 -1
  85. package/dist/Resources/Kits/SketchKit.js +1 -0
  86. package/dist/Services/AssetService.js +29 -1
  87. package/dist/Services/BackgroundService.d.ts +10 -2
  88. package/dist/Services/BackgroundService.js +52 -11
  89. package/dist/Services/CatalogService.d.ts +1 -0
  90. package/dist/Services/CatalogService.js +8 -3
  91. package/dist/Services/ColorCritiqueService.d.ts +42 -0
  92. package/dist/Services/ColorCritiqueService.js +232 -0
  93. package/dist/Services/ContextService.js +9 -5
  94. package/dist/Services/DescriptionService.d.ts +2 -1
  95. package/dist/Services/DescriptionService.js +8 -2
  96. package/dist/Services/DetailService.d.ts +7 -0
  97. package/dist/Services/DetailService.js +18 -0
  98. package/dist/Services/FocusCritiqueService.d.ts +23 -0
  99. package/dist/Services/FocusCritiqueService.js +166 -0
  100. package/dist/Services/FramingService.d.ts +31 -0
  101. package/dist/Services/FramingService.js +108 -0
  102. package/dist/Services/GazeService.js +3 -1
  103. package/dist/Services/GroundDetailService.d.ts +50 -0
  104. package/dist/Services/GroundDetailService.js +115 -0
  105. package/dist/Services/KitService.d.ts +11 -2
  106. package/dist/Services/KitService.js +45 -10
  107. package/dist/Services/LightingService.d.ts +15 -0
  108. package/dist/Services/LightingService.js +124 -6
  109. package/dist/Services/PaletteService.d.ts +108 -0
  110. package/dist/Services/PaletteService.js +282 -0
  111. package/dist/Services/PieceService.d.ts +4 -0
  112. package/dist/Services/PieceService.js +28 -7
  113. package/dist/Services/PlacementService.js +7 -1
  114. package/dist/Services/PlaneBackgroundService.d.ts +4 -0
  115. package/dist/Services/PlaneBackgroundService.js +42 -3
  116. package/dist/Services/PlaneProjectionService.d.ts +4 -0
  117. package/dist/Services/PlaneProjectionService.js +33 -4
  118. package/dist/Services/RasterService.js +20 -3
  119. package/dist/Services/RidgeService.d.ts +31 -0
  120. package/dist/Services/RidgeService.js +85 -0
  121. package/dist/Services/ScaleCritiqueService.d.ts +11 -0
  122. package/dist/Services/ScaleCritiqueService.js +57 -0
  123. package/dist/Services/SkyDetailService.d.ts +39 -0
  124. package/dist/Services/SkyDetailService.js +95 -0
  125. package/dist/Services/{ContactCritiqueService.d.ts → TangentCritiqueService.d.ts} +10 -6
  126. package/dist/Services/TangentCritiqueService.js +136 -0
  127. package/dist/Services/TextService.d.ts +43 -3
  128. package/dist/Services/TextService.js +288 -32
  129. package/dist/Services/ThumbnailCritiqueService.d.ts +30 -0
  130. package/dist/Services/ThumbnailCritiqueService.js +130 -0
  131. package/dist/Utils/ColorUtil.d.ts +14 -0
  132. package/dist/Utils/ColorUtil.js +68 -5
  133. package/dist/Utils/DetailUtil.d.ts +7 -0
  134. package/dist/Utils/DetailUtil.js +15 -0
  135. package/dist/Utils/FontMetricsUtil.d.ts +7 -0
  136. package/dist/Utils/FontMetricsUtil.js +694 -0
  137. package/dist/Utils/OklabUtil.d.ts +18 -0
  138. package/dist/Utils/OklabUtil.js +89 -0
  139. package/dist/Utils/PersonArmUtil.d.ts +13 -1
  140. package/dist/Utils/PersonArmUtil.js +53 -5
  141. package/dist/Utils/PersonHeadUtil.js +3 -1
  142. package/dist/Utils/PersonOutfitUtil.d.ts +16 -0
  143. package/dist/Utils/PersonOutfitUtil.js +89 -13
  144. package/dist/Utils/PersonUtil.d.ts +2 -0
  145. package/dist/Utils/PersonUtil.js +14 -4
  146. package/dist/Utils/SanitizeUtil.js +1 -0
  147. package/dist/Utils/ShapeUtil.d.ts +9 -0
  148. package/dist/Utils/ShapeUtil.js +26 -0
  149. package/dist/Utils/TypesettingUtil.d.ts +17 -0
  150. package/dist/Utils/TypesettingUtil.js +92 -0
  151. package/dist/cli.js +32 -3
  152. package/dist/render.d.ts +3 -1
  153. package/dist/render.js +5 -0
  154. package/fonts/DMSerifDisplay-Regular.ttf +0 -0
  155. package/fonts/OFL.txt +2 -0
  156. package/fonts/PatrickHand-Regular.ttf +0 -0
  157. package/package.json +1 -1
  158. package/skills/draw-scene/SKILL.md +2 -1
  159. package/skills/draw-scene/recipes/carousel.yaml +1 -1
  160. package/skills/draw-scene/recipes/conference-keynote.yaml +43 -0
  161. package/skills/draw-scene/recipes/product-feature.yaml +41 -0
  162. package/skills/draw-scene/recipes/product-illustration.yaml +2 -1
  163. package/skills/draw-scene/references/catalog.md +19 -1
  164. package/skills/draw-scene/references/dsl.md +24 -6
  165. package/dist/Services/ContactCritiqueService.js +0 -101
@@ -11,12 +11,31 @@ class PlaneProjectionService {
11
11
  static BOARD_SPREAD_MIN = 0.72;
12
12
  static BOARD_SPREAD_RANGE = 0.28;
13
13
  static FRAME_FILL = 0.98;
14
+ static ISO_UNIT = 35e-4;
15
+ static shrinkOf(isIso, depth) {
16
+ if (isIso) {
17
+ return () => 1;
18
+ }
19
+ return (groundZ) => 1 / (1 + depth * Math.max(groundZ, -0.85 / depth));
20
+ }
21
+ static lensOf(isIso, room, canvas, frame, depth) {
22
+ if (isIso) {
23
+ return PlaneProjectionService.isometricLens(frame);
24
+ }
25
+ if (room) {
26
+ return PlaneProjectionService.roomLens(room, frame);
27
+ }
28
+ return PlaneProjectionService.boardLens(canvas, frame, depth);
29
+ }
14
30
  static create(canvas, width, height) {
15
- const room = PlaneProjectionService.roomOf(canvas.camera);
16
- const depth = room?.depth ?? canvas.depth ?? PlaneProjectionService.BOARD_DEPTH;
17
- const shrink = (groundZ) => 1 / (1 + depth * Math.max(groundZ, -0.85 / depth));
31
+ const camera = canvas.camera;
32
+ const options = typeof camera === "string" ? { preset: camera } : camera ?? {};
33
+ const isIso = options.preset === "isometric" || canvas.kit === "isometric";
34
+ const room = isIso ? null : PlaneProjectionService.roomOf(canvas.camera);
35
+ const depth = isIso ? 0 : room?.depth ?? canvas.depth ?? PlaneProjectionService.BOARD_DEPTH;
36
+ const shrink = PlaneProjectionService.shrinkOf(isIso, depth);
18
37
  const frame = { width, height, zoom: canvas.scale ?? 1, shrink };
19
- const lens = room ? PlaneProjectionService.roomLens(room, frame) : PlaneProjectionService.boardLens(canvas, frame, depth);
38
+ const lens = PlaneProjectionService.lensOf(isIso, room, canvas, frame, depth);
20
39
  const { unit, spread, screenX, screenY } = lens;
21
40
  const fill = PlaneProjectionService.FRAME_FILL;
22
41
  const pxPerUnit = (groundZ, factor = 1) => unit * shrink(groundZ) * factor;
@@ -69,6 +88,16 @@ class PlaneProjectionService {
69
88
  screenY: (groundZ) => horizonY + (nearY - horizonY) * shrink(groundZ)
70
89
  };
71
90
  }
91
+ static isometricLens(frame) {
92
+ const { width, height, zoom } = frame;
93
+ return {
94
+ eyeX: 0.5,
95
+ unit: height * PlaneProjectionService.ISO_UNIT * zoom,
96
+ spread: () => 1,
97
+ screenX: (groundX) => width / 2 + (groundX - 0.5) * width * PlaneProjectionService.FRAME_FILL,
98
+ screenY: (groundZ) => height * 0.55 + groundZ * height * 0.38
99
+ };
100
+ }
72
101
  static boardLens(canvas, frame, depth) {
73
102
  const { width, height, zoom, shrink } = frame;
74
103
  const nearY = height * (canvas.near_y ?? PlaneProjectionService.BOARD_NEAR_Y);
@@ -26,7 +26,10 @@ class RasterService {
26
26
  fullLab: RasterService.labOf(source.fullPixels, pixelCount),
27
27
  backLab: RasterService.labOf(source.backPixels, pixelCount),
28
28
  objects,
29
- owner
29
+ owner,
30
+ horizonRatio: source.horizonRatio,
31
+ setting: source.setting,
32
+ focusId: source.focusId
30
33
  };
31
34
  }
32
35
  static objectOf(layer, width, height) {
@@ -47,7 +50,18 @@ class RasterService {
47
50
  box.bottom = Math.max(box.bottom, row);
48
51
  }
49
52
  }
50
- return { id: layer.id, kind: layer.kind, related: layer.related, alpha, area, box };
53
+ return {
54
+ id: layer.id,
55
+ asset: layer.asset,
56
+ kind: layer.kind,
57
+ related: layer.related,
58
+ alpha,
59
+ area,
60
+ box,
61
+ isFocus: layer.isFocus,
62
+ height: layer.height,
63
+ depth: layer.depth
64
+ };
51
65
  }
52
66
  static labOf(pixels, pixelCount) {
53
67
  const lab = new Float32Array(pixelCount * RasterService.LAB_COMPONENTS);
@@ -58,7 +72,10 @@ class RasterService {
58
72
  PixelUtil.read(pixels, offset + 1),
59
73
  PixelUtil.read(pixels, offset + 2)
60
74
  );
61
- lab.set([lightness, greenRed, blueYellow], index * RasterService.LAB_COMPONENTS);
75
+ const targetIndex = index * RasterService.LAB_COMPONENTS;
76
+ lab[targetIndex] = lightness;
77
+ lab[targetIndex + 1] = greenRed;
78
+ lab[targetIndex + 2] = blueYellow;
62
79
  }
63
80
  return lab;
64
81
  }
@@ -0,0 +1,31 @@
1
+ export interface RidgeOptions {
2
+ count: number;
3
+ seed: number;
4
+ width: number;
5
+ horizonY: number;
6
+ groundColor: string;
7
+ airColor: string;
8
+ bottomY: number;
9
+ }
10
+ export declare class RidgeService {
11
+ private static readonly SAMPLE_COUNT;
12
+ private static readonly MAX_ELEVATION_FACTOR;
13
+ private static readonly ELEVATION_DROP;
14
+ private static readonly AMPLITUDE_RATIO;
15
+ private static readonly BASE_AMP_SCALE;
16
+ private static readonly OCTAVE1_WEIGHT;
17
+ private static readonly OCTAVE2_WEIGHT;
18
+ private static readonly OCTAVE3_WEIGHT;
19
+ private static readonly MAX_MIX_FACTOR;
20
+ private static readonly FULL_TURN;
21
+ private static readonly FREQ1_BASE;
22
+ private static readonly FREQ1_SPAN;
23
+ private static readonly FREQ2_BASE;
24
+ private static readonly FREQ2_SPAN;
25
+ private static readonly FREQ3_BASE;
26
+ private static readonly FREQ3_SPAN;
27
+ private static readonly LAYER_SEED_STEP;
28
+ static draw(options: RidgeOptions): string;
29
+ private static drawLayer;
30
+ private static buildPath;
31
+ }
@@ -0,0 +1,85 @@
1
+ import { ColorUtil } from "../Utils/ColorUtil.js";
2
+ import { SeedUtil } from "../Utils/SeedUtil.js";
3
+ class RidgeService {
4
+ static SAMPLE_COUNT = 24;
5
+ static MAX_ELEVATION_FACTOR = 0.14;
6
+ static ELEVATION_DROP = 0.45;
7
+ static AMPLITUDE_RATIO = 0.35;
8
+ static BASE_AMP_SCALE = 0.5;
9
+ static OCTAVE1_WEIGHT = 0.55;
10
+ static OCTAVE2_WEIGHT = 0.3;
11
+ static OCTAVE3_WEIGHT = 0.15;
12
+ static MAX_MIX_FACTOR = 0.52;
13
+ static FULL_TURN = Math.PI * 2;
14
+ static FREQ1_BASE = 1.5;
15
+ static FREQ1_SPAN = 0.8;
16
+ static FREQ2_BASE = 3.5;
17
+ static FREQ2_SPAN = 1.5;
18
+ static FREQ3_BASE = 7;
19
+ static FREQ3_SPAN = 2.5;
20
+ static LAYER_SEED_STEP = 101;
21
+ static draw(options) {
22
+ const { count, seed, width, horizonY, groundColor, airColor, bottomY } = options;
23
+ if (count <= 0) {
24
+ return "";
25
+ }
26
+ let svg = "";
27
+ for (let index = 0; index < count; index++) {
28
+ svg += RidgeService.drawLayer({ index, count, seed, width, horizonY, groundColor, airColor, bottomY });
29
+ }
30
+ return svg;
31
+ }
32
+ static drawLayer(parts) {
33
+ const { index, count, seed, width, horizonY, groundColor, airColor, bottomY } = parts;
34
+ const random = SeedUtil.sequence(seed + index * RidgeService.LAYER_SEED_STEP);
35
+ const elevationRatio = 1 - index / count * RidgeService.ELEVATION_DROP;
36
+ const baseElevation = horizonY * RidgeService.MAX_ELEVATION_FACTOR * elevationRatio;
37
+ const ampScale = RidgeService.BASE_AMP_SCALE + index / count * RidgeService.BASE_AMP_SCALE;
38
+ const amplitude = baseElevation * RidgeService.AMPLITUDE_RATIO * ampScale;
39
+ const freq1 = (RidgeService.FREQ1_BASE + random() * RidgeService.FREQ1_SPAN) * Math.PI / width;
40
+ const phase1 = random() * RidgeService.FULL_TURN;
41
+ const freq2 = (RidgeService.FREQ2_BASE + random() * RidgeService.FREQ2_SPAN) * Math.PI / width;
42
+ const phase2 = random() * RidgeService.FULL_TURN;
43
+ const freq3 = (RidgeService.FREQ3_BASE + random() * RidgeService.FREQ3_SPAN) * Math.PI / width;
44
+ const phase3 = random() * RidgeService.FULL_TURN;
45
+ const points = [];
46
+ for (let sample = 0; sample <= RidgeService.SAMPLE_COUNT; sample++) {
47
+ const posX = sample / RidgeService.SAMPLE_COUNT * width;
48
+ const octave1 = Math.sin(freq1 * posX + phase1) * RidgeService.OCTAVE1_WEIGHT;
49
+ const octave2 = Math.sin(freq2 * posX + phase2) * RidgeService.OCTAVE2_WEIGHT;
50
+ const octave3 = Math.sin(freq3 * posX + phase3) * RidgeService.OCTAVE3_WEIGHT;
51
+ const wave = octave1 + octave2 + octave3;
52
+ const posY = horizonY - baseElevation + amplitude * wave;
53
+ points.push({ x: posX, y: posY });
54
+ }
55
+ const path = RidgeService.buildPath(points, width, bottomY);
56
+ const mixWeight = RidgeService.MAX_MIX_FACTOR * (1 - (index + 0.5) / (count + 0.5));
57
+ const color = ColorUtil.mix(groundColor, airColor, mixWeight);
58
+ return `<path d="${path}" fill="${color}"/>`;
59
+ }
60
+ static buildPath(points, width, bottomY) {
61
+ const first = points[0];
62
+ if (!first) {
63
+ return "";
64
+ }
65
+ let commands = `M 0 ${first.y.toFixed(1)}`;
66
+ for (let index = 1; index < points.length; index++) {
67
+ const prev = points[index - 1];
68
+ const curr = points[index];
69
+ if (prev && curr) {
70
+ const midX = (prev.x + curr.x) / 2;
71
+ const midY = (prev.y + curr.y) / 2;
72
+ commands += ` Q ${prev.x.toFixed(1)} ${prev.y.toFixed(1)} ${midX.toFixed(1)} ${midY.toFixed(1)}`;
73
+ }
74
+ }
75
+ const last = points[points.length - 1];
76
+ if (last) {
77
+ commands += ` L ${last.x.toFixed(1)} ${last.y.toFixed(1)}`;
78
+ }
79
+ commands += ` L ${width.toFixed(1)} ${bottomY.toFixed(1)} L 0 ${bottomY.toFixed(1)} Z`;
80
+ return commands;
81
+ }
82
+ }
83
+ export {
84
+ RidgeService
85
+ };
@@ -0,0 +1,11 @@
1
+ import type { CritiqueInput } from "../Protocols/CompilationProtocol.js";
2
+ export declare class ScaleCritiqueService {
3
+ private static readonly MIN_SCALE_RATIO;
4
+ private static readonly MIN_SCALE_OBJECT_COUNT;
5
+ private static readonly MIN_DEPTH_OBJECT_COUNT;
6
+ private static readonly NON_MEANINGFUL_KINDS;
7
+ private static readonly DEPTH_TO_OTHER_DEPTHS;
8
+ static critique(input: CritiqueInput): string[];
9
+ private static checkScale;
10
+ private static checkDepth;
11
+ }
@@ -0,0 +1,57 @@
1
+ import { IdUtil } from "../Utils/IdUtil.js";
2
+ class ScaleCritiqueService {
3
+ // Why: when the largest and smallest objects differ by less than 1.5x in height, visual hierarchy is flat and stagnant.
4
+ static MIN_SCALE_RATIO = 1.5;
5
+ // Why: scale variety requires at least 3 objects to establish a meaningful visual hierarchy.
6
+ static MIN_SCALE_OBJECT_COUNT = 3;
7
+ // Why: depth layer critique only applies when there are more than three objects to distribute across planes.
8
+ static MIN_DEPTH_OBJECT_COUNT = 3;
9
+ static NON_MEANINGFUL_KINDS = ["floor", "sky", "ceiling"];
10
+ static DEPTH_TO_OTHER_DEPTHS = {
11
+ mid: "'near' or 'far'",
12
+ near: "'mid' or 'far'",
13
+ far: "'near' or 'mid'"
14
+ };
15
+ static critique(input) {
16
+ const meaningful = input.objects.filter(
17
+ (object) => !object.isIgnored && !IdUtil.isOneOf(ScaleCritiqueService.NON_MEANINGFUL_KINDS, object.kind) && (object.height ?? 0) > 0
18
+ );
19
+ return [
20
+ ...ScaleCritiqueService.checkScale(meaningful),
21
+ ...ScaleCritiqueService.checkDepth(meaningful, input.setting)
22
+ ];
23
+ }
24
+ static checkScale(objects) {
25
+ if (objects.length < ScaleCritiqueService.MIN_SCALE_OBJECT_COUNT) {
26
+ return [];
27
+ }
28
+ const heights = objects.map((object) => object.height ?? 0);
29
+ const maxHeight = Math.max(...heights);
30
+ const minHeight = Math.min(...heights);
31
+ if (minHeight > 0 && maxHeight / minHeight < ScaleCritiqueService.MIN_SCALE_RATIO) {
32
+ return ["objects have similar sizes; make the focus larger or add a small object for scale"];
33
+ }
34
+ return [];
35
+ }
36
+ static checkDepth(objects, setting) {
37
+ if (setting !== "outdoor" || objects.length <= ScaleCritiqueService.MIN_DEPTH_OBJECT_COUNT) {
38
+ return [];
39
+ }
40
+ const depths = objects.map((object) => object.depth).filter((depth) => depth != null);
41
+ if (depths.length === 0) {
42
+ return [];
43
+ }
44
+ const uniqueDepths = [...new Set(depths)];
45
+ if (uniqueDepths.length === 1) {
46
+ const singleDepth = uniqueDepths[0];
47
+ if (singleDepth) {
48
+ const suggestion = IdUtil.lookup(ScaleCritiqueService.DEPTH_TO_OTHER_DEPTHS, singleDepth) ?? "'near' or 'far'";
49
+ return [`everything is at depth '${singleDepth}'; move something to ${suggestion}`];
50
+ }
51
+ }
52
+ return [];
53
+ }
54
+ }
55
+ export {
56
+ ScaleCritiqueService
57
+ };
@@ -0,0 +1,39 @@
1
+ import type { TextRect } from "../Protocols/CompilationProtocol.js";
2
+ import type { CloudDensity } from "../Protocols/SceneProtocol.js";
3
+ import type { Theme } from "../Protocols/ThemeProtocol.js";
4
+ export interface Box {
5
+ x0: number;
6
+ y0: number;
7
+ x1: number;
8
+ y1: number;
9
+ }
10
+ export interface AmbientCloudOptions {
11
+ density?: CloudDensity;
12
+ seed: number;
13
+ width: number;
14
+ horizonY: number;
15
+ paperColor: string;
16
+ textRects?: readonly TextRect[];
17
+ focusBox?: Box | null;
18
+ }
19
+ export declare class SkyDetailService {
20
+ private static readonly CLOUD_BASE_WIDTH;
21
+ private static readonly CLOUD_BASE_HEIGHT;
22
+ private static readonly TEXT_MARGIN;
23
+ private static readonly FEW_COUNT;
24
+ private static readonly MANY_COUNT;
25
+ private static readonly SEED_STEP;
26
+ private static readonly SKY_MID_STOP;
27
+ private static readonly SKY_BAND_STOP;
28
+ private static readonly WARM_SHIFT;
29
+ private static readonly X_START_RATIO;
30
+ private static readonly X_SPAN_RATIO;
31
+ private static readonly SHADOW_AMOUNT;
32
+ private static readonly DENSITY_TO_COUNT;
33
+ private static readonly CLOUD_SPECS;
34
+ static skyGradientStops(theme: Theme): string;
35
+ static ambientClouds(options: AmbientCloudOptions): string;
36
+ private static drawOneCloud;
37
+ private static overlapsAny;
38
+ private static intersects;
39
+ }
@@ -0,0 +1,95 @@
1
+ import { ColorUtil } from "../Utils/ColorUtil.js";
2
+ import { SeedUtil } from "../Utils/SeedUtil.js";
3
+ class SkyDetailService {
4
+ static CLOUD_BASE_WIDTH = 110;
5
+ static CLOUD_BASE_HEIGHT = 50;
6
+ static TEXT_MARGIN = 20;
7
+ static FEW_COUNT = 3;
8
+ static MANY_COUNT = 6;
9
+ static SEED_STEP = 79;
10
+ static SKY_MID_STOP = 0.55;
11
+ static SKY_BAND_STOP = 0.85;
12
+ static WARM_SHIFT = 0.12;
13
+ static X_START_RATIO = 0.1;
14
+ static X_SPAN_RATIO = 0.8;
15
+ static SHADOW_AMOUNT = -0.08;
16
+ static DENSITY_TO_COUNT = {
17
+ none: 0,
18
+ few: SkyDetailService.FEW_COUNT,
19
+ many: SkyDetailService.MANY_COUNT
20
+ };
21
+ static CLOUD_SPECS = [
22
+ { scale: 0.55, opacity: 0.45, minYRatio: 0.12, maxYRatio: 0.35 },
23
+ { scale: 0.85, opacity: 0.7, minYRatio: 0.28, maxYRatio: 0.58 },
24
+ { scale: 1.15, opacity: 0.92, minYRatio: 0.42, maxYRatio: 0.78 }
25
+ ];
26
+ static skyGradientStops(theme) {
27
+ const skyMid = ColorUtil.mix(theme.skyTop, theme.skyBottom, SkyDetailService.SKY_MID_STOP);
28
+ const skyBand = ColorUtil.sh(theme.skyBottom, SkyDetailService.WARM_SHIFT);
29
+ return `<stop offset="0" stop-color="${theme.skyTop}"/><stop offset="${SkyDetailService.SKY_MID_STOP}" stop-color="${skyMid}"/><stop offset="${SkyDetailService.SKY_BAND_STOP}" stop-color="${skyBand}"/><stop offset="1" stop-color="${theme.skyBottom}"/>`;
30
+ }
31
+ static ambientClouds(options) {
32
+ const { density = "none", seed, width, horizonY, paperColor, textRects = [], focusBox } = options;
33
+ const count = SkyDetailService.DENSITY_TO_COUNT[density];
34
+ if (count <= 0) {
35
+ return "";
36
+ }
37
+ let svg = "";
38
+ for (let index = 0; index < count; index++) {
39
+ svg += SkyDetailService.drawOneCloud({
40
+ index,
41
+ seed,
42
+ width,
43
+ horizonY,
44
+ paperColor,
45
+ textRects,
46
+ focusBox
47
+ });
48
+ }
49
+ return svg;
50
+ }
51
+ static drawOneCloud(parts) {
52
+ const { index, seed, width, horizonY, paperColor, textRects, focusBox } = parts;
53
+ const random = SeedUtil.sequence(seed + index * SkyDetailService.SEED_STEP);
54
+ const specIndex = index % SkyDetailService.CLOUD_SPECS.length;
55
+ const spec = SkyDetailService.CLOUD_SPECS[specIndex] ?? {
56
+ scale: 0.55,
57
+ opacity: 0.45,
58
+ minYRatio: 0.12,
59
+ maxYRatio: 0.35
60
+ };
61
+ const posX = (SkyDetailService.X_START_RATIO + random() * SkyDetailService.X_SPAN_RATIO) * width;
62
+ const yRatio = spec.minYRatio + random() * (spec.maxYRatio - spec.minYRatio);
63
+ const posY = horizonY * yRatio;
64
+ const halfWidth = SkyDetailService.CLOUD_BASE_WIDTH * spec.scale / 2;
65
+ const halfHeight = SkyDetailService.CLOUD_BASE_HEIGHT * spec.scale / 2;
66
+ const cloudBox = {
67
+ x0: posX - halfWidth - SkyDetailService.TEXT_MARGIN,
68
+ y0: posY - halfHeight - SkyDetailService.TEXT_MARGIN,
69
+ x1: posX + halfWidth + SkyDetailService.TEXT_MARGIN,
70
+ y1: posY + halfHeight + SkyDetailService.TEXT_MARGIN
71
+ };
72
+ if (SkyDetailService.overlapsAny(cloudBox, textRects, focusBox)) {
73
+ return "";
74
+ }
75
+ const shaded = ColorUtil.sh(paperColor, SkyDetailService.SHADOW_AMOUNT);
76
+ return `<g transform="translate(${posX.toFixed(1)} ${posY.toFixed(1)}) scale(${spec.scale.toFixed(2)})" fill="${paperColor}" opacity="${spec.opacity}"><circle cx="-28" cy="-15" r="15"/><circle cx="0" cy="-26" r="22"/><circle cx="28" cy="-15" r="15"/><rect x="-43" y="-15" width="86" height="15" rx="7"/><path d="M-43 -8 Q-43 0 -36 0 L36 0 Q43 0 43 -8 Z" fill="${shaded}" opacity="0.9"/></g>`;
77
+ }
78
+ static overlapsAny(cloudBox, textRects, focusBox) {
79
+ if (focusBox && SkyDetailService.intersects(cloudBox, focusBox)) {
80
+ return true;
81
+ }
82
+ return textRects.some((rect) => SkyDetailService.intersects(cloudBox, {
83
+ x0: rect.x0,
84
+ y0: rect.y0,
85
+ x1: rect.x1,
86
+ y1: rect.y1
87
+ }));
88
+ }
89
+ static intersects(first, second) {
90
+ return first.x0 < second.x1 && first.x1 > second.x0 && first.y0 < second.y1 && first.y1 > second.y0;
91
+ }
92
+ }
93
+ export {
94
+ SkyDetailService
95
+ };
@@ -1,19 +1,23 @@
1
1
  import type { Raster } from "../Protocols/CritiqueProtocol.js";
2
- export declare class ContactCritiqueService {
2
+ export declare class TangentCritiqueService {
3
3
  private static readonly MIN_AREA;
4
- private static readonly NEAR_DISTANCE;
5
- private static readonly DILATION;
4
+ private static readonly NEAR_DISTANCE_PX;
5
+ private static readonly DILATION_PX;
6
6
  private static readonly OPAQUE_ALPHA;
7
7
  private static readonly MIN_NEAR_PIXELS;
8
- private static readonly MAX_OVERLAP_PIXELS;
9
- private static readonly MAX_OVERLAP_SHARE;
10
- private static readonly MAX_EDGE_GAP;
8
+ private static readonly MAX_ALMOST_TOUCH_PIXELS;
9
+ private static readonly MAX_SKY_OVERLAP_SHARE;
10
+ private static readonly HORIZON_GAP_PX;
11
+ private static readonly MAX_EDGE_GAP_PX;
12
+ private static readonly MIN_GAP_PX;
11
13
  static critique(raster: Raster): string[];
12
14
  private static tangencies;
13
15
  private static isTangent;
16
+ private static isIgnoredPair;
14
17
  private static boxesAreClose;
15
18
  private static countContacts;
16
19
  private static dilate;
17
20
  private static stamp;
21
+ private static horizonTouches;
18
22
  private static edgeTouches;
19
23
  }
@@ -0,0 +1,136 @@
1
+ import { PixelUtil } from "../Utils/PixelUtil.js";
2
+ class TangentCritiqueService {
3
+ // Why: objects with fewer pixels than an icon are details or props and cannot form a prominent tangent.
4
+ static MIN_AREA = 30;
5
+ // Why: shapes whose bounding boxes are further apart than 4 px cannot touch after dilation.
6
+ static NEAR_DISTANCE_PX = 4;
7
+ // Why: a 2 px dilation radius detects edges that sit within a 2 px gap of each other.
8
+ static DILATION_PX = 2;
9
+ // Why: alpha above 128 defines the perceived solid boundary of an antialiased SVG element.
10
+ static OPAQUE_ALPHA = 128;
11
+ // Why: at least 4 meeting pixels are required to avoid single-pixel antialiasing noise.
12
+ static MIN_NEAR_PIXELS = 4;
13
+ // Why: accidental edge touches overlap by only 1 to 2 pixels.
14
+ static MAX_ALMOST_TOUCH_PIXELS = 2;
15
+ // Why: sky elements touching ground crowns with under 8% overlap create visual ambiguity.
16
+ static MAX_SKY_OVERLAP_SHARE = 0.08;
17
+ // Why: a 2 px gap to the horizon creates an awkward tangent resting right on the horizon line.
18
+ static HORIZON_GAP_PX = 2;
19
+ // Why: an object stopping 1 to 2 px short of the frame edge creates an accidental edge tangent.
20
+ static MAX_EDGE_GAP_PX = 2;
21
+ // Why: a gap under 8 px looks like an accidental touch rather than deliberate composition spacing.
22
+ static MIN_GAP_PX = 8;
23
+ static critique(raster) {
24
+ const candidates = raster.objects.filter(
25
+ (object) => object.area >= TangentCritiqueService.MIN_AREA && object.kind !== "floor"
26
+ );
27
+ return [
28
+ ...TangentCritiqueService.tangencies(raster, candidates),
29
+ ...candidates.flatMap((object) => TangentCritiqueService.horizonTouches(raster, object)),
30
+ ...candidates.flatMap((object) => TangentCritiqueService.edgeTouches(raster, object))
31
+ ];
32
+ }
33
+ static tangencies(raster, candidates) {
34
+ const dilated = candidates.map((object) => TangentCritiqueService.dilate(raster, object));
35
+ const messages = [];
36
+ candidates.forEach((first, firstIndex) => {
37
+ const firstDilated = dilated[firstIndex] ?? new Uint8Array(0);
38
+ for (const second of candidates.slice(firstIndex + 1)) {
39
+ if (TangentCritiqueService.isTangent(raster, { first, second, firstDilated })) {
40
+ messages.push(
41
+ `'${first.id}' just touches '${second.id}' (tangent); overlap them clearly or leave a gap of at least ${TangentCritiqueService.MIN_GAP_PX} px`
42
+ );
43
+ }
44
+ }
45
+ });
46
+ return messages;
47
+ }
48
+ static isTangent(raster, pair) {
49
+ const { first, second } = pair;
50
+ if (TangentCritiqueService.isIgnoredPair(first, second) || !TangentCritiqueService.boxesAreClose(first, second)) {
51
+ return false;
52
+ }
53
+ const { near, overlap } = TangentCritiqueService.countContacts(raster, pair);
54
+ const minArea = Math.min(first.area, second.area);
55
+ const isNearTouch = near >= TangentCritiqueService.MIN_NEAR_PIXELS && overlap <= TangentCritiqueService.MAX_ALMOST_TOUCH_PIXELS;
56
+ const hasSky = first.kind === "sky" || second.kind === "sky";
57
+ const isSkyTouch = hasSky && near > 0 && overlap <= TangentCritiqueService.MAX_SKY_OVERLAP_SHARE * minArea;
58
+ return isNearTouch || isSkyTouch;
59
+ }
60
+ static isIgnoredPair(first, second) {
61
+ if (first.related.includes(second.id) || second.related.includes(first.id)) {
62
+ return true;
63
+ }
64
+ const firstPrefix = first.id.includes("_") ? first.id.slice(0, first.id.indexOf("_")) : null;
65
+ const secondPrefix = second.id.includes("_") ? second.id.slice(0, second.id.indexOf("_")) : null;
66
+ return firstPrefix !== null && firstPrefix === secondPrefix;
67
+ }
68
+ static boxesAreClose(first, second) {
69
+ const distance = TangentCritiqueService.NEAR_DISTANCE_PX;
70
+ const isApartHorizontally = first.box.right + distance < second.box.left || second.box.right + distance < first.box.left;
71
+ const isApartVertically = first.box.bottom + distance < second.box.top || second.box.bottom + distance < first.box.top;
72
+ return !isApartHorizontally && !isApartVertically;
73
+ }
74
+ static countContacts(raster, pair) {
75
+ const { first, second, firstDilated } = pair;
76
+ let near = 0;
77
+ let overlap = 0;
78
+ for (let index = 0; index < raster.pixelCount; index++) {
79
+ if (PixelUtil.read(second.alpha, index) <= TangentCritiqueService.OPAQUE_ALPHA) {
80
+ continue;
81
+ }
82
+ if (PixelUtil.read(first.alpha, index) > TangentCritiqueService.OPAQUE_ALPHA) {
83
+ overlap++;
84
+ } else if (PixelUtil.read(firstDilated, index) > 0) {
85
+ near++;
86
+ }
87
+ }
88
+ return { near, overlap };
89
+ }
90
+ static dilate(raster, object) {
91
+ const dilated = new Uint8Array(raster.pixelCount);
92
+ for (let index = 0; index < raster.pixelCount; index++) {
93
+ if (PixelUtil.read(object.alpha, index) > TangentCritiqueService.OPAQUE_ALPHA) {
94
+ const center = { row: Math.trunc(index / raster.width), column: index % raster.width };
95
+ TangentCritiqueService.stamp(dilated, raster, center);
96
+ }
97
+ }
98
+ return dilated;
99
+ }
100
+ static stamp(dilated, raster, center) {
101
+ const reach = TangentCritiqueService.DILATION_PX;
102
+ const firstRow = Math.max(0, center.row - reach);
103
+ const lastRow = Math.min(raster.height - 1, center.row + reach);
104
+ const firstColumn = Math.max(0, center.column - reach);
105
+ const lastColumn = Math.min(raster.width - 1, center.column + reach);
106
+ for (let row = firstRow; row <= lastRow; row++) {
107
+ dilated.fill(1, row * raster.width + firstColumn, row * raster.width + lastColumn + 1);
108
+ }
109
+ }
110
+ static horizonTouches(raster, object) {
111
+ if (raster.horizonRatio == null || object.kind === "sky") {
112
+ return [];
113
+ }
114
+ const horizonY = Math.round(raster.height * raster.horizonRatio);
115
+ const tolerancePx = TangentCritiqueService.HORIZON_GAP_PX;
116
+ const isTopAtHorizon = Math.abs(object.box.top - horizonY) <= tolerancePx;
117
+ const isBottomAtHorizon = Math.abs(object.box.bottom - horizonY) <= tolerancePx;
118
+ const isSpanningAcross = object.box.top < horizonY - 1 && object.box.bottom > horizonY + 1;
119
+ if ((isTopAtHorizon || isBottomAtHorizon) && !isSpanningAcross) {
120
+ return [`'${object.id}' touches the horizon; move it above or below`];
121
+ }
122
+ return [];
123
+ }
124
+ static edgeTouches(raster, object) {
125
+ const maxEdgeGap = TangentCritiqueService.MAX_EDGE_GAP_PX;
126
+ const gaps = [
127
+ ["left", object.box.left],
128
+ ["right", raster.width - 1 - object.box.right],
129
+ ["top", object.box.top]
130
+ ];
131
+ return gaps.filter(([, gap]) => gap > 0 && gap <= maxEdgeGap).map(([side]) => `'${object.id}' touches the edge (${side}); move it away from the edge or let it crop on purpose`);
132
+ }
133
+ }
134
+ export {
135
+ TangentCritiqueService
136
+ };
@@ -5,7 +5,6 @@ export interface TextResult {
5
5
  rects: TextRect[];
6
6
  }
7
7
  export declare class TextService {
8
- private static readonly FONT;
9
8
  private static readonly TITLE_SIZE;
10
9
  private static readonly SUBTITLE_SIZE;
11
10
  private static readonly LABEL_SIZE;
@@ -16,6 +15,7 @@ export declare class TextService {
16
15
  private static readonly ROLE_TO_WEIGHT;
17
16
  private static readonly ROLE_TO_IS_BOLD;
18
17
  private static readonly HORIZONTAL_TO_ALIGNMENT;
18
+ private static readonly ANCHOR_TO_LEFT_OF;
19
19
  private static readonly DEFAULT_SIZE;
20
20
  private static readonly DEFAULT_WEIGHT;
21
21
  private static readonly MARGIN;
@@ -23,8 +23,8 @@ export declare class TextService {
23
23
  private static readonly BASELINE_ASCENT;
24
24
  private static readonly SUBTITLE_GAP;
25
25
  private static readonly LINE_HEIGHT;
26
- private static readonly BOLD_CHAR_WIDTH;
27
- private static readonly REGULAR_CHAR_WIDTH;
26
+ private static readonly FONT_NAME_TO_FAMILY;
27
+ private static readonly FONT_TO_CHAR_WIDTH;
28
28
  private static readonly MIN_CONTRAST;
29
29
  private static readonly SELF_COVER;
30
30
  private static readonly OBJECT_COVER;
@@ -36,12 +36,52 @@ export declare class TextService {
36
36
  private static readonly BOX_TOP_PAD;
37
37
  private static readonly BOX_BOTTOM_EXTRA;
38
38
  private static readonly BOX_BOTTOM_PAD;
39
+ private static readonly TRACKING_THRESHOLD_PX;
40
+ private static readonly DEFAULT_TIGHT_TRACKING;
41
+ private static readonly TRACKING_DECIMALS;
42
+ private static readonly DEFAULT_STICKER_ROTATION;
43
+ private static readonly STICKER_STROKE_FRACTION;
44
+ private static readonly STICKER_MIN_STROKE;
45
+ private static readonly STICKER_SHADOW_DY;
46
+ private static readonly STICKER_SHADOW_BLUR;
47
+ private static readonly STICKER_SHADOW_OPACITY;
48
+ private static readonly PILL_HORIZONTAL_PAD;
49
+ private static readonly PILL_VERTICAL_PAD;
50
+ private static readonly PILL_SHADOW_DY;
51
+ private static readonly PILL_SHADOW_BLUR;
52
+ private static readonly PILL_SHADOW_OPACITY;
53
+ private static readonly HIGHLIGHT_TOP;
54
+ private static readonly HIGHLIGHT_BOTTOM;
55
+ private static readonly HIGHLIGHT_PAD;
56
+ private static readonly HIGHLIGHT_SKEW;
57
+ private static readonly HIGHLIGHT_OPACITY;
58
+ private static readonly UNDERLINE_Y_OFFSET;
59
+ private static readonly HALF_CIRCLE_DEG;
60
+ private static readonly DEG_TO_RAD;
61
+ private static readonly HALF;
62
+ private static readonly STYLE_IGNORES_CONTRAST;
63
+ private static readonly BOX_STYLE_TO_RECT;
39
64
  static render(texts: SceneText[], context: CompilationContext, list: Placement[], backdrop: string): TextResult;
40
65
  private static themeColor;
41
66
  private static isRole;
42
67
  private static layoutOf;
68
+ private static resolveTracking;
43
69
  private static baseline;
70
+ private static rectOf;
71
+ private static rectForPlain;
72
+ private static rectForDefault;
73
+ private static rectForPill;
74
+ private static rectForSticker;
75
+ private static rectForHighlight;
76
+ private static rectForUnderline;
44
77
  private static boxOf;
78
+ private static renderRectBox;
79
+ private static renderPillBox;
80
+ private static renderStickerBox;
81
+ private static renderHighlightBox;
82
+ private static renderUnderline;
83
+ private static underlinedPieces;
84
+ private static escapeText;
45
85
  private static warnCovered;
46
86
  private static element;
47
87
  }