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
0
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 2.1.11 to 2.1.12

18

dist/index.esm.js
/*!
* @antv/g-plugin-image-loader
* @description A G plugin for loading image
* @version 2.1.11
* @date 11/27/2024, 2:17:32 PM
* @version 2.1.12
* @date 12/20/2024, 6:52:51 AM
* @author AntVis

@@ -13,3 +13,3 @@ * @docs https://g.antv.antgroup.com/

import _inherits from '@babel/runtime/helpers/inherits';
import { ElementEvent, OffscreenCanvasCreator, isBrowser, parsedTransformToMat4, parseTransform, DisplayObject, GradientType, computeLinearGradient, computeRadialGradient, UnitType, Shape, AbstractRendererPlugin } from '@antv/g-lite';
import { ElementEvent, OffscreenCanvasCreator, parsedTransformToMat4, parseTransform, DisplayObject, GradientType, computeLinearGradient, computeRadialGradient, UnitType, Shape, AbstractRendererPlugin } from '@antv/g-lite';
import _regeneratorRuntime from '@babel/runtime/helpers/regeneratorRuntime';

@@ -248,2 +248,3 @@ import _objectSpread from '@babel/runtime/helpers/objectSpread2';

value: function getOrCreateImage(src, ref) {
var _this2 = this;
var imageSource = isString(src) ? src : src.src;

@@ -274,12 +275,5 @@ if (!isString(src) && !IMAGE_CACHE.has(imageSource)) {

}
// @see https://github.com/antvis/g/issues/938
var createImage = this.context.config.createImage;
return new Promise(function (resolve, reject) {
var image;
if (createImage) {
image = createImage(imageSource);
} else if (isBrowser) {
image = new window.Image();
}
// @see https://github.com/antvis/g/issues/938
var image = _this2.context.config.createImage();
if (image) {

@@ -286,0 +280,0 @@ var _imageCache2 = {

/*!
* @antv/g-plugin-image-loader
* @description A G plugin for loading image
* @version 2.1.11
* @date 11/27/2024, 2:17:32 PM
* @version 2.1.12
* @date 12/20/2024, 6:52:51 AM
* @author AntVis

@@ -249,2 +249,3 @@ * @docs https://g.antv.antgroup.com/

value: function getOrCreateImage(src, ref) {
var _this2 = this;
var imageSource = util.isString(src) ? src : src.src;

@@ -275,12 +276,5 @@ if (!util.isString(src) && !IMAGE_CACHE.has(imageSource)) {

}
// @see https://github.com/antvis/g/issues/938
var createImage = this.context.config.createImage;
return new Promise(function (resolve, reject) {
var image;
if (createImage) {
image = createImage(imageSource);
} else if (gLite.isBrowser) {
image = new window.Image();
}
// @see https://github.com/antvis/g/issues/938
var image = _this2.context.config.createImage();
if (image) {

@@ -287,0 +281,0 @@ var _imageCache2 = {

/*!
* @antv/g-plugin-image-loader
* @description A G plugin for loading image
* @version 2.1.11
* @date 11/27/2024, 2:17:32 PM
* @version 2.1.12
* @date 12/20/2024, 6:52:51 AM
* @author AntVis
* @docs https://g.antv.antgroup.com/
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@antv/g-lite")):"function"==typeof define&&define.amd?define(["exports","@antv/g-lite"],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){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}function i(t){var e=function(t,e){if("object"!=n(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var i=r.call(t,e||"default");if("object"!=n(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==n(e)?e:e+""}function o(t,e){for(var r=0;e.length>r;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,i(n.key),n)}}function a(t,e,r){return e&&o(t.prototype,e),r&&o(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function c(t){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},c(t)}function u(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(u=function(){return!!t})()}function l(t,e){if(e&&("object"==n(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function f(t,e){return f=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},f(t,e)}function s(){s=function(){return e};var t,e={},r=Object.prototype,i=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},a="function"==typeof Symbol?Symbol:{},c=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",l=a.toStringTag||"@@toStringTag";function f(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{f({},"")}catch(t){f=function(t,e,r){return t[e]=r}}function h(t,e,r,n){var i=Object.create((e&&e.prototype instanceof b?e:b).prototype),a=new R(n||[]);return o(i,"_invoke",{value:A(t,r,a)}),i}function p(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=h;var d="suspendedStart",v="suspendedYield",y="executing",g="completed",m={};function b(){}function w(){}function O(){}var S={};f(S,c,(function(){return this}));var E=Object.getPrototypeOf,x=E&&E(E(_([])));x&&x!==r&&i.call(x,c)&&(S=x);var k=O.prototype=b.prototype=Object.create(S);function j(t){["next","throw","return"].forEach((function(e){f(t,e,(function(t){return this._invoke(e,t)}))}))}function P(t,e){function r(o,a,c,u){var l=p(t[o],t,a);if("throw"!==l.type){var f=l.arg,s=f.value;return s&&"object"==n(s)&&i.call(s,"__await")?e.resolve(s.__await).then((function(t){r("next",t,c,u)}),(function(t){r("throw",t,c,u)})):e.resolve(s).then((function(t){f.value=t,c(f)}),(function(t){return r("throw",t,c,u)}))}u(l.arg)}var a;o(this,"_invoke",{value:function(t,n){function i(){return new e((function(e,i){r(t,n,e,i)}))}return a=a?a.then(i,i):i()}})}function A(e,r,n){var i=d;return function(o,a){if(i===y)throw Error("Generator is already running");if(i===g){if("throw"===o)throw a;return{value:t,done:!0}}for(n.method=o,n.arg=a;;){var c=n.delegate;if(c){var u=I(c,n);if(u){if(u===m)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(i===d)throw i=g,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);i=y;var l=p(e,r,n);if("normal"===l.type){if(i=n.done?g:v,l.arg===m)continue;return{value:l.arg,done:n.done}}"throw"===l.type&&(i=g,n.method="throw",n.arg=l.arg)}}}function I(e,r){var n=r.method,i=e.iterator[n];if(i===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,I(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),m;var o=p(i,e.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,m;var a=o.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,m):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,m)}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 T(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function R(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(L,this),this.reset(!0)}function _(e){if(e||""===e){var r=e[c];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,a=function r(){for(;++o<e.length;)if(i.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return a.next=a}}throw new TypeError(n(e)+" is not iterable")}return w.prototype=O,o(k,"constructor",{value:O,configurable:!0}),o(O,"constructor",{value:w,configurable:!0}),w.displayName=f(O,l,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===w||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,O):(t.__proto__=O,f(t,l,"GeneratorFunction")),t.prototype=Object.create(k),t},e.awrap=function(t){return{__await:t}},j(P.prototype),f(P.prototype,u,(function(){return this})),e.AsyncIterator=P,e.async=function(t,r,n,i,o){void 0===o&&(o=Promise);var a=new P(h(t,r,n,i),o);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},j(k),f(k,l,"Generator"),f(k,c,(function(){return this})),f(k,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=_,R.prototype={constructor:R,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(T),!e)for(var r in this)"t"===r.charAt(0)&&i.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function n(n,i){return c.type="throw",c.arg=e,r.next=n,i&&(r.method="next",r.arg=t),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],c=a.completion;if("root"===a.tryLoc)return n("end");if(this.prev>=a.tryLoc){var u=i.call(a,"catchLoc"),l=i.call(a,"finallyLoc");if(u&&l){if(a.catchLoc>this.prev)return n(a.catchLoc,!0);if(a.finallyLoc>this.prev)return n(a.finallyLoc)}else if(u){if(a.catchLoc>this.prev)return n(a.catchLoc,!0)}else{if(!l)throw Error("try statement without catch or finally");if(a.finallyLoc>this.prev)return n(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(this.prev>=n.tryLoc&&i.call(n,"finallyLoc")&&n.finallyLoc>this.prev){var o=n;break}}o&&("break"===t||"continue"===t)&&e>=o.tryLoc&&o.finallyLoc>=e&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,m):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),m},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),T(r),m}},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 i=n.arg;T(r)}return i}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:_(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),m}},e}function h(t,e,r){return(e=i(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function p(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function d(t){for(var e=1;arguments.length>e;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?p(Object(r),!0).forEach((function(e){h(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):p(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function v(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);e>r;r++)n[r]=t[r];return n}function y(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,i,o,a,c=[],u=!0,l=!1;try{if(o=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=o.call(r)).done)&&(c.push(n.value),c.length!==e);u=!0);}catch(t){l=!0,i=t}finally{try{if(!u&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(l)throw i}}return c}}(t,e)||function(t,e){if(t){if("string"==typeof t)return v(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?v(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(t,e,r,n,i,o,a){try{var c=t[o](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,i)}function m(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function a(t){g(o,n,i,a,c,"next",t)}function c(t){g(o,n,i,a,c,"throw",t)}a(void 0)}))}}function b(t){return"string"==typeof t}var w="undefined"!=typeof Float32Array?Float32Array:Array;Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)});var O=function(){return a((function t(){r(this,t),this.cacheStore=new Map}),[{key:"onRefAdded",value:function(t){}},{key:"has",value:function(t){return this.cacheStore.has(t)}},{key:"put",value:function(t,e,r){return!this.cacheStore.has(t)&&(this.cacheStore.set(t,{value:e,counter:new Set([r])}),this.onRefAdded(r),!0)}},{key:"get",value:function(t,e){var r=this.cacheStore.get(t);return r?(r.counter.has(e)||(r.counter.add(e),this.onRefAdded(e)),r.value):null}},{key:"update",value:function(t,e,r){var n=this.cacheStore.get(t);return!!n&&(n.value=d(d({},n.value),e),n.counter.has(r)||(n.counter.add(r),this.onRefAdded(r)),!0)}},{key:"release",value:function(t,e){var r=this.cacheStore.get(t);return!!r&&(r.counter.delete(e),r.counter.size>0||this.cacheStore.delete(t),!0)}},{key:"releaseRef",value:function(t){var e=this;Array.from(this.cacheStore.keys()).forEach((function(r){e.release(r,t)}))}},{key:"getSize",value:function(){return this.cacheStore.size}},{key:"clear",value:function(){this.cacheStore.clear()}}])}(),S=[],E=[],x=function(){function t(){r(this,t)}return a(t,null,[{key:"stop",value:function(){t.rafId&&((arguments.length>0&&void 0!==arguments[0]?arguments[0]:t.api).cancelAnimationFrame(t.rafId),t.rafId=null)}},{key:"executeTask",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:t.api;(S.length>0||E.length>0)&&(E.forEach((function(t){return t()})),E=S.splice(0,t.TASK_NUM_PER_FRAME),t.rafId=e.requestAnimationFrame((function(){t.executeTask(e)})))}},{key:"sliceImage",value:function(e,r,n,i){for(var o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:t.api,c=e.naturalWidth||e.width,u=e.naturalHeight||e.height,l=r-o,f=n-o,s=Math.ceil(c/l),h=Math.ceil(u/f),p={tileSize:[r,n],gridSize:[h,s],tiles:Array(h).fill(null).map((function(){return Array(s).fill(null)}))},d=function(t){for(var o=function(o){S.push((function(){var s=o*l,h=t*f,d=[Math.min(r,c-s),Math.min(n,u-h)],v=d[0],y=d[1],g=a.createCanvas();g.width=r,g.height=n,g.getContext("2d").drawImage(e,s,h,v,y,0,0,v,y),p.tiles[t][o]={x:s,y:h,tileX:o,tileY:t,data:g},i()}))},h=0;s>h;h++)o(h)},v=0;h>v;v++)d(v);return t.stop(),t.executeTask(),p}}])}();x.TASK_NUM_PER_FRAME=10;var k=new O;k.onRefAdded=function(t){var r=this;t.addEventListener(e.ElementEvent.DESTROY,(function(){r.releaseRef(t)}),{once:!0})};var j=function(){return a((function t(e,n){r(this,t),this.gradientCache={},this.patternCache={},this.context=e,this.runtime=n}),[{key:"getImageSync",value:function(t,e,r){var n=b(t)?t:t.src;if(k.has(n)){var i=k.get(n,e);if(i.img.complete)return null==r||r(i),i}return this.getOrCreateImage(t,e).then((function(t){null==r||r(t)})).catch((function(){})),null}},{key:"getOrCreateImage",value:function(t,r){var n=b(t)?t:t.src;if(!b(t)&&!k.has(n)){var i={img:t,size:[t.naturalWidth||t.width,t.naturalHeight||t.height],tileSize:P(t)};k.put(n,i,r)}if(k.has(n)){var o=k.get(n,r);return o.img.complete?Promise.resolve(o):new Promise((function(t,e){o.img.addEventListener("load",(function(){o.size=[o.img.naturalWidth||o.img.width,o.img.naturalHeight||o.img.height],o.tileSize=P(o.img),t(o)})),o.img.addEventListener("error",(function(t){e(t)}))}))}var a=this.context.config.createImage;return new Promise((function(t,i){var o;if(a?o=a(n):e.isBrowser&&(o=new window.Image),o){var c={img:o,size:[0,0],tileSize:P(o)};k.put(n,c,r),o.onload=function(){c.size=[o.naturalWidth||o.width,o.naturalHeight||o.height],c.tileSize=P(c.img),t(c)},o.onerror=function(t){i(t)},o.crossOrigin="Anonymous",o.src=n}}))}},{key:"createDownSampledImage",value:(n=m(s().mark((function t(e,r){var n,i,o,a,c,u,l,f,h,p,v,g,m,b;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getOrCreateImage(e,r);case 2:if(void 0===(n=t.sent).downSamplingRate){t.next=5;break}return t.abrupt("return",n);case 5:if(c=void 0===(a=(o="boolean"==typeof(i=this.context.config.enableLargeImageOptimization)?{}:i).maxDownSampledImageSize)?2048:a,l=void 0===(u=o.downSamplingRateThreshold)?.5:u,f=this.runtime.globalThis.createImageBitmap,h=y(n.size,2),g=n.img,m=Math.min((c+c)/((p=h[0])+(v=h[1])),Math.max(.01,Math.min(l,.5))),b=d(d({},n),{},{downSamplingRate:m}),k.update(n.img.src,b,r),!f){t.next=25;break}return t.prev=14,t.next=17,f(n.img,{resizeWidth:p*m,resizeHeight:v*m});case 17:g=t.sent,t.next=23;break;case 20:t.prev=20,t.t0=t.catch(14),m=1;case 23:t.next=26;break;case 25:m=1;case 26:return b=d(d({},this.getImageSync(e,r)),{},{downSampled:g,downSamplingRate:m}),k.update(n.img.src,b,r),t.abrupt("return",b);case 29:case"end":return t.stop()}}),t,this,[[14,20]])}))),function(t,e){return n.apply(this,arguments)})},{key:"createImageTiles",value:(t=m(s().mark((function t(r,n,i,o){var a,c,u;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getOrCreateImage(r,o);case 2:return a=t.sent,x.api={requestAnimationFrame:(c=o.ownerDocument.defaultView).requestAnimationFrame,cancelAnimationFrame:c.cancelAnimationFrame,createCanvas:function(){return e.OffscreenCanvasCreator.createCanvas()}},u=d(d({},a),x.sliceImage(a.img,a.tileSize[0],a.tileSize[0],i)),k.update(a.img.src,u,o),t.abrupt("return",u);case 8:case"end":return t.stop()}}),t,this)}))),function(e,r,n,i){return t.apply(this,arguments)})},{key:"releaseImage",value:function(t,e){k.release(b(t)?t:t.src,e)}},{key:"releaseImageRef",value:function(t){k.releaseRef(t)}},{key:"getOrCreatePatternSync",value:function(t,r,n,i,o,a,c){var u=this.generatePatternKey(r);if(u&&this.patternCache[u])return this.patternCache[u];var l,f=r.image,s=r.repetition,h=r.transform,p=!1;if(b(f)){var d=this.getImageSync(f,t,c);l=null==d?void 0:d.img}else i?(l=i,p=!0):l=f;var v,y,g=l&&n.createPattern(l,s);g&&(v=h?e.parsedTransformToMat4(e.parseTransform(h),new e.DisplayObject({})):function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}((y=new w(16),w!=Float32Array&&(y[1]=0,y[2]=0,y[3]=0,y[4]=0,y[6]=0,y[7]=0,y[8]=0,y[9]=0,y[11]=0,y[12]=0,y[13]=0,y[14]=0),y[0]=1,y[5]=1,y[10]=1,y[15]=1,y)),p&&function(t,e,r){var n=r[0],i=r[1],o=r[2];t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*i,t[5]=e[5]*i,t[6]=e[6]*i,t[7]=e[7]*i,t[8]=e[8]*o,t[9]=e[9]*o,t[10]=e[10]*o,t[11]=e[11]*o,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]}(v,v,[1/o,1/o,1]),g.setTransform({a:v[0],b:v[1],c:v[4],d:v[5],e:v[12]+a[0],f:v[13]+a[1]}));return u&&g&&(this.patternCache[u]=g),g}},{key:"getOrCreateGradient",value:function(t,r){var n=this.generateGradientKey(t),i=t.type,o=t.steps,a=t.min,c=t.width,u=t.height,l=t.cx,f=t.cy,s=t.size;if(this.gradientCache[n])return this.gradientCache[n];var h=null;if(i===e.GradientType.LinearGradient){var p=e.computeLinearGradient(a,c,u,t.angle);h=r.createLinearGradient(p.x1,p.y1,p.x2,p.y2)}else if(i===e.GradientType.RadialGradient){var d=e.computeRadialGradient(a,c,u,l,f,s),v=d.x,y=d.y;h=r.createRadialGradient(v,y,0,v,y,d.r)}return h&&(o.forEach((function(t){var r,n=t.offset;n.unit===e.UnitType.kPercentage&&(null===(r=h)||void 0===r||r.addColorStop(n.value/100,""+t.color))})),this.gradientCache[n]=h),this.gradientCache[n]}},{key:"generateGradientKey",value:function(t){var e=t.min,r=t.width,n=t.height,i=t.steps,o=t.angle,a=t.cx,c=t.cy,u=t.size;return"gradient-".concat(t.type,"-").concat((null==o?void 0:""+o)||0,"-").concat((null==a?void 0:""+a)||0,"-").concat((null==c?void 0:""+c)||0,"-").concat((null==u?void 0:""+u)||0,"-").concat(e[0],"-").concat(e[1],"-").concat(r,"-").concat(n,"-").concat(i.map((function(t){var e=t.color;return"".concat(t.offset).concat(e)})).join("-"))}},{key:"generatePatternKey",value:function(t){var e=t.image,r=t.repetition;return b(e)?"pattern-".concat(e,"-").concat(r):"rect"===e.nodeName?"pattern-".concat(e.entity,"-").concat(r):void 0}}]);var t,n}();function P(t){if(!t.complete)return[0,0];var e=t.naturalWidth||t.width,r=t.naturalHeight||t.height,n=256;return[256,512].forEach((function(t){1e3>Math.ceil(r/t)*Math.ceil(e/t)&&(n=t)})),[n,n]}j.isSupportTile=!!e.OffscreenCanvasCreator.createCanvas();var A=function(){function t(){r(this,t)}return a(t,[{key:"apply",value:function(r){var n=r.renderingService,i=r.imagePool,o=r.renderingContext.root.ownerDocument.defaultView,a=function(t,e,r){var n=t.parsedStyle,i=n.width,o=n.height;i&&!o?t.setAttribute("height",r/e*i):!i&&o&&t.setAttribute("width",e/r*o)},c=function(t){var r=t.target,o=r.attributes;if(r.nodeName===e.Shape.IMAGE){var c=o.keepAspectRatio;i.getImageSync(o.src,r,(function(t){var e=t.img;c&&a(r,e.width,e.height),r.renderable.dirty=!0,n.dirtify()}))}},u=function(t){var r=t.target,o=t.prevValue,c=t.newValue;r.nodeName===e.Shape.IMAGE&&"src"===t.attrName&&(o!==c&&i.releaseImage(o,r),b(c)&&i.getOrCreateImage(c,r).then((function(t){var e=t.img;r.attributes.keepAspectRatio&&a(r,e.width,e.height),r.renderable.dirty=!0,n.dirtify()})).catch((function(){})))};n.hooks.init.tap(t.tag,(function(){o.addEventListener(e.ElementEvent.MOUNTED,c),o.addEventListener(e.ElementEvent.ATTR_MODIFIED,u)})),n.hooks.destroy.tap(t.tag,(function(){o.removeEventListener(e.ElementEvent.MOUNTED,c),o.removeEventListener(e.ElementEvent.ATTR_MODIFIED,u)}))}}])}();A.tag="LoadImage";var I=function(t){function e(){var t,n,i,o;r(this,e);for(var a=arguments.length,f=Array(a),s=0;a>s;s++)f[s]=arguments[s];return n=this,i=e,o=[].concat(f),i=c(i),(t=l(n,u()?Reflect.construct(i,o||[],c(n).constructor):i.apply(n,o))).name="image-loader",t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&f(t,e)}(e,t),a(e,[{key:"init",value:function(t){this.context.imagePool=new j(this.context,t),this.addRenderingPlugin(new A)}},{key:"destroy",value:function(){this.removeAllRenderingPlugins()}}])}(e.AbstractRendererPlugin);t.ImagePool=j,t.Plugin=I}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@antv/g-lite")):"function"==typeof define&&define.amd?define(["exports","@antv/g-lite"],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){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}function i(t){var e=function(t,e){if("object"!=n(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var i=r.call(t,e||"default");if("object"!=n(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==n(e)?e:e+""}function o(t,e){for(var r=0;e.length>r;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,i(n.key),n)}}function a(t,e,r){return e&&o(t.prototype,e),r&&o(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function c(t){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},c(t)}function u(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(u=function(){return!!t})()}function l(t,e){if(e&&("object"==n(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function f(t,e){return f=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},f(t,e)}function s(){s=function(){return e};var t,e={},r=Object.prototype,i=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},a="function"==typeof Symbol?Symbol:{},c=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",l=a.toStringTag||"@@toStringTag";function f(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{f({},"")}catch(t){f=function(t,e,r){return t[e]=r}}function h(t,e,r,n){var i=Object.create((e&&e.prototype instanceof b?e:b).prototype),a=new R(n||[]);return o(i,"_invoke",{value:A(t,r,a)}),i}function p(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=h;var d="suspendedStart",v="suspendedYield",y="executing",g="completed",m={};function b(){}function w(){}function O(){}var S={};f(S,c,(function(){return this}));var E=Object.getPrototypeOf,x=E&&E(E(_([])));x&&x!==r&&i.call(x,c)&&(S=x);var k=O.prototype=b.prototype=Object.create(S);function j(t){["next","throw","return"].forEach((function(e){f(t,e,(function(t){return this._invoke(e,t)}))}))}function P(t,e){function r(o,a,c,u){var l=p(t[o],t,a);if("throw"!==l.type){var f=l.arg,s=f.value;return s&&"object"==n(s)&&i.call(s,"__await")?e.resolve(s.__await).then((function(t){r("next",t,c,u)}),(function(t){r("throw",t,c,u)})):e.resolve(s).then((function(t){f.value=t,c(f)}),(function(t){return r("throw",t,c,u)}))}u(l.arg)}var a;o(this,"_invoke",{value:function(t,n){function i(){return new e((function(e,i){r(t,n,e,i)}))}return a=a?a.then(i,i):i()}})}function A(e,r,n){var i=d;return function(o,a){if(i===y)throw Error("Generator is already running");if(i===g){if("throw"===o)throw a;return{value:t,done:!0}}for(n.method=o,n.arg=a;;){var c=n.delegate;if(c){var u=L(c,n);if(u){if(u===m)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(i===d)throw i=g,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);i=y;var l=p(e,r,n);if("normal"===l.type){if(i=n.done?g:v,l.arg===m)continue;return{value:l.arg,done:n.done}}"throw"===l.type&&(i=g,n.method="throw",n.arg=l.arg)}}}function L(e,r){var n=r.method,i=e.iterator[n];if(i===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,L(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),m;var o=p(i,e.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,m;var a=o.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,m):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,m)}function I(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 T(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function R(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(I,this),this.reset(!0)}function _(e){if(e||""===e){var r=e[c];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,a=function r(){for(;++o<e.length;)if(i.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return a.next=a}}throw new TypeError(n(e)+" is not iterable")}return w.prototype=O,o(k,"constructor",{value:O,configurable:!0}),o(O,"constructor",{value:w,configurable:!0}),w.displayName=f(O,l,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===w||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,O):(t.__proto__=O,f(t,l,"GeneratorFunction")),t.prototype=Object.create(k),t},e.awrap=function(t){return{__await:t}},j(P.prototype),f(P.prototype,u,(function(){return this})),e.AsyncIterator=P,e.async=function(t,r,n,i,o){void 0===o&&(o=Promise);var a=new P(h(t,r,n,i),o);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},j(k),f(k,l,"Generator"),f(k,c,(function(){return this})),f(k,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=_,R.prototype={constructor:R,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(T),!e)for(var r in this)"t"===r.charAt(0)&&i.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function n(n,i){return c.type="throw",c.arg=e,r.next=n,i&&(r.method="next",r.arg=t),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],c=a.completion;if("root"===a.tryLoc)return n("end");if(this.prev>=a.tryLoc){var u=i.call(a,"catchLoc"),l=i.call(a,"finallyLoc");if(u&&l){if(a.catchLoc>this.prev)return n(a.catchLoc,!0);if(a.finallyLoc>this.prev)return n(a.finallyLoc)}else if(u){if(a.catchLoc>this.prev)return n(a.catchLoc,!0)}else{if(!l)throw Error("try statement without catch or finally");if(a.finallyLoc>this.prev)return n(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(this.prev>=n.tryLoc&&i.call(n,"finallyLoc")&&n.finallyLoc>this.prev){var o=n;break}}o&&("break"===t||"continue"===t)&&e>=o.tryLoc&&o.finallyLoc>=e&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,m):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),m},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),T(r),m}},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 i=n.arg;T(r)}return i}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:_(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),m}},e}function h(t,e,r){return(e=i(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function p(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function d(t){for(var e=1;arguments.length>e;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?p(Object(r),!0).forEach((function(e){h(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):p(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function v(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);e>r;r++)n[r]=t[r];return n}function y(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,i,o,a,c=[],u=!0,l=!1;try{if(o=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=o.call(r)).done)&&(c.push(n.value),c.length!==e);u=!0);}catch(t){l=!0,i=t}finally{try{if(!u&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(l)throw i}}return c}}(t,e)||function(t,e){if(t){if("string"==typeof t)return v(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?v(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(t,e,r,n,i,o,a){try{var c=t[o](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,i)}function m(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function a(t){g(o,n,i,a,c,"next",t)}function c(t){g(o,n,i,a,c,"throw",t)}a(void 0)}))}}function b(t){return"string"==typeof t}var w="undefined"!=typeof Float32Array?Float32Array:Array;Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)});var O=function(){return a((function t(){r(this,t),this.cacheStore=new Map}),[{key:"onRefAdded",value:function(t){}},{key:"has",value:function(t){return this.cacheStore.has(t)}},{key:"put",value:function(t,e,r){return!this.cacheStore.has(t)&&(this.cacheStore.set(t,{value:e,counter:new Set([r])}),this.onRefAdded(r),!0)}},{key:"get",value:function(t,e){var r=this.cacheStore.get(t);return r?(r.counter.has(e)||(r.counter.add(e),this.onRefAdded(e)),r.value):null}},{key:"update",value:function(t,e,r){var n=this.cacheStore.get(t);return!!n&&(n.value=d(d({},n.value),e),n.counter.has(r)||(n.counter.add(r),this.onRefAdded(r)),!0)}},{key:"release",value:function(t,e){var r=this.cacheStore.get(t);return!!r&&(r.counter.delete(e),r.counter.size>0||this.cacheStore.delete(t),!0)}},{key:"releaseRef",value:function(t){var e=this;Array.from(this.cacheStore.keys()).forEach((function(r){e.release(r,t)}))}},{key:"getSize",value:function(){return this.cacheStore.size}},{key:"clear",value:function(){this.cacheStore.clear()}}])}(),S=[],E=[],x=function(){function t(){r(this,t)}return a(t,null,[{key:"stop",value:function(){t.rafId&&((arguments.length>0&&void 0!==arguments[0]?arguments[0]:t.api).cancelAnimationFrame(t.rafId),t.rafId=null)}},{key:"executeTask",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:t.api;(S.length>0||E.length>0)&&(E.forEach((function(t){return t()})),E=S.splice(0,t.TASK_NUM_PER_FRAME),t.rafId=e.requestAnimationFrame((function(){t.executeTask(e)})))}},{key:"sliceImage",value:function(e,r,n,i){for(var o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:t.api,c=e.naturalWidth||e.width,u=e.naturalHeight||e.height,l=r-o,f=n-o,s=Math.ceil(c/l),h=Math.ceil(u/f),p={tileSize:[r,n],gridSize:[h,s],tiles:Array(h).fill(null).map((function(){return Array(s).fill(null)}))},d=function(t){for(var o=function(o){S.push((function(){var s=o*l,h=t*f,d=[Math.min(r,c-s),Math.min(n,u-h)],v=d[0],y=d[1],g=a.createCanvas();g.width=r,g.height=n,g.getContext("2d").drawImage(e,s,h,v,y,0,0,v,y),p.tiles[t][o]={x:s,y:h,tileX:o,tileY:t,data:g},i()}))},h=0;s>h;h++)o(h)},v=0;h>v;v++)d(v);return t.stop(),t.executeTask(),p}}])}();x.TASK_NUM_PER_FRAME=10;var k=new O;k.onRefAdded=function(t){var r=this;t.addEventListener(e.ElementEvent.DESTROY,(function(){r.releaseRef(t)}),{once:!0})};var j=function(){return a((function t(e,n){r(this,t),this.gradientCache={},this.patternCache={},this.context=e,this.runtime=n}),[{key:"getImageSync",value:function(t,e,r){var n=b(t)?t:t.src;if(k.has(n)){var i=k.get(n,e);if(i.img.complete)return null==r||r(i),i}return this.getOrCreateImage(t,e).then((function(t){null==r||r(t)})).catch((function(){})),null}},{key:"getOrCreateImage",value:function(t,e){var r=this,n=b(t)?t:t.src;if(!b(t)&&!k.has(n)){var i={img:t,size:[t.naturalWidth||t.width,t.naturalHeight||t.height],tileSize:P(t)};k.put(n,i,e)}if(k.has(n)){var o=k.get(n,e);return o.img.complete?Promise.resolve(o):new Promise((function(t,e){o.img.addEventListener("load",(function(){o.size=[o.img.naturalWidth||o.img.width,o.img.naturalHeight||o.img.height],o.tileSize=P(o.img),t(o)})),o.img.addEventListener("error",(function(t){e(t)}))}))}return new Promise((function(t,i){var o=r.context.config.createImage();if(o){var a={img:o,size:[0,0],tileSize:P(o)};k.put(n,a,e),o.onload=function(){a.size=[o.naturalWidth||o.width,o.naturalHeight||o.height],a.tileSize=P(a.img),t(a)},o.onerror=function(t){i(t)},o.crossOrigin="Anonymous",o.src=n}}))}},{key:"createDownSampledImage",value:(n=m(s().mark((function t(e,r){var n,i,o,a,c,u,l,f,h,p,v,g,m,b;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getOrCreateImage(e,r);case 2:if(void 0===(n=t.sent).downSamplingRate){t.next=5;break}return t.abrupt("return",n);case 5:if(c=void 0===(a=(o="boolean"==typeof(i=this.context.config.enableLargeImageOptimization)?{}:i).maxDownSampledImageSize)?2048:a,l=void 0===(u=o.downSamplingRateThreshold)?.5:u,f=this.runtime.globalThis.createImageBitmap,h=y(n.size,2),g=n.img,m=Math.min((c+c)/((p=h[0])+(v=h[1])),Math.max(.01,Math.min(l,.5))),b=d(d({},n),{},{downSamplingRate:m}),k.update(n.img.src,b,r),!f){t.next=25;break}return t.prev=14,t.next=17,f(n.img,{resizeWidth:p*m,resizeHeight:v*m});case 17:g=t.sent,t.next=23;break;case 20:t.prev=20,t.t0=t.catch(14),m=1;case 23:t.next=26;break;case 25:m=1;case 26:return b=d(d({},this.getImageSync(e,r)),{},{downSampled:g,downSamplingRate:m}),k.update(n.img.src,b,r),t.abrupt("return",b);case 29:case"end":return t.stop()}}),t,this,[[14,20]])}))),function(t,e){return n.apply(this,arguments)})},{key:"createImageTiles",value:(t=m(s().mark((function t(r,n,i,o){var a,c,u;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getOrCreateImage(r,o);case 2:return a=t.sent,x.api={requestAnimationFrame:(c=o.ownerDocument.defaultView).requestAnimationFrame,cancelAnimationFrame:c.cancelAnimationFrame,createCanvas:function(){return e.OffscreenCanvasCreator.createCanvas()}},u=d(d({},a),x.sliceImage(a.img,a.tileSize[0],a.tileSize[0],i)),k.update(a.img.src,u,o),t.abrupt("return",u);case 8:case"end":return t.stop()}}),t,this)}))),function(e,r,n,i){return t.apply(this,arguments)})},{key:"releaseImage",value:function(t,e){k.release(b(t)?t:t.src,e)}},{key:"releaseImageRef",value:function(t){k.releaseRef(t)}},{key:"getOrCreatePatternSync",value:function(t,r,n,i,o,a,c){var u=this.generatePatternKey(r);if(u&&this.patternCache[u])return this.patternCache[u];var l,f=r.image,s=r.repetition,h=r.transform,p=!1;if(b(f)){var d=this.getImageSync(f,t,c);l=null==d?void 0:d.img}else i?(l=i,p=!0):l=f;var v,y,g=l&&n.createPattern(l,s);g&&(v=h?e.parsedTransformToMat4(e.parseTransform(h),new e.DisplayObject({})):function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}((y=new w(16),w!=Float32Array&&(y[1]=0,y[2]=0,y[3]=0,y[4]=0,y[6]=0,y[7]=0,y[8]=0,y[9]=0,y[11]=0,y[12]=0,y[13]=0,y[14]=0),y[0]=1,y[5]=1,y[10]=1,y[15]=1,y)),p&&function(t,e,r){var n=r[0],i=r[1],o=r[2];t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*i,t[5]=e[5]*i,t[6]=e[6]*i,t[7]=e[7]*i,t[8]=e[8]*o,t[9]=e[9]*o,t[10]=e[10]*o,t[11]=e[11]*o,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]}(v,v,[1/o,1/o,1]),g.setTransform({a:v[0],b:v[1],c:v[4],d:v[5],e:v[12]+a[0],f:v[13]+a[1]}));return u&&g&&(this.patternCache[u]=g),g}},{key:"getOrCreateGradient",value:function(t,r){var n=this.generateGradientKey(t),i=t.type,o=t.steps,a=t.min,c=t.width,u=t.height,l=t.cx,f=t.cy,s=t.size;if(this.gradientCache[n])return this.gradientCache[n];var h=null;if(i===e.GradientType.LinearGradient){var p=e.computeLinearGradient(a,c,u,t.angle);h=r.createLinearGradient(p.x1,p.y1,p.x2,p.y2)}else if(i===e.GradientType.RadialGradient){var d=e.computeRadialGradient(a,c,u,l,f,s),v=d.x,y=d.y;h=r.createRadialGradient(v,y,0,v,y,d.r)}return h&&(o.forEach((function(t){var r,n=t.offset;n.unit===e.UnitType.kPercentage&&(null===(r=h)||void 0===r||r.addColorStop(n.value/100,""+t.color))})),this.gradientCache[n]=h),this.gradientCache[n]}},{key:"generateGradientKey",value:function(t){var e=t.min,r=t.width,n=t.height,i=t.steps,o=t.angle,a=t.cx,c=t.cy,u=t.size;return"gradient-".concat(t.type,"-").concat((null==o?void 0:""+o)||0,"-").concat((null==a?void 0:""+a)||0,"-").concat((null==c?void 0:""+c)||0,"-").concat((null==u?void 0:""+u)||0,"-").concat(e[0],"-").concat(e[1],"-").concat(r,"-").concat(n,"-").concat(i.map((function(t){var e=t.color;return"".concat(t.offset).concat(e)})).join("-"))}},{key:"generatePatternKey",value:function(t){var e=t.image,r=t.repetition;return b(e)?"pattern-".concat(e,"-").concat(r):"rect"===e.nodeName?"pattern-".concat(e.entity,"-").concat(r):void 0}}]);var t,n}();function P(t){if(!t.complete)return[0,0];var e=t.naturalWidth||t.width,r=t.naturalHeight||t.height,n=256;return[256,512].forEach((function(t){1e3>Math.ceil(r/t)*Math.ceil(e/t)&&(n=t)})),[n,n]}j.isSupportTile=!!e.OffscreenCanvasCreator.createCanvas();var A=function(){function t(){r(this,t)}return a(t,[{key:"apply",value:function(r){var n=r.renderingService,i=r.imagePool,o=r.renderingContext.root.ownerDocument.defaultView,a=function(t,e,r){var n=t.parsedStyle,i=n.width,o=n.height;i&&!o?t.setAttribute("height",r/e*i):!i&&o&&t.setAttribute("width",e/r*o)},c=function(t){var r=t.target,o=r.attributes;if(r.nodeName===e.Shape.IMAGE){var c=o.keepAspectRatio;i.getImageSync(o.src,r,(function(t){var e=t.img;c&&a(r,e.width,e.height),r.renderable.dirty=!0,n.dirtify()}))}},u=function(t){var r=t.target,o=t.prevValue,c=t.newValue;r.nodeName===e.Shape.IMAGE&&"src"===t.attrName&&(o!==c&&i.releaseImage(o,r),b(c)&&i.getOrCreateImage(c,r).then((function(t){var e=t.img;r.attributes.keepAspectRatio&&a(r,e.width,e.height),r.renderable.dirty=!0,n.dirtify()})).catch((function(){})))};n.hooks.init.tap(t.tag,(function(){o.addEventListener(e.ElementEvent.MOUNTED,c),o.addEventListener(e.ElementEvent.ATTR_MODIFIED,u)})),n.hooks.destroy.tap(t.tag,(function(){o.removeEventListener(e.ElementEvent.MOUNTED,c),o.removeEventListener(e.ElementEvent.ATTR_MODIFIED,u)}))}}])}();A.tag="LoadImage";var L=function(t){function e(){var t,n,i,o;r(this,e);for(var a=arguments.length,f=Array(a),s=0;a>s;s++)f[s]=arguments[s];return n=this,i=e,o=[].concat(f),i=c(i),(t=l(n,u()?Reflect.construct(i,o||[],c(n).constructor):i.apply(n,o))).name="image-loader",t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&f(t,e)}(e,t),a(e,[{key:"init",value:function(t){this.context.imagePool=new j(this.context,t),this.addRenderingPlugin(new A)}},{key:"destroy",value:function(){this.removeAllRenderingPlugins()}}])}(e.AbstractRendererPlugin);t.ImagePool=j,t.Plugin=L}));
//# sourceMappingURL=index.umd.min.js.map
{
"name": "@antv/g-plugin-image-loader",
"version": "2.1.11",
"version": "2.1.12",
"description": "A G plugin for loading image",

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

"tslib": "^2.5.3",
"@antv/g-lite": "2.2.9"
"@antv/g-lite": "2.2.10"
},

@@ -43,0 +43,0 @@ "publishConfig": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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