@20baht/stickers 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -79,7 +79,7 @@ Light DOM, display block; the canvas fills the element's width at 1:1, so size t
79
79
  | `enter` | `number` | Seconds after first shown to pop in on the bounce entrance. |
80
80
  | `replay-on-hover` | `boolean` | Replay from frame 0 when the pointer enters. |
81
81
  | `line` | `number` | Outline weight as a multiple of the sticker's own: `0.6` thinner, `1.5` bolder. 1 by default. |
82
- | `label` | `string` | Accessible name; the sticker's name by default. |
82
+ | `label` | `string` | Accessible name; the sticker's name by default. `label=""` makes it decorative: skipped by assistive technology. |
83
83
 
84
84
  `replay()` restarts the motion. Register stickers before the element renders.
85
85
 
@@ -98,6 +98,13 @@ view waits until it scrolls in.
98
98
  | `gold` | `--baht-gold-400` | coins, stars, bells |
99
99
  | `ok` | `--baht-success` | checks, success |
100
100
  | `hot` | `--baht-error` | hearts, alerts |
101
+ | `free` | `--baht-color-text` | lines with no fill behind them |
102
+
103
+ The ink itself (`ink`, the outline of every fill) stays dark in dark mode. A line with nothing painted behind it (steam,
104
+ a stem, a signal arc) has no fill to stand on, so there it takes `free`: `--baht-color-text`, or the text colour on a
105
+ page without the tokens. A line that runs over a fill is ink on the fill and `free` past its edge. A `palette` of
106
+ your own draws those lines in its `ink` unless it sets `free`. Through `draw()`, "nothing behind it" means
107
+ transparent pixels: over a ground you painted first, lines are ink.
101
108
 
102
109
  Fixed palettes: `BAHT` (฿20) and `PALETTES.note50 | note100 | note500 | note1000`; helpers `brand(a, b)`,
103
110
  `mono(hex)`, `hue(deg)`. `paletteFromTokens(el)` reads the tokens yourself.
@@ -129,6 +136,22 @@ needed). With `interactive` the diagram is a group of buttons: each node takes f
129
136
  fires `baht-node` with `{ id, node }` (bubbles, composed), for opening the machine it stands for. The docs site has a builder
130
137
  that writes this JSON: https://bahtui-docs.pages.dev/guides/sticker-graph/
131
138
 
139
+ ## Under a Content-Security-Policy
140
+
141
+ The canvas needs nothing. Each element adds one `<style>` to `<head>` the first time it connects
142
+ (`#baht-sticker-style`, `#baht-sticker-graph-style`), which a CSP whose `style-src` has no
143
+ `'unsafe-inline'` blocks. Give it the page's nonce:
144
+
145
+ ```html
146
+ <script nonce="{RANDOM}">window.litNonce = '{RANDOM}'</script> <!-- every element on the page -->
147
+ <baht-sticker name="piggy-bank" nonce="{RANDOM}"></baht-sticker> <!-- or the first one -->
148
+ ```
149
+
150
+ The sheet takes the `nonce` of the element that adds it, or of the nearest ancestor that has one (the
151
+ stickers inside a `<baht-sticker-graph nonce>`), else `window.litNonce` (Lit's own name for the
152
+ page's nonce). The sheet is added once, so the nonce must be there before the first sticker connects.
153
+ In Angular, `nonce="…"` or `[attr.nonce]="nonce"` on the element.
154
+
132
155
  ## Entry points
133
156
 
134
157
  | Import | Contents |
package/dist/element.d.ts CHANGED
@@ -7,7 +7,7 @@ import type { Icon, Palette } from './sticker.js';
7
7
  * Give it a registered `name` (`<baht-sticker name="piggy-bank">` after `import '@20baht/stickers/all'` or
8
8
  * `registerSticker(piggyBank)`), or an `icon` object as a property, which wins over `name`.
9
9
  *
10
- * Without `palette` it reads the --baht-* tokens (primary, neutral, success, error, amber) where it sits and
10
+ * Without `palette` it reads the --baht-* tokens (primary, neutral, success, error, amber, text) where it sits and
11
11
  * re-reads them when the root's `data-note`, `data-theme`, `data-baht-theme`, `class` or `style`, or the colour scheme, changes,
12
12
  * so it follows the banknote theme and dark mode. It reads them when it is on screen: a sticker out of view waits
13
13
  * until it scrolls in, and one whose colours come back the same does not repaint.
@@ -19,8 +19,12 @@ import type { Icon, Palette } from './sticker.js';
19
19
  * @attr offset - Frames ahead of the page clock, to put neighbours out of phase.
20
20
  * @attr enter - Seconds after first shown to pop in on the bounce entrance; unset skips the entrance.
21
21
  * @attr replay-on-hover - Replay from frame 0 when the pointer enters.
22
- * @attr label - Accessible name; the sticker's name by default.
22
+ * @attr label - Accessible name; the sticker's name by default. Empty (`label=""`) makes the sticker decorative:
23
+ * assistive technology skips it, for one beside words that already say the same.
23
24
  * @attr line - Outline weight as a multiple of the sticker's own: `0.6` thinner, `1.5` bolder; 1 by default.
25
+ * @attr nonce - The standard attribute, read when the first sticker adds the one `<style>` every sticker shares:
26
+ * that sheet carries it, for a CSP `style-src` without `'unsafe-inline'`. Unset: an ancestor's (a graph's), else
27
+ * `window.litNonce`.
24
28
  */
25
29
  export declare class BahtSticker extends LitElement {
26
30
  static properties: {
@@ -70,6 +74,7 @@ export declare class BahtSticker extends LitElement {
70
74
  offset: number | undefined;
71
75
  enter: number | undefined;
72
76
  replayOnHover: boolean;
77
+ /** Accessible name; unset is the sticker's name, `''` makes it decorative (hidden from assistive technology). */
73
78
  label: string | undefined;
74
79
  /** Outline weight as a multiple of the sticker's own; unset is 1. */
75
80
  line: number | undefined;
@@ -86,6 +91,8 @@ export declare class BahtSticker extends LitElement {
86
91
  connectedCallback(): void;
87
92
  disconnectedCallback(): void;
88
93
  protected updated(changed: PropertyValues<this>): void;
94
+ /** An image with a name, or, with an empty one, nothing assistive technology reads. */
95
+ private nameCanvas;
89
96
  private readonly onPointerEnter;
90
97
  /** The theme may have changed: the tokens are read again when the sticker is next painted, not here. */
91
98
  private readonly onTheme;
package/dist/element.js CHANGED
@@ -1,14 +1,17 @@
1
1
  // <baht-sticker>: plays a sticker on canvas, coloured from the page's --baht-* tokens unless given a palette.
2
2
  import { LitElement } from 'lit';
3
3
  import { getSticker, paletteFromTokens, play } from './sticker.js';
4
+ import { styleNonce } from './style-nonce.js';
4
5
  const TAG = 'baht-sticker';
5
6
  const STYLE_ID = 'baht-sticker-style';
6
7
  /** One sheet for every sticker: block by default, the canvas fills its width at 1:1. Size the element with css. */
7
- function injectStyle() {
8
+ function injectStyle(nonce) {
8
9
  if (document.getElementById(STYLE_ID))
9
10
  return;
10
11
  const style = document.createElement('style');
11
12
  style.id = STYLE_ID;
13
+ if (nonce)
14
+ style.nonce = nonce;
12
15
  style.textContent = `:where(${TAG}){display:block}:where(${TAG})>canvas{display:block;width:100%;aspect-ratio:1}`;
13
16
  document.head.append(style);
14
17
  }
@@ -29,8 +32,10 @@ function watchTheme(stale) {
29
32
  attributes: true,
30
33
  attributeFilter: ['data-note', 'data-theme', 'data-baht-theme', 'class', 'style'],
31
34
  });
32
- schemeWatch = matchMedia('(prefers-color-scheme: dark)');
33
- schemeWatch.addEventListener('change', onTheme);
35
+ // jsdom has no matchMedia
36
+ schemeWatch =
37
+ typeof matchMedia === 'undefined' ? undefined : matchMedia('(prefers-color-scheme: dark)');
38
+ schemeWatch?.addEventListener('change', onTheme);
34
39
  }
35
40
  /** Taken down again when the last sticker leaves the page. */
36
41
  function unwatchTheme(stale) {
@@ -48,7 +53,7 @@ function unwatchTheme(stale) {
48
53
  * Give it a registered `name` (`<baht-sticker name="piggy-bank">` after `import '@20baht/stickers/all'` or
49
54
  * `registerSticker(piggyBank)`), or an `icon` object as a property, which wins over `name`.
50
55
  *
51
- * Without `palette` it reads the --baht-* tokens (primary, neutral, success, error, amber) where it sits and
56
+ * Without `palette` it reads the --baht-* tokens (primary, neutral, success, error, amber, text) where it sits and
52
57
  * re-reads them when the root's `data-note`, `data-theme`, `data-baht-theme`, `class` or `style`, or the colour scheme, changes,
53
58
  * so it follows the banknote theme and dark mode. It reads them when it is on screen: a sticker out of view waits
54
59
  * until it scrolls in, and one whose colours come back the same does not repaint.
@@ -60,8 +65,12 @@ function unwatchTheme(stale) {
60
65
  * @attr offset - Frames ahead of the page clock, to put neighbours out of phase.
61
66
  * @attr enter - Seconds after first shown to pop in on the bounce entrance; unset skips the entrance.
62
67
  * @attr replay-on-hover - Replay from frame 0 when the pointer enters.
63
- * @attr label - Accessible name; the sticker's name by default.
68
+ * @attr label - Accessible name; the sticker's name by default. Empty (`label=""`) makes the sticker decorative:
69
+ * assistive technology skips it, for one beside words that already say the same.
64
70
  * @attr line - Outline weight as a multiple of the sticker's own: `0.6` thinner, `1.5` bolder; 1 by default.
71
+ * @attr nonce - The standard attribute, read when the first sticker adds the one `<style>` every sticker shares:
72
+ * that sheet carries it, for a CSP `style-src` without `'unsafe-inline'`. Unset: an ancestor's (a graph's), else
73
+ * `window.litNonce`.
65
74
  */
66
75
  export class BahtSticker extends LitElement {
67
76
  static { this.properties = {
@@ -119,11 +128,10 @@ export class BahtSticker extends LitElement {
119
128
  }
120
129
  connectedCallback() {
121
130
  super.connectedCallback();
122
- injectStyle();
131
+ injectStyle(styleNonce(this));
123
132
  this.canvas ??= document.createElement('canvas');
124
133
  if (!this.canvas.isConnected)
125
134
  this.append(this.canvas);
126
- this.canvas.setAttribute('role', 'img');
127
135
  this.addEventListener('pointerenter', this.onPointerEnter);
128
136
  watchTheme(this.onTheme);
129
137
  // the first connect starts from updated(); a reconnect has no property change to start it
@@ -140,12 +148,23 @@ export class BahtSticker extends LitElement {
140
148
  }
141
149
  updated(changed) {
142
150
  const icon = this.resolvedIcon;
143
- this.canvas?.setAttribute('aria-label', this.label ?? icon?.name ?? this.name ?? 'sticker');
151
+ this.nameCanvas(this.label ?? icon?.name ?? this.name ?? 'sticker');
144
152
  if (icon !== this.playing || !this.player)
145
153
  this.start();
146
154
  else if (changed.size)
147
155
  this.player.set(this.options());
148
156
  }
157
+ /** An image with a name, or, with an empty one, nothing assistive technology reads. */
158
+ nameCanvas(name) {
159
+ const attrs = { role: 'img', 'aria-label': name, 'aria-hidden': 'true' };
160
+ const on = name === '' ? ['aria-hidden'] : ['role', 'aria-label'];
161
+ for (const [attr, value] of Object.entries(attrs)) {
162
+ if (on.includes(attr))
163
+ this.canvas?.setAttribute(attr, value);
164
+ else
165
+ this.canvas?.removeAttribute(attr);
166
+ }
167
+ }
149
168
  options() {
150
169
  return {
151
170
  palette: this.palette ?? this.readTokens,
package/dist/graph.d.ts CHANGED
@@ -88,6 +88,8 @@ export declare function layoutGraph(graph: StickerGraph): GraphLayout;
88
88
  * @attr hide-grid - Leaves out the floor grid.
89
89
  * @attr label - Accessible name of the diagram.
90
90
  * @attr interactive - Nodes are focusable buttons that fire `baht-node`.
91
+ * @attr nonce - The standard attribute: the `<style>` the graph adds (and its stickers' one) carries it, for a CSP
92
+ * `style-src` without `'unsafe-inline'`. Unset: `window.litNonce`.
91
93
  */
92
94
  export declare class BahtStickerGraph extends LitElement {
93
95
  static properties: {
package/dist/graph.js CHANGED
@@ -3,6 +3,7 @@
3
3
  import { html, LitElement, nothing, svg } from 'lit';
4
4
  import './element.js';
5
5
  import { onFace, VIEWS } from './sticker.js';
6
+ import { styleNonce } from './style-nonce.js';
6
7
  /** Floor units per grid cell, and the sticker's width in the same units. */
7
8
  export const CELL = 150;
8
9
  export const STICKER = 150;
@@ -90,11 +91,13 @@ const TAG = 'baht-sticker-graph';
90
91
  const STYLE_ID = 'baht-sticker-graph-style';
91
92
  const GAP_MS = 260;
92
93
  const REST_MS = 1400;
93
- function injectStyle() {
94
+ function injectStyle(nonce) {
94
95
  if (document.getElementById(STYLE_ID))
95
96
  return;
96
97
  const style = document.createElement('style');
97
98
  style.id = STYLE_ID;
99
+ if (nonce)
100
+ style.nonce = nonce;
98
101
  style.textContent = `
99
102
  :where(${TAG}){display:block;position:relative;font-family:var(--baht-font-mono,ui-monospace,monospace)}
100
103
  :where(${TAG}) .bsg-stage{position:relative;width:100%;overflow:hidden}
@@ -157,6 +160,8 @@ function arrow(from, to) {
157
160
  * @attr hide-grid - Leaves out the floor grid.
158
161
  * @attr label - Accessible name of the diagram.
159
162
  * @attr interactive - Nodes are focusable buttons that fire `baht-node`.
163
+ * @attr nonce - The standard attribute: the `<style>` the graph adds (and its stickers' one) carries it, for a CSP
164
+ * `style-src` without `'unsafe-inline'`. Unset: `window.litNonce`.
160
165
  */
161
166
  export class BahtStickerGraph extends LitElement {
162
167
  static { this.properties = {
@@ -214,7 +219,7 @@ export class BahtStickerGraph extends LitElement {
214
219
  }
215
220
  connectedCallback() {
216
221
  super.connectedCallback();
217
- injectStyle();
222
+ injectStyle(styleNonce(this));
218
223
  if (typeof matchMedia !== 'undefined') {
219
224
  this.motion = matchMedia('(prefers-reduced-motion: reduce)');
220
225
  this.motion.addEventListener('change', this.wake);
@@ -12,6 +12,9 @@ import { scissors } from './scissors.js';
12
12
  import { clipboard } from './clipboard.js';
13
13
  import { highlighter } from './highlighter.js';
14
14
  import { eyedropper } from './eyedropper.js';
15
+ import { ticketSearch } from './ticket-search.js';
16
+ import { ticketStamped } from './ticket-stamped.js';
17
+ import { ticketWallet } from './ticket-wallet.js';
15
18
  import { timer } from './timer.js';
16
19
  import { snapshots } from './snapshots.js';
17
20
  import { remoteDesktop } from './remote-desktop.js';
@@ -182,6 +185,6 @@ import { redmiNote9sPro } from './redmi-note-9s-pro.js';
182
185
  import { nas2bay } from './nas-2bay.js';
183
186
  import { powerStation } from './power-station.js';
184
187
  import { studioMonitors } from './studio-monitors.js';
185
- export { file, trash, copyFiles, compare, remoteFolder, photo, hardDrive, usbDrive, snip, scissors, clipboard, highlighter, eyedropper, timer, snapshots, remoteDesktop, cursor, keyboard, terminal, tunnel, wakeOnLan, lockScreen, aiAgent, certificate, sslCertificate, piggyBank, stock, bahtNote, dollarNote, bond, goldBar, kaprao, noodleSoup, padSeeEw, trainTicket, tukTuk, chaYen, mangoStickyRice, twoFactor, otp, sms, email, register, support, idCard, fingerprint, faceId, password, verified, qrCode, accessPoint, allInOne, badgeReader, bear, bladeChassis, cctv, classicPhone, cooling, coreSwitch, database, desktopTower, firewall, homeRouter, hsm, iotSensor, ipPhone, key, kvm, laptop, loadBalancer, miniPc, modem, monitor, nas, notebook, patchPanel, pdu, pos, printer, rack, router, server, serverCabinet, shield, smartphone, smartTv, storageArray, switchBox, tablet, tapeLibrary, ups, vpnGateway, wallet, macMini, thinkpadL380, macbookAir, ipadGen8, iphone17, redmiNote9sPro, nas2bay, powerStation, studioMonitors, receipt, income, expense, coins, calculator, budgetJar, pieChart, calendarMonth, cron, kanban, goal, overBudget, savingStreak, emptyState, exportFile, scanSlip, interest, btsCard, motorbikeTaxi, convenienceBag, electricBill, phoneTopup, rent, marketBasket, lottery, templeDonation, fuel, shoppingBox, salary, angpao, freelance, spiritHouse, thaiHouse, woodenWindow, waterJar, streetFoodCart, plasticStool, powerPole, streetSign, mailboxThai, chedi, marigold, phuangMalai, bananaTree, bamboo, longTailBoat, bananaLeaf, thaiLantern, lotus, sun, moon, cloud, rainCloud, storm, rainbow, star, shootingStar, rock, pottedPlant, cactus, monstera, flower, tulip, tree, palmTree, campfire, tent, confetti, musicNote, mediaPlayer, paperBoat, kite, alarmClock, books, hotDrink, lamp, discImage, keyPair, metrics, virtualMachine, floatingIp, };
188
+ export { file, trash, copyFiles, compare, remoteFolder, photo, hardDrive, usbDrive, snip, scissors, clipboard, highlighter, eyedropper, timer, snapshots, remoteDesktop, cursor, keyboard, terminal, tunnel, wakeOnLan, lockScreen, aiAgent, certificate, sslCertificate, piggyBank, stock, bahtNote, dollarNote, bond, goldBar, kaprao, noodleSoup, padSeeEw, trainTicket, ticketStamped, ticketSearch, ticketWallet, tukTuk, chaYen, mangoStickyRice, twoFactor, otp, sms, email, register, support, idCard, fingerprint, faceId, password, verified, qrCode, accessPoint, allInOne, badgeReader, bear, bladeChassis, cctv, classicPhone, cooling, coreSwitch, database, desktopTower, firewall, homeRouter, hsm, iotSensor, ipPhone, key, kvm, laptop, loadBalancer, miniPc, modem, monitor, nas, notebook, patchPanel, pdu, pos, printer, rack, router, server, serverCabinet, shield, smartphone, smartTv, storageArray, switchBox, tablet, tapeLibrary, ups, vpnGateway, wallet, macMini, thinkpadL380, macbookAir, ipadGen8, iphone17, redmiNote9sPro, nas2bay, powerStation, studioMonitors, receipt, income, expense, coins, calculator, budgetJar, pieChart, calendarMonth, cron, kanban, goal, overBudget, savingStreak, emptyState, exportFile, scanSlip, interest, btsCard, motorbikeTaxi, convenienceBag, electricBill, phoneTopup, rent, marketBasket, lottery, templeDonation, fuel, shoppingBox, salary, angpao, freelance, spiritHouse, thaiHouse, woodenWindow, waterJar, streetFoodCart, plasticStool, powerPole, streetSign, mailboxThai, chedi, marigold, phuangMalai, bananaTree, bamboo, longTailBoat, bananaLeaf, thaiLantern, lotus, sun, moon, cloud, rainCloud, storm, rainbow, star, shootingStar, rock, pottedPlant, cactus, monstera, flower, tulip, tree, palmTree, campfire, tent, confetti, musicNote, mediaPlayer, paperBoat, kite, alarmClock, books, hotDrink, lamp, discImage, keyPair, metrics, virtualMachine, floatingIp, };
186
189
  /** The whole set, in catalogue order. */
187
190
  export declare const ICONS: readonly Icon[];
@@ -11,6 +11,9 @@ import { scissors } from './scissors.js';
11
11
  import { clipboard } from './clipboard.js';
12
12
  import { highlighter } from './highlighter.js';
13
13
  import { eyedropper } from './eyedropper.js';
14
+ import { ticketSearch } from './ticket-search.js';
15
+ import { ticketStamped } from './ticket-stamped.js';
16
+ import { ticketWallet } from './ticket-wallet.js';
14
17
  import { timer } from './timer.js';
15
18
  import { snapshots } from './snapshots.js';
16
19
  import { remoteDesktop } from './remote-desktop.js';
@@ -181,7 +184,7 @@ import { redmiNote9sPro } from './redmi-note-9s-pro.js';
181
184
  import { nas2bay } from './nas-2bay.js';
182
185
  import { powerStation } from './power-station.js';
183
186
  import { studioMonitors } from './studio-monitors.js';
184
- export { file, trash, copyFiles, compare, remoteFolder, photo, hardDrive, usbDrive, snip, scissors, clipboard, highlighter, eyedropper, timer, snapshots, remoteDesktop, cursor, keyboard, terminal, tunnel, wakeOnLan, lockScreen, aiAgent, certificate, sslCertificate, piggyBank, stock, bahtNote, dollarNote, bond, goldBar, kaprao, noodleSoup, padSeeEw, trainTicket, tukTuk, chaYen, mangoStickyRice, twoFactor, otp, sms, email, register, support, idCard, fingerprint, faceId, password, verified, qrCode, accessPoint, allInOne, badgeReader, bear, bladeChassis, cctv, classicPhone, cooling, coreSwitch, database, desktopTower, firewall, homeRouter, hsm, iotSensor, ipPhone, key, kvm, laptop, loadBalancer, miniPc, modem, monitor, nas, notebook, patchPanel, pdu, pos, printer, rack, router, server, serverCabinet, shield, smartphone, smartTv, storageArray, switchBox, tablet, tapeLibrary, ups, vpnGateway, wallet, macMini, thinkpadL380, macbookAir, ipadGen8, iphone17, redmiNote9sPro, nas2bay, powerStation, studioMonitors, receipt, income, expense, coins, calculator, budgetJar, pieChart, calendarMonth, cron, kanban, goal, overBudget, savingStreak, emptyState, exportFile, scanSlip, interest, btsCard, motorbikeTaxi, convenienceBag, electricBill, phoneTopup, rent, marketBasket, lottery, templeDonation, fuel, shoppingBox, salary, angpao, freelance, spiritHouse, thaiHouse, woodenWindow, waterJar, streetFoodCart, plasticStool, powerPole, streetSign, mailboxThai, chedi, marigold, phuangMalai, bananaTree, bamboo, longTailBoat, bananaLeaf, thaiLantern, lotus, sun, moon, cloud, rainCloud, storm, rainbow, star, shootingStar, rock, pottedPlant, cactus, monstera, flower, tulip, tree, palmTree, campfire, tent, confetti, musicNote, mediaPlayer, paperBoat, kite, alarmClock, books, hotDrink, lamp, discImage, keyPair, metrics, virtualMachine, floatingIp, };
187
+ export { file, trash, copyFiles, compare, remoteFolder, photo, hardDrive, usbDrive, snip, scissors, clipboard, highlighter, eyedropper, timer, snapshots, remoteDesktop, cursor, keyboard, terminal, tunnel, wakeOnLan, lockScreen, aiAgent, certificate, sslCertificate, piggyBank, stock, bahtNote, dollarNote, bond, goldBar, kaprao, noodleSoup, padSeeEw, trainTicket, ticketStamped, ticketSearch, ticketWallet, tukTuk, chaYen, mangoStickyRice, twoFactor, otp, sms, email, register, support, idCard, fingerprint, faceId, password, verified, qrCode, accessPoint, allInOne, badgeReader, bear, bladeChassis, cctv, classicPhone, cooling, coreSwitch, database, desktopTower, firewall, homeRouter, hsm, iotSensor, ipPhone, key, kvm, laptop, loadBalancer, miniPc, modem, monitor, nas, notebook, patchPanel, pdu, pos, printer, rack, router, server, serverCabinet, shield, smartphone, smartTv, storageArray, switchBox, tablet, tapeLibrary, ups, vpnGateway, wallet, macMini, thinkpadL380, macbookAir, ipadGen8, iphone17, redmiNote9sPro, nas2bay, powerStation, studioMonitors, receipt, income, expense, coins, calculator, budgetJar, pieChart, calendarMonth, cron, kanban, goal, overBudget, savingStreak, emptyState, exportFile, scanSlip, interest, btsCard, motorbikeTaxi, convenienceBag, electricBill, phoneTopup, rent, marketBasket, lottery, templeDonation, fuel, shoppingBox, salary, angpao, freelance, spiritHouse, thaiHouse, woodenWindow, waterJar, streetFoodCart, plasticStool, powerPole, streetSign, mailboxThai, chedi, marigold, phuangMalai, bananaTree, bamboo, longTailBoat, bananaLeaf, thaiLantern, lotus, sun, moon, cloud, rainCloud, storm, rainbow, star, shootingStar, rock, pottedPlant, cactus, monstera, flower, tulip, tree, palmTree, campfire, tent, confetti, musicNote, mediaPlayer, paperBoat, kite, alarmClock, books, hotDrink, lamp, discImage, keyPair, metrics, virtualMachine, floatingIp, };
185
188
  /** The whole set, in catalogue order. */
186
189
  export const ICONS = [
187
190
  wallet,
@@ -339,6 +342,9 @@ export const ICONS = [
339
342
  noodleSoup,
340
343
  padSeeEw,
341
344
  trainTicket,
345
+ ticketStamped,
346
+ ticketSearch,
347
+ ticketWallet,
342
348
  tukTuk,
343
349
  chaYen,
344
350
  mangoStickyRice,
@@ -0,0 +1,2 @@
1
+ import type { Icon } from '../sticker.js';
2
+ export declare const ticketSearch: Icon;
@@ -0,0 +1,50 @@
1
+ // Nothing matches: a magnifier goes over a blank coupon and finds no line on it.
2
+ // Drawn for ITSM (itsm-web), moved here from its repo.
3
+ import { jolt, slide, twinkle } from '../motions.js';
4
+ import { ellipse, line, poly, rect, ring } from '../sticker.js';
5
+ import { EXT, FACE, glow, LINE } from './shared.js';
6
+ const BAND = [
7
+ [-165, -100],
8
+ [165, -100],
9
+ [165, -64],
10
+ [-165, -64],
11
+ ];
12
+ const PERF = [-54, -26, 2, 30, 58].map((y) => ({
13
+ d: line([-84, y], [-84, y + 14]),
14
+ line: 4,
15
+ }));
16
+ export const ticketSearch = {
17
+ name: 'ticket-search',
18
+ frames: 180,
19
+ line: LINE,
20
+ extrude: EXT,
21
+ still: 80,
22
+ layers: [
23
+ { id: 'root', p: [246, 262], shapes: [] },
24
+ {
25
+ id: 'ticket',
26
+ parent: 'root',
27
+ tilt: FACE,
28
+ m: { ...jolt(), k: 0.5 },
29
+ shapes: [
30
+ { d: rect(-165, -100, 330, 190, 16), fill: 'white', depth: 0.8 },
31
+ { d: poly(BAND, [16, 16, 0, 0]), fill: 'main' },
32
+ ...PERF,
33
+ { d: line([-146, -24], [-106, -24]), line: 9 },
34
+ { d: line([-146, 4], [-116, 4]) },
35
+ ],
36
+ },
37
+ {
38
+ parent: 'root',
39
+ tilt: FACE,
40
+ m: slide([86, 10], 14, 50, 50),
41
+ shapes: [
42
+ { d: rect(8, 84, 28, 96, 12), fill: 'gold', depth: 0.8 },
43
+ { d: ellipse(22, 22, 52), fill: 'tint' },
44
+ { d: ring(22, 22, 66, 48), fill: 'deep', depth: 0.6 },
45
+ { d: line([-4, 12], [12, -4]), line: 7 },
46
+ ],
47
+ },
48
+ glow('root', [-160, -120], 24, [twinkle(60), twinkle(140, true)]),
49
+ ],
50
+ };
@@ -0,0 +1,2 @@
1
+ import type { Icon } from '../sticker.js';
2
+ export declare const ticketStamped: Icon;
@@ -0,0 +1,66 @@
1
+ // A request handed in: a coupon lies on the desk, a rubber stamp comes down on it and leaves a green check.
2
+ // Drawn for ITSM (itsm-web), moved here from its repo.
3
+ import { impact, slide, twinkle } from '../motions.js';
4
+ import { line } from '../sticker.js';
5
+ import { block, dot, faceOf, ISO, quad, solid, stroke } from '../iso.js';
6
+ import { drum } from './object-drum.js';
7
+ import { glow, LINE } from './shared.js';
8
+ const TICKET = block([-170, -95, 0], [340, 0, 0], [0, 190, 0], [0, 0, 14]);
9
+ const TOP = faceOf(TICKET, 'top');
10
+ // the coupon's tear line, left of the stub
11
+ const PERF = [0.1, 0.24, 0.38, 0.52, 0.66].map((t) => ({
12
+ d: stroke(TOP, [0.27, t], [0.27, t + 0.07]),
13
+ line: 4,
14
+ }));
15
+ // the mark sits where the stamp lands
16
+ const MARK = [0.64, 0.38];
17
+ const [mx, my] = TOP.at(...MARK);
18
+ const PAD = block([-8, -63, 14], [112, 0, 0], [0, 80, 0], [0, 0, 24]);
19
+ const NECK = drum([48, -23, 38], [0, 0, 44], 15, 15, { side: 'grey', cap: 'grey' });
20
+ const KNOB = drum([48, -23, 78], [0, 0, 34], 34, 34, { side: 'main', cap: 'main' });
21
+ const RAISED = 120;
22
+ export const ticketStamped = {
23
+ name: 'ticket-stamped',
24
+ frames: 180,
25
+ line: LINE,
26
+ extrude: [0, 0],
27
+ still: 130,
28
+ layers: [
29
+ { id: 'desk', p: [250, 320], shapes: [] },
30
+ {
31
+ id: 'ticket',
32
+ parent: 'desk',
33
+ m: { ...impact([0, 6]), at: 14 },
34
+ shapes: [
35
+ ...solid(TICKET, { fill: 'white' }, 4),
36
+ { d: quad(TOP, 0, 0.8, 1, 0.2, 4), fill: 'main' },
37
+ ...PERF,
38
+ { d: stroke(TOP, [0.07, 0.56], [0.2, 0.56]), line: 9 },
39
+ { d: stroke(TOP, [0.07, 0.36], [0.17, 0.36]) },
40
+ { d: stroke(TOP, [0.34, 0.64], [0.46, 0.64]) },
41
+ { d: stroke(TOP, [0.34, 0.44], [0.44, 0.44]) },
42
+ { d: stroke(TOP, [0.34, 0.24], [0.46, 0.24]) },
43
+ ],
44
+ },
45
+ {
46
+ parent: 'ticket',
47
+ a: [mx, my],
48
+ p: [mx, my],
49
+ m: [twinkle(26), twinkle(150, true)],
50
+ shapes: [
51
+ { d: dot(TOP, MARK[0], MARK[1], 0.12, 0.215), fill: 'ok' },
52
+ {
53
+ d: line(TOP.at(MARK[0] - 0.055, MARK[1] + 0.01), TOP.at(MARK[0] - 0.01, MARK[1] - 0.08), TOP.at(MARK[0] + 0.065, MARK[1] + 0.1)),
54
+ line: 9,
55
+ },
56
+ ],
57
+ },
58
+ {
59
+ parent: 'desk',
60
+ p: [0, -RAISED],
61
+ m: slide([0, RAISED], 6, 14, 34),
62
+ shapes: [...solid(PAD, { fill: 'deep', top: 'main' }, 4), ...NECK.shapes, ...KNOB.shapes],
63
+ },
64
+ glow('desk', [ISO([-170, 0, 0])[0] + 10, -120], 24, [twinkle(64), twinkle(140, true)]),
65
+ ],
66
+ };
@@ -0,0 +1,2 @@
1
+ import type { Icon } from '../sticker.js';
2
+ export declare const ticketWallet: Icon;
@@ -0,0 +1,44 @@
1
+ // No request yet: a ticket wallet with a blank coupon that slides up out of its pocket, ready to fill in.
2
+ // Drawn for ITSM (itsm-web), moved here from its repo.
3
+ import { jolt, slide, twinkle } from '../motions.js';
4
+ import { line, pill, rect } from '../sticker.js';
5
+ import { EXT, FACE, glow, LINE } from './shared.js';
6
+ const PERF = [-118, -88, -58, -28, 2, 32, 62, 92].map((x) => ({
7
+ d: line([x, -62], [x + 16, -62]),
8
+ line: 4,
9
+ }));
10
+ export const ticketWallet = {
11
+ name: 'ticket-wallet',
12
+ frames: 180,
13
+ line: LINE,
14
+ extrude: EXT,
15
+ still: 90,
16
+ layers: [
17
+ { id: 'root', p: [250, 290], m: { ...jolt(), k: 0.5 }, shapes: [] },
18
+ { id: 'face', parent: 'root', tilt: FACE, shapes: [] },
19
+ {
20
+ parent: 'face',
21
+ shapes: [{ d: rect(-150, -110, 300, 220, 20), fill: 'deep', depth: 1 }],
22
+ },
23
+ {
24
+ parent: 'face',
25
+ m: slide([0, -56], 12, 60, 48),
26
+ shapes: [
27
+ { d: rect(-128, -100, 256, 180, 12), fill: 'white', depth: 0.3 },
28
+ { d: line([-104, -80], [-30, -80]), line: 9 },
29
+ { d: pill(66, -88, 40, 16), fill: 'ok' },
30
+ ...PERF,
31
+ { d: line([-104, -36], [40, -36]) },
32
+ ],
33
+ },
34
+ {
35
+ parent: 'face',
36
+ shapes: [
37
+ { d: rect(-150, -18, 300, 128, 20), fill: 'main', depth: 0.6 },
38
+ { d: rect(-46, 26, 92, 40, 8), fill: 'white', depth: 0.2 },
39
+ { d: line([-26, 46], [26, 46]) },
40
+ ],
41
+ },
42
+ glow('root', [-170, -130], 24, [twinkle(60), twinkle(140, true)]),
43
+ ],
44
+ };
package/dist/load.d.ts CHANGED
@@ -166,6 +166,9 @@ declare const LOADERS: {
166
166
  'thai-house': () => Promise<Icon>;
167
167
  'thai-lantern': () => Promise<Icon>;
168
168
  'thinkpad-l380': () => Promise<Icon>;
169
+ 'ticket-search': () => Promise<Icon>;
170
+ 'ticket-stamped': () => Promise<Icon>;
171
+ 'ticket-wallet': () => Promise<Icon>;
169
172
  timer: () => Promise<Icon>;
170
173
  'train-ticket': () => Promise<Icon>;
171
174
  trash: () => Promise<Icon>;
package/dist/load.js CHANGED
@@ -165,6 +165,9 @@ const LOADERS = {
165
165
  'thai-house': async () => (await import('./icons/thai-house.js')).thaiHouse,
166
166
  'thai-lantern': async () => (await import('./icons/thai-lantern.js')).thaiLantern,
167
167
  'thinkpad-l380': async () => (await import('./icons/thinkpad-l380.js')).thinkpadL380,
168
+ 'ticket-search': async () => (await import('./icons/ticket-search.js')).ticketSearch,
169
+ 'ticket-stamped': async () => (await import('./icons/ticket-stamped.js')).ticketStamped,
170
+ 'ticket-wallet': async () => (await import('./icons/ticket-wallet.js')).ticketWallet,
168
171
  timer: async () => (await import('./icons/timer.js')).timer,
169
172
  'train-ticket': async () => (await import('./icons/train-ticket.js')).trainTicket,
170
173
  trash: async () => (await import('./icons/trash.js')).trash,
package/dist/sticker.d.ts CHANGED
@@ -44,6 +44,8 @@ export interface Palette {
44
44
  grey: string;
45
45
  paper: string;
46
46
  ink: string;
47
+ /** Lines with nothing painted behind them (steam, a stem, a signal arc), so they read on a dark page; `ink` when unset. */
48
+ free?: string;
47
49
  }
48
50
  export declare const ACCENTS: readonly ["main", "gold", "tint", "ok", "hot", "deep"];
49
51
  export type Accent = (typeof ACCENTS)[number];
@@ -63,6 +65,8 @@ export declare const PALETTES: {
63
65
  grey: string;
64
66
  paper: string;
65
67
  ink: string;
68
+ /** Lines with nothing painted behind them (steam, a stem, a signal arc), so they read on a dark page; `ink` when unset. */
69
+ free?: string;
66
70
  };
67
71
  note100: {
68
72
  main: string;
@@ -75,6 +79,8 @@ export declare const PALETTES: {
75
79
  grey: string;
76
80
  paper: string;
77
81
  ink: string;
82
+ /** Lines with nothing painted behind them (steam, a stem, a signal arc), so they read on a dark page; `ink` when unset. */
83
+ free?: string;
78
84
  };
79
85
  note500: {
80
86
  main: string;
@@ -87,6 +93,8 @@ export declare const PALETTES: {
87
93
  grey: string;
88
94
  paper: string;
89
95
  ink: string;
96
+ /** Lines with nothing painted behind them (steam, a stem, a signal arc), so they read on a dark page; `ink` when unset. */
97
+ free?: string;
90
98
  };
91
99
  note1000: {
92
100
  main: string;
@@ -99,11 +107,13 @@ export declare const PALETTES: {
99
107
  grey: string;
100
108
  paper: string;
101
109
  ink: string;
110
+ /** Lines with nothing painted behind them (steam, a stem, a signal arc), so they read on a dark page; `ink` when unset. */
111
+ free?: string;
102
112
  };
103
113
  };
104
114
  export type PaletteName = keyof typeof PALETTES;
105
115
  /** A slot, so the colour follows the palette it is drawn with, or a fixed hex. */
106
- export type Swatch = keyof Palette | `#${string}`;
116
+ export type Swatch = Exclude<keyof Palette, 'free'> | `#${string}`;
107
117
  /** Which way flat faces turn, as the layer tilt and icon extrude that draw it. `right` is the house view. */
108
118
  export declare const VIEWS: {
109
119
  readonly right: {
@@ -189,7 +199,10 @@ export declare const shift: <T>(track: Track<T>, by: number) => Track<T>;
189
199
  /** Where a point drawn on a face with this tilt lands in the layer's parent, for pivots and sparkles. */
190
200
  export declare function onFace(tilt: Vec, [x, y]: Vec): Vec;
191
201
  type Ctx = CanvasRenderingContext2D;
192
- /** Paints frame f of an icon into ctx, whose current transform maps icon units (0..size) to its box; `line` scales every outline. */
202
+ /**
203
+ * Paints frame f of an icon into ctx, whose current transform maps icon units (0..size) to its box; `line` scales
204
+ * every outline. The palette's `free` goes on lines over transparent pixels: over a ground already painted they are ink.
205
+ */
193
206
  export declare function draw(ctx: Ctx, icon: Icon, frame: number, palette?: Partial<Palette>, line?: number): void;
194
207
  /** Every accent turned `deg` around the hue wheel, each keeping its own lightness and strength. */
195
208
  export declare function hue(deg: number, from?: Palette): Palette;
@@ -200,7 +213,8 @@ export declare function mono(color: string, from?: Palette): Palette;
200
213
  /** The --baht-* token each accent reads, so a sticker follows the page's banknote theme and dark mode. */
201
214
  export declare const TOKENS: Record<Accent, string>;
202
215
  /**
203
- * The accents as `el` sees the --baht-* tokens right now, as hex. Unset tokens fall back to BAHT.
216
+ * The accents as `el` sees the --baht-* tokens right now, as hex, and the text colour as `free`. Unset tokens fall
217
+ * back to BAHT. The ink is not read: it outlines fills, which stay light or coloured in dark mode.
204
218
  * Colours are resolved by the browser (var(), color-mix()) and read back through a 1px canvas.
205
219
  */
206
220
  export declare function paletteFromTokens(el: Element): Palette;
package/dist/sticker.js CHANGED
@@ -418,6 +418,38 @@ function drawShape(pen, S, d, trim, pose, width, scale = 1) {
418
418
  drawSlab(pen, { ...S, fill }, d, path, pose, w);
419
419
  fillOutlined(pen, path, w, pen.colour(fill));
420
420
  }
421
+ /**
422
+ * A layer's shapes, back to front. With a `free` colour, lines go down in two passes: ink where something is painted
423
+ * already, `free` where nothing is. Lines in a row share the passes, or the second would find the first behind it
424
+ * and turn to ink where they cross.
425
+ */
426
+ function drawLayer(pen, shapes, free, one) {
427
+ const { ctx } = pen;
428
+ const isLine = (S) => S !== undefined && S.fill === undefined;
429
+ for (let i = 0; i < shapes.length; i++) {
430
+ const S = shapes[i];
431
+ if (!S)
432
+ continue;
433
+ if (free === undefined || !isLine(S)) {
434
+ one(pen, S, i);
435
+ continue;
436
+ }
437
+ const from = i;
438
+ while (isLine(shapes[i + 1]))
439
+ i++;
440
+ const run = shapes.slice(from, i + 1);
441
+ const over = ctx.globalCompositeOperation;
442
+ ctx.globalCompositeOperation = 'source-atop';
443
+ run.forEach((L, j) => {
444
+ one(pen, L, from + j);
445
+ });
446
+ ctx.globalCompositeOperation = 'destination-over';
447
+ run.forEach((L, j) => {
448
+ one({ ...pen, ink: free }, L, from + j);
449
+ });
450
+ ctx.globalCompositeOperation = over;
451
+ }
452
+ }
421
453
  /** Clips to a matte layer's shapes, like an After Effects track matte. */
422
454
  function clipTo(pen, mask, sc) {
423
455
  const region = new Path2D();
@@ -430,7 +462,7 @@ function clipTo(pen, mask, sc) {
430
462
  }
431
463
  function render(ctx, icon, sc, palette, line = 1) {
432
464
  const base = ctx.getTransform();
433
- const colour = (c) => (c.startsWith('#') ? c : palette[c]);
465
+ const colour = (c) => c.startsWith('#') ? c : palette[c];
434
466
  const pen = {
435
467
  ctx,
436
468
  base,
@@ -441,6 +473,8 @@ function render(ctx, icon, sc, palette, line = 1) {
441
473
  dev: Math.sqrt(Math.abs(base.a * base.d - base.b * base.c)) || 1,
442
474
  step: new DOMMatrix(),
443
475
  };
476
+ // an icon that names its ink means it on every line
477
+ const free = icon.ink === undefined && palette.free !== pen.ink ? palette.free : undefined;
444
478
  ctx.save();
445
479
  ctx.miterLimit = 4;
446
480
  for (const { L, pose, ds, trims } of sc.parts) {
@@ -448,8 +482,8 @@ function render(ctx, icon, sc, palette, line = 1) {
448
482
  const mask = L.clip ? sc.byId.get(L.clip) : undefined;
449
483
  if (mask)
450
484
  clipTo(pen, mask, sc);
451
- L.shapes.forEach((S, i) => {
452
- drawShape(pen, S, ds[i] ?? '', trims[i] ?? 1, pose, (icon.line ?? 4) * line, line);
485
+ drawLayer(pen, L.shapes, free, (nib, S, i) => {
486
+ drawShape(nib, S, ds[i] ?? '', trims[i] ?? 1, pose, (icon.line ?? 4) * line, line);
453
487
  });
454
488
  if (mask)
455
489
  ctx.restore();
@@ -464,7 +498,10 @@ function resolve(p) {
464
498
  const key = JSON.stringify(p);
465
499
  return themed.get(key) ?? remember(themed, key, { ...BAHT, ...p }, 200);
466
500
  }
467
- /** Paints frame f of an icon into ctx, whose current transform maps icon units (0..size) to its box; `line` scales every outline. */
501
+ /**
502
+ * Paints frame f of an icon into ctx, whose current transform maps icon units (0..size) to its box; `line` scales
503
+ * every outline. The palette's `free` goes on lines over transparent pixels: over a ground already painted they are ink.
504
+ */
468
505
  export function draw(ctx, icon, frame, palette, line = 1) {
469
506
  render(ctx, icon, scene(icon, frame), resolve(palette), line);
470
507
  }
@@ -569,6 +606,8 @@ export const TOKENS = {
569
606
  ok: '--baht-success',
570
607
  hot: '--baht-error',
571
608
  };
609
+ /** What a line with nothing behind it reads: the text token, or the text colour on a page without the tokens. */
610
+ const FREE = 'var(--baht-color-text, currentColor)';
572
611
  let probing;
573
612
  /** The span and the 1px canvas every token read goes through, made once. */
574
613
  function probeKit() {
@@ -582,26 +621,30 @@ function probeKit() {
582
621
  return probing;
583
622
  }
584
623
  /**
585
- * The accents as `el` sees the --baht-* tokens right now, as hex. Unset tokens fall back to BAHT.
624
+ * The accents as `el` sees the --baht-* tokens right now, as hex, and the text colour as `free`. Unset tokens fall
625
+ * back to BAHT. The ink is not read: it outlines fills, which stay light or coloured in dark mode.
586
626
  * Colours are resolved by the browser (var(), color-mix()) and read back through a 1px canvas.
587
627
  */
588
628
  export function paletteFromTokens(el) {
589
629
  const { probe, ctx } = probeKit();
590
630
  el.appendChild(probe);
591
631
  const out = { ...BAHT };
592
- for (const k of ACCENTS) {
632
+ const read = (value, fallback) => {
593
633
  probe.style.color = '';
594
- probe.style.color = `var(${TOKENS[k]}, ${BAHT[k]})`;
634
+ probe.style.color = value;
595
635
  const css = getComputedStyle(probe).color;
596
636
  if (!ctx || !css)
597
- continue;
637
+ return fallback;
598
638
  ctx.clearRect(0, 0, 1, 1);
599
- ctx.fillStyle = BAHT[k];
639
+ ctx.fillStyle = fallback;
600
640
  ctx.fillStyle = css;
601
641
  ctx.fillRect(0, 0, 1, 1);
602
642
  const [r = 0, g = 0, b = 0] = ctx.getImageData(0, 0, 1, 1).data;
603
- out[k] = `#${[r, g, b].map((v) => v.toString(16).padStart(2, '0')).join('')}`;
604
- }
643
+ return `#${[r, g, b].map((v) => v.toString(16).padStart(2, '0')).join('')}`;
644
+ };
645
+ for (const k of ACCENTS)
646
+ out[k] = read(`var(${TOKENS[k]}, ${BAHT[k]})`, BAHT[k]);
647
+ out.free = read(FREE, BAHT.ink);
605
648
  probe.remove();
606
649
  return out;
607
650
  }
@@ -866,7 +909,8 @@ function reread(l) {
866
909
  if (typeof from !== 'function')
867
910
  return;
868
911
  const next = resolve(from());
869
- const slots = Object.keys(next);
912
+ // both: `free` may be in one and not the other
913
+ const slots = Object.keys({ ...l.pal, ...next });
870
914
  if (next === l.pal || slots.every((k) => next[k] === l.pal[k]))
871
915
  return;
872
916
  l.pal = next;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The nonce a `<style>` an element of this package adds carries, for a page whose CSP `style-src`
3
+ * has no `'unsafe-inline'`: the `nonce` of the element or of the nearest ancestor that has one (a
4
+ * sticker inside a `<baht-sticker-graph nonce>`), else Lit's page-wide `window.litNonce`.
5
+ */
6
+ export declare function styleNonce(element: HTMLElement): string;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The nonce a `<style>` an element of this package adds carries, for a page whose CSP `style-src`
3
+ * has no `'unsafe-inline'`: the `nonce` of the element or of the nearest ancestor that has one (a
4
+ * sticker inside a `<baht-sticker-graph nonce>`), else Lit's page-wide `window.litNonce`.
5
+ */
6
+ export function styleNonce(element) {
7
+ for (let at = element; at; at = at.parentElement) {
8
+ // a browser hides the attribute once connected (the property keeps it); happy-dom has no property
9
+ if (at.nonce)
10
+ return at.nonce;
11
+ const attribute = at.getAttribute('nonce');
12
+ if (attribute)
13
+ return attribute;
14
+ }
15
+ const page = globalThis.litNonce;
16
+ return typeof page === 'string' ? page : '';
17
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@20baht/stickers",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "description": "Animated isometric slab stickers for bahtui: a <baht-sticker> Lit element that follows the --baht-* tokens and banknote themes, a growing set of illustrations, and the canvas runtime that plays them on After Effects keyframe presets.",
6
6
  "license": "MIT",