@guilhermebkel/scenec 0.2.0 → 0.2.2

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 +23 -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
@@ -1,5 +1,6 @@
1
1
  export type Lab = readonly [number, number, number];
2
2
  export type Rgb = readonly [number, number, number];
3
+ export type Lch = readonly [number, number, number];
3
4
  export declare class OklabUtil {
4
5
  private static readonly CHANNEL_MAX;
5
6
  private static readonly GAMMA_KNEE;
@@ -7,17 +8,34 @@ export declare class OklabUtil {
7
8
  private static readonly GAMMA_OFFSET;
8
9
  private static readonly GAMMA_DIVISOR;
9
10
  private static readonly GAMMA_EXPONENT;
11
+ private static readonly DELINEAR_KNEE;
12
+ private static readonly DELINEAR_EXPONENT;
13
+ private static readonly CUBE;
14
+ private static readonly FULL_TURN;
15
+ private static readonly GAMUT_STEPS;
16
+ private static readonly CHANNEL_MIN_LIMIT;
17
+ private static readonly CHANNEL_MAX_LIMIT;
10
18
  private static readonly HEX_RADIX;
11
19
  private static readonly HEX_DIGITS;
12
20
  private static readonly HEX_CHANNEL_STARTS;
13
21
  private static readonly RGB_TO_CONE;
14
22
  private static readonly CONE_TO_LAB;
23
+ private static readonly LAB_TO_CONE;
24
+ private static readonly CONE_TO_RGB;
15
25
  private static readonly CHANNEL_TO_LINEAR;
16
26
  static fromRgb(red: number, green: number, blue: number): Lab;
27
+ static toRgb(lightness: number, greenRed: number, blueYellow: number): Rgb;
28
+ static labToLch(lab: Lab): Lch;
29
+ static lchToLab(lch: Lch): Lab;
30
+ static lchToRgb(lch: Lch): Rgb;
31
+ static lchToHex(lch: Lch): string;
32
+ static clampGamut(lch: Lch): Rgb;
33
+ private static isInGamut;
17
34
  static distance(first: Lab, second: Lab): number;
18
35
  static toHex(red: number, green: number, blue: number): string;
19
36
  static rgbOfHex(hex: string): Rgb;
20
37
  private static dot;
21
38
  private static linear;
22
39
  private static linearOf;
40
+ private static delinear;
23
41
  }
@@ -5,6 +5,13 @@ class OklabUtil {
5
5
  static GAMMA_OFFSET = 0.055;
6
6
  static GAMMA_DIVISOR = 1.055;
7
7
  static GAMMA_EXPONENT = 2.4;
8
+ static DELINEAR_KNEE = 31308e-7;
9
+ static DELINEAR_EXPONENT = 1 / 2.4;
10
+ static CUBE = 3;
11
+ static FULL_TURN = Math.PI * 2;
12
+ static GAMUT_STEPS = 12;
13
+ static CHANNEL_MIN_LIMIT = -0.5;
14
+ static CHANNEL_MAX_LIMIT = 255.5;
8
15
  static HEX_RADIX = 16;
9
16
  static HEX_DIGITS = 2;
10
17
  static HEX_CHANNEL_STARTS = [1, 3, 5];
@@ -18,6 +25,16 @@ class OklabUtil {
18
25
  [1.9779984951, -2.428592205, 0.4505937099],
19
26
  [0.0259040371, 0.7827717662, -0.808675766]
20
27
  ];
28
+ static LAB_TO_CONE = [
29
+ [1, 0.3963377774, 0.2158037573],
30
+ [1, -0.1055613458, -0.0638541728],
31
+ [1, -0.0894841775, -1.291485548]
32
+ ];
33
+ static CONE_TO_RGB = [
34
+ [4.0767416621, -3.3077115913, 0.2309699292],
35
+ [-1.2684380046, 2.6097574011, -0.3413193965],
36
+ [-0.0041960863, -0.7034186147, 1.707614701]
37
+ ];
21
38
  static CHANNEL_TO_LINEAR = Float32Array.from(
22
39
  { length: OklabUtil.CHANNEL_MAX + 1 },
23
40
  (_, channel) => OklabUtil.linearOf(channel)
@@ -31,6 +48,71 @@ class OklabUtil {
31
48
  const [lightness = 0, greenRed = 0, blueYellow = 0] = OklabUtil.CONE_TO_LAB.map((row) => OklabUtil.dot(row, cones));
32
49
  return [lightness, greenRed, blueYellow];
33
50
  }
51
+ static toRgb(lightness, greenRed, blueYellow) {
52
+ const lab = [lightness, greenRed, blueYellow];
53
+ const [longCone = 0, mediumCone = 0, shortCone = 0] = OklabUtil.LAB_TO_CONE.map(
54
+ (row) => OklabUtil.dot(row, lab) ** OklabUtil.CUBE
55
+ );
56
+ const cones = [longCone, mediumCone, shortCone];
57
+ const [linearRed = 0, linearGreen = 0, linearBlue = 0] = OklabUtil.CONE_TO_RGB.map(
58
+ (row) => OklabUtil.dot(row, cones)
59
+ );
60
+ return [
61
+ OklabUtil.delinear(linearRed),
62
+ OklabUtil.delinear(linearGreen),
63
+ OklabUtil.delinear(linearBlue)
64
+ ];
65
+ }
66
+ static labToLch(lab) {
67
+ const [lightness, greenRed, blueYellow] = lab;
68
+ const chroma = Math.hypot(greenRed, blueYellow);
69
+ const rawHue = Math.atan2(blueYellow, greenRed);
70
+ const hue = (rawHue + OklabUtil.FULL_TURN) % OklabUtil.FULL_TURN;
71
+ return [lightness, chroma, hue];
72
+ }
73
+ static lchToLab(lch) {
74
+ const [lightness, chroma, hue] = lch;
75
+ return [lightness, chroma * Math.cos(hue), chroma * Math.sin(hue)];
76
+ }
77
+ static lchToRgb(lch) {
78
+ const [lightness, greenRed, blueYellow] = OklabUtil.lchToLab(lch);
79
+ return OklabUtil.toRgb(lightness, greenRed, blueYellow);
80
+ }
81
+ static lchToHex(lch) {
82
+ const [clampedRed, clampedGreen, clampedBlue] = OklabUtil.clampGamut(lch);
83
+ return OklabUtil.toHex(clampedRed, clampedGreen, clampedBlue);
84
+ }
85
+ static clampGamut(lch) {
86
+ const [lightness, initialChroma, hue] = lch;
87
+ let low = 0;
88
+ let high = initialChroma;
89
+ let currentChroma = initialChroma;
90
+ if (!OklabUtil.isInGamut(OklabUtil.lchToRgb([lightness, currentChroma, hue]))) {
91
+ for (let step = 0; step < OklabUtil.GAMUT_STEPS; step++) {
92
+ const mid = (low + high) / 2;
93
+ if (OklabUtil.isInGamut(OklabUtil.lchToRgb([lightness, mid, hue]))) {
94
+ low = mid;
95
+ } else {
96
+ high = mid;
97
+ }
98
+ }
99
+ currentChroma = low;
100
+ }
101
+ const [red, green, blue] = OklabUtil.lchToRgb([lightness, currentChroma, hue]);
102
+ const roundedRed = Math.round(red);
103
+ const roundedGreen = Math.round(green);
104
+ const roundedBlue = Math.round(blue);
105
+ return [
106
+ Math.max(0, Math.min(OklabUtil.CHANNEL_MAX, roundedRed)),
107
+ Math.max(0, Math.min(OklabUtil.CHANNEL_MAX, roundedGreen)),
108
+ Math.max(0, Math.min(OklabUtil.CHANNEL_MAX, roundedBlue))
109
+ ];
110
+ }
111
+ static isInGamut(rgb) {
112
+ return rgb.every(
113
+ (channel) => channel >= OklabUtil.CHANNEL_MIN_LIMIT && channel <= OklabUtil.CHANNEL_MAX_LIMIT
114
+ );
115
+ }
34
116
  static distance(first, second) {
35
117
  return Math.hypot(first[0] - second[0], first[1] - second[1], first[2] - second[2]);
36
118
  }
@@ -56,6 +138,13 @@ class OklabUtil {
56
138
  const unit = channel / OklabUtil.CHANNEL_MAX;
57
139
  return unit <= OklabUtil.GAMMA_KNEE ? unit / OklabUtil.GAMMA_LINEAR_DIVISOR : ((unit + OklabUtil.GAMMA_OFFSET) / OklabUtil.GAMMA_DIVISOR) ** OklabUtil.GAMMA_EXPONENT;
58
140
  }
141
+ static delinear(linear) {
142
+ if (linear <= OklabUtil.DELINEAR_KNEE) {
143
+ return linear * OklabUtil.GAMMA_LINEAR_DIVISOR * OklabUtil.CHANNEL_MAX;
144
+ }
145
+ const scaled = OklabUtil.GAMMA_DIVISOR * linear ** OklabUtil.DELINEAR_EXPONENT - OklabUtil.GAMMA_OFFSET;
146
+ return scaled * OklabUtil.CHANNEL_MAX;
147
+ }
59
148
  }
60
149
  export {
61
150
  OklabUtil
@@ -7,13 +7,25 @@ export declare class PersonArmUtil {
7
7
  private static readonly FINGER_ANGLES;
8
8
  private static readonly FINGER_LENGTHS;
9
9
  private static readonly SHORT_SLEEVE_SPLIT;
10
+ private static readonly SLEEVE_WIDTHS;
11
+ private static readonly SKIN_WIDTHS;
12
+ private static readonly SHORT_SLEEVE_WIDTHS;
13
+ private static readonly MAX_MITER;
14
+ private static readonly MIN_MITER_DOT;
15
+ private static readonly FOLD_HALF_WIDTH;
16
+ private static readonly FOLD_SHADE;
10
17
  private static readonly HALF_TURN_DEGREES;
11
18
  private static readonly BODY_CENTER_Y;
12
19
  static round(value: number): number;
13
20
  static ik(shoulder: Point, target: Point, side: number, bend?: BendName): Arm;
14
21
  static hand(position: Point, skin: string, isOpen: boolean, elbow: Point): string;
22
+ static taper(points: Point[], widths: number[], color: string): string;
23
+ private static foldOf;
15
24
  static armPath(shoulder: Point, arm: Arm, colors: {
16
25
  sleeve: string;
17
26
  skin: string;
18
- }, isShortSleeve: boolean): string;
27
+ }, options: {
28
+ isShortSleeve: boolean;
29
+ hasFold: boolean;
30
+ }): string;
19
31
  }
@@ -7,6 +7,13 @@ class PersonArmUtil {
7
7
  static FINGER_ANGLES = [-27, -9, 9, 27];
8
8
  static FINGER_LENGTHS = [2.4, 3.1, 2.9, 2.1];
9
9
  static SHORT_SLEEVE_SPLIT = 0.6;
10
+ static SLEEVE_WIDTHS = [8.4, 6.8, 5.4];
11
+ static SKIN_WIDTHS = [7, 5.8, 4.8];
12
+ static SHORT_SLEEVE_WIDTHS = [8.6, 7.8];
13
+ static MAX_MITER = 1.6;
14
+ static MIN_MITER_DOT = 0.5;
15
+ static FOLD_HALF_WIDTH = 3;
16
+ static FOLD_SHADE = 0.22;
10
17
  static HALF_TURN_DEGREES = 180;
11
18
  static BODY_CENTER_Y = -60;
12
19
  static round(value) {
@@ -55,7 +62,7 @@ class PersonArmUtil {
55
62
  const placement = `translate(${round(position[0])} ${round(position[1])}) rotate(${round(angle)})`;
56
63
  const wrap = (inner) => `<g transform="${placement}">${inner}</g>`;
57
64
  if (!isOpen) {
58
- return wrap(`<ellipse cx="1.2" cy="${0.9 * thumbSide}" rx="1.9" ry="1.3" fill="${shade}" transform="rotate(${-30 * thumbSide} 1.2 ${0.9 * thumbSide})"/><rect x="-1.2" y="-3.1" width="6.4" height="6.2" rx="3" fill="${skin}"/><ellipse cx="2.4" cy="${2.6 * thumbSide}" rx="2.2" ry="1.25" fill="${skin}" transform="rotate(${-20 * thumbSide} 2.4 ${2.6 * thumbSide})"/><path d="M4.2 -1.6 L4.2 1.6" stroke="${shade}" stroke-width="0.6" stroke-linecap="round"/>`);
65
+ return wrap(`<ellipse cx="1.2" cy="${0.9 * thumbSide}" rx="1.9" ry="1.3" fill="${shade}" transform="rotate(${-30 * thumbSide} 1.2 ${0.9 * thumbSide})"/><path d="M-1.2 -2.9 L3 -3.2 Q6.6 -3.1 6.6 0 Q6.6 3.1 3 3.2 L-1.2 2.9 Z" fill="${skin}"/><ellipse cx="2.4" cy="${2.6 * thumbSide}" rx="2.2" ry="1.25" fill="${skin}" transform="rotate(${-20 * thumbSide} 2.4 ${2.6 * thumbSide})"/><path d="M4.2 -1.6 L4.2 1.6" stroke="${shade}" stroke-width="0.6" stroke-linecap="round"/>`);
59
66
  }
60
67
  const fingers = PersonArmUtil.FINGER_ANGLES.map((fingerAngle, index) => {
61
68
  const length = PersonArmUtil.FINGER_LENGTHS[index] ?? 0;
@@ -64,19 +71,60 @@ class PersonArmUtil {
64
71
  }).join("");
65
72
  return wrap(`<ellipse cx="1.3" cy="0" rx="3.7" ry="3.5" fill="${skin}"/>${fingers}<path d="M0.6 ${2.2 * thumbSide} L1.8 ${5 * thumbSide}" stroke="${skin}" stroke-width="2.3" stroke-linecap="round"/>`);
66
73
  }
67
- static armPath(shoulder, arm, colors, isShortSleeve) {
74
+ static taper(points, widths, color) {
68
75
  const round = (value) => PersonArmUtil.round(value);
76
+ const last = points.length - 1;
77
+ const sides = points.map((point, index) => {
78
+ const before = points[Math.max(0, index - 1)] ?? point;
79
+ const after = points[Math.min(last, index + 1)] ?? point;
80
+ const length = Math.hypot(after[0] - before[0], after[1] - before[1]) || 1;
81
+ const normal = [-(after[1] - before[1]) / length, (after[0] - before[0]) / length];
82
+ const segmentFrom = index === last ? points[index - 1] ?? point : point;
83
+ const segmentTo = index === last ? point : points[index + 1] ?? point;
84
+ const segmentLength = Math.hypot(segmentTo[0] - segmentFrom[0], segmentTo[1] - segmentFrom[1]) || 1;
85
+ const segmentNormal = [
86
+ -(segmentTo[1] - segmentFrom[1]) / segmentLength,
87
+ (segmentTo[0] - segmentFrom[0]) / segmentLength
88
+ ];
89
+ const dot = normal[0] * segmentNormal[0] + normal[1] * segmentNormal[1];
90
+ const miter = Math.min(PersonArmUtil.MAX_MITER, 1 / Math.max(PersonArmUtil.MIN_MITER_DOT, dot));
91
+ const half = (widths[index] ?? widths.at(-1) ?? 1) / 2 * miter;
92
+ return {
93
+ left: [point[0] + normal[0] * half, point[1] + normal[1] * half],
94
+ right: [point[0] - normal[0] * half, point[1] - normal[1] * half],
95
+ radius: (widths[index] ?? widths.at(-1) ?? 1) / 2
96
+ };
97
+ });
98
+ const first = sides[0];
99
+ const end = sides[last];
100
+ if (!first || !end) {
101
+ return "";
102
+ }
103
+ const along = sides.map((side) => `L${round(side.left[0])} ${round(side.left[1])}`).join("");
104
+ const back = sides.map((side) => `L${round(side.right[0])} ${round(side.right[1])}`).reverse().join("");
105
+ const cap = (radius, to) => `A${round(radius)} ${round(radius)} 0 0 0 ${round(to[0])} ${round(to[1])}`;
106
+ return `<path d="M${round(first.left[0])} ${round(first.left[1])}${along}${cap(end.radius, end.right)}${back}${cap(first.radius, first.left)}Z" fill="${color}"/>`;
107
+ }
108
+ static foldOf(from, to, color) {
109
+ const round = (value) => PersonArmUtil.round(value);
110
+ const length = Math.hypot(to[0] - from[0], to[1] - from[1]) || 1;
111
+ const normal = [-(to[1] - from[1]) / length, (to[0] - from[0]) / length];
112
+ const half = PersonArmUtil.FOLD_HALF_WIDTH;
113
+ return `<path d="M${round(to[0] + normal[0] * half)} ${round(to[1] + normal[1] * half)} Q${round(to[0] + (to[0] - from[0]) / length)} ${round(to[1] + (to[1] - from[1]) / length)} ${round(to[0] - normal[0] * half)} ${round(to[1] - normal[1] * half)}" stroke="${color}" stroke-width="0.8" fill="none" stroke-linecap="round"/>`;
114
+ }
115
+ static armPath(shoulder, arm, colors, options) {
69
116
  const { elbow, hand } = arm;
70
- const stroke = 'fill="none" stroke-linecap="round" stroke-linejoin="round"';
117
+ const { isShortSleeve, hasFold } = options;
118
+ const fold = hasFold ? PersonArmUtil.foldOf(shoulder, elbow, ColorUtil.sh(colors.sleeve, -PersonArmUtil.FOLD_SHADE)) : "";
71
119
  if (!isShortSleeve) {
72
- return `<path d="M${round(shoulder[0])} ${round(shoulder[1])} L${round(elbow[0])} ${round(elbow[1])} L${round(hand[0])} ${round(hand[1])}" stroke="${colors.sleeve}" ${stroke} stroke-width="7"/>`;
120
+ return PersonArmUtil.taper([shoulder, elbow, hand], PersonArmUtil.SLEEVE_WIDTHS, colors.sleeve) + fold;
73
121
  }
74
122
  const split = PersonArmUtil.SHORT_SLEEVE_SPLIT;
75
123
  const middle = [
76
124
  shoulder[0] + (elbow[0] - shoulder[0]) * split,
77
125
  shoulder[1] + (elbow[1] - shoulder[1]) * split
78
126
  ];
79
- return `<path d="M${round(middle[0])} ${round(middle[1])} L${round(elbow[0])} ${round(elbow[1])} L${round(hand[0])} ${round(hand[1])}" stroke="${colors.skin}" ${stroke} stroke-width="6"/><path d="M${round(shoulder[0])} ${round(shoulder[1])} L${round(middle[0])} ${round(middle[1])}" stroke="${colors.sleeve}" ${stroke} stroke-width="8"/>`;
127
+ return PersonArmUtil.taper([middle, elbow, hand], PersonArmUtil.SKIN_WIDTHS, colors.skin) + PersonArmUtil.taper([shoulder, middle], PersonArmUtil.SHORT_SLEEVE_WIDTHS, colors.sleeve);
80
128
  }
81
129
  }
82
130
  export {
@@ -1,5 +1,6 @@
1
1
  import { ColorUtil } from "./ColorUtil.js";
2
2
  import { FallbackUtil } from "./FallbackUtil.js";
3
+ import { DetailUtil } from "./DetailUtil.js";
3
4
  import { IdUtil } from "./IdUtil.js";
4
5
  import { PersonArmUtil } from "./PersonArmUtil.js";
5
6
  class PersonHeadUtil {
@@ -92,7 +93,8 @@ class PersonHeadUtil {
92
93
  const style = FallbackUtil.nonEmpty(params.hair, "short");
93
94
  const builder = IdUtil.lookup(PersonHeadUtil.STYLE_TO_HAIR, style);
94
95
  const { backHair, front } = builder?.(hair, side) ?? { backHair: "", front: "" };
95
- const neck = `<rect x="-3" y="-85" width="6" height="7" fill="${ColorUtil.sh(skin, -0.12)}"/>`;
96
+ const neckSkin = ColorUtil.sh(skin, -0.12);
97
+ const neck = `<path d="M-3 -85 L3 -85 L3.8 -77.5 L-3.8 -77.5 Z" fill="${neckSkin}"/>` + (DetailUtil.rankOf(params.detail) >= 1 ? `<ellipse cx="0" cy="-79.4" rx="4.6" ry="1.8" fill="${ColorUtil.sh(skin, -0.28)}"/>` : "");
96
98
  if (isBack) {
97
99
  return neck + backHair + PersonHeadUtil.backOfHead(style, skin, hair);
98
100
  }
@@ -12,9 +12,20 @@ export interface PersonLook {
12
12
  gown: string | null;
13
13
  sleeve: string;
14
14
  isShortSleeve: boolean;
15
+ detail: number;
15
16
  }
16
17
  export declare class PersonOutfitUtil {
17
18
  private static readonly LAB_COAT;
19
+ private static readonly FOLD_DETAIL;
20
+ private static readonly OUTFIT_TO_HEM_KIND;
21
+ private static readonly BUILD_TO_HEM_KIND;
22
+ private static readonly LONG_HEMS;
23
+ private static readonly HEM_KIND_TO_PATH;
24
+ private static readonly OUTFIT_TO_COLLAR;
25
+ private static readonly HEM_SHADE;
26
+ private static readonly SOLE_LIGHTEN;
27
+ private static readonly LEG_TAPER;
28
+ private static readonly WALKING_LEG_WIDTHS;
18
29
  private static readonly HAT_NAME_TO_BUILDER;
19
30
  private static readonly OUTFIT_TO_TRAITS;
20
31
  private static readonly BOTTOM_TO_LEG_SHAPE;
@@ -27,6 +38,8 @@ export declare class PersonOutfitUtil {
27
38
  static lookOf(params: PersonParams, theme: Theme): PersonLook;
28
39
  private static legShapeOf;
29
40
  private static legColorOf;
41
+ static shoe(look: PersonLook, centerX: number, direction: number): string;
42
+ private static hem;
30
43
  static seatedLegs(look: PersonLook, facing: number): string;
31
44
  private static seatedSkirt;
32
45
  static seatedTorso(look: PersonLook, facing: number): string;
@@ -34,6 +47,9 @@ export declare class PersonOutfitUtil {
34
47
  private static walkingLegs;
35
48
  private static restingLegs;
36
49
  static standingTorso(look: PersonLook, params: PersonParams, isBack: boolean): string;
50
+ private static hemKindOf;
51
+ private static torsoDetails;
52
+ private static collar;
37
53
  private static baseTorso;
38
54
  private static upperLayers;
39
55
  private static gownLayer;
@@ -1,10 +1,35 @@
1
1
  import { BOTTOM_NAMES, OUTFIT_NAMES } from "../Protocols/PersonProtocol.js";
2
2
  import { ColorUtil } from "./ColorUtil.js";
3
3
  import { FallbackUtil } from "./FallbackUtil.js";
4
+ import { DetailUtil } from "./DetailUtil.js";
4
5
  import { IdUtil } from "./IdUtil.js";
6
+ import { PersonArmUtil } from "./PersonArmUtil.js";
5
7
  import { PersonHeadUtil } from "./PersonHeadUtil.js";
6
8
  class PersonOutfitUtil {
7
9
  static LAB_COAT = "#FBFBF8";
10
+ static FOLD_DETAIL = 2;
11
+ static OUTFIT_TO_HEM_KIND = { labcoat: "labcoat", dress: "none" };
12
+ static BUILD_TO_HEM_KIND = { heavy: "heavy" };
13
+ static LONG_HEMS = /* @__PURE__ */ new Set(["gown", "labcoat", "none"]);
14
+ static HEM_KIND_TO_PATH = {
15
+ gown: "M-18 -16.2 L18 -16.2 L18 -14 L-18 -14 Z",
16
+ labcoat: "M-15 -29.2 L15 -29.2 L15 -27 L-15 -27 Z",
17
+ none: "",
18
+ heavy: "M-13 -46.4 L13 -46.4 L13 -44 L-13 -44 Z",
19
+ standard: "M-12 -46.4 L12 -46.4 L12 -44 L-12 -44 Z"
20
+ };
21
+ static OUTFIT_TO_COLLAR = {
22
+ labcoat: () => {
23
+ const lapel = ColorUtil.sh(PersonOutfitUtil.LAB_COAT, -0.06);
24
+ return `<path d="M-6 -82 L0 -73 L-8.5 -66 Z M6 -82 L0 -73 L8.5 -66 Z" fill="${lapel}"/>`;
25
+ },
26
+ sweater: (look) => `<path d="M-6.2 -81.4 Q0 -75.8 6.2 -81.4" stroke="${ColorUtil.sh(look.top, -0.28)}" stroke-width="2.2" fill="none" stroke-linecap="round"/>`,
27
+ tshirt: (look) => `<path d="M-6.2 -81.4 Q0 -75.8 6.2 -81.4" stroke="${ColorUtil.sh(look.top, -0.28)}" stroke-width="1.1" fill="none" stroke-linecap="round"/><path d="M-4.6 -81 Q0 -77.4 4.6 -81" fill="${ColorUtil.sh(look.skin, -0.12)}"/>`
28
+ };
29
+ static HEM_SHADE = 0.2;
30
+ static SOLE_LIGHTEN = 0.3;
31
+ static LEG_TAPER = 0.4;
32
+ static WALKING_LEG_WIDTHS = [8.8, 6.4];
8
33
  static HAT_NAME_TO_BUILDER = {
9
34
  grad_cap: (look) => PersonOutfitUtil.graduationCap(look),
10
35
  cap: (look, params, side) => PersonOutfitUtil.cap(look, params, side)
@@ -34,8 +59,8 @@ class PersonOutfitUtil {
34
59
  };
35
60
  static BOTTOM_TO_STANDING_OVERLAY = {
36
61
  shorts: (look) => `<path d="M-11 -47 L11 -47 L12 -30 L1 -30 L0 -36 L-1 -30 L-12 -30 Z" fill="${look.bottomColor}"/><path d="M4 -47 L11 -47 L12 -30 L5 -30 Z" fill="${ColorUtil.sh(look.bottomColor, -0.12)}"/>`,
37
- skirt: (look) => `<path d="M-12 -48 L12 -48 L17 -27 L-17 -27 Z" fill="${look.bottomColor}"/><path d="M4 -48 L12 -48 L17 -27 L7 -27 Z" fill="${ColorUtil.sh(look.bottomColor, -0.12)}"/>`,
38
- dress: (look) => `<path d="M-12 -48 L12 -48 L18 -24 L-18 -24 Z" fill="${look.top}"/><path d="M4 -48 L12 -48 L18 -24 L7 -24 Z" fill="${ColorUtil.sh(look.top, -0.12)}"/>`
62
+ skirt: (look) => `<path d="M-12 -48 L12 -48 L17 -27 L-17 -27 Z" fill="${look.bottomColor}"/>` + PersonOutfitUtil.hem(look, "M-17.2 -29.2 L17.2 -29.2 L17 -27 L-17 -27 Z", look.bottomColor) + `<path d="M4 -48 L12 -48 L17 -27 L7 -27 Z" fill="${ColorUtil.sh(look.bottomColor, -0.12)}"/>`,
63
+ dress: (look) => `<path d="M-12 -48 L12 -48 L18 -24 L-18 -24 Z" fill="${look.top}"/>` + PersonOutfitUtil.hem(look, "M-18.2 -26.2 L18.2 -26.2 L18 -24 L-18 -24 Z", look.top) + `<path d="M4 -48 L12 -48 L18 -24 L7 -24 Z" fill="${ColorUtil.sh(look.top, -0.12)}"/>`
39
64
  };
40
65
  static colorOf(theme, name, fallback) {
41
66
  if (!name) {
@@ -67,7 +92,8 @@ class PersonOutfitUtil {
67
92
  shoes: PersonOutfitUtil.colorOf(theme, params.shoes, theme.ink),
68
93
  gown,
69
94
  sleeve: traits?.isLabCoat ? PersonOutfitUtil.LAB_COAT : gown ?? jacket ?? top,
70
- isShortSleeve: !jacket && traits?.isTshirt === true
95
+ isShortSleeve: !jacket && traits?.isTshirt === true,
96
+ detail: DetailUtil.rankOf(params.detail)
71
97
  };
72
98
  }
73
99
  static legShapeOf(look) {
@@ -76,10 +102,23 @@ class PersonOutfitUtil {
76
102
  static legColorOf(look) {
77
103
  return PersonOutfitUtil.legShapeOf(look).isCovered ? look.bottomColor : look.skin;
78
104
  }
105
+ static shoe(look, centerX, direction) {
106
+ const { shoes, detail } = look;
107
+ const round = (value) => PersonArmUtil.round(value);
108
+ const heel = round(centerX - direction * 5);
109
+ const toe = round(centerX + direction * 6);
110
+ const tip = round(toe + direction * 1.2);
111
+ const base = `<path d="M${heel} -5.4 L${heel} -0.8 L${round(toe - direction * 0.5)} -0.8 Q${tip} -0.8 ${tip} -2.8 Q${round(toe - direction)} -5.6 ${round(centerX)} -5.6 Z" fill="${shoes}"/>`;
112
+ const sole = `<path d="M${heel} -1.8 L${tip} -1.8 L${round(toe + direction * 0.7)} -0.5 L${heel} -0.5 Z" fill="${ColorUtil.sh(shoes, PersonOutfitUtil.SOLE_LIGHTEN)}"/>`;
113
+ return base + (detail >= 1 ? sole : "");
114
+ }
115
+ static hem(look, path, color) {
116
+ return look.detail >= 1 ? `<path d="${path}" fill="${ColorUtil.sh(color, -PersonOutfitUtil.HEM_SHADE)}"/>` : "";
117
+ }
79
118
  static seatedLegs(look, facing) {
80
- const { shoes } = look;
81
119
  const legColor = PersonOutfitUtil.legColorOf(look);
82
- const legs = `<path d="M0 -45 L${facing * 24} -45 L${facing * 24} -4" stroke="${legColor}" stroke-width="11" fill="none" stroke-linejoin="round"/><path d="M${facing * 2} -41 L${facing * 24} -41" stroke="${ColorUtil.sh(legColor, -0.12)}" stroke-width="3" fill="none"/><path d="M${facing * 21} -3 L${facing * 32} -3 Q${facing * 32} -8 ${facing * 25} -8 L${facing * 21} -8 Z" fill="${shoes}"/>`;
120
+ const knee = [facing * 24, -45];
121
+ const legs = PersonArmUtil.taper([[0, -45], knee, [facing * 24, -4]], [11.5, 10.5, 8.5], legColor) + `<path d="M${facing * 2} -41 L${facing * 24} -41" stroke="${ColorUtil.sh(legColor, -0.12)}" stroke-width="3" fill="none"/><g transform="translate(0 -2.2)">${PersonOutfitUtil.shoe(look, facing * 26, facing)}</g>`;
83
122
  return legs + (IdUtil.lookup(PersonOutfitUtil.BOTTOM_TO_SEATED_OVERLAY, look.bottom)?.(look, facing) ?? "");
84
123
  }
85
124
  static seatedSkirt(look, facing, fill) {
@@ -88,23 +127,60 @@ class PersonOutfitUtil {
88
127
  static seatedTorso(look, facing) {
89
128
  const { jacket, top } = look;
90
129
  const torsoColor = jacket ?? top;
91
- return `<rect x="-10" y="-81" width="20" height="40" rx="7" fill="${torsoColor}"/><path d="M${-facing * 10} -74 Q${-facing * 10} -81 ${-facing * 4} -81 L${-facing * 3} -81 L${-facing * 3} -41 L${-facing * 10} -41 Z" fill="${ColorUtil.sh(torsoColor, -0.13)}"/>` + (jacket ? `<path d="M${facing * 5} -80 L${facing * 9} -76 L${facing * 9} -44 L${facing * 4} -44 Z" fill="${top}"/>` : "");
130
+ const hem = PersonOutfitUtil.hem(look, "M-10 -43.4 L10 -43.4 L10 -41 L-10 -41 Z", torsoColor);
131
+ const fold = look.detail >= PersonOutfitUtil.FOLD_DETAIL ? `<path d="M${-facing * 8} -52 Q${-facing * 2} -49.5 ${facing * 6} -52.5" stroke="${ColorUtil.sh(torsoColor, -0.22)}" stroke-width="0.9" fill="none" stroke-linecap="round"/>` : "";
132
+ return `<rect x="-10" y="-81" width="20" height="40" rx="7" fill="${torsoColor}"/><path d="M${-facing * 10} -74 Q${-facing * 10} -81 ${-facing * 4} -81 L${-facing * 3} -81 L${-facing * 3} -41 L${-facing * 10} -41 Z" fill="${ColorUtil.sh(torsoColor, -0.13)}"/>` + (jacket ? `<path d="M${facing * 5} -80 L${facing * 9} -76 L${facing * 9} -44 L${facing * 4} -44 Z" fill="${top}"/>` : "") + hem + fold;
92
133
  }
93
134
  static standingLegs(look, isWalking) {
94
- const { shoes } = look;
95
135
  const legColor = PersonOutfitUtil.legColorOf(look);
96
136
  const legWidth = PersonOutfitUtil.legShapeOf(look).width;
97
- const legs = isWalking ? PersonOutfitUtil.walkingLegs(legColor, shoes) : PersonOutfitUtil.restingLegs(legColor, shoes, legWidth);
137
+ const isCovered = PersonOutfitUtil.legShapeOf(look).isCovered;
138
+ const legs = isWalking ? PersonOutfitUtil.walkingLegs(look, legColor) : PersonOutfitUtil.restingLegs(look, { legColor, legWidth, isCovered });
98
139
  return legs + (IdUtil.lookup(PersonOutfitUtil.BOTTOM_TO_STANDING_OVERLAY, look.bottom)?.(look) ?? "");
99
140
  }
100
- static walkingLegs(legColor, shoes) {
101
- return `<path d="M-3 -45 L-12 -3" stroke="${legColor}" stroke-width="8" stroke-linecap="round"/><path d="M3 -45 L11 -3" stroke="${ColorUtil.sh(legColor, -0.12)}" stroke-width="8" stroke-linecap="round"/><ellipse cx="-14" cy="-2.5" rx="5.5" ry="2.8" fill="${shoes}"/><ellipse cx="14" cy="-2.5" rx="5.5" ry="2.8" fill="${shoes}"/>`;
141
+ static walkingLegs(look, legColor) {
142
+ return PersonArmUtil.taper([[-3, -45], [-12, -3]], PersonOutfitUtil.WALKING_LEG_WIDTHS, legColor) + PersonArmUtil.taper([[3, -45], [11, -3]], PersonOutfitUtil.WALKING_LEG_WIDTHS, ColorUtil.sh(legColor, -0.12)) + PersonOutfitUtil.shoe(look, -14, -1) + PersonOutfitUtil.shoe(look, 14, 1);
102
143
  }
103
- static restingLegs(legColor, shoes, legWidth) {
104
- return `<rect x="${-1 - legWidth}" y="-47" width="${legWidth}" height="45" rx="3" fill="${legColor}"/><rect x="1" y="-47" width="${legWidth}" height="45" rx="3" fill="${legColor}"/><rect x="${1 + legWidth * 0.45}" y="-47" width="${legWidth * 0.55}" height="45" rx="2" fill="${ColorUtil.sh(legColor, -0.12)}"/><ellipse cx="-5.5" cy="-2.5" rx="5.5" ry="2.8" fill="${shoes}"/><ellipse cx="5.5" cy="-2.5" rx="5.5" ry="2.8" fill="${shoes}"/>`;
144
+ static restingLegs(look, leg) {
145
+ const { legColor, legWidth, isCovered } = leg;
146
+ const round = (value) => PersonArmUtil.round(value);
147
+ const bottomInset = legWidth * PersonOutfitUtil.LEG_TAPER;
148
+ const left = -1 - legWidth / 2;
149
+ const right = 1 + legWidth / 2;
150
+ const tapered = (center, color) => `<path d="M${round(center - legWidth / 2)} -47 L${round(center + legWidth / 2)} -47 L${round(center + bottomInset)} -2 L${round(center - bottomInset)} -2 Z" fill="${color}"/>`;
151
+ const shade = `<path d="M${round(1 + legWidth * 0.45)} -47 L${round(1 + legWidth)} -47 L${round(right + bottomInset)} -2 L${round(right - legWidth * 0.04)} -2 Z" fill="${ColorUtil.sh(legColor, -0.12)}"/>`;
152
+ const cuff = isCovered ? PersonOutfitUtil.hem(look, `M${round(left - bottomInset - 0.4)} -9.6 L${round(left + bottomInset + 0.4)} -9.6 L${round(left + bottomInset)} -7.2 L${round(left - bottomInset)} -7.2 Z`, legColor) + PersonOutfitUtil.hem(look, `M${round(right - bottomInset - 0.4)} -9.6 L${round(right + bottomInset + 0.4)} -9.6 L${round(right + bottomInset)} -7.2 L${round(right - bottomInset)} -7.2 Z`, legColor) : "";
153
+ return tapered(left, legColor) + tapered(right, legColor) + shade + cuff + PersonOutfitUtil.shoe(look, -5.5, -1) + PersonOutfitUtil.shoe(look, 5.5, 1);
105
154
  }
106
155
  static standingTorso(look, params, isBack) {
107
- return PersonOutfitUtil.baseTorso(look, params.build === "heavy") + PersonOutfitUtil.upperLayers(look, isBack) + PersonOutfitUtil.gownLayer(look, params, isBack) + PersonOutfitUtil.labCoatLayer(look, isBack);
156
+ return PersonOutfitUtil.baseTorso(look, params.build === "heavy") + PersonOutfitUtil.upperLayers(look, isBack) + PersonOutfitUtil.gownLayer(look, params, isBack) + PersonOutfitUtil.labCoatLayer(look, isBack) + PersonOutfitUtil.torsoDetails(look, params, isBack);
157
+ }
158
+ static hemKindOf(look, params) {
159
+ if (look.gown) {
160
+ return "gown";
161
+ }
162
+ const named = IdUtil.lookup(PersonOutfitUtil.OUTFIT_TO_HEM_KIND, look.outfit);
163
+ if (named) {
164
+ return named;
165
+ }
166
+ return IdUtil.lookup(PersonOutfitUtil.BUILD_TO_HEM_KIND, params.build) ?? "standard";
167
+ }
168
+ static torsoDetails(look, params, isBack) {
169
+ const torsoColor = look.jacket ?? look.top;
170
+ const kind = PersonOutfitUtil.hemKindOf(look, params);
171
+ const kindToColor = { gown: look.gown ?? torsoColor, labcoat: PersonOutfitUtil.LAB_COAT };
172
+ const hemColor = IdUtil.lookup(kindToColor, kind) ?? torsoColor;
173
+ const hem = PersonOutfitUtil.hem(look, PersonOutfitUtil.HEM_KIND_TO_PATH[kind], hemColor);
174
+ const hasFold = look.detail >= PersonOutfitUtil.FOLD_DETAIL && !PersonOutfitUtil.LONG_HEMS.has(kind);
175
+ const fold = hasFold ? `<path d="M-9 -54 Q-2 -51.5 6 -54.5" stroke="${ColorUtil.sh(torsoColor, -0.22)}" stroke-width="0.9" fill="none" stroke-linecap="round"/>` : "";
176
+ const hasCollar = !isBack && look.detail >= 1;
177
+ return hem + fold + (hasCollar ? PersonOutfitUtil.collar(look) : "");
178
+ }
179
+ static collar(look) {
180
+ if (look.jacket) {
181
+ return `<path d="M-6 -82 L-1 -76 L-7.5 -71 Z M6 -82 L1 -76 L7.5 -71 Z" fill="${ColorUtil.sh(look.jacket, -0.1)}"/>`;
182
+ }
183
+ return IdUtil.lookup(PersonOutfitUtil.OUTFIT_TO_COLLAR, look.outfit)?.(look) ?? "";
108
184
  }
109
185
  static baseTorso(look, isHeavy) {
110
186
  const torsoColor = look.jacket ?? look.top;
@@ -12,6 +12,7 @@ export declare class PersonUtil {
12
12
  seated: ("drinking" | "reading" | "sitting" | "typing")[];
13
13
  };
14
14
  private static readonly AGE_TO_SCALE;
15
+ private static readonly BODY_TO_SCALE;
15
16
  private static readonly ADULT_SCALE;
16
17
  private static readonly BUILD_TO_WIDTH;
17
18
  private static readonly MIN_HEIGHT;
@@ -20,6 +21,7 @@ export declare class PersonUtil {
20
21
  private static readonly POSE_TO_GAZE;
21
22
  private static readonly FACING_TO_SIDE;
22
23
  private static readonly POSE_TO_SEATED_PROP;
24
+ private static readonly FOLD_DETAIL;
23
25
  private static readonly SEATED_HEAD_TILT;
24
26
  private static readonly STANDING_HEAD_TILT;
25
27
  private static readonly FRONT_HEAD_TILT;
@@ -40,6 +40,12 @@ class PersonUtil {
40
40
  adult: { bx: 1, by: 1, hs: 1 },
41
41
  elder: { bx: 1, by: 0.95, hs: 1 }
42
42
  };
43
+ // Why: head to body about 1:2.3 (chibi), 1:4.3 (standard, the original drawing) and 1:6 (long, the editorial look).
44
+ static BODY_TO_SCALE = {
45
+ chibi: { bx: 1.12, by: 0.62, hs: 1.5 },
46
+ standard: { bx: 1, by: 1, hs: 1 },
47
+ long: { bx: 0.86, by: 1.4, hs: 0.86 }
48
+ };
43
49
  static ADULT_SCALE = { bx: 1, by: 1, hs: 1 };
44
50
  static BUILD_TO_WIDTH = {
45
51
  slim: 0.88,
@@ -78,6 +84,7 @@ class PersonUtil {
78
84
  reading: (hand, facing, theme) => PersonUtil.book(hand, facing, theme),
79
85
  drinking: (hand, facing, theme) => PersonUtil.cup(hand, facing, theme)
80
86
  };
87
+ static FOLD_DETAIL = 2;
81
88
  static SEATED_HEAD_TILT = 7;
82
89
  static STANDING_HEAD_TILT = 6;
83
90
  static FRONT_HEAD_TILT = 4;
@@ -87,7 +94,8 @@ class PersonUtil {
87
94
  const requested = Number(params.height) || 1;
88
95
  const heightFactor = Math.max(PersonUtil.MIN_HEIGHT, Math.min(PersonUtil.MAX_HEIGHT, requested));
89
96
  const width = IdUtil.lookup(PersonUtil.BUILD_TO_WIDTH, params.build) ?? 1;
90
- return { bx: age.bx * width, by: age.by * heightFactor, hs: age.hs };
97
+ const body = IdUtil.lookup(PersonUtil.BODY_TO_SCALE, params.body) ?? PersonUtil.ADULT_SCALE;
98
+ return { bx: age.bx * width * body.bx, by: age.by * heightFactor * body.by, hs: age.hs * body.hs };
91
99
  }
92
100
  static gazeOf(params, pose, facing = 1) {
93
101
  if (Array.isArray(params.gaze)) {
@@ -132,8 +140,9 @@ class PersonUtil {
132
140
  const frontArm = PersonArmUtil.ik(shoulder, [target[0] * facing, target[1]], facing, "down");
133
141
  const backSkin = ColorUtil.sh(skin, -0.15);
134
142
  const backColors = { sleeve: ColorUtil.sh(sleeve, -0.18), skin: backSkin };
135
- const armsBack = PersonArmUtil.armPath(shoulder, backArm, backColors, isShortSleeve) + PersonArmUtil.hand(backArm.hand, backSkin, false, backArm.elbow);
136
- const armsFront = PersonArmUtil.armPath(shoulder, frontArm, { sleeve, skin }, isShortSleeve) + PersonArmUtil.hand(frontArm.hand, skin, false, frontArm.elbow);
143
+ const armOptions = { isShortSleeve, hasFold: look.detail >= PersonUtil.FOLD_DETAIL };
144
+ const armsBack = PersonArmUtil.armPath(shoulder, backArm, backColors, armOptions) + PersonArmUtil.hand(backArm.hand, backSkin, false, backArm.elbow);
145
+ const armsFront = PersonArmUtil.armPath(shoulder, frontArm, { sleeve, skin }, armOptions) + PersonArmUtil.hand(frontArm.hand, skin, false, frontArm.elbow);
137
146
  const gaze = PersonUtil.gazeOf(params, pose, facing);
138
147
  const head = PersonHeadUtil.head(params, theme, { side: facing, isBack: false, gaze });
139
148
  const legs = PersonOutfitUtil.seatedLegs(look, facing);
@@ -171,7 +180,8 @@ class PersonUtil {
171
180
  const colors = { sleeve, skin };
172
181
  const isLeftOpen = Boolean(targets.isLeftOpen);
173
182
  const isRightOpen = Boolean(targets.isRightOpen);
174
- const arms = PersonArmUtil.armPath(leftShoulder, left, colors, isShortSleeve) + PersonArmUtil.hand(left.hand, skin, isLeftOpen, left.elbow) + PersonArmUtil.armPath(rightShoulder, right, colors, isShortSleeve) + PersonArmUtil.hand(right.hand, skin, isRightOpen, right.elbow);
183
+ const armOptions = { isShortSleeve, hasFold: look.detail >= PersonUtil.FOLD_DETAIL };
184
+ const arms = PersonArmUtil.armPath(leftShoulder, left, colors, armOptions) + PersonArmUtil.hand(left.hand, skin, isLeftOpen, left.elbow) + PersonArmUtil.armPath(rightShoulder, right, colors, armOptions) + PersonArmUtil.hand(right.hand, skin, isRightOpen, right.elbow);
175
185
  if (isBack) {
176
186
  const head2 = PersonHeadUtil.head(params, theme, { side: 0, isBack: true, gaze: [0, 0] });
177
187
  const backSvg = PersonUtil.bodyGroup(scale, legs + torso + arms) + PersonUtil.headGroup(scale, head2 + hat);
@@ -30,6 +30,7 @@ class SanitizeUtil {
30
30
  "feComponentTransfer",
31
31
  "feComposite",
32
32
  "feConvolveMatrix",
33
+ "feDisplacementMap",
33
34
  "feDropShadow",
34
35
  "feFlood",
35
36
  "feFuncA",
@@ -16,6 +16,14 @@ export interface EllipsePaint {
16
16
  fill: string;
17
17
  extra?: string;
18
18
  }
19
+ export interface BlobOptions {
20
+ lobes?: number;
21
+ wobble?: number;
22
+ seed?: number;
23
+ squash?: number;
24
+ fill?: string;
25
+ extra?: string;
26
+ }
19
27
  export declare class ShapeUtil {
20
28
  private static readonly ROUNDING_FACTOR;
21
29
  private static readonly HALF_TURN_DEGREES;
@@ -23,6 +31,7 @@ export declare class ShapeUtil {
23
31
  static round(value: number): number;
24
32
  static toRadians(degrees: number): number;
25
33
  static circle(centerX: number, centerY: number, radius: number, fill: string, extra?: string): string;
34
+ static blob(centerX: number, centerY: number, radius: number, options?: BlobOptions): string;
26
35
  static rect(...[posX, posY, width, height, fill, style]: RectArguments): string;
27
36
  static ellipse(centerX: number, centerY: number, radiusX: number, radiusY: number, paint: string | EllipsePaint): string;
28
37
  static shadow(theme: Theme, radiusX: number, radiusY?: number): string;
@@ -1,3 +1,4 @@
1
+ import { SeedUtil } from "./SeedUtil.js";
1
2
  class ShapeUtil {
2
3
  static ROUNDING_FACTOR = 100;
3
4
  static HALF_TURN_DEGREES = 180;
@@ -13,6 +14,31 @@ class ShapeUtil {
13
14
  const cy = ShapeUtil.round(centerY);
14
15
  return `<circle cx="${cx}" cy="${cy}" r="${ShapeUtil.round(radius)}" fill="${fill}" ${extra}/>`;
15
16
  }
17
+ static blob(centerX, centerY, radius, options = {}) {
18
+ const { lobes = 5, wobble = 0.08, seed = 1, squash = 1, fill = "#000", extra = "" } = options;
19
+ const random = SeedUtil.sequence(seed + lobes * 7919);
20
+ const phaseA = random() * Math.PI * 2;
21
+ const phaseB = random() * Math.PI * 2;
22
+ const count = lobes * 4;
23
+ const points = [];
24
+ for (let index = 0; index < count; index++) {
25
+ const angle = index / count * Math.PI * 2;
26
+ const wave = 0.65 * Math.sin(lobes * angle + phaseA) + 0.35 * Math.sin((lobes * 2 + 1) * angle + phaseB);
27
+ const length = radius * (1 + wobble * wave);
28
+ points.push([centerX + Math.cos(angle) * length * squash, centerY + Math.sin(angle) * length]);
29
+ }
30
+ const at = (index) => points[(index + count) % count] ?? [centerX, centerY];
31
+ const start = at(0);
32
+ let path = `M${ShapeUtil.round(start[0])} ${ShapeUtil.round(start[1])}`;
33
+ for (let index = 0; index < count; index++) {
34
+ const [before, from, to, after] = [at(index - 1), at(index), at(index + 1), at(index + 2)];
35
+ const c1 = [from[0] + (to[0] - before[0]) / 6, from[1] + (to[1] - before[1]) / 6];
36
+ const c2 = [to[0] - (after[0] - from[0]) / 6, to[1] - (after[1] - from[1]) / 6];
37
+ const parts = [c1[0], c1[1], c2[0], c2[1], to[0], to[1]].map((value) => ShapeUtil.round(value ?? 0));
38
+ path += `C${parts.join(" ")}`;
39
+ }
40
+ return `<path d="${path}Z" fill="${fill}" ${extra}/>`;
41
+ }
16
42
  static rect(...[posX, posY, width, height, fill, style = {}]) {
17
43
  const { rx = 0, extra = "" } = style;
18
44
  const column = ShapeUtil.round(posX);
@@ -0,0 +1,17 @@
1
+ export interface TypesettingOptions {
2
+ readonly wrap?: number;
3
+ readonly hasBalance?: boolean;
4
+ }
5
+ export interface TextRange {
6
+ readonly start: number;
7
+ readonly length: number;
8
+ }
9
+ export declare class TypesettingUtil {
10
+ private static readonly DEFAULT_LINE_COUNT;
11
+ private static readonly REGEX_SPECIAL_CHARS;
12
+ static splitLines(content: string, options?: TypesettingOptions): string[];
13
+ private static resolveLineCount;
14
+ static balancePartition(words: readonly string[], targetLineCount: number): string[];
15
+ private static findBestPartition;
16
+ static emphasisRanges(line: string, words?: readonly string[]): TextRange[];
17
+ }