@open-pencil/scene-graph 0.17.0-beta.3 → 0.17.0-beta.5

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 (283) hide show
  1. package/dist/arrays.d.ts +17 -0
  2. package/dist/arrays.d.ts.map +1 -0
  3. package/dist/arrays.js +38 -0
  4. package/dist/arrays.js.map +1 -0
  5. package/dist/buffered-events.js +1 -1
  6. package/dist/buffered-events.js.map +1 -1
  7. package/dist/clipping.d.ts +7 -1
  8. package/dist/clipping.d.ts.map +1 -1
  9. package/dist/clipping.js +23 -19
  10. package/dist/clipping.js.map +1 -1
  11. package/dist/components/index.d.ts +2 -2
  12. package/dist/components/index.js +2 -2
  13. package/dist/components/properties.d.ts +1 -3
  14. package/dist/components/properties.d.ts.map +1 -1
  15. package/dist/components/properties.js +2 -9
  16. package/dist/components/properties.js.map +1 -1
  17. package/dist/corners.d.ts +22 -0
  18. package/dist/corners.d.ts.map +1 -0
  19. package/dist/corners.js +52 -0
  20. package/dist/corners.js.map +1 -0
  21. package/dist/css/grid.d.ts +4 -1
  22. package/dist/css/grid.d.ts.map +1 -1
  23. package/dist/css/grid.js +16 -7
  24. package/dist/css/grid.js.map +1 -1
  25. package/dist/css/index.d.ts +2 -2
  26. package/dist/css/index.js +2 -2
  27. package/dist/css/values.d.ts +6 -1
  28. package/dist/css/values.d.ts.map +1 -1
  29. package/dist/font-style.d.ts +2 -1
  30. package/dist/font-style.d.ts.map +1 -1
  31. package/dist/font-style.js +31 -6
  32. package/dist/font-style.js.map +1 -1
  33. package/dist/geometry.d.ts +68 -3
  34. package/dist/geometry.d.ts.map +1 -1
  35. package/dist/geometry.js +155 -5
  36. package/dist/geometry.js.map +1 -1
  37. package/dist/gradient.d.ts +9 -2
  38. package/dist/gradient.d.ts.map +1 -1
  39. package/dist/gradient.js +29 -1
  40. package/dist/gradient.js.map +1 -1
  41. package/dist/graph.d.ts +4 -0
  42. package/dist/graph.d.ts.map +1 -1
  43. package/dist/graph.js +30 -4
  44. package/dist/graph.js.map +1 -1
  45. package/dist/group-bounds.d.ts.map +1 -1
  46. package/dist/group-bounds.js +4 -3
  47. package/dist/group-bounds.js.map +1 -1
  48. package/dist/guides.d.ts +11 -2
  49. package/dist/guides.d.ts.map +1 -1
  50. package/dist/guides.js +30 -1
  51. package/dist/guides.js.map +1 -1
  52. package/dist/hit-test.d.ts.map +1 -1
  53. package/dist/hit-test.js +57 -5
  54. package/dist/hit-test.js.map +1 -1
  55. package/dist/icons/fit.d.ts +17 -0
  56. package/dist/icons/fit.d.ts.map +1 -0
  57. package/dist/icons/fit.js +21 -0
  58. package/dist/icons/fit.js.map +1 -0
  59. package/dist/icons/glyph.d.ts.map +1 -1
  60. package/dist/icons/glyph.js +5 -4
  61. package/dist/icons/glyph.js.map +1 -1
  62. package/dist/icons/index.d.ts +2 -1
  63. package/dist/icons/index.js +2 -1
  64. package/dist/images.d.ts +14 -4
  65. package/dist/images.d.ts.map +1 -1
  66. package/dist/images.js +45 -5
  67. package/dist/images.js.map +1 -1
  68. package/dist/instances/assignments.js +39 -6
  69. package/dist/instances/assignments.js.map +1 -1
  70. package/dist/instances/index.d.ts.map +1 -1
  71. package/dist/instances/index.js +39 -2
  72. package/dist/instances/index.js.map +1 -1
  73. package/dist/instances/kept-overrides.js +2 -2
  74. package/dist/instances/kept-overrides.js.map +1 -1
  75. package/dist/instances/matching.js +68 -0
  76. package/dist/instances/matching.js.map +1 -0
  77. package/dist/instances/overrides.d.ts +4 -1
  78. package/dist/instances/overrides.d.ts.map +1 -1
  79. package/dist/instances/overrides.js +13 -1
  80. package/dist/instances/overrides.js.map +1 -1
  81. package/dist/instances/protection.js +67 -0
  82. package/dist/instances/protection.js.map +1 -0
  83. package/dist/instances/swap.js +7 -5
  84. package/dist/instances/swap.js.map +1 -1
  85. package/dist/instances/sync.js +10 -116
  86. package/dist/instances/sync.js.map +1 -1
  87. package/dist/layout/guides.d.ts +17 -1
  88. package/dist/layout/guides.d.ts.map +1 -1
  89. package/dist/layout/guides.js +31 -11
  90. package/dist/layout/guides.js.map +1 -1
  91. package/dist/layout/index.d.ts +4 -2
  92. package/dist/layout/index.js +4 -2
  93. package/dist/layout/limits.d.ts +40 -0
  94. package/dist/layout/limits.d.ts.map +1 -0
  95. package/dist/layout/limits.js +54 -0
  96. package/dist/layout/limits.js.map +1 -0
  97. package/dist/layout/sizing.d.ts.map +1 -1
  98. package/dist/layout/sizing.js +0 -1
  99. package/dist/layout/sizing.js.map +1 -1
  100. package/dist/layout/spacing.d.ts +10 -0
  101. package/dist/layout/spacing.d.ts.map +1 -0
  102. package/dist/layout/spacing.js +12 -0
  103. package/dist/layout/spacing.js.map +1 -0
  104. package/dist/masks.d.ts +28 -0
  105. package/dist/masks.d.ts.map +1 -0
  106. package/dist/masks.js +53 -0
  107. package/dist/masks.js.map +1 -0
  108. package/dist/matrix.d.ts +2 -1
  109. package/dist/matrix.d.ts.map +1 -1
  110. package/dist/matrix.js +14 -1
  111. package/dist/matrix.js.map +1 -1
  112. package/dist/node-defaults.d.ts +9 -1
  113. package/dist/node-defaults.d.ts.map +1 -1
  114. package/dist/node-defaults.js +16 -1
  115. package/dist/node-defaults.js.map +1 -1
  116. package/dist/outline/flatten.d.ts.map +1 -1
  117. package/dist/outline/flatten.js +24 -17
  118. package/dist/outline/flatten.js.map +1 -1
  119. package/dist/outline/hit.d.ts +2 -8
  120. package/dist/outline/hit.d.ts.map +1 -1
  121. package/dist/outline/hit.js +16 -25
  122. package/dist/outline/hit.js.map +1 -1
  123. package/dist/outline/index.d.ts +3 -3
  124. package/dist/outline/index.js +3 -3
  125. package/dist/outline/shapes.d.ts +3 -1
  126. package/dist/outline/shapes.d.ts.map +1 -1
  127. package/dist/outline/shapes.js +18 -39
  128. package/dist/outline/shapes.js.map +1 -1
  129. package/dist/paints/index.d.ts +3 -1
  130. package/dist/paints/index.js +3 -1
  131. package/dist/paints/pattern.d.ts +13 -0
  132. package/dist/paints/pattern.d.ts.map +1 -0
  133. package/dist/paints/pattern.js +47 -0
  134. package/dist/paints/pattern.js.map +1 -0
  135. package/dist/paints/shows.d.ts +11 -0
  136. package/dist/paints/shows.d.ts.map +1 -0
  137. package/dist/paints/shows.js +16 -0
  138. package/dist/paints/shows.js.map +1 -0
  139. package/dist/paths/arc.d.ts +32 -0
  140. package/dist/paths/arc.d.ts.map +1 -0
  141. package/dist/paths/arc.js +49 -0
  142. package/dist/paths/arc.js.map +1 -0
  143. package/dist/paths/index.d.ts +5 -0
  144. package/dist/paths/index.js +5 -0
  145. package/dist/paths/network.d.ts +43 -0
  146. package/dist/paths/network.d.ts.map +1 -0
  147. package/dist/paths/network.js +249 -0
  148. package/dist/paths/network.js.map +1 -0
  149. package/dist/paths/sink.d.ts +20 -0
  150. package/dist/paths/sink.d.ts.map +1 -0
  151. package/dist/paths/sink.js +32 -0
  152. package/dist/paths/sink.js.map +1 -0
  153. package/dist/paths/smooth-corners.d.ts +25 -0
  154. package/dist/paths/smooth-corners.d.ts.map +1 -0
  155. package/dist/paths/smooth-corners.js +196 -0
  156. package/dist/paths/smooth-corners.js.map +1 -0
  157. package/dist/plugin-data/fields.d.ts +4 -0
  158. package/dist/plugin-data/fields.d.ts.map +1 -1
  159. package/dist/plugin-data/fields.js +2 -0
  160. package/dist/plugin-data/fields.js.map +1 -1
  161. package/dist/polygon.d.ts +1 -3
  162. package/dist/polygon.d.ts.map +1 -1
  163. package/dist/polygon.js +1 -16
  164. package/dist/polygon.js.map +1 -1
  165. package/dist/resize.d.ts.map +1 -1
  166. package/dist/resize.js +5 -5
  167. package/dist/resize.js.map +1 -1
  168. package/dist/scaling/node.d.ts.map +1 -1
  169. package/dist/scaling/node.js +25 -3
  170. package/dist/scaling/node.js.map +1 -1
  171. package/dist/text/auto-resize.d.ts +15 -0
  172. package/dist/text/auto-resize.d.ts.map +1 -0
  173. package/dist/text/auto-resize.js +23 -0
  174. package/dist/text/auto-resize.js.map +1 -0
  175. package/dist/text/index.d.ts +4 -3
  176. package/dist/text/index.js +4 -3
  177. package/dist/text/lengths.d.ts +6 -1
  178. package/dist/text/lengths.d.ts.map +1 -1
  179. package/dist/text/lengths.js +10 -1
  180. package/dist/text/lengths.js.map +1 -1
  181. package/dist/text/overflow.d.ts +14 -5
  182. package/dist/text/overflow.d.ts.map +1 -1
  183. package/dist/text/overflow.js +24 -6
  184. package/dist/text/overflow.js.map +1 -1
  185. package/dist/text/path.js +10 -0
  186. package/dist/text/path.js.map +1 -0
  187. package/dist/text/picture.js +5 -5
  188. package/dist/text/picture.js.map +1 -1
  189. package/dist/transfer/dependencies.d.ts.map +1 -1
  190. package/dist/transfer/dependencies.js +3 -2
  191. package/dist/transfer/dependencies.js.map +1 -1
  192. package/dist/transfer/nodes.js +2 -1
  193. package/dist/transfer/nodes.js.map +1 -1
  194. package/dist/types.d.ts +21 -8
  195. package/dist/types.d.ts.map +1 -1
  196. package/dist/types.js.map +1 -1
  197. package/dist/variables/index.d.ts +4 -3
  198. package/dist/variables/index.d.ts.map +1 -1
  199. package/dist/variables/index.js +4 -3
  200. package/dist/variables/index.js.map +1 -1
  201. package/dist/variables/lookup.d.ts +20 -0
  202. package/dist/variables/lookup.d.ts.map +1 -0
  203. package/dist/variables/lookup.js +34 -0
  204. package/dist/variables/lookup.js.map +1 -0
  205. package/dist/variables/paints.d.ts +35 -4
  206. package/dist/variables/paints.d.ts.map +1 -1
  207. package/dist/variables/paints.js +67 -16
  208. package/dist/variables/paints.js.map +1 -1
  209. package/dist/variables/resolution.d.ts +3 -1
  210. package/dist/variables/resolution.d.ts.map +1 -1
  211. package/dist/variables/resolution.js +8 -3
  212. package/dist/variables/resolution.js.map +1 -1
  213. package/dist/variables/subtree.js +1 -1
  214. package/dist/variables/subtree.js.map +1 -1
  215. package/dist/vector-network.d.ts.map +1 -1
  216. package/dist/vector-network.js +12 -76
  217. package/dist/vector-network.js.map +1 -1
  218. package/package.json +25 -1
  219. package/src/arrays.ts +37 -0
  220. package/src/buffered-events.ts +2 -1
  221. package/src/clipping.ts +11 -8
  222. package/src/components/properties.ts +1 -13
  223. package/src/corners.ts +93 -0
  224. package/src/css/grid.ts +21 -7
  225. package/src/css/index.ts +1 -1
  226. package/src/font-style.ts +38 -4
  227. package/src/geometry.ts +219 -6
  228. package/src/gradient.ts +23 -1
  229. package/src/graph.ts +22 -4
  230. package/src/group-bounds.ts +7 -3
  231. package/src/guides.ts +26 -1
  232. package/src/hit-test.ts +68 -10
  233. package/src/icons/fit.ts +24 -0
  234. package/src/icons/glyph.ts +5 -4
  235. package/src/icons/index.ts +1 -0
  236. package/src/images.ts +67 -7
  237. package/src/instances/assignments.ts +65 -7
  238. package/src/instances/index.ts +53 -4
  239. package/src/instances/kept-overrides.ts +2 -5
  240. package/src/instances/matching.ts +101 -0
  241. package/src/instances/overrides.ts +18 -0
  242. package/src/instances/protection.ts +103 -0
  243. package/src/instances/swap.ts +11 -9
  244. package/src/instances/sync.ts +11 -184
  245. package/src/layout/guides.ts +42 -9
  246. package/src/layout/index.ts +2 -0
  247. package/src/layout/limits.ts +64 -0
  248. package/src/layout/sizing.ts +0 -2
  249. package/src/layout/spacing.ts +11 -0
  250. package/src/masks.ts +51 -0
  251. package/src/matrix.ts +15 -2
  252. package/src/node-defaults.ts +23 -3
  253. package/src/outline/flatten.ts +30 -18
  254. package/src/outline/hit.ts +16 -33
  255. package/src/outline/index.ts +2 -2
  256. package/src/outline/shapes.ts +19 -36
  257. package/src/paints/index.ts +2 -0
  258. package/src/paints/pattern.ts +45 -0
  259. package/src/paints/shows.ts +13 -0
  260. package/src/paths/arc.ts +59 -0
  261. package/src/paths/index.ts +4 -0
  262. package/src/paths/network.ts +334 -0
  263. package/src/paths/sink.ts +50 -0
  264. package/src/paths/smooth-corners.ts +356 -0
  265. package/src/plugin-data/fields.ts +2 -0
  266. package/src/polygon.ts +0 -17
  267. package/src/resize.ts +6 -7
  268. package/src/scaling/node.ts +29 -3
  269. package/src/text/auto-resize.ts +25 -0
  270. package/src/text/index.ts +1 -0
  271. package/src/text/lengths.ts +11 -0
  272. package/src/text/overflow.ts +32 -6
  273. package/src/text/path.ts +13 -0
  274. package/src/text/picture.ts +5 -5
  275. package/src/transfer/dependencies.ts +3 -2
  276. package/src/transfer/nodes.ts +2 -1
  277. package/src/types.ts +25 -8
  278. package/src/variables/index.ts +1 -0
  279. package/src/variables/lookup.ts +31 -0
  280. package/src/variables/paints.ts +101 -20
  281. package/src/variables/resolution.ts +14 -2
  282. package/src/variables/subtree.ts +1 -1
  283. package/src/vector-network.ts +17 -138
@@ -0,0 +1,196 @@
1
+ import { minOf } from "../arrays.js";
2
+ //#region src/paths/smooth-corners.ts
3
+ function smoothCornerRadii(node, width, height, spread) {
4
+ const radius = (value) => Math.max(0, value + spread);
5
+ const radii = node.independentCorners ? {
6
+ topLeft: radius(node.topLeftRadius),
7
+ topRight: radius(node.topRightRadius),
8
+ bottomRight: radius(node.bottomRightRadius),
9
+ bottomLeft: radius(node.bottomLeftRadius)
10
+ } : {
11
+ topLeft: radius(node.cornerRadius),
12
+ topRight: radius(node.cornerRadius),
13
+ bottomRight: radius(node.cornerRadius),
14
+ bottomLeft: radius(node.cornerRadius)
15
+ };
16
+ if (radii.topLeft === radii.topRight && radii.topRight === radii.bottomRight && radii.bottomRight === radii.bottomLeft) {
17
+ const budget = Math.min(width, height) / 2;
18
+ const clampedRadius = Math.min(radii.topLeft, budget);
19
+ return {
20
+ topLeft: {
21
+ radius: clampedRadius,
22
+ budget
23
+ },
24
+ topRight: {
25
+ radius: clampedRadius,
26
+ budget
27
+ },
28
+ bottomRight: {
29
+ radius: clampedRadius,
30
+ budget
31
+ },
32
+ bottomLeft: {
33
+ radius: clampedRadius,
34
+ budget
35
+ }
36
+ };
37
+ }
38
+ const budgets = {
39
+ topLeft: -1,
40
+ topRight: -1,
41
+ bottomRight: -1,
42
+ bottomLeft: -1
43
+ };
44
+ const adjacentByCorner = {
45
+ topLeft: [{
46
+ corner: "topRight",
47
+ sideLength: width
48
+ }, {
49
+ corner: "bottomLeft",
50
+ sideLength: height
51
+ }],
52
+ topRight: [{
53
+ corner: "topLeft",
54
+ sideLength: width
55
+ }, {
56
+ corner: "bottomRight",
57
+ sideLength: height
58
+ }],
59
+ bottomRight: [{
60
+ corner: "bottomLeft",
61
+ sideLength: width
62
+ }, {
63
+ corner: "topRight",
64
+ sideLength: height
65
+ }],
66
+ bottomLeft: [{
67
+ corner: "bottomRight",
68
+ sideLength: width
69
+ }, {
70
+ corner: "topLeft",
71
+ sideLength: height
72
+ }]
73
+ };
74
+ for (const corner of Object.keys(radii).sort((a, b) => radii[b] - radii[a])) {
75
+ const cornerRadius = radii[corner];
76
+ const budget = minOf(adjacentByCorner[corner].map((adjacent) => {
77
+ const adjacentRadius = radii[adjacent.corner];
78
+ if (cornerRadius === 0 && adjacentRadius === 0) return 0;
79
+ if (budgets[adjacent.corner] >= 0) return adjacent.sideLength - budgets[adjacent.corner];
80
+ return cornerRadius / (cornerRadius + adjacentRadius) * adjacent.sideLength;
81
+ }));
82
+ budgets[corner] = budget;
83
+ radii[corner] = Math.min(cornerRadius, budget);
84
+ }
85
+ return {
86
+ topLeft: {
87
+ radius: radii.topLeft,
88
+ budget: budgets.topLeft
89
+ },
90
+ topRight: {
91
+ radius: radii.topRight,
92
+ budget: budgets.topRight
93
+ },
94
+ bottomRight: {
95
+ radius: radii.bottomRight,
96
+ budget: budgets.bottomRight
97
+ },
98
+ bottomLeft: {
99
+ radius: radii.bottomLeft,
100
+ budget: budgets.bottomLeft
101
+ }
102
+ };
103
+ }
104
+ function degreesToRadians(degrees) {
105
+ return degrees * Math.PI / 180;
106
+ }
107
+ function smoothCornerPathParams(corner, smoothing) {
108
+ let cornerSmoothing = smoothing;
109
+ let p = (1 + cornerSmoothing) * corner.radius;
110
+ if (corner.radius > 0) {
111
+ const maxSmoothing = corner.budget / corner.radius - 1;
112
+ cornerSmoothing = Math.min(cornerSmoothing, maxSmoothing);
113
+ p = Math.min(p, corner.budget);
114
+ }
115
+ const arcMeasure = 90 * (1 - cornerSmoothing);
116
+ const arcSectionLength = Math.sin(degreesToRadians(arcMeasure / 2)) * corner.radius * Math.sqrt(2);
117
+ const angleAlpha = (90 - arcMeasure) / 2;
118
+ const p3ToP4Distance = corner.radius * Math.tan(degreesToRadians(angleAlpha / 2));
119
+ const angleBeta = 45 * cornerSmoothing;
120
+ const c = p3ToP4Distance * Math.cos(degreesToRadians(angleBeta));
121
+ const d = c * Math.tan(degreesToRadians(angleBeta));
122
+ const b = (p - arcSectionLength - c - d) / 3;
123
+ return {
124
+ a: 2 * b,
125
+ b,
126
+ c,
127
+ d,
128
+ p,
129
+ radius: corner.radius,
130
+ arcSectionLength
131
+ };
132
+ }
133
+ function drawTopRightSmoothCorner(path, corner, x, y) {
134
+ if (corner.radius === 0) {
135
+ path.lineTo(x + corner.p, y);
136
+ return;
137
+ }
138
+ path.cubicTo(x + corner.a, y, x + corner.a + corner.b, y, x + corner.a + corner.b + corner.c, y + corner.d);
139
+ path.arcToRotated(corner.radius, corner.radius, 0, true, false, x + corner.p - corner.d, y + corner.p - corner.a - corner.b - corner.c);
140
+ path.cubicTo(x + corner.p, y + corner.p - corner.a - corner.b, x + corner.p, y + corner.p - corner.a, x + corner.p, y + corner.p);
141
+ }
142
+ function drawBottomRightSmoothCorner(path, corner, x, y) {
143
+ if (corner.radius === 0) {
144
+ path.lineTo(x, y + corner.p);
145
+ return;
146
+ }
147
+ path.cubicTo(x, y + corner.a, x, y + corner.a + corner.b, x - corner.d, y + corner.a + corner.b + corner.c);
148
+ path.arcToRotated(corner.radius, corner.radius, 0, true, false, x - corner.p + corner.a + corner.b + corner.c, y + corner.p - corner.d);
149
+ path.cubicTo(x - corner.p + corner.a + corner.b, y + corner.p, x - corner.p + corner.a, y + corner.p, x - corner.p, y + corner.p);
150
+ }
151
+ function drawBottomLeftSmoothCorner(path, corner, x, y) {
152
+ if (corner.radius === 0) {
153
+ path.lineTo(x - corner.p, y);
154
+ return;
155
+ }
156
+ path.cubicTo(x - corner.a, y, x - corner.a - corner.b, y, x - corner.a - corner.b - corner.c, y - corner.d);
157
+ path.arcToRotated(corner.radius, corner.radius, 0, true, false, x - corner.p + corner.d, y - corner.p + corner.a + corner.b + corner.c);
158
+ path.cubicTo(x - corner.p, y - corner.p + corner.a + corner.b, x - corner.p, y - corner.p + corner.a, x - corner.p, y - corner.p);
159
+ }
160
+ function drawTopLeftSmoothCorner(path, corner, x, y) {
161
+ if (corner.radius === 0) {
162
+ path.lineTo(x, y - corner.p);
163
+ return;
164
+ }
165
+ path.cubicTo(x, y - corner.a, x, y - corner.a - corner.b, x + corner.d, y - corner.a - corner.b - corner.c);
166
+ path.arcToRotated(corner.radius, corner.radius, 0, true, false, x + corner.p - corner.a - corner.b - corner.c, y - corner.p + corner.d);
167
+ path.cubicTo(x + corner.p - corner.a - corner.b, y - corner.p, x + corner.p - corner.a, y - corner.p, x + corner.p, y - corner.p);
168
+ }
169
+ /**
170
+ * Trace a rectangle with smoothed corners into `path`, as Figma rounds them. False, with nothing
171
+ * traced, when no corner is rounded, so the caller can draw a plain rectangle.
172
+ */
173
+ function traceSmoothRect(path, node, box, spread = 0) {
174
+ const { left, top, right, bottom } = box;
175
+ const smoothing = Math.max(0, Math.min(node.cornerSmoothing, 1));
176
+ const corners = smoothCornerRadii(node, right - left, bottom - top, spread);
177
+ const topLeftCorner = smoothCornerPathParams(corners.topLeft, smoothing);
178
+ const topRightCorner = smoothCornerPathParams(corners.topRight, smoothing);
179
+ const bottomRightCorner = smoothCornerPathParams(corners.bottomRight, smoothing);
180
+ const bottomLeftCorner = smoothCornerPathParams(corners.bottomLeft, smoothing);
181
+ if (topLeftCorner.radius === 0 && topRightCorner.radius === 0 && bottomRightCorner.radius === 0 && bottomLeftCorner.radius === 0) return false;
182
+ path.moveTo(right - topRightCorner.p, top);
183
+ drawTopRightSmoothCorner(path, topRightCorner, right - topRightCorner.p, top);
184
+ path.lineTo(right, bottom - bottomRightCorner.p);
185
+ drawBottomRightSmoothCorner(path, bottomRightCorner, right, bottom - bottomRightCorner.p);
186
+ path.lineTo(left + bottomLeftCorner.p, bottom);
187
+ drawBottomLeftSmoothCorner(path, bottomLeftCorner, left + bottomLeftCorner.p, bottom);
188
+ path.lineTo(left, top + topLeftCorner.p);
189
+ drawTopLeftSmoothCorner(path, topLeftCorner, left, top + topLeftCorner.p);
190
+ path.close();
191
+ return true;
192
+ }
193
+ //#endregion
194
+ export { traceSmoothRect };
195
+
196
+ //# sourceMappingURL=smooth-corners.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smooth-corners.js","names":[],"sources":["../../src/paths/smooth-corners.ts"],"sourcesContent":["import { minOf } from '../arrays'\nimport type { SceneNode } from '../types'\nimport type { PathSink } from './sink'\n\n/** What a rectangle's smoothed corners are drawn from. */\nexport type SmoothRectNode = Pick<\n SceneNode,\n | 'cornerRadius'\n | 'cornerSmoothing'\n | 'independentCorners'\n | 'topLeftRadius'\n | 'topRightRadius'\n | 'bottomRightRadius'\n | 'bottomLeftRadius'\n>\n\n/**\n * Where a smoothed rectangle is traced: a CanvasKit `PathBuilder`, or a writer of SVG path data.\n * `arcToRotated` takes CanvasKit's arguments, which match an SVG arc's.\n */\nexport interface SmoothCornerSink extends PathSink {\n arcToRotated(\n rx: number,\n ry: number,\n xAxisRotate: number,\n useSmallArc: boolean,\n isCCW: boolean,\n x: number,\n y: number\n ): unknown\n}\n\ntype SmoothCornerKey = 'topLeft' | 'topRight' | 'bottomRight' | 'bottomLeft'\n\ntype SmoothCorner = {\n radius: number\n budget: number\n}\n\ntype SmoothCornerPathParams = {\n a: number\n b: number\n c: number\n d: number\n p: number\n radius: number\n arcSectionLength: number\n}\n\nfunction smoothCornerRadii(\n node: SmoothRectNode,\n width: number,\n height: number,\n spread: number\n): Record<SmoothCornerKey, SmoothCorner> {\n const radius = (value: number) => Math.max(0, value + spread)\n const radii: Record<SmoothCornerKey, number> = node.independentCorners\n ? {\n topLeft: radius(node.topLeftRadius),\n topRight: radius(node.topRightRadius),\n bottomRight: radius(node.bottomRightRadius),\n bottomLeft: radius(node.bottomLeftRadius)\n }\n : {\n topLeft: radius(node.cornerRadius),\n topRight: radius(node.cornerRadius),\n bottomRight: radius(node.cornerRadius),\n bottomLeft: radius(node.cornerRadius)\n }\n\n if (\n radii.topLeft === radii.topRight &&\n radii.topRight === radii.bottomRight &&\n radii.bottomRight === radii.bottomLeft\n ) {\n const budget = Math.min(width, height) / 2\n const clampedRadius = Math.min(radii.topLeft, budget)\n return {\n topLeft: { radius: clampedRadius, budget },\n topRight: { radius: clampedRadius, budget },\n bottomRight: { radius: clampedRadius, budget },\n bottomLeft: { radius: clampedRadius, budget }\n }\n }\n\n const budgets: Record<SmoothCornerKey, number> = {\n topLeft: -1,\n topRight: -1,\n bottomRight: -1,\n bottomLeft: -1\n }\n const adjacentByCorner: Record<\n SmoothCornerKey,\n Array<{ corner: SmoothCornerKey; sideLength: number }>\n > = {\n topLeft: [\n { corner: 'topRight', sideLength: width },\n { corner: 'bottomLeft', sideLength: height }\n ],\n topRight: [\n { corner: 'topLeft', sideLength: width },\n { corner: 'bottomRight', sideLength: height }\n ],\n bottomRight: [\n { corner: 'bottomLeft', sideLength: width },\n { corner: 'topRight', sideLength: height }\n ],\n bottomLeft: [\n { corner: 'bottomRight', sideLength: width },\n { corner: 'topLeft', sideLength: height }\n ]\n }\n\n for (const corner of (Object.keys(radii) as SmoothCornerKey[]).sort(\n (a, b) => radii[b] - radii[a]\n )) {\n const cornerRadius = radii[corner]\n const budget = minOf(\n adjacentByCorner[corner].map((adjacent) => {\n const adjacentRadius = radii[adjacent.corner]\n if (cornerRadius === 0 && adjacentRadius === 0) return 0\n if (budgets[adjacent.corner] >= 0) return adjacent.sideLength - budgets[adjacent.corner]\n return (cornerRadius / (cornerRadius + adjacentRadius)) * adjacent.sideLength\n })\n )\n budgets[corner] = budget\n radii[corner] = Math.min(cornerRadius, budget)\n }\n\n return {\n topLeft: { radius: radii.topLeft, budget: budgets.topLeft },\n topRight: { radius: radii.topRight, budget: budgets.topRight },\n bottomRight: { radius: radii.bottomRight, budget: budgets.bottomRight },\n bottomLeft: { radius: radii.bottomLeft, budget: budgets.bottomLeft }\n }\n}\n\nfunction degreesToRadians(degrees: number): number {\n return (degrees * Math.PI) / 180\n}\n\nfunction smoothCornerPathParams(corner: SmoothCorner, smoothing: number): SmoothCornerPathParams {\n let cornerSmoothing = smoothing\n let p = (1 + cornerSmoothing) * corner.radius\n if (corner.radius > 0) {\n const maxSmoothing = corner.budget / corner.radius - 1\n cornerSmoothing = Math.min(cornerSmoothing, maxSmoothing)\n p = Math.min(p, corner.budget)\n }\n\n const arcMeasure = 90 * (1 - cornerSmoothing)\n const arcSectionLength = Math.sin(degreesToRadians(arcMeasure / 2)) * corner.radius * Math.sqrt(2)\n const angleAlpha = (90 - arcMeasure) / 2\n const p3ToP4Distance = corner.radius * Math.tan(degreesToRadians(angleAlpha / 2))\n const angleBeta = 45 * cornerSmoothing\n const c = p3ToP4Distance * Math.cos(degreesToRadians(angleBeta))\n const d = c * Math.tan(degreesToRadians(angleBeta))\n const b = (p - arcSectionLength - c - d) / 3\n\n return {\n a: 2 * b,\n b,\n c,\n d,\n p,\n radius: corner.radius,\n arcSectionLength\n }\n}\n\nfunction drawTopRightSmoothCorner(\n path: SmoothCornerSink,\n corner: SmoothCornerPathParams,\n x: number,\n y: number\n) {\n if (corner.radius === 0) {\n path.lineTo(x + corner.p, y)\n return\n }\n path.cubicTo(\n x + corner.a,\n y,\n x + corner.a + corner.b,\n y,\n x + corner.a + corner.b + corner.c,\n y + corner.d\n )\n path.arcToRotated(\n corner.radius,\n corner.radius,\n 0,\n true,\n false,\n x + corner.p - corner.d,\n y + corner.p - corner.a - corner.b - corner.c\n )\n path.cubicTo(\n x + corner.p,\n y + corner.p - corner.a - corner.b,\n x + corner.p,\n y + corner.p - corner.a,\n x + corner.p,\n y + corner.p\n )\n}\n\nfunction drawBottomRightSmoothCorner(\n path: SmoothCornerSink,\n corner: SmoothCornerPathParams,\n x: number,\n y: number\n) {\n if (corner.radius === 0) {\n path.lineTo(x, y + corner.p)\n return\n }\n path.cubicTo(\n x,\n y + corner.a,\n x,\n y + corner.a + corner.b,\n x - corner.d,\n y + corner.a + corner.b + corner.c\n )\n path.arcToRotated(\n corner.radius,\n corner.radius,\n 0,\n true,\n false,\n x - corner.p + corner.a + corner.b + corner.c,\n y + corner.p - corner.d\n )\n path.cubicTo(\n x - corner.p + corner.a + corner.b,\n y + corner.p,\n x - corner.p + corner.a,\n y + corner.p,\n x - corner.p,\n y + corner.p\n )\n}\n\nfunction drawBottomLeftSmoothCorner(\n path: SmoothCornerSink,\n corner: SmoothCornerPathParams,\n x: number,\n y: number\n) {\n if (corner.radius === 0) {\n path.lineTo(x - corner.p, y)\n return\n }\n path.cubicTo(\n x - corner.a,\n y,\n x - corner.a - corner.b,\n y,\n x - corner.a - corner.b - corner.c,\n y - corner.d\n )\n path.arcToRotated(\n corner.radius,\n corner.radius,\n 0,\n true,\n false,\n x - corner.p + corner.d,\n y - corner.p + corner.a + corner.b + corner.c\n )\n path.cubicTo(\n x - corner.p,\n y - corner.p + corner.a + corner.b,\n x - corner.p,\n y - corner.p + corner.a,\n x - corner.p,\n y - corner.p\n )\n}\n\nfunction drawTopLeftSmoothCorner(\n path: SmoothCornerSink,\n corner: SmoothCornerPathParams,\n x: number,\n y: number\n) {\n if (corner.radius === 0) {\n path.lineTo(x, y - corner.p)\n return\n }\n path.cubicTo(\n x,\n y - corner.a,\n x,\n y - corner.a - corner.b,\n x + corner.d,\n y - corner.a - corner.b - corner.c\n )\n path.arcToRotated(\n corner.radius,\n corner.radius,\n 0,\n true,\n false,\n x + corner.p - corner.a - corner.b - corner.c,\n y - corner.p + corner.d\n )\n path.cubicTo(\n x + corner.p - corner.a - corner.b,\n y - corner.p,\n x + corner.p - corner.a,\n y - corner.p,\n x + corner.p,\n y - corner.p\n )\n}\n\n/**\n * Trace a rectangle with smoothed corners into `path`, as Figma rounds them. False, with nothing\n * traced, when no corner is rounded, so the caller can draw a plain rectangle.\n */\nexport function traceSmoothRect(\n path: SmoothCornerSink,\n node: SmoothRectNode,\n box: { left: number; top: number; right: number; bottom: number },\n spread = 0\n): boolean {\n const { left, top, right, bottom } = box\n const smoothing = Math.max(0, Math.min(node.cornerSmoothing, 1))\n const corners = smoothCornerRadii(node, right - left, bottom - top, spread)\n const topLeftCorner = smoothCornerPathParams(corners.topLeft, smoothing)\n const topRightCorner = smoothCornerPathParams(corners.topRight, smoothing)\n const bottomRightCorner = smoothCornerPathParams(corners.bottomRight, smoothing)\n const bottomLeftCorner = smoothCornerPathParams(corners.bottomLeft, smoothing)\n\n if (\n topLeftCorner.radius === 0 &&\n topRightCorner.radius === 0 &&\n bottomRightCorner.radius === 0 &&\n bottomLeftCorner.radius === 0\n ) {\n return false\n }\n\n path.moveTo(right - topRightCorner.p, top)\n drawTopRightSmoothCorner(path, topRightCorner, right - topRightCorner.p, top)\n path.lineTo(right, bottom - bottomRightCorner.p)\n drawBottomRightSmoothCorner(path, bottomRightCorner, right, bottom - bottomRightCorner.p)\n path.lineTo(left + bottomLeftCorner.p, bottom)\n drawBottomLeftSmoothCorner(path, bottomLeftCorner, left + bottomLeftCorner.p, bottom)\n path.lineTo(left, top + topLeftCorner.p)\n drawTopLeftSmoothCorner(path, topLeftCorner, left, top + topLeftCorner.p)\n path.close()\n return true\n}\n"],"mappings":";;AAiDA,SAAS,kBACP,MACA,OACA,QACA,QACuC;CACvC,MAAM,UAAU,UAAkB,KAAK,IAAI,GAAG,QAAQ,MAAM;CAC5D,MAAM,QAAyC,KAAK,qBAChD;EACE,SAAS,OAAO,KAAK,aAAa;EAClC,UAAU,OAAO,KAAK,cAAc;EACpC,aAAa,OAAO,KAAK,iBAAiB;EAC1C,YAAY,OAAO,KAAK,gBAAgB;CAC1C,IACA;EACE,SAAS,OAAO,KAAK,YAAY;EACjC,UAAU,OAAO,KAAK,YAAY;EAClC,aAAa,OAAO,KAAK,YAAY;EACrC,YAAY,OAAO,KAAK,YAAY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AS;CAC/E,MAAM,mBAAmB,uBAAuB,QAAQ,YAAY,SAAS;CAE7E,IACE,cAAc,WAAW,KACzB,eAAe,WAAW,KAC1B,kBAAkB,WAAW,KAC7B,iBAAiB,WAAW,GAE5B,OAAO;CAGT,KAAK,OAAO,QAAQ,eAAe,GAAG,GAAG;CACzC,yBAAyB,MAAM,gBAAgB,QAAQ,eAAe,GAAG,GAAG;CAC5E,KAAK,OAAO,OAAO,SAAS,kBAAkB,CAAC;CAC/C,4BAA4B,MAAM,mBAAmB,OAAO,SAAS,kBAAkB,CAAC;CACxF,KAAK,OAAO,OAAO,iBAAiB,GAAG,MAAM;CAC7C,2BAA2B,MAAM,kBAAkB,OAAO,iBAAiB,GAAG,MAAM;CACpF,KAAK,OAAO,MAAM,MAAM,cAAc,CAAC;CACvC,wBAAwB,MAAM,eAAe,MAAM,MAAM,cAAc,CAAC;CACxE,KAAK,MAAM;CACX,OAAO;AACT"}
@@ -72,6 +72,10 @@ declare const OPEN_PENCIL_PLUGIN_DATA: {
72
72
  }>;
73
73
  /** The attribute that switches manual modes, on each VARIABLE_SET. */
74
74
  modeAttribute: PluginDataField<string>;
75
+ /** The library mode each mode of a copied collection came from, by the file's mode id. */
76
+ libraryModes: PluginDataField<{
77
+ [x: string]: string;
78
+ }>;
75
79
  /** One entry per paint picked in OkHCL, so the picker reopens on the same coordinates. */
76
80
  okhcl: PluginDataField<OkHCLPayload>;
77
81
  /** How a main component or component set behaves as a control in preview. */
@@ -1 +1 @@
1
- {"version":3,"file":"fields.d.ts","names":[],"sources":["../../src/plugin-data/fields.ts"],"mappings":";;;;;;;UAsHiB;EACf,OAAO;EACP,cAAc;IAAiB;IAAa;;;;;;;;cAuCjC;;iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgFG,kBAAkB,kBAAkB,oBAAoB"}
1
+ {"version":3,"file":"fields.d.ts","names":[],"sources":["../../src/plugin-data/fields.ts"],"mappings":";;;;;;;UAsHiB;EACf,OAAO;EACP,cAAc;IAAiB;IAAa;;;;;;;;cAuCjC;;iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkFG,kBAAkB,kBAAkB,oBAAoB"}
@@ -144,6 +144,8 @@ const OPEN_PENCIL_PLUGIN_DATA = {
144
144
  modeConditions: jsonPluginDataField("modeConditions", "format", v.record(v.string(), cssTextSchema)),
145
145
  /** The attribute that switches manual modes, on each VARIABLE_SET. */
146
146
  modeAttribute: jsonPluginDataField("modeAttribute", "format", v.pipe(v.string(), v.trim(), v.maxLength(100), v.regex(MODE_ATTRIBUTE_PATTERN))),
147
+ /** The library mode each mode of a copied collection came from, by the file's mode id. */
148
+ libraryModes: jsonPluginDataField("libraryModes", "format", v.record(v.string(), v.string())),
147
149
  /** One entry per paint picked in OkHCL, so the picker reopens on the same coordinates. */
148
150
  okhcl: jsonPluginDataField("okhcl", "content", okhclSchema),
149
151
  /** How a main component or component set behaves as a control in preview. */
@@ -1 +1 @@
1
- {"version":3,"file":"fields.js","names":[],"sources":["../../src/plugin-data/fields.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport { behaviourSchema } from '../behaviours/schema'\nimport type { OkHCLPayload } from '../color/okhcl'\nimport { commentThreadsSchema } from '../comments/schema'\nimport { isExportFormatId, type ExportFormatId } from '../export-format'\nimport { clampExportScale } from '../export-scale'\nimport { FIG_COMPRESSIONS } from '../fig-compression'\nimport { iconSchema, iconTintSchema } from '../icons/schema'\nimport type { Rect } from '../primitives'\nimport { shaderPaintSchema } from '../shaders/schema'\nimport { nodeStatusSchema, statusWorkflowSchema } from '../statuses/schema'\nimport {\n MODE_ATTRIBUTE_PATTERN,\n TOKEN_UNITS,\n type EnabledLibraryBinding,\n type ExportSetting,\n type LayoutDirection,\n type LibraryAssetSource,\n type PluginDataEntry,\n type SourceLibraryPublication,\n type TextDirection,\n type TokenUnit\n} from '../types'\nimport {\n jsonPluginDataField,\n textPluginDataField,\n withoutPluginData,\n type PluginDataKey\n} from './field'\n\nconst DIRECTIONS = ['AUTO', 'LTR', 'RTL'] as const satisfies readonly (\n | TextDirection\n | LayoutDirection\n)[]\n\nconst textPathBoxSchema: v.GenericSchema<unknown, Rect> = v.pipe(\n v.object({ x: v.number(), y: v.number(), width: v.number(), height: v.number() }),\n v.check(\n ({ x, y, width, height }) => Number.isFinite(x + y + width + height) && width > 0 && height > 0\n )\n)\n\n/** String-valued entries of a JSON object; other entries are dropped, not rejected. */\nconst boundVariablesSchema = v.pipe(\n v.custom<Record<string, unknown>>(\n (value) => typeof value === 'object' && value !== null && !Array.isArray(value)\n ),\n v.transform((value) =>\n Object.fromEntries(\n Object.entries(value).filter(\n (entry): entry is [string, string] => typeof entry[1] === 'string'\n )\n )\n )\n)\n\n/** Every entry must be valid, or the whole value is ignored in favour of native settings. */\nconst exportSettingsSchema: v.GenericSchema<unknown, ExportSetting[]> = v.array(\n v.pipe(\n v.object({\n scale: v.pipe(v.number(), v.finite()),\n format: v.custom<ExportFormatId>(isExportFormatId),\n suffix: v.optional(v.string()),\n size: v.optional(\n v.object({\n type: v.picklist(['WIDTH', 'HEIGHT']),\n value: v.pipe(v.number(), v.finite())\n })\n ),\n contentsOnly: v.optional(v.boolean()),\n useAbsoluteBounds: v.optional(v.boolean()),\n colorProfile: v.optional(v.picklist(['DOCUMENT', 'SRGB', 'DISPLAY_P3_V4'])),\n svgOutlineText: v.optional(v.boolean()),\n svgIdAttribute: v.optional(v.boolean()),\n svgSimplifyStroke: v.optional(v.boolean())\n }),\n // Clamp at the file boundary: imported plugin data may carry a scale the UI never produces.\n v.transform((setting) => ({ ...setting, scale: clampExportScale(setting.scale) }))\n )\n)\n\nconst librarySourceSchema: v.GenericSchema<unknown, LibraryAssetSource> = v.pipe(\n v.object({\n identity: v.object({ libraryId: v.string(), assetKey: v.string(), revisionId: v.string() }),\n sourceNodeId: v.optional(v.unknown()),\n readOnly: v.optional(v.unknown())\n }),\n v.transform(({ identity, sourceNodeId, readOnly }) => ({\n identity,\n sourceNodeId: typeof sourceNodeId === 'string' ? sourceNodeId : null,\n readOnly: readOnly === true\n }))\n)\n\nconst enabledLibrarySchema = v.object({\n libraryId: v.string(),\n revisionId: v.string(),\n enabled: v.optional(v.unknown())\n})\n\n/** Invalid entries are skipped one by one, so one bad binding keeps the others. */\nconst enabledLibrariesSchema: v.GenericSchema<unknown, EnabledLibraryBinding[]> = v.pipe(\n v.array(v.unknown()),\n v.transform((items) =>\n items.flatMap((item) => {\n const parsed = v.safeParse(enabledLibrarySchema, item)\n if (!parsed.success) return []\n const { libraryId, revisionId, enabled } = parsed.output\n return [{ libraryId, revisionId, enabled: enabled === true }]\n })\n )\n)\n\n// Shape only. Whether a string is valid CSS is checked where it is written into a stylesheet.\nconst cssTextSchema = v.pipe(v.string(), v.trim(), v.nonEmpty(), v.maxLength(1000))\n\n/** Token fields Figma has no slot for, with mode ids as the file spells them. */\nexport interface StoredToken {\n unit?: TokenUnit\n expressions?: Record<string, { css: string; resolved?: number }>\n}\n\nconst tokenSchema: v.GenericSchema<unknown, StoredToken> = v.object({\n unit: v.optional(v.picklist(TOKEN_UNITS)),\n expressions: v.optional(\n v.record(\n v.string(),\n v.object({ css: cssTextSchema, resolved: v.optional(v.pipe(v.number(), v.finite())) })\n )\n )\n})\n\nconst okhclSchema: v.GenericSchema<unknown, OkHCLPayload> = v.object({\n version: v.literal(1),\n kind: v.picklist(['fill', 'stroke']),\n index: v.number(),\n color: v.object({\n h: v.number(),\n c: v.number(),\n l: v.number(),\n a: v.fallback(v.optional(v.number()), undefined)\n })\n})\n\nconst sourceLibraryPublicationSchema: v.GenericSchema<unknown, SourceLibraryPublication> = v.object(\n {\n libraryId: v.string(),\n revisionId: v.string(),\n name: v.string(),\n catalogSource: v.optional(v.string())\n }\n)\n\n/**\n * Every plugin-data entry OpenPencil writes under {@link OPEN_PENCIL_PLUGIN_ID}: state Figma's\n * format has no field for. Add a key here, never as a string elsewhere, so reading and writing\n * it share one schema.\n */\nexport const OPEN_PENCIL_PLUGIN_DATA = {\n /** A text node's direction, on TEXT nodes. */\n textDirection: textPluginDataField('textDirection', 'format', DIRECTIONS),\n /** An auto-layout frame's direction. */\n layoutDirection: textPluginDataField('layoutDirection', 'format', DIRECTIONS),\n /** Marks a component set Figma would read as a plain frame. */\n nodeType: textPluginDataField('nodeType', 'format', ['COMPONENT_SET']),\n /** Variable bindings by field path, including those Figma cannot store natively. */\n boundVariables: jsonPluginDataField('boundVariables', 'format', boundVariablesSchema),\n exportSettings: jsonPluginDataField('exportSettings', 'format', exportSettingsSchema),\n /** The node-local rect a TEXT_PATH layout maps onto, which Kiwi has no field for. */\n textPathBox: jsonPluginDataField('textPathBox', 'format', textPathBoxSchema),\n /** The library asset a node was inserted from. */\n librarySource: jsonPluginDataField('librarySource', 'bookkeeping', librarySourceSchema),\n /** The library source layer a library definition's layer copies, on every definition layer. */\n libraryLayer: jsonPluginDataField(\n 'libraryLayer',\n 'bookkeeping',\n v.pipe(v.string(), v.nonEmpty(), v.maxLength(1024))\n ),\n /**\n * The document root's id, on the DOCUMENT node, whose own GUID is always Figma's `0:0`; the\n * root keeps it across a save as every layer keeps its GUID.\n */\n documentId: jsonPluginDataField(\n 'documentId',\n 'bookkeeping',\n v.pipe(v.string(), v.nonEmpty(), v.maxLength(64))\n ),\n /** Libraries enabled for the document, on the DOCUMENT node. */\n enabledLibraries: jsonPluginDataField('enabledLibraries', 'bookkeeping', enabledLibrariesSchema),\n /** The library this document publishes as, on the DOCUMENT node. */\n sourceLibraryPublication: jsonPluginDataField(\n 'sourceLibraryPublication',\n 'bookkeeping',\n sourceLibraryPublicationSchema\n ),\n /** Canvas comment threads, deleted ones included, on the DOCUMENT node. */\n comments: jsonPluginDataField('comments', 'bookkeeping', commentThreadsSchema),\n /** The statuses layers can be in, on the DOCUMENT node. */\n statuses: jsonPluginDataField('statuses', 'bookkeeping', statusWorkflowSchema),\n /** How tightly the document's `.fig` data is compressed, on the DOCUMENT node. */\n figCompression: textPluginDataField('figCompression', 'bookkeeping', FIG_COMPRESSIONS),\n /** A layer's status, any state of the workflow; Figma's `sectionStatusInfo` knows only two. */\n status: jsonPluginDataField('status', 'format', nodeStatusSchema),\n /** Unit and CSS expressions, on each VARIABLE. */\n token: jsonPluginDataField('token', 'format', tokenSchema),\n /** Mode conditions by mode id, on each VARIABLE_SET. */\n modeConditions: jsonPluginDataField(\n 'modeConditions',\n 'format',\n v.record(v.string(), cssTextSchema)\n ),\n /** The attribute that switches manual modes, on each VARIABLE_SET. */\n modeAttribute: jsonPluginDataField(\n 'modeAttribute',\n 'format',\n v.pipe(v.string(), v.trim(), v.maxLength(100), v.regex(MODE_ATTRIBUTE_PATTERN))\n ),\n /** One entry per paint picked in OkHCL, so the picker reopens on the same coordinates. */\n okhcl: jsonPluginDataField('okhcl', 'content', okhclSchema),\n /** How a main component or component set behaves as a control in preview. */\n behaviour: jsonPluginDataField('behaviour', 'content', behaviourSchema),\n /** The icon a frame draws, such as `lucide:home`, on the frame its paths are in. */\n icon: jsonPluginDataField('icon', 'content', iconSchema),\n /** Which of an icon path's paints its icon's color sets, on each path the source drew in it. */\n iconTint: jsonPluginDataField('iconTint', 'content', iconTintSchema),\n /** One entry per paint that draws a shader, matched to its image paint by the frame's hash. */\n shader: jsonPluginDataField('shader', 'content', shaderPaintSchema)\n} satisfies Record<string, PluginDataKey>\n\nconst NOT_CONTENT = Object.values(OPEN_PENCIL_PLUGIN_DATA).filter(\n (field) => field.role !== 'content'\n)\n\n/**\n * A node's plugin data that is part of its content, in a stable order: OpenPencil's content\n * fields and every other plugin's entries, which the node carries wherever it goes. Format\n * copies of node fields and bookkeeping are left out.\n */\nexport function contentPluginData(entries: readonly PluginData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AAC,CAClD;;CAEA,kBAAkB,oBAAoB,oBAAoB,eAAe,sBAAsB;;CAE/F,0BAA0B,oBACxB,4BACA,eACA,8BACF;;CAEA,UAAU,oBAAoB,YAAY,eAAe,oBAAoB;;CAE7E,UAAU,oBAAoB,YAAY,eAAe,oBAAoB;;CAE7E,gBAAgB,oBAAoB,kBAAkB,eAAe,gBAAgB;;CAErF,QAAQ,oBAAoB,UAAU,UAAU,gBAAgB;;CAEhE,OAAO,oBAAoB,SAAS,UAAU,WAAW;;CAEzD,gBAAgB,oBACd,kBACA,UACA,EAAE,OAAO,EAAE,OAAO,GAAG,aAAa,CACpC;;CAEA,eAAe,oBACb,iBACA,UACA,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,GAAG,EAAE,UAAU,GAAG,GAAG,EAAE,MAAM,sBAAsB,CAAC,CAChF;;CAEA,OAAO,oBAAoB,SAAS,WAAW,WAAW;;CAE1D,WAAW,oBAAoB,aAAa,WAAW,eAAe;;CAEtE,MAAM,oBAAoB,QAAQ,WAAW,UAAU;;CAEvD,UAAU,oBAAoB,YAAY,WAAW,cAAc;;CAEnE,QAAQ,oBAAoB,UAAU,WAAW,iBAAiB;AACpE;AAEA,MAAM,cAAc,OAAO,OAAO,uBAAuB,CAAC,CAAC,QACxD,UAAU,MAAM,SAAS,SAC5B;;;;;;AAOA,SAAgB,kBAAkB,SAAwD;CACxF,OAAO,kBAAkB,SAAS,WAAW,CAAC,CAAC,MAC5C,GAAG,MAAM,EAAE,SAAS,cAAc,EAAE,QAAQ,KAAK,EAAE,IAAI,cAAc,EAAE,GAAG,CAC7E;AACF"}
1
+ {"version":3,"file":"fields.js","names":[],"sources":["../../src/plugin-data/fields.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport { behaviourSchema } from '../behaviours/schema'\nimport type { OkHCLPayload } from '../color/okhcl'\nimport { commentThreadsSchema } from '../comments/schema'\nimport { isExportFormatId, type ExportFormatId } from '../export-format'\nimport { clampExportScale } from '../export-scale'\nimport { FIG_COMPRESSIONS } from '../fig-compression'\nimport { iconSchema, iconTintSchema } from '../icons/schema'\nimport type { Rect } from '../primitives'\nimport { shaderPaintSchema } from '../shaders/schema'\nimport { nodeStatusSchema, statusWorkflowSchema } from '../statuses/schema'\nimport {\n MODE_ATTRIBUTE_PATTERN,\n TOKEN_UNITS,\n type EnabledLibraryBinding,\n type ExportSetting,\n type LayoutDirection,\n type LibraryAssetSource,\n type PluginDataEntry,\n type SourceLibraryPublication,\n type TextDirection,\n type TokenUnit\n} from '../types'\nimport {\n jsonPluginDataField,\n textPluginDataField,\n withoutPluginData,\n type PluginDataKey\n} from './field'\n\nconst DIRECTIONS = ['AUTO', 'LTR', 'RTL'] as const satisfies readonly (\n | TextDirection\n | LayoutDirection\n)[]\n\nconst textPathBoxSchema: v.GenericSchema<unknown, Rect> = v.pipe(\n v.object({ x: v.number(), y: v.number(), width: v.number(), height: v.number() }),\n v.check(\n ({ x, y, width, height }) => Number.isFinite(x + y + width + height) && width > 0 && height > 0\n )\n)\n\n/** String-valued entries of a JSON object; other entries are dropped, not rejected. */\nconst boundVariablesSchema = v.pipe(\n v.custom<Record<string, unknown>>(\n (value) => typeof value === 'object' && value !== null && !Array.isArray(value)\n ),\n v.transform((value) =>\n Object.fromEntries(\n Object.entries(value).filter(\n (entry): entry is [string, string] => typeof entry[1] === 'string'\n )\n )\n )\n)\n\n/** Every entry must be valid, or the whole value is ignored in favour of native settings. */\nconst exportSettingsSchema: v.GenericSchema<unknown, ExportSetting[]> = v.array(\n v.pipe(\n v.object({\n scale: v.pipe(v.number(), v.finite()),\n format: v.custom<ExportFormatId>(isExportFormatId),\n suffix: v.optional(v.string()),\n size: v.optional(\n v.object({\n type: v.picklist(['WIDTH', 'HEIGHT']),\n value: v.pipe(v.number(), v.finite())\n })\n ),\n contentsOnly: v.optional(v.boolean()),\n useAbsoluteBounds: v.optional(v.boolean()),\n colorProfile: v.optional(v.picklist(['DOCUMENT', 'SRGB', 'DISPLAY_P3_V4'])),\n svgOutlineText: v.optional(v.boolean()),\n svgIdAttribute: v.optional(v.boolean()),\n svgSimplifyStroke: v.optional(v.boolean())\n }),\n // Clamp at the file boundary: imported plugin data may carry a scale the UI never produces.\n v.transform((setting) => ({ ...setting, scale: clampExportScale(setting.scale) }))\n )\n)\n\nconst librarySourceSchema: v.GenericSchema<unknown, LibraryAssetSource> = v.pipe(\n v.object({\n identity: v.object({ libraryId: v.string(), assetKey: v.string(), revisionId: v.string() }),\n sourceNodeId: v.optional(v.unknown()),\n readOnly: v.optional(v.unknown())\n }),\n v.transform(({ identity, sourceNodeId, readOnly }) => ({\n identity,\n sourceNodeId: typeof sourceNodeId === 'string' ? sourceNodeId : null,\n readOnly: readOnly === true\n }))\n)\n\nconst enabledLibrarySchema = v.object({\n libraryId: v.string(),\n revisionId: v.string(),\n enabled: v.optional(v.unknown())\n})\n\n/** Invalid entries are skipped one by one, so one bad binding keeps the others. */\nconst enabledLibrariesSchema: v.GenericSchema<unknown, EnabledLibraryBinding[]> = v.pipe(\n v.array(v.unknown()),\n v.transform((items) =>\n items.flatMap((item) => {\n const parsed = v.safeParse(enabledLibrarySchema, item)\n if (!parsed.success) return []\n const { libraryId, revisionId, enabled } = parsed.output\n return [{ libraryId, revisionId, enabled: enabled === true }]\n })\n )\n)\n\n// Shape only. Whether a string is valid CSS is checked where it is written into a stylesheet.\nconst cssTextSchema = v.pipe(v.string(), v.trim(), v.nonEmpty(), v.maxLength(1000))\n\n/** Token fields Figma has no slot for, with mode ids as the file spells them. */\nexport interface StoredToken {\n unit?: TokenUnit\n expressions?: Record<string, { css: string; resolved?: number }>\n}\n\nconst tokenSchema: v.GenericSchema<unknown, StoredToken> = v.object({\n unit: v.optional(v.picklist(TOKEN_UNITS)),\n expressions: v.optional(\n v.record(\n v.string(),\n v.object({ css: cssTextSchema, resolved: v.optional(v.pipe(v.number(), v.finite())) })\n )\n )\n})\n\nconst okhclSchema: v.GenericSchema<unknown, OkHCLPayload> = v.object({\n version: v.literal(1),\n kind: v.picklist(['fill', 'stroke']),\n index: v.number(),\n color: v.object({\n h: v.number(),\n c: v.number(),\n l: v.number(),\n a: v.fallback(v.optional(v.number()), undefined)\n })\n})\n\nconst sourceLibraryPublicationSchema: v.GenericSchema<unknown, SourceLibraryPublication> = v.object(\n {\n libraryId: v.string(),\n revisionId: v.string(),\n name: v.string(),\n catalogSource: v.optional(v.string())\n }\n)\n\n/**\n * Every plugin-data entry OpenPencil writes under {@link OPEN_PENCIL_PLUGIN_ID}: state Figma's\n * format has no field for. Add a key here, never as a string elsewhere, so reading and writing\n * it share one schema.\n */\nexport const OPEN_PENCIL_PLUGIN_DATA = {\n /** A text node's direction, on TEXT nodes. */\n textDirection: textPluginDataField('textDirection', 'format', DIRECTIONS),\n /** An auto-layout frame's direction. */\n layoutDirection: textPluginDataField('layoutDirection', 'format', DIRECTIONS),\n /** Marks a component set Figma would read as a plain frame. */\n nodeType: textPluginDataField('nodeType', 'format', ['COMPONENT_SET']),\n /** Variable bindings by field path, including those Figma cannot store natively. */\n boundVariables: jsonPluginDataField('boundVariables', 'format', boundVariablesSchema),\n exportSettings: jsonPluginDataField('exportSettings', 'format', exportSettingsSchema),\n /** The node-local rect a TEXT_PATH layout maps onto, which Kiwi has no field for. */\n textPathBox: jsonPluginDataField('textPathBox', 'format', textPathBoxSchema),\n /** The library asset a node was inserted from. */\n librarySource: jsonPluginDataField('librarySource', 'bookkeeping', librarySourceSchema),\n /** The library source layer a library definition's layer copies, on every definition layer. */\n libraryLayer: jsonPluginDataField(\n 'libraryLayer',\n 'bookkeeping',\n v.pipe(v.string(), v.nonEmpty(), v.maxLength(1024))\n ),\n /**\n * The document root's id, on the DOCUMENT node, whose own GUID is always Figma's `0:0`; the\n * root keeps it across a save as every layer keeps its GUID.\n */\n documentId: jsonPluginDataField(\n 'documentId',\n 'bookkeeping',\n v.pipe(v.string(), v.nonEmpty(), v.maxLength(64))\n ),\n /** Libraries enabled for the document, on the DOCUMENT node. */\n enabledLibraries: jsonPluginDataField('enabledLibraries', 'bookkeeping', enabledLibrariesSchema),\n /** The library this document publishes as, on the DOCUMENT node. */\n sourceLibraryPublication: jsonPluginDataField(\n 'sourceLibraryPublication',\n 'bookkeeping',\n sourceLibraryPublicationSchema\n ),\n /** Canvas comment threads, deleted ones included, on the DOCUMENT node. */\n comments: jsonPluginDataField('comments', 'bookkeeping', commentThreadsSchema),\n /** The statuses layers can be in, on the DOCUMENT node. */\n statuses: jsonPluginDataField('statuses', 'bookkeeping', statusWorkflowSchema),\n /** How tightly the document's `.fig` data is compressed, on the DOCUMENT node. */\n figCompression: textPluginDataField('figCompression', 'bookkeeping', FIG_COMPRESSIONS),\n /** A layer's status, any state of the workflow; Figma's `sectionStatusInfo` knows only two. */\n status: jsonPluginDataField('status', 'format', nodeStatusSchema),\n /** Unit and CSS expressions, on each VARIABLE. */\n token: jsonPluginDataField('token', 'format', tokenSchema),\n /** Mode conditions by mode id, on each VARIABLE_SET. */\n modeConditions: jsonPluginDataField(\n 'modeConditions',\n 'format',\n v.record(v.string(), cssTextSchema)\n ),\n /** The attribute that switches manual modes, on each VARIABLE_SET. */\n modeAttribute: jsonPluginDataField(\n 'modeAttribute',\n 'format',\n v.pipe(v.string(), v.trim(), v.maxLength(100), v.regex(MODE_ATTRIBUTE_PATTERN))\n ),\n /** The library mode each mode of a copied collection came from, by the file's mode id. */\n libraryModes: jsonPluginDataField('libraryModes', 'format', v.record(v.string(), v.string())),\n /** One entry per paint picked in OkHCL, so the picker reopens on the same coordinates. */\n okhcl: jsonPluginDataField('okhcl', 'content', okhclSchema),\n /** How a main component or component set behaves as a control in preview. */\n behaviour: jsonPluginDataField('behaviour', 'content', behaviourSchema),\n /** The icon a frame draws, such as `lucide:home`, on the frame its paths are in. */\n icon: jsonPluginDataField('icon', 'content', iconSchema),\n /** Which of an icon path's paints its icon's color sets, on each path the source drew in it. */\n iconTint: jsonPluginDataField('iconTint', 'content', iconTintSchema),\n /** One entry per paint that draws a shader, matched to its image paint by the frame's hash. */\n shader: jsonPluginDataField('shader', 'content', shaderPaintSchema)\n} satisfies Record<string, PluginDataKey>\n\nconst NOT_CONTENT = Object.values(OPEN_PENCIL_PLUGIN_DATA).filter(\n (field) => field.role !== 'content'\n)\n\n/**\n * A node's plugin data that is part of its content, in a stable order: OpenPencil's content\n * fields and every other plugin's entries, which the node carries wherever it goes. Format\n * copies of node fields and bookkeeping are left out.\n */\nexport function contentPluginData(entries: readonly PluginDataEntry[]): PluginDataEntry[] {\n return withoutPluginData(entries, NOT_CONTENT).sort(\n (a, b) => a.pluginId.localeCompare(b.pluginId) || a.key.localeCompare(b.key)\n )\n}\n"],"mappings":";;;;;;;;;;;;AA+BA,MAAM,aAAa;CAAC;CAAQ;CAAO;AAAK;AAKxC,MAAM,oBAAoD,EAAE,KAC1D,EAAE,OAAO;CAAE,GAAG,EAAE,OAAO;CAAG,GAAG,EAAE,OAAO;CAAG,OAAO,EAAE,OAAO;CAAG,QAAQ,EAAE,OAAO;AAAE,CAAC,GAChF,EAAE,OACC,EAAE,GAAG,GAAG,OAAO,aAAa,OAAO,SAAS,IAAI,IAAI,QAAQ,MAAM,KAAK,QAAQ,KAAK,SAAS,CAChG,CACF;;AAGA,MAAM,uBAAuB,EAAE,KAC7B,EAAE,QACC,UAAU,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK,CAChF,GACA,EAAE,WAAW,UACX,OAAO,YACL,OAAO,QAAQ,KAAK,CAAC,CAAC,QACnB,UAAqC,OAAO,MAAM,OAAO,QAC5D,CACF,CACF,CACF;;AAGA,MAAM,uBAAkE,EAAE,MACxE,EAAE,KACA,EAAE,OAAO;CACP,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC;CACpC,QAAQ,EAAE,OAAuB,gBAAgB;CACjD,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC;CAC7B,MAAM,EAAE,SACN,EAAE,OAAO;EACP,MAAM,EAAE,SAAS,CAAC,SAAS,Q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OAAO,kBAAkB,SAAS,WAAW,CAAC,CAAC,MAC5C,GAAG,MAAM,EAAE,SAAS,cAAc,EAAE,QAAQ,KAAK,EAAE,IAAI,cAAc,EAAE,GAAG,CAC7E;AACF"}
package/dist/polygon.d.ts CHANGED
@@ -26,8 +26,6 @@ type PolygonOutlineCommand = {
26
26
  } | {
27
27
  type: 'Z';
28
28
  };
29
- /** Outline commands as SVG path data, with each coordinate passed through `round`. */
30
- declare function outlineSVGPath(commands: readonly PolygonOutlineCommand[], round?: (value: number) => number): string;
31
29
  type PolygonNode = Pick<SceneNode, 'type' | 'width' | 'height' | 'pointCount' | 'starInnerRadius' | 'cornerRadius' | 'cornerSmoothing'>;
32
30
  interface PolygonCorner {
33
31
  vertex: Vector;
@@ -51,5 +49,5 @@ declare function polygonCorners(node: PolygonNode): PolygonCorner[];
51
49
  /** The outline of a polygon or star with its corner radius and smoothing, in its own pixels. */
52
50
  declare function polygonOutline(node: PolygonNode): PolygonOutlineCommand[];
53
51
  //#endregion
54
- export { POINT_COUNT_RANGE, PolygonCorner, PolygonOutlineCommand, outlineSVGPath, polygonCorners, polygonOutline };
52
+ export { POINT_COUNT_RANGE, PolygonCorner, PolygonOutlineCommand, polygonCorners, polygonOutline };
55
53
  //# sourceMappingURL=polygon.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"polygon.d.ts","names":[],"sources":["../src/polygon.ts"],"mappings":";;;;;;;;;cAWa;WAAA;WAAA;;KAED;EACN;EAAiB;EAAW;;EAC5B;EAAW;EAAY;EAAY;EAAY;EAAY;EAAW;;EACtE;;;iBAGU,eACd,mBAAmB,yBACnB,SAAQ;KAcL,cAAc,KACjB;UAUe;EACf,QAAQ;;EAER,UAAU;;EAEV,UAAU;;EAEV;;EAEA;;EAEA;;;;;;;iBA2Bc,eAAe,MAAM,cAAc;;iBAsHnC,eAAe,MAAM,cAAc"}
1
+ {"version":3,"file":"polygon.d.ts","names":[],"sources":["../src/polygon.ts"],"mappings":";;;;;;;;;cAWa;WAAA;WAAA;;KAED;EACN;EAAiB;EAAW;;EAC5B;EAAW;EAAY;EAAY;EAAY;EAAY;EAAW;;EACtE;;KAED,cAAc,KACjB;UAUe;EACf,QAAQ;;EAER,UAAU;;EAEV,UAAU;;EAEV;;EAEA;;EAEA;;;;;;;iBA2Bc,eAAe,MAAM,cAAc;;iBAsHnC,eAAe,MAAM,cAAc"}
package/dist/polygon.js CHANGED
@@ -10,21 +10,6 @@ const POINT_COUNT_RANGE = {
10
10
  min: 3,
11
11
  max: 60
12
12
  };
13
- /** Outline commands as SVG path data, with each coordinate passed through `round`. */
14
- function outlineSVGPath(commands, round = (value) => Math.round(value * 100) / 100) {
15
- return commands.map((command) => {
16
- if (command.type === "Z") return "Z";
17
- if (command.type === "C") return `C${[
18
- command.x1,
19
- command.y1,
20
- command.x2,
21
- command.y2,
22
- command.x,
23
- command.y
24
- ].map(round).join(" ")}`;
25
- return `${command.type}${round(command.x)} ${round(command.y)}`;
26
- }).join("");
27
- }
28
13
  const sub = (a, b) => ({
29
14
  x: a.x - b.x,
30
15
  y: a.y - b.y
@@ -215,6 +200,6 @@ function polygonOutline(node) {
215
200
  return commands;
216
201
  }
217
202
  //#endregion
218
- export { POINT_COUNT_RANGE, outlineSVGPath, polygonCorners, polygonOutline };
203
+ export { POINT_COUNT_RANGE, polygonCorners, polygonOutline };
219
204
 
220
205
  //# sourceMappingURL=polygon.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"polygon.js","names":[],"sources":["../src/polygon.ts"],"sourcesContent":["import { polygonVertices } from './geometry'\nimport type { Vector } from './primitives'\nimport type { SceneNode } from './types'\n\n/**\n * Rounded polygon and star outlines, as Figma draws them. Each corner, convex or not, is rounded by\n * a circular arc tangent to both edges, capped so that it and its neighbours fit along every edge;\n * corner smoothing replaces the arc's ends with curves that ease into the edges, as on rectangles.\n */\n\n/** Figma keeps a polygon's sides or a star's points within this range, and its plugin API clamps to it. */\nexport const POINT_COUNT_RANGE = { min: 3, max: 60 } as const\n\nexport type PolygonOutlineCommand =\n | { type: 'M' | 'L'; x: number; y: number }\n | { type: 'C'; x1: number; y1: number; x2: number; y2: number; x: number; y: number }\n | { type: 'Z' }\n\n/** Outline commands as SVG path data, with each coordinate passed through `round`. */\nexport function outlineSVGPath(\n commands: readonly PolygonOutlineCommand[],\n round: (value: number) => number = (value) => Math.round(value * 100) / 100\n): string {\n return commands\n .map((command) => {\n if (command.type === 'Z') return 'Z'\n if (command.type === 'C') {\n const points = [command.x1, command.y1, command.x2, command.y2, command.x, command.y]\n return `C${points.map(round).join(' ')}`\n }\n return `${command.type}${round(command.x)} ${round(command.y)}`\n })\n .join('')\n}\n\ntype PolygonNode = Pick<\n SceneNode,\n | 'type'\n | 'width'\n | 'height'\n | 'pointCount'\n | 'starInnerRadius'\n | 'cornerRadius'\n | 'cornerSmoothing'\n>\n\nexport interface PolygonCorner {\n vertex: Vector\n /** The unit direction of the edge arriving at the vertex. */\n incoming: Vector\n /** The unit direction of the edge leaving the vertex. */\n outgoing: Vector\n /** How far the outline turns at the vertex, in radians: 0 for a straight line. */\n turn: number\n /** The radius the corner is drawn with, after fitting it along its edges. */\n radius: number\n /** How far along each edge from the vertex the rounding starts. */\n extent: number\n}\n\nconst sub = (a: Vector, b: Vector): Vector => ({ x: a.x - b.x, y: a.y - b.y })\nconst along = (point: Vector, direction: Vector, distance: number): Vector => ({\n x: point.x + direction.x * distance,\n y: point.y + direction.y * distance\n})\n\nfunction unit(vector: Vector): Vector {\n const length = Math.hypot(vector.x, vector.y)\n return length > 0 ? { x: vector.x / length, y: vector.y / length } : { x: 0, y: 0 }\n}\n\n/** The perpendicular of `direction` on the side the outline turns towards. */\nfunction inward(direction: Vector, towards: Vector): Vector {\n const normal = { x: -direction.y, y: direction.x }\n return normal.x * towards.x + normal.y * towards.y < 0\n ? { x: direction.y, y: -direction.x }\n : normal\n}\n\n/**\n * The polygon's or star's corners with the radius each is drawn with. A corner turning by α keeps\n * r·tan(α/2) of each edge, so on an edge of length L between corners turning by α and β the radius\n * is at most L / (tan(α/2) + tan(β/2)); each corner takes the least of its two edges' limits.\n */\nexport function polygonCorners(node: PolygonNode): PolygonCorner[] {\n const vertices = polygonVertices(node)\n const count = vertices.length\n const at = (index: number) => vertices[(index + count) % count]\n const shape = vertices.map((vertex, index) => {\n const incoming = unit(sub(vertex, at(index - 1)))\n const outgoing = unit(sub(at(index + 1), vertex))\n const cos = Math.min(1, Math.max(-1, incoming.x * outgoing.x + incoming.y * outgoing.y))\n const turn = Math.acos(cos)\n return { vertex, incoming, outgoing, turn, factor: Math.tan(turn / 2) }\n })\n const edgeLimit = (index: number) => {\n const from = shape[(index + count) % count]\n const to = shape[(index + 1 + count) % count]\n const length = Math.hypot(to.vertex.x - from.vertex.x, to.vertex.y - from.vertex.y)\n const factors = from.factor + to.factor\n return factors > 0 ? length / factors : Number.POSITIVE_INFINITY\n }\n const requested = Math.max(0, node.cornerRadius)\n return shape.map(({ factor, ...corner }, index) => {\n const radius = Math.min(requested, edgeLimit(index - 1), edgeLimit(index))\n return { ...corner, radius, extent: radius * factor }\n })\n}\n\ninterface SmoothCorner {\n /** Where the rounding starts, along each edge from the vertex. */\n p: number\n a: number\n b: number\n c: number\n d: number\n /** The angle each eased end takes from the arc, in radians. */\n ease: number\n}\n\n/**\n * Figma's smoothing for a corner turning by any angle: the rectangle construction with the\n * tangent length r·tan(α/2) in place of r and α/2 in place of 45°. Smoothing grows the rounded\n * part of each edge by up to its tangent length again.\n */\nfunction smoothCorner(corner: PolygonCorner, smoothing: number): SmoothCorner {\n const { radius, extent } = corner\n const p = (1 + smoothing) * extent\n const ease = (corner.turn * smoothing) / 2\n const toEase = radius * Math.tan(ease / 2)\n const c = toEase * Math.cos(ease)\n const d = toEase * Math.sin(ease)\n const arcStart = extent - radius * Math.sin(ease) - d\n const b = (p - arcStart - c - d) / 3\n return { p, a: 2 * b, b, c, d, ease }\n}\n\nfunction rotate(direction: Vector, towards: Vector, angle: number): Vector {\n const normal = inward(direction, towards)\n return {\n x: direction.x * Math.cos(angle) + normal.x * Math.sin(angle),\n y: direction.y * Math.cos(angle) + normal.y * Math.sin(angle)\n }\n}\n\nfunction cubic(c1: Vector, c2: Vector, to: Vector): PolygonOutlineCommand {\n return { type: 'C', x1: c1.x, y1: c1.y, x2: c2.x, y2: c2.y, x: to.x, y: to.y }\n}\n\n/** The rounded corner from where it leaves the incoming edge to where it joins the outgoing one. */\nfunction cornerCommands(corner: PolygonCorner, smooth: SmoothCorner): PolygonOutlineCommand[] {\n const { vertex, incoming, outgoing, radius, turn } = corner\n const { p, a, b, c, d, ease } = smooth\n const back = { x: -incoming.x, y: -incoming.y }\n const start = along(vertex, back, p)\n const end = along(vertex, outgoing, p)\n const normalIn = inward(incoming, outgoing)\n const normalOut = inward(outgoing, back)\n const arcFrom = along(along(start, incoming, a + b + c), normalIn, d)\n const arcTo = along(along(end, outgoing, -(a + b + c)), normalOut, d)\n const commands: PolygonOutlineCommand[] = []\n if (ease > 0)\n commands.push(cubic(along(start, incoming, a), along(start, incoming, a + b), arcFrom))\n const sweep = turn - 2 * ease\n if (sweep > 0) {\n const handle = (4 / 3) * Math.tan(sweep / 4) * radius\n const leaving = rotate(incoming, outgoing, ease)\n const arriving = rotate(outgoing, incoming, ease)\n commands.push(cubic(along(arcFrom, leaving, handle), along(arcTo, arriving, -handle), arcTo))\n }\n if (ease > 0) commands.push(cubic(along(end, outgoing, -(a + b)), along(end, outgoing, -a), end))\n return commands\n}\n\n/**\n * The smoothing every corner can take: on each edge a corner may use the part its tangent length\n * takes of both corners' tangent lengths, and Figma lowers smoothing for the whole shape to what\n * its tightest corner allows rather than corner by corner.\n */\nfunction fittedSmoothing(corners: readonly PolygonCorner[], smoothing: number): number {\n const count = corners.length\n const share = (corner: PolygonCorner, neighbour: PolygonCorner) => {\n const length = Math.hypot(\n neighbour.vertex.x - corner.vertex.x,\n neighbour.vertex.y - corner.vertex.y\n )\n return (length * corner.extent) / (corner.extent + neighbour.extent)\n }\n return corners.reduce(\n (fitted, corner, index) => {\n if (!(corner.extent > 0)) return fitted\n const budget = Math.min(\n share(corner, corners[(index - 1 + count) % count]),\n share(corner, corners[(index + 1) % count])\n )\n return Math.min(fitted, budget / corner.extent - 1)\n },\n Math.min(Math.max(smoothing, 0), 1)\n )\n}\n\n/** The outline of a polygon or star with its corner radius and smoothing, in its own pixels. */\nexport function polygonOutline(node: PolygonNode): PolygonOutlineCommand[] {\n const corners = polygonCorners(node)\n const smoothing = Math.max(0, fittedSmoothing(corners, node.cornerSmoothing))\n const commands: PolygonOutlineCommand[] = []\n let current: Vector | null = null\n // Corners whose rounding meets along an edge leave no line between them.\n const lineTo = ({ x, y }: Vector) => {\n if (current && Math.hypot(x - current.x, y - current.y) < 1e-6) return\n commands.push({ type: current ? 'L' : 'M', x, y })\n current = { x, y }\n }\n for (const corner of corners) {\n if (!(corner.radius > 0) || !(corner.turn > 0)) {\n lineTo(corner.vertex)\n continue\n }\n const smooth = smoothCorner(corner, smoothing)\n lineTo(along(corner.vertex, { x: -corner.incoming.x, y: -corner.incoming.y }, smooth.p))\n for (const command of cornerCommands(corner, smooth)) {\n commands.push(command)\n if (command.type === 'C') current = { x: command.x, y: command.y }\n }\n }\n commands.push({ type: 'Z' })\n return commands\n}\n"],"mappings":";;;;;;;;AAWA,MAAa,oBAAoB;CAAE,KAAK;CAAG,KAAK;AAAG;;AAQnD,SAAgB,eACd,UACA,SAAoC,UAAU,KAAK,MAAM,QAAQ,GAAG,IAAI,KAChE;CACR,OAAO,SACJ,KAAK,YAAY;EAChB,IAAI,QAAQ,SAAS,KAAK,OAAO;EACjC,IAAI,QAAQ,SAAS,KAEnB,OAAO,IAAI;GADK,QAAQ;GAAI,QAAQ;GAAI,QAAQ;GAAI,QAAQ;GAAI,QAAQ;GAAG,QAAQ;EACnE,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,KAAK,GAAG;EAEvC,OAAO,GAAG,QAAQ,OAAO,MAAM,QAAQ,CAAC,EAAE,GAAG,MAAM,QAAQ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,aAAa,QAAQ,SAAS;EAC7C,OAAO,MAAM,OAAO,QAAQ;GAAE,GAAG,CAAC,OAAO,SAAS;GAAG,GAAG,CAAC,OAAO,SAAS;EAAE,GAAG,OAAO,CAAC,CAAC;EACvF,KAAK,MAAM,WAAW,eAAe,QAAQ,MAAM,GAAG;GACpD,SAAS,KAAK,OAAO;GACrB,IAAI,QAAQ,SAAS,KAAK,UAAU;IAAE,GAAG,QAAQ;IAAG,GAAG,QAAQ;GAAE;EACnE;CACF;CACA,SAAS,KAAK,EAAE,MAAM,IAAI,CAAC;CAC3B,OAAO;AACT"}
1
+ {"version":3,"file":"polygon.js","names":[],"sources":["../src/polygon.ts"],"sourcesContent":["import { polygonVertices } from './geometry'\nimport type { Vector } from './primitives'\nimport type { SceneNode } from './types'\n\n/**\n * Rounded polygon and star outlines, as Figma draws them. Each corner, convex or not, is rounded by\n * a circular arc tangent to both edges, capped so that it and its neighbours fit along every edge;\n * corner smoothing replaces the arc's ends with curves that ease into the edges, as on rectangles.\n */\n\n/** Figma keeps a polygon's sides or a star's points within this range, and its plugin API clamps to it. */\nexport const POINT_COUNT_RANGE = { min: 3, max: 60 } as const\n\nexport type PolygonOutlineCommand =\n | { type: 'M' | 'L'; x: number; y: number }\n | { type: 'C'; x1: number; y1: number; x2: number; y2: number; x: number; y: number }\n | { type: 'Z' }\n\ntype PolygonNode = Pick<\n SceneNode,\n | 'type'\n | 'width'\n | 'height'\n | 'pointCount'\n | 'starInnerRadius'\n | 'cornerRadius'\n | 'cornerSmoothing'\n>\n\nexport interface PolygonCorner {\n vertex: Vector\n /** The unit direction of the edge arriving at the vertex. */\n incoming: Vector\n /** The unit direction of the edge leaving the vertex. */\n outgoing: Vector\n /** How far the outline turns at the vertex, in radians: 0 for a straight line. */\n turn: number\n /** The radius the corner is drawn with, after fitting it along its edges. */\n radius: number\n /** How far along each edge from the vertex the rounding starts. */\n extent: number\n}\n\nconst sub = (a: Vector, b: Vector): Vector => ({ x: a.x - b.x, y: a.y - b.y })\nconst along = (point: Vector, direction: Vector, distance: number): Vector => ({\n x: point.x + direction.x * distance,\n y: point.y + direction.y * distance\n})\n\nfunction unit(vector: Vector): Vector {\n const length = Math.hypot(vector.x, vector.y)\n return length > 0 ? { x: vector.x / length, y: vector.y / length } : { x: 0, y: 0 }\n}\n\n/** The perpendicular of `direction` on the side the outline turns towards. */\nfunction inward(direction: Vector, towards: Vector): Vector {\n const normal = { x: -direction.y, y: direction.x }\n return normal.x * towards.x + normal.y * towards.y < 0\n ? { x: direction.y, y: -direction.x }\n : normal\n}\n\n/**\n * The polygon's or star's corners with the radius each is drawn with. A corner turning by α keeps\n * r·tan(α/2) of each edge, so on an edge of length L between corners turning by α and β the radius\n * is at most L / (tan(α/2) + tan(β/2)); each corner takes the least of its two edges' limits.\n */\nexport function polygonCorners(node: PolygonNode): PolygonCorner[] {\n const vertices = polygonVertices(node)\n const count = vertices.length\n const at = (index: number) => vertices[(index + count) % count]\n const shape = vertices.map((vertex, index) => {\n const incoming = unit(sub(vertex, at(index - 1)))\n const outgoing = unit(sub(at(index + 1), vertex))\n const cos = Math.min(1, Math.max(-1, incoming.x * outgoing.x + incoming.y * outgoing.y))\n const turn = Math.acos(cos)\n return { vertex, incoming, outgoing, turn, factor: Math.tan(turn / 2) }\n })\n const edgeLimit = (index: number) => {\n const from = shape[(index + count) % count]\n const to = shape[(index + 1 + count) % count]\n const length = Math.hypot(to.vertex.x - from.vertex.x, to.vertex.y - from.vertex.y)\n const factors = from.factor + to.factor\n return factors > 0 ? length / factors : Number.POSITIVE_INFINITY\n }\n const requested = Math.max(0, node.cornerRadius)\n return shape.map(({ factor, ...corner }, index) => {\n const radius = Math.min(requested, edgeLimit(index - 1), edgeLimit(index))\n return { ...corner, radius, extent: radius * factor }\n })\n}\n\ninterface SmoothCorner {\n /** Where the rounding starts, along each edge from the vertex. */\n p: number\n a: number\n b: number\n c: number\n d: number\n /** The angle each eased end takes from the arc, in radians. */\n ease: number\n}\n\n/**\n * Figma's smoothing for a corner turning by any angle: the rectangle construction with the\n * tangent length r·tan(α/2) in place of r and α/2 in place of 45°. Smoothing grows the rounded\n * part of each edge by up to its tangent length again.\n */\nfunction smoothCorner(corner: PolygonCorner, smoothing: number): SmoothCorner {\n const { radius, extent } = corner\n const p = (1 + smoothing) * extent\n const ease = (corner.turn * smoothing) / 2\n const toEase = radius * Math.tan(ease / 2)\n const c = toEase * Math.cos(ease)\n const d = toEase * Math.sin(ease)\n const arcStart = extent - radius * Math.sin(ease) - d\n const b = (p - arcStart - c - d) / 3\n return { p, a: 2 * b, b, c, d, ease }\n}\n\nfunction rotate(direction: Vector, towards: Vector, angle: number): Vector {\n const normal = inward(direction, towards)\n return {\n x: direction.x * Math.cos(angle) + normal.x * Math.sin(angle),\n y: direction.y * Math.cos(angle) + normal.y * Math.sin(angle)\n }\n}\n\nfunction cubic(c1: Vector, c2: Vector, to: Vector): PolygonOutlineCommand {\n return { type: 'C', x1: c1.x, y1: c1.y, x2: c2.x, y2: c2.y, x: to.x, y: to.y }\n}\n\n/** The rounded corner from where it leaves the incoming edge to where it joins the outgoing one. */\nfunction cornerCommands(corner: PolygonCorner, smooth: SmoothCorner): PolygonOutlineCommand[] {\n const { vertex, incoming, outgoing, radius, turn } = corner\n const { p, a, b, c, d, ease } = smooth\n const back = { x: -incoming.x, y: -incoming.y }\n const start = along(vertex, back, p)\n const end = along(vertex, outgoing, p)\n const normalIn = inward(incoming, outgoing)\n const normalOut = inward(outgoing, back)\n const arcFrom = along(along(start, incoming, a + b + c), normalIn, d)\n const arcTo = along(along(end, outgoing, -(a + b + c)), normalOut, d)\n const commands: PolygonOutlineCommand[] = []\n if (ease > 0)\n commands.push(cubic(along(start, incoming, a), along(start, incoming, a + b), arcFrom))\n const sweep = turn - 2 * ease\n if (sweep > 0) {\n const handle = (4 / 3) * Math.tan(sweep / 4) * radius\n const leaving = rotate(incoming, outgoing, ease)\n const arriving = rotate(outgoing, incoming, ease)\n commands.push(cubic(along(arcFrom, leaving, handle), along(arcTo, arriving, -handle), arcTo))\n }\n if (ease > 0) commands.push(cubic(along(end, outgoing, -(a + b)), along(end, outgoing, -a), end))\n return commands\n}\n\n/**\n * The smoothing every corner can take: on each edge a corner may use the part its tangent length\n * takes of both corners' tangent lengths, and Figma lowers smoothing for the whole shape to what\n * its tightest corner allows rather than corner by corner.\n */\nfunction fittedSmoothing(corners: readonly PolygonCorner[], smoothing: number): number {\n const count = corners.length\n const share = (corner: PolygonCorner, neighbour: PolygonCorner) => {\n const length = Math.hypot(\n neighbour.vertex.x - corner.vertex.x,\n neighbour.vertex.y - corner.vertex.y\n )\n return (length * corner.extent) / (corner.extent + neighbour.extent)\n }\n return corners.reduce(\n (fitted, corner, index) => {\n if (!(corner.extent > 0)) return fitted\n const budget = Math.min(\n share(corner, corners[(index - 1 + count) % count]),\n share(corner, corners[(index + 1) % count])\n )\n return Math.min(fitted, budget / corner.extent - 1)\n },\n Math.min(Math.max(smoothing, 0), 1)\n )\n}\n\n/** The outline of a polygon or star with its corner radius and smoothing, in its own pixels. */\nexport function polygonOutline(node: PolygonNode): PolygonOutlineCommand[] {\n const corners = polygonCorners(node)\n const smoothing = Math.max(0, fittedSmoothing(corners, node.cornerSmoothing))\n const commands: PolygonOutlineCommand[] = []\n let current: Vector | null = null\n // Corners whose rounding meets along an edge leave no line between them.\n const lineTo = ({ x, y }: Vector) => {\n if (current && Math.hypot(x - current.x, y - current.y) < 1e-6) return\n commands.push({ type: current ? 'L' : 'M', x, y })\n current = { x, y }\n }\n for (const corner of corners) {\n if (!(corner.radius > 0) || !(corner.turn > 0)) {\n lineTo(corner.vertex)\n continue\n }\n const smooth = smoothCorner(corner, smoothing)\n lineTo(along(corner.vertex, { x: -corner.incoming.x, y: -corner.incoming.y }, smooth.p))\n for (const command of cornerCommands(corner, smooth)) {\n commands.push(command)\n if (command.type === 'C') current = { x: command.x, y: command.y }\n }\n }\n commands.push({ type: 'Z' })\n return commands\n}\n"],"mappings":";;;;;;;;AAWA,MAAa,oBAA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SAAS;EAC7C,OAAO,MAAM,OAAO,QAAQ;GAAE,GAAG,CAAC,OAAO,SAAS;GAAG,GAAG,CAAC,OAAO,SAAS;EAAE,GAAG,OAAO,CAAC,CAAC;EACvF,KAAK,MAAM,WAAW,eAAe,QAAQ,MAAM,GAAG;GACpD,SAAS,KAAK,OAAO;GACrB,IAAI,QAAQ,SAAS,KAAK,UAAU;IAAE,GAAG,QAAQ;IAAG,GAAG,QAAQ;GAAE;EACnE;CACF;CACA,SAAS,KAAK,EAAE,MAAM,IAAI,CAAC;CAC3B,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"resize.d.ts","names":[],"sources":["../src/resize.ts"],"mappings":";;;;;;;;;KAuBY,iBAAiB,KAC3B;UAiBQ;WACC;EACT,QAAQ,aAAa;;;KAeX,kBAAkB;EAAS;EAAkB;;;iBAkDzC,iBACd,QAAQ,MACR,MAAM,KAAK,2BACX,YAAY,gBACZ,UAAU,iBACT;;;;;iBA4Ba,qBACd,OAAO,MACP,cAAc,KAAK,2BACnB,aAAa,KAAK,2BAClB,YAAY,gBACZ,UAAU,gBACV,8BACC;iBAca,gBACd,OAAO,MACP,cAAc,KAAK,2BACnB,aAAa,KAAK,4BACjB;iBASa,4BACd,eAAe,sBACf,uBACA,wBACA,eACA,iBACC;;iBA6Ba,qBAAqB,MAAM,YAAY;;;;;;;iBAoDvC,sBACd,MAAM,KACJ,kJAUF,mBACA,oBACA,eACA,iBACC,QAAQ;iBAsFK,yBACd,OAAO,aACP,iBACC,YAAY;;;;;iBAwBC,YACd,MAAM,KAAK,+BACX,SAAS,KAAK,+BACd,kBACA,mBACC,QAAQ,KAAK;KASX,OAAO,KAAK;;;;;iBAmJD,gCACd,OAAO,aACP,gBACA,YAAY,MACZ,WAAW,MACX,WAAW,oBAAoB,kBAC9B,YAAY,QAAQ"}
1
+ {"version":3,"file":"resize.d.ts","names":[],"sources":["../src/resize.ts"],"mappings":";;;;;;;;;KAwBY,iBAAiB,KAC3B;UAiBQ;WACC;EACT,QAAQ,aAAa;;;KAeX,kBAAkB;EAAS;EAAkB;;;iBAkDzC,iBACd,QAAQ,MACR,MAAM,KAAK,2BACX,YAAY,gBACZ,UAAU,iBACT;;;;;iBA4Ba,qBACd,OAAO,MACP,cAAc,KAAK,2BACnB,aAAa,KAAK,2BAClB,YAAY,gBACZ,UAAU,gBACV,8BACC;iBAca,gBACd,OAAO,MACP,cAAc,KAAK,2BACnB,aAAa,KAAK,4BACjB;iBASa,4BACd,eAAe,sBACf,uBACA,wBACA,eACA,iBACC;;iBA6Ba,qBAAqB,MAAM,YAAY;;;;;;;iBAoDvC,sBACd,MAAM,KACJ,kJAUF,mBACA,oBACA,eACA,iBACC,QAAQ;iBAoFK,yBACd,OAAO,aACP,iBACC,YAAY;;;;;iBAwBC,YACd,MAAM,KAAK,+BACX,SAAS,KAAK,+BACd,kBACA,mBACC,QAAQ,KAAK;KASX,OAAO,KAAK;;;;;iBAmJD,gCACd,OAAO,aACP,gBACA,YAAY,MACZ,WAAW,MACX,WAAW,oBAAoB,kBAC9B,YAAY,QAAQ"}
package/dist/resize.js CHANGED
@@ -5,6 +5,7 @@ import { cloneVectorNetwork, copyDerivedGlyphs, copyGeometryPaths, copyStroke, c
5
5
  import { CONSTRAINT_PARENT_TYPES } from "./constraints.js";
6
6
  import { groupFitChanges } from "./group-bounds.js";
7
7
  import { enforcedAspectRatio } from "./layout/aspect-ratio.js";
8
+ import { followsPath } from "./text/path.js";
8
9
  //#region src/resize.ts
9
10
  /**
10
11
  * Containers whose resize moves their children: the constraint parents, and groups and booleans,
@@ -215,10 +216,9 @@ function scaledGeometryChanges(orig, origWidth, origHeight, width, height) {
215
216
  if (orig.fillGeometry.length > 0) changes.fillGeometry = scaleGeometryPaths(orig.fillGeometry, sx, sy);
216
217
  const outlineOnly = orig.type === "TEXT" || orig.type === "VECTOR" && !hasPath(orig);
217
218
  if (orig.strokeGeometry.length > 0) changes.strokeGeometry = outlineOnly ? scaleGeometryPaths(orig.strokeGeometry, sx, sy) : [];
218
- const glyphs = orig.derivedTextGlyphs ?? [];
219
- const pathText = !!orig.textPathData || !!orig.textPathBox || glyphs.some((glyph) => (glyph.rotation ?? 0) !== 0);
220
- if (glyphs.length > 0 && pathText) {
221
- changes.derivedTextGlyphs = scaleDerivedGlyphs(glyphs, sx, sy);
219
+ const pathText = followsPath(orig);
220
+ if (pathText) {
221
+ changes.derivedTextGlyphs = scaleDerivedGlyphs(orig.derivedTextGlyphs, sx, sy);
222
222
  if (orig.textPathBox) changes.textPathBox = {
223
223
  x: orig.textPathBox.x * sx,
224
224
  y: orig.textPathBox.y * sy,
@@ -226,7 +226,7 @@ function scaledGeometryChanges(orig, origWidth, origHeight, width, height) {
226
226
  height: orig.textPathBox.height * sy
227
227
  };
228
228
  }
229
- if (orig.strokes.length > 0 && glyphs.length > 0 && pathText) changes.strokes = scaleStrokes(orig.strokes, sx, sy);
229
+ if (orig.strokes.length > 0 && pathText) changes.strokes = scaleStrokes(orig.strokes, sx, sy);
230
230
  return changes;
231
231
  }
232
232
  /** Copies of the geometry a resize may change, as the snapshot held it before the resize. */