@@ -37,7 +37,11 @@ import {
3737 Util ,
3838 warn ,
3939} from "../shared/util.js" ;
40- import { PDFDateString , setLayerDimensions } from "./display_utils.js" ;
40+ import {
41+ changeLightness ,
42+ PDFDateString ,
43+ setLayerDimensions ,
44+ } from "./display_utils.js" ;
4145import { AnnotationStorage } from "./annotation_storage.js" ;
4246import { ColorConverters } from "../shared/scripting_utils.js" ;
4347import { DOMSVGFactory } from "./svg_factory.js" ;
@@ -232,46 +236,13 @@ class AnnotationElement {
232236 const opacity = this . data . opacity ?? 1 ;
233237 const oppositeOpacity = 255 * ( 1 - opacity ) ;
234238
235- return this . # changeLightness(
239+ return changeLightness (
236240 Math . min ( r + oppositeOpacity , 255 ) ,
237241 Math . min ( g + oppositeOpacity , 255 ) ,
238242 Math . min ( b + oppositeOpacity , 255 )
239243 ) ;
240244 }
241245
242- #changeLightness( r , g , b ) {
243- r /= 255 ;
244- g /= 255 ;
245- b /= 255 ;
246-
247- const max = Math . max ( r , g , b ) ;
248- const min = Math . min ( r , g , b ) ;
249- const l = ( max + min ) / 2 ;
250- const newL = ( ( ( 1 + Math . sqrt ( l ) ) / 2 ) * 100 ) . toFixed ( 2 ) ;
251-
252- if ( max === min ) {
253- // gray
254- return `hsl(0, 0%, ${ newL } %)` ;
255- }
256-
257- const d = max - min ;
258-
259- // hue (branch on max only; avoids mod)
260- let h ;
261- if ( max === r ) {
262- h = ( g - b ) / d + ( g < b ? 6 : 0 ) ;
263- } else if ( max === g ) {
264- h = ( b - r ) / d + 2 ;
265- } else {
266- // max === b
267- h = ( r - g ) / d + 4 ;
268- }
269- h = ( h * 60 ) . toFixed ( 2 ) ;
270- const s = ( ( d / ( 1 - Math . abs ( 2 * l - 1 ) ) ) * 100 ) . toFixed ( 2 ) ;
271-
272- return `hsl(${ h } , ${ s } %, ${ newL } %)` ;
273- }
274-
275246 _normalizePoint ( point ) {
276247 const {
277248 page : { view } ,
0 commit comments