@zcomponent/core 1.20.0-beta → 1.21.0-beta

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.
@@ -65,6 +65,12 @@ export declare class Audio extends Component<undefined, AudioConstructorProps> i
65
65
  * @zdefault 1
66
66
  */
67
67
  readonly volume: Observable<number, never>;
68
+ /** @zprop
69
+ * @zdefault false
70
+ * @zgroup Audio
71
+ * @zgrouppriority 20
72
+ */
73
+ readonly loop: Observable<boolean, never>;
68
74
  /**
69
75
  * @zprop
70
76
  * @zui
@@ -46,6 +46,15 @@ export class Audio extends Component {
46
46
  * @zdefault 1
47
47
  */
48
48
  this.volume = new Observable(1, this._updateVolume);
49
+ /** @zprop
50
+ * @zdefault false
51
+ * @zgroup Audio
52
+ * @zgrouppriority 20
53
+ */
54
+ this.loop = new Observable(false, v => {
55
+ if (this._session)
56
+ this._session.source.loop = v;
57
+ });
49
58
  const audioContextContext = mgr.get(AudioContextContext);
50
59
  this.audioContext = useAudioContext(mgr);
51
60
  this._gain = this.audioContext.createGain();
@@ -101,9 +110,20 @@ export class Audio extends Component {
101
110
  source.playbackRate.value = Math.abs(this._rate);
102
111
  source.buffer = this._rate < 0 ? this._getReversed(this.audioBuffer) : this.audioBuffer;
103
112
  source.connect(this.destination);
113
+ source.loop = this.loop.value;
104
114
  const startedAt = this.audioContext.currentTime - resolvedPlayhead / source.playbackRate.value;
105
115
  source.start(0, resolvedPlayhead);
106
- source.addEventListener('ended', () => this.onEnded.emit(this));
116
+ const onEnded = () => {
117
+ if (this.loop.value) {
118
+ this.onEnded.emit(this);
119
+ this._playhead = 0;
120
+ }
121
+ else {
122
+ this.onEnded.emit(this);
123
+ delete this._session;
124
+ }
125
+ };
126
+ source.addEventListener('ended', onEnded);
107
127
  this._session = { source, startedAt };
108
128
  this.onPlay.emit(this);
109
129
  }
@@ -1,4 +1,4 @@
1
- import { CanvasContext, Observable, registerLoadable } from '..';
1
+ import { CanvasContext, Observable, registerLoadable, useOverlay } from '..';
2
2
  import { TakeSnapshot, ImageFormat } from '../behaviors/TakeSnapshot';
3
3
  import { DownloadSnapshot } from '../behaviors/DownloadSnapshot';
4
4
  import { ShareSnapshot } from '../behaviors/ShareSnapshot';
@@ -99,6 +99,7 @@ export class SnapshotUI extends Component {
99
99
  this.socialShareBehaviours.onShare?.addListener(() => {
100
100
  this.onShare.emit();
101
101
  });
102
+ const overlay = useOverlay(this.contextManager).value;
102
103
  this.shareDiv = new ShareDivElement(showShare, async () => {
103
104
  try {
104
105
  this.socialShareBehaviours.share();
@@ -106,7 +107,7 @@ export class SnapshotUI extends Component {
106
107
  catch (err) {
107
108
  console.error('Error sharing:', err);
108
109
  }
109
- });
110
+ }, overlay);
110
111
  this.captureButton = new CaptureButtonElement(this.contextManager);
111
112
  registerLoadable(this.contextManager, new Promise(resolve => (this.style.onload = resolve)));
112
113
  this.style.rel = 'stylesheet';
@@ -233,7 +234,7 @@ class CaptureButtonElement {
233
234
  circle.style.opacity = '0';
234
235
  ring.style.opacity = '0.8';
235
236
  });
236
- document.body.appendChild(this.button);
237
+ canvasContext.overlay.value.appendChild(this.button);
237
238
  }
238
239
  get onClick() {
239
240
  return this.clickEvent;
@@ -251,8 +252,9 @@ class ShareDivElement {
251
252
  * @param withShareButton - Whether to include a share button.
252
253
  * @param shareFunction - The function to call when the share button is clicked.
253
254
  */
254
- constructor(withShareButton, shareFunction) {
255
+ constructor(withShareButton, shareFunction, rootDom = document.body) {
255
256
  this.shareFunction = shareFunction;
257
+ this.rootDom = rootDom;
256
258
  this.onDownload = new Event();
257
259
  // public onShare = new Event();
258
260
  this.onClose = new Event();
@@ -274,7 +276,7 @@ class ShareDivElement {
274
276
  `;
275
277
  const temporaryElement = document.createElement('div');
276
278
  temporaryElement.innerHTML = template.trim();
277
- document.body.appendChild(temporaryElement.firstElementChild);
279
+ rootDom.appendChild(temporaryElement.firstElementChild);
278
280
  const div = document.getElementById('social-share-div');
279
281
  div.style.display = 'none';
280
282
  const saveButton = document.getElementById('zee-save-button');
@@ -297,7 +299,8 @@ class ShareDivElement {
297
299
  button.addEventListener('mouseup', () => {
298
300
  button.classList.remove('active');
299
301
  });
300
- button.addEventListener('touchstart', () => {
302
+ button.addEventListener('touchstart', e => {
303
+ e.preventDefault();
301
304
  isCancelled = false;
302
305
  button.classList.add('active');
303
306
  document.addEventListener('touchmove', handleTouchMove);
@@ -312,7 +315,8 @@ class ShareDivElement {
312
315
  button.classList.remove('hover');
313
316
  }
314
317
  };
315
- const handleTouchEnd = () => {
318
+ const handleTouchEnd = e => {
319
+ e.preventDefault();
316
320
  document.removeEventListener('touchmove', handleTouchMove);
317
321
  document.removeEventListener('touchend', handleTouchEnd);
318
322
  if (!isCancelled) {
@@ -332,19 +336,20 @@ class ShareDivElement {
332
336
  this.shareFunction();
333
337
  });
334
338
  }
335
- addEvents(closeButton, this.onClose);
339
+ addEvents(closeButton, () => {
340
+ this.hide();
341
+ this.onClose.emit();
342
+ });
336
343
  closeButton.addEventListener('click', () => {
337
344
  div.style.display = 'none';
338
345
  });
339
346
  }
340
347
  hide() {
341
348
  const div = document.querySelector('#social-share-div');
342
- document.body.style.overflow = 'auto';
343
349
  div.style.display = 'none';
344
350
  }
345
351
  show() {
346
352
  const div = document.querySelector('#social-share-div');
347
- document.body.style.overflow = 'hidden';
348
353
  div.style.display = 'block';
349
354
  }
350
355
  }
package/lib/types.d.ts CHANGED
@@ -151,6 +151,8 @@ export type Type = StringPrimitiveType | NumberPrimitiveType | BooleanPrimitiveT
151
151
  export declare enum TypeHint {
152
152
  'proportion' = "proportion",
153
153
  'color-norm-rgb' = "color-norm-rgb",
154
+ 'color-norm-rgb-srgb' = "color-norm-rgb-srgb",
155
+ 'color-norm-rgb-linear' = "color-norm-rgb-linear",
154
156
  'color-norm-rgba' = "color-norm-rgba",
155
157
  'color-unnorm-rgb' = "color-unnorm-rgb",
156
158
  'color-unnorm-rgba' = "color-unnorm-rgba",
package/lib/types.js CHANGED
@@ -29,6 +29,8 @@ export var TypeHint;
29
29
  (function (TypeHint) {
30
30
  TypeHint["proportion"] = "proportion";
31
31
  TypeHint["color-norm-rgb"] = "color-norm-rgb";
32
+ TypeHint["color-norm-rgb-srgb"] = "color-norm-rgb-srgb";
33
+ TypeHint["color-norm-rgb-linear"] = "color-norm-rgb-linear";
32
34
  TypeHint["color-norm-rgba"] = "color-norm-rgba";
33
35
  TypeHint["color-unnorm-rgb"] = "color-unnorm-rgb";
34
36
  TypeHint["color-unnorm-rgba"] = "color-unnorm-rgba";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zcomponent/core",
3
- "version": "1.20.0-beta",
3
+ "version": "1.21.0-beta",
4
4
  "description": "The core component model and built-in functionality for Mattercraft.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",