@kws3/ui 2.0.5 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/CHANGELOG.mdx +10 -0
  2. package/buttons/ConfirmButton.svelte +7 -6
  3. package/buttons/DeleteButton.svelte +14 -8
  4. package/buttons/ProcessButton.svelte +15 -9
  5. package/buttons/SubmitButton.svelte +11 -8
  6. package/canvas/Canvas.svelte +263 -0
  7. package/canvas/ESignature.svelte +101 -0
  8. package/canvas/PenControls.svelte +234 -0
  9. package/canvas/PenInput.svelte +152 -0
  10. package/charts/AreaChart.svelte +2 -2
  11. package/charts/BarChart.svelte +2 -2
  12. package/charts/Chart.svelte +16 -12
  13. package/charts/DonutChart.svelte +2 -2
  14. package/charts/LineChart.svelte +2 -2
  15. package/charts/MixedChart.svelte +2 -2
  16. package/charts/PieChart.svelte +2 -2
  17. package/charts/RadialChart.svelte +2 -2
  18. package/charts/utils.d.ts +553 -0
  19. package/charts/utils.d.ts.map +1 -0
  20. package/charts/utils.js +27 -4
  21. package/controls/Checkbox.svelte +7 -6
  22. package/controls/FileUpload.svelte +5 -4
  23. package/controls/NumberInput.svelte +5 -5
  24. package/controls/Radio.svelte +2 -2
  25. package/controls/RangeSlider.svelte +3 -3
  26. package/controls/Toggle.svelte +2 -2
  27. package/controls/ToggleButtons.svelte +1 -1
  28. package/datagrid/GridView/GridRow.svelte +4 -4
  29. package/datagrid/GridView/GridView.svelte +7 -4
  30. package/datagrid/Pagination/Pagination.svelte +12 -11
  31. package/form/index.d.ts +15 -0
  32. package/form/index.d.ts.map +1 -0
  33. package/forms/AutoComplete.svelte +5 -5
  34. package/forms/Datepicker.svelte +4 -3
  35. package/forms/MaskedInput.svelte +1 -1
  36. package/forms/PasswordInput.svelte +224 -0
  37. package/forms/PasswordValidator/validatePassword.d.ts +5 -0
  38. package/forms/PasswordValidator/validatePassword.d.ts.map +1 -0
  39. package/forms/SearchInput.svelte +10 -5
  40. package/forms/Timepicker.svelte +9 -6
  41. package/forms/actions.d.ts +9 -0
  42. package/forms/actions.d.ts.map +1 -0
  43. package/forms/actions.js +6 -0
  44. package/forms/colorpicker/Colorpicker.d.ts +3 -0
  45. package/forms/colorpicker/Colorpicker.d.ts.map +1 -0
  46. package/forms/colorpicker/Colorpicker.js +12 -2
  47. package/forms/colorpicker/Colorpicker.svelte +10 -3
  48. package/forms/select/MultiSelect.svelte +8 -9
  49. package/forms/select/SearchableSelect.svelte +10 -5
  50. package/helpers/CardModal.svelte +7 -2
  51. package/helpers/ClipboardCopier.svelte +3 -3
  52. package/helpers/Dialog/Dialog.svelte +9 -7
  53. package/helpers/Dialog/index.d.ts +42 -0
  54. package/helpers/Dialog/index.d.ts.map +1 -0
  55. package/helpers/Dialog/index.js +58 -19
  56. package/helpers/Divider.svelte +10 -4
  57. package/helpers/FloatingUI/Floatie.svelte +1 -1
  58. package/helpers/FloatingUI/index.d.ts +51 -0
  59. package/helpers/FloatingUI/index.d.ts.map +1 -0
  60. package/helpers/FloatingUI/index.js +13 -0
  61. package/helpers/Icon.svelte +14 -7
  62. package/helpers/Loader.svelte +5 -5
  63. package/helpers/Message.svelte +11 -6
  64. package/helpers/Modal.svelte +7 -2
  65. package/helpers/Notification.svelte +6 -2
  66. package/helpers/Popover.svelte +13 -6
  67. package/helpers/Skeleton.svelte +3 -3
  68. package/helpers/Timeline/Timeline.svelte +1 -1
  69. package/helpers/Timeline/TimelineItem.svelte +8 -4
  70. package/helpers/Tooltip.d.ts +19 -0
  71. package/helpers/Tooltip.d.ts.map +1 -0
  72. package/helpers/Tooltip.js +14 -1
  73. package/index.d.ts +69 -0
  74. package/index.d.ts.map +1 -0
  75. package/index.js +7 -0
  76. package/internal/DrawingPad.d.ts +86 -0
  77. package/internal/DrawingPad.d.ts.map +1 -0
  78. package/internal/DrawingPad.js +306 -0
  79. package/internal/UndoManager.d.ts +17 -0
  80. package/internal/UndoManager.d.ts.map +1 -0
  81. package/internal/UndoManager.js +84 -0
  82. package/internal/fuzzy.d.ts +24 -0
  83. package/internal/fuzzy.d.ts.map +1 -0
  84. package/internal/index.d.ts +16 -0
  85. package/internal/index.d.ts.map +1 -0
  86. package/internal/index.js +5 -1
  87. package/internal/scrollIntoActiveElement.d.ts +2 -0
  88. package/internal/scrollIntoActiveElement.d.ts.map +1 -0
  89. package/keyboard/index.d.ts +30 -0
  90. package/keyboard/index.d.ts.map +1 -0
  91. package/keyboard/index.js +1 -1
  92. package/package.json +7 -4
  93. package/resizeObserver/index.d.ts +8 -0
  94. package/resizeObserver/index.d.ts.map +1 -0
  95. package/search/index.d.ts +17 -0
  96. package/search/index.d.ts.map +1 -0
  97. package/settings.d.ts +22 -0
  98. package/settings.d.ts.map +1 -0
  99. package/settings.js +6 -1
  100. package/styles/Canvas.scss +100 -0
  101. package/transitions/components/getEasing.d.ts +2 -0
  102. package/transitions/components/getEasing.d.ts.map +1 -0
  103. package/tsconfig.json +33 -0
  104. package/types/index.d.ts +103 -9
  105. package/types/type-defs/index.d.ts +64 -0
  106. package/utils/index.d.ts +77 -0
  107. package/utils/index.d.ts.map +1 -0
  108. package/types/type-defs/index.ts +0 -14
package/CHANGELOG.mdx CHANGED
@@ -1,3 +1,13 @@
1
+ # 2.1.1
2
+ - Package `text-mask-core` moved to @kws3 namespace and removed from dependencies.
3
+
4
+ # 2.1.0
5
+ - Bugfix with Colorpicker component, where colors could not be typed in manually.
6
+ - Extended typing and typescript support
7
+ - New Components added `Canvas`, `ESignature`, `PenInput` and `PenControls`
8
+ - Exposed `Canvas` tools (`Pen` and `Eraser`) from `DrawingPad` - drawing helper module.
9
+ - New Components added `PasswordInput` with value show/hide feature.
10
+
1
11
  ## 2.0.5
2
12
  - `RangeSlider` - Expose native `input` event
3
13
  - `RangeSlider` - Supports thumb color class `is-thumb-{color}`
@@ -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 {''|'small'|'medium'|'large'} [size=""] - Size of the Button, Default: `""`
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 {''|'dark' | 'light' | 'warning' | 'info' | 'danger' | 'primary' | 'success'} [color="primary"] - Color of the Button, Default: `"primary"`
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] - How long to wait before `done` event is fired, and the UI state reverts back to normal, Default: `600`
17
- @param {number} [error_timeout=3000] - How long to wait before `error` event is fired, and the UI state reverts back to normal, Default: `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
- * How long to wait before `done` event is fired, and the UI state reverts back to normal
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
- * How long to wait before `error` event is fired, and the UI state reverts back to normal
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 {''|'small'|'medium'|'large'} [size=""] - Size of the Button, Default: `""`
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 {''|'dark' | 'light' | 'warning' | 'info' | 'danger' | 'primary' | 'success'} [color="danger"] - Color of the Button, Default: `"danger"`
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] - How long to wait before `erased` event is fired, and the UI state reverts back to normal, Default: `600`
16
- @param {number} [error_timeout=3000] - How long to wait before `error` event is fired, and the UI state reverts back to normal, Default: `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 {import('@kws3/ui/types').SizeOptions}
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 {import('@kws3/ui/types').ColorOptions}
87
+ * @type {ColorOptions}
82
88
  */
83
89
  color = "danger",
84
90
  /**
@@ -106,11 +112,11 @@
106
112
  */
107
113
  disabled = false,
108
114
  /**
109
- * How long to wait before `erased` event is fired, and the UI state reverts back to normal
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
- * How long to wait before `error` event is fired, and the UI state reverts back to normal
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 {''|'small'|'medium'|'large'} [size=""] - Size of the Button, Default: `""`
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 {''|'dark' | 'light' | 'warning' | 'info' | 'danger' | 'primary' | 'success'} [color="primary"] - Color of the Button, Default: `"primary"`
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 {object} [context=null] - Context property, Default: `null`
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] - How long to wait before `done` event is fired, and the UI state reverts back to normal, Default: `600`
16
- @param {number} [error_timeout=3000] - How long to wait before `error` event is fired, and the UI state reverts back to normal, Default: `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 {import('@kws3/ui/types').SizeOptions}
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 {import('@kws3/ui/types').ColorOptions}
88
+ * @type {ColorOptions}
83
89
  */
84
90
  color = "primary",
85
91
  /**
@@ -107,11 +113,11 @@
107
113
  */
108
114
  disabled = false,
109
115
  /**
110
- * How long to wait before `done` event is fired, and the UI state reverts back to normal
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
- * How long to wait before `error` event is fired, and the UI state reverts back to normal
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
- @param {''|'small'|'medium'|'large'} [size=""] - Size of the Button, Default: `""`
5
- @param {''|'primary'|'warning'|'info'|'danger'|'dark'|'light'} [color="primary"] - Color of the Button, Default: `"primary"`
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 {object} [tracker={}] - Tracker object to be sent from outside to change the state of the button., Default: `{}`
14
- @param {number} [completion_timeout=600] - How long to wait before `saved` event is fired, and the UI state reverts back to normal, Default: `600`
15
- @param {number} [error_timeout=3000] - How long to wait before `error` event is fired, and the UI state reverts back to normal, Default: `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 {Exclude<ColorOptions , 'success'>}
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
- * How long to wait before `saved` event is fired, and the UI state reverts back to normal
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
- * How long to wait before `error` event is fired, and the UI state reverts back to normal
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>