headless-svg-to-excalidraw 0.0.1 → 0.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.
Files changed (3) hide show
  1. package/README.md +16 -12
  2. package/dist/index.mjs +3 -3
  3. package/package.json +13 -2
package/README.md CHANGED
@@ -1,17 +1,23 @@
1
1
  # svg-to-excalidraw
2
2
 
3
- Library to convert SVG to Excalidraws file format.
3
+ Library to convert SVG to Excalidraw's file format.
4
+
5
+ > This is a shameless fork of [@excalidraw/svg-to-excalidraw](https://github.com/excalidraw/svg-to-excalidraw) with the intent of keeping it up to date, using TypeScript, and removing browser dependencies.
4
6
 
5
7
  ## :floppy_disk: Installation
6
8
 
7
9
  ```bash
8
- yarn add svg-to-excalidraw
10
+ bun add headless-svg-to-excalidraw
11
+ # or
12
+ npm install headless-svg-to-excalidraw
13
+ # or
14
+ yarn add headless-svg-to-excalidraw
9
15
  ```
10
16
 
11
17
  ## :beginner: Usage
12
18
 
13
19
  ```typescript
14
- import svgToEx from "svg-to-excalidraw";
20
+ import { convert } from "headless-svg-to-excalidraw";
15
21
 
16
22
  const heartSVG = `
17
23
  <svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
@@ -23,7 +29,7 @@ const heartSVG = `
23
29
  </svg>
24
30
  `;
25
31
 
26
- const { hasErrors, errors, content } = svgToEx.convert(heartSVG);
32
+ const { hasErrors, errors, content } = convert(heartSVG);
27
33
 
28
34
  // SVG parsing errors are propagated through.
29
35
  if (hasErrors) {
@@ -31,10 +37,8 @@ if (hasErrors) {
31
37
  return;
32
38
  }
33
39
 
34
- navigator.clipboard.writeText(content);
35
-
36
- // the heart excalidraw json is now copied to your clipboard.
37
- // Just Paste it into your Excalidraw session!
40
+ // Write to file or use however you need
41
+ console.log(content);
38
42
  ```
39
43
 
40
44
  ## :game_die: Running tests
@@ -46,12 +50,12 @@ TODO.
46
50
  #### Building the Project
47
51
 
48
52
  ```bash
49
- yarn build
53
+ bun run build
50
54
 
51
- # Build and watch whenever a file is updated
52
- yarn build:watch
55
+ # Type checking
56
+ bun run typecheck
53
57
  ```
54
58
 
55
59
  ## :busts_in_silhouette: Contributing
56
60
 
57
- Pull requests are welcome. For major changes, please [open an issue](https://github.com/excalidraw/svg-to-excalidraw/issues) first to discuss what you would like to change.
61
+ Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import { mat4, vec3 } from "gl-matrix";
2
1
  import { Random } from "roughjs/bin/math";
3
2
  import { nanoid } from "nanoid";
4
3
  import chroma from "chroma-js";
4
+ import { mat4, vec3 } from "gl-matrix";
5
5
  import { DOMParser, parseHTML } from "linkedom";
6
6
  import { pointsOnPath } from "points-on-path";
7
7
 
@@ -84,7 +84,7 @@ const attrHandlers = {
84
84
  }
85
85
  };
86
86
  function presAttrsToElementValues(el) {
87
- return [...el.attributes].reduce((exVals, attr) => {
87
+ return Array.from(el.attributes).reduce((exVals, attr) => {
88
88
  const name = attr.name;
89
89
  if (Object.keys(attrHandlers).includes(name)) attrHandlers[name]({
90
90
  el,
@@ -362,7 +362,7 @@ const allwaysPassedUseAttrs = [
362
362
  "xlink:href"
363
363
  ];
364
364
  const getDefElWithCorrectAttrs = (defEl, useEl) => {
365
- return [...useEl.attributes].reduce((el, attr) => {
365
+ return Array.from(useEl.attributes).reduce((el, attr) => {
366
366
  if (skippedUseAttrs.includes(attr.value)) return el;
367
367
  if (!defEl.hasAttribute(attr.name) || allwaysPassedUseAttrs.includes(attr.name)) el.setAttribute(attr.name, useEl.getAttribute(attr.name) || "");
368
368
  return el;
package/package.json CHANGED
@@ -1,11 +1,19 @@
1
1
  {
2
2
  "name": "headless-svg-to-excalidraw",
3
- "version": "0.0.1",
3
+ "version": "0.0.9",
4
4
  "description": "Convert SVG to Excalidraw's file format, no browser required.",
5
5
  "type": "module",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/awhiteside1/headless-svg-to-excalidraw.git"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/awhiteside1/headless-svg-to-excalidraw/issues"
15
+ },
16
+ "homepage": "https://github.com/awhiteside1/headless-svg-to-excalidraw#readme",
9
17
  "exports": {
10
18
  ".": {
11
19
  "import": {
@@ -21,10 +29,13 @@
21
29
  "scripts": {
22
30
  "build": "tsdown",
23
31
  "clean": "rm -rf dist",
24
- "typecheck": "tsc --noEmit"
32
+ "typecheck": "tsc --noEmit",
33
+ "test": "bun test"
25
34
  },
26
35
  "license": "MIT",
27
36
  "devDependencies": {
37
+ "@tsconfig/bun": "^1.0.10",
38
+ "@types/bun": "^1.3.7",
28
39
  "@types/chroma-js": "^2.1.3",
29
40
  "tsdown": "^0.20.1",
30
41
  "typescript": "^5.9.3"