zimjs 20.0.7 → 20.0.9

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/zim.js +394 -440
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zimjs",
3
- "version": "20.0.7",
3
+ "version": "20.0.9",
4
4
  "type": "module",
5
5
  "main": "./src/zim.js",
6
6
  "types": "./ts-src/typings/zim",
package/src/zim.js CHANGED
@@ -58287,10 +58287,15 @@ Automatically manages user sensor permission via ZIM PermissionAsk if permission
58287
58287
  NOTE: If permission has already been granted, tilt activates immediately.
58288
58288
  If multiple objects call tilt(), turn(), or shake() before permission is granted, they are queued and activated together once the user accepts.
58289
58289
 
58290
+ NOTE: To change the text of the Dialog set: F.sensorText = "OKAY?"; // BEFORE calling the tilt()
58291
+ To change buttons of the Dialog set: F.sensorAsk.yes.text = "OUI"; F.sensorAsk.no.text = "NON"; // AFTER calling the tilt()
58292
+
58290
58293
  ALSO: see noTilt() to remove tilt behaviors.
58291
58294
 
58292
58295
  ALSO: see tiltBoundary() to dynamically change or clear the boundary rectangle.
58293
58296
 
58297
+ SEE: https://zimjs.com/020/tilt.html
58298
+
58294
58299
  EXAMPLE
58295
58300
  // Basic rolling ball constrained to stage bounds
58296
58301
  const ball = new Circle(30, red)
@@ -58323,135 +58328,135 @@ ready - (default null) callback function called when permission resolves, receiv
58323
58328
 
58324
58329
  RETURNS obj for chaining
58325
58330
  --*///+34.9
58326
- zim.tilt = function(obj, boundary, damp, factor, mode, type, ready) {
58327
- var sig = "obj, boundary, damp, factor, mode, type, ready";
58328
- var duo; if (duo = zob(zim.tilt, arguments, sig)) return duo;
58329
- if ((obj.type=="AC"||(obj.type=="Emoji"&&obj.svg&&obj.svg.type=="AC"))&&WW.zdf) {WW.zdf.ac("tilt", arguments); return obj;}
58330
- z_d("34.9");
58331
+ zim.tilt = function(obj, boundary, damp, factor, mode, type, ready) {
58332
+ var sig = "obj, boundary, damp, factor, mode, type, ready";
58333
+ var duo; if (duo = zob(zim.tilt, arguments, sig)) return duo;
58334
+ if ((obj.type=="AC"||(obj.type=="Emoji"&&obj.svg&&obj.svg.type=="AC"))&&WW.zdf) {WW.zdf.ac("tilt", arguments); return obj;}
58335
+ z_d("34.9");
58331
58336
 
58332
- // MONITOR
58333
- var mID = "z~tilt";
58334
- if (obj && obj.mID && ((obj.mID[2] && obj.mID[2]=="-") || obj.mID[0]=="-")) mID = "z~-";
58337
+ // MONITOR
58338
+ var mID = "z~tilt";
58339
+ if (obj && obj.mID && ((obj.mID[2] && obj.mID[2]=="-") || obj.mID[0]=="-")) mID = "z~-";
58335
58340
 
58336
- if (zot(obj)) return;
58341
+ if (zot(obj)) return;
58337
58342
 
58338
- // Clean up any existing tilt on this object first
58339
- if (obj._tiltTicker) zim.noTilt(obj);
58340
-
58341
- var f = obj.frame || (typeof zdf != "undefined" ? zdf : WW.zdf);
58342
- var s = obj.stage || (f ? f.stage : null);
58343
-
58344
- // Set initial boundary
58345
- zim.tiltBoundary(obj, boundary);
58346
-
58347
- if (zot(damp)) damp = 0.05;
58348
- if (zot(factor)) factor = 0.5;
58349
- var factorX = typeof factor === "object" ? factor.x : factor;
58350
- var factorY = typeof factor === "object" ? factor.y : factor;
58351
- if (zot(mode)) mode = "move";
58352
- if (zot(type)) type = "deviceorientation";
58353
-
58354
- var dampX = damp ? new zim.Damp(mode == "position" ? obj.x : 0, damp) : null;
58355
- var dampY = damp ? new zim.Damp(mode == "position" ? obj.y : 0, damp) : null;
58356
- var currentRot = {x: 0, y: 0, z: 0};
58357
-
58358
- function updateTilt() {
58359
- var orient = 0;
58360
- if (typeof WW != "undefined") {
58361
- if (WW.screen && WW.screen.orientation && WW.screen.orientation.angle != null) {
58362
- orient = WW.screen.orientation.angle;
58363
- } else if (typeof WW.orientation != "undefined") {
58364
- orient = WW.orientation;
58365
- }
58366
- }
58367
-
58368
- var beta = currentRot.x;
58369
- var gamma = currentRot.y;
58370
- var tiltX, tiltY;
58371
-
58372
- if (orient == 90) {
58373
- tiltX = beta;
58374
- tiltY = -gamma;
58375
- } else if (orient == -90 || orient == 270) {
58376
- tiltX = -beta;
58377
- tiltY = gamma;
58378
- } else if (orient == 180) {
58379
- tiltX = -gamma;
58380
- tiltY = -beta;
58381
- } else {
58382
- tiltX = gamma;
58383
- tiltY = beta;
58384
- }
58343
+ // Clean up any existing tilt on this object first
58344
+ if (obj._tiltTicker) zim.noTilt(obj);
58385
58345
 
58386
- if (mode == "move") {
58387
- var rotX = dampX ? dampX.convert(tiltX) : tiltX;
58388
- var rotY = dampY ? dampY.convert(tiltY) : tiltY;
58389
- obj.x += rotX * factorX;
58390
- obj.y += rotY * factorY;
58391
- } else if (mode == "position") {
58392
- var targetX = (obj._tiltStartX != null ? obj._tiltStartX : obj.x) + tiltX * factorX * 10;
58393
- var targetY = (obj._tiltStartY != null ? obj._tiltStartY : obj.y) + tiltY * factorY * 10;
58394
- obj.x = dampX ? dampX.convert(targetX) : targetX;
58395
- obj.y = dampY ? dampY.convert(targetY) : targetY;
58396
- }
58346
+ var f = obj.frame || (typeof zdf != "undefined" ? zdf : WW.zdf);
58347
+ var s = obj.stage || (f ? f.stage : null);
58397
58348
 
58398
- if (obj._tiltBoundary) {
58399
- obj.x = zim.constrain(obj.x, obj._tiltBoundary.x, obj._tiltBoundary.x + obj._tiltBoundary.width);
58400
- obj.y = zim.constrain(obj.y, obj._tiltBoundary.y, obj._tiltBoundary.y + obj._tiltBoundary.height);
58401
- }
58349
+ // Set initial boundary
58350
+ zim.tiltBoundary(obj, boundary);
58402
58351
 
58403
- if (s) s.update();
58404
- }
58352
+ if (zot(damp)) damp = 0.05;
58353
+ if (zot(factor)) factor = 0.5;
58354
+ var factorX = typeof factor === "object" ? factor.x : factor;
58355
+ var factorY = typeof factor === "object" ? factor.y : factor;
58356
+ if (zot(mode)) mode = "move";
58357
+ if (zot(type)) type = "deviceorientation";
58405
58358
 
58406
- function activate() {
58407
- obj._tiltStartX = obj.x;
58408
- obj._tiltStartY = obj.y;
58409
- if (mode == "position" && dampX && dampY) {
58410
- dampX.immediate(obj.x);
58411
- dampY.immediate(obj.y);
58412
- }
58413
-
58414
- obj._tiltType = type;
58415
- obj._tiltListener = function(e) {
58416
- if (e.rotation) {
58417
- currentRot.x = e.rotation.x || 0;
58418
- currentRot.y = e.rotation.y || 0;
58419
- currentRot.z = e.rotation.z || 0;
58359
+ var dampX = damp ? new zim.Damp(mode == "position" ? obj.x : 0, damp) : null;
58360
+ var dampY = damp ? new zim.Damp(mode == "position" ? obj.y : 0, damp) : null;
58361
+ var currentRot = {x: 0, y: 0, z: 0};
58362
+
58363
+ function updateTilt() {
58364
+ var orient = 0;
58365
+ if (typeof WW != "undefined") {
58366
+ if (WW.screen && WW.screen.orientation && WW.screen.orientation.angle != null) {
58367
+ orient = WW.screen.orientation.angle;
58368
+ } else if (typeof WW.orientation != "undefined") {
58369
+ orient = WW.orientation;
58370
+ }
58371
+ }
58372
+
58373
+ var beta = currentRot.x;
58374
+ var gamma = currentRot.y;
58375
+ var tiltX, tiltY;
58376
+
58377
+ if (orient == 90) {
58378
+ tiltX = beta;
58379
+ tiltY = -gamma;
58380
+ } else if (orient == -90 || orient == 270) {
58381
+ tiltX = -beta;
58382
+ tiltY = gamma;
58383
+ } else if (orient == 180) {
58384
+ tiltX = -gamma;
58385
+ tiltY = -beta;
58420
58386
  } else {
58421
- currentRot.x = e.beta || 0;
58422
- currentRot.y = e.gamma || 0;
58423
- currentRot.z = e.alpha || 0;
58387
+ tiltX = gamma;
58388
+ tiltY = beta;
58424
58389
  }
58425
- };
58426
- f.on(type, obj._tiltListener);
58427
58390
 
58428
- obj._tiltTicker = zim.Ticker.add(updateTilt);
58429
- if (ready) ready(true, obj);
58430
- }
58391
+ if (mode == "move") {
58392
+ var rotX = dampX ? dampX.convert(tiltX) : tiltX;
58393
+ var rotY = dampY ? dampY.convert(tiltY) : tiltY;
58394
+ obj.x += rotX * factorX;
58395
+ obj.y += rotY * factorY;
58396
+ } else if (mode == "position") {
58397
+ var targetX = (obj._tiltStartX != null ? obj._tiltStartX : obj.x) + tiltX * factorX * 10;
58398
+ var targetY = (obj._tiltStartY != null ? obj._tiltStartY : obj.y) + tiltY * factorY * 10;
58399
+ obj.x = dampX ? dampX.convert(targetX) : targetX;
58400
+ obj.y = dampY ? dampY.convert(targetY) : targetY;
58401
+ }
58431
58402
 
58432
- // Simple function queue
58433
- if (f._permissionGranted) {
58434
- activate();
58435
- } else if (f._permissionPending) {
58436
- f._permissionQueue.push(activate);
58437
- } else {
58438
- f._permissionPending = true;
58439
- f._permissionQueue = [activate];
58403
+ if (obj._tiltBoundary) {
58404
+ obj.x = zim.constrain(obj.x, obj._tiltBoundary.x, obj._tiltBoundary.x + obj._tiltBoundary.width);
58405
+ obj.y = zim.constrain(obj.y, obj._tiltBoundary.y, obj._tiltBoundary.y + obj._tiltBoundary.height);
58406
+ }
58440
58407
 
58441
- new zim.PermissionAsk(function(yes) {
58442
- f._permissionPending = false;
58443
- if (yes) {
58444
- f._permissionGranted = true;
58445
- zim.loop(f._permissionQueue, function(fn) { fn(); });
58408
+ if (s) s.update();
58409
+ }
58410
+
58411
+ function activate() {
58412
+ obj._tiltStartX = obj.x;
58413
+ obj._tiltStartY = obj.y;
58414
+ if (mode == "position" && dampX && dampY) {
58415
+ dampX.immediate(obj.x);
58416
+ dampY.immediate(obj.y);
58417
+ }
58418
+
58419
+ obj._tiltType = type;
58420
+ obj._tiltListener = function(e) {
58421
+ if (e.rotation) {
58422
+ currentRot.x = e.rotation.x || 0;
58423
+ currentRot.y = e.rotation.y || 0;
58424
+ currentRot.z = e.rotation.z || 0;
58425
+ } else {
58426
+ currentRot.x = e.beta || 0;
58427
+ currentRot.y = e.gamma || 0;
58428
+ currentRot.z = e.alpha || 0;
58429
+ }
58430
+ };
58431
+ f.on(type, obj._tiltListener);
58432
+
58433
+ obj._tiltTicker = zim.Ticker.add(updateTilt);
58434
+ if (ready) ready(true, obj);
58435
+ }
58436
+
58437
+ // Shared Permission check & queueing
58438
+ if (f._permissionGranted) {
58439
+ activate();
58440
+ } else if (f._permissionPending) {
58441
+ f._permissionQueue.push({ activate: activate, reject: function() { if (ready) ready(false, obj); } });
58442
+ } else {
58443
+ f._permissionPending = true;
58444
+ f._permissionQueue = [{ activate: activate, reject: function() { if (ready) ready(false, obj); } }];
58445
+
58446
+ new zim.PermissionAsk(function(yes) {
58447
+ f._permissionPending = false;
58448
+ if (yes) {
58449
+ f._permissionGranted = true;
58450
+ zim.loop(f._permissionQueue, function(item) { item.activate(); });
58451
+ } else {
58452
+ zim.loop(f._permissionQueue, function(item) { item.reject(); });
58453
+ }
58446
58454
  f._permissionQueue = [];
58447
- } else {
58448
- if (ready) ready(false, obj);
58449
- }
58450
- }, type);
58451
- }
58455
+ }, type);
58456
+ }
58452
58457
 
58453
- return obj;
58454
- };//-34.9
58458
+ return obj;
58459
+ };//-34.9
58455
58460
 
58456
58461
 
58457
58462
  /*--
@@ -58472,33 +58477,31 @@ END EXAMPLE
58472
58477
 
58473
58478
  RETURNS obj for chaining
58474
58479
  --*///+34.91
58475
- zim.noTilt = function(obj) {
58476
- var sig = "obj";
58477
- var duo; if (duo = zob(zim.noTilt, arguments, sig)) return duo;
58478
- z_d("34.91");
58479
-
58480
- if (zot(obj) || !obj.on || !obj.zimTouch) return;
58480
+ zim.noTilt = function(obj) {
58481
+ var sig = "obj";
58482
+ var duo; if (duo = zob(zim.noTilt, arguments, sig)) return duo;
58483
+ z_d("34.91");
58481
58484
 
58482
- // MONITOR
58483
- var mID = "z~noTilt";
58484
- if (obj && obj.mID && ((obj.mID[2] && obj.mID[2]=="-") || obj.mID[0]=="-")) mID = "z~-";
58485
-
58486
- if (zot(obj)) return;
58487
- var f = obj.frame || (typeof zdf != "undefined" ? zdf : WW.zdf);
58485
+ if (zot(obj) || !obj.on || !obj.zimTouch) return;
58488
58486
 
58489
- if (obj._tiltListener && f) {
58490
- f.off(obj._tiltType || "deviceorientation", obj._tiltListener);
58491
- obj._tiltListener = null;
58492
- }
58493
- if (obj._tiltTicker) {
58494
- zim.Ticker.remove(obj._tiltTicker);
58495
- obj._tiltTicker = null;
58496
- }
58497
- obj._tiltBoundary = null;
58487
+ // MONITOR
58488
+ var mID = "z~noTilt";
58489
+ if (obj && obj.mID && ((obj.mID[2] && obj.mID[2]=="-") || obj.mID[0]=="-")) mID = "z~-";
58490
+
58491
+ var f = obj.frame || (typeof zdf != "undefined" ? zdf : WW.zdf);
58498
58492
 
58499
- return obj;
58493
+ if (obj._tiltListener && f) {
58494
+ f.off(obj._tiltType || "deviceorientation", obj._tiltListener);
58495
+ obj._tiltListener = null;
58496
+ }
58497
+ if (obj._tiltTicker) {
58498
+ zim.Ticker.remove(obj._tiltTicker);
58499
+ obj._tiltTicker = null;
58500
+ }
58501
+ obj._tiltBoundary = null;
58500
58502
 
58501
- };//-34.91
58503
+ return obj;
58504
+ };//-34.91
58502
58505
 
58503
58506
 
58504
58507
  /*--
@@ -58610,8 +58613,13 @@ NOTE: If permission has already been granted, turn activates immediately.
58610
58613
  If multiple objects call tilt(), turn(), or shake() before permission is granted, they are queued and activated together once the user accepts.
58611
58614
  Rotation is applied relative to the object's initial rotation when turn() is called (for example, an arrow rotated -90 to point up will maintain that -90 offset).
58612
58615
 
58616
+ NOTE: To change the text of the Dialog set: F.sensorText = "OKAY?"; // BEFORE calling the turn()
58617
+ To change buttons of the Dialog set: F.sensorAsk.yes.text = "OUI"; F.sensorAsk.no.text = "NON"; // AFTER calling the turn()
58618
+
58613
58619
  ALSO: see noTurn() to remove turning behaviors.
58614
58620
 
58621
+ SEE: https://zimjs.com/020/turn.html
58622
+
58615
58623
  EXAMPLE
58616
58624
  // Point an arrow with device heading (stays pointing up in world space)
58617
58625
  const arrow = new Arrow({type:"thick"}).sca(4).rot(-90).centerReg().turn();
@@ -58669,7 +58677,8 @@ RETURNS obj for chaining
58669
58677
  var dampRot = damp ? new zim.Damp(obj.rotation, damp) : null;
58670
58678
  var startDeviceAngle = null;
58671
58679
  var currentDeviceAngle = null;
58672
- var lastMode = null;
58680
+ var lastSteerAng = null;
58681
+ var lastFlatAng = null;
58673
58682
 
58674
58683
  function angleDiff(a, b) {
58675
58684
  var diff = (a - b) % 360;
@@ -58686,28 +58695,18 @@ RETURNS obj for chaining
58686
58695
  }
58687
58696
 
58688
58697
  function updateTurn() {
58689
- if (startDeviceAngle === null || currentDeviceAngle === null) return;
58690
-
58691
- var orient = 0;
58692
- if (typeof WW != "undefined") {
58693
- if (WW.screen && WW.screen.orientation && WW.screen.orientation.angle != null) {
58694
- orient = WW.screen.orientation.angle;
58695
- } else if (typeof WW.orientation != "undefined") {
58696
- orient = WW.orientation;
58697
- }
58698
- }
58698
+ if (currentDeviceAngle === null) return;
58699
58699
 
58700
58700
  var startRot = obj._turnStartRot != null ? obj._turnStartRot : 0;
58701
58701
  var targetRot = obj.rotation;
58702
58702
 
58703
58703
  if (mode == "relative") {
58704
- var diff = angleDiff(currentDeviceAngle, startDeviceAngle);
58704
+ var diff = currentDeviceAngle - (startDeviceAngle || 0);
58705
58705
  targetRot = startRot - diff * factor;
58706
58706
  } else if (mode == "absolute") {
58707
- var absHeading = (currentDeviceAngle - orient + 360) % 360;
58708
- targetRot = startRot - absHeading * factor;
58707
+ targetRot = startRot - currentDeviceAngle * factor;
58709
58708
  } else if (mode == "continuous") {
58710
- var cDiff = angleDiff(currentDeviceAngle, startDeviceAngle);
58709
+ var cDiff = angleDiff(currentDeviceAngle, startDeviceAngle || 0);
58711
58710
  targetRot = obj.rotation - (cDiff * factor * 0.05);
58712
58711
  }
58713
58712
 
@@ -58729,39 +58728,67 @@ RETURNS obj for chaining
58729
58728
  obj._turnStartRot = obj.rotation;
58730
58729
  startDeviceAngle = null;
58731
58730
  currentDeviceAngle = null;
58732
- lastMode = null;
58731
+ lastSteerAng = null;
58732
+ lastFlatAng = null;
58733
58733
  if (dampRot) dampRot.immediate(obj.rotation);
58734
58734
 
58735
58735
  obj._turnType = type;
58736
58736
  obj._turnListener = function(e) {
58737
+ var orient = 0;
58738
+ if (typeof WW != "undefined") {
58739
+ if (WW.screen && WW.screen.orientation && WW.screen.orientation.angle != null) {
58740
+ orient = WW.screen.orientation.angle;
58741
+ } else if (typeof WW.orientation != "undefined") {
58742
+ orient = WW.orientation;
58743
+ }
58744
+ }
58745
+
58737
58746
  var beta = e.rotation ? e.rotation.x : (e.beta || 0);
58738
58747
  var gamma = e.rotation ? e.rotation.y : (e.gamma || 0);
58739
- var alpha = e.rotation && e.rotation.z != null ? e.rotation.z : (e.alpha != null ? (360 - e.alpha) : 0);
58748
+ var alpha = e.rotation && e.rotation.z != null ? e.rotation.z : (e.alpha != null ? (360 - e.alpha) % 360 : 0);
58740
58749
 
58741
- var isUpright = Math.abs(beta) > 20 || Math.abs(gamma) > 20;
58742
- var curMode = isUpright ? "upright" : "flat";
58743
- var ang;
58744
-
58745
- if (isUpright) {
58746
- var radB = beta * (Math.PI / 180);
58747
- var radG = gamma * (Math.PI / 180);
58748
- ang = Math.atan2(Math.sin(radG), Math.cos(radG) * Math.sin(radB)) * (180 / Math.PI);
58750
+ var tiltX, tiltY;
58751
+ if (orient == 90) {
58752
+ tiltX = beta;
58753
+ tiltY = -gamma;
58754
+ } else if (orient == -90 || orient == 270) {
58755
+ tiltX = -beta;
58756
+ tiltY = gamma;
58757
+ } else if (orient == 180) {
58758
+ tiltX = -gamma;
58759
+ tiltY = -beta;
58749
58760
  } else {
58750
- ang = alpha;
58761
+ tiltX = gamma;
58762
+ tiltY = beta;
58751
58763
  }
58752
58764
 
58753
- if (startDeviceAngle === null) {
58754
- startDeviceAngle = ang;
58755
- lastMode = curMode;
58756
- if (dampRot) dampRot.immediate(obj.rotation);
58757
- } else if (lastMode !== null && curMode !== lastMode) {
58758
- // Seamless transition between upright and flat
58759
- var prevDiff = angleDiff(currentDeviceAngle, startDeviceAngle);
58760
- startDeviceAngle = ang - prevDiff;
58761
- lastMode = curMode;
58762
- }
58765
+ var mag = Math.sqrt(tiltX * tiltX + tiltY * tiltY);
58766
+ var steerAng = Math.atan2(tiltX, tiltY) * (180 / Math.PI);
58767
+ var flatAng = (alpha - orient + 360) % 360;
58763
58768
 
58764
- currentDeviceAngle = ang;
58769
+ if (mode == "absolute") {
58770
+ currentDeviceAngle = flatAng;
58771
+ if (startDeviceAngle === null) startDeviceAngle = flatAng;
58772
+ } else {
58773
+ if (currentDeviceAngle === null) {
58774
+ startDeviceAngle = 0;
58775
+ currentDeviceAngle = 0;
58776
+ lastSteerAng = steerAng;
58777
+ lastFlatAng = flatAng;
58778
+ if (dampRot) dampRot.immediate(obj.rotation);
58779
+ } else {
58780
+ var dSteer = angleDiff(steerAng, lastSteerAng);
58781
+ var dFlat = angleDiff(flatAng, lastFlatAng);
58782
+
58783
+ // Smoothly blend between flat table (mag <= 20) and upright wheel (mag >= 50)
58784
+ var w = zim.constrain((mag - 20) / 30, 0, 1);
58785
+ var delta = (1 - w) * dFlat + w * dSteer;
58786
+
58787
+ currentDeviceAngle += delta;
58788
+ lastSteerAng = steerAng;
58789
+ lastFlatAng = flatAng;
58790
+ }
58791
+ }
58765
58792
  };
58766
58793
  f.on(type, obj._turnListener);
58767
58794
 
@@ -58769,24 +58796,24 @@ RETURNS obj for chaining
58769
58796
  if (ready) ready(true, obj);
58770
58797
  }
58771
58798
 
58772
- // Simple function queue
58799
+ // Shared Permission check & queueing
58773
58800
  if (f._permissionGranted) {
58774
58801
  activate();
58775
58802
  } else if (f._permissionPending) {
58776
- f._permissionQueue.push(activate);
58803
+ f._permissionQueue.push({ activate: activate, reject: function() { if (ready) ready(false, obj); } });
58777
58804
  } else {
58778
58805
  f._permissionPending = true;
58779
- f._permissionQueue = [activate];
58806
+ f._permissionQueue = [{ activate: activate, reject: function() { if (ready) ready(false, obj); } }];
58780
58807
 
58781
58808
  new zim.PermissionAsk(function(yes) {
58782
58809
  f._permissionPending = false;
58783
58810
  if (yes) {
58784
58811
  f._permissionGranted = true;
58785
- zim.loop(f._permissionQueue, function(fn) { fn(); });
58786
- f._permissionQueue = [];
58812
+ zim.loop(f._permissionQueue, function(item) { item.activate(); });
58787
58813
  } else {
58788
- if (ready) ready(false, obj);
58814
+ zim.loop(f._permissionQueue, function(item) { item.reject(); });
58789
58815
  }
58816
+ f._permissionQueue = [];
58790
58817
  }, type);
58791
58818
  }
58792
58819
 
@@ -58851,8 +58878,13 @@ Automatically manages user sensor permission via ZIM PermissionAsk if permission
58851
58878
  NOTE: If permission has already been granted, shake activates immediately.
58852
58879
  If multiple objects call tilt(), turn(), or shake() before permission is granted, they are queued and activated together once the user accepts.
58853
58880
 
58881
+ NOTE: To change the text of the Dialog set: F.sensorText = "OKAY?"; // BEFORE calling the shake()
58882
+ To change buttons of the Dialog set: F.sensorAsk.yes.text = "OUI"; F.sensorAsk.no.text = "NON"; // AFTER calling the shake()
58883
+
58854
58884
  ALSO: see noShake() to remove shake listeners.
58855
58885
 
58886
+ SEE: https://zimjs.com/020/shake.html
58887
+
58856
58888
  EXAMPLE
58857
58889
  const color = series(red,green,blue);
58858
58890
  const bottle = new Rectangle(80, 160, purple).centerReg().shake({
@@ -58897,137 +58929,137 @@ Dispatches a "shakestop" event on obj when shaking stops.
58897
58929
 
58898
58930
  RETURNS obj for chaining
58899
58931
  --*///+34.95
58900
- zim.shake = function(obj, call, stopCall, threshold, wait, factor, type, ready) {
58901
- var sig = "obj, call, stopCall, threshold, wait, factor, type, ready";
58902
- var duo; if (duo = zob(zim.shake, arguments, sig)) return duo;
58903
- if ((obj.type=="AC"||(obj.type=="Emoji"&&obj.svg&&obj.svg.type=="AC"))&&WW.zdf) {WW.zdf.ac("shake", arguments); return obj;}
58904
- z_d("34.95");
58932
+ zim.shake = function(obj, call, stopCall, threshold, wait, factor, type, ready) {
58933
+ var sig = "obj, call, stopCall, threshold, wait, factor, type, ready";
58934
+ var duo; if (duo = zob(zim.shake, arguments, sig)) return duo;
58935
+ if ((obj.type=="AC"||(obj.type=="Emoji"&&obj.svg&&obj.svg.type=="AC"))&&WW.zdf) {WW.zdf.ac("shake", arguments); return obj;}
58936
+ z_d("34.95");
58905
58937
 
58906
- // MONITOR
58907
- var mID = "z~shake";
58908
- if (obj && obj.mID && ((obj.mID[2] && obj.mID[2]=="-") || obj.mID[0]=="-")) mID = "z~-";
58938
+ // MONITOR
58939
+ var mID = "z~shake";
58940
+ if (obj && obj.mID && ((obj.mID[2] && obj.mID[2]=="-") || obj.mID[0]=="-")) mID = "z~-";
58909
58941
 
58910
- if (zot(obj)) return;
58942
+ if (zot(obj)) return;
58911
58943
 
58912
- // Clean up any existing shake on this object first
58913
- if (obj._shakeListener) zim.noShake(obj);
58944
+ // Clean up any existing shake on this object first
58945
+ if (obj._shakeListener) zim.noShake(obj);
58914
58946
 
58915
- var f = obj.frame || (typeof zdf != "undefined" ? zdf : WW.zdf);
58916
- var s = obj.stage || (f ? f.stage : null);
58947
+ var f = obj.frame || (typeof zdf != "undefined" ? zdf : WW.zdf);
58948
+ var s = obj.stage || (f ? f.stage : null);
58917
58949
 
58918
- if (zot(threshold)) threshold = 10;
58919
- if (zot(wait)) wait = 0.5;
58920
- if (zot(factor)) factor = 1;
58921
- if (zot(type)) type = "devicemotion";
58950
+ if (zot(threshold)) threshold = 10;
58951
+ if (zot(wait)) wait = 0.5;
58952
+ if (zot(factor)) factor = 1;
58953
+ if (zot(type)) type = "devicemotion";
58922
58954
 
58923
- var lastX = 0, lastY = 0, lastZ = 0;
58924
- var lastTime = 0;
58955
+ var lastX = 0, lastY = 0, lastZ = 0;
58956
+ var lastTime = 0;
58925
58957
 
58926
- function handleMotion(e) {
58927
- var acc = e.acceleration && (e.acceleration.x != null || e.acceleration.y != null) ?
58928
- e.acceleration : (e.accelerationIncludingGravity || e);
58958
+ function handleMotion(e) {
58959
+ var acc = e.acceleration && (e.acceleration.x != null || e.acceleration.y != null) ?
58960
+ e.acceleration : (e.accelerationIncludingGravity || e);
58929
58961
 
58930
- var ax = acc.x || 0;
58931
- var ay = acc.y || 0;
58932
- var az = acc.z || 0;
58962
+ var ax = acc.x || 0;
58963
+ var ay = acc.y || 0;
58964
+ var az = acc.z || 0;
58933
58965
 
58934
- var deltaX = ax - lastX;
58935
- var deltaY = ay - lastY;
58936
- var deltaZ = az - lastZ;
58966
+ var deltaX = ax - lastX;
58967
+ var deltaY = ay - lastY;
58968
+ var deltaZ = az - lastZ;
58937
58969
 
58938
- lastX = ax;
58939
- lastY = ay;
58940
- lastZ = az;
58970
+ lastX = ax;
58971
+ lastY = ay;
58972
+ lastZ = az;
58941
58973
 
58942
- var mag = Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ) * factor;
58974
+ var mag = Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ) * factor;
58943
58975
 
58944
- if (mag >= threshold) {
58945
- var now = Date.now();
58976
+ if (mag >= threshold) {
58977
+ var now = Date.now();
58946
58978
 
58947
- // Reset stop timer on active motion
58948
- if (obj._shakeStopTimeout) obj._shakeStopTimeout.clear();
58979
+ if (obj._shakeStopTimeout) obj._shakeStopTimeout.clear();
58949
58980
 
58950
- obj._shakeStopTimeout = zim.timeout(wait, function() {
58951
- obj._shakeStopTimeout = null;
58952
- if (stopCall) stopCall(obj);
58953
- obj.dispatchEvent({
58954
- type: "shakestop",
58955
- event: e
58981
+ obj._shakeStopTimeout = zim.timeout(wait, function() {
58982
+ obj._shakeStopTimeout = null;
58983
+ if (stopCall) stopCall(obj);
58984
+ obj.dispatchEvent({
58985
+ type: "shakestop",
58986
+ event: e
58987
+ });
58988
+ if (s) s.update();
58956
58989
  });
58957
- if (s) s.update();
58958
- });
58959
58990
 
58960
- if (now - lastTime >= wait * 1000) {
58961
- lastTime = now;
58991
+ if (now - lastTime >= wait * 1000) {
58992
+ lastTime = now;
58962
58993
 
58963
- var orient = 0;
58964
- if (typeof WW != "undefined") {
58965
- if (WW.screen && WW.screen.orientation && WW.screen.orientation.angle != null) {
58966
- orient = WW.screen.orientation.angle;
58967
- } else if (typeof WW.orientation != "undefined") {
58968
- orient = WW.orientation;
58994
+ var orient = 0;
58995
+ if (typeof WW != "undefined") {
58996
+ if (WW.screen && WW.screen.orientation && WW.screen.orientation.angle != null) {
58997
+ orient = WW.screen.orientation.angle;
58998
+ } else if (typeof WW.orientation != "undefined") {
58999
+ orient = WW.orientation;
59000
+ }
58969
59001
  }
58970
- }
58971
59002
 
58972
- var shakeX, shakeY, shakeZ = deltaZ * factor;
58973
- if (orient == 90) {
58974
- shakeX = deltaY * factor;
58975
- shakeY = -deltaX * factor;
58976
- } else if (orient == -90 || orient == 270) {
58977
- shakeX = -deltaY * factor;
58978
- shakeY = deltaX * factor;
58979
- } else if (orient == 180) {
58980
- shakeX = -deltaX * factor;
58981
- shakeY = -deltaY * factor;
58982
- } else { // 0 portrait
58983
- shakeX = deltaX * factor;
58984
- shakeY = deltaY * factor;
58985
- }
58986
-
58987
- if (call) call(mag, shakeX, shakeY, shakeZ, obj, e);
58988
- obj.dispatchEvent({
58989
- type: "shake",
58990
- total: mag,
58991
- x: shakeX,
58992
- y: shakeY,
58993
- z: shakeZ,
58994
- event: e
58995
- });
59003
+ var shakeX, shakeY, shakeZ = deltaZ * factor;
59004
+ if (orient == 90) {
59005
+ shakeX = deltaY * factor;
59006
+ shakeY = -deltaX * factor;
59007
+ } else if (orient == -90 || orient == 270) {
59008
+ shakeX = -deltaY * factor;
59009
+ shakeY = deltaX * factor;
59010
+ } else if (orient == 180) {
59011
+ shakeX = -deltaX * factor;
59012
+ shakeY = -deltaY * factor;
59013
+ } else {
59014
+ shakeX = deltaX * factor;
59015
+ shakeY = deltaY * factor;
59016
+ }
58996
59017
 
59018
+ if (call) call(mag, shakeX, shakeY, shakeZ, obj, e);
59019
+ obj.dispatchEvent({
59020
+ type: "shake",
59021
+ total: mag,
59022
+ x: shakeX,
59023
+ y: shakeY,
59024
+ z: shakeZ,
59025
+ event: e
59026
+ });
59027
+
59028
+ if (s) s.update();
59029
+ }
58997
59030
  }
58998
59031
  }
58999
- }
59000
59032
 
59001
- function activate() {
59002
- obj._shakeType = type;
59003
- obj._shakeListener = handleMotion;
59004
- f.on(type, obj._shakeListener);
59005
- if (ready) ready(true, obj);
59006
- }
59033
+ function activate() {
59034
+ obj._shakeType = type;
59035
+ obj._shakeListener = handleMotion;
59036
+ f.on(type, obj._shakeListener);
59037
+ if (ready) ready(true, obj);
59038
+ }
59007
59039
 
59008
- // Simple function queue
59009
- if (f._permissionGranted) {
59010
- activate();
59011
- } else if (f._permissionPending) {
59012
- f._permissionQueue.push(activate);
59013
- } else {
59014
- f._permissionPending = true;
59015
- f._permissionQueue = [activate];
59040
+ // Shared Permission check & queueing
59041
+ if (f._permissionGranted) {
59042
+ activate();
59043
+ } else if (f._permissionPending) {
59044
+ f._permissionQueue.push({ activate: activate, reject: function() { if (ready) ready(false, obj); } });
59045
+ } else {
59046
+ f._permissionPending = true;
59047
+ f._permissionQueue = [{ activate: activate, reject: function() { if (ready) ready(false, obj); } }];
59016
59048
 
59017
- new zim.PermissionAsk(function(yes) {
59018
- f._permissionPending = false;
59019
- if (yes) {
59020
- f._permissionGranted = true;
59021
- zim.loop(f._permissionQueue, function(fn) { fn(); });
59049
+ new zim.PermissionAsk(function(yes) {
59050
+ f._permissionPending = false;
59051
+ if (yes) {
59052
+ f._permissionGranted = true;
59053
+ zim.loop(f._permissionQueue, function(item) { item.activate(); });
59054
+ } else {
59055
+ zim.loop(f._permissionQueue, function(item) { item.reject(); });
59056
+ }
59022
59057
  f._permissionQueue = [];
59023
- } else {
59024
- if (ready) ready(false, obj);
59025
- }
59026
- }, type);
59027
- }
59058
+ }, type);
59059
+ }
59028
59060
 
59029
- return obj;
59030
- };//-34.95
59061
+ return obj;
59062
+ };//-34.95
59031
59063
 
59032
59064
 
59033
59065
  /*--
@@ -59048,30 +59080,30 @@ END EXAMPLE
59048
59080
 
59049
59081
  RETURNS obj for chaining
59050
59082
  --*///+34.96
59051
- zim.noShake = function(obj) {
59052
- var sig = "obj";
59053
- var duo; if (duo = zob(zim.noShake, arguments, sig)) return duo;
59054
- z_d("34.96");
59083
+ zim.noShake = function(obj) {
59084
+ var sig = "obj";
59085
+ var duo; if (duo = zob(zim.noShake, arguments, sig)) return duo;
59086
+ z_d("34.96");
59055
59087
 
59056
- if (zot(obj) || !obj.on || !obj.zimTouch) return;
59088
+ if (zot(obj) || !obj.on || !obj.zimTouch) return;
59057
59089
 
59058
- // MONITOR
59059
- var mID = "z~noShake";
59060
- if (obj && obj.mID && ((obj.mID[2] && obj.mID[2]=="-") || obj.mID[0]=="-")) mID = "z~-";
59090
+ // MONITOR
59091
+ var mID = "z~noShake";
59092
+ if (obj && obj.mID && ((obj.mID[2] && obj.mID[2]=="-") || obj.mID[0]=="-")) mID = "z~-";
59061
59093
 
59062
- var f = obj.frame || (typeof zdf != "undefined" ? zdf : WW.zdf);
59094
+ var f = obj.frame || (typeof zdf != "undefined" ? zdf : WW.zdf);
59063
59095
 
59064
- if (obj._shakeListener && f) {
59065
- f.off(obj._shakeType || "devicemotion", obj._shakeListener);
59066
- obj._shakeListener = null;
59067
- }
59068
- if (obj._shakeStopTimeout) {
59069
- obj._shakeStopTimeout.clear();
59070
- obj._shakeStopTimeout = null;
59071
- }
59096
+ if (obj._shakeListener && f) {
59097
+ f.off(obj._shakeType || "devicemotion", obj._shakeListener);
59098
+ obj._shakeListener = null;
59099
+ }
59100
+ if (obj._shakeStopTimeout) {
59101
+ obj._shakeStopTimeout.clear();
59102
+ obj._shakeStopTimeout = null;
59103
+ }
59072
59104
 
59073
- return obj;
59074
- };//-34.96
59105
+ return obj;
59106
+ };//-34.96
59075
59107
 
59076
59108
  // SUBSECTION HIT TESTS
59077
59109
 
@@ -98631,118 +98663,6 @@ END EXAMPLE
98631
98663
  // See Frame for the cursors property
98632
98664
  //-83.867
98633
98665
 
98634
- /*--
98635
- Tilt - device orientation event
98636
-
98637
- Tilt
98638
- "deviceorientation" Frame event
98639
-
98640
- DESCRIPTION
98641
- The Frame has a "deviceorientation" event to capture tilt or device rotation (like a compass)
98642
- and a "devicemotion" event to capture shaking the device with the accelerometer.
98643
-
98644
- SEE: the tilt() method (just after gesture()) for a one line version
98645
-
98646
- SEE: Shake - for the "devicemotion" event for accelerometer motion
98647
-
98648
- SEE: the PermissionAsk() class which will handle asking for permissions on devices.
98649
-
98650
- EXAMPLE
98651
- // SEE ALSO THE TILT METHOD FOR A ONE LINE VERSION
98652
-
98653
- // TILT OR COMPASS - https://zimjs.com/zapp/Z_Q5UYS
98654
- // for capturing tilt on device (rotation about an axis)
98655
- // be on a mobile device or a device with sensors
98656
- new PermissionAsk(yes=>{
98657
- if (yes) { // the user answered yes to PermissionAsk
98658
- // all code goes in here
98659
- new Label("Tilt the device to move circle").alp(.3).pos(0,30,CENTER);
98660
- const circle = new Circle().center();
98661
- const amount = .5;
98662
- const compass = new Line(60, 4, light, "arrow").rot(90).centerReg(circle); // point up
98663
- F.on("deviceorientation", e=>{
98664
- // for tilt
98665
- circle.mov(e.rotation.y*amount, e.rotation.x*amount);
98666
- circle.x = constrain(circle.x, 0, W);
98667
- circle.y = constrain(circle.y, 0, H);
98668
- // for compass use e.rotation.z
98669
- // which has 0 angle at device start rotation (not necessarily North)
98670
- compass.rot(90-e.rotation.z); // rotate opposite device rotation
98671
- S.update();
98672
- });
98673
- } else { // the user answered no to PermissionAsk
98674
- new Pane("SENSOR not available",yellow).show();
98675
- }
98676
- });
98677
- END EXAMPLE
98678
-
98679
- EVENTS
98680
- "deviceorientation" - for tilt
98681
- fired as device orientation changes:
98682
- eventObject.rotation.x (beta in HTML specs) holds rotation about the x axis between -180 and 180 (tipped forward or backward)
98683
- eventObject.rotation.y (gamma in HTML specs) holds rotation about the y axis between -90 and 90 (tipped left or right)
98684
- eventObject.rotation.z (alpha in HTML specs) holds rotation about the z axis 0-360 clockwise (relative to orientation when app loads)
98685
- note rotation.z is 360-alpha compared to the HTML 5 specs
98686
- note also that beta, gamma and alpha from the HTML 5 specs are also provided
98687
- --*///+83.86
98688
- // Device motion and orientation events are available as Frame events
98689
- //-83.86
98690
-
98691
- /*--
98692
- Shake - device motion event
98693
-
98694
- Shake
98695
- "devicemotion" Frame event
98696
-
98697
- DESCRIPTION
98698
- The Frame has a "devicemotion" event to capture shaking the device with the accelerometer.
98699
-
98700
- SEE: Tilt - for the "deviceorientation" event for tilt or compass
98701
-
98702
- SEE: the PermissionAsk() class which will handle asking for permissions on devices.
98703
-
98704
- EXAMPLE
98705
- // SHAKE - https://zimjs.com/zapp/Z_XF8JM
98706
- // for capturing shaking motion on device (acceleration about an axis)
98707
- // be on a mobile device or a device with sensors
98708
- new PermissionAsk(init, "devicemotion");
98709
- function init(yes) {
98710
- if (yes) { // the user answered yes to PermissionAsk
98711
- // all code goes in here
98712
- new Label("Shake the device").center();
98713
- S.update();
98714
- let id;
98715
- F.on("devicemotion", e=>{
98716
- // for shake
98717
- if (
98718
- Math.abs(e.acceleration.x) > 5 ||
98719
- Math.abs(e.acceleration.y) > 5 ||
98720
- Math.abs(e.acceleration.z) > 5
98721
- ) {
98722
- if (F.color != green) {
98723
- F.color = green;
98724
- S.update();
98725
- }
98726
- if (id) id.clear();
98727
- id = timeout(.2, ()=>{
98728
- F.color = light;
98729
- S.update();
98730
- });
98731
- }
98732
- });
98733
- } else { // the user answered no to PermissionAsk
98734
- new Pane("SENSOR not available",yellow).show();
98735
- }
98736
- }
98737
- END EXAMPLE
98738
-
98739
- EVENTS
98740
- "devicemotion" - for shake
98741
- fired on moving mobile device - like a shake - eventObject.acceleration holds x, y and z properties of motion
98742
- --*///+83.87
98743
- // Device motion and orientation events are available as Frame events
98744
- //-83.87
98745
-
98746
98666
  /*--
98747
98667
  zim.PermissionAsk = function(callback, permissionType, color, backgroundColor, style, group, inherit)
98748
98668
 
@@ -98758,9 +98678,14 @@ Pre ZIM 018, this was done with a sensors parameter on the Frame.
98758
98678
  The sensors parameter has now been removed and the events are handled with PermissionAsk.
98759
98679
 
98760
98680
  NOTE: this started as SensorAsk but the class has been adjusted to handle other permissions and the name has been changed in ZIM 016
98681
+
98761
98682
  NOTE: as of ZIM 5.5.0 the zim namespace is no longer required (unless zns is set to true before running zim)
98683
+
98762
98684
  NOTE: sensor prompt text can be customized prior to calling with F.sensorText = "Custom message";
98763
98685
 
98686
+ NOTE: as of ZIM 020 tilt(), turn(), and shake() can be applied as methods to DisplayObjects
98687
+ and will call PermissionAsk automatically so would suggest using those methods
98688
+
98764
98689
  EXAMPLE
98765
98690
  // DEVICE ORIENTATION - gives angle of device in all 3 dimensions
98766
98691
  // See https://zimjs.com/zapp/Z_Q5UYS
@@ -98930,42 +98855,71 @@ no - reference to the zim Button with NO
98930
98855
  return;
98931
98856
  }
98932
98857
 
98933
- // sensors only
98934
- if (typeof DeviceOrientationEvent != "undefined" && DeviceOrientationEvent && typeof DeviceOrientationEvent.requestPermission == "function") {
98858
+ // Fast check: if sensors not supported in environment (e.g. non-secure HTTP or missing API)
98859
+ var hasOrientAPI = typeof DeviceOrientationEvent != "undefined" && DeviceOrientationEvent;
98860
+ var hasMotionAPI = typeof DeviceMotionEvent != "undefined" && DeviceMotionEvent;
98861
+ if (WW.isSecureContext === false || (pt == "deviceorientation" && !hasOrientAPI) || (pt == "devicemotion" && !hasMotionAPI)) {
98862
+ callback(false, pt == "deviceorientation" ? 1 : 2);
98863
+ return;
98864
+ }
98865
+
98866
+ var isIOS = (M == "ios" || (typeof navigator != "undefined" && (/iPad|iPhone|iPod/.test(navigator.userAgent) || (navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1))));
98867
+
98868
+ // Sensors probe: Only iOS devices with requestPermission require the PermissionAsk popup
98869
+ if (isIOS && typeof DeviceOrientationEvent != "undefined" && DeviceOrientationEvent && typeof DeviceOrientationEvent.requestPermission == "function") {
98935
98870
  setPane();
98936
98871
  } else {
98937
- var called = false;
98938
- WW.addEventListener(permissionType, testMe);
98872
+ var tested = false;
98873
+ var timer = setTimeout(function() {
98874
+ if (tested) return;
98875
+ tested = true;
98876
+ WW.removeEventListener(permissionType, testMe);
98877
+ callback(false, 3); // 3 - timeout / no sensor hardware (e.g. desktop)
98878
+ }, 500);
98879
+
98939
98880
  function testMe(e) {
98940
- if (okay) return;
98941
- if (permissionType=="deviceorientation") {
98942
- if (e.alpha==null || (e.alpha==0&&e.beta==0&&e.gamma==0)) callback(false, 1);
98943
- else setEvents();
98881
+ if (tested || okay) return;
98882
+ if (permissionType == "deviceorientation") {
98883
+ if (e.alpha != null || e.beta != null || e.gamma != null) {
98884
+ tested = true;
98885
+ clearTimeout(timer);
98886
+ WW.removeEventListener(permissionType, testMe);
98887
+ setEvents();
98888
+ } else {
98889
+ tested = true;
98890
+ clearTimeout(timer);
98891
+ WW.removeEventListener(permissionType, testMe);
98892
+ callback(false, 1);
98893
+ }
98944
98894
  } else {
98945
- if (!e.acceleration || e.acceleration.x==null) callback(false, 2);
98946
- else setEvents();
98947
- }
98948
- called = true;
98949
- WW.removeEventListener(permissionType, testMe);
98950
- }
98951
- setTimeout(function(){
98952
- if (!called) callback(false, 3);
98953
- }, 5000);
98895
+ var hasAcc = e.acceleration && (e.acceleration.x != null || e.acceleration.y != null || e.acceleration.z != null);
98896
+ var hasGrav = e.accelerationIncludingGravity && (e.accelerationIncludingGravity.x != null || e.accelerationIncludingGravity.y != null || e.accelerationIncludingGravity.z != null);
98897
+ if (hasAcc || hasGrav) {
98898
+ tested = true;
98899
+ clearTimeout(timer);
98900
+ WW.removeEventListener(permissionType, testMe);
98901
+ setEvents();
98902
+ } else {
98903
+ tested = true;
98904
+ clearTimeout(timer);
98905
+ WW.removeEventListener(permissionType, testMe);
98906
+ callback(false, 2);
98907
+ }
98908
+ }
98909
+ }
98910
+ WW.addEventListener(permissionType, testMe);
98954
98911
  }
98955
98912
 
98956
- var lastZ = 0;
98957
- var flip = 0;
98958
98913
  function deviceorientationEvent(e) {
98959
- var z = 360-e.alpha;
98960
- if (Math.abs(z-lastZ) > 180 - 45 && Math.abs(z-lastZ) < 180 + 45) flip = flip == 0 ? 180 : 0;
98961
- lastZ = z;
98962
- e.rotation = {x:e.beta, y:e.gamma, z:(z + flip) % 360};
98914
+ var z = e.alpha != null ? (360 - e.alpha) % 360 : 0;
98915
+ e.rotation = {x:e.beta || 0, y:e.gamma || 0, z:z};
98963
98916
  frame.dispatchEvent(e);
98964
98917
  }
98965
98918
  function devicemotionEvent(e) {
98966
98919
  frame.dispatchEvent(e);
98967
98920
  }
98968
98921
  function setEvents() {
98922
+ if (frame) frame._permissionGranted = true;
98969
98923
  if (permissionType=="deviceorientation") {
98970
98924
  frame.zimDeviceorientationEvent = deviceorientationEvent;
98971
98925
  WW.addEventListener("deviceorientation", frame.zimDeviceorientationEvent);
@@ -107998,4 +107952,4 @@ export let Ticker = zim.Ticker;
107998
107952
  export let Style = zim.Style;
107999
107953
  export let assets = zim.assets;
108000
107954
  export let assetIDs = zim.assetIDs;
108001
- export let ZIMON = zim.ZIMON;
107955
+ export let ZIMON = zim.ZIMON;