Skip to content

Commit 1c6011c

Browse files
Copilotcubap
andauthored
Extract duplicate filter construction logic into helper function (#336)
* Initial plan * Extract duplicate filter logic into helper function Co-authored-by: cubap <1119165+cubap@users.noreply.github.com> * Add documentation to clarify when each filter method should be used Co-authored-by: cubap <1119165+cubap@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: cubap <1119165+cubap@users.noreply.github.com>
1 parent 41752f7 commit 1c6011c

1 file changed

Lines changed: 17 additions & 21 deletions

File tree

components/page-tool/index.js

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export default class PageTool extends HTMLElement {
118118
}, 0)
119119
}
120120

121+
// Apply filters to standard transcription interface images (uses CSS classes on imageEl)
121122
updateMainImageFilters(imageEl) {
122123
if (!imageEl) return
123124

@@ -131,6 +132,20 @@ export default class PageTool extends HTMLElement {
131132
imageEl.style.filter = filters.join(' ')
132133
}
133134

135+
// Apply filters to simple transcription interface images (uses component state)
136+
applyFiltersToImage(imageEl) {
137+
if (!imageEl) return
138+
139+
const filters = []
140+
if (this.grayscaleActive) filters.push('grayscale(100%)')
141+
if (this.invertActive) filters.push('invert(100%)')
142+
filters.push(`contrast(${this.contrast}%)`)
143+
filters.push(`brightness(${this.brightness}%)`)
144+
145+
imageEl.style.transition = 'filter 250ms ease'
146+
imageEl.style.filter = filters.join(' ')
147+
}
148+
134149
applyFilters() {
135150
const iface = this.getTranscriptionInterface()
136151
const transcriptionInterface = iface?.shadowRoot
@@ -144,27 +159,8 @@ export default class PageTool extends HTMLElement {
144159
const imgTopImg = transcriptionInterface.querySelector('#imgTop img')
145160
const imgBottomImg = transcriptionInterface.querySelector('#imgBottom img')
146161

147-
if (imgTopImg) {
148-
const filters = []
149-
if (this.grayscaleActive) filters.push('grayscale(100%)')
150-
if (this.invertActive) filters.push('invert(100%)')
151-
filters.push(`contrast(${this.contrast}%)`)
152-
filters.push(`brightness(${this.brightness}%)`)
153-
154-
imgTopImg.style.transition = 'filter 250ms ease'
155-
imgTopImg.style.filter = filters.join(' ')
156-
}
157-
158-
if (imgBottomImg) {
159-
const filters = []
160-
if (this.grayscaleActive) filters.push('grayscale(100%)')
161-
if (this.invertActive) filters.push('invert(100%)')
162-
filters.push(`contrast(${this.contrast}%)`)
163-
filters.push(`brightness(${this.brightness}%)`)
164-
165-
imgBottomImg.style.transition = 'filter 250ms ease'
166-
imgBottomImg.style.filter = filters.join(' ')
167-
}
162+
this.applyFiltersToImage(imgTopImg)
163+
this.applyFiltersToImage(imgBottomImg)
168164

169165
const canvasPanel = transcriptionInterface.querySelector('tpen-line-image')?.shadowRoot?.querySelector('canvas-panel')?.shadowRoot
170166
if (!canvasPanel) return

0 commit comments

Comments
 (0)