@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
@@ -0,0 +1,87 @@
1
+ import { CanvasDevice } from "../interfaces/ICanvasGrid";
2
+ import { VemResponsive } from "../interfaces/IVemCore";
3
+ import { VemPositionResponsive } from "../interfaces/IVemPosition";
4
+ /**
5
+ * Finds the first available position for a new responsive element within a canvas.
6
+ * @param canvasWidth - The width of the canvas in terms of columns.
7
+ * @param newElement - The new responsive element to place on the canvas.
8
+ * @param elements - The existing elements on the canvas.
9
+ * @param device - The target device type (e.g., desktop, tablet, mobile) to calculate responsive positions.
10
+ * @returns - The column and row start positions for the new element, or `undefined` if no valid position is found.
11
+ */
12
+ export declare function findAvailablePosition(canvasWidth: number, newElement: VemResponsive, elements: VemResponsive[], device: CanvasDevice): {
13
+ colStart: number;
14
+ rowStart: number;
15
+ } | undefined;
16
+ /**
17
+ * Updates the responsive position of a given element for a specified device.
18
+ * @param element - The responsive element to update.
19
+ * @param newPosition - The new position values to update for the element.
20
+ * @param device - The target device type (e.g., desktop, tablet, mobile) for which the position is updated.
21
+ * @returns - A new `VemResponsive` object with the updated responsive position for the specified device.
22
+ */
23
+ export declare function updateResponsivePosition(element: VemResponsive, newPosition: Partial<VemPositionResponsive>, device: CanvasDevice): VemResponsive;
24
+ /**
25
+ * Finds available positions for a list of responsive elements on a canvas and updates their positions.
26
+ * @param canvasWidth - The width of the canvas in grid columns.
27
+ * @param newElements - The list of new responsive elements to position.
28
+ * @param elements - The list of existing responsive elements already positioned on the canvas.
29
+ * @param device - The target device type (e.g., desktop, tablet, mobile) for which positions are calculated.
30
+ * @returns - A list of responsive elements with updated positions for the specified device.
31
+ */
32
+ export declare function findResponsiveAvailablePositions(canvasWidth: number, newElements: VemResponsive[], elements: VemResponsive[], device: CanvasDevice): VemResponsive[];
33
+ /**
34
+ * Adjusts the `colSpan` of a responsive element to fit within the specified canvas width and updates its position.
35
+ * @param element - The responsive element to adjust.
36
+ * @param canvasWidth - The width of the canvas in grid columns.
37
+ * @param canvasDevice - The target device type (e.g., desktop, tablet, mobile).
38
+ * @returns - The updated responsive element with an adjusted `colSpan`.
39
+ */
40
+ export declare function updateResponsiveElementColSpan(element: VemResponsive, canvasWidth: number, canvasDevice: CanvasDevice): VemResponsive;
41
+ export declare const getResponsiveGridElementsBottomLimit: (elements: VemResponsive[], device: CanvasDevice, rowGap: number) => number;
42
+ /**
43
+ * Calculates the distances of elements from a reference point and returns a list of objects
44
+ * containing the calculated distance and the corresponding element.
45
+ * @param elements - An array of `VemResponsive` objects. Each object represents an element with
46
+ * a `position` property that contains responsive positions for various devices.
47
+ * @param device - The specific device type (key of `CanvasDevice`) to determine the responsive position.
48
+ * @param referencePoint - An object representing the reference point with `x` and `y` coordinates.
49
+ * @param referencePoint.x
50
+ * @param referencePoint.y
51
+ * @returns - An array of objects, where each object contains:
52
+ * - `distance`: The squared Euclidean distance from the reference point.
53
+ * - `element`: The corresponding `VemResponsive` object.
54
+ */
55
+ export declare const calculateDistancesToReferencePoint: (elements: VemResponsive[], device: CanvasDevice, referencePoint: {
56
+ x: number;
57
+ y: number;
58
+ }) => {
59
+ distance: number;
60
+ element: VemResponsive;
61
+ }[];
62
+ /**
63
+ /**
64
+ Sorts objects containing a `distance` and `element` by distance in ascending order.
65
+ If two objects have the same distance, it resolves the tie by comparing the `colStart` property
66
+ of their responsive positions for the `DESKTOP` device.
67
+ * @param a - An object containing:
68
+ * - `distance`: The calculated distance from a reference point.
69
+ * - `element`: A `VemResponsive` object with responsive position data.
70
+ * @param b - Another object with the same structure as `a`.
71
+ * @param a.element
72
+ * @param a.distance
73
+ * @param _device - The device type (of type `CanvasDevice`). Currently unused in this function.
74
+ * @param b.distance
75
+ * @param b.element
76
+ * @returns - A negative number if `a` should come before `b`,
77
+ * a positive number if `a` should come after `b`,
78
+ * or 0 if they have the same distance and `colStart` values.
79
+ */
80
+ export declare const sortByDistanceInResponsiveFunction: (a: {
81
+ distance: number;
82
+ element: VemResponsive;
83
+ }, b: {
84
+ distance: number;
85
+ element: VemResponsive;
86
+ }, _device: CanvasDevice) => number;
87
+ export declare const sortResponsiveElements: (elements: VemResponsive<unknown>[], sortByDevice?: CanvasDevice) => VemResponsive<unknown>[];
@@ -0,0 +1,155 @@
1
+ import { CanvasDevice } from "../interfaces/ICanvasGrid";
2
+ import { VemPositionType, } from "../interfaces/IVemPosition";
3
+ import { OverlapIntervalTree } from "../utils/overlap";
4
+ import { setElementPosition } from "../utils/position";
5
+ const SPACE_DELTA = 1;
6
+ const HEIGHT_DELTA = 32;
7
+ /**
8
+ * Finds the first available position for a new responsive element within a canvas.
9
+ * @param canvasWidth - The width of the canvas in terms of columns.
10
+ * @param newElement - The new responsive element to place on the canvas.
11
+ * @param elements - The existing elements on the canvas.
12
+ * @param device - The target device type (e.g., desktop, tablet, mobile) to calculate responsive positions.
13
+ * @returns - The column and row start positions for the new element, or `undefined` if no valid position is found.
14
+ */
15
+ export function findAvailablePosition(canvasWidth, newElement, elements, device) {
16
+ const { colSpan: newWidth, rowSpan: newHeight } = newElement.position.responsive[device];
17
+ const sortedElements = elements
18
+ .slice()
19
+ .sort((a, b) => a.position.responsive[device].rowStart -
20
+ b.position.responsive[device].rowStart);
21
+ const intervalTree = new OverlapIntervalTree();
22
+ for (const element of sortedElements) {
23
+ const elemPosition = element.position.responsive[device];
24
+ const colEnd = elemPosition.colStart + (elemPosition.colSpan - 1);
25
+ const rowEnd = elemPosition.rowStart + elemPosition.rowSpan - 1;
26
+ if (!intervalTree.overlaps(elemPosition.colStart, colEnd, elemPosition.rowStart, rowEnd)) {
27
+ intervalTree.insert(elemPosition.colStart, colEnd, elemPosition.rowStart, rowEnd);
28
+ }
29
+ }
30
+ for (let rowStart = 1; rowStart <= Infinity - newHeight; rowStart += SPACE_DELTA) {
31
+ // height iteration will be until it finds a result
32
+ for (let colStart = 1; colStart <= canvasWidth - newWidth + 1; colStart += SPACE_DELTA) {
33
+ if (!intervalTree.overlaps(colStart, colStart + newWidth - 1, rowStart, rowStart + newHeight - 1)) {
34
+ const col = colStart === 0 ? 1 : colStart;
35
+ const row = rowStart === 0 ? 1 : rowStart;
36
+ return { colStart: col, rowStart: row };
37
+ }
38
+ }
39
+ }
40
+ return undefined;
41
+ }
42
+ /**
43
+ * Updates the responsive position of a given element for a specified device.
44
+ * @param element - The responsive element to update.
45
+ * @param newPosition - The new position values to update for the element.
46
+ * @param device - The target device type (e.g., desktop, tablet, mobile) for which the position is updated.
47
+ * @returns - A new `VemResponsive` object with the updated responsive position for the specified device.
48
+ */
49
+ export function updateResponsivePosition(element, newPosition, device) {
50
+ var _a;
51
+ return Object.assign(Object.assign({}, element), { position: Object.assign(Object.assign({}, element.position), { responsive: Object.assign(Object.assign({}, element.position.responsive), { [device]: Object.assign(Object.assign({}, (_a = element.position.responsive) === null || _a === void 0 ? void 0 : _a[device]), newPosition) }) }) });
52
+ }
53
+ /**
54
+ * Finds available positions for a list of responsive elements on a canvas and updates their positions.
55
+ * @param canvasWidth - The width of the canvas in grid columns.
56
+ * @param newElements - The list of new responsive elements to position.
57
+ * @param elements - The list of existing responsive elements already positioned on the canvas.
58
+ * @param device - The target device type (e.g., desktop, tablet, mobile) for which positions are calculated.
59
+ * @returns - A list of responsive elements with updated positions for the specified device.
60
+ */
61
+ export function findResponsiveAvailablePositions(canvasWidth, newElements, elements, device) {
62
+ const processedElements = elements.slice();
63
+ const resultElems = [];
64
+ newElements.forEach((nElement) => {
65
+ const newElement = updateResponsiveElementColSpan(nElement, canvasWidth, device);
66
+ const availablePosition = findAvailablePosition(canvasWidth, newElement, processedElements, device);
67
+ const newElemWithPosition = updateResponsivePosition(newElement, availablePosition, device);
68
+ resultElems.push(newElemWithPosition);
69
+ processedElements.push(newElemWithPosition);
70
+ });
71
+ return resultElems;
72
+ }
73
+ /**
74
+ * Adjusts the `colSpan` of a responsive element to fit within the specified canvas width and updates its position.
75
+ * @param element - The responsive element to adjust.
76
+ * @param canvasWidth - The width of the canvas in grid columns.
77
+ * @param canvasDevice - The target device type (e.g., desktop, tablet, mobile).
78
+ * @returns - The updated responsive element with an adjusted `colSpan`.
79
+ */
80
+ export function updateResponsiveElementColSpan(element, canvasWidth, canvasDevice) {
81
+ const currentPosition = element.position.responsive[canvasDevice];
82
+ const fixedColSpan = Math.min(currentPosition.colSpan, canvasWidth);
83
+ const position = Object.assign(Object.assign({}, currentPosition), { colSpan: fixedColSpan });
84
+ return setElementPosition(element, VemPositionType.RESPONSIVE, canvasDevice, position);
85
+ }
86
+ export const getResponsiveGridElementsBottomLimit = (elements, device, rowGap) => {
87
+ if (!elements.length)
88
+ return 0;
89
+ const mappedElements = elements.map((element) => {
90
+ const elementPosition = element.position.responsive;
91
+ const maxRows = elementPosition[device].rowStart + elementPosition[device].rowSpan;
92
+ return maxRows * HEIGHT_DELTA + (maxRows - 1) * rowGap;
93
+ });
94
+ return Math.max(...mappedElements);
95
+ };
96
+ /**
97
+ * Calculates the distances of elements from a reference point and returns a list of objects
98
+ * containing the calculated distance and the corresponding element.
99
+ * @param elements - An array of `VemResponsive` objects. Each object represents an element with
100
+ * a `position` property that contains responsive positions for various devices.
101
+ * @param device - The specific device type (key of `CanvasDevice`) to determine the responsive position.
102
+ * @param referencePoint - An object representing the reference point with `x` and `y` coordinates.
103
+ * @param referencePoint.x
104
+ * @param referencePoint.y
105
+ * @returns - An array of objects, where each object contains:
106
+ * - `distance`: The squared Euclidean distance from the reference point.
107
+ * - `element`: The corresponding `VemResponsive` object.
108
+ */
109
+ export const calculateDistancesToReferencePoint = (elements, device, referencePoint) => {
110
+ return elements.map((element) => {
111
+ var _a, _b;
112
+ const position = (_b = (_a = element.position) === null || _a === void 0 ? void 0 : _a.responsive) === null || _b === void 0 ? void 0 : _b[device];
113
+ if (!position) {
114
+ throw new Error(`Position for device ${device} is undefined for element with Id ${element.elementId}.`);
115
+ }
116
+ const distance = Math.pow(referencePoint.x - position.colStart, 2) +
117
+ Math.pow(referencePoint.y - position.rowStart, 2);
118
+ return {
119
+ distance,
120
+ element,
121
+ };
122
+ });
123
+ };
124
+ /**
125
+ /**
126
+ Sorts objects containing a `distance` and `element` by distance in ascending order.
127
+ If two objects have the same distance, it resolves the tie by comparing the `colStart` property
128
+ of their responsive positions for the `DESKTOP` device.
129
+ * @param a - An object containing:
130
+ * - `distance`: The calculated distance from a reference point.
131
+ * - `element`: A `VemResponsive` object with responsive position data.
132
+ * @param b - Another object with the same structure as `a`.
133
+ * @param a.element
134
+ * @param a.distance
135
+ * @param _device - The device type (of type `CanvasDevice`). Currently unused in this function.
136
+ * @param b.distance
137
+ * @param b.element
138
+ * @returns - A negative number if `a` should come before `b`,
139
+ * a positive number if `a` should come after `b`,
140
+ * or 0 if they have the same distance and `colStart` values.
141
+ */
142
+ export const sortByDistanceInResponsiveFunction = (a, b, _device) => {
143
+ if (a.distance === b.distance) {
144
+ return (a.element.position.responsive[CanvasDevice.DESKTOP].colStart -
145
+ b.element.position.responsive[CanvasDevice.DESKTOP].colStart);
146
+ }
147
+ return a.distance - b.distance;
148
+ };
149
+ export const sortResponsiveElements = (elements, sortByDevice) => {
150
+ const sortedElements = calculateDistancesToReferencePoint(elements, sortByDevice, {
151
+ x: 1,
152
+ y: 1,
153
+ }).sort((a, b) => sortByDistanceInResponsiveFunction(a, b, sortByDevice));
154
+ return sortedElements.map((element) => element.element);
155
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./helpers/index";
2
+ export * from "./interfaces/index";
@@ -0,0 +1,2 @@
1
+ export * from "./helpers/index";
2
+ export * from "./interfaces/index";
@@ -0,0 +1,5 @@
1
+ export declare enum CanvasDevice {
2
+ DESKTOP = "desktop",
3
+ TABLET = "tablet",
4
+ MOBILE = "mobile"
5
+ }
@@ -0,0 +1,6 @@
1
+ export var CanvasDevice;
2
+ (function (CanvasDevice) {
3
+ CanvasDevice["DESKTOP"] = "desktop";
4
+ CanvasDevice["TABLET"] = "tablet";
5
+ CanvasDevice["MOBILE"] = "mobile";
6
+ })(CanvasDevice || (CanvasDevice = {}));
@@ -0,0 +1,5 @@
1
+ export interface FindAvailablePositionOptions {
2
+ initialY?: number;
3
+ findRightToLeft?: boolean;
4
+ canvasHeight?: number;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,29 @@
1
+ import { VemPositionConfigFixed, VemPositionConfigMap, VemPositionConfigResponsive, VemPositionType } from "./IVemPosition";
2
+ interface VemBase {
3
+ elementId: string;
4
+ type: string;
5
+ contentId?: string;
6
+ }
7
+ export interface VemCorePosition {
8
+ fixed?: VemPositionConfigFixed;
9
+ responsive?: VemPositionConfigResponsive;
10
+ }
11
+ interface VemCore<TPosition extends VemPositionType | unknown, TItemData = unknown> extends VemBase {
12
+ itemData: TItemData;
13
+ /** Indicates if its a personalized Vem */
14
+ isEup?: boolean;
15
+ /** Data to be saved in the client chart when it's saved by EUP (Only applies for VemAnalytics) */
16
+ chartBody?: unknown;
17
+ /** Dashboard Actions in the element */
18
+ actions?: unknown[];
19
+ position: TPosition extends VemPositionType ? VemCorePosition & Record<TPosition, VemPositionConfigMap[TPosition]> : VemCorePosition;
20
+ }
21
+ export type Vem<T = unknown, TPosition extends VemPositionType = VemPositionType> = VemCore<TPosition, T>;
22
+ export type VemPos<TPosition extends VemPositionType> = VemCore<TPosition>;
23
+ export type VemResponsive<T = unknown> = VemCore<VemPositionType.RESPONSIVE, T>;
24
+ export type VemFixed<T = unknown> = VemCore<VemPositionType.FIXED, T>;
25
+ export interface VemElementMap<T = unknown> {
26
+ [VemPositionType.FIXED]: VemFixed<T>;
27
+ [VemPositionType.RESPONSIVE]: VemResponsive<T>;
28
+ }
29
+ export {};
@@ -0,0 +1 @@
1
+ import { VemPositionType, } from "./IVemPosition";
@@ -0,0 +1,44 @@
1
+ export interface VemSizeFixed {
2
+ width: number;
3
+ height: number;
4
+ }
5
+ export interface VemSizeResponsive {
6
+ colSpan: number;
7
+ rowSpan: number;
8
+ }
9
+ export interface VemPositionFixed extends VemSizeFixed {
10
+ x: number;
11
+ y: number;
12
+ z: number;
13
+ }
14
+ export interface VemPositionResponsive extends VemSizeResponsive {
15
+ colStart: number;
16
+ rowStart: number;
17
+ }
18
+ export type VemPosition = VemPositionFixed | VemPositionResponsive;
19
+ export interface VemPositionMap {
20
+ [VemPositionType.FIXED]: VemPositionFixed;
21
+ [VemPositionType.RESPONSIVE]: VemPositionResponsive;
22
+ }
23
+ export declare enum VemPositionType {
24
+ FIXED = "fixed",
25
+ RESPONSIVE = "responsive"
26
+ }
27
+ interface VemPositionBase<TPosition extends VemPosition> {
28
+ desktop: TPosition;
29
+ tablet?: TPosition;
30
+ mobile?: TPosition;
31
+ }
32
+ export type VemPositionConfigFixed = VemPositionBase<VemPositionFixed>;
33
+ export type VemPositionConfigResponsive = VemPositionBase<VemPositionResponsive>;
34
+ export type VemPositionConfig = VemPositionConfigFixed | VemPositionConfigResponsive;
35
+ export interface VemPositionConfigMap {
36
+ [VemPositionType.FIXED]: VemPositionConfigFixed;
37
+ [VemPositionType.RESPONSIVE]: VemPositionConfigResponsive;
38
+ }
39
+ export type VemSize = VemSizeFixed | VemSizeResponsive;
40
+ export interface VemSizeConfig {
41
+ [VemPositionType.FIXED]: VemSizeFixed;
42
+ [VemPositionType.RESPONSIVE]: VemSizeResponsive;
43
+ }
44
+ export {};
@@ -0,0 +1,5 @@
1
+ export var VemPositionType;
2
+ (function (VemPositionType) {
3
+ VemPositionType["FIXED"] = "fixed";
4
+ VemPositionType["RESPONSIVE"] = "responsive";
5
+ })(VemPositionType || (VemPositionType = {}));
@@ -0,0 +1,4 @@
1
+ export * from "./ICanvasGrid";
2
+ export * from "./IFixedPosition";
3
+ export * from "./IVemCore";
4
+ export * from "./IVemPosition";
@@ -0,0 +1,4 @@
1
+ export * from "./ICanvasGrid";
2
+ export * from "./IFixedPosition";
3
+ export * from "./IVemCore";
4
+ export * from "./IVemPosition";
@@ -0,0 +1,4 @@
1
+ import { CanvasDevice } from "../interfaces/ICanvasGrid";
2
+ import { Vem } from "../interfaces/IVemCore";
3
+ import { VemPositionType } from "../interfaces/IVemPosition";
4
+ export declare const copyDesktopPositionToDevice: (elements: Vem[], newCanvasDevice: CanvasDevice, canvasType: VemPositionType) => Vem[];
@@ -0,0 +1,24 @@
1
+ import { setElementPosition } from "./position";
2
+ import { CanvasDevice } from "../interfaces/ICanvasGrid";
3
+ import { VemPositionType, } from "../interfaces/IVemPosition";
4
+ export const copyDesktopPositionToDevice = (elements, newCanvasDevice, canvasType) => {
5
+ const defaultPositionMap = {
6
+ [VemPositionType.FIXED]: {
7
+ x: 0,
8
+ y: 0,
9
+ },
10
+ [VemPositionType.RESPONSIVE]: {
11
+ colStart: 1,
12
+ rowStart: 1,
13
+ },
14
+ };
15
+ return elements.map((element) => {
16
+ var _a;
17
+ if (!((_a = element.position[canvasType]) === null || _a === void 0 ? void 0 : _a[newCanvasDevice])) {
18
+ const desktopViewPosition = element.position[canvasType][CanvasDevice.DESKTOP];
19
+ const newDevicePosition = Object.assign(Object.assign(Object.assign({}, desktopViewPosition), defaultPositionMap[canvasType]), { preCalculated: true });
20
+ return setElementPosition(element, canvasType, newCanvasDevice, newDevicePosition);
21
+ }
22
+ return element;
23
+ });
24
+ };
@@ -0,0 +1,12 @@
1
+ import { CanvasDevice, VemFixed, VemPositionFixed } from "../interfaces";
2
+ export declare const hasOverflow: (element: VemFixed, device: CanvasDevice, resolution: number, canvasHeight?: number) => boolean;
3
+ export declare const hasOverlap: (element: VemFixed, elements: VemFixed[], device: CanvasDevice) => number;
4
+ export declare const itemXOverflow: (item: VemFixed, device: CanvasDevice, resolution: number) => boolean;
5
+ export declare const itemYOverflow: (item: VemFixed, device: CanvasDevice, canvasHeight: number) => boolean;
6
+ export declare const checkFixedGridItemsOverlap: (item: VemPositionFixed, itemToCompare: VemPositionFixed) => boolean;
7
+ export declare const dxGetFixedGridItemDevice: (element: VemFixed, device: CanvasDevice) => VemPositionFixed;
8
+ export declare const dxGetFixedGridItemX: (element: VemFixed, device: CanvasDevice, allowNegative?: boolean) => number;
9
+ export declare const dxGetFixedGridItemY: (element: VemFixed, device: CanvasDevice, allowNegative?: boolean) => number;
10
+ export declare const dxGetFixedGridItemZ: (element: VemFixed, device: CanvasDevice) => number;
11
+ export declare const dxGetFixedGridItemHeight: (element: VemFixed, device: CanvasDevice) => number;
12
+ export declare const dxGetFixedGridItemWidth: (element: VemFixed, device: CanvasDevice) => number;
@@ -0,0 +1,72 @@
1
+ export const hasOverflow = (element, device, resolution, canvasHeight) => {
2
+ const hasXOverflow = itemXOverflow(element, device, resolution);
3
+ const hasYOverflow = canvasHeight
4
+ ? itemYOverflow(element, device, canvasHeight)
5
+ : false;
6
+ return hasXOverflow || hasYOverflow;
7
+ };
8
+ export const hasOverlap = (element, elements, device) => {
9
+ const elementPosition = element.position.fixed[device];
10
+ if (!elementPosition)
11
+ return;
12
+ const overlappingElements = elements.filter((cElement) => checkFixedGridItemsOverlap(elementPosition, cElement.position.fixed[device]));
13
+ return overlappingElements.length;
14
+ };
15
+ export const itemXOverflow = (item, device, resolution) => {
16
+ const fixedPosition = item.position.fixed;
17
+ return (!!fixedPosition[device] &&
18
+ fixedPosition[device].x + fixedPosition[device].width > resolution);
19
+ };
20
+ export const itemYOverflow = (item, device, canvasHeight) => {
21
+ const fixedPosition = item.position.fixed;
22
+ return (!!fixedPosition[device] &&
23
+ fixedPosition[device].y + fixedPosition[device].height > canvasHeight);
24
+ };
25
+ export const checkFixedGridItemsOverlap = (item, itemToCompare) => {
26
+ return !(item.x + item.width < itemToCompare.x ||
27
+ item.x > itemToCompare.x + itemToCompare.width ||
28
+ item.y + item.height < itemToCompare.y ||
29
+ item.y > itemToCompare.y + itemToCompare.height);
30
+ };
31
+ export const dxGetFixedGridItemDevice = (element, device) => {
32
+ return {
33
+ x: dxGetFixedGridItemX(element, device),
34
+ y: dxGetFixedGridItemY(element, device),
35
+ z: dxGetFixedGridItemZ(element, device),
36
+ height: dxGetFixedGridItemHeight(element, device),
37
+ width: dxGetFixedGridItemWidth(element, device),
38
+ };
39
+ };
40
+ export const dxGetFixedGridItemX = (element, device, allowNegative = false) => {
41
+ var _a;
42
+ const position = element.position.fixed[device];
43
+ const itemX = (_a = position === null || position === void 0 ? void 0 : position.x) !== null && _a !== void 0 ? _a : 0;
44
+ if (!allowNegative) {
45
+ return itemX >= 0 ? itemX : 0;
46
+ }
47
+ return itemX;
48
+ };
49
+ export const dxGetFixedGridItemY = (element, device, allowNegative = false) => {
50
+ var _a;
51
+ const position = element.position.fixed[device];
52
+ const itemY = (_a = position === null || position === void 0 ? void 0 : position.y) !== null && _a !== void 0 ? _a : 0;
53
+ if (!allowNegative) {
54
+ return itemY >= 0 ? itemY : 0;
55
+ }
56
+ return itemY;
57
+ };
58
+ export const dxGetFixedGridItemZ = (element, device) => {
59
+ var _a;
60
+ const position = element.position.fixed[device];
61
+ return (_a = position === null || position === void 0 ? void 0 : position.z) !== null && _a !== void 0 ? _a : 1;
62
+ };
63
+ export const dxGetFixedGridItemHeight = (element, device) => {
64
+ var _a;
65
+ const position = element.position.fixed[device];
66
+ return (_a = position === null || position === void 0 ? void 0 : position.height) !== null && _a !== void 0 ? _a : 400;
67
+ };
68
+ export const dxGetFixedGridItemWidth = (element, device) => {
69
+ var _a;
70
+ const position = element.position.fixed[device];
71
+ return (_a = position === null || position === void 0 ? void 0 : position.width) !== null && _a !== void 0 ? _a : 400;
72
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Compares two objects based on their `distance` property and determines their relative order.
3
+ * @param a - An object with a `distance` property (number).
4
+ * @param b - Another object with a `distance` property (number).
5
+ * @param a.distance
6
+ * @param b.distance
7
+ * @returns - A negative number if `a` has a smaller distance than `b`,
8
+ * a positive number if `a` has a larger distance than `b`,
9
+ * or 0 if both have equal distances.
10
+ */
11
+ export declare const sortByDistanceFunction: (a: {
12
+ distance: number;
13
+ }, b: {
14
+ distance: number;
15
+ }) => 0 | 1 | -1;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Compares two objects based on their `distance` property and determines their relative order.
3
+ * @param a - An object with a `distance` property (number).
4
+ * @param b - Another object with a `distance` property (number).
5
+ * @param a.distance
6
+ * @param b.distance
7
+ * @returns - A negative number if `a` has a smaller distance than `b`,
8
+ * a positive number if `a` has a larger distance than `b`,
9
+ * or 0 if both have equal distances.
10
+ */
11
+ export const sortByDistanceFunction = (a, b) => {
12
+ if (a.distance === b.distance) {
13
+ return 0;
14
+ }
15
+ return a.distance < b.distance ? -1 : 1;
16
+ };
@@ -0,0 +1,63 @@
1
+ interface OverlapNode {
2
+ startX: number;
3
+ endX: number;
4
+ startY: number;
5
+ endY: number;
6
+ maxEndX: number;
7
+ maxEndY: number;
8
+ left?: OverlapNode;
9
+ right?: OverlapNode;
10
+ }
11
+ /**
12
+ *
13
+ */
14
+ export declare class OverlapIntervalTree {
15
+ root?: OverlapNode;
16
+ /**
17
+ *
18
+ */
19
+ constructor();
20
+ /**
21
+ *
22
+ * @param startX
23
+ * @param endX
24
+ * @param startY
25
+ * @param endY
26
+ */
27
+ insert(startX: number, endX: number, startY: number, endY: number): void;
28
+ /**
29
+ *
30
+ * @param startX
31
+ * @param endX
32
+ * @param startY
33
+ * @param endY
34
+ */
35
+ private _initNode;
36
+ /**
37
+ *
38
+ * @param node
39
+ * @param startX
40
+ * @param endX
41
+ * @param startY
42
+ * @param endY
43
+ */
44
+ private _insert;
45
+ /**
46
+ *
47
+ * @param startX
48
+ * @param endX
49
+ * @param startY
50
+ * @param endY
51
+ */
52
+ overlaps(startX: number, endX: number, startY: number, endY: number): boolean;
53
+ /**
54
+ *
55
+ * @param node
56
+ * @param startX
57
+ * @param endX
58
+ * @param startY
59
+ * @param endY
60
+ */
61
+ private _overlaps;
62
+ }
63
+ export {};