@inditextech/weave-sdk 3.9.0-SNAPSHOT.186.1 → 3.9.1

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/dist/types.js CHANGED
@@ -32,13 +32,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
32
32
  }) : target, mod));
33
33
 
34
34
  //#endregion
35
- //#region node_modules/emittery/maps.js
35
+ //#region ../../node_modules/emittery/maps.js
36
36
  const anyMap = new WeakMap();
37
37
  const eventsMap = new WeakMap();
38
38
  const producersMap = new WeakMap();
39
39
 
40
40
  //#endregion
41
- //#region node_modules/emittery/index.js
41
+ //#region ../../node_modules/emittery/index.js
42
42
  const anyProducer = Symbol("anyProducer");
43
43
  const resolvedPromise = Promise.resolve();
44
44
  const listenerAdded = Symbol("listenerAdded");
@@ -442,11 +442,11 @@ var require_lodash = __commonJS({ "../../node_modules/lodash/lodash.js"(exports,
442
442
  /** Used as a safe reference for `undefined` in pre-ES5 environments. */
443
443
  var undefined$1;
444
444
  /** Used as the semantic version number. */
445
- var VERSION = "4.17.21";
445
+ var VERSION = "4.18.1";
446
446
  /** Used as the size to enable large array optimizations. */
447
447
  var LARGE_ARRAY_SIZE$1 = 200;
448
448
  /** Error message constants. */
449
- var CORE_ERROR_TEXT = "Unsupported core-js use. Try https://npms.io/search?q=ponyfill.", FUNC_ERROR_TEXT$2 = "Expected a function", INVALID_TEMPL_VAR_ERROR_TEXT = "Invalid `variable` option passed into `_.template`";
449
+ var CORE_ERROR_TEXT = "Unsupported core-js use. Try https://npms.io/search?q=ponyfill.", FUNC_ERROR_TEXT$2 = "Expected a function", INVALID_TEMPL_VAR_ERROR_TEXT = "Invalid `variable` option passed into `_.template`", INVALID_TEMPL_IMPORTS_ERROR_TEXT = "Invalid `imports` option passed into `_.template`";
450
450
  /** Used to stand-in for `undefined` hash values. */
451
451
  var HASH_UNDEFINED$2 = "__lodash_hash_undefined__";
452
452
  /** Used as the maximum memoize cache size. */
@@ -1886,6 +1886,10 @@ var require_lodash = __commonJS({ "../../node_modules/lodash/lodash.js"(exports,
1886
1886
  * embedded Ruby (ERB) as well as ES2015 template strings. Change the
1887
1887
  * following template settings to use alternative delimiters.
1888
1888
  *
1889
+ * **Security:** See
1890
+ * [threat model](https://github.com/lodash/lodash/blob/main/threat-model.md)
1891
+ * — `_.template` is insecure and will be removed in v5.
1892
+ *
1889
1893
  * @static
1890
1894
  * @memberOf _
1891
1895
  * @type {Object}
@@ -2288,7 +2292,7 @@ var require_lodash = __commonJS({ "../../node_modules/lodash/lodash.js"(exports,
2288
2292
  * @name has
2289
2293
  * @memberOf SetCache
2290
2294
  * @param {*} value The value to search for.
2291
- * @returns {number} Returns `true` if `value` is found, else `false`.
2295
+ * @returns {boolean} Returns `true` if `value` is found, else `false`.
2292
2296
  */
2293
2297
  function setCacheHas(value) {
2294
2298
  return this.__data__.has(value);
@@ -3826,8 +3830,15 @@ var require_lodash = __commonJS({ "../../node_modules/lodash/lodash.js"(exports,
3826
3830
  */
3827
3831
  function baseUnset(object, path) {
3828
3832
  path = castPath(path, object);
3829
- object = parent(object, path);
3830
- return object == null || delete object[toKey(last(path))];
3833
+ var index = -1, length = path.length;
3834
+ if (!length) return true;
3835
+ while (++index < length) {
3836
+ var key = toKey(path[index]);
3837
+ if (key === "__proto__" && !hasOwnProperty$9.call(object, "__proto__")) return false;
3838
+ if ((key === "constructor" || key === "prototype") && index < length - 1) return false;
3839
+ }
3840
+ var obj = parent(object, path);
3841
+ return obj == null || delete obj[toKey(last(path))];
3831
3842
  }
3832
3843
  /**
3833
3844
  * The base implementation of `_.update`.
@@ -5731,7 +5742,7 @@ var require_lodash = __commonJS({ "../../node_modules/lodash/lodash.js"(exports,
5731
5742
  }
5732
5743
  /**
5733
5744
  * Creates an array with all falsey values removed. The values `false`, `null`,
5734
- * `0`, `""`, `undefined`, and `NaN` are falsey.
5745
+ * `0`, `-0`, `0n`, `""`, `undefined`, and `NaN` are falsy.
5735
5746
  *
5736
5747
  * @static
5737
5748
  * @memberOf _
@@ -6209,7 +6220,7 @@ var require_lodash = __commonJS({ "../../node_modules/lodash/lodash.js"(exports,
6209
6220
  var index = -1, length = pairs == null ? 0 : pairs.length, result$1 = {};
6210
6221
  while (++index < length) {
6211
6222
  var pair = pairs[index];
6212
- result$1[pair[0]] = pair[1];
6223
+ baseAssignValue$4(result$1, pair[0], pair[1]);
6213
6224
  }
6214
6225
  return result$1;
6215
6226
  }
@@ -12312,6 +12323,8 @@ var require_lodash = __commonJS({ "../../node_modules/lodash/lodash.js"(exports,
12312
12323
  * **Note:** JavaScript follows the IEEE-754 standard for resolving
12313
12324
  * floating-point values which can produce unexpected results.
12314
12325
  *
12326
+ * **Note:** If `lower` is greater than `upper`, the values are swapped.
12327
+ *
12315
12328
  * @static
12316
12329
  * @memberOf _
12317
12330
  * @since 0.7.0
@@ -12325,9 +12338,16 @@ var require_lodash = __commonJS({ "../../node_modules/lodash/lodash.js"(exports,
12325
12338
  * _.random(0, 5);
12326
12339
  * // => an integer between 0 and 5
12327
12340
  *
12341
+ * // when lower is greater than upper the values are swapped
12342
+ * _.random(5, 0);
12343
+ * // => an integer between 0 and 5
12344
+ *
12328
12345
  * _.random(5);
12329
12346
  * // => also an integer between 0 and 5
12330
12347
  *
12348
+ * _.random(-5);
12349
+ * // => an integer between -5 and 0
12350
+ *
12331
12351
  * _.random(5, true);
12332
12352
  * // => a floating-point number between 0 and 5
12333
12353
  *
@@ -12860,6 +12880,10 @@ var require_lodash = __commonJS({ "../../node_modules/lodash/lodash.js"(exports,
12860
12880
  * properties may be accessed as free variables in the template. If a setting
12861
12881
  * object is given, it takes precedence over `_.templateSettings` values.
12862
12882
  *
12883
+ * **Security:** `_.template` is insecure and should not be used. It will be
12884
+ * removed in Lodash v5. Avoid untrusted input. See
12885
+ * [threat model](https://github.com/lodash/lodash/blob/main/threat-model.md).
12886
+ *
12863
12887
  * **Note:** In the development build `_.template` utilizes
12864
12888
  * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
12865
12889
  * for easier debugging.
@@ -12961,8 +12985,11 @@ var require_lodash = __commonJS({ "../../node_modules/lodash/lodash.js"(exports,
12961
12985
  var settings = lodash.templateSettings;
12962
12986
  if (guard && isIterateeCall$2(string, options, guard)) options = undefined$1;
12963
12987
  string = toString(string);
12964
- options = assignInWith({}, options, settings, customDefaultsAssignIn);
12965
- var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn), importsKeys = keys(imports), importsValues = baseValues(imports, importsKeys);
12988
+ options = assignWith({}, options, settings, customDefaultsAssignIn);
12989
+ var imports = assignWith({}, options.imports, settings.imports, customDefaultsAssignIn), importsKeys = keys(imports), importsValues = baseValues(imports, importsKeys);
12990
+ arrayEach(importsKeys, function(key) {
12991
+ if (reForbiddenIdentifierChars.test(key)) throw new Error$1(INVALID_TEMPL_IMPORTS_ERROR_TEXT);
12992
+ });
12966
12993
  var isEscaping, isEvaluating, index = 0, interpolate = options.interpolate || reNoMatch, source = "__p += '";
12967
12994
  var reDelimiters = RegExp$1((options.escape || reNoMatch).source + "|" + interpolate.source + "|" + (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + "|" + (options.evaluate || reNoMatch).source + "|$", "g");
12968
12995
  var sourceURL = "//# sourceURL=" + (hasOwnProperty$9.call(options, "sourceURL") ? (options.sourceURL + "").replace(/\s/g, " ") : "lodash.templateSources[" + ++templateCounter + "]") + "\n";
@@ -20755,8 +20782,8 @@ var WeaveNode = class {
20755
20782
  return cancelBubble;
20756
20783
  }
20757
20784
  handleMouseout(e, node) {
20758
- const isCtrlOrMetaPressed = e.evt.ctrlKey || e.evt.metaKey;
20759
- if (isCtrlOrMetaPressed) return;
20785
+ const isCtrlOrMetaPressed = e.evt?.ctrlKey || e.evt?.metaKey;
20786
+ if (isCtrlOrMetaPressed) return false;
20760
20787
  const realNode = this.instance.getInstanceRecursive(node);
20761
20788
  if (realNode) this.hideHoverState();
20762
20789
  }
@@ -21421,10 +21448,16 @@ var WeaveTargetingManager = class {
21421
21448
  const utilityLayer = this.instance.getUtilityLayer();
21422
21449
  if (utilityLayer) utilityLayer.visible(false);
21423
21450
  let containerAlt = containerOverCursor(this.instance, [], relativeMousePointer);
21424
- if (!containerAlt) containerAlt = this.instance.getMainLayer();
21425
21451
  const nodesSelection = this.instance.getPlugin("nodesSelection");
21426
21452
  if (nodesSelection) nodesSelection.getTransformer().visible(false);
21427
- relativeMousePointer = containerAlt?.getRelativePointerPosition() ?? relativeMousePointer;
21453
+ if (containerAlt && point === void 0) relativeMousePointer = containerAlt.getRelativePointerPosition() ?? relativeMousePointer;
21454
+ if (!containerAlt && point === void 0) {
21455
+ containerAlt = this.instance.getMainLayer();
21456
+ relativeMousePointer = containerAlt?.getRelativePointerPosition() ?? {
21457
+ x: 0,
21458
+ y: 0
21459
+ };
21460
+ }
21428
21461
  if (utilityLayer) utilityLayer.visible(true);
21429
21462
  if (nodesSelection) nodesSelection.getTransformer().visible(true);
21430
21463
  return {
@@ -22019,7 +22052,7 @@ var WeaveRegisterManager = class {
22019
22052
 
22020
22053
  //#endregion
22021
22054
  //#region package.json
22022
- var version = "3.9.0-SNAPSHOT.186.1";
22055
+ var version = "3.9.1";
22023
22056
 
22024
22057
  //#endregion
22025
22058
  //#region src/managers/setup.ts
@@ -25720,7 +25753,7 @@ const WEAVE_IMAGE_DEFAULT_CONFIG = {
25720
25753
  cursor: { loading: "wait" }
25721
25754
  },
25722
25755
  imageLoading: {
25723
- maxRetryAttempts: 15,
25756
+ maxRetryAttempts: 3,
25724
25757
  retryDelayMs: 2e3
25725
25758
  },
25726
25759
  crossOrigin: "anonymous",
@@ -25770,19 +25803,7 @@ var WeaveImageCrop = class WeaveImageCrop {
25770
25803
  this.onClose = () => {};
25771
25804
  this.handleHide = this.hide.bind(this);
25772
25805
  }
25773
- show(onClose, options) {
25774
- this.onClose = onClose;
25775
- const nodeEdgeSnappingPlugin = this.getNodesEdgeSnappingPlugin();
25776
- if (nodeEdgeSnappingPlugin) nodeEdgeSnappingPlugin.disable();
25777
- const nodeDistanceSnappingPlugin = this.getNodesDistanceSnappingPlugin();
25778
- if (nodeDistanceSnappingPlugin) nodeDistanceSnappingPlugin.disable();
25779
- const nodesSelectionPlugin = this.getNodesSelectionPlugin();
25780
- if (nodesSelectionPlugin) nodesSelectionPlugin.disable();
25781
- this.node.clearCache(this.image);
25782
- this.image.setAttrs({ cropping: true });
25783
- this.image.listening(false);
25784
- const imageAttrs = this.image.getAttrs();
25785
- this.internalImage.hide();
25806
+ setupCropImage(imageAttrs, visible) {
25786
25807
  this.cropGroup.destroyChildren();
25787
25808
  const actualScale = imageAttrs.uncroppedImage.width / imageAttrs.imageInfo.width;
25788
25809
  const cropScale = imageAttrs.cropInfo ? imageAttrs.cropInfo.scaleX : actualScale;
@@ -25796,10 +25817,26 @@ var WeaveImageCrop = class WeaveImageCrop {
25796
25817
  scaleY: 1,
25797
25818
  image: this.internalImage.image(),
25798
25819
  crop: void 0,
25799
- visible: true,
25820
+ visible,
25800
25821
  listening: false,
25801
25822
  draggable: false
25802
25823
  });
25824
+ return { realScale };
25825
+ }
25826
+ show(onClose, options) {
25827
+ this.onClose = onClose;
25828
+ const nodeEdgeSnappingPlugin = this.getNodesEdgeSnappingPlugin();
25829
+ if (nodeEdgeSnappingPlugin) nodeEdgeSnappingPlugin.disable();
25830
+ const nodeDistanceSnappingPlugin = this.getNodesDistanceSnappingPlugin();
25831
+ if (nodeDistanceSnappingPlugin) nodeDistanceSnappingPlugin.disable();
25832
+ const nodesSelectionPlugin = this.getNodesSelectionPlugin();
25833
+ if (nodesSelectionPlugin) nodesSelectionPlugin.disable();
25834
+ this.node.clearCache(this.image);
25835
+ this.image.setAttrs({ cropping: true });
25836
+ this.image.listening(false);
25837
+ const imageAttrs = this.image.getAttrs();
25838
+ this.internalImage.hide();
25839
+ const { realScale } = this.setupCropImage(imageAttrs, true);
25803
25840
  this.imageOffsetX = imageAttrs.cropInfo ? imageAttrs.cropInfo.x * realScale : 0;
25804
25841
  this.imageOffsetY = imageAttrs.cropInfo ? imageAttrs.cropInfo.y * realScale : 0;
25805
25842
  const cropModeConfiguration = this.node.getConfiguration().cropMode;
@@ -26176,23 +26213,7 @@ var WeaveImageCrop = class WeaveImageCrop {
26176
26213
  }
26177
26214
  unCrop() {
26178
26215
  const imageAttrs = this.image.getAttrs();
26179
- this.cropGroup.destroyChildren();
26180
- const actualScale = imageAttrs.uncroppedImage.width / imageAttrs.imageInfo.width;
26181
- const cropScale = imageAttrs.cropInfo ? imageAttrs.cropInfo.scaleX : actualScale;
26182
- const realScale = actualScale / cropScale;
26183
- this.cropImage = new Konva.Image({
26184
- x: imageAttrs.cropInfo ? -imageAttrs.cropInfo.x * realScale : 0,
26185
- y: imageAttrs.cropInfo ? -imageAttrs.cropInfo.y * realScale : 0,
26186
- width: imageAttrs.uncroppedImage.width,
26187
- height: imageAttrs.uncroppedImage.height,
26188
- scaleX: 1,
26189
- scaleY: 1,
26190
- image: this.internalImage.image(),
26191
- crop: void 0,
26192
- visible: false,
26193
- listening: false,
26194
- draggable: false
26195
- });
26216
+ this.setupCropImage(imageAttrs, false);
26196
26217
  this.cropGroup.add(this.cropImage);
26197
26218
  const cropImageStage = this.cropImage.getAbsolutePosition();
26198
26219
  this.image.setAttrs({
@@ -26241,12 +26262,80 @@ var WeaveImageCrop = class WeaveImageCrop {
26241
26262
  this.instance.updateNode(this.node.serialize(this.image));
26242
26263
  }
26243
26264
  }
26265
+ handleClipExternal(image, reference) {
26266
+ const stage = this.instance.getStage();
26267
+ const originalRotation = image.getAbsoluteRotation();
26268
+ if (image.getAbsoluteRotation() !== reference.getAbsoluteRotation()) throw new Error("Image and reference must have the same rotation", { cause: "RotationNotAligned" });
26269
+ const originalContainer = image.getParent();
26270
+ const group = new Konva.Group();
26271
+ image.moveTo(group);
26272
+ reference.moveTo(group);
26273
+ originalContainer?.add(group);
26274
+ group.rotate(-originalRotation);
26275
+ const dImage = group.findOne("#" + image.getAttrs().id);
26276
+ const dReference = group.findOne("#" + reference.getAttrs().id);
26277
+ const intersectionRectAbs = this.getIntersectionRect(dImage, dReference);
26278
+ const intersectionRect = this.getIntersectionRect(dImage, dReference, stage);
26279
+ const imageRect = dImage.getClientRect({
26280
+ relativeTo: stage,
26281
+ skipStroke: true
26282
+ });
26283
+ if (!intersectionRect || !intersectionRectAbs) return;
26284
+ const imageAttrs = this.image.getAttrs();
26285
+ const actualScale = imageAttrs.uncroppedImage.width / imageAttrs.imageInfo.width;
26286
+ const cropScale = imageAttrs.cropInfo ? imageAttrs.cropInfo.scaleX : actualScale;
26287
+ const realScale = actualScale / cropScale;
26288
+ const imageOffsetX = imageAttrs.cropInfo ? imageAttrs.cropInfo.x * realScale : 0;
26289
+ const imageOffsetY = imageAttrs.cropInfo ? imageAttrs.cropInfo.y * realScale : 0;
26290
+ const diffX = intersectionRect.x - imageRect.x;
26291
+ const diffY = intersectionRect.y - imageRect.y;
26292
+ const realClipRect = {
26293
+ scaleX: actualScale,
26294
+ scaleY: actualScale,
26295
+ x: WeaveImageCrop.roundTo6Decimals(diffX + imageOffsetX),
26296
+ y: WeaveImageCrop.roundTo6Decimals(diffY + imageOffsetY),
26297
+ width: WeaveImageCrop.roundTo6Decimals(intersectionRect.width),
26298
+ height: WeaveImageCrop.roundTo6Decimals(intersectionRect.height)
26299
+ };
26300
+ if (dImage) {
26301
+ const cropSize = {
26302
+ x: diffX,
26303
+ y: diffY,
26304
+ width: intersectionRect.width,
26305
+ height: intersectionRect.height
26306
+ };
26307
+ dImage.setAttrs({
26308
+ width: intersectionRect.width,
26309
+ height: intersectionRect.height,
26310
+ cropInfo: realClipRect,
26311
+ cropSize,
26312
+ uncroppedImage: {
26313
+ width: imageAttrs.uncroppedImage.width,
26314
+ height: imageAttrs.uncroppedImage.height
26315
+ }
26316
+ });
26317
+ dImage.setAbsolutePosition(intersectionRectAbs);
26318
+ group.rotate(originalRotation);
26319
+ group.getChildren().forEach((child) => {
26320
+ child.moveTo(originalContainer);
26321
+ });
26322
+ group.destroy();
26323
+ const fImage = stage.findOne("#" + image.getAttrs().id);
26324
+ if (fImage) this.instance.updateNodeNT(this.node.serialize(fImage));
26325
+ }
26326
+ }
26244
26327
  static roundTo6Decimals(value) {
26245
26328
  return parseFloat(value.toFixed(6));
26246
26329
  }
26247
- getIntersectionRect(a, b) {
26248
- const rectA = a.getClientRect({ skipStroke: true });
26249
- const rectB = b.getClientRect({ skipStroke: true });
26330
+ getIntersectionRect(a, b, relativeTo) {
26331
+ const rectA = a.getClientRect({
26332
+ skipStroke: true,
26333
+ relativeTo
26334
+ });
26335
+ const rectB = b.getClientRect({
26336
+ skipStroke: true,
26337
+ relativeTo
26338
+ });
26250
26339
  const x1 = WeaveImageCrop.roundTo6Decimals(Math.max(rectA.x, rectB.x));
26251
26340
  const y1 = WeaveImageCrop.roundTo6Decimals(Math.max(rectA.y, rectB.y));
26252
26341
  const x2 = WeaveImageCrop.roundTo6Decimals(Math.min(rectA.x + rectA.width, rectB.x + rectB.width));
@@ -26738,8 +26827,8 @@ var WeaveImageNode = class extends WeaveNode {
26738
26827
  y: p.y - offsetY
26739
26828
  }));
26740
26829
  const rect = new Konva.Rect({
26741
- width: absoluteCorners[1].x - absoluteCorners[0].x,
26742
- height: absoluteCorners[2].y - absoluteCorners[0].y,
26830
+ width: Math.hypot(absoluteCorners[1].x - absoluteCorners[0].x, absoluteCorners[1].y - absoluteCorners[0].y),
26831
+ height: Math.hypot(absoluteCorners[3].x - absoluteCorners[0].x, absoluteCorners[3].y - absoluteCorners[0].y),
26743
26832
  fill: "transparent",
26744
26833
  strokeScaleEnabled: false,
26745
26834
  strokeWidth: 2,
@@ -26864,7 +26953,11 @@ var WeaveImageNode = class extends WeaveNode {
26864
26953
  onUpdate(nodeInstance, nextProps) {
26865
26954
  const id = nodeInstance.getAttrs().id;
26866
26955
  const node = nodeInstance;
26867
- nodeInstance.setAttrs({ ...nextProps });
26956
+ nodeInstance.setAttrs({
26957
+ ...nextProps,
26958
+ ...nextProps.cropInfo ? { cropInfo: nextProps.cropInfo } : { cropInfo: void 0 },
26959
+ ...nextProps.cropSize ? { cropSize: nextProps.cropSize } : { cropSize: void 0 }
26960
+ });
26868
26961
  const imagePlaceholder = node.findOne(`#${id}-placeholder`);
26869
26962
  const internalImage = node.findOne(`#${id}-image`);
26870
26963
  const nodeAttrs = node.getAttrs();
@@ -26908,29 +27001,12 @@ var WeaveImageNode = class extends WeaveNode {
26908
27001
  });
26909
27002
  }
26910
27003
  if (this.imageState[id ?? ""]?.loaded && this.imageState[id ?? ""]?.error) {
26911
- imagePlaceholder?.setAttrs({
26912
- ...internalImageProps,
26913
- ...nodeAttrs.imageProperties ?? {},
26914
- name: void 0,
26915
- id: `${id}-placeholder`,
26916
- nodeId: id,
26917
- x: 0,
26918
- y: 0,
26919
- scaleX: 1,
26920
- scaleY: 1,
26921
- rotation: 0,
26922
- visible: true,
26923
- fill: this.config.style.placeholder.fill,
26924
- strokeWidth: 0,
26925
- draggable: false,
26926
- zIndex: 0
26927
- });
26928
27004
  internalImage?.setAttrs({
26929
27005
  ...internalImageProps,
26930
27006
  ...nodeAttrs.imageProperties ?? {},
26931
27007
  name: void 0,
26932
27008
  id: `${id}-image`,
26933
- image: void 0,
27009
+ image: this.imageFallback[id ?? ""],
26934
27010
  nodeId: id,
26935
27011
  x: 0,
26936
27012
  y: 0,
@@ -26941,6 +27017,8 @@ var WeaveImageNode = class extends WeaveNode {
26941
27017
  draggable: false,
26942
27018
  zIndex: 1
26943
27019
  });
27020
+ internalImage?.visible(true);
27021
+ this.updateImageCrop(nodeInstance);
26944
27022
  }
26945
27023
  if (this.imageState[id ?? ""]?.loaded && !this.imageState[id ?? ""]?.error) {
26946
27024
  internalImage?.setAttrs({
@@ -26995,14 +27073,18 @@ var WeaveImageNode = class extends WeaveNode {
26995
27073
  }
26996
27074
  preloadImage(imageId, imageURL, { onLoad, onError }, loadingTryout = false) {
26997
27075
  const imageURLToLoad = imageURL ?? "http://localhost/false-image";
27076
+ if (imageURLToLoad === "") {
27077
+ this.setErrorState(imageId);
27078
+ return;
27079
+ }
26998
27080
  this.imageSource[imageId] = Konva.Util.createImageElement();
26999
27081
  this.imageSource[imageId].crossOrigin = this.config.crossOrigin;
27000
27082
  this.imageSource[imageId].onerror = (error) => {
27001
- if (!loadingTryout) this.imageState[imageId] = {
27002
- status: "error",
27003
- loaded: false,
27004
- error: true
27005
- };
27083
+ if (!loadingTryout) {
27084
+ const stage = this.instance.getStage();
27085
+ const image = stage.findOne(`#${imageId}`);
27086
+ if (image) this.setErrorState(imageId, image);
27087
+ }
27006
27088
  onError(error);
27007
27089
  };
27008
27090
  this.imageSource[imageId].onload = async () => {
@@ -27097,36 +27179,29 @@ var WeaveImageNode = class extends WeaveNode {
27097
27179
  }
27098
27180
  },
27099
27181
  onError: (error) => {
27100
- if (!this.config.useFallbackImage) this.imageTryoutIds[id] = setTimeout(() => {
27101
- const node = this.instance.getStage().findOne(`#${id}`);
27102
- if (node) {
27103
- this.imageTryoutAttempts[id] = (this.imageTryoutAttempts[id] ?? 0) + 1;
27104
- this.loadImage(node.getAttrs(), node, false, true);
27105
- }
27106
- }, this.config.imageLoading.retryDelayMs);
27182
+ if (!this.config.useFallbackImage) {
27183
+ const tryoutAttempts = this.imageTryoutAttempts[id] ?? 0;
27184
+ if (tryoutAttempts - 1 < this.config.imageLoading.maxRetryAttempts) {
27185
+ this.loadImageTryout(id);
27186
+ return;
27187
+ } else this.setErrorState(id, image);
27188
+ }
27107
27189
  if (loadTryout) {
27108
27190
  const tryoutAttempts = this.imageTryoutAttempts[id] ?? 0;
27109
- if (tryoutAttempts < this.config.imageLoading.maxRetryAttempts) this.imageTryoutIds[id] = setTimeout(() => {
27110
- const node = this.instance.getStage().findOne(`#${id}`);
27111
- if (node) {
27112
- this.imageTryoutAttempts[id] = tryoutAttempts + 1;
27113
- this.loadImage(node.getAttrs(), node, false, true);
27114
- }
27115
- }, this.config.imageLoading.retryDelayMs);
27191
+ if (tryoutAttempts - 1 < this.config.imageLoading.maxRetryAttempts) {
27192
+ this.loadImageTryout(id);
27193
+ return;
27194
+ } else this.setErrorState(id, image);
27116
27195
  return;
27117
27196
  }
27118
27197
  if (this.config.useFallbackImage && !useFallback && !loadTryout && imageProps.imageFallback) {
27119
27198
  this.loadImage({ ...params }, image, true);
27120
27199
  return;
27121
27200
  }
27122
- this.imageState[id] = {
27123
- status: "error",
27124
- loaded: false,
27125
- error: true
27126
- };
27201
+ this.setErrorState(id, image);
27127
27202
  image.setAttrs({ image: void 0 });
27203
+ console.error("Error loading image", error);
27128
27204
  this.resolveAsyncElement(id);
27129
- console.error("Error loading image", realImageURL, error);
27130
27205
  imagePlaceholder?.setAttrs({ visible: true });
27131
27206
  internalImage?.setAttrs({ visible: false });
27132
27207
  this.cacheNode(image);
@@ -27256,6 +27331,41 @@ var WeaveImageNode = class extends WeaveNode {
27256
27331
  }
27257
27332
  nodeInstance.destroy();
27258
27333
  }
27334
+ loadImageTryout(imageId) {
27335
+ this.imageTryoutIds[imageId] = setTimeout(() => {
27336
+ const node = this.instance.getStage().findOne(`#${imageId}`);
27337
+ if (node) {
27338
+ const tryoutAttempts = this.imageTryoutAttempts[imageId] ?? 0;
27339
+ this.imageTryoutAttempts[imageId] = tryoutAttempts + 1;
27340
+ this.loadImage(node.getAttrs(), node, false, true);
27341
+ }
27342
+ }, this.config.imageLoading.retryDelayMs);
27343
+ }
27344
+ setErrorState(imageId, image) {
27345
+ this.imageState[imageId] = {
27346
+ status: "loaded",
27347
+ loaded: true,
27348
+ error: true
27349
+ };
27350
+ this.resolveAsyncElement(imageId);
27351
+ if (image) this.cacheNode(image);
27352
+ }
27353
+ cropImageWithReference(image, reference) {
27354
+ const internalImage = image?.findOne(`#${image.getAttrs().id}-image`);
27355
+ const cropGroup = image?.findOne(`#${image.getAttrs().id}-cropGroup`);
27356
+ if (!internalImage || !cropGroup) throw new Error("Provided element is not a valid image node.", { cause: "InvalidImageNode" });
27357
+ this.imageCrop = new WeaveImageCrop(this.instance, this, image, internalImage, cropGroup);
27358
+ this.instance.stateTransactional(() => {
27359
+ this.imageCrop?.handleClipExternal(image, reference);
27360
+ const nodeHandler = this.instance.getNodeHandler(reference.getAttrs().nodeType);
27361
+ if (nodeHandler) {
27362
+ const rectangleState = nodeHandler.serialize(reference);
27363
+ this.instance.removeNodeNT(rectangleState);
27364
+ }
27365
+ });
27366
+ this.getNodesSelectionPlugin()?.setSelectedNodes([image]);
27367
+ this.getNodesSelectionPlugin()?.getHoverTransformer().forceUpdate();
27368
+ }
27259
27369
  };
27260
27370
 
27261
27371
  //#endregion
@@ -34428,14 +34538,15 @@ var WeaveImageToolAction = class extends WeaveAction {
34428
34538
  const dragProperties = this.instance.getDragProperties();
34429
34539
  if (dragProperties && dragId === WEAVE_IMAGE_TOOL_ACTION_NAME) {
34430
34540
  this.instance.getStage().setPointersPositions(e);
34431
- const position = this.instance.getStage().getRelativePointerPosition();
34432
- if (!position) return;
34541
+ const { mousePoint, container } = this.instance.getMousePointer();
34542
+ if (!mousePoint) return;
34433
34543
  this.instance.triggerAction(WEAVE_IMAGE_TOOL_ACTION_NAME, {
34434
34544
  type: WEAVE_IMAGE_TOOL_UPLOAD_TYPE.IMAGE_URL,
34435
34545
  image: dragProperties.imageURL,
34436
34546
  ...dragProperties.imageId ? { imageId: dragProperties.imageId } : {},
34437
34547
  ...dragProperties.forceMainContainer && { forceMainContainer: dragProperties.forceMainContainer },
34438
- position
34548
+ container,
34549
+ position: mousePoint
34439
34550
  });
34440
34551
  }
34441
34552
  });
@@ -34602,7 +34713,7 @@ var WeaveImageToolAction = class extends WeaveAction {
34602
34713
  }
34603
34714
  const { mousePoint, container } = this.instance.getMousePointer(position);
34604
34715
  this.imageAction[nodeId].clickPoint = mousePoint;
34605
- this.imageAction[nodeId].container = container;
34716
+ this.imageAction[nodeId].container = this.imageAction[nodeId].container ?? container;
34606
34717
  const nodeHandler = this.instance.getNodeHandler("image");
34607
34718
  const imageWidth = this.imageAction[nodeId].props.width ? this.imageAction[nodeId].props.width : imageSource?.width;
34608
34719
  const imageHeight = this.imageAction[nodeId].props.height ? this.imageAction[nodeId].props.height : imageSource?.height;
@@ -34669,9 +34780,9 @@ var WeaveImageToolAction = class extends WeaveAction {
34669
34780
  props: this.initProps(),
34670
34781
  imageId: nodeId,
34671
34782
  clickPoint: null,
34672
- container: void 0,
34673
34783
  imageFile: null,
34674
34784
  imageURL: null,
34785
+ container: params?.container,
34675
34786
  forceMainContainer: params?.forceMainContainer ?? false,
34676
34787
  uploadType: null,
34677
34788
  uploadImageFunction: null
@@ -34878,12 +34989,13 @@ var WeaveImagesToolAction = class extends WeaveAction {
34878
34989
  const dragProperties = this.instance.getDragProperties();
34879
34990
  if (dragProperties && dragId === WEAVE_IMAGES_TOOL_ACTION_NAME) {
34880
34991
  this.instance.getStage().setPointersPositions(e);
34881
- const position = this.instance.getStage().getRelativePointerPosition();
34882
- if (!position) return;
34992
+ const { mousePoint, container } = this.instance.getMousePointer();
34993
+ if (!mousePoint) return;
34883
34994
  this.instance.triggerAction(WEAVE_IMAGES_TOOL_ACTION_NAME, {
34884
34995
  type: WEAVE_IMAGES_TOOL_UPLOAD_TYPE.IMAGE_URL,
34885
34996
  images: dragProperties.imagesURL,
34886
- position,
34997
+ container,
34998
+ position: mousePoint,
34887
34999
  ...dragProperties.forceMainContainer && { forceMainContainer: dragProperties.forceMainContainer }
34888
35000
  });
34889
35001
  }
@@ -35044,7 +35156,7 @@ var WeaveImagesToolAction = class extends WeaveAction {
35044
35156
  stage.container().style.cursor = "default";
35045
35157
  const { mousePoint, container } = this.instance.getMousePointer(position);
35046
35158
  this.clickPoint = mousePoint;
35047
- this.container = container;
35159
+ this.container = this.container ?? container;
35048
35160
  const originPoint = {
35049
35161
  x: this.clickPoint?.x ?? 0,
35050
35162
  y: this.clickPoint?.y ?? 0
@@ -35099,10 +35211,8 @@ var WeaveImagesToolAction = class extends WeaveAction {
35099
35211
  },
35100
35212
  uploadImageFunction: uploadImageFunctionInternal,
35101
35213
  ...imageId && { imageId },
35102
- position: {
35103
- x: position$1.x,
35104
- y: position$1.y
35105
- },
35214
+ position: position$1,
35215
+ container: this.container,
35106
35216
  forceMainContainer: this.forceMainContainer,
35107
35217
  nodeId: nodeId$1
35108
35218
  }, true);
@@ -35136,10 +35246,8 @@ var WeaveImagesToolAction = class extends WeaveAction {
35136
35246
  },
35137
35247
  ...imageId && { imageId },
35138
35248
  ...options && { options },
35139
- position: {
35140
- x: position$1.x,
35141
- y: position$1.y
35142
- },
35249
+ position: position$1,
35250
+ container: this.container,
35143
35251
  forceMainContainer: this.forceMainContainer,
35144
35252
  nodeId: nodeId$1
35145
35253
  }, true);
@@ -35172,6 +35280,7 @@ var WeaveImagesToolAction = class extends WeaveAction {
35172
35280
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
35173
35281
  if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
35174
35282
  if (params?.position) this.setState(WEAVE_IMAGES_TOOL_STATE.SELECTED_POSITION);
35283
+ if (params?.container) this.container = params.container;
35175
35284
  this.nodesIds = [];
35176
35285
  this.forceMainContainer = params.forceMainContainer ?? false;
35177
35286
  if (params.type === WEAVE_IMAGES_TOOL_UPLOAD_TYPE.FILE) {
@@ -36989,11 +37098,13 @@ var WeaveVideoToolAction = class extends WeaveAction {
36989
37098
  const dragProperties = this.instance.getDragProperties();
36990
37099
  if (dragProperties && dragId === VIDEO_TOOL_ACTION_NAME) {
36991
37100
  this.instance.getStage().setPointersPositions(e);
36992
- const position = this.instance.getStage().getRelativePointerPosition();
37101
+ const { mousePoint, container } = this.instance.getMousePointer();
37102
+ if (!mousePoint) return;
36993
37103
  this.instance.triggerAction(VIDEO_TOOL_ACTION_NAME, {
36994
37104
  videoId: dragProperties.videoId,
36995
37105
  videoParams: dragProperties.videoParams,
36996
- position
37106
+ container,
37107
+ position: mousePoint
36997
37108
  });
36998
37109
  }
36999
37110
  });
@@ -37044,7 +37155,7 @@ var WeaveVideoToolAction = class extends WeaveAction {
37044
37155
  if (this.videoId && this.videoParams) {
37045
37156
  const { mousePoint, container } = this.instance.getMousePointer(position);
37046
37157
  this.clickPoint = mousePoint;
37047
- this.container = container;
37158
+ this.container = this.container ?? container;
37048
37159
  const nodeHandler = this.instance.getNodeHandler("video");
37049
37160
  if (nodeHandler) {
37050
37161
  const node = nodeHandler.create(this.videoId, {
@@ -37075,6 +37186,7 @@ var WeaveVideoToolAction = class extends WeaveAction {
37075
37186
  this.cancelAction = cancelAction;
37076
37187
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
37077
37188
  if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
37189
+ this.container = params?.container;
37078
37190
  this.forceMainContainer = params?.forceMainContainer ?? false;
37079
37191
  if (params?.videoId) this.updateProps({ videoId: params.videoId });
37080
37192
  if (params?.videoParams) {