zimjs 16.2.2 → 16.2.3

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 +149 -50
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zimjs",
3
- "version": "16.2.2",
3
+ "version": "16.2.3",
4
4
  "type": "module",
5
5
  "main": "./src/zim.js",
6
6
  "types": "./ts-src/typings/zim",
package/src/zim.js CHANGED
@@ -4046,6 +4046,50 @@ RETURNS Boolean indicating success
4046
4046
  return true;
4047
4047
  };//-17.1
4048
4048
 
4049
+ /*--
4050
+ zim.setProps = function(obj, props)
4051
+
4052
+ setProps
4053
+ zim function
4054
+
4055
+ DESCRIPTION
4056
+ Sets the props of an object literal {} on the provided object or array
4057
+ Each value can be a ZIM VEE value - see docs for ZIM Pick()
4058
+ Thanks Pettis Brandon and Joseph Diefenbach for the thoughts on this
4059
+
4060
+ NOTE: as of ZIM 5.5.0 the zim namespace is no longer required (unless zns is set to true before running zim)
4061
+
4062
+ EXAMPLE
4063
+ const c = new Circle().addTo();
4064
+ setProps(c, {x:100, y:200}); // can also use CreateJS set() method for this
4065
+
4066
+ // Set props for each object in array
4067
+ const a = [new Circle().loc(100,100), new Rectangle().loc(300,100)];
4068
+ setProps(a, {color:red, borderColor:blue}); // cannot use CreateJS set() method for this
4069
+
4070
+ // Use the setProps() method of a Tile - just calls the setProps() function
4071
+ // The method is available on Tile, Wrapper, LabelLetters, LabelWords, LabelOnPath, LabelOnArc, etc.
4072
+ new Tile().center().setProps(color:[red, orange, yellow])
4073
+ END EXAMPLE
4074
+
4075
+ PARAMETERS
4076
+ obj - an object or an array of objects
4077
+ props - an object literal {} of properties and values to set on the object or objects in an array
4078
+ the value can be ZIM VEE values - see docs for ZIM Pick()
4079
+
4080
+ --*///+17.15
4081
+ zim.setProps = function(obj, props) {
4082
+ z_d("17.15");
4083
+ if (zot(obj)) return;
4084
+ if (!Array.isArray(obj)) obj = [obj];
4085
+ zim.loop(obj, function (item) {
4086
+ zim.loop(props, function(name, val) {
4087
+ item[name] = zik(val);
4088
+ });
4089
+ });
4090
+ };//-17.15
4091
+
4092
+
4049
4093
  /*--
4050
4094
  zim.mobile = function(orientation)
4051
4095
 
@@ -21641,6 +21685,9 @@ METHODS
21641
21685
  toggle(state) - leave off state to toggle path to opposite state. Use true to hide and false to show - returns object for chaining
21642
21686
  hidePath() - hides path - returns object for chaining
21643
21687
  showPath() - shows path - returns object for chaining
21688
+ setProps(properties) - sets provided properties (as {prop:val, prop:val}) for each letter
21689
+ the values accept ZIM VEE - dynamic parameters - see ZIM Pick()
21690
+ returns object for chaining
21644
21691
  resize() - if not interactive, call this to update the text on the path - returns object for chaining
21645
21692
  cache(see Container docs for parameter description) - overrides CreateJS cache() and returns object for chaining
21646
21693
  Leave parameters blank to cache bounds of shape (plus outer edge of border if borderWidth > 0)
@@ -21744,6 +21791,11 @@ zim.LabelOnPath = function(label, path, percentAngle, percents, showPath, allowT
21744
21791
  that.resize();
21745
21792
  }
21746
21793
 
21794
+ this.setProps = function(props) {
21795
+ zim.setProps(this.letters, props);
21796
+ return this;
21797
+ }
21798
+
21747
21799
  this.resize = function() {
21748
21800
  var segmentRatios = path.segmentRatios;
21749
21801
  var segmentPoints = path.segmentPoints;
@@ -21920,6 +21972,9 @@ inherit - (default null) used internally but can receive an {} of styles directl
21920
21972
 
21921
21973
  METHODS
21922
21974
  hasProp(property as String) - returns true if property exists on object else returns false
21975
+ setProps(properties) - sets provided properties (as {prop:val, prop:val}) for each label
21976
+ the values accept ZIM VEE - dynamic parameters - see ZIM Pick()
21977
+ returns object for chaining
21923
21978
  clone() - makes a copy with properties such as x, y, etc. also copied
21924
21979
  dispose() - removes from parent, removes event listeners - must still set outside references to null for garbage collection
21925
21980
 
@@ -22078,8 +22133,12 @@ zim.LabelOnArc = function(label, size, font, color, radius, flip, spacing, lette
22078
22133
  lastAngle = letter.rotation = lastAngle + angles[i];
22079
22134
  }
22080
22135
  }
22081
-
22082
-
22136
+
22137
+ this.setProps = function(props) {
22138
+ zim.setProps(this.labels, props);
22139
+ return this;
22140
+ }
22141
+
22083
22142
  Object.defineProperty(this, 'radius', {
22084
22143
  get: function() {
22085
22144
  return radius;
@@ -22198,6 +22257,9 @@ inherit - (default null) used internally but can receive an {} of styles directl
22198
22257
 
22199
22258
  METHODS
22200
22259
  hasProp(property as String) - returns true if property exists on object else returns false
22260
+ setProps(properties) - sets provided properties (as {prop:val, prop:val}) for each label
22261
+ the values accept ZIM VEE - dynamic parameters - see ZIM Pick()
22262
+ returns object for chaining
22201
22263
  clone() - makes a copy with properties such as x, y, etc. also copied
22202
22264
  dispose() - removes from parent, removes event listeners - must still set outside references to null for garbage collection
22203
22265
 
@@ -22701,6 +22763,10 @@ added, click, dblclick, mousedown, mouseout, mouseover, pressdown (ZIM), pressmo
22701
22763
  this.regX = this.getBounds().x;
22702
22764
  this.regY = this.getBounds().y;
22703
22765
 
22766
+ this.setProps = function(props) {
22767
+ zim.setProps(this.labels, props);
22768
+ return this;
22769
+ }
22704
22770
 
22705
22771
  Object.defineProperty(this, 'color', {
22706
22772
  get: function () {
@@ -22849,7 +22915,7 @@ hasProp(property as String) - returns true if property exists on object else ret
22849
22915
  clone() - makes a copy with properties such as x, y, etc. also copied
22850
22916
  dispose() - removes from parent, removes event listeners - must still set outside references to null for garbage collection
22851
22917
 
22852
- ALSO: See ZIM Wrapper for methods such as add(), addAt(), remove(), resize(), etc.
22918
+ ALSO: See ZIM Wrapper for methods such as setProps(), add(), addAt(), remove(), resize(), etc.
22853
22919
 
22854
22920
  ALSO: ZIM 4TH adds all the methods listed under Container (see above), such as:
22855
22921
  drag(), hitTestRect(), animate(), sca(), reg(), mov(), center(), centerReg(),
@@ -51582,7 +51648,8 @@ css - (default false) set to true if there is no Frame
51582
51648
  </script>
51583
51649
  protect - (default false) protects animation from being interrupted before finishing
51584
51650
  unless manually interrupted with stopAnimate()
51585
- protect is always true (regardless of parameter setting) if loop or rewind parameters are set
51651
+ protect will default to true if loop or rewind parameters are set
51652
+ but this can be overriden if protect is set to false
51586
51653
  override - (default true) subesequent tweens of any type on object cancel all earlier tweens on object
51587
51654
  set to false to allow multiple tweens of same object
51588
51655
  from - |ZIM VEE| (default false) set to true to animate from obj properties to the current properties set on target
@@ -51945,6 +52012,7 @@ RETURNS the target for chaining (or null if no target is provided and run on zim
51945
52012
  if (zot(params)) params = target;
51946
52013
  if (zot(ticker)) ticker = true;
51947
52014
  if (zot(css)) css = false;
52015
+ var originalProtect = protect;
51948
52016
  if (zot(protect)) protect = false;
51949
52017
  if (zot(from)) from = false;
51950
52018
  if (zot(set)) set = {};
@@ -52459,49 +52527,58 @@ RETURNS the target for chaining (or null if no target is provided and run on zim
52459
52527
  }
52460
52528
  }
52461
52529
 
52462
- // convert color tween
52463
- if (target.setColorRange && !zot(obj.color)) {
52464
- var color = obj.color;
52465
- delete obj.color;
52466
- obj.colorRange = 1;
52467
- target.setColorRange(target.color, color);
52468
- target.colorRange = 0;
52469
- } else if (obj.color && (target.material || target.isMaterial)) {
52470
- if (target.isMaterial) {
52471
- zogy("ZIM animate - please animate the color on the mesh not the material");
52472
- return target;
52473
- }
52474
- var coTarget = target;
52475
- if (coTarget.cT) {zim.Ticker.remove(coTarget.cT);}
52476
- target = {val:0, zimTweens:{}, ticker:coTarget.cT};
52477
- var startColor = coTarget.material.color.getHexString();
52478
- var endColor = obj.color;
52479
- obj = {val:1};
52480
- coTarget.cT = zim.Ticker.add(function() {
52481
- var cc = zim.colorRange("#"+startColor, endColor, target.val);
52482
- coTarget.material.color.set(cc);
52483
- });
52484
- if (call) {
52485
- var oldCall = call;
52486
- call = function() {
52487
- if (coTarget.cT == target.ticker) {
52488
- oldCall(callParams||coTarget);
52489
- zim.Ticker.remove(coTarget.cT);
52490
- coTarget.cT = null;
52491
- target = null;
52492
- }
52530
+ // convert color tween - added protect for colorRange in ZIM 016
52531
+ var colorBusy = target.zimBusy && target.zimBusy.colorRange;
52532
+ if (!colorBusy) {
52533
+ if (target.setColorRange && !zot(obj.color)) {
52534
+ var color = obj.color;
52535
+ delete obj.color;
52536
+ obj.colorRange = 1;
52537
+ target.setColorRange(target.color, color);
52538
+ target.colorRange = 0;
52539
+ } else if (obj.color && (target.material || target.isMaterial)) {
52540
+ if (target.isMaterial) {
52541
+ zogy("ZIM animate - please animate the color on the mesh not the material");
52542
+ return target;
52493
52543
  }
52494
- } else {
52495
- call = function() {
52496
- if (coTarget.cT == target.ticker) {
52497
- zim.Ticker.remove(coTarget.cT);
52498
- coTarget.cT = null;
52499
- target = null;
52544
+ var coTarget = target;
52545
+ if (coTarget.cT) {zim.Ticker.remove(coTarget.cT);}
52546
+ target = {val:0, zimTweens:{}, ticker:coTarget.cT};
52547
+ var startColor = coTarget.material.color.getHexString();
52548
+ var endColor = obj.color;
52549
+ obj = {val:1};
52550
+ coTarget.cT = zim.Ticker.add(function() {
52551
+ var cc = zim.colorRange("#"+startColor, endColor, target.val);
52552
+ coTarget.material.color.set(cc);
52553
+ });
52554
+ if (call) {
52555
+ var oldCall = call;
52556
+ call = function() {
52557
+ if (coTarget.cT == target.ticker) {
52558
+ oldCall(callParams||coTarget);
52559
+ zim.Ticker.remove(coTarget.cT);
52560
+ coTarget.cT = null;
52561
+ target = null;
52562
+ }
52563
+ }
52564
+ } else {
52565
+ call = function() {
52566
+ if (coTarget.cT == target.ticker) {
52567
+ zim.Ticker.remove(coTarget.cT);
52568
+ coTarget.cT = null;
52569
+ target = null;
52570
+ }
52500
52571
  }
52501
52572
  }
52502
52573
  }
52574
+ } else {
52575
+ if (obj.color) { // just to handle protect
52576
+ delete obj.color;
52577
+ obj.colorRange = 1;
52578
+ }
52503
52579
  }
52504
52580
 
52581
+
52505
52582
  // moved these to before protect (to catch scale convert) - ZIM Cat
52506
52583
  // PREPARE ZIK RANDOM VALUES PASSED IN AS ARRAY OR RAND OBJECT {min, max, integer, negative}
52507
52584
  var savedPicks = {};
@@ -52516,6 +52593,7 @@ RETURNS the target for chaining (or null if no target is provided and run on zim
52516
52593
  delete obj.scale;
52517
52594
  }
52518
52595
 
52596
+
52519
52597
  // PROTECT LOOPS AND REWINDS WITH BUSY
52520
52598
  // if protected or a loop or rewind is currently running for any of these properties
52521
52599
  // then remove the property from obj as it is currently busy
@@ -52523,7 +52601,6 @@ RETURNS the target for chaining (or null if no target is provided and run on zim
52523
52601
  if (!target.zimBusy) break;
52524
52602
  if (target.zimBusy[o]) delete obj[o];
52525
52603
  }
52526
-
52527
52604
  if (zim.isEmpty(obj)) return; // nothing left to animate
52528
52605
  if (target.type != "Sprite") {
52529
52606
  if (target.type != undefined) target.paused = false;
@@ -52537,6 +52614,7 @@ RETURNS the target for chaining (or null if no target is provided and run on zim
52537
52614
  }
52538
52615
  }
52539
52616
  function addZimBusy() {
52617
+ if (originalProtect === false) return;
52540
52618
  if (!target.zimMouseEnabledCheck) {
52541
52619
  target.zimMouseEnabledCheck = true;
52542
52620
  target.zimLastMouseEnabled = target.mouseEnabled;
@@ -52554,6 +52632,7 @@ RETURNS the target for chaining (or null if no target is provided and run on zim
52554
52632
  if (protect || cjsProps.loop || cjsProps.rewind) addZimBusy();
52555
52633
 
52556
52634
 
52635
+
52557
52636
  // IDS and IDSETS
52558
52637
  // this is for ids and idSets on this target
52559
52638
  // a single tween for an id does not get an idSet
@@ -59781,6 +59860,9 @@ METHODS
59781
59860
  add(items) - add an item or an array of items to the wrapper - will call a resize() - returns the wrapper for chaining
59782
59861
  addAt(items, index) - insert an item or an array of items at an index - will call a resize() - returns the wrapper for chaining
59783
59862
  remove(items) - removes an item or items (pass in an array) - will call a resize() - returns the wrapper for chaining
59863
+ setProps(properties) - sets provided properties (as {prop:val, prop:val}) for each item
59864
+ the values accept ZIM VEE - dynamic parameters - see ZIM Pick()
59865
+ returns object for chaining
59784
59866
  resize(width, height) - resize the wrapper passing an optional width and height - returns wrapper for chaining
59785
59867
  most of the properties below resize the wrapper automatically
59786
59868
  hasProp(property as String) - returns true if property exists on object else returns false
@@ -60337,6 +60419,13 @@ alpha, cursor, shadow, name, mouseChildren, mouseEnabled, parent, numChildren, e
60337
60419
  }
60338
60420
  } // end alignObjects
60339
60421
 
60422
+
60423
+ this.setProps = function(props) {
60424
+ zim.setProps(this.items, props);
60425
+ return this;
60426
+ }
60427
+
60428
+
60340
60429
  Object.defineProperty(that, 'spacingH', {
60341
60430
  get: function() {
60342
60431
  return spacingH;
@@ -60724,6 +60813,9 @@ itemUnderPoint(x, y, ignoreSpacing) - gets the item under a global point - (with
60724
60813
  ** will not work properly with squeeze and gets original items - so not items that are moved
60725
60814
  x and y are F.mouseX, F.mouseY for example.
60726
60815
  ignoreSpacing defaults to true and is a bigger selection space if there is spacing (can also be set to HORIZONTAL or VERTICAL to ignore only one direction)
60816
+ setProps(properties) - sets provided properties (as {prop:val, prop:val}) for each item
60817
+ the values accept ZIM VEE - dynamic parameters - see ZIM Pick()
60818
+ returns object for chaining
60727
60819
  remake(items) - pass in an array of items to tile - see items property for editing current list - returns tile for chaining
60728
60820
  can also change rows and cols and remake()
60729
60821
  resize(width, height) - resize the tile with new width and/or height if the width and/or height parameters were set - returns tile for chaining
@@ -61220,6 +61312,11 @@ note: the item is not the event object target - as that is the tile
61220
61312
  } // end resize
61221
61313
 
61222
61314
  resize(width, height);
61315
+
61316
+ this.setProps = function(props) {
61317
+ zim.setProps(this.items, props);
61318
+ return this;
61319
+ }
61223
61320
 
61224
61321
  this.itemUnderPoint = function(x, y, ignoreSpacing) {
61225
61322
  if (zot(ignoreSpacing)) ignoreSpacing = true;
@@ -82833,23 +82930,23 @@ zim.Frame = function(scaling, width, height, color, outerColor, ready, assets, p
82833
82930
  WW.removeEventListener("mouseup", leftEvent);
82834
82931
 
82835
82932
  if (!allowDefault) document.body.style.overflow = "auto";
82836
- zim.Ticker.dispose(stage);
82837
82933
  recursiveDispose(stage);
82838
- if (that == zim.tickerFrame) zim.tickerFrame = null;
82839
82934
  function recursiveDispose(obj) {
82840
- if (obj && obj.dispose) obj.dispose();
82935
+ if (obj.dispose) obj.dispose();
82841
82936
  else {
82842
- if (obj) obj.removeAllEventListeners();
82843
- if (obj && obj.numChildren) {
82937
+ obj.removeAllEventListeners();
82938
+ if (obj.numChildren) {
82844
82939
  for (var i=obj.numChildren-1; i>=0; i--) {
82845
82940
  recursiveDispose(obj.getChildAt(i));
82846
82941
  }
82847
82942
  }
82848
- if (obj && obj.parent) obj.parent.removeChild(obj);
82943
+ if (obj.parent) obj.parent.removeChild(obj);
82849
82944
  }
82850
82945
  obj = null;
82851
82946
  }
82852
- if (zid(canvasID)) zid(canvasID).parentNode.removeChild(zid(canvasID));
82947
+ if (zid(canvasID)) zid(canvasID).parentNode.removeChild(zid(canvasID));
82948
+ zim.Ticker.dispose(stage);
82949
+ if (that == zim.tickerFrame) zim.tickerFrame = null;
82853
82950
  if (that === WW.zdf) WW.zdf = WW.S = WW.W = WW.H = null;
82854
82951
 
82855
82952
  stage = null;
@@ -87672,7 +87769,8 @@ EXAMPLE
87672
87769
  const lb = new LeaderBoard({
87673
87770
  data:"E-MAILED CODE FROM zimjs.com/leaderboard/",
87674
87771
  corner:0,
87675
- backgroundColor:dark
87772
+ backgroundColor:dark,
87773
+ titleColor:light
87676
87774
  }).center();
87677
87775
 
87678
87776
  // then to record a score at some point later:
@@ -90570,6 +90668,7 @@ export let makeSyllable = zim.makeSyllable;
90570
90668
  export let makePrimitive = zim.makePrimitive;
90571
90669
  export let makeMath = zim.makeMath;
90572
90670
  export let swapProperties = zim.swapProperties;
90671
+ export let setProps = zim.setProps;
90573
90672
  export let mobile = zim.mobile;
90574
90673
  export let vee = zim.vee;
90575
90674
  export let extend = zim.extend;