@ox-content/vite-plugin 1.0.0-alpha.0 → 2.0.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 (58) hide show
  1. package/dist/chunk.cjs +39 -49
  2. package/dist/github.cjs +323 -3
  3. package/dist/github.cjs.map +1 -0
  4. package/dist/github.mjs +2 -0
  5. package/dist/{github2.js → github2.mjs} +2 -3
  6. package/dist/github2.mjs.map +1 -0
  7. package/dist/index.cjs +1371 -598
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +114 -69
  10. package/dist/index.d.cts.map +1 -1
  11. package/dist/index.d.mts +1960 -0
  12. package/dist/index.d.mts.map +1 -0
  13. package/dist/{index.js → index.mjs} +1383 -623
  14. package/dist/index.mjs.map +1 -0
  15. package/dist/mermaid.cjs +115 -3
  16. package/dist/mermaid.cjs.map +1 -0
  17. package/dist/{mermaid2.js → mermaid.mjs} +14 -6
  18. package/dist/mermaid.mjs.map +1 -0
  19. package/dist/mermaid2.mjs +2 -0
  20. package/dist/ogp.cjs +316 -3
  21. package/dist/ogp.cjs.map +1 -0
  22. package/dist/ogp.mjs +2 -0
  23. package/dist/{ogp2.js → ogp2.mjs} +2 -3
  24. package/dist/ogp2.mjs.map +1 -0
  25. package/dist/tabs.cjs +212 -3
  26. package/dist/tabs.cjs.map +1 -0
  27. package/dist/tabs.mjs +2 -0
  28. package/dist/{tabs2.js → tabs2.mjs} +2 -3
  29. package/dist/tabs2.mjs.map +1 -0
  30. package/dist/youtube.cjs +135 -3
  31. package/dist/youtube.cjs.map +1 -0
  32. package/dist/youtube.mjs +2 -0
  33. package/dist/{youtube2.js → youtube2.mjs} +2 -3
  34. package/dist/youtube2.mjs.map +1 -0
  35. package/package.json +61 -56
  36. package/dist/github.js +0 -3
  37. package/dist/github2.cjs +0 -313
  38. package/dist/github2.cjs.map +0 -1
  39. package/dist/github2.js.map +0 -1
  40. package/dist/index.d.ts +0 -1915
  41. package/dist/index.d.ts.map +0 -1
  42. package/dist/index.js.map +0 -1
  43. package/dist/mermaid.js +0 -3
  44. package/dist/mermaid2.cjs +0 -92
  45. package/dist/mermaid2.cjs.map +0 -1
  46. package/dist/mermaid2.js.map +0 -1
  47. package/dist/ogp.js +0 -3
  48. package/dist/ogp2.cjs +0 -306
  49. package/dist/ogp2.cjs.map +0 -1
  50. package/dist/ogp2.js.map +0 -1
  51. package/dist/tabs.js +0 -3
  52. package/dist/tabs2.cjs +0 -203
  53. package/dist/tabs2.cjs.map +0 -1
  54. package/dist/tabs2.js.map +0 -1
  55. package/dist/youtube.js +0 -3
  56. package/dist/youtube2.cjs +0 -127
  57. package/dist/youtube2.cjs.map +0 -1
  58. package/dist/youtube2.js.map +0 -1
package/dist/tabs2.cjs DELETED
@@ -1,203 +0,0 @@
1
- const require_chunk = require('./chunk.cjs');
2
- let unified = require("unified");
3
- let rehype_parse = require("rehype-parse");
4
- rehype_parse = require_chunk.__toESM(rehype_parse);
5
- let rehype_stringify = require("rehype-stringify");
6
- rehype_stringify = require_chunk.__toESM(rehype_stringify);
7
-
8
- //#region src/plugins/tabs.ts
9
- /**
10
- * Tabs Plugin - Pure CSS implementation
11
- *
12
- * Transforms <Tabs>/<Tab> components into accessible HTML
13
- * with CSS :has() based tab switching (no JavaScript required).
14
- */
15
- let tabGroupCounter = 0;
16
- /**
17
- * Reset tab group counter (for testing).
18
- */
19
- function resetTabGroupCounter() {
20
- tabGroupCounter = 0;
21
- }
22
- /**
23
- * Get element attribute value.
24
- */
25
- function getAttribute(el, name) {
26
- const value = el.properties?.[name];
27
- if (typeof value === "string") return value;
28
- if (Array.isArray(value)) return value.join(" ");
29
- }
30
- /**
31
- * Parse Tab elements from Tabs children.
32
- */
33
- function parseTabChildren(children) {
34
- const tabs = [];
35
- for (const child of children) {
36
- if (child.type !== "element") continue;
37
- if (child.tagName.toLowerCase() === "tab") {
38
- const label = getAttribute(child, "label") || `Tab ${tabs.length + 1}`;
39
- tabs.push({
40
- label,
41
- content: child.children.filter((c) => c.type === "element" || c.type === "text")
42
- });
43
- }
44
- }
45
- return tabs;
46
- }
47
- /**
48
- * Create the HTML structure for tabs.
49
- */
50
- function createTabsElement(tabs, groupId) {
51
- const children = [];
52
- const headerChildren = [];
53
- tabs.forEach((tab, index) => {
54
- const inputId = `ox-tab-${groupId}-${index}`;
55
- headerChildren.push({
56
- type: "element",
57
- tagName: "input",
58
- properties: {
59
- type: "radio",
60
- name: `ox-tabs-${groupId}`,
61
- id: inputId,
62
- checked: index === 0 ? true : void 0
63
- },
64
- children: []
65
- });
66
- headerChildren.push({
67
- type: "element",
68
- tagName: "label",
69
- properties: { htmlFor: inputId },
70
- children: [{
71
- type: "text",
72
- value: tab.label
73
- }]
74
- });
75
- });
76
- children.push({
77
- type: "element",
78
- tagName: "div",
79
- properties: { className: ["ox-tabs-header"] },
80
- children: headerChildren
81
- });
82
- tabs.forEach((tab, index) => {
83
- children.push({
84
- type: "element",
85
- tagName: "div",
86
- properties: {
87
- className: ["ox-tab-panel"],
88
- "data-tab": String(index)
89
- },
90
- children: tab.content
91
- });
92
- });
93
- return {
94
- type: "element",
95
- tagName: "div",
96
- properties: {
97
- className: ["ox-tabs"],
98
- "data-group": groupId
99
- },
100
- children
101
- };
102
- }
103
- /**
104
- * Create fallback HTML using <details> elements.
105
- */
106
- function createFallbackElement(tabs) {
107
- const children = [];
108
- tabs.forEach((tab, index) => {
109
- children.push({
110
- type: "element",
111
- tagName: "details",
112
- properties: { open: index === 0 ? true : void 0 },
113
- children: [{
114
- type: "element",
115
- tagName: "summary",
116
- properties: {},
117
- children: [{
118
- type: "text",
119
- value: tab.label
120
- }]
121
- }, {
122
- type: "element",
123
- tagName: "div",
124
- properties: { className: ["ox-tabs-fallback-content"] },
125
- children: tab.content
126
- }]
127
- });
128
- });
129
- return {
130
- type: "element",
131
- tagName: "noscript",
132
- properties: {},
133
- children: [{
134
- type: "element",
135
- tagName: "div",
136
- properties: { className: ["ox-tabs-fallback"] },
137
- children
138
- }]
139
- };
140
- }
141
- /**
142
- * Rehype plugin to transform Tabs components.
143
- */
144
- function rehypeTabs() {
145
- return (tree) => {
146
- const visit = (node) => {
147
- if ("children" in node) for (let i = 0; i < node.children.length; i++) {
148
- const child = node.children[i];
149
- if (child.type === "element") if (child.tagName.toLowerCase() === "tabs") {
150
- const tabs = parseTabChildren(child.children);
151
- if (tabs.length > 0) {
152
- const wrapper = {
153
- type: "element",
154
- tagName: "div",
155
- properties: { className: ["ox-tabs-container"] },
156
- children: [createTabsElement(tabs, String(tabGroupCounter++)), createFallbackElement(tabs)]
157
- };
158
- node.children[i] = wrapper;
159
- }
160
- } else visit(child);
161
- }
162
- };
163
- visit(tree);
164
- };
165
- }
166
- /**
167
- * Transform Tabs components in HTML.
168
- */
169
- async function transformTabs(html) {
170
- const result = await (0, unified.unified)().use(rehype_parse.default, { fragment: true }).use(rehypeTabs).use(rehype_stringify.default).process(html);
171
- return String(result);
172
- }
173
- /**
174
- * Generate dynamic CSS for :has() based tab switching.
175
- * This is needed because :has() selectors need unique IDs.
176
- */
177
- function generateTabsCSS(groupCount) {
178
- if (groupCount === 0) return "";
179
- let css = "/* Dynamic Tabs CSS */\n";
180
- for (let g = 0; g < groupCount; g++) for (let t = 0; t < 8; t++) css += `.ox-tabs[data-group="${g}"]:has(#ox-tab-${g}-${t}:checked) .ox-tab-panel[data-tab="${t}"] { display: block; }\n`;
181
- return css;
182
- }
183
-
184
- //#endregion
185
- Object.defineProperty(exports, 'generateTabsCSS', {
186
- enumerable: true,
187
- get: function () {
188
- return generateTabsCSS;
189
- }
190
- });
191
- Object.defineProperty(exports, 'resetTabGroupCounter', {
192
- enumerable: true,
193
- get: function () {
194
- return resetTabGroupCounter;
195
- }
196
- });
197
- Object.defineProperty(exports, 'transformTabs', {
198
- enumerable: true,
199
- get: function () {
200
- return transformTabs;
201
- }
202
- });
203
- //# sourceMappingURL=tabs2.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tabs2.cjs","names":["rehypeParse","rehypeStringify"],"sources":["../src/plugins/tabs.ts"],"sourcesContent":["/**\n * Tabs Plugin - Pure CSS implementation\n *\n * Transforms <Tabs>/<Tab> components into accessible HTML\n * with CSS :has() based tab switching (no JavaScript required).\n */\n\nimport { unified } from \"unified\";\nimport rehypeParse from \"rehype-parse\";\nimport rehypeStringify from \"rehype-stringify\";\nimport type { Root, Element } from \"hast\";\n\nlet tabGroupCounter = 0;\n\n/**\n * Reset tab group counter (for testing).\n */\nexport function resetTabGroupCounter(): void {\n tabGroupCounter = 0;\n}\n\n/**\n * Get element attribute value.\n */\nfunction getAttribute(el: Element, name: string): string | undefined {\n const value = el.properties?.[name];\n if (typeof value === \"string\") return value;\n if (Array.isArray(value)) return value.join(\" \");\n return undefined;\n}\n\ninterface TabData {\n label: string;\n content: Element[];\n}\n\n/**\n * Parse Tab elements from Tabs children.\n */\nfunction parseTabChildren(children: Element[\"children\"]): TabData[] {\n const tabs: TabData[] = [];\n\n for (const child of children) {\n if (child.type !== \"element\") continue;\n\n // Handle <Tab label=\"...\">\n if (child.tagName.toLowerCase() === \"tab\") {\n const label = getAttribute(child, \"label\") || `Tab ${tabs.length + 1}`;\n tabs.push({\n label,\n content: child.children.filter(\n (c): c is Element => c.type === \"element\" || c.type === \"text\",\n ) as Element[],\n });\n }\n }\n\n return tabs;\n}\n\n/**\n * Create the HTML structure for tabs.\n */\nfunction createTabsElement(tabs: TabData[], groupId: string): Element {\n const children: Element[\"children\"] = [];\n\n // Create header with radio inputs and labels\n const headerChildren: Element[\"children\"] = [];\n\n tabs.forEach((tab, index) => {\n const inputId = `ox-tab-${groupId}-${index}`;\n\n // Radio input\n headerChildren.push({\n type: \"element\",\n tagName: \"input\",\n properties: {\n type: \"radio\",\n name: `ox-tabs-${groupId}`,\n id: inputId,\n checked: index === 0 ? true : undefined,\n },\n children: [],\n });\n\n // Label\n headerChildren.push({\n type: \"element\",\n tagName: \"label\",\n properties: {\n htmlFor: inputId,\n },\n children: [{ type: \"text\", value: tab.label }],\n });\n });\n\n // Tabs header\n children.push({\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-tabs-header\"] },\n children: headerChildren,\n });\n\n // Tab panels\n tabs.forEach((tab, index) => {\n children.push({\n type: \"element\",\n tagName: \"div\",\n properties: {\n className: [\"ox-tab-panel\"],\n \"data-tab\": String(index),\n },\n children: tab.content,\n });\n });\n\n return {\n type: \"element\",\n tagName: \"div\",\n properties: {\n className: [\"ox-tabs\"],\n \"data-group\": groupId,\n },\n children,\n };\n}\n\n/**\n * Create fallback HTML using <details> elements.\n */\nfunction createFallbackElement(tabs: TabData[]): Element {\n const children: Element[\"children\"] = [];\n\n tabs.forEach((tab, index) => {\n children.push({\n type: \"element\",\n tagName: \"details\",\n properties: {\n open: index === 0 ? true : undefined,\n },\n children: [\n {\n type: \"element\",\n tagName: \"summary\",\n properties: {},\n children: [{ type: \"text\", value: tab.label }],\n },\n {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-tabs-fallback-content\"] },\n children: tab.content,\n },\n ],\n });\n });\n\n return {\n type: \"element\",\n tagName: \"noscript\",\n properties: {},\n children: [\n {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-tabs-fallback\"] },\n children,\n },\n ],\n };\n}\n\n/**\n * Rehype plugin to transform Tabs components.\n */\nfunction rehypeTabs() {\n return (tree: Root) => {\n const visit = (node: Root | Element) => {\n if (\"children\" in node) {\n for (let i = 0; i < node.children.length; i++) {\n const child = node.children[i];\n\n if (child.type === \"element\") {\n // Check for <Tabs> component\n if (child.tagName.toLowerCase() === \"tabs\") {\n const tabs = parseTabChildren(child.children);\n\n if (tabs.length > 0) {\n const groupId = String(tabGroupCounter++);\n const tabsElement = createTabsElement(tabs, groupId);\n const fallbackElement = createFallbackElement(tabs);\n\n // Replace <Tabs> with new structure\n // Keep main tabs and add noscript fallback\n const wrapper: Element = {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-tabs-container\"] },\n children: [tabsElement, fallbackElement],\n };\n\n node.children[i] = wrapper;\n }\n } else {\n visit(child);\n }\n }\n }\n }\n };\n\n visit(tree);\n };\n}\n\n/**\n * Transform Tabs components in HTML.\n */\nexport async function transformTabs(html: string): Promise<string> {\n const result = await unified()\n .use(rehypeParse, { fragment: true })\n .use(rehypeTabs)\n .use(rehypeStringify)\n .process(html);\n\n return String(result);\n}\n\n/**\n * Generate dynamic CSS for :has() based tab switching.\n * This is needed because :has() selectors need unique IDs.\n */\nexport function generateTabsCSS(groupCount: number): string {\n if (groupCount === 0) return \"\";\n\n let css = \"/* Dynamic Tabs CSS */\\n\";\n\n for (let g = 0; g < groupCount; g++) {\n for (let t = 0; t < 8; t++) {\n css += `.ox-tabs[data-group=\"${g}\"]:has(#ox-tab-${g}-${t}:checked) .ox-tab-panel[data-tab=\"${t}\"] { display: block; }\\n`;\n }\n }\n\n return css;\n}\n"],"mappings":";;;;;;;;;;;;;;AAYA,IAAI,kBAAkB;;;;AAKtB,SAAgB,uBAA6B;AAC3C,mBAAkB;;;;;AAMpB,SAAS,aAAa,IAAa,MAAkC;CACnE,MAAM,QAAQ,GAAG,aAAa;AAC9B,KAAI,OAAO,UAAU,SAAU,QAAO;AACtC,KAAI,MAAM,QAAQ,MAAM,CAAE,QAAO,MAAM,KAAK,IAAI;;;;;AAYlD,SAAS,iBAAiB,UAA0C;CAClE,MAAM,OAAkB,EAAE;AAE1B,MAAK,MAAM,SAAS,UAAU;AAC5B,MAAI,MAAM,SAAS,UAAW;AAG9B,MAAI,MAAM,QAAQ,aAAa,KAAK,OAAO;GACzC,MAAM,QAAQ,aAAa,OAAO,QAAQ,IAAI,OAAO,KAAK,SAAS;AACnE,QAAK,KAAK;IACR;IACA,SAAS,MAAM,SAAS,QACrB,MAAoB,EAAE,SAAS,aAAa,EAAE,SAAS,OACzD;IACF,CAAC;;;AAIN,QAAO;;;;;AAMT,SAAS,kBAAkB,MAAiB,SAA0B;CACpE,MAAM,WAAgC,EAAE;CAGxC,MAAM,iBAAsC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;GACE,MAAM;GACN,SAAS;GACT,YAAY,EAAE,WAAW,CAAC,mBAAmB,EAAE;GAC/C;GACD,CACF;EACF;;;;;AAMH,SAAS,aAAa;AACpB,SAAQ,SAAe;EACrB,MAAM,SAAS,SAAyB;AACtC,OAAI,cAAc,KAChB,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,SAAS,QAAQ,KAAK;IAC7C,MAAM,QAAQ,KAAK,SAAS;AAE5B,QAAI,MAAM,SAAS,UAEjB,KAAI,MAAM,QAAQ,aAAa,KAAK,QAAQ;KAC1C,MAAM,OAAO,iBAAiB,MAAM,SAAS;AAE7C,SAAI,KAAK,SAAS,GAAG;MAOnB,MAAM,UAAmB;OACvB,MAAM;OACN,SAAS;OACT,YAAY,EAAE,WAAW,CAAC,oBAAoB,EAAE;OAChD,UAAU,CATQ,kBAAkB,MADtB,OAAO,kBAAkB,CACW,EAC5B,sBAAsB,KAAK,CAQT;OACzC;AAED,WAAK,SAAS,KAAK;;UAGrB,OAAM,MAAM;;;AAOtB,QAAM,KAAK;;;;;;AAOf,eAAsB,cAAc,MAA+B;CACjE,MAAM,SAAS,4BAAe,CAC3B,IAAIA,sBAAa,EAAE,UAAU,MAAM,CAAC,CACpC,IAAI,WAAW,CACf,IAAIC,yBAAgB,CACpB,QAAQ,KAAK;AAEhB,QAAO,OAAO,OAAO;;;;;;AAOvB,SAAgB,gBAAgB,YAA4B;AAC1D,KAAI,eAAe,EAAG,QAAO;CAE7B,IAAI,MAAM;AAEV,MAAK,IAAI,IAAI,GAAG,IAAI,YAAY,IAC9B,MAAK,IAAI,IAAI,GAAG,IAAI,GAAG,IACrB,QAAO,wBAAwB,EAAE,iBAAiB,EAAE,GAAG,EAAE,oCAAoC,EAAE;AAInG,QAAO"}
package/dist/tabs2.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"tabs2.js","names":[],"sources":["../src/plugins/tabs.ts"],"sourcesContent":["/**\n * Tabs Plugin - Pure CSS implementation\n *\n * Transforms <Tabs>/<Tab> components into accessible HTML\n * with CSS :has() based tab switching (no JavaScript required).\n */\n\nimport { unified } from \"unified\";\nimport rehypeParse from \"rehype-parse\";\nimport rehypeStringify from \"rehype-stringify\";\nimport type { Root, Element } from \"hast\";\n\nlet tabGroupCounter = 0;\n\n/**\n * Reset tab group counter (for testing).\n */\nexport function resetTabGroupCounter(): void {\n tabGroupCounter = 0;\n}\n\n/**\n * Get element attribute value.\n */\nfunction getAttribute(el: Element, name: string): string | undefined {\n const value = el.properties?.[name];\n if (typeof value === \"string\") return value;\n if (Array.isArray(value)) return value.join(\" \");\n return undefined;\n}\n\ninterface TabData {\n label: string;\n content: Element[];\n}\n\n/**\n * Parse Tab elements from Tabs children.\n */\nfunction parseTabChildren(children: Element[\"children\"]): TabData[] {\n const tabs: TabData[] = [];\n\n for (const child of children) {\n if (child.type !== \"element\") continue;\n\n // Handle <Tab label=\"...\">\n if (child.tagName.toLowerCase() === \"tab\") {\n const label = getAttribute(child, \"label\") || `Tab ${tabs.length + 1}`;\n tabs.push({\n label,\n content: child.children.filter(\n (c): c is Element => c.type === \"element\" || c.type === \"text\",\n ) as Element[],\n });\n }\n }\n\n return tabs;\n}\n\n/**\n * Create the HTML structure for tabs.\n */\nfunction createTabsElement(tabs: TabData[], groupId: string): Element {\n const children: Element[\"children\"] = [];\n\n // Create header with radio inputs and labels\n const headerChildren: Element[\"children\"] = [];\n\n tabs.forEach((tab, index) => {\n const inputId = `ox-tab-${groupId}-${index}`;\n\n // Radio input\n headerChildren.push({\n type: \"element\",\n tagName: \"input\",\n properties: {\n type: \"radio\",\n name: `ox-tabs-${groupId}`,\n id: inputId,\n checked: index === 0 ? true : undefined,\n },\n children: [],\n });\n\n // Label\n headerChildren.push({\n type: \"element\",\n tagName: \"label\",\n properties: {\n htmlFor: inputId,\n },\n children: [{ type: \"text\", value: tab.label }],\n });\n });\n\n // Tabs header\n children.push({\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-tabs-header\"] },\n children: headerChildren,\n });\n\n // Tab panels\n tabs.forEach((tab, index) => {\n children.push({\n type: \"element\",\n tagName: \"div\",\n properties: {\n className: [\"ox-tab-panel\"],\n \"data-tab\": String(index),\n },\n children: tab.content,\n });\n });\n\n return {\n type: \"element\",\n tagName: \"div\",\n properties: {\n className: [\"ox-tabs\"],\n \"data-group\": groupId,\n },\n children,\n };\n}\n\n/**\n * Create fallback HTML using <details> elements.\n */\nfunction createFallbackElement(tabs: TabData[]): Element {\n const children: Element[\"children\"] = [];\n\n tabs.forEach((tab, index) => {\n children.push({\n type: \"element\",\n tagName: \"details\",\n properties: {\n open: index === 0 ? true : undefined,\n },\n children: [\n {\n type: \"element\",\n tagName: \"summary\",\n properties: {},\n children: [{ type: \"text\", value: tab.label }],\n },\n {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-tabs-fallback-content\"] },\n children: tab.content,\n },\n ],\n });\n });\n\n return {\n type: \"element\",\n tagName: \"noscript\",\n properties: {},\n children: [\n {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-tabs-fallback\"] },\n children,\n },\n ],\n };\n}\n\n/**\n * Rehype plugin to transform Tabs components.\n */\nfunction rehypeTabs() {\n return (tree: Root) => {\n const visit = (node: Root | Element) => {\n if (\"children\" in node) {\n for (let i = 0; i < node.children.length; i++) {\n const child = node.children[i];\n\n if (child.type === \"element\") {\n // Check for <Tabs> component\n if (child.tagName.toLowerCase() === \"tabs\") {\n const tabs = parseTabChildren(child.children);\n\n if (tabs.length > 0) {\n const groupId = String(tabGroupCounter++);\n const tabsElement = createTabsElement(tabs, groupId);\n const fallbackElement = createFallbackElement(tabs);\n\n // Replace <Tabs> with new structure\n // Keep main tabs and add noscript fallback\n const wrapper: Element = {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-tabs-container\"] },\n children: [tabsElement, fallbackElement],\n };\n\n node.children[i] = wrapper;\n }\n } else {\n visit(child);\n }\n }\n }\n }\n };\n\n visit(tree);\n };\n}\n\n/**\n * Transform Tabs components in HTML.\n */\nexport async function transformTabs(html: string): Promise<string> {\n const result = await unified()\n .use(rehypeParse, { fragment: true })\n .use(rehypeTabs)\n .use(rehypeStringify)\n .process(html);\n\n return String(result);\n}\n\n/**\n * Generate dynamic CSS for :has() based tab switching.\n * This is needed because :has() selectors need unique IDs.\n */\nexport function generateTabsCSS(groupCount: number): string {\n if (groupCount === 0) return \"\";\n\n let css = \"/* Dynamic Tabs CSS */\\n\";\n\n for (let g = 0; g < groupCount; g++) {\n for (let t = 0; t < 8; t++) {\n css += `.ox-tabs[data-group=\"${g}\"]:has(#ox-tab-${g}-${t}:checked) .ox-tab-panel[data-tab=\"${t}\"] { display: block; }\\n`;\n }\n }\n\n return css;\n}\n"],"mappings":";;;;;;;;;;;AAYA,IAAI,kBAAkB;;;;AAKtB,SAAgB,uBAA6B;AAC3C,mBAAkB;;;;;AAMpB,SAAS,aAAa,IAAa,MAAkC;CACnE,MAAM,QAAQ,GAAG,aAAa;AAC9B,KAAI,OAAO,UAAU,SAAU,QAAO;AACtC,KAAI,MAAM,QAAQ,MAAM,CAAE,QAAO,MAAM,KAAK,IAAI;;;;;AAYlD,SAAS,iBAAiB,UAA0C;CAClE,MAAM,OAAkB,EAAE;AAE1B,MAAK,MAAM,SAAS,UAAU;AAC5B,MAAI,MAAM,SAAS,UAAW;AAG9B,MAAI,MAAM,QAAQ,aAAa,KAAK,OAAO;GACzC,MAAM,QAAQ,aAAa,OAAO,QAAQ,IAAI,OAAO,KAAK,SAAS;AACnE,QAAK,KAAK;IACR;IACA,SAAS,MAAM,SAAS,QACrB,MAAoB,EAAE,SAAS,aAAa,EAAE,SAAS,OACzD;IACF,CAAC;;;AAIN,QAAO;;;;;AAMT,SAAS,kBAAkB,MAAiB,SAA0B;CACpE,MAAM,WAAgC,EAAE;CAGxC,MAAM,iBAAsC,EAAE;AAE9C,MAAK,SAAS,KAAK,UAAU;EAC3B,MAAM,UAAU,UAAU,QAAQ,GAAG;AAGrC,iBAAe,KAAK;G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SAAS,aAAa;AACpB,SAAQ,SAAe;EACrB,MAAM,SAAS,SAAyB;AACtC,OAAI,cAAc,KAChB,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,SAAS,QAAQ,KAAK;IAC7C,MAAM,QAAQ,KAAK,SAAS;AAE5B,QAAI,MAAM,SAAS,UAEjB,KAAI,MAAM,QAAQ,aAAa,KAAK,QAAQ;KAC1C,MAAM,OAAO,iBAAiB,MAAM,SAAS;AAE7C,SAAI,KAAK,SAAS,GAAG;MAOnB,MAAM,UAAmB;OACvB,MAAM;OACN,SAAS;OACT,YAAY,EAAE,WAAW,CAAC,oBAAoB,EAAE;OAChD,UAAU,CATQ,kBAAkB,MADtB,OAAO,kBAAkB,CACW,EAC5B,sBAAsB,KAAK,CAQT;OACzC;AAED,WAAK,SAAS,KAAK;;UAGrB,OAAM,MAAM;;;AAOtB,QAAM,KAAK;;;;;;AAOf,eAAsB,cAAc,MAA+B;CACjE,MAAM,SAAS,MAAM,SAAS,CAC3B,IAAI,aAAa,EAAE,UAAU,MAAM,CAAC,CACpC,IAAI,WAAW,CACf,IAAI,gBAAgB,CACpB,QAAQ,KAAK;AAEhB,QAAO,OAAO,OAAO;;;;;;AAOvB,SAAgB,gBAAgB,YAA4B;AAC1D,KAAI,eAAe,EAAG,QAAO;CAE7B,IAAI,MAAM;AAEV,MAAK,IAAI,IAAI,GAAG,IAAI,YAAY,IAC9B,MAAK,IAAI,IAAI,GAAG,IAAI,GAAG,IACrB,QAAO,wBAAwB,EAAE,iBAAiB,EAAE,GAAG,EAAE,oCAAoC,EAAE;AAInG,QAAO"}
package/dist/youtube.js DELETED
@@ -1,3 +0,0 @@
1
- import { n as transformYouTube, t as extractVideoId } from "./youtube2.js";
2
-
3
- export { transformYouTube };
package/dist/youtube2.cjs DELETED
@@ -1,127 +0,0 @@
1
- const require_chunk = require('./chunk.cjs');
2
- let unified = require("unified");
3
- let rehype_parse = require("rehype-parse");
4
- rehype_parse = require_chunk.__toESM(rehype_parse);
5
- let rehype_stringify = require("rehype-stringify");
6
- rehype_stringify = require_chunk.__toESM(rehype_stringify);
7
-
8
- //#region src/plugins/youtube.ts
9
- /**
10
- * YouTube Plugin - Privacy-enhanced iframe embedding
11
- *
12
- * Transforms <YouTube> components into responsive iframe embeds
13
- * using youtube-nocookie.com for enhanced privacy.
14
- */
15
- const defaultOptions = {
16
- privacyEnhanced: true,
17
- aspectRatio: "16/9",
18
- allowFullscreen: true,
19
- lazyLoad: true
20
- };
21
- /**
22
- * Get element attribute value.
23
- */
24
- function getAttribute(el, name) {
25
- const value = el.properties?.[name];
26
- if (typeof value === "string") return value;
27
- if (Array.isArray(value)) return value.join(" ");
28
- }
29
- /**
30
- * Extract YouTube video ID from various URL formats.
31
- */
32
- function extractVideoId(input) {
33
- if (/^[a-zA-Z0-9_-]{11}$/.test(input)) return input;
34
- for (const pattern of [/(?:youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/|youtube\.com\/v\/)([a-zA-Z0-9_-]{11})/, /youtube\.com\/shorts\/([a-zA-Z0-9_-]{11})/]) {
35
- const match = input.match(pattern);
36
- if (match) return match[1];
37
- }
38
- return null;
39
- }
40
- /**
41
- * Build YouTube embed URL with parameters.
42
- */
43
- function buildEmbedUrl(videoId, options, params) {
44
- const domain = options.privacyEnhanced ? "www.youtube-nocookie.com" : "www.youtube.com";
45
- const url = new URL(`https://${domain}/embed/${videoId}`);
46
- if (params) for (const [key, value] of Object.entries(params)) url.searchParams.set(key, value);
47
- return url.toString();
48
- }
49
- /**
50
- * Create YouTube embed element.
51
- */
52
- function createYouTubeElement(videoId, options, title, start) {
53
- const params = {};
54
- if (start) params.start = start;
55
- const iframe = {
56
- type: "element",
57
- tagName: "iframe",
58
- properties: {
59
- src: buildEmbedUrl(videoId, options, params),
60
- title: title || `YouTube video ${videoId}`,
61
- allow: "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share",
62
- referrerpolicy: "strict-origin-when-cross-origin",
63
- allowfullscreen: options.allowFullscreen || void 0,
64
- loading: options.lazyLoad ? "lazy" : void 0
65
- },
66
- children: []
67
- };
68
- return {
69
- type: "element",
70
- tagName: "div",
71
- properties: {
72
- className: ["ox-youtube"],
73
- style: `aspect-ratio: ${options.aspectRatio};`
74
- },
75
- children: [iframe]
76
- };
77
- }
78
- /**
79
- * Rehype plugin to transform YouTube components.
80
- */
81
- function rehypeYouTube(options) {
82
- return (tree) => {
83
- const visit = (node) => {
84
- if ("children" in node) for (let i = 0; i < node.children.length; i++) {
85
- const child = node.children[i];
86
- if (child.type === "element") if (child.tagName.toLowerCase() === "youtube") {
87
- const id = getAttribute(child, "id");
88
- const url = getAttribute(child, "url");
89
- const title = getAttribute(child, "title");
90
- const start = getAttribute(child, "start");
91
- const videoId = id ? extractVideoId(id) : url ? extractVideoId(url) : null;
92
- if (videoId) {
93
- const youtubeElement = createYouTubeElement(videoId, options, title, start);
94
- node.children[i] = youtubeElement;
95
- }
96
- } else visit(child);
97
- }
98
- };
99
- visit(tree);
100
- };
101
- }
102
- /**
103
- * Transform YouTube components in HTML.
104
- */
105
- async function transformYouTube(html, options) {
106
- const mergedOptions = {
107
- ...defaultOptions,
108
- ...options
109
- };
110
- const result = await (0, unified.unified)().use(rehype_parse.default, { fragment: true }).use(rehypeYouTube, mergedOptions).use(rehype_stringify.default).process(html);
111
- return String(result);
112
- }
113
-
114
- //#endregion
115
- Object.defineProperty(exports, 'extractVideoId', {
116
- enumerable: true,
117
- get: function () {
118
- return extractVideoId;
119
- }
120
- });
121
- Object.defineProperty(exports, 'transformYouTube', {
122
- enumerable: true,
123
- get: function () {
124
- return transformYouTube;
125
- }
126
- });
127
- //# sourceMappingURL=youtube2.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"youtube2.cjs","names":["rehypeParse","rehypeStringify"],"sources":["../src/plugins/youtube.ts"],"sourcesContent":["/**\n * YouTube Plugin - Privacy-enhanced iframe embedding\n *\n * Transforms <YouTube> components into responsive iframe embeds\n * using youtube-nocookie.com for enhanced privacy.\n */\n\nimport { unified } from \"unified\";\nimport rehypeParse from \"rehype-parse\";\nimport rehypeStringify from \"rehype-stringify\";\nimport type { Root, Element, Properties } from \"hast\";\n\nexport interface YouTubeOptions {\n /** Use privacy-enhanced mode (youtube-nocookie.com). Default: true */\n privacyEnhanced?: boolean;\n /** Default aspect ratio. Default: \"16/9\" */\n aspectRatio?: string;\n /** Allow fullscreen. Default: true */\n allowFullscreen?: boolean;\n /** Lazy load iframe. Default: true */\n lazyLoad?: boolean;\n}\n\nconst defaultOptions: Required<YouTubeOptions> = {\n privacyEnhanced: true,\n aspectRatio: \"16/9\",\n allowFullscreen: true,\n lazyLoad: true,\n};\n\n/**\n * Get element attribute value.\n */\nfunction getAttribute(el: Element, name: string): string | undefined {\n const value = el.properties?.[name];\n if (typeof value === \"string\") return value;\n if (Array.isArray(value)) return value.join(\" \");\n return undefined;\n}\n\n/**\n * Extract YouTube video ID from various URL formats.\n */\nexport function extractVideoId(input: string): string | null {\n // Already a video ID (11 characters, alphanumeric + _ -)\n if (/^[a-zA-Z0-9_-]{11}$/.test(input)) {\n return input;\n }\n\n // Full URL patterns\n const patterns = [\n /(?:youtube\\.com\\/watch\\?v=|youtu\\.be\\/|youtube\\.com\\/embed\\/|youtube\\.com\\/v\\/)([a-zA-Z0-9_-]{11})/,\n /youtube\\.com\\/shorts\\/([a-zA-Z0-9_-]{11})/,\n ];\n\n for (const pattern of patterns) {\n const match = input.match(pattern);\n if (match) return match[1];\n }\n\n return null;\n}\n\n/**\n * Build YouTube embed URL with parameters.\n */\nfunction buildEmbedUrl(\n videoId: string,\n options: Required<YouTubeOptions>,\n params?: Record<string, string>,\n): string {\n const domain = options.privacyEnhanced ? \"www.youtube-nocookie.com\" : \"www.youtube.com\";\n const url = new URL(`https://${domain}/embed/${videoId}`);\n\n // Add any custom parameters\n if (params) {\n for (const [key, value] of Object.entries(params)) {\n url.searchParams.set(key, value);\n }\n }\n\n return url.toString();\n}\n\n/**\n * Create YouTube embed element.\n */\nfunction createYouTubeElement(\n videoId: string,\n options: Required<YouTubeOptions>,\n title?: string,\n start?: string,\n): Element {\n const params: Record<string, string> = {};\n if (start) {\n params.start = start;\n }\n\n const embedUrl = buildEmbedUrl(videoId, options, params);\n\n const iframeProps: Properties = {\n src: embedUrl,\n title: title || `YouTube video ${videoId}`,\n allow:\n \"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\",\n referrerpolicy: \"strict-origin-when-cross-origin\",\n allowfullscreen: options.allowFullscreen || undefined,\n loading: options.lazyLoad ? \"lazy\" : undefined,\n };\n\n const iframe: Element = {\n type: \"element\",\n tagName: \"iframe\",\n properties: iframeProps,\n children: [],\n };\n\n return {\n type: \"element\",\n tagName: \"div\",\n properties: {\n className: [\"ox-youtube\"],\n style: `aspect-ratio: ${options.aspectRatio};`,\n },\n children: [iframe],\n };\n}\n\n/**\n * Rehype plugin to transform YouTube components.\n */\nfunction rehypeYouTube(options: Required<YouTubeOptions>) {\n return (tree: Root) => {\n const visit = (node: Root | Element) => {\n if (\"children\" in node) {\n for (let i = 0; i < node.children.length; i++) {\n const child = node.children[i];\n\n if (child.type === \"element\") {\n // Check for <YouTube> component\n if (child.tagName.toLowerCase() === \"youtube\") {\n const id = getAttribute(child, \"id\");\n const url = getAttribute(child, \"url\");\n const title = getAttribute(child, \"title\");\n const start = getAttribute(child, \"start\");\n\n // Extract video ID from id or url attribute\n const videoId = id ? extractVideoId(id) : url ? extractVideoId(url) : null;\n\n if (videoId) {\n const youtubeElement = createYouTubeElement(videoId, options, title, start);\n node.children[i] = youtubeElement;\n }\n } else {\n visit(child);\n }\n }\n }\n }\n };\n\n visit(tree);\n };\n}\n\n/**\n * Transform YouTube components in HTML.\n */\nexport async function transformYouTube(html: string, options?: YouTubeOptions): Promise<string> {\n const mergedOptions = { ...defaultOptions, ...options };\n\n const result = await unified()\n .use(rehypeParse, { fragment: true })\n .use(rehypeYouTube, mergedOptions)\n .use(rehypeStringify)\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;;;AAMH,SAAS,cAAc,SAAmC;AACxD,SAAQ,SAAe;EACrB,MAAM,SAAS,SAAyB;AACtC,OAAI,cAAc,KAChB,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,SAAS,QAAQ,KAAK;IAC7C,MAAM,QAAQ,KAAK,SAAS;AAE5B,QAAI,MAAM,SAAS,UAEjB,KAAI,MAAM,QAAQ,aAAa,KAAK,WAAW;KAC7C,MAAM,KAAK,aAAa,OAAO,KAAK;KACpC,MAAM,MAAM,aAAa,OAAO,MAAM;KACtC,MAAM,QAAQ,aAAa,OAAO,QAAQ;KAC1C,MAAM,QAAQ,aAAa,OAAO,QAAQ;KAG1C,MAAM,UAAU,KAAK,eAAe,GAAG,GAAG,MAAM,eAAe,IAAI,GAAG;AAEtE,SAAI,SAAS;MACX,MAAM,iBAAiB,qBAAqB,SAAS,SAAS,OAAO,MAAM;AAC3E,WAAK,SAAS,KAAK;;UAGrB,OAAM,MAAM;;;AAOtB,QAAM,KAAK;;;;;;AAOf,eAAsB,iBAAiB,MAAc,SAA2C;CAC9F,MAAM,gBAAgB;EAAE,GAAG;EAAgB,GAAG;EAAS;CAEvD,MAAM,SAAS,4BAAe,CAC3B,IAAIA,sBAAa,EAAE,UAAU,MAAM,CAAC,CACpC,IAAI,eAAe,cAAc,CACjC,IAAIC,yBAAgB,CACpB,QAAQ,KAAK;AAEhB,QAAO,OAAO,OAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"youtube2.js","names":[],"sources":["../src/plugins/youtube.ts"],"sourcesContent":["/**\n * YouTube Plugin - Privacy-enhanced iframe embedding\n *\n * Transforms <YouTube> components into responsive iframe embeds\n * using youtube-nocookie.com for enhanced privacy.\n */\n\nimport { unified } from \"unified\";\nimport rehypeParse from \"rehype-parse\";\nimport rehypeStringify from \"rehype-stringify\";\nimport type { Root, Element, Properties } from \"hast\";\n\nexport interface YouTubeOptions {\n /** Use privacy-enhanced mode (youtube-nocookie.com). Default: true */\n privacyEnhanced?: boolean;\n /** Default aspect ratio. Default: \"16/9\" */\n aspectRatio?: string;\n /** Allow fullscreen. Default: true */\n allowFullscreen?: boolean;\n /** Lazy load iframe. Default: true */\n lazyLoad?: boolean;\n}\n\nconst defaultOptions: Required<YouTubeOptions> = {\n privacyEnhanced: true,\n aspectRatio: \"16/9\",\n allowFullscreen: true,\n lazyLoad: true,\n};\n\n/**\n * Get element attribute value.\n */\nfunction getAttribute(el: Element, name: string): string | undefined {\n const value = el.properties?.[name];\n if (typeof value === \"string\") return value;\n if (Array.isArray(value)) return value.join(\" \");\n return undefined;\n}\n\n/**\n * Extract YouTube video ID from various URL formats.\n */\nexport function extractVideoId(input: string): string | null {\n // Already a video ID (11 characters, alphanumeric + _ -)\n if (/^[a-zA-Z0-9_-]{11}$/.test(input)) {\n return input;\n }\n\n // Full URL patterns\n const patterns = [\n /(?:youtube\\.com\\/watch\\?v=|youtu\\.be\\/|youtube\\.com\\/embed\\/|youtube\\.com\\/v\\/)([a-zA-Z0-9_-]{11})/,\n /youtube\\.com\\/shorts\\/([a-zA-Z0-9_-]{11})/,\n ];\n\n for (const pattern of patterns) {\n const match = input.match(pattern);\n if (match) return match[1];\n }\n\n return null;\n}\n\n/**\n * Build YouTube embed URL with parameters.\n */\nfunction buildEmbedUrl(\n videoId: string,\n options: Required<YouTubeOptions>,\n params?: Record<string, string>,\n): string {\n const domain = options.privacyEnhanced ? \"www.youtube-nocookie.com\" : \"www.youtube.com\";\n const url = new URL(`https://${domain}/embed/${videoId}`);\n\n // Add any custom parameters\n if (params) {\n for (const [key, value] of Object.entries(params)) {\n url.searchParams.set(key, value);\n }\n }\n\n return url.toString();\n}\n\n/**\n * Create YouTube embed element.\n */\nfunction createYouTubeElement(\n videoId: string,\n options: Required<YouTubeOptions>,\n title?: string,\n start?: string,\n): Element {\n const params: Record<string, string> = {};\n if (start) {\n params.start = start;\n }\n\n const embedUrl = buildEmbedUrl(videoId, options, params);\n\n const iframeProps: Properties = {\n src: embedUrl,\n title: title || `YouTube video ${videoId}`,\n allow:\n \"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\",\n referrerpolicy: \"strict-origin-when-cross-origin\",\n allowfullscreen: options.allowFullscreen || undefined,\n loading: options.lazyLoad ? \"lazy\" : undefined,\n };\n\n const iframe: Element = {\n type: \"element\",\n tagName: \"iframe\",\n properties: iframeProps,\n children: [],\n };\n\n return {\n type: \"element\",\n tagName: \"div\",\n properties: {\n className: [\"ox-youtube\"],\n style: `aspect-ratio: ${options.aspectRatio};`,\n },\n children: [iframe],\n };\n}\n\n/**\n * Rehype plugin to transform YouTube components.\n */\nfunction rehypeYouTube(options: Required<YouTubeOptions>) {\n return (tree: Root) => {\n const visit = (node: Root | Element) => {\n if (\"children\" in node) {\n for (let i = 0; i < node.children.length; i++) {\n const child = node.children[i];\n\n if (child.type === \"element\") {\n // Check for <YouTube> component\n if (child.tagName.toLowerCase() === \"youtube\") {\n const id = getAttribute(child, \"id\");\n const url = getAttribute(child, \"url\");\n const title = getAttribute(child, \"title\");\n const start = getAttribute(child, \"start\");\n\n // Extract video ID from id or url attribute\n const videoId = id ? extractVideoId(id) : url ? extractVideoId(url) : null;\n\n if (videoId) {\n const youtubeElement = createYouTubeElement(videoId, options, title, start);\n node.children[i] = youtubeElement;\n }\n } else {\n visit(child);\n }\n }\n }\n }\n };\n\n visit(tree);\n };\n}\n\n/**\n * Transform YouTube components in HTML.\n */\nexport async function transformYouTube(html: string, options?: YouTubeOptions): Promise<string> {\n const mergedOptions = { ...defaultOptions, ...options };\n\n const result = await unified()\n .use(rehypeParse, { fragment: true })\n .use(rehypeYouTube, mergedOptions)\n .use(rehypeStringify)\n .process(html);\n\n return String(result);\n}\n"],"mappings":";;;;;;;;;;;AAuBA,MAAM,iBAA2C;CAC/C,iBAAiB;CACjB,aAAa;CACb,iBAAiB;CACjB,UAAU;CACX;;;;AAKD,SAAS,aAAa,IAAa,MAAkC;CACnE,MAAM,QAAQ,GAAG,aAAa;AAC9B,KAAI,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