@ax-design/reveal-highlight 0.3.0-alpha.9 → 0.4.0
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 +0 -8
- package/build/BaseConfig.d.ts +43 -0
- package/build/BaseConfig.d.ts.map +1 -0
- package/build/CanvasConfig.d.ts +7 -93
- package/build/CanvasConfig.d.ts.map +1 -1
- package/build/CustomElements.d.ts +18 -4
- package/build/CustomElements.d.ts.map +1 -1
- package/build/RevealBoundryStore.d.ts +50 -10
- package/build/RevealBoundryStore.d.ts.map +1 -1
- package/build/RevealStateManager.d.ts +3 -0
- package/build/RevealStateManager.d.ts.map +1 -1
- package/build/SvgConfig.d.ts +17 -0
- package/build/SvgConfig.d.ts.map +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/main.js +169 -17
- package/build/utils/extractRGBValue.d.ts +2 -0
- package/build/utils/extractRGBValue.d.ts.map +1 -0
- package/build/utils/isValidateBorderDecorationType.d.ts +3 -0
- package/build/utils/isValidateBorderDecorationType.d.ts.map +1 -0
- package/build/utils/types.d.ts +103 -0
- package/build/utils/types.d.ts.map +1 -0
- package/docs/demo/index.html +70 -143
- package/docs/demo/ng.html +992 -0
- package/es/BaseConfig.d.ts +43 -0
- package/es/BaseConfig.d.ts.map +1 -0
- package/es/BaseConfig.js +220 -0
- package/es/BaseConfig.js.map +1 -0
- package/es/CanvasConfig.d.ts +7 -93
- package/es/CanvasConfig.d.ts.map +1 -1
- package/es/CanvasConfig.js +35 -239
- package/es/CanvasConfig.js.map +1 -1
- package/es/CustomElements.d.ts +18 -4
- package/es/CustomElements.d.ts.map +1 -1
- package/es/CustomElements.js +82 -7
- package/es/CustomElements.js.map +1 -1
- package/es/RevealBoundryStore.d.ts +50 -10
- package/es/RevealBoundryStore.d.ts.map +1 -1
- package/es/RevealBoundryStore.js +129 -35
- package/es/RevealBoundryStore.js.map +1 -1
- package/es/RevealStateManager.d.ts +3 -0
- package/es/RevealStateManager.d.ts.map +1 -1
- package/es/RevealStateManager.js +35 -8
- package/es/RevealStateManager.js.map +1 -1
- package/es/SvgConfig.d.ts +17 -0
- package/es/SvgConfig.d.ts.map +1 -0
- package/es/SvgConfig.js +346 -0
- package/es/SvgConfig.js.map +1 -0
- package/es/index.d.ts.map +1 -1
- package/es/index.js +10 -16
- package/es/index.js.map +1 -1
- package/es/utils/extractRGBValue.d.ts +2 -0
- package/es/utils/extractRGBValue.d.ts.map +1 -0
- package/es/utils/extractRGBValue.js +48 -0
- package/es/utils/extractRGBValue.js.map +1 -0
- package/es/utils/isValidateBorderDecorationType.d.ts +3 -0
- package/es/utils/isValidateBorderDecorationType.d.ts.map +1 -0
- package/es/utils/isValidateBorderDecorationType.js +10 -0
- package/es/utils/isValidateBorderDecorationType.js.map +1 -0
- package/es/utils/types.d.ts +103 -0
- package/es/utils/types.d.ts.map +1 -0
- package/es/utils/types.js +2 -0
- package/es/utils/types.js.map +1 -0
- package/package.json +30 -30
- package/src/BaseConfig.ts +311 -0
- package/src/CanvasConfig.ts +66 -387
- package/src/CustomElements.ts +97 -14
- package/src/RevealBoundryStore.ts +138 -39
- package/src/RevealStateManager.ts +40 -10
- package/src/SvgConfig.ts +422 -0
- package/src/index.ts +10 -16
- package/src/utils/extractRGBValue.ts +58 -0
- package/src/utils/isValidateBorderDecorationType.ts +8 -0
- package/src/utils/types.ts +106 -0
- package/.yarnrc.yml +0 -1
- package/docs/demo/debug.html +0 -72
package/build/main.js
CHANGED
|
@@ -1,28 +1,141 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):(e="undefined"==typeof globalThis?e||self:globalThis,t(e.AxRevealHighlight={}))})(this,function(e){'use strict';var t=Number.isNaN,r=Math.max,a=Math.floor;function i(e){return c.compat?new u(e):new p(e)}function o(){customElements.define(x.ElementName,x),customElements.define(F.ElementName,F),customElements.define(P.ElementName,P),customElements.define(C.ElementName,C)}function n({compat:e=!1,borderDetectionMode:t="strictEdge"}){if(B)return void console.warn("You have already registered Ax RevealHighlight, please do not call this function repeatedly.");if(c.borderDetectionMode=t,c.compat=e,B=!0,window.CSS&&window.CSS.registerProperty)window.CSS.registerProperty({name:"--reveal-color",syntax:"<color>",initialValue:"rgb(0, 0, 0)",inherits:!0}),window.CSS.registerProperty({name:"--reveal-opacity",syntax:"<number>",initialValue:"0.26",inherits:!0}),window.CSS.registerProperty({name:"--reveal-border-color",syntax:`<color>|${w}`,initialValue:w,inherits:!0}),window.CSS.registerProperty({name:"--reveal-border-width",syntax:"<length>",initialValue:"1px",inherits:!0}),window.CSS.registerProperty({name:"--reveal-border-fill-radius",syntax:"<number>",initialValue:"1.5",inherits:!0}),window.CSS.registerProperty({name:"--reveal-border-decoration-type",syntax:"<custom-ident>",initialValue:"miter",inherits:!0}),window.CSS.registerProperty({name:"--reveal-border-decoration-radius",syntax:"<length>",initialValue:"0",inherits:!0}),window.CSS.registerProperty({name:"--reveal-border-decoration-top-left-radius",syntax:"<length>",initialValue:"-1px",inherits:!0}),window.CSS.registerProperty({name:"--reveal-border-decoration-top-right-radius",syntax:"<length>",initialValue:"-1px",inherits:!0}),window.CSS.registerProperty({name:"--reveal-border-decoration-bottom-left-radius",syntax:"<length>",initialValue:"-1px",inherits:!0}),window.CSS.registerProperty({name:"--reveal-border-decoration-bottom-right-radius",syntax:"<length>",initialValue:"-1px",inherits:!0}),window.CSS.registerProperty({name:"--reveal-border-left-type",syntax:"<custom-ident>",initialValue:"line",inherits:!0}),window.CSS.registerProperty({name:"--reveal-border-right-type",syntax:"<custom-ident>",initialValue:"line",inherits:!0}),window.CSS.registerProperty({name:"--reveal-border-top-type",syntax:"<custom-ident>",initialValue:"line",inherits:!0}),window.CSS.registerProperty({name:"--reveal-border-bottom-type",syntax:"<custom-ident>",initialValue:"line",inherits:!0}),window.CSS.registerProperty({name:"--reveal-hover-light",syntax:"<custom-ident>",initialValue:"true",inherits:!0}),window.CSS.registerProperty({name:"--reveal-hover-light-color",syntax:`<color>|${w}`,initialValue:w,inherits:!0}),window.CSS.registerProperty({name:"--reveal-hover-light-fill-radius",syntax:"<number>",initialValue:"1.5",inherits:!0}),window.CSS.registerProperty({name:"--reveal-hover-light-fill-radius-mode",syntax:"<custom-ident>",initialValue:"relative",inherits:!0}),window.CSS.registerProperty({name:"--reveal-diffuse",syntax:"<custom-ident>",initialValue:"true",inherits:!0}),window.CSS.registerProperty({name:"--reveal-press-animation",syntax:"<custom-ident>",initialValue:"true",inherits:!0}),window.CSS.registerProperty({name:"--reveal-press-animation-color",syntax:`<color>|${w}`,initialValue:w,inherits:!0}),window.CSS.registerProperty({name:"--reveal-press-animation-radius-mode",syntax:"<custom-ident>",initialValue:"cover",inherits:!0}),window.CSS.registerProperty({name:"--reveal-press-animation-speed",syntax:"<number>",initialValue:"2000",inherits:!0}),window.CSS.registerProperty({name:"--reveal-release-animation-accelerate-rate",syntax:"<number>",initialValue:"6",inherits:!0}),o();else if(e){const e=document.documentElement;e.style.setProperty("--reveal-color","rgb(0, 0, 0)"),e.style.setProperty("--reveal-opacity","0.26"),e.style.setProperty("--reveal-border-color",w),e.style.setProperty("--reveal-border-width","1px"),e.style.setProperty("--reveal-border-fill-radius","1.5"),e.style.setProperty("--reveal-border-decoration-type","miter"),e.style.setProperty("--reveal-border-decoration-radius","0"),e.style.setProperty("--reveal-border-decoration-top-left-radius","-1"),e.style.setProperty("--reveal-border-decoration-top-right-radius","-1"),e.style.setProperty("--reveal-border-decoration-bottom-left-radius","-1"),e.style.setProperty("--reveal-border-decoration-bottom-right-radius","-1"),e.style.setProperty("--reveal-border-left-type","line"),e.style.setProperty("--reveal-border-right-type","line"),e.style.setProperty("--reveal-border-top-type","line"),e.style.setProperty("--reveal-border-bottom-type","line"),e.style.setProperty("--reveal-hover-light","true"),e.style.setProperty("--reveal-hover-light-color",w),e.style.setProperty("--reveal-hover-light-fill-radius","1.5"),e.style.setProperty("--reveal-hover-light-fill-radius-mode","relative"),e.style.setProperty("--reveal-diffuse","true"),e.style.setProperty("--reveal-press-animation","true"),e.style.setProperty("--reveal-press-animation-radius-mode","cover"),e.style.setProperty("--reveal-press-animation-color",w),e.style.setProperty("--reveal-press-animation-speed","2000"),e.style.setProperty("--reveal-release-animation-accelerate-rate","6"),o()}else console.warn("Your browser do NOT support `CSS.registerProperty` method, registration failed!"),console.warn("If you are the developer, try using `register(true)` to support old browsers.")}let l="strictEdge",d=!1;class s extends Error{constructor(){super("Border detection mode has already been initialized."),this.name="InitializedError"}}const c={compat:!1,get borderDetectionMode(){return l},set borderDetectionMode(e){if(d)throw new s;l=e,d=!0}};class u{constructor(e){if(!u.colorParser){const e=document.createElement("div");e.style.display="none !important",document.body.appendChild(e),u.colorParser=e,u.colorParserStyle=window.getComputedStyle(e)}this.el=e,this.style=window.getComputedStyle(e)}size(){return this.style.length}get(e){return this.style.getPropertyValue(e).trim()}getColor(e){return u.colorParser.style.color=this.get(e),u.colorParserStyle.color||"rgb(0, 0, 0)"}getNumber(e){// Length values in computed style will always in the unit of px
|
|
2
2
|
// Maybe NaN
|
|
3
|
-
return parseFloat(this.get(
|
|
4
|
-
}}const
|
|
3
|
+
return parseFloat(this.get(e))}}class p{constructor(e){this.el=e,this.style=e.computedStyleMap()}size(){return this.style.size}get(e){return this.style.get(e).toString()}getColor(e){return this.get(e)}getNumber(e){const t=this.style.get(e).value;return"number"==typeof t?t:parseFloat(t);// Maybe NaN
|
|
4
|
+
}}const m=e=>{if(""===e)return"";if("#"===e[0]){// Thanks bro:
|
|
5
5
|
// https://stackoverflow.com/a/11508164/3931936
|
|
6
|
-
const
|
|
7
|
-
|
|
6
|
+
const i=parseInt(e.substring(1),16);var t=255&i>>16,r=255&i>>8,a=255&i;return t+","+r+","+a}else{let t="",r=!1,a=0;for(let o=0;o<e.length;o++){const i=e[o],n=i.charCodeAt(0)-48;if(" "!==i){if(r&&!(0<=n&&10>n)&&","!==i&&")"!==i)throw new SyntaxError(`${e} is not a validate color value!`);if(!r&&"("===i){r=!0;continue}if(2>a&&")"===i)throw new SyntaxError(`${e} should have at least three color channel`);if(","===i&&a++,")"===i)return t;r&&(t+=i)}}return t}},h=e=>"round"===e||"bevel"===e||"miter"===e;class y{constructor(e,t,o){/**
|
|
7
|
+
* If is cleaned up by `RevealBoundaryStore` during animation
|
|
8
|
+
* duration checkup.
|
|
9
|
+
*/this.pxRatio=window.devicePixelRatio||1,this.paintedWidth=0,this.paintedHeight=0,this.currentFrameId=-1,this.cachedBoundingRectFrameId=-2,this.cachedBoundingRect={top:-1,left:-1,width:-1,height:-1},this.cachedStyleFrameId=-2,this.cachedStyle={trueFillRadius:[0,0],color:"",opacity:1,borderColor:"",borderFillRadius:0,borderDecorationType:"miter",borderDecorationRadius:0,topLeftBorderDecorationRadius:0,topRightBorderDecorationRadius:0,bottomLeftBorderDecorationRadius:0,bottomRightBorderDecorationRadius:0,withLeftBorderFactor:1,withRightBorderFactor:1,withTopBorderFactor:1,withBottomBorderFactor:1,borderWidth:1,hoverLight:!0,hoverLightColor:"",hoverLightFillMode:"",hoverLightFillRadius:0,diffuse:!0,pressAnimation:!0,pressAnimationFillMode:"",pressAnimationColor:"",pressAnimationSpeed:0,releaseAnimationAccelerateRate:0},this.dirty=!1,this.shapeDirty=!0,this.fillDirty=!0,this.animationDirty=!0,this.cleanedUpForAnimation=!1,this.mouseUpClientX=null,this.mouseUpClientY=null,this.mouseDownAnimateStartFrame=null,this.mouseDownAnimateCurrentFrame=null,this.mouseDownAnimateReleasedFrame=null,this.mouseDownAnimateLogicFrame=null,this.mousePressed=!1,this.mouseReleased=!1,this.cacheBoundingRect=()=>{if(this.currentFrameId!==this.cachedBoundingRectFrameId){const e=this.container.getBoundingClientRect();this.cachedBoundingRect.top=a(e.top),this.cachedBoundingRect.left=a(e.left),this.cachedBoundingRect.width=a(e.width),this.cachedBoundingRect.height=a(e.height),this.cachedBoundingRectFrameId=this.currentFrameId}},this.getTrueFillRadius=(e=[0,0],t=this.computedStyle.get("--reveal-hover-light-fill-radius-mode")||"relative")=>{const a=this.cachedBoundingRect;switch(t){case"relative":e[0]=Math.min(a.width,a.height),e[1]=r(a.width,a.height);break;case"absolute":e[0]=-1,e[1]=-1;break;default:throw new SyntaxError("The value of `--reveal-hover-light-fill-radius-mode` must be `relative`, `absolute`, but got `"+t+"`!");}return e},this.getPropFromMultipleSource=(e,t)=>{const r=this.container.dataset[e];return r?r:this.computedStyle.get(t)},this.getNumberPropFromMultipleSource=(e,t)=>{var r=Number.parseFloat;const a=this.container.dataset[e];return a?r(a):this.computedStyle.getNumber(t)},this.cacheCanvasPaintingStyle=()=>{if(this.currentFrameId===this.cachedStyleFrameId)return;if(0===this.computedStyle.size())return;const e=m(this.computedStyle.getColor("--reveal-color"))||"0, 0, 0",t=m(this.computedStyle.getColor("--reveal-border-color"))||e,a=m(this.computedStyle.getColor("--reveal-hover-light-color"))||e,i=m(this.computedStyle.getColor("--reveal-press-animation-color"))||e,o=e,n=this.computedStyle.getNumber("--reveal-opacity"),l=t,d=this.computedStyle.getNumber("--reveal-border-fill-radius"),s=this.computedStyle.get("--reveal-border-decoration-type")||"miter",u=this.computedStyle.getNumber("--reveal-border-width"),p="line"===this.getPropFromMultipleSource("leftBorder","--reveal-border-left-type")?1:0,y="line"===this.getPropFromMultipleSource("rightBorder","--reveal-border-right-type")?1:0,v="line"===this.getPropFromMultipleSource("topBorder","--reveal-border-top-type")?1:0,g="line"===this.getPropFromMultipleSource("bottomBorder","--reveal-border-bottom-type")?1:0,R="true"===this.computedStyle.get("--reveal-hover-light"),f=a,S=this.computedStyle.getNumber("--reveal-hover-light-fill-radius"),b=this.computedStyle.get("--reveal-hover-light-fill-radius-mode")||"relative",x="true"===this.computedStyle.get("--reveal-diffuse"),F="true"===this.computedStyle.get("--reveal-press-animation"),P=this.computedStyle.get("--reveal-press-animation-radius-mode"),C=i,w=this.computedStyle.getNumber("--reveal-press-animation-speed"),B=this.computedStyle.getNumber("--reveal-release-animation-accelerate-rate"),D=this.computedStyle.getNumber("--reveal-border-decoration-radius"),r=this.getNumberPropFromMultipleSource("topLeftBorderRadius","--reveal-border-decoration-top-left-radius"),A=this.getNumberPropFromMultipleSource("topRightBorderRadius","--reveal-border-decoration-top-right-radius"),T=this.getNumberPropFromMultipleSource("bottomLeftBorderRadius","--reveal-border-decoration-bottom-left-radius"),L=this.getNumberPropFromMultipleSource("bottomRightBorderRadius","--reveal-border-decoration-bottom-right-radius"),I=0<=r?r:D,M=0<=A?A:D,E=0<=T?T:D,V=0<=L?L:D,N=this.cachedStyle;if(this.fillDirty=this.fillDirty||N.color!==o,this.fillDirty=this.fillDirty||N.opacity!==n,this.fillDirty=this.fillDirty||N.borderColor!==l,this.fillDirty=this.fillDirty||N.borderFillRadius!==d,this.fillDirty=this.fillDirty||N.hoverLightColor!==f,this.fillDirty=this.fillDirty||N.hoverLightFillRadius!==S,this.fillDirty=this.fillDirty||N.hoverLightFillMode!==b,this.shapeDirty=this.shapeDirty||N.borderDecorationType!==s,this.shapeDirty=this.shapeDirty||N.borderWidth!==u,this.shapeDirty=this.shapeDirty||N.withLeftBorderFactor!==p,this.shapeDirty=this.shapeDirty||N.withRightBorderFactor!==y,this.shapeDirty=this.shapeDirty||N.withTopBorderFactor!==v,this.shapeDirty=this.shapeDirty||N.withBottomBorderFactor!==g,this.shapeDirty=this.shapeDirty||N.topLeftBorderDecorationRadius!==I,this.shapeDirty=this.shapeDirty||N.topRightBorderDecorationRadius!==M,this.shapeDirty=this.shapeDirty||N.bottomLeftBorderDecorationRadius!==E,this.shapeDirty=this.shapeDirty||N.bottomRightBorderDecorationRadius!==V,this.animationDirty=this.animationDirty||N.pressAnimation!==F,this.animationDirty=this.animationDirty||N.pressAnimationFillMode!==P,this.animationDirty=this.animationDirty||N.pressAnimationColor!==C,this.animationDirty=this.animationDirty||N.pressAnimationSpeed!==w,this.animationDirty=this.animationDirty||N.releaseAnimationAccelerateRate!==B,N.color=o,N.opacity=n,N.borderColor=l,N.borderFillRadius=d,N.borderDecorationType=s,N.borderWidth=u,N.withLeftBorderFactor=p,N.withRightBorderFactor=y,N.withTopBorderFactor=v,N.withBottomBorderFactor=g,N.hoverLight=R,N.hoverLightColor=f,N.hoverLightFillRadius=S,N.hoverLightFillMode=b,N.diffuse=x,N.pressAnimation=F,N.pressAnimationFillMode=P,N.pressAnimationColor=C,N.pressAnimationSpeed=w,N.releaseAnimationAccelerateRate=B,N.topLeftBorderDecorationRadius=I,N.topRightBorderDecorationRadius=M,N.bottomLeftBorderDecorationRadius=E,N.bottomRightBorderDecorationRadius=V,this.getTrueFillRadius(N.trueFillRadius,N.hoverLightFillMode),!h(N.borderDecorationType))throw new SyntaxError("The value of `--reveal-border-decoration-type` must be `round`, `bevel` or `miter`!");this.cachedStyleFrameId=this.currentFrameId},this.mouseInCanvas=()=>{const e=this.cachedBoundingRect,t=this._store.clientX-e.left,r=this._store.clientY-e.top;return 0<t&&0<r&&t<e.width&&r<e.height},this.syncSizeToRevealRadius=(e,t)=>{const{trueFillRadius:r}=this.cachedStyle,a=r[1]||1,i=2*a*this.pxRatio*t;(e.width!==i||e.height!==i)&&(e.width=i,e.height=i)},this._store=e,this.container=o,this.element=t,this.computedStyle=i(o)}}const v=()=>document.createElement("canvas");class g extends y{constructor(e,i,o){super(e,i,o),this.updateCachedReveal=()=>{if(!this.fillDirty)return;const e=this.cachedStyle,t=e.trueFillRadius[1]*this.pxRatio,r=this.cachedImg.cachedReveal,{borderReveal:a,fillReveal:o}=this.cachedImg.cachedCanvas,{borderReveal:n,fillReveal:l}=this.cachedImg.cachedCtx;this._store.updateMaxRadius(e.trueFillRadius[1]*e.borderFillRadius);for(let d=0;2>d;d++){// 0 means border, 1 means hover light.
|
|
8
10
|
//-----------------------------------------
|
|
9
11
|
// Last rendered style.
|
|
10
|
-
const i=0==
|
|
11
|
-
case"round":this.ctx.moveTo(
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
this.updateAnimateGrd(this.mouseDownAnimateLogicFrame,
|
|
12
|
+
const i=0==d?r.borderReveal:r.fillReveal,s=0==d?e.borderColor:e.hoverLightColor,c=0==d?e.borderFillRadius:e.hoverLightFillRadius,u=s===i.color&&e.opacity===i.opacity&&c===i.radiusFactor;if(u)continue;const p=0==d?a:o,m=0==d?n:l;if(this.syncSizeToRevealRadius(p,c),!m)continue;m.clearRect(0,0,p.width,p.height);const h=0==d?e.opacity:.5*e.opacity,y=t*c,v=m.createRadialGradient(y,y,0,y,y,y);v.addColorStop(0,`rgba(${s}, ${h})`),v.addColorStop(1,`rgba(${s}, 0.0)`);const g=2*t*c;m.fillStyle=v,m.clearRect(0,0,g,g),m.fillRect(0,0,g,g),i.radius=y,i.radiusFactor=c,i.color=s,i.opacity=e.opacity,this.ctx&&(i.pattern=this.ctx.createPattern(p,"no-repeat"))}this.fillDirty=!1},this.updateCachedBitmap=()=>{this.ctx&&this.updateCachedReveal()},this.updateAnimateGrd=(e,t)=>{const{pressAnimationColor:r,opacity:a}=this.cachedStyle,i=a*(.2-e),o=a*(.1-.07*e),n=.1+.8*e,l=0>i?0:i,d=0>o?0:o;let s=0;s=1<n?1:n,s=0>n?0:n,t.addColorStop(0,`rgba(${r},${l})`),t.addColorStop(.55*s,`rgba(${r},${d})`),t.addColorStop(s,`rgba(${r}, 0)`)},this.drawShape=e=>{if(!this.ctx)return;const t=this.cachedBoundingRect,r=t.width*this.pxRatio,a=t.height*this.pxRatio,i=this.cachedStyle,o=i.borderWidth*this.pxRatio,n=i.topLeftBorderDecorationRadius*this.pxRatio,l=i.topRightBorderDecorationRadius*this.pxRatio,d=i.bottomLeftBorderDecorationRadius*this.pxRatio,s=i.bottomRightBorderDecorationRadius*this.pxRatio,c=i.withLeftBorderFactor,u=i.withRightBorderFactor,p=i.withTopBorderFactor,m=i.withBottomBorderFactor,h=o<n?n-o:0,y=o<l?l-o:0,v=o<d?d-o:0,g=o<s?s-o:0;switch(this.ctx.beginPath(),i.borderDecorationType){// Oh... Fuck... It's painful...
|
|
13
|
+
case"round":this.ctx.moveTo(n,0),this.ctx.arcTo(r,0,r,a,l),this.ctx.lineTo(r,a-s),this.ctx.arcTo(r,a,s,a,s),this.ctx.lineTo(d,a),this.ctx.arcTo(0,a,0,s,d),this.ctx.lineTo(0,n),this.ctx.arcTo(0,0,n,0,n),e&&(this.ctx.moveTo(h,o*p),this.ctx.arcTo(o*c,o*p,o*c,h+o*p,h),this.ctx.lineTo(o*c,a-o*m-v),this.ctx.arcTo(o*c,a-o*m,o*c+v,a-o*m,v),this.ctx.lineTo(r-o*u-g,a-o*m),this.ctx.arcTo(r-o*u,a-o*m,r-o*u,a-o*m-g,g),this.ctx.lineTo(r-o*u,o*p+y),this.ctx.arcTo(r-o*u,o*p,r-o*u-y,o*p,y),this.ctx.lineTo(h,o*p));break;case"bevel":this.ctx.moveTo(n,0),this.ctx.lineTo(r-l,0),this.ctx.lineTo(r,l),this.ctx.lineTo(r,a-s),this.ctx.lineTo(r-s,a),this.ctx.lineTo(d,a),this.ctx.lineTo(0,a-d),this.ctx.lineTo(0,n),this.ctx.lineTo(n,0),this.ctx.lineTo(r-l,0),e&&(this.ctx.moveTo(h+o*c,o*p),this.ctx.lineTo(o*c,h+o*p),this.ctx.lineTo(o*c,a-v-o*m),this.ctx.lineTo(o*c+v,a-o*m),this.ctx.lineTo(r-g-o*u,a-o*m),this.ctx.lineTo(r-o*u,a-g-o*m),this.ctx.lineTo(r-o*u,y+o*p),this.ctx.lineTo(r-y-o*u,o*p),this.ctx.lineTo(h+o*u,o*p));break;case"miter":this.ctx.moveTo(0,0),this.ctx.lineTo(r,0),this.ctx.lineTo(r,a),this.ctx.lineTo(0,a),this.ctx.lineTo(0,0),e&&(this.ctx.moveTo(o*c,o*p),this.ctx.lineTo(o*c,a-o*m),this.ctx.lineTo(r-o*u,a-o*m),this.ctx.lineTo(r-o*u,o*p),this.ctx.lineTo(o*c,o*p));}this.ctx.closePath()},this.syncSizeToElement=e=>{const t=this.cachedBoundingRect;(e.width!==t.width||e.height!==t.height)&&(e.width=t.width*this.pxRatio,e.height=t.height*this.pxRatio,e.style.width=`${t.width}px`,e.style.height=`${t.height}px`)},this.clear=()=>{if(!this.ctx)return!1;if(!this.dirty)return!1;const{width:e,height:t}=this.cachedBoundingRect;return this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,e*window.devicePixelRatio,t*window.devicePixelRatio),this.dirty=!1,!0},this.paint=e=>{const i=this._store,o=i.animationQueue.includes(this),n=i.clientX===i.paintedClientX&&i.clientY===i.paintedClientY;if(n&&!e&&!o)return!1;if(!this.ctx)return!1;if(this.dirty=!0,this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.paintedWidth,this.paintedHeight),!i.mouseInBoundary&&!o)return!1;if(!this.cachedImg.cachedReveal)return!1;this.syncSizeToElement(this.element),this.cacheBoundingRect();const l=this.cachedBoundingRect,d=i.clientX-l.left,s=i.clientY-l.top;if(t(d)||t(s))return!1;const u=this.cachedStyle;this.getTrueFillRadius(u.trueFillRadius),this.paintedWidth=l.width*this.pxRatio,this.paintedHeight=l.height*this.pxRatio;const c=u.trueFillRadius[1],p=d-c<l.width,m=s-c<l.height,h=0<d+c&&p&&0<s+c&&m;if(!h&&!o)return!1;if(this.cacheCanvasPaintingStyle(),this.updateCachedBitmap(),i.mouseInBoundary){const e=0<d&&0<s&&d<l.width&&s<l.height,t=this.cachedImg.cachedReveal.fillReveal.pattern;if(u.hoverLight&&e&&t){// draw fill.
|
|
14
|
+
const e=this.cachedImg.cachedReveal.fillReveal.radius,r=a(d*this.pxRatio-e),i=a(s*this.pxRatio-e);this.ctx.setTransform(1,0,0,1,0,0),this.drawShape(!1),this.ctx.translate(r,i),this.ctx.fillStyle=t,this.ctx.fill()}const r=u.diffuse&&h||e,i=this.cachedImg.cachedReveal.borderReveal.pattern;if(0!==u.borderWidth&&i&&r){// Draw border.
|
|
15
|
+
const e=this.cachedImg.cachedReveal.borderReveal.radius,t=a(d*this.pxRatio-e),r=a(s*this.pxRatio-e);this.ctx.setTransform(1,0,0,1,0,0),this.drawShape(!0),this.ctx.translate(t,r),this.ctx.fillStyle=i,this.ctx.fill()}}if(u.pressAnimation&&this.mousePressed&&this.mouseDownAnimateLogicFrame){this.ctx.setTransform(1,0,0,1,0,0);const e="constrained"===u.pressAnimationFillMode?u.trueFillRadius[1]:r(l.width,l.height),t=this.mouseReleased&&this.mouseUpClientX&&this.mouseUpClientY?this.ctx.createRadialGradient((this.mouseUpClientX-l.left)*this.pxRatio,(this.mouseUpClientY-l.top)*this.pxRatio,0,(this.mouseUpClientX-l.left)*this.pxRatio,(this.mouseUpClientY-l.top)*this.pxRatio,e*this.pxRatio):this.ctx.createRadialGradient(d*this.pxRatio,s*this.pxRatio,0,d*this.pxRatio,s*this.pxRatio,e*this.pxRatio);// prettier-ignore
|
|
16
|
+
this.updateAnimateGrd(this.mouseDownAnimateLogicFrame,t),this.drawShape(!1),this.ctx.fillStyle=t,this.ctx.fill()}return!0},this.ctx=i.getContext("2d");const n={borderReveal:v(),fillReveal:v()},l={borderReveal:n.borderReveal.getContext("2d"),fillReveal:n.fillReveal.getContext("2d")};this.cachedImg={cachedReveal:{borderReveal:{radiusFactor:-1,radius:-1,color:"INVALID",opacity:0,pattern:null},fillReveal:{radiusFactor:-1,radius:-1,color:"INVALID",opacity:0,pattern:null}},cachedCanvas:n,cachedCtx:l}}}class R extends y{constructor(e,a,i){super(e,a,i),this.updateCachedBitmap=()=>{},this.updateCachedReveal=()=>{const e=this.cachedStyle,t=this.cachedImg.cachedGradientStop;t.borderReveal[0].style.stopColor=e.borderColor,t.borderReveal[1].style.stopColor=e.borderColor,t.borderReveal[0].style.stopOpacity=e.opacity.toString(),t.borderReveal[1].style.stopOpacity="0",t.fillReveal[0].style.stopColor=e.hoverLightColor,t.fillReveal[1].style.stopColor=e.hoverLightColor,t.fillReveal[0].style.stopOpacity=(.5*e.opacity).toString(),t.fillReveal[1].style.stopOpacity="0",t.rippleReveal[0].style.stopColor=e.pressAnimationColor,t.rippleReveal[1].style.stopColor=e.pressAnimationColor,t.rippleReveal[2].style.stopColor=e.pressAnimationColor;const r=this.cachedImg.cachedGradient,a=-1===e.trueFillRadius[0];r.borderReveal.r.baseVal.value=a?e.borderFillRadius:e.borderFillRadius*e.trueFillRadius[1],r.fillReveal.r.baseVal.value=a?e.hoverLightFillRadius:e.hoverLightFillRadius*e.trueFillRadius[0],this.fillDirty=!1},this.updateAnimateGrd=(e,t,r,a)=>{const{opacity:i}=this.cachedStyle,o=i*(.2-e),n=i*(.1-.07*e),l=.1+.8*e,d=0>o?0:o,s=0>n?0:n;let c=0;c=1<l?1:l,c=0>l?0:l;const u=this.cachedImg.cachedGradientStop;u.rippleReveal[0].style.stopOpacity=d.toString(),u.rippleReveal[1].style.stopOpacity=s.toString(),u.rippleReveal[2].style.stopOpacity="0",u.rippleReveal[0].offset.baseVal=0,u.rippleReveal[1].offset.baseVal=.55*c,u.rippleReveal[2].offset.baseVal=c;const p=this.cachedImg.cachedGradient;p.rippleReveal.r.baseVal.value=a,p.rippleReveal.cx.baseVal.value=t,p.rippleReveal.cy.baseVal.value=r},this.updateGradientPosition=(e,t)=>{const r=this.cachedImg.cachedGradient;r.borderReveal.cx.baseVal.value=e,r.borderReveal.cy.baseVal.value=t,r.fillReveal.cx.baseVal.value=e,r.fillReveal.cy.baseVal.value=t},this.drawShape=(e,t)=>{const r=this.cachedBoundingRect,a=r.width,i=r.height,o=this.cachedStyle,n=o.borderWidth,l=o.topLeftBorderDecorationRadius,s=o.topRightBorderDecorationRadius,c=o.bottomLeftBorderDecorationRadius,u=o.bottomRightBorderDecorationRadius,p=o.withLeftBorderFactor,m=o.withRightBorderFactor,h=o.withTopBorderFactor,y=o.withBottomBorderFactor,v=o.withLeftBorderFactor?0:1,g=o.withRightBorderFactor?0:1,R=o.withTopBorderFactor?0:1,f=o.withBottomBorderFactor?0:1,S=!o.withTopBorderFactor&&!o.withLeftBorderFactor,b=!o.withTopBorderFactor&&!o.withRightBorderFactor,x=!o.withBottomBorderFactor&&!o.withLeftBorderFactor,F=!o.withBottomBorderFactor&&!o.withRightBorderFactor,P=n<l?l-n:0,C=n<s?s-n:0,w=n<c?c-n:0,B=n<u?u-n:0;let D="";// Step 1: Starting point
|
|
17
|
+
switch(D+=e?`M ${l}, 0 `:`M ${n}, ${P+n} `,o.borderDecorationType){// Oh... Fuck again...
|
|
18
|
+
case"round":e&&(D+=`
|
|
19
|
+
h ${a-l-s}
|
|
20
|
+
a ${s}, ${s} 0 0 1 ${s}, ${s}
|
|
21
|
+
v ${i-s-u}
|
|
22
|
+
a ${u}, ${u} 0 0 1 ${-u}, ${u}
|
|
23
|
+
h ${-a+c+u}
|
|
24
|
+
a ${c}, ${c} 0 0 1 ${-c}, ${-c}
|
|
25
|
+
v ${-i+s+u}
|
|
26
|
+
a ${l}, ${l} 0 0 1 ${l}, ${-l}
|
|
27
|
+
Z
|
|
28
|
+
`),D+=`
|
|
29
|
+
M ${n*p}, ${P+n}
|
|
30
|
+
v ${i-P-w-2*n+f*n}
|
|
31
|
+
a ${w}, ${w} 0 0 0 ${w}, ${w}
|
|
32
|
+
h ${a-w-B-2*n+v*n+g*n}
|
|
33
|
+
a ${B}, ${B} 0 0 0 ${B}, ${-B}
|
|
34
|
+
v ${-i+C+B+2*n-R*n-f*n}
|
|
35
|
+
a ${C}, ${C} 0 0 0 ${-C}, ${-C}
|
|
36
|
+
h ${-a+w+B+2*n-v*n-g*n}
|
|
37
|
+
a ${P}, ${P} 0 0 0 ${-P}, ${P}
|
|
38
|
+
L ${n*p}, ${P+n}
|
|
39
|
+
`;break;case"bevel":e&&(D+=`
|
|
40
|
+
h ${a-l-s}
|
|
41
|
+
l ${s} ${s}
|
|
42
|
+
v ${i-s-u}
|
|
43
|
+
l ${-u} ${u}
|
|
44
|
+
h ${-a+s+u}
|
|
45
|
+
l ${-c} ${-c}
|
|
46
|
+
v ${-i+s+u}
|
|
47
|
+
l ${l} ${-l}
|
|
48
|
+
Z
|
|
49
|
+
`),D+=`
|
|
50
|
+
M ${n}, ${P+n}
|
|
51
|
+
${v?`h ${-n}`:""}
|
|
52
|
+
v ${i-P-w-2*n}
|
|
53
|
+
${v?`h ${n}`:""}
|
|
54
|
+
${x?`l ${-n} 0`:""}
|
|
55
|
+
l ${w} ${w}
|
|
56
|
+
${x?`l ${n} 0`:""}
|
|
57
|
+
${f?`v ${n}`:""}
|
|
58
|
+
h ${a-w-B-2*n}
|
|
59
|
+
${f?`v ${-n}`:""}
|
|
60
|
+
${F?`l ${n} 0`:""}
|
|
61
|
+
l ${B} ${-B}
|
|
62
|
+
${F?`l ${-n} 0`:""}
|
|
63
|
+
${g?`h ${n}`:""}
|
|
64
|
+
v ${-i+P+w+2*n}
|
|
65
|
+
${g?`h ${-n}`:""}
|
|
66
|
+
${b?`l 0 ${-n}`:""}
|
|
67
|
+
l ${-C} ${-C}
|
|
68
|
+
${b?`l 0 ${n}`:""}
|
|
69
|
+
${R?`v ${-n}`:""}
|
|
70
|
+
h ${-a+w+B+2*n}
|
|
71
|
+
${R?`v ${n}`:""}
|
|
72
|
+
${S?`l 0 ${-n}`:""}
|
|
73
|
+
l ${-P} ${P}
|
|
74
|
+
${S?`l 0 ${n}`:""}
|
|
75
|
+
`;break;case"miter":e&&(D+=`
|
|
76
|
+
M 0, 0
|
|
77
|
+
h ${a}
|
|
78
|
+
v ${i}
|
|
79
|
+
h ${0-a}
|
|
80
|
+
v ${0-i}
|
|
81
|
+
Z
|
|
82
|
+
`),D+=`
|
|
83
|
+
M ${n*p}, ${n*h}
|
|
84
|
+
v ${i-h*n-y*n}
|
|
85
|
+
h ${a-p*n-m*n}
|
|
86
|
+
v ${-i+h*n+y*n}
|
|
87
|
+
h ${-a+p*n+m*n}
|
|
88
|
+
`;}// Step 3: Close the path
|
|
89
|
+
D+="miter"===o.borderDecorationType?e?`L ${n}, ${n}`:`z`:e?`L ${P+n}, ${P+n}`:`z`,t.setAttribute("d",D)},this.syncSizeToElement=e=>{const t=this.cachedBoundingRect,r=e.width.baseVal,a=e.height.baseVal;(r.value!==t.width||a.value!==t.height)&&(r.value=t.width,a.value=t.height)},this.clear=e=>{e||this.internalClear()},this.internalClear=()=>{if(!this.dirty)return!1;const e=this.cachedImg.cachedPath;return e.borderReveal.style.fill="transparent",e.fillReveal.style.fill="transparent",e.rippleReveal.style.fill="transparent",this.dirty=!1,!0},this.paint=e=>{const a=this._store,i=a.animationQueue.includes(this),o=a.clientX===a.paintedClientX&&a.clientY===a.paintedClientY;if(o&&!e&&!i)return!1;if(!a.mouseInBoundary&&!i)return this.internalClear(),!1;this.syncSizeToElement(this.element),this.cacheBoundingRect();const n=this.cachedBoundingRect,l=a.clientX-n.left,d=a.clientY-n.top;if(t(l)||t(d))return!1;const s=this.cachedStyle;this.getTrueFillRadius(s.trueFillRadius),this.paintedWidth=n.width,this.paintedHeight=n.height;const c=this.cachedImg.cachedGradient,u=r(c.borderReveal.r.baseVal.value,c.fillReveal.r.baseVal.value);this._store.updateMaxRadius(u),this.cacheCanvasPaintingStyle(),this.fillDirty&&this.updateCachedReveal();const p=l-u<n.width,m=d-u<n.height,h=0<l+u&&p&&0<d+u&&m;if(!h&&!i)return this.internalClear(),!1;if(this.dirty=!0,this.updateGradientPosition(l,d),this.shapeDirty&&(this.drawShape(!0,this.cachedImg.cachedPath.borderReveal),this.drawShape(!1,this.cachedImg.cachedPath.fillReveal),this.drawShape(!1,this.cachedImg.cachedPath.rippleReveal),this.shapeDirty=!1),a.mouseInBoundary){const e=0<l&&0<d&&l<n.width&&d<n.height;s.hoverLight&&e?this.cachedImg.cachedPath.fillReveal.style.fill="url(#fillGrad)":"transparent"!==this.cachedImg.cachedPath.fillReveal.style.fill&&(this.cachedImg.cachedPath.fillReveal.style.fill="transparent");const t=s.diffuse&&h||e;0!==s.borderWidth&&t?this.cachedImg.cachedPath.borderReveal.style.fill="url(#borderGrad)":"transparent"!==this.cachedImg.cachedPath.borderReveal.style.fill&&(this.cachedImg.cachedPath.borderReveal.style.fill="transparent")}if(s.pressAnimation&&this.mousePressed&&this.mouseDownAnimateLogicFrame){const e="constrained"===s.pressAnimationFillMode?s.trueFillRadius[1]:r(n.width,n.height);this.mouseReleased&&this.mouseUpClientX&&this.mouseUpClientY?this.updateAnimateGrd(this.mouseDownAnimateLogicFrame,this.mouseUpClientX-n.left,this.mouseUpClientY-n.top,e):this.updateAnimateGrd(this.mouseDownAnimateLogicFrame,l,d,e),this.cachedImg.cachedPath.rippleReveal.style.fill="url(#rippleGrad)"}else"transparent"!==this.cachedImg.cachedPath.rippleReveal.style.fill&&(this.cachedImg.cachedPath.rippleReveal.style.fill="transparent");return!0},this._store=e;const o={borderReveal:a.querySelector("#borderPath"),fillReveal:a.querySelector("#fillPath"),rippleReveal:a.querySelector("#ripplePath")},n={borderReveal:a.querySelector("#borderGrad"),fillReveal:a.querySelector("#fillGrad"),rippleReveal:a.querySelector("#rippleGrad")},l={borderReveal:[a.querySelector("#borderCenter"),a.querySelector("#borderOut")],fillReveal:[a.querySelector("#fillCenter"),a.querySelector("#fillOut")],rippleReveal:[a.querySelector("#rippleCenter"),a.querySelector("#rippleMiddle"),a.querySelector("#rippleOut")]};this.cachedImg={cachedReveal:{borderReveal:{radiusFactor:-1,radius:-1,color:"INVALID",opacity:0,pattern:null},fillReveal:{radiusFactor:-1,radius:-1,color:"INVALID",opacity:0,pattern:null}},cachedPath:o,cachedGradient:n,cachedGradientStop:l}}}class f{constructor(e,t){// The current cursor position relative to window.
|
|
15
90
|
// The cursor position of painted reveal effect.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Repaint all canvas while user's pointer has entered the boundary.
|
|
93
|
+
*/ /**
|
|
94
|
+
* Clear all canvas while user's pointer leave the bounary.
|
|
95
|
+
*/ /**
|
|
96
|
+
* The painting method that draw everything on your screen.
|
|
97
|
+
* @param frame current frame index, if this value is 0, it means all canvas
|
|
98
|
+
* should be cleaned.
|
|
99
|
+
* @param skipSamePointerPositionCheck Literally.
|
|
100
|
+
*/ /**
|
|
101
|
+
* Clear all canvas.
|
|
102
|
+
*/ /**
|
|
103
|
+
* This is the effect while user pressed on the reveal highlight,
|
|
104
|
+
* the ripple start to spread slowly.
|
|
105
|
+
*/ /**
|
|
106
|
+
* This is the effect while user released it's pointer, the spreading
|
|
107
|
+
* ripple animation will start to accelerate.
|
|
108
|
+
*/ /**
|
|
109
|
+
* Cleanup all animations.
|
|
110
|
+
* @param skipPaint Only cleanup data or also clean up the canvas
|
|
111
|
+
* @param forceClean Clean the canvas or not
|
|
112
|
+
*/ /**
|
|
113
|
+
* Clean up the config of an animation, but the canvas won't cleaned up.
|
|
114
|
+
* @param config The config to be cleaned up.
|
|
115
|
+
* @param skipPaint Skip painting.
|
|
116
|
+
* @param forceClean Force clear the painting.
|
|
117
|
+
*/this.clientX=-1e3,this.clientY=-1e3,this.paintedClientX=-1e3,this.paintedClientY=-1e3,this.mouseInBoundary=!1,this.canvasList=[],this.animationQueue=[],this.animationFrame=null,this.mouseUpClientX=null,this.mouseUpClientY=null,this.mouseDownAnimateStartFrame=null,this.mouseDownAnimateCurrentFrame=null,this.mouseDownAnimateReleasedFrame=null,this.mouseDownAnimateLogicFrame=null,this.mousePressed=!1,this.mouseReleased=!1,this.maxRadius=-1,this.requestedAnimationFrame=!1,this.addReveal=(e,t)=>{let r;const a=Object.prototype.toString.call(e);if("[object HTMLCanvasElement]"===a)r=new g(this,e,t);else if("[object SVGSVGElement]"===a)r=new R(this,e,t);else throw new TypeError(`Unknown element type, got: ${a}, Canvas or SVG element expected.`);r.cacheBoundingRect(),r.cacheCanvasPaintingStyle(),r.updateCachedBitmap(),this.canvasList.push(r)},this.removeReveal=e=>{this.canvasList=this.canvasList.filter(t=>t&&t.element!==e)},this.updateMaxRadius=e=>{this.maxRadius=r(e,this.maxRadius)},this.requestPaintAll=e=>{this.requestedAnimationFrame||(this.requestedAnimationFrame=!0,this.animationFrame=window.requestAnimationFrame(t=>{this.requestedAnimationFrame=!1,this.paintAll(e?-1:t,!0)}))},this.updatePointerPosition=(e,t)=>{this.clientX=e,this.clientY=t;const r=this.container.getBoundingClientRect();let a=!0;e<r.left-this.maxRadius&&(a=!1),e>r.right+this.maxRadius&&(a=!1),t<r.top-this.maxRadius&&(a=!1),t>r.bottom+this.maxRadius&&(a=!1),this.mouseInBoundary=a},this.onPointerMoveOnScreen=(e,t)=>{if(this.updatePointerPosition(e,t),!!this.mouseInBoundary)return this.requestPaintAll(),!0},this.onPointerEnterBoundary=()=>{this.mouseInBoundary=!0,this.animationFrame||this.requestPaintAll()},this.onPointerLeaveBoundary=()=>{this.mouseInBoundary=!1,this.requestPaintAll(!0)},this.paintAll=(e,t)=>{if(t||this.mouseInBoundary||0!==this.animationQueue.length){// Animation duration checkup
|
|
118
|
+
for(let t=0;t<this.animationQueue.length;t++){const r=this.animationQueue[t];if(!e||r.currentFrameId===e)continue;r.currentFrameId=e,null===r.mouseDownAnimateStartFrame&&(r.mouseDownAnimateStartFrame=e);// Calculate how long the animation has been playing
|
|
119
|
+
const a=e-r.mouseDownAnimateStartFrame;r.mouseDownAnimateCurrentFrame=a;const i=r.cachedStyle.pressAnimationSpeed,o=r.cachedStyle.releaseAnimationAccelerateRate;// We assume that Ripple is a one-way linear process from
|
|
120
|
+
// no diffusion to fully diffused,
|
|
121
|
+
// and Logic Frame represents the progress of the animation
|
|
122
|
+
// in this process.
|
|
123
|
+
let n=a;r.mouseReleased&&r.mouseDownAnimateReleasedFrame&&(n+=(a-r.mouseDownAnimateReleasedFrame)*o),r.mouseDownAnimateLogicFrame=n/i,1<r.mouseDownAnimateLogicFrame&&(r.cleanedUpForAnimation=!0)}// Paint the canvas one by one
|
|
124
|
+
for(let r=0;r<this.canvasList.length;r++){const a=this.canvasList[r];if(a.currentFrameId=e,a.cleanedUpForAnimation)this.cleanUpAnimationUnit(a,!1),a.cleanedUpForAnimation=!1;else{const e=-1===this.animationQueue.indexOf(a);this.mouseInBoundary||e?a.paint(t):a.clear(!1)}}this.paintedClientX=this.clientX,this.paintedClientY=this.clientY,this.mouseInBoundary||0!==this.animationQueue.length?this.requestPaintAll():this.animationFrame=null}},this.clearAll=e=>{this.cleanupAnimation(e,!0)},this.initializeAnimation=()=>{const e=this.canvasList.find(e=>e.mouseInCanvas());e&&(!this.animationQueue.includes(e)&&this.animationQueue.push(e),e.mouseDownAnimateStartFrame=null,e.mousePressed=!0,e.mouseReleased=!1)},this.switchAnimation=()=>{for(let e=0;e<this.animationQueue.length;e++){const t=this.animationQueue[e];t.mouseReleased||(t.mouseReleased=!0,t.mouseDownAnimateReleasedFrame=t.mouseDownAnimateCurrentFrame,t.mouseUpClientX=this.clientX,t.mouseUpClientY=this.clientY)}},this.cleanupAnimation=(e,t)=>{for(let r=0;r<this.animationQueue.length;r++){const a=this.animationQueue[r];this.cleanUpAnimationUnit(a,e,t)}},this.cleanUpAnimationUnit=(e,t,r)=>{e.mouseUpClientX=null,e.mouseUpClientY=null,e.mouseDownAnimateStartFrame=null,e.mouseDownAnimateCurrentFrame=null,e.mouseDownAnimateReleasedFrame=null,e.mouseDownAnimateLogicFrame=null,e.mousePressed=!1,e.mouseReleased=!1;const a=this.animationQueue.indexOf(e);-1<a&&this.animationQueue.splice(a,1),t||(r?e.clear(!1):this.mouseInBoundary?e.paint(!0):e.clear(!0))},this.getRevealAnimationConfig=()=>this.canvasList.find(e=>e.mouseInCanvas())||null,this.id=e,this.container=t}}class S{constructor(){if(this._currentHashId=0,this._storage=[],this.requestedTraverseBoundaries=!1,this.cachedMouseX=-1,this.cachedMouseY=-1,this.pointerLeaveScheduled=!1,this.handlePointerLeave=()=>{this.pointerLeaveScheduled||(this.pointerLeaveScheduled=!0,window.requestAnimationFrame(()=>{for(let e=0;e<this._storage.length;e++)this._storage[e].onPointerLeaveBoundary();this.pointerLeaveScheduled=!1}))},this.handlePointerMove=e=>{this.cachedMouseX=e.clientX,this.cachedMouseY=e.clientY,this.requestedTraverseBoundaries||(window.requestAnimationFrame(this.traverseBoundaries),this.requestedTraverseBoundaries=!0)},this.traverseBoundaries=()=>{this.requestedTraverseBoundaries=!1;for(let e=0;e<this._storage.length;e++)this._storage[e].onPointerMoveOnScreen(this.cachedMouseX,this.cachedMouseY)},this.newBoundary=e=>{const t=this._currentHashId++,r=new f(t,e);return this._storage.push(r),r},this.removeBoundary=e=>{this._storage=this._storage.filter(t=>t!==e)},"experimentalAutoFit"===c.borderDetectionMode){if("undefined"==typeof Window)return;window.addEventListener("pointermove",this.handlePointerMove),window.addEventListener("pointerup",e=>{"mouse"!==e.pointerType&&this.handlePointerLeave()}),window.addEventListener("pointerleave",e=>{"mouse"===e.pointerType&&this.handlePointerLeave()})}}}const b="undefined"==typeof globalThis.Window?class{constructor(){this.root={innerHTML:"",querySelector:()=>null},this.attachShadow=()=>null}}:HTMLElement;class x extends b{constructor(){super(...arguments),this.stateManager=new S}}x.ElementName="ax-reveal-provider";class F extends b{constructor(){/**
|
|
125
|
+
* Update the position of your pointer.
|
|
126
|
+
* @param ev Pointer event from the listener.
|
|
127
|
+
*/super(),this.root=this.attachShadow({mode:"open"}),this.updatePointerPosition=e=>{this.waitForStorage(t=>{t.clientX=e.clientX,t.clientY=e.clientY})},this.handlePointerEnter=()=>this.waitForStorage(e=>e.onPointerEnterBoundary()),this.handlePointerLeave=()=>this.waitForStorage(e=>e.onPointerLeaveBoundary()),this.handlePointerMove=this.updatePointerPosition,this.handlePointerUp=e=>{"mouse"===e.pointerType?this.waitForStorage(e=>e.switchAnimation()):this.waitForStorage(e=>e.clearAll(!1))},this.handlePointerDown=e=>this.waitForStorage(t=>{this.setPointerCapture(e.pointerId),this.updatePointerPosition(e),t.initializeAnimation()}),this.root.innerHTML=`
|
|
20
128
|
<div>
|
|
21
129
|
<slot></slot>
|
|
130
|
+
</div>`}get storage(){return this._storage}set storage(e){const t=this._storage;t&&(this.dispatchEvent(new CustomEvent(F.removeStorageEvent,{detail:t})),F.stateManager.removeBoundary(t)),e&&(this._storage=e,this.dispatchEvent(new CustomEvent(F.attachStorageEvent,{detail:e}))),t&&e&&this.dispatchEvent(new CustomEvent(F.replaceStorageEvent,{detail:{old:t,new:e}}))}waitForStorage(e){this.storage===void 0?this.addEventListener(F.attachStorageEvent,()=>e(this.storage),{once:!0}):e(this.storage)}appendStorage(e=!1){if(!e&&this.storage)return;const t=this.closest(x.ElementName),r=t?t.stateManager:F.stateManager;this.storage=r.newBoundary(this)}connectedCallback(){this.appendStorage(!0),"strictEdge"===c.borderDetectionMode&&(this.addEventListener("pointerenter",this.handlePointerEnter),this.addEventListener("pointerleave",this.handlePointerLeave),this.addEventListener("pointermove",this.handlePointerMove)),this.addEventListener("pointerdown",this.handlePointerDown),this.addEventListener("pointerup",this.handlePointerUp)}disconnectedCallback(){this.storage=void 0}}F.ElementName="ax-reveal-bound",F.removeStorageEvent="removeStorage",F.attachStorageEvent="attachStorage",F.replaceStorageEvent="replaceStorage",F.stateManager=new S;class P extends b{constructor(){super(),this.root=this.attachShadow({mode:"open"}),this.root.innerHTML=`
|
|
131
|
+
<div class="ax-reveal">
|
|
22
132
|
<canvas></canvas>
|
|
23
|
-
|
|
133
|
+
<div class="content"><slot></slot></div>
|
|
134
|
+
</div>
|
|
24
135
|
<style>
|
|
25
|
-
|
|
136
|
+
.ax-reveal { display: content; }
|
|
137
|
+
.ax-reveal * { user-drag: none; touch-action: none; user-select: none; }
|
|
138
|
+
.content { position: relative; }
|
|
26
139
|
canvas { top: 0; left: 0; pointer-events: none; width: 100%; height: 100%; position: absolute; }
|
|
27
140
|
:host { display: inline-block; position: relative; }
|
|
28
141
|
:host([block]) { display: block; }
|
|
@@ -31,5 +144,44 @@ this.clientX=-1e3,this.clientY=-1e3,this.paintedClientX=-1e3,this.paintedClientY
|
|
|
31
144
|
:host([inline-flex]) { display: inline-flex; }
|
|
32
145
|
:host([grid]) { display: grid; }
|
|
33
146
|
:host([inline-grid]) { display: inline-grid; }
|
|
147
|
+
::slotted(*) { user-drag: none; touch-action: none; }
|
|
148
|
+
::slotted(button) { outline:none; }
|
|
149
|
+
</style>`,this.canvas=this.root.querySelector("canvas")}adoptedCallback(){this.disconnectedCallback(),this.connectedCallback()}disconnectedCallback(){this.boundary&&this.boundary.waitForStorage(e=>e.removeReveal(this.canvas))}connectedCallback(){if(this.boundary=this.closest(F.ElementName),!this.boundary)throw new SyntaxError("You must use "+F.ElementName+" as the boundary of reveal highlight!");this.boundary.waitForStorage(e=>setTimeout(()=>e.addReveal(this.canvas,this),0))}}P.ElementName="ax-reveal";class C extends b{constructor(){super(),this.root=this.attachShadow({mode:"open"}),this.root.innerHTML=`
|
|
150
|
+
<div class="ax-reveal">
|
|
151
|
+
<svg>
|
|
152
|
+
<defs>
|
|
153
|
+
<radialGradient id="borderGrad" gradientUnits="userSpaceOnUse" r="10">
|
|
154
|
+
<stop id="borderCenter" offset="0%" />
|
|
155
|
+
<stop id="borderOut" offset="100%" />
|
|
156
|
+
</radialGradient>
|
|
157
|
+
<radialGradient id="fillGrad" gradientUnits="userSpaceOnUse" r="10">
|
|
158
|
+
<stop id="fillCenter" offset="0%" />
|
|
159
|
+
<stop id="fillOut" offset="100%" />
|
|
160
|
+
</radialGradient>
|
|
161
|
+
<radialGradient id="rippleGrad" gradientUnits="userSpaceOnUse" r="10">
|
|
162
|
+
<stop id="rippleCenter" offset="0%" />
|
|
163
|
+
<stop id="rippleMiddle" offset="0%" />
|
|
164
|
+
<stop id="rippleOut" offset="0%" />
|
|
165
|
+
</radialGradient>
|
|
166
|
+
</defs>
|
|
167
|
+
<path id="borderPath" fill="url(#borderGrad)" />
|
|
168
|
+
<path id="fillPath" fill="url(#fillGrad)" />
|
|
169
|
+
<path id="ripplePath" fill="url(#rippleGrad)" />
|
|
170
|
+
</svg>
|
|
171
|
+
<div class="content"><slot></slot></div>
|
|
172
|
+
</div>
|
|
173
|
+
<style>
|
|
174
|
+
.ax-reveal { display: content; }
|
|
175
|
+
.ax-reveal * { user-drag: none; touch-action: none; user-select: none; }
|
|
176
|
+
.content { position: relative; }
|
|
177
|
+
svg { top: 0; left: 0; pointer-events: none; width: 100%; height: 100%; position: absolute; }
|
|
178
|
+
:host { display: inline-block; position: relative; }
|
|
179
|
+
:host([block]) { display: block; }
|
|
180
|
+
:host([inline-block]) { display: inline-block; }
|
|
181
|
+
:host([flex]) { display: flex; }
|
|
182
|
+
:host([inline-flex]) { display: inline-flex; }
|
|
183
|
+
:host([grid]) { display: grid; }
|
|
184
|
+
:host([inline-grid]) { display: inline-grid; }
|
|
185
|
+
::slotted(*) { user-drag: none; touch-action: none; }
|
|
34
186
|
::slotted(button) { outline:none; }
|
|
35
|
-
</style>`,this.
|
|
187
|
+
</style>`,this.svg=this.root.querySelector("svg")}adoptedCallback(){this.disconnectedCallback(),this.connectedCallback()}disconnectedCallback(){this.boundary&&this.boundary.waitForStorage(e=>e.removeReveal(this.svg))}connectedCallback(){if(this.boundary=this.closest(F.ElementName),!this.boundary)throw new SyntaxError("You must use "+F.ElementName+" as the boundary of reveal highlight!");this.boundary.waitForStorage(e=>setTimeout(()=>e.addReveal(this.svg,this),0))}}C.ElementName="ax-reveal-ng";const w="magic";let B=!1;e.register=n,Object.defineProperty(e,"__esModule",{value:!0})});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractRGBValue.d.ts","sourceRoot":"","sources":["../../src/utils/extractRGBValue.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,MAAO,MAAM,WAyDxC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isValidateBorderDecorationType.d.ts","sourceRoot":"","sources":["../../src/utils/isValidateBorderDecorationType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,eAAO,MAAM,8BAA8B,MAAO,MAAM,0BAKvD,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
export declare type BorderDecoration = 'round' | 'bevel' | 'miter';
|
|
2
|
+
export interface CachedBoundingRect {
|
|
3
|
+
top: number;
|
|
4
|
+
left: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
}
|
|
8
|
+
export interface CachedStyle {
|
|
9
|
+
color: string;
|
|
10
|
+
opacity: number;
|
|
11
|
+
trueFillRadius: [number, number];
|
|
12
|
+
borderColor: string;
|
|
13
|
+
borderFillRadius: number;
|
|
14
|
+
borderDecorationType: BorderDecoration;
|
|
15
|
+
borderDecorationRadius: number;
|
|
16
|
+
topLeftBorderDecorationRadius: number;
|
|
17
|
+
topRightBorderDecorationRadius: number;
|
|
18
|
+
bottomLeftBorderDecorationRadius: number;
|
|
19
|
+
bottomRightBorderDecorationRadius: number;
|
|
20
|
+
/**
|
|
21
|
+
* @param withLeftBorderFactor
|
|
22
|
+
* If the left border is shown, this value is 1, or the value is 0.
|
|
23
|
+
*/
|
|
24
|
+
withLeftBorderFactor: number;
|
|
25
|
+
/**
|
|
26
|
+
* @param withRightBorderFactor
|
|
27
|
+
* If the right border is shown, this value is 1, or the value is 0.
|
|
28
|
+
*/
|
|
29
|
+
withRightBorderFactor: number;
|
|
30
|
+
/**
|
|
31
|
+
* @param withTopBorderFactor
|
|
32
|
+
* If the top border is shown, this value is 1, or the value is 0.
|
|
33
|
+
*/
|
|
34
|
+
withTopBorderFactor: number;
|
|
35
|
+
/**
|
|
36
|
+
* @param withBottomBorderFactor
|
|
37
|
+
* If the bottom border is shown, this value is 1, or the value is 0.
|
|
38
|
+
*/
|
|
39
|
+
withBottomBorderFactor: number;
|
|
40
|
+
borderWidth: number;
|
|
41
|
+
hoverLight: boolean;
|
|
42
|
+
hoverLightColor: string;
|
|
43
|
+
hoverLightFillMode: string;
|
|
44
|
+
hoverLightFillRadius: number;
|
|
45
|
+
diffuse: boolean;
|
|
46
|
+
pressAnimation: boolean;
|
|
47
|
+
pressAnimationFillMode: string;
|
|
48
|
+
pressAnimationColor: string;
|
|
49
|
+
pressAnimationSpeed: number;
|
|
50
|
+
releaseAnimationAccelerateRate: number;
|
|
51
|
+
}
|
|
52
|
+
interface CachedReveal {
|
|
53
|
+
radius: number;
|
|
54
|
+
radiusFactor: number;
|
|
55
|
+
color: string;
|
|
56
|
+
opacity: number;
|
|
57
|
+
pattern: CanvasPattern | null;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Cached border and body pattern, for faster painting on the canvas.
|
|
61
|
+
* @interface CachedRevealBitmap
|
|
62
|
+
*/
|
|
63
|
+
export interface CachedRevealBitmap {
|
|
64
|
+
cachedReveal: {
|
|
65
|
+
borderReveal: CachedReveal;
|
|
66
|
+
fillReveal: CachedReveal;
|
|
67
|
+
};
|
|
68
|
+
cachedCanvas: {
|
|
69
|
+
borderReveal: HTMLCanvasElement;
|
|
70
|
+
fillReveal: HTMLCanvasElement;
|
|
71
|
+
};
|
|
72
|
+
cachedCtx: {
|
|
73
|
+
borderReveal: CanvasRenderingContext2D | null;
|
|
74
|
+
fillReveal: CanvasRenderingContext2D | null;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Cached border and body pattern, just to store something in similar way.
|
|
79
|
+
* @interface CachedRevealPath
|
|
80
|
+
*/
|
|
81
|
+
export interface CachedRevealPath {
|
|
82
|
+
cachedReveal: {
|
|
83
|
+
readonly borderReveal: CachedReveal;
|
|
84
|
+
readonly fillReveal: CachedReveal;
|
|
85
|
+
};
|
|
86
|
+
cachedPath: {
|
|
87
|
+
readonly borderReveal: SVGPathElement;
|
|
88
|
+
readonly fillReveal: SVGPathElement;
|
|
89
|
+
readonly rippleReveal: SVGPathElement;
|
|
90
|
+
};
|
|
91
|
+
cachedGradient: {
|
|
92
|
+
readonly borderReveal: SVGRadialGradientElement;
|
|
93
|
+
readonly fillReveal: SVGRadialGradientElement;
|
|
94
|
+
readonly rippleReveal: SVGRadialGradientElement;
|
|
95
|
+
};
|
|
96
|
+
cachedGradientStop: {
|
|
97
|
+
readonly borderReveal: Readonly<[SVGStopElement, SVGStopElement]>;
|
|
98
|
+
readonly fillReveal: Readonly<[SVGStopElement, SVGStopElement]>;
|
|
99
|
+
readonly rippleReveal: Readonly<[SVGStopElement, SVGStopElement, SVGStopElement]>;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
export {};
|
|
103
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA,oBAAY,gBAAgB,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;AAE3D,MAAM,WAAW,kBAAkB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,oBAAoB,EAAE,gBAAgB,CAAC;IACvC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,6BAA6B,EAAE,MAAM,CAAC;IACtC,8BAA8B,EAAE,MAAM,CAAC;IACvC,gCAAgC,EAAE,MAAM,CAAC;IACzC,iCAAiC,EAAE,MAAM,CAAC;IAC1C;;;OAGG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,qBAAqB,EAAE,MAAM,CAAC;IAC9B;;;OAGG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,sBAAsB,EAAE,MAAM,CAAC;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,cAAc,EAAE,OAAO,CAAC;IACxB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,8BAA8B,EAAE,MAAM,CAAC;CAC1C;AAED,UAAU,YAAY;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,aAAa,GAAG,IAAI,CAAC;CACjC;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IAC/B,YAAY,EAAE;QACV,YAAY,EAAE,YAAY,CAAC;QAC3B,UAAU,EAAE,YAAY,CAAC;KAC5B,CAAC;IACF,YAAY,EAAE;QACV,YAAY,EAAE,iBAAiB,CAAC;QAChC,UAAU,EAAE,iBAAiB,CAAC;KACjC,CAAC;IACF,SAAS,EAAE;QACP,YAAY,EAAE,wBAAwB,GAAG,IAAI,CAAC;QAC9C,UAAU,EAAE,wBAAwB,GAAG,IAAI,CAAC;KAC/C,CAAC;CACL;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC7B,YAAY,EAAE;QACV,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;QACpC,QAAQ,CAAC,UAAU,EAAE,YAAY,CAAC;KACrC,CAAC;IACF,UAAU,EAAE;QACR,QAAQ,CAAC,YAAY,EAAE,cAAc,CAAC;QACtC,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAC;QACpC,QAAQ,CAAC,YAAY,EAAE,cAAc,CAAC;KACzC,CAAC;IACF,cAAc,EAAE;QACZ,QAAQ,CAAC,YAAY,EAAE,wBAAwB,CAAC;QAChD,QAAQ,CAAC,UAAU,EAAE,wBAAwB,CAAC;QAC9C,QAAQ,CAAC,YAAY,EAAE,wBAAwB,CAAC;KACnD,CAAC;IACF,kBAAkB,EAAE;QAChB,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC;QAClE,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC;QAChE,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC,cAAc,EAAE,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC;KACrF,CAAC;CACL"}
|