@kitschpatrol/unplugin-tldraw 1.0.0
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.d.ts +50 -0
- package/dist/api.js +2 -0
- package/dist/bun.d.ts +12 -0
- package/dist/bun.js +5 -0
- package/dist/client.d.ts +17 -0
- package/dist/esbuild.d.ts +21 -0
- package/dist/esbuild.js +20 -0
- package/dist/farm.d.ts +23 -0
- package/dist/farm.js +22 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +34 -0
- package/dist/nuxt.d.ts +17 -0
- package/dist/nuxt.js +30 -0
- package/dist/options-OhkbiFS8.d.ts +61 -0
- package/dist/rolldown.d.ts +23 -0
- package/dist/rolldown.js +22 -0
- package/dist/rollup.d.ts +23 -0
- package/dist/rollup.js +22 -0
- package/dist/rspack.d.ts +22 -0
- package/dist/rspack.js +22 -0
- package/dist/tldraw-ZdwazU9j.js +309 -0
- package/dist/vite.d.ts +23 -0
- package/dist/vite.js +22 -0
- package/dist/webpack.d.ts +23 -0
- package/dist/webpack.js +22 -0
- package/license.txt +21 -0
- package/package.json +148 -0
- package/readme.md +436 -0
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { defu } from "defu";
|
|
2
|
+
import { log, setDefaultLogOptions } from "lognow";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { tldrawToImage } from "@kitschpatrol/tldraw-cli";
|
|
5
|
+
import crypto from "node:crypto";
|
|
6
|
+
import fs from "node:fs/promises";
|
|
7
|
+
import pLimit from "p-limit";
|
|
8
|
+
import prettyBytes from "pretty-bytes";
|
|
9
|
+
import prettyMilliseconds from "pretty-ms";
|
|
10
|
+
//#region src/core/options.ts
|
|
11
|
+
const DEFAULT_OPTIONS = {
|
|
12
|
+
cacheDirectory: "./node_modules/.cache/tldraw",
|
|
13
|
+
cacheEnabled: true,
|
|
14
|
+
defaultImageOptions: {
|
|
15
|
+
dark: false,
|
|
16
|
+
format: "svg",
|
|
17
|
+
padding: 32,
|
|
18
|
+
scale: 1,
|
|
19
|
+
stripStyle: false,
|
|
20
|
+
transparent: false
|
|
21
|
+
},
|
|
22
|
+
maxConcurrentConversions: 2,
|
|
23
|
+
pruneCacheOnBuild: false,
|
|
24
|
+
verbose: false
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Resolve and normalize user options.
|
|
28
|
+
*/
|
|
29
|
+
function resolveOptions(options) {
|
|
30
|
+
const resolved = defu(options, DEFAULT_OPTIONS);
|
|
31
|
+
resolved.cacheDirectory = path.resolve(resolved.cacheDirectory);
|
|
32
|
+
return resolved;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Parse query params from an import path into per-import overrides.
|
|
36
|
+
* Converts string values to appropriate types (booleans, numbers).
|
|
37
|
+
*/
|
|
38
|
+
function parseImportOverrides(queryString) {
|
|
39
|
+
const params = new URLSearchParams(queryString);
|
|
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;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return overrides;
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/core/tldraw.ts
|
|
71
|
+
const CACHE_FILE_NAME = ".tldraw-plugin-cache.json";
|
|
72
|
+
const TLDR_EXTENSION_REGEX = /\.tldr(?:\?|$)/;
|
|
73
|
+
const CACHE_HASH_REGEX = /-([a-f\d]{8})\.[^.]+$/;
|
|
74
|
+
var TldrawExport = class {
|
|
75
|
+
/**
|
|
76
|
+
* Pattern matching `.tldr` file imports. The `resolveId` hook filters on
|
|
77
|
+
* this.
|
|
78
|
+
*/
|
|
79
|
+
get identifierPattern() {
|
|
80
|
+
return TLDR_EXTENSION_REGEX;
|
|
81
|
+
}
|
|
82
|
+
convertLimit;
|
|
83
|
+
options;
|
|
84
|
+
pathsSeen = /* @__PURE__ */ new Set();
|
|
85
|
+
pendingRequests = /* @__PURE__ */ new Map();
|
|
86
|
+
persistentCacheDirty = false;
|
|
87
|
+
resolvedCache = /* @__PURE__ */ new Map();
|
|
88
|
+
get cacheFilePath() {
|
|
89
|
+
return path.join(this.options.cacheDirectory, CACHE_FILE_NAME);
|
|
90
|
+
}
|
|
91
|
+
constructor(options) {
|
|
92
|
+
this.options = resolveOptions(options);
|
|
93
|
+
this.convertLimit = pLimit(this.options.maxConcurrentConversions);
|
|
94
|
+
setDefaultLogOptions({
|
|
95
|
+
name: "unplugin-tldraw",
|
|
96
|
+
verbose: this.options.verbose
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Converts a `.tldr` file to an image and returns the absolute path of the
|
|
101
|
+
* cached image. Uses caching, request deduplication, and concurrency
|
|
102
|
+
* limiting.
|
|
103
|
+
*
|
|
104
|
+
* @param tldrPath - Absolute or relative path to the `.tldr` file.
|
|
105
|
+
* @param overrides - Per-import option overrides (from query params).
|
|
106
|
+
*/
|
|
107
|
+
async convert(tldrPath, overrides) {
|
|
108
|
+
const absolutePath = path.resolve(tldrPath);
|
|
109
|
+
const cacheKey = overrides && Object.keys(overrides).length > 0 ? `${absolutePath}?${stableStringify(overrides)}` : absolutePath;
|
|
110
|
+
if (this.options.cacheEnabled) {
|
|
111
|
+
const cached = this.resolvedCache.get(cacheKey);
|
|
112
|
+
if (cached !== void 0) {
|
|
113
|
+
if (await this.isFileHashCurrent(absolutePath, cached, overrides)) {
|
|
114
|
+
log.debug(`Cache hit for "${this.relativePath(absolutePath)}"`);
|
|
115
|
+
if (this.options.pruneCacheOnBuild) this.pathsSeen.add(cached);
|
|
116
|
+
return cached;
|
|
117
|
+
}
|
|
118
|
+
this.resolvedCache.delete(cacheKey);
|
|
119
|
+
this.persistentCacheDirty = true;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const pending = this.pendingRequests.get(cacheKey);
|
|
123
|
+
if (pending !== void 0) {
|
|
124
|
+
log.debug(`Waiting for in-flight conversion of "${this.relativePath(absolutePath)}"`);
|
|
125
|
+
return pending;
|
|
126
|
+
}
|
|
127
|
+
const convertPromise = this.convertLimit(async () => this.doConvert(absolutePath, overrides));
|
|
128
|
+
this.pendingRequests.set(cacheKey, convertPromise);
|
|
129
|
+
try {
|
|
130
|
+
const result = await convertPromise;
|
|
131
|
+
this.resolvedCache.set(cacheKey, result);
|
|
132
|
+
this.persistentCacheDirty = true;
|
|
133
|
+
await this.savePersistentCache();
|
|
134
|
+
return result;
|
|
135
|
+
} finally {
|
|
136
|
+
this.pendingRequests.delete(cacheKey);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Initialize the cache directory and load persistent cache from disk.
|
|
141
|
+
*/
|
|
142
|
+
async initialize() {
|
|
143
|
+
await fs.mkdir(this.options.cacheDirectory, { recursive: true });
|
|
144
|
+
await this.loadPersistentCache();
|
|
145
|
+
log.debug(`Initialized with cache at "${this.options.cacheDirectory}"`);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Delete cached files that were not used during this build.
|
|
149
|
+
*/
|
|
150
|
+
async pruneCache() {
|
|
151
|
+
if (!this.options.pruneCacheOnBuild) return;
|
|
152
|
+
const destinationFiles = await fs.readdir(this.options.cacheDirectory);
|
|
153
|
+
const fileNamesToKeep = new Set(Array.from(this.pathsSeen, (filePath) => path.basename(filePath)));
|
|
154
|
+
for (const destinationFile of destinationFiles) {
|
|
155
|
+
if (destinationFile === CACHE_FILE_NAME) continue;
|
|
156
|
+
if (!fileNamesToKeep.has(destinationFile)) {
|
|
157
|
+
log.debug(`Cleaning up unused image: ${destinationFile}`);
|
|
158
|
+
await fs.rm(path.join(this.options.cacheDirectory, destinationFile));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Persist the in-memory cache to disk.
|
|
164
|
+
*/
|
|
165
|
+
async savePersistentCache() {
|
|
166
|
+
if (!this.persistentCacheDirty) return;
|
|
167
|
+
const cache = {};
|
|
168
|
+
for (const [identifier, result] of this.resolvedCache.entries()) cache[this.toRelativeCacheKey(identifier)] = { result: toPosixPath(path.relative(this.options.cacheDirectory, result)) };
|
|
169
|
+
await fs.writeFile(this.cacheFilePath, JSON.stringify(cache, void 0, 2));
|
|
170
|
+
this.persistentCacheDirty = false;
|
|
171
|
+
log.debug(`Saved ${this.resolvedCache.size} entries to persistent cache`);
|
|
172
|
+
}
|
|
173
|
+
async doConvert(absolutePath, overrides) {
|
|
174
|
+
const startTime = performance.now();
|
|
175
|
+
const { frame, page, ...imageOverrides } = overrides ?? {};
|
|
176
|
+
const mergedImageOptions = defu(imageOverrides, this.options.defaultImageOptions);
|
|
177
|
+
const { format } = mergedImageOptions;
|
|
178
|
+
const optionsForHash = { ...mergedImageOptions };
|
|
179
|
+
if (frame !== void 0) optionsForHash.frame = frame;
|
|
180
|
+
if (page !== void 0) optionsForHash.page = page;
|
|
181
|
+
const contentHash = await computeCacheKey(absolutePath, optionsForHash);
|
|
182
|
+
const slugParts = [path.basename(absolutePath, ".tldr")];
|
|
183
|
+
if (page !== void 0) slugParts.push(slugify(page));
|
|
184
|
+
if (frame !== void 0) slugParts.push(slugify(frame));
|
|
185
|
+
slugParts.push(contentHash);
|
|
186
|
+
const cachedFileName = `${slugParts.filter(Boolean).join("-")}.${format}`;
|
|
187
|
+
const cachedFilePath = path.join(this.options.cacheDirectory, cachedFileName);
|
|
188
|
+
if (this.options.cacheEnabled && await fileExists(cachedFilePath)) {
|
|
189
|
+
log.debug(`Disk cache hit for "${this.relativePath(absolutePath)}" → "${cachedFileName}"`);
|
|
190
|
+
if (this.options.pruneCacheOnBuild) this.pathsSeen.add(cachedFilePath);
|
|
191
|
+
return cachedFilePath;
|
|
192
|
+
}
|
|
193
|
+
log.debug(`Converting "${this.relativePath(absolutePath)}"...`);
|
|
194
|
+
await fs.mkdir(this.options.cacheDirectory, { recursive: true });
|
|
195
|
+
const tempOutputDirectory = path.join(this.options.cacheDirectory, `.tmp-${crypto.randomUUID()}`);
|
|
196
|
+
await fs.mkdir(tempOutputDirectory, { recursive: true });
|
|
197
|
+
const tldrawCliOptions = {
|
|
198
|
+
dark: mergedImageOptions.dark,
|
|
199
|
+
format,
|
|
200
|
+
output: tempOutputDirectory,
|
|
201
|
+
padding: mergedImageOptions.padding,
|
|
202
|
+
scale: mergedImageOptions.scale,
|
|
203
|
+
stripStyle: mergedImageOptions.stripStyle,
|
|
204
|
+
transparent: mergedImageOptions.transparent
|
|
205
|
+
};
|
|
206
|
+
if (frame !== void 0) tldrawCliOptions.frames = [frame];
|
|
207
|
+
if (page !== void 0) tldrawCliOptions.pages = [page];
|
|
208
|
+
try {
|
|
209
|
+
const outputFile = (await tldrawToImage(absolutePath, tldrawCliOptions))[0];
|
|
210
|
+
if (!outputFile) throw new Error(`tldraw-cli produced no output for "${absolutePath}"`);
|
|
211
|
+
await fs.rename(outputFile, cachedFilePath);
|
|
212
|
+
} finally {
|
|
213
|
+
await fs.rm(tempOutputDirectory, {
|
|
214
|
+
force: true,
|
|
215
|
+
recursive: true
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
if (this.options.pruneCacheOnBuild) this.pathsSeen.add(cachedFilePath);
|
|
219
|
+
const elapsed = prettyMilliseconds(performance.now() - startTime);
|
|
220
|
+
const fileSize = prettyBytes((await fs.stat(cachedFilePath)).size);
|
|
221
|
+
log.debug(`Converted in ${elapsed} (${fileSize}) → "${cachedFileName}"`);
|
|
222
|
+
return cachedFilePath;
|
|
223
|
+
}
|
|
224
|
+
fromRelativeCacheKey(relativeKey) {
|
|
225
|
+
const queryIndex = relativeKey.indexOf("?");
|
|
226
|
+
const relativePath = queryIndex === -1 ? relativeKey : relativeKey.slice(0, queryIndex);
|
|
227
|
+
const query = queryIndex === -1 ? "" : relativeKey.slice(queryIndex);
|
|
228
|
+
return path.resolve(this.options.cacheDirectory, relativePath) + query;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Checks if a cached result still matches the source file's content hash.
|
|
232
|
+
*/
|
|
233
|
+
async isFileHashCurrent(sourcePath, cachedResultPath, overrides) {
|
|
234
|
+
if (!await fileExists(cachedResultPath)) return false;
|
|
235
|
+
const cachedBasename = path.basename(cachedResultPath);
|
|
236
|
+
const cachedHashMatch = CACHE_HASH_REGEX.exec(cachedBasename);
|
|
237
|
+
if (!cachedHashMatch?.[1]) return false;
|
|
238
|
+
const { frame, page, ...imageOverrides } = overrides ?? {};
|
|
239
|
+
const optionsForHash = { ...defu(imageOverrides, this.options.defaultImageOptions) };
|
|
240
|
+
if (frame !== void 0) optionsForHash.frame = frame;
|
|
241
|
+
if (page !== void 0) optionsForHash.page = page;
|
|
242
|
+
return await computeCacheKey(sourcePath, optionsForHash) === cachedHashMatch[1];
|
|
243
|
+
}
|
|
244
|
+
async loadPersistentCache() {
|
|
245
|
+
try {
|
|
246
|
+
const cacheContent = await fs.readFile(this.cacheFilePath, "utf8");
|
|
247
|
+
const cache = JSON.parse(cacheContent);
|
|
248
|
+
let validEntries = 0;
|
|
249
|
+
let staleEntries = 0;
|
|
250
|
+
for (const [relativeIdentifier, entry] of Object.entries(cache)) {
|
|
251
|
+
const absoluteIdentifier = this.fromRelativeCacheKey(relativeIdentifier);
|
|
252
|
+
const absoluteResult = path.resolve(this.options.cacheDirectory, entry.result);
|
|
253
|
+
if (await fileExists(absoluteResult)) {
|
|
254
|
+
this.resolvedCache.set(absoluteIdentifier, absoluteResult);
|
|
255
|
+
validEntries++;
|
|
256
|
+
} else {
|
|
257
|
+
this.persistentCacheDirty = true;
|
|
258
|
+
staleEntries++;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
if (staleEntries > 0) log.debug(`Removed ${staleEntries} stale entries from cache (files no longer exist on disk)`);
|
|
262
|
+
log.debug(`Loaded ${validEntries} entries from persistent cache`);
|
|
263
|
+
} catch {}
|
|
264
|
+
}
|
|
265
|
+
relativePath(absolutePath) {
|
|
266
|
+
return path.relative(process.cwd(), absolutePath);
|
|
267
|
+
}
|
|
268
|
+
toRelativeCacheKey(absoluteKey) {
|
|
269
|
+
const queryIndex = absoluteKey.indexOf("?");
|
|
270
|
+
const absolutePath = queryIndex === -1 ? absoluteKey : absoluteKey.slice(0, queryIndex);
|
|
271
|
+
const query = queryIndex === -1 ? "" : absoluteKey.slice(queryIndex);
|
|
272
|
+
return toPosixPath(path.relative(this.options.cacheDirectory, absolutePath)) + query;
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
async function computeCacheKey(filePath, options) {
|
|
276
|
+
const fileBuffer = await fs.readFile(filePath);
|
|
277
|
+
const hash = crypto.createHash("sha1");
|
|
278
|
+
hash.update(fileBuffer);
|
|
279
|
+
hash.update(stableStringify(options));
|
|
280
|
+
return hash.digest("hex").slice(0, 8);
|
|
281
|
+
}
|
|
282
|
+
function stableStringify(value) {
|
|
283
|
+
return JSON.stringify(value, Object.keys(value).toSorted());
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Convert a native path string to POSIX form. No-op on POSIX. Used when
|
|
287
|
+
* persisting paths to disk so the cache file is portable across OSes.
|
|
288
|
+
*/
|
|
289
|
+
function toPosixPath(p) {
|
|
290
|
+
return p.split(path.sep).join("/");
|
|
291
|
+
}
|
|
292
|
+
async function fileExists(filePath) {
|
|
293
|
+
try {
|
|
294
|
+
await fs.access(filePath);
|
|
295
|
+
return true;
|
|
296
|
+
} catch (error) {
|
|
297
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") return false;
|
|
298
|
+
throw error;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Simple slugify for frame/page names in filenames. Converts to lowercase,
|
|
303
|
+
* replaces non-alphanumeric with hyphens, trims.
|
|
304
|
+
*/
|
|
305
|
+
function slugify(text) {
|
|
306
|
+
return text.toLowerCase().replaceAll(/[^\da-z]+/g, "-").replaceAll(/^-+|-+$/g, "");
|
|
307
|
+
}
|
|
308
|
+
//#endregion
|
|
309
|
+
export { parseImportOverrides as n, resolveOptions as r, TldrawExport as t };
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { n as Options } from "./options-OhkbiFS8.js";
|
|
2
|
+
import * as _$vite from "vite";
|
|
3
|
+
|
|
4
|
+
//#region src/vite.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* This entry file is for Vite plugin.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Vite plugin
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // vite.config.ts
|
|
15
|
+
* import tldraw from '@kitschpatrol/unplugin-tldraw/vite'
|
|
16
|
+
*
|
|
17
|
+
* export default defineConfig({
|
|
18
|
+
* plugins: [tldraw()],
|
|
19
|
+
* })
|
|
20
|
+
*/
|
|
21
|
+
declare const _default: (options?: Options | undefined) => _$vite.Plugin<any> | _$vite.Plugin<any>[];
|
|
22
|
+
//#endregion
|
|
23
|
+
export { _default as default };
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { unpluginFactory } from "./index.js";
|
|
2
|
+
import { createVitePlugin } from "unplugin";
|
|
3
|
+
//#region src/vite.ts
|
|
4
|
+
/**
|
|
5
|
+
* This entry file is for Vite plugin.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Vite plugin
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // vite.config.ts
|
|
14
|
+
* import tldraw from '@kitschpatrol/unplugin-tldraw/vite'
|
|
15
|
+
*
|
|
16
|
+
* export default defineConfig({
|
|
17
|
+
* plugins: [tldraw()],
|
|
18
|
+
* })
|
|
19
|
+
*/
|
|
20
|
+
var vite_default = createVitePlugin(unpluginFactory);
|
|
21
|
+
//#endregion
|
|
22
|
+
export { vite_default as default };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { n as Options } from "./options-OhkbiFS8.js";
|
|
2
|
+
import * as _$webpack from "webpack";
|
|
3
|
+
|
|
4
|
+
//#region src/webpack.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* This entry file is for webpack plugin.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Webpack plugin
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // webpack.config.js
|
|
15
|
+
* import tldraw from '@kitschpatrol/unplugin-tldraw/webpack'
|
|
16
|
+
*
|
|
17
|
+
* export default {
|
|
18
|
+
* plugins: [tldraw()],
|
|
19
|
+
* }
|
|
20
|
+
*/
|
|
21
|
+
declare const _default: (options?: Options | undefined) => _$webpack.WebpackPluginInstance;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { _default as default };
|
package/dist/webpack.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { unpluginFactory } from "./index.js";
|
|
2
|
+
import { createWebpackPlugin } from "unplugin";
|
|
3
|
+
//#region src/webpack.ts
|
|
4
|
+
/**
|
|
5
|
+
* This entry file is for webpack plugin.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Webpack plugin
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // webpack.config.js
|
|
14
|
+
* import tldraw from '@kitschpatrol/unplugin-tldraw/webpack'
|
|
15
|
+
*
|
|
16
|
+
* export default {
|
|
17
|
+
* plugins: [tldraw()],
|
|
18
|
+
* }
|
|
19
|
+
*/
|
|
20
|
+
var webpack_default = createWebpackPlugin(unpluginFactory);
|
|
21
|
+
//#endregion
|
|
22
|
+
export { webpack_default as default };
|
package/license.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Eric Mika
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kitschpatrol/unplugin-tldraw",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Unplugin for module-style import of local tldraw .tldr files with automatic conversion to SVG or PNG.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"tldraw",
|
|
7
|
+
"tldr",
|
|
8
|
+
"unplugin",
|
|
9
|
+
"vite",
|
|
10
|
+
"webpack",
|
|
11
|
+
"rspack",
|
|
12
|
+
"rollup",
|
|
13
|
+
"rolldown",
|
|
14
|
+
"esbuild",
|
|
15
|
+
"farm",
|
|
16
|
+
"bun",
|
|
17
|
+
"nuxt",
|
|
18
|
+
"diagram",
|
|
19
|
+
"drawing",
|
|
20
|
+
"whiteboard",
|
|
21
|
+
"sketch",
|
|
22
|
+
"import",
|
|
23
|
+
"npm-package"
|
|
24
|
+
],
|
|
25
|
+
"homepage": "https://github.com/kitschpatrol/unplugin-tldraw",
|
|
26
|
+
"bugs": "https://github.com/kitschpatrol/unplugin-tldraw/issues",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/kitschpatrol/unplugin-tldraw.git"
|
|
30
|
+
},
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"author": {
|
|
33
|
+
"name": "Eric Mika",
|
|
34
|
+
"email": "eric@ericmika.com",
|
|
35
|
+
"url": "https://ericmika.com"
|
|
36
|
+
},
|
|
37
|
+
"sideEffects": false,
|
|
38
|
+
"type": "module",
|
|
39
|
+
"exports": {
|
|
40
|
+
".": "./dist/index.js",
|
|
41
|
+
"./*": "./*",
|
|
42
|
+
"./api": "./dist/api.js",
|
|
43
|
+
"./bun": "./dist/bun.js",
|
|
44
|
+
"./client": {
|
|
45
|
+
"types": "./dist/client.d.ts"
|
|
46
|
+
},
|
|
47
|
+
"./esbuild": "./dist/esbuild.js",
|
|
48
|
+
"./farm": "./dist/farm.js",
|
|
49
|
+
"./nuxt": "./dist/nuxt.js",
|
|
50
|
+
"./rolldown": "./dist/rolldown.js",
|
|
51
|
+
"./rollup": "./dist/rollup.js",
|
|
52
|
+
"./rspack": "./dist/rspack.js",
|
|
53
|
+
"./vite": "./dist/vite.js",
|
|
54
|
+
"./webpack": "./dist/webpack.js"
|
|
55
|
+
},
|
|
56
|
+
"main": "./dist/index.js",
|
|
57
|
+
"module": "./dist/index.js",
|
|
58
|
+
"types": "./dist/index.d.ts",
|
|
59
|
+
"typesVersions": {
|
|
60
|
+
"*": {
|
|
61
|
+
"*": [
|
|
62
|
+
"./dist/*",
|
|
63
|
+
"./*"
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"files": [
|
|
68
|
+
"dist"
|
|
69
|
+
],
|
|
70
|
+
"dependencies": {
|
|
71
|
+
"@kitschpatrol/tldraw-cli": "^5.0.16",
|
|
72
|
+
"@types/node": "~22.18.13",
|
|
73
|
+
"defu": "^6.1.7",
|
|
74
|
+
"lognow": "^0.6.1",
|
|
75
|
+
"p-limit": "^7.3.0",
|
|
76
|
+
"pretty-bytes": "^7.1.0",
|
|
77
|
+
"pretty-ms": "^9.3.0",
|
|
78
|
+
"unplugin": "^3.0.0"
|
|
79
|
+
},
|
|
80
|
+
"devDependencies": {
|
|
81
|
+
"@farmfe/core": ">=1.7.11",
|
|
82
|
+
"@kitschpatrol/shared-config": "^7.5.1",
|
|
83
|
+
"@nuxt/kit": "^3.21.2",
|
|
84
|
+
"@nuxt/schema": "^3.21.2",
|
|
85
|
+
"@sxzz/test-utils": "^0.5.18",
|
|
86
|
+
"@vitest/browser-playwright": "^4.1.5",
|
|
87
|
+
"bumpp": "^11.0.1",
|
|
88
|
+
"esbuild": "*",
|
|
89
|
+
"playwright": "^1.59.1",
|
|
90
|
+
"poptab": "^1.1.0",
|
|
91
|
+
"rollup": "^4.60.2",
|
|
92
|
+
"shx": "^0.4.0",
|
|
93
|
+
"tsdown": "^0.21.10",
|
|
94
|
+
"typescript": "~5.9.3",
|
|
95
|
+
"vite": "^7.3.2",
|
|
96
|
+
"vitest": "^4.1.5",
|
|
97
|
+
"webpack": "^5.106.2"
|
|
98
|
+
},
|
|
99
|
+
"peerDependencies": {
|
|
100
|
+
"@farmfe/core": ">=1",
|
|
101
|
+
"@nuxt/kit": "^3",
|
|
102
|
+
"@nuxt/schema": "^3",
|
|
103
|
+
"esbuild": "*",
|
|
104
|
+
"rollup": "^3",
|
|
105
|
+
"vite": ">=3",
|
|
106
|
+
"webpack": "^4 || ^5"
|
|
107
|
+
},
|
|
108
|
+
"peerDependenciesMeta": {
|
|
109
|
+
"@farmfe/core": {
|
|
110
|
+
"optional": true
|
|
111
|
+
},
|
|
112
|
+
"@nuxt/kit": {
|
|
113
|
+
"optional": true
|
|
114
|
+
},
|
|
115
|
+
"@nuxt/schema": {
|
|
116
|
+
"optional": true
|
|
117
|
+
},
|
|
118
|
+
"esbuild": {
|
|
119
|
+
"optional": true
|
|
120
|
+
},
|
|
121
|
+
"rollup": {
|
|
122
|
+
"optional": true
|
|
123
|
+
},
|
|
124
|
+
"vite": {
|
|
125
|
+
"optional": true
|
|
126
|
+
},
|
|
127
|
+
"webpack": {
|
|
128
|
+
"optional": true
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
"engines": {
|
|
132
|
+
"node": ">=22.18.0"
|
|
133
|
+
},
|
|
134
|
+
"publishConfig": {
|
|
135
|
+
"access": "public"
|
|
136
|
+
},
|
|
137
|
+
"scripts": {
|
|
138
|
+
"build": "tsdown",
|
|
139
|
+
"clean": "shx rm -f pnpm-lock.yaml && git clean -fdX -e !.claude/",
|
|
140
|
+
"dev": "tsdown --watch",
|
|
141
|
+
"fix": "ksc fix",
|
|
142
|
+
"lint": "ksc lint",
|
|
143
|
+
"play": "poptab && pnpm -C playground run dev",
|
|
144
|
+
"release": "bumpp --commit 'Release: %s' && pnpm build && NPM_AUTH_TOKEN=$(op read 'op://Personal/npm/token') && pnpm publish",
|
|
145
|
+
"test": "vitest run",
|
|
146
|
+
"test:browser": "vitest run --config vitest.browser.config.ts"
|
|
147
|
+
}
|
|
148
|
+
}
|