@whatsaaaa/design-system 0.3.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,7 +12,7 @@ The package is [`@whatsaaaa/design-system`](https://www.npmjs.com/package/@whats
12
12
  | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- |
13
13
  | Identity | The ghost in every cut, the wordmark, six poses, a sprite per project, favicons, README headers, social cards and a profile banner. All generated | `src/identity/ghost.ts`, `identity/` |
14
14
  | Tokens | Rosé Pine main for dark and Dawn for light, mapped to roles, with type, space, radii and motion | `tokens/` |
15
- | Styles | Prose, code blocks, tables, lists, callouts, and the terminal frame: tab bar, prompts, status line | `src/css/` |
15
+ | Styles | Prose, code blocks, tables, lists, callouts, a segmented control, terms and values, and the terminal frame: tab bar, prompts, status line | `src/css/` |
16
16
  | The ghost as an element | `<ws-ghost>`, with the easter egg | `src/ghost/` |
17
17
  | Docs theme | A VitePress theme on top of VitePress's default theme | `src/vitepress/`, `src/vitepress-config/` |
18
18
  | Style guide | A site that shows all of it with real content, in dark and light, and offers the assets for download | `styleguide/` |
@@ -65,7 +65,7 @@ CI runs on every pull request:
65
65
  - the unit tests, with the contrast of every role pair in both themes,
66
66
  - that `assets/` is what the sources produce,
67
67
  - that the package and the style guide build,
68
- - the browser tests: no page overflows sideways at phone, tablet and desktop width in either theme, no page logs an error when it loads, the easter egg works with the mouse, the keyboard and reduced motion, the keys of the status line work and their switch turns them off, the path of the status line gives way at every width from 320 px and the theme button switches the theme, an element for one theme shows only in it, the browser's theme-color follows the theme, a control that takes the focus is not left under the status line and no bar or corner of the window cuts off its focus ring, the first tab starts on the border of the sidebar, both fonts draw Serbian Latin, and the pages of the style guide look like their stored screenshots.
68
+ - the browser tests: no page overflows sideways at phone, tablet and desktop width in either theme, no page logs an error when it loads, the easter egg works with the mouse, the keyboard and reduced motion, the keys of the status line work and their switch turns them off, the path of the status line gives way at every width from 320 px and the theme button switches the theme, a `dark` or `light` class chooses the theme as `data-theme` does, an element for one theme shows only in it, the browser's theme-color follows the theme, a control that takes the focus is not left under the status line and no bar or corner of the window cuts off its focus ring, the first tab starts on the border of the sidebar, the pieces of a form fit every width from 320 px (a segmented control works with the keyboard, stands out at 3:1 and takes the selection colors in forced colors, amounts line up at the right in figures of one width, a number field has no spin buttons and its arrow keys step it, wrapped code hangs and stays inside its block, a long email breaks after its @, and the check icon and the ghost files draw), both fonts draw Serbian Latin, and the pages of the style guide look like their stored screenshots.
69
69
 
70
70
  The screenshots are in `tests/browser/__screenshots__/` and are taken on Linux, in the Playwright container, so they are the same on every machine. After a change that is meant to be seen, update them:
71
71
 
@@ -122,6 +122,18 @@
122
122
  "height": 64,
123
123
  "use": "The ghost in its lost pose, for light backgrounds."
124
124
  },
125
+ {
126
+ "file": "ghost-on-dark.svg",
127
+ "width": 20,
128
+ "height": 24,
129
+ "use": "The ghost without the margin of its grid, for dark backgrounds: in a link, on a line of text, against an edge."
130
+ },
131
+ {
132
+ "file": "ghost-on-light.svg",
133
+ "width": 20,
134
+ "height": 24,
135
+ "use": "The ghost without the margin of its grid, for light backgrounds: in a link, on a line of text, against an edge."
136
+ },
125
137
  {
126
138
  "file": "favicon.svg",
127
139
  "width": 64,
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 24" width="20" height="24" role="img" aria-label="whatsaaaa ghost"><title>whatsaaaa ghost</title><g shape-rendering="crispEdges"><path d="M4 0h12v2h-12zM2 2h16v2h-16zM0 4h20v2h-20zM0 6h4v2h-4zM8 6h4v2h-4zM16 6h4v2h-4zM0 8h4v2h-4zM8 8h4v2h-4zM16 8h4v2h-4zM0 10h20v2h-20zM0 12h4v2h-4zM6 12h2v2h-2zM12 12h2v2h-2zM16 12h4v2h-4zM0 14h6v2h-6zM14 14h6v2h-6zM0 16h8v2h-8zM12 16h8v2h-8zM0 18h20v2h-20zM0 20h8v2h-8zM12 20h8v2h-8zM2 22h4v2h-4zM14 22h4v2h-4z" fill="#e0def4"/><path d="M8 14h4v2h-4zM8 16h4v2h-4z" fill="#eb6f92"/></g></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 24" width="20" height="24" role="img" aria-label="whatsaaaa ghost"><title>whatsaaaa ghost</title><g shape-rendering="crispEdges"><path d="M4 0h12v2h-12zM2 2h16v2h-16zM0 4h20v2h-20zM0 6h4v2h-4zM8 6h4v2h-4zM16 6h4v2h-4zM0 8h4v2h-4zM8 8h4v2h-4zM16 8h4v2h-4zM0 10h20v2h-20zM0 12h4v2h-4zM6 12h2v2h-2zM12 12h2v2h-2zM16 12h4v2h-4zM0 14h6v2h-6zM14 14h6v2h-6zM0 16h8v2h-8zM12 16h8v2h-8zM0 18h20v2h-20zM0 20h8v2h-8zM12 20h8v2h-8zM2 22h4v2h-4zM14 22h4v2h-4z" fill="#575279"/><path d="M8 14h4v2h-4zM8 16h4v2h-4z" fill="#b4637a"/></g></svg>
package/dist/css/base.css CHANGED
@@ -38,6 +38,20 @@ code, kbd, samp, pre {
38
38
  font-variant-ligatures: none;
39
39
  }
40
40
 
41
+ input[type="number"] {
42
+ appearance: textfield;
43
+ }
44
+
45
+ input[type="number"]::-webkit-inner-spin-button {
46
+ appearance: none;
47
+ margin: 0;
48
+ }
49
+
50
+ input[type="number"]::-webkit-outer-spin-button {
51
+ appearance: none;
52
+ margin: 0;
53
+ }
54
+
41
55
  :focus-visible {
42
56
  border-radius: var(--ws-radius-sm);
43
57
  outline: var(--ws-border-width-medium) solid var(--ws-color-interactive);
package/dist/css/code.css CHANGED
@@ -34,6 +34,24 @@
34
34
  overflow-x: auto;
35
35
  }
36
36
 
37
+ .ws-code--wrap {
38
+ --ws-code-hang: 0;
39
+ }
40
+
41
+ .ws-code--wrap > pre {
42
+ white-space: pre-wrap;
43
+ overflow-wrap: anywhere;
44
+ overflow-x: visible;
45
+ }
46
+
47
+ .ws-code--wrap .line {
48
+ box-sizing: border-box;
49
+ width: 100%;
50
+ text-indent: calc(var(--ws-code-hang) * -1ch);
51
+ padding-inline-start: calc(var(--ws-code-hang) * 1ch);
52
+ display: inline-block;
53
+ }
54
+
37
55
  .ws-code code {
38
56
  font: inherit;
39
57
  }
@@ -22,6 +22,33 @@ ws-ghost {
22
22
  display: block;
23
23
  }
24
24
 
25
+ @media (width < 64rem) {
26
+ ws-ghost[compact-px="1"] .ws-ghost__sprite {
27
+ width: 10px;
28
+ height: 12px;
29
+ }
30
+
31
+ ws-ghost[compact-px="2"] .ws-ghost__sprite {
32
+ width: 20px;
33
+ height: 24px;
34
+ }
35
+
36
+ ws-ghost[compact-px="3"] .ws-ghost__sprite {
37
+ width: 30px;
38
+ height: 36px;
39
+ }
40
+
41
+ ws-ghost[compact-px="4"] .ws-ghost__sprite {
42
+ width: 40px;
43
+ height: 48px;
44
+ }
45
+
46
+ ws-ghost[compact-px="5"] .ws-ghost__sprite {
47
+ width: 50px;
48
+ height: 60px;
49
+ }
50
+ }
51
+
25
52
  .ws-ghost__body {
26
53
  fill: currentColor;
27
54
  }
@@ -3,6 +3,7 @@
3
3
  --ws-icon-tip: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 1.8a4.3 4.3 0 0 0-2.3 7.9v1.5h4.6V9.7A4.3 4.3 0 0 0 8 1.8ZM6.4 13.6h3.2'/%3E%3C/svg%3E");
4
4
  --ws-icon-warning: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 2.2 14.2 13H1.8ZM8 6.6v3M8 11.3v.2'/%3E%3C/svg%3E");
5
5
  --ws-icon-danger: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5.4 1.8h5.2l3.6 3.6v5.2l-3.6 3.6H5.4l-3.6-3.6V5.4ZM8 5v3.6M8 10.9v.2'/%3E%3C/svg%3E");
6
+ --ws-icon-check: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 8.5 6.5 12 13 4.5'/%3E%3C/svg%3E");
6
7
  --ws-icon-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 14' fill='none' stroke='%23000' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 2 8 7 2 12'/%3E%3C/svg%3E");
7
8
  --ws-icon-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='%23000' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 9 9 3M4.25 3H9v4.75'/%3E%3C/svg%3E");
8
9
  }
@@ -0,0 +1,57 @@
1
+ .ws-pairs {
2
+ column-gap: var(--ws-space-16);
3
+ border-bottom: var(--ws-border-width-thin) dashed var(--ws-color-border);
4
+ grid-template-columns: fit-content(40%) minmax(0, 1fr);
5
+ margin: 0;
6
+ display: grid;
7
+ }
8
+
9
+ .ws-pairs > div {
10
+ grid-column: 1 / -1;
11
+ grid-template-columns: inherit;
12
+ column-gap: inherit;
13
+ padding-block: var(--ws-space-8);
14
+ border-top: var(--ws-border-width-thin) dashed var(--ws-color-border);
15
+ align-items: baseline;
16
+ display: grid;
17
+ }
18
+
19
+ @supports (grid-template-columns: subgrid) {
20
+ .ws-pairs > div {
21
+ grid-template-columns: subgrid;
22
+ }
23
+ }
24
+
25
+ .ws-pairs dt {
26
+ color: var(--ws-color-text-secondary);
27
+ font: var(--ws-text-label);
28
+ overflow-wrap: anywhere;
29
+ }
30
+
31
+ .ws-pairs dd {
32
+ color: var(--ws-color-text);
33
+ font-family: var(--ws-font-family-sans);
34
+ font-size: var(--ws-font-size-16);
35
+ line-height: var(--ws-font-line-height-normal);
36
+ overflow-wrap: anywhere;
37
+ margin: 0;
38
+ }
39
+
40
+ .ws-pairs--amounts {
41
+ grid-template-columns: minmax(0, 1fr) auto;
42
+ }
43
+
44
+ .ws-pairs--amounts dd {
45
+ font-variant-numeric: tabular-nums;
46
+ text-align: end;
47
+ white-space: nowrap;
48
+ }
49
+
50
+ .ws-pairs > .ws-pairs__total {
51
+ border-top-style: solid;
52
+ }
53
+
54
+ .ws-pairs__total :is(dt, dd) {
55
+ color: var(--ws-color-text);
56
+ font-weight: var(--ws-font-weight-semibold);
57
+ }
@@ -0,0 +1,71 @@
1
+ .ws-segmented {
2
+ max-width: 100%;
3
+ display: inline-flex;
4
+ }
5
+
6
+ .ws-segmented > button {
7
+ min-width: 0;
8
+ min-height: var(--ws-size-control);
9
+ padding: 0 var(--ws-space-16);
10
+ border: var(--ws-border-width-thin) solid var(--ws-color-field-border);
11
+ color: var(--ws-color-text-secondary);
12
+ font: var(--ws-text-label);
13
+ cursor: pointer;
14
+ background: none;
15
+ border-radius: 0;
16
+ margin: 0;
17
+ position: relative;
18
+ }
19
+
20
+ .ws-segmented > button:first-child {
21
+ border-start-start-radius: var(--ws-radius-md);
22
+ border-end-start-radius: var(--ws-radius-md);
23
+ }
24
+
25
+ .ws-segmented > button:last-child {
26
+ border-start-end-radius: var(--ws-radius-md);
27
+ border-end-end-radius: var(--ws-radius-md);
28
+ }
29
+
30
+ .ws-segmented > button + button {
31
+ margin-inline-start: calc(-1 * var(--ws-border-width-thin));
32
+ }
33
+
34
+ .ws-segmented > button:hover {
35
+ z-index: 1;
36
+ border-color: var(--ws-color-text-secondary);
37
+ background: var(--ws-color-raised);
38
+ color: var(--ws-color-text);
39
+ }
40
+
41
+ .ws-segmented > button[aria-pressed="true"] {
42
+ z-index: 2;
43
+ border-color: var(--ws-color-interactive);
44
+ background: var(--ws-color-raised);
45
+ box-shadow: inset 0 0 0 var(--ws-border-width-thin) var(--ws-color-interactive);
46
+ color: var(--ws-color-text);
47
+ cursor: default;
48
+ }
49
+
50
+ .ws-segmented > button:focus-visible {
51
+ z-index: 3;
52
+ }
53
+
54
+ .ws-segmented > button:disabled {
55
+ z-index: 0;
56
+ border-color: var(--ws-color-text-faint);
57
+ color: var(--ws-color-text-faint);
58
+ cursor: not-allowed;
59
+ background: none;
60
+ }
61
+
62
+ @media (forced-colors: active) {
63
+ .ws-segmented > button[aria-pressed="true"] {
64
+ box-shadow: none;
65
+ color: highlighttext;
66
+ forced-color-adjust: none;
67
+ background: highlight;
68
+ border-color: highlight;
69
+ outline-color: highlight;
70
+ }
71
+ }
@@ -1,19 +1,15 @@
1
- :is(.ws-theme-dark, .ws-status-line__item--dark):where([data-theme="light"], [data-theme="light"] *):not([data-theme="light"] [data-theme="dark"], [data-theme="light"] [data-theme="dark"] *), :is(.ws-theme-dark, .ws-status-line__item--dark):where([data-theme="light"] [data-theme="dark"] [data-theme="light"], [data-theme="light"] [data-theme="dark"] [data-theme="light"] *):not([data-theme="light"] [data-theme="dark"] [data-theme="light"] [data-theme="dark"], [data-theme="light"] [data-theme="dark"] [data-theme="light"] [data-theme="dark"] *) {
2
- display: none !important;
3
- }
4
-
5
- :is(.ws-theme-light, .ws-status-line__item--light):where([data-theme="dark"], [data-theme="dark"] *):not([data-theme="dark"] [data-theme="light"], [data-theme="dark"] [data-theme="light"] *), :is(.ws-theme-light, .ws-status-line__item--light):where([data-theme="dark"] [data-theme="light"] [data-theme="dark"], [data-theme="dark"] [data-theme="light"] [data-theme="dark"] *):not([data-theme="dark"] [data-theme="light"] [data-theme="dark"] [data-theme="light"], [data-theme="dark"] [data-theme="light"] [data-theme="dark"] [data-theme="light"] *) {
1
+ :is(.ws-theme-dark, .ws-status-line__item--dark):where(:is([data-theme="light"], .light:where(:not([data-theme], .dark))), :is([data-theme="light"], .light:where(:not([data-theme], .dark))) *):not(:is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))), :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) *), :is(.ws-theme-dark, .ws-status-line__item--dark):where(:is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))), :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) *):not(:is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))), :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) *), :is(.ws-theme-light, .ws-status-line__item--light):where(:is([data-theme="dark"], .dark:where(:not([data-theme], .light))), :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) *):not(:is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))), :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) *), :is(.ws-theme-light, .ws-status-line__item--light):where(:is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))), :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) *):not(:is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))), :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) *) {
6
2
  display: none !important;
7
3
  }
8
4
 
9
5
  @media (prefers-color-scheme: light) {
10
- :is(.ws-theme-dark, .ws-status-line__item--dark):not([data-theme], [data-theme] *) {
6
+ :is(.ws-theme-dark, .ws-status-line__item--dark):not([data-theme], .dark:where(:not(.light)), .light:where(:not(.dark)), :is([data-theme], .dark:where(:not(.light)), .light:where(:not(.dark))) *) {
11
7
  display: none !important;
12
8
  }
13
9
  }
14
10
 
15
11
  @media not (prefers-color-scheme: light) {
16
- :is(.ws-theme-light, .ws-status-line__item--light):not([data-theme], [data-theme] *) {
12
+ :is(.ws-theme-light, .ws-status-line__item--light):not([data-theme], .dark:where(:not(.light)), .light:where(:not(.dark)), :is([data-theme], .dark:where(:not(.light)), .light:where(:not(.dark))) *) {
17
13
  display: none !important;
18
14
  }
19
15
  }
@@ -1,19 +1,15 @@
1
- :is(.ws-theme-dark, .ws-status-line__item--dark):where([data-theme="light"], [data-theme="light"] *):not([data-theme="light"] [data-theme="dark"], [data-theme="light"] [data-theme="dark"] *), :is(.ws-theme-dark, .ws-status-line__item--dark):where([data-theme="light"] [data-theme="dark"] [data-theme="light"], [data-theme="light"] [data-theme="dark"] [data-theme="light"] *):not([data-theme="light"] [data-theme="dark"] [data-theme="light"] [data-theme="dark"], [data-theme="light"] [data-theme="dark"] [data-theme="light"] [data-theme="dark"] *) {
2
- display: none !important;
3
- }
4
-
5
- :is(.ws-theme-light, .ws-status-line__item--light):where([data-theme="dark"], [data-theme="dark"] *):not([data-theme="dark"] [data-theme="light"], [data-theme="dark"] [data-theme="light"] *), :is(.ws-theme-light, .ws-status-line__item--light):where([data-theme="dark"] [data-theme="light"] [data-theme="dark"], [data-theme="dark"] [data-theme="light"] [data-theme="dark"] *):not([data-theme="dark"] [data-theme="light"] [data-theme="dark"] [data-theme="light"], [data-theme="dark"] [data-theme="light"] [data-theme="dark"] [data-theme="light"] *) {
1
+ :is(.ws-theme-dark, .ws-status-line__item--dark):where(:is([data-theme="light"], .light:where(:not([data-theme], .dark))), :is([data-theme="light"], .light:where(:not([data-theme], .dark))) *):not(:is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))), :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) *), :is(.ws-theme-dark, .ws-status-line__item--dark):where(:is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))), :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) *):not(:is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))), :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) *), :is(.ws-theme-light, .ws-status-line__item--light):where(:is([data-theme="dark"], .dark:where(:not([data-theme], .light))), :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) *):not(:is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))), :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) *), :is(.ws-theme-light, .ws-status-line__item--light):where(:is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))), :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) *):not(:is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))), :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) :is([data-theme="dark"], .dark:where(:not([data-theme], .light))) :is([data-theme="light"], .light:where(:not([data-theme], .dark))) *) {
6
2
  display: none !important;
7
3
  }
8
4
 
9
5
  @media (prefers-color-scheme: light) {
10
- :is(.ws-theme-dark, .ws-status-line__item--dark):not([data-theme], [data-theme] *) {
6
+ :is(.ws-theme-dark, .ws-status-line__item--dark):not([data-theme], .dark:where(:not(.light)), .light:where(:not(.dark)), :is([data-theme], .dark:where(:not(.light)), .light:where(:not(.dark))) *) {
11
7
  display: none !important;
12
8
  }
13
9
  }
14
10
 
15
11
  @media not (prefers-color-scheme: light) {
16
- :is(.ws-theme-light, .ws-status-line__item--light):not([data-theme], [data-theme] *) {
12
+ :is(.ws-theme-light, .ws-status-line__item--light):not([data-theme], .dark:where(:not(.light)), .light:where(:not(.dark)), :is([data-theme], .dark:where(:not(.light)), .light:where(:not(.dark))) *) {
17
13
  display: none !important;
18
14
  }
19
15
  }
@@ -9,8 +9,8 @@ export declare function lettersThatFit(width: number): number;
9
9
  /** Furthest the tail can move right, in font pixels. */
10
10
  export declare const maxTailShift: (text: string) => number;
11
11
  /**
12
- * A pixel speech bubble with stepped corners, as SVG.
12
+ * A pixel speech bubble with stepped corners, as an SVG element built without markup.
13
13
  * `unit` is the size of one font pixel. The tail points down when the bubble sits above the
14
14
  * speaker and up when it sits below, and `tailShift` moves it right, in font pixels.
15
15
  */
16
- export declare function bubbleSvg(text: string, unit: number, side: BubbleSide, tailShift?: number): string;
16
+ export declare function bubbleElement(text: string, unit: number, side: BubbleSide, tailShift?: number, document?: Document): SVGSVGElement;
@@ -1,4 +1,5 @@
1
1
  import { BUBBLE_ADVANCE, BUBBLE_GLYPHS } from "./glyphs.js";
2
+ import { svgElement } from "./svg.js";
2
3
  /** Height of the bubble's body, and of the tail under or over it, in font pixels. */
3
4
  const BODY = 15;
4
5
  const TAIL = 3;
@@ -15,11 +16,11 @@ export function lettersThatFit(width) {
15
16
  /** Furthest the tail can move right, in font pixels. */
16
17
  export const maxTailShift = (text) => bubbleSize(text).width - 7;
17
18
  /**
18
- * A pixel speech bubble with stepped corners, as SVG.
19
+ * A pixel speech bubble with stepped corners, as an SVG element built without markup.
19
20
  * `unit` is the size of one font pixel. The tail points down when the bubble sits above the
20
21
  * speaker and up when it sits below, and `tailShift` moves it right, in font pixels.
21
22
  */
22
- export function bubbleSvg(text, unit, side, tailShift = 0) {
23
+ export function bubbleElement(text, unit, side, tailShift = 0, document = globalThis.document) {
23
24
  const { width, height } = bubbleSize(text);
24
25
  const top = side === 'below' ? TAIL : 0;
25
26
  // three steps, narrowing toward the speaker
@@ -36,15 +37,22 @@ export function bubbleSvg(text, unit, side, tailShift = 0) {
36
37
  ];
37
38
  const shape = `M1 ${top}h${width - 2}v1h1v${BODY - 2}h-1v1h${2 - width}v-1h-1v${2 - BODY}h1z` +
38
39
  steps.map(([x, y, run]) => `M${x + tailShift} ${y}h${run}v1h${-run}z`).join('');
39
- const letters = [...text]
40
- .map((char, index) => {
40
+ const letters = svgElement(document, 'g', { class: 'ws-ghost__bubble-text' });
41
+ letters.append(...[...text].map((char, index) => {
41
42
  const glyph = BUBBLE_GLYPHS[char];
42
43
  if (!glyph)
43
44
  throw new Error(`The speech bubble has no glyph for "${char}"`);
44
- return `<path d="${glyph}" transform="translate(${PADDING + index * BUBBLE_ADVANCE} ${top + 11})"/>`;
45
- })
46
- .join('');
47
- return (`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}" width="${width * unit}" height="${height * unit}" shape-rendering="crispEdges">` +
48
- `<path class="ws-ghost__bubble-shape" d="${shape}"/>` +
49
- `<g class="ws-ghost__bubble-text">${letters}</g></svg>`);
45
+ return svgElement(document, 'path', {
46
+ d: glyph,
47
+ transform: `translate(${PADDING + index * BUBBLE_ADVANCE} ${top + 11})`,
48
+ });
49
+ }));
50
+ const svg = svgElement(document, 'svg', {
51
+ viewBox: `0 0 ${width} ${height}`,
52
+ width: String(width * unit),
53
+ height: String(height * unit),
54
+ 'shape-rendering': 'crispEdges',
55
+ });
56
+ svg.append(svgElement(document, 'path', { class: 'ws-ghost__bubble-shape', d: shape }), letters);
57
+ return svg;
50
58
  }
@@ -3,7 +3,8 @@
3
3
  * the easter egg. Press the ghost three times in a row and it shouts the handle in a speech
4
4
  * bubble. Every further press holds the a for one letter longer.
5
5
  *
6
- * Everything here is safe to import on a server. Only `defineGhost()` needs a browser.
6
+ * Everything here is safe to import on a server. Only `defineGhost()` needs a browser, and
7
+ * `ghostElement()` a document.
7
8
  */
8
9
  import { type GhostPose } from '../identity/ghost.ts';
9
10
  export type { GhostPose } from '../identity/ghost.ts';
@@ -31,7 +32,12 @@ export interface GhostSvgOptions {
31
32
  * The free ghost as inline SVG, without its margin, so it sits in a line of text.
32
33
  * The body takes the text color and the tongue the brand color (see css/ghost.css).
33
34
  */
34
- export declare function ghostSvg({ px, pose }?: GhostSvgOptions): string;
35
+ export declare function ghostSvg(options?: GhostSvgOptions): string;
36
+ /**
37
+ * The same ghost as `ghostSvg()`, as an element built without markup, for a script that adds
38
+ * it to a page where setting `innerHTML` is not wanted or not allowed.
39
+ */
40
+ export declare function ghostElement(options?: GhostSvgOptions, document?: Document): SVGSVGElement;
35
41
  export interface GhostMarkupOptions {
36
42
  px?: number;
37
43
  }
@@ -3,11 +3,13 @@
3
3
  * the easter egg. Press the ghost three times in a row and it shouts the handle in a speech
4
4
  * bubble. Every further press holds the a for one letter longer.
5
5
  *
6
- * Everything here is safe to import on a server. Only `defineGhost()` needs a browser.
6
+ * Everything here is safe to import on a server. Only `defineGhost()` needs a browser, and
7
+ * `ghostElement()` a document.
7
8
  */
8
9
  import { GHOST_POSES } from "../identity/ghost.js";
9
10
  import { spriteBounds, spritePaths } from "../identity/sprite.js";
10
- import { bubbleSize, bubbleSvg, lettersThatFit, maxTailShift } from "./bubble.js";
11
+ import { bubbleElement, bubbleSize, lettersThatFit, maxTailShift, } from "./bubble.js";
12
+ import { SVG, svgElement } from "./svg.js";
11
13
  /** The pixels the ghost occupies in its 16 x 16 grid. Every pose has the same outline. */
12
14
  const BOUNDS = spriteBounds(GHOST_POSES.idle);
13
15
  /** The ghost is this many sprite pixels wide and tall. */
@@ -25,21 +27,53 @@ export const FIRST_SHOUT = 4;
25
27
  export const LONGEST_SHOUT = 16;
26
28
  /** The text of a shout with `count` a's. */
27
29
  export const shoutText = (count) => `whats${'a'.repeat(count)}!`;
30
+ /** The attributes of the ghost's `<svg>`, and its two paths, for the markup and the element. */
31
+ function sprite({ px = 2, pose = 'idle' }) {
32
+ const { body, love } = spritePaths(GHOST_POSES[pose]);
33
+ return {
34
+ attributes: {
35
+ class: 'ws-ghost__sprite',
36
+ viewBox: `${BOUNDS.x} ${BOUNDS.y} ${BOUNDS.width} ${BOUNDS.height}`,
37
+ width: String(BOUNDS.width * px),
38
+ height: String(BOUNDS.height * px),
39
+ 'shape-rendering': 'crispEdges',
40
+ 'aria-hidden': 'true',
41
+ },
42
+ paths: [
43
+ ['ws-ghost__body', body],
44
+ ['ws-ghost__tongue', love],
45
+ ],
46
+ };
47
+ }
28
48
  /**
29
49
  * The free ghost as inline SVG, without its margin, so it sits in a line of text.
30
50
  * The body takes the text color and the tongue the brand color (see css/ghost.css).
31
51
  */
32
- export function ghostSvg({ px = 2, pose = 'idle' } = {}) {
33
- const { body, love } = spritePaths(GHOST_POSES[pose]);
34
- return (`<svg class="ws-ghost__sprite" xmlns="http://www.w3.org/2000/svg" viewBox="${BOUNDS.x} ${BOUNDS.y} ${BOUNDS.width} ${BOUNDS.height}" width="${BOUNDS.width * px}" height="${BOUNDS.height * px}" shape-rendering="crispEdges" aria-hidden="true">` +
35
- `<path class="ws-ghost__body" d="${body}"/><path class="ws-ghost__tongue" d="${love}"/></svg>`);
52
+ export function ghostSvg(options = {}) {
53
+ const { attributes, paths } = sprite(options);
54
+ const attrs = Object.entries({ xmlns: SVG, ...attributes })
55
+ .map(([name, value]) => `${name}="${value}"`)
56
+ .join(' ');
57
+ return `<svg ${attrs}>${paths.map(([name, d]) => `<path class="${name}" d="${d}"/>`).join('')}</svg>`;
58
+ }
59
+ /**
60
+ * The same ghost as `ghostSvg()`, as an element built without markup, for a script that adds
61
+ * it to a page where setting `innerHTML` is not wanted or not allowed.
62
+ */
63
+ export function ghostElement(options = {}, document = globalThis.document) {
64
+ const { attributes, paths } = sprite(options);
65
+ const svg = svgElement(document, 'svg', attributes);
66
+ svg.append(...paths.map(([name, d]) => svgElement(document, 'path', { class: name, d })));
67
+ return svg;
36
68
  }
69
+ /** The accessible name of the ghost's button. */
70
+ const BUTTON_LABEL = 'The whatsaaaa ghost';
37
71
  /**
38
72
  * The inside of a <ws-ghost>, for rendering it on a server so the ghost is there before
39
73
  * any script runs. The element fills itself in when it is empty.
40
74
  */
41
75
  export function ghostMarkup({ px = 2 } = {}) {
42
- return `<button type="button" class="ws-ghost__button" aria-label="The whatsaaaa ghost">${ghostSvg({ px })}</button>`;
76
+ return `<button type="button" class="ws-ghost__button" aria-label="${BUTTON_LABEL}">${ghostSvg({ px })}</button>`;
43
77
  }
44
78
  /** Space kept between the bubble and the edge of the window, and between bubble and ghost. */
45
79
  const WINDOW_MARGIN = 8;
@@ -59,8 +93,14 @@ export function attachGhost(host) {
59
93
  const unit = px >= 4 ? 3 : 2;
60
94
  /** The shout the host asks to hold, as a number of a's. None when it is not set. */
61
95
  const held = Number(host.getAttribute('shout'));
62
- if (!host.querySelector('.ws-ghost__button'))
63
- host.innerHTML = ghostMarkup({ px });
96
+ if (!host.querySelector('.ws-ghost__button')) {
97
+ const filled = host.ownerDocument.createElement('button');
98
+ filled.type = 'button';
99
+ filled.className = 'ws-ghost__button';
100
+ filled.setAttribute('aria-label', BUTTON_LABEL);
101
+ filled.append(ghostElement({ px }, host.ownerDocument));
102
+ host.replaceChildren(filled);
103
+ }
64
104
  const button = host.querySelector('.ws-ghost__button');
65
105
  const body = host.querySelector('.ws-ghost__body');
66
106
  const tongue = host.querySelector('.ws-ghost__tongue');
@@ -113,7 +153,7 @@ export function attachGhost(host) {
113
153
  // Drawn again only when it looks different. Moving it must not replay its pop.
114
154
  const drawing = `${shouting}|${side}|${tailShift}`;
115
155
  if (drawing !== drawn) {
116
- bubble.innerHTML = bubbleSvg(shouting, unit, side, tailShift);
156
+ bubble.replaceChildren(bubbleElement(shouting, unit, side, tailShift, host.ownerDocument));
117
157
  bubble.dataset.side = side;
118
158
  drawn = drawing;
119
159
  }
@@ -0,0 +1,4 @@
1
+ /** The namespace of SVG. */
2
+ export declare const SVG = "http://www.w3.org/2000/svg";
3
+ /** An SVG element with its attributes, built without markup. */
4
+ export declare function svgElement<K extends keyof SVGElementTagNameMap>(document: Document, name: K, attributes: Record<string, string>): SVGElementTagNameMap[K];
@@ -0,0 +1,9 @@
1
+ /** The namespace of SVG. */
2
+ export const SVG = 'http://www.w3.org/2000/svg';
3
+ /** An SVG element with its attributes, built without markup. */
4
+ export function svgElement(document, name, attributes) {
5
+ const element = document.createElementNS(SVG, name);
6
+ for (const [attribute, value] of Object.entries(attributes))
7
+ element.setAttribute(attribute, value);
8
+ return element;
9
+ }