@kws3/ui 2.0.4 → 2.1.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 +13 -1
- package/buttons/ConfirmButton.svelte +7 -6
- package/buttons/DeleteButton.svelte +14 -8
- package/buttons/ProcessButton.svelte +15 -9
- package/buttons/SubmitButton.svelte +11 -8
- package/canvas/Canvas.svelte +263 -0
- package/canvas/ESignature.svelte +101 -0
- package/canvas/PenControls.svelte +234 -0
- package/canvas/PenInput.svelte +152 -0
- package/charts/AreaChart.svelte +2 -2
- package/charts/BarChart.svelte +2 -2
- package/charts/Chart.svelte +16 -12
- package/charts/DonutChart.svelte +2 -2
- package/charts/LineChart.svelte +2 -2
- package/charts/MixedChart.svelte +2 -2
- package/charts/PieChart.svelte +2 -2
- package/charts/RadialChart.svelte +2 -2
- package/charts/utils.d.ts +553 -0
- package/charts/utils.d.ts.map +1 -0
- package/charts/utils.js +27 -4
- package/controls/Checkbox.svelte +7 -6
- package/controls/FileUpload.svelte +5 -4
- package/controls/NumberInput.svelte +5 -5
- package/controls/Radio.svelte +2 -2
- package/controls/RangeSlider.svelte +4 -2
- package/controls/Toggle.svelte +2 -2
- package/controls/ToggleButtons.svelte +1 -1
- package/datagrid/GridView/GridRow.svelte +4 -4
- package/datagrid/GridView/GridView.svelte +7 -4
- package/datagrid/Pagination/Pagination.svelte +12 -11
- package/form/index.d.ts +15 -0
- package/form/index.d.ts.map +1 -0
- package/forms/AutoComplete.svelte +12 -6
- package/forms/Datepicker.svelte +4 -3
- package/forms/PasswordInput.svelte +224 -0
- package/forms/PasswordValidator/validatePassword.d.ts +5 -0
- package/forms/PasswordValidator/validatePassword.d.ts.map +1 -0
- package/forms/SearchInput.svelte +18 -7
- package/forms/Timepicker.svelte +9 -6
- package/forms/actions.d.ts +9 -0
- package/forms/actions.d.ts.map +1 -0
- package/forms/actions.js +6 -0
- package/forms/colorpicker/Colorpicker.d.ts +3 -0
- package/forms/colorpicker/Colorpicker.d.ts.map +1 -0
- package/forms/colorpicker/Colorpicker.js +12 -2
- package/forms/colorpicker/Colorpicker.svelte +10 -3
- package/forms/select/MultiSelect.svelte +14 -9
- package/forms/select/SearchableSelect.svelte +10 -5
- package/helpers/CardModal.svelte +7 -2
- package/helpers/ClipboardCopier.svelte +3 -3
- package/helpers/Dialog/Dialog.svelte +9 -7
- package/helpers/Dialog/index.d.ts +42 -0
- package/helpers/Dialog/index.d.ts.map +1 -0
- package/helpers/Dialog/index.js +58 -19
- package/helpers/Divider.svelte +10 -4
- package/helpers/FloatingUI/Floatie.svelte +1 -1
- package/helpers/FloatingUI/index.d.ts +51 -0
- package/helpers/FloatingUI/index.d.ts.map +1 -0
- package/helpers/FloatingUI/index.js +13 -0
- package/helpers/Icon.svelte +14 -7
- package/helpers/Loader.svelte +5 -5
- package/helpers/Message.svelte +11 -6
- package/helpers/Modal.svelte +7 -2
- package/helpers/Notification.svelte +6 -2
- package/helpers/Popover.svelte +13 -6
- package/helpers/Skeleton.svelte +3 -3
- package/helpers/Timeline/Timeline.svelte +1 -1
- package/helpers/Timeline/TimelineItem.svelte +8 -4
- package/helpers/Tooltip.d.ts +19 -0
- package/helpers/Tooltip.d.ts.map +1 -0
- package/helpers/Tooltip.js +14 -1
- package/index.d.ts +69 -0
- package/index.d.ts.map +1 -0
- package/index.js +7 -0
- package/internal/DrawingPad.d.ts +86 -0
- package/internal/DrawingPad.d.ts.map +1 -0
- package/internal/DrawingPad.js +306 -0
- package/internal/UndoManager.d.ts +17 -0
- package/internal/UndoManager.d.ts.map +1 -0
- package/internal/UndoManager.js +84 -0
- package/internal/fuzzy.d.ts +24 -0
- package/internal/fuzzy.d.ts.map +1 -0
- package/internal/index.d.ts +16 -0
- package/internal/index.d.ts.map +1 -0
- package/internal/index.js +5 -1
- package/internal/scrollIntoActiveElement.d.ts +2 -0
- package/internal/scrollIntoActiveElement.d.ts.map +1 -0
- package/keyboard/index.d.ts +30 -0
- package/keyboard/index.d.ts.map +1 -0
- package/keyboard/index.js +1 -1
- package/package.json +6 -3
- package/resizeObserver/index.d.ts +8 -0
- package/resizeObserver/index.d.ts.map +1 -0
- package/search/index.d.ts +17 -0
- package/search/index.d.ts.map +1 -0
- package/settings.d.ts +22 -0
- package/settings.d.ts.map +1 -0
- package/settings.js +6 -1
- package/styles/Canvas.scss +100 -0
- package/styles/RangeSlider.scss +12 -0
- package/transitions/components/getEasing.d.ts +2 -0
- package/transitions/components/getEasing.d.ts.map +1 -0
- package/tsconfig.json +33 -0
- package/types/index.d.ts +103 -9
- package/types/type-defs/index.d.ts +64 -0
- package/utils/index.d.ts +77 -0
- package/utils/index.d.ts.map +1 -0
- package/types/type-defs/index.ts +0 -14
package/CHANGELOG.mdx
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
|
+
# 2.1.0
|
|
2
|
+
- Bugfix with Colorpicker component, where colors could not be typed in manually.
|
|
3
|
+
- Extended typing and typescript support
|
|
4
|
+
- New Components added `Canvas`, `ESignature`, `PenInput` and `PenControls`
|
|
5
|
+
- Exposed `Canvas` tools (`Pen` and `Eraser`) from `DrawingPad` - drawing helper module.
|
|
6
|
+
- New Components added `PasswordInput` with value show/hide feature.
|
|
7
|
+
|
|
8
|
+
## 2.0.5
|
|
9
|
+
- `RangeSlider` - Expose native `input` event
|
|
10
|
+
- `RangeSlider` - Supports thumb color class `is-thumb-{color}`
|
|
11
|
+
- `AutoComplete`, `SearchInput`, `SearchableSelect` and `MultiSelect` - deprecated `scoreThreshold`, changed to `score_threshold`
|
|
12
|
+
|
|
1
13
|
## 2.0.4
|
|
2
|
-
- `ToggleButtons` - set the value if not disabled and not the same value is set
|
|
14
|
+
- `ToggleButtons` - set the value if not disabled and not the same value is set
|
|
3
15
|
|
|
4
16
|
## 2.0.3
|
|
5
17
|
- Sveltkit compatibility fix ('window' not defined)
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
@component
|
|
3
3
|
|
|
4
|
+
|
|
4
5
|
@param {string} [button_class=""] - CSS classes for the Confirm button, Default: `""`
|
|
5
6
|
@param {string} [text=""] - Button text, Default: `""`
|
|
6
|
-
@param {
|
|
7
|
+
@param {SizeOptions} [size=] - Size of the Button, Default: ``
|
|
7
8
|
@param {string} [icon="check"] - Name of the icon that is to be displayed in the button, Default: `"check"`
|
|
8
|
-
@param {
|
|
9
|
+
@param {ColorOptions} [color=primary] - Color of the Button, Default: `primary`
|
|
9
10
|
@param {string} [cy=""] - data-cy attribute for cypress, Default: `""`
|
|
10
11
|
@param {string} [done_icon="check"] - Name of the icon displayed after task is completed successfully, Default: `"check"`
|
|
11
12
|
@param {string} [done_text="Done"] - Button text displayed after task is completed successfully, Default: `"Done"`
|
|
@@ -13,8 +14,8 @@
|
|
|
13
14
|
@param {boolean} [disabled=false] - Disables the button when `true`, Default: `false`
|
|
14
15
|
@param {boolean} [should_confirm=true] - When `false`, skips the confirmation prompt, and makes it a one step process, Default: `true`
|
|
15
16
|
@param {string} [context=""] - Context property, Default: `""`
|
|
16
|
-
@param {number} [completion_timeout=600] -
|
|
17
|
-
@param {number} [error_timeout=3000] -
|
|
17
|
+
@param {number} [completion_timeout=600] - Specifies the duration to wait after the `done` event, before the UI state returns to normal, Default: `600`
|
|
18
|
+
@param {number} [error_timeout=3000] - Specifies the duration to wait after the `error` event, before the UI state returns to normal, Default: `3000`
|
|
18
19
|
@param {string} [class=""] - CSS classes for button container, Default: `""`
|
|
19
20
|
|
|
20
21
|
### Events
|
|
@@ -137,11 +138,11 @@
|
|
|
137
138
|
*/
|
|
138
139
|
context = "",
|
|
139
140
|
/**
|
|
140
|
-
*
|
|
141
|
+
* Specifies the duration to wait after the `done` event, before the UI state returns to normal
|
|
141
142
|
*/
|
|
142
143
|
completion_timeout = 600,
|
|
143
144
|
/**
|
|
144
|
-
*
|
|
145
|
+
* Specifies the duration to wait after the `error` event, before the UI state returns to normal
|
|
145
146
|
*/
|
|
146
147
|
error_timeout = 3000;
|
|
147
148
|
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
@component
|
|
3
3
|
|
|
4
|
+
|
|
4
5
|
@param {string} [button_class=""] - CSS classes for the Delete button, Default: `""`
|
|
5
6
|
@param {string} [text="Delete"] - Button text, Default: `"Delete"`
|
|
6
|
-
@param {
|
|
7
|
+
@param {SizeOptions} [size=] - Size of the Button, Default: ``
|
|
7
8
|
@param {string} [icon="minus-circle"] - Name of the icon that is to be displayed in the button, Default: `"minus-circle"`
|
|
8
|
-
@param {
|
|
9
|
+
@param {ColorOptions} [color=danger] - Color of the Button, Default: `danger`
|
|
9
10
|
@param {string} [cy=""] - data-cy attribute for cypress, Default: `""`
|
|
10
11
|
@param {string} [done_icon="check"] - Name of the icon displayed after task is completed successfully, Default: `"check"`
|
|
11
12
|
@param {string} [done_text="Deleted"] - Button text displayed after task is completed successfully, Default: `"Deleted"`
|
|
12
13
|
@param {object} [context=null] - Context property, Default: `null`
|
|
13
14
|
@param {boolean} [icon_only=false] - Removes text, and text space in the button, Default: `false`
|
|
14
15
|
@param {boolean} [disabled=false] - Disables the button when `true`, Default: `false`
|
|
15
|
-
@param {number} [completion_timeout=600] -
|
|
16
|
-
@param {number} [error_timeout=3000] -
|
|
16
|
+
@param {number} [completion_timeout=600] - Specifies the duration to wait after the `erased` event, before the UI state returns to normal, Default: `600`
|
|
17
|
+
@param {number} [error_timeout=3000] - Specifies the duration to wait after the `error` event, before the UI state returns to normal, Default: `3000`
|
|
17
18
|
@param {string} [class=""] - CSS classes for the button container, Default: `""`
|
|
18
19
|
|
|
19
20
|
### Events
|
|
@@ -59,6 +60,11 @@
|
|
|
59
60
|
|
|
60
61
|
const fire = createEventDispatcher();
|
|
61
62
|
|
|
63
|
+
/**
|
|
64
|
+
* @typedef {import('@kws3/ui/types').ColorOptions} ColorOptions
|
|
65
|
+
* @typedef {import('@kws3/ui/types').SizeOptions} SizeOptions
|
|
66
|
+
*/
|
|
67
|
+
|
|
62
68
|
/**
|
|
63
69
|
* CSS classes for the Delete button
|
|
64
70
|
*/
|
|
@@ -69,7 +75,7 @@
|
|
|
69
75
|
text = "Delete",
|
|
70
76
|
/**
|
|
71
77
|
* Size of the Button
|
|
72
|
-
* @type {
|
|
78
|
+
* @type {SizeOptions}
|
|
73
79
|
*/
|
|
74
80
|
size = "",
|
|
75
81
|
/**
|
|
@@ -78,7 +84,7 @@
|
|
|
78
84
|
icon = "minus-circle",
|
|
79
85
|
/**
|
|
80
86
|
* Color of the Button
|
|
81
|
-
* @type {
|
|
87
|
+
* @type {ColorOptions}
|
|
82
88
|
*/
|
|
83
89
|
color = "danger",
|
|
84
90
|
/**
|
|
@@ -106,11 +112,11 @@
|
|
|
106
112
|
*/
|
|
107
113
|
disabled = false,
|
|
108
114
|
/**
|
|
109
|
-
*
|
|
115
|
+
* Specifies the duration to wait after the `erased` event, before the UI state returns to normal
|
|
110
116
|
*/
|
|
111
117
|
completion_timeout = 600,
|
|
112
118
|
/**
|
|
113
|
-
*
|
|
119
|
+
* Specifies the duration to wait after the `error` event, before the UI state returns to normal
|
|
114
120
|
*/
|
|
115
121
|
error_timeout = 3000;
|
|
116
122
|
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
@component
|
|
3
3
|
|
|
4
|
+
|
|
4
5
|
@param {string} [button_class=""] - CSS classes for the Process button, Default: `""`
|
|
5
6
|
@param {string} [text="Click Me"] - Button text, Default: `"Click Me"`
|
|
6
|
-
@param {
|
|
7
|
+
@param {SizeOptions} [size=] - Size of the Button, Default: ``
|
|
7
8
|
@param {string} [icon="check"] - Name of the icon that is to be displayed in the button, Default: `"check"`
|
|
8
|
-
@param {
|
|
9
|
+
@param {ColorOptions} [color=primary] - Color of the Button, Default: `primary`
|
|
9
10
|
@param {string} [cy=""] - data-cy attribute for cypress, Default: `""`
|
|
10
11
|
@param {string} [done_icon="check"] - Name of the icon displayed after task is completed successfully, Default: `"check"`
|
|
11
12
|
@param {string} [done_text="Done"] - Button text displayed after task is completed successfully, Default: `"Done"`
|
|
12
|
-
@param {
|
|
13
|
+
@param {string} [context=""] - Context property, Default: `""`
|
|
13
14
|
@param {boolean} [icon_only=false] - Removes text, and text space in the button, Default: `false`
|
|
14
15
|
@param {boolean} [disabled=false] - Disables the button when `true`, Default: `false`
|
|
15
|
-
@param {number} [completion_timeout=600] -
|
|
16
|
-
@param {number} [error_timeout=3000] -
|
|
16
|
+
@param {number} [completion_timeout=600] - Specifies the duration to wait after the `done` event, before the UI state returns to normal, Default: `600`
|
|
17
|
+
@param {number} [error_timeout=3000] - Specifies the duration to wait after the `error` event, before the UI state returns to normal, Default: `3000`
|
|
17
18
|
@param {string} [class=""] - CSS classes for button container, Default: `""`
|
|
18
19
|
|
|
19
20
|
### Events
|
|
@@ -60,6 +61,11 @@
|
|
|
60
61
|
|
|
61
62
|
const fire = createEventDispatcher();
|
|
62
63
|
|
|
64
|
+
/**
|
|
65
|
+
* @typedef {import('@kws3/ui/types').ColorOptions} ColorOptions
|
|
66
|
+
* @typedef {import('@kws3/ui/types').SizeOptions} SizeOptions
|
|
67
|
+
*/
|
|
68
|
+
|
|
63
69
|
/**
|
|
64
70
|
* CSS classes for the Process button
|
|
65
71
|
*/
|
|
@@ -70,7 +76,7 @@
|
|
|
70
76
|
text = "Click Me",
|
|
71
77
|
/**
|
|
72
78
|
* Size of the Button
|
|
73
|
-
* @type {
|
|
79
|
+
* @type {SizeOptions}
|
|
74
80
|
*/
|
|
75
81
|
size = "",
|
|
76
82
|
/**
|
|
@@ -79,7 +85,7 @@
|
|
|
79
85
|
icon = "check",
|
|
80
86
|
/**
|
|
81
87
|
* Color of the Button
|
|
82
|
-
* @type {
|
|
88
|
+
* @type {ColorOptions}
|
|
83
89
|
*/
|
|
84
90
|
color = "primary",
|
|
85
91
|
/**
|
|
@@ -107,11 +113,11 @@
|
|
|
107
113
|
*/
|
|
108
114
|
disabled = false,
|
|
109
115
|
/**
|
|
110
|
-
*
|
|
116
|
+
* Specifies the duration to wait after the `done` event, before the UI state returns to normal
|
|
111
117
|
*/
|
|
112
118
|
completion_timeout = 600,
|
|
113
119
|
/**
|
|
114
|
-
*
|
|
120
|
+
* Specifies the duration to wait after the `error` event, before the UI state returns to normal
|
|
115
121
|
*/
|
|
116
122
|
error_timeout = 3000;
|
|
117
123
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
@component
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
@param {
|
|
4
|
+
|
|
5
|
+
@param {SizeOptions} [size=] - Size of the Button, Default: ``
|
|
6
|
+
@param {ColorOptions} [color=primary] - Color of the Button, Default: `primary`
|
|
6
7
|
@param {string} [text="Save Changes"] - Button text, Default: `"Save Changes"`
|
|
7
8
|
@param {string} [saved_text="Saved"] - Text displayed after submission is completed successfully, Default: `"Saved"`
|
|
8
9
|
@param {string} [error_text="Failed to Save"] - Text displayed if submission is not successful, Default: `"Failed to Save"`
|
|
@@ -10,9 +11,9 @@
|
|
|
10
11
|
@param {string} [cy="submit"] - data-cy attribute for cypress, Default: `"submit"`
|
|
11
12
|
@param {boolean} [icon_only=false] - Removes text, and text space in the button, Default: `false`
|
|
12
13
|
@param {boolean} [disabled=false] - Disables the button when `true`, Default: `false`
|
|
13
|
-
@param {
|
|
14
|
-
@param {number} [completion_timeout=600] -
|
|
15
|
-
@param {number} [error_timeout=3000] -
|
|
14
|
+
@param {ButtonTracker} [tracker=undefined] - Tracker object to be sent from outside to change the state of the button., Default: `undefined`
|
|
15
|
+
@param {number} [completion_timeout=600] - Specifies the duration to wait after the `saved` event, before the UI state returns to normal, Default: `600`
|
|
16
|
+
@param {number} [error_timeout=3000] - Specifies the duration to wait after the `error` event, before the UI state returns to normal, Default: `3000`
|
|
16
17
|
@param {string} [class=""] - CSS classes for Button container, Default: `""`
|
|
17
18
|
@method `saving()` - call this method on form saving state
|
|
18
19
|
@method `saved(callback, timeout)` - call this method after form saved
|
|
@@ -55,6 +56,7 @@
|
|
|
55
56
|
/**
|
|
56
57
|
* @typedef {import('@kws3/ui/types').ColorOptions} ColorOptions
|
|
57
58
|
* @typedef {import('@kws3/ui/types').SizeOptions} SizeOptions
|
|
59
|
+
* @typedef {import('@kws3/ui/types').ButtonTracker} ButtonTracker
|
|
58
60
|
*/
|
|
59
61
|
|
|
60
62
|
/**
|
|
@@ -64,7 +66,7 @@
|
|
|
64
66
|
export let size = "",
|
|
65
67
|
/**
|
|
66
68
|
* Color of the Button
|
|
67
|
-
* @type {
|
|
69
|
+
* @type {ColorOptions}
|
|
68
70
|
*/
|
|
69
71
|
color = "primary",
|
|
70
72
|
/**
|
|
@@ -97,6 +99,7 @@
|
|
|
97
99
|
disabled = false,
|
|
98
100
|
/**
|
|
99
101
|
* Tracker object to be sent from outside to change the state of the button.
|
|
102
|
+
* @type {ButtonTracker}
|
|
100
103
|
*/
|
|
101
104
|
tracker = {
|
|
102
105
|
saving: false,
|
|
@@ -104,11 +107,11 @@
|
|
|
104
107
|
error: false,
|
|
105
108
|
},
|
|
106
109
|
/**
|
|
107
|
-
*
|
|
110
|
+
* Specifies the duration to wait after the `saved` event, before the UI state returns to normal
|
|
108
111
|
*/
|
|
109
112
|
completion_timeout = 600,
|
|
110
113
|
/**
|
|
111
|
-
*
|
|
114
|
+
* Specifies the duration to wait after the `error` event, before the UI state returns to normal
|
|
112
115
|
*/
|
|
113
116
|
error_timeout = 3000;
|
|
114
117
|
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@param {string} [width="250px"] - Canvas width, Default: `"250px"`
|
|
6
|
+
@param {string} [height="250px"] - Canvas height, Default: `"250px"`
|
|
7
|
+
@param {string |'Pen'|'Eraser'} [active_tool=""] - Default active tool, Default: `""`
|
|
8
|
+
@param {string} [image=""] - The Data created in the canvas by the user, Default: `""`
|
|
9
|
+
@param {boolean} [is_touched=false] - Determines whether canvas is touched or not, Default: `false`
|
|
10
|
+
@param {number} [pen_width=2] - `CONST` pen width, Default: `2`
|
|
11
|
+
@param {number} [eraser_width=6] - `CONST` Eraser width, Default: `6`
|
|
12
|
+
@param {string} [pen_color="#ff0000"] - line color, Default: `"#ff0000"`
|
|
13
|
+
@param {string} [background_image=""] - `CONST` Background image for the canvas, Default: `""`
|
|
14
|
+
@param {boolean} [readonly=false] - `CONST` Determines whether canvas is readonly or not, Default: `false`
|
|
15
|
+
@param {boolean} [disabled=false] - `CONST` Determines whether canvas is disabled or not, Default: `false`
|
|
16
|
+
@param {number} [initial_scale=1] - Initial transform scale for the canvas before expansion, Default: `1`
|
|
17
|
+
@param {string} [expand_from="center"] - The direction from which the canvas should expand.
|
|
18
|
+
'top', 'bottom', 'left', 'right', 'center' and also 'n%', Default: `"center"`
|
|
19
|
+
@param {string} [expand_to="center"] - The direction to which the canvas should expand.
|
|
20
|
+
'top', 'bottom', 'left', 'right', 'center' and also 'n%', Default: `"center"`
|
|
21
|
+
@param {number} [expand_scale=50] - Transform scale of the canvas on expansion
|
|
22
|
+
value in percentage %, Default: `50`
|
|
23
|
+
@param {array} [actions=[]] - `CONST` List of actions toolbar, Default: `[]`
|
|
24
|
+
@param {Extract<Positions, 'bottom'|'top'>} [toolbar_placement=bottom] - Default position of the action toolbar, Default: `bottom`
|
|
25
|
+
@param {object} [tools={}] - List of tools available for user to select from, Default: `{}`
|
|
26
|
+
@param {string} [cy=""] - data-cy attribute for cypress, Default: `""`
|
|
27
|
+
@param {boolean} [has_controls=true] - Determines control tools available or not, Default: `true`
|
|
28
|
+
@param {Extract<Positions, 'start'|'center'|'end'>} [control_position=center] - `CONST` Default position of controls, Default: `center`
|
|
29
|
+
@method `getActions()` - GetActions method
|
|
30
|
+
|
|
31
|
+
-->
|
|
32
|
+
|
|
33
|
+
<div
|
|
34
|
+
class="
|
|
35
|
+
kws-canvas-wrapper
|
|
36
|
+
{toolbar_placement === 'top' ? 'has-toolbar-top' : ''}
|
|
37
|
+
"
|
|
38
|
+
class:expanded
|
|
39
|
+
style:width
|
|
40
|
+
style:--kws-peninput-height={height}
|
|
41
|
+
style:--kws-peninput-width={width}
|
|
42
|
+
style:transform="scale({expanded ? 1 + expand_scale * 0.01 : initial_scale})"
|
|
43
|
+
style:transform-origin="{expand_from}
|
|
44
|
+
{expand_to}"
|
|
45
|
+
data-cy={cy}>
|
|
46
|
+
<PenInput {...$$props} {expanded} bind:DRAWING_PAD on:change={onChange} />
|
|
47
|
+
|
|
48
|
+
{#if has_controls}
|
|
49
|
+
<PenControls
|
|
50
|
+
{...$$props}
|
|
51
|
+
on:changeColor={({ detail: { color } }) => changeColor(color)}
|
|
52
|
+
on:setTool={({ detail: { tool } }) => setTool(tool)}
|
|
53
|
+
on:undo={() => undo()}
|
|
54
|
+
on:redo={() => redo()}
|
|
55
|
+
on:reset={() => reset()}
|
|
56
|
+
on:toggleExpand={() => toggleExpand()}
|
|
57
|
+
{active_tool}
|
|
58
|
+
default_color={pen_color}
|
|
59
|
+
bind:can_undo
|
|
60
|
+
bind:can_redo
|
|
61
|
+
bind:show_tools />
|
|
62
|
+
{/if}
|
|
63
|
+
</div>
|
|
64
|
+
|
|
65
|
+
<script>
|
|
66
|
+
// @ts-nocheck
|
|
67
|
+
|
|
68
|
+
import PenInput from "./PenInput.svelte";
|
|
69
|
+
import PenControls from "./PenControls.svelte";
|
|
70
|
+
import { onMount } from "svelte";
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @typedef {import('@kws3/ui/types').Positions} Positions
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Canvas width
|
|
78
|
+
*/
|
|
79
|
+
export let width = "250px";
|
|
80
|
+
/**
|
|
81
|
+
* Canvas height
|
|
82
|
+
*/
|
|
83
|
+
export let height = "250px";
|
|
84
|
+
/**
|
|
85
|
+
* Default active tool
|
|
86
|
+
* @type {string |'Pen'|'Eraser'}
|
|
87
|
+
*/
|
|
88
|
+
export let active_tool = "";
|
|
89
|
+
/**
|
|
90
|
+
* The Data created in the canvas by the user
|
|
91
|
+
*/
|
|
92
|
+
export let image = "";
|
|
93
|
+
/**
|
|
94
|
+
* Determines whether canvas is touched or not
|
|
95
|
+
*/
|
|
96
|
+
export let is_touched = false;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* pen width
|
|
100
|
+
*/
|
|
101
|
+
export const pen_width = 2;
|
|
102
|
+
/**
|
|
103
|
+
* Eraser width
|
|
104
|
+
*/
|
|
105
|
+
export const eraser_width = 6;
|
|
106
|
+
/**
|
|
107
|
+
* line color
|
|
108
|
+
*/
|
|
109
|
+
export let pen_color = "#ff0000";
|
|
110
|
+
/**
|
|
111
|
+
* Background image for the canvas
|
|
112
|
+
*/
|
|
113
|
+
export const background_image = "";
|
|
114
|
+
/**
|
|
115
|
+
* Determines whether canvas is readonly or not
|
|
116
|
+
*/
|
|
117
|
+
export const readonly = false;
|
|
118
|
+
/**
|
|
119
|
+
* Determines whether canvas is disabled or not
|
|
120
|
+
*/
|
|
121
|
+
export const disabled = false;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Initial transform scale for the canvas before expansion
|
|
125
|
+
*/
|
|
126
|
+
export let initial_scale = 1;
|
|
127
|
+
/**
|
|
128
|
+
* The direction from which the canvas should expand.
|
|
129
|
+
* 'top', 'bottom', 'left', 'right', 'center' and also 'n%'
|
|
130
|
+
*/
|
|
131
|
+
export let expand_from = "center";
|
|
132
|
+
/**
|
|
133
|
+
* The direction to which the canvas should expand.
|
|
134
|
+
* 'top', 'bottom', 'left', 'right', 'center' and also 'n%'
|
|
135
|
+
*/
|
|
136
|
+
export let expand_to = "center";
|
|
137
|
+
/**
|
|
138
|
+
* Transform scale of the canvas on expansion
|
|
139
|
+
* value in percentage %
|
|
140
|
+
*/
|
|
141
|
+
export let expand_scale = 50;
|
|
142
|
+
/**
|
|
143
|
+
* List of actions toolbar
|
|
144
|
+
*/
|
|
145
|
+
export const actions = [
|
|
146
|
+
"controls",
|
|
147
|
+
"colorpicker",
|
|
148
|
+
"undo",
|
|
149
|
+
"redo",
|
|
150
|
+
"reset",
|
|
151
|
+
"expand",
|
|
152
|
+
];
|
|
153
|
+
/**
|
|
154
|
+
* Default position of the action toolbar
|
|
155
|
+
* @type {Extract<Positions, 'bottom'|'top'>}
|
|
156
|
+
*/
|
|
157
|
+
export let toolbar_placement = "bottom";
|
|
158
|
+
/**
|
|
159
|
+
* List of tools available for user to select from
|
|
160
|
+
*/
|
|
161
|
+
export let tools = {};
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* data-cy attribute for cypress
|
|
165
|
+
*/
|
|
166
|
+
export let cy = "";
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Determines control tools available or not
|
|
170
|
+
*/
|
|
171
|
+
export let has_controls = true;
|
|
172
|
+
/**
|
|
173
|
+
* Default position of controls
|
|
174
|
+
* @type {Extract<Positions, 'start'|'center'|'end'>}
|
|
175
|
+
*/
|
|
176
|
+
export const control_position = "center";
|
|
177
|
+
|
|
178
|
+
let DRAWING_PAD;
|
|
179
|
+
|
|
180
|
+
let can_undo = false,
|
|
181
|
+
can_redo = false,
|
|
182
|
+
expanded = false,
|
|
183
|
+
show_tools = false,
|
|
184
|
+
settingFlag = false;
|
|
185
|
+
|
|
186
|
+
let penColor = "000000";
|
|
187
|
+
|
|
188
|
+
$: penColor =
|
|
189
|
+
typeof window !== "undefined" &&
|
|
190
|
+
window.CSS &&
|
|
191
|
+
window.CSS.supports("color", pen_color)
|
|
192
|
+
? pen_color
|
|
193
|
+
: "#000000";
|
|
194
|
+
$: is_touched = can_undo;
|
|
195
|
+
$: expanded, setScaleFactor();
|
|
196
|
+
$: image, syncImage();
|
|
197
|
+
$: penColor, setColor();
|
|
198
|
+
|
|
199
|
+
onMount(() => {
|
|
200
|
+
setTool(active_tool);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
export function getActions() {
|
|
204
|
+
if (DRAWING_PAD) {
|
|
205
|
+
return DRAWING_PAD;
|
|
206
|
+
}
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function setTool(tool) {
|
|
211
|
+
active_tool = tool;
|
|
212
|
+
show_tools = false;
|
|
213
|
+
DRAWING_PAD && DRAWING_PAD.setTool(tool);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function setScaleFactor() {
|
|
217
|
+
DRAWING_PAD &&
|
|
218
|
+
DRAWING_PAD.setScaleFactor(
|
|
219
|
+
expanded ? 1 + expand_scale * 0.01 : initial_scale
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function setColor() {
|
|
224
|
+
DRAWING_PAD && DRAWING_PAD.setColor(`#${penColor}`);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function syncImage() {
|
|
228
|
+
if (!settingFlag) {
|
|
229
|
+
DRAWING_PAD && DRAWING_PAD.syncImage(image);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function changeColor(color) {
|
|
234
|
+
penColor = color.substring(1);
|
|
235
|
+
setColor();
|
|
236
|
+
}
|
|
237
|
+
function toggleExpand() {
|
|
238
|
+
expanded = !expanded;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function undo() {
|
|
242
|
+
DRAWING_PAD && DRAWING_PAD.undo();
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function redo() {
|
|
246
|
+
DRAWING_PAD && DRAWING_PAD.redo();
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function reset() {
|
|
250
|
+
DRAWING_PAD && DRAWING_PAD.reset();
|
|
251
|
+
can_undo = false;
|
|
252
|
+
can_redo = false;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function onChange({ detail }) {
|
|
256
|
+
let { canvasImage, canRedo, canUndo } = detail;
|
|
257
|
+
settingFlag = true;
|
|
258
|
+
image = canvasImage;
|
|
259
|
+
can_undo = canUndo;
|
|
260
|
+
can_redo = canRedo;
|
|
261
|
+
settingFlag = false;
|
|
262
|
+
}
|
|
263
|
+
</script>
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@param {string} [image=""] - The Data created in the canvas by the user (readonly) (base64), Default: `""`
|
|
6
|
+
@param {boolean} [is_touched=false] - (readonly) Determines whether canvas is touched or not, Default: `false`
|
|
7
|
+
@param {string} [width="520px"] - Canvas width, Default: `"520px"`
|
|
8
|
+
@param {string} [height="170px"] - Canvas height, Default: `"170px"`
|
|
9
|
+
@param {string} [background_image=""] - Background image for the canvas, Default: `""`
|
|
10
|
+
@param {boolean} [readonly=false] - Determines whether canvas is readonly or not, Default: `false`
|
|
11
|
+
@param {boolean} [disabled=false] - Determines whether canvas is disabled or not, Default: `false`
|
|
12
|
+
@param {string} [expand_from="center"] - The direction to which the canvas should expand, Default: `"center"`
|
|
13
|
+
@param {string} [expand_to="center"] - The direction to which the canvas should expand, Default: `"center"`
|
|
14
|
+
@param {number} [expand_scale=50] - Transform scale of the canvas on expansion, Default: `50`
|
|
15
|
+
@param {array} [actions=[]] - `CONST` List of actions toolbar, Default: `[]`
|
|
16
|
+
@param {Extract<Positions, 'start'|'center'|'end'>} [control_position=center] - Default position of controls, Default: `center`
|
|
17
|
+
|
|
18
|
+
-->
|
|
19
|
+
<Canvas
|
|
20
|
+
bind:image
|
|
21
|
+
bind:is_touched
|
|
22
|
+
{width}
|
|
23
|
+
{height}
|
|
24
|
+
{background_image}
|
|
25
|
+
{readonly}
|
|
26
|
+
{disabled}
|
|
27
|
+
{control_position}
|
|
28
|
+
{tools}
|
|
29
|
+
{expand_from}
|
|
30
|
+
{expand_to}
|
|
31
|
+
{expand_scale}
|
|
32
|
+
active_tool="Pen"
|
|
33
|
+
{actions}
|
|
34
|
+
has_controls={!readonly && !disabled}
|
|
35
|
+
toolbar_placement={!readonly && !disabled ? "top" : undefined} />
|
|
36
|
+
|
|
37
|
+
<script>
|
|
38
|
+
import { Canvas, Pen } from "@kws3/ui";
|
|
39
|
+
/**
|
|
40
|
+
* @typedef {import('@kws3/ui/types').Positions} Positions
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The Data created in the canvas by the user (readonly) (base64)
|
|
45
|
+
*/
|
|
46
|
+
export let image = "",
|
|
47
|
+
/**
|
|
48
|
+
* (readonly) Determines whether canvas is touched or not
|
|
49
|
+
*/
|
|
50
|
+
is_touched = false,
|
|
51
|
+
/**
|
|
52
|
+
* Canvas width
|
|
53
|
+
*/
|
|
54
|
+
width = "520px",
|
|
55
|
+
/**
|
|
56
|
+
* Canvas height
|
|
57
|
+
*/
|
|
58
|
+
height = "170px",
|
|
59
|
+
/**
|
|
60
|
+
* Background image for the canvas
|
|
61
|
+
*/
|
|
62
|
+
background_image = "",
|
|
63
|
+
/**
|
|
64
|
+
* Determines whether canvas is readonly or not
|
|
65
|
+
*/
|
|
66
|
+
readonly = false,
|
|
67
|
+
/**
|
|
68
|
+
* Determines whether canvas is disabled or not
|
|
69
|
+
*/
|
|
70
|
+
disabled = false,
|
|
71
|
+
/**
|
|
72
|
+
* The direction from which the canvas should expand.
|
|
73
|
+
* 'top', 'bottom', 'left', 'right', 'center' and also 'n%'
|
|
74
|
+
*/
|
|
75
|
+
expand_from = "center",
|
|
76
|
+
/**
|
|
77
|
+
* The direction to which the canvas should expand.
|
|
78
|
+
* 'top', 'bottom', 'left', 'right', 'center' and also 'n%'
|
|
79
|
+
*/
|
|
80
|
+
expand_to = "center",
|
|
81
|
+
/**
|
|
82
|
+
* Transform scale of the canvas on expansion
|
|
83
|
+
* value in percentage %
|
|
84
|
+
*/
|
|
85
|
+
expand_scale = 50,
|
|
86
|
+
/**
|
|
87
|
+
* Default position of controls
|
|
88
|
+
* @type {Extract<Positions, 'start'|'center'|'end'>}
|
|
89
|
+
*/
|
|
90
|
+
control_position = "center",
|
|
91
|
+
/**
|
|
92
|
+
* List of actions toolbar
|
|
93
|
+
*/
|
|
94
|
+
actions = [
|
|
95
|
+
"undo",
|
|
96
|
+
"redo",
|
|
97
|
+
"reset",
|
|
98
|
+
];
|
|
99
|
+
|
|
100
|
+
let tools = { Pen };
|
|
101
|
+
</script>
|