@shotstack/shotstack-canvas 2.0.9 → 2.0.11

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.
@@ -263,7 +263,7 @@ declare const richCaptionAssetSchema: z.ZodObject<{
263
263
  start: z.ZodNumber;
264
264
  end: z.ZodNumber;
265
265
  confidence: z.ZodOptional<z.ZodNumber>;
266
- }, z.core.$strict>>>;
266
+ }, z.core.$strip>>>;
267
267
  font: z.ZodOptional<z.ZodObject<{
268
268
  family: z.ZodDefault<z.ZodString>;
269
269
  size: z.ZodDefault<z.ZodNumber>;
@@ -316,6 +316,12 @@ declare const richCaptionAssetSchema: z.ZodObject<{
316
316
  color: z.ZodOptional<z.ZodString>;
317
317
  opacity: z.ZodDefault<z.ZodNumber>;
318
318
  }, z.core.$strict>>;
319
+ border: z.ZodOptional<z.ZodObject<{
320
+ width: z.ZodDefault<z.ZodNumber>;
321
+ color: z.ZodDefault<z.ZodString>;
322
+ opacity: z.ZodDefault<z.ZodNumber>;
323
+ radius: z.ZodDefault<z.ZodNumber>;
324
+ }, z.core.$strip>>;
319
325
  padding: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
320
326
  top: z.ZodDefault<z.ZodNumber>;
321
327
  right: z.ZodDefault<z.ZodNumber>;
@@ -366,13 +372,6 @@ declare const richCaptionAssetSchema: z.ZodObject<{
366
372
  down: "down";
367
373
  }>>;
368
374
  }, z.core.$strict>>;
369
- position: z.ZodDefault<z.ZodEnum<{
370
- center: "center";
371
- top: "top";
372
- bottom: "bottom";
373
- }>>;
374
- maxWidth: z.ZodDefault<z.ZodNumber>;
375
- maxLines: z.ZodDefault<z.ZodNumber>;
376
375
  customFonts: z.ZodOptional<z.ZodArray<z.ZodObject<{
377
376
  src: z.ZodString;
378
377
  family: z.ZodString;
@@ -389,7 +388,7 @@ declare const CanvasRichCaptionAssetSchema: z.ZodObject<{
389
388
  start: z.ZodNumber;
390
389
  end: z.ZodNumber;
391
390
  confidence: z.ZodOptional<z.ZodNumber>;
392
- }, z.core.$strict>>>;
391
+ }, z.core.$strip>>>;
393
392
  font: z.ZodOptional<z.ZodObject<{
394
393
  family: z.ZodDefault<z.ZodString>;
395
394
  size: z.ZodDefault<z.ZodNumber>;
@@ -442,6 +441,12 @@ declare const CanvasRichCaptionAssetSchema: z.ZodObject<{
442
441
  color: z.ZodOptional<z.ZodString>;
443
442
  opacity: z.ZodDefault<z.ZodNumber>;
444
443
  }, z.core.$strict>>;
444
+ border: z.ZodOptional<z.ZodObject<{
445
+ width: z.ZodDefault<z.ZodNumber>;
446
+ color: z.ZodDefault<z.ZodString>;
447
+ opacity: z.ZodDefault<z.ZodNumber>;
448
+ radius: z.ZodDefault<z.ZodNumber>;
449
+ }, z.core.$strip>>;
445
450
  padding: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
446
451
  top: z.ZodDefault<z.ZodNumber>;
447
452
  right: z.ZodDefault<z.ZodNumber>;
@@ -492,13 +497,6 @@ declare const CanvasRichCaptionAssetSchema: z.ZodObject<{
492
497
  down: "down";
493
498
  }>>;
494
499
  }, z.core.$strict>>;
495
- position: z.ZodDefault<z.ZodEnum<{
496
- center: "center";
497
- top: "top";
498
- bottom: "bottom";
499
- }>>;
500
- maxWidth: z.ZodDefault<z.ZodNumber>;
501
- maxLines: z.ZodDefault<z.ZodNumber>;
502
500
  customFonts: z.ZodOptional<z.ZodArray<z.ZodObject<{
503
501
  src: z.ZodString;
504
502
  family: z.ZodString;
@@ -603,9 +601,11 @@ interface WordTiming {
603
601
  interface CaptionLayoutConfig {
604
602
  frameWidth: number;
605
603
  frameHeight: number;
606
- maxWidth: number;
604
+ availableWidth: number;
607
605
  maxLines: number;
608
- position: "top" | "center" | "bottom";
606
+ verticalAlign: "top" | "middle" | "bottom";
607
+ horizontalAlign: "left" | "center" | "right";
608
+ paddingLeft: number;
609
609
  fontSize: number;
610
610
  fontFamily: string;
611
611
  fontWeight: string | number;
@@ -1060,6 +1060,11 @@ declare function renderSvgAssetToPng(asset: CanvasSvgAsset, options?: {
1060
1060
  background?: string;
1061
1061
  }): Promise<ResvgRenderResult>;
1062
1062
 
1063
+ declare const ASCENT_RATIO = 0.8;
1064
+ declare const DESCENT_RATIO = 0.2;
1065
+ declare const WORD_BG_OPACITY = 1;
1066
+ declare const WORD_BG_BORDER_RADIUS = 4;
1067
+ declare const WORD_BG_PADDING_RATIO = 0.12;
1063
1068
  interface RichCaptionGeneratorConfig {
1064
1069
  frameWidth: number;
1065
1070
  frameHeight: number;
@@ -1093,7 +1098,13 @@ interface BackgroundConfig {
1093
1098
  borderRadius: number;
1094
1099
  padding: number;
1095
1100
  }
1096
- declare function generateRichCaptionDrawOps(asset: CanvasRichCaptionAsset, layout: CaptionLayout, frameTimeMs: number, layoutEngine: CaptionLayoutEngine, _config: RichCaptionGeneratorConfig): DrawOp[];
1101
+ declare function extractCaptionPadding(asset: CanvasRichCaptionAsset): {
1102
+ top: number;
1103
+ right: number;
1104
+ bottom: number;
1105
+ left: number;
1106
+ };
1107
+ declare function generateRichCaptionDrawOps(asset: CanvasRichCaptionAsset, layout: CaptionLayout, frameTimeMs: number, layoutEngine: CaptionLayoutEngine, config: RichCaptionGeneratorConfig): DrawOp[];
1097
1108
  declare function generateRichCaptionFrame(asset: CanvasRichCaptionAsset, layout: CaptionLayout, frameTimeMs: number, layoutEngine: CaptionLayoutEngine, config: RichCaptionGeneratorConfig): {
1098
1109
  ops: DrawOp[];
1099
1110
  visibleWordCount: number;
@@ -1184,6 +1195,8 @@ declare class RichCaptionRenderer {
1184
1195
  getStats(): RenderStats;
1185
1196
  resetStats(): void;
1186
1197
  clearCache(): void;
1198
+ private mapVerticalAlign;
1199
+ private mapHorizontalAlign;
1187
1200
  private extractAnimationStyle;
1188
1201
  private extractAnimationSpeed;
1189
1202
  private logProgress;
@@ -1316,4 +1329,4 @@ declare function createTextEngine(opts?: {
1316
1329
  destroy(): void;
1317
1330
  }>;
1318
1331
 
1319
- export { type AnimationDirection, type AnimationStyle, type ArcCommand, type BackgroundConfig, type BoundingBox, type CanvasRichCaptionAsset, CanvasRichCaptionAssetSchema, type CanvasRichTextAsset, CanvasRichTextAssetSchema, type CanvasSvgAsset, CanvasSvgAssetSchema, type CaptionGroup, type CaptionLayout, type CaptionLayoutConfig, CaptionLayoutEngine, type CaptionLine, type ClosePathCommand, type CubicBezierCommand, type DrawOp, type EngineInit, type FastVideoOptions, type FastVideoResult, type FontConfig, FontRegistry, type FrameSchedule, type Glyph, type GradientSpec, type IVideoEncoder, type LineToCommand, type MoveToCommand, NodeRawEncoder, type NormalizedPathCommand, type ParsedPathCommand, type PathCommandType, type Point2D, type PositionedWord, type QuadraticBezierCommand, type RGBA, type RenderFrame, type RenderStats, type Renderer, type ResvgRenderOptions, type ResvgRenderResult, type RichCaptionGeneratorConfig, RichCaptionRenderer, type RichCaptionRendererOptions, type ShadowConfig, type ShapedLine, type ShapedWord, type ShapedWordGlyph, type ShotstackRichTextAsset, type ShotstackSvgAsset, type StrokeConfig, type StrokeSpec, type ValidAsset, type VideoEncoderCapabilities, type VideoEncoderConfig, type VideoEncoderProgress, type WordAnimationConfig, type WordAnimationState, type WordTiming, WordTimingStore, arcToCubicBeziers, breakIntoLines, calculateAnimationStatesForGroup, commandsToPathString, computeSimplePathBounds, createDefaultGeneratorConfig, createFrameSchedule, createNodePainter, createNodeRawEncoder, createRichCaptionRenderer, createTextEngine, createVideoEncoder, detectPlatform, detectSubtitleFormat, findWordAtTime, generateRichCaptionDrawOps, generateRichCaptionFrame, generateShapePathData, getDefaultAnimationConfig, getDrawCaptionWordOps, getEncoderCapabilities, getEncoderWarning, groupWordsByPause, isDrawCaptionWordOp, isRTLText, isWebCodecsH264Supported, normalizePath, normalizePathString, parseSubtitleToWords, parseSvgPath, quadraticToCubic, renderSvgAssetToPng, renderSvgToPng, richCaptionAssetSchema, shapeToSvgString };
1332
+ export { ASCENT_RATIO, type AnimationDirection, type AnimationStyle, type ArcCommand, type BackgroundConfig, type BoundingBox, type CanvasRichCaptionAsset, CanvasRichCaptionAssetSchema, type CanvasRichTextAsset, CanvasRichTextAssetSchema, type CanvasSvgAsset, CanvasSvgAssetSchema, type CaptionGroup, type CaptionLayout, type CaptionLayoutConfig, CaptionLayoutEngine, type CaptionLine, type ClosePathCommand, type CubicBezierCommand, DESCENT_RATIO, type DrawOp, type EngineInit, type FastVideoOptions, type FastVideoResult, type FontConfig, FontRegistry, type FrameSchedule, type Glyph, type GradientSpec, type IVideoEncoder, type LineToCommand, type MoveToCommand, NodeRawEncoder, type NormalizedPathCommand, type ParsedPathCommand, type PathCommandType, type Point2D, type PositionedWord, type QuadraticBezierCommand, type RGBA, type RenderFrame, type RenderStats, type Renderer, type ResvgRenderOptions, type ResvgRenderResult, type RichCaptionGeneratorConfig, RichCaptionRenderer, type RichCaptionRendererOptions, type ShadowConfig, type ShapedLine, type ShapedWord, type ShapedWordGlyph, type ShotstackRichTextAsset, type ShotstackSvgAsset, type StrokeConfig, type StrokeSpec, type ValidAsset, type VideoEncoderCapabilities, type VideoEncoderConfig, type VideoEncoderProgress, WORD_BG_BORDER_RADIUS, WORD_BG_OPACITY, WORD_BG_PADDING_RATIO, type WordAnimationConfig, type WordAnimationState, type WordTiming, WordTimingStore, arcToCubicBeziers, breakIntoLines, calculateAnimationStatesForGroup, commandsToPathString, computeSimplePathBounds, createDefaultGeneratorConfig, createFrameSchedule, createNodePainter, createNodeRawEncoder, createRichCaptionRenderer, createTextEngine, createVideoEncoder, detectPlatform, detectSubtitleFormat, extractCaptionPadding, findWordAtTime, generateRichCaptionDrawOps, generateRichCaptionFrame, generateShapePathData, getDefaultAnimationConfig, getDrawCaptionWordOps, getEncoderCapabilities, getEncoderWarning, groupWordsByPause, isDrawCaptionWordOp, isRTLText, isWebCodecsH264Supported, normalizePath, normalizePathString, parseSubtitleToWords, parseSvgPath, quadraticToCubic, renderSvgAssetToPng, renderSvgToPng, richCaptionAssetSchema, shapeToSvgString };
@@ -263,7 +263,7 @@ declare const richCaptionAssetSchema: z.ZodObject<{
263
263
  start: z.ZodNumber;
264
264
  end: z.ZodNumber;
265
265
  confidence: z.ZodOptional<z.ZodNumber>;
266
- }, z.core.$strict>>>;
266
+ }, z.core.$strip>>>;
267
267
  font: z.ZodOptional<z.ZodObject<{
268
268
  family: z.ZodDefault<z.ZodString>;
269
269
  size: z.ZodDefault<z.ZodNumber>;
@@ -316,6 +316,12 @@ declare const richCaptionAssetSchema: z.ZodObject<{
316
316
  color: z.ZodOptional<z.ZodString>;
317
317
  opacity: z.ZodDefault<z.ZodNumber>;
318
318
  }, z.core.$strict>>;
319
+ border: z.ZodOptional<z.ZodObject<{
320
+ width: z.ZodDefault<z.ZodNumber>;
321
+ color: z.ZodDefault<z.ZodString>;
322
+ opacity: z.ZodDefault<z.ZodNumber>;
323
+ radius: z.ZodDefault<z.ZodNumber>;
324
+ }, z.core.$strip>>;
319
325
  padding: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
320
326
  top: z.ZodDefault<z.ZodNumber>;
321
327
  right: z.ZodDefault<z.ZodNumber>;
@@ -366,13 +372,6 @@ declare const richCaptionAssetSchema: z.ZodObject<{
366
372
  down: "down";
367
373
  }>>;
368
374
  }, z.core.$strict>>;
369
- position: z.ZodDefault<z.ZodEnum<{
370
- center: "center";
371
- top: "top";
372
- bottom: "bottom";
373
- }>>;
374
- maxWidth: z.ZodDefault<z.ZodNumber>;
375
- maxLines: z.ZodDefault<z.ZodNumber>;
376
375
  customFonts: z.ZodOptional<z.ZodArray<z.ZodObject<{
377
376
  src: z.ZodString;
378
377
  family: z.ZodString;
@@ -389,7 +388,7 @@ declare const CanvasRichCaptionAssetSchema: z.ZodObject<{
389
388
  start: z.ZodNumber;
390
389
  end: z.ZodNumber;
391
390
  confidence: z.ZodOptional<z.ZodNumber>;
392
- }, z.core.$strict>>>;
391
+ }, z.core.$strip>>>;
393
392
  font: z.ZodOptional<z.ZodObject<{
394
393
  family: z.ZodDefault<z.ZodString>;
395
394
  size: z.ZodDefault<z.ZodNumber>;
@@ -442,6 +441,12 @@ declare const CanvasRichCaptionAssetSchema: z.ZodObject<{
442
441
  color: z.ZodOptional<z.ZodString>;
443
442
  opacity: z.ZodDefault<z.ZodNumber>;
444
443
  }, z.core.$strict>>;
444
+ border: z.ZodOptional<z.ZodObject<{
445
+ width: z.ZodDefault<z.ZodNumber>;
446
+ color: z.ZodDefault<z.ZodString>;
447
+ opacity: z.ZodDefault<z.ZodNumber>;
448
+ radius: z.ZodDefault<z.ZodNumber>;
449
+ }, z.core.$strip>>;
445
450
  padding: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
446
451
  top: z.ZodDefault<z.ZodNumber>;
447
452
  right: z.ZodDefault<z.ZodNumber>;
@@ -492,13 +497,6 @@ declare const CanvasRichCaptionAssetSchema: z.ZodObject<{
492
497
  down: "down";
493
498
  }>>;
494
499
  }, z.core.$strict>>;
495
- position: z.ZodDefault<z.ZodEnum<{
496
- center: "center";
497
- top: "top";
498
- bottom: "bottom";
499
- }>>;
500
- maxWidth: z.ZodDefault<z.ZodNumber>;
501
- maxLines: z.ZodDefault<z.ZodNumber>;
502
500
  customFonts: z.ZodOptional<z.ZodArray<z.ZodObject<{
503
501
  src: z.ZodString;
504
502
  family: z.ZodString;
@@ -603,9 +601,11 @@ interface WordTiming {
603
601
  interface CaptionLayoutConfig {
604
602
  frameWidth: number;
605
603
  frameHeight: number;
606
- maxWidth: number;
604
+ availableWidth: number;
607
605
  maxLines: number;
608
- position: "top" | "center" | "bottom";
606
+ verticalAlign: "top" | "middle" | "bottom";
607
+ horizontalAlign: "left" | "center" | "right";
608
+ paddingLeft: number;
609
609
  fontSize: number;
610
610
  fontFamily: string;
611
611
  fontWeight: string | number;
@@ -1060,6 +1060,11 @@ declare function renderSvgAssetToPng(asset: CanvasSvgAsset, options?: {
1060
1060
  background?: string;
1061
1061
  }): Promise<ResvgRenderResult>;
1062
1062
 
1063
+ declare const ASCENT_RATIO = 0.8;
1064
+ declare const DESCENT_RATIO = 0.2;
1065
+ declare const WORD_BG_OPACITY = 1;
1066
+ declare const WORD_BG_BORDER_RADIUS = 4;
1067
+ declare const WORD_BG_PADDING_RATIO = 0.12;
1063
1068
  interface RichCaptionGeneratorConfig {
1064
1069
  frameWidth: number;
1065
1070
  frameHeight: number;
@@ -1093,7 +1098,13 @@ interface BackgroundConfig {
1093
1098
  borderRadius: number;
1094
1099
  padding: number;
1095
1100
  }
1096
- declare function generateRichCaptionDrawOps(asset: CanvasRichCaptionAsset, layout: CaptionLayout, frameTimeMs: number, layoutEngine: CaptionLayoutEngine, _config: RichCaptionGeneratorConfig): DrawOp[];
1101
+ declare function extractCaptionPadding(asset: CanvasRichCaptionAsset): {
1102
+ top: number;
1103
+ right: number;
1104
+ bottom: number;
1105
+ left: number;
1106
+ };
1107
+ declare function generateRichCaptionDrawOps(asset: CanvasRichCaptionAsset, layout: CaptionLayout, frameTimeMs: number, layoutEngine: CaptionLayoutEngine, config: RichCaptionGeneratorConfig): DrawOp[];
1097
1108
  declare function generateRichCaptionFrame(asset: CanvasRichCaptionAsset, layout: CaptionLayout, frameTimeMs: number, layoutEngine: CaptionLayoutEngine, config: RichCaptionGeneratorConfig): {
1098
1109
  ops: DrawOp[];
1099
1110
  visibleWordCount: number;
@@ -1184,6 +1195,8 @@ declare class RichCaptionRenderer {
1184
1195
  getStats(): RenderStats;
1185
1196
  resetStats(): void;
1186
1197
  clearCache(): void;
1198
+ private mapVerticalAlign;
1199
+ private mapHorizontalAlign;
1187
1200
  private extractAnimationStyle;
1188
1201
  private extractAnimationSpeed;
1189
1202
  private logProgress;
@@ -1316,4 +1329,4 @@ declare function createTextEngine(opts?: {
1316
1329
  destroy(): void;
1317
1330
  }>;
1318
1331
 
1319
- export { type AnimationDirection, type AnimationStyle, type ArcCommand, type BackgroundConfig, type BoundingBox, type CanvasRichCaptionAsset, CanvasRichCaptionAssetSchema, type CanvasRichTextAsset, CanvasRichTextAssetSchema, type CanvasSvgAsset, CanvasSvgAssetSchema, type CaptionGroup, type CaptionLayout, type CaptionLayoutConfig, CaptionLayoutEngine, type CaptionLine, type ClosePathCommand, type CubicBezierCommand, type DrawOp, type EngineInit, type FastVideoOptions, type FastVideoResult, type FontConfig, FontRegistry, type FrameSchedule, type Glyph, type GradientSpec, type IVideoEncoder, type LineToCommand, type MoveToCommand, NodeRawEncoder, type NormalizedPathCommand, type ParsedPathCommand, type PathCommandType, type Point2D, type PositionedWord, type QuadraticBezierCommand, type RGBA, type RenderFrame, type RenderStats, type Renderer, type ResvgRenderOptions, type ResvgRenderResult, type RichCaptionGeneratorConfig, RichCaptionRenderer, type RichCaptionRendererOptions, type ShadowConfig, type ShapedLine, type ShapedWord, type ShapedWordGlyph, type ShotstackRichTextAsset, type ShotstackSvgAsset, type StrokeConfig, type StrokeSpec, type ValidAsset, type VideoEncoderCapabilities, type VideoEncoderConfig, type VideoEncoderProgress, type WordAnimationConfig, type WordAnimationState, type WordTiming, WordTimingStore, arcToCubicBeziers, breakIntoLines, calculateAnimationStatesForGroup, commandsToPathString, computeSimplePathBounds, createDefaultGeneratorConfig, createFrameSchedule, createNodePainter, createNodeRawEncoder, createRichCaptionRenderer, createTextEngine, createVideoEncoder, detectPlatform, detectSubtitleFormat, findWordAtTime, generateRichCaptionDrawOps, generateRichCaptionFrame, generateShapePathData, getDefaultAnimationConfig, getDrawCaptionWordOps, getEncoderCapabilities, getEncoderWarning, groupWordsByPause, isDrawCaptionWordOp, isRTLText, isWebCodecsH264Supported, normalizePath, normalizePathString, parseSubtitleToWords, parseSvgPath, quadraticToCubic, renderSvgAssetToPng, renderSvgToPng, richCaptionAssetSchema, shapeToSvgString };
1332
+ export { ASCENT_RATIO, type AnimationDirection, type AnimationStyle, type ArcCommand, type BackgroundConfig, type BoundingBox, type CanvasRichCaptionAsset, CanvasRichCaptionAssetSchema, type CanvasRichTextAsset, CanvasRichTextAssetSchema, type CanvasSvgAsset, CanvasSvgAssetSchema, type CaptionGroup, type CaptionLayout, type CaptionLayoutConfig, CaptionLayoutEngine, type CaptionLine, type ClosePathCommand, type CubicBezierCommand, DESCENT_RATIO, type DrawOp, type EngineInit, type FastVideoOptions, type FastVideoResult, type FontConfig, FontRegistry, type FrameSchedule, type Glyph, type GradientSpec, type IVideoEncoder, type LineToCommand, type MoveToCommand, NodeRawEncoder, type NormalizedPathCommand, type ParsedPathCommand, type PathCommandType, type Point2D, type PositionedWord, type QuadraticBezierCommand, type RGBA, type RenderFrame, type RenderStats, type Renderer, type ResvgRenderOptions, type ResvgRenderResult, type RichCaptionGeneratorConfig, RichCaptionRenderer, type RichCaptionRendererOptions, type ShadowConfig, type ShapedLine, type ShapedWord, type ShapedWordGlyph, type ShotstackRichTextAsset, type ShotstackSvgAsset, type StrokeConfig, type StrokeSpec, type ValidAsset, type VideoEncoderCapabilities, type VideoEncoderConfig, type VideoEncoderProgress, WORD_BG_BORDER_RADIUS, WORD_BG_OPACITY, WORD_BG_PADDING_RATIO, type WordAnimationConfig, type WordAnimationState, type WordTiming, WordTimingStore, arcToCubicBeziers, breakIntoLines, calculateAnimationStatesForGroup, commandsToPathString, computeSimplePathBounds, createDefaultGeneratorConfig, createFrameSchedule, createNodePainter, createNodeRawEncoder, createRichCaptionRenderer, createTextEngine, createVideoEncoder, detectPlatform, detectSubtitleFormat, extractCaptionPadding, findWordAtTime, generateRichCaptionDrawOps, generateRichCaptionFrame, generateShapePathData, getDefaultAnimationConfig, getDrawCaptionWordOps, getEncoderCapabilities, getEncoderWarning, groupWordsByPause, isDrawCaptionWordOp, isRTLText, isWebCodecsH264Supported, normalizePath, normalizePathString, parseSubtitleToWords, parseSvgPath, quadraticToCubic, renderSvgAssetToPng, renderSvgToPng, richCaptionAssetSchema, shapeToSvgString };