/**
* boxlib.js — 盒型库 / 模板 / 素材 / 纹理 / 动效 / 色板 数据层
* 对标包小盒「盒型库 · 模板 · 素材 · 动效」的数据组织方式。
*/
(function () {
'use strict';
/* ---------------- 盒型库 ---------------- */
// gen: 刀版生成结构;sizes: 固定尺寸(可改尺寸为 null);mats: 可选材质
var BOXLIB = [
{ no: '100010', name: '反向插锁盒', cat: '纸盒', gen: 'tuck', sizes: null, printable: true, hot: 5 },
{ no: '100011', name: '直插盒', cat: '纸盒', gen: 'straight', sizes: null, printable: true, hot: 3 },
{ no: '100020', name: '卡纸折叠盒', cat: '纸盒', gen: 'carton', sizes: null, printable: true, hot: 5 },
{ no: '100030', name: '飞机式插锁盒', cat: '纸盒', gen: 'mailer', sizes: null, printable: true, hot: 4 },
{ no: '100040', name: '扣底盒', cat: '纸盒', gen: 'autobottom', sizes: null, printable: true, hot: 4 },
{ no: '100050', name: '平口箱', cat: '纸箱', gen: 'rsc', sizes: null, printable: true, hot: 3 },
{ no: '100060', name: '四折边对盖盒', cat: '纸箱', gen: 'rsc', sizes: [[200, 140, 80], [260, 180, 100]], printable: true, hot: 2 },
{ no: '360110', name: '异型书型精品翻盖礼盒', cat: '精装盒', gen: 'mailbox', sizes: [[220, 60, 160]], printable: true, hot: 3 },
{ no: '360120', name: '翻盖精品礼盒', cat: '精装盒', gen: 'mailbox', sizes: null, printable: true, hot: 4 },
{ no: '360130', name: '到底V槽天地盖盒', cat: '精装盒', gen: 'drawer', sizes: [[180, 120, 60]], printable: true, hot: 2 },
{ no: '360140', name: '抽屉盒', cat: '精装盒', gen: 'drawer', sizes: null, printable: true, hot: 3 },
{ no: '220010', name: '手提袋', cat: '手提袋', gen: 'bag', sizes: [[200, 100, 260], [250, 120, 320], [300, 140, 400]], printable: true, hot: 5 },
{ no: '220013', name: '平口手提袋', cat: '手提袋', gen: 'bag', sizes: [[200, 100, 260]], printable: true, hot: 2 },
{ no: '220041', name: '弧形孔手提袋', cat: '手提袋', gen: 'bag', sizes: [[220, 110, 300]], printable: true, hot: 2 },
{ no: '220040', name: '免提手袋', cat: '手提袋', gen: 'bag', sizes: [[180, 90, 240]], printable: false, hot: 1 },
{ no: '240010', name: '封套', cat: '封套/卡片/文件', gen: 'sleeve', sizes: null, printable: true, hot: 3 },
{ no: '240030', name: '梯形盒套', cat: '封套/卡片/文件', gen: 'sleeve', sizes: [[160, 60, 220]], printable: true, hot: 1 },
{ no: '240090', name: '快餐盒封套', cat: '封套/卡片/文件', gen: 'sleeve', sizes: [[200, 90, 60]], printable: true, hot: 1 },
{ no: '260030', name: '矩形卡牌', cat: '封套/卡片/文件', gen: 'card', sizes: [[90, 54], [85, 54]], printable: true, hot: 2 },
{ no: '260040', name: '圆形卡牌', cat: '封套/卡片/文件', gen: 'card', sizes: [[80, 80]], printable: true, hot: 1 },
{ no: '261010', name: '矩形吊牌', cat: '封套/卡片/文件', gen: 'card', sizes: [[50, 90], [60, 100]], printable: true, hot: 2 },
{ no: '261002', name: '椭圆形吊牌', cat: '封套/卡片/文件', gen: 'card', sizes: [[60, 95]], printable: true, hot: 1 },
{ no: '270010', name: '矩形标签', cat: '封套/卡片/文件', gen: 'card', sizes: [[60, 40], [80, 50]], printable: true, hot: 2 },
{ no: '270020', name: '圆形标签', cat: '封套/卡片/文件', gen: 'card', sizes: [[50, 50]], printable: true, hot: 2 }
];
var BOX_CATS = ['热门', '纸盒', '精装盒', '手提袋', '封套/卡片/文件', '更多'];
function boxById(no) {
return BOXLIB.find(function (b) { return b.no === no; }) || null;
}
/* ---------------- 模板 ---------------- */
// 模板 = 各外表面预设(颜色 / 文字 / 素材),套用时自动适配当前印刷面尺寸
var TEMPLATES = [
{
id: 't1', name: '苹果果汁软糖塑料袋包装设计', cat: '食品饮料', pro: false,
face: 'front', color: '#fde9d2', texts: [
{ text: '苹果果汁软糖', size: 16, weight: 800, color: '#c2451f', align: 'center', x: 50, y: 34 },
{ text: 'APPLE JUICE GUMMY · 净含量 120g', size: 5, weight: 400, color: '#8a6a4a', align: 'center', x: 50, y: 52 }
], asset: { id: 'apple' }
},
{ id: 't2', name: '西瓜味雪糕包装设计', cat: '食品饮料', pro: true, face: 'front', color: '#ffe3ea', texts: [{ text: '西瓜味雪糕', size: 15, weight: 800, color: '#e0486c', align: 'center', x: 50, y: 38 }, { text: 'WATERMELON ICE CREAM', size: 4.5, weight: 600, color: '#b25a70', align: 'center', x: 50, y: 50 }], asset: null },
{ id: 't3', name: '橙汁饮料玻璃瓶包装设计', cat: '食品饮料', pro: false, face: 'front', color: '#ffe9c9', texts: [{ text: '鲜榨橙汁', size: 16, weight: 800, color: '#e07c1f', align: 'center', x: 50, y: 36 }, { text: 'ORANGE JUICE 100%', size: 4.5, weight: 600, color: '#a06a30', align: 'center', x: 50, y: 48 }], asset: null },
{ id: 't4', name: '巧克力冰淇淋', cat: '食品饮料', pro: true, face: 'front', color: '#6b4a32', texts: [{ text: '巧克力冰淇淋', size: 14, weight: 800, color: '#ffe6c8', align: 'center', x: 50, y: 40 }, { text: 'CHOCOLATE ICE CREAM', size: 4.2, weight: 400, color: '#d9b898', align: 'center', x: 50, y: 52 }], asset: null },
{ id: 't5', name: '数码家电开箱盒', cat: '数码家电', pro: true, face: 'front', color: '#20242c', texts: [{ text: 'SMART HOME', size: 13, weight: 800, color: '#ffffff', align: 'center', x: 50, y: 36 }, { text: '智能家庭中枢 · 2代', size: 5, weight: 400, color: '#9aa3b2', align: 'center', x: 50, y: 48 }], asset: null },
{ id: 't6', name: '蓝牙耳机天地盖盒', cat: '数码家电', pro: false, face: 'front', color: '#eef1f5', texts: [{ text: 'AIR BUDS', size: 14, weight: 800, color: '#1c2733', align: 'center', x: 50, y: 38 }, { text: '真无线降噪耳机', size: 5, weight: 600, color: '#5c6b7c', align: 'center', x: 50, y: 50 }], asset: null },
{ id: 't7', name: '乌龙茶饮包装', cat: '日常用品', pro: false, face: 'front', color: '#e8f2e4', texts: [{ text: '乌龙茶', size: 17, weight: 800, color: '#2e5c3a', align: 'center', x: 50, y: 36 }, { text: '无糖 · 零卡 · 冷泡', size: 5, weight: 400, color: '#6a8a70', align: 'center', x: 50, y: 50 }], asset: null },
{ id: 't8', name: '香氛蜡烛礼盒', cat: '日常用品', pro: true, face: 'front', color: '#f4ece2', texts: [{ text: 'Perfume', size: 15, weight: 400, color: '#7a5c48', align: 'center', x: 50, y: 38, italic: true }, { text: 'SCENTED CANDLE · 200g', size: 4.2, weight: 400, color: '#a08868', align: 'center', x: 50, y: 50 }], asset: null },
{ id: 't9', name: '美妆精华简约盒', cat: '日常用品', pro: false, face: 'front', color: '#ffffff', texts: [{ text: 'GLOW SERUM', size: 13, weight: 700, color: '#c9a15c', align: 'center', x: 50, y: 40, italic: true }, { text: '焕采精华液 30ml', size: 5, weight: 400, color: '#8a7a5c', align: 'center', x: 50, y: 52 }], asset: null },
{ id: 't10', name: '电商发货飞机盒', cat: '热门', pro: false, face: 'front', color: '#d7b17c', texts: [{ text: 'THANK YOU', size: 13, weight: 800, color: '#6a4a26', align: 'center', x: 50, y: 40 }, { text: '轻拿轻放 · 易碎品', size: 5, weight: 400, color: '#8a6a46', align: 'center', x: 50, y: 52 }], asset: { id: 'fragile' } },
{ id: 't11', name: '精品手提袋', cat: '热门', pro: true, face: 'front', color: '#2c2c2e', texts: [{ text: 'GIFT', size: 15, weight: 700, color: '#e8c88a', align: 'center', x: 50, y: 40, italic: true }, { text: '精品礼遇 · 有档次', size: 4.5, weight: 400, color: '#b8a888', align: 'center', x: 50, y: 52 }], asset: null },
{ id: 't12', name: '中秋月饼礼盒', cat: '热门', pro: false, face: 'front', color: '#a3372c', texts: [{ text: '中秋礼遇', size: 16, weight: 800, color: '#f7e2b8', align: 'center', x: 50, y: 36 }, { text: 'FLOWER MOONCAKE', size: 4.2, weight: 400, color: '#e0b890', align: 'center', x: 50, y: 50 }], asset: null }
];
var TEMPLATE_CATS = ['热门', '食品饮料', '数码家电', '日常用品', '更多'];
/* ---------------- 素材库(内联 SVG) ---------------- */
var ICONS = {
recycle: { name: '回收标志', svg: '' },
up: { name: '向上', svg: '' },
umbrella: { name: '防雨', svg: '' },
dry: { name: '防潮 / 保持干燥', svg: '' },
fragile: { name: '易碎品(酒杯)', svg: '' },
stack: { name: '堆码层数', svg: '4' },
careful: { name: '小心棱角', svg: '' },
ce: { name: 'CE 认证', svg: '' },
fda: { name: 'FDA', svg: 'FDA' },
rohs: { name: 'RoHS', svg: 'RoHS' },
fc: { name: 'FC 认证', svg: 'FC' },
ccc: { name: 'CCC', svg: 'CCC' },
green: { name: '绿点回收', svg: '' },
iso: { name: 'ISO 质量', svg: 'ISO9001' },
noLitter: { name: '请勿乱扔', svg: '' },
battery: { name: '电子回收', svg: '' },
apple: { name: '苹果', svg: '' },
leaf: { name: '叶子环保', svg: '' },
heart: { name: '爱心', svg: '' },
star: { name: '星星', svg: '' }
};
var SHAPES = {
square: { name: '方形', draw: 'rect' },
circle: { name: '圆形', draw: 'circle' },
triangle: { name: '三角形', draw: 'triangle' },
ring: { name: '圆环', draw: 'ring' },
line: { name: '横线', draw: 'line' },
ribbon: { name: '丝带横幅', draw: 'ribbon' },
badge: { name: '圆形徽章', draw: 'badge' },
rounded: { name: '圆角框', draw: 'rounded' }
};
var ASSET_CATS = ['全部', '形状', '图标', '插画', '抠图'];
function assetSvg(id, color) {
var ic = ICONS[id];
if (ic) return '';
return null;
}
// 形状素材 → canvas dataURL
function shapeDataUrl(kind, color, size) {
var c = document.createElement('canvas');
c.width = c.height = size || 160;
var ctx = c.getContext('2d');
ctx.fillStyle = color || '#17140f';
var s = c.width;
if (kind === 'rect') ctx.fillRect(s * 0.1, s * 0.28, s * 0.8, s * 0.44);
if (kind === 'circle') { ctx.beginPath(); ctx.arc(s / 2, s / 2, s * 0.36, 0, 7); ctx.fill(); }
if (kind === 'triangle') { ctx.beginPath(); ctx.moveTo(s / 2, s * 0.16); ctx.lineTo(s * 0.86, s * 0.8); ctx.lineTo(s * 0.14, s * 0.8); ctx.closePath(); ctx.fill(); }
if (kind === 'ring') { ctx.lineWidth = s * 0.1; ctx.strokeStyle = ctx.fillStyle; ctx.beginPath(); ctx.arc(s / 2, s / 2, s * 0.3, 0, 7); ctx.stroke(); }
if (kind === 'line') ctx.fillRect(s * 0.1, s * 0.46, s * 0.8, s * 0.07);
if (kind === 'ribbon') { ctx.beginPath(); ctx.moveTo(s * 0.08, s * 0.36); ctx.lineTo(s * 0.92, s * 0.36); ctx.lineTo(s * 0.84, s * 0.5); ctx.lineTo(s * 0.92, s * 0.64); ctx.lineTo(s * 0.08, s * 0.64); ctx.lineTo(s * 0.16, s * 0.5); ctx.closePath(); ctx.fill(); }
if (kind === 'badge') { ctx.beginPath(); ctx.arc(s / 2, s / 2, s * 0.34, 0, 7); ctx.fill(); ctx.globalCompositeOperation = 'destination-out'; ctx.beginPath(); ctx.arc(s / 2, s / 2, s * 0.24, 0, 7); ctx.fill(); ctx.globalCompositeOperation = 'source-over'; }
if (kind === 'rounded') { ctx.lineWidth = s * 0.06; ctx.strokeStyle = ctx.fillStyle; var r = s * 0.12; ctx.beginPath(); ctx.moveTo(s * 0.14 + r, s * 0.22); ctx.arcTo(s * 0.86, s * 0.22, s * 0.86, s * 0.78, r); ctx.arcTo(s * 0.86, s * 0.78, s * 0.14, s * 0.78, r); ctx.arcTo(s * 0.14, s * 0.78, s * 0.14, s * 0.22, r); ctx.arcTo(s * 0.14, s * 0.22, s * 0.86, s * 0.22, r); ctx.closePath(); ctx.stroke(); }
return c.toDataURL('image/png');
}
/* ---------------- 纹理库(程序化生成) ---------------- */
var TEXTURES = [
{ id: 'kraft', name: '牛皮纸纹', gen: 'kraft' },
{ id: 'dots', name: '圆点', gen: 'dots' },
{ id: 'stripe', name: '斜条纹', gen: 'stripe' },
{ id: 'linen', name: '亚麻', gen: 'linen' },
{ id: 'floral', name: '碎花', gen: 'floral' },
{ id: 'marble', name: '大理石', gen: 'marble' }
];
function textureDataUrl(id) {
var c = document.createElement('canvas');
c.width = c.height = 220;
var ctx = c.getContext('2d');
var t = TEXTURES.find(function (x) { return x.id === id; });
if (!t) return null;
if (t.gen === 'kraft') {
ctx.fillStyle = '#d9b98a'; ctx.fillRect(0, 0, 220, 220);
for (var i = 0; i < 260; i += 1) {
ctx.strokeStyle = 'rgba(150,110,60,' + (0.05 + Math.random() * 0.1) + ')';
ctx.lineWidth = 0.7;
var x = Math.random() * 220, y = Math.random() * 220;
ctx.beginPath(); ctx.moveTo(x, y);
ctx.quadraticCurveTo(x + 14, y + (Math.random() * 8 - 4), x + 30, y + (Math.random() * 6 - 3));
ctx.stroke();
}
} else if (t.gen === 'dots') {
ctx.fillStyle = '#f6efe2'; ctx.fillRect(0, 0, 220, 220);
ctx.fillStyle = '#e2b8a0';
for (var a = 0; a < 7; a += 1) for (var b = 0; b < 7; b += 1) {
ctx.beginPath(); ctx.arc(16 + a * 32 + (b % 2) * 16, 16 + b * 32, 4.5, 0, 7); ctx.fill();
}
} else if (t.gen === 'stripe') {
ctx.fillStyle = '#f2ede2'; ctx.fillRect(0, 0, 220, 220);
ctx.strokeStyle = 'rgba(150,140,120,.35)'; ctx.lineWidth = 7;
for (var s2 = -220; s2 < 440; s2 += 30) { ctx.beginPath(); ctx.moveTo(s2, 0); ctx.lineTo(s2 + 220, 220); ctx.stroke(); }
} else if (t.gen === 'linen') {
ctx.fillStyle = '#efe9db'; ctx.fillRect(0, 0, 220, 220);
for (var v = 0; v < 220; v += 4) { ctx.strokeStyle = 'rgba(120,110,90,.10)'; ctx.beginPath(); ctx.moveTo(v, 0); ctx.lineTo(v, 220); ctx.stroke(); }
for (var h2 = 0; h2 < 220; h2 += 4) { ctx.strokeStyle = 'rgba(120,110,90,.08)'; ctx.beginPath(); ctx.moveTo(0, h2); ctx.lineTo(220, h2); ctx.stroke(); }
} else if (t.gen === 'floral') {
ctx.fillStyle = '#f7f1e8'; ctx.fillRect(0, 0, 220, 220);
for (var f = 0; f < 9; f += 1) {
var fx = Math.random() * 220, fy = Math.random() * 220;
ctx.fillStyle = ['#e8b8c0', '#b8c8e0', '#e0d0a0'][f % 3];
for (var p = 0; p < 5; p += 1) {
ctx.beginPath();
ctx.ellipse(fx + Math.cos(p / 5 * 6.28) * 7, fy + Math.sin(p / 5 * 6.28) * 7, 5.5, 3.4, p / 5 * 6.28, 0, 7);
ctx.fill();
}
ctx.fillStyle = '#c8a860'; ctx.beginPath(); ctx.arc(fx, fy, 2.6, 0, 7); ctx.fill();
}
} else if (t.gen === 'marble') {
ctx.fillStyle = '#f0eee9'; ctx.fillRect(0, 0, 220, 220);
for (var m = 0; m < 26; m += 1) {
ctx.strokeStyle = 'rgba(120,118,110,' + (0.08 + Math.random() * 0.16) + ')';
ctx.lineWidth = 0.6 + Math.random() * 1.6;
var mx = Math.random() * 220, my = Math.random() * 220;
ctx.beginPath(); ctx.moveTo(mx, my);
ctx.bezierCurveTo(mx + 40, my + 30 * (Math.random() - 0.5), mx + 80, my - 30 * (Math.random() - 0.5), mx + 130, my + 20 * (Math.random() - 0.5));
ctx.stroke();
}
}
return c.toDataURL('image/jpeg', 0.85);
}
/* ---------------- 3D 快捷色板(包小盒马卡龙色) ---------------- */
var SWATCHES = ['#f6d4d4', '#f8ddc8', '#d8e4f8', '#e2d9f6', '#ffffff', '#f6ecd4', '#f8d8e4', '#e6e6e6', '#b9c2cc', '#5b7ba6'];
var FACE_COLORS = ['#e5484d', '#3b82f6', '#22c55e', '#f59e0b', '#fde68a', '#17140f', '#2dd4bf', '#ec4899', '#a16207', '#94a3b8'];
/* ---------------- 动效(10 种,与包小盒一一对应) ---------------- */
var ANIMS = [
{ id: 'fold', name: '折叠展开', dur: 4 },
{ id: 'spinFlat', name: '物体平视自转一圈', dur: 5 },
{ id: 'spinTop', name: '物体俯视自转一周', dur: 3 },
{ id: 'dropSpin', name: '旋转掉落', dur: 4 },
{ id: 'zoomIn', name: '由远到近', dur: 4 },
{ id: 'dropZoom', name: '掉落后放大细节', dur: 8 },
{ id: 'zoomDetail', name: '由远到近放大细节', dur: 4 },
{ id: 'fromLeft', name: '从左侧旋转入场', dur: 5 },
{ id: 'curveIn', name: '由远到近曲线入场', dur: 5 },
{ id: 'foldBounce', name: '折叠动画弹跳入场', dur: 5 }
];
window.PL = window.PL || {};
window.PL.boxlib = {
BOXLIB: BOXLIB, BOX_CATS: BOX_CATS, boxById: boxById,
TEMPLATES: TEMPLATES, TEMPLATE_CATS: TEMPLATE_CATS,
ICONS: ICONS, SHAPES: SHAPES, ASSET_CATS: ASSET_CATS, assetSvg: assetSvg, shapeDataUrl: shapeDataUrl,
TEXTURES: TEXTURES, textureDataUrl: textureDataUrl,
SWATCHES: SWATCHES, FACE_COLORS: FACE_COLORS,
ANIMS: ANIMS
};
})();