@bluepic/embed 0.6.25 → 0.6.27
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.
- package/dist/bluepic-embed.iife.js +101 -101
- package/dist/bluepic-embed.umd.js +101 -101
- package/dist/main.cjs +24 -24
- package/dist/main.mjs +1990 -1290
- package/dist/style.css +1 -1
- package/dist/util/export.d.ts +9 -1
- package/dist/util/gif/GifEncoderSink.d.ts +24 -0
- package/dist/util/gif/encodeCore.d.ts +36 -0
- package/dist/util/gif/exportGifLocal.d.ts +45 -0
- package/dist/util/gif/gifEncoder.worker.d.ts +1 -0
- package/dist/util/gif/sandboxGif.d.ts +37 -0
- package/package.json +2 -1
package/dist/util/export.d.ts
CHANGED
|
@@ -25,6 +25,14 @@ export declare const videoFormats: {
|
|
|
25
25
|
mp4: "video/mp4";
|
|
26
26
|
mov: "video/quicktime";
|
|
27
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* GIF: rendered frame by frame like a video (local first, server as the
|
|
30
|
+
* fallback), delivered and billed like an image. A template without animated
|
|
31
|
+
* GIFs becomes a one-frame GIF.
|
|
32
|
+
*/
|
|
33
|
+
export declare const gifFormats: {
|
|
34
|
+
gif: "image/gif";
|
|
35
|
+
};
|
|
28
36
|
export type RenderRemoteOptions = {
|
|
29
37
|
apiBaseUrl: string;
|
|
30
38
|
env: 'dev' | 'prod';
|
|
@@ -33,7 +41,7 @@ export type RenderRemoteOptions = {
|
|
|
33
41
|
};
|
|
34
42
|
export declare function renderSerialRemote(campaignId: number, templateId: string, data: {
|
|
35
43
|
[k: string]: unknown;
|
|
36
|
-
}, width: number, height: number, framesX: number, framesY: number, format: keyof typeof imageFormats, opts: RenderRemoteOptions,
|
|
44
|
+
}, width: number, height: number, framesX: number, framesY: number, format: keyof typeof imageFormats | keyof typeof gifFormats, opts: RenderRemoteOptions,
|
|
37
45
|
/**
|
|
38
46
|
* Multi-canvas templates (canvases v2): the canvas to render. The server
|
|
39
47
|
* refetches the persisted serial (root = Default canvas) by templateId, so
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collects frames into a GIF. Encodes in a Web Worker when the page allows one
|
|
3
|
+
* (pipelined with rendering), otherwise on the main thread — a strict CSP
|
|
4
|
+
* `worker-src` on a customer page must not break the export, only slow it.
|
|
5
|
+
*/
|
|
6
|
+
export declare class GifEncoderSink {
|
|
7
|
+
private worker?;
|
|
8
|
+
private local?;
|
|
9
|
+
private inFlight;
|
|
10
|
+
private drainWaiters;
|
|
11
|
+
private failure?;
|
|
12
|
+
private donePromise?;
|
|
13
|
+
private resolveDone?;
|
|
14
|
+
private rejectDone?;
|
|
15
|
+
readonly mode: 'worker' | 'main-thread';
|
|
16
|
+
private constructor();
|
|
17
|
+
static create(repeat: number): Promise<GifEncoderSink>;
|
|
18
|
+
private handle;
|
|
19
|
+
private fail;
|
|
20
|
+
/** Queues one frame. `rgba` is taken over (transferred) — do not reuse it. */
|
|
21
|
+
addFrame(rgba: Uint8ClampedArray, width: number, height: number, delayMs: number): Promise<void>;
|
|
22
|
+
finish(): Promise<Blob>;
|
|
23
|
+
dispose(): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One GIF stream, frame by frame. Shared by the encoder worker and the
|
|
3
|
+
* main-thread fallback so both produce byte-identical files.
|
|
4
|
+
*
|
|
5
|
+
* Every frame gets its own 256-colour palette (local colour table) and covers
|
|
6
|
+
* the whole canvas. Frames with transparent pixels use 1-bit alpha (GIF has no
|
|
7
|
+
* soft alpha); every frame is disposed to background so the previous one
|
|
8
|
+
* never shows through a transparent pixel.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createGifWriter(repeat: number): {
|
|
11
|
+
addFrame(rgba: Uint8ClampedArray | Uint8Array, width: number, height: number, delayMs: number): void;
|
|
12
|
+
finish(): Uint8Array;
|
|
13
|
+
};
|
|
14
|
+
export type GifWorkerRequest = {
|
|
15
|
+
type: 'start';
|
|
16
|
+
repeat: number;
|
|
17
|
+
} | {
|
|
18
|
+
type: 'frame';
|
|
19
|
+
rgba: ArrayBuffer;
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
delayMs: number;
|
|
23
|
+
} | {
|
|
24
|
+
type: 'finish';
|
|
25
|
+
};
|
|
26
|
+
export type GifWorkerResponse = {
|
|
27
|
+
type: 'ready';
|
|
28
|
+
} | {
|
|
29
|
+
type: 'ack';
|
|
30
|
+
} | {
|
|
31
|
+
type: 'done';
|
|
32
|
+
bytes: ArrayBuffer;
|
|
33
|
+
} | {
|
|
34
|
+
type: 'error';
|
|
35
|
+
message: string;
|
|
36
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type GifExportTimeline, type SandboxEvaluator } from './sandboxGif';
|
|
2
|
+
/** The slice of BxLiveTemplate's API a GIF export needs. */
|
|
3
|
+
export type GifExportLiveTemplate = SandboxEvaluator & {
|
|
4
|
+
render(options: {
|
|
5
|
+
type: 'image/png';
|
|
6
|
+
resolution: number;
|
|
7
|
+
quality: number;
|
|
8
|
+
vectorExportOptions?: {
|
|
9
|
+
mode: 'optimized' | 'raw';
|
|
10
|
+
keepGroupTransforms: boolean;
|
|
11
|
+
rasterizeAllMasks: boolean;
|
|
12
|
+
vectorizeAllTexts: boolean;
|
|
13
|
+
};
|
|
14
|
+
watermark: boolean;
|
|
15
|
+
resultType: 'canvas';
|
|
16
|
+
externalCanvas: HTMLCanvasElement | null;
|
|
17
|
+
svgLoadWaitDelay?: number;
|
|
18
|
+
}): Promise<HTMLCanvasElement>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Stepped GIF frames reach the rasterizer as data: URIs, and exportSVGDocument
|
|
22
|
+
* caches every image by its URL for the life of the page. Dropped after an
|
|
23
|
+
* export so a long one does not keep every frame in memory.
|
|
24
|
+
*/
|
|
25
|
+
export declare function purgeInlinedFrames(): void;
|
|
26
|
+
export type LocalGifExportResult = {
|
|
27
|
+
blob: Blob;
|
|
28
|
+
timeline: GifExportTimeline;
|
|
29
|
+
encoder: 'worker' | 'main-thread';
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Exports the live template as a GIF in the browser.
|
|
33
|
+
*
|
|
34
|
+
* The sandbox decides the timeline (core's kgV of the GIF lengths, frames only
|
|
35
|
+
* where a GIF changes, <= 10 fps). For every frame the sandbox is moved to its
|
|
36
|
+
* time and waited on until each GIF painted the right frame, then the canvas is
|
|
37
|
+
* rendered exactly like a PNG export and handed to the encoder, which works in
|
|
38
|
+
* a worker while the next frame renders. A template without animated GIFs —
|
|
39
|
+
* or on a core older than 0.6.3 — becomes a one-frame GIF.
|
|
40
|
+
*/
|
|
41
|
+
export declare function exportGifLocal(liveTemplate: GifExportLiveTemplate, options: {
|
|
42
|
+
watermark: boolean;
|
|
43
|
+
svgLoadWaitDelay?: number;
|
|
44
|
+
onProgress?: (progress: number) => void;
|
|
45
|
+
}): Promise<LocalGifExportResult>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sandbox side of GIF export (core >= 0.6.3, see bluepic-core
|
|
3
|
+
* src/serial/__default__/src/App.vue): `bx_gif_timeline`, `bx_set_gif_stepping`,
|
|
4
|
+
* `bx_gif_settle`. Older sandboxes have none of it — every helper here then
|
|
5
|
+
* degrades to "one still frame" instead of failing.
|
|
6
|
+
*
|
|
7
|
+
* NB: the arrows below are shipped as SOURCE TEXT through `evaluate()`, so
|
|
8
|
+
* they must stay self-contained — no helper, no import, no named inner
|
|
9
|
+
* function (see util/imageStates/probe.ts).
|
|
10
|
+
*/
|
|
11
|
+
export type SandboxEvaluator = {
|
|
12
|
+
evaluate(func: Function, ...args: string[]): Promise<unknown>;
|
|
13
|
+
};
|
|
14
|
+
export type GifExportTimeline = {
|
|
15
|
+
durationMs: number;
|
|
16
|
+
frames: {
|
|
17
|
+
timeMs: number;
|
|
18
|
+
delayMs: number;
|
|
19
|
+
}[];
|
|
20
|
+
loop: boolean;
|
|
21
|
+
capped: boolean;
|
|
22
|
+
naturalDurationMs: number | null;
|
|
23
|
+
gifCount: number;
|
|
24
|
+
ownTimeline: boolean;
|
|
25
|
+
};
|
|
26
|
+
/** What a template without animated GIFs (or an old sandbox) exports: one still. */
|
|
27
|
+
export declare const STILL_TIMELINE: GifExportTimeline;
|
|
28
|
+
export declare function sandboxSupportsGifExport(sandbox: SandboxEvaluator): Promise<boolean>;
|
|
29
|
+
export declare function readGifTimeline(sandbox: SandboxEvaluator): Promise<GifExportTimeline>;
|
|
30
|
+
/**
|
|
31
|
+
* Switches the sandbox's GIFs to follow TIME (`true`) or back to the browser's
|
|
32
|
+
* own animation (`false`). Remembers and restores the TIME the sandbox had, so
|
|
33
|
+
* the editor's preview is left exactly as it was.
|
|
34
|
+
*/
|
|
35
|
+
export declare function setGifStepping(sandbox: SandboxEvaluator, on: boolean): Promise<void>;
|
|
36
|
+
/** Moves the sandbox to `seconds` and resolves once every GIF shows its frame for it. */
|
|
37
|
+
export declare function seekSandboxTime(sandbox: SandboxEvaluator, seconds: number): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bluepic/embed",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.27",
|
|
4
4
|
"description": "Bluepic embed sdk",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -90,6 +90,7 @@
|
|
|
90
90
|
"detect-browser": "^5.3.0",
|
|
91
91
|
"downloadjs": "^1.4.7",
|
|
92
92
|
"fontkit": "^2.0.4",
|
|
93
|
+
"gifenc": "^1.0.3",
|
|
93
94
|
"highlight.js": "^11.11.1",
|
|
94
95
|
"inline-style-parser": "^0.2.7",
|
|
95
96
|
"markdown-it": "^15.0.0",
|