Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@antv/g-plugin-image-loader

Package Overview
Dependencies
Maintainers
58
Versions
152
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@antv/g-plugin-image-loader - npm Package Compare versions

Comparing version 0.5.0-alpha.0 to 0.5.0

8

dist/index.d.ts

@@ -1,9 +0,9 @@

import type { RendererPlugin, Syringe } from '@antv/g';
import { AbstractRendererPlugin } from '@antv/g';
import { ImagePool } from './ImagePool';
export { ImagePool };
export declare class Plugin implements RendererPlugin {
export declare class Plugin extends AbstractRendererPlugin {
name: string;
init(container: Syringe.Container): void;
destroy(container: Syringe.Container): void;
init(): void;
destroy(): void;
}
//# sourceMappingURL=index.d.ts.map

@@ -1,167 +0,4 @@

import { isBrowser, isString, GradientType, computeLinearGradient, computeRadialGradient, inject, CanvasConfig, singleton, RenderingContext, RenderingPluginContribution, ElementEvent, Shape, Module } from '@antv/g';
import { isBrowser, isString, GradientType, computeLinearGradient, computeRadialGradient, inject, CanvasConfig, singleton, RenderingContext, RenderingPluginContribution, ElementEvent, Shape, Module, AbstractRendererPlugin } from '@antv/g';
import { __decorate, __metadata } from 'tslib';
var ImagePool = /*#__PURE__*/function () {
function ImagePool() {
this.imageCache = {};
this.gradientCache = {};
this.patternCache = {};
this.canvasConfig = void 0;
}
var _proto = ImagePool.prototype;
_proto.getImageSync = function getImageSync(src, callback) {
if (!this.imageCache[src]) {
this.getOrCreateImage(src).then(function () {
if (callback) {
callback();
}
});
}
return this.imageCache[src];
};
_proto.getOrCreateImage = function getOrCreateImage(src) {
var _this = this;
if (this.imageCache[src]) {
return Promise.resolve(this.imageCache[src]);
} // @see https://github.com/antvis/g/issues/938
var createImage = this.canvasConfig.createImage;
return new Promise(function (resolve, reject) {
var image;
if (createImage) {
image = createImage(src);
} else if (isBrowser) {
image = new window.Image();
}
if (image) {
image.onload = function () {
resolve(image);
};
image.onerror = function (ev) {
reject(ev);
};
image.crossOrigin = 'Anonymous';
image.src = src;
_this.imageCache[src] = image;
}
});
};
_proto.getOrCreatePatternSync = function getOrCreatePatternSync(pattern, context, callback) {
var patternKey = this.generatePatternKey(pattern);
if (patternKey && this.patternCache[patternKey]) {
return this.patternCache[patternKey];
}
var image = pattern.image,
repetition = pattern.repetition;
var src; // Image URL
if (isString(image)) {
src = this.getImageSync(image, callback);
} else {
src = image;
} // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createPattern
var canvasPattern = src && context.createPattern(src, repetition);
if (patternKey && canvasPattern) {
this.patternCache[patternKey] = canvasPattern;
}
return canvasPattern;
};
_proto.getOrCreateGradient = function getOrCreateGradient(params, context) {
var key = this.generateGradientKey(params); // @ts-ignore
var type = params.type,
steps = params.steps,
width = params.width,
height = params.height,
angle = params.angle,
cx = params.cx,
cy = params.cy;
if (this.gradientCache[key]) {
return this.gradientCache[key];
}
var gradient = null;
if (type === GradientType.LinearGradient) {
var _computeLinearGradien = computeLinearGradient(width, height, angle),
x1 = _computeLinearGradien.x1,
y1 = _computeLinearGradien.y1,
x2 = _computeLinearGradien.x2,
y2 = _computeLinearGradien.y2; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createLinearGradient
gradient = context.createLinearGradient(x1, y1, x2, y2);
} else if (type === GradientType.RadialGradient) {
var _computeRadialGradien = computeRadialGradient(width, height, cx, cy),
x = _computeRadialGradien.x,
y = _computeRadialGradien.y,
r = _computeRadialGradien.r; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createRadialGradient
gradient = context.createRadialGradient(x, y, 0, x, y, r);
}
if (gradient) {
steps.forEach(function (_ref) {
var _gradient;
var offset = _ref[0],
color = _ref[1];
(_gradient = gradient) === null || _gradient === void 0 ? void 0 : _gradient.addColorStop(offset, color);
});
this.gradientCache[key] = gradient;
}
return this.gradientCache[key];
};
_proto.generateGradientKey = function generateGradientKey(params) {
// @ts-ignore
var type = params.type,
width = params.width,
height = params.height,
steps = params.steps,
angle = params.angle,
cx = params.cx,
cy = params.cy;
return "gradient-" + type + "-" + (angle || 0) + "-" + (cx || 0) + "-" + (cy || 0) + "-" + width + "-" + height + "-" + steps.map(function (step) {
return step.join('');
}).join('-');
};
_proto.generatePatternKey = function generatePatternKey(pattern) {
var image = pattern.image,
repetition = pattern.repetition; // only generate cache for Image
if (isString(image)) {
return "pattern-" + image + "-" + repetition;
}
};
return ImagePool;
}();
__decorate([inject(CanvasConfig), __metadata("design:type", Object)], ImagePool.prototype, "canvasConfig", void 0);
ImagePool = __decorate([singleton()], ImagePool);
function _regeneratorRuntime() {

@@ -548,2 +385,180 @@ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */

function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
_setPrototypeOf(subClass, superClass);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
var ImagePool = /*#__PURE__*/function () {
function ImagePool() {
this.imageCache = {};
this.gradientCache = {};
this.patternCache = {};
this.canvasConfig = void 0;
}
var _proto = ImagePool.prototype;
_proto.getImageSync = function getImageSync(src, callback) {
if (!this.imageCache[src]) {
this.getOrCreateImage(src).then(function () {
if (callback) {
callback();
}
});
}
return this.imageCache[src];
};
_proto.getOrCreateImage = function getOrCreateImage(src) {
var _this = this;
if (this.imageCache[src]) {
return Promise.resolve(this.imageCache[src]);
} // @see https://github.com/antvis/g/issues/938
var createImage = this.canvasConfig.createImage;
return new Promise(function (resolve, reject) {
var image;
if (createImage) {
image = createImage(src);
} else if (isBrowser) {
image = new window.Image();
}
if (image) {
image.onload = function () {
resolve(image);
};
image.onerror = function (ev) {
reject(ev);
};
image.crossOrigin = 'Anonymous';
image.src = src;
_this.imageCache[src] = image;
}
});
};
_proto.getOrCreatePatternSync = function getOrCreatePatternSync(pattern, context, callback) {
var patternKey = this.generatePatternKey(pattern);
if (patternKey && this.patternCache[patternKey]) {
return this.patternCache[patternKey];
}
var image = pattern.image,
repetition = pattern.repetition;
var src; // Image URL
if (isString(image)) {
src = this.getImageSync(image, callback);
} else {
src = image;
} // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createPattern
var canvasPattern = src && context.createPattern(src, repetition);
if (patternKey && canvasPattern) {
this.patternCache[patternKey] = canvasPattern;
}
return canvasPattern;
};
_proto.getOrCreateGradient = function getOrCreateGradient(params, context) {
var key = this.generateGradientKey(params); // @ts-ignore
var type = params.type,
steps = params.steps,
width = params.width,
height = params.height,
angle = params.angle,
cx = params.cx,
cy = params.cy;
if (this.gradientCache[key]) {
return this.gradientCache[key];
}
var gradient = null;
if (type === GradientType.LinearGradient) {
var _computeLinearGradien = computeLinearGradient(width, height, angle),
x1 = _computeLinearGradien.x1,
y1 = _computeLinearGradien.y1,
x2 = _computeLinearGradien.x2,
y2 = _computeLinearGradien.y2; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createLinearGradient
gradient = context.createLinearGradient(x1, y1, x2, y2);
} else if (type === GradientType.RadialGradient) {
var _computeRadialGradien = computeRadialGradient(width, height, cx, cy),
x = _computeRadialGradien.x,
y = _computeRadialGradien.y,
r = _computeRadialGradien.r; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createRadialGradient
gradient = context.createRadialGradient(x, y, 0, x, y, r);
}
if (gradient) {
steps.forEach(function (_ref) {
var _gradient;
var offset = _ref[0],
color = _ref[1];
(_gradient = gradient) === null || _gradient === void 0 ? void 0 : _gradient.addColorStop(offset, color);
});
this.gradientCache[key] = gradient;
}
return this.gradientCache[key];
};
_proto.generateGradientKey = function generateGradientKey(params) {
// @ts-ignore
var type = params.type,
width = params.width,
height = params.height,
steps = params.steps,
angle = params.angle,
cx = params.cx,
cy = params.cy;
return "gradient-" + type + "-" + (angle || 0) + "-" + (cx || 0) + "-" + (cy || 0) + "-" + width + "-" + height + "-" + steps.map(function (step) {
return step.join('');
}).join('-');
};
_proto.generatePatternKey = function generatePatternKey(pattern) {
var image = pattern.image,
repetition = pattern.repetition; // only generate cache for Image
if (isString(image)) {
return "pattern-" + image + "-" + repetition;
}
};
return ImagePool;
}();
__decorate([inject(CanvasConfig), __metadata("design:type", Object)], ImagePool.prototype, "canvasConfig", void 0);
ImagePool = __decorate([singleton()], ImagePool);
var _class;

@@ -637,5 +652,15 @@

});
var Plugin = /*#__PURE__*/function () {
var Plugin = /*#__PURE__*/function (_AbstractRendererPlug) {
_inheritsLoose(Plugin, _AbstractRendererPlug);
function Plugin() {
this.name = 'image-loader';
var _this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
_this.name = 'image-loader';
return _this;
}

@@ -645,13 +670,13 @@

_proto.init = function init(container) {
container.load(containerModule, true);
_proto.init = function init() {
this.container.load(containerModule, true);
};
_proto.destroy = function destroy(container) {
container.unload(containerModule);
_proto.destroy = function destroy() {
this.container.unload(containerModule);
};
return Plugin;
}();
}(AbstractRendererPlugin);
export { ImagePool, Plugin };

@@ -8,165 +8,2 @@ 'use strict';

exports.ImagePool = /*#__PURE__*/function () {
function ImagePool() {
this.imageCache = {};
this.gradientCache = {};
this.patternCache = {};
this.canvasConfig = void 0;
}
var _proto = ImagePool.prototype;
_proto.getImageSync = function getImageSync(src, callback) {
if (!this.imageCache[src]) {
this.getOrCreateImage(src).then(function () {
if (callback) {
callback();
}
});
}
return this.imageCache[src];
};
_proto.getOrCreateImage = function getOrCreateImage(src) {
var _this = this;
if (this.imageCache[src]) {
return Promise.resolve(this.imageCache[src]);
} // @see https://github.com/antvis/g/issues/938
var createImage = this.canvasConfig.createImage;
return new Promise(function (resolve, reject) {
var image;
if (createImage) {
image = createImage(src);
} else if (g.isBrowser) {
image = new window.Image();
}
if (image) {
image.onload = function () {
resolve(image);
};
image.onerror = function (ev) {
reject(ev);
};
image.crossOrigin = 'Anonymous';
image.src = src;
_this.imageCache[src] = image;
}
});
};
_proto.getOrCreatePatternSync = function getOrCreatePatternSync(pattern, context, callback) {
var patternKey = this.generatePatternKey(pattern);
if (patternKey && this.patternCache[patternKey]) {
return this.patternCache[patternKey];
}
var image = pattern.image,
repetition = pattern.repetition;
var src; // Image URL
if (g.isString(image)) {
src = this.getImageSync(image, callback);
} else {
src = image;
} // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createPattern
var canvasPattern = src && context.createPattern(src, repetition);
if (patternKey && canvasPattern) {
this.patternCache[patternKey] = canvasPattern;
}
return canvasPattern;
};
_proto.getOrCreateGradient = function getOrCreateGradient(params, context) {
var key = this.generateGradientKey(params); // @ts-ignore
var type = params.type,
steps = params.steps,
width = params.width,
height = params.height,
angle = params.angle,
cx = params.cx,
cy = params.cy;
if (this.gradientCache[key]) {
return this.gradientCache[key];
}
var gradient = null;
if (type === g.GradientType.LinearGradient) {
var _computeLinearGradien = g.computeLinearGradient(width, height, angle),
x1 = _computeLinearGradien.x1,
y1 = _computeLinearGradien.y1,
x2 = _computeLinearGradien.x2,
y2 = _computeLinearGradien.y2; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createLinearGradient
gradient = context.createLinearGradient(x1, y1, x2, y2);
} else if (type === g.GradientType.RadialGradient) {
var _computeRadialGradien = g.computeRadialGradient(width, height, cx, cy),
x = _computeRadialGradien.x,
y = _computeRadialGradien.y,
r = _computeRadialGradien.r; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createRadialGradient
gradient = context.createRadialGradient(x, y, 0, x, y, r);
}
if (gradient) {
steps.forEach(function (_ref) {
var _gradient;
var offset = _ref[0],
color = _ref[1];
(_gradient = gradient) === null || _gradient === void 0 ? void 0 : _gradient.addColorStop(offset, color);
});
this.gradientCache[key] = gradient;
}
return this.gradientCache[key];
};
_proto.generateGradientKey = function generateGradientKey(params) {
// @ts-ignore
var type = params.type,
width = params.width,
height = params.height,
steps = params.steps,
angle = params.angle,
cx = params.cx,
cy = params.cy;
return "gradient-" + type + "-" + (angle || 0) + "-" + (cx || 0) + "-" + (cy || 0) + "-" + width + "-" + height + "-" + steps.map(function (step) {
return step.join('');
}).join('-');
};
_proto.generatePatternKey = function generatePatternKey(pattern) {
var image = pattern.image,
repetition = pattern.repetition; // only generate cache for Image
if (g.isString(image)) {
return "pattern-" + image + "-" + repetition;
}
};
return ImagePool;
}();
tslib.__decorate([g.inject(g.CanvasConfig), tslib.__metadata("design:type", Object)], exports.ImagePool.prototype, "canvasConfig", void 0);
exports.ImagePool = tslib.__decorate([g.singleton()], exports.ImagePool);
function _regeneratorRuntime() {

@@ -553,2 +390,180 @@ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */

function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
_setPrototypeOf(subClass, superClass);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
exports.ImagePool = /*#__PURE__*/function () {
function ImagePool() {
this.imageCache = {};
this.gradientCache = {};
this.patternCache = {};
this.canvasConfig = void 0;
}
var _proto = ImagePool.prototype;
_proto.getImageSync = function getImageSync(src, callback) {
if (!this.imageCache[src]) {
this.getOrCreateImage(src).then(function () {
if (callback) {
callback();
}
});
}
return this.imageCache[src];
};
_proto.getOrCreateImage = function getOrCreateImage(src) {
var _this = this;
if (this.imageCache[src]) {
return Promise.resolve(this.imageCache[src]);
} // @see https://github.com/antvis/g/issues/938
var createImage = this.canvasConfig.createImage;
return new Promise(function (resolve, reject) {
var image;
if (createImage) {
image = createImage(src);
} else if (g.isBrowser) {
image = new window.Image();
}
if (image) {
image.onload = function () {
resolve(image);
};
image.onerror = function (ev) {
reject(ev);
};
image.crossOrigin = 'Anonymous';
image.src = src;
_this.imageCache[src] = image;
}
});
};
_proto.getOrCreatePatternSync = function getOrCreatePatternSync(pattern, context, callback) {
var patternKey = this.generatePatternKey(pattern);
if (patternKey && this.patternCache[patternKey]) {
return this.patternCache[patternKey];
}
var image = pattern.image,
repetition = pattern.repetition;
var src; // Image URL
if (g.isString(image)) {
src = this.getImageSync(image, callback);
} else {
src = image;
} // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createPattern
var canvasPattern = src && context.createPattern(src, repetition);
if (patternKey && canvasPattern) {
this.patternCache[patternKey] = canvasPattern;
}
return canvasPattern;
};
_proto.getOrCreateGradient = function getOrCreateGradient(params, context) {
var key = this.generateGradientKey(params); // @ts-ignore
var type = params.type,
steps = params.steps,
width = params.width,
height = params.height,
angle = params.angle,
cx = params.cx,
cy = params.cy;
if (this.gradientCache[key]) {
return this.gradientCache[key];
}
var gradient = null;
if (type === g.GradientType.LinearGradient) {
var _computeLinearGradien = g.computeLinearGradient(width, height, angle),
x1 = _computeLinearGradien.x1,
y1 = _computeLinearGradien.y1,
x2 = _computeLinearGradien.x2,
y2 = _computeLinearGradien.y2; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createLinearGradient
gradient = context.createLinearGradient(x1, y1, x2, y2);
} else if (type === g.GradientType.RadialGradient) {
var _computeRadialGradien = g.computeRadialGradient(width, height, cx, cy),
x = _computeRadialGradien.x,
y = _computeRadialGradien.y,
r = _computeRadialGradien.r; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createRadialGradient
gradient = context.createRadialGradient(x, y, 0, x, y, r);
}
if (gradient) {
steps.forEach(function (_ref) {
var _gradient;
var offset = _ref[0],
color = _ref[1];
(_gradient = gradient) === null || _gradient === void 0 ? void 0 : _gradient.addColorStop(offset, color);
});
this.gradientCache[key] = gradient;
}
return this.gradientCache[key];
};
_proto.generateGradientKey = function generateGradientKey(params) {
// @ts-ignore
var type = params.type,
width = params.width,
height = params.height,
steps = params.steps,
angle = params.angle,
cx = params.cx,
cy = params.cy;
return "gradient-" + type + "-" + (angle || 0) + "-" + (cx || 0) + "-" + (cy || 0) + "-" + width + "-" + height + "-" + steps.map(function (step) {
return step.join('');
}).join('-');
};
_proto.generatePatternKey = function generatePatternKey(pattern) {
var image = pattern.image,
repetition = pattern.repetition; // only generate cache for Image
if (g.isString(image)) {
return "pattern-" + image + "-" + repetition;
}
};
return ImagePool;
}();
tslib.__decorate([g.inject(g.CanvasConfig), tslib.__metadata("design:type", Object)], exports.ImagePool.prototype, "canvasConfig", void 0);
exports.ImagePool = tslib.__decorate([g.singleton()], exports.ImagePool);
var _class;

@@ -642,5 +657,15 @@

});
var Plugin = /*#__PURE__*/function () {
var Plugin = /*#__PURE__*/function (_AbstractRendererPlug) {
_inheritsLoose(Plugin, _AbstractRendererPlug);
function Plugin() {
this.name = 'image-loader';
var _this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
_this.name = 'image-loader';
return _this;
}

@@ -650,13 +675,13 @@

_proto.init = function init(container) {
container.load(containerModule, true);
_proto.init = function init() {
this.container.load(containerModule, true);
};
_proto.destroy = function destroy(container) {
container.unload(containerModule);
_proto.destroy = function destroy() {
this.container.unload(containerModule);
};
return Plugin;
}();
}(g.AbstractRendererPlugin);
exports.Plugin = Plugin;
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@antv/g')) :
typeof define === 'function' && define.amd ? define(['exports', '@antv/g'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.G = global.G || {}, global.G.ImageLoader = {}), global.window.G));
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@antv/g')) :
typeof define === 'function' && define.amd ? define(['exports', '@antv/g'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.G = global.G || {}, global.G.ImageLoader = {}), global.window.G));
}(this, (function (exports, g) { 'use strict';
/******************************************************************************
Copyright (c) Microsoft Corporation.
function _regeneratorRuntime() {
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
_regeneratorRuntime = function () {
return exports;
};
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
var exports = {},
Op = Object.prototype,
hasOwn = Op.hasOwnProperty,
$Symbol = "function" == typeof Symbol ? Symbol : {},
iteratorSymbol = $Symbol.iterator || "@@iterator",
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
function define(obj, key, value) {
return Object.defineProperty(obj, key, {
value: value,
enumerable: !0,
configurable: !0,
writable: !0
}), obj[key];
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
try {
define({}, "");
} catch (err) {
define = function (obj, key, value) {
return obj[key] = value;
};
}
exports.ImagePool = /*#__PURE__*/function () {
function ImagePool() {
this.imageCache = {};
this.gradientCache = {};
this.patternCache = {};
this.canvasConfig = void 0;
}
function wrap(innerFn, outerFn, self, tryLocsList) {
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
generator = Object.create(protoGenerator.prototype),
context = new Context(tryLocsList || []);
return generator._invoke = function (innerFn, self, context) {
var state = "suspendedStart";
return function (method, arg) {
if ("executing" === state) throw new Error("Generator is already running");
var _proto = ImagePool.prototype;
if ("completed" === state) {
if ("throw" === method) throw arg;
return doneResult();
}
_proto.getImageSync = function getImageSync(src, callback) {
if (!this.imageCache[src]) {
this.getOrCreateImage(src).then(function () {
if (callback) {
callback();
for (context.method = method, context.arg = arg;;) {
var delegate = context.delegate;
if (delegate) {
var delegateResult = maybeInvokeDelegate(delegate, context);
if (delegateResult) {
if (delegateResult === ContinueSentinel) continue;
return delegateResult;
}
}
});
}
return this.imageCache[src];
};
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
if ("suspendedStart" === state) throw state = "completed", context.arg;
context.dispatchException(context.arg);
} else "return" === context.method && context.abrupt("return", context.arg);
state = "executing";
var record = tryCatch(innerFn, self, context);
_proto.getOrCreateImage = function getOrCreateImage(src) {
var _this = this;
if ("normal" === record.type) {
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
return {
value: record.arg,
done: context.done
};
}
if (this.imageCache[src]) {
return Promise.resolve(this.imageCache[src]);
} // @see https://github.com/antvis/g/issues/938
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
}
};
}(innerFn, self, context), generator;
}
function tryCatch(fn, obj, arg) {
try {
return {
type: "normal",
arg: fn.call(obj, arg)
};
} catch (err) {
return {
type: "throw",
arg: err
};
}
}
var createImage = this.canvasConfig.createImage;
return new Promise(function (resolve, reject) {
var image;
exports.wrap = wrap;
var ContinueSentinel = {};
if (createImage) {
image = createImage(src);
} else if (g.isBrowser) {
image = new window.Image();
}
function Generator() {}
if (image) {
image.onload = function () {
resolve(image);
};
function GeneratorFunction() {}
image.onerror = function (ev) {
reject(ev);
};
function GeneratorFunctionPrototype() {}
image.crossOrigin = 'Anonymous';
image.src = src;
_this.imageCache[src] = image;
}
var IteratorPrototype = {};
define(IteratorPrototype, iteratorSymbol, function () {
return this;
});
var getProto = Object.getPrototypeOf,
NativeIteratorPrototype = getProto && getProto(getProto(values([])));
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
function defineIteratorMethods(prototype) {
["next", "throw", "return"].forEach(function (method) {
define(prototype, method, function (arg) {
return this._invoke(method, arg);
});
};
});
}
_proto.getOrCreatePatternSync = function getOrCreatePatternSync(pattern, context, callback) {
var patternKey = this.generatePatternKey(pattern);
function AsyncIterator(generator, PromiseImpl) {
function invoke(method, arg, resolve, reject) {
var record = tryCatch(generator[method], generator, arg);
if (patternKey && this.patternCache[patternKey]) {
return this.patternCache[patternKey];
if ("throw" !== record.type) {
var result = record.arg,
value = result.value;
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
invoke("next", value, resolve, reject);
}, function (err) {
invoke("throw", err, resolve, reject);
}) : PromiseImpl.resolve(value).then(function (unwrapped) {
result.value = unwrapped, resolve(result);
}, function (error) {
return invoke("throw", error, resolve, reject);
});
}
var image = pattern.image,
repetition = pattern.repetition;
var src; // Image URL
reject(record.arg);
}
if (g.isString(image)) {
src = this.getImageSync(image, callback);
} else {
src = image;
} // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createPattern
var previousPromise;
var canvasPattern = src && context.createPattern(src, repetition);
if (patternKey && canvasPattern) {
this.patternCache[patternKey] = canvasPattern;
this._invoke = function (method, arg) {
function callInvokeWithMethodAndArg() {
return new PromiseImpl(function (resolve, reject) {
invoke(method, arg, resolve, reject);
});
}
return canvasPattern;
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
};
}
_proto.getOrCreateGradient = function getOrCreateGradient(params, context) {
var key = this.generateGradientKey(params); // @ts-ignore
function maybeInvokeDelegate(delegate, context) {
var method = delegate.iterator[context.method];
var type = params.type,
steps = params.steps,
width = params.width,
height = params.height,
angle = params.angle,
cx = params.cx,
cy = params.cy;
if (this.gradientCache[key]) {
return this.gradientCache[key];
if (undefined === method) {
if (context.delegate = null, "throw" === context.method) {
if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
}
var gradient = null;
return ContinueSentinel;
}
if (type === g.GradientType.LinearGradient) {
var _computeLinearGradien = g.computeLinearGradient(width, height, angle),
x1 = _computeLinearGradien.x1,
y1 = _computeLinearGradien.y1,
x2 = _computeLinearGradien.x2,
y2 = _computeLinearGradien.y2; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createLinearGradient
var record = tryCatch(method, delegate.iterator, context.arg);
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
var info = record.arg;
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
}
function pushTryEntry(locs) {
var entry = {
tryLoc: locs[0]
};
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
}
gradient = context.createLinearGradient(x1, y1, x2, y2);
} else if (type === g.GradientType.RadialGradient) {
var _computeRadialGradien = g.computeRadialGradient(width, height, cx, cy),
x = _computeRadialGradien.x,
y = _computeRadialGradien.y,
r = _computeRadialGradien.r; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createRadialGradient
function resetTryEntry(entry) {
var record = entry.completion || {};
record.type = "normal", delete record.arg, entry.completion = record;
}
function Context(tryLocsList) {
this.tryEntries = [{
tryLoc: "root"
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
}
gradient = context.createRadialGradient(x, y, 0, x, y, r);
}
function values(iterable) {
if (iterable) {
var iteratorMethod = iterable[iteratorSymbol];
if (iteratorMethod) return iteratorMethod.call(iterable);
if ("function" == typeof iterable.next) return iterable;
if (gradient) {
steps.forEach(function (_ref) {
var _gradient;
if (!isNaN(iterable.length)) {
var i = -1,
next = function next() {
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
var offset = _ref[0],
color = _ref[1];
(_gradient = gradient) === null || _gradient === void 0 ? void 0 : _gradient.addColorStop(offset, color);
});
this.gradientCache[key] = gradient;
return next.value = undefined, next.done = !0, next;
};
return next.next = next;
}
}
return this.gradientCache[key];
return {
next: doneResult
};
}
_proto.generateGradientKey = function generateGradientKey(params) {
// @ts-ignore
var type = params.type,
width = params.width,
height = params.height,
steps = params.steps,
angle = params.angle,
cx = params.cx,
cy = params.cy;
return "gradient-" + type + "-" + (angle || 0) + "-" + (cx || 0) + "-" + (cy || 0) + "-" + width + "-" + height + "-" + steps.map(function (step) {
return step.join('');
}).join('-');
function doneResult() {
return {
value: undefined,
done: !0
};
}
_proto.generatePatternKey = function generatePatternKey(pattern) {
var image = pattern.image,
repetition = pattern.repetition; // only generate cache for Image
return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
var ctor = "function" == typeof genFun && genFun.constructor;
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
}, exports.mark = function (genFun) {
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
}, exports.awrap = function (arg) {
return {
__await: arg
};
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
return this;
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
void 0 === PromiseImpl && (PromiseImpl = Promise);
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
return result.done ? result.value : iter.next();
});
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
return this;
}), define(Gp, "toString", function () {
return "[object Generator]";
}), exports.keys = function (object) {
var keys = [];
if (g.isString(image)) {
return "pattern-" + image + "-" + repetition;
for (var key in object) keys.push(key);
return keys.reverse(), function next() {
for (; keys.length;) {
var key = keys.pop();
if (key in object) return next.value = key, next.done = !1, next;
}
return next.done = !0, next;
};
}, exports.values = values, Context.prototype = {
constructor: Context,
reset: function (skipTempReset) {
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
},
stop: function () {
this.done = !0;
var rootRecord = this.tryEntries[0].completion;
if ("throw" === rootRecord.type) throw rootRecord.arg;
return this.rval;
},
dispatchException: function (exception) {
if (this.done) throw exception;
var context = this;
return ImagePool;
}();
function handle(loc, caught) {
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
}
__decorate([g.inject(g.CanvasConfig), __metadata("design:type", Object)], exports.ImagePool.prototype, "canvasConfig", void 0);
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i],
record = entry.completion;
if ("root" === entry.tryLoc) return handle("end");
exports.ImagePool = __decorate([g.singleton()], exports.ImagePool);
if (entry.tryLoc <= this.prev) {
var hasCatch = hasOwn.call(entry, "catchLoc"),
hasFinally = hasOwn.call(entry, "finallyLoc");
function _regeneratorRuntime() {
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
if (hasCatch && hasFinally) {
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
} else if (hasCatch) {
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
} else {
if (!hasFinally) throw new Error("try statement without catch or finally");
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
}
}
}
},
abrupt: function (type, arg) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
_regeneratorRuntime = function () {
return exports;
};
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
var finallyEntry = entry;
break;
}
}
var exports = {},
Op = Object.prototype,
hasOwn = Op.hasOwnProperty,
$Symbol = "function" == typeof Symbol ? Symbol : {},
iteratorSymbol = $Symbol.iterator || "@@iterator",
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
var record = finallyEntry ? finallyEntry.completion : {};
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
},
complete: function (record, afterLoc) {
if ("throw" === record.type) throw record.arg;
return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
},
finish: function (finallyLoc) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
}
},
catch: function (tryLoc) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
function define(obj, key, value) {
return Object.defineProperty(obj, key, {
value: value,
enumerable: !0,
configurable: !0,
writable: !0
}), obj[key];
}
if (entry.tryLoc === tryLoc) {
var record = entry.completion;
try {
define({}, "");
} catch (err) {
define = function (obj, key, value) {
return obj[key] = value;
};
if ("throw" === record.type) {
var thrown = record.arg;
resetTryEntry(entry);
}
return thrown;
}
}
throw new Error("illegal catch attempt");
},
delegateYield: function (iterable, resultName, nextLoc) {
return this.delegate = {
iterator: values(iterable),
resultName: resultName,
nextLoc: nextLoc
}, "next" === this.method && (this.arg = undefined), ContinueSentinel;
}
}, exports;
}
function wrap(innerFn, outerFn, self, tryLocsList) {
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
generator = Object.create(protoGenerator.prototype),
context = new Context(tryLocsList || []);
return generator._invoke = function (innerFn, self, context) {
var state = "suspendedStart";
return function (method, arg) {
if ("executing" === state) throw new Error("Generator is already running");
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if ("completed" === state) {
if ("throw" === method) throw arg;
return doneResult();
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
for (context.method = method, context.arg = arg;;) {
var delegate = context.delegate;
function _asyncToGenerator(fn) {
return function () {
var self = this,
args = arguments;
return new Promise(function (resolve, reject) {
var gen = fn.apply(self, args);
if (delegate) {
var delegateResult = maybeInvokeDelegate(delegate, context);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
if (delegateResult) {
if (delegateResult === ContinueSentinel) continue;
return delegateResult;
}
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
if ("suspendedStart" === state) throw state = "completed", context.arg;
context.dispatchException(context.arg);
} else "return" === context.method && context.abrupt("return", context.arg);
state = "executing";
var record = tryCatch(innerFn, self, context);
_next(undefined);
});
};
}
if ("normal" === record.type) {
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
return {
value: record.arg,
done: context.done
};
}
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
}
};
}(innerFn, self, context), generator;
}
_setPrototypeOf(subClass, superClass);
}
function tryCatch(fn, obj, arg) {
try {
return {
type: "normal",
arg: fn.call(obj, arg)
};
} catch (err) {
return {
type: "throw",
arg: err
};
}
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
exports.wrap = wrap;
var ContinueSentinel = {};
/******************************************************************************
Copyright (c) Microsoft Corporation.
function Generator() {}
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
function GeneratorFunction() {}
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function GeneratorFunctionPrototype() {}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
var IteratorPrototype = {};
define(IteratorPrototype, iteratorSymbol, function () {
return this;
});
var getProto = Object.getPrototypeOf,
NativeIteratorPrototype = getProto && getProto(getProto(values([])));
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
}
function defineIteratorMethods(prototype) {
["next", "throw", "return"].forEach(function (method) {
define(prototype, method, function (arg) {
return this._invoke(method, arg);
});
exports.ImagePool = /*#__PURE__*/function () {
function ImagePool() {
this.imageCache = {};
this.gradientCache = {};
this.patternCache = {};
this.canvasConfig = void 0;
}
var _proto = ImagePool.prototype;
_proto.getImageSync = function getImageSync(src, callback) {
if (!this.imageCache[src]) {
this.getOrCreateImage(src).then(function () {
if (callback) {
callback();
}
});
}
function AsyncIterator(generator, PromiseImpl) {
function invoke(method, arg, resolve, reject) {
var record = tryCatch(generator[method], generator, arg);
return this.imageCache[src];
};
if ("throw" !== record.type) {
var result = record.arg,
value = result.value;
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
invoke("next", value, resolve, reject);
}, function (err) {
invoke("throw", err, resolve, reject);
}) : PromiseImpl.resolve(value).then(function (unwrapped) {
result.value = unwrapped, resolve(result);
}, function (error) {
return invoke("throw", error, resolve, reject);
});
}
_proto.getOrCreateImage = function getOrCreateImage(src) {
var _this = this;
reject(record.arg);
}
if (this.imageCache[src]) {
return Promise.resolve(this.imageCache[src]);
} // @see https://github.com/antvis/g/issues/938
var previousPromise;
this._invoke = function (method, arg) {
function callInvokeWithMethodAndArg() {
return new PromiseImpl(function (resolve, reject) {
invoke(method, arg, resolve, reject);
});
}
var createImage = this.canvasConfig.createImage;
return new Promise(function (resolve, reject) {
var image;
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
};
}
if (createImage) {
image = createImage(src);
} else if (g.isBrowser) {
image = new window.Image();
}
function maybeInvokeDelegate(delegate, context) {
var method = delegate.iterator[context.method];
if (image) {
image.onload = function () {
resolve(image);
};
if (undefined === method) {
if (context.delegate = null, "throw" === context.method) {
if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
}
image.onerror = function (ev) {
reject(ev);
};
return ContinueSentinel;
image.crossOrigin = 'Anonymous';
image.src = src;
_this.imageCache[src] = image;
}
});
};
var record = tryCatch(method, delegate.iterator, context.arg);
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
var info = record.arg;
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
}
_proto.getOrCreatePatternSync = function getOrCreatePatternSync(pattern, context, callback) {
var patternKey = this.generatePatternKey(pattern);
function pushTryEntry(locs) {
var entry = {
tryLoc: locs[0]
};
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
if (patternKey && this.patternCache[patternKey]) {
return this.patternCache[patternKey];
}
function resetTryEntry(entry) {
var record = entry.completion || {};
record.type = "normal", delete record.arg, entry.completion = record;
}
var image = pattern.image,
repetition = pattern.repetition;
var src; // Image URL
function Context(tryLocsList) {
this.tryEntries = [{
tryLoc: "root"
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
}
if (g.isString(image)) {
src = this.getImageSync(image, callback);
} else {
src = image;
} // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createPattern
function values(iterable) {
if (iterable) {
var iteratorMethod = iterable[iteratorSymbol];
if (iteratorMethod) return iteratorMethod.call(iterable);
if ("function" == typeof iterable.next) return iterable;
if (!isNaN(iterable.length)) {
var i = -1,
next = function next() {
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
var canvasPattern = src && context.createPattern(src, repetition);
return next.value = undefined, next.done = !0, next;
};
return next.next = next;
}
}
return {
next: doneResult
};
if (patternKey && canvasPattern) {
this.patternCache[patternKey] = canvasPattern;
}
function doneResult() {
return {
value: undefined,
done: !0
};
}
return canvasPattern;
};
return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
var ctor = "function" == typeof genFun && genFun.constructor;
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
}, exports.mark = function (genFun) {
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
}, exports.awrap = function (arg) {
return {
__await: arg
};
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
return this;
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
void 0 === PromiseImpl && (PromiseImpl = Promise);
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
return result.done ? result.value : iter.next();
});
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
return this;
}), define(Gp, "toString", function () {
return "[object Generator]";
}), exports.keys = function (object) {
var keys = [];
_proto.getOrCreateGradient = function getOrCreateGradient(params, context) {
var key = this.generateGradientKey(params); // @ts-ignore
for (var key in object) keys.push(key);
var type = params.type,
steps = params.steps,
width = params.width,
height = params.height,
angle = params.angle,
cx = params.cx,
cy = params.cy;
return keys.reverse(), function next() {
for (; keys.length;) {
var key = keys.pop();
if (key in object) return next.value = key, next.done = !1, next;
}
if (this.gradientCache[key]) {
return this.gradientCache[key];
}
return next.done = !0, next;
};
}, exports.values = values, Context.prototype = {
constructor: Context,
reset: function (skipTempReset) {
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
},
stop: function () {
this.done = !0;
var rootRecord = this.tryEntries[0].completion;
if ("throw" === rootRecord.type) throw rootRecord.arg;
return this.rval;
},
dispatchException: function (exception) {
if (this.done) throw exception;
var context = this;
var gradient = null;
function handle(loc, caught) {
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
}
if (type === g.GradientType.LinearGradient) {
var _computeLinearGradien = g.computeLinearGradient(width, height, angle),
x1 = _computeLinearGradien.x1,
y1 = _computeLinearGradien.y1,
x2 = _computeLinearGradien.x2,
y2 = _computeLinearGradien.y2; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createLinearGradient
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i],
record = entry.completion;
if ("root" === entry.tryLoc) return handle("end");
if (entry.tryLoc <= this.prev) {
var hasCatch = hasOwn.call(entry, "catchLoc"),
hasFinally = hasOwn.call(entry, "finallyLoc");
gradient = context.createLinearGradient(x1, y1, x2, y2);
} else if (type === g.GradientType.RadialGradient) {
var _computeRadialGradien = g.computeRadialGradient(width, height, cx, cy),
x = _computeRadialGradien.x,
y = _computeRadialGradien.y,
r = _computeRadialGradien.r; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createRadialGradient
if (hasCatch && hasFinally) {
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
} else if (hasCatch) {
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
} else {
if (!hasFinally) throw new Error("try statement without catch or finally");
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
}
}
}
},
abrupt: function (type, arg) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
var finallyEntry = entry;
break;
}
}
gradient = context.createRadialGradient(x, y, 0, x, y, r);
}
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
var record = finallyEntry ? finallyEntry.completion : {};
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
},
complete: function (record, afterLoc) {
if ("throw" === record.type) throw record.arg;
return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
},
finish: function (finallyLoc) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
}
},
catch: function (tryLoc) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
if (gradient) {
steps.forEach(function (_ref) {
var _gradient;
if (entry.tryLoc === tryLoc) {
var record = entry.completion;
var offset = _ref[0],
color = _ref[1];
(_gradient = gradient) === null || _gradient === void 0 ? void 0 : _gradient.addColorStop(offset, color);
});
this.gradientCache[key] = gradient;
}
if ("throw" === record.type) {
var thrown = record.arg;
resetTryEntry(entry);
}
return this.gradientCache[key];
};
return thrown;
}
}
_proto.generateGradientKey = function generateGradientKey(params) {
// @ts-ignore
var type = params.type,
width = params.width,
height = params.height,
steps = params.steps,
angle = params.angle,
cx = params.cx,
cy = params.cy;
return "gradient-" + type + "-" + (angle || 0) + "-" + (cx || 0) + "-" + (cy || 0) + "-" + width + "-" + height + "-" + steps.map(function (step) {
return step.join('');
}).join('-');
};
throw new Error("illegal catch attempt");
},
delegateYield: function (iterable, resultName, nextLoc) {
return this.delegate = {
iterator: values(iterable),
resultName: resultName,
nextLoc: nextLoc
}, "next" === this.method && (this.arg = undefined), ContinueSentinel;
}
}, exports;
}
_proto.generatePatternKey = function generatePatternKey(pattern) {
var image = pattern.image,
repetition = pattern.repetition; // only generate cache for Image
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
if (g.isString(image)) {
return "pattern-" + image + "-" + repetition;
}
};
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
return ImagePool;
}();
function _asyncToGenerator(fn) {
return function () {
var self = this,
args = arguments;
return new Promise(function (resolve, reject) {
var gen = fn.apply(self, args);
__decorate([g.inject(g.CanvasConfig), __metadata("design:type", Object)], exports.ImagePool.prototype, "canvasConfig", void 0);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
exports.ImagePool = __decorate([g.singleton()], exports.ImagePool);
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
var _class;
_next(undefined);
});
};
var LoadImagePlugin_1;
var LoadImagePlugin = LoadImagePlugin_1 = (_class = /*#__PURE__*/function () {
function LoadImagePlugin() {
this.imagePool = void 0;
this.renderingContext = void 0;
}
var _class;
var _proto = LoadImagePlugin.prototype;
var LoadImagePlugin_1;
var LoadImagePlugin = LoadImagePlugin_1 = (_class = /*#__PURE__*/function () {
function LoadImagePlugin() {
this.imagePool = void 0;
this.renderingContext = void 0;
}
_proto.apply = function apply(renderingService) {
var _this = this;
var _proto = LoadImagePlugin.prototype;
var handleMounted = function handleMounted(e) {
var object = e.target;
var nodeName = object.nodeName,
attributes = object.attributes;
_proto.apply = function apply(renderingService) {
var _this = this;
if (nodeName === g.Shape.IMAGE) {
var img = attributes.img;
var handleMounted = function handleMounted(e) {
var object = e.target;
var nodeName = object.nodeName,
attributes = object.attributes;
if (g.isString(img)) {
_this.imagePool.getImageSync(img, function () {
// set dirty rectangle flag
object.renderable.dirty = true;
renderingService.dirtify();
});
}
}
};
if (nodeName === g.Shape.IMAGE) {
var img = attributes.img;
var handleAttributeChanged = function handleAttributeChanged(e) {
var object = e.target;
var attrName = e.attrName,
newValue = e.newValue;
if (g.isString(img)) {
_this.imagePool.getImageSync(img, function () {
if (object.nodeName === g.Shape.IMAGE) {
if (attrName === 'img') {
if (g.isString(newValue)) {
_this.imagePool.getOrCreateImage(newValue).then(function () {
// set dirty rectangle flag

@@ -607,82 +639,75 @@ object.renderable.dirty = true;

}
};
}
};
var handleAttributeChanged = function handleAttributeChanged(e) {
var object = e.target;
var attrName = e.attrName,
newValue = e.newValue;
renderingService.hooks.init.tapPromise(LoadImagePlugin_1.tag, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_this.renderingContext.root.addEventListener(g.ElementEvent.MOUNTED, handleMounted);
if (object.nodeName === g.Shape.IMAGE) {
if (attrName === 'img') {
if (g.isString(newValue)) {
_this.imagePool.getOrCreateImage(newValue).then(function () {
// set dirty rectangle flag
object.renderable.dirty = true;
renderingService.dirtify();
});
}
_this.renderingContext.root.addEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
case 2:
case "end":
return _context.stop();
}
}
};
}, _callee);
})));
renderingService.hooks.destroy.tap(LoadImagePlugin_1.tag, function () {
_this.renderingContext.root.removeEventListener(g.ElementEvent.MOUNTED, handleMounted);
renderingService.hooks.init.tapPromise(LoadImagePlugin_1.tag, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_this.renderingContext.root.addEventListener(g.ElementEvent.MOUNTED, handleMounted);
_this.renderingContext.root.removeEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
});
};
_this.renderingContext.root.addEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
return LoadImagePlugin;
}(), _class.tag = 'LoadImage', _class);
case 2:
case "end":
return _context.stop();
}
}
}, _callee);
})));
renderingService.hooks.destroy.tap(LoadImagePlugin_1.tag, function () {
_this.renderingContext.root.removeEventListener(g.ElementEvent.MOUNTED, handleMounted);
__decorate([g.inject(exports.ImagePool), __metadata("design:type", exports.ImagePool)], LoadImagePlugin.prototype, "imagePool", void 0);
_this.renderingContext.root.removeEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
});
};
__decorate([g.inject(g.RenderingContext), __metadata("design:type", Object)], LoadImagePlugin.prototype, "renderingContext", void 0);
return LoadImagePlugin;
}(), _class.tag = 'LoadImage', _class);
LoadImagePlugin = LoadImagePlugin_1 = __decorate([g.singleton({
contrib: g.RenderingPluginContribution
})], LoadImagePlugin);
__decorate([g.inject(exports.ImagePool), __metadata("design:type", exports.ImagePool)], LoadImagePlugin.prototype, "imagePool", void 0);
var containerModule = g.Module(function (register) {
register(exports.ImagePool);
register(LoadImagePlugin);
});
var Plugin = /*#__PURE__*/function (_AbstractRendererPlug) {
_inheritsLoose(Plugin, _AbstractRendererPlug);
__decorate([g.inject(g.RenderingContext), __metadata("design:type", Object)], LoadImagePlugin.prototype, "renderingContext", void 0);
function Plugin() {
var _this;
LoadImagePlugin = LoadImagePlugin_1 = __decorate([g.singleton({
contrib: g.RenderingPluginContribution
})], LoadImagePlugin);
var containerModule = g.Module(function (register) {
register(exports.ImagePool);
register(LoadImagePlugin);
});
var Plugin = /*#__PURE__*/function () {
function Plugin() {
this.name = 'image-loader';
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var _proto = Plugin.prototype;
_this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
_this.name = 'image-loader';
return _this;
}
_proto.init = function init(container) {
container.load(containerModule, true);
};
var _proto = Plugin.prototype;
_proto.destroy = function destroy(container) {
container.unload(containerModule);
};
_proto.init = function init() {
this.container.load(containerModule, true);
};
return Plugin;
}();
_proto.destroy = function destroy() {
this.container.unload(containerModule);
};
exports.Plugin = Plugin;
return Plugin;
}(g.AbstractRendererPlugin);
Object.defineProperty(exports, '__esModule', { value: true });
exports.Plugin = Plugin;
Object.defineProperty(exports, '__esModule', { value: true });
})));

@@ -1,3 +0,3 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@antv/g")):"function"==typeof define&&define.amd?define(["exports","@antv/g"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).G=t.G||{},t.G.ImageLoader={}),t.window.G)}(this,(function(t,e){"use strict";function r(t,e,r,n){var o,i=arguments.length,a=3>i?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,r,n);else for(var c=t.length-1;c>=0;c--)(o=t[c])&&(a=(3>i?o(a):i>3?o(e,r,a):o(e,r))||a);return i>3&&a&&Object.defineProperty(e,r,a),a}function n(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function o(){
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@antv/g")):"function"==typeof define&&define.amd?define(["exports","@antv/g"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).G=t.G||{},t.G.ImageLoader={}),t.window.G)}(this,(function(t,e){"use strict";function r(){
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
o=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",a=n.asyncIterator||"@@asyncIterator",c=n.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var o=Object.create((e&&e.prototype instanceof l?e:l).prototype),i=new C(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return O()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=E(a,r);if(c){if(c===h)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=s(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===h)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(t,r,i),o}function s(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=f;var h={};function l(){}function d(){}function g(){}var p={};u(p,i,(function(){return this}));var v=Object.getPrototypeOf,y=v&&v(v(P([])));y&&y!==e&&r.call(y,i)&&(p=y);var m=g.prototype=l.prototype=Object.create(p);function w(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function x(t,e){function n(o,i,a,c){var u=s(t[o],t,i);if("throw"!==u.type){var f=u.arg,h=f.value;return h&&"object"==typeof h&&r.call(h,"__await")?e.resolve(h.__await).then((function(t){n("next",t,a,c)}),(function(t){n("throw",t,a,c)})):e.resolve(h).then((function(t){f.value=t,a(f)}),(function(t){return n("throw",t,a,c)}))}c(u.arg)}var o;this._invoke=function(t,r){function i(){return new e((function(e,o){n(t,r,e,o)}))}return o=o?o.then(i,i):i()}}function E(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,E(t,e),"throw"===e.method))return h;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return h}var n=s(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,h;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,h):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,h)}function L(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function b(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function C(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(L,this),this.reset(!0)}function P(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:O}}function O(){return{value:void 0,done:!0}}return d.prototype=g,u(m,"constructor",g),u(g,"constructor",d),d.displayName=u(g,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,u(t,c,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},w(x.prototype),u(x.prototype,a,(function(){return this})),t.AsyncIterator=x,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new x(f(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(m),u(m,c,"Generator"),u(m,i,(function(){return this})),u(m,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=P,C.prototype={constructor:C,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(b),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(this.prev>=i.tryLoc){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(i.catchLoc>this.prev)return n(i.catchLoc,!0);if(i.finallyLoc>this.prev)return n(i.finallyLoc)}else if(c){if(i.catchLoc>this.prev)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(i.finallyLoc>this.prev)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(this.prev>=o.tryLoc&&r.call(o,"finallyLoc")&&o.finallyLoc>this.prev){var i=o;break}}i&&("break"===t||"continue"===t)&&e>=i.tryLoc&&i.finallyLoc>=e&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,h):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),h},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),b(r),h}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;b(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:P(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),h}},t}function i(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function a(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var a=t.apply(e,r);function c(t){i(a,n,o,c,u,"next",t)}function u(t){i(a,n,o,c,u,"throw",t)}c(void 0)}))}}var c,u;t.ImagePool=function(){function t(){this.imageCache={},this.gradientCache={},this.patternCache={},this.canvasConfig=void 0}var r=t.prototype;return r.getImageSync=function(t,e){return this.imageCache[t]||this.getOrCreateImage(t).then((function(){e&&e()})),this.imageCache[t]},r.getOrCreateImage=function(t){var r=this;if(this.imageCache[t])return Promise.resolve(this.imageCache[t]);var n=this.canvasConfig.createImage;return new Promise((function(o,i){var a;n?a=n(t):e.isBrowser&&(a=new window.Image),a&&(a.onload=function(){o(a)},a.onerror=function(t){i(t)},a.crossOrigin="Anonymous",a.src=t,r.imageCache[t]=a)}))},r.getOrCreatePatternSync=function(t,r,n){var o=this.generatePatternKey(t);if(o&&this.patternCache[o])return this.patternCache[o];var i,a=t.image,c=t.repetition,u=(i=e.isString(a)?this.getImageSync(a,n):a)&&r.createPattern(i,c);return o&&u&&(this.patternCache[o]=u),u},r.getOrCreateGradient=function(t,r){var n=this.generateGradientKey(t),o=t.type,i=t.steps,a=t.width,c=t.height,u=t.cx,f=t.cy;if(this.gradientCache[n])return this.gradientCache[n];var s=null;if(o===e.GradientType.LinearGradient){var h=e.computeLinearGradient(a,c,t.angle);s=r.createLinearGradient(h.x1,h.y1,h.x2,h.y2)}else if(o===e.GradientType.RadialGradient){var l=e.computeRadialGradient(a,c,u,f),d=l.x,g=l.y;s=r.createRadialGradient(d,g,0,d,g,l.r)}return s&&(i.forEach((function(t){var e;null===(e=s)||void 0===e||e.addColorStop(t[0],t[1])})),this.gradientCache[n]=s),this.gradientCache[n]},r.generateGradientKey=function(t){return"gradient-"+t.type+"-"+(t.angle||0)+"-"+(t.cx||0)+"-"+(t.cy||0)+"-"+t.width+"-"+t.height+"-"+t.steps.map((function(t){return t.join("")})).join("-")},r.generatePatternKey=function(t){var r=t.image,n=t.repetition;if(e.isString(r))return"pattern-"+r+"-"+n},t}(),r([e.inject(e.CanvasConfig),n("design:type",Object)],t.ImagePool.prototype,"canvasConfig",void 0),t.ImagePool=r([e.singleton()],t.ImagePool);var f=(c=function(){function t(){this.imagePool=void 0,this.renderingContext=void 0}return t.prototype.apply=function(t){var r=this,n=function(n){var o=n.target;if(o.nodeName===e.Shape.IMAGE){var i=o.attributes.img;e.isString(i)&&r.imagePool.getImageSync(i,(function(){o.renderable.dirty=!0,t.dirtify()}))}},i=function(n){var o=n.target,i=n.newValue;o.nodeName===e.Shape.IMAGE&&"img"===n.attrName&&e.isString(i)&&r.imagePool.getOrCreateImage(i).then((function(){o.renderable.dirty=!0,t.dirtify()}))};t.hooks.init.tapPromise(u.tag,a(o().mark((function t(){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:r.renderingContext.root.addEventListener(e.ElementEvent.MOUNTED,n),r.renderingContext.root.addEventListener(e.ElementEvent.ATTR_MODIFIED,i);case 2:case"end":return t.stop()}}),t)})))),t.hooks.destroy.tap(u.tag,(function(){r.renderingContext.root.removeEventListener(e.ElementEvent.MOUNTED,n),r.renderingContext.root.removeEventListener(e.ElementEvent.ATTR_MODIFIED,i)}))},t}(),c.tag="LoadImage",u=c);r([e.inject(t.ImagePool),n("design:type",t.ImagePool)],f.prototype,"imagePool",void 0),r([e.inject(e.RenderingContext),n("design:type",Object)],f.prototype,"renderingContext",void 0),f=u=r([e.singleton({contrib:e.RenderingPluginContribution})],f);var s=e.Module((function(e){e(t.ImagePool),e(f)}));t.Plugin=function(){function t(){this.name="image-loader"}var e=t.prototype;return e.init=function(t){t.load(s,!0)},e.destroy=function(t){t.unload(s)},t}(),Object.defineProperty(t,"__esModule",{value:!0})}));
r=function(){return t};var t={},e=Object.prototype,n=e.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var o=Object.create((e&&e.prototype instanceof l?e:l).prototype),i=new C(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return O()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=b(a,r);if(c){if(c===h)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=s(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===h)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(t,r,i),o}function s(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=f;var h={};function l(){}function d(){}function p(){}var g={};u(g,i,(function(){return this}));var v=Object.getPrototypeOf,y=v&&v(v(P([])));y&&y!==e&&n.call(y,i)&&(g=y);var m=p.prototype=l.prototype=Object.create(g);function w(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function x(t,e){function r(o,i,a,c){var u=s(t[o],t,i);if("throw"!==u.type){var f=u.arg,h=f.value;return h&&"object"==typeof h&&n.call(h,"__await")?e.resolve(h.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(h).then((function(t){f.value=t,a(f)}),(function(t){return r("throw",t,a,c)}))}c(u.arg)}var o;this._invoke=function(t,n){function i(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(i,i):i()}}function b(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,b(t,e),"throw"===e.method))return h;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return h}var n=s(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,h;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,h):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,h)}function E(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function L(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function C(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function P(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,o=function e(){for(;++r<t.length;)if(n.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:O}}function O(){return{value:void 0,done:!0}}return d.prototype=p,u(m,"constructor",p),u(p,"constructor",d),d.displayName=u(p,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,u(t,c,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},w(x.prototype),u(x.prototype,a,(function(){return this})),t.AsyncIterator=x,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new x(f(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(m),u(m,c,"Generator"),u(m,i,(function(){return this})),u(m,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=P,C.prototype={constructor:C,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(L),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(this.prev>=i.tryLoc){var c=n.call(i,"catchLoc"),u=n.call(i,"finallyLoc");if(c&&u){if(i.catchLoc>this.prev)return r(i.catchLoc,!0);if(i.finallyLoc>this.prev)return r(i.finallyLoc)}else if(c){if(i.catchLoc>this.prev)return r(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(i.finallyLoc>this.prev)return r(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(this.prev>=o.tryLoc&&n.call(o,"finallyLoc")&&o.finallyLoc>this.prev){var i=o;break}}i&&("break"===t||"continue"===t)&&e>=i.tryLoc&&i.finallyLoc>=e&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,h):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),h},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),L(r),h}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;L(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:P(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),h}},t}function n(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function o(t){return function(){var e=this,r=arguments;return new Promise((function(o,i){var a=t.apply(e,r);function c(t){n(a,o,i,c,u,"next",t)}function u(t){n(a,o,i,c,u,"throw",t)}c(void 0)}))}}function i(t,e){return i=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},i(t,e)}function a(t,e,r,n){var o,i=arguments.length,a=3>i?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,r,n);else for(var c=t.length-1;c>=0;c--)(o=t[c])&&(a=(3>i?o(a):i>3?o(e,r,a):o(e,r))||a);return i>3&&a&&Object.defineProperty(e,r,a),a}function c(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}var u,f;t.ImagePool=function(){function t(){this.imageCache={},this.gradientCache={},this.patternCache={},this.canvasConfig=void 0}var r=t.prototype;return r.getImageSync=function(t,e){return this.imageCache[t]||this.getOrCreateImage(t).then((function(){e&&e()})),this.imageCache[t]},r.getOrCreateImage=function(t){var r=this;if(this.imageCache[t])return Promise.resolve(this.imageCache[t]);var n=this.canvasConfig.createImage;return new Promise((function(o,i){var a;n?a=n(t):e.isBrowser&&(a=new window.Image),a&&(a.onload=function(){o(a)},a.onerror=function(t){i(t)},a.crossOrigin="Anonymous",a.src=t,r.imageCache[t]=a)}))},r.getOrCreatePatternSync=function(t,r,n){var o=this.generatePatternKey(t);if(o&&this.patternCache[o])return this.patternCache[o];var i,a=t.image,c=t.repetition,u=(i=e.isString(a)?this.getImageSync(a,n):a)&&r.createPattern(i,c);return o&&u&&(this.patternCache[o]=u),u},r.getOrCreateGradient=function(t,r){var n=this.generateGradientKey(t),o=t.type,i=t.steps,a=t.width,c=t.height,u=t.cx,f=t.cy;if(this.gradientCache[n])return this.gradientCache[n];var s=null;if(o===e.GradientType.LinearGradient){var h=e.computeLinearGradient(a,c,t.angle);s=r.createLinearGradient(h.x1,h.y1,h.x2,h.y2)}else if(o===e.GradientType.RadialGradient){var l=e.computeRadialGradient(a,c,u,f),d=l.x,p=l.y;s=r.createRadialGradient(d,p,0,d,p,l.r)}return s&&(i.forEach((function(t){var e;null===(e=s)||void 0===e||e.addColorStop(t[0],t[1])})),this.gradientCache[n]=s),this.gradientCache[n]},r.generateGradientKey=function(t){return"gradient-"+t.type+"-"+(t.angle||0)+"-"+(t.cx||0)+"-"+(t.cy||0)+"-"+t.width+"-"+t.height+"-"+t.steps.map((function(t){return t.join("")})).join("-")},r.generatePatternKey=function(t){var r=t.image,n=t.repetition;if(e.isString(r))return"pattern-"+r+"-"+n},t}(),a([e.inject(e.CanvasConfig),c("design:type",Object)],t.ImagePool.prototype,"canvasConfig",void 0),t.ImagePool=a([e.singleton()],t.ImagePool);var s=(u=function(){function t(){this.imagePool=void 0,this.renderingContext=void 0}return t.prototype.apply=function(t){var n=this,i=function(r){var o=r.target;if(o.nodeName===e.Shape.IMAGE){var i=o.attributes.img;e.isString(i)&&n.imagePool.getImageSync(i,(function(){o.renderable.dirty=!0,t.dirtify()}))}},a=function(r){var o=r.target,i=r.newValue;o.nodeName===e.Shape.IMAGE&&"img"===r.attrName&&e.isString(i)&&n.imagePool.getOrCreateImage(i).then((function(){o.renderable.dirty=!0,t.dirtify()}))};t.hooks.init.tapPromise(f.tag,o(r().mark((function t(){return r().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:n.renderingContext.root.addEventListener(e.ElementEvent.MOUNTED,i),n.renderingContext.root.addEventListener(e.ElementEvent.ATTR_MODIFIED,a);case 2:case"end":return t.stop()}}),t)})))),t.hooks.destroy.tap(f.tag,(function(){n.renderingContext.root.removeEventListener(e.ElementEvent.MOUNTED,i),n.renderingContext.root.removeEventListener(e.ElementEvent.ATTR_MODIFIED,a)}))},t}(),u.tag="LoadImage",f=u);a([e.inject(t.ImagePool),c("design:type",t.ImagePool)],s.prototype,"imagePool",void 0),a([e.inject(e.RenderingContext),c("design:type",Object)],s.prototype,"renderingContext",void 0),s=f=a([e.singleton({contrib:e.RenderingPluginContribution})],s);var h=e.Module((function(e){e(t.ImagePool),e(s)})),l=function(t){var e,r;function n(){for(var e,r=arguments.length,n=new Array(r),o=0;r>o;o++)n[o]=arguments[o];return(e=t.call.apply(t,[this].concat(n))||this).name="image-loader",e}r=t,(e=n).prototype=Object.create(r.prototype),e.prototype.constructor=e,i(e,r);var o=n.prototype;return o.init=function(){this.container.load(h,!0)},o.destroy=function(){this.container.unload(h)},n}(e.AbstractRendererPlugin);t.Plugin=l,Object.defineProperty(t,"__esModule",{value:!0})}));
{
"name": "@antv/g-plugin-image-loader",
"version": "0.5.0-alpha.0",
"version": "0.5.0",
"description": "A G plugin for loading image",

@@ -41,3 +41,3 @@ "keywords": [

},
"gitHead": "94fbafea28d1f2910720172b7e45a859c8e3a454"
"gitHead": "5e346e68fda61488806180f03564e4d340ae91c3"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc