@emasoft/svg-matrix 1.0.8 → 1.0.9
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/README.md +99 -1
- package/package.json +1 -1
- package/src/index.js +1 -1
package/README.md
CHANGED
|
@@ -54,12 +54,91 @@ node test/benchmark-precision.js
|
|
|
54
54
|
|
|
55
55
|
## Installation
|
|
56
56
|
|
|
57
|
+
### Node.js (Local Installation)
|
|
58
|
+
|
|
59
|
+
**Step 1: Install the package**
|
|
60
|
+
|
|
57
61
|
```bash
|
|
58
62
|
npm install @emasoft/svg-matrix
|
|
59
63
|
```
|
|
60
64
|
|
|
65
|
+
**Step 2: Import what you need**
|
|
66
|
+
|
|
67
|
+
You can import specific modules (recommended - smaller bundle):
|
|
68
|
+
|
|
61
69
|
```js
|
|
62
|
-
import { Matrix, Vector, Transforms2D
|
|
70
|
+
import { Matrix, Vector, Transforms2D } from '@emasoft/svg-matrix';
|
|
71
|
+
|
|
72
|
+
const rotation = Transforms2D.rotate(Math.PI / 4);
|
|
73
|
+
console.log(rotation);
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Or import everything as a single namespace:
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
import * as SVGMatrix from '@emasoft/svg-matrix';
|
|
80
|
+
|
|
81
|
+
// Now use SVGMatrix.ModuleName
|
|
82
|
+
const v = SVGMatrix.Vector.from([1, 2, 3]);
|
|
83
|
+
const m = SVGMatrix.Matrix.identity(3);
|
|
84
|
+
const rotation = SVGMatrix.Transforms2D.rotate(Math.PI / 4);
|
|
85
|
+
const pathData = SVGMatrix.GeometryToPath.circleToPathData(100, 100, 50);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**Complete Node.js Example**
|
|
89
|
+
|
|
90
|
+
Save this as `example.js` and run with `node example.js`:
|
|
91
|
+
|
|
92
|
+
```js
|
|
93
|
+
// example.js
|
|
94
|
+
import {
|
|
95
|
+
Matrix,
|
|
96
|
+
Vector,
|
|
97
|
+
Transforms2D,
|
|
98
|
+
GeometryToPath,
|
|
99
|
+
SVGFlatten
|
|
100
|
+
} from '@emasoft/svg-matrix';
|
|
101
|
+
|
|
102
|
+
// 1. Vector operations
|
|
103
|
+
const v = Vector.from([1, 2, 3]);
|
|
104
|
+
const w = Vector.from([4, 5, 6]);
|
|
105
|
+
console.log('Dot product:', v.dot(w).toString());
|
|
106
|
+
console.log('Cross product:', v.cross(w).toNumberArray());
|
|
107
|
+
|
|
108
|
+
// 2. Matrix operations
|
|
109
|
+
const A = Matrix.from([[1, 2], [3, 4]]);
|
|
110
|
+
console.log('Determinant:', A.determinant().toString());
|
|
111
|
+
console.log('Inverse:', A.inverse().toNumberArray());
|
|
112
|
+
|
|
113
|
+
// 3. 2D Transforms
|
|
114
|
+
const transform = Transforms2D.translation(100, 50)
|
|
115
|
+
.mul(Transforms2D.rotate(Math.PI / 4))
|
|
116
|
+
.mul(Transforms2D.scale(2));
|
|
117
|
+
|
|
118
|
+
const [x, y] = Transforms2D.applyTransform(transform, 10, 10);
|
|
119
|
+
console.log(`Transformed point: (${x}, ${y})`);
|
|
120
|
+
|
|
121
|
+
// 4. SVG path transformation
|
|
122
|
+
const circlePath = GeometryToPath.circleToPathData(0, 0, 50);
|
|
123
|
+
const transformedPath = SVGFlatten.transformPathData(circlePath, transform);
|
|
124
|
+
console.log('Transformed circle path:', transformedPath);
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**Using with CommonJS (require)**
|
|
128
|
+
|
|
129
|
+
This library uses ES modules. If you need CommonJS:
|
|
130
|
+
|
|
131
|
+
```js
|
|
132
|
+
// Option 1: Dynamic import (recommended)
|
|
133
|
+
async function main() {
|
|
134
|
+
const { Matrix, Vector } = await import('@emasoft/svg-matrix');
|
|
135
|
+
const v = Vector.from([1, 2, 3]);
|
|
136
|
+
console.log(v.norm().toString());
|
|
137
|
+
}
|
|
138
|
+
main();
|
|
139
|
+
|
|
140
|
+
// Option 2: Add "type": "module" to your package.json
|
|
141
|
+
// Then you can use import statements directly
|
|
63
142
|
```
|
|
64
143
|
|
|
65
144
|
### Browser Usage (CDN)
|
|
@@ -121,6 +200,25 @@ Popular CDN with good caching.
|
|
|
121
200
|
</script>
|
|
122
201
|
```
|
|
123
202
|
|
|
203
|
+
#### Import Everything as a Namespace
|
|
204
|
+
|
|
205
|
+
If you want all modules under one name:
|
|
206
|
+
|
|
207
|
+
```html
|
|
208
|
+
<script type="module">
|
|
209
|
+
// Import everything as "SVGMatrix"
|
|
210
|
+
import * as SVGMatrix from 'https://esm.sh/@emasoft/svg-matrix';
|
|
211
|
+
|
|
212
|
+
// Now use SVGMatrix.ModuleName
|
|
213
|
+
const v = SVGMatrix.Vector.from([1, 2, 3]);
|
|
214
|
+
const m = SVGMatrix.Matrix.identity(3);
|
|
215
|
+
const rotation = SVGMatrix.Transforms2D.rotate(Math.PI / 4);
|
|
216
|
+
const [x, y] = SVGMatrix.Transforms2D.applyTransform(rotation, 10, 0);
|
|
217
|
+
|
|
218
|
+
console.log('All modules available:', Object.keys(SVGMatrix));
|
|
219
|
+
</script>
|
|
220
|
+
```
|
|
221
|
+
|
|
124
222
|
#### Pin to a Specific Version
|
|
125
223
|
|
|
126
224
|
To avoid breaking changes, pin to a specific version:
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -49,7 +49,7 @@ import { Logger, LogLevel, setLogLevel, getLogLevel as getLoggerLevel, enableFil
|
|
|
49
49
|
* Library version
|
|
50
50
|
* @constant {string}
|
|
51
51
|
*/
|
|
52
|
-
export const VERSION = '1.0.
|
|
52
|
+
export const VERSION = '1.0.9';
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
55
|
* Default precision for path output (decimal places)
|