sketchmark 0.2.5 → 0.2.7

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/layout/index.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EAKV,MAAM,UAAU,CAAC;AAwZlB,wBAAgB,SAAS,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAmB1E;AAoID,wBAAgB,MAAM,CAAC,EAAE,EAAE,UAAU,GAAG,UAAU,CA+NjD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/layout/index.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EAKV,MAAM,UAAU,CAAC;AA2ZlB,wBAAgB,SAAS,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAmB1E;AAoID,wBAAgB,MAAM,CAAC,EAAE,EAAE,UAAU,GAAG,UAAU,CA+NjD"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/renderer/canvas/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,UAAU,EAOX,MAAM,aAAa,CAAC;AAsCrB,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,EAAQ,MAAM,CAAC;IACrB,UAAU,CAAC,EAAG,MAAM,CAAC;IACrB,SAAS,CAAC,EAAI,MAAM,CAAC;IACrB,MAAM,CAAC,EAAO,MAAM,CAAC;IACrB,KAAK,CAAC,EAAQ,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;IACxC,OAAO,CAAC,EAAM,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAySD,wBAAgB,cAAc,CAC5B,EAAE,EAAO,UAAU,EACnB,MAAM,EAAG,iBAAiB,EAC1B,OAAO,GAAE,qBAA0B,GAClC,IAAI,CA2cN;AAGD,wBAAgB,eAAe,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAOxE;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAEpE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/renderer/canvas/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,UAAU,EAOX,MAAM,aAAa,CAAC;AAsCrB,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,EAAQ,MAAM,CAAC;IACrB,UAAU,CAAC,EAAG,MAAM,CAAC;IACrB,SAAS,CAAC,EAAI,MAAM,CAAC;IACrB,MAAM,CAAC,EAAO,MAAM,CAAC;IACrB,KAAK,CAAC,EAAQ,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;IACxC,OAAO,CAAC,EAAM,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AA+SD,wBAAgB,cAAc,CAC5B,EAAE,EAAO,UAAU,EACnB,MAAM,EAAG,iBAAiB,EAC1B,OAAO,GAAE,qBAA0B,GAClC,IAAI,CA6cN;AAGD,wBAAgB,eAAe,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAOxE;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAEpE"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/renderer/svg/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,UAAU,EAMX,MAAM,aAAa,CAAC;AAqhBrB,MAAM,WAAW,kBAAkB;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;IAClC,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,wBAAgB,WAAW,CACzB,EAAE,EAAE,UAAU,EACd,SAAS,EAAE,WAAW,GAAG,aAAa,EACtC,OAAO,GAAE,kBAAuB,GAC/B,aAAa,CAksBf;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAKtD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/renderer/svg/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,UAAU,EAMX,MAAM,aAAa,CAAC;AA8hBrB,MAAM,WAAW,kBAAkB;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;IAClC,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,wBAAgB,WAAW,CACzB,EAAE,EAAE,UAAU,EACd,SAAS,EAAE,WAAW,GAAG,aAAa,EACtC,OAAO,GAAE,kBAAuB,GAC/B,aAAa,CAosBf;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAKtD"}
@@ -425,7 +425,7 @@ var AIDiagram = (function (exports) {
425
425
  kind: "node",
426
426
  id,
427
427
  shape,
428
- label: props.label || (shape === "image" || shape === "icon" ? "" : id),
428
+ label: props.label || id,
429
429
  ...(groupId ? { groupId } : {}),
430
430
  ...(props.width ? { width: parseFloat(props.width) } : {}),
431
431
  ...(props.height ? { height: parseFloat(props.height) } : {}),
@@ -1510,10 +1510,13 @@ var AIDiagram = (function (exports) {
1510
1510
  }
1511
1511
  break;
1512
1512
  }
1513
- case "icon":
1514
- n.w = n.w || 48;
1515
- n.h = n.h || (n.label !== n.id ? 64 : 48); // extra height for label
1513
+ case "icon": {
1514
+ const iconBase = 48;
1515
+ const labelH = n.label ? 20 : 0;
1516
+ n.w = n.w || Math.max(iconBase, n.label ? labelW : 0);
1517
+ n.h = n.h || (iconBase + labelH);
1516
1518
  break;
1519
+ }
1517
1520
  default:
1518
1521
  n.w = n.w || Math.max(MIN_W, Math.min(MAX_W, labelW));
1519
1522
  n.h = n.h || 52;
@@ -5117,27 +5120,32 @@ var AIDiagram = (function (exports) {
5117
5120
  const iconColor = s.color
5118
5121
  ? encodeURIComponent(String(s.color))
5119
5122
  : encodeURIComponent(String(palette.nodeStroke));
5120
- const iconSize = Math.min(n.w, n.h) - 4;
5123
+ // reserve bottom 20px for label when present
5124
+ const labelSpace = n.label ? 20 : 0;
5125
+ const iconAreaH = n.h - labelSpace;
5126
+ const iconSize = Math.min(n.w, iconAreaH) - 4;
5121
5127
  const iconUrl = `https://api.iconify.design/${prefix}/${name}.svg?color=${iconColor}&width=${iconSize}&height=${iconSize}`;
5122
5128
  const img = document.createElementNS(NS, "image");
5123
5129
  img.setAttribute("href", iconUrl);
5124
- img.setAttribute("x", String(n.x + 1));
5125
- img.setAttribute("y", String(n.y + 1));
5126
- img.setAttribute("width", String(n.w - 2));
5127
- img.setAttribute("height", String(n.h - 2));
5130
+ const iconX = n.x + (n.w - iconSize) / 2;
5131
+ const iconY = n.y + (iconAreaH - iconSize) / 2;
5132
+ img.setAttribute("x", String(iconX));
5133
+ img.setAttribute("y", String(iconY));
5134
+ img.setAttribute("width", String(iconSize));
5135
+ img.setAttribute("height", String(iconSize));
5128
5136
  img.setAttribute("preserveAspectRatio", "xMidYMid meet");
5129
5137
  if (s.opacity != null)
5130
5138
  img.setAttribute("opacity", String(s.opacity));
5131
- // clip-path for rounded corners (same as image)
5139
+ // clip-path for rounded corners
5132
5140
  const clipId = `clip-${n.id}`;
5133
5141
  const defs = document.createElementNS(NS, "defs");
5134
5142
  const clip = document.createElementNS(NS, "clipPath");
5135
5143
  clip.setAttribute("id", clipId);
5136
5144
  const rect = document.createElementNS(NS, "rect");
5137
- rect.setAttribute("x", String(n.x + 1));
5138
- rect.setAttribute("y", String(n.y + 1));
5139
- rect.setAttribute("width", String(n.w - 2));
5140
- rect.setAttribute("height", String(n.h - 2));
5145
+ rect.setAttribute("x", String(iconX));
5146
+ rect.setAttribute("y", String(iconY));
5147
+ rect.setAttribute("width", String(iconSize));
5148
+ rect.setAttribute("height", String(iconSize));
5141
5149
  rect.setAttribute("rx", "6");
5142
5150
  clip.appendChild(rect);
5143
5151
  defs.appendChild(clip);
@@ -5163,12 +5171,15 @@ var AIDiagram = (function (exports) {
5163
5171
  }
5164
5172
  case "image": {
5165
5173
  if (n.imageUrl) {
5174
+ // reserve bottom 20px for label when present
5175
+ const imgLabelSpace = n.label ? 20 : 0;
5176
+ const imgAreaH = n.h - imgLabelSpace;
5166
5177
  const img = document.createElementNS(NS, "image");
5167
5178
  img.setAttribute("href", n.imageUrl);
5168
5179
  img.setAttribute("x", String(n.x + 1));
5169
5180
  img.setAttribute("y", String(n.y + 1));
5170
5181
  img.setAttribute("width", String(n.w - 2));
5171
- img.setAttribute("height", String(n.h - 2));
5182
+ img.setAttribute("height", String(imgAreaH - 2));
5172
5183
  img.setAttribute("preserveAspectRatio", "xMidYMid meet");
5173
5184
  const clipId = `clip-${n.id}`;
5174
5185
  const defs = document.createElementNS(NS, "defs");
@@ -5178,7 +5189,7 @@ var AIDiagram = (function (exports) {
5178
5189
  rect.setAttribute("x", String(n.x + 1));
5179
5190
  rect.setAttribute("y", String(n.y + 1));
5180
5191
  rect.setAttribute("width", String(n.w - 2));
5181
- rect.setAttribute("height", String(n.h - 2));
5192
+ rect.setAttribute("height", String(imgAreaH - 2));
5182
5193
  rect.setAttribute("rx", "6");
5183
5194
  clip.appendChild(rect);
5184
5195
  defs.appendChild(clip);
@@ -5430,11 +5441,14 @@ var AIDiagram = (function (exports) {
5430
5441
  const nodeBodyBottom = n.y + n.h - pad;
5431
5442
  const nodeBodyMid = n.y + n.h / 2;
5432
5443
  const blockH = (lines.length - 1) * lineHeight;
5433
- const textCY = verticalAlign === "top"
5434
- ? nodeBodyTop + blockH / 2
5435
- : verticalAlign === "bottom"
5436
- ? nodeBodyBottom - blockH / 2
5437
- : nodeBodyMid;
5444
+ const isMediaShape = n.shape === "icon" || n.shape === "image";
5445
+ const textCY = isMediaShape
5446
+ ? n.y + n.h - 10 // label below the icon/image
5447
+ : verticalAlign === "top"
5448
+ ? nodeBodyTop + blockH / 2
5449
+ : verticalAlign === "bottom"
5450
+ ? nodeBodyBottom - blockH / 2
5451
+ : nodeBodyMid;
5438
5452
  if (n.label) {
5439
5453
  ng.appendChild(lines.length > 1
5440
5454
  ? mkMultilineText(lines, textX, textCY, fontSize, fontWeight, textColor, textAnchor, lineHeight, nodeFont, letterSpacing)
@@ -6145,7 +6159,10 @@ var AIDiagram = (function (exports) {
6145
6159
  const iconColor = s.color
6146
6160
  ? encodeURIComponent(String(s.color))
6147
6161
  : encodeURIComponent(String(palette.nodeStroke));
6148
- const iconSize = Math.min(n.w, n.h) - 4;
6162
+ // reserve bottom for label
6163
+ const iconLabelSpace = n.label ? 20 : 0;
6164
+ const iconAreaH = n.h - iconLabelSpace;
6165
+ const iconSize = Math.min(n.w, iconAreaH) - 4;
6149
6166
  const iconUrl = `https://api.iconify.design/${prefix}/${name}.svg?color=${iconColor}&width=${iconSize}&height=${iconSize}`;
6150
6167
  const img = new Image();
6151
6168
  img.crossOrigin = 'anonymous';
@@ -6153,23 +6170,23 @@ var AIDiagram = (function (exports) {
6153
6170
  ctx.save();
6154
6171
  if (s.opacity != null)
6155
6172
  ctx.globalAlpha = Number(s.opacity);
6156
- // clip-path for rounded corners (same as image)
6173
+ const iconX = n.x + (n.w - iconSize) / 2;
6174
+ const iconY = n.y + (iconAreaH - iconSize) / 2;
6157
6175
  ctx.beginPath();
6158
6176
  const r = 6;
6159
- ctx.moveTo(n.x + r, n.y);
6160
- ctx.lineTo(n.x + n.w - r, n.y);
6161
- ctx.quadraticCurveTo(n.x + n.w, n.y, n.x + n.w, n.y + r);
6162
- ctx.lineTo(n.x + n.w, n.y + n.h - r);
6163
- ctx.quadraticCurveTo(n.x + n.w, n.y + n.h, n.x + n.w - r, n.y + n.h);
6164
- ctx.lineTo(n.x + r, n.y + n.h);
6165
- ctx.quadraticCurveTo(n.x, n.y + n.h, n.x, n.y + n.h - r);
6166
- ctx.lineTo(n.x, n.y + r);
6167
- ctx.quadraticCurveTo(n.x, n.y, n.x + r, n.y);
6177
+ ctx.moveTo(iconX + r, iconY);
6178
+ ctx.lineTo(iconX + iconSize - r, iconY);
6179
+ ctx.quadraticCurveTo(iconX + iconSize, iconY, iconX + iconSize, iconY + r);
6180
+ ctx.lineTo(iconX + iconSize, iconY + iconSize - r);
6181
+ ctx.quadraticCurveTo(iconX + iconSize, iconY + iconSize, iconX + iconSize - r, iconY + iconSize);
6182
+ ctx.lineTo(iconX + r, iconY + iconSize);
6183
+ ctx.quadraticCurveTo(iconX, iconY + iconSize, iconX, iconY + iconSize - r);
6184
+ ctx.lineTo(iconX, iconY + r);
6185
+ ctx.quadraticCurveTo(iconX, iconY, iconX + r, iconY);
6168
6186
  ctx.closePath();
6169
6187
  ctx.clip();
6170
- ctx.drawImage(img, n.x + 1, n.y + 1, n.w - 2, n.h - 2);
6188
+ ctx.drawImage(img, iconX, iconY, iconSize, iconSize);
6171
6189
  ctx.restore();
6172
- // only draw border when stroke is explicitly set
6173
6190
  if (s.stroke) {
6174
6191
  rc.rectangle(n.x + 1, n.y + 1, n.w - 2, n.h - 2, { ...opts, fill: 'none' });
6175
6192
  }
@@ -6183,6 +6200,9 @@ var AIDiagram = (function (exports) {
6183
6200
  }
6184
6201
  case 'image': {
6185
6202
  if (n.imageUrl) {
6203
+ // reserve bottom for label
6204
+ const imgLblSpace = n.label ? 20 : 0;
6205
+ const imgAreaH = n.h - imgLblSpace;
6186
6206
  const img = new Image();
6187
6207
  img.crossOrigin = 'anonymous';
6188
6208
  img.onload = () => {
@@ -6192,15 +6212,15 @@ var AIDiagram = (function (exports) {
6192
6212
  ctx.moveTo(n.x + r, n.y);
6193
6213
  ctx.lineTo(n.x + n.w - r, n.y);
6194
6214
  ctx.quadraticCurveTo(n.x + n.w, n.y, n.x + n.w, n.y + r);
6195
- ctx.lineTo(n.x + n.w, n.y + n.h - r);
6196
- ctx.quadraticCurveTo(n.x + n.w, n.y + n.h, n.x + n.w - r, n.y + n.h);
6197
- ctx.lineTo(n.x + r, n.y + n.h);
6198
- ctx.quadraticCurveTo(n.x, n.y + n.h, n.x, n.y + n.h - r);
6215
+ ctx.lineTo(n.x + n.w, n.y + imgAreaH - r);
6216
+ ctx.quadraticCurveTo(n.x + n.w, n.y + imgAreaH, n.x + n.w - r, n.y + imgAreaH);
6217
+ ctx.lineTo(n.x + r, n.y + imgAreaH);
6218
+ ctx.quadraticCurveTo(n.x, n.y + imgAreaH, n.x, n.y + imgAreaH - r);
6199
6219
  ctx.lineTo(n.x, n.y + r);
6200
6220
  ctx.quadraticCurveTo(n.x, n.y, n.x + r, n.y);
6201
6221
  ctx.closePath();
6202
6222
  ctx.clip();
6203
- ctx.drawImage(img, n.x + 1, n.y + 1, n.w - 2, n.h - 2);
6223
+ ctx.drawImage(img, n.x + 1, n.y + 1, n.w - 2, imgAreaH - 2);
6204
6224
  ctx.restore();
6205
6225
  // only draw border when stroke is explicitly set
6206
6226
  if (s.stroke) {
@@ -6392,9 +6412,12 @@ var AIDiagram = (function (exports) {
6392
6412
  const nodeBodyTop = n.y + pad;
6393
6413
  const nodeBodyBottom = n.y + n.h - pad;
6394
6414
  const blockH = (lines.length - 1) * lineHeight;
6395
- const textCY = vertAlign === 'top' ? nodeBodyTop + blockH / 2
6396
- : vertAlign === 'bottom' ? nodeBodyBottom - blockH / 2
6397
- : n.y + n.h / 2; // middle (default)
6415
+ const isMediaShape = n.shape === 'icon' || n.shape === 'image';
6416
+ const textCY = isMediaShape
6417
+ ? n.y + n.h - 10 // label below the icon/image
6418
+ : vertAlign === 'top' ? nodeBodyTop + blockH / 2
6419
+ : vertAlign === 'bottom' ? nodeBodyBottom - blockH / 2
6420
+ : n.y + n.h / 2; // middle (default)
6398
6421
  if (n.label) {
6399
6422
  if (lines.length > 1) {
6400
6423
  drawMultilineText(ctx, lines, textX, textCY, fontSize, fontWeight, textColor, textAlign, lineHeight, nodeFont, letterSpacing);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sketchmark",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "A plain-text DSL for hand-drawn diagrams. Write boxes, edges, and groups as code — renders sketchy SVG/Canvas via rough.js with a built-in step-by-step animation system.",
5
5
  "keywords": [
6
6
  "diagram",