Embed UPC

One universal CDN snippet for your whole store. Each product page sets UPC_PRODUCT JSON; UPC mounts with that dynamic data — no per-product snippets.

Quickstart

  1. Sign up as a merchant and buy a plan on Account.
  2. Open Merchant → Embed snippet (or Account), set rectangle / freeform print guide, copy the universal code.
  3. On every product page: set window.UPC_PRODUCT, then paste the same snippet.

Product JSON (dynamic)

Coordinates use a 600×600 design grid. Rectangle print areas use x / y / width / height. Freeform areas add points (3+ vertices); content is hard-clipped to that shape.

window.UPC_PRODUCT = {
  id: "sku-123",
  template: "tshirt",
  title: "Classic Tee",
  sides: [
    {
      id: "front",
      label: "Front",
      mockupUrl: "https://…/tee-front.png",
      // Rectangle
      printArea: { x: 190, y: 160, width: 220, height: 280 }
      // Or freeform polygon (phone cutout, irregular chest, …):
      // printArea: {
      //   x: 190, y: 55, width: 220, height: 490,
      //   points: [
      //     { x: 210, y: 55 }, { x: 390, y: 55 },
      //     { x: 410, y: 75 }, { x: 410, y: 525 },
      //     { x: 390, y: 545 }, { x: 210, y: 545 },
      //     { x: 190, y: 525 }, { x: 190, y: 195 },
      //     { x: 280, y: 195 }, { x: 280, y: 55 }
      //   ]
      // }
    }
  ]
};

CDN script

<script src="http://localhost:3010/cdn/upc.js" data-license="upc_…"></script>

Inline embed

<div id="upc-customizer"></div>
<script>/* set window.UPC_PRODUCT */</script>
<script src="http://localhost:3010/cdn/upc.js" data-license="upc_…"></script>
<script>
  UPC.mount({
    container: "#upc-customizer",
    mode: "inline",
    license: "upc_…",
    product: window.UPC_PRODUCT || UPC.readProduct(),
    features: { text: true, images: true, shapes: true, layers: true },
    ui: { placement: "below", showFrame: true }
  });
</script>

UPC.mount API

OptionTypeDescription
containerstring | ElementMount host
mode"inline" | "popup"Embed style
triggerstringPopup button selector
licensestringupc_* key
productobjectDynamic product JSON
featuresobjectDesign tools
uiobjectToolbar, colors, printGuide
themeobjectCanvas theme + guide stroke

Export & upload (merchant)

After the shopper finishes designing, capture the canvas as a File / Blob, upload it to your storage (S3, Cloudinary, Shopify Files, your API), then save the returned URL + editable design JSON on the order/line item. UPC does not require uploading to our servers.

ProductCustomizer methods (@upc/core)

MethodReturnsUse for
exportPNG(multiplier?)Promise<string>PNG data URL (base64)
exportBlob(multiplier?)Promise<Blob>Raw binary for FormData
exportFile(filename?, multiplier?)Promise<File>Browser File for upload APIs
exportForUpload({ filename?, multiplier? })Promise<{ design, previewDataUrl, previewBlob, previewFile }>One-shot: JSON + File + Blob
save()Promise<{ previewDataUrl, design }>PNG data URL + design JSON
dataUrlToBlob(dataUrl)BlobHelper: data URL → Blob
dataUrlToFile(dataUrl, filename?)FileHelper: data URL → File

CDN helpers (upc.js)

Same converters on the global UPC object — no npm install needed on a classic storefront theme:

// After you have a PNG data URL from the customizer:
const file = UPC.dataUrlToFile(previewDataUrl, "design.png");
const blob = UPC.dataUrlToBlob(previewDataUrl);

const form = new FormData();
form.append("file", file); // or blob
await fetch("/apps/your-upload", { method: "POST", body: form });

Storefront example — Add to cart

import { dataUrlToFile } from "@upc/core";
// customizer = your ProductCustomizer instance (ref from mount)

async function addCustomizedToCart() {
  const pack = await customizer.exportForUpload({
    filename: "design-" + Date.now() + ".png",
    multiplier: 2,
  });

  // 1) Upload File to YOUR backend / CDN
  const form = new FormData();
  form.append("file", pack.previewFile);
  form.append("productId", pack.design.productId || "");
  const up = await fetch("/api/upload-design", {
    method: "POST",
    body: form,
  });
  const { url: previewUrl } = await up.json();

  // 2) Attach to cart / order (Shopify line item props, Woo meta, etc.)
  await fetch("/api/cart/add", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      previewUrl,                 // hosted image you print from
      designJson: pack.design,    // reopen / edit later
      // optional: also keep pack.previewDataUrl for tiny previews
    }),
  });
}

// Alternative: save() then convert yourself
const { previewDataUrl, design } = await customizer.save();
const file = dataUrlToFile(previewDataUrl, "upc-design.png");
// or: UPC.dataUrlToFile(previewDataUrl, "upc-design.png")

Wire addCustomizedToCart to your Add to cart / Checkout button. Keep designJson so the shopper (or you) can reopen the design in UPC later.

Features flags

features: { text: true, images: true, shapes: true, layers: true }

Toggle these in the snippet builder under Shopper tools. Demo catalog products/templates are configured by platform admin only.

UI config

ui: {
  showFrame: true,
  showHeader: true,
  placement: "below", // above | inner-horizontal | inner-vertical | collapsible | drawer-right
  collapsibleCorner: "bottom-right",
  accentColor: "#0d6b4f",
  backgroundColor: "#f3f0ea",
  editorBackground: "#ffffff",
  outOfBoundsOpacity: 0.35,
  printGuide: { /* see Print area guide */ },
  tools: {
    text: true, image: true, rect: true, circle: true, triangle: true,
    layers: true, clear: true, undo: true, redo: true, save: true, header: true
  }
}

Editor tools (shopper)

  • Text / Image / Shapes — add content inside the print area; clipped automatically.
  • Selection bar — with text or a shape selected, change font (text) and fill color.
  • Layers — click a layer to select it, drag to reorder, delete via ✕ or the Delete key.

License & domains

Payment records the plan only — it does not show a license key. On Dashboard → Payments & license, click Generate license key, enter the store website URL, and get a key bound to that store. Update the URL later to move the same key. CDN checks GET /api/licenses/validate?key=&host= before mount.

  • Starter — 1 store license · Powered by UPC
  • Growth — 3 store licenses · Powered by UPC
  • Professional — unlimited store licenses · white-label (no badge)
  • localhost is always allowed for local testing.