@kws3/ui 4.1.4 → 4.2.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.
package/CHANGELOG.mdx CHANGED
@@ -1,3 +1,10 @@
1
+ ## 4.2.0
2
+ - Fix grid row transitions to be global
3
+ - Add `createScaler` and `scale` functions to utils
4
+ - `GridView` is no longer wrapped in `div.data-table`
5
+ - New component `StickyColumnsTableWrapper` added
6
+ - Use dynamic scroll shadows for `InfiniteList` component
7
+
1
8
  ## 4.1.4
2
9
  - add `black` and `white` as valid color types
3
10
 
@@ -28,7 +28,7 @@
28
28
  -->
29
29
  {#if transition}
30
30
  <tr
31
- in:fly={{ x: 20, delay: 25 * row_index }}
31
+ in:fly|global={{ x: 20, delay: 25 * row_index }}
32
32
  on:click|stopPropagation={rowClick}
33
33
  class:is-selected={activated && visualActivationOnClick}
34
34
  class:is-checked={checked}>
@@ -32,59 +32,60 @@
32
32
  - `_forwardEvent`
33
33
 
34
34
  -->
35
- <div class="data-table" data-cy="data-table">
36
- <table
37
- class="table is-fullwidth {is_striped ? 'is-striped' : ''} {is_narrow
38
- ? 'is-narrow'
39
- : ''} {clickableRows ? 'is-hoverable' : ''} is-bordered {klass}">
40
- <thead>
41
- <tr>
42
- {#if bulk_actions}
43
- <th width="30">
44
- <Checkbox
45
- size="medium"
46
- color={selectAllCheckboxColor}
47
- style="margin:0;"
48
- inverted={true}
49
- bind:checked={selectAll}
50
- on:change={changed} />
51
- </th>
35
+
36
+ <table
37
+ class="table kws-grid-view is-fullwidth {is_striped
38
+ ? 'is-striped'
39
+ : ''} {is_narrow ? 'is-narrow' : ''} {clickableRows
40
+ ? 'is-hoverable'
41
+ : ''} is-bordered {klass}">
42
+ <thead>
43
+ <tr>
44
+ {#if bulk_actions}
45
+ <th style="width:30px">
46
+ <Checkbox
47
+ size="medium"
48
+ color={selectAllCheckboxColor}
49
+ style="margin:0;"
50
+ inverted={true}
51
+ bind:checked={selectAll}
52
+ on:change={changed} />
53
+ </th>
54
+ {/if}
55
+ {#each column_keys as column}
56
+ {#if isVisible(column)}
57
+ <th>{columns[column]}</th>
52
58
  {/if}
53
- {#each column_keys as column}
54
- {#if isVisible(column)}
55
- <th>{columns[column]}</th>
56
- {/if}
57
- {/each}
58
- </tr>
59
- </thead>
60
- <tbody data-cy="grid-view-tbody">
61
- {#each data as row, row_index (row[iteration_key])}
62
- <svelte:component
63
- this={mainRowComponent}
64
- on:rowClick
65
- on:rowSelectChecked
66
- on:_forwardEvent
67
- {row_index}
68
- {transition}
69
- {column_keys}
70
- {clickableRows}
71
- {visualActivationOnClick}
72
- {isVisible}
73
- {transforms}
74
- {classNames}
75
- {styles}
76
- {cellComponent}
77
- {row}
78
- {bulk_actions}
79
- {activatedId}
80
- {selectedIds}
81
- {selectCheckboxColor}
82
- {selectCheckboxSize}
83
- checked={selectAll} />
84
59
  {/each}
85
- </tbody>
86
- </table>
87
- </div>
60
+ </tr>
61
+ </thead>
62
+ <tbody data-cy="grid-view-tbody">
63
+ {#each data as row, row_index (row[iteration_key])}
64
+ <svelte:component
65
+ this={mainRowComponent}
66
+ on:rowClick
67
+ on:rowSelectChecked
68
+ on:_forwardEvent
69
+ {row_index}
70
+ {transition}
71
+ {column_keys}
72
+ {clickableRows}
73
+ {visualActivationOnClick}
74
+ {isVisible}
75
+ {transforms}
76
+ {classNames}
77
+ {styles}
78
+ {cellComponent}
79
+ {row}
80
+ {bulk_actions}
81
+ {activatedId}
82
+ {selectedIds}
83
+ {selectCheckboxColor}
84
+ {selectCheckboxSize}
85
+ checked={selectAll} />
86
+ {/each}
87
+ </tbody>
88
+ </table>
88
89
 
89
90
  <script>
90
91
  import GridRow from "./GridRow.svelte";
@@ -0,0 +1,107 @@
1
+ <!--
2
+ @component
3
+
4
+
5
+ @param {string} [outer_class=""] - CSS classes for the outer container, Default: `""`
6
+ @param {string} [inner_class=""] - CSS classes for the inner container, Default: `""`
7
+ @param {string} [width="100%"] - CSS value string to determine the width of the inner table, Default: `"100%"`
8
+ @method `relayout()` - Method to recalculate layouts.
9
+ Call this method when the content of the <slot> changes
10
+
11
+ ### Slots
12
+ - `<slot name="default" />`
13
+
14
+ -->
15
+ <svelte:window on:resize={debouncedResize} />
16
+ <div class="kws-sticky-columns-table-wrapper data-table-wrapper {outer_class}">
17
+ <div class="data-list-inner-wrapper {inner_class}">
18
+ <div
19
+ class="data-table has-custom-scrollbar"
20
+ bind:this={scrollContainer}
21
+ on:scroll={scrollHandler}>
22
+ <slot />
23
+ </div>
24
+ </div>
25
+ <div
26
+ class="fake-shadow-contraint left"
27
+ style="left: {leftShadowLeft}px;opacity:{needsScroll
28
+ ? scale(scrollLeft)
29
+ : 0};">
30
+ <div class="fake-inner-shadow" />
31
+ </div>
32
+ <div
33
+ class="fake-shadow-contraint right"
34
+ style="opacity:{needsScroll ? 1 - scale(scrollLeft) : 0};">
35
+ <div class="fake-inner-shadow" />
36
+ </div>
37
+ </div>
38
+
39
+ <script>
40
+ import { debounce, createScaler } from "@kws3/ui/utils";
41
+ import { onMount, tick } from "svelte";
42
+
43
+ /** CSS classes for the outer container*/
44
+ export let outer_class = "";
45
+ /** CSS classes for the inner container*/
46
+ export let inner_class = "";
47
+ /** CSS value string to determine the width of the inner table*/
48
+ export let width = "100%";
49
+
50
+ $: width, applyWidth(width);
51
+
52
+ let scrollContainer;
53
+
54
+ let leftShadowLeft = 0;
55
+ let scrollWidth = 0;
56
+ let offsetWidth = 0;
57
+ let needsScroll = false;
58
+ let scrollLeft = 0;
59
+
60
+ let scale = createScaler([0, 1], [0, 1]);
61
+
62
+ onMount(mounted);
63
+
64
+ function mounted() {
65
+ relayout();
66
+ }
67
+
68
+ /**
69
+ * Method to recalculate layouts.
70
+ * Call this method when the content of the <slot> changes
71
+ */
72
+ export function relayout() {
73
+ tick().then(() => {
74
+ leftShadowLeft = -1;
75
+ needsScroll = false;
76
+ const stickies = scrollContainer.querySelectorAll(
77
+ "thead>tr>th.is-sticky-column",
78
+ );
79
+
80
+ stickies.forEach((th) => {
81
+ leftShadowLeft += th.offsetWidth;
82
+ });
83
+
84
+ scrollWidth = scrollContainer.scrollWidth;
85
+ offsetWidth = scrollContainer.offsetWidth;
86
+
87
+ let diff = scrollWidth - offsetWidth;
88
+ if (scrollWidth > offsetWidth) {
89
+ needsScroll = true;
90
+ }
91
+ scale = createScaler([0, diff], [0, 1]);
92
+ });
93
+ }
94
+
95
+ const debouncedResize = debounce(relayout, 350);
96
+
97
+ function scrollHandler(e) {
98
+ scrollLeft = e.target.scrollLeft;
99
+ }
100
+
101
+ function applyWidth(width) {
102
+ tick().then(() => {
103
+ scrollContainer.querySelector("table.table").style.width = width;
104
+ debouncedResize();
105
+ });
106
+ }
107
+ </script>
@@ -21,12 +21,14 @@ while more items are loading
21
21
  {#if hasResizeObserver}
22
22
  <div
23
23
  bind:this={viewport}
24
- class="kws-scrollable-list kws-infinite-list with-resize-observer {klass}"
25
- on:scroll={handle_scroll}
24
+ class="kws-infinite-list with-resize-observer {klass}"
26
25
  style="height:{height};{style}"
27
26
  use:resizeObserver
28
27
  on:resize={resize}>
29
- <div bind:this={contents}>
28
+ <div
29
+ class="kws-infinite-list-inner"
30
+ on:scroll={handle_scroll}
31
+ bind:this={contents}>
30
32
  {#each visible as item (item.index)}
31
33
  <div class="row">
32
34
  <!--Default slot for list view items-->
@@ -34,18 +36,30 @@ while more items are loading
34
36
  </div>
35
37
  {/each}
36
38
  <!--Optional slot to display a loading graphic at the bottom of the list
37
- while more items are loading-->
39
+ while more items are loading-->
38
40
  <slot name="loader" />
39
41
  </div>
42
+ <div
43
+ class="fake-shadow-contraint top"
44
+ style="opacity:{needsScroll ? scale(scrollTop) : 0};">
45
+ <div class="fake-inner-shadow" />
46
+ </div>
47
+ <div
48
+ class="fake-shadow-contraint bottom"
49
+ style="opacity:{needsScroll ? 1 - scale(scrollTop) : 0};">
50
+ <div class="fake-inner-shadow" />
51
+ </div>
40
52
  </div>
41
53
  {:else}
42
54
  <div
43
55
  bind:this={viewport}
44
- class="kws-scrollable-list kws-infinite-list {klass}"
45
- on:scroll={handle_scroll}
56
+ class="kws-infinite-list {klass}"
46
57
  style="height:{height};{style}"
47
- bind:offsetHeight={viewport_height}>
48
- <div bind:this={contents}>
58
+ bind:offsetHeight={viewportHeight}>
59
+ <div
60
+ class="kws-infinite-list-inner"
61
+ on:scroll={handle_scroll}
62
+ bind:this={contents}>
49
63
  {#each visible as item (item.index)}
50
64
  <div class="row">
51
65
  <!--Default slot for list view items-->
@@ -53,24 +67,72 @@ while more items are loading
53
67
  </div>
54
68
  {/each}
55
69
  <!--Optional slot to display a loading graphic at the bottom of the list
56
- while more items are loading-->
70
+ while more items are loading-->
57
71
  <slot name="loader" />
58
72
  </div>
73
+ <div
74
+ class="fake-shadow-contraint top"
75
+ style="opacity:{needsScroll ? scale(scrollTop) : 0};">
76
+ <div class="fake-inner-shadow" />
77
+ </div>
78
+ <div
79
+ class="fake-shadow-contraint bottom"
80
+ style="opacity:{needsScroll ? 1 - scale(scrollTop) : 0};">
81
+ <div class="fake-inner-shadow" />
82
+ </div>
59
83
  </div>
60
84
  {/if}
61
85
 
62
86
  <style>
63
87
  .kws-infinite-list {
64
- overflow: auto;
65
- -webkit-overflow-scrolling: touch;
66
88
  position: relative;
67
89
  height: 100%;
68
90
  }
91
+
92
+ .kws-infinite-list-inner {
93
+ width: 100%;
94
+ height: 100%;
95
+ overflow: auto;
96
+ -webkit-overflow-scrolling: touch;
97
+ }
98
+
99
+ .fake-shadow-contraint {
100
+ position: absolute;
101
+ pointer-events: none;
102
+ top: 0;
103
+ left: 0;
104
+ width: 100%;
105
+ height: 20px;
106
+ overflow: hidden;
107
+ }
108
+ .fake-shadow-contraint .fake-inner-shadow {
109
+ position: absolute;
110
+ left: 0;
111
+ top: -1px;
112
+ width: 100%;
113
+ height: 1px;
114
+ box-shadow:
115
+ 0 0 6px 0 #000,
116
+ 0 0 12px 0 #000,
117
+ 0 0 18px 0 #000,
118
+ 0 0 20px 0 #000;
119
+ }
120
+
121
+ .fake-shadow-contraint.bottom {
122
+ top: auto;
123
+ bottom: 0;
124
+ }
125
+
126
+ .fake-shadow-contraint.bottom .fake-inner-shadow {
127
+ top: auto;
128
+ bottom: -1px;
129
+ }
69
130
  </style>
70
131
 
71
132
  <script>
72
133
  import { hasResizeObserver, resizeObserver } from "@kws3/ui/resizeObserver";
73
- import { createEventDispatcher } from "svelte";
134
+ import { createEventDispatcher, tick } from "svelte";
135
+ import { createScaler } from "@kws3/ui/utils";
74
136
 
75
137
  const fire = createEventDispatcher();
76
138
  /**
@@ -103,18 +165,28 @@ while more items are loading
103
165
  // local state
104
166
  let viewport,
105
167
  contents,
106
- viewport_height = 0,
168
+ viewportHeight = 0,
169
+ scrollHeight = 0,
170
+ offsetHeight = 0,
107
171
  visible,
108
172
  fired = false;
109
173
 
174
+ let scale = createScaler([0, 1], [0, 1]);
175
+
176
+ let needsScroll = false,
177
+ scrollTop = 0;
178
+
110
179
  $: visible = items.slice().map((data, i) => ({
111
180
  index: iteration_key ? data[iteration_key] : i,
112
181
  data,
113
182
  }));
114
183
 
184
+ $: viewportHeight, visible, relayout();
185
+
115
186
  function handle_scroll() {
116
- const { scrollTop, scrollHeight } = viewport;
117
- let offset = scrollHeight - viewport_height - scrollTop;
187
+ scrollHeight = contents.scrollHeight;
188
+ scrollTop = contents.scrollTop;
189
+ let offset = scrollHeight - viewportHeight - scrollTop;
118
190
  // fire on:end event if we scrolled past the end_offset
119
191
  if (offset <= end_offset) {
120
192
  if (!fired) {
@@ -130,6 +202,21 @@ while more items are loading
130
202
  }
131
203
 
132
204
  const resize = () => {
133
- viewport_height = viewport.offsetHeight;
205
+ viewportHeight = viewport.offsetHeight;
134
206
  };
207
+
208
+ export function relayout() {
209
+ tick().then(() => {
210
+ needsScroll = false;
211
+
212
+ scrollHeight = contents.scrollHeight;
213
+ offsetHeight = contents.offsetHeight;
214
+
215
+ let diff = scrollHeight - offsetHeight;
216
+ if (scrollHeight > offsetHeight) {
217
+ needsScroll = true;
218
+ }
219
+ scale = createScaler([0, diff], [0, 1]);
220
+ });
221
+ }
135
222
  </script>
package/index.d.ts CHANGED
@@ -53,6 +53,7 @@ export { default as TileView } from "./datagrid/TileView/TileView.svelte";
53
53
  export { default as DataSearch } from "./datagrid/DataSearch/DataSearch.svelte";
54
54
  export { default as Pagination } from "./datagrid/Pagination/Pagination.svelte";
55
55
  export { default as DataSort } from "./datagrid/DataSort/DataSort.svelte";
56
+ export { default as StickyColumnsTableWrapper } from "./datagrid/StickyColumnsTableWrapper.svelte";
56
57
  export { default as Chart } from "./charts/Chart.svelte";
57
58
  export { default as DonutChart } from "./charts/DonutChart.svelte";
58
59
  export { default as PieChart } from "./charts/PieChart.svelte";
package/index.js CHANGED
@@ -79,6 +79,7 @@ export { default as TileView } from "./datagrid/TileView/TileView.svelte";
79
79
  export { default as DataSearch } from "./datagrid/DataSearch/DataSearch.svelte";
80
80
  export { default as Pagination } from "./datagrid/Pagination/Pagination.svelte";
81
81
  export { default as DataSort } from "./datagrid/DataSort/DataSort.svelte";
82
+ export { default as StickyColumnsTableWrapper } from "./datagrid/StickyColumnsTableWrapper.svelte";
82
83
 
83
84
  export { default as Chart } from "./charts/Chart.svelte";
84
85
  export { default as DonutChart } from "./charts/DonutChart.svelte";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kws3/ui",
3
- "version": "4.1.4",
3
+ "version": "4.2.0",
4
4
  "description": "UI components for use with Svelte v3 applications.",
5
5
  "main": "index.js",
6
6
  "svelte": "index.js",
@@ -29,11 +29,11 @@
29
29
  "@kws3/text-mask-core": "^5.1.3",
30
30
  "apexcharts": "3.33.2",
31
31
  "flatpickr": "^4.5.2",
32
- "svelte-portal": "^2.1.2",
32
+ "svelte-portal": "^2.2.1",
33
33
  "tippy.js": "^6.3.1"
34
34
  },
35
35
  "devDependencies": {
36
36
  "typescript": "^5.2.2"
37
37
  },
38
- "gitHead": "69ffd54529ddc0d7ccddbc0304d48acff0724c4c"
38
+ "gitHead": "cc7a86edeb6099b9ac018c0bf73a4134ebf287a3"
39
39
  }
package/search/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @typedef {import('@kws3/ui/types').SearchOptions} SearchOptions - contains search options and fuzzy lib options
3
- * @typedef {import('@kws3/ui/types').SearchHelper} SearchHelper - returned search helper function which take unction take params `needle` and `haystack`.
3
+ * @typedef {import('@kws3/ui/types').SearchHelper} SearchHelper - returned search helper function which take function take params `needle` and `haystack`.
4
4
  */
5
5
  /**
6
6
  * @param {SearchOptions} opts
@@ -11,7 +11,7 @@ export function makeSearchEngine(opts: SearchOptions): (needle: string, haystack
11
11
  */
12
12
  export type SearchOptions = import('@kws3/ui/types').SearchOptions;
13
13
  /**
14
- * - returned search helper function which take unction take params `needle` and `haystack`.
14
+ * - returned search helper function which take function take params `needle` and `haystack`.
15
15
  */
16
16
  export type SearchHelper = import('@kws3/ui/types').SearchHelper;
17
17
  //# sourceMappingURL=index.d.ts.map
package/search/index.js CHANGED
@@ -2,7 +2,7 @@ import { fuzzy } from "../internal";
2
2
 
3
3
  /**
4
4
  * @typedef {import('@kws3/ui/types').SearchOptions} SearchOptions - contains search options and fuzzy lib options
5
- * @typedef {import('@kws3/ui/types').SearchHelper} SearchHelper - returned search helper function which take unction take params `needle` and `haystack`.
5
+ * @typedef {import('@kws3/ui/types').SearchHelper} SearchHelper - returned search helper function which take function take params `needle` and `haystack`.
6
6
  */
7
7
 
8
8
  /**
@@ -45,7 +45,7 @@ export function makeSearchEngine(opts) {
45
45
  let calculatedLimit = maxScore - scoreThreshold;
46
46
 
47
47
  OPTS = OPTS.filter(
48
- (r) => r.score > (calculatedLimit > 0 ? calculatedLimit : 0)
48
+ (r) => r.score > (calculatedLimit > 0 ? calculatedLimit : 0),
49
49
  );
50
50
  return OPTS.map((i) => i.original);
51
51
  };
package/styles/Grid.scss CHANGED
@@ -1,12 +1,20 @@
1
- $kws-gridview-box-shadow: 0 0.125rem 0.1875rem rgba(0, 0, 0, 0.1),
1
+ $kws-gridview-box-shadow:
2
+ 0 0.125rem 0.1875rem rgba(0, 0, 0, 0.1),
2
3
  0 0 0 0.0625rem rgba(0, 0, 0, 0.1) !default;
3
4
  $kws-gridview-th-background: $table-background-color !default;
4
5
  $kws-gridview-th-color: $text !default;
5
6
  $kws-gridview-tag-margin: 0 0.125rem 0.125rem 0 !default;
6
7
  $kws-gridview-icon-size: 1.5em !default;
7
- $kws-gridview-checked-row-background: $primary-light !default;
8
+ $kws-gridview-checked-row-background: $info-light !default;
8
9
 
9
- .data-table .table {
10
+ $kws-gridview-active-row-background: $table-row-active-background-color !default;
11
+ $kws-gridview-active-row-color: $table-row-active-color !default;
12
+
13
+ $kws-gridview-background: $table-background-color !default;
14
+ $kws-gridview-striped-row-background: $table-striped-row-even-background-color !default;
15
+ $kws-gridview-sticky-column-border-color: $border !default;
16
+
17
+ .table.kws-grid-view {
10
18
  box-shadow: $kws-gridview-box-shadow;
11
19
  th {
12
20
  background: $kws-gridview-th-background;
@@ -69,3 +77,85 @@ $kws-gridview-checked-row-background: $primary-light !default;
69
77
  }
70
78
  }
71
79
  }
80
+
81
+ .data-table {
82
+ overflow: auto;
83
+ }
84
+ .kws-sticky-columns-table-wrapper {
85
+ position: relative;
86
+
87
+ .data-table {
88
+ margin-bottom: 1.5rem;
89
+ .table {
90
+ margin-bottom: 0;
91
+ }
92
+ }
93
+
94
+ .data-table .table {
95
+ &.is-striped tbody {
96
+ tr:not(.is-selected):nth-child(odd) td.is-sticky-column {
97
+ background: $kws-gridview-background;
98
+ }
99
+ tr:not(.is-selected):nth-child(even) td.is-sticky-column {
100
+ background: $kws-gridview-striped-row-background;
101
+ }
102
+ tr.is-selected {
103
+ background-color: transparent;
104
+ td {
105
+ background: $kws-gridview-active-row-background;
106
+ color: $kws-gridview-active-row-color;
107
+ }
108
+ }
109
+ }
110
+ td,
111
+ th {
112
+ &.is-sticky-column {
113
+ position: sticky;
114
+ &:first-child {
115
+ left: 0;
116
+ }
117
+ }
118
+ }
119
+ &.is-bordered {
120
+ td.is-sticky-column,
121
+ th.is-sticky-column {
122
+ box-shadow: inset -1px 0 0 $kws-gridview-sticky-column-border-color;
123
+ border-left-width: 0;
124
+ border-right-width: 0;
125
+ }
126
+ }
127
+ &.has-sticky-columns {
128
+ margin-bottom: 0px;
129
+ }
130
+ }
131
+
132
+ .fake-shadow-contraint {
133
+ position: absolute;
134
+ pointer-events: none;
135
+ top: 0;
136
+ right: 0;
137
+ bottom: 0;
138
+ width: 15px;
139
+ overflow: hidden;
140
+ .fake-inner-shadow {
141
+ position: absolute;
142
+ top: 0;
143
+ right: -1px;
144
+ height: 100%;
145
+ width: 1px;
146
+ box-shadow:
147
+ 0 0 6px 0 #000,
148
+ 0 0 9px 0 #000,
149
+ 0 0 15px 0 #000;
150
+ }
151
+
152
+ &.left {
153
+ right: auto;
154
+ left: 0;
155
+ .fake-inner-shadow {
156
+ right: auto;
157
+ left: -1px;
158
+ }
159
+ }
160
+ }
161
+ }
package/utils/index.d.ts CHANGED
@@ -69,6 +69,22 @@ export function randomPercent(min?: number, max?: number): string;
69
69
  * @param {string} [fileName=''] - File Name.
70
70
  */
71
71
  export function fileDownloader(data?: any, fileName?: string): void;
72
+ /**
73
+ * Scales `value` between `inputRange` and `outputRange`
74
+ * @param {number} value
75
+ * @param {[number, number]} inputRange
76
+ * @param {[number, number]} outputRange
77
+ * @returns {number}
78
+ */
79
+ export function scale(value: number, inputRange: [number, number], outputRange: [number, number]): number;
80
+ /**
81
+ * Returns a function that can scale a `value` between
82
+ * `inputRange` and `outputRange`
83
+ * @param {[number, number]} inputRange
84
+ * @param {[number, number]} outputRange
85
+ * @returns {function}
86
+ */
87
+ export function createScaler(inputRange: [number, number], outputRange: [number, number]): Function;
72
88
  /**
73
89
  * Request an animation before the next repaint.
74
90
  * @param {function} [callback=function(){}] - callback function
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,+BAHW,MAAM,QACN,MAAM,UAIhB;AAED;;;GAGG;AACH,8BAFW,MAAM,UAQhB;AAED;;;GAGG;AACH,kCAFW,MAAM,OAIhB;AAsBD;;;;;;;;GAQG;AACH,oDAJW,MAAM,WACN,OAAO;;;EA2BjB;AAED;;;GAGG;AACH,+CAFW,MAAM,UAIhB;AAED;;;;GAIG;AACH,qCAFW,MAAM,QAKhB;AAED;;;GAGG;AACH,6BAFW,MAAM,UAKhB;AAED;;;GAGG;AACH,kCAFW,MAAM,UAUhB;AAED;;;;;;;GAOG;AACH,gDAHW,MAAM,QACN,MAAM,UAMhB;AAED;;;;GAIG;AACH,oCAHW,MAAM,QACN,MAAM,UAIhB;AAED;;;;GAIG;AACH,sDAFW,MAAM,QAYhB;AAtID;;;GAGG;AACH,sBAce"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,+BAHW,MAAM,QACN,MAAM,UAIhB;AAED;;;GAGG;AACH,8BAFW,MAAM,UAQhB;AAED;;;GAGG;AACH,kCAFW,MAAM,OAIhB;AAsBD;;;;;;;;GAQG;AACH,oDAJW,MAAM,WACN,OAAO;;;EA2BjB;AAED;;;GAGG;AACH,+CAFW,MAAM,UAIhB;AAED;;;;GAIG;AACH,qCAFW,MAAM,QAKhB;AAED;;;GAGG;AACH,6BAFW,MAAM,UAKhB;AAED;;;GAGG;AACH,kCAFW,MAAM,UAUhB;AAED;;;;;;;GAOG;AACH,gDAHW,MAAM,QACN,MAAM,UAMhB;AAED;;;;GAIG;AACH,oCAHW,MAAM,QACN,MAAM,UAIhB;AAED;;;;GAIG;AACH,sDAFW,MAAM,QAYhB;AAED;;;;;;GAMG;AACH,6BALW,MAAM,cACN,CAAC,MAAM,EAAE,MAAM,CAAC,eAChB,CAAC,MAAM,EAAE,MAAM,CAAC,GACd,MAAM,CAQlB;AAED;;;;;;GAMG;AACH,yCAJW,CAAC,MAAM,EAAE,MAAM,CAAC,eAChB,CAAC,MAAM,EAAE,MAAM,CAAC,YAU1B;AArKD;;;GAGG;AACH,sBAce"}
package/utils/index.js CHANGED
@@ -162,3 +162,34 @@ export function fileDownloader(data, fileName = "file_name") {
162
162
  a.click();
163
163
  window.URL.revokeObjectURL(url);
164
164
  }
165
+
166
+ /**
167
+ * Scales `value` between `inputRange` and `outputRange`
168
+ * @param {number} value
169
+ * @param {[number, number]} inputRange
170
+ * @param {[number, number]} outputRange
171
+ * @returns {number}
172
+ */
173
+ export function scale(value, inputRange, outputRange) {
174
+ return (
175
+ ((value - inputRange[0]) * (outputRange[1] - outputRange[0])) /
176
+ (inputRange[1] - inputRange[0]) +
177
+ outputRange[0]
178
+ );
179
+ }
180
+
181
+ /**
182
+ * Returns a function that can scale a `value` between
183
+ * `inputRange` and `outputRange`
184
+ * @param {[number, number]} inputRange
185
+ * @param {[number, number]} outputRange
186
+ * @returns {function}
187
+ */
188
+ export function createScaler(inputRange, outputRange) {
189
+ /**
190
+ * @param {number} value
191
+ */
192
+ return function (value) {
193
+ return scale(value, inputRange, outputRange);
194
+ };
195
+ }