@fsegurai/marked-extended-accordion 18.0.0 → 19.0.0-beta.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/README.custom.md CHANGED
@@ -203,6 +203,46 @@ Content with slower transition
203
203
 
204
204
  <!-- SECTION:CUSTOM_USAGE_NOTES -->
205
205
 
206
+ ### Sanitizer-safe markup and the browser runtime (19.0.0-beta.0)
207
+
208
+ By default the HTML survives strict sanitizers such as Angular's `SecurityContext.HTML`, which removes `id`, `name`,
209
+ `style`, `data-*` and `<svg>`. Those values move into class tokens (`mx-accordion-<key>-<value>`):
210
+
211
+ | 18.0 markup | 19.0.0-beta.0 default |
212
+ | --- | --- |
213
+ | `id="accordion-x1y2z3"` | `mx-accordion-id-accordion-x1y2z3` |
214
+ | `name="faq"` (exclusive group) | `mx-accordion-group-faq` |
215
+ | `style="--…-animation-duration: 0.5s; …"` | `mx-accordion-duration-0_2e5s`, `mx-accordion-easing-…` (only when they differ from the defaults) |
216
+ | `data-section="intro"` | `mx-accordion-dataSection-intro` |
217
+ | variant `<svg>` icon | `<span class="marked-extended-accordion-icon mx-accordion-icon-note">`, drawn by `accordion.css` |
218
+
219
+ `<details>`, `<summary>` and `open` survive sanitizing, so expanding and collapsing works without JavaScript. The rest is
220
+ done by a scoped runtime that you attach after the HTML is in the DOM:
221
+
222
+ ```javascript
223
+ import markedExtendedAccordion, { attachAccordion } from '@fsegurai/marked-extended-accordion';
224
+
225
+ marked.use(markedExtendedAccordion());
226
+ container.innerHTML = marked.parse(markdown);
227
+
228
+ const dispose = attachAccordion(container); // { className } if you changed the extension's className
229
+ // later: dispose();
230
+ ```
231
+
232
+ - Applies the per-block `duration`/`easing` CSS variables and restores the `data-*` attributes.
233
+ - Exclusive groups: opening an accordion closes the other open accordions of its group inside `container`.
234
+ - `#id` links whose target lost its `id` open and scroll to the accordion carrying that id token.
235
+ - Dispatches a bubbling `marked-extended:accordion:toggle` event with `detail: { id, open, group }`.
236
+ - Listeners live on `container` only; attaching twice is a no-op; the first `dispose()` removes everything.
237
+ - Replacing the content of `container` keeps groups, links and events working (they are delegated). The CSS variables
238
+ and `data-*` attributes are per element: call `attachAccordion.refresh(container)` after a re-render, or attach with
239
+ `attachAccordion(container, { observe: true })` (a `MutationObserver` on `container` only, disconnected by dispose).
240
+
241
+ Pass `unsafeHtml: true` to keep the 18.0 markup (`id`, `name`, `style`, `data-*`, inline `<svg>`) when you do not
242
+ sanitize the HTML. Custom templates can still use `{accordionId}`, `{nameAttr}`, `{dataAttrs}` and `{styleAttr}`
243
+ (strict sanitizers remove what they produce), and the new `{tokenClasses}` placeholder.
244
+
245
+
206
246
  ### Importing Styles
207
247
 
208
248
  Starting from version 17.0.0, this extension **does not automatically inject styles**. You must import the CSS or SCSS
@@ -302,7 +342,7 @@ Complete example for projects without build tools:
302
342
  <title>Marked Extended Accordion Example</title>
303
343
 
304
344
  <!-- Import Marked.js from CDN -->
305
- <script src="https://cdn.jsdelivr.net/npm/marked@17/lib/marked.umd.js"></script>
345
+ <script src="https://cdn.jsdelivr.net/npm/marked@18/lib/marked.umd.js"></script>
306
346
 
307
347
  <!-- Import Accordion Extension from CDN -->
308
348
  <script src="https://cdn.jsdelivr.net/npm/@fsegurai/marked-extended-accordion@latest/dist/index.umd.js"></script>
package/README.md CHANGED
@@ -255,6 +255,46 @@ Content with slower transition
255
255
  `````
256
256
  ```
257
257
 
258
+ ### Sanitizer-safe markup and the browser runtime (19.0.0-beta.0)
259
+
260
+ By default the HTML survives strict sanitizers such as Angular's `SecurityContext.HTML`, which removes `id`, `name`,
261
+ `style`, `data-*` and `<svg>`. Those values move into class tokens (`mx-accordion-<key>-<value>`):
262
+
263
+ | 18.0 markup | 19.0.0-beta.0 default |
264
+ | --- | --- |
265
+ | `id="accordion-x1y2z3"` | `mx-accordion-id-accordion-x1y2z3` |
266
+ | `name="faq"` (exclusive group) | `mx-accordion-group-faq` |
267
+ | `style="--…-animation-duration: 0.5s; …"` | `mx-accordion-duration-0_2e5s`, `mx-accordion-easing-…` (only when they differ from the defaults) |
268
+ | `data-section="intro"` | `mx-accordion-dataSection-intro` |
269
+ | variant `<svg>` icon | `<span class="marked-extended-accordion-icon mx-accordion-icon-note">`, drawn by `accordion.css` |
270
+
271
+ `<details>`, `<summary>` and `open` survive sanitizing, so expanding and collapsing works without JavaScript. The rest is
272
+ done by a scoped runtime that you attach after the HTML is in the DOM:
273
+
274
+ ```javascript
275
+ import markedExtendedAccordion, { attachAccordion } from '@fsegurai/marked-extended-accordion';
276
+
277
+ marked.use(markedExtendedAccordion());
278
+ container.innerHTML = marked.parse(markdown);
279
+
280
+ const dispose = attachAccordion(container); // { className } if you changed the extension's className
281
+ // later: dispose();
282
+ ```
283
+
284
+ - Applies the per-block `duration`/`easing` CSS variables and restores the `data-*` attributes.
285
+ - Exclusive groups: opening an accordion closes the other open accordions of its group inside `container`.
286
+ - `#id` links whose target lost its `id` open and scroll to the accordion carrying that id token.
287
+ - Dispatches a bubbling `marked-extended:accordion:toggle` event with `detail: { id, open, group }`.
288
+ - Listeners live on `container` only; attaching twice is a no-op; the first `dispose()` removes everything.
289
+ - Replacing the content of `container` keeps groups, links and events working (they are delegated). The CSS variables
290
+ and `data-*` attributes are per element: call `attachAccordion.refresh(container)` after a re-render, or attach with
291
+ `attachAccordion(container, { observe: true })` (a `MutationObserver` on `container` only, disconnected by dispose).
292
+
293
+ Pass `unsafeHtml: true` to keep the 18.0 markup (`id`, `name`, `style`, `data-*`, inline `<svg>`) when you do not
294
+ sanitize the HTML. Custom templates can still use `{accordionId}`, `{nameAttr}`, `{dataAttrs}` and `{styleAttr}`
295
+ (strict sanitizers remove what they produce), and the new `{tokenClasses}` placeholder.
296
+
297
+
258
298
  ### Importing Styles
259
299
 
260
300
  Starting from version 17.0.0, this extension **does not automatically inject styles**. You must import the CSS or SCSS
@@ -354,7 +394,7 @@ Complete example for projects without build tools:
354
394
  <title>Marked Extended Accordion Example</title>
355
395
 
356
396
  <!-- Import Marked.js from CDN -->
357
- <script src="https://cdn.jsdelivr.net/npm/marked@17/lib/marked.umd.js"></script>
397
+ <script src="https://cdn.jsdelivr.net/npm/marked@18/lib/marked.umd.js"></script>
358
398
 
359
399
  <!-- Import Accordion Extension from CDN -->
360
400
  <script src="https://cdn.jsdelivr.net/npm/@fsegurai/marked-extended-accordion@latest/dist/index.umd.js"></script>
@@ -2028,6 +2068,7 @@ on [GitHub](https://github.com/fsegurai/marked-extensions/issues).
2028
2068
  | All - Bundle | [@fsegurai/marked-extended-bundle](https://www.npmjs.com/package/@fsegurai/marked-extended-bundle) | ![npm](https://img.shields.io/npm/v/@fsegurai/marked-extended-bundle) | Includes all extensions in a single package for easy integration |
2029
2069
  | Accordion | [@fsegurai/marked-extended-accordion](https://www.npmjs.com/package/@fsegurai/marked-extended-accordion) | ![npm](https://img.shields.io/npm/v/@fsegurai/marked-extended-accordion) | Add collapsible accordion sections to your markdown |
2030
2070
  | Alert | [@fsegurai/marked-extended-alert](https://www.npmjs.com/package/@fsegurai/marked-extended-alert) | ![npm](https://img.shields.io/npm/v/@fsegurai/marked-extended-alert) | Create styled alert boxes for important information |
2071
+ | Code | [@fsegurai/marked-extended-code](https://www.npmjs.com/package/@fsegurai/marked-extended-code) | ![npm](https://img.shields.io/npm/v/@fsegurai/marked-extended-code) | Code blocks with titles, line numbers, highlights and diff markers |
2031
2072
  | Comments | [@fsegurai/marked-extended-comments](https://www.npmjs.com/package/@fsegurai/marked-extended-comments) | ![npm](https://img.shields.io/npm/v/@fsegurai/marked-extended-comments) | Add comment sections with author and timestamp metadata |
2032
2073
  | Embeds | [@fsegurai/marked-extended-embeds](https://www.npmjs.com/package/@fsegurai/marked-extended-embeds) | ![npm](https://img.shields.io/npm/v/@fsegurai/marked-extended-embeds) | Easily embed content from various platforms (YouTube, Twitter, etc.) |
2033
2074
  | Footnote | [@fsegurai/marked-extended-footnote](https://www.npmjs.com/package/@fsegurai/marked-extended-footnote) | ![npm](https://img.shields.io/npm/v/@fsegurai/marked-extended-footnote) | Add footnotes with automatic numbering |
package/dist/index.cjs CHANGED
@@ -1,4 +1,13 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var e={className:`marked-extended-accordion`,prefixId:`accordion-`,animationDuration:`0.3s`,animationEasing:`ease-in-out`,iconPosition:`before`,variants:[],template:null,customizeToken:null},t=[{type:`note`,icon:`<svg class="octicon octicon-info mr-2" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z"></path></svg>`},{type:`tip`,icon:`<svg class="octicon octicon-light-bulb mr-2" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M8 1.5c-2.363 0-4 1.69-4 3.75 0 .984.424 1.625.984 2.304l.214.253c.223.264.47.556.673.848.284.411.537.896.621 1.49a.75.75 0 0 1-1.484.211c-.04-.282-.163-.547-.37-.847a8.456 8.456 0 0 0-.542-.68c-.084-.1-.173-.205-.268-.32C3.201 7.75 2.5 6.766 2.5 5.25 2.5 2.31 4.863 0 8 0s5.5 2.31 5.5 5.25c0 1.516-.701 2.5-1.328 3.259-.095.115-.184.22-.268.319-.207.245-.383.453-.541.681-.208.3-.33.565-.37.847a.751.751 0 0 1-1.485-.212c.084-.593.337-1.078.621-1.489.203-.292.45-.584.673-.848.075-.088.147-.173.213-.253.561-.679.985-1.32.985-2.304 0-2.06-1.637-3.75-4-3.75ZM5.75 12h4.5a.75.75 0 0 1 0 1.5h-4.5a.75.75 0 0 1 0-1.5ZM6 15.25a.75.75 0 0 1 .75-.75h2.5a.75.75 0 0 1 0 1.5h-2.5a.75.75 0 0 1-.75-.75Z"></path></svg>`},{type:`important`,icon:`<svg class="octicon octicon-report mr-2" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M0 1.75C0 .784.784 0 1.75 0h12.5C15.216 0 16 .784 16 1.75v9.5A1.75 1.75 0 0 1 14.25 13H8.06l-2.573 2.573A1.458 1.458 0 0 1 3 14.543V13H1.75A1.75 1.75 0 0 1 0 11.25Zm1.75-.25a.25.25 0 0 0-.25.25v9.5c0 .138.112.25.25.25h2a.75.75 0 0 1 .75.75v2.19l2.72-2.72a.749.749 0 0 1 .53-.22h6.5a.25.25 0 0 0 .25-.25v-9.5a.25.25 0 0 0-.25-.25Zm7 2.25v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 9a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path></svg>`},{type:`warning`,icon:`<svg class="octicon octicon-alert mr-2" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path></svg>`},{type:`caution`,icon:`<svg class="octicon octicon-stop mr-2" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M4.47.22A.749.749 0 0 1 5 0h6c.199 0 .389.079.53.22l4.25 4.25c.141.14.22.331.22.53v6a.749.749 0 0 1-.22.53l-4.25 4.25A.749.749 0 0 1 11 16H5a.749.749 0 0 1-.53-.22L.22 11.53A.749.749 0 0 1 0 11V5c0-.199.079-.389.22-.53Zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5ZM8 4a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5A.75.75 0 0 1 8 4Zm0 8a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z"></path></svg>`}],n=[{name:`title`,defaultValue:``},{name:`expanded`,defaultValue:`false`},{name:`level`,defaultValue:`3`},{name:`duration`,defaultValue:``},{name:`easing`,defaultValue:``},{name:`group`,defaultValue:``},{name:`id`,defaultValue:``},{name:`icon`,defaultValue:``},{name:`iconPosition`,defaultValue:``},{name:`variant`,defaultValue:``},{name:`class`,defaultValue:``}],r=`
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var e=/^[A-Za-z][A-Za-z0-9]*$/,t=/^[A-Za-z0-9-]$/;function n(t,n){if(!e.test(n))throw TypeError(`Invalid class token ${t} "${n}": expected /${e.source}/`)}function r(e){let n=``;for(let r of new TextEncoder().encode(e)){let e=String.fromCharCode(r);n+=t.test(e)?e:`_${r.toString(16).padStart(2,`0`)}`}return n}function i(e){let n=[];for(let r=0;r<e.length;r++){let i=e[r];if(i===`_`){let t=e.slice(r+1,r+3);if(!/^[0-9a-f]{2}$/.test(t))return null;n.push(Number.parseInt(t,16)),r+=2}else if(t.test(i))n.push(i.charCodeAt(0));else return null}try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(new Uint8Array(n))}catch{return null}}function a(e,t,i){return n(`pkg`,e),n(`key`,t),`mx-${e}-${t}-${r(String(i))}`}function o(t,r){n(`pkg`,r);let a=`mx-${r}-`,o={};for(let n of t.split(/\s+/)){if(!n.startsWith(a))continue;let t=n.slice(a.length),r=t.indexOf(`-`);if(r<=0)continue;let s=t.slice(0,r);if(!e.test(s))continue;let c=i(t.slice(r+1));c!==null&&(o[s]=c)}return o}function s(e,t){return o(e.getAttribute(`class`)??``,t)}function c(e,t,n,r){return e.querySelector(`.${a(t,n,r)}`)}var l=/^data[A-Z0-9][a-z0-9]*(?:[A-Z][a-z0-9]*)*$/;function u(e,t){if(!t)return null;let n=t.replace(/["\\]|[^\x20-\x7e]/gu,e=>e===`"`||e===`\\`?`\\${e}`:`\\${e.codePointAt(0).toString(16)} `);return e.querySelector(`[id="${n}"]`)}function d(e){let t=e.toLowerCase();if(!t.startsWith(`data-`))return null;let n=t.split(`-`).slice(1);return n.length===0||n.some((e,t)=>!/^[a-z0-9]+$/.test(e)||t>0&&/^\d/.test(e))?null:`data${n.map(e=>e[0].toUpperCase()+e.slice(1)).join(``)}`}function f(e){return l.test(e)?`data-${e.slice(4).replace(/[A-Z]/g,(e,t)=>`${t?`-`:``}${e.toLowerCase()}`)}`:null}function p(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#39;`)}var m=`marked-extended`;function h(e,t){return`${m}:${e}:${t}`}function g(e,t,n,r){return e.dispatchEvent(new CustomEvent(h(t,n),{bubbles:!0,composed:!0,cancelable:!0,detail:r}))}function _(e,t){let n=5381;for(let t=0;t<e.length;t++)n=(n<<5)+n+e.charCodeAt(t)>>>0;let r=n.toString(36);return t?`${t}-${r}`:r}var v=()=>{};function y(e,t){console.error(`[marked-extended:${e}]`,t)}var b=new WeakMap;function x(e){return typeof e==`function`?{dispose:e}:e??{}}function S(e,t){let n=(e.nodeType===9?e.defaultView:e.ownerDocument?.defaultView)?.MutationObserver??(typeof MutationObserver>`u`?void 0:MutationObserver);if(!n)return null;let r=!1,i=!1,a=new n(()=>{r||i||(r=!0,queueMicrotask(()=>{r=!1,i||t()}))});return a.observe(e,{childList:!0,subtree:!0}),()=>{i=!0,a.disconnect()}}function C(e){let{name:t}=e,n=((n,r={})=>{let i=b.get(n);if(i?.has(t))return v;let{observe:a=!1,...o}=r,s;try{s=x(e.attach(n,o))}catch(e){return y(t,e),v}i||(i=new Map,b.set(n,i));let c=()=>{try{s.refresh?.()}catch(e){y(t,e)}},l=a&&s.refresh?S(n,c):null,u=!1,d=()=>{if(u)return;u=!0;let e=b.get(n);e?.get(t)?.dispose===d&&e.delete(t),l?.();try{s.dispose?.()}catch(e){y(t,e)}};return i.set(t,{dispose:d,refresh:c}),d});return Object.defineProperty(n,"runtimeName",{value:t}),n.isAttached=e=>b.get(e)?.has(t)??!1,n.refresh=e=>{let n=b.get(e)?.get(t);return n?.refresh(),n!==void 0},n}function w(e,t,n,r,i){let a=i=>{let a=i.target,o=(a&&a.nodeType===1?a:a?.parentElement??null)?.closest(n);if(o&&e.contains(o))try{r(i,o)}catch(e){y(`delegated:${t}`,e)}};return e.addEventListener(t,a,i),()=>e.removeEventListener(t,a,i)}var T={className:`marked-extended-accordion`,prefixId:`accordion-`,animationDuration:`0.3s`,animationEasing:`ease-in-out`,iconPosition:`before`,variants:[],template:null,customizeToken:null,unsafeHtml:!1},E=[{type:`note`,icon:`<svg class="octicon octicon-info mr-2" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z"></path></svg>`},{type:`tip`,icon:`<svg class="octicon octicon-light-bulb mr-2" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M8 1.5c-2.363 0-4 1.69-4 3.75 0 .984.424 1.625.984 2.304l.214.253c.223.264.47.556.673.848.284.411.537.896.621 1.49a.75.75 0 0 1-1.484.211c-.04-.282-.163-.547-.37-.847a8.456 8.456 0 0 0-.542-.68c-.084-.1-.173-.205-.268-.32C3.201 7.75 2.5 6.766 2.5 5.25 2.5 2.31 4.863 0 8 0s5.5 2.31 5.5 5.25c0 1.516-.701 2.5-1.328 3.259-.095.115-.184.22-.268.319-.207.245-.383.453-.541.681-.208.3-.33.565-.37.847a.751.751 0 0 1-1.485-.212c.084-.593.337-1.078.621-1.489.203-.292.45-.584.673-.848.075-.088.147-.173.213-.253.561-.679.985-1.32.985-2.304 0-2.06-1.637-3.75-4-3.75ZM5.75 12h4.5a.75.75 0 0 1 0 1.5h-4.5a.75.75 0 0 1 0-1.5ZM6 15.25a.75.75 0 0 1 .75-.75h2.5a.75.75 0 0 1 0 1.5h-2.5a.75.75 0 0 1-.75-.75Z"></path></svg>`},{type:`important`,icon:`<svg class="octicon octicon-report mr-2" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M0 1.75C0 .784.784 0 1.75 0h12.5C15.216 0 16 .784 16 1.75v9.5A1.75 1.75 0 0 1 14.25 13H8.06l-2.573 2.573A1.458 1.458 0 0 1 3 14.543V13H1.75A1.75 1.75 0 0 1 0 11.25Zm1.75-.25a.25.25 0 0 0-.25.25v9.5c0 .138.112.25.25.25h2a.75.75 0 0 1 .75.75v2.19l2.72-2.72a.749.749 0 0 1 .53-.22h6.5a.25.25 0 0 0 .25-.25v-9.5a.25.25 0 0 0-.25-.25Zm7 2.25v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 9a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path></svg>`},{type:`warning`,icon:`<svg class="octicon octicon-alert mr-2" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path></svg>`},{type:`caution`,icon:`<svg class="octicon octicon-stop mr-2" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M4.47.22A.749.749 0 0 1 5 0h6c.199 0 .389.079.53.22l4.25 4.25c.141.14.22.331.22.53v6a.749.749 0 0 1-.22.53l-4.25 4.25A.749.749 0 0 1 11 16H5a.749.749 0 0 1-.53-.22L.22 11.53A.749.749 0 0 1 0 11V5c0-.199.079-.389.22-.53Zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5ZM8 4a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5A.75.75 0 0 1 8 4Zm0 8a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z"></path></svg>`}],D=new Map(E.map(e=>[e.icon,e.type])),O=[{name:`title`,defaultValue:``},{name:`expanded`,defaultValue:`false`},{name:`level`,defaultValue:`3`},{name:`duration`,defaultValue:``},{name:`easing`,defaultValue:``},{name:`group`,defaultValue:``},{name:`id`,defaultValue:``},{name:`icon`,defaultValue:``},{name:`iconPosition`,defaultValue:``},{name:`variant`,defaultValue:``},{name:`class`,defaultValue:``}],k=`
2
+ <details class="{className}{variantClass}{extraClasses}{tokenClasses}" {expandedAttr}>
3
+ <summary class="{className}-header">
4
+ {iconBefore}<{headingTag} class="{className}-title">{title}</{headingTag}>{iconAfter}
5
+ </summary>
6
+ <div class="{className}-content">
7
+ {content}
8
+ </div>
9
+ </details>
10
+ `,A=`
2
11
  <details id="{accordionId}" class="{className}{variantClass}{extraClasses}" {expandedAttr} {nameAttr}{dataAttrs} style="{styleAttr}">
3
12
  <summary class="{className}-header">
4
13
  {iconBefore}<{headingTag} class="{className}-title">{title}</{headingTag}>{iconAfter}
@@ -7,6 +16,6 @@ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{val
7
16
  {content}
8
17
  </div>
9
18
  </details>
10
- `;function i(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#39;`)}function a(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t+e.charCodeAt(n)>>>0;return t.toString(36)}function o(e){if(e.length>=2){let t=e[0],n=e[e.length-1];if(t===`"`&&n===`"`||t===`'`&&n===`'`)return e.slice(1,-1)}return e}function s(e){let t=/^(`{3,}|~{3,})[ \t]*accordion[ \t]*\r?\n([\s\S]*?)\r?\n\1[ \t]*(?:\n|$)/.exec(e);return t?{raw:t[0],body:t[2]}:null}function c(e){let t={},r={};n.forEach(e=>{t[e.name]=e.defaultValue});let i=e.split(`
11
- `),a=0;for(;a<i.length&&i[a].trim()===``;)a++;let s=/^([\w-]+)\s*:\s*(.*)$/,c=/^---\s*$/;if(!(a<i.length&&s.test(i[a].trim())))return{attrs:t,dataAttrs:r,content:e.trim()};let l=-1;for(let e=a;e<i.length;e++)if(c.test(i[e])){l=e;break}if(l===-1)return{attrs:t,dataAttrs:r,content:e.trim()};let u=new Set(n.map(e=>e.name)),d=/^data-[\w-]+$/;for(let e=a;e<l;e++){let n=i[e].trim();if(n===``)continue;let a=s.exec(n);if(!a)continue;let[,c,l]=a,f=o(l.trim());u.has(c)?t[c]=f:d.test(c)&&(r[c]=f)}return{attrs:t,dataAttrs:r,content:i.slice(l+1).join(`
12
- `).trim()}}function l(e){let t=e.trim().toLowerCase();return t===`true`||t===`yes`||t===`1`}function u(e){let{prefixId:t,title:n,titleTokens:o,expanded:s,level:c,className:l,animationDuration:u,animationEasing:d,template:f,group:p,customId:m,icon:h,iconPosition:g,variant:_,variantIcon:v,extraClasses:y,dataAttrs:b,raw:x,tokens:S,parser:C}=e,w=m?i(m):`${t}${a(x)}`,T=S&&S.length>0?C.parse(S):``,E=o&&o.length>0?C.parseInline(o):i(n),D=`h${c}`,O=p?`name="${i(p)}"`:``,k=_?` ${l}-${_}`:``,A=y?` ${i(y)}`:``,j=Object.entries(b||{}).map(([e,t])=>` ${e}="${i(t)}"`).join(``),M=`--${l}-animation-duration: ${i(u)}; --${l}-transition-timing: ${i(d)};`,N=``;h?N=`<span class="${l}-icon" aria-hidden="true">${i(h)}</span>`:v&&(N=`<span class="${l}-icon" aria-hidden="true">${v}</span>`);let P=g===`after`?``:N,F=g===`after`?N:``,I=f||r,L={accordionId:w,headingTag:D,title:E,content:T,expanded:s?`true`:`false`,expandedAttr:s?`open`:``,nameAttr:O,dataAttrs:j,styleAttr:M,variantClass:k,extraClasses:A,iconBefore:P,iconAfter:F,icon:N,animationDuration:u,className:l};return I.replace(/\{(\w+)\}/g,(e,t)=>Object.hasOwn(L,t)?L[t]:e)}function d(e){let{className:n,prefixId:r,animationDuration:i,animationEasing:a,iconPosition:o,template:u}=e,d=new Map(t.map(e=>[e.type,e]));return e.variants.forEach(e=>{d.set(e.type,e)}),{name:`accordion`,level:`block`,start(e){let t=/(?:^|\n)(?:`{3,}|~{3,})[ \t]*accordion\b/.exec(e);return t?t.index:void 0},tokenizer(e){let t=s(e);if(!t)return;let{attrs:f,dataAttrs:p,content:m}=c(t.body),h=this.lexer.blockTokens(m),g=f.title.replace(/</g,`&lt;`).replace(/>/g,`&gt;`),_=this.lexer.inlineTokens(g),v=parseInt(f.level,10),y=f.variant,b=y?d.get(y):void 0,x=f.iconPosition,S=x===`before`||x===`after`?x:o;return{type:`accordion`,raw:t.raw,tokens:h,titleTokens:_,meta:{prefixId:r,title:f.title,expanded:l(f.expanded),level:v>=1&&v<=6?v:3,className:n,animationDuration:f.duration||i,animationEasing:f.easing||a,template:u,group:f.group,customId:f.id,icon:f.icon,iconPosition:S,variant:b?b.type:``,variantIcon:b?b.icon:``,extraClasses:f.class,dataAttrs:p}}}}}function f(){return{name:`accordion`,renderer(e){let t=e;return u({...t.meta,raw:t.raw,titleTokens:t.titleTokens||[],tokens:t.tokens||[],parser:this.parser})}}}function p(t={}){let n={...e,...t};return{walkTokens(e){e.type===`accordion`&&n.customizeToken&&typeof n.customizeToken==`function`&&n.customizeToken(e)},extensions:[d(n),f()]}}exports.default=p;
19
+ `;function j(e,t){let{group:n,animationDuration:r,animationEasing:i,dataAttrs:o}=e,s=[a(`accordion`,`id`,t)];n&&s.push(a(`accordion`,`group`,n)),r&&r!==T.animationDuration&&s.push(a(`accordion`,`duration`,r)),i&&i!==T.animationEasing&&s.push(a(`accordion`,`easing`,i));for(let[e,t]of Object.entries(o||{})){let n=d(e);n&&s.push(a(`accordion`,n,t))}return` ${s.join(` `)}`}function M(e,t,n){let r=n?void 0:D.get(t);return r?`<span class="${e}-icon ${a(`accordion`,`icon`,r)}" aria-hidden="true"></span>`:`<span class="${e}-icon" aria-hidden="true">${t}</span>`}function N(e){let{prefixId:t,title:n,titleTokens:r,expanded:i,level:a,className:o,animationDuration:s,animationEasing:c,template:l,group:u,customId:d,icon:f,iconPosition:m,variant:h,variantIcon:g,extraClasses:v,dataAttrs:y,unsafeHtml:b=!1,raw:x,tokens:S,parser:C}=e,w=d||`${t}${_(x)}`,T=p(w),E=S&&S.length>0?C.parse(S):``,D=r&&r.length>0?C.parseInline(r):p(n),O=`h${a}`,N=u?`name="${p(u)}"`:``,P=h?` ${o}-${h}`:``,F=v?` ${p(v)}`:``,I=Object.entries(y||{}).map(([e,t])=>` ${e}="${p(t)}"`).join(``),L=`--${o}-animation-duration: ${p(s)}; --${o}-transition-timing: ${p(c)};`,R=``;f?R=`<span class="${o}-icon" aria-hidden="true">${p(f)}</span>`:g&&(R=M(o,g,b));let z=m===`after`?``:R,B=m===`after`?R:``,V=l||(b?A:k),H={accordionId:T,headingTag:O,title:D,content:E,expanded:i?`true`:`false`,expandedAttr:i?`open`:``,nameAttr:N,dataAttrs:I,styleAttr:L,variantClass:P,extraClasses:F,tokenClasses:b?``:j(e,w),iconBefore:z,iconAfter:B,icon:R,animationDuration:s,className:o};return V.replace(/\{(\w+)\}/g,(e,t)=>Object.hasOwn(H,t)?H[t]:e)}function P(e){if(e.length>=2){let t=e[0],n=e[e.length-1];if(t===`"`&&n===`"`||t===`'`&&n===`'`)return e.slice(1,-1)}return e}function F(e){let t=/^(`{3,}|~{3,})[ \t]*accordion[ \t]*\r?\n([\s\S]*?)\r?\n\1[ \t]*(?:\n|$)/.exec(e);return t?{raw:t[0],body:t[2]}:null}function I(e){let t={},n={};O.forEach(e=>{t[e.name]=e.defaultValue});let r=e.split(`
20
+ `),i=0;for(;i<r.length&&r[i].trim()===``;)i++;let a=/^([\w-]+)\s*:\s*(.*)$/,o=/^---\s*$/;if(!(i<r.length&&a.test(r[i].trim())))return{attrs:t,dataAttrs:n,content:e.trim()};let s=-1;for(let e=i;e<r.length;e++)if(o.test(r[e])){s=e;break}if(s===-1)return{attrs:t,dataAttrs:n,content:e.trim()};let c=new Set(O.map(e=>e.name)),l=/^data-[\w-]+$/;for(let e=i;e<s;e++){let i=r[e].trim();if(i===``)continue;let o=a.exec(i);if(!o)continue;let[,s,u]=o,d=P(u.trim());c.has(s)?t[s]=d:l.test(s)&&(n[s]=d)}return{attrs:t,dataAttrs:n,content:r.slice(s+1).join(`
21
+ `).trim()}}function L(e){let t=e.trim().toLowerCase();return t===`true`||t===`yes`||t===`1`}function R(e){let{className:t,prefixId:n,animationDuration:r,animationEasing:i,iconPosition:a,template:o,unsafeHtml:s}=e,c=new Map(E.map(e=>[e.type,e]));return e.variants.forEach(e=>{c.set(e.type,e)}),{name:`accordion`,level:`block`,start(e){let t=/(?:^|\n)(?:`{3,}|~{3,})[ \t]*accordion\b/.exec(e);return t?t.index:void 0},tokenizer(e){let l=F(e);if(!l)return;let{attrs:u,dataAttrs:d,content:f}=I(l.body),p=this.lexer.blockTokens(f),m=u.title.replace(/</g,`&lt;`).replace(/>/g,`&gt;`),h=this.lexer.inlineTokens(m),g=parseInt(u.level,10),_=u.variant,v=_?c.get(_):void 0,y=u.iconPosition,b=y===`before`||y===`after`?y:a;return{type:`accordion`,raw:l.raw,tokens:p,titleTokens:h,meta:{prefixId:n,title:u.title,expanded:L(u.expanded),level:g>=1&&g<=6?g:3,className:t,animationDuration:u.duration||r,animationEasing:u.easing||i,template:o,group:u.group,customId:u.id,icon:u.icon,iconPosition:b,variant:v?v.type:``,variantIcon:v?v.icon:``,extraClasses:u.class,dataAttrs:d,unsafeHtml:s}}}}}function z(){return{name:`accordion`,renderer(e){let t=e;return N({...t.meta,raw:t.raw,titleTokens:t.titleTokens||[],tokens:t.tokens||[],parser:this.parser})}}}var B=`accordion`,V=`details[class*="mx-accordion-id-"]`;function H(e,t){let n=s(e,B);n.duration&&e.style.setProperty(`--${t}-animation-duration`,n.duration),n.easing&&e.style.setProperty(`--${t}-transition-timing`,n.easing);for(let[t,r]of Object.entries(n)){let n=f(t);n&&!e.hasAttribute(n)&&e.setAttribute(n,r)}}function U(e,t){if(u(e,t))return null;let n=c(e,B,`id`,t);return n?.tagName===`DETAILS`?n:null}var W=C({name:B,attach(e,t){let n=t.className??T.className,r=()=>{for(let t of e.querySelectorAll(V))H(t,n)};r();let i=t=>{let n=t.target;if(!n||n.nodeType!==1||!n.matches(V)||!e.contains(n))return;let r=s(n,B),i=r.group??``;if(n.open&&i)for(let t of e.querySelectorAll(V))t!==n&&t.open&&s(t,B).group===i&&(t.open=!1);g(n,B,`toggle`,{id:r.id??``,open:n.open,group:i})};e.addEventListener(`toggle`,i,!0);let a=w(e,`click`,`a[href^="#"]`,(t,n)=>{let r=n.getAttribute(`href`)?.slice(1)??``;if(!r)return;let i=r;try{i=decodeURIComponent(r)}catch{}let a=U(e,i);a&&(t.preventDefault(),a.open||=!0,a.scrollIntoView?.({block:`start`,behavior:`smooth`}))});return{refresh:r,dispose:()=>{e.removeEventListener(`toggle`,i,!0),a()}}}});function G(e={}){let t={...T,...e};return{walkTokens(e){e.type===`accordion`&&t.customizeToken&&typeof t.customizeToken==`function`&&t.customizeToken(e)},extensions:[R(t),z()]}}exports.attachAccordion=W,exports.default=G;
package/dist/index.esm.js CHANGED
@@ -1,5 +1,171 @@
1
+ var e = /^[A-Za-z][A-Za-z0-9]*$/, t = /^[A-Za-z0-9-]$/;
2
+ function n(t, n) {
3
+ if (!e.test(n)) throw TypeError(`Invalid class token ${t} "${n}": expected /${e.source}/`);
4
+ }
5
+ function r(e) {
6
+ let n = "";
7
+ for (let r of new TextEncoder().encode(e)) {
8
+ let e = String.fromCharCode(r);
9
+ n += t.test(e) ? e : `_${r.toString(16).padStart(2, "0")}`;
10
+ }
11
+ return n;
12
+ }
13
+ function i(e) {
14
+ let n = [];
15
+ for (let r = 0; r < e.length; r++) {
16
+ let i = e[r];
17
+ if (i === "_") {
18
+ let t = e.slice(r + 1, r + 3);
19
+ if (!/^[0-9a-f]{2}$/.test(t)) return null;
20
+ n.push(Number.parseInt(t, 16)), r += 2;
21
+ } else if (t.test(i)) n.push(i.charCodeAt(0));
22
+ else return null;
23
+ }
24
+ try {
25
+ return new TextDecoder("utf-8", { fatal: !0 }).decode(new Uint8Array(n));
26
+ } catch {
27
+ return null;
28
+ }
29
+ }
30
+ function a(e, t, i) {
31
+ return n("pkg", e), n("key", t), `mx-${e}-${t}-${r(String(i))}`;
32
+ }
33
+ function o(t, r) {
34
+ n("pkg", r);
35
+ let a = `mx-${r}-`, o = {};
36
+ for (let n of t.split(/\s+/)) {
37
+ if (!n.startsWith(a)) continue;
38
+ let t = n.slice(a.length), r = t.indexOf("-");
39
+ if (r <= 0) continue;
40
+ let s = t.slice(0, r);
41
+ if (!e.test(s)) continue;
42
+ let c = i(t.slice(r + 1));
43
+ c !== null && (o[s] = c);
44
+ }
45
+ return o;
46
+ }
47
+ function s(e, t) {
48
+ return o(e.getAttribute("class") ?? "", t);
49
+ }
50
+ function c(e, t, n, r) {
51
+ return e.querySelector(`.${a(t, n, r)}`);
52
+ }
53
+ var l = /^data[A-Z0-9][a-z0-9]*(?:[A-Z][a-z0-9]*)*$/;
54
+ function u(e, t) {
55
+ if (!t) return null;
56
+ let n = t.replace(/["\\]|[^\x20-\x7e]/gu, (e) => e === "\"" || e === "\\" ? `\\${e}` : `\\${e.codePointAt(0).toString(16)} `);
57
+ return e.querySelector(`[id="${n}"]`);
58
+ }
59
+ function d(e) {
60
+ let t = e.toLowerCase();
61
+ if (!t.startsWith("data-")) return null;
62
+ let n = t.split("-").slice(1);
63
+ return n.length === 0 || n.some((e, t) => !/^[a-z0-9]+$/.test(e) || t > 0 && /^\d/.test(e)) ? null : `data${n.map((e) => e[0].toUpperCase() + e.slice(1)).join("")}`;
64
+ }
65
+ function f(e) {
66
+ return l.test(e) ? `data-${e.slice(4).replace(/[A-Z]/g, (e, t) => `${t ? "-" : ""}${e.toLowerCase()}`)}` : null;
67
+ }
68
+ //#endregion
69
+ //#region ../core/src/escape.ts
70
+ function p(e) {
71
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
72
+ }
73
+ function m(e, t) {
74
+ return `marked-extended:${e}:${t}`;
75
+ }
76
+ function h(e, t, n, r) {
77
+ return e.dispatchEvent(new CustomEvent(m(t, n), {
78
+ bubbles: !0,
79
+ composed: !0,
80
+ cancelable: !0,
81
+ detail: r
82
+ }));
83
+ }
84
+ //#endregion
85
+ //#region ../core/src/hash.ts
86
+ function g(e, t) {
87
+ let n = 5381;
88
+ for (let t = 0; t < e.length; t++) n = (n << 5) + n + e.charCodeAt(t) >>> 0;
89
+ let r = n.toString(36);
90
+ return t ? `${t}-${r}` : r;
91
+ }
92
+ //#endregion
93
+ //#region ../core/src/runtime.ts
94
+ var _ = () => {};
95
+ function v(e, t) {
96
+ console.error(`[marked-extended:${e}]`, t);
97
+ }
98
+ var y = /* @__PURE__ */ new WeakMap();
99
+ function b(e) {
100
+ return typeof e == "function" ? { dispose: e } : e ?? {};
101
+ }
102
+ function x(e, t) {
103
+ let n = (e.nodeType === 9 ? e.defaultView : e.ownerDocument?.defaultView)?.MutationObserver ?? (typeof MutationObserver > "u" ? void 0 : MutationObserver);
104
+ if (!n) return null;
105
+ let r = !1, i = !1, a = new n(() => {
106
+ r || i || (r = !0, queueMicrotask(() => {
107
+ r = !1, i || t();
108
+ }));
109
+ });
110
+ return a.observe(e, {
111
+ childList: !0,
112
+ subtree: !0
113
+ }), () => {
114
+ i = !0, a.disconnect();
115
+ };
116
+ }
117
+ function S(e) {
118
+ let { name: t } = e, n = ((n, r = {}) => {
119
+ let i = y.get(n);
120
+ if (i?.has(t)) return _;
121
+ let { observe: a = !1, ...o } = r, s;
122
+ try {
123
+ s = b(e.attach(n, o));
124
+ } catch (e) {
125
+ return v(t, e), _;
126
+ }
127
+ i || (i = /* @__PURE__ */ new Map(), y.set(n, i));
128
+ let c = () => {
129
+ try {
130
+ s.refresh?.();
131
+ } catch (e) {
132
+ v(t, e);
133
+ }
134
+ }, l = a && s.refresh ? x(n, c) : null, u = !1, d = () => {
135
+ if (u) return;
136
+ u = !0;
137
+ let e = y.get(n);
138
+ e?.get(t)?.dispose === d && e.delete(t), l?.();
139
+ try {
140
+ s.dispose?.();
141
+ } catch (e) {
142
+ v(t, e);
143
+ }
144
+ };
145
+ return i.set(t, {
146
+ dispose: d,
147
+ refresh: c
148
+ }), d;
149
+ });
150
+ return Object.defineProperty(n, "runtimeName", { value: t }), n.isAttached = (e) => y.get(e)?.has(t) ?? !1, n.refresh = (e) => {
151
+ let n = y.get(e)?.get(t);
152
+ return n?.refresh(), n !== void 0;
153
+ }, n;
154
+ }
155
+ function C(e, t, n, r, i) {
156
+ let a = (i) => {
157
+ let a = i.target, o = (a && a.nodeType === 1 ? a : a?.parentElement ?? null)?.closest(n);
158
+ if (o && e.contains(o)) try {
159
+ r(i, o);
160
+ } catch (e) {
161
+ v(`delegated:${t}`, e);
162
+ }
163
+ };
164
+ return e.addEventListener(t, a, i), () => e.removeEventListener(t, a, i);
165
+ }
166
+ //#endregion
1
167
  //#region src/utils/constants.ts
2
- var e = {
168
+ var w = {
3
169
  className: "marked-extended-accordion",
4
170
  prefixId: "accordion-",
5
171
  animationDuration: "0.3s",
@@ -7,8 +173,9 @@ var e = {
7
173
  iconPosition: "before",
8
174
  variants: [],
9
175
  template: null,
10
- customizeToken: null
11
- }, t = [
176
+ customizeToken: null,
177
+ unsafeHtml: !1
178
+ }, T = [
12
179
  {
13
180
  type: "note",
14
181
  icon: "<svg class=\"octicon octicon-info mr-2\" viewBox=\"0 0 16 16\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z\"></path></svg>"
@@ -29,7 +196,7 @@ var e = {
29
196
  type: "caution",
30
197
  icon: "<svg class=\"octicon octicon-stop mr-2\" viewBox=\"0 0 16 16\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"M4.47.22A.749.749 0 0 1 5 0h6c.199 0 .389.079.53.22l4.25 4.25c.141.14.22.331.22.53v6a.749.749 0 0 1-.22.53l-4.25 4.25A.749.749 0 0 1 11 16H5a.749.749 0 0 1-.53-.22L.22 11.53A.749.749 0 0 1 0 11V5c0-.199.079-.389.22-.53Zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5ZM8 4a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5A.75.75 0 0 1 8 4Zm0 8a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z\"></path></svg>"
31
198
  }
32
- ], n = [
199
+ ], E = new Map(T.map((e) => [e.icon, e.type])), D = [
33
200
  {
34
201
  name: "title",
35
202
  defaultValue: ""
@@ -74,106 +241,110 @@ var e = {
74
241
  name: "class",
75
242
  defaultValue: ""
76
243
  }
77
- ], r = "\n<details id=\"{accordionId}\" class=\"{className}{variantClass}{extraClasses}\" {expandedAttr} {nameAttr}{dataAttrs} style=\"{styleAttr}\">\n <summary class=\"{className}-header\">\n {iconBefore}<{headingTag} class=\"{className}-title\">{title}</{headingTag}>{iconAfter}\n </summary>\n <div class=\"{className}-content\">\n {content}\n </div>\n</details>\n";
244
+ ], O = "\n<details class=\"{className}{variantClass}{extraClasses}{tokenClasses}\" {expandedAttr}>\n <summary class=\"{className}-header\">\n {iconBefore}<{headingTag} class=\"{className}-title\">{title}</{headingTag}>{iconAfter}\n </summary>\n <div class=\"{className}-content\">\n {content}\n </div>\n</details>\n", k = "\n<details id=\"{accordionId}\" class=\"{className}{variantClass}{extraClasses}\" {expandedAttr} {nameAttr}{dataAttrs} style=\"{styleAttr}\">\n <summary class=\"{className}-header\">\n {iconBefore}<{headingTag} class=\"{className}-title\">{title}</{headingTag}>{iconAfter}\n </summary>\n <div class=\"{className}-content\">\n {content}\n </div>\n</details>\n";
78
245
  //#endregion
79
- //#region src/markdown-utils.ts
80
- function i(e) {
81
- return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
246
+ //#region src/renderer.ts
247
+ function A(e, t) {
248
+ let { group: n, animationDuration: r, animationEasing: i, dataAttrs: o } = e, s = [a("accordion", "id", t)];
249
+ n && s.push(a("accordion", "group", n)), r && r !== w.animationDuration && s.push(a("accordion", "duration", r)), i && i !== w.animationEasing && s.push(a("accordion", "easing", i));
250
+ for (let [e, t] of Object.entries(o || {})) {
251
+ let n = d(e);
252
+ n && s.push(a("accordion", n, t));
253
+ }
254
+ return ` ${s.join(" ")}`;
255
+ }
256
+ function j(e, t, n) {
257
+ let r = n ? void 0 : E.get(t);
258
+ return r ? `<span class="${e}-icon ${a("accordion", "icon", r)}" aria-hidden="true"></span>` : `<span class="${e}-icon" aria-hidden="true">${t}</span>`;
259
+ }
260
+ function M(e) {
261
+ let { prefixId: t, title: n, titleTokens: r, expanded: i, level: a, className: o, animationDuration: s, animationEasing: c, template: l, group: u, customId: d, icon: f, iconPosition: m, variant: h, variantIcon: _, extraClasses: v, dataAttrs: y, unsafeHtml: b = !1, raw: x, tokens: S, parser: C } = e, w = d || `${t}${g(x)}`, T = p(w), E = S && S.length > 0 ? C.parse(S) : "", D = r && r.length > 0 ? C.parseInline(r) : p(n), M = `h${a}`, N = u ? `name="${p(u)}"` : "", P = h ? ` ${o}-${h}` : "", F = v ? ` ${p(v)}` : "", I = Object.entries(y || {}).map(([e, t]) => ` ${e}="${p(t)}"`).join(""), L = `--${o}-animation-duration: ${p(s)}; --${o}-transition-timing: ${p(c)};`, R = "";
262
+ f ? R = `<span class="${o}-icon" aria-hidden="true">${p(f)}</span>` : _ && (R = j(o, _, b));
263
+ let z = m === "after" ? "" : R, B = m === "after" ? R : "", V = l || (b ? k : O), H = {
264
+ accordionId: T,
265
+ headingTag: M,
266
+ title: D,
267
+ content: E,
268
+ expanded: i ? "true" : "false",
269
+ expandedAttr: i ? "open" : "",
270
+ nameAttr: N,
271
+ dataAttrs: I,
272
+ styleAttr: L,
273
+ variantClass: P,
274
+ extraClasses: F,
275
+ tokenClasses: b ? "" : A(e, w),
276
+ iconBefore: z,
277
+ iconAfter: B,
278
+ icon: R,
279
+ animationDuration: s,
280
+ className: o
281
+ };
282
+ return V.replace(/\{(\w+)\}/g, (e, t) => Object.hasOwn(H, t) ? H[t] : e);
82
283
  }
83
284
  //#endregion
84
285
  //#region src/utils/props.ts
85
- function a(e) {
86
- let t = 5381;
87
- for (let n = 0; n < e.length; n++) t = (t << 5) + t + e.charCodeAt(n) >>> 0;
88
- return t.toString(36);
89
- }
90
- function o(e) {
286
+ function N(e) {
91
287
  if (e.length >= 2) {
92
288
  let t = e[0], n = e[e.length - 1];
93
289
  if (t === "\"" && n === "\"" || t === "'" && n === "'") return e.slice(1, -1);
94
290
  }
95
291
  return e;
96
292
  }
97
- function s(e) {
293
+ function P(e) {
98
294
  let t = /^(`{3,}|~{3,})[ \t]*accordion[ \t]*\r?\n([\s\S]*?)\r?\n\1[ \t]*(?:\n|$)/.exec(e);
99
295
  return t ? {
100
296
  raw: t[0],
101
297
  body: t[2]
102
298
  } : null;
103
299
  }
104
- function c(e) {
105
- let t = {}, r = {};
106
- n.forEach((e) => {
300
+ function F(e) {
301
+ let t = {}, n = {};
302
+ D.forEach((e) => {
107
303
  t[e.name] = e.defaultValue;
108
304
  });
109
- let i = e.split("\n"), a = 0;
110
- for (; a < i.length && i[a].trim() === "";) a++;
111
- let s = /^([\w-]+)\s*:\s*(.*)$/, c = /^---\s*$/;
112
- if (!(a < i.length && s.test(i[a].trim()))) return {
305
+ let r = e.split("\n"), i = 0;
306
+ for (; i < r.length && r[i].trim() === "";) i++;
307
+ let a = /^([\w-]+)\s*:\s*(.*)$/, o = /^---\s*$/;
308
+ if (!(i < r.length && a.test(r[i].trim()))) return {
113
309
  attrs: t,
114
- dataAttrs: r,
310
+ dataAttrs: n,
115
311
  content: e.trim()
116
312
  };
117
- let l = -1;
118
- for (let e = a; e < i.length; e++) if (c.test(i[e])) {
119
- l = e;
313
+ let s = -1;
314
+ for (let e = i; e < r.length; e++) if (o.test(r[e])) {
315
+ s = e;
120
316
  break;
121
317
  }
122
- if (l === -1) return {
318
+ if (s === -1) return {
123
319
  attrs: t,
124
- dataAttrs: r,
320
+ dataAttrs: n,
125
321
  content: e.trim()
126
322
  };
127
- let u = new Set(n.map((e) => e.name)), d = /^data-[\w-]+$/;
128
- for (let e = a; e < l; e++) {
129
- let n = i[e].trim();
130
- if (n === "") continue;
131
- let a = s.exec(n);
132
- if (!a) continue;
133
- let [, c, l] = a, f = o(l.trim());
134
- u.has(c) ? t[c] = f : d.test(c) && (r[c] = f);
323
+ let c = new Set(D.map((e) => e.name)), l = /^data-[\w-]+$/;
324
+ for (let e = i; e < s; e++) {
325
+ let i = r[e].trim();
326
+ if (i === "") continue;
327
+ let o = a.exec(i);
328
+ if (!o) continue;
329
+ let [, s, u] = o, d = N(u.trim());
330
+ c.has(s) ? t[s] = d : l.test(s) && (n[s] = d);
135
331
  }
136
332
  return {
137
333
  attrs: t,
138
- dataAttrs: r,
139
- content: i.slice(l + 1).join("\n").trim()
334
+ dataAttrs: n,
335
+ content: r.slice(s + 1).join("\n").trim()
140
336
  };
141
337
  }
142
- function l(e) {
338
+ function I(e) {
143
339
  let t = e.trim().toLowerCase();
144
340
  return t === "true" || t === "yes" || t === "1";
145
341
  }
146
342
  //#endregion
147
- //#region src/renderer.ts
148
- function u(e) {
149
- let { prefixId: t, title: n, titleTokens: o, expanded: s, level: c, className: l, animationDuration: u, animationEasing: d, template: f, group: p, customId: m, icon: h, iconPosition: g, variant: _, variantIcon: v, extraClasses: y, dataAttrs: b, raw: x, tokens: S, parser: C } = e, w = m ? i(m) : `${t}${a(x)}`, T = S && S.length > 0 ? C.parse(S) : "", E = o && o.length > 0 ? C.parseInline(o) : i(n), D = `h${c}`, O = p ? `name="${i(p)}"` : "", k = _ ? ` ${l}-${_}` : "", A = y ? ` ${i(y)}` : "", j = Object.entries(b || {}).map(([e, t]) => ` ${e}="${i(t)}"`).join(""), M = `--${l}-animation-duration: ${i(u)}; --${l}-transition-timing: ${i(d)};`, N = "";
150
- h ? N = `<span class="${l}-icon" aria-hidden="true">${i(h)}</span>` : v && (N = `<span class="${l}-icon" aria-hidden="true">${v}</span>`);
151
- let P = g === "after" ? "" : N, F = g === "after" ? N : "", I = f || r, L = {
152
- accordionId: w,
153
- headingTag: D,
154
- title: E,
155
- content: T,
156
- expanded: s ? "true" : "false",
157
- expandedAttr: s ? "open" : "",
158
- nameAttr: O,
159
- dataAttrs: j,
160
- styleAttr: M,
161
- variantClass: k,
162
- extraClasses: A,
163
- iconBefore: P,
164
- iconAfter: F,
165
- icon: N,
166
- animationDuration: u,
167
- className: l
168
- };
169
- return I.replace(/\{(\w+)\}/g, (e, t) => Object.hasOwn(L, t) ? L[t] : e);
170
- }
171
- //#endregion
172
343
  //#region src/tokenizer.ts
173
- function d(e) {
174
- let { className: n, prefixId: r, animationDuration: i, animationEasing: a, iconPosition: o, template: u } = e, d = new Map(t.map((e) => [e.type, e]));
344
+ function L(e) {
345
+ let { className: t, prefixId: n, animationDuration: r, animationEasing: i, iconPosition: a, template: o, unsafeHtml: s } = e, c = new Map(T.map((e) => [e.type, e]));
175
346
  return e.variants.forEach((e) => {
176
- d.set(e.type, e);
347
+ c.set(e.type, e);
177
348
  }), {
178
349
  name: "accordion",
179
350
  level: "block",
@@ -182,42 +353,43 @@ function d(e) {
182
353
  return t ? t.index : void 0;
183
354
  },
184
355
  tokenizer(e) {
185
- let t = s(e);
186
- if (!t) return;
187
- let { attrs: f, dataAttrs: p, content: m } = c(t.body), h = this.lexer.blockTokens(m), g = f.title.replace(/</g, "&lt;").replace(/>/g, "&gt;"), _ = this.lexer.inlineTokens(g), v = parseInt(f.level, 10), y = f.variant, b = y ? d.get(y) : void 0, x = f.iconPosition, S = x === "before" || x === "after" ? x : o;
356
+ let l = P(e);
357
+ if (!l) return;
358
+ let { attrs: u, dataAttrs: d, content: f } = F(l.body), p = this.lexer.blockTokens(f), m = u.title.replace(/</g, "&lt;").replace(/>/g, "&gt;"), h = this.lexer.inlineTokens(m), g = parseInt(u.level, 10), _ = u.variant, v = _ ? c.get(_) : void 0, y = u.iconPosition, b = y === "before" || y === "after" ? y : a;
188
359
  return {
189
360
  type: "accordion",
190
- raw: t.raw,
191
- tokens: h,
192
- titleTokens: _,
361
+ raw: l.raw,
362
+ tokens: p,
363
+ titleTokens: h,
193
364
  meta: {
194
- prefixId: r,
195
- title: f.title,
196
- expanded: l(f.expanded),
197
- level: v >= 1 && v <= 6 ? v : 3,
198
- className: n,
199
- animationDuration: f.duration || i,
200
- animationEasing: f.easing || a,
201
- template: u,
202
- group: f.group,
203
- customId: f.id,
204
- icon: f.icon,
205
- iconPosition: S,
206
- variant: b ? b.type : "",
207
- variantIcon: b ? b.icon : "",
208
- extraClasses: f.class,
209
- dataAttrs: p
365
+ prefixId: n,
366
+ title: u.title,
367
+ expanded: I(u.expanded),
368
+ level: g >= 1 && g <= 6 ? g : 3,
369
+ className: t,
370
+ animationDuration: u.duration || r,
371
+ animationEasing: u.easing || i,
372
+ template: o,
373
+ group: u.group,
374
+ customId: u.id,
375
+ icon: u.icon,
376
+ iconPosition: b,
377
+ variant: v ? v.type : "",
378
+ variantIcon: v ? v.icon : "",
379
+ extraClasses: u.class,
380
+ dataAttrs: d,
381
+ unsafeHtml: s
210
382
  }
211
383
  };
212
384
  }
213
385
  };
214
386
  }
215
- function f() {
387
+ function R() {
216
388
  return {
217
389
  name: "accordion",
218
390
  renderer(e) {
219
391
  let t = e;
220
- return u({
392
+ return M({
221
393
  ...t.meta,
222
394
  raw: t.raw,
223
395
  titleTokens: t.titleTokens || [],
@@ -228,18 +400,74 @@ function f() {
228
400
  };
229
401
  }
230
402
  //#endregion
403
+ //#region src/runtime.ts
404
+ var z = "accordion", B = "details[class*=\"mx-accordion-id-\"]";
405
+ function V(e, t) {
406
+ let n = s(e, z);
407
+ n.duration && e.style.setProperty(`--${t}-animation-duration`, n.duration), n.easing && e.style.setProperty(`--${t}-transition-timing`, n.easing);
408
+ for (let [t, r] of Object.entries(n)) {
409
+ let n = f(t);
410
+ n && !e.hasAttribute(n) && e.setAttribute(n, r);
411
+ }
412
+ }
413
+ function H(e, t) {
414
+ if (u(e, t)) return null;
415
+ let n = c(e, z, "id", t);
416
+ return n?.tagName === "DETAILS" ? n : null;
417
+ }
418
+ var U = S({
419
+ name: z,
420
+ attach(e, t) {
421
+ let n = t.className ?? w.className, r = () => {
422
+ for (let t of e.querySelectorAll(B)) V(t, n);
423
+ };
424
+ r();
425
+ let i = (t) => {
426
+ let n = t.target;
427
+ if (!n || n.nodeType !== 1 || !n.matches(B) || !e.contains(n)) return;
428
+ let r = s(n, z), i = r.group ?? "";
429
+ if (n.open && i) for (let t of e.querySelectorAll(B)) t !== n && t.open && s(t, z).group === i && (t.open = !1);
430
+ h(n, z, "toggle", {
431
+ id: r.id ?? "",
432
+ open: n.open,
433
+ group: i
434
+ });
435
+ };
436
+ e.addEventListener("toggle", i, !0);
437
+ let a = C(e, "click", "a[href^=\"#\"]", (t, n) => {
438
+ let r = n.getAttribute("href")?.slice(1) ?? "";
439
+ if (!r) return;
440
+ let i = r;
441
+ try {
442
+ i = decodeURIComponent(r);
443
+ } catch {}
444
+ let a = H(e, i);
445
+ a && (t.preventDefault(), a.open ||= !0, a.scrollIntoView?.({
446
+ block: "start",
447
+ behavior: "smooth"
448
+ }));
449
+ });
450
+ return {
451
+ refresh: r,
452
+ dispose: () => {
453
+ e.removeEventListener("toggle", i, !0), a();
454
+ }
455
+ };
456
+ }
457
+ });
458
+ //#endregion
231
459
  //#region src/index.ts
232
- function p(t = {}) {
233
- let n = {
234
- ...e,
235
- ...t
460
+ function W(e = {}) {
461
+ let t = {
462
+ ...w,
463
+ ...e
236
464
  };
237
465
  return {
238
466
  walkTokens(e) {
239
- e.type === "accordion" && n.customizeToken && typeof n.customizeToken == "function" && n.customizeToken(e);
467
+ e.type === "accordion" && t.customizeToken && typeof t.customizeToken == "function" && t.customizeToken(e);
240
468
  },
241
- extensions: [d(n), f()]
469
+ extensions: [L(t), R()]
242
470
  };
243
471
  }
244
472
  //#endregion
245
- export { p as default };
473
+ export { U as attachAccordion, W as default };
package/dist/index.umd.js CHANGED
@@ -1,4 +1,13 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.markedExtendedAccordion={}))})(this,function(e){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var t={className:`marked-extended-accordion`,prefixId:`accordion-`,animationDuration:`0.3s`,animationEasing:`ease-in-out`,iconPosition:`before`,variants:[],template:null,customizeToken:null},n=[{type:`note`,icon:`<svg class="octicon octicon-info mr-2" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z"></path></svg>`},{type:`tip`,icon:`<svg class="octicon octicon-light-bulb mr-2" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M8 1.5c-2.363 0-4 1.69-4 3.75 0 .984.424 1.625.984 2.304l.214.253c.223.264.47.556.673.848.284.411.537.896.621 1.49a.75.75 0 0 1-1.484.211c-.04-.282-.163-.547-.37-.847a8.456 8.456 0 0 0-.542-.68c-.084-.1-.173-.205-.268-.32C3.201 7.75 2.5 6.766 2.5 5.25 2.5 2.31 4.863 0 8 0s5.5 2.31 5.5 5.25c0 1.516-.701 2.5-1.328 3.259-.095.115-.184.22-.268.319-.207.245-.383.453-.541.681-.208.3-.33.565-.37.847a.751.751 0 0 1-1.485-.212c.084-.593.337-1.078.621-1.489.203-.292.45-.584.673-.848.075-.088.147-.173.213-.253.561-.679.985-1.32.985-2.304 0-2.06-1.637-3.75-4-3.75ZM5.75 12h4.5a.75.75 0 0 1 0 1.5h-4.5a.75.75 0 0 1 0-1.5ZM6 15.25a.75.75 0 0 1 .75-.75h2.5a.75.75 0 0 1 0 1.5h-2.5a.75.75 0 0 1-.75-.75Z"></path></svg>`},{type:`important`,icon:`<svg class="octicon octicon-report mr-2" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M0 1.75C0 .784.784 0 1.75 0h12.5C15.216 0 16 .784 16 1.75v9.5A1.75 1.75 0 0 1 14.25 13H8.06l-2.573 2.573A1.458 1.458 0 0 1 3 14.543V13H1.75A1.75 1.75 0 0 1 0 11.25Zm1.75-.25a.25.25 0 0 0-.25.25v9.5c0 .138.112.25.25.25h2a.75.75 0 0 1 .75.75v2.19l2.72-2.72a.749.749 0 0 1 .53-.22h6.5a.25.25 0 0 0 .25-.25v-9.5a.25.25 0 0 0-.25-.25Zm7 2.25v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 9a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path></svg>`},{type:`warning`,icon:`<svg class="octicon octicon-alert mr-2" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path></svg>`},{type:`caution`,icon:`<svg class="octicon octicon-stop mr-2" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M4.47.22A.749.749 0 0 1 5 0h6c.199 0 .389.079.53.22l4.25 4.25c.141.14.22.331.22.53v6a.749.749 0 0 1-.22.53l-4.25 4.25A.749.749 0 0 1 11 16H5a.749.749 0 0 1-.53-.22L.22 11.53A.749.749 0 0 1 0 11V5c0-.199.079-.389.22-.53Zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5ZM8 4a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5A.75.75 0 0 1 8 4Zm0 8a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z"></path></svg>`}],r=[{name:`title`,defaultValue:``},{name:`expanded`,defaultValue:`false`},{name:`level`,defaultValue:`3`},{name:`duration`,defaultValue:``},{name:`easing`,defaultValue:``},{name:`group`,defaultValue:``},{name:`id`,defaultValue:``},{name:`icon`,defaultValue:``},{name:`iconPosition`,defaultValue:``},{name:`variant`,defaultValue:``},{name:`class`,defaultValue:``}],i=`
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.markedExtendedAccordion={}))})(this,function(e){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var t=/^[A-Za-z][A-Za-z0-9]*$/,n=/^[A-Za-z0-9-]$/;function r(e,n){if(!t.test(n))throw TypeError(`Invalid class token ${e} "${n}": expected /${t.source}/`)}function i(e){let t=``;for(let r of new TextEncoder().encode(e)){let e=String.fromCharCode(r);t+=n.test(e)?e:`_${r.toString(16).padStart(2,`0`)}`}return t}function a(e){let t=[];for(let r=0;r<e.length;r++){let i=e[r];if(i===`_`){let n=e.slice(r+1,r+3);if(!/^[0-9a-f]{2}$/.test(n))return null;t.push(Number.parseInt(n,16)),r+=2}else if(n.test(i))t.push(i.charCodeAt(0));else return null}try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(new Uint8Array(t))}catch{return null}}function o(e,t,n){return r(`pkg`,e),r(`key`,t),`mx-${e}-${t}-${i(String(n))}`}function s(e,n){r(`pkg`,n);let i=`mx-${n}-`,o={};for(let n of e.split(/\s+/)){if(!n.startsWith(i))continue;let e=n.slice(i.length),r=e.indexOf(`-`);if(r<=0)continue;let s=e.slice(0,r);if(!t.test(s))continue;let c=a(e.slice(r+1));c!==null&&(o[s]=c)}return o}function c(e,t){return s(e.getAttribute(`class`)??``,t)}function l(e,t,n,r){return e.querySelector(`.${o(t,n,r)}`)}var u=/^data[A-Z0-9][a-z0-9]*(?:[A-Z][a-z0-9]*)*$/;function d(e,t){if(!t)return null;let n=t.replace(/["\\]|[^\x20-\x7e]/gu,e=>e===`"`||e===`\\`?`\\${e}`:`\\${e.codePointAt(0).toString(16)} `);return e.querySelector(`[id="${n}"]`)}function f(e){let t=e.toLowerCase();if(!t.startsWith(`data-`))return null;let n=t.split(`-`).slice(1);return n.length===0||n.some((e,t)=>!/^[a-z0-9]+$/.test(e)||t>0&&/^\d/.test(e))?null:`data${n.map(e=>e[0].toUpperCase()+e.slice(1)).join(``)}`}function p(e){return u.test(e)?`data-${e.slice(4).replace(/[A-Z]/g,(e,t)=>`${t?`-`:``}${e.toLowerCase()}`)}`:null}function m(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#39;`)}var h=`marked-extended`;function g(e,t){return`${h}:${e}:${t}`}function _(e,t,n,r){return e.dispatchEvent(new CustomEvent(g(t,n),{bubbles:!0,composed:!0,cancelable:!0,detail:r}))}function v(e,t){let n=5381;for(let t=0;t<e.length;t++)n=(n<<5)+n+e.charCodeAt(t)>>>0;let r=n.toString(36);return t?`${t}-${r}`:r}var y=()=>{};function b(e,t){console.error(`[marked-extended:${e}]`,t)}var x=new WeakMap;function S(e){return typeof e==`function`?{dispose:e}:e??{}}function C(e,t){let n=(e.nodeType===9?e.defaultView:e.ownerDocument?.defaultView)?.MutationObserver??(typeof MutationObserver>`u`?void 0:MutationObserver);if(!n)return null;let r=!1,i=!1,a=new n(()=>{r||i||(r=!0,queueMicrotask(()=>{r=!1,i||t()}))});return a.observe(e,{childList:!0,subtree:!0}),()=>{i=!0,a.disconnect()}}function w(e){let{name:t}=e,n=((n,r={})=>{let i=x.get(n);if(i?.has(t))return y;let{observe:a=!1,...o}=r,s;try{s=S(e.attach(n,o))}catch(e){return b(t,e),y}i||(i=new Map,x.set(n,i));let c=()=>{try{s.refresh?.()}catch(e){b(t,e)}},l=a&&s.refresh?C(n,c):null,u=!1,d=()=>{if(u)return;u=!0;let e=x.get(n);e?.get(t)?.dispose===d&&e.delete(t),l?.();try{s.dispose?.()}catch(e){b(t,e)}};return i.set(t,{dispose:d,refresh:c}),d});return Object.defineProperty(n,"runtimeName",{value:t}),n.isAttached=e=>x.get(e)?.has(t)??!1,n.refresh=e=>{let n=x.get(e)?.get(t);return n?.refresh(),n!==void 0},n}function T(e,t,n,r,i){let a=i=>{let a=i.target,o=(a&&a.nodeType===1?a:a?.parentElement??null)?.closest(n);if(o&&e.contains(o))try{r(i,o)}catch(e){b(`delegated:${t}`,e)}};return e.addEventListener(t,a,i),()=>e.removeEventListener(t,a,i)}var E={className:`marked-extended-accordion`,prefixId:`accordion-`,animationDuration:`0.3s`,animationEasing:`ease-in-out`,iconPosition:`before`,variants:[],template:null,customizeToken:null,unsafeHtml:!1},D=[{type:`note`,icon:`<svg class="octicon octicon-info mr-2" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z"></path></svg>`},{type:`tip`,icon:`<svg class="octicon octicon-light-bulb mr-2" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M8 1.5c-2.363 0-4 1.69-4 3.75 0 .984.424 1.625.984 2.304l.214.253c.223.264.47.556.673.848.284.411.537.896.621 1.49a.75.75 0 0 1-1.484.211c-.04-.282-.163-.547-.37-.847a8.456 8.456 0 0 0-.542-.68c-.084-.1-.173-.205-.268-.32C3.201 7.75 2.5 6.766 2.5 5.25 2.5 2.31 4.863 0 8 0s5.5 2.31 5.5 5.25c0 1.516-.701 2.5-1.328 3.259-.095.115-.184.22-.268.319-.207.245-.383.453-.541.681-.208.3-.33.565-.37.847a.751.751 0 0 1-1.485-.212c.084-.593.337-1.078.621-1.489.203-.292.45-.584.673-.848.075-.088.147-.173.213-.253.561-.679.985-1.32.985-2.304 0-2.06-1.637-3.75-4-3.75ZM5.75 12h4.5a.75.75 0 0 1 0 1.5h-4.5a.75.75 0 0 1 0-1.5ZM6 15.25a.75.75 0 0 1 .75-.75h2.5a.75.75 0 0 1 0 1.5h-2.5a.75.75 0 0 1-.75-.75Z"></path></svg>`},{type:`important`,icon:`<svg class="octicon octicon-report mr-2" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M0 1.75C0 .784.784 0 1.75 0h12.5C15.216 0 16 .784 16 1.75v9.5A1.75 1.75 0 0 1 14.25 13H8.06l-2.573 2.573A1.458 1.458 0 0 1 3 14.543V13H1.75A1.75 1.75 0 0 1 0 11.25Zm1.75-.25a.25.25 0 0 0-.25.25v9.5c0 .138.112.25.25.25h2a.75.75 0 0 1 .75.75v2.19l2.72-2.72a.749.749 0 0 1 .53-.22h6.5a.25.25 0 0 0 .25-.25v-9.5a.25.25 0 0 0-.25-.25Zm7 2.25v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 9a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path></svg>`},{type:`warning`,icon:`<svg class="octicon octicon-alert mr-2" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path></svg>`},{type:`caution`,icon:`<svg class="octicon octicon-stop mr-2" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M4.47.22A.749.749 0 0 1 5 0h6c.199 0 .389.079.53.22l4.25 4.25c.141.14.22.331.22.53v6a.749.749 0 0 1-.22.53l-4.25 4.25A.749.749 0 0 1 11 16H5a.749.749 0 0 1-.53-.22L.22 11.53A.749.749 0 0 1 0 11V5c0-.199.079-.389.22-.53Zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5ZM8 4a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5A.75.75 0 0 1 8 4Zm0 8a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z"></path></svg>`}],O=new Map(D.map(e=>[e.icon,e.type])),k=[{name:`title`,defaultValue:``},{name:`expanded`,defaultValue:`false`},{name:`level`,defaultValue:`3`},{name:`duration`,defaultValue:``},{name:`easing`,defaultValue:``},{name:`group`,defaultValue:``},{name:`id`,defaultValue:``},{name:`icon`,defaultValue:``},{name:`iconPosition`,defaultValue:``},{name:`variant`,defaultValue:``},{name:`class`,defaultValue:``}],A=`
2
+ <details class="{className}{variantClass}{extraClasses}{tokenClasses}" {expandedAttr}>
3
+ <summary class="{className}-header">
4
+ {iconBefore}<{headingTag} class="{className}-title">{title}</{headingTag}>{iconAfter}
5
+ </summary>
6
+ <div class="{className}-content">
7
+ {content}
8
+ </div>
9
+ </details>
10
+ `,j=`
2
11
  <details id="{accordionId}" class="{className}{variantClass}{extraClasses}" {expandedAttr} {nameAttr}{dataAttrs} style="{styleAttr}">
3
12
  <summary class="{className}-header">
4
13
  {iconBefore}<{headingTag} class="{className}-title">{title}</{headingTag}>{iconAfter}
@@ -7,6 +16,6 @@
7
16
  {content}
8
17
  </div>
9
18
  </details>
10
- `;function a(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#39;`)}function o(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t+e.charCodeAt(n)>>>0;return t.toString(36)}function s(e){if(e.length>=2){let t=e[0],n=e[e.length-1];if(t===`"`&&n===`"`||t===`'`&&n===`'`)return e.slice(1,-1)}return e}function c(e){let t=/^(`{3,}|~{3,})[ \t]*accordion[ \t]*\r?\n([\s\S]*?)\r?\n\1[ \t]*(?:\n|$)/.exec(e);return t?{raw:t[0],body:t[2]}:null}function l(e){let t={},n={};r.forEach(e=>{t[e.name]=e.defaultValue});let i=e.split(`
11
- `),a=0;for(;a<i.length&&i[a].trim()===``;)a++;let o=/^([\w-]+)\s*:\s*(.*)$/,c=/^---\s*$/;if(!(a<i.length&&o.test(i[a].trim())))return{attrs:t,dataAttrs:n,content:e.trim()};let l=-1;for(let e=a;e<i.length;e++)if(c.test(i[e])){l=e;break}if(l===-1)return{attrs:t,dataAttrs:n,content:e.trim()};let u=new Set(r.map(e=>e.name)),d=/^data-[\w-]+$/;for(let e=a;e<l;e++){let r=i[e].trim();if(r===``)continue;let a=o.exec(r);if(!a)continue;let[,c,l]=a,f=s(l.trim());u.has(c)?t[c]=f:d.test(c)&&(n[c]=f)}return{attrs:t,dataAttrs:n,content:i.slice(l+1).join(`
12
- `).trim()}}function u(e){let t=e.trim().toLowerCase();return t===`true`||t===`yes`||t===`1`}function d(e){let{prefixId:t,title:n,titleTokens:r,expanded:s,level:c,className:l,animationDuration:u,animationEasing:d,template:f,group:p,customId:m,icon:h,iconPosition:g,variant:_,variantIcon:v,extraClasses:y,dataAttrs:b,raw:x,tokens:S,parser:C}=e,w=m?a(m):`${t}${o(x)}`,T=S&&S.length>0?C.parse(S):``,E=r&&r.length>0?C.parseInline(r):a(n),D=`h${c}`,O=p?`name="${a(p)}"`:``,k=_?` ${l}-${_}`:``,A=y?` ${a(y)}`:``,j=Object.entries(b||{}).map(([e,t])=>` ${e}="${a(t)}"`).join(``),M=`--${l}-animation-duration: ${a(u)}; --${l}-transition-timing: ${a(d)};`,N=``;h?N=`<span class="${l}-icon" aria-hidden="true">${a(h)}</span>`:v&&(N=`<span class="${l}-icon" aria-hidden="true">${v}</span>`);let P=g===`after`?``:N,F=g===`after`?N:``,I=f||i,L={accordionId:w,headingTag:D,title:E,content:T,expanded:s?`true`:`false`,expandedAttr:s?`open`:``,nameAttr:O,dataAttrs:j,styleAttr:M,variantClass:k,extraClasses:A,iconBefore:P,iconAfter:F,icon:N,animationDuration:u,className:l};return I.replace(/\{(\w+)\}/g,(e,t)=>Object.hasOwn(L,t)?L[t]:e)}function f(e){let{className:t,prefixId:r,animationDuration:i,animationEasing:a,iconPosition:o,template:s}=e,d=new Map(n.map(e=>[e.type,e]));return e.variants.forEach(e=>{d.set(e.type,e)}),{name:`accordion`,level:`block`,start(e){let t=/(?:^|\n)(?:`{3,}|~{3,})[ \t]*accordion\b/.exec(e);return t?t.index:void 0},tokenizer(e){let n=c(e);if(!n)return;let{attrs:f,dataAttrs:p,content:m}=l(n.body),h=this.lexer.blockTokens(m),g=f.title.replace(/</g,`&lt;`).replace(/>/g,`&gt;`),_=this.lexer.inlineTokens(g),v=parseInt(f.level,10),y=f.variant,b=y?d.get(y):void 0,x=f.iconPosition,S=x===`before`||x===`after`?x:o;return{type:`accordion`,raw:n.raw,tokens:h,titleTokens:_,meta:{prefixId:r,title:f.title,expanded:u(f.expanded),level:v>=1&&v<=6?v:3,className:t,animationDuration:f.duration||i,animationEasing:f.easing||a,template:s,group:f.group,customId:f.id,icon:f.icon,iconPosition:S,variant:b?b.type:``,variantIcon:b?b.icon:``,extraClasses:f.class,dataAttrs:p}}}}}function p(){return{name:`accordion`,renderer(e){let t=e;return d({...t.meta,raw:t.raw,titleTokens:t.titleTokens||[],tokens:t.tokens||[],parser:this.parser})}}}function m(e={}){let n={...t,...e};return{walkTokens(e){e.type===`accordion`&&n.customizeToken&&typeof n.customizeToken==`function`&&n.customizeToken(e)},extensions:[f(n),p()]}}e.default=m});
19
+ `;function M(e,t){let{group:n,animationDuration:r,animationEasing:i,dataAttrs:a}=e,s=[o(`accordion`,`id`,t)];n&&s.push(o(`accordion`,`group`,n)),r&&r!==E.animationDuration&&s.push(o(`accordion`,`duration`,r)),i&&i!==E.animationEasing&&s.push(o(`accordion`,`easing`,i));for(let[e,t]of Object.entries(a||{})){let n=f(e);n&&s.push(o(`accordion`,n,t))}return` ${s.join(` `)}`}function N(e,t,n){let r=n?void 0:O.get(t);return r?`<span class="${e}-icon ${o(`accordion`,`icon`,r)}" aria-hidden="true"></span>`:`<span class="${e}-icon" aria-hidden="true">${t}</span>`}function P(e){let{prefixId:t,title:n,titleTokens:r,expanded:i,level:a,className:o,animationDuration:s,animationEasing:c,template:l,group:u,customId:d,icon:f,iconPosition:p,variant:h,variantIcon:g,extraClasses:_,dataAttrs:y,unsafeHtml:b=!1,raw:x,tokens:S,parser:C}=e,w=d||`${t}${v(x)}`,T=m(w),E=S&&S.length>0?C.parse(S):``,D=r&&r.length>0?C.parseInline(r):m(n),O=`h${a}`,k=u?`name="${m(u)}"`:``,P=h?` ${o}-${h}`:``,F=_?` ${m(_)}`:``,I=Object.entries(y||{}).map(([e,t])=>` ${e}="${m(t)}"`).join(``),L=`--${o}-animation-duration: ${m(s)}; --${o}-transition-timing: ${m(c)};`,R=``;f?R=`<span class="${o}-icon" aria-hidden="true">${m(f)}</span>`:g&&(R=N(o,g,b));let z=p===`after`?``:R,B=p===`after`?R:``,V=l||(b?j:A),H={accordionId:T,headingTag:O,title:D,content:E,expanded:i?`true`:`false`,expandedAttr:i?`open`:``,nameAttr:k,dataAttrs:I,styleAttr:L,variantClass:P,extraClasses:F,tokenClasses:b?``:M(e,w),iconBefore:z,iconAfter:B,icon:R,animationDuration:s,className:o};return V.replace(/\{(\w+)\}/g,(e,t)=>Object.hasOwn(H,t)?H[t]:e)}function F(e){if(e.length>=2){let t=e[0],n=e[e.length-1];if(t===`"`&&n===`"`||t===`'`&&n===`'`)return e.slice(1,-1)}return e}function I(e){let t=/^(`{3,}|~{3,})[ \t]*accordion[ \t]*\r?\n([\s\S]*?)\r?\n\1[ \t]*(?:\n|$)/.exec(e);return t?{raw:t[0],body:t[2]}:null}function L(e){let t={},n={};k.forEach(e=>{t[e.name]=e.defaultValue});let r=e.split(`
20
+ `),i=0;for(;i<r.length&&r[i].trim()===``;)i++;let a=/^([\w-]+)\s*:\s*(.*)$/,o=/^---\s*$/;if(!(i<r.length&&a.test(r[i].trim())))return{attrs:t,dataAttrs:n,content:e.trim()};let s=-1;for(let e=i;e<r.length;e++)if(o.test(r[e])){s=e;break}if(s===-1)return{attrs:t,dataAttrs:n,content:e.trim()};let c=new Set(k.map(e=>e.name)),l=/^data-[\w-]+$/;for(let e=i;e<s;e++){let i=r[e].trim();if(i===``)continue;let o=a.exec(i);if(!o)continue;let[,s,u]=o,d=F(u.trim());c.has(s)?t[s]=d:l.test(s)&&(n[s]=d)}return{attrs:t,dataAttrs:n,content:r.slice(s+1).join(`
21
+ `).trim()}}function R(e){let t=e.trim().toLowerCase();return t===`true`||t===`yes`||t===`1`}function z(e){let{className:t,prefixId:n,animationDuration:r,animationEasing:i,iconPosition:a,template:o,unsafeHtml:s}=e,c=new Map(D.map(e=>[e.type,e]));return e.variants.forEach(e=>{c.set(e.type,e)}),{name:`accordion`,level:`block`,start(e){let t=/(?:^|\n)(?:`{3,}|~{3,})[ \t]*accordion\b/.exec(e);return t?t.index:void 0},tokenizer(e){let l=I(e);if(!l)return;let{attrs:u,dataAttrs:d,content:f}=L(l.body),p=this.lexer.blockTokens(f),m=u.title.replace(/</g,`&lt;`).replace(/>/g,`&gt;`),h=this.lexer.inlineTokens(m),g=parseInt(u.level,10),_=u.variant,v=_?c.get(_):void 0,y=u.iconPosition,b=y===`before`||y===`after`?y:a;return{type:`accordion`,raw:l.raw,tokens:p,titleTokens:h,meta:{prefixId:n,title:u.title,expanded:R(u.expanded),level:g>=1&&g<=6?g:3,className:t,animationDuration:u.duration||r,animationEasing:u.easing||i,template:o,group:u.group,customId:u.id,icon:u.icon,iconPosition:b,variant:v?v.type:``,variantIcon:v?v.icon:``,extraClasses:u.class,dataAttrs:d,unsafeHtml:s}}}}}function B(){return{name:`accordion`,renderer(e){let t=e;return P({...t.meta,raw:t.raw,titleTokens:t.titleTokens||[],tokens:t.tokens||[],parser:this.parser})}}}var V=`accordion`,H=`details[class*="mx-accordion-id-"]`;function U(e,t){let n=c(e,V);n.duration&&e.style.setProperty(`--${t}-animation-duration`,n.duration),n.easing&&e.style.setProperty(`--${t}-transition-timing`,n.easing);for(let[t,r]of Object.entries(n)){let n=p(t);n&&!e.hasAttribute(n)&&e.setAttribute(n,r)}}function W(e,t){if(d(e,t))return null;let n=l(e,V,`id`,t);return n?.tagName===`DETAILS`?n:null}var G=w({name:V,attach(e,t){let n=t.className??E.className,r=()=>{for(let t of e.querySelectorAll(H))U(t,n)};r();let i=t=>{let n=t.target;if(!n||n.nodeType!==1||!n.matches(H)||!e.contains(n))return;let r=c(n,V),i=r.group??``;if(n.open&&i)for(let t of e.querySelectorAll(H))t!==n&&t.open&&c(t,V).group===i&&(t.open=!1);_(n,V,`toggle`,{id:r.id??``,open:n.open,group:i})};e.addEventListener(`toggle`,i,!0);let a=T(e,`click`,`a[href^="#"]`,(t,n)=>{let r=n.getAttribute(`href`)?.slice(1)??``;if(!r)return;let i=r;try{i=decodeURIComponent(r)}catch{}let a=W(e,i);a&&(t.preventDefault(),a.open||=!0,a.scrollIntoView?.({block:`start`,behavior:`smooth`}))});return{refresh:r,dispose:()=>{e.removeEventListener(`toggle`,i,!0),a()}}}});function K(e={}){let t={...E,...e};return{walkTokens(e){e.type===`accordion`&&t.customizeToken&&typeof t.customizeToken==`function`&&t.customizeToken(e)},extensions:[z(t),B()]}}e.attachAccordion=G,e.default=K});
@@ -55,3 +55,46 @@
55
55
  animation: none;
56
56
  }
57
57
  }
58
+
59
+ /*
60
+ * Built-in variant icons (default, sanitizer-safe markup).
61
+ * The renderer emits <span class="… mx-accordion-icon-<type>" aria-hidden="true"></span>;
62
+ * the Octicons below are drawn as a CSS mask in the current text colour.
63
+ * With `unsafeHtml: true` the icons stay inline <svg> elements instead.
64
+ */
65
+ [class*="mx-accordion-icon-"] {
66
+ display: inline-block;
67
+ flex: none;
68
+ width: 16px;
69
+ height: 16px;
70
+ vertical-align: text-bottom;
71
+ background-color: currentColor;
72
+ -webkit-mask-image: var(--mx-accordion-icon);
73
+ mask-image: var(--mx-accordion-icon);
74
+ -webkit-mask-repeat: no-repeat;
75
+ mask-repeat: no-repeat;
76
+ -webkit-mask-position: center;
77
+ mask-position: center;
78
+ -webkit-mask-size: contain;
79
+ mask-size: contain;
80
+ }
81
+
82
+ .mx-accordion-icon-note {
83
+ --mx-accordion-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z'/%3E%3C/svg%3E");
84
+ }
85
+
86
+ .mx-accordion-icon-tip {
87
+ --mx-accordion-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 1.5c-2.363 0-4 1.69-4 3.75 0 .984.424 1.625.984 2.304l.214.253c.223.264.47.556.673.848.284.411.537.896.621 1.49a.75.75 0 0 1-1.484.211c-.04-.282-.163-.547-.37-.847a8.456 8.456 0 0 0-.542-.68c-.084-.1-.173-.205-.268-.32C3.201 7.75 2.5 6.766 2.5 5.25 2.5 2.31 4.863 0 8 0s5.5 2.31 5.5 5.25c0 1.516-.701 2.5-1.328 3.259-.095.115-.184.22-.268.319-.207.245-.383.453-.541.681-.208.3-.33.565-.37.847a.751.751 0 0 1-1.485-.212c.084-.593.337-1.078.621-1.489.203-.292.45-.584.673-.848.075-.088.147-.173.213-.253.561-.679.985-1.32.985-2.304 0-2.06-1.637-3.75-4-3.75ZM5.75 12h4.5a.75.75 0 0 1 0 1.5h-4.5a.75.75 0 0 1 0-1.5ZM6 15.25a.75.75 0 0 1 .75-.75h2.5a.75.75 0 0 1 0 1.5h-2.5a.75.75 0 0 1-.75-.75Z'/%3E%3C/svg%3E");
88
+ }
89
+
90
+ .mx-accordion-icon-important {
91
+ --mx-accordion-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M0 1.75C0 .784.784 0 1.75 0h12.5C15.216 0 16 .784 16 1.75v9.5A1.75 1.75 0 0 1 14.25 13H8.06l-2.573 2.573A1.458 1.458 0 0 1 3 14.543V13H1.75A1.75 1.75 0 0 1 0 11.25Zm1.75-.25a.25.25 0 0 0-.25.25v9.5c0 .138.112.25.25.25h2a.75.75 0 0 1 .75.75v2.19l2.72-2.72a.749.749 0 0 1 .53-.22h6.5a.25.25 0 0 0 .25-.25v-9.5a.25.25 0 0 0-.25-.25Zm7 2.25v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 9a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z'/%3E%3C/svg%3E");
92
+ }
93
+
94
+ .mx-accordion-icon-warning {
95
+ --mx-accordion-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z'/%3E%3C/svg%3E");
96
+ }
97
+
98
+ .mx-accordion-icon-caution {
99
+ --mx-accordion-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4.47.22A.749.749 0 0 1 5 0h6c.199 0 .389.079.53.22l4.25 4.25c.141.14.22.331.22.53v6a.749.749 0 0 1-.22.53l-4.25 4.25A.749.749 0 0 1 11 16H5a.749.749 0 0 1-.53-.22L.22 11.53A.749.749 0 0 1 0 11V5c0-.199.079-.389.22-.53Zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5ZM8 4a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5A.75.75 0 0 1 8 4Zm0 8a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z'/%3E%3C/svg%3E");
100
+ }
@@ -53,3 +53,45 @@ $accordion-fade-distance: -10px !default;
53
53
  }
54
54
  }
55
55
 
56
+ /*
57
+ * Built-in variant icons (default, sanitizer-safe markup).
58
+ * The renderer emits <span class="… mx-accordion-icon-<type>" aria-hidden="true"></span>;
59
+ * the Octicons below are drawn as a CSS mask in the current text colour.
60
+ * With `unsafeHtml: true` the icons stay inline <svg> elements instead.
61
+ */
62
+ [class*="mx-accordion-icon-"] {
63
+ display: inline-block;
64
+ flex: none;
65
+ width: 16px;
66
+ height: 16px;
67
+ vertical-align: text-bottom;
68
+ background-color: currentColor;
69
+ -webkit-mask-image: var(--mx-accordion-icon);
70
+ mask-image: var(--mx-accordion-icon);
71
+ -webkit-mask-repeat: no-repeat;
72
+ mask-repeat: no-repeat;
73
+ -webkit-mask-position: center;
74
+ mask-position: center;
75
+ -webkit-mask-size: contain;
76
+ mask-size: contain;
77
+ }
78
+
79
+ .mx-accordion-icon-note {
80
+ --mx-accordion-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z'/%3E%3C/svg%3E");
81
+ }
82
+
83
+ .mx-accordion-icon-tip {
84
+ --mx-accordion-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 1.5c-2.363 0-4 1.69-4 3.75 0 .984.424 1.625.984 2.304l.214.253c.223.264.47.556.673.848.284.411.537.896.621 1.49a.75.75 0 0 1-1.484.211c-.04-.282-.163-.547-.37-.847a8.456 8.456 0 0 0-.542-.68c-.084-.1-.173-.205-.268-.32C3.201 7.75 2.5 6.766 2.5 5.25 2.5 2.31 4.863 0 8 0s5.5 2.31 5.5 5.25c0 1.516-.701 2.5-1.328 3.259-.095.115-.184.22-.268.319-.207.245-.383.453-.541.681-.208.3-.33.565-.37.847a.751.751 0 0 1-1.485-.212c.084-.593.337-1.078.621-1.489.203-.292.45-.584.673-.848.075-.088.147-.173.213-.253.561-.679.985-1.32.985-2.304 0-2.06-1.637-3.75-4-3.75ZM5.75 12h4.5a.75.75 0 0 1 0 1.5h-4.5a.75.75 0 0 1 0-1.5ZM6 15.25a.75.75 0 0 1 .75-.75h2.5a.75.75 0 0 1 0 1.5h-2.5a.75.75 0 0 1-.75-.75Z'/%3E%3C/svg%3E");
85
+ }
86
+
87
+ .mx-accordion-icon-important {
88
+ --mx-accordion-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M0 1.75C0 .784.784 0 1.75 0h12.5C15.216 0 16 .784 16 1.75v9.5A1.75 1.75 0 0 1 14.25 13H8.06l-2.573 2.573A1.458 1.458 0 0 1 3 14.543V13H1.75A1.75 1.75 0 0 1 0 11.25Zm1.75-.25a.25.25 0 0 0-.25.25v9.5c0 .138.112.25.25.25h2a.75.75 0 0 1 .75.75v2.19l2.72-2.72a.749.749 0 0 1 .53-.22h6.5a.25.25 0 0 0 .25-.25v-9.5a.25.25 0 0 0-.25-.25Zm7 2.25v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 9a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z'/%3E%3C/svg%3E");
89
+ }
90
+
91
+ .mx-accordion-icon-warning {
92
+ --mx-accordion-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z'/%3E%3C/svg%3E");
93
+ }
94
+
95
+ .mx-accordion-icon-caution {
96
+ --mx-accordion-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4.47.22A.749.749 0 0 1 5 0h6c.199 0 .389.079.53.22l4.25 4.25c.141.14.22.331.22.53v6a.749.749 0 0 1-.22.53l-4.25 4.25A.749.749 0 0 1 11 16H5a.749.749 0 0 1-.53-.22L.22 11.53A.749.749 0 0 1 0 11V5c0-.199.079-.389.22-.53Zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5ZM8 4a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5A.75.75 0 0 1 8 4Zm0 8a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z'/%3E%3C/svg%3E");
97
+ }
@@ -1,6 +1,7 @@
1
1
  import { Token } from 'marked';
2
2
  import { AccordionOptions } from './types';
3
- export type { AccordionMeta, AccordionOptions, AccordionRendererOptions, AccordionToken } from './types';
3
+ export { attachAccordion } from './runtime';
4
+ export type { AccordionMeta, AccordionOptions, AccordionRendererOptions, AccordionRuntime, AccordionRuntimeOptions, AccordionToggleDetail, AccordionToken, Dispose, RuntimeAttachOptions, RuntimeRoot, } from './types';
4
5
  /**
5
6
  * Marked Extended Accordion extension
6
7
  *
@@ -0,0 +1,26 @@
1
+ import { AccordionRuntime } from './types';
2
+ /**
3
+ * Browser runtime for sanitizer-safe accordions.
4
+ *
5
+ * - Applies the per-block `duration`/`easing` CSS variables and restores the
6
+ * `data-*` attributes carried as class tokens.
7
+ * - Exclusive groups (`group:` front matter): opening an accordion closes the
8
+ * other open accordions of the same group inside `root`.
9
+ * - `#id` links whose target has no `id` (removed by the sanitizer) open and
10
+ * scroll to the accordion carrying `mx-accordion-id-<id>`.
11
+ * - Emits `marked-extended:accordion:toggle` ({@link AccordionToggleDetail}) when
12
+ * an accordion opens or closes.
13
+ *
14
+ * All listeners are registered on `root` and delegated, so they keep working
15
+ * when the content of `root` is replaced. The CSS variables and `data-*`
16
+ * attributes are per element: after replacing the content, call
17
+ * `attachAccordion.refresh(root)`, or attach with `{ observe: true }`. Calling
18
+ * it again on the same root is a no-op; the returned function removes
19
+ * everything it added.
20
+ *
21
+ * @example
22
+ * const dispose = attachAccordion(container, { observe: true });
23
+ * // later, e.g. in a component's destroy hook
24
+ * dispose();
25
+ */
26
+ export declare const attachAccordion: AccordionRuntime;
@@ -30,6 +30,62 @@ export interface AccordionOptions {
30
30
  template?: string | null;
31
31
  /** Function to customize the accordion token */
32
32
  customizeToken?: ((token: AccordionToken) => void) | null;
33
+ /**
34
+ * Emit the 18.0 markup (`id`, `name`, `style`, `data-*` and inline `<svg>` icons).
35
+ *
36
+ * By default (`false`) the markup survives strict sanitizers such as Angular's:
37
+ * the id, group, duration, easing and `data-*` values become class tokens
38
+ * (`mx-accordion-<key>-<value>`) that {@link attachAccordion} applies in the
39
+ * browser, and built-in icons are drawn with CSS. Only enable it when the HTML
40
+ * is not sanitized.
41
+ * @default false
42
+ */
43
+ unsafeHtml?: boolean;
44
+ }
45
+ /** Releases what a runtime set up. Calling it more than once is safe. */
46
+ export type Dispose = () => void;
47
+ /** A subtree a runtime can be attached to. */
48
+ export type RuntimeRoot = Element | Document | DocumentFragment;
49
+ /** Options every runtime attach accepts, besides its own. */
50
+ export interface RuntimeAttachOptions {
51
+ /**
52
+ * Watch `root` (only `root`, never `document` or `body`) with a
53
+ * `MutationObserver` and refresh after its children change. The observer is
54
+ * disconnected by dispose. @default false
55
+ */
56
+ observe?: boolean;
57
+ }
58
+ /** Options of {@link attachAccordion}. */
59
+ export interface AccordionRuntimeOptions {
60
+ /**
61
+ * Base class name used for the CSS variables (`--<className>-animation-duration`).
62
+ * Must match the extension's `className` option.
63
+ * @default 'marked-extended-accordion'
64
+ */
65
+ className: string;
66
+ }
67
+ /** Detail of the `marked-extended:accordion:toggle` event. */
68
+ export interface AccordionToggleDetail {
69
+ /** Accordion id (from the `id` front matter key or the content hash) */
70
+ id: string;
71
+ /** Whether the accordion is now open */
72
+ open: boolean;
73
+ /** Exclusive group name, or an empty string */
74
+ group: string;
75
+ }
76
+ /** `attachAccordion(root, options?)`: scoped, idempotent and disposable. */
77
+ export interface AccordionRuntime {
78
+ (root: RuntimeRoot, options?: Partial<AccordionRuntimeOptions> & RuntimeAttachOptions): Dispose;
79
+ /** The runtime name (`accordion`). */
80
+ readonly runtimeName: string;
81
+ /** Whether the runtime is currently attached to `root`. */
82
+ isAttached(root: RuntimeRoot): boolean;
83
+ /**
84
+ * Re-applies the per-element setup to the current content of `root`, e.g.
85
+ * after a framework replaced its `innerHTML`. Delegated behaviour needs no
86
+ * refresh. Returns `false` when the runtime is not attached to `root`.
87
+ */
88
+ refresh(root: RuntimeRoot): boolean;
33
89
  }
34
90
  /**
35
91
  * Metadata for the accordion token
@@ -67,6 +123,8 @@ export interface AccordionMeta {
67
123
  extraClasses: string;
68
124
  /** Custom `data-*` attributes parsed from front matter */
69
125
  dataAttrs: Record<string, string>;
126
+ /** Emit the 18.0 markup instead of sanitizer-safe markup */
127
+ unsafeHtml?: boolean;
70
128
  }
71
129
  /**
72
130
  * Token for accordion blocks
@@ -125,6 +183,8 @@ export interface AccordionRendererOptions {
125
183
  extraClasses: string;
126
184
  /** Custom `data-*` attributes parsed from front matter */
127
185
  dataAttrs: Record<string, string>;
186
+ /** Emit the 18.0 markup instead of sanitizer-safe markup */
187
+ unsafeHtml?: boolean;
128
188
  /** Raw source of the accordion block, used to derive a deterministic id */
129
189
  raw: string;
130
190
  /** Tokens to render as content */
@@ -9,6 +9,11 @@ export declare const DEFAULT_OPTIONS: Required<AccordionOptions>;
9
9
  * over by any `variants` passed in options.
10
10
  */
11
11
  export declare const DEFAULT_VARIANTS: AccordionVariant[];
12
+ /**
13
+ * Built-in icon names keyed by their inline SVG markup. In the default (safe)
14
+ * mode a variant icon equal to one of these SVGs is rendered as a CSS icon.
15
+ */
16
+ export declare const BUILTIN_ICON_NAMES: ReadonlyMap<string, string>;
12
17
  /**
13
18
  * Supported front matter key definition.
14
19
  */
@@ -22,23 +27,34 @@ export interface SupportedProp {
22
27
  */
23
28
  export declare const SUPPORTED_PROPS: SupportedProp[];
24
29
  /**
25
- * The default accordion template with improved accessibility.
30
+ * The default (sanitizer-safe) accordion template.
26
31
  * Uses placeholders that will be replaced during rendering:
27
- * - {accordionId} - Unique ID for the accordion element
28
32
  * - {title} - Rendered title (inline markdown) of the accordion
29
33
  * - {content} - Content inside the accordion
30
34
  * - {expanded} - Whether the accordion is expanded (true/false)
31
35
  * - {expandedAttr} - 'open' attribute if expanded, empty if not
32
- * - {nameAttr} - 'name="group"' attribute for exclusive accordions, empty if none
33
- * - {dataAttrs} - Serialized custom `data-*` attributes, empty if none
34
- * - {styleAttr} - Inline CSS custom properties for duration and easing
35
- * - {animationDuration} - Duration of the animation
36
36
  * - {headingTag} - Heading tag based on level (h1-h6)
37
37
  * - {className} - Base CSS class for the accordion
38
38
  * - {variantClass} - Variant modifier class (' {className}-{variant}'), empty if none
39
39
  * - {extraClasses} - Extra per-block classes (' classA classB'), empty if none
40
+ * - {tokenClasses} - Class tokens carrying the id, group, duration, easing and `data-*`
41
+ * values (' mx-accordion-id-… …'); empty with `unsafeHtml`
40
42
  * - {icon} - Icon markup (before-title alias, kept for backward compatibility)
41
43
  * - {iconBefore} - Icon markup when positioned before the title, empty otherwise
42
44
  * - {iconAfter} - Icon markup when positioned after the title, empty otherwise
45
+ *
46
+ * The 18.0 placeholders stay available to custom templates: {accordionId},
47
+ * {nameAttr}, {dataAttrs}, {styleAttr} and {animationDuration}. Strict
48
+ * sanitizers remove the attributes they produce.
49
+ */
50
+ export declare const DEFAULT_TEMPLATE = "\n<details class=\"{className}{variantClass}{extraClasses}{tokenClasses}\" {expandedAttr}>\n <summary class=\"{className}-header\">\n {iconBefore}<{headingTag} class=\"{className}-title\">{title}</{headingTag}>{iconAfter}\n </summary>\n <div class=\"{className}-content\">\n {content}\n </div>\n</details>\n";
51
+ /**
52
+ * The 18.0 template, used by default when `unsafeHtml` is `true`.
53
+ * Besides the placeholders of {@link DEFAULT_TEMPLATE}:
54
+ * - {accordionId} - Unique ID for the accordion element
55
+ * - {nameAttr} - 'name="group"' attribute for exclusive accordions, empty if none
56
+ * - {dataAttrs} - Serialized custom `data-*` attributes, empty if none
57
+ * - {styleAttr} - Inline CSS custom properties for duration and easing
58
+ * - {animationDuration} - Duration of the animation
43
59
  */
44
- export declare const DEFAULT_TEMPLATE = "\n<details id=\"{accordionId}\" class=\"{className}{variantClass}{extraClasses}\" {expandedAttr} {nameAttr}{dataAttrs} style=\"{styleAttr}\">\n <summary class=\"{className}-header\">\n {iconBefore}<{headingTag} class=\"{className}-title\">{title}</{headingTag}>{iconAfter}\n </summary>\n <div class=\"{className}-content\">\n {content}\n </div>\n</details>\n";
60
+ export declare const UNSAFE_TEMPLATE = "\n<details id=\"{accordionId}\" class=\"{className}{variantClass}{extraClasses}\" {expandedAttr} {nameAttr}{dataAttrs} style=\"{styleAttr}\">\n <summary class=\"{className}-header\">\n {iconBefore}<{headingTag} class=\"{className}-title\">{title}</{headingTag}>{iconAfter}\n </summary>\n <div class=\"{className}-content\">\n {content}\n </div>\n</details>\n";
@@ -1,12 +1,3 @@
1
- import { escapeHtml } from '../markdown-utils';
2
- export { escapeHtml };
3
- /**
4
- * Deterministic string hash (djb2) encoded as base36. Produces a stable,
5
- * SSR-safe identifier for a given input across runs.
6
- * @param value - String to hash
7
- * @returns Base36-encoded hash
8
- */
9
- export declare function hashId(value: string): string;
10
1
  /**
11
2
  * Strips a single pair of matching surrounding quotes from a value.
12
3
  * @param value - Raw value
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fsegurai/marked-extended-accordion",
3
- "version": "18.0.0",
3
+ "version": "19.0.0-beta.0",
4
4
  "description": "Extension for Marked.js that adds support for extended accordion blocks, allowing the creation of expandable panels with content. It supports any Markdown rendering and can be customized to fit your needs.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -1,19 +0,0 @@
1
- /**
2
- * Shared HTML helper for marked-extensions packages.
3
- *
4
- * SOURCE OF TRUTH: packages/.helper/utils/markdown-utils.ts
5
- * A verbatim copy of this file is written into each consuming package's `src/`
6
- * by `bun run generate:helpers`. Do NOT edit the generated copies — edit here
7
- * and re-run the generator. Each copy is bundled inline at build time, so
8
- * packages stay self-contained (no cross-package runtime dependency).
9
- *
10
- * Only genuinely universal helpers belong here. `escapeHtml` is used by every
11
- * package; partial-use helpers (e.g. hashId, stripQuotes) stay local to their
12
- * users so no package carries code it doesn't call.
13
- */
14
- /**
15
- * Escapes characters that are unsafe in HTML text/attribute contexts.
16
- * @param value - String to escape
17
- * @returns HTML-escaped string
18
- */
19
- export declare function escapeHtml(value: string): string;