MCPcopy Index your code
hub / github.com/easydiffusion/easydiffusion / constructor

Method constructor

ui/media/js/image-editor.js:432–546  ·  view source on GitHub ↗
(popup, inpainter = false)

Source from the content-addressed store, hash-verified

430
431class ImageEditor {
432 constructor(popup, inpainter = false) {
433 this.inpainter = inpainter
434 this.popup = popup
435 this.history = new EditorHistory(this)
436 if (inpainter) {
437 this.popup.classList.add("inpainter")
438 }
439 this.drawing = false
440 this.temp_previous_tool = null // used for the ctrl-colorpicker functionality
441 this.container = popup.querySelector(".editor-controls-center > div")
442 this.layers = {}
443 var layer_names = ["background", "drawing", "overlay"]
444 layer_names.forEach((name) => {
445 let canvas = document.createElement("canvas")
446 canvas.className = `editor-canvas-${name}`
447 this.container.appendChild(canvas)
448 this.layers[name] = {
449 name: name,
450 canvas: canvas,
451 ctx: canvas.getContext("2d"),
452 }
453 })
454 this.containerScale = 1.0
455
456 // add mouse handlers
457 this.container.addEventListener("mousedown", this.mouseHandler.bind(this))
458 this.container.addEventListener("mouseup", this.mouseHandler.bind(this))
459 this.container.addEventListener("mousemove", this.mouseHandler.bind(this))
460 this.container.addEventListener("mouseout", this.mouseHandler.bind(this))
461 this.container.addEventListener("mouseenter", this.mouseHandler.bind(this))
462
463 this.container.addEventListener("touchstart", this.mouseHandler.bind(this))
464 this.container.addEventListener("touchmove", this.mouseHandler.bind(this))
465 this.container.addEventListener("touchcancel", this.mouseHandler.bind(this))
466 this.container.addEventListener("touchend", this.mouseHandler.bind(this))
467
468 // initialize editor controls
469 this.options = {}
470 this.optionElements = {}
471 IMAGE_EDITOR_SECTIONS.forEach((section) => {
472 section.id = `image_editor_${section.name}`
473 var sectionElement = document.createElement("div")
474 sectionElement.className = section.id
475
476 var title = document.createElement("h4")
477 title.innerText = section.title
478 sectionElement.appendChild(title)
479
480 var optionsContainer = document.createElement("div")
481 optionsContainer.classList.add("editor-options-container")
482
483 this.optionElements[section.name] = []
484 section.options.forEach((option, index) => {
485 var optionHolder = document.createElement("div")
486 var optionElement = document.createElement("div")
487 optionHolder.appendChild(optionElement)
488 section.initElement(optionElement, option)
489 optionElement.addEventListener("click", (target) => this.selectOption(section.name, index))

Callers

nothing calls this directly

Calls 9

selectOptionMethod · 0.95
runActionMethod · 0.95
setSizeMethod · 0.95
pushMethod · 0.80
appendMethod · 0.80
addMethod · 0.45
appendChildMethod · 0.45
addEventListenerMethod · 0.45
bindMethod · 0.45

Tested by

no test coverage detected