@@ -17,6 +17,11 @@ import { AnnotationEditorParamsType, shadow } from "../../shared/util.js";
1717import { KeyboardManager } from "./tools.js" ;
1818import { noContextMenu } from "../display_utils.js" ;
1919
20+ /**
21+ * ColorPicker class provides a color picker for the annotation editor.
22+ * It displays a dropdown with some predefined colors and allows the user
23+ * to select a color for the annotation.
24+ */
2025class ColorPicker {
2126 #button = null ;
2227
@@ -304,4 +309,64 @@ class ColorPicker {
304309 }
305310}
306311
307- export { ColorPicker } ;
312+ /**
313+ * BasicColorPicker class provides a simple color picker.
314+ * It displays an input element (with type="color") that allows the user
315+ * to select a color for the annotation.
316+ */
317+ class BasicColorPicker {
318+ #input = null ;
319+
320+ #editor = null ;
321+
322+ #uiManager = null ;
323+
324+ static #l10nColor = null ;
325+
326+ constructor ( editor ) {
327+ this . #editor = editor ;
328+ this . #uiManager = editor . _uiManager ;
329+
330+ BasicColorPicker . #l10nColor ||= Object . freeze ( {
331+ freetext : "pdfjs-editor-color-picker-free-text-input" ,
332+ ink : "pdfjs-editor-color-picker-ink-input" ,
333+ } ) ;
334+ }
335+
336+ renderButton ( ) {
337+ if ( this . #input) {
338+ return this . #input;
339+ }
340+ const { editorType, colorType, colorValue } = this . #editor;
341+ const input = ( this . #input = document . createElement ( "input" ) ) ;
342+ input . type = "color" ;
343+ input . value = colorValue || "#000000" ;
344+ input . className = "basicColorPicker" ;
345+ input . tabIndex = 0 ;
346+ input . setAttribute ( "data-l10n-id" , BasicColorPicker . #l10nColor[ editorType ] ) ;
347+ input . addEventListener (
348+ "input" ,
349+ ( ) => {
350+ this . #uiManager. updateParams ( colorType , input . value ) ;
351+ } ,
352+ { signal : this . #uiManager. _signal }
353+ ) ;
354+ return input ;
355+ }
356+
357+ update ( value ) {
358+ if ( ! this . #input) {
359+ return ;
360+ }
361+ this . #input. value = value ;
362+ }
363+
364+ destroy ( ) {
365+ this . #input?. remove ( ) ;
366+ this . #input = null ;
367+ }
368+
369+ hideDropdown ( ) { }
370+ }
371+
372+ export { BasicColorPicker , ColorPicker } ;
0 commit comments