@wayke-se/ev-web 1.0.0-beta.1 → 1.0.0-beta.2
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 +136 -224
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ Upgrading from 0.x? See [Migrating from 0.x to 1.0](#migrating-from-0x-to-10).
|
|
|
6
6
|
|
|
7
7
|
## Quick start
|
|
8
8
|
|
|
9
|
-
Add this where the calculator should be shown, and replace `<vehicle id>` with the id of the vehicle's ad at Wayke
|
|
9
|
+
Add this where the calculator should be shown, and replace `<vehicle id>` with the id of the vehicle's ad at Wayke:
|
|
10
10
|
|
|
11
11
|
```html
|
|
12
12
|
<div id="wayke-ev"></div>
|
|
@@ -17,87 +17,14 @@ Add this where the calculator should be shown, and replace `<vehicle id>` with t
|
|
|
17
17
|
</script>
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
<summary>The same snippet for Wayke's test environment</summary>
|
|
22
|
-
|
|
23
|
-
For a staging site or `localhost`, registered in Wayke's test environment. See [Environments](#environments).
|
|
24
|
-
|
|
25
|
-
```html
|
|
26
|
-
<div id="wayke-ev"></div>
|
|
27
|
-
<script type="module">
|
|
28
|
-
import { mount } from 'https://cdn.wayke.se/public-assets/wayke-ev-web/1.0.0/index.js';
|
|
29
|
-
|
|
30
|
-
mount('#wayke-ev', { id: '<vehicle id>', environment: 'test' });
|
|
31
|
-
</script>
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
</details>
|
|
35
|
-
|
|
36
|
-
Three things to know:
|
|
37
|
-
|
|
38
|
-
* **Your domain has to be registered with Wayke.** Wayke recognizes the site by its domain. Until the domain is registered, nothing is shown. Ask your contact at Wayke to register it, and see [Environments](#environments) for development.
|
|
39
|
-
* **Only battery-electric cars have a charging cost.** For any other vehicle nothing is shown, so the snippet can be on every vehicle page. See [When nothing is shown](#when-nothing-is-shown).
|
|
40
|
-
* **The calculator uses the font of your page.** Set the colors to match your site, see [Colors and fonts](#colors-and-fonts).
|
|
41
|
-
|
|
42
|
-
## Contents
|
|
43
|
-
|
|
44
|
-
* [Add to your site](#add-to-your-site): [CDN](#cdn), [npm](#npm)
|
|
45
|
-
* [Environments](#environments)
|
|
46
|
-
* [Options](#options)
|
|
47
|
-
* [Passing the figures yourself](#passing-the-figures-yourself)
|
|
48
|
-
* [When nothing is shown](#when-nothing-is-shown)
|
|
49
|
-
* [Colors and fonts](#colors-and-fonts)
|
|
50
|
-
* [Events](#events)
|
|
51
|
-
* [How the cost is calculated](#how-the-cost-is-calculated)
|
|
52
|
-
* [Development](#development)
|
|
53
|
-
* [Migrating from 0.x to 1.0](#migrating-from-0x-to-10)
|
|
54
|
-
|
|
55
|
-
## Add to your site
|
|
20
|
+
Two things to know:
|
|
56
21
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
| Any website, without a build step, such as a CMS or static HTML | [CDN](#cdn) |
|
|
60
|
-
| A website with its own bundler (Vite, webpack, Next.js, ...) | [npm](#npm) |
|
|
61
|
-
|
|
62
|
-
### CDN
|
|
63
|
-
|
|
64
|
-
Every release is published to the Wayke CDN. Nothing needs to be installed.
|
|
65
|
-
|
|
66
|
-
```
|
|
67
|
-
https://cdn.wayke.se/public-assets/wayke-ev-web/<version>/index.js
|
|
68
|
-
```
|
|
22
|
+
* **Your domain has to be registered with Wayke.** Until it is, nothing is shown. Ask your contact at Wayke to register it.
|
|
23
|
+
* **Only battery-electric cars have a charging cost.** For any other vehicle nothing is shown, so the snippet can be on every vehicle page.
|
|
69
24
|
|
|
70
|
-
|
|
25
|
+
That is all most sites need. The rest of this page covers npm, the options and the details.
|
|
71
26
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
**Option A: import** (recommended) is the snippet in [Quick start](#quick-start).
|
|
75
|
-
|
|
76
|
-
**Option B: script tag.** The script sets `window.WaykeEv` when it has loaded. Module scripts run after the page has been read, so wait for `DOMContentLoaded` before you use it. If the snippet is added after the page has loaded, for example by a tag manager, `DOMContentLoaded` has already happened, so use option A.
|
|
77
|
-
|
|
78
|
-
```html
|
|
79
|
-
<div id="wayke-ev"></div>
|
|
80
|
-
<script type="module" src="https://cdn.wayke.se/public-assets/wayke-ev-web/1.0.0/index.js"></script>
|
|
81
|
-
<script>
|
|
82
|
-
window.addEventListener('DOMContentLoaded', () => {
|
|
83
|
-
WaykeEv.mount('#wayke-ev', { id: '<vehicle id>' });
|
|
84
|
-
});
|
|
85
|
-
</script>
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
#### Stylesheet
|
|
89
|
-
|
|
90
|
-
The script adds its stylesheet, `index.css` in the same folder, to the top of `<head>`, and shows the calculator when it has loaded. Since it is added first, the styles of your site override it.
|
|
91
|
-
|
|
92
|
-
To load the stylesheet yourself, add a `<link>` to it with the same URL. The script finds it and does not add it again.
|
|
93
|
-
|
|
94
|
-
```html
|
|
95
|
-
<link rel="stylesheet" href="https://cdn.wayke.se/public-assets/wayke-ev-web/1.0.0/index.css">
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
To not load the stylesheet at all, add `disablecssinjection` to the script tag in option B. The calculator is then unstyled.
|
|
99
|
-
|
|
100
|
-
### npm
|
|
27
|
+
## With npm
|
|
101
28
|
|
|
102
29
|
```bash
|
|
103
30
|
npm install @wayke-se/ev-web
|
|
@@ -109,11 +36,14 @@ import '@wayke-se/ev-web/style.css';
|
|
|
109
36
|
|
|
110
37
|
const calculator = mount('#wayke-ev', { id: '<vehicle id>' });
|
|
111
38
|
|
|
112
|
-
// When the element goes away
|
|
39
|
+
// When the element goes away:
|
|
113
40
|
calculator.unmount();
|
|
114
41
|
```
|
|
115
42
|
|
|
116
|
-
The first argument is a CSS selector or an element. The package is ESM only, has no dependencies
|
|
43
|
+
The first argument is a CSS selector or an element. The package is ESM only, has no dependencies and comes with TypeScript types. It needs a browser, so call `mount` on the client.
|
|
44
|
+
|
|
45
|
+
<details>
|
|
46
|
+
<summary>In React</summary>
|
|
117
47
|
|
|
118
48
|
```tsx
|
|
119
49
|
import { useEffect, useRef } from 'react';
|
|
@@ -133,44 +63,90 @@ export const ChargingCost = ({ id }: { id: string }) => {
|
|
|
133
63
|
};
|
|
134
64
|
```
|
|
135
65
|
|
|
136
|
-
|
|
66
|
+
</details>
|
|
137
67
|
|
|
138
|
-
|
|
139
|
-
|---------------|-------|------------------------------|
|
|
140
|
-
| `production` (default) | The vehicles on wayke.se and drive.no | Wayke's production environment |
|
|
141
|
-
| `test` | Test vehicles | Wayke's test environment |
|
|
68
|
+
## Options
|
|
142
69
|
|
|
143
|
-
|
|
70
|
+
Either `id` or `data` is required. Everything else is optional.
|
|
144
71
|
|
|
145
|
-
|
|
72
|
+
| Option | Default | |
|
|
73
|
+
|--------|---------|---|
|
|
74
|
+
| `id` | | The id of the vehicle's ad at Wayke. The calculator fetches the figures itself. |
|
|
75
|
+
| `data` | | The figures, when your page already has them. See [Passing the figures yourself](#passing-the-figures-yourself). |
|
|
76
|
+
| `environment` | `'production'` | `'test'` uses Wayke's test environment, see [Test environment](#test-environment). |
|
|
77
|
+
| `apiKey` | The origin of the page | Identifies the site instead of its domain. |
|
|
78
|
+
| `marketCode` | The market of the vehicle | `'SE'` or `'NO'`. Sweden counts the distance in mil, Norway in km. |
|
|
79
|
+
| `language` | `sv` in Sweden, `nb` in Norway | `'sv'`, `'nb'` or `'en'`. |
|
|
80
|
+
| `theme` | | Your colors, see [Colors and fonts](#colors-and-fonts). |
|
|
81
|
+
| `hash` | `false` | Adds `#wayke-ev` to the url while the calculator dialog is open, so the browser's back button closes it. Useful on mobile, where the dialog covers the screen. |
|
|
82
|
+
| `onEvent` | | See [Events](#events). |
|
|
146
83
|
|
|
147
|
-
|
|
84
|
+
`mount` returns `{ unmount }`. It throws if no element matches the target, or if neither `id` nor `data` is given. It never throws for a vehicle or a network problem: nothing is shown, and [`onEvent`](#events) tells you why.
|
|
148
85
|
|
|
149
|
-
|
|
150
|
-
|
|
86
|
+
## Colors and fonts
|
|
87
|
+
|
|
88
|
+
The calculator has no font of its own and inherits the font of your page. Its accents are turquoise until you set your own colors:
|
|
89
|
+
|
|
90
|
+
```js
|
|
91
|
+
mount('#wayke-ev', {
|
|
92
|
+
id: '<vehicle id>',
|
|
93
|
+
theme: {
|
|
94
|
+
primaryColor: '#227a29', // slider and radio buttons
|
|
95
|
+
primaryColorForeground: '#ffffff', // placed on top of primaryColor
|
|
96
|
+
linkColor: '#19b52f',
|
|
97
|
+
},
|
|
98
|
+
});
|
|
151
99
|
```
|
|
152
100
|
|
|
153
|
-
|
|
101
|
+
To change more, add your own CSS. All class names start with `waykeev-`, inside `.waykeev-root`, and a class selector of yours always wins over the calculator's own styles. The class names can change between versions, so check your CSS when you update.
|
|
154
102
|
|
|
155
|
-
|
|
156
|
-
|--------|------|---------|---|
|
|
157
|
-
| `id` | `string` | | The id of the vehicle's ad at Wayke. The calculator fetches the figures itself. |
|
|
158
|
-
| `data` | [`ChargingData`](#passing-the-figures-yourself) | | The figures, when your page already has them. No request is made. |
|
|
159
|
-
| `environment` | `'production' \| 'test'` | `'production'` | See [Environments](#environments). |
|
|
160
|
-
| `apiKey` | `string` | The origin of the page | Identifies the site instead of its domain. |
|
|
161
|
-
| `marketCode` | `'SE' \| 'NO'` | The market of the vehicle | Sweden counts the distance in mil and Norway in km. |
|
|
162
|
-
| `language` | `'sv' \| 'nb' \| 'en'` | `sv` in Sweden, `nb` in Norway | |
|
|
163
|
-
| `theme` | `{ primaryColor?, primaryColorForeground?, linkColor? }` | | See [Colors and fonts](#colors-and-fonts). |
|
|
164
|
-
| `hash` | `boolean` | `false` | Adds `#wayke-ev` to the url while the calculator dialog is open, so the browser's back button closes it. Useful on mobile, where the dialog covers the screen. |
|
|
165
|
-
| `onEvent` | `(event) => void` | | See [Events](#events). |
|
|
103
|
+
## Events
|
|
166
104
|
|
|
167
|
-
`
|
|
105
|
+
`onEvent` is called with one object, and `type` tells the events apart.
|
|
168
106
|
|
|
169
|
-
|
|
107
|
+
| `type` | Other fields | When |
|
|
108
|
+
|--------|--------------|------|
|
|
109
|
+
| `ready` | `data` | The calculator is on the page. |
|
|
110
|
+
| `unavailable` | `reason` | Nothing is shown: the vehicle has no charging cost. |
|
|
111
|
+
| `error` | `reason` | Nothing is shown: the request failed. |
|
|
112
|
+
| `distance-change` | `distanceKm`, `control` | The visitor changed the yearly distance. In km in both markets. `control` is `'slider'` or `'select'`. |
|
|
113
|
+
| `modal-open`, `modal-close` | | The dialog for an own electricity price. |
|
|
114
|
+
| `price-option-change` | `priceOption` | `'standard'` or `'custom'`. |
|
|
115
|
+
| `custom-price-change` | `pricePerKwh` | The visitor's own price per kWh, in the market's currency: 1.5 for 150 öre. |
|
|
116
|
+
|
|
117
|
+
The calculator takes no space until it has figures to show, so your page keeps its layout. When nothing is shown, `reason` is one of:
|
|
118
|
+
|
|
119
|
+
| `type` | `reason` | Meaning |
|
|
120
|
+
|--------|----------|---------|
|
|
121
|
+
| `unavailable` | `no-charging-data` | The vehicle is not battery-electric, or Wayke lacks the data to estimate its cost. |
|
|
122
|
+
| `unavailable` | `not-found` | No published vehicle has this id in this environment. |
|
|
123
|
+
| `error` | `unauthorized` | The domain of the page, or `apiKey`, is not registered with Wayke in this environment. |
|
|
124
|
+
| `error` | `rate-limited`, `network`, `server` | The request did not succeed. |
|
|
125
|
+
|
|
126
|
+
To show a heading of your own only when there is a calculator, wait for `ready`:
|
|
127
|
+
|
|
128
|
+
```js
|
|
129
|
+
mount('#wayke-ev', {
|
|
130
|
+
id: '<vehicle id>',
|
|
131
|
+
onEvent: (event) => {
|
|
132
|
+
if (event.type === 'ready') document.querySelector('#charging-heading').hidden = false;
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Test environment
|
|
138
|
+
|
|
139
|
+
Set `environment: 'test'` while you develop, to work with Wayke's test vehicles:
|
|
140
|
+
|
|
141
|
+
```js
|
|
142
|
+
mount('#wayke-ev', { id: '<vehicle id>', environment: 'test' });
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
The domain has to be registered in the environment you use, so have `localhost` or your staging domain registered in test. A vehicle id belongs to one environment: an id from production is unknown in test.
|
|
170
146
|
|
|
171
147
|
## Passing the figures yourself
|
|
172
148
|
|
|
173
|
-
If your page already reads the vehicle from Wayke's GraphQL API, pass the figures as `data`. The calculator then makes no request
|
|
149
|
+
If your page already reads the vehicle from Wayke's GraphQL API, pass the figures as `data`. The calculator then makes no request and is on the page at once.
|
|
174
150
|
|
|
175
151
|
```ts
|
|
176
152
|
import { mount, type ChargingData } from '@wayke-se/ev-web';
|
|
@@ -187,7 +163,10 @@ const data: ChargingData = {
|
|
|
187
163
|
mount('#wayke-ev', { data });
|
|
188
164
|
```
|
|
189
165
|
|
|
190
|
-
|
|
166
|
+
<details>
|
|
167
|
+
<summary>Where the figures are in the GraphQL API</summary>
|
|
168
|
+
|
|
169
|
+
They are attributes of the vehicle. The three `charging*` attributes are `null` for a vehicle without a charging cost.
|
|
191
170
|
|
|
192
171
|
```graphql
|
|
193
172
|
query ($id: ID!) {
|
|
@@ -211,87 +190,7 @@ query ($id: ID!) {
|
|
|
211
190
|
}
|
|
212
191
|
```
|
|
213
192
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
## When nothing is shown
|
|
217
|
-
|
|
218
|
-
The calculator takes no space until it has figures to show, and stays empty when it has none. Your page keeps its layout, and `onEvent` tells you why:
|
|
219
|
-
|
|
220
|
-
| Event | `reason` | Meaning |
|
|
221
|
-
|-------|----------|---------|
|
|
222
|
-
| `unavailable` | `no-charging-data` | The vehicle is not battery-electric (petrol, diesel and plug-in hybrids have no charging cost), or Wayke lacks the data to estimate its cost. |
|
|
223
|
-
| `unavailable` | `not-found` | No published vehicle has this id in this environment. |
|
|
224
|
-
| `error` | `unauthorized` | The domain of the page, or `apiKey`, is not registered with Wayke in this environment. |
|
|
225
|
-
| `error` | `rate-limited` | Too many requests from the site in a short time. |
|
|
226
|
-
| `error` | `network` | The request did not reach Wayke. |
|
|
227
|
-
| `error` | `server` | Wayke answered with an error. |
|
|
228
|
-
|
|
229
|
-
To show a section heading only when there is a calculator, wait for `ready`:
|
|
230
|
-
|
|
231
|
-
```js
|
|
232
|
-
mount('#wayke-ev', {
|
|
233
|
-
id,
|
|
234
|
-
onEvent: (event) => {
|
|
235
|
-
if (event.type === 'ready') document.querySelector('#charging-section').hidden = false;
|
|
236
|
-
},
|
|
237
|
-
});
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
## Colors and fonts
|
|
241
|
-
|
|
242
|
-
The calculator has no font of its own and inherits the font of your page. Its accents are turquoise until you set your own colors:
|
|
243
|
-
|
|
244
|
-
```js
|
|
245
|
-
mount('#wayke-ev', {
|
|
246
|
-
id,
|
|
247
|
-
theme: {
|
|
248
|
-
primaryColor: '#227a29', // slider and radio buttons
|
|
249
|
-
primaryColorForeground: '#ffffff', // placed on top of primaryColor
|
|
250
|
-
linkColor: '#19b52f',
|
|
251
|
-
},
|
|
252
|
-
});
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
The theme is set per calculator, so two on the same page can differ.
|
|
256
|
-
|
|
257
|
-
To change more than the colors, add your own CSS. All class names start with `waykeev-`, and the calculator is wrapped in `.waykeev-root`. Its own element styles sit inside `:where()`, so a class selector of yours always wins:
|
|
258
|
-
|
|
259
|
-
```css
|
|
260
|
-
.waykeev-root .waykeev-heading {
|
|
261
|
-
font-family: 'Your Heading Font', sans-serif;
|
|
262
|
-
}
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
The class names are not part of the public API and can change between versions, so check your CSS when you update.
|
|
266
|
-
|
|
267
|
-
The calculator never changes the styles of your page. Your page can change the calculator though: a rule on an element, such as `button { ... }` or `h2 { ... }`, also applies inside it. If something looks off, look for such a rule first.
|
|
268
|
-
|
|
269
|
-
## Events
|
|
270
|
-
|
|
271
|
-
`onEvent` is called with one object. `type` tells the events apart.
|
|
272
|
-
|
|
273
|
-
| `type` | Other fields | When |
|
|
274
|
-
|--------|--------------|------|
|
|
275
|
-
| `ready` | `data` | The calculator is on the page. `data` is the figures it shows. Like every event, it is delivered after `mount` has returned. |
|
|
276
|
-
| `unavailable` | `reason` | Nothing is shown, see [When nothing is shown](#when-nothing-is-shown). |
|
|
277
|
-
| `error` | `reason` | Nothing is shown, see [When nothing is shown](#when-nothing-is-shown). |
|
|
278
|
-
| `distance-change` | `distanceKm`, `control` | The visitor changed the yearly distance. `distanceKm` is in km in both markets, `control` is `'slider'` or `'select'`. |
|
|
279
|
-
| `modal-open` | | The visitor opened the dialog for their own electricity price. |
|
|
280
|
-
| `modal-close` | | The dialog was closed. |
|
|
281
|
-
| `price-option-change` | `priceOption` | `'standard'` or `'custom'`. |
|
|
282
|
-
| `custom-price-change` | `pricePerKwh` | The visitor entered their own price. In the market's currency per kWh, so 1.5 for 150 öre. |
|
|
283
|
-
|
|
284
|
-
```ts
|
|
285
|
-
import { mount, type EvEvent } from '@wayke-se/ev-web';
|
|
286
|
-
|
|
287
|
-
const onEvent = (event: EvEvent) => {
|
|
288
|
-
if (event.type === 'distance-change') {
|
|
289
|
-
analytics.track('charging_distance', { km: event.distanceKm });
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
|
-
|
|
293
|
-
mount('#wayke-ev', { id, onEvent });
|
|
294
|
-
```
|
|
193
|
+
</details>
|
|
295
194
|
|
|
296
195
|
## How the cost is calculated
|
|
297
196
|
|
|
@@ -299,32 +198,38 @@ mount('#wayke-ev', { id, onEvent });
|
|
|
299
198
|
cost per month = energy per km × price per kWh × distance per year / 12
|
|
300
199
|
```
|
|
301
200
|
|
|
302
|
-
* **Energy per km** comes from Wayke
|
|
303
|
-
* **Price per kWh** is Wayke's template price for the market, with energy tax and VAT included. The grid fee is not included.
|
|
201
|
+
* **Energy per km** comes from Wayke: the energy drawn from the socket, charging losses included, based on the car's WLTP figures.
|
|
202
|
+
* **Price per kWh** is Wayke's template price for the market, with energy tax and VAT included. The grid fee is not included. The visitor can enter their own price instead, which is calculated in the browser without a request.
|
|
304
203
|
* **Distance per year** is chosen by the visitor: 500 to 5 000 mil in Sweden, 5 000 to 50 000 km in Norway.
|
|
305
204
|
|
|
306
|
-
|
|
205
|
+
## CDN details
|
|
307
206
|
|
|
308
|
-
|
|
207
|
+
Every release is published to `https://cdn.wayke.se/public-assets/wayke-ev-web/<version>/index.js`. Use an exact version: its files never change, so your site only changes when you update the version in the snippet. The latest version is shown on [npm](https://www.npmjs.com/package/@wayke-se/ev-web).
|
|
309
208
|
|
|
310
|
-
|
|
311
|
-
npm install
|
|
312
|
-
npm start # the development page on http://localhost:5000, against Wayke's test environment
|
|
313
|
-
npm test # lint, types, stylelint and unit tests
|
|
314
|
-
npm run build # dist/ for npm and dist-cdn/ for the CDN
|
|
315
|
-
```
|
|
209
|
+
The script adds its stylesheet, `index.css` in the same folder, to the top of `<head>`, so the styles of your site override it. To load the stylesheet yourself, add a `<link>` to it with the same URL, and the script does not add it again.
|
|
316
210
|
|
|
317
|
-
|
|
211
|
+
<details>
|
|
212
|
+
<summary>With a script tag instead of import</summary>
|
|
318
213
|
|
|
319
|
-
|
|
214
|
+
The script sets `window.WaykeEv` when it has loaded. Module scripts run after the page has been read, so wait for `DOMContentLoaded`. If the snippet is added after the page has loaded, for example by a tag manager, use the import in [Quick start](#quick-start) instead.
|
|
320
215
|
|
|
321
|
-
|
|
216
|
+
```html
|
|
217
|
+
<div id="wayke-ev"></div>
|
|
218
|
+
<script type="module" src="https://cdn.wayke.se/public-assets/wayke-ev-web/1.0.0/index.js"></script>
|
|
219
|
+
<script>
|
|
220
|
+
window.addEventListener('DOMContentLoaded', () => {
|
|
221
|
+
WaykeEv.mount('#wayke-ev', { id: '<vehicle id>' });
|
|
222
|
+
});
|
|
223
|
+
</script>
|
|
224
|
+
```
|
|
322
225
|
|
|
323
|
-
|
|
226
|
+
Add `disablecssinjection` to the script tag to not load the stylesheet at all. The calculator is then unstyled.
|
|
324
227
|
|
|
325
|
-
|
|
228
|
+
</details>
|
|
229
|
+
|
|
230
|
+
## Migrating from 0.x to 1.0
|
|
326
231
|
|
|
327
|
-
|
|
232
|
+
1.0 is a rewrite. The calculator looks the same, is a fifth of the size, and no longer makes a request for an own electricity price.
|
|
328
233
|
|
|
329
234
|
```js
|
|
330
235
|
// 0.x
|
|
@@ -345,40 +250,47 @@ import '@wayke-se/ev-web/style.css';
|
|
|
345
250
|
mount('#custom-id', { id: '4a18e9a4-f7ee-458e-8bb4-9b6b8b778bbf' });
|
|
346
251
|
```
|
|
347
252
|
|
|
348
|
-
**2. Options.**
|
|
349
|
-
|
|
350
253
|
| 0.x | 1.0 |
|
|
351
254
|
|-----|-----|
|
|
255
|
+
| `new WaykeEvWeb(options)` | `mount(target, options)` |
|
|
256
|
+
| `@wayke-se/ev-web/dist/index.css` | `@wayke-se/ev-web/style.css` |
|
|
257
|
+
| `window.WaykeEvWeb` (CDN) | `window.WaykeEv.mount`, or import `mount` from the script |
|
|
352
258
|
| `url: 'https://api.wayke.se'` | Remove it. Production is the default. |
|
|
353
259
|
| `url: 'https://api.wayketech.se'` | `environment: 'test'` |
|
|
354
|
-
| `rootId: 'custom-id'` | The first argument
|
|
260
|
+
| `rootId: 'custom-id'` | The first argument, `'#custom-id'`. It is required: the calculator is no longer added to `<body>` without it. |
|
|
355
261
|
| `marketCode` | Optional. The market follows the vehicle. |
|
|
356
262
|
| `theme`, `hash` | Unchanged. |
|
|
357
|
-
| `onEvent: (view, event, data) => ...` | `onEvent: (event) => ...`, see below. |
|
|
358
|
-
|
|
359
|
-
**3. The stylesheet** is imported from `@wayke-se/ev-web/style.css` instead of `@wayke-se/ev-web/dist/index.css`.
|
|
360
|
-
|
|
361
|
-
**4. CDN.** The script now exports `mount`, and `window.WaykeEvWeb` is replaced by `window.WaykeEv.mount`. See [CDN](#cdn).
|
|
263
|
+
| `onEvent: (view, event, data) => ...` | `onEvent: (event) => ...`, with new names, see below. |
|
|
362
264
|
|
|
363
|
-
|
|
265
|
+
Events:
|
|
364
266
|
|
|
365
267
|
| 0.x | 1.0 |
|
|
366
268
|
|-----|-----|
|
|
367
|
-
| `INITIALIZED`, `INITIAL_REQUEST_PENDING` | Removed. |
|
|
368
269
|
| `INITIAL_REQUEST_SUCCEEDED` | `ready` |
|
|
369
270
|
| `INITIAL_REQUEST_FAILED` | `unavailable` or `error`, with a `reason` |
|
|
370
271
|
| `DISTANCE_SLIDER`, `DISTANCE_SELECT` | `distance-change` with `control` |
|
|
371
272
|
| `MODAL_OPENED`, `MODAL_CLOSED` | `modal-open`, `modal-close` |
|
|
372
|
-
| `TOGGLE_PRICE` | `price-option-change
|
|
373
|
-
| `CUSTOM_PRICE_CHANGE` | `custom-price-change
|
|
374
|
-
| `
|
|
273
|
+
| `TOGGLE_PRICE` | `price-option-change`, with `'standard'` or `'custom'` (was `'standardPrice'` or `'customPrice'`) |
|
|
274
|
+
| `CUSTOM_PRICE_CHANGE` | `custom-price-change`, with `pricePerKwh` in kronor (`customPrice` was in öre) |
|
|
275
|
+
| `INITIALIZED`, `INITIAL_REQUEST_PENDING`, `REQUEST_CUSTOM_PRICE_*` | Removed |
|
|
375
276
|
|
|
376
|
-
|
|
277
|
+
Also different:
|
|
377
278
|
|
|
378
|
-
* **
|
|
379
|
-
* **The fonts are gone.** 0.x came with Wayke's and Drive's fonts
|
|
279
|
+
* **A registration number is no longer accepted as `id`.** Use the id of the vehicle's ad at Wayke.
|
|
280
|
+
* **The fonts are gone.** 0.x came with Wayke's and Drive's fonts, 1.0 uses the font of your page.
|
|
380
281
|
* **More cars get a cost.** 0.x showed nothing for a car without a battery capacity at Wayke. 1.0 then uses the car's WLTP consumption.
|
|
381
|
-
* **
|
|
382
|
-
* **
|
|
383
|
-
|
|
384
|
-
|
|
282
|
+
* **The package is ESM only.** `require('@wayke-se/ev-web')` no longer works.
|
|
283
|
+
* **If nothing is shown after the upgrade**, `onEvent` gets `error` with the reason `unauthorized` when the domain is not registered. Ask your contact at Wayke to check the registration.
|
|
284
|
+
|
|
285
|
+
## Development
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
npm install
|
|
289
|
+
npm start # the development page on http://localhost:5000, against Wayke's test environment
|
|
290
|
+
npm test # lint, types, stylelint and unit tests
|
|
291
|
+
npm run build # dist/ for npm and dist-cdn/ for the CDN
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
The origin of the development page has to be registered in Wayke's test environment. `PORT=5050 npm start` uses another port, and `WAYKE_API_KEY=<key> npm start` identifies the page with a key instead of its origin.
|
|
295
|
+
|
|
296
|
+
A push to `main` or `test` releases the version in `package.json` to the CDN and npm. A pre-release version, such as `1.1.0-beta.1`, gets the npm tag `next`, and so does everything released from `test`. Only a plain version on `main` becomes `latest`. A version that is already published is refused, so bump the version first. The release log prints the CDN url the files are served from.
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var L="1.0.0-beta.
|
|
1
|
+
var L="1.0.0-beta.2";var he=[5e3,1e4,15e3,2e4,25e3,3e4,35e3,4e4,45e3,5e4],ee=15e3,te=a=>{let t=a==="SE"?10:1,r=he.map(s=>s/t);return{unit:a==="SE"?"mil":"km",kmPerUnit:t,options:r,min:r[0],max:r[r.length-1],step:5e3/t}},T=a=>Math.round(a*100),ne=(a,t)=>{if(!(typeof t!="number"||!(t>0)))return T(t)===T(a.pricePerKwh)?a.costPerKm:a.energyPer100Km/100*t},ae=(a,t)=>{if(!(a===void 0||Number.isNaN(a)))return Math.round(a*t/12)},A=a=>typeof a=="number"&&Number.isFinite(a)&&a>0,K=a=>!!a&&A(a.energyPer100Km)&&A(a.costPerKm)&&A(a.pricePerKwh);var ve={production:"https://public-api.wayke.com/graphql",test:"https://public-test-api.wayke.com/graphql"},we=`ev-web@${L}`,be=`
|
|
2
2
|
chargingEnergyConsumption { floatValue }
|
|
3
3
|
chargingCostPerKilometer { floatValue unit }
|
|
4
4
|
chargingPricePerKwh { floatValue }
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../package.json", "../src/chargingCost.ts", "../src/api.ts", "../src/i18n.ts", "../src/dom.ts", "../src/widget.ts", "../src/mount.ts"],
|
|
4
|
-
"sourcesContent": ["{\n \"name\": \"@wayke-se/ev-web\",\n \"version\": \"1.0.0-beta.1\",\n \"description\": \"Embeddable widget that shows what it costs to charge an electric car from Wayke\",\n \"type\": \"module\",\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"default\": \"./dist/index.js\"\n },\n \"./style.css\": \"./dist/style.css\",\n \"./package.json\": \"./package.json\"\n },\n \"sideEffects\": [\n \"*.css\"\n ],\n \"files\": [\n \"dist\"\n ],\n \"scripts\": {\n \"start\": \"node ./esbuild/start.js\",\n \"build\": \"npm run clean && node ./esbuild/lib.js && node ./esbuild/cdn.js\",\n \"clean\": \"rimraf build dist dist-cdn www/build\",\n \"test\": \"npm run lint && npm run typecheck && npm run stylelint && npm run test:unit\",\n \"test:unit\": \"vitest run\",\n \"lint\": \"biome check\",\n \"lint:fix\": \"biome check --write\",\n \"typecheck\": \"tsc --noEmit\",\n \"stylelint\": \"stylelint \\\"src/**/*.scss\\\"\",\n \"prepare\": \"husky\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/wayke-se/wayke-ev-web.git\"\n },\n \"author\": \"Wayke\",\n \"license\": \"MIT\",\n \"bugs\": {\n \"url\": \"https://github.com/wayke-se/wayke-ev-web/issues\"\n },\n \"homepage\": \"https://github.com/wayke-se/wayke-ev-web#readme\",\n \"keywords\": [\n \"wayke\",\n \"electric vehicle\",\n \"charging cost\",\n \"widget\"\n ],\n \"devDependencies\": {\n \"@biomejs/biome\": \"2.6.3\",\n \"@types/node\": \"^24.19.2\",\n \"esbuild\": \"^0.28.2\",\n \"esbuild-sass-plugin\": \"^3.7.0\",\n \"happy-dom\": \"^21.0.4\",\n \"husky\": \"^9.1.7\",\n \"lint-staged\": \"^17.6.0\",\n \"rimraf\": \"^6.1.3\",\n \"stylelint\": \"^18.1.0\",\n \"stylelint-config-standard-scss\": \"^18.0.0\",\n \"typescript\": \"^7.0.2\",\n \"vitest\": \"^5.1.2\"\n },\n \"lint-staged\": {\n \"*.{ts,js,json}\": \"biome check --write --no-errors-on-unmatched\",\n \"*.scss\": \"stylelint --fix\"\n },\n \"allowScripts\": {\n \"@parcel/watcher\": false,\n \"esbuild\": true,\n \"fsevents\": false\n }\n}\n", "import type { ChargingData, MarketCode } from './types.js';\n\n// Yearly distances the visitor can choose between, in km.\nconst DISTANCES_KM = [5000, 10000, 15000, 20000, 25000, 30000, 35000, 40000, 45000, 50000];\n\nexport const DEFAULT_DISTANCE_KM = 15000;\n\nexport interface DistanceScale {\n /** Sweden counts in Scandinavian miles (1 mil = 10 km), Norway in km. */\n unit: 'mil' | 'km';\n kmPerUnit: number;\n /** In the market's unit. */\n options: number[];\n min: number;\n max: number;\n step: number;\n}\n\nexport const distanceScale = (marketCode: MarketCode): DistanceScale => {\n const kmPerUnit = marketCode === 'SE' ? 10 : 1;\n const options = DISTANCES_KM.map((km) => km / kmPerUnit);\n return {\n unit: marketCode === 'SE' ? 'mil' : 'km',\n kmPerUnit,\n options,\n min: options[0] as number,\n max: options[options.length - 1] as number,\n step: 5000 / kmPerUnit,\n };\n};\n\n/** The price in whole \u00F6re/\u00F8re, which is what the visitor sees and types. */\nexport const toCents = (pricePerKwh: number): number => Math.round(pricePerKwh * 100);\n\n/**\n * Cost per km at the visitor's own price per kWh. Undefined for a missing or\n * invalid price.\n *\n * At the template price it is the template cost itself: Wayke computes that figure\n * from an unrounded price, so energy \u00D7 the rounded price would land a krona or two\n * off per month and the two price options would disagree before anything is typed.\n */\nexport const costPerKmAtPrice = (\n data: ChargingData,\n pricePerKwh: number | undefined\n): number | undefined => {\n if (typeof pricePerKwh !== 'number' || !(pricePerKwh > 0)) return undefined;\n if (toCents(pricePerKwh) === toCents(data.pricePerKwh)) return data.costPerKm;\n return (data.energyPer100Km / 100) * pricePerKwh;\n};\n\n/** Undefined when there is no cost per km. A cost that rounds to 0 is still a cost. */\nexport const monthlyCost = (\n costPerKm: number | undefined,\n distanceKmPerYear: number\n): number | undefined => {\n if (costPerKm === undefined || Number.isNaN(costPerKm)) return undefined;\n return Math.round((costPerKm * distanceKmPerYear) / 12);\n};\n\nconst isPositive = (value: unknown): value is number =>\n typeof value === 'number' && Number.isFinite(value) && value > 0;\n\n/** True when the figures are enough to show a calculator. */\nexport const isChargingData = (\n data: Partial<ChargingData> | null | undefined\n): data is ChargingData =>\n !!data &&\n isPositive(data.energyPer100Km) &&\n isPositive(data.costPerKm) &&\n isPositive(data.pricePerKwh);\n", "// Reads a vehicle's charging figures from Wayke's public GraphQL API. The site is\n// identified by its own origin, which Wayke has registered, unless an explicit key\n// is given (local development).\n\nimport { version } from '../package.json';\nimport { isChargingData } from './chargingCost.js';\nimport type {\n ChargingData,\n Environment,\n ErrorReason,\n MarketCode,\n UnavailableReason,\n} from './types.js';\n\nconst API_URLS: Record<Environment, string> = {\n production: 'https://public-api.wayke.com/graphql',\n test: 'https://public-test-api.wayke.com/graphql',\n};\n\n/** Shows up in Wayke's traces, so it is visible which sites run which version. */\nconst CLIENT_VERSION = `ev-web@${version}`;\n\nconst ATTRIBUTES = `\n chargingEnergyConsumption { floatValue }\n chargingCostPerKilometer { floatValue unit }\n chargingPricePerKwh { floatValue }\n batteryCapacityNet { intValue }\n batteryCapacityGross { intValue }\n electricRangeWltp { minvalue }\n`;\n\nconst AD_FIELDS = `id iteration { item { ... on Vehicle { attributes { ${ATTRIBUTES} } } } }`;\n\n// Older ads have a legacy id that differs from the ad's id, and sites that have\n// stored those still pass them. byIterationId resolves such an id to the ad, so\n// both are asked for in the one request.\nconst QUERY = `\nquery EvWebChargingData($id: ID!) {\n ads {\n byAdId(ID: $id) { ${AD_FIELDS} }\n byIterationId(iterationId: $id) { ads { ${AD_FIELDS} } }\n }\n}`;\n\ninterface AdNode {\n id: string;\n iteration?: {\n item?: {\n attributes?: {\n chargingEnergyConsumption?: { floatValue?: number | null } | null;\n chargingCostPerKilometer?: { floatValue?: number | null; unit?: string | null } | null;\n chargingPricePerKwh?: { floatValue?: number | null } | null;\n batteryCapacityNet?: { intValue?: number | null } | null;\n batteryCapacityGross?: { intValue?: number | null } | null;\n electricRangeWltp?: { minvalue?: number | null } | null;\n } | null;\n } | null;\n } | null;\n}\n\ninterface QueryResult {\n ads?: {\n byAdId?: AdNode | null;\n byIterationId?: { ads?: AdNode[] | null } | null;\n } | null;\n}\n\nexport class ApiError extends Error {\n readonly reason: ErrorReason;\n\n constructor(reason: ErrorReason) {\n super(`Wayke EV: ${reason}`);\n this.name = 'ApiError';\n this.reason = reason;\n }\n}\n\nexport type ChargingDataResult =\n | { status: 'ok'; data: ChargingData }\n | { status: 'unavailable'; reason: UnavailableReason };\n\nconst positive = (value: number | null | undefined): number | undefined =>\n typeof value === 'number' && value > 0 ? value : undefined;\n\n// The cost's unit is \"SEK/km\" or \"NOK/km\": the currency tells the market.\nconst marketOfUnit = (unit: string | null | undefined): MarketCode | undefined => {\n if (unit?.startsWith('NOK')) return 'NO';\n if (unit?.startsWith('SEK')) return 'SE';\n return undefined;\n};\n\n/** Exported for the tests. */\nexport const toChargingData = (ad: AdNode | null | undefined): ChargingDataResult => {\n if (!ad) return { status: 'unavailable', reason: 'not-found' };\n const attributes = ad.iteration?.item?.attributes;\n const data: Partial<ChargingData> = {\n energyPer100Km: positive(attributes?.chargingEnergyConsumption?.floatValue),\n costPerKm: positive(attributes?.chargingCostPerKilometer?.floatValue),\n pricePerKwh: positive(attributes?.chargingPricePerKwh?.floatValue),\n marketCode: marketOfUnit(attributes?.chargingCostPerKilometer?.unit),\n batteryCapacityKwh:\n positive(attributes?.batteryCapacityNet?.intValue) ??\n positive(attributes?.batteryCapacityGross?.intValue),\n rangeKm: positive(attributes?.electricRangeWltp?.minvalue),\n };\n if (!isChargingData(data)) return { status: 'unavailable', reason: 'no-charging-data' };\n return { status: 'ok', data };\n};\n\ninterface FetchOptions {\n id: string;\n environment: Environment;\n apiKey?: string;\n signal?: AbortSignal;\n}\n\nexport const fetchChargingData = async ({\n id,\n environment,\n apiKey,\n signal,\n}: FetchOptions): Promise<ChargingDataResult> => {\n let response: Response;\n try {\n response = await fetch(API_URLS[environment], {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'x-api-key': apiKey || window.location.origin,\n 'x-graphql-client-version': CLIENT_VERSION,\n },\n body: JSON.stringify({ query: QUERY, variables: { id } }),\n signal,\n });\n } catch (error) {\n if (signal?.aborted) throw error;\n throw new ApiError('network');\n }\n\n if (response.status === 401 || response.status === 403) throw new ApiError('unauthorized');\n if (response.status === 429) throw new ApiError('rate-limited');\n\n const body = (await response.json().catch(() => null)) as { data?: QueryResult } | null;\n if (!response.ok || !body) throw new ApiError('server');\n\n // An id that is not a GUID comes back as a GraphQL error next to null data;\n // to the site that is the same as an id no vehicle has.\n const ads = body.data?.ads;\n return toChargingData(ads?.byAdId ?? ads?.byIterationId?.ads?.[0]);\n};\n", "import type { Language, MarketCode } from './types.js';\n\nconst sv = {\n title: 'Ber\u00E4kna laddkostnad',\n description:\n 'Se vad det kostar att ladda den h\u00E4r elbilen per m\u00E5nad. Ange din \u00E5rliga k\u00F6rstr\u00E4cka f\u00F6r att se bilens uppskattade laddkostnad.',\n modalDescription:\n 'H\u00E4r ser du den uppskattade laddkostnaden f\u00F6r just den h\u00E4r bilen. R\u00E4kna p\u00E5 schablonpriset eller p\u00E5 ditt eget elpris.',\n yearlyDistance: 'Din \u00E5rliga k\u00F6rstr\u00E4cka',\n adjustToYourPrice: 'Vill du anpassa kostnaden efter ditt elpris?',\n openCalculator: '\u00D6ppna utr\u00E4knaren',\n closeModal: 'St\u00E4ng',\n costPerMonthUnit: 'kr/m\u00E5n',\n pricePerKwhUnit: '\u00F6re/kWh',\n energyUnit: 'kWh/100 km',\n unknownCost: 'Ok\u00E4nt',\n disclaimerStandard:\n 'Ber\u00E4knat p\u00E5 bilens energi\u00E5tg\u00E5ng utifr\u00E5n WLTP-v\u00E4rden, inklusive laddf\u00F6rluster, den angivna \u00E5rliga k\u00F6rstr\u00E4ckan och ett schablonpris p\u00E5 {price}.',\n disclaimerCustom:\n 'Ber\u00E4knat p\u00E5 bilens energi\u00E5tg\u00E5ng utifr\u00E5n WLTP-v\u00E4rden, inklusive laddf\u00F6rluster, den angivna \u00E5rliga k\u00F6rstr\u00E4ckan och ditt angivna elpris.',\n whichPrice: 'Vilket elpris vill du r\u00E4kna p\u00E5?',\n standardPrice: 'Schablonpris',\n customPrice: 'Eget elpris',\n yourPrice: 'Ditt elpris',\n yourPriceHelp: 'Ange ditt totala pris per kWh s\u00E5 som det st\u00E5r p\u00E5 din faktura.',\n showHelp: 'Visa hj\u00E4lp',\n hideHelp: 'D\u00F6lj hj\u00E4lp',\n batteryCapacity: 'Bilens batterikapacitet',\n range: 'Bilens r\u00E4ckvidd (WLTP)',\n energyUse: 'Energi\u00E5tg\u00E5ng inkl. laddf\u00F6rluster',\n statedDistance: 'Angiven \u00E5rlig k\u00F6rstr\u00E4cka',\n standardPriceRow: 'Elpris schablon, inkl. energiskatt och moms',\n gridFee: 'Eln\u00E4tsavgift',\n gridFeeValue: 'Inte inkluderad i ber\u00E4kningen',\n poweredBy: 'Powered by',\n};\n\ntype Messages = typeof sv;\n\nconst nb: Messages = {\n title: 'Beregn ladekostnad',\n description:\n 'Se hva det koster \u00E5 lade denne elbilen per m\u00E5ned. Oppgi din \u00E5rlige kj\u00F8relengde for \u00E5 se bilens estimerte ladekostnad.',\n modalDescription:\n 'Her ser du den estimerte ladekostnaden for akkurat denne bilen. Regn med sjablongprisen eller med din egen str\u00F8mpris.',\n yearlyDistance: 'Din \u00E5rlige kj\u00F8relengde',\n adjustToYourPrice: 'Vil du tilpasse kostnaden til din str\u00F8mpris?',\n openCalculator: '\u00C5pne kalkulatoren',\n closeModal: 'Lukk',\n costPerMonthUnit: 'kr/mnd',\n pricePerKwhUnit: '\u00F8re/kWh',\n energyUnit: 'kWh/100 km',\n unknownCost: 'Ukjent',\n disclaimerStandard:\n 'Beregnet p\u00E5 bilens energiforbruk basert p\u00E5 WLTP-verdier, inkludert ladetap, den angitte \u00E5rlige kj\u00F8relengden og en sjablongpris p\u00E5 {price}.',\n disclaimerCustom:\n 'Beregnet p\u00E5 bilens energiforbruk basert p\u00E5 WLTP-verdier, inkludert ladetap, den angitte \u00E5rlige kj\u00F8relengden og din angitte str\u00F8mpris.',\n whichPrice: 'Hvilken str\u00F8mpris vil du regne med?',\n standardPrice: 'Sjablongpris',\n customPrice: 'Egen str\u00F8mpris',\n yourPrice: 'Din str\u00F8mpris',\n yourPriceHelp: 'Oppgi din totale pris per kWh slik den st\u00E5r p\u00E5 fakturaen din.',\n showHelp: 'Vis hjelp',\n hideHelp: 'Skjul hjelp',\n batteryCapacity: 'Bilens batterikapasitet',\n range: 'Bilens rekkevidde (WLTP)',\n energyUse: 'Energiforbruk inkl. ladetap',\n statedDistance: 'Angitt \u00E5rlig kj\u00F8relengde',\n standardPriceRow: 'Str\u00F8mpris sjablong, inkl. avgifter og mva.',\n gridFee: 'Nettleie',\n gridFeeValue: 'Ikke inkludert i beregningen',\n poweredBy: 'Powered by',\n};\n\nconst en: Messages = {\n title: 'Calculate charging cost',\n description:\n 'See what it costs to charge this electric car per month. Enter your yearly distance to see the estimated charging cost.',\n modalDescription:\n 'This is the estimated charging cost for this car. Use the standard electricity price or your own.',\n yearlyDistance: 'Your yearly distance',\n adjustToYourPrice: 'Want to use your own electricity price?',\n openCalculator: 'Open the calculator',\n closeModal: 'Close',\n costPerMonthUnit: 'kr/month',\n pricePerKwhUnit: '\u00F6re/kWh',\n energyUnit: 'kWh/100 km',\n unknownCost: 'Unknown',\n disclaimerStandard:\n \"Based on the car's energy use from WLTP figures, charging losses included, the yearly distance and a standard price of {price}.\",\n disclaimerCustom:\n \"Based on the car's energy use from WLTP figures, charging losses included, the yearly distance and your own electricity price.\",\n whichPrice: 'Which electricity price do you want to use?',\n standardPrice: 'Standard price',\n customPrice: 'Own electricity price',\n yourPrice: 'Your electricity price',\n yourPriceHelp: 'Enter your total price per kWh as shown on your invoice.',\n showHelp: 'Show help',\n hideHelp: 'Hide help',\n batteryCapacity: 'Battery capacity',\n range: 'Range (WLTP)',\n energyUse: 'Energy use incl. charging losses',\n statedDistance: 'Yearly distance',\n standardPriceRow: 'Standard electricity price, incl. energy tax and VAT',\n gridFee: 'Grid fee',\n gridFeeValue: 'Not included in the calculation',\n poweredBy: 'Powered by',\n};\n\nconst MESSAGES: Record<Language, Messages> = { sv, nb, en };\n\nconst LOCALES: Record<Language, string> = { sv: 'sv-SE', nb: 'nb-NO', en: 'en-GB' };\n\nexport type MessageKey = keyof Messages;\n\nexport interface Translator {\n (key: MessageKey, values?: Record<string, string>): string;\n /** Formats a number the way the language writes it, e.g. \"1 500\" and \"20,4\". */\n number: (value: number, maximumFractionDigits?: number) => string;\n}\n\nexport const defaultLanguage = (marketCode: MarketCode): Language =>\n marketCode === 'NO' ? 'nb' : 'sv';\n\nexport const createTranslator = (language: Language): Translator => {\n const messages = MESSAGES[language] ?? sv;\n const locale = LOCALES[language] ?? LOCALES.sv;\n\n const t = ((key, values) => {\n const message = messages[key];\n if (!values) return message;\n return message.replace(/\\{(\\w+)\\}/g, (match, name: string) => values[name] ?? match);\n }) as Translator;\n\n t.number = (value, maximumFractionDigits = 0) =>\n new Intl.NumberFormat(locale, { maximumFractionDigits }).format(value);\n\n return t;\n};\n\n/** The brand behind the figures: Wayke in Sweden, Drive in Norway. */\nexport const brandOf = (marketCode: MarketCode) =>\n marketCode === 'NO'\n ? { name: 'Drive', url: 'https://www.drive.no' }\n : { name: 'Wayke', url: 'https://www.wayke.se' };\n", "// A minimal element builder. Everything the widget shows is created through it,\n// with text set as text nodes, so nothing from the API or the options is ever\n// parsed as HTML.\n\ntype Attributes = Record<string, string | number | boolean | undefined>;\ntype Child = Node | string | false | null | undefined;\n\nconst SVG_NS = 'http://www.w3.org/2000/svg';\n\nconst setAttributes = (element: Element, attributes: Attributes) => {\n for (const [name, value] of Object.entries(attributes)) {\n if (value === undefined || value === false) continue;\n element.setAttribute(name, value === true ? '' : String(value));\n }\n};\n\nexport const h = <K extends keyof HTMLElementTagNameMap>(\n tag: K,\n attributes: Attributes = {},\n ...children: Child[]\n): HTMLElementTagNameMap[K] => {\n const element = document.createElement(tag);\n setAttributes(element, attributes);\n for (const child of children) {\n if (child === false || child === null || child === undefined) continue;\n element.append(child);\n }\n return element;\n};\n\n/** A decorative icon: one path in a 16 \u00D7 16 viewBox. */\nexport const icon = (path: string) => {\n const svg = document.createElementNS(SVG_NS, 'svg');\n setAttributes(svg, {\n viewBox: '0 0 16 16',\n class: 'waykeev-icon',\n 'aria-hidden': 'true',\n focusable: 'false',\n });\n const shape = document.createElementNS(SVG_NS, 'path');\n shape.setAttribute('d', path);\n svg.append(shape);\n return svg;\n};\n\nexport const ICONS = {\n bulb: 'M7 2V1c0-.6.4-1 1-1s1 .4 1 1v1c0 .6-.4 1-1 1s-1-.4-1-1zM2.3 4.7c.2.2.4.3.7.3s.5-.1.7-.3c.4-.4.4-1 0-1.4l-1-1c-.4-.4-1-.4-1.4 0s-.4 1 0 1.4l1 1zm12.4-1c.4-.4.4-1 0-1.4s-1-.4-1.4 0l-1 1c-.4.4-.4 1 0 1.4.2.2.4.3.7.3s.5-.1.7-.3l1-1zm-2.4 2.6c.5.7.7 1.5.7 2.4 0 .8-.2 1.6-.7 2.3-.3.5-.8 1-1.3 1.3V15c0 .6-.4 1-1 1H6c-.6 0-1-.4-1-1v-2.7c-.5-.3-1-.8-1.3-1.3-.5-.7-.7-1.5-.7-2.4 0-.8.2-1.6.7-2.3.4-.7 1.1-1.3 1.8-1.7C6.3 4.2 7.1 4 8 4c.9 0 1.7.2 2.5.6.7.4 1.4 1 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156 11.4a13.292 13.292 0 0 1-4.537 8.195 13.441 13.441 0 0 1-8.84 3.206H1.063L0 38h13.919c11.74 0 21.349-8.41 22.88-19.018C38.328 8.373 31.01 0 19.27 0Z';\n\n// The Wayke symbol: fifteen dots as [cx, cy, r].\nconst WAYKE_SYMBOL: [number, number, number][] = [\n [4.25, 39.68, 4.25],\n [25.15, 68.03, 4.96],\n [46.04, 96.38, 6.38],\n [66.93, 68.03, 7.09],\n [87.82, 39.68, 8.5],\n [108.72, 68.03, 10.63],\n [129.61, 96.38, 12.76],\n [150.5, 68.03, 13.47],\n [171.4, 39.68, 14.17],\n [129.61, 39.68, 12.05],\n [66.93, 11.34, 7.09],\n [150.5, 11.34, 11.34],\n [108.72, 11.34, 10.63],\n [46.04, 39.68, 6.38],\n [25.15, 11.34, 4.96],\n];\n\n/** The brand symbol shown next to \"Powered by\". */\nexport const brandSymbol = (brand: string) => {\n const svg = document.createElementNS(SVG_NS, 'svg');\n setAttributes(svg, {\n class: 'waykeev-powered-by-wayke',\n 'aria-hidden': 'true',\n focusable: 'false',\n viewBox: brand === 'Drive' ? '0 0 37 38' : '0 0 185.57 109.13',\n });\n if (brand === 'Drive') {\n const shape = document.createElementNS(SVG_NS, 'path');\n shape.setAttribute('d', DRIVE_SYMBOL);\n svg.append(shape);\n return svg;\n }\n for (const [cx, cy, r] of WAYKE_SYMBOL) {\n const circle = document.createElementNS(SVG_NS, 'circle');\n setAttributes(circle, { cx, cy, r });\n svg.append(circle);\n }\n return svg;\n};\n", "// The calculator itself: a preview on the page with the cost at Wayke's template\n// electricity price, and a dialog where the visitor can use their own price.\n// All figures are computed in the browser from `data`; nothing is fetched here.\n\nimport {\n costPerKmAtPrice,\n DEFAULT_DISTANCE_KM,\n distanceScale,\n monthlyCost,\n toCents,\n} from './chargingCost.js';\nimport { brandSymbol, h, ICONS, icon } from './dom.js';\nimport { brandOf, type Translator } from './i18n.js';\nimport type { ChargingData, EvEvent, MarketCode, PriceOption } from './types.js';\n\nconst HASH = '#wayke-ev';\n\nlet instances = 0;\n\nexport interface WidgetProps {\n data: ChargingData;\n marketCode: MarketCode;\n t: Translator;\n hash: boolean;\n emit: (event: EvEvent) => void;\n /** Aborted on unmount: every listener the widget adds is tied to it. */\n signal: AbortSignal;\n}\n\n/** \"1,5\" and \"1.5\" are both a price; anything else is no price. */\nconst parsePrice = (value: string): number | undefined => {\n const normalized = value.trim().replace(',', '.');\n if (!/^\\d+(\\.\\d+)?$/.test(normalized)) return undefined;\n const price = Number.parseFloat(normalized);\n return price > 0 ? price : undefined;\n};\n\nexport const renderWidget = (root: HTMLElement, props: WidgetProps) => {\n const { data, marketCode, t, emit, signal } = props;\n const uid = `waykeev-${++instances}`;\n const scale = distanceScale(marketCode);\n const brand = brandOf(marketCode);\n const templateCents = toCents(data.pricePerKwh);\n\n const state = {\n /** In the market's unit: mil in Sweden, km in Norway. */\n distance: DEFAULT_DISTANCE_KM / scale.kmPerUnit,\n priceOption: 'standard' as PriceOption,\n /** The visitor's own price in \u00F6re/\u00F8re per kWh. Undefined while the field is empty or invalid. */\n customCents: templateCents as number | undefined,\n };\n\n const distanceKm = () => state.distance * scale.kmPerUnit;\n const distanceLabel = (distance: number) => `${t.number(distance)} ${scale.unit}`;\n const priceLabel = (cents: number) => `${t.number(cents)} ${t('pricePerKwhUnit')}`;\n\n const costLabel = (priceOption: PriceOption) => {\n const costPerKm =\n priceOption === 'standard'\n ? data.costPerKm\n : costPerKmAtPrice(\n data,\n state.customCents === undefined ? undefined : state.customCents / 100\n );\n const cost = monthlyCost(costPerKm, distanceKm());\n return cost === undefined ? t('unknownCost') : `${t.number(cost)} ${t('costPerMonthUnit')}`;\n };\n\n // Each part of the page that shows a figure registers how to refresh itself.\n const refreshers: (() => void)[] = [];\n const refresh = () => {\n for (const run of refreshers) run();\n };\n\n const distanceControls = (idPrefix: string) => {\n const selectId = `${idPrefix}-distance`;\n const select = h(\n 'select',\n { class: 'waykeev-select', id: selectId, name: 'distance' },\n ...scale.options.map((option) => h('option', { value: option }, distanceLabel(option)))\n );\n const range = h('input', {\n type: 'range',\n class: 'waykeev-input-range__input',\n name: 'distance',\n min: scale.min,\n max: scale.max,\n step: scale.step,\n 'aria-label': t('yearlyDistance'),\n });\n\n const onChange = (control: 'slider' | 'select') => (event: Event) => {\n const value = Number.parseInt((event.currentTarget as HTMLInputElement).value, 10);\n if (Number.isNaN(value) || value === state.distance) return;\n state.distance = value;\n refresh();\n emit({ type: 'distance-change', distanceKm: distanceKm(), control });\n };\n select.addEventListener('change', onChange('select'), { signal });\n range.addEventListener('input', onChange('slider'), { signal });\n\n refreshers.push(() => {\n select.value = String(state.distance);\n range.value = String(state.distance);\n const percentage = Math.round(((state.distance - scale.min) / (scale.max - scale.min)) * 100);\n range.style.setProperty('--percentage', `${percentage}%`);\n });\n\n return [\n h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--2' },\n h(\n 'div',\n { class: 'waykeev-input-label' },\n h('label', { class: 'waykeev-input-label__label', for: selectId }, t('yearlyDistance'))\n ),\n select\n ),\n h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--2' },\n h('div', { class: 'waykeev-input-range' }, range)\n ),\n ];\n };\n\n const poweredBy = () => [\n h(\n 'div',\n { class: 'waykeev-hstack__item waykeev-hstack__item--no-shrink' },\n brandSymbol(brand.name)\n ),\n h(\n 'div',\n {\n class:\n 'waykeev-hstack__item waykeev-text waykeev-text--size-small waykeev-text--font-regular',\n },\n `${t('poweredBy')} `,\n h(\n 'a',\n {\n href: brand.url,\n target: '_blank',\n rel: 'noopener noreferrer',\n class:\n 'waykeev-link waykeev-link--no-external-icon waykeev-link--current-color waykeev-link--underline',\n },\n brand.name\n )\n ),\n ];\n\n /** The highlighted box with the monthly cost and what it is based on. */\n const costBalloon = (priceOption: () => PriceOption, ...extra: Node[]) => {\n const cost = h('div', {\n class: 'waykeev-heading waykeev-heading--3 waykeev-no-margin',\n 'aria-live': 'polite',\n });\n const disclaimer = h('div', { class: 'waykeev-disclaimer' });\n refreshers.push(() => {\n cost.textContent = `${costLabel(priceOption())}*`;\n disclaimer.textContent = `* ${\n priceOption() === 'standard'\n ? t('disclaimerStandard', { price: priceLabel(templateCents) })\n : t('disclaimerCustom')\n }`;\n });\n return h(\n 'div',\n { class: 'waykeev-balloon' },\n h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--3' },\n h('div', { class: 'waykeev-stack waykeev-stack--1' }, cost),\n h('div', { class: 'waykeev-stack waykeev-stack--1' }, disclaimer)\n ),\n ...extra\n );\n };\n\n const detailRow = (label: string, value: string | (() => string)) => {\n const valueNode = h('div', { class: 'waykeev-key-value-list__value' });\n if (typeof value === 'string') {\n valueNode.textContent = value;\n } else {\n refreshers.push(() => {\n valueNode.textContent = value();\n });\n }\n return h(\n 'li',\n { class: 'waykeev-key-value-list__item' },\n h('div', { class: 'waykeev-key-value-list__key' }, label),\n valueNode\n );\n };\n\n // ---- Dialog ----------------------------------------------------------------\n\n const titleId = `${uid}-modal-title`;\n const priceInputId = `${uid}-price`;\n const helpId = `${uid}-price-help`;\n\n const priceInput = h('input', {\n type: 'text',\n inputmode: 'decimal',\n autocomplete: 'off',\n id: priceInputId,\n name: 'custom-price',\n class: 'waykeev-input-text__input',\n value: templateCents,\n });\n priceInput.addEventListener(\n 'input',\n () => {\n state.customCents = parsePrice(priceInput.value);\n refresh();\n },\n { signal }\n );\n priceInput.addEventListener(\n 'change',\n () => {\n if (state.customCents !== undefined) {\n emit({ type: 'custom-price-change', pricePerKwh: state.customCents / 100 });\n }\n },\n { signal }\n );\n\n const help = h('div', { class: 'waykeev-input-label__foldout', id: helpId, hidden: true });\n help.textContent = t('yourPriceHelp');\n const helpLabel = h('span', { class: 'waykeev-sr-only' }, t('showHelp'));\n const helpButton = h(\n 'button',\n {\n type: 'button',\n class: 'waykeev-input-label__help-btn',\n 'aria-expanded': 'false',\n 'aria-controls': helpId,\n },\n helpLabel,\n icon(ICONS.help)\n );\n helpButton.addEventListener(\n 'click',\n () => {\n help.hidden = !help.hidden;\n helpButton.setAttribute('aria-expanded', String(!help.hidden));\n helpLabel.textContent = t(help.hidden ? 'showHelp' : 'hideHelp');\n helpButton\n .querySelector('svg')\n ?.replaceWith(icon(help.hidden ? ICONS.help : ICONS.helpClose));\n },\n { signal }\n );\n\n const priceField = h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--2' },\n h(\n 'div',\n { class: 'waykeev-input-label' },\n h('label', { class: 'waykeev-input-label__label', for: priceInputId }, t('yourPrice')),\n h('div', { class: 'waykeev-input-label__help' }, helpButton),\n help\n ),\n h(\n 'div',\n { class: 'waykeev-input-text' },\n priceInput,\n h('div', { class: 'waykeev-input-text__unit' }, t('pricePerKwhUnit'))\n )\n );\n\n const priceOptionRadio = (value: PriceOption, label: string) => {\n const id = `${uid}-price-${value}`;\n const input = h('input', {\n type: 'radio',\n id,\n name: `${uid}-price-option`,\n value,\n class: 'waykeev-input-selection__input',\n checked: value === state.priceOption,\n });\n input.addEventListener(\n 'change',\n () => {\n if (!input.checked || state.priceOption === value) return;\n state.priceOption = value;\n refresh();\n emit({ type: 'price-option-change', priceOption: value });\n },\n { signal }\n );\n return h(\n 'div',\n { class: 'waykeev-input-group__item' },\n h(\n 'div',\n { class: 'waykeev-input-selection' },\n input,\n h(\n 'div',\n { class: 'waykeev-input-selection__header' },\n h('label', { class: 'waykeev-input-selection__label', for: id }, label)\n )\n )\n );\n };\n\n // Shown for the template price only: with an own price they say nothing.\n const templatePriceRows = [\n detailRow(t('standardPriceRow'), priceLabel(templateCents)),\n detailRow(t('gridFee'), t('gridFeeValue')),\n ];\n\n refreshers.push(() => {\n const custom = state.priceOption === 'custom';\n priceField.hidden = !custom;\n for (const row of templatePriceRows) row.hidden = custom;\n });\n\n const closeButton = h(\n 'button',\n { type: 'button', class: 'waykeev-modal__close-btn' },\n h('span', { class: 'waykeev-sr-only' }, t('closeModal')),\n icon(ICONS.close)\n );\n\n const dialog = h(\n 'dialog',\n { class: 'waykeev-dialog', 'aria-labelledby': titleId },\n h(\n 'div',\n { class: 'waykeev-modal' },\n h(\n 'div',\n { class: 'waykeev-modal__container' },\n h(\n 'div',\n { class: 'waykeev-modal__center' },\n h(\n 'div',\n { class: 'waykeev-modal__dialog' },\n h('div', { class: 'waykeev-modal__close' }, closeButton),\n h(\n 'div',\n { class: 'waykeev-modal__body' },\n h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--3' },\n h('h3', { class: 'waykeev-heading waykeev-heading--3', id: titleId }, t('title')),\n h(\n 'div',\n { class: 'waykeev-content' },\n h('p', { class: 'waykeev-content__p' }, t('modalDescription'))\n )\n ),\n h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--3' },\n ...distanceControls(`${uid}-modal`)\n ),\n h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--3' },\n h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--2' },\n h(\n 'fieldset',\n { class: 'waykeev-input-group' },\n h(\n 'legend',\n { class: 'waykeev-input-label' },\n h('div', { class: 'waykeev-input-label__label' }, t('whichPrice'))\n ),\n priceOptionRadio('standard', t('standardPrice')),\n priceOptionRadio('custom', t('customPrice'))\n )\n ),\n priceField\n ),\n h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--3' },\n costBalloon(\n () => state.priceOption,\n h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--3' },\n h(\n 'ul',\n { class: 'waykeev-key-value-list' },\n data.batteryCapacityKwh !== undefined &&\n detailRow(\n t('batteryCapacity'),\n `${t.number(data.batteryCapacityKwh, 1)} kWh`\n ),\n data.rangeKm !== undefined &&\n detailRow(t('range'), `${t.number(data.rangeKm)} km`),\n detailRow(\n t('energyUse'),\n `${t.number(data.energyPer100Km, 1)} ${t('energyUnit')}`\n ),\n detailRow(t('statedDistance'), () => distanceLabel(state.distance)),\n ...templatePriceRows\n )\n )\n )\n )\n ),\n h(\n 'footer',\n { class: 'waykeev-modal__footer' },\n h(\n 'div',\n { class: 'waykeev-hstack waykeev-hstack--spacing-1 waykeev-hstack--align-center' },\n ...poweredBy()\n )\n )\n )\n )\n )\n )\n );\n\n let pushedHash = false;\n\n const openDialog = () => {\n if (dialog.open) return;\n dialog.showModal();\n if (props.hash && window.location.hash !== HASH) {\n window.location.hash = HASH;\n pushedHash = true;\n }\n emit({ type: 'modal-open' });\n };\n\n closeButton.addEventListener('click', () => dialog.close(), { signal });\n\n // A click on the dimmed area around the dialog closes it, like Escape does.\n dialog.addEventListener(\n 'click',\n (event) => {\n const target = event.target as HTMLElement;\n if (target === dialog || target.matches('.waykeev-modal, .waykeev-modal__center')) {\n dialog.close();\n }\n },\n { signal }\n );\n\n // Fires for the close button, Escape and the back button alike.\n dialog.addEventListener(\n 'close',\n () => {\n if (pushedHash && window.location.hash === HASH) window.history.back();\n pushedHash = false;\n emit({ type: 'modal-close' });\n },\n { signal }\n );\n\n if (props.hash) {\n window.addEventListener(\n 'hashchange',\n () => {\n if (dialog.open && window.location.hash !== HASH) {\n pushedHash = false;\n dialog.close();\n }\n },\n { signal }\n );\n }\n\n // ---- Preview ---------------------------------------------------------------\n\n const openButton = h(\n 'button',\n { type: 'button', class: 'waykeev-link', 'aria-haspopup': 'dialog' },\n h('span', { class: 'waykeev-link__content' }, t('openCalculator'))\n );\n openButton.addEventListener('click', openDialog, { signal });\n\n root.replaceChildren(\n h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--3' },\n h('h2', { class: 'waykeev-heading waykeev-heading--2' }, t('title')),\n h(\n 'div',\n { class: 'waykeev-content' },\n h('p', { class: 'waykeev-content__p' }, t('description'))\n )\n ),\n h('div', { class: 'waykeev-stack waykeev-stack--3' }, ...distanceControls(uid)),\n h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--3' },\n costBalloon(() => 'standard')\n ),\n h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--3' },\n h(\n 'div',\n { class: 'waykeev-hstack waykeev-hstack--spacing-2 waykeev-hstack--align-center' },\n h(\n 'div',\n { class: 'waykeev-hstack__item waykeev-hstack__item--no-shrink', 'aria-hidden': 'true' },\n h(\n 'div',\n {\n class:\n 'waykeev-icon-backdrop waykeev-icon-backdrop--large waykeev-icon-backdrop--success',\n },\n icon(ICONS.bulb)\n )\n ),\n h(\n 'div',\n { class: 'waykeev-hstack__item waykeev-hstack__item--grow' },\n h(\n 'span',\n { class: 'waykeev-text waykeev-text--font-medium waykeev-text--bump-right' },\n t('adjustToYourPrice')\n ),\n openButton\n )\n )\n ),\n h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--3' },\n h(\n 'div',\n {\n class:\n 'waykeev-hstack waykeev-hstack--spacing-1 waykeev-hstack--align-center waykeev-hstack--justify-center',\n },\n ...poweredBy()\n )\n ),\n dialog\n );\n\n refresh();\n};\n", "import { version } from '../package.json';\nimport { ApiError, fetchChargingData } from './api.js';\nimport { isChargingData } from './chargingCost.js';\nimport { createTranslator, defaultLanguage } from './i18n.js';\nimport type { ChargingData, EvEvent, EvInstance, MountOptions, Theme } from './types.js';\nimport { renderWidget } from './widget.js';\n\nconst resolveTarget = (target: string | Element): Element => {\n const element = typeof target === 'string' ? document.querySelector(target) : target;\n if (!element) throw new Error(`Wayke EV: no element matches \"${target}\"`);\n return element;\n};\n\n// Set on the widget's own root, so two widgets on a page can have different themes.\nconst applyTheme = (root: HTMLElement, theme: Theme | undefined) => {\n if (theme?.primaryColor) root.style.setProperty('--theme-primary-bg', theme.primaryColor);\n if (theme?.primaryColorForeground) {\n root.style.setProperty('--theme-primary-fg', theme.primaryColorForeground);\n }\n if (theme?.linkColor) root.style.setProperty('--theme-link-color', theme.linkColor);\n};\n\n/**\n * Shows the charging cost calculator for one vehicle inside `target`, a CSS selector\n * or an element.\n *\n * Nothing is shown while the figures load, or when the vehicle has no charging cost:\n * `onEvent` then gets `unavailable` or `error`, and the page keeps its layout.\n */\nexport const mount = (target: string | Element, options: MountOptions): EvInstance => {\n const element = resolveTarget(target);\n if (!options?.id && !options?.data) {\n throw new Error('Wayke EV: either \"id\" or \"data\" is required');\n }\n\n const controller = new AbortController();\n const root = document.createElement('div');\n root.className = 'waykeev-root';\n root.dataset.version = version;\n root.hidden = true;\n applyTheme(root, options.theme);\n element.append(root);\n\n // A listener that throws must not take the widget down with it.\n const emit = (event: EvEvent) => {\n if (controller.signal.aborted) return;\n try {\n options.onEvent?.(event);\n } catch (error) {\n setTimeout(() => {\n throw error;\n });\n }\n };\n\n const show = (data: ChargingData) => {\n const marketCode = options.marketCode ?? data.marketCode ?? 'SE';\n root.dataset.market = marketCode;\n renderWidget(root, {\n data,\n marketCode,\n t: createTranslator(options.language ?? defaultLanguage(marketCode)),\n hash: options.hash === true,\n emit,\n signal: controller.signal,\n });\n root.hidden = false;\n // Always after mount() has returned, also when the figures were passed in, so a\n // listener can rely on having the instance.\n queueMicrotask(() => emit({ type: 'ready', data }));\n };\n\n if (options.data) {\n if (isChargingData(options.data)) show(options.data);\n else queueMicrotask(() => emit({ type: 'unavailable', reason: 'no-charging-data' }));\n } else if (options.id) {\n fetchChargingData({\n id: options.id,\n environment: options.environment ?? 'production',\n apiKey: options.apiKey,\n signal: controller.signal,\n })\n .then((result) => {\n if (controller.signal.aborted) return;\n if (result.status === 'ok') show(result.data);\n else emit({ type: 'unavailable', reason: result.reason });\n })\n .catch((error: unknown) => {\n if (controller.signal.aborted) return;\n emit({ type: 'error', reason: error instanceof ApiError ? error.reason : 'network' });\n });\n }\n\n return {\n unmount: () => {\n if (controller.signal.aborted) return;\n // Closing first lets the dialog undo the hash it added and report that it closed.\n root.querySelector<HTMLDialogElement>('dialog[open]')?.close();\n controller.abort();\n root.remove();\n },\n };\n};\n"],
|
|
4
|
+
"sourcesContent": ["{\n \"name\": \"@wayke-se/ev-web\",\n \"version\": \"1.0.0-beta.2\",\n \"description\": \"Embeddable widget that shows what it costs to charge an electric car from Wayke\",\n \"type\": \"module\",\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"default\": \"./dist/index.js\"\n },\n \"./style.css\": \"./dist/style.css\",\n \"./package.json\": \"./package.json\"\n },\n \"sideEffects\": [\n \"*.css\"\n ],\n \"files\": [\n \"dist\"\n ],\n \"scripts\": {\n \"start\": \"node ./esbuild/start.js\",\n \"build\": \"npm run clean && node ./esbuild/lib.js && node ./esbuild/cdn.js\",\n \"clean\": \"rimraf build dist dist-cdn www/build\",\n \"test\": \"npm run lint && npm run typecheck && npm run stylelint && npm run test:unit\",\n \"test:unit\": \"vitest run\",\n \"lint\": \"biome check\",\n \"lint:fix\": \"biome check --write\",\n \"typecheck\": \"tsc --noEmit\",\n \"stylelint\": \"stylelint \\\"src/**/*.scss\\\"\",\n \"prepare\": \"husky\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/wayke-se/wayke-ev-web.git\"\n },\n \"author\": \"Wayke\",\n \"license\": \"MIT\",\n \"bugs\": {\n \"url\": \"https://github.com/wayke-se/wayke-ev-web/issues\"\n },\n \"homepage\": \"https://github.com/wayke-se/wayke-ev-web#readme\",\n \"keywords\": [\n \"wayke\",\n \"electric vehicle\",\n \"charging cost\",\n \"widget\"\n ],\n \"devDependencies\": {\n \"@biomejs/biome\": \"2.6.3\",\n \"@types/node\": \"^24.19.2\",\n \"esbuild\": \"^0.28.2\",\n \"esbuild-sass-plugin\": \"^3.7.0\",\n \"happy-dom\": \"^21.0.4\",\n \"husky\": \"^9.1.7\",\n \"lint-staged\": \"^17.6.0\",\n \"rimraf\": \"^6.1.3\",\n \"stylelint\": \"^18.1.0\",\n \"stylelint-config-standard-scss\": \"^18.0.0\",\n \"typescript\": \"^7.0.2\",\n \"vitest\": \"^5.1.2\"\n },\n \"lint-staged\": {\n \"*.{ts,js,json}\": \"biome check --write --no-errors-on-unmatched\",\n \"*.scss\": \"stylelint --fix\"\n },\n \"allowScripts\": {\n \"@parcel/watcher\": false,\n \"esbuild\": true,\n \"fsevents\": false\n }\n}\n", "import type { ChargingData, MarketCode } from './types.js';\n\n// Yearly distances the visitor can choose between, in km.\nconst DISTANCES_KM = [5000, 10000, 15000, 20000, 25000, 30000, 35000, 40000, 45000, 50000];\n\nexport const DEFAULT_DISTANCE_KM = 15000;\n\nexport interface DistanceScale {\n /** Sweden counts in Scandinavian miles (1 mil = 10 km), Norway in km. */\n unit: 'mil' | 'km';\n kmPerUnit: number;\n /** In the market's unit. */\n options: number[];\n min: number;\n max: number;\n step: number;\n}\n\nexport const distanceScale = (marketCode: MarketCode): DistanceScale => {\n const kmPerUnit = marketCode === 'SE' ? 10 : 1;\n const options = DISTANCES_KM.map((km) => km / kmPerUnit);\n return {\n unit: marketCode === 'SE' ? 'mil' : 'km',\n kmPerUnit,\n options,\n min: options[0] as number,\n max: options[options.length - 1] as number,\n step: 5000 / kmPerUnit,\n };\n};\n\n/** The price in whole \u00F6re/\u00F8re, which is what the visitor sees and types. */\nexport const toCents = (pricePerKwh: number): number => Math.round(pricePerKwh * 100);\n\n/**\n * Cost per km at the visitor's own price per kWh. Undefined for a missing or\n * invalid price.\n *\n * At the template price it is the template cost itself: Wayke computes that figure\n * from an unrounded price, so energy \u00D7 the rounded price would land a krona or two\n * off per month and the two price options would disagree before anything is typed.\n */\nexport const costPerKmAtPrice = (\n data: ChargingData,\n pricePerKwh: number | undefined\n): number | undefined => {\n if (typeof pricePerKwh !== 'number' || !(pricePerKwh > 0)) return undefined;\n if (toCents(pricePerKwh) === toCents(data.pricePerKwh)) return data.costPerKm;\n return (data.energyPer100Km / 100) * pricePerKwh;\n};\n\n/** Undefined when there is no cost per km. A cost that rounds to 0 is still a cost. */\nexport const monthlyCost = (\n costPerKm: number | undefined,\n distanceKmPerYear: number\n): number | undefined => {\n if (costPerKm === undefined || Number.isNaN(costPerKm)) return undefined;\n return Math.round((costPerKm * distanceKmPerYear) / 12);\n};\n\nconst isPositive = (value: unknown): value is number =>\n typeof value === 'number' && Number.isFinite(value) && value > 0;\n\n/** True when the figures are enough to show a calculator. */\nexport const isChargingData = (\n data: Partial<ChargingData> | null | undefined\n): data is ChargingData =>\n !!data &&\n isPositive(data.energyPer100Km) &&\n isPositive(data.costPerKm) &&\n isPositive(data.pricePerKwh);\n", "// Reads a vehicle's charging figures from Wayke's public GraphQL API. The site is\n// identified by its own origin, which Wayke has registered, unless an explicit key\n// is given (local development).\n\nimport { version } from '../package.json';\nimport { isChargingData } from './chargingCost.js';\nimport type {\n ChargingData,\n Environment,\n ErrorReason,\n MarketCode,\n UnavailableReason,\n} from './types.js';\n\nconst API_URLS: Record<Environment, string> = {\n production: 'https://public-api.wayke.com/graphql',\n test: 'https://public-test-api.wayke.com/graphql',\n};\n\n/** Shows up in Wayke's traces, so it is visible which sites run which version. */\nconst CLIENT_VERSION = `ev-web@${version}`;\n\nconst ATTRIBUTES = `\n chargingEnergyConsumption { floatValue }\n chargingCostPerKilometer { floatValue unit }\n chargingPricePerKwh { floatValue }\n batteryCapacityNet { intValue }\n batteryCapacityGross { intValue }\n electricRangeWltp { minvalue }\n`;\n\nconst AD_FIELDS = `id iteration { item { ... on Vehicle { attributes { ${ATTRIBUTES} } } } }`;\n\n// Older ads have a legacy id that differs from the ad's id, and sites that have\n// stored those still pass them. byIterationId resolves such an id to the ad, so\n// both are asked for in the one request.\nconst QUERY = `\nquery EvWebChargingData($id: ID!) {\n ads {\n byAdId(ID: $id) { ${AD_FIELDS} }\n byIterationId(iterationId: $id) { ads { ${AD_FIELDS} } }\n }\n}`;\n\ninterface AdNode {\n id: string;\n iteration?: {\n item?: {\n attributes?: {\n chargingEnergyConsumption?: { floatValue?: number | null } | null;\n chargingCostPerKilometer?: { floatValue?: number | null; unit?: string | null } | null;\n chargingPricePerKwh?: { floatValue?: number | null } | null;\n batteryCapacityNet?: { intValue?: number | null } | null;\n batteryCapacityGross?: { intValue?: number | null } | null;\n electricRangeWltp?: { minvalue?: number | null } | null;\n } | null;\n } | null;\n } | null;\n}\n\ninterface QueryResult {\n ads?: {\n byAdId?: AdNode | null;\n byIterationId?: { ads?: AdNode[] | null } | null;\n } | null;\n}\n\nexport class ApiError extends Error {\n readonly reason: ErrorReason;\n\n constructor(reason: ErrorReason) {\n super(`Wayke EV: ${reason}`);\n this.name = 'ApiError';\n this.reason = reason;\n }\n}\n\nexport type ChargingDataResult =\n | { status: 'ok'; data: ChargingData }\n | { status: 'unavailable'; reason: UnavailableReason };\n\nconst positive = (value: number | null | undefined): number | undefined =>\n typeof value === 'number' && value > 0 ? value : undefined;\n\n// The cost's unit is \"SEK/km\" or \"NOK/km\": the currency tells the market.\nconst marketOfUnit = (unit: string | null | undefined): MarketCode | undefined => {\n if (unit?.startsWith('NOK')) return 'NO';\n if (unit?.startsWith('SEK')) return 'SE';\n return undefined;\n};\n\n/** Exported for the tests. */\nexport const toChargingData = (ad: AdNode | null | undefined): ChargingDataResult => {\n if (!ad) return { status: 'unavailable', reason: 'not-found' };\n const attributes = ad.iteration?.item?.attributes;\n const data: Partial<ChargingData> = {\n energyPer100Km: positive(attributes?.chargingEnergyConsumption?.floatValue),\n costPerKm: positive(attributes?.chargingCostPerKilometer?.floatValue),\n pricePerKwh: positive(attributes?.chargingPricePerKwh?.floatValue),\n marketCode: marketOfUnit(attributes?.chargingCostPerKilometer?.unit),\n batteryCapacityKwh:\n positive(attributes?.batteryCapacityNet?.intValue) ??\n positive(attributes?.batteryCapacityGross?.intValue),\n rangeKm: positive(attributes?.electricRangeWltp?.minvalue),\n };\n if (!isChargingData(data)) return { status: 'unavailable', reason: 'no-charging-data' };\n return { status: 'ok', data };\n};\n\ninterface FetchOptions {\n id: string;\n environment: Environment;\n apiKey?: string;\n signal?: AbortSignal;\n}\n\nexport const fetchChargingData = async ({\n id,\n environment,\n apiKey,\n signal,\n}: FetchOptions): Promise<ChargingDataResult> => {\n let response: Response;\n try {\n response = await fetch(API_URLS[environment], {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'x-api-key': apiKey || window.location.origin,\n 'x-graphql-client-version': CLIENT_VERSION,\n },\n body: JSON.stringify({ query: QUERY, variables: { id } }),\n signal,\n });\n } catch (error) {\n if (signal?.aborted) throw error;\n throw new ApiError('network');\n }\n\n if (response.status === 401 || response.status === 403) throw new ApiError('unauthorized');\n if (response.status === 429) throw new ApiError('rate-limited');\n\n const body = (await response.json().catch(() => null)) as { data?: QueryResult } | null;\n if (!response.ok || !body) throw new ApiError('server');\n\n // An id that is not a GUID comes back as a GraphQL error next to null data;\n // to the site that is the same as an id no vehicle has.\n const ads = body.data?.ads;\n return toChargingData(ads?.byAdId ?? ads?.byIterationId?.ads?.[0]);\n};\n", "import type { Language, MarketCode } from './types.js';\n\nconst sv = {\n title: 'Ber\u00E4kna laddkostnad',\n description:\n 'Se vad det kostar att ladda den h\u00E4r elbilen per m\u00E5nad. Ange din \u00E5rliga k\u00F6rstr\u00E4cka f\u00F6r att se bilens uppskattade laddkostnad.',\n modalDescription:\n 'H\u00E4r ser du den uppskattade laddkostnaden f\u00F6r just den h\u00E4r bilen. R\u00E4kna p\u00E5 schablonpriset eller p\u00E5 ditt eget elpris.',\n yearlyDistance: 'Din \u00E5rliga k\u00F6rstr\u00E4cka',\n adjustToYourPrice: 'Vill du anpassa kostnaden efter ditt elpris?',\n openCalculator: '\u00D6ppna utr\u00E4knaren',\n closeModal: 'St\u00E4ng',\n costPerMonthUnit: 'kr/m\u00E5n',\n pricePerKwhUnit: '\u00F6re/kWh',\n energyUnit: 'kWh/100 km',\n unknownCost: 'Ok\u00E4nt',\n disclaimerStandard:\n 'Ber\u00E4knat p\u00E5 bilens energi\u00E5tg\u00E5ng utifr\u00E5n WLTP-v\u00E4rden, inklusive laddf\u00F6rluster, den angivna \u00E5rliga k\u00F6rstr\u00E4ckan och ett schablonpris p\u00E5 {price}.',\n disclaimerCustom:\n 'Ber\u00E4knat p\u00E5 bilens energi\u00E5tg\u00E5ng utifr\u00E5n WLTP-v\u00E4rden, inklusive laddf\u00F6rluster, den angivna \u00E5rliga k\u00F6rstr\u00E4ckan och ditt angivna elpris.',\n whichPrice: 'Vilket elpris vill du r\u00E4kna p\u00E5?',\n standardPrice: 'Schablonpris',\n customPrice: 'Eget elpris',\n yourPrice: 'Ditt elpris',\n yourPriceHelp: 'Ange ditt totala pris per kWh s\u00E5 som det st\u00E5r p\u00E5 din faktura.',\n showHelp: 'Visa hj\u00E4lp',\n hideHelp: 'D\u00F6lj hj\u00E4lp',\n batteryCapacity: 'Bilens batterikapacitet',\n range: 'Bilens r\u00E4ckvidd (WLTP)',\n energyUse: 'Energi\u00E5tg\u00E5ng inkl. laddf\u00F6rluster',\n statedDistance: 'Angiven \u00E5rlig k\u00F6rstr\u00E4cka',\n standardPriceRow: 'Elpris schablon, inkl. energiskatt och moms',\n gridFee: 'Eln\u00E4tsavgift',\n gridFeeValue: 'Inte inkluderad i ber\u00E4kningen',\n poweredBy: 'Powered by',\n};\n\ntype Messages = typeof sv;\n\nconst nb: Messages = {\n title: 'Beregn ladekostnad',\n description:\n 'Se hva det koster \u00E5 lade denne elbilen per m\u00E5ned. Oppgi din \u00E5rlige kj\u00F8relengde for \u00E5 se bilens estimerte ladekostnad.',\n modalDescription:\n 'Her ser du den estimerte ladekostnaden for akkurat denne bilen. Regn med sjablongprisen eller med din egen str\u00F8mpris.',\n yearlyDistance: 'Din \u00E5rlige kj\u00F8relengde',\n adjustToYourPrice: 'Vil du tilpasse kostnaden til din str\u00F8mpris?',\n openCalculator: '\u00C5pne kalkulatoren',\n closeModal: 'Lukk',\n costPerMonthUnit: 'kr/mnd',\n pricePerKwhUnit: '\u00F8re/kWh',\n energyUnit: 'kWh/100 km',\n unknownCost: 'Ukjent',\n disclaimerStandard:\n 'Beregnet p\u00E5 bilens energiforbruk basert p\u00E5 WLTP-verdier, inkludert ladetap, den angitte \u00E5rlige kj\u00F8relengden og en sjablongpris p\u00E5 {price}.',\n disclaimerCustom:\n 'Beregnet p\u00E5 bilens energiforbruk basert p\u00E5 WLTP-verdier, inkludert ladetap, den angitte \u00E5rlige kj\u00F8relengden og din angitte str\u00F8mpris.',\n whichPrice: 'Hvilken str\u00F8mpris vil du regne med?',\n standardPrice: 'Sjablongpris',\n customPrice: 'Egen str\u00F8mpris',\n yourPrice: 'Din str\u00F8mpris',\n yourPriceHelp: 'Oppgi din totale pris per kWh slik den st\u00E5r p\u00E5 fakturaen din.',\n showHelp: 'Vis hjelp',\n hideHelp: 'Skjul hjelp',\n batteryCapacity: 'Bilens batterikapasitet',\n range: 'Bilens rekkevidde (WLTP)',\n energyUse: 'Energiforbruk inkl. ladetap',\n statedDistance: 'Angitt \u00E5rlig kj\u00F8relengde',\n standardPriceRow: 'Str\u00F8mpris sjablong, inkl. avgifter og mva.',\n gridFee: 'Nettleie',\n gridFeeValue: 'Ikke inkludert i beregningen',\n poweredBy: 'Powered by',\n};\n\nconst en: Messages = {\n title: 'Calculate charging cost',\n description:\n 'See what it costs to charge this electric car per month. Enter your yearly distance to see the estimated charging cost.',\n modalDescription:\n 'This is the estimated charging cost for this car. Use the standard electricity price or your own.',\n yearlyDistance: 'Your yearly distance',\n adjustToYourPrice: 'Want to use your own electricity price?',\n openCalculator: 'Open the calculator',\n closeModal: 'Close',\n costPerMonthUnit: 'kr/month',\n pricePerKwhUnit: '\u00F6re/kWh',\n energyUnit: 'kWh/100 km',\n unknownCost: 'Unknown',\n disclaimerStandard:\n \"Based on the car's energy use from WLTP figures, charging losses included, the yearly distance and a standard price of {price}.\",\n disclaimerCustom:\n \"Based on the car's energy use from WLTP figures, charging losses included, the yearly distance and your own electricity price.\",\n whichPrice: 'Which electricity price do you want to use?',\n standardPrice: 'Standard price',\n customPrice: 'Own electricity price',\n yourPrice: 'Your electricity price',\n yourPriceHelp: 'Enter your total price per kWh as shown on your invoice.',\n showHelp: 'Show help',\n hideHelp: 'Hide help',\n batteryCapacity: 'Battery capacity',\n range: 'Range (WLTP)',\n energyUse: 'Energy use incl. charging losses',\n statedDistance: 'Yearly distance',\n standardPriceRow: 'Standard electricity price, incl. energy tax and VAT',\n gridFee: 'Grid fee',\n gridFeeValue: 'Not included in the calculation',\n poweredBy: 'Powered by',\n};\n\nconst MESSAGES: Record<Language, Messages> = { sv, nb, en };\n\nconst LOCALES: Record<Language, string> = { sv: 'sv-SE', nb: 'nb-NO', en: 'en-GB' };\n\nexport type MessageKey = keyof Messages;\n\nexport interface Translator {\n (key: MessageKey, values?: Record<string, string>): string;\n /** Formats a number the way the language writes it, e.g. \"1 500\" and \"20,4\". */\n number: (value: number, maximumFractionDigits?: number) => string;\n}\n\nexport const defaultLanguage = (marketCode: MarketCode): Language =>\n marketCode === 'NO' ? 'nb' : 'sv';\n\nexport const createTranslator = (language: Language): Translator => {\n const messages = MESSAGES[language] ?? sv;\n const locale = LOCALES[language] ?? LOCALES.sv;\n\n const t = ((key, values) => {\n const message = messages[key];\n if (!values) return message;\n return message.replace(/\\{(\\w+)\\}/g, (match, name: string) => values[name] ?? match);\n }) as Translator;\n\n t.number = (value, maximumFractionDigits = 0) =>\n new Intl.NumberFormat(locale, { maximumFractionDigits }).format(value);\n\n return t;\n};\n\n/** The brand behind the figures: Wayke in Sweden, Drive in Norway. */\nexport const brandOf = (marketCode: MarketCode) =>\n marketCode === 'NO'\n ? { name: 'Drive', url: 'https://www.drive.no' }\n : { name: 'Wayke', url: 'https://www.wayke.se' };\n", "// A minimal element builder. Everything the widget shows is created through it,\n// with text set as text nodes, so nothing from the API or the options is ever\n// parsed as HTML.\n\ntype Attributes = Record<string, string | number | boolean | undefined>;\ntype Child = Node | string | false | null | undefined;\n\nconst SVG_NS = 'http://www.w3.org/2000/svg';\n\nconst setAttributes = (element: Element, attributes: Attributes) => {\n for (const [name, value] of Object.entries(attributes)) {\n if (value === undefined || value === false) continue;\n element.setAttribute(name, value === true ? '' : String(value));\n }\n};\n\nexport const h = <K extends keyof HTMLElementTagNameMap>(\n tag: K,\n attributes: Attributes = {},\n ...children: Child[]\n): HTMLElementTagNameMap[K] => {\n const element = document.createElement(tag);\n setAttributes(element, attributes);\n for (const child of children) {\n if (child === false || child === null || child === undefined) continue;\n element.append(child);\n }\n return element;\n};\n\n/** A decorative icon: one path in a 16 \u00D7 16 viewBox. */\nexport const icon = (path: string) => {\n const svg = document.createElementNS(SVG_NS, 'svg');\n setAttributes(svg, {\n viewBox: '0 0 16 16',\n class: 'waykeev-icon',\n 'aria-hidden': 'true',\n focusable: 'false',\n });\n const shape = document.createElementNS(SVG_NS, 'path');\n shape.setAttribute('d', path);\n svg.append(shape);\n return svg;\n};\n\nexport const ICONS = {\n bulb: 'M7 2V1c0-.6.4-1 1-1s1 .4 1 1v1c0 .6-.4 1-1 1s-1-.4-1-1zM2.3 4.7c.2.2.4.3.7.3s.5-.1.7-.3c.4-.4.4-1 0-1.4l-1-1c-.4-.4-1-.4-1.4 0s-.4 1 0 1.4l1 1zm12.4-1c.4-.4.4-1 0-1.4s-1-.4-1.4 0l-1 1c-.4.4-.4 1 0 1.4.2.2.4.3.7.3s.5-.1.7-.3l1-1zm-2.4 2.6c.5.7.7 1.5.7 2.4 0 .8-.2 1.6-.7 2.3-.3.5-.8 1-1.3 1.3V15c0 .6-.4 1-1 1H6c-.6 0-1-.4-1-1v-2.7c-.5-.3-1-.8-1.3-1.3-.5-.7-.7-1.5-.7-2.4 0-.8.2-1.6.7-2.3.4-.7 1.1-1.3 1.8-1.7C6.3 4.2 7.1 4 8 4c.9 0 1.7.2 2.5.6.7.4 1.4 1 1.8 1.7zM11 8.6c0-.4-.1-.9-.4-1.3-.2-.3-.6-.7-1.1-.9C9.1 6.1 8.6 6 8 6c-.5 0-1.1.1-1.5.4-.5.2-.9.5-1.1.9-.3.4-.4.9-.4 1.3s.1.9.4 1.3c.3.4.6.7 1.1 1 .3.2.5.5.5.9V14h2v-2.2c0-.4.2-.7.5-.9.5-.2.8-.6 1.1-1 .3-.4.4-.8.4-1.3zM15 7h-.5c-.6 0-1 .4-1 1s.4 1 1 1h.5c.6 0 1-.4 1-1s-.4-1-1-1zM1.5 7H1c-.6 0-1 .4-1 1s.4 1 1 1h.5c.6 0 1-.4 1-1s-.4-1-1-1z',\n close: 'M9.1 8l5.9 5.9-1.1 1.1L8 9.1 2.1 15 1 13.9 6.9 8 1 2.1 2.1 1 8 6.9 13.9 1 15 2.1 9.1 8z',\n help: 'M8 0C3.6 0 0 3.6 0 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8zm0 14c-3.3 0-6-2.7-6-6s2.7-6 6-6 6 2.7 6 6-2.7 6-6 6zm-1.4-3.8h1.9V12H6.6v-1.8zm3.8-3.4c0 1-.5 1.5-1.4 2l-.4.3c-.3.1-.3.2-.3.4v.1H6.7v-.3c0-.6.1-.9.8-1.3l.7-.4c.3-.2.6-.4.6-.8s-.3-.7-.7-.7c-.5 0-.8.3-.8.8v.3H5.7v-.4c0-1.2.8-2 2.3-2 1.5 0 2.4.7 2.4 2z',\n helpClose:\n 'M8 0C3.6 0 0 3.6 0 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8zm0 14c-3.3 0-6-2.7-6-6s2.7-6 6-6 6 2.7 6 6-2.7 6-6 6zm3.5-8.1L9.4 8l2.1 2.1-1.4 1.4L8 9.4l-2.1 2.1-1.4-1.4L6.6 8 4.5 5.9l1.4-1.4L8 6.6l2.1-2.1 1.4 1.4z',\n};\n\nconst DRIVE_SYMBOL =\n 'M19.27 0H5.348L2.126 22.838h8.445l2.126-15.241h5.479c6.83 0 11.086 4.886 10.156 11.4a13.292 13.292 0 0 1-4.537 8.195 13.441 13.441 0 0 1-8.84 3.206H1.063L0 38h13.919c11.74 0 21.349-8.41 22.88-19.018C38.328 8.373 31.01 0 19.27 0Z';\n\n// The Wayke symbol: fifteen dots as [cx, cy, r].\nconst WAYKE_SYMBOL: [number, number, number][] = [\n [4.25, 39.68, 4.25],\n [25.15, 68.03, 4.96],\n [46.04, 96.38, 6.38],\n [66.93, 68.03, 7.09],\n [87.82, 39.68, 8.5],\n [108.72, 68.03, 10.63],\n [129.61, 96.38, 12.76],\n [150.5, 68.03, 13.47],\n [171.4, 39.68, 14.17],\n [129.61, 39.68, 12.05],\n [66.93, 11.34, 7.09],\n [150.5, 11.34, 11.34],\n [108.72, 11.34, 10.63],\n [46.04, 39.68, 6.38],\n [25.15, 11.34, 4.96],\n];\n\n/** The brand symbol shown next to \"Powered by\". */\nexport const brandSymbol = (brand: string) => {\n const svg = document.createElementNS(SVG_NS, 'svg');\n setAttributes(svg, {\n class: 'waykeev-powered-by-wayke',\n 'aria-hidden': 'true',\n focusable: 'false',\n viewBox: brand === 'Drive' ? '0 0 37 38' : '0 0 185.57 109.13',\n });\n if (brand === 'Drive') {\n const shape = document.createElementNS(SVG_NS, 'path');\n shape.setAttribute('d', DRIVE_SYMBOL);\n svg.append(shape);\n return svg;\n }\n for (const [cx, cy, r] of WAYKE_SYMBOL) {\n const circle = document.createElementNS(SVG_NS, 'circle');\n setAttributes(circle, { cx, cy, r });\n svg.append(circle);\n }\n return svg;\n};\n", "// The calculator itself: a preview on the page with the cost at Wayke's template\n// electricity price, and a dialog where the visitor can use their own price.\n// All figures are computed in the browser from `data`; nothing is fetched here.\n\nimport {\n costPerKmAtPrice,\n DEFAULT_DISTANCE_KM,\n distanceScale,\n monthlyCost,\n toCents,\n} from './chargingCost.js';\nimport { brandSymbol, h, ICONS, icon } from './dom.js';\nimport { brandOf, type Translator } from './i18n.js';\nimport type { ChargingData, EvEvent, MarketCode, PriceOption } from './types.js';\n\nconst HASH = '#wayke-ev';\n\nlet instances = 0;\n\nexport interface WidgetProps {\n data: ChargingData;\n marketCode: MarketCode;\n t: Translator;\n hash: boolean;\n emit: (event: EvEvent) => void;\n /** Aborted on unmount: every listener the widget adds is tied to it. */\n signal: AbortSignal;\n}\n\n/** \"1,5\" and \"1.5\" are both a price; anything else is no price. */\nconst parsePrice = (value: string): number | undefined => {\n const normalized = value.trim().replace(',', '.');\n if (!/^\\d+(\\.\\d+)?$/.test(normalized)) return undefined;\n const price = Number.parseFloat(normalized);\n return price > 0 ? price : undefined;\n};\n\nexport const renderWidget = (root: HTMLElement, props: WidgetProps) => {\n const { data, marketCode, t, emit, signal } = props;\n const uid = `waykeev-${++instances}`;\n const scale = distanceScale(marketCode);\n const brand = brandOf(marketCode);\n const templateCents = toCents(data.pricePerKwh);\n\n const state = {\n /** In the market's unit: mil in Sweden, km in Norway. */\n distance: DEFAULT_DISTANCE_KM / scale.kmPerUnit,\n priceOption: 'standard' as PriceOption,\n /** The visitor's own price in \u00F6re/\u00F8re per kWh. Undefined while the field is empty or invalid. */\n customCents: templateCents as number | undefined,\n };\n\n const distanceKm = () => state.distance * scale.kmPerUnit;\n const distanceLabel = (distance: number) => `${t.number(distance)} ${scale.unit}`;\n const priceLabel = (cents: number) => `${t.number(cents)} ${t('pricePerKwhUnit')}`;\n\n const costLabel = (priceOption: PriceOption) => {\n const costPerKm =\n priceOption === 'standard'\n ? data.costPerKm\n : costPerKmAtPrice(\n data,\n state.customCents === undefined ? undefined : state.customCents / 100\n );\n const cost = monthlyCost(costPerKm, distanceKm());\n return cost === undefined ? t('unknownCost') : `${t.number(cost)} ${t('costPerMonthUnit')}`;\n };\n\n // Each part of the page that shows a figure registers how to refresh itself.\n const refreshers: (() => void)[] = [];\n const refresh = () => {\n for (const run of refreshers) run();\n };\n\n const distanceControls = (idPrefix: string) => {\n const selectId = `${idPrefix}-distance`;\n const select = h(\n 'select',\n { class: 'waykeev-select', id: selectId, name: 'distance' },\n ...scale.options.map((option) => h('option', { value: option }, distanceLabel(option)))\n );\n const range = h('input', {\n type: 'range',\n class: 'waykeev-input-range__input',\n name: 'distance',\n min: scale.min,\n max: scale.max,\n step: scale.step,\n 'aria-label': t('yearlyDistance'),\n });\n\n const onChange = (control: 'slider' | 'select') => (event: Event) => {\n const value = Number.parseInt((event.currentTarget as HTMLInputElement).value, 10);\n if (Number.isNaN(value) || value === state.distance) return;\n state.distance = value;\n refresh();\n emit({ type: 'distance-change', distanceKm: distanceKm(), control });\n };\n select.addEventListener('change', onChange('select'), { signal });\n range.addEventListener('input', onChange('slider'), { signal });\n\n refreshers.push(() => {\n select.value = String(state.distance);\n range.value = String(state.distance);\n const percentage = Math.round(((state.distance - scale.min) / (scale.max - scale.min)) * 100);\n range.style.setProperty('--percentage', `${percentage}%`);\n });\n\n return [\n h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--2' },\n h(\n 'div',\n { class: 'waykeev-input-label' },\n h('label', { class: 'waykeev-input-label__label', for: selectId }, t('yearlyDistance'))\n ),\n select\n ),\n h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--2' },\n h('div', { class: 'waykeev-input-range' }, range)\n ),\n ];\n };\n\n const poweredBy = () => [\n h(\n 'div',\n { class: 'waykeev-hstack__item waykeev-hstack__item--no-shrink' },\n brandSymbol(brand.name)\n ),\n h(\n 'div',\n {\n class:\n 'waykeev-hstack__item waykeev-text waykeev-text--size-small waykeev-text--font-regular',\n },\n `${t('poweredBy')} `,\n h(\n 'a',\n {\n href: brand.url,\n target: '_blank',\n rel: 'noopener noreferrer',\n class:\n 'waykeev-link waykeev-link--no-external-icon waykeev-link--current-color waykeev-link--underline',\n },\n brand.name\n )\n ),\n ];\n\n /** The highlighted box with the monthly cost and what it is based on. */\n const costBalloon = (priceOption: () => PriceOption, ...extra: Node[]) => {\n const cost = h('div', {\n class: 'waykeev-heading waykeev-heading--3 waykeev-no-margin',\n 'aria-live': 'polite',\n });\n const disclaimer = h('div', { class: 'waykeev-disclaimer' });\n refreshers.push(() => {\n cost.textContent = `${costLabel(priceOption())}*`;\n disclaimer.textContent = `* ${\n priceOption() === 'standard'\n ? t('disclaimerStandard', { price: priceLabel(templateCents) })\n : t('disclaimerCustom')\n }`;\n });\n return h(\n 'div',\n { class: 'waykeev-balloon' },\n h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--3' },\n h('div', { class: 'waykeev-stack waykeev-stack--1' }, cost),\n h('div', { class: 'waykeev-stack waykeev-stack--1' }, disclaimer)\n ),\n ...extra\n );\n };\n\n const detailRow = (label: string, value: string | (() => string)) => {\n const valueNode = h('div', { class: 'waykeev-key-value-list__value' });\n if (typeof value === 'string') {\n valueNode.textContent = value;\n } else {\n refreshers.push(() => {\n valueNode.textContent = value();\n });\n }\n return h(\n 'li',\n { class: 'waykeev-key-value-list__item' },\n h('div', { class: 'waykeev-key-value-list__key' }, label),\n valueNode\n );\n };\n\n // ---- Dialog ----------------------------------------------------------------\n\n const titleId = `${uid}-modal-title`;\n const priceInputId = `${uid}-price`;\n const helpId = `${uid}-price-help`;\n\n const priceInput = h('input', {\n type: 'text',\n inputmode: 'decimal',\n autocomplete: 'off',\n id: priceInputId,\n name: 'custom-price',\n class: 'waykeev-input-text__input',\n value: templateCents,\n });\n priceInput.addEventListener(\n 'input',\n () => {\n state.customCents = parsePrice(priceInput.value);\n refresh();\n },\n { signal }\n );\n priceInput.addEventListener(\n 'change',\n () => {\n if (state.customCents !== undefined) {\n emit({ type: 'custom-price-change', pricePerKwh: state.customCents / 100 });\n }\n },\n { signal }\n );\n\n const help = h('div', { class: 'waykeev-input-label__foldout', id: helpId, hidden: true });\n help.textContent = t('yourPriceHelp');\n const helpLabel = h('span', { class: 'waykeev-sr-only' }, t('showHelp'));\n const helpButton = h(\n 'button',\n {\n type: 'button',\n class: 'waykeev-input-label__help-btn',\n 'aria-expanded': 'false',\n 'aria-controls': helpId,\n },\n helpLabel,\n icon(ICONS.help)\n );\n helpButton.addEventListener(\n 'click',\n () => {\n help.hidden = !help.hidden;\n helpButton.setAttribute('aria-expanded', String(!help.hidden));\n helpLabel.textContent = t(help.hidden ? 'showHelp' : 'hideHelp');\n helpButton\n .querySelector('svg')\n ?.replaceWith(icon(help.hidden ? ICONS.help : ICONS.helpClose));\n },\n { signal }\n );\n\n const priceField = h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--2' },\n h(\n 'div',\n { class: 'waykeev-input-label' },\n h('label', { class: 'waykeev-input-label__label', for: priceInputId }, t('yourPrice')),\n h('div', { class: 'waykeev-input-label__help' }, helpButton),\n help\n ),\n h(\n 'div',\n { class: 'waykeev-input-text' },\n priceInput,\n h('div', { class: 'waykeev-input-text__unit' }, t('pricePerKwhUnit'))\n )\n );\n\n const priceOptionRadio = (value: PriceOption, label: string) => {\n const id = `${uid}-price-${value}`;\n const input = h('input', {\n type: 'radio',\n id,\n name: `${uid}-price-option`,\n value,\n class: 'waykeev-input-selection__input',\n checked: value === state.priceOption,\n });\n input.addEventListener(\n 'change',\n () => {\n if (!input.checked || state.priceOption === value) return;\n state.priceOption = value;\n refresh();\n emit({ type: 'price-option-change', priceOption: value });\n },\n { signal }\n );\n return h(\n 'div',\n { class: 'waykeev-input-group__item' },\n h(\n 'div',\n { class: 'waykeev-input-selection' },\n input,\n h(\n 'div',\n { class: 'waykeev-input-selection__header' },\n h('label', { class: 'waykeev-input-selection__label', for: id }, label)\n )\n )\n );\n };\n\n // Shown for the template price only: with an own price they say nothing.\n const templatePriceRows = [\n detailRow(t('standardPriceRow'), priceLabel(templateCents)),\n detailRow(t('gridFee'), t('gridFeeValue')),\n ];\n\n refreshers.push(() => {\n const custom = state.priceOption === 'custom';\n priceField.hidden = !custom;\n for (const row of templatePriceRows) row.hidden = custom;\n });\n\n const closeButton = h(\n 'button',\n { type: 'button', class: 'waykeev-modal__close-btn' },\n h('span', { class: 'waykeev-sr-only' }, t('closeModal')),\n icon(ICONS.close)\n );\n\n const dialog = h(\n 'dialog',\n { class: 'waykeev-dialog', 'aria-labelledby': titleId },\n h(\n 'div',\n { class: 'waykeev-modal' },\n h(\n 'div',\n { class: 'waykeev-modal__container' },\n h(\n 'div',\n { class: 'waykeev-modal__center' },\n h(\n 'div',\n { class: 'waykeev-modal__dialog' },\n h('div', { class: 'waykeev-modal__close' }, closeButton),\n h(\n 'div',\n { class: 'waykeev-modal__body' },\n h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--3' },\n h('h3', { class: 'waykeev-heading waykeev-heading--3', id: titleId }, t('title')),\n h(\n 'div',\n { class: 'waykeev-content' },\n h('p', { class: 'waykeev-content__p' }, t('modalDescription'))\n )\n ),\n h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--3' },\n ...distanceControls(`${uid}-modal`)\n ),\n h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--3' },\n h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--2' },\n h(\n 'fieldset',\n { class: 'waykeev-input-group' },\n h(\n 'legend',\n { class: 'waykeev-input-label' },\n h('div', { class: 'waykeev-input-label__label' }, t('whichPrice'))\n ),\n priceOptionRadio('standard', t('standardPrice')),\n priceOptionRadio('custom', t('customPrice'))\n )\n ),\n priceField\n ),\n h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--3' },\n costBalloon(\n () => state.priceOption,\n h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--3' },\n h(\n 'ul',\n { class: 'waykeev-key-value-list' },\n data.batteryCapacityKwh !== undefined &&\n detailRow(\n t('batteryCapacity'),\n `${t.number(data.batteryCapacityKwh, 1)} kWh`\n ),\n data.rangeKm !== undefined &&\n detailRow(t('range'), `${t.number(data.rangeKm)} km`),\n detailRow(\n t('energyUse'),\n `${t.number(data.energyPer100Km, 1)} ${t('energyUnit')}`\n ),\n detailRow(t('statedDistance'), () => distanceLabel(state.distance)),\n ...templatePriceRows\n )\n )\n )\n )\n ),\n h(\n 'footer',\n { class: 'waykeev-modal__footer' },\n h(\n 'div',\n { class: 'waykeev-hstack waykeev-hstack--spacing-1 waykeev-hstack--align-center' },\n ...poweredBy()\n )\n )\n )\n )\n )\n )\n );\n\n let pushedHash = false;\n\n const openDialog = () => {\n if (dialog.open) return;\n dialog.showModal();\n if (props.hash && window.location.hash !== HASH) {\n window.location.hash = HASH;\n pushedHash = true;\n }\n emit({ type: 'modal-open' });\n };\n\n closeButton.addEventListener('click', () => dialog.close(), { signal });\n\n // A click on the dimmed area around the dialog closes it, like Escape does.\n dialog.addEventListener(\n 'click',\n (event) => {\n const target = event.target as HTMLElement;\n if (target === dialog || target.matches('.waykeev-modal, .waykeev-modal__center')) {\n dialog.close();\n }\n },\n { signal }\n );\n\n // Fires for the close button, Escape and the back button alike.\n dialog.addEventListener(\n 'close',\n () => {\n if (pushedHash && window.location.hash === HASH) window.history.back();\n pushedHash = false;\n emit({ type: 'modal-close' });\n },\n { signal }\n );\n\n if (props.hash) {\n window.addEventListener(\n 'hashchange',\n () => {\n if (dialog.open && window.location.hash !== HASH) {\n pushedHash = false;\n dialog.close();\n }\n },\n { signal }\n );\n }\n\n // ---- Preview ---------------------------------------------------------------\n\n const openButton = h(\n 'button',\n { type: 'button', class: 'waykeev-link', 'aria-haspopup': 'dialog' },\n h('span', { class: 'waykeev-link__content' }, t('openCalculator'))\n );\n openButton.addEventListener('click', openDialog, { signal });\n\n root.replaceChildren(\n h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--3' },\n h('h2', { class: 'waykeev-heading waykeev-heading--2' }, t('title')),\n h(\n 'div',\n { class: 'waykeev-content' },\n h('p', { class: 'waykeev-content__p' }, t('description'))\n )\n ),\n h('div', { class: 'waykeev-stack waykeev-stack--3' }, ...distanceControls(uid)),\n h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--3' },\n costBalloon(() => 'standard')\n ),\n h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--3' },\n h(\n 'div',\n { class: 'waykeev-hstack waykeev-hstack--spacing-2 waykeev-hstack--align-center' },\n h(\n 'div',\n { class: 'waykeev-hstack__item waykeev-hstack__item--no-shrink', 'aria-hidden': 'true' },\n h(\n 'div',\n {\n class:\n 'waykeev-icon-backdrop waykeev-icon-backdrop--large waykeev-icon-backdrop--success',\n },\n icon(ICONS.bulb)\n )\n ),\n h(\n 'div',\n { class: 'waykeev-hstack__item waykeev-hstack__item--grow' },\n h(\n 'span',\n { class: 'waykeev-text waykeev-text--font-medium waykeev-text--bump-right' },\n t('adjustToYourPrice')\n ),\n openButton\n )\n )\n ),\n h(\n 'div',\n { class: 'waykeev-stack waykeev-stack--3' },\n h(\n 'div',\n {\n class:\n 'waykeev-hstack waykeev-hstack--spacing-1 waykeev-hstack--align-center waykeev-hstack--justify-center',\n },\n ...poweredBy()\n )\n ),\n dialog\n );\n\n refresh();\n};\n", "import { version } from '../package.json';\nimport { ApiError, fetchChargingData } from './api.js';\nimport { isChargingData } from './chargingCost.js';\nimport { createTranslator, defaultLanguage } from './i18n.js';\nimport type { ChargingData, EvEvent, EvInstance, MountOptions, Theme } from './types.js';\nimport { renderWidget } from './widget.js';\n\nconst resolveTarget = (target: string | Element): Element => {\n const element = typeof target === 'string' ? document.querySelector(target) : target;\n if (!element) throw new Error(`Wayke EV: no element matches \"${target}\"`);\n return element;\n};\n\n// Set on the widget's own root, so two widgets on a page can have different themes.\nconst applyTheme = (root: HTMLElement, theme: Theme | undefined) => {\n if (theme?.primaryColor) root.style.setProperty('--theme-primary-bg', theme.primaryColor);\n if (theme?.primaryColorForeground) {\n root.style.setProperty('--theme-primary-fg', theme.primaryColorForeground);\n }\n if (theme?.linkColor) root.style.setProperty('--theme-link-color', theme.linkColor);\n};\n\n/**\n * Shows the charging cost calculator for one vehicle inside `target`, a CSS selector\n * or an element.\n *\n * Nothing is shown while the figures load, or when the vehicle has no charging cost:\n * `onEvent` then gets `unavailable` or `error`, and the page keeps its layout.\n */\nexport const mount = (target: string | Element, options: MountOptions): EvInstance => {\n const element = resolveTarget(target);\n if (!options?.id && !options?.data) {\n throw new Error('Wayke EV: either \"id\" or \"data\" is required');\n }\n\n const controller = new AbortController();\n const root = document.createElement('div');\n root.className = 'waykeev-root';\n root.dataset.version = version;\n root.hidden = true;\n applyTheme(root, options.theme);\n element.append(root);\n\n // A listener that throws must not take the widget down with it.\n const emit = (event: EvEvent) => {\n if (controller.signal.aborted) return;\n try {\n options.onEvent?.(event);\n } catch (error) {\n setTimeout(() => {\n throw error;\n });\n }\n };\n\n const show = (data: ChargingData) => {\n const marketCode = options.marketCode ?? data.marketCode ?? 'SE';\n root.dataset.market = marketCode;\n renderWidget(root, {\n data,\n marketCode,\n t: createTranslator(options.language ?? defaultLanguage(marketCode)),\n hash: options.hash === true,\n emit,\n signal: controller.signal,\n });\n root.hidden = false;\n // Always after mount() has returned, also when the figures were passed in, so a\n // listener can rely on having the instance.\n queueMicrotask(() => emit({ type: 'ready', data }));\n };\n\n if (options.data) {\n if (isChargingData(options.data)) show(options.data);\n else queueMicrotask(() => emit({ type: 'unavailable', reason: 'no-charging-data' }));\n } else if (options.id) {\n fetchChargingData({\n id: options.id,\n environment: options.environment ?? 'production',\n apiKey: options.apiKey,\n signal: controller.signal,\n })\n .then((result) => {\n if (controller.signal.aborted) return;\n if (result.status === 'ok') show(result.data);\n else emit({ type: 'unavailable', reason: result.reason });\n })\n .catch((error: unknown) => {\n if (controller.signal.aborted) return;\n emit({ type: 'error', reason: error instanceof ApiError ? error.reason : 'network' });\n });\n }\n\n return {\n unmount: () => {\n if (controller.signal.aborted) return;\n // Closing first lets the dialog undo the hash it added and report that it closed.\n root.querySelector<HTMLDialogElement>('dialog[open]')?.close();\n controller.abort();\n root.remove();\n },\n };\n};\n"],
|
|
5
5
|
"mappings": "AAEE,IAAAA,EAAW,eCCb,IAAMC,GAAe,CAAC,IAAM,IAAO,KAAO,IAAO,KAAO,IAAO,KAAO,IAAO,KAAO,GAAK,EAE5EC,GAAsB,KAatBC,GAAiBC,GAA0C,CACtE,IAAMC,EAAYD,IAAe,KAAO,GAAK,EACvCE,EAAUL,GAAa,IAAKM,GAAOA,EAAKF,CAAS,EACvD,MAAO,CACL,KAAMD,IAAe,KAAO,MAAQ,KACpC,UAAAC,EACA,QAAAC,EACA,IAAKA,EAAQ,CAAC,EACd,IAAKA,EAAQA,EAAQ,OAAS,CAAC,EAC/B,KAAM,IAAOD,CACf,CACF,EAGaG,EAAWC,GAAgC,KAAK,MAAMA,EAAc,GAAG,EAUvEC,GAAmB,CAC9BC,EACAF,IACuB,CACvB,GAAI,SAAOA,GAAgB,UAAY,EAAEA,EAAc,IACvD,OAAID,EAAQC,CAAW,IAAMD,EAAQG,EAAK,WAAW,EAAUA,EAAK,UAC5DA,EAAK,eAAiB,IAAOF,CACvC,EAGaG,GAAc,CACzBC,EACAC,IACuB,CACvB,GA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,MAAOT,GAAmB,CACrBJ,EAAW,OAAO,SACtBE,EAAK,CAAE,KAAM,QAAS,OAAQE,aAAiBU,EAAWV,EAAM,OAAS,SAAU,CAAC,CACtF,CAAC,EAGE,CACL,QAAS,IAAM,CACTJ,EAAW,OAAO,UAEtBJ,EAAK,cAAiC,cAAc,GAAG,MAAM,EAC7DI,EAAW,MAAM,EACjBJ,EAAK,OAAO,EACd,CACF,CACF",
|
|
6
6
|
"names": ["version", "DISTANCES_KM", "DEFAULT_DISTANCE_KM", "distanceScale", "marketCode", "kmPerUnit", "options", "km", "toCents", "pricePerKwh", "costPerKmAtPrice", "data", "monthlyCost", "costPerKm", "distanceKmPerYear", "isPositive", "value", "isChargingData", "API_URLS", "CLIENT_VERSION", "version", "ATTRIBUTES", "AD_FIELDS", "QUERY", "ApiError", "reason", "positive", "value", "marketOfUnit", "unit", "toChargingData", "ad", "attributes", "data", "isChargingData", "fetchChargingData", "id", "environment", "apiKey", "signal", "response", "error", "body", "ads", "sv", "nb", "en", "MESSAGES", "LOCALES", "defaultLanguage", "marketCode", "createTranslator", "language", "messages", "locale", "t", "key", "values", "message", "match", "name", "value", "maximumFractionDigits", "brandOf", "SVG_NS", "setAttributes", "element", "attributes", "name", "value", "h", "tag", "children", "child", "icon", "path", "svg", "shape", "ICONS", "DRIVE_SYMBOL", "WAYKE_SYMBOL", "brandSymbol", "brand", "cx", "cy", "r", "circle", "HASH", "instances", "parsePrice", "value", "normalized", "price", "renderWidget", "root", "props", "data", "marketCode", "t", "emit", "signal", "uid", "scale", "distanceScale", "brand", "brandOf", "templateCents", "toCents", "state", "DEFAULT_DISTANCE_KM", "distanceKm", "distanceLabel", "distance", "priceLabel", "cents", "costLabel", "priceOption", "costPerKm", "costPerKmAtPrice", "cost", "monthlyCost", "refreshers", "refresh", "run", "distanceControls", "idPrefix", "selectId", "select", "h", "option", "range", "onChange", "control", "event", "percentage", "poweredBy", "brandSymbol", "costBalloon", "extra", "disclaimer", "detailRow", "label", "valueNode", "titleId", "priceInputId", "helpId", "priceInput", "help", "helpLabel", "helpButton", "icon", "ICONS", "priceField", "priceOptionRadio", "id", "input", "templatePriceRows", "custom", "row", "closeButton", "dialog", "pushedHash", "openDialog", "target", "openButton", "resolveTarget", "target", "element", "applyTheme", "root", "theme", "mount", "options", "controller", "version", "emit", "event", "error", "show", "data", "marketCode", "renderWidget", "createTranslator", "defaultLanguage", "isChargingData", "fetchChargingData", "result", "ApiError"]
|
|
7
7
|
}
|