starlight-annotations 0.1.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.
package/README.md CHANGED
@@ -1,16 +1,24 @@
1
- # starlight-annotations
1
+ # ๐Ÿ–๏ธ starlight-annotations
2
+
3
+ [![npm](https://img.shields.io/npm/v/starlight-annotations?color=blue)](https://www.npmjs.com/package/starlight-annotations)
4
+ [![CI](https://github.com/alessandroros/starlight-annotations/actions/workflows/ci.yml/badge.svg)](https://github.com/alessandroros/starlight-annotations/actions/workflows/ci.yml)
5
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green)](https://github.com/alessandroros/starlight-annotations/blob/main/LICENSE)
6
+ [![Starlight plugin](https://img.shields.io/badge/Starlight-plugin-8a55f6)](https://starlight.astro.build/resources/plugins/)
2
7
 
3
8
  Let readers highlight text and leave notes on your [Starlight](https://starlight.astro.build) docs. Notes are JSON files committed to your Git repository, not stored by a third-party service.
4
9
 
5
- - **Select, note, discuss.** Markdown notes with a formatting toolbar, replies, "in reply to" references, resolve and reopen.
6
- - **Anchored to the text.** W3C Web Annotation selectors: notes find their place again after edits, and long passages are stored by their start and end.
7
- - **Your repo, your data.** One file per page on a branch of its own; every note is a commit by its author.
8
- - **Runs anywhere.** The API is one Web-standard handler for Cloudflare Workers, Netlify, Vercel, Deno or Node. Or keep personal notes in the browser, with no server.
9
- - **No DOM rewriting.** Highlights use the CSS Custom Highlight API, so Mermaid, Expressive Code and other plugins are untouched.
10
+ **๐Ÿ“– [Documentation](https://alessandroros.github.io/starlight-annotations/) ยท โœจ [Live demo](https://alessandroros.github.io/starlight-annotations/guides/demo/)**
11
+
12
+ ## Features
10
13
 
11
- **[Documentation and live demo](https://alessandroros.github.io/starlight-annotations/)**
14
+ - ๐Ÿ’ฌ **Select, note, discuss.** Markdown notes with a formatting toolbar, replies, "in reply to" references, resolve and reopen.
15
+ - ๐Ÿ“Œ **Anchored to the text.** W3C Web Annotation selectors: notes find their place again after edits, and long passages are stored by their start and end.
16
+ - ๐Ÿ—‚๏ธ **Your repo, your data.** One file per page on a branch of its own; every note is a commit by its author.
17
+ - ๐ŸŒ **Runs anywhere.** The API is one Web-standard handler for Cloudflare Workers, Netlify, Vercel, Deno or Node. Or keep personal notes in the browser, with no server.
18
+ - ๐Ÿชถ **Light and safe.** Highlights use the CSS Custom Highlight API, so the page markup is never rewritten. Notes cannot inject HTML, and the Markdown parser loads only when it is needed.
19
+ - ๐ŸŒ **Multilingual.** English, Italian, German, French and Spanish built in; the UI follows the page language.
12
20
 
13
- ## Quick start
21
+ ## ๐Ÿš€ Quick start
14
22
 
15
23
  ```sh
16
24
  npm install starlight-annotations
@@ -34,7 +42,9 @@ export default defineConfig({
34
42
 
35
43
  Run `npm run dev`, select text on any page and press **Annotate**. During development notes are written to `.annotations/` in your project.
36
44
 
37
- For the published site, mount the handler next to your pages, for example on a Cloudflare Worker:
45
+ ## โ˜๏ธ Publish
46
+
47
+ Mount the handler next to your pages, for example on a Cloudflare Worker:
38
48
 
39
49
  ```js
40
50
  import { createAnnotationsHandler, github } from 'starlight-annotations/server';
@@ -59,6 +69,6 @@ See [Store notes on GitHub](https://alessandroros.github.io/starlight-annotation
59
69
 
60
70
  No server? `starlightAnnotations({ backend: 'browser' })` keeps notes in each reader's browser.
61
71
 
62
- ## License
72
+ ## ๐Ÿ“„ License
63
73
 
64
- MIT
74
+ MIT ยฉ Alessandro Rosa
package/index.js CHANGED
@@ -14,7 +14,10 @@ export default function starlightAnnotations(options = {}) {
14
14
  return {
15
15
  name: 'starlight-annotations',
16
16
  hooks: {
17
- 'config:setup'({ addIntegration }) {
17
+ 'config:setup'({ addIntegration, config: starlightConfig, updateConfig }) {
18
+ // Starlight links customCss on every page, in dev and in the build.
19
+ // (CSS imported by an injected script is bundled but not linked.)
20
+ updateConfig({ customCss: [...(starlightConfig.customCss ?? []), 'starlight-annotations/styles.css'] });
18
21
  addIntegration(annotationsIntegration(config));
19
22
  },
20
23
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "starlight-annotations",
3
- "version": "0.1.0",
4
- "description": "Let readers highlight text and leave notes on Starlight docs. Notes are JSON files committed to your Git repository.",
3
+ "version": "0.1.1",
4
+ "description": "๐Ÿ–๏ธ Let readers highlight text and leave notes on Starlight docs. Notes are committed to your Git repository.",
5
5
  "license": "MIT",
6
6
  "author": "Alessandro Rosa",
7
7
  "type": "module",
@@ -10,7 +10,7 @@
10
10
  "url": "git+https://github.com/alessandroros/starlight-annotations.git",
11
11
  "directory": "packages/starlight-annotations"
12
12
  },
13
- "homepage": "https://github.com/alessandroros/starlight-annotations",
13
+ "homepage": "https://alessandroros.github.io/starlight-annotations/",
14
14
  "bugs": "https://github.com/alessandroros/starlight-annotations/issues",
15
15
  "keywords": [
16
16
  "withastro",
@@ -20,7 +20,11 @@
20
20
  "annotations",
21
21
  "comments",
22
22
  "documentation",
23
- "web-annotation"
23
+ "web-annotation",
24
+ "highlight",
25
+ "notes",
26
+ "feedback",
27
+ "docs-review"
24
28
  ],
25
29
  "exports": {
26
30
  ".": {
@@ -36,6 +40,7 @@
36
40
  "default": "./src/server/node.js"
37
41
  },
38
42
  "./client": "./src/client/annotations.js",
43
+ "./styles.css": "./src/client/styles.css",
39
44
  "./package.json": "./package.json"
40
45
  },
41
46
  "files": [
@@ -6,12 +6,9 @@
6
6
  // Notes are written in Markdown (GitHub flavour) and stored as typed.
7
7
  // micromark escapes raw HTML and drops javascript: links by default, so a
8
8
  // note cannot inject markup into the page.
9
- import { micromark } from 'micromark';
10
- import { gfm, gfmHtml } from 'micromark-extension-gfm';
11
9
  import config from 'virtual:starlight-annotations/config';
12
10
  import { createBackend } from './backend.js';
13
11
  import { strings } from './i18n.js';
14
- import './styles.css';
15
12
 
16
13
  const BASE = import.meta.env.BASE_URL.replace(/\/$/, '');
17
14
  // Text the reader does not see as content: diagrams (rendered late), heading
@@ -26,8 +23,35 @@ const mod = mac ? 'โŒ˜' : 'Ctrl+';
26
23
 
27
24
  // ---- Markdown ----
28
25
 
26
+ // The Markdown parser is most of the client's weight, so it loads on demand:
27
+ // when the page has notes, or when the reader starts to write one. Until it
28
+ // arrives a note shows as plain text, then it is filled in.
29
+ let markdown = null;
30
+ let markdownLoading = null;
31
+ const waitingForMarkdown = new Map(); // element -> source
32
+
33
+ function loadMarkdown() {
34
+ markdownLoading ??= Promise.all([import('micromark'), import('micromark-extension-gfm')]).then(([{ micromark }, { gfm, gfmHtml }]) => {
35
+ markdown = (source) => micromark(source, { extensions: [gfm()], htmlExtensions: [gfmHtml()] });
36
+ for (const [target, source] of waitingForMarkdown) if (target.isConnected) renderMarkdown(target, source);
37
+ waitingForMarkdown.clear();
38
+ }).catch(() => {
39
+ // Offline or blocked: notes stay as plain text, and the next note retries.
40
+ markdownLoading = null;
41
+ });
42
+ return markdownLoading;
43
+ }
44
+
29
45
  function renderMarkdown(target, source) {
30
- target.innerHTML = micromark(source, { extensions: [gfm()], htmlExtensions: [gfmHtml()] });
46
+ if (!markdown) {
47
+ target.textContent = source;
48
+ target.classList.add('annot-md-pending');
49
+ waitingForMarkdown.set(target, source);
50
+ loadMarkdown();
51
+ return target;
52
+ }
53
+ target.classList.remove('annot-md-pending');
54
+ target.innerHTML = markdown(source);
31
55
  for (const link of target.querySelectorAll('a[href]')) {
32
56
  // micromark empties unsafe URLs (javascript: and the like): show plain text.
33
57
  if (!link.getAttribute('href')) {
@@ -654,6 +678,7 @@ async function start(root) {
654
678
 
655
679
  function compose() {
656
680
  if (!selected) return;
681
+ loadMarkdown();
657
682
  state.pending = selected.selector;
658
683
  selectButton.hidden = true;
659
684
  window.getSelection()?.removeAllRanges();
@@ -172,6 +172,9 @@
172
172
  .annot-text {
173
173
  overflow-wrap: anywhere;
174
174
  }
175
+ .annot-md-pending {
176
+ white-space: pre-wrap;
177
+ }
175
178
 
176
179
  /* Markdown inside notes and the preview: compact, sized for the panel. */
177
180
  .annot-md > :first-child {