|
| 1 | +/** |
| 2 | + * @vitest-environment jsdom |
| 3 | + */ |
| 4 | +import { describe, expect, it } from 'vitest' |
| 5 | +import { parseShapeNode } from '@/lib/pptx-renderer/model/nodes/shape-node' |
| 6 | +import { parseXml } from '@/lib/pptx-renderer/parser/xml-parser' |
| 7 | +import type { RenderContext } from '@/lib/pptx-renderer/renderer/render-context' |
| 8 | +import { renderShape } from '@/lib/pptx-renderer/renderer/shape-renderer' |
| 9 | + |
| 10 | +const EMPTY_NODE = parseXml( |
| 11 | + '<p:spTree xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" />' |
| 12 | +) |
| 13 | + |
| 14 | +function createContext(): RenderContext { |
| 15 | + const slide = { |
| 16 | + index: 0, |
| 17 | + nodes: [], |
| 18 | + layoutIndex: '', |
| 19 | + rels: new Map(), |
| 20 | + slidePath: 'ppt/slides/slide1.xml', |
| 21 | + showMasterSp: true, |
| 22 | + } |
| 23 | + |
| 24 | + return { |
| 25 | + presentation: { |
| 26 | + width: 960, |
| 27 | + height: 540, |
| 28 | + slides: [slide], |
| 29 | + layouts: new Map(), |
| 30 | + masters: new Map(), |
| 31 | + themes: new Map(), |
| 32 | + slideToLayout: new Map(), |
| 33 | + layoutToMaster: new Map(), |
| 34 | + masterToTheme: new Map(), |
| 35 | + media: new Map(), |
| 36 | + charts: new Map(), |
| 37 | + isWps: false, |
| 38 | + }, |
| 39 | + slide, |
| 40 | + theme: { |
| 41 | + colorScheme: new Map(), |
| 42 | + majorFont: { latin: 'Calibri', ea: '', cs: '' }, |
| 43 | + minorFont: { latin: 'Calibri', ea: '', cs: '' }, |
| 44 | + fillStyles: [], |
| 45 | + lineStyles: [], |
| 46 | + effectStyles: [], |
| 47 | + }, |
| 48 | + master: { |
| 49 | + colorMap: new Map(), |
| 50 | + textStyles: {}, |
| 51 | + placeholders: [], |
| 52 | + spTree: EMPTY_NODE, |
| 53 | + rels: new Map(), |
| 54 | + }, |
| 55 | + layout: { |
| 56 | + placeholders: [], |
| 57 | + spTree: EMPTY_NODE, |
| 58 | + rels: new Map(), |
| 59 | + showMasterSp: true, |
| 60 | + }, |
| 61 | + mediaUrlCache: new Map(), |
| 62 | + colorCache: new Map(), |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +describe('renderShape', () => { |
| 67 | + it('inserts the rect gradient blend group before the main path', () => { |
| 68 | + const node = parseShapeNode( |
| 69 | + parseXml(` |
| 70 | + <p:sp xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" |
| 71 | + xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"> |
| 72 | + <p:nvSpPr><p:cNvPr id="2" name="Rect" /><p:cNvSpPr /><p:nvPr /></p:nvSpPr> |
| 73 | + <p:spPr> |
| 74 | + <a:xfrm><a:off x="0" y="0" /><a:ext cx="914400" cy="914400" /></a:xfrm> |
| 75 | + <a:prstGeom prst="rect"><a:avLst /></a:prstGeom> |
| 76 | + <a:gradFill> |
| 77 | + <a:gsLst> |
| 78 | + <a:gs pos="0"><a:srgbClr val="FF0000" /></a:gs> |
| 79 | + <a:gs pos="100000"><a:srgbClr val="0000FF" /></a:gs> |
| 80 | + </a:gsLst> |
| 81 | + <a:path path="rect" /> |
| 82 | + </a:gradFill> |
| 83 | + </p:spPr> |
| 84 | + </p:sp> |
| 85 | + `) |
| 86 | + ) |
| 87 | + |
| 88 | + const svg = renderShape(node, createContext()).querySelector('svg') |
| 89 | + |
| 90 | + const blendGroup = svg?.querySelector(':scope > g[clip-path]') |
| 91 | + expect(blendGroup?.nextElementSibling?.localName).toBe('path') |
| 92 | + expect(blendGroup?.nextElementSibling?.getAttribute('fill')).toBe('none') |
| 93 | + }) |
| 94 | +}) |
0 commit comments