@zcomponent/core 1.29.0 → 2.0.0-alpha.2
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 +1 -0
- package/css/zcomponent.css +121 -122
- package/index.js +0 -3
- package/lib/actionbehavior.d.ts +3 -3
- package/lib/actionbehavior.js +20 -19
- package/lib/animation/animation.d.ts +13 -6
- package/lib/animation/animation.js +56 -43
- package/lib/animation/bezier.d.ts +6 -0
- package/lib/animation/bezier.js +8 -2
- package/lib/animation/clips/clip.d.ts +13 -1
- package/lib/animation/clips/clip.js +34 -14
- package/lib/animation/index.d.ts +4 -4
- package/lib/animation/index.js +4 -4
- package/lib/animation/layer.d.ts +9 -0
- package/lib/animation/layer.js +28 -12
- package/lib/animation/layerclip.d.ts +21 -0
- package/lib/animation/layerclip.js +82 -45
- package/lib/animation/tracks/cliptrack.d.ts +18 -0
- package/lib/animation/tracks/cliptrack.js +27 -6
- package/lib/animation/tracks/functiontrack.d.ts +9 -0
- package/lib/animation/tracks/functiontrack.js +16 -3
- package/lib/animation/tracks/propertytrack.d.ts +20 -1
- package/lib/animation/tracks/propertytrack.js +48 -11
- package/lib/animation/tracks/streamtrack.d.ts +18 -0
- package/lib/animation/tracks/streamtrack.js +32 -6
- package/lib/animation/tracks/track.d.ts +8 -2
- package/lib/animation/tracks/track.js +3 -2
- package/lib/behavior.js +13 -10
- package/lib/behaviors/ActivateState.d.ts +22 -24
- package/lib/behaviors/ActivateState.js +145 -35
- package/lib/behaviors/CallFunction.d.ts +2 -4
- package/lib/behaviors/CallFunction.js +69 -11
- package/lib/behaviors/ChangeRootScene.d.ts +35 -0
- package/lib/behaviors/ChangeRootScene.js +123 -0
- package/lib/behaviors/ConsoleLog.d.ts +6 -5
- package/lib/behaviors/ConsoleLog.js +95 -12
- package/lib/behaviors/DownloadSnapshot.d.ts +7 -12
- package/lib/behaviors/DownloadSnapshot.js +70 -19
- package/lib/behaviors/EmitComponentPropEvent.d.ts +1 -3
- package/lib/behaviors/EmitComponentPropEvent.js +80 -12
- package/lib/behaviors/LaunchURL.d.ts +5 -5
- package/lib/behaviors/LaunchURL.js +92 -10
- package/lib/behaviors/LogAnalyticsEvent.d.ts +10 -4
- package/lib/behaviors/LogAnalyticsEvent.js +88 -7
- package/lib/behaviors/PauseLayerClip.d.ts +7 -9
- package/lib/behaviors/PauseLayerClip.js +89 -21
- package/lib/behaviors/PlayLayerClip.d.ts +35 -32
- package/lib/behaviors/PlayLayerClip.js +202 -48
- package/lib/behaviors/PlaySound.d.ts +19 -25
- package/lib/behaviors/PlaySound.js +122 -28
- package/lib/behaviors/SetLayerOff.d.ts +7 -9
- package/lib/behaviors/SetLayerOff.js +88 -21
- package/lib/behaviors/ShareSnapshot.d.ts +5 -9
- package/lib/behaviors/ShareSnapshot.js +70 -17
- package/lib/behaviors/ShowTextAlert.d.ts +16 -29
- package/lib/behaviors/ShowTextAlert.js +116 -48
- package/lib/behaviors/TakeSnapshot.d.ts +22 -26
- package/lib/behaviors/TakeSnapshot.js +131 -56
- package/lib/behaviors/ToggleLayerClips.d.ts +45 -62
- package/lib/behaviors/ToggleLayerClips.js +233 -64
- package/lib/behaviors/stream/PauseStream.d.ts +5 -16
- package/lib/behaviors/stream/PauseStream.js +94 -34
- package/lib/behaviors/stream/PlayStream.d.ts +14 -27
- package/lib/behaviors/stream/PlayStream.js +123 -34
- package/lib/behaviors/stream/SeekStream.d.ts +8 -18
- package/lib/behaviors/stream/SeekStream.js +97 -31
- package/lib/behaviors/stream/StopStream.d.ts +6 -15
- package/lib/behaviors/stream/StopStream.js +89 -27
- package/lib/component.d.ts +36 -13
- package/lib/component.js +237 -151
- package/lib/components/AnimatedLoader.d.ts +51 -0
- package/lib/components/AnimatedLoader.js +159 -0
- package/lib/components/Audio.d.ts +35 -37
- package/lib/components/Audio.js +264 -151
- package/lib/components/AudioLayerSettings.d.ts +13 -11
- package/lib/components/AudioLayerSettings.js +76 -18
- package/lib/components/Children.d.ts +2 -1
- package/lib/components/Children.js +66 -13
- package/lib/components/ConditionalConstruct.d.ts +44 -0
- package/lib/components/ConditionalConstruct.js +142 -0
- package/lib/components/DefaultCookieConsent.d.ts +53 -73
- package/lib/components/DefaultCookieConsent.js +382 -264
- package/lib/components/DefaultLoader.d.ts +40 -28
- package/lib/components/DefaultLoader.js +198 -46
- package/lib/components/Gamepad.d.ts +5 -26
- package/lib/components/Gamepad.js +201 -65
- package/lib/components/LoaderScope.d.ts +15 -0
- package/lib/components/LoaderScope.js +71 -0
- package/lib/components/LongLoad.d.ts +11 -15
- package/lib/components/LongLoad.js +89 -34
- package/lib/components/SnapshotUI.d.ts +19 -24
- package/lib/components/SnapshotUI.js +202 -105
- package/lib/context.d.ts +23 -5
- package/lib/context.js +12 -6
- package/lib/contexts/analyticscontext.d.ts +12 -2
- package/lib/contexts/analyticscontext.js +68 -10
- package/lib/contexts/audiocontextcontext.d.ts +1 -1
- package/lib/contexts/audiocontextcontext.js +9 -8
- package/lib/contexts/canvascontext.d.ts +32 -18
- package/lib/contexts/canvascontext.js +195 -120
- package/lib/contexts/cookieconsentcontext.d.ts +38 -28
- package/lib/contexts/cookieconsentcontext.js +35 -32
- package/lib/contexts/documentflagmanager.js +15 -11
- package/lib/contexts/environmentcontext.d.ts +22 -6
- package/lib/contexts/environmentcontext.js +135 -21
- package/lib/contexts/gamepadcontext.d.ts +29 -26
- package/lib/contexts/gamepadcontext.js +46 -46
- package/lib/contexts/gesturecontext.d.ts +31 -6
- package/lib/contexts/gesturecontext.js +110 -85
- package/lib/contexts/globaltagcontext.d.ts +1 -1
- package/lib/contexts/globaltagcontext.js +8 -11
- package/lib/contexts/loadcontext.d.ts +45 -8
- package/lib/contexts/loadcontext.js +232 -82
- package/lib/contexts/orientationcontext.d.ts +13 -15
- package/lib/contexts/orientationcontext.js +150 -67
- package/lib/contexts/rootcomponentscontext.d.ts +16 -0
- package/lib/contexts/rootcomponentscontext.js +65 -0
- package/lib/contexts/snapshotContext.d.ts +0 -3
- package/lib/contexts/snapshotContext.js +78 -23
- package/lib/contexts/tagcontext.d.ts +5 -5
- package/lib/contexts/tagcontext.js +16 -16
- package/lib/contexts/textalertcontext.d.ts +1 -5
- package/lib/contexts/textalertcontext.js +1 -5
- package/lib/contexts/usereventcontext.d.ts +1 -1
- package/lib/contexts/usereventcontext.js +12 -12
- package/lib/data/animation.d.ts +10 -2
- package/lib/data/change.d.ts +1 -1
- package/lib/data/change.js +7 -0
- package/lib/data/core.d.ts +9 -1
- package/lib/data/index.d.ts +1 -1
- package/lib/data/index.js +1 -1
- package/lib/decorators.d.ts +348 -0
- package/lib/decorators.js +239 -0
- package/lib/decoratorutils.d.ts +3 -0
- package/lib/decoratorutils.js +8 -0
- package/lib/emitter.d.ts +15 -2
- package/lib/emitter.js +15 -6
- package/lib/entity.d.ts +43 -25
- package/lib/entity.js +104 -71
- package/lib/event.d.ts +2 -1
- package/lib/event.js +1 -4
- package/lib/groups.d.ts +18 -0
- package/lib/groups.js +19 -0
- package/lib/icons.d.ts +3372 -0
- package/lib/icons.js +1 -0
- package/lib/index.d.ts +18 -13
- package/lib/index.js +17 -13
- package/lib/inflate.d.ts +7 -7
- package/lib/inflate.js +5 -5
- package/lib/observable.d.ts +9 -2
- package/lib/observable.js +5 -4
- package/lib/observe.d.ts +18 -0
- package/lib/observe.js +177 -0
- package/lib/profile.d.ts +9 -5
- package/lib/profile.js +27 -17
- package/lib/selectors.d.ts +1 -1
- package/lib/selectors.js +5 -4
- package/lib/types.d.ts +161 -19
- package/lib/types.js +22 -1
- package/lib/values/values.d.ts +7 -8
- package/lib/values/values.js +1 -2
- package/lib/values/valuesmutator.d.ts +4 -1
- package/lib/values/valuesmutator.js +10 -8
- package/lib/zcomponent.d.ts +21 -10
- package/lib/zcomponent.js +717 -540
- package/package.json +22 -5
- package/lib/behaviors/ChangeCursor.d.ts +0 -39
- package/lib/behaviors/ChangeCursor.js +0 -44
|
@@ -1,22 +1,80 @@
|
|
|
1
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
2
|
+
var useValue = arguments.length > 2;
|
|
3
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
4
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
5
|
+
}
|
|
6
|
+
return useValue ? value : void 0;
|
|
7
|
+
};
|
|
8
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
9
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
10
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
11
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
12
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
13
|
+
var _, done = false;
|
|
14
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
15
|
+
var context = {};
|
|
16
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
17
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
18
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
19
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
20
|
+
if (kind === "accessor") {
|
|
21
|
+
if (result === void 0) continue;
|
|
22
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
23
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
24
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
25
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
26
|
+
}
|
|
27
|
+
else if (_ = accept(result)) {
|
|
28
|
+
if (kind === "field") initializers.unshift(_);
|
|
29
|
+
else descriptor[key] = _;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
33
|
+
done = true;
|
|
34
|
+
};
|
|
1
35
|
import { Context } from '../context';
|
|
36
|
+
import { zUI } from '../decorators';
|
|
2
37
|
import { Event } from '../event';
|
|
3
38
|
/** @zcontext */
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
39
|
+
let AnalyticsContext = (() => {
|
|
40
|
+
let _classSuper = Context;
|
|
41
|
+
let _instanceExtraInitializers = [];
|
|
42
|
+
let _logEvent_decorators;
|
|
43
|
+
return class AnalyticsContext extends _classSuper {
|
|
44
|
+
static {
|
|
45
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
46
|
+
_logEvent_decorators = [zUI()];
|
|
47
|
+
__esDecorate(this, null, _logEvent_decorators, { kind: "method", name: "logEvent", static: false, private: false, access: { has: obj => "logEvent" in obj, get: obj => obj.logEvent }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
48
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
49
|
+
}
|
|
50
|
+
onEvent = (__runInitializers(this, _instanceExtraInitializers), new Event());
|
|
51
|
+
/**
|
|
52
|
+
* @zui
|
|
53
|
+
*/
|
|
54
|
+
logEvent(name, params) {
|
|
55
|
+
this.onEvent.emit(name, params);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
})();
|
|
59
|
+
export { AnalyticsContext };
|
|
14
60
|
/**
|
|
15
61
|
* Logs an analytics event.
|
|
16
62
|
*/
|
|
17
63
|
export function logEvent(mgr, name, params) {
|
|
18
64
|
return mgr.get(AnalyticsContext).logEvent(name, params);
|
|
19
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* A decorator that logs an analytics event when the decorated function is called.
|
|
68
|
+
*
|
|
69
|
+
* @param name the name of the event to log
|
|
70
|
+
* @param params any additional parameters to pass ot the analytics provider
|
|
71
|
+
*/
|
|
72
|
+
export function zLogEvent(name, params) {
|
|
73
|
+
return (originalMethod, context) => function (...args) {
|
|
74
|
+
logEvent(this.contextManager, name, params);
|
|
75
|
+
return originalMethod.call(this, ...args);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
20
78
|
/**
|
|
21
79
|
* Returns the analytics onEvent event.
|
|
22
80
|
*/
|
|
@@ -5,6 +5,10 @@ import { nextUserEvent } from './usereventcontext';
|
|
|
5
5
|
* @zcontext
|
|
6
6
|
*/
|
|
7
7
|
export class AudioContextContext extends Context {
|
|
8
|
+
constructorProps;
|
|
9
|
+
audioContext = new AudioContext();
|
|
10
|
+
_layers = new Map();
|
|
11
|
+
layers = this._layers;
|
|
8
12
|
/**
|
|
9
13
|
* Creates an instance of AudioContextContext.
|
|
10
14
|
* @param contextManager - The current ContextManager
|
|
@@ -13,14 +17,6 @@ export class AudioContextContext extends Context {
|
|
|
13
17
|
constructor(contextManager, constructorProps) {
|
|
14
18
|
super(contextManager, constructorProps);
|
|
15
19
|
this.constructorProps = constructorProps;
|
|
16
|
-
this.audioContext = new AudioContext();
|
|
17
|
-
this._layers = new Map();
|
|
18
|
-
this.layers = this._layers;
|
|
19
|
-
this._resumeAudioContext = () => {
|
|
20
|
-
if (this.audioContext.state === 'suspended' && document.visibilityState === 'visible') {
|
|
21
|
-
this.audioContext.resume();
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
20
|
nextUserEvent(contextManager).then(() => {
|
|
25
21
|
this.audioContext.resume();
|
|
26
22
|
document.addEventListener('visibilitychange', this._resumeAudioContext);
|
|
@@ -61,6 +57,11 @@ export class AudioContextContext extends Context {
|
|
|
61
57
|
this.audioContext.close();
|
|
62
58
|
return super.dispose();
|
|
63
59
|
}
|
|
60
|
+
_resumeAudioContext = () => {
|
|
61
|
+
if (this.audioContext.state === 'suspended' && document.visibilityState === 'visible') {
|
|
62
|
+
this.audioContext.resume();
|
|
63
|
+
}
|
|
64
|
+
};
|
|
64
65
|
}
|
|
65
66
|
/**
|
|
66
67
|
* Returns the audio context.
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Context, ContextManager } from '../context';
|
|
2
|
+
import type { Entity, RegisterOptions } from '../entity';
|
|
2
3
|
import { Event } from '../event';
|
|
3
4
|
import { Observable } from '../observable';
|
|
5
|
+
import { ValueOf } from '../types';
|
|
4
6
|
/**
|
|
5
7
|
* Defines options for initializing a `CanvasContext`.
|
|
6
8
|
* - `canvas`: Optional HTMLCanvasElement to be managed.
|
|
@@ -27,8 +29,10 @@ export declare class CanvasContext extends Context {
|
|
|
27
29
|
readonly canvas: HTMLCanvasElement;
|
|
28
30
|
readonly overlayDefault: HTMLDivElement;
|
|
29
31
|
readonly overlay: Observable<HTMLDivElement>;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
readonly size: Observable<[
|
|
33
|
+
number,
|
|
34
|
+
number
|
|
35
|
+
]>;
|
|
32
36
|
private _resizeObserver;
|
|
33
37
|
/**
|
|
34
38
|
* Creates an instance of CanvasContext.
|
|
@@ -55,23 +59,25 @@ export declare class CanvasContext extends Context {
|
|
|
55
59
|
/**
|
|
56
60
|
* Enum representing horizontal alignment options: 'left', 'center', 'right'.
|
|
57
61
|
*/
|
|
58
|
-
export declare
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
62
|
+
export declare const HorizontalAlignment: {
|
|
63
|
+
readonly left: "left";
|
|
64
|
+
readonly leftSafe: "leftSafe";
|
|
65
|
+
readonly center: "center";
|
|
66
|
+
readonly right: "right";
|
|
67
|
+
readonly rightSafe: "rightSafe";
|
|
68
|
+
};
|
|
69
|
+
export type HorizontalAlignmentValue = ValueOf<typeof HorizontalAlignment>;
|
|
65
70
|
/**
|
|
66
71
|
* Enum representing vertical alignment options: 'top', 'center', 'bottom', 'topSafe', 'bottomSafe'.
|
|
67
72
|
*/
|
|
68
|
-
export declare
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
73
|
+
export declare const VerticalAlignment: {
|
|
74
|
+
readonly top: "top";
|
|
75
|
+
readonly topSafe: "topSafe";
|
|
76
|
+
readonly center: "center";
|
|
77
|
+
readonly bottom: "bottom";
|
|
78
|
+
readonly bottomSafe: "bottomSafe";
|
|
79
|
+
};
|
|
80
|
+
export type VerticalAlignmentValue = ValueOf<typeof VerticalAlignment>;
|
|
75
81
|
/**
|
|
76
82
|
* Retrieves the canvas element from the `CanvasContext`.
|
|
77
83
|
* @param {ContextManager} mgr The context manager instance.
|
|
@@ -122,4 +128,12 @@ export declare function useCanvasToArrayBuffer(mgr: ContextManager): Promise<Arr
|
|
|
122
128
|
* @param {VerticalAlignment} v The vertical alignment value.
|
|
123
129
|
* @returns {string} A string of class names for the specified alignments.
|
|
124
130
|
*/
|
|
125
|
-
export declare function classNameForAlignment(h:
|
|
131
|
+
export declare function classNameForAlignment(h: HorizontalAlignmentValue, v: VerticalAlignmentValue): string;
|
|
132
|
+
/**
|
|
133
|
+
* A decorator that will register the decorated function to be called when the canvas `onBeforeRender` event is fired.
|
|
134
|
+
*/
|
|
135
|
+
export declare function zOnBeforeRender<EntityType extends Entity>(opts?: RegisterOptions): (originalMethod: (dt: number) => any, context: ClassMethodDecoratorContext<EntityType>) => any;
|
|
136
|
+
/**
|
|
137
|
+
* A decorator that will register the decorated function to be called when the canvas `onBeforeRender` event is fired.
|
|
138
|
+
*/
|
|
139
|
+
export declare function zOnAfterRender<EntityType extends Entity>(opts?: RegisterOptions): (originalMethod: (dt: number) => any, context: ClassMethodDecoratorContext<EntityType>) => any;
|
|
@@ -1,4 +1,39 @@
|
|
|
1
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
2
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
3
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
4
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
5
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
6
|
+
var _, done = false;
|
|
7
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
8
|
+
var context = {};
|
|
9
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
10
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
11
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
12
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
13
|
+
if (kind === "accessor") {
|
|
14
|
+
if (result === void 0) continue;
|
|
15
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
16
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
17
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
18
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
19
|
+
}
|
|
20
|
+
else if (_ = accept(result)) {
|
|
21
|
+
if (kind === "field") initializers.unshift(_);
|
|
22
|
+
else descriptor[key] = _;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
26
|
+
done = true;
|
|
27
|
+
};
|
|
28
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
29
|
+
var useValue = arguments.length > 2;
|
|
30
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
31
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
32
|
+
}
|
|
33
|
+
return useValue ? value : void 0;
|
|
34
|
+
};
|
|
1
35
|
import { Context } from '../context';
|
|
36
|
+
import { zUI } from '../decorators';
|
|
2
37
|
import { Event } from '../event';
|
|
3
38
|
import { Observable } from '../observable';
|
|
4
39
|
/**
|
|
@@ -11,140 +46,158 @@ import { Observable } from '../observable';
|
|
|
11
46
|
* - `size`: Observable for the canvas size, updated on resize.
|
|
12
47
|
* @zcontext
|
|
13
48
|
* */
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
49
|
+
let CanvasContext = (() => {
|
|
50
|
+
let _classSuper = Context;
|
|
51
|
+
let _size_decorators;
|
|
52
|
+
let _size_initializers = [];
|
|
53
|
+
let _size_extraInitializers = [];
|
|
54
|
+
return class CanvasContext extends _classSuper {
|
|
55
|
+
static {
|
|
56
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
57
|
+
_size_decorators = [zUI()];
|
|
58
|
+
__esDecorate(null, null, _size_decorators, { kind: "field", name: "size", static: false, private: false, access: { has: obj => "size" in obj, get: obj => obj.size, set: (obj, value) => { obj.size = value; } }, metadata: _metadata }, _size_initializers, _size_extraInitializers);
|
|
59
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
60
|
+
}
|
|
61
|
+
constructorProps;
|
|
62
|
+
onBeforeRender = new Event();
|
|
63
|
+
onAfterRender = new Event();
|
|
64
|
+
canvas;
|
|
65
|
+
overlayDefault;
|
|
66
|
+
overlay;
|
|
67
|
+
size = __runInitializers(this, _size_initializers, void 0);
|
|
68
|
+
_resizeObserver = (__runInitializers(this, _size_extraInitializers), new ResizeObserver(entries => {
|
|
26
69
|
for (const entry of entries) {
|
|
27
70
|
if (entry.target !== this.canvas)
|
|
28
71
|
continue;
|
|
29
72
|
this.size.value = [entry.contentRect.width, entry.contentRect.height];
|
|
30
73
|
}
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
this.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
74
|
+
}));
|
|
75
|
+
/**
|
|
76
|
+
* Creates an instance of CanvasContext.
|
|
77
|
+
* @param contextManager - The current ContextManager
|
|
78
|
+
* @param constructorProps - The constructor properties.
|
|
79
|
+
*/
|
|
80
|
+
constructor(contextManager, constructorProps) {
|
|
81
|
+
super(contextManager, constructorProps);
|
|
82
|
+
this.constructorProps = constructorProps;
|
|
83
|
+
if (!constructorProps.canvas) {
|
|
84
|
+
this.canvas = document.createElement('canvas');
|
|
85
|
+
this.canvas.style.position = 'fixed';
|
|
86
|
+
this.canvas.style.top = '0px';
|
|
87
|
+
this.canvas.style.left = '0px';
|
|
88
|
+
this.canvas.style.width = '100%';
|
|
89
|
+
this.canvas.style.height = '100%';
|
|
90
|
+
this.canvas.style.touchAction = 'none';
|
|
91
|
+
this.canvas.style.webkitUserSelect = 'none';
|
|
92
|
+
this.canvas.style.userSelect = 'none';
|
|
93
|
+
document.body.append(this.canvas);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
this.canvas = constructorProps.canvas;
|
|
97
|
+
}
|
|
98
|
+
this.overlayDefault = constructorProps.overlay ?? document.createElement('div');
|
|
99
|
+
this.overlayDefault.id = 'zcomponent-overlay';
|
|
100
|
+
if (!constructorProps.overlay) {
|
|
101
|
+
document.body.append(this.overlayDefault);
|
|
102
|
+
}
|
|
103
|
+
this.overlay = new Observable(this.overlayDefault, undefined, false);
|
|
104
|
+
this.size = new Observable([this.canvas.clientWidth, this.canvas.clientHeight]);
|
|
105
|
+
this._resizeObserver.observe(this.canvas);
|
|
106
|
+
let lastRect;
|
|
107
|
+
this.onBeforeRender.addListener(() => {
|
|
108
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
109
|
+
if (lastRect && lastRect.top === rect.top && lastRect.left === rect.left && lastRect.width === rect.width && lastRect.height === rect.height)
|
|
110
|
+
return;
|
|
111
|
+
this.overlayDefault.style.top = rect.top.toString() + 'px';
|
|
112
|
+
this.overlayDefault.style.left = rect.left.toString() + 'px';
|
|
113
|
+
this.overlayDefault.style.width = rect.width.toString() + 'px';
|
|
114
|
+
this.overlayDefault.style.height = rect.height.toString() + 'px';
|
|
115
|
+
lastRect = rect;
|
|
116
|
+
});
|
|
43
117
|
}
|
|
44
|
-
|
|
45
|
-
|
|
118
|
+
/**
|
|
119
|
+
* Captures the canvas content and returns it as a Data URL after the current frame has rendered.
|
|
120
|
+
* @param type The MIME image format type.
|
|
121
|
+
* @param quality Between 0 and 1 indicating image quality. Defaults to 1.
|
|
122
|
+
*/
|
|
123
|
+
async captureToDataURL(type = 'image/jpeg', quality = 1) {
|
|
124
|
+
await useOnAfterRender(this.contextManager).next;
|
|
125
|
+
return this.canvas.toDataURL(type, quality);
|
|
46
126
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
127
|
+
/**
|
|
128
|
+
* Captures the canvas content and returns it as an ArrayBuffer after the current frame has rendered.
|
|
129
|
+
* @param type The MIME image format type.
|
|
130
|
+
* @param quality Between 0 and 1 indicating image quality. Defaults to 1.
|
|
131
|
+
*/
|
|
132
|
+
async captureToArrayBuffer(type = 'image/jpeg', quality = 1) {
|
|
133
|
+
await useOnAfterRender(this.contextManager).next;
|
|
134
|
+
const blob = await this.canvasToBlob(type, quality);
|
|
135
|
+
return this.blobToArrayBuffer(blob);
|
|
51
136
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
}, type, quality);
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
blobToArrayBuffer(blob) {
|
|
99
|
-
return new Promise((resolve, reject) => {
|
|
100
|
-
const reader = new FileReader();
|
|
101
|
-
reader.onloadend = () => {
|
|
102
|
-
if (reader.result instanceof ArrayBuffer) {
|
|
103
|
-
resolve(reader.result);
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
reject(new Error('Failed to read Blob as ArrayBuffer'));
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
reader.onerror = () => {
|
|
110
|
-
reject(new Error('Error reading Blob as ArrayBuffer'));
|
|
111
|
-
};
|
|
112
|
-
reader.readAsArrayBuffer(blob);
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
dispose() {
|
|
116
|
-
this.onBeforeRender.clearListeners();
|
|
117
|
-
this.onAfterRender.clearListeners();
|
|
118
|
-
this._resizeObserver.disconnect();
|
|
119
|
-
if (!this.constructorProps.canvas)
|
|
120
|
-
this.canvas.remove();
|
|
121
|
-
if (!this.constructorProps.overlay)
|
|
122
|
-
this.overlayDefault.remove();
|
|
123
|
-
return super.dispose();
|
|
124
|
-
}
|
|
125
|
-
}
|
|
137
|
+
canvasToBlob(type, quality) {
|
|
138
|
+
return new Promise((resolve, reject) => {
|
|
139
|
+
this.canvas.toBlob(blob => {
|
|
140
|
+
if (blob) {
|
|
141
|
+
resolve(blob);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
reject(new Error('Failed to capture canvas as Blob'));
|
|
145
|
+
}
|
|
146
|
+
}, type, quality);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
blobToArrayBuffer(blob) {
|
|
150
|
+
return new Promise((resolve, reject) => {
|
|
151
|
+
const reader = new FileReader();
|
|
152
|
+
reader.onloadend = () => {
|
|
153
|
+
if (reader.result instanceof ArrayBuffer) {
|
|
154
|
+
resolve(reader.result);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
reject(new Error('Failed to read Blob as ArrayBuffer'));
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
reader.onerror = () => {
|
|
161
|
+
reject(new Error('Error reading Blob as ArrayBuffer'));
|
|
162
|
+
};
|
|
163
|
+
reader.readAsArrayBuffer(blob);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
dispose() {
|
|
167
|
+
this.onBeforeRender.clearListeners();
|
|
168
|
+
this.onAfterRender.clearListeners();
|
|
169
|
+
this._resizeObserver.disconnect();
|
|
170
|
+
if (!this.constructorProps.canvas)
|
|
171
|
+
this.canvas.remove();
|
|
172
|
+
if (!this.constructorProps.overlay)
|
|
173
|
+
this.overlayDefault.remove();
|
|
174
|
+
return super.dispose();
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
})();
|
|
178
|
+
export { CanvasContext };
|
|
126
179
|
/**
|
|
127
180
|
* Enum representing horizontal alignment options: 'left', 'center', 'right'.
|
|
128
181
|
*/
|
|
129
|
-
export
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
182
|
+
export const HorizontalAlignment = {
|
|
183
|
+
left: 'left',
|
|
184
|
+
leftSafe: 'leftSafe',
|
|
185
|
+
center: 'center',
|
|
186
|
+
right: 'right',
|
|
187
|
+
rightSafe: 'rightSafe',
|
|
188
|
+
};
|
|
189
|
+
Object.freeze(HorizontalAlignment);
|
|
137
190
|
/**
|
|
138
191
|
* Enum representing vertical alignment options: 'top', 'center', 'bottom', 'topSafe', 'bottomSafe'.
|
|
139
192
|
*/
|
|
140
|
-
export
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
193
|
+
export const VerticalAlignment = {
|
|
194
|
+
top: 'top',
|
|
195
|
+
topSafe: 'topSafe',
|
|
196
|
+
center: 'center',
|
|
197
|
+
bottom: 'bottom',
|
|
198
|
+
bottomSafe: 'bottomSafe',
|
|
199
|
+
};
|
|
200
|
+
Object.freeze(VerticalAlignment);
|
|
148
201
|
/**
|
|
149
202
|
* Retrieves the canvas element from the `CanvasContext`.
|
|
150
203
|
* @param {ContextManager} mgr The context manager instance.
|
|
@@ -255,3 +308,25 @@ export function classNameForAlignment(h, v) {
|
|
|
255
308
|
names.push('zcomponent-h-vc');
|
|
256
309
|
return names.join(' ');
|
|
257
310
|
}
|
|
311
|
+
/**
|
|
312
|
+
* A decorator that will register the decorated function to be called when the canvas `onBeforeRender` event is fired.
|
|
313
|
+
*/
|
|
314
|
+
export function zOnBeforeRender(opts) {
|
|
315
|
+
return (originalMethod, context) => {
|
|
316
|
+
context.addInitializer(function () {
|
|
317
|
+
this.register(useOnBeforeRender(this.contextManager), (...args) => this[context.name].call(this, ...args), opts);
|
|
318
|
+
});
|
|
319
|
+
return originalMethod;
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* A decorator that will register the decorated function to be called when the canvas `onBeforeRender` event is fired.
|
|
324
|
+
*/
|
|
325
|
+
export function zOnAfterRender(opts) {
|
|
326
|
+
return (originalMethod, context) => {
|
|
327
|
+
context.addInitializer(function () {
|
|
328
|
+
this.register(useOnAfterRender(this.contextManager), (...args) => this[context.name].call(this, ...args), opts);
|
|
329
|
+
});
|
|
330
|
+
return originalMethod;
|
|
331
|
+
};
|
|
332
|
+
}
|