zimjs 18.1.8 → 18.2.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/zim.js +95 -47
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zimjs",
3
- "version": "18.1.8",
3
+ "version": "18.2.0",
4
4
  "type": "module",
5
5
  "main": "./src/zim.js",
6
6
  "types": "./ts-src/typings/zim",
package/src/zim.js CHANGED
@@ -47749,6 +47749,8 @@ zim.Carousel3D = function(width, height, items, widthFactor, heightFactor, curve
47749
47749
 
47750
47750
  var shift;
47751
47751
  var min, max;
47752
+
47753
+
47752
47754
 
47753
47755
  this.makeCarousel = function() {
47754
47756
 
@@ -47811,7 +47813,7 @@ zim.Carousel3D = function(width, height, items, widthFactor, heightFactor, curve
47811
47813
  that.holder.loop(function(item, i) {
47812
47814
  item.y = item.start - r + (that.amount+r+r*2*1000000 + item.shift) % (r*2);
47813
47815
  var delta = item.y - center;
47814
- var w = Math.sqrt(Math.pow(r,2) - Math.pow(delta,2)) * 2;
47816
+ var w = (Math.sqrt(Math.pow(r,2) - Math.pow(delta,2)) * 2) || 0;
47815
47817
  item.width = w;
47816
47818
  var sh = zim.sign((height/2-item.y)) * Math.round(Math.pow((height/2-item.y), 2)/(10+900*(1-that.curve)));
47817
47819
  item.mov(0,delta*heightFactor+sh);
@@ -47824,12 +47826,12 @@ zim.Carousel3D = function(width, height, items, widthFactor, heightFactor, curve
47824
47826
  that.holder.loop(function(item, i) {
47825
47827
  item.x = item.start - r + (that.amount+r+r*2*1000000 + item.shift) % (r*2);
47826
47828
  var delta = item.x - center;
47827
- var h = Math.sqrt(Math.pow(r,2) - Math.pow(delta,2)) * 2;
47828
- item.height = h;
47829
+ var h = (Math.sqrt(Math.pow(r,2) - Math.pow(delta,2)) * 2) || 0;
47830
+ item.height = h;
47829
47831
  var sh = zim.sign((width/2-item.x)) * Math.round(Math.pow((width/2-item.x), 2)/(10+900*(1-that.curve)));
47830
- item.mov(delta*widthFactor+sh);
47832
+ item.mov(delta*widthFactor+sh);
47831
47833
  item.height = constrain(item.height - (height-item.height)*heightFactor,0,100000);
47832
- item.visible = item.height>0;
47834
+ item.visible = item.height>0;
47833
47835
  });
47834
47836
  that.holder.sortBy("height");
47835
47837
  }
@@ -47837,7 +47839,7 @@ zim.Carousel3D = function(width, height, items, widthFactor, heightFactor, curve
47837
47839
  var index = that.currentItem.dexIndex;
47838
47840
  if (index != that.latestIndex) {
47839
47841
  that.holder.loop(function(item,i,t) {
47840
- if (interactive) {
47842
+ if (interactive) {
47841
47843
  if (item==that.currentItem) {
47842
47844
  item.mouseEnabled = true;
47843
47845
  item.mouseChildren = true;
@@ -55917,7 +55919,9 @@ hitTestPoint
55917
55919
  zim DisplayObject method
55918
55920
 
55919
55921
  DESCRIPTION
55920
- See if shape of obj is hitting the global point x and y on the stage.
55922
+ Tests if shape of obj is hitting the global point x and y on the stage.
55923
+
55924
+ NOTE: https://zimjs.com/tips.html#HITTEST for tips on Hit Tests
55921
55925
 
55922
55926
  EXAMPLE
55923
55927
  const circle = new Circle().loc(100,100).drag();
@@ -55968,7 +55972,9 @@ hitTestReg
55968
55972
  zim DisplayObject method
55969
55973
 
55970
55974
  DESCRIPTION
55971
- See if the shape shape of an object is hitting the registration point of object (other).
55975
+ Tests if the shape shape of an object is hitting the registration point of object (other).
55976
+
55977
+ NOTE: https://zimjs.com/tips.html#HITTEST for tips on Hit Tests
55972
55978
 
55973
55979
  EXAMPLE
55974
55980
  const circle = new Circle(50, red).center().drag();
@@ -56018,6 +56024,8 @@ The rectangle is based on the position, registration and bounds of object (other
56018
56024
  num is how many points on the edge of the rectangle we test - default is 0.
56019
56025
  The four corners are always tested as well as the very middle of the rectangle.
56020
56026
 
56027
+ NOTE: https://zimjs.com/tips.html#HITTEST for tips on Hit Tests
56028
+
56021
56029
  EXAMPLE
56022
56030
  const circle = new Circle(50, red).center().drag();
56023
56031
  const rect = new Rectangle(100, 100, blue).loc(100,100);
@@ -56113,7 +56121,9 @@ zim DisplayObject method
56113
56121
  DESCRIPTION
56114
56122
  Uses an equation to see if the bounds of a rectangular object is hitting a point x, y.
56115
56123
  This is faster than hitTests on shapes - so will have the speed of hitTestBounds, hitTestCircles and hitTestGrid.
56116
- A margin parameter is provided to tweak the hitTest
56124
+ A margin parameter is provided to tweak the hitTest.
56125
+
56126
+ NOTE: https://zimjs.com/tips.html#HITTEST for tips on Hit Tests
56117
56127
 
56118
56128
  EXAMPLE
56119
56129
  const rect = new Rectangle(50, 50, red).center().drag();
@@ -56156,9 +56166,11 @@ zim DisplayObject method
56156
56166
  DESCRIPTION
56157
56167
  See if the shape of an object is hitting points on a circle of another object.
56158
56168
  The circle is based on the position, registration and bounds of object (other).
56159
- num is how many points around the circle we test - default is 8
56169
+ num is how many points around the circle we test - default is 8.
56160
56170
  Also checks center of circle hitting.
56161
56171
 
56172
+ NOTE: https://zimjs.com/tips.html#HITTEST for tips on Hit Tests
56173
+
56162
56174
  EXAMPLE
56163
56175
  var circle = new Circle(50, red).center().drag();
56164
56176
  var triangle = new Triangle(100, 100, 100, blue).loc(100,100);
@@ -56239,9 +56251,11 @@ DO NOT use with a rotated rectangle object - for that use hitTestRect() or hitTe
56239
56251
  This is faster than hitTests on shapes - so will have the speed of hitTestBounds, hitTestCircles and hitTestGrid.
56240
56252
  The circle is based on a the object radius if there is one
56241
56253
  and if no radius then the average of the width and height divided by two.
56242
- A margin parameter is provided to tweak the hitTest
56243
- The rect is based on the bounds of the second object projected globally as a rectangle
56244
- If the second object bounds are rotated, the global bounds will be bigger to keep parallel to the axes
56254
+ A margin parameter is provided to tweak the hitTest.
56255
+ The rect is based on the bounds of the second object projected globally as a rectangle.
56256
+ If the second object bounds are rotated, the global bounds will be bigger to keep parallel to the axes.
56257
+
56258
+ NOTE: https://zimjs.com/tips.html#HITTEST for tips on Hit Tests
56245
56259
 
56246
56260
  EXAMPLE
56247
56261
  const ball = new Circle(50, red).center().drag();
@@ -56304,7 +56318,9 @@ Uses an equation to see if a circlular object is hitting a point x, y.
56304
56318
  This is faster than hitTests on shapes - so will have the speed of hitTestBounds, hitTestCircles and hitTestGrid.
56305
56319
  The circle is based on a the object radius if there is one
56306
56320
  and if no radius then the average of the width and height divided by two.
56307
- A margin parameter is provided to tweak the hitTest
56321
+ A margin parameter is provided to tweak the hitTest.
56322
+
56323
+ NOTE: https://zimjs.com/tips.html#HITTEST for tips on Hit Tests
56308
56324
 
56309
56325
  EXAMPLE
56310
56326
  const ball = new Circle(50, red).center().drag();
@@ -56356,7 +56372,9 @@ Uses an equation to see if two circles are intersecting.
56356
56372
  This is faster than hitTests on shapes - so will have the speed of hitTestBounds and hitTestGrid.
56357
56373
  The circles are based on the bounds of the two objects - it does not matter on which object the method is placed.
56358
56374
  If the bounds are not square then half the average length of the sides is used as the radius.
56359
- A margin parameter is provided to tweak the hitTest
56375
+ A margin parameter is provided to tweak the hitTest.
56376
+
56377
+ NOTE: https://zimjs.com/tips.html#HITTEST for tips on Hit Tests
56360
56378
 
56361
56379
  EXAMPLE
56362
56380
  const ball = new Circle(50, red).center().drag();
@@ -56413,6 +56431,8 @@ See if obj.getBounds() is hitting other.getBounds().
56413
56431
  Margin can be adjusted to tweak the hitTest.
56414
56432
  Pass in a boundsShape shape if you want a demonstration of where the bounds are.
56415
56433
 
56434
+ NOTE: https://zimjs.com/tips.html#HITTEST for tips on Hit Tests
56435
+
56416
56436
  EXAMPLE
56417
56437
  const circle = new Circle(50, red).center().drag();
56418
56438
  const rect = new Rectangle(100, 100, blue).loc(100,100);
@@ -56470,9 +56490,12 @@ zim DisplayObject method
56470
56490
 
56471
56491
  DESCRIPTION
56472
56492
  See if the shape of an object is hitting points on a path of a Squiggle or Blob.
56473
- num is how many points between each point on the path we test - default is 2
56493
+ num is how many points between each point on the path we test - default is 2.
56494
+
56474
56495
  SEE: https://zimjs.com/hittestpath.html
56475
56496
 
56497
+ NOTE: https://zimjs.com/tips.html#HITTEST for tips on Hit Tests
56498
+
56476
56499
  EXAMPLE
56477
56500
  const path = new Blob().center();
56478
56501
  const circle = new Circle(50, purple).pos(100,100).drag();
@@ -56555,6 +56578,8 @@ Converts an x and y point to an index in a grid.
56555
56578
  If you have a grid of rectangles, for instance, use this to find out which rectangle is beneath the cursor.
56556
56579
  This technique will work faster than any of the other hit tests.
56557
56580
 
56581
+ NOTE: https://zimjs.com/tips.html#HITTEST for tips on Hit Tests
56582
+
56558
56583
  EXAMPLE
56559
56584
  const tile = new Tile(new Rectangle(100,100),5,4,10,10).center();
56560
56585
  const circle = new Circle(10,green).pos(10,10).drag();
@@ -74073,7 +74098,7 @@ dispatches a "swipestop" event when swipeup has happened and value has stopped c
74073
74098
  //-69.5
74074
74099
 
74075
74100
  /*--
74076
- zim.MotionController = function(target, type, speed, axis, boundary, map, diagonal, damp, flip, orient, constant, firstPerson, turnSpeed, moveThreshold, stickThreshold, container, localBoundary, mouseMoveOutside, mousedownIncludes, minPercentSpeed, maxPercentSpeed, dampKeyup, rotate, mouseOutside, tileObj, penDown, offTime)
74101
+ zim.MotionController = function(target, type, speed, axis, boundary, map, diagonal, damp, flip, orient, constant, firstPerson, turnSpeed, moveThreshold, stickThreshold, container, localBoundary, mouseMoveOutside, mousedownIncludes, minPercentSpeed, maxPercentSpeed, dampKeyup, rotate, mouseOutside, tileObj, penDown, offTime, startAngle)
74077
74102
 
74078
74103
  MotionController
74079
74104
  zim class - extends a createjs EventDispatcher
@@ -74114,6 +74139,18 @@ new MotionController({
74114
74139
  });
74115
74140
  END EXAMPLE
74116
74141
 
74142
+ EXAMPLE
74143
+ // good setting for motion following cursor
74144
+ // on mousedown or finger dragging on mobile
74145
+ const t = new Triangle(80,100,100).rot(90).center();
74146
+ const mc = new MotionController({
74147
+ target:t,
74148
+ type:"follow",
74149
+ orient:true,
74150
+ offTime:.25
74151
+ });
74152
+ END EXAMPLE
74153
+
74117
74154
  EXAMPLE
74118
74155
  F.loadAssets(["beach02.jpg", "playbeachball.png"], "https://zimjs.org/assets/"); // or load in Frame()
74119
74156
  F.on("complete", ()=>{
@@ -74255,7 +74292,7 @@ METHODS
74255
74292
  pause(state, time) - state defaults to true and pauses the motionController (sets speed to 0)
74256
74293
  set state to false to unpause the motionController (sets speed to speed before pausing)
74257
74294
  set the time (default 0) to the seconds to take while slowing the motionController to 0 speed (also see ZIM TIME constant)
74258
- immediate(x, y) - set the damping immediately to this value to avoid damping to value - returns object for chaining
74295
+ immediate(x, y, rotation) - set the damping immediately to this value to avoid damping to value - returns object for chaining
74259
74296
  convert(x, y) - for manual mode, pass in x and y and damping and rotation will be calculated
74260
74297
  dispose() - remove listeners and Ticker, Swiper and GamePad, where applicable
74261
74298
 
@@ -74299,8 +74336,8 @@ dispatches a "mousedown" event if type is "mousedown" or "pressmove"
74299
74336
  dispatches a "pressing" event if type is "pressmove" - note, this dispatches even if not moving
74300
74337
  dispatches a "moving" event if target is moving and "startmoving" and "stopmoving" events
74301
74338
  --*///+69.7
74302
- zim.MotionController = function(target, type, speed, axis, boundary, map, diagonal, damp, flip, orient, constant, firstPerson, turnSpeed, moveThreshold, stickThreshold, container, localBoundary, mouseMoveOutside, mousedownIncludes, minPercentSpeed, maxPercentSpeed, dampKeyup, rotate, mouseOutside, tileObj, penDown, offTime) {
74303
- var sig = "target, type, speed, axis, boundary, map, diagonal, damp, flip, orient, constant, firstPerson, turnSpeed, moveThreshold, stickThreshold, container, localBoundary, mouseMoveOutside, mousedownIncludes, minPercentSpeed, maxPercentSpeed, dampKeyup, rotate, mouseOutside, tileObj, penDown, offTime";
74339
+ zim.MotionController = function(target, type, speed, axis, boundary, map, diagonal, damp, flip, orient, constant, firstPerson, turnSpeed, moveThreshold, stickThreshold, container, localBoundary, mouseMoveOutside, mousedownIncludes, minPercentSpeed, maxPercentSpeed, dampKeyup, rotate, mouseOutside, tileObj, penDown, offTime, startAngle) {
74340
+ var sig = "target, type, speed, axis, boundary, map, diagonal, damp, flip, orient, constant, firstPerson, turnSpeed, moveThreshold, stickThreshold, container, localBoundary, mouseMoveOutside, mousedownIncludes, minPercentSpeed, maxPercentSpeed, dampKeyup, rotate, mouseOutside, tileObj, penDown, offTime, startAngle";
74304
74341
  var duo; if (duo = zob(zim.MotionController, arguments, sig, this)) return duo;
74305
74342
  z_d("69.7");
74306
74343
 
@@ -74417,6 +74454,7 @@ dispatches a "moving" event if target is moving and "startmoving" and "stopmovin
74417
74454
  if (container && container.backing) this.mousedownIncludes.push(container.backing);
74418
74455
  // this.mousedownExcludes = mousedownExcludes;
74419
74456
  if (zot(dampKeyup)) dampKeyup = .3;
74457
+ if (zot(startAngle)) startAngle = 0;
74420
74458
 
74421
74459
  if (boundary && boundary.type!="Blob") {
74422
74460
  target.x = zim.constrain(target.x, boundary.x, boundary.x+boundary.width);
@@ -74810,6 +74848,7 @@ dispatches a "moving" event if target is moving and "startmoving" and "stopmovin
74810
74848
  speedY = trig.speedY;
74811
74849
 
74812
74850
  if (!rotate) return;
74851
+
74813
74852
  if (!zot(trig.angle)) that.rotation = trig.angle+target.zimMCStartAngle;
74814
74853
  if (zot(that.rotation)) {
74815
74854
  that.rotation = that.target.rotation;
@@ -74831,6 +74870,7 @@ dispatches a "moving" event if target is moving and "startmoving" and "stopmovin
74831
74870
  that.dampR.immediate(oldR); // required otherwise damping equation has mind of its own
74832
74871
  that.target.rotation = oldR; // make sure to set this again as we may have changed oldR for proper rotational direction when damped
74833
74872
  that.rotation = newR;
74873
+
74834
74874
  }
74835
74875
  function normalizeAngle(a) {
74836
74876
  return (a % 360 + 360) % 360;
@@ -74892,7 +74932,7 @@ dispatches a "moving" event if target is moving and "startmoving" and "stopmovin
74892
74932
 
74893
74933
  function makeKeyInterval() {
74894
74934
 
74895
- that.keyInterval = interval(time, function() {
74935
+ that.keyInterval = interval(time, function() {
74896
74936
  if (down && down[0]==0&&down[1]==0&&down[2]==0&down[3]==0) {
74897
74937
  that.keyInterval.clear();
74898
74938
  that.keyInterval = null;
@@ -74968,7 +75008,7 @@ dispatches a "moving" event if target is moving and "startmoving" and "stopmovin
74968
75008
  var mainTicker = zim.Ticker.add(function() {
74969
75009
  if (tileObj) return;
74970
75010
  if (target.draggingCheck) return;
74971
- if (type == "manual") calculate();
75011
+ if (type == "manual" && !dPad) calculate();
74972
75012
  if (that.boundary && that.boundary.type!="Blob") {
74973
75013
  that.x = zim.constrain(that.x, that.boundary.x, that.boundary.x+that.boundary.width);
74974
75014
  that.y = zim.constrain(that.y, that.boundary.y, that.boundary.y+that.boundary.height);
@@ -91051,33 +91091,38 @@ Note: there are more features to the Web Speech API - see the HTML docs
91051
91091
 
91052
91092
  var SpeechRecognition = WW.SpeechRecognition || WW.webkitSpeechRecognition;
91053
91093
  var SpeechGrammarList = WW.SpeechGrammarList || WW.webkitSpeechGrammarList;
91094
+
91095
+ var recognition;
91096
+ var SpeechRecognitionEvent = WW.SpeechRecognitionEvent || WW.webkitSpeechRecognitionEvent;
91054
91097
  // this is causing an error on firefox even though they use this in their examples
91055
91098
  // and we have all the speech about:config setting set to true
91056
- var SpeechRecognitionEvent = WW.SpeechRecognitionEvent || WW.webkitSpeechRecognitionEvent;
91057
- var recognition = this.recognition = new SpeechRecognition();
91058
- recognition.continuous = false;
91059
- recognition.lang = this.language = "en-US";
91060
- recognition.interimResults = true;
91061
- recognition.maxAlternatives = 1;
91062
-
91063
- recognition.addEventListener("result", function(e) {
91064
- var ev = new createjs.Event("result");
91065
- ev.words = e.results[0][0].transcript;
91066
- ev.confidence = e.results[0][0].confidence;
91067
- that.dispatchEvent(ev);
91068
- });
91069
- recognition.addEventListener("speechend", function(e) {
91070
- recognition.stop();
91071
- that.dispatchEvent(e);
91072
- });
91073
- recognition.addEventListener("error", function(e) {
91074
- that.dispatchEvent(e);
91075
- });
91099
+ // so test for existence
91100
+ if (typeof SpeechRecognition != "undefined") {
91101
+ recognition = this.recognition = new SpeechRecognition();
91102
+ recognition.continuous = false;
91103
+ recognition.lang = this.language = "en-US";
91104
+ recognition.interimResults = true;
91105
+ recognition.maxAlternatives = 1;
91106
+
91107
+ recognition.addEventListener("result", function(e) {
91108
+ var ev = new createjs.Event("result");
91109
+ ev.words = e.results[0][0].transcript;
91110
+ ev.confidence = e.results[0][0].confidence;
91111
+ that.dispatchEvent(ev);
91112
+ });
91113
+ recognition.addEventListener("speechend", function(e) {
91114
+ recognition.stop();
91115
+ that.dispatchEvent(e);
91116
+ });
91117
+ recognition.addEventListener("error", function(e) {
91118
+ that.dispatchEvent(e);
91119
+ });
91120
+ }
91076
91121
 
91077
91122
  }
91078
91123
 
91079
91124
  this.listen = function(interim, language) {
91080
- if (M=="ios") {zogy("not supported on iOS Web"); return this;}
91125
+ if (M=="ios" || !recognition) {zogy("Speech recognition not supported - search how to activate"); return this;}
91081
91126
  if (zot(interim)) interim = true;
91082
91127
  recognition.interimResults = this.interim = interim;
91083
91128
  if (zot(language)) recognition.lang = this.language;
@@ -91099,7 +91144,10 @@ Note: there are more features to the Web Speech API - see the HTML docs
91099
91144
  var sig = "text, voice, volume, lang, rate, pitch";
91100
91145
  var duo; if (duo = zob(this.talk, arguments, sig)) return duo;
91101
91146
 
91102
- if (typeof speechSynthesis == "undefined") return;
91147
+ if (typeof speechSynthesis == "undefined") {
91148
+ zogy("Speech synthesis not supported - search how to activate");
91149
+ return;
91150
+ }
91103
91151
  // https://wicg.github.io/speech-api
91104
91152
  if (zot(text)) return;
91105
91153
  var utter = new SpeechSynthesisUtterance();
@@ -91126,13 +91174,13 @@ Note: there are more features to the Web Speech API - see the HTML docs
91126
91174
  }
91127
91175
 
91128
91176
  this.stopTalking = function() {
91129
- if (speechSynthesis) speechSynthesis.cancel();
91177
+ if (typeof speechSynthesis != "undefined") speechSynthesis.cancel();
91130
91178
  }
91131
91179
  this.pauseTalking = function() {
91132
- if (speechSynthesis) speechSynthesis.pause();
91180
+ if (typeof speechSynthesis != "undefined") speechSynthesis.pause();
91133
91181
  }
91134
91182
  this.resumeTalking = function() {
91135
- if (speechSynthesis) speechSynthesis.resume();
91183
+ if (typeof speechSynthesis != "undefined") speechSynthesis.resume();
91136
91184
  }
91137
91185
 
91138
91186
  this.getVoices = function() {