@slithy/prim-interface 0.3.1 → 0.3.3

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
@@ -6,6 +6,21 @@ Browser-facing API for `@slithy/prim-lib`. Consumed by `apps/prim-demo`.
6
6
 
7
7
  Wraps `prim-lib` in a `run()` / `runWorker()` API and provides save/copy/share helpers for exporting results. `run()` runs the optimizer on the main thread; `runWorker()` moves computation into a Web Worker, keeping the main thread responsive during long jobs. Both share the same callback API.
8
8
 
9
+ ## Vite setup
10
+
11
+ This package ships a Web Worker and is incompatible with Vite's dependency optimizer. Add it to `optimizeDeps.exclude` in your Vite config:
12
+
13
+ ```ts
14
+ // vite.config.ts
15
+ optimizeDeps: {
16
+ exclude: ['@slithy/prim-interface']
17
+ }
18
+ ```
19
+
20
+ The same applies to `electron-vite` projects — the exclusion goes under `renderer.optimizeDeps.exclude`.
21
+
22
+ ---
23
+
9
24
  ## Exports
10
25
 
11
26
  ### `run(source, config, callbacks)` / `runWorker(source, config, callbacks)`
@@ -34,7 +49,7 @@ job.resume();
34
49
 
35
50
  **`run()`** — runs the optimizer on the main thread via `requestAnimationFrame`. Simpler; no worker overhead. UI may feel sluggish during compute-heavy steps at high `shapes` / `mutations` settings.
36
51
 
37
- **`runWorker()`** — moves all computation into a Web Worker using `OffscreenCanvas`. The main thread only handles DOM updates (appending the canvas/SVG, calling callbacks). Requires a bundler that understands `new Worker(new URL(..., import.meta.url))` — Vite handles this automatically. Shape constructors in `config.shapeTypes` are mapped to names internally; only the built-in shapes (`Triangle`, `Rectangle`, `Ellipse`, `Circle`, `Square`, `Hexagon`, `Glyph`) are supported.
52
+ **`runWorker()`** — moves all computation into a Web Worker using `OffscreenCanvas`. The main thread only handles DOM updates (appending the canvas/SVG, calling callbacks). Requires a bundler that understands `new Worker(new URL(..., import.meta.url))` — Vite handles this, but see the Vite setup section above for a required config change. Shape constructors in `config.shapeTypes` are mapped to names internally; only the built-in shapes (`Triangle`, `Rectangle`, `Ellipse`, `Circle`, `Square`, `Hexagon`, `Glyph`) are supported.
38
53
 
39
54
  ### Config
40
55
 
package/dist/index.d.ts CHANGED
@@ -11,6 +11,7 @@ interface Config {
11
11
  viewSize: number;
12
12
  allowUpscale?: boolean;
13
13
  pixelRatio?: number;
14
+ glyphChar?: string;
14
15
  shapeTypes: Array<new (w: number, h: number) => ShapeInterface>;
15
16
  shapeWeights?: number[];
16
17
  fill: 'auto' | string;
package/dist/index.js CHANGED
@@ -74,7 +74,7 @@ function run(source, cfg, callbacks = {}) {
74
74
  // src/runWorker.ts
75
75
  import { Canvas as Canvas2, renderStepToCtx, stepDataToSVGElement } from "@slithy/prim-lib";
76
76
  function runWorker(source, cfg, callbacks = {}) {
77
- const url = source instanceof File ? URL.createObjectURL(source) : source;
77
+ const url = source instanceof File ? URL.createObjectURL(source) : new URL(source, globalThis.location.href).href;
78
78
  const isBlob = source instanceof File;
79
79
  let stopped = false;
80
80
  let result = null;
@@ -2,6 +2,7 @@ import { PreCfg, StepData, SerializedOutput } from '@slithy/prim-lib';
2
2
 
3
3
  type WorkerCfg = Omit<PreCfg, 'shapeTypes'> & {
4
4
  shapeTypeNames: string[];
5
+ glyphChar?: string;
5
6
  };
6
7
  type WorkerInbound = {
7
8
  type: 'start';
@@ -16,10 +16,18 @@ self.onmessage = async (e) => {
16
16
  switch (msg.type) {
17
17
  case "start": {
18
18
  const { url, cfg: workerCfg } = msg;
19
- const { shapeTypeNames, ...rest } = workerCfg;
19
+ const { shapeTypeNames, glyphChar, ...rest } = workerCfg;
20
20
  const shapeTypes = shapeTypeNames.map((name) => {
21
21
  const ctor = SHAPES[name];
22
22
  if (!ctor) throw new Error(`[prim worker] Unknown shape type: ${name}`);
23
+ if (name === "Glyph" && glyphChar) {
24
+ const char = glyphChar;
25
+ return class GlyphWithChar extends Glyph {
26
+ constructor(w, h) {
27
+ super(w, h, char);
28
+ }
29
+ };
30
+ }
23
31
  return ctor;
24
32
  });
25
33
  const preCfg = { ...rest, shapeTypes };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slithy/prim-interface",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Browser-facing API for primitive-based image reconstruction.",
5
5
  "type": "module",
6
6
  "exports": {