@leafer/core 1.9.7 → 1.9.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/lib/core.cjs CHANGED
@@ -249,18 +249,34 @@ class LeafData {
249
249
  }
250
250
  }
251
251
 
252
- const {round: round$3, pow: pow$1, PI: PI$1} = Math;
253
-
254
- const MathHelper = {
255
- within(value, min, max) {
256
- if (isObject(min)) max = min.max, min = min.min;
257
- if (!isUndefined(min) && value < min) value = min;
258
- if (!isUndefined(max) && value > max) value = max;
259
- return value;
252
+ let tempA, tempB, tempTo;
253
+
254
+ const {max: max$1} = Math, tempFour = [ 0, 0, 0, 0 ];
255
+
256
+ const FourNumberHelper = {
257
+ zero: [ ...tempFour ],
258
+ tempFour: tempFour,
259
+ set(to, top, right, bottom, left) {
260
+ if (right === undefined) right = bottom = left = top;
261
+ to[0] = top;
262
+ to[1] = right;
263
+ to[2] = bottom;
264
+ to[3] = left;
265
+ return to;
260
266
  },
261
- fourNumber(num, maxValue) {
267
+ setTemp(top, right, bottom, left) {
268
+ return set$1(tempFour, top, right, bottom, left);
269
+ },
270
+ toTempAB(a, b, change) {
271
+ tempTo = change ? isNumber(a) ? b : a : [];
272
+ if (isNumber(a)) tempA = setTemp(a), tempB = b; else if (isNumber(b)) tempA = a,
273
+ tempB = setTemp(b); else tempA = a, tempB = b;
274
+ if (tempA.length !== 4) tempA = get$1(tempA);
275
+ if (tempB.length !== 4) tempB = get$1(tempB);
276
+ },
277
+ get(num, maxValue) {
262
278
  let data;
263
- if (isArray(num)) {
279
+ if (!isNumber(num)) {
264
280
  switch (num.length) {
265
281
  case 4:
266
282
  data = isUndefined(maxValue) ? num : [ ...num ];
@@ -283,9 +299,39 @@ const MathHelper = {
283
299
  }
284
300
  }
285
301
  if (!data) data = [ num, num, num, num ];
286
- if (maxValue) for (let i = 0; i < 4; i++) if (data[i] > maxValue) data[i] = maxValue;
302
+ if (!isUndefined(maxValue)) for (let i = 0; i < 4; i++) if (data[i] > maxValue) data[i] = maxValue;
287
303
  return data;
288
304
  },
305
+ max(t, other, change) {
306
+ if (isNumber(t) && isNumber(other)) return max$1(t, other);
307
+ toTempAB(t, other, change);
308
+ return set$1(tempTo, max$1(tempA[0], tempB[0]), max$1(tempA[1], tempB[1]), max$1(tempA[2], tempB[2]), max$1(tempA[3], tempB[3]));
309
+ },
310
+ add(t, other, change) {
311
+ if (isNumber(t) && isNumber(other)) return t + other;
312
+ toTempAB(t, other, change);
313
+ return set$1(tempTo, tempA[0] + tempB[0], tempA[1] + tempB[1], tempA[2] + tempB[2], tempA[3] + tempB[3]);
314
+ },
315
+ swapAndScale(t, scaleX, scaleY, change) {
316
+ if (isNumber(t)) return scaleX === scaleY ? t * scaleX : [ t * scaleY, t * scaleX ];
317
+ const to = change ? t : [];
318
+ const [top, right, bottom, left] = t.length === 4 ? t : get$1(t);
319
+ return set$1(to, bottom * scaleY, left * scaleX, top * scaleY, right * scaleX);
320
+ }
321
+ };
322
+
323
+ const {set: set$1, get: get$1, setTemp: setTemp, toTempAB: toTempAB} = FourNumberHelper;
324
+
325
+ const {round: round$3, pow: pow$1, PI: PI$1} = Math;
326
+
327
+ const MathHelper = {
328
+ within(value, min, max) {
329
+ if (isObject(min)) max = min.max, min = min.min;
330
+ if (!isUndefined(min) && value < min) value = min;
331
+ if (!isUndefined(max) && value > max) value = max;
332
+ return value;
333
+ },
334
+ fourNumber: FourNumberHelper.get,
289
335
  formatRotation(rotation, unsign) {
290
336
  rotation %= 360;
291
337
  if (unsign) {
@@ -1220,19 +1266,11 @@ const BoundsHelper = {
1220
1266
  B.move(t, x, y);
1221
1267
  return t;
1222
1268
  },
1223
- toOffsetOutBounds(t, to, parent) {
1224
- if (!to) {
1225
- to = t;
1226
- } else {
1227
- copy$6(to, t);
1228
- }
1229
- if (parent) {
1230
- to.offsetX = -(B.maxX(parent) - t.x);
1231
- to.offsetY = -(B.maxY(parent) - t.y);
1232
- } else {
1233
- to.offsetX = t.x + t.width;
1234
- to.offsetY = t.y + t.height;
1235
- }
1269
+ toOffsetOutBounds(t, to, offsetBounds) {
1270
+ if (!to) to = t; else copy$6(to, t);
1271
+ if (!offsetBounds) offsetBounds = t;
1272
+ to.offsetX = B.maxX(offsetBounds);
1273
+ to.offsetY = B.maxY(offsetBounds);
1236
1274
  B.move(to, -to.offsetX, -to.offsetY);
1237
1275
  },
1238
1276
  scale(t, scaleX, scaleY = scaleX, onlySize) {
@@ -2263,7 +2301,7 @@ class LeaferCanvasBase extends Canvas {
2263
2301
  const {pixelRatio: pixelRatio, pixelSnap: pixelSnap} = this, w = this.worldTransform;
2264
2302
  if (parentMatrix) multiplyParent$3(matrix, parentMatrix, w);
2265
2303
  pixelScale(matrix, pixelRatio, w);
2266
- if (pixelSnap) {
2304
+ if (pixelSnap && !matrix.ignorePixelSnap) {
2267
2305
  if (matrix.half && matrix.half * pixelRatio % 2) w.e = round$1(w.e - .5) + .5, w.f = round$1(w.f - .5) + .5; else w.e = round$1(w.e),
2268
2306
  w.f = round$1(w.f);
2269
2307
  }
@@ -5873,8 +5911,8 @@ const LeafBounds = {
5873
5911
  copyAndSpread(layout.strokeBounds, layout.boxBounds, layout.strokeBoxSpread);
5874
5912
  },
5875
5913
  __updateRenderBounds(_bounds) {
5876
- const layout = this.__layout;
5877
- layout.renderSpread > 0 ? copyAndSpread(layout.renderBounds, layout.boxBounds, layout.renderSpread) : copy$1(layout.renderBounds, layout.strokeBounds);
5914
+ const layout = this.__layout, {renderSpread: renderSpread} = layout;
5915
+ isNumber(renderSpread) && renderSpread <= 0 ? copy$1(layout.renderBounds, layout.strokeBounds) : copyAndSpread(layout.renderBounds, layout.boxBounds, renderSpread);
5878
5916
  }
5879
5917
  };
5880
5918
 
@@ -5972,6 +6010,8 @@ const tempScaleData = {};
5972
6010
 
5973
6011
  const {LEAF: LEAF, create: create} = IncrementId;
5974
6012
 
6013
+ const {stintSet: stintSet} = DataHelper;
6014
+
5975
6015
  const {toInnerPoint: toInnerPoint, toOuterPoint: toOuterPoint, multiplyParent: multiplyParent} = MatrixHelper;
5976
6016
 
5977
6017
  const {toOuterOf: toOuterOf} = BoundsHelper;
@@ -6253,7 +6293,8 @@ exports.Leaf = class Leaf {
6253
6293
  const cameraWorld = this.__cameraWorld, world = this.__world;
6254
6294
  multiplyParent(world, options.matrix, cameraWorld, undefined, world);
6255
6295
  toOuterOf(this.__layout.renderBounds, cameraWorld, cameraWorld);
6256
- cameraWorld.half !== world.half && (cameraWorld.half = world.half);
6296
+ stintSet(cameraWorld, "half", world.half);
6297
+ stintSet(cameraWorld, "ignorePixelSnap", world.ignorePixelSnap);
6257
6298
  return cameraWorld;
6258
6299
  } else {
6259
6300
  return this.__world;
@@ -6776,7 +6817,7 @@ class LeafLevelList {
6776
6817
  }
6777
6818
  }
6778
6819
 
6779
- const version = "1.9.7";
6820
+ const version = "1.9.8";
6780
6821
 
6781
6822
  exports.AlignHelper = AlignHelper;
6782
6823
 
@@ -6816,6 +6857,8 @@ exports.Eventer = Eventer;
6816
6857
 
6817
6858
  exports.FileHelper = FileHelper;
6818
6859
 
6860
+ exports.FourNumberHelper = FourNumberHelper;
6861
+
6819
6862
  exports.ImageEvent = ImageEvent;
6820
6863
 
6821
6864
  exports.ImageManager = ImageManager;
package/lib/core.esm.js CHANGED
@@ -247,18 +247,34 @@ class LeafData {
247
247
  }
248
248
  }
249
249
 
250
- const {round: round$3, pow: pow$1, PI: PI$1} = Math;
251
-
252
- const MathHelper = {
253
- within(value, min, max) {
254
- if (isObject(min)) max = min.max, min = min.min;
255
- if (!isUndefined(min) && value < min) value = min;
256
- if (!isUndefined(max) && value > max) value = max;
257
- return value;
250
+ let tempA, tempB, tempTo;
251
+
252
+ const {max: max$1} = Math, tempFour = [ 0, 0, 0, 0 ];
253
+
254
+ const FourNumberHelper = {
255
+ zero: [ ...tempFour ],
256
+ tempFour: tempFour,
257
+ set(to, top, right, bottom, left) {
258
+ if (right === undefined) right = bottom = left = top;
259
+ to[0] = top;
260
+ to[1] = right;
261
+ to[2] = bottom;
262
+ to[3] = left;
263
+ return to;
264
+ },
265
+ setTemp(top, right, bottom, left) {
266
+ return set$1(tempFour, top, right, bottom, left);
258
267
  },
259
- fourNumber(num, maxValue) {
268
+ toTempAB(a, b, change) {
269
+ tempTo = change ? isNumber(a) ? b : a : [];
270
+ if (isNumber(a)) tempA = setTemp(a), tempB = b; else if (isNumber(b)) tempA = a,
271
+ tempB = setTemp(b); else tempA = a, tempB = b;
272
+ if (tempA.length !== 4) tempA = get$1(tempA);
273
+ if (tempB.length !== 4) tempB = get$1(tempB);
274
+ },
275
+ get(num, maxValue) {
260
276
  let data;
261
- if (isArray(num)) {
277
+ if (!isNumber(num)) {
262
278
  switch (num.length) {
263
279
  case 4:
264
280
  data = isUndefined(maxValue) ? num : [ ...num ];
@@ -281,9 +297,39 @@ const MathHelper = {
281
297
  }
282
298
  }
283
299
  if (!data) data = [ num, num, num, num ];
284
- if (maxValue) for (let i = 0; i < 4; i++) if (data[i] > maxValue) data[i] = maxValue;
300
+ if (!isUndefined(maxValue)) for (let i = 0; i < 4; i++) if (data[i] > maxValue) data[i] = maxValue;
285
301
  return data;
286
302
  },
303
+ max(t, other, change) {
304
+ if (isNumber(t) && isNumber(other)) return max$1(t, other);
305
+ toTempAB(t, other, change);
306
+ return set$1(tempTo, max$1(tempA[0], tempB[0]), max$1(tempA[1], tempB[1]), max$1(tempA[2], tempB[2]), max$1(tempA[3], tempB[3]));
307
+ },
308
+ add(t, other, change) {
309
+ if (isNumber(t) && isNumber(other)) return t + other;
310
+ toTempAB(t, other, change);
311
+ return set$1(tempTo, tempA[0] + tempB[0], tempA[1] + tempB[1], tempA[2] + tempB[2], tempA[3] + tempB[3]);
312
+ },
313
+ swapAndScale(t, scaleX, scaleY, change) {
314
+ if (isNumber(t)) return scaleX === scaleY ? t * scaleX : [ t * scaleY, t * scaleX ];
315
+ const to = change ? t : [];
316
+ const [top, right, bottom, left] = t.length === 4 ? t : get$1(t);
317
+ return set$1(to, bottom * scaleY, left * scaleX, top * scaleY, right * scaleX);
318
+ }
319
+ };
320
+
321
+ const {set: set$1, get: get$1, setTemp: setTemp, toTempAB: toTempAB} = FourNumberHelper;
322
+
323
+ const {round: round$3, pow: pow$1, PI: PI$1} = Math;
324
+
325
+ const MathHelper = {
326
+ within(value, min, max) {
327
+ if (isObject(min)) max = min.max, min = min.min;
328
+ if (!isUndefined(min) && value < min) value = min;
329
+ if (!isUndefined(max) && value > max) value = max;
330
+ return value;
331
+ },
332
+ fourNumber: FourNumberHelper.get,
287
333
  formatRotation(rotation, unsign) {
288
334
  rotation %= 360;
289
335
  if (unsign) {
@@ -1218,19 +1264,11 @@ const BoundsHelper = {
1218
1264
  B.move(t, x, y);
1219
1265
  return t;
1220
1266
  },
1221
- toOffsetOutBounds(t, to, parent) {
1222
- if (!to) {
1223
- to = t;
1224
- } else {
1225
- copy$6(to, t);
1226
- }
1227
- if (parent) {
1228
- to.offsetX = -(B.maxX(parent) - t.x);
1229
- to.offsetY = -(B.maxY(parent) - t.y);
1230
- } else {
1231
- to.offsetX = t.x + t.width;
1232
- to.offsetY = t.y + t.height;
1233
- }
1267
+ toOffsetOutBounds(t, to, offsetBounds) {
1268
+ if (!to) to = t; else copy$6(to, t);
1269
+ if (!offsetBounds) offsetBounds = t;
1270
+ to.offsetX = B.maxX(offsetBounds);
1271
+ to.offsetY = B.maxY(offsetBounds);
1234
1272
  B.move(to, -to.offsetX, -to.offsetY);
1235
1273
  },
1236
1274
  scale(t, scaleX, scaleY = scaleX, onlySize) {
@@ -2261,7 +2299,7 @@ class LeaferCanvasBase extends Canvas {
2261
2299
  const {pixelRatio: pixelRatio, pixelSnap: pixelSnap} = this, w = this.worldTransform;
2262
2300
  if (parentMatrix) multiplyParent$3(matrix, parentMatrix, w);
2263
2301
  pixelScale(matrix, pixelRatio, w);
2264
- if (pixelSnap) {
2302
+ if (pixelSnap && !matrix.ignorePixelSnap) {
2265
2303
  if (matrix.half && matrix.half * pixelRatio % 2) w.e = round$1(w.e - .5) + .5, w.f = round$1(w.f - .5) + .5; else w.e = round$1(w.e),
2266
2304
  w.f = round$1(w.f);
2267
2305
  }
@@ -5871,8 +5909,8 @@ const LeafBounds = {
5871
5909
  copyAndSpread(layout.strokeBounds, layout.boxBounds, layout.strokeBoxSpread);
5872
5910
  },
5873
5911
  __updateRenderBounds(_bounds) {
5874
- const layout = this.__layout;
5875
- layout.renderSpread > 0 ? copyAndSpread(layout.renderBounds, layout.boxBounds, layout.renderSpread) : copy$1(layout.renderBounds, layout.strokeBounds);
5912
+ const layout = this.__layout, {renderSpread: renderSpread} = layout;
5913
+ isNumber(renderSpread) && renderSpread <= 0 ? copy$1(layout.renderBounds, layout.strokeBounds) : copyAndSpread(layout.renderBounds, layout.boxBounds, renderSpread);
5876
5914
  }
5877
5915
  };
5878
5916
 
@@ -5970,6 +6008,8 @@ const tempScaleData = {};
5970
6008
 
5971
6009
  const {LEAF: LEAF, create: create} = IncrementId;
5972
6010
 
6011
+ const {stintSet: stintSet} = DataHelper;
6012
+
5973
6013
  const {toInnerPoint: toInnerPoint, toOuterPoint: toOuterPoint, multiplyParent: multiplyParent} = MatrixHelper;
5974
6014
 
5975
6015
  const {toOuterOf: toOuterOf} = BoundsHelper;
@@ -6251,7 +6291,8 @@ let Leaf = class Leaf {
6251
6291
  const cameraWorld = this.__cameraWorld, world = this.__world;
6252
6292
  multiplyParent(world, options.matrix, cameraWorld, undefined, world);
6253
6293
  toOuterOf(this.__layout.renderBounds, cameraWorld, cameraWorld);
6254
- cameraWorld.half !== world.half && (cameraWorld.half = world.half);
6294
+ stintSet(cameraWorld, "half", world.half);
6295
+ stintSet(cameraWorld, "ignorePixelSnap", world.ignorePixelSnap);
6255
6296
  return cameraWorld;
6256
6297
  } else {
6257
6298
  return this.__world;
@@ -6774,6 +6815,6 @@ class LeafLevelList {
6774
6815
  }
6775
6816
  }
6776
6817
 
6777
- const version = "1.9.7";
6818
+ const version = "1.9.8";
6778
6819
 
6779
- export { AlignHelper, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsEvent, BoundsHelper, Branch, BranchHelper, BranchRender, CanvasManager, ChildEvent, Creator, DataHelper, Debug, Direction4, Direction9, EllipseHelper, Event, EventCreator, Eventer, FileHelper, ImageEvent, ImageManager, IncrementId, LayoutEvent, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, LeaferCanvasBase, LeaferEvent, LeaferImage, MathHelper, Matrix, MatrixHelper, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Platform, Plugin, Point, PointHelper, PropertyEvent, RectHelper, RenderEvent, ResizeEvent, Resource, Run, StringNumberMap, TaskItem, TaskProcessor, TwoPointBoundsHelper, UICreator, WaitHelper, WatchEvent, affectRenderBoundsType, affectStrokeBoundsType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, createDescriptor, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, dimType, doBoundsType, doStrokeType, emptyData, eraserType, extraPropertyEventMap, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, isArray, isData, isEmptyData, isFinite, isNull, isNumber, isObject, isString, isUndefined, layoutProcessor, leaferTransformAttrMap, maskType, naturalBoundsType, opacityType, path, pathInputType, pathType, pen, positionType, registerUI, registerUIEvent, rewrite, rewriteAble, rotationType, scaleType, scrollType, sortType, strokeType, surfaceType, tempBounds, tempMatrix, tempPoint$2 as tempPoint, tryToNumber, useModule, version, visibleType };
6820
+ export { AlignHelper, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsEvent, BoundsHelper, Branch, BranchHelper, BranchRender, CanvasManager, ChildEvent, Creator, DataHelper, Debug, Direction4, Direction9, EllipseHelper, Event, EventCreator, Eventer, FileHelper, FourNumberHelper, ImageEvent, ImageManager, IncrementId, LayoutEvent, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, LeaferCanvasBase, LeaferEvent, LeaferImage, MathHelper, Matrix, MatrixHelper, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Platform, Plugin, Point, PointHelper, PropertyEvent, RectHelper, RenderEvent, ResizeEvent, Resource, Run, StringNumberMap, TaskItem, TaskProcessor, TwoPointBoundsHelper, UICreator, WaitHelper, WatchEvent, affectRenderBoundsType, affectStrokeBoundsType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, createDescriptor, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, dimType, doBoundsType, doStrokeType, emptyData, eraserType, extraPropertyEventMap, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, isArray, isData, isEmptyData, isFinite, isNull, isNumber, isObject, isString, isUndefined, layoutProcessor, leaferTransformAttrMap, maskType, naturalBoundsType, opacityType, path, pathInputType, pathType, pen, positionType, registerUI, registerUIEvent, rewrite, rewriteAble, rotationType, scaleType, scrollType, sortType, strokeType, surfaceType, tempBounds, tempMatrix, tempPoint$2 as tempPoint, tryToNumber, useModule, version, visibleType };