lit-intlayer 9.9.3 → 9.9.4

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.
Files changed (72) hide show
  1. package/dist/cjs/client/IntlayerBinding.cjs +93 -1
  2. package/dist/cjs/client/index.cjs +28 -1
  3. package/dist/cjs/client/installIntlayer.cjs +6 -1
  4. package/dist/cjs/client/useDictionary.cjs +24 -1
  5. package/dist/cjs/client/useDictionaryDynamic.cjs +47 -1
  6. package/dist/cjs/client/useIntlayer.cjs +30 -1
  7. package/dist/cjs/client/useLocale.cjs +90 -1
  8. package/dist/cjs/client/useLocaleStorage.cjs +56 -1
  9. package/dist/cjs/client/useRewriteURL.cjs +48 -1
  10. package/dist/cjs/editor/useEditor.cjs +3 -1
  11. package/dist/cjs/format/index.cjs +19 -1
  12. package/dist/cjs/format/useCompact.cjs +34 -1
  13. package/dist/cjs/format/useCurrency.cjs +34 -1
  14. package/dist/cjs/format/useDate.cjs +52 -1
  15. package/dist/cjs/format/useIntl.cjs +66 -1
  16. package/dist/cjs/format/useList.cjs +34 -1
  17. package/dist/cjs/format/useNumber.cjs +40 -1
  18. package/dist/cjs/format/usePercentage.cjs +34 -1
  19. package/dist/cjs/format/useRelativeTime.cjs +34 -1
  20. package/dist/cjs/format/useUnit.cjs +34 -1
  21. package/dist/cjs/getDictionary.cjs +14 -1
  22. package/dist/cjs/getIntlayer.cjs +14 -1
  23. package/dist/cjs/html/HTMLRenderer.cjs +53 -1
  24. package/dist/cjs/html/index.cjs +8 -1
  25. package/dist/cjs/html/installIntlayerHTML.cjs +90 -1
  26. package/dist/cjs/html/types.cjs +1 -1
  27. package/dist/cjs/index.cjs +41 -1
  28. package/dist/cjs/markdown/MarkdownRenderer.cjs +97 -1
  29. package/dist/cjs/markdown/compiler.cjs +72 -1
  30. package/dist/cjs/markdown/index.cjs +12 -1
  31. package/dist/cjs/markdown/installIntlayerMarkdown.cjs +98 -1
  32. package/dist/cjs/markdown/runtime.cjs +86 -1
  33. package/dist/cjs/plugins.cjs +217 -3
  34. package/dist/cjs/renderIntlayerNode.cjs +29 -1
  35. package/dist/esm/client/IntlayerBinding.mjs +75 -33
  36. package/dist/esm/client/index.mjs +9 -9
  37. package/dist/esm/client/installIntlayer.mjs +1 -1
  38. package/dist/esm/client/useDictionary.mjs +22 -10
  39. package/dist/esm/client/useDictionaryDynamic.mjs +44 -11
  40. package/dist/esm/client/useIntlayer.mjs +28 -10
  41. package/dist/esm/client/useLocale.mjs +71 -19
  42. package/dist/esm/client/useLocaleStorage.mjs +45 -12
  43. package/dist/esm/client/useRewriteURL.mjs +36 -18
  44. package/dist/esm/editor/useEditor.mjs +1 -1
  45. package/dist/esm/format/index.mjs +10 -10
  46. package/dist/esm/format/useCompact.mjs +23 -19
  47. package/dist/esm/format/useCurrency.mjs +23 -19
  48. package/dist/esm/format/useDate.mjs +37 -27
  49. package/dist/esm/format/useIntl.mjs +54 -13
  50. package/dist/esm/format/useList.mjs +23 -19
  51. package/dist/esm/format/useNumber.mjs +29 -19
  52. package/dist/esm/format/usePercentage.mjs +23 -19
  53. package/dist/esm/format/useRelativeTime.mjs +23 -19
  54. package/dist/esm/format/useUnit.mjs +23 -19
  55. package/dist/esm/getDictionary.mjs +11 -6
  56. package/dist/esm/getIntlayer.mjs +11 -6
  57. package/dist/esm/html/HTMLRenderer.mjs +38 -13
  58. package/dist/esm/html/index.mjs +3 -3
  59. package/dist/esm/html/installIntlayerHTML.mjs +82 -13
  60. package/dist/esm/index.mjs +12 -12
  61. package/dist/esm/markdown/MarkdownRenderer.mjs +66 -26
  62. package/dist/esm/markdown/compiler.mjs +68 -22
  63. package/dist/esm/markdown/index.mjs +4 -4
  64. package/dist/esm/markdown/installIntlayerMarkdown.mjs +87 -23
  65. package/dist/esm/markdown/runtime.mjs +58 -28
  66. package/dist/esm/plugins.mjs +156 -106
  67. package/dist/esm/renderIntlayerNode.mjs +17 -17
  68. package/dist/installIntlayer-CCMOc1XT.mjs +174 -0
  69. package/dist/installIntlayer-HB8aIQ-i.js +203 -0
  70. package/package.json +7 -7
  71. package/dist/installIntlayer-CFvvijL7.js +0 -1
  72. package/dist/installIntlayer-CTpPd7yz.mjs +0 -82
@@ -1,17 +1,86 @@
1
1
  // src/html/installIntlayerHTML.ts
2
- var e = null, t = (t) => e || (e = { renderHTML: t }, e), n = (e) => {
3
- let n;
4
- if (typeof e == "function") n = e;
2
+ /**
3
+ * Singleton instance
4
+ */
5
+ var instance = null;
6
+ /**
7
+ * Create and return a single IntlayerHTMLProvider instance.
8
+ */
9
+ var createIntlayerHTMLClient = (renderHTML) => {
10
+ if (instance) return instance;
11
+ instance = { renderHTML };
12
+ return instance;
13
+ };
14
+ /**
15
+ * Install the Intlayer HTML provider for your Lit application.
16
+ *
17
+ * The installed renderer is used by `<intlayer-html-renderer>` and
18
+ * `useHTMLRenderer()`.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import { installIntlayerHTML } from 'lit-intlayer';
23
+ *
24
+ * installIntlayerHTML({
25
+ * components: {
26
+ * a: ({ href, children }) => `<a class="styled-link" href="${href}">${children}</a>`,
27
+ * },
28
+ * });
29
+ * ```
30
+ */
31
+ var installIntlayerHTML = (pluginOptions) => {
32
+ let renderHTML;
33
+ if (typeof pluginOptions === "function") renderHTML = pluginOptions;
5
34
  else {
6
- let { components: t, renderHTML: r } = e ?? {};
7
- n = r || ((e, n) => {
8
- let r = n && typeof n == "object" && "components" in n ? n.components : n, i = {
9
- ...t ?? {},
10
- ...r ?? {}
35
+ const { components, renderHTML: customRender } = pluginOptions ?? {};
36
+ if (customRender) renderHTML = customRender;
37
+ else renderHTML = (rawHTML, overrides) => {
38
+ const overrideComponents = overrides && typeof overrides === "object" && "components" in overrides ? overrides.components : overrides;
39
+ const mergedComponents = {
40
+ ...components ?? {},
41
+ ...overrideComponents ?? {}
11
42
  };
12
- return Object.keys(i).length, e;
13
- });
43
+ if (!Object.keys(mergedComponents).length) return rawHTML;
44
+ return rawHTML;
45
+ };
14
46
  }
15
- return t(n);
16
- }, r = () => e || { renderHTML: (e) => e }, i = async (t) => e || n(await t());
17
- export { t as createIntlayerHTMLClient, n as installIntlayerHTML, i as installIntlayerHTMLDynamic, r as useHTML };
47
+ return createIntlayerHTMLClient(renderHTML);
48
+ };
49
+ /**
50
+ * Access the installed IntlayerHTMLProvider.
51
+ * Returns a fallback renderer that outputs the raw HTML string if no
52
+ * provider has been installed.
53
+ */
54
+ var useHTML = () => {
55
+ if (instance) return instance;
56
+ return { renderHTML: (rawHTML) => rawHTML };
57
+ };
58
+ /**
59
+ * Asynchronously install an HTML renderer whose implementation is loaded
60
+ * via a dynamic `import()`.
61
+ *
62
+ * Use this to keep a heavy HTML sanitiser / component renderer out of the
63
+ * initial bundle — the loader is only called the first time this function
64
+ * is executed.
65
+ *
66
+ * The returned promise resolves once the provider is ready. Any calls to
67
+ * `useHTML()` before the promise resolves will use the fallback (identity)
68
+ * renderer.
69
+ *
70
+ * @param loader - A zero-argument async function that resolves to either a
71
+ * `RenderHTMLFunction` or an `IntlayerHTMLPluginOptions` object.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * // Load a custom HTML sanitiser only when needed
76
+ * await installIntlayerHTMLDynamic(async () => {
77
+ * const DOMPurify = await import('dompurify');
78
+ * return (html) => DOMPurify.sanitize(html);
79
+ * });
80
+ * ```
81
+ */
82
+ var installIntlayerHTMLDynamic = async (loader) => {
83
+ if (instance) return instance;
84
+ return installIntlayerHTML(await loader());
85
+ };
86
+ export { createIntlayerHTMLClient, installIntlayerHTML, installIntlayerHTMLDynamic, useHTML };
@@ -1,13 +1,13 @@
1
- import { getLocaleInStorage as e, localeCookie as t, localeInStorage as n, setLocaleCookie as r, setLocaleInStorage as i, useLocaleCookie as a, useLocaleStorage as o } from "./client/useLocaleStorage.mjs";
2
- import { a as s, i as c, n as l, r as u, t as d } from "../installIntlayer-CTpPd7yz.mjs";
3
- import { getDictionary as f } from "./getDictionary.mjs";
4
- import { getIntlayer as p } from "./getIntlayer.mjs";
5
- import { IntlayerBinding as m, createContentProxy as h } from "./client/IntlayerBinding.mjs";
6
- import { getPlugins as g, htmlPlugin as _, insertionPlugin as v, intlayerNodePlugins as y, markdownPlugin as b, markdownStringPlugin as x } from "./plugins.mjs";
7
- import { useDictionary as S } from "./client/useDictionary.mjs";
8
- import { useDictionaryDynamic as C } from "./client/useDictionaryDynamic.mjs";
9
- import { useIntlayer as w } from "./client/useIntlayer.mjs";
10
- import { LocaleController as T, useLocale as E } from "./client/useLocale.mjs";
11
- import { useRewriteURL as D } from "./client/useRewriteURL.mjs";
1
+ import { getLocaleInStorage, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage } from "./client/useLocaleStorage.mjs";
2
+ import { a as useEditor, i as installIntlayer, n as createIntlayerClient, r as getIntlayerClient, t as IntlayerClient } from "../installIntlayer-CCMOc1XT.mjs";
3
+ import { getDictionary } from "./getDictionary.mjs";
4
+ import { getIntlayer } from "./getIntlayer.mjs";
5
+ import { IntlayerBinding, createContentProxy } from "./client/IntlayerBinding.mjs";
6
+ import { useDictionary } from "./client/useDictionary.mjs";
7
+ import { useDictionaryDynamic } from "./client/useDictionaryDynamic.mjs";
8
+ import { getPlugins, htmlPlugin, insertionPlugin, intlayerNodePlugins, markdownPlugin, markdownStringPlugin } from "./plugins.mjs";
9
+ import { useIntlayer } from "./client/useIntlayer.mjs";
10
+ import { LocaleController, useLocale } from "./client/useLocale.mjs";
11
+ import { useRewriteURL } from "./client/useRewriteURL.mjs";
12
12
  import "./client/index.mjs";
13
- export { m as IntlayerBinding, d as IntlayerClient, T as LocaleController, h as createContentProxy, l as createIntlayerClient, f as getDictionary, p as getIntlayer, u as getIntlayerClient, e as getLocaleInStorage, g as getPlugins, _ as htmlPlugin, v as insertionPlugin, c as installIntlayer, y as intlayerNodePlugins, t as localeCookie, n as localeInStorage, b as markdownPlugin, x as markdownStringPlugin, r as setLocaleCookie, i as setLocaleInStorage, S as useDictionary, C as useDictionaryDynamic, s as useEditor, w as useIntlayer, E as useLocale, a as useLocaleCookie, o as useLocaleStorage, D as useRewriteURL };
13
+ export { IntlayerBinding, IntlayerClient, LocaleController, createContentProxy, createIntlayerClient, getDictionary, getIntlayer, getIntlayerClient, getLocaleInStorage, getPlugins, htmlPlugin, insertionPlugin, installIntlayer, intlayerNodePlugins, localeCookie, localeInStorage, markdownPlugin, markdownStringPlugin, setLocaleCookie, setLocaleInStorage, useDictionary, useDictionaryDynamic, useEditor, useIntlayer, useLocale, useLocaleCookie, useLocaleStorage, useRewriteURL };
@@ -1,54 +1,94 @@
1
- import { LitElement as e, html as t, nothing as n } from "lit";
2
- import { unsafeHTML as r } from "lit/directives/unsafe-html.js";
3
- import { compileMarkdown as i } from "./compiler.mjs";
4
- import { useMarkdown as a } from "./installIntlayerMarkdown.mjs";
1
+ import { LitElement, html, nothing } from "lit";
2
+ import { unsafeHTML } from "lit/directives/unsafe-html.js";
3
+ import { compileMarkdown } from "./compiler.mjs";
4
+ import { useMarkdown } from "./installIntlayerMarkdown.mjs";
5
5
  // src/markdown/MarkdownRenderer.ts
6
- var o = (e, { forceBlock: t, forceInline: n, preserveFrontmatter: r, tagfilter: a } = {}) => i(e, {
7
- forceBlock: t,
8
- forceInline: n,
9
- preserveFrontmatter: r,
10
- tagfilter: a
11
- }), s = (e = {}) => {
12
- let t = a();
13
- return (n) => t.renderMarkdown(n, {
14
- forceBlock: e.forceBlock,
15
- forceInline: e.forceInline,
16
- preserveFrontmatter: e.preserveFrontmatter,
17
- tagfilter: e.tagfilter
18
- }, e.components, e.wrapper);
19
- }, c = class extends e {
6
+ /**
7
+ * Renders markdown to an HTML string without using the global provider.
8
+ * Pass the result to `unsafeHTML()` in a Lit template.
9
+ */
10
+ var renderMarkdown = (content, { forceBlock, forceInline, preserveFrontmatter, tagfilter } = {}) => {
11
+ return compileMarkdown(content, {
12
+ forceBlock,
13
+ forceInline,
14
+ preserveFrontmatter,
15
+ tagfilter
16
+ });
17
+ };
18
+ /**
19
+ * Returns a render function that uses the global provider's configuration
20
+ * (installed via `installIntlayerMarkdown`), falling back to `compileMarkdown`.
21
+ */
22
+ var useMarkdownRenderer = (props = {}) => {
23
+ const provider = useMarkdown();
24
+ return (content) => provider.renderMarkdown(content, {
25
+ forceBlock: props.forceBlock,
26
+ forceInline: props.forceInline,
27
+ preserveFrontmatter: props.preserveFrontmatter,
28
+ tagfilter: props.tagfilter
29
+ }, props.components, props.wrapper);
30
+ };
31
+ /**
32
+ * `<intlayer-markdown-renderer>` — renders a markdown string as HTML.
33
+ *
34
+ * Renders into the light DOM (no shadow root) so that the host page's CSS
35
+ * can style the generated markup.
36
+ *
37
+ * Uses the globally installed markdown renderer when available
38
+ * (see `installIntlayerMarkdown`), or falls back to the default compiler.
39
+ *
40
+ * @example
41
+ * ```html
42
+ * <intlayer-markdown-renderer content="# Hello **World**">
43
+ * </intlayer-markdown-renderer>
44
+ * ```
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * import { html } from 'lit';
49
+ * import 'lit-intlayer/markdown'; // registers the element
50
+ *
51
+ * html`<intlayer-markdown-renderer .content=${myMarkdown}></intlayer-markdown-renderer>`
52
+ * ```
53
+ */
54
+ var MarkdownRenderer = class extends LitElement {
20
55
  static properties = {
21
56
  content: { type: [String, Object] },
22
57
  forceBlock: { type: Boolean },
23
58
  forceInline: { type: Boolean },
24
59
  preserveFrontmatter: { type: Boolean },
25
60
  tagfilter: { type: Boolean },
26
- renderMarkdown: { attribute: !1 }
61
+ renderMarkdown: { attribute: false }
27
62
  };
63
+ /** The markdown string to compile and render. */
28
64
  content = "";
29
65
  forceBlock;
30
66
  forceInline;
31
67
  preserveFrontmatter;
32
68
  tagfilter;
69
+ /** Optional custom render function — overrides the global provider. */
33
70
  renderMarkdownFn;
71
+ /** Render into light DOM so host-page CSS can style the output. */
34
72
  createRenderRoot() {
35
73
  return this;
36
74
  }
37
75
  render() {
38
- if (!this.content) return n;
39
- let e;
40
- return e = this.renderMarkdownFn ? this.renderMarkdownFn(this.content, {
76
+ if (!this.content) return nothing;
77
+ let compiled;
78
+ if (this.renderMarkdownFn) compiled = this.renderMarkdownFn(this.content, {
41
79
  forceBlock: this.forceBlock,
42
80
  forceInline: this.forceInline,
43
81
  preserveFrontmatter: this.preserveFrontmatter,
44
82
  tagfilter: this.tagfilter
45
- }, void 0, void 0) : s({
83
+ }, void 0, void 0);
84
+ else compiled = useMarkdownRenderer({
46
85
  forceBlock: this.forceBlock,
47
86
  forceInline: this.forceInline,
48
87
  preserveFrontmatter: this.preserveFrontmatter,
49
88
  tagfilter: this.tagfilter
50
- })(this.content), t`${r(e)}`;
89
+ })(this.content);
90
+ return html`${unsafeHTML(compiled)}`;
51
91
  }
52
92
  };
53
- customElements.get("intlayer-markdown-renderer") || customElements.define("intlayer-markdown-renderer", c);
54
- export { c as MarkdownRenderer, o as renderMarkdown, s as useMarkdownRenderer };
93
+ if (!customElements.get("intlayer-markdown-renderer")) customElements.define("intlayer-markdown-renderer", MarkdownRenderer);
94
+ export { MarkdownRenderer, renderMarkdown, useMarkdownRenderer };
@@ -1,24 +1,70 @@
1
- import { compileWithOptions as e, parseMarkdown as t, renderMarkdownAst as n } from "@intlayer/core/markdown";
2
- import r from "./runtime.mjs";
1
+ import { compileWithOptions, parseMarkdown as parseMarkdown$1, renderMarkdownAst } from "@intlayer/core/markdown";
2
+ import litRuntime from "./runtime.mjs";
3
3
  // src/markdown/compiler.ts
4
- var i = (e = "", n = {}) => {
5
- let { components: i, namedCodesToUnicode: a, sanitizer: o, slugify: s, ...c } = n;
6
- return t(e, {
7
- runtime: r,
8
- components: i,
9
- namedCodesToUnicode: a,
10
- sanitizer: o,
11
- slugify: s
12
- }, c);
13
- }, a = (t = "", i = {}) => {
14
- if (typeof t == "string") return e(t, r, i);
15
- let { components: a, namedCodesToUnicode: o, sanitizer: s, slugify: c, ...l } = i;
16
- return n(t, {
17
- runtime: r,
18
- components: a,
19
- namedCodesToUnicode: o,
20
- sanitizer: s,
21
- slugify: c
22
- }, l);
4
+ /**
5
+ * Lit adapter for the framework-agnostic markdown processor.
6
+ *
7
+ * Compiles markdown to an HTML string for use with Lit's `unsafeHTML` directive
8
+ * or the `<intlayer-markdown-renderer>` custom element.
9
+ */
10
+ /**
11
+ * **Step 1 of 2 — parse only.**
12
+ * Converts a raw markdown string into a `ParsedMarkdown` AST without rendering
13
+ * any HTML. Use this when you need to:
14
+ * - Cache the parsed result and render it several times with different options.
15
+ * - Inspect or transform the AST before rendering.
16
+ * - Defer the render step to a later point.
17
+ *
18
+ * @param markdown - The markdown source string.
19
+ * @param options - Options that affect parsing (sanitizer, slugify, …).
20
+ * @returns A `ParsedMarkdown` AST ready to be passed to `compileMarkdown`.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * const ast = parseMarkdown('# Hello **World**');
25
+ * const html = compileMarkdown(ast);
26
+ * ```
27
+ */
28
+ var parseMarkdown = (markdown = "", options = {}) => {
29
+ const { components, namedCodesToUnicode, sanitizer, slugify, ...compilerOptions } = options;
30
+ return parseMarkdown$1(markdown, {
31
+ runtime: litRuntime,
32
+ components,
33
+ namedCodesToUnicode,
34
+ sanitizer,
35
+ slugify
36
+ }, compilerOptions);
23
37
  };
24
- export { a as compileMarkdown, i as parseMarkdown };
38
+ /**
39
+ * **Steps 1 + 2 — parse and render in one shot.**
40
+ * Accepts a raw markdown string or a pre-parsed `ParsedMarkdown` AST and
41
+ * returns an HTML string. Use with Lit's `unsafeHTML` directive or the
42
+ * `<intlayer-markdown-renderer>` custom element.
43
+ *
44
+ * @param input - Markdown string or pre-parsed AST.
45
+ * @param options - Rendering options (custom components, sanitizer, slugify, …).
46
+ * @returns An HTML string representing the rendered markdown.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * import { unsafeHTML } from 'lit/directives/unsafe-html.js';
51
+ *
52
+ * class MyElement extends LitElement {
53
+ * render() {
54
+ * return html`${unsafeHTML(compileMarkdown('# Hello **World**'))}`;
55
+ * }
56
+ * }
57
+ * ```
58
+ */
59
+ var compileMarkdown = (input = "", options = {}) => {
60
+ if (typeof input === "string") return compileWithOptions(input, litRuntime, options);
61
+ const { components, namedCodesToUnicode, sanitizer, slugify, ...compilerOptions } = options;
62
+ return renderMarkdownAst(input, {
63
+ runtime: litRuntime,
64
+ components,
65
+ namedCodesToUnicode,
66
+ sanitizer,
67
+ slugify
68
+ }, compilerOptions);
69
+ };
70
+ export { compileMarkdown, parseMarkdown };
@@ -1,4 +1,4 @@
1
- import { compileMarkdown as e, parseMarkdown as t } from "./compiler.mjs";
2
- import { installIntlayerMarkdown as n, installIntlayerMarkdownDynamic as r, useMarkdown as i } from "./installIntlayerMarkdown.mjs";
3
- import { MarkdownRenderer as a, renderMarkdown as o, useMarkdownRenderer as s } from "./MarkdownRenderer.mjs";
4
- export { a as MarkdownRenderer, e as compileMarkdown, n as installIntlayerMarkdown, r as installIntlayerMarkdownDynamic, t as parseMarkdown, o as renderMarkdown, i as useMarkdown, s as useMarkdownRenderer };
1
+ import { compileMarkdown, parseMarkdown } from "./compiler.mjs";
2
+ import { installIntlayerMarkdown, installIntlayerMarkdownDynamic, useMarkdown } from "./installIntlayerMarkdown.mjs";
3
+ import { MarkdownRenderer, renderMarkdown, useMarkdownRenderer } from "./MarkdownRenderer.mjs";
4
+ export { MarkdownRenderer, compileMarkdown, installIntlayerMarkdown, installIntlayerMarkdownDynamic, parseMarkdown, renderMarkdown, useMarkdown, useMarkdownRenderer };
@@ -1,30 +1,94 @@
1
- import { compileMarkdown as e } from "./compiler.mjs";
1
+ import { compileMarkdown } from "./compiler.mjs";
2
2
  // src/markdown/installIntlayerMarkdown.ts
3
- var t = null, n = (e, n) => t || (t = {
4
- components: n,
5
- renderMarkdown: e
6
- }, t), r = (t) => {
7
- let r, i;
8
- if (typeof t == "function") r = t;
3
+ /**
4
+ * Singleton instance
5
+ */
6
+ var instance = null;
7
+ /**
8
+ * Create and return a single IntlayerMarkdownProvider instance.
9
+ */
10
+ var createIntlayerMarkdownClient = (renderMarkdown, components) => {
11
+ if (instance) return instance;
12
+ instance = {
13
+ components,
14
+ renderMarkdown
15
+ };
16
+ return instance;
17
+ };
18
+ /**
19
+ * Install the Intlayer Markdown provider for your Lit application.
20
+ *
21
+ * Call once at startup, before any elements that render markdown are connected.
22
+ * The installed renderer is used by `<intlayer-markdown-renderer>` and
23
+ * `useMarkdownRenderer()`.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * import { installIntlayerMarkdown } from 'lit-intlayer/markdown';
28
+ *
29
+ * installIntlayerMarkdown({ forceBlock: true });
30
+ * ```
31
+ */
32
+ var installIntlayerMarkdown = (pluginOptions) => {
33
+ let renderMarkdown;
34
+ let providerComponents;
35
+ if (typeof pluginOptions === "function") renderMarkdown = pluginOptions;
9
36
  else {
10
- let { components: n, wrapper: a, forceBlock: o, forceInline: s, preserveFrontmatter: c, tagfilter: l, renderMarkdown: u } = t ?? {};
11
- if (i = n, u) r = u;
37
+ const { components, wrapper, forceBlock, forceInline, preserveFrontmatter, tagfilter, renderMarkdown: customRender } = pluginOptions ?? {};
38
+ providerComponents = components;
39
+ if (customRender) renderMarkdown = customRender;
12
40
  else {
13
- let t = {
14
- forceBlock: o,
15
- forceInline: s,
16
- preserveFrontmatter: c,
17
- tagfilter: l
41
+ const internalOptions = {
42
+ forceBlock,
43
+ forceInline,
44
+ preserveFrontmatter,
45
+ tagfilter
18
46
  };
19
- r = (n, r, i, a) => e(n, {
20
- ...t,
21
- forceBlock: r?.forceBlock ?? t.forceBlock,
22
- forceInline: r?.forceInline ?? t.forceInline,
23
- preserveFrontmatter: r?.preserveFrontmatter ?? t.preserveFrontmatter,
24
- tagfilter: r?.tagfilter ?? t.tagfilter
47
+ renderMarkdown = (markdown, options, componentsOverride, wrapperOverride) => compileMarkdown(markdown, {
48
+ ...internalOptions,
49
+ forceBlock: options?.forceBlock ?? internalOptions.forceBlock,
50
+ forceInline: options?.forceInline ?? internalOptions.forceInline,
51
+ preserveFrontmatter: options?.preserveFrontmatter ?? internalOptions.preserveFrontmatter,
52
+ tagfilter: options?.tagfilter ?? internalOptions.tagfilter
25
53
  });
26
54
  }
27
55
  }
28
- return n(r, i);
29
- }, i = () => t || { renderMarkdown: (t) => e(t) }, a = async (e) => t || r(await e());
30
- export { n as createIntlayerMarkdownClient, r as installIntlayerMarkdown, a as installIntlayerMarkdownDynamic, i as useMarkdown };
56
+ return createIntlayerMarkdownClient(renderMarkdown, providerComponents);
57
+ };
58
+ /**
59
+ * Access the installed IntlayerMarkdownProvider.
60
+ * Returns a fallback renderer that outputs the raw markdown string if no
61
+ * provider has been installed.
62
+ */
63
+ var useMarkdown = () => {
64
+ if (instance) return instance;
65
+ return { renderMarkdown: (markdown) => compileMarkdown(markdown) };
66
+ };
67
+ /**
68
+ * Asynchronously install a markdown renderer whose implementation is loaded
69
+ * via a dynamic `import()`.
70
+ *
71
+ * Use this to keep the markdown compiler out of the initial bundle — the
72
+ * loader is only called the first time this function is executed.
73
+ *
74
+ * The returned promise resolves once the provider is ready. Any calls to
75
+ * `useMarkdown()` before the promise resolves will use the fallback
76
+ * (raw-string) renderer.
77
+ *
78
+ * @param loader - A zero-argument async function that resolves to either a
79
+ * `RenderMarkdownFunction` or an `IntlayerMarkdownPluginOptions` object.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * // Load a custom markdown renderer (e.g. marked) only when needed
84
+ * await installIntlayerMarkdownDynamic(async () => {
85
+ * const { marked } = await import('marked');
86
+ * return (markdown) => marked(markdown) as string;
87
+ * });
88
+ * ```
89
+ */
90
+ var installIntlayerMarkdownDynamic = async (loader) => {
91
+ if (instance) return instance;
92
+ return installIntlayerMarkdown(await loader());
93
+ };
94
+ export { createIntlayerMarkdownClient, installIntlayerMarkdown, installIntlayerMarkdownDynamic, useMarkdown };
@@ -1,5 +1,5 @@
1
1
  // src/markdown/runtime.ts
2
- var e = /* @__PURE__ */ new Set([
2
+ var SELF_CLOSING_TAGS = /* @__PURE__ */ new Set([
3
3
  "area",
4
4
  "base",
5
5
  "br",
@@ -14,37 +14,67 @@ var e = /* @__PURE__ */ new Set([
14
14
  "source",
15
15
  "track",
16
16
  "wbr"
17
- ]), t = (e) => e ? Object.entries(e).filter(([e, t]) => t != null && e !== "key").map(([e, t]) => typeof t == "boolean" ? t ? e : "" : e === "_innerHTML" ? "" : `${e}="${String(t).replace(/&/g, "&amp;").replace(/"/g, "&quot;")}"`).filter(Boolean).join(" ") : "", n = "__lit_fragment__", r = {
18
- createElement: (r, i, ...a) => {
19
- let o = a.flat(1e400).join("");
20
- if (r === n) return o;
21
- if (typeof r == "string") {
22
- let n = t(i), a = n ? ` ${n}` : "", s = i?._innerHTML;
23
- return e.has(r) ? `<${r}${a}>` : s === void 0 ? `<${r}${a}>${o}</${r}>` : `<${r}${a}>${s}</${r}>`;
17
+ ]);
18
+ var buildPropsString = (props) => {
19
+ if (!props) return "";
20
+ return Object.entries(props).filter(([key, value]) => value !== void 0 && value !== null && key !== "key").map(([key, value]) => {
21
+ if (typeof value === "boolean") return value ? key : "";
22
+ if (key === "_innerHTML") return "";
23
+ return `${key}="${String(value).replace(/&/g, "&amp;").replace(/"/g, "&quot;")}"`;
24
+ }).filter(Boolean).join(" ");
25
+ };
26
+ var LIT_FRAGMENT = "__lit_fragment__";
27
+ /**
28
+ * Lit-specific MarkdownRuntime that produces HTML strings.
29
+ */
30
+ var litRuntime = {
31
+ createElement: (type, props, ...children) => {
32
+ const childStr = children.flat(1e400).join("");
33
+ if (type === LIT_FRAGMENT) return childStr;
34
+ if (typeof type === "string") {
35
+ const propsStr = buildPropsString(props);
36
+ const propsWithSpace = propsStr ? ` ${propsStr}` : "";
37
+ const innerHTML = props?._innerHTML;
38
+ if (SELF_CLOSING_TAGS.has(type)) return `<${type}${propsWithSpace}>`;
39
+ if (innerHTML !== void 0) return `<${type}${propsWithSpace}>${innerHTML}</${type}>`;
40
+ return `<${type}${propsWithSpace}>${childStr}</${type}>`;
24
41
  }
25
- if (typeof r == "function") try {
26
- let e = r({
27
- ...i,
28
- children: o
42
+ if (typeof type === "function") try {
43
+ const result = type({
44
+ ...props,
45
+ children: childStr
29
46
  });
30
- return typeof e == "string" ? e : o;
47
+ return typeof result === "string" ? result : childStr;
31
48
  } catch {
32
- return o;
49
+ return childStr;
33
50
  }
34
- return o;
51
+ return childStr;
52
+ },
53
+ cloneElement: (element, _props, ..._children) => {
54
+ return typeof element === "string" ? element : String(element ?? "");
35
55
  },
36
- cloneElement: (e, t, ...n) => typeof e == "string" ? e : String(e ?? ""),
37
- Fragment: n,
38
- normalizeProps: (e, t) => {
39
- let n = {};
40
- for (let [e, r] of Object.entries(t)) e === "className" ? n.class = r : e === "htmlFor" ? n.for = r : e === "dangerouslySetInnerHTML" && r?.__html ? n._innerHTML = r.__html : n[e] = r;
41
- return n;
56
+ Fragment: LIT_FRAGMENT,
57
+ /**
58
+ * Normalize props to standard HTML attribute names.
59
+ */
60
+ normalizeProps: (_tag, props) => {
61
+ const normalized = {};
62
+ for (const [key, value] of Object.entries(props)) if (key === "className") normalized.class = value;
63
+ else if (key === "htmlFor") normalized.for = value;
64
+ else if (key === "dangerouslySetInnerHTML" && value?.__html) normalized._innerHTML = value.__html;
65
+ else normalized[key] = value;
66
+ return normalized;
42
67
  }
43
- }, i = (e = {}) => {
44
- let { onCreateElement: t } = e;
45
- return t ? {
46
- ...r,
47
- createElement: (e, n, ...r) => t(e, n, r)
48
- } : r;
49
68
  };
50
- export { i as createLitRuntime, r as default, r as litRuntime };
69
+ /**
70
+ * Creates a Lit runtime with a custom createElement for advanced use cases.
71
+ */
72
+ var createLitRuntime = (options = {}) => {
73
+ const { onCreateElement } = options;
74
+ if (onCreateElement) return {
75
+ ...litRuntime,
76
+ createElement: (type, props, ...children) => onCreateElement(type, props, children)
77
+ };
78
+ return litRuntime;
79
+ };
80
+ export { createLitRuntime, litRuntime as default, litRuntime };