@grethel-labs/excaliplant 1.4.0 → 1.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grethel-labs/excaliplant",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Render PlantUML as hand-drawn Excalidraw diagrams, SVG and PNG.",
5
5
  "type": "module",
6
6
  "main": "./src/index.mjs",
@@ -35,10 +35,21 @@ const stats = { hits: 0, misses: 0, elkRuns: 0 };
35
35
  */
36
36
  function loadElk() {
37
37
  if (!elkPromise) {
38
+ // elkjs ends with `if (typeof document === "undefined" && typeof self !== "undefined")
39
+ // self.onmessage = …`: evaluated inside a Web Worker it installs its own message
40
+ // handler. Loaded lazily, that replaces the handler of the host that runs the
41
+ // library in the worker (the playground), which then never answers again. Put the
42
+ // host's handler back right after ELK has been created, before any message can be
43
+ // dispatched.
44
+ const scope = /** @type {any} */ (globalThis);
45
+ const hostHandler = scope.onmessage;
38
46
  elkPromise = import("elkjs/lib/elk.bundled.js")
39
47
  .then((mod) => {
48
+ // The worker script is evaluated lazily by the constructor, not by the import.
49
+ const elk = new /** @type {any} */ (mod).default();
50
+ if (scope.onmessage !== hostHandler) scope.onmessage = hostHandler;
40
51
  elkLoaded = true;
41
- return new /** @type {any} */ (mod).default();
52
+ return elk;
42
53
  })
43
54
  .catch((err) => {
44
55
  elkPromise = null;