@uibit/effect-trigger 0.1.1 → 0.2.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/dist/frameworks/angular/index.ts +89 -84
- package/dist/frameworks/astro/index.d.ts +16 -1
- package/dist/frameworks/preact/index.d.ts +2 -0
- package/dist/frameworks/react/index.ts +196 -0
- package/dist/frameworks/solid/index.d.ts +1 -1
- package/dist/frameworks/stencil/index.d.ts +2 -0
- package/dist/frameworks/svelte/index.svelte +91 -35
- package/dist/frameworks/vue/index.ts +205 -31
- package/package.json +3 -3
- package/dist/frameworks/react/index.d.ts +0 -30
|
@@ -1,93 +1,98 @@
|
|
|
1
|
-
import { Component, ChangeDetectionStrategy, ElementRef, input, effect, output, booleanAttribute, numberAttribute } from '@angular/core';
|
|
1
|
+
import { Component, ChangeDetectionStrategy, ElementRef, model, input, effect, output, booleanAttribute, numberAttribute } from '@angular/core';
|
|
2
2
|
import '@uibit/effect-trigger';
|
|
3
3
|
import type { EffectTrigger as HTMLElementClass } from '@uibit/effect-trigger';
|
|
4
4
|
import type { EffectTriggerType, EffectBehaviorType } from '@uibit/effect-trigger';
|
|
5
|
-
|
|
6
5
|
@Component({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
selector: 'uibit-effect-trigger',
|
|
7
|
+
template: '<ng-content></ng-content>',
|
|
8
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
9
|
+
standalone: true,
|
|
10
|
+
host: {
|
|
11
|
+
'(uibit-particle-create)': 'uibitParticleCreate.emit($event); trigger.set($event.detail?.trigger !== undefined ? $event.detail.trigger : $event.target.trigger)'
|
|
12
|
+
}
|
|
14
13
|
})
|
|
15
14
|
export class NgxEffectTrigger {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
constructor(private el: ElementRef<HTMLElementClass>){
|
|
16
|
+
effect(()=>{
|
|
17
|
+
if (this.el.nativeElement) {
|
|
18
|
+
this.el.nativeElement.trigger = this.trigger();
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
effect(()=>{
|
|
22
|
+
if (this.el.nativeElement) {
|
|
23
|
+
this.el.nativeElement.behavior = this.behavior();
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
effect(()=>{
|
|
27
|
+
if (this.el.nativeElement) {
|
|
28
|
+
this.el.nativeElement.density = this.density();
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
effect(()=>{
|
|
32
|
+
if (this.el.nativeElement) {
|
|
33
|
+
this.el.nativeElement.velocity = this.velocity();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
effect(()=>{
|
|
37
|
+
if (this.el.nativeElement) {
|
|
38
|
+
this.el.nativeElement.randomize = this.randomize();
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
effect(()=>{
|
|
42
|
+
if (this.el.nativeElement) {
|
|
43
|
+
this.el.nativeElement.stagger = this.stagger();
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
effect(()=>{
|
|
47
|
+
if (this.el.nativeElement) {
|
|
48
|
+
this.el.nativeElement.scaleRange = this.scaleRange();
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
effect(()=>{
|
|
52
|
+
if (this.el.nativeElement) {
|
|
53
|
+
this.el.nativeElement.rotationRange = this.rotationRange();
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
effect(()=>{
|
|
57
|
+
if (this.el.nativeElement) {
|
|
58
|
+
this.el.nativeElement.keyframes = this.keyframes();
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
effect(()=>{
|
|
62
|
+
if (this.el.nativeElement) {
|
|
63
|
+
this.el.nativeElement.targetSelector = this.targetSelector();
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
effect(()=>{
|
|
67
|
+
if (this.el.nativeElement) {
|
|
68
|
+
this.el.nativeElement.destinationSelector = this.destinationSelector();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
effect(()=>{
|
|
72
|
+
if (this.el.nativeElement) {
|
|
73
|
+
this.el.nativeElement.locale = this.locale();
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
readonly trigger = model<EffectTriggerType>('click');
|
|
78
|
+
readonly behavior = input<EffectBehaviorType>('float-displace');
|
|
79
|
+
readonly density = input<number, any>(1, {
|
|
80
|
+
transform: numberAttribute
|
|
21
81
|
});
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
82
|
+
readonly velocity = input<string>('1s');
|
|
83
|
+
readonly randomize = input<boolean, any>(false, {
|
|
84
|
+
transform: booleanAttribute
|
|
26
85
|
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
this.el.nativeElement.randomize = this.randomize();
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
effect(() => {
|
|
43
|
-
if (this.el.nativeElement) {
|
|
44
|
-
this.el.nativeElement.stagger = this.stagger();
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
effect(() => {
|
|
48
|
-
if (this.el.nativeElement) {
|
|
49
|
-
this.el.nativeElement.scaleRange = this.scaleRange();
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
effect(() => {
|
|
53
|
-
if (this.el.nativeElement) {
|
|
54
|
-
this.el.nativeElement.rotationRange = this.rotationRange();
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
effect(() => {
|
|
58
|
-
if (this.el.nativeElement) {
|
|
59
|
-
this.el.nativeElement.keyframes = this.keyframes();
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
effect(() => {
|
|
63
|
-
if (this.el.nativeElement) {
|
|
64
|
-
this.el.nativeElement.targetSelector = this.targetSelector();
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
effect(() => {
|
|
68
|
-
if (this.el.nativeElement) {
|
|
69
|
-
this.el.nativeElement.destinationSelector = this.destinationSelector();
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
effect(() => {
|
|
73
|
-
if (this.el.nativeElement) {
|
|
74
|
-
this.el.nativeElement.locale = this.locale();
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
readonly trigger = input<EffectTriggerType, any>('click');
|
|
80
|
-
readonly behavior = input<EffectBehaviorType, any>('float-displace');
|
|
81
|
-
readonly density = input<number, any>(1, { transform: numberAttribute });
|
|
82
|
-
readonly velocity = input<string, any>('1s');
|
|
83
|
-
readonly randomize = input<boolean, any>(false, { transform: booleanAttribute });
|
|
84
|
-
readonly stagger = input<string, any>('0ms');
|
|
85
|
-
readonly scaleRange = input<string, any>('0.5,1.5');
|
|
86
|
-
readonly rotationRange = input<string, any>('-180,180');
|
|
87
|
-
readonly keyframes = input<string | undefined, any>('');
|
|
88
|
-
readonly targetSelector = input<string | undefined, any>('');
|
|
89
|
-
readonly destinationSelector = input<string | undefined, any>('');
|
|
90
|
-
readonly locale = input<string, any>('');
|
|
91
|
-
|
|
92
|
-
readonly uibitParticleCreate = output<CustomEvent<{ particle: HTMLElement, index: number, trigger: string }>>();
|
|
86
|
+
readonly stagger = input<string>('0ms');
|
|
87
|
+
readonly scaleRange = input<string>('0.5,1.5');
|
|
88
|
+
readonly rotationRange = input<string>('-180,180');
|
|
89
|
+
readonly keyframes = input<string | undefined>(undefined);
|
|
90
|
+
readonly targetSelector = input<string | undefined>(undefined);
|
|
91
|
+
readonly destinationSelector = input<string | undefined>(undefined);
|
|
92
|
+
readonly locale = input<string>('');
|
|
93
|
+
readonly uibitParticleCreate = output<CustomEvent<{
|
|
94
|
+
particle: HTMLElement;
|
|
95
|
+
index: number;
|
|
96
|
+
trigger: string;
|
|
97
|
+
}>>();
|
|
93
98
|
}
|
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
import type { EffectTrigger as HTMLElementClass } from '@uibit/effect-trigger';
|
|
2
2
|
import '@uibit/effect-trigger';
|
|
3
|
+
import type { EffectTriggerType, EffectBehaviorType } from '@uibit/effect-trigger';
|
|
3
4
|
|
|
4
5
|
declare global {
|
|
5
6
|
namespace astroHTML.JSX {
|
|
6
7
|
interface IntrinsicElements {
|
|
7
|
-
'uibit-effect-trigger': Partial<HTMLElementClass> & astroHTML.JSX.HTMLAttributes
|
|
8
|
+
'uibit-effect-trigger': Partial<HTMLElementClass> & astroHTML.JSX.HTMLAttributes & {
|
|
9
|
+
trigger?: EffectTriggerType;
|
|
10
|
+
behavior?: EffectBehaviorType;
|
|
11
|
+
density?: number;
|
|
12
|
+
velocity?: string;
|
|
13
|
+
randomize?: boolean;
|
|
14
|
+
stagger?: string;
|
|
15
|
+
scaleRange?: string;
|
|
16
|
+
rotationRange?: string;
|
|
17
|
+
keyframes?: string | undefined;
|
|
18
|
+
targetSelector?: string | undefined;
|
|
19
|
+
destinationSelector?: string | undefined;
|
|
20
|
+
locale?: string;
|
|
21
|
+
"on:uibit-particle-create"?: (event: CustomEvent<{ particle: HTMLElement, index: number, trigger: string }>) => void;
|
|
22
|
+
};
|
|
8
23
|
}
|
|
9
24
|
}
|
|
10
25
|
}
|
|
@@ -19,6 +19,8 @@ declare module 'preact' {
|
|
|
19
19
|
targetSelector?: string | undefined;
|
|
20
20
|
destinationSelector?: string | undefined;
|
|
21
21
|
locale?: string;
|
|
22
|
+
onUibitParticleCreate?: (event: CustomEvent<{ particle: HTMLElement, index: number, trigger: string }>) => void;
|
|
23
|
+
"on:uibit-particle-create"?: (event: CustomEvent<{ particle: HTMLElement, index: number, trigger: string }>) => void;
|
|
22
24
|
};
|
|
23
25
|
}
|
|
24
26
|
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import React, { useRef, useEffect, useLayoutEffect, useImperativeHandle } from 'react';
|
|
2
|
+
import type { EffectTrigger as HTMLElementClass } from '@uibit/effect-trigger';
|
|
3
|
+
import '@uibit/effect-trigger';
|
|
4
|
+
import type { EffectTriggerType, EffectBehaviorType } from '@uibit/effect-trigger';
|
|
5
|
+
const useTypeOfLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
6
|
+
export interface EffectTriggerProps extends Omit<React.HTMLAttributes<HTMLElementClass>, 'trigger' | 'behavior' | 'density' | 'velocity' | 'randomize' | 'stagger' | 'scaleRange' | 'rotationRange' | 'keyframes' | 'targetSelector' | 'destinationSelector' | 'locale' | 'onUibitParticleCreate'> {
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
trigger?: EffectTriggerType;
|
|
9
|
+
behavior?: EffectBehaviorType;
|
|
10
|
+
density?: number;
|
|
11
|
+
velocity?: string;
|
|
12
|
+
randomize?: boolean;
|
|
13
|
+
stagger?: string;
|
|
14
|
+
scaleRange?: string;
|
|
15
|
+
rotationRange?: string;
|
|
16
|
+
keyframes?: string | undefined;
|
|
17
|
+
targetSelector?: string | undefined;
|
|
18
|
+
destinationSelector?: string | undefined;
|
|
19
|
+
locale?: string;
|
|
20
|
+
onUibitParticleCreate?: (event: CustomEvent<{
|
|
21
|
+
particle: HTMLElement;
|
|
22
|
+
index: number;
|
|
23
|
+
trigger: string;
|
|
24
|
+
}>) => void;
|
|
25
|
+
}
|
|
26
|
+
export const EffectTrigger = ({ ref, children, ...props }: EffectTriggerProps & {
|
|
27
|
+
ref?: React.Ref<HTMLElementClass>;
|
|
28
|
+
})=>{
|
|
29
|
+
const innerRef = useRef<HTMLElementClass>(null);
|
|
30
|
+
const propsRef = useRef(props);
|
|
31
|
+
propsRef.current = props;
|
|
32
|
+
useImperativeHandle(ref, ()=>innerRef.current!);
|
|
33
|
+
useTypeOfLayoutEffect(()=>{
|
|
34
|
+
const element = innerRef.current;
|
|
35
|
+
if (element && props.trigger !== undefined) {
|
|
36
|
+
(element as any).trigger = props.trigger;
|
|
37
|
+
}
|
|
38
|
+
}, [
|
|
39
|
+
props.trigger
|
|
40
|
+
]);
|
|
41
|
+
useTypeOfLayoutEffect(()=>{
|
|
42
|
+
const element = innerRef.current;
|
|
43
|
+
if (element && props.behavior !== undefined) {
|
|
44
|
+
(element as any).behavior = props.behavior;
|
|
45
|
+
}
|
|
46
|
+
}, [
|
|
47
|
+
props.behavior
|
|
48
|
+
]);
|
|
49
|
+
useTypeOfLayoutEffect(()=>{
|
|
50
|
+
const element = innerRef.current;
|
|
51
|
+
if (element && props.density !== undefined) {
|
|
52
|
+
(element as any).density = props.density;
|
|
53
|
+
}
|
|
54
|
+
}, [
|
|
55
|
+
props.density
|
|
56
|
+
]);
|
|
57
|
+
useTypeOfLayoutEffect(()=>{
|
|
58
|
+
const element = innerRef.current;
|
|
59
|
+
if (element && props.velocity !== undefined) {
|
|
60
|
+
(element as any).velocity = props.velocity;
|
|
61
|
+
}
|
|
62
|
+
}, [
|
|
63
|
+
props.velocity
|
|
64
|
+
]);
|
|
65
|
+
useTypeOfLayoutEffect(()=>{
|
|
66
|
+
const element = innerRef.current;
|
|
67
|
+
if (element && props.randomize !== undefined) {
|
|
68
|
+
(element as any).randomize = props.randomize;
|
|
69
|
+
}
|
|
70
|
+
}, [
|
|
71
|
+
props.randomize
|
|
72
|
+
]);
|
|
73
|
+
useTypeOfLayoutEffect(()=>{
|
|
74
|
+
const element = innerRef.current;
|
|
75
|
+
if (element && props.stagger !== undefined) {
|
|
76
|
+
(element as any).stagger = props.stagger;
|
|
77
|
+
}
|
|
78
|
+
}, [
|
|
79
|
+
props.stagger
|
|
80
|
+
]);
|
|
81
|
+
useTypeOfLayoutEffect(()=>{
|
|
82
|
+
const element = innerRef.current;
|
|
83
|
+
if (element && props.scaleRange !== undefined) {
|
|
84
|
+
(element as any).scaleRange = props.scaleRange;
|
|
85
|
+
}
|
|
86
|
+
}, [
|
|
87
|
+
props.scaleRange
|
|
88
|
+
]);
|
|
89
|
+
useTypeOfLayoutEffect(()=>{
|
|
90
|
+
const element = innerRef.current;
|
|
91
|
+
if (element && props.rotationRange !== undefined) {
|
|
92
|
+
(element as any).rotationRange = props.rotationRange;
|
|
93
|
+
}
|
|
94
|
+
}, [
|
|
95
|
+
props.rotationRange
|
|
96
|
+
]);
|
|
97
|
+
useTypeOfLayoutEffect(()=>{
|
|
98
|
+
const element = innerRef.current;
|
|
99
|
+
if (element && props.keyframes !== undefined) {
|
|
100
|
+
(element as any).keyframes = props.keyframes;
|
|
101
|
+
}
|
|
102
|
+
}, [
|
|
103
|
+
props.keyframes
|
|
104
|
+
]);
|
|
105
|
+
useTypeOfLayoutEffect(()=>{
|
|
106
|
+
const element = innerRef.current;
|
|
107
|
+
if (element && props.targetSelector !== undefined) {
|
|
108
|
+
(element as any).targetSelector = props.targetSelector;
|
|
109
|
+
}
|
|
110
|
+
}, [
|
|
111
|
+
props.targetSelector
|
|
112
|
+
]);
|
|
113
|
+
useTypeOfLayoutEffect(()=>{
|
|
114
|
+
const element = innerRef.current;
|
|
115
|
+
if (element && props.destinationSelector !== undefined) {
|
|
116
|
+
(element as any).destinationSelector = props.destinationSelector;
|
|
117
|
+
}
|
|
118
|
+
}, [
|
|
119
|
+
props.destinationSelector
|
|
120
|
+
]);
|
|
121
|
+
useTypeOfLayoutEffect(()=>{
|
|
122
|
+
const element = innerRef.current;
|
|
123
|
+
if (element && props.locale !== undefined) {
|
|
124
|
+
(element as any).locale = props.locale;
|
|
125
|
+
}
|
|
126
|
+
}, [
|
|
127
|
+
props.locale
|
|
128
|
+
]);
|
|
129
|
+
useTypeOfLayoutEffect(()=>{
|
|
130
|
+
const element = innerRef.current;
|
|
131
|
+
if (!element) return;
|
|
132
|
+
const handleEvent = (event: Event)=>{
|
|
133
|
+
if (propsRef.current.onUibitParticleCreate) {
|
|
134
|
+
propsRef.current.onUibitParticleCreate(event as any);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
element.addEventListener('uibit-particle-create', handleEvent);
|
|
138
|
+
return ()=>{
|
|
139
|
+
element.removeEventListener('uibit-particle-create', handleEvent);
|
|
140
|
+
};
|
|
141
|
+
}, []);
|
|
142
|
+
const domProps = {
|
|
143
|
+
...props
|
|
144
|
+
};
|
|
145
|
+
const customPropNames = [
|
|
146
|
+
'trigger',
|
|
147
|
+
'behavior',
|
|
148
|
+
'density',
|
|
149
|
+
'velocity',
|
|
150
|
+
'randomize',
|
|
151
|
+
'stagger',
|
|
152
|
+
'scaleRange',
|
|
153
|
+
'rotationRange',
|
|
154
|
+
'keyframes',
|
|
155
|
+
'targetSelector',
|
|
156
|
+
'destinationSelector',
|
|
157
|
+
'locale',
|
|
158
|
+
'onUibitParticleCreate'
|
|
159
|
+
];
|
|
160
|
+
for (const key of customPropNames){
|
|
161
|
+
delete (domProps as any)[key];
|
|
162
|
+
}
|
|
163
|
+
return React.createElement('uibit-effect-trigger', {
|
|
164
|
+
ref: innerRef,
|
|
165
|
+
...domProps
|
|
166
|
+
}, children);
|
|
167
|
+
};
|
|
168
|
+
declare global {
|
|
169
|
+
namespace React {
|
|
170
|
+
namespace JSX {
|
|
171
|
+
interface IntrinsicElements {
|
|
172
|
+
'uibit-effect-trigger': React.ClassAttributes<HTMLElementClass> & React.HTMLAttributes<HTMLElementClass> & {
|
|
173
|
+
children?: React.ReactNode;
|
|
174
|
+
class?: string;
|
|
175
|
+
trigger?: EffectTriggerType;
|
|
176
|
+
behavior?: EffectBehaviorType;
|
|
177
|
+
density?: number;
|
|
178
|
+
velocity?: string;
|
|
179
|
+
randomize?: boolean;
|
|
180
|
+
stagger?: string;
|
|
181
|
+
scaleRange?: string;
|
|
182
|
+
rotationRange?: string;
|
|
183
|
+
keyframes?: string | undefined;
|
|
184
|
+
targetSelector?: string | undefined;
|
|
185
|
+
destinationSelector?: string | undefined;
|
|
186
|
+
locale?: string;
|
|
187
|
+
onUibitParticleCreate?: (event: CustomEvent<{
|
|
188
|
+
particle: HTMLElement;
|
|
189
|
+
index: number;
|
|
190
|
+
trigger: string;
|
|
191
|
+
}>) => void;
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
@@ -19,7 +19,7 @@ declare module 'solid-js' {
|
|
|
19
19
|
targetSelector?: string | undefined;
|
|
20
20
|
destinationSelector?: string | undefined;
|
|
21
21
|
locale?: string;
|
|
22
|
-
"on:uibit-particle-create"?: (event: CustomEvent) => void;
|
|
22
|
+
"on:uibit-particle-create"?: (event: CustomEvent<{ particle: HTMLElement, index: number, trigger: string }>) => void;
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -18,6 +18,8 @@ declare module '@stencil/core' {
|
|
|
18
18
|
targetSelector?: string | undefined;
|
|
19
19
|
destinationSelector?: string | undefined;
|
|
20
20
|
locale?: string;
|
|
21
|
+
onUibitParticleCreate?: (event: CustomEvent<{ particle: HTMLElement, index: number, trigger: string }>) => void;
|
|
22
|
+
"on:uibit-particle-create"?: (event: CustomEvent<{ particle: HTMLElement, index: number, trigger: string }>) => void;
|
|
21
23
|
};
|
|
22
24
|
}
|
|
23
25
|
}
|
|
@@ -2,23 +2,24 @@
|
|
|
2
2
|
import '@uibit/effect-trigger';
|
|
3
3
|
import type { EffectTrigger as HTMLElementClass } from '@uibit/effect-trigger';
|
|
4
4
|
import type { EffectTriggerType, EffectBehaviorType } from '@uibit/effect-trigger';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
trigger =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
5
|
+
|
|
6
|
+
let {
|
|
7
|
+
trigger = $bindable(),
|
|
8
|
+
behavior = $bindable(),
|
|
9
|
+
density = $bindable(),
|
|
10
|
+
velocity = $bindable(),
|
|
11
|
+
randomize = $bindable(),
|
|
12
|
+
stagger = $bindable(),
|
|
13
|
+
scaleRange = $bindable(),
|
|
14
|
+
rotationRange = $bindable(),
|
|
15
|
+
keyframes = $bindable(),
|
|
16
|
+
targetSelector = $bindable(),
|
|
17
|
+
destinationSelector = $bindable(),
|
|
18
|
+
locale = $bindable(),
|
|
19
|
+
children,
|
|
20
|
+
...restProps
|
|
20
21
|
} = $props<{
|
|
21
|
-
children?:
|
|
22
|
+
children?: import('svelte').Snippet;
|
|
22
23
|
trigger?: EffectTriggerType;
|
|
23
24
|
behavior?: EffectBehaviorType;
|
|
24
25
|
density?: number;
|
|
@@ -31,53 +32,108 @@
|
|
|
31
32
|
targetSelector?: string | undefined;
|
|
32
33
|
destinationSelector?: string | undefined;
|
|
33
34
|
locale?: string;
|
|
34
|
-
|
|
35
|
+
|
|
36
|
+
[key: string]: any;
|
|
35
37
|
}>();
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (elementRef && trigger !== undefined) {
|
|
38
|
+
|
|
39
|
+
let elementRef: HTMLElementClass | null = $state(null);
|
|
40
|
+
|
|
41
|
+
$effect(() => {
|
|
42
|
+
if (elementRef && trigger !== undefined && elementRef.trigger !== trigger) {
|
|
41
43
|
elementRef.trigger = trigger;
|
|
42
44
|
}
|
|
43
|
-
if (elementRef && behavior !== undefined) {
|
|
45
|
+
if (elementRef && behavior !== undefined && elementRef.behavior !== behavior) {
|
|
44
46
|
elementRef.behavior = behavior;
|
|
45
47
|
}
|
|
46
|
-
if (elementRef && density !== undefined) {
|
|
48
|
+
if (elementRef && density !== undefined && elementRef.density !== density) {
|
|
47
49
|
elementRef.density = density;
|
|
48
50
|
}
|
|
49
|
-
if (elementRef && velocity !== undefined) {
|
|
51
|
+
if (elementRef && velocity !== undefined && elementRef.velocity !== velocity) {
|
|
50
52
|
elementRef.velocity = velocity;
|
|
51
53
|
}
|
|
52
|
-
if (elementRef && randomize !== undefined) {
|
|
54
|
+
if (elementRef && randomize !== undefined && elementRef.randomize !== randomize) {
|
|
53
55
|
elementRef.randomize = randomize;
|
|
54
56
|
}
|
|
55
|
-
if (elementRef && stagger !== undefined) {
|
|
57
|
+
if (elementRef && stagger !== undefined && elementRef.stagger !== stagger) {
|
|
56
58
|
elementRef.stagger = stagger;
|
|
57
59
|
}
|
|
58
|
-
if (elementRef && scaleRange !== undefined) {
|
|
60
|
+
if (elementRef && scaleRange !== undefined && elementRef.scaleRange !== scaleRange) {
|
|
59
61
|
elementRef.scaleRange = scaleRange;
|
|
60
62
|
}
|
|
61
|
-
if (elementRef && rotationRange !== undefined) {
|
|
63
|
+
if (elementRef && rotationRange !== undefined && elementRef.rotationRange !== rotationRange) {
|
|
62
64
|
elementRef.rotationRange = rotationRange;
|
|
63
65
|
}
|
|
64
|
-
if (elementRef && keyframes !== undefined) {
|
|
66
|
+
if (elementRef && keyframes !== undefined && elementRef.keyframes !== keyframes) {
|
|
65
67
|
elementRef.keyframes = keyframes;
|
|
66
68
|
}
|
|
67
|
-
if (elementRef && targetSelector !== undefined) {
|
|
69
|
+
if (elementRef && targetSelector !== undefined && elementRef.targetSelector !== targetSelector) {
|
|
68
70
|
elementRef.targetSelector = targetSelector;
|
|
69
71
|
}
|
|
70
|
-
if (elementRef && destinationSelector !== undefined) {
|
|
72
|
+
if (elementRef && destinationSelector !== undefined && elementRef.destinationSelector !== destinationSelector) {
|
|
71
73
|
elementRef.destinationSelector = destinationSelector;
|
|
72
74
|
}
|
|
73
|
-
if (elementRef && locale !== undefined) {
|
|
75
|
+
if (elementRef && locale !== undefined && elementRef.locale !== locale) {
|
|
74
76
|
elementRef.locale = locale;
|
|
75
77
|
}
|
|
76
78
|
});
|
|
77
|
-
|
|
79
|
+
|
|
80
|
+
$effect(() => {
|
|
81
|
+
const element = elementRef;
|
|
82
|
+
if (!element) return;
|
|
83
|
+
|
|
84
|
+
const handleEvent = () => {
|
|
85
|
+
if (trigger !== element.trigger) {
|
|
86
|
+
trigger = element.trigger as any;
|
|
87
|
+
}
|
|
88
|
+
if (behavior !== element.behavior) {
|
|
89
|
+
behavior = element.behavior as any;
|
|
90
|
+
}
|
|
91
|
+
if (density !== element.density) {
|
|
92
|
+
density = element.density as any;
|
|
93
|
+
}
|
|
94
|
+
if (velocity !== element.velocity) {
|
|
95
|
+
velocity = element.velocity as any;
|
|
96
|
+
}
|
|
97
|
+
if (randomize !== element.randomize) {
|
|
98
|
+
randomize = element.randomize as any;
|
|
99
|
+
}
|
|
100
|
+
if (stagger !== element.stagger) {
|
|
101
|
+
stagger = element.stagger as any;
|
|
102
|
+
}
|
|
103
|
+
if (scaleRange !== element.scaleRange) {
|
|
104
|
+
scaleRange = element.scaleRange as any;
|
|
105
|
+
}
|
|
106
|
+
if (rotationRange !== element.rotationRange) {
|
|
107
|
+
rotationRange = element.rotationRange as any;
|
|
108
|
+
}
|
|
109
|
+
if (keyframes !== element.keyframes) {
|
|
110
|
+
keyframes = element.keyframes as any;
|
|
111
|
+
}
|
|
112
|
+
if (targetSelector !== element.targetSelector) {
|
|
113
|
+
targetSelector = element.targetSelector as any;
|
|
114
|
+
}
|
|
115
|
+
if (destinationSelector !== element.destinationSelector) {
|
|
116
|
+
destinationSelector = element.destinationSelector as any;
|
|
117
|
+
}
|
|
118
|
+
if (locale !== element.locale) {
|
|
119
|
+
locale = element.locale as any;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const events = ['change', 'input', 'uibit-particle-create'];
|
|
124
|
+
for (const event of events) {
|
|
125
|
+
element.addEventListener(event, handleEvent);
|
|
126
|
+
}
|
|
127
|
+
return () => {
|
|
128
|
+
for (const event of events) {
|
|
129
|
+
element.removeEventListener(event, handleEvent);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
|
|
78
134
|
</script>
|
|
79
135
|
|
|
80
|
-
<uibit-effect-trigger bind:this={elementRef} {
|
|
136
|
+
<uibit-effect-trigger bind:this={elementRef} {...restProps}>
|
|
81
137
|
|
|
82
138
|
{#if children}
|
|
83
139
|
{@render children()}
|
|
@@ -1,36 +1,210 @@
|
|
|
1
|
-
import { defineComponent, h } from 'vue';
|
|
1
|
+
import { defineComponent, h, ref, watch } from 'vue';
|
|
2
2
|
import type { EffectTrigger as HTMLElementClass } from '@uibit/effect-trigger';
|
|
3
3
|
import '@uibit/effect-trigger';
|
|
4
4
|
import type { EffectTriggerType, EffectBehaviorType } from '@uibit/effect-trigger';
|
|
5
|
-
|
|
6
5
|
export const EffectTrigger = defineComponent({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
6
|
+
name: 'EffectTrigger',
|
|
7
|
+
props: {
|
|
8
|
+
trigger: {
|
|
9
|
+
type: [
|
|
10
|
+
String,
|
|
11
|
+
Number,
|
|
12
|
+
Boolean,
|
|
13
|
+
Array,
|
|
14
|
+
Object
|
|
15
|
+
] as any
|
|
16
|
+
},
|
|
17
|
+
behavior: {
|
|
18
|
+
type: [
|
|
19
|
+
String,
|
|
20
|
+
Number,
|
|
21
|
+
Boolean,
|
|
22
|
+
Array,
|
|
23
|
+
Object
|
|
24
|
+
] as any
|
|
25
|
+
},
|
|
26
|
+
density: {
|
|
27
|
+
type: [
|
|
28
|
+
String,
|
|
29
|
+
Number,
|
|
30
|
+
Boolean,
|
|
31
|
+
Array,
|
|
32
|
+
Object
|
|
33
|
+
] as any
|
|
34
|
+
},
|
|
35
|
+
velocity: {
|
|
36
|
+
type: [
|
|
37
|
+
String,
|
|
38
|
+
Number,
|
|
39
|
+
Boolean,
|
|
40
|
+
Array,
|
|
41
|
+
Object
|
|
42
|
+
] as any
|
|
43
|
+
},
|
|
44
|
+
randomize: {
|
|
45
|
+
type: [
|
|
46
|
+
String,
|
|
47
|
+
Number,
|
|
48
|
+
Boolean,
|
|
49
|
+
Array,
|
|
50
|
+
Object
|
|
51
|
+
] as any
|
|
52
|
+
},
|
|
53
|
+
stagger: {
|
|
54
|
+
type: [
|
|
55
|
+
String,
|
|
56
|
+
Number,
|
|
57
|
+
Boolean,
|
|
58
|
+
Array,
|
|
59
|
+
Object
|
|
60
|
+
] as any
|
|
61
|
+
},
|
|
62
|
+
scaleRange: {
|
|
63
|
+
type: [
|
|
64
|
+
String,
|
|
65
|
+
Number,
|
|
66
|
+
Boolean,
|
|
67
|
+
Array,
|
|
68
|
+
Object
|
|
69
|
+
] as any
|
|
70
|
+
},
|
|
71
|
+
rotationRange: {
|
|
72
|
+
type: [
|
|
73
|
+
String,
|
|
74
|
+
Number,
|
|
75
|
+
Boolean,
|
|
76
|
+
Array,
|
|
77
|
+
Object
|
|
78
|
+
] as any
|
|
79
|
+
},
|
|
80
|
+
keyframes: {
|
|
81
|
+
type: [
|
|
82
|
+
String,
|
|
83
|
+
Number,
|
|
84
|
+
Boolean,
|
|
85
|
+
Array,
|
|
86
|
+
Object
|
|
87
|
+
] as any
|
|
88
|
+
},
|
|
89
|
+
targetSelector: {
|
|
90
|
+
type: [
|
|
91
|
+
String,
|
|
92
|
+
Number,
|
|
93
|
+
Boolean,
|
|
94
|
+
Array,
|
|
95
|
+
Object
|
|
96
|
+
] as any
|
|
97
|
+
},
|
|
98
|
+
destinationSelector: {
|
|
99
|
+
type: [
|
|
100
|
+
String,
|
|
101
|
+
Number,
|
|
102
|
+
Boolean,
|
|
103
|
+
Array,
|
|
104
|
+
Object
|
|
105
|
+
] as any
|
|
106
|
+
},
|
|
107
|
+
locale: {
|
|
108
|
+
type: [
|
|
109
|
+
String,
|
|
110
|
+
Number,
|
|
111
|
+
Boolean,
|
|
112
|
+
Array,
|
|
113
|
+
Object
|
|
114
|
+
] as any
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
emits: [
|
|
118
|
+
'uibit-particle-create'
|
|
119
|
+
],
|
|
120
|
+
setup (props, { slots, emit }) {
|
|
121
|
+
const elementRef = ref<HTMLElementClass | null>(null);
|
|
122
|
+
if (false) {
|
|
123
|
+
watch(()=>props.modelValue, (newVal)=>{
|
|
124
|
+
if (elementRef.value && newVal !== undefined && elementRef.value.value !== newVal) {
|
|
125
|
+
elementRef.value.value = newVal;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
watch(()=>props.value, (newVal)=>{
|
|
129
|
+
if (elementRef.value && newVal !== undefined && elementRef.value.value !== newVal) {
|
|
130
|
+
elementRef.value.value = newVal;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
watch(()=>props.trigger, (newVal)=>{
|
|
135
|
+
if (elementRef.value && newVal !== undefined) {
|
|
136
|
+
(elementRef.value as any).trigger = newVal;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
watch(()=>props.behavior, (newVal)=>{
|
|
140
|
+
if (elementRef.value && newVal !== undefined) {
|
|
141
|
+
(elementRef.value as any).behavior = newVal;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
watch(()=>props.density, (newVal)=>{
|
|
145
|
+
if (elementRef.value && newVal !== undefined) {
|
|
146
|
+
(elementRef.value as any).density = newVal;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
watch(()=>props.velocity, (newVal)=>{
|
|
150
|
+
if (elementRef.value && newVal !== undefined) {
|
|
151
|
+
(elementRef.value as any).velocity = newVal;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
watch(()=>props.randomize, (newVal)=>{
|
|
155
|
+
if (elementRef.value && newVal !== undefined) {
|
|
156
|
+
(elementRef.value as any).randomize = newVal;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
watch(()=>props.stagger, (newVal)=>{
|
|
160
|
+
if (elementRef.value && newVal !== undefined) {
|
|
161
|
+
(elementRef.value as any).stagger = newVal;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
watch(()=>props.scaleRange, (newVal)=>{
|
|
165
|
+
if (elementRef.value && newVal !== undefined) {
|
|
166
|
+
(elementRef.value as any).scaleRange = newVal;
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
watch(()=>props.rotationRange, (newVal)=>{
|
|
170
|
+
if (elementRef.value && newVal !== undefined) {
|
|
171
|
+
(elementRef.value as any).rotationRange = newVal;
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
watch(()=>props.keyframes, (newVal)=>{
|
|
175
|
+
if (elementRef.value && newVal !== undefined) {
|
|
176
|
+
(elementRef.value as any).keyframes = newVal;
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
watch(()=>props.targetSelector, (newVal)=>{
|
|
180
|
+
if (elementRef.value && newVal !== undefined) {
|
|
181
|
+
(elementRef.value as any).targetSelector = newVal;
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
watch(()=>props.destinationSelector, (newVal)=>{
|
|
185
|
+
if (elementRef.value && newVal !== undefined) {
|
|
186
|
+
(elementRef.value as any).destinationSelector = newVal;
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
watch(()=>props.locale, (newVal)=>{
|
|
190
|
+
if (elementRef.value && newVal !== undefined) {
|
|
191
|
+
(elementRef.value as any).locale = newVal;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
return ()=>{
|
|
195
|
+
const eventListeners: Record<string, any> = {};
|
|
196
|
+
eventListeners['onUibit-particle-create'] = (event: Event)=>{
|
|
197
|
+
emit('uibit-particle-create', event);
|
|
198
|
+
};
|
|
199
|
+
const mergedProps = {
|
|
200
|
+
...props,
|
|
201
|
+
...eventListeners,
|
|
202
|
+
ref: elementRef
|
|
203
|
+
};
|
|
204
|
+
if (false && props.modelValue !== undefined) {
|
|
205
|
+
(mergedProps as any).value = props.modelValue;
|
|
206
|
+
}
|
|
207
|
+
return h('uibit-effect-trigger', mergedProps, slots.default?.());
|
|
208
|
+
};
|
|
209
|
+
}
|
|
36
210
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uibit/effect-trigger",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A behavioral engine that intercepts user actions (click, hover, visible) on standard DOM elements to trigger custom particle animations, physics-based viewport crossings, or micro-feedback flows using slotted SVGs or markup templates.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"import": "./dist/index.js"
|
|
12
12
|
},
|
|
13
13
|
"./custom-elements.json": "./custom-elements.json",
|
|
14
|
-
"./react": "./dist/frameworks/react/index.
|
|
14
|
+
"./react": "./dist/frameworks/react/index.ts",
|
|
15
15
|
"./vue": "./dist/frameworks/vue/index.ts",
|
|
16
16
|
"./svelte": "./dist/frameworks/svelte/index.svelte",
|
|
17
17
|
"./angular": "./dist/frameworks/angular/index.ts",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@types/node": "^20.19.43",
|
|
47
47
|
"lit": "^3.3.3",
|
|
48
48
|
"typescript": "7.0.2",
|
|
49
|
-
"@uibit/codegen": "0.
|
|
49
|
+
"@uibit/codegen": "0.2.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"lit": "^3.0.0",
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { HTMLAttributes, ClassAttributes } from 'react';
|
|
2
|
-
import type { EffectTrigger as HTMLElementClass } from '@uibit/effect-trigger';
|
|
3
|
-
import '@uibit/effect-trigger';
|
|
4
|
-
import type { EffectTriggerType, EffectBehaviorType } from '@uibit/effect-trigger';
|
|
5
|
-
|
|
6
|
-
declare global {
|
|
7
|
-
namespace React {
|
|
8
|
-
namespace JSX {
|
|
9
|
-
interface IntrinsicElements {
|
|
10
|
-
'uibit-effect-trigger': ClassAttributes<HTMLElementClass> & HTMLAttributes<HTMLElementClass> & {
|
|
11
|
-
children?: React.ReactNode;
|
|
12
|
-
class?: string;
|
|
13
|
-
trigger?: EffectTriggerType;
|
|
14
|
-
behavior?: EffectBehaviorType;
|
|
15
|
-
density?: number;
|
|
16
|
-
velocity?: string;
|
|
17
|
-
randomize?: boolean;
|
|
18
|
-
stagger?: string;
|
|
19
|
-
scaleRange?: string;
|
|
20
|
-
rotationRange?: string;
|
|
21
|
-
keyframes?: string | undefined;
|
|
22
|
-
targetSelector?: string | undefined;
|
|
23
|
-
destinationSelector?: string | undefined;
|
|
24
|
-
locale?: string;
|
|
25
|
-
onUibitParticleCreate?: (event: any) => void;
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|