@20baht/stickers 0.1.1 → 0.1.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 +8 -1
- package/dist/element.d.ts +6 -2
- package/dist/element.js +19 -6
- package/dist/icons/index.d.ts +4 -1
- package/dist/icons/index.js +7 -1
- package/dist/icons/ticket-search.d.ts +2 -0
- package/dist/icons/ticket-search.js +50 -0
- package/dist/icons/ticket-stamped.d.ts +2 -0
- package/dist/icons/ticket-stamped.js +66 -0
- package/dist/icons/ticket-wallet.d.ts +2 -0
- package/dist/icons/ticket-wallet.js +44 -0
- package/dist/load.d.ts +3 -0
- package/dist/load.js +3 -0
- package/dist/sticker.d.ts +17 -3
- package/dist/sticker.js +56 -12
- package/package.json +1 -1
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.
|
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,7 +19,8 @@ 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.
|
|
24
25
|
*/
|
|
25
26
|
export declare class BahtSticker extends LitElement {
|
|
@@ -70,6 +71,7 @@ export declare class BahtSticker extends LitElement {
|
|
|
70
71
|
offset: number | undefined;
|
|
71
72
|
enter: number | undefined;
|
|
72
73
|
replayOnHover: boolean;
|
|
74
|
+
/** Accessible name; unset is the sticker's name, `''` makes it decorative (hidden from assistive technology). */
|
|
73
75
|
label: string | undefined;
|
|
74
76
|
/** Outline weight as a multiple of the sticker's own; unset is 1. */
|
|
75
77
|
line: number | undefined;
|
|
@@ -86,6 +88,8 @@ export declare class BahtSticker extends LitElement {
|
|
|
86
88
|
connectedCallback(): void;
|
|
87
89
|
disconnectedCallback(): void;
|
|
88
90
|
protected updated(changed: PropertyValues<this>): void;
|
|
91
|
+
/** An image with a name, or, with an empty one, nothing assistive technology reads. */
|
|
92
|
+
private nameCanvas;
|
|
89
93
|
private readonly onPointerEnter;
|
|
90
94
|
/** The theme may have changed: the tokens are read again when the sticker is next painted, not here. */
|
|
91
95
|
private readonly onTheme;
|
package/dist/element.js
CHANGED
|
@@ -29,8 +29,10 @@ function watchTheme(stale) {
|
|
|
29
29
|
attributes: true,
|
|
30
30
|
attributeFilter: ['data-note', 'data-theme', 'data-baht-theme', 'class', 'style'],
|
|
31
31
|
});
|
|
32
|
-
|
|
33
|
-
schemeWatch
|
|
32
|
+
// jsdom has no matchMedia
|
|
33
|
+
schemeWatch =
|
|
34
|
+
typeof matchMedia === 'undefined' ? undefined : matchMedia('(prefers-color-scheme: dark)');
|
|
35
|
+
schemeWatch?.addEventListener('change', onTheme);
|
|
34
36
|
}
|
|
35
37
|
/** Taken down again when the last sticker leaves the page. */
|
|
36
38
|
function unwatchTheme(stale) {
|
|
@@ -48,7 +50,7 @@ function unwatchTheme(stale) {
|
|
|
48
50
|
* Give it a registered `name` (`<baht-sticker name="piggy-bank">` after `import '@20baht/stickers/all'` or
|
|
49
51
|
* `registerSticker(piggyBank)`), or an `icon` object as a property, which wins over `name`.
|
|
50
52
|
*
|
|
51
|
-
* Without `palette` it reads the --baht-* tokens (primary, neutral, success, error, amber) where it sits and
|
|
53
|
+
* Without `palette` it reads the --baht-* tokens (primary, neutral, success, error, amber, text) where it sits and
|
|
52
54
|
* re-reads them when the root's `data-note`, `data-theme`, `data-baht-theme`, `class` or `style`, or the colour scheme, changes,
|
|
53
55
|
* so it follows the banknote theme and dark mode. It reads them when it is on screen: a sticker out of view waits
|
|
54
56
|
* until it scrolls in, and one whose colours come back the same does not repaint.
|
|
@@ -60,7 +62,8 @@ function unwatchTheme(stale) {
|
|
|
60
62
|
* @attr offset - Frames ahead of the page clock, to put neighbours out of phase.
|
|
61
63
|
* @attr enter - Seconds after first shown to pop in on the bounce entrance; unset skips the entrance.
|
|
62
64
|
* @attr replay-on-hover - Replay from frame 0 when the pointer enters.
|
|
63
|
-
* @attr label - Accessible name; the sticker's name by default.
|
|
65
|
+
* @attr label - Accessible name; the sticker's name by default. Empty (`label=""`) makes the sticker decorative:
|
|
66
|
+
* assistive technology skips it, for one beside words that already say the same.
|
|
64
67
|
* @attr line - Outline weight as a multiple of the sticker's own: `0.6` thinner, `1.5` bolder; 1 by default.
|
|
65
68
|
*/
|
|
66
69
|
export class BahtSticker extends LitElement {
|
|
@@ -123,7 +126,6 @@ export class BahtSticker extends LitElement {
|
|
|
123
126
|
this.canvas ??= document.createElement('canvas');
|
|
124
127
|
if (!this.canvas.isConnected)
|
|
125
128
|
this.append(this.canvas);
|
|
126
|
-
this.canvas.setAttribute('role', 'img');
|
|
127
129
|
this.addEventListener('pointerenter', this.onPointerEnter);
|
|
128
130
|
watchTheme(this.onTheme);
|
|
129
131
|
// the first connect starts from updated(); a reconnect has no property change to start it
|
|
@@ -140,12 +142,23 @@ export class BahtSticker extends LitElement {
|
|
|
140
142
|
}
|
|
141
143
|
updated(changed) {
|
|
142
144
|
const icon = this.resolvedIcon;
|
|
143
|
-
this.
|
|
145
|
+
this.nameCanvas(this.label ?? icon?.name ?? this.name ?? 'sticker');
|
|
144
146
|
if (icon !== this.playing || !this.player)
|
|
145
147
|
this.start();
|
|
146
148
|
else if (changed.size)
|
|
147
149
|
this.player.set(this.options());
|
|
148
150
|
}
|
|
151
|
+
/** An image with a name, or, with an empty one, nothing assistive technology reads. */
|
|
152
|
+
nameCanvas(name) {
|
|
153
|
+
const attrs = { role: 'img', 'aria-label': name, 'aria-hidden': 'true' };
|
|
154
|
+
const on = name === '' ? ['aria-hidden'] : ['role', 'aria-label'];
|
|
155
|
+
for (const [attr, value] of Object.entries(attrs)) {
|
|
156
|
+
if (on.includes(attr))
|
|
157
|
+
this.canvas?.setAttribute(attr, value);
|
|
158
|
+
else
|
|
159
|
+
this.canvas?.removeAttribute(attr);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
149
162
|
options() {
|
|
150
163
|
return {
|
|
151
164
|
palette: this.palette ?? this.readTokens,
|
package/dist/icons/index.d.ts
CHANGED
|
@@ -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[];
|
package/dist/icons/index.js
CHANGED
|
@@ -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,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,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,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
|
-
/**
|
|
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
|
|
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) =>
|
|
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
|
|
452
|
-
drawShape(
|
|
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
|
-
/**
|
|
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
|
|
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
|
-
|
|
632
|
+
const read = (value, fallback) => {
|
|
593
633
|
probe.style.color = '';
|
|
594
|
-
probe.style.color =
|
|
634
|
+
probe.style.color = value;
|
|
595
635
|
const css = getComputedStyle(probe).color;
|
|
596
636
|
if (!ctx || !css)
|
|
597
|
-
|
|
637
|
+
return fallback;
|
|
598
638
|
ctx.clearRect(0, 0, 1, 1);
|
|
599
|
-
ctx.fillStyle =
|
|
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
|
-
|
|
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
|
-
|
|
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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@20baht/stickers",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
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",
|