zimjs 20.0.8 → 20.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/zim.js +221 -239
- package/ts-src/typings/zim/index.d.ts +3 -0
package/package.json
CHANGED
package/src/zim.js
CHANGED
|
@@ -26511,7 +26511,7 @@ EXAMPLE
|
|
|
26511
26511
|
// copy the emoji or use the copy link and paste into the string below
|
|
26512
26512
|
// leave the noto_ at the start and paste the emoji icon right after the _
|
|
26513
26513
|
// where icon is the actual emoji icon (or a unicode number, or a noto code)
|
|
26514
|
-
// this will create
|
|
26514
|
+
// this will create an SVG that is the same across platforms (Windows, Linux, Android, iOS)
|
|
26515
26515
|
new Emoji("noto_icon")
|
|
26516
26516
|
.center()
|
|
26517
26517
|
.drag();
|
|
@@ -44485,7 +44485,7 @@ const emojiPicker = new EmojiPicker()
|
|
|
44485
44485
|
.change(() => {
|
|
44486
44486
|
// we will make a bigger emoji by passing the code of the currentEmoji
|
|
44487
44487
|
// to the new Emoji - you can clone and then scale but that can look blotchy
|
|
44488
|
-
const emoji = new Emoji(emojiPicker.
|
|
44488
|
+
const emoji = new Emoji(emojiPicker.selectedEmoji.code, 200)
|
|
44489
44489
|
.centerReg()
|
|
44490
44490
|
.drag();
|
|
44491
44491
|
S.update();
|
|
@@ -44535,9 +44535,11 @@ addChild(), removeChild(), addChildAt(), getChildAt(), contains(), removeAllChil
|
|
|
44535
44535
|
|
|
44536
44536
|
PROPERTIES
|
|
44537
44537
|
type - holds the class name as a String
|
|
44538
|
-
selectedEmoji -
|
|
44538
|
+
selectedEmoji - the selected ZIM Emoji object
|
|
44539
44539
|
clone the object to let the user use it
|
|
44540
44540
|
or make a new Emoji() from the selectedEmoji.code and pass in a different size, etc.
|
|
44541
|
+
selectedText - the text of the selected Emoji
|
|
44542
|
+
currentEmoji - (depricated) actually the Label of the selectedEmoji - left for backwards compatibility
|
|
44541
44543
|
emojiData - get the list of emojis - warning, if zog to console they will look like emojis
|
|
44542
44544
|
wrapper - the ZIM Wrapper used for the picker
|
|
44543
44545
|
|
|
@@ -44615,7 +44617,9 @@ added, click, dblclick, mousedown, mouseout, mouseover, pressdown (ZIM), pressmo
|
|
|
44615
44617
|
this.add(this.backdrop);
|
|
44616
44618
|
this.add(this.wrapper);
|
|
44617
44619
|
this.wrapper.tap(function(e) {
|
|
44618
|
-
that.
|
|
44620
|
+
that.selectedText = e.target.text;
|
|
44621
|
+
that.selectedEmoji = e.target.parent;
|
|
44622
|
+
that.currentEmoji = e.target; // accidentally is the label property - leaving for backwards compatibility
|
|
44619
44623
|
that.dispatchEvent("change");
|
|
44620
44624
|
});
|
|
44621
44625
|
if (style!==false) zim.styleTransforms(this, DS);
|
|
@@ -58294,6 +58298,8 @@ ALSO: see noTilt() to remove tilt behaviors.
|
|
|
58294
58298
|
|
|
58295
58299
|
ALSO: see tiltBoundary() to dynamically change or clear the boundary rectangle.
|
|
58296
58300
|
|
|
58301
|
+
SEE: https://zimjs.com/020/tilt.html
|
|
58302
|
+
|
|
58297
58303
|
EXAMPLE
|
|
58298
58304
|
// Basic rolling ball constrained to stage bounds
|
|
58299
58305
|
const ball = new Circle(30, red)
|
|
@@ -58356,35 +58362,11 @@ RETURNS obj for chaining
|
|
|
58356
58362
|
|
|
58357
58363
|
var dampX = damp ? new zim.Damp(mode == "position" ? obj.x : 0, damp) : null;
|
|
58358
58364
|
var dampY = damp ? new zim.Damp(mode == "position" ? obj.y : 0, damp) : null;
|
|
58359
|
-
var
|
|
58365
|
+
var currentVector = {x: 0, y: 0};
|
|
58360
58366
|
|
|
58361
58367
|
function updateTilt() {
|
|
58362
|
-
var
|
|
58363
|
-
|
|
58364
|
-
if (WW.screen && WW.screen.orientation && WW.screen.orientation.angle != null) {
|
|
58365
|
-
orient = WW.screen.orientation.angle;
|
|
58366
|
-
} else if (typeof WW.orientation != "undefined") {
|
|
58367
|
-
orient = WW.orientation;
|
|
58368
|
-
}
|
|
58369
|
-
}
|
|
58370
|
-
|
|
58371
|
-
var beta = currentRot.x;
|
|
58372
|
-
var gamma = currentRot.y;
|
|
58373
|
-
var tiltX, tiltY;
|
|
58374
|
-
|
|
58375
|
-
if (orient == 90) {
|
|
58376
|
-
tiltX = beta;
|
|
58377
|
-
tiltY = -gamma;
|
|
58378
|
-
} else if (orient == -90 || orient == 270) {
|
|
58379
|
-
tiltX = -beta;
|
|
58380
|
-
tiltY = gamma;
|
|
58381
|
-
} else if (orient == 180) {
|
|
58382
|
-
tiltX = -gamma;
|
|
58383
|
-
tiltY = -beta;
|
|
58384
|
-
} else {
|
|
58385
|
-
tiltX = gamma;
|
|
58386
|
-
tiltY = beta;
|
|
58387
|
-
}
|
|
58368
|
+
var tiltX = currentVector.x;
|
|
58369
|
+
var tiltY = currentVector.y;
|
|
58388
58370
|
|
|
58389
58371
|
if (mode == "move") {
|
|
58390
58372
|
var rotX = dampX ? dampX.convert(tiltX) : tiltX;
|
|
@@ -58416,14 +58398,50 @@ RETURNS obj for chaining
|
|
|
58416
58398
|
|
|
58417
58399
|
obj._tiltType = type;
|
|
58418
58400
|
obj._tiltListener = function(e) {
|
|
58419
|
-
|
|
58420
|
-
|
|
58421
|
-
|
|
58422
|
-
|
|
58401
|
+
var orient = 0;
|
|
58402
|
+
if (typeof WW != "undefined") {
|
|
58403
|
+
if (WW.screen && WW.screen.orientation && WW.screen.orientation.angle != null) {
|
|
58404
|
+
orient = WW.screen.orientation.angle;
|
|
58405
|
+
} else if (typeof WW.orientation != "undefined") {
|
|
58406
|
+
orient = WW.orientation;
|
|
58407
|
+
}
|
|
58408
|
+
}
|
|
58409
|
+
|
|
58410
|
+
if (type == "devicemotion" || e.accelerationIncludingGravity || e.accelerationData) {
|
|
58411
|
+
var acc = e.accelerationData || e.accelerationIncludingGravity || e.acceleration || e;
|
|
58412
|
+
var ax = acc.x || 0;
|
|
58413
|
+
var ay = acc.y || 0;
|
|
58414
|
+
|
|
58415
|
+
if (orient == 90) {
|
|
58416
|
+
currentVector.x = ay * 5;
|
|
58417
|
+
currentVector.y = ax * 5;
|
|
58418
|
+
} else if (orient == -90 || orient == 270) {
|
|
58419
|
+
currentVector.x = -ay * 5;
|
|
58420
|
+
currentVector.y = -ax * 5;
|
|
58421
|
+
} else if (orient == 180) {
|
|
58422
|
+
currentVector.x = ax * 5;
|
|
58423
|
+
currentVector.y = -ay * 5;
|
|
58424
|
+
} else {
|
|
58425
|
+
currentVector.x = -ax * 5;
|
|
58426
|
+
currentVector.y = ay * 5;
|
|
58427
|
+
}
|
|
58423
58428
|
} else {
|
|
58424
|
-
|
|
58425
|
-
|
|
58426
|
-
|
|
58429
|
+
var beta = e.rotation ? e.rotation.x : (e.beta || 0);
|
|
58430
|
+
var gamma = e.rotation ? e.rotation.y : (e.gamma || 0);
|
|
58431
|
+
|
|
58432
|
+
if (orient == 90) {
|
|
58433
|
+
currentVector.x = beta;
|
|
58434
|
+
currentVector.y = -gamma;
|
|
58435
|
+
} else if (orient == -90 || orient == 270) {
|
|
58436
|
+
currentVector.x = -beta;
|
|
58437
|
+
currentVector.y = gamma;
|
|
58438
|
+
} else if (orient == 180) {
|
|
58439
|
+
currentVector.x = -gamma;
|
|
58440
|
+
currentVector.y = -beta;
|
|
58441
|
+
} else {
|
|
58442
|
+
currentVector.x = gamma;
|
|
58443
|
+
currentVector.y = beta;
|
|
58444
|
+
}
|
|
58427
58445
|
}
|
|
58428
58446
|
};
|
|
58429
58447
|
f.on(type, obj._tiltListener);
|
|
@@ -58432,24 +58450,29 @@ RETURNS obj for chaining
|
|
|
58432
58450
|
if (ready) ready(true, obj);
|
|
58433
58451
|
}
|
|
58434
58452
|
|
|
58435
|
-
//
|
|
58436
|
-
if (f._permissionGranted) {
|
|
58453
|
+
// Per-type Permission check & queueing
|
|
58454
|
+
if (!f._permissionGranted) f._permissionGranted = {};
|
|
58455
|
+
if (!f._permissionPending) f._permissionPending = {};
|
|
58456
|
+
if (!f._permissionQueue) f._permissionQueue = {};
|
|
58457
|
+
if (!f._permissionQueue[type]) f._permissionQueue[type] = [];
|
|
58458
|
+
|
|
58459
|
+
if (f._permissionGranted[type]) {
|
|
58437
58460
|
activate();
|
|
58438
|
-
} else if (f._permissionPending) {
|
|
58439
|
-
f._permissionQueue.push({ activate: activate, reject: function() { if (ready) ready(false, obj); } });
|
|
58461
|
+
} else if (f._permissionPending[type]) {
|
|
58462
|
+
f._permissionQueue[type].push({ activate: activate, reject: function() { if (ready) ready(false, obj); } });
|
|
58440
58463
|
} else {
|
|
58441
|
-
f._permissionPending = true;
|
|
58442
|
-
f._permissionQueue
|
|
58464
|
+
f._permissionPending[type] = true;
|
|
58465
|
+
f._permissionQueue[type].push({ activate: activate, reject: function() { if (ready) ready(false, obj); } });
|
|
58443
58466
|
|
|
58444
58467
|
new zim.PermissionAsk(function(yes) {
|
|
58445
|
-
f._permissionPending = false;
|
|
58468
|
+
f._permissionPending[type] = false;
|
|
58446
58469
|
if (yes) {
|
|
58447
|
-
f._permissionGranted = true;
|
|
58448
|
-
zim.loop(f._permissionQueue, function(item) { item.activate(); });
|
|
58470
|
+
f._permissionGranted[type] = true;
|
|
58471
|
+
zim.loop(f._permissionQueue[type], function(item) { item.activate(); });
|
|
58449
58472
|
} else {
|
|
58450
|
-
zim.loop(f._permissionQueue, function(item) { item.reject(); });
|
|
58473
|
+
zim.loop(f._permissionQueue[type], function(item) { item.reject(); });
|
|
58451
58474
|
}
|
|
58452
|
-
f._permissionQueue = [];
|
|
58475
|
+
f._permissionQueue[type] = [];
|
|
58453
58476
|
}, type);
|
|
58454
58477
|
}
|
|
58455
58478
|
|
|
@@ -58480,7 +58503,7 @@ RETURNS obj for chaining
|
|
|
58480
58503
|
var duo; if (duo = zob(zim.noTilt, arguments, sig)) return duo;
|
|
58481
58504
|
z_d("34.91");
|
|
58482
58505
|
|
|
58483
|
-
if (zot(obj) || !obj.on
|
|
58506
|
+
if (zot(obj) || !obj.on) return;
|
|
58484
58507
|
|
|
58485
58508
|
// MONITOR
|
|
58486
58509
|
var mID = "z~noTilt";
|
|
@@ -58616,6 +58639,8 @@ To change buttons of the Dialog set: F.sensorAsk.yes.text = "OUI"; F.sensorAsk.n
|
|
|
58616
58639
|
|
|
58617
58640
|
ALSO: see noTurn() to remove turning behaviors.
|
|
58618
58641
|
|
|
58642
|
+
SEE: https://zimjs.com/020/turn.html
|
|
58643
|
+
|
|
58619
58644
|
EXAMPLE
|
|
58620
58645
|
// Point an arrow with device heading (stays pointing up in world space)
|
|
58621
58646
|
const arrow = new Arrow({type:"thick"}).sca(4).rot(-90).centerReg().turn();
|
|
@@ -58673,7 +58698,8 @@ RETURNS obj for chaining
|
|
|
58673
58698
|
var dampRot = damp ? new zim.Damp(obj.rotation, damp) : null;
|
|
58674
58699
|
var startDeviceAngle = null;
|
|
58675
58700
|
var currentDeviceAngle = null;
|
|
58676
|
-
var
|
|
58701
|
+
var lastSteerAng = null;
|
|
58702
|
+
var lastFlatAng = null;
|
|
58677
58703
|
|
|
58678
58704
|
function angleDiff(a, b) {
|
|
58679
58705
|
var diff = (a - b) % 360;
|
|
@@ -58690,28 +58716,18 @@ RETURNS obj for chaining
|
|
|
58690
58716
|
}
|
|
58691
58717
|
|
|
58692
58718
|
function updateTurn() {
|
|
58693
|
-
if (
|
|
58694
|
-
|
|
58695
|
-
var orient = 0;
|
|
58696
|
-
if (typeof WW != "undefined") {
|
|
58697
|
-
if (WW.screen && WW.screen.orientation && WW.screen.orientation.angle != null) {
|
|
58698
|
-
orient = WW.screen.orientation.angle;
|
|
58699
|
-
} else if (typeof WW.orientation != "undefined") {
|
|
58700
|
-
orient = WW.orientation;
|
|
58701
|
-
}
|
|
58702
|
-
}
|
|
58719
|
+
if (currentDeviceAngle === null) return;
|
|
58703
58720
|
|
|
58704
58721
|
var startRot = obj._turnStartRot != null ? obj._turnStartRot : 0;
|
|
58705
58722
|
var targetRot = obj.rotation;
|
|
58706
58723
|
|
|
58707
58724
|
if (mode == "relative") {
|
|
58708
|
-
var diff =
|
|
58725
|
+
var diff = currentDeviceAngle - (startDeviceAngle || 0);
|
|
58709
58726
|
targetRot = startRot - diff * factor;
|
|
58710
58727
|
} else if (mode == "absolute") {
|
|
58711
|
-
|
|
58712
|
-
targetRot = startRot - absHeading * factor;
|
|
58728
|
+
targetRot = startRot - currentDeviceAngle * factor;
|
|
58713
58729
|
} else if (mode == "continuous") {
|
|
58714
|
-
var cDiff = angleDiff(currentDeviceAngle, startDeviceAngle);
|
|
58730
|
+
var cDiff = angleDiff(currentDeviceAngle, startDeviceAngle || 0);
|
|
58715
58731
|
targetRot = obj.rotation - (cDiff * factor * 0.05);
|
|
58716
58732
|
}
|
|
58717
58733
|
|
|
@@ -58733,38 +58749,70 @@ RETURNS obj for chaining
|
|
|
58733
58749
|
obj._turnStartRot = obj.rotation;
|
|
58734
58750
|
startDeviceAngle = null;
|
|
58735
58751
|
currentDeviceAngle = null;
|
|
58736
|
-
|
|
58752
|
+
lastSteerAng = null;
|
|
58753
|
+
lastFlatAng = null;
|
|
58737
58754
|
if (dampRot) dampRot.immediate(obj.rotation);
|
|
58738
58755
|
|
|
58739
58756
|
obj._turnType = type;
|
|
58740
58757
|
obj._turnListener = function(e) {
|
|
58758
|
+
var orient = 0;
|
|
58759
|
+
if (typeof WW != "undefined") {
|
|
58760
|
+
if (WW.screen && WW.screen.orientation && WW.screen.orientation.angle != null) {
|
|
58761
|
+
orient = WW.screen.orientation.angle;
|
|
58762
|
+
} else if (typeof WW.orientation != "undefined") {
|
|
58763
|
+
orient = WW.orientation;
|
|
58764
|
+
}
|
|
58765
|
+
}
|
|
58766
|
+
|
|
58741
58767
|
var beta = e.rotation ? e.rotation.x : (e.beta || 0);
|
|
58742
58768
|
var gamma = e.rotation ? e.rotation.y : (e.gamma || 0);
|
|
58743
|
-
var alpha = e.rotation && e.rotation.z != null ? e.rotation.z : (e.alpha != null ? (360 - e.alpha) : 0);
|
|
58769
|
+
var alpha = e.rotation && e.rotation.z != null ? e.rotation.z : (e.alpha != null ? (360 - e.alpha) % 360 : 0);
|
|
58770
|
+
|
|
58771
|
+
var tiltX, tiltY;
|
|
58772
|
+
if (orient == 90) {
|
|
58773
|
+
tiltX = beta;
|
|
58774
|
+
tiltY = -gamma;
|
|
58775
|
+
} else if (orient == -90 || orient == 270) {
|
|
58776
|
+
tiltX = -beta;
|
|
58777
|
+
tiltY = gamma;
|
|
58778
|
+
} else if (orient == 180) {
|
|
58779
|
+
tiltX = -gamma;
|
|
58780
|
+
tiltY = -beta;
|
|
58781
|
+
} else {
|
|
58782
|
+
tiltX = gamma;
|
|
58783
|
+
tiltY = beta;
|
|
58784
|
+
}
|
|
58744
58785
|
|
|
58745
|
-
var
|
|
58746
|
-
var
|
|
58747
|
-
var
|
|
58786
|
+
var mag = Math.sqrt(tiltX * tiltX + tiltY * tiltY);
|
|
58787
|
+
var steerAng = Math.atan2(tiltX, tiltY) * (180 / Math.PI);
|
|
58788
|
+
var flatAng = (alpha + orient + 360) % 360;
|
|
58748
58789
|
|
|
58749
|
-
if (
|
|
58750
|
-
|
|
58751
|
-
|
|
58752
|
-
ang = Math.atan2(Math.sin(radG), Math.cos(radG) * Math.sin(radB)) * (180 / Math.PI);
|
|
58790
|
+
if (mode == "absolute") {
|
|
58791
|
+
currentDeviceAngle = flatAng;
|
|
58792
|
+
if (startDeviceAngle === null) startDeviceAngle = flatAng;
|
|
58753
58793
|
} else {
|
|
58754
|
-
|
|
58755
|
-
|
|
58794
|
+
if (currentDeviceAngle === null) {
|
|
58795
|
+
startDeviceAngle = 0;
|
|
58796
|
+
currentDeviceAngle = 0;
|
|
58797
|
+
lastSteerAng = steerAng;
|
|
58798
|
+
lastFlatAng = flatAng;
|
|
58799
|
+
if (dampRot) dampRot.immediate(obj.rotation);
|
|
58800
|
+
} else {
|
|
58801
|
+
var dSteer = angleDiff(steerAng, lastSteerAng);
|
|
58802
|
+
var dFlat = angleDiff(flatAng, lastFlatAng);
|
|
58756
58803
|
|
|
58757
|
-
|
|
58758
|
-
|
|
58759
|
-
|
|
58760
|
-
|
|
58761
|
-
|
|
58762
|
-
|
|
58763
|
-
startDeviceAngle = ang - prevDiff;
|
|
58764
|
-
lastMode = curMode;
|
|
58765
|
-
}
|
|
58804
|
+
var delta;
|
|
58805
|
+
if (mag > 35 && Math.abs(dSteer) > Math.abs(dFlat) && Math.abs(beta) < 70) {
|
|
58806
|
+
delta = dSteer;
|
|
58807
|
+
} else {
|
|
58808
|
+
delta = dFlat;
|
|
58809
|
+
}
|
|
58766
58810
|
|
|
58767
|
-
|
|
58811
|
+
currentDeviceAngle += delta;
|
|
58812
|
+
lastSteerAng = steerAng;
|
|
58813
|
+
lastFlatAng = flatAng;
|
|
58814
|
+
}
|
|
58815
|
+
}
|
|
58768
58816
|
};
|
|
58769
58817
|
f.on(type, obj._turnListener);
|
|
58770
58818
|
|
|
@@ -58772,24 +58820,29 @@ RETURNS obj for chaining
|
|
|
58772
58820
|
if (ready) ready(true, obj);
|
|
58773
58821
|
}
|
|
58774
58822
|
|
|
58775
|
-
//
|
|
58776
|
-
if (f._permissionGranted) {
|
|
58823
|
+
// Per-type Permission check & queueing
|
|
58824
|
+
if (!f._permissionGranted) f._permissionGranted = {};
|
|
58825
|
+
if (!f._permissionPending) f._permissionPending = {};
|
|
58826
|
+
if (!f._permissionQueue) f._permissionQueue = {};
|
|
58827
|
+
if (!f._permissionQueue[type]) f._permissionQueue[type] = [];
|
|
58828
|
+
|
|
58829
|
+
if (f._permissionGranted[type]) {
|
|
58777
58830
|
activate();
|
|
58778
|
-
} else if (f._permissionPending) {
|
|
58779
|
-
f._permissionQueue.push({ activate: activate, reject: function() { if (ready) ready(false, obj); } });
|
|
58831
|
+
} else if (f._permissionPending[type]) {
|
|
58832
|
+
f._permissionQueue[type].push({ activate: activate, reject: function() { if (ready) ready(false, obj); } });
|
|
58780
58833
|
} else {
|
|
58781
|
-
f._permissionPending = true;
|
|
58782
|
-
f._permissionQueue
|
|
58834
|
+
f._permissionPending[type] = true;
|
|
58835
|
+
f._permissionQueue[type].push({ activate: activate, reject: function() { if (ready) ready(false, obj); } });
|
|
58783
58836
|
|
|
58784
58837
|
new zim.PermissionAsk(function(yes) {
|
|
58785
|
-
f._permissionPending = false;
|
|
58838
|
+
f._permissionPending[type] = false;
|
|
58786
58839
|
if (yes) {
|
|
58787
|
-
f._permissionGranted = true;
|
|
58788
|
-
zim.loop(f._permissionQueue, function(item) { item.activate(); });
|
|
58840
|
+
f._permissionGranted[type] = true;
|
|
58841
|
+
zim.loop(f._permissionQueue[type], function(item) { item.activate(); });
|
|
58789
58842
|
} else {
|
|
58790
|
-
zim.loop(f._permissionQueue, function(item) { item.reject(); });
|
|
58843
|
+
zim.loop(f._permissionQueue[type], function(item) { item.reject(); });
|
|
58791
58844
|
}
|
|
58792
|
-
f._permissionQueue = [];
|
|
58845
|
+
f._permissionQueue[type] = [];
|
|
58793
58846
|
}, type);
|
|
58794
58847
|
}
|
|
58795
58848
|
|
|
@@ -58819,7 +58872,7 @@ RETURNS obj for chaining
|
|
|
58819
58872
|
var duo; if (duo = zob(zim.noTurn, arguments, sig)) return duo;
|
|
58820
58873
|
z_d("34.94");
|
|
58821
58874
|
|
|
58822
|
-
if (zot(obj) || !obj.on
|
|
58875
|
+
if (zot(obj) || !obj.on) return;
|
|
58823
58876
|
|
|
58824
58877
|
// MONITOR
|
|
58825
58878
|
var mID = "z~noTurn";
|
|
@@ -58859,6 +58912,8 @@ To change buttons of the Dialog set: F.sensorAsk.yes.text = "OUI"; F.sensorAsk.n
|
|
|
58859
58912
|
|
|
58860
58913
|
ALSO: see noShake() to remove shake listeners.
|
|
58861
58914
|
|
|
58915
|
+
SEE: https://zimjs.com/020/shake.html
|
|
58916
|
+
|
|
58862
58917
|
EXAMPLE
|
|
58863
58918
|
const color = series(red,green,blue);
|
|
58864
58919
|
const bottle = new Rectangle(80, 160, purple).centerReg().shake({
|
|
@@ -58927,16 +58982,27 @@ RETURNS obj for chaining
|
|
|
58927
58982
|
if (zot(type)) type = "devicemotion";
|
|
58928
58983
|
|
|
58929
58984
|
var lastX = 0, lastY = 0, lastZ = 0;
|
|
58985
|
+
var seeded = false;
|
|
58930
58986
|
var lastTime = 0;
|
|
58931
58987
|
|
|
58932
58988
|
function handleMotion(e) {
|
|
58933
|
-
var acc = e.
|
|
58934
|
-
|
|
58989
|
+
var acc = e.accelerationData || e.accelerationIncludingGravity || e.acceleration || e;
|
|
58990
|
+
if (e.acceleration && (e.acceleration.x || e.acceleration.y || e.acceleration.z)) {
|
|
58991
|
+
acc = e.acceleration;
|
|
58992
|
+
}
|
|
58935
58993
|
|
|
58936
58994
|
var ax = acc.x || 0;
|
|
58937
58995
|
var ay = acc.y || 0;
|
|
58938
58996
|
var az = acc.z || 0;
|
|
58939
58997
|
|
|
58998
|
+
if (!seeded) {
|
|
58999
|
+
seeded = true;
|
|
59000
|
+
lastX = ax;
|
|
59001
|
+
lastY = ay;
|
|
59002
|
+
lastZ = az;
|
|
59003
|
+
return;
|
|
59004
|
+
}
|
|
59005
|
+
|
|
58940
59006
|
var deltaX = ax - lastX;
|
|
58941
59007
|
var deltaY = ay - lastY;
|
|
58942
59008
|
var deltaZ = az - lastZ;
|
|
@@ -59005,30 +59071,36 @@ RETURNS obj for chaining
|
|
|
59005
59071
|
}
|
|
59006
59072
|
|
|
59007
59073
|
function activate() {
|
|
59074
|
+
seeded = false;
|
|
59008
59075
|
obj._shakeType = type;
|
|
59009
59076
|
obj._shakeListener = handleMotion;
|
|
59010
59077
|
f.on(type, obj._shakeListener);
|
|
59011
59078
|
if (ready) ready(true, obj);
|
|
59012
59079
|
}
|
|
59013
59080
|
|
|
59014
|
-
//
|
|
59015
|
-
if (f._permissionGranted) {
|
|
59081
|
+
// Per-type Permission check & queueing
|
|
59082
|
+
if (!f._permissionGranted) f._permissionGranted = {};
|
|
59083
|
+
if (!f._permissionPending) f._permissionPending = {};
|
|
59084
|
+
if (!f._permissionQueue) f._permissionQueue = {};
|
|
59085
|
+
if (!f._permissionQueue[type]) f._permissionQueue[type] = [];
|
|
59086
|
+
|
|
59087
|
+
if (f._permissionGranted[type]) {
|
|
59016
59088
|
activate();
|
|
59017
|
-
} else if (f._permissionPending) {
|
|
59018
|
-
f._permissionQueue.push({ activate: activate, reject: function() { if (ready) ready(false, obj); } });
|
|
59089
|
+
} else if (f._permissionPending[type]) {
|
|
59090
|
+
f._permissionQueue[type].push({ activate: activate, reject: function() { if (ready) ready(false, obj); } });
|
|
59019
59091
|
} else {
|
|
59020
|
-
f._permissionPending = true;
|
|
59021
|
-
f._permissionQueue
|
|
59092
|
+
f._permissionPending[type] = true;
|
|
59093
|
+
f._permissionQueue[type].push({ activate: activate, reject: function() { if (ready) ready(false, obj); } });
|
|
59022
59094
|
|
|
59023
59095
|
new zim.PermissionAsk(function(yes) {
|
|
59024
|
-
f._permissionPending = false;
|
|
59096
|
+
f._permissionPending[type] = false;
|
|
59025
59097
|
if (yes) {
|
|
59026
|
-
f._permissionGranted = true;
|
|
59027
|
-
zim.loop(f._permissionQueue, function(item) { item.activate(); });
|
|
59098
|
+
f._permissionGranted[type] = true;
|
|
59099
|
+
zim.loop(f._permissionQueue[type], function(item) { item.activate(); });
|
|
59028
59100
|
} else {
|
|
59029
|
-
zim.loop(f._permissionQueue, function(item) { item.reject(); });
|
|
59101
|
+
zim.loop(f._permissionQueue[type], function(item) { item.reject(); });
|
|
59030
59102
|
}
|
|
59031
|
-
f._permissionQueue = [];
|
|
59103
|
+
f._permissionQueue[type] = [];
|
|
59032
59104
|
}, type);
|
|
59033
59105
|
}
|
|
59034
59106
|
|
|
@@ -59059,7 +59131,7 @@ RETURNS obj for chaining
|
|
|
59059
59131
|
var duo; if (duo = zob(zim.noShake, arguments, sig)) return duo;
|
|
59060
59132
|
z_d("34.96");
|
|
59061
59133
|
|
|
59062
|
-
if (zot(obj) || !obj.on
|
|
59134
|
+
if (zot(obj) || !obj.on) return;
|
|
59063
59135
|
|
|
59064
59136
|
// MONITOR
|
|
59065
59137
|
var mID = "z~noShake";
|
|
@@ -94587,12 +94659,12 @@ zim.Frame = function(scaling, width, height, color, outerColor, ready, assets, p
|
|
|
94587
94659
|
// // }
|
|
94588
94660
|
// }
|
|
94589
94661
|
|
|
94590
|
-
|
|
94662
|
+
var svgRoot = "https://raw.githubusercontent.com/googlefonts/noto-emoji/v2.042/svg/";
|
|
94591
94663
|
|
|
94592
94664
|
var match;
|
|
94593
94665
|
if (a.match) match = a.match(/^noto_(.*)/);
|
|
94594
94666
|
if (match) {
|
|
94595
|
-
a = {id:a, src:
|
|
94667
|
+
a = {id:a, src:svgRoot + getNotoFilename(match[1])}
|
|
94596
94668
|
}
|
|
94597
94669
|
if (a.replace) a = a.replace(/gf_/i, "https://fonts.googleapis.com/css?family=");
|
|
94598
94670
|
// split multi into individual ZIM asset objects and make the first of these
|
|
@@ -94606,8 +94678,8 @@ zim.Frame = function(scaling, width, height, color, outerColor, ready, assets, p
|
|
|
94606
94678
|
if (isVideoUrl(aj)) continue;
|
|
94607
94679
|
if (aj.match) match = aj.match(/^noto_(.*)/);
|
|
94608
94680
|
if (match) {
|
|
94609
|
-
aj = {id:aj, src:
|
|
94610
|
-
}
|
|
94681
|
+
aj = {id:aj, src:svgRoot + getNotoFilename(match[1])}
|
|
94682
|
+
}
|
|
94611
94683
|
if (aj.split) {
|
|
94612
94684
|
var temp = aj.split("?");
|
|
94613
94685
|
ext = temp[0].match(re);
|
|
@@ -97656,6 +97728,8 @@ added, click, dblclick, mousedown, mouseout, mouseover, pressdown (ZIM), pressmo
|
|
|
97656
97728
|
}
|
|
97657
97729
|
zim.extend(zim.SVG, zim.Container, ["clone"], "zimContainer", false);//-83.09
|
|
97658
97730
|
|
|
97731
|
+
|
|
97732
|
+
|
|
97659
97733
|
/*--
|
|
97660
97734
|
Speech = function()
|
|
97661
97735
|
|
|
@@ -98637,118 +98711,6 @@ END EXAMPLE
|
|
|
98637
98711
|
// See Frame for the cursors property
|
|
98638
98712
|
//-83.867
|
|
98639
98713
|
|
|
98640
|
-
/*--
|
|
98641
|
-
Tilt - device orientation event
|
|
98642
|
-
|
|
98643
|
-
Tilt
|
|
98644
|
-
"deviceorientation" Frame event
|
|
98645
|
-
|
|
98646
|
-
DESCRIPTION
|
|
98647
|
-
The Frame has a "deviceorientation" event to capture tilt or device rotation (like a compass)
|
|
98648
|
-
and a "devicemotion" event to capture shaking the device with the accelerometer.
|
|
98649
|
-
|
|
98650
|
-
SEE: the tilt() method (just after gesture()) for a one line version
|
|
98651
|
-
|
|
98652
|
-
SEE: Shake - for the "devicemotion" event for accelerometer motion
|
|
98653
|
-
|
|
98654
|
-
SEE: the PermissionAsk() class which will handle asking for permissions on devices.
|
|
98655
|
-
|
|
98656
|
-
EXAMPLE
|
|
98657
|
-
// SEE ALSO THE TILT METHOD FOR A ONE LINE VERSION
|
|
98658
|
-
|
|
98659
|
-
// TILT OR COMPASS - https://zimjs.com/zapp/Z_Q5UYS
|
|
98660
|
-
// for capturing tilt on device (rotation about an axis)
|
|
98661
|
-
// be on a mobile device or a device with sensors
|
|
98662
|
-
new PermissionAsk(yes=>{
|
|
98663
|
-
if (yes) { // the user answered yes to PermissionAsk
|
|
98664
|
-
// all code goes in here
|
|
98665
|
-
new Label("Tilt the device to move circle").alp(.3).pos(0,30,CENTER);
|
|
98666
|
-
const circle = new Circle().center();
|
|
98667
|
-
const amount = .5;
|
|
98668
|
-
const compass = new Line(60, 4, light, "arrow").rot(90).centerReg(circle); // point up
|
|
98669
|
-
F.on("deviceorientation", e=>{
|
|
98670
|
-
// for tilt
|
|
98671
|
-
circle.mov(e.rotation.y*amount, e.rotation.x*amount);
|
|
98672
|
-
circle.x = constrain(circle.x, 0, W);
|
|
98673
|
-
circle.y = constrain(circle.y, 0, H);
|
|
98674
|
-
// for compass use e.rotation.z
|
|
98675
|
-
// which has 0 angle at device start rotation (not necessarily North)
|
|
98676
|
-
compass.rot(90-e.rotation.z); // rotate opposite device rotation
|
|
98677
|
-
S.update();
|
|
98678
|
-
});
|
|
98679
|
-
} else { // the user answered no to PermissionAsk
|
|
98680
|
-
new Pane("SENSOR not available",yellow).show();
|
|
98681
|
-
}
|
|
98682
|
-
});
|
|
98683
|
-
END EXAMPLE
|
|
98684
|
-
|
|
98685
|
-
EVENTS
|
|
98686
|
-
"deviceorientation" - for tilt
|
|
98687
|
-
fired as device orientation changes:
|
|
98688
|
-
eventObject.rotation.x (beta in HTML specs) holds rotation about the x axis between -180 and 180 (tipped forward or backward)
|
|
98689
|
-
eventObject.rotation.y (gamma in HTML specs) holds rotation about the y axis between -90 and 90 (tipped left or right)
|
|
98690
|
-
eventObject.rotation.z (alpha in HTML specs) holds rotation about the z axis 0-360 clockwise (relative to orientation when app loads)
|
|
98691
|
-
note rotation.z is 360-alpha compared to the HTML 5 specs
|
|
98692
|
-
note also that beta, gamma and alpha from the HTML 5 specs are also provided
|
|
98693
|
-
--*///+83.86
|
|
98694
|
-
// Device motion and orientation events are available as Frame events
|
|
98695
|
-
//-83.86
|
|
98696
|
-
|
|
98697
|
-
/*--
|
|
98698
|
-
Shake - device motion event
|
|
98699
|
-
|
|
98700
|
-
Shake
|
|
98701
|
-
"devicemotion" Frame event
|
|
98702
|
-
|
|
98703
|
-
DESCRIPTION
|
|
98704
|
-
The Frame has a "devicemotion" event to capture shaking the device with the accelerometer.
|
|
98705
|
-
|
|
98706
|
-
SEE: Tilt - for the "deviceorientation" event for tilt or compass
|
|
98707
|
-
|
|
98708
|
-
SEE: the PermissionAsk() class which will handle asking for permissions on devices.
|
|
98709
|
-
|
|
98710
|
-
EXAMPLE
|
|
98711
|
-
// SHAKE - https://zimjs.com/zapp/Z_XF8JM
|
|
98712
|
-
// for capturing shaking motion on device (acceleration about an axis)
|
|
98713
|
-
// be on a mobile device or a device with sensors
|
|
98714
|
-
new PermissionAsk(init, "devicemotion");
|
|
98715
|
-
function init(yes) {
|
|
98716
|
-
if (yes) { // the user answered yes to PermissionAsk
|
|
98717
|
-
// all code goes in here
|
|
98718
|
-
new Label("Shake the device").center();
|
|
98719
|
-
S.update();
|
|
98720
|
-
let id;
|
|
98721
|
-
F.on("devicemotion", e=>{
|
|
98722
|
-
// for shake
|
|
98723
|
-
if (
|
|
98724
|
-
Math.abs(e.acceleration.x) > 5 ||
|
|
98725
|
-
Math.abs(e.acceleration.y) > 5 ||
|
|
98726
|
-
Math.abs(e.acceleration.z) > 5
|
|
98727
|
-
) {
|
|
98728
|
-
if (F.color != green) {
|
|
98729
|
-
F.color = green;
|
|
98730
|
-
S.update();
|
|
98731
|
-
}
|
|
98732
|
-
if (id) id.clear();
|
|
98733
|
-
id = timeout(.2, ()=>{
|
|
98734
|
-
F.color = light;
|
|
98735
|
-
S.update();
|
|
98736
|
-
});
|
|
98737
|
-
}
|
|
98738
|
-
});
|
|
98739
|
-
} else { // the user answered no to PermissionAsk
|
|
98740
|
-
new Pane("SENSOR not available",yellow).show();
|
|
98741
|
-
}
|
|
98742
|
-
}
|
|
98743
|
-
END EXAMPLE
|
|
98744
|
-
|
|
98745
|
-
EVENTS
|
|
98746
|
-
"devicemotion" - for shake
|
|
98747
|
-
fired on moving mobile device - like a shake - eventObject.acceleration holds x, y and z properties of motion
|
|
98748
|
-
--*///+83.87
|
|
98749
|
-
// Device motion and orientation events are available as Frame events
|
|
98750
|
-
//-83.87
|
|
98751
|
-
|
|
98752
98714
|
/*--
|
|
98753
98715
|
zim.PermissionAsk = function(callback, permissionType, color, backgroundColor, style, group, inherit)
|
|
98754
98716
|
|
|
@@ -98769,6 +98731,9 @@ NOTE: as of ZIM 5.5.0 the zim namespace is no longer required (unless zns is set
|
|
|
98769
98731
|
|
|
98770
98732
|
NOTE: sensor prompt text can be customized prior to calling with F.sensorText = "Custom message";
|
|
98771
98733
|
|
|
98734
|
+
NOTE: as of ZIM 020 tilt(), turn(), and shake() can be applied as methods to DisplayObjects
|
|
98735
|
+
and will call PermissionAsk automatically so would suggest using those methods
|
|
98736
|
+
|
|
98772
98737
|
EXAMPLE
|
|
98773
98738
|
// DEVICE ORIENTATION - gives angle of device in all 3 dimensions
|
|
98774
98739
|
// See https://zimjs.com/zapp/Z_Q5UYS
|
|
@@ -98938,8 +98903,18 @@ no - reference to the zim Button with NO
|
|
|
98938
98903
|
return;
|
|
98939
98904
|
}
|
|
98940
98905
|
|
|
98941
|
-
//
|
|
98942
|
-
|
|
98906
|
+
// Fast check: if sensors not supported in environment (e.g. non-secure HTTP or missing API)
|
|
98907
|
+
var hasOrientAPI = typeof DeviceOrientationEvent != "undefined" && DeviceOrientationEvent;
|
|
98908
|
+
var hasMotionAPI = typeof DeviceMotionEvent != "undefined" && DeviceMotionEvent;
|
|
98909
|
+
if (WW.isSecureContext === false || (pt == "deviceorientation" && !hasOrientAPI) || (pt == "devicemotion" && !hasMotionAPI)) {
|
|
98910
|
+
callback(false, pt == "deviceorientation" ? 1 : 2);
|
|
98911
|
+
return;
|
|
98912
|
+
}
|
|
98913
|
+
|
|
98914
|
+
var isIOS = (M == "ios" || (typeof navigator != "undefined" && (/iPad|iPhone|iPod/.test(navigator.userAgent) || (navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1))));
|
|
98915
|
+
|
|
98916
|
+
// Sensors probe: Only iOS devices with requestPermission require the PermissionAsk popup
|
|
98917
|
+
if (isIOS && typeof DeviceOrientationEvent != "undefined" && DeviceOrientationEvent && typeof DeviceOrientationEvent.requestPermission == "function") {
|
|
98943
98918
|
setPane();
|
|
98944
98919
|
} else {
|
|
98945
98920
|
var tested = false;
|
|
@@ -98948,7 +98923,7 @@ no - reference to the zim Button with NO
|
|
|
98948
98923
|
tested = true;
|
|
98949
98924
|
WW.removeEventListener(permissionType, testMe);
|
|
98950
98925
|
callback(false, 3); // 3 - timeout / no sensor hardware (e.g. desktop)
|
|
98951
|
-
},
|
|
98926
|
+
}, 1500);
|
|
98952
98927
|
|
|
98953
98928
|
function testMe(e) {
|
|
98954
98929
|
if (tested || okay) return;
|
|
@@ -98959,6 +98934,7 @@ no - reference to the zim Button with NO
|
|
|
98959
98934
|
WW.removeEventListener(permissionType, testMe);
|
|
98960
98935
|
setEvents();
|
|
98961
98936
|
} else {
|
|
98937
|
+
// Fast fail on desktop dummy event with nulls
|
|
98962
98938
|
tested = true;
|
|
98963
98939
|
clearTimeout(timer);
|
|
98964
98940
|
WW.removeEventListener(permissionType, testMe);
|
|
@@ -98973,6 +98949,7 @@ no - reference to the zim Button with NO
|
|
|
98973
98949
|
WW.removeEventListener(permissionType, testMe);
|
|
98974
98950
|
setEvents();
|
|
98975
98951
|
} else {
|
|
98952
|
+
// Fast fail on desktop dummy motion with nulls
|
|
98976
98953
|
tested = true;
|
|
98977
98954
|
clearTimeout(timer);
|
|
98978
98955
|
WW.removeEventListener(permissionType, testMe);
|
|
@@ -98983,20 +98960,25 @@ no - reference to the zim Button with NO
|
|
|
98983
98960
|
WW.addEventListener(permissionType, testMe);
|
|
98984
98961
|
}
|
|
98985
98962
|
|
|
98986
|
-
var lastZ = 0;
|
|
98987
|
-
var flip = 0;
|
|
98988
98963
|
function deviceorientationEvent(e) {
|
|
98989
|
-
var z = 360-e.alpha;
|
|
98990
|
-
|
|
98991
|
-
lastZ = z;
|
|
98992
|
-
e.rotation = {x:e.beta, y:e.gamma, z:(z + flip) % 360};
|
|
98964
|
+
var z = e.alpha != null ? (360 - e.alpha) % 360 : 0;
|
|
98965
|
+
e.rotation = {x:e.beta || 0, y:e.gamma || 0, z:z};
|
|
98993
98966
|
frame.dispatchEvent(e);
|
|
98994
98967
|
}
|
|
98995
98968
|
function devicemotionEvent(e) {
|
|
98969
|
+
var acc = (e.accelerationIncludingGravity || e.acceleration || e);
|
|
98970
|
+
e.accelerationData = {
|
|
98971
|
+
x: acc.x || 0,
|
|
98972
|
+
y: acc.y || 0,
|
|
98973
|
+
z: acc.z || 0
|
|
98974
|
+
};
|
|
98996
98975
|
frame.dispatchEvent(e);
|
|
98997
98976
|
}
|
|
98998
98977
|
function setEvents() {
|
|
98999
|
-
if (frame)
|
|
98978
|
+
if (frame) {
|
|
98979
|
+
if (!frame._permissionGranted) frame._permissionGranted = {};
|
|
98980
|
+
frame._permissionGranted[permissionType] = true;
|
|
98981
|
+
}
|
|
99000
98982
|
if (permissionType=="deviceorientation") {
|
|
99001
98983
|
frame.zimDeviceorientationEvent = deviceorientationEvent;
|
|
99002
98984
|
WW.addEventListener("deviceorientation", frame.zimDeviceorientationEvent);
|
|
@@ -108029,4 +108011,4 @@ export let Ticker = zim.Ticker;
|
|
|
108029
108011
|
export let Style = zim.Style;
|
|
108030
108012
|
export let assets = zim.assets;
|
|
108031
108013
|
export let assetIDs = zim.assetIDs;
|
|
108032
|
-
export let ZIMON = zim.ZIMON;
|
|
108014
|
+
export let ZIMON = zim.ZIMON;
|
|
@@ -2906,6 +2906,8 @@ declare namespace zim {
|
|
|
2906
2906
|
enabled: boolean
|
|
2907
2907
|
// END ZIM Component Interface
|
|
2908
2908
|
readonly selectedEmoji: Emoji
|
|
2909
|
+
readonly selectedText: string
|
|
2910
|
+
readonly currentEmoji: Label
|
|
2909
2911
|
readonly emojiData: string[]
|
|
2910
2912
|
}
|
|
2911
2913
|
export class TextEditor extends Container implements zimComponent {
|
|
@@ -4279,6 +4281,7 @@ declare namespace zim {
|
|
|
4279
4281
|
export function parseAudioSprite(audioSpriteData: { resources: string[], spritemap: {} }, outputAudioSprite?: boolean): { src: string, data: {} }
|
|
4280
4282
|
export function previewAudioSprite(audioSpriteData: {}, numLetters?: number, frame?: Frame): Tabs
|
|
4281
4283
|
export function svgToBitmap(svg: string | SVGElement, callBack: Function): void
|
|
4284
|
+
export function makeContent(content:string|number|DisplayObject|{}, maxWidth?:number, color?:color, scrollBar?:boolean): string|number|DisplayObject
|
|
4282
4285
|
export function fastFrame(cjs: any, stage: createjs.Stage | createjs.StageGL): Function
|
|
4283
4286
|
export function addWires({ }): {}
|
|
4284
4287
|
export function setBlurDetect(): void
|