@pixeasy/customizer
v3.0.4
Published
Framework-agnostic SDK to embed the Pixeasy customizer in Angular, React, Vue, or any ESM app.
Readme
Pixeasy Customizer SDK
Framework-agnostic SDK to embed the Pixeasy customizer in Angular, React, Vue, or any ESM app.
Installation
npm install @pixeasy/customizerQuick Start
import { createPixeasyBuilder } from '@pixeasy/customizer';
import '@pixeasy/customizer/styles.css';
const builder = createPixeasyBuilder();
builder.open({
container: 'pixeasyBuilder',
apiKey: 'dk_xxx_yyy',
productId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
});Note: container can be a CSS selector string (element id) or an HTMLElement reference.
API Reference
createPixeasyBuilder()
Creates and returns a new PixeasyBuilder instance. You can create multiple builder instances if needed.
const builder = createPixeasyBuilder();PixeasyBuilder.open(options)
Opens the customizer with the specified configuration.
Options
type PixeasyOpenOptions = {
// Required
container: string | HTMLElement; // CSS selector or DOM element to mount the customizer
apiKey: string; // Your API key (format: dk_xxx_yyy)
productId: string; // Product ID (UUID format)
// Optional
predesignId?: string; // Load a pre-designed template
submissionNumber?: string; // Load an existing submission for editing
locale?: string; // Language/locale code (e.g., 'en', 'fr', 'de')
theme?: string; // Theme name or color scheme
readonly?: boolean; // Set to true to disable editing (view-only mode)
};Option Details
| Option | Type | Required | Description |
| ------------------ | ----------------------- | -------- | ------------------------------------------------------------------------------------- |
| container | string \| HTMLElement | Yes | Target container to mount the customizer. If string, treated as element ID. |
| apiKey | string | Yes | Your Pixeasy API key for authentication. |
| productId | string | Yes | UUID of the product to customize. |
| predesignId | string | No | Load a pre-designed template/predesign. Useful for template-based workflows. |
| submissionNumber | string | No | Load an existing submission for editing or review. Use with readonly for view-only. |
| locale | string | No | Set the UI language. Examples: 'en', 'fr', 'de', 'es'. |
| theme | string | No | Apply a theme or color scheme to the customizer UI. |
| readonly | boolean | No | Enable view-only mode. Prevents editing and submission. Perfect for order review. |
Events
All events can be subscribed using builder.on(eventName, handler).
| Event | When it fires | Payload |
| -------------------- | -------------------------------------------------------------------------------------------- | ------------------------------ |
| manifest-loaded | After the product manifest loads successfully. | ManifestLoadedEventDetail |
| sdk-ready | After the customizer initializes and is ready for interaction. | SdkReadyEventDetail |
| submission:success | After a successful submission. | SubmissionSuccessEventDetail |
| submission:failed | When submission fails (API error, network issue, or validation error). | SubmissionFailedEventDetail |
| error | When a runtime error occurs (invalid config, manifest load failed, asset load failed, etc.). | ErrorEventDetail |
| closed | When the customizer is closed via builder.close(). | undefined |
Event Payload Types
// Fires after manifest is loaded
interface ManifestLoadedEventDetail {
productId: string;
manifestMeta?: {
version?: string;
} | null;
}
// Fires when SDK is ready for use
interface SdkReadyEventDetail {
productId: string;
}
// Fires on successful submission
interface SubmissionSuccessEventDetail {
productId?: string;
views?: string[]; // Generated views/angles
submissionNumber: string; // Unique submission identifier
}
// Fires when submission fails
interface SubmissionFailedEventDetail {
productId?: string;
views?: string[];
message: string; // Error message
errors?: string[]; // Detailed error list
}
// Fires on SDK errors
interface ErrorEventDetail {
code: 'INVALID_CONFIG' | 'MANIFEST_LOAD_FAILED' | 'ASSET_LOAD_FAILED' | 'RUNTIME_ERROR';
message: string;
}Event Subscription Example
import { SDK_EVENTS } from '@pixeasy/customizer';
const builder = createPixeasyBuilder();
builder.open({
container: 'pixeasyBuilder',
apiKey: 'dk_xxx_yyy',
productId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
});
// Subscribe to events
builder
.on(SDK_EVENTS.MANIFEST_LOADED, (event) => {
console.log('Manifest loaded for product:', event.productId);
})
.on(SDK_EVENTS.SDK_READY, (event) => {
console.log('Customizer is ready!', event.productId);
})
.on(SDK_EVENTS.SUBMISSION_SUCCESS, (event) => {
console.log('Submission successful:', event.submissionNumber);
console.log('Generated views:', event.views);
})
.on(SDK_EVENTS.SUBMISSION_FAILED, (event) => {
console.error('Submission failed:', event.message);
if (event.errors) {
console.error('Errors:', event.errors);
}
})
.on(SDK_EVENTS.ERROR, (event) => {
console.error(`Error [${event.code}]:`, event.message);
})
.on(SDK_EVENTS.CLOSED, () => {
console.log('Customizer closed');
});Unsubscribing from Events
const handleSuccess = (event) => console.log('Success:', event.submissionNumber);
builder.on(SDK_EVENTS.SUBMISSION_SUCCESS, handleSuccess);
// Later, remove the listener
builder.off(SDK_EVENTS.SUBMISSION_SUCCESS, handleSuccess);Framework Examples
React
Basic Usage
import { useEffect } from 'react';
import { createPixeasyBuilder } from '@pixeasy/customizer';
import '@pixeasy/customizer/styles.css';
export function CustomizerHost() {
useEffect(() => {
const builder = createPixeasyBuilder();
builder.open({
container: 'pixeasyBuilder',
apiKey: 'dk_xxx_yyy',
productId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
});
return () => builder.close();
}, []);
return <div id="pixeasyBuilder" />;
}Advanced Usage with Events
import { useEffect } from 'react';
import { createPixeasyBuilder, SDK_EVENTS } from '@pixeasy/customizer';
import '@pixeasy/customizer/styles.css';
export function CustomizerWithEvents() {
useEffect(() => {
const builder = createPixeasyBuilder();
builder
.on(SDK_EVENTS.SDK_READY, () => {
console.log('Customizer ready');
})
.on(SDK_EVENTS.SUBMISSION_SUCCESS, (event) => {
console.log('Submission successful:', event.submissionNumber);
// Handle success - e.g., show confirmation, redirect, etc.
})
.on(SDK_EVENTS.ERROR, (event) => {
console.error('Error occurred:', event.message);
})
.open({
container: 'pixeasyBuilder',
apiKey: 'dk_xxx_yyy',
productId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
locale: 'en',
theme: 'dark',
});
return () => builder.close();
}, []);
return <div id="pixeasyBuilder" style={{ width: '100%', height: '100vh' }} />;
}Load Existing Submission
import { useEffect } from 'react';
import { createPixeasyBuilder, SDK_EVENTS } from '@pixeasy/customizer';
import '@pixeasy/customizer/styles.css';
export function EditSubmission({ submissionNumber }: { submissionNumber: string }) {
useEffect(() => {
const builder = createPixeasyBuilder();
builder
.on(SDK_EVENTS.SUBMISSION_SUCCESS, (event) => {
console.log('Updated submission:', event.submissionNumber);
})
.open({
container: 'pixeasyBuilder',
apiKey: 'dk_xxx_yyy',
productId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
submissionNumber: submissionNumber, // Load for editing
});
return () => builder.close();
}, [submissionNumber]);
return <div id="pixeasyBuilder" />;
}View-Only Mode
import { useEffect } from 'react';
import { createPixeasyBuilder } from '@pixeasy/customizer';
import '@pixeasy/customizer/styles.css';
export function ViewSubmission({ submissionNumber }: { submissionNumber: string }) {
useEffect(() => {
const builder = createPixeasyBuilder();
builder.open({
container: 'pixeasyBuilder',
apiKey: 'dk_xxx_yyy',
productId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
submissionNumber: submissionNumber,
readonly: true, // Enable view-only mode
});
return () => builder.close();
}, [submissionNumber]);
return <div id="pixeasyBuilder" />;
}Vue
Basic Usage
import { onMounted, onBeforeUnmount } from 'vue';
import { createPixeasyBuilder } from '@pixeasy/customizer';
import '@pixeasy/customizer/styles.css';
export default {
setup() {
const builder = createPixeasyBuilder();
onMounted(() => {
builder.open({
container: 'pixeasyBuilder',
apiKey: 'dk_xxx_yyy',
productId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
});
});
onBeforeUnmount(() => builder.close());
return {};
},
};With Events and Options
import { onMounted, onBeforeUnmount } from 'vue';
import { createPixeasyBuilder, SDK_EVENTS } from '@pixeasy/customizer';
import '@pixeasy/customizer/styles.css';
export default {
props: {
submissionNumber: [String, null],
},
setup(props) {
const builder = createPixeasyBuilder();
onMounted(() => {
builder
.on(SDK_EVENTS.SDK_READY, () => {
console.log('Customizer initialized');
})
.on(SDK_EVENTS.SUBMISSION_SUCCESS, (event) => {
console.log('Saved:', event.submissionNumber);
})
.open({
container: 'pixeasyBuilder',
apiKey: 'dk_xxx_yyy',
productId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
submissionNumber: props.submissionNumber || undefined,
locale: 'en',
});
});
onBeforeUnmount(() => builder.close());
return {};
},
};Exports
Personalized Design Templates
For a complete third-party integration guide, including save-event payloads and the server webhook, see Personalized template integration.
The same npm package also registers <pixeasy-personalized-customizer>. This is a separate
runtime from <pixeasy-customizer>: it loads the latest active published template assigned to
the requested 2D product. Existing createPixeasyBuilder() integrations keep their behavior.
import {
createPixeasyPersonalizedBuilder,
PERSONALIZED_CUSTOMIZER_EVENTS,
} from '@pixeasy/customizer-stage';
const personalizer = createPixeasyPersonalizedBuilder();
personalizer.on(PERSONALIZED_CUSTOMIZER_EVENTS.READY, ({ version }) => {
console.log('Published template version', version);
});
personalizer.on(PERSONALIZED_CUSTOMIZER_EVENTS.CHANGED, (state) => {
// Fires for product, variant, and personalization changes.
// Use state.productId to update the product shown by your storefront.
console.log('Selected product', state.productId);
});
personalizer.on(PERSONALIZED_CUSTOMIZER_EVENTS.APPLIED, (saved) => {
// Store these credentials with the customer's account or order.
// Save saved.designId and saved.editToken on your backend.
console.log(saved.designId, saved.canvases);
});
personalizer.open({
container: 'personalizer-controls',
className: 'shop-personalizer',
canvasContainerId: 'personalizer-canvas',
apiKey: 'dk_xxx_yyy',
userUniqueId: 'customer-uuid',
productId: 'product-uuid',
templateId: 'published-template-uuid',
});Pass userUniqueId to show the customer's logo library beside each editable image field.
Customers can choose a logo from their library or the shared collection, subject to the field's
image type and image count limits. For the custom element, use the user-unique-id attribute.
Apply now calls POST /public/personalized-designs/apply. It validates the required fields,
renders every active canvas at 300 DPI using each placement's printable dimensions, and stores
the editable values, text and logo overlay snapshots, source images, canvas PNGs, and composed product/variant preview images. Overlay inches are measured from the rendered canvas using the selected assigned product's printable dimensions. The selected variant and color are saved. The submission PDF is generated using the 2D submission layout.
The design ID is the ID of a record in the shared submissions table. The event contains the saved design ID,
edit token, revision, and per-canvas PNG URLs. The SDK shows canvas image download buttons after apply. The PDF URL can be empty while generation is pending. Treat the edit token as a customer secret;
store it on your server with the customer's order or account. Export URLs are temporary.
The distributor API key needs ProductRead, SubmissionCreate, and SubmissionRead scopes.
To reopen the design, pass both saved credentials to open() with the same product and template:
personalizer.open({
container: 'personalizer-controls',
canvasContainerId: 'personalizer-canvas',
apiKey: 'dk_xxx_yyy',
productId: 'product-uuid',
templateId: 'published-template-uuid',
designId: savedDesignId,
editToken: savedEditToken,
});The SDK loads the exact published template version used by the design and restores its values
and image transforms. Saving again currently creates a new submission with a new design ID,
submission number, and edit token; store the latest credentials from the event.
GET /public/personalized-designs/{designId} requires the distributor API key and
X-Edit-Token header; it can refresh expired export links.
Provide both divs in the host page:
<div id="personalizer-canvas"></div>
<div id="personalizer-controls"></div>canvasContainerId is optional. When supplied, the canvas stage renders inside that div
and stays synchronized with the controls mounted in container. The divs must be distinct
and already exist when open() is called. Without it, the canvas stays inside the controls UI.
The personalized-template response includes the distributor's primary and secondary colors and the product's admin color pack when available. Color controls start with a custom picker, followed by a short palette and a See all colors action. Upload fields support both browsing and dragging image files into the upload box.
The optional className sets a class on the custom element. Because the controls use Shadow
DOM, host styles can use CSS variables and ::part() to customize them:
.shop-personalizer {
--personalized-primary: #154f72;
--personalized-secondary: #f6c65b;
--personalized-on-primary: white;
--personalized-background: #f5f8fa;
--personalized-surface: white;
--personalized-ink: #172033;
--personalized-muted: #526078;
--personalized-border: #dfe4ec;
}
.shop-personalizer > div::part(field-card) { padding-block: 1.5rem; }
.shop-personalizer > div::part(text-input),
.shop-personalizer > div::part(setting-input) { border-radius: 4px; }
.shop-personalizer > div::part(upload-box) { border-style: solid; }
.shop-personalizer > div::part(color-swatch) { width: 42px; height: 42px; }Other stable parts include shell, header, apply-button, product-switcher, product-button,
variant-switcher, variant-button, canvas-tabs, canvas-tab,
preview-panel, form-panel, image-card, color-control, color-options,
color-picker, see-colors, and range-input for crop controls. CSS variables take precedence over distributor colors
when supplied by the host.
The custom element also accepts api-key, product-id, template-id, optional
canvas-container-id, design-id, edit-token, and readonly
attributes. The builder exposes getDesignState(), getCanvasSvg(), getCanvasImage(),
and close(). The canvas export methods return the current product view with the design
as SVG or a PNG data URL after rendering is ready; they return null before that.
The builders pass apiKey and editToken without adding DOM attributes. Existing
custom-element attributes remain supported and are removed when the element connects.
The browser still uses the API key in requests, so this only removes it from the DOM.
personalized:changed
fires as text or images change, personalized:applied fires after the design has been saved,
and personalized:error reports loading failures. The design state contains template
version, selected product and variant IDs, text values, uploaded image data URLs, per-image positions and scales, and default
asset IDs. A single-image upload replaces its default; multi-image fields can replace each
image individually. The published product view is used as the canvas background, with the
design positioned in the assigned placement. Apply persists a shared design submission and
links its personalized editing state through DesignSubmissionId.
Image corner handles resize proportionally; side handles change width or height independently.
imageAxisScales in the emitted design state stores per-image { x, y } scale values.
The existing imageScales field remains for older integrations; it reports the X scale
when an image has different X and Y values.
The published-template endpoint is
GET /public/products/{productId}/personalized-design-templates/{templateId} and requires
the same X-API-Key header as other public SDK endpoints. It returns only an active template
whose latest published version includes the enabled product. It supplies the shared canvases,
asset URLs, and product placement maps. The SDK also requests
GET /public/products/{productId}/personalized-design-templates/{templateId}/product for the
selected product's variants, view images, fonts, and colors. Changing products requests only
that product's details; changing a variant color uses the product data already loaded.
Variant choices show the configured color thumbnail image when available, otherwise the color
code. Hover or keyboard focus reveals the variant name.
The package exports the following:
Classes & Functions
createPixeasyBuilder()- Factory function to create a newPixeasyBuilderinstancePixeasyBuilder- Main class for managing the customizer lifecycledefinePixeasyCustomizerElement()- Registers the<pixeasy-customizer>custom element (auto-called internally)generateThumbnails()- Utility function to generate product thumbnails from SVG and 3D models
Types
PixeasyOpenOptions- Configuration object forbuilder.open()SdkElementConfig- Base configuration interfaceManifestLoadedEventDetail- Payload for manifest-loaded eventSdkReadyEventDetail- Payload for sdk-ready eventSubmissionSuccessEventDetail- Payload for submission:success eventSubmissionFailedEventDetail- Payload for submission:failed eventErrorEventDetail- Payload for error eventSDK_EVENTS- Enum of all available event namesBuilderEventName- Type-safe event name typeThumbnailView- View types for thumbnail generation ('front' | 'right' | 'back' | 'left')GeneratedThumbnail- Thumbnail generation result
Stylesheets
@pixeasy/customizer/styles.css- Required stylesheet (import once in your app)
Common Use Cases
Create a New Design from Scratch
builder.open({
container: 'pixeasyBuilder',
apiKey: 'dk_xxx_yyy',
productId: 'product-uuid',
});Use a Template/Predesign
builder.open({
container: 'pixeasyBuilder',
apiKey: 'dk_xxx_yyy',
productId: 'product-uuid',
predesignId: 'predesign-uuid', // Start with a pre-designed template
});Edit an Existing Submission
builder.open({
container: 'pixeasyBuilder',
apiKey: 'dk_xxx_yyy',
productId: 'product-uuid',
submissionNumber: 'SUB-12345', // Load existing submission
});Review Order (Read-Only)
builder.open({
container: 'pixeasyBuilder',
apiKey: 'dk_xxx_yyy',
productId: 'product-uuid',
submissionNumber: 'SUB-12345',
readonly: true, // Disable editing
});Multi-Language Support
builder.open({
container: 'pixeasyBuilder',
apiKey: 'dk_xxx_yyy',
productId: 'product-uuid',
locale: 'de', // German, or 'fr', 'es', etc.
});Best Practices
Always import styles - Include the CSS stylesheet once in your app:
import '@pixeasy/customizer/styles.css';Handle errors gracefully - Always subscribe to the
errorevent:builder.on(SDK_EVENTS.ERROR, (event) => { console.error(`Error [${event.code}]: ${event.message}`); // Show user-friendly error message });Validate API key and Product ID - These are required for the customizer to function:
if (!apiKey || !productId) { throw new Error('Missing required configuration'); }Clean up on unmount - Always call
builder.close()when the component unmounts to prevent memory leaksUse events for flow control - Subscribe to
submission:successto handle post-submission actionsHandle locale properly - Set the locale to match user preferences before opening
Use readonly mode for reviews - Enable
readonly: truewhen showing past submissions or previews
