leafer-game 0.0.1 → 1.0.8
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/README.md +1 -1
- package/dist/web.cjs +678 -0
- package/dist/web.esm.js +654 -0
- package/dist/web.esm.min.js +1 -0
- package/dist/web.js +14413 -0
- package/dist/web.min.cjs +1 -0
- package/dist/web.min.js +1 -0
- package/dist/web.module.js +14231 -0
- package/dist/web.module.min.js +1 -0
- package/package.json +37 -14
- package/src/index.ts +1 -2
- package/types/index.d.ts +1 -0
package/dist/web.min.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var t=require("leafer-ui"),e=require("@leafer-in/robot"),n=require("@leafer-ui/draw"),o=require("@leafer-ui/core"),i=require("@leafer-in/animate");function a(t,e){return n.decorateLeafAttr(t,(t=>n.attr({set(o){this.__setAttr(t,o),this.waitLeafer((()=>e?n.State.setStyleName(this,e,o):n.State.set(this,o)))}})))}function r(t){return n.decorateLeafAttr(t,(t=>n.attr({set(e){this.__setAttr(t,e),this.__layout.stateStyleChanged=!0}})))}function s(t,e){if(e&&!0!==e)return e;if(!t.button){let{parent:e}=t;for(let t=0;t<2;t++)if(e){if(e.button)return e;e=e.parent}}return null}function l(t,e){"object"!=typeof e&&(e=void 0),f(t,e,"in")}function c(t,e){const{normalStyle:n}=t;"object"!=typeof e&&(e=void 0),n&&(e||(e=n),f(t,e,"out"))}const u={};function f(t,e,n){const{normalStyle:i}=t;e||(e=u),e.scale&&(o.MathHelper.assignScale(e,e.scale),delete e.scale),e!==u&&o.State.canAnimate||(n=null);let a=!!n&&function(t,e,n){let i="in"===t?"transition":"transitionOut";"out"===t&&o.isNull(n[i])&&o.isNull(e[i])&&(i="transition");return o.isNull(e[i])?n[i]:e[i]}(n,e,t);const r=a?function(t,e){const n=p(e,t),o=t.animate();o&&p(n,t,o.fromStyle);return n}(t,e):void 0;t.killAnimate("transition"),i&&t.set(i,!0);const s=h(t);if(s){const{animation:o}=s;if(o){const i=t.animate(o,void 0,"animation",!0);Object.assign(s,i.endingStyle),"in"!==n||e.animation!==o?i.kill():a=!1,delete s.animation}t.normalStyle=d(s,t),t.set(s,!0)}else t.normalStyle=void 0;if(a){const e=d(r,t);t.set(r,!0),t.animate([r,e],a,"transition",!0)}t.__layout.stateStyleChanged=!1}function h(t){let e;const n={},{state:i}=t,a=s(t),r=i&&t.states[i];r&&o.State.isState(i,t,a)&&(e=y(n,r));const l=n.selectedStyle||t.selectedStyle;if(l&&o.State.isSelected(t,a)&&(e=y(n,l)),o.State.isDisabled(t,a)){const o=n.disabledStyle||t.disabledStyle;o&&(e=y(n,o))}else{const i=n.focusStyle||t.focusStyle;i&&o.State.isFocus(t,a)&&(e=y(n,i));const r=n.hoverStyle||t.hoverStyle;r&&o.State.isHover(t,a)&&(e=y(n,r));const s=n.pressStyle||t.pressStyle;s&&o.State.isPress(t,a)&&(e=y(n,s))}return e?n:void 0}function d(t,e,n,i){const a=n?t:{},r=n||t;for(let t in r)i&&o.State.animateExcludes[t]||(a[t]=e[t]);return a}function p(t,e,n){return d(t,e,n,!0)}function y(t,e){return Object.assign(t,e),!0}function S(t,e){const n=t[e];n&&l(t,n),t.button&&g(t.children,e)}function m(t,e,n){n||(n=t.states[e]),l(t,n),t.button&&g(t.children,null,e)}function g(t,e,n){if(!t)return;let i,a;for(let r=0,s=t.length;r<s;r++){if(i=t[r],e){switch(a=!0,e){case"hoverStyle":o.State.isHover(i)&&(a=!1);break;case"pressStyle":o.State.isPress(i)&&(a=!1);break;case"focusStyle":o.State.isFocus(i)&&(a=!1)}a&&S(i,e)}else n&&m(i,n);i.isBranch&&g(i.children,e,n)}}function b(t,e){const n=t[e];n&&c(t,n),t.button&&_(t.children,e)}function P(t,e,n){c(t,n),t.button&&_(t.children,null,e)}function _(t,e,n){if(!t)return;let o;for(let i=0,a=t.length;i<a;i++)o=t[i],e?b(o,e):n&&P(o,n),o.isBranch&&_(o.children,e,n)}function v(t,e,n){let o;const i=e.leafer?e.leafer.interaction:null;if(i&&(o=i[t](e),!o&&n)){const a=s(e,n);a&&(o=i[t](a))}return o}function x(t,e,n){let o=e[t];if(!o&&n){const i=s(e,n);i&&(o=i[t])}return o}o.State.animateExcludes={animation:1,animationOut:1,transition:1,transitionOut:1,states:1,state:1,normalStyle:1,hoverStyle:1,pressStyle:1,focusStyle:1,selectedStyle:1,disabledStyle:1},o.State.isState=function(t,e,n){return function(t,e,n){let o=e.states[t];if(!o&&n){const i=s(e,n);i&&(o=i.states[t])}return!!o}(t,e,n)},o.State.isSelected=function(t,e){return x("selected",t,e)},o.State.isDisabled=function(t,e){return x("disabled",t,e)},o.State.isFocus=function(t,e){return v("isFocus",t,e)},o.State.isHover=function(t,e){return v("isHover",t,e)},o.State.isPress=function(t,e){return v("isPress",t,e)},o.State.isDrag=function(t,e){return v("isDrag",t,e)},o.State.setStyleName=function(t,e,n){n?m(t,e,t[e]):P(t,e,t[e])},o.State.set=function(t,e){const n=t.states[e];n?m(t,e,n):P(t,e,n)},o.State.getStyle=h,o.State.updateStyle=f,o.State.updateEventStyle=function(t,e){switch(e){case o.PointerEvent.ENTER:S(t,"hoverStyle");break;case o.PointerEvent.LEAVE:b(t,"hoverStyle");break;case o.PointerEvent.DOWN:S(t,"pressStyle");break;case o.PointerEvent.UP:b(t,"pressStyle")}};const M=o.UI.prototype;a(!1,"selectedStyle")(M,"selected"),a(!1,"disabledStyle")(M,"disabled"),r({})(M,"states"),a("")(M,"state"),o.dataType()(M,"normalStyle"),r()(M,"hoverStyle"),r()(M,"pressStyle"),r()(M,"focusStyle"),r()(M,"selectedStyle"),r()(M,"disabledStyle"),o.dataType(!1)(M,"button"),M.focus=function(t=!0){this.waitLeafer((()=>{let{focusData:e}=this.app.interaction;t?(e&&e.focus(!1),e=this):e=null,this.app.interaction.focusData=e,t?S(this,"focusStyle"):b(this,"focusStyle")}))},M.updateState=function(){o.State.updateStyle(this,void 0,"in")};const D=[.1488743389,.4333953941,.6794095682,.8650633666,.9739065285],H=[.2955242247,.2692667193,.2190863625,.1494513491,.0666713443],{sqrt:O}=Math,k={getDistance(t,e,n,o,i,a,r,s){let l,c,u,f,h,d,p=0;for(let y=0;y<D.length;y++)l=.5*(1+D[y]),c=.5*(1-D[y]),u=j(l,t,n,i,r),f=j(l,e,o,a,s),h=j(c,t,n,i,r),d=j(c,e,o,a,s),p+=H[y]*(O(u*u+f*f)+O(h*h+d*d));return.5*p},getDerivative(t,e,n,o,i){const a=1-t;return 3*a*a*(n-e)+6*a*t*(o-n)+3*t*t*(i-o)},cut(t,e,o,i,a,r,s,l,c,u){const f=1-e,h=f*o+e*a,d=f*i+e*r,p=f*a+e*s,y=f*r+e*l,S=f*h+e*p,m=f*d+e*y,g=f*S+e*(f*p+e*(f*s+e*c)),b=f*m+e*(f*y+e*(f*l+e*u));t.push(n.PathCommandMap.C,h,d,S,m,g,b)}},{getDerivative:j}=k,{M:A,L:C,C:E,Z:T}=n.PathCommandMap,w={},F={},N={transform(t,e){let n,o=0;const i=t.length;for(;o<i;)switch(n=t[o],n){case A:case C:N.transformPoints(t,e,o,1),o+=3;break;case E:N.transformPoints(t,e,o,3),o+=7;break;case T:o+=1}},transformPoints(t,e,o,i){for(let a=o+1,r=a+2*i;a<r;a+=2)w.x=t[a],w.y=t[a+1],n.MatrixHelper.toOuterPoint(e,w),t[a]=w.x,t[a+1]=w.y},getMotionPathData(t){let e,o,i,a,r=0,s=[],l=0,c=0,u=0;const f=t.length;for(;l<f;){switch(a=t[l],a){case A:case C:o=t[l+1],i=t[l+2],e=a===C&&l>0?n.PointHelper.getDistanceFrom(c,u,o,i):0,c=o,u=i,l+=3;break;case E:o=t[l+5],i=t[l+6],e=k.getDistance(c,u,t[l+1],t[l+2],t[l+3],t[l+4],o,i),c=o,u=i,l+=7;break;case T:l+=1;default:e=0}s.push(e),r+=e}return{total:r,segments:s,data:t}},getDistancePoint(t,e){const{segments:o,data:i}=t;e=n.UnitConvert.number(e,t.total);let a,r,s,l,c=0,u={},f=0,h=0,d=0,p=0;const y=i.length;for(;f<y;){switch(l=i[f],l){case A:case C:if(r=i[f+1],s=i[f+2],a=o[h],c+a>e||!t.total)return f||(d=r,p=s),F.x=d,F.y=p,u.x=r,u.y=s,n.PointHelper.getDistancePoint(F,u,e-c,!0),u.rotation=n.PointHelper.getAngle(F,u),u;d=r,p=s,f+=3;break;case E:if(r=i[f+5],s=i[f+6],a=o[h],c+a>e){const t=i[f+1],o=i[f+2],l=i[f+3],h=i[f+4];return e-=c,n.BezierHelper.getPointAndSet(e/a,d,p,t,o,l,h,r,s,u),n.BezierHelper.getPointAndSet(Math.max(0,e-.1)/a,d,p,t,o,l,h,r,s,F),u.rotation=n.PointHelper.getAngle(F,u),u}d=r,p=s,f+=7;break;case T:f+=1;default:a=0}h++,c+=a}return u},getDistancePath(t,e){const{segments:o,data:i}=t,a=[];e=n.UnitConvert.number(e,t.total);let r,s,l,c,u=0,f={},h=0,d=0,p=0,y=0;const S=i.length;for(;h<S;){switch(c=i[h],c){case A:case C:if(s=i[h+1],l=i[h+2],r=o[d],u+r>e||!t.total)return h||(p=s,y=l),F.x=p,F.y=y,f.x=s,f.y=l,n.PointHelper.getDistancePoint(F,f,e-u,!0),a.push(c,f.x,f.y),a;p=s,y=l,h+=3,a.push(c,p,y);break;case E:const S=i[h+1],m=i[h+2],g=i[h+3],b=i[h+4];if(s=i[h+5],l=i[h+6],r=o[d],u+r>e)return k.cut(a,(e-u)/r,p,y,S,m,g,b,s,l),a;p=s,y=l,h+=7,a.push(c,S,m,g,b,s,l);break;case T:h+=1,a.push(c);default:r=0}d++,u+=r}return a}};function L(t){return n.decorateLeafAttr(t,(t=>n.attr({set(e){this.__setAttr(t,e),this.__hasMotionPath=this.motionPath||!n.isNull(this.motion),this.__layout.matrixChanged||this.__layout.matrixChange()}})))}n.Transition.register("motion",(function(t,e,o,i){return t?"object"==typeof t&&(t=n.UnitConvert.number(t,i.getMotionTotal())):t=0,e?"object"==typeof e&&(e=n.UnitConvert.number(e,i.getMotionTotal())):e=0,n.Transition.number(t,e,o)})),n.Transition.register("motionRotation",(function(t,e,o){return n.Transition.number(t,e,o)}));const B=n.UI.prototype,{updateMatrix:U,updateAllMatrix:q}=n.LeafHelper,{updateBounds:R}=n.BranchHelper;function z(t){const{motion:e,leaferIsCreated:o}=t;if(!n.isNull(e)){if(o&&(t.leafer.created=!1),t.motionPath){const n=V(t);n.total&&(t.__.__pathForRender=N.getDistancePath(n,e))}else t.set(t.getMotionPoint(e)),t.__hasAutoLayout||(t.isBranch?(q(t),R(t,t)):U(t));o&&(t.leafer.created=!0)}}function I(t){const{parent:e}=t;if(!t.motionPath&&e){const{children:t}=e;for(let e=0;e<t.length;e++)if(t[e].motionPath)return t[e]}return t}function V(t){const e=t.__;return e.__pathForMotion?e.__pathForMotion:e.__pathForMotion=N.getMotionPathData(t.getPath(!0,!0))}L()(B,"motionPath"),L()(B,"motion"),L(!0)(B,"motionRotation"),B.getMotionPathData=function(){return V(I(this))},B.getMotionPoint=function(t){const e=I(this),o=V(e);if(!o.total)return{};const i=N.getDistancePoint(o,t);n.MatrixHelper.toOuterPoint(e.localTransform,i);const{motionRotation:a}=this;return!1===a?delete i.rotation:"number"==typeof a&&(i.rotation+=a),i},B.getMotionTotal=function(){return this.getMotionPathData().total},B.__updateMotionPath=function(){const t=this.__;if(this.__layout.resized&&t.__pathForMotion&&(t.__pathForMotion=void 0),this.motionPath){let t;const{children:e}=this.parent,{leaferIsReady:o}=this;for(let i=0;i<e.length;i++)t=e[i],n.isNull(t.motion)||t.__layout.matrixChanged||(o&&t!==this&&this.leafer.layouter.addExtra(t),z(t))}else z(this)},exports.HighBezierHelper=k,exports.HighCurveHelper=N,exports.motionPathType=L,exports.stateStyleType=r,exports.stateType=a,Object.keys(t).forEach((function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})})),Object.keys(e).forEach((function(t){"default"===t||Object.prototype.hasOwnProperty.call(exports,t)||Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})})),Object.keys(i).forEach((function(t){"default"===t||Object.prototype.hasOwnProperty.call(exports,t)||Object.defineProperty(exports,t,{enumerable:!0,get:function(){return i[t]}})}));
|