@antv/g-webgpu 2.0.23 → 2.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +2 -2
- package/dist/index.js +2 -2
- package/dist/index.umd.min.js +7 -7
- package/dist/index.umd.min.js.map +1 -1
- package/package.json +6 -6
package/dist/index.esm.js
CHANGED
package/dist/index.js
CHANGED
package/dist/index.umd.min.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @antv/g-webgpu
|
|
3
3
|
* @description A renderer implemented by WebGPU
|
|
4
|
-
* @version 2.0.
|
|
5
|
-
* @date
|
|
4
|
+
* @version 2.0.24
|
|
5
|
+
* @date 11/1/2024, 5:16:22 AM
|
|
6
6
|
* @author AntVis
|
|
7
7
|
* @docs https://g.antv.antgroup.com/
|
|
8
8
|
*/
|
|
@@ -11,15 +11,15 @@
|
|
|
11
11
|
* @antv/g-math
|
|
12
12
|
* @description Geometry util
|
|
13
13
|
* @version 3.0.0
|
|
14
|
-
* @date
|
|
14
|
+
* @date 11/1/2024, 5:12:47 AM
|
|
15
15
|
* @author AntVis
|
|
16
16
|
* @docs https://g.antv.antgroup.com/
|
|
17
17
|
*/function $n(e,t,r,n){var i=e-r,a=t-n;return Math.sqrt(i*i+a*a)}function Jn(e,t,r,n,i){return{x:(1-i)*e+i*r,y:(1-i)*t+i*n}}function ei(e,t,r,n,i){var a=1-i;return a*a*a*e+3*t*i*a*a+3*r*i*i*a+n*i*i*i}function ti(e,t,r,n,i,a,o,s,u){if(0===u)return function(e,t){for(var r=0,n=e.length,i=0;n>i;i++)r+=$n(e[i],t[i],e[(i+1)%n],t[(i+1)%n]);return r/2}([e,r,i,o],[t,n,a,s]);var l=function(e,t,r,n,i,a,o,s,u){var l=ei(e,r,i,o,u),c=ei(t,n,a,s,u),f=Jn(e,t,r,n,u),d=Jn(r,n,i,a,u),h=Jn(i,a,o,s,u),_=Jn(f.x,f.y,d.x,d.y,u),p=Jn(d.x,d.y,h.x,h.y,u);return[[e,t,f.x,f.y,_.x,_.y,l,c],[l,c,p.x,p.y,h.x,h.y,o,s]]}(e,t,r,n,i,a,o,s,.5),c=[].concat(yn(l[0]),[u-1]),f=[].concat(yn(l[1]),[u-1]);return ti.apply(void 0,yn(c))+ti.apply(void 0,yn(f))}function ri(e,t,r,n){var i=1-n;return i*i*e+2*n*i*t+n*n*r}function ni(e,t,r,n,i,a,o){if(0===o)return($n(e,t,r,n)+$n(r,n,i,a)+$n(e,t,i,a))/2;var s=function(e,t,r,n,i,a,o){var s=ri(e,r,i,o),u=ri(t,n,a,o),l=Jn(e,t,r,n,o),c=Jn(r,n,i,a,o);return[[e,t,l.x,l.y,s,u],[s,u,c.x,c.y,i,a]]}(e,t,r,n,i,a,.5),u=s[0],l=s[1];return u.push(o-1),l.push(o-1),ni.apply(void 0,yn(u))+ni.apply(void 0,yn(l))}
|
|
18
18
|
/*!
|
|
19
19
|
* @antv/g-plugin-device-renderer
|
|
20
20
|
* @description A G plugin of renderer implementation with GPUDevice
|
|
21
|
-
* @version 2.1.
|
|
22
|
-
* @date
|
|
21
|
+
* @version 2.1.4
|
|
22
|
+
* @date 11/1/2024, 5:15:20 AM
|
|
23
23
|
* @author AntVis
|
|
24
24
|
* @docs https://g.antv.antgroup.com/
|
|
25
25
|
*/
|
|
@@ -27,8 +27,8 @@ var ii=u((function e(){l(this,e),this.drawcalls=[]}));ii.tag="c-renderable-3d";v
|
|
|
27
27
|
/*!
|
|
28
28
|
* @antv/g-plugin-image-loader
|
|
29
29
|
* @description A G plugin for loading image
|
|
30
|
-
* @version 2.0.
|
|
31
|
-
* @date
|
|
30
|
+
* @version 2.0.15
|
|
31
|
+
* @date 11/1/2024, 5:14:22 AM
|
|
32
32
|
* @author AntVis
|
|
33
33
|
* @docs https://g.antv.antgroup.com/
|
|
34
34
|
*/var Qo=qo("cacheStore"),$o=function(){return u((function e(){l(this,e),Object.defineProperty(this,Qo,{writable:!0,value:new Map})}),[{key:"has",value:function(e){return jo(this,Qo)[Qo].has(e)}},{key:"put",value:function(e,t,r){return!jo(this,Qo)[Qo].has(e)&&(jo(this,Qo)[Qo].set(e,{value:t,counter:new Set([r])}),!0)}},{key:"get",value:function(e,t){var r=jo(this,Qo)[Qo].get(e);return r?(r.counter.add(t),r.value):null}},{key:"update",value:function(e,t,r){var n=jo(this,Qo)[Qo].get(e);return!!n&&(n.value=o(o({},n.value),t),n.counter.add(r),!0)}},{key:"release",value:function(e,t){var r=jo(this,Qo)[Qo].get(e);return!!r&&(r.counter.delete(t),r.counter.size>0||jo(this,Qo)[Qo].delete(e),!0)}},{key:"releaseRef",value:function(e){var t=this;jo(this,Qo)[Qo].keys().forEach((function(r){t.release(r,e)}))}},{key:"getSize",value:function(){return jo(this,Qo)[Qo].size}},{key:"clear",value:function(){jo(this,Qo)[Qo].clear()}}])}(),Jo=[],es=[],ts=function(){function e(){l(this,e)}return u(e,null,[{key:"stop",value:function(){e.rafId&&((arguments.length>0&&void 0!==arguments[0]?arguments[0]:e.api).cancelAnimationFrame(e.rafId),e.rafId=null)}},{key:"executeTask",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:e.api;(Jo.length>0||es.length>0)&&(es.forEach((function(e){return e()})),es=Jo.splice(0,e.TASK_NUM_PER_FRAME),e.rafId=t.requestAnimationFrame((function(){e.executeTask(t)})))}},{key:"sliceImage",value:function(t,r,n){for(var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:e.api,o=t.naturalWidth||t.width,s=t.naturalHeight||t.height,u=r-i,l=n-i,c=Math.ceil(o/u),f=Math.ceil(s/l),d={tileSize:[r,n],gridSize:[f,c],tiles:Array(f).fill(null).map((function(){return Array(c).fill(null)}))},h=function(e){for(var i=function(i){Jo.push((function(){var c=i*u,f=e*l,h=[Math.min(r,o-c),Math.min(n,s-f)],_=h[0],p=h[1],E=a.createCanvas();E.width=r,E.height=n,E.getContext("2d").drawImage(t,c,f,_,p,0,0,_,p),d.tiles[e][i]={x:c,y:f,tileX:i,tileY:e,data:E}}))},f=0;c>f;f++)i(f)},_=0;f>_;_++)h(_);return e.stop(),e.executeTask(),d}}])}();ts.TASK_NUM_PER_FRAME=10;var rs=new $o,ns=function(){return u((function e(t,r){l(this,e),this.imageCache={},this.gradientCache={},this.patternCache={},this.context=t,this.runtime=r}),[{key:"getImageSync",value:function(e,t,r){var n=I(e)?e:e.src;if(rs.has(n)){var i=rs.get(n,t);if(i.img.complete)return null==r||r(i),i}return this.getOrCreateImage(e,t).then((function(e){null==r||r(e)})).catch((function(){})),null}},{key:"getOrCreateImage",value:function(e,r){var n=I(e)?e:e.src;if(!I(e)&&!rs.has(n)){var i={img:e,size:[e.naturalWidth||e.width,e.naturalHeight||e.height],tileSize:is(e)};rs.put(n,i,r)}if(rs.has(n)){var a=rs.get(n,r);return a.img.complete?Promise.resolve(a):new Promise((function(e,t){a.img.addEventListener("load",(function(){a.tileSize=is(a.img),e(a)})),a.img.addEventListener("error",(function(e){t(e)}))}))}var o=this.context.config.createImage;return new Promise((function(e,i){var a;if(o?a=o(n):t.isBrowser&&(a=new window.Image),a){var s={img:a,size:[0,0],tileSize:is(a)};rs.put(n,s,r),a.onload=function(){s.size=[a.naturalWidth||a.width,a.naturalHeight||a.height],s.tileSize=is(s.img),e(s)},a.onerror=function(e){i(e)},a.crossOrigin="Anonymous",a.src=n}}))}},{key:"createDownSampledImage",value:(r=P(S().mark((function e(t,r){var n,i,a,s,u,l,c,f,d,h,_,p,E,v;return S().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getOrCreateImage(t,r);case 2:if(void 0===(n=e.sent).downSamplingRate){e.next=5;break}return e.abrupt("return",n);case 5:if(u=void 0===(s=(a="boolean"==typeof(i=this.context.config.enableLargeImageOptimization)?{}:i).maxDownSampledImageSize)?2048:s,c=void 0===(l=a.downSamplingRateThreshold)?.5:l,f=this.runtime.globalThis.createImageBitmap,d=y(n.size,2),p=n.img,E=Math.min((u+u)/((h=d[0])+(_=d[1])),Math.max(.01,Math.min(c,.5))),v=o(o({},n),{},{downSamplingRate:E}),rs.update(n.img.src,v,r),!f){e.next=25;break}return e.prev=14,e.next=17,f(n.img,{resizeWidth:h*E,resizeHeight:_*E});case 17:p=e.sent,e.next=23;break;case 20:e.prev=20,e.t0=e.catch(14),E=1;case 23:e.next=26;break;case 25:E=1;case 26:return v=o(o({},this.getImageSync(t,r)),{},{downSampled:p,downSamplingRate:E}),rs.update(n.img.src,v,r),e.abrupt("return",v);case 29:case"end":return e.stop()}}),e,this,[[14,20]])}))),function(e,t){return r.apply(this,arguments)})},{key:"createImageTiles",value:(e=P(S().mark((function e(r,n,i){var a,s,u;return S().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getOrCreateImage(r,i);case 2:return a=e.sent,ts.api={requestAnimationFrame:(s=i.ownerDocument.defaultView).requestAnimationFrame,cancelAnimationFrame:s.cancelAnimationFrame,createCanvas:function(){return t.OffscreenCanvasCreator.createCanvas()}},u=o(o({},a),ts.sliceImage(a.img,a.tileSize[0],a.tileSize[0])),rs.update(a.img.src,u,i),e.abrupt("return",u);case 8:case"end":return e.stop()}}),e,this)}))),function(t,r,n){return e.apply(this,arguments)})},{key:"releaseImage",value:function(e,t){rs.release(I(e)?e:e.src,t)}},{key:"releaseImageRef",value:function(e){rs.releaseRef(e)}},{key:"getOrCreatePatternSync",value:function(e,r,n,i,a,o,s){var u=this.generatePatternKey(r);if(u&&this.patternCache[u])return this.patternCache[u];var l,c=r.image,f=r.repetition,d=r.transform,h=!1;if(I(c)){var _=this.getImageSync(c,e,s);l=null==_?void 0:_.img}else i?(l=i,h=!0):l=c;var p,E=l&&n.createPattern(l,f);E&&(p=d?t.parsedTransformToMat4(t.parseTransform(d),new t.DisplayObject({})):k(L()),h&&V(p,p,[1/a,1/a,1]),E.setTransform({a:p[0],b:p[1],c:p[4],d:p[5],e:p[12]+o[0],f:p[13]+o[1]}));return u&&E&&(this.patternCache[u]=E),E}},{key:"getOrCreateGradient",value:function(e,r){var n=this.generateGradientKey(e),i=e.type,a=e.steps,o=e.min,s=e.width,u=e.height,l=e.cx,c=e.cy,f=e.size;if(this.gradientCache[n])return this.gradientCache[n];var d=null;if(i===t.GradientType.LinearGradient){var h=t.computeLinearGradient(o,s,u,e.angle);d=r.createLinearGradient(h.x1,h.y1,h.x2,h.y2)}else if(i===t.GradientType.RadialGradient){var _=t.computeRadialGradient(o,s,u,l,c,f),p=_.x,E=_.y;d=r.createRadialGradient(p,E,0,p,E,_.r)}return d&&(a.forEach((function(e){var r,n=e.offset;n.unit===t.UnitType.kPercentage&&(null===(r=d)||void 0===r||r.addColorStop(n.value/100,""+e.color))})),this.gradientCache[n]=d),this.gradientCache[n]}},{key:"generateGradientKey",value:function(e){var t=e.min,r=e.width,n=e.height,i=e.steps,a=e.angle,o=e.cx,s=e.cy,u=e.size;return"gradient-".concat(e.type,"-").concat((null==a?void 0:""+a)||0,"-").concat((null==o?void 0:""+o)||0,"-").concat((null==s?void 0:""+s)||0,"-").concat((null==u?void 0:""+u)||0,"-").concat(t[0],"-").concat(t[1],"-").concat(r,"-").concat(n,"-").concat(i.map((function(e){var t=e.color;return"".concat(e.offset).concat(t)})).join("-"))}},{key:"generatePatternKey",value:function(e){var t=e.image,r=e.repetition;return I(t)?"pattern-".concat(t,"-").concat(r):"rect"===t.nodeName?"pattern-".concat(t.entity,"-").concat(r):void 0}}]);var e,r}();function is(e){if(!e.complete)return[0,0];var t=e.naturalWidth||e.width,r=e.naturalHeight||e.height,n=256;return[256,512].forEach((function(e){1e3>Math.ceil(r/e)*Math.ceil(t/e)&&(n=e)})),[n,n]}ns.isSupportTile=!!t.OffscreenCanvasCreator.createCanvas();var as=function(){function e(){l(this,e)}return u(e,[{key:"apply",value:function(r){var n=r.renderingService,i=r.imagePool,a=r.renderingContext.root.ownerDocument.defaultView,o=function(e,t,r){var n=e.parsedStyle,i=n.width,a=n.height;i&&!a?e.setAttribute("height",r/t*i):!i&&a&&e.setAttribute("width",t/r*a)},s=function(e){var r=e.target,a=r.attributes;if(r.nodeName===t.Shape.IMAGE){var s=a.src,u=a.keepAspectRatio;I(s)&&i.getImageSync(s,r,(function(e){var t=e.img;u&&o(r,t.width,t.height),r.renderable.dirty=!0,n.dirtify()}))}},u=function(e){var r=e.target,a=e.prevValue,s=e.newValue;r.nodeName===t.Shape.IMAGE&&"src"===e.attrName&&(a!==s&&i.releaseImage(a,r),I(s)&&i.getOrCreateImage(s,r).then((function(e){var t=e.img;r.attributes.keepAspectRatio&&o(r,t.width,t.height),r.renderable.dirty=!0,n.dirtify()})).catch((function(){})))};function l(e){var r=e.target;r.nodeName===t.Shape.IMAGE&&i.releaseImageRef(r)}n.hooks.init.tap(e.tag,(function(){a.addEventListener(t.ElementEvent.MOUNTED,s),a.addEventListener(t.ElementEvent.ATTR_MODIFIED,u),a.addEventListener(t.ElementEvent.DESTROY,l)})),n.hooks.destroy.tap(e.tag,(function(){a.removeEventListener(t.ElementEvent.MOUNTED,s),a.removeEventListener(t.ElementEvent.ATTR_MODIFIED,u),a.removeEventListener(t.ElementEvent.DESTROY,l)}))}}])}();as.tag="LoadImage";var os=function(e){function t(){var e;l(this,t);for(var r=arguments.length,n=Array(r),i=0;r>i;i++)n[i]=arguments[i];return(e=h(this,t,[].concat(n))).name="image-loader",e}return p(t,e),u(t,[{key:"init",value:function(e){this.context.imagePool=new ns(this.context,e),this.addRenderingPlugin(new as)}},{key:"destroy",value:function(){this.removeAllRenderingPlugins()}}])}(t.AbstractRendererPlugin),ss=function(){return u((function e(t){l(this,e),this.canvasConfig=t.config,this.deviceRendererPlugin=t.deviceRendererPlugin}),[{key:"init",value:function(){var e=this.canvasConfig,t=e.container,r=e.canvas;if(r)this.$canvas=r,t&&r.parentElement!==t&&t.appendChild(r),this.$container=r.parentElement,this.canvasConfig.container=this.$container;else if(t&&(this.$container=I(t)?document.getElementById(t):t,this.$container)){var n=document.createElement("canvas");this.$container.appendChild(n),this.$container.style.position||(this.$container.style.position="relative"),this.$canvas=n}this.resize(this.canvasConfig.width,this.canvasConfig.height)}},{key:"getDomElement",value:function(){return this.$canvas}},{key:"getContext",value:function(){return this.deviceRendererPlugin.getDevice().canvasContext}},{key:"getBoundingClientRect",value:function(){if(this.$canvas.getBoundingClientRect)return this.$canvas.getBoundingClientRect()}},{key:"destroy",value:function(){this.$container&&this.$canvas&&this.$canvas.parentNode&&this.$container.removeChild(this.$canvas)}},{key:"resize",value:function(e,r){var n=this.canvasConfig.devicePixelRatio||t.isBrowser&&window.devicePixelRatio||1;if(this.dpr=n=1>n?1:Math.ceil(n),this.$canvas){var i=this.getDPR();this.$canvas.width=i*e,this.$canvas.height=i*r,t.setDOMSize(this.$canvas,e,r)}}},{key:"getDPR",value:function(){return this.dpr}},{key:"applyCursorStyle",value:function(e){this.$container&&this.$container.style&&(this.$container.style.cursor=e)}},{key:"toDataURL",value:(e=P(S().mark((function e(t){return S().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return","");case 1:case"end":return e.stop()}}),e)}))),function(t){return e.apply(this,arguments)})}]);var e}(),us=function(e){function t(e,r){var n;return l(this,t),(n=h(this,t)).name="webgpu-context-register",n.rendererPlugin=e,n.config=r,n}return p(t,e),u(t,[{key:"init",value:function(){this.context.ContextService=ss,this.context.deviceRendererPlugin=this.rendererPlugin;var e=this.config;this.context.deviceContribution=new gn({shaderCompilerPath:null==e?void 0:e.shaderCompilerPath,onContextLost:null==e?void 0:e.onContextLost})}},{key:"destroy",value:function(){delete this.context.ContextService}}])}(t.AbstractRendererPlugin),ls=function(e){function r(e){var n;l(this,r),(n=h(this,r,[o({enableSizeAttenuation:!1},e)])).clipSpaceNearZ=t.ClipSpaceNearZ.ZERO;var i=new Go;return n.registerPlugin(new us(i,e)),n.registerPlugin(new os),n.registerPlugin(i),n.registerPlugin(new Wo),n.registerPlugin(new Yo),n}return p(r,e),u(r)}(t.AbstractRenderer);e.DeviceRenderer=Vo,e.DomInteraction=Ho,e.HTMLRenderer=Ko,e.Renderer=ls}));
|