mdat-plugin-tldraw 2.0.0 → 2.0.2
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.js +8 -9
- package/package.json +12 -11
- package/readme.md +7 -3
package/dist/index.js
CHANGED
|
@@ -11,16 +11,16 @@ var src_default = { tldraw: { async content(options, context) {
|
|
|
11
11
|
dest: z.string().optional(),
|
|
12
12
|
src: z.string()
|
|
13
13
|
}).parse(options);
|
|
14
|
-
const
|
|
15
|
-
const assetsPath = path.resolve(
|
|
16
|
-
if (!await isDirectory(assetsPath)) throw new Error("Destination must be a directory`");
|
|
14
|
+
const markdownDirectory = context?.filePath ? path.dirname(context.filePath) : process.cwd();
|
|
15
|
+
const assetsPath = path.resolve(markdownDirectory, destination);
|
|
17
16
|
await fs.mkdir(assetsPath, { recursive: true });
|
|
17
|
+
if (!await isDirectory(assetsPath)) throw new Error("Destination must be a directory");
|
|
18
18
|
let sourceHash = await isFile(src) ? await getFileHash(src) : void 0;
|
|
19
19
|
if (sourceHash !== void 0) {
|
|
20
20
|
const fileName = path.basename(src, path.extname(src));
|
|
21
21
|
const possibleLightPath = path.join(assetsPath, `${fileName}-${sourceHash}-light.svg`);
|
|
22
22
|
const possibleDarkPath = path.join(assetsPath, `${fileName}-${sourceHash}-dark.svg`);
|
|
23
|
-
if (await isFile(possibleLightPath) && await isFile(possibleDarkPath)) return getPictureElement(
|
|
23
|
+
if (await isFile(possibleLightPath) && await isFile(possibleDarkPath)) return getPictureElement(markdownDirectory, possibleLightPath, possibleDarkPath, alt);
|
|
24
24
|
}
|
|
25
25
|
const [lightPath] = await tldrawToImage(src, {
|
|
26
26
|
dark: false,
|
|
@@ -47,13 +47,12 @@ var src_default = { tldraw: { async content(options, context) {
|
|
|
47
47
|
const assetName = path.basename(asset);
|
|
48
48
|
if (assetName !== darkPathHashedName && assetName !== lightPathHashedName && assetName.startsWith(filePrefix) && assetName.endsWith(".svg")) await fs.rm(path.join(assetsPath, assetName));
|
|
49
49
|
}
|
|
50
|
-
return getPictureElement(
|
|
50
|
+
return getPictureElement(markdownDirectory, lightPathHashed, darkPathHashed, alt);
|
|
51
51
|
} } };
|
|
52
|
-
function getPictureElement(
|
|
53
|
-
const
|
|
54
|
-
const relativeLightPath = path.relative(basePath, lightPath);
|
|
52
|
+
function getPictureElement(baseDirectory, lightPath, darkPath, alt) {
|
|
53
|
+
const relativeLightPath = path.relative(baseDirectory, lightPath).split(path.sep).join("/");
|
|
55
54
|
return `<picture>
|
|
56
|
-
<source media="(prefers-color-scheme: dark)" srcset="${path.relative(
|
|
55
|
+
<source media="(prefers-color-scheme: dark)" srcset="${path.relative(baseDirectory, darkPath).split(path.sep).join("/")}">
|
|
57
56
|
<source media="(prefers-color-scheme: light)" srcset="${relativeLightPath}">
|
|
58
57
|
<img alt="${alt}" src="${relativeLightPath}">
|
|
59
58
|
</picture>`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mdat-plugin-tldraw",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Mdat plugin to embed tldraw diagrams in Markdown files.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown",
|
|
@@ -35,19 +35,20 @@
|
|
|
35
35
|
"dist/*"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@kitschpatrol/tldraw-cli": "^5.0.
|
|
38
|
+
"@kitschpatrol/tldraw-cli": "^5.0.16",
|
|
39
39
|
"path-type": "^6.0.0",
|
|
40
40
|
"zod": "^4.3.6"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@kitschpatrol/shared-config": "^7.
|
|
44
|
-
"@types/node": "~20.19.
|
|
43
|
+
"@kitschpatrol/shared-config": "^7.5.0",
|
|
44
|
+
"@types/node": "~20.19.39",
|
|
45
45
|
"bumpp": "^11.0.1",
|
|
46
|
-
"mdat": "^2.
|
|
47
|
-
"remark-mdat": "^2.
|
|
48
|
-
"
|
|
46
|
+
"mdat": "^2.3.0",
|
|
47
|
+
"remark-mdat": "^2.2.1",
|
|
48
|
+
"shx": "^0.4.0",
|
|
49
|
+
"tsdown": "^0.21.10",
|
|
49
50
|
"typescript": "~5.9.3",
|
|
50
|
-
"vitest": "^4.1.
|
|
51
|
+
"vitest": "^4.1.5"
|
|
51
52
|
},
|
|
52
53
|
"peerDependencies": {
|
|
53
54
|
"mdat": "^2.0.0",
|
|
@@ -64,10 +65,10 @@
|
|
|
64
65
|
},
|
|
65
66
|
"scripts": {
|
|
66
67
|
"build": "tsdown --no-fixed-extension --tsconfig tsconfig.build.json",
|
|
67
|
-
"clean": "
|
|
68
|
+
"clean": "shx rm -f pnpm-lock.yaml && git clean -fdX -e !.claude/",
|
|
68
69
|
"fix": "ksc fix",
|
|
69
70
|
"lint": "ksc lint",
|
|
70
|
-
"release": "bumpp --commit 'Release: %s' && pnpm
|
|
71
|
-
"test": "vitest run
|
|
71
|
+
"release": "bumpp --commit 'Release: %s' && pnpm build && NPM_AUTH_TOKEN=$(op read 'op://Personal/npm/token') && pnpm publish",
|
|
72
|
+
"test": "vitest run"
|
|
72
73
|
}
|
|
73
74
|
}
|
package/readme.md
CHANGED
|
@@ -123,13 +123,17 @@ Older `mdat` 1.x compatible versions [remain available](https://www.npmjs.com/pa
|
|
|
123
123
|
|
|
124
124
|
## Maintainers
|
|
125
125
|
|
|
126
|
-
[
|
|
126
|
+
[kitschpatrol](https://github.com/kitschpatrol)
|
|
127
127
|
|
|
128
128
|
<!-- contributing -->
|
|
129
129
|
|
|
130
130
|
## Contributing
|
|
131
131
|
|
|
132
|
-
[Issues](https://github.com/kitschpatrol/mdat-plugin-tldraw/issues)
|
|
132
|
+
[Issues](https://github.com/kitschpatrol/mdat-plugin-tldraw/issues) are welcome and appreciated.
|
|
133
|
+
|
|
134
|
+
Please open an issue to discuss changes before submitting a pull request. Unsolicited PRs (especially AI-generated ones) are unlikely to be merged.
|
|
135
|
+
|
|
136
|
+
This repository uses [@kitschpatrol/shared-config](https://github.com/kitschpatrol/shared-config) (via its `ksc` CLI) for linting and formatting, plus [MDAT](https://github.com/kitschpatrol/mdat) for readme placeholder expansion.
|
|
133
137
|
|
|
134
138
|
<!-- /contributing -->
|
|
135
139
|
|
|
@@ -137,6 +141,6 @@ Older `mdat` 1.x compatible versions [remain available](https://www.npmjs.com/pa
|
|
|
137
141
|
|
|
138
142
|
## License
|
|
139
143
|
|
|
140
|
-
[MIT](license.txt) © Eric Mika
|
|
144
|
+
[MIT](license.txt) © [Eric Mika](https://ericmika.com)
|
|
141
145
|
|
|
142
146
|
<!-- /license -->
|