libpag
Version:
Portable Animated Graphics
1,480 lines (1,456 loc) • 359 kB
JavaScript
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// Tencent is pleased to support the open source community by making libpag available.
//
// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// unless required by applicable law or agreed to in writing, software distributed under the
// license is distributed on an "as is" basis, without warranties or conditions of any kind,
// either express or implied. see the license for the specific language governing permissions
// and limitations under the license.
//
/////////////////////////////////////////////////////////////////////////////////////////////////
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.libpag = {}));
})(this, (function (exports) { 'use strict';
const getGlobalObject = () => {
if (typeof globalThis !== "undefined") {
return globalThis;
}
if (typeof window !== "undefined") {
return window;
}
if (typeof global !== "undefined") {
return global;
}
if (typeof self !== "undefined") {
return self;
}
throw new Error("unable to locate global object");
};
const globalObject = getGlobalObject();
if (typeof globalObject.globalThis === "undefined") {
Object.defineProperty(globalObject, "globalThis", {
get() {
return globalObject;
}
});
}
let PAGModule;
const setPAGModule = (module) => {
PAGModule = module;
};
function wasmAwaitRewind(constructor) {
const ignoreStaticFunctions = ["length", "name", "prototype", "wasmAsyncMethods"];
let staticFunctions = Object.getOwnPropertyNames(constructor).filter(
(name) => ignoreStaticFunctions.indexOf(name) === -1
);
if (constructor.wasmAsyncMethods && constructor.wasmAsyncMethods.length > 0) {
staticFunctions = staticFunctions.filter((name) => constructor.wasmAsyncMethods.indexOf(name) === -1);
}
let functions = Object.getOwnPropertyNames(constructor.prototype).filter(
(name) => name !== "constructor" && typeof constructor.prototype[name] === "function"
);
if (constructor.prototype.wasmAsyncMethods && constructor.prototype.wasmAsyncMethods.length > 0) {
functions = functions.filter((name) => constructor.prototype.wasmAsyncMethods.indexOf(name) === -1);
}
const proxyFn = (target, methodName) => {
const fn = target[methodName];
target[methodName] = function(...args) {
if (PAGModule.Asyncify.currData !== null) {
const currData = PAGModule.Asyncify.currData;
PAGModule.Asyncify.currData = null;
const ret = fn.call(this, ...args);
PAGModule.Asyncify.currData = currData;
return ret;
} else {
return fn.call(this, ...args);
}
};
};
staticFunctions.forEach((name) => proxyFn(constructor, name));
functions.forEach((name) => proxyFn(constructor.prototype, name));
}
function wasmAsyncMethod(target, propertyKey, descriptor) {
if (!target.wasmAsyncMethods) {
target.wasmAsyncMethods = [];
}
target.wasmAsyncMethods.push(propertyKey);
}
function destroyVerify(constructor) {
let functions = Object.getOwnPropertyNames(constructor.prototype).filter(
(name) => name !== "constructor" && typeof constructor.prototype[name] === "function"
);
const proxyFn = (target, methodName) => {
const fn = target[methodName];
target[methodName] = function(...args) {
if (this["isDestroyed"]) {
console.error(`Don't call ${methodName} of the ${constructor.name} that is destroyed.`);
return;
}
return fn.call(this, ...args);
};
};
functions.forEach((name) => proxyFn(constructor.prototype, name));
}
var PAGScaleMode = /* @__PURE__ */ ((PAGScaleMode2) => {
PAGScaleMode2[PAGScaleMode2["None"] = 0] = "None";
PAGScaleMode2[PAGScaleMode2["Stretch"] = 1] = "Stretch";
PAGScaleMode2[PAGScaleMode2["LetterBox"] = 2] = "LetterBox";
PAGScaleMode2[PAGScaleMode2["Zoom"] = 3] = "Zoom";
return PAGScaleMode2;
})(PAGScaleMode || {});
var PAGViewListenerEvent = /* @__PURE__ */ ((PAGViewListenerEvent2) => {
PAGViewListenerEvent2["onAnimationStart"] = "onAnimationStart";
PAGViewListenerEvent2["onAnimationEnd"] = "onAnimationEnd";
PAGViewListenerEvent2["onAnimationCancel"] = "onAnimationCancel";
PAGViewListenerEvent2["onAnimationRepeat"] = "onAnimationRepeat";
PAGViewListenerEvent2["onAnimationUpdate"] = "onAnimationUpdate";
PAGViewListenerEvent2["onAnimationPlay"] = "onAnimationPlay";
PAGViewListenerEvent2["onAnimationPause"] = "onAnimationPause";
PAGViewListenerEvent2["onAnimationFlushed"] = "onAnimationFlushed";
return PAGViewListenerEvent2;
})(PAGViewListenerEvent || {});
var ParagraphJustification = /* @__PURE__ */ ((ParagraphJustification2) => {
ParagraphJustification2[ParagraphJustification2["LeftJustify"] = 0] = "LeftJustify";
ParagraphJustification2[ParagraphJustification2["CenterJustify"] = 1] = "CenterJustify";
ParagraphJustification2[ParagraphJustification2["RightJustify"] = 2] = "RightJustify";
ParagraphJustification2[ParagraphJustification2["FullJustifyLastLineLeft"] = 3] = "FullJustifyLastLineLeft";
ParagraphJustification2[ParagraphJustification2["FullJustifyLastLineRight"] = 4] = "FullJustifyLastLineRight";
ParagraphJustification2[ParagraphJustification2["FullJustifyLastLineCenter"] = 5] = "FullJustifyLastLineCenter";
ParagraphJustification2[ParagraphJustification2["FullJustifyLastLineFull"] = 6] = "FullJustifyLastLineFull";
return ParagraphJustification2;
})(ParagraphJustification || {});
var TextDirection = /* @__PURE__ */ ((TextDirection2) => {
TextDirection2[TextDirection2["Default"] = 0] = "Default";
TextDirection2[TextDirection2["Horizontal"] = 1] = "Horizontal";
TextDirection2[TextDirection2["Vertical"] = 2] = "Vertical";
return TextDirection2;
})(TextDirection || {});
var LayerType = /* @__PURE__ */ ((LayerType2) => {
LayerType2[LayerType2["Unknown"] = 0] = "Unknown";
LayerType2[LayerType2["Null"] = 1] = "Null";
LayerType2[LayerType2["Solid"] = 2] = "Solid";
LayerType2[LayerType2["Text"] = 3] = "Text";
LayerType2[LayerType2["Shape"] = 4] = "Shape";
LayerType2[LayerType2["Image"] = 5] = "Image";
LayerType2[LayerType2["PreCompose"] = 6] = "PreCompose";
return LayerType2;
})(LayerType || {});
var PAGTimeStretchMode = /* @__PURE__ */ ((PAGTimeStretchMode2) => {
PAGTimeStretchMode2[PAGTimeStretchMode2["None"] = 0] = "None";
PAGTimeStretchMode2[PAGTimeStretchMode2["Scale"] = 1] = "Scale";
PAGTimeStretchMode2[PAGTimeStretchMode2["Repeat"] = 2] = "Repeat";
PAGTimeStretchMode2[PAGTimeStretchMode2["RepeatInverted"] = 3] = "RepeatInverted";
return PAGTimeStretchMode2;
})(PAGTimeStretchMode || {});
var MatrixIndex = /* @__PURE__ */ ((MatrixIndex2) => {
MatrixIndex2[MatrixIndex2["a"] = 0] = "a";
MatrixIndex2[MatrixIndex2["c"] = 1] = "c";
MatrixIndex2[MatrixIndex2["tx"] = 2] = "tx";
MatrixIndex2[MatrixIndex2["b"] = 3] = "b";
MatrixIndex2[MatrixIndex2["d"] = 4] = "d";
MatrixIndex2[MatrixIndex2["ty"] = 5] = "ty";
return MatrixIndex2;
})(MatrixIndex || {});
var DecoderResult = /* @__PURE__ */ ((DecoderResult2) => {
DecoderResult2[DecoderResult2["Success"] = 0] = "Success";
DecoderResult2[DecoderResult2["TryAgainLater"] = -1] = "TryAgainLater";
DecoderResult2[DecoderResult2["Error"] = -2] = "Error";
return DecoderResult2;
})(DecoderResult || {});
var ColorType = /* @__PURE__ */ ((ColorType2) => {
ColorType2[ColorType2["Unknown"] = 0] = "Unknown";
ColorType2[ColorType2["ALPHA_8"] = 1] = "ALPHA_8";
ColorType2[ColorType2["RGBA_8888"] = 2] = "RGBA_8888";
ColorType2[ColorType2["BGRA_8888"] = 3] = "BGRA_8888";
return ColorType2;
})(ColorType || {});
var AlphaType = /* @__PURE__ */ ((AlphaType2) => {
AlphaType2[AlphaType2["Unknown"] = 0] = "Unknown";
AlphaType2[AlphaType2["Opaque"] = 1] = "Opaque";
AlphaType2[AlphaType2["Premultiplied"] = 2] = "Premultiplied";
AlphaType2[AlphaType2["Unpremultiplied"] = 3] = "Unpremultiplied";
return AlphaType2;
})(AlphaType || {});
var types = /*#__PURE__*/Object.freeze({
__proto__: null,
PAGScaleMode: PAGScaleMode,
PAGViewListenerEvent: PAGViewListenerEvent,
ParagraphJustification: ParagraphJustification,
TextDirection: TextDirection,
LayerType: LayerType,
PAGTimeStretchMode: PAGTimeStretchMode,
MatrixIndex: MatrixIndex,
DecoderResult: DecoderResult,
ColorType: ColorType,
AlphaType: AlphaType
});
var __defProp$e = Object.defineProperty;
var __getOwnPropDesc$b = Object.getOwnPropertyDescriptor;
var __decorateClass$b = (decorators, target, key, kind) => {
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$b(target, key) : target;
for (var i = decorators.length - 1, decorator; i >= 0; i--)
if (decorator = decorators[i])
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
if (kind && result)
__defProp$e(target, key, result);
return result;
};
let Matrix = class {
constructor(wasmIns) {
this.isDestroyed = false;
this.wasmIns = wasmIns;
}
static makeAll(scaleX, skewX, transX, skewY, scaleY, transY, pers0 = 0, pers1 = 0, pers2 = 1) {
const wasmIns = PAGModule._Matrix._MakeAll(scaleX, skewX, transX, skewY, scaleY, transY, pers0, pers1, pers2);
if (!wasmIns)
throw new Error("Matrix.makeAll fail, please check parameters valid!");
return new Matrix(wasmIns);
}
static makeScale(scaleX, scaleY) {
let wasmIns;
if (scaleY !== void 0) {
wasmIns = PAGModule._Matrix._MakeScale(scaleX, scaleY);
} else {
wasmIns = PAGModule._Matrix._MakeScale(scaleX);
}
if (!wasmIns)
throw new Error("Matrix.makeScale fail, please check parameters valid!");
return new Matrix(wasmIns);
}
static makeTrans(dx, dy) {
const wasmIns = PAGModule._Matrix._MakeTrans(dx, dy);
if (!wasmIns)
throw new Error("Matrix.makeTrans fail, please check parameters valid!");
return new Matrix(wasmIns);
}
get a() {
return this.wasmIns ? this.wasmIns._get(MatrixIndex.a) : 0;
}
set a(value) {
var _a;
(_a = this.wasmIns) == null ? void 0 : _a._set(MatrixIndex.a, value);
}
get b() {
return this.wasmIns ? this.wasmIns._get(MatrixIndex.b) : 0;
}
set b(value) {
var _a;
(_a = this.wasmIns) == null ? void 0 : _a._set(MatrixIndex.b, value);
}
get c() {
return this.wasmIns ? this.wasmIns._get(MatrixIndex.c) : 0;
}
set c(value) {
var _a;
(_a = this.wasmIns) == null ? void 0 : _a._set(MatrixIndex.c, value);
}
get d() {
return this.wasmIns ? this.wasmIns._get(MatrixIndex.d) : 0;
}
set d(value) {
var _a;
(_a = this.wasmIns) == null ? void 0 : _a._set(MatrixIndex.d, value);
}
get tx() {
return this.wasmIns ? this.wasmIns._get(MatrixIndex.tx) : 0;
}
set tx(value) {
var _a;
(_a = this.wasmIns) == null ? void 0 : _a._set(MatrixIndex.tx, value);
}
get ty() {
return this.wasmIns ? this.wasmIns._get(MatrixIndex.ty) : 0;
}
set ty(value) {
var _a;
(_a = this.wasmIns) == null ? void 0 : _a._set(MatrixIndex.ty, value);
}
get(index) {
return this.wasmIns ? this.wasmIns._get(index) : 0;
}
set(index, value) {
var _a;
(_a = this.wasmIns) == null ? void 0 : _a._set(index, value);
}
setAll(scaleX, skewX, transX, skewY, scaleY, transY) {
var _a;
(_a = this.wasmIns) == null ? void 0 : _a._setAll(scaleX, skewX, transX, skewY, scaleY, transY, 0, 0, 1);
}
setAffine(a, b, c, d, tx, ty) {
var _a;
(_a = this.wasmIns) == null ? void 0 : _a._setAffine(a, b, c, d, tx, ty);
}
reset() {
var _a;
(_a = this.wasmIns) == null ? void 0 : _a._reset();
}
setTranslate(dx, dy) {
var _a;
(_a = this.wasmIns) == null ? void 0 : _a._setTranslate(dx, dy);
}
setScale(sx, sy, px = 0, py = 0) {
var _a;
(_a = this.wasmIns) == null ? void 0 : _a._setScale(sx, sy, px, py);
}
setRotate(degrees, px = 0, py = 0) {
var _a;
(_a = this.wasmIns) == null ? void 0 : _a._setRotate(degrees, px, py);
}
setSinCos(sinV, cosV, px = 0, py = 0) {
var _a;
(_a = this.wasmIns) == null ? void 0 : _a._setSinCos(sinV, cosV, px, py);
}
setSkew(kx, ky, px = 0, py = 0) {
var _a;
(_a = this.wasmIns) == null ? void 0 : _a._setSkew(kx, ky, px, py);
}
setConcat(a, b) {
var _a;
(_a = this.wasmIns) == null ? void 0 : _a._setConcat(a.wasmIns, b.wasmIns);
}
preTranslate(dx, dy) {
var _a;
(_a = this.wasmIns) == null ? void 0 : _a._preTranslate(dx, dy);
}
preScale(sx, sy, px = 0, py = 0) {
var _a;
(_a = this.wasmIns) == null ? void 0 : _a._preScale(sx, sy, px, py);
}
preRotate(degrees, px = 0, py = 0) {
var _a;
(_a = this.wasmIns) == null ? void 0 : _a._preRotate(degrees, px, py);
}
preSkew(kx, ky, px = 0, py = 0) {
var _a;
(_a = this.wasmIns) == null ? void 0 : _a._preSkew(kx, ky, px, py);
}
preConcat(other) {
var _a;
(_a = this.wasmIns) == null ? void 0 : _a._preConcat(other.wasmIns);
}
postTranslate(dx, dy) {
var _a;
(_a = this.wasmIns) == null ? void 0 : _a._postTranslate(dx, dy);
}
postScale(sx, sy, px = 0, py = 0) {
var _a;
(_a = this.wasmIns) == null ? void 0 : _a._postScale(sx, sy, px, py);
}
postRotate(degrees, px = 0, py = 0) {
var _a;
(_a = this.wasmIns) == null ? void 0 : _a._postRotate(degrees, px, py);
}
postSkew(kx, ky, px = 0, py = 0) {
var _a;
(_a = this.wasmIns) == null ? void 0 : _a._postSkew(kx, ky, px, py);
}
postConcat(other) {
var _a;
(_a = this.wasmIns) == null ? void 0 : _a._postConcat(other.wasmIns);
}
destroy() {
this.wasmIns.delete();
}
};
Matrix = __decorateClass$b([
destroyVerify,
wasmAwaitRewind
], Matrix);
const rewindData = (fn, scope, ...args) => {
if (PAGModule.Asyncify.currData !== null) {
const currData = PAGModule.Asyncify.currData;
PAGModule.Asyncify.currData = null;
const ret = fn.call(scope, ...args);
PAGModule.Asyncify.currData = currData;
return ret;
} else {
return fn.call(scope, ...args);
}
};
const proxyVector = (vector, process) => {
const proxy = new Proxy(vector, {
get(target, property, receiver) {
switch (property) {
case "get":
return (index) => {
const wasmIns = rewindData(target.get, target, index);
return !wasmIns ? wasmIns : process(wasmIns);
};
case "push_back":
return (value) => {
rewindData(target.push_back, target, value.wasmIns || value);
return void 0;
};
case "size":
return () => {
return rewindData(target.size, target);
};
default:
return Reflect.get(target, property, receiver);
}
}
});
return proxy;
};
const layer2typeLayer = (wasmIns) => {
switch (rewindData(wasmIns._layerType, wasmIns)) {
case LayerType.Solid:
return new PAGModule.PAGSolidLayer(wasmIns);
case LayerType.Text:
return new PAGModule.PAGTextLayer(wasmIns);
case LayerType.Image:
return new PAGModule.PAGImageLayer(wasmIns);
default:
return new PAGModule.PAGLayer(wasmIns);
}
};
const getLayerTypeName = (layerType) => {
switch (layerType) {
case LayerType.Solid:
return "Solid";
case LayerType.Text:
return "Text";
case LayerType.Shape:
return "Shape";
case LayerType.Image:
return "Image";
case LayerType.PreCompose:
return "PreCompose";
default:
return "Unknown";
}
};
const getWasmIns = (value) => {
if (value == null ? void 0 : value.wasmIns) {
return value.wasmIns;
}
return value;
};
const isInstanceOf = (value, type) => typeof type !== "undefined" && value instanceof type;
var __defProp$d = Object.defineProperty;
var __getOwnPropDesc$a = Object.getOwnPropertyDescriptor;
var __decorateClass$a = (decorators, target, key, kind) => {
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$a(target, key) : target;
for (var i = decorators.length - 1, decorator; i >= 0; i--)
if (decorator = decorators[i])
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
if (kind && result)
__defProp$d(target, key, result);
return result;
};
let PAGLayer = class {
constructor(wasmIns) {
this.isDestroyed = false;
this.wasmIns = wasmIns;
}
uniqueID() {
return this.wasmIns._uniqueID();
}
layerType() {
return this.wasmIns._layerType();
}
layerName() {
return this.wasmIns._layerName();
}
matrix() {
const wasmIns = this.wasmIns._matrix();
if (!wasmIns)
throw new Error("Get matrix fail!");
return new Matrix(wasmIns);
}
setMatrix(matrix) {
this.wasmIns._setMatrix(matrix.wasmIns);
}
resetMatrix() {
this.wasmIns._resetMatrix();
}
getTotalMatrix() {
const wasmIns = this.wasmIns._getTotalMatrix();
if (!wasmIns)
throw new Error("Get total matrix fail!");
return new Matrix(this.wasmIns._getTotalMatrix());
}
alpha() {
return this.wasmIns._alpha();
}
setAlpha(opacity) {
this.wasmIns._setAlpha(opacity);
}
visible() {
return this.wasmIns._visible();
}
setVisible(visible) {
this.wasmIns._setVisible(visible);
}
editableIndex() {
return this.wasmIns._editableIndex();
}
parent() {
const wasmIns = this.wasmIns._parent();
if (!wasmIns)
throw new Error("Get total matrix fail!");
return new PAGComposition(wasmIns);
}
markers() {
const wasmIns = this.wasmIns._markers();
if (!wasmIns)
throw new Error("Get markers fail!");
return proxyVector(wasmIns, (wasmIns2) => wasmIns2);
}
localTimeToGlobal(localTime) {
return this.wasmIns._localTimeToGlobal(localTime);
}
globalToLocalTime(globalTime) {
return this.wasmIns._globalToLocalTime(globalTime);
}
duration() {
return this.wasmIns._duration();
}
frameRate() {
return this.wasmIns._frameRate();
}
startTime() {
return this.wasmIns._startTime();
}
setStartTime(time) {
this.wasmIns._setStartTime(time);
}
currentTime() {
return this.wasmIns._currentTime();
}
setCurrentTime(time) {
this.wasmIns._setCurrentTime(time);
}
getProgress() {
return this.wasmIns._getProgress();
}
setProgress(percent) {
this.wasmIns._setProgress(percent);
}
preFrame() {
this.wasmIns._preFrame();
}
nextFrame() {
this.wasmIns._nextFrame();
}
getBounds() {
return this.wasmIns._getBounds();
}
trackMatteLayer() {
const wasmIns = this.wasmIns._trackMatteLayer();
if (!wasmIns)
throw new Error("Get track matte layer fail!");
return layer2typeLayer(wasmIns);
}
excludedFromTimeline() {
return this.wasmIns._excludedFromTimeline();
}
setExcludedFromTimeline(value) {
this.wasmIns._setExcludedFromTimeline(value);
}
isPAGFile() {
return this.wasmIns._isPAGFile();
}
asTypeLayer() {
return layer2typeLayer(this);
}
isDelete() {
return this.wasmIns.isDelete();
}
destroy() {
this.wasmIns.delete();
this.isDestroyed = true;
}
};
PAGLayer = __decorateClass$a([
destroyVerify,
wasmAwaitRewind
], PAGLayer);
var __defProp$c = Object.defineProperty;
var __getOwnPropDesc$9 = Object.getOwnPropertyDescriptor;
var __decorateClass$9 = (decorators, target, key, kind) => {
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$9(target, key) : target;
for (var i = decorators.length - 1, decorator; i >= 0; i--)
if (decorator = decorators[i])
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
if (kind && result)
__defProp$c(target, key, result);
return result;
};
let PAGComposition = class extends PAGLayer {
static make(width, height) {
const wasmIns = PAGModule._PAGComposition._Make(width, height);
if (!wasmIns)
throw new Error("Make PAGComposition fail!");
return new PAGComposition(wasmIns);
}
width() {
return this.wasmIns._width();
}
height() {
return this.wasmIns._height();
}
setContentSize(width, height) {
this.wasmIns._setContentSize(width, height);
}
numChildren() {
return this.wasmIns._numChildren();
}
getLayerAt(index) {
const wasmIns = this.wasmIns._getLayerAt(index);
if (!wasmIns)
throw new Error(`Get layer at ${index} fail!`);
return layer2typeLayer(wasmIns);
}
getLayerIndex(pagLayer) {
return this.wasmIns._getLayerIndex(pagLayer.wasmIns);
}
setLayerIndex(pagLayer, index) {
return this.wasmIns._setLayerIndex(pagLayer.wasmIns, index);
}
addLayer(pagLayer) {
return this.wasmIns._addLayer(pagLayer.wasmIns);
}
addLayerAt(pagLayer, index) {
return this.wasmIns._addLayerAt(pagLayer.wasmIns, index);
}
contains(pagLayer) {
return this.wasmIns._contains(pagLayer.wasmIns);
}
removeLayer(pagLayer) {
const wasmIns = this.wasmIns._removeLayer(pagLayer.wasmIns);
if (!wasmIns)
throw new Error("Remove layer fail!");
return layer2typeLayer(wasmIns);
}
removeLayerAt(index) {
const wasmIns = this.wasmIns._removeLayerAt(index);
if (!wasmIns)
throw new Error(`Remove layer at ${index} fail!`);
return layer2typeLayer(wasmIns);
}
removeAllLayers() {
this.wasmIns._removeAllLayers();
}
swapLayer(pagLayer1, pagLayer2) {
this.wasmIns._swapLayer(pagLayer1.wasmIns, pagLayer2.wasmIns);
}
swapLayerAt(index1, index2) {
this.wasmIns._swapLayerAt(index1, index2);
}
audioBytes() {
return this.wasmIns._audioBytes();
}
audioMarkers() {
const wasmIns = this.wasmIns._audioMarkers();
if (!wasmIns)
throw new Error(`Get audioMarkers fail!`);
return proxyVector(wasmIns, (wasmIns2) => wasmIns2);
}
audioStartTime() {
return this.wasmIns._audioStartTime();
}
getLayersByName(layerName) {
const wasmIns = this.wasmIns._getLayersByName(layerName);
if (!wasmIns)
throw new Error(`Get layers by ${layerName} fail!`);
return proxyVector(wasmIns, layer2typeLayer);
}
getLayersUnderPoint(localX, localY) {
const wasmIns = this.wasmIns._getLayersUnderPoint(localX, localY);
if (!wasmIns)
throw new Error(`Get layers under point ${localX},${localY} fail!`);
return proxyVector(wasmIns, layer2typeLayer);
}
};
PAGComposition = __decorateClass$9([
destroyVerify,
wasmAwaitRewind
], PAGComposition);
const readFile = (file) => new Promise((resolve) => {
const reader = new FileReader();
reader.onload = () => {
resolve(reader.result);
};
reader.onerror = () => {
console.error(reader.error.message);
};
reader.readAsArrayBuffer(file);
});
const transferToArrayBuffer = (data) => {
if (isInstanceOf(data, globalThis.File)) {
return readFile(data);
} else if (isInstanceOf(data, globalThis.Blob)) {
return readFile(new File([data], ""));
} else if (isInstanceOf(data, globalThis.ArrayBuffer)) {
return Promise.resolve(data);
}
return Promise.resolve(null);
};
const writeBufferToWasm = (module, data) => {
const uint8Array = new Uint8Array(data);
const numBytes = uint8Array.byteLength;
const dataPtr = module._malloc(numBytes);
const dataOnHeap = new Uint8Array(module.HEAPU8.buffer, dataPtr, numBytes);
dataOnHeap.set(uint8Array);
return { byteOffset: dataPtr, length: numBytes, free: () => module._free(dataPtr) };
};
const readBufferFromWasm = (module, data, handle) => {
const uint8Array = new Uint8Array(data);
const dataPtr = module._malloc(uint8Array.byteLength);
if (!handle(dataPtr, uint8Array.byteLength))
return { data: null, free: () => module._free(dataPtr) };
const dataOnHeap = new Uint8Array(module.HEAPU8.buffer, dataPtr, uint8Array.byteLength);
uint8Array.set(dataOnHeap);
return { data: uint8Array, free: () => module._free(dataPtr) };
};
var __defProp$b = Object.defineProperty;
var __getOwnPropDesc$8 = Object.getOwnPropertyDescriptor;
var __decorateClass$8 = (decorators, target, key, kind) => {
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$8(target, key) : target;
for (var i = decorators.length - 1, decorator; i >= 0; i--)
if (decorator = decorators[i])
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
if (kind && result)
__defProp$b(target, key, result);
return result;
};
let PAGFile = class extends PAGComposition {
static async load(data) {
const buffer = await transferToArrayBuffer(data);
if (!buffer)
throw new Error(
"Initialize PAGFile data type error, please put check data type must to be File \uFF5C Blob | ArrayBuffer!"
);
return PAGFile.loadFromBuffer(buffer);
}
static loadFromBuffer(buffer) {
if (!buffer || !(buffer.byteLength > 0))
throw new Error("Initialize PAGFile data not be empty!");
const { byteOffset, length, free } = writeBufferToWasm(PAGModule, buffer);
const wasmIns = PAGModule._PAGFile._Load(byteOffset, length);
free();
if (!wasmIns)
throw new Error("Load PAGFile fail!");
const pagFile = new PAGFile(wasmIns);
return pagFile;
}
static maxSupportedTagLevel() {
return PAGModule._PAGFile._MaxSupportedTagLevel();
}
tagLevel() {
return this.wasmIns._tagLevel();
}
numTexts() {
return this.wasmIns._numTexts();
}
numImages() {
return this.wasmIns._numImages();
}
numVideos() {
return this.wasmIns._numVideos();
}
getTextData(editableTextIndex) {
return this.wasmIns._getTextData(editableTextIndex);
}
replaceText(editableTextIndex, textData) {
this.wasmIns._replaceText(editableTextIndex, textData);
}
replaceImage(editableImageIndex, pagImage) {
this.wasmIns._replaceImage(editableImageIndex, pagImage.wasmIns);
}
getLayersByEditableIndex(editableIndex, layerType) {
const wasmIns = this.wasmIns._getLayersByEditableIndex(editableIndex, layerType);
if (!wasmIns)
throw new Error(`Get ${getLayerTypeName(layerType)} layers by ${editableIndex} fail!`);
return proxyVector(wasmIns, layer2typeLayer);
}
getEditableIndices(layerType) {
return this.wasmIns._getEditableIndices(layerType);
}
timeStretchMode() {
return this.wasmIns._timeStretchMode();
}
setTimeStretchMode(value) {
this.wasmIns._setTimeStretchMode(value);
}
setDuration(duration) {
this.wasmIns._setDuration(duration);
}
copyOriginal() {
const wasmIns = this.wasmIns._copyOriginal();
if (!wasmIns)
throw new Error(`Copy original fail!`);
return new PAGFile(wasmIns);
}
};
__decorateClass$8([
wasmAsyncMethod
], PAGFile, "load", 1);
PAGFile = __decorateClass$8([
destroyVerify,
wasmAwaitRewind
], PAGFile);
var __defProp$a = Object.defineProperty;
var __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor;
var __decorateClass$7 = (decorators, target, key, kind) => {
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target;
for (var i = decorators.length - 1, decorator; i >= 0; i--)
if (decorator = decorators[i])
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
if (kind && result)
__defProp$a(target, key, result);
return result;
};
let PAGSurface = class {
constructor(wasmIns) {
this.isDestroyed = false;
this.wasmIns = wasmIns;
}
static fromCanvas(canvasID) {
const wasmIns = PAGModule._PAGSurface._FromCanvas(canvasID);
if (!wasmIns)
throw new Error(`Make PAGSurface from canvas ${canvasID} fail!`);
return new PAGSurface(wasmIns);
}
static fromTexture(textureID, width, height, flipY) {
const wasmIns = PAGModule._PAGSurface._FromTexture(textureID, width, height, flipY);
if (!wasmIns)
throw new Error(`Make PAGSurface from texture ${textureID} fail!`);
return new PAGSurface(wasmIns);
}
static fromRenderTarget(frameBufferID, width, height, flipY) {
const wasmIns = PAGModule._PAGSurface._FromRenderTarget(frameBufferID, width, height, flipY);
if (!wasmIns)
throw new Error(`Make PAGSurface from frameBuffer ${frameBufferID} fail!`);
return new PAGSurface(wasmIns);
}
width() {
return this.wasmIns._width();
}
height() {
return this.wasmIns._height();
}
updateSize() {
this.wasmIns._updateSize();
}
clearAll() {
return this.wasmIns._clearAll();
}
freeCache() {
this.wasmIns._freeCache();
}
readPixels(colorType, alphaType) {
if (colorType === ColorType.Unknown)
return null;
const rowBytes = this.width() * (colorType === ColorType.ALPHA_8 ? 1 : 4);
const length = rowBytes * this.height();
const dataUint8Array = new Uint8Array(length);
const { data, free } = readBufferFromWasm(PAGModule, dataUint8Array, (dataPtr) => {
return this.wasmIns._readPixels(colorType, alphaType, dataPtr, rowBytes);
});
free();
return data;
}
destroy() {
this.wasmIns.delete();
this.isDestroyed = true;
}
};
PAGSurface = __decorateClass$7([
destroyVerify,
wasmAwaitRewind
], PAGSurface);
var __defProp$9 = Object.defineProperty;
var __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor;
var __decorateClass$6 = (decorators, target, key, kind) => {
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target;
for (var i = decorators.length - 1, decorator; i >= 0; i--)
if (decorator = decorators[i])
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
if (kind && result)
__defProp$9(target, key, result);
return result;
};
let PAGPlayer = class {
constructor(wasmIns) {
this.isDestroyed = false;
this.videoReaders = [];
this.wasmIns = wasmIns;
}
static create() {
const wasmIns = new PAGModule._PAGPlayer();
if (!wasmIns)
throw new Error("Create PAGPlayer fail!");
return new PAGPlayer(wasmIns);
}
setProgress(progress) {
this.wasmIns._setProgress(progress);
}
async flush() {
return PAGModule.webAssemblyQueue.exec(this.wasmIns._flush, this.wasmIns);
}
async flushInternal(callback) {
const res = await PAGModule.webAssemblyQueue.exec(async () => {
PAGModule.currentPlayer = this;
const res2 = await this.wasmIns._flush();
PAGModule.currentPlayer = null;
callback(res2);
return res2;
}, this.wasmIns);
for (const videoReader of this.videoReaders) {
const error = await videoReader.getError();
if (error !== null) {
throw error;
}
}
return res;
}
duration() {
return this.wasmIns._duration();
}
getProgress() {
return this.wasmIns._getProgress();
}
currentFrame() {
return this.wasmIns._currentFrame();
}
videoEnabled() {
return this.wasmIns._videoEnabled();
}
setVideoEnabled(enabled) {
this.wasmIns._setVideoEnabled(enabled);
}
cacheEnabled() {
return this.wasmIns._cacheEnabled();
}
setCacheEnabled(enabled) {
this.wasmIns._setCacheEnabled(enabled);
}
cacheScale() {
return this.wasmIns._cacheScale();
}
setCacheScale(value) {
this.wasmIns._setCacheScale(value);
}
maxFrameRate() {
return this.wasmIns._maxFrameRate();
}
setMaxFrameRate(value) {
this.wasmIns._setMaxFrameRate(value);
}
scaleMode() {
return this.wasmIns._scaleMode();
}
setScaleMode(value) {
this.wasmIns._setScaleMode(value);
}
setSurface(pagSurface) {
this.wasmIns._setSurface(getWasmIns(pagSurface));
}
getComposition() {
const wasmIns = this.wasmIns._getComposition();
if (!wasmIns)
throw new Error("Get composition fail!");
if (wasmIns._isPAGFile()) {
return new PAGFile(wasmIns);
}
return new PAGComposition(wasmIns);
}
setComposition(pagComposition) {
this.wasmIns._setComposition(getWasmIns(pagComposition));
}
getSurface() {
const wasmIns = this.wasmIns._getSurface();
if (!wasmIns)
throw new Error("Get surface fail!");
return new PAGSurface(wasmIns);
}
matrix() {
const wasmIns = this.wasmIns._matrix();
if (!wasmIns)
throw new Error("Get matrix fail!");
return new Matrix(wasmIns);
}
setMatrix(matrix) {
this.wasmIns._setMatrix(matrix.wasmIns);
}
nextFrame() {
this.wasmIns._nextFrame();
}
preFrame() {
this.wasmIns._preFrame();
}
autoClear() {
return this.wasmIns._autoClear();
}
setAutoClear(value) {
this.wasmIns._setAutoClear(value);
}
getBounds(pagLayer) {
return this.wasmIns._getBounds(pagLayer.wasmIns);
}
getLayersUnderPoint(localX, localY) {
const wasmIns = this.wasmIns._getLayersUnderPoint(localX, localY);
if (!wasmIns)
throw new Error(`Get layers under point, x: ${localX} y:${localY} fail!`);
return proxyVector(wasmIns, layer2typeLayer);
}
hitTestPoint(pagLayer, surfaceX, surfaceY, pixelHitTest = false) {
return this.wasmIns._hitTestPoint(pagLayer.wasmIns, surfaceX, surfaceY, pixelHitTest);
}
renderingTime() {
return this.wasmIns._renderingTime();
}
imageDecodingTime() {
return this.wasmIns._imageDecodingTime();
}
presentingTime() {
return this.wasmIns._presentingTime();
}
graphicsMemory() {
return this.wasmIns._graphicsMemory();
}
prepare() {
return PAGModule.webAssemblyQueue.exec(async () => {
PAGModule.currentPlayer = this;
await this.wasmIns._prepare();
PAGModule.currentPlayer = null;
}, this.wasmIns);
}
destroy() {
this.wasmIns.delete();
this.isDestroyed = true;
}
linkVideoReader(videoReader) {
this.videoReaders.push(videoReader);
}
unlinkVideoReader(videoReader) {
const index = this.videoReaders.indexOf(videoReader);
if (index !== -1) {
this.videoReaders.splice(index, 1);
}
}
};
__decorateClass$6([
wasmAsyncMethod
], PAGPlayer.prototype, "flush", 1);
__decorateClass$6([
wasmAsyncMethod
], PAGPlayer.prototype, "flushInternal", 1);
PAGPlayer = __decorateClass$6([
destroyVerify,
wasmAwaitRewind
], PAGPlayer);
var __defProp$8 = Object.defineProperty;
var __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor;
var __decorateClass$5 = (decorators, target, key, kind) => {
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target;
for (var i = decorators.length - 1, decorator; i >= 0; i--)
if (decorator = decorators[i])
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
if (kind && result)
__defProp$8(target, key, result);
return result;
};
let PAGImage = class {
constructor(wasmIns) {
this.isDestroyed = false;
this.wasmIns = wasmIns;
}
static async fromFile(data) {
return new Promise((resolve, reject) => {
const image = new Image();
image.onload = async () => {
resolve(PAGImage.fromSource(image));
};
image.onerror = (error) => {
reject(error);
};
image.src = URL.createObjectURL(data);
});
}
static fromSource(source) {
const wasmIns = PAGModule._PAGImage._FromNativeImage(source);
if (!wasmIns)
throw new Error("Make PAGImage from source fail!");
return new PAGImage(wasmIns);
}
static fromPixels(pixels, width, height, colorType, alphaType) {
const rowBytes = width * (colorType === ColorType.ALPHA_8 ? 1 : 4);
const { byteOffset, free } = writeBufferToWasm(PAGModule, pixels);
const wasmIns = PAGModule._PAGImage._FromPixels(byteOffset, width, height, rowBytes, colorType, alphaType);
free();
if (!wasmIns)
throw new Error("Make PAGImage from pixels fail!");
return new PAGImage(wasmIns);
}
static fromTexture(textureID, width, height, flipY) {
const wasmIns = PAGModule._PAGImage._FromTexture(textureID, width, height, flipY);
if (!wasmIns)
throw new Error("Make PAGImage from texture fail!");
return new PAGImage(wasmIns);
}
width() {
return this.wasmIns._width();
}
height() {
return this.wasmIns._height();
}
scaleMode() {
return this.wasmIns._scaleMode();
}
setScaleMode(scaleMode) {
this.wasmIns._setScaleMode(scaleMode);
}
matrix() {
const wasmIns = this.wasmIns._matrix();
if (!wasmIns)
throw new Error("Get matrix fail!");
return new Matrix(wasmIns);
}
setMatrix(matrix) {
this.wasmIns._setMatrix(matrix.wasmIns);
}
destroy() {
this.wasmIns.delete();
this.isDestroyed = true;
}
};
__decorateClass$5([
wasmAsyncMethod
], PAGImage, "fromFile", 1);
PAGImage = __decorateClass$5([
destroyVerify,
wasmAwaitRewind
], PAGImage);
class EventManager {
constructor() {
this.listenerMap = /* @__PURE__ */ new Map();
}
on(eventName, listener) {
let listenerList = [];
if (this.listenerMap.has(eventName)) {
listenerList = this.listenerMap.get(eventName);
}
listenerList.push(listener);
this.listenerMap.set(eventName, listenerList);
}
off(eventName, listener) {
if (!this.listenerMap.has(eventName))
return false;
const listenerList = this.listenerMap.get(eventName);
if (listenerList.length === 0)
return false;
if (!listener) {
this.listenerMap.delete(eventName);
return true;
}
const index = listenerList.indexOf(listener);
if (index === -1)
return false;
listenerList.splice(index, 1);
return true;
}
emit(eventName, event) {
if (!this.listenerMap.has(eventName))
return false;
const listenerList = this.listenerMap.get(eventName);
if (listenerList.length === 0)
return false;
listenerList.forEach((listener) => listener(event));
return true;
}
}
const VIDEO_DECODE_WAIT_FRAME = 3;
const VIDEO_DECODE_SEEK_TIMEOUT_FRAME = 12;
const DEFAULT_CANVAS_SIZE = 2560;
const WEBGL_CONTEXT_ATTRIBUTES = {
depth: false,
stencil: false,
antialias: false
};
const VIDEO_PLAYBACK_RATE_MIN = 0.125;
const VIDEO_PLAYBACK_RATE_MAX = 4;
const CANVAS_POOL_MAX_SIZE = 10;
const nav = (navigator == null ? void 0 : navigator.userAgent) || "";
const ANDROID = /android|adr/i.test(nav);
const MOBILE = /(mobile)/i.test(nav) && ANDROID;
!(/(mobile)/i.test(nav) || MOBILE) && /Mac OS X/i.test(nav);
const IPHONE = /(iphone|ipad|ipod)/i.test(nav);
const WECHAT = /MicroMessenger/i.test(nav);
const SAFARI_OR_IOS_WEBVIEW = /^((?!chrome|android).)*safari/i.test(nav) || IPHONE;
const WORKER = typeof globalThis.importScripts === "function";
const canvasPool = new Array();
const isOffscreenCanvas = (element) => isInstanceOf(element, globalThis.OffscreenCanvas);
const isCanvas = (element) => isOffscreenCanvas(element) || isInstanceOf(element, globalThis.HTMLCanvasElement);
const getCanvas2D = (width, height) => {
let canvas = canvasPool.pop() || createCanvas2D();
if (canvas !== null) {
canvas.width = width;
canvas.height = height;
}
return canvas;
};
const releaseCanvas2D = (canvas) => {
if (canvasPool.length < CANVAS_POOL_MAX_SIZE) {
canvasPool.push(canvas);
}
};
const createCanvas2D = () => {
if (SAFARI_OR_IOS_WEBVIEW && !WORKER) {
return document.createElement("canvas");
}
try {
const offscreenCanvas = new OffscreenCanvas(0, 0);
const context = offscreenCanvas.getContext("2d");
if (typeof context.measureText === "function")
return offscreenCanvas;
return document.createElement("canvas");
} catch (err) {
return document.createElement("canvas");
}
};
const calculateDisplaySize = (canvas) => {
const styleDeclaration = globalThis.getComputedStyle(canvas, null);
const computedSize = {
width: Number(styleDeclaration.width.replace("px", "")),
height: Number(styleDeclaration.height.replace("px", ""))
};
if (computedSize.width > 0 && computedSize.height > 0) {
return computedSize;
} else {
const styleSize = {
width: Number(canvas.style.width.replace("px", "")),
height: Number(canvas.style.height.replace("px", ""))
};
if (styleSize.width > 0 && styleSize.height > 0) {
return styleSize;
} else {
return {
width: canvas.width,
height: canvas.height
};
}
}
};
var __defProp$7 = Object.defineProperty;
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues$3 = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp$3.call(b, prop))
__defNormalProp$3(a, prop, b[prop]);
if (__getOwnPropSymbols$3)
for (var prop of __getOwnPropSymbols$3(b)) {
if (__propIsEnum$3.call(b, prop))
__defNormalProp$3(a, prop, b[prop]);
}
return a;
};
class BackendContext {
constructor(handle, adopted = false) {
this.isDestroyed = false;
this.oldHandle = 0;
this.handle = handle;
this.adopted = adopted;
}
static from(gl) {
if (gl instanceof BackendContext) {
return new BackendContext(gl.handle, true);
} else {
const majorVersion = isInstanceOf(gl, globalThis.WebGL2RenderingContext) ? 2 : 1;
const { GL } = PAGModule;
let id = 0;
if (GL.contexts.length > 0) {
id = GL.contexts.findIndex((context) => (context == null ? void 0 : context.GLctx) === gl);
}
if (id < 1) {
id = GL.registerContext(gl, __spreadValues$3({
majorVersion,
minorVersion: 0
}, WEBGL_CONTEXT_ATTRIBUTES));
return new BackendContext(id);
}
return new BackendContext(id, true);
}
}
getContext() {
return PAGModule.GL.getContext(this.handle).GLctx;
}
makeCurrent() {
var _a;
if (this.isDestroyed)
return false;
this.oldHandle = ((_a = PAGModule.GL.currentContext) == null ? void 0 : _a.handle) || 0;
if (this.oldHandle === this.handle)
return true;
return PAGModule.GL.makeContextCurrent(this.handle);
}
clearCurrent() {
if (this.isDestroyed)
return;
if (this.oldHandle === this.handle)
return;
PAGModule.GL.makeContextCurrent(0);
if (this.oldHandle) {
PAGModule.GL.makeContextCurrent(this.oldHandle);
}
}
registerTexture(texture) {
return this.register(PAGModule.GL.textures, texture);
}
getTexture(handled) {
return PAGModule.GL.textures[handled];
}
unregisterTexture(handle) {
PAGModule.GL.textures[handle] = null;
}
registerRenderTarget(framebuffer) {
return this.register(PAGModule.GL.framebuffers, framebuffer);
}
getRenderTarget(handle) {
return PAGModule.GL.framebuffers[handle];
}
unregisterRenderTarget(handle) {
PAGModule.GL.framebuffers[handle] = null;
}
destroy() {
if (this.adopted)
return;
PAGModule.GL.deleteContext(this.handle);
}
register(table, item) {
const handle = PAGModule.GL.getNewId(table);
table[handle] = item;
return handle;
}
}
var __defProp$6 = Object.defineProperty;
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues$2 = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp$2.call(b, prop))
__defNormalProp$2(a, prop, b[prop]);
if (__getOwnPropSymbols$2)
for (var prop of __getOwnPropSymbols$2(b)) {
if (__propIsEnum$2.call(b, prop))
__defNormalProp$2(a, prop, b[prop]);
}
return a;
};
const renderCanvasList = [];
class RenderCanvas {
constructor(canvas, contextAttributes) {
this._canvas = null;
this._glContext = null;
this.retainCount = 0;
this._canvas = canvas;
const gl = canvas.getContext("webgl", __spreadValues$2(__spreadValues$2({}, WEBGL_CONTEXT_ATTRIBUTES), contextAttributes));
if (!gl)
throw new Error("Canvas context is not WebGL!");
this._glContext = BackendContext.from(gl);
}
static from(canvas, contextAttributes) {
let renderCanvas = renderCanvasList.find((targetCanvas) => targetCanvas.canvas === canvas);
if (renderCanvas)
return renderCanvas;
renderCanvas = new RenderCanvas(canvas, contextAttributes);
renderCanvasList.push(renderCanvas);
return renderCanvas;
}
retain() {
this.retainCount += 1;
}
release() {
this.retainCount -= 1;
if (this.retainCount === 0) {
if (!this._glContext)
return;
this._glContext.destroy();
this._glContext = null;
this._canvas = null;
}
}
get canvas() {
return this._canvas;
}
get glContext() {
return this._glContext;
}
}
let getTime;
try {
getTime = performance.now.bind(performance);
} catch (e) {
getTime = Date.now.bind(Date);
}
class Clock {
constructor() {
this.startTime = getTime();
this.markers = {};
}
reset() {
this.startTime = getTime();
this.markers = {};
}
mark(key) {
if (!key) {
console.log("Clock.mark(): An empty marker name was specified!");
return;
}
if (Object.keys(this.markers).find((markerKey) => markerKey === key)) {
console.log(`Clock.mark(): The specified marker name '${key}' already exists!`);
return;
}
this.markers[key] = getTime();
}
measure(makerFrom, makerTo) {
let start;
let end;
if (!makerFrom) {
start = this.startTime;
} else {
if (!Object.keys(this.markers).find((markerKey) => markerKey === makerFrom)) {
console.log(`Clock.measure(): The specified makerFrom '${makerFrom}' does not exist!`);
return 0;
}
start = this.markers[makerFrom];
}
if (!makerTo) {
end = getTime();
} else {
if (!Object.keys(this.markers).find((markerKey) => markerKey === makerTo)) {
console.log(`Clock.measure(): The specified makerTo '${makerTo}' does not exist!`);
return 0;
}
end = this.markers[makerTo];
}
return end - start;
}
}
var __defProp$5 = Object.defineProperty;
var __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor;
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues$1 = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp$1.call(b, prop))
__defNormalProp$1(a, prop, b[prop]);
if