@qrvey/utils 1.15.0-8 → 1.15.0

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 (141) hide show
  1. package/dist/cjs/columns/constants/COLUMN_ICON.js +32 -32
  2. package/dist/cjs/columns/helpers/index.d.ts +1 -0
  3. package/dist/cjs/columns/helpers/index.js +1 -0
  4. package/dist/cjs/columns/helpers/isNumericalColumn.d.ts +1 -1
  5. package/dist/cjs/columns/helpers/isNumericalColumn.js +1 -1
  6. package/dist/cjs/columns/helpers/isStringColumn.d.ts +7 -0
  7. package/dist/cjs/columns/helpers/isStringColumn.js +19 -0
  8. package/dist/cjs/dates/relative/RelativeStatementAdapter.js +2 -1
  9. package/dist/cjs/elements/helpers/fixed.d.ts +96 -0
  10. package/dist/cjs/elements/helpers/fixed.js +248 -0
  11. package/dist/cjs/elements/helpers/gridStrategy.d.ts +29 -0
  12. package/dist/cjs/elements/helpers/gridStrategy.js +83 -0
  13. package/dist/cjs/elements/helpers/index.d.ts +3 -0
  14. package/dist/cjs/elements/helpers/index.js +22 -0
  15. package/dist/cjs/elements/helpers/responsive.d.ts +87 -0
  16. package/dist/cjs/elements/helpers/responsive.js +166 -0
  17. package/dist/cjs/elements/index.d.ts +2 -0
  18. package/dist/cjs/elements/index.js +18 -0
  19. package/dist/cjs/elements/interfaces/ICanvasGrid.d.ts +5 -0
  20. package/dist/cjs/elements/interfaces/ICanvasGrid.js +9 -0
  21. package/dist/cjs/elements/interfaces/IFixedPosition.d.ts +5 -0
  22. package/dist/cjs/elements/interfaces/IFixedPosition.js +2 -0
  23. package/dist/cjs/elements/interfaces/IVemCore.d.ts +29 -0
  24. package/dist/cjs/elements/interfaces/IVemCore.js +3 -0
  25. package/dist/cjs/elements/interfaces/IVemPosition.d.ts +44 -0
  26. package/dist/cjs/elements/interfaces/IVemPosition.js +8 -0
  27. package/dist/cjs/elements/interfaces/index.d.ts +4 -0
  28. package/dist/cjs/elements/interfaces/index.js +20 -0
  29. package/dist/cjs/elements/utils/element.d.ts +4 -0
  30. package/dist/cjs/elements/utils/element.js +28 -0
  31. package/dist/cjs/elements/utils/fixed.position.d.ts +12 -0
  32. package/dist/cjs/elements/utils/fixed.position.js +86 -0
  33. package/dist/cjs/elements/utils/general.d.ts +15 -0
  34. package/dist/cjs/elements/utils/general.js +20 -0
  35. package/dist/cjs/elements/utils/overlap.d.ts +63 -0
  36. package/dist/cjs/elements/utils/overlap.js +99 -0
  37. package/dist/cjs/elements/utils/position.d.ts +4 -0
  38. package/dist/cjs/elements/utils/position.js +5 -0
  39. package/dist/cjs/filters/adapters/FDToLogic.js +2 -1
  40. package/dist/cjs/filters/helpers/backend/buildExpression.js +1 -0
  41. package/dist/cjs/filters/helpers/backend/buildFilters.d.ts +5 -0
  42. package/dist/cjs/filters/helpers/backend/buildFilters.js +23 -1
  43. package/dist/cjs/filters/helpers/backend/getBackendValues.js +4 -1
  44. package/dist/cjs/filters/helpers/getAvailableScopesIDsByConfig.js +1 -0
  45. package/dist/cjs/filters/helpers/settings/getFilterSettings.js +1 -1
  46. package/dist/cjs/filters/interfaces/backend/IFBExpression.js +0 -1
  47. package/dist/cjs/general/array/getUniqueSimpleArray.d.ts +6 -0
  48. package/dist/cjs/general/array/getUniqueSimpleArray.js +14 -0
  49. package/dist/cjs/general/array/index.d.ts +1 -0
  50. package/dist/cjs/general/array/index.js +1 -0
  51. package/dist/cjs/general/string/index.d.ts +4 -0
  52. package/dist/cjs/general/string/index.js +4 -0
  53. package/dist/cjs/general/string/secureHTML.d.ts +8 -0
  54. package/dist/cjs/general/string/secureHTML.js +13 -0
  55. package/dist/cjs/general/string/strategies/XSSEstrictedSanitizer.d.ts +8 -0
  56. package/dist/cjs/general/string/strategies/XSSEstrictedSanitizer.js +23 -0
  57. package/dist/cjs/general/string/strategies/XSSSanitizer.d.ts +8 -0
  58. package/dist/cjs/general/string/strategies/XSSSanitizer.js +19 -0
  59. package/dist/cjs/general/string/urlValidator.d.ts +10 -0
  60. package/dist/cjs/general/string/urlValidator.js +38 -0
  61. package/dist/cjs/globalization/interfaces/chart_builder/II18nChartBuilderSorting.d.ts +2 -0
  62. package/dist/cjs/globalization/interfaces/export/II18nExportingModal.d.ts +6 -0
  63. package/dist/cjs/globalization/interfaces/export/II18nExportingModalApplyButtonLabel.d.ts +1 -0
  64. package/dist/cjs/globalization/labels/chart_builder/I18N_CHART_BUILDER_GENERAL_OPTIONS.js +2 -0
  65. package/dist/cjs/globalization/labels/export/I18N_EXPORT_MODAL.js +10 -1
  66. package/dist/cjs/index.d.ts +1 -0
  67. package/dist/cjs/index.js +1 -0
  68. package/dist/cjs/interfaces/SatinizerStrategy.d.ts +3 -0
  69. package/dist/cjs/interfaces/SatinizerStrategy.js +2 -0
  70. package/dist/cjs/themes/constants/AUTOMATIC_GLOBAL_CSS_VARIABLES_FOR_LIGHT.js +3 -3
  71. package/dist/columns/constants/COLUMN_ICON.js +32 -32
  72. package/dist/columns/helpers/index.d.ts +1 -0
  73. package/dist/columns/helpers/index.js +1 -0
  74. package/dist/columns/helpers/isNumericalColumn.d.ts +1 -1
  75. package/dist/columns/helpers/isNumericalColumn.js +1 -1
  76. package/dist/columns/helpers/isStringColumn.d.ts +7 -0
  77. package/dist/columns/helpers/isStringColumn.js +15 -0
  78. package/dist/dates/relative/RelativeStatementAdapter.js +2 -1
  79. package/dist/elements/helpers/fixed.d.ts +96 -0
  80. package/dist/elements/helpers/fixed.js +236 -0
  81. package/dist/elements/helpers/gridStrategy.d.ts +29 -0
  82. package/dist/elements/helpers/gridStrategy.js +78 -0
  83. package/dist/elements/helpers/index.d.ts +3 -0
  84. package/dist/elements/helpers/index.js +3 -0
  85. package/dist/elements/helpers/responsive.d.ts +87 -0
  86. package/dist/elements/helpers/responsive.js +155 -0
  87. package/dist/elements/index.d.ts +2 -0
  88. package/dist/elements/index.js +2 -0
  89. package/dist/elements/interfaces/ICanvasGrid.d.ts +5 -0
  90. package/dist/elements/interfaces/ICanvasGrid.js +6 -0
  91. package/dist/elements/interfaces/IFixedPosition.d.ts +5 -0
  92. package/dist/elements/interfaces/IFixedPosition.js +1 -0
  93. package/dist/elements/interfaces/IVemCore.d.ts +29 -0
  94. package/dist/elements/interfaces/IVemCore.js +1 -0
  95. package/dist/elements/interfaces/IVemPosition.d.ts +44 -0
  96. package/dist/elements/interfaces/IVemPosition.js +5 -0
  97. package/dist/elements/interfaces/index.d.ts +4 -0
  98. package/dist/elements/interfaces/index.js +4 -0
  99. package/dist/elements/utils/element.d.ts +4 -0
  100. package/dist/elements/utils/element.js +24 -0
  101. package/dist/elements/utils/fixed.position.d.ts +12 -0
  102. package/dist/elements/utils/fixed.position.js +72 -0
  103. package/dist/elements/utils/general.d.ts +15 -0
  104. package/dist/elements/utils/general.js +16 -0
  105. package/dist/elements/utils/overlap.d.ts +63 -0
  106. package/dist/elements/utils/overlap.js +95 -0
  107. package/dist/elements/utils/position.d.ts +4 -0
  108. package/dist/elements/utils/position.js +1 -0
  109. package/dist/filters/adapters/FDToLogic.js +2 -1
  110. package/dist/filters/helpers/backend/buildExpression.js +1 -0
  111. package/dist/filters/helpers/backend/buildFilters.d.ts +5 -0
  112. package/dist/filters/helpers/backend/buildFilters.js +23 -1
  113. package/dist/filters/helpers/backend/getBackendValues.js +4 -1
  114. package/dist/filters/helpers/getAvailableScopesIDsByConfig.js +1 -0
  115. package/dist/filters/helpers/settings/getFilterSettings.js +1 -1
  116. package/dist/filters/interfaces/backend/IFBExpression.js +0 -1
  117. package/dist/general/array/getUniqueSimpleArray.d.ts +6 -0
  118. package/dist/general/array/getUniqueSimpleArray.js +10 -0
  119. package/dist/general/array/index.d.ts +1 -0
  120. package/dist/general/array/index.js +1 -0
  121. package/dist/general/string/index.d.ts +4 -0
  122. package/dist/general/string/index.js +4 -0
  123. package/dist/general/string/secureHTML.d.ts +8 -0
  124. package/dist/general/string/secureHTML.js +9 -0
  125. package/dist/general/string/strategies/XSSEstrictedSanitizer.d.ts +8 -0
  126. package/dist/general/string/strategies/XSSEstrictedSanitizer.js +19 -0
  127. package/dist/general/string/strategies/XSSSanitizer.d.ts +8 -0
  128. package/dist/general/string/strategies/XSSSanitizer.js +15 -0
  129. package/dist/general/string/urlValidator.d.ts +10 -0
  130. package/dist/general/string/urlValidator.js +34 -0
  131. package/dist/globalization/interfaces/chart_builder/II18nChartBuilderSorting.d.ts +2 -0
  132. package/dist/globalization/interfaces/export/II18nExportingModal.d.ts +6 -0
  133. package/dist/globalization/interfaces/export/II18nExportingModalApplyButtonLabel.d.ts +1 -0
  134. package/dist/globalization/labels/chart_builder/I18N_CHART_BUILDER_GENERAL_OPTIONS.js +2 -0
  135. package/dist/globalization/labels/export/I18N_EXPORT_MODAL.js +10 -1
  136. package/dist/index.d.ts +1 -0
  137. package/dist/index.js +1 -0
  138. package/dist/interfaces/SatinizerStrategy.d.ts +3 -0
  139. package/dist/interfaces/SatinizerStrategy.js +1 -0
  140. package/dist/themes/constants/AUTOMATIC_GLOBAL_CSS_VARIABLES_FOR_LIGHT.js +3 -3
  141. package/package.json +3 -2
@@ -3,36 +3,36 @@ import { COMPLEX_COLUMN } from "./COMPLEX_COLUMN";
3
3
  import { COMPOUND_COLUMN } from "./COMPOUND_COLUMN";
4
4
  import { NUMERICAL_COLUMN } from "./NUMERICAL_COLUMN";
5
5
  export const COLUMN_ICON = {
6
- [NUMERICAL_COLUMN.RATING]: "q-icon-star",
7
- [COMPLEX_COLUMN.TEXTFIELD]: "q-icon-short-text",
8
- [COMPLEX_COLUMN.LONGTEXT]: "q-icon-long-text",
9
- [COLUMN.TEXT_LABEL]: "q-icon-text-left",
10
- [COLUMN.TEXT_CATEGORY]: "q-icon-text-left",
11
- [COLUMN.YES_NO]: "q-icon-yes-no",
12
- [COLUMN.RANKING]: "q-icon-ranking",
13
- [COLUMN.DATE]: "q-icon-date",
14
- [COLUMN.TIME]: "q-icon-time",
15
- [NUMERICAL_COLUMN.SLIDEBAR]: "q-icon-slidebar",
16
- [COMPLEX_COLUMN.IMAGEUPLOAD]: "q-icon-image-upload",
17
- [COLUMN.SIGNATURE]: "q-icon-signature",
18
- [COMPLEX_COLUMN.EXPRESSION]: "q-icon-expression",
19
- [NUMERICAL_COLUMN.NUMERIC]: "q-icon-numeric",
20
- [COLUMN.IMAGE]: "q-icon-image",
21
- [COMPOUND_COLUMN.NAME]: "q-icon-name",
22
- [COLUMN.EMAIL_FORM]: "q-icon-email",
23
- [COLUMN.PHONE]: "q-icon-phone",
24
- [COMPOUND_COLUMN.USADDRESS]: "q-icon-us-address",
25
- [COMPOUND_COLUMN.ADDRESS]: "q-icon-address",
26
- [COLUMN.PASSWORD]: "q-icon-password",
27
- [COLUMN.DROPDOWN]: "q-icon-dropdown",
28
- [COLUMN.LOOKUP]: "q-icon-Lookup",
29
- [COLUMN.SINGLE_CHOICE]: "q-icon-multiple-choice",
30
- [COLUMN.MULTIPLE_CHOICE]: "q-icon-multiple-choice",
31
- [COLUMN.BUCKET]: "q-icon-bucket",
32
- [COLUMN.FORMULA]: "q-icon-formula",
33
- [COLUMN.TEXT_FORMULA]: "q-icon-formula",
34
- [COLUMN.DATE_FORMULA]: "q-icon-formula",
35
- [COLUMN.NUMERIC_FORMULA]: "q-icon-formula",
36
- [COMPLEX_COLUMN.FILEUPLOAD]: "q-icon-file_upload",
37
- [COLUMN.AGGREGATED_FORMULA]: "q-icon-an-aggcb",
6
+ [NUMERICAL_COLUMN.RATING]: "new-q-icon-wf-rating",
7
+ [COMPLEX_COLUMN.TEXTFIELD]: "new-q-icon-wf-short-text",
8
+ [COMPLEX_COLUMN.LONGTEXT]: "new-q-icon-wf-long-text",
9
+ [COLUMN.TEXT_LABEL]: "new-q-icon-qv-justify-left",
10
+ [COLUMN.TEXT_CATEGORY]: "new-q-icon-qv-justify-left",
11
+ [COLUMN.YES_NO]: "new-q-icon-wf-yes-no",
12
+ [COLUMN.RANKING]: "new-q-icon-wf-ranking",
13
+ [COLUMN.DATE]: "new-q-icon-wf-date",
14
+ [COLUMN.TIME]: "new-q-icon-wf-dt-time",
15
+ [NUMERICAL_COLUMN.SLIDEBAR]: "new-q-icon-wf-slide-bar",
16
+ [COMPLEX_COLUMN.IMAGEUPLOAD]: "new-q-icon-wf-image-upload",
17
+ [COLUMN.SIGNATURE]: "new-q-icon-wf-signature",
18
+ [COMPLEX_COLUMN.EXPRESSION]: "new-q-icon-wf-expression",
19
+ [NUMERICAL_COLUMN.NUMERIC]: "new-q-icon-wf-numeric",
20
+ [COLUMN.IMAGE]: "new-q-icon-wf-image",
21
+ [COMPOUND_COLUMN.NAME]: "new-q-icon-wf-name",
22
+ [COLUMN.EMAIL_FORM]: "new-q-icon-wf-email",
23
+ [COLUMN.PHONE]: "new-q-icon-wf-phone-number",
24
+ [COMPOUND_COLUMN.USADDRESS]: "new-q-icon-wf-us-address",
25
+ [COMPOUND_COLUMN.ADDRESS]: "new-q-icon-wf-address",
26
+ [COLUMN.PASSWORD]: "new-q-icon-wf-password",
27
+ [COLUMN.DROPDOWN]: "new-q-icon-wf-dropdown",
28
+ [COLUMN.LOOKUP]: "new-q-icon-wf-lookup",
29
+ [COLUMN.SINGLE_CHOICE]: "new-q-icon-wf-multiple-choice",
30
+ [COLUMN.MULTIPLE_CHOICE]: "new-q-icon-wf-multiple-choice",
31
+ [COLUMN.BUCKET]: "new-q-icon-an-buckets",
32
+ [COLUMN.FORMULA]: "new-q-icon-an-formula",
33
+ [COLUMN.TEXT_FORMULA]: "new-q-icon-an-formula",
34
+ [COLUMN.DATE_FORMULA]: "new-q-icon-an-formula",
35
+ [COLUMN.NUMERIC_FORMULA]: "new-q-icon-an-formula",
36
+ [COMPLEX_COLUMN.FILEUPLOAD]: "new-q-icon-wf-file-upload",
37
+ [COLUMN.AGGREGATED_FORMULA]: "new-q-icon-wf-dt-array-aggregate",
38
38
  };
@@ -6,3 +6,4 @@ export * from "./isComplexColumn";
6
6
  export * from "./isCompoundColumn";
7
7
  export * from "./isDateColumn";
8
8
  export * from "./isNumericalColumn";
9
+ export * from "./isStringColumn";
@@ -6,3 +6,4 @@ export * from "./isComplexColumn";
6
6
  export * from "./isCompoundColumn";
7
7
  export * from "./isDateColumn";
8
8
  export * from "./isNumericalColumn";
9
+ export * from "./isStringColumn";
@@ -1,7 +1,7 @@
1
1
  import { IColumn } from "../interfaces/IColumn";
2
2
  /**
3
3
  * Validates if the given column is numerical type
4
- * @param {IColumn} column the column info
4
+ * @param column the column info
5
5
  * @returns true: the column is numerical type
6
6
  */
7
7
  export declare const isNumericalColumn: (column: IColumn) => boolean;
@@ -5,7 +5,7 @@ import { COLUMN } from "../constants/COLUMN";
5
5
  import { NUMERICAL_COLUMNS } from "../constants/NUMERICAL_COLUMNS";
6
6
  /**
7
7
  * Validates if the given column is numerical type
8
- * @param {IColumn} column the column info
8
+ * @param column the column info
9
9
  * @returns true: the column is numerical type
10
10
  */
11
11
  export const isNumericalColumn = (column) => !isEmpty(column) &&
@@ -0,0 +1,7 @@
1
+ import { IColumn } from "../interfaces/IColumn";
2
+ /**
3
+ * Validates if the given column is text type
4
+ * @param column the column info
5
+ * @returns true: the column is numerical type
6
+ */
7
+ export declare const isStringColumn: (column: IColumn) => boolean;
@@ -0,0 +1,15 @@
1
+ import { FORMULA } from "../../formulas/constants/FORMULA";
2
+ import { isEmpty } from "../../general/mix/isEmpty";
3
+ import { isObject } from "../../general/object/isObject";
4
+ import { COLUMN } from "../constants/COLUMN";
5
+ /**
6
+ * Validates if the given column is text type
7
+ * @param column the column info
8
+ * @returns true: the column is numerical type
9
+ */
10
+ export const isStringColumn = (column) => !isEmpty(column) &&
11
+ isObject(column) &&
12
+ ([COLUMN.TEXT_LABEL, COLUMN.LONGTEXT, COLUMN.TEXT_FORMULA].includes(column.type) ||
13
+ (column.type === COLUMN.FORMULA && column.formulaType === FORMULA.TEXT) ||
14
+ (column.type === COLUMN.AGGREGATED_FORMULA &&
15
+ column.formulaType === FORMULA.TEXT));
@@ -6,6 +6,7 @@ import { getStatementCase } from "./helpers/getStatementCase";
6
6
  import { DATE_GROUPING_PROPERTY } from "../constants/DATE_GROUPING_PROPERTY";
7
7
  import { parseDate } from "./helpers/parseDate";
8
8
  import { DATETIME_FORMAT } from "./constants/DATE_FORMATS";
9
+ import { isEmpty } from "../../general";
9
10
  export class RelativeStatementAdapter {
10
11
  constructor(statement, now = new Date()) {
11
12
  this.statement =
@@ -19,7 +20,7 @@ export class RelativeStatementAdapter {
19
20
  return this.get("unit");
20
21
  }
21
22
  get anchor() {
22
- return this.get("anchor");
23
+ return isEmpty(this.get("anchor")) ? undefined : this.get("anchor");
23
24
  }
24
25
  get number() {
25
26
  return this.get("number");
@@ -0,0 +1,96 @@
1
+ import { CanvasDevice } from "../interfaces/ICanvasGrid";
2
+ import { FindAvailablePositionOptions } from "../interfaces/IFixedPosition";
3
+ import { VemFixed } from "../interfaces/IVemCore";
4
+ import { VemPositionFixed } from "../interfaces/IVemPosition";
5
+ /**
6
+ * update the position for a specific device
7
+ * @param element element to be updated
8
+ * @param newDevicePosition new position attributes for the element
9
+ * @param device device for the update
10
+ * @returns new element with its position updated
11
+ */
12
+ export declare function updateFixedPosition(element: VemFixed, newDevicePosition: Partial<VemPositionFixed>, device: CanvasDevice): VemFixed;
13
+ /**
14
+ * Finds the first available position within a canvas where a new element can be placed without overlapping existing elements.
15
+ * @param canvasWidth - The width of the canvas in pixels.
16
+ * @param newElement - The new element to be placed, with fixed position properties.
17
+ * @param elements - The list of existing elements on the canvas.
18
+ * @param device - The device type (e.g., desktop, tablet, mobile) for determining element positions.
19
+ * @param [options] - Additional options for position finding.
20
+ * @param [options.canvasHeight] - The maximum height of the canvas in pixels. Defaults to `Infinity`.
21
+ * @param [options.findRightToLeft] - Whether to search for positions from right to left. Defaults to `false`.
22
+ * @param [options.initialY] - The initial Y-coordinate to start the search. Defaults to `0`.
23
+ * @returns - The x and y coordinates of the first available position.
24
+ * @throws {Error} - Throws an error if no valid position is found and `canvasHeight` is not specified.
25
+ */
26
+ export declare function findAvailablePosition(canvasWidth: number, newElement: VemFixed, elements: VemFixed[], device: CanvasDevice, options?: FindAvailablePositionOptions): {
27
+ x: number;
28
+ y: number;
29
+ };
30
+ export declare const getFixedPositionByDevice: (item: VemFixed, device: CanvasDevice) => VemPositionFixed | undefined;
31
+ /**
32
+ * Finds available positions for multiple new elements within a canvas, ensuring they do not overlap with existing elements.
33
+ * @param canvasWidth - The width of the canvas in pixels.
34
+ * @param newElements - The list of new elements to be positioned, each with fixed position properties.
35
+ * @param elements - The list of existing elements on the canvas.
36
+ * @param device - The device type (e.g., desktop, tablet, mobile) for determining element positions.
37
+ * @param [startWithPositionY] - Whether to start the position search for each new element based on its initial Y-coordinate. Defaults to `false`.
38
+ * @param [findRightToLeft] - Whether to search for positions from right to left. Defaults to `false`.
39
+ * @param [canvasHeight] - The maximum height of the canvas in pixels. If not provided, the search height is unlimited.
40
+ * @returns List of elements with their recalculated positions.
41
+ */
42
+ export declare function findFixedAvailablePositions(canvasWidth: number, newElements: VemFixed[], elements: VemFixed[], device: CanvasDevice, startWithPositionY?: boolean, findRightToLeft?: boolean, canvasHeight?: number): VemFixed[];
43
+ /**
44
+ * Recalculates the positions of elements on the canvas, preserving the position of those
45
+ * that meet certain conditions (no overflow or overlap). Elements that do not meet these
46
+ * conditions are recalculated to find a new valid position.
47
+ * @param elements - List of elements to recalculate.
48
+ * @param device - The device on which the canvas is being rendered.
49
+ * @param resolution - The resolution of the canvas.
50
+ * @param [canvasHeight] - Optional height of the canvas.
51
+ * @returns - List of elements with their recalculated positions.
52
+ */
53
+ export declare const recalculatePreservingPositions: (elements: VemFixed[], device: CanvasDevice, resolution: number, canvasHeight?: number) => VemFixed[];
54
+ /**
55
+ * Adjusts the `width` of a fixed element to fit within the specified canvas width and updates its position.
56
+ * @param element - The fixed element to adjust.
57
+ * @param canvasWidth - The width of the canvas in grid columns.
58
+ * @param canvasDevice - The target device type (e.g., desktop, tablet, mobile).
59
+ * @returns - The updated responsive element with an adjusted `width`.
60
+ */
61
+ export declare function updateFixedElementWidth(element: VemFixed, canvasWidth: number, canvasDevice: CanvasDevice): VemFixed;
62
+ /**
63
+ * @param elements elements to calculate
64
+ * @param device current device
65
+ * @returns height
66
+ */
67
+ export declare const getFixedGridElementsBottomLimit: (elements: VemFixed[], device: CanvasDevice) => number;
68
+ /**
69
+ * Calculates distances of elements from a given reference point on the canvas device.
70
+ * @param elements - Array of `VemFixed` elements to calculate distances for.
71
+ * @param device - Canvas device providing the coordinates of the elements.
72
+ * @param referencePoint - The reference point to calculate distances from.
73
+ * @param referencePoint.x
74
+ * @param referencePoint.y
75
+ * @returns An array of objects containing the original elements and their calculated distances from the reference point.
76
+ */
77
+ export declare const calculateDistancesToReferencePoint: (elements: VemFixed[], device: CanvasDevice, referencePoint: {
78
+ x: number;
79
+ y: number;
80
+ }) => {
81
+ distance: number;
82
+ element: VemFixed;
83
+ }[];
84
+ /**
85
+ * Sorts elements based on their distance from a reference point on the canvas.
86
+ * @param elements - Array of `VemFixed` elements to be sorted.
87
+ * @param device - Canvas device providing the coordinates of the elements.
88
+ * @param referencePoint - The reference point to calculate distances from.
89
+ * @param referencePoint.x
90
+ * @param referencePoint.y
91
+ * @returns An array of `VemFixed` elements sorted by their distance from the reference point (0, 0).
92
+ */
93
+ export declare const sortElementsFromReferencePoint: (elements: VemFixed<unknown>[], device: CanvasDevice, referencePoint: {
94
+ x: number;
95
+ y: number;
96
+ }) => VemFixed<unknown>[];
@@ -0,0 +1,236 @@
1
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
2
+ import { CanvasDevice } from "../interfaces/ICanvasGrid";
3
+ import { VemPositionType } from "../interfaces/IVemPosition";
4
+ import { dxGetFixedGridItemDevice, hasOverflow, hasOverlap, } from "../utils/fixed.position";
5
+ import { sortByDistanceFunction } from "../utils/general";
6
+ import { OverlapIntervalTree } from "../utils/overlap";
7
+ import { setElementPosition } from "../utils/position";
8
+ const SPACE_DELTA = 10;
9
+ /**
10
+ * update the position for a specific device
11
+ * @param element element to be updated
12
+ * @param newDevicePosition new position attributes for the element
13
+ * @param device device for the update
14
+ * @returns new element with its position updated
15
+ */
16
+ export function updateFixedPosition(element, newDevicePosition, device) {
17
+ var _a;
18
+ return Object.assign(Object.assign({}, element), { position: Object.assign(Object.assign({}, element.position), { fixed: Object.assign(Object.assign({}, element.position.fixed), { [device]: Object.assign(Object.assign({}, (_a = element.position.fixed) === null || _a === void 0 ? void 0 : _a[device]), newDevicePosition) }) }) });
19
+ }
20
+ /**
21
+ * Finds the first available position within a canvas where a new element can be placed without overlapping existing elements.
22
+ * @param canvasWidth - The width of the canvas in pixels.
23
+ * @param newElement - The new element to be placed, with fixed position properties.
24
+ * @param elements - The list of existing elements on the canvas.
25
+ * @param device - The device type (e.g., desktop, tablet, mobile) for determining element positions.
26
+ * @param [options] - Additional options for position finding.
27
+ * @param [options.canvasHeight] - The maximum height of the canvas in pixels. Defaults to `Infinity`.
28
+ * @param [options.findRightToLeft] - Whether to search for positions from right to left. Defaults to `false`.
29
+ * @param [options.initialY] - The initial Y-coordinate to start the search. Defaults to `0`.
30
+ * @returns - The x and y coordinates of the first available position.
31
+ * @throws {Error} - Throws an error if no valid position is found and `canvasHeight` is not specified.
32
+ */
33
+ export function findAvailablePosition(canvasWidth, newElement, elements, device, options = {}) {
34
+ var _a, _b;
35
+ const { width: newWidth, height: newHeight } = getFixedPositionByDevice(newElement, device);
36
+ const canvasHeight = (_a = options.canvasHeight) !== null && _a !== void 0 ? _a : Infinity;
37
+ const sortedElements = options.findRightToLeft
38
+ ? elements
39
+ .slice()
40
+ .sort((b, a) => b.position.fixed[device].x - a.position.fixed[device].x)
41
+ : elements
42
+ .slice()
43
+ .sort((a, b) => a.position.fixed[device].y - b.position.fixed[device].y);
44
+ const intervalTree = new OverlapIntervalTree();
45
+ for (const element of sortedElements) {
46
+ const elemPosition = element.position.fixed[device];
47
+ intervalTree.insert(elemPosition.x, elemPosition.x + elemPosition.width, elemPosition.y, elemPosition.y + elemPosition.height);
48
+ }
49
+ let startX = options.findRightToLeft ? canvasWidth - newWidth : 0;
50
+ const initialY = (_b = options.initialY) !== null && _b !== void 0 ? _b : 0;
51
+ let increment = options.findRightToLeft ? -SPACE_DELTA : SPACE_DELTA;
52
+ for (let y = initialY; y <= canvasHeight - newHeight; y += SPACE_DELTA) {
53
+ let x = startX;
54
+ while (x >= 0 && x <= canvasWidth - newWidth) {
55
+ if (!intervalTree.overlaps(x, x + newWidth, y, y + newHeight)) {
56
+ return { x, y };
57
+ }
58
+ x += increment;
59
+ }
60
+ if (options.findRightToLeft) {
61
+ startX = 0;
62
+ increment = SPACE_DELTA;
63
+ }
64
+ }
65
+ if (options.canvasHeight)
66
+ return { x: 0, y: 0 };
67
+ throw new Error("No valid position found");
68
+ }
69
+ export const getFixedPositionByDevice = (item, device) => {
70
+ const fixedPosition = item.position.fixed;
71
+ const devicePosition = fixedPosition[device];
72
+ return isValidPosition(devicePosition) ? devicePosition : undefined;
73
+ };
74
+ const isValidPosition = (position) => {
75
+ return ((position === null || position === void 0 ? void 0 : position.y) !== undefined &&
76
+ position.x !== undefined &&
77
+ position.z !== undefined &&
78
+ position.height !== undefined &&
79
+ position.width !== undefined);
80
+ };
81
+ /**
82
+ * Finds available positions for multiple new elements within a canvas, ensuring they do not overlap with existing elements.
83
+ * @param canvasWidth - The width of the canvas in pixels.
84
+ * @param newElements - The list of new elements to be positioned, each with fixed position properties.
85
+ * @param elements - The list of existing elements on the canvas.
86
+ * @param device - The device type (e.g., desktop, tablet, mobile) for determining element positions.
87
+ * @param [startWithPositionY] - Whether to start the position search for each new element based on its initial Y-coordinate. Defaults to `false`.
88
+ * @param [findRightToLeft] - Whether to search for positions from right to left. Defaults to `false`.
89
+ * @param [canvasHeight] - The maximum height of the canvas in pixels. If not provided, the search height is unlimited.
90
+ * @returns List of elements with their recalculated positions.
91
+ */
92
+ export function findFixedAvailablePositions(canvasWidth, newElements, elements, device, startWithPositionY = false, findRightToLeft = false, canvasHeight) {
93
+ const processedElements = elements.slice();
94
+ const resultElems = [];
95
+ newElements.forEach((nElement) => {
96
+ const initialY = startWithPositionY
97
+ ? nElement.position.fixed[device].y
98
+ : 0;
99
+ const newElement = updateFixedElementWidth(nElement, canvasWidth, device);
100
+ const availablePosition = findAvailablePosition(canvasWidth, newElement, processedElements, device, { initialY, findRightToLeft, canvasHeight });
101
+ const newElemWithPosition = updateFixedPosition(newElement, availablePosition, device);
102
+ resultElems.push(newElemWithPosition);
103
+ processedElements.push(newElemWithPosition);
104
+ });
105
+ return resultElems;
106
+ }
107
+ /**
108
+ * Recalculates the positions of elements on the canvas, preserving the position of those
109
+ * that meet certain conditions (no overflow or overlap). Elements that do not meet these
110
+ * conditions are recalculated to find a new valid position.
111
+ * @param elements - List of elements to recalculate.
112
+ * @param device - The device on which the canvas is being rendered.
113
+ * @param resolution - The resolution of the canvas.
114
+ * @param [canvasHeight] - Optional height of the canvas.
115
+ * @returns - List of elements with their recalculated positions.
116
+ */
117
+ export const recalculatePreservingPositions = (elements, device, resolution, canvasHeight) => {
118
+ const keepElementPositions = getElementsWithKeepPosition([...elements], device, resolution, canvasHeight);
119
+ const elementIds = keepElementPositions.map((element) => element.elementId);
120
+ const elementsToCalculate = elements.filter((cElement) => !elementIds.includes(cElement.elementId));
121
+ const defaultElements = keepElementPositions.length
122
+ ? keepElementPositions
123
+ : [];
124
+ const currentElements = canvasHeight ? defaultElements : elements;
125
+ const newElements = findFixedAvailablePositions(resolution, elementsToCalculate, currentElements, device, false, false, canvasHeight);
126
+ return [...keepElementPositions, ...newElements];
127
+ };
128
+ /**
129
+ * Filters elements that should retain their current position on the canvas by checking
130
+ * that they do not have overflow (spilling outside the canvas) or overlap (colliding with other elements).
131
+ * @param elements - List of elements to check.
132
+ * @param device - The device on which the canvas is being rendered.
133
+ * @param resolution - The resolution of the canvas.
134
+ * @param [canvasHeight] - Optional height of the canvas.
135
+ * @returns - List of elements that can retain their current position.
136
+ */
137
+ const getElementsWithKeepPosition = (elements, device, resolution, canvasHeight) => {
138
+ const calculatedElements = elements.map((mElement) => {
139
+ const desktopPosition = dxGetFixedGridItemDevice(mElement, CanvasDevice.DESKTOP);
140
+ return updateFixedPosition(mElement, desktopPosition, device);
141
+ });
142
+ return calculatedElements.filter((cElement) => {
143
+ const currentElements = calculatedElements.filter((fElement) => fElement.elementId !== cElement.elementId);
144
+ const overflow = hasOverflow(cElement, device, resolution, canvasHeight);
145
+ const overlap = hasOverlap(cElement, currentElements, device);
146
+ return !overflow && !overlap;
147
+ });
148
+ };
149
+ /**
150
+ * Adjusts the `width` of a fixed element to fit within the specified canvas width and updates its position.
151
+ * @param element - The fixed element to adjust.
152
+ * @param canvasWidth - The width of the canvas in grid columns.
153
+ * @param canvasDevice - The target device type (e.g., desktop, tablet, mobile).
154
+ * @returns - The updated responsive element with an adjusted `width`.
155
+ */
156
+ export function updateFixedElementWidth(element, canvasWidth, canvasDevice) {
157
+ const currentPosition = element.position.fixed[canvasDevice];
158
+ const fixedWidth = Math.min(currentPosition === null || currentPosition === void 0 ? void 0 : currentPosition.width, canvasWidth);
159
+ const position = Object.assign(Object.assign({}, currentPosition), { width: fixedWidth });
160
+ return setElementPosition(element, VemPositionType.FIXED, canvasDevice, position);
161
+ }
162
+ /**
163
+ * Retrieves the Y-coordinate of a fixed grid element for a specific device.
164
+ * If `allowNegative` is false (default), the function ensures the Y-coordinate is non-negative.
165
+ * @param element - The element to retrieve the Y-coordinate from.
166
+ * @param device - The device for which the Y-coordinate is calculated.
167
+ * @param [allowNegative] - Whether to allow negative Y-coordinates.
168
+ * @returns - The Y-coordinate of the element.
169
+ */
170
+ const getFixedGridElementY = (element, device, allowNegative = false) => {
171
+ var _a;
172
+ const position = element.position.fixed[device];
173
+ const itemY = (_a = position === null || position === void 0 ? void 0 : position.y) !== null && _a !== void 0 ? _a : 0;
174
+ if (!allowNegative) {
175
+ return itemY >= 0 ? itemY : 0;
176
+ }
177
+ return itemY;
178
+ };
179
+ /**
180
+ * Retrieves the height of a fixed grid element for a specific device.
181
+ * @param element - The element to retrieve the height from.
182
+ * @param device - The device for which the height is calculated.
183
+ * @returns - The height of the element, or undefined if not defined.
184
+ */
185
+ const getFixedGridElementHeight = (element, device) => {
186
+ const position = element.position.fixed[device];
187
+ return position === null || position === void 0 ? void 0 : position.height;
188
+ };
189
+ /**
190
+ * @param elements elements to calculate
191
+ * @param device current device
192
+ * @returns height
193
+ */
194
+ export const getFixedGridElementsBottomLimit = (elements, device) => {
195
+ if (!elements.length)
196
+ return 0;
197
+ return Math.max(...elements.map((element) => getFixedGridElementY(element, device) +
198
+ getFixedGridElementHeight(element, device)));
199
+ };
200
+ /**
201
+ * Calculates distances of elements from a given reference point on the canvas device.
202
+ * @param elements - Array of `VemFixed` elements to calculate distances for.
203
+ * @param device - Canvas device providing the coordinates of the elements.
204
+ * @param referencePoint - The reference point to calculate distances from.
205
+ * @param referencePoint.x
206
+ * @param referencePoint.y
207
+ * @returns An array of objects containing the original elements and their calculated distances from the reference point.
208
+ */
209
+ export const calculateDistancesToReferencePoint = (elements, device, referencePoint) => {
210
+ return elements.map((element) => {
211
+ const elementPosition = getFixedPositionByDevice(element, device);
212
+ if (!elementPosition) {
213
+ throw new Error(`Position for device ${device} is undefined for element with Id ${element.elementId}.`);
214
+ }
215
+ const distance = Math.pow(referencePoint.x - elementPosition.x, 2) +
216
+ Math.pow(referencePoint.y - elementPosition.y, 2);
217
+ return {
218
+ distance,
219
+ element,
220
+ };
221
+ });
222
+ };
223
+ /**
224
+ * Sorts elements based on their distance from a reference point on the canvas.
225
+ * @param elements - Array of `VemFixed` elements to be sorted.
226
+ * @param device - Canvas device providing the coordinates of the elements.
227
+ * @param referencePoint - The reference point to calculate distances from.
228
+ * @param referencePoint.x
229
+ * @param referencePoint.y
230
+ * @returns An array of `VemFixed` elements sorted by their distance from the reference point (0, 0).
231
+ */
232
+ export const sortElementsFromReferencePoint = (elements, device, referencePoint) => {
233
+ const calculatedElements = calculateDistancesToReferencePoint(elements, device, referencePoint);
234
+ const sortedElements = [...calculatedElements].sort(sortByDistanceFunction);
235
+ return sortedElements.map((element) => element.element);
236
+ };
@@ -0,0 +1,29 @@
1
+ import { CanvasDevice, Vem } from "../interfaces";
2
+ interface RecalculateOptions {
3
+ canvasHeight?: number;
4
+ sort?: CanvasDevice;
5
+ allowCopy?: boolean;
6
+ keepPosition?: boolean;
7
+ }
8
+ /**
9
+ * Recalculates the positions of elements on a canvas based on the canvas type.
10
+ * @param newElements - The list of elements to be recalculated. Each element has properties based on its type.
11
+ * @param currentElements - The list of elements to be recalculated. Each element has properties based on its type.
12
+ * @param canvasWidth - The width of the canvas in pixels.
13
+ * @param canvasType - The type of canvas (e.g., "fixed") that determines how positions are recalculated.
14
+ * @param device - The device type (e.g., desktop, tablet, mobile) for determining element positions.
15
+ * @param canvasHeight - variable for the canvas with header component
16
+ * @param options
17
+ * @returns - A list of elements with updated positions if the canvas type is "fixed" or "responsive".
18
+ */
19
+ export declare function recalculateElements(newElements: Vem[], currentElements: Vem[], canvasWidth: number, canvasType: string, device: CanvasDevice, options?: RecalculateOptions): Vem[];
20
+ /**
21
+ * The calculation is delegated to a specific strategy based on the `canvasType`.
22
+ * @param elements - The list of elements in the canvas.
23
+ * @param canvasType - The type of canvas (e.g., "fixed", "responsive").
24
+ * @param device - The target device type (e.g., desktop, tablet, mobile).
25
+ * @param [rowGap] - The optional gap (in pixels) between rows in the canvas.
26
+ * @returns - The calculated canvas height based on the selected strategy. Returns an empty array if no strategy is found.
27
+ */
28
+ export declare function calculateCanvasHeight(elements: Vem[], canvasType: string, device: CanvasDevice, rowGap?: number): number;
29
+ export {};
@@ -0,0 +1,78 @@
1
+ import { findFixedAvailablePositions, getFixedGridElementsBottomLimit, recalculatePreservingPositions, sortElementsFromReferencePoint, } from "./fixed";
2
+ import { findResponsiveAvailablePositions, getResponsiveGridElementsBottomLimit, sortResponsiveElements, } from "./responsive";
3
+ import { CanvasDevice, VemPositionType, } from "../interfaces";
4
+ import { copyDesktopPositionToDevice } from "../utils/element";
5
+ const recalculateStrategies = {
6
+ fixed: (elements, currentElements, canvasWidth, device, options) => {
7
+ const isSorted = !currentElements.length;
8
+ const changedElements = (options.allowCopy
9
+ ? copyDesktopPositionToDevice(elements, device, VemPositionType.FIXED)
10
+ : elements);
11
+ // sort elements
12
+ const orderedElements = isSorted
13
+ ? sortElementsFromReferencePoint(changedElements, options.sort, {
14
+ x: 0,
15
+ y: 0,
16
+ })
17
+ : changedElements;
18
+ return options.canvasHeight
19
+ ? recalculatePreservingPositions(orderedElements, device, canvasWidth, options.canvasHeight)
20
+ : findFixedAvailablePositions(canvasWidth, orderedElements, currentElements, device, false, false, options === null || options === void 0 ? void 0 : options.canvasHeight);
21
+ },
22
+ responsive: (elements, currentElements, canvasWidth, device, options) => {
23
+ const isSorted = !currentElements.length;
24
+ const changedElements = (options.allowCopy
25
+ ? copyDesktopPositionToDevice(elements, device, VemPositionType.RESPONSIVE)
26
+ : elements);
27
+ const orderedElements = isSorted
28
+ ? sortResponsiveElements(changedElements, options.sort)
29
+ : changedElements;
30
+ return findResponsiveAvailablePositions(canvasWidth, orderedElements, currentElements, device);
31
+ },
32
+ };
33
+ const calculateCanvasHeightStrategies = {
34
+ fixed: (elements, device) => {
35
+ return getFixedGridElementsBottomLimit(elements, device);
36
+ },
37
+ responsive: (elements, device, rowGap) => {
38
+ return getResponsiveGridElementsBottomLimit(elements, device, rowGap);
39
+ },
40
+ };
41
+ /**
42
+ * Recalculates the positions of elements on a canvas based on the canvas type.
43
+ * @param newElements - The list of elements to be recalculated. Each element has properties based on its type.
44
+ * @param currentElements - The list of elements to be recalculated. Each element has properties based on its type.
45
+ * @param canvasWidth - The width of the canvas in pixels.
46
+ * @param canvasType - The type of canvas (e.g., "fixed") that determines how positions are recalculated.
47
+ * @param device - The device type (e.g., desktop, tablet, mobile) for determining element positions.
48
+ * @param canvasHeight - variable for the canvas with header component
49
+ * @param options
50
+ * @returns - A list of elements with updated positions if the canvas type is "fixed" or "responsive".
51
+ */
52
+ export function recalculateElements(newElements, currentElements, canvasWidth, canvasType, device, options) {
53
+ const strategy = recalculateStrategies[canvasType];
54
+ if (!strategy) {
55
+ return [];
56
+ }
57
+ const defaultOptions = {
58
+ sort: CanvasDevice.DESKTOP,
59
+ allowCopy: true,
60
+ };
61
+ const calculatedOptions = Object.assign(Object.assign({}, defaultOptions), options);
62
+ return strategy(newElements, currentElements, canvasWidth, device, calculatedOptions);
63
+ }
64
+ /**
65
+ * The calculation is delegated to a specific strategy based on the `canvasType`.
66
+ * @param elements - The list of elements in the canvas.
67
+ * @param canvasType - The type of canvas (e.g., "fixed", "responsive").
68
+ * @param device - The target device type (e.g., desktop, tablet, mobile).
69
+ * @param [rowGap] - The optional gap (in pixels) between rows in the canvas.
70
+ * @returns - The calculated canvas height based on the selected strategy. Returns an empty array if no strategy is found.
71
+ */
72
+ export function calculateCanvasHeight(elements, canvasType, device, rowGap) {
73
+ const strategy = calculateCanvasHeightStrategies[canvasType];
74
+ if (!strategy) {
75
+ return 0;
76
+ }
77
+ return strategy(elements, device, rowGap);
78
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./gridStrategy";
2
+ export { updateFixedElementWidth } from "./fixed";
3
+ export { updateResponsiveElementColSpan } from "./responsive";
@@ -0,0 +1,3 @@
1
+ export * from "./gridStrategy";
2
+ export { updateFixedElementWidth } from "./fixed";
3
+ export { updateResponsiveElementColSpan } from "./responsive";