@ascribed/elements 0.1.2-next.5 → 0.1.2-next.7

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/CONTRACT.md CHANGED
@@ -10,7 +10,7 @@ The site output (SPEC §9.4) is markdown plus custom elements. This contract is
10
10
  | `@available`, badge or filter | [`<ascribe-availability>`](#4-ascribe-availability-and-ascribe-availability-target) with `<ascribe-availability-target>` | CSS only |
11
11
  | `@details` | [`<details>`](#5-details) with `<summary>` | Optional CSS |
12
12
  | Project widget | [An element named after the widget](#6-project-widgets), and `<ascribe-group>` for groups | The project's own; `<ascribe-group>` is the library's |
13
- | Glossary term | [An ordinary link](#7-glossary-terms) | None |
13
+ | Glossary term | [An ordinary link](#7-glossary-terms), marked with `data-ascribe-term` | Optional CSS |
14
14
 
15
15
  A change to this contract changes the site emitter (`crates/tessera-emit`), the element library, and the site-render fixtures (`tests/render/`) together.
16
16
 
@@ -222,4 +222,16 @@ A wrapping widget follows §0's layout for elements that wrap markdown; an empty
222
222
 
223
223
  ## 7. Glossary terms
224
224
 
225
- There's no element for glossary terms. In the site output, an occurrence the glossary links (docs/content/contracts/content-model.md §13) is an ordinary markdown link to the term's `link` target, as a route, with the term's definition as the link title: `[API key](/docs/reference/glossary/#api-key "A secret token that authenticates the Quill agent.")`. Terms without a `link` stay plain text (content-model.md Q7).
225
+ There's no element for glossary terms. In the site output, an occurrence the glossary links (docs/content/contracts/content-model.md §13) is an ordinary markdown link to the term's `link` target, as a route, with the term's definition as the link title, followed directly by an attribute marker (docs/content/contracts/site-render.md §2.3) that gives the `<a>` a `data-ascribe-term` attribute holding the term's id:
226
+
227
+ ```markdown
228
+ [API key](/docs/reference/glossary/#api-key "A secret token that authenticates the Quill agent.")<ascribe-attributes data-ascribe-term="api-key"></ascribe-attributes>
229
+ ```
230
+
231
+ ```html
232
+ <a href="/docs/reference/glossary/#api-key" title="A secret token that authenticates the Quill agent." data-ascribe-term="api-key">API key</a>
233
+ ```
234
+
235
+ Terms without a `link` stay plain text (content-model.md Q7).
236
+
237
+ **Rendering:** a link, which the library's CSS underlines with dots (`a[data-ascribe-term]`). A site restyles it, or shows the definition as a popover, by selecting on the attribute.
package/README.md CHANGED
@@ -39,6 +39,37 @@ elements. Defaults are in `css/style.css`.
39
39
  | Tabs | `--ascribe-tab-color`, `--ascribe-tab-active-color`, `--ascribe-tab-focus-color`, `--ascribe-tab-hover-background` |
40
40
  | Availability | `--ascribe-state-color` and `--ascribe-state-background`, and `--ascribe-state-<state>-color` and `--ascribe-state-<state>-background` for `ga`, `preview`, `beta`, `deprecated`, and `removed` |
41
41
 
42
+ ### Light and dark
43
+
44
+ The default colors are light or dark as the page is. They're dark where the
45
+ page's `color-scheme` is `dark`, or `light dark` while the reader's system is in
46
+ dark mode, and light otherwise, including on a page that declares no
47
+ `color-scheme`. So a site with a dark mode gets dark elements by declaring it:
48
+
49
+ ```css
50
+ :root {
51
+ color-scheme: light dark;
52
+ }
53
+ ```
54
+
55
+ A page whose colors don't follow its `color-scheme` sets
56
+ `data-ascribe-scheme="light"` or `"dark"` on its root element, as the review
57
+ marks read it. The defaults use CSS `light-dark()`; a browser without it shows
58
+ the light colors. A property a site sets replaces both colors, so set it for
59
+ each scheme when you set one:
60
+
61
+ ```css
62
+ :root {
63
+ --ascribe-note-color: light-dark(#0550ae, #79c0ff);
64
+ }
65
+ ```
66
+
67
+ ### Glossary terms
68
+
69
+ A glossary link carries `data-ascribe-term` with the term's id, and its title
70
+ is the definition. The library underlines it with dots; restyle it by
71
+ selecting on the attribute, such as `a[data-ascribe-term]`.
72
+
42
73
  ### A project's own note types and lifecycle states
43
74
 
44
75
  Notes and availability targets carry their type or states as attributes, so a
package/css/style.css CHANGED
@@ -4,6 +4,12 @@
4
4
  * Everything here works without the script; only <ascribe-tabs> adds
5
5
  * behavior. Theme it by setting the --ascribe-* custom properties (listed in
6
6
  * README.md) on :root or any ancestor.
7
+ *
8
+ * The colors are light or dark as the page is: dark where the page's
9
+ * `color-scheme` is `dark`, or `light dark` with the reader's system in dark
10
+ * mode, and light otherwise, including on a page that declares no
11
+ * `color-scheme`. A page whose own colors don't follow its `color-scheme`
12
+ * sets `data-ascribe-scheme="light"` or `"dark"` on its root element.
7
13
  */
8
14
 
9
15
  :root {
@@ -62,6 +68,59 @@
62
68
  --ascribe-state-removed-background: #ffebe9;
63
69
  }
64
70
 
71
+ /* The same colors, light and dark. `light-dark()` picks by the element's
72
+ `color-scheme`, which it inherits from the page; an engine without
73
+ `light-dark()` keeps the light colors above. */
74
+ @supports (color: light-dark(#000, #fff)) {
75
+ :root {
76
+ --ascribe-border-color: light-dark(#d0d7de, #3d444d);
77
+ --ascribe-muted-color: light-dark(#57606a, #9198a1);
78
+
79
+ --ascribe-note-color: light-dark(#0969da, #4493f8);
80
+ --ascribe-note-background: light-dark(#ddf4ff, #121d2f);
81
+ --ascribe-tip-color: light-dark(#1a7f37, #3fb950);
82
+ --ascribe-tip-background: light-dark(#dafbe1, #12261e);
83
+ --ascribe-important-color: light-dark(#8250df, #ab7df8);
84
+ --ascribe-important-background: light-dark(#fbefff, #1f1a33);
85
+ --ascribe-warning-color: light-dark(#9a6700, #d29922);
86
+ --ascribe-warning-background: light-dark(#fff8c5, #272115);
87
+ --ascribe-caution-color: light-dark(#cf222e, #f85149);
88
+ --ascribe-caution-background: light-dark(#ffebe9, #2d1517);
89
+
90
+ --ascribe-steps-color: light-dark(#0969da, #4493f8);
91
+ --ascribe-steps-marker-text-color: light-dark(#ffffff, #0d1117);
92
+
93
+ --ascribe-tab-color: light-dark(#57606a, #9198a1);
94
+ --ascribe-tab-active-color: light-dark(#0969da, #4493f8);
95
+ --ascribe-tab-focus-color: light-dark(#0969da, #4493f8);
96
+ --ascribe-tab-hover-background: light-dark(#f6f8fa, #151b23);
97
+
98
+ --ascribe-state-color: light-dark(#57606a, #9198a1);
99
+ --ascribe-state-background: light-dark(#eaeef2, #212830);
100
+ --ascribe-state-ga-color: light-dark(#1a7f37, #3fb950);
101
+ --ascribe-state-ga-background: light-dark(#dafbe1, #12261e);
102
+ --ascribe-state-preview-color: light-dark(#8250df, #ab7df8);
103
+ --ascribe-state-preview-background: light-dark(#fbefff, #1f1a33);
104
+ --ascribe-state-beta-color: light-dark(#0969da, #4493f8);
105
+ --ascribe-state-beta-background: light-dark(#ddf4ff, #121d2f);
106
+ --ascribe-state-deprecated-color: light-dark(#9a6700, #d29922);
107
+ --ascribe-state-deprecated-background: light-dark(#fff8c5, #272115);
108
+ --ascribe-state-removed-color: light-dark(#cf222e, #f85149);
109
+ --ascribe-state-removed-background: light-dark(#ffebe9, #2d1517);
110
+ }
111
+
112
+ /* A page that says which it is. */
113
+ :root[data-ascribe-scheme="light"]
114
+ :is(ascribe-note, ascribe-steps, ascribe-tabs, ascribe-availability) {
115
+ color-scheme: light;
116
+ }
117
+
118
+ :root[data-ascribe-scheme="dark"]
119
+ :is(ascribe-note, ascribe-steps, ascribe-tabs, ascribe-availability) {
120
+ color-scheme: dark;
121
+ }
122
+ }
123
+
65
124
  /* <ascribe-note> ---------------------------------------------------------- */
66
125
 
67
126
  ascribe-note {
@@ -300,3 +359,11 @@ ascribe-availability-target[states$=" removed"] {
300
359
  ascribe-group {
301
360
  display: block;
302
361
  }
362
+
363
+ /* Glossary terms ---------------------------------------------------------- */
364
+
365
+ /* A link to a glossary term, whose title is the term's definition. */
366
+ a[data-ascribe-term] {
367
+ text-decoration-line: underline;
368
+ text-decoration-style: dotted;
369
+ }
package/dist/group.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"group.js","sourceRoot":"","sources":["../src/group.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,MAAM,OAAO,YAAa,SAAQ,WAAW;CAAG"}
1
+ {"version":3,"file":"group.js","sourceRoot":"","sources":["../src/group.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,MAAM,OAAO,YAAa,SAAQ,WAAW;CAAG","sourcesContent":["/** `<ascribe-group>` (CONTRACT.md §6): wraps a widget group's arms. No behavior. */\nexport class AscribeGroup extends HTMLElement {}\n"]}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,mEAAmE;AACnE,qEAAqE;AAErE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;AAEjD,MAAM,QAAQ,GAAyC;IACrD,CAAC,cAAc,EAAE,WAAW,CAAC;IAC7B,CAAC,aAAa,EAAE,UAAU,CAAC;IAC3B,CAAC,eAAe,EAAE,YAAY,CAAC;CAChC,CAAC;AAEF,KAAK,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,QAAQ,EAAE,CAAC;IAC3C,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,cAAc,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;AAC1E,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,mEAAmE;AACnE,qEAAqE;AAErE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;AAEjD,MAAM,QAAQ,GAAyC;IACrD,CAAC,cAAc,EAAE,WAAW,CAAC;IAC7B,CAAC,aAAa,EAAE,UAAU,CAAC;IAC3B,CAAC,eAAe,EAAE,YAAY,CAAC;CAChC,CAAC;AAEF,KAAK,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,QAAQ,EAAE,CAAC;IAC3C,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,cAAc,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;AAC1E,CAAC","sourcesContent":["// @ascribed/elements: registers Ascribe's custom elements. Only\n// <ascribe-tabs> has behavior; the rest are styled by the CSS file\n// (`@ascribed/elements/style.css`), which works without this script.\n\nimport { AscribeGroup } from \"./group.js\";\nimport { AscribeTab, AscribeTabs } from \"./tabs.js\";\n\nexport { AscribeGroup, AscribeTab, AscribeTabs };\n\nconst registry: [string, CustomElementConstructor][] = [\n [\"ascribe-tabs\", AscribeTabs],\n [\"ascribe-tab\", AscribeTab],\n [\"ascribe-group\", AscribeGroup],\n];\n\nfor (const [name, constructor] of registry) {\n if (!customElements.get(name)) customElements.define(name, constructor);\n}\n"]}
package/dist/tabs.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"tabs.js","sourceRoot":"","sources":["../src/tabs.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,4EAA4E;AAC5E,wEAAwE;AACxE,WAAW;AAEX,MAAM,cAAc,GAAG,eAAe,CAAC;AAEvC,6EAA6E;AAC7E,MAAM,WAAW,GAAG,IAAI,GAAG,EAAkB,CAAC;AAE9C,kEAAkE;AAClE,MAAM,YAAY,GAAG,IAAI,GAAG,EAAe,CAAC;AAE5C,IAAI,SAAS,GAAG,CAAC,CAAC;AAElB,SAAS,UAAU,CAAC,SAAiB;IACnC,uEAAuE;IACvE,8BAA8B;IAC9B,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC1C,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC;IACxC,IAAI,CAAC;QACH,OAAO,YAAY,CAAC,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CAAC;IAC1D,CAAC;IAAC,MAAM,CAAC;QACP,yCAAyC;QACzC,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAA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QAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;QACnC,IAAI,IAAY,CAAC;QACjB,QAAQ,KAAK,CAAC,GAAG,EAAE,CAAC;YAClB,KAAK,YAAY;gBACf,IAAI,GAAG,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;gBACxD,MAAM;YACR,KAAK,WAAW;gBACd,IAAI,GAAG,IAAI,CAAC,SAAS,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;gBACxD,MAAM;YACR,KAAK,MAAM;gBACT,IAAI,GAAG,CAAC,CAAC;gBACT,MAAM;YACR,KAAK,KAAK;gBACR,IAAI,GAAG,IAAI,CAAC;gBACZ,MAAM;YACR;gBACE,OAAO;QACX,CAAC;QACD,KAAK,CAAC,cAAc,EAAE,CAAC;QACvB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACnB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC;IAC/B,CAAC;CACF","sourcesContent":["// <ascribe-tabs> and <ascribe-tab> (CONTRACT.md §3): the library's only\n// element with behavior. Without this script every tab shows with its label\n// (CSS generated content); with it, the group follows the WAI-ARIA tabs\n// pattern.\n\nconst STORAGE_PREFIX = \"ascribe-tabs:\";\n\n/** Choices made this page load, for readers whose storage is unavailable. */\nconst pageChoices = new Map<string, string>();\n\n/** Every connected, initialized group with a `sync` attribute. */\nconst syncedGroups = new Set<AscribeTabs>();\n\nlet idCounter = 0;\n\nfunction readChoice(dimension: string): string | null {\n // This page's choices are always at least as fresh as storage, which a\n // failed write leaves behind.\n const chosen = pageChoices.get(dimension);\n if (chosen !== undefined) return chosen;\n try {\n return localStorage.getItem(STORAGE_PREFIX + dimension);\n } catch {\n // Storage can be blocked or unavailable.\n return null;\n }\n}\n\nfunction writeChoice(dimension: string, value: string): void {\n pageChoices.set(dimension, value);\n try {\n localStorage.setItem(STORAGE_PREFIX + dimension, value);\n } catch {\n // The choice lasts for the page only.\n }\n}\n\nfunction valuesOf(tab: Element): string[] {\n return (tab.getAttribute(\"value\") ?? \"\").split(/\\s+/).filter(Boolean);\n}\n\n/** A tab panel: one arm of a `@variant` group. Styled by CSS; no behavior. */\nexport class AscribeTab extends HTMLElement {}\n\nexport class AscribeTabs extends HTMLElement {\n #tablist: HTMLElement | null = null;\n #tabs: HTMLElement[] = [];\n #buttons: HTMLButtonElement[] = [];\n #selected = 0;\n #ready = false;\n\n connectedCallback(): void {\n // A parser-created element is connected before its children are parsed.\n if (document.readyState === \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", () => this.#setup(), { once: true });\n } else {\n this.#setup();\n }\n }\n\n disconnectedCallback(): void {\n this.#teardown();\n }\n\n #setup(): void {\n if (!this.isConnected || this.#ready) return;\n this.#tabs = Array.from(this.children).filter(\n (child): child is HTMLElement => child.localName === \"ascribe-tab\",\n );\n if (this.#tabs.length === 0) return;\n this.#ready = true;\n\n const tablist = document.createElement(\"div\");\n tablist.setAttribute(\"role\", \"tablist\");\n this.#tablist = tablist;\n\n this.#buttons = this.#tabs.map((tab) => {\n if (!tab.id) tab.id = `ascribe-tab-${++idCounter}`;\n const button = document.createElement(\"button\");\n button.type = \"button\";\n button.id = `${tab.id}-button`;\n button.setAttribute(\"role\", \"tab\");\n button.setAttribute(\"aria-controls\", tab.id);\n button.textContent = tab.getAttribute(\"label\") ?? \"\";\n button.addEventListener(\"click\", () => this.#choose(this.#buttons.indexOf(button)));\n button.addEventListener(\"keydown\", (event) => this.#onKeydown(event));\n tablist.append(button);\n tab.setAttribute(\"role\", \"tabpanel\");\n tab.setAttribute(\"aria-labelledby\", button.id);\n return button;\n });\n this.prepend(tablist);\n\n const sync = this.getAttribute(\"sync\");\n let initial = 0;\n if (sync !== null) {\n syncedGroups.add(this);\n const remembered = readChoice(sync);\n const match = remembered === null ? -1 : this.#indexOfValue(remembered);\n if (match >= 0) initial = match;\n }\n this.#select(initial);\n }\n\n #teardown(): void {\n if (!this.#ready) return;\n syncedGroups.delete(this);\n this.#tablist?.remove();\n for (const tab of this.#tabs) {\n tab.removeAttribute(\"role\");\n tab.removeAttribute(\"aria-labelledby\");\n tab.removeAttribute(\"hidden\");\n }\n this.#tablist = null;\n this.#tabs = [];\n this.#buttons = [];\n this.#ready = false;\n }\n\n #indexOfValue(value: string): number {\n return this.#tabs.findIndex((tab) => valuesOf(tab).includes(value));\n }\n\n /** Select a tab without recording or syncing the choice. */\n #select(index: number): void {\n this.#selected = index;\n this.#tabs.forEach((tab, i) => {\n tab.toggleAttribute(\"hidden\", i !== index);\n });\n this.#buttons.forEach((button, i) => {\n button.setAttribute(\"aria-selected\", String(i === index));\n button.tabIndex = i === index ? 0 : -1;\n });\n }\n\n /** The reader picked a tab: select it and, for a synced group, tell the rest. */\n #choose(index: number): void {\n this.#select(index);\n const sync = this.getAttribute(\"sync\");\n const tab = this.#tabs[index];\n const choice = tab ? valuesOf(tab)[0] : undefined;\n if (sync === null || choice === undefined) return;\n writeChoice(sync, choice);\n for (const group of syncedGroups) {\n if (group !== this && group.getAttribute(\"sync\") === sync) group.#follow(choice);\n }\n }\n\n /** Another group with the same `sync` made a choice; keep our selection if we have no match. */\n #follow(value: string): void {\n const index = this.#indexOfValue(value);\n if (index >= 0) this.#select(index);\n }\n\n #onKeydown(event: KeyboardEvent): void {\n const last = this.#tabs.length - 1;\n let next: number;\n switch (event.key) {\n case \"ArrowRight\":\n next = this.#selected === last ? 0 : this.#selected + 1;\n break;\n case \"ArrowLeft\":\n next = this.#selected === 0 ? last : this.#selected - 1;\n break;\n case \"Home\":\n next = 0;\n break;\n case \"End\":\n next = last;\n break;\n default:\n return;\n }\n event.preventDefault();\n this.#choose(next);\n this.#buttons[next]?.focus();\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ascribed/elements",
3
- "version": "0.1.2-next.5",
3
+ "version": "0.1.2-next.7",
4
4
  "description": "Ascribe's web component library for the site output.",
5
5
  "type": "module",
6
6
  "license": "MPL-2.0",
@@ -36,7 +36,7 @@
36
36
  "publishConfig": {
37
37
  "access": "public"
38
38
  },
39
- "gitHead": "dda2215605bc8df46005f8b12efccd406269f994",
39
+ "gitHead": "0bd81c5fbd7e4fb79f501cb86a7b93beb3e1b421",
40
40
  "scripts": {
41
41
  "build": "tsc -p tsconfig.build.json",
42
42
  "typecheck": "tsc --noEmit",