@memberjunction/ng-markdown 5.43.0 → 5.45.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.
Files changed (49) hide show
  1. package/dist/__tests__/markdown.service.dom.test.d.ts +2 -0
  2. package/dist/__tests__/markdown.service.dom.test.d.ts.map +1 -0
  3. package/dist/__tests__/markdown.service.dom.test.js +86 -0
  4. package/dist/__tests__/markdown.service.dom.test.js.map +1 -0
  5. package/dist/__tests__/web-dom-utils.test.d.ts +2 -0
  6. package/dist/__tests__/web-dom-utils.test.d.ts.map +1 -0
  7. package/dist/__tests__/web-dom-utils.test.js +160 -0
  8. package/dist/__tests__/web-dom-utils.test.js.map +1 -0
  9. package/dist/lib/components/markdown.component.d.ts +1 -1
  10. package/dist/lib/components/markdown.component.d.ts.map +1 -1
  11. package/dist/lib/components/markdown.component.dom.test.d.ts +2 -0
  12. package/dist/lib/components/markdown.component.dom.test.d.ts.map +1 -0
  13. package/dist/lib/components/markdown.component.dom.test.js +81 -0
  14. package/dist/lib/components/markdown.component.dom.test.js.map +1 -0
  15. package/dist/lib/components/markdown.component.js +1 -1
  16. package/dist/lib/components/markdown.component.js.map +1 -1
  17. package/dist/lib/extensions/code-copy.extension.d.ts +0 -7
  18. package/dist/lib/extensions/code-copy.extension.d.ts.map +1 -1
  19. package/dist/lib/extensions/code-copy.extension.js +1 -58
  20. package/dist/lib/extensions/code-copy.extension.js.map +1 -1
  21. package/dist/lib/extensions/collapsible-headings.extension.d.ts +5 -67
  22. package/dist/lib/extensions/collapsible-headings.extension.d.ts.map +1 -1
  23. package/dist/lib/extensions/collapsible-headings.extension.js +5 -179
  24. package/dist/lib/extensions/collapsible-headings.extension.js.map +1 -1
  25. package/dist/lib/extensions/svg-renderer.extension.d.ts +5 -28
  26. package/dist/lib/extensions/svg-renderer.extension.d.ts.map +1 -1
  27. package/dist/lib/extensions/svg-renderer.extension.js +5 -72
  28. package/dist/lib/extensions/svg-renderer.extension.js.map +1 -1
  29. package/dist/lib/services/markdown.service.d.ts +27 -43
  30. package/dist/lib/services/markdown.service.d.ts.map +1 -1
  31. package/dist/lib/services/markdown.service.js +56 -235
  32. package/dist/lib/services/markdown.service.js.map +1 -1
  33. package/dist/public-api.d.ts +0 -1
  34. package/dist/public-api.d.ts.map +1 -1
  35. package/dist/public-api.js +6 -3
  36. package/dist/public-api.js.map +1 -1
  37. package/package.json +4 -6
  38. package/dist/__tests__/markdown-types.test.d.ts +0 -2
  39. package/dist/__tests__/markdown-types.test.d.ts.map +0 -1
  40. package/dist/__tests__/markdown-types.test.js +0 -78
  41. package/dist/__tests__/markdown-types.test.js.map +0 -1
  42. package/dist/lib/extensions/html-block-repair.extension.d.ts +0 -20
  43. package/dist/lib/extensions/html-block-repair.extension.d.ts.map +0 -1
  44. package/dist/lib/extensions/html-block-repair.extension.js +0 -43
  45. package/dist/lib/extensions/html-block-repair.extension.js.map +0 -1
  46. package/dist/lib/types/markdown.types.d.ts +0 -194
  47. package/dist/lib/types/markdown.types.d.ts.map +0 -1
  48. package/dist/lib/types/markdown.types.js +0 -25
  49. package/dist/lib/types/markdown.types.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"collapsible-headings.extension.js","sourceRoot":"","sources":["../../../src/lib/extensions/collapsible-headings.extension.ts"],"names":[],"mappings":"AAwCA,MAAM,eAAe,GAAoB;IACvC,UAAU,EAAE,CAAC;IACb,eAAe,EAAE,IAAI;IACrB,gBAAgB,EAAE,SAAS;IAC3B,WAAW,EAAE,aAAa;CAC3B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,UAAU,kCAAkC,CAChD,OAAoC;IAEpC,MAAM,IAAI,GAAoB,EAAE,GAAG,eAAe,EAAE,GAAG,OAAO,EAAE,CAAC;IAEjE,OAAO;QACL,QAAQ,EAAE;YACR,wEAAwE;YACxE,OAAO,CAAC,KAAqB;gBAC3B,MAAM,EAAE,KAAK,EA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OAAO,EAAE,EAAE;QAC3B,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACnC,MAAM,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,qBAAqB,CAAC,CAAC;QAC5D,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,CAAC,YAAY,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;QAChD,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,SAAsB,EAAE,SAAiB;IACvE,MAAM,OAAO,GAAG,SAAS,CAAC,aAAa,CAAC,IAAI,SAAS,EAAE,CAAC,CAAC;IACzD,IAAI,CAAC,OAAO;QAAE,OAAO;IAErB,yDAAyD;IACzD,IAAI,OAAO,GAAuB,OAAO,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAC1E,OAAO,OAAO,EAAE,CAAC;QACf,IAAI,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;YAC5C,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YACtC,MAAM,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,2DAA2D,CAAC,CAAC;YAClG,IAAI,MAAM,EAAE,CAAC;gBACX,MAAM,CAAC,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;YAC/C,CAAC;QACH,CAAC;QACD,OAAO,GAAG,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,sBAAsB,CAAC,IAAI,IAAI,CAAC;IAC3E,CAAC;AACH,CAAC","sourcesContent":["import { MarkedExtension, Tokens } from 'marked';\n\n/**\n * Options for the collapsible headings extension\n */\nexport interface CollapsibleHeadingsOptions {\n /**\n * The minimum heading level to make collapsible (1-6)\n * Headings at this level and below will be collapsible\n * @default 2\n */\n startLevel?: 1 | 2 | 3 | 4 | 5 | 6;\n\n /**\n * Whether sections should be expanded by default\n * @default true\n */\n defaultExpanded?: boolean;\n\n /**\n * Specify which heading levels should start expanded.\n * Takes precedence over defaultExpanded for specified levels.\n * @default undefined (uses defaultExpanded for all levels)\n */\n autoExpandLevels?: number[];\n\n /**\n * CSS class prefix for generated elements\n * @default 'collapsible'\n */\n classPrefix?: string;\n}\n\ninterface ResolvedOptions {\n startLevel: 1 | 2 | 3 | 4 | 5 | 6;\n defaultExpanded: boolean;\n autoExpandLevels?: number[];\n classPrefix: string;\n}\n\nconst DEFAULT_OPTIONS: ResolvedOptions = {\n startLevel: 2,\n defaultExpanded: true,\n autoExpandLevels: undefined,\n classPrefix: 'collapsible'\n};\n\n/**\n * Creates a marked extension that wraps heading sections in collapsible containers.\n *\n * This extension transforms headings into clickable toggles that can expand/collapse\n * the content that follows them (until the next heading of equal or higher level).\n *\n * The key innovation is that child sections are properly NESTED inside parent sections,\n * so collapsing a parent will hide all its children.\n *\n * Usage:\n * ```typescript\n * import { Marked } from 'marked';\n * import { createCollapsibleHeadingsExtension } from './collapsible-headings.extension';\n *\n * const marked = new Marked();\n * marked.use(createCollapsibleHeadingsExtension({ startLevel: 2 }));\n * ```\n *\n * The generated HTML structure (properly nested):\n * ```html\n * <div class=\"collapsible-section\" data-level=\"2\">\n * <div class=\"collapsible-heading-wrapper\">\n * <h2 class=\"collapsible-heading\" id=\"...\">Parent Heading</h2>\n * </div>\n * <div class=\"collapsible-content\">\n * <p>Content under parent...</p>\n * <div class=\"collapsible-section\" data-level=\"3\">\n * <div class=\"collapsible-heading-wrapper\">\n * <h3 class=\"collapsible-heading\" id=\"...\">Child Heading</h3>\n * </div>\n * <div class=\"collapsible-content\">\n * <p>Content under child...</p>\n * </div>\n * </div>\n * </div>\n * </div>\n * ```\n *\n * Note: The toggle button is added dynamically by the component after rendering\n * to avoid issues with Angular's HTML sanitizer.\n */\nexport function createCollapsibleHeadingsExtension(\n options?: CollapsibleHeadingsOptions\n): MarkedExtension {\n const opts: ResolvedOptions = { ...DEFAULT_OPTIONS, ...options };\n\n return {\n renderer: {\n // Mark headings with a special marker that we'll process in postprocess\n heading(token: Tokens.Heading): string {\n const { depth, text } = token;\n const escapedText = text.toLowerCase().replace(/[^\\w]+/g, '-');\n const id = `heading-${escapedText}`;\n\n // Only make headings collapsible at or below the start level\n if (depth >= opts.startLevel) {\n // Use a marker format that we'll parse in postprocess\n // Format: <!--COLLAPSIBLE_HEADING:level:id:text-->\n const marker = `<!--COLLAPSIBLE_HEADING:${depth}:${id}:${encodeURIComponent(text)}-->`;\n return `${marker}<h${depth} id=\"${id}\">${text}</h${depth}>\\n`;\n }\n\n // Regular heading rendering for levels above startLevel\n return `<h${depth} id=\"${id}\">${text}</h${depth}>\\n`;\n }\n },\n\n hooks: {\n postprocess(html: string): string {\n return restructureToNestedSections(html, opts);\n }\n }\n };\n}\n\n/**\n * Restructures flat HTML with heading markers into properly nested collapsible sections.\n * This is the key function that creates the hierarchical structure needed for\n * parent collapse to affect children.\n */\nfunction restructureToNestedSections(\n html: string,\n opts: ResolvedOptions\n): string {\n // Parse the HTML to find all content chunks and headings\n const markerRegex = /<!--COLLAPSIBLE_HEADING:(\\d):([^:]+):([^>]+)-->/g;\n\n // Split HTML by markers while capturing the markers\n const parts: Array<{ type: 'content' | 'heading'; content: string; level?: number; id?: string; text?: string }> = [];\n let lastIndex = 0;\n let match;\n\n while ((match = markerRegex.exec(html)) !== null) {\n // Add content before this marker\n if (match.index > lastIndex) {\n const content = html.slice(lastIndex, match.index);\n if (content.trim()) {\n parts.push({ type: 'content', content });\n }\n }\n\n // Add the heading marker info\n parts.push({\n type: 'heading',\n content: '', // Will be filled with the actual h tag\n level: parseInt(match[1], 10),\n id: match[2],\n text: decodeURIComponent(match[3])\n });\n\n lastIndex = match.index + match[0].length;\n }\n\n // Add remaining content after last marker\n if (lastIndex < html.length) {\n const content = html.slice(lastIndex);\n if (content.trim()) {\n parts.push({ type: 'content', content });\n }\n }\n\n // If no collapsible headings, return original HTML\n if (!parts.some(p => p.type === 'heading')) {\n return html;\n }\n\n // Now build the nested structure\n return buildNestedStructure(parts, opts);\n}\n\n/**\n * Determine if a heading level should start expanded based on options\n */\nfunction shouldLevelBeExpanded(level: number, opts: ResolvedOptions): boolean {\n // If autoExpandLevels is specified, use it\n if (opts.autoExpandLevels !== undefined) {\n return opts.autoExpandLevels.includes(level);\n }\n // Otherwise fall back to defaultExpanded\n return opts.defaultExpanded;\n}\n\n/**\n * Builds the nested HTML structure from the parsed parts.\n */\nfunction buildNestedStructure(\n parts: Array<{ type: 'content' | 'heading'; content: string; level?: number; id?: string; text?: string }>,\n opts: ResolvedOptions\n): string {\n const result: string[] = [];\n // Stack tracks open sections: { level, hasContent }\n const sectionStack: Array<{ level: number }> = [];\n\n for (let i = 0; i < parts.length; i++) {\n const part = parts[i];\n\n if (part.type === 'content') {\n // Regular content - just add it\n result.push(part.content);\n } else if (part.type === 'heading' && part.level !== undefined) {\n const level = part.level;\n\n // Close any sections at same or higher level (lower number = higher level)\n while (sectionStack.length > 0 && sectionStack[sectionStack.length - 1].level >= level) {\n // Close the content div and section div\n result.push('</div></div>');\n sectionStack.pop();\n }\n\n // Determine expanded state for this specific level\n const isExpanded = shouldLevelBeExpanded(level, opts);\n const expandedClass = isExpanded ? '' : ' collapsed';\n\n // Extract the actual h tag from the next content piece if it starts with it\n let headingHtml = `<h${level} class=\"${opts.classPrefix}-heading\" id=\"${part.id}\">${part.text}</h${level}>`;\n\n // Look ahead to find and remove the actual h tag from content\n if (i + 1 < parts.length && parts[i + 1].type === 'content') {\n const nextContent = parts[i + 1].content;\n const hTagRegex = new RegExp(`<h${level}[^>]*id=\"${part.id}\"[^>]*>[^<]*</h${level}>\\\\s*`);\n const hTagMatch = nextContent.match(hTagRegex);\n if (hTagMatch) {\n // Use the actual h tag and remove it from content\n headingHtml = hTagMatch[0].replace(`<h${level}`, `<h${level} class=\"${opts.classPrefix}-heading\"`);\n parts[i + 1].content = nextContent.replace(hTagRegex, '');\n }\n }\n\n // Open new section\n result.push(`<div class=\"${opts.classPrefix}-section${expandedClass}\" data-level=\"${level}\">`);\n result.push(`<div class=\"${opts.classPrefix}-heading-wrapper\">`);\n result.push(headingHtml);\n result.push('</div>');\n result.push(`<div class=\"${opts.classPrefix}-content\">`);\n\n sectionStack.push({ level });\n }\n }\n\n // Close any remaining open sections\n while (sectionStack.length > 0) {\n result.push('</div></div>');\n sectionStack.pop();\n }\n\n return result.join('');\n}\n\n/**\n * Helper function to toggle a collapsible section programmatically\n */\nexport function toggleCollapsibleSection(sectionElement: HTMLElement): void {\n const isCollapsed = sectionElement.classList.contains('collapsed');\n const toggle = sectionElement.querySelector('.collapsible-toggle');\n\n sectionElement.classList.toggle('collapsed');\n\n if (toggle) {\n toggle.setAttribute('aria-expanded', String(isCollapsed));\n }\n}\n\n/**\n * Expand all collapsible sections in a container\n */\nexport function expandAllSections(container: HTMLElement): void {\n const sections = container.querySelectorAll('.collapsible-section.collapsed');\n sections.forEach((section) => {\n section.classList.remove('collapsed');\n const toggle = section.querySelector('.collapsible-toggle');\n if (toggle) {\n toggle.setAttribute('aria-expanded', 'true');\n }\n });\n}\n\n/**\n * Collapse all collapsible sections in a container\n */\nexport function collapseAllSections(container: HTMLElement): void {\n const sections = container.querySelectorAll('.collapsible-section:not(.collapsed)');\n sections.forEach((section) => {\n section.classList.add('collapsed');\n const toggle = section.querySelector('.collapsible-toggle');\n if (toggle) {\n toggle.setAttribute('aria-expanded', 'false');\n }\n });\n}\n\n/**\n * Expand sections to reveal a specific heading by ID\n */\nexport function expandToHeading(container: HTMLElement, headingId: string): void {\n const heading = container.querySelector(`#${headingId}`);\n if (!heading) return;\n\n // Find all ancestor collapsible sections and expand them\n let current: HTMLElement | null = heading.closest('.collapsible-section');\n while (current) {\n if (current.classList.contains('collapsed')) {\n current.classList.remove('collapsed');\n const toggle = current.querySelector(':scope > .collapsible-heading-wrapper .collapsible-toggle');\n if (toggle) {\n toggle.setAttribute('aria-expanded', 'true');\n }\n }\n current = current.parentElement?.closest('.collapsible-section') || null;\n }\n}\n"]}
1
+ {"version":3,"file":"collapsible-headings.extension.js","sourceRoot":"","sources":["../../../src/lib/extensions/collapsible-headings.extension.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAC,cAA2B;IAClE,MAAM,WAAW,GAAG,cAAc,CAAC,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IACnE,MAAM,MAAM,GAAG,cAAc,CAAC,aAAa,CAAC,qBAAqB,CAAC,CAAC;IAEnE,cAAc,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAE7C,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,CAAC,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,SAAsB;IACtD,MAAM,QAAQ,GAAG,SAAS,CAAC,gBAAgB,CAAC,gCAAgC,CAAC,CAAC;IAC9E,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3B,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QACtC,MAAM,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,qBAAqB,CAAC,CAAC;QAC5D,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,CAAC,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,SAAsB;IACxD,MAAM,QAAQ,GAAG,SAAS,CAAC,gBAAgB,CAAC,sCAAsC,CAAC,CAAC;IACpF,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3B,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACnC,MAAM,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,qBAAqB,CAAC,CAAC;QAC5D,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,CAAC,YAAY,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;QAChD,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,SAAsB,EAAE,SAAiB;IACvE,MAAM,OAAO,GAAG,SAAS,CAAC,aAAa,CAAC,IAAI,SAAS,EAAE,CAAC,CAAC;IACzD,IAAI,CAAC,OAAO;QAAE,OAAO;IAErB,yDAAyD;IACzD,IAAI,OAAO,GAAuB,OAAO,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAC1E,OAAO,OAAO,EAAE,CAAC;QACf,IAAI,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;YAC5C,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YACtC,MAAM,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,2DAA2D,CAAC,CAAC;YAClG,IAAI,MAAM,EAAE,CAAC;gBACX,MAAM,CAAC,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;YAC/C,CAAC;QACH,CAAC;QACD,OAAO,GAAG,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,sBAAsB,CAAC,IAAI,IAAI,CAAC;IAC3E,CAAC;AACH,CAAC","sourcesContent":["/**\n * Web-only DOM helpers for collapsible heading sections.\n *\n * The framework-agnostic marked extension that produces the nested\n * `<div class=\"collapsible-section\">` HTML (`createCollapsibleHeadingsExtension`)\n * now lives in `@memberjunction/markdown-core`. This file keeps the browser-only\n * helpers that toggle the rendered sections in a live DOM.\n */\n\n/**\n * Helper function to toggle a collapsible section programmatically\n */\nexport function toggleCollapsibleSection(sectionElement: HTMLElement): void {\n const isCollapsed = sectionElement.classList.contains('collapsed');\n const toggle = sectionElement.querySelector('.collapsible-toggle');\n\n sectionElement.classList.toggle('collapsed');\n\n if (toggle) {\n toggle.setAttribute('aria-expanded', String(isCollapsed));\n }\n}\n\n/**\n * Expand all collapsible sections in a container\n */\nexport function expandAllSections(container: HTMLElement): void {\n const sections = container.querySelectorAll('.collapsible-section.collapsed');\n sections.forEach((section) => {\n section.classList.remove('collapsed');\n const toggle = section.querySelector('.collapsible-toggle');\n if (toggle) {\n toggle.setAttribute('aria-expanded', 'true');\n }\n });\n}\n\n/**\n * Collapse all collapsible sections in a container\n */\nexport function collapseAllSections(container: HTMLElement): void {\n const sections = container.querySelectorAll('.collapsible-section:not(.collapsed)');\n sections.forEach((section) => {\n section.classList.add('collapsed');\n const toggle = section.querySelector('.collapsible-toggle');\n if (toggle) {\n toggle.setAttribute('aria-expanded', 'false');\n }\n });\n}\n\n/**\n * Expand sections to reveal a specific heading by ID\n */\nexport function expandToHeading(container: HTMLElement, headingId: string): void {\n const heading = container.querySelector(`#${headingId}`);\n if (!heading) return;\n\n // Find all ancestor collapsible sections and expand them\n let current: HTMLElement | null = heading.closest('.collapsible-section');\n while (current) {\n if (current.classList.contains('collapsed')) {\n current.classList.remove('collapsed');\n const toggle = current.querySelector(':scope > .collapsible-heading-wrapper .collapsible-toggle');\n if (toggle) {\n toggle.setAttribute('aria-expanded', 'true');\n }\n }\n current = current.parentElement?.closest('.collapsible-section') || null;\n }\n}\n"]}
@@ -1,34 +1,11 @@
1
- import { MarkedExtension } from 'marked';
2
1
  /**
3
- * Creates a marked extension that renders SVG code blocks as actual SVG images.
2
+ * Web-only DOM utilities that complement the SVG renderer marked extension.
4
3
  *
5
- * When encountering a code block with language "svg", this extension will
6
- * render it as an actual SVG element instead of showing the code.
7
- *
8
- * This is useful for:
9
- * - UX mockups and wireframes
10
- * - Diagrams and illustrations
11
- * - Icons and simple graphics
12
- * - Any visual content that can be expressed as SVG
13
- *
14
- * Usage in markdown:
15
- * ```svg
16
- * <svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
17
- * <circle cx="50" cy="50" r="40" fill="blue"/>
18
- * </svg>
19
- * ```
20
- *
21
- * The generated HTML structure:
22
- * ```html
23
- * <div class="svg-rendered">
24
- * <svg ...>...</svg>
25
- * </div>
26
- * ```
27
- *
28
- * Security note: SVG content is rendered as-is. Make sure to only render
29
- * trusted SVG content or enable sanitization if rendering user-provided content.
4
+ * The framework-agnostic SVG tokenizer/renderer (`createSvgRendererExtension`,
5
+ * `isSvgContent`) now lives in `@memberjunction/markdown-core`. This file keeps
6
+ * the browser-only sanitization helper, which operates on a live DOM subtree
7
+ * after the SVG has been inserted into the page.
30
8
  */
31
- export declare function createSvgRendererExtension(): MarkedExtension;
32
9
  /**
33
10
  * Helper function to sanitize SVG content by removing potentially dangerous elements.
34
11
  * Call this on the container element after rendering if you need additional security.
@@ -1 +1 @@
1
- {"version":3,"file":"svg-renderer.extension.d.ts","sourceRoot":"","sources":["../../../src/lib/extensions/svg-renderer.extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,0BAA0B,IAAI,eAAe,CAmC5D;AAiBD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,WAAW,GAAG,IAAI,CAgD/D"}
1
+ {"version":3,"file":"svg-renderer.extension.d.ts","sourceRoot":"","sources":["../../../src/lib/extensions/svg-renderer.extension.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,WAAW,GAAG,IAAI,CAgD/D"}
@@ -1,78 +1,11 @@
1
1
  /**
2
- * Creates a marked extension that renders SVG code blocks as actual SVG images.
2
+ * Web-only DOM utilities that complement the SVG renderer marked extension.
3
3
  *
4
- * When encountering a code block with language "svg", this extension will
5
- * render it as an actual SVG element instead of showing the code.
6
- *
7
- * This is useful for:
8
- * - UX mockups and wireframes
9
- * - Diagrams and illustrations
10
- * - Icons and simple graphics
11
- * - Any visual content that can be expressed as SVG
12
- *
13
- * Usage in markdown:
14
- * ```svg
15
- * <svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
16
- * <circle cx="50" cy="50" r="40" fill="blue"/>
17
- * </svg>
18
- * ```
19
- *
20
- * The generated HTML structure:
21
- * ```html
22
- * <div class="svg-rendered">
23
- * <svg ...>...</svg>
24
- * </div>
25
- * ```
26
- *
27
- * Security note: SVG content is rendered as-is. Make sure to only render
28
- * trusted SVG content or enable sanitization if rendering user-provided content.
4
+ * The framework-agnostic SVG tokenizer/renderer (`createSvgRendererExtension`,
5
+ * `isSvgContent`) now lives in `@memberjunction/markdown-core`. This file keeps
6
+ * the browser-only sanitization helper, which operates on a live DOM subtree
7
+ * after the SVG has been inserted into the page.
29
8
  */
30
- export function createSvgRendererExtension() {
31
- return {
32
- extensions: [{
33
- name: 'svgCodeBlock',
34
- level: 'block',
35
- start(src) {
36
- // Look for ```svg at the start of the source
37
- const match = src.match(/^```svg\b/);
38
- return match ? match.index : undefined;
39
- },
40
- tokenizer(src) {
41
- // Match ```svg code blocks
42
- const rule = /^```svg\n([\s\S]*?)```(?:\n|$)/;
43
- const match = rule.exec(src);
44
- if (match) {
45
- const svgContent = match[1].trim();
46
- // Only process if it looks like valid SVG
47
- if (isSvgContent(svgContent)) {
48
- return {
49
- type: 'svgCodeBlock',
50
- raw: match[0],
51
- svgContent: svgContent
52
- };
53
- }
54
- }
55
- return undefined;
56
- },
57
- renderer(token) {
58
- const svgToken = token;
59
- return `<div class="svg-rendered">${svgToken.svgContent}</div>\n`;
60
- }
61
- }]
62
- };
63
- }
64
- /**
65
- * Basic validation to check if content appears to be SVG.
66
- * This is a simple check - it doesn't fully validate SVG syntax.
67
- */
68
- function isSvgContent(content) {
69
- // Check if it starts with <svg and contains closing </svg>
70
- const startsWithSvg = content.toLowerCase().startsWith('<svg');
71
- const hasSvgClosing = content.toLowerCase().includes('</svg>');
72
- // Also accept self-closing SVG (rare but valid)
73
- const isSelfClosing = content.toLowerCase().match(/<svg[^>]*\/>/);
74
- return (startsWithSvg && hasSvgClosing) || !!isSelfClosing;
75
- }
76
9
  /**
77
10
  * Helper function to sanitize SVG content by removing potentially dangerous elements.
78
11
  * Call this on the container element after rendering if you need additional security.
@@ -1 +1 @@
1
- {"version":3,"file":"svg-renderer.extension.js","sourceRoot":"","sources":["../../../src/lib/extensions/svg-renderer.extension.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,0BAA0B;IACxC,OAAO;QACL,UAAU,EAAE,CAAC;gBACX,IAAI,EAAE,cAAc;gBACpB,KAAK,EAAE,OAAO;gBACd,KAAK,CAAC,GAAW;oBACf,6CAA6C;oBAC7C,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;oBACrC,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;gBACzC,CAAC;gBACD,SAAS,CAAC,GAAW;oBACnB,2BAA2B;oBAC3B,MAAM,IAAI,GAAG,gCAAgC,CAAC;oBAC9C,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;oBAE7B,IAAI,KAAK,EAAE,CAAC;wBACV,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;wBAEnC,0CAA0C;wBAC1C,IAAI,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC;4BAC7B,OAAO;gCACL,IAAI,EAAE,cAAc;gCACpB,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;gCACb,UAAU,EAAE,UAAU;6BACvB,CAAC;wBACJ,CAAC;oBACH,CAAC;oBACD,OAAO,SAAS,CAAC;gBACnB,CAAC;gBACD,QAAQ,CAAC,KAAK;oBACZ,MAAM,QAAQ,GAAG,KAA0C,CAAC;oBAC5D,OAAO,6BAA6B,QAAQ,C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AAM,EAAE,CAAC;QACf,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { MarkedExtension } from 'marked';\n\n/**\n * Creates a marked extension that renders SVG code blocks as actual SVG images.\n *\n * When encountering a code block with language \"svg\", this extension will\n * render it as an actual SVG element instead of showing the code.\n *\n * This is useful for:\n * - UX mockups and wireframes\n * - Diagrams and illustrations\n * - Icons and simple graphics\n * - Any visual content that can be expressed as SVG\n *\n * Usage in markdown:\n * ```svg\n * <svg width=\"100\" height=\"100\" xmlns=\"http://www.w3.org/2000/svg\">\n * <circle cx=\"50\" cy=\"50\" r=\"40\" fill=\"blue\"/>\n * </svg>\n * ```\n *\n * The generated HTML structure:\n * ```html\n * <div class=\"svg-rendered\">\n * <svg ...>...</svg>\n * </div>\n * ```\n *\n * Security note: SVG content is rendered as-is. Make sure to only render\n * trusted SVG content or enable sanitization if rendering user-provided content.\n */\nexport function createSvgRendererExtension(): MarkedExtension {\n return {\n extensions: [{\n name: 'svgCodeBlock',\n level: 'block',\n start(src: string) {\n // Look for ```svg at the start of the source\n const match = src.match(/^```svg\\b/);\n return match ? match.index : undefined;\n },\n tokenizer(src: string) {\n // Match ```svg code blocks\n const rule = /^```svg\\n([\\s\\S]*?)```(?:\\n|$)/;\n const match = rule.exec(src);\n\n if (match) {\n const svgContent = match[1].trim();\n\n // Only process if it looks like valid SVG\n if (isSvgContent(svgContent)) {\n return {\n type: 'svgCodeBlock',\n raw: match[0],\n svgContent: svgContent\n };\n }\n }\n return undefined;\n },\n renderer(token) {\n const svgToken = token as unknown as { svgContent: string };\n return `<div class=\"svg-rendered\">${svgToken.svgContent}</div>\\n`;\n }\n }]\n };\n}\n\n/**\n * Basic validation to check if content appears to be SVG.\n * This is a simple check - it doesn't fully validate SVG syntax.\n */\nfunction isSvgContent(content: string): boolean {\n // Check if it starts with <svg and contains closing </svg>\n const startsWithSvg = content.toLowerCase().startsWith('<svg');\n const hasSvgClosing = content.toLowerCase().includes('</svg>');\n\n // Also accept self-closing SVG (rare but valid)\n const isSelfClosing = content.toLowerCase().match(/<svg[^>]*\\/>/);\n\n return (startsWithSvg && hasSvgClosing) || !!isSelfClosing;\n}\n\n/**\n * Helper function to sanitize SVG content by removing potentially dangerous elements.\n * Call this on the container element after rendering if you need additional security.\n *\n * @param container The DOM element containing rendered SVG\n */\nexport function sanitizeSvgContent(container: HTMLElement): void {\n // Remove script elements\n const scripts = container.querySelectorAll('script');\n scripts.forEach(script => script.remove());\n\n // Remove event handlers from all elements\n const allElements = container.querySelectorAll('*');\n allElements.forEach(el => {\n // Remove common event handler attributes\n const dangerousAttrs = [\n 'onload', 'onerror', 'onclick', 'onmouseover', 'onmouseout',\n 'onfocus', 'onblur', 'onchange', 'onsubmit', 'onreset',\n 'onkeydown', 'onkeyup', 'onkeypress'\n ];\n\n dangerousAttrs.forEach(attr => {\n if (el.hasAttribute(attr)) {\n el.removeAttribute(attr);\n }\n });\n\n // Remove javascript: URLs from href/xlink:href\n if (el.hasAttribute('href')) {\n const href = el.getAttribute('href') || '';\n if (href.toLowerCase().startsWith('javascript:')) {\n el.removeAttribute('href');\n }\n }\n if (el.hasAttribute('xlink:href')) {\n const href = el.getAttribute('xlink:href') || '';\n if (href.toLowerCase().startsWith('javascript:')) {\n el.removeAttribute('xlink:href');\n }\n }\n });\n\n // Remove foreignObject elements (can contain HTML/scripts)\n const foreignObjects = container.querySelectorAll('foreignObject');\n foreignObjects.forEach(fo => fo.remove());\n\n // Remove use elements pointing to external resources\n const useElements = container.querySelectorAll('use');\n useElements.forEach(use => {\n const href = use.getAttribute('href') || use.getAttribute('xlink:href') || '';\n if (href.startsWith('http://') || href.startsWith('https://') || href.startsWith('//')) {\n use.remove();\n }\n });\n}\n"]}
1
+ {"version":3,"file":"svg-renderer.extension.js","sourceRoot":"","sources":["../../../src/lib/extensions/svg-renderer.extension.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,SAA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AE,CAAC;gBACjD,EAAE,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;YACnC,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,2DAA2D;IAC3D,MAAM,cAAc,GAAG,SAAS,CAAC,gBAAgB,CAAC,eAAe,CAAC,CAAC;IACnE,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC;IAE1C,qDAAqD;IACrD,MAAM,WAAW,GAAG,SAAS,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACtD,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACxB,MAAM,IAAI,GAAG,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,YAAY,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;QAC9E,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACvF,GAAG,CAAC,MAAM,EAAE,CAAC;QACf,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * Web-only DOM utilities that complement the SVG renderer marked extension.\n *\n * The framework-agnostic SVG tokenizer/renderer (`createSvgRendererExtension`,\n * `isSvgContent`) now lives in `@memberjunction/markdown-core`. This file keeps\n * the browser-only sanitization helper, which operates on a live DOM subtree\n * after the SVG has been inserted into the page.\n */\n\n/**\n * Helper function to sanitize SVG content by removing potentially dangerous elements.\n * Call this on the container element after rendering if you need additional security.\n *\n * @param container The DOM element containing rendered SVG\n */\nexport function sanitizeSvgContent(container: HTMLElement): void {\n // Remove script elements\n const scripts = container.querySelectorAll('script');\n scripts.forEach(script => script.remove());\n\n // Remove event handlers from all elements\n const allElements = container.querySelectorAll('*');\n allElements.forEach(el => {\n // Remove common event handler attributes\n const dangerousAttrs = [\n 'onload', 'onerror', 'onclick', 'onmouseover', 'onmouseout',\n 'onfocus', 'onblur', 'onchange', 'onsubmit', 'onreset',\n 'onkeydown', 'onkeyup', 'onkeypress'\n ];\n\n dangerousAttrs.forEach(attr => {\n if (el.hasAttribute(attr)) {\n el.removeAttribute(attr);\n }\n });\n\n // Remove javascript: URLs from href/xlink:href\n if (el.hasAttribute('href')) {\n const href = el.getAttribute('href') || '';\n if (href.toLowerCase().startsWith('javascript:')) {\n el.removeAttribute('href');\n }\n }\n if (el.hasAttribute('xlink:href')) {\n const href = el.getAttribute('xlink:href') || '';\n if (href.toLowerCase().startsWith('javascript:')) {\n el.removeAttribute('xlink:href');\n }\n }\n });\n\n // Remove foreignObject elements (can contain HTML/scripts)\n const foreignObjects = container.querySelectorAll('foreignObject');\n foreignObjects.forEach(fo => fo.remove());\n\n // Remove use elements pointing to external resources\n const useElements = container.querySelectorAll('use');\n useElements.forEach(use => {\n const href = use.getAttribute('href') || use.getAttribute('xlink:href') || '';\n if (href.startsWith('http://') || href.startsWith('https://') || href.startsWith('//')) {\n use.remove();\n }\n });\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { MarkdownConfig, HeadingInfo } from '../types/markdown.types';
1
+ import { MarkdownConfig, ResolvedMarkdownConfig, HeadingInfo } from '@memberjunction/markdown-core';
2
2
  import 'prismjs/components/prism-typescript';
3
3
  import 'prismjs/components/prism-javascript';
4
4
  import 'prismjs/components/prism-css';
@@ -14,37 +14,33 @@ import 'prismjs/components/prism-yaml';
14
14
  import 'prismjs/components/prism-markdown';
15
15
  import 'prismjs/components/prism-graphql';
16
16
  import * as i0 from "@angular/core";
17
- type ResolvedMarkdownConfig = Required<Omit<MarkdownConfig, 'autoExpandLevels'>> & {
18
- autoExpandLevels?: number[];
19
- };
20
17
  /**
21
- * Service for parsing and rendering markdown content.
22
- * Uses marked.js with various extensions for syntax highlighting,
23
- * diagrams, alerts, and more.
18
+ * Service for parsing and rendering markdown content on the web.
19
+ *
20
+ * The parsing/configuration work (marked setup, custom extensions, HTML and
21
+ * token output) is owned by the framework-agnostic `@memberjunction/markdown-core`
22
+ * {@link MarkdownEngine}. This Angular service is the web shell around it: it
23
+ * injects a Prism-based highlighter into the engine and keeps the browser-only
24
+ * concerns here — Mermaid rendering, copy buttons, and the DOM-based fixup of
25
+ * HTML that marked miscoded as a code block.
24
26
  */
25
27
  export declare class MarkdownService {
26
- private marked;
28
+ private engine;
27
29
  private mermaidInitialized;
28
30
  private lastMermaidTheme;
29
31
  private currentConfig;
30
- private headingList;
31
- constructor();
32
- /**
33
- * Configure the marked instance with the provided options
34
- */
35
- configureMarked(config: MarkdownConfig): void;
36
32
  /**
37
- * Resolve the effective mermaid theme.
38
- * 'auto' maps to 'dark' or 'default' based on the document's data-theme attribute.
33
+ * Prism-backed highlight function injected into the core engine. The engine
34
+ * itself has no Prism dependency it calls this for the HTML output path.
39
35
  */
40
- private resolveEffectiveMermaidTheme;
36
+ private prismHighlight;
37
+ constructor();
41
38
  /**
42
- * Initialize Mermaid with the current theme configuration.
43
- * Re-initializes when the effective theme changes.
39
+ * Configure the underlying engine with the provided options.
44
40
  */
45
- private initializeMermaid;
41
+ configureMarked(config: MarkdownConfig): void;
46
42
  /**
47
- * Parse markdown to HTML
43
+ * Parse markdown to HTML.
48
44
  * @param markdown The markdown string to parse
49
45
  * @param config Optional config overrides for this parse operation
50
46
  * @returns The rendered HTML string
@@ -54,6 +50,16 @@ export declare class MarkdownService {
54
50
  * Parse markdown asynchronously (useful for large documents)
55
51
  */
56
52
  parseAsync(markdown: string, config?: Partial<MarkdownConfig>): Promise<string>;
53
+ /**
54
+ * Resolve the effective mermaid theme.
55
+ * 'auto' maps to 'dark' or 'default' based on the document's data-theme attribute.
56
+ */
57
+ private resolveEffectiveMermaidTheme;
58
+ /**
59
+ * Initialize Mermaid with the current theme configuration.
60
+ * Re-initializes when the effective theme changes.
61
+ */
62
+ private initializeMermaid;
57
63
  /**
58
64
  * Render Mermaid diagrams in a container element
59
65
  * Call this after the HTML has been inserted into the DOM
@@ -98,10 +104,6 @@ export declare class MarkdownService {
98
104
  * Get list of supported Prism languages
99
105
  */
100
106
  getSupportedLanguages(): string[];
101
- /**
102
- * Escape HTML entities for safe display
103
- */
104
- private escapeHtml;
105
107
  /**
106
108
  * Fix HTML that was incorrectly wrapped in <pre><code> blocks by marked.
107
109
  * This happens when marked interprets inline HTML (especially indented HTML)
@@ -118,25 +120,7 @@ export declare class MarkdownService {
118
120
  * that indicate this is meant to be rendered HTML, not code.
119
121
  */
120
122
  private looksLikeStructuralHtml;
121
- /**
122
- * Normalize indentation in HTML blocks to prevent marked from treating
123
- * indented HTML as code blocks (4 spaces = code block in markdown).
124
- *
125
- * This finds HTML blocks (starting with common block-level tags) and
126
- * removes ALL leading whitespace from lines within those blocks to ensure
127
- * marked doesn't interpret any nested content as code blocks.
128
- */
129
- private normalizeHtmlBlockIndentation;
130
- /**
131
- * Check if a line contains a self-closing tag or opens and closes the same tag
132
- */
133
- private isSelfClosingLine;
134
- /**
135
- * Update the tag stack based on opening/closing tags in the line
136
- */
137
- private updateTagStack;
138
123
  static ɵfac: i0.ɵɵFactoryDeclaration<MarkdownService, never>;
139
124
  static ɵprov: i0.ɵɵInjectableDeclaration<MarkdownService>;
140
125
  }
141
- export {};
142
126
  //# sourceMappingURL=markdown.service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.service.d.ts","sourceRoot":"","sources":["../../../src/lib/services/markdown.service.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,cAAc,EAEd,WAAW,EAEZ,MAAM,yBAAyB,CAAC;AAOjC,OAAO,qCAAqC,CAAC;AAC7C,OAAO,qCAAqC,CAAC;AAC7C,OAAO,8BAA8B,CAAC;AACtC,OAAO,+BAA+B,CAAC;AACvC,OAAO,+BAA+B,CAAC;AACvC,OAAO,+BAA+B,CAAC;AACvC,OAAO,8BAA8B,CAAC;AACtC,OAAO,iCAAiC,CAAC;AACzC,OAAO,iCAAiC,CAAC;AACzC,OAAO,+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G;IACI,WAAW,IAAI,IAAI;IAI1B;;OAEG;IACI,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIjD;;OAEG;IACI,qBAAqB,IAAI,MAAM,EAAE;IAMxC;;OAEG;IACH,OAAO,CAAC,UAAU;IAMlB;;;;;;;;OAQG;IACH,OAAO,CAAC,kBAAkB;IAsE1B;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;IAyB/B;;;;;;;OAOG;IACH,OAAO,CAAC,6BAA6B;IA0DrC;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAWzB;;OAEG;IACH,OAAO,CAAC,cAAc;yCApiBX,eAAe;6CAAf,eAAe;CAskB3B"}
1
+ {"version":3,"file":"markdown.service.d.ts","sourceRoot":"","sources":["../../../src/lib/services/markdown.service.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,cAAc,EAEd,sBAAsB,EACtB,WAAW,EAEZ,MAAM,+BAA+B,CAAC;AAIvC,OAAO,qCAAqC,CAAC;AAC7C,OAAO,qCAAqC,CAAC;AAC7C,OAAO,8BAA8B,CAAC;AACtC,OAAO,+BAA+B,CAAC;AACvC,OAAO,+BAA+B,CAAC;AACvC,OAAO,+BAA+B,CAAC;AACvC,OAAO,8BAA8B,CAAC;AACtC,OAAO,iCAAiC,CAAC;AACzC,OAAO,iCAAiC,CAAC;AACzC,OAAO,+BAA+B,CAAC;AACvC,OAAO,iCAAiC,CAAC;AACzC,OAAO,+BAA+B,CAAC;AACvC,OAAO,mCAAmC,CAAC;AAC3C,OAAO,kCAAkC,CAAC;;AAE1C;;;;;;;;;GASG;AACH,qBAGa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAwB;IACtC,OAAO,CAAC,kBAAkB,CAAS;IACnC,OAAO,CAAC,gBAAgB,CAAuB;IAC/C,OAAO,CAAC,aAAa,CAA0D;IAE/E;;;OAGG;IACH,OAAO,CAAC,cAAc,CAUpB;;IAMF;;OAEG;IACI,eAAe,CAAC,MAAM,EAAE,cAAc,GA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