@inditextech/weave-sdk 5.0.0-SNAPSHOT.338.1 → 5.0.0-SNAPSHOT.342.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/sdk.js CHANGED
@@ -9442,7 +9442,7 @@ var WeaveRegisterManager = class {
9442
9442
 
9443
9443
  //#endregion
9444
9444
  //#region package.json
9445
- var version = "5.0.0-SNAPSHOT.338.1";
9445
+ var version = "5.0.0-SNAPSHOT.342.1";
9446
9446
 
9447
9447
  //#endregion
9448
9448
  //#region src/managers/setup.ts
@@ -9802,54 +9802,80 @@ var WeaveExportManager = class {
9802
9802
  outH
9803
9803
  };
9804
9804
  }
9805
+ cloneStageForExport() {
9806
+ const originalStage = this.instance.getStage();
9807
+ const stage = originalStage.clone();
9808
+ const mainLayer = stage.findOne("#mainLayer");
9809
+ if (!mainLayer) throw new Error("Main layer not found");
9810
+ const selectionLayer = stage.findOne(`#${WEAVE_NODES_SELECTION_LAYER_ID}`);
9811
+ selectionLayer?.destroy();
9812
+ const gridLayer = stage.findOne(`#${WEAVE_GRID_LAYER_ID}`);
9813
+ gridLayer?.destroy();
9814
+ const scaleX = originalStage.scaleX();
9815
+ const scaleY = originalStage.scaleY();
9816
+ return {
9817
+ stage,
9818
+ mainLayer,
9819
+ originalScale: {
9820
+ scaleX,
9821
+ scaleY
9822
+ }
9823
+ };
9824
+ }
9825
+ setupForExport({ nodes, bounds, stage, mainLayer, scaleX, scaleY, options, exportArea }) {
9826
+ const { padding = 0, pixelRatio = 1, backgroundColor = WEAVE_EXPORT_BACKGROUND_COLOR } = options;
9827
+ const unscaledBounds = {
9828
+ x: bounds.x / scaleX,
9829
+ y: bounds.y / scaleY,
9830
+ width: bounds.width / scaleX,
9831
+ height: bounds.height / scaleY
9832
+ };
9833
+ const background = new Konva.Rect({
9834
+ x: unscaledBounds.x - padding,
9835
+ y: unscaledBounds.y - padding,
9836
+ width: unscaledBounds.width + 2 * padding,
9837
+ height: unscaledBounds.height + 2 * padding,
9838
+ strokeWidth: 0,
9839
+ fill: backgroundColor
9840
+ });
9841
+ const exportGroup = new Konva.Group();
9842
+ if (!exportArea) {
9843
+ exportGroup.add(background);
9844
+ for (const node of nodes) {
9845
+ const clonedNode = node.clone({ id: v4_default() });
9846
+ const absPos = node.getAbsolutePosition();
9847
+ clonedNode.absolutePosition({
9848
+ x: absPos.x / scaleX,
9849
+ y: absPos.y / scaleY
9850
+ });
9851
+ exportGroup.add(clonedNode);
9852
+ }
9853
+ mainLayer.add(exportGroup);
9854
+ } else mainLayer.add(background);
9855
+ const backgroundRect = background.getClientRect();
9856
+ stage.batchDraw();
9857
+ const { pixelRatio: finalPixelRatio } = this.fitKonvaPixelRatio(Math.round(backgroundRect.width), Math.round(backgroundRect.height), pixelRatio);
9858
+ return {
9859
+ exportGroup,
9860
+ pixelRatio: finalPixelRatio,
9861
+ backgroundRect
9862
+ };
9863
+ }
9805
9864
  exportNodesAsImage(nodes, boundingNodes, options) {
9806
9865
  return new Promise((resolve) => {
9807
- const { format = WEAVE_EXPORT_FORMATS.PNG, padding = 0, pixelRatio = 1, backgroundColor = WEAVE_EXPORT_BACKGROUND_COLOR } = options;
9808
- const originalStage = this.instance.getStage();
9809
- const stage = originalStage.clone();
9810
- const mainLayer = stage.findOne("#mainLayer");
9811
- if (!mainLayer) throw new Error("Main layer not found");
9812
- const selectionLayer = stage.findOne(`#${WEAVE_NODES_SELECTION_LAYER_ID}`);
9813
- selectionLayer?.destroy();
9814
- const gridLayer = stage.findOne(`#${WEAVE_GRID_LAYER_ID}`);
9815
- gridLayer?.destroy();
9816
- stage.scale({
9817
- x: 1,
9818
- y: 1
9819
- });
9866
+ const { format = WEAVE_EXPORT_FORMATS.PNG } = options;
9867
+ const { stage, mainLayer, originalScale: { scaleX, scaleY } } = this.cloneStageForExport();
9820
9868
  if (mainLayer) {
9821
- const bounds = getExportBoundingBox(boundingNodes(nodes));
9822
- const scaleX = originalStage.scaleX();
9823
- const scaleY = originalStage.scaleY();
9824
- const unscaledBounds = {
9825
- x: bounds.x / scaleX,
9826
- y: bounds.y / scaleY,
9827
- width: bounds.width / scaleX,
9828
- height: bounds.height / scaleY
9829
- };
9830
- const exportGroup = new Konva.Group();
9831
- const background = new Konva.Rect({
9832
- x: unscaledBounds.x - padding,
9833
- y: unscaledBounds.y - padding,
9834
- width: unscaledBounds.width + 2 * padding,
9835
- height: unscaledBounds.height + 2 * padding,
9836
- strokeWidth: 0,
9837
- fill: backgroundColor
9869
+ const { pixelRatio: finalPixelRatio, backgroundRect, exportGroup } = this.setupForExport({
9870
+ nodes,
9871
+ bounds: getExportBoundingBox(boundingNodes(nodes)),
9872
+ stage,
9873
+ mainLayer,
9874
+ scaleX,
9875
+ scaleY,
9876
+ options,
9877
+ exportArea: false
9838
9878
  });
9839
- exportGroup.add(background);
9840
- for (const node of nodes) {
9841
- const clonedNode = node.clone({ id: v4_default() });
9842
- const absPos = node.getAbsolutePosition();
9843
- clonedNode.absolutePosition({
9844
- x: absPos.x / scaleX,
9845
- y: absPos.y / scaleY
9846
- });
9847
- exportGroup.add(clonedNode);
9848
- }
9849
- mainLayer.add(exportGroup);
9850
- const backgroundRect = background.getClientRect();
9851
- stage.batchDraw();
9852
- const { pixelRatio: finalPixelRatio } = this.fitKonvaPixelRatio(Math.round(backgroundRect.width), Math.round(backgroundRect.height), pixelRatio);
9853
9879
  exportGroup.toImage({
9854
9880
  x: Math.round(backgroundRect.x),
9855
9881
  y: Math.round(backgroundRect.y),
@@ -9869,48 +9895,19 @@ var WeaveExportManager = class {
9869
9895
  }
9870
9896
  exportNodesAsBlob(nodes, boundingNodes, options) {
9871
9897
  return new Promise((resolve) => {
9872
- const { format = WEAVE_EXPORT_FORMATS.PNG, padding = 0, pixelRatio = 1, backgroundColor = WEAVE_EXPORT_BACKGROUND_COLOR } = options;
9873
- const originalStage = this.instance.getStage();
9874
- const stage = originalStage.clone();
9875
- const mainLayer = stage.findOne("#mainLayer");
9876
- if (!mainLayer) throw new Error("Main layer not found");
9877
- const selectionLayer = stage.findOne(`#${WEAVE_NODES_SELECTION_LAYER_ID}`);
9878
- selectionLayer?.destroy();
9879
- const gridLayer = stage.findOne(`#${WEAVE_GRID_LAYER_ID}`);
9880
- gridLayer?.destroy();
9898
+ const { format = WEAVE_EXPORT_FORMATS.PNG } = options;
9899
+ const { stage, mainLayer, originalScale: { scaleX, scaleY } } = this.cloneStageForExport();
9881
9900
  if (mainLayer) {
9882
- const bounds = getExportBoundingBox(boundingNodes(nodes));
9883
- const scaleX = originalStage.scaleX();
9884
- const scaleY = originalStage.scaleY();
9885
- const unscaledBounds = {
9886
- x: bounds.x / scaleX,
9887
- y: bounds.y / scaleY,
9888
- width: bounds.width / scaleX,
9889
- height: bounds.height / scaleY
9890
- };
9891
- const exportGroup = new Konva.Group();
9892
- const background = new Konva.Rect({
9893
- x: unscaledBounds.x - padding,
9894
- y: unscaledBounds.y - padding,
9895
- width: unscaledBounds.width + 2 * padding,
9896
- height: unscaledBounds.height + 2 * padding,
9897
- strokeWidth: 0,
9898
- fill: backgroundColor
9901
+ const { pixelRatio: finalPixelRatio, backgroundRect, exportGroup } = this.setupForExport({
9902
+ nodes,
9903
+ bounds: getExportBoundingBox(boundingNodes(nodes)),
9904
+ stage,
9905
+ mainLayer,
9906
+ scaleX,
9907
+ scaleY,
9908
+ options,
9909
+ exportArea: false
9899
9910
  });
9900
- exportGroup.add(background);
9901
- for (const node of nodes) {
9902
- const clonedNode = node.clone({ id: v4_default() });
9903
- const absPos = node.getAbsolutePosition();
9904
- clonedNode.absolutePosition({
9905
- x: absPos.x / scaleX,
9906
- y: absPos.y / scaleY
9907
- });
9908
- exportGroup.add(clonedNode);
9909
- }
9910
- mainLayer.add(exportGroup);
9911
- const backgroundRect = background.getClientRect();
9912
- stage.batchDraw();
9913
- const { pixelRatio: finalPixelRatio } = this.fitKonvaPixelRatio(Math.round(backgroundRect.width), Math.round(backgroundRect.height), pixelRatio);
9914
9911
  exportGroup.toBlob({
9915
9912
  x: Math.round(backgroundRect.x),
9916
9913
  y: Math.round(backgroundRect.y),
@@ -9934,52 +9931,19 @@ var WeaveExportManager = class {
9934
9931
  }
9935
9932
  exportNodesAsCanvas(nodes, boundingNodes, options) {
9936
9933
  return new Promise((resolve) => {
9937
- const { format = WEAVE_EXPORT_FORMATS.PNG, padding = 0, pixelRatio = 1, backgroundColor = WEAVE_EXPORT_BACKGROUND_COLOR } = options;
9938
- const originalStage = this.instance.getStage();
9939
- const stage = originalStage.clone();
9940
- const mainLayer = stage.findOne("#mainLayer");
9941
- if (!mainLayer) throw new Error("Main layer not found");
9942
- const selectionLayer = stage.findOne(`#${WEAVE_NODES_SELECTION_LAYER_ID}`);
9943
- selectionLayer?.destroy();
9944
- const gridLayer = stage.findOne(`#${WEAVE_GRID_LAYER_ID}`);
9945
- gridLayer?.destroy();
9946
- stage.scale({
9947
- x: 1,
9948
- y: 1
9949
- });
9934
+ const { format = WEAVE_EXPORT_FORMATS.PNG } = options;
9935
+ const { stage, mainLayer, originalScale: { scaleX, scaleY } } = this.cloneStageForExport();
9950
9936
  if (mainLayer) {
9951
- const bounds = getExportBoundingBox(boundingNodes(nodes));
9952
- const scaleX = originalStage.scaleX();
9953
- const scaleY = originalStage.scaleY();
9954
- const unscaledBounds = {
9955
- x: bounds.x / scaleX,
9956
- y: bounds.y / scaleY,
9957
- width: bounds.width / scaleX,
9958
- height: bounds.height / scaleY
9959
- };
9960
- const exportGroup = new Konva.Group();
9961
- const background = new Konva.Rect({
9962
- x: unscaledBounds.x - padding,
9963
- y: unscaledBounds.y - padding,
9964
- width: unscaledBounds.width + 2 * padding,
9965
- height: unscaledBounds.height + 2 * padding,
9966
- strokeWidth: 0,
9967
- fill: backgroundColor
9937
+ const { pixelRatio: finalPixelRatio, backgroundRect, exportGroup } = this.setupForExport({
9938
+ nodes,
9939
+ bounds: getExportBoundingBox(boundingNodes(nodes)),
9940
+ stage,
9941
+ mainLayer,
9942
+ scaleX,
9943
+ scaleY,
9944
+ options,
9945
+ exportArea: false
9968
9946
  });
9969
- exportGroup.add(background);
9970
- for (const node of nodes) {
9971
- const clonedNode = node.clone({ id: v4_default() });
9972
- const absPos = node.getAbsolutePosition();
9973
- clonedNode.absolutePosition({
9974
- x: absPos.x / scaleX,
9975
- y: absPos.y / scaleY
9976
- });
9977
- exportGroup.add(clonedNode);
9978
- }
9979
- mainLayer.add(exportGroup);
9980
- const backgroundRect = background.getClientRect();
9981
- stage.batchDraw();
9982
- const { pixelRatio: finalPixelRatio } = this.fitKonvaPixelRatio(Math.round(backgroundRect.width), Math.round(backgroundRect.height), pixelRatio);
9983
9947
  exportGroup.toCanvas({
9984
9948
  x: Math.round(backgroundRect.x),
9985
9949
  y: Math.round(backgroundRect.y),
@@ -9999,180 +9963,99 @@ var WeaveExportManager = class {
9999
9963
  }
10000
9964
  exportAreaAsImage(area, options) {
10001
9965
  return new Promise((resolve) => {
10002
- const { format = WEAVE_EXPORT_FORMATS.PNG, padding = 0, pixelRatio = 1, backgroundColor = WEAVE_EXPORT_BACKGROUND_COLOR } = options;
10003
- const nodesSelectionPluginPrev = this.getNodesSelectionPlugin()?.isEnabled();
10004
- const nodesStageGridPluginPrev = this.getStageGridPlugin()?.isEnabled();
10005
- this.getNodesSelectionPlugin()?.disable();
10006
- this.getStageGridPlugin()?.disable();
10007
- const stage = this.instance.getStage();
10008
- const mainLayer = this.instance.getMainLayer();
10009
- if (!mainLayer) throw new Error("Main layer not found");
10010
- const originalPosition = {
10011
- x: stage.x(),
10012
- y: stage.y()
10013
- };
10014
- const originalScale = {
10015
- x: stage.scaleX(),
10016
- y: stage.scaleY()
10017
- };
10018
- stage.scale({
10019
- x: 1,
10020
- y: 1
10021
- });
10022
- stage.position({
10023
- x: 0,
10024
- y: 0
10025
- });
10026
- const bounds = area;
10027
- const background = new Konva.Rect({
10028
- x: bounds.x - padding,
10029
- y: bounds.y - padding,
10030
- width: bounds.width + 2 * padding,
10031
- height: bounds.height + 2 * padding,
10032
- strokeWidth: 0,
10033
- fill: backgroundColor
10034
- });
10035
- mainLayer.add(background);
10036
- background.moveToBottom();
10037
- stage.batchDraw();
10038
- stage.toImage({
10039
- x: area.x,
10040
- y: area.y,
10041
- width: area.width,
10042
- height: area.height,
10043
- mimeType: format,
10044
- pixelRatio,
10045
- quality: options.quality ?? 1,
10046
- callback: (img) => {
10047
- background.destroy();
10048
- stage.position(originalPosition);
10049
- stage.scale(originalScale);
10050
- stage.batchDraw();
10051
- if (nodesSelectionPluginPrev) this.getNodesSelectionPlugin()?.enable();
10052
- if (nodesStageGridPluginPrev) this.getStageGridPlugin()?.enable();
10053
- resolve(img);
10054
- }
10055
- });
9966
+ const { format = WEAVE_EXPORT_FORMATS.PNG } = options;
9967
+ const { stage, mainLayer, originalScale: { scaleX, scaleY } } = this.cloneStageForExport();
9968
+ if (mainLayer) {
9969
+ const { pixelRatio: finalPixelRatio } = this.setupForExport({
9970
+ nodes: [],
9971
+ bounds: area,
9972
+ stage,
9973
+ mainLayer,
9974
+ scaleX,
9975
+ scaleY,
9976
+ options,
9977
+ exportArea: true
9978
+ });
9979
+ stage.toImage({
9980
+ x: area.x,
9981
+ y: area.y,
9982
+ width: area.width,
9983
+ height: area.height,
9984
+ mimeType: format,
9985
+ pixelRatio: finalPixelRatio,
9986
+ quality: options.quality ?? 1,
9987
+ callback: (img) => {
9988
+ stage.destroy();
9989
+ resolve(img);
9990
+ }
9991
+ });
9992
+ }
10056
9993
  });
10057
9994
  }
10058
9995
  exportAreaAsBlob(area, options) {
10059
9996
  return new Promise((resolve) => {
10060
- const { format = WEAVE_EXPORT_FORMATS.PNG, padding = 0, pixelRatio = 1, backgroundColor = WEAVE_EXPORT_BACKGROUND_COLOR } = options;
10061
- const nodesSelectionPluginPrev = this.getNodesSelectionPlugin()?.isEnabled();
10062
- const nodesStageGridPluginPrev = this.getStageGridPlugin()?.isEnabled();
10063
- this.getNodesSelectionPlugin()?.disable();
10064
- this.getStageGridPlugin()?.disable();
10065
- const stage = this.instance.getStage();
10066
- const mainLayer = this.instance.getMainLayer();
10067
- if (!mainLayer) throw new Error("Main layer not found");
10068
- const originalPosition = {
10069
- x: stage.x(),
10070
- y: stage.y()
10071
- };
10072
- const originalScale = {
10073
- x: stage.scaleX(),
10074
- y: stage.scaleY()
10075
- };
10076
- stage.scale({
10077
- x: 1,
10078
- y: 1
10079
- });
10080
- stage.position({
10081
- x: 0,
10082
- y: 0
10083
- });
10084
- const bounds = area;
10085
- const background = new Konva.Rect({
10086
- x: bounds.x - padding,
10087
- y: bounds.y - padding,
10088
- width: bounds.width + 2 * padding,
10089
- height: bounds.height + 2 * padding,
10090
- strokeWidth: 0,
10091
- fill: backgroundColor
10092
- });
10093
- mainLayer.add(background);
10094
- background.moveToBottom();
10095
- stage.batchDraw();
10096
- stage.toBlob({
10097
- x: area.x,
10098
- y: area.y,
10099
- width: area.width,
10100
- height: area.height,
10101
- mimeType: format,
10102
- pixelRatio,
10103
- quality: options.quality ?? 1,
10104
- callback: (blob) => {
10105
- background.destroy();
10106
- stage.position(originalPosition);
10107
- stage.scale(originalScale);
10108
- stage.batchDraw();
10109
- if (nodesSelectionPluginPrev) this.getNodesSelectionPlugin()?.enable();
10110
- if (nodesStageGridPluginPrev) this.getStageGridPlugin()?.enable();
10111
- if (!blob) {
10112
- (0, import_reject.default)(new Error("Failed to generate image blob"));
10113
- return;
9997
+ const { format = WEAVE_EXPORT_FORMATS.PNG } = options;
9998
+ const { stage, mainLayer, originalScale: { scaleX, scaleY } } = this.cloneStageForExport();
9999
+ if (mainLayer) {
10000
+ const { pixelRatio: finalPixelRatio } = this.setupForExport({
10001
+ nodes: [],
10002
+ bounds: area,
10003
+ stage,
10004
+ mainLayer,
10005
+ scaleX,
10006
+ scaleY,
10007
+ options,
10008
+ exportArea: true
10009
+ });
10010
+ stage.toBlob({
10011
+ x: area.x,
10012
+ y: area.y,
10013
+ width: area.width,
10014
+ height: area.height,
10015
+ mimeType: format,
10016
+ pixelRatio: finalPixelRatio,
10017
+ quality: options.quality ?? 1,
10018
+ callback: (blob) => {
10019
+ stage.destroy();
10020
+ if (!blob) {
10021
+ (0, import_reject.default)(new Error("Failed to generate image blob"));
10022
+ return;
10023
+ }
10024
+ resolve(blob);
10114
10025
  }
10115
- resolve(blob);
10116
- }
10117
- });
10026
+ });
10027
+ }
10118
10028
  });
10119
10029
  }
10120
10030
  exportAreaAsCanvas(area, options) {
10121
10031
  return new Promise((resolve) => {
10122
- const { format = WEAVE_EXPORT_FORMATS.PNG, padding = 0, pixelRatio = 1, backgroundColor = WEAVE_EXPORT_BACKGROUND_COLOR } = options;
10123
- const nodesSelectionPluginPrev = this.getNodesSelectionPlugin()?.isEnabled();
10124
- const nodesStageGridPluginPrev = this.getStageGridPlugin()?.isEnabled();
10125
- this.getNodesSelectionPlugin()?.disable();
10126
- this.getStageGridPlugin()?.disable();
10127
- const stage = this.instance.getStage();
10128
- const mainLayer = this.instance.getMainLayer();
10129
- if (!mainLayer) throw new Error("Main layer not found");
10130
- const originalPosition = {
10131
- x: stage.x(),
10132
- y: stage.y()
10133
- };
10134
- const originalScale = {
10135
- x: stage.scaleX(),
10136
- y: stage.scaleY()
10137
- };
10138
- stage.scale({
10139
- x: 1,
10140
- y: 1
10141
- });
10142
- stage.position({
10143
- x: 0,
10144
- y: 0
10145
- });
10146
- const bounds = area;
10147
- const background = new Konva.Rect({
10148
- x: bounds.x - padding,
10149
- y: bounds.y - padding,
10150
- width: bounds.width + 2 * padding,
10151
- height: bounds.height + 2 * padding,
10152
- strokeWidth: 0,
10153
- fill: backgroundColor
10154
- });
10155
- mainLayer.add(background);
10156
- background.moveToBottom();
10157
- stage.batchDraw();
10158
- stage.toCanvas({
10159
- x: area.x,
10160
- y: area.y,
10161
- width: area.width,
10162
- height: area.height,
10163
- mimeType: format,
10164
- pixelRatio,
10165
- quality: options.quality ?? 1,
10166
- callback: (canvas) => {
10167
- background.destroy();
10168
- stage.position(originalPosition);
10169
- stage.scale(originalScale);
10170
- stage.batchDraw();
10171
- if (nodesSelectionPluginPrev) this.getNodesSelectionPlugin()?.enable();
10172
- if (nodesStageGridPluginPrev) this.getStageGridPlugin()?.enable();
10173
- resolve(canvas);
10174
- }
10175
- });
10032
+ const { format = WEAVE_EXPORT_FORMATS.PNG } = options;
10033
+ const { stage, mainLayer, originalScale: { scaleX, scaleY } } = this.cloneStageForExport();
10034
+ if (mainLayer) {
10035
+ const { pixelRatio: finalPixelRatio } = this.setupForExport({
10036
+ nodes: [],
10037
+ bounds: area,
10038
+ stage,
10039
+ mainLayer,
10040
+ scaleX,
10041
+ scaleY,
10042
+ options,
10043
+ exportArea: true
10044
+ });
10045
+ stage.toCanvas({
10046
+ x: area.x,
10047
+ y: area.y,
10048
+ width: area.width,
10049
+ height: area.height,
10050
+ mimeType: format,
10051
+ pixelRatio: finalPixelRatio,
10052
+ quality: options.quality ?? 1,
10053
+ callback: (canvas) => {
10054
+ stage.destroy();
10055
+ resolve(canvas);
10056
+ }
10057
+ });
10058
+ }
10176
10059
  });
10177
10060
  }
10178
10061
  async exportNodesServerSide(nodes, boundingNodes, options) {