@whatsaaaa/design-system 0.0.0 → 0.1.1

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.
Files changed (168) hide show
  1. package/README.md +151 -0
  2. package/assets/building-blocks/apple-touch-icon.png +0 -0
  3. package/assets/building-blocks/favicon-16.png +0 -0
  4. package/assets/building-blocks/favicon-32.png +0 -0
  5. package/assets/building-blocks/favicon.ico +0 -0
  6. package/assets/building-blocks/favicon.svg +1 -0
  7. package/assets/building-blocks/icon-192.png +0 -0
  8. package/assets/building-blocks/icon-512.png +0 -0
  9. package/assets/building-blocks/lockup-dark.svg +1 -0
  10. package/assets/building-blocks/lockup-light.svg +1 -0
  11. package/assets/building-blocks/mark-mono.svg +1 -0
  12. package/assets/building-blocks/mark-on-dark.svg +1 -0
  13. package/assets/building-blocks/mark-on-light.svg +1 -0
  14. package/assets/building-blocks/mark.svg +1 -0
  15. package/assets/building-blocks/readme-header.png +0 -0
  16. package/assets/building-blocks/readme-header.svg +1 -0
  17. package/assets/building-blocks/social-card.png +0 -0
  18. package/assets/building-blocks/social-card.svg +1 -0
  19. package/assets/building-blocks/wordmark-dark.svg +1 -0
  20. package/assets/building-blocks/wordmark-light.svg +1 -0
  21. package/assets/dotfiles/apple-touch-icon.png +0 -0
  22. package/assets/dotfiles/favicon-16.png +0 -0
  23. package/assets/dotfiles/favicon-32.png +0 -0
  24. package/assets/dotfiles/favicon.ico +0 -0
  25. package/assets/dotfiles/favicon.svg +1 -0
  26. package/assets/dotfiles/icon-192.png +0 -0
  27. package/assets/dotfiles/icon-512.png +0 -0
  28. package/assets/dotfiles/lockup-dark.svg +1 -0
  29. package/assets/dotfiles/lockup-light.svg +1 -0
  30. package/assets/dotfiles/mark-mono.svg +1 -0
  31. package/assets/dotfiles/mark-on-dark.svg +1 -0
  32. package/assets/dotfiles/mark-on-light.svg +1 -0
  33. package/assets/dotfiles/mark.svg +1 -0
  34. package/assets/dotfiles/readme-header.png +0 -0
  35. package/assets/dotfiles/readme-header.svg +1 -0
  36. package/assets/dotfiles/social-card.png +0 -0
  37. package/assets/dotfiles/social-card.svg +1 -0
  38. package/assets/dotfiles/wordmark-dark.svg +1 -0
  39. package/assets/dotfiles/wordmark-light.svg +1 -0
  40. package/assets/form-builder/apple-touch-icon.png +0 -0
  41. package/assets/form-builder/favicon-16.png +0 -0
  42. package/assets/form-builder/favicon-32.png +0 -0
  43. package/assets/form-builder/favicon.ico +0 -0
  44. package/assets/form-builder/favicon.svg +1 -0
  45. package/assets/form-builder/icon-192.png +0 -0
  46. package/assets/form-builder/icon-512.png +0 -0
  47. package/assets/form-builder/lockup-dark.svg +1 -0
  48. package/assets/form-builder/lockup-light.svg +1 -0
  49. package/assets/form-builder/mark-mono.svg +1 -0
  50. package/assets/form-builder/mark-on-dark.svg +1 -0
  51. package/assets/form-builder/mark-on-light.svg +1 -0
  52. package/assets/form-builder/mark.svg +1 -0
  53. package/assets/form-builder/readme-header.png +0 -0
  54. package/assets/form-builder/readme-header.svg +1 -0
  55. package/assets/form-builder/social-card.png +0 -0
  56. package/assets/form-builder/social-card.svg +1 -0
  57. package/assets/form-builder/wordmark-dark.svg +1 -0
  58. package/assets/form-builder/wordmark-light.svg +1 -0
  59. package/assets/manifest.json +541 -0
  60. package/assets/whatsaaaa/apple-touch-icon.png +0 -0
  61. package/assets/whatsaaaa/favicon-16.png +0 -0
  62. package/assets/whatsaaaa/favicon-32.png +0 -0
  63. package/assets/whatsaaaa/favicon.ico +0 -0
  64. package/assets/whatsaaaa/favicon.svg +1 -0
  65. package/assets/whatsaaaa/icon-192.png +0 -0
  66. package/assets/whatsaaaa/icon-512.png +0 -0
  67. package/assets/whatsaaaa/lockup-dark.svg +1 -0
  68. package/assets/whatsaaaa/lockup-light.svg +1 -0
  69. package/assets/whatsaaaa/mark-mono.svg +1 -0
  70. package/assets/whatsaaaa/mark-on-dark.svg +1 -0
  71. package/assets/whatsaaaa/mark-on-light.svg +1 -0
  72. package/assets/whatsaaaa/mark.svg +1 -0
  73. package/assets/whatsaaaa/pose-blink-dark.svg +1 -0
  74. package/assets/whatsaaaa/pose-blink-light.svg +1 -0
  75. package/assets/whatsaaaa/pose-idle-dark.svg +1 -0
  76. package/assets/whatsaaaa/pose-idle-light.svg +1 -0
  77. package/assets/whatsaaaa/pose-lost-dark.svg +1 -0
  78. package/assets/whatsaaaa/pose-lost-light.svg +1 -0
  79. package/assets/whatsaaaa/pose-shout-dark.svg +1 -0
  80. package/assets/whatsaaaa/pose-shout-light.svg +1 -0
  81. package/assets/whatsaaaa/pose-wag-left-dark.svg +1 -0
  82. package/assets/whatsaaaa/pose-wag-left-light.svg +1 -0
  83. package/assets/whatsaaaa/pose-wag-right-dark.svg +1 -0
  84. package/assets/whatsaaaa/pose-wag-right-light.svg +1 -0
  85. package/assets/whatsaaaa/readme-header.png +0 -0
  86. package/assets/whatsaaaa/readme-header.svg +1 -0
  87. package/assets/whatsaaaa/social-card.png +0 -0
  88. package/assets/whatsaaaa/social-card.svg +1 -0
  89. package/assets/whatsaaaa/wordmark-dark.svg +1 -0
  90. package/assets/whatsaaaa/wordmark-light.svg +1 -0
  91. package/dist/color.d.ts +5 -0
  92. package/dist/color.js +7 -0
  93. package/dist/css/base.css +50 -0
  94. package/dist/css/callout.css +64 -0
  95. package/dist/css/code.css +50 -0
  96. package/dist/css/ghost.css +93 -0
  97. package/dist/css/icons.css +8 -0
  98. package/dist/css/prose.css +320 -0
  99. package/dist/css/terminal.css +424 -0
  100. package/dist/fonts/inter-latin-ext-wght-italic.woff2 +0 -0
  101. package/dist/fonts/inter-latin-ext-wght-normal.woff2 +0 -0
  102. package/dist/fonts/inter-latin-wght-italic.woff2 +0 -0
  103. package/dist/fonts/inter-latin-wght-normal.woff2 +0 -0
  104. package/dist/fonts/inter.OFL.txt +93 -0
  105. package/dist/fonts/jetbrains-mono-latin-ext-wght-italic.woff2 +0 -0
  106. package/dist/fonts/jetbrains-mono-latin-ext-wght-normal.woff2 +0 -0
  107. package/dist/fonts/jetbrains-mono-latin-wght-italic.woff2 +0 -0
  108. package/dist/fonts/jetbrains-mono-latin-wght-normal.woff2 +0 -0
  109. package/dist/fonts/jetbrains-mono.OFL.txt +93 -0
  110. package/dist/fonts.css +85 -0
  111. package/dist/ghost/bubble.d.ts +16 -0
  112. package/dist/ghost/bubble.js +50 -0
  113. package/dist/ghost/glyphs.d.ts +12 -0
  114. package/dist/ghost/glyphs.js +19 -0
  115. package/dist/ghost/index.d.ts +57 -0
  116. package/dist/ghost/index.js +227 -0
  117. package/dist/identity/ghost.d.ts +28 -0
  118. package/dist/identity/ghost.js +129 -0
  119. package/dist/identity/marks.d.ts +48 -0
  120. package/dist/identity/marks.js +52 -0
  121. package/dist/identity/sprite.d.ts +43 -0
  122. package/dist/identity/sprite.js +100 -0
  123. package/dist/index.css +1404 -0
  124. package/dist/shiki/index.d.ts +20 -0
  125. package/dist/shiki/index.js +64 -0
  126. package/dist/shortcuts/index.d.ts +48 -0
  127. package/dist/shortcuts/index.js +155 -0
  128. package/dist/shortcuts/init.js +2 -0
  129. package/dist/theme/index.d.ts +24 -0
  130. package/dist/theme/index.js +60 -0
  131. package/dist/theme/init.js +2 -0
  132. package/dist/tokens.css +537 -0
  133. package/dist/tokens.d.ts +194 -0
  134. package/dist/tokens.js +336 -0
  135. package/dist/vitepress-config/index.d.ts +16 -0
  136. package/dist/vitepress-config/index.js +36 -0
  137. package/dist/vitepress-config/markdown.d.ts +6 -0
  138. package/dist/vitepress-config/markdown.js +50 -0
  139. package/dist/vitepress-config/types.d.ts +16 -0
  140. package/dist/vitepress-config/types.js +1 -0
  141. package/docs/usage.md +226 -0
  142. package/licenses/README.md +10 -0
  143. package/licenses/departure-mono.OFL.txt +93 -0
  144. package/licenses/rose-pine-palette.LICENSE +21 -0
  145. package/package.json +155 -3
  146. package/src/vitepress/Layout.vue +77 -0
  147. package/src/vitepress/components/Crumb.vue +32 -0
  148. package/src/vitepress/components/NavGhost.vue +23 -0
  149. package/src/vitepress/components/NotFound.vue +22 -0
  150. package/src/vitepress/components/StatusLine.vue +128 -0
  151. package/src/vitepress/env.d.ts +2 -0
  152. package/src/vitepress/index.ts +34 -0
  153. package/src/vitepress/path.ts +19 -0
  154. package/src/vitepress/styles/doc.css +385 -0
  155. package/src/vitepress/styles/home.css +47 -0
  156. package/src/vitepress/styles/layout.css +97 -0
  157. package/src/vitepress/styles/nav.css +441 -0
  158. package/src/vitepress/styles/search.css +55 -0
  159. package/src/vitepress/styles/sidebar.css +173 -0
  160. package/src/vitepress/styles/vars.css +204 -0
  161. package/src/vitepress/support.ts +15 -0
  162. package/src/vitepress/theme.d.ts +8 -0
  163. package/tokens/contrast.json +271 -0
  164. package/tokens/core.tokens.json +743 -0
  165. package/tokens/palette.tokens.json +222 -0
  166. package/tokens/theme-dark.tokens.json +146 -0
  167. package/tokens/theme-light.tokens.json +146 -0
  168. package/tokens/whatsaaaa.resolver.json +43 -0
package/dist/fonts.css ADDED
@@ -0,0 +1,85 @@
1
+ /*
2
+ * JetBrains Mono and Inter as variable fonts, self-hosted.
3
+ * Both are licensed under the SIL Open Font License 1.1. The licenses are next to the files, in fonts/.
4
+ * A browser downloads a subset only when the page has characters from it.
5
+ */
6
+
7
+ /* JetBrains Mono, normal, latin-ext */
8
+ @font-face {
9
+ font-family: 'JetBrains Mono';
10
+ font-style: normal;
11
+ font-weight: 100 800;
12
+ font-display: swap;
13
+ src: url('./fonts/jetbrains-mono-latin-ext-wght-normal.woff2') format('woff2-variations');
14
+ unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
15
+ }
16
+
17
+ /* JetBrains Mono, normal, latin */
18
+ @font-face {
19
+ font-family: 'JetBrains Mono';
20
+ font-style: normal;
21
+ font-weight: 100 800;
22
+ font-display: swap;
23
+ src: url('./fonts/jetbrains-mono-latin-wght-normal.woff2') format('woff2-variations');
24
+ unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
25
+ }
26
+
27
+ /* JetBrains Mono, italic, latin-ext */
28
+ @font-face {
29
+ font-family: 'JetBrains Mono';
30
+ font-style: italic;
31
+ font-weight: 100 800;
32
+ font-display: swap;
33
+ src: url('./fonts/jetbrains-mono-latin-ext-wght-italic.woff2') format('woff2-variations');
34
+ unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
35
+ }
36
+
37
+ /* JetBrains Mono, italic, latin */
38
+ @font-face {
39
+ font-family: 'JetBrains Mono';
40
+ font-style: italic;
41
+ font-weight: 100 800;
42
+ font-display: swap;
43
+ src: url('./fonts/jetbrains-mono-latin-wght-italic.woff2') format('woff2-variations');
44
+ unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
45
+ }
46
+
47
+ /* Inter, normal, latin-ext */
48
+ @font-face {
49
+ font-family: 'Inter';
50
+ font-style: normal;
51
+ font-weight: 100 900;
52
+ font-display: swap;
53
+ src: url('./fonts/inter-latin-ext-wght-normal.woff2') format('woff2-variations');
54
+ unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
55
+ }
56
+
57
+ /* Inter, normal, latin */
58
+ @font-face {
59
+ font-family: 'Inter';
60
+ font-style: normal;
61
+ font-weight: 100 900;
62
+ font-display: swap;
63
+ src: url('./fonts/inter-latin-wght-normal.woff2') format('woff2-variations');
64
+ unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
65
+ }
66
+
67
+ /* Inter, italic, latin-ext */
68
+ @font-face {
69
+ font-family: 'Inter';
70
+ font-style: italic;
71
+ font-weight: 100 900;
72
+ font-display: swap;
73
+ src: url('./fonts/inter-latin-ext-wght-italic.woff2') format('woff2-variations');
74
+ unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
75
+ }
76
+
77
+ /* Inter, italic, latin */
78
+ @font-face {
79
+ font-family: 'Inter';
80
+ font-style: italic;
81
+ font-weight: 100 900;
82
+ font-display: swap;
83
+ src: url('./fonts/inter-latin-wght-italic.woff2') format('woff2-variations');
84
+ unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
85
+ }
@@ -0,0 +1,16 @@
1
+ export type BubbleSide = 'above' | 'below';
2
+ /** Width and height of the bubble for a text, in font pixels. */
3
+ export declare function bubbleSize(text: string): {
4
+ width: number;
5
+ height: number;
6
+ };
7
+ /** How many letters fit a bubble that may be `width` font pixels wide. */
8
+ export declare function lettersThatFit(width: number): number;
9
+ /** Furthest the tail can move right, in font pixels. */
10
+ export declare const maxTailShift: (text: string) => number;
11
+ /**
12
+ * A pixel speech bubble with stepped corners, as SVG.
13
+ * `unit` is the size of one font pixel. The tail points down when the bubble sits above the
14
+ * speaker and up when it sits below, and `tailShift` moves it right, in font pixels.
15
+ */
16
+ export declare function bubbleSvg(text: string, unit: number, side: BubbleSide, tailShift?: number): string;
@@ -0,0 +1,50 @@
1
+ import { BUBBLE_ADVANCE, BUBBLE_GLYPHS } from "./glyphs.js";
2
+ /** Height of the bubble's body, and of the tail under or over it, in font pixels. */
3
+ const BODY = 15;
4
+ const TAIL = 3;
5
+ /** Empty font pixels left and right of the text. */
6
+ const PADDING = 3;
7
+ /** Width and height of the bubble for a text, in font pixels. */
8
+ export function bubbleSize(text) {
9
+ return { width: [...text].length * BUBBLE_ADVANCE + 2 * PADDING, height: BODY + TAIL };
10
+ }
11
+ /** How many letters fit a bubble that may be `width` font pixels wide. */
12
+ export function lettersThatFit(width) {
13
+ return Math.floor((width - 2 * PADDING) / BUBBLE_ADVANCE);
14
+ }
15
+ /** Furthest the tail can move right, in font pixels. */
16
+ export const maxTailShift = (text) => bubbleSize(text).width - 7;
17
+ /**
18
+ * A pixel speech bubble with stepped corners, as SVG.
19
+ * `unit` is the size of one font pixel. The tail points down when the bubble sits above the
20
+ * speaker and up when it sits below, and `tailShift` moves it right, in font pixels.
21
+ */
22
+ export function bubbleSvg(text, unit, side, tailShift = 0) {
23
+ const { width, height } = bubbleSize(text);
24
+ const top = side === 'below' ? TAIL : 0;
25
+ // three steps, narrowing toward the speaker
26
+ const steps = side === 'below'
27
+ ? [
28
+ [3, top - 1, 3],
29
+ [2, top - 2, 2],
30
+ [1, top - 3, 1],
31
+ ]
32
+ : [
33
+ [3, BODY, 3],
34
+ [2, BODY + 1, 2],
35
+ [1, BODY + 2, 1],
36
+ ];
37
+ const shape = `M1 ${top}h${width - 2}v1h1v${BODY - 2}h-1v1h${2 - width}v-1h-1v${2 - BODY}h1z` +
38
+ steps.map(([x, y, run]) => `M${x + tailShift} ${y}h${run}v1h${-run}z`).join('');
39
+ const letters = [...text]
40
+ .map((char, index) => {
41
+ const glyph = BUBBLE_GLYPHS[char];
42
+ if (!glyph)
43
+ 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>`);
50
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The six letters of the shout, as pixel outlines, so the speech bubble loads no font.
3
+ *
4
+ * They are the glyphs of Departure Mono 1.500 at its native 11 px.
5
+ * Copyright 2022-2024 Helena Zhang (helenazhang.com), SIL Open Font License 1.1.
6
+ * The license is in licenses/departure-mono.OFL.txt.
7
+ *
8
+ * Each glyph is path data in font pixels, with the baseline at y = 0.
9
+ */
10
+ export declare const BUBBLE_GLYPHS: Record<string, string>;
11
+ /** How far one letter moves the next, in font pixels. */
12
+ export declare const BUBBLE_ADVANCE = 7;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The six letters of the shout, as pixel outlines, so the speech bubble loads no font.
3
+ *
4
+ * They are the glyphs of Departure Mono 1.500 at its native 11 px.
5
+ * Copyright 2022-2024 Helena Zhang (helenazhang.com), SIL Open Font License 1.1.
6
+ * The license is in licenses/departure-mono.OFL.txt.
7
+ *
8
+ * Each glyph is path data in font pixels, with the baseline at y = 0.
9
+ */
10
+ export const BUBBLE_GLYPHS = {
11
+ w: 'M1 -6L1 -1L2 -1L2 -6M5 -6L5 -1L4 -1L4 0L6 0L6 -6M4 -1L4 -6L3 -6L3 -1M2 -1L2 0L3 0L3 -1',
12
+ h: 'M1 -8L1 0L2 0L2 -4L3 -4L3 -5L2 -5L2 -8M5 -5L5 0L6 0L6 -5M3 -6L3 -5L5 -5L5 -6',
13
+ a: 'M1 -3L1 -1L2 -1L2 -3M2 -1L2 0L4 0L4 -1M4 -2L4 -1L5 -1L5 0L6 0L6 -5L5 -5L5 -4L2 -4L2 -3L5 -3L5 -2M2 -6L2 -5L5 -5L5 -6',
14
+ t: 'M2 -8L2 -6L1 -6L1 -5L2 -5L2 -1L3 -1L3 -5L6 -5L6 -6L3 -6L3 -8M3 -1L3 0L5 0L5 -1M5 -2L5 -1L6 -1L6 -2',
15
+ s: 'M5 -1L2 -1L2 0L5 0M2 -1L2 -2L1 -2L1 -1M5 -6L2 -6L2 -5L5 -5M1 -5L1 -4L2 -4L2 -5M2 -4L2 -3L5 -3L5 -4M5 -3L5 -1L6 -1L6 -3M5 -5L5 -4L6 -4L6 -5',
16
+ '!': 'M3 -8L3 -2L4 -2L4 -8M3 -1L3 0L4 0L4 -1',
17
+ };
18
+ /** How far one letter moves the next, in font pixels. */
19
+ export const BUBBLE_ADVANCE = 7;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * The ghost as a usable piece: static markup for any page, and the <ws-ghost> element with
3
+ * the easter egg. Press the ghost three times in a row and it shouts the handle in a speech
4
+ * bubble. Every further press holds the a for one letter longer.
5
+ *
6
+ * Everything here is safe to import on a server. Only `defineGhost()` needs a browser.
7
+ */
8
+ import { type GhostPose } from '../identity/ghost.ts';
9
+ export type { GhostPose } from '../identity/ghost.ts';
10
+ /** The ghost is this many sprite pixels wide and tall. */
11
+ export declare const GHOST_WIDTH: number;
12
+ export declare const GHOST_HEIGHT: number;
13
+ /** Presses have to follow each other within this many milliseconds to count as a row. */
14
+ export declare const PRESS_WINDOW = 1500;
15
+ /** The shout starts at this press. The ones before it only wag the tongue. */
16
+ export declare const PRESSES_TO_SHOUT = 3;
17
+ /** How long the tongue stays wagged, and how long the shout stays, in milliseconds. */
18
+ export declare const WAG_HOLD = 700;
19
+ export declare const SHOUT_HOLD = 2600;
20
+ /** The handle is shouted with at least this many a's, and at most this many. */
21
+ export declare const FIRST_SHOUT = 4;
22
+ export declare const LONGEST_SHOUT = 16;
23
+ /** The text of a shout with `count` a's. */
24
+ export declare const shoutText: (count: number) => string;
25
+ export interface GhostSvgOptions {
26
+ /** Size of one sprite pixel in CSS pixels. Whole numbers keep the sprite sharp. */
27
+ px?: number;
28
+ pose?: GhostPose;
29
+ }
30
+ /**
31
+ * The free ghost as inline SVG, without its margin, so it sits in a line of text.
32
+ * The body takes the text color and the tongue the brand color (see css/ghost.css).
33
+ */
34
+ export declare function ghostSvg({ px, pose }?: GhostSvgOptions): string;
35
+ export interface GhostMarkupOptions {
36
+ px?: number;
37
+ }
38
+ /**
39
+ * The inside of a <ws-ghost>, for rendering it on a server so the ghost is there before
40
+ * any script runs. The element fills itself in when it is empty.
41
+ */
42
+ export declare function ghostMarkup({ px }?: GhostMarkupOptions): string;
43
+ /**
44
+ * Makes a host element behave as the ghost. Returns a function that undoes it.
45
+ * <ws-ghost> calls this for itself. Call it directly to use another element as the host.
46
+ *
47
+ * Attributes of the host:
48
+ * - `px`: size of one sprite pixel (default 2)
49
+ * - `bubble`: `above` or `below` to fix the side the bubble takes (default: above when it fits)
50
+ * - `shout`: a number of a's. The ghost shouts at once and holds it, for showing the shout
51
+ */
52
+ export declare function attachGhost(host: HTMLElement): () => void;
53
+ /**
54
+ * Registers <ws-ghost>. Call it once in the browser. Does nothing on a server or when the
55
+ * element is already registered.
56
+ */
57
+ export declare function defineGhost(): void;
@@ -0,0 +1,227 @@
1
+ /**
2
+ * The ghost as a usable piece: static markup for any page, and the <ws-ghost> element with
3
+ * the easter egg. Press the ghost three times in a row and it shouts the handle in a speech
4
+ * bubble. Every further press holds the a for one letter longer.
5
+ *
6
+ * Everything here is safe to import on a server. Only `defineGhost()` needs a browser.
7
+ */
8
+ import { GHOST_POSES } from "../identity/ghost.js";
9
+ import { spriteBounds, spritePaths } from "../identity/sprite.js";
10
+ import { bubbleSize, bubbleSvg, lettersThatFit, maxTailShift } from "./bubble.js";
11
+ /** The pixels the ghost occupies in its 16 x 16 grid. Every pose has the same outline. */
12
+ const BOUNDS = spriteBounds(GHOST_POSES.idle);
13
+ /** The ghost is this many sprite pixels wide and tall. */
14
+ export const GHOST_WIDTH = BOUNDS.width;
15
+ export const GHOST_HEIGHT = BOUNDS.height;
16
+ /** Presses have to follow each other within this many milliseconds to count as a row. */
17
+ export const PRESS_WINDOW = 1500;
18
+ /** The shout starts at this press. The ones before it only wag the tongue. */
19
+ export const PRESSES_TO_SHOUT = 3;
20
+ /** How long the tongue stays wagged, and how long the shout stays, in milliseconds. */
21
+ export const WAG_HOLD = 700;
22
+ export const SHOUT_HOLD = 2600;
23
+ /** The handle is shouted with at least this many a's, and at most this many. */
24
+ export const FIRST_SHOUT = 4;
25
+ export const LONGEST_SHOUT = 16;
26
+ /** The text of a shout with `count` a's. */
27
+ export const shoutText = (count) => `whats${'a'.repeat(count)}!`;
28
+ /**
29
+ * The free ghost as inline SVG, without its margin, so it sits in a line of text.
30
+ * The body takes the text color and the tongue the brand color (see css/ghost.css).
31
+ */
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>`);
36
+ }
37
+ /**
38
+ * The inside of a <ws-ghost>, for rendering it on a server so the ghost is there before
39
+ * any script runs. The element fills itself in when it is empty.
40
+ */
41
+ export function ghostMarkup({ px = 2 } = {}) {
42
+ return `<button type="button" class="ws-ghost__button" aria-label="The whatsaaaa ghost">${ghostSvg({ px })}</button>`;
43
+ }
44
+ /** Space kept between the bubble and the edge of the window, and between bubble and ghost. */
45
+ const WINDOW_MARGIN = 8;
46
+ const BUBBLE_GAP = 4;
47
+ /**
48
+ * Makes a host element behave as the ghost. Returns a function that undoes it.
49
+ * <ws-ghost> calls this for itself. Call it directly to use another element as the host.
50
+ *
51
+ * Attributes of the host:
52
+ * - `px`: size of one sprite pixel (default 2)
53
+ * - `bubble`: `above` or `below` to fix the side the bubble takes (default: above when it fits)
54
+ * - `shout`: a number of a's. The ghost shouts at once and holds it, for showing the shout
55
+ */
56
+ export function attachGhost(host) {
57
+ const px = Number(host.getAttribute('px')) || 2;
58
+ // one bubble pixel: larger next to a large ghost
59
+ const unit = px >= 4 ? 3 : 2;
60
+ /** The shout the host asks to hold, as a number of a's. None when it is not set. */
61
+ const held = Number(host.getAttribute('shout'));
62
+ if (!host.querySelector('.ws-ghost__button'))
63
+ host.innerHTML = ghostMarkup({ px });
64
+ const button = host.querySelector('.ws-ghost__button');
65
+ const body = host.querySelector('.ws-ghost__body');
66
+ const tongue = host.querySelector('.ws-ghost__tongue');
67
+ const view = host.ownerDocument.defaultView;
68
+ // the bubble is drawn for the eye, the live region carries the shout to screen readers
69
+ const bubble = host.ownerDocument.createElement('span');
70
+ bubble.className = 'ws-ghost__bubble';
71
+ bubble.setAttribute('popover', 'manual');
72
+ bubble.setAttribute('aria-hidden', 'true');
73
+ const live = host.ownerDocument.createElement('span');
74
+ live.className = 'ws-ghost__live';
75
+ live.setAttribute('role', 'status');
76
+ live.setAttribute('aria-live', 'polite');
77
+ host.append(bubble, live);
78
+ let presses = 0;
79
+ let lastPress = 0;
80
+ /** The shout that shows and the a's in it. Empty and none while the ghost is quiet. */
81
+ let shouting = '';
82
+ let letters = 0;
83
+ let calm;
84
+ const pose = (name) => {
85
+ const { body: bodyPath, love } = spritePaths(GHOST_POSES[name]);
86
+ body.setAttribute('d', bodyPath);
87
+ tongue.setAttribute('d', love);
88
+ host.dataset.pose = name;
89
+ };
90
+ /** What the bubble shows now: its text, its side and where its tail is. */
91
+ let drawn = '';
92
+ /** Where the ghost was when the bubble was last placed. */
93
+ let placedFor = '';
94
+ let following = 0;
95
+ /** Puts the bubble next to the ghost: above it when there is room, and inside the window. */
96
+ const place = () => {
97
+ if (!shouting)
98
+ return;
99
+ const ghost = button.getBoundingClientRect();
100
+ const size = bubbleSize(shouting);
101
+ const [width, height] = [size.width * unit, size.height * unit];
102
+ const fixed = host.getAttribute('bubble');
103
+ const side = fixed === 'above' || fixed === 'below'
104
+ ? fixed
105
+ : ghost.top - BUBBLE_GAP - height >= WINDOW_MARGIN
106
+ ? 'above'
107
+ : 'below';
108
+ const wanted = ghost.left + ghost.width * 0.55;
109
+ const windowWidth = host.ownerDocument.documentElement.clientWidth;
110
+ const left = Math.max(WINDOW_MARGIN, Math.min(wanted, windowWidth - WINDOW_MARGIN - width));
111
+ // when the bubble had to move left, its tail moves right to stay at the ghost
112
+ const tailShift = Math.max(0, Math.min(Math.round((wanted - left) / unit), maxTailShift(shouting)));
113
+ // Drawn again only when it looks different. Moving it must not replay its pop.
114
+ const drawing = `${shouting}|${side}|${tailShift}`;
115
+ if (drawing !== drawn) {
116
+ bubble.innerHTML = bubbleSvg(shouting, unit, side, tailShift);
117
+ bubble.dataset.side = side;
118
+ drawn = drawing;
119
+ }
120
+ bubble.style.left = `${Math.round(left)}px`;
121
+ bubble.style.top = `${Math.round(side === 'above' ? ghost.top - BUBBLE_GAP - height : ghost.bottom + BUBBLE_GAP)}px`;
122
+ placedFor = position();
123
+ };
124
+ const position = () => {
125
+ const ghost = button.getBoundingClientRect();
126
+ return `${ghost.left},${ghost.top},${ghost.width},${ghost.height},${host.ownerDocument.documentElement.clientWidth}`;
127
+ };
128
+ /**
129
+ * The bubble is drawn above the page, so nothing moves it along with the ghost. While it is
130
+ * open it looks every frame where the ghost is and follows: a scroll, a window that
131
+ * changes size, or a page that reflows when a font or an image arrives late.
132
+ */
133
+ const follow = () => {
134
+ if (position() !== placedFor)
135
+ place();
136
+ following = view.requestAnimationFrame(follow);
137
+ };
138
+ const showBubble = () => {
139
+ bubble.dataset.open = '';
140
+ // a popover is drawn above everything and is never clipped
141
+ if (typeof bubble.showPopover === 'function' && !bubble.matches(':popover-open'))
142
+ bubble.showPopover();
143
+ following = view.requestAnimationFrame(follow);
144
+ };
145
+ const hideBubble = () => {
146
+ view.cancelAnimationFrame(following);
147
+ if (typeof bubble.hidePopover === 'function' && bubble.matches(':popover-open'))
148
+ bubble.hidePopover();
149
+ delete bubble.dataset.open;
150
+ bubble.replaceChildren();
151
+ drawn = '';
152
+ placedFor = '';
153
+ };
154
+ const quiet = () => {
155
+ clearTimeout(calm);
156
+ shouting = '';
157
+ letters = 0;
158
+ hideBubble();
159
+ live.textContent = '';
160
+ pose('idle');
161
+ };
162
+ const shout = (count) => {
163
+ // the bubble never gets wider than the window: the shout stops growing instead
164
+ const room = (host.ownerDocument.documentElement.clientWidth - 2 * WINDOW_MARGIN) / unit;
165
+ const most = Math.max(2, lettersThatFit(room) - shoutText(0).length);
166
+ const started = !shouting;
167
+ letters = Math.min(count, most, LONGEST_SHOUT);
168
+ shouting = shoutText(letters);
169
+ pose('shout');
170
+ if (started) {
171
+ showBubble();
172
+ // announced once, when the shout starts, not for every letter added to it
173
+ live.textContent = shouting;
174
+ }
175
+ place();
176
+ };
177
+ /** What the ghost goes back to after a wag or a shout: the shout it holds, or quiet. */
178
+ const rest = () => {
179
+ if (held > 0)
180
+ shout(held);
181
+ else
182
+ quiet();
183
+ };
184
+ const press = () => {
185
+ const now = Date.now();
186
+ presses = now - lastPress < PRESS_WINDOW ? presses + 1 : 1;
187
+ lastPress = now;
188
+ clearTimeout(calm);
189
+ // a press while the shout shows continues it, however long ago the last one was
190
+ if (shouting || presses >= PRESSES_TO_SHOUT) {
191
+ shout(shouting ? letters + 1 : FIRST_SHOUT);
192
+ calm = setTimeout(rest, SHOUT_HOLD);
193
+ return;
194
+ }
195
+ // The first presses only wag the tongue. With reduced motion the ghost keeps still.
196
+ if (view.matchMedia?.('(prefers-reduced-motion: reduce)').matches)
197
+ return;
198
+ pose(presses === 1 ? 'wag-left' : 'wag-right');
199
+ calm = setTimeout(rest, WAG_HOLD);
200
+ };
201
+ button.addEventListener('click', press);
202
+ rest();
203
+ return () => {
204
+ button.removeEventListener('click', press);
205
+ quiet();
206
+ bubble.remove();
207
+ live.remove();
208
+ };
209
+ }
210
+ /**
211
+ * Registers <ws-ghost>. Call it once in the browser. Does nothing on a server or when the
212
+ * element is already registered.
213
+ */
214
+ export function defineGhost() {
215
+ if (typeof customElements === 'undefined' || customElements.get('ws-ghost'))
216
+ return;
217
+ customElements.define('ws-ghost', class extends HTMLElement {
218
+ #detach;
219
+ connectedCallback() {
220
+ this.#detach = attachGhost(this);
221
+ }
222
+ disconnectedCallback() {
223
+ this.#detach?.();
224
+ this.#detach = undefined;
225
+ }
226
+ });
227
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The ghost, pixel by pixel. This file is the source of the mark: the asset kit, the
3
+ * <ws-ghost> element and the style guide all draw from it.
4
+ *
5
+ * It is original artwork: a pale body with a dome, two square eyes, a w-shaped mouth with the
6
+ * tongue out, and a hem that stands on two points. Three habits keep it apart from other
7
+ * ghosts: the tongue is always there and always in the love color, the body is never
8
+ * recolored, and nothing is ever drawn on its face or its tile.
9
+ *
10
+ * `B` body, `T` tongue, `_` a hole in the body (eyes and mouth), `.` empty.
11
+ */
12
+ export declare const GHOST_POSES: {
13
+ /** The mark itself. */
14
+ readonly idle: readonly ["................", "................", ".....BBBBBB.....", "....BBBBBBBB....", "...BBBBBBBBBB...", "...BB__BB__BB...", "...BB__BB__BB...", "...BBBBBBBBBB...", "...BB_B__B_BB...", "...BBB_TT_BBB...", "...BBBBTTBBBB...", "...BBBBBBBBBB...", "...BBBB..BBBB...", "....BB....BB....", "................", "................"];
15
+ /** Eyes half shut. */
16
+ readonly blink: readonly ["................", "................", ".....BBBBBB.....", "....BBBBBBBB....", "...BBBBBBBBBB...", "...BBBBBBBBBB...", "...BB__BB__BB...", "...BBBBBBBBBB...", "...BB_B__B_BB...", "...BBB_TT_BBB...", "...BBBBTTBBBB...", "...BBBBBBBBBB...", "...BBBB..BBBB...", "....BB....BB....", "................", "................"];
17
+ /** The tongue one pixel to the left. */
18
+ readonly 'wag-left': readonly ["................", "................", ".....BBBBBB.....", "....BBBBBBBB....", "...BBBBBBBBBB...", "...BB__BB__BB...", "...BB__BB__BB...", "...BBBBBBBBBB...", "...BB_B__B_BB...", "...BBB_TT_BBB...", "...BBBTTBBBBB...", "...BBBBBBBBBB...", "...BBBB..BBBB...", "....BB....BB....", "................", "................"];
19
+ /** The tongue one pixel to the right. */
20
+ readonly 'wag-right': readonly ["................", "................", ".....BBBBBB.....", "....BBBBBBBB....", "...BBBBBBBBBB...", "...BB__BB__BB...", "...BB__BB__BB...", "...BBBBBBBBBB...", "...BB_B__B_BB...", "...BBB_TT_BBB...", "...BBBBBTTBBB...", "...BBBBBBBBBB...", "...BBBB..BBBB...", "....BB....BB....", "................", "................"];
21
+ /** Mouth wide open, for the shout. */
22
+ readonly shout: readonly ["................", "................", ".....BBBBBB.....", "....BBBBBBBB....", "...BB__BB__BB...", "...BB__BB__BB...", "...BBBBBBBBBB...", "...BB______BB...", "...BB_TTTT_BB...", "...BBBTTTTBBB...", "...BBBBTTBBBB...", "...BBBBBBBBBB...", "...BBBB..BBBB...", "....BB....BB....", "................", "................"];
23
+ /** Eyes looking away and the mouth shut, for a page that is not there. */
24
+ readonly lost: readonly ["................", "................", ".....BBBBBB.....", "....BBBBBBBB....", "...BBBBBBBBBB...", "...BB__BB__BB...", "...BBB_BBB_BB...", "...BBBBBBBBBB...", "...BBBBBBBBBB...", "...BBB____BBB...", "...BBBBBBBBBB...", "...BBBBBBBBBB...", "...BBBB..BBBB...", "....BB....BB....", "................", "................"];
25
+ };
26
+ export type GhostPose = keyof typeof GHOST_POSES;
27
+ /** The mark: the ghost at rest. */
28
+ export declare const GHOST: readonly ["................", "................", ".....BBBBBB.....", "....BBBBBBBB....", "...BBBBBBBBBB...", "...BB__BB__BB...", "...BB__BB__BB...", "...BBBBBBBBBB...", "...BB_B__B_BB...", "...BBB_TT_BBB...", "...BBBBTTBBBB...", "...BBBBBBBBBB...", "...BBBB..BBBB...", "....BB....BB....", "................", "................"];
@@ -0,0 +1,129 @@
1
+ /**
2
+ * The ghost, pixel by pixel. This file is the source of the mark: the asset kit, the
3
+ * <ws-ghost> element and the style guide all draw from it.
4
+ *
5
+ * It is original artwork: a pale body with a dome, two square eyes, a w-shaped mouth with the
6
+ * tongue out, and a hem that stands on two points. Three habits keep it apart from other
7
+ * ghosts: the tongue is always there and always in the love color, the body is never
8
+ * recolored, and nothing is ever drawn on its face or its tile.
9
+ *
10
+ * `B` body, `T` tongue, `_` a hole in the body (eyes and mouth), `.` empty.
11
+ */
12
+ export const GHOST_POSES = {
13
+ /** The mark itself. */
14
+ idle: [
15
+ '................',
16
+ '................',
17
+ '.....BBBBBB.....',
18
+ '....BBBBBBBB....',
19
+ '...BBBBBBBBBB...',
20
+ '...BB__BB__BB...',
21
+ '...BB__BB__BB...',
22
+ '...BBBBBBBBBB...',
23
+ '...BB_B__B_BB...',
24
+ '...BBB_TT_BBB...',
25
+ '...BBBBTTBBBB...',
26
+ '...BBBBBBBBBB...',
27
+ '...BBBB..BBBB...',
28
+ '....BB....BB....',
29
+ '................',
30
+ '................',
31
+ ],
32
+ /** Eyes half shut. */
33
+ blink: [
34
+ '................',
35
+ '................',
36
+ '.....BBBBBB.....',
37
+ '....BBBBBBBB....',
38
+ '...BBBBBBBBBB...',
39
+ '...BBBBBBBBBB...',
40
+ '...BB__BB__BB...',
41
+ '...BBBBBBBBBB...',
42
+ '...BB_B__B_BB...',
43
+ '...BBB_TT_BBB...',
44
+ '...BBBBTTBBBB...',
45
+ '...BBBBBBBBBB...',
46
+ '...BBBB..BBBB...',
47
+ '....BB....BB....',
48
+ '................',
49
+ '................',
50
+ ],
51
+ /** The tongue one pixel to the left. */
52
+ 'wag-left': [
53
+ '................',
54
+ '................',
55
+ '.....BBBBBB.....',
56
+ '....BBBBBBBB....',
57
+ '...BBBBBBBBBB...',
58
+ '...BB__BB__BB...',
59
+ '...BB__BB__BB...',
60
+ '...BBBBBBBBBB...',
61
+ '...BB_B__B_BB...',
62
+ '...BBB_TT_BBB...',
63
+ '...BBBTTBBBBB...',
64
+ '...BBBBBBBBBB...',
65
+ '...BBBB..BBBB...',
66
+ '....BB....BB....',
67
+ '................',
68
+ '................',
69
+ ],
70
+ /** The tongue one pixel to the right. */
71
+ 'wag-right': [
72
+ '................',
73
+ '................',
74
+ '.....BBBBBB.....',
75
+ '....BBBBBBBB....',
76
+ '...BBBBBBBBBB...',
77
+ '...BB__BB__BB...',
78
+ '...BB__BB__BB...',
79
+ '...BBBBBBBBBB...',
80
+ '...BB_B__B_BB...',
81
+ '...BBB_TT_BBB...',
82
+ '...BBBBBTTBBB...',
83
+ '...BBBBBBBBBB...',
84
+ '...BBBB..BBBB...',
85
+ '....BB....BB....',
86
+ '................',
87
+ '................',
88
+ ],
89
+ /** Mouth wide open, for the shout. */
90
+ shout: [
91
+ '................',
92
+ '................',
93
+ '.....BBBBBB.....',
94
+ '....BBBBBBBB....',
95
+ '...BB__BB__BB...',
96
+ '...BB__BB__BB...',
97
+ '...BBBBBBBBBB...',
98
+ '...BB______BB...',
99
+ '...BB_TTTT_BB...',
100
+ '...BBBTTTTBBB...',
101
+ '...BBBBTTBBBB...',
102
+ '...BBBBBBBBBB...',
103
+ '...BBBB..BBBB...',
104
+ '....BB....BB....',
105
+ '................',
106
+ '................',
107
+ ],
108
+ /** Eyes looking away and the mouth shut, for a page that is not there. */
109
+ lost: [
110
+ '................',
111
+ '................',
112
+ '.....BBBBBB.....',
113
+ '....BBBBBBBB....',
114
+ '...BBBBBBBBBB...',
115
+ '...BB__BB__BB...',
116
+ '...BBB_BBB_BB...',
117
+ '...BBBBBBBBBB...',
118
+ '...BBBBBBBBBB...',
119
+ '...BBB____BBB...',
120
+ '...BBBBBBBBBB...',
121
+ '...BBBBBBBBBB...',
122
+ '...BBBB..BBBB...',
123
+ '....BB....BB....',
124
+ '................',
125
+ '................',
126
+ ],
127
+ };
128
+ /** The mark: the ghost at rest. */
129
+ export const GHOST = GHOST_POSES.idle;