mdat-plugin-tldraw 1.0.5 → 1.0.7
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.d.ts +1 -3
- package/dist/index.js +13 -14
- package/package.json +14 -8
- package/readme.md +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -12,14 +12,15 @@ var src_default = { tldraw: { async content(options) {
|
|
|
12
12
|
alt: z.string().optional(),
|
|
13
13
|
src: z.string()
|
|
14
14
|
}).parse(options);
|
|
15
|
-
const
|
|
15
|
+
const config = await loadConfig();
|
|
16
|
+
const { assetsPath } = config;
|
|
16
17
|
await fs.mkdir(assetsPath, { recursive: true });
|
|
17
18
|
let sourceHash = await isFile(src) ? await getFileHash(src) : void 0;
|
|
18
19
|
if (sourceHash !== void 0) {
|
|
19
20
|
const fileName = path.basename(src, path.extname(src));
|
|
20
21
|
const possibleLightPath = path.join(assetsPath, `${fileName}-${sourceHash}-light.svg`);
|
|
21
22
|
const possibleDarkPath = path.join(assetsPath, `${fileName}-${sourceHash}-dark.svg`);
|
|
22
|
-
if (await isFile(possibleLightPath) && await isFile(possibleDarkPath)) return getPictureElement(possibleLightPath, possibleDarkPath, alt);
|
|
23
|
+
if (await isFile(possibleLightPath) && await isFile(possibleDarkPath)) return getPictureElement(config, possibleLightPath, possibleDarkPath, alt);
|
|
23
24
|
}
|
|
24
25
|
const [lightPath] = await tldrawToImage(src, {
|
|
25
26
|
dark: false,
|
|
@@ -38,20 +39,18 @@ var src_default = { tldraw: { async content(options) {
|
|
|
38
39
|
});
|
|
39
40
|
const darkPathHashed = `${stripExtension(darkPath)}-${sourceHash}-dark.svg`;
|
|
40
41
|
await fs.rename(darkPath, darkPathHashed);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (assetName !== darkPathHashedName && assetName !== lightPathHashedName && assetName.startsWith(filePrefix) && assetName.endsWith(".svg")) await fs.rm(path.join(assetsPath, assetName));
|
|
49
|
-
}
|
|
42
|
+
const darkPathHashedName = path.basename(darkPathHashed);
|
|
43
|
+
const lightPathHashedName = path.basename(lightPathHashed);
|
|
44
|
+
const filePrefix = lightPathHashedName.replace(`${sourceHash}-light.svg`, "");
|
|
45
|
+
const currentAssets = await fs.readdir(assetsPath);
|
|
46
|
+
for (const asset of currentAssets) {
|
|
47
|
+
const assetName = path.basename(asset);
|
|
48
|
+
if (assetName !== darkPathHashedName && assetName !== lightPathHashedName && assetName.startsWith(filePrefix) && assetName.endsWith(".svg")) await fs.rm(path.join(assetsPath, assetName));
|
|
50
49
|
}
|
|
51
|
-
return getPictureElement(lightPathHashed, darkPathHashed, alt);
|
|
50
|
+
return getPictureElement(config, lightPathHashed, darkPathHashed, alt);
|
|
52
51
|
} } };
|
|
53
|
-
|
|
54
|
-
const { packageFile } =
|
|
52
|
+
function getPictureElement(config, lightPath, darkPath, alt) {
|
|
53
|
+
const { packageFile } = config;
|
|
55
54
|
if (packageFile === void 0) throw new Error("No package file found");
|
|
56
55
|
const basePath = path.dirname(packageFile);
|
|
57
56
|
const relativeLightPath = path.relative(basePath, lightPath);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mdat-plugin-tldraw",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Mdat plugin to embed tldraw diagrams in Markdown files.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown",
|
|
@@ -34,17 +34,17 @@
|
|
|
34
34
|
"dist/*"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@kitschpatrol/tldraw-cli": "^5.0.
|
|
37
|
+
"@kitschpatrol/tldraw-cli": "^5.0.10",
|
|
38
38
|
"path-type": "^6.0.0",
|
|
39
|
-
"type-fest": "^5.4.
|
|
39
|
+
"type-fest": "^5.4.4",
|
|
40
40
|
"zod": "^3.25.76"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@kitschpatrol/shared-config": "^
|
|
44
|
-
"@types/node": "
|
|
45
|
-
"bumpp": "^10.4.
|
|
46
|
-
"mdat": "^1.3.
|
|
47
|
-
"tsdown": "^0.20.
|
|
43
|
+
"@kitschpatrol/shared-config": "^6.0.0",
|
|
44
|
+
"@types/node": "~20.19.33",
|
|
45
|
+
"bumpp": "^10.4.1",
|
|
46
|
+
"mdat": "^1.3.5",
|
|
47
|
+
"tsdown": "^0.20.3",
|
|
48
48
|
"typescript": "~5.9.3",
|
|
49
49
|
"vitest": "^4.0.18"
|
|
50
50
|
},
|
|
@@ -54,6 +54,12 @@
|
|
|
54
54
|
"engines": {
|
|
55
55
|
"node": ">=20.19.0"
|
|
56
56
|
},
|
|
57
|
+
"devEngines": {
|
|
58
|
+
"runtime": {
|
|
59
|
+
"name": "node",
|
|
60
|
+
"version": ">=22.21.0"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
57
63
|
"scripts": {
|
|
58
64
|
"build": "tsdown --no-fixed-extension --tsconfig tsconfig.build.json",
|
|
59
65
|
"clean": "git rm -f pnpm-lock.yaml ; git clean -fdX",
|
package/readme.md
CHANGED
|
@@ -29,7 +29,7 @@ The plugin automatically generates both "light" and "dark" SVG variations of a t
|
|
|
29
29
|
|
|
30
30
|
Generated assets are intelligently hashed to aide in cache busting. For locally referenced files, the image will only be regenerated when the content in the source file changes.
|
|
31
31
|
|
|
32
|
-
The rule
|
|
32
|
+
The rule accepts either a path to a local `.tldr` file, or remote tldraw URLs.
|
|
33
33
|
|
|
34
34
|
The implementation is based on [@kitschpatrol/tldraw-cli](https://github.com/kitschpatrol/tldraw-cli), which depends on Puppeteer to generate the assets, so it can be a bit slow. Referencing local files instead of remote URLs is recommended for improved performance.
|
|
35
35
|
|