@elementalfx/dissolve 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +72 -2
- package/dist/dissolve.d.ts +18 -0
- package/dist/dissolve.d.ts.map +1 -0
- package/dist/dissolve.global.js +2 -0
- package/dist/filter.d.ts +29 -0
- package/dist/filter.d.ts.map +1 -0
- package/dist/global.d.ts +2 -0
- package/dist/global.d.ts.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +764 -0
- package/dist/index.js.map +7 -0
- package/dist/mask.d.ts +34 -0
- package/dist/mask.d.ts.map +1 -0
- package/dist/options.d.ts +39 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/particles.d.ts +28 -0
- package/dist/particles.d.ts.map +1 -0
- package/dist/snapshot.d.ts +21 -0
- package/dist/snapshot.d.ts.map +1 -0
- package/package.json +66 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 aviyer42
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,73 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @elementalfx/dissolve
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Make any element vanish in style. It can crumble into dust and blow away, burn with a glowing edge, melt down in drips, or fade through noise. `assemble()` brings it back the same way.
|
|
4
|
+
|
|
5
|
+
It works on cards, text, images, canvas and video. The browser keeps drawing the real element the whole time and an SVG filter masks it, so there's no screenshot that could look slightly off. About 7 KB gzipped.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @elementalfx/dissolve
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Use
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import { dissolve, assemble } from '@elementalfx/dissolve';
|
|
17
|
+
|
|
18
|
+
await dissolve('#card'); // crumbles into dust, then is hidden
|
|
19
|
+
await assemble('#card'); // the dust flies back
|
|
20
|
+
|
|
21
|
+
await dissolve(toast, { effect: 'burn' }); // burns from the bottom up
|
|
22
|
+
await dissolve(row, { effect: 'melt', after: 'remove' });
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Both return a promise that resolves when the animation is over. By default a dissolved element is hidden with `visibility: hidden`, so the layout doesn't jump. Pass `after: 'remove'` to take it out of the page instead.
|
|
26
|
+
|
|
27
|
+
### Script tag
|
|
28
|
+
|
|
29
|
+
```html
|
|
30
|
+
<script src="https://unpkg.com/@elementalfx/dissolve/dist/dissolve.global.js"></script>
|
|
31
|
+
<script>
|
|
32
|
+
ElementalFX.dissolve.dissolve('#card', { effect: 'burn' });
|
|
33
|
+
</script>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Effects
|
|
37
|
+
|
|
38
|
+
| Effect | What happens |
|
|
39
|
+
| --- | --- |
|
|
40
|
+
| `dust` | The element crumbles from one side into specks in its own colors, which blow away on a breeze (default) |
|
|
41
|
+
| `burn` | A glowing edge eats through it, leaving a charred band and sparks |
|
|
42
|
+
| `melt` | Each column drips down at its own pace while it fades |
|
|
43
|
+
| `fade` | A soft, blotchy fade |
|
|
44
|
+
|
|
45
|
+
## Options
|
|
46
|
+
|
|
47
|
+
| Option | Default | Description |
|
|
48
|
+
| --- | --- | --- |
|
|
49
|
+
| `effect` | `'dust'` | `'dust'`, `'burn'`, `'melt'` or `'fade'` |
|
|
50
|
+
| `duration` | 1.6 s | 2.2 s for burn, 1.8 s for melt, 1 s for fade. `0` hides or shows the element at once |
|
|
51
|
+
| `direction` | per effect | Which way the edge travels: `'right'`, `'left'`, `'up'`, `'down'` or `'none'` (blotches everywhere at once). Dust defaults to `'right'`, burn to `'up'`, fade to `'none'` |
|
|
52
|
+
| `noise` | `0.4` | How ragged the edge is, from 0 (a straight line) to 1 (blotches) |
|
|
53
|
+
| `scale` | `36` | Size of the blotches in px |
|
|
54
|
+
| `color` | `'#ff7a1a'` | Fire color for `burn` |
|
|
55
|
+
| `particles` | `1` | How many dust specks or sparks, as a multiple of the default |
|
|
56
|
+
| `grain` | `3` | Size of a dust speck in px |
|
|
57
|
+
| `after` | `'hide'` | `'hide'` keeps the element's space; `'remove'` takes it out of the page |
|
|
58
|
+
| `seed` | random | Same seed, same pattern |
|
|
59
|
+
| `respectReducedMotion` | `true` | A plain quick fade instead when the user prefers reduced motion |
|
|
60
|
+
|
|
61
|
+
Also exported: `isDissolved(element)`, which is true while `dissolve` has the element hidden.
|
|
62
|
+
|
|
63
|
+
## How it works
|
|
64
|
+
|
|
65
|
+
Each run builds a small noise texture that decides which spots vanish first, a sweep in one direction roughened by noise. The element gets an SVG filter that compares that texture against a moving threshold. Burning adds two more thresholds just ahead of the edge: one for a glowing band and one for a charred band. Melting uses a displacement map instead, where each column runs down by its own amount.
|
|
66
|
+
|
|
67
|
+
The dust needs to know the element's colors. For that, the package takes a small, low-resolution picture of it. Images, canvas and video are drawn directly; anything else is copied into an SVG `<foreignObject>` with its computed styles inlined. That picture only colors the specks, so if a web font or a cross-origin image doesn't make it in, a few specks come out the wrong color and the element itself still looks right. When no picture can be taken, the specks use the element's text and background colors.
|
|
68
|
+
|
|
69
|
+
Every speck leaves from the exact spot where the element disappears, because the specks and the filter read the same noise texture. `assemble` runs everything backwards: each speck flies in and lands on its spot just as that spot reappears.
|
|
70
|
+
|
|
71
|
+
Afterwards, the element's style attribute is exactly as it was.
|
|
72
|
+
|
|
73
|
+
MIT License
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type DissolveOptions } from './options.js';
|
|
2
|
+
type Target = Element | string;
|
|
3
|
+
/**
|
|
4
|
+
* Makes an element vanish: crumbling into dust, burning away, melting or
|
|
5
|
+
* fading. Resolves when it has gone. The element is then hidden (keeping
|
|
6
|
+
* its space) or removed, depending on `after`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function dissolve(target: Target, options?: DissolveOptions): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* The same effects in reverse: dust gathers into the element, a burn
|
|
11
|
+
* un-burns, a melt runs back up. Works on an element hidden by `dissolve`,
|
|
12
|
+
* or on one that is visible (it disappears first, then assembles).
|
|
13
|
+
*/
|
|
14
|
+
export declare function assemble(target: Target, options?: DissolveOptions): Promise<void>;
|
|
15
|
+
/** Whether `dissolve` has hidden this element. */
|
|
16
|
+
export declare function isDissolved(target: Target): boolean;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=dissolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dissolve.d.ts","sourceRoot":"","sources":["../src/dissolve.ts"],"names":[],"mappings":"AAGA,OAAO,EAA0C,KAAK,eAAe,EAAgC,MAAM,cAAc,CAAC;AAI1H,KAAK,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AA4B/B;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAErF;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAErF;AAED,kDAAkD;AAClD,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEnD"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! @elementalfx/dissolve v0.1.1 | MIT */
|
|
2
|
+
"use strict";var ElementalFX=ElementalFX||{};ElementalFX.dissolve=(()=>{var Z=Object.defineProperty;var Nt=Object.getOwnPropertyDescriptor;var Bt=Object.getOwnPropertyNames;var Ut=Object.prototype.hasOwnProperty;var Gt=(t,e)=>{for(var n in e)Z(t,n,{get:e[n],enumerable:!0})},$t=(t,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Bt(e))!Ut.call(t,i)&&i!==n&&Z(t,i,{get:()=>e[i],enumerable:!(s=Nt(e,i))||s.enumerable});return t};var Vt=t=>$t(Z({},"__esModule",{value:!0}),t);var le={};Gt(le,{activeSpecks:()=>xt,assemble:()=>Pt,dissolve:()=>Tt,isDissolved:()=>Ot,resolveOptions:()=>j});var N=typeof window<"u"&&typeof document<"u",jt="(prefers-reduced-motion: reduce)";function lt(){return N&&typeof window.matchMedia=="function"&&window.matchMedia(jt).matches}function ut(t=2){let e=N&&window.devicePixelRatio||1;return Math.max(1,Math.min(t,e))}function et(t){if(typeof t!="string")return t;let e=document.querySelector(t);if(!e)throw new Error(`[elementalfx] No element matches "${t}"`);return e}var P=new Set,D=0,H=0;function ft(t){D=0;let e=H?Math.min((t-H)/1e3,.1):1/60;H=t;for(let n of Array.from(P))try{n(e,t)}catch(s){P.delete(n),console.error("[elementalfx] An effect threw during a frame and was stopped.",s)}P.size>0?D=requestAnimationFrame(ft):H=0}function V(t){return P.add(t),D||(D=requestAnimationFrame(ft)),()=>{P.delete(t),P.size===0&&D&&(cancelAnimationFrame(D),D=0,H=0)}}function A(t=1){let e=t>>>0;return()=>{e=e+1831565813>>>0;let n=e;return n=Math.imul(n^n>>>15,n|1),n^=n+Math.imul(n^n>>>7,n|61),((n^n>>>14)>>>0)/4294967296}}var dt=new Uint8Array(512);{let t=A(1337),e=Array.from({length:256},(n,s)=>s);for(let n=255;n>0;n--){let s=Math.floor(t()*(n+1)),i=e[n];e[n]=e[s],e[s]=i}for(let n=0;n<512;n++)dt[n]=e[n&255]}function tt(t){return t*t*t*(t*(t*6-15)+10)}function C(t,e,n,s){let i=t&15,r=i<8?e:n,o=i<4?n:i===12||i===14?e:s;return((i&1)===0?r:-r)+((i&2)===0?o:-o)}function k(t,e,n){return t+(e-t)*n}function O(t,e,n){let s=Math.floor(t),i=Math.floor(e),r=Math.floor(n),o=s&255,c=i&255,a=r&255;t-=s,e-=i,n-=r;let m=tt(t),u=tt(e),f=tt(n),d=dt,g=d[o]+c,y=d[g]+a,b=d[g+1]+a,p=d[o+1]+c,l=d[p]+a,h=d[p+1]+a;return k(k(k(C(d[y],t,e,n),C(d[l],t-1,e,n),m),k(C(d[b],t,e-1,n),C(d[h],t-1,e-1,n),m),u),k(k(C(d[y+1],t,e,n-1),C(d[l+1],t-1,e,n-1),m),k(C(d[b+1],t,e-1,n-1),C(d[h+1],t-1,e-1,n-1),m),u),f)}var st="http://www.w3.org/2000/svg",B=null,zt=0;function Xt(){if(B?.isConnected)return B;let t=document.createElementNS(st,"svg");return t.setAttribute("aria-hidden","true"),t.setAttribute("data-fx","dissolve"),t.setAttribute("width","0"),t.setAttribute("height","0"),t.style.cssText="position:absolute;width:0;height:0;overflow:hidden;pointer-events:none",B=document.createElementNS(st,"defs"),t.append(B),document.body.append(t),B}function v(t,e,n){let s=document.createElementNS(st,e);for(let[i,r]of Object.entries(n))s.setAttribute(i,String(r)),i==="href"&&s.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",String(r));return t.append(s),s}function nt(t,e,n,s){let i=v(t,"feComponentTransfer",{in:e,result:n});return v(i,"feFuncA",{type:"linear",slope:s,intercept:0})}function ht(t){let{effect:e,width:n,height:s}=t,i=`fx-dissolve-${++zt}`,r=Math.ceil(Math.max(n,s)*.1)+8,o=t.reach??1,c=v(Xt(),"filter",{id:i,filterUnits:"userSpaceOnUse",primitiveUnits:"userSpaceOnUse",x:-r,y:-r,width:n+r*2,height:(e==="melt"?s*o:s)+r*2,"color-interpolation-filters":"sRGB"}),a=e==="fade"?.12:.02,m=1/a,u=.045,f=[],d=null,g=null;if(e==="melt"){v(c,"feImage",{href:t.drip,x:0,y:0,width:n,height:s*o,preserveAspectRatio:"none",result:"drip"}),d=v(c,"feDisplacementMap",{in:"SourceGraphic",in2:"drip",scale:0,xChannelSelector:"R",yChannelSelector:"G",result:"moved"}),v(c,"feFlood",{"flood-color":"#fff",x:0,y:0,width:n,height:s*o,result:"columns"}),v(c,"feComposite",{in:"moved",in2:"columns",operator:"in",result:"melted"});let p=v(c,"feComponentTransfer",{in:"melted"});g=v(p,"feFuncA",{type:"linear",slope:1,intercept:0})}else if(v(c,"feImage",{href:t.mask,x:0,y:0,width:n,height:s,preserveAspectRatio:"none",result:"mask"}),f.push({func:nt(c,"mask","alive",m),offset:0}),e==="burn"){f.push({func:nt(c,"mask","inner",m),offset:u}),f.push({func:nt(c,"mask","core",m),offset:u*2.5}),v(c,"feComposite",{in:"alive",in2:"inner",operator:"out",result:"hotBand"}),v(c,"feComposite",{in:"inner",in2:"core",operator:"out",result:"charBand"}),v(c,"feComposite",{in:"SourceGraphic",in2:"core",operator:"in",result:"intact"}),v(c,"feColorMatrix",{in:"SourceGraphic",type:"matrix",values:"0.25 0 0 0 0.04 0 0.18 0 0 0.02 0 0 0.14 0 0.01 0 0 0 1 0",result:"dark"}),v(c,"feComposite",{in:"dark",in2:"charBand",operator:"in",result:"charred"}),v(c,"feFlood",{"flood-color":t.color,result:"flame"}),v(c,"feComposite",{in:"flame",in2:"hotBand",operator:"in",result:"hot0"}),v(c,"feComposite",{in:"hot0",in2:"SourceAlpha",operator:"in",result:"hot"}),v(c,"feGaussianBlur",{in:"hot",stdDeviation:3,result:"glow"});let p=v(c,"feMerge",{});for(let l of["glow","intact","charred","hot"])v(p,"feMergeNode",{in:l})}else v(c,"feComposite",{in:"SourceGraphic",in2:"alive",operator:"in"});let y=e==="burn"?-(u*2.5+a):-a,b=1+a;return{id:i,start:y,end:b,set(p){for(let{func:l,offset:h}of f)l.setAttribute("intercept",String(-m*(p+h)))},melt(p,l){d?.setAttribute("scale",String(p*2)),g?.setAttribute("slope",String(l))},destroy(){c.remove()}}}function _t(t,e,n){let s=0,i=.5,r=1;for(let o=0;o<3;o++)s+=i*O(t*r,e*r,n+o*7.31),i*=.5,r*=2.03;return s}function Wt(t,e,n){switch(t){case"right":return e;case"left":return 1-e;case"down":return n;case"up":return 1-n;default:return 0}}function mt(t,e,n){let s=document.createElement("canvas");s.width=t,s.height=e;let i=s.getContext("2d"),r=i.createImageData(t,e);return n(r.data),i.putImageData(r,0,0),s.toDataURL("image/png")}function pt(t,e,n){let s=Math.max(4,Math.ceil(Math.max(t,e)/256)),i=Math.max(2,Math.ceil(t/s)),r=Math.max(2,Math.ceil(e/s)),o=new Float32Array(i*r),c=A(n.seed),a=c()*100,m=c()*1e3,u=c()*1e3,f=n.direction==="none"?1:n.noise,d=s/n.scale,g=1/0,y=-1/0;for(let l=0;l<r;l++)for(let h=0;h<i;h++){let M=_t(m+h*d,u+l*d,a)*.9+.5,x=(1-f)*Wt(n.direction,h/(i-1),l/(r-1))+f*M;o[l*i+h]=x,x<g&&(g=x),x>y&&(y=x)}let b=y-g||1;for(let l=0;l<o.length;l++)o[l]=(o[l]-g)/b;let p=mt(i,r,l=>{for(let h=0;h<o.length;h++)l[h*4]=255,l[h*4+1]=255,l[h*4+2]=255,l[h*4+3]=Math.round(o[h]*255)});return{width:t,height:e,step:s,columns:i,rows:r,values:o,url:p,at(l,h){let M=Math.min(i-1,Math.max(0,Math.floor(l/s))),x=Math.min(r-1,Math.max(0,Math.floor(h/s)));return o[x*i+M]}}}function gt(t,e,n,s){let i=Math.max(4,Math.ceil(Math.max(t,e*n)/256)),r=Math.max(2,Math.ceil(t/i)),o=Math.max(2,Math.ceil(e*n/i)),a=A(s)()*100,m=new Float32Array(r);for(let u=0;u<r;u++){let f=O(u*i/18,a,.5)*.55+O(u*i/60,a,3.1)*.45+.5;m[u]=.15+.85*Math.pow(Math.min(1,Math.max(0,f)),2.4)}return mt(r,o,u=>{for(let f=0;f<o;f++){let d=Math.min(1,f*i/e);for(let g=0;g<r;g++){let y=m[g]*Math.pow(d,1.3),b=(f*r+g)*4;u[b]=128,u[b+1]=Math.round(128-y*127),u[b+2]=128,u[b+3]=255}}})}var bt={dust:1.6,burn:2.2,melt:1.8,fade:1},qt={dust:"right",burn:"up",melt:"down",fade:"none"};function j(t={}){let e=t.effect&&t.effect in bt?t.effect:"dust";return{effect:e,duration:Math.max(0,t.duration??bt[e]),direction:t.direction??qt[e],noise:Math.min(1,Math.max(0,t.noise??.4)),scale:Math.max(4,t.scale??36),color:t.color??"#ff7a1a",particles:Math.max(0,t.particles??1),grain:Math.max(1,t.grain??3),after:t.after==="remove"?"remove":"hide",seed:t.seed??Math.floor(Math.random()*2**31),respectReducedMotion:t.respectReducedMotion??!0}}var Yt=12e3,L=[],w=null,U=null,z=null,R=1,yt=0;function vt(){return U&&w?.isConnected||(w=document.createElement("canvas"),w.setAttribute("aria-hidden","true"),w.setAttribute("data-fx","dissolve"),w.style.cssText="position:fixed;left:0;top:0;width:100vw;height:100vh;pointer-events:none;z-index:2147483000",document.body.append(w),U=w.getContext("2d"),it()),U}function it(){if(!w)return;R=ut(2);let t=document.documentElement.clientWidth,e=document.documentElement.clientHeight;w.width=Math.round(t*R),w.height=Math.round(e*R)}function ot(t){if(t.length===0||typeof document>"u")return;let e=Yt-L.length;e<=0||(L.push(...t.length>e?t.slice(0,e):t),vt(),z||(window.addEventListener("resize",it),z=V(Kt)))}function xt(){return L.length}function Kt(t){yt+=t;let e=vt(),n=w.width,s=w.height;e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,n,s),e.setTransform(R,0,0,R,-window.scrollX*R,-window.scrollY*R);let i=[],r=[];for(let o of L){if(o.delay&&o.delay>0){o.delay-=t,i.push(o);continue}if(o.age+=t,o.age>=o.life)continue;i.push(o);let c=o.age/o.life,a,m=o.size;if(o.kind==="gather"){let u=1-Math.pow(1-c,3);o.x=o.x0+(o.x1-o.x0)*u,o.y=o.y0+(o.y1-o.y0)*u+Math.sin(c*Math.PI)*-18,a=Math.min(1,c*3)}else{let u=O(o.x*.01,o.y*.01,yt*.6)*140;o.vx+=u*t,o.vy+=(o.kind==="spark"?-220:-40)*t;let f=Math.exp(-(o.kind==="spark"?1.2:.6)*t);o.vx*=f,o.vy*=f,o.x+=o.vx*t,o.y+=o.vy*t,a=1-c*c,m*=o.kind==="spark"?1-c*.7:1-c*.5}if(o.kind==="spark"){r.push(o);continue}e.globalAlpha=a,e.fillStyle=o.color,e.fillRect(o.x-m/2,o.y-m/2,m,m)}if(r.length){e.globalCompositeOperation="lighter";for(let o of r){let c=o.age/o.life,a=o.size*(1-c*.7);e.fillStyle=o.color,e.globalAlpha=(1-c)*.25,e.fillRect(o.x-a*1.5,o.y-a*1.5,a*3,a*3),e.globalAlpha=1-c,e.fillRect(o.x-a/2,o.y-a/2,a,a)}e.globalCompositeOperation="source-over"}e.globalAlpha=1,L=i,L.length===0&&(z?.(),z=null,window.removeEventListener("resize",it),w?.remove(),w=null,U=null)}var Mt="http://www.w3.org/1999/xhtml";var Jt=new Set(["SCRIPT","STYLE","LINK","TEMPLATE","NOSCRIPT","IFRAME","OBJECT","EMBED"]);function rt(t,e,n){try{let s=document.createElement("canvas");s.width=e,s.height=n;let i=s.getContext("2d",{willReadFrequently:!0});return i.drawImage(t,0,0,e,n),{columns:e,rows:n,data:i.getImageData(0,0,e,n).data}}catch{return null}}function Qt(t,e,n){try{if(t instanceof HTMLCanvasElement)return t.toDataURL();let s=document.createElement("canvas"),i=Math.min(1,256/Math.max(e,n,1));return s.width=Math.max(1,Math.round(e*i)),s.height=Math.max(1,Math.round(n*i)),s.getContext("2d").drawImage(t,0,0,s.width,s.height),s.toDataURL()}catch{return""}}function wt(t){let e=getComputedStyle(t),n="";for(let s=0;s<e.length;s++){let i=e[s];n+=`${i}:${e.getPropertyValue(i)};`}return n}function Et(t,e){if(--e.left<0)return null;let n=t.tagName.toUpperCase();if(t instanceof SVGElement)return t.cloneNode(!0);if(t instanceof HTMLImageElement||t instanceof HTMLCanvasElement||t instanceof HTMLVideoElement){let i=document.createElementNS(Mt,"img");return i.setAttribute("style",wt(t)),i.setAttribute("src",Qt(t,t.offsetWidth,t.offsetHeight)),i}let s=document.createElementNS(Mt,t.localName);s.setAttribute("style",wt(t)),(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement)&&s.setAttribute("value",t.value);for(let i of t.childNodes)if(i.nodeType===3)s.append(i.textContent??"");else if(i.nodeType===1&&!Jt.has(i.tagName.toUpperCase())){let r=Et(i,e);if(!r)return null;s.append(r)}return n==="TEXTAREA"&&(s.textContent=t.value),s}function Zt(t,e){return new Promise(n=>{let s=new Image,i=setTimeout(()=>n(null),e);s.onload=()=>{clearTimeout(i),n(s)},s.onerror=()=>{clearTimeout(i),n(null)},s.src=t})}async function St(t,e,n,s,i){if(t instanceof HTMLImageElement)return!t.complete||t.naturalWidth===0?null:rt(t,s,i);if(t instanceof HTMLCanvasElement||t instanceof HTMLVideoElement)return rt(t,s,i);let r=Et(t,{left:800});if(!r)return null;r.style.setProperty("margin","0"),r.style.setProperty("position","static"),r.style.setProperty("transform","none"),r.style.setProperty("filter","none"),r.style.setProperty("opacity","1"),r.style.setProperty("visibility","visible"),r.style.setProperty("width",`${e}px`),r.style.setProperty("height",`${n}px`),r.style.setProperty("box-sizing","border-box");let o=new XMLSerializer().serializeToString(r),c=`<svg xmlns="http://www.w3.org/2000/svg" width="${e}" height="${n}"><foreignObject x="0" y="0" width="100%" height="100%">${o}</foreignObject></svg>`,a=await Zt(`data:image/svg+xml;charset=utf-8,${encodeURIComponent(c)}`,1500);return a?rt(a,s,i):null}var G=new WeakMap,X=new WeakMap,q=new WeakMap;function At(t){q.has(t)||q.set(t,{attribute:t.getAttribute("style"),css:t.style.cssText})}function Rt(t){let e=q.get(t);!e||t.style.cssText!==e.css||(q.delete(t),t.getAttribute("style"),e.attribute===null?t.removeAttribute("style"):t.setAttribute("style",e.attribute))}var Ct=1.6,te=6e3;function Tt(t,e={}){return Lt(t,e,!1)}function Pt(t,e={}){return Lt(t,e,!0)}function Ot(t){return N&&G.has(et(t))}function ee(t){At(t),G.has(t)||G.set(t,[t.style.getPropertyValue("visibility"),t.style.getPropertyPriority("visibility")]),t.style.setProperty("visibility","hidden","important")}function _(t){let e=G.get(t);e&&(G.delete(t),e[0]?t.style.setProperty("visibility",e[0],e[1]):t.style.removeProperty("visibility"),Rt(t))}function ne(t){switch(t){case"right":return[1,0];case"left":return[-1,0];case"up":return[0,-1];case"down":return[0,1];default:return[0,0]}}function kt(t){let e=t.match(/rgba?\(([^)]+)\)/);if(!e)return null;let n=e[1].split(/[\s,/]+/).filter(Boolean).map(Number);return[n[0]??0,n[1]??0,n[2]??0,n.length>3?n[3]:1]}async function se(t,e,n,s,i){let r=i.grain;for(;e/r*(n/r)>6e4;)r*=1.5;let o=Math.max(1,Math.ceil(e/r)),c=Math.max(1,Math.ceil(n/r)),a=await St(t,e,n,o,c),m=A(i.seed^1540483477),u=[];if(a){let{data:b}=a;for(let p=0;p<c;p++)for(let l=0;l<o;l++){let h=(p*o+l)*4;if(b[h+3]<40)continue;let x=b[h],S=b[h+1],E=b[h+2],T=(l+.5)*r,I=(p+.5)*r;u.push({x:T,y:I,at:s.at(T,I),color:`rgb(${x},${S},${E})`})}return u}let f=getComputedStyle(t),d=kt(f.backgroundColor),g=kt(f.color)??[40,40,40,1],y=d&&d[3]>.1;for(let b=0;b<c;b++)for(let p=0;p<o;p++){if(!y&&m()>.3)continue;let[l,h,M]=y&&m()>.15?d:g,x=(p+.5)*r,S=(b+.5)*r;u.push({x,y:S,at:s.at(x,S),color:`rgb(${l},${h},${M})`})}return u}async function Lt(t,e,n){if(!N)return;let s=et(t);X.get(s)?.();let i=j(e);if(i.duration===0){n?_(s):W(s,i);return}if(i.respectReducedMotion&<()){n&&_(s),await s.animate?.([{opacity:n?0:1},{opacity:n?1:0}],{duration:250,easing:"ease"})?.finished.catch(()=>{}),n||W(s,i);return}let r=s,o=s.getBoundingClientRect(),c=r.offsetWidth||o.width,a=r.offsetHeight||o.height;if(c<1||a<1){n?_(s):W(s,i);return}let m=i.effect==="melt",u=m?null:pt(c,a,i),f=ht({effect:i.effect,width:c,height:a,mask:u?.url??"",drip:m?gt(c,a,Ct,i.seed):void 0,reach:Ct,color:i.color}),d=[s.style.getPropertyValue("filter"),s.style.getPropertyPriority("filter")],g=getComputedStyle(s).filter,y=p=>{if(m){let l=n?1-p:p;f.melt(a*1.8*l*l,1-ce(.5,1,l))}else{let l=n?1-p:p;f.set(f.start+(f.end-f.start)*l)}};y(0),At(s),s.style.setProperty("filter",`url(#${f.id})${g&&g!=="none"?` ${g}`:""}`,"important"),n&&_(s),await ae(u?.url);let b=u&&(i.effect==="dust"||i.effect==="burn")&&i.particles>0?await se(s,c,a,u,i):[];return new Promise(p=>{let l=0,h=null,M=A(i.seed^668265263),[x,S]=ne(i.direction),E=b.sort((K,F)=>K.at-F.at),T=0,I=E.length?Math.min(1,te*i.particles/E.length):0,Y=()=>{X.get(s)===Y&&X.delete(s),h?.(),h=null,f.destroy(),d[0]?s.style.setProperty("filter",d[0],d[1]):s.style.removeProperty("filter"),Rt(s),n||W(s,i),p()};X.set(s,Y),n&&i.effect==="dust"&&re(s,E,I,i,x,S,f,M),h=V(K=>{l+=K;let F=Math.min(1,l/i.duration);if(y(F),!n&&E.length){let It=f.start+(f.end-f.start)*F,$=s.getBoundingClientRect(),Ft=$.width/c,Ht=$.height/a,J=[];for(;T<E.length&&E[T].at<=It;){let Q=E[T++],ct=$.left+window.scrollX+Q.x*Ft,at=$.top+window.scrollY+Q.y*Ht;i.effect==="burn"?oe(J,ct,at,i,M):M()<I&&J.push(ie(Q,ct,at,i,x,S,c,a,M))}ot(J)}F>=1&&Y()})})}function ie(t,e,n,s,i,r,o,c,a){let m=i,u=r;if(m===0&&u===0){let d=t.x-o/2,g=t.y-c/2,y=Math.hypot(d,g)||1;m=d/y,u=g/y}let f=50+a()*150;return{x:e,y:n,vx:m*f+(a()-.5)*70,vy:u*f+(a()-.5)*70-30-a()*60,age:0,life:.8+a()*1.1,size:s.grain*(.7+a()*.6),color:t.color,kind:"dust"}}var Dt=["#fff3b0","#ffd166","#ff9f1c","#ff6b00"];function oe(t,e,n,s,i){let r=i();r<.03*s.particles?t.push({x:e,y:n,vx:(i()-.5)*90,vy:-60-i()*160,age:0,life:.5+i()*.9,size:1.5+i()*2,color:Dt[Math.floor(i()*Dt.length)],kind:"spark"}):r<.03*s.particles+.06*s.particles&&t.push({x:e,y:n,vx:(i()-.5)*40,vy:-20-i()*50,age:0,life:.6+i()*.8,size:s.grain*(.6+i()*.5),color:"#2b211c",kind:"dust"})}function re(t,e,n,s,i,r,o,c){let a=t.getBoundingClientRect(),m=t,u=a.width/(m.offsetWidth||a.width),f=a.height/(m.offsetHeight||a.height),d=o.end-o.start,g=[];for(let y of e){if(c()>=n)continue;let b=(o.end-y.at)/d*s.duration,p=Math.min(b,.6+c()*.6);if(p<.05)continue;let l=a.left+window.scrollX+y.x*u,h=a.top+window.scrollY+y.y*f,M=i,x=r;if(M===0&&x===0){let E=c()*Math.PI*2;M=Math.cos(E),x=Math.sin(E)}let S=80+c()*180;g.push({x:l,y:h,vx:0,vy:0,age:0,life:p,delay:b-p,size:s.grain*(.7+c()*.6),color:y.color,kind:"gather",x0:l+M*S+(c()-.5)*60,y0:h+x*S+(c()-.5)*60-30,x1:l,y1:h})}ot(g)}function W(t,e){e.after==="remove"?t.remove():ee(t)}function ce(t,e,n){let s=Math.min(1,Math.max(0,(n-t)/(e-t)));return s*s*(3-2*s)}function ae(t){if(!t)return Promise.resolve();let e=new Image;return e.src=t,e.decode().catch(()=>{})}return Vt(le);})();
|
package/dist/filter.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { DissolveEffect } from './options.js';
|
|
2
|
+
export interface DissolveFilter {
|
|
3
|
+
/** Use as `filter: url(#id)`. */
|
|
4
|
+
readonly id: string;
|
|
5
|
+
/** Where the vanishing edge is, in mask units: below 0 shows everything, past 1 hides everything. */
|
|
6
|
+
readonly start: number;
|
|
7
|
+
readonly end: number;
|
|
8
|
+
set(edge: number): void;
|
|
9
|
+
/** For melting: how far content has run (px) and how opaque it still is. */
|
|
10
|
+
melt(distance: number, opacity: number): void;
|
|
11
|
+
destroy(): void;
|
|
12
|
+
}
|
|
13
|
+
export interface FilterSetup {
|
|
14
|
+
effect: DissolveEffect;
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
mask: string;
|
|
18
|
+
drip?: string;
|
|
19
|
+
/** How far below the element melted content can run, as a multiple of its height. */
|
|
20
|
+
reach?: number;
|
|
21
|
+
color: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Builds the SVG filter that does the vanishing. The mask image is compared
|
|
25
|
+
* against a moving threshold with steep linear transfer functions; burning
|
|
26
|
+
* adds a glowing band and a charred band just ahead of the edge.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createFilter(setup: FilterSetup): DissolveFilter;
|
|
29
|
+
//# sourceMappingURL=filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../src/filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAsCnD,MAAM,WAAW,cAAc;IAC7B,iCAAiC;IACjC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,qGAAqG;IACrG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,4EAA4E;IAC5E,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9C,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,cAAc,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qFAAqF;IACrF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,WAAW,GAAG,cAAc,CA4E/D"}
|
package/dist/global.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global.d.ts","sourceRoot":"","sources":["../src/global.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { dissolve, assemble, isDissolved } from './dissolve.js';
|
|
2
|
+
export { resolveOptions, type DissolveOptions, type DissolveEffect, type DissolveDirection, type ResolvedDissolveOptions } from './options.js';
|
|
3
|
+
export { activeSpecks } from './particles.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,KAAK,iBAAiB,EAAE,KAAK,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAC/I,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|