zimjs 20.0.4 → 20.0.5

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 +34 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zimjs",
3
- "version": "20.0.4",
3
+ "version": "20.0.5",
4
4
  "type": "module",
5
5
  "main": "./src/zim.js",
6
6
  "types": "./ts-src/typings/zim",
package/src/zim.js CHANGED
@@ -57837,7 +57837,7 @@ EXAMPLE
57837
57837
  // Basic rolling ball constrained to stage bounds
57838
57838
  const ball = new Circle(30, red)
57839
57839
  .center()
57840
- .tilt(true);
57840
+ .tilt(S);
57841
57841
  END EXAMPLE
57842
57842
 
57843
57843
  EXAMPLE
@@ -58052,11 +58052,42 @@ RETURNS obj for chaining
58052
58052
  z_d("34.77");
58053
58053
  if (zot(obj) || !obj.on) return;
58054
58054
  var f = obj.frame || (typeof zdf != "undefined" ? zdf : WW.zdf);
58055
+ var s = obj.stage || (f ? f.stage : null);
58056
+
58057
+ // Helper to calculate bounded limits keeping obj inside container bounds
58058
+ function getContainedBoundary(bx, by, bw, bh) {
58059
+ var b = obj.getBounds ? obj.getBounds() : null;
58060
+ if (b) {
58061
+ return new zim.Boundary(
58062
+ bx - b.x * obj.scaleX,
58063
+ by - b.y * obj.scaleY,
58064
+ Math.max(0, bw - b.width * obj.scaleX),
58065
+ Math.max(0, bh - b.height * obj.scaleY)
58066
+ );
58067
+ }
58068
+ return new zim.Boundary(bx, by, bw, bh);
58069
+ }
58055
58070
 
58056
58071
  if (zot(boundary) || boundary === false || boundary === null) {
58057
58072
  obj._tiltBoundary = null;
58058
- } else if (boundary === true && f) {
58059
- obj._tiltBoundary = new zim.Boundary(0, 0, f.width, f.height);
58073
+ } else if (boundary === true) {
58074
+ // True -> Stage dimensions
58075
+ var sw = f ? f.width : (s ? s.width : 0);
58076
+ var sh = f ? f.height : (s ? s.height : 0);
58077
+ obj._tiltBoundary = getContainedBoundary(0, 0, sw, sh);
58078
+ } else if (boundary && (boundary.type == "Stage" || boundary == s || (s && boundary == s.canvas))) {
58079
+ // Stage passed as boundary
58080
+ var sw = boundary.width || (f ? f.width : 0);
58081
+ var sh = boundary.height || (f ? f.height : 0);
58082
+ obj._tiltBoundary = getContainedBoundary(0, 0, sw, sh);
58083
+ } else if (boundary && boundary.type != "Boundary" && !Array.isArray(boundary) && (boundary.getBounds || boundary.width != null)) {
58084
+ // DisplayObject (Container, Rectangle, etc.) passed as boundary
58085
+ var b = boundary.getBounds ? boundary.getBounds() : null;
58086
+ var bw = boundary.width != null ? boundary.width : (b ? b.width : 0);
58087
+ var bh = boundary.height != null ? boundary.height : (b ? b.height : 0);
58088
+ var bx = boundary.x || 0;
58089
+ var by = boundary.y || 0;
58090
+ obj._tiltBoundary = getContainedBoundary(bx, by, bw, bh);
58060
58091
  } else if (Array.isArray(boundary)) {
58061
58092
  obj._tiltBoundary = new zim.Boundary(boundary[0], boundary[1], boundary[2], boundary[3]);
58062
58093
  } else if (typeof boundary === "number" && !zot(y)) {