@petit-kit/scoped 0.0.6 → 0.0.8-beta.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/README.md +92 -33
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +693 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -1
- package/dist/plugins/content/index.d.ts +1 -0
- package/dist/plugins/content/index.d.ts.map +1 -0
- package/dist/plugins/device/index.d.ts +8 -0
- package/dist/plugins/device/index.d.ts.map +1 -0
- package/dist/plugins/index.d.ts +12 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/inview/index.d.ts +63 -0
- package/dist/plugins/inview/index.d.ts.map +1 -0
- package/dist/plugins/lenis/index.d.ts +37 -0
- package/dist/plugins/lenis/index.d.ts.map +1 -0
- package/dist/plugins/lerp/index.d.ts +42 -0
- package/dist/plugins/lerp/index.d.ts.map +1 -0
- package/dist/plugins/localstorage/index.d.ts +57 -0
- package/dist/plugins/localstorage/index.d.ts.map +1 -0
- package/dist/plugins/morph/index.d.ts +92 -0
- package/dist/plugins/morph/index.d.ts.map +1 -0
- package/dist/plugins/mouse/index.d.ts +91 -0
- package/dist/plugins/mouse/index.d.ts.map +1 -0
- package/dist/plugins/pointer/index.d.ts +59 -0
- package/dist/plugins/pointer/index.d.ts.map +1 -0
- package/dist/plugins/spring/index.d.ts +42 -0
- package/dist/plugins/spring/index.d.ts.map +1 -0
- package/dist/plugins/timer/index.d.ts +82 -0
- package/dist/plugins/timer/index.d.ts.map +1 -0
- package/dist/plugins/window/index.d.ts +14 -0
- package/dist/plugins/window/index.d.ts.map +1 -0
- package/package.json +13 -11
package/README.md
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
<br />
|
|
2
2
|
|
|
3
|
-
<
|
|
4
|
-
<
|
|
5
|
-
|
|
3
|
+
<div style="border-radius=30px; overflow: hidden;">
|
|
4
|
+
<p align="center">
|
|
5
|
+
<img src='https://github.com/petit-kit/scoped/blob/main/assets/logo.svg?raw=true' />
|
|
6
|
+
</p>
|
|
7
|
+
</div>
|
|
6
8
|
<br />
|
|
7
9
|
<br />
|
|
8
10
|
|
|
9
|
-
# Scoped - 0.0.
|
|
11
|
+
# Scoped - 0.0.8-beta.1
|
|
10
12
|
|
|
11
13
|
### A lightweight, framework-agnostic library for building web components with reactive state, bindings, lifecycle hooks, template-based rendering and plugins.
|
|
12
14
|
|
|
@@ -74,19 +76,25 @@ define(
|
|
|
74
76
|
};
|
|
75
77
|
|
|
76
78
|
return () => `
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
79
|
+
<div>
|
|
80
|
+
<input
|
|
81
|
+
type="range" min="0" max="360" step="1"
|
|
82
|
+
bind:value="value"
|
|
83
|
+
on:input="handleChange"
|
|
84
|
+
/>
|
|
85
|
+
<c-number ref="number" bind:value="value"></c-number>
|
|
86
|
+
</div>
|
|
87
|
+
`;
|
|
86
88
|
}
|
|
87
89
|
);
|
|
88
90
|
```
|
|
89
91
|
|
|
92
|
+
And you just have to call the component in the DOM like so:
|
|
93
|
+
|
|
94
|
+
```xml
|
|
95
|
+
<c-slider value="5"></c-slider>
|
|
96
|
+
```
|
|
97
|
+
|
|
90
98
|
The `define()` function is used to declare a new component.
|
|
91
99
|
|
|
92
100
|
```typescript
|
|
@@ -189,6 +197,18 @@ Interpolation with `${...}` gives you access to state, props, or anything in clo
|
|
|
189
197
|
};
|
|
190
198
|
```
|
|
191
199
|
|
|
200
|
+
### XSS
|
|
201
|
+
|
|
202
|
+
When interpolating **user-provided** or untrusted content, use `escapeHtml` to prevent XSS. It escapes `&`, `<`, `>`, `"`, and `'` so the content is safe in HTML context.
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
({ escapeHtml }) => {
|
|
206
|
+
return () => `<span>${escapeHtml(userInput)}</span>`;
|
|
207
|
+
};
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
`escapeHtml` accepts any value (falsy values return empty string) and returns a string safe for HTML. Do **not** use it with content you control and intend as markup — for that, use `bind:html` instead.
|
|
211
|
+
|
|
192
212
|
### Event Handlers
|
|
193
213
|
|
|
194
214
|
Use `on:eventName="handler"` to bind events, where **handler** is a function from your **actions** object or setup context:
|
|
@@ -478,14 +498,50 @@ define('my-card', {}, () => {
|
|
|
478
498
|
|
|
479
499
|
Lifecycle hooks let you run code at specific moments in the component's life, such as mount, update, or destruction.
|
|
480
500
|
|
|
481
|
-
| Method | Description
|
|
482
|
-
| ------------------------ |
|
|
483
|
-
| **`onMount(cb)`** | After mount
|
|
484
|
-
| **`onDestroy(cb)`** | On destroy
|
|
485
|
-
| **`onUpdate(cb)`** | After each update
|
|
486
|
-
| **`onBeforeUpdate(cb)`** | Before each update
|
|
487
|
-
| **`onFirstUpdate(cb)`** | Once, after first render
|
|
488
|
-
| **`onPropsChanged(cb)`** | When props change
|
|
501
|
+
| Method | Description |
|
|
502
|
+
| ------------------------ | ------------------------- |
|
|
503
|
+
| **`onMount(cb)`** | After mount |
|
|
504
|
+
| **`onDestroy(cb)`** | On destroy |
|
|
505
|
+
| **`onUpdate(cb)`** | After each update |
|
|
506
|
+
| **`onBeforeUpdate(cb)`** | Before each update |
|
|
507
|
+
| **`onFirstUpdate(cb)`** | Once, after first render |
|
|
508
|
+
| **`onPropsChanged(cb)`** | When props change |
|
|
509
|
+
| **`shouldRender(cb)`** | Conditionally skip render |
|
|
510
|
+
|
|
511
|
+
<br/>
|
|
512
|
+
|
|
513
|
+
### shouldRender
|
|
514
|
+
|
|
515
|
+
Register a predicate to conditionally skip full renders. When the callback returns `false`, the template is not executed and the DOM is not updated. Effects and `onUpdate` hooks still run.
|
|
516
|
+
|
|
517
|
+
The callback receives a context object:
|
|
518
|
+
|
|
519
|
+
| Property | Type | Description |
|
|
520
|
+
| ----------------- | ----------- | ------------------------------------------------ |
|
|
521
|
+
| **`reason`** | `string` | `'mount'` \| `'props'` \| `'state'` \| `'force'` |
|
|
522
|
+
| **`changedKeys`** | `string[]?` | For props/state: which keys changed |
|
|
523
|
+
|
|
524
|
+
<br />
|
|
525
|
+
|
|
526
|
+
```typescript
|
|
527
|
+
define('c-lazy-list', {}, ({ shouldRender, state, props }) => {
|
|
528
|
+
state.paused = false;
|
|
529
|
+
|
|
530
|
+
shouldRender((ctx) => {
|
|
531
|
+
// Always render on props change
|
|
532
|
+
if (ctx.reason === 'props') return true;
|
|
533
|
+
// Skip state updates when tab is hidden (e.g. scroll position)
|
|
534
|
+
if (ctx.reason === 'state' && document.visibilityState === 'hidden')
|
|
535
|
+
return false;
|
|
536
|
+
// Skip specific state keys
|
|
537
|
+
if (ctx.reason === 'state' && ctx.changedKeys?.includes('scrollY'))
|
|
538
|
+
return false;
|
|
539
|
+
return true;
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
return () => `<ul>${props.items.map((i) => `<li>${i}</li>`).join('')}</ul>`;
|
|
543
|
+
});
|
|
544
|
+
```
|
|
489
545
|
|
|
490
546
|
## Select
|
|
491
547
|
|
|
@@ -518,37 +574,40 @@ define('c-my-component', {}, ({ $, host }) => {
|
|
|
518
574
|
|
|
519
575
|
Scoped includes a set of optional plugins to extend or enhance component behavior. You can import any of these plugins and register them via the `plugins` option.
|
|
520
576
|
|
|
521
|
-
⏲
|
|
577
|
+
⏲ Plugins documentation is working in progress
|
|
522
578
|
|
|
523
579
|
**Available Plugins:**
|
|
524
580
|
|
|
525
|
-
-
|
|
526
|
-
Adds a reactive spring physics engine for animating values with natural, spring-like motion. Powered by
|
|
581
|
+
- **<a href="https://github.com/petit-kit/scoped/tree/main/src/plugins/lerp/README.md" target="_blank">lerpPlugin</a> & <a href="https://github.com/petit-kit/scoped/tree/main/src/plugins/spring/README.md" target="_blank">springPlugin</a>**
|
|
582
|
+
Adds a reactive spring physics engine for animating values with natural, spring-like motion. Powered by <a href="https://github.com/petit-kit/animate" target="_blank">@petit-kit/animate</a>. Integrates seamlessly with the timer plugin for requestAnimationFrame-based updates.
|
|
527
583
|
|
|
528
|
-
-
|
|
584
|
+
- **<a href="https://github.com/petit-kit/scoped/tree/main/src/plugins/morph/README.md" target="_blank">morphPlugin</a>**
|
|
529
585
|
Provides idiomorph-based DOM morphing for efficient, non-destructive updates.
|
|
530
586
|
|
|
531
|
-
-
|
|
587
|
+
- **<a href="https://github.com/petit-kit/scoped/tree/main/src/plugins/device/README.md" target="_blank">devicePlugin</a>**
|
|
532
588
|
Detects and reacts to device and input type changes (e.g., pointer type, hover support).
|
|
533
589
|
|
|
534
|
-
-
|
|
535
|
-
Integrates the
|
|
590
|
+
- **<a href="https://github.com/petit-kit/scoped/tree/main/src/plugins/lenis/README.md" target="_blank">lenisPlugin</a>**
|
|
591
|
+
Integrates the <a href="https://github.com/studio-freight/lenis" target="_blank">Lenis</a> smooth scrolling library.
|
|
536
592
|
|
|
537
|
-
-
|
|
593
|
+
- **<a href="https://github.com/petit-kit/scoped/tree/main/src/plugins/timer/README.md" target="_blank">timerPlugin</a>**
|
|
538
594
|
Adds easy interval, timeout, and requestAnimationFrame timers to your component logic.
|
|
539
595
|
|
|
540
|
-
-
|
|
596
|
+
- **<a href="https://github.com/petit-kit/scoped/tree/main/src/plugins/window/README.md" target="_blank">windowPlugin</a>**
|
|
541
597
|
Supplies window-level utilities such as window resize and scroll event listeners.
|
|
542
598
|
|
|
543
|
-
-
|
|
599
|
+
- **<a href="https://github.com/petit-kit/scoped/tree/main/src/plugins/inview/README.md" target="_blank">inViewPlugin</a>**
|
|
544
600
|
Detects when an element is within the viewport and triggers handlers (uses IntersectionObserver).
|
|
545
601
|
|
|
546
|
-
-
|
|
602
|
+
- **<a href="https://github.com/petit-kit/scoped/tree/main/src/plugins/mouse/README.md" target="_blank">mousePlugin</a>**
|
|
547
603
|
Tracks mouse position, mouse events, and allows you to listen to wheel/pointer activity.
|
|
548
604
|
|
|
549
|
-
-
|
|
605
|
+
- **<a href="https://github.com/petit-kit/scoped/tree/main/src/plugins/pointer/README.md" target="_blank">pointerPlugin</a>**
|
|
550
606
|
Lerp mouse position
|
|
551
607
|
|
|
608
|
+
- **<a href="https://github.com/petit-kit/scoped/tree/main/src/plugins/localstorage/README.md" target="_blank">localStoragePlugin</a>**
|
|
609
|
+
Scoped localStorage API with optional key prefix and JSON serialization.
|
|
610
|
+
|
|
552
611
|
**Usage Example:**
|
|
553
612
|
|
|
554
613
|
```javascript
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";function t({from:t=0,to:e=1,mass:n=1,stiffness:s=120,damping:i=14,velocity:o=0,tolerance:d=.001,resumeOnTarget:p=!0}={}){function m(){return h(v)}function w(t){if(M)return m();if(r(v)&&r(S)&&r(b)){let e=!0;for(let o=0;o<v.length;o+=1){const r=v[o]-S[o],c=(-s*r-i*b[o])/n;b[o]+=c*t,v[o]+=b[o]*t;const h=v[o]-S[o];(Math.abs(b[o])>=d||Math.abs(h)>=d)&&(e=!1)}if(e){for(let t=0;t<v.length;t+=1)v[t]=S[t],b[t]=0;M=!0}return y.value=v,y.velocity=b,h(v)}if(c(v)&&c(S)&&c(b)){const e=y.objectKeys??Object.keys(v);let o=!0;for(const r of e){const e=v[r]-S[r],c=(-s*e-i*b[r])/n;b[r]+=c*t,v[r]+=b[r]*t;const h=v[r]-S[r];(Math.abs(b[r])>=d||Math.abs(h)>=d)&&(o=!1)}if(o){for(const t of e)v[t]=S[t],b[t]=0;M=!0}return y.value=v,y.velocity=b,h(v)}const e=S;let o=b;o+=(-s*(v-e)-i*o)/n*t,v+=o*t,b=o,y.value=v,y.velocity=b;const f=v-e;return Math.abs(o)<d&&Math.abs(f)<d&&(v=e,b=0,y.value=v,y.velocity=b,M=!0),v}const y=a({from:t,to:e,velocity:o,label:"Spring"}),g=y.normalizeInput;let v=y.value,b=y.velocity??o,S=y.target,j=null,M=!1;const x=new Set;return{setTarget:function(t){const e=g(t),n=!f(e,S);if(S=e,y.target=e,v=y.value,p&&M&&n){M=!1,j=null;for(const t of x)t(S)}},setValue:function(t,e={}){const{resetVelocity:n=!0,resetTime:s=!0,setTarget:i=!1,markDone:o=!1}=e;v=g(t),y.value=v,i&&(S=h(v),y.target=S);const r=M||!f(v,S);if(n&&(b=null!=y.arrayLength?l(0,y.arrayLength):null!=y.objectKeys?u(0,y.objectKeys):0,y.velocity=b),s&&(j=null),o&&(M=!0),r&&!o){M=!1,j=null;for(const t of x)t(S)}},getValue:m,isDone:function(){return M},onResume:function(t){return x.add(t),()=>{x.delete(t)}},step:w,next:function(t=performance.now()){if(null==j)return j=t,m();const e=(t-j)/1e3;j=t;const n=1/30;let s=e,i=m();for(;s>0&&!M;){const t=Math.min(s,n);i=w(t),s-=t}return i}}}function e(t,e){return t?`${t}:${e}`:e}function n(t,e){if(!e||"object"!=typeof e||null==e.type)return null!=t?t:e;const{type:n,default:s}=e;if(null==t)return s;try{switch(n){case String:return String(t);case Number:{const e=Number(t);return Number.isNaN(e)?s:e}case Boolean:return""===t||"true"===t||"false"!==t&&"0"!==t&&null!=t;case Object:case Array:try{return"string"==typeof t?JSON.parse(t):t}catch{return n===Array?Array.isArray(s)?s:[]:s}default:return t}}catch{return s}}function s(t,e,n,s){if(!s||"object"!=typeof s||!s.reflect)return;let i=null;const o=s.type;if(o!==Boolean){if(o===Object||o===Array)try{i=null==n?null:JSON.stringify(n)}catch{i=null}else i=null==n?null:String(n);null==i?t.removeAttribute(e):t.setAttribute(e,i)}else n?t.setAttribute(e,""):t.removeAttribute(e)}const i=()=>({name:"timer",extend:t=>{const e=new Set,n=new Set,s=new Set,i={setTimeout:(t,n,...s)=>{let i;return i=setTimeout((...n)=>{e.delete(i),t(...n)},n,...s),e.add(i),i},setInterval:(t,e,...s)=>{const i=setInterval(t,e,...s);return n.add(i),i},raf:(t,e)=>{let n=0,i=!0,o=0;const r="number"==typeof e&&e>0?1e3/e:0,c=e=>{if(s.delete(n),i){if(r){if(e-o>=r){const n=o?e-o:r;o=e,t(e,n)}}else{const n=o?e-o:0;o=e,t(e,n)}n=requestAnimationFrame(c),s.add(n)}};return n=requestAnimationFrame(c),s.add(n),()=>{i&&(i=!1,s.delete(n),cancelAnimationFrame(n))}}};return t.onDestroy(()=>{for(const t of e)clearTimeout(t);e.clear();for(const t of n)clearInterval(t);n.clear();for(const t of s)cancelAnimationFrame(t);s.clear()}),{timer:i}}}),o=()=>({name:"mouse",extend:t=>{const e=new Map,n=(t,n)=>{if("undefined"==typeof window)return()=>{};const s=t=>{const e=t;n(e.clientX,e.clientY,e)};window.addEventListener(t,s);let i=e.get(t);return i||(i=new Set,e.set(t,i)),i.add(s),()=>{window.removeEventListener(t,s),i?.delete(s)}};return t.onDestroy(()=>{if("undefined"!=typeof window){for(const[t,n]of e){for(const e of n)window.removeEventListener(t,e);n.clear()}e.clear()}}),{onMouseMove:t=>n("mousemove",t),onMouseDown:t=>n("mousedown",t),onMouseUp:t=>n("mouseup",t),onMouseWheel:t=>(t=>{if("undefined"==typeof window)return()=>{};const n=e=>{const n=e;t(n.clientX,n.clientY,n.deltaY,n)};window.addEventListener("wheel",n);let s=e.get("wheel");return s||(s=new Set,e.set("wheel",s)),s.add(n),()=>{window.removeEventListener("wheel",n),s?.delete(n)}})(t)}}}),r=t=>Array.isArray(t),c=t=>null!=t&&"object"==typeof t&&!Array.isArray(t),h=t=>r(t)?t.slice():c(t)?{...t}:t,f=(t,e)=>{if(r(t)&&r(e)){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n+=1)if(!Object.is(t[n],e[n]))return!1;return!0}if(c(t)&&c(e)){const n=Object.keys(t),s=Object.keys(e);if(n.length!==s.length)return!1;for(const s of n){if(!(s in e))return!1;if(!Object.is(t[s],e[s]))return!1}return!0}return!(r(t)||r(e)||c(t)||c(e))&&Object.is(t,e)},l=(t,e)=>Array.from({length:e},()=>t),u=(t,e)=>e.reduce((e,n)=>(e[n]=t,e),{}),a=({from:t,to:e,velocity:n,label:s})=>{const i={value:t,target:e,velocity:n,arrayLength:null,objectKeys:null,normalizeInput:t=>t},o=t=>{if(null==i.arrayLength){if(null!=i.objectKeys)throw new Error(`${s} value shape mismatch (array vs object).`);i.arrayLength=t,r(i.value)||(i.value=l(i.value,t)),r(i.target)||(i.target=l(i.target,t)),void 0===i.velocity||r(i.velocity)||(i.velocity=l(i.velocity,t))}},h=t=>{if(null==i.objectKeys){if(null!=i.arrayLength)throw new Error(`${s} value shape mismatch (object vs array).`);i.objectKeys=t,c(i.value)||(i.value=u(i.value,t)),c(i.target)||(i.target=u(i.target,t)),void 0===i.velocity||c(i.velocity)||(i.velocity=u(i.velocity,t))}},f=t=>{if(r(t)){if(null!=i.objectKeys)throw new Error(`${s} value shape mismatch (array vs object).`);if(null==i.arrayLength&&o(t.length),t.length!==i.arrayLength)throw new Error(`${s} value length mismatch (expected ${i.arrayLength}, got ${t.length}).`);return t.slice()}if(c(t)){if(null!=i.arrayLength)throw new Error(`${s} value shape mismatch (object vs array).`);const e=Object.keys(t);if(null==i.objectKeys&&h(e),i.objectKeys&&e.length!==i.objectKeys.length)throw new Error(`${s} value keys mismatch (expected ${i.objectKeys.length}, got ${e.length}).`);if(i.objectKeys)for(const e of i.objectKeys)if(!(e in t))throw new Error(`${s} value keys mismatch (missing key "${e}").`);return{...t}}return null!=i.arrayLength?l(t,i.arrayLength):null!=i.objectKeys?u(t,i.objectKeys):t};i.normalizeInput=f;const a=r(t)||r(e)||void 0!==n&&r(n),d=c(t)||c(e)||void 0!==n&&c(n);if(a&&d)throw new Error(`${s} value shape mismatch (array vs object).`);if(a){const s=r(t)?t.length:r(e)?e.length:n.length;o(s),i.value=f(t),i.target=f(e),void 0!==i.velocity&&(i.velocity=f(i.velocity))}else if(d){const s=c(t)?Object.keys(t):c(e)?Object.keys(e):Object.keys(n);h(s),i.value=f(t),i.target=f(e),void 0!==i.velocity&&(i.velocity=f(i.velocity))}return i};let d={x:-1,y:-1};const p={stiffness:300,damping:30,mass:1},m="0.0.8-beta.1",w={"&":"&","<":"<",">":">",'"':""","'":"'"},y=t=>null==t||""===t?"":String(t).replace(/[&<>"']/g,t=>w[t]),g=/\{([A-Za-z_$][\w$]*)\}/g;exports.SCOPE_VERSION=m,exports.define=function(t,e={},i){const{props:o={},shadow:r=!1,styles:c,plugins:h}=e,f=h??[],l=()=>{};class u extends HTMLElement{constructor(){super(),this.version=m,this.t={};for(const t of Object.keys(o)){const e=o[t];this.t[t]=e&&"object"==typeof e&&("type"in e||"default"in e)?e:{type:void 0,default:e,reflect:!1}}this.props={},this.state={},this.actions={},this.refs={},this.emit=this.emit.bind(this),this.listen=this.listen.bind(this),this.setState=this.setState.bind(this),this.updateState=this.updateState.bind(this),this.setProps=this.setProps.bind(this),this.scheduleUpdate=this.scheduleUpdate.bind(this),this.update=this.update.bind(this),this.forceRender=this.forceRender.bind(this),this.destroy=this.destroy.bind(this),this.$=this.$.bind(this),this.i=null,this.o=null,this.h=!1,this.l=!1,this.u=r,this.p=r?this.attachShadow({mode:"open"}):this,this.m=null,this.S=[],this.j=[],this.M=[],this.O=[],this._=[],this.A=[],this.T=[],this.k=[],this.L=null,this.C="mount",this.F=void 0,this.I=new Map,this.R=!1,this.V=!1,this.q={},this.D=t,this.H=!1,this.N=new Set,this.U=!1,this.B=new Map,this.W=0,this.J=!1}P(t){const e=this.u?this.p.host:this;let n=t.parentElement;for(;n;){if(n===e)return!1;if(n.tagName.includes("-"))return!0;n=n.parentElement}return!1}static get observedAttributes(){return Object.keys(o)}attributeChangedCallback(t,e,s){if(e===s)return;const i=this.t[t],o=this.q[t],r=n(s,i);if(this.props[t]=r,this.R&&o!==r)for(const e of this.k)try{e(t,o,r)}catch(t){l(String(t?.message||t))}this.q[t]=r,this.N.has(t)?this.N.delete(t):this.i&&this.isConnected?this.U?this.H=!0:(this.C="props",this.F=[t],this.update(!0)):this.H=!0}connectedCallback(){for(const t in this.t){if(!this.t.hasOwnProperty(t))continue;const e=n(this.getAttribute(t),this.t[t]);this.props[t]=e,this.q[t]=e}r||this.m||(this.m=this.K());let t=null;try{if(i){const e={props:this.props,state:this.state,actions:this.actions,refs:this.refs,emit:this.emit,listen:this.listen,updateState:this.updateState.bind(this),$:this.$,host:this,onMount:t=>this.M.push(t),onDestroy:t=>this.O.push(t),onUpdate:t=>this._.push(t),onBeforeUpdate:t=>this.A.push(t),onFirstUpdate:t=>this.T.push(t),onPropsChanged:t=>this.k.push(t),shouldRender:t=>{this.L=t},link:(t,e)=>{const n=e||t;this.state[n]=this.props[t],this.k.push((e,s,i)=>{e===t&&(Object.is(this.state[n],i)||(this.state[n]=i))});const i={fn:()=>{const e=this.state[n];if(Object.is(this.props[t],e))return;this.props[t]=e,this.q[t]=e;const i=this.t[t],o=i?{...i,reflect:!0}:i,r=this.getAttribute(t);this.N.add(t),s(this,t,e,o),r===this.getAttribute(t)&&this.N.delete(t)},deps:()=>[this.state[n]]};this.S.push(i)},computed:(t,e)=>{let n;if(void 0!==e)try{const t="function"==typeof e?e():e;Array.isArray(t)&&(n=t)}catch(t){String(t?.message||t)}const s={getter:t,deps:e,value:void 0!==e?t(n):t()};this.j.push(s);const i=()=>s.value;return i.Z=s,this.G(i),i},effect:(t,e)=>{const n={fn:t,deps:e};return this.S.push(n),()=>this.X(n)},delegate:(t,e,n)=>(this.Y(t,e,n),()=>this.tt(t,e,n)),escapeHtml:y};for(const t of f)if(t)try{const n=t.extend(e,this);n&&"object"==typeof n&&Object.assign(e,n)}catch(t){l(String(t?.message||t))}t=i(e)}}catch(t){throw String(t?.message||t),t}if(this.i="function"!=typeof t?()=>"":t,this.U=!0,this.C="mount",this.F=void 0,this.update(!0),this.U=!1,this.H&&(this.H=!1,this.C="props",this.F=void 0,this.update(!0)),!this.R){this.R=!0;for(const t of this.M)try{t()}catch(t){l(String(t?.message||t))}}}disconnectedCallback(){this.destroy()}remove(){super.remove()}$(t){const e=this.p.querySelectorAll(t);return 0===e.length?null:1===e.length?e[0]:Array.from(e)}destroy(){for(const t of this.O)try{t()}catch(t){l(String(t?.message||t))}for(const t of this.S)if(t.cleanup){try{t.cleanup()}catch(t){l(String(t?.message||t))}t.cleanup=void 0}for(const[,t]of this.I)try{this.p.removeEventListener(t.eventType,t.listener)}catch{}this.I.clear(),this.R=!1}emit(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e,bubbles:!0,composed:!0}))}listen(t,e,n,s){const i=n;t.addEventListener(e,i,s);const o=()=>{try{t.removeEventListener(e,i,s)}catch{}};return this.O.push(o),o}setState(t){const e=[],n=t,s=this.state;for(const t in n){if(!Object.prototype.hasOwnProperty.call(n,t))continue;const i=n[t];Object.is(s[t],i)||(s[t]=i,e.push(t))}if(0!==e.length)if(this.U||!this.R)this.C="state",this.F=e,this.update(!0);else{if(!this.i||!this.isConnected)return;if(this.h)return;this.h=!0;const t=[...e];requestAnimationFrame(()=>{this.h=!1,this.i&&this.isConnected&&(this.C="state",this.F=t,this.update(!0))})}}updateState(t){Object.assign(this.state,t),this.i&&this.isConnected&&this.et()}setProps(t){const e=Object.keys(t);if(0===e.length)return;const n=[];for(const i of e){const e=t[i],o=this.q[i];this.props[i]=e,this.R&&o!==e&&n.push(i);const r=this.t[i];r&&r.reflect&&s(this,i,e,r),this.R&&o===e||(this.q[i]=e)}if(this.R&&n.length>0)for(const e of n){const n=this.q[e],s=t[e];for(const t of this.k)try{t(e,n,s)}catch(t){l(String(t?.message||t))}}this.i&&this.isConnected?(this.C="props",this.F=n,this.update(!0)):this.H=!0}scheduleUpdate(){this.i&&this.isConnected&&this.et()}et(){this.l||this.h||(this.l=!0,("function"==typeof queueMicrotask?queueMicrotask:t=>Promise.resolve().then(t))(()=>{this.l=!1,this.i&&this.isConnected&&(this.h||this.update(!1))}))}update(t){if(this.i){if(t&&this.R)for(const t of this.A)try{t()}catch(t){l(String(t?.message||t))}if(t){const t={reason:this.C,changedKeys:this.F};if(null===this.L||this.L(t)){this.nt();let t="";try{t=this.i()}catch(e){String(e?.message||e),t=""}if("string"!=typeof t&&(t=null==t?"":String(t)),t=((t,e)=>{const n={...this.props,...e};return t.replace(g,(t,e)=>{const s=n[e];return null==s?"":String(s)})})(t,this.state),!this.u){const e=`data-scope-owner="${this.D}"`;t=t.replace(/<slot(?![^>]*data-scope-owner)(\s|>)/g,`<slot ${e}$1`)}this.J=!1;const e=null!==this.o&&Object.is(this.o,t);let n=!1;e&&this.R||(this.p.innerHTML=t,this.o=t,n=!0),this.U?("function"==typeof requestAnimationFrame?requestAnimationFrame:t=>setTimeout(t,0))(()=>{this.i&&this.isConnected&&(n&&!r&&this.projectSlots(),n&&this.st(),this.it(),this.ot())}):(n&&!r&&this.projectSlots(),n&&this.st(),this.it(),this.ot())}else this.it(),this.R&&this.ot()}else this.J&&this.nt(),this.it(),this.R&&this.ot()}}forceRender(){this.o=null,this.i&&this.isConnected?this.U?this.H=!0:(this.C="force",this.F=void 0,this.update(!0)):this.H=!0}ot(){if(!this.V){this.V=!0;for(const t of this.T)try{t()}catch(t){l(String(t?.message||t))}}for(const t of this._)try{t()}catch(t){l(String(t?.message||t))}this.rt()}rt(){const t=(this.u?this.p:this).querySelectorAll("*"),e=Object.prototype.hasOwnProperty,n=this.state,s=this.props;this.actions;for(let i=0;i<t.length;i++){const o=t[i];if(this.P(o))continue;if(0===o.attributes.length)continue;const r=o.attributes;for(let t=r.length-1;t>=0;t--){const i=r[t];if(!i.name.startsWith("bind:"))continue;const c=i.name.slice(5),h=i.value,f=h?h.trim():"";let l,u=!1;if(f){const t=this.B.get(f);if(t){t.Z&&(this.J=!0);try{l=t()}catch{}u=!0}}if(!u){const t=f||c,i=e.call(n,t),o=!i&&e.call(s,t);i?l=n[t]:o&&(l=s[t])}if("text"===c){const t=null==l?"":String(l);o.textContent!==t&&(o.textContent=t)}else if("html"===c){const t=null==l?"":String(l);o.innerHTML!==t&&(o.innerHTML=t)}else if(c in o){if(!Object.is(o[c],l))try{o[c]=l}catch{}if("value"===c)try{null==l?o.removeAttribute("value"):o.setAttribute("value",String(l))}catch{}}else if(null!=l)try{o.setAttribute(c,String(l))}catch{}const a=`__scopeBind_${c}`,d=o[a];if(d){const t=d.ct;t&&o.removeEventListener(t,d),delete o[a]}}}}ht(t,e){if(!t||!e||t.length!==e.length)return!0;for(let n=0;n<e.length;n++)if(!Object.is(t[n],e[n]))return!0;return!1}nt(){for(const t of this.j){let e,n=!0;if(void 0!==t.deps)try{const s="function"==typeof t.deps?t.deps():t.deps;Array.isArray(s)&&(e=s,n=this.ht(t.prevDeps,e))}catch(t){l(String(t?.message||t)),n=!0,e=void 0}if(n){try{t.value=void 0!==t.deps?t.getter(e):t.getter()}catch(t){l(String(t?.message||t))}e&&(t.prevDeps=e.slice())}}}it(){for(const t of this.S){let e,n=!0;if(void 0!==t.deps)try{const s="function"==typeof t.deps?t.deps():t.deps;Array.isArray(s)&&(e=s,n=this.ht(t.prevDeps,e))}catch(t){l(String(t?.message||t)),n=!0,e=void 0}if(n){if(t.cleanup){try{t.cleanup()}catch{}t.cleanup=void 0}try{const n=void 0!==t.deps?t.fn(e):t.fn();"function"==typeof n&&(t.cleanup=n)}catch{}e&&(t.prevDeps=e.slice())}}}X(t){const e=this.S.indexOf(t);if(-1!==e){if(t.cleanup)try{t.cleanup()}catch{}this.S.splice(e,1)}}G(t){const e=t.ft;if(e&&"string"==typeof e)return this.B.set(e,t),e;const n=`__scope_bind_${++this.W}__`;this.B.set(n,t);try{t.ft=n,t.toString=()=>n}catch{}return n}st(){const t=(this.u?this.p:this).querySelectorAll("*"),e=this.refs;for(const t in e)e.hasOwnProperty(t)&&delete e[t];for(let n=0;n<t.length;n++){const s=t[n];if(this.P(s))continue;const i=s.getAttribute("ref");if(i&&(e[i]?Array.isArray(e[i])?e[i].push(s):e[i]=[e[i],s]:e[i]=s),s.attributes.length>0){const t=s.attributes;for(let e=t.length-1;e>=0;e--){const n=t[e];if(!n.name.startsWith("on:"))continue;const i=n.name.slice(3),o=n.value,r=`__tinyHandler_${i}`,c=s[r];c&&s.removeEventListener(i,c),s.removeAttribute(n.name);const h=this.actions[o];if(h&&"function"==typeof h){const t=t=>{h.call(this.actions,t)};s[r]=t,s.addEventListener(i,t)}}}}}K(){const t=new Map,e=this.childNodes,n=[];for(let t=0;t<e.length;t++)n.push(e[t]);for(let e=0;e<n.length;e++){const s=n[e];let i="";1===s.nodeType&&s.getAttribute&&(i=s.getAttribute("slot")||""),t.has(i)||t.set(i,[]),t.get(i).push(s)}for(let t=0;t<n.length;t++){const e=n[t];e.parentNode&&e.parentNode.removeChild(e)}return t}projectSlots(){const t=this.m||new Map,e=(this.u?this.p:this).querySelectorAll(`slot[data-scope-owner="${this.D}"]`);if(0!==e.length)for(let n=0;n<e.length;n++){const s=e[n],i=s.getAttribute("name")||"",o=t.get(i)||[];if(o.length){const t=document.createDocumentFragment();for(let e=0;e<o.length;e++){const n=o[e];let s;if(1===n.nodeType&&n.tagName.includes("-")&&n.m instanceof Map){const t=n,e=document.createElement(t.tagName.toLowerCase());for(let n=0;n<t.attributes.length;n++){const s=t.attributes[n];e.setAttribute(s.name,s.value)}for(const n of t.m.values())for(let t=0;t<n.length;t++)e.appendChild(n[t].cloneNode(!0));s=e}else s=n.cloneNode(!0);t.appendChild(s)}s.replaceWith(t)}else{const t=s.childNodes,e=[];for(let n=0;n<t.length;n++)e.push(t[n]);if(e.length>0){const t=document.createDocumentFragment();for(let n=0;n<e.length;n++)t.appendChild(e[n]);s.replaceWith(t)}}}}Y(t,e,n){const s=`${t}::${e}`;let i=this.I.get(s);if(!i){const n=t=>{const n=t.target&&t.target.closest?t.target.closest(e):null;if(n)for(const e of i.handlers)try{e(t,n)}catch{}};i={eventType:t,selector:e,listener:n,handlers:new Set},this.I.set(s,i),this.p.addEventListener(t,n)}i.handlers.add(n)}tt(t,e,n){const s=`${t}::${e}`,i=this.I.get(s);if(i&&(i.handlers.delete(n),0===i.handlers.size)){try{this.p.removeEventListener(t,i.listener)}catch{}this.I.delete(s)}}}if(!customElements.get(t)){if(c&&"undefined"!=typeof document){const e=`scope-${t}-styles`;if(!document.getElementById(e)){const t=document.createElement("style");t.id=e,t.textContent=c,document.head.appendChild(t)}}try{customElements.define(t,u)}catch(t){String(t?.message||t)}}return u},exports.devicePlugin=()=>({name:"device",extend:t=>{const e=new Map;return t.onDestroy(()=>{for(const[t,n]of e)t.removeEventListener("change",n);e.clear()}),{onMediaQuery:(t,n,s={})=>{if("undefined"==typeof window||"undefined"==typeof matchMedia)return()=>{};const{immediate:i=!0}=s,o=matchMedia(t),r=t=>{n(t.matches,t)};return o.addEventListener("change",r),e.set(o,r),i&&n(o.matches,null),()=>{o.removeEventListener("change",r),e.delete(o)}}}}}),exports.happy=()=>{console.info("The website is using @petit-kit/scoped v"+m,"\nhttps://github.com/petit-kit/scoped")},exports.inViewPlugin=()=>({name:"inview",extend:(t,e)=>{const n=new Set,s=(t,e,s={})=>{if("undefined"==typeof window||"undefined"==typeof IntersectionObserver)return()=>{};const{immediate:i=!0,...o}=s;let r=!i;const c=new IntersectionObserver(n=>{for(const s of n)s.target===t&&(r?r=!1:e(s.isIntersecting,s))},o);return c.observe(t),n.add(c),()=>{c.unobserve(t),c.disconnect(),n.delete(c)}};return t.onDestroy(()=>{for(const t of n)t.disconnect();n.clear()}),{onInView:(t,n)=>s(e,t,n),observeInView:(t,e,n)=>s(t,e,n)}}}),exports.lenisPlugin=t=>({name:"lenis",extend:e=>{const n=new Set;return e.onDestroy(()=>{for(const{lenis:t,handler:e}of n)"function"==typeof t.off&&t.off("scroll",e);n.clear()}),{onLenisScroll:e=>{const s=t();if(!s)return()=>{};const i=t=>{e(t)};s.on("scroll",i);const o={lenis:s,handler:i};return n.add(o),()=>{n.has(o)&&(n.delete(o),"function"==typeof s.off&&s.off("scroll",i))}}}}}),exports.lerpPlugin=()=>({name:"lerp",extend:t=>{const{timer:e}=i().extend(t,t.host),n=new Set;return t.onDestroy(()=>{for(const t of n)t();n.clear()}),{createLerp:t=>function({from:t=0,to:e=1,lerp:n=.1,tolerance:s=.001,resumeOnTarget:i=!0}={}){function o(){return h(p)}function l(t){if(y)return o();const e=(t=>t<0?0:t>1?1:t)(n);if(0===e)return o();if(1===e)return p=h(m),u.value=p,y=!0,o();const i=t>0?1-Math.pow(1-e,60*t):0;if(r(p)&&r(m)){let t=!0;for(let e=0;e<p.length;e+=1)p[e]+=(m[e]-p[e])*i,Math.abs(m[e]-p[e])>=s&&(t=!1);if(t){for(let t=0;t<p.length;t+=1)p[t]=m[t];y=!0}return u.value=p,h(p)}if(c(p)&&c(m)){const t=u.objectKeys??Object.keys(p);let e=!0;for(const n of t)p[n]+=(m[n]-p[n])*i,Math.abs(m[n]-p[n])>=s&&(e=!1);if(e){for(const e of t)p[e]=m[e];y=!0}return u.value=p,h(p)}const f=m;return p+=(f-p)*i,u.value=p,Math.abs(f-p)<s&&(p=f,u.value=p,y=!0),p}const u=a({from:t,to:e,label:"Lerp"}),d=u.normalizeInput;let p=u.value,m=u.target,w=null,y=!1;const g=new Set;return{setTarget:function(t){const e=d(t),n=!f(e,m);if(m=e,u.target=e,p=u.value,i&&y&&n){y=!1,w=null;for(const t of g)t(m)}},setValue:function(t,e={}){const{resetTime:n=!0,setTarget:s=!1,markDone:i=!1}=e;p=d(t),u.value=p,s&&(m=h(p),u.target=m);const o=y||!f(p,m);if(n&&(w=null),i&&(y=!0),o&&!i){y=!1,w=null;for(const t of g)t(m)}},getValue:o,isDone:function(){return y},onResume:function(t){return g.add(t),()=>{g.delete(t)}},step:l,next:function(t=performance.now()){if(null==w)return w=t,o();const e=(t-w)/1e3;w=t;const n=1/30;let s=e,i=o();for(;s>0&&!y;){const t=Math.min(s,n);i=l(t),s-=t}return i}}}(t),runLerp:(t,s,i={})=>{const{fps:o,immediate:r=!0,stopWhenDone:c=!0}=i;let h=!1,f=null;r&&s(t.getValue(),t);const l=()=>{f||(f=e.raf(e=>{if(h)return;const n=t.next(e);s(n,t),c&&t.isDone()&&u()},o))},u=()=>{f&&(f(),f=null)};l();const a=t.onResume(()=>{!h&&c&&(r&&s(t.getValue(),t),l())}),d=()=>{h||(h=!0,a(),u(),n.delete(d))};return n.add(d),d}}}}),exports.localStoragePlugin=(t={})=>({name:"localstorage",extend:n=>{const{prefix:s="",json:i=!0}=t,o="undefined"==typeof window?null:window.localStorage;return{storage:{get:t=>{if(o)try{const n=o.getItem(e(s,t));if(null===n)return;return i?JSON.parse(n):n}catch{return}},set:(t,n)=>{if(o)try{const r=i?JSON.stringify(n):String(n);o.setItem(e(s,t),r)}catch{}},remove:t=>{o&&o.removeItem(e(s,t))},clear:()=>{if(!o)return;if(!s)return;const t=[];for(let e=0;e<o.length;e++){const n=o.key(e);null!=n&&n.startsWith(s+":")&&t.push(n)}for(const e of t)o.removeItem(e)}}}}}),exports.morphPlugin=(t,e={})=>({name:"morph",extend:(n,s)=>{const{ignoreActiveValue:i=!0,callbacks:o}=e,r=t(),c=s,h=c.p,f=c.u?ShadowRoot.prototype:HTMLElement.prototype,l=Object.getOwnPropertyDescriptor(f,"innerHTML"),u=t=>{r.morph(h,t,{morphStyle:"innerHTML",ignoreActiveValue:i,callbacks:o})};let a=!0;return Object.defineProperty(h,"innerHTML",{set(t){a?(l.set.call(this,t),a=!1):u(t)},get(){return l.get.call(this)},configurable:!0}),n.onDestroy(()=>{delete h.innerHTML}),{morph:u}}}),exports.mousePlugin=o,exports.pointerPlugin=()=>({name:"pointer",extend:e=>{const{onMouseMove:n}=o().extend(e,e.host),{timer:s}=i().extend(e,e.host);d.x=window.innerWidth/2,d.y=window.innerHeight/2;const r={x:t({from:d.x,to:d.x,...p}),y:t({from:d.y,to:d.y,...p})};return n((t,e)=>{r.x.setTarget(t),r.y.setTarget(e)}),{onPointerMove:t=>{let e=d.x,n=d.y;s.raf(s=>{const i=r.x.next(s),o=r.y.next(s);var c,h;e===i&&n===o||(t({x:i,y:o,v:(c={x:i,y:o},h={x:e,y:n},{x:c.x-h.x,y:c.y-h.y,magnitude:Math.sqrt((c.x-h.x)*(c.x-h.x)+(c.y-h.y)*(c.y-h.y))}).magnitude}),e=i,n=o)})},onMouseMove:n}}}),exports.springPlugin=()=>({name:"spring",extend:e=>{const{timer:n}=i().extend(e,e.host),s=new Set;return e.onDestroy(()=>{for(const t of s)t();s.clear()}),{createSpring:e=>t(e),runSpring:(t,e,i={})=>{const{fps:o,immediate:r=!0,stopWhenDone:c=!0}=i;let h=!1,f=null;r&&e(t.getValue(),t);const l=()=>{f||(f=n.raf(n=>{if(h)return;const s=t.next(n);e(s,t),c&&t.isDone()&&u()},o))},u=()=>{f&&(f(),f=null)};l();const a=t.onResume(()=>{!h&&c&&(r&&e(t.getValue(),t),l())}),d=()=>{h||(h=!0,a(),u(),s.delete(d))};return s.add(d),d}}}}),exports.timerPlugin=i,exports.windowPlugin=()=>({name:"window",extend:t=>{const e=new Set,n=new Set,s=new Set,i=(t,n={})=>{if("undefined"==typeof window)return()=>{};const{immediate:s=!0}=n,i=e=>{t(window.innerWidth,window.innerHeight,e)};return window.addEventListener("resize",i),e.add(i),s&&i(new UIEvent("resize")),()=>{window.removeEventListener("resize",i),e.delete(i)}};return t.onDestroy(()=>{if("undefined"!=typeof window){for(const t of e)window.removeEventListener("resize",t);e.clear();for(const t of s)t.disconnect();s.clear();for(const t of n)window.removeEventListener("scroll",t);n.clear()}}),{onViewportResize:i,onWindowResize:(t,e={})=>{if("undefined"==typeof window)return()=>{};if("undefined"==typeof ResizeObserver)return i((e,n,s)=>t(e,n,s),e);const{immediate:n=!0}=e,o=document.documentElement,r=new ResizeObserver(e=>{const n=e[0];if(!n)return;const{width:s,height:i}=n.contentRect;t(s,i,n)});if(r.observe(o),s.add(r),n){const e=o.getBoundingClientRect();t(e.width,e.height,new UIEvent("resize"))}return()=>{r.disconnect(),s.delete(r)}},onWindowScroll:(t,e={})=>{if("undefined"==typeof window)return()=>{};const{immediate:s=!0}=e,i=e=>{t(window.scrollX,window.scrollY,e)};return window.addEventListener("scroll",i,{passive:!0}),n.add(i),s&&i(new Event("scroll")),()=>{window.removeEventListener("scroll",i),n.delete(i)}}}}});
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|