PPTX
效果与填充
为形状应用阴影、发光、3D 效果和各种填充类型
通过视觉效果(阴影、发光、3D)和填充(纯色、渐变、图片、透明)增强形状。
纯色填充
import { generatePresentation } from "@office-open/pptx";
{
"slides": [
{
"children": [
{
"shape": {
"x": "1.3cm",
"y": "1.3cm",
"width": "10.6cm",
"height": "6.6cm",
"fill": { "type": "solid", "color": "2E74B5" }
}
}
]
}
]
}
{
children: [
{
shape: {
x: "1.3cm",
y: "1.3cm",
width: "10.6cm",
height: "6.6cm",
fill: { type: "solid", color: "2E74B5" },
},
},
],
}
简写形式 -- 直接传入颜色字符串:
{
"slides": [
{
"children": [
{
"shape": {
"x": "1.3cm",
"y": "1.3cm",
"width": "10.6cm",
"height": "6.6cm",
"fill": "2E74B5"
}
}
]
}
]
}
{
children: [
{
shape: {
x: "1.3cm",
y: "1.3cm",
width: "10.6cm",
height: "6.6cm",
fill: "2E74B5",
},
},
],
}
渐变填充
线性渐变(带角度)
{
"slides": [
{
"children": [
{
"shape": {
"x": "1.3cm",
"y": "1.3cm",
"width": "15.9cm",
"height": "6.6cm",
"fill": {
"type": "gradient",
"stops": [
{ "position": 0, "color": "0D47A1" },
{ "position": 100, "color": "42A5F5" }
],
"angle": 45
}
}
}
]
}
]
}
{
children: [
{
shape: {
x: "1.3cm",
y: "1.3cm",
width: "15.9cm",
height: "6.6cm",
fill: {
type: "gradient",
stops: [
{ position: 0, color: "0D47A1" },
{ position: 100, color: "42A5F5" },
],
angle: 45,
},
},
},
],
}
径向渐变(带路径)
{
"slides": [
{
"children": [
{
"shape": {
"x": "1.3cm",
"y": "1.3cm",
"width": "10.6cm",
"height": "10.6cm",
"geometry": "ellipse",
"fill": {
"type": "gradient",
"stops": [
{ "position": 0, "color": "FFFFFF" },
{ "position": 100, "color": "1565C0" }
],
"path": "circle"
}
}
}
]
}
]
}
{
children: [
{
shape: {
x: "1.3cm",
y: "1.3cm",
width: "10.6cm",
height: "10.6cm",
geometry: "ellipse",
fill: {
type: "gradient",
stops: [
{ position: 0, color: "FFFFFF" },
{ position: 100, color: "1565C0" },
],
path: "circle",
},
},
},
],
}
多色标渐变
{
"slides": [
{
"children": [
{
"shape": {
"x": "1.3cm",
"y": "1.3cm",
"width": "15.9cm",
"height": "6.6cm",
"fill": {
"type": "gradient",
"stops": [
{ "position": 0, "color": "E53935" },
{ "position": 50, "color": "FF9800" },
{ "position": 100, "color": "FFEB3B" }
],
"angle": 90
}
}
}
]
}
]
}
{
children: [
{
shape: {
x: "1.3cm",
y: "1.3cm",
width: "15.9cm",
height: "6.6cm",
fill: {
type: "gradient",
stops: [
{ position: 0, color: "E53935" },
{ position: 50, color: "FF9800" },
{ position: 100, color: "FFEB3B" },
],
angle: 90,
},
},
},
],
}
图片填充(Blip Fill)
data 字段接受原始字节(Uint8Array、ArrayBuffer、Buffer),也支持 base64 data URL(如 data:image/png;base64,...)。
import * as fs from "node:fs";
{
"slides": [
{
"children": [
{
"shape": {
"x": "1.3cm",
"y": "1.3cm",
"width": "15.9cm",
"height": "9.3cm",
"fill": {
"type": "blip",
"data": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=",
"imageType": "png"
}
}
}
]
}
]
}
{
children: [
{
shape: {
x: "1.3cm",
y: "1.3cm",
width: "15.9cm",
height: "9.3cm",
fill: {
type: "blip",
data: new Uint8Array(fs.readFileSync("texture.png")),
imageType: "png",
},
},
},
],
}
无填充(透明)
{
"slides": [
{
"children": [
{
"shape": {
"x": "1.3cm",
"y": "1.3cm",
"width": "13.2cm",
"height": "6.6cm",
"fill": { "type": "none" },
"outline": { "color": "2E74B5", "width": 2 }
}
}
]
}
]
}
{
children: [
{
shape: {
x: "1.3cm",
y: "1.3cm",
width: "13.2cm",
height: "6.6cm",
fill: { type: "none" },
outline: { color: "2E74B5", width: 12700 },
},
},
],
}
轮廓
{
"slides": [
{
"children": [
{
"shape": {
"x": "1.3cm",
"y": "1.3cm",
"width": "13.2cm",
"height": "6.6cm",
"fill": { "type": "solid", "color": "E3F2FD" },
"outline": {
"color": "1565C0",
"width": "0.1cm",
"dashStyle": "solid"
}
}
}
]
}
]
}
{
children: [
{
shape: {
x: "1.3cm",
y: "1.3cm",
width: "13.2cm",
height: "6.6cm",
fill: { type: "solid", color: "E3F2FD" },
outline: {
color: "1565C0",
width: "336.0cm", // 宽度(EMU,12700 = 1pt)
dashStyle: "solid", // "solid" | "dash" | "dashDot" | "lgDash" | "sysDot" | "sysDash"
},
},
},
],
}
效果
使用 effects 属性控制阴影、发光、倒影、柔化边缘和 3D 效果:
外部阴影
{
"slides": [
{
"children": [
{
"shape": {
"x": "1.3cm",
"y": "1.3cm",
"width": "5.3cm",
"height": "3.2cm",
"fill": "ED7D31",
"effects": {
"outerShadow": {
"blur": 50800,
"distance": 38100,
"direction": 5400000,
"color": "000000",
"alpha": 50
}
}
}
}
]
}
]
}
{
children: [
{
shape: {
x: "1.3cm",
y: "1.3cm",
width: "5.3cm",
height: "3.2cm",
fill: "ED7D31",
effects: {
outerShadow: {
blur: 50800, // 模糊半径(EMU)
distance: 38100, // 偏移距离(EMU)
direction: 5400000, // 角度(60000分之一度)
color: "000000",
alpha: 50, // 不透明度百分比
},
},
},
},
],
}
内部阴影
{
"slides": [
{
"children": [
{
"shape": {
"x": "1.3cm",
"y": "1.3cm",
"width": "5.3cm",
"height": "3.2cm",
"fill": "5B9BD5",
"effects": {
"innerShadow": {
"blur": 40000,
"distance": 30000,
"direction": 5400000,
"color": "000000",
"alpha": 40
}
}
}
}
]
}
]
}
{
children: [
{
shape: {
x: "1.3cm",
y: "1.3cm",
width: "5.3cm",
height: "3.2cm",
fill: "5B9BD5",
effects: {
innerShadow: {
blur: 40000,
distance: 30000,
direction: 5400000,
color: "000000",
alpha: 40,
},
},
},
},
],
}
发光
{
"slides": [
{
"children": [
{
"shape": {
"x": "1.3cm",
"y": "1.3cm",
"width": "5.3cm",
"height": "3.2cm",
"fill": "70AD47",
"effects": {
"glow": {
"radius": 152400,
"color": "92D050",
"alpha": 60
}
}
}
}
]
}
]
}
{
children: [
{
shape: {
x: "1.3cm",
y: "1.3cm",
width: "5.3cm",
height: "3.2cm",
fill: "70AD47",
effects: {
glow: {
radius: 152400, // 发光半径(EMU)
color: "92D050",
alpha: 60,
},
},
},
},
],
}
倒影
{
"slides": [
{
"children": [
{
"shape": {
"x": "1.3cm",
"y": "1.3cm",
"width": "5.3cm",
"height": "3.2cm",
"fill": "FFC000",
"effects": {
"reflection": {
"blurRadius": 6350,
"distance": 38100,
"direction": 5400000,
"startAlpha": 90,
"endAlpha": 0
}
}
}
}
]
}
]
}
{
children: [
{
shape: {
x: "1.3cm",
y: "1.3cm",
width: "5.3cm",
height: "3.2cm",
fill: "FFC000",
effects: {
reflection: {
blurRadius: 6350,
distance: 38100,
direction: 5400000,
startAlpha: 90, // 起始不透明度百分比
endAlpha: 0, // 结束不透明度百分比
},
},
},
},
],
}
柔化边缘
{
"slides": [
{
"children": [
{
"shape": {
"x": "1.3cm",
"y": "1.3cm",
"width": "5.3cm",
"height": "3.2cm",
"fill": "BF8F00",
"effects": {
"softEdge": { "radius": 50800 }
}
}
}
]
}
]
}
{
children: [
{
shape: {
x: "1.3cm",
y: "1.3cm",
width: "5.3cm",
height: "3.2cm",
fill: "BF8F00",
effects: {
softEdge: { radius: 50800 },
},
},
},
],
}
3D 旋转和斜面
{
"slides": [
{
"children": [
{
"shape": {
"x": "1.3cm",
"y": "1.3cm",
"width": "5.3cm",
"height": "4.0cm",
"fill": "FFC000",
"effects": {
"rotation3D": {
"x": "0.5cm",
"y": "0.8cm",
"z": 10,
"perspective": 500
},
"bevelTop": { "width": 8, "height": 8 },
"extrusionH": 50000,
"material": "plastic"
}
}
}
]
}
]
}
{
children: [
{
shape: {
x: "1.3cm",
y: "1.3cm",
width: "5.3cm",
height: "4.0cm",
fill: "FFC000",
effects: {
rotation3D: {
x: "0.5cm", // X 轴旋转(度)
y: "0.8cm", // Y 轴旋转(度)
z: 10, // Z 轴旋转(度)
perspective: 500, // 透视值
},
bevelTop: { width: 8, height: 8 },
extrusionH: 50000, // 挤出高度(EMU)
material: "plastic", // "plastic" | "metal" | "matte" | "flat"
},
},
},
],
}
组合效果
可以同时应用多种效果:
{
"slides": [
{
"children": [
{
"shape": {
"x": "1.3cm",
"y": "1.3cm",
"width": "5.3cm",
"height": "3.2cm",
"fill": "7030A0",
"effects": {
"outerShadow": {
"blur": 40000,
"distance": 30000,
"direction": 2700000,
"color": "000000",
"alpha": 40
},
"glow": { "radius": 101600, "color": "B381E7", "alpha": 35 }
}
}
}
]
}
]
}
{
children: [
{
shape: {
x: "1.3cm",
y: "1.3cm",
width: "5.3cm",
height: "3.2cm",
fill: "7030A0",
effects: {
outerShadow: {
blur: 40000,
distance: 30000,
direction: 2700000,
color: "000000",
alpha: 40,
},
glow: { radius: 101600, color: "B381E7", alpha: 35 },
},
},
},
],
}
Effects 选项
| 属性 | 类型 | 说明 |
|---|---|---|
outerShadow | ShadowOptions | 外部阴影 |
innerShadow | ShadowOptions | 内部阴影 |
glow | GlowOptions | 发光效果 |
reflection | ReflectionOptions | 倒影效果 |
softEdge | SoftEdgeOptions | 柔化边缘效果 |
rotation3D | Rotation3DOptions | 3D 旋转 |
bevelTop | PPTXBevelOptions | 顶部斜面 |
bevelBottom | PPTXBevelOptions | 底部斜面 |
extrusionH | number | 挤出高度(EMU) |
material | string | 材质类型 |
lighting | string | 灯光类型 |