@pokela/components 2.6.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ExplodedView.d.ts CHANGED
@@ -10,6 +10,12 @@ import { type ReactNode } from 'react';
10
10
  * - Osoitin kääntää pinoa ja erkanee kerroksia.
11
11
  * - Elementit, joilla on sama `data-kohde`, syttyvät yhdessä: osoitin
12
12
  * komponentin päällä näyttää sen jokaisessa kerroksessa.
13
+ * - `data-token="ink"` (väri `--ink`) tai `data-token="display-l"`
14
+ * (tyyppi `--text-display-l`) merkitsee tokenin. Osoitin tokenin päällä
15
+ * sytyttää muiden kerrosten elementit, joiden laskettu tyyli käyttää
16
+ * sen arvoa, ja osoitin elementin päällä sytyttää sen tokenit. Käyttöä
17
+ * ei merkitä käsin: se luetaan selaimen lasketusta tyylistä, joten se
18
+ * pysyy totena kun tyylit muuttuvat.
13
19
  * - Klikkaus nostaa kerroksen kerrallaan esiin ja lopuksi palauttaa
14
20
  * koko pinon.
15
21
  * - Tilassa `auki` vieritys kokoaa kerrokset yhdeksi suoraksi
package/ExplodedView.js CHANGED
@@ -118,14 +118,57 @@ export default function ExplodedView({ layers, label, tila = 'auki', className,
118
118
  }
119
119
  liiku();
120
120
  };
121
+ /* Tokenin arvo selaimen laskemana: väri rgb-muodossa, tyyppi pikseleinä. */
122
+ function tokeninArvo(nimi) {
123
+ const apu = document.createElement('i');
124
+ apu.style.color = `var(--${nimi})`;
125
+ apu.style.fontSize = `var(--text-${nimi})`;
126
+ hero.append(apu);
127
+ const s = getComputedStyle(apu);
128
+ const tyyppi = getComputedStyle(hero).getPropertyValue(`--text-${nimi}`).trim() !== '';
129
+ const arvo = tyyppi ? { tyyppi: s.fontSize } : { vari: s.color };
130
+ apu.remove();
131
+ return arvo;
132
+ }
133
+ /* Käyttääkö elementti arvoa itse: teksti omana tekstinään, väri
134
+ myös taustana tai viivana. */
135
+ function kayttaa(x, arvo) {
136
+ const s = getComputedStyle(x);
137
+ const teksti = [...x.childNodes].some((c) => c.nodeType === 3 && c.textContent?.trim());
138
+ if (arvo.tyyppi)
139
+ return teksti && s.fontSize === arvo.tyyppi;
140
+ return ((teksti && s.color === arvo.vari) ||
141
+ s.backgroundColor === arvo.vari ||
142
+ (parseFloat(s.borderTopWidth) > 0 && s.borderTopColor === arvo.vari) ||
143
+ (parseFloat(s.borderBottomWidth) > 0 && s.borderBottomColor === arvo.vari));
144
+ }
145
+ const sammuta = () => el.querySelectorAll('.exploded--valaistu').forEach((x) => x.classList.remove('exploded--valaistu'));
121
146
  const valaise = (e) => {
122
- el.querySelectorAll('.exploded--valaistu').forEach((x) => x.classList.remove('exploded--valaistu'));
123
- const k = e.target.closest('[data-kohde]');
124
- if (!k)
147
+ sammuta();
148
+ const kohde = e.target;
149
+ const token = kohde.closest('[data-token]');
150
+ const tokenit = [...el.querySelectorAll('[data-token]')];
151
+ if (token) {
152
+ /* Token: sen käyttäjät muissa kerroksissa. */
153
+ const arvo = tokeninArvo(token.dataset.token);
154
+ const oma = token.closest('.exploded__layer');
155
+ token.classList.add('exploded--valaistu');
156
+ el.querySelectorAll('.exploded__plate, .exploded__plate *').forEach((x) => {
157
+ if (x.closest('.exploded__layer') !== oma && !x.closest('[data-token]') && kayttaa(x, arvo))
158
+ x.classList.add('exploded--valaistu');
159
+ });
125
160
  return;
126
- el.querySelectorAll(`[data-kohde="${k.dataset.kohde}"]`).forEach((x) => x.classList.add('exploded--valaistu'));
161
+ }
162
+ /* Komponentti kaikissa kerroksissa ja elementin omat tokenit. */
163
+ const k = kohde.closest('[data-kohde]');
164
+ if (k)
165
+ el.querySelectorAll(`[data-kohde="${k.dataset.kohde}"]`).forEach((x) => x.classList.add('exploded--valaistu'));
166
+ if (kohde.closest('.exploded__plate'))
167
+ tokenit.forEach((t) => {
168
+ if (kayttaa(kohde, tokeninArvo(t.dataset.token)))
169
+ t.classList.add('exploded--valaistu');
170
+ });
127
171
  };
128
- const sammuta = () => el.querySelectorAll('.exploded--valaistu').forEach((x) => x.classList.remove('exploded--valaistu'));
129
172
  /* Vieritys kokoaa, kun kuva poistuu yläreunasta. */
130
173
  const vieritys = () => {
131
174
  const r = hero.getBoundingClientRect();
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @pokela/components
2
2
 
3
- React-komponentit: **Pokela Design System**, versio 2.6.0.
3
+ React-komponentit: **Pokela Design System**, versio 2.7.0.
4
4
 
5
5
  > Generoitu hakemistosta `components/` — samoista tiedostoista joita sivusto
6
6
  > ajaa. Älä muokkaa käsin: muutokset tehdään lähteeseen ja paketti
@@ -50,6 +50,10 @@ the total duration.
50
50
  `ExplodedView` shows layers as plates in 3D space: how a finished surface is
51
51
  built from its parts. Each layer is real markup, not an image. Give elements
52
52
  the same `data-kohde` in several layers and they light up together on hover.
53
+ Mark a token with `data-token` (`"ink"` for `--ink`, `"display-l"` for
54
+ `--text-display-l`): hovering it lights every element in the other layers
55
+ whose computed style uses that value, and hovering an element lights its
56
+ tokens. Usage is read from computed styles, never marked by hand.
53
57
  `tila="koottu"` starts with the layers collapsed into one surface. Put no
54
58
  links or buttons inside the layers; the whole view is one image to a screen
55
59
  reader, described by `label`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pokela/components",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "description": "React-komponentit: Pokela Design System. Generoitu tiedostoista components/, ei käsin ylläpidetty.",
5
5
  "license": "MIT",
6
6
  "author": "Veli-Matti Pokela",
@@ -27,7 +27,7 @@
27
27
  "LICENSE"
28
28
  ],
29
29
  "dependencies": {
30
- "@pokela/tokens": "^2.6.0"
30
+ "@pokela/tokens": "^2.7.0"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "react": ">=18"
@@ -62,13 +62,22 @@
62
62
  transition: opacity var(--dur-slow) var(--ease-standard);
63
63
  }
64
64
 
65
+ /* Lähde on taustapinnalla, ei paperilla: ink-faint jää siinä alle 4.5:1. */
66
+ .exploded__name .meta--s { color: var(--ink-muted); }
67
+
65
68
  .exploded__stack--kohdistus .exploded__layer:not(.exploded__layer--aktiivinen) .exploded__plate,
66
69
  .exploded__stack--kohdistus .exploded__layer:not(.exploded__layer--aktiivinen) .exploded__name { opacity: 0.35; }
70
+ /* Himmennetty levy ei ota osoitinta: nostetun levyn peitetyt osat,
71
+ kuten viuhkassa piiloon jäävät tokenit, saa osoitettua. */
72
+ .exploded__stack--kohdistus .exploded__layer:not(.exploded__layer--aktiivinen) { pointer-events: none; }
67
73
 
68
- /* Sama kohde kaikissa kerroksissa: katkoviiva muuttuu yhtenäiseksi. */
69
- .exploded [data-kohde] {
70
- outline: var(--hairline) dashed transparent;
74
+ /* Sama kohde tai token kaikissa kerroksissa saa yhtenäisen viivan.
75
+ Korostuksen on oltava pohjaa spesifisempi: kun se ei ollut,
76
+ luokka vaihtui mutta viiva jäi läpinäkyväksi. */
77
+ .exploded__plate,
78
+ .exploded__plate * {
79
+ outline: var(--hairline) solid transparent;
71
80
  outline-offset: var(--space-4);
72
- transition: outline-color var(--dur-fast) var(--ease-standard);
73
81
  }
74
- .exploded--valaistu { outline: var(--hairline-strong) solid var(--ink); }
82
+ .exploded__plate * { transition: outline-color var(--dur-fast) var(--ease-standard); }
83
+ .exploded .exploded--valaistu { outline: var(--hairline-strong) solid var(--ink); }