@htmlbricks/hb-gauge 0.71.36 → 0.72.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/README.md CHANGED
@@ -1,109 +1,53 @@
1
- ## `hb-gauge` — gauge
1
+ # hb-gauge
2
2
 
3
- **Category:** data
4
- **Tags:** data, chart
3
+ **Category:** data · **Tags:** data, chart
5
4
 
6
- ### Overview
5
+ ## Summary
7
6
 
8
- `hb-gauge` is a web component that embeds **JustGage** (SVG gauges via Raphael; vendored as `libs/justgage.js` in this package) inside the shadow root. You pass a single JSON payload that mirrors JustGage’s configuration object. After mount, the library instantiates the gauge on an internal mount node; on destroy it tears the instance down cleanly.
7
+ **JustGage** SVG gauge inside the shadow root: pass **`options`** as JSON (or object from JS). Created on mount, destroyed on teardown, recreated on window **resize** (200 ms debounce) and when **`options`** is reparsed from a string.
9
8
 
10
- The gauge is **recreated** when the window is resized (handled with a **200 ms debounce**) so the SVG keeps a sensible size relative to the host. When `options` is supplied as a **string**, the component parses it with `JSON.parse`; if a gauge instance already exists, that parse path triggers a **rebuild** so the new JSON takes effect. (If you bind `options` as an object in a Svelte host, rely on resize or remount for full redraw unless your integration matches the string-based update path.)
11
-
12
- There are **no custom events** on this element (`Events` is empty in the public typings).
13
-
14
- ### Custom element
9
+ ## Custom element
15
10
 
16
11
  `hb-gauge`
17
12
 
18
- ### Attributes (snake_case; string values from HTML)
13
+ ## Attributes
19
14
 
20
- | Attribute | Required | Description |
15
+ | Attribute | Type (logical) | HTML / notes |
21
16
  | --- | --- | --- |
22
- | `options` | yes | JSON string describing the gauge. Merged with `{ element }` pointing at the internal `#gauge` node before constructing JustGage. You must include at least **`value`**, **`min`**, and **`max`** for a sensible dial; any additional keys supported by your bundled JustGage build (labels, colors, `gaugeWidthScale`, donut mode, etc.) can be added in the same object. |
23
- | `id` | no | Optional string identifier (forwarded through the component props). |
24
-
25
- From HTML, **`options` is always a string**: pass a serialized JSON object (see examples below). The implementation may parse that string when it runs as a web component.
26
-
27
- The authoring TypeScript type `Component` also lists optional `style`; the current Svelte implementation does not wire a dedicated `style` prop—you can still apply ordinary host styling (for example `width`, `height`, or `min-height`) on `<hb-gauge>` itself, and use **`--hb-gauge-min-height`** for layout reserve before paint.
28
-
29
- ### TypeScript shape (`Component`)
30
-
31
- For editors and wrappers that import `Component` from `types/webcomponent.type.d.ts`:
32
-
33
- - **`options`** — in typings this is modeled as `IGauge` (`value`, `min`, `max`). At runtime the same object is spread into JustGage, so real configs are often richer than `IGauge`; treat the type as a **minimum** contract and refer to JustGage for the full option surface.
34
- - **`id`** — optional string.
35
- - **`style`** — optional string in the type file only; see note above for styling the host.
36
-
37
- ### Events
17
+ | `options` | `string` \| `GaugeOptions` | **Required** for a useful chart. Merged with `{ element: #gauge }` before JustGage. Minimum: **`value`**, **`min`**, **`max`**; extra keys follow JustGage. |
18
+ | `id` | `string` (optional) | |
19
+ | `style` | `string` (optional) | Typings only; host `style` still applies to `<hb-gauge>`. |
38
20
 
39
- None declared for this component.
21
+ ## Custom events
40
22
 
41
- ### Styling
23
+ **None** — `Events` is `{}`.
42
24
 
43
- Bulma styles are included in the shadow bundle for consistency with other HTML Bricks components, but the visible gauge is drawn by JustGage (SVG), not Bulma layout primitives. Theme your app with **`--bulma-*`** tokens on the document if you want host-level consistency with the rest of the library.
25
+ ## Styling
44
26
 
45
- #### CSS custom properties
27
+ ### CSS custom properties (`extra/docs.ts`)
46
28
 
47
- | Variable | Description |
29
+ | Variable | Role |
48
30
  | --- | --- |
49
- | `--hb-gauge-min-height` | Minimum height of the `:host` element (default `0` in `styles/webcomponent.scss`). Use it when you need reserved vertical space before the gauge finishes laying out. |
31
+ | `--hb-gauge-min-height` | Reserved vertical space on `:host` before paint. |
50
32
 
51
- #### CSS parts
33
+ ### CSS parts (`extra/docs.ts`)
52
34
 
53
- | Part | Description |
35
+ | Part | Role |
54
36
  | --- | --- |
55
- | `gauge` | The JustGage mount node (`#gauge`). It is `width: 100%` by default; you can target this part to adjust width, height, or overflow behavior around the SVG. |
56
-
57
- #### Slots
58
-
59
- None.
60
-
61
- ### Examples
62
-
63
- **Minimal 0–100 gauge**
64
-
65
- ```html
66
- <hb-gauge options='{"value":50,"min":0,"max":100}'></hb-gauge>
67
- ```
68
-
69
- **Quarter of the scale**
37
+ | `gauge` | Mount node `#gauge` (`width: 100%`). |
70
38
 
71
- ```html
72
- <hb-gauge options='{"value":25,"min":0,"max":100}'></hb-gauge>
73
- ```
39
+ ### Slots
74
40
 
75
- **Wider numeric range**
41
+ **None.**
76
42
 
77
- ```html
78
- <hb-gauge options='{"value":250,"min":0,"max":500}'></hb-gauge>
79
- ```
43
+ Bulma is bundled for consistency; the visible dial is SVG from JustGage.
80
44
 
81
- **Value at the upper bound**
45
+ ## TypeScript
82
46
 
83
- ```html
84
- <hb-gauge options='{"value":100,"min":0,"max":100}'></hb-gauge>
85
- ```
47
+ `types/webcomponent.type.d.ts` — `Component`, `IGauge`, `GaugeOptions`, `Events`.
86
48
 
87
- **Host sizing and minimum height**
49
+ ## Minimal HTML example
88
50
 
89
51
  ```html
90
- <hb-gauge
91
- style="width: 280px; height: 200px;"
92
- options='{"value":72,"min":0,"max":100}'
93
- ></hb-gauge>
94
- ```
95
-
96
- ```html
97
- <hb-gauge
98
- style="width: 100%;"
99
- options='{"value":10,"min":0,"max":100}'
100
- ></hb-gauge>
52
+ <hb-gauge options='{"value":50,"min":0,"max":100}'></hb-gauge>
101
53
  ```
102
-
103
- (Combine `style` on the custom element with `--hb-gauge-min-height` in your page CSS if you need a stable block size before the gauge renders.)
104
-
105
- ### Implementation notes
106
-
107
- - The mount target is `<div part="gauge" id="gauge" style="width:100%">` inside the shadow tree; JustGage receives `Object.assign({ element: gaugeEl }, options)`.
108
- - If `options` arrives as a string, it is `JSON.parse`’d in an effect; when both the mount node and an existing instance exist, the gauge is **recreated** to pick up the new config.
109
- - Console logging is present in the source around mount for debugging (`gaugeEl`); remove or silence in production builds if that matters for your environment.
package/manifest.json CHANGED
@@ -21,7 +21,15 @@
21
21
  "type": "string"
22
22
  },
23
23
  "options": {
24
- "$ref": "#/definitions/IGauge"
24
+ "anyOf": [
25
+ {
26
+ "type": "string"
27
+ },
28
+ {
29
+ "$ref": "#/definitions/GaugeOptions"
30
+ }
31
+ ],
32
+ "description": "JSON string from HTML, or an object when set from JavaScript."
25
33
  },
26
34
  "style": {
27
35
  "type": "string"
@@ -32,8 +40,8 @@
32
40
  ],
33
41
  "type": "object"
34
42
  },
35
- "IGauge": {
36
- "additionalProperties": false,
43
+ "GaugeOptions": {
44
+ "description": "JustGage constructor options merged with `{ element }` in the component.",
37
45
  "properties": {
38
46
  "max": {
39
47
  "type": "number"
@@ -46,9 +54,9 @@
46
54
  }
47
55
  },
48
56
  "required": [
49
- "value",
57
+ "max",
50
58
  "min",
51
- "max"
59
+ "value"
52
60
  ],
53
61
  "type": "object"
54
62
  }
@@ -148,5 +156,5 @@
148
156
  "size": {},
149
157
  "iifePath": "main.iife.js",
150
158
  "repoName": "@htmlbricks/hb-gauge",
151
- "version": "0.71.36"
159
+ "version": "0.72.0"
152
160
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htmlbricks/hb-gauge",
3
- "version": "0.71.36",
3
+ "version": "0.72.0",
4
4
  "contributors": [],
5
5
  "description": "SVG gauge wrapper around JustGage: pass JustGage-compatible options as JSON (`value`, min/max, labels, colors, etc.). The gauge is created on the shadow host after mount, destroyed on teardown, and recreated when `options` changes or the window resizes (debounced) so it stays sized correctly.",
6
6
  "licenses": [
@@ -9,7 +9,15 @@
9
9
  "type": "string"
10
10
  },
11
11
  "options": {
12
- "$ref": "#/definitions/IGauge"
12
+ "anyOf": [
13
+ {
14
+ "type": "string"
15
+ },
16
+ {
17
+ "$ref": "#/definitions/GaugeOptions"
18
+ }
19
+ ],
20
+ "description": "JSON string from HTML, or an object when set from JavaScript."
13
21
  },
14
22
  "style": {
15
23
  "type": "string"
@@ -20,8 +28,8 @@
20
28
  ],
21
29
  "type": "object"
22
30
  },
23
- "IGauge": {
24
- "additionalProperties": false,
31
+ "GaugeOptions": {
32
+ "description": "JustGage constructor options merged with `{ element }` in the component.",
25
33
  "properties": {
26
34
  "max": {
27
35
  "type": "number"
@@ -34,9 +42,9 @@
34
42
  }
35
43
  },
36
44
  "required": [
37
- "value",
45
+ "max",
38
46
  "min",
39
- "max"
47
+ "value"
40
48
  ],
41
49
  "type": "object"
42
50
  }
@@ -4,10 +4,14 @@ export type IGauge = {
4
4
  max: number;
5
5
  };
6
6
 
7
+ /** JustGage constructor options merged with `{ element }` in the component. */
8
+ export type GaugeOptions = IGauge & Record<string, unknown>;
9
+
7
10
  export type Component = {
8
11
  id?: string;
9
12
  style?: string;
10
- options: IGauge;
13
+ /** JSON string from HTML, or an object when set from JavaScript. */
14
+ options: string | GaugeOptions;
11
15
  };
12
16
 
13
17
  export type Events = {};