@mocanvas/compat 4.1.0 → 4.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.
Files changed (3) hide show
  1. package/MIGRATION.md +36 -0
  2. package/compat.css +96 -0
  3. package/package.json +14 -7
package/MIGRATION.md CHANGED
@@ -253,6 +253,40 @@ during the zero-rename step. Under pnpm's strict `node_modules` that means
253
253
  adding `@mocanvas/mocanvas` to your own dependencies alongside
254
254
  `@mocanvas/compat`.
255
255
 
256
+ **If your own CSS reads tldraw's custom properties, add a second line:**
257
+
258
+ ```ts
259
+ import "@mocanvas/compat/compat.css"
260
+ ```
261
+
262
+ This is the half of the compat layer that nothing checks for you. The package
263
+ alias covers the symbols TypeScript sees; it cannot cover the `--tl-*` names in
264
+ your stylesheets. Without it a migration goes green — build, types, tests — and
265
+ the damage shows up only to the eye, because a `var()` that resolves to nothing
266
+ does not fail, it deletes the declaration it sits in (and inside `calc()`, the
267
+ whole property). One consumer found it as a cursor whose white outline had
268
+ quietly stopped being drawn.
269
+
270
+ `compat.css` maps tldraw's tokens onto mocanvas's and gives **every** one a
271
+ literal fallback, so a token with no counterpart cannot take a rule down with
272
+ it. Two groups are worth knowing about:
273
+
274
+ | tldraw token | What you get |
275
+ | --- | --- |
276
+ | `--tl-zoom`, `--tl-scale` | Real values. mocanvas now stamps `--mocanvas-zoom` and `--mocanvas-scale` on the canvas container and restamps them on zoom, so `calc()` rules that hold a constant on-screen size keep working. |
277
+ | `--tl-color-overlay`, `--tl-color-background-overlay`, `--tl-color-warn` | A static fallback. mocanvas has no equivalent, so these do not follow your theme — set them yourself if they matter. |
278
+
279
+ Everything else maps onto a themed mocanvas variable and follows a theme swap
280
+ or a flip to dark. The stylesheet is scoped to `.mocanvas` rather than `:root`,
281
+ so a page that still renders a real tldraw editor somewhere keeps its own
282
+ values.
283
+
284
+ **Next.js**: an app coming from tldraw almost certainly lists it in
285
+ `serverExternalPackages`. Next matches that by package name, so leaving
286
+ `@mocanvas/mocanvas` in the list turns `…/mocanvas.css` into a request Node has
287
+ to resolve — and Node has no loader for `.css`. Take mocanvas out of the list
288
+ entirely; there is nothing in it that needs to be external.
289
+
256
290
  ### Step 2 — drop the prefixes
257
291
 
258
292
  Once the app builds and runs against `@mocanvas/compat`, rename `TLFoo` →
@@ -663,6 +697,8 @@ aspirational.
663
697
  | `ShapeUtil.toSvg`, `ShapeUtil.toBackgroundSvg` | Not `ShapeUtil` members. Custom shapes contribute to SVG export through `registerShapeSvgRenderer(type, renderer)`; without one they fall back to `geometryFallbackSvg`. |
664
698
  | Sync protocol | Wire compatibility with tldraw's own sync protocol is not planned. `@mocanvas/sync` is a working transport of its own — presence records, `store.mergeRemoteChanges`, and a relay — but it does not speak tldraw's wire format. |
665
699
  | `image` shape on the GPU | The texture path exists in the engine (`StyleWords.texture` + `uploadTexture`) but the `image` shape still draws an `<img>` in the DOM overlay. |
700
+ | `FrameShapeUtil` default size | mocanvas creates a frame at **160×90**; tldraw creates one at 320×180. Same aspect, half the size. It only bites code that creates a frame *programmatically* without passing `w`/`h` — drawing one with the tool sizes it from the drag either way. Pass explicit dimensions if the size matters to you. Aligning the default is a behaviour change and is not being made in a patch release. |
701
+ | An unregistered shape type in `store.put()` | Accepted, deliberately, and confirmed rather than fixed. A `.tldr` written by a build that knows a shape type this one does not must survive a load/save round trip instead of being dropped on the next save, so an unknown `type` passes its props through untouched. Its *other* fields are still validated — `x` must be a number whatever the type is — and a type you did register is validated in full. See `COMPAT.md`. |
666
702
  | Text rendering | DOM overlay. Glyph-atlas text in WASM is phase 3. |
667
703
  | GPU frame clipping | The `CLIP` flag and `isClipShape` hook are wired end to end, but no built-in shape enables it yet (phase 3). |
668
704
  | WebGPU backend | Phase 3. WebGL2 is the only backend today, behind `RenderBackend`. |
package/compat.css ADDED
@@ -0,0 +1,96 @@
1
+ /**
2
+ * tldraw's CSS custom properties, mapped onto mocanvas's.
3
+ *
4
+ * `@mocanvas/compat` aliases the *symbols* an app imports. It did not alias the
5
+ * custom properties an app's stylesheets read, and that gap is invisible to
6
+ * every check a migration runs: TypeScript sees nothing, the build succeeds,
7
+ * the tests pass, and the regression is a white outline that quietly stopped
8
+ * being drawn. Import this alongside the package alias and a stylesheet
9
+ * written against tldraw keeps resolving.
10
+ *
11
+ * import "@mocanvas/mocanvas/mocanvas.css"
12
+ * import "@mocanvas/compat/compat.css"
13
+ *
14
+ * ## Every declaration carries a literal fallback, on purpose
15
+ *
16
+ * A `var()` that resolves to nothing makes the whole declaration invalid — so
17
+ * one missing token does not just lose its own colour, it takes the rule it
18
+ * appears in with it, and in a `calc()` it takes the entire property. Every
19
+ * mapping below therefore ends in a concrete value. A token mocanvas has no
20
+ * equivalent for still resolves to something defensible rather than poisoning
21
+ * the rule around it.
22
+ *
23
+ * ## What this cannot give you
24
+ *
25
+ * The tokens below marked "no equivalent" resolve to a static fallback, which
26
+ * keeps your CSS valid but is not the value tldraw would have computed. They
27
+ * are listed in MIGRATION.md §7 so you can decide what to do about each.
28
+ *
29
+ * Scoped to `.mocanvas` rather than `:root` so an app that still renders a real
30
+ * tldraw editor somewhere on the page keeps its own values.
31
+ */
32
+
33
+ .mocanvas,
34
+ .tl-container {
35
+ /* ---- camera ---------------------------------------------------------
36
+ * The two that are computed, not themed. `--tl-zoom` is the camera's zoom
37
+ * and `--tl-scale` its reciprocal — what a rule multiplies by to hold a
38
+ * constant on-screen size while the canvas zooms.
39
+ */
40
+ --tl-zoom: var(--mocanvas-zoom, 1);
41
+ --tl-scale: var(--mocanvas-scale, 1);
42
+
43
+ /* ---- surfaces and text ---------------------------------------------- */
44
+ --tl-color-background: var(--mocanvas-background, #f9fafb);
45
+ --tl-color-low: var(--mocanvas-background, #f9fafb);
46
+ --tl-color-panel: var(--mocanvas-ui-panel, #ffffff);
47
+ --tl-color-panel-contrast: var(--mocanvas-ui-text, #1d1d1d);
48
+ --tl-color-text: var(--mocanvas-ui-text, #1d1d1d);
49
+ --tl-color-text-1: var(--mocanvas-ui-text, #1d1d1d);
50
+ --tl-color-text-3: var(--mocanvas-ui-muted, #9a9a9a);
51
+ --tl-color-text-shadow: var(--mocanvas-background, #f9fafb);
52
+ --tl-color-divider: var(--mocanvas-ui-panel-border, #e8e8e8);
53
+ --tl-color-muted-1: var(--mocanvas-ui-hover, rgba(0, 0, 0, 0.04));
54
+ --tl-color-muted-2: var(--mocanvas-ui-active, rgba(0, 0, 0, 0.08));
55
+ --tl-color-hint: var(--mocanvas-snap, #bd5b16);
56
+ --tl-color-focus: var(--mocanvas-ui-accent, #2f80ed);
57
+
58
+ /* ---- selection ------------------------------------------------------
59
+ * `--tl-color-selected-contrast` is the one whose absence was found by eye:
60
+ * the chevron cursor draws its outline in it, and an empty value removed the
61
+ * outline without failing anything.
62
+ */
63
+ --tl-color-selected: var(--mocanvas-selection, #2f80ed);
64
+ --tl-color-selected-contrast: var(--mocanvas-selection-fg, #ffffff);
65
+ --tl-color-selection-fill: var(--mocanvas-brush-fill, rgba(47, 128, 237, 0.08));
66
+ --tl-color-selection-stroke: var(--mocanvas-selection, #2f80ed);
67
+ --tl-color-brush-fill: var(--mocanvas-brush-fill, rgba(47, 128, 237, 0.08));
68
+ --tl-color-brush-stroke: var(--mocanvas-brush-stroke, rgba(47, 128, 237, 0.4));
69
+ --tl-color-grid: var(--mocanvas-grid, #d4d4d4);
70
+ --tl-color-laser: #ff0000; /* no equivalent: the laser colour is not on the ramp */
71
+ --tl-color-cursor: var(--mocanvas-selection, #2f80ed);
72
+ --tl-color-note-border: rgba(0, 0, 0, 0.08); /* no equivalent */
73
+
74
+ /* ---- chrome ---------------------------------------------------------- */
75
+ --tl-color-primary: var(--mocanvas-ui-accent, #2f80ed);
76
+ --tl-color-background-secondary: var(--mocanvas-ui-dock, #ffffff);
77
+ --tl-font-draw: var(--mocanvas-ui-font, ui-sans-serif, system-ui, sans-serif);
78
+ --tl-font-sans: var(--mocanvas-ui-font, ui-sans-serif, system-ui, sans-serif);
79
+ --tl-font-mono: var(--mocanvas-ui-mono, ui-monospace, monospace);
80
+ --tl-radius: var(--mocanvas-ui-radius, 10px);
81
+ --tl-shadow-1: var(--mocanvas-ui-shadow, 0 1px 2px rgba(0, 0, 0, 0.12));
82
+ --tl-shadow-2: var(--mocanvas-ui-shadow, 0 2px 6px rgba(0, 0, 0, 0.14));
83
+ --tl-space-1: 4px;
84
+ --tl-space-2: 8px;
85
+ --tl-space-3: 12px;
86
+ --tl-space-4: 16px;
87
+
88
+ /* ---- no equivalent ---------------------------------------------------
89
+ * Static fallbacks. They keep a migrated rule valid; they are not values
90
+ * mocanvas computes, and it will not notice if you need a different one.
91
+ */
92
+ --tl-color-overlay: rgba(0, 0, 0, 0.2);
93
+ --tl-color-background-overlay: rgba(0, 0, 0, 0.2);
94
+ --tl-color-warn: #e03131;
95
+ --tl-color-accent: var(--mocanvas-ui-accent, #2f80ed);
96
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mocanvas/compat",
3
- "version": "4.1.0",
3
+ "version": "4.2.0",
4
4
  "description": "TL-prefixed aliases over the mocanvas API, for projects migrating an existing tldraw app.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Symbio Digital",
@@ -16,6 +16,7 @@
16
16
  "node": ">=22.12.0"
17
17
  },
18
18
  "files": [
19
+ "compat.css",
19
20
  "dist",
20
21
  "README.md",
21
22
  "LICENSE",
@@ -27,13 +28,19 @@
27
28
  "MIGRATION.md",
28
29
  "UI.md"
29
30
  ],
30
- "sideEffects": false,
31
+ "sideEffects": [
32
+ "*.css"
33
+ ],
31
34
  "main": "./dist/index.js",
32
35
  "types": "./dist/index.d.ts",
33
36
  "exports": {
34
37
  ".": {
35
38
  "types": "./dist/index.d.ts",
36
- "import": "./dist/index.js"
39
+ "default": "./dist/index.js"
40
+ },
41
+ "./compat.css": {
42
+ "style": "./compat.css",
43
+ "default": "./compat.css"
37
44
  },
38
45
  "./package.json": "./package.json"
39
46
  },
@@ -41,10 +48,10 @@
41
48
  "access": "public"
42
49
  },
43
50
  "dependencies": {
44
- "@mocanvas/editor": "4.1.0",
45
- "@mocanvas/mocanvas": "4.1.0",
46
- "@mocanvas/store": "4.1.0",
47
- "@mocanvas/state": "4.1.0"
51
+ "@mocanvas/mocanvas": "4.2.0",
52
+ "@mocanvas/editor": "4.2.0",
53
+ "@mocanvas/state": "4.2.0",
54
+ "@mocanvas/store": "4.2.0"
48
55
  },
49
56
  "devDependencies": {
50
57
  "@types/react": "^19.1.0",