@sakibcoolz/asset-import 0.1.1 → 0.2.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.
- package/README.md +27 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,17 +1,39 @@
|
|
|
1
1
|
# @sakibcoolz/asset-import
|
|
2
2
|
|
|
3
|
-
Allow-list SVG sanitizer for
|
|
3
|
+
**Allow-list SVG sanitizer** for the [3D SCADA SDK](https://github.com/sakibcoolz/3d-scada-sdk): turns an untrusted SVG drawing (for example a P&ID or floor plan) into a safe shape model and clean markup, used for reference underlays under a 3D plant. No DOM required — runs in Node.js, browsers and workers.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
6
|
npm install @sakibcoolz/asset-import
|
|
7
7
|
```
|
|
8
|
+
ESM only · Node.js 20+ · TypeScript types included · MIT
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
## Quick start
|
|
11
|
+
|
|
12
|
+
```js
|
|
10
13
|
import { sanitizeSvg } from '@sakibcoolz/asset-import';
|
|
14
|
+
|
|
15
|
+
const result = sanitizeSvg(untrustedSvgText);
|
|
16
|
+
if (result.ok) {
|
|
17
|
+
result.svg; // shape model: viewBox and shapes (paths, transforms, fills, strokes)
|
|
18
|
+
result.markup; // clean SVG markup rebuilt from the model only
|
|
19
|
+
result.notes; // what was dropped (text, metadata, unknown elements…)
|
|
20
|
+
} else {
|
|
21
|
+
result.errors; // e.g. [{ code: 'FORBIDDEN_ELEMENT', … }] for a <script>
|
|
22
|
+
}
|
|
11
23
|
```
|
|
12
24
|
|
|
13
|
-
|
|
25
|
+
In [`@sakibcoolz/react`](https://www.npmjs.com/package/@sakibcoolz/react) the editor's **Underlay** section uses this to import an `.svg` and lay it flat under the scene.
|
|
26
|
+
|
|
27
|
+
## What it does
|
|
28
|
+
- **Keeps:** shapes, paths, groups, transforms and presentation styles (fill, stroke, opacity…).
|
|
29
|
+
- **Drops, with notes:** text, metadata, unknown elements and attributes.
|
|
30
|
+
- **Rejects:** scripts and event handlers, `href`/links, `url()`/`data:`/`javascript:` values, `image`/`use`/`foreignObject`, DOCTYPE and entities, malformed XML or paths, and anything over the limits.
|
|
31
|
+
- **Limits** (`defaultSvgLimits`, adjustable): 512 KiB, 5,000 elements, depth 32, 20,000 path commands.
|
|
14
32
|
|
|
15
|
-
|
|
33
|
+
## API
|
|
34
|
+
- `sanitizeSvg(text, limits?)` → `{ ok: true, svg, markup, notes }` or `{ ok: false, errors }`.
|
|
35
|
+
- `toSvgMarkup(model)` — markup from a sanitized model.
|
|
36
|
+
- `defaultSvgLimits`.
|
|
37
|
+
- Types: `SanitizedSvg`, `SvgShape`, `SvgMatrix`, `SanitizeResult`, `SvgError`, `SvgErrorCode`, `SvgNote`, `SvgLimits`.
|
|
16
38
|
|
|
17
|
-
MIT
|
|
39
|
+
Licence: MIT
|
package/package.json
CHANGED