markdown-to-html-cli 3.2.11 → 3.2.14

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdown-style.js","sourceRoot":"","sources":["../../src/nodes/markdown-style.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAs/BpB,CAAA;AAED,MAAM,UAAU,aAAa,CAAC,KAAuB;IACnD,OAAO,CAAC;YACN,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,QAAQ;YACjB,UAAU,EAAE;gBACV,IAAI,EAAE,QAAQ;gBACd,uDAAuD;aACxD;YACD,QAAQ,EAAE,CAAC;oBACT,IAAI,EAAE,MAAM;oBACZ,KAAK,EAAE,YAAY;iBACpB,CAAC;SACH,EAAE;YACD,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,KAAK;YACd,UAAU,EAAE;gBACV,KAAK,EAAE,6DAA6D;aACrE;YACD,QAAQ,EAAE,CAAC;oBACT,IAAI,EAAE,SAAS;oBACf,OAAO,EAAE,gBAAgB;oBACzB,QAAQ,EAAE,KAAK;iBAChB,CAAC;SACH,CAAC,CAAA;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdown-to-html-cli",
3
- "version": "3.2.11",
3
+ "version": "3.2.14",
4
4
  "license": "MIT",
5
5
  "description": "Command line tool generates markdown as html.",
6
6
  "homepage": "https://jaywcjlove.github.io/markdown-to-html-cli",
@@ -34,31 +34,22 @@
34
34
  },
35
35
  "files": [
36
36
  "lib",
37
- "github-fork-ribbon.css",
38
- "github.css"
37
+ "src"
39
38
  ],
40
39
  "dependencies": {
41
- "@mapbox/rehype-prism": "~0.8.0",
42
40
  "@types/fs-extra": "~9.0.13",
43
41
  "@types/minimist": "~1.2.2",
42
+ "@uiw/github-corners": "~1.5.10",
43
+ "@wcj/markdown-style": "~1.0.1",
44
+ "@wcj/markdown-to-html": "~2.0.2",
44
45
  "fs-extra": "~10.0.0",
45
46
  "minimist": "~1.2.5",
46
- "rehype-attr": "~2.0.7",
47
47
  "rehype-autolink-headings": "~6.1.0",
48
48
  "rehype-document": "~6.0.1",
49
49
  "rehype-format": "~4.0.1",
50
- "rehype-meta": "~3.2.0",
51
- "rehype-raw": "~6.1.0",
52
- "rehype-rewrite": "~3.0.4",
50
+ "rehype-prism-plus": "~1.3.2",
53
51
  "rehype-slug": "~5.0.0",
54
- "rehype-stringify": "~9.0.2",
55
52
  "rehype-urls": "~1.1.1",
56
- "rehype-video": "~1.1.1",
57
- "rehype-wrap": "~1.0.10",
58
- "remark-gemoji": "~7.0.1",
59
- "remark-gfm": "~3.0.1",
60
- "remark-parse": "~10.0.1",
61
- "remark-rehype": "~10.1.0",
62
- "unified": "~10.1.1"
53
+ "remark-gemoji": "~7.0.1"
63
54
  }
64
55
  }
package/src/cli.ts ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { run } from './index';
4
+
5
+ run();
package/src/create.ts ADDED
@@ -0,0 +1,101 @@
1
+ import markdown, { Options } from '@wcj/markdown-to-html';
2
+ import { getCodeString } from 'rehype-rewrite';
3
+ import rehypeDocument from 'rehype-document';
4
+ import rehypeAutolinkHeadings from 'rehype-autolink-headings';
5
+ import rehypeSlug from 'rehype-slug';
6
+ import remarkGemoji from 'remark-gemoji';
7
+ // @ts-ignore
8
+ import rehypeUrls from 'rehype-urls';
9
+ import rehypeFormat from 'rehype-format';
10
+ import { githubCorners } from './nodes/github-corners';
11
+ import { githubCornersFork } from './nodes/github-corners-fork';
12
+ import { octiconLink } from './nodes/octiconLink';
13
+ import { markdownStyle } from './nodes/markdown-style';
14
+ import { copyElement, copyStyle, copyScript } from './nodes/copy';
15
+ import { darkMode } from './nodes/dark-mode';
16
+ import { MDToHTMLOptions } from './';
17
+
18
+ // https://stackoverflow.com/questions/46745014/alternative-for-dirname-in-node-when-using-the-experimental-modules-flag
19
+ // export const _dirname = dirname(fileURLToPath(import.meta.url));
20
+ // const filename = fileURLToPath(import.meta.url);
21
+ // const dirname = path.dirname(filename);
22
+
23
+ export const _dirname = __dirname;
24
+ export interface CreateOptions extends MDToHTMLOptions { }
25
+
26
+ export function create(options: MDToHTMLOptions = {}) {
27
+ const { markdown: string, document, rewrite, reurls = {} } = options;
28
+
29
+ const mdOptions: Options = {
30
+ hastNode: false,
31
+ remarkPlugins: [remarkGemoji],
32
+ rehypePlugins: [
33
+ [rehypeUrls, (url: any) => {
34
+ if (reurls[url.href]) {
35
+ url.path = reurls[url.href];
36
+ return url.path;
37
+ }
38
+ }],
39
+ [rehypeSlug],
40
+ [rehypeAutolinkHeadings],
41
+ [rehypeFormat],
42
+ ],
43
+ rewrite: (node, index, parent) => {
44
+ if ((node.type == 'element' && node.tagName === 'body') || (!document && node.type === 'root')) {
45
+ node.children = markdownStyle(node.children as any);
46
+ darkMode().forEach(item => node.children.unshift(item));
47
+ }
48
+ if (options['github-corners'] && ((document && node.type == 'element' && node.tagName === 'body') || (!document && node.type === 'root'))) {
49
+ node.children = Array.isArray(node.children) ? node.children : [];
50
+ if (options['github-corners-fork']) {
51
+ node.children.unshift(githubCornersFork({ href: options['github-corners'] }));
52
+ } else {
53
+ githubCorners({ href: options['github-corners'] }).forEach(item => {
54
+ node.children.unshift(item)
55
+ });
56
+ }
57
+ }
58
+ if (node.type == 'element' && /h(1|2|3|4|5|6)/.test(node.tagName) && node.children && Array.isArray(node.children) && node.children.length > 0) {
59
+ const child = node.children[0];
60
+ if (child && child.type === 'element' && child.properties) {
61
+ child.properties = { className: 'anchor', ...child.properties };
62
+ child.children = [octiconLink()];
63
+ }
64
+ }
65
+ if (node.type == 'element' && node.tagName === 'markdown-style') {
66
+ node.children.unshift(copyStyle())
67
+ node.children.unshift(copyScript())
68
+ }
69
+ if (node.type == 'element' && node.tagName === 'pre') {
70
+ const code = getCodeString(node.children);
71
+ node.children.push(copyElement(code));
72
+ }
73
+ if (rewrite && typeof rewrite === 'function') {
74
+ rewrite(node, index, parent);
75
+ }
76
+ }
77
+ }
78
+
79
+ if (document) {
80
+ const documentOptions = { ...document };
81
+ if (document.js) {
82
+ documentOptions.js = Array.isArray(document.js) ? document.js : [document.js];
83
+ }
84
+
85
+ if (document.script) {
86
+ documentOptions.script = Array.isArray(document.script) ? document.script : [document.script];
87
+ }
88
+
89
+ if (document.link) {
90
+ documentOptions.link = Array.isArray(document.link) ? document.link : [document.link];
91
+ }
92
+
93
+ if (document.style) {
94
+ documentOptions.style = Array.isArray(document.style) ? document.style : [document.style];
95
+ }
96
+
97
+ mdOptions.rehypePlugins.unshift([rehypeDocument, documentOptions]);
98
+ }
99
+
100
+ return markdown(string || '', mdOptions) as string;
101
+ }
package/src/index.ts ADDED
@@ -0,0 +1,113 @@
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ import minimist, { ParsedArgs } from 'minimist';
4
+ import { Options } from 'rehype-document';
5
+ import { RehypeRewriteOptions } from 'rehype-rewrite';
6
+ import { create, _dirname } from './create';
7
+ import { formatConfig } from './utils';
8
+
9
+ export * from './create';
10
+ export * from './utils';
11
+
12
+ export interface RunArgvs extends Omit<ParsedArgs, '_'> {
13
+ version?: string;
14
+ source?: string;
15
+ output?: string;
16
+ /** Add a Github corner to your project page. */
17
+ 'github-corners'?: string;
18
+ /** Github corners style. */
19
+ 'github-corners-fork'?: boolean;
20
+ /** Markdown string. */
21
+ markdown?: string;
22
+ /** The `<title>` tag is required in HTML documents! */
23
+ title?: string;
24
+ /** Specify the configuration file. Default: `<process.cwd()>/package.json` */
25
+ config?: string;
26
+ /** Define a description of your web page */
27
+ description?: string;
28
+ /** Define keywords for search engines */
29
+ keywords?: string;
30
+ /** Add a Favicon to your Site */
31
+ favicon?: string;
32
+ /** Define the author of a page */
33
+ author?: string;
34
+ }
35
+
36
+ export interface MDToHTMLOptions extends RunArgvs {
37
+ /** [rehype-document](https://github.com/rehypejs/rehype-document#options) options */
38
+ document?: Options;
39
+ /** Rewrite Element. [rehype-rewrite](https://github.com/jaywcjlove/rehype-rewrite#rewritenode-index-parent-void) */
40
+ rewrite?: RehypeRewriteOptions['rewrite'];
41
+ /** rewrite URLs of href and src attributes. */
42
+ reurls?: Record<string, string>;
43
+ }
44
+
45
+ export function run(opts = {} as Omit<RunArgvs, '_'>) {
46
+ const argvs = minimist<RunArgvs>(process.argv.slice(2), {
47
+ alias: {
48
+ help: 'h',
49
+ version: 'v',
50
+ config: 'c',
51
+ source: 's',
52
+ output: 'o',
53
+ },
54
+ default: {
55
+ version: opts.v || opts.version || false,
56
+ help: opts.h || opts.help || false,
57
+ source: opts.s || opts.source || 'README.md',
58
+ markdown: opts.markdown || '',
59
+ description: opts.description || '',
60
+ output: opts.o || opts.output || 'index.html',
61
+ },
62
+ });
63
+ if (argvs.h || argvs.help) {
64
+ console.log(`${cliHelp}${exampleHelp}`);
65
+ return;
66
+ }
67
+ const pkgPath = path.resolve(_dirname, '..', 'package.json')
68
+ if ((argvs.v || argvs.version) && fs.existsSync(pkgPath)) {
69
+ const pkg = fs.readJSONSync(pkgPath);
70
+ console.log(`\n \x1b[35mmarkdown-to-html-cli\x1b[0m v${pkg.version}\n`);
71
+ return pkg.version;
72
+ }
73
+ if (argvs.source && !argvs.markdown) {
74
+ argvs.markdown = fs.readFileSync(path.resolve(argvs.source)).toString();
75
+ }
76
+ const options = formatConfig({ ...opts, ...argvs });
77
+ const output = path.resolve(argvs.output);
78
+
79
+ const strMarkdown = create({ ...argvs, ...options });
80
+ fs.writeFileSync(output, strMarkdown);
81
+ console.log(`\nmarkdown-to-html: \x1b[32;1m${path.relative(process.cwd(), output)}\x1b[0m\n`);
82
+ }
83
+
84
+ export const cliHelp: string = `\n Usage: markdown-to-html [options] [--help|h]
85
+
86
+ Options:\n
87
+ --author Define the author of a page.
88
+ --config, -o Specify the configuration file. Default: "<process.cwd()>/package.json".
89
+ --description Define a description of your web page.
90
+ --favicon Add a Favicon to your Site.
91
+ --github-corners Add a Github corner to your project page.
92
+ --github-corners-fork Github corners style.
93
+ --keywords Define keywords for search engines.
94
+ --markdown Markdown string.
95
+ --output, -o Output static pages to the specified directory. Default: "index.html"
96
+ --source, -s The path of the target file "README.md". Default: "README.md"
97
+ --title The \`<title>\` tag is required in HTML documents!
98
+ --version, -v Show version number
99
+ --help, -h Displays help information.
100
+ `;
101
+
102
+ export const exampleHelp: string =`\n Example:
103
+
104
+ \x1b[35mnpm\x1b[0m markdown-to-html-cli
105
+ \x1b[35mnpm\x1b[0m markdown-to-html \x1b[33m--title\x1b[0m="Hello World!"
106
+ \x1b[35mnpm\x1b[0m markdown-to-html \x1b[33m--config\x1b[0m="config/conf.json"
107
+ \x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--markdown\x1b[0m="Hello World!"
108
+ \x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--github-corners\x1b[0m https://github.com/jaywcjlove/markdown-to-html-cli
109
+ \x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--github-corners\x1b[0m https://github.com/jaywcjlove --github-corners-fork
110
+ \x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--output\x1b[0m coverage/index.html
111
+ \x1b[35mnpm\x1b[0m markdown-to-html-cli \x1b[33m--source\x1b[0m README.md
112
+
113
+ `;
@@ -0,0 +1,148 @@
1
+ import { Element } from 'hast';
2
+
3
+ const style = `.markdown-body pre .copied {
4
+ display: flex;
5
+ position: absolute;
6
+ cursor: pointer;
7
+ color: #a5afbb;
8
+ top: 6px;
9
+ right: 6px;
10
+ border-radius: 5px;
11
+ background: #82828226;
12
+ padding: 6px;
13
+ font-size: 12px;
14
+ transition: all .3s;
15
+ }
16
+ .markdown-body pre .copied:not(.active) {
17
+ visibility: hidden;
18
+ }
19
+ .markdown-body pre:hover .copied {
20
+ visibility: visible;
21
+ }
22
+ .markdown-body pre:hover .copied:hover {
23
+ background: #4caf50;
24
+ color: #fff;
25
+ }
26
+ .markdown-body pre:hover .copied:active,
27
+ .markdown-body pre .copied.active {
28
+ background: #2e9b33;
29
+ color: #fff;
30
+ }
31
+ .markdown-body pre .copied .octicon-copy {
32
+ display: block;
33
+ }
34
+ .markdown-body pre .copied .octicon-check {
35
+ display: none;
36
+ }
37
+ .markdown-body pre .active .octicon-copy {
38
+ display: none;
39
+ }
40
+ .markdown-body pre .active .octicon-check {
41
+ display: block;
42
+ }`;
43
+
44
+ export function copyStyle(): Element {
45
+ return {
46
+ type: 'element',
47
+ tagName: 'style',
48
+ children: [
49
+ {
50
+ type: 'text',
51
+ value: style
52
+ }
53
+ ]
54
+ }
55
+ }
56
+
57
+ const script = `/*! @uiw/copy-to-clipboard v1.0.12 | MIT (c) 2021 Kenny Wang | https://github.com/uiwjs/copy-to-clipboard.git */
58
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).copyTextToClipboard=t()}(this,(function(){"use strict";return function(e,t){const o=document.createElement("textarea");o.value=e,o.setAttribute("readonly",""),o.style={position:"absolute",left:"-9999px"},document.body.appendChild(o);const n=document.getSelection().rangeCount>0&&document.getSelection().getRangeAt(0);o.select();let c=!1;try{c=!!document.execCommand("copy")}catch(e){c=!1}document.body.removeChild(o),n&&document.getSelection&&(document.getSelection().removeAllRanges(),document.getSelection().addRange(n)),t&&t(c)}}));
59
+
60
+ function copied(target, str) {
61
+ target.classList.add('active');
62
+ copyTextToClipboard(target.dataset.code, function() {
63
+ setTimeout(() => {
64
+ target.classList.remove('active');
65
+ }, 2000);
66
+ });
67
+ }`;
68
+
69
+ export function copyScript(): Element {
70
+ return {
71
+ type: 'element',
72
+ tagName: 'script',
73
+ children: [
74
+ {
75
+ type: 'text',
76
+ value: script
77
+ }
78
+ ]
79
+ }
80
+ }
81
+
82
+ export function copyElement(str: string = ''): Element {
83
+ return {
84
+ type: 'element',
85
+ tagName: 'div',
86
+ properties: {
87
+ onclick: 'copied(this)',
88
+ 'data-code': str,
89
+ className: 'copied',
90
+ },
91
+ children: [
92
+ {
93
+ type: 'element',
94
+ tagName: 'svg',
95
+ properties: {
96
+ className: 'octicon-copy',
97
+ ariaHidden: 'true',
98
+ viewBox: '0 0 16 16',
99
+ fill: 'currentColor',
100
+ height: 12,
101
+ width: 12,
102
+ },
103
+ children: [
104
+ {
105
+ type: 'element',
106
+ tagName: 'path',
107
+ properties: {
108
+ fillRule: 'evenodd',
109
+ d: 'M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z'
110
+ },
111
+ children: []
112
+ }, {
113
+ type: 'element',
114
+ tagName: 'path',
115
+ properties: {
116
+ fillRule: 'evenodd',
117
+ d: 'M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z'
118
+ },
119
+ children: []
120
+ }
121
+ ]
122
+ },
123
+ {
124
+ type: 'element',
125
+ tagName: 'svg',
126
+ properties: {
127
+ className: 'octicon-check',
128
+ ariaHidden: 'true',
129
+ viewBox: '0 0 16 16',
130
+ fill: 'currentColor',
131
+ height: 12,
132
+ width: 12,
133
+ },
134
+ children: [
135
+ {
136
+ type: 'element',
137
+ tagName: 'path',
138
+ properties: {
139
+ fillRule: 'evenodd',
140
+ d: 'M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z'
141
+ },
142
+ children: []
143
+ }
144
+ ]
145
+ }
146
+ ]
147
+ }
148
+ }
@@ -0,0 +1,31 @@
1
+ import { Element } from 'hast';
2
+
3
+ const scriptString = `const t=document;const e="_dark_mode_theme_";const s="permanent";const o="colorschemechange";const i="permanentcolorscheme";const h="light";const r="dark";const n=(t,e,s=e)=>{Object.defineProperty(t,s,{enumerable:true,get(){const t=this.getAttribute(e);return t===null?"":t},set(t){this.setAttribute(e,t)}})};const c=(t,e,s=e)=>{Object.defineProperty(t,s,{enumerable:true,get(){return this.hasAttribute(e)},set(t){if(t){this.setAttribute(e,"")}else{this.removeAttribute(e)}}})};class a extends HTMLElement{static get observedAttributes(){return["mode",h,r,s]}LOCAL_NANE=e;constructor(){super();this.t()}connectedCallback(){n(this,"mode");n(this,r);n(this,h);c(this,s);const a=localStorage.getItem(e);if(a&&[h,r].includes(a)){this.mode=a;this.permanent=true}if(this.permanent&&!a){localStorage.setItem(e,this.mode)}const l=[h,r].includes(a);if(this.permanent&&a){this.o()}else{if(window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches){this.mode=r;this.o()}if(window.matchMedia&&window.matchMedia("(prefers-color-scheme: light)").matches){this.mode=h;this.o()}}if(!this.permanent&&!l){window.matchMedia("(prefers-color-scheme: light)").onchange=t=>{this.mode=t.matches?h:r;this.o()};window.matchMedia("(prefers-color-scheme: dark)").onchange=t=>{this.mode=t.matches?r:h;this.o()}}const d=new MutationObserver(((s,h)=>{this.mode=t.documentElement.dataset.colorMode;if(this.permanent&&l){localStorage.setItem(e,this.mode);this.i(i,{permanent:this.permanent})}this.h();this.i(o,{colorScheme:this.mode})}));d.observe(t.documentElement,{attributes:true});this.i(o,{colorScheme:this.mode});this.h()}attributeChangedCallback(t,s,o){if(t==="mode"&&s!==o&&[h,r].includes(o)){const t=localStorage.getItem(e);if(this.mode===t){this.mode=o;this.h();this.o()}else if(this.mode&&this.mode!==t){this.h();this.o()}}else if((t===h||t===r)&&s!==o){this.h()}if(t==="permanent"&&typeof this.permanent==="boolean"){this.permanent?localStorage.setItem(e,this.mode):localStorage.removeItem(e)}}o(){t.documentElement.setAttribute("data-color-mode",this.mode)}h(){this.icon.textContent=this.mode===h?"🌒":"🌞";this.text.textContent=this.mode===h?this.getAttribute(r):this.getAttribute(h)}t(){var s=this.attachShadow({mode:"open"});this.label=t.createElement("span");this.label.setAttribute("class","wrapper");this.label.onclick=()=>{this.mode=this.mode===h?r:h;if(this.permanent){localStorage.setItem(e,this.mode)}this.o();this.h()};s.appendChild(this.label);this.icon=t.createElement("span");this.label.appendChild(this.icon);this.text=t.createElement("span");this.label.appendChild(this.text);const o=\`\n[data-color-mode*='dark'], [data-color-mode*='dark'] body {\n color-scheme: dark;\n --color-theme-bg: #0d1117;\n --color-theme-text: #c9d1d9;\n background-color: var(--color-theme-bg);\n color: var(--color-theme-text);\n}\n\n[data-color-mode*='light'], [data-color-mode*='light'] body {\n color-scheme: light;\n --color-theme-bg: #fff;\n --color-theme-text: #24292f;\n background-color: var(--color-theme-bg);\n color: var(--color-theme-text);\n}\`;const i="_dark_mode_style_";const n=t.getElementById(i);if(!n){var c=t.createElement("style");c.id=i;c.textContent=o;t.head.appendChild(c)}var a=t.createElement("style");a.textContent=\`\n .wrapper { cursor: pointer; user-select: none; position: relative; }\n .wrapper > span + span { margin-left: .4rem; }\n \`;s.appendChild(a)}i(t,e){this.dispatchEvent(new CustomEvent(t,{bubbles:true,composed:true,detail:e}))}}customElements.define("dark-mode",a);`
4
+
5
+ /**
6
+ * @wcj/dark-mode@1.0.14
7
+ * https://github.com/jaywcjlove/dark-mode
8
+ */
9
+ export function darkMode(): Element[] {
10
+ return [{
11
+ type: 'element',
12
+ tagName: 'script',
13
+ // properties: {
14
+ // src: 'https://unpkg.com/@wcj/dark-mode',
15
+ // },
16
+ children: [{
17
+ type: 'text',
18
+ value: scriptString,
19
+ }]
20
+ }, {
21
+ type: 'element',
22
+ tagName: 'dark-mode',
23
+ properties: {
24
+ permanent: true,
25
+ style: 'position: fixed; top: 8px; left: 10px; z-index: 999;',
26
+ dark: 'Dark',
27
+ light: 'Light',
28
+ },
29
+ children: []
30
+ }]
31
+ }
@@ -1,4 +1,6 @@
1
- .github-fork-ribbon {
1
+ import { Element } from 'hast';
2
+
3
+ const style = `.github-fork-ribbon {
2
4
  width: 12.1em;
3
5
  height: 12.1em;
4
6
  position: absolute;
@@ -88,4 +90,39 @@
88
90
  border-style: dotted;
89
91
  border-color: #fff;
90
92
  border-color: rgba(255, 255, 255, 0.7);
93
+ }`;
94
+
95
+ interface GithubCorners {
96
+ href?: string;
91
97
  }
98
+
99
+ export function githubCornersFork(opts: GithubCorners): Element {
100
+ const { href } = opts;
101
+ if (!href) {
102
+ return;
103
+ }
104
+ return {
105
+ type: 'element',
106
+ tagName: 'a',
107
+ properties: {
108
+ 'aria-label': 'Fork me on Github',
109
+ title: 'Fork me on GitHub',
110
+ target: '__blank',
111
+ className: 'github-fork-ribbon',
112
+ 'data-ribbon': 'Fork me on GitHub',
113
+ href,
114
+ },
115
+ children: [
116
+ {
117
+ type: 'element',
118
+ tagName: 'style',
119
+ children: [
120
+ {
121
+ type: 'text',
122
+ value: style
123
+ }
124
+ ]
125
+ }
126
+ ]
127
+ }
128
+ }
@@ -0,0 +1,116 @@
1
+ import { Element } from 'hast';
2
+
3
+ interface GithubCorners {
4
+ href?: string;
5
+ }
6
+
7
+ /**
8
+ * @uiw/github-corners@1.5.10
9
+ * https://github.com/uiwjs/react-github-corners
10
+ */
11
+ const scriptString = `const TEMPLATE = document.createElement("template");
12
+ TEMPLATE.innerHTML = \`
13
+ <style>
14
+ :host a:hover .octo-arm {
15
+ animation: octocat-wave 560ms ease-in-out;
16
+ }
17
+ @keyframes octocat-wave {
18
+ 0%, 100% {
19
+ transform: rotate(0);
20
+ }
21
+ 20%, 60% {
22
+ transform: rotate(-25deg);
23
+ }
24
+ 40%, 80% {
25
+ transform: rotate(10deg);
26
+ }
27
+ }
28
+ @media (max-width:500px) {
29
+ :host a:hover .octo-arm {
30
+ animation: none;
31
+ }
32
+ :host .octo-arm {
33
+ animation: octocat-wave 560ms ease-in-out;
34
+ }
35
+ }
36
+ </style>
37
+ <svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true" style="position: absolute; border: 0px; top: 0px;">
38
+ <a xlink:href="https://github.com/uiwjs/react-github-corners" target="_blank" rel="nofollow sponsored" style="fill: rgb(21, 21, 19); color: rgb(255, 255, 255);">
39
+ <g>
40
+ <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
41
+ <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" class="octo-arm" style="transform-origin: 130px 106px;"></path>
42
+ <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path>
43
+ </g>
44
+ </a>
45
+ </svg>
46
+ \`;
47
+ export class GithubCorners extends HTMLElement {
48
+ constructor() {
49
+ super();
50
+ this.right = '0';
51
+ this.shadow = this.attachShadow({ mode: 'open' });
52
+ this.shadow.appendChild(this.ownerDocument.importNode(TEMPLATE.content, true));
53
+ this.update();
54
+ }
55
+ static get observedAttributes() {
56
+ return ['z-index', 'target', 'height', 'width', 'href', 'color', 'fill', 'position', 'top', 'left', 'right', 'bottom', 'transform'];
57
+ }
58
+ setAttr(name, value) {
59
+ const svg = this.shadow.querySelector('svg');
60
+ if (/(href)/.test(name.toLocaleLowerCase())) {
61
+ svg.lastElementChild.setAttribute('xlink:href', value);
62
+ }
63
+ else if (/(color|fill)/.test(name.toLocaleLowerCase())) {
64
+ svg.firstElementChild.style[name] = value;
65
+ }
66
+ else if (/(z-index|height|width|position|top|left|right|bottom|transform)/.test(name.toLocaleLowerCase())) {
67
+ svg.style[name] = value;
68
+ }
69
+ else {
70
+ svg.setAttribute(name, value);
71
+ }
72
+ }
73
+ update() {
74
+ ;
75
+ [...this.getAttributeNames(), 'right'].forEach((name) => {
76
+ const value = this.getAttribute(name) || this[name] || '';
77
+ this.setAttr(name, value);
78
+ });
79
+ }
80
+ attributeChangedCallback(name, oldValue, newValue) {
81
+ if (oldValue !== newValue) {
82
+ this.setAttr(name, newValue);
83
+ }
84
+ }
85
+ }
86
+ customElements.define('github-corners', GithubCorners);`;
87
+
88
+ export function githubCorners(opts: GithubCorners): Element[] {
89
+ const { href } = opts;
90
+ if (!href) {
91
+ return;
92
+ }
93
+ return [
94
+ {
95
+ type: 'element',
96
+ tagName: 'github-corners',
97
+ properties: {
98
+ target: '__blank',
99
+ position: 'fixed',
100
+ href,
101
+ },
102
+ children: []
103
+ }, {
104
+ type: 'element',
105
+ tagName: 'script',
106
+ properties: {
107
+ type: 'module',
108
+ // src: 'https://unpkg.com/@uiw/github-corners?module',
109
+ },
110
+ children: [{
111
+ type: 'text',
112
+ value: scriptString,
113
+ }]
114
+ }
115
+ ];
116
+ }