@meframe/core 0.0.42 → 0.0.43

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":"VideoComposer.d.ts","sourceRoot":"","sources":["../../../src/stages/compose/VideoComposer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,cAAc,EACd,aAAa,EACb,gBAAgB,EAGjB,MAAM,SAAS,CAAC;AAIjB,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAapD;;GAEG;AACH,qBAAa,aAAa;IACxB,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,gBAAgB,CAAC,GAAG;QACtE,cAAc,CAAC,EAAE,iBAAiB,GAAG,eAAe,CAAC;KACtD,CAAC;IACF,QAAQ,CAAC,MAAM,EAAE,eAAe,GAAG,iBAAiB,CAAC;IAErD,OAAO,CAAC,GAAG,CAA+D;IAC1E,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,mBAAmB,CAAsB;IACjD,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,eAAe,CAAS;gBAEpB,MAAM,EAAE,kBAAkB;IAgDtC,OAAO,CAAC,aAAa;IA8BrB,aAAa,CAAC,YAAY,CAAC,EAAE,kBAAkB,GAAG,eAAe,CAAC,cAAc,EAAE,UAAU,CAAC;IA6BvF,YAAY,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IA2E7D,iBAAiB,CACrB,WAAW,EAAE,cAAc,EAC3B,SAAS,EAAE,cAAc,EACzB,UAAU,EAAE,gBAAgB,GAC3B,OAAO,CAAC,aAAa,CAAC;IAWzB,OAAO,CAAC,WAAW;YAaL,iBAAiB;YAUjB,SAAS;IAkBvB,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,kBAAkB,CAAC,GAAG,IAAI;IAuBvD,O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-18,6 +18,8 @@ class VideoComposer {
18
18
  filterProcessor;
19
19
  frameDurationUs;
20
20
  // Cached frame duration
21
+ fontsLoadingPromise = null;
22
+ loadedFonts = /* @__PURE__ */ new Set();
21
23
  constructor(config) {
22
24
  this.config = this.applyDefaults(config);
23
25
  this.frameDurationUs = Math.round(1e6 / this.config.fps);
@@ -46,7 +48,7 @@ class VideoComposer {
46
48
  throw new Error("Failed to create 2D rendering context");
47
49
  }
48
50
  this.ctx.imageSmoothingEnabled = this.config.enableSmoothing;
49
- this.loadFonts();
51
+ this.fontsLoadingPromise = this.loadFonts();
50
52
  this.ctx.imageSmoothingQuality = "high";
51
53
  this.layerRenderer = new LayerRenderer(
52
54
  this.ctx,
@@ -104,6 +106,10 @@ class VideoComposer {
104
106
  return stream;
105
107
  }
106
108
  async composeFrame(request) {
109
+ if (this.fontsLoadingPromise) {
110
+ await this.fontsLoadingPromise;
111
+ this.fontsLoadingPromise = null;
112
+ }
107
113
  if (request.layers.length > this.config.maxLayers) {
108
114
  throw new Error(`Too many layers: ${request.layers.length} > ${this.config.maxLayers}`);
109
115
  }
@@ -194,14 +200,17 @@ class VideoComposer {
194
200
  return;
195
201
  }
196
202
  for (const font of this.config.fonts) {
203
+ if (this.loadedFonts.has(font.family)) {
204
+ continue;
205
+ }
197
206
  try {
198
207
  const fontFace = new FontFace(font.family, `url(${font.url})`);
199
- await fontFace.load();
208
+ const loadedFont = await fontFace.load();
200
209
  if ("fonts" in self) {
201
- self.fonts.add(fontFace);
210
+ self.fonts.add(loadedFont);
202
211
  }
203
- } catch (error) {
204
- console.warn(`[VideoComposer] Failed to load font ${font.family}:`, error);
212
+ this.loadedFonts.add(font.family);
213
+ } catch {
205
214
  }
206
215
  }
207
216
  }
@@ -220,7 +229,7 @@ class VideoComposer {
220
229
  this.ctx.imageSmoothingEnabled = this.config.enableSmoothing;
221
230
  }
222
231
  if (config.fonts) {
223
- this.loadFonts();
232
+ this.fontsLoadingPromise = this.loadFonts();
224
233
  }
225
234
  }
226
235
  dispose() {
@@ -1 +1 @@
1
- {"version":3,"file":"VideoComposer.js","sources":["../../../src/stages/compose/VideoComposer.ts"],"sourcesContent":["import type {\n VideoComposeConfig,\n ComposeRequest,\n ComposeResult,\n TransitionEffect,\n VideoLayer,\n Layer,\n} from './types';\nimport { LayerRenderer } from './LayerRenderer';\nimport { TransitionProcessor } from './TransitionProcessor';\nimport { FilterProcessor } from './FilterProcessor';\nimport { ClipInstructionSet } from './instructions';\n\nconst closeLayerFrame = (layer: Layer) => {\n if ((layer as any).type === 'video') {\n // If layer has videoFrame, close it\n const vf = (layer as VideoLayer).videoFrame;\n if (vf?.close) {\n vf.close();\n }\n // RcFrame should not be closed here as it's managed by CacheManager\n }\n};\n\n/**\n * VideoComposer - Main visual composition orchestrator\n */\nexport class VideoComposer {\n readonly config: Omit<Required<VideoComposeConfig>, 'externalCanvas'> & {\n externalCanvas?: HTMLCanvasElement | OffscreenCanvas;\n };\n readonly canvas: OffscreenCanvas | HTMLCanvasElement;\n\n private ctx: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D;\n private layerRenderer: LayerRenderer;\n private transitionProcessor: TransitionProcessor;\n private filterProcessor: FilterProcessor;\n private frameDurationUs: number; // Cached frame duration\n\n constructor(config: VideoComposeConfig) {\n this.config = this.applyDefaults(config);\n this.frameDurationUs = Math.round(1_000_000 / this.config.fps); // Pre-calculate\n\n if (config.externalCanvas) {\n this.canvas = config.externalCanvas;\n\n // FIX: Ensure external canvas dimensions match the config\n if (this.canvas.width !== this.config.width || this.canvas.height !== this.config.height) {\n this.canvas.width = this.config.width;\n this.canvas.height = this.config.height;\n }\n\n this.ctx = this.canvas.getContext('2d', {\n alpha: true,\n desynchronized: true,\n willReadFrequently: false,\n colorSpace: 'srgb',\n }) as CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;\n } else {\n this.canvas = new OffscreenCanvas(this.config.width, this.config.height);\n this.ctx = this.canvas.getContext('2d', {\n alpha: true,\n desynchronized: true,\n willReadFrequently: false,\n colorSpace: 'srgb',\n }) as OffscreenCanvasRenderingContext2D;\n }\n\n if (!this.ctx) {\n throw new Error('Failed to create 2D rendering context');\n }\n\n this.ctx.imageSmoothingEnabled = this.config.enableSmoothing;\n\n this.loadFonts();\n this.ctx.imageSmoothingQuality = 'high';\n\n this.layerRenderer = new LayerRenderer(\n this.ctx,\n this.config.width,\n this.config.height,\n this.config.fps\n );\n this.transitionProcessor = new TransitionProcessor(this.config.width, this.config.height);\n this.filterProcessor = new FilterProcessor();\n }\n\n private applyDefaults(config: VideoComposeConfig): Omit<\n Required<VideoComposeConfig>,\n 'externalCanvas'\n > & {\n externalCanvas?: HTMLCanvasElement | OffscreenCanvas;\n } {\n return {\n width: config.width || 720,\n height: config.height || 1280,\n fps: config.fps || 30,\n backgroundColor: config.backgroundColor ?? '#000',\n renderer: config.renderer ?? 'canvas2d',\n enableSmoothing: config.enableSmoothing ?? true,\n enableHardwareAcceleration: config.enableHardwareAcceleration ?? true,\n revision: config.revision ?? 0,\n inputHighWaterMark: config.inputHighWaterMark ?? 3,\n outputHighWaterMark: config.outputHighWaterMark ?? 1,\n maxLayers: config.maxLayers ?? 100,\n timeline: config.timeline ?? {\n clipId: 'default',\n trackId: 'main',\n clipStartUs: 0,\n clipDurationUs: Infinity,\n compositionFps: 30,\n },\n fonts: config.fonts ?? [],\n externalCanvas: config.externalCanvas,\n };\n }\n\n createStreams(_instruction?: ClipInstructionSet): TransformStream<ComposeRequest, VideoFrame> {\n // Always create new streams for each clip\n // ReadableStreams can only be consumed once\n const stream = new TransformStream<ComposeRequest, VideoFrame>(\n {\n transform: async (request, controller) => {\n // console.log('[VideoComposer] transform', request, controller.desiredSize);\n const result = await this.composeFrame(request);\n if (result.frame) {\n controller.enqueue(result.frame);\n }\n // setTimeout(() => {\n // result.frame.close();\n // }, 1000);\n },\n\n flush: async () => {\n this.filterProcessor.clearCache();\n },\n },\n {\n highWaterMark: this.config.inputHighWaterMark,\n },\n {\n highWaterMark: this.config.outputHighWaterMark,\n }\n );\n return stream;\n }\n async composeFrame(request: ComposeRequest): Promise<ComposeResult> {\n if (request.layers.length > this.config.maxLayers) {\n throw new Error(`Too many layers: ${request.layers.length} > ${this.config.maxLayers}`);\n }\n\n this.clearCanvas();\n\n // Calculate current frame number for animations (relative to clip start)\n const frameDurationUs = 1_000_000 / this.config.fps;\n const relativeFrame = Math.floor(request.timeUs / frameDurationUs);\n this.layerRenderer.setCurrentFrame(relativeFrame);\n\n if (request.transition) {\n this.ctx.save();\n this.transitionProcessor.applyTransition(this.ctx, request.transition);\n }\n\n for (const layer of request.layers) {\n if (!layer.visible || layer.opacity <= 0) {\n // Close video frame for invisible layers\n closeLayerFrame(layer);\n continue;\n }\n\n try {\n // If layer has RcFrame, use it within the rendering scope\n if ((layer as any).rcFrame) {\n await (layer as any).rcFrame.use(async (frame: VideoFrame) => {\n // Set the cloned frame for this render cycle\n (layer as VideoLayer).videoFrame = frame;\n\n if (layer.filters && layer.filters.length > 0) {\n this.ctx.save();\n this.filterProcessor.applyFilters(this.ctx, layer.filters);\n }\n await this.layerRenderer.renderLayer(layer);\n\n if (layer.filters && layer.filters.length > 0) {\n this.ctx.restore();\n }\n });\n } else {\n // Regular layer without RcFrame\n if (layer.filters && layer.filters.length > 0) {\n this.ctx.save();\n this.filterProcessor.applyFilters(this.ctx, layer.filters);\n }\n await this.layerRenderer.renderLayer(layer);\n\n if (layer.filters && layer.filters.length > 0) {\n this.ctx.restore();\n }\n }\n } catch (error) {\n console.error('[VideoComposer] composeFrame error: ', error);\n // Always close video frame after rendering (or on error)\n closeLayerFrame(layer);\n }\n }\n\n if (request.transition) {\n this.ctx.restore();\n }\n\n let frame: VideoFrame | null = null;\n if (!this.config.externalCanvas) {\n frame = await this.createOutputFrame(request.timeUs);\n }\n\n return {\n frame,\n timeUs: request.timeUs,\n };\n }\n\n async composeTransition(\n fromRequest: ComposeRequest,\n toRequest: ComposeRequest,\n transition: TransitionEffect\n ): Promise<ComposeResult> {\n await this.composeFrame(fromRequest);\n\n const toFrameRequest = {\n ...toRequest,\n transition,\n };\n\n return this.composeFrame(toFrameRequest);\n }\n\n private clearCanvas(): void {\n if (this.config.backgroundColor) {\n this.ctx.fillStyle = this.config.backgroundColor;\n this.ctx.fillRect(0, 0, this.config.width, this.config.height);\n } else {\n this.ctx.clearRect(0, 0, this.config.width, this.config.height);\n }\n }\n\n // private sortLayers(layers: Layer[]): Layer[] {\n // return [...layers].sort((a, b) => a.zIndex - b.zIndex);\n // }\n\n private async createOutputFrame(timeUs: number): Promise<VideoFrame> {\n const frame = new VideoFrame(this.canvas, {\n timestamp: timeUs,\n duration: this.frameDurationUs, // Use cached duration\n alpha: 'discard',\n visibleRect: { x: 0, y: 0, width: this.canvas.width, height: this.canvas.height },\n });\n return frame;\n }\n\n private async loadFonts(): Promise<void> {\n if (!this.config.fonts || this.config.fonts.length === 0) {\n return;\n }\n\n for (const font of this.config.fonts) {\n try {\n const fontFace = new FontFace(font.family, `url(${font.url})`);\n await fontFace.load();\n if ('fonts' in self) {\n (self as any).fonts.add(fontFace);\n }\n } catch (error) {\n console.warn(`[VideoComposer] Failed to load font ${font.family}:`, error);\n }\n }\n }\n\n updateConfig(config: Partial<VideoComposeConfig>): void {\n Object.assign(this.config, this.applyDefaults({ ...this.config, ...config }));\n\n if (config.fps !== undefined) {\n this.frameDurationUs = Math.round(1_000_000 / this.config.fps); // Update cached duration\n }\n\n if (config.width || config.height) {\n this.canvas.width = this.config.width;\n this.canvas.height = this.config.height;\n this.layerRenderer.updateDimensions(this.config.width, this.config.height);\n this.transitionProcessor.updateDimensions(this.config.width, this.config.height);\n }\n\n if (config.enableSmoothing !== undefined) {\n this.ctx.imageSmoothingEnabled = this.config.enableSmoothing;\n }\n\n if (config.fonts) {\n this.loadFonts();\n }\n }\n\n dispose(): void {\n this.filterProcessor.clearCache();\n }\n}\n"],"names":["frame"],"mappings":";;;AAaA,MAAM,kBAAkB,CAAC,UAAiB;AACxC,MAAK,MAAc,SAAS,SA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AC7D,cAAM,SAAS,KAAA;AACf,YAAI,WAAW,MAAM;AAClB,eAAa,MAAM,IAAI,QAAQ;AAAA,QAClC;AAAA,MACF,SAAS,OAAO;AACd,gBAAQ,KAAK,uCAAuC,KAAK,MAAM,KAAK,KAAK;AAAA,MAC3E;AAAA,IACF;AAAA,EACF;AAAA,EAEA,aAAa,QAA2C;AACtD,WAAO,OAAO,KAAK,QAAQ,KAAK,cAAc,EAAE,GAAG,KAAK,QAAQ,GAAG,OAAA,CAAQ,CAAC;AAE5E,QAAI,OAAO,QAAQ,QAAW;AAC5B,WAAK,kBAAkB,KAAK,MAAM,MAAY,KAAK,OAAO,GAAG;AAAA,IAC/D;AAEA,QAAI,OAAO,SAAS,OAAO,QAAQ;AACjC,WAAK,OAAO,QAAQ,KAAK,OAAO;AAChC,WAAK,OAAO,SAAS,KAAK,OAAO;AACjC,WAAK,cAAc,iBAAiB,KAAK,OAAO,OAAO,KAAK,OAAO,MAAM;AACzE,WAAK,oBAAoB,iBAAiB,KAAK,OAAO,OAAO,KAAK,OAAO,MAAM;AAAA,IACjF;AAEA,QAAI,OAAO,oBAAoB,QAAW;AACxC,WAAK,IAAI,wBAAwB,KAAK,OAAO;AAAA,IAC/C;AAEA,QAAI,OAAO,OAAO;AAChB,WAAK,UAAA;AAAA,IACP;AAAA,EACF;AAAA,EAEA,UAAgB;AACd,SAAK,gBAAgB,WAAA;AAAA,EACvB;AACF;"}
1
+ {"version":3,"file":"VideoComposer.js","sources":["../../../src/stages/compose/VideoComposer.ts"],"sourcesContent":["import type {\n VideoComposeConfig,\n ComposeRequest,\n ComposeResult,\n TransitionEffect,\n VideoLayer,\n Layer,\n} from './types';\nimport { LayerRenderer } from './LayerRenderer';\nimport { TransitionProcessor } from './TransitionProcessor';\nimport { FilterProcessor } from './FilterProcessor';\nimport { ClipInstructionSet } from './instructions';\n\nconst closeLayerFrame = (layer: Layer) => {\n if ((layer as any).type === 'video') {\n // If layer has videoFrame, close it\n const vf = (layer as VideoLayer).videoFrame;\n if (vf?.close) {\n vf.close();\n }\n // RcFrame should not be closed here as it's managed by CacheManager\n }\n};\n\n/**\n * VideoComposer - Main visual composition orchestrator\n */\nexport class VideoComposer {\n readonly config: Omit<Required<VideoComposeConfig>, 'externalCanvas'> & {\n externalCanvas?: HTMLCanvasElement | OffscreenCanvas;\n };\n readonly canvas: OffscreenCanvas | HTMLCanvasElement;\n\n private ctx: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D;\n private layerRenderer: LayerRenderer;\n private transitionProcessor: TransitionProcessor;\n private filterProcessor: FilterProcessor;\n private frameDurationUs: number; // Cached frame duration\n private fontsLoadingPromise: Promise<void> | null = null;\n private loadedFonts = new Set<string>();\n\n constructor(config: VideoComposeConfig) {\n this.config = this.applyDefaults(config);\n this.frameDurationUs = Math.round(1_000_000 / this.config.fps); // Pre-calculate\n\n if (config.externalCanvas) {\n this.canvas = config.externalCanvas;\n\n // FIX: Ensure external canvas dimensions match the config\n if (this.canvas.width !== this.config.width || this.canvas.height !== this.config.height) {\n this.canvas.width = this.config.width;\n this.canvas.height = this.config.height;\n }\n\n this.ctx = this.canvas.getContext('2d', {\n alpha: true,\n desynchronized: true,\n willReadFrequently: false,\n colorSpace: 'srgb',\n }) as CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;\n } else {\n this.canvas = new OffscreenCanvas(this.config.width, this.config.height);\n this.ctx = this.canvas.getContext('2d', {\n alpha: true,\n desynchronized: true,\n willReadFrequently: false,\n colorSpace: 'srgb',\n }) as OffscreenCanvasRenderingContext2D;\n }\n\n if (!this.ctx) {\n throw new Error('Failed to create 2D rendering context');\n }\n\n this.ctx.imageSmoothingEnabled = this.config.enableSmoothing;\n\n // Start loading fonts but don't block constructor\n this.fontsLoadingPromise = this.loadFonts();\n this.ctx.imageSmoothingQuality = 'high';\n\n this.layerRenderer = new LayerRenderer(\n this.ctx,\n this.config.width,\n this.config.height,\n this.config.fps\n );\n this.transitionProcessor = new TransitionProcessor(this.config.width, this.config.height);\n this.filterProcessor = new FilterProcessor();\n }\n\n private applyDefaults(config: VideoComposeConfig): Omit<\n Required<VideoComposeConfig>,\n 'externalCanvas'\n > & {\n externalCanvas?: HTMLCanvasElement | OffscreenCanvas;\n } {\n return {\n width: config.width || 720,\n height: config.height || 1280,\n fps: config.fps || 30,\n backgroundColor: config.backgroundColor ?? '#000',\n renderer: config.renderer ?? 'canvas2d',\n enableSmoothing: config.enableSmoothing ?? true,\n enableHardwareAcceleration: config.enableHardwareAcceleration ?? true,\n revision: config.revision ?? 0,\n inputHighWaterMark: config.inputHighWaterMark ?? 3,\n outputHighWaterMark: config.outputHighWaterMark ?? 1,\n maxLayers: config.maxLayers ?? 100,\n timeline: config.timeline ?? {\n clipId: 'default',\n trackId: 'main',\n clipStartUs: 0,\n clipDurationUs: Infinity,\n compositionFps: 30,\n },\n fonts: config.fonts ?? [],\n externalCanvas: config.externalCanvas,\n };\n }\n\n createStreams(_instruction?: ClipInstructionSet): TransformStream<ComposeRequest, VideoFrame> {\n // Always create new streams for each clip\n // ReadableStreams can only be consumed once\n const stream = new TransformStream<ComposeRequest, VideoFrame>(\n {\n transform: async (request, controller) => {\n // console.log('[VideoComposer] transform', request, controller.desiredSize);\n const result = await this.composeFrame(request);\n if (result.frame) {\n controller.enqueue(result.frame);\n }\n // setTimeout(() => {\n // result.frame.close();\n // }, 1000);\n },\n\n flush: async () => {\n this.filterProcessor.clearCache();\n },\n },\n {\n highWaterMark: this.config.inputHighWaterMark,\n },\n {\n highWaterMark: this.config.outputHighWaterMark,\n }\n );\n return stream;\n }\n async composeFrame(request: ComposeRequest): Promise<ComposeResult> {\n // Ensure fonts are loaded before rendering\n if (this.fontsLoadingPromise) {\n await this.fontsLoadingPromise;\n this.fontsLoadingPromise = null; // Only wait once\n }\n\n if (request.layers.length > this.config.maxLayers) {\n throw new Error(`Too many layers: ${request.layers.length} > ${this.config.maxLayers}`);\n }\n\n this.clearCanvas();\n\n // Calculate current frame number for animations (relative to clip start)\n const frameDurationUs = 1_000_000 / this.config.fps;\n const relativeFrame = Math.floor(request.timeUs / frameDurationUs);\n this.layerRenderer.setCurrentFrame(relativeFrame);\n\n if (request.transition) {\n this.ctx.save();\n this.transitionProcessor.applyTransition(this.ctx, request.transition);\n }\n\n for (const layer of request.layers) {\n if (!layer.visible || layer.opacity <= 0) {\n // Close video frame for invisible layers\n closeLayerFrame(layer);\n continue;\n }\n\n try {\n // If layer has RcFrame, use it within the rendering scope\n if ((layer as any).rcFrame) {\n await (layer as any).rcFrame.use(async (frame: VideoFrame) => {\n // Set the cloned frame for this render cycle\n (layer as VideoLayer).videoFrame = frame;\n\n if (layer.filters && layer.filters.length > 0) {\n this.ctx.save();\n this.filterProcessor.applyFilters(this.ctx, layer.filters);\n }\n await this.layerRenderer.renderLayer(layer);\n\n if (layer.filters && layer.filters.length > 0) {\n this.ctx.restore();\n }\n });\n } else {\n // Regular layer without RcFrame\n if (layer.filters && layer.filters.length > 0) {\n this.ctx.save();\n this.filterProcessor.applyFilters(this.ctx, layer.filters);\n }\n await this.layerRenderer.renderLayer(layer);\n\n if (layer.filters && layer.filters.length > 0) {\n this.ctx.restore();\n }\n }\n } catch (error) {\n console.error('[VideoComposer] composeFrame error: ', error);\n // Always close video frame after rendering (or on error)\n closeLayerFrame(layer);\n }\n }\n\n if (request.transition) {\n this.ctx.restore();\n }\n\n let frame: VideoFrame | null = null;\n if (!this.config.externalCanvas) {\n frame = await this.createOutputFrame(request.timeUs);\n }\n\n return {\n frame,\n timeUs: request.timeUs,\n };\n }\n\n async composeTransition(\n fromRequest: ComposeRequest,\n toRequest: ComposeRequest,\n transition: TransitionEffect\n ): Promise<ComposeResult> {\n await this.composeFrame(fromRequest);\n\n const toFrameRequest = {\n ...toRequest,\n transition,\n };\n\n return this.composeFrame(toFrameRequest);\n }\n\n private clearCanvas(): void {\n if (this.config.backgroundColor) {\n this.ctx.fillStyle = this.config.backgroundColor;\n this.ctx.fillRect(0, 0, this.config.width, this.config.height);\n } else {\n this.ctx.clearRect(0, 0, this.config.width, this.config.height);\n }\n }\n\n // private sortLayers(layers: Layer[]): Layer[] {\n // return [...layers].sort((a, b) => a.zIndex - b.zIndex);\n // }\n\n private async createOutputFrame(timeUs: number): Promise<VideoFrame> {\n const frame = new VideoFrame(this.canvas, {\n timestamp: timeUs,\n duration: this.frameDurationUs, // Use cached duration\n alpha: 'discard',\n visibleRect: { x: 0, y: 0, width: this.canvas.width, height: this.canvas.height },\n });\n return frame;\n }\n\n private async loadFonts(): Promise<void> {\n if (!this.config.fonts || this.config.fonts.length === 0) {\n return;\n }\n\n for (const font of this.config.fonts) {\n if (this.loadedFonts.has(font.family)) {\n continue;\n }\n\n try {\n const fontFace = new FontFace(font.family, `url(${font.url})`);\n const loadedFont = await fontFace.load();\n\n if ('fonts' in self) {\n self.fonts.add(loadedFont);\n }\n\n this.loadedFonts.add(font.family);\n } catch {\n // Font loading failed, will fallback to system fonts\n }\n }\n }\n\n updateConfig(config: Partial<VideoComposeConfig>): void {\n Object.assign(this.config, this.applyDefaults({ ...this.config, ...config }));\n\n if (config.fps !== undefined) {\n this.frameDurationUs = Math.round(1_000_000 / this.config.fps); // Update cached duration\n }\n\n if (config.width || config.height) {\n this.canvas.width = this.config.width;\n this.canvas.height = this.config.height;\n this.layerRenderer.updateDimensions(this.config.width, this.config.height);\n this.transitionProcessor.updateDimensions(this.config.width, this.config.height);\n }\n\n if (config.enableSmoothing !== undefined) {\n this.ctx.imageSmoothingEnabled = this.config.enableSmoothing;\n }\n\n if (config.fonts) {\n this.fontsLoadingPromise = this.loadFonts();\n }\n }\n\n dispose(): void {\n this.filterProcessor.clearCache();\n }\n}\n"],"names":["frame"],"mappings":";;;AAaA,MAAM,kBAAkB,CAAC,UAAiB;AACxC,MAAK,MAAc,SAAS,SAAS;AAEnC,UAAM,KAAM,MAAqB;AACjC,QAAI,IAAI,OAAO;AACb,SAAG,MAAA;AAAA,IACL;AAAA,EAEF;AACF;AAKO,MAAM,cAAc;AAAA,EAChB;AAA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AO,CAAC,SAAS,CAAC,CAAC;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;IACzC,cAAc,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;CAC/C;AAED,wBAAgB,kBAAkB,CAAC,GAAG,SAAS,EAAE,YAAY,EAAE,GAAG,YAAY,CAgB7E;AAqVD,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CA6DvD,CAAC;AAEF,wBAAgB,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,YAAY,CA0B9D"}
1
+ {"version":3,"file":"font-templates.d.ts","sourceRoot":"","sources":["../../../../src/stages/compose/font-system/font-templates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9E,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;IACzC,cAAc,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;CAC/C;AAED,wBAAgB,kBAAkB,CAAC,GAAG,SAAS,EAAE,YAAY,EAAE,GAAG,YAAY,CAgB7E;AAgWD,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CA+DvD,CAAC;AAEF,wBAAgB,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,YAAY,CA0B9D"}
@@ -238,6 +238,13 @@ const globalTop80 = {
238
238
  top: "80%"
239
239
  }
240
240
  };
241
+ const globalTop92 = {
242
+ name: "global-top-92",
243
+ globalPosition: {
244
+ position: "absolute",
245
+ top: "92%"
246
+ }
247
+ };
241
248
  const globalBottom5 = {
242
249
  name: "global-bottom-5",
243
250
  globalPosition: {
@@ -268,13 +275,15 @@ blackText.name = "blackText";
268
275
  const baseSubtitle = mergeFontTemplates(normal40, fillWhite, strokeBlack8, globalTop70);
269
276
  baseSubtitle.name = "baseSubtitle";
270
277
  const baseSubtitleCenter = mergeFontTemplates(
271
- normal50,
278
+ normal40,
272
279
  fillWhite,
273
- strokeBlack16,
274
- globalCenter,
280
+ strokeBlack8,
281
+ globalTop70,
275
282
  container60
276
283
  );
277
284
  baseSubtitleCenter.name = "baseSubtitleCenter";
285
+ const baseSubtitle16_9 = mergeFontTemplates(normal40, fillWhite, strokeBlack8, globalTop92);
286
+ baseSubtitle16_9.name = "baseSubtitle16_9";
278
287
  const yellowSubtitle = mergeFontTemplates(yellowText, globalTop70);
279
288
  yellowSubtitle.name = "yellowSubtitle";
280
289
  const whiteSubtitle = mergeFontTemplates(whiteText, globalTop70);
@@ -339,6 +348,7 @@ const FONT_TEMPLATES = {
339
348
  "global-top-20": globalTop20,
340
349
  "global-top-70": globalTop70,
341
350
  "global-top-80": globalTop80,
351
+ "global-top-92": globalTop92,
342
352
  "global-bottom-5": globalBottom5,
343
353
  "global-bottom-10": globalBottom10,
344
354
  "global-bottom-15": globalBottom15,
@@ -347,6 +357,7 @@ const FONT_TEMPLATES = {
347
357
  blackText,
348
358
  baseSubtitle,
349
359
  baseSubtitleCenter,
360
+ baseSubtitle16_9,
350
361
  yellowSubtitle,
351
362
  whiteSubtitle,
352
363
  blackSubtitle,
@@ -366,7 +377,7 @@ function getTemplate(templateName) {
366
377
  fontFamily: "Arial, sans-serif",
367
378
  fill: "rgb(255, 255, 255)",
368
379
  stroke: "rgb(0, 0, 0)",
369
- strokeWidth: 4,
380
+ strokeWidth: 8,
370
381
  lineHeight: 1.2
371
382
  }
372
383
  };
@@ -1 +1 @@
1
- {"version":3,"file":"font-templates.js","sources":["../../../../src/stages/compose/font-system/font-templates.ts"],"sourcesContent":["import type { TextStyle, ContainerStyle, GlobalPositionStyle } from './types';\n\nexport interface FontTemplate {\n name: string;\n textStyle?: Partial<TextStyle>;\n containerStyle?: Partial<ContainerStyle>;\n globalPosition?: Partial<GlobalPositionStyle>;\n}\n\nexport function mergeFontTemplates(...templates: FontTemplate[]): FontTemplate {\n const merged: FontTemplate = { name: 'merged' };\n\n for (const template of templates) {\n if (template.textStyle) {\n merged.textStyle = { ...merged.textStyle, ...template.textStyle };\n }\n if (template.containerStyle) {\n merged.containerStyle = { ...merged.containerStyle, ...template.containerStyle };\n }\n if (template.globalPosition) {\n merged.globalPosition = { ...merged.globalPosition, ...template.globalPosition };\n }\n }\n\n return merged;\n}\n\nconst normal30: FontTemplate = {\n name: 'normal-30',\n textStyle: { fontSize: 30 },\n};\n\nconst normal40: FontTemplate = {\n name: 'normal-40',\n textStyle: { fontSize: 40 },\n};\n\nconst normal50: FontTemplate = {\n name: 'normal-50',\n textStyle: { fontSize: 50 },\n};\n\nconst normal60: FontTemplate = {\n name: 'normal-60',\n textStyle: { fontSize: 60 },\n};\n\nconst normal80: FontTemplate = {\n name: 'normal-80',\n textStyle: { fontSize: 80 },\n};\n\nconst bold40: FontTemplate = {\n name: 'bold-40',\n textStyle: { fontWeight: 'bold', fontSize: 40 },\n};\n\nconst bold50: FontTemplate = {\n name: 'bold-50',\n textStyle: { fontWeight: 'bold', fontSize: 50 },\n};\n\nconst bold60: FontTemplate = {\n name: 'bold-60',\n textStyle: { fontWeight: 'bold', letterSpacing: '0.05em', fontSize: 60 },\n};\n\nconst fillBlack: FontTemplate = {\n name: 'fill-black',\n textStyle: { fill: 'rgb(0, 0, 0)' },\n};\n\nconst fillWhite: FontTemplate = {\n name: 'fill-white',\n textStyle: { fill: 'rgb(255, 255, 255)' },\n};\n\nconst fillYellow: FontTemplate = {\n name: 'fill-yellow',\n textStyle: { fill: 'rgb(255, 215, 0)' },\n};\n\nconst fillRed: FontTemplate = {\n name: 'fill-red',\n textStyle: { fill: 'rgb(255, 77, 77)' },\n};\n\nconst fillPink: FontTemplate = {\n name: 'fill-pink',\n textStyle: { fill: 'rgb(255, 192, 203)' },\n};\n\nconst strokeBlack: FontTemplate = {\n name: 'stroke-black',\n textStyle: {\n paintOrder: 'stroke',\n strokeLinejoin: 'round',\n strokeLinecap: 'round',\n stroke: 'rgb(0, 0, 0)',\n },\n};\n\nconst strokeWhite: FontTemplate = {\n name: 'stroke-white',\n textStyle: {\n paintOrder: 'stroke',\n strokeLinejoin: 'round',\n strokeLinecap: 'round',\n stroke: 'rgb(255, 255, 255)',\n },\n};\n\nconst strokeYellow: FontTemplate = {\n name: 'stroke-yellow',\n textStyle: {\n paintOrder: 'stroke',\n strokeLinejoin: 'round',\n strokeLinecap: 'round',\n stroke: 'rgb(255, 215, 0)',\n },\n};\n\nconst stroke0: FontTemplate = {\n name: 'stroke-0',\n textStyle: { strokeWidth: 0 },\n};\n\nconst stroke2: FontTemplate = {\n name: 'stroke-2',\n textStyle: { strokeWidth: 2 },\n};\n\nconst stroke4: FontTemplate = {\n name: 'stroke-4',\n textStyle: { strokeWidth: 4 },\n};\n\nconst stroke6: FontTemplate = {\n name: 'stroke-6',\n textStyle: { strokeWidth: 6 },\n};\n\nconst stroke8: FontTemplate = {\n name: 'stroke-8',\n textStyle: { strokeWidth: 8 },\n};\n\nconst stroke16: FontTemplate = {\n name: 'stroke-16',\n textStyle: { strokeWidth: 16 },\n};\n\nconst strokeBlack4 = mergeFontTemplates(strokeBlack, stroke4);\nstrokeBlack4.name = 'stroke-black-4';\n\nconst strokeBlack6 = mergeFontTemplates(strokeBlack, stroke6);\nstrokeBlack6.name = 'stroke-black-6';\n\nconst strokeBlack8 = mergeFontTemplates(strokeBlack, stroke8);\nstrokeBlack8.name = 'stroke-black-8';\n\nconst strokeBlack16 = mergeFontTemplates(strokeBlack, stroke16);\nstrokeBlack16.name = 'stroke-black-16';\n\nconst strokeWhite4 = mergeFontTemplates(strokeWhite, stroke4);\nstrokeWhite4.name = 'stroke-white-4';\n\nconst strokeWhite8 = mergeFontTemplates(strokeWhite, stroke8);\nstrokeWhite8.name = 'stroke-white-8';\n\nconst strokeYellow4 = mergeFontTemplates(strokeYellow, stroke4);\nstrokeYellow4.name = 'stroke-yellow-4';\n\nconst strokeYellow8 = mergeFontTemplates(strokeYellow, stroke8);\nstrokeYellow8.name = 'stroke-yellow-8';\n\nconst containerFull: FontTemplate = {\n name: 'container-full',\n containerStyle: { width: '100%' },\n};\n\nconst container60: FontTemplate = {\n name: 'container-60',\n containerStyle: { width: '60%' },\n};\n\nconst container80: FontTemplate = {\n name: 'container-80',\n containerStyle: { width: '80%' },\n};\n\nconst container95: FontTemplate = {\n name: 'container-95',\n containerStyle: { width: '95%' },\n};\n\nconst container98: FontTemplate = {\n name: 'container-98',\n containerStyle: { width: '98%' },\n};\n\nconst containerBlack: FontTemplate = {\n name: 'container-black',\n containerStyle: {\n backgroundColor: 'black',\n padding: '10px 10px 4px 10px',\n borderRadius: 10,\n width: '80%',\n },\n};\n\nconst containerWhite: FontTemplate = {\n name: 'container-white',\n containerStyle: {\n backgroundColor: 'white',\n padding: '10px 10px 4px 10px',\n borderRadius: 10,\n width: '80%',\n },\n};\n\nconst containerYellow: FontTemplate = {\n name: 'container-yellow',\n containerStyle: {\n backgroundColor: 'yellow',\n padding: '10px 10px 4px 10px',\n borderRadius: 10,\n width: '80%',\n },\n};\n\nconst containerBlackOpacity40: FontTemplate = {\n name: 'container-black-opacity-40',\n containerStyle: {\n backgroundColor: 'rgba(0, 0, 0, 0.4)',\n padding: '10px 10px 4px 10px',\n borderRadius: 10,\n width: '80%',\n },\n};\n\nconst globalCenter: FontTemplate = {\n name: 'global-center',\n globalPosition: {\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n },\n};\n\nconst globalHorizontalCenter: FontTemplate = {\n name: 'global-horizontal-center',\n globalPosition: {\n display: 'flex',\n justifyContent: 'center',\n },\n};\n\nconst globalTop5: FontTemplate = {\n name: 'global-top-5',\n globalPosition: {\n position: 'absolute',\n top: '5%',\n },\n};\n\nconst globalTop10: FontTemplate = {\n name: 'global-top-10',\n globalPosition: {\n position: 'absolute',\n top: '10%',\n },\n};\n\nconst globalTop20: FontTemplate = {\n name: 'global-top-20',\n globalPosition: {\n position: 'absolute',\n top: '20%',\n },\n};\n\nconst globalTop70: FontTemplate = {\n name: 'global-top-70',\n globalPosition: {\n position: 'absolute',\n top: '70%',\n },\n};\n\nconst globalTop80: FontTemplate = {\n name: 'global-top-80',\n globalPosition: {\n position: 'absolute',\n top: '80%',\n },\n};\n\nconst globalBottom5: FontTemplate = {\n name: 'global-bottom-5',\n globalPosition: {\n position: 'absolute',\n bottom: '5%',\n },\n};\n\nconst globalBottom10: FontTemplate = {\n name: 'global-bottom-10',\n globalPosition: {\n position: 'absolute',\n bottom: '10%',\n },\n};\n\nconst globalBottom15: FontTemplate = {\n name: 'global-bottom-15',\n globalPosition: {\n position: 'absolute',\n bottom: '15%',\n },\n};\n\nconst yellowText = mergeFontTemplates(normal40, fillYellow, strokeBlack8);\nyellowText.name = 'yellowText';\n\nconst whiteText = mergeFontTemplates(normal40, fillWhite, strokeBlack8);\nwhiteText.name = 'whiteText';\n\nconst blackText = mergeFontTemplates(normal40, fillBlack, strokeWhite8);\nblackText.name = 'blackText';\n\nconst baseSubtitle = mergeFontTemplates(normal40, fillWhite, strokeBlack8, globalTop70);\nbaseSubtitle.name = 'baseSubtitle';\n\nconst baseSubtitleCenter = mergeFontTemplates(\n normal50,\n fillWhite,\n strokeBlack16,\n globalCenter,\n container60\n);\nbaseSubtitleCenter.name = 'baseSubtitleCenter';\n\nconst yellowSubtitle = mergeFontTemplates(yellowText, globalTop70);\nyellowSubtitle.name = 'yellowSubtitle';\n\nconst whiteSubtitle = mergeFontTemplates(whiteText, globalTop70);\nwhiteSubtitle.name = 'whiteSubtitle';\n\nconst blackSubtitle = mergeFontTemplates(blackText, globalTop70);\nblackSubtitle.name = 'blackSubtitle';\n\nconst subtitleBackgroundBlack = mergeFontTemplates(\n normal40,\n fillWhite,\n globalTop70,\n containerBlack\n);\nsubtitleBackgroundBlack.name = 'subtitleBackgroundBlack';\n\nconst title = mergeFontTemplates(yellowText, bold50, globalTop5, container95);\ntitle.name = 'title';\n\nconst subtitle = mergeFontTemplates(normal30, fillWhite, strokeBlack8, globalTop5, container80);\nsubtitle.name = 'subtitle';\n\nexport const FONT_TEMPLATES: Record<string, FontTemplate> = {\n 'normal-30': normal30,\n 'normal-40': normal40,\n 'normal-50': normal50,\n 'normal-60': normal60,\n 'normal-80': normal80,\n 'bold-40': bold40,\n 'bold-50': bold50,\n 'bold-60': bold60,\n 'fill-black': fillBlack,\n 'fill-white': fillWhite,\n 'fill-yellow': fillYellow,\n 'fill-red': fillRed,\n 'fill-pink': fillPink,\n 'stroke-black': strokeBlack,\n 'stroke-white': strokeWhite,\n 'stroke-yellow': strokeYellow,\n 'stroke-0': stroke0,\n 'stroke-2': stroke2,\n 'stroke-4': stroke4,\n 'stroke-6': stroke6,\n 'stroke-8': stroke8,\n 'stroke-16': stroke16,\n 'stroke-black-4': strokeBlack4,\n 'stroke-black-6': strokeBlack6,\n 'stroke-black-8': strokeBlack8,\n 'stroke-black-16': strokeBlack16,\n 'stroke-white-4': strokeWhite4,\n 'stroke-white-8': strokeWhite8,\n 'stroke-yellow-4': strokeYellow4,\n 'stroke-yellow-8': strokeYellow8,\n 'container-full': containerFull,\n 'container-60': container60,\n 'container-80': container80,\n 'container-95': container95,\n 'container-98': container98,\n 'container-black': containerBlack,\n 'container-white': containerWhite,\n 'container-yellow': containerYellow,\n 'container-black-opacity-40': containerBlackOpacity40,\n 'global-center': globalCenter,\n 'global-horizontal-center': globalHorizontalCenter,\n 'global-top-5': globalTop5,\n 'global-top-10': globalTop10,\n 'global-top-20': globalTop20,\n 'global-top-70': globalTop70,\n 'global-top-80': globalTop80,\n 'global-bottom-5': globalBottom5,\n 'global-bottom-10': globalBottom10,\n 'global-bottom-15': globalBottom15,\n yellowText,\n whiteText,\n blackText,\n baseSubtitle,\n baseSubtitleCenter,\n yellowSubtitle,\n whiteSubtitle,\n blackSubtitle,\n subtitleBackgroundBlack,\n title,\n subtitle,\n};\n\nexport function getTemplate(templateName: string): FontTemplate {\n const templateNames = templateName.split(' ').filter(Boolean);\n const templates = templateNames\n .map((name) => FONT_TEMPLATES[name])\n .filter((t): t is FontTemplate => t !== undefined);\n\n if (templates.length === 0) {\n return {\n name: 'default',\n textStyle: {\n fontSize: 40,\n fontWeight: 400,\n fontFamily: 'Arial, sans-serif',\n fill: 'rgb(255, 255, 255)',\n stroke: 'rgb(0, 0, 0)',\n strokeWidth: 4,\n lineHeight: 1.2,\n },\n };\n }\n\n if (templates.length === 1) {\n return templates[0]!;\n }\n\n return mergeFontTemplates(...templates);\n}\n"],"names":[],"mappings":"AASO,SAAS,sBAAsB,WAAyC;AAC7E,QAAM,SAAuB,EAAE,MAAM,SAAA;AAErC,aAAW,YAAY,WAAW;AAChC,QAAI,SAAS,WAAW;AACtB,aAAO,YAAY,EAAE,GAAG,OAAO,WAAW,GAAG,SAAS,UAAA;AAAA,IACxD;AACA,QAAI,SAAS,gBAAgB;AAC3B,aAAO,iBAAiB,EAAE,GAAG,OAAO,gBAAgB,GAAG,SAAS,eAAA;AAAA,IAClE;AACA,QAAI,SAAS,gBAAgB;AAC3B,aAAO,iBAAiB,EAAE,GAAG,OAAO,gBAAgB,GAAG,SAAS,eAAA;AAAA,IAClE;AAAA,EACF;AAEA,SAAO;AACT;AAEA,MAAM,WAAyB;AAAA,EAC7B,MAAM;AAAA,EACN,WAAW,EAAE,UAAU,GAAA;AACzB;AAEA,MAAM,WAAyB;AAAA,EAC7B,MAAM;AAAA,EACN,WAAW,EAAE,UAAU,GAAA;AACzB;AAEA,MAAM,WAAyB;AAAA,EAC7B,MAAM;AAAA,EACN,WAAW,EAAE,UAAU,GAAA;AACzB;AAEA,MAAM,WAAyB;AAAA,EAC7B,MAAM;AAAA,EACN,WAAW,EAAE,UAAU,GAAA;AACzB;AAEA,MAAM,WAAyB;AAAA,EAC7B,MAAM;AAAA,EACN,WAAW,EAAE,UAAU,GAAA;AACzB;AAEA,MAAM,SAAuB;AAAA,EAC3B,MAA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C,SAAS,eAAe,IAAI,CAAC,EAClC,OAAO,CAAC,MAAyB,MAAM,MAAS;AAEnD,MAAI,UAAU,WAAW,GAAG;AAC1B,WAAO;AAAA,MACL,MAAM;AAAA,MACN,WAAW;AAAA,QACT,UAAU;AAAA,QACV,YAAY;AAAA,QACZ,YAAY;AAAA,QACZ,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,aAAa;AAAA,QACb,YAAY;AAAA,MAAA;AAAA,IACd;AAAA,EAEJ;AAEA,MAAI,UAAU,WAAW,GAAG;AAC1B,WAAO,UAAU,CAAC;AAAA,EACpB;AAEA,SAAO,mBAAmB,GAAG,SAAS;AACxC;"}
1
+ {"version":3,"file":"font-templates.js","sources":["../../../../src/stages/compose/font-system/font-templates.ts"],"sourcesContent":["import type { TextStyle, ContainerStyle, GlobalPositionStyle } from './types';\n\nexport interface FontTemplate {\n name: string;\n textStyle?: Partial<TextStyle>;\n containerStyle?: Partial<ContainerStyle>;\n globalPosition?: Partial<GlobalPositionStyle>;\n}\n\nexport function mergeFontTemplates(...templates: FontTemplate[]): FontTemplate {\n const merged: FontTemplate = { name: 'merged' };\n\n for (const template of templates) {\n if (template.textStyle) {\n merged.textStyle = { ...merged.textStyle, ...template.textStyle };\n }\n if (template.containerStyle) {\n merged.containerStyle = { ...merged.containerStyle, ...template.containerStyle };\n }\n if (template.globalPosition) {\n merged.globalPosition = { ...merged.globalPosition, ...template.globalPosition };\n }\n }\n\n return merged;\n}\n\nconst normal30: FontTemplate = {\n name: 'normal-30',\n textStyle: { fontSize: 30 },\n};\n\nconst normal40: FontTemplate = {\n name: 'normal-40',\n textStyle: { fontSize: 40 },\n};\n\nconst normal50: FontTemplate = {\n name: 'normal-50',\n textStyle: { fontSize: 50 },\n};\n\nconst normal60: FontTemplate = {\n name: 'normal-60',\n textStyle: { fontSize: 60 },\n};\n\nconst normal80: FontTemplate = {\n name: 'normal-80',\n textStyle: { fontSize: 80 },\n};\n\nconst bold40: FontTemplate = {\n name: 'bold-40',\n textStyle: { fontWeight: 'bold', fontSize: 40 },\n};\n\nconst bold50: FontTemplate = {\n name: 'bold-50',\n textStyle: { fontWeight: 'bold', fontSize: 50 },\n};\n\nconst bold60: FontTemplate = {\n name: 'bold-60',\n textStyle: { fontWeight: 'bold', letterSpacing: '0.05em', fontSize: 60 },\n};\n\nconst fillBlack: FontTemplate = {\n name: 'fill-black',\n textStyle: { fill: 'rgb(0, 0, 0)' },\n};\n\nconst fillWhite: FontTemplate = {\n name: 'fill-white',\n textStyle: { fill: 'rgb(255, 255, 255)' },\n};\n\nconst fillYellow: FontTemplate = {\n name: 'fill-yellow',\n textStyle: { fill: 'rgb(255, 215, 0)' },\n};\n\nconst fillRed: FontTemplate = {\n name: 'fill-red',\n textStyle: { fill: 'rgb(255, 77, 77)' },\n};\n\nconst fillPink: FontTemplate = {\n name: 'fill-pink',\n textStyle: { fill: 'rgb(255, 192, 203)' },\n};\n\nconst strokeBlack: FontTemplate = {\n name: 'stroke-black',\n textStyle: {\n paintOrder: 'stroke',\n strokeLinejoin: 'round',\n strokeLinecap: 'round',\n stroke: 'rgb(0, 0, 0)',\n },\n};\n\nconst strokeWhite: FontTemplate = {\n name: 'stroke-white',\n textStyle: {\n paintOrder: 'stroke',\n strokeLinejoin: 'round',\n strokeLinecap: 'round',\n stroke: 'rgb(255, 255, 255)',\n },\n};\n\nconst strokeYellow: FontTemplate = {\n name: 'stroke-yellow',\n textStyle: {\n paintOrder: 'stroke',\n strokeLinejoin: 'round',\n strokeLinecap: 'round',\n stroke: 'rgb(255, 215, 0)',\n },\n};\n\nconst stroke0: FontTemplate = {\n name: 'stroke-0',\n textStyle: { strokeWidth: 0 },\n};\n\nconst stroke2: FontTemplate = {\n name: 'stroke-2',\n textStyle: { strokeWidth: 2 },\n};\n\nconst stroke4: FontTemplate = {\n name: 'stroke-4',\n textStyle: { strokeWidth: 4 },\n};\n\nconst stroke6: FontTemplate = {\n name: 'stroke-6',\n textStyle: { strokeWidth: 6 },\n};\n\nconst stroke8: FontTemplate = {\n name: 'stroke-8',\n textStyle: { strokeWidth: 8 },\n};\n\nconst stroke16: FontTemplate = {\n name: 'stroke-16',\n textStyle: { strokeWidth: 16 },\n};\n\nconst strokeBlack4 = mergeFontTemplates(strokeBlack, stroke4);\nstrokeBlack4.name = 'stroke-black-4';\n\nconst strokeBlack6 = mergeFontTemplates(strokeBlack, stroke6);\nstrokeBlack6.name = 'stroke-black-6';\n\nconst strokeBlack8 = mergeFontTemplates(strokeBlack, stroke8);\nstrokeBlack8.name = 'stroke-black-8';\n\nconst strokeBlack16 = mergeFontTemplates(strokeBlack, stroke16);\nstrokeBlack16.name = 'stroke-black-16';\n\nconst strokeWhite4 = mergeFontTemplates(strokeWhite, stroke4);\nstrokeWhite4.name = 'stroke-white-4';\n\nconst strokeWhite8 = mergeFontTemplates(strokeWhite, stroke8);\nstrokeWhite8.name = 'stroke-white-8';\n\nconst strokeYellow4 = mergeFontTemplates(strokeYellow, stroke4);\nstrokeYellow4.name = 'stroke-yellow-4';\n\nconst strokeYellow8 = mergeFontTemplates(strokeYellow, stroke8);\nstrokeYellow8.name = 'stroke-yellow-8';\n\nconst containerFull: FontTemplate = {\n name: 'container-full',\n containerStyle: { width: '100%' },\n};\n\nconst container60: FontTemplate = {\n name: 'container-60',\n containerStyle: { width: '60%' },\n};\n\nconst container80: FontTemplate = {\n name: 'container-80',\n containerStyle: { width: '80%' },\n};\n\nconst container95: FontTemplate = {\n name: 'container-95',\n containerStyle: { width: '95%' },\n};\n\nconst container98: FontTemplate = {\n name: 'container-98',\n containerStyle: { width: '98%' },\n};\n\nconst containerBlack: FontTemplate = {\n name: 'container-black',\n containerStyle: {\n backgroundColor: 'black',\n padding: '10px 10px 4px 10px',\n borderRadius: 10,\n width: '80%',\n },\n};\n\nconst containerWhite: FontTemplate = {\n name: 'container-white',\n containerStyle: {\n backgroundColor: 'white',\n padding: '10px 10px 4px 10px',\n borderRadius: 10,\n width: '80%',\n },\n};\n\nconst containerYellow: FontTemplate = {\n name: 'container-yellow',\n containerStyle: {\n backgroundColor: 'yellow',\n padding: '10px 10px 4px 10px',\n borderRadius: 10,\n width: '80%',\n },\n};\n\nconst containerBlackOpacity40: FontTemplate = {\n name: 'container-black-opacity-40',\n containerStyle: {\n backgroundColor: 'rgba(0, 0, 0, 0.4)',\n padding: '10px 10px 4px 10px',\n borderRadius: 10,\n width: '80%',\n },\n};\n\nconst globalCenter: FontTemplate = {\n name: 'global-center',\n globalPosition: {\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n },\n};\n\nconst globalHorizontalCenter: FontTemplate = {\n name: 'global-horizontal-center',\n globalPosition: {\n display: 'flex',\n justifyContent: 'center',\n },\n};\n\nconst globalTop5: FontTemplate = {\n name: 'global-top-5',\n globalPosition: {\n position: 'absolute',\n top: '5%',\n },\n};\n\nconst globalTop10: FontTemplate = {\n name: 'global-top-10',\n globalPosition: {\n position: 'absolute',\n top: '10%',\n },\n};\n\nconst globalTop20: FontTemplate = {\n name: 'global-top-20',\n globalPosition: {\n position: 'absolute',\n top: '20%',\n },\n};\n\nconst globalTop70: FontTemplate = {\n name: 'global-top-70',\n globalPosition: {\n position: 'absolute',\n top: '70%',\n },\n};\n\nconst globalTop80: FontTemplate = {\n name: 'global-top-80',\n globalPosition: {\n position: 'absolute',\n top: '80%',\n },\n};\n\nconst globalTop92: FontTemplate = {\n name: 'global-top-92',\n globalPosition: {\n position: 'absolute',\n top: '92%',\n },\n};\n\nconst globalBottom5: FontTemplate = {\n name: 'global-bottom-5',\n globalPosition: {\n position: 'absolute',\n bottom: '5%',\n },\n};\n\nconst globalBottom10: FontTemplate = {\n name: 'global-bottom-10',\n globalPosition: {\n position: 'absolute',\n bottom: '10%',\n },\n};\n\nconst globalBottom15: FontTemplate = {\n name: 'global-bottom-15',\n globalPosition: {\n position: 'absolute',\n bottom: '15%',\n },\n};\n\nconst yellowText = mergeFontTemplates(normal40, fillYellow, strokeBlack8);\nyellowText.name = 'yellowText';\n\nconst whiteText = mergeFontTemplates(normal40, fillWhite, strokeBlack8);\nwhiteText.name = 'whiteText';\n\nconst blackText = mergeFontTemplates(normal40, fillBlack, strokeWhite8);\nblackText.name = 'blackText';\n\nconst baseSubtitle = mergeFontTemplates(normal40, fillWhite, strokeBlack8, globalTop70);\nbaseSubtitle.name = 'baseSubtitle';\n\nconst baseSubtitleCenter = mergeFontTemplates(\n normal40,\n fillWhite,\n strokeBlack8,\n globalTop70,\n container60\n);\nbaseSubtitleCenter.name = 'baseSubtitleCenter';\n\nconst baseSubtitle16_9 = mergeFontTemplates(normal40, fillWhite, strokeBlack8, globalTop92);\nbaseSubtitle16_9.name = 'baseSubtitle16_9';\n\nconst yellowSubtitle = mergeFontTemplates(yellowText, globalTop70);\nyellowSubtitle.name = 'yellowSubtitle';\n\nconst whiteSubtitle = mergeFontTemplates(whiteText, globalTop70);\nwhiteSubtitle.name = 'whiteSubtitle';\n\nconst blackSubtitle = mergeFontTemplates(blackText, globalTop70);\nblackSubtitle.name = 'blackSubtitle';\n\nconst subtitleBackgroundBlack = mergeFontTemplates(\n normal40,\n fillWhite,\n globalTop70,\n containerBlack\n);\nsubtitleBackgroundBlack.name = 'subtitleBackgroundBlack';\n\nconst title = mergeFontTemplates(yellowText, bold50, globalTop5, container95);\ntitle.name = 'title';\n\nconst subtitle = mergeFontTemplates(normal30, fillWhite, strokeBlack8, globalTop5, container80);\nsubtitle.name = 'subtitle';\n\nexport const FONT_TEMPLATES: Record<string, FontTemplate> = {\n 'normal-30': normal30,\n 'normal-40': normal40,\n 'normal-50': normal50,\n 'normal-60': normal60,\n 'normal-80': normal80,\n 'bold-40': bold40,\n 'bold-50': bold50,\n 'bold-60': bold60,\n 'fill-black': fillBlack,\n 'fill-white': fillWhite,\n 'fill-yellow': fillYellow,\n 'fill-red': fillRed,\n 'fill-pink': fillPink,\n 'stroke-black': strokeBlack,\n 'stroke-white': strokeWhite,\n 'stroke-yellow': strokeYellow,\n 'stroke-0': stroke0,\n 'stroke-2': stroke2,\n 'stroke-4': stroke4,\n 'stroke-6': stroke6,\n 'stroke-8': stroke8,\n 'stroke-16': stroke16,\n 'stroke-black-4': strokeBlack4,\n 'stroke-black-6': strokeBlack6,\n 'stroke-black-8': strokeBlack8,\n 'stroke-black-16': strokeBlack16,\n 'stroke-white-4': strokeWhite4,\n 'stroke-white-8': strokeWhite8,\n 'stroke-yellow-4': strokeYellow4,\n 'stroke-yellow-8': strokeYellow8,\n 'container-full': containerFull,\n 'container-60': container60,\n 'container-80': container80,\n 'container-95': container95,\n 'container-98': container98,\n 'container-black': containerBlack,\n 'container-white': containerWhite,\n 'container-yellow': containerYellow,\n 'container-black-opacity-40': containerBlackOpacity40,\n 'global-center': globalCenter,\n 'global-horizontal-center': globalHorizontalCenter,\n 'global-top-5': globalTop5,\n 'global-top-10': globalTop10,\n 'global-top-20': globalTop20,\n 'global-top-70': globalTop70,\n 'global-top-80': globalTop80,\n 'global-top-92': globalTop92,\n 'global-bottom-5': globalBottom5,\n 'global-bottom-10': globalBottom10,\n 'global-bottom-15': globalBottom15,\n yellowText,\n whiteText,\n blackText,\n baseSubtitle,\n baseSubtitleCenter,\n baseSubtitle16_9,\n yellowSubtitle,\n whiteSubtitle,\n blackSubtitle,\n subtitleBackgroundBlack,\n title,\n subtitle,\n};\n\nexport function getTemplate(templateName: string): FontTemplate {\n const templateNames = templateName.split(' ').filter(Boolean);\n const templates = templateNames\n .map((name) => FONT_TEMPLATES[name])\n .filter((t): t is FontTemplate => t !== undefined);\n\n if (templates.length === 0) {\n return {\n name: 'default',\n textStyle: {\n fontSize: 40,\n fontWeight: 400,\n fontFamily: 'Arial, sans-serif',\n fill: 'rgb(255, 255, 255)',\n stroke: 'rgb(0, 0, 0)',\n strokeWidth: 8,\n lineHeight: 1.2,\n },\n };\n }\n\n if (templates.length === 1) {\n return templates[0]!;\n }\n\n return mergeFontTemplates(...templates);\n}\n"],"names":[],"mappings":"AASO,SAAS,sBAAsB,WAAyC;AAC7E,QAAM,SAAuB,EAAE,MA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,QAAQ;AAAA,QACR,aAAa;AAAA,QACb,YAAY;AAAA,MAAA;AAAA,IACd;AAAA,EAEJ;AAEA,MAAI,UAAU,WAAW,GAAG;AAC1B,WAAO,UAAU,CAAC;AAAA,EACpB;AAEA,SAAO,mBAAmB,GAAG,SAAS;AACxC;"}
@@ -893,13 +893,26 @@ class LayerRenderer {
893
893
  const { videoFrame, crop } = layer;
894
894
  const videoWidth = videoFrame.displayWidth || videoFrame.codedWidth;
895
895
  const videoHeight = videoFrame.displayHeight || videoFrame.codedHeight;
896
- const scaleX = this.width / videoWidth;
897
- const scaleY = this.height / videoHeight;
898
- const scale = Math.min(scaleX, scaleY);
899
- const renderWidth = Math.round(videoWidth * scale);
900
- const renderHeight = Math.round(videoHeight * scale);
901
- const renderX = Math.round((this.width - renderWidth) / 2);
902
- const renderY = Math.round((this.height - renderHeight) / 2);
896
+ const naturalScale = this.height / videoHeight;
897
+ const scaledWidth = videoWidth * naturalScale;
898
+ const scaledHeight = videoHeight * naturalScale;
899
+ const FILL_THRESHOLD = 0.9;
900
+ const shouldFill = scaledWidth / this.width > FILL_THRESHOLD && scaledHeight / this.height > FILL_THRESHOLD;
901
+ let renderWidth;
902
+ let renderHeight;
903
+ let renderX;
904
+ let renderY;
905
+ if (shouldFill) {
906
+ renderWidth = this.width;
907
+ renderHeight = this.height;
908
+ renderX = 0;
909
+ renderY = 0;
910
+ } else {
911
+ renderWidth = Math.round(scaledWidth);
912
+ renderHeight = Math.round(scaledHeight);
913
+ renderX = Math.round((this.width - renderWidth) / 2);
914
+ renderY = Math.round((this.height - renderHeight) / 2);
915
+ }
903
916
  if (crop) {
904
917
  this.ctx.drawImage(
905
918
  videoFrame,
@@ -956,9 +969,21 @@ class LayerRenderer {
956
969
  renderHeight = imgHeight;
957
970
  }
958
971
  } else {
959
- renderWidth = this.width;
960
- renderHeight = this.height;
972
+ const naturalScale = this.width / imgWidth;
973
+ const scaledWidth = imgWidth * naturalScale;
974
+ const scaledHeight = imgHeight * naturalScale;
975
+ const FILL_THRESHOLD = 0.9;
976
+ const shouldFill = scaledWidth / this.width > FILL_THRESHOLD && scaledHeight / this.height > FILL_THRESHOLD;
977
+ if (shouldFill) {
978
+ renderWidth = this.width;
979
+ renderHeight = this.height;
980
+ } else {
981
+ renderWidth = Math.round(scaledWidth);
982
+ renderHeight = Math.round(scaledHeight);
983
+ }
961
984
  }
985
+ const renderX = isAttachment ? 0 : Math.round((this.width - renderWidth) / 2);
986
+ const renderY = isAttachment ? 0 : Math.round((this.height - renderHeight) / 2);
962
987
  if (crop) {
963
988
  this.ctx.drawImage(
964
989
  source,
@@ -966,13 +991,13 @@ class LayerRenderer {
966
991
  crop.y,
967
992
  crop.width,
968
993
  crop.height,
969
- 0,
970
- 0,
994
+ renderX,
995
+ renderY,
971
996
  renderWidth,
972
997
  renderHeight
973
998
  );
974
999
  } else {
975
- this.ctx.drawImage(source, 0, 0, renderWidth, renderHeight);
1000
+ this.ctx.drawImage(source, renderX, renderY, renderWidth, renderHeight);
976
1001
  }
977
1002
  }
978
1003
  }
@@ -1457,6 +1482,8 @@ class VideoComposer {
1457
1482
  filterProcessor;
1458
1483
  frameDurationUs;
1459
1484
  // Cached frame duration
1485
+ fontsLoadingPromise = null;
1486
+ loadedFonts = /* @__PURE__ */ new Set();
1460
1487
  constructor(config) {
1461
1488
  this.config = this.applyDefaults(config);
1462
1489
  this.frameDurationUs = Math.round(1e6 / this.config.fps);
@@ -1485,7 +1512,7 @@ class VideoComposer {
1485
1512
  throw new Error("Failed to create 2D rendering context");
1486
1513
  }
1487
1514
  this.ctx.imageSmoothingEnabled = this.config.enableSmoothing;
1488
- this.loadFonts();
1515
+ this.fontsLoadingPromise = this.loadFonts();
1489
1516
  this.ctx.imageSmoothingQuality = "high";
1490
1517
  this.layerRenderer = new LayerRenderer(
1491
1518
  this.ctx,
@@ -1543,6 +1570,10 @@ class VideoComposer {
1543
1570
  return stream;
1544
1571
  }
1545
1572
  async composeFrame(request) {
1573
+ if (this.fontsLoadingPromise) {
1574
+ await this.fontsLoadingPromise;
1575
+ this.fontsLoadingPromise = null;
1576
+ }
1546
1577
  if (request.layers.length > this.config.maxLayers) {
1547
1578
  throw new Error(`Too many layers: ${request.layers.length} > ${this.config.maxLayers}`);
1548
1579
  }
@@ -1633,14 +1664,17 @@ class VideoComposer {
1633
1664
  return;
1634
1665
  }
1635
1666
  for (const font of this.config.fonts) {
1667
+ if (this.loadedFonts.has(font.family)) {
1668
+ continue;
1669
+ }
1636
1670
  try {
1637
1671
  const fontFace = new FontFace(font.family, `url(${font.url})`);
1638
- await fontFace.load();
1672
+ const loadedFont = await fontFace.load();
1639
1673
  if ("fonts" in self) {
1640
- self.fonts.add(fontFace);
1674
+ self.fonts.add(loadedFont);
1641
1675
  }
1642
- } catch (error) {
1643
- console.warn(`[VideoComposer] Failed to load font ${font.family}:`, error);
1676
+ this.loadedFonts.add(font.family);
1677
+ } catch {
1644
1678
  }
1645
1679
  }
1646
1680
  }
@@ -1659,7 +1693,7 @@ class VideoComposer {
1659
1693
  this.ctx.imageSmoothingEnabled = this.config.enableSmoothing;
1660
1694
  }
1661
1695
  if (config.fonts) {
1662
- this.loadFonts();
1696
+ this.fontsLoadingPromise = this.loadFonts();
1663
1697
  }
1664
1698
  }
1665
1699
  dispose() {
@@ -2432,4 +2466,4 @@ export {
2432
2466
  VideoComposeWorker,
2433
2467
  videoCompose_worker as default
2434
2468
  };
2435
- //# sourceMappingURL=video-compose.worker.Ckk8AtaQ.js.map
2469
+ //# sourceMappingURL=video-compose.worker.D_542rY_.js.map