@grethel-labs/excaliplant 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  # excaliplant
3
3
 
4
- > PlantUML → ELK layout → Excalidraw renderer with a plugin-based parser.  ·  **v0.1.3**  ·  73 tests  ·  MIT
4
+ > PlantUML → ELK layout → Excalidraw renderer with a plugin-based parser.  ·  **v0.1.4**  ·  73 tests  ·  MIT
5
5
 
6
6
  `@grethel-labs/excaliplant` takes PlantUML source, runs it through a plugin-based
7
7
  parser, lays it out with [ELK](https://github.com/kieler/elkjs), and
@@ -13,11 +13,11 @@ artefacts.
13
13
  <table>
14
14
  <tr>
15
15
  <td align="center" width="50%">
16
- <a href="docs/ressources/generated/png/modules.png"><img src="docs/ressources/generated/png/modules.png" alt="Module structure" width="380"/></a><br/>
16
+ <a href="docs/ressources/generated/svg/modules.svg"><img src="docs/ressources/generated/svg/modules.svg" alt="Module structure" width="380"/></a><br/>
17
17
  <sub><b>Module structure</b> — rendered by excaliplant itself</sub>
18
18
  </td>
19
19
  <td align="center" width="50%">
20
- <a href="docs/ressources/generated/png/sequence.png"><img src="docs/ressources/generated/png/sequence.png" alt="renderPlantUml flow" width="380"/></a><br/>
20
+ <a href="docs/ressources/generated/svg/sequence.svg"><img src="docs/ressources/generated/svg/sequence.svg" alt="renderPlantUml flow" width="380"/></a><br/>
21
21
  <sub><b>renderPlantUml flow</b> — rendered by excaliplant itself</sub>
22
22
  </td>
23
23
  </tr>
@@ -111,7 +111,7 @@ JSDoc tags.
111
111
 
112
112
  ### Module structure
113
113
 
114
- ![Module structure](docs/ressources/generated/png/modules.png)
114
+ ![Module structure](docs/ressources/generated/svg/modules.svg)
115
115
 
116
116
  _Sources: [PlantUML](docs/ressources/generated/puml/modules.puml) · [SVG](docs/ressources/generated/svg/modules.svg)_
117
117
 
@@ -122,7 +122,7 @@ each plugin handling one PlantUML construct.
122
122
 
123
123
  ### renderPlantUml flow
124
124
 
125
- ![renderPlantUml flow](docs/ressources/generated/png/sequence.png)
125
+ ![renderPlantUml flow](docs/ressources/generated/svg/sequence.svg)
126
126
 
127
127
  _Sources: [PlantUML](docs/ressources/generated/puml/sequence.puml) · [SVG](docs/ressources/generated/svg/sequence.svg)_
128
128
 
@@ -141,7 +141,7 @@ The call graph for `renderPlantUml(text)` walks three subsystems:
141
141
 
142
142
  ### Parser plugins
143
143
 
144
- ![Parser plugins](docs/ressources/generated/png/plugins.png)
144
+ ![Parser plugins](docs/ressources/generated/svg/plugins.svg)
145
145
 
146
146
  _Sources: [PlantUML](docs/ressources/generated/puml/plugins.puml) · [SVG](docs/ressources/generated/svg/plugins.svg)_
147
147
 
@@ -175,6 +175,10 @@ PlantUML text
175
175
 
176
176
  ```text
177
177
  excaliplant
178
+ ├── assets
179
+ │ └── fonts
180
+ │ ├── Excalifont-Regular.woff2
181
+ │ └── LICENSE.txt
178
182
  ├── docs
179
183
  │ ├── ressources
180
184
  │ ├── scripts
@@ -211,6 +215,7 @@ excaliplant
211
215
  │ │ └── svg.mjs
212
216
  │ └── style
213
217
  │ ├── colors.mjs
218
+ │ ├── font.mjs
214
219
  │ └── text.mjs
215
220
  ├── tests
216
221
  │ ├── edge_cases.test.mjs
@@ -0,0 +1,20 @@
1
+ Excalifont
2
+ ==========
3
+
4
+ The Excalifont woff2 font file in this directory is bundled into
5
+ @grethel-labs/excaliplant so SVG and PNG exports render text in the
6
+ same hand-drawn typeface that Excalidraw uses on screen.
7
+
8
+ Origin: https://github.com/excalidraw/excalidraw (packages/excalidraw/fonts/Excalifont)
9
+ License: SIL Open Font License, Version 1.1 (OFL-1.1)
10
+ https://scripts.sil.org/OFL
11
+
12
+ Copyright (c) 2024 by Excalidraw. All rights reserved.
13
+ Excalifont is a trademark of Excalidraw.
14
+
15
+ Manufacturer/designer:
16
+ - Your Own Font Foundry (Virgil)
17
+ - Ján Filípek / DizajnDesign (Excalifont, modifications)
18
+
19
+ The font is redistributed under the OFL-1.1; see the upstream LICENSE
20
+ for the full text. This bundling is permitted by §2 of the OFL.
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@grethel-labs/excaliplant",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "PlantUML → ELK layout → Excalidraw renderer with a plugin-based parser.",
5
5
  "type": "module",
6
6
  "main": "index.mjs",
7
7
  "files": [
8
8
  "index.mjs",
9
9
  "src/",
10
+ "assets/fonts/",
10
11
  "README.md",
11
12
  "LICENSE"
12
13
  ],
@@ -6,6 +6,8 @@
6
6
 
7
7
  import { Resvg } from "@resvg/resvg-js";
8
8
 
9
+ import { EXCALIFONT_FONT_PATH } from "../style/font.mjs";
10
+
9
11
  const DEFAULT_PNG_WIDTH = 4800; // 4× the default 1200 SVG canvas.
10
12
 
11
13
  /**
@@ -22,7 +24,15 @@ export function svgToPng(svgText, opts = {}) {
22
24
  const resvg = new Resvg(svgText, {
23
25
  fitTo: { mode: "width", value: width },
24
26
  background: opts.background ?? "#ffffff",
25
- font: { loadSystemFonts: true },
27
+ // resvg ignores @font-face / data-URL fonts in the SVG, so we
28
+ // have to point it at the bundled Excalifont woff2 explicitly —
29
+ // otherwise PNG text would fall back to a system font and lose
30
+ // the Excalidraw-style handwriting.
31
+ font: {
32
+ loadSystemFonts: true,
33
+ fontFiles: [EXCALIFONT_FONT_PATH],
34
+ defaultFontFamily: "Excalifont",
35
+ },
26
36
  });
27
37
  return resvg.render().asPng();
28
38
  }
@@ -12,7 +12,12 @@
12
12
 
13
13
  import rough from "roughjs";
14
14
 
15
- const FONT_FAMILY = "Helvetica, Arial, sans-serif";
15
+ import {
16
+ EXCALIFONT_FONT_FACE,
17
+ EXCALIFONT_FONT_STACK,
18
+ } from "../style/font.mjs";
19
+
20
+ const FONT_FAMILY = EXCALIFONT_FONT_STACK;
16
21
  const ROUGHNESS = 1; // Excalidraw's default roughness.
17
22
  const BOWING = 1;
18
23
  const FILL_WEIGHT = 0; // 0 → roughjs picks a sensible default.
@@ -39,7 +44,11 @@ export function excalidrawToSvg(doc, opts = {}) {
39
44
 
40
45
  const bg = opts.background ?? doc.appState?.viewBackgroundColor ?? "#ffffff";
41
46
  const out = [];
42
- out.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${w} ${h}" width="${w}" height="${h}" font-family="${FONT_FAMILY}">`);
47
+ out.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${w} ${h}" width="${w}" height="${h}" font-family='${FONT_FAMILY}'>`);
48
+ // Inline Excalifont so the SVG carries the same hand-drawn typeface
49
+ // Excalidraw uses on screen, even when GitHub or any other host
50
+ // serves the file as a sandboxed `<img>` (no external font fetches).
51
+ out.push(`<defs><style type="text/css"><![CDATA[${EXCALIFONT_FONT_FACE}]]></style></defs>`);
43
52
  out.push(`<rect width="100%" height="100%" fill="${escapeAttr(bg)}"/>`);
44
53
  out.push(`<g transform="translate(${tx} ${ty})">`);
45
54
  out.push(arrowheadDefs());
@@ -0,0 +1,39 @@
1
+ // Inline Excalifont so exported SVGs and PNGs render text in the same
2
+ // hand-drawn typeface that Excalidraw uses on screen.
3
+ //
4
+ // Excalidraw ships Excalifont as a multi-subset family. We bundle the
5
+ // Latin subset (U+20-7E plus common punctuation) — that's all our
6
+ // labels need, and keeps the inline data URL small (~33 KB base64).
7
+ //
8
+ // At import time we read the woff2 once and cache:
9
+ // - `EXCALIFONT_WOFF2` the raw bytes (resvg-js consumes these)
10
+ // - `EXCALIFONT_DATA_URL` base64 data URL for inlining in SVG
11
+ // - `EXCALIFONT_FONT_FACE` a `@font-face` rule string ready to
12
+ // drop inside an SVG `<style>` element
13
+ // - `EXCALIFONT_FAMILY` the family name ("Excalifont")
14
+ //
15
+ // The font is OFL-licensed; the upstream copy lives at
16
+ // excalidraw/excalidraw on GitHub. The OFL notice is preserved in the
17
+ // repo's NOTICE/LICENSE-fonts file alongside the binary.
18
+
19
+ import { readFileSync } from "node:fs";
20
+ import { fileURLToPath } from "node:url";
21
+ import path from "node:path";
22
+
23
+ const here = path.dirname(fileURLToPath(import.meta.url));
24
+ const FONT_PATH = path.resolve(here, "..", "..", "assets", "fonts", "Excalifont-Regular.woff2");
25
+
26
+ export const EXCALIFONT_FAMILY = "Excalifont";
27
+ export const EXCALIFONT_FONT_PATH = FONT_PATH;
28
+ export const EXCALIFONT_WOFF2 = readFileSync(FONT_PATH);
29
+ export const EXCALIFONT_DATA_URL =
30
+ `data:font/woff2;base64,${EXCALIFONT_WOFF2.toString("base64")}`;
31
+
32
+ // `@font-face` rule for embedding inside an SVG `<style>` block. The
33
+ // fallback chain after Excalifont keeps text legible if a renderer
34
+ // strips `<style>` (some sanitizers do).
35
+ export const EXCALIFONT_FONT_FACE =
36
+ `@font-face{font-family:"${EXCALIFONT_FAMILY}";src:url(${EXCALIFONT_DATA_URL}) format("woff2");font-display:swap;}`;
37
+
38
+ export const EXCALIFONT_FONT_STACK =
39
+ `"${EXCALIFONT_FAMILY}", "Segoe Print", "Comic Sans MS", "Apple Chancery", cursive`;