zimjs 16.2.7 → 16.2.9
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 +1 -1
- package/src/zim.js +172 -14
- package/ts-src/typings/zim/index.d.ts +3 -2
package/package.json
CHANGED
package/src/zim.js
CHANGED
|
@@ -32,7 +32,7 @@ Node module - also see ES6 modules at https://zimjs.com/cdn
|
|
|
32
32
|
// Thanks to Karel Rosseel for proof-reading the site
|
|
33
33
|
// Thanks Ami Hanya and team for such prolific work with ZIM and all the suggestions
|
|
34
34
|
// Of course, thanks to all the ZIM users - it is always nice to hear from you
|
|
35
|
-
// at https://zimjs.com
|
|
35
|
+
// at https://forum.zimjs.com and https://zimjs.com/discord
|
|
36
36
|
// There are several dozen thanks through out the code as well - cheers!
|
|
37
37
|
|
|
38
38
|
// This is used for the build but in a browser would be
|
|
@@ -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
|
|
|
@@ -17626,6 +17667,16 @@ b1.removeFrom();
|
|
|
17626
17667
|
// s2.removeFrom();
|
|
17627
17668
|
END EXAMPLE
|
|
17628
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
|
+
|
|
17629
17680
|
PARAMETERS
|
|
17630
17681
|
** supports DUO - parameters or single object with properties below
|
|
17631
17682
|
** supports VEE - parameters marked with ZIM VEE mean a zim Pick() object or Pick Literal can be passed
|
|
@@ -17743,8 +17794,15 @@ reversePoints(sameStart) - reverse the order of the points
|
|
|
17743
17794
|
This also swaps each rectangle in the Bezier controls
|
|
17744
17795
|
also see the Code module for reversePoint(points) function to operate on data points in Squiggle format
|
|
17745
17796
|
Note: reversing blob points with the reversePoints function will make the starting point the last point
|
|
17746
|
-
makeSquiggle(index) - create a new Squiggle by cutting
|
|
17747
|
-
returns the new Squiggle - the
|
|
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
|
|
17748
17806
|
update(normalize) - update the Blob if animating control points, etc. would do this in a Ticker
|
|
17749
17807
|
set normalize (default false) to true to use pointsAdjusted for rotated and scaled points
|
|
17750
17808
|
use true for manually editing points after setting rotation or scale on point
|
|
@@ -18668,6 +18726,93 @@ added, click, dblclick, mousedown, mouseout, mouseover, pressdown (ZIM), pressmo
|
|
|
18668
18726
|
return s;
|
|
18669
18727
|
};
|
|
18670
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
|
+
|
|
18671
18816
|
that.update = function(normalize) {
|
|
18672
18817
|
if (normalize) {
|
|
18673
18818
|
// located any rotated or scaled points
|
|
@@ -25584,9 +25729,9 @@ closeColor - (default grey) - the color of the close X if close is requested
|
|
|
25584
25729
|
autoPadding - (default 70) the padding used by AUTO width or height
|
|
25585
25730
|
autoPaddingH - (default autoPadding) the padding used by AUTO width
|
|
25586
25731
|
autoPaddingV - (default autoPadding) the padding used by AUTO height
|
|
25587
|
-
|
|
25588
|
-
|
|
25589
|
-
|
|
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
|
|
25590
25735
|
style - (default true) set to false to ignore styles set with the STYLE - will receive original parameter defaults
|
|
25591
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)
|
|
25592
25737
|
inherit - (default null) used internally but can receive an {} of styles directly
|
|
@@ -32843,7 +32988,7 @@ added, click, dblclick, mousedown, mouseout, mouseover, pressdown (ZIM), pressmo
|
|
|
32843
32988
|
};
|
|
32844
32989
|
};
|
|
32845
32990
|
zim["z"+"ut"] = function(e) { // patch for ZIM Distill
|
|
32846
|
-
if (!zot(e) && e["ke"+"y"]) {
|
|
32991
|
+
if (!zot(e) && e["ke"+"y"]) {
|
|
32847
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"]);
|
|
32848
32993
|
} else {
|
|
32849
32994
|
return true;
|
|
@@ -36032,6 +36177,11 @@ NOTE: as of ZIM 5.5.0 the zim namespace is no longer required (unless zns is set
|
|
|
36032
36177
|
|
|
36033
36178
|
EXAMPLE
|
|
36034
36179
|
const label = new Label("").pos(0,100,CENTER);
|
|
36180
|
+
|
|
36181
|
+
// The NumPad is built in to the Keyboard
|
|
36182
|
+
// To set the parameters, such as titleBar, use STYLE before making the Keyboard
|
|
36183
|
+
STYLE = {titleBar:"CALCULATE", align:CENTER};
|
|
36184
|
+
|
|
36035
36185
|
const keyboard = new Keyboard({
|
|
36036
36186
|
labels:label,
|
|
36037
36187
|
numPadScale:.75,
|
|
@@ -36048,7 +36198,7 @@ PARAMETERS
|
|
|
36048
36198
|
** supports OCT - parameter defaults can be set with STYLE control (like CSS)
|
|
36049
36199
|
advanced - (default false) set to true to add one more row of round brackets, exponential and percent or modulus
|
|
36050
36200
|
or set to "simple" to show only numbers, backspace and return
|
|
36051
|
-
titleBar - |ZIM VEE| (default "
|
|
36201
|
+
titleBar - |ZIM VEE| (default "NUMPAD") a String or ZIM Label title that will be presented on a titleBar across the top
|
|
36052
36202
|
titleBarColor - |ZIM VEE| (default black) the text color of the titleBar if a titleBar is requested
|
|
36053
36203
|
titleBarBackgroundColor - |ZIM VEE| (default "rgba(0,0,0,.2)") the background color of the titleBar if a titleBar is requested
|
|
36054
36204
|
titleBarHeight - (default fit label) the height of the titleBar if a titleBar is requested
|
|
@@ -36146,7 +36296,6 @@ added, click, dblclick, mousedown, mouseout, mouseover, pressdown (ZIM), pressmo
|
|
|
36146
36296
|
this.type = "NumPad";
|
|
36147
36297
|
|
|
36148
36298
|
var that = this;
|
|
36149
|
-
|
|
36150
36299
|
|
|
36151
36300
|
function ms(letter, color) {
|
|
36152
36301
|
if (zot(color)) color = mist;
|
|
@@ -68636,7 +68785,11 @@ dispatches a "moving" event if target is moving and "startmoving" and "stopmovin
|
|
|
68636
68785
|
if (container && container.backing) this.mousedownIncludes.push(container.backing);
|
|
68637
68786
|
// this.mousedownExcludes = mousedownExcludes;
|
|
68638
68787
|
if (zot(dampKeyup)) dampKeyup = .3;
|
|
68639
|
-
|
|
68788
|
+
|
|
68789
|
+
if (boundary && boundary.type!="Blob") {
|
|
68790
|
+
target.x = zim.constrain(target.x, boundary.x, boundary.x+boundary.width);
|
|
68791
|
+
target.y = zim.constrain(target.y, boundary.y, boundary.y+boundary.height);
|
|
68792
|
+
}
|
|
68640
68793
|
|
|
68641
68794
|
that.dampKeyup = dampKeyup;
|
|
68642
68795
|
this.dirX = 0;
|
|
@@ -80818,13 +80971,14 @@ setDefault() - sets the frame to be the default frame
|
|
|
80818
80971
|
the default frame has the stage that addTo(), center(), etc. will use as the default container
|
|
80819
80972
|
a global varible called zdf is also available
|
|
80820
80973
|
as of ZIM ZIM 01, global variables F, S, W, H are provided for frame, stage, width and height of the default frame
|
|
80821
|
-
keyboardMessage(color, backgroundColor, message, response, percent) |ZIM DUO| - place a message to press screen for keyboard control
|
|
80974
|
+
keyboardMessage(color, backgroundColor, message, response, percent, call) |ZIM DUO| - place a message to press screen for keyboard control
|
|
80822
80975
|
works with iFrames as well to avoid having to press outside the canvas on the iframe
|
|
80823
80976
|
it does this by turning off the canvas pointer events until the iframe is pressed
|
|
80824
80977
|
color defaults to yellow, backgroundColor to black
|
|
80825
80978
|
response is the message given when the stage or iframe has been pressed to activate the keyboard
|
|
80826
80979
|
pass in "" for no message and response - to use a custom Pane() for example.
|
|
80827
80980
|
percent defaults to 80% the stage width
|
|
80981
|
+
call - the function to call when keyboard is active - or see keyboardactive event
|
|
80828
80982
|
returns the label if repositioning is desired
|
|
80829
80983
|
Dispatches a "keyboardactive" event when pressed to activate keyboard
|
|
80830
80984
|
fullscreen(mode) - set Frame to HTML fullscreen - mode defaults to true - set to false to come out of fullscreen
|
|
@@ -82873,8 +83027,8 @@ zim.Frame = function(scaling, width, height, color, outerColor, ready, assets, p
|
|
|
82873
83027
|
// Fixed in ZIM 014 to
|
|
82874
83028
|
if (zot(zim.blurCheck)) zim.setBlurDetect(); // added in ZIM NFT 01 for tabfocus and tabblur events
|
|
82875
83029
|
|
|
82876
|
-
this.keyboardMessage = function(color, backgroundColor, message, response, percent) {
|
|
82877
|
-
var sig = "color, backgroundColor, message, response, percent";
|
|
83030
|
+
this.keyboardMessage = function(color, backgroundColor, message, response, percent, call) {
|
|
83031
|
+
var sig = "color, backgroundColor, message, response, percent, call";
|
|
82878
83032
|
var duo; if (duo = zob(that.keyboardMessage, arguments, sig)) return duo;
|
|
82879
83033
|
if (zot(color)) color = zim.yellow;
|
|
82880
83034
|
if (zot(backgroundColor)) backgroundColor = "black";
|
|
@@ -82922,6 +83076,7 @@ zim.Frame = function(scaling, width, height, color, outerColor, ready, assets, p
|
|
|
82922
83076
|
});
|
|
82923
83077
|
that.stage.update();
|
|
82924
83078
|
}
|
|
83079
|
+
if (call && typeof call == "function") call();
|
|
82925
83080
|
that.dispatchEvent("keyboardactive");
|
|
82926
83081
|
}
|
|
82927
83082
|
return message==""?null:message;
|
|
@@ -88291,6 +88446,8 @@ type - "Orb"
|
|
|
88291
88446
|
** If added to ZIM Board receives these properties:
|
|
88292
88447
|
boardCol - get the visible column index of the tile (negative if left of board)
|
|
88293
88448
|
boardRow - get the visible column index of the tile (negative if right of board)
|
|
88449
|
+
color - the color of the orb
|
|
88450
|
+
color2 - the color2 of the orb
|
|
88294
88451
|
moving - get whether the item is moving (also moving event on board)
|
|
88295
88452
|
boardTile - get the tile under the item
|
|
88296
88453
|
square = a string of "row-col" - so "0-0", "0-1", "0-2", etc. and "3-2" is third row, second column
|
|
@@ -90693,6 +90850,7 @@ export let toBW = zim.toBW;
|
|
|
90693
90850
|
export let invertColor = zim.invertColor;
|
|
90694
90851
|
export let zimEase = zim.zimEase;
|
|
90695
90852
|
export let spline = zim.spline;
|
|
90853
|
+
export let getPointAtPercent = zim.getPointAtPercent;
|
|
90696
90854
|
export let pointAlongCurve = zim.pointAlongCurve;
|
|
90697
90855
|
export let distanceAlongCurve = zim.distanceAlongCurve;
|
|
90698
90856
|
export let closestPointAlongCurve = zim.closestPointAlongCurve;
|
|
@@ -90983,4 +91141,4 @@ export let Ticker = zim.Ticker;
|
|
|
90983
91141
|
export let Style = zim.Style;
|
|
90984
91142
|
export let assets = zim.assets;
|
|
90985
91143
|
export let assetIDs = zim.assetIDs;
|
|
90986
|
-
export let ZIMON = zim.ZIMON;
|
|
91144
|
+
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
|
|
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
|