discord-transcript-ui 1.0.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/ATTRIBUTION.md ADDED
@@ -0,0 +1,43 @@
1
+ # Attribution
2
+
3
+ This library is an independent, from-scratch implementation. It is **not** a fork of
4
+ any existing package, but its HTML vocabulary is deliberately compatible with
5
+ [`@skyra/discord-components-core`](https://github.com/skyra-project/discord-components)
6
+ (MIT), which this project's tag names and attribute names follow so that existing
7
+ knowledge, examples, and documentation transfer, and so a future parser can target a
8
+ familiar surface.
9
+
10
+ The following were informed by that upstream project:
11
+
12
+ - the set of custom element names (`discord-messages`, `discord-message`, `discord-embed`, …);
13
+ - attribute naming conventions (for example `author`, `avatar`, `role-color`, `compact-mode`);
14
+ - the general geometry of Discord's chat UI, used as a reference while hand-writing the stylesheet.
15
+
16
+ Upstream licence notice, reproduced as required:
17
+
18
+ ```
19
+ MIT License
20
+
21
+ Copyright (c) 2021 Skyra
22
+
23
+ Permission is hereby granted, free of charge, to any person obtaining a copy
24
+ of this software and associated documentation files (the "Software"), to deal
25
+ in the Software without restriction, including without limitation the rights
26
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27
+ copies of the Software, and to permit persons to whom the Software is
28
+ furnished to do so, subject to the following conditions:
29
+
30
+ The above copyright notice and this permission notice shall be included in all
31
+ copies or substantial portions of the Software.
32
+
33
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39
+ SOFTWARE.
40
+ ```
41
+
42
+ No source code or stylesheet text is copied from that project. Discord is a trademark
43
+ of Discord Inc.; this project is unaffiliated with Discord and with Skyra.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 <copyright holder>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,125 @@
1
+ # discord-transcript-ui
2
+
3
+ **Rendering Discord transcripts from a single stylesheet and one optional script — no
4
+ Shadow DOM, no framework, no build step for the people viewing them.**
5
+
6
+ The point is storage. Inlining Discord's styles and components into every exported
7
+ transcript makes each file large and every file pay for the same bytes. Here the styling
8
+ lives in one CSS file and the behaviour in one small script, both cached by the browser
9
+ across *all* transcripts, and both loadable from several CDNs with a fallback chain.
10
+
11
+ | Artifact | Raw | gzip | brotli |
12
+ | --- | --- | --- | --- |
13
+ | `discord-transcript.min.css` | 32.5 KB | **6.1 KB** | 5.4 KB |
14
+ | `discord-transcript.min.js` (optional) | 14.9 KB | **4.8 KB** | 4.2 KB |
15
+
16
+ A transcript HTML file then contains only its own text and markup.
17
+
18
+ ## Quick start
19
+
20
+ ```html
21
+ <!doctype html>
22
+ <html lang="en">
23
+ <head>
24
+ <meta charset="utf-8" />
25
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/discord-transcript-ui@1.0.0/dist/discord-transcript.min.css" />
26
+ <script>
27
+ window.$discordMessage = {
28
+ profiles: {
29
+ skyra: { author: 'Skyra', avatar: '…', roleColor: '#5865f2', bot: true, verified: true }
30
+ }
31
+ };
32
+ </script>
33
+ <script src="https://cdn.jsdelivr.net/npm/discord-transcript-ui@1.0.0/dist/discord-transcript.min.js" defer></script>
34
+ </head>
35
+ <body class="dt-page">
36
+ <div class="dt-page__inner">
37
+ <discord-messages channel-name="general" channel-type="text">
38
+ <discord-message profile="skyra" timestamp="2024-03-15T14:31:00Z">
39
+ Hello, <discord-mention>Alyx</discord-mention>!
40
+ </discord-message>
41
+ </discord-messages>
42
+ </div>
43
+ </body>
44
+ </html>
45
+ ```
46
+
47
+ For a real transcript, generate the file with the multi-mirror bootstrap instead of a
48
+ single link tag:
49
+
50
+ ```bash
51
+ npm run build
52
+ node tools/scaffold.mjs --body examples/messages.html \
53
+ --config examples/config.js --out transcript.html --title "general — 2024-03-15"
54
+ ```
55
+
56
+ That writes the recovery comment, the profile config and the fallback chain for you.
57
+ Open `demo/index.html` for a full gallery of every supported component, and
58
+ `demo/no-js.html` to see exactly what survives without the script.
59
+
60
+ ## What it renders
61
+
62
+ Messages and continuation rows · author info with bot/verified/server/OP badges · replies ·
63
+ mentions with `@`/`#` · timestamps (`t T d D f F R s S`) · spoilers · embeds with fields,
64
+ footer, thumbnail and media · image, video, audio and file attachments · reactions ·
65
+ system messages · threads · slash-command lines · buttons and action rows · headings,
66
+ bold/italic/underline/strikethrough, inline and block code, quotes, lists and links.
67
+
68
+ Everything degrades: without the script, author names come from `attr(author)`, mentions
69
+ add their own `@`/`#`, reactions show emoji + count, file cards render from attributes, and
70
+ any nested `<img>`/`<video>`/`<audio>` still plays. See the table in `docs/SPEC.md §10`.
71
+
72
+ ## Project layout
73
+
74
+ ```
75
+ src/discord-transcript.css the single stylesheet (hand-written, flattened, themed with --dt-* tokens)
76
+ src/discord-transcript.js the optional enhancement layer (vanilla, ~5 KB gzip)
77
+ build/build.mjs minify + sha256/SRI manifest + dist/v<version>/ copies
78
+ build/verify.mjs headless-Chrome assertions over computed styles and layout
79
+ build/serve.mjs tiny static server for previewing the demo
80
+ tools/scaffold.mjs fragment + config -> finished CDN transcript
81
+ assets/cdn-loader.html the multi-mirror bootstrap that goes into transcripts
82
+ demo/ component gallery, and a no-script degradation page
83
+ examples/ a body fragment, a config, and a generated transcript
84
+ docs/SPEC.md the markup contract your parser is built against
85
+ docs/CDN-STRATEGY.md keeping archived transcripts alive for 5-10 years
86
+ docs/DESIGN-TOKENS.md Discord's live design tokens, with sources and open questions
87
+ ```
88
+
89
+ ## Scripts
90
+
91
+ | Command | Does |
92
+ | --- | --- |
93
+ | `npm run build` | Writes `dist/` (minified, unminified, versioned copies, `manifest.json`, recovery comment) and prints sizes. |
94
+ | `npm run build:check` | Fails if `dist/` does not match `src/` — put this in CI. |
95
+ | `npm run verify` | Launches headless Chrome and asserts computed styles on the enhanced page, the no-script page and the bootstrap page. |
96
+ | `npm run scaffold -- --body … --out …` | Generates a finished transcript file. |
97
+ | `npm run serve` | Serves the repo at `http://127.0.0.1:8080/demo/`. |
98
+
99
+ ## Design notes
100
+
101
+ * **Light DOM only.** A CDN stylesheet cannot reach into Shadow DOM, so components are
102
+ plain custom elements styled globally. That is also why there is no `::part()`.
103
+ * **Content belongs in markup, chrome in attributes.** Attributes are for things the script
104
+ can reconstruct (avatars from a profile, formatted dates); text, descriptions, fields and
105
+ media stay as real HTML so they survive a broken CDN.
106
+ * **Theming is data.** Every colour, size and font is a `--dt-*` custom property; override
107
+ them on `:root`, on `<discord-messages>`, or per element. Values follow Discord's current
108
+ "visual refresh" palette (`docs/DESIGN-TOKENS.md`).
109
+ * **Tag names match `@skyra/discord-components-core`** where it makes sense, so existing
110
+ knowledge transfers — but this is an independent light-DOM implementation, not a fork.
111
+ The differences are listed in `docs/SPEC.md §12`.
112
+
113
+ ## Publishing your own copy
114
+
115
+ The package name, repository and CDN list live in `lib.config.json`. Change them **before
116
+ the first release** (after that the URLs are frozen into archived transcripts), then follow
117
+ `docs/CDN-STRATEGY.md §6`. The build emits byte-identical copies under `dist/v<version>/`
118
+ for tag-based hosts and computes SRI hashes for every artifact.
119
+
120
+ ## Licence
121
+
122
+ MIT. Tag names and attribute conventions follow
123
+ [`@skyra/discord-components`](https://github.com/skyra-project/discord-components) (MIT);
124
+ no code or stylesheet text is copied from it. See `ATTRIBUTION.md`. Discord is a trademark
125
+ of Discord Inc.; this project is unaffiliated with Discord and with Skyra.