@torpor/ui 0.3.5 → 0.3.7

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 (241) hide show
  1. package/dist/Chart/BarChart.torp +159 -0
  2. package/dist/Chart/DataSeries.ts +5 -0
  3. package/dist/Chart/GridLines.torp +62 -0
  4. package/dist/Chart/LineChart.torp +196 -0
  5. package/dist/Chart/PieChart.torp +145 -0
  6. package/dist/Chart/ScatterChart.torp +215 -0
  7. package/dist/Chart/SparkLine.torp +71 -0
  8. package/dist/Chart/XAxis.torp +60 -0
  9. package/dist/Chart/YAxis.torp +41 -0
  10. package/dist/Chart/index.d.ts +220 -0
  11. package/dist/Chart/index.js +34 -0
  12. package/dist/Chart/index.js.map +1 -0
  13. package/dist/Form/TextArea.torp +3 -0
  14. package/dist/Form/index.d.ts +2 -0
  15. package/dist/metafile-esm.json +1 -1
  16. package/dist/utils/chartColors.ts +17 -0
  17. package/dist/utils/chartUtils.ts +71 -0
  18. package/package.json +10 -3
  19. package/CHANGELOG.md +0 -344
  20. package/scripts/postbuild.ts +0 -127
  21. package/src/Accordion/Accordion.torp +0 -230
  22. package/src/Accordion/AccordionContent.torp +0 -46
  23. package/src/Accordion/AccordionHeader.torp +0 -45
  24. package/src/Accordion/AccordionItem.torp +0 -101
  25. package/src/Accordion/AccordionTrigger.torp +0 -70
  26. package/src/Accordion/AccordionTypes.ts +0 -36
  27. package/src/Accordion/index.ts +0 -7
  28. package/src/Breadcrumb/Breadcrumb.torp +0 -45
  29. package/src/Breadcrumb/BreadcrumbItem.torp +0 -30
  30. package/src/Breadcrumb/BreadcrumbSeparator.torp +0 -27
  31. package/src/Breadcrumb/index.ts +0 -5
  32. package/src/Calendar/Calendar.torp +0 -277
  33. package/src/Calendar/CalendarDay.torp +0 -78
  34. package/src/Calendar/CalendarTypes.ts +0 -22
  35. package/src/Calendar/index.ts +0 -4
  36. package/src/Contextual/Contextual.torp +0 -129
  37. package/src/Contextual/ContextualContent.torp +0 -112
  38. package/src/Contextual/ContextualTrigger.torp +0 -70
  39. package/src/Contextual/ContextualTypes.ts +0 -30
  40. package/src/Contextual/index.ts +0 -5
  41. package/src/Dialog/Dialog.torp +0 -136
  42. package/src/Dialog/DialogBody.torp +0 -44
  43. package/src/Dialog/DialogButton.torp +0 -66
  44. package/src/Dialog/DialogFooter.torp +0 -25
  45. package/src/Dialog/DialogHeader.torp +0 -45
  46. package/src/Dialog/DialogTypes.ts +0 -17
  47. package/src/Dialog/index.ts +0 -7
  48. package/src/Disclosure/Disclosure.torp +0 -82
  49. package/src/Disclosure/DisclosureContent.torp +0 -46
  50. package/src/Disclosure/DisclosureHeader.torp +0 -45
  51. package/src/Disclosure/DisclosureTrigger.torp +0 -47
  52. package/src/Disclosure/DisclosureTypes.ts +0 -13
  53. package/src/Disclosure/index.ts +0 -6
  54. package/src/Drawer/Drawer.torp +0 -127
  55. package/src/Drawer/DrawerContent.torp +0 -83
  56. package/src/Drawer/DrawerOverlay.torp +0 -42
  57. package/src/Drawer/DrawerTrigger.torp +0 -39
  58. package/src/Drawer/DrawerTypes.ts +0 -24
  59. package/src/Drawer/index.ts +0 -6
  60. package/src/Form/CheckBox.torp +0 -94
  61. package/src/Form/Field.torp +0 -95
  62. package/src/Form/File.torp +0 -102
  63. package/src/Form/Form.torp +0 -147
  64. package/src/Form/FormTypes.ts +0 -35
  65. package/src/Form/Hidden.torp +0 -25
  66. package/src/Form/Input.torp +0 -112
  67. package/src/Form/Label.torp +0 -35
  68. package/src/Form/Message.torp +0 -39
  69. package/src/Form/Option.torp +0 -28
  70. package/src/Form/Select.torp +0 -101
  71. package/src/Form/StandardSchemaV1.ts +0 -70
  72. package/src/Form/TextArea.torp +0 -105
  73. package/src/Form/index.ts +0 -13
  74. package/src/Menu/Menu.torp +0 -174
  75. package/src/Menu/MenuButton.torp +0 -74
  76. package/src/Menu/MenuCheck.torp +0 -89
  77. package/src/Menu/MenuGroup.torp +0 -31
  78. package/src/Menu/MenuIndicator.torp +0 -40
  79. package/src/Menu/MenuPopout.torp +0 -83
  80. package/src/Menu/MenuPopoutContent.torp +0 -84
  81. package/src/Menu/MenuPopoutTrigger.torp +0 -128
  82. package/src/Menu/MenuRadio.torp +0 -103
  83. package/src/Menu/MenuRadioGroup.torp +0 -109
  84. package/src/Menu/MenuSeparator.torp +0 -26
  85. package/src/Menu/MenuTypes.ts +0 -60
  86. package/src/Menu/index.ts +0 -25
  87. package/src/MenuBar/MenuBar.torp +0 -162
  88. package/src/MenuBar/MenuBarItem.torp +0 -116
  89. package/src/MenuBar/MenuBarItemContent.torp +0 -119
  90. package/src/MenuBar/MenuBarItemTrigger.torp +0 -99
  91. package/src/MenuBar/MenuBarTypes.ts +0 -36
  92. package/src/MenuBar/index.ts +0 -6
  93. package/src/Modal/Modal.torp +0 -122
  94. package/src/Modal/ModalContent.torp +0 -81
  95. package/src/Modal/ModalOverlay.torp +0 -42
  96. package/src/Modal/ModalTrigger.torp +0 -54
  97. package/src/Modal/ModalTypes.ts +0 -22
  98. package/src/Modal/index.ts +0 -10
  99. package/src/Modal/showModal.ts +0 -19
  100. package/src/Modal/showPrompt.ts +0 -23
  101. package/src/NavMenu/NavMenu.torp +0 -190
  102. package/src/NavMenu/NavMenuButton.torp +0 -55
  103. package/src/NavMenu/NavMenuElement.torp +0 -55
  104. package/src/NavMenu/NavMenuGroup.torp +0 -41
  105. package/src/NavMenu/NavMenuGroupHeader.torp +0 -41
  106. package/src/NavMenu/NavMenuLink.torp +0 -60
  107. package/src/NavMenu/NavMenuPopout.torp +0 -89
  108. package/src/NavMenu/NavMenuPopoutButton.torp +0 -129
  109. package/src/NavMenu/NavMenuPopoutContent.torp +0 -92
  110. package/src/NavMenu/NavMenuSeparator.torp +0 -24
  111. package/src/NavMenu/NavMenuTypes.ts +0 -32
  112. package/src/NavMenu/index.ts +0 -23
  113. package/src/Notification/Notification.torp +0 -71
  114. package/src/Notification/NotificationClose.torp +0 -39
  115. package/src/Notification/NotificationContainer.torp +0 -26
  116. package/src/Notification/NotificationContent.torp +0 -25
  117. package/src/Notification/NotificationTypes.ts +0 -5
  118. package/src/Notification/index.ts +0 -13
  119. package/src/Notification/showNotification.ts +0 -30
  120. package/src/Popover/Popover.torp +0 -129
  121. package/src/Popover/PopoverContent.torp +0 -117
  122. package/src/Popover/PopoverTrigger.torp +0 -62
  123. package/src/Popover/PopoverTypes.ts +0 -30
  124. package/src/Popover/index.ts +0 -6
  125. package/src/Popover/showPopover.ts +0 -24
  126. package/src/Slider/Slider.torp +0 -84
  127. package/src/Slider/index.ts +0 -3
  128. package/src/TabGroup/TabContent.torp +0 -49
  129. package/src/TabGroup/TabGroup.torp +0 -250
  130. package/src/TabGroup/TabGroupTypes.ts +0 -44
  131. package/src/TabGroup/TabHeader.torp +0 -81
  132. package/src/TabGroup/TabList.torp +0 -61
  133. package/src/TabGroup/TabTrigger.torp +0 -76
  134. package/src/TabGroup/index.ts +0 -7
  135. package/src/ambient.d.ts +0 -7
  136. package/src/icons/ArrowDown.torp +0 -18
  137. package/src/icons/ArrowLeft.torp +0 -18
  138. package/src/icons/ArrowRight.torp +0 -18
  139. package/src/icons/ArrowUp.torp +0 -18
  140. package/src/icons/Bars.torp +0 -20
  141. package/src/icons/Check.torp +0 -18
  142. package/src/icons/ChevronDown.torp +0 -18
  143. package/src/icons/ChevronLeft.torp +0 -18
  144. package/src/icons/ChevronRight.torp +0 -18
  145. package/src/icons/ChevronUp.torp +0 -18
  146. package/src/icons/Cross.torp +0 -19
  147. package/src/icons/IconTypes.ts +0 -10
  148. package/src/icons/Loading.torp +0 -19
  149. package/src/icons/Minus.torp +0 -18
  150. package/src/icons/Plus.torp +0 -19
  151. package/src/icons/index.ts +0 -31
  152. package/src/motion/fade.ts +0 -16
  153. package/src/motion/grow.ts +0 -23
  154. package/src/motion/index.ts +0 -6
  155. package/src/motion/measure.ts +0 -28
  156. package/src/motion/slide.ts +0 -45
  157. package/src/mount/clickPopover.ts +0 -51
  158. package/src/mount/contextPopover.ts +0 -51
  159. package/src/mount/disableScroll.ts +0 -28
  160. package/src/mount/hoverPopover.ts +0 -58
  161. package/src/mount/hoverTrigger.ts +0 -59
  162. package/src/mount/trapFocus.ts +0 -58
  163. package/src/utils/dateUtils.ts +0 -244
  164. package/src/utils/documentEvents.ts +0 -17
  165. package/src/utils/getId.ts +0 -6
  166. package/src/utils/getScrollParent.ts +0 -22
  167. package/src/utils/setContextPosition.ts +0 -31
  168. package/src/utils/setPopoverPosition.ts +0 -142
  169. package/test/Accordion/accessibility.test.ts +0 -59
  170. package/test/Accordion/components/AccordionAccessibility.torp +0 -44
  171. package/test/Accordion/components/AccordionKeyboard.torp +0 -32
  172. package/test/Accordion/components/AccordionList.torp +0 -23
  173. package/test/Accordion/components/AccordionMultiple.torp +0 -32
  174. package/test/Accordion/components/AccordionSingle.torp +0 -32
  175. package/test/Accordion/for-items.test.ts +0 -52
  176. package/test/Accordion/keyboard.test.ts +0 -64
  177. package/test/Accordion/multiple-item-toggle.test.ts +0 -32
  178. package/test/Accordion/multiple-item-value.test.ts +0 -17
  179. package/test/Accordion/single-item-toggle.test.ts +0 -31
  180. package/test/Accordion/single-item-value.test.ts +0 -17
  181. package/test/Breadcrumb/accessibility.test.ts +0 -29
  182. package/test/Breadcrumb/basic.test.ts +0 -17
  183. package/test/Breadcrumb/components/BreadcrumbTest.torp +0 -15
  184. package/test/Calendar/components/CalendarTest.torp +0 -9
  185. package/test/Calendar/default.test.ts +0 -18
  186. package/test/Dialog/accessibility-alert.test.ts +0 -40
  187. package/test/Dialog/accessibility-modal.test.ts +0 -52
  188. package/test/Dialog/components/DialogAccessibility.torp +0 -25
  189. package/test/Dialog/components/DialogFunction.torp +0 -36
  190. package/test/Dialog/components/DialogModal.torp +0 -30
  191. package/test/Dialog/components/DialogVariable.torp +0 -33
  192. package/test/Dialog/function.test.ts +0 -26
  193. package/test/Dialog/variable.test.ts +0 -27
  194. package/test/Disclosure/accessibility.test.ts +0 -31
  195. package/test/Disclosure/components/DisclosureTest.torp +0 -17
  196. package/test/Disclosure/default.test.ts +0 -15
  197. package/test/Disclosure/toggle.test.ts +0 -20
  198. package/test/Form/components/FieldTest.torp +0 -25
  199. package/test/Form/components/FormTest.torp +0 -31
  200. package/test/Form/components/InputTest.torp +0 -9
  201. package/test/Form/field.test.ts +0 -34
  202. package/test/Form/form.test.ts +0 -34
  203. package/test/Form/input.test.ts +0 -19
  204. package/test/Menu/accessibility.test.ts +0 -83
  205. package/test/Menu/basic.test.ts +0 -58
  206. package/test/Menu/components/MenuAccessibility.torp +0 -59
  207. package/test/Menu/components/MenuBasic.torp +0 -58
  208. package/test/MenuBar/accessibility.test.ts +0 -87
  209. package/test/MenuBar/basic.test.ts +0 -22
  210. package/test/MenuBar/components/MenuBarAccessibility.torp +0 -34
  211. package/test/MenuBar/components/MenuBarBasic.torp +0 -25
  212. package/test/NavMenu/accessibility.test.ts +0 -97
  213. package/test/NavMenu/basic.test.ts +0 -22
  214. package/test/NavMenu/components/NavMenuAccessibility.torp +0 -35
  215. package/test/NavMenu/components/NavMenuBasic.torp +0 -28
  216. package/test/Notification/accessibility.test.ts +0 -21
  217. package/test/Notification/components/CustomNotification.torp +0 -14
  218. package/test/Notification/components/NotificationAccessibility.torp +0 -14
  219. package/test/Notification/components/NotificationFunction.torp +0 -17
  220. package/test/Notification/components/NotificationVariable.torp +0 -22
  221. package/test/Notification/function.test.ts +0 -25
  222. package/test/Notification/variable.test.ts +0 -25
  223. package/test/Popover/components/CustomDialog.torp +0 -25
  224. package/test/Popover/components/PopoverFunction.torp +0 -37
  225. package/test/Popover/components/PopoverTrigger.torp +0 -36
  226. package/test/Popover/components/PopoverVariable.torp +0 -40
  227. package/test/Popover/function.test.ts +0 -21
  228. package/test/Popover/trigger.test.ts +0 -27
  229. package/test/Popover/variable.test.ts +0 -27
  230. package/test/TabGroup/accessibility.test.ts +0 -67
  231. package/test/TabGroup/components/TabGroupAccessibility.torp +0 -28
  232. package/test/TabGroup/components/TabGroupKeyboard.torp +0 -28
  233. package/test/TabGroup/components/TabGroupList.torp +0 -26
  234. package/test/TabGroup/components/TabGroupTrigger.torp +0 -28
  235. package/test/TabGroup/for-items.test.ts +0 -52
  236. package/test/TabGroup/item-trigger.test.ts +0 -33
  237. package/test/TabGroup/item-value.test.ts +0 -17
  238. package/test/TabGroup/keyboard.test.ts +0 -72
  239. package/tsconfig.json +0 -4
  240. package/tsup.config.ts +0 -37
  241. package/vitest.config.ts +0 -12
@@ -0,0 +1,215 @@
1
+ import type { ClassValue, StyleValue } from "@torpor/view";
2
+ import XAxis from "./XAxis.torp";
3
+ import YAxis from "./YAxis.torp";
4
+ import GridLines from "./GridLines.torp";
5
+ import {
6
+ calculateStepValue,
7
+ calculateStepLabels,
8
+ calculateValueHeight,
9
+ calculateChartBottom,
10
+ calculateChartLeft
11
+ } from "../utils/chartUtils";
12
+ import { chartColors } from "../utils/chartColors";
13
+
14
+ interface Pair {
15
+ x: number;
16
+ y: number;
17
+ label: string;
18
+ }
19
+
20
+ interface DataSeries {
21
+ name: string;
22
+ color: string;
23
+ data: Pair[];
24
+ }
25
+
26
+ interface ScatterChartProps {
27
+ /** An ID for the root element */
28
+ id?: string;
29
+ /** Classes for the root element */
30
+ class?: ClassValue,
31
+ /** Styles for the root element */
32
+ style?: StyleValue,
33
+ series: DataSeries[],
34
+ height?: number,
35
+ width?: number,
36
+ xLabel?: string,
37
+ yLabel?: string,
38
+ xStepCount?: number,
39
+ xStepValue?: number,
40
+ yStepCount?: number,
41
+ yStepValue?: number,
42
+ hideXAxis?: boolean,
43
+ hideYAxis?: boolean,
44
+ showHLines?: boolean,
45
+ showVLines?: boolean,
46
+ }
47
+
48
+ export default function ScatterChart($props: ScatterChartProps) {
49
+ const defaultHeight = 200;
50
+ const defaultWidth = 400;
51
+
52
+ let container: HTMLElement;
53
+ let measurer: SVGTextElement;
54
+
55
+ let $state = $watch({
56
+ textWidth: 0,
57
+ textHeight: 0,
58
+ get calculatedHeight() {
59
+ return $props.height || defaultHeight;
60
+ },
61
+ get calculatedWidth() {
62
+ return $props.width || container?.clientWidth || defaultWidth;
63
+ },
64
+ get maxXValue() {
65
+ return calculateMaxValue($props.series, "x");
66
+ },
67
+ get calculatedXStepValue() {
68
+ return $props.xStepValue || calculateStepValue($state.maxXValue, $props.xStepCount);
69
+ },
70
+ get xStepLabels() {
71
+ return calculateStepLabels($props.xStepCount || 2, $state.calculatedXStepValue);
72
+ },
73
+ get maxYValue() {
74
+ return calculateMaxValue($props.series, "y");
75
+ },
76
+ get calculatedYStepValue() {
77
+ return $props.yStepValue || calculateStepValue($state.maxYValue, $props.yStepCount);
78
+ },
79
+ get yStepLabels() {
80
+ return calculateStepLabels($props.yStepCount || 2, $state.calculatedYStepValue);
81
+ },
82
+ get itemWidth() {
83
+ return calculateValueHeight(
84
+ $state.calculatedWidth - $state.chartLeft,
85
+ $state.textHeight,
86
+ $state.calculatedXStepValue,
87
+ $props.xStepCount || 2
88
+ );
89
+ },
90
+ get valueHeight() {
91
+ return calculateValueHeight($state.chartBottom, $state.textHeight, $state.calculatedYStepValue, $props.yStepCount || 2);
92
+ },
93
+ get chartBottom() {
94
+ return calculateChartBottom($props.xLabel ?? "", $state.calculatedHeight, $state.textHeight);
95
+ },
96
+ get chartLeft() {
97
+ return calculateChartLeft($state.yStepLabels, $props.yLabel ?? "", $state.textHeight, $state.textWidth);
98
+ },
99
+ get pointSeries() {
100
+ return buildPointSeries(
101
+ $props.series,
102
+ $state.chartLeft,
103
+ $state.chartBottom,
104
+ $state.itemWidth,
105
+ $state.valueHeight
106
+ );
107
+ },
108
+ });
109
+
110
+ $mount(() => {
111
+ // HACK: Wait until the measurer is really available
112
+ setTimeout(() => {
113
+ const bbox = measurer.getBBox();
114
+ $state.textWidth = bbox.width;
115
+ $state.textHeight = bbox.height * 1.5;
116
+ measurer.remove();
117
+ }, 1);
118
+ });
119
+
120
+ function calculateMaxValue(series: DataSeries[], field: "x" | "y") {
121
+ // HACK: Yeah, nested reduces
122
+ return series.reduce((a, b) => {
123
+ return Math.max(
124
+ a,
125
+ b.data.reduce((c, d) => Math.max(c, field === "x" ? d.x : d.y), 0)
126
+ );
127
+ }, 0);
128
+ }
129
+
130
+ function buildPointSeries(
131
+ theSeries: DataSeries[],
132
+ theChartLeft: number,
133
+ theChartBottom: number,
134
+ theItemWidth: number,
135
+ theValueHeight: number
136
+ ) {
137
+ return theSeries.map((series) => {
138
+ return series.data.map((item) => {
139
+ const x = +(theChartLeft + item.x * theItemWidth).toFixed(2);
140
+ const y = +(theChartBottom - item.y * theValueHeight).toFixed(2);
141
+ return { x, y };
142
+ });
143
+ });
144
+ }
145
+
146
+ @render {
147
+ <div
148
+ {$props?.id}
149
+ class={["torp-scatter-chart", $props?.class]}
150
+ {$props?.style}
151
+ &ref={container}
152
+ >
153
+ <svg version="1.1" width={$state.calculatedWidth} height={$state.calculatedHeight}>
154
+ <g>
155
+ <text &ref={measurer} x="-999" y="-999">8</text>
156
+
157
+ @if ($state.textWidth && $state.textHeight) {
158
+ <XAxis
159
+ showAxis={!$props.hideXAxis}
160
+ height={$state.calculatedHeight}
161
+ width={$state.calculatedWidth}
162
+ {$state.itemWidth}
163
+ {$state.textHeight}
164
+ xLabel={$props.xLabel ?? ""}
165
+ labels={[]}
166
+ stepLabels={$state.xStepLabels}
167
+ stepValue={$state.calculatedXStepValue}
168
+ {$state.chartLeft}
169
+ {$state.chartBottom}
170
+ />
171
+ <YAxis
172
+ showAxis={!$props.hideYAxis}
173
+ {$state.valueHeight}
174
+ {$state.textHeight}
175
+ yLabel={$props.yLabel ?? ""}
176
+ stepLabels={$state.yStepLabels}
177
+ stepValue={$state.calculatedYStepValue}
178
+ {$state.chartLeft}
179
+ {$state.chartBottom}
180
+ />
181
+ <GridLines
182
+ {$props.showHLines}
183
+ {$props.showVLines}
184
+ width={$state.calculatedWidth}
185
+ labels={[]}
186
+ xStepValue={$state.calculatedXStepValue}
187
+ {$state.xStepLabels}
188
+ yStepValue={$state.calculatedYStepValue}
189
+ {$state.yStepLabels}
190
+ {$state.itemWidth}
191
+ {$state.valueHeight}
192
+ {$state.chartLeft}
193
+ {$state.chartBottom}
194
+ type="line"
195
+ />
196
+ @for (let [i, series] of $props.series.entries()) {
197
+ @for (let [j, point] of $state.pointSeries[i].entries()) {
198
+ <circle
199
+ cx={point.x}
200
+ cy={point.y}
201
+ r="4"
202
+ fill={series.color || chartColors[i % chartColors.length]}
203
+ >
204
+ <title>{
205
+ `${[series.name, series.data[j].label, series.data[j].x].filter(Boolean).join("\n")}, ${series.data[j].y}`
206
+ }</title>
207
+ </circle>
208
+ }
209
+ }
210
+ }
211
+ </g>
212
+ </svg>
213
+ </div>
214
+ }
215
+ }
@@ -0,0 +1,71 @@
1
+ import type { ClassValue, StyleValue } from "@torpor/view";
2
+ import { calculateMaxValue } from "../utils/chartUtils";
3
+ import { chartColors } from "../utils/chartColors";
4
+
5
+ interface SparkLineProps {
6
+ /** An ID for the root element */
7
+ id?: string;
8
+ /** Classes for the root element */
9
+ class?: ClassValue,
10
+ /** Styles for the root element */
11
+ style?: StyleValue,
12
+ data: number[];
13
+ color?: string,
14
+ height?: number,
15
+ width?: number,
16
+ }
17
+
18
+ export default function SparkLine($props: SparkLineProps) {
19
+ const defaultHeight = 20;
20
+ const defaultWidth = 100;
21
+
22
+ let container: HTMLElement;
23
+
24
+ let $state = $watch({
25
+ get calculatedHeight() {
26
+ return $props.height || defaultHeight;
27
+ },
28
+ get calculatedWidth() {
29
+ return $props.width || container?.clientWidth || defaultWidth;
30
+ },
31
+ get calculatedSeries() {
32
+ return [{ name: "", color: $props.color ?? "", data: $props.data }];
33
+ },
34
+ get maxValue() {
35
+ return calculateMaxValue($state.calculatedSeries);
36
+ },
37
+ get itemWidth() {
38
+ return $state.calculatedWidth / $props.data.length;
39
+ },
40
+ get valueHeight() {
41
+ return ($state.calculatedHeight - 4) / $state.maxValue;
42
+ },
43
+ get pointSeries() {
44
+ return $props.data.map((value, i) => {
45
+ const x = +(i * $state.itemWidth).toFixed(2);
46
+ const y = +($state.calculatedHeight - 2 - value * $state.valueHeight).toFixed(2);
47
+ return { x, y };
48
+ });
49
+ }
50
+ });
51
+
52
+ @render {
53
+ <div
54
+ {$props?.id}
55
+ class={["torp-spark-line", $props?.class]}
56
+ {$props?.style}
57
+ &ref={container}
58
+ >
59
+ <svg version="1.1" width={$state.calculatedWidth} height={$state.calculatedHeight}>
60
+ <g>
61
+ <polyline
62
+ points={$state.pointSeries.map((p) => `${p.x},${p.y}`).join(" ")}
63
+ stroke={$props.color || chartColors[0]}
64
+ stroke-width="2"
65
+ fill="none"
66
+ />
67
+ </g>
68
+ </svg>
69
+ </div>
70
+ }
71
+ }
@@ -0,0 +1,60 @@
1
+ interface XAxisProps {
2
+ showAxis: boolean,
3
+ height: number,
4
+ width: number,
5
+ itemWidth: number,
6
+ textHeight: number,
7
+ xLabel: string,
8
+ labels: string[] ,
9
+ stepLabels:number[] ,
10
+ stepValue: number,
11
+ chartLeft: number,
12
+ chartBottom: number,
13
+ }
14
+
15
+ export default function XAxis($props: XAxisProps) {
16
+ let $state = $watch({
17
+ chartLabelBottom: $props.xLabel ? $props.height - $props.textHeight : $props.height,
18
+ });
19
+
20
+ @render {
21
+ <svg>
22
+ @if ($props.showAxis) {
23
+ <line x1={$props.chartLeft} y1={$props.chartBottom} x2={$props.width} y2={$props.chartBottom} />
24
+ }
25
+ @if ($props.xLabel) {
26
+ <text
27
+ text-anchor="middle"
28
+ dominant-baseline="text-after-edge"
29
+ x={$props.width - ($props.width - $props.chartLeft) / 2}
30
+ y={$props.height}
31
+ >
32
+ {$props.xLabel}
33
+ </text>
34
+ }
35
+ @if ($props.stepLabels.length && $props.stepValue) {
36
+ @for (let [i, label] of $props.stepLabels.entries()) {
37
+ <text
38
+ text-anchor="middle"
39
+ dominant-baseline="text-after-edge"
40
+ x={$props.chartLeft + i * $props.stepValue * $props.itemWidth}
41
+ y={$state.chartLabelBottom}
42
+ >
43
+ {label}
44
+ </text>
45
+ }
46
+ } else {
47
+ @for (let [i, label] of $props.labels.entries()) {
48
+ <text
49
+ text-anchor="middle"
50
+ dominant-baseline="text-after-edge"
51
+ x={$props.chartLeft + $props.itemWidth * i + $props.itemWidth / 2}
52
+ y={$state.chartLabelBottom}
53
+ >
54
+ {label}
55
+ </text>
56
+ }
57
+ }
58
+ </svg>
59
+ }
60
+ }
@@ -0,0 +1,41 @@
1
+ interface YAxisProps {
2
+ showAxis: boolean,
3
+ valueHeight: number,
4
+ textHeight: number,
5
+ yLabel: string,
6
+ stepLabels: number[],
7
+ stepValue: number,
8
+ chartLeft: number,
9
+ chartBottom: number,
10
+ }
11
+
12
+ export default function YAxis($props: YAxisProps) {
13
+ @render {
14
+ <svg>
15
+ @if ($props.showAxis) {
16
+ <line x1={$props.chartLeft} y1={$props.chartBottom} x2={$props.chartLeft} y2={0} />
17
+ }
18
+ @if ($props.yLabel) {
19
+ <text
20
+ text-anchor="middle"
21
+ dominant-baseline="hanging"
22
+ x={0}
23
+ y={$props.chartBottom / 2}
24
+ transform={`rotate(-90, ${0}, ${$props.chartBottom / 2})`}
25
+ >
26
+ {$props.yLabel}
27
+ </text>
28
+ }
29
+ @for (let [i, label] of $props.stepLabels.entries()) {
30
+ <text
31
+ text-anchor="end"
32
+ dominant-baseline="middle"
33
+ x={$props.chartLeft - $props.textHeight / 4}
34
+ y={$props.chartBottom - i * $props.stepValue * $props.valueHeight}
35
+ >
36
+ {label}
37
+ </text>
38
+ }
39
+ </svg>
40
+ }
41
+ }
@@ -0,0 +1,220 @@
1
+ import { type SlotRender } from "@torpor/view";
2
+
3
+
4
+ interface BarChartProps {
5
+ /** An ID for the root element */
6
+ id?: string;
7
+ /** Classes for the root element */
8
+ class?: ClassValue,
9
+ /** Styles for the root element */
10
+ style?: StyleValue,
11
+ series: DataSeries[],
12
+ height?: number,
13
+ width?: number,
14
+ xLabel?: string,
15
+ yLabel?: string,
16
+ maxValue?: number,
17
+ stepCount?: number,
18
+ stepValue?: number,
19
+ hideXAxis?: boolean,
20
+ hideYAxis?: boolean,
21
+ showHLines?: boolean,
22
+ showVLines?: boolean,
23
+ }
24
+
25
+ declare function BarChart(
26
+ $parent: ParentNode,
27
+ $anchor: Node | null,
28
+ $props: BarChartProps,
29
+ $context?: Record<PropertyKey, any>,
30
+ $slots?: Record<string, SlotRender>,
31
+ ): void;
32
+
33
+
34
+
35
+ interface GridLinesProps {
36
+ /** An ID for the root element */
37
+ id?: string;
38
+ /** Classes for the root element */
39
+ class?: ClassValue,
40
+ /** Styles for the root element */
41
+ style?: StyleValue,
42
+ showHLines?: boolean,
43
+ showVLines?: boolean,
44
+ width: number;
45
+ labels: string[];
46
+ xStepValue: number;
47
+ xStepLabels: number[];
48
+ yStepValue: number;
49
+ yStepLabels: number[];
50
+ itemWidth: number;
51
+ valueHeight: number;
52
+ chartLeft: number;
53
+ chartBottom: number;
54
+ type: string;
55
+ }
56
+
57
+ declare function GridLines(
58
+ $parent: ParentNode,
59
+ $anchor: Node | null,
60
+ $props: GridLinesProps,
61
+ $context?: Record<PropertyKey, any>,
62
+ $slots?: Record<string, SlotRender>,
63
+ ): void;
64
+
65
+
66
+
67
+ interface LineChartProps {
68
+ /** An ID for the root element */
69
+ id?: string;
70
+ /** Classes for the root element */
71
+ class?: ClassValue,
72
+ /** Styles for the root element */
73
+ style?: StyleValue,
74
+ series: DataSeries[],
75
+ height?: number,
76
+ width?: number,
77
+ xLabel?: string,
78
+ yLabel?: string,
79
+ maxValue?: number,
80
+ stepCount?: number,
81
+ stepValue?: number,
82
+ showPoints?: boolean,
83
+ hideXAxis?: boolean,
84
+ hideYAxis?: boolean,
85
+ showHLines?: boolean,
86
+ showVLines?: boolean,
87
+ }
88
+
89
+ declare function LineChart(
90
+ $parent: ParentNode,
91
+ $anchor: Node | null,
92
+ $props: LineChartProps,
93
+ $context?: Record<PropertyKey, any>,
94
+ $slots?: Record<string, SlotRender>,
95
+ ): void;
96
+
97
+
98
+
99
+ interface PieChartProps {
100
+ /** An ID for the root element */
101
+ id?: string;
102
+ /** Classes for the root element */
103
+ class?: ClassValue,
104
+ /** Styles for the root element */
105
+ style?: StyleValue,
106
+ data: PieData[],
107
+ size?: number,
108
+ radius?: number,
109
+ cutout?: number,
110
+ }
111
+
112
+ declare function PieChart(
113
+ $parent: ParentNode,
114
+ $anchor: Node | null,
115
+ $props: PieChartProps,
116
+ $context?: Record<PropertyKey, any>,
117
+ $slots?: Record<string, SlotRender>,
118
+ ): void;
119
+
120
+
121
+
122
+ interface ScatterChartProps {
123
+ /** An ID for the root element */
124
+ id?: string;
125
+ /** Classes for the root element */
126
+ class?: ClassValue,
127
+ /** Styles for the root element */
128
+ style?: StyleValue,
129
+ series: DataSeries[],
130
+ height?: number,
131
+ width?: number,
132
+ xLabel?: string,
133
+ yLabel?: string,
134
+ xStepCount?: number,
135
+ xStepValue?: number,
136
+ yStepCount?: number,
137
+ yStepValue?: number,
138
+ hideXAxis?: boolean,
139
+ hideYAxis?: boolean,
140
+ showHLines?: boolean,
141
+ showVLines?: boolean,
142
+ }
143
+
144
+ declare function ScatterChart(
145
+ $parent: ParentNode,
146
+ $anchor: Node | null,
147
+ $props: ScatterChartProps,
148
+ $context?: Record<PropertyKey, any>,
149
+ $slots?: Record<string, SlotRender>,
150
+ ): void;
151
+
152
+
153
+
154
+ interface SparkLineProps {
155
+ /** An ID for the root element */
156
+ id?: string;
157
+ /** Classes for the root element */
158
+ class?: ClassValue,
159
+ /** Styles for the root element */
160
+ style?: StyleValue,
161
+ data: number[];
162
+ color?: string,
163
+ height?: number,
164
+ width?: number,
165
+ }
166
+
167
+ declare function SparkLine(
168
+ $parent: ParentNode,
169
+ $anchor: Node | null,
170
+ $props: SparkLineProps,
171
+ $context?: Record<PropertyKey, any>,
172
+ $slots?: Record<string, SlotRender>,
173
+ ): void;
174
+
175
+
176
+
177
+ interface XAxisProps {
178
+ showAxis: boolean,
179
+ height: number,
180
+ width: number,
181
+ itemWidth: number,
182
+ textHeight: number,
183
+ xLabel: string,
184
+ labels: string[] ,
185
+ stepLabels:number[] ,
186
+ stepValue: number,
187
+ chartLeft: number,
188
+ chartBottom: number,
189
+ }
190
+
191
+ declare function XAxis(
192
+ $parent: ParentNode,
193
+ $anchor: Node | null,
194
+ $props: XAxisProps,
195
+ $context?: Record<PropertyKey, any>,
196
+ $slots?: Record<string, SlotRender>,
197
+ ): void;
198
+
199
+
200
+
201
+ interface YAxisProps {
202
+ showAxis: boolean,
203
+ valueHeight: number,
204
+ textHeight: number,
205
+ yLabel: string,
206
+ stepLabels: number[],
207
+ stepValue: number,
208
+ chartLeft: number,
209
+ chartBottom: number,
210
+ }
211
+
212
+ declare function YAxis(
213
+ $parent: ParentNode,
214
+ $anchor: Node | null,
215
+ $props: YAxisProps,
216
+ $context?: Record<PropertyKey, any>,
217
+ $slots?: Record<string, SlotRender>,
218
+ ): void;
219
+
220
+ export { BarChart, GridLines, LineChart, PieChart, ScatterChart, SparkLine, XAxis, YAxis };
@@ -0,0 +1,34 @@
1
+ // src/Chart/BarChart.torp
2
+ import BarChart_default from "./BarChart.torp";
3
+
4
+ // src/Chart/GridLines.torp
5
+ import GridLines_default from "./GridLines.torp";
6
+
7
+ // src/Chart/LineChart.torp
8
+ import LineChart_default from "./LineChart.torp";
9
+
10
+ // src/Chart/PieChart.torp
11
+ import PieChart_default from "./PieChart.torp";
12
+
13
+ // src/Chart/ScatterChart.torp
14
+ import ScatterChart_default from "./ScatterChart.torp";
15
+
16
+ // src/Chart/SparkLine.torp
17
+ import SparkLine_default from "./SparkLine.torp";
18
+
19
+ // src/Chart/XAxis.torp
20
+ import XAxis_default from "./XAxis.torp";
21
+
22
+ // src/Chart/YAxis.torp
23
+ import YAxis_default from "./YAxis.torp";
24
+ export {
25
+ BarChart_default as BarChart,
26
+ GridLines_default as GridLines,
27
+ LineChart_default as LineChart,
28
+ PieChart_default as PieChart,
29
+ ScatterChart_default as ScatterChart,
30
+ SparkLine_default as SparkLine,
31
+ XAxis_default as XAxis,
32
+ YAxis_default as YAxis
33
+ };
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -19,6 +19,8 @@ interface TextAreaProps {
19
19
  placeholder?: string,
20
20
  /** Whether the input should be readonly */
21
21
  readonly?: boolean,
22
+ /** Whether the input's value is required */
23
+ required?: boolean,
22
24
  /** The maximum number of characters allowed for the input value */
23
25
  maxlength?: number,
24
26
  /** An ARIA label for describing the input to screen readers when there is no associated label element */
@@ -94,6 +96,7 @@ export default function TextArea($props: TextAreaProps | undefined) {
94
96
  {$props?.rows}
95
97
  {$props?.placeholder}
96
98
  {$props?.readonly}
99
+ {$props?.required}
97
100
  {$props?.maxlength}
98
101
  aria-label={$props?.ariaLabel}
99
102
  data-valid={$state.valid ? "valid" : "invalid"}
@@ -322,6 +322,8 @@ interface TextAreaProps {
322
322
  placeholder?: string,
323
323
  /** Whether the input should be readonly */
324
324
  readonly?: boolean,
325
+ /** Whether the input's value is required */
326
+ required?: boolean,
325
327
  /** The maximum number of characters allowed for the input value */
326
328
  maxlength?: number,
327
329
  /** An ARIA label for describing the input to screen readers when there is no associated label element */