pag-player
Version:
pag预览插件
9 lines • 156 kB
JavaScript
/*
* @Author: wangpan pan.wang@ushow.media
* @Date: 2025-03-11 23:47:54
* @LastEditors: wangpan pan.wang@ushow.media
* @LastEditTime: 2025-03-11 23:48:05
* @FilePath: /pag-preview/src/libpag.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).libpag={})}(this,(function(e){"use strict";const t=(()=>{if("undefined"!=typeof globalThis)return globalThis;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;if("undefined"!=typeof self)return self;throw new Error("unable to locate global object")})();let r;void 0===t.globalThis&&Object.defineProperty(t,"globalThis",{get:()=>t});function n(e){const t=["length","name","prototype","wasmAsyncMethods"];let n=Object.getOwnPropertyNames(e).filter((e=>-1===t.indexOf(e)));e.wasmAsyncMethods&&e.wasmAsyncMethods.length>0&&(n=n.filter((t=>-1===e.wasmAsyncMethods.indexOf(t))));let a=Object.getOwnPropertyNames(e.prototype).filter((t=>"constructor"!==t&&"function"==typeof e.prototype[t]));e.prototype.wasmAsyncMethods&&e.prototype.wasmAsyncMethods.length>0&&(a=a.filter((t=>-1===e.prototype.wasmAsyncMethods.indexOf(t))));const i=(e,t)=>{const n=e[t];e[t]=function(...e){if(null!==r.Asyncify.currData){const t=r.Asyncify.currData;r.Asyncify.currData=null;const a=n.call(this,...e);return r.Asyncify.currData=t,a}return n.call(this,...e)}};n.forEach((t=>i(e,t))),a.forEach((t=>i(e.prototype,t)))}function a(e,t,r){e.wasmAsyncMethods||(e.wasmAsyncMethods=[]),e.wasmAsyncMethods.push(t)}function i(e){let t=Object.getOwnPropertyNames(e.prototype).filter((t=>"constructor"!==t&&"function"==typeof e.prototype[t]));const r=(t,r)=>{const n=t[r];t[r]=function(...t){if(!this.isDestroyed)return n.call(this,...t);console.error(`Don't call ${r} of the ${e.name} that is destroyed.`)}};t.forEach((t=>r(e.prototype,t)))}var o=(e=>(e[e.None=0]="None",e[e.Stretch=1]="Stretch",e[e.LetterBox=2]="LetterBox",e[e.Zoom=3]="Zoom",e))(o||{}),s=(e=>(e.onAnimationStart="onAnimationStart",e.onAnimationEnd="onAnimationEnd",e.onAnimationCancel="onAnimationCancel",e.onAnimationRepeat="onAnimationRepeat",e.onAnimationUpdate="onAnimationUpdate",e.onAnimationPlay="onAnimationPlay",e.onAnimationPause="onAnimationPause",e.onAnimationFlushed="onAnimationFlushed",e))(s||{}),l=(e=>(e[e.LeftJustify=0]="LeftJustify",e[e.CenterJustify=1]="CenterJustify",e[e.RightJustify=2]="RightJustify",e[e.FullJustifyLastLineLeft=3]="FullJustifyLastLineLeft",e[e.FullJustifyLastLineRight=4]="FullJustifyLastLineRight",e[e.FullJustifyLastLineCenter=5]="FullJustifyLastLineCenter",e[e.FullJustifyLastLineFull=6]="FullJustifyLastLineFull",e))(l||{}),u=(e=>(e[e.Default=0]="Default",e[e.Horizontal=1]="Horizontal",e[e.Vertical=2]="Vertical",e))(u||{}),c=(e=>(e[e.Unknown=0]="Unknown",e[e.Null=1]="Null",e[e.Solid=2]="Solid",e[e.Text=3]="Text",e[e.Shape=4]="Shape",e[e.Image=5]="Image",e[e.PreCompose=6]="PreCompose",e))(c||{}),f=(e=>(e[e.None=0]="None",e[e.Scale=1]="Scale",e[e.Repeat=2]="Repeat",e[e.RepeatInverted=3]="RepeatInverted",e))(f||{}),d=(e=>(e[e.a=0]="a",e[e.c=1]="c",e[e.tx=2]="tx",e[e.b=3]="b",e[e.d=4]="d",e[e.ty=5]="ty",e))(d||{}),h=(e=>(e[e.Success=0]="Success",e[e.TryAgainLater=-1]="TryAgainLater",e[e.Error=-2]="Error",e))(h||{}),m=(e=>(e[e.Unknown=0]="Unknown",e[e.ALPHA_8=1]="ALPHA_8",e[e.RGBA_8888=2]="RGBA_8888",e[e.BGRA_8888=3]="BGRA_8888",e))(m||{}),p=(e=>(e[e.Unknown=0]="Unknown",e[e.Opaque=1]="Opaque",e[e.Premultiplied=2]="Premultiplied",e[e.Unpremultiplied=3]="Unpremultiplied",e))(p||{}),y=Object.freeze({__proto__:null,PAGScaleMode:o,PAGViewListenerEvent:s,ParagraphJustification:l,TextDirection:u,LayerType:c,PAGTimeStretchMode:f,MatrixIndex:d,DecoderResult:h,ColorType:m,AlphaType:p}),v=Object.defineProperty,g=Object.getOwnPropertyDescriptor;let w=class{constructor(e){this.isDestroyed=!1,this.wasmIns=e}static makeAll(e,t,n,a,i,o,s=0,l=0,u=1){const c=r._Matrix._MakeAll(e,t,n,a,i,o,s,l,u);if(!c)throw new Error("Matrix.makeAll fail, please check parameters valid!");return new w(c)}static makeScale(e,t){let n;if(n=void 0!==t?r._Matrix._MakeScale(e,t):r._Matrix._MakeScale(e),!n)throw new Error("Matrix.makeScale fail, please check parameters valid!");return new w(n)}static makeTrans(e,t){const n=r._Matrix._MakeTrans(e,t);if(!n)throw new Error("Matrix.makeTrans fail, please check parameters valid!");return new w(n)}get a(){return this.wasmIns?this.wasmIns._get(d.a):0}set a(e){var t;null==(t=this.wasmIns)||t._set(d.a,e)}get b(){return this.wasmIns?this.wasmIns._get(d.b):0}set b(e){var t;null==(t=this.wasmIns)||t._set(d.b,e)}get c(){return this.wasmIns?this.wasmIns._get(d.c):0}set c(e){var t;null==(t=this.wasmIns)||t._set(d.c,e)}get d(){return this.wasmIns?this.wasmIns._get(d.d):0}set d(e){var t;null==(t=this.wasmIns)||t._set(d.d,e)}get tx(){return this.wasmIns?this.wasmIns._get(d.tx):0}set tx(e){var t;null==(t=this.wasmIns)||t._set(d.tx,e)}get ty(){return this.wasmIns?this.wasmIns._get(d.ty):0}set ty(e){var t;null==(t=this.wasmIns)||t._set(d.ty,e)}get(e){return this.wasmIns?this.wasmIns._get(e):0}set(e,t){var r;null==(r=this.wasmIns)||r._set(e,t)}setAll(e,t,r,n,a,i){var o;null==(o=this.wasmIns)||o._setAll(e,t,r,n,a,i,0,0,1)}setAffine(e,t,r,n,a,i){var o;null==(o=this.wasmIns)||o._setAffine(e,t,r,n,a,i)}reset(){var e;null==(e=this.wasmIns)||e._reset()}setTranslate(e,t){var r;null==(r=this.wasmIns)||r._setTranslate(e,t)}setScale(e,t,r=0,n=0){var a;null==(a=this.wasmIns)||a._setScale(e,t,r,n)}setRotate(e,t=0,r=0){var n;null==(n=this.wasmIns)||n._setRotate(e,t,r)}setSinCos(e,t,r=0,n=0){var a;null==(a=this.wasmIns)||a._setSinCos(e,t,r,n)}setSkew(e,t,r=0,n=0){var a;null==(a=this.wasmIns)||a._setSkew(e,t,r,n)}setConcat(e,t){var r;null==(r=this.wasmIns)||r._setConcat(e.wasmIns,t.wasmIns)}preTranslate(e,t){var r;null==(r=this.wasmIns)||r._preTranslate(e,t)}preScale(e,t,r=0,n=0){var a;null==(a=this.wasmIns)||a._preScale(e,t,r,n)}preRotate(e,t=0,r=0){var n;null==(n=this.wasmIns)||n._preRotate(e,t,r)}preSkew(e,t,r=0,n=0){var a;null==(a=this.wasmIns)||a._preSkew(e,t,r,n)}preConcat(e){var t;null==(t=this.wasmIns)||t._preConcat(e.wasmIns)}postTranslate(e,t){var r;null==(r=this.wasmIns)||r._postTranslate(e,t)}postScale(e,t,r=0,n=0){var a;null==(a=this.wasmIns)||a._postScale(e,t,r,n)}postRotate(e,t=0,r=0){var n;null==(n=this.wasmIns)||n._postRotate(e,t,r)}postSkew(e,t,r=0,n=0){var a;null==(a=this.wasmIns)||a._postSkew(e,t,r,n)}postConcat(e){var t;null==(t=this.wasmIns)||t._postConcat(e.wasmIns)}destroy(){this.wasmIns.delete()}};w=((e,t,r,n)=>{for(var a,i=n>1?void 0:n?g(t,r):t,o=e.length-1;o>=0;o--)(a=e[o])&&(i=(n?a(t,r,i):a(i))||i);return n&&i&&v(t,r,i),i})([i,n],w);const _=(e,t,...n)=>{if(null!==r.Asyncify.currData){const a=r.Asyncify.currData;r.Asyncify.currData=null;const i=e.call(t,...n);return r.Asyncify.currData=a,i}return e.call(t,...n)},b=(e,t)=>new Proxy(e,{get(e,r,n){switch(r){case"get":return r=>{const n=_(e.get,e,r);return n?t(n):n};case"push_back":return t=>{_(e.push_back,e,t.wasmIns||t)};case"size":return()=>_(e.size,e);default:return Reflect.get(e,r,n)}}}),E=e=>{switch(_(e._layerType,e)){case c.Solid:return new r.PAGSolidLayer(e);case c.Text:return new r.PAGTextLayer(e);case c.Image:return new r.PAGImageLayer(e);default:return new r.PAGLayer(e)}},C=e=>(null==e?void 0:e.wasmIns)?e.wasmIns:e,x=(e,t)=>void 0!==t&&e instanceof t;var P=Object.defineProperty,T=Object.getOwnPropertyDescriptor;let A=class{constructor(e){this.isDestroyed=!1,this.wasmIns=e}uniqueID(){return this.wasmIns._uniqueID()}layerType(){return this.wasmIns._layerType()}layerName(){return this.wasmIns._layerName()}matrix(){const e=this.wasmIns._matrix();if(!e)throw new Error("Get matrix fail!");return new w(e)}setMatrix(e){this.wasmIns._setMatrix(e.wasmIns)}resetMatrix(){this.wasmIns._resetMatrix()}getTotalMatrix(){if(!this.wasmIns._getTotalMatrix())throw new Error("Get total matrix fail!");return new w(this.wasmIns._getTotalMatrix())}alpha(){return this.wasmIns._alpha()}setAlpha(e){this.wasmIns._setAlpha(e)}visible(){return this.wasmIns._visible()}setVisible(e){this.wasmIns._setVisible(e)}editableIndex(){return this.wasmIns._editableIndex()}parent(){const e=this.wasmIns._parent();if(!e)throw new Error("Get total matrix fail!");return new S(e)}markers(){const e=this.wasmIns._markers();if(!e)throw new Error("Get markers fail!");return b(e,(e=>e))}localTimeToGlobal(e){return this.wasmIns._localTimeToGlobal(e)}globalToLocalTime(e){return this.wasmIns._globalToLocalTime(e)}duration(){return this.wasmIns._duration()}frameRate(){return this.wasmIns._frameRate()}startTime(){return this.wasmIns._startTime()}setStartTime(e){this.wasmIns._setStartTime(e)}currentTime(){return this.wasmIns._currentTime()}setCurrentTime(e){this.wasmIns._setCurrentTime(e)}getProgress(){return this.wasmIns._getProgress()}setProgress(e){this.wasmIns._setProgress(e)}preFrame(){this.wasmIns._preFrame()}nextFrame(){this.wasmIns._nextFrame()}getBounds(){return this.wasmIns._getBounds()}trackMatteLayer(){const e=this.wasmIns._trackMatteLayer();if(!e)throw new Error("Get track matte layer fail!");return E(e)}excludedFromTimeline(){return this.wasmIns._excludedFromTimeline()}setExcludedFromTimeline(e){this.wasmIns._setExcludedFromTimeline(e)}isPAGFile(){return this.wasmIns._isPAGFile()}asTypeLayer(){return E(this)}isDelete(){return this.wasmIns.isDelete()}destroy(){this.wasmIns.delete(),this.isDestroyed=!0}};A=((e,t,r,n)=>{for(var a,i=n>1?void 0:n?T(t,r):t,o=e.length-1;o>=0;o--)(a=e[o])&&(i=(n?a(t,r,i):a(i))||i);return n&&i&&P(t,r,i),i})([i,n],A);var I=Object.defineProperty,k=Object.getOwnPropertyDescriptor;let S=class extends A{static make(e,t){const n=r._PAGComposition._Make(e,t);if(!n)throw new Error("Make PAGComposition fail!");return new S(n)}width(){return this.wasmIns._width()}height(){return this.wasmIns._height()}setContentSize(e,t){this.wasmIns._setContentSize(e,t)}numChildren(){return this.wasmIns._numChildren()}getLayerAt(e){const t=this.wasmIns._getLayerAt(e);if(!t)throw new Error(`Get layer at ${e} fail!`);return E(t)}getLayerIndex(e){return this.wasmIns._getLayerIndex(e.wasmIns)}setLayerIndex(e,t){return this.wasmIns._setLayerIndex(e.wasmIns,t)}addLayer(e){return this.wasmIns._addLayer(e.wasmIns)}addLayerAt(e,t){return this.wasmIns._addLayerAt(e.wasmIns,t)}contains(e){return this.wasmIns._contains(e.wasmIns)}removeLayer(e){const t=this.wasmIns._removeLayer(e.wasmIns);if(!t)throw new Error("Remove layer fail!");return E(t)}removeLayerAt(e){const t=this.wasmIns._removeLayerAt(e);if(!t)throw new Error(`Remove layer at ${e} fail!`);return E(t)}removeAllLayers(){this.wasmIns._removeAllLayers()}swapLayer(e,t){this.wasmIns._swapLayer(e.wasmIns,t.wasmIns)}swapLayerAt(e,t){this.wasmIns._swapLayerAt(e,t)}audioBytes(){return this.wasmIns._audioBytes()}audioMarkers(){const e=this.wasmIns._audioMarkers();if(!e)throw new Error("Get audioMarkers fail!");return b(e,(e=>e))}audioStartTime(){return this.wasmIns._audioStartTime()}getLayersByName(e){const t=this.wasmIns._getLayersByName(e);if(!t)throw new Error(`Get layers by ${e} fail!`);return b(t,E)}getLayersUnderPoint(e,t){const r=this.wasmIns._getLayersUnderPoint(e,t);if(!r)throw new Error(`Get layers under point ${e},${t} fail!`);return b(r,E)}};S=((e,t,r,n)=>{for(var a,i=n>1?void 0:n?k(t,r):t,o=e.length-1;o>=0;o--)(a=e[o])&&(i=(n?a(t,r,i):a(i))||i);return n&&i&&I(t,r,i),i})([i,n],S);const F=e=>new Promise((t=>{const r=new FileReader;r.onload=()=>{t(r.result)},r.onerror=()=>{console.error(r.error.message)},r.readAsArrayBuffer(e)})),D=(e,t)=>{const r=new Uint8Array(t),n=r.byteLength,a=e._malloc(n);return new Uint8Array(e.HEAPU8.buffer,a,n).set(r),{byteOffset:a,length:n,free:()=>e._free(a)}};var L=Object.defineProperty,M=Object.getOwnPropertyDescriptor,R=(e,t,r,n)=>{for(var a,i=n>1?void 0:n?M(t,r):t,o=e.length-1;o>=0;o--)(a=e[o])&&(i=(n?a(t,r,i):a(i))||i);return n&&i&&L(t,r,i),i};let G=class extends S{static async load(e){const t=await(e=>x(e,globalThis.File)?F(e):x(e,globalThis.Blob)?F(new File([e],"")):x(e,globalThis.ArrayBuffer)?Promise.resolve(e):Promise.resolve(null))(e);if(!t)throw new Error("Initialize PAGFile data type error, please put check data type must to be File | Blob | ArrayBuffer!");return G.loadFromBuffer(t)}static loadFromBuffer(e){if(!(e&&e.byteLength>0))throw new Error("Initialize PAGFile data not be empty!");const{byteOffset:t,length:n,free:a}=D(r,e),i=r._PAGFile._Load(t,n);if(a(),!i)throw new Error("Load PAGFile fail!");return new G(i)}static maxSupportedTagLevel(){return r._PAGFile._MaxSupportedTagLevel()}tagLevel(){return this.wasmIns._tagLevel()}numTexts(){return this.wasmIns._numTexts()}numImages(){return this.wasmIns._numImages()}numVideos(){return this.wasmIns._numVideos()}getTextData(e){return this.wasmIns._getTextData(e)}replaceText(e,t){this.wasmIns._replaceText(e,t)}replaceImage(e,t){this.wasmIns._replaceImage(e,t.wasmIns)}getLayersByEditableIndex(e,t){const r=this.wasmIns._getLayersByEditableIndex(e,t);if(!r)throw new Error(`Get ${(e=>{switch(e){case c.Solid:return"Solid";case c.Text:return"Text";case c.Shape:return"Shape";case c.Image:return"Image";case c.PreCompose:return"PreCompose";default:return"Unknown"}})(t)} layers by ${e} fail!`);return b(r,E)}getEditableIndices(e){return this.wasmIns._getEditableIndices(e)}timeStretchMode(){return this.wasmIns._timeStretchMode()}setTimeStretchMode(e){this.wasmIns._setTimeStretchMode(e)}setDuration(e){this.wasmIns._setDuration(e)}copyOriginal(){const e=this.wasmIns._copyOriginal();if(!e)throw new Error("Copy original fail!");return new G(e)}};R([a],G,"load",1),G=R([i,n],G);var B=Object.defineProperty,O=Object.getOwnPropertyDescriptor;let j=class{constructor(e){this.isDestroyed=!1,this.wasmIns=e}static fromCanvas(e){const t=r._PAGSurface._FromCanvas(e);if(!t)throw new Error(`Make PAGSurface from canvas ${e} fail!`);return new j(t)}static fromTexture(e,t,n,a){const i=r._PAGSurface._FromTexture(e,t,n,a);if(!i)throw new Error(`Make PAGSurface from texture ${e} fail!`);return new j(i)}static fromRenderTarget(e,t,n,a){const i=r._PAGSurface._FromRenderTarget(e,t,n,a);if(!i)throw new Error(`Make PAGSurface from frameBuffer ${e} fail!`);return new j(i)}width(){return this.wasmIns._width()}height(){return this.wasmIns._height()}updateSize(){this.wasmIns._updateSize()}clearAll(){return this.wasmIns._clearAll()}freeCache(){this.wasmIns._freeCache()}readPixels(e,t){if(e===m.Unknown)return null;const n=this.width()*(e===m.ALPHA_8?1:4),a=n*this.height(),i=new Uint8Array(a),{data:o,free:s}=((e,t,r)=>{const n=new Uint8Array(t),a=e._malloc(n.byteLength);if(!r(a,n.byteLength))return{data:null,free:()=>e._free(a)};const i=new Uint8Array(e.HEAPU8.buffer,a,n.byteLength);return n.set(i),{data:n,free:()=>e._free(a)}})(r,i,(r=>this.wasmIns._readPixels(e,t,r,n)));return s(),o}destroy(){this.wasmIns.delete(),this.isDestroyed=!0}};j=((e,t,r,n)=>{for(var a,i=n>1?void 0:n?O(t,r):t,o=e.length-1;o>=0;o--)(a=e[o])&&(i=(n?a(t,r,i):a(i))||i);return n&&i&&B(t,r,i),i})([i,n],j);var V=Object.defineProperty,N=Object.getOwnPropertyDescriptor,$=(e,t,r,n)=>{for(var a,i=n>1?void 0:n?N(t,r):t,o=e.length-1;o>=0;o--)(a=e[o])&&(i=(n?a(t,r,i):a(i))||i);return n&&i&&V(t,r,i),i};let U=class{constructor(e){this.isDestroyed=!1,this.videoReaders=[],this.wasmIns=e}static create(){const e=new r._PAGPlayer;if(!e)throw new Error("Create PAGPlayer fail!");return new U(e)}setProgress(e){this.wasmIns._setProgress(e)}async flush(){return r.webAssemblyQueue.exec(this.wasmIns._flush,this.wasmIns)}async flushInternal(e){const t=await r.webAssemblyQueue.exec((async()=>{r.currentPlayer=this;const t=await this.wasmIns._flush();return r.currentPlayer=null,e(t),t}),this.wasmIns);for(const e of this.videoReaders){const t=await e.getError();if(null!==t)throw t}return t}duration(){return this.wasmIns._duration()}getProgress(){return this.wasmIns._getProgress()}currentFrame(){return this.wasmIns._currentFrame()}videoEnabled(){return this.wasmIns._videoEnabled()}setVideoEnabled(e){this.wasmIns._setVideoEnabled(e)}cacheEnabled(){return this.wasmIns._cacheEnabled()}setCacheEnabled(e){this.wasmIns._setCacheEnabled(e)}cacheScale(){return this.wasmIns._cacheScale()}setCacheScale(e){this.wasmIns._setCacheScale(e)}maxFrameRate(){return this.wasmIns._maxFrameRate()}setMaxFrameRate(e){this.wasmIns._setMaxFrameRate(e)}scaleMode(){return this.wasmIns._scaleMode()}setScaleMode(e){this.wasmIns._setScaleMode(e)}setSurface(e){this.wasmIns._setSurface(C(e))}getComposition(){const e=this.wasmIns._getComposition();if(!e)throw new Error("Get composition fail!");return e._isPAGFile()?new G(e):new S(e)}setComposition(e){this.wasmIns._setComposition(C(e))}getSurface(){const e=this.wasmIns._getSurface();if(!e)throw new Error("Get surface fail!");return new j(e)}matrix(){const e=this.wasmIns._matrix();if(!e)throw new Error("Get matrix fail!");return new w(e)}setMatrix(e){this.wasmIns._setMatrix(e.wasmIns)}nextFrame(){this.wasmIns._nextFrame()}preFrame(){this.wasmIns._preFrame()}autoClear(){return this.wasmIns._autoClear()}setAutoClear(e){this.wasmIns._setAutoClear(e)}getBounds(e){return this.wasmIns._getBounds(e.wasmIns)}getLayersUnderPoint(e,t){const r=this.wasmIns._getLayersUnderPoint(e,t);if(!r)throw new Error(`Get layers under point, x: ${e} y:${t} fail!`);return b(r,E)}hitTestPoint(e,t,r,n=!1){return this.wasmIns._hitTestPoint(e.wasmIns,t,r,n)}renderingTime(){return this.wasmIns._renderingTime()}imageDecodingTime(){return this.wasmIns._imageDecodingTime()}presentingTime(){return this.wasmIns._presentingTime()}graphicsMemory(){return this.wasmIns._graphicsMemory()}prepare(){return r.webAssemblyQueue.exec((async()=>{r.currentPlayer=this,await this.wasmIns._prepare(),r.currentPlayer=null}),this.wasmIns)}destroy(){this.wasmIns.delete(),this.isDestroyed=!0}linkVideoReader(e){this.videoReaders.push(e)}unlinkVideoReader(e){const t=this.videoReaders.indexOf(e);-1!==t&&this.videoReaders.splice(t,1)}};$([a],U.prototype,"flush",1),$([a],U.prototype,"flushInternal",1),U=$([i,n],U);var H=Object.defineProperty,z=Object.getOwnPropertyDescriptor,W=(e,t,r,n)=>{for(var a,i=n>1?void 0:n?z(t,r):t,o=e.length-1;o>=0;o--)(a=e[o])&&(i=(n?a(t,r,i):a(i))||i);return n&&i&&H(t,r,i),i};let q=class{constructor(e){this.isDestroyed=!1,this.wasmIns=e}static async fromFile(e){return new Promise(((t,r)=>{const n=new Image;n.onload=async()=>{t(q.fromSource(n))},n.onerror=e=>{r(e)},n.src=URL.createObjectURL(e)}))}static fromSource(e){const t=r._PAGImage._FromNativeImage(e);if(!t)throw new Error("Make PAGImage from source fail!");return new q(t)}static fromPixels(e,t,n,a,i){const o=t*(a===m.ALPHA_8?1:4),{byteOffset:s,free:l}=D(r,e),u=r._PAGImage._FromPixels(s,t,n,o,a,i);if(l(),!u)throw new Error("Make PAGImage from pixels fail!");return new q(u)}static fromTexture(e,t,n,a){const i=r._PAGImage._FromTexture(e,t,n,a);if(!i)throw new Error("Make PAGImage from texture fail!");return new q(i)}width(){return this.wasmIns._width()}height(){return this.wasmIns._height()}scaleMode(){return this.wasmIns._scaleMode()}setScaleMode(e){this.wasmIns._setScaleMode(e)}matrix(){const e=this.wasmIns._matrix();if(!e)throw new Error("Get matrix fail!");return new w(e)}setMatrix(e){this.wasmIns._setMatrix(e.wasmIns)}destroy(){this.wasmIns.delete(),this.isDestroyed=!0}};W([a],q,"fromFile",1),q=W([i,n],q);class X{constructor(){this.listenerMap=new Map}on(e,t){let r=[];this.listenerMap.has(e)&&(r=this.listenerMap.get(e)),r.push(t),this.listenerMap.set(e,r)}off(e,t){if(!this.listenerMap.has(e))return!1;const r=this.listenerMap.get(e);if(0===r.length)return!1;if(!t)return this.listenerMap.delete(e),!0;const n=r.indexOf(t);return-1!==n&&(r.splice(n,1),!0)}emit(e,t){if(!this.listenerMap.has(e))return!1;const r=this.listenerMap.get(e);return 0!==r.length&&(r.forEach((e=>e(t))),!0)}}const J=2560,K={depth:!1,stencil:!1,antialias:!1},Q=(null==navigator?void 0:navigator.userAgent)||"",Y=/android|adr/i.test(Q),Z=/(mobile)/i.test(Q)&&Y;!/(mobile)/i.test(Q)&&!Z&&/Mac OS X/i.test(Q);const ee=/(iphone|ipad|ipod)/i.test(Q),te=/MicroMessenger/i.test(Q),re=/^((?!chrome|android).)*safari/i.test(Q)||ee,ne="function"==typeof globalThis.importScripts,ae=new Array,ie=e=>x(e,globalThis.OffscreenCanvas),oe=(e,t)=>{let r=ae.pop()||le();return null!==r&&(r.width=e,r.height=t),r},se=e=>{ae.length<10&&ae.push(e)},le=()=>{if(re&&!ne)return document.createElement("canvas");try{const e=new OffscreenCanvas(0,0);return"function"==typeof e.getContext("2d").measureText?e:document.createElement("canvas")}catch(e){return document.createElement("canvas")}};var ue=Object.defineProperty,ce=Object.getOwnPropertySymbols,fe=Object.prototype.hasOwnProperty,de=Object.prototype.propertyIsEnumerable,he=(e,t,r)=>t in e?ue(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;class me{constructor(e,t=!1){this.isDestroyed=!1,this.oldHandle=0,this.handle=e,this.adopted=t}static from(e){if(e instanceof me)return new me(e.handle,!0);{const t=x(e,globalThis.WebGL2RenderingContext)?2:1,{GL:n}=r;let a=0;return n.contexts.length>0&&(a=n.contexts.findIndex((t=>(null==t?void 0:t.GLctx)===e))),a<1?(a=n.registerContext(e,((e,t)=>{for(var r in t||(t={}))fe.call(t,r)&&he(e,r,t[r]);if(ce)for(var r of ce(t))de.call(t,r)&&he(e,r,t[r]);return e})({majorVersion:t,minorVersion:0},K)),new me(a)):new me(a,!0)}}getContext(){return r.GL.getContext(this.handle).GLctx}makeCurrent(){var e;return!this.isDestroyed&&(this.oldHandle=(null==(e=r.GL.currentContext)?void 0:e.handle)||0,this.oldHandle===this.handle||r.GL.makeContextCurrent(this.handle))}clearCurrent(){this.isDestroyed||this.oldHandle!==this.handle&&(r.GL.makeContextCurrent(0),this.oldHandle&&r.GL.makeContextCurrent(this.oldHandle))}registerTexture(e){return this.register(r.GL.textures,e)}getTexture(e){return r.GL.textures[e]}unregisterTexture(e){r.GL.textures[e]=null}registerRenderTarget(e){return this.register(r.GL.framebuffers,e)}getRenderTarget(e){return r.GL.framebuffers[e]}unregisterRenderTarget(e){r.GL.framebuffers[e]=null}destroy(){this.adopted||r.GL.deleteContext(this.handle)}register(e,t){const n=r.GL.getNewId(e);return e[n]=t,n}}var pe=Object.defineProperty,ye=Object.getOwnPropertySymbols,ve=Object.prototype.hasOwnProperty,ge=Object.prototype.propertyIsEnumerable,we=(e,t,r)=>t in e?pe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,_e=(e,t)=>{for(var r in t||(t={}))ve.call(t,r)&&we(e,r,t[r]);if(ye)for(var r of ye(t))ge.call(t,r)&&we(e,r,t[r]);return e};const be=[];class Ee{constructor(e,t){this._canvas=null,this._glContext=null,this.retainCount=0,this._canvas=e;const r=e.getContext("webgl",_e(_e({},K),t));if(!r)throw new Error("Canvas context is not WebGL!");this._glContext=me.from(r)}static from(e,t){let r=be.find((t=>t.canvas===e));return r||(r=new Ee(e,t),be.push(r),r)}retain(){this.retainCount+=1}release(){if(this.retainCount-=1,0===this.retainCount){if(!this._glContext)return;this._glContext.destroy(),this._glContext=null,this._canvas=null}}get canvas(){return this._canvas}get glContext(){return this._glContext}}let Ce;try{Ce=performance.now.bind(performance)}catch(e){Ce=Date.now.bind(Date)}class xe{constructor(){this.startTime=Ce(),this.markers={}}reset(){this.startTime=Ce(),this.markers={}}mark(e){e?Object.keys(this.markers).find((t=>t===e))?console.log(`Clock.mark(): The specified marker name '${e}' already exists!`):this.markers[e]=Ce():console.log("Clock.mark(): An empty marker name was specified!")}measure(e,t){let r,n;if(e){if(!Object.keys(this.markers).find((t=>t===e)))return console.log(`Clock.measure(): The specified makerFrom '${e}' does not exist!`),0;r=this.markers[e]}else r=this.startTime;if(t){if(!Object.keys(this.markers).find((e=>e===t)))return console.log(`Clock.measure(): The specified makerTo '${t}' does not exist!`),0;n=this.markers[t]}else n=Ce();return n-r}}var Pe=Object.defineProperty,Te=Object.getOwnPropertyDescriptor,Ae=Object.getOwnPropertySymbols,Ie=Object.prototype.hasOwnProperty,ke=Object.prototype.propertyIsEnumerable,Se=(e,t,r)=>t in e?Pe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Fe=(e,t)=>{for(var r in t||(t={}))Ie.call(t,r)&&Se(e,r,t[r]);if(Ae)for(var r of Ae(t))ke.call(t,r)&&Se(e,r,t[r]);return e};let De=class{constructor(e,t){this.repeatCount=0,this.isPlaying=!1,this.isDestroyed=!1,this.pagViewOptions={useScale:!0,useCanvas2D:!1,firstFrame:!0},this.renderCanvas=null,this.pagGlContext=null,this.frameRate=0,this.pagSurface=null,this.playFrame=-1,this.timer=null,this.flushingNextFrame=!1,this.playTime=0,this.startTime=0,this.repeatedTimes=0,this.eventManager=new X,this.rawWidth=0,this.rawHeight=0,this.debugData={FPS:0,flushTime:0},this.fpsBuffer=[],this.player=e,this.canvasElement=t}static async init(e,t,n={}){let a=null;if("string"==typeof t?a=document.getElementById(t.substr(1)):("undefined"!=typeof window&&x(t,globalThis.HTMLCanvasElement)||ie(t))&&(a=t),!a)throw new Error("Canvas is not found!");const i=r.PAGPlayer.create(),o=new De(i,a);return o.pagViewOptions=Fe(Fe({},o.pagViewOptions),n),o.pagViewOptions.useCanvas2D?(r.globalCanvas.retain(),o.pagGlContext=me.from(r.globalCanvas.glContext)):(o.renderCanvas=Ee.from(a),o.renderCanvas.retain(),o.pagGlContext=me.from(o.renderCanvas.glContext)),o.resetSize(o.pagViewOptions.useScale),o.frameRate=e.frameRate(),o.pagSurface=this.makePAGSurface(o.pagGlContext,o.rawWidth,o.rawHeight),o.player.setSurface(o.pagSurface),o.player.setComposition(e),o.setProgress(0),o.pagViewOptions.firstFrame&&(await o.flush(),o.playFrame=0),o}static makePAGSurface(e,t,r){if(!e.makeCurrent())throw new Error("Make context current fail!");const n=j.fromRenderTarget(0,t,r,!0);return e.clearCurrent(),n}duration(){return this.player.duration()}addListener(e,t){return this.eventManager.on(e,t)}removeListener(e,t){return this.eventManager.off(e,t)}async play(){if(this.isPlaying)return;this.isPlaying=!0,this.startTime=1e3*this.getNowTime()-this.playTime;for(const e of this.player.videoReaders)e.isPlaying=!0;const e=this.playTime;await this.flushLoop(!0),0===e&&this.eventManager.emit("onAnimationStart",this),this.eventManager.emit("onAnimationPlay",this),0===this.playFrame&&this.eventManager.emit("onAnimationUpdate",this)}pause(){if(this.isPlaying){this.clearTimer();for(const e of this.player.videoReaders)e.pause();this.isPlaying=!1,this.eventManager.emit("onAnimationPause",this)}}async stop(e=!0){this.clearTimer(),this.playTime=0,this.player.setProgress(0),this.playFrame=0,await this.flush();for(const e of this.player.videoReaders)e.stop();this.isPlaying=!1,e&&this.eventManager.emit("onAnimationCancel",this)}setRepeatCount(e){this.repeatCount=e<0?0:e-1}getProgress(){return this.player.getProgress()}currentFrame(){return this.player.currentFrame()}setProgress(e){return this.playTime=e*this.duration(),this.startTime=1e3*this.getNowTime()-this.playTime,this.isPlaying||this.player.setProgress(e),e}videoEnabled(){return this.player.videoEnabled()}setVideoEnabled(e){this.player.setVideoEnabled(e)}cacheEnabled(){return this.player.cacheEnabled()}setCacheEnabled(e){this.player.setCacheEnabled(e)}cacheScale(){return this.player.cacheScale()}setCacheScale(e){this.player.setCacheScale(e)}maxFrameRate(){return this.player.maxFrameRate()}setMaxFrameRate(e){this.player.setMaxFrameRate(e)}scaleMode(){return this.player.scaleMode()}setScaleMode(e){this.player.setScaleMode(e)}async flush(){const e=new xe,t=await this.player.flushInternal((t=>{var n,a;if(this.pagViewOptions.useCanvas2D&&t&&r.globalCanvas.canvas){this.canvasContext||(this.canvasContext=null==(n=this.canvasElement)?void 0:n.getContext("2d"));const e=this.canvasContext.globalCompositeOperation;this.canvasContext.globalCompositeOperation="copy",null==(a=this.canvasContext)||a.drawImage(r.globalCanvas.canvas,0,r.globalCanvas.canvas.height-this.rawHeight,this.rawWidth,this.rawHeight,0,0,this.canvasContext.canvas.width,this.canvasContext.canvas.height),this.canvasContext.globalCompositeOperation=e}e.mark("flush"),this.setDebugData({flushTime:e.measure("","flush")}),this.updateFPS()}));return this.eventManager.emit("onAnimationUpdate",this),t&&this.eventManager.emit("onAnimationFlushed",this),t}freeCache(){var e;null==(e=this.pagSurface)||e.freeCache()}getComposition(){return this.player.getComposition()}setComposition(e){this.player.setComposition(e)}matrix(){return this.player.matrix()}setMatrix(e){this.player.setMatrix(e)}getLayersUnderPoint(e,t){return this.player.getLayersUnderPoint(e,t)}updateSize(){var e;if(!this.canvasElement)throw new Error("Canvas element is not found!");if(this.rawWidth=this.canvasElement.width,this.rawHeight=this.canvasElement.height,!this.pagGlContext)return;const t=De.makePAGSurface(this.pagGlContext,this.rawWidth,this.rawHeight);this.player.setSurface(t),null==(e=this.pagSurface)||e.destroy(),this.pagSurface=t}prepare(){return this.player.prepare()}makeSnapshot(){return createImageBitmap(this.canvasElement)}destroy(){var e,t,n;this.clearTimer(),this.player.destroy(),null==(e=this.pagSurface)||e.destroy(),this.pagViewOptions.useCanvas2D?r.globalCanvas.release():null==(t=this.renderCanvas)||t.release(),null==(n=this.pagGlContext)||n.destroy(),this.pagGlContext=null,this.canvasContext=null,this.canvasElement=null,this.isDestroyed=!0}getDebugData(){return this.debugData}setDebugData(e){this.debugData=Fe(Fe({},this.debugData),e)}async flushLoop(e=!1){if(this.isPlaying&&(this.setTimer(),!this.flushingNextFrame))try{this.flushingNextFrame=!0,await this.flushNextFrame(e),this.flushingNextFrame=!1}catch(e){throw this.flushingNextFrame=!1,"The play() request was interrupted because the document was hidden!"!==e.message&&this.clearTimer(),e}}async flushNextFrame(e=!1){const t=this.duration();this.playTime=1e3*this.getNowTime()-this.startTime;const r=Math.floor(this.playTime/1e6*this.frameRate),n=Math.floor(this.playTime/t);if(!e&&this.repeatCount>=0&&n>this.repeatCount)return this.clearTimer(),this.player.setProgress(1),await this.flush(),this.playTime=0,this.isPlaying=!1,this.repeatedTimes=0,this.eventManager.emit("onAnimationEnd",this),!0;if(!e&&this.repeatedTimes===n&&this.playFrame===r)return!1;this.repeatedTimes<n&&this.eventManager.emit("onAnimationRepeat",this),this.player.setProgress(this.playTime%t/t);const a=await this.flush();return this.needResetStartTime()&&(this.startTime=1e3*this.getNowTime()-this.playTime),this.playFrame=r,this.repeatedTimes=n,a}getNowTime(){try{return performance.now()}catch(e){return Date.now()}}setTimer(){this.timer=ne?self.setTimeout((()=>{this.flushLoop()}),1/this.frameRate*1e3):globalThis.requestAnimationFrame((()=>{this.flushLoop()}))}clearTimer(){this.timer&&(ne?self.clearTimeout(this.timer):globalThis.cancelAnimationFrame(this.timer),this.timer=null)}resetSize(e=!0){if(!this.canvasElement)throw new Error("Canvas element is not found!");if(!e||ie(this.canvasElement))return this.rawWidth=this.canvasElement.width,void(this.rawHeight=this.canvasElement.height);const t=this.canvasElement,r=(e=>{const t=globalThis.getComputedStyle(e,null),r={width:Number(t.width.replace("px","")),height:Number(t.height.replace("px",""))};if(r.width>0&&r.height>0)return r;{const t={width:Number(e.style.width.replace("px","")),height:Number(e.style.height.replace("px",""))};return t.width>0&&t.height>0?t:{width:e.width,height:e.height}}})(t);t.style.width=`${r.width}px`,t.style.height=`${r.height}px`,this.rawWidth=r.width*globalThis.devicePixelRatio,this.rawHeight=r.height*globalThis.devicePixelRatio,t.width=this.rawWidth,t.height=this.rawHeight}updateFPS(){let e;try{e=performance.now()}catch(t){e=Date.now()}this.fpsBuffer=this.fpsBuffer.filter((t=>e-t<=1e3)),this.fpsBuffer.push(e),this.setDebugData({FPS:this.fpsBuffer.length})}needResetStartTime(){for(const e of this.player.videoReaders)if(e.isSought)return!0;return!1}};De=((e,t,r,n)=>{for(var a,i=n>1?void 0:n?Te(t,r):t,o=e.length-1;o>=0;o--)(a=e[o])&&(i=(n?a(t,r,i):a(i))||i);return n&&i&&Pe(t,r,i),i})([i],De);const Le=["emoji"].concat(...["Arial",'"Courier New"',"Georgia",'"Times New Roman"','"Trebuchet MS"',"Verdana"]);var Me=Object.defineProperty,Re=Object.getOwnPropertyDescriptor,Ge=(e,t,r,n)=>{for(var a,i=n>1?void 0:n?Re(t,r):t,o=e.length-1;o>=0;o--)(a=e[o])&&(i=(n?a(t,r,i):a(i))||i);return n&&i&&Me(t,r,i),i};let Be=class{constructor(e){this.isDestroyed=!1,this.wasmIns=e,this.fontFamily=this.wasmIns.fontFamily,this.fontStyle=this.wasmIns.fontStyle}static create(e,t){const n=r._PAGFont._create(e,t);if(!n)throw new Error("Create PAGFont fail!");return new Be(n)}static async registerFont(e,t){const r=await F(t);if(!(r&&r.byteLength>0))throw new Error("Initialize PAGFont data not be empty!");const n=new Uint8Array(r),a=new FontFace(e,n);document.fonts.add(a),await a.load()}static registerFallbackFontNames(e=[]){const t=new r.VectorString,n=e.concat(Le);for(const e of n)t.push_back(e);r._PAGFont._SetFallbackFontNames(t),t.delete()}destroy(){this.wasmIns.delete(),this.isDestroyed=!0}};Ge([a],Be,"registerFont",1),Be=Ge([i,n],Be);let Oe={};const je=(e,t,r,n=!1)=>{var a;t in Oe||(Oe[t]=[]),null==(a=Oe[t])||a.push({node:e,handler:r,capture:n}),e.addEventListener(t,r,n)},Ve=(e,t,r)=>{var n;t in Oe&&(null==(n=Oe[t])||n.filter((({node:t,handler:n})=>t===e&&n===r)).forEach((({node:e,handler:r,capture:n})=>e.removeEventListener(t,r,n))))},Ne=(e,t)=>{var r,n;t in Oe&&(null==(r=Oe[t])||r.filter((({node:t})=>t===e)).forEach((({node:e,handler:r,capture:n})=>e.removeEventListener(t,r,n))),Oe[t]=null==(n=Oe[t])?void 0:n.filter((({node:t})=>t!==e)))};var $e=(e=>(e.PAGInit="PAGInit",e.PAGView_init="PAGView.init",e.PAGView_duration="PAGView.duration",e.PAGView_play="PAGView.play",e.PAGView_pause="PAGView.pause",e.PAGView_stop="PAGView.stop",e.PAGView_setRepeatCount="PAGView.setRepeatCount",e.PAGView_getProgress="PAGView.getProgress",e.PAGView_currentFrame="PAGView.currentFrame",e.PAGView_setProgress="PAGView.setProgress",e.PAGView_scaleMode="PAGView.scaleMode",e.PAGView_setScaleMode="PAGView.setScaleMode",e.PAGView_flush="PAGView.flush",e.PAGView_getDebugData="PAGView.getDebugData",e.PAGView_destroy="PAGView.destroy",e.PAGFile_load="PAGFile.load",e.PAGFile_getTextData="PAGFile.getTextData",e.PAGFile_replaceText="PAGFile.replaceText",e.PAGFile_replaceImage="PAGFile.replaceImage",e.PAGFile_destroy="PAGFile.destroy",e.PAGImage_fromSource="PAGImage.fromSource",e.PAGImage_destroy="PAGImage.destroy",e.VideoReader_constructor="VideoReader.constructor",e.VideoReader_prepare="VideoReader.prepare",e.VideoReader_play="VideoReader.play",e.VideoReader_pause="VideoReader.pause",e.VideoReader_stop="VideoReader.stop",e.VideoReader_getError="VideoReader.getError",e.PAGModule_linkVideoReader="PAGModule.linkVideoReader",e.TextDocument_delete="TextDocument.delete",e))($e||{});let Ue=0;const He=(e,t,r,n=[])=>new Promise((a=>{const i=(e=>`${e}_${Ue++}`)(t.name),o=t=>{t.data.name===i&&(e.removeEventListener("message",o),a(r(...t.data.args)))};e.addEventListener("message",o),e.postMessage({name:i,args:t.args},n)}));class ze{constructor(e){this.bitmap=e}setBitmap(e){this.bitmap&&this.bitmap.close(),this.bitmap=e}}class We{constructor(e){this.bitmap=null,this.isSought=!1,this.isPlaying=!1,this.bitmapImage=new ze(null),this.proxyId=e}prepare(e,t){return new Promise((r=>{He(self,{name:$e.VideoReader_prepare,args:[this.proxyId,e,t]},(e=>{this.bitmapImage.setBitmap(e),r()}))}))}getVideo(){return this.bitmapImage}onDestroy(){self.postMessage({name:"VideoReader.onDestroy",args:[this.proxyId]})}play(){return new Promise((e=>{He(self,{name:$e.VideoReader_play,args:[this.proxyId]},(()=>{e()}))}))}pause(){He(self,{name:$e.VideoReader_pause,args:[this.proxyId]},(()=>{}))}stop(){He(self,{name:$e.VideoReader_stop,args:[this.proxyId]},(()=>{}))}getError(){return new Promise((e=>{He(self,{name:$e.VideoReader_getError,args:[this.proxyId]},(t=>{e(t)}))}))}}const qe=e=>new Promise((t=>{const r=()=>{Ve(e,"canplay",r),clearTimeout(n),t(!0)};je(e,"canplay",r);const n=setTimeout((()=>{Ve(e,"canplay",r),t(!1)}),1e3)}));class Xe{constructor(e,t,n,a,i,o=!1){if(this.isSought=!1,this.isPlaying=!1,this.bitmap=null,this.videoEl=null,this.frameRate=0,this.canplay=!1,this.staticTimeRanges=null,this.disablePlaybackRate=!1,this.error=null,this.player=null,this.width=0,this.height=0,this.bitmapCanvas=null,this.bitmapCtx=null,x(e,globalThis.HTMLVideoElement))this.videoEl=e,this.canplay=!0;else{this.videoEl=document.createElement("video"),this.videoEl.style.display="none",this.videoEl.muted=!0,this.videoEl.playsInline=!0,this.videoEl.preload="auto",this.videoEl.width=t,this.videoEl.height=n,qe(this.videoEl).then((()=>{this.canplay=!0}));const r=new Blob([e],{type:"video/mp4"});this.videoEl.src=URL.createObjectURL(r),ee&&this.videoEl.load()}this.frameRate=a,this.width=t,this.height=n,this.staticTimeRanges=new Je(i),(3840<t||3840<n)&&(this.disablePlaybackRate=!0),o||this.linkPlayer(r.currentPlayer)}static async create(e,t,n,a,i){var o;if(ne){const s=await new Promise((r=>{const o=e,s=o.buffer.slice(o.byteOffset,o.byteOffset+o.byteLength);He(self,{name:$e.VideoReader_constructor,args:[s,t,n,a,i,!0]},(e=>{r(e)}),[s])})),l=new We(s);return null==(o=r.currentPlayer)||o.linkVideoReader(l),l}return new Xe(e,t,n,a,i)}async prepare(e,t){var r;this.setError(null),this.isSought=!1;const{currentTime:n}=this.videoEl,a=e/this.frameRate;if(0===n&&0===a)if(this.canplay||re){try{await this.play()}catch(e){this.setError(e)}await new Promise((e=>{requestAnimationFrame((()=>{this.pause(),e()}))}))}else await qe(this.videoEl);else if(Math.round(a*this.frameRate)===Math.round(n*this.frameRate));else{if(null==(r=this.staticTimeRanges)?void 0:r.contains(e))return void await this.seek(a,!1);if(!(Math.abs(n-a)<1/this.frameRate*3))return this.isSought=!0,void await this.seek(a)}const i=Math.min(Math.max(t,.125),4);if(this.disablePlaybackRate||this.videoEl.playbackRate===i||(this.videoEl.playbackRate=i),this.isPlaying&&this.videoEl.paused)try{await this.play()}catch(e){this.setError(e)}}getVideo(){return this.videoEl}async generateBitmap(){var e,t;return this.bitmapCanvas||(this.bitmapCanvas=new OffscreenCanvas(this.width,this.height),this.bitmapCanvas.width=this.width,this.bitmapCanvas.height=this.height,this.bitmapCtx=this.bitmapCanvas.getContext("2d")),null==(e=this.bitmapCtx)||e.fillRect(0,0,this.width,this.height),null==(t=this.bitmapCtx)||t.drawImage(this.videoEl,0,0,this.width,this.height),this.bitmap=await createImageBitmap(this.bitmapCanvas),this.bitmap}async play(){var e;if(this.videoEl.paused){if(te&&window.WeixinJSBridge&&await new Promise((e=>{window.WeixinJSBridge.invoke("getNetworkType",{},(()=>{e()}),(()=>{e()}))})),"visible"!==document.visibilityState){const e=()=>{"visible"===document.visibilityState&&(this.videoEl&&this.videoEl.play(),window.removeEventListener("visibilitychange",e))};throw window.addEventListener("visibilitychange",e),new Error("The play() request was interrupted because the document was hidden!")}await(null==(e=this.videoEl)?void 0:e.play())}}pause(){var e;this.isPlaying=!1,this.videoEl.paused||null==(e=this.videoEl)||e.pause()}stop(){var e;this.isPlaying=!1,this.videoEl.paused||null==(e=this.videoEl)||e.pause(),this.videoEl.currentTime=0}getError(){return this.error}onDestroy(){this.player&&this.player.unlinkVideoReader(this),Ne(this.videoEl,"playing"),Ne(this.videoEl,"timeupdate"),this.videoEl=null,this.bitmapCanvas=null,this.bitmapCtx=null}seek(e,t=!0){return new Promise((r=>{let n=!1,a=null;const i=async()=>{var e;if(t&&this.videoEl.paused)try{await this.play()}catch(e){this.setError(e)}else t||this.videoEl.paused||null==(e=this.videoEl)||e.pause()},o=async()=>{if(!this.videoEl)return this.setError(new Error("Video element doesn't exist!")),void r();Ve(this.videoEl,"seeked",o),await i(),n=!0,clearTimeout(a),a=null,r()};if(!this.videoEl)return this.setError(new Error("Video element doesn't exist!")),void r();je(this.videoEl,"seeked",o),this.videoEl.currentTime=e,a=setTimeout((()=>{if(!n){if(!this.videoEl)return this.setError(new Error("Video element doesn't exist!")),void r();Ve(this.videoEl,"seeked",o),i(),r()}}),1e3/this.frameRate*12)}))}setError(e){this.error=e}linkPlayer(e){this.player=e,e&&e.linkVideoReader(this)}}class Je{constructor(e){this.timeRanges=e}contains(e){if(0===this.timeRanges.length)return!1;for(let t of this.timeRanges)if(t.start<=e&&e<t.end)return!0;return!1}}const Ke=e=>{const t=new Int32Array(e.data.buffer);return{left:Qe(t,e.width,e.height),top:Ye(t,e.width,e.height),right:Ze(t,e.width,e.height),bottom:et(t,e.width,e.height)}},Qe=(e,t,r)=>{const n=e.length/t,a=e.length/r;for(let r=0;r<a;r++)for(let a=0;a<n;a++)if(0!==e[r+a*t])return r;return a},Ye=(e,t,r)=>{const n=e.length/t,a=e.length/r;for(let r=0;r<n;r++)for(let n=0;n<a;n++)if(0!==e[r*t+n])return r;return n},Ze=(e,t,r)=>{const n=e.length/t;for(let a=e.length/r-1;a>0;a--)for(let r=n-1;r>0;r--)if(0!==e[a+t*r])return a;return 0},et=(e,t,r)=>{const n=e.length/t,a=e.length/r;for(let r=n-1;r>0;r--)for(let n=a-1;n>0;n--)if(0!==e[r*t+n])return r;return 0};class tt{constructor(e,t,r,n=!1,a=!1){this.fontBoundingBoxMap=[],this.fontName=e,this.fontStyle=t,this.size=r,this.fauxBold=n,this.fauxItalic=a,this.loadCanvas()}static setCanvas(e){tt.canvas=e}static setContext(e){tt.context=e}static isUnicodePropertyEscapeSupported(){try{new RegExp("\\p{L}","u");return!0}catch(e){return!1}}static isEmoji(e){let t;return t=this.isUnicodePropertyEscapeSupported()?new RegExp("\\p{Extended_Pictographic}|[#*0-9]\\uFE0F?\\u20E3|[\\uD83C\\uDDE6-\\uD83C\\uDDFF]","u"):/(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/,t.test(e)}fontString(){const e=[];this.fauxItalic&&e.push("italic"),this.fauxBold&&e.push("bold"),e.push(`${this.size}px`);const t=Le.concat();return t.unshift(...((e,t="")=>{if(!e)return[];const r=e.split(" ");let n=[];1===r.length?n.push(e):(n.push(r.join("")),n.push(r.join(" ")));const a=n.reduce(((e,r)=>(t?(e.push(`"${r} ${t}"`),e.push(`"${r}-${t}"`)):e.push(`"${r}"`),e)),[]);return""!==t&&a.push(`"${e}"`),a})(this.fontName,this.fontStyle)),e.push(`${t.join(",")}`),e.join(" ")}getTextAdvance(e){const{context:t}=tt;return t.font=this.fontString(),t.measureText(e).width}getTextBounds(e){const{context:t}=tt;t.font=this.fontString();const r=this.measureText(t,e);return{left:Math.floor(-r.actualBoundingBoxLeft),top:Math.floor(-r.actualBoundingBoxAscent),right:Math.ceil(r.actualBoundingBoxRight),bottom:Math.ceil(r.actualBoundingBoxDescent)}}generateFontMetrics(){const{context:e}=tt;e.font=this.fontString();const t=this.measureText(e,"中"),r=t.actualBoundingBoxAscent,n=this.measureText(e,"x").actualBoundingBoxAscent;return{ascent:-t.fontBoundingBoxAscent,descent:t.fontBoundingBoxDescent,xHeight:n,capHeight:r}}generateImage(e,t){const r=oe(t.right-t.left,t.bottom-t.top),n=r.getContext("2d");return n.font=this.fontString(),n.fillText(e,-t.left,-t.top),r}loadCanvas(){tt.canvas||(tt.setCanvas(oe(10,10)),tt.setContext(tt.canvas.getContext("2d",{willReadFrequently:!0})))}measureText(e,t){const r=e.measureText(t);if(null==r?void 0:r.actualBoundingBoxAscent)return r;e.canvas.width=1.5*this.size,e.canvas.height=1.5*this.size;const n=[0,this.size];e.clearRect(0,0,e.canvas.width,e.canvas.height),e.font=this.fontString(),e.fillText(t,n[0],n[1]);const a=e.getImageData(0,0,e.canvas.width,e.canvas.height),{left:i,top:o,right:s,bottom:l}=Ke(a);let u;e.clearRect(0,0,e.canvas.width,e.canvas.height);const c=this.fontBoundingBoxMap.find((e=>e.key===this.fontName));if(c)u=c.value;else{e.font=this.fontString(),e.fillText("测",n[0],n[1]);const t=e.getImageData(0,0,e.canvas.width,e.canvas.height);u=Ke(t),this.fontBoundingBoxMap.push({key:this.fontName,value:u}),e.clearRect(0,0,e.canvas.width,e.canvas.height)}return{actualBoundingBoxAscent:n[1]-o,actualBoundingBoxRight:s-n[0],actualBoundingBoxDescent:l-n[1],actualBoundingBoxLeft:n[0]-i,fontBoundingBoxAscent:u.bottom-u.top,fontBoundingBoxDescent:0,width:u.right-u.left}}}class rt{static create(e){return new rt(e)}static getLineCap(e){switch(e){case r.TGFXLineCap.Round:return"round";case r.TGFXLineCap.Square:return"square";default:return"butt"}}static getLineJoin(e){switch(e){case r.TGFXLineJoin.Round:return"round";case r.TGFXLineJoin.Bevel:return"bevel";default:return"miter"}}constructor(e){this.canvas=e,this.context=this.canvas.getContext("2d")}updateCanvas(e){this.canvas=e}fillPath(e,t){this.context.setTransform(1,0,0,1,0,0),t===r.TGFXPathFillType.InverseWinding||t===r.TGFXPathFillType.InverseEvenOdd?(this.context.clip(e,t===r.TGFXPathFillType.InverseEvenOdd?"evenodd":"nonzero"),this.context.fillRect(0,0,this.canvas.width,this.canvas.height)):this.context.fill(e,t===r.TGFXPathFillType.EvenOdd?"evenodd":"nonzero")}fillText(e,t,r,n){const a=new tt(e.name,e.style,e.size,e.bold,e.italic),i=new w(n);this.context.setTransform(i.a,i.b,i.c,i.d,i.tx,i.ty),this.context.font=a.fontString();for(let e=0;e<t.size();e++){const n=r.get(e);this.context.fillText(t.get(e),n.x,n.y)}}strokeText(e,t,r,n,a){if(t.width<.5)return;const i=new tt(e.name,e.style,e.size,e.bold,e.italic),o=new w(a);this.context.setTransform(o.a,o.b,o.c,o.d,o.tx,o.ty),this.context.font=i.fontString(),this.context.lineJoin=rt.getLineJoin(t.join),this.context.miterLimit=t.miterLimit,this.context.lineCap=rt.getLineCap(t.cap),this.context.lineWidth=t.width;for(let e=0;e<r.size();e++){const t=n.get(e);this.context.strokeText(r.get(e),t.x,t.y)}}clear(){this.context.clearRect(0,0,this.canvas.width,this.canvas.height)}}class nt{constructor(){this._canvas=null,this._glContext=null,this.width=J,this.height=J,this.retainCount=0}retain(){if(0===this.retainCount){try{this._canvas=new OffscreenCanvas(0,0)}catch(e){this._canvas=document.createElement("canvas")}this._canvas.width=this.width,this._canvas.height=this.height;const e=this._canvas.getContext("webgl",K);if(!e)throw new Error("Canvas context is not WebGL!");this._glContext=me.from(e)}this.retainCount+=1}release(){if(this.retainCount-=1,0===this.retainCount){if(!this._glContext)return;this._glContext.destroy(),this._glContext=null,this._canvas=null}}get canvas(){return this._canvas}get glContext(){return this._glContext}setCanvasSize(e=2560,t=2560){this.width=e,this.height=t,this._glContext&&this._canvas&&(this._canvas.width=e,this._canvas.height=t)}}var at=Object.defineProperty,it=Object.getOwnPropertyDescriptor;let ot=class extends A{static make(e,t,n=0,a="",i=""){return new ot("string"==typeof t?r._PAGTextLayer._Make(e,t,n,a,i):r._PAGTextLayer._Make(e,t))}fillColor(){return this.wasmIns._fillColor()}setFillColor(e){this.wasmIns._setFillColor(e)}font(){return new Be(this.wasmIns._font())}setFont(e){this.wasmIns._setFont(e.wasmIns)}fontSize(){return this.wasmIns._fontSize()}setFontSize(e){this.wasmIns._setFontSize(e)}strokeColor(){return this.wasmIns._strokeColor()}setStrokeColor(e){this.wasmIns._setStrokeColor(e)}text(){return this.wasmIns._text()}setText(e){this.wasmIns._setText(e)}reset(){this.wasmIns._reset()}};ot=((e,t,r,n)=>{for(var a,i=n>1?void 0:n?it(t,r):t,o=e.length-1;o>=0;o--)(a=e[o])&&(i=(n?a(t,r,i):a(i))||i);return n&&i&&at(t,r,i),i})([i,n],ot);var st=Object.defineProperty,lt=Object.getOwnPropertyDescriptor;let ut=class extends A{static make(e,t,n){const a=r._PAGImageLayer._Make(e,t,n);if(!a)throw new Error("Make PAGImageLayer fail!");return new ut(a)}contentDuration(){return this.wasmIns._contentDuration()}getVideoRanges(){return this.wasmIns._getVideoRanges()}replaceImage(e){this.wasmIns._replaceImage(e.wasmIns)}setImage(e){this.wasmIns._setImage(e.wasmIns)}layerTimeToContent(e){return this.wasmIns._layerTimeToContent(e)}contentTimeToLayer(e){return this.wasmIns._contentTimeToLayer(e)}imageBytes(){return this.wasmIns._imageBytes()}};ut=((e,t,r,n)=>{for(var a,i=n>1?void 0:n?lt(t,r):t,o=e.length-1;o>=0;o--)(a=e[o])&&(i=(n?a(t,r,i):a(i))||i);return n&&i&&st(t,r,i),i})([i,n],ut);var ct=Object.defineProperty,ft=Object.getOwnPropertyDescriptor;let dt=class extends A{static make(e,t,n,a,i){const o=r._PAGSolidLayer._Make(e,t,n,a,i);if(!o)throw new Error("Make PAGSolidLayer fail!");return new dt(o)}solidColor(){return this.wasmIns._solidColor()}setSolidColor(e){this.wasmIns._setSolidColor(e)}};dt=((e,t,r,n)=>{for(var a,i=n>1?void 0:n?ft(t,r):t,o=e.length-1;o>=0;o--)(a=e[o])&&(i=(n?a(t,r,i):a(i))||i);return n&&i&&ct(t,r,i),i})([i,n],dt);const ht=e=>new Promise((t=>{const r=new Image;r.onload=function(){t(r)},r.onerror=function(){console.error("image create from bytes error."),t(null)},r.src=e}));var mt=Object.freeze({__proto__:null,createImage:ht,createImageFromBytes:e=>{const t=new Blob([e],{type:"image/*"});return ht(URL.createObjectURL(t))},readImagePixels:(e,t,r,n)=>{if(!t)return null;const a=oe(r,n),i=a.getContext("2d");if(!i)return null;i.drawImage(t,0,0,r,n);const{data:o}=i.getImageData(0,0,r,n);return se(a),0===o.length?null:D(e,o)},hasWebpSupport:()=>{try{return 0===document.createElement("canvas").toDataURL("image/webp",.5).indexOf("data:image/webp")}catch(e){return!1}},getSourceSize:e=>x(e,globalThis.HTMLVideoElement)?{width:e.videoWidth,height:e.videoHeight}:{width:e.width,height:e.height},uploadToTexture:(e,t,r,n)=>{var a;let i=t instanceof ze?t.bitmap:t;if(!i)return;const o=null==(a=e.currentContext)?void 0:a.GLctx;o.bindTexture(o.TEXTURE_2D,e.textures[r]),n?(o.pixelStorei(o.UNPACK_ALIGNMENT,1),o.texSubImage2D(o.TEXTURE_2D,0,0,0,o.ALPHA,o.UNSIGNED_BYTE,i)):(o.pixelStorei(o.UNPACK_ALIGNMENT,4),o.pixelStorei(o.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),o.texSubImage2D(o.TEXTURE_2D,0,0,0,o.RGBA,o.UNSIGNED_BYTE,i),o.pixelStorei(o.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1))},isAndroidMiniprogram:()=>{if("undefined"!=typeof wx&&wx.getSystemInfoSync)return"android"===wx.getSystemInfoSync().platform},releaseNativeImage:e=>{var t;x(e,globalThis.ImageBitmap)?e.close():(ie(t=e)||x(t,globalThis.HTMLCanvasElement))&&se(e)},getBytesFromPath:async(e,t)=>{const r=await fetch(t).then((e=>e.arrayBuffer()));return D(e,r)},createCanvas2D:oe});var pt=Object.defineProperty,yt=Object.getOwnPro