mdat-plugin-tldraw 2.0.0 → 2.0.1

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.
Files changed (2) hide show
  1. package/dist/index.js +8 -9
  2. package/package.json +7 -7
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 markdownFilePath = context?.filePath ?? process.cwd();
15
- const assetsPath = path.resolve(path.dirname(markdownFilePath), destination);
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(markdownFilePath, possibleLightPath, possibleDarkPath, alt);
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(markdownFilePath, lightPathHashed, darkPathHashed, alt);
50
+ return getPictureElement(markdownDirectory, lightPathHashed, darkPathHashed, alt);
51
51
  } } };
52
- function getPictureElement(markdownFilePath, lightPath, darkPath, alt) {
53
- const basePath = path.dirname(markdownFilePath);
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(basePath, darkPath)}">
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.0",
3
+ "version": "2.0.1",
4
4
  "description": "Mdat plugin to embed tldraw diagrams in Markdown files.",
5
5
  "keywords": [
6
6
  "markdown",
@@ -35,16 +35,16 @@
35
35
  "dist/*"
36
36
  ],
37
37
  "dependencies": {
38
- "@kitschpatrol/tldraw-cli": "^5.0.13",
38
+ "@kitschpatrol/tldraw-cli": "^5.0.14",
39
39
  "path-type": "^6.0.0",
40
40
  "zod": "^4.3.6"
41
41
  },
42
42
  "devDependencies": {
43
- "@kitschpatrol/shared-config": "^7.0.0",
44
- "@types/node": "~20.19.37",
43
+ "@kitschpatrol/shared-config": "^7.0.1",
44
+ "@types/node": "~20.19.39",
45
45
  "bumpp": "^11.0.1",
46
- "mdat": "^2.0.0",
47
- "remark-mdat": "^2.0.0",
46
+ "mdat": "^2.1.0",
47
+ "remark-mdat": "^2.2.0",
48
48
  "tsdown": "^0.21.7",
49
49
  "typescript": "~5.9.3",
50
50
  "vitest": "^4.1.2"
@@ -68,6 +68,6 @@
68
68
  "fix": "ksc fix",
69
69
  "lint": "ksc lint",
70
70
  "release": "bumpp --commit 'Release: %s' && pnpm run build && NPM_AUTH_TOKEN=$(op read 'op://Personal/npm/token') && pnpm publish",
71
- "test": "vitest run --no-file-parallelism"
71
+ "test": "vitest run"
72
72
  }
73
73
  }