@thanh01.pmt/presentation-kit 0.2.17 → 0.2.18

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.
@@ -6,7 +6,80 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
6
6
 
7
7
  var yaml__default = /*#__PURE__*/_interopDefault(yaml);
8
8
 
9
- // src/core/layout/serializer.ts
9
+ // src/plugins/shiki.ts
10
+ var highlighterPromise = null;
11
+ var highlighterFailed = false;
12
+ var SUPPORTED_LANGS = [
13
+ "javascript",
14
+ "typescript",
15
+ "python",
16
+ "cpp",
17
+ "c",
18
+ "java",
19
+ "html",
20
+ "css",
21
+ "json",
22
+ "yaml",
23
+ "bash",
24
+ "shell",
25
+ "sql",
26
+ "go",
27
+ "rust",
28
+ "swift",
29
+ "kotlin",
30
+ "ruby",
31
+ "php",
32
+ "xml",
33
+ "markdown",
34
+ "dockerfile",
35
+ "toml",
36
+ "ini",
37
+ "graphql",
38
+ "prisma",
39
+ "solidity"
40
+ ];
41
+ async function getHighlighter() {
42
+ if (highlighterFailed) {
43
+ highlighterPromise = null;
44
+ highlighterFailed = false;
45
+ }
46
+ if (!highlighterPromise) {
47
+ highlighterPromise = import('shiki').then(
48
+ (mod) => mod.createHighlighter({
49
+ themes: ["vitesse-dark", "vitesse-light"],
50
+ langs: [...SUPPORTED_LANGS]
51
+ })
52
+ ).catch((err) => {
53
+ highlighterPromise = null;
54
+ highlighterFailed = true;
55
+ throw new Error(`[presentation-kit] Failed to load Shiki highlighter: ${err}`);
56
+ });
57
+ }
58
+ return highlighterPromise;
59
+ }
60
+ function decodeHtmlEntities(html) {
61
+ return html.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&#x27;/g, "'").replace(/&nbsp;/g, " ").replace(/&#(\d+);/g, (_, code) => String.fromCharCode(Number(code))).replace(/&#x([0-9a-fA-F]+);/g, (_, hex) => String.fromCharCode(parseInt(hex, 16)));
62
+ }
63
+ function getShikiTheme(theme) {
64
+ if (theme === "light") return "vitesse-light";
65
+ return "vitesse-dark";
66
+ }
67
+ async function highlightCodeBlocks(html, theme = "dark") {
68
+ if (!html.includes("<pre><code")) return html;
69
+ const highlighter = await getHighlighter();
70
+ const shikiTheme = getShikiTheme(theme);
71
+ return html.replace(
72
+ /<pre><code class="language-(\w+)">([\s\S]*?)<\/code><\/pre>/g,
73
+ (_, lang, code) => {
74
+ const decoded = decodeHtmlEntities(code);
75
+ try {
76
+ return highlighter.codeToHtml(decoded, { lang, theme: shikiTheme });
77
+ } catch {
78
+ return `<pre><code class="language-${lang}">${code}</code></pre>`;
79
+ }
80
+ }
81
+ );
82
+ }
10
83
  function serializeLayoutToComment(layout) {
11
84
  if (!layout.boxes || layout.boxes.length === 0) return "";
12
85
  const cleanData = {
@@ -3589,6 +3662,50 @@ main();`;
3589
3662
  }
3590
3663
 
3591
3664
  // src/html-engine/compiler.ts
3665
+ var SHIKI_LANGS = /* @__PURE__ */ new Set([
3666
+ "javascript",
3667
+ "typescript",
3668
+ "python",
3669
+ "cpp",
3670
+ "c",
3671
+ "java",
3672
+ "html",
3673
+ "css",
3674
+ "json",
3675
+ "yaml",
3676
+ "bash",
3677
+ "shell",
3678
+ "sql",
3679
+ "go",
3680
+ "rust",
3681
+ "swift",
3682
+ "kotlin",
3683
+ "ruby",
3684
+ "php",
3685
+ "xml",
3686
+ "markdown",
3687
+ "dockerfile",
3688
+ "toml",
3689
+ "ini",
3690
+ "graphql",
3691
+ "prisma",
3692
+ "solidity"
3693
+ ]);
3694
+ function normalizeShikiLang(lang) {
3695
+ if (!lang) return null;
3696
+ const l = String(lang).toLowerCase().trim();
3697
+ if (SHIKI_LANGS.has(l)) return l;
3698
+ if (l === "js") return "javascript";
3699
+ if (l === "ts") return "typescript";
3700
+ if (l === "py") return "python";
3701
+ if (l === "sh") return "bash";
3702
+ if (l === "yml") return "yaml";
3703
+ if (l === "c++") return "cpp";
3704
+ return null;
3705
+ }
3706
+ function decodeHtmlEntities2(html) {
3707
+ return html.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#039;/g, "'").replace(/&#x27;/g, "'");
3708
+ }
3592
3709
  function compileHtmlDeck(deckData, options) {
3593
3710
  const theme = options?.themeOverride || resolveHtmlTheme(deckData.theme);
3594
3711
  const slides = deckData.slides || [];
@@ -3596,7 +3713,11 @@ function compileHtmlDeck(deckData, options) {
3596
3713
  const renderedSlides = slides.map((slide, index) => {
3597
3714
  const preset = HTML_SLIDE_PRESETS[slide.layoutId] || HTML_SLIDE_PRESETS["hero-cover"];
3598
3715
  const normalizedSlots = normalizeSlideSlots(slide);
3599
- const innerHtml = preset.template(normalizedSlots, theme);
3716
+ let innerHtml = preset.template(normalizedSlots, theme);
3717
+ if (normalizedSlots.code != null && String(normalizedSlots.code).trim()) {
3718
+ const lang = normalizeShikiLang(normalizedSlots.language) || "typescript";
3719
+ innerHtml = innerHtml.replace("<code>", `<code class="language-${lang}">`);
3720
+ }
3600
3721
  const notesAttr = slide.notes ? ` data-notes="${encodeURIComponent(slide.notes)}"` : "";
3601
3722
  const customClass = slide.customClass ? ` ${slide.customClass}` : "";
3602
3723
  return `
@@ -3622,14 +3743,45 @@ function compileHtmlDeck(deckData, options) {
3622
3743
  title: deckData.title
3623
3744
  };
3624
3745
  }
3746
+ async function highlightDeckCodeBlocks(html, scheme = "dark") {
3747
+ if (!html.includes('<code class="language-')) return html;
3748
+ const highlighter = await getHighlighter();
3749
+ const shikiTheme = scheme === "light" ? "vitesse-light" : "vitesse-dark";
3750
+ return html.replace(
3751
+ /<pre([^>]*)><code class="language-(\w+)">([\s\S]*?)<\/code><\/pre>/g,
3752
+ (full, preAttrs, lang, escapedCode) => {
3753
+ try {
3754
+ const decoded = decodeHtmlEntities2(escapedCode);
3755
+ return highlighter.codeToHtml(decoded, { lang, theme: shikiTheme }).replace("<pre", `<pre${preAttrs}`);
3756
+ } catch {
3757
+ return full;
3758
+ }
3759
+ }
3760
+ );
3761
+ }
3762
+ async function compileHtmlDeckAsync(deckData, options) {
3763
+ const result = compileHtmlDeck(deckData, options);
3764
+ if (options?.highlight === false) return result;
3765
+ try {
3766
+ const html = await highlightDeckCodeBlocks(result.html, result.theme.scheme);
3767
+ return { ...result, html };
3768
+ } catch (err) {
3769
+ console.warn("[html-engine] Shiki highlighting unavailable, using plain escaped code:", err);
3770
+ return result;
3771
+ }
3772
+ }
3625
3773
 
3626
3774
  exports.HTML_SLIDE_PRESETS = HTML_SLIDE_PRESETS;
3627
3775
  exports.HTML_THEMES = HTML_THEMES;
3628
3776
  exports.SLIDE_LAYOUT_PRESETS = SLIDE_LAYOUT_PRESETS;
3629
3777
  exports.compileHtmlDeck = compileHtmlDeck;
3778
+ exports.compileHtmlDeckAsync = compileHtmlDeckAsync;
3630
3779
  exports.generateHtmlShell = generateHtmlShell;
3780
+ exports.getHighlighter = getHighlighter;
3631
3781
  exports.getSlideLayoutPresetById = getSlideLayoutPresetById;
3632
3782
  exports.getSlideLayoutPresetsByCategory = getSlideLayoutPresetsByCategory;
3783
+ exports.highlightCodeBlocks = highlightCodeBlocks;
3784
+ exports.highlightDeckCodeBlocks = highlightDeckCodeBlocks;
3633
3785
  exports.normalizeSlideSlots = normalizeSlideSlots;
3634
3786
  exports.removeSlideElementFromMarkdown = removeSlideElementFromMarkdown;
3635
3787
  exports.resolveHtmlTheme = resolveHtmlTheme;
@@ -3637,5 +3789,5 @@ exports.serializeLayoutToComment = serializeLayoutToComment;
3637
3789
  exports.splitMarkdownSlides = splitMarkdownSlides;
3638
3790
  exports.updateSlideLayoutInMarkdown = updateSlideLayoutInMarkdown;
3639
3791
  exports.updateSlideTextInMarkdown = updateSlideTextInMarkdown;
3640
- //# sourceMappingURL=chunk-JNTRKKJX.cjs.map
3641
- //# sourceMappingURL=chunk-JNTRKKJX.cjs.map
3792
+ //# sourceMappingURL=chunk-SFBEDDGU.cjs.map
3793
+ //# sourceMappingURL=chunk-SFBEDDGU.cjs.map