diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f06235c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +dist diff --git a/README.md b/README.md new file mode 100644 index 0000000..2151536 --- /dev/null +++ b/README.md @@ -0,0 +1,64 @@ +# md4wc + +A Web component for rendering Markdown to HTML. + +## Features + +- ⚡ Insane fast rendering using [md4w](https://github.com/ije/md4w) (written in Zig) +- ✨ Declarative usage +- 💡 Lightweight +- 📘 ESM modules + +## Installation + +```sh +npm install md4wc md4c +# or pnpm install md4wc md4c +``` + +## How to use + +### Register + +Register the `MarkdownContent` and optionally `MarkdownContext`. + +```js +import { MarkdownContent } from "md4wc"; +customElements.define("md-content", new MarkdownContent()); +``` + +Or you can use the static helper + +```js +import { MarkdownContent } from "md4wc"; +class YourComponent extends MarkdownContent { + static { + this.register("md-content", YourComponent); + } +} + +export default MarkdownContextComponent; +``` + +### Usage + +Declare your markup and pass the `WASM` module path as `href`. This will initialize the `md4c` module under to hood. But you can do the same thing manually using `import { init } from "md4w`. + +```html + + + +``` + +```js +const md = this.querySelector("md-content"); +md.dispatchEvent(new CustomEvent("render", { detail: "Markdown content" })); +``` + +## References + +- https://developer.mozilla.org/en-US/docs/Web/API/Web_components + +``` + +``` diff --git a/jsr.json b/jsr.json new file mode 100644 index 0000000..0f41a5f --- /dev/null +++ b/jsr.json @@ -0,0 +1,7 @@ +{ + "name": "md4wc", + "version": "1.0.1", + "exports": { + ".": "./src/index.js" + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..1555d1d --- /dev/null +++ b/package.json @@ -0,0 +1,41 @@ +{ + "name": "md4wc", + "repository": "https://github.com/karesztrk/md4wc", + "version": "1.0.1", + "description": "", + "type": "module", + "types": "./types/index.d.ts", + "module": "./dist/index.js", + "scripts": { + "build": "rollup -c && pnpm generate:types", + "generate:types": "node ./scripts/generate-types.js", + "prepublishOnly": "pnpm build" + }, + "exports": { + ".": { + "types": "./types/index.d.ts", + "browser": "./dist/index.js", + "default": "./dist/index.js" + }, + "./package.json": "./package.json" + }, + "files": [ + "dist", + "types" + ], + "author": "", + "license": "MIT", + "dependencies": { + "@karesztrk/webcomponent-base": "^1.0.9" + }, + "devDependencies": { + "@rollup/plugin-node-resolve": "^15.2.3", + "@rollup/plugin-terser": "^0.4.4", + "dts-buddy": "^0.5.1", + "prettier": "^3.3.3", + "rollup": "^4.19.0" + }, + "peerDependencies": { + "md4w": "^0.2.6" + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml new file mode 100644 index 0000000..f5b4765 --- /dev/null +++ b/pnpm-lock.yaml @@ -0,0 +1,554 @@ +lockfileVersion: '9.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +importers: + + .: + dependencies: + '@karesztrk/webcomponent-base': + specifier: ^1.0.9 + version: 1.0.9 + md4w: + specifier: ^0.2.6 + version: 0.2.6 + devDependencies: + '@rollup/plugin-node-resolve': + specifier: ^15.2.3 + version: 15.2.3(rollup@4.19.0) + '@rollup/plugin-terser': + specifier: ^0.4.4 + version: 0.4.4(rollup@4.19.0) + dts-buddy: + specifier: ^0.5.1 + version: 0.5.1(typescript@5.5.4) + prettier: + specifier: ^3.3.3 + version: 3.3.3 + rollup: + specifier: ^4.19.0 + version: 4.19.0 + +packages: + + '@jridgewell/gen-mapping@0.3.5': + resolution: {integrity: sha512-IzL8ZoEDIBRWEzlCcRhOaCupYyN5gdIK+Q6fbFdPDg6HqX6jpkItn7DFIpW9LQzXG6Df9sA7+OKnq0qlz/GaQg==} + engines: {node: '>=6.0.0'} + + '@jridgewell/resolve-uri@3.1.2': + resolution: {integrity: sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==} + engines: {node: '>=6.0.0'} + + '@jridgewell/set-array@1.2.1': + resolution: {integrity: sha512-R8gLRTZeyp03ymzP/6Lil/28tGeGEzhx1q2k703KGWRAI1VdvPIXdG70VJc2pAMw3NA6JKL5hhFu1sJX0Mnn/A==} + engines: {node: '>=6.0.0'} + + '@jridgewell/source-map@0.3.6': + resolution: {integrity: sha512-1ZJTZebgqllO79ue2bm3rIGud/bOe0pP5BjSRCRxxYkEZS8STV7zN84UBbiYu7jy+eCKSnVIUgoWWE/tt+shMQ==} + + '@jridgewell/sourcemap-codec@1.5.0': + resolution: {integrity: sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==} + + '@jridgewell/trace-mapping@0.3.25': + resolution: {integrity: sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==} + + '@karesztrk/webcomponent-base@1.0.9': + resolution: {integrity: sha512-rlHiPm2XQv/BpRFIQYIWVKCRFMzNGZb9TupRNc6GKUf7s4nUDMK9klpyrrC0/8nBEysMwVUcAv6bnSG8IjOqUg==} + + '@rollup/plugin-node-resolve@15.2.3': + resolution: {integrity: sha512-j/lym8nf5E21LwBT4Df1VD6hRO2L2iwUeUmP7litikRsVp1H6NWx20NEp0Y7su+7XGc476GnXXc4kFeZNGmaSQ==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^2.78.0||^3.0.0||^4.0.0 + peerDependenciesMeta: + rollup: + optional: true + + '@rollup/plugin-terser@0.4.4': + resolution: {integrity: sha512-XHeJC5Bgvs8LfukDwWZp7yeqin6ns8RTl2B9avbejt6tZqsqvVoWI7ZTQrcNsfKEDWBTnTxM8nMDkO2IFFbd0A==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^2.0.0||^3.0.0||^4.0.0 + peerDependenciesMeta: + rollup: + optional: true + + '@rollup/pluginutils@5.1.0': + resolution: {integrity: sha512-XTIWOPPcpvyKI6L1NHo0lFlCyznUEyPmPY1mc3KpPVDYulHSTvyeLNVW00QTLIAFNhR3kYnJTQHeGqU4M3n09g==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0 + peerDependenciesMeta: + rollup: + optional: true + + '@rollup/rollup-android-arm-eabi@4.19.0': + resolution: {integrity: sha512-JlPfZ/C7yn5S5p0yKk7uhHTTnFlvTgLetl2VxqE518QgyM7C9bSfFTYvB/Q/ftkq0RIPY4ySxTz+/wKJ/dXC0w==} + cpu: [arm] + os: [android] + + '@rollup/rollup-android-arm64@4.19.0': + resolution: {integrity: sha512-RDxUSY8D1tWYfn00DDi5myxKgOk6RvWPxhmWexcICt/MEC6yEMr4HNCu1sXXYLw8iAsg0D44NuU+qNq7zVWCrw==} + cpu: [arm64] + os: [android] + + '@rollup/rollup-darwin-arm64@4.19.0': + resolution: {integrity: sha512-emvKHL4B15x6nlNTBMtIaC9tLPRpeA5jMvRLXVbl/W9Ie7HhkrE7KQjvgS9uxgatL1HmHWDXk5TTS4IaNJxbAA==} + cpu: [arm64] + os: [darwin] + + '@rollup/rollup-darwin-x64@4.19.0': + resolution: {integrity: sha512-fO28cWA1dC57qCd+D0rfLC4VPbh6EOJXrreBmFLWPGI9dpMlER2YwSPZzSGfq11XgcEpPukPTfEVFtw2q2nYJg==} + cpu: [x64] + os: [darwin] + + '@rollup/rollup-linux-arm-gnueabihf@4.19.0': + resolution: {integrity: sha512-2Rn36Ubxdv32NUcfm0wB1tgKqkQuft00PtM23VqLuCUR4N5jcNWDoV5iBC9jeGdgS38WK66ElncprqgMUOyomw==} + cpu: [arm] + os: [linux] + + '@rollup/rollup-linux-arm-musleabihf@4.19.0': + resolution: {integrity: sha512-gJuzIVdq/X1ZA2bHeCGCISe0VWqCoNT8BvkQ+BfsixXwTOndhtLUpOg0A1Fcx/+eA6ei6rMBzlOz4JzmiDw7JQ==} + cpu: [arm] + os: [linux] + + '@rollup/rollup-linux-arm64-gnu@4.19.0': + resolution: {integrity: sha512-0EkX2HYPkSADo9cfeGFoQ7R0/wTKb7q6DdwI4Yn/ULFE1wuRRCHybxpl2goQrx4c/yzK3I8OlgtBu4xvted0ug==} + cpu: [arm64] + os: [linux] + + '@rollup/rollup-linux-arm64-musl@4.19.0': + resolution: {integrity: sha512-GlIQRj9px52ISomIOEUq/IojLZqzkvRpdP3cLgIE1wUWaiU5Takwlzpz002q0Nxxr1y2ZgxC2obWxjr13lvxNQ==} + cpu: [arm64] + os: [linux] + + '@rollup/rollup-linux-powerpc64le-gnu@4.19.0': + resolution: {integrity: sha512-N6cFJzssruDLUOKfEKeovCKiHcdwVYOT1Hs6dovDQ61+Y9n3Ek4zXvtghPPelt6U0AH4aDGnDLb83uiJMkWYzQ==} + cpu: [ppc64] + os: [linux] + + '@rollup/rollup-linux-riscv64-gnu@4.19.0': + resolution: {integrity: sha512-2DnD3mkS2uuam/alF+I7M84koGwvn3ZVD7uG+LEWpyzo/bq8+kKnus2EVCkcvh6PlNB8QPNFOz6fWd5N8o1CYg==} + cpu: [riscv64] + os: [linux] + + '@rollup/rollup-linux-s390x-gnu@4.19.0': + resolution: {integrity: sha512-D6pkaF7OpE7lzlTOFCB2m3Ngzu2ykw40Nka9WmKGUOTS3xcIieHe82slQlNq69sVB04ch73thKYIWz/Ian8DUA==} + cpu: [s390x] + os: [linux] + + '@rollup/rollup-linux-x64-gnu@4.19.0': + resolution: {integrity: sha512-HBndjQLP8OsdJNSxpNIN0einbDmRFg9+UQeZV1eiYupIRuZsDEoeGU43NQsS34Pp166DtwQOnpcbV/zQxM+rWA==} + cpu: [x64] + os: [linux] + + '@rollup/rollup-linux-x64-musl@4.19.0': + resolution: {integrity: sha512-HxfbvfCKJe/RMYJJn0a12eiOI9OOtAUF4G6ozrFUK95BNyoJaSiBjIOHjZskTUffUrB84IPKkFG9H9nEvJGW6A==} + cpu: [x64] + os: [linux] + + '@rollup/rollup-win32-arm64-msvc@4.19.0': + resolution: {integrity: sha512-HxDMKIhmcguGTiP5TsLNolwBUK3nGGUEoV/BO9ldUBoMLBssvh4J0X8pf11i1fTV7WShWItB1bKAKjX4RQeYmg==} + cpu: [arm64] + os: [win32] + + '@rollup/rollup-win32-ia32-msvc@4.19.0': + resolution: {integrity: sha512-xItlIAZZaiG/u0wooGzRsx11rokP4qyc/79LkAOdznGRAbOFc+SfEdfUOszG1odsHNgwippUJavag/+W/Etc6Q==} + cpu: [ia32] + os: [win32] + + '@rollup/rollup-win32-x64-msvc@4.19.0': + resolution: {integrity: sha512-xNo5fV5ycvCCKqiZcpB65VMR11NJB+StnxHz20jdqRAktfdfzhgjTiJ2doTDQE/7dqGaV5I7ZGqKpgph6lCIag==} + cpu: [x64] + os: [win32] + + '@types/estree@1.0.5': + resolution: {integrity: sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==} + + '@types/resolve@1.20.2': + resolution: {integrity: sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==} + + acorn@8.12.1: + resolution: {integrity: sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==} + engines: {node: '>=0.4.0'} + hasBin: true + + buffer-from@1.1.2: + resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==} + + builtin-modules@3.3.0: + resolution: {integrity: sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==} + engines: {node: '>=6'} + + commander@2.20.3: + resolution: {integrity: sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==} + + deepmerge@4.3.1: + resolution: {integrity: sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==} + engines: {node: '>=0.10.0'} + + dts-buddy@0.5.1: + resolution: {integrity: sha512-naiM3F8hSlBIrMl+WyU9KQsC+Vd0i9jVBeksQ5IsH9Rfzpqx27TmSCftlsY9UxFxAWxoGcf5EB3p1xi0JxWzPw==} + hasBin: true + peerDependencies: + typescript: '>=5.0.4 <5.6' + + estree-walker@2.0.2: + resolution: {integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==} + + fsevents@2.3.3: + resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==} + engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} + os: [darwin] + + function-bind@1.1.2: + resolution: {integrity: sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==} + + globalyzer@0.1.0: + resolution: {integrity: sha512-40oNTM9UfG6aBmuKxk/giHn5nQ8RVz/SS4Ir6zgzOv9/qC3kKZ9v4etGTcJbEl/NyVQH7FGU7d+X1egr57Md2Q==} + + globrex@0.1.2: + resolution: {integrity: sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==} + + hasown@2.0.2: + resolution: {integrity: sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==} + engines: {node: '>= 0.4'} + + is-builtin-module@3.2.1: + resolution: {integrity: sha512-BSLE3HnV2syZ0FK0iMA/yUGplUeMmNz4AW5fnTunbCIqZi4vG3WjJT9FHMy5D69xmAYBHXQhJdALdpwVxV501A==} + engines: {node: '>=6'} + + is-core-module@2.15.0: + resolution: {integrity: sha512-Dd+Lb2/zvk9SKy1TGCt1wFJFo/MWBPMX5x7KcvLajWTGuomczdQX61PvY5yK6SVACwpoexWo81IfFyoKY2QnTA==} + engines: {node: '>= 0.4'} + + is-module@1.0.0: + resolution: {integrity: sha512-51ypPSPCoTEIN9dy5Oy+h4pShgJmPCygKfyRCISBI+JoWT/2oJvK8QPxmwv7b/p239jXrm9M1mlQbyKJ5A152g==} + + kleur@4.1.5: + resolution: {integrity: sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ==} + engines: {node: '>=6'} + + locate-character@3.0.0: + resolution: {integrity: sha512-SW13ws7BjaeJ6p7Q6CO2nchbYEc3X3J6WrmTTDto7yMPqVSZTUyY5Tjbid+Ab8gLnATtygYtiDIJGQRRn2ZOiA==} + + magic-string@0.30.10: + resolution: {integrity: sha512-iIRwTIf0QKV3UAnYK4PU8uiEc4SRh5jX0mwpIwETPpHdhVM4f53RSwS/vXvN1JhGX+Cs7B8qIq3d6AH49O5fAQ==} + + md4w@0.2.6: + resolution: {integrity: sha512-CBLQ2PxVe9WA+/nndZCx/Y+1C3DtmtSeubmXTPhMIgsXtq9gVGleikREko5FYnV6Dz4cHDWm0Ea+YMLpIjP4Kw==} + + mri@1.2.0: + resolution: {integrity: sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==} + engines: {node: '>=4'} + + path-parse@1.0.7: + resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==} + + picomatch@2.3.1: + resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==} + engines: {node: '>=8.6'} + + prettier@3.3.3: + resolution: {integrity: sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==} + engines: {node: '>=14'} + hasBin: true + + randombytes@2.1.0: + resolution: {integrity: sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==} + + resolve@1.22.8: + resolution: {integrity: sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==} + hasBin: true + + rollup@4.19.0: + resolution: {integrity: sha512-5r7EYSQIowHsK4eTZ0Y81qpZuJz+MUuYeqmmYmRMl1nwhdmbiYqt5jwzf6u7wyOzJgYqtCRMtVRKOtHANBz7rA==} + engines: {node: '>=18.0.0', npm: '>=8.0.0'} + hasBin: true + + sade@1.8.1: + resolution: {integrity: sha512-xal3CZX1Xlo/k4ApwCFrHVACi9fBqJ7V+mwhBsuf/1IOKbBy098Fex+Wa/5QMubw09pSZ/u8EY8PWgevJsXp1A==} + engines: {node: '>=6'} + + safe-buffer@5.2.1: + resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==} + + serialize-javascript@6.0.2: + resolution: {integrity: sha512-Saa1xPByTTq2gdeFZYLLo+RFE35NHZkAbqZeWNd3BpzppeVisAqpDjcp8dyf6uIvEqJRd46jemmyA4iFIeVk8g==} + + smob@1.5.0: + resolution: {integrity: sha512-g6T+p7QO8npa+/hNx9ohv1E5pVCmWrVCUzUXJyLdMmftX6ER0oiWY/w9knEonLpnOp6b6FenKnMfR8gqwWdwig==} + + source-map-support@0.5.21: + resolution: {integrity: sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==} + + source-map@0.6.1: + resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==} + engines: {node: '>=0.10.0'} + + supports-preserve-symlinks-flag@1.0.0: + resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==} + engines: {node: '>= 0.4'} + + terser@5.31.3: + resolution: {integrity: sha512-pAfYn3NIZLyZpa83ZKigvj6Rn9c/vd5KfYGX7cN1mnzqgDcxWvrU5ZtAfIKhEXz9nRecw4z3LXkjaq96/qZqAA==} + engines: {node: '>=10'} + hasBin: true + + tiny-glob@0.2.9: + resolution: {integrity: sha512-g/55ssRPUjShh+xkfx9UPDXqhckHEsHr4Vd9zX55oSdGZc/MD0m3sferOkwWtp98bv+kcVfEHtRJgBVJzelrzg==} + + ts-api-utils@1.3.0: + resolution: {integrity: sha512-UQMIo7pb8WRomKR1/+MFVLTroIvDVtMX3K6OUir8ynLyzB8Jeriont2bTAtmNPa1ekAgN7YPDyf6V+ygrdU+eQ==} + engines: {node: '>=16'} + peerDependencies: + typescript: '>=4.2.0' + + typescript@5.5.4: + resolution: {integrity: sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==} + engines: {node: '>=14.17'} + hasBin: true + +snapshots: + + '@jridgewell/gen-mapping@0.3.5': + dependencies: + '@jridgewell/set-array': 1.2.1 + '@jridgewell/sourcemap-codec': 1.5.0 + '@jridgewell/trace-mapping': 0.3.25 + + '@jridgewell/resolve-uri@3.1.2': {} + + '@jridgewell/set-array@1.2.1': {} + + '@jridgewell/source-map@0.3.6': + dependencies: + '@jridgewell/gen-mapping': 0.3.5 + '@jridgewell/trace-mapping': 0.3.25 + + '@jridgewell/sourcemap-codec@1.5.0': {} + + '@jridgewell/trace-mapping@0.3.25': + dependencies: + '@jridgewell/resolve-uri': 3.1.2 + '@jridgewell/sourcemap-codec': 1.5.0 + + '@karesztrk/webcomponent-base@1.0.9': {} + + '@rollup/plugin-node-resolve@15.2.3(rollup@4.19.0)': + dependencies: + '@rollup/pluginutils': 5.1.0(rollup@4.19.0) + '@types/resolve': 1.20.2 + deepmerge: 4.3.1 + is-builtin-module: 3.2.1 + is-module: 1.0.0 + resolve: 1.22.8 + optionalDependencies: + rollup: 4.19.0 + + '@rollup/plugin-terser@0.4.4(rollup@4.19.0)': + dependencies: + serialize-javascript: 6.0.2 + smob: 1.5.0 + terser: 5.31.3 + optionalDependencies: + rollup: 4.19.0 + + '@rollup/pluginutils@5.1.0(rollup@4.19.0)': + dependencies: + '@types/estree': 1.0.5 + estree-walker: 2.0.2 + picomatch: 2.3.1 + optionalDependencies: + rollup: 4.19.0 + + '@rollup/rollup-android-arm-eabi@4.19.0': + optional: true + + '@rollup/rollup-android-arm64@4.19.0': + optional: true + + '@rollup/rollup-darwin-arm64@4.19.0': + optional: true + + '@rollup/rollup-darwin-x64@4.19.0': + optional: true + + '@rollup/rollup-linux-arm-gnueabihf@4.19.0': + optional: true + + '@rollup/rollup-linux-arm-musleabihf@4.19.0': + optional: true + + '@rollup/rollup-linux-arm64-gnu@4.19.0': + optional: true + + '@rollup/rollup-linux-arm64-musl@4.19.0': + optional: true + + '@rollup/rollup-linux-powerpc64le-gnu@4.19.0': + optional: true + + '@rollup/rollup-linux-riscv64-gnu@4.19.0': + optional: true + + '@rollup/rollup-linux-s390x-gnu@4.19.0': + optional: true + + '@rollup/rollup-linux-x64-gnu@4.19.0': + optional: true + + '@rollup/rollup-linux-x64-musl@4.19.0': + optional: true + + '@rollup/rollup-win32-arm64-msvc@4.19.0': + optional: true + + '@rollup/rollup-win32-ia32-msvc@4.19.0': + optional: true + + '@rollup/rollup-win32-x64-msvc@4.19.0': + optional: true + + '@types/estree@1.0.5': {} + + '@types/resolve@1.20.2': {} + + acorn@8.12.1: {} + + buffer-from@1.1.2: {} + + builtin-modules@3.3.0: {} + + commander@2.20.3: {} + + deepmerge@4.3.1: {} + + dts-buddy@0.5.1(typescript@5.5.4): + dependencies: + '@jridgewell/source-map': 0.3.6 + '@jridgewell/sourcemap-codec': 1.5.0 + globrex: 0.1.2 + kleur: 4.1.5 + locate-character: 3.0.0 + magic-string: 0.30.10 + sade: 1.8.1 + tiny-glob: 0.2.9 + ts-api-utils: 1.3.0(typescript@5.5.4) + typescript: 5.5.4 + + estree-walker@2.0.2: {} + + fsevents@2.3.3: + optional: true + + function-bind@1.1.2: {} + + globalyzer@0.1.0: {} + + globrex@0.1.2: {} + + hasown@2.0.2: + dependencies: + function-bind: 1.1.2 + + is-builtin-module@3.2.1: + dependencies: + builtin-modules: 3.3.0 + + is-core-module@2.15.0: + dependencies: + hasown: 2.0.2 + + is-module@1.0.0: {} + + kleur@4.1.5: {} + + locate-character@3.0.0: {} + + magic-string@0.30.10: + dependencies: + '@jridgewell/sourcemap-codec': 1.5.0 + + md4w@0.2.6: {} + + mri@1.2.0: {} + + path-parse@1.0.7: {} + + picomatch@2.3.1: {} + + prettier@3.3.3: {} + + randombytes@2.1.0: + dependencies: + safe-buffer: 5.2.1 + + resolve@1.22.8: + dependencies: + is-core-module: 2.15.0 + path-parse: 1.0.7 + supports-preserve-symlinks-flag: 1.0.0 + + rollup@4.19.0: + dependencies: + '@types/estree': 1.0.5 + optionalDependencies: + '@rollup/rollup-android-arm-eabi': 4.19.0 + '@rollup/rollup-android-arm64': 4.19.0 + '@rollup/rollup-darwin-arm64': 4.19.0 + '@rollup/rollup-darwin-x64': 4.19.0 + '@rollup/rollup-linux-arm-gnueabihf': 4.19.0 + '@rollup/rollup-linux-arm-musleabihf': 4.19.0 + '@rollup/rollup-linux-arm64-gnu': 4.19.0 + '@rollup/rollup-linux-arm64-musl': 4.19.0 + '@rollup/rollup-linux-powerpc64le-gnu': 4.19.0 + '@rollup/rollup-linux-riscv64-gnu': 4.19.0 + '@rollup/rollup-linux-s390x-gnu': 4.19.0 + '@rollup/rollup-linux-x64-gnu': 4.19.0 + '@rollup/rollup-linux-x64-musl': 4.19.0 + '@rollup/rollup-win32-arm64-msvc': 4.19.0 + '@rollup/rollup-win32-ia32-msvc': 4.19.0 + '@rollup/rollup-win32-x64-msvc': 4.19.0 + fsevents: 2.3.3 + + sade@1.8.1: + dependencies: + mri: 1.2.0 + + safe-buffer@5.2.1: {} + + serialize-javascript@6.0.2: + dependencies: + randombytes: 2.1.0 + + smob@1.5.0: {} + + source-map-support@0.5.21: + dependencies: + buffer-from: 1.1.2 + source-map: 0.6.1 + + source-map@0.6.1: {} + + supports-preserve-symlinks-flag@1.0.0: {} + + terser@5.31.3: + dependencies: + '@jridgewell/source-map': 0.3.6 + acorn: 8.12.1 + commander: 2.20.3 + source-map-support: 0.5.21 + + tiny-glob@0.2.9: + dependencies: + globalyzer: 0.1.0 + globrex: 0.1.2 + + ts-api-utils@1.3.0(typescript@5.5.4): + dependencies: + typescript: 5.5.4 + + typescript@5.5.4: {} diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..d369e0e --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,19 @@ +import terser from "@rollup/plugin-terser"; +import resolve from "@rollup/plugin-node-resolve"; +import { defineConfig } from "rollup"; + +export default defineConfig({ + input: "src/index.js", + output: [ + { + dir: "dist", + format: "es", + exports: "named", + preserveModules: true, + preserveModulesRoot: "src", + sourcemap: true, + }, + ], + external: ["md4w"], + plugins: [resolve(), terser()], +}); diff --git a/scripts/generate-types.js b/scripts/generate-types.js new file mode 100644 index 0000000..3754316 --- /dev/null +++ b/scripts/generate-types.js @@ -0,0 +1,13 @@ +import fs from "node:fs"; +import { fileURLToPath } from "node:url"; +import { createBundle } from "dts-buddy"; + +const dir = fileURLToPath(new URL("..", import.meta.url)); +const pkg = JSON.parse(fs.readFileSync(`${dir}/package.json`, "utf-8")); + +await createBundle({ + output: `${dir}/types/index.d.ts`, + modules: { + [pkg.name]: `${dir}/src/index.d.ts`, + }, +}); diff --git a/src/MarkdownContent.js b/src/MarkdownContent.js new file mode 100644 index 0000000..c7fa761 --- /dev/null +++ b/src/MarkdownContent.js @@ -0,0 +1,29 @@ +import { mdToHtml } from "md4w"; +import { LightElement } from "@karesztrk/webcomponent-base"; + +class MarkdownContent extends LightElement { + /** + * @type {string| undefined} content + */ + content; + + constructor() { + super(); + + this.addEventListener("render", (e) => { + if (e instanceof CustomEvent) { + const content = e.detail; + this.content = content; + this.render(); + } + }); + } + + render() { + if (this.content) { + this.innerHTML = mdToHtml(this.content); + } + } +} + +export default MarkdownContent; diff --git a/src/MarkdownContext.js b/src/MarkdownContext.js new file mode 100644 index 0000000..8c54cf0 --- /dev/null +++ b/src/MarkdownContext.js @@ -0,0 +1,35 @@ +import { init } from "md4w"; +import { LightElement } from "@karesztrk/webcomponent-base"; + +class MarkdownContext extends LightElement { + constructor() { + super(); + this.init(); + } + + /** + * Initializes the context. + * @returns {Promise} href + */ + init() { + return new Promise((resolve, reject) => { + if (this.href) { + init(this.href) + .then(() => { + resolve(); + }) + .catch(() => reject()); + } else { + reject(); + } + }); + } + + get href() { + return this.getAttribute("href"); + } + + render() {} +} + +export default MarkdownContext; diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..1498ba5 --- /dev/null +++ b/src/index.js @@ -0,0 +1,4 @@ +import MarkdownContext from "./MarkdownContext"; +import MarkdownContent from "./MarkdownContent"; + +export { MarkdownContext, MarkdownContent }; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..92f53c8 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,18 @@ +{ + "include": ["./*.js", "./src/"], + "compilerOptions": { + "module": "esnext", + "lib": ["esnext", "dom", "dom.iterable"], + "target": "esnext", + "moduleResolution": "bundler", + "noEmit": true, + "resolveJsonModule": true, + "noEmitOnError": true, + "noErrorTruncation": true, + "allowSyntheticDefaultImports": true, + "verbatimModuleSyntax": true, + "strict": true, + "allowJs": true, + "checkJs": true + } +} diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..c99ebf8 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,23 @@ +declare module 'md4wc' { + import type { LightElement } from '@karesztrk/webcomponent-base'; + export default MarkdownContext; + class MarkdownContext extends LightElement { + /** + * Initializes the context. + * @returns href + */ + init(): Promise; + get href(): string | null; + } + export default MarkdownContent; + class MarkdownContent extends LightElement { + /** + * @type {string| undefined} content + */ + content: string | undefined; + } + + export { MarkdownContext, MarkdownContent }; +} + +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/types/index.d.ts.map b/types/index.d.ts.map new file mode 100644 index 0000000..664a3f0 --- /dev/null +++ b/types/index.d.ts.map @@ -0,0 +1,9 @@ +{ + "version": 3, + "file": "index.d.ts", + "names": [], + "sources": [], + "sourcesContent": [], + "mappings": "", + "ignoreList": [] +} \ No newline at end of file