iwmlib/dist/iwmlib.3rdparty.min.js

253 lines
1.3 MiB
JavaScript
Raw Normal View History

2022-10-04 15:26:17 +02:00
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.OptimalSelect=t():e.OptimalSelect=t()}(this,function(){return r=[function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.convertNodeList=function(e){for(var t=e.length,r=new Array(t),i=0;i<t;i++)r[i]=e[i];return r},t.escapeValue=function(e){return e&&e.replace(/['"`\\/:\?&!#$%^()[\]{|}*+;,.<=>@~]/g,"\\$&").replace(/\n/g,"A")}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getCommonAncestor=function(e){for(var t=(1<arguments.length&&void 0!==arguments[1]?arguments[1]:{}).root,i=void 0===t?document:t,n=[],r=(e.forEach(function(e,t){for(var r=[];e!==i;)e=e.parentNode,r.unshift(e);n[t]=r}),n.sort(function(e,t){return e.length-t.length}),n.shift()),o=null,a=0,s=r.length;a<s;a++)if("break"===function(){var t=r[a];if(n.some(function(e){return!e.some(function(e){return e===t})}))return"break";o=t}())break;return o},t.getCommonProperties=function(e){var l={classes:[],attributes:{},tag:null};return e.forEach(function(e){var r,i,n,t,o=l.classes,a=l.attributes,s=l.tag;void 0!==o&&((r=e.getAttribute("class"))?(r=r.trim().split(" "),o.length?(o=o.filter(function(t){return r.some(function(e){return e===t})})).length?l.classes=o:delete l.classes:l.classes=r):delete l.classes),void 0!==a&&(i=e.attributes,n=Object.keys(i).reduce(function(e,t){var t=i[t],r=t.name;return t&&"class"!==r&&(e[r]=t.value),e},{}),o=Object.keys(n),t=Object.keys(a),o.length?t.length?(a=t.reduce(function(e,t){var r=a[t];return r===n[t]&&(e[t]=r),e},{}),Object.keys(a).length?l.attributes=a:delete l.attributes):l.attributes=n:delete l.attributes),void 0!==s&&(o=e.tagName.toLowerCase(),s?o!==s&&delete l.tag:l.tag=o)}),l}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};Array.isArray(t)||(t=t.length?(0,h.convertNodeList)(t):[t]);if(!t.length||t.some(function(e){return 1!==e.nodeType}))throw new Error('Invalid input - to compare HTMLElements its necessary to provide a reference of the selected node(s)! (missing "elements")');(0,u.default)(t[0],r);var i=e.replace(/> /g,">").split(/\s+(?=(?:(?:[^"]*"){2})*[^"]*$)/);if(i.length<2)return c("",e,"",t);var n=[i.pop()];for(;1<i.length;){var o=i.pop(),a=i.join(" "),s=n.join(" "),l=a+" "+s;document.querySelectorAll(l).length!==t.length&&n.unshift(c(a,o,s,t))}n.unshift(i[0]),(i=n)[0]=c("",i[0],i.slice(1).join(" "),t),i[i.length-1]=c(i.slice(0,-1).join(" "),i[i.length-1],"",t);return i.join(" ").replace(/>/g,"> ").trim()};var i=r(3),u=(i=i)&&i.__esModule?i:{default:i},h=r(0);function c(r,i,n,o){if(r.length&&(r+=" "),n.length&&(n=" "+n),/\[*\]/.test(i)){var e=i.replace(/=.*$/,"]"),a=""+r+e+n;if(f(document.querySelectorAll(a),o))i=e;else for(var s=document.querySelectorAll(""+r+e),l=0,t=s.length;l<t;l++)if("break"===function(){var e,t=s[l];if(o.some(function(e){return t.contains(e)}))return e=t.tagName.toLowerCase(),a=""+r+e+n,f(document.querySelectorAll(a),o)&&(i=e),"break"}())break}if(/>/.test(i)&&(e=i.replace(/>/,""),a=""+r+e+n,f(document.querySelectorAll(a),o)&&(i=e)),/:nth-child/.test(i)&&(e=i.replace(/nth-child/g,"nth-of-type"),a=""+r+e+n,f(document.querySelectorAll(a),o)&&(i=e)),/\.\S+\.\S+/.test(i)){for(var u=i.trim().split(".").slice(1).map(function(e){return"."+e}).sort(function(e,t){return e.length-t.length});u.length;){var h=i.replace(u.shift(),"").trim();if(!(a=(""+r+h+n).trim()).length||">"===a.charAt(0)||">"===a.charAt(a.length-1))break;f(document.querySelectorAll(a),o)&&(i=h)}if((u=i&&i.match(/\./g))&&2<u.length)for(var c=document.querySelectorAll(""+r+i),l=0,t=c.length;l<t;l++)if("break"===function(){var e,t=c[l];if(o.some(function(e){return t.contains(e)}))return e=t.tagName.toLowerCase(),a=""+r+e+n,f(document.querySelectorAll(a),o)&&(i=e),"break"}())break}return i}function f(r,e){var i=r.length;return i===e.length&&e.every(function(e){for(var t=0;t<i;t++)if(r[t]===e)return!0;
2022-10-04 10:51:35 +02:00
attribute vec3 aVertexPosition;
attribute vec2 aTextureCoord;
attribute vec4 aColor;
attribute float aTextureId;
uniform mat3 projectionMatrix;
varying vec2 vTextureCoord;
varying vec4 vColor;
varying float vTextureId;
void main(void){
gl_Position.xyw = projectionMatrix * aVertexPosition;
gl_Position.z = 0.0;
vTextureCoord = aTextureCoord;
vTextureId = aTextureId;
vColor = aColor;
}
`,fragment:`
varying vec2 vTextureCoord;
varying vec4 vColor;
varying float vTextureId;
uniform sampler2D uSamplers[%count%];
void main(void){
vec4 color;
%forloop%
gl_FragColor = color * vColor;
2022-10-04 15:26:17 +02:00
}`,geometryClass:j,vertexSize:7},e);return class extends _.AbstractBatchRenderer{constructor(e){super(e),this.shaderGenerator=new _.BatchShaderGenerator(t,r),this.geometryClass=n,this.vertexSize=i}packInterleavedGeometry(e,t,r,i,n){var{uint32View:o,float32View:a}=t,s=i/this.vertexSize,l=e.uvs,u=e.indices,h=e.vertexData,c=e.vertexData2d,f=e._texture.baseTexture._batchLocation,t=Math.min(e.worldAlpha,1),p=t<1&&e._texture.baseTexture.alphaMode?g.premultiplyTint(e._tintRGB,t):e._tintRGB+(255*t<<24);if(c){let t=0;for(let e=0;e<c.length;e+=3,t+=2)a[i++]=c[e],a[i++]=c[e+1],a[i++]=c[e+2],a[i++]=l[t],a[i++]=l[t+1],o[i++]=p,a[i++]=f}else for(let e=0;e<h.length;e+=2)a[i++]=h[e],a[i++]=h[e+1],a[i++]=1,a[i++]=l[e],a[i++]=l[e+1],o[i++]=p,a[i++]=f;for(let e=0;e<u.length;e++)r[n++]=s+u[e]}}}}class G{constructor(e,t=!0){G.prototype.__init.call(this),this.legacy=e,t&&(this.enabled=!0),this.legacy.proj=this}__init(){this._enabled=!1}get enabled(){return this._enabled}set enabled(e){this._enabled=e}clear(){}}s.TRANSFORM_STEP=void 0;var X,r=s.TRANSFORM_STEP||(s.TRANSFORM_STEP={}),r=(r[r.NONE=0]="NONE",r[r.BEFORE_PROJ=4]="BEFORE_PROJ",r[r.PROJ=5]="PROJ",r[r.ALL=9]="ALL",s.AFFINE=void 0,s.AFFINE||(s.AFFINE={}));function H(e){var t=this.proj,r=this,i=e._worldID,n=r.localTransform,o=t.scaleAfterAffine&&2<=t.affine,a=(r._localID!==r._currentLocalID&&(o?(n.a=r._cx,n.b=r._sx,n.c=r._cy,n.d=r._sy,n.tx=r.position._x,n.ty=r.position._y):(n.a=r._cx*r.scale._x,n.b=r._sx*r.scale._x,n.c=r._cy*r.scale._y,n.d=r._sy*r.scale._y,n.tx=r.position._x-(r.pivot._x*n.a+r.pivot._y*n.c),n.ty=r.position._y-(r.pivot._x*n.b+r.pivot._y*n.d)),r._currentLocalID=r._localID,t._currentProjID=-1),t._projID);t._currentProjID!==a&&(t._currentProjID=a,t.updateLocalTransform(n),r._parentID=-1),r._parentID!==i&&((a=e.proj)&&!a._affine?t.world.setToMult(a.world,t.local):t.world.setToMultLegacy(e.worldTransform,t.local),n=r.worldTransform,t.world.copyTo(n,t._affine,t.affinePreserveOrientation),o&&(n.a*=r.scale._x,n.b*=r.scale._x,n.c*=r.scale._y,n.d*=r.scale._y,n.tx-=r.pivot._x*n.a+r.pivot._y*n.c,n.ty-=r.pivot._x*n.b+r.pivot._y*n.d),r._parentID=i,r._worldID++)}r[r.NONE=0]="NONE",r[r.FREE=1]="FREE",r[r.AXIS_X=2]="AXIS_X",r[r.AXIS_Y=3]="AXIS_Y",r[r.POINT=4]="POINT",r[r.AXIS_XR=5]="AXIS_XR";class i extends G{constructor(...e){super(...e),i.prototype.__init.call(this),i.prototype.__init2.call(this),i.prototype.__init3.call(this),i.prototype.__init4.call(this),i.prototype.__init5.call(this)}updateLocalTransform(e){}__init(){this._projID=0}__init2(){this._currentProjID=-1}__init3(){this._affine=s.AFFINE.NONE}__init4(){this.affinePreserveOrientation=!1}__init5(){this.scaleAfterAffine=!0}set affine(e){this._affine!==e&&(this._affine=e,this._currentProjID=-1,this.legacy._currentLocalID=-1)}get affine(){return this._affine}set enabled(e){e!==this._enabled&&(this._enabled=e,this.legacy.updateTransform=e?H:p.Transform.prototype.updateTransform,this.legacy._parentID=-1)}clear(){this._currentProjID=-1,this._projID=0}}class Y extends _.AbstractBatchRenderer{constructor(...e){super(...e),Y.prototype.__init.call(this),Y.prototype.__init2.call(this)}__init(){this.forceMaxTextures=0}getUniforms(e){return this.defUniforms}syncUniforms(e){if(e){var t=this._shader;for(const r in e)t.uniforms[r]=e[r]}}__init2(){this.defUniforms={}}buildDrawCalls(t,r,i){var{_bufferedElements:n,_attributeBuffer:o,_indexBuffer:a,vertexSize:s}=this,l=_.AbstractBatchRenderer._drawCallPool;let u=this._dcIndex,h=this._aIndex,c=this._iIndex,f=l[u];f.start=this._iIndex,f.texArray=t;for(let e=r;e<i;++e){var p=n[e],d=p._texture.baseTexture,d=g.premultiplyBlendMode[d.alphaMode?1:0][p.blendMode],m=this.getUniforms(p);n[e]=null,r<e&&(f.blend!==d||f.uniforms!==m)&&(f.size=c-f.start,r=e,(f=l[++u]).texArray=t,f.start=c),this.packInterleavedGeometry(p,o,a,h,c),h+=p.vertexData.length/2*s,c+=p.indices.length,f.blend=d,f.uniforms=m}r<i&&(f.size=c-f.start,++u),this._dcIndex=u,this._aIndex=h,this._iIndex=c}drawBatches(){var t=this._dcIndex,{gl:r,state:i,shader:n}=this.renderer,o=_.AbstractBatchRenderer._drawCallPool;let a=null,s=null;for(let e=0;e
2022-10-04 10:51:35 +02:00
attribute vec2 aTextureCoord;
uniform mat3 projectionMatrix;
uniform mat3 translationMatrix;
uniform mat3 uTransform;
varying vec3 vTextureCoord;
void main(void)
{
gl_Position.xyw = projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0);
vTextureCoord = uTransform * vec3(aTextureCoord, 1.0);
}
`,c=new n;class K extends _.ObjectRenderer{constructor(e){super(e),K.prototype.__init.call(this);e={globals:this.renderer.globalUniforms};this.shader=_.Shader.from(V,`
varying vec3 vTextureCoord;
uniform sampler2D uSampler;
uniform vec4 uColor;
uniform mat3 uMapCoord;
uniform vec4 uClampFrame;
uniform vec2 uClampOffset;
void main(void)
{
vec2 coord = mod(vTextureCoord.xy / vTextureCoord.z - uClampOffset, vec2(1.0, 1.0)) + uClampOffset;
coord = (uMapCoord * vec3(coord, 1.0)).xy;
coord = clamp(coord, uClampFrame.xy, uClampFrame.zw);
vec4 sample = texture2D(uSampler, coord);
gl_FragColor = sample * uColor;
}
`,e),this.simpleShader=_.Shader.from(V,`
varying vec3 vTextureCoord;
uniform sampler2D uSampler;
uniform vec4 uColor;
void main(void)
{
vec4 sample = texture2D(uSampler, vTextureCoord.xy / vTextureCoord.z);
gl_FragColor = sample * uColor;
}
2022-10-04 15:26:17 +02:00
`,e)}__init(){this.quad=new _.QuadUv}render(e){var t=this.renderer,r=this.quad;let i=r.vertices;i[0]=i[6]=e._width*-e.anchor.x,i[1]=i[3]=e._height*-e.anchor.y,i[2]=i[4]=e._width*(1-e.anchor.x),i[5]=i[7]=e._height*(1-e.anchor.y),e.uvRespectAnchor&&((i=r.uvs)[0]=i[6]=-e.anchor.x,i[1]=i[3]=-e.anchor.y,i[2]=i[4]=1-e.anchor.x,i[5]=i[7]=1-e.anchor.y),r.invalidate();var n=e._texture,o=n.baseTexture,a=e.tileProj.world,s=e.uvMatrix;let l=o.isPowerOfTwo&&n.frame.width===o.width&&n.frame.height===o.height;l&&(o._glTextures[t.CONTEXT_UID]?l=o.wrapMode!==h.WRAP_MODES.CLAMP:o.wrapMode===h.WRAP_MODES.CLAMP&&(o.wrapMode=h.WRAP_MODES.REPEAT));var u=l?this.simpleShader:this.shader;c.identity(),c.scale(n.width,n.height),c.prepend(a),c.scale(1/e._width,1/e._height),c.invert(),l?c.prepend(s.mapCoord):(u.uniforms.uMapCoord=s.mapCoord.toArray(!0),u.uniforms.uClampFrame=s.uClampFrame,u.uniforms.uClampOffset=s.uClampOffset),u.uniforms.uTransform=c.toArray(!0),u.uniforms.uColor=g.premultiplyTintToRgba(e.tint,e.worldAlpha,u.uniforms.uColor,o.premultiplyAlpha),u.uniforms.translationMatrix=e.worldTransform.toArray(!0),u.uniforms.uSampler=n,t.shader.bind(u,!1),t.geometry.bind(r,void 0),t.state.setBlendMode(g.correctBlendMode(e.blendMode,o.premultiplyAlpha)),t.geometry.draw(h.DRAW_MODES.TRIANGLES,6,0)}}const u=new p.Point,f=[new p.Point,new p.Point,new p.Point,new p.Point],a=new p.Rectangle,J=new n;class l extends i{constructor(e,t){super(e,t),l.prototype.__init.call(this),l.prototype.__init2.call(this),l.prototype.__init3.call(this),this.local=new n,this.world=new n}__init(){this.matrix=new n}__init2(){this.pivot=new p.ObservablePoint(this.onChange,this,0,0)}__init3(){this.reverseLocalOrder=!1}onChange(){var e=this.pivot,t=this.matrix.mat3;t[6]=-(e._x*t[0]+e._y*t[3]),t[7]=-(e._x*t[1]+e._y*t[4]),this._projID++}setAxisX(e,t=1){var r=e.x,e=e.y,i=Math.sqrt(r*r+e*e),n=this.matrix.mat3;n[0]=r/i,n[1]=e/i,n[2]=t/i,this.onChange()}setAxisY(e,t=1){var r=e.x,e=e.y,i=Math.sqrt(r*r+e*e),n=this.matrix.mat3;n[3]=r/i,n[4]=e/i,n[5]=t/i,this.onChange()}mapSprite(e,t){var r=e.texture;a.x=-e.anchor.x*r.orig.width,a.y=-e.anchor.y*r.orig.height,a.width=r.orig.width,a.height=r.orig.height,this.mapQuad(a,t)}mapQuad(t,r){f[0].set(t.x,t.y),f[1].set(t.x+t.width,t.y),f[2].set(t.x+t.width,t.y+t.height),f[3].set(t.x,t.y+t.height);let i=1,n=2,o=3;t=W(r[0],r[2],r[1],r[3],u);if(0!==t){i=1,n=3,o=2;var t=Math.sqrt((r[0].x-u.x)*(r[0].x-u.x)+(r[0].y-u.y)*(r[0].y-u.y)),a=Math.sqrt((r[i].x-u.x)*(r[i].x-u.x)+(r[i].y-u.y)*(r[i].y-u.y)),s=Math.sqrt((r[n].x-u.x)*(r[n].x-u.x)+(r[n].y-u.y)*(r[n].y-u.y)),l=Math.sqrt((r[o].x-u.x)*(r[o].x-u.x)+(r[o].y-u.y)*(r[o].y-u.y)),t=(t+l)/l,l=(a+s)/s,s=(a+s)/a;let e=this.matrix.mat3;e[0]=f[0].x*t,e[1]=f[0].y*t,e[2]=t,e[3]=f[i].x*l,e[4]=f[i].y*l,e[5]=l,e[6]=f[n].x*s,e[7]=f[n].y*s,e[8]=s,this.matrix.invert(),(e=J.mat3)[0]=r[0].x,e[1]=r[0].y,e[2]=1,e[3]=r[i].x,e[4]=r[i].y,e[5]=1,e[6]=r[n].x,e[7]=r[n].y,e[8]=1,this.matrix.setToMult(J,this.matrix),this._projID++}}updateLocalTransform(e){0!==this._projID?this.reverseLocalOrder?this.local.setToMultLegacy2(this.matrix,e):this.local.setToMultLegacy(e,this.matrix):this.local.copyFrom(e)}clear(){super.clear(),this.matrix.identity(),this.pivot.set(0,0)}}function Z(){return this.proj.affine?this.transform.worldTransform:this.proj.world}class Q extends e.Container{constructor(){super(),this.proj=new l(this.transform)}toLocal(e,t,r,i,n=s.TRANSFORM_STEP.ALL){return t&&(e=t.toGlobal(e,r,i)),i||this._recursivePostUpdateTransform(),n>=s.TRANSFORM_STEP.PROJ?(i||this.displayObjectUpdateTransform(),(this.proj.affine?this.transform.worldTransform:this.proj.world).applyInverse(e,r)):(this.parent?r=this.parent.worldTransform.applyInverse(e,r):(r.x=e.x,r.y=e.y),n===s.TRANSFORM_STEP.NONE?r:this.transform.localTransform.applyInverse(r,r))}get worldTransform(){return this.proj.affine?this.transform.worldTransform:this.proj.world}}const $=Q.prototype.toLocal;class d extends o.Mesh{static __initStatic(){this.defaultVertexShader=`precision highp float;
2022-10-04 10:51:35 +02:00
attribute vec2 aVertexPosition;
attribute vec2 aTextureCoord;
uniform mat3 projectionMatrix;
uniform mat3 translationMatrix;
uniform mat3 uTextureMatrix;
varying vec2 vTextureCoord;
void main(void)
{
gl_Position.xyw = projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0);
gl_Position.z = 0.0;
vTextureCoord = (uTextureMatrix * vec3(aTextureCoord, 1.0)).xy;
}
`}static __initStatic2(){this.defaultFragmentShader=`
varying vec2 vTextureCoord;
uniform vec4 uColor;
uniform sampler2D uSampler;
void main(void)
{
gl_FragColor = texture2D(uSampler, vTextureCoord) * uColor;
2022-10-04 15:26:17 +02:00
}`}constructor(e,t,r,i){super(e,t,r,i),d.prototype.__init.call(this),this.proj=new l(this.transform)}__init(){this.vertexData2d=null}calculateVertices(){if(this.proj._affine)this.vertexData2d=null,super.calculateVertices();else{var e=this.geometry,t=e.buffers[0].data;if(e.vertexDirtyId!==this.vertexDirty||this._transformID!==this.transform._worldID){this._transformID=this.transform._worldID,this.vertexData.length!==t.length&&(this.vertexData=new Float32Array(t.length)),this.vertexData2d&&this.vertexData2d.length===3*t.length/2||(this.vertexData2d=new Float32Array(3*t.length));var r=this.proj.world.mat3,i=this.vertexData2d,n=this.vertexData;for(let e=0;e<n.length/2;e++){var o=t[2*e],a=t[2*e+1],s=r[0]*o+r[3]*a+r[6],l=r[1]*o+r[4]*a+r[7],o=r[2]*o+r[5]*a+r[8];i[3*e]=s,i[3*e+1]=l,i[3*e+2]=o,n[2*e]=s/o,n[2*e+1]=l/o}this.vertexDirty=e.vertexDirtyId}}}_renderDefault(e){var t=this.shader;t.alpha=this.worldAlpha,t.update&&t.update(),e.batch.flush(),function(e){let t=void 0,r=e[0],i=1;for(;i<e.length;){var n=e[i],o=e[i+1];if(i+=2,("optionalAccess"===n||"optionalCall"===n)&&null==r)return;"access"===n||"optionalAccess"===n?r=o(t=r):"call"!==n&&"optionalCall"!==n||(r=o((...e)=>r.call(t,...e)),t=void 0)}return r}([t,"access",e=>e.program,"access",e=>e.uniformData,"optionalAccess",e=>e.translationMatrix])&&(t.uniforms.translationMatrix=this.worldTransform.toArray(!0)),e.shader.bind(t,!1),e.state.set(this.state),e.geometry.bind(this.geometry,t),e.geometry.draw(this.drawMode,this.size,this.start,this.geometry.instanceCount)}toLocal(e,t,r,i,n=s.TRANSFORM_STEP.ALL){return $.call(this,e,t,r,i,n)}get worldTransform(){return this.proj.affine?this.transform.worldTransform:this.proj.world}}d.__initStatic(),d.__initStatic2();class ee extends d{constructor(e,t,r,i,n){super(new o.MeshGeometry(t,r,i),new o.MeshMaterial(e,{program:_.Program.from(d.defaultVertexShader,d.defaultFragmentShader),pluginName:"batch2d"}),null,n),ee.prototype.__init2.call(this),this.geometry.getBuffer("aVertexPosition").static=!1}__init2(){this.autoUpdate=!0}get vertices(){return this.geometry.getBuffer("aVertexPosition").data}set vertices(e){this.geometry.getBuffer("aVertexPosition").data=e}_render(e){this.autoUpdate&&this.geometry.getBuffer("aVertexPosition").update(),super._render(e)}}class m extends t.Sprite{constructor(e){super(e),m.prototype.__init.call(this),this.proj=new l(this.transform),this.pluginName="batch2d"}__init(){this.vertexData2d=null}_calculateBounds(){this.calculateTrimmedVertices(),this._bounds.addQuad(this.vertexTrimmedData)}calculateVertices(){var n=this._texture;if(this.proj._affine)this.vertexData2d=null,super.calculateVertices();else{this.vertexData2d||(this.vertexData2d=new Float32Array(12));var o=this.transform._worldID,a=n._updateID;if(this._transformID!==o||this._textureID!==a){this._textureID!==a&&(this.uvs=n._uvs.uvsFloat32),this._transformID=o,this._textureID=a;var o=this.proj.world.mat3,a=this.vertexData2d,s=this.vertexData,l=n.trim,n=n.orig,u=this._anchor;let e,t,r,i;r=l?(t=l.x-u._x*n.width,e=t+l.width,(i=l.y-u._y*n.height)+l.height):(t=-u._x*n.width,e=t+n.width,(i=-u._y*n.height)+n.height),a[0]=o[0]*t+o[3]*i+o[6],a[1]=o[1]*t+o[4]*i+o[7],a[2]=o[2]*t+o[5]*i+o[8],a[3]=o[0]*e+o[3]*i+o[6],a[4]=o[1]*e+o[4]*i+o[7],a[5]=o[2]*e+o[5]*i+o[8],a[6]=o[0]*e+o[3]*r+o[6],a[7]=o[1]*e+o[4]*r+o[7],a[8]=o[2]*e+o[5]*r+o[8],a[9]=o[0]*t+o[3]*r+o[6],a[10]=o[1]*t+o[4]*r+o[7],a[11]=o[2]*t+o[5]*r+o[8],s[0]=a[0]/a[2],s[1]=a[1]/a[2],s[2]=a[3]/a[5],s[3]=a[4]/a[5],s[4]=a[6]/a[8],s[5]=a[7]/a[8],s[6]=a[9]/a[11],s[7]=a[10]/a[11]}}}calculateTrimmedVertices(){if(this.proj._affine)super.calculateTrimmedVertices();else{var e=this.transform._worldID,t=this._texture._updateID;if(this.vertexTrimmedData){if(this._transformTrimmedID===e&&this._textureTrimmedID===t)return}else this.vertexTrimmedData=new Float32Array(8);this._transformTrimmedID=e,this._textureTrimmedID=t;var e=this._texture,t=this.vertexTrimmedData,e=e.orig,r=this.tileProj?this._width:e.width,e=this.tileProj?this._height:e.height,i=this._anchor,n=this.proj.world.mat3,o=-i._x*r,r=o+r,i=-i._y*e,e=i+e,a=1/(n[2]*o+n[5]*
2022-10-04 10:51:35 +02:00
attribute vec2 aVertexPosition;
attribute vec2 aTextureCoord;
uniform mat3 projectionMatrix;
uniform mat3 otherMatrix;
varying vec3 vMaskCoord;
varying vec2 vTextureCoord;
void main(void)
{
gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);
vTextureCoord = aTextureCoord;
vMaskCoord = otherMatrix * vec3( aTextureCoord, 1.0);
}
`,`
varying vec3 vMaskCoord;
varying vec2 vTextureCoord;
uniform sampler2D uSampler;
uniform sampler2D mask;
uniform float alpha;
uniform vec4 maskClamp;
void main(void)
{
vec2 uv = vMaskCoord.xy / vMaskCoord.z;
float clip = step(3.5,
step(maskClamp.x, uv.x) +
step(maskClamp.y, uv.y) +
step(uv.x, maskClamp.z) +
step(uv.y, maskClamp.w));
vec4 original = texture2D(uSampler, vTextureCoord);
vec4 masky = texture2D(mask, uv);
original *= (masky.r * masky.a * alpha * clip);
gl_FragColor = original;
}
2022-10-04 15:26:17 +02:00
`),oe.prototype.__init.call(this),e.renderable=!1,this.maskSprite=e}__init(){this.maskMatrix=new n}apply(e,t,r,i){var n=this.maskSprite,o=this.maskSprite.texture;o.valid&&(o.uvMatrix||(o.uvMatrix=new _.TextureMatrix(o,0)),o.uvMatrix.update(),this.uniforms.npmAlpha=o.baseTexture.alphaMode?0:1,this.uniforms.mask=n.texture,this.uniforms.otherMatrix=oe.calculateSpriteMatrix(t,this.maskMatrix,n).prepend(o.uvMatrix.mapCoord),this.uniforms.alpha=n.worldAlpha,this.uniforms.maskClamp=o.uvMatrix.uClampFrame,e.applyFilter(this,t,r,i))}static calculateSpriteMatrix(e,t,r){var i=r.proj,n=e.filterFrame,i=i&&!i._affine?i.world.copyTo2dOr3d(ne):ne.copyFrom(r.transform.worldTransform),o=r.texture.orig;return t.set(e.width,0,0,e.height,n.x,n.y),i.invert(),t.setToMult(i,t),t.scaleAndTranslate(1/o.width,1/o.height,r.anchor.x,r.anchor.y),t}}_.MaskSystem.prototype.pushSpriteMask=function(e){var t=e["maskObject"],e=e._target;let r=this.alphaMaskPool[this.alphaMaskIndex];(r=r||(this.alphaMaskPool[this.alphaMaskIndex]=[new oe(t)]))[0].resolution=this.renderer.resolution,r[0].maskSprite=t;var i=e.filterArea;e.filterArea=t.getBounds(!0),this.renderer.filter.push(e,r),e.filterArea=i,this.alphaMaskIndex++},_.Renderer.registerPlugin("tilingSprite2d",K);class ae extends p.Point{constructor(e,t,r){super(e,t),this.z=r}set(e,t,r){return this.x=e||0,this.y=void 0===t?this.x:t||0,this.z=void 0===t?this.x:r||0,this}copyFrom(e){return this.set(e.x,e.y,e.z||0),this}copyTo(e){return e.set(this.x,this.y,this.z),e}}class y extends p.ObservablePoint{constructor(...e){super(...e),y.prototype.__init.call(this)}__init(){this._z=0}get z(){return this._z}set z(e){this._z!==e&&(this._z=e,this.cb.call(this.scope))}set(e,t,r){var e=e||0,i=void 0===t?e:t||0,t=void 0===t?e:r||0;return this._x===e&&this._y===i&&this._z===t||(this._x=e,this._y=i,this._z=t,this.cb.call(this.scope)),this}copyFrom(e){return this.set(e.x,e.y,e.z||0),this}copyTo(e){return e.set(this._x,this._y,this._z),e}}class b{constructor(e,t,r){b.prototype.__init.call(this),b.prototype.__init2.call(this),b.prototype.__init3.call(this),this._x=e||0,this._y=t||0,this._z=r||0,this.quaternion=new Float64Array(4),this.quaternion[3]=1,this.update()}__init(){this._quatUpdateId=-1}__init2(){this._quatDirtyId=0}__init3(){this._sign=1}get x(){return this._x}set x(e){this._x!==e&&(this._x=e,this._quatDirtyId++)}get y(){return this._y}set y(e){this._y!==e&&(this._y=e,this._quatDirtyId++)}get z(){return this._z}set z(e){this._z!==e&&(this._z=e,this._quatDirtyId++)}get pitch(){return this._x}set pitch(e){this._x!==e&&(this._x=e,this._quatDirtyId++)}get yaw(){return this._y}set yaw(e){this._y!==e&&(this._y=e,this._quatDirtyId++)}get roll(){return this._z}set roll(e){this._z!==e&&(this._z=e,this._quatDirtyId++)}set(e,t,r){e=e||0,t=t||0,r=r||0;this._x===e&&this._y===t&&this._z===r||(this._x=e,this._y=t,this._z=r,this._quatDirtyId++)}copyFrom(e){var t=e.x,r=e.y,e=e.z;return this._x===t&&this._y===r&&this._z===e||(this._x=t,this._y=r,this._z=e,this._quatDirtyId++),this}copyTo(e){return e.set(this._x,this._y,this._z),e}equals(e){return this._x===e.x&&this._y===e.y&&this._z===e.z}clone(){return new b(this._x,this._y,this._z)}update(){if(this._quatUpdateId===this._quatDirtyId)return!1;this._quatUpdateId=this._quatDirtyId;var e=Math.cos(this._x/2),t=Math.cos(this._y/2),r=Math.cos(this._z/2),i=this._sign,n=i*Math.sin(this._x/2),o=i*Math.sin(this._y/2),i=i*Math.sin(this._z/2),a=this.quaternion;return a[0]=n*t*r+e*o*i,a[1]=e*o*r-n*t*i,a[2]=e*t*i+n*o*r,a[3]=e*t*r-n*o*i,!0}}class x{constructor(e,t,r,i,n){this.cb=e,this.scope=t,x.prototype.__init.call(this),x.prototype.__init2.call(this),x.prototype.__init3.call(this),this._x=r||0,this._y=i||0,this._z=n||0,this.quaternion=new Float64Array(4),this.quaternion[3]=1,this.update()}__init(){this._quatUpdateId=-1}__init2(){this._quatDirtyId=0}__init3(){this._sign=1}get x(){return this._x}set x(e){this._x!==e&&(this._x=e,this._quatDirtyId++,this.cb.call(this.scope))}get y(){return this._y}set y(e){this._y!==e&&(this._y=e,this._quatDirtyId++,this.cb.call(this.scope))}get z(){return this._z}set z(
2022-10-04 10:51:35 +02:00
attribute vec2 aVertexPosition;
attribute vec3 aTrans1;
attribute vec3 aTrans2;
attribute vec2 aSamplerSize;
attribute vec4 aFrame;
attribute vec4 aColor;
attribute float aTextureId;
uniform mat3 projectionMatrix;
uniform mat3 translationMatrix;
varying vec2 vertexPosition;
varying vec3 vTrans1;
varying vec3 vTrans2;
varying vec2 vSamplerSize;
varying vec4 vFrame;
varying vec4 vColor;
varying float vTextureId;
void main(void){
gl_Position.xyw = projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0);
gl_Position.z = 0.0;
vertexPosition = aVertexPosition;
vTrans1 = aTrans1;
vTrans2 = aTrans2;
vTextureId = aTextureId;
vColor = aColor;
vSamplerSize = aSamplerSize;
vFrame = aFrame;
}
`,fragment:`precision highp float;
varying vec2 vertexPosition;
varying vec3 vTrans1;
varying vec3 vTrans2;
varying vec2 vSamplerSize;
varying vec4 vFrame;
varying vec4 vColor;
varying float vTextureId;
uniform sampler2D uSamplers[%count%];
uniform vec4 distortion;
void main(void){
vec2 surface;
vec2 surface2;
float vx = vertexPosition.x;
float vy = vertexPosition.y;
float dx = distortion.x;
float dy = distortion.y;
float revx = distortion.z;
float revy = distortion.w;
if (distortion.x == 0.0) {
surface.x = vx;
surface.y = vy / (1.0 + dy * vx);
surface2 = surface;
} else
if (distortion.y == 0.0) {
surface.y = vy;
surface.x = vx / (1.0 + dx * vy);
surface2 = surface;
} else {
float c = vy * dx - vx * dy;
float b = (c + 1.0) * 0.5;
float b2 = (-c + 1.0) * 0.5;
float d = b * b + vx * dy;
if (d < -0.00001) {
discard;
}
d = sqrt(max(d, 0.0));
surface.x = (- b + d) * revy;
surface2.x = (- b - d) * revy;
surface.y = (- b2 + d) * revx;
surface2.y = (- b2 - d) * revx;
}
vec2 uv;
uv.x = vTrans1.x * surface.x + vTrans1.y * surface.y + vTrans1.z;
uv.y = vTrans2.x * surface.x + vTrans2.y * surface.y + vTrans2.z;
vec2 pixels = uv * vSamplerSize;
if (pixels.x < vFrame.x || pixels.x > vFrame.z ||
pixels.y < vFrame.y || pixels.y > vFrame.w) {
uv.x = vTrans1.x * surface2.x + vTrans1.y * surface2.y + vTrans1.z;
uv.y = vTrans2.x * surface2.x + vTrans2.y * surface2.y + vTrans2.z;
pixels = uv * vSamplerSize;
if (pixels.x < vFrame.x || pixels.x > vFrame.z ||
pixels.y < vFrame.y || pixels.y > vFrame.w) {
discard;
}
}
vec4 edge;
edge.xy = clamp(pixels - vFrame.xy + 0.5, vec2(0.0, 0.0), vec2(1.0, 1.0));
edge.zw = clamp(vFrame.zw - pixels + 0.5, vec2(0.0, 0.0), vec2(1.0, 1.0));
float alpha = 1.0; //edge.x * edge.y * edge.z * edge.w;
vec4 rColor = vColor * alpha;
float textureId = floor(vTextureId+0.5);
vec2 vTextureCoord = uv;
vec4 color;
%forloop%
gl_FragColor = color * rColor;
2022-10-04 15:26:17 +02:00
}`,geometryClass:_e,vertexSize:16},e);return X=class extends Y{constructor(e){super(e),X.prototype.__init.call(this),X.prototype.__init2.call(this),X.prototype.__init3.call(this),this.shaderGenerator=new _.BatchShaderGenerator(t,r),this.geometryClass=n,this.vertexSize=i}__init(){this.defUniforms={translationMatrix:new p.Matrix,distortion:new Float32Array([0,0,1/0,1/0])}}__init2(){this.size=1e3}__init3(){this.forceMaxTextures=1}getUniforms(e){e=e.proj;return null!==e.surface?e.uniforms:null!==e._activeProjection?e._activeProjection.uniforms:this.defUniforms}packInterleavedGeometry(e,t,r,i,n){var{uint32View:o,float32View:a}=t,s=i/this.vertexSize,l=e.indices,u=e.vertexData,h=e._texture._frame,c=e.aTrans,{_batchLocation:f,realWidth:p,realHeight:d,resolution:m}=e._texture.baseTexture,t=Math.min(e.worldAlpha,1),_=t<1&&e._texture.baseTexture.alphaMode?g.premultiplyTint(e._tintRGB,t):e._tintRGB+(255*t<<24);for(let e=0;e<u.length;e+=2)a[i]=u[e],a[i+1]=u[e+1],a[i+2]=c.a,a[i+3]=c.c,a[i+4]=c.tx,a[i+5]=c.b,a[i+6]=c.d,a[i+7]=c.ty,a[i+8]=p,a[i+9]=d,a[i+10]=h.x*m,a[i+11]=h.y*m,a[i+12]=(h.x+h.width)*m,a[i+13]=(h.y+h.height)*m,o[i+14]=_,a[i+15]=f,i+=16;for(let e=0;e<l.length;e++)r[n++]=s+l[e]}}}}const P=[new p.Point,new p.Point,new p.Point,new p.Point],R=[0,0,0,0];class C{constructor(){C.prototype.__init.call(this),C.prototype.__init2.call(this),C.prototype.__init3.call(this),C.prototype.__init4.call(this)}__init(){this.surfaceID="default"}__init2(){this._updateID=0}__init3(){this.vertexSrc=""}__init4(){this.fragmentSrc=""}fillUniforms(e){}clear(){}boundsQuad(e,t,r){let i=t[0],n=t[1],o=t[0],a=t[1];for(let e=2;e<8;e+=2)i>t[e]&&(i=t[e]),o<t[e]&&(o=t[e]),n>t[e+1]&&(n=t[e+1]),a<t[e+1]&&(a=t[e+1]);if(P[0].set(i,n),this.apply(P[0],P[0]),P[1].set(o,n),this.apply(P[1],P[1]),P[2].set(o,a),this.apply(P[2],P[2]),P[3].set(i,a),this.apply(P[3],P[3]),r)r.apply(P[0],P[0]),r.apply(P[1],P[1]),r.apply(P[2],P[2]),r.apply(P[3],P[3]),t[0]=P[0].x,t[1]=P[0].y,t[2]=P[1].x,t[3]=P[1].y,t[4]=P[2].x,t[5]=P[2].y,t[6]=P[3].x,t[7]=P[3].y;else{for(let e=1;e<=3;e++){var s;(P[e].y<P[0].y||P[e].y===P[0].y&&P[e].x<P[0].x)&&(s=P[0],P[0]=P[e],P[e]=s)}for(let e=1;e<=3;e++)R[e]=Math.atan2(P[e].y-P[0].y,P[e].x-P[0].x);for(let t=1;t<=3;t++)for(let e=t+1;e<=3;e++){var l;R[t]>R[e]&&(l=P[t],P[t]=P[e],P[e]=l,l=R[t],R[t]=R[e],R[e]=l)}t[0]=P[0].x,t[1]=P[0].y,t[2]=P[1].x,t[3]=P[1].y,t[4]=P[2].x,t[5]=P[2].y,t[6]=P[3].x,t[7]=P[3].y,(P[3].x-P[2].x)*(P[1].y-P[2].y)-(P[1].x-P[2].x)*(P[3].y-P[2].y)<0&&(t[4]=P[3].x,t[5]=P[3].y)}}}const ve=new p.Matrix,M=new p.Rectangle,I=new p.Point;class ye extends C{constructor(...e){super(...e),ye.prototype.__init.call(this)}__init(){this.distortion=new p.Point}clear(){this.distortion.set(0,0)}apply(e,t){t=t||new p.Point;var r=this.distortion,i=e.x*e.y;return t.x=e.x+r.x*i,t.y=e.y+r.y*i,t}applyInverse(e,t){t=t||new p.Point;var r=e.x,e=e.y,i=this.distortion.x,n=this.distortion.y;if(0===i)t.x=r,t.y=e/(1+n*r);else if(0===n)t.y=e,t.x=r/(1+i*e);else{var e=.5*(e*i-r*n+1)/n,o=e*e+r/n;if(o<=1e-5)return t.set(NaN,NaN),t;t.x=0<n?-e+Math.sqrt(o):-e-Math.sqrt(o),t.y=(r/t.x-1)/i}return t}mapSprite(e,t,r){var i=e.texture;return M.x=-e.anchor.x*i.orig.width,M.y=-e.anchor.y*i.orig.height,M.width=i.orig.width,M.height=i.orig.height,this.mapQuad(M,t,r||e.transform)}mapQuad(e,t,r){var i=-e.x/e.width,n=-e.y/e.height,o=(1-e.x)/e.width,e=(1-e.y)/e.height,a=t[0].x*(1-i)+t[1].x*i,s=t[0].y*(1-i)+t[1].y*i,l=t[0].x*(1-o)+t[1].x*o,u=t[0].y*(1-o)+t[1].y*o,h=t[3].x*(1-i)+t[2].x*i,i=t[3].y*(1-i)+t[2].y*i,c=t[3].x*(1-o)+t[2].x*o,t=t[3].y*(1-o)+t[2].y*o,o=a*(1-n)+h*n,f=s*(1-n)+i*n,p=l*(1-n)+c*n,n=u*(1-n)+t*n,a=a*(1-e)+h*e,h=s*(1-e)+i*e,s=l*(1-e)+c*e,i=u*(1-e)+t*e,l=ve;return l.tx=o,l.ty=f,l.a=p-o,l.b=n-f,l.c=a-o,l.d=h-f,I.set(s,i),l.applyInverse(I,I),this.distortion.set(I.x-1,I.y-1),r.setFromMatrix(l),this}fillUniforms(e){e.distortion=e.distortion||new Float32Array([0,0,0,0]);var t=Math.abs(this.distortion.x),r=Math.abs(this.distortion.y);e.distortion[0]=1e4*t<=r?0:this.distortion.x,e.distortion[1]=1e4*r<=t?0:this.distortion.y,e.distortion[2]=1/e.distortion[0],e.distortion[3]=1/e.distorti