chore: formatting
This commit is contained in:
parent
75eebf52bc
commit
a709af0059
|
|
@ -1,16 +1,16 @@
|
||||||
export function createOffscreenCanvas({
|
export function createOffscreenCanvas({
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
}: {
|
}: {
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
}): OffscreenCanvas | HTMLCanvasElement {
|
}): OffscreenCanvas | HTMLCanvasElement {
|
||||||
try {
|
try {
|
||||||
return new OffscreenCanvas(width, height);
|
return new OffscreenCanvas(width, height);
|
||||||
} catch {
|
} catch {
|
||||||
const canvas = document.createElement("canvas");
|
const canvas = document.createElement("canvas");
|
||||||
canvas.width = width;
|
canvas.width = width;
|
||||||
canvas.height = height;
|
canvas.height = height;
|
||||||
return canvas;
|
return canvas;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,10 @@ import { createOffscreenCanvas } from "../canvas-utils";
|
||||||
import { BlurBackgroundNode } from "../nodes/blur-background-node";
|
import { BlurBackgroundNode } from "../nodes/blur-background-node";
|
||||||
import { ColorNode } from "../nodes/color-node";
|
import { ColorNode } from "../nodes/color-node";
|
||||||
import { EffectLayerNode } from "../nodes/effect-layer-node";
|
import { EffectLayerNode } from "../nodes/effect-layer-node";
|
||||||
import { GraphicNode, type ResolvedGraphicNodeState } from "../nodes/graphic-node";
|
import {
|
||||||
|
GraphicNode,
|
||||||
|
type ResolvedGraphicNodeState,
|
||||||
|
} from "../nodes/graphic-node";
|
||||||
import { ImageNode } from "../nodes/image-node";
|
import { ImageNode } from "../nodes/image-node";
|
||||||
import { RootNode } from "../nodes/root-node";
|
import { RootNode } from "../nodes/root-node";
|
||||||
import { StickerNode } from "../nodes/sticker-node";
|
import { StickerNode } from "../nodes/sticker-node";
|
||||||
|
|
@ -367,7 +370,9 @@ function computeVisualTransform({
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function fullCanvasTransform(renderer: CanvasRenderer): QuadTransformDescriptor {
|
function fullCanvasTransform(
|
||||||
|
renderer: CanvasRenderer,
|
||||||
|
): QuadTransformDescriptor {
|
||||||
return {
|
return {
|
||||||
centerX: renderer.width / 2,
|
centerX: renderer.width / 2,
|
||||||
centerY: renderer.height / 2,
|
centerY: renderer.height / 2,
|
||||||
|
|
@ -425,7 +430,8 @@ function buildMaskArtifacts({
|
||||||
const shouldRenderMaskDirectly =
|
const shouldRenderMaskDirectly =
|
||||||
canRenderMaskDirectly &&
|
canRenderMaskDirectly &&
|
||||||
(!definition.renderer.buildPath ||
|
(!definition.renderer.buildPath ||
|
||||||
(mask.params.feather > 0 && definition.renderer.renderMaskHandlesFeather));
|
(mask.params.feather > 0 &&
|
||||||
|
definition.renderer.renderMaskHandlesFeather));
|
||||||
if (shouldRenderMaskDirectly && definition.renderer.renderMask) {
|
if (shouldRenderMaskDirectly && definition.renderer.renderMask) {
|
||||||
definition.renderer.renderMask({
|
definition.renderer.renderMask({
|
||||||
resolvedParams: mask.params,
|
resolvedParams: mask.params,
|
||||||
|
|
@ -437,11 +443,12 @@ function buildMaskArtifacts({
|
||||||
if (definition.renderer.renderMaskHandlesFeather) {
|
if (definition.renderer.renderMaskHandlesFeather) {
|
||||||
feather = 0;
|
feather = 0;
|
||||||
}
|
}
|
||||||
strokePath = definition.renderer.buildStrokePath?.({
|
strokePath =
|
||||||
resolvedParams: mask.params,
|
definition.renderer.buildStrokePath?.({
|
||||||
width: transform.width,
|
resolvedParams: mask.params,
|
||||||
height: transform.height,
|
width: transform.width,
|
||||||
}) ?? null;
|
height: transform.height,
|
||||||
|
}) ?? null;
|
||||||
} else {
|
} else {
|
||||||
if (!definition.renderer.buildPath) {
|
if (!definition.renderer.buildPath) {
|
||||||
return { mask: null, strokeLayer: null };
|
return { mask: null, strokeLayer: null };
|
||||||
|
|
@ -487,7 +494,10 @@ function buildMaskArtifacts({
|
||||||
});
|
});
|
||||||
|
|
||||||
let strokeLayer: FrameItemDescriptor | null = null;
|
let strokeLayer: FrameItemDescriptor | null = null;
|
||||||
if (mask.params.strokeWidth > 0 && (strokePath || definition.renderer.renderStroke)) {
|
if (
|
||||||
|
mask.params.strokeWidth > 0 &&
|
||||||
|
(strokePath || definition.renderer.renderStroke)
|
||||||
|
) {
|
||||||
const strokeCanvas = createOffscreenCanvas({
|
const strokeCanvas = createOffscreenCanvas({
|
||||||
width: Math.round(transform.width),
|
width: Math.round(transform.width),
|
||||||
height: Math.round(transform.height),
|
height: Math.round(transform.height),
|
||||||
|
|
@ -580,4 +590,3 @@ function drawTransformedCanvas({
|
||||||
ctx.drawImage(source, x, y, transform.width, transform.height);
|
ctx.drawImage(source, x, y, transform.width, transform.height);
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,11 @@ export function loadStickerSource({
|
||||||
image.src = url;
|
image.src = url;
|
||||||
});
|
});
|
||||||
|
|
||||||
return { source: image, width: image.naturalWidth, height: image.naturalHeight };
|
return {
|
||||||
|
source: image,
|
||||||
|
width: image.naturalWidth,
|
||||||
|
height: image.naturalHeight,
|
||||||
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
stickerSourceCache.set(stickerId, promise);
|
stickerSourceCache.set(stickerId, promise);
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,7 @@ import { BaseNode } from "./base-node";
|
||||||
import type { TextElement } from "@/timeline";
|
import type { TextElement } from "@/timeline";
|
||||||
import type { EffectPass } from "@/effects/types";
|
import type { EffectPass } from "@/effects/types";
|
||||||
import type { Transform } from "@/rendering";
|
import type { Transform } from "@/rendering";
|
||||||
import {
|
import { drawMeasuredTextLayout } from "@/text/primitives";
|
||||||
drawMeasuredTextLayout,
|
|
||||||
} from "@/text/primitives";
|
|
||||||
import type { MeasuredTextElement } from "@/text/measure-element";
|
import type { MeasuredTextElement } from "@/text/measure-element";
|
||||||
|
|
||||||
export type TextNodeParams = TextElement & {
|
export type TextNodeParams = TextElement & {
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,7 @@ export interface ResolvedVisualNodeState {
|
||||||
effectPasses: EffectPass[][];
|
effectPasses: EffectPass[][];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ResolvedVisualSourceNodeState
|
export interface ResolvedVisualSourceNodeState extends ResolvedVisualNodeState {
|
||||||
extends ResolvedVisualNodeState {
|
|
||||||
source: CanvasImageSource;
|
source: CanvasImageSource;
|
||||||
sourceWidth: number;
|
sourceWidth: number;
|
||||||
sourceHeight: number;
|
sourceHeight: number;
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,10 @@ import {
|
||||||
type BackdropSource,
|
type BackdropSource,
|
||||||
type ResolvedBlurBackgroundNodeState,
|
type ResolvedBlurBackgroundNodeState,
|
||||||
} from "./nodes/blur-background-node";
|
} from "./nodes/blur-background-node";
|
||||||
import { EffectLayerNode, type ResolvedEffectLayerNodeState } from "./nodes/effect-layer-node";
|
import {
|
||||||
|
EffectLayerNode,
|
||||||
|
type ResolvedEffectLayerNodeState,
|
||||||
|
} from "./nodes/effect-layer-node";
|
||||||
import {
|
import {
|
||||||
GraphicNode,
|
GraphicNode,
|
||||||
type ResolvedGraphicNodeState,
|
type ResolvedGraphicNodeState,
|
||||||
|
|
@ -232,7 +235,10 @@ async function resolveImageNode({
|
||||||
node: ImageNode;
|
node: ImageNode;
|
||||||
context: ResolveContext;
|
context: ResolveContext;
|
||||||
}): Promise<ResolvedVisualSourceNodeState | null> {
|
}): Promise<ResolvedVisualSourceNodeState | null> {
|
||||||
const source = await loadImageSource(node.params.url, node.params.maxSourceSize);
|
const source = await loadImageSource(
|
||||||
|
node.params.url,
|
||||||
|
node.params.maxSourceSize,
|
||||||
|
);
|
||||||
const visualState = resolveVisualState({
|
const visualState = resolveVisualState({
|
||||||
params: node.params,
|
params: node.params,
|
||||||
context,
|
context,
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,9 @@ export class SceneExporter extends EventEmitter<SceneExporterEvents> {
|
||||||
}): Promise<ArrayBuffer | null> {
|
}): Promise<ArrayBuffer | null> {
|
||||||
const fps = this.renderer.fps;
|
const fps = this.renderer.fps;
|
||||||
const fpsFloat = frameRateToFloat(fps);
|
const fpsFloat = frameRateToFloat(fps);
|
||||||
const ticksPerFrame = Math.round(TICKS_PER_SECOND * fps.denominator / fps.numerator);
|
const ticksPerFrame = Math.round(
|
||||||
|
(TICKS_PER_SECOND * fps.denominator) / fps.numerator,
|
||||||
|
);
|
||||||
const frameCount = Math.floor(rootNode.duration / ticksPerFrame);
|
const frameCount = Math.floor(rootNode.duration / ticksPerFrame);
|
||||||
|
|
||||||
const outputFormat =
|
const outputFormat =
|
||||||
|
|
@ -106,8 +108,7 @@ export class SceneExporter extends EventEmitter<SceneExporterEvents> {
|
||||||
|
|
||||||
let audioSource: AudioBufferSource | null = null;
|
let audioSource: AudioBufferSource | null = null;
|
||||||
if (this.shouldIncludeAudio && this.audioBuffer) {
|
if (this.shouldIncludeAudio && this.audioBuffer) {
|
||||||
let audioCodec: "aac" | "opus" =
|
let audioCodec: "aac" | "opus" = this.format === "webm" ? "opus" : "aac";
|
||||||
this.format === "webm" ? "opus" : "aac";
|
|
||||||
|
|
||||||
if (audioCodec === "aac" && typeof AudioEncoder !== "undefined") {
|
if (audioCodec === "aac" && typeof AudioEncoder !== "undefined") {
|
||||||
const { supported } = await AudioEncoder.isConfigSupported({
|
const { supported } = await AudioEncoder.isConfigSupported({
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue