@kitschpatrol/unplugin-tldraw 1.1.1 → 1.1.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/api.js CHANGED
@@ -1,2 +1,2 @@
1
- import { r as resolveOptions, t as TldrawExport } from "./tldraw-C8VVllK_.js";
1
+ import { r as resolveOptions, t as TldrawExport } from "./tldraw--EsjzXjm.js";
2
2
  export { TldrawExport, resolveOptions };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as parseImportOverrides, t as TldrawExport } from "./tldraw-C8VVllK_.js";
1
+ import { n as parseImportOverrides, t as TldrawExport } from "./tldraw--EsjzXjm.js";
2
2
  import path from "node:path";
3
3
  import { createUnplugin } from "unplugin";
4
4
  //#region src/index.ts
@@ -19,8 +19,8 @@ const unpluginFactory = (options) => {
19
19
  const queryIndex = id.indexOf("?");
20
20
  const cleanId = queryIndex === -1 ? id : id.slice(0, queryIndex);
21
21
  const queryString = queryIndex === -1 ? "" : id.slice(queryIndex + 1);
22
- const resolvedPath = importer && (cleanId.startsWith("./") || cleanId.startsWith("../")) ? path.resolve(path.dirname(importer), cleanId) : cleanId;
23
- const overrides = queryString ? parseImportOverrides(queryString) : void 0;
22
+ const resolvedPath = importer !== void 0 && importer !== "" && (cleanId.startsWith("./") || cleanId.startsWith("../")) ? path.resolve(path.dirname(importer), cleanId) : cleanId;
23
+ const overrides = queryString === "" ? void 0 : parseImportOverrides(queryString);
24
24
  return tldrawExport.convert(resolvedPath, overrides);
25
25
  }
26
26
  },
@@ -38,39 +38,39 @@ function resolveOptions(options) {
38
38
  function parseImportOverrides(queryString) {
39
39
  const params = new URLSearchParams(queryString);
40
40
  const overrides = {};
41
- for (const [key, value] of params.entries()) {
42
- if (key === "tldr" || key === "tldraw") continue;
43
- switch (key) {
44
- case "dark":
45
- case "stripStyle":
46
- case "transparent":
47
- if (value === "true" || value === "") overrides[key] = true;
48
- else if (value === "false") overrides[key] = false;
49
- else log.warn(`Ignoring invalid value for "${key}": "${value}". Expected "true" or "false".`);
50
- break;
51
- case "format":
52
- overrides.format = value;
53
- break;
54
- case "frame":
55
- case "page":
56
- overrides[key] = value;
57
- break;
58
- case "padding":
59
- case "scale": {
60
- const numberValue = Number(value);
61
- if (!Number.isNaN(numberValue)) overrides[key] = numberValue;
62
- break;
63
- }
64
- default: break;
41
+ for (const [key, value] of params) applyOverride(overrides, key, value);
42
+ return overrides;
43
+ }
44
+ function applyOverride(overrides, key, value) {
45
+ switch (key) {
46
+ case "dark":
47
+ case "stripStyle":
48
+ case "transparent":
49
+ if (value === "true" || value === "") overrides[key] = true;
50
+ else if (value === "false") overrides[key] = false;
51
+ else log.warn(`Ignoring invalid value for "${key}": "${value}". Expected "true" or "false".`);
52
+ break;
53
+ case "format":
54
+ overrides.format = value;
55
+ break;
56
+ case "frame":
57
+ case "page":
58
+ overrides[key] = value;
59
+ break;
60
+ case "padding":
61
+ case "scale": {
62
+ const numberValue = Number(value);
63
+ if (!Number.isNaN(numberValue)) overrides[key] = numberValue;
64
+ break;
65
65
  }
66
+ default: break;
66
67
  }
67
- return overrides;
68
68
  }
69
69
  //#endregion
70
70
  //#region src/core/tldraw.ts
71
71
  const CACHE_FILE_NAME = ".tldraw-plugin-cache.json";
72
- const TLDR_EXTENSION_REGEX = /\.tldr(?:\?|$)/;
73
- const CACHE_HASH_REGEX = /-([a-f\d]{8})\.[^.]+$/;
72
+ const TLDR_EXTENSION_REGEX = /\.tldr(?:\?|$)/v;
73
+ const CACHE_HASH_REGEX = /-([a-f\d]{8})\.[^.]+$/v;
74
74
  var TldrawExport = class {
75
75
  /**
76
76
  * Pattern matching `.tldr` file imports. The `resolveId` hook filters on
@@ -165,7 +165,7 @@ var TldrawExport = class {
165
165
  async savePersistentCache() {
166
166
  if (!this.persistentCacheDirty) return;
167
167
  const cache = {};
168
- for (const [identifier, result] of this.resolvedCache.entries()) cache[this.toRelativeCacheKey(identifier)] = { result: toPosixPath(path.relative(this.options.cacheDirectory, result)) };
168
+ for (const [identifier, result] of this.resolvedCache) cache[this.toRelativeCacheKey(identifier)] = { result: toPosixPath(path.relative(this.options.cacheDirectory, result)) };
169
169
  await fs.writeFile(this.cacheFilePath, JSON.stringify(cache, void 0, 2));
170
170
  this.persistentCacheDirty = false;
171
171
  log.debug(`Saved ${this.resolvedCache.size} entries to persistent cache`);
@@ -206,8 +206,8 @@ var TldrawExport = class {
206
206
  if (frame !== void 0) tldrawCliOptions.frames = [frame];
207
207
  if (page !== void 0) tldrawCliOptions.pages = [page];
208
208
  try {
209
- const outputFile = (await tldrawToImage(absolutePath, tldrawCliOptions))[0];
210
- if (!outputFile) throw new Error(`tldraw-cli produced no output for "${absolutePath}"`);
209
+ const outputFile = (await tldrawToImage(absolutePath, tldrawCliOptions)).at(0);
210
+ if (outputFile === void 0) throw new Error(`tldraw-cli produced no output for "${absolutePath}"`);
211
211
  await fs.rename(outputFile, cachedFilePath);
212
212
  } finally {
213
213
  await fs.rm(tempOutputDirectory, {
@@ -233,13 +233,13 @@ var TldrawExport = class {
233
233
  async isFileHashCurrent(sourcePath, cachedResultPath, overrides) {
234
234
  if (!await fileExists(cachedResultPath)) return false;
235
235
  const cachedBasename = path.basename(cachedResultPath);
236
- const cachedHashMatch = CACHE_HASH_REGEX.exec(cachedBasename);
237
- if (!cachedHashMatch?.[1]) return false;
236
+ const cachedHash = CACHE_HASH_REGEX.exec(cachedBasename)?.[1];
237
+ if (cachedHash === void 0) return false;
238
238
  const { frame, page, ...imageOverrides } = overrides ?? {};
239
239
  const optionsForHash = { ...defu(imageOverrides, this.options.defaultImageOptions) };
240
240
  if (frame !== void 0) optionsForHash.frame = frame;
241
241
  if (page !== void 0) optionsForHash.page = page;
242
- return await computeCacheKey(sourcePath, optionsForHash) === cachedHashMatch[1];
242
+ return await computeCacheKey(sourcePath, optionsForHash) === cachedHash;
243
243
  }
244
244
  async loadPersistentCache() {
245
245
  try {
@@ -303,7 +303,7 @@ async function fileExists(filePath) {
303
303
  * replaces non-alphanumeric with hyphens, trims.
304
304
  */
305
305
  function slugify(text) {
306
- return text.toLowerCase().replaceAll(/[^\da-z]+/g, "-").replaceAll(/^-+|-+$/g, "");
306
+ return text.toLowerCase().replaceAll(/[^\da-z]+/gv, "-").replaceAll(/^-+|-+$/gv, "");
307
307
  }
308
308
  //#endregion
309
309
  export { parseImportOverrides as n, resolveOptions as r, TldrawExport as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitschpatrol/unplugin-tldraw",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Unplugin for module-style import of local tldraw .tldr files with automatic conversion to SVG or PNG.",
5
5
  "keywords": [
6
6
  "tldraw",
@@ -68,35 +68,35 @@
68
68
  "dist"
69
69
  ],
70
70
  "dependencies": {
71
- "@kitschpatrol/tldraw-cli": "^6.0.0",
71
+ "@kitschpatrol/tldraw-cli": "^6.0.1",
72
72
  "@types/node": "~22.19.19",
73
73
  "defu": "^6.1.7",
74
74
  "lognow": "^0.6.2",
75
75
  "p-limit": "^7.3.0",
76
76
  "pretty-bytes": "^7.1.0",
77
77
  "pretty-ms": "^9.3.0",
78
- "unplugin": "^3.0.0"
78
+ "unplugin": "^3.3.0"
79
79
  },
80
80
  "devDependencies": {
81
81
  "@farmfe/core": ">=1.7.11",
82
- "@kitschpatrol/shared-config": "^7.6.3",
83
- "@nuxt/kit": "^4.4.6",
84
- "@nuxt/schema": "^4.4.6",
85
- "@rspack/core": "^2.0.5",
82
+ "@kitschpatrol/shared-config": "^8.0.0",
83
+ "@nuxt/kit": "^4.4.8",
84
+ "@nuxt/schema": "^4.4.8",
85
+ "@rspack/core": "^2.1.1",
86
86
  "@sxzz/test-utils": "^0.5.18",
87
- "@vitest/browser-playwright": "^4.1.7",
87
+ "@vitest/browser-playwright": "^4.1.9",
88
88
  "bumpp": "^11.1.0",
89
89
  "esbuild": "*",
90
- "playwright": "^1.60.0",
90
+ "playwright": "^1.61.1",
91
91
  "poptab": "^1.1.1",
92
- "rolldown": "^1.0.3",
93
- "rollup": "^4.60.4",
92
+ "rolldown": "^1.1.3",
93
+ "rollup": "^4.62.2",
94
94
  "shx": "^0.4.0",
95
- "tsdown": "^0.22.1",
96
- "typescript": "~5.9.3",
97
- "vite": "^7.3.3",
98
- "vitest": "^4.1.7",
99
- "webpack": "^5.107.2"
95
+ "tsdown": "^0.22.3",
96
+ "typescript": "~6.0.3",
97
+ "vite": "^8.1.3",
98
+ "vitest": "^4.1.9",
99
+ "webpack": "^5.108.3"
100
100
  },
101
101
  "peerDependencies": {
102
102
  "@farmfe/core": ">=1",
@@ -141,6 +141,12 @@
141
141
  "engines": {
142
142
  "node": ">=22.22.2"
143
143
  },
144
+ "devEngines": {
145
+ "runtime": {
146
+ "name": "node",
147
+ "version": ">=24.16.0"
148
+ }
149
+ },
144
150
  "publishConfig": {
145
151
  "access": "public"
146
152
  },