@weasel-js/svg 1.5.1 → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { Path, FillStyle, StrokeAlign, StyledRun, TextStyle, TextVerticalAlign, Stroke, MarkerEntry, TilePatternSpec, IngestCtx } from '@weasel-js/core';
1
+ import { Mat3 } from '@weasel-js/geom';
2
+ import { Path, FillStyle, ScreenLength, StrokeAlign, StyledRun, TextStyle, TextVerticalAlign, Stroke, MarkerEntry, TilePatternSpec, IngestCtx } from '@weasel-js/core';
2
3
 
3
4
  /**
4
5
  * Public types for `@weasel-js/svg`. The package exposes a flat,
@@ -47,10 +48,15 @@ interface NamespacedElement {
47
48
  children?: Record<string, NamespacedElement[]>;
48
49
  }
49
50
  /**
50
- * 2x3 affine matrix in column-major form (SVG's `matrix(a b c d e f)`
51
- * order). Maps `[x', y'] = [a*x + c*y + e, b*x + d*y + f]`.
51
+ * 2x3 affine matrix in SVG's `matrix(a b c d e f)` order, mapping
52
+ * `[x', y'] = [a*x + c*y + e, b*x + d*y + f]`.
53
+ *
54
+ * The same order the kernel's affine tier uses, so this is that type under
55
+ * the name the SVG spec gives it — not a parallel one. An `SvgGroupNode`'s
56
+ * transform and a geom `Mat3` are interchangeable without a conversion.
52
57
  */
53
- type Matrix = readonly [number, number, number, number, number, number];
58
+ type Matrix = Mat3;
59
+
54
60
  /** Identity matrix — useful as a default in tests / constructors. */
55
61
  declare const IDENTITY_MATRIX: Matrix;
56
62
  /**
@@ -73,11 +79,9 @@ type SvgPaint = {
73
79
  interface SvgStroke {
74
80
  paint: SvgPaint;
75
81
  /** World units, or `{ px }` for a width that holds its rendered thickness
76
- * however the document is scaled — SVG's `vector-effect="non-scaling-stroke"`,
77
- * and the same unit system as the kit's `Stroke.width`. */
78
- width: number | {
79
- px: number;
80
- };
82
+ * however the document is scaled — SVG's `vector-effect="non-scaling-stroke"`.
83
+ * Literally the kit's own unit, not a second spelling of it. */
84
+ width: ScreenLength;
81
85
  opacity?: number;
82
86
  /** `stroke-linecap`. Default per SVG spec is `'butt'`. */
83
87
  cap?: 'butt' | 'round' | 'square';
package/dist/index.js CHANGED
@@ -1,21 +1,9 @@
1
1
  import { pathFromD, PATH_M, PATH_L, PATH_Z, boundsOfPath, resolveScreenLength, SCRIPT_METRICS, dwarn, getMarker, registerMarker, createInsertOp, PathBuilder, parseColor, rgbaToHex, resolveTextStyle, layoutRuns, resolveRuns, resolveAlign, PATH_C, PATH_Q, solid, fillToBoundsFrame, getPaintKind } from '@weasel-js/core';
2
- import { invert } from '@weasel-js/geom';
2
+ import { identity, multiply, invert } from '@weasel-js/geom';
3
3
  import { tileGeometry } from '@weasel-js/core/patterns-builtin';
4
4
 
5
5
  // src/parse.ts
6
-
7
- // src/types.ts
8
- var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
9
- function multiply(a, b) {
10
- return [
11
- a[0] * b[0] + a[2] * b[1],
12
- a[1] * b[0] + a[3] * b[1],
13
- a[0] * b[2] + a[2] * b[3],
14
- a[1] * b[2] + a[3] * b[3],
15
- a[0] * b[4] + a[2] * b[5] + a[4],
16
- a[1] * b[4] + a[3] * b[5] + a[5]
17
- ];
18
- }
6
+ var IDENTITY_MATRIX = identity();
19
7
  function applyMatrix(m, x, y) {
20
8
  return { x: m[0] * x + m[2] * y + m[4], y: m[1] * x + m[3] * y + m[5] };
21
9
  }
@@ -77,10 +65,9 @@ function parseTransform(attr, onWarn) {
77
65
  return result;
78
66
  }
79
67
  function rebaseTransform(ctm, local) {
80
- const inv = invert([...ctm]);
68
+ const inv = invert(ctm);
81
69
  if (!inv) return null;
82
- const [a, b, c, d, e, f] = inv;
83
- return multiply(multiply(ctm, local), [a, b, c, d, e, f]);
70
+ return multiply(multiply(ctm, local), inv);
84
71
  }
85
72
  function decomposeRotation(m, cx, cy, eps = 1e-4) {
86
73
  const [a, b, c, d, e, f] = m;