/* DevBox · CSS / SVG 生成器 */ (function () { 'use strict' const { genTool: G } = DB const preview = (css, html) => { const box = document.createElement('div'); box.className = 'cssdemo'; box.style.cssText = css; if (html) box.innerHTML = html; return box } G({ id: 'css-gradient', name: 'CSS 渐变生成', group: 'web', icon: 'palette', desc: '线性 / 径向渐变,色标数量可调,一键复制 CSS', keywords: ['gradient', '渐变', 'css'], fields: [ { key: 'type', label: '类型', type: 'select', value: 'linear', options: [['linear', '线性'], ['radial', '径向']] }, { key: 'angle', label: '角度', type: 'number', value: 135, min: 0, max: 360 }, { key: 'c1', label: '色 1', type: 'text', value: '#5b8cff' }, { key: 'c2', label: '色 2', type: 'text', value: '#9d6bff' }, { key: 'c3', label: '色 3', type: 'text', value: '#33d6a6' }], run: ({ type, angle, c1, c2, c3 }) => { const grad = type === 'linear' ? `linear-gradient(${angle}deg, ${c1}, ${c2}, ${c3})` : `radial-gradient(circle at 50% 50%, ${c1}, ${c2}, ${c3})` window.__lastCss = { background: grad } return { text: `background: ${grad};`, hint: '已实时预览(下载/复制直接用)' } } }) G({ id: 'box-shadow', name: 'CSS 阴影生成', group: 'web', icon: 'box', desc: '多层阴影可叠加,卡片、按钮的立体感', keywords: ['shadow', '阴影', 'css'], fields: [ { key: 'x', label: 'X', type: 'number', value: 0, min: -100 }, { key: 'y', label: 'Y', type: 'number', value: 12, min: -100 }, { key: 'blur', label: '模糊', type: 'number', value: 30, min: 0 }, { key: 'spread', label: '扩散', type: 'number', value: -6, min: -100 }, { key: 'color', label: '颜色', type: 'text', value: 'rgba(0,0,0,.35)' }, { key: 'inset', label: '内阴影', type: 'check', value: false }], run: ({ x, y, blur, spread, color, inset }) => ({ text: `box-shadow: ${inset ? 'inset ' : ''}${x}px ${y}px ${blur}px ${spread}px ${color};` }) }) G({ id: 'border-radius', name: '圆角生成', group: 'web', icon: 'box', desc: '八点圆角,不对称那种圆润感也能做', keywords: ['radius', '圆角', 'css'], fields: [ { key: 'a', label: '左上', type: 'number', value: 16 }, { key: 'b', label: '右上', type: 'number', value: 16 }, { key: 'c', label: '右下', type: 'number', value: 16 }, { key: 'd', label: '左下', type: 'number', value: 16 }], run: ({ a, b, c, d }) => ({ text: `border-radius: ${a}px ${b}px ${c}px ${d}px;` }) }) G({ id: 'css-triangle', name: 'CSS 三角形', group: 'web', icon: 'box', desc: '朝上/下/左/右的三角,尖角还有斜边,一句话给 CSS', keywords: ['triangle', '三角形', 'css'], fields: [ { key: 'dir', label: '方向', type: 'select', value: 'up', options: [['up', '朝上'], ['down', '朝下'], ['left', '朝左'], ['right', '朝右']] }, { key: 'size', label: '边长', type: 'number', value: 20 }, { key: 'color', label: '颜色', type: 'text', value: '#5b8cff' }], run: ({ dir, size, color }) => { const s = size; const map = { up: [s, s, 0, s], down: [0, s, s, s], left: [s, s, s, 0], right: [s, 0, s, s] } return { text: `width: 0; height: 0; border-width: ${map[dir].join('px ')}px; border-style: solid; border-color: ${dir === 'up' ? `transparent transparent ${color} transparent` : dir === 'down' ? `${color} transparent transparent transparent` : dir === 'left' ? `transparent ${color} transparent transparent` : `transparent transparent transparent ${color}`};` } } }) G({ id: 'glassmorphism', name: '毛玻璃卡片', group: 'web', icon: 'palette', desc: '半透明 + 模糊 + 细边,生成现成的玻璃卡片样式', keywords: ['glass', '毛玻璃', '模糊'], fields: [{ key: 'blur', label: '模糊', type: 'number', value: 18 }, { key: 'alpha', label: '透明度', type: 'text', value: '0.12' }], run: ({ blur, alpha }) => ({ text: `.glass {\n background: rgba(255, 255, 255, ${alpha});\n backdrop-filter: blur(${blur}px);\n -webkit-backdrop-filter: blur(${blur}px);\n border: 1px solid rgba(255, 255, 255, 0.22);\n border-radius: 16px;\n box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);\n}` }) }) G({ id: 'grid-generator', name: '网格背景图', group: 'web', icon: 'box', desc: 'CSS 网格 / 点阵背景,一行搞定', keywords: ['grid', '网格', '背景'], fields: [{ key: 'size', label: '格子', type: 'number', value: 24 }, { key: 'color', label: '线色', type: 'text', value: 'rgba(255,255,255,.08)' }, { key: 'dot', label: '点阵', type: 'check', value: false }], run: ({ size, color, dot }) => ({ text: dot ? `background-image: radial-gradient(${color} 1px, transparent 1px);\nbackground-size: ${size}px ${size}px;` : `background-image: linear-gradient(${color} 1px, transparent 1px), linear-gradient(90deg, ${color} 1px, transparent 1px);\nbackground-size: ${size}px ${size}px;` }) }) G({ id: 'clip-path', name: 'clip-path 裁剪', group: 'web', icon: 'box', desc: '常用多边形裁剪:六边形、菱形、斜角、箭尾', keywords: ['clip-path', '裁剪', '多边形'], fields: [{ key: 'shape', label: '形状', type: 'select', value: 'hex', options: [['hex', '六边形'], ['diamond', '菱形'], ['cut', '斜角'], ['arrow', '箭尾'], ['badge', '徽章']] }], run: ({ shape }) => { const P = { hex: 'polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%)', diamond: 'polygon(50% 0, 100% 50%, 50% 100%, 0 50%)', cut: 'polygon(0 0, 100% 0, 100% 70%, 70% 100%, 0 100%)', arrow: 'polygon(0 0, 80% 0, 100% 50%, 80% 100%, 0 100%)', badge: 'polygon(0 0, 100% 0, 100% 75%, 50% 100%, 0 75%)' } return { text: `clip-path: ${P[shape]};` } } }) G({ id: 'svg-wave', name: 'SVG 波浪分隔', group: 'web', icon: 'code', desc: '生成波浪形状的内联 SVG,做区块分隔很好看', keywords: ['svg', 'wave', '波浪'], fields: [{ key: 'w', label: '宽', type: 'number', value: 1200, min: 100 }, { key: 'h', label: '高', type: 'number', value: 90, min: 20 }, { key: 'color', label: '颜色', type: 'text', value: '#5b8cff' }], run: ({ w, h, color }) => { const d = `M0 ${h * .6} C ${w * .15} ${h * .1}, ${w * .35} ${h * .95}, ${w * .5} ${h * .55} S ${w * .85} ${h * .1}, ${w} ${h * .5} L ${w} ${h} L 0 ${h} Z` return { text: `\n \n` } } }) G({ id: 'svg-pattern', name: 'SVG 图案背景', group: 'web', icon: 'code', desc: '斜纹、圆点、方格、三角,直接当 background-image', keywords: ['svg', 'pattern', '图案', '背景'], fields: [{ key: 'kind', label: '样式', type: 'select', value: 'diag', options: [['diag', '斜纹'], ['dot', '圆点'], ['grid', '方格'], ['tri', '三角']] }, { key: 'color', label: '颜色', type: 'text', value: '%235b8cff' }, { key: 'size', label: '尺寸', type: 'number', value: 16 }], run: ({ kind, color, size }) => { const c = color.startsWith('%23') ? color : '%23' + color.replace('#', '') const s = kind === 'diag' ? `` : kind === 'dot' ? `` : kind === 'grid' ? `` : `` return { text: `background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='${size}' height='${size}'%3E${s.replace(/#/g, '%23')}%3C/svg%3E");` } } }) G({ id: 'svg-blob', name: 'SVG 不规则形状', group: 'web', icon: 'code', desc: '随机圆润的 blob 形状,做头像底、装饰块', keywords: ['svg', 'blob', '形状'], fields: [{ key: 'seed', label: '随机种子', type: 'number', value: 7 }], run: ({ seed }) => { let x = seed * 9301 + 49297; const rnd = () => { x = (x * 9301 + 49297) % 233280; return x / 233280 } const pts = Array.from({ length: 8 }, (_, i) => { const a = (i / 8) * Math.PI * 2; const r = 38 + rnd() * 14; return [50 + Math.cos(a) * r, 50 + Math.sin(a) * r] }) const d = pts.map(([px, py], i) => { const [nx, ny] = pts[(i + 1) % pts.length]; const mx = (px + nx) / 2, my = (py + ny) / 2; return `${i ? 'Q' : 'M'}${px.toFixed(1)} ${py.toFixed(1)} ${mx.toFixed(1)} ${my.toFixed(1)}` }).join(' ') + ' Z' return { text: `\n \n` } } }) G({ id: 'css-loader', name: 'CSS 加载动画', group: 'web', icon: 'bolt', desc: '几个现成的纯 CSS 加载动画,直接抄走', keywords: ['loader', '加载', '动画', 'spinner'], fields: [{ key: 'kind', label: '样式', type: 'select', value: 'ring', options: [['ring', '转圈'], ['dots', '三点'], ['bar', '进度条'], ['pulse', '呼吸']] }, { key: 'color', label: '颜色', type: 'text', value: '#5b8cff' }], run: ({ kind, color }) => { const MAP = { ring: `.loader{width:34px;height:34px;border-radius:50%;border:3px solid rgba(255,255,255,.18);border-top-color:${color};animation:spin .8s linear infinite}\n@keyframes spin{to{transform:rotate(360deg)}}`, dots: `.loader{display:flex;gap:6px}.loader i{width:9px;height:9px;border-radius:50%;background:${color};animation:bounce .6s ease-in-out infinite alternate}\n.loader i:nth-child(2){animation-delay:.15s}.loader i:nth-child(3){animation-delay:.3s}\n@keyframes bounce{to{transform:translateY(-9px);opacity:.5}}`, bar: `.loader{width:180px;height:6px;border-radius:3px;background:rgba(255,255,255,.15);overflow:hidden;position:relative}\n.loader:after{content:'';position:absolute;inset:0;width:40%;background:${color};animation:slide 1.1s ease-in-out infinite}\n@keyframes slide{0%{left:-40%}100%{left:100%}}`, pulse: `.loader{width:30px;height:30px;border-radius:50%;background:${color};animation:pulse 1.1s ease-in-out infinite}\n@keyframes pulse{0%,100%{transform:scale(.7);opacity:.55}50%{transform:scale(1);opacity:1}}` } return { text: MAP[kind] } } }) })()