@uibit/effect-trigger 0.1.0 → 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.
@@ -1,87 +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
- selector: 'uibit-effect-trigger',
8
- template: '<ng-content></ng-content>',
9
- changeDetection: ChangeDetectionStrategy.OnPush,
10
- standalone: true,
11
- host: {
12
- '(uibit-particle-create)': 'uibitParticleCreate.emit($event)'
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
- constructor(private el: ElementRef<HTMLElementClass>) {
17
- effect(() => {
18
- if (this.el.nativeElement) {
19
- this.el.nativeElement.trigger = this.trigger();
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
- effect(() => {
23
- if (this.el.nativeElement) {
24
- this.el.nativeElement.behavior = this.behavior();
25
- }
82
+ readonly velocity = input<string>('1s');
83
+ readonly randomize = input<boolean, any>(false, {
84
+ transform: booleanAttribute
26
85
  });
27
- effect(() => {
28
- if (this.el.nativeElement) {
29
- this.el.nativeElement.density = this.density();
30
- }
31
- });
32
- effect(() => {
33
- if (this.el.nativeElement) {
34
- this.el.nativeElement.velocity = this.velocity();
35
- }
36
- });
37
- effect(() => {
38
- if (this.el.nativeElement) {
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
- }
73
-
74
- readonly trigger = input<EffectTriggerType, any>('click');
75
- readonly behavior = input<EffectBehaviorType, any>('float-displace');
76
- readonly density = input<number, any>(1, { transform: numberAttribute });
77
- readonly velocity = input<string, any>('1s');
78
- readonly randomize = input<boolean, any>(false, { transform: booleanAttribute });
79
- readonly stagger = input<string, any>('0ms');
80
- readonly scaleRange = input<string, any>('0.5,1.5');
81
- readonly rotationRange = input<string, any>('-180,180');
82
- readonly keyframes = input<string | undefined, any>('');
83
- readonly targetSelector = input<string | undefined, any>('');
84
- readonly destinationSelector = input<string | undefined, any>('');
85
-
86
- 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
+ }>>();
87
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
  }
@@ -18,6 +18,9 @@ declare module 'preact' {
18
18
  keyframes?: string | undefined;
19
19
  targetSelector?: string | undefined;
20
20
  destinationSelector?: string | undefined;
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;
21
24
  };
22
25
  }
23
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
+ }
@@ -18,7 +18,8 @@ declare module 'solid-js' {
18
18
  keyframes?: string | undefined;
19
19
  targetSelector?: string | undefined;
20
20
  destinationSelector?: string | undefined;
21
- "on:uibit-particle-create"?: (event: CustomEvent) => void;
21
+ locale?: string;
22
+ "on:uibit-particle-create"?: (event: CustomEvent<{ particle: HTMLElement, index: number, trigger: string }>) => void;
22
23
  };
23
24
  }
24
25
  }
@@ -17,6 +17,9 @@ declare module '@stencil/core' {
17
17
  keyframes?: string | undefined;
18
18
  targetSelector?: string | undefined;
19
19
  destinationSelector?: string | undefined;
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;
20
23
  };
21
24
  }
22
25
  }
@@ -2,22 +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
- let {
7
- trigger = undefined,
8
- behavior = undefined,
9
- density = undefined,
10
- velocity = undefined,
11
- randomize = undefined,
12
- stagger = undefined,
13
- scaleRange = undefined,
14
- rotationRange = undefined,
15
- keyframes = undefined,
16
- targetSelector = undefined,
17
- destinationSelector = undefined,
18
- children
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
19
21
  } = $props<{
20
- children?: any;
22
+ children?: import('svelte').Snippet;
21
23
  trigger?: EffectTriggerType;
22
24
  behavior?: EffectBehaviorType;
23
25
  density?: number;
@@ -29,50 +31,109 @@
29
31
  keyframes?: string | undefined;
30
32
  targetSelector?: string | undefined;
31
33
  destinationSelector?: string | undefined;
32
-
34
+ locale?: string;
35
+
36
+ [key: string]: any;
33
37
  }>();
34
-
35
- let elementRef: HTMLElementClass | null = $state(null);
36
-
37
- $effect(() => {
38
- if (elementRef && trigger !== undefined) {
38
+
39
+ let elementRef: HTMLElementClass | null = $state(null);
40
+
41
+ $effect(() => {
42
+ if (elementRef && trigger !== undefined && elementRef.trigger !== trigger) {
39
43
  elementRef.trigger = trigger;
40
44
  }
41
- if (elementRef && behavior !== undefined) {
45
+ if (elementRef && behavior !== undefined && elementRef.behavior !== behavior) {
42
46
  elementRef.behavior = behavior;
43
47
  }
44
- if (elementRef && density !== undefined) {
48
+ if (elementRef && density !== undefined && elementRef.density !== density) {
45
49
  elementRef.density = density;
46
50
  }
47
- if (elementRef && velocity !== undefined) {
51
+ if (elementRef && velocity !== undefined && elementRef.velocity !== velocity) {
48
52
  elementRef.velocity = velocity;
49
53
  }
50
- if (elementRef && randomize !== undefined) {
54
+ if (elementRef && randomize !== undefined && elementRef.randomize !== randomize) {
51
55
  elementRef.randomize = randomize;
52
56
  }
53
- if (elementRef && stagger !== undefined) {
57
+ if (elementRef && stagger !== undefined && elementRef.stagger !== stagger) {
54
58
  elementRef.stagger = stagger;
55
59
  }
56
- if (elementRef && scaleRange !== undefined) {
60
+ if (elementRef && scaleRange !== undefined && elementRef.scaleRange !== scaleRange) {
57
61
  elementRef.scaleRange = scaleRange;
58
62
  }
59
- if (elementRef && rotationRange !== undefined) {
63
+ if (elementRef && rotationRange !== undefined && elementRef.rotationRange !== rotationRange) {
60
64
  elementRef.rotationRange = rotationRange;
61
65
  }
62
- if (elementRef && keyframes !== undefined) {
66
+ if (elementRef && keyframes !== undefined && elementRef.keyframes !== keyframes) {
63
67
  elementRef.keyframes = keyframes;
64
68
  }
65
- if (elementRef && targetSelector !== undefined) {
69
+ if (elementRef && targetSelector !== undefined && elementRef.targetSelector !== targetSelector) {
66
70
  elementRef.targetSelector = targetSelector;
67
71
  }
68
- if (elementRef && destinationSelector !== undefined) {
72
+ if (elementRef && destinationSelector !== undefined && elementRef.destinationSelector !== destinationSelector) {
69
73
  elementRef.destinationSelector = destinationSelector;
70
74
  }
75
+ if (elementRef && locale !== undefined && elementRef.locale !== locale) {
76
+ elementRef.locale = locale;
77
+ }
71
78
  });
72
-
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
+
73
134
  </script>
74
135
 
75
- <uibit-effect-trigger bind:this={elementRef} {...$$restProps}>
136
+ <uibit-effect-trigger bind:this={elementRef} {...restProps}>
76
137
 
77
138
  {#if children}
78
139
  {@render children()}