@mirrordown/remd-spoiler 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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+
3
+
4
+ ## 0.1.1
5
+ <sub>2026-10-28</sub>
6
+
7
+ - *(patch)*
8
+ Backslash-escaped delimiters are now literal in `remd-mark`, `remd-ins`, `remd-del`, `remd-kbd`, `remd-spoiler`, `remd-sub` and `remd-sup`, as they already were in the `mdit-*` plugins: `\==not marked==` renders as `==not marked==` instead of a `<mark>`, while an escaped backslash (`\==marked==`) still allows the markup. These plugins now depend on the new `@mirrordown/core` package, which holds logic shared across Mirrordown's engines.
9
+ - *(patch)*
10
+ `||spoiler||` now pairs delimiters with markdown-it's rules in every engine: `remd-spoiler` runs on `@mirrordown/core`'s delimiter scan (which gains the `|` marker), so a closer pairs with the nearest opener, spoilers nest, and an odd-length run's extra `|` stays outside; it drops its `unist-util-find-*` and `unist-builder` dependencies.
11
+
12
+ New `@mirrordown/sat-spoiler` renders the same JavaScript-free click-to-reveal markup, ships the same stylesheet, and is included in `@mirrordown/preset-satteri`.
13
+
14
+ ## 0.1.0
15
+ <sub>2026-07-01</sub>
16
+
17
+ - *(minor)*
18
+ Add the spoiler plugin set: Discord-style `||spoiler||` click-to-reveal for inline content and images. Inline text becomes an obscured bar (per-line via `box-decoration-break`); wrap an image (`||![](…)||`) and it renders heavily blurred with a centered **SPOILER** pill, revealing the sharp image on click — Discord's image-spoiler treatment. The whole interaction is a `<label>` wrapping a visually-hidden checkbox and the content, revealed with the `:checked` sibling selector, so **no JavaScript runs** and it works in the VSCode preview. Keyboard-operable (Space) and announced as a spoiler control by screen readers. Combines with `lightbox` (`||!![](…)||`) for a spoilered image that is also click-to-zoom once revealed. The markdown-it and remark plugins emit identical HTML. Also bundles the `markdown-spoiler` VSCode preview extension in the extension pack.
package/README.md ADDED
@@ -0,0 +1,141 @@
1
+ # @mirrordown/remd-spoiler
2
+
3
+ > Part of [Mirrordown](https://github.com/mirrordown/mirrordown) — a suite of markdown syntax extensions for the unified, markdown-it and Sätteri ecosystems.
4
+
5
+ A remark/rehype (unified) plugin for the `spoiler` syntax extension.
6
+
7
+ ## Overview
8
+
9
+ The `spoiler` plugin hides content behind a click-to-reveal cover using Discord's `||…||` syntax. Wrap inline content in double pipes — `||the butler did it||` — and it renders as an obscured bar; click it (or focus it and press <kbd>Space</kbd>) to reveal the text in place. Wrap an image and it renders blurred with a centered **SPOILER** label, like Discord's image spoilers.
10
+
11
+ The entire interaction is built from HTML and CSS only — a `<label>` wrapping a visually-hidden checkbox and the content, revealed with the `:checked` sibling selector. **No JavaScript runs**, so it works in environments that disable scripts, such as the VSCode Markdown preview.
12
+
13
+ ```html
14
+ <label class="markdown-spoiler">
15
+ <input type="checkbox" class="markdown-spoiler-toggle" aria-label="spoiler" />
16
+ <span class="markdown-spoiler-content">the butler did it</span>
17
+ </label>
18
+ ```
19
+
20
+ The checkbox is the only interactive control, so it stays keyboard-operable and is announced by screen readers as a spoiler control — the hidden text is not read aloud until the reader chooses to reveal it.
21
+
22
+ ## Syntax
23
+
24
+ Wrap any inline content in `||…||`. Click a bar below to reveal it; click again to hide it.
25
+
26
+ ````markdown
27
+ The killer was ||the butler|| all along, hidden in ||the conservatory||.
28
+ ````
29
+
30
+ In renderers without the plugin, `||…||` renders as plain text.
31
+
32
+ ### Rich inline content
33
+
34
+ A spoiler can wrap any inline markup — emphasis, code, links — and it stays obscured until revealed. A long spoiler wraps across lines with each line getting its own bar, just like Discord.
35
+
36
+ ````markdown
37
+ The recipe needs ||**two** cups of `flour` and a
38
+ [secret ingredient](https://example.com) that nobody expects||.
39
+ ````
40
+
41
+ ### Image spoilers
42
+
43
+ Wrap an image to hide it behind a blur and a **SPOILER** label — Discord's treatment for spoilered image embeds. Clicking reveals the sharp image.
44
+
45
+ ````markdown
46
+ Careful, dinner photo incoming: ||![A young sapling](./assets/sapling.jpg "Sapling")||
47
+ ````
48
+
49
+ ### Spoilered, zoomable images
50
+
51
+ Combine with the [`lightbox`](/guide/plugins/lightbox) plugin (`||!![…]()||`) for a spoilered image that is also click-to-zoom once revealed.
52
+
53
+ ````markdown
54
+ The reveal: ||!![Mount Fuji at dawn](./assets/fuji.jpg "Mount Fuji")||
55
+ ````
56
+
57
+ ### Inside links
58
+
59
+ A spoiler works inside a link — the whole revealed content remains the link target.
60
+
61
+ ````markdown
62
+ Read [the ||shocking twist||](https://example.com) at your own risk.
63
+ ````
64
+
65
+ ## Accessibility
66
+
67
+ The spoiler is a real checkbox with `aria-label="spoiler"`, so assistive technology announces it as a control the user can operate rather than reading the hidden text aloud. Keyboard users <kbd>Tab</kbd> to the spoiler and press <kbd>Space</kbd> to reveal it; a focus ring marks the current spoiler. Revealing is reversible (unlike Discord, which locks open) — a superset of the expected behavior.
68
+
69
+ ## Customization
70
+
71
+ The stylesheet keeps its rules in `@layer markdown-spoiler`, so any unlayered CSS you write overrides them without `!important`. The common knobs are exposed as custom properties — set them on `:root` or any ancestor:
72
+
73
+ | Property | Default | Description |
74
+ | ----------------------------------- | ------------------------------------------- | --------------------------------------- |
75
+ | `--markdown-spoiler-bar` | `#202225` | Obscured bar color (text spoilers). |
76
+ | `--markdown-spoiler-radius` | `0.25rem` | Bar corner radius. |
77
+ | `--markdown-spoiler-duration` | `0.15s` | Reveal transition duration. |
78
+ | `--markdown-spoiler-revealed` | `color-mix(in srgb, currentColor 8%, …)` | Background behind revealed text. |
79
+ | `--markdown-spoiler-media-blur` | `2.5rem` | Blur radius for image spoilers. |
80
+ | `--markdown-spoiler-label` | `"SPOILER"` | Text of the image-spoiler pill. |
81
+
82
+ ```css
83
+ :root {
84
+ --markdown-spoiler-bar: #111;
85
+ --markdown-spoiler-radius: 0.5rem;
86
+ --markdown-spoiler-label: "HIDDEN";
87
+ }
88
+ ```
89
+
90
+ ## Browser support
91
+
92
+ Text spoilers work everywhere (checkbox + sibling selector). Image spoilers use [`:has()`](https://developer.mozilla.org/docs/Web/CSS/:has) to detect media and [`box-decoration-break`](https://developer.mozilla.org/docs/Web/CSS/box-decoration-break) for per-line bars (Chromium 105+, Safari, Firefox 122+); where unsupported, an image spoiler still hides its content, just without the per-line polish.
93
+
94
+ ## Install
95
+
96
+ Install `@mirrordown/remd-spoiler`. You must also pass `spoilerHastHandlers` to `remarkRehype` and import the stylesheet:
97
+
98
+ ```sh
99
+ npm install @mirrordown/remd-spoiler
100
+ ```
101
+
102
+ ### Unified
103
+
104
+ ```ts
105
+ import { unified } from "unified";
106
+ import remarkParse from "remark-parse";
107
+ import remarkRehype from "remark-rehype";
108
+ import rehypeStringify from "rehype-stringify";
109
+ import { remarkSpoiler, spoilerHastHandlers } from "@mirrordown/remd-spoiler";
110
+ import "@mirrordown/remd-spoiler/spoiler.css";
111
+
112
+ const processor = unified()
113
+ .use(remarkParse)
114
+ .use(remarkSpoiler)
115
+ .use(remarkRehype, { handlers: spoilerHastHandlers })
116
+ .use(rehypeStringify);
117
+ ```
118
+
119
+ ### Astro
120
+
121
+ ```ts
122
+ // astro.config.ts
123
+ import { defineConfig } from "astro/config";
124
+ import { remarkSpoiler, spoilerHastHandlers } from "@mirrordown/remd-spoiler";
125
+ import "@mirrordown/remd-spoiler/spoiler.css";
126
+
127
+ export default defineConfig({
128
+ markdown: {
129
+ remarkPlugins: [remarkSpoiler],
130
+ remarkRehype: { handlers: spoilerHastHandlers },
131
+ },
132
+ });
133
+ ```
134
+
135
+ ## Documentation
136
+
137
+ Full documentation, more examples, and configuration options: [github.com/mirrordown/mirrordown](https://github.com/mirrordown/mirrordown) (dedicated docs site coming soon).
138
+
139
+ ## License
140
+
141
+ MIT © [Drake Costa](https://saeris.gg)
@@ -0,0 +1,35 @@
1
+ import { Plugin } from "unified";
2
+ import { Data, Parent, PhrasingContent, Root } from "mdast";
3
+ import { Element, ElementContent } from "hast";
4
+ /** Optional data carried by a {@link Spoiler} node. */
5
+ export interface SpoilerData extends Data {}
6
+ /**
7
+ * An mdast node for `||spoiler||` text, rendered as a click-to-reveal spoiler
8
+ * (a `<label>` wrapping a checkbox and a content `<span>`).
9
+ */
10
+ export interface Spoiler extends Parent {
11
+ type: `spoiler`;
12
+ children: PhrasingContent[];
13
+ data?: SpoilerData | undefined;
14
+ }
15
+ interface HastState {
16
+ all: (node: Spoiler) => ElementContent[];
17
+ patch: (from: Spoiler, to: Element) => void;
18
+ }
19
+ type SpoilerHandler = (state: HastState, node: Spoiler) => Element;
20
+ /** mdast-to-hast handler for spoiler nodes, for use with `remark-rehype`. */
21
+ export declare const spoilerHastHandlers: Record<string, SpoilerHandler>;
22
+ /**
23
+ * remark plugin for Discord-style spoiler syntax (`||text||`), wrapping each match in a {@link Spoiler} node. Pair with {@link spoilerHastHandlers} via `remarkRehype({ handlers: spoilerHastHandlers })` so the node renders as a click-to-reveal spoiler. The scan is shared with markdown-it's pairing rules and the Sätteri plugin through `@mirrordown/core`, and the output is byte-identical to `@mirrordown/mdit-spoiler`.
24
+ */
25
+ export declare const remarkSpoiler: Plugin<[], Root>;
26
+ declare module "mdast" {
27
+ interface PhrasingContentMap {
28
+ spoiler: Spoiler;
29
+ }
30
+ interface RootContentMap {
31
+ spoiler: Spoiler;
32
+ }
33
+ }
34
+ export {};
35
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/plugin.ts","../src/augment.ts"],"mappings":";;;;iBAOiB,oBAAoB;;;;;iBAMpB,gBAAgB;EAC/B;EACA,UAAU;EACV,OAAO;;UAOC;EACR,MAAM,MAAM,YAAY;EACxB,QAAQ,MAAM,SAAS,IAAI;;KAExB,kBAAkB,OAAO,WAAW,MAAM,YAAY;;qBAoC9C,qBAAqB,eAAe;;;;qBAOpC,eAAe,WAAW;;YChE3B;IACR,SAAS;;YAGD;IACR,SAAS"}
package/dist/index.mjs ADDED
@@ -0,0 +1,66 @@
1
+ import { visit } from "unist-util-visit";
2
+ import { createDelimitedTransform, maskTreeEscapes } from "@mirrordown/core";
3
+ // src/plugin.ts
4
+ /**
5
+ * Build the `<label><input><span>...</span></label>` hast subtree. The checkbox
6
+ * precedes the content span so CSS's `:checked ~ .content` combinator can reach
7
+ * it; the content is a following sibling, not a child, of the checkbox.
8
+ */
9
+ const buildSpoilerHast = (state, node) => {
10
+ const result = {
11
+ type: `element`,
12
+ tagName: `label`,
13
+ properties: { class: `markdown-spoiler` },
14
+ children: [{
15
+ type: `element`,
16
+ tagName: `input`,
17
+ properties: {
18
+ type: `checkbox`,
19
+ class: `markdown-spoiler-toggle`,
20
+ "aria-label": `spoiler`
21
+ },
22
+ children: []
23
+ }, {
24
+ type: `element`,
25
+ tagName: `span`,
26
+ properties: { class: `markdown-spoiler-content` },
27
+ children: state.all(node)
28
+ }]
29
+ };
30
+ state.patch(node, result);
31
+ return result;
32
+ };
33
+ /** mdast-to-hast handler for spoiler nodes, for use with `remark-rehype`. */
34
+ const spoilerHastHandlers = { spoiler: buildSpoilerHast };
35
+ /**
36
+ * remark plugin for Discord-style spoiler syntax (`||text||`), wrapping each match in a {@link Spoiler} node. Pair with {@link spoilerHastHandlers} via `remarkRehype({ handlers: spoilerHastHandlers })` so the node renders as a click-to-reveal spoiler. The scan is shared with markdown-it's pairing rules and the Sätteri plugin through `@mirrordown/core`, and the output is byte-identical to `@mirrordown/mdit-spoiler`.
37
+ */
38
+ const remarkSpoiler = () => {
39
+ const transform = createDelimitedTransform(`|`, {
40
+ text: (value) => ({
41
+ type: `text`,
42
+ value
43
+ }),
44
+ wrap: (children) => ({
45
+ type: `spoiler`,
46
+ children
47
+ })
48
+ });
49
+ const transformer = (tree, file) => {
50
+ const restoreEscapes = maskTreeEscapes(tree, String(file));
51
+ const seen = /* @__PURE__ */ new WeakSet();
52
+ visit(tree, `text`, (_node, _index, parent) => {
53
+ if (!parent || seen.has(parent) || transform.built(parent)) return;
54
+ seen.add(parent);
55
+ const children = parent.children;
56
+ const next = transform(children, parent.type);
57
+ if (next !== children) parent.children = [...next];
58
+ return 0;
59
+ });
60
+ restoreEscapes();
61
+ };
62
+ return transformer;
63
+ };
64
+ export { remarkSpoiler, spoilerHastHandlers };
65
+
66
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import { visit } from \"unist-util-visit\";\nimport type { Plugin, Transformer } from \"unified\";\nimport type { Data, Parent, PhrasingContent, Root } from \"mdast\";\nimport type { Element, ElementContent, Properties } from \"hast\";\nimport { createDelimitedTransform, maskTreeEscapes } from \"@mirrordown/core\";\n\n/** Optional data carried by a {@link Spoiler} node. */\nexport interface SpoilerData extends Data {}\n\n/**\n * An mdast node for `||spoiler||` text, rendered as a click-to-reveal spoiler\n * (a `<label>` wrapping a checkbox and a content `<span>`).\n */\nexport interface Spoiler extends Parent {\n type: `spoiler`;\n children: PhrasingContent[];\n data?: SpoilerData | undefined;\n}\n\n// Minimal hast-handler surface. remark-rehype's real `State`/`Handler` types\n// carry the whole conversion API; we only need `all()` to convert this node's\n// mdast children into hast. Typed locally to avoid a dependency on\n// mdast-util-to-hast just for two type names.\ninterface HastState {\n all: (node: Spoiler) => ElementContent[];\n patch: (from: Spoiler, to: Element) => void;\n}\ntype SpoilerHandler = (state: HastState, node: Spoiler) => Element;\n\n/**\n * Build the `<label><input><span>...</span></label>` hast subtree. The checkbox\n * precedes the content span so CSS's `:checked ~ .content` combinator can reach\n * it; the content is a following sibling, not a child, of the checkbox.\n */\nconst buildSpoilerHast = (state: HastState, node: Spoiler): Element => {\n const inputProps: Properties = {\n type: `checkbox`,\n class: `markdown-spoiler-toggle`,\n \"aria-label\": `spoiler`\n };\n const input: Element = {\n type: `element`,\n tagName: `input`,\n properties: inputProps,\n children: []\n };\n const content: Element = {\n type: `element`,\n tagName: `span`,\n properties: { class: `markdown-spoiler-content` },\n children: state.all(node)\n };\n const result: Element = {\n type: `element`,\n tagName: `label`,\n properties: { class: `markdown-spoiler` },\n children: [input, content]\n };\n state.patch(node, result);\n return result;\n};\n\n/** mdast-to-hast handler for spoiler nodes, for use with `remark-rehype`. */\nexport const spoilerHastHandlers: Record<string, SpoilerHandler> = {\n spoiler: buildSpoilerHast\n};\n\n/**\n * remark plugin for Discord-style spoiler syntax (`||text||`), wrapping each match in a {@link Spoiler} node. Pair with {@link spoilerHastHandlers} via `remarkRehype({ handlers: spoilerHastHandlers })` so the node renders as a click-to-reveal spoiler. The scan is shared with markdown-it's pairing rules and the Sätteri plugin through `@mirrordown/core`, and the output is byte-identical to `@mirrordown/mdit-spoiler`.\n */\nexport const remarkSpoiler: Plugin<[], Root> = () => {\n const transform = createDelimitedTransform<PhrasingContent>(`|`, {\n text: (value) => ({ type: `text`, value }),\n wrap: (children): Spoiler => ({ type: `spoiler`, children })\n });\n\n const transformer: Transformer<Root> = (tree, file) => {\n // Escapes are resolved before this runs; mask escaped characters so a backslash-escaped delimiter is not matched, as in markdown-it.\n const restoreEscapes = maskTreeEscapes(tree, String(file));\n const seen = new WeakSet<Parent>();\n visit(tree, `text`, (_node, _index, parent: Parent | undefined) => {\n // Spoilers the scan built have already had their content scanned.\n if (!parent || seen.has(parent) || transform.built(parent)) return;\n seen.add(parent);\n // A text node's parent holds phrasing content.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n const children = parent.children as PhrasingContent[];\n const next = transform(children, parent.type);\n if (next !== children) parent.children = [...next];\n // Walk the restructured children from the start; this parent is done.\n return 0;\n });\n restoreEscapes();\n };\n\n return transformer;\n};\n"],"mappings":";;;;;;;;AAkCA,MAAM,oBAAoB,OAAkB,SAA2B;CAkBrE,MAAM,SAAkB;EACtB,MAAM;EACN,SAAS;EACT,YAAY,EAAE,OAAO,mBAAmB;EACxC,UAAU,CAAC;GAfX,MAAM;GACN,SAAS;GACT,YAAY;IAPZ,MAAM;IACN,OAAO;IACP,cAAc;GAKO;GACrB,UAAU,CAAC;EAYI,GAAG;GATlB,MAAM;GACN,SAAS;GACT,YAAY,EAAE,OAAO,2BAA2B;GAChD,UAAU,MAAM,IAAI,IAAI;EAMA,CAAC;CAC3B;CACA,MAAM,MAAM,MAAM,MAAM;CACxB,OAAO;AACT;;AAGA,MAAa,sBAAsD,EACjE,SAAS,iBACX;;;;AAKA,MAAa,sBAAwC;CACnD,MAAM,YAAY,yBAA0C,KAAK;EAC/D,OAAO,WAAW;GAAE,MAAM;GAAQ;EAAM;EACxC,OAAO,cAAuB;GAAE,MAAM;GAAW;EAAS;CAC5D,CAAC;CAED,MAAM,eAAkC,MAAM,SAAS;EAErD,MAAM,iBAAiB,gBAAgB,MAAM,OAAO,IAAI,CAAC;EACzD,MAAM,uBAAO,IAAI,QAAgB;EACjC,MAAM,MAAM,SAAS,OAAO,QAAQ,WAA+B;GAEjE,IAAI,CAAC,UAAU,KAAK,IAAI,MAAM,KAAK,UAAU,MAAM,MAAM,GAAG;GAC5D,KAAK,IAAI,MAAM;GAGf,MAAM,WAAW,OAAO;GACxB,MAAM,OAAO,UAAU,UAAU,OAAO,IAAI;GAC5C,IAAI,SAAS,UAAU,OAAO,WAAW,CAAC,GAAG,IAAI;GAEjD,OAAO;EACT,CAAC;EACD,eAAe;CACjB;CAEA,OAAO;AACT"}
@@ -0,0 +1,316 @@
1
+ /*
2
+ Spoiler — default stylesheet
3
+ -----------------------------------------------------------------------------
4
+ A fully declarative, JavaScript-free Discord-style spoiler. The markup is a
5
+ <label> wrapping a visually-hidden checkbox and a content <span>:
6
+
7
+ <label class="markdown-spoiler">
8
+ <input type="checkbox" class="markdown-spoiler-toggle" aria-label="spoiler">
9
+ <span class="markdown-spoiler-content">hidden text</span>
10
+ </label>
11
+
12
+ Clicking anywhere on the bar (the whole <label> is the hit target) toggles the
13
+ checkbox; `:checked ~ .content` reveals the text. The checkbox is the only
14
+ interactive control, so it stays keyboard-operable (Space) and is announced as
15
+ a control by screen readers — the hidden text is not read aloud until the user
16
+ chooses to reveal it.
17
+
18
+ All visual rules live inside @layer markdown-spoiler so any unlayered consumer
19
+ CSS overrides them without !important.
20
+
21
+ Tunable via public custom properties (set on :root or any ancestor):
22
+ --markdown-spoiler-bar obscured bar color (default #202225)
23
+ --markdown-spoiler-radius bar corner radius (default 0.25rem)
24
+ --markdown-spoiler-duration reveal transition duration (default 0.15s)
25
+ --markdown-spoiler-revealed background behind revealed text
26
+ (default: 8% of the current text color)
27
+ */
28
+
29
+ @layer markdown-spoiler {
30
+ .markdown-spoiler {
31
+ /* stay in the inline flow of the surrounding sentence */
32
+ cursor: pointer;
33
+ }
34
+
35
+ /*
36
+ Visually hide the checkbox while keeping it in the accessibility tree and
37
+ focus order. `display: none` / `visibility: hidden` would remove it from the
38
+ tab order and break keyboard reveal, so use the clip technique instead.
39
+ */
40
+ .markdown-spoiler-toggle {
41
+ position: absolute;
42
+ width: 1px;
43
+ height: 1px;
44
+ margin: -1px;
45
+ padding: 0;
46
+ border: 0;
47
+ overflow: hidden;
48
+ white-space: nowrap;
49
+ clip-path: inset(50%);
50
+ }
51
+
52
+ .markdown-spoiler-content {
53
+ /*
54
+ Keep the content as plain inline text so it wraps at word boundaries like
55
+ normal prose. `box-decoration-break: clone` then redraws the bar's
56
+ background/padding/radius on EACH wrapped line fragment instead of
57
+ stretching one box across the break — this is what gives Discord's
58
+ per-line rounded bars. The -webkit- prefix is still required (Safari,
59
+ Chrome); the property is not yet Baseline.
60
+ */
61
+ color: transparent;
62
+ background-color: var(--markdown-spoiler-bar, #202225);
63
+ border-radius: var(--markdown-spoiler-radius, 0.25rem);
64
+ padding: 0 0.15em;
65
+ cursor: pointer;
66
+ user-select: none;
67
+ -webkit-user-select: none;
68
+ -webkit-box-decoration-break: clone;
69
+ box-decoration-break: clone;
70
+ transition:
71
+ color var(--markdown-spoiler-duration, 0.15s) ease,
72
+ background-color var(--markdown-spoiler-duration, 0.15s) ease;
73
+ }
74
+
75
+ /*
76
+ Hover: lighten the black bar slightly, matching Discord's subtle hover cue.
77
+ Only while unrevealed (a revealed spoiler is normal text). `:has()` scopes to
78
+ an unchecked toggle so the hover lighten doesn't fight the revealed style.
79
+ */
80
+ .markdown-spoiler:has(.markdown-spoiler-toggle:not(:checked)):hover
81
+ .markdown-spoiler-content {
82
+ background-color: var(
83
+ --markdown-spoiler-bar-hover,
84
+ color-mix(in srgb, var(--markdown-spoiler-bar, #202225) 85%, white)
85
+ );
86
+ }
87
+
88
+ /* Fade embedded media in/out with the same duration as the text reveal. */
89
+ .markdown-spoiler-content > * {
90
+ transition:
91
+ opacity var(--markdown-spoiler-duration, 0.15s) ease,
92
+ filter var(--markdown-spoiler-duration, 0.15s) ease;
93
+ }
94
+
95
+ /*
96
+ `color: transparent` only hides text. Inline children that carry their own
97
+ ink — code spans (own background), nested sub/sup/mark — are hidden with
98
+ `visibility: hidden`, which keeps their layout box so the bar stays sized to
99
+ the content and the black bar covers them.
100
+ */
101
+ .markdown-spoiler-content > * {
102
+ visibility: hidden;
103
+ }
104
+
105
+ /*
106
+ Media spoilers get Discord's treatment, not a black bar: the image stays
107
+ visible but is heavily blurred, with a centered "SPOILER" pill on top. A
108
+ black box would hide the fact that there's an image at all; the blur signals
109
+ "there's media here, click to reveal" while still concealing the content.
110
+
111
+ The content becomes inline-block (so it sizes to the media box and can host a
112
+ centered ::after overlay), the bar background is dropped, and the media child
113
+ is blurred rather than hidden. :has() detects the media case in pure CSS — no
114
+ JS, and text spoilers are untouched.
115
+ */
116
+ .markdown-spoiler-content:has(> img, > svg, > .markdown-lightbox-trigger) {
117
+ display: inline-block;
118
+ position: relative;
119
+ vertical-align: text-bottom;
120
+ background-color: transparent;
121
+ padding: 0;
122
+ overflow: hidden;
123
+ }
124
+
125
+ .markdown-spoiler-content:has(> img, > svg, > .markdown-lightbox-trigger)
126
+ > * {
127
+ visibility: visible;
128
+ display: block;
129
+ /*
130
+ `filter: blur()` samples pixels beyond the element's edges; against the
131
+ transparent area outside the media those samples average toward nothing,
132
+ producing a DARK vignette at the clipped edges. To hide it, scale the media
133
+ up so its blurred fringe falls entirely outside the content's overflow clip
134
+ — only the solid, fully-sampled interior remains visible. The scale factor
135
+ must cover ~2× the blur radius on each axis; 1.35 clears the default blur.
136
+ transform-origin defaults to center, so it stays centered under the pill.
137
+ */
138
+ scale: 1.35;
139
+ filter: blur(var(--markdown-spoiler-media-blur, 2.5rem));
140
+ transition:
141
+ filter var(--markdown-spoiler-duration, 0.15s) ease,
142
+ scale var(--markdown-spoiler-duration, 0.15s) ease;
143
+ }
144
+
145
+ /* The centered "SPOILER" pill overlay. A pseudo-element's text is never
146
+ selectable, matching Discord. Sits above the blurred media, centered.
147
+ Note: no space before ::after — it's the pseudo-element OF the content span,
148
+ not of a descendant (a descendant <img> is replaced and has no ::after).
149
+
150
+ z-index raises both pseudo-elements above the media child: a blurred child
151
+ creates its own stacking context, so without an explicit z-index the raster
152
+ <img> paints over the pill (the img/svg discrepancy — the bright blurred
153
+ image bled through the semi-transparent pill). ::after (text) sits above
154
+ ::before (the pill background). */
155
+ .markdown-spoiler-content:has(
156
+ > img,
157
+ > svg,
158
+ > .markdown-lightbox-trigger
159
+ )::after {
160
+ content: var(--markdown-spoiler-label, "SPOILER");
161
+ position: absolute;
162
+ inset: 0;
163
+ z-index: 2;
164
+ display: flex;
165
+ align-items: center;
166
+ justify-content: center;
167
+ pointer-events: none;
168
+ font-size: 0.75rem;
169
+ font-weight: 700;
170
+ letter-spacing: 0.05em;
171
+ color: #fff;
172
+ }
173
+
174
+ .markdown-spoiler-content:has(
175
+ > img,
176
+ > svg,
177
+ > .markdown-lightbox-trigger
178
+ )::before {
179
+ content: "";
180
+ position: absolute;
181
+ top: 50%;
182
+ left: 50%;
183
+ z-index: 1;
184
+ translate: -50% -50%;
185
+ width: 5.5rem;
186
+ height: 1.75rem;
187
+ border-radius: 1rem;
188
+ background: rgb(0 0 0 / 60%);
189
+ pointer-events: none;
190
+ transition: background var(--markdown-spoiler-duration, 0.15s) ease;
191
+ }
192
+
193
+ /*
194
+ Image hover (while unrevealed): brighten the blurred media so the whole
195
+ spoiler reads as "lifting", matching Discord's hover cue. Scoped to an
196
+ unchecked toggle so a revealed image isn't affected.
197
+ */
198
+ .markdown-spoiler:has(.markdown-spoiler-toggle:not(:checked)):hover
199
+ .markdown-spoiler-content:has(> img, > svg, > .markdown-lightbox-trigger)
200
+ > * {
201
+ /* keep the anti-vignette scale; add brightness so the image lifts */
202
+ scale: 1.35;
203
+ filter: blur(var(--markdown-spoiler-media-blur, 2.5rem)) brightness(1.2);
204
+ }
205
+
206
+ /* Hover: the pill goes solid black (Discord raises pill contrast on hover). */
207
+ .markdown-spoiler:has(.markdown-spoiler-toggle:not(:checked)):hover
208
+ .markdown-spoiler-content:has(
209
+ > img,
210
+ > svg,
211
+ > .markdown-lightbox-trigger
212
+ )::before {
213
+ background: rgb(0 0 0 / 90%);
214
+ }
215
+
216
+ /* Revealed: the checkbox is checked, so show the content in place. */
217
+ .markdown-spoiler-toggle:checked ~ .markdown-spoiler-content {
218
+ color: inherit;
219
+ background-color: var(
220
+ --markdown-spoiler-revealed,
221
+ color-mix(in srgb, currentColor 8%, transparent)
222
+ );
223
+ cursor: auto;
224
+ user-select: auto;
225
+ -webkit-user-select: auto;
226
+ }
227
+
228
+ .markdown-spoiler-toggle:checked ~ .markdown-spoiler-content > * {
229
+ visibility: visible;
230
+ }
231
+
232
+ /* A revealed media spoiler: unblur, drop the bar background and the overlay. */
233
+ .markdown-spoiler-toggle:checked
234
+ ~ .markdown-spoiler-content:has(
235
+ > img,
236
+ > svg,
237
+ > .markdown-lightbox-trigger
238
+ ) {
239
+ background-color: transparent;
240
+ }
241
+
242
+ .markdown-spoiler-toggle:checked
243
+ ~ .markdown-spoiler-content:has(> img, > svg, > .markdown-lightbox-trigger)
244
+ > * {
245
+ filter: none;
246
+ scale: 1; /* undo the anti-vignette upscale so revealed media is 1:1 */
247
+ }
248
+
249
+ .markdown-spoiler-toggle:checked
250
+ ~ .markdown-spoiler-content:has(
251
+ > img,
252
+ > svg,
253
+ > .markdown-lightbox-trigger
254
+ )::before,
255
+ .markdown-spoiler-toggle:checked
256
+ ~ .markdown-spoiler-content:has(
257
+ > img,
258
+ > svg,
259
+ > .markdown-lightbox-trigger
260
+ )::after {
261
+ content: none;
262
+ }
263
+
264
+ /*
265
+ The checkbox is visually hidden, so route its focus ring to the visible bar.
266
+ :has() lets the label style itself based on the descendant checkbox's focus.
267
+ A plain outline wraps each line-box (so multi-line text bars still get a ring
268
+ on every fragment) and hugs the single inline-block of a media spoiler.
269
+ */
270
+ .markdown-spoiler:has(.markdown-spoiler-toggle:focus-visible)
271
+ .markdown-spoiler-content {
272
+ outline: 2px solid Highlight;
273
+ outline-offset: 2px;
274
+ }
275
+
276
+ /* Respect reduced-motion: reveal instantly, no color fade. */
277
+ @media (prefers-reduced-motion: reduce) {
278
+ .markdown-spoiler-content {
279
+ transition: none;
280
+ }
281
+ }
282
+ }
283
+
284
+ /*
285
+ Lightbox integration — DELIBERATELY UNLAYERED.
286
+ --------------------------------------------------------------------------
287
+ A spoilered lightbox image (`||!![…]()||`) nests a
288
+ <button class="markdown-lightbox-trigger"> inside the spoiler. While the
289
+ spoiler is unrevealed the trigger must (a) be visually blurred and (b) NOT
290
+ intercept the click — otherwise the first click opens the zoom dialog and
291
+ skips the reveal entirely. The click must fall through to the <label> so the
292
+ checkbox toggles and reveals first; the trigger becomes interactive only once
293
+ revealed, giving the intended two-step "reveal, then zoom".
294
+
295
+ These rules live OUTSIDE @layer on purpose: @mirrordown/mdit-lightbox's own
296
+ `.markdown-lightbox-trigger { all: unset }` is inside @layer markdown-lightbox,
297
+ and whichever layer is declared last would otherwise win and reset
298
+ pointer-events. An unlayered rule always beats a layered one regardless of
299
+ stylesheet order, so this functional integration holds either way.
300
+ */
301
+ .markdown-spoiler-toggle:not(:checked)
302
+ ~ .markdown-spoiler-content
303
+ > .markdown-lightbox-trigger {
304
+ pointer-events: none;
305
+ filter: blur(var(--markdown-spoiler-media-blur, 2.5rem));
306
+ scale: 1.35;
307
+ }
308
+
309
+ /* Once revealed, the trigger is interactive and sharp so the lightbox zoom works. */
310
+ .markdown-spoiler-toggle:checked
311
+ ~ .markdown-spoiler-content
312
+ > .markdown-lightbox-trigger {
313
+ pointer-events: auto;
314
+ filter: none;
315
+ scale: 1;
316
+ }
package/package.json CHANGED
@@ -1,11 +1,47 @@
1
1
  {
2
2
  "name": "@mirrordown/remd-spoiler",
3
- "version": "0.0.0",
4
3
  "description": "A remark plugin for Discord-style spoiler syntax (||text||), rendering click-to-reveal spoilers.",
4
+ "version": "0.1.1",
5
5
  "license": "MIT",
6
6
  "author": "Drake Costa <drake@saeris.io> (https://saeris.gg)",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/mirrordown/mirrordown.git"
10
+ },
11
+ "style": "./dist/spoiler.css",
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "type": "module",
16
+ "exports": {
17
+ ".": {
18
+ "development": "./src/index.ts",
19
+ "types": "./dist/index.d.mts",
20
+ "import": "./dist/index.mjs"
21
+ },
22
+ "./*.css": "./dist/*.css"
23
+ },
24
+ "dependencies": {
25
+ "@mirrordown/core": "^0.1.0",
26
+ "unist-util-visit": "^5.1.0"
27
+ },
28
+ "devDependencies": {
29
+ "@types/hast": "^3.0.4",
30
+ "@types/mdast": "^4.0.4",
31
+ "unified": "^11.0.0"
32
+ },
33
+ "peerDependencies": {
34
+ "unified": "^11.0.0"
35
+ },
36
+ "engines": {
37
+ "node": ">=24.0.0"
38
+ },
39
+ "bumpy": {
40
+ "publishCommand": [
41
+ "node ../../scripts/sync-jsr-version.mjs",
42
+ "node ../../scripts/npm-publish.mjs",
43
+ "node ../../scripts/jsr-resolve-deps.mjs",
44
+ "node ../../scripts/jsr-publish.mjs"
45
+ ]
10
46
  }
11
- }
47
+ }