@snowcone-app/canvas 0.40.21 → 0.40.23

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 (50) hide show
  1. package/dist/{CanvasRenderer-BmLEU_Zb.js → CanvasRenderer-JcBrIZ6I.js} +454 -452
  2. package/dist/{CanvasRenderer-BmLEU_Zb.js.map → CanvasRenderer-JcBrIZ6I.js.map} +1 -1
  3. package/dist/{CanvasStateV1-DnpfA376.js → CanvasStateV1-BJ5-75NN.js} +3 -3
  4. package/dist/{CanvasStateV1-DnpfA376.js.map → CanvasStateV1-BJ5-75NN.js.map} +1 -1
  5. package/dist/{ContextualToolbars-DSJykxdc.js → ContextualToolbars-wmbHxn5a.js} +2058 -1991
  6. package/dist/{ContextualToolbars-DSJykxdc.js.map → ContextualToolbars-wmbHxn5a.js.map} +1 -1
  7. package/dist/{EditorCanvasImpl-t5MD0lMB.js → EditorCanvasImpl-CI_mLBGt.js} +8 -8
  8. package/dist/{EditorCanvasImpl-t5MD0lMB.js.map → EditorCanvasImpl-CI_mLBGt.js.map} +1 -1
  9. package/dist/{ExportManager-CnUTZrbv.js → ExportManager-CHlByUYV.js} +856 -839
  10. package/dist/ExportManager-CHlByUYV.js.map +1 -0
  11. package/dist/{FontAnalyzer-Bjtl4XTH.js → FontAnalyzer-Bj2KrX80.js} +1592 -1530
  12. package/dist/FontAnalyzer-Bj2KrX80.js.map +1 -0
  13. package/dist/{ImagePanel-AWQgzuXz.js → ImagePanel-0ZwDDaCy.js} +6 -6
  14. package/dist/{ImagePanel-AWQgzuXz.js.map → ImagePanel-0ZwDDaCy.js.map} +1 -1
  15. package/dist/{SnowconeCanvas-BWv3Sd5P.js → SnowconeCanvas-0w0-l9tm.js} +10 -10
  16. package/dist/{SnowconeCanvas-BWv3Sd5P.js.map → SnowconeCanvas-0w0-l9tm.js.map} +1 -1
  17. package/dist/advanced.mjs +39 -39
  18. package/dist/components/toolbars/SecondaryPanels.d.ts +3 -0
  19. package/dist/core/ImageElement.d.ts +20 -0
  20. package/dist/core/TextMetrics.d.ts +14 -2
  21. package/dist/core/masked-crop.d.ts +57 -0
  22. package/dist/{custom-icons-Bn8_I4kt.js → custom-icons-up58ZbC9.js} +2 -2
  23. package/dist/{custom-icons-Bn8_I4kt.js.map → custom-icons-up58ZbC9.js.map} +1 -1
  24. package/dist/{design-builder-B3v5OAQo.js → design-builder-DUEwCUmA.js} +396 -396
  25. package/dist/{design-builder-B3v5OAQo.js.map → design-builder-DUEwCUmA.js.map} +1 -1
  26. package/dist/{embed-D6-jVZMw.js → embed-VKMR6QO1.js} +10 -10
  27. package/dist/{embed-D6-jVZMw.js.map → embed-VKMR6QO1.js.map} +1 -1
  28. package/dist/embed.mjs +7 -7
  29. package/dist/{export-worker.bundle.string-DXciOLDt.js → export-worker.bundle.string-C6Zm9Wt-.js} +146 -27
  30. package/dist/{export-worker.bundle.string-DXciOLDt.js.map → export-worker.bundle.string-C6Zm9Wt-.js.map} +1 -1
  31. package/dist/{guards-B_Q3pewr.js → guards-CQeF53PN.js} +2 -2
  32. package/dist/{guards-B_Q3pewr.js.map → guards-CQeF53PN.js.map} +1 -1
  33. package/dist/index.mjs +9 -9
  34. package/dist/internals.mjs +6 -6
  35. package/dist/rendering/MaskRenderer.d.ts +13 -0
  36. package/dist/{template-fields-B4sJfQjP.js → template-fields-tobyHoMe.js} +5 -5
  37. package/dist/{template-fields-B4sJfQjP.js.map → template-fields-tobyHoMe.js.map} +1 -1
  38. package/dist/testing.mjs +3 -3
  39. package/dist/types/index.d.ts +10 -0
  40. package/dist/{useCommands-CZHeVauL.js → useCommands-Cm3mDB-l.js} +225 -225
  41. package/dist/{useCommands-CZHeVauL.js.map → useCommands-Cm3mDB-l.js.map} +1 -1
  42. package/dist/{usePieceGuideBundle-DsCv7HKy.js → usePieceGuideBundle-BTnUn33k.js} +2 -2
  43. package/dist/{usePieceGuideBundle-DsCv7HKy.js.map → usePieceGuideBundle-BTnUn33k.js.map} +1 -1
  44. package/dist/{validation-D9catdeB.js → validation-D4zxugNJ.js} +11 -11
  45. package/dist/{validation-D9catdeB.js.map → validation-D4zxugNJ.js.map} +1 -1
  46. package/dist/workers/export-worker.bundle.string.d.ts +1 -1
  47. package/example/package.json +1 -1
  48. package/package.json +3 -3
  49. package/dist/ExportManager-CnUTZrbv.js.map +0 -1
  50. package/dist/FontAnalyzer-Bjtl4XTH.js.map +0 -1
package/dist/embed.mjs CHANGED
@@ -1,10 +1,10 @@
1
- import { C as a, g as t, h as o, K as r, N as i, O as n, P as d, Q as m, R as u, b as l, a as E, j as c, k as p, l as g } from "./useCommands-CZHeVauL.js";
2
- import { E as C, R as S, a as T, b as f, S as P, c as R, d as b, e as B, f as v, g as y, i as F, h, p as k, s as D, j as I, k as K, l as L, v as w } from "./embed-D6-jVZMw.js";
3
- import { t as M, Y as j } from "./FontAnalyzer-Bjtl4XTH.js";
4
- import { D as N, e as Y, h as _, i as z, b as H } from "./design-builder-B3v5OAQo.js";
5
- import { D as O, T as Q, r as V, u as q, a as U, b as W, c as X, d as Z, e as $, w as ee } from "./template-fields-B4sJfQjP.js";
6
- import { G as ae, H as te, J as oe, K as re } from "./ExportManager-CnUTZrbv.js";
7
- import { s as ne } from "./CanvasStateV1-DnpfA376.js";
1
+ import { C as a, g as t, h as o, K as r, N as i, O as n, P as d, Q as m, R as u, b as l, a as E, j as c, k as p, l as g } from "./useCommands-Cm3mDB-l.js";
2
+ import { E as C, R as S, a as T, b as f, S as P, c as R, d as b, e as B, f as v, g as y, i as F, h, p as k, s as D, j as I, k as K, l as L, v as w } from "./embed-VKMR6QO1.js";
3
+ import { t as M, Y as j } from "./FontAnalyzer-Bj2KrX80.js";
4
+ import { D as N, e as Y, h as _, i as z, b as H } from "./design-builder-DUEwCUmA.js";
5
+ import { D as O, T as Q, r as V, u as q, a as U, b as W, c as X, d as Z, e as $, w as ee } from "./template-fields-tobyHoMe.js";
6
+ import { G as ae, H as te, J as oe, K as re } from "./ExportManager-CHlByUYV.js";
7
+ import { s as ne } from "./CanvasStateV1-BJ5-75NN.js";
8
8
  export {
9
9
  a as CanvasServicesProvider,
10
10
  N as DesignBuilder,
@@ -19829,6 +19829,9 @@ const n = `"use strict";
19829
19829
  }
19830
19830
  return _measureCanvas;
19831
19831
  }
19832
+ function wrapFitTolerance(maxWidth) {
19833
+ return 0.5 + Math.max(0, maxWidth) * 0.01;
19834
+ }
19832
19835
  function buildFontString2(fontSize, fontFamily, bold = false, italic = false) {
19833
19836
  const parts = [];
19834
19837
  if (italic) {
@@ -19886,15 +19889,15 @@ const n = `"use strict";
19886
19889
  const allTextWithSpaces = leadingSpaces + allText + trailingSpaces;
19887
19890
  const allTextWidth = measure(allTextWithSpaces);
19888
19891
  const isSmallSize = maxWidth < 200;
19889
- const wrapTolerancePercent = strict ? 0 : isSmallSize ? 0.08 : 0.05;
19890
- const wrapTolerance = strict ? 0 : Math.max(20, maxWidth * wrapTolerancePercent);
19892
+ const wrapTolerancePercent = isSmallSize ? 0.08 : 0.05;
19893
+ const wrapTolerance = strict ? wrapFitTolerance(maxWidth) : Math.max(20, maxWidth * wrapTolerancePercent);
19891
19894
  if (allTextWidth <= maxWidth + wrapTolerance) {
19892
19895
  return [allTextWithSpaces];
19893
19896
  }
19894
19897
  const lines = [];
19895
19898
  let currentLine = "";
19896
- const lineTolerancePercent = strict ? 0 : isSmallSize ? 0.05 : 0.03;
19897
- const lineTolerance = strict ? 0 : Math.max(15, maxWidth * lineTolerancePercent);
19899
+ const lineTolerancePercent = isSmallSize ? 0.05 : 0.03;
19900
+ const lineTolerance = strict ? wrapFitTolerance(maxWidth) : Math.max(15, maxWidth * lineTolerancePercent);
19898
19901
  for (let i = 0; i < words.length; i++) {
19899
19902
  const word = words[i];
19900
19903
  const wordWidth = measure(word);
@@ -20961,6 +20964,7 @@ const n = `"use strict";
20961
20964
  function wrapRichTextSpans(spans, maxWidth, element) {
20962
20965
  const ctx = getMeasureContext();
20963
20966
  const lines = [];
20967
+ const fitWidth = maxWidth + wrapFitTolerance(maxWidth);
20964
20968
  const measureText = (text, style) => {
20965
20969
  const fontSize = style.fontSize || element.fontSize;
20966
20970
  const fontFamily = style.fontFamily || element.fontFamily;
@@ -21050,7 +21054,7 @@ const n = `"use strict";
21050
21054
  }
21051
21055
  currentLineWidth += wordWidth;
21052
21056
  } else {
21053
- if (wordWidth > maxWidth) {
21057
+ if (wordWidth > fitWidth) {
21054
21058
  if (currentLine.length > 0) {
21055
21059
  finishLine();
21056
21060
  }
@@ -21059,7 +21063,7 @@ const n = `"use strict";
21059
21063
  let charBuffer = "";
21060
21064
  for (const char of chars) {
21061
21065
  const charWidth = measureText(char, span.style);
21062
- if (currentLineWidth + charWidth > maxWidth && currentLineWidth > 0) {
21066
+ if (currentLineWidth + charWidth > fitWidth && currentLineWidth > 0) {
21063
21067
  if (charBuffer.length > 0) {
21064
21068
  if (currentLine.length > 0) {
21065
21069
  const lastSpan = currentLine[currentLine.length - 1];
@@ -21092,7 +21096,7 @@ const n = `"use strict";
21092
21096
  }
21093
21097
  }
21094
21098
  } else {
21095
- if (currentLineWidth + wordWidth > maxWidth && currentLine.length > 0) {
21099
+ if (currentLineWidth + wordWidth > fitWidth && currentLine.length > 0) {
21096
21100
  finishLine();
21097
21101
  }
21098
21102
  wordSpans.forEach((span) => {
@@ -23137,6 +23141,29 @@ const n = `"use strict";
23137
23141
  };
23138
23142
  }
23139
23143
 
23144
+ // src/core/masked-crop.ts
23145
+ var MASKED_CROP_FRAME = "frame";
23146
+ var FULL_CROP = Object.freeze({ cropX: 0, cropY: 0, cropWidth: 1, cropHeight: 1 });
23147
+ function isLegacyMaskedCrop(td, hasMasks) {
23148
+ return hasMasks && td?.maskedCrop !== MASKED_CROP_FRAME;
23149
+ }
23150
+ function effectiveImageCrop(td, hasMasks) {
23151
+ if (!td || isLegacyMaskedCrop(td, hasMasks)) return { ...FULL_CROP };
23152
+ return {
23153
+ cropX: td.cropX ?? 0,
23154
+ cropY: td.cropY ?? 0,
23155
+ cropWidth: td.cropWidth ?? 1,
23156
+ cropHeight: td.cropHeight ?? 1
23157
+ };
23158
+ }
23159
+ function imageFrameSize(td, hasMasks) {
23160
+ const c = effectiveImageCrop(td, hasMasks);
23161
+ return { width: (td?.width ?? 0) * c.cropWidth, height: (td?.height ?? 0) * c.cropHeight };
23162
+ }
23163
+ function hasImageMasks(el) {
23164
+ return Array.isArray(el?.masks) && el.masks.length > 0;
23165
+ }
23166
+
23140
23167
  // src/effects/mask-presets.ts
23141
23168
  var THUMB_SIZE2 = 64;
23142
23169
  var MASK_SIZE = 512;
@@ -23468,6 +23495,15 @@ const n = `"use strict";
23468
23495
  }
23469
23496
  ctx.restore();
23470
23497
  }
23498
+ function maskParentFrameSize(parentElement) {
23499
+ const parentTd = parentElement.transformData;
23500
+ const parentAny = parentElement;
23501
+ const parentFrame = parentTd && parentTd.type === "image" ? imageFrameSize(parentTd, hasImageMasks(parentElement)) : null;
23502
+ return {
23503
+ width: parentFrame?.width || parentTd?.width || parentAny.width || 0,
23504
+ height: parentFrame?.height || parentTd?.height || parentAny.height || 0
23505
+ };
23506
+ }
23471
23507
  function renderMaskElement(ctx, maskElement, parentElement) {
23472
23508
  const parentX = parentElement.x || 0;
23473
23509
  const parentY = parentElement.y || 0;
@@ -23481,10 +23517,7 @@ const n = `"use strict";
23481
23517
  rotation: (maskElement.rotation || 0) + (parentElement.rotation || 0)
23482
23518
  };
23483
23519
  const MASK_OVERSIZE = 4;
23484
- const parentTd = parentElement.transformData;
23485
- const parentAny = parentElement;
23486
- const parentW = parentTd?.width || parentAny.width || 0;
23487
- const parentH = parentTd?.height || parentAny.height || 0;
23520
+ const { width: parentW, height: parentH } = maskParentFrameSize(parentElement);
23488
23521
  const maskTd = maskElement.transformData;
23489
23522
  if (parentW && parentH && maskTd) {
23490
23523
  absoluteMaskElement.transformData = {
@@ -23929,8 +23962,8 @@ const n = `"use strict";
23929
23962
  ctx.fillStyle = artboardData.backgroundColor || "#ffffff";
23930
23963
  ctx.fillRect(0, 0, artboardData.width, artboardData.height);
23931
23964
  }
23932
- await preloadDistressTextures(elements, artboardData);
23933
- await preloadMaskImages(elements);
23965
+ await preloadDistressTextures(walkElements(elements), artboardData);
23966
+ await preloadMaskImages(walkElements(elements));
23934
23967
  const renderStartTime = performance.now();
23935
23968
  await renderElements(ctx, elements, artboardData);
23936
23969
  if (artboardData.distressTexture?.enabled) {
@@ -24058,7 +24091,7 @@ const n = `"use strict";
24058
24091
  };
24059
24092
  renderShapeElement(ctx, adjustedElement);
24060
24093
  } else if (element.type === "group") {
24061
- console.warn(\`[Export Worker] Group rendering not yet implemented: \${element.id}\`);
24094
+ renderGroupElement(ctx, element, artboardX, artboardY);
24062
24095
  } else {
24063
24096
  console.warn(\`[Export Worker] Unknown element type: \${element.type}\`);
24064
24097
  }
@@ -24146,6 +24179,71 @@ const n = `"use strict";
24146
24179
  }
24147
24180
  }
24148
24181
  async function renderElements(ctx, elements, artboardData) {
24182
+ activeArtboard = artboardData;
24183
+ renderElementList(ctx, elements, artboardData);
24184
+ }
24185
+ var activeArtboard = null;
24186
+ function renderGroupElement(ctx, group, artboardX, artboardY) {
24187
+ const children = (group.children ?? []).filter((c) => c && c.visible !== false).map((c) => ({ ...c, type: c.type || c.transformType }));
24188
+ if (children.length === 0) return;
24189
+ const layer = new OffscreenCanvas(ctx.canvas.width, ctx.canvas.height);
24190
+ const layerCtx = layer.getContext("2d");
24191
+ layerCtx.imageSmoothingEnabled = true;
24192
+ layerCtx.imageSmoothingQuality = "high";
24193
+ layerCtx.setTransform(ctx.getTransform());
24194
+ renderElementList(layerCtx, children, {
24195
+ ...activeArtboard ?? { id: group.id, name: group.id, width: ctx.canvas.width, height: ctx.canvas.height },
24196
+ x: artboardX,
24197
+ y: artboardY,
24198
+ backgroundColor: "transparent",
24199
+ exportBackground: false
24200
+ });
24201
+ ctx.save();
24202
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
24203
+ if (typeof group.opacity === "number" && group.opacity < 1) ctx.globalAlpha *= Math.max(0, group.opacity);
24204
+ ctx.drawImage(layer, 0, 0);
24205
+ ctx.restore();
24206
+ }
24207
+ function renderClippedSegments(ctx, elements, paint) {
24208
+ let content = [];
24209
+ const flush = (mask) => {
24210
+ if (!mask) {
24211
+ for (const el of content) paint(ctx, el);
24212
+ content = [];
24213
+ return;
24214
+ }
24215
+ const layer = new OffscreenCanvas(ctx.canvas.width, ctx.canvas.height);
24216
+ const layerCtx = layer.getContext("2d");
24217
+ layerCtx.imageSmoothingEnabled = true;
24218
+ layerCtx.imageSmoothingQuality = "high";
24219
+ layerCtx.setTransform(ctx.getTransform());
24220
+ for (const el of content) paint(layerCtx, el);
24221
+ const maskLayer = new OffscreenCanvas(ctx.canvas.width, ctx.canvas.height);
24222
+ const maskCtx = maskLayer.getContext("2d");
24223
+ maskCtx.setTransform(ctx.getTransform());
24224
+ paint(maskCtx, mask);
24225
+ layerCtx.save();
24226
+ layerCtx.setTransform(1, 0, 0, 1, 0, 0);
24227
+ layerCtx.globalCompositeOperation = "destination-in";
24228
+ layerCtx.drawImage(maskLayer, 0, 0);
24229
+ layerCtx.restore();
24230
+ ctx.save();
24231
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
24232
+ ctx.drawImage(layer, 0, 0);
24233
+ ctx.restore();
24234
+ content = [];
24235
+ };
24236
+ for (const el of elements) {
24237
+ if (el.isClipping || el.blendMode === "clip") {
24238
+ if (content.length > 0) flush(el);
24239
+ else paint(ctx, el);
24240
+ } else {
24241
+ content.push(el);
24242
+ }
24243
+ }
24244
+ flush();
24245
+ }
24246
+ function renderElementList(ctx, elements, artboardData) {
24149
24247
  const artboardX = artboardData.x || 0;
24150
24248
  const artboardY = artboardData.y || 0;
24151
24249
  const allElementConfigs = elements.map((el) => ({
@@ -24169,11 +24267,11 @@ const n = `"use strict";
24169
24267
  const elementConfig = allElementConfigs[i];
24170
24268
  const compositeOp = element.blendMode === "knockout" ? "destination-out" : "destination-in";
24171
24269
  const scope = elementConfig.knockoutParts?.scope || "group";
24172
- if (scope === "artboard") {
24173
- for (let j = 0; j < i; j++) {
24174
- const id = allElementConfigs[j].id;
24175
- if (id) knockoutRenderedIds.add(id);
24176
- }
24270
+ const hasCompositingParts = elementConfig.knockoutParts?.fill || elementConfig.knockoutParts?.stroke;
24271
+ if (!hasCompositingParts || scope !== "artboard") continue;
24272
+ for (let j = 0; j < i; j++) {
24273
+ const id = allElementConfigs[j].id;
24274
+ if (id) knockoutRenderedIds.add(id);
24177
24275
  }
24178
24276
  renderWithCompositing(
24179
24277
  ctx,
@@ -24187,15 +24285,29 @@ const n = `"use strict";
24187
24285
  knockoutRenderedIds.add(element.id);
24188
24286
  }
24189
24287
  }
24190
- for (const element of elements) {
24191
- if (!knockoutRenderedIds.has(element.id)) {
24288
+ renderClippedSegments(
24289
+ ctx,
24290
+ elements.filter((element) => !knockoutRenderedIds.has(element.id) && element.visible !== false),
24291
+ (target, element) => {
24192
24292
  try {
24193
- renderSingleElementWithEffects(ctx, element, artboardX, artboardY);
24293
+ renderSingleElementWithEffects(target, element, artboardX, artboardY);
24194
24294
  } catch (error) {
24195
24295
  console.error(\`[Export Worker] Failed to render element \${element.id}:\`, error);
24196
24296
  }
24197
24297
  }
24198
- }
24298
+ );
24299
+ }
24300
+ function walkElements(elements) {
24301
+ const out = [];
24302
+ const visit = (list) => {
24303
+ for (const el of list ?? []) {
24304
+ if (!el) continue;
24305
+ out.push(el);
24306
+ if (Array.isArray(el.children)) visit(el.children);
24307
+ }
24308
+ };
24309
+ visit(elements);
24310
+ return out;
24199
24311
  }
24200
24312
  async function preloadDistressTextures(elements, artboardData) {
24201
24313
  const textureUrls = /* @__PURE__ */ new Set();
@@ -24269,9 +24381,16 @@ const n = `"use strict";
24269
24381
  async function applyWorkerArtboardImageMask(ctx, config, artboard) {
24270
24382
  if (!config.enabled || !config.imageUrl || config.opacity <= 0) return;
24271
24383
  try {
24272
- const response = await fetch(config.imageUrl);
24273
- const blob = await response.blob();
24274
- const img = await createImageBitmap(blob);
24384
+ let img;
24385
+ if (config.imageUrl.startsWith("builtin-mask:")) {
24386
+ const generated = generateMaskBitmap(config.imageUrl);
24387
+ if (!generated) throw new Error(\`E_MASK_PRESET_UNKNOWN: \${config.imageUrl}\`);
24388
+ img = generated;
24389
+ } else {
24390
+ const response = await fetch(config.imageUrl);
24391
+ const blob = await response.blob();
24392
+ img = await createImageBitmap(blob);
24393
+ }
24275
24394
  const transform = ctx.getTransform();
24276
24395
  const pixelWidth = transform.a * artboard.width;
24277
24396
  const pixelHeight = transform.d * artboard.height;
@@ -24354,4 +24473,4 @@ const n = `"use strict";
24354
24473
  export {
24355
24474
  n as default
24356
24475
  };
24357
- //# sourceMappingURL=export-worker.bundle.string-DXciOLDt.js.map
24476
+ //# sourceMappingURL=export-worker.bundle.string-C6Zm9Wt-.js.map