nicecode-v2/packages/meta/lib/ImageEditor/viewer/index.js
2024-01-10 15:15:12 +08:00

94 lines
3.6 KiB
JavaScript

var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __decorateClass = (decorators, target, key, kind) => {
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(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(target, key, result);
return result;
};
// src/ImageEditor/viewer/index.ts
var viewer_exports = {};
__export(viewer_exports, {
default: () => viewer_default
});
module.exports = __toCommonJS(viewer_exports);
var import_func = require("@zhst/func");
var import_class = require("rc-util/lib/Dom/class");
var import_utils = require("../utils");
var import_render = __toESM(require("./render"));
var import_event = __toESM(require("./event"));
var import_shape = __toESM(require("./shape"));
var import_helper = __toESM(require("./helper"));
var import_constants = require("./constants");
var import_index = require("./index.scss");
var Viewer = class {
constructor(element, options) {
this.element = element;
this.options = Object.assign({}, (0, import_func.isPlainObject)(options) && options);
this.ready = false;
this.init();
}
async init() {
try {
this.build();
this.bind();
await this.render();
this.ready = true;
(0, import_utils.dispatchEvent)(this.element, import_constants.EVENT_VIEWER_READY);
} catch (error) {
(0, import_utils.dispatchEvent)(this.element, import_constants.EVENT_VIEWER_ERROR);
}
}
build() {
const canvas = document.createElement("canvas");
(0, import_class.addClass)(canvas, import_constants.CLASS_CANVAS);
this.element.appendChild(canvas);
this.canvas = canvas;
}
refleshImage(options) {
this.options = Object.assign({}, (0, import_func.isPlainObject)(options) && options);
this.ready = false;
this.element.removeChild(this.canvas);
this.init();
}
destroy() {
var _a, _b;
window.cancelAnimationFrame(this.animationFrame);
this.unbind();
(_b = (_a = this.element) == null ? void 0 : _a.removeChild) == null ? void 0 : _b.call(_a, this.canvas);
}
};
Viewer = __decorateClass([
(0, import_utils.Mixin)(import_render.default, import_event.default, import_shape.default, import_helper.default)
], Viewer);
var viewer_default = Viewer;