@creative-web-solution/front-library 7.0.7 → 7.1.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/CHANGELOG.md +15 -0
- package/DOM/Class.ts +10 -12
- package/DOM/DocumentSize.ts +3 -1
- package/DOM/Filter.ts +0 -2
- package/DOM/Index.ts +1 -3
- package/DOM/Manipulation.ts +0 -3
- package/DOM/Matrix.ts +12 -12
- package/DOM/Offset.ts +4 -5
- package/DOM/OuterSize.ts +12 -12
- package/DOM/PageToDOM.ts +2 -2
- package/DOM/Position.ts +3 -3
- package/DOM/Size.ts +3 -7
- package/DOM/StrToDOM.ts +0 -1
- package/DOM/Styles.ts +3 -12
- package/DOM/Traversing.ts +0 -6
- package/DOM/WindowScroll.ts +3 -1
- package/DOM/WindowSize.ts +3 -1
- package/DOM/Wrap.ts +0 -1
- package/Events/DeviceOrientation.ts +27 -31
- package/Events/EventsManager.ts +10 -25
- package/Events/Gesture.ts +36 -37
- package/Events/HistoryController.ts +11 -17
- package/Events/ImageLoad.ts +35 -19
- package/Events/IntersectObserver.ts +15 -19
- package/Events/KeyboardHandler.ts +10 -8
- package/Events/MediaQueriesEvents.ts +53 -51
- package/Events/OnAnimationEnd.ts +2 -3
- package/Events/OnTransitionEnd.ts +3 -3
- package/Events/PubSub.ts +5 -8
- package/Events/TouchHover.ts +18 -21
- package/Events/WindowEvents.ts +26 -30
- package/Helpers/Colors.ts +7 -23
- package/Helpers/Cookie.ts +5 -12
- package/Helpers/Coordinates.ts +0 -7
- package/Helpers/Debounce.ts +3 -7
- package/Helpers/Defer.ts +1 -1
- package/Helpers/GetValue.ts +0 -2
- package/Helpers/Insert.ts +0 -1
- package/Helpers/Sequential.ts +0 -2
- package/Helpers/Slice.ts +0 -3
- package/Helpers/Throttle.ts +0 -1
- package/Helpers/TransitionHelpers.ts +8 -6
- package/Helpers/Type.ts +1 -14
- package/Helpers/Unique.ts +3 -3
- package/Helpers/UrlParser.ts +13 -22
- package/Helpers/Wait.ts +1 -1
- package/Modules/Accordion/Tab.ts +18 -16
- package/Modules/Accordion/index.ts +24 -16
- package/Modules/Autocomplete.ts +95 -101
- package/Modules/DragSlider.ts +72 -63
- package/Modules/GlobalState.ts +60 -53
- package/Modules/LoadGMap.ts +4 -7
- package/Modules/Notifications/Notification.ts +28 -32
- package/Modules/Notifications/index.ts +43 -36
- package/Modules/Popin/Popin.ts +100 -110
- package/Modules/Popin/PopinAccessibility.ts +8 -8
- package/Modules/Popin/PopinBackground.ts +11 -11
- package/Modules/Popin/PopinController.ts +23 -29
- package/Modules/Popin/Tools.ts +18 -19
- package/Modules/QuickTemplate.ts +4 -6
- package/Modules/ScrollSnap.ts +110 -104
- package/Modules/SkinCheckbox.ts +51 -37
- package/Modules/SkinFile.ts +62 -52
- package/Modules/SkinRadio.ts +62 -42
- package/Modules/SkinSelect.ts +116 -100
- package/Modules/Slider/Slide.ts +49 -52
- package/Modules/Slider/Slider.ts +100 -136
- package/Modules/Slider/SliderControls.ts +60 -59
- package/Modules/Tabs/Tab.ts +27 -23
- package/Modules/Tabs/index.ts +35 -25
- package/Modules/Validator/Date.ts +2 -1
- package/Modules/Validator/Equals.ts +1 -1
- package/Modules/Validator/Internal/Input.ts +370 -0
- package/Modules/Validator/Internal/InputValidator.ts +99 -0
- package/Modules/Validator/Internal/ValidatorFunctionsController.ts +58 -0
- package/Modules/Validator/Max.ts +1 -1
- package/Modules/Validator/Min.ts +1 -1
- package/Modules/Validator/MultiRequired.ts +5 -5
- package/Modules/Validator/Number.ts +1 -0
- package/Modules/Validator/Pattern.ts +1 -1
- package/Modules/Validator/Recaptcha.ts +1 -0
- package/Modules/Validator/Required.ts +3 -2
- package/Modules/Validator/ServerCheck.ts +23 -15
- package/Modules/Validator/Tools/GetQueryFromForm.ts +1 -6
- package/Modules/Validator/Tools/IsDate.ts +2 -3
- package/Modules/Validator/Tools/IsEmail.ts +2 -5
- package/Modules/Validator/Tools/IsEmpty.ts +0 -2
- package/Modules/Validator/Tools/IsNumber.ts +0 -2
- package/Modules/Validator/Tools/IsUrl.ts +1 -3
- package/Modules/Validator/Tools/Label.ts +5 -15
- package/Modules/Validator/Tools/RadioButton.ts +4 -10
- package/Modules/Validator/Url.ts +1 -0
- package/Modules/Validator/index.ts +36 -36
- package/Modules/YouTubePlayer.ts +18 -16
- package/README.md +1 -1
- package/Types/Accordion.d.ts +36 -0
- package/Types/Autocomplete.d.ts +95 -0
- package/Types/DOM.d.ts +69 -0
- package/Types/DragSlider.d.ts +56 -0
- package/Types/EventsHelpers.d.ts +390 -0
- package/Types/GLImageTransition.d.ts +47 -43
- package/Types/GlobalState.d.ts +9 -0
- package/Types/Helpers.d.ts +30 -0
- package/Types/Notifications.d.ts +48 -44
- package/Types/Popin.d.ts +95 -0
- package/Types/ScrollSnap.d.ts +66 -0
- package/Types/SkinCheckbox.d.ts +26 -0
- package/Types/SkinFile.d.ts +38 -0
- package/Types/SkinRadio.d.ts +28 -0
- package/Types/SkinSelect.d.ts +59 -0
- package/Types/Slider.d.ts +106 -0
- package/Types/Tabs.d.ts +26 -0
- package/Types/Validator.d.ts +72 -0
- package/Types/YouTubePlayer.d.ts +27 -0
- package/Types/index.d.ts +22 -21
- package/WebGL/GLImageTransition/GLImageTransition.ts +83 -80
- package/WebGL/GLImageTransition/Presets/Cellular.ts +11 -11
- package/WebGL/GLImageTransition/Presets/Fade.ts +2 -3
- package/WebGL/GLImageTransition/Presets/HorizontalMovingGrid.ts +9 -9
- package/WebGL/GLImageTransition/Presets/PresetSample.ts +11 -9
- package/WebGL/GLImageTransition/Presets/Solarisation.ts +7 -12
- package/package.json +1 -1
- package/Modules/Template.ts +0 -209
- package/Types/AccordionTypes.d.ts +0 -29
- package/Types/AutocompleteTypes.d.ts +0 -85
- package/Types/DOMTypes.d.ts +0 -62
- package/Types/DragSliderTypes.d.ts +0 -52
- package/Types/EventsHelpersTypes.d.ts +0 -370
- package/Types/GlobalStateTypes.d.ts +0 -5
- package/Types/HelpersTypes.d.ts +0 -23
- package/Types/MediaPreloaderTypes.d.ts +0 -12
- package/Types/PopinTypes.d.ts +0 -83
- package/Types/ScrollSnapTypes.d.ts +0 -62
- package/Types/SkinCheckboxTypes.d.ts +0 -23
- package/Types/SkinFileTypes.d.ts +0 -34
- package/Types/SkinRadioTypes.d.ts +0 -24
- package/Types/SkinSelectTypes.d.ts +0 -48
- package/Types/SliderTypes.d.ts +0 -97
- package/Types/TabsTypes.d.ts +0 -22
- package/Types/ValidatorTypes.d.ts +0 -61
- package/Types/YouTubePlayerTypes.d.ts +0 -23
package/Types/Tabs.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
namespace FLib {
|
|
2
|
+
namespace Tabs {
|
|
3
|
+
type AnimationFunction = ( $tab: HTMLElement, $panel: HTMLElement ) => Promise<void>;
|
|
4
|
+
type Callback = ( $tab: HTMLElement, $panel: HTMLElement, autoClose?: boolean ) => void;
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
type Options = {
|
|
8
|
+
/** @defaultValue 'li[aria-selected]' */
|
|
9
|
+
tabSelector: string;
|
|
10
|
+
onOpenAtStart?: TabsCallbackType;
|
|
11
|
+
onOpen?: TabsCallbackType;
|
|
12
|
+
onClose?: TabsCallbackType;
|
|
13
|
+
animations: {
|
|
14
|
+
open: TabsAnimationFunctionType;
|
|
15
|
+
close: TabsAnimationFunctionType;
|
|
16
|
+
destroy: TabsAnimationFunctionType;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
type TabOptions = Options & {
|
|
22
|
+
onOpenTab: (( tab: Tab ) => void) | null;
|
|
23
|
+
index: number;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
namespace FLib {
|
|
2
|
+
namespace Validator {
|
|
3
|
+
type ValidationState = {
|
|
4
|
+
$input: HTMLElement;
|
|
5
|
+
value: string | string[];
|
|
6
|
+
isValid: boolean;
|
|
7
|
+
label: string;
|
|
8
|
+
data?: any;
|
|
9
|
+
isLiveValidation: boolean;
|
|
10
|
+
extraErrorMessages?: string[];
|
|
11
|
+
extraMessages?: string[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type Validator = {
|
|
15
|
+
name: string;
|
|
16
|
+
selector: string;
|
|
17
|
+
isAsynch: boolean;
|
|
18
|
+
validate: ValidateFunction;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
type ValidateFunction = ( $input: HTMLElement, value: string | string[], isLiveValidation: boolean, validatorOptions ) => Promise<ValidationState>
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
type ValidationReturnType = {
|
|
26
|
+
"inputs": Input[];
|
|
27
|
+
"errors": Input[];
|
|
28
|
+
"$form": HTMLElement;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type FieldValidationReturnType = {
|
|
32
|
+
"input": Input;
|
|
33
|
+
"error": Input | null;
|
|
34
|
+
"$form": HTMLElement;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
type Options = {
|
|
39
|
+
/** @defaultValue input,textarea,select */
|
|
40
|
+
fields: string;
|
|
41
|
+
/** @defaultValue input[type="button"], input[type="submit"], input[type="reset"], input */
|
|
42
|
+
filter: string;
|
|
43
|
+
/** @defaultValue data-error-label */
|
|
44
|
+
customErrorLabelPrefix: string;
|
|
45
|
+
/** @defaultValue `{}` */
|
|
46
|
+
errorMessages: { [ key: string ]: string };
|
|
47
|
+
validatorsOptions?: { [ key: string ]: any };
|
|
48
|
+
onValidate?: ( data: ValidationReturnType ) => void;
|
|
49
|
+
onInvalidate?: ( data: ValidationReturnType ) => void;
|
|
50
|
+
liveValidation?: {
|
|
51
|
+
onValidate?: ( input: Input, event ) => void;
|
|
52
|
+
onInvalidate?: ( input: Input, event ) => void;
|
|
53
|
+
eventsName: {
|
|
54
|
+
/** @defaultValue change */
|
|
55
|
+
optin: string;
|
|
56
|
+
/** @defaultValue change */
|
|
57
|
+
select: string;
|
|
58
|
+
/** @defaultValue input */
|
|
59
|
+
inputText: string;
|
|
60
|
+
}
|
|
61
|
+
eventsHook
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
type CustomValidatorRadioInput = HTMLInputElement & {
|
|
67
|
+
__$radioMaster: CustomValidatorRadioInput;
|
|
68
|
+
__$radioGroup: CustomValidatorRadioInput[];
|
|
69
|
+
__$otherRadioOfGroup: CustomValidatorRadioInput[];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
namespace FLib {
|
|
2
|
+
namespace YouTubePlayer {
|
|
3
|
+
type Options = {
|
|
4
|
+
height: number;
|
|
5
|
+
width: number;
|
|
6
|
+
videoId: string;
|
|
7
|
+
$wrapper: HTMLElement;
|
|
8
|
+
/**
|
|
9
|
+
* @defaultValue //www.youtube.com/iframe_api
|
|
10
|
+
*/
|
|
11
|
+
apiUrl: string;
|
|
12
|
+
onPlayerStateChange?: ( e: YT.PlayerEvent ) => void;
|
|
13
|
+
/**
|
|
14
|
+
* @defaultValue `{ "autoplay": 0, "controls": 2, "autohide": 1, "modestbranding": 1, "showinfo": 0 }`
|
|
15
|
+
*/
|
|
16
|
+
playerVars: YT.PlayerVars;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type PlayerWindow = Window & typeof globalThis & {
|
|
20
|
+
onYouTubeIframeAPIReady: (() => void) | null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type PlayerWrapper = HTMLElement & {
|
|
24
|
+
YTPlayer: YT.Player;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
package/Types/index.d.ts
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
declare namespace FLib {}
|
|
2
|
+
|
|
3
|
+
import './Accordion';
|
|
4
|
+
import './Autocomplete';
|
|
5
|
+
import './DOM';
|
|
6
|
+
import './DragSlider';
|
|
7
|
+
import './EventsHelpers';
|
|
8
|
+
import './GLImageTransition';
|
|
9
|
+
import './Global';
|
|
10
|
+
import './GlobalState';
|
|
11
|
+
import './Helpers';
|
|
12
|
+
import './Notifications';
|
|
13
|
+
import './Popin';
|
|
14
|
+
import './ScrollSnap';
|
|
15
|
+
import './SkinCheckbox';
|
|
16
|
+
import './SkinFile';
|
|
17
|
+
import './SkinRadio';
|
|
18
|
+
import './SkinSelect';
|
|
19
|
+
import './Slider';
|
|
20
|
+
import './Tabs';
|
|
21
|
+
import './Validator';
|
|
22
|
+
import './YouTubePlayer';
|
|
@@ -50,8 +50,8 @@ export default class GLImageTransition {
|
|
|
50
50
|
#deltaTime!: number;
|
|
51
51
|
#imagesInfo!: { width: number, height: number, aspect: number };
|
|
52
52
|
|
|
53
|
-
#SHADER_PRESET:
|
|
54
|
-
#OPTIONS:
|
|
53
|
+
#SHADER_PRESET: FLib.GLImageTransition.Preset;
|
|
54
|
+
#OPTIONS: FLib.GLImageTransition.Options;
|
|
55
55
|
#DURATION: number;
|
|
56
56
|
#$CANVAS: HTMLCanvasElement;
|
|
57
57
|
#GL: WebGLRenderingContext;
|
|
@@ -74,70 +74,70 @@ export default class GLImageTransition {
|
|
|
74
74
|
#TEXTURE_2: WebGLTexture;
|
|
75
75
|
|
|
76
76
|
|
|
77
|
-
get $canvas() {
|
|
77
|
+
get $canvas(): HTMLCanvasElement {
|
|
78
78
|
return this.#$CANVAS;
|
|
79
79
|
}
|
|
80
|
-
get context() {
|
|
80
|
+
get context(): WebGLRenderingContext {
|
|
81
81
|
return this.#GL;
|
|
82
82
|
}
|
|
83
|
-
get size() {
|
|
83
|
+
get size(): { width: number, height: number } {
|
|
84
84
|
return this.#canvasSize;
|
|
85
85
|
}
|
|
86
|
-
get aspect() {
|
|
86
|
+
get aspect(): number {
|
|
87
87
|
return this.#canvasAspect;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
|
|
91
|
-
constructor( userOptions:
|
|
91
|
+
constructor( userOptions: Partial<FLib.GLImageTransition.Options> = {}) {
|
|
92
92
|
|
|
93
|
-
this.#OPTIONS = Object.assign( {}, DEFAULT_OPTIONS, userOptions );
|
|
93
|
+
this.#OPTIONS = Object.assign( {}, DEFAULT_OPTIONS, userOptions ) as FLib.GLImageTransition.Options;
|
|
94
94
|
|
|
95
95
|
if ( !this.#OPTIONS.preset ) {
|
|
96
96
|
throw 'You must add a preset that implement GLImageTransitionPreset in the options object ';
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
this.#SHADER_PRESET = this.#OPTIONS.preset;
|
|
100
|
-
this.#DURATION = this.#OPTIONS.duration
|
|
100
|
+
this.#DURATION = this.#OPTIONS.duration * 1000; // convert in ms
|
|
101
101
|
|
|
102
102
|
this.#$CANVAS = document.createElement( 'canvas' );
|
|
103
103
|
this.#OPTIONS.canvasCssClass && aClass( this.#$CANVAS, this.#OPTIONS.canvasCssClass );
|
|
104
104
|
|
|
105
|
-
append( this.#$CANVAS, this.#OPTIONS.$wrapper
|
|
105
|
+
append( this.#$CANVAS, this.#OPTIONS.$wrapper );
|
|
106
106
|
|
|
107
|
-
this.#GL = this.#$CANVAS.getContext( this.#OPTIONS.context
|
|
107
|
+
this.#GL = this.#$CANVAS.getContext( this.#OPTIONS.context ) as WebGLRenderingContext;
|
|
108
108
|
|
|
109
109
|
if ( !this.#GL ) {
|
|
110
110
|
throw 'Unable to initialize WebGL. Your browser may not support it.';
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
// Convert 0 -> 1 colors in 0 -> 255
|
|
114
|
-
this.#OPTIONS.dummyTextureColor = this.#OPTIONS.dummyTextureColor
|
|
114
|
+
this.#OPTIONS.dummyTextureColor = this.#OPTIONS.dummyTextureColor.map( v => v * 255 );
|
|
115
115
|
|
|
116
116
|
|
|
117
|
-
this.#VERTEX_BUFFER = this
|
|
117
|
+
this.#VERTEX_BUFFER = this.#createBuffer( this.#GL.ARRAY_BUFFER, new Float32Array([
|
|
118
118
|
-1.0, 1.0, 0.0,
|
|
119
119
|
-1.0, -1.0, 0.0,
|
|
120
120
|
1.0, -1.0, 0.0,
|
|
121
121
|
1.0, 1.0, 0.0
|
|
122
122
|
]) );
|
|
123
123
|
|
|
124
|
-
this.#TEXTURE_BUFFER = this
|
|
124
|
+
this.#TEXTURE_BUFFER = this.#createBuffer( this.#GL.ARRAY_BUFFER, new Float32Array([
|
|
125
125
|
0.0, 0.0,
|
|
126
126
|
0.0, 1.0,
|
|
127
127
|
1.0, 1.0,
|
|
128
128
|
1.0, 0.0
|
|
129
129
|
]) );
|
|
130
130
|
|
|
131
|
-
this.#INDEX_BUFFER = this
|
|
131
|
+
this.#INDEX_BUFFER = this.#createBuffer( this.#GL.ELEMENT_ARRAY_BUFFER, new Uint16Array([
|
|
132
132
|
3, 2, 1,
|
|
133
133
|
3, 1, 0
|
|
134
134
|
]) );
|
|
135
135
|
|
|
136
136
|
|
|
137
|
-
this.#VERTEX_SHADER = this
|
|
138
|
-
this.#FRAGMENT_SHADER = this
|
|
137
|
+
this.#VERTEX_SHADER = this.#createShader( this.#GL.VERTEX_SHADER, VERTEX_SHADER_SOURCE );
|
|
138
|
+
this.#FRAGMENT_SHADER = this.#createShader( this.#GL.FRAGMENT_SHADER, this.#SHADER_PRESET.fsSource );
|
|
139
139
|
|
|
140
|
-
this.#SHADER_PROGRAM = this.#GL.createProgram()
|
|
140
|
+
this.#SHADER_PROGRAM = this.#GL.createProgram() as WebGLProgram;
|
|
141
141
|
|
|
142
142
|
this.#GL.attachShader( this.#SHADER_PROGRAM, this.#VERTEX_SHADER);
|
|
143
143
|
this.#GL.attachShader( this.#SHADER_PROGRAM, this.#FRAGMENT_SHADER);
|
|
@@ -150,18 +150,18 @@ export default class GLImageTransition {
|
|
|
150
150
|
this.#A_VERTEX_POSITION = this.#GL.getAttribLocation( this.#SHADER_PROGRAM, 'aVertexPosition' );
|
|
151
151
|
this.#A_TEXTURE_COORDS = this.#GL.getAttribLocation( this.#SHADER_PROGRAM, 'aTextureCoord' );
|
|
152
152
|
|
|
153
|
-
this.#U_PROJECTION_MATRIX = this.#GL.getUniformLocation( this.#SHADER_PROGRAM, 'uProjectionMatrix' )
|
|
154
|
-
this.#U_MODEL_VIEW_MATRIX = this.#GL.getUniformLocation( this.#SHADER_PROGRAM, 'uModelViewMatrix' )
|
|
155
|
-
this.#U_SAMPLER = this.#GL.getUniformLocation( this.#SHADER_PROGRAM, 'uSampler' )
|
|
156
|
-
this.#U_SAMPLER_2 = this.#GL.getUniformLocation( this.#SHADER_PROGRAM, 'uSampler2' )
|
|
157
|
-
this.#U_PROGRESS = this.#GL.getUniformLocation( this.#SHADER_PROGRAM, 'uProgress' )
|
|
158
|
-
this.#U_TIME = this.#GL.getUniformLocation( this.#SHADER_PROGRAM, 'uTime' )
|
|
159
|
-
this.#U_DELTA_TIME = this.#GL.getUniformLocation( this.#SHADER_PROGRAM, 'uDeltaTime' )
|
|
153
|
+
this.#U_PROJECTION_MATRIX = this.#GL.getUniformLocation( this.#SHADER_PROGRAM, 'uProjectionMatrix' ) as WebGLUniformLocation;
|
|
154
|
+
this.#U_MODEL_VIEW_MATRIX = this.#GL.getUniformLocation( this.#SHADER_PROGRAM, 'uModelViewMatrix' ) as WebGLUniformLocation;
|
|
155
|
+
this.#U_SAMPLER = this.#GL.getUniformLocation( this.#SHADER_PROGRAM, 'uSampler' ) as WebGLUniformLocation;
|
|
156
|
+
this.#U_SAMPLER_2 = this.#GL.getUniformLocation( this.#SHADER_PROGRAM, 'uSampler2' ) as WebGLUniformLocation;
|
|
157
|
+
this.#U_PROGRESS = this.#GL.getUniformLocation( this.#SHADER_PROGRAM, 'uProgress' ) as WebGLUniformLocation;
|
|
158
|
+
this.#U_TIME = this.#GL.getUniformLocation( this.#SHADER_PROGRAM, 'uTime' ) as WebGLUniformLocation;
|
|
159
|
+
this.#U_DELTA_TIME = this.#GL.getUniformLocation( this.#SHADER_PROGRAM, 'uDeltaTime' ) as WebGLUniformLocation;
|
|
160
160
|
|
|
161
161
|
this.#SHADER_PRESET.addUniform && this.#SHADER_PRESET.addUniform( this.#GL, this.#SHADER_PROGRAM );
|
|
162
162
|
|
|
163
|
-
this.#TEXTURE_1 = this
|
|
164
|
-
this.#TEXTURE_2 = this
|
|
163
|
+
this.#TEXTURE_1 = this.#createTexture();
|
|
164
|
+
this.#TEXTURE_2 = this.#createTexture();
|
|
165
165
|
|
|
166
166
|
this.#canvasSize = {
|
|
167
167
|
"width": -1,
|
|
@@ -186,14 +186,14 @@ export default class GLImageTransition {
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
|
|
189
|
-
this
|
|
189
|
+
this.#clear();
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
|
|
193
193
|
/**
|
|
194
194
|
* Clean objects and remove all bindings
|
|
195
195
|
*/
|
|
196
|
-
destroy() {
|
|
196
|
+
destroy(): this {
|
|
197
197
|
this.#GL.deleteBuffer( this.#VERTEX_BUFFER );
|
|
198
198
|
this.#GL.deleteBuffer( this.#TEXTURE_BUFFER );
|
|
199
199
|
this.#GL.deleteBuffer( this.#INDEX_BUFFER );
|
|
@@ -202,17 +202,14 @@ export default class GLImageTransition {
|
|
|
202
202
|
this.#GL.deleteShader( this.#VERTEX_SHADER );
|
|
203
203
|
|
|
204
204
|
window.removeEventListener( 'resize', this.#onResize );
|
|
205
|
-
};
|
|
206
205
|
|
|
206
|
+
return this;
|
|
207
|
+
}
|
|
207
208
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
* @param {Number} width
|
|
211
|
-
* @param {Number} height
|
|
212
|
-
*/
|
|
213
|
-
updateCanvasSize( width, height ) {
|
|
209
|
+
|
|
210
|
+
updateCanvasSize( width: number, height: number ): this {
|
|
214
211
|
if ( width === this.#canvasSize.width && height === this.#canvasSize.height ) {
|
|
215
|
-
return;
|
|
212
|
+
return this;
|
|
216
213
|
}
|
|
217
214
|
|
|
218
215
|
this.#canvasSize = {
|
|
@@ -224,32 +221,38 @@ export default class GLImageTransition {
|
|
|
224
221
|
|
|
225
222
|
this.#$CANVAS.setAttribute( 'width', `${ this.#canvasSize.width }` );
|
|
226
223
|
this.#$CANVAS.setAttribute( 'height', `${ this.#canvasSize.height }` );
|
|
227
|
-
|
|
224
|
+
|
|
225
|
+
return this;
|
|
226
|
+
}
|
|
228
227
|
|
|
229
228
|
|
|
230
229
|
/**
|
|
231
230
|
* Start the rendering loop
|
|
232
231
|
*/
|
|
233
|
-
startRender() {
|
|
232
|
+
startRender(): this {
|
|
234
233
|
this.#rafID = requestAnimationFrame( this.#render );
|
|
235
|
-
|
|
234
|
+
|
|
235
|
+
return this;
|
|
236
|
+
}
|
|
236
237
|
|
|
237
238
|
|
|
238
239
|
/**
|
|
239
240
|
* Stop the rendering loop
|
|
240
241
|
*/
|
|
241
|
-
stopRender() {
|
|
242
|
+
stopRender(): this {
|
|
242
243
|
cancelAnimationFrame( this.#rafID );
|
|
243
|
-
|
|
244
|
+
|
|
245
|
+
return this;
|
|
246
|
+
}
|
|
244
247
|
|
|
245
248
|
|
|
246
249
|
/**
|
|
247
250
|
* Load and init of the first displayed image
|
|
248
251
|
*/
|
|
249
252
|
loadAndInitImage( url: string ): this {
|
|
250
|
-
this
|
|
253
|
+
this.#loadImage( url, this.#TEXTURE_1, true )
|
|
251
254
|
.then( $image => {
|
|
252
|
-
|
|
255
|
+
const { naturalWidth, naturalHeight } = $image;
|
|
253
256
|
this.#imagesInfo = {
|
|
254
257
|
"width": naturalWidth,
|
|
255
258
|
"height": naturalHeight,
|
|
@@ -260,7 +263,7 @@ export default class GLImageTransition {
|
|
|
260
263
|
this.#isImage1 = true;
|
|
261
264
|
|
|
262
265
|
return this;
|
|
263
|
-
}
|
|
266
|
+
}
|
|
264
267
|
|
|
265
268
|
|
|
266
269
|
/**
|
|
@@ -270,9 +273,9 @@ export default class GLImageTransition {
|
|
|
270
273
|
*/
|
|
271
274
|
initImage( $image: HTMLImageElement ): this {
|
|
272
275
|
|
|
273
|
-
this
|
|
276
|
+
this.#setTexture( this.#TEXTURE_1, $image );
|
|
274
277
|
|
|
275
|
-
|
|
278
|
+
const { naturalWidth, naturalHeight } = $image;
|
|
276
279
|
|
|
277
280
|
this.#imagesInfo = {
|
|
278
281
|
"width": naturalWidth,
|
|
@@ -283,7 +286,7 @@ export default class GLImageTransition {
|
|
|
283
286
|
this.#isImage1 = true;
|
|
284
287
|
|
|
285
288
|
return this;
|
|
286
|
-
}
|
|
289
|
+
}
|
|
287
290
|
|
|
288
291
|
|
|
289
292
|
/**
|
|
@@ -297,13 +300,13 @@ export default class GLImageTransition {
|
|
|
297
300
|
const currentTexture = this.#isImage1 ? this.#TEXTURE_2 : this.#TEXTURE_1;
|
|
298
301
|
const transitionEdge = this.#isImage1 ? 1 : 0;
|
|
299
302
|
|
|
300
|
-
this
|
|
303
|
+
this.#loadImage( url, currentTexture, false )
|
|
301
304
|
.then( () => {
|
|
302
|
-
this
|
|
305
|
+
this.#tweenTransition( transitionEdge );
|
|
303
306
|
} );
|
|
304
307
|
|
|
305
308
|
return this;
|
|
306
|
-
}
|
|
309
|
+
}
|
|
307
310
|
|
|
308
311
|
|
|
309
312
|
/**
|
|
@@ -317,20 +320,20 @@ export default class GLImageTransition {
|
|
|
317
320
|
}
|
|
318
321
|
|
|
319
322
|
if ( this.#isImage1 ) {
|
|
320
|
-
this
|
|
321
|
-
this
|
|
323
|
+
this.#setTexture( this.#TEXTURE_2, $image );
|
|
324
|
+
this.#tweenTransition( 1 );
|
|
322
325
|
|
|
323
326
|
return this;
|
|
324
327
|
}
|
|
325
328
|
|
|
326
|
-
this
|
|
327
|
-
this
|
|
329
|
+
this.#setTexture( this.#TEXTURE_1, $image );
|
|
330
|
+
this.#tweenTransition( 0 );
|
|
328
331
|
|
|
329
332
|
return this;
|
|
330
|
-
}
|
|
333
|
+
}
|
|
331
334
|
|
|
332
335
|
|
|
333
|
-
|
|
336
|
+
#setTexture = ( texture: WebGLTexture, $image: TexImageSource ): void => {
|
|
334
337
|
this.#GL.bindTexture( this.#GL.TEXTURE_2D, texture );
|
|
335
338
|
this.#GL.texImage2D( this.#GL.TEXTURE_2D, 0, this.#GL.RGBA, this.#GL.RGBA, this.#GL.UNSIGNED_BYTE, $image);
|
|
336
339
|
|
|
@@ -340,7 +343,7 @@ export default class GLImageTransition {
|
|
|
340
343
|
}
|
|
341
344
|
|
|
342
345
|
|
|
343
|
-
|
|
346
|
+
#loadImage = ( url: string, texture: WebGLTexture, isInit: boolean ): Promise<HTMLImageElement> => {
|
|
344
347
|
|
|
345
348
|
return new Promise( ( resolve ) => {
|
|
346
349
|
|
|
@@ -350,7 +353,7 @@ export default class GLImageTransition {
|
|
|
350
353
|
|
|
351
354
|
$IMAGE.addEventListener( 'load', () => {
|
|
352
355
|
|
|
353
|
-
this
|
|
356
|
+
this.#setTexture( texture, $IMAGE );
|
|
354
357
|
|
|
355
358
|
this.#OPTIONS.onImageLoaded && this.#OPTIONS.onImageLoaded.call( $IMAGE, url, isInit );
|
|
356
359
|
|
|
@@ -361,7 +364,7 @@ export default class GLImageTransition {
|
|
|
361
364
|
$IMAGE.addEventListener( 'error', () => {
|
|
362
365
|
this.#OPTIONS.onImageError && this.#OPTIONS.onImageError.call( $IMAGE, url, isInit );
|
|
363
366
|
|
|
364
|
-
this
|
|
367
|
+
this.#setDummyTexture( texture );
|
|
365
368
|
|
|
366
369
|
resolve( $IMAGE );
|
|
367
370
|
} );
|
|
@@ -373,7 +376,7 @@ export default class GLImageTransition {
|
|
|
373
376
|
}
|
|
374
377
|
|
|
375
378
|
|
|
376
|
-
|
|
379
|
+
#getAspect = (): { x: number, y: number } => {
|
|
377
380
|
let horizontalDrawAspect, verticalDrawAspect;
|
|
378
381
|
|
|
379
382
|
|
|
@@ -403,7 +406,7 @@ export default class GLImageTransition {
|
|
|
403
406
|
}
|
|
404
407
|
|
|
405
408
|
|
|
406
|
-
|
|
409
|
+
#_tween = (): void => {
|
|
407
410
|
if ( this.#transition.time >= this.#DURATION ) {
|
|
408
411
|
this.#transition.value = this.#transition.edge;
|
|
409
412
|
this.#transition.isTweening = false;
|
|
@@ -424,11 +427,11 @@ export default class GLImageTransition {
|
|
|
424
427
|
|
|
425
428
|
this.#transition.time += this.#deltaTime;
|
|
426
429
|
|
|
427
|
-
requestAnimationFrame( this
|
|
430
|
+
requestAnimationFrame( this.#_tween.bind( this ) );
|
|
428
431
|
}
|
|
429
432
|
|
|
430
433
|
|
|
431
|
-
|
|
434
|
+
#tweenTransition = ( edge: number ): void => {
|
|
432
435
|
if ( this.#transition.isTweening ) {
|
|
433
436
|
return;
|
|
434
437
|
}
|
|
@@ -446,16 +449,16 @@ export default class GLImageTransition {
|
|
|
446
449
|
|
|
447
450
|
this.#transition.isTweening = true;
|
|
448
451
|
|
|
449
|
-
requestAnimationFrame( this
|
|
452
|
+
requestAnimationFrame( this.#_tween.bind( this ) );
|
|
450
453
|
}
|
|
451
454
|
|
|
452
455
|
|
|
453
|
-
#render = ( time ) => {
|
|
456
|
+
#render = ( time: number ): void => {
|
|
454
457
|
|
|
455
458
|
this.#deltaTime = time - this.#lastLoopTime;
|
|
456
459
|
this.#lastLoopTime = time;
|
|
457
460
|
|
|
458
|
-
this
|
|
461
|
+
this.#clear();
|
|
459
462
|
|
|
460
463
|
if ( !this.#imagesInfo ) {
|
|
461
464
|
this.#rafID = requestAnimationFrame( this.#render );
|
|
@@ -463,7 +466,7 @@ export default class GLImageTransition {
|
|
|
463
466
|
}
|
|
464
467
|
|
|
465
468
|
const projectionMatrix = createMat4();
|
|
466
|
-
const aspectDelta = this
|
|
469
|
+
const aspectDelta = this.#getAspect();
|
|
467
470
|
|
|
468
471
|
orthoMat4( projectionMatrix, -1, 1, -1, 1, 0.0, 10.0 );
|
|
469
472
|
|
|
@@ -532,13 +535,13 @@ export default class GLImageTransition {
|
|
|
532
535
|
}
|
|
533
536
|
|
|
534
537
|
|
|
535
|
-
|
|
536
|
-
return this
|
|
538
|
+
#createTexture = (): WebGLTexture => {
|
|
539
|
+
return this.#setDummyTexture( this.#GL.createTexture() as WebGLTexture );
|
|
537
540
|
}
|
|
538
541
|
|
|
539
542
|
|
|
540
|
-
|
|
541
|
-
const pixel = new Uint8Array( this.#OPTIONS.dummyTextureColor
|
|
543
|
+
#setDummyTexture = ( texture: WebGLTexture ): WebGLTexture => {
|
|
544
|
+
const pixel = new Uint8Array( this.#OPTIONS.dummyTextureColor );
|
|
542
545
|
|
|
543
546
|
this.#GL.bindTexture( this.#GL.TEXTURE_2D, texture );
|
|
544
547
|
|
|
@@ -551,8 +554,8 @@ export default class GLImageTransition {
|
|
|
551
554
|
}
|
|
552
555
|
|
|
553
556
|
|
|
554
|
-
|
|
555
|
-
const SHADER = this.#GL.createShader( type )
|
|
557
|
+
#createShader = ( type: number, source: string ): WebGLShader => {
|
|
558
|
+
const SHADER = this.#GL.createShader( type ) as WebGLShader;
|
|
556
559
|
|
|
557
560
|
this.#GL.shaderSource( SHADER, source );
|
|
558
561
|
this.#GL.compileShader( SHADER );
|
|
@@ -567,18 +570,18 @@ export default class GLImageTransition {
|
|
|
567
570
|
}
|
|
568
571
|
|
|
569
572
|
|
|
570
|
-
|
|
571
|
-
const buffer = this.#GL.createBuffer();
|
|
573
|
+
#createBuffer = ( target: number, data: Float32Array | Uint16Array ): WebGLBuffer => {
|
|
574
|
+
const buffer = this.#GL.createBuffer() as WebGLBuffer;
|
|
572
575
|
|
|
573
576
|
this.#GL.bindBuffer( target, buffer );
|
|
574
577
|
this.#GL.bufferData( target, data, this.#GL.STATIC_DRAW );
|
|
575
578
|
|
|
576
|
-
return buffer
|
|
579
|
+
return buffer;
|
|
577
580
|
}
|
|
578
581
|
|
|
579
582
|
|
|
580
|
-
|
|
581
|
-
|
|
583
|
+
#clear = (): void => {
|
|
584
|
+
const [ r, v, b, a ] = this.#OPTIONS.backgroundColor;
|
|
582
585
|
|
|
583
586
|
// Clear the canvas
|
|
584
587
|
this.#GL.clearColor( r, v, b, a );
|
|
@@ -599,7 +602,7 @@ export default class GLImageTransition {
|
|
|
599
602
|
}
|
|
600
603
|
|
|
601
604
|
|
|
602
|
-
#onResize = () => {
|
|
605
|
+
#onResize = (): void => {
|
|
603
606
|
this.updateCanvasSize( this.#$CANVAS.clientWidth, this.#$CANVAS.clientHeight );
|
|
604
607
|
}
|
|
605
608
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Reveal the next image using cells shape
|
|
3
3
|
* Insipred by @patriciogv - Simple Voronoi
|
|
4
4
|
*/
|
|
5
|
-
export default class Cellular implements
|
|
5
|
+
export default class Cellular implements FLib.GLImageTransition.Preset {
|
|
6
6
|
|
|
7
7
|
#scale: number;
|
|
8
8
|
#seed: number;
|
|
@@ -10,7 +10,7 @@ export default class Cellular implements GLImageTransitionPreset {
|
|
|
10
10
|
#U_SEED!: WebGLUniformLocation | null;
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
get fsSource() {
|
|
13
|
+
get fsSource(): string {
|
|
14
14
|
return `
|
|
15
15
|
#ifdef GL_ES
|
|
16
16
|
precision mediump float;
|
|
@@ -83,23 +83,23 @@ export default class Cellular implements GLImageTransitionPreset {
|
|
|
83
83
|
gl_FragColor = vec4( color, 1.0 );
|
|
84
84
|
}
|
|
85
85
|
`;
|
|
86
|
-
}
|
|
86
|
+
}
|
|
87
87
|
|
|
88
|
-
get scale() {
|
|
88
|
+
get scale(): number {
|
|
89
89
|
return this.#scale;
|
|
90
90
|
}
|
|
91
|
-
get seed() {
|
|
91
|
+
get seed(): number {
|
|
92
92
|
return this.#seed;
|
|
93
93
|
}
|
|
94
|
-
get U_SCALE() {
|
|
94
|
+
get U_SCALE(): WebGLUniformLocation | null {
|
|
95
95
|
return this.#U_SCALE;
|
|
96
96
|
}
|
|
97
|
-
get U_SEED() {
|
|
97
|
+
get U_SEED(): WebGLUniformLocation | null {
|
|
98
98
|
return this.#U_SEED;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
|
|
102
|
-
constructor( scale
|
|
102
|
+
constructor( scale = 10 ) {
|
|
103
103
|
this.#scale = scale;
|
|
104
104
|
this.#seed = Math.random() * 45000;
|
|
105
105
|
}
|
|
@@ -108,7 +108,7 @@ export default class Cellular implements GLImageTransitionPreset {
|
|
|
108
108
|
/**
|
|
109
109
|
* Create specific uniforms for this preset
|
|
110
110
|
*/
|
|
111
|
-
addUniform( GL: WebGLRenderingContext, SHADER_PROGRAM: WebGLProgram ) {
|
|
111
|
+
addUniform( GL: WebGLRenderingContext, SHADER_PROGRAM: WebGLProgram ): void {
|
|
112
112
|
this.#U_SCALE = GL.getUniformLocation( SHADER_PROGRAM, 'uScale' );
|
|
113
113
|
this.#U_SEED = GL.getUniformLocation( SHADER_PROGRAM, 'uSeed' );
|
|
114
114
|
}
|
|
@@ -117,7 +117,7 @@ export default class Cellular implements GLImageTransitionPreset {
|
|
|
117
117
|
/**
|
|
118
118
|
* Update the uniforms of this preset during render
|
|
119
119
|
*/
|
|
120
|
-
updateUniform( GL: WebGLRenderingContext ) {
|
|
120
|
+
updateUniform( GL: WebGLRenderingContext ): void {
|
|
121
121
|
GL.uniform1f( this.#U_SCALE, this.#scale );
|
|
122
122
|
GL.uniform1f( this.#U_SEED, this.#seed );
|
|
123
123
|
}
|
|
@@ -126,7 +126,7 @@ export default class Cellular implements GLImageTransitionPreset {
|
|
|
126
126
|
/**
|
|
127
127
|
* Called each time before a transition
|
|
128
128
|
*/
|
|
129
|
-
onTransitionStart() {
|
|
129
|
+
onTransitionStart(): void {
|
|
130
130
|
this.#seed = Math.random() * 45000;
|
|
131
131
|
}
|
|
132
132
|
}
|