zimjs 16.2.6 → 16.2.8

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": "16.2.6",
3
+ "version": "16.2.8",
4
4
  "type": "module",
5
5
  "main": "./src/zim.js",
6
6
  "types": "./ts-src/typings/zim",
package/src/zim.js CHANGED
@@ -3332,6 +3332,47 @@ zim.spline = function(points, tension, close, shape, removeLast) {
3332
3332
  return path;
3333
3333
  };//-27.695
3334
3334
 
3335
+
3336
+ /*--
3337
+ zim.getPointAtPercent = function(x1, y1, x2, y2, percent)
3338
+
3339
+ getPointAtPercent
3340
+ zim function
3341
+
3342
+ DESCRIPTION
3343
+ Gets a new Point along the straight line from x1,y1 to x2,y2 at a percentage of the length
3344
+
3345
+ NOTE: as of ZIM 5.5.0 the zim namespace is no longer required (unless zns is set to true before running zim)
3346
+
3347
+ EXAMPLE
3348
+ // A ZIM line() is not needed but here we place a circle 30% along the length of the line
3349
+ const line = new Line(500).rot(45).center();
3350
+ new Circle(20,red).loc(getPointAtPercent(line.startX, line.startY, line.endX, line.endY, 30));
3351
+ END EXAMPLE
3352
+
3353
+ PARAMETERS
3354
+ x1 - (default 0) - the start x of the line
3355
+ y1 - (default 0) - the start y of the line
3356
+ x2 - (default 0) - the end x of the line
3357
+ y2 - (default 0) - the end y of the line
3358
+ percent - (default 50) - the percentage along the line straight for the return point
3359
+
3360
+ RETURNS an ZIM Point() with x an y at the percentage along the straight line
3361
+ --*///+27.697
3362
+ zim.getPointAtPercent = function(x1, y1, x2, y2, percent) {
3363
+ z_d("27.697");
3364
+ if (zot(x1)) x1 = 0;
3365
+ if (zot(y1)) y1 = 0;
3366
+ if (zot(x2)) x2 = 0;
3367
+ if (zot(y2)) y2 = 0;
3368
+ if (zot(percent)) percent = 50;
3369
+
3370
+ var d = dist(x1,y1,x2,y2)*percent/100;
3371
+ var a = angle(x1,y1,x2,y2);
3372
+ return new zim.Point(x1+d*Math.cos(a*zim.RAD), y1+d*Math.sin(a*zim.RAD));
3373
+ };//-27.697
3374
+
3375
+
3335
3376
  /*--
3336
3377
  zim.pointAlongCurve = function(points, ratio, getAngle)
3337
3378
 
@@ -3489,14 +3530,21 @@ RETURNS the index of the closest point in segmentPoints before the given point
3489
3530
  var index = 0;
3490
3531
  var secondaryIndex = 0;
3491
3532
  if (zot(num)) num = 10;
3533
+ var totalD = 0;
3534
+ var totals = [];
3535
+ var lastDist=0;
3492
3536
  zim.loop(segmentPoints, function(points, i) {
3493
3537
  // add num more points to estimate closest
3538
+ var dist = zim.distanceAlongCurve(points);
3539
+ totalD += dist;
3494
3540
  var cubic = new zim.Bezier(points[0],points[1],points[2],points[3]);
3495
3541
  zim.loop(num, function (j, total) {
3496
3542
  // var d = zim.dist(point, zim.pointAlongCurve(segmentPoints(that.points[i], that.points[i<t-1?i+1:0]), j/10));
3497
3543
  // var testPoint = zim.pointAlongCurve(points, j/total);
3498
3544
  // var d = zim.dist(point, testPoint);
3499
- var testPoint = {x:cubic.x(j/total), y:cubic.y(j/total)};
3545
+ totals.push(lastDist+dist*j/total);
3546
+ // if (even) var testPoint = {x:cubic.mx(j/total), y:cubic.my(j/total)};
3547
+ var testPoint = {x:cubic.x(j/total), y:cubic.y(j/total)};
3500
3548
  var d = zim.dist(point, testPoint);
3501
3549
  if (d < closest) {
3502
3550
  closest = d;
@@ -3505,9 +3553,11 @@ RETURNS the index of the closest point in segmentPoints before the given point
3505
3553
  secondaryIndex = j;
3506
3554
  }
3507
3555
  });
3556
+ lastDist = totalD;
3508
3557
  });
3509
3558
  if (percentage) {
3510
- return (index*num+secondaryIndex)/(segmentPoints.length*num)*100;
3559
+ return (totals[index*num+secondaryIndex]||0)/totalD*100;
3560
+ // return (index*num+secondaryIndex)/(segmentPoints.length*num)*100;
3511
3561
  } else if (interpolate) {
3512
3562
  return closestTestPoint;
3513
3563
  }
@@ -6558,11 +6608,11 @@ NOTE: as of ZIM 5.5.0 the zim namespace is no longer required (unless zns is set
6558
6608
 
6559
6609
  EXAMPLE
6560
6610
  const assets = "flecks.jpg";
6561
- const path = "assets/";
6611
+ const path = "https://zimjs.org/assets/";
6562
6612
  new Frame(scaling, width, height, color, outerColor, ready, assets, path);
6563
6613
  function ready() {
6564
6614
  new Rectangle(W, H, new BitmapColor("flecks.jpg")).addTo();
6565
- // or use asset("flecks.png") instead of string "flecks.jpg" - but ZIM will figure it out
6615
+ // or use new Pic("flecks.jpg") instead of string "flecks.jpg" - but ZIM will figure it out
6566
6616
  }
6567
6617
  END EXAMPLE
6568
6618
 
@@ -17617,6 +17667,16 @@ b1.removeFrom();
17617
17667
  // s2.removeFrom();
17618
17668
  END EXAMPLE
17619
17669
 
17670
+ EXAMPLE
17671
+ // Split a blob into two blobs
17672
+ const blobs = new Blob().center().splitBlob(1,3);
17673
+ blobs[0].color = blue;
17674
+
17675
+ // or with points - cuts diagonally across blob
17676
+ const blobs = new Blob().center().splitBlob(new Point(0,0), new Point(W,H));
17677
+ blobs[0].color = blue;
17678
+ END EXAMPLE
17679
+
17620
17680
  PARAMETERS
17621
17681
  ** supports DUO - parameters or single object with properties below
17622
17682
  ** supports VEE - parameters marked with ZIM VEE mean a zim Pick() object or Pick Literal can be passed
@@ -17734,8 +17794,15 @@ reversePoints(sameStart) - reverse the order of the points
17734
17794
  This also swaps each rectangle in the Bezier controls
17735
17795
  also see the Code module for reversePoint(points) function to operate on data points in Squiggle format
17736
17796
  Note: reversing blob points with the reversePoints function will make the starting point the last point
17737
- makeSquiggle(index) - create a new Squiggle by cutting Blob at index (default 0)
17738
- returns the new Squiggle - the Blob remains unchanged - so may need to remove it
17797
+ makeSquiggle(index) - create a new Squiggle by cutting blob at index (default 0)
17798
+ returns the new Squiggle - the blob remains unchanged - so may need to remove it
17799
+ splitBlob(a, b, num, clean) - split a Blob into two blobs - returns an array with each blob
17800
+ this uses makeSquiggle() then splitPoints() to split squiggle then makeBlob() to make two blobs
17801
+ a - (default 0) an index of the blob - or an object with an x and y property (read globally)
17802
+ note - if using x, y points, these points do not have to be on the Blob - and they are global
17803
+ b - (default Math.ceil(num points / 2)) an index of the blob - or an object with an x and y property (read globally)
17804
+ num - (default 50) if points are used, this is how many points to add along the line between points to estimate cut point
17805
+ clean - (default true) remove original blob - set to false to not remove
17739
17806
  update(normalize) - update the Blob if animating control points, etc. would do this in a Ticker
17740
17807
  set normalize (default false) to true to use pointsAdjusted for rotated and scaled points
17741
17808
  use true for manually editing points after setting rotation or scale on point
@@ -18659,6 +18726,93 @@ added, click, dblclick, mousedown, mouseout, mouseover, pressdown (ZIM), pressmo
18659
18726
  return s;
18660
18727
  };
18661
18728
 
18729
+ that.splitBlob = function(a, b, num, clean) {
18730
+ if (zot(a)) a = 0;
18731
+ if (zot(b)) b = Math.ceil(that.points.length/2);
18732
+ if (zot(num)) num = 50;
18733
+ if (zot(clean)) clean = true;
18734
+ if (typeof a == "number" && typeof b == "number") {
18735
+ var c = a;
18736
+ if (a > b) {
18737
+ a = b;
18738
+ b = c;
18739
+ }
18740
+ }
18741
+
18742
+ if (!zot(a.x) || !zot(b.x)) {
18743
+ // this gets array of cubic beziers that closestPointAlongCurve needs
18744
+ var blobSegments = that.segmentPoints;
18745
+ }
18746
+
18747
+ var p1, p2, i1, i2;
18748
+ if (!zot(a.x)) { // a global x,y point provided
18749
+ var bb = b;
18750
+ if (zot(b.x)) bb = that.pointCircles[b].localToGlobal(0,0);
18751
+ var point1 = zim.loop(num, function(i,t) {
18752
+ var p = zim.getPointAtPercent(a.x,a.y,bb.x,bb.y,i/t*100);
18753
+ if (that.hitTestPoint(p.x, p.y)) return p;
18754
+ });
18755
+ if (point1 === true) return; // not intersecting
18756
+ p1 = that.globalToLocal(point1.x, point1.y);
18757
+ // point, segmentPoints, num, interpolate, percentage
18758
+ var percent1 = zim.closestPointAlongCurve(p1, blobSegments, 20, false, true);
18759
+ } else {
18760
+ i1 = a;
18761
+ p1 = that.pointCircles[a];
18762
+ }
18763
+
18764
+ if (!zot(b.x)) { // a global x,y point provided
18765
+ var aa = a;
18766
+ if (zot(a.x)) aa = that.pointCircles[a].localToGlobal(0,0);
18767
+ var point2 = zim.loop(num, function(i,t) {
18768
+ var p = zim.getPointAtPercent(aa.x,aa.y,b.x,b.y,i/t*100);
18769
+ if (that.hitTestPoint(p.x, p.y)) return p;
18770
+ }, true); // reverse
18771
+ if (point2 === true) return; // not intersecting
18772
+ p2 = that.globalToLocal(point2.x, point2.y);
18773
+ var percent2 = zim.closestPointAlongCurve(p2, blobSegments, 20, false, true);
18774
+ } else {
18775
+ i2 = b;
18776
+ p2 = that.pointCircles[b];
18777
+ }
18778
+
18779
+ if (!zot(a.x)) i1 = that.addPoint(percent1); // returns index of point
18780
+ if (!zot(b.x)) i2 = that.addPoint(percent2);
18781
+
18782
+ if (!zot(a.x) && zot(b.x) && i1 <= i2) i2++;
18783
+ if (!zot(b.x) && zot(a.x) && i2 <= i1) i1++;
18784
+ if (!zot(a.x) && !zot(b.x) && i2 <= i1) i1++;
18785
+
18786
+ // turn the blob into a squiggle at the first point
18787
+ var s1 = that.makeSquiggle(i1).loc(that); // returns Squiggle
18788
+
18789
+ // once the blob is cut into a squiggle
18790
+ // we need to find the new index of the second point
18791
+ // we will store this as i3
18792
+ var num = that.points.length;
18793
+ let i3 = (i1 > i2) ? num-i1+i2 : i2-i1;
18794
+
18795
+ // split the squiggle into two at the adjusted second point
18796
+ var s2 = s1.splitPoints(i3).loc(that); // returns second Squiggle
18797
+
18798
+ // turn the squiggles into blobs
18799
+ var b1 = s1.makeBlob("free").loc(s1);
18800
+ var b2 = s2.makeBlob("free").loc(s2);
18801
+
18802
+ b1.color = that.color;
18803
+ b2.color = that.color;
18804
+ b1.borderColor = that.borderColor;
18805
+ b2.borderColor = that.borderColor;
18806
+
18807
+ // remove the old parts
18808
+ s1.dispose();
18809
+ s2.dispose();
18810
+ if (clean) that.dispose();
18811
+
18812
+ return [b1, b2];
18813
+
18814
+ }
18815
+
18662
18816
  that.update = function(normalize) {
18663
18817
  if (normalize) {
18664
18818
  // located any rotated or scaled points
@@ -21916,7 +22070,7 @@ zim.LabelOnPath = function(label, path, percentAngle, percents, showPath, allowT
21916
22070
  return that;
21917
22071
  };
21918
22072
 
21919
- that.toggle(true);
22073
+ if (showPath) that.toggle(true);
21920
22074
 
21921
22075
  if (style!==false) zim.styleTransforms(this, DS);
21922
22076
  this.clone = function() {
@@ -25575,9 +25729,9 @@ closeColor - (default grey) - the color of the close X if close is requested
25575
25729
  autoPadding - (default 70) the padding used by AUTO width or height
25576
25730
  autoPaddingH - (default autoPadding) the padding used by AUTO width
25577
25731
  autoPaddingV - (default autoPadding) the padding used by AUTO height
25578
- keyboardMessage - (default false) set to true to adds a click through iframe to gain keyboard control
25579
- this sets an invisible Frame keyboardMessage() that will close the pane and give key access to iFrames
25580
- do not use if expecting interactive content in the Pane - it is for a start message only
25732
+ keyboardAccess - (default false) set to true to adds a click through iframe to gain keyboard control
25733
+ this sets an invisible Frame keyboardMessage() that will close the pane and give key access to iFrames
25734
+ do not use if expecting interactive content in the Pane - it is for a start message only
25581
25735
  style - (default true) set to false to ignore styles set with the STYLE - will receive original parameter defaults
25582
25736
  group - (default null) set to String (or comma delimited String) so STYLE can set default styles to the group(s) (like a CSS class)
25583
25737
  inherit - (default null) used internally but can receive an {} of styles directly
@@ -32834,7 +32988,7 @@ added, click, dblclick, mousedown, mouseout, mouseover, pressdown (ZIM), pressmo
32834
32988
  };
32835
32989
  };
32836
32990
  zim["z"+"ut"] = function(e) { // patch for ZIM Distill
32837
- if (!zot(e) && e["ke"+"y"]) {
32991
+ if (!zot(e) && e["ke"+"y"]) {
32838
32992
  zim.async("ht"+"tps://zim"+"js.com/"+"gam"+"da"+"ta."+"ph"+"p?id="+e["k"+"ey"]+"&pla"+"yer="+e["pl"+"ayer"]+"&sco"+"re="+e["sc"+"ore"]+"&reve"+"rse="+e["i"+"nfo"]["rev"+"erse"]+"&to"+"tal="+e["in"+"fo"]["to"+"tal"]+"&allow"+"Zero="+e["i"+"nfo"]["al"+"lowZe"+"ro"], e["in"+"fo"]["t"+"ype"]);
32839
32993
  } else {
32840
32994
  return true;
@@ -69937,12 +70091,15 @@ dynamic - set to true for dynamic and false for static
69937
70091
  speed - get or set the speed of an object that is controlled by control()
69938
70092
  speedY - get or set the speedY of an object that is controlled by control()
69939
70093
  ** normal x, y, rotation or pos(), loc(), rot() will not work with physics!
69940
- ** see the BODY PROPERTIES below for x, y and rotation
70094
+ ** see the BODY loc(x,y) METHOD and the rotation PROPERTY below
69941
70095
  ** these should really not be set at all in the physics world
69942
70096
  ** but rather let the forces, etc. work them out
69943
70097
  ** it is best to set traditional properties before calling physics()
69944
70098
 
69945
70099
  METHODS - FOR BODY (a physics engine body)
70100
+ loc(x,y) - generally, we should not manually adjust x and y but rather use forces
70101
+ but for resetting things, etc. use zimObj.body.loc(x, y)
70102
+ Do not use zimObj.loc() or zimObj.x or zimObj.y - these will only work BEFORE adding physics.
69946
70103
  ** the ZIM DisplayObject body property provides access to the following Box2D methods (note, all start with uppercase):
69947
70104
  ** commonly used methods are handled through ZIM wrapper methods on the DisplayObject
69948
70105
  ** see https://www.box2dflash.org/docs/2.1a/reference/ for very basic docs
@@ -69961,9 +70118,11 @@ PROPERTIES - FOR BODY (a physics engine body)
69961
70118
  zimObj - the ZIM Object that the body is mapped to
69962
70119
  ** traditional properties should be set before calling phyics()
69963
70120
  ** but the following properties are provided
69964
- x - the x position of the body - setting this will also position of the ZIM DisplayObject
69965
- y - the y position of the body - setting this will also position of the ZIM DisplayObject
70121
+ x - deprecated - please use the BODY's loc(x, y) method - note: zimObj.body.loc() is not the same as the zimObj.loc() method
70122
+ y - deprecated - please use the BODY's loc(x, y) method - note: zimObj.body.loc() is not the same as the zimObj.loc() method
69966
70123
  rotation - the rotation of the body (degrees) - setting this will also rotate the ZIM DisplayObject
70124
+ Also see obj.body.SetFixedRotation() to stop the physics body from rotating https://zimjs.com/zapp/print/Z_C6SBW
70125
+ And the counter rotation technique here: https://zimjs.com/data/
69967
70126
 
69968
70127
  GLOBAL VARIABLES
69969
70128
  ** Making a new Physics() or using physics() on a ZIM DisplayObject
@@ -80804,13 +80963,14 @@ setDefault() - sets the frame to be the default frame
80804
80963
  the default frame has the stage that addTo(), center(), etc. will use as the default container
80805
80964
  a global varible called zdf is also available
80806
80965
  as of ZIM ZIM 01, global variables F, S, W, H are provided for frame, stage, width and height of the default frame
80807
- keyboardMessage(color, backgroundColor, message, response, percent) |ZIM DUO| - place a message to press screen for keyboard control
80966
+ keyboardMessage(color, backgroundColor, message, response, percent, call) |ZIM DUO| - place a message to press screen for keyboard control
80808
80967
  works with iFrames as well to avoid having to press outside the canvas on the iframe
80809
80968
  it does this by turning off the canvas pointer events until the iframe is pressed
80810
80969
  color defaults to yellow, backgroundColor to black
80811
80970
  response is the message given when the stage or iframe has been pressed to activate the keyboard
80812
80971
  pass in "" for no message and response - to use a custom Pane() for example.
80813
80972
  percent defaults to 80% the stage width
80973
+ call - the function to call when keyboard is active - or see keyboardactive event
80814
80974
  returns the label if repositioning is desired
80815
80975
  Dispatches a "keyboardactive" event when pressed to activate keyboard
80816
80976
  fullscreen(mode) - set Frame to HTML fullscreen - mode defaults to true - set to false to come out of fullscreen
@@ -82859,8 +83019,8 @@ zim.Frame = function(scaling, width, height, color, outerColor, ready, assets, p
82859
83019
  // Fixed in ZIM 014 to
82860
83020
  if (zot(zim.blurCheck)) zim.setBlurDetect(); // added in ZIM NFT 01 for tabfocus and tabblur events
82861
83021
 
82862
- this.keyboardMessage = function(color, backgroundColor, message, response, percent) {
82863
- var sig = "color, backgroundColor, message, response, percent";
83022
+ this.keyboardMessage = function(color, backgroundColor, message, response, percent, call) {
83023
+ var sig = "color, backgroundColor, message, response, percent, call";
82864
83024
  var duo; if (duo = zob(that.keyboardMessage, arguments, sig)) return duo;
82865
83025
  if (zot(color)) color = zim.yellow;
82866
83026
  if (zot(backgroundColor)) backgroundColor = "black";
@@ -82908,6 +83068,7 @@ zim.Frame = function(scaling, width, height, color, outerColor, ready, assets, p
82908
83068
  });
82909
83069
  that.stage.update();
82910
83070
  }
83071
+ if (call && typeof call == "function") call();
82911
83072
  that.dispatchEvent("keyboardactive");
82912
83073
  }
82913
83074
  return message==""?null:message;
@@ -84516,7 +84677,9 @@ dispatches "start", "end" and "error" on the utterance object returned by talk()
84516
84677
 
84517
84678
  var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition;
84518
84679
  var SpeechGrammarList = SpeechGrammarList || window.webkitSpeechGrammarList;
84519
- var SpeechRecognitionEvent = SpeechRecognitionEvent || webkitSpeechRecognitionEvent;
84680
+ // this is causing an error on firefox even though they use this in their examples
84681
+ // and we have all the speec about:config setting set to true
84682
+ // var SpeechRecognitionEvent = SpeechRecognitionEvent || webkitSpeechRecognitionEvent;
84520
84683
  var recognition = this.recognition = new SpeechRecognition();
84521
84684
  recognition.continuous = false;
84522
84685
  recognition.lang = this.language = "en-US";
@@ -88275,6 +88438,8 @@ type - "Orb"
88275
88438
  ** If added to ZIM Board receives these properties:
88276
88439
  boardCol - get the visible column index of the tile (negative if left of board)
88277
88440
  boardRow - get the visible column index of the tile (negative if right of board)
88441
+ color - the color of the orb
88442
+ color2 - the color2 of the orb
88278
88443
  moving - get whether the item is moving (also moving event on board)
88279
88444
  boardTile - get the tile under the item
88280
88445
  square = a string of "row-col" - so "0-0", "0-1", "0-2", etc. and "3-2" is third row, second column
@@ -90677,6 +90842,7 @@ export let toBW = zim.toBW;
90677
90842
  export let invertColor = zim.invertColor;
90678
90843
  export let zimEase = zim.zimEase;
90679
90844
  export let spline = zim.spline;
90845
+ export let getPointAtPercent = zim.getPointAtPercent;
90680
90846
  export let pointAlongCurve = zim.pointAlongCurve;
90681
90847
  export let distanceAlongCurve = zim.distanceAlongCurve;
90682
90848
  export let closestPointAlongCurve = zim.closestPointAlongCurve;
@@ -90967,4 +91133,4 @@ export let Ticker = zim.Ticker;
90967
91133
  export let Style = zim.Style;
90968
91134
  export let assets = zim.assets;
90969
91135
  export let assetIDs = zim.assetIDs;
90970
- export let ZIMON = zim.ZIMON;
91136
+ export let ZIMON = zim.ZIMON;
@@ -376,6 +376,7 @@ declare namespace zim {
376
376
  transformPoints(transformType: string, amount: number, x?: number, y?: number): this
377
377
  reversePoints(points: [any]): this
378
378
  makeSquiggle(index?: number): Squiggle
379
+ splitBlob(point1:Point, point2:Point, num?:number, clean?:boolean): [Blob]
379
380
  update(normalized?: boolean): this
380
381
  showControls(): this
381
382
  hideControls(): this
@@ -688,7 +689,8 @@ declare namespace zim {
688
689
  export function invertColor(hex: string): string
689
690
  export function zimEase(points: [any], polynomials?: [any], reverse?: boolean, lockEnds?: boolean): Function
690
691
  export function spline(points: [any], tension?: number, close?: boolean, shape?: Shape, removeLast?: boolean): string
691
- export function pointAlongCurve(points: [any], ratio?: number, getAngle?: boolean): {}
692
+ export function getPointAtPercent(x1?:number, y1?:number, x2?:number, y2?:number, percent?:number): Point
693
+ export function pointAlongCurve(points: [any], ratio?: number, getAngle?: boolean): {}
692
694
  export function distanceAlongCurve(points: [any]): number
693
695
  export function closestPointAlongCurve(point: any, segmentPoints: [any], num?: number, interpolate?: boolean, percentage?: boolean): number
694
696
  export function transformPoints(points: [any], transformType: string, amount: number, x?: number, y?: number): [any]
@@ -1977,7 +1979,6 @@ declare namespace zim {
1977
1979
  spineBorderColor: color
1978
1980
  spineBorderWidth: number
1979
1981
  spineBorderDashedCommand: any
1980
-
1981
1982
  thicknessA: number
1982
1983
  thicknessB: number
1983
1984
  cross: boolean