vizmatic 0.1.19 → 0.1.21

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/PROMPT.md CHANGED
@@ -333,7 +333,7 @@ Theme and render APIs:
333
333
  - `WatermarkInput`: `boolean | string | WatermarkOptions | ReactElement<WatermarkElementProps>`. `true` uses Vizmatic defaults. A string sets the watermark text. A React element can be `<Watermark>...</Watermark>` or any custom element.
334
334
  - `WatermarkImageOptions`: `src`, `width?: number`, `height?: number`, `alt?: string`. Programmatic `src` should be a URL or data URI. CLI `--watermark-image` accepts URL, data URI, or local path.
335
335
  - `WatermarkOptions`: `text?: string | false`, `image?: string | WatermarkImageOptions`, `icon?: ReactNode | string | false`, `element?: ReactNode`, `position?: "top-left" | "top-right" | "bottom-left" | "bottom-right" = "top-right"`, `opacity?: number`, `color?: string`.
336
- - `RenderOptions`: `width`, `height`, `outputPath`, `background?: "transparent" | "theme" | CSS color = "transparent"`, `watermark?: WatermarkInput`, `brand?: boolean | string` as a compatibility alias, `crop?: boolean = true`, `scale?: number = 2`.
336
+ - `RenderOptions`: `width`, `height`, `outputPath`, `background?: "transparent" | "theme" | CSS color = "transparent"`, `watermark?: WatermarkInput`, `brand?: boolean | string` as a compatibility alias, `crop?: boolean | "height" | "both" = true`, `scale?: number = 2`. Use `crop: "height"` when host layouts require stable width but should still trim extra vertical whitespace.
337
337
  - `renderToBuffer(element, width, height, options?)`: `options` supports `background?`, `watermark?`, `brand?`, `scale?`.
338
338
  - `renderToSvg(element, width, height, options?)`: `options` supports `background?`, `watermark?`, `brand?`.
339
339
  - `renderAnimatedGif(scenes, options)`: `scenes: AnimatedScene[]`, `options: AnimationOptions`.
package/README.md CHANGED
@@ -571,7 +571,7 @@ Vizmatic exports a fairly complete visual kit. Common cases should use these pri
571
571
  import { renderAnimatedGif, renderToPng, renderToBuffer, renderToSvg } from "vizmatic"
572
572
  ```
573
573
 
574
- `renderToPng` renders at 2x scale by default, uses alpha transparency unless `background` is set, checks for clipped content, crops extra vertical whitespace, and can apply an optional watermark. Use `background: "theme"` to paint `c.bg`, or any CSS color string for a fixed fill. Use `watermark.image` for a URL or data URI; the CLI also accepts local image paths through `--watermark-image`. For frame-owned branding, export `watermark = <Watermark>...</Watermark>` from the frame module. `brand` still works as a compatibility alias.
574
+ `renderToPng` renders at 2x scale by default, uses alpha transparency unless `background` is set, checks for clipped content, crops extra vertical whitespace, and can apply an optional watermark. Use `background: "theme"` to paint `c.bg`, or any CSS color string for a fixed fill. Use `crop: "height"` when a downstream layout needs fixed width but still wants vertical whitespace trimmed. Use `watermark.image` for a URL or data URI; the CLI also accepts local image paths through `--watermark-image`. For frame-owned branding, export `watermark = <Watermark>...</Watermark>` from the frame module. `brand` still works as a compatibility alias.
575
575
 
576
576
  ```ts
577
577
  await renderToPng(element, {
@@ -580,7 +580,7 @@ await renderToPng(element, {
580
580
  outputPath: "dist/frame.png",
581
581
  background: "theme",
582
582
  watermark: { text: "Your Product", image: "https://example.com/logo.svg", position: "top-right" },
583
- crop: true,
583
+ crop: "height",
584
584
  scale: 2,
585
585
  })
586
586
  ```
package/dist/cli.js CHANGED
@@ -4153,10 +4153,13 @@ function LineChart({
4153
4153
  const allValues = series.flatMap((item) => item.points);
4154
4154
  const domain = chartDomain(allValues, min, max);
4155
4155
  const maxPoints = Math.max(...series.map((item) => item.points.length), 1);
4156
- const xStep = maxPoints <= 1 ? plot.innerWidth : plot.innerWidth / (maxPoints - 1);
4156
+ const xInset = maxPoints <= 1 ? 0 : Math.min(26, Math.max(14, plot.innerWidth * 0.06));
4157
+ const xStart = maxPoints <= 1 ? plot.x + plot.innerWidth / 2 : plot.x + xInset;
4158
+ const xSpan = maxPoints <= 1 ? 0 : Math.max(1, plot.innerWidth - xInset * 2);
4159
+ const xStep = maxPoints <= 1 ? 0 : xSpan / (maxPoints - 1);
4157
4160
  const ticks = chartTicks(domain.min, domain.max, 4);
4158
4161
  const pointFor = (value, index) => {
4159
- const x = plot.x + index * xStep;
4162
+ const x = xStart + index * xStep;
4160
4163
  const y = yInPlot(value, domain, plot);
4161
4164
  return { x, y };
4162
4165
  };
@@ -4199,7 +4202,12 @@ function LineChart({
4199
4202
  if (item.points.length === 0) return [];
4200
4203
  const color = chartColor(item.color, c, seriesIndex);
4201
4204
  const linePath = pathFor(item.points);
4202
- const areaPath = item.area && item.points.length > 1 ? `${linePath} L ${plot.x + (item.points.length - 1) * xStep} ${plot.bottom} L ${plot.x} ${plot.bottom} Z` : "";
4205
+ let areaPath = "";
4206
+ if (item.area && item.points.length > 1) {
4207
+ const firstPoint = pointFor(item.points[0], 0);
4208
+ const lastPoint = pointFor(item.points[item.points.length - 1], item.points.length - 1);
4209
+ areaPath = `${linePath} L ${lastPoint.x} ${plot.bottom} L ${firstPoint.x} ${plot.bottom} Z`;
4210
+ }
4203
4211
  const elements = [];
4204
4212
  if (areaPath) {
4205
4213
  elements.push(React.createElement("path", { key: `${item.name}-area`, d: areaPath, fill: color, opacity: 0.12 }));
@@ -4240,10 +4248,9 @@ function LineChart({
4240
4248
  fontWeight: 700,
4241
4249
  transform: "translate(-50%, -50%) rotate(-90deg)"
4242
4250
  }),
4243
- ...(labels ?? []).map((label, index, allLabels) => {
4244
- const x = plot.x + index * xStep;
4245
- const align = index === 0 ? "left" : index === allLabels.length - 1 ? "right" : "center";
4246
- return chartLabel(`line-x-${label}`, label, x, height - 14, c, { align, width: 72 });
4251
+ ...(labels ?? []).map((label, index) => {
4252
+ const x = xStart + index * xStep;
4253
+ return chartLabel(`line-x-${label}`, label, x, height - 14, c, { width: 72 });
4247
4254
  })
4248
4255
  )
4249
4256
  });
@@ -5199,6 +5206,12 @@ function cropSavesEnough(source, target) {
5199
5206
  function resolveWatermark(options) {
5200
5207
  return options.watermark ?? options.brand;
5201
5208
  }
5209
+ function shouldCropHeight(crop) {
5210
+ return crop !== false;
5211
+ }
5212
+ function shouldCropViewport(crop) {
5213
+ return crop !== false && crop !== "height";
5214
+ }
5202
5215
  async function renderToPng(element, options, createFn, theme) {
5203
5216
  await renderToPngWithOutput(element, options, createFn, theme);
5204
5217
  }
@@ -5248,7 +5261,7 @@ async function renderToPngInContext(element, options, createFn, theme) {
5248
5261
  let finalElement = element;
5249
5262
  const heightSaved = options.height - bounds.height;
5250
5263
  const heightSavedPercent = heightSaved / options.height * 100;
5251
- if (options.crop !== false && heightSavedPercent >= CROP_THRESHOLD_PERCENT) {
5264
+ if (shouldCropHeight(options.crop) && heightSavedPercent >= CROP_THRESHOLD_PERCENT) {
5252
5265
  finalHeight = bounds.height;
5253
5266
  if (createFn && theme) {
5254
5267
  finalElement = createFn(theme);
@@ -5286,7 +5299,7 @@ async function renderToPngInContext(element, options, createFn, theme) {
5286
5299
  finalSvg = await renderFinalSvg(finalElement, finalWidth, finalHeight);
5287
5300
  }
5288
5301
  }
5289
- if (options.crop !== false) {
5302
+ if (shouldCropViewport(options.crop)) {
5290
5303
  const viewportCheck = new Resvg(finalSvg, {
5291
5304
  fitTo: { mode: "width", value: finalWidth },
5292
5305
  background: "rgba(0, 0, 0, 0)"
package/dist/index.cjs CHANGED
@@ -4167,10 +4167,13 @@ function LineChart({
4167
4167
  const allValues = series.flatMap((item) => item.points);
4168
4168
  const domain = chartDomain(allValues, min, max);
4169
4169
  const maxPoints = Math.max(...series.map((item) => item.points.length), 1);
4170
- const xStep = maxPoints <= 1 ? plot.innerWidth : plot.innerWidth / (maxPoints - 1);
4170
+ const xInset = maxPoints <= 1 ? 0 : Math.min(26, Math.max(14, plot.innerWidth * 0.06));
4171
+ const xStart = maxPoints <= 1 ? plot.x + plot.innerWidth / 2 : plot.x + xInset;
4172
+ const xSpan = maxPoints <= 1 ? 0 : Math.max(1, plot.innerWidth - xInset * 2);
4173
+ const xStep = maxPoints <= 1 ? 0 : xSpan / (maxPoints - 1);
4171
4174
  const ticks = chartTicks(domain.min, domain.max, 4);
4172
4175
  const pointFor = (value, index) => {
4173
- const x = plot.x + index * xStep;
4176
+ const x = xStart + index * xStep;
4174
4177
  const y = yInPlot(value, domain, plot);
4175
4178
  return { x, y };
4176
4179
  };
@@ -4213,7 +4216,12 @@ function LineChart({
4213
4216
  if (item.points.length === 0) return [];
4214
4217
  const color = chartColor(item.color, c, seriesIndex);
4215
4218
  const linePath = pathFor(item.points);
4216
- const areaPath = item.area && item.points.length > 1 ? `${linePath} L ${plot.x + (item.points.length - 1) * xStep} ${plot.bottom} L ${plot.x} ${plot.bottom} Z` : "";
4219
+ let areaPath = "";
4220
+ if (item.area && item.points.length > 1) {
4221
+ const firstPoint = pointFor(item.points[0], 0);
4222
+ const lastPoint = pointFor(item.points[item.points.length - 1], item.points.length - 1);
4223
+ areaPath = `${linePath} L ${lastPoint.x} ${plot.bottom} L ${firstPoint.x} ${plot.bottom} Z`;
4224
+ }
4217
4225
  const elements = [];
4218
4226
  if (areaPath) {
4219
4227
  elements.push(import_react.default.createElement("path", { key: `${item.name}-area`, d: areaPath, fill: color, opacity: 0.12 }));
@@ -4254,10 +4262,9 @@ function LineChart({
4254
4262
  fontWeight: 700,
4255
4263
  transform: "translate(-50%, -50%) rotate(-90deg)"
4256
4264
  }),
4257
- ...(labels ?? []).map((label, index, allLabels) => {
4258
- const x = plot.x + index * xStep;
4259
- const align = index === 0 ? "left" : index === allLabels.length - 1 ? "right" : "center";
4260
- return chartLabel(`line-x-${label}`, label, x, height - 14, c, { align, width: 72 });
4265
+ ...(labels ?? []).map((label, index) => {
4266
+ const x = xStart + index * xStep;
4267
+ return chartLabel(`line-x-${label}`, label, x, height - 14, c, { width: 72 });
4261
4268
  })
4262
4269
  )
4263
4270
  });
@@ -5214,6 +5221,12 @@ function cropSavesEnough(source, target) {
5214
5221
  function resolveWatermark(options) {
5215
5222
  return options.watermark ?? options.brand;
5216
5223
  }
5224
+ function shouldCropHeight(crop) {
5225
+ return crop !== false;
5226
+ }
5227
+ function shouldCropViewport(crop) {
5228
+ return crop !== false && crop !== "height";
5229
+ }
5217
5230
  async function renderToPng(element, options, createFn, theme) {
5218
5231
  await renderToPngWithOutput(element, options, createFn, theme);
5219
5232
  }
@@ -5263,7 +5276,7 @@ async function renderToPngInContext(element, options, createFn, theme) {
5263
5276
  let finalElement = element;
5264
5277
  const heightSaved = options.height - bounds.height;
5265
5278
  const heightSavedPercent = heightSaved / options.height * 100;
5266
- if (options.crop !== false && heightSavedPercent >= CROP_THRESHOLD_PERCENT) {
5279
+ if (shouldCropHeight(options.crop) && heightSavedPercent >= CROP_THRESHOLD_PERCENT) {
5267
5280
  finalHeight = bounds.height;
5268
5281
  if (createFn && theme) {
5269
5282
  finalElement = createFn(theme);
@@ -5301,7 +5314,7 @@ async function renderToPngInContext(element, options, createFn, theme) {
5301
5314
  finalSvg = await renderFinalSvg(finalElement, finalWidth, finalHeight);
5302
5315
  }
5303
5316
  }
5304
- if (options.crop !== false) {
5317
+ if (shouldCropViewport(options.crop)) {
5305
5318
  const viewportCheck = new import_resvg_js.Resvg(finalSvg, {
5306
5319
  fitTo: { mode: "width", value: finalWidth },
5307
5320
  background: "rgba(0, 0, 0, 0)"
package/dist/index.d.cts CHANGED
@@ -1298,6 +1298,7 @@ interface FontData {
1298
1298
  */
1299
1299
  declare function loadAdditionalAsset(code: string, segment: string): Promise<string | Font[]>;
1300
1300
  declare function getFonts(): Promise<FontData[]>;
1301
+ type CropMode = boolean | 'both' | 'height';
1301
1302
  interface RenderOptions {
1302
1303
  width: number;
1303
1304
  height: number;
@@ -1307,8 +1308,8 @@ interface RenderOptions {
1307
1308
  watermark?: WatermarkInput;
1308
1309
  /** Backward-compatible alias for watermark. */
1309
1310
  brand?: boolean | string;
1310
- /** Disable height autocrop for fixed-size frames. */
1311
- crop?: boolean;
1311
+ /** Auto-crop mode. true/"both" crops height and transparent gutters; "height" preserves declared width; false disables crop. */
1312
+ crop?: CropMode;
1312
1313
  /** Retina output scale. */
1313
1314
  scale?: number;
1314
1315
  /** Root background for Vizmatic primitives. Defaults to alpha-transparent PNG/SVG output. */
@@ -1446,4 +1447,4 @@ interface OverflowResult {
1446
1447
  */
1447
1448
  declare function detectOverflow(pixels: Uint8Array, width: number, height: number, bgColor: string, edgeTolerance?: number, minDensity?: number, alphaThreshold?: number): OverflowResult;
1448
1449
 
1449
- export { type AnimatedScene, type AnimationOptions, Arrow, ArrowMarkerDef, AxisPlot, type AxisPlotPath, Badge, BadgePill, BarChart, type BarChartDatum, Box, CalloutCard, Canvas, Card, ChartFrame, type ChartLegendItem, type ChartMargins, type ChartValueFormat, CodeBlock, type CodeLineSpec, type ColorName, Column, Comparison, type ComparisonSideSpec, Connector, type CropRegion, DashedLine, DataTable, DetailList, DotPoint, EquationCard, Flow, FlowArrow, type FlowStageSpec, GradientChip, GraphDiagram, type GraphDiagramEdge, type GraphDiagramNode, Grid, Heatmap, type IllustrationBuilder, type IntervalDatum, IntervalPlot, KeyValueList, type KeyValueRow, LayeredNetwork, type LayeredNetworkLayer, Legend, LineChart, type LineChartSeries, MathText, Matrix, MetricCard, MiniBarChart, type MiniBarDatum, type OverflowResult, Panel, Pipeline, type PlotArea, ProgressList, ProgressRow, type ProgressRowSpec, QuadrantChart, type QuadrantRegion, type RenderBackground, type RenderOptions, type RenderOutput, Row, ScatterPlot, type ScatterPoint, Scene, Stack, StackedBar, type StackedBarSegment, type StatusKind, StatusList, StatusRow, type StatusRowSpec, StepCard, SvgFrame, SvgMathText, SvgPoint, TextLabel, type ThemeColors, type ThemeMode, Tile, TileGrid, type TileSpec, TiledMatrix, type TiledMatrixRegion, TitleBar, type ToneName, ToneStrip, type TransitionType, ValuePill, VectorArrow, VectorSegment, Watermark, type WatermarkElementProps, type WatermarkImageOptions, type WatermarkInput, type WatermarkOptions, type WatermarkPosition, WindowFrame, canvas, colors, createPlotArea, cropPixels, defineIllustration, detectBackgroundColor, detectContentBounds, detectOverflow, formatMathText, getColor, getFonts, getGradient, getStyles, getThemeColors, getToneColor, getToneGradient, gradients, heatColor, loadAdditionalAsset, normalizeWatermark, renderAnimatedGif, renderToBuffer, renderToPng, renderToPngWithOutput, renderToSvg, styles, toneGradients, typography, wrapWithBrand, wrapWithWatermark };
1450
+ export { type AnimatedScene, type AnimationOptions, Arrow, ArrowMarkerDef, AxisPlot, type AxisPlotPath, Badge, BadgePill, BarChart, type BarChartDatum, Box, CalloutCard, Canvas, Card, ChartFrame, type ChartLegendItem, type ChartMargins, type ChartValueFormat, CodeBlock, type CodeLineSpec, type ColorName, Column, Comparison, type ComparisonSideSpec, Connector, type CropMode, type CropRegion, DashedLine, DataTable, DetailList, DotPoint, EquationCard, Flow, FlowArrow, type FlowStageSpec, GradientChip, GraphDiagram, type GraphDiagramEdge, type GraphDiagramNode, Grid, Heatmap, type IllustrationBuilder, type IntervalDatum, IntervalPlot, KeyValueList, type KeyValueRow, LayeredNetwork, type LayeredNetworkLayer, Legend, LineChart, type LineChartSeries, MathText, Matrix, MetricCard, MiniBarChart, type MiniBarDatum, type OverflowResult, Panel, Pipeline, type PlotArea, ProgressList, ProgressRow, type ProgressRowSpec, QuadrantChart, type QuadrantRegion, type RenderBackground, type RenderOptions, type RenderOutput, Row, ScatterPlot, type ScatterPoint, Scene, Stack, StackedBar, type StackedBarSegment, type StatusKind, StatusList, StatusRow, type StatusRowSpec, StepCard, SvgFrame, SvgMathText, SvgPoint, TextLabel, type ThemeColors, type ThemeMode, Tile, TileGrid, type TileSpec, TiledMatrix, type TiledMatrixRegion, TitleBar, type ToneName, ToneStrip, type TransitionType, ValuePill, VectorArrow, VectorSegment, Watermark, type WatermarkElementProps, type WatermarkImageOptions, type WatermarkInput, type WatermarkOptions, type WatermarkPosition, WindowFrame, canvas, colors, createPlotArea, cropPixels, defineIllustration, detectBackgroundColor, detectContentBounds, detectOverflow, formatMathText, getColor, getFonts, getGradient, getStyles, getThemeColors, getToneColor, getToneGradient, gradients, heatColor, loadAdditionalAsset, normalizeWatermark, renderAnimatedGif, renderToBuffer, renderToPng, renderToPngWithOutput, renderToSvg, styles, toneGradients, typography, wrapWithBrand, wrapWithWatermark };
package/dist/index.d.ts CHANGED
@@ -1298,6 +1298,7 @@ interface FontData {
1298
1298
  */
1299
1299
  declare function loadAdditionalAsset(code: string, segment: string): Promise<string | Font[]>;
1300
1300
  declare function getFonts(): Promise<FontData[]>;
1301
+ type CropMode = boolean | 'both' | 'height';
1301
1302
  interface RenderOptions {
1302
1303
  width: number;
1303
1304
  height: number;
@@ -1307,8 +1308,8 @@ interface RenderOptions {
1307
1308
  watermark?: WatermarkInput;
1308
1309
  /** Backward-compatible alias for watermark. */
1309
1310
  brand?: boolean | string;
1310
- /** Disable height autocrop for fixed-size frames. */
1311
- crop?: boolean;
1311
+ /** Auto-crop mode. true/"both" crops height and transparent gutters; "height" preserves declared width; false disables crop. */
1312
+ crop?: CropMode;
1312
1313
  /** Retina output scale. */
1313
1314
  scale?: number;
1314
1315
  /** Root background for Vizmatic primitives. Defaults to alpha-transparent PNG/SVG output. */
@@ -1446,4 +1447,4 @@ interface OverflowResult {
1446
1447
  */
1447
1448
  declare function detectOverflow(pixels: Uint8Array, width: number, height: number, bgColor: string, edgeTolerance?: number, minDensity?: number, alphaThreshold?: number): OverflowResult;
1448
1449
 
1449
- export { type AnimatedScene, type AnimationOptions, Arrow, ArrowMarkerDef, AxisPlot, type AxisPlotPath, Badge, BadgePill, BarChart, type BarChartDatum, Box, CalloutCard, Canvas, Card, ChartFrame, type ChartLegendItem, type ChartMargins, type ChartValueFormat, CodeBlock, type CodeLineSpec, type ColorName, Column, Comparison, type ComparisonSideSpec, Connector, type CropRegion, DashedLine, DataTable, DetailList, DotPoint, EquationCard, Flow, FlowArrow, type FlowStageSpec, GradientChip, GraphDiagram, type GraphDiagramEdge, type GraphDiagramNode, Grid, Heatmap, type IllustrationBuilder, type IntervalDatum, IntervalPlot, KeyValueList, type KeyValueRow, LayeredNetwork, type LayeredNetworkLayer, Legend, LineChart, type LineChartSeries, MathText, Matrix, MetricCard, MiniBarChart, type MiniBarDatum, type OverflowResult, Panel, Pipeline, type PlotArea, ProgressList, ProgressRow, type ProgressRowSpec, QuadrantChart, type QuadrantRegion, type RenderBackground, type RenderOptions, type RenderOutput, Row, ScatterPlot, type ScatterPoint, Scene, Stack, StackedBar, type StackedBarSegment, type StatusKind, StatusList, StatusRow, type StatusRowSpec, StepCard, SvgFrame, SvgMathText, SvgPoint, TextLabel, type ThemeColors, type ThemeMode, Tile, TileGrid, type TileSpec, TiledMatrix, type TiledMatrixRegion, TitleBar, type ToneName, ToneStrip, type TransitionType, ValuePill, VectorArrow, VectorSegment, Watermark, type WatermarkElementProps, type WatermarkImageOptions, type WatermarkInput, type WatermarkOptions, type WatermarkPosition, WindowFrame, canvas, colors, createPlotArea, cropPixels, defineIllustration, detectBackgroundColor, detectContentBounds, detectOverflow, formatMathText, getColor, getFonts, getGradient, getStyles, getThemeColors, getToneColor, getToneGradient, gradients, heatColor, loadAdditionalAsset, normalizeWatermark, renderAnimatedGif, renderToBuffer, renderToPng, renderToPngWithOutput, renderToSvg, styles, toneGradients, typography, wrapWithBrand, wrapWithWatermark };
1450
+ export { type AnimatedScene, type AnimationOptions, Arrow, ArrowMarkerDef, AxisPlot, type AxisPlotPath, Badge, BadgePill, BarChart, type BarChartDatum, Box, CalloutCard, Canvas, Card, ChartFrame, type ChartLegendItem, type ChartMargins, type ChartValueFormat, CodeBlock, type CodeLineSpec, type ColorName, Column, Comparison, type ComparisonSideSpec, Connector, type CropMode, type CropRegion, DashedLine, DataTable, DetailList, DotPoint, EquationCard, Flow, FlowArrow, type FlowStageSpec, GradientChip, GraphDiagram, type GraphDiagramEdge, type GraphDiagramNode, Grid, Heatmap, type IllustrationBuilder, type IntervalDatum, IntervalPlot, KeyValueList, type KeyValueRow, LayeredNetwork, type LayeredNetworkLayer, Legend, LineChart, type LineChartSeries, MathText, Matrix, MetricCard, MiniBarChart, type MiniBarDatum, type OverflowResult, Panel, Pipeline, type PlotArea, ProgressList, ProgressRow, type ProgressRowSpec, QuadrantChart, type QuadrantRegion, type RenderBackground, type RenderOptions, type RenderOutput, Row, ScatterPlot, type ScatterPoint, Scene, Stack, StackedBar, type StackedBarSegment, type StatusKind, StatusList, StatusRow, type StatusRowSpec, StepCard, SvgFrame, SvgMathText, SvgPoint, TextLabel, type ThemeColors, type ThemeMode, Tile, TileGrid, type TileSpec, TiledMatrix, type TiledMatrixRegion, TitleBar, type ToneName, ToneStrip, type TransitionType, ValuePill, VectorArrow, VectorSegment, Watermark, type WatermarkElementProps, type WatermarkImageOptions, type WatermarkInput, type WatermarkOptions, type WatermarkPosition, WindowFrame, canvas, colors, createPlotArea, cropPixels, defineIllustration, detectBackgroundColor, detectContentBounds, detectOverflow, formatMathText, getColor, getFonts, getGradient, getStyles, getThemeColors, getToneColor, getToneGradient, gradients, heatColor, loadAdditionalAsset, normalizeWatermark, renderAnimatedGif, renderToBuffer, renderToPng, renderToPngWithOutput, renderToSvg, styles, toneGradients, typography, wrapWithBrand, wrapWithWatermark };
package/dist/index.js CHANGED
@@ -4040,10 +4040,13 @@ function LineChart({
4040
4040
  const allValues = series.flatMap((item) => item.points);
4041
4041
  const domain = chartDomain(allValues, min, max);
4042
4042
  const maxPoints = Math.max(...series.map((item) => item.points.length), 1);
4043
- const xStep = maxPoints <= 1 ? plot.innerWidth : plot.innerWidth / (maxPoints - 1);
4043
+ const xInset = maxPoints <= 1 ? 0 : Math.min(26, Math.max(14, plot.innerWidth * 0.06));
4044
+ const xStart = maxPoints <= 1 ? plot.x + plot.innerWidth / 2 : plot.x + xInset;
4045
+ const xSpan = maxPoints <= 1 ? 0 : Math.max(1, plot.innerWidth - xInset * 2);
4046
+ const xStep = maxPoints <= 1 ? 0 : xSpan / (maxPoints - 1);
4044
4047
  const ticks = chartTicks(domain.min, domain.max, 4);
4045
4048
  const pointFor = (value, index) => {
4046
- const x = plot.x + index * xStep;
4049
+ const x = xStart + index * xStep;
4047
4050
  const y = yInPlot(value, domain, plot);
4048
4051
  return { x, y };
4049
4052
  };
@@ -4086,7 +4089,12 @@ function LineChart({
4086
4089
  if (item.points.length === 0) return [];
4087
4090
  const color = chartColor(item.color, c, seriesIndex);
4088
4091
  const linePath = pathFor(item.points);
4089
- const areaPath = item.area && item.points.length > 1 ? `${linePath} L ${plot.x + (item.points.length - 1) * xStep} ${plot.bottom} L ${plot.x} ${plot.bottom} Z` : "";
4092
+ let areaPath = "";
4093
+ if (item.area && item.points.length > 1) {
4094
+ const firstPoint = pointFor(item.points[0], 0);
4095
+ const lastPoint = pointFor(item.points[item.points.length - 1], item.points.length - 1);
4096
+ areaPath = `${linePath} L ${lastPoint.x} ${plot.bottom} L ${firstPoint.x} ${plot.bottom} Z`;
4097
+ }
4090
4098
  const elements = [];
4091
4099
  if (areaPath) {
4092
4100
  elements.push(React.createElement("path", { key: `${item.name}-area`, d: areaPath, fill: color, opacity: 0.12 }));
@@ -4127,10 +4135,9 @@ function LineChart({
4127
4135
  fontWeight: 700,
4128
4136
  transform: "translate(-50%, -50%) rotate(-90deg)"
4129
4137
  }),
4130
- ...(labels ?? []).map((label, index, allLabels) => {
4131
- const x = plot.x + index * xStep;
4132
- const align = index === 0 ? "left" : index === allLabels.length - 1 ? "right" : "center";
4133
- return chartLabel(`line-x-${label}`, label, x, height - 14, c, { align, width: 72 });
4138
+ ...(labels ?? []).map((label, index) => {
4139
+ const x = xStart + index * xStep;
4140
+ return chartLabel(`line-x-${label}`, label, x, height - 14, c, { width: 72 });
4134
4141
  })
4135
4142
  )
4136
4143
  });
@@ -5086,6 +5093,12 @@ function cropSavesEnough(source, target) {
5086
5093
  function resolveWatermark(options) {
5087
5094
  return options.watermark ?? options.brand;
5088
5095
  }
5096
+ function shouldCropHeight(crop) {
5097
+ return crop !== false;
5098
+ }
5099
+ function shouldCropViewport(crop) {
5100
+ return crop !== false && crop !== "height";
5101
+ }
5089
5102
  async function renderToPng(element, options, createFn, theme) {
5090
5103
  await renderToPngWithOutput(element, options, createFn, theme);
5091
5104
  }
@@ -5135,7 +5148,7 @@ async function renderToPngInContext(element, options, createFn, theme) {
5135
5148
  let finalElement = element;
5136
5149
  const heightSaved = options.height - bounds.height;
5137
5150
  const heightSavedPercent = heightSaved / options.height * 100;
5138
- if (options.crop !== false && heightSavedPercent >= CROP_THRESHOLD_PERCENT) {
5151
+ if (shouldCropHeight(options.crop) && heightSavedPercent >= CROP_THRESHOLD_PERCENT) {
5139
5152
  finalHeight = bounds.height;
5140
5153
  if (createFn && theme) {
5141
5154
  finalElement = createFn(theme);
@@ -5173,7 +5186,7 @@ async function renderToPngInContext(element, options, createFn, theme) {
5173
5186
  finalSvg = await renderFinalSvg(finalElement, finalWidth, finalHeight);
5174
5187
  }
5175
5188
  }
5176
- if (options.crop !== false) {
5189
+ if (shouldCropViewport(options.crop)) {
5177
5190
  const viewportCheck = new Resvg(finalSvg, {
5178
5191
  fitTo: { mode: "width", value: finalWidth },
5179
5192
  background: "rgba(0, 0, 0, 0)"
package/docs/PROMPT.md CHANGED
@@ -333,7 +333,7 @@ Theme and render APIs:
333
333
  - `WatermarkInput`: `boolean | string | WatermarkOptions | ReactElement<WatermarkElementProps>`. `true` uses Vizmatic defaults. A string sets the watermark text. A React element can be `<Watermark>...</Watermark>` or any custom element.
334
334
  - `WatermarkImageOptions`: `src`, `width?: number`, `height?: number`, `alt?: string`. Programmatic `src` should be a URL or data URI. CLI `--watermark-image` accepts URL, data URI, or local path.
335
335
  - `WatermarkOptions`: `text?: string | false`, `image?: string | WatermarkImageOptions`, `icon?: ReactNode | string | false`, `element?: ReactNode`, `position?: "top-left" | "top-right" | "bottom-left" | "bottom-right" = "top-right"`, `opacity?: number`, `color?: string`.
336
- - `RenderOptions`: `width`, `height`, `outputPath`, `background?: "transparent" | "theme" | CSS color = "transparent"`, `watermark?: WatermarkInput`, `brand?: boolean | string` as a compatibility alias, `crop?: boolean = true`, `scale?: number = 2`.
336
+ - `RenderOptions`: `width`, `height`, `outputPath`, `background?: "transparent" | "theme" | CSS color = "transparent"`, `watermark?: WatermarkInput`, `brand?: boolean | string` as a compatibility alias, `crop?: boolean | "height" | "both" = true`, `scale?: number = 2`. Use `crop: "height"` when host layouts require stable width but should still trim extra vertical whitespace.
337
337
  - `renderToBuffer(element, width, height, options?)`: `options` supports `background?`, `watermark?`, `brand?`, `scale?`.
338
338
  - `renderToSvg(element, width, height, options?)`: `options` supports `background?`, `watermark?`, `brand?`.
339
339
  - `renderAnimatedGif(scenes, options)`: `scenes: AnimatedScene[]`, `options: AnimationOptions`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vizmatic",
3
- "version": "0.1.19",
3
+ "version": "0.1.21",
4
4
  "description": "Theme-aware visual primitives and render pipeline for AI-generated diagrams, figures, and presentation frames.",
5
5
  "type": "module",
6
6
  "license": "MIT",