fix(excalidraw): resolve canvas module path and add canonical file location convention
Fix convert.mjs to resolve canvas from .export-runtime via createRequire instead of bare import (which resolves relative to script location, not CWD). Add File Location Convention section to SKILL.md — diagrams save .excalidraw source alongside PNGs in the project's image directory for easy re-export. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -4,13 +4,20 @@
|
||||
* Filters pseudo-elements, adds required defaults, expands labels into bound text.
|
||||
*/
|
||||
import { readFileSync, writeFileSync } from 'fs';
|
||||
import { dirname, join } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { createRequire } from 'module';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const runtimeRequire = createRequire(join(__dirname, '.export-runtime', 'package.json'));
|
||||
|
||||
// Canvas-based text measurement with graceful fallback to heuristic.
|
||||
// Excalidraw renders with Virgil (hand-drawn font); system sans-serif
|
||||
// is a reasonable proxy. The 1.1x multiplier accounts for Virgil being wider.
|
||||
let measureText;
|
||||
try {
|
||||
const { createCanvas } = await import('canvas');
|
||||
const canvas = runtimeRequire('canvas');
|
||||
const { createCanvas } = canvas;
|
||||
const cvs = createCanvas(1, 1);
|
||||
const ctx = cvs.getContext('2d');
|
||||
measureText = (text, fontSize) => {
|
||||
|
||||
Reference in New Issue
Block a user