vizmatic 0.1.17 → 0.1.18
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/cli.js +56 -25
- package/dist/index.cjs +32 -15
- package/dist/index.js +32 -15
- package/docs/assets/examples/rag-graph_dark.png +0 -0
- package/docs/assets/examples/rag-graph_light.png +0 -0
- package/docs/assets/examples/theme-background_dark.png +0 -0
- package/docs/assets/examples/theme-background_light.png +0 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -4946,7 +4946,7 @@ function cropPixels(pixels, srcWidth, region) {
|
|
|
4946
4946
|
}
|
|
4947
4947
|
return out;
|
|
4948
4948
|
}
|
|
4949
|
-
function detectOverflow(pixels, width, height, bgColor, edgeTolerance = 3, minDensity = 0.05, alphaThreshold =
|
|
4949
|
+
function detectOverflow(pixels, width, height, bgColor, edgeTolerance = 3, minDensity = 0.05, alphaThreshold = 10) {
|
|
4950
4950
|
const isBackground = createBackgroundMatcher(bgColor);
|
|
4951
4951
|
function isContentPixel(x, y) {
|
|
4952
4952
|
const idx = (y * width + x) * 4;
|
|
@@ -5228,20 +5228,37 @@ async function renderToPngInContext(element, options, createFn, theme) {
|
|
|
5228
5228
|
}
|
|
5229
5229
|
}
|
|
5230
5230
|
const watermark = resolveWatermark(options);
|
|
5231
|
-
const
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
|
|
5231
|
+
const renderFinalSvg = async (targetElement, targetWidth, targetHeight) => {
|
|
5232
|
+
const outputElement = watermark ? wrapWithWatermark(
|
|
5233
|
+
targetElement,
|
|
5234
|
+
targetWidth,
|
|
5235
|
+
targetHeight,
|
|
5236
|
+
theme || "dark",
|
|
5237
|
+
watermark
|
|
5238
|
+
) : targetElement;
|
|
5239
|
+
const renderedSvg = await satori(outputElement, {
|
|
5240
|
+
width: targetWidth,
|
|
5241
|
+
height: targetHeight,
|
|
5242
|
+
fonts,
|
|
5243
|
+
loadAdditionalAsset
|
|
5244
|
+
});
|
|
5245
|
+
return sanitizeSvg(renderedSvg);
|
|
5246
|
+
};
|
|
5247
|
+
let finalSvg = await renderFinalSvg(finalElement, finalWidth, finalHeight);
|
|
5248
|
+
if (finalHeight < options.height) {
|
|
5249
|
+
const cropCheck = new Resvg(finalSvg, {
|
|
5250
|
+
fitTo: { mode: "width", value: finalWidth },
|
|
5251
|
+
background: "rgba(0, 0, 0, 0)"
|
|
5252
|
+
}).render();
|
|
5253
|
+
const cropPixels2 = new Uint8Array(cropCheck.pixels.buffer);
|
|
5254
|
+
const cropBg = detectBackgroundColor(cropPixels2);
|
|
5255
|
+
const cropOverflow = detectOverflow(cropPixels2, finalWidth, cropCheck.height, cropBg);
|
|
5256
|
+
if (cropOverflow.overflows) {
|
|
5257
|
+
finalHeight = options.height;
|
|
5258
|
+
finalElement = element;
|
|
5259
|
+
finalSvg = await renderFinalSvg(finalElement, finalWidth, finalHeight);
|
|
5260
|
+
}
|
|
5261
|
+
}
|
|
5245
5262
|
const resvg = new Resvg(finalSvg, {
|
|
5246
5263
|
fitTo: {
|
|
5247
5264
|
mode: "width",
|
|
@@ -5558,13 +5575,24 @@ function resolveSelfEntry() {
|
|
|
5558
5575
|
return void 0;
|
|
5559
5576
|
}
|
|
5560
5577
|
}
|
|
5561
|
-
function
|
|
5562
|
-
|
|
5578
|
+
function resolveSelfImportEntry() {
|
|
5579
|
+
const moduleDir = dirname3(fileURLToPath2(import.meta.url));
|
|
5580
|
+
const bundledEntry = join2(moduleDir, "index.js");
|
|
5581
|
+
if (existsSync2(bundledEntry)) return bundledEntry;
|
|
5582
|
+
const sourceEntry = join2(moduleDir, "index.ts");
|
|
5583
|
+
if (existsSync2(sourceEntry)) return sourceEntry;
|
|
5584
|
+
return void 0;
|
|
5585
|
+
}
|
|
5586
|
+
function resolveSelfImportSpecifier() {
|
|
5587
|
+
return resolveSelfImportEntry() ?? "vizmatic";
|
|
5563
5588
|
}
|
|
5564
5589
|
function resolveReactRequireSpecifier() {
|
|
5565
5590
|
const reactEntry = resolveFrameDependency("react");
|
|
5566
5591
|
return reactEntry ?? "react";
|
|
5567
5592
|
}
|
|
5593
|
+
function resolveReactImportSpecifier() {
|
|
5594
|
+
return resolveReactRequireSpecifier();
|
|
5595
|
+
}
|
|
5568
5596
|
function resolveFrameDependency(request) {
|
|
5569
5597
|
try {
|
|
5570
5598
|
if (request === "vizmatic") return resolveSelfEntry();
|
|
@@ -5637,10 +5665,10 @@ function bareFrameExportsForSource(source) {
|
|
|
5637
5665
|
});
|
|
5638
5666
|
}
|
|
5639
5667
|
function buildAutoImportStatement(names) {
|
|
5640
|
-
const specifiers = names.map((name) => ` ${name}
|
|
5641
|
-
return `
|
|
5668
|
+
const specifiers = names.map((name) => ` ${name} as ${bareFrameAlias(name)}`).join(",\n");
|
|
5669
|
+
return `import {
|
|
5642
5670
|
${specifiers}
|
|
5643
|
-
}
|
|
5671
|
+
} from ${JSON.stringify(resolveSelfImportSpecifier())}`;
|
|
5644
5672
|
}
|
|
5645
5673
|
function buildAutoImportDeclarations(names) {
|
|
5646
5674
|
return names.map((name) => {
|
|
@@ -5684,9 +5712,7 @@ function buildBareFrameModule(framePath, source) {
|
|
|
5684
5712
|
height ??= frameHeight ?? DEFAULT_FRAME_HEIGHT;
|
|
5685
5713
|
const autoImports = bareFrameExportsForSource(body);
|
|
5686
5714
|
return `/** @jsxRuntime classic */
|
|
5687
|
-
import
|
|
5688
|
-
const __require = __createRequire(${JSON.stringify(import.meta.url)})
|
|
5689
|
-
const React = __require(${JSON.stringify(resolveReactRequireSpecifier())})
|
|
5715
|
+
import React from ${JSON.stringify(resolveReactImportSpecifier())}
|
|
5690
5716
|
${buildAutoImportStatement(autoImports)}
|
|
5691
5717
|
${imports.join("\n")}
|
|
5692
5718
|
|
|
@@ -5710,7 +5736,7 @@ ${setup}
|
|
|
5710
5736
|
return (${jsx})
|
|
5711
5737
|
}
|
|
5712
5738
|
|
|
5713
|
-
export default create
|
|
5739
|
+
export default { create, width, height }
|
|
5714
5740
|
`;
|
|
5715
5741
|
}
|
|
5716
5742
|
function isBareFrameSource(source) {
|
|
@@ -5726,6 +5752,7 @@ async function importBareFrame(filePath, source) {
|
|
|
5726
5752
|
if (!moduleSource) return void 0;
|
|
5727
5753
|
const tempDir = await mkdtemp(join2(tmpdir(), "vizmatic-frame-"));
|
|
5728
5754
|
const tempPath = join2(tempDir, `${basename(filePath).replace(/\.[^.]+$/, "")}.generated.tsx`);
|
|
5755
|
+
await writeFile3(join2(tempDir, "package.json"), '{"type":"module"}\n');
|
|
5729
5756
|
await writeFile3(tempPath, `${moduleSource}
|
|
5730
5757
|
`);
|
|
5731
5758
|
try {
|
|
@@ -6066,6 +6093,10 @@ async function main() {
|
|
|
6066
6093
|
}
|
|
6067
6094
|
}
|
|
6068
6095
|
main().catch((error) => {
|
|
6069
|
-
|
|
6096
|
+
if (process.env.VIZMATIC_DEBUG === "1" && error instanceof Error) {
|
|
6097
|
+
console.error(error.stack ?? error.message);
|
|
6098
|
+
} else {
|
|
6099
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
6100
|
+
}
|
|
6070
6101
|
process.exit(1);
|
|
6071
6102
|
});
|
package/dist/index.cjs
CHANGED
|
@@ -4960,7 +4960,7 @@ function cropPixels(pixels, srcWidth, region) {
|
|
|
4960
4960
|
}
|
|
4961
4961
|
return out;
|
|
4962
4962
|
}
|
|
4963
|
-
function detectOverflow(pixels, width, height, bgColor, edgeTolerance = 3, minDensity = 0.05, alphaThreshold =
|
|
4963
|
+
function detectOverflow(pixels, width, height, bgColor, edgeTolerance = 3, minDensity = 0.05, alphaThreshold = 10) {
|
|
4964
4964
|
const isBackground = createBackgroundMatcher(bgColor);
|
|
4965
4965
|
function isContentPixel(x, y) {
|
|
4966
4966
|
const idx = (y * width + x) * 4;
|
|
@@ -5243,20 +5243,37 @@ async function renderToPngInContext(element, options, createFn, theme) {
|
|
|
5243
5243
|
}
|
|
5244
5244
|
}
|
|
5245
5245
|
const watermark = resolveWatermark(options);
|
|
5246
|
-
const
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
|
|
5251
|
-
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5246
|
+
const renderFinalSvg = async (targetElement, targetWidth, targetHeight) => {
|
|
5247
|
+
const outputElement = watermark ? wrapWithWatermark(
|
|
5248
|
+
targetElement,
|
|
5249
|
+
targetWidth,
|
|
5250
|
+
targetHeight,
|
|
5251
|
+
theme || "dark",
|
|
5252
|
+
watermark
|
|
5253
|
+
) : targetElement;
|
|
5254
|
+
const renderedSvg = await satori(outputElement, {
|
|
5255
|
+
width: targetWidth,
|
|
5256
|
+
height: targetHeight,
|
|
5257
|
+
fonts,
|
|
5258
|
+
loadAdditionalAsset
|
|
5259
|
+
});
|
|
5260
|
+
return sanitizeSvg(renderedSvg);
|
|
5261
|
+
};
|
|
5262
|
+
let finalSvg = await renderFinalSvg(finalElement, finalWidth, finalHeight);
|
|
5263
|
+
if (finalHeight < options.height) {
|
|
5264
|
+
const cropCheck = new import_resvg_js.Resvg(finalSvg, {
|
|
5265
|
+
fitTo: { mode: "width", value: finalWidth },
|
|
5266
|
+
background: "rgba(0, 0, 0, 0)"
|
|
5267
|
+
}).render();
|
|
5268
|
+
const cropPixels2 = new Uint8Array(cropCheck.pixels.buffer);
|
|
5269
|
+
const cropBg = detectBackgroundColor(cropPixels2);
|
|
5270
|
+
const cropOverflow = detectOverflow(cropPixels2, finalWidth, cropCheck.height, cropBg);
|
|
5271
|
+
if (cropOverflow.overflows) {
|
|
5272
|
+
finalHeight = options.height;
|
|
5273
|
+
finalElement = element;
|
|
5274
|
+
finalSvg = await renderFinalSvg(finalElement, finalWidth, finalHeight);
|
|
5275
|
+
}
|
|
5276
|
+
}
|
|
5260
5277
|
const resvg = new import_resvg_js.Resvg(finalSvg, {
|
|
5261
5278
|
fitTo: {
|
|
5262
5279
|
mode: "width",
|
package/dist/index.js
CHANGED
|
@@ -4834,7 +4834,7 @@ function cropPixels(pixels, srcWidth, region) {
|
|
|
4834
4834
|
}
|
|
4835
4835
|
return out;
|
|
4836
4836
|
}
|
|
4837
|
-
function detectOverflow(pixels, width, height, bgColor, edgeTolerance = 3, minDensity = 0.05, alphaThreshold =
|
|
4837
|
+
function detectOverflow(pixels, width, height, bgColor, edgeTolerance = 3, minDensity = 0.05, alphaThreshold = 10) {
|
|
4838
4838
|
const isBackground = createBackgroundMatcher(bgColor);
|
|
4839
4839
|
function isContentPixel(x, y) {
|
|
4840
4840
|
const idx = (y * width + x) * 4;
|
|
@@ -5116,20 +5116,37 @@ async function renderToPngInContext(element, options, createFn, theme) {
|
|
|
5116
5116
|
}
|
|
5117
5117
|
}
|
|
5118
5118
|
const watermark = resolveWatermark(options);
|
|
5119
|
-
const
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
|
|
5132
|
-
|
|
5119
|
+
const renderFinalSvg = async (targetElement, targetWidth, targetHeight) => {
|
|
5120
|
+
const outputElement = watermark ? wrapWithWatermark(
|
|
5121
|
+
targetElement,
|
|
5122
|
+
targetWidth,
|
|
5123
|
+
targetHeight,
|
|
5124
|
+
theme || "dark",
|
|
5125
|
+
watermark
|
|
5126
|
+
) : targetElement;
|
|
5127
|
+
const renderedSvg = await satori(outputElement, {
|
|
5128
|
+
width: targetWidth,
|
|
5129
|
+
height: targetHeight,
|
|
5130
|
+
fonts,
|
|
5131
|
+
loadAdditionalAsset
|
|
5132
|
+
});
|
|
5133
|
+
return sanitizeSvg(renderedSvg);
|
|
5134
|
+
};
|
|
5135
|
+
let finalSvg = await renderFinalSvg(finalElement, finalWidth, finalHeight);
|
|
5136
|
+
if (finalHeight < options.height) {
|
|
5137
|
+
const cropCheck = new Resvg(finalSvg, {
|
|
5138
|
+
fitTo: { mode: "width", value: finalWidth },
|
|
5139
|
+
background: "rgba(0, 0, 0, 0)"
|
|
5140
|
+
}).render();
|
|
5141
|
+
const cropPixels2 = new Uint8Array(cropCheck.pixels.buffer);
|
|
5142
|
+
const cropBg = detectBackgroundColor(cropPixels2);
|
|
5143
|
+
const cropOverflow = detectOverflow(cropPixels2, finalWidth, cropCheck.height, cropBg);
|
|
5144
|
+
if (cropOverflow.overflows) {
|
|
5145
|
+
finalHeight = options.height;
|
|
5146
|
+
finalElement = element;
|
|
5147
|
+
finalSvg = await renderFinalSvg(finalElement, finalWidth, finalHeight);
|
|
5148
|
+
}
|
|
5149
|
+
}
|
|
5133
5150
|
const resvg = new Resvg(finalSvg, {
|
|
5134
5151
|
fitTo: {
|
|
5135
5152
|
mode: "width",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED