-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodeOps.ts
68 lines (58 loc) · 1.67 KB
/
nodeOps.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { RendererOptions } from 'vue'
import {
PDFNodes,
PDFElements,
PDFDocumentElement,
PDFViewElement,
PDFTextElement,
PDFTextNode,
} from './elements'
function noop(fn: string): any {
throw Error(`no-op: ${fn}`)
}
export const nodeMap: Record<string, PDFNodes | PDFElements> = {}
export const nodeOps: RendererOptions<PDFNodes, PDFElements> = {
patchProp: (el, key, prevVal, nextVal) => {
console.log('patchProp', { el, key, prevVal, nextVal })
if (key === 'styles') {
el.styles = { ...el.styles, ...nextVal }
}
},
insert: (child, parent, anchor) => {
if (parent instanceof PDFDocumentElement) {
nodeMap[parent.id] = parent
}
if (!(child.id in nodeMap)) {
nodeMap[child.id] = child
}
parent.children.push(child.id)
child.parent = parent.id
console.log('insert', { parent, child })
},
createElement: (tag) => {
if (tag === 'View') return new PDFViewElement()
if (tag === 'Text') return new PDFTextElement()
console.log(`createElement: ${tag}`)
throw Error(`Illigal tag ${tag}`)
},
createText: (text) => {
console.log(`createText: ${text}`)
return new PDFTextNode(text)
},
parentNode: (node) => {
console.log('parentNode')
return null
},
createComment: (text): any => {
console.log(`createComment ${text}`)
return text
},
setText: () => noop('setText'),
setElementText: () => noop('setElementText'),
nextSibling: () => noop('nextSibling'),
querySelector: () => noop('querySelector'),
setScopeId: () => noop('setScopeId'),
cloneNode: () => noop('cloneNode'),
insertStaticContent: () => noop('insertStaticContent'),
remove: () => noop('remove'),
}