@asyra/preset 0.5.8 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (257) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +2 -2
  3. package/dist/agent-activity.d.ts +61 -0
  4. package/dist/agent-activity.d.ts.map +1 -0
  5. package/dist/agent-activity.js +224 -0
  6. package/dist/agent-activity.js.map +1 -0
  7. package/dist/catalog.d.ts.map +1 -1
  8. package/dist/catalog.js +2 -2
  9. package/dist/catalog.js.map +1 -1
  10. package/dist/cleanup-reporter.d.ts.map +1 -1
  11. package/dist/cleanup-reporter.js.map +1 -1
  12. package/dist/components/fills.d.ts +3 -1
  13. package/dist/components/fills.d.ts.map +1 -1
  14. package/dist/components/fills.js +74 -0
  15. package/dist/components/fills.js.map +1 -1
  16. package/dist/components/frame.d.ts +2 -2
  17. package/dist/components/frame.d.ts.map +1 -1
  18. package/dist/components/frame.js +1 -0
  19. package/dist/components/frame.js.map +1 -1
  20. package/dist/components/group.d.ts +9 -21
  21. package/dist/components/group.d.ts.map +1 -1
  22. package/dist/components/group.js +188 -84
  23. package/dist/components/group.js.map +1 -1
  24. package/dist/components/oval.d.ts +2 -2
  25. package/dist/components/oval.d.ts.map +1 -1
  26. package/dist/components/oval.js +3 -1
  27. package/dist/components/oval.js.map +1 -1
  28. package/dist/components/rectangle.d.ts +2 -2
  29. package/dist/components/rectangle.d.ts.map +1 -1
  30. package/dist/components/rectangle.js +3 -1
  31. package/dist/components/rectangle.js.map +1 -1
  32. package/dist/components/shape-hit-area.d.ts.map +1 -1
  33. package/dist/components/shape-hit-area.js.map +1 -1
  34. package/dist/components/text.d.ts +9 -0
  35. package/dist/components/text.d.ts.map +1 -0
  36. package/dist/components/text.js +61 -0
  37. package/dist/components/text.js.map +1 -0
  38. package/dist/components/vector-compound-fill.d.ts +8 -0
  39. package/dist/components/vector-compound-fill.d.ts.map +1 -0
  40. package/dist/components/vector-compound-fill.js +149 -0
  41. package/dist/components/vector-compound-fill.js.map +1 -0
  42. package/dist/components/vector.d.ts.map +1 -1
  43. package/dist/components/vector.js +85 -565
  44. package/dist/components/vector.js.map +1 -1
  45. package/dist/composition/error.d.ts.map +1 -1
  46. package/dist/composition/error.js.map +1 -1
  47. package/dist/composition/profile-provider.d.ts +2 -1
  48. package/dist/composition/profile-provider.d.ts.map +1 -1
  49. package/dist/composition/profile-provider.js +8 -2
  50. package/dist/composition/profile-provider.js.map +1 -1
  51. package/dist/composition/resolve.d.ts +2 -0
  52. package/dist/composition/resolve.d.ts.map +1 -1
  53. package/dist/composition/resolve.js +30 -6
  54. package/dist/composition/resolve.js.map +1 -1
  55. package/dist/defaults/install.d.ts.map +1 -1
  56. package/dist/defaults/install.js +2 -1
  57. package/dist/defaults/install.js.map +1 -1
  58. package/dist/defaults/installation.d.ts.map +1 -1
  59. package/dist/defaults/installation.js +2 -0
  60. package/dist/defaults/installation.js.map +1 -1
  61. package/dist/defaults/modules/selection.d.ts.map +1 -1
  62. package/dist/defaults/modules/selection.js.map +1 -1
  63. package/dist/defaults/modules/vector-editing.d.ts.map +1 -1
  64. package/dist/defaults/modules/vector-editing.js.map +1 -1
  65. package/dist/defaults/owned-state.d.ts.map +1 -1
  66. package/dist/defaults/owned-state.js.map +1 -1
  67. package/dist/defaults/private-manager.d.ts.map +1 -1
  68. package/dist/defaults/private-manager.js +2 -1
  69. package/dist/defaults/private-manager.js.map +1 -1
  70. package/dist/events/preset-event-names.d.ts +2 -0
  71. package/dist/events/preset-event-names.d.ts.map +1 -1
  72. package/dist/events/register-events.d.ts.map +1 -1
  73. package/dist/events/register-events.js +4 -2
  74. package/dist/events/register-events.js.map +1 -1
  75. package/dist/group-bounds.d.ts +36 -0
  76. package/dist/group-bounds.d.ts.map +1 -0
  77. package/dist/group-bounds.js +141 -0
  78. package/dist/group-bounds.js.map +1 -0
  79. package/dist/index.d.ts +3 -0
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +2 -0
  82. package/dist/index.js.map +1 -1
  83. package/dist/preset.d.ts.map +1 -1
  84. package/dist/preset.js +5 -3
  85. package/dist/preset.js.map +1 -1
  86. package/dist/props/components/anchor-points-component.d.ts.map +1 -1
  87. package/dist/props/components/anchor-points-component.js.map +1 -1
  88. package/dist/props/components/children-map-property-component.d.ts.map +1 -1
  89. package/dist/props/components/children-map-property-component.js.map +1 -1
  90. package/dist/props/components/fills-component.d.ts.map +1 -1
  91. package/dist/props/components/fills-component.js +3 -2
  92. package/dist/props/components/fills-component.js.map +1 -1
  93. package/dist/props/components/position-component.js +1 -1
  94. package/dist/props/components/position-component.js.map +1 -1
  95. package/dist/props/components/strokes-component.d.ts.map +1 -1
  96. package/dist/props/components/strokes-component.js +4 -3
  97. package/dist/props/components/strokes-component.js.map +1 -1
  98. package/dist/props/components/text-component.d.ts +67 -0
  99. package/dist/props/components/text-component.d.ts.map +1 -0
  100. package/dist/props/components/text-component.js +128 -0
  101. package/dist/props/components/text-component.js.map +1 -0
  102. package/dist/props/components/vector-networks-component.d.ts.map +1 -1
  103. package/dist/props/components/vector-networks-component.js.map +1 -1
  104. package/dist/props/components/vector-points-component.d.ts.map +1 -1
  105. package/dist/props/components/vector-points-component.js.map +1 -1
  106. package/dist/props/components/vector-segments-component.d.ts.map +1 -1
  107. package/dist/props/components/vector-segments-component.js.map +1 -1
  108. package/dist/props/register-property-schemas.d.ts.map +1 -1
  109. package/dist/props/register-property-schemas.js +6 -0
  110. package/dist/props/register-property-schemas.js.map +1 -1
  111. package/dist/render-layers/selection-overlay-render-layer.d.ts.map +1 -1
  112. package/dist/render-layers/selection-overlay-render-layer.js +7 -2
  113. package/dist/render-layers/selection-overlay-render-layer.js.map +1 -1
  114. package/dist/render-layers/vector-path-editing-render-layer.d.ts.map +1 -1
  115. package/dist/render-layers/vector-path-editing-render-layer.js.map +1 -1
  116. package/dist/selection/ids.d.ts.map +1 -1
  117. package/dist/selection/ids.js.map +1 -1
  118. package/dist/selection/register-default-selections.d.ts.map +1 -1
  119. package/dist/selection/register-default-selections.js +4 -2
  120. package/dist/selection/register-default-selections.js.map +1 -1
  121. package/dist/spatial/assets/binary.d.ts +22 -0
  122. package/dist/spatial/assets/binary.d.ts.map +1 -0
  123. package/dist/spatial/assets/binary.js +132 -0
  124. package/dist/spatial/assets/binary.js.map +1 -0
  125. package/dist/spatial/assets/decode.d.ts +23 -0
  126. package/dist/spatial/assets/decode.d.ts.map +1 -0
  127. package/dist/spatial/assets/decode.js +102 -0
  128. package/dist/spatial/assets/decode.js.map +1 -0
  129. package/dist/spatial/assets/preview-worker.d.ts +13 -0
  130. package/dist/spatial/assets/preview-worker.d.ts.map +1 -0
  131. package/dist/spatial/assets/preview-worker.js +188 -0
  132. package/dist/spatial/assets/preview-worker.js.map +1 -0
  133. package/dist/spatial/assets/scene.d.ts +13 -0
  134. package/dist/spatial/assets/scene.d.ts.map +1 -0
  135. package/dist/spatial/assets/scene.js +99 -0
  136. package/dist/spatial/assets/scene.js.map +1 -0
  137. package/dist/spatial/assets/schema.d.ts +22 -0
  138. package/dist/spatial/assets/schema.d.ts.map +1 -0
  139. package/dist/spatial/assets/schema.js +93 -0
  140. package/dist/spatial/assets/schema.js.map +1 -0
  141. package/dist/spatial/bounds.d.ts +15 -0
  142. package/dist/spatial/bounds.d.ts.map +1 -0
  143. package/dist/spatial/bounds.js +94 -0
  144. package/dist/spatial/bounds.js.map +1 -0
  145. package/dist/spatial/camera-controls.d.ts +53 -0
  146. package/dist/spatial/camera-controls.d.ts.map +1 -0
  147. package/dist/spatial/camera-controls.js +208 -0
  148. package/dist/spatial/camera-controls.js.map +1 -0
  149. package/dist/spatial/components.d.ts +20 -0
  150. package/dist/spatial/components.d.ts.map +1 -0
  151. package/dist/spatial/components.js +83 -0
  152. package/dist/spatial/components.js.map +1 -0
  153. package/dist/spatial/editing.d.ts +51 -0
  154. package/dist/spatial/editing.d.ts.map +1 -0
  155. package/dist/spatial/editing.js +152 -0
  156. package/dist/spatial/editing.js.map +1 -0
  157. package/dist/spatial/emissive-bloom.d.ts +22 -0
  158. package/dist/spatial/emissive-bloom.d.ts.map +1 -0
  159. package/dist/spatial/emissive-bloom.js +197 -0
  160. package/dist/spatial/emissive-bloom.js.map +1 -0
  161. package/dist/spatial/graphics.d.ts +9 -0
  162. package/dist/spatial/graphics.d.ts.map +1 -0
  163. package/dist/spatial/graphics.js +119 -0
  164. package/dist/spatial/graphics.js.map +1 -0
  165. package/dist/spatial/lazy-engine.d.ts +6 -0
  166. package/dist/spatial/lazy-engine.d.ts.map +1 -0
  167. package/dist/spatial/lazy-engine.js +92 -0
  168. package/dist/spatial/lazy-engine.js.map +1 -0
  169. package/dist/spatial/lighting.d.ts +28 -0
  170. package/dist/spatial/lighting.d.ts.map +1 -0
  171. package/dist/spatial/lighting.js +103 -0
  172. package/dist/spatial/lighting.js.map +1 -0
  173. package/dist/spatial/opaque-frame.d.ts +11 -0
  174. package/dist/spatial/opaque-frame.d.ts.map +1 -0
  175. package/dist/spatial/opaque-frame.js +131 -0
  176. package/dist/spatial/opaque-frame.js.map +1 -0
  177. package/dist/spatial/pose.d.ts +22 -0
  178. package/dist/spatial/pose.d.ts.map +1 -0
  179. package/dist/spatial/pose.js +83 -0
  180. package/dist/spatial/pose.js.map +1 -0
  181. package/dist/spatial/presentation.d.ts +16 -0
  182. package/dist/spatial/presentation.d.ts.map +1 -0
  183. package/dist/spatial/presentation.js +66 -0
  184. package/dist/spatial/presentation.js.map +1 -0
  185. package/dist/spatial/reflection-environment.d.ts +13 -0
  186. package/dist/spatial/reflection-environment.d.ts.map +1 -0
  187. package/dist/spatial/reflection-environment.js +63 -0
  188. package/dist/spatial/reflection-environment.js.map +1 -0
  189. package/dist/spatial/registration.d.ts +6 -0
  190. package/dist/spatial/registration.d.ts.map +1 -0
  191. package/dist/spatial/registration.js +82 -0
  192. package/dist/spatial/registration.js.map +1 -0
  193. package/dist/spatial/shadow-frame.d.ts +13 -0
  194. package/dist/spatial/shadow-frame.d.ts.map +1 -0
  195. package/dist/spatial/shadow-frame.js +60 -0
  196. package/dist/spatial/shadow-frame.js.map +1 -0
  197. package/dist/spatial/spatial-contract.d.ts +10 -0
  198. package/dist/spatial/spatial-contract.d.ts.map +1 -0
  199. package/dist/spatial/spatial-contract.js +414 -0
  200. package/dist/spatial/spatial-contract.js.map +1 -0
  201. package/dist/spatial/spatial-layer.d.ts +47 -0
  202. package/dist/spatial/spatial-layer.d.ts.map +1 -0
  203. package/dist/spatial/spatial-layer.js +224 -0
  204. package/dist/spatial/spatial-layer.js.map +1 -0
  205. package/dist/spatial/surface-contract.d.ts +4 -0
  206. package/dist/spatial/surface-contract.d.ts.map +1 -0
  207. package/dist/spatial/surface-contract.js +40 -0
  208. package/dist/spatial/surface-contract.js.map +1 -0
  209. package/dist/spatial/surface-textures.d.ts +8 -0
  210. package/dist/spatial/surface-textures.d.ts.map +1 -0
  211. package/dist/spatial/surface-textures.js +46 -0
  212. package/dist/spatial/surface-textures.js.map +1 -0
  213. package/dist/spatial/three-engine.d.ts +91 -0
  214. package/dist/spatial/three-engine.d.ts.map +1 -0
  215. package/dist/spatial/three-engine.js +1127 -0
  216. package/dist/spatial/three-engine.js.map +1 -0
  217. package/dist/spatial/transmission-capture.d.ts +13 -0
  218. package/dist/spatial/transmission-capture.d.ts.map +1 -0
  219. package/dist/spatial/transmission-capture.js +215 -0
  220. package/dist/spatial/transmission-capture.js.map +1 -0
  221. package/dist/spatial-assets.d.ts +4 -0
  222. package/dist/spatial-assets.d.ts.map +1 -0
  223. package/dist/spatial-assets.js +4 -0
  224. package/dist/spatial-assets.js.map +1 -0
  225. package/dist/spatial-contract.d.ts +3 -0
  226. package/dist/spatial-contract.d.ts.map +1 -0
  227. package/dist/spatial-contract.js +3 -0
  228. package/dist/spatial-contract.js.map +1 -0
  229. package/dist/spatial-engine.d.ts +5 -0
  230. package/dist/spatial-engine.d.ts.map +1 -0
  231. package/dist/spatial-engine.js +5 -0
  232. package/dist/spatial-engine.js.map +1 -0
  233. package/dist/spatial.d.ts +9 -0
  234. package/dist/spatial.d.ts.map +1 -0
  235. package/dist/spatial.js +9 -0
  236. package/dist/spatial.js.map +1 -0
  237. package/dist/subscriptions/data-channel.d.ts.map +1 -1
  238. package/dist/subscriptions/data-channel.js +372 -124
  239. package/dist/subscriptions/data-channel.js.map +1 -1
  240. package/dist/subscriptions/render-system.d.ts.map +1 -1
  241. package/dist/subscriptions/render-system.js +4 -2
  242. package/dist/subscriptions/render-system.js.map +1 -1
  243. package/dist/subscriptions/shared-channels.d.ts.map +1 -1
  244. package/dist/subscriptions/shared-channels.js +4 -2
  245. package/dist/subscriptions/shared-channels.js.map +1 -1
  246. package/dist/subscriptions/vector-selection.d.ts +4 -0
  247. package/dist/subscriptions/vector-selection.d.ts.map +1 -0
  248. package/dist/subscriptions/vector-selection.js +175 -0
  249. package/dist/subscriptions/vector-selection.js.map +1 -0
  250. package/dist/types.d.ts +2 -0
  251. package/dist/types.d.ts.map +1 -1
  252. package/dist/ui/register-properties.d.ts.map +1 -1
  253. package/dist/ui/register-properties.js +3 -2
  254. package/dist/ui/register-properties.js.map +1 -1
  255. package/dist/vector/synthetic-handle.d.ts.map +1 -1
  256. package/dist/vector/synthetic-handle.js.map +1 -1
  257. package/package.json +43 -11
@@ -1,7 +1,8 @@
1
1
  import { PropertyTypes, StrokeJoinTypes, createDefaultStroke, emitDiagnosticCounter, isRecord, setElementGeometryLocalBounds } from '@asyra/utils';
2
- import core, { VECTOR_TOKENS, isVectorAnchorNode as isAnchorNode, isPointInsidePreparedEvenOddShape, prepareEvenOddShape, sortVectorItemsById } from '@asyra/core';
3
- import { DEFAULT_VECTOR_FILLS, applyRenderableFill, getRenderableFill, getRenderableFills } from './fills.js';
2
+ import core, { VECTOR_TOKENS, RenderGraphics, isVectorAnchorNode as isAnchorNode, sortVectorItemsById } from '@asyra/core';
3
+ import { DEFAULT_VECTOR_FILLS, getRenderableFill, toMeshProjectionPaint } from './fills.js';
4
4
  import { PRESET_REGISTRATION } from '../registration.js';
5
+ import { prepareVectorCompoundFill } from './vector-compound-fill.js';
5
6
  const emitVectorRenderCounter = emitDiagnosticCounter;
6
7
  const normalizeRawPathTopologyFillRule = (value) => (value === 'evenodd' ? 'evenodd' : 'nonzero');
7
8
  const isNormalizedVectorRenderDataInput = (data) => {
@@ -89,12 +90,6 @@ const getControlNode = (points, pointId) => {
89
90
  }
90
91
  return point;
91
92
  };
92
- const MIN_FLATTEN_STEPS = 12;
93
- const MAX_FLATTEN_STEPS = 64;
94
- const DEFAULT_FLATTEN_SEGMENT_LENGTH = 12;
95
- const INTERSECTION_EPS = 1e-6;
96
- const NODE_KEY_EPS = 1e-4;
97
- const MAX_OPEN_SEGMENTS = 1200;
98
93
  const MIN_VECTOR_RENDER_SIZE = 0.1;
99
94
  const cubicBezierPoint = (p0, p1, p2, p3, t) => {
100
95
  const u = 1 - t;
@@ -181,409 +176,6 @@ const calculateVectorLocalBounds = (points, segments, networks) => {
181
176
  height: bounds.maxY - bounds.minY || MIN_VECTOR_RENDER_SIZE
182
177
  };
183
178
  };
184
- const estimateCurveLength = (p0, p1, p2, p3) => Math.hypot(p1.x - p0.x, p1.y - p0.y) +
185
- Math.hypot(p2.x - p1.x, p2.y - p1.y) +
186
- Math.hypot(p3.x - p2.x, p3.y - p2.y);
187
- const getFlattenStepsForTarget = (p0, p1, p2, p3, targetSegmentLength, minSteps, maxSteps) => {
188
- const length = estimateCurveLength(p0, p1, p2, p3);
189
- const steps = Math.ceil(length / targetSegmentLength);
190
- return Math.max(minSteps, Math.min(maxSteps, steps));
191
- };
192
- const getFlattenSteps = (p0, p1, p2, p3) => getFlattenStepsForTarget(p0, p1, p2, p3, DEFAULT_FLATTEN_SEGMENT_LENGTH, MIN_FLATTEN_STEPS, MAX_FLATTEN_STEPS);
193
- const toSegmentKeyCoord = (value) => value === null || value === undefined ? 'n' : `${value}`;
194
- const buildSegmentKey = (start, end, outControl, inControl) => [
195
- toSegmentKeyCoord(start.x),
196
- toSegmentKeyCoord(start.y),
197
- toSegmentKeyCoord(end.x),
198
- toSegmentKeyCoord(end.y),
199
- toSegmentKeyCoord(outControl?.x),
200
- toSegmentKeyCoord(outControl?.y),
201
- toSegmentKeyCoord(inControl?.x),
202
- toSegmentKeyCoord(inControl?.y)
203
- ].join('|');
204
- const polygonArea = (points) => {
205
- if (points.length < 3) {
206
- return 0;
207
- }
208
- let area = 0;
209
- for (let i = 0; i < points.length; i += 1) {
210
- const next = (i + 1) % points.length;
211
- area += points[i].x * points[next].y - points[next].x * points[i].y;
212
- }
213
- return area / 2;
214
- };
215
- const flattenCubic = (p0, p1, p2, p3, steps) => {
216
- const points = [p0];
217
- for (let i = 1; i <= steps; i += 1) {
218
- const t = i / steps;
219
- points.push(cubicBezierPoint(p0, p1, p2, p3, t));
220
- }
221
- return points;
222
- };
223
- const cross = (a, b) => a.x * b.y - a.y * b.x;
224
- const segmentIntersection = (a, b, c, d) => {
225
- const r = { x: b.x - a.x, y: b.y - a.y };
226
- const s = { x: d.x - c.x, y: d.y - c.y };
227
- const denom = cross(r, s);
228
- if (Math.abs(denom) <= INTERSECTION_EPS) {
229
- return null;
230
- }
231
- const cma = { x: c.x - a.x, y: c.y - a.y };
232
- const t = cross(cma, s) / denom;
233
- const u = cross(cma, r) / denom;
234
- if (t <= INTERSECTION_EPS ||
235
- t >= 1 - INTERSECTION_EPS ||
236
- u <= INTERSECTION_EPS ||
237
- u >= 1 - INTERSECTION_EPS) {
238
- return null;
239
- }
240
- return {
241
- t,
242
- u,
243
- point: {
244
- x: a.x + r.x * t,
245
- y: a.y + r.y * t
246
- }
247
- };
248
- };
249
- const uniqueSorted = (values) => {
250
- const sorted = [...values].sort((a, b) => a - b);
251
- const result = [];
252
- sorted.forEach((value) => {
253
- const last = result[result.length - 1];
254
- if (last === undefined || Math.abs(value - last) > INTERSECTION_EPS) {
255
- result.push(value);
256
- }
257
- });
258
- return result;
259
- };
260
- const toNodeKey = (point) => `${Math.round(point.x / NODE_KEY_EPS)},${Math.round(point.y / NODE_KEY_EPS)}`;
261
- const splitSegmentsByIntersections = (segments) => {
262
- const splitParams = segments.map(() => [0, 1]);
263
- if (segments.length < 2) {
264
- return segments;
265
- }
266
- const bounds = segments.map((segment) => {
267
- const minX = Math.min(segment.start.x, segment.end.x);
268
- const maxX = Math.max(segment.start.x, segment.end.x);
269
- const minY = Math.min(segment.start.y, segment.end.y);
270
- const maxY = Math.max(segment.start.y, segment.end.y);
271
- return { minX, maxX, minY, maxY };
272
- });
273
- const avgLength = segments.reduce((sum, segment) => sum +
274
- Math.hypot(segment.end.x - segment.start.x, segment.end.y - segment.start.y), 0) / segments.length;
275
- const cellSize = Math.max(12, Math.min(64, avgLength || 12));
276
- const toCell = (value) => Math.floor(value / cellSize);
277
- const cellMap = new Map();
278
- bounds.forEach((box, index) => {
279
- const startX = toCell(box.minX);
280
- const endX = toCell(box.maxX);
281
- const startY = toCell(box.minY);
282
- const endY = toCell(box.maxY);
283
- for (let x = startX; x <= endX; x += 1) {
284
- for (let y = startY; y <= endY; y += 1) {
285
- const key = `${x},${y}`;
286
- const list = cellMap.get(key);
287
- if (list) {
288
- list.push(index);
289
- }
290
- else {
291
- cellMap.set(key, [index]);
292
- }
293
- }
294
- }
295
- });
296
- const seen = new Int32Array(segments.length);
297
- let stamp = 0;
298
- for (let i = 0; i < segments.length; i += 1) {
299
- stamp += 1;
300
- const candidateIndices = [];
301
- const box = bounds[i];
302
- const startX = toCell(box.minX);
303
- const endX = toCell(box.maxX);
304
- const startY = toCell(box.minY);
305
- const endY = toCell(box.maxY);
306
- for (let x = startX; x <= endX; x += 1) {
307
- for (let y = startY; y <= endY; y += 1) {
308
- const list = cellMap.get(`${x},${y}`);
309
- if (!list) {
310
- continue;
311
- }
312
- for (const j of list) {
313
- if (j <= i) {
314
- continue;
315
- }
316
- if (seen[j] === stamp) {
317
- continue;
318
- }
319
- seen[j] = stamp;
320
- candidateIndices.push(j);
321
- }
322
- }
323
- }
324
- for (const j of candidateIndices) {
325
- const other = bounds[j];
326
- if (box.maxX < other.minX - INTERSECTION_EPS ||
327
- box.minX > other.maxX + INTERSECTION_EPS ||
328
- box.maxY < other.minY - INTERSECTION_EPS ||
329
- box.minY > other.maxY + INTERSECTION_EPS) {
330
- continue;
331
- }
332
- const hit = segmentIntersection(segments[i].start, segments[i].end, segments[j].start, segments[j].end);
333
- if (!hit) {
334
- continue;
335
- }
336
- splitParams[i].push(hit.t);
337
- splitParams[j].push(hit.u);
338
- }
339
- }
340
- const result = [];
341
- segments.forEach((segment, index) => {
342
- const params = uniqueSorted(splitParams[index]);
343
- for (let i = 0; i < params.length - 1; i += 1) {
344
- const t0 = params[i];
345
- const t1 = params[i + 1];
346
- if (t1 - t0 <= INTERSECTION_EPS) {
347
- continue;
348
- }
349
- const start = {
350
- x: segment.start.x + (segment.end.x - segment.start.x) * t0,
351
- y: segment.start.y + (segment.end.y - segment.start.y) * t0
352
- };
353
- const end = {
354
- x: segment.start.x + (segment.end.x - segment.start.x) * t1,
355
- y: segment.start.y + (segment.end.y - segment.start.y) * t1
356
- };
357
- if (Math.hypot(end.x - start.x, end.y - start.y) <= INTERSECTION_EPS) {
358
- continue;
359
- }
360
- result.push({ start, end });
361
- }
362
- });
363
- return result;
364
- };
365
- const buildFlattenedSegmentsWithCache = (orderedNetworks, points, segments, cache, pointOffset) => {
366
- const prevKeyMap = cache?.segmentKeyMap ?? {};
367
- const prevLinesMap = cache?.segmentLinesMap ?? {};
368
- const nextKeyMap = {};
369
- const nextLinesMap = {};
370
- const flattenedSegments = [];
371
- orderedNetworks.forEach((network) => {
372
- network.segmentIds.forEach((segmentId) => {
373
- const segment = segments[segmentId];
374
- if (!segment) {
375
- return;
376
- }
377
- const start = getAnchorNode(points, segment.startId);
378
- const end = getAnchorNode(points, segment.endId);
379
- if (!start || !end) {
380
- return;
381
- }
382
- const outControl = getControlNode(points, segment.outControlId);
383
- const inControl = getControlNode(points, segment.inControlId);
384
- const startPos = {
385
- x: start.x - pointOffset.x,
386
- y: start.y - pointOffset.y
387
- };
388
- const endPos = {
389
- x: end.x - pointOffset.x,
390
- y: end.y - pointOffset.y
391
- };
392
- const outControlPos = outControl
393
- ? {
394
- x: outControl.x - pointOffset.x,
395
- y: outControl.y - pointOffset.y
396
- }
397
- : null;
398
- const inControlPos = inControl
399
- ? {
400
- x: inControl.x - pointOffset.x,
401
- y: inControl.y - pointOffset.y
402
- }
403
- : null;
404
- const key = buildSegmentKey(startPos, endPos, outControlPos, inControlPos);
405
- let lines = prevLinesMap[segmentId];
406
- if (!lines || prevKeyMap[segmentId] !== key) {
407
- if (!outControlPos && !inControlPos) {
408
- lines = [{ start: startPos, end: endPos }];
409
- }
410
- else {
411
- const p0 = startPos;
412
- const p1 = outControlPos ?? p0;
413
- const p3 = endPos;
414
- const p2 = inControlPos ?? p3;
415
- const pointsOnCurve = flattenCubic(p0, p1, p2, p3, getFlattenSteps(p0, p1, p2, p3));
416
- lines = [];
417
- for (let i = 0; i < pointsOnCurve.length - 1; i += 1) {
418
- lines.push({
419
- start: pointsOnCurve[i],
420
- end: pointsOnCurve[i + 1]
421
- });
422
- }
423
- }
424
- }
425
- if (!lines) {
426
- return;
427
- }
428
- nextKeyMap[segmentId] = key;
429
- nextLinesMap[segmentId] = lines;
430
- flattenedSegments.push(...lines);
431
- });
432
- });
433
- const directedSegments = flattenedSegments;
434
- return {
435
- flattenedSegments,
436
- directedSegments,
437
- segmentKeyMap: nextKeyMap,
438
- segmentLinesMap: nextLinesMap
439
- };
440
- };
441
- const polygonCentroid = (points) => {
442
- const area = polygonArea(points);
443
- if (Math.abs(area) <= INTERSECTION_EPS) {
444
- const sum = points.reduce((acc, point) => ({ x: acc.x + point.x, y: acc.y + point.y }), { x: 0, y: 0 });
445
- return {
446
- x: sum.x / points.length,
447
- y: sum.y / points.length
448
- };
449
- }
450
- let cx = 0;
451
- let cy = 0;
452
- for (let i = 0; i < points.length; i += 1) {
453
- const next = (i + 1) % points.length;
454
- const crossValue = points[i].x * points[next].y - points[next].x * points[i].y;
455
- cx += (points[i].x + points[next].x) * crossValue;
456
- cy += (points[i].y + points[next].y) * crossValue;
457
- }
458
- const factor = 1 / (6 * area);
459
- return { x: cx * factor, y: cy * factor };
460
- };
461
- const evenOddContains = (point, segments) => {
462
- let inside = false;
463
- const { x, y } = point;
464
- segments.forEach((segment) => {
465
- const p1 = segment.start;
466
- const p2 = segment.end;
467
- if (p1.y > y === p2.y > y) {
468
- return;
469
- }
470
- const t = (y - p1.y) / (p2.y - p1.y);
471
- if (t <= INTERSECTION_EPS || t >= 1 - INTERSECTION_EPS) {
472
- return;
473
- }
474
- const intersectX = p1.x + (p2.x - p1.x) * t;
475
- if (intersectX > x + INTERSECTION_EPS) {
476
- inside = !inside;
477
- }
478
- });
479
- return inside;
480
- };
481
- const buildFillFaces = (flattenedSegments, directedSegments) => {
482
- if (flattenedSegments.length > MAX_OPEN_SEGMENTS) {
483
- return [];
484
- }
485
- const splitSegments = splitSegmentsByIntersections(flattenedSegments);
486
- if (splitSegments.length === 0) {
487
- return [];
488
- }
489
- const nodes = new Map();
490
- const pointsList = [];
491
- const getNodeId = (point) => {
492
- const key = toNodeKey(point);
493
- const existing = nodes.get(key);
494
- if (existing !== undefined) {
495
- return existing;
496
- }
497
- const id = pointsList.length;
498
- nodes.set(key, id);
499
- pointsList.push(point);
500
- return id;
501
- };
502
- const edges = [];
503
- const adjacency = [];
504
- const ensureAdj = (nodeId) => {
505
- if (!adjacency[nodeId]) {
506
- adjacency[nodeId] = [];
507
- }
508
- };
509
- splitSegments.forEach((segment) => {
510
- const from = getNodeId(segment.start);
511
- const to = getNodeId(segment.end);
512
- if (from === to) {
513
- return;
514
- }
515
- const angleForward = Math.atan2(segment.end.y - segment.start.y, segment.end.x - segment.start.x);
516
- const angleBackward = Math.atan2(segment.start.y - segment.end.y, segment.start.x - segment.end.x);
517
- const forwardIndex = edges.length;
518
- const backwardIndex = edges.length + 1;
519
- edges.push({
520
- from,
521
- to,
522
- angle: angleForward,
523
- rev: backwardIndex
524
- });
525
- edges.push({
526
- from: to,
527
- to: from,
528
- angle: angleBackward,
529
- rev: forwardIndex
530
- });
531
- ensureAdj(from);
532
- ensureAdj(to);
533
- adjacency[from].push(forwardIndex);
534
- adjacency[to].push(backwardIndex);
535
- });
536
- adjacency.forEach((edgeIds) => {
537
- edgeIds.sort((a, b) => edges[a].angle - edges[b].angle);
538
- });
539
- const visited = new Array(edges.length).fill(false);
540
- const faces = [];
541
- for (let edgeIndex = 0; edgeIndex < edges.length; edgeIndex += 1) {
542
- if (visited[edgeIndex]) {
543
- continue;
544
- }
545
- const face = [];
546
- let currentEdge = edgeIndex;
547
- let guard = 0;
548
- while (!visited[currentEdge] && guard < edges.length * 2) {
549
- guard += 1;
550
- visited[currentEdge] = true;
551
- const edge = edges[currentEdge];
552
- face.push(pointsList[edge.from]);
553
- const outgoing = adjacency[edge.to] ?? [];
554
- if (outgoing.length === 0) {
555
- break;
556
- }
557
- const revIndex = outgoing.indexOf(edge.rev);
558
- if (revIndex === -1) {
559
- break;
560
- }
561
- const nextIndex = (revIndex - 1 + outgoing.length) % outgoing.length;
562
- currentEdge = outgoing[nextIndex];
563
- if (currentEdge === edgeIndex) {
564
- break;
565
- }
566
- }
567
- if (face.length < 3) {
568
- continue;
569
- }
570
- const area = polygonArea(face);
571
- if (Math.abs(area) <= INTERSECTION_EPS) {
572
- continue;
573
- }
574
- faces.push(face);
575
- }
576
- if (faces.length === 0) {
577
- return [];
578
- }
579
- if (directedSegments.length === 0) {
580
- return [];
581
- }
582
- return faces.filter((face) => {
583
- const centroid = polygonCentroid(face);
584
- return evenOddContains(centroid, directedSegments);
585
- });
586
- };
587
179
  const buildEvenOddShape = (orderedNetworks, points, segments, pointOffset) => {
588
180
  const shape = { paths: [] };
589
181
  orderedNetworks.forEach((network) => {
@@ -693,19 +285,6 @@ const drawVectorNetworkPath = (graphic, network, points, segments, pointOffset)
693
285
  const drawVectorPath = (graphic, orderedNetworks, points, segments, pointOffset) => {
694
286
  orderedNetworks.forEach((network) => drawVectorNetworkPath(graphic, network, points, segments, pointOffset));
695
287
  };
696
- const drawFillFaces = (graphic, faces) => {
697
- faces.forEach((face) => {
698
- if (face.length < 3) {
699
- return;
700
- }
701
- graphic.moveTo(face[0].x, face[0].y);
702
- for (let i = 1; i < face.length; i += 1) {
703
- graphic.lineTo(face[i].x, face[i].y);
704
- }
705
- graphic.closePath();
706
- });
707
- };
708
- const getFillPayload = (fills) => Array.isArray(fills) && fills.length > 0 ? fills : [];
709
288
  const applyBaseVectorStroke = (graphic, strokes, replayPath) => {
710
289
  for (const stroke of strokes) {
711
290
  if (!isRecord(stroke)) {
@@ -724,161 +303,102 @@ const applyBaseVectorStroke = (graphic, strokes, replayPath) => {
724
303
  return;
725
304
  }
726
305
  };
306
+ const vectorFillProjections = new WeakMap();
727
307
  const renderVectorGraphic = (graphic, data) => {
728
308
  const renderData = normalizeVectorRenderData(data);
729
- const cache = graphic;
730
- graphic.clear();
731
- graphic.hitArea = null;
732
- setElementGeometryLocalBounds(graphic, null);
733
- const renderStateGraphic = graphic;
734
- renderStateGraphic.geometry?.clear?.();
735
- renderStateGraphic.batched = false;
736
- renderStateGraphic._transform?.updateLocalTransform?.();
737
- const { fills, x, y, points, segments, networks, rotation, scaleX, scaleY, skewX, skewY } = renderData;
738
- const orderedNetworks = sortVectorItemsById(Object.values(networks));
739
- const workspaceGeometryBounds = calculateVectorLocalBounds(points, segments, orderedNetworks);
740
- const pointOffset = {
741
- x: workspaceGeometryBounds.x,
742
- y: workspaceGeometryBounds.y
309
+ const { points, segments, networks, fillRule, fills } = renderData;
310
+ let state = vectorFillProjections.get(graphic);
311
+ const geometryChanged = !state ||
312
+ state.points !== points ||
313
+ state.segments !== segments ||
314
+ state.networks !== networks ||
315
+ state.fillRule !== fillRule;
316
+ const orderedNetworks = state && !geometryChanged
317
+ ? state.orderedNetworks
318
+ : sortVectorItemsById(Object.values(networks));
319
+ const bounds = state && !geometryChanged
320
+ ? state.bounds
321
+ : calculateVectorLocalBounds(points, segments, orderedNetworks);
322
+ const pointOffset = { x: bounds.x, y: bounds.y };
323
+ const paint = state?.fills === fills ? state.paint : toMeshProjectionPaint(fills);
324
+ const hasPaint = paint.kind === 'solid' || paint.material.fills.length > 0;
325
+ const coverage = state && !geometryChanged
326
+ ? state.coverage
327
+ : prepareVectorCompoundFill(buildEvenOddShape(orderedNetworks, points, segments, pointOffset), fillRule);
328
+ const model = {
329
+ polygons: coverage.faces,
330
+ bounds: { minX: 0, minY: 0, maxX: bounds.width, maxY: bounds.height }
743
331
  };
744
- graphic.setSourceSpaceOrigin(pointOffset);
745
- vectorRenderGeometryProjectionCache.set(graphic, {
746
- workspaceOrigin: pointOffset
747
- });
748
- graphic.x = x;
749
- graphic.y = y;
750
- graphic.rotation = rotation;
751
- setElementGeometryLocalBounds(graphic, {
752
- x: 0,
753
- y: 0,
754
- width: workspaceGeometryBounds.width,
755
- height: workspaceGeometryBounds.height
756
- });
757
- graphic.width = renderData.width;
758
- graphic.height = renderData.height;
759
- graphic.scale.set(scaleX, scaleY);
760
- graphic.skew.set(skewX, skewY);
761
- if (orderedNetworks.length === 0) {
762
- return;
763
- }
764
- const fillPayload = getFillPayload(fills);
765
- const hasRenderableFill = getRenderableFills(fillPayload).length > 0;
766
- const hasClosedNetwork = renderData.closed === true ||
767
- orderedNetworks.some((network) => network.closed && network.pointIds.length > 2);
768
- const shape = buildEvenOddShape(orderedNetworks, points, segments, pointOffset);
769
- if (hasRenderableFill) {
770
- const preparedFillShape = prepareEvenOddShape(shape);
771
- const hitCache = cache.__vectorFillHitCache;
772
- const reuseHitArea = hitCache?.points === points &&
773
- hitCache.segments === segments &&
774
- hitCache.networks === networks &&
775
- hitCache.pointOffsetX === pointOffset.x &&
776
- hitCache.pointOffsetY === pointOffset.y &&
777
- hitCache.hasVisibleFill === true;
778
- const hitArea = reuseHitArea
779
- ? hitCache.hitArea
780
- : {
781
- contains: (hitX, hitY) => isPointInsidePreparedEvenOddShape({ x: hitX, y: hitY }, preparedFillShape)
782
- };
783
- cache.__vectorFillHitCache = {
784
- preparedFillShape,
332
+ if (!state) {
333
+ state = {
785
334
  points,
786
335
  segments,
787
336
  networks,
788
- pointOffsetX: pointOffset.x,
789
- pointOffsetY: pointOffset.y,
790
- hasVisibleFill: true,
791
- hitArea
337
+ fillRule,
338
+ orderedNetworks,
339
+ bounds,
340
+ coverage,
341
+ fills,
342
+ paint,
343
+ projection: core.createMeshProjection({ model, paint })
792
344
  };
793
- graphic.hitArea = hitArea;
345
+ state.projection.attach(graphic);
346
+ vectorFillProjections.set(graphic, state);
794
347
  }
795
348
  else {
796
- cache.__vectorFillHitCache = undefined;
797
- }
798
- if (fillPayload.length === 0) {
799
- if (cache.__evenOddFillCache?.fill) {
800
- cache.__evenOddFillCache.fill.dispose();
801
- cache.__evenOddFillCache = undefined;
349
+ if (geometryChanged) {
350
+ state.projection.update({ model, paint });
351
+ }
352
+ else if (state.paint !== paint) {
353
+ state.projection.updatePaint(paint);
802
354
  }
355
+ Object.assign(state, {
356
+ points,
357
+ segments,
358
+ networks,
359
+ fillRule,
360
+ orderedNetworks,
361
+ bounds,
362
+ coverage,
363
+ fills,
364
+ paint
365
+ });
366
+ }
367
+ graphic.clear();
368
+ graphic.batched = true;
369
+ graphic.hitArea = hasPaint ? { contains: coverage.contains } : null;
370
+ state.projection.setVisible(coverage.faces.length > 0 && hasPaint);
371
+ graphic.setSourceSpaceOrigin(pointOffset);
372
+ vectorRenderGeometryProjectionCache.set(graphic, {
373
+ workspaceOrigin: pointOffset
374
+ });
375
+ setElementGeometryLocalBounds(graphic, { x: 0, y: 0, width: bounds.width, height: bounds.height });
376
+ graphic.x = renderData.x;
377
+ graphic.y = renderData.y;
378
+ graphic.rotation = renderData.rotation;
379
+ graphic.width = renderData.width;
380
+ graphic.height = renderData.height;
381
+ graphic.scale.set(renderData.scaleX, renderData.scaleY);
382
+ graphic.skew.set(renderData.skewX, renderData.skewY);
383
+ // Unfilled paths keep their ordinary graphics path. A filled path's stroke
384
+ // is a later child, above its mesh; material changes cannot reverse order.
385
+ const hasFill = hasPaint && coverage.faces.length > 0;
386
+ if (!hasFill) {
803
387
  applyBaseVectorStroke(graphic, renderData.strokes ?? [], () => drawVectorPath(graphic, orderedNetworks, points, segments, pointOffset));
804
- return;
805
388
  }
806
- const hasGradient = fillPayload.some((fill) => fill.kind === 'gradient');
807
- let previewFill = false;
808
- if (hasGradient) {
809
- const evenOddCache = cache.__evenOddFillCache ?? { fill: null };
810
- const reuseEvenOddFill = evenOddCache.fill &&
811
- evenOddCache.width === renderData.width &&
812
- evenOddCache.height === renderData.height &&
813
- evenOddCache.fillPayload === fillPayload &&
814
- evenOddCache.points === points &&
815
- evenOddCache.segments === segments &&
816
- evenOddCache.networks === networks &&
817
- evenOddCache.pointOffsetX === pointOffset.x &&
818
- evenOddCache.pointOffsetY === pointOffset.y;
819
- if (!reuseEvenOddFill) {
820
- evenOddCache.fill?.dispose();
821
- evenOddCache.fill = core.createEvenOddFillStyle({
822
- width: renderData.width,
823
- height: renderData.height,
824
- offsetX: 0,
825
- offsetY: 0,
826
- shape,
827
- fills: fillPayload
828
- });
829
- evenOddCache.width = renderData.width;
830
- evenOddCache.height = renderData.height;
831
- evenOddCache.fillPayload = fillPayload;
832
- evenOddCache.points = points;
833
- evenOddCache.segments = segments;
834
- evenOddCache.networks = networks;
835
- evenOddCache.pointOffsetX = pointOffset.x;
836
- evenOddCache.pointOffsetY = pointOffset.y;
837
- }
838
- cache.__evenOddFillCache = evenOddCache;
839
- if (evenOddCache.fill) {
840
- graphic.rect(0, 0, renderData.width, renderData.height);
841
- graphic.fill(evenOddCache.fill.style);
842
- }
843
- else if (hasClosedNetwork) {
844
- previewFill = true;
845
- }
389
+ if (hasFill && renderData.strokes?.length && !state.stroke) {
390
+ state.stroke = new RenderGraphics();
391
+ graphic.addChild(state.stroke);
846
392
  }
847
- else {
848
- cache.__evenOddFillCache?.fill?.dispose();
849
- cache.__evenOddFillCache = undefined;
850
- if (renderData.fillRule === 'nonzero' && hasClosedNetwork) {
851
- cache.__vectorFillCache = undefined;
852
- drawVectorPath(graphic, orderedNetworks, points, segments, pointOffset);
853
- applyRenderableFill(graphic, fillPayload, {
854
- replayPath: () => drawVectorPath(graphic, orderedNetworks, points, segments, pointOffset)
855
- });
856
- }
857
- else {
858
- const fillCache = cache.__vectorFillCache ?? { faces: [] };
859
- const { flattenedSegments, directedSegments, segmentKeyMap, segmentLinesMap } = buildFlattenedSegmentsWithCache(orderedNetworks, points, segments, fillCache, pointOffset);
860
- const fillFaces = buildFillFaces(flattenedSegments, directedSegments);
861
- fillCache.faces = fillFaces;
862
- fillCache.segmentKeyMap = segmentKeyMap;
863
- fillCache.segmentLinesMap = segmentLinesMap;
864
- cache.__vectorFillCache = fillCache;
865
- if (fillFaces.length > 0) {
866
- drawFillFaces(graphic, fillFaces);
867
- applyRenderableFill(graphic, fillPayload, {
868
- replayPath: () => drawFillFaces(graphic, fillFaces)
869
- });
870
- }
871
- else if (hasClosedNetwork) {
872
- previewFill = true;
873
- }
393
+ if (state.stroke) {
394
+ const stroke = state.stroke;
395
+ stroke.clear();
396
+ stroke.visible =
397
+ hasFill && orderedNetworks.length > 0 && !!renderData.strokes?.length;
398
+ if (stroke.visible) {
399
+ applyBaseVectorStroke(stroke, renderData.strokes ?? [], () => drawVectorPath(stroke, orderedNetworks, points, segments, pointOffset));
874
400
  }
875
401
  }
876
- if (previewFill) {
877
- applyRenderableFill(graphic, fillPayload, {
878
- replayPath: () => drawVectorPath(graphic, orderedNetworks, points, segments, pointOffset)
879
- });
880
- }
881
- applyBaseVectorStroke(graphic, renderData.strokes ?? [], () => drawVectorPath(graphic, orderedNetworks, points, segments, pointOffset));
882
402
  };
883
403
  export const VECTOR_RENDER_STRATEGY = Object.assign((graphic, data) => {
884
404
  renderVectorGraphic(graphic, data);
@@ -904,7 +424,7 @@ export const VECTOR_COMPONENT_DEFINITION = {
904
424
  {
905
425
  name: PropertyTypes.POSITION,
906
426
  type: PropertyTypes.POSITION,
907
- alias: ['x', 'y', 'rotation']
427
+ alias: ['x', 'y', 'rotation', 'scaleX', 'scaleY']
908
428
  },
909
429
  {
910
430
  name: PropertyTypes.DIMENSION,