@shotstack/shotstack-canvas 1.5.3 → 1.5.5

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.
@@ -135,12 +135,15 @@ var animationSchema = import_joi.default.object({
135
135
  var borderSchema = import_joi.default.object({
136
136
  width: import_joi.default.number().min(0).default(0),
137
137
  color: import_joi.default.string().pattern(HEX6).default("#000000"),
138
- opacity: import_joi.default.number().min(0).max(1).default(1)
138
+ opacity: import_joi.default.number().min(0).max(1).default(1),
139
+ borderRadius: import_joi.default.number().min(0).optional()
139
140
  }).unknown(false);
140
141
  var backgroundSchema = import_joi.default.object({
141
142
  color: import_joi.default.string().pattern(HEX6).optional(),
142
143
  opacity: import_joi.default.number().min(0).max(1).default(1),
143
- borderRadius: import_joi.default.number().min(0).default(0),
144
+ backgroundRadius: import_joi.default.number().min(0).default(0),
145
+ borderRadius: import_joi.default.number().min(0).optional(),
146
+ // Deprecated: use backgroundRadius
144
147
  border: borderSchema.optional()
145
148
  }).unknown(false);
146
149
  var paddingSchema = import_joi.default.alternatives().try(
@@ -985,31 +988,35 @@ async function buildDrawOps(p) {
985
988
  const bgY = 0;
986
989
  const bgWidth = p.canvas.width;
987
990
  const bgHeight = p.canvas.height;
991
+ const backgroundRadius = p.background.backgroundRadius ?? p.background.borderRadius ?? 0;
992
+ const halfBorder = p.background.border?.width ? p.background.border.width / 2 : 0;
988
993
  if (p.background.color) {
994
+ const bgInset = halfBorder;
995
+ const bgFillRadius = Math.max(0, backgroundRadius - bgInset);
989
996
  ops.push({
990
997
  op: "Rectangle",
991
- x: bgX,
992
- y: bgY,
993
- width: bgWidth,
994
- height: bgHeight,
998
+ x: bgX + bgInset,
999
+ y: bgY + bgInset,
1000
+ width: bgWidth - bgInset * 2,
1001
+ height: bgHeight - bgInset * 2,
995
1002
  fill: { kind: "solid", color: p.background.color, opacity: p.background.opacity },
996
- borderRadius: p.background.borderRadius
1003
+ borderRadius: bgFillRadius
997
1004
  });
998
1005
  }
999
1006
  if (p.background.border && p.background.border.width > 0) {
1000
- const halfBorder = p.background.border.width / 2;
1007
+ const borderRadius = p.background.border.borderRadius !== void 0 ? p.background.border.borderRadius : backgroundRadius;
1001
1008
  ops.push({
1002
1009
  op: "RectangleStroke",
1003
- x: bgX + halfBorder,
1004
- y: bgY + halfBorder,
1005
- width: bgWidth - p.background.border.width,
1006
- height: bgHeight - p.background.border.width,
1010
+ x: bgX,
1011
+ y: bgY,
1012
+ width: bgWidth,
1013
+ height: bgHeight,
1007
1014
  stroke: {
1008
1015
  width: p.background.border.width,
1009
1016
  color: p.background.border.color,
1010
1017
  opacity: p.background.border.opacity
1011
1018
  },
1012
- borderRadius: Math.max(0, p.background.borderRadius - halfBorder)
1019
+ borderRadius
1013
1020
  });
1014
1021
  }
1015
1022
  }
@@ -2066,11 +2073,13 @@ function computePathBounds2(d) {
2066
2073
  };
2067
2074
  }
2068
2075
  function roundRectPath(ctx, x, y, w, h, r) {
2069
- ctx.moveTo(x + r, y);
2070
- ctx.arcTo(x + w, y, x + w, y + h, r);
2071
- ctx.arcTo(x + w, y + h, x, y + h, r);
2072
- ctx.arcTo(x, y + h, x, y, r);
2073
- ctx.arcTo(x, y, x + w, y, r);
2076
+ const maxRadius = Math.min(w, h) / 2;
2077
+ const radius = Math.min(r, maxRadius);
2078
+ ctx.moveTo(x + radius, y);
2079
+ ctx.arcTo(x + w, y, x + w, y + h, radius);
2080
+ ctx.arcTo(x + w, y + h, x, y + h, radius);
2081
+ ctx.arcTo(x, y + h, x, y, radius);
2082
+ ctx.arcTo(x, y, x + w, y, radius);
2074
2083
  ctx.closePath();
2075
2084
  }
2076
2085
  function tokenizePath2(d) {
@@ -63,11 +63,13 @@ type RichTextValidated = Required<{
63
63
  background?: {
64
64
  color?: string;
65
65
  opacity: number;
66
- borderRadius: number;
66
+ backgroundRadius: number;
67
+ borderRadius?: number;
67
68
  border?: {
68
69
  width: number;
69
70
  color: string;
70
71
  opacity: number;
72
+ borderRadius?: number;
71
73
  };
72
74
  };
73
75
  padding?: number | {
@@ -63,11 +63,13 @@ type RichTextValidated = Required<{
63
63
  background?: {
64
64
  color?: string;
65
65
  opacity: number;
66
- borderRadius: number;
66
+ backgroundRadius: number;
67
+ borderRadius?: number;
67
68
  border?: {
68
69
  width: number;
69
70
  color: string;
70
71
  opacity: number;
72
+ borderRadius?: number;
71
73
  };
72
74
  };
73
75
  padding?: number | {
@@ -97,12 +97,15 @@ var animationSchema = Joi.object({
97
97
  var borderSchema = Joi.object({
98
98
  width: Joi.number().min(0).default(0),
99
99
  color: Joi.string().pattern(HEX6).default("#000000"),
100
- opacity: Joi.number().min(0).max(1).default(1)
100
+ opacity: Joi.number().min(0).max(1).default(1),
101
+ borderRadius: Joi.number().min(0).optional()
101
102
  }).unknown(false);
102
103
  var backgroundSchema = Joi.object({
103
104
  color: Joi.string().pattern(HEX6).optional(),
104
105
  opacity: Joi.number().min(0).max(1).default(1),
105
- borderRadius: Joi.number().min(0).default(0),
106
+ backgroundRadius: Joi.number().min(0).default(0),
107
+ borderRadius: Joi.number().min(0).optional(),
108
+ // Deprecated: use backgroundRadius
106
109
  border: borderSchema.optional()
107
110
  }).unknown(false);
108
111
  var paddingSchema = Joi.alternatives().try(
@@ -946,31 +949,35 @@ async function buildDrawOps(p) {
946
949
  const bgY = 0;
947
950
  const bgWidth = p.canvas.width;
948
951
  const bgHeight = p.canvas.height;
952
+ const backgroundRadius = p.background.backgroundRadius ?? p.background.borderRadius ?? 0;
953
+ const halfBorder = p.background.border?.width ? p.background.border.width / 2 : 0;
949
954
  if (p.background.color) {
955
+ const bgInset = halfBorder;
956
+ const bgFillRadius = Math.max(0, backgroundRadius - bgInset);
950
957
  ops.push({
951
958
  op: "Rectangle",
952
- x: bgX,
953
- y: bgY,
954
- width: bgWidth,
955
- height: bgHeight,
959
+ x: bgX + bgInset,
960
+ y: bgY + bgInset,
961
+ width: bgWidth - bgInset * 2,
962
+ height: bgHeight - bgInset * 2,
956
963
  fill: { kind: "solid", color: p.background.color, opacity: p.background.opacity },
957
- borderRadius: p.background.borderRadius
964
+ borderRadius: bgFillRadius
958
965
  });
959
966
  }
960
967
  if (p.background.border && p.background.border.width > 0) {
961
- const halfBorder = p.background.border.width / 2;
968
+ const borderRadius = p.background.border.borderRadius !== void 0 ? p.background.border.borderRadius : backgroundRadius;
962
969
  ops.push({
963
970
  op: "RectangleStroke",
964
- x: bgX + halfBorder,
965
- y: bgY + halfBorder,
966
- width: bgWidth - p.background.border.width,
967
- height: bgHeight - p.background.border.width,
971
+ x: bgX,
972
+ y: bgY,
973
+ width: bgWidth,
974
+ height: bgHeight,
968
975
  stroke: {
969
976
  width: p.background.border.width,
970
977
  color: p.background.border.color,
971
978
  opacity: p.background.border.opacity
972
979
  },
973
- borderRadius: Math.max(0, p.background.borderRadius - halfBorder)
980
+ borderRadius
974
981
  });
975
982
  }
976
983
  }
@@ -2027,11 +2034,13 @@ function computePathBounds2(d) {
2027
2034
  };
2028
2035
  }
2029
2036
  function roundRectPath(ctx, x, y, w, h, r) {
2030
- ctx.moveTo(x + r, y);
2031
- ctx.arcTo(x + w, y, x + w, y + h, r);
2032
- ctx.arcTo(x + w, y + h, x, y + h, r);
2033
- ctx.arcTo(x, y + h, x, y, r);
2034
- ctx.arcTo(x, y, x + w, y, r);
2037
+ const maxRadius = Math.min(w, h) / 2;
2038
+ const radius = Math.min(r, maxRadius);
2039
+ ctx.moveTo(x + radius, y);
2040
+ ctx.arcTo(x + w, y, x + w, y + h, radius);
2041
+ ctx.arcTo(x + w, y + h, x, y + h, radius);
2042
+ ctx.arcTo(x, y + h, x, y, radius);
2043
+ ctx.arcTo(x, y, x + w, y, radius);
2035
2044
  ctx.closePath();
2036
2045
  }
2037
2046
  function tokenizePath2(d) {
@@ -63,11 +63,13 @@ type RichTextValidated = Required<{
63
63
  background?: {
64
64
  color?: string;
65
65
  opacity: number;
66
- borderRadius: number;
66
+ backgroundRadius: number;
67
+ borderRadius?: number;
67
68
  border?: {
68
69
  width: number;
69
70
  color: string;
70
71
  opacity: number;
72
+ borderRadius?: number;
71
73
  };
72
74
  };
73
75
  padding?: number | {
package/dist/entry.web.js CHANGED
@@ -101,12 +101,15 @@ var animationSchema = Joi.object({
101
101
  var borderSchema = Joi.object({
102
102
  width: Joi.number().min(0).default(0),
103
103
  color: Joi.string().pattern(HEX6).default("#000000"),
104
- opacity: Joi.number().min(0).max(1).default(1)
104
+ opacity: Joi.number().min(0).max(1).default(1),
105
+ borderRadius: Joi.number().min(0).optional()
105
106
  }).unknown(false);
106
107
  var backgroundSchema = Joi.object({
107
108
  color: Joi.string().pattern(HEX6).optional(),
108
109
  opacity: Joi.number().min(0).max(1).default(1),
109
- borderRadius: Joi.number().min(0).default(0),
110
+ backgroundRadius: Joi.number().min(0).default(0),
111
+ borderRadius: Joi.number().min(0).optional(),
112
+ // Deprecated: use backgroundRadius
110
113
  border: borderSchema.optional()
111
114
  }).unknown(false);
112
115
  var paddingSchema = Joi.alternatives().try(
@@ -951,31 +954,35 @@ async function buildDrawOps(p) {
951
954
  const bgY = 0;
952
955
  const bgWidth = p.canvas.width;
953
956
  const bgHeight = p.canvas.height;
957
+ const backgroundRadius = p.background.backgroundRadius ?? p.background.borderRadius ?? 0;
958
+ const halfBorder = p.background.border?.width ? p.background.border.width / 2 : 0;
954
959
  if (p.background.color) {
960
+ const bgInset = halfBorder;
961
+ const bgFillRadius = Math.max(0, backgroundRadius - bgInset);
955
962
  ops.push({
956
963
  op: "Rectangle",
957
- x: bgX,
958
- y: bgY,
959
- width: bgWidth,
960
- height: bgHeight,
964
+ x: bgX + bgInset,
965
+ y: bgY + bgInset,
966
+ width: bgWidth - bgInset * 2,
967
+ height: bgHeight - bgInset * 2,
961
968
  fill: { kind: "solid", color: p.background.color, opacity: p.background.opacity },
962
- borderRadius: p.background.borderRadius
969
+ borderRadius: bgFillRadius
963
970
  });
964
971
  }
965
972
  if (p.background.border && p.background.border.width > 0) {
966
- const halfBorder = p.background.border.width / 2;
973
+ const borderRadius = p.background.border.borderRadius !== void 0 ? p.background.border.borderRadius : backgroundRadius;
967
974
  ops.push({
968
975
  op: "RectangleStroke",
969
- x: bgX + halfBorder,
970
- y: bgY + halfBorder,
971
- width: bgWidth - p.background.border.width,
972
- height: bgHeight - p.background.border.width,
976
+ x: bgX,
977
+ y: bgY,
978
+ width: bgWidth,
979
+ height: bgHeight,
973
980
  stroke: {
974
981
  width: p.background.border.width,
975
982
  color: p.background.border.color,
976
983
  opacity: p.background.border.opacity
977
984
  },
978
- borderRadius: Math.max(0, p.background.borderRadius - halfBorder)
985
+ borderRadius
979
986
  });
980
987
  }
981
988
  }
@@ -1761,11 +1768,12 @@ function createWebPainter(canvas) {
1761
1768
  ctx.lineWidth = op.stroke.width;
1762
1769
  if (op.borderRadius && op.borderRadius > 0) {
1763
1770
  const p = new Path2D();
1764
- const r = op.borderRadius;
1765
1771
  const x = op.x;
1766
1772
  const y = op.y;
1767
1773
  const w = op.width;
1768
1774
  const h = op.height;
1775
+ const maxRadius = Math.min(w, h) / 2;
1776
+ const r = Math.min(op.borderRadius, maxRadius);
1769
1777
  p.moveTo(x + r, y);
1770
1778
  p.arcTo(x + w, y, x + w, y + h, r);
1771
1779
  p.arcTo(x + w, y + h, x, y + h, r);
@@ -1784,12 +1792,14 @@ function createWebPainter(canvas) {
1784
1792
  };
1785
1793
  }
1786
1794
  function drawRoundedRect(ctx, x, y, w, h, r) {
1795
+ const maxRadius = Math.min(w, h) / 2;
1796
+ const radius = Math.min(r, maxRadius);
1787
1797
  const p = new Path2D();
1788
- p.moveTo(x + r, y);
1789
- p.arcTo(x + w, y, x + w, y + h, r);
1790
- p.arcTo(x + w, y + h, x, y + h, r);
1791
- p.arcTo(x, y + h, x, y, r);
1792
- p.arcTo(x, y, x + w, y, r);
1798
+ p.moveTo(x + radius, y);
1799
+ p.arcTo(x + w, y, x + w, y + h, radius);
1800
+ p.arcTo(x + w, y + h, x, y + h, radius);
1801
+ p.arcTo(x, y + h, x, y, radius);
1802
+ p.arcTo(x, y, x + w, y, radius);
1793
1803
  p.closePath();
1794
1804
  ctx.save();
1795
1805
  ctx.fill(p);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shotstack/shotstack-canvas",
3
- "version": "1.5.3",
3
+ "version": "1.5.5",
4
4
  "description": "Text layout & animation engine (HarfBuzz) for Node & Web - fully self-contained.",
5
5
  "type": "module",
6
6
  "main": "./dist/entry.node.cjs",