-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
95 lines (86 loc) · 2.48 KB
/
test.js
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import Filter from "./index"
import * as f from "./index"
//TEST
// <filter id="shadow" x0="-50%" y0="-50%" width="200%" height="200%"
// filterUnits="userSpaceOnUse">
// <feColorMatrix in="SourceGraphic" type="matrix"
// values="1 0 0 0 0
// 0 1 0 0 0
// 0 0 1 0 0
// 0 0 0 -1 1"
// result="INVERSE"/>
// <feColorMatrix in="SourceGraphic" type="matrix"
// values="1 0 0 0 0
// 0 1 0 0 0
// 0 0 1 0 0
// 0 0 0 0.7 0"
// result="ATTENUATED"/>
//
// <feGaussianBlur in="INVERSE" stdDeviation="2" result="SHADOW" />
// <feOffset dy="-3" in="SHADOW" result="SHIFTED_SHADOW"></feOffset>
//
// <feComposite operator="in" in="SHIFTED_SHADOW" in2="SourceGraphic" result="CLIPPED_SHADOW"/>
// <feBlend mode="multiply" in="SourceGraphic" in2="CLIPPED_SHADOW" result="FULL_EFFECT"/>
// <feBlend mode="normal" in="ATTENUATED" in2="FULL_EFFECT" result="OUTPUT"/>
// </filter>
const crossFade = (x, y, amt) =>
Filter.do(function* () {
const attenuated = yield f.feColorMatrix({
in: x,
type: "matrix",
values: `1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 ${amt} 0`,
})
const blend = yield f.feBlend({
in: attenuated,
in2: y,
mode: "normal",
})
return Filter.done(blend)
})
const innerShadow = (source) =>
Filter.do(function* () {
const inverse = yield f.feColorMatrix({
in: source,
type: "matrix",
values: `1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 -1 1`,
})
const shadow = yield f.feGaussianBlur({
in: inverse,
stdDeviation: 2,
})
const shifted = yield f.feOffset({
in: shadow,
dy: -3,
})
const clipped = yield f.feComposite({
in: shifted,
in2: source,
operator: "in",
})
const full = yield f.feBlend({
in: source,
in2: clipped,
mode: "multiply",
})
const blend = yield crossFade(source, full, 0.7)
return Filter.done(blend)
})
const program = Filter.do(function* () {
const source = yield f.sourceGraphic()
const shadow = yield innerShadow(source)
return Filter.done(shadow)
})
const filter = Filter(program, {
id: "shadow",
x0: "-50%",
y0: "-50%",
width: "200%",
height: "200%",
})
console.log(filter.print())