Skip to main content

Dynamic Views

Dynamic Views let users add, remove, duplicate, resize, and reorder views at runtime. This is useful for products where the number of sides or panels is user-defined — e.g. multi-page booklets, custom packaging, or variable-panel signage.

Enabling Dynamic Views

Set enableDynamicViews: true in your options:

const chamevo = new ChamevoJS({
canvas,
options: {
enableDynamicViews: true,
dynamicViewsOptions: {
formats: [[210, 297], [148, 210], [300, 300]],
minWidth: 50,
maxWidth: 500,
minHeight: 50,
maxHeight: 500,
pricePerArea: 0.05,
},
},
});

Configuration

DynamicViewsOptions

PropertyTypeDefaultDescription
formats[number, number][]Preset format sizes as [width, height] pairs (in the active unitOfMeasurement). Displayed as selectable cards in the UI.
pricePerAreanumber0Price per unit area. When set, each dynamic view's dimensions contribute to the total price.
minWidthnumberMinimum allowed width.
maxWidthnumberMaximum allowed width.
minHeightnumberMinimum allowed height.
maxHeightnumberMaximum allowed height.

Module Config (CVDynamicViewsModuleConfig)

Fine-tune the UI via modulesConfig.dynamicViews:

options: {
enableDynamicViews: true,
modulesConfig: {
dynamicViews: {
showFormats: true,
showCustomSize: true,
showDuplicate: true,
showRemove: true,
showAreaPrice: true,
},
},
}
PropertyTypeDefaultDescription
showFormatsbooleantrueShow preset format cards.
showCustomSizebooleantrueShow custom width/height inputs.
showDuplicatebooleantrueShow duplicate button on view cards.
showRemovebooleantrueShow remove button on dynamic view cards.
showAreaPricebooleantrueShow area price calculation.

API Methods

addView(options?)

Add a new view at runtime. Returns the new view index, or -1 if dynamic views are disabled.

const index = await chamevo.addView({
title: 'Page 3',
width: 300,
height: 400,
insertAfter: 1, // Insert after view index 1
});
OptionTypeDefaultDescription
titlestring'View N'Display title for the new view.
widthnumberCurrent view's widthStage width in pixels.
heightnumberCurrent view's heightStage height in pixels.
insertAfternumberLast viewInsert the new view after this index.

New views are created with isDynamic: true and include a print area with a 20px inset.

removeView(index)

Remove a dynamic view. Returns false if the view is not dynamic or is the only view.

const removed = await chamevo.removeView(2);

duplicateView(index)

Deep-copy a view and insert the duplicate immediately after the source. Returns the new view index, or -1 if disabled.

const newIndex = await chamevo.duplicateView(0);

resizeView(index, width, height)

Resize a view's stage dimensions and update its print area.

chamevo.resizeView(1, 600, 400);

reorderViews(fromIndex, toIndex)

Move a view from one position to another.

await chamevo.reorderViews(0, 2); // Move first view to third position

Events

EventPayloadDescription
viewAdd{ view, index }A new view was added.
viewRemove{ view, index }A view was removed.
viewDuplicate{ sourceIndex, newView, newIndex }A view was duplicated.
viewResize{ viewIndex, width, height, unit }A view was resized.
viewReorder{ fromIndex, toIndex }A view was reordered.
chamevo.on('viewAdd', ({ view, index }) => {
console.log(`View "${view.title}" added at index ${index}`);
});

chamevo.on('viewResize', ({ viewIndex, width, height, unit }) => {
console.log(`View ${viewIndex} resized to ${width}x${height} ${unit}`);
});

Area Pricing

When pricePerArea is set, each unlocked dynamic view contributes to the total price based on its dimensions:

area price = width × height × pricePerArea

Dimensions are converted from pixels using unitOfMeasurement (default: mm). Locked dynamic views do not incur area pricing.

options: {
enableDynamicViews: true,
unitOfMeasurement: 'cm',
dynamicViewsOptions: {
pricePerArea: 0.10, // $0.10 per cm²
},
}

UI Component

The cv-views-grid component renders automatically inside cv-customizer when enableDynamicViews is enabled. It provides:

  • View cards with generated thumbnails, dimensions, and lock badges
  • Drag-and-drop reordering
  • Duplicate and remove buttons (dynamic views only)
  • Add panel with preset format cards and custom width/height inputs
  • Area price display

Next Steps