/*!
* Jodit Editor (https://xdsoft.net/jodit/)
* Released under MIT see LICENSE.txt in the project root for license information.
* Copyright (c) 2013-2025 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
*/
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import * as consts from "../../core/constants.js";
import { IS_ES_NEXT, IS_IE, KEY_ALT } from "../../core/constants.js";
import { autobind, watch } from "../../core/decorators/index.js";
import { Dom } from "../../core/dom/dom.js";
import { eventEmitter, pluginSystem } from "../../core/global.js";
import { $$, attr, css, dataBind, innerWidth, markOwner, offset } from "../../core/helpers/index.js";
import { Plugin } from "../../core/plugin/plugin.js";
import "./config.js";
const keyBInd = '__jodit-resizer_binded';
/**
* The module creates a supporting frame for resizing of the elements img and table
*/
export class resizer extends Plugin {
constructor() {
super(...arguments);
this.LOCK_KEY = 'resizer';
this.element = null;
this.isResizeMode = false;
this.isShown = false;
this.startX = 0;
this.startY = 0;
this.width = 0;
this.height = 0;
this.ratio = 0;
this.rect = this.j.c.fromHTML(`
`);
this.sizeViewer = this.rect.getElementsByTagName('span')[0];
this.pointerX = 0;
this.pointerY = 0;
this.isAltMode = false;
this.onClickElement = (element) => {
if (this.isResizeMode) {
return;
}
if (this.element !== element || !this.isShown) {
this.element = element;
this.show();
if (Dom.isTag(this.element, 'img') && !this.element.complete) {
this.j.e.one(this.element, 'load', this.updateSize);
}
}
};
this.updateSize = () => {
if (this.isInDestruct || !this.isShown) {
return;
}
if (this.element && this.rect) {
const workplacePosition = this.getWorkplacePosition();
const pos = offset(this.element, this.j, this.j.ed), left = parseInt(this.rect.style.left || '0', 10), top = parseInt(this.rect.style.top || '0', 10), w = this.rect.offsetWidth, h = this.rect.offsetHeight;
const newTop = pos.top - workplacePosition.top, newLeft = pos.left - workplacePosition.left;
if (top !== newTop ||
left !== newLeft ||
w !== this.element.offsetWidth ||
h !== this.element.offsetHeight) {
css(this.rect, {
top: newTop,
left: newLeft,
width: this.element.offsetWidth,
height: this.element.offsetHeight
});
if (this.j.events) {
this.j.e.fire(this.element, 'changesize');
// check for first init. Ex. inlinePopup hides when it was fired
if (!isNaN(left)) {
this.j.e.fire('resize');
}
}
}
}
};
this.hideSizeViewer = () => {
this.sizeViewer.style.opacity = '0';
};
}
/** @override */
afterInit(editor) {
$$('div', this.rect).forEach((resizeHandle) => {
editor.e.on(resizeHandle, 'mousedown.resizer touchstart.resizer', this.onStartResizing.bind(this, resizeHandle));
});
eventEmitter.on('hideHelpers', this.hide);
editor.e
.on('readonly', (isReadOnly) => {
if (isReadOnly) {
this.hide();
}
})
.on('afterInit changePlace', this.addEventListeners.bind(this))
.on('afterGetValueFromEditor.resizer', (data) => {
const rgx = /]+data-jodit_iframe_wrapper[^>]+>(.*?