Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 0 additions & 78 deletions scratch2/filter.js

This file was deleted.

81 changes: 45 additions & 36 deletions scratch2/style.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import SVG from "./draw.js"
import Color from "../shared/color.js"
import Filter from "./filter.js"
import cssContent from "./style.css.js"

export default class Style {
Expand Down Expand Up @@ -1317,49 +1316,59 @@ export default class Style {
}

static bevelFilter(id, inset) {
const f = new Filter(id)
return SVG.withChildren(
SVG.el("filter", { id, x: "0", y: "0", width: "1", height: "1" }),
[
SVG.el("feOffset", { dx: inset ? "1" : "-1", dy: inset ? "1" : "-1", in: "SourceAlpha" }),
SVG.el("feGaussianBlur", { stdDeviation: "1", edgeMode: "none" }),
SVG.el("feColorMatrix", { type: "matrix", values: `
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 -.7 .7
`, result: "shadow" }),

const alpha = "SourceAlpha"
const s = inset ? -1 : 1
const blur = f.blur(1, alpha)
SVG.el("feOffset", { dx: inset ? "-1" : "1", dy: inset ? "-1" : "1", in: "SourceAlpha" }),
SVG.el("feGaussianBlur", { stdDeviation: "1", edgeMode: "none" }),
SVG.el("feColorMatrix", { type: "matrix", values: `
0 0 0 0 1
0 0 0 0 1
0 0 0 0 1
0 0 0 -.15 .15
` }),

f.merge([
"SourceGraphic",
f.comp(
"in",
f.flood("#fff", 0.15),
f.subtract(alpha, f.offset(+s, +s, blur)),
),
f.comp(
"in",
f.flood("#000", 0.7),
f.subtract(alpha, f.offset(-s, -s, blur)),
),
])

return f.el
SVG.el("feComposite", { operator: "atop", in2: "SourceGraphic" }),
SVG.el("feComposite", { operator: "atop", in: "shadow" }),
],
)
}

static darkFilter(id) {
const f = new Filter(id)

f.merge([
"SourceGraphic",
f.comp("in", f.flood("#000", 0.2), "SourceAlpha"),
])

return f.el
return SVG.withChildren(
SVG.el("filter", { id, x: "0", y: "0", width: "1", height: "1" }),
[
SVG.el("feColorMatrix", { type: "matrix", values: `
.8 0 0 0 0
0 .8 0 0 0
0 0 .8 0 0
0 0 0 1 0
` }),
],
)
}

static lightFilter(id) {
const f = new Filter(id)

f.merge([
"SourceGraphic",
f.comp("in", f.flood("#fff", 0.4), "SourceAlpha"),
])

return f.el
return SVG.withChildren(
SVG.el("filter", { id, x: "0", y: "0", width: "1", height: "1" }),
[
SVG.el("feColorMatrix", { type: "matrix", values: `
.6 0 0 0 .4
0 .6 0 0 .4
0 0 .6 0 .4
0 0 0 1 0
` }),
],
)
}

static darkRect(w, h, color, el) {
Expand Down
88 changes: 0 additions & 88 deletions scratch3/filter.js

This file was deleted.

20 changes: 11 additions & 9 deletions scratch3/style.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import SVG from "./draw.js"
import Color from "../shared/color.js"
import cssContent from "./style.css.js"
import Filter from "./filter.js"

// Need to define here, as we cannot reference Style#makeNewIcons
// during JS loading phase.
Expand Down Expand Up @@ -2339,13 +2338,16 @@ export default class Style {
}

static zebraFilter(id, isDark) {
const f = new Filter(id)

f.merge([
"SourceGraphic",
f.comp("in", f.flood(isDark ? "#000" : "#fff", 0.3), "SourceAlpha"),
])

return f.el
return SVG.withChildren(
SVG.el("filter", { id, x: "0", y: "0", width: "1", height: "1" }),
[
SVG.el("feColorMatrix", { type: "matrix", values: `
.7 0 0 0 ${isDark ? 0 : .3}
0 .7 0 0 ${isDark ? 0 : .3}
0 0 .7 0 ${isDark ? 0 : .3}
0 0 0 1 0
` }),
],
)
}
}
1 change: 1 addition & 0 deletions snap/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2636,6 +2636,7 @@ export class DocumentView {

group.querySelectorAll(".snap-drop-shadow").forEach(el => {
el.style.filter = `url(#snapDropShadow-${this.id})`
el.setAttribute("transform", `${el.getAttribute("transform") || ""} translate(-1 -1)`)
})
group.querySelectorAll(".snap-bevel").forEach(el => {
el.style.filter = `url(#snapBevelFilter-${this.id})`
Expand Down
Loading