@shotstack/shotstack-canvas 1.5.4 → 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,50 +988,37 @@ 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",
998
+ x: bgX + bgInset,
999
+ y: bgY + bgInset,
1000
+ width: bgWidth - bgInset * 2,
1001
+ height: bgHeight - bgInset * 2,
1002
+ fill: { kind: "solid", color: p.background.color, opacity: p.background.opacity },
1003
+ borderRadius: bgFillRadius
1004
+ });
1005
+ }
1006
+ if (p.background.border && p.background.border.width > 0) {
1007
+ const borderRadius = p.background.border.borderRadius !== void 0 ? p.background.border.borderRadius : backgroundRadius;
1008
+ ops.push({
1009
+ op: "RectangleStroke",
991
1010
  x: bgX,
992
1011
  y: bgY,
993
1012
  width: bgWidth,
994
1013
  height: bgHeight,
995
- fill: { kind: "solid", color: p.background.color, opacity: p.background.opacity },
996
- borderRadius: p.background.borderRadius
1014
+ stroke: {
1015
+ width: p.background.border.width,
1016
+ color: p.background.border.color,
1017
+ opacity: p.background.border.opacity
1018
+ },
1019
+ borderRadius
997
1020
  });
998
1021
  }
999
- if (p.background.border && p.background.border.width > 0) {
1000
- const halfBorder = p.background.border.width / 2;
1001
- const borderRadius = p.background.borderRadius;
1002
- if (borderRadius <= halfBorder) {
1003
- ops.push({
1004
- op: "RectangleStroke",
1005
- x: bgX,
1006
- y: bgY,
1007
- width: bgWidth,
1008
- height: bgHeight,
1009
- stroke: {
1010
- width: p.background.border.width,
1011
- color: p.background.border.color,
1012
- opacity: p.background.border.opacity
1013
- },
1014
- borderRadius
1015
- });
1016
- } else {
1017
- ops.push({
1018
- op: "RectangleStroke",
1019
- x: bgX + halfBorder,
1020
- y: bgY + halfBorder,
1021
- width: bgWidth - p.background.border.width,
1022
- height: bgHeight - p.background.border.width,
1023
- stroke: {
1024
- width: p.background.border.width,
1025
- color: p.background.border.color,
1026
- opacity: p.background.border.opacity
1027
- },
1028
- borderRadius: borderRadius - halfBorder
1029
- });
1030
- }
1031
- }
1032
1022
  }
1033
1023
  ops.push(...textOps);
1034
1024
  return ops;
@@ -2083,11 +2073,13 @@ function computePathBounds2(d) {
2083
2073
  };
2084
2074
  }
2085
2075
  function roundRectPath(ctx, x, y, w, h, r) {
2086
- ctx.moveTo(x + r, y);
2087
- ctx.arcTo(x + w, y, x + w, y + h, r);
2088
- ctx.arcTo(x + w, y + h, x, y + h, r);
2089
- ctx.arcTo(x, y + h, x, y, r);
2090
- 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);
2091
2083
  ctx.closePath();
2092
2084
  }
2093
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,50 +949,37 @@ 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",
959
+ x: bgX + bgInset,
960
+ y: bgY + bgInset,
961
+ width: bgWidth - bgInset * 2,
962
+ height: bgHeight - bgInset * 2,
963
+ fill: { kind: "solid", color: p.background.color, opacity: p.background.opacity },
964
+ borderRadius: bgFillRadius
965
+ });
966
+ }
967
+ if (p.background.border && p.background.border.width > 0) {
968
+ const borderRadius = p.background.border.borderRadius !== void 0 ? p.background.border.borderRadius : backgroundRadius;
969
+ ops.push({
970
+ op: "RectangleStroke",
952
971
  x: bgX,
953
972
  y: bgY,
954
973
  width: bgWidth,
955
974
  height: bgHeight,
956
- fill: { kind: "solid", color: p.background.color, opacity: p.background.opacity },
957
- borderRadius: p.background.borderRadius
975
+ stroke: {
976
+ width: p.background.border.width,
977
+ color: p.background.border.color,
978
+ opacity: p.background.border.opacity
979
+ },
980
+ borderRadius
958
981
  });
959
982
  }
960
- if (p.background.border && p.background.border.width > 0) {
961
- const halfBorder = p.background.border.width / 2;
962
- const borderRadius = p.background.borderRadius;
963
- if (borderRadius <= halfBorder) {
964
- ops.push({
965
- op: "RectangleStroke",
966
- x: bgX,
967
- y: bgY,
968
- width: bgWidth,
969
- height: bgHeight,
970
- stroke: {
971
- width: p.background.border.width,
972
- color: p.background.border.color,
973
- opacity: p.background.border.opacity
974
- },
975
- borderRadius
976
- });
977
- } else {
978
- ops.push({
979
- op: "RectangleStroke",
980
- x: bgX + halfBorder,
981
- y: bgY + halfBorder,
982
- width: bgWidth - p.background.border.width,
983
- height: bgHeight - p.background.border.width,
984
- stroke: {
985
- width: p.background.border.width,
986
- color: p.background.border.color,
987
- opacity: p.background.border.opacity
988
- },
989
- borderRadius: borderRadius - halfBorder
990
- });
991
- }
992
- }
993
983
  }
994
984
  ops.push(...textOps);
995
985
  return ops;
@@ -2044,11 +2034,13 @@ function computePathBounds2(d) {
2044
2034
  };
2045
2035
  }
2046
2036
  function roundRectPath(ctx, x, y, w, h, r) {
2047
- ctx.moveTo(x + r, y);
2048
- ctx.arcTo(x + w, y, x + w, y + h, r);
2049
- ctx.arcTo(x + w, y + h, x, y + h, r);
2050
- ctx.arcTo(x, y + h, x, y, r);
2051
- 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);
2052
2044
  ctx.closePath();
2053
2045
  }
2054
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,50 +954,37 @@ 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",
964
+ x: bgX + bgInset,
965
+ y: bgY + bgInset,
966
+ width: bgWidth - bgInset * 2,
967
+ height: bgHeight - bgInset * 2,
968
+ fill: { kind: "solid", color: p.background.color, opacity: p.background.opacity },
969
+ borderRadius: bgFillRadius
970
+ });
971
+ }
972
+ if (p.background.border && p.background.border.width > 0) {
973
+ const borderRadius = p.background.border.borderRadius !== void 0 ? p.background.border.borderRadius : backgroundRadius;
974
+ ops.push({
975
+ op: "RectangleStroke",
957
976
  x: bgX,
958
977
  y: bgY,
959
978
  width: bgWidth,
960
979
  height: bgHeight,
961
- fill: { kind: "solid", color: p.background.color, opacity: p.background.opacity },
962
- borderRadius: p.background.borderRadius
980
+ stroke: {
981
+ width: p.background.border.width,
982
+ color: p.background.border.color,
983
+ opacity: p.background.border.opacity
984
+ },
985
+ borderRadius
963
986
  });
964
987
  }
965
- if (p.background.border && p.background.border.width > 0) {
966
- const halfBorder = p.background.border.width / 2;
967
- const borderRadius = p.background.borderRadius;
968
- if (borderRadius <= halfBorder) {
969
- ops.push({
970
- op: "RectangleStroke",
971
- x: bgX,
972
- y: bgY,
973
- width: bgWidth,
974
- height: bgHeight,
975
- stroke: {
976
- width: p.background.border.width,
977
- color: p.background.border.color,
978
- opacity: p.background.border.opacity
979
- },
980
- borderRadius
981
- });
982
- } else {
983
- ops.push({
984
- op: "RectangleStroke",
985
- x: bgX + halfBorder,
986
- y: bgY + halfBorder,
987
- width: bgWidth - p.background.border.width,
988
- height: bgHeight - p.background.border.width,
989
- stroke: {
990
- width: p.background.border.width,
991
- color: p.background.border.color,
992
- opacity: p.background.border.opacity
993
- },
994
- borderRadius: borderRadius - halfBorder
995
- });
996
- }
997
- }
998
988
  }
999
989
  ops.push(...textOps);
1000
990
  return ops;
@@ -1778,11 +1768,12 @@ function createWebPainter(canvas) {
1778
1768
  ctx.lineWidth = op.stroke.width;
1779
1769
  if (op.borderRadius && op.borderRadius > 0) {
1780
1770
  const p = new Path2D();
1781
- const r = op.borderRadius;
1782
1771
  const x = op.x;
1783
1772
  const y = op.y;
1784
1773
  const w = op.width;
1785
1774
  const h = op.height;
1775
+ const maxRadius = Math.min(w, h) / 2;
1776
+ const r = Math.min(op.borderRadius, maxRadius);
1786
1777
  p.moveTo(x + r, y);
1787
1778
  p.arcTo(x + w, y, x + w, y + h, r);
1788
1779
  p.arcTo(x + w, y + h, x, y + h, r);
@@ -1801,12 +1792,14 @@ function createWebPainter(canvas) {
1801
1792
  };
1802
1793
  }
1803
1794
  function drawRoundedRect(ctx, x, y, w, h, r) {
1795
+ const maxRadius = Math.min(w, h) / 2;
1796
+ const radius = Math.min(r, maxRadius);
1804
1797
  const p = new Path2D();
1805
- p.moveTo(x + r, y);
1806
- p.arcTo(x + w, y, x + w, y + h, r);
1807
- p.arcTo(x + w, y + h, x, y + h, r);
1808
- p.arcTo(x, y + h, x, y, r);
1809
- 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);
1810
1803
  p.closePath();
1811
1804
  ctx.save();
1812
1805
  ctx.fill(p);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shotstack/shotstack-canvas",
3
- "version": "1.5.4",
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",