zimjs 20.0.9 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zimjs",
3
- "version": "20.0.9",
3
+ "version": "20.1.0",
4
4
  "type": "module",
5
5
  "main": "./src/zim.js",
6
6
  "types": "./ts-src/typings/zim",
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 and SVG that is the same across platforms (Windows, Linux, Android, iOS)
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.currentEmoji.code, 200)
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 - get the selected emoji - this is a zim Emoji object
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.currentEmoji = e.target;
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);
@@ -58358,35 +58362,11 @@ RETURNS obj for chaining
58358
58362
 
58359
58363
  var dampX = damp ? new zim.Damp(mode == "position" ? obj.x : 0, damp) : null;
58360
58364
  var dampY = damp ? new zim.Damp(mode == "position" ? obj.y : 0, damp) : null;
58361
- var currentRot = {x: 0, y: 0, z: 0};
58365
+ var currentVector = {x: 0, y: 0};
58362
58366
 
58363
58367
  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;
58386
- } else {
58387
- tiltX = gamma;
58388
- tiltY = beta;
58389
- }
58368
+ var tiltX = currentVector.x;
58369
+ var tiltY = currentVector.y;
58390
58370
 
58391
58371
  if (mode == "move") {
58392
58372
  var rotX = dampX ? dampX.convert(tiltX) : tiltX;
@@ -58418,14 +58398,50 @@ RETURNS obj for chaining
58418
58398
 
58419
58399
  obj._tiltType = type;
58420
58400
  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;
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
+ }
58425
58428
  } else {
58426
- currentRot.x = e.beta || 0;
58427
- currentRot.y = e.gamma || 0;
58428
- currentRot.z = e.alpha || 0;
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
+ }
58429
58445
  }
58430
58446
  };
58431
58447
  f.on(type, obj._tiltListener);
@@ -58434,24 +58450,29 @@ RETURNS obj for chaining
58434
58450
  if (ready) ready(true, obj);
58435
58451
  }
58436
58452
 
58437
- // Shared Permission check & queueing
58438
- 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]) {
58439
58460
  activate();
58440
- } else if (f._permissionPending) {
58441
- 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); } });
58442
58463
  } else {
58443
- f._permissionPending = true;
58444
- f._permissionQueue = [{ activate: activate, reject: function() { if (ready) ready(false, obj); } }];
58464
+ f._permissionPending[type] = true;
58465
+ f._permissionQueue[type].push({ activate: activate, reject: function() { if (ready) ready(false, obj); } });
58445
58466
 
58446
58467
  new zim.PermissionAsk(function(yes) {
58447
- f._permissionPending = false;
58468
+ f._permissionPending[type] = false;
58448
58469
  if (yes) {
58449
- f._permissionGranted = true;
58450
- zim.loop(f._permissionQueue, function(item) { item.activate(); });
58470
+ f._permissionGranted[type] = true;
58471
+ zim.loop(f._permissionQueue[type], function(item) { item.activate(); });
58451
58472
  } else {
58452
- zim.loop(f._permissionQueue, function(item) { item.reject(); });
58473
+ zim.loop(f._permissionQueue[type], function(item) { item.reject(); });
58453
58474
  }
58454
- f._permissionQueue = [];
58475
+ f._permissionQueue[type] = [];
58455
58476
  }, type);
58456
58477
  }
58457
58478
 
@@ -58482,7 +58503,7 @@ RETURNS obj for chaining
58482
58503
  var duo; if (duo = zob(zim.noTilt, arguments, sig)) return duo;
58483
58504
  z_d("34.91");
58484
58505
 
58485
- if (zot(obj) || !obj.on || !obj.zimTouch) return;
58506
+ if (zot(obj) || !obj.on) return;
58486
58507
 
58487
58508
  // MONITOR
58488
58509
  var mID = "z~noTilt";
@@ -58764,7 +58785,7 @@ RETURNS obj for chaining
58764
58785
 
58765
58786
  var mag = Math.sqrt(tiltX * tiltX + tiltY * tiltY);
58766
58787
  var steerAng = Math.atan2(tiltX, tiltY) * (180 / Math.PI);
58767
- var flatAng = (alpha - orient + 360) % 360;
58788
+ var flatAng = (alpha + orient + 360) % 360;
58768
58789
 
58769
58790
  if (mode == "absolute") {
58770
58791
  currentDeviceAngle = flatAng;
@@ -58780,9 +58801,12 @@ RETURNS obj for chaining
58780
58801
  var dSteer = angleDiff(steerAng, lastSteerAng);
58781
58802
  var dFlat = angleDiff(flatAng, lastFlatAng);
58782
58803
 
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;
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
+ }
58786
58810
 
58787
58811
  currentDeviceAngle += delta;
58788
58812
  lastSteerAng = steerAng;
@@ -58796,24 +58820,29 @@ RETURNS obj for chaining
58796
58820
  if (ready) ready(true, obj);
58797
58821
  }
58798
58822
 
58799
- // Shared Permission check & queueing
58800
- 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]) {
58801
58830
  activate();
58802
- } else if (f._permissionPending) {
58803
- 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); } });
58804
58833
  } else {
58805
- f._permissionPending = true;
58806
- f._permissionQueue = [{ activate: activate, reject: function() { if (ready) ready(false, obj); } }];
58834
+ f._permissionPending[type] = true;
58835
+ f._permissionQueue[type].push({ activate: activate, reject: function() { if (ready) ready(false, obj); } });
58807
58836
 
58808
58837
  new zim.PermissionAsk(function(yes) {
58809
- f._permissionPending = false;
58838
+ f._permissionPending[type] = false;
58810
58839
  if (yes) {
58811
- f._permissionGranted = true;
58812
- zim.loop(f._permissionQueue, function(item) { item.activate(); });
58840
+ f._permissionGranted[type] = true;
58841
+ zim.loop(f._permissionQueue[type], function(item) { item.activate(); });
58813
58842
  } else {
58814
- zim.loop(f._permissionQueue, function(item) { item.reject(); });
58843
+ zim.loop(f._permissionQueue[type], function(item) { item.reject(); });
58815
58844
  }
58816
- f._permissionQueue = [];
58845
+ f._permissionQueue[type] = [];
58817
58846
  }, type);
58818
58847
  }
58819
58848
 
@@ -58843,7 +58872,7 @@ RETURNS obj for chaining
58843
58872
  var duo; if (duo = zob(zim.noTurn, arguments, sig)) return duo;
58844
58873
  z_d("34.94");
58845
58874
 
58846
- if (zot(obj) || !obj.on || !obj.zimTouch) return;
58875
+ if (zot(obj) || !obj.on) return;
58847
58876
 
58848
58877
  // MONITOR
58849
58878
  var mID = "z~noTurn";
@@ -58953,16 +58982,27 @@ RETURNS obj for chaining
58953
58982
  if (zot(type)) type = "devicemotion";
58954
58983
 
58955
58984
  var lastX = 0, lastY = 0, lastZ = 0;
58985
+ var seeded = false;
58956
58986
  var lastTime = 0;
58957
58987
 
58958
58988
  function handleMotion(e) {
58959
- var acc = e.acceleration && (e.acceleration.x != null || e.acceleration.y != null) ?
58960
- e.acceleration : (e.accelerationIncludingGravity || e);
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
+ }
58961
58993
 
58962
58994
  var ax = acc.x || 0;
58963
58995
  var ay = acc.y || 0;
58964
58996
  var az = acc.z || 0;
58965
58997
 
58998
+ if (!seeded) {
58999
+ seeded = true;
59000
+ lastX = ax;
59001
+ lastY = ay;
59002
+ lastZ = az;
59003
+ return;
59004
+ }
59005
+
58966
59006
  var deltaX = ax - lastX;
58967
59007
  var deltaY = ay - lastY;
58968
59008
  var deltaZ = az - lastZ;
@@ -59031,30 +59071,36 @@ RETURNS obj for chaining
59031
59071
  }
59032
59072
 
59033
59073
  function activate() {
59074
+ seeded = false;
59034
59075
  obj._shakeType = type;
59035
59076
  obj._shakeListener = handleMotion;
59036
59077
  f.on(type, obj._shakeListener);
59037
59078
  if (ready) ready(true, obj);
59038
59079
  }
59039
59080
 
59040
- // Shared Permission check & queueing
59041
- 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]) {
59042
59088
  activate();
59043
- } else if (f._permissionPending) {
59044
- 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); } });
59045
59091
  } else {
59046
- f._permissionPending = true;
59047
- f._permissionQueue = [{ activate: activate, reject: function() { if (ready) ready(false, obj); } }];
59092
+ f._permissionPending[type] = true;
59093
+ f._permissionQueue[type].push({ activate: activate, reject: function() { if (ready) ready(false, obj); } });
59048
59094
 
59049
59095
  new zim.PermissionAsk(function(yes) {
59050
- f._permissionPending = false;
59096
+ f._permissionPending[type] = false;
59051
59097
  if (yes) {
59052
- f._permissionGranted = true;
59053
- zim.loop(f._permissionQueue, function(item) { item.activate(); });
59098
+ f._permissionGranted[type] = true;
59099
+ zim.loop(f._permissionQueue[type], function(item) { item.activate(); });
59054
59100
  } else {
59055
- zim.loop(f._permissionQueue, function(item) { item.reject(); });
59101
+ zim.loop(f._permissionQueue[type], function(item) { item.reject(); });
59056
59102
  }
59057
- f._permissionQueue = [];
59103
+ f._permissionQueue[type] = [];
59058
59104
  }, type);
59059
59105
  }
59060
59106
 
@@ -59085,7 +59131,7 @@ RETURNS obj for chaining
59085
59131
  var duo; if (duo = zob(zim.noShake, arguments, sig)) return duo;
59086
59132
  z_d("34.96");
59087
59133
 
59088
- if (zot(obj) || !obj.on || !obj.zimTouch) return;
59134
+ if (zot(obj) || !obj.on) return;
59089
59135
 
59090
59136
  // MONITOR
59091
59137
  var mID = "z~noShake";
@@ -94613,12 +94659,12 @@ zim.Frame = function(scaling, width, height, color, outerColor, ready, assets, p
94613
94659
  // // }
94614
94660
  // }
94615
94661
 
94616
-
94662
+ var svgRoot = "https://raw.githubusercontent.com/googlefonts/noto-emoji/v2.042/svg/";
94617
94663
 
94618
94664
  var match;
94619
94665
  if (a.match) match = a.match(/^noto_(.*)/);
94620
94666
  if (match) {
94621
- a = {id:a, src:"https://raw.githubusercontent.com/googlefonts/noto-emoji/main/svg/" + getNotoFilename(match[1])}
94667
+ a = {id:a, src:svgRoot + getNotoFilename(match[1])}
94622
94668
  }
94623
94669
  if (a.replace) a = a.replace(/gf_/i, "https://fonts.googleapis.com/css?family=");
94624
94670
  // split multi into individual ZIM asset objects and make the first of these
@@ -94632,8 +94678,8 @@ zim.Frame = function(scaling, width, height, color, outerColor, ready, assets, p
94632
94678
  if (isVideoUrl(aj)) continue;
94633
94679
  if (aj.match) match = aj.match(/^noto_(.*)/);
94634
94680
  if (match) {
94635
- aj = {id:aj, src:"https://raw.githubusercontent.com/googlefonts/noto-emoji/main/svg/" + getNotoFilename(match[1])}
94636
- }
94681
+ aj = {id:aj, src:svgRoot + getNotoFilename(match[1])}
94682
+ }
94637
94683
  if (aj.split) {
94638
94684
  var temp = aj.split("?");
94639
94685
  ext = temp[0].match(re);
@@ -97682,6 +97728,8 @@ added, click, dblclick, mousedown, mouseout, mouseover, pressdown (ZIM), pressmo
97682
97728
  }
97683
97729
  zim.extend(zim.SVG, zim.Container, ["clone"], "zimContainer", false);//-83.09
97684
97730
 
97731
+
97732
+
97685
97733
  /*--
97686
97734
  Speech = function()
97687
97735
 
@@ -98875,7 +98923,7 @@ no - reference to the zim Button with NO
98875
98923
  tested = true;
98876
98924
  WW.removeEventListener(permissionType, testMe);
98877
98925
  callback(false, 3); // 3 - timeout / no sensor hardware (e.g. desktop)
98878
- }, 500);
98926
+ }, 1500);
98879
98927
 
98880
98928
  function testMe(e) {
98881
98929
  if (tested || okay) return;
@@ -98886,6 +98934,7 @@ no - reference to the zim Button with NO
98886
98934
  WW.removeEventListener(permissionType, testMe);
98887
98935
  setEvents();
98888
98936
  } else {
98937
+ // Fast fail on desktop dummy event with nulls
98889
98938
  tested = true;
98890
98939
  clearTimeout(timer);
98891
98940
  WW.removeEventListener(permissionType, testMe);
@@ -98900,6 +98949,7 @@ no - reference to the zim Button with NO
98900
98949
  WW.removeEventListener(permissionType, testMe);
98901
98950
  setEvents();
98902
98951
  } else {
98952
+ // Fast fail on desktop dummy motion with nulls
98903
98953
  tested = true;
98904
98954
  clearTimeout(timer);
98905
98955
  WW.removeEventListener(permissionType, testMe);
@@ -98916,10 +98966,19 @@ no - reference to the zim Button with NO
98916
98966
  frame.dispatchEvent(e);
98917
98967
  }
98918
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
+ };
98919
98975
  frame.dispatchEvent(e);
98920
98976
  }
98921
98977
  function setEvents() {
98922
- if (frame) frame._permissionGranted = true;
98978
+ if (frame) {
98979
+ if (!frame._permissionGranted) frame._permissionGranted = {};
98980
+ frame._permissionGranted[permissionType] = true;
98981
+ }
98923
98982
  if (permissionType=="deviceorientation") {
98924
98983
  frame.zimDeviceorientationEvent = deviceorientationEvent;
98925
98984
  WW.addEventListener("deviceorientation", frame.zimDeviceorientationEvent);
@@ -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