@taole/giftstage 0.1.28 → 0.1.30

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.
Files changed (74) hide show
  1. package/README.md +89 -36
  2. package/dist/core/audio-manager.d.ts +19 -0
  3. package/dist/core/gift-stage.d.ts +117 -0
  4. package/dist/core/index.d.ts +4 -0
  5. package/dist/core/post-animator.d.ts +43 -0
  6. package/dist/core/render-manager.d.ts +99 -0
  7. package/dist/core/webcodecs-video-atlas.d.ts +30 -0
  8. package/dist/gift-stage.cjs.js +225 -225
  9. package/dist/gift-stage.es.js +2537 -2062
  10. package/dist/gpu/detect.d.ts +2 -0
  11. package/dist/gpu/gl-utils.d.ts +10 -0
  12. package/dist/gpu/index.d.ts +3 -0
  13. package/dist/gpu/webgl1-backend.d.ts +43 -0
  14. package/dist/gpu/webgl2-backend.d.ts +69 -0
  15. package/dist/gpu/webgpu-backend.d.ts +155 -0
  16. package/dist/index.d.ts +27 -0
  17. package/dist/parsers/atlas-builder.d.ts +37 -0
  18. package/dist/parsers/atlas-packing.d.ts +31 -0
  19. package/dist/parsers/index.d.ts +7 -0
  20. package/dist/parsers/inflate-js.d.ts +37 -0
  21. package/dist/parsers/svga-image-decode-worker-client.d.ts +14 -0
  22. package/dist/parsers/svga-parser-worker-client.d.ts +31 -0
  23. package/dist/parsers/svga-parser.d.ts +49 -0
  24. package/dist/parsers/svga-proto-js.d.ts +7 -0
  25. package/dist/parsers/svga-sprite-table-binary.d.ts +36 -0
  26. package/dist/parsers/svga-sprite-table.d.ts +59 -0
  27. package/dist/parsers/svga-worker-payload-binary.d.ts +10 -0
  28. package/dist/parsers/vap-config-parser.d.ts +20 -0
  29. package/dist/renderers/alpha-video-renderer.d.ts +48 -0
  30. package/dist/renderers/image-renderer.d.ts +13 -0
  31. package/dist/renderers/index.d.ts +4 -0
  32. package/dist/renderers/svga-batch-renderer.d.ts +113 -0
  33. package/dist/renderers/vap-renderer.d.ts +58 -0
  34. package/dist/renderers/vertex-builder.d.ts +5 -0
  35. package/dist/shaders/index.d.ts +49 -0
  36. package/dist/types/index.d.ts +699 -0
  37. package/dist/utils/abort.d.ts +3 -0
  38. package/dist/utils/atlas-constants.d.ts +9 -0
  39. package/dist/utils/buffer-pool.d.ts +14 -0
  40. package/dist/utils/canvas-dpr.d.ts +37 -0
  41. package/dist/utils/clip-mesh.d.ts +6 -0
  42. package/dist/utils/detect.d.ts +7 -0
  43. package/dist/utils/easing.d.ts +7 -0
  44. package/dist/utils/frame-budget.d.ts +36 -0
  45. package/dist/utils/gift-object-fit.d.ts +14 -0
  46. package/dist/utils/gift-position.d.ts +5 -0
  47. package/dist/utils/gift-size.d.ts +11 -0
  48. package/dist/utils/gift-transform.d.ts +29 -0
  49. package/dist/utils/html-video-upload-gate.d.ts +35 -0
  50. package/dist/utils/image-source.d.ts +9 -0
  51. package/dist/utils/math.d.ts +9 -0
  52. package/dist/utils/resource-cache.d.ts +20 -0
  53. package/dist/utils/slot-content.d.ts +17 -0
  54. package/dist/utils/svg-path-parser.d.ts +11 -0
  55. package/dist/utils/svga-binary-cache.d.ts +26 -0
  56. package/dist/utils/svga-work-scheduler.d.ts +7 -0
  57. package/dist/utils/triangulate.d.ts +11 -0
  58. package/dist/utils/utf8.d.ts +2 -0
  59. package/dist/utils/vap-mix-composer.d.ts +26 -0
  60. package/dist/utils/wc-atlas-upload-size.d.ts +9 -0
  61. package/dist/video/mp4box-loader.d.ts +2 -0
  62. package/dist/video/webcodecs-mp4-core.d.ts +49 -0
  63. package/dist/video/webcodecs-mp4-playback.d.ts +71 -0
  64. package/dist/video/webcodecs-mp4.worker.d.ts +18 -0
  65. package/dist/wasm/wasm-bridge.d.ts +36 -0
  66. package/dist/workers/parser-worker.d.ts +13 -0
  67. package/dist/workers/svga-atlas-worker-client.d.ts +25 -0
  68. package/dist/workers/svga-atlas-worker.d.ts +37 -0
  69. package/dist/workers/svga-clip-worker-client.d.ts +6 -0
  70. package/dist/workers/svga-clip-worker.d.ts +17 -0
  71. package/dist/workers/svga-image-decode-worker.d.ts +19 -0
  72. package/dist/workers/vertex-worker.d.ts +15 -0
  73. package/dist/workers/worker-scheduler.d.ts +19 -0
  74. package/package.json +7 -5
@@ -0,0 +1,20 @@
1
+ import type { VAPConfig, VAPFrameItem } from '../types';
2
+ export declare function parseVAPConfig(config: string | object): Promise<VAPConfig>;
3
+ export declare function getVAPFrame(config: VAPConfig, frameIndex: number): VAPFrameItem | undefined;
4
+ /**
5
+ * Logical content size for layout/aspect (matches visible RGB frame, not full mp4 frame).
6
+ * `videoW`/`videoH` often include separate alpha bands; use `w`/`h` or `rgbFrame` w×h.
7
+ */
8
+ export declare function getVAPContentSize(info: VAPConfig['info']): {
9
+ w: number;
10
+ h: number;
11
+ };
12
+ /**
13
+ * Compute normalized UV coordinates for a frame region within the video texture.
14
+ */
15
+ export declare function computeVAPUV(region: [number, number, number, number], videoW: number, videoH: number): {
16
+ left: number;
17
+ right: number;
18
+ top: number;
19
+ bottom: number;
20
+ };
@@ -0,0 +1,48 @@
1
+ import type { GPUBackend, GiftSlot } from '../types';
2
+ export declare class AlphaVideoRenderer {
3
+ private quadVB;
4
+ private quadIB;
5
+ /** Packed rect + atlas remap + opacity per instance (WebGPU + WebGL2 instanced path). */
6
+ private instancePackScratch;
7
+ private projCacheW;
8
+ private projCacheH;
9
+ private projCache;
10
+ private scratchTransform;
11
+ private readonly contentSizeScratch;
12
+ private readonly layoutScratch;
13
+ private readonly wcDbgFirstDraw;
14
+ private readonly wcDbgNullWarns;
15
+ private readonly htmlGate;
16
+ private readonly lastWcFrameRef;
17
+ private readonly scratchAtlasRemap;
18
+ private readonly processedHtmlGatesScratch;
19
+ private readonly instancedTexturesScratch;
20
+ private readonly instancedUniformsScratch;
21
+ private readonly instancedDrawCommand;
22
+ private readonly geometryTexturesScratch;
23
+ private readonly geometryUniformsScratch;
24
+ private readonly geometryDrawCommand;
25
+ private static alphaVideoContentSize;
26
+ private static readonly QUAD_VERTS;
27
+ private static readonly QUAD_INDICES;
28
+ syncVideoTextures(backend: GPUBackend, slots: Map<string, GiftSlot>): boolean;
29
+ draw(backend: GPUBackend, slots: Map<string, GiftSlot>): void;
30
+ drawSlot(backend: GPUBackend, slot: GiftSlot): void;
31
+ /**
32
+ * Emit consecutive texture batches without allocating per-frame lists or maps.
33
+ * RenderManager already groups normal runs by texture/object-fit; preserving input order also keeps
34
+ * the public renderer correct when callers provide mixed textures or cover slots.
35
+ * WebGPU: `drawIndexed` instance path; WebGL2: `drawElementsInstanced` + instance vertex attributes.
36
+ */
37
+ private drawInstancedAlphaBatches;
38
+ private flushInstancedBatch;
39
+ /** Writes rect + atlas remap + opacity at `floatOffset` into `out`. */
40
+ private fillAlphaInstanceData;
41
+ releaseHtmlVideo(slot: GiftSlot): void;
42
+ clearWebCodecsFrameRef(slotId: string): void;
43
+ private getHtmlVideoGateId;
44
+ private drawGeometry;
45
+ private ensureQuadBuffers;
46
+ private getProjection;
47
+ destroy(backend: GPUBackend): void;
48
+ }
@@ -0,0 +1,13 @@
1
+ import type { GPUBackend, GiftSlot } from '../types';
2
+ export declare class ImageRenderer {
3
+ private quadVB;
4
+ private quadIB;
5
+ private readonly scratchTransform;
6
+ private projCacheW;
7
+ private projCacheH;
8
+ private projCache;
9
+ private static readonly QUAD_VERTS;
10
+ private static readonly QUAD_INDICES;
11
+ drawSlot(backend: GPUBackend, slot: GiftSlot): void;
12
+ destroy(backend: GPUBackend): void;
13
+ }
@@ -0,0 +1,4 @@
1
+ export { SVGABatchRenderer } from './svga-batch-renderer';
2
+ export { VAPRenderer } from './vap-renderer';
3
+ export { AlphaVideoRenderer } from './alpha-video-renderer';
4
+ export { buildBatchVerticesJS } from './vertex-builder';
@@ -0,0 +1,113 @@
1
+ import type { GPUBackend, GPUBufferHandle, GiftSlot, VideoEntity } from '../types';
2
+ export interface ClipMeshCache {
3
+ vertices: Float32Array;
4
+ indices: Uint32Array;
5
+ /**
6
+ * Axis-aligned rectangle in local SVGA space when the clip mesh is a simple quad
7
+ * (scissor fast path). `undefined` = not yet analyzed, `null` = not a rectangle.
8
+ */
9
+ rect?: {
10
+ x: number;
11
+ y: number;
12
+ w: number;
13
+ h: number;
14
+ } | null;
15
+ /** Lazily created static GPU buffers (local-space vertices, transformed via u_transform). */
16
+ vertexBuf?: GPUBufferHandle | null;
17
+ indexBuf?: GPUBufferHandle | null;
18
+ }
19
+ interface SVGAClipPrewarmOptions {
20
+ frameBudgetMs?: number;
21
+ workerTimeSliceMs?: number;
22
+ checkActive?: () => void;
23
+ useWorker?: boolean;
24
+ signal?: AbortSignal;
25
+ }
26
+ export type SVGAClipMeshMap = Map<string, ClipMeshCache>;
27
+ export declare class SVGABatchRenderer {
28
+ private static readonly INSTANCED_QUAD_VERTS;
29
+ private static readonly INSTANCED_QUAD_INDICES;
30
+ private pool;
31
+ private vertexBufHandles;
32
+ private indexBufHandles;
33
+ private clipSpriteVertBufHandles;
34
+ private clipSpriteIdxBufHandles;
35
+ private batchDrawCursor;
36
+ private clipSpriteDrawCursor;
37
+ private canvasWidth;
38
+ private canvasHeight;
39
+ private projCacheW;
40
+ private projCacheH;
41
+ private projCache;
42
+ private clipMeshCache;
43
+ /** Meshes with lazily created GPU buffers (released in destroy). */
44
+ private clipMeshesWithBuffers;
45
+ private clipFrameDataScratch;
46
+ private instancedFrameDataScratch;
47
+ private clipSpriteVertsScratch;
48
+ private clipSpriteIndicesScratch;
49
+ private shapeVertsScratch;
50
+ private instancedQuadVB;
51
+ private instancedQuadIB;
52
+ private whiteTexture;
53
+ private shapeMeshCache;
54
+ /** Column-major mat4 scratch for clip-mask u_transform (uploaded synchronously per draw). */
55
+ private clipTransformMat;
56
+ /** Scissor rect of the slot currently being drawn (canvas pixels), for clip intersection/restore. */
57
+ private slotScissor;
58
+ /** Grow-only SpriteWork pool; cursor resets each flushGroup. */
59
+ private spriteWorkPool;
60
+ private spriteWorkCursor;
61
+ /** Reused scratch arrays (consumed synchronously). */
62
+ private batchSpritesScratch;
63
+ private drawGroupScratch;
64
+ /** Per-entity result of the "any frame has shapes" scan (no-atlas render check). */
65
+ private entityHasShapesCache;
66
+ private readonly affineScratch;
67
+ beginFrame(backend: GPUBackend): void;
68
+ flush(backend: GPUBackend, slots: Map<string, GiftSlot>): void;
69
+ drawSlot(backend: GPUBackend, slot: GiftSlot): void;
70
+ drawSlots(backend: GPUBackend, slots: Iterable<GiftSlot>): void;
71
+ prewarmClipMeshes(entity: Pick<VideoEntity, 'spriteTable'>, options?: SVGAClipPrewarmOptions): Promise<number>;
72
+ hydrateClipMeshes(meshes: SVGAClipMeshMap | null | undefined): void;
73
+ snapshotClipMeshes(entity: Pick<VideoEntity, 'spriteTable'>): SVGAClipMeshMap;
74
+ private flushGroup;
75
+ private acquireSpriteWork;
76
+ /** Drop object references so removed slots/entities are not retained by the pool. */
77
+ private releaseSpriteWorks;
78
+ private getProjection;
79
+ private drawBatch;
80
+ private drawBatchInstancedWebGL;
81
+ private drawClippedSprite;
82
+ /** Rect clip in canvas space intersected with the slot scissor. Returns false when fully clipped. */
83
+ private applyClipRectScissor;
84
+ private restoreSlotScissor;
85
+ private getClipRect;
86
+ private ensureClipMeshBuffers;
87
+ private packClipTransform;
88
+ private drawSingleSprite;
89
+ private clearClipStencil;
90
+ private rotateTransform;
91
+ private packFrameData;
92
+ /** Resolve atlas/override texture into a pooled SpriteWork entry. Returns false when missing. */
93
+ private resolveSpriteTextureInto;
94
+ private drawShapeFrame;
95
+ private hasAtlasTexture;
96
+ private hasRenderableSVGA;
97
+ private getWhiteTexture;
98
+ private getShapeMesh;
99
+ private appendShape;
100
+ private buildShapeSubPaths;
101
+ private appendFill;
102
+ private appendStroke;
103
+ private clamp01;
104
+ private cleanupPoints;
105
+ private getClipMesh;
106
+ private ensureVertexBuffer;
107
+ private ensureIndexBuffer;
108
+ private ensureClipSpriteVertexBuffer;
109
+ private ensureClipSpriteIndexBuffer;
110
+ private ensureInstancedQuadBuffers;
111
+ destroy(backend: GPUBackend): void;
112
+ }
113
+ export {};
@@ -0,0 +1,58 @@
1
+ import type { GPUBackend, GiftSlot } from '../types';
2
+ export declare class VAPRenderer {
3
+ private instancedQuadVB;
4
+ private instancedQuadIB;
5
+ private quadVB;
6
+ private quadIB;
7
+ private rgbaWebGLQuadVB;
8
+ private rgbaTopLeftQuadVB;
9
+ private rgbaQuadIB;
10
+ private readonly wcDbgFirstDraw;
11
+ private readonly wcDbgNullWarns;
12
+ private readonly htmlGate;
13
+ /** Skip GPU upload when `getFrameForTime` returns the same `VideoFrame` instance (rAF > clip FPS). */
14
+ private readonly lastWcFrameRef;
15
+ private readonly scratchAtlasRemap;
16
+ private instancePackScratch;
17
+ private scratchTransform;
18
+ private readonly processedHtmlGatesScratch;
19
+ private readonly vapVertexScratch;
20
+ private projCacheW;
21
+ private projCacheH;
22
+ private projCache;
23
+ private static readonly QUAD_VERTS;
24
+ /**
25
+ * WebGL canvas/image uploads keep the classic texture-origin mismatch, so we still need
26
+ * the vertically flipped UVs here.
27
+ */
28
+ private static readonly RGBA_QUAD_VERTS_WEBGL;
29
+ /**
30
+ * WebGPU `copyExternalImageToTexture` uses top-left image origin, so mixed RGBA canvases
31
+ * should sample without the extra vertical flip.
32
+ */
33
+ private static readonly RGBA_QUAD_VERTS_WEBGPU;
34
+ private static readonly QUAD_INDICES;
35
+ /**
36
+ * Upload video frames **before** `beginFrame` so WebGPU queue copies complete before the render pass
37
+ * (avoids subtle ordering / starvation when many videos update in one rAF).
38
+ */
39
+ syncVideoTextures(backend: GPUBackend, slots: Map<string, GiftSlot>): boolean;
40
+ draw(backend: GPUBackend, slots: Map<string, GiftSlot>): void;
41
+ drawSlot(backend: GPUBackend, slot: GiftSlot): void;
42
+ /**
43
+ * Group by shared `videoTextureHandle` (atlas or same texture), one instanced draw per group.
44
+ */
45
+ private drawInstancedVapBatches;
46
+ /** mat4 + atlasRemap + rgb/alpha UV rects (`computeVAPUV` order). */
47
+ private fillVapInstanceData;
48
+ private syncMixedTexture;
49
+ releaseHtmlVideo(slot: GiftSlot): void;
50
+ clearWebCodecsFrameRef(slotId: string): void;
51
+ private drawGeometry;
52
+ private drawMixedGeometry;
53
+ private drawMixedDirectGeometry;
54
+ private ensureBuffer;
55
+ destroy(backend: GPUBackend): void;
56
+ private getMixedFrameIndex;
57
+ private getHtmlVideoGateId;
58
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Pure JS port of Unity BuildBatchMeshJob.Execute() and WASM build_batch_vertices().
3
+ * Used as fallback when WASM is unavailable or on main thread.
4
+ */
5
+ export declare function buildBatchVerticesJS(frames: Float32Array, outVertices: Float32Array, outIndices: Uint32Array): number;
@@ -0,0 +1,49 @@
1
+ export declare const glsl: {
2
+ readonly svgaBatchPremul: {
3
+ readonly vert: string;
4
+ readonly frag: string;
5
+ };
6
+ readonly svgaInstancedPremul: {
7
+ readonly vert: string;
8
+ readonly frag: string;
9
+ };
10
+ readonly vap: {
11
+ readonly vert: string;
12
+ readonly frag: string;
13
+ };
14
+ readonly vapMixOverlay: {
15
+ readonly vert: string;
16
+ readonly frag: string;
17
+ };
18
+ readonly vapInstanced: {
19
+ readonly vert: string;
20
+ readonly frag: string;
21
+ };
22
+ readonly alphaVideo: {
23
+ readonly vert: string;
24
+ readonly frag: string;
25
+ };
26
+ readonly alphaVideoInstanced: {
27
+ readonly vert: string;
28
+ readonly frag: string;
29
+ };
30
+ readonly rgbaTextured: {
31
+ readonly vert: string;
32
+ readonly frag: string;
33
+ };
34
+ readonly clipMask: {
35
+ readonly vert: string;
36
+ readonly frag: string;
37
+ };
38
+ };
39
+ export declare const wgsl: {
40
+ readonly svgaBatchPremul: string;
41
+ readonly svgaInstancedPremul: string;
42
+ readonly vap: string;
43
+ readonly vapMixOverlay: string;
44
+ readonly vapInstanced: string;
45
+ readonly alphaVideo: string;
46
+ readonly alphaVideoInstanced: string;
47
+ readonly rgbaTextured: string;
48
+ readonly clipMask: string;
49
+ };