zimjs 16.2.2 → 16.2.4

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 +155 -58
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zimjs",
3
- "version": "16.2.2",
3
+ "version": "16.2.4",
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(),
@@ -33774,6 +33840,7 @@ added, click, dblclick, mousedown, mouseout, mouseover, pressdown (ZIM), pressmo
33774
33840
  selector = this.selector = new zim.Rectangle(targetW, targetH, zim.faint, zim.faint, borderWidth, corner, dashed, {ignoreScale:!resizeScale})
33775
33841
  .centerReg(that);
33776
33842
  selector.loc(tile.width/2, target.y+paddingV, that, behind?0:1);
33843
+ zog(tile.width/2, target.y+paddingV)
33777
33844
  selector.visible = false;
33778
33845
  }
33779
33846
  if (!(selectedIndex < 0 || zot(currentItem))) {
@@ -34028,13 +34095,9 @@ added, click, dblclick, mousedown, mouseout, mouseover, pressdown (ZIM), pressmo
34028
34095
  if (style!==false) zim.styleTransforms(this, DS); // global function - would have put on DisplayObject if had access to it
34029
34096
 
34030
34097
  this.clone = function(exact) {
34031
- if (exact) {
34032
- var exactItems = [];
34033
- for (var i=0; i<that.tile.items.length; i++) {
34034
- exactItems.push(that.tile.items[i].clone(true));
34035
- }
34036
- }
34037
- return that.cloneProps(new zim.Selector(exact?zim.series(exactItems):(tile.clone?tile.clone():tile), borderColor, borderWidth, backgroundColor, corner, dashed, paddingH, paddingV, speed, diagonal, dim, multi, keyArrows, behind, resizeScale, selectedIndex, liveIndex, this.style, this.group));
34098
+ var cl = tile.clone?tile.clone(exact):tile;
34099
+ cl.x = cl.y = 0;
34100
+ return that.cloneProps(new zim.Selector(cl, borderColor, borderWidth, backgroundColor, corner, dashed, paddingH, paddingV, speed, diagonal, dim, multi, keyArrows, behind, resizeScale, selectedIndex, liveIndex, this.style, this.group));
34038
34101
  };
34039
34102
  this.dispose = function(a,b,disposing) {
34040
34103
  if (that.keyEvent && that.stage) that.stage.frame.off("keydown", that.keyEvent);
@@ -51582,7 +51645,8 @@ css - (default false) set to true if there is no Frame
51582
51645
  </script>
51583
51646
  protect - (default false) protects animation from being interrupted before finishing
51584
51647
  unless manually interrupted with stopAnimate()
51585
- protect is always true (regardless of parameter setting) if loop or rewind parameters are set
51648
+ protect will default to true if loop or rewind parameters are set
51649
+ but this can be overriden if protect is set to false
51586
51650
  override - (default true) subesequent tweens of any type on object cancel all earlier tweens on object
51587
51651
  set to false to allow multiple tweens of same object
51588
51652
  from - |ZIM VEE| (default false) set to true to animate from obj properties to the current properties set on target
@@ -51945,6 +52009,7 @@ RETURNS the target for chaining (or null if no target is provided and run on zim
51945
52009
  if (zot(params)) params = target;
51946
52010
  if (zot(ticker)) ticker = true;
51947
52011
  if (zot(css)) css = false;
52012
+ var originalProtect = protect;
51948
52013
  if (zot(protect)) protect = false;
51949
52014
  if (zot(from)) from = false;
51950
52015
  if (zot(set)) set = {};
@@ -52459,49 +52524,58 @@ RETURNS the target for chaining (or null if no target is provided and run on zim
52459
52524
  }
52460
52525
  }
52461
52526
 
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
- }
52527
+ // convert color tween - added protect for colorRange in ZIM 016
52528
+ var colorBusy = target.zimBusy && target.zimBusy.colorRange;
52529
+ if (!colorBusy) {
52530
+ if (target.setColorRange && !zot(obj.color)) {
52531
+ var color = obj.color;
52532
+ delete obj.color;
52533
+ obj.colorRange = 1;
52534
+ target.setColorRange(target.color, color);
52535
+ target.colorRange = 0;
52536
+ } else if (obj.color && (target.material || target.isMaterial)) {
52537
+ if (target.isMaterial) {
52538
+ zogy("ZIM animate - please animate the color on the mesh not the material");
52539
+ return target;
52493
52540
  }
52494
- } else {
52495
- call = function() {
52496
- if (coTarget.cT == target.ticker) {
52497
- zim.Ticker.remove(coTarget.cT);
52498
- coTarget.cT = null;
52499
- target = null;
52541
+ var coTarget = target;
52542
+ if (coTarget.cT) {zim.Ticker.remove(coTarget.cT);}
52543
+ target = {val:0, zimTweens:{}, ticker:coTarget.cT};
52544
+ var startColor = coTarget.material.color.getHexString();
52545
+ var endColor = obj.color;
52546
+ obj = {val:1};
52547
+ coTarget.cT = zim.Ticker.add(function() {
52548
+ var cc = zim.colorRange("#"+startColor, endColor, target.val);
52549
+ coTarget.material.color.set(cc);
52550
+ });
52551
+ if (call) {
52552
+ var oldCall = call;
52553
+ call = function() {
52554
+ if (coTarget.cT == target.ticker) {
52555
+ oldCall(callParams||coTarget);
52556
+ zim.Ticker.remove(coTarget.cT);
52557
+ coTarget.cT = null;
52558
+ target = null;
52559
+ }
52560
+ }
52561
+ } else {
52562
+ call = function() {
52563
+ if (coTarget.cT == target.ticker) {
52564
+ zim.Ticker.remove(coTarget.cT);
52565
+ coTarget.cT = null;
52566
+ target = null;
52567
+ }
52500
52568
  }
52501
52569
  }
52502
52570
  }
52571
+ } else {
52572
+ if (obj.color) { // just to handle protect
52573
+ delete obj.color;
52574
+ obj.colorRange = 1;
52575
+ }
52503
52576
  }
52504
52577
 
52578
+
52505
52579
  // moved these to before protect (to catch scale convert) - ZIM Cat
52506
52580
  // PREPARE ZIK RANDOM VALUES PASSED IN AS ARRAY OR RAND OBJECT {min, max, integer, negative}
52507
52581
  var savedPicks = {};
@@ -52516,6 +52590,7 @@ RETURNS the target for chaining (or null if no target is provided and run on zim
52516
52590
  delete obj.scale;
52517
52591
  }
52518
52592
 
52593
+
52519
52594
  // PROTECT LOOPS AND REWINDS WITH BUSY
52520
52595
  // if protected or a loop or rewind is currently running for any of these properties
52521
52596
  // then remove the property from obj as it is currently busy
@@ -52523,7 +52598,6 @@ RETURNS the target for chaining (or null if no target is provided and run on zim
52523
52598
  if (!target.zimBusy) break;
52524
52599
  if (target.zimBusy[o]) delete obj[o];
52525
52600
  }
52526
-
52527
52601
  if (zim.isEmpty(obj)) return; // nothing left to animate
52528
52602
  if (target.type != "Sprite") {
52529
52603
  if (target.type != undefined) target.paused = false;
@@ -52537,6 +52611,7 @@ RETURNS the target for chaining (or null if no target is provided and run on zim
52537
52611
  }
52538
52612
  }
52539
52613
  function addZimBusy() {
52614
+ if (originalProtect === false) return;
52540
52615
  if (!target.zimMouseEnabledCheck) {
52541
52616
  target.zimMouseEnabledCheck = true;
52542
52617
  target.zimLastMouseEnabled = target.mouseEnabled;
@@ -52554,6 +52629,7 @@ RETURNS the target for chaining (or null if no target is provided and run on zim
52554
52629
  if (protect || cjsProps.loop || cjsProps.rewind) addZimBusy();
52555
52630
 
52556
52631
 
52632
+
52557
52633
  // IDS and IDSETS
52558
52634
  // this is for ids and idSets on this target
52559
52635
  // a single tween for an id does not get an idSet
@@ -59781,6 +59857,9 @@ METHODS
59781
59857
  add(items) - add an item or an array of items to the wrapper - will call a resize() - returns the wrapper for chaining
59782
59858
  addAt(items, index) - insert an item or an array of items at an index - will call a resize() - returns the wrapper for chaining
59783
59859
  remove(items) - removes an item or items (pass in an array) - will call a resize() - returns the wrapper for chaining
59860
+ setProps(properties) - sets provided properties (as {prop:val, prop:val}) for each item
59861
+ the values accept ZIM VEE - dynamic parameters - see ZIM Pick()
59862
+ returns object for chaining
59784
59863
  resize(width, height) - resize the wrapper passing an optional width and height - returns wrapper for chaining
59785
59864
  most of the properties below resize the wrapper automatically
59786
59865
  hasProp(property as String) - returns true if property exists on object else returns false
@@ -60337,6 +60416,13 @@ alpha, cursor, shadow, name, mouseChildren, mouseEnabled, parent, numChildren, e
60337
60416
  }
60338
60417
  } // end alignObjects
60339
60418
 
60419
+
60420
+ this.setProps = function(props) {
60421
+ zim.setProps(this.items, props);
60422
+ return this;
60423
+ }
60424
+
60425
+
60340
60426
  Object.defineProperty(that, 'spacingH', {
60341
60427
  get: function() {
60342
60428
  return spacingH;
@@ -60724,6 +60810,9 @@ itemUnderPoint(x, y, ignoreSpacing) - gets the item under a global point - (with
60724
60810
  ** will not work properly with squeeze and gets original items - so not items that are moved
60725
60811
  x and y are F.mouseX, F.mouseY for example.
60726
60812
  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)
60813
+ setProps(properties) - sets provided properties (as {prop:val, prop:val}) for each item
60814
+ the values accept ZIM VEE - dynamic parameters - see ZIM Pick()
60815
+ returns object for chaining
60727
60816
  remake(items) - pass in an array of items to tile - see items property for editing current list - returns tile for chaining
60728
60817
  can also change rows and cols and remake()
60729
60818
  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 +61309,11 @@ note: the item is not the event object target - as that is the tile
61220
61309
  } // end resize
61221
61310
 
61222
61311
  resize(width, height);
61312
+
61313
+ this.setProps = function(props) {
61314
+ zim.setProps(this.items, props);
61315
+ return this;
61316
+ }
61223
61317
 
61224
61318
  this.itemUnderPoint = function(x, y, ignoreSpacing) {
61225
61319
  if (zot(ignoreSpacing)) ignoreSpacing = true;
@@ -61520,6 +61614,7 @@ note: the item is not the event object target - as that is the tile
61520
61614
  if (style!==false) zim.styleTransforms(this, DS); // global function - would have put on DisplayObject if had access to it
61521
61615
 
61522
61616
  this.clone = function(exact) {
61617
+ if (unique) exact = true; // added ZIM 016
61523
61618
  if (exact) {
61524
61619
  var exactItems = [];
61525
61620
  if (backgroundColor) var exactBackgroundColors = [];
@@ -61529,7 +61624,7 @@ note: the item is not the event object target - as that is the tile
61529
61624
  if (backgroundColor) exactBackgroundColors.push(backgroundColors[i]);
61530
61625
  if (backing) exactBackings.push(backings[i].clone(true));
61531
61626
  }
61532
- }
61627
+ }
61533
61628
  return that.cloneProps(new zim.Tile(exact&&exactItems?zim.series(exactItems):(obj.clone?obj.clone():obj), that.cols, that.rows, that.spacingH, that.spacingV, exact?false:unique, width, height, that.squeezeH, that.squeezeV, colSize, rowSize, align, valign, that.items.length, that.mirrorH, that.mirrorV, snapToPixel, exact?false:clone, events, exact, scaleToH, scaleToV, scaleToType, exact&&exactBackgroundColors?zim.series(exactBackgroundColors):backgroundColor, backgroundPadding, backgroundPaddingH, backgroundPaddingV, exact&&exactBackings?zim.series(exactBackings):(backing&&backing.clone)?backing.clone():backing, backdropColor, backdropPadding, backdropPaddingH, backdropPaddingV, (mat&&mat.clone)?mat.clone():mat, this.style, this.group));
61534
61629
  };
61535
61630
  };
@@ -82833,23 +82928,23 @@ zim.Frame = function(scaling, width, height, color, outerColor, ready, assets, p
82833
82928
  WW.removeEventListener("mouseup", leftEvent);
82834
82929
 
82835
82930
  if (!allowDefault) document.body.style.overflow = "auto";
82836
- zim.Ticker.dispose(stage);
82837
82931
  recursiveDispose(stage);
82838
- if (that == zim.tickerFrame) zim.tickerFrame = null;
82839
82932
  function recursiveDispose(obj) {
82840
- if (obj && obj.dispose) obj.dispose();
82933
+ if (obj.dispose) obj.dispose();
82841
82934
  else {
82842
- if (obj) obj.removeAllEventListeners();
82843
- if (obj && obj.numChildren) {
82935
+ obj.removeAllEventListeners();
82936
+ if (obj.numChildren) {
82844
82937
  for (var i=obj.numChildren-1; i>=0; i--) {
82845
82938
  recursiveDispose(obj.getChildAt(i));
82846
82939
  }
82847
82940
  }
82848
- if (obj && obj.parent) obj.parent.removeChild(obj);
82941
+ if (obj.parent) obj.parent.removeChild(obj);
82849
82942
  }
82850
82943
  obj = null;
82851
82944
  }
82852
- if (zid(canvasID)) zid(canvasID).parentNode.removeChild(zid(canvasID));
82945
+ if (zid(canvasID)) zid(canvasID).parentNode.removeChild(zid(canvasID));
82946
+ zim.Ticker.dispose(stage);
82947
+ if (that == zim.tickerFrame) zim.tickerFrame = null;
82853
82948
  if (that === WW.zdf) WW.zdf = WW.S = WW.W = WW.H = null;
82854
82949
 
82855
82950
  stage = null;
@@ -87672,7 +87767,8 @@ EXAMPLE
87672
87767
  const lb = new LeaderBoard({
87673
87768
  data:"E-MAILED CODE FROM zimjs.com/leaderboard/",
87674
87769
  corner:0,
87675
- backgroundColor:dark
87770
+ backgroundColor:dark,
87771
+ titleColor:light
87676
87772
  }).center();
87677
87773
 
87678
87774
  // then to record a score at some point later:
@@ -90570,6 +90666,7 @@ export let makeSyllable = zim.makeSyllable;
90570
90666
  export let makePrimitive = zim.makePrimitive;
90571
90667
  export let makeMath = zim.makeMath;
90572
90668
  export let swapProperties = zim.swapProperties;
90669
+ export let setProps = zim.setProps;
90573
90670
  export let mobile = zim.mobile;
90574
90671
  export let vee = zim.vee;
90575
90672
  export let extend = zim.extend;