@chromamark/renderer 0.1.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/LICENSE.md ADDED
@@ -0,0 +1,15 @@
1
+ Copyright 2026 CJ Fravel
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ 1. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ 2. **SaaS Provision**: If you use this software to provide a Software-as-a-Service (SaaS) offering, you must provide access to the source code of the modified version of the Software that you are using in your service, under the terms of this license. The access must be provided within a reasonable time, but no later than 30 days, and the access method should be publicly documented.
8
+
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10
+
11
+ ---
12
+
13
+ ## Third-party components
14
+
15
+ The published browser bundles in `dist/` embed [markdown-it](https://github.com/markdown-it/markdown-it), which is licensed under the [MIT License](https://github.com/markdown-it/markdown-it/blob/master/LICENSE).
package/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # @chromamark/renderer
2
+
3
+ The ChromaMark renderer — a [`markdown-it`](https://github.com/markdown-it/markdown-it)
4
+ plugin that adds colored blocks, colored pills, collapsible sections, fields,
5
+ meters, and inline diff on top of CommonMark + GFM. Ships a browser bundle and a
6
+ theme stylesheet.
7
+
8
+ See the [ChromaMark spec](../../SPEC.md) for the full format.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install @chromamark/renderer
14
+ ```
15
+
16
+ ## Node / bundler API
17
+
18
+ ```js
19
+ import chromamark, { render, createRenderer } from '@chromamark/renderer';
20
+ ```
21
+
22
+ | Export | Description |
23
+ | ------------------------- | ----------------------------------------------------------------- |
24
+ | `default` (`chromamark`) | markdown-it plugin: `new MarkdownIt().use(chromamark, options?)`. |
25
+ | `render(src, options?)` | Convenience: ChromaMark string → HTML fragment. |
26
+ | `createRenderer(options?)`| A `markdown-it` instance preconfigured with ChromaMark. |
27
+
28
+ ### Options
29
+
30
+ All features are on by default; pass `false` to disable any of them:
31
+
32
+ ```js
33
+ createRenderer({
34
+ container: true, // ::: colored callouts
35
+ details: true, // ::: details collapsibles
36
+ fields: true, // ::: fields key/value lists
37
+ pill: true, // [!…] badges
38
+ text: true, // [.…] colored text
39
+ meter: true, // [=…] progress meters
40
+ critic: true, // {++…++} CriticMarkup diff
41
+ });
42
+ ```
43
+
44
+ ## Browser API
45
+
46
+ The bundle in `dist/` embeds the parser **and** theme. Load it from a CDN:
47
+
48
+ ```html
49
+ <!-- minified global build (window.ChromaMark) -->
50
+ <script src="https://cdn.jsdelivr.net/gh/cjfravel-dev/ChromaMark/packages/renderer/dist/chromamark.min.js"
51
+ data-chromamark-auto></script>
52
+ ```
53
+
54
+ Or import the ES module:
55
+
56
+ ```js
57
+ import ChromaMark from '@chromamark/renderer/browser';
58
+ ChromaMark.autoRender();
59
+ ```
60
+
61
+ | Method | Description |
62
+ | ------------------------------ | ---------------------------------------------------------------------- |
63
+ | `autoRender(options?)` | Inject the theme, then render every target on the page. |
64
+ | `renderElement(target, opts?)` | Render one element (selector or node) in place / as a sibling. |
65
+ | `renderAll(selector?, opts?)` | Render all matching elements. |
66
+ | `injectTheme(doc?)` | Add the theme `<style>` once (idempotent). |
67
+ | `render(src, opts?)` | ChromaMark string → HTML. |
68
+ | `theme` | The theme CSS as a string. |
69
+
70
+ Targets default to `<script type="text/chromamark">`, `template.chromamark`,
71
+ `.chromamark`, and `[data-chromamark]`. Adding `data-chromamark-auto` to the
72
+ loading `<script>` runs `autoRender()` automatically once the DOM is ready.
73
+
74
+ ## Theme
75
+
76
+ The stylesheet is available standalone for cases where you render server-side and
77
+ want to ship the CSS via a `<link>`:
78
+
79
+ ```js
80
+ import '@chromamark/renderer/theme.css';
81
+ ```
82
+
83
+ ```html
84
+ <link rel="stylesheet"
85
+ href="https://cdn.jsdelivr.net/gh/cjfravel-dev/ChromaMark/packages/renderer/dist/chromamark.css">
86
+ ```
87
+
88
+ Tones map to CSS custom properties (`--cm-success-fg`, …) and respond to
89
+ `prefers-color-scheme` or an explicit `data-theme="dark"` / `"light"` on a
90
+ container.
91
+
92
+ ## Scripts
93
+
94
+ ```bash
95
+ npm test # node:test suite
96
+ npm run build # esbuild → dist/chromamark.esm.js, dist/chromamark.min.js, dist/chromamark.css
97
+ ```
98
+
99
+ ## License
100
+
101
+ Modified MIT License with a SaaS source-availability provision — see [LICENSE.md](./LICENSE.md).
@@ -0,0 +1,113 @@
1
+ /*
2
+ * ChromaMark theme — maps semantic tones to real colors and styles every
3
+ * rendered construct. Tones are theme-owned: switch light/dark and colors
4
+ * follow. Load alongside HTML produced by @chromamark/renderer.
5
+ *
6
+ * Theme resolution order: explicit [data-theme] wins; otherwise the reader's
7
+ * prefers-color-scheme is honored.
8
+ */
9
+
10
+ :root {
11
+ --cm-success-fg:#1a7f37; --cm-success-bg:#dafbe1; --cm-success-bd:#2da44e;
12
+ --cm-danger-fg:#cf222e; --cm-danger-bg:#ffebe9; --cm-danger-bd:#ff8182;
13
+ --cm-warning-fg:#9a6700; --cm-warning-bg:#fff8c5; --cm-warning-bd:#d4a72c;
14
+ --cm-info-fg:#0969da; --cm-info-bg:#ddf4ff; --cm-info-bd:#54aeff;
15
+ --cm-tip-fg:#0f7b6c; --cm-tip-bg:#d3f5f0; --cm-tip-bd:#3bc4b0;
16
+ --cm-muted-fg:#656d76; --cm-muted-bg:#f6f8fa; --cm-muted-bd:#d0d7de;
17
+ --cm-neutral-bg:#f6f8fa; --cm-neutral-bd:#d0d7de;
18
+ }
19
+
20
+ @media (prefers-color-scheme: dark) {
21
+ :root:not([data-theme="light"]) {
22
+ --cm-success-fg:#3fb950; --cm-success-bg:#12261e; --cm-success-bd:#238636;
23
+ --cm-danger-fg:#f85149; --cm-danger-bg:#25171c; --cm-danger-bd:#da3633;
24
+ --cm-warning-fg:#d29922; --cm-warning-bg:#272115; --cm-warning-bd:#9e6a03;
25
+ --cm-info-fg:#58a6ff; --cm-info-bg:#0d2233; --cm-info-bd:#1f6feb;
26
+ --cm-tip-fg:#56d4c3; --cm-tip-bg:#0c2620; --cm-tip-bd:#1c6f63;
27
+ --cm-muted-fg:#8b949e; --cm-muted-bg:#161b22; --cm-muted-bd:#30363d;
28
+ --cm-neutral-bg:#161b22; --cm-neutral-bd:#30363d;
29
+ }
30
+ }
31
+
32
+ [data-theme="dark"] {
33
+ --cm-success-fg:#3fb950; --cm-success-bg:#12261e; --cm-success-bd:#238636;
34
+ --cm-danger-fg:#f85149; --cm-danger-bg:#25171c; --cm-danger-bd:#da3633;
35
+ --cm-warning-fg:#d29922; --cm-warning-bg:#272115; --cm-warning-bd:#9e6a03;
36
+ --cm-info-fg:#58a6ff; --cm-info-bg:#0d2233; --cm-info-bd:#1f6feb;
37
+ --cm-tip-fg:#56d4c3; --cm-tip-bg:#0c2620; --cm-tip-bd:#1c6f63;
38
+ --cm-muted-fg:#8b949e; --cm-muted-bg:#161b22; --cm-muted-bd:#30363d;
39
+ --cm-neutral-bg:#161b22; --cm-neutral-bd:#30363d;
40
+ }
41
+
42
+ /* Map a tone onto the generic --fg/--bg/--bd consumed by every component. */
43
+ [data-tone="success"]{--fg:var(--cm-success-fg);--bg:var(--cm-success-bg);--bd:var(--cm-success-bd);}
44
+ [data-tone="danger"] {--fg:var(--cm-danger-fg); --bg:var(--cm-danger-bg); --bd:var(--cm-danger-bd);}
45
+ [data-tone="warning"]{--fg:var(--cm-warning-fg);--bg:var(--cm-warning-bg);--bd:var(--cm-warning-bd);}
46
+ [data-tone="info"] {--fg:var(--cm-info-fg); --bg:var(--cm-info-bg); --bd:var(--cm-info-bd);}
47
+ [data-tone="tip"] {--fg:var(--cm-tip-fg); --bg:var(--cm-tip-bg); --bd:var(--cm-tip-bd);}
48
+ [data-tone="muted"] {--fg:var(--cm-muted-fg); --bg:var(--cm-muted-bg); --bd:var(--cm-muted-bd);}
49
+
50
+ /* Custom color (color=…): derive a tinted bg/border from the chosen --fg. */
51
+ .cm-custom {
52
+ --bg:color-mix(in srgb, var(--fg) 12%, transparent);
53
+ --bd:color-mix(in srgb, var(--fg) 45%, transparent);
54
+ }
55
+
56
+ /* ---- Colored block / callout ---- */
57
+ .cm-block {
58
+ border:1px solid var(--bd, var(--cm-neutral-bd)); border-left-width:4px;
59
+ background:var(--bg, var(--cm-neutral-bg));
60
+ border-radius:8px; padding:10px 14px; margin:12px 0;
61
+ }
62
+ .cm-block > .cm-title { font-weight:700; color:var(--fg, inherit); }
63
+ .cm-block > .cm-body > :first-child { margin-top:0; }
64
+ .cm-block > .cm-body > :last-child { margin-bottom:0; }
65
+
66
+ /* ---- Pill / badge ---- */
67
+ .cm-pill {
68
+ display:inline-block; color:var(--fg); background:var(--bg); border:1px solid var(--bd);
69
+ border-radius:999px; padding:0 .55em; font-size:.82em; font-weight:600; line-height:1.7;
70
+ white-space:nowrap;
71
+ }
72
+
73
+ /* ---- Inline colored text (tint, no fill) ---- */
74
+ .cm-text { color:var(--fg); font-weight:600; }
75
+
76
+ /* ---- Progress meter ---- */
77
+ .cm-meter { display:inline-flex; align-items:center; gap:8px; vertical-align:middle; }
78
+ .cm-meter .cm-track {
79
+ width:120px; height:8px; border-radius:999px; background:var(--cm-neutral-bg);
80
+ border:1px solid var(--cm-neutral-bd); overflow:hidden;
81
+ }
82
+ .cm-meter .cm-fill { display:block; height:100%; background:var(--fg, var(--cm-info-fg)); }
83
+ .cm-meter .cm-val { font-size:.82em; font-weight:600; color:var(--fg); }
84
+
85
+ /* ---- Fields (key/value) ---- */
86
+ .cm-fields {
87
+ display:grid; grid-template-columns:auto 1fr; gap:4px 16px; margin:12px 0;
88
+ border:1px solid var(--cm-neutral-bd); border-radius:8px; padding:12px 14px;
89
+ background:var(--cm-neutral-bg);
90
+ }
91
+ .cm-fields dt { font-weight:600; opacity:.75; }
92
+ .cm-fields dd { margin:0; }
93
+
94
+ /* ---- Collapsible ---- */
95
+ .cm-details { border:1px solid var(--bd); border-radius:8px; margin:12px 0; overflow:hidden; }
96
+ .cm-details > summary {
97
+ cursor:pointer; padding:8px 14px; font-weight:600; list-style:none; background:var(--cm-neutral-bg);
98
+ }
99
+ .cm-details[data-tone] > summary, .cm-details.cm-custom > summary { color:var(--fg); background:var(--bg); }
100
+ .cm-details > summary::-webkit-details-marker { display:none; }
101
+ .cm-details > summary::before {
102
+ content:"\25B8"; display:inline-block; margin-right:8px; transition:transform .15s ease;
103
+ }
104
+ .cm-details[open] > summary::before { transform:rotate(90deg); }
105
+ .cm-details > .cm-body { padding:10px 14px; }
106
+ .cm-details > .cm-body > :first-child { margin-top:0; }
107
+ .cm-details > .cm-body > :last-child { margin-bottom:0; }
108
+
109
+ /* ---- Inline diff (CriticMarkup) ---- */
110
+ .crit-add { background:var(--cm-success-bg); color:var(--cm-success-fg); text-decoration:none; border-radius:3px; padding:0 2px; }
111
+ .crit-del { background:var(--cm-danger-bg); color:var(--cm-danger-fg); text-decoration:line-through; border-radius:3px; padding:0 2px; }
112
+ .crit-mark { background:var(--cm-warning-bg); border-radius:3px; padding:0 2px; }
113
+ .crit-comment { color:var(--cm-muted-fg); font-style:italic; }