@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.
Files changed (168) hide show
  1. package/README.md +1 -0
  2. package/css/zcomponent.css +121 -122
  3. package/index.js +0 -3
  4. package/lib/actionbehavior.d.ts +3 -3
  5. package/lib/actionbehavior.js +20 -19
  6. package/lib/animation/animation.d.ts +13 -6
  7. package/lib/animation/animation.js +56 -43
  8. package/lib/animation/bezier.d.ts +6 -0
  9. package/lib/animation/bezier.js +8 -2
  10. package/lib/animation/clips/clip.d.ts +13 -1
  11. package/lib/animation/clips/clip.js +34 -14
  12. package/lib/animation/index.d.ts +4 -4
  13. package/lib/animation/index.js +4 -4
  14. package/lib/animation/layer.d.ts +9 -0
  15. package/lib/animation/layer.js +28 -12
  16. package/lib/animation/layerclip.d.ts +21 -0
  17. package/lib/animation/layerclip.js +82 -45
  18. package/lib/animation/tracks/cliptrack.d.ts +18 -0
  19. package/lib/animation/tracks/cliptrack.js +27 -6
  20. package/lib/animation/tracks/functiontrack.d.ts +9 -0
  21. package/lib/animation/tracks/functiontrack.js +16 -3
  22. package/lib/animation/tracks/propertytrack.d.ts +20 -1
  23. package/lib/animation/tracks/propertytrack.js +48 -11
  24. package/lib/animation/tracks/streamtrack.d.ts +18 -0
  25. package/lib/animation/tracks/streamtrack.js +32 -6
  26. package/lib/animation/tracks/track.d.ts +8 -2
  27. package/lib/animation/tracks/track.js +3 -2
  28. package/lib/behavior.js +13 -10
  29. package/lib/behaviors/ActivateState.d.ts +22 -24
  30. package/lib/behaviors/ActivateState.js +145 -35
  31. package/lib/behaviors/CallFunction.d.ts +2 -4
  32. package/lib/behaviors/CallFunction.js +69 -11
  33. package/lib/behaviors/ChangeRootScene.d.ts +35 -0
  34. package/lib/behaviors/ChangeRootScene.js +123 -0
  35. package/lib/behaviors/ConsoleLog.d.ts +6 -5
  36. package/lib/behaviors/ConsoleLog.js +95 -12
  37. package/lib/behaviors/DownloadSnapshot.d.ts +7 -12
  38. package/lib/behaviors/DownloadSnapshot.js +70 -19
  39. package/lib/behaviors/EmitComponentPropEvent.d.ts +1 -3
  40. package/lib/behaviors/EmitComponentPropEvent.js +80 -12
  41. package/lib/behaviors/LaunchURL.d.ts +5 -5
  42. package/lib/behaviors/LaunchURL.js +92 -10
  43. package/lib/behaviors/LogAnalyticsEvent.d.ts +10 -4
  44. package/lib/behaviors/LogAnalyticsEvent.js +88 -7
  45. package/lib/behaviors/PauseLayerClip.d.ts +7 -9
  46. package/lib/behaviors/PauseLayerClip.js +89 -21
  47. package/lib/behaviors/PlayLayerClip.d.ts +35 -32
  48. package/lib/behaviors/PlayLayerClip.js +202 -48
  49. package/lib/behaviors/PlaySound.d.ts +19 -25
  50. package/lib/behaviors/PlaySound.js +122 -28
  51. package/lib/behaviors/SetLayerOff.d.ts +7 -9
  52. package/lib/behaviors/SetLayerOff.js +88 -21
  53. package/lib/behaviors/ShareSnapshot.d.ts +5 -9
  54. package/lib/behaviors/ShareSnapshot.js +70 -17
  55. package/lib/behaviors/ShowTextAlert.d.ts +16 -29
  56. package/lib/behaviors/ShowTextAlert.js +116 -48
  57. package/lib/behaviors/TakeSnapshot.d.ts +22 -26
  58. package/lib/behaviors/TakeSnapshot.js +131 -56
  59. package/lib/behaviors/ToggleLayerClips.d.ts +45 -62
  60. package/lib/behaviors/ToggleLayerClips.js +233 -64
  61. package/lib/behaviors/stream/PauseStream.d.ts +5 -16
  62. package/lib/behaviors/stream/PauseStream.js +94 -34
  63. package/lib/behaviors/stream/PlayStream.d.ts +14 -27
  64. package/lib/behaviors/stream/PlayStream.js +123 -34
  65. package/lib/behaviors/stream/SeekStream.d.ts +8 -18
  66. package/lib/behaviors/stream/SeekStream.js +97 -31
  67. package/lib/behaviors/stream/StopStream.d.ts +6 -15
  68. package/lib/behaviors/stream/StopStream.js +89 -27
  69. package/lib/component.d.ts +36 -13
  70. package/lib/component.js +237 -151
  71. package/lib/components/AnimatedLoader.d.ts +51 -0
  72. package/lib/components/AnimatedLoader.js +159 -0
  73. package/lib/components/Audio.d.ts +35 -37
  74. package/lib/components/Audio.js +264 -151
  75. package/lib/components/AudioLayerSettings.d.ts +13 -11
  76. package/lib/components/AudioLayerSettings.js +76 -18
  77. package/lib/components/Children.d.ts +2 -1
  78. package/lib/components/Children.js +66 -13
  79. package/lib/components/ConditionalConstruct.d.ts +44 -0
  80. package/lib/components/ConditionalConstruct.js +142 -0
  81. package/lib/components/DefaultCookieConsent.d.ts +53 -73
  82. package/lib/components/DefaultCookieConsent.js +382 -264
  83. package/lib/components/DefaultLoader.d.ts +40 -28
  84. package/lib/components/DefaultLoader.js +198 -46
  85. package/lib/components/Gamepad.d.ts +5 -26
  86. package/lib/components/Gamepad.js +201 -65
  87. package/lib/components/LoaderScope.d.ts +15 -0
  88. package/lib/components/LoaderScope.js +71 -0
  89. package/lib/components/LongLoad.d.ts +11 -15
  90. package/lib/components/LongLoad.js +89 -34
  91. package/lib/components/SnapshotUI.d.ts +19 -24
  92. package/lib/components/SnapshotUI.js +202 -105
  93. package/lib/context.d.ts +23 -5
  94. package/lib/context.js +12 -6
  95. package/lib/contexts/analyticscontext.d.ts +12 -2
  96. package/lib/contexts/analyticscontext.js +68 -10
  97. package/lib/contexts/audiocontextcontext.d.ts +1 -1
  98. package/lib/contexts/audiocontextcontext.js +9 -8
  99. package/lib/contexts/canvascontext.d.ts +32 -18
  100. package/lib/contexts/canvascontext.js +195 -120
  101. package/lib/contexts/cookieconsentcontext.d.ts +38 -28
  102. package/lib/contexts/cookieconsentcontext.js +35 -32
  103. package/lib/contexts/documentflagmanager.js +15 -11
  104. package/lib/contexts/environmentcontext.d.ts +22 -6
  105. package/lib/contexts/environmentcontext.js +135 -21
  106. package/lib/contexts/gamepadcontext.d.ts +29 -26
  107. package/lib/contexts/gamepadcontext.js +46 -46
  108. package/lib/contexts/gesturecontext.d.ts +31 -6
  109. package/lib/contexts/gesturecontext.js +110 -85
  110. package/lib/contexts/globaltagcontext.d.ts +1 -1
  111. package/lib/contexts/globaltagcontext.js +8 -11
  112. package/lib/contexts/loadcontext.d.ts +45 -8
  113. package/lib/contexts/loadcontext.js +232 -82
  114. package/lib/contexts/orientationcontext.d.ts +13 -15
  115. package/lib/contexts/orientationcontext.js +150 -67
  116. package/lib/contexts/rootcomponentscontext.d.ts +16 -0
  117. package/lib/contexts/rootcomponentscontext.js +65 -0
  118. package/lib/contexts/snapshotContext.d.ts +0 -3
  119. package/lib/contexts/snapshotContext.js +78 -23
  120. package/lib/contexts/tagcontext.d.ts +5 -5
  121. package/lib/contexts/tagcontext.js +16 -16
  122. package/lib/contexts/textalertcontext.d.ts +1 -5
  123. package/lib/contexts/textalertcontext.js +1 -5
  124. package/lib/contexts/usereventcontext.d.ts +1 -1
  125. package/lib/contexts/usereventcontext.js +12 -12
  126. package/lib/data/animation.d.ts +10 -2
  127. package/lib/data/change.d.ts +1 -1
  128. package/lib/data/change.js +7 -0
  129. package/lib/data/core.d.ts +9 -1
  130. package/lib/data/index.d.ts +1 -1
  131. package/lib/data/index.js +1 -1
  132. package/lib/decorators.d.ts +348 -0
  133. package/lib/decorators.js +239 -0
  134. package/lib/decoratorutils.d.ts +3 -0
  135. package/lib/decoratorutils.js +8 -0
  136. package/lib/emitter.d.ts +15 -2
  137. package/lib/emitter.js +15 -6
  138. package/lib/entity.d.ts +43 -25
  139. package/lib/entity.js +104 -71
  140. package/lib/event.d.ts +2 -1
  141. package/lib/event.js +1 -4
  142. package/lib/groups.d.ts +18 -0
  143. package/lib/groups.js +19 -0
  144. package/lib/icons.d.ts +3372 -0
  145. package/lib/icons.js +1 -0
  146. package/lib/index.d.ts +18 -13
  147. package/lib/index.js +17 -13
  148. package/lib/inflate.d.ts +7 -7
  149. package/lib/inflate.js +5 -5
  150. package/lib/observable.d.ts +9 -2
  151. package/lib/observable.js +5 -4
  152. package/lib/observe.d.ts +18 -0
  153. package/lib/observe.js +177 -0
  154. package/lib/profile.d.ts +9 -5
  155. package/lib/profile.js +27 -17
  156. package/lib/selectors.d.ts +1 -1
  157. package/lib/selectors.js +5 -4
  158. package/lib/types.d.ts +161 -19
  159. package/lib/types.js +22 -1
  160. package/lib/values/values.d.ts +7 -8
  161. package/lib/values/values.js +1 -2
  162. package/lib/values/valuesmutator.d.ts +4 -1
  163. package/lib/values/valuesmutator.js +10 -8
  164. package/lib/zcomponent.d.ts +21 -10
  165. package/lib/zcomponent.js +717 -540
  166. package/package.json +22 -5
  167. package/lib/behaviors/ChangeCursor.d.ts +0 -39
  168. package/lib/behaviors/ChangeCursor.js +0 -44
package/lib/icons.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/lib/index.d.ts CHANGED
@@ -1,19 +1,24 @@
1
- export { ValuesManager } from './values/values';
2
- export * from './component';
3
- export * from './behavior';
4
1
  export * from './actionbehavior';
5
- export * from './zcomponent';
2
+ export * from './animation';
3
+ export * from './behavior';
4
+ export { CacheOptions, CachePerformer, cache } from './cache';
5
+ export * from './component';
6
6
  export * from './context';
7
- export * from './event';
7
+ export * from './contexts/analyticscontext';
8
+ export * from './contexts/audiocontextcontext';
8
9
  export * from './contexts/canvascontext';
9
- export * from './contexts/loadcontext';
10
10
  export * from './contexts/cookieconsentcontext';
11
- export * from './contexts/analyticscontext';
12
- export * from './contexts/usereventcontext';
13
- export * from './contexts/tagcontext';
11
+ export * from './contexts/environmentcontext';
14
12
  export * from './contexts/gamepadcontext';
13
+ export * from './contexts/loadcontext';
14
+ export * from './contexts/rootcomponentscontext';
15
+ export * from './contexts/tagcontext';
16
+ export * from './contexts/usereventcontext';
17
+ export * from './decorators';
18
+ export * from './event';
19
+ export * from './groups';
15
20
  export * from './observable';
16
- export * from './contexts/environmentcontext';
17
- export * from './contexts/audiocontextcontext';
18
- export * from './animation';
19
- export { cache, CacheOptions, CachePerformer } from './cache';
21
+ export { reset } from './observe';
22
+ export { Angle, Color, EmailAddress, MultilineText, ProjectFile, Proportion, Range, Time, Url, ValueOf } from './types';
23
+ export { ValuesManager } from './values/values';
24
+ export * from './zcomponent';
package/lib/index.js CHANGED
@@ -1,22 +1,26 @@
1
- export { ValuesManager } from './values/values';
2
- export * from './component';
3
- export * from './behavior';
4
1
  export * from './actionbehavior';
5
- export * from './zcomponent';
2
+ export * from './animation';
3
+ export * from './behavior';
4
+ export { cache } from './cache';
5
+ export * from './component';
6
6
  export * from './context';
7
- export * from './event';
7
+ export * from './contexts/analyticscontext';
8
+ export * from './contexts/audiocontextcontext';
8
9
  export * from './contexts/canvascontext';
9
- export * from './contexts/loadcontext';
10
10
  export * from './contexts/cookieconsentcontext';
11
- export * from './contexts/analyticscontext';
12
- export * from './contexts/usereventcontext';
13
- export * from './contexts/tagcontext';
11
+ export * from './contexts/environmentcontext';
14
12
  export * from './contexts/gamepadcontext';
13
+ export * from './contexts/loadcontext';
14
+ export * from './contexts/rootcomponentscontext';
15
+ export * from './contexts/tagcontext';
16
+ export * from './contexts/usereventcontext';
17
+ export * from './decorators';
18
+ export * from './event';
19
+ export * from './groups';
15
20
  export * from './observable';
16
- export * from './contexts/environmentcontext';
17
- export * from './contexts/audiocontextcontext';
18
- export * from './animation';
19
- export { cache } from './cache';
21
+ export { reset } from './observe';
22
+ export { ValuesManager } from './values/values';
23
+ export * from './zcomponent';
20
24
  const link = document.createElement('link');
21
25
  link.setAttribute('rel', 'stylesheet');
22
26
  link.setAttribute('href', new URL('../css/zcomponent.css', import.meta.url).toString());
package/lib/inflate.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { Track } from './animation/tracks/track';
2
- import * as Data from './data';
3
- import { ZComponent } from './zcomponent';
4
- import { Clip } from './animation/clips/clip';
5
1
  import { Animation } from './animation/animation';
6
- import { LayerClip } from './animation/layerclip';
7
- import { Layer } from './animation/layer';
8
- import { ByID } from './data';
9
2
  import { Bezier } from './animation/bezier';
3
+ import { Clip } from './animation/clips/clip';
10
4
  import { Keyframe } from './animation/keyframe';
5
+ import { Layer } from './animation/layer';
6
+ import { LayerClip } from './animation/layerclip';
7
+ import { Track } from './animation/tracks/track';
8
+ import * as Data from './data';
9
+ import { ByID } from './data';
10
+ import { ZComponent } from './zcomponent';
11
11
  /**
12
12
  * Creates a track from the provided data.
13
13
  *
package/lib/inflate.js CHANGED
@@ -1,12 +1,12 @@
1
- import * as Data from './data';
2
- import { PropertyTrack } from './animation/tracks/propertytrack';
1
+ import { Bezier } from './animation/bezier';
3
2
  import { Clip } from './animation/clips/clip';
4
- import { LayerClip } from './animation/layerclip';
5
3
  import { Layer } from './animation/layer';
4
+ import { LayerClip } from './animation/layerclip';
6
5
  import { ClipTrack } from './animation/tracks/cliptrack';
7
- import { Bezier } from './animation/bezier';
8
- import { StreamTrack } from './animation/tracks/streamtrack';
9
6
  import { FunctionTrack } from './animation/tracks/functiontrack';
7
+ import { PropertyTrack } from './animation/tracks/propertytrack';
8
+ import { StreamTrack } from './animation/tracks/streamtrack';
9
+ import * as Data from './data';
10
10
  /**
11
11
  * Creates a track from the provided data.
12
12
  *
@@ -1,5 +1,9 @@
1
1
  import { Emitter } from './emitter';
2
- type Resolved<T, M> = [T] extends [never] ? M : T;
2
+ type Resolved<T, M> = [
3
+ T
4
+ ] extends [
5
+ never
6
+ ] ? M : T;
3
7
  /**
4
8
  * A class that holds a value and watches it for changes (deeply by default).
5
9
  *
@@ -32,7 +36,10 @@ type Resolved<T, M> = [T] extends [never] ? M : T;
32
36
  * @typeParam Type - The type of the contained value
33
37
  * @typeParam TypeInternal - An internal type used to improve automatic type detection
34
38
  */
35
- export declare class Observable<Type = never, TypeInternal extends any[] | [] | never = never> extends Emitter<[Resolved<Type, TypeInternal>]> {
39
+ export declare class Observable<Type = never, TypeInternal extends any[] | [
40
+ ] | never = never> extends Emitter<[
41
+ Resolved<Type, TypeInternal>
42
+ ]> {
36
43
  private _deep;
37
44
  private _proxies;
38
45
  private _value;
package/lib/observable.js CHANGED
@@ -1,5 +1,4 @@
1
1
  /* eslint-disable @typescript-eslint/no-this-alias */
2
- /* eslint-disable @typescript-eslint/adjacent-overload-signatures */
3
2
  import { Emitter } from './emitter';
4
3
  /**
5
4
  * A class that holds a value and watches it for changes (deeply by default).
@@ -34,10 +33,13 @@ import { Emitter } from './emitter';
34
33
  * @typeParam TypeInternal - An internal type used to improve automatic type detection
35
34
  */
36
35
  export class Observable extends Emitter {
36
+ _deep;
37
+ _proxies = new WeakMap();
38
+ _value;
39
+ _default;
37
40
  constructor(def, withHandler, _deep = true, callWithImmediately = false) {
38
41
  super();
39
42
  this._deep = _deep;
40
- this._proxies = new WeakMap();
41
43
  this._default = clone(def, _deep);
42
44
  this._value = this._wrap(clone(def, _deep));
43
45
  if (withHandler)
@@ -63,7 +65,7 @@ export class Observable extends Emitter {
63
65
  if (!shouldWrap(val))
64
66
  return val;
65
67
  if (Array.isArray(target) && p === 'splice') {
66
- return function (...args) {
68
+ return (...args) => {
67
69
  for (let i = 2; i < args.length; i++) {
68
70
  args[i] = clone(args[i], true);
69
71
  }
@@ -116,7 +118,6 @@ export class Observable extends Emitter {
116
118
  this._emit(this._value.proxy);
117
119
  }
118
120
  setValueAtPath(path, val) {
119
- // eslint-disable-next-line @typescript-eslint/no-this-alias
120
121
  let target = this;
121
122
  let key = 'value';
122
123
  for (let i = 0; i < path.length; i++) {
@@ -0,0 +1,18 @@
1
+ import { Event } from './event';
2
+ export interface ObserveOptions {
3
+ shallow?: boolean;
4
+ callImmediately?: boolean;
5
+ priority?: number;
6
+ }
7
+ /**
8
+ * Makes a property on an object observable. Whenever the property changes, the provided function will be called with the new value.
9
+ */
10
+ export declare function observe<ObjectType extends object, PropNameType extends keyof ObjectType>(object: ObjectType, prop: PropNameType, fn: (v: ObjectType[PropNameType]) => void, options?: ObserveOptions): void;
11
+ export declare function unobserve<ObjectType extends object, PropNameType extends keyof ObjectType>(object: ObjectType, prop: PropNameType, fn: (v: ObjectType[PropNameType]) => void): void;
12
+ export declare function notify<ObjectType extends object, PropNameType extends keyof ObjectType>(object: ObjectType, prop: PropNameType): void;
13
+ export declare function makeObservable<T>(entity: object, propName: string, deep?: boolean, forceDefaultUpdate?: boolean): Event<[
14
+ value: T,
15
+ entity: object,
16
+ prop: string
17
+ ]>;
18
+ export declare function reset(entity: object, propName: string): boolean;
package/lib/observe.js ADDED
@@ -0,0 +1,177 @@
1
+ import { Event } from './event';
2
+ const _eventsSymbol = Symbol();
3
+ const _defaultsSymbol = Symbol();
4
+ function getEvent(entity, propName) {
5
+ if (entity[_eventsSymbol] === undefined)
6
+ entity[_eventsSymbol] = new Map();
7
+ return entity[_eventsSymbol].get(propName);
8
+ }
9
+ function setEvent(entity, propName, evt) {
10
+ if (entity[_eventsSymbol] === undefined)
11
+ entity[_eventsSymbol] = new Map();
12
+ entity[_eventsSymbol].set(propName, evt);
13
+ }
14
+ function getDefault(entity, propName) {
15
+ if (entity[_defaultsSymbol] === undefined)
16
+ entity[_defaultsSymbol] = new Map();
17
+ return entity[_defaultsSymbol].get(propName);
18
+ }
19
+ function setDefault(entity, propName, def) {
20
+ if (entity[_defaultsSymbol] === undefined)
21
+ entity[_defaultsSymbol] = new Map();
22
+ entity[_defaultsSymbol].set(propName, def);
23
+ }
24
+ /**
25
+ * Makes a property on an object observable. Whenever the property changes, the provided function will be called with the new value.
26
+ */
27
+ export function observe(object, prop, fn, options) {
28
+ const e = makeObservable(object, prop, !(options?.shallow ?? false));
29
+ e.addListener(fn, options?.priority);
30
+ if (options?.callImmediately)
31
+ fn(object[prop]);
32
+ }
33
+ export function unobserve(object, prop, fn) {
34
+ const e = getEvent(object, prop);
35
+ if (!e)
36
+ return;
37
+ e.removeListener(fn);
38
+ }
39
+ export function notify(object, prop) {
40
+ const e = getEvent(object, prop);
41
+ e?.emit(object[prop], object, prop);
42
+ }
43
+ function resolveDescriptor(obj, propName) {
44
+ const p = Object.getOwnPropertyDescriptor(obj, propName);
45
+ if (p)
46
+ return p;
47
+ const proto = Object.getPrototypeOf(obj);
48
+ if (!proto || proto === Object.prototype)
49
+ return undefined;
50
+ return resolveDescriptor(proto, propName);
51
+ }
52
+ export function makeObservable(entity, propName, deep = true, forceDefaultUpdate = false) {
53
+ let _event = getEvent(entity, propName);
54
+ if (_event) {
55
+ if (forceDefaultUpdate)
56
+ setDefault(entity, propName, clone(entity[propName], deep));
57
+ return _event;
58
+ }
59
+ _event = new Event();
60
+ setEvent(entity, propName, _event);
61
+ setDefault(entity, propName, clone(entity[propName], deep));
62
+ const descriptor = resolveDescriptor(entity, propName);
63
+ let _value = wrap(clone(entity[propName], deep));
64
+ descriptor?.set?.(_value.proxy);
65
+ const _proxies = new WeakMap();
66
+ function getValue() {
67
+ return descriptor?.get ? descriptor?.get?.call(entity) : _value.proxy;
68
+ }
69
+ function wrap(v) {
70
+ if (!shouldWrap(v) || !deep)
71
+ return { proxy: v, target: v };
72
+ return {
73
+ target: v,
74
+ proxy: new Proxy(v, {
75
+ get(target, p, receiver) {
76
+ const val = target[p];
77
+ if (!shouldWrap(val))
78
+ return val;
79
+ if (Array.isArray(target) && p === 'splice') {
80
+ return (...args) => {
81
+ for (let i = 2; i < args.length; i++) {
82
+ args[i] = clone(args[i], true);
83
+ }
84
+ val.apply(target, args);
85
+ _event?.emit(getValue(), entity, propName);
86
+ };
87
+ }
88
+ if (val['__z_is_observable'])
89
+ return val;
90
+ const proxy = _proxies.get(val) || wrap(val);
91
+ _proxies.set(val, proxy);
92
+ return proxy.proxy;
93
+ },
94
+ set(target, p, val) {
95
+ const changed = target[p] !== val;
96
+ target[p] = clone(val, true);
97
+ if (changed)
98
+ _event?.emit(getValue(), entity, propName);
99
+ return true;
100
+ },
101
+ deleteProperty(target, p) {
102
+ const changed = target[p] !== undefined;
103
+ delete target[p];
104
+ if (changed)
105
+ _event?.emit(getValue(), entity, propName);
106
+ return true;
107
+ },
108
+ }),
109
+ };
110
+ }
111
+ Object.defineProperty(entity, propName, {
112
+ enumerable: true,
113
+ get: getValue,
114
+ set: v => {
115
+ const changed = v !== getValue();
116
+ if (descriptor?.get && !descriptor?.set)
117
+ throw new Error('Unable to set property with getter but no setter');
118
+ _value = wrap(clone(v, deep));
119
+ descriptor?.set?.call(entity, _value.proxy);
120
+ if (changed)
121
+ _event?.emit(_value.proxy, entity, propName);
122
+ },
123
+ configurable: true,
124
+ });
125
+ return _event;
126
+ }
127
+ export function reset(entity, propName) {
128
+ if (entity[_defaultsSymbol] === undefined || !entity[_defaultsSymbol].has(propName))
129
+ return false;
130
+ entity[propName] = getDefault(entity, propName);
131
+ return true;
132
+ }
133
+ function shouldWrap(a) {
134
+ if (Array.isArray(a))
135
+ return true;
136
+ if (a === null)
137
+ return false;
138
+ if (typeof a === 'object' && a !== null) {
139
+ const proto = Object.getPrototypeOf(a);
140
+ if (proto === Object.prototype || proto === null)
141
+ return true;
142
+ }
143
+ if (typeof a === 'function')
144
+ return false;
145
+ return false;
146
+ }
147
+ function clone(a, deep) {
148
+ if (!deep) {
149
+ if (Array.isArray(a))
150
+ a.slice();
151
+ if (typeof a === 'object' && a !== null) {
152
+ const proto = Object.getPrototypeOf(a);
153
+ if (proto === Object.prototype || proto === null) {
154
+ return { ...a };
155
+ }
156
+ }
157
+ return a;
158
+ }
159
+ if (Array.isArray(a)) {
160
+ const ret = new Array(a.length);
161
+ for (let i = 0; i < ret.length; i++) {
162
+ ret[i] = clone(a[i], true);
163
+ }
164
+ return ret;
165
+ }
166
+ if (typeof a === 'object' && a !== null) {
167
+ const proto = Object.getPrototypeOf(a);
168
+ if (proto === Object.prototype || proto === null) {
169
+ const ret = Object.create(null);
170
+ for (const entry of Object.getOwnPropertyNames(a)) {
171
+ ret[entry] = clone(a[entry], true);
172
+ }
173
+ return ret;
174
+ }
175
+ }
176
+ return a;
177
+ }
package/lib/profile.d.ts CHANGED
@@ -1,10 +1,12 @@
1
+ import { ValueOf } from './types';
1
2
  /**
2
3
  * The user device type. Can be either desktop or mobile.
3
4
  */
4
- export declare enum DeviceType {
5
- DESKTOP = "desktop",
6
- MOBILE = "mobile"
7
- }
5
+ export declare const DeviceType: {
6
+ readonly DESKTOP: "desktop";
7
+ readonly MOBILE: "mobile";
8
+ };
9
+ export type DeviceTypeValue = ValueOf<typeof DeviceType>;
8
10
  /**
9
11
  * A helper class to store the user device type and other profile related information.
10
12
  */
@@ -15,6 +17,7 @@ export declare class Profile {
15
17
  isDesktop: boolean;
16
18
  /**
17
19
  * Whether the user is muted by default.
20
+ * @default false
18
21
  */
19
22
  muteByDefault: boolean;
20
23
  /**
@@ -27,6 +30,7 @@ export declare class Profile {
27
30
  urlSearchParams: URLSearchParams;
28
31
  /**
29
32
  * Whether the debug mode is enabled. This is enabled by adding the `debug=true` query parameter to the URL.
33
+ * @default false
30
34
  */
31
35
  debugMode: boolean;
32
36
  /**
@@ -36,5 +40,5 @@ export declare class Profile {
36
40
  /**
37
41
  * Returns the user agent type.
38
42
  */
39
- get userAgent(): DeviceType;
43
+ get userAgent(): DeviceTypeValue;
40
44
  }
package/lib/profile.js CHANGED
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * The user device type. Can be either desktop or mobile.
3
3
  */
4
- export var DeviceType;
5
- (function (DeviceType) {
6
- DeviceType["DESKTOP"] = "desktop";
7
- DeviceType["MOBILE"] = "mobile";
8
- })(DeviceType || (DeviceType = {}));
4
+ export const DeviceType = {
5
+ DESKTOP: 'desktop',
6
+ MOBILE: 'mobile',
7
+ };
8
+ Object.freeze(DeviceType);
9
9
  /**
10
10
  * Determines the device type based on the user agent string.
11
11
  *
@@ -23,22 +23,32 @@ function getDeviceType() {
23
23
  * A helper class to store the user device type and other profile related information.
24
24
  */
25
25
  export class Profile {
26
+ /**
27
+ * Whether the user is using a desktop device.
28
+ */
29
+ isDesktop;
30
+ /**
31
+ * Whether the user is muted by default.
32
+ * @default false
33
+ */
34
+ muteByDefault = false;
35
+ /**
36
+ * The client language. This is the language of the browser.
37
+ */
38
+ clientLanguage = window.navigator.language;
39
+ /**
40
+ * The URL search parameters from the current window location.
41
+ */
42
+ urlSearchParams;
43
+ /**
44
+ * Whether the debug mode is enabled. This is enabled by adding the `debug=true` query parameter to the URL.
45
+ * @default false
46
+ */
47
+ debugMode = false;
26
48
  /**
27
49
  * Creates an instance of Profile.
28
50
  */
29
51
  constructor() {
30
- /**
31
- * Whether the user is muted by default.
32
- */
33
- this.muteByDefault = false;
34
- /**
35
- * The client language. This is the language of the browser.
36
- */
37
- this.clientLanguage = window.navigator.language;
38
- /**
39
- * Whether the debug mode is enabled. This is enabled by adding the `debug=true` query parameter to the URL.
40
- */
41
- this.debugMode = false;
42
52
  this.urlSearchParams = new URLSearchParams(window.location.search);
43
53
  this.debugMode = this.urlSearchParams.has('debug') && this.urlSearchParams.get('debug') === 'true';
44
54
  this.isDesktop = getDeviceType() === DeviceType.DESKTOP;
@@ -1,5 +1,5 @@
1
- import { BehaviorByID, EntityPropOverride, Import, NodeByID, ParsedImport, Props, ZComponentData } from './data/core';
2
1
  import * as Data from './data';
2
+ import { BehaviorByID, EntityPropOverride, Import, NodeByID, ParsedImport, Props, ZComponentData } from './data/core';
3
3
  import { ZValues } from './values/values';
4
4
  /**
5
5
  * Parses an import string into a tuple containing the import path and import name.
package/lib/selectors.js CHANGED
@@ -1,9 +1,9 @@
1
- import { EntityPropOverrideType } from './data/core';
2
1
  import * as path from 'path';
3
- import { outputForType } from './types';
4
2
  import * as Data from './data';
5
- import * as VALUES from './values/valuesmutator';
6
3
  import { computeBehaviorHierarchy } from './data';
4
+ import { EntityPropOverrideType } from './data/core';
5
+ import { outputForType } from './types';
6
+ import * as VALUES from './values/valuesmutator';
7
7
  /**
8
8
  * Parses an import string into a tuple containing the import path and import name.
9
9
  *
@@ -325,9 +325,10 @@ export const typeDefinitionForComponent = (nodes, props, constructorProps, scrip
325
325
  `@zicon ${icon ?? 'zcomponent'}`,
326
326
  ...(group ? [`@zgroup ${group}`] : []),
327
327
  ...(tags ?? []).map(tag => `@ztag ${tag}`),
328
+ '@ztag zcomponent',
328
329
  ...(parents ?? []).map(parent => `@zparents ${parent}`),
329
330
  ];
330
- return `import { ZComponent, ContextManager, Observable, Animation, Layer, LayerClip, Event } from "@zcomponent/core";
331
+ return `import { ZComponent, ContextManager, Observable, Animation, Layer, LayerClip, Event, ConstructorForComponent } from "@zcomponent/core";
331
332
 
332
333
  ${importStrings.join('\n')}
333
334