@ox-content/vite-plugin 3.0.0-alpha.11 → 3.0.0-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +102 -69
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +56 -23
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +56 -23
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +100 -67
- package/dist/index.mjs.map +1 -1
- package/dist/markdown-tables.cjs +70 -0
- package/dist/markdown-tables.cjs.map +1 -0
- package/dist/markdown-tables.d.cts +25 -0
- package/dist/markdown-tables.d.cts.map +1 -0
- package/dist/markdown-tables.d.mts +25 -0
- package/dist/markdown-tables.d.mts.map +1 -0
- package/dist/markdown-tables.mjs +66 -0
- package/dist/markdown-tables.mjs.map +1 -0
- package/dist/styles/all.css +1 -0
- package/dist/styles/markdown-tables.css +14 -0
- package/package.json +14 -3
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.markdownTableScrollLabel = markdownTableScrollLabel;
|
|
4
|
+
exports.enhanceMarkdownTables = enhanceMarkdownTables;
|
|
5
|
+
const TABINDEX_FLAG = "oxTableScrollTabindex";
|
|
6
|
+
const LABEL_FLAG = "oxTableScrollLabel";
|
|
7
|
+
const SCROLLABLE_ATTR = "data-ox-table-scrollable";
|
|
8
|
+
function markdownTableScrollLabel(locale) {
|
|
9
|
+
const language = locale?.split("-")[0]?.toLowerCase();
|
|
10
|
+
if (language === "ja") {
|
|
11
|
+
return "横スクロールできる表";
|
|
12
|
+
}
|
|
13
|
+
return "Scrollable table";
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Makes overflowing Markdown tables keyboard-scrollable without wrapping or
|
|
17
|
+
* replacing the native `<table>` element.
|
|
18
|
+
*
|
|
19
|
+
* Run this after rendering Markdown and again after layout-changing updates.
|
|
20
|
+
* Narrow tables stay out of the tab order when overflow can be measured.
|
|
21
|
+
*/
|
|
22
|
+
function enhanceMarkdownTables(root, options = {}) {
|
|
23
|
+
const target = root ?? globalThis.document;
|
|
24
|
+
if (!target?.querySelectorAll) {
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
const selector = options.selector ?? ".content table";
|
|
28
|
+
const locale = ownerDocument(target)?.documentElement.lang;
|
|
29
|
+
const label = options.label ?? markdownTableScrollLabel(locale);
|
|
30
|
+
let scrollableCount = 0;
|
|
31
|
+
for (const table of target.querySelectorAll(selector)) {
|
|
32
|
+
if (typeof HTMLElement === "undefined" || !(table instanceof HTMLElement)) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (table.tagName !== "TABLE") {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const scrollable = table.scrollWidth > table.clientWidth + 1;
|
|
39
|
+
table.toggleAttribute(SCROLLABLE_ATTR, scrollable);
|
|
40
|
+
if (scrollable) {
|
|
41
|
+
scrollableCount++;
|
|
42
|
+
if (!table.hasAttribute("tabindex")) {
|
|
43
|
+
table.tabIndex = 0;
|
|
44
|
+
table.dataset[TABINDEX_FLAG] = "true";
|
|
45
|
+
}
|
|
46
|
+
if (!table.hasAttribute("aria-label") && !table.hasAttribute("aria-labelledby")) {
|
|
47
|
+
table.setAttribute("aria-label", label);
|
|
48
|
+
table.dataset[LABEL_FLAG] = "true";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
if (table.dataset[TABINDEX_FLAG] === "true") {
|
|
53
|
+
table.removeAttribute("tabindex");
|
|
54
|
+
delete table.dataset[TABINDEX_FLAG];
|
|
55
|
+
}
|
|
56
|
+
if (table.dataset[LABEL_FLAG] === "true") {
|
|
57
|
+
table.removeAttribute("aria-label");
|
|
58
|
+
delete table.dataset[LABEL_FLAG];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return scrollableCount;
|
|
63
|
+
}
|
|
64
|
+
function ownerDocument(root) {
|
|
65
|
+
if (typeof Document !== "undefined" && root instanceof Document) {
|
|
66
|
+
return root;
|
|
67
|
+
}
|
|
68
|
+
return root.ownerDocument ?? globalThis.document;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=markdown-tables.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-tables.cjs","sourceRoot":"","sources":["../../../home/runner/work/ox-content/ox-content/npm/vite-plugin-ox-content/src/markdown-tables.ts"],"names":[],"mappings":";;;;AAaA,MAAM,aAAa,GAAG,uBAAuB,CAAC;AAC9C,MAAM,UAAU,GAAG,oBAAoB,CAAC;AACxC,MAAM,eAAe,GAAG,0BAA0B,CAAC;AAEnD,kCAAyC,MAAe;IACtD,MAAM,QAAQ,GAAG,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC;IACtD,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACtB,OAAO,YAAY,CAAC;IACtB,CAAC;IACD,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAED;;;;;;GAMG;AACH,+BACE,IAAiB,EACjB,OAAO,GAAoC,EAAE;IAE7C,MAAM,MAAM,GAAG,IAAI,IAAI,UAAU,CAAC,QAAQ,CAAC;IAC3C,IAAI,CAAC,MAAM,EAAE,gBAAgB,EAAE,CAAC;QAC9B,OAAO,CAAC,CAAC;IACX,CAAC;IAED,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,gBAAgB,CAAC;IACtD,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,EAAE,eAAe,CAAC,IAAI,CAAC;IAC3D,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,wBAAwB,CAAC,MAAM,CAAC,CAAC;IAChE,IAAI,eAAe,GAAG,CAAC,CAAC;IAExB,KAAK,MAAM,KAAK,IAAI,MAA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O,CAAC,UAAU,CAAC,CAAC;YACnC,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC;AAED,SAAS,aAAa,CAAC,IAAgB;IACrC,IAAI,OAAO,QAAQ,KAAK,WAAW,IAAI,IAAI,YAAY,QAAQ,EAAE,CAAC;QAChE,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,IAAI,CAAC,aAAa,IAAI,UAAU,CAAC,QAAQ,CAAC;AACnD,CAAC","sourcesContent":["export interface MarkdownTableEnhancementOptions {\n /**\n * Tables to enhance. Defaults to Markdown content tables styled by\n * `@ox-content/vite-plugin/styles/core.css`.\n */\n selector?: string;\n /**\n * Accessible name applied only when an overflowing table has no existing\n * `aria-label` or `aria-labelledby`.\n */\n label?: string;\n}\n\nconst TABINDEX_FLAG = \"oxTableScrollTabindex\";\nconst LABEL_FLAG = \"oxTableScrollLabel\";\nconst SCROLLABLE_ATTR = \"data-ox-table-scrollable\";\n\nexport function markdownTableScrollLabel(locale?: string): string {\n const language = locale?.split(\"-\")[0]?.toLowerCase();\n if (language === \"ja\") {\n return \"横スクロールできる表\";\n }\n return \"Scrollable table\";\n}\n\n/**\n * Makes overflowing Markdown tables keyboard-scrollable without wrapping or\n * replacing the native `<table>` element.\n *\n * Run this after rendering Markdown and again after layout-changing updates.\n * Narrow tables stay out of the tab order when overflow can be measured.\n */\nexport function enhanceMarkdownTables(\n root?: ParentNode,\n options: MarkdownTableEnhancementOptions = {},\n): number {\n const target = root ?? globalThis.document;\n if (!target?.querySelectorAll) {\n return 0;\n }\n\n const selector = options.selector ?? \".content table\";\n const locale = ownerDocument(target)?.documentElement.lang;\n const label = options.label ?? markdownTableScrollLabel(locale);\n let scrollableCount = 0;\n\n for (const table of target.querySelectorAll(selector)) {\n if (typeof HTMLElement === \"undefined\" || !(table instanceof HTMLElement)) {\n continue;\n }\n if (table.tagName !== \"TABLE\") {\n continue;\n }\n\n const scrollable = table.scrollWidth > table.clientWidth + 1;\n table.toggleAttribute(SCROLLABLE_ATTR, scrollable);\n if (scrollable) {\n scrollableCount++;\n if (!table.hasAttribute(\"tabindex\")) {\n table.tabIndex = 0;\n table.dataset[TABINDEX_FLAG] = \"true\";\n }\n if (!table.hasAttribute(\"aria-label\") && !table.hasAttribute(\"aria-labelledby\")) {\n table.setAttribute(\"aria-label\", label);\n table.dataset[LABEL_FLAG] = \"true\";\n }\n } else {\n if (table.dataset[TABINDEX_FLAG] === \"true\") {\n table.removeAttribute(\"tabindex\");\n delete table.dataset[TABINDEX_FLAG];\n }\n if (table.dataset[LABEL_FLAG] === \"true\") {\n table.removeAttribute(\"aria-label\");\n delete table.dataset[LABEL_FLAG];\n }\n }\n }\n\n return scrollableCount;\n}\n\nfunction ownerDocument(root: ParentNode): Document | undefined {\n if (typeof Document !== \"undefined\" && root instanceof Document) {\n return root;\n }\n return root.ownerDocument ?? globalThis.document;\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/markdown-tables.d.ts
|
|
2
|
+
interface MarkdownTableEnhancementOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Tables to enhance. Defaults to Markdown content tables styled by
|
|
5
|
+
* `@ox-content/vite-plugin/styles/core.css`.
|
|
6
|
+
*/
|
|
7
|
+
selector?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Accessible name applied only when an overflowing table has no existing
|
|
10
|
+
* `aria-label` or `aria-labelledby`.
|
|
11
|
+
*/
|
|
12
|
+
label?: string;
|
|
13
|
+
}
|
|
14
|
+
declare function markdownTableScrollLabel(locale?: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Makes overflowing Markdown tables keyboard-scrollable without wrapping or
|
|
17
|
+
* replacing the native `<table>` element.
|
|
18
|
+
*
|
|
19
|
+
* Run this after rendering Markdown and again after layout-changing updates.
|
|
20
|
+
* Narrow tables stay out of the tab order when overflow can be measured.
|
|
21
|
+
*/
|
|
22
|
+
declare function enhanceMarkdownTables(root?: ParentNode, options?: MarkdownTableEnhancementOptions): number;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { MarkdownTableEnhancementOptions, enhanceMarkdownTables, markdownTableScrollLabel };
|
|
25
|
+
//# sourceMappingURL=markdown-tables.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-tables.d.cts","names":[],"sources":["../src/markdown-tables.ts"],"mappings":";UAAiB;;;;;EAKf;;;;;EAKA;;iBAOc,yBAAyB;;;;;;;;iBAezB,sBACd,OAAO,YACP,UAAS"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/markdown-tables.d.ts
|
|
2
|
+
interface MarkdownTableEnhancementOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Tables to enhance. Defaults to Markdown content tables styled by
|
|
5
|
+
* `@ox-content/vite-plugin/styles/core.css`.
|
|
6
|
+
*/
|
|
7
|
+
selector?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Accessible name applied only when an overflowing table has no existing
|
|
10
|
+
* `aria-label` or `aria-labelledby`.
|
|
11
|
+
*/
|
|
12
|
+
label?: string;
|
|
13
|
+
}
|
|
14
|
+
declare function markdownTableScrollLabel(locale?: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Makes overflowing Markdown tables keyboard-scrollable without wrapping or
|
|
17
|
+
* replacing the native `<table>` element.
|
|
18
|
+
*
|
|
19
|
+
* Run this after rendering Markdown and again after layout-changing updates.
|
|
20
|
+
* Narrow tables stay out of the tab order when overflow can be measured.
|
|
21
|
+
*/
|
|
22
|
+
declare function enhanceMarkdownTables(root?: ParentNode, options?: MarkdownTableEnhancementOptions): number;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { MarkdownTableEnhancementOptions, enhanceMarkdownTables, markdownTableScrollLabel };
|
|
25
|
+
//# sourceMappingURL=markdown-tables.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-tables.d.mts","names":[],"sources":["../src/markdown-tables.ts"],"mappings":";UAAiB;;;;;EAKf;;;;;EAKA;;iBAOc,yBAAyB;;;;;;;;iBAezB,sBACd,OAAO,YACP,UAAS"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const TABINDEX_FLAG = "oxTableScrollTabindex";
|
|
2
|
+
const LABEL_FLAG = "oxTableScrollLabel";
|
|
3
|
+
const SCROLLABLE_ATTR = "data-ox-table-scrollable";
|
|
4
|
+
export function markdownTableScrollLabel(locale) {
|
|
5
|
+
const language = locale?.split("-")[0]?.toLowerCase();
|
|
6
|
+
if (language === "ja") {
|
|
7
|
+
return "横スクロールできる表";
|
|
8
|
+
}
|
|
9
|
+
return "Scrollable table";
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Makes overflowing Markdown tables keyboard-scrollable without wrapping or
|
|
13
|
+
* replacing the native `<table>` element.
|
|
14
|
+
*
|
|
15
|
+
* Run this after rendering Markdown and again after layout-changing updates.
|
|
16
|
+
* Narrow tables stay out of the tab order when overflow can be measured.
|
|
17
|
+
*/
|
|
18
|
+
export function enhanceMarkdownTables(root, options = {}) {
|
|
19
|
+
const target = root ?? globalThis.document;
|
|
20
|
+
if (!target?.querySelectorAll) {
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
const selector = options.selector ?? ".content table";
|
|
24
|
+
const locale = ownerDocument(target)?.documentElement.lang;
|
|
25
|
+
const label = options.label ?? markdownTableScrollLabel(locale);
|
|
26
|
+
let scrollableCount = 0;
|
|
27
|
+
for (const table of target.querySelectorAll(selector)) {
|
|
28
|
+
if (typeof HTMLElement === "undefined" || !(table instanceof HTMLElement)) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (table.tagName !== "TABLE") {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const scrollable = table.scrollWidth > table.clientWidth + 1;
|
|
35
|
+
table.toggleAttribute(SCROLLABLE_ATTR, scrollable);
|
|
36
|
+
if (scrollable) {
|
|
37
|
+
scrollableCount++;
|
|
38
|
+
if (!table.hasAttribute("tabindex")) {
|
|
39
|
+
table.tabIndex = 0;
|
|
40
|
+
table.dataset[TABINDEX_FLAG] = "true";
|
|
41
|
+
}
|
|
42
|
+
if (!table.hasAttribute("aria-label") && !table.hasAttribute("aria-labelledby")) {
|
|
43
|
+
table.setAttribute("aria-label", label);
|
|
44
|
+
table.dataset[LABEL_FLAG] = "true";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
if (table.dataset[TABINDEX_FLAG] === "true") {
|
|
49
|
+
table.removeAttribute("tabindex");
|
|
50
|
+
delete table.dataset[TABINDEX_FLAG];
|
|
51
|
+
}
|
|
52
|
+
if (table.dataset[LABEL_FLAG] === "true") {
|
|
53
|
+
table.removeAttribute("aria-label");
|
|
54
|
+
delete table.dataset[LABEL_FLAG];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return scrollableCount;
|
|
59
|
+
}
|
|
60
|
+
function ownerDocument(root) {
|
|
61
|
+
if (typeof Document !== "undefined" && root instanceof Document) {
|
|
62
|
+
return root;
|
|
63
|
+
}
|
|
64
|
+
return root.ownerDocument ?? globalThis.document;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=markdown-tables.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-tables.mjs","sourceRoot":"","sources":["../../../home/runner/work/ox-content/ox-content/npm/vite-plugin-ox-content/src/markdown-tables.ts"],"names":[],"mappings":"AAaA,MAAM,aAAa,GAAG,uBAAuB,CAAC;AAC9C,MAAM,UAAU,GAAG,oBAAoB,CAAC;AACxC,MAAM,eAAe,GAAG,0BAA0B,CAAC;AAEnD,MAAM,UAAU,wBAAwB,CAAC,MAAe;IACtD,MAAM,QAAQ,GAAG,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC;IACtD,IAAI,QAAQ,KAAK,IAAI,EAAE,CA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I,CAAC,KAAK,CAAC,YAAY,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,iBAAiB,CAAC,EAAE,CAAC;gBAChF,KAAK,CAAC,YAAY,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;gBACxC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC;YACrC,CAAC;QACH,CAAC;aAAM,CAAC;YACN,IAAI,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,MAAM,EAAE,CAAC;gBAC5C,KAAK,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;gBAClC,OAAO,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;YACtC,CAAC;YACD,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,MAAM,EAAE,CAAC;gBACzC,KAAK,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;gBACpC,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YACnC,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC;AAED,SAAS,aAAa,CAAC,IAAgB;IACrC,IAAI,OAAO,QAAQ,KAAK,WAAW,IAAI,IAAI,YAAY,QAAQ,EAAE,CAAC;QAChE,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,IAAI,CAAC,aAAa,IAAI,UAAU,CAAC,QAAQ,CAAC;AACnD,CAAC","sourcesContent":["export interface MarkdownTableEnhancementOptions {\n /**\n * Tables to enhance. Defaults to Markdown content tables styled by\n * `@ox-content/vite-plugin/styles/core.css`.\n */\n selector?: string;\n /**\n * Accessible name applied only when an overflowing table has no existing\n * `aria-label` or `aria-labelledby`.\n */\n label?: string;\n}\n\nconst TABINDEX_FLAG = \"oxTableScrollTabindex\";\nconst LABEL_FLAG = \"oxTableScrollLabel\";\nconst SCROLLABLE_ATTR = \"data-ox-table-scrollable\";\n\nexport function markdownTableScrollLabel(locale?: string): string {\n const language = locale?.split(\"-\")[0]?.toLowerCase();\n if (language === \"ja\") {\n return \"横スクロールできる表\";\n }\n return \"Scrollable table\";\n}\n\n/**\n * Makes overflowing Markdown tables keyboard-scrollable without wrapping or\n * replacing the native `<table>` element.\n *\n * Run this after rendering Markdown and again after layout-changing updates.\n * Narrow tables stay out of the tab order when overflow can be measured.\n */\nexport function enhanceMarkdownTables(\n root?: ParentNode,\n options: MarkdownTableEnhancementOptions = {},\n): number {\n const target = root ?? globalThis.document;\n if (!target?.querySelectorAll) {\n return 0;\n }\n\n const selector = options.selector ?? \".content table\";\n const locale = ownerDocument(target)?.documentElement.lang;\n const label = options.label ?? markdownTableScrollLabel(locale);\n let scrollableCount = 0;\n\n for (const table of target.querySelectorAll(selector)) {\n if (typeof HTMLElement === \"undefined\" || !(table instanceof HTMLElement)) {\n continue;\n }\n if (table.tagName !== \"TABLE\") {\n continue;\n }\n\n const scrollable = table.scrollWidth > table.clientWidth + 1;\n table.toggleAttribute(SCROLLABLE_ATTR, scrollable);\n if (scrollable) {\n scrollableCount++;\n if (!table.hasAttribute(\"tabindex\")) {\n table.tabIndex = 0;\n table.dataset[TABINDEX_FLAG] = \"true\";\n }\n if (!table.hasAttribute(\"aria-label\") && !table.hasAttribute(\"aria-labelledby\")) {\n table.setAttribute(\"aria-label\", label);\n table.dataset[LABEL_FLAG] = \"true\";\n }\n } else {\n if (table.dataset[TABINDEX_FLAG] === \"true\") {\n table.removeAttribute(\"tabindex\");\n delete table.dataset[TABINDEX_FLAG];\n }\n if (table.dataset[LABEL_FLAG] === \"true\") {\n table.removeAttribute(\"aria-label\");\n delete table.dataset[LABEL_FLAG];\n }\n }\n }\n\n return scrollableCount;\n}\n\nfunction ownerDocument(root: ParentNode): Document | undefined {\n if (typeof Document !== \"undefined\" && root instanceof Document) {\n return root;\n }\n return root.ownerDocument ?? globalThis.document;\n}\n"]}
|
package/dist/styles/all.css
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* Responsive Markdown tables for custom hosts */
|
|
2
|
+
.content table {
|
|
3
|
+
display: block;
|
|
4
|
+
width: max-content;
|
|
5
|
+
max-width: 100%;
|
|
6
|
+
box-sizing: border-box;
|
|
7
|
+
overflow-x: auto;
|
|
8
|
+
-webkit-overflow-scrolling: touch;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.content table[data-ox-table-scrollable="true"]:focus-visible {
|
|
12
|
+
outline: var(--octc-focus-ring, 2px solid Highlight);
|
|
13
|
+
outline-offset: var(--octc-focus-offset, 2px);
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ox-content/vite-plugin",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.13",
|
|
4
4
|
"description": "Vite plugin for Ox Content - High-performance Markdown processing with Environment API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"environment-api",
|
|
@@ -38,6 +38,16 @@
|
|
|
38
38
|
"require": "./dist/incremental-dom.cjs",
|
|
39
39
|
"types": "./dist/incremental-dom.d.mts"
|
|
40
40
|
},
|
|
41
|
+
"./markdown-tables": {
|
|
42
|
+
"import": {
|
|
43
|
+
"types": "./dist/markdown-tables.d.mts",
|
|
44
|
+
"default": "./dist/markdown-tables.mjs"
|
|
45
|
+
},
|
|
46
|
+
"require": {
|
|
47
|
+
"types": "./dist/markdown-tables.d.cts",
|
|
48
|
+
"default": "./dist/markdown-tables.cjs"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
41
51
|
"./vitepress-migrate": {
|
|
42
52
|
"import": "./dist/vitepress-cli.mjs",
|
|
43
53
|
"types": "./dist/vitepress-cli.d.mts"
|
|
@@ -59,6 +69,7 @@
|
|
|
59
69
|
"./styles/twitter-full.css": "./dist/styles/twitter-full.css",
|
|
60
70
|
"./styles/ogp.css": "./dist/styles/ogp.css",
|
|
61
71
|
"./styles/github.css": "./dist/styles/github.css",
|
|
72
|
+
"./styles/markdown-tables.css": "./dist/styles/markdown-tables.css",
|
|
62
73
|
"./styles/youtube.css": "./dist/styles/youtube.css",
|
|
63
74
|
"./styles/tabs.css": "./dist/styles/tabs.css",
|
|
64
75
|
"./styles/mermaid.css": "./dist/styles/mermaid.css",
|
|
@@ -88,7 +99,7 @@
|
|
|
88
99
|
"satori-html": "^0.3.2",
|
|
89
100
|
"typescript": "^7.0.2",
|
|
90
101
|
"unified": "^11.0.5",
|
|
91
|
-
"@ox-content/napi": "3.0.0-alpha.
|
|
102
|
+
"@ox-content/napi": "3.0.0-alpha.13"
|
|
92
103
|
},
|
|
93
104
|
"devDependencies": {
|
|
94
105
|
"@playwright/test": "^1.62.1",
|
|
@@ -137,7 +148,7 @@
|
|
|
137
148
|
}
|
|
138
149
|
},
|
|
139
150
|
"scripts": {
|
|
140
|
-
"build": "vp pack && node scripts/copy-component-styles.mjs",
|
|
151
|
+
"build": "vp pack && node scripts/build-standalone-markdown-tables.mjs && node scripts/copy-component-styles.mjs",
|
|
141
152
|
"build:styles": "node scripts/copy-component-styles.mjs",
|
|
142
153
|
"dev": "vp pack --watch",
|
|
143
154
|
"typecheck": "tsgo --noEmit",
|