@spectratools/graphic-designer-cli 0.7.0 → 0.7.1

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/dist/renderer.js CHANGED
@@ -1151,12 +1151,12 @@ function withAlpha2(color, alpha) {
1151
1151
  }
1152
1152
  function drawGradientRect(ctx, rect, gradient, borderRadius = 0) {
1153
1153
  const fill = gradient.type === "linear" ? createLinearRectGradient(ctx, rect, gradient.angle ?? 180) : ctx.createRadialGradient(
1154
- rect.x + rect.width / 2,
1155
- rect.y + rect.height / 2,
1156
- 0,
1157
- rect.x + rect.width / 2,
1158
- rect.y + rect.height / 2,
1159
- Math.max(rect.width, rect.height) / 2
1154
+ gradient.cx ?? rect.x + rect.width / 2,
1155
+ gradient.cy ?? rect.y + rect.height / 2,
1156
+ gradient.innerRadius ?? 0,
1157
+ gradient.cx ?? rect.x + rect.width / 2,
1158
+ gradient.cy ?? rect.y + rect.height / 2,
1159
+ gradient.outerRadius ?? Math.max(rect.width, rect.height) / 2
1160
1160
  );
1161
1161
  addGradientStops(fill, gradient.stops);
1162
1162
  ctx.save();
@@ -2610,6 +2610,13 @@ function expandRect(rect, amount) {
2610
2610
  height: rect.height + amount * 2
2611
2611
  };
2612
2612
  }
2613
+ function applyDrawShadow(ctx, shadow) {
2614
+ if (!shadow) return;
2615
+ ctx.shadowColor = shadow.color;
2616
+ ctx.shadowBlur = shadow.blur;
2617
+ ctx.shadowOffsetX = shadow.offsetX;
2618
+ ctx.shadowOffsetY = shadow.offsetY;
2619
+ }
2613
2620
  function fromPoints(points) {
2614
2621
  const minX = Math.min(...points.map((point) => point.x));
2615
2622
  const minY = Math.min(...points.map((point) => point.y));
@@ -2791,6 +2798,7 @@ function renderDrawCommands(ctx, commands, theme) {
2791
2798
  height: command.height
2792
2799
  };
2793
2800
  withOpacity(ctx, command.opacity, () => {
2801
+ applyDrawShadow(ctx, command.shadow);
2794
2802
  roundRectPath(ctx, rect, command.radius);
2795
2803
  if (command.fill) {
2796
2804
  ctx.fillStyle = command.fill;
@@ -2814,6 +2822,7 @@ function renderDrawCommands(ctx, commands, theme) {
2814
2822
  }
2815
2823
  case "circle": {
2816
2824
  withOpacity(ctx, command.opacity, () => {
2825
+ applyDrawShadow(ctx, command.shadow);
2817
2826
  ctx.beginPath();
2818
2827
  ctx.arc(command.cx, command.cy, command.radius, 0, Math.PI * 2);
2819
2828
  ctx.closePath();
@@ -2848,6 +2857,7 @@ function renderDrawCommands(ctx, commands, theme) {
2848
2857
  case "text": {
2849
2858
  const fontFamily = resolveDrawFont(theme, command.fontFamily);
2850
2859
  withOpacity(ctx, command.opacity, () => {
2860
+ applyDrawShadow(ctx, command.shadow);
2851
2861
  applyFont(ctx, {
2852
2862
  size: command.fontSize,
2853
2863
  weight: command.fontWeight,
@@ -2898,6 +2908,7 @@ function renderDrawCommands(ctx, commands, theme) {
2898
2908
  const to = { x: command.x2, y: command.y2 };
2899
2909
  const lineAngle = angleBetween(from, to);
2900
2910
  withOpacity(ctx, command.opacity, () => {
2911
+ applyDrawShadow(ctx, command.shadow);
2901
2912
  drawLine(ctx, from, to, {
2902
2913
  color: command.color,
2903
2914
  width: command.width,
@@ -2922,6 +2933,7 @@ function renderDrawCommands(ctx, commands, theme) {
2922
2933
  case "bezier": {
2923
2934
  const points = command.points;
2924
2935
  withOpacity(ctx, command.opacity, () => {
2936
+ applyDrawShadow(ctx, command.shadow);
2925
2937
  drawBezier(ctx, points, {
2926
2938
  color: command.color,
2927
2939
  width: command.width,
@@ -2955,6 +2967,7 @@ function renderDrawCommands(ctx, commands, theme) {
2955
2967
  const operations = parseSvgPath(command.d);
2956
2968
  const baseBounds = pathBounds(operations);
2957
2969
  withOpacity(ctx, command.opacity, () => {
2970
+ applyDrawShadow(ctx, command.shadow);
2958
2971
  applySvgOperations(ctx, operations);
2959
2972
  if (command.fill) {
2960
2973
  ctx.fillStyle = command.fill;
@@ -2995,9 +3008,16 @@ function renderDrawCommands(ctx, commands, theme) {
2995
3008
  height: textHeight + command.paddingY * 2
2996
3009
  };
2997
3010
  withOpacity(ctx, command.opacity, () => {
3011
+ applyDrawShadow(ctx, command.shadow);
2998
3012
  roundRectPath(ctx, rect, command.borderRadius);
2999
3013
  ctx.fillStyle = command.background;
3000
3014
  ctx.fill();
3015
+ if (command.shadow) {
3016
+ ctx.shadowColor = "transparent";
3017
+ ctx.shadowBlur = 0;
3018
+ ctx.shadowOffsetX = 0;
3019
+ ctx.shadowOffsetY = 0;
3020
+ }
3001
3021
  applyFont(ctx, {
3002
3022
  size: command.fontSize,
3003
3023
  weight: 600,
@@ -3025,6 +3045,7 @@ function renderDrawCommands(ctx, commands, theme) {
3025
3045
  height: command.height
3026
3046
  };
3027
3047
  withOpacity(ctx, command.opacity, () => {
3048
+ applyDrawShadow(ctx, command.shadow);
3028
3049
  drawGradientRect(ctx, rect, command.gradient, command.radius);
3029
3050
  });
3030
3051
  rendered.push({
@@ -3346,9 +3367,19 @@ var linearGradientSchema = z2.object({
3346
3367
  }).strict();
3347
3368
  var radialGradientSchema = z2.object({
3348
3369
  type: z2.literal("radial"),
3370
+ cx: z2.number().optional(),
3371
+ cy: z2.number().optional(),
3372
+ innerRadius: z2.number().min(0).optional(),
3373
+ outerRadius: z2.number().min(0).optional(),
3349
3374
  stops: z2.array(gradientStopSchema).min(2)
3350
3375
  }).strict();
3351
3376
  var gradientSchema = z2.discriminatedUnion("type", [linearGradientSchema, radialGradientSchema]);
3377
+ var drawShadowSchema = z2.object({
3378
+ color: colorHexSchema2.default("rgba(0,0,0,0.5)"),
3379
+ blur: z2.number().min(0).max(64).default(10),
3380
+ offsetX: z2.number().default(0),
3381
+ offsetY: z2.number().default(4)
3382
+ }).strict();
3352
3383
  var drawFontFamilySchema = z2.enum(["heading", "body", "mono"]);
3353
3384
  var drawRectSchema = z2.object({
3354
3385
  type: z2.literal("rect"),
@@ -3360,7 +3391,8 @@ var drawRectSchema = z2.object({
3360
3391
  stroke: colorHexSchema2.optional(),
3361
3392
  strokeWidth: z2.number().min(0).max(32).default(0),
3362
3393
  radius: z2.number().min(0).max(256).default(0),
3363
- opacity: z2.number().min(0).max(1).default(1)
3394
+ opacity: z2.number().min(0).max(1).default(1),
3395
+ shadow: drawShadowSchema.optional()
3364
3396
  }).strict();
3365
3397
  var drawCircleSchema = z2.object({
3366
3398
  type: z2.literal("circle"),
@@ -3370,7 +3402,8 @@ var drawCircleSchema = z2.object({
3370
3402
  fill: colorHexSchema2.optional(),
3371
3403
  stroke: colorHexSchema2.optional(),
3372
3404
  strokeWidth: z2.number().min(0).max(32).default(0),
3373
- opacity: z2.number().min(0).max(1).default(1)
3405
+ opacity: z2.number().min(0).max(1).default(1),
3406
+ shadow: drawShadowSchema.optional()
3374
3407
  }).strict();
3375
3408
  var drawTextSchema = z2.object({
3376
3409
  type: z2.literal("text"),
@@ -3385,7 +3418,8 @@ var drawTextSchema = z2.object({
3385
3418
  baseline: z2.enum(["top", "middle", "alphabetic", "bottom"]).default("alphabetic"),
3386
3419
  letterSpacing: z2.number().min(-10).max(50).default(0),
3387
3420
  maxWidth: z2.number().positive().optional(),
3388
- opacity: z2.number().min(0).max(1).default(1)
3421
+ opacity: z2.number().min(0).max(1).default(1),
3422
+ shadow: drawShadowSchema.optional()
3389
3423
  }).strict();
3390
3424
  var drawLineSchema = z2.object({
3391
3425
  type: z2.literal("line"),
@@ -3398,7 +3432,8 @@ var drawLineSchema = z2.object({
3398
3432
  dash: z2.array(z2.number()).max(6).optional(),
3399
3433
  arrow: z2.enum(["none", "end", "start", "both"]).default("none"),
3400
3434
  arrowSize: z2.number().min(4).max(32).default(10),
3401
- opacity: z2.number().min(0).max(1).default(1)
3435
+ opacity: z2.number().min(0).max(1).default(1),
3436
+ shadow: drawShadowSchema.optional()
3402
3437
  }).strict();
3403
3438
  var drawPointSchema = z2.object({
3404
3439
  x: z2.number(),
@@ -3412,7 +3447,8 @@ var drawBezierSchema = z2.object({
3412
3447
  dash: z2.array(z2.number()).max(6).optional(),
3413
3448
  arrow: z2.enum(["none", "end", "start", "both"]).default("none"),
3414
3449
  arrowSize: z2.number().min(4).max(32).default(10),
3415
- opacity: z2.number().min(0).max(1).default(1)
3450
+ opacity: z2.number().min(0).max(1).default(1),
3451
+ shadow: drawShadowSchema.optional()
3416
3452
  }).strict();
3417
3453
  var drawPathSchema = z2.object({
3418
3454
  type: z2.literal("path"),
@@ -3420,7 +3456,8 @@ var drawPathSchema = z2.object({
3420
3456
  fill: colorHexSchema2.optional(),
3421
3457
  stroke: colorHexSchema2.optional(),
3422
3458
  strokeWidth: z2.number().min(0).max(32).default(0),
3423
- opacity: z2.number().min(0).max(1).default(1)
3459
+ opacity: z2.number().min(0).max(1).default(1),
3460
+ shadow: drawShadowSchema.optional()
3424
3461
  }).strict();
3425
3462
  var drawBadgeSchema = z2.object({
3426
3463
  type: z2.literal("badge"),
@@ -3434,7 +3471,8 @@ var drawBadgeSchema = z2.object({
3434
3471
  paddingX: z2.number().min(0).max(64).default(10),
3435
3472
  paddingY: z2.number().min(0).max(32).default(4),
3436
3473
  borderRadius: z2.number().min(0).max(64).default(12),
3437
- opacity: z2.number().min(0).max(1).default(1)
3474
+ opacity: z2.number().min(0).max(1).default(1),
3475
+ shadow: drawShadowSchema.optional()
3438
3476
  }).strict();
3439
3477
  var drawGradientRectSchema = z2.object({
3440
3478
  type: z2.literal("gradient-rect"),
@@ -3444,7 +3482,8 @@ var drawGradientRectSchema = z2.object({
3444
3482
  height: z2.number().positive(),
3445
3483
  gradient: gradientSchema,
3446
3484
  radius: z2.number().min(0).max(256).default(0),
3447
- opacity: z2.number().min(0).max(1).default(1)
3485
+ opacity: z2.number().min(0).max(1).default(1),
3486
+ shadow: drawShadowSchema.optional()
3448
3487
  }).strict();
3449
3488
  var drawGridSchema = z2.object({
3450
3489
  type: z2.literal("grid"),