suneditor 3.0.0-beta.2 → 3.0.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +186 -184
- package/LICENSE +21 -21
- package/README.md +157 -180
- package/dist/suneditor.min.css +1 -1
- package/dist/suneditor.min.js +1 -1
- package/package.json +126 -123
- package/src/assets/design/color.css +131 -121
- package/src/assets/design/index.css +3 -3
- package/src/assets/design/size.css +37 -35
- package/src/assets/design/typography.css +37 -37
- package/src/assets/icons/defaultIcons.js +247 -232
- package/src/assets/suneditor-contents.css +779 -778
- package/src/assets/suneditor.css +43 -35
- package/src/core/base/eventHandlers/handler_toolbar.js +135 -135
- package/src/core/base/eventHandlers/handler_ww_clipboard.js +56 -56
- package/src/core/base/eventHandlers/handler_ww_dragDrop.js +115 -113
- package/src/core/base/eventHandlers/handler_ww_key_input.js +1200 -1200
- package/src/core/base/eventHandlers/handler_ww_mouse.js +194 -194
- package/src/core/base/eventManager.js +1550 -1484
- package/src/core/base/history.js +355 -355
- package/src/core/class/char.js +163 -162
- package/src/core/class/component.js +856 -842
- package/src/core/class/format.js +3433 -3422
- package/src/core/class/html.js +1927 -1890
- package/src/core/class/menu.js +357 -346
- package/src/core/class/nodeTransform.js +424 -424
- package/src/core/class/offset.js +858 -891
- package/src/core/class/selection.js +710 -620
- package/src/core/class/shortcuts.js +98 -98
- package/src/core/class/toolbar.js +438 -430
- package/src/core/class/ui.js +424 -422
- package/src/core/class/viewer.js +750 -750
- package/src/core/editor.js +1810 -1708
- package/src/core/section/actives.js +268 -241
- package/src/core/section/constructor.js +1348 -1661
- package/src/core/section/context.js +102 -102
- package/src/core/section/documentType.js +582 -561
- package/src/core/section/options.js +367 -0
- package/src/core/util/instanceCheck.js +59 -0
- package/src/editorInjector/_classes.js +36 -36
- package/src/editorInjector/_core.js +92 -92
- package/src/editorInjector/index.js +75 -75
- package/src/events.js +634 -622
- package/src/helper/clipboard.js +59 -59
- package/src/helper/converter.js +586 -564
- package/src/helper/dom/domCheck.js +304 -304
- package/src/helper/dom/domQuery.js +677 -669
- package/src/helper/dom/domUtils.js +618 -557
- package/src/helper/dom/index.js +12 -12
- package/src/helper/env.js +249 -240
- package/src/helper/index.js +25 -25
- package/src/helper/keyCodeMap.js +183 -183
- package/src/helper/numbers.js +72 -72
- package/src/helper/unicode.js +47 -47
- package/src/langs/ckb.js +231 -231
- package/src/langs/cs.js +231 -231
- package/src/langs/da.js +231 -231
- package/src/langs/de.js +231 -231
- package/src/langs/en.js +230 -230
- package/src/langs/es.js +231 -231
- package/src/langs/fa.js +231 -231
- package/src/langs/fr.js +231 -231
- package/src/langs/he.js +231 -231
- package/src/langs/hu.js +230 -230
- package/src/langs/index.js +28 -28
- package/src/langs/it.js +231 -231
- package/src/langs/ja.js +230 -230
- package/src/langs/km.js +230 -230
- package/src/langs/ko.js +230 -230
- package/src/langs/lv.js +231 -231
- package/src/langs/nl.js +231 -231
- package/src/langs/pl.js +231 -231
- package/src/langs/pt_br.js +231 -231
- package/src/langs/ro.js +231 -231
- package/src/langs/ru.js +231 -231
- package/src/langs/se.js +231 -231
- package/src/langs/tr.js +231 -231
- package/src/langs/uk.js +231 -231
- package/src/langs/ur.js +231 -231
- package/src/langs/zh_cn.js +231 -231
- package/src/modules/ApiManager.js +191 -191
- package/src/modules/Browser.js +669 -667
- package/src/modules/ColorPicker.js +364 -362
- package/src/modules/Controller.js +474 -454
- package/src/modules/Figure.js +1620 -1617
- package/src/modules/FileManager.js +359 -359
- package/src/modules/HueSlider.js +577 -565
- package/src/modules/Modal.js +346 -346
- package/src/modules/ModalAnchorEditor.js +643 -643
- package/src/modules/SelectMenu.js +549 -549
- package/src/modules/_DragHandle.js +17 -17
- package/src/modules/index.js +14 -14
- package/src/plugins/browser/audioGallery.js +83 -83
- package/src/plugins/browser/fileBrowser.js +103 -103
- package/src/plugins/browser/fileGallery.js +83 -83
- package/src/plugins/browser/imageGallery.js +81 -81
- package/src/plugins/browser/videoGallery.js +103 -103
- package/src/plugins/command/blockquote.js +61 -60
- package/src/plugins/command/exportPDF.js +134 -134
- package/src/plugins/command/fileUpload.js +456 -456
- package/src/plugins/command/list_bulleted.js +149 -148
- package/src/plugins/command/list_numbered.js +152 -151
- package/src/plugins/dropdown/align.js +157 -155
- package/src/plugins/dropdown/backgroundColor.js +108 -104
- package/src/plugins/dropdown/font.js +141 -137
- package/src/plugins/dropdown/fontColor.js +109 -105
- package/src/plugins/dropdown/formatBlock.js +170 -178
- package/src/plugins/dropdown/hr.js +152 -152
- package/src/plugins/dropdown/layout.js +83 -83
- package/src/plugins/dropdown/lineHeight.js +131 -130
- package/src/plugins/dropdown/list.js +123 -122
- package/src/plugins/dropdown/paragraphStyle.js +138 -138
- package/src/plugins/dropdown/table.js +4110 -4000
- package/src/plugins/dropdown/template.js +83 -83
- package/src/plugins/dropdown/textStyle.js +149 -149
- package/src/plugins/field/mention.js +242 -242
- package/src/plugins/index.js +120 -120
- package/src/plugins/input/fontSize.js +414 -410
- package/src/plugins/input/pageNavigator.js +71 -70
- package/src/plugins/modal/audio.js +677 -677
- package/src/plugins/modal/drawing.js +537 -531
- package/src/plugins/modal/embed.js +886 -886
- package/src/plugins/modal/image.js +1377 -1376
- package/src/plugins/modal/link.js +248 -240
- package/src/plugins/modal/math.js +563 -563
- package/src/plugins/modal/video.js +1226 -1226
- package/src/plugins/popup/anchor.js +224 -222
- package/src/suneditor.js +114 -107
- package/src/themes/dark.css +132 -122
- package/src/typedef.js +132 -130
- package/types/assets/icons/defaultIcons.d.ts +8 -0
- package/types/core/base/eventManager.d.ts +29 -4
- package/types/core/class/char.d.ts +2 -1
- package/types/core/class/component.d.ts +1 -2
- package/types/core/class/format.d.ts +8 -1
- package/types/core/class/html.d.ts +8 -0
- package/types/core/class/menu.d.ts +8 -0
- package/types/core/class/offset.d.ts +24 -26
- package/types/core/class/selection.d.ts +2 -0
- package/types/core/class/toolbar.d.ts +6 -0
- package/types/core/class/ui.d.ts +1 -1
- package/types/core/editor.d.ts +34 -12
- package/types/core/section/constructor.d.ts +5 -638
- package/types/core/section/documentType.d.ts +12 -2
- package/types/core/section/options.d.ts +740 -0
- package/types/core/util/instanceCheck.d.ts +50 -0
- package/types/editorInjector/_core.d.ts +5 -5
- package/types/editorInjector/index.d.ts +2 -2
- package/types/events.d.ts +2 -0
- package/types/helper/converter.d.ts +9 -0
- package/types/helper/dom/domQuery.d.ts +5 -5
- package/types/helper/dom/domUtils.d.ts +8 -0
- package/types/helper/env.d.ts +6 -1
- package/types/helper/index.d.ts +4 -1
- package/types/index.d.ts +122 -120
- package/types/langs/_Lang.d.ts +194 -194
- package/types/modules/ColorPicker.d.ts +5 -1
- package/types/modules/Controller.d.ts +8 -4
- package/types/modules/Figure.d.ts +2 -1
- package/types/modules/HueSlider.d.ts +4 -1
- package/types/modules/SelectMenu.d.ts +1 -1
- package/types/plugins/command/blockquote.d.ts +1 -0
- package/types/plugins/command/list_bulleted.d.ts +1 -0
- package/types/plugins/command/list_numbered.d.ts +1 -0
- package/types/plugins/dropdown/align.d.ts +1 -0
- package/types/plugins/dropdown/backgroundColor.d.ts +1 -0
- package/types/plugins/dropdown/font.d.ts +1 -0
- package/types/plugins/dropdown/fontColor.d.ts +1 -0
- package/types/plugins/dropdown/formatBlock.d.ts +3 -2
- package/types/plugins/dropdown/lineHeight.d.ts +1 -0
- package/types/plugins/dropdown/list.d.ts +1 -0
- package/types/plugins/dropdown/table.d.ts +6 -0
- package/types/plugins/input/fontSize.d.ts +1 -0
- package/types/plugins/modal/drawing.d.ts +4 -0
- package/types/plugins/modal/link.d.ts +32 -15
- package/types/suneditor.d.ts +13 -9
- package/types/typedef.d.ts +8 -0
package/src/modules/Figure.js
CHANGED
|
@@ -1,1617 +1,1620 @@
|
|
|
1
|
-
import EditorInjector from '../editorInjector';
|
|
2
|
-
import { Controller, SelectMenu, _DragHandle } from '../modules';
|
|
3
|
-
import { dom, numbers, env, converter, keyCodeMap } from '../helper';
|
|
4
|
-
|
|
5
|
-
const { ON_OVER_COMPONENT } = env;
|
|
6
|
-
const DIRECTION_CURSOR_MAP = { tl: 'nwse-resize', tr: 'nesw-resize', bl: 'nesw-resize', br: 'nwse-resize', lw: 'ew-resize', th: 'ns-resize', rw: 'ew-resize', bh: 'ns-resize' };
|
|
7
|
-
const DIR_DIAGONAL = 'tl|bl|tr|br';
|
|
8
|
-
const DIR_W = 'lw|rw';
|
|
9
|
-
let __resizing_p_wh = false;
|
|
10
|
-
let __resizing_p_ow = false;
|
|
11
|
-
let __resizing_cw = 0;
|
|
12
|
-
let __resizing_sw = 0;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @typedef {Object} FigureParams
|
|
16
|
-
* @property {string} [sizeUnit="px"] Size unit
|
|
17
|
-
* @property {{ current: string, default: string }} [autoRatio=null] Auto ratio { current: '00%', default: '00%' }
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @typedef {Object} FigureInfo
|
|
22
|
-
* @property {HTMLElement} target Target element (img, iframe, video, audio, table, etc.)
|
|
23
|
-
* @property {HTMLElement} container Container element (div.se-component|span.se-component.se-inline-component)
|
|
24
|
-
* @property {?HTMLElement} cover Cover element (FIGURE|null)
|
|
25
|
-
* @property {?HTMLElement} inlineCover Inline cover element (span.se-inline-component)
|
|
26
|
-
* @property {?HTMLElement} caption Caption element (FIGCAPTION)
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @typedef {Object} FigureTargetInfo
|
|
31
|
-
* @property {HTMLElement} container Container element (div.se-component|span.se-component.se-inline-component)
|
|
32
|
-
* @property {?HTMLElement=} cover Cover element (FIGURE|null)
|
|
33
|
-
* @property {?HTMLElement=} caption Caption element (FIGCAPTION)
|
|
34
|
-
* @property {string} [align] - Alignment of the element.
|
|
35
|
-
* @property {{w:number, h:number}} [ratio] - The aspect ratio of the element.
|
|
36
|
-
* @property {string|number} [w] - Width of the element.
|
|
37
|
-
* @property {string|number} [h] - Height of the element.
|
|
38
|
-
* @property {number} [t] - Top position.
|
|
39
|
-
* @property {number} [l] - Left position.
|
|
40
|
-
* @property {string|number} width - Width, can be a number or 'auto'.
|
|
41
|
-
* @property {string|number} height - Height, can be a number or 'auto'.
|
|
42
|
-
* @property {number} [originWidth] - Original width from `naturalWidth` or `offsetWidth`.
|
|
43
|
-
* @property {number} [originHeight] - Original height from `naturalHeight` or `offsetHeight`.
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* @typedef {Array<Array<
|
|
48
|
-
* string |
|
|
49
|
-
* {
|
|
50
|
-
* action: (element: Node, value: string, target: Node) => void,
|
|
51
|
-
* command: string,
|
|
52
|
-
* value: string,
|
|
53
|
-
* title: string,
|
|
54
|
-
* icon: string
|
|
55
|
-
* }
|
|
56
|
-
* >>} FigureControls
|
|
57
|
-
* "mirror". "rotate", "caption", "revert", "edit", "copy", "remove", "as", "resize_auto,[number]"
|
|
58
|
-
*/
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* @class
|
|
62
|
-
* @description Controller module class
|
|
63
|
-
*/
|
|
64
|
-
class Figure extends EditorInjector {
|
|
65
|
-
/**
|
|
66
|
-
* @constructor
|
|
67
|
-
* @param {*} inst The instance object that called the constructor.
|
|
68
|
-
* @param {FigureControls} controls Controller button array
|
|
69
|
-
* @param {FigureParams} params Figure options
|
|
70
|
-
*/
|
|
71
|
-
constructor(inst, controls, params) {
|
|
72
|
-
super(inst.editor);
|
|
73
|
-
this.kind = inst.constructor.key || inst.constructor.name;
|
|
74
|
-
this._alignIcons = {
|
|
75
|
-
none: this.icons.format_float_none,
|
|
76
|
-
left: this.icons.format_float_left,
|
|
77
|
-
right: this.icons.format_float_right,
|
|
78
|
-
center: this.icons.format_float_center
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
// modules
|
|
82
|
-
/** @type {Object<string, *>} */
|
|
83
|
-
this._action = {};
|
|
84
|
-
const controllerEl = CreateHTML_controller(this, controls || []);
|
|
85
|
-
this.controller = new Controller(this, controllerEl, { position: 'bottom', disabled: true }, this.kind);
|
|
86
|
-
// align selectmenu
|
|
87
|
-
this.alignButton = controllerEl.querySelector('[data-command="onalign"]');
|
|
88
|
-
const alignMenus = CreateAlign(this, this.alignButton);
|
|
89
|
-
if (alignMenus) {
|
|
90
|
-
this.selectMenu_align = new SelectMenu(this, { checkList: false, position: 'bottom-center' });
|
|
91
|
-
this.selectMenu_align.on(this.alignButton, this.#SetMenuAlign.bind(this), { class: 'se-figure-select-list' });
|
|
92
|
-
this.selectMenu_align.create(alignMenus.items, alignMenus.html);
|
|
93
|
-
}
|
|
94
|
-
// as [block, inline] selectmenu
|
|
95
|
-
this.asButton = controllerEl.querySelector('[data-command="onas"]');
|
|
96
|
-
const asMenus = CreateAs(this, this.asButton);
|
|
97
|
-
if (asMenus) {
|
|
98
|
-
this.selectMenu_as = new SelectMenu(this, { checkList: false, position: 'bottom-center' });
|
|
99
|
-
this.selectMenu_as.on(this.asButton, this.#SetMenuAs.bind(this), { class: 'se-figure-select-list' });
|
|
100
|
-
this.selectMenu_as.create(asMenus.items, asMenus.html);
|
|
101
|
-
}
|
|
102
|
-
// resize selectmenu
|
|
103
|
-
this.resizeButton = controllerEl.querySelector('[data-command="onresize"]');
|
|
104
|
-
const resizeMenus = CreateResize(this, this.resizeButton);
|
|
105
|
-
if (resizeMenus) {
|
|
106
|
-
this.selectMenu_resize = new SelectMenu(this, { checkList: false, position: 'bottom-left', dir: 'ltr' });
|
|
107
|
-
this.selectMenu_resize.on(this.resizeButton, this.#SetResize.bind(this));
|
|
108
|
-
this.selectMenu_resize.create(resizeMenus.items, resizeMenus.html);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// members
|
|
112
|
-
this.inst = inst;
|
|
113
|
-
this.sizeUnit = params.sizeUnit || 'px';
|
|
114
|
-
this.autoRatio = params.autoRatio;
|
|
115
|
-
this.isVertical = false;
|
|
116
|
-
this.percentageButtons = controllerEl.querySelectorAll('[data-command="resize_percent"]');
|
|
117
|
-
this.captionButton = controllerEl.querySelector('[data-command="caption"]');
|
|
118
|
-
this.align = 'none';
|
|
119
|
-
this.as = 'block';
|
|
120
|
-
this._element = null;
|
|
121
|
-
this._cover = null;
|
|
122
|
-
this._inlineCover = null;
|
|
123
|
-
this._container = null;
|
|
124
|
-
this._caption = null;
|
|
125
|
-
this._width = '';
|
|
126
|
-
this._height = '';
|
|
127
|
-
this._resize_w = 0;
|
|
128
|
-
this._resize_h = 0;
|
|
129
|
-
this._element_w = 0;
|
|
130
|
-
this._element_h = 0;
|
|
131
|
-
this._element_l = 0;
|
|
132
|
-
this._element_t = 0;
|
|
133
|
-
this._resizeClientX = 0;
|
|
134
|
-
this._resizeClientY = 0;
|
|
135
|
-
this._resize_direction = '';
|
|
136
|
-
this._floatClassStr = '__se__float-none|__se__float-left|__se__float-center|__se__float-right';
|
|
137
|
-
this.__preventSizechange = false;
|
|
138
|
-
this.__revertSize = { w: '', h: '' };
|
|
139
|
-
/** @type {{left?: number, top?: number}} */
|
|
140
|
-
this.__offset = {};
|
|
141
|
-
this.__offContainer = this.#OffFigureContainer.bind(this);
|
|
142
|
-
this.__containerResizing = this.#ContainerResizing.bind(this);
|
|
143
|
-
this.__containerResizingOff = this.#ContainerResizingOff.bind(this);
|
|
144
|
-
this.__containerResizingESC = this.#ContainerResizingESC.bind(this);
|
|
145
|
-
this.__onContainerEvent = null;
|
|
146
|
-
this.__offContainerEvent = null;
|
|
147
|
-
this.__onResizeESCEvent = null;
|
|
148
|
-
this.__fileManagerInfo = false;
|
|
149
|
-
|
|
150
|
-
// init
|
|
151
|
-
this.eventManager.addEvent(this.alignButton, 'click', this.#OnClick_alignButton.bind(this));
|
|
152
|
-
this.eventManager.addEvent(this.asButton, 'click', this.#OnClick_asButton.bind(this));
|
|
153
|
-
this.eventManager.addEvent(this.resizeButton, 'click', this.#OnClick_resizeButton.bind(this));
|
|
154
|
-
this.editor.applyFrameRoots((e) => {
|
|
155
|
-
if (!e.get('wrapper').querySelector('.se-controller.se-resizing-container')) {
|
|
156
|
-
// resizing
|
|
157
|
-
const main = CreateHTML_resizeDot();
|
|
158
|
-
const handles = main.querySelectorAll('.se-resize-dot > span');
|
|
159
|
-
e.set('_figure', {
|
|
160
|
-
main: main,
|
|
161
|
-
border: main.querySelector('.se-resize-dot'),
|
|
162
|
-
display: main.querySelector('.se-resize-display'),
|
|
163
|
-
handles: handles
|
|
164
|
-
});
|
|
165
|
-
e.get('wrapper').appendChild(main);
|
|
166
|
-
this.eventManager.addEvent(handles, 'mousedown', this.#OnResizeContainer.bind(this));
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* @description Create a container for the resizing component and insert the element.
|
|
173
|
-
* @param {Node} element Target element
|
|
174
|
-
* @param {string=} className Class name of container (fixed: se-component)
|
|
175
|
-
* @returns {FigureInfo} {target, container, cover, inlineCover, caption}
|
|
176
|
-
*/
|
|
177
|
-
static CreateContainer(element, className) {
|
|
178
|
-
dom.utils.createElement('DIV', { class: 'se-component' + (className ? ' ' + className : '') }, dom.utils.createElement('FIGURE', null, element));
|
|
179
|
-
return Figure.GetContainer(element);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* @description Create a container for the inline resizing component and insert the element.
|
|
184
|
-
* @param {Node} element Target element
|
|
185
|
-
* @param {string} [className] Class name of container (fixed: se-component se-inline-component)
|
|
186
|
-
* @returns {FigureInfo} {target, container, cover, inlineCover, caption}
|
|
187
|
-
*/
|
|
188
|
-
static CreateInlineContainer(element, className) {
|
|
189
|
-
dom.utils.createElement('SPAN', { class: 'se-component se-inline-component' + (className ? ' ' + className : '') }, element);
|
|
190
|
-
return Figure.GetContainer(element);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* @description Return HTML string of caption(FIGCAPTION) element
|
|
195
|
-
* @param {Node} cover Cover element(FIGURE). "CreateContainer().cover"
|
|
196
|
-
* @returns {HTMLElement} caption element
|
|
197
|
-
*/
|
|
198
|
-
static CreateCaption(cover, text) {
|
|
199
|
-
const caption = dom.utils.createElement('FIGCAPTION', null, '<div>' + text + '</div>');
|
|
200
|
-
cover.appendChild(caption);
|
|
201
|
-
return caption;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* @description Get the element's container(.se-component) info.
|
|
206
|
-
* @param {Node} element Target element
|
|
207
|
-
* @returns {FigureInfo} {target, container, cover, inlineCover, caption}
|
|
208
|
-
*/
|
|
209
|
-
static GetContainer(element) {
|
|
210
|
-
const cover = dom.query.getParentElement(element, 'FIGURE', 2);
|
|
211
|
-
const inlineCover = dom.query.getParentElement(element, 'SPAN', 2);
|
|
212
|
-
return {
|
|
213
|
-
target: /** @type {HTMLElement} */ (element),
|
|
214
|
-
container: /** @type {HTMLElement} */ (dom.query.getParentElement(element, Figure.is, 2) || cover),
|
|
215
|
-
cover: /** @type {HTMLElement} */ (cover),
|
|
216
|
-
inlineCover: dom.utils.hasClass(inlineCover, 'se-inline-component') ? /** @type {HTMLElement} */ (inlineCover) : null,
|
|
217
|
-
caption: /** @type {HTMLElement} */ (dom.query.getEdgeChild(element.parentElement, 'FIGCAPTION', false))
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* @description Ratio calculation
|
|
223
|
-
* @param {string|number} w Width size
|
|
224
|
-
* @param {string|number} h Height size
|
|
225
|
-
* @param {?string=} [defaultSizeUnit="px"] Default size unit (default: "px")
|
|
226
|
-
* @return {{w: number, h: number}}
|
|
227
|
-
*/
|
|
228
|
-
static GetRatio(w, h, defaultSizeUnit) {
|
|
229
|
-
let rw = 1,
|
|
230
|
-
rh = 1;
|
|
231
|
-
if (/\d+/.test(w + '') && /\d+/.test(h + '')) {
|
|
232
|
-
const xUnit = (!numbers.is(w) && String(w).replace(/\d+|\./g, '')) || defaultSizeUnit || 'px';
|
|
233
|
-
const yUnit = (!numbers.is(h) && String(h).replace(/\d+|\./g, '')) || defaultSizeUnit || 'px';
|
|
234
|
-
if (xUnit === yUnit) {
|
|
235
|
-
const w_number = numbers.get(w, 4);
|
|
236
|
-
const h_number = numbers.get(h, 4);
|
|
237
|
-
rw = w_number / h_number;
|
|
238
|
-
rh = h_number / w_number;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return {
|
|
243
|
-
w: numbers.get(rw, 4),
|
|
244
|
-
h: numbers.get(rh, 4)
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* @description Ratio calculation
|
|
250
|
-
* @param {string|number} w Width size
|
|
251
|
-
* @param {string|number} h Height size
|
|
252
|
-
* @param {string} defaultSizeUnit Default size unit (default: "px")
|
|
253
|
-
* @param {{w: number, h: number}} ratio Ratio size (Figure.GetRatio)
|
|
254
|
-
* @return {{w: string|number, h: string|number}}
|
|
255
|
-
*/
|
|
256
|
-
static CalcRatio(w, h, defaultSizeUnit, ratio) {
|
|
257
|
-
if (/\d+/.test(w + '') && /\d+/.test(h + '')) {
|
|
258
|
-
const xUnit = (!numbers.is(w) && String(w).replace(/\d+|\./g, '')) || defaultSizeUnit || 'px';
|
|
259
|
-
const yUnit = (!numbers.is(h) && String(h).replace(/\d+|\./g, '')) || defaultSizeUnit || 'px';
|
|
260
|
-
if (xUnit === yUnit) {
|
|
261
|
-
const dec = xUnit === '%' ? 2 : 0;
|
|
262
|
-
const ow = w;
|
|
263
|
-
const oh = h;
|
|
264
|
-
h = numbers.get(ratio.h * numbers.get(ow, dec), dec) + yUnit;
|
|
265
|
-
w = numbers.get(ratio.w * numbers.get(oh, dec), dec) + xUnit;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
return {
|
|
270
|
-
w: w,
|
|
271
|
-
h: h
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* @description It is judged whether it is the component[img, iframe, video, audio, table] cover(class="se-component") and table, hr
|
|
277
|
-
* @param {Node} element Target element
|
|
278
|
-
* @returns {boolean}
|
|
279
|
-
*/
|
|
280
|
-
static is(element) {
|
|
281
|
-
return dom.utils.hasClass(element, 'se-component') || /^(HR)$/.test(element?.nodeName);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* @description Close the figure's controller
|
|
286
|
-
*/
|
|
287
|
-
close() {
|
|
288
|
-
this.editor._preventBlur = false;
|
|
289
|
-
dom.utils.removeClass(this._cover, 'se-figure-selected');
|
|
290
|
-
this.controller.close();
|
|
291
|
-
this.component._removeDragEvent();
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* @description Open the figure's controller
|
|
296
|
-
* @param {Node} targetNode Target element
|
|
297
|
-
* @param {Object} params params
|
|
298
|
-
* @param {boolean} [params.nonResizing=false] Do not display the resizing button
|
|
299
|
-
* @param {boolean} [params.nonSizeInfo=false] Do not display the size information
|
|
300
|
-
* @param {boolean} [params.nonBorder=false] Do not display the selected style line
|
|
301
|
-
* @param {boolean} [params.figureTarget=false] If true, the target is a figure element
|
|
302
|
-
* @param {boolean} [params.__fileManagerInfo=false] If true, the file manager is called
|
|
303
|
-
* @returns {FigureTargetInfo|undefined} figure target info
|
|
304
|
-
*/
|
|
305
|
-
open(targetNode, { nonResizing, nonSizeInfo, nonBorder, figureTarget, __fileManagerInfo }) {
|
|
306
|
-
if (!targetNode) {
|
|
307
|
-
console.warn('[SUNEDITOR.modules.Figure.open] The "targetNode" is null.');
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
if (_DragHandle.get('__overInfo')
|
|
312
|
-
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
this.
|
|
338
|
-
|
|
339
|
-
const
|
|
340
|
-
const
|
|
341
|
-
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
const
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
this.
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
_figure.main.style.
|
|
369
|
-
_figure.main.style.
|
|
370
|
-
_figure.
|
|
371
|
-
_figure.
|
|
372
|
-
_figure.border.style.
|
|
373
|
-
_figure.border.style.
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
dom.utils.
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
dom.utils.
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
_figure.
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
//
|
|
411
|
-
this.
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
this.
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
this.
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
)
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
this.
|
|
443
|
-
this.
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
* @
|
|
471
|
-
* @param {
|
|
472
|
-
* @param {
|
|
473
|
-
* @param {boolean=} params.
|
|
474
|
-
* @param {
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
* @
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
if (
|
|
490
|
-
this._setPercentSize(
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
* @
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
? figure.
|
|
527
|
-
:
|
|
528
|
-
?
|
|
529
|
-
:
|
|
530
|
-
|
|
531
|
-
:
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
* @
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
const
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
* @
|
|
576
|
-
* @
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
const {
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
container
|
|
601
|
-
|
|
602
|
-
.
|
|
603
|
-
.
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
const
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
.
|
|
633
|
-
.
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
* @
|
|
649
|
-
* @
|
|
650
|
-
* @param {
|
|
651
|
-
* @param {string|number}
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
this.
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
* @
|
|
670
|
-
* @
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
const
|
|
675
|
-
const
|
|
676
|
-
const
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
let
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
const
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
this.
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
* @
|
|
755
|
-
* @param {Node}
|
|
756
|
-
* @param {Node}
|
|
757
|
-
* @param {
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
existElement
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
refer.parentElement.
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
existElement.
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
formats
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
existElement.parentNode.
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
* @
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
const
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
element.style.
|
|
806
|
-
element.style.
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
this.
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
* @
|
|
815
|
-
* @param {
|
|
816
|
-
* @param {?string|number}
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
const
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
const
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
const
|
|
841
|
-
const
|
|
842
|
-
const
|
|
843
|
-
const
|
|
844
|
-
const
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
this.
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
cover.style.
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
const
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
* @
|
|
874
|
-
* @
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
this.
|
|
879
|
-
this.
|
|
880
|
-
this.
|
|
881
|
-
this.
|
|
882
|
-
this.
|
|
883
|
-
this.
|
|
884
|
-
this.
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
* @
|
|
890
|
-
* @
|
|
891
|
-
* @param {
|
|
892
|
-
* @param {number}
|
|
893
|
-
* @param {number}
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
let
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
* @
|
|
932
|
-
* @
|
|
933
|
-
* @param {string|number}
|
|
934
|
-
* @param {string}
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
const
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
if (
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
this.
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
* @
|
|
968
|
-
* @
|
|
969
|
-
* @param {string}
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
* @
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
this.
|
|
989
|
-
this.
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
this._element.style.
|
|
996
|
-
this._element.style.
|
|
997
|
-
this.
|
|
998
|
-
this._cover.style.
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
* @
|
|
1010
|
-
* @
|
|
1011
|
-
* @param {string|number}
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
this._container.style.
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
this._cover.style.
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
this._element.style.
|
|
1033
|
-
this._element.style.
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
if (this.
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
* @
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
this._cover.style.
|
|
1053
|
-
this.
|
|
1054
|
-
this._container.style.
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
dom.utils.
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
* @
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
* @
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
* @
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
* @
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
this.
|
|
1097
|
-
this.__revertSize.
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
this._element.setAttribute('
|
|
1103
|
-
this._element.setAttribute('
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
* @
|
|
1112
|
-
* @
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
* @
|
|
1124
|
-
* @
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
* @
|
|
1136
|
-
* @
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
const
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
* @
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
this.
|
|
1163
|
-
this.eventManager.removeGlobalEvent(this.
|
|
1164
|
-
this.eventManager.removeGlobalEvent(this.
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
this.
|
|
1168
|
-
this.ui.
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
* @
|
|
1174
|
-
* @
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
dragHandle.style.
|
|
1182
|
-
dragHandle.style.
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
_DragHandle.set('
|
|
1186
|
-
_DragHandle.set('
|
|
1187
|
-
_DragHandle.set('
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
* @param {HTMLElement}
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
dragHandle.style.
|
|
1201
|
-
dragHandle.style.
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
e.
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
const inst = _DragHandle.get('__figureInst');
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
const
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
if (/
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
resizeBorder.style.height =
|
|
1277
|
-
resultH =
|
|
1278
|
-
}
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
}
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
const
|
|
1430
|
-
const
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
}
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
const
|
|
1452
|
-
const
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
}
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
}
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
<span class="
|
|
1490
|
-
<span class="
|
|
1491
|
-
<span class="
|
|
1492
|
-
<span class="
|
|
1493
|
-
<span class="
|
|
1494
|
-
<
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
}
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
}
|
|
1616
|
-
|
|
1617
|
-
|
|
1
|
+
import EditorInjector from '../editorInjector';
|
|
2
|
+
import { Controller, SelectMenu, _DragHandle } from '../modules';
|
|
3
|
+
import { dom, numbers, env, converter, keyCodeMap } from '../helper';
|
|
4
|
+
|
|
5
|
+
const { ON_OVER_COMPONENT } = env;
|
|
6
|
+
const DIRECTION_CURSOR_MAP = { tl: 'nwse-resize', tr: 'nesw-resize', bl: 'nesw-resize', br: 'nwse-resize', lw: 'ew-resize', th: 'ns-resize', rw: 'ew-resize', bh: 'ns-resize' };
|
|
7
|
+
const DIR_DIAGONAL = 'tl|bl|tr|br';
|
|
8
|
+
const DIR_W = 'lw|rw';
|
|
9
|
+
let __resizing_p_wh = false;
|
|
10
|
+
let __resizing_p_ow = false;
|
|
11
|
+
let __resizing_cw = 0;
|
|
12
|
+
let __resizing_sw = 0;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {Object} FigureParams
|
|
16
|
+
* @property {string} [sizeUnit="px"] Size unit
|
|
17
|
+
* @property {{ current: string, default: string }} [autoRatio=null] Auto ratio { current: '00%', default: '00%' }
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @typedef {Object} FigureInfo
|
|
22
|
+
* @property {HTMLElement} target Target element (img, iframe, video, audio, table, etc.)
|
|
23
|
+
* @property {HTMLElement} container Container element (div.se-component|span.se-component.se-inline-component)
|
|
24
|
+
* @property {?HTMLElement} cover Cover element (FIGURE|null)
|
|
25
|
+
* @property {?HTMLElement} inlineCover Inline cover element (span.se-inline-component)
|
|
26
|
+
* @property {?HTMLElement} caption Caption element (FIGCAPTION)
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @typedef {Object} FigureTargetInfo
|
|
31
|
+
* @property {HTMLElement} container Container element (div.se-component|span.se-component.se-inline-component)
|
|
32
|
+
* @property {?HTMLElement=} cover Cover element (FIGURE|null)
|
|
33
|
+
* @property {?HTMLElement=} caption Caption element (FIGCAPTION)
|
|
34
|
+
* @property {string} [align] - Alignment of the element.
|
|
35
|
+
* @property {{w:number, h:number}} [ratio] - The aspect ratio of the element.
|
|
36
|
+
* @property {string|number} [w] - Width of the element.
|
|
37
|
+
* @property {string|number} [h] - Height of the element.
|
|
38
|
+
* @property {number} [t] - Top position.
|
|
39
|
+
* @property {number} [l] - Left position.
|
|
40
|
+
* @property {string|number} width - Width, can be a number or 'auto'.
|
|
41
|
+
* @property {string|number} height - Height, can be a number or 'auto'.
|
|
42
|
+
* @property {number} [originWidth] - Original width from `naturalWidth` or `offsetWidth`.
|
|
43
|
+
* @property {number} [originHeight] - Original height from `naturalHeight` or `offsetHeight`.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @typedef {Array<Array<
|
|
48
|
+
* string |
|
|
49
|
+
* {
|
|
50
|
+
* action: (element: Node, value: string, target: Node) => void,
|
|
51
|
+
* command: string,
|
|
52
|
+
* value: string,
|
|
53
|
+
* title: string,
|
|
54
|
+
* icon: string
|
|
55
|
+
* }
|
|
56
|
+
* >>} FigureControls
|
|
57
|
+
* "mirror". "rotate", "caption", "revert", "edit", "copy", "remove", "as", "resize_auto,[number]"
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @class
|
|
62
|
+
* @description Controller module class
|
|
63
|
+
*/
|
|
64
|
+
class Figure extends EditorInjector {
|
|
65
|
+
/**
|
|
66
|
+
* @constructor
|
|
67
|
+
* @param {*} inst The instance object that called the constructor.
|
|
68
|
+
* @param {FigureControls} controls Controller button array
|
|
69
|
+
* @param {FigureParams} params Figure options
|
|
70
|
+
*/
|
|
71
|
+
constructor(inst, controls, params) {
|
|
72
|
+
super(inst.editor);
|
|
73
|
+
this.kind = inst.constructor.key || inst.constructor.name;
|
|
74
|
+
this._alignIcons = {
|
|
75
|
+
none: this.icons.format_float_none,
|
|
76
|
+
left: this.icons.format_float_left,
|
|
77
|
+
right: this.icons.format_float_right,
|
|
78
|
+
center: this.icons.format_float_center
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// modules
|
|
82
|
+
/** @type {Object<string, *>} */
|
|
83
|
+
this._action = {};
|
|
84
|
+
const controllerEl = CreateHTML_controller(this, controls || []);
|
|
85
|
+
this.controller = new Controller(this, controllerEl, { position: 'bottom', disabled: true }, this.kind);
|
|
86
|
+
// align selectmenu
|
|
87
|
+
this.alignButton = controllerEl.querySelector('[data-command="onalign"]');
|
|
88
|
+
const alignMenus = CreateAlign(this, this.alignButton);
|
|
89
|
+
if (alignMenus) {
|
|
90
|
+
this.selectMenu_align = new SelectMenu(this, { checkList: false, position: 'bottom-center' });
|
|
91
|
+
this.selectMenu_align.on(this.alignButton, this.#SetMenuAlign.bind(this), { class: 'se-figure-select-list' });
|
|
92
|
+
this.selectMenu_align.create(alignMenus.items, alignMenus.html);
|
|
93
|
+
}
|
|
94
|
+
// as [block, inline] selectmenu
|
|
95
|
+
this.asButton = controllerEl.querySelector('[data-command="onas"]');
|
|
96
|
+
const asMenus = CreateAs(this, this.asButton);
|
|
97
|
+
if (asMenus) {
|
|
98
|
+
this.selectMenu_as = new SelectMenu(this, { checkList: false, position: 'bottom-center' });
|
|
99
|
+
this.selectMenu_as.on(this.asButton, this.#SetMenuAs.bind(this), { class: 'se-figure-select-list' });
|
|
100
|
+
this.selectMenu_as.create(asMenus.items, asMenus.html);
|
|
101
|
+
}
|
|
102
|
+
// resize selectmenu
|
|
103
|
+
this.resizeButton = controllerEl.querySelector('[data-command="onresize"]');
|
|
104
|
+
const resizeMenus = CreateResize(this, this.resizeButton);
|
|
105
|
+
if (resizeMenus) {
|
|
106
|
+
this.selectMenu_resize = new SelectMenu(this, { checkList: false, position: 'bottom-left', dir: 'ltr' });
|
|
107
|
+
this.selectMenu_resize.on(this.resizeButton, this.#SetResize.bind(this));
|
|
108
|
+
this.selectMenu_resize.create(resizeMenus.items, resizeMenus.html);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// members
|
|
112
|
+
this.inst = inst;
|
|
113
|
+
this.sizeUnit = params.sizeUnit || 'px';
|
|
114
|
+
this.autoRatio = params.autoRatio;
|
|
115
|
+
this.isVertical = false;
|
|
116
|
+
this.percentageButtons = controllerEl.querySelectorAll('[data-command="resize_percent"]');
|
|
117
|
+
this.captionButton = controllerEl.querySelector('[data-command="caption"]');
|
|
118
|
+
this.align = 'none';
|
|
119
|
+
this.as = 'block';
|
|
120
|
+
this._element = null;
|
|
121
|
+
this._cover = null;
|
|
122
|
+
this._inlineCover = null;
|
|
123
|
+
this._container = null;
|
|
124
|
+
this._caption = null;
|
|
125
|
+
this._width = '';
|
|
126
|
+
this._height = '';
|
|
127
|
+
this._resize_w = 0;
|
|
128
|
+
this._resize_h = 0;
|
|
129
|
+
this._element_w = 0;
|
|
130
|
+
this._element_h = 0;
|
|
131
|
+
this._element_l = 0;
|
|
132
|
+
this._element_t = 0;
|
|
133
|
+
this._resizeClientX = 0;
|
|
134
|
+
this._resizeClientY = 0;
|
|
135
|
+
this._resize_direction = '';
|
|
136
|
+
this._floatClassStr = '__se__float-none|__se__float-left|__se__float-center|__se__float-right';
|
|
137
|
+
this.__preventSizechange = false;
|
|
138
|
+
this.__revertSize = { w: '', h: '' };
|
|
139
|
+
/** @type {{left?: number, top?: number}} */
|
|
140
|
+
this.__offset = {};
|
|
141
|
+
this.__offContainer = this.#OffFigureContainer.bind(this);
|
|
142
|
+
this.__containerResizing = this.#ContainerResizing.bind(this);
|
|
143
|
+
this.__containerResizingOff = this.#ContainerResizingOff.bind(this);
|
|
144
|
+
this.__containerResizingESC = this.#ContainerResizingESC.bind(this);
|
|
145
|
+
this.__onContainerEvent = null;
|
|
146
|
+
this.__offContainerEvent = null;
|
|
147
|
+
this.__onResizeESCEvent = null;
|
|
148
|
+
this.__fileManagerInfo = false;
|
|
149
|
+
|
|
150
|
+
// init
|
|
151
|
+
this.eventManager.addEvent(this.alignButton, 'click', this.#OnClick_alignButton.bind(this));
|
|
152
|
+
this.eventManager.addEvent(this.asButton, 'click', this.#OnClick_asButton.bind(this));
|
|
153
|
+
this.eventManager.addEvent(this.resizeButton, 'click', this.#OnClick_resizeButton.bind(this));
|
|
154
|
+
this.editor.applyFrameRoots((e) => {
|
|
155
|
+
if (!e.get('wrapper').querySelector('.se-controller.se-resizing-container')) {
|
|
156
|
+
// resizing
|
|
157
|
+
const main = CreateHTML_resizeDot();
|
|
158
|
+
const handles = main.querySelectorAll('.se-resize-dot > span');
|
|
159
|
+
e.set('_figure', {
|
|
160
|
+
main: main,
|
|
161
|
+
border: main.querySelector('.se-resize-dot'),
|
|
162
|
+
display: main.querySelector('.se-resize-display'),
|
|
163
|
+
handles: handles
|
|
164
|
+
});
|
|
165
|
+
e.get('wrapper').appendChild(main);
|
|
166
|
+
this.eventManager.addEvent(handles, 'mousedown', this.#OnResizeContainer.bind(this));
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* @description Create a container for the resizing component and insert the element.
|
|
173
|
+
* @param {Node} element Target element
|
|
174
|
+
* @param {string=} className Class name of container (fixed: se-component)
|
|
175
|
+
* @returns {FigureInfo} {target, container, cover, inlineCover, caption}
|
|
176
|
+
*/
|
|
177
|
+
static CreateContainer(element, className) {
|
|
178
|
+
dom.utils.createElement('DIV', { class: 'se-component' + (className ? ' ' + className : '') }, dom.utils.createElement('FIGURE', null, element));
|
|
179
|
+
return Figure.GetContainer(element);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @description Create a container for the inline resizing component and insert the element.
|
|
184
|
+
* @param {Node} element Target element
|
|
185
|
+
* @param {string} [className] Class name of container (fixed: se-component se-inline-component)
|
|
186
|
+
* @returns {FigureInfo} {target, container, cover, inlineCover, caption}
|
|
187
|
+
*/
|
|
188
|
+
static CreateInlineContainer(element, className) {
|
|
189
|
+
dom.utils.createElement('SPAN', { class: 'se-component se-inline-component' + (className ? ' ' + className : '') }, element);
|
|
190
|
+
return Figure.GetContainer(element);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* @description Return HTML string of caption(FIGCAPTION) element
|
|
195
|
+
* @param {Node} cover Cover element(FIGURE). "CreateContainer().cover"
|
|
196
|
+
* @returns {HTMLElement} caption element
|
|
197
|
+
*/
|
|
198
|
+
static CreateCaption(cover, text) {
|
|
199
|
+
const caption = dom.utils.createElement('FIGCAPTION', null, '<div>' + text + '</div>');
|
|
200
|
+
cover.appendChild(caption);
|
|
201
|
+
return caption;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* @description Get the element's container(.se-component) info.
|
|
206
|
+
* @param {Node} element Target element
|
|
207
|
+
* @returns {FigureInfo} {target, container, cover, inlineCover, caption}
|
|
208
|
+
*/
|
|
209
|
+
static GetContainer(element) {
|
|
210
|
+
const cover = dom.query.getParentElement(element, 'FIGURE', 2);
|
|
211
|
+
const inlineCover = dom.query.getParentElement(element, 'SPAN', 2);
|
|
212
|
+
return {
|
|
213
|
+
target: /** @type {HTMLElement} */ (element),
|
|
214
|
+
container: /** @type {HTMLElement} */ (dom.query.getParentElement(element, Figure.is, 2) || cover),
|
|
215
|
+
cover: /** @type {HTMLElement} */ (cover),
|
|
216
|
+
inlineCover: dom.utils.hasClass(inlineCover, 'se-inline-component') ? /** @type {HTMLElement} */ (inlineCover) : null,
|
|
217
|
+
caption: /** @type {HTMLElement} */ (dom.query.getEdgeChild(element.parentElement, 'FIGCAPTION', false))
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* @description Ratio calculation
|
|
223
|
+
* @param {string|number} w Width size
|
|
224
|
+
* @param {string|number} h Height size
|
|
225
|
+
* @param {?string=} [defaultSizeUnit="px"] Default size unit (default: "px")
|
|
226
|
+
* @return {{w: number, h: number}}
|
|
227
|
+
*/
|
|
228
|
+
static GetRatio(w, h, defaultSizeUnit) {
|
|
229
|
+
let rw = 1,
|
|
230
|
+
rh = 1;
|
|
231
|
+
if (/\d+/.test(w + '') && /\d+/.test(h + '')) {
|
|
232
|
+
const xUnit = (!numbers.is(w) && String(w).replace(/\d+|\./g, '')) || defaultSizeUnit || 'px';
|
|
233
|
+
const yUnit = (!numbers.is(h) && String(h).replace(/\d+|\./g, '')) || defaultSizeUnit || 'px';
|
|
234
|
+
if (xUnit === yUnit) {
|
|
235
|
+
const w_number = numbers.get(w, 4);
|
|
236
|
+
const h_number = numbers.get(h, 4);
|
|
237
|
+
rw = w_number / h_number;
|
|
238
|
+
rh = h_number / w_number;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return {
|
|
243
|
+
w: numbers.get(rw, 4),
|
|
244
|
+
h: numbers.get(rh, 4)
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* @description Ratio calculation
|
|
250
|
+
* @param {string|number} w Width size
|
|
251
|
+
* @param {string|number} h Height size
|
|
252
|
+
* @param {string} defaultSizeUnit Default size unit (default: "px")
|
|
253
|
+
* @param {{w: number, h: number}} ratio Ratio size (Figure.GetRatio)
|
|
254
|
+
* @return {{w: string|number, h: string|number}}
|
|
255
|
+
*/
|
|
256
|
+
static CalcRatio(w, h, defaultSizeUnit, ratio) {
|
|
257
|
+
if (/\d+/.test(w + '') && /\d+/.test(h + '')) {
|
|
258
|
+
const xUnit = (!numbers.is(w) && String(w).replace(/\d+|\./g, '')) || defaultSizeUnit || 'px';
|
|
259
|
+
const yUnit = (!numbers.is(h) && String(h).replace(/\d+|\./g, '')) || defaultSizeUnit || 'px';
|
|
260
|
+
if (xUnit === yUnit) {
|
|
261
|
+
const dec = xUnit === '%' ? 2 : 0;
|
|
262
|
+
const ow = w;
|
|
263
|
+
const oh = h;
|
|
264
|
+
h = numbers.get(ratio.h * numbers.get(ow, dec), dec) + yUnit;
|
|
265
|
+
w = numbers.get(ratio.w * numbers.get(oh, dec), dec) + xUnit;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return {
|
|
270
|
+
w: w,
|
|
271
|
+
h: h
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* @description It is judged whether it is the component[img, iframe, video, audio, table] cover(class="se-component") and table, hr
|
|
277
|
+
* @param {Node} element Target element
|
|
278
|
+
* @returns {boolean}
|
|
279
|
+
*/
|
|
280
|
+
static is(element) {
|
|
281
|
+
return dom.utils.hasClass(element, 'se-component') || /^(HR)$/.test(element?.nodeName);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* @description Close the figure's controller
|
|
286
|
+
*/
|
|
287
|
+
close() {
|
|
288
|
+
this.editor._preventBlur = false;
|
|
289
|
+
dom.utils.removeClass(this._cover, 'se-figure-selected');
|
|
290
|
+
this.controller.close();
|
|
291
|
+
this.component._removeDragEvent();
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* @description Open the figure's controller
|
|
296
|
+
* @param {Node} targetNode Target element
|
|
297
|
+
* @param {Object} params params
|
|
298
|
+
* @param {boolean} [params.nonResizing=false] Do not display the resizing button
|
|
299
|
+
* @param {boolean} [params.nonSizeInfo=false] Do not display the size information
|
|
300
|
+
* @param {boolean} [params.nonBorder=false] Do not display the selected style line
|
|
301
|
+
* @param {boolean} [params.figureTarget=false] If true, the target is a figure element
|
|
302
|
+
* @param {boolean} [params.__fileManagerInfo=false] If true, the file manager is called
|
|
303
|
+
* @returns {FigureTargetInfo|undefined} figure target info
|
|
304
|
+
*/
|
|
305
|
+
open(targetNode, { nonResizing, nonSizeInfo, nonBorder, figureTarget, __fileManagerInfo }) {
|
|
306
|
+
if (!targetNode) {
|
|
307
|
+
console.warn('[SUNEDITOR.modules.Figure.open] The "targetNode" is null.');
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (_DragHandle.get('__overInfo') === ON_OVER_COMPONENT) {
|
|
312
|
+
nonBorder = true;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const figureInfo = Figure.GetContainer(targetNode);
|
|
316
|
+
const target = figureInfo.target;
|
|
317
|
+
let exceptionFormat = false;
|
|
318
|
+
if (!figureInfo.container) {
|
|
319
|
+
if (!this.options.get('strictMode').formatFilter) {
|
|
320
|
+
figureInfo.container = target;
|
|
321
|
+
figureInfo.cover = target;
|
|
322
|
+
exceptionFormat = true;
|
|
323
|
+
} else {
|
|
324
|
+
return {
|
|
325
|
+
container: null,
|
|
326
|
+
cover: null,
|
|
327
|
+
width: target.style.width || /** @type {HTMLImageElement} */ (target).width || '',
|
|
328
|
+
height: target.style.height || /** @type {HTMLImageElement} */ (target).height || ''
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
_DragHandle.set('__figureInst', this);
|
|
334
|
+
|
|
335
|
+
this._setFigureInfo(figureInfo);
|
|
336
|
+
|
|
337
|
+
const sizeTarget = /** @type {HTMLElement} */ (figureTarget ? this._cover || this._container || target : target);
|
|
338
|
+
const w = sizeTarget.offsetWidth || null;
|
|
339
|
+
const h = sizeTarget.offsetHeight || null;
|
|
340
|
+
const { top, left, scrollX, scrollY } = this.offset.getLocal(sizeTarget);
|
|
341
|
+
|
|
342
|
+
const dataSize = (target.getAttribute('data-se-size') || '').split(',');
|
|
343
|
+
const ratio = Figure.GetRatio(dataSize[0] || numbers.get(target.style.width, 2) || w, dataSize[1] || numbers.get(target.style.height, 2) || h, this.sizeUnit);
|
|
344
|
+
const targetInfo = {
|
|
345
|
+
container: figureInfo.container,
|
|
346
|
+
cover: figureInfo.cover,
|
|
347
|
+
caption: figureInfo.caption,
|
|
348
|
+
align: this.align,
|
|
349
|
+
ratio: ratio,
|
|
350
|
+
w: w || '',
|
|
351
|
+
h: h || '',
|
|
352
|
+
t: top,
|
|
353
|
+
l: left,
|
|
354
|
+
width: dataSize[0] || 'auto',
|
|
355
|
+
height: dataSize[1] || 'auto',
|
|
356
|
+
originWidth: /** @type {HTMLImageElement} */ (target).naturalWidth || target.offsetWidth,
|
|
357
|
+
originHeight: /** @type {HTMLImageElement} */ (target).naturalHeight || target.offsetHeight
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
this._width = targetInfo.width;
|
|
361
|
+
this._height = targetInfo.height;
|
|
362
|
+
if (__fileManagerInfo || this.__fileManagerInfo) return targetInfo;
|
|
363
|
+
|
|
364
|
+
const _figure = this.editor.frameContext.get('_figure');
|
|
365
|
+
this.editor._figureContainer = _figure.main;
|
|
366
|
+
_figure.main.style.top = top + 'px';
|
|
367
|
+
_figure.main.style.left = left + 'px';
|
|
368
|
+
_figure.main.style.width = (this.isVertical ? h : w) + 'px';
|
|
369
|
+
_figure.main.style.height = (this.isVertical ? w : h) + 'px';
|
|
370
|
+
_figure.border.style.top = '0px';
|
|
371
|
+
_figure.border.style.left = '0px';
|
|
372
|
+
_figure.border.style.width = (this.isVertical ? h : w) + 'px';
|
|
373
|
+
_figure.border.style.height = (this.isVertical ? w : h) + 'px';
|
|
374
|
+
|
|
375
|
+
this.__offset = { left: left + scrollX, top: top + scrollY };
|
|
376
|
+
this.editor.opendControllers.push({
|
|
377
|
+
position: 'none',
|
|
378
|
+
form: _figure.main,
|
|
379
|
+
target: sizeTarget,
|
|
380
|
+
inst: this,
|
|
381
|
+
notInCarrier: true
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
// percentage active
|
|
385
|
+
const value = /%$/.test(target.style.width) && /%$/.test(figureInfo.container.style.width) ? numbers.get(figureInfo.container.style.width, 0) / 100 + '' : '';
|
|
386
|
+
for (let i = 0, len = this.percentageButtons.length; i < len; i++) {
|
|
387
|
+
if (this.percentageButtons[i].getAttribute('data-value') === value) {
|
|
388
|
+
dom.utils.addClass(this.percentageButtons[i], 'active');
|
|
389
|
+
} else {
|
|
390
|
+
dom.utils.removeClass(this.percentageButtons[i], 'active');
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// caption active
|
|
395
|
+
if (this.captionButton) {
|
|
396
|
+
if (figureInfo.caption) {
|
|
397
|
+
dom.utils.addClass(this.captionButton, 'active');
|
|
398
|
+
} else {
|
|
399
|
+
dom.utils.removeClass(this.captionButton, 'active');
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
_figure.display.style.display = nonSizeInfo || this._inlineCover ? 'none' : '';
|
|
404
|
+
_figure.border.style.display = nonBorder ? 'none' : '';
|
|
405
|
+
_figure.main.style.display = 'block';
|
|
406
|
+
|
|
407
|
+
if (_DragHandle.get('__overInfo') !== ON_OVER_COMPONENT) {
|
|
408
|
+
// align button
|
|
409
|
+
this._setAlignIcon();
|
|
410
|
+
// as button
|
|
411
|
+
this._setAsIcon();
|
|
412
|
+
this.ui._visibleControllers(true, true);
|
|
413
|
+
// size
|
|
414
|
+
const size = this.getSize(target);
|
|
415
|
+
dom.utils.changeTxt(_figure.display, this.lang[this.align === 'none' ? 'basic' : this.align] + ' (' + size.w + ', ' + size.h + ')');
|
|
416
|
+
this._displayResizeHandles(!nonResizing);
|
|
417
|
+
// rotate, aption, align, onresize - display;
|
|
418
|
+
const transformButtons = this.controller.form.querySelectorAll(
|
|
419
|
+
'[data-command="rotate"][data-value="90"], [data-command="rotate"][data-value="-90"], [data-command="caption"], [data-command="onalign"], [data-command="onresize"]'
|
|
420
|
+
);
|
|
421
|
+
const display = this._inlineCover || exceptionFormat ? 'none' : '';
|
|
422
|
+
transformButtons.forEach((button) => {
|
|
423
|
+
/** @type {HTMLButtonElement} */ (button).style.display = display;
|
|
424
|
+
});
|
|
425
|
+
// onas
|
|
426
|
+
const onas = this.controller.form.querySelector('[data-command="onas"]');
|
|
427
|
+
if (onas) {
|
|
428
|
+
/** @type {HTMLButtonElement} */ (onas).style.display = exceptionFormat ? 'none' : '';
|
|
429
|
+
}
|
|
430
|
+
// selecte
|
|
431
|
+
dom.utils.removeClass(this._cover, 'se-figure-over-selected');
|
|
432
|
+
this.controller.open(_figure.main, null, { initMethod: this.__offContainer, isWWTarget: false, addOffset: null });
|
|
433
|
+
this._w.setTimeout(() => _DragHandle.set('__overInfo', false), 0);
|
|
434
|
+
} else {
|
|
435
|
+
dom.utils.addClass(this._cover, 'se-figure-over-selected');
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// set members
|
|
439
|
+
dom.utils.addClass(this._cover, 'se-figure-selected');
|
|
440
|
+
this._element_w = this._resize_w = w;
|
|
441
|
+
this._element_h = this._resize_h = h;
|
|
442
|
+
this._element_l = left;
|
|
443
|
+
this._element_t = top;
|
|
444
|
+
|
|
445
|
+
// drag
|
|
446
|
+
if (!this._inlineCover && (_DragHandle.get('__overInfo') !== ON_OVER_COMPONENT || dom.utils.hasClass(figureInfo.container, 'se-input-component'))) {
|
|
447
|
+
this._setDragEvent(_figure.main);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
return targetInfo;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* @description Hide the controller
|
|
455
|
+
*/
|
|
456
|
+
controllerHide() {
|
|
457
|
+
this.controller.hide();
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* @description Hide the controller
|
|
462
|
+
*/
|
|
463
|
+
controllerShow() {
|
|
464
|
+
this.controller.show();
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* @description Open the figure's controller
|
|
469
|
+
* @param {Node} target Target element
|
|
470
|
+
* @param {Object} [params={}] params
|
|
471
|
+
* @param {boolean=} params.isWWTarget If the controller is in the WYSIWYG area, set it to true.
|
|
472
|
+
* @param {() => void=} params.initMethod Method to be called when the controller is closed.
|
|
473
|
+
* @param {boolean=} params.disabled If true, the controller is disabled.
|
|
474
|
+
* @param {{left: number, top: number}=} params.addOffset Additional offset values
|
|
475
|
+
*/
|
|
476
|
+
controllerOpen(target, params) {
|
|
477
|
+
this._element = /** @type {HTMLElement} */ (target);
|
|
478
|
+
this.controller.open(target, null, params);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* @description Set the element's container size
|
|
483
|
+
* @param {string|number} w Width size
|
|
484
|
+
* @param {string|number} h Height size
|
|
485
|
+
*/
|
|
486
|
+
setSize(w, h) {
|
|
487
|
+
if (/%$/.test(w + '')) {
|
|
488
|
+
this._setPercentSize(w, h);
|
|
489
|
+
} else if ((!w || w === 'auto') && (!h || h === 'auto')) {
|
|
490
|
+
if (this.autoRatio) this._setPercentSize(100, this.autoRatio.default || this.autoRatio.current);
|
|
491
|
+
else this._setAutoSize();
|
|
492
|
+
} else {
|
|
493
|
+
this._applySize(w, h, '');
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* @description Gets the Figure size
|
|
499
|
+
* @param {?Node=} targetNode Target element, default is the current element
|
|
500
|
+
* @returns {{w: string, h: string}}
|
|
501
|
+
*/
|
|
502
|
+
getSize(targetNode) {
|
|
503
|
+
if (!targetNode) targetNode = this._element;
|
|
504
|
+
if (!targetNode) return { w: '', h: '' };
|
|
505
|
+
|
|
506
|
+
const figure = Figure.GetContainer(targetNode);
|
|
507
|
+
const target = figure.target;
|
|
508
|
+
if (!figure.container) {
|
|
509
|
+
// exceptionFormat
|
|
510
|
+
if (!this.options.get('strictMode').formatFilter) {
|
|
511
|
+
return {
|
|
512
|
+
w: target.style.width || 'auto',
|
|
513
|
+
h: target.style.height || 'auto'
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
return {
|
|
517
|
+
w: '',
|
|
518
|
+
h: target.style.height
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
const w = !/%$/.test(target.style.width) ? target.style.width : ((figure.container && numbers.get(figure.container.style.width, 2)) || 100) + '%';
|
|
523
|
+
const h = figure.inlineCover
|
|
524
|
+
? figure.inlineCover.style.height || /** @type {HTMLElement} */ (targetNode).style.height || String(/** @type {HTMLImageElement} */ (targetNode).height || '')
|
|
525
|
+
: numbers.get(figure.cover.style.paddingBottom, 0) > 0 && !this.isVertical
|
|
526
|
+
? figure.cover.style.height
|
|
527
|
+
: !/%$/.test(target.style.height) || !/%$/.test(target.style.width)
|
|
528
|
+
? target.style.height
|
|
529
|
+
: ((figure.container && numbers.get(figure.container.style.height, 2)) || 100) + '%';
|
|
530
|
+
return {
|
|
531
|
+
w: w || 'auto',
|
|
532
|
+
h: h || 'auto'
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* @description Align the container.
|
|
538
|
+
* @param {?Node} targetNode Target element
|
|
539
|
+
* @param {string} align "none"|"left"|"center"|"right"
|
|
540
|
+
*/
|
|
541
|
+
setAlign(targetNode, align) {
|
|
542
|
+
if (!targetNode) targetNode = this._element;
|
|
543
|
+
this.align = align = align || 'none';
|
|
544
|
+
|
|
545
|
+
const figure = Figure.GetContainer(targetNode);
|
|
546
|
+
if (!figure.cover) return;
|
|
547
|
+
|
|
548
|
+
const target = figure.target;
|
|
549
|
+
const container = figure.container;
|
|
550
|
+
const cover = figure.cover;
|
|
551
|
+
if (/%$/.test(target.style.width) && align === 'center' && !this.component.isInline(container)) {
|
|
552
|
+
container.style.minWidth = '100%';
|
|
553
|
+
cover.style.width = container.style.width;
|
|
554
|
+
} else {
|
|
555
|
+
container.style.minWidth = '';
|
|
556
|
+
cover.style.width = this.isVertical ? target.style.height || target.offsetHeight + 'px' : !target.style.width || target.style.width === 'auto' ? '' : target.style.width || '100%';
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
if (!dom.utils.hasClass(container, '__se__float-' + align)) {
|
|
560
|
+
dom.utils.removeClass(container, this._floatClassStr);
|
|
561
|
+
dom.utils.addClass(container, '__se__float-' + align);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
if (this.autoRatio) {
|
|
565
|
+
const { w, h } = this.getSize(this._element);
|
|
566
|
+
this.__setCoverPaddingBottom(w, h);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
this._setAlignIcon();
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* @description As style[block, inline] the component
|
|
574
|
+
* @param {?Node} targetNode Target element
|
|
575
|
+
* @param {"block"|"inline"} formatStyle Format style
|
|
576
|
+
* @returns {HTMLElement} New target element after conversion
|
|
577
|
+
*/
|
|
578
|
+
convertAsFormat(targetNode, formatStyle) {
|
|
579
|
+
if (!targetNode) targetNode = this._element;
|
|
580
|
+
this.as = formatStyle || 'block';
|
|
581
|
+
const { container, inlineCover, target } = Figure.GetContainer(targetNode);
|
|
582
|
+
const { w, h } = this.getSize(target);
|
|
583
|
+
|
|
584
|
+
const newTarget = /** @type {HTMLElement} */ (target.cloneNode(false));
|
|
585
|
+
newTarget.style.width = '';
|
|
586
|
+
newTarget.style.height = '';
|
|
587
|
+
newTarget.removeAttribute('width');
|
|
588
|
+
newTarget.removeAttribute('height');
|
|
589
|
+
|
|
590
|
+
switch (formatStyle) {
|
|
591
|
+
case 'inline': {
|
|
592
|
+
if (inlineCover) break;
|
|
593
|
+
this.component.deselect();
|
|
594
|
+
|
|
595
|
+
const next = container.nextElementSibling;
|
|
596
|
+
const parent = container.parentElement;
|
|
597
|
+
|
|
598
|
+
const figure = Figure.CreateInlineContainer(newTarget);
|
|
599
|
+
dom.utils.addClass(
|
|
600
|
+
figure.container,
|
|
601
|
+
container.className
|
|
602
|
+
.split(' ')
|
|
603
|
+
.filter((v) => v !== 'se-figure-selected' && v !== 'se-component-selected')
|
|
604
|
+
.join('|')
|
|
605
|
+
);
|
|
606
|
+
|
|
607
|
+
this._asFormatChange(figure, w, h);
|
|
608
|
+
|
|
609
|
+
const line = dom.utils.createElement(this.options.get('defaultLine'), null, figure.container);
|
|
610
|
+
parent.insertBefore(line, next);
|
|
611
|
+
dom.utils.removeItem(container);
|
|
612
|
+
|
|
613
|
+
break;
|
|
614
|
+
}
|
|
615
|
+
case 'block': {
|
|
616
|
+
if (!inlineCover) break;
|
|
617
|
+
this.component.deselect();
|
|
618
|
+
|
|
619
|
+
this.selection.setRange(container, 0, container, 1);
|
|
620
|
+
const r = this.html.remove();
|
|
621
|
+
const s = this.nodeTransform.split(r.container, r.offset, 0);
|
|
622
|
+
|
|
623
|
+
if (s?.previousElementSibling && dom.check.isZeroWidth(s.previousElementSibling)) {
|
|
624
|
+
dom.utils.removeItem(s.previousElementSibling);
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
const figure = Figure.CreateContainer(newTarget);
|
|
628
|
+
dom.utils.addClass(
|
|
629
|
+
figure.container,
|
|
630
|
+
container.className
|
|
631
|
+
.split(' ')
|
|
632
|
+
.filter((v) => v !== 'se-inline-component' && v !== 'se-figure-selected' && v !== 'se-component-selected')
|
|
633
|
+
.join('|')
|
|
634
|
+
);
|
|
635
|
+
|
|
636
|
+
this._asFormatChange(figure, w, h);
|
|
637
|
+
|
|
638
|
+
(s || r.container).parentElement.insertBefore(figure.container, s);
|
|
639
|
+
|
|
640
|
+
break;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
return newTarget;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* @private
|
|
649
|
+
* @description Handles format conversion (block/inline) for the figure component and applies size changes.
|
|
650
|
+
* @param {FigureInfo} figureinfo {target, container, cover, inlineCover, caption}
|
|
651
|
+
* @param {string|number} w Width value.
|
|
652
|
+
* @param {string|number} h Height value.
|
|
653
|
+
*/
|
|
654
|
+
_asFormatChange(figureinfo, w, h) {
|
|
655
|
+
const kind = this.kind;
|
|
656
|
+
figureinfo.target.onload = () => this.component.select(figureinfo.target, kind);
|
|
657
|
+
|
|
658
|
+
this._setFigureInfo(figureinfo);
|
|
659
|
+
|
|
660
|
+
if (figureinfo.inlineCover) {
|
|
661
|
+
this.setAlign(figureinfo.target, 'none');
|
|
662
|
+
this.deleteTransform();
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
this.setSize(w, h);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* @description Controller button action
|
|
670
|
+
* @param {HTMLButtonElement} target Target button element
|
|
671
|
+
* @returns
|
|
672
|
+
*/
|
|
673
|
+
controllerAction(target) {
|
|
674
|
+
const command = target.getAttribute('data-command');
|
|
675
|
+
const value = target.getAttribute('data-value');
|
|
676
|
+
const type = target.getAttribute('data-type');
|
|
677
|
+
const element = this._element;
|
|
678
|
+
if (/^on.+/.test(command) || type === 'selectMenu') return;
|
|
679
|
+
|
|
680
|
+
switch (command) {
|
|
681
|
+
case 'mirror': {
|
|
682
|
+
const info = this.#GetRotateValue(element);
|
|
683
|
+
let x = info.x;
|
|
684
|
+
let y = info.y;
|
|
685
|
+
|
|
686
|
+
if ((value === 'h' && !this.isVertical) || (value === 'v' && this.isVertical)) {
|
|
687
|
+
y = y ? '' : '180';
|
|
688
|
+
} else {
|
|
689
|
+
x = x ? '' : '180';
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
this._setRotate(element, info.r, x, y);
|
|
693
|
+
break;
|
|
694
|
+
}
|
|
695
|
+
case 'rotate':
|
|
696
|
+
this.setTransform(element, null, null, value);
|
|
697
|
+
break;
|
|
698
|
+
case 'caption':
|
|
699
|
+
if (!this._caption) {
|
|
700
|
+
const caption = Figure.CreateCaption(this._cover, this.lang.caption);
|
|
701
|
+
const captionText = dom.query.getEdgeChild(caption, (current) => current.nodeType === 3, false);
|
|
702
|
+
|
|
703
|
+
if (!captionText) {
|
|
704
|
+
caption.focus();
|
|
705
|
+
} else {
|
|
706
|
+
this.selection.setRange(captionText, 0, captionText, captionText.textContent.length);
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
this.controller.close();
|
|
710
|
+
} else {
|
|
711
|
+
dom.utils.removeItem(this._caption);
|
|
712
|
+
this._w.setTimeout(this.component.select.bind(this.component, element, this.kind), 0);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
this._caption = !this._caption;
|
|
716
|
+
if (/\d+/.test(element.style.height) || (this.isVertical && this._caption)) {
|
|
717
|
+
if (/%$/.test(element.style.width) || /auto/.test(element.style.height)) {
|
|
718
|
+
this.deleteTransform();
|
|
719
|
+
} else {
|
|
720
|
+
this.setTransform(element, element.style.width, element.style.height, 0);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
break;
|
|
724
|
+
case 'revert':
|
|
725
|
+
this._setRevert();
|
|
726
|
+
break;
|
|
727
|
+
case 'edit':
|
|
728
|
+
this.inst.edit(element);
|
|
729
|
+
break;
|
|
730
|
+
case 'copy': {
|
|
731
|
+
this.component.copy(this._container);
|
|
732
|
+
break;
|
|
733
|
+
}
|
|
734
|
+
case 'remove':
|
|
735
|
+
this.inst.destroy(element);
|
|
736
|
+
this.controller.close();
|
|
737
|
+
break;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
if (/^__c__/.test(command)) {
|
|
741
|
+
this._action[command](element, value, target);
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
if (/^edit$/.test(command)) return;
|
|
746
|
+
|
|
747
|
+
this.history.push(false);
|
|
748
|
+
if (!/^remove|caption$/.test(command)) {
|
|
749
|
+
this.component.select(element, this.kind);
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* @description Inspect the figure component format and change it to the correct format.
|
|
755
|
+
* @param {Node} container - The container element of the figure component.
|
|
756
|
+
* @param {Node} originEl - The original element of the figure component.
|
|
757
|
+
* @param {Node} anchorCover - The anchor cover element of the figure component.
|
|
758
|
+
* @param {import('./FileManager').default} [fileManagerInst=null] - FileManager module instance, if used.
|
|
759
|
+
*/
|
|
760
|
+
retainFigureFormat(container, originEl, anchorCover, fileManagerInst) {
|
|
761
|
+
const isInline = this.component.isInline(container);
|
|
762
|
+
let existElement = this.format.isBlock(originEl.parentNode) || dom.check.isWysiwygFrame(originEl.parentNode) ? originEl : dom.check.isAnchor(originEl.parentNode) ? originEl.parentNode : this.format.getLine(originEl) || originEl;
|
|
763
|
+
|
|
764
|
+
if (dom.query.getParentElement(originEl, dom.check.isExcludeFormat)) {
|
|
765
|
+
existElement = anchorCover && anchorCover !== originEl ? anchorCover : originEl;
|
|
766
|
+
existElement.parentNode.replaceChild(container, existElement);
|
|
767
|
+
} else if (isInline && this.format.isLine(existElement)) {
|
|
768
|
+
const refer = isInline && /^SPAN$/i.test(originEl.parentElement.nodeName) ? originEl.parentElement : originEl;
|
|
769
|
+
refer.parentElement.replaceChild(container, refer);
|
|
770
|
+
} else if (dom.check.isListCell(existElement)) {
|
|
771
|
+
const refer = dom.query.getParentElement(originEl, (current) => current.parentNode === existElement);
|
|
772
|
+
existElement.insertBefore(container, refer);
|
|
773
|
+
dom.utils.removeItem(originEl);
|
|
774
|
+
this.nodeTransform.removeEmptyNode(refer, null, true);
|
|
775
|
+
} else if (this.format.isLine(existElement)) {
|
|
776
|
+
const refer = dom.query.getParentElement(originEl, (current) => current.parentNode === existElement);
|
|
777
|
+
existElement = this.nodeTransform.split(existElement, refer);
|
|
778
|
+
existElement.parentNode.insertBefore(container, existElement);
|
|
779
|
+
dom.utils.removeItem(originEl);
|
|
780
|
+
this.nodeTransform.removeEmptyNode(existElement, null, true);
|
|
781
|
+
} else {
|
|
782
|
+
if (this.format.isLine(existElement.parentNode)) {
|
|
783
|
+
const formats = existElement.parentNode;
|
|
784
|
+
formats.parentNode.insertBefore(container, existElement.previousSibling ? formats.nextElementSibling : formats);
|
|
785
|
+
if (fileManagerInst?.__updateTags.map((current) => existElement.contains(current)).length === 0) dom.utils.removeItem(existElement);
|
|
786
|
+
else if (dom.check.isZeroWidth(existElement)) dom.utils.removeItem(existElement);
|
|
787
|
+
} else {
|
|
788
|
+
existElement = dom.check.isFigure(existElement.parentNode) ? dom.query.getParentElement(existElement.parentNode, Figure.is) : existElement;
|
|
789
|
+
existElement.parentNode.replaceChild(container, existElement);
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
/**
|
|
795
|
+
* @description Initialize the transform style (rotation) of the element.
|
|
796
|
+
* @param {?Node=} node Target element, default is the current element
|
|
797
|
+
*/
|
|
798
|
+
deleteTransform(node) {
|
|
799
|
+
if (!node) node = this._element;
|
|
800
|
+
|
|
801
|
+
const element = /** @type {HTMLElement} */ (node);
|
|
802
|
+
const size = (element.getAttribute('data-se-size') || '').split(',');
|
|
803
|
+
this.isVertical = false;
|
|
804
|
+
|
|
805
|
+
element.style.maxWidth = '';
|
|
806
|
+
element.style.transform = '';
|
|
807
|
+
element.style.transformOrigin = '';
|
|
808
|
+
|
|
809
|
+
this._deleteCaptionPosition(element);
|
|
810
|
+
this._applySize(size[0] || 'auto', size[1] || '', '');
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
/**
|
|
814
|
+
* @description Set the transform style (rotation) of the element.
|
|
815
|
+
* @param {Node} node Target element
|
|
816
|
+
* @param {?string|number} width Element's width size
|
|
817
|
+
* @param {?string|number} height Element's height size
|
|
818
|
+
*/
|
|
819
|
+
setTransform(node, width, height, deg) {
|
|
820
|
+
try {
|
|
821
|
+
this.__preventSizechange = true;
|
|
822
|
+
const info = this.#GetRotateValue(node);
|
|
823
|
+
const slope = info.r + (deg || 0) * 1;
|
|
824
|
+
deg = Math.abs(slope) >= 360 ? 0 : slope;
|
|
825
|
+
const isVertical = (this.isVertical = /^(90|270)$/.test(Math.abs(deg).toString()));
|
|
826
|
+
|
|
827
|
+
width = numbers.get(width, 0);
|
|
828
|
+
height = numbers.get(height, 0);
|
|
829
|
+
|
|
830
|
+
const element = /** @type {HTMLElement} */ (node);
|
|
831
|
+
const dataSize = (element.getAttribute('data-se-size') || 'auto,auto').split(',');
|
|
832
|
+
let transOrigin = '';
|
|
833
|
+
if (/auto|%$/.test(dataSize[0]) && !isVertical) {
|
|
834
|
+
if (dataSize[0] === 'auto' && dataSize[1] === 'auto') {
|
|
835
|
+
this._setAutoSize();
|
|
836
|
+
} else {
|
|
837
|
+
this._setPercentSize(dataSize[0], dataSize[1]);
|
|
838
|
+
}
|
|
839
|
+
} else {
|
|
840
|
+
const figureInfo = Figure.GetContainer(element);
|
|
841
|
+
const cover = figureInfo.cover || figureInfo.inlineCover;
|
|
842
|
+
const offsetW = width || element.offsetWidth;
|
|
843
|
+
const offsetH = height || element.offsetHeight;
|
|
844
|
+
const w = (isVertical ? offsetH : offsetW) + 'px';
|
|
845
|
+
const h = (isVertical ? offsetW : offsetH) + 'px';
|
|
846
|
+
|
|
847
|
+
this._deletePercentSize();
|
|
848
|
+
this._applySize(offsetW + 'px', offsetH + 'px', '');
|
|
849
|
+
|
|
850
|
+
cover.style.width = w;
|
|
851
|
+
cover.style.height = figureInfo.caption || figureInfo.inlineCover ? '' : h;
|
|
852
|
+
|
|
853
|
+
if (isVertical) {
|
|
854
|
+
const transW = offsetW / 2 + 'px ' + offsetW / 2 + 'px 0';
|
|
855
|
+
const transH = offsetH / 2 + 'px ' + offsetH / 2 + 'px 0';
|
|
856
|
+
transOrigin = deg === 90 || deg === -270 ? transH : transW;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
element.style.transformOrigin = transOrigin;
|
|
861
|
+
this._setRotate(element, deg, info.x, info.y);
|
|
862
|
+
|
|
863
|
+
if (isVertical) element.style.maxWidth = 'none';
|
|
864
|
+
else element.style.maxWidth = '';
|
|
865
|
+
|
|
866
|
+
this._setCaptionPosition(element);
|
|
867
|
+
} finally {
|
|
868
|
+
this.__preventSizechange = false;
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* @private
|
|
874
|
+
* @description Sets figure component properties such as cover, container, caption, and alignment.
|
|
875
|
+
* @param {FigureInfo} figureInfo - {target, container, cover, inlineCover, caption}
|
|
876
|
+
*/
|
|
877
|
+
_setFigureInfo(figureInfo) {
|
|
878
|
+
this._inlineCover = figureInfo.inlineCover;
|
|
879
|
+
this._cover = figureInfo.cover || this._inlineCover;
|
|
880
|
+
this._container = figureInfo.container;
|
|
881
|
+
this._caption = figureInfo.caption;
|
|
882
|
+
this._element = figureInfo.target;
|
|
883
|
+
this.align = (this._container.className.match(/(?:^|\s)__se__float-(none|left|center|right)(?:$|\s)/) || [])[1] || figureInfo.target.style.float || 'none';
|
|
884
|
+
this.as = this._inlineCover ? 'inline' : 'block';
|
|
885
|
+
this.isVertical = /^(90|270)$/.test(Math.abs(this.#GetRotateValue(figureInfo.target).r).toString());
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
/**
|
|
889
|
+
* @private
|
|
890
|
+
* @description Applies rotation transformation to the target element.
|
|
891
|
+
* @param {HTMLElement} element Target element.
|
|
892
|
+
* @param {number} r Rotation degree.
|
|
893
|
+
* @param {number} x X-axis rotation value.
|
|
894
|
+
* @param {number} y Y-axis rotation value.
|
|
895
|
+
*/
|
|
896
|
+
_setRotate(element, r, x, y) {
|
|
897
|
+
let width = (element.offsetWidth - element.offsetHeight) * (/^-/.test(r + '') ? 1 : -1);
|
|
898
|
+
let translate = '';
|
|
899
|
+
|
|
900
|
+
if (/[1-9]/.test(r + '') && (x || y)) {
|
|
901
|
+
translate = x ? 'Y' : 'X';
|
|
902
|
+
|
|
903
|
+
switch (r + '') {
|
|
904
|
+
case '90':
|
|
905
|
+
translate = x && y ? 'X' : y ? translate : '';
|
|
906
|
+
break;
|
|
907
|
+
case '270':
|
|
908
|
+
width *= -1;
|
|
909
|
+
translate = x && y ? 'Y' : x ? translate : '';
|
|
910
|
+
break;
|
|
911
|
+
case '-90':
|
|
912
|
+
translate = x && y ? 'Y' : x ? translate : '';
|
|
913
|
+
break;
|
|
914
|
+
case '-270':
|
|
915
|
+
width *= -1;
|
|
916
|
+
translate = x && y ? 'X' : y ? translate : '';
|
|
917
|
+
break;
|
|
918
|
+
default:
|
|
919
|
+
translate = '';
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
if (r % 180 === 0) {
|
|
924
|
+
element.style.maxWidth = '';
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
element.style.transform = 'rotate(' + r + 'deg)' + (x ? ' rotateX(' + x + 'deg)' : '') + (y ? ' rotateY(' + y + 'deg)' : '') + (translate ? ' translate' + translate + '(' + width + 'px)' : '');
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
/**
|
|
931
|
+
* @private
|
|
932
|
+
* @description Applies size adjustments to the figure element.
|
|
933
|
+
* @param {string|number} w Width value.
|
|
934
|
+
* @param {string|number} h Height value.
|
|
935
|
+
* @param {string} direction Resize direction.
|
|
936
|
+
*/
|
|
937
|
+
_applySize(w, h, direction) {
|
|
938
|
+
const onlyW = /^(rw|lw)$/.test(direction) && /\d+/.test(this._element.style.height);
|
|
939
|
+
const onlyH = /^(th|bh)$/.test(direction) && /\d+/.test(this._element.style.width);
|
|
940
|
+
h = /** @type {string} */ (h || (this.autoRatio ? this.autoRatio.current || this.autoRatio.default : h));
|
|
941
|
+
w = /** @type {string} */ (numbers.is(w) ? w + this.sizeUnit : w);
|
|
942
|
+
|
|
943
|
+
if (!/%$/.test(w) && !/%$/.test(h) && !onlyW && !onlyH) this._deletePercentSize();
|
|
944
|
+
|
|
945
|
+
const sizeTarget = this._cover || this._element;
|
|
946
|
+
|
|
947
|
+
if (this.autoRatio) this._cover.style.width = w;
|
|
948
|
+
if (!onlyH) {
|
|
949
|
+
sizeTarget.style.width = this._element.style.width = w;
|
|
950
|
+
}
|
|
951
|
+
if (!onlyW) {
|
|
952
|
+
h = numbers.is(h) ? h + this.sizeUnit : h;
|
|
953
|
+
sizeTarget.style.height = this._element.style.height = this.autoRatio && !this.isVertical ? '100%' : h;
|
|
954
|
+
if (this.autoRatio) {
|
|
955
|
+
this._cover.style.height = h;
|
|
956
|
+
this.__setCoverPaddingBottom(w, h);
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
if (this.align === 'center') this.setAlign(this._element, this.align);
|
|
961
|
+
|
|
962
|
+
// save current size
|
|
963
|
+
this._saveCurrentSize();
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
/**
|
|
967
|
+
* @private
|
|
968
|
+
* @description Sets padding-bottom for cover elements based on width and height.
|
|
969
|
+
* @param {string} w Width value.
|
|
970
|
+
* @param {string} h Height value.
|
|
971
|
+
*/
|
|
972
|
+
__setCoverPaddingBottom(w, h) {
|
|
973
|
+
if (this._inlineCover === this._cover) return;
|
|
974
|
+
|
|
975
|
+
this._cover.style.height = h;
|
|
976
|
+
if (/%$/.test(w) && this.align === 'center') {
|
|
977
|
+
this._cover.style.paddingBottom = !/%$/.test(h) ? h : numbers.get((numbers.get(h, 2) / 100) * numbers.get(w, 2), 2) + '%';
|
|
978
|
+
} else {
|
|
979
|
+
this._cover.style.paddingBottom = h;
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
/**
|
|
984
|
+
* @private
|
|
985
|
+
* @description Sets the figure element to its auto size.
|
|
986
|
+
*/
|
|
987
|
+
_setAutoSize() {
|
|
988
|
+
if (this._caption) this._caption.style.marginTop = '';
|
|
989
|
+
this.deleteTransform();
|
|
990
|
+
this._deletePercentSize();
|
|
991
|
+
|
|
992
|
+
if (this.autoRatio) {
|
|
993
|
+
this._setPercentSize('100%', this.autoRatio.current || this.autoRatio.default);
|
|
994
|
+
} else {
|
|
995
|
+
this._element.style.maxWidth = '';
|
|
996
|
+
this._element.style.width = '';
|
|
997
|
+
this._element.style.height = '';
|
|
998
|
+
this._cover.style.width = '';
|
|
999
|
+
this._cover.style.height = '';
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
this.setAlign(this._element, this.align);
|
|
1003
|
+
|
|
1004
|
+
// save current size
|
|
1005
|
+
this._saveCurrentSize();
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
/**
|
|
1009
|
+
* @private
|
|
1010
|
+
* @description Sets the figure element's size in percentage.
|
|
1011
|
+
* @param {string|number} w Width percentage.
|
|
1012
|
+
* @param {string|number} h Height percentage.
|
|
1013
|
+
*/
|
|
1014
|
+
_setPercentSize(w, h) {
|
|
1015
|
+
if (!h) h = this.autoRatio ? (/%$/.test(this.autoRatio.current) ? this.autoRatio.current : this.autoRatio.default) : h;
|
|
1016
|
+
h = h && !/%$/.test(h + '') && !numbers.get(h, 0) ? (numbers.is(h) ? h + '%' : h) : numbers.is(h) ? h + this.sizeUnit : h || (this.autoRatio ? this.autoRatio.default : '');
|
|
1017
|
+
|
|
1018
|
+
const heightPercentage = /%$/.test(h + '');
|
|
1019
|
+
this._container.style.width = String(numbers.is(w) ? w + '%' : w);
|
|
1020
|
+
this._container.style.height = '';
|
|
1021
|
+
|
|
1022
|
+
// exceptionFormat
|
|
1023
|
+
if (this._element === this._cover && !this.options.get('strictMode').formatFilter) {
|
|
1024
|
+
this._saveCurrentSize();
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
if (this._inlineCover !== this._cover) {
|
|
1029
|
+
this._cover.style.width = '100%';
|
|
1030
|
+
this._cover.style.height = String(h);
|
|
1031
|
+
}
|
|
1032
|
+
this._element.style.width = '100%';
|
|
1033
|
+
this._element.style.maxWidth = '';
|
|
1034
|
+
this._element.style.height = String(this.autoRatio ? '100%' : heightPercentage ? '' : h);
|
|
1035
|
+
|
|
1036
|
+
if (this.align === 'center') this.setAlign(this._element, this.align);
|
|
1037
|
+
if (this.autoRatio) {
|
|
1038
|
+
this.__setCoverPaddingBottom(String(w), String(h));
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
this._setCaptionPosition(this._element);
|
|
1042
|
+
|
|
1043
|
+
// save current size
|
|
1044
|
+
this._saveCurrentSize();
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
/**
|
|
1048
|
+
* @private
|
|
1049
|
+
* @description Deletes percentage-based sizing from the figure element.
|
|
1050
|
+
*/
|
|
1051
|
+
_deletePercentSize() {
|
|
1052
|
+
this._cover.style.width = '';
|
|
1053
|
+
this._cover.style.height = '';
|
|
1054
|
+
this._container.style.width = '';
|
|
1055
|
+
this._container.style.height = '';
|
|
1056
|
+
|
|
1057
|
+
dom.utils.removeClass(this._container, this._floatClassStr);
|
|
1058
|
+
dom.utils.addClass(this._container, '__se__float-' + this.align);
|
|
1059
|
+
|
|
1060
|
+
if (this.align === 'center') this.setAlign(this._element, this.align);
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
/**
|
|
1064
|
+
* @private
|
|
1065
|
+
* @description Reverts the figure element to its previously saved size.
|
|
1066
|
+
*/
|
|
1067
|
+
_setRevert() {
|
|
1068
|
+
this.setSize(this.__revertSize.w, this.__revertSize.h);
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
/**
|
|
1072
|
+
* @private
|
|
1073
|
+
* @description Updates the figure's alignment icon.
|
|
1074
|
+
*/
|
|
1075
|
+
_setAlignIcon() {
|
|
1076
|
+
if (!this.alignButton) return;
|
|
1077
|
+
dom.utils.changeElement(this.alignButton.firstElementChild, this._alignIcons[this.align]);
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
/**
|
|
1081
|
+
* @private
|
|
1082
|
+
* @description Updates the figure's block/inline format icon.
|
|
1083
|
+
*/
|
|
1084
|
+
_setAsIcon() {
|
|
1085
|
+
if (!this.asButton) return;
|
|
1086
|
+
dom.utils.changeElement(this.asButton.firstElementChild, this.icons[`as_${this.as}`]);
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
/**
|
|
1090
|
+
* @private
|
|
1091
|
+
* @description Saves the current size of the figure component.
|
|
1092
|
+
*/
|
|
1093
|
+
_saveCurrentSize() {
|
|
1094
|
+
if (this.__preventSizechange) return;
|
|
1095
|
+
|
|
1096
|
+
const dataSize = (this._element.getAttribute('data-se-size') || ',').split(',');
|
|
1097
|
+
this.__revertSize.w = dataSize[0];
|
|
1098
|
+
this.__revertSize.h = dataSize[1];
|
|
1099
|
+
|
|
1100
|
+
const size = this.getSize(this._element);
|
|
1101
|
+
// add too width, height attribute
|
|
1102
|
+
this._element.setAttribute('width', size.w.replace('px', ''));
|
|
1103
|
+
this._element.setAttribute('height', size.h.replace('px', ''));
|
|
1104
|
+
this._element.setAttribute('data-se-size', size.w + ',' + size.h);
|
|
1105
|
+
if (this.autoRatio) {
|
|
1106
|
+
this.autoRatio.current = /%$/.test(size.h) ? size.h : '';
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
/**
|
|
1111
|
+
* @private
|
|
1112
|
+
* @description Adjusts the position of the caption within the figure.
|
|
1113
|
+
* @param {HTMLElement} element Target element.
|
|
1114
|
+
*/
|
|
1115
|
+
_setCaptionPosition(element) {
|
|
1116
|
+
const figcaption = /** @type {HTMLElement} */ (dom.query.getEdgeChild(dom.query.getParentElement(element, 'FIGURE'), 'FIGCAPTION', false));
|
|
1117
|
+
if (figcaption) {
|
|
1118
|
+
figcaption.style.marginTop = (this.isVertical ? element.offsetWidth - element.offsetHeight : 0) + 'px';
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
/**
|
|
1123
|
+
* @private
|
|
1124
|
+
* @description Removes the margin top property from the figure caption.
|
|
1125
|
+
* @param {HTMLElement} element Target element.
|
|
1126
|
+
*/
|
|
1127
|
+
_deleteCaptionPosition(element) {
|
|
1128
|
+
const figcaption = /** @type {HTMLElement} */ (dom.query.getEdgeChild(dom.query.getParentElement(element, 'FIGURE'), 'FIGCAPTION', false));
|
|
1129
|
+
if (figcaption) {
|
|
1130
|
+
figcaption.style.marginTop = '';
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
/**
|
|
1135
|
+
* @private
|
|
1136
|
+
* @description Displays or hides the resize handles of the figure component.
|
|
1137
|
+
* @param {boolean} display Whether to display resize handles.
|
|
1138
|
+
*/
|
|
1139
|
+
_displayResizeHandles(display) {
|
|
1140
|
+
const type = !display ? 'none' : 'flex';
|
|
1141
|
+
this.controller.form.style.display = type;
|
|
1142
|
+
|
|
1143
|
+
const _figure = this.editor.frameContext.get('_figure');
|
|
1144
|
+
const resizeHandles = _figure.handles;
|
|
1145
|
+
for (let i = 0, len = resizeHandles.length; i < len; i++) {
|
|
1146
|
+
resizeHandles[i].style.display = type;
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
if (type === 'none') {
|
|
1150
|
+
dom.utils.addClass(_figure.main, 'se-resize-ing');
|
|
1151
|
+
this.__onResizeESCEvent = this.eventManager.addGlobalEvent('keydown', this.__containerResizingESC);
|
|
1152
|
+
} else {
|
|
1153
|
+
dom.utils.removeClass(_figure.main, 'se-resize-ing');
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
/**
|
|
1158
|
+
* @private
|
|
1159
|
+
* @description Removes the resize event listeners.
|
|
1160
|
+
*/
|
|
1161
|
+
_offResizeEvent() {
|
|
1162
|
+
this.component._removeDragEvent();
|
|
1163
|
+
this.eventManager.removeGlobalEvent(this.__onContainerEvent);
|
|
1164
|
+
this.eventManager.removeGlobalEvent(this.__offContainerEvent);
|
|
1165
|
+
this.eventManager.removeGlobalEvent(this.__onResizeESCEvent);
|
|
1166
|
+
|
|
1167
|
+
this._displayResizeHandles(true);
|
|
1168
|
+
this.ui._offCurrentController();
|
|
1169
|
+
this.ui.disableBackWrapper();
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
/**
|
|
1173
|
+
* @private
|
|
1174
|
+
* @description Sets up drag event handling for the figure component.
|
|
1175
|
+
* @param {Node} figureMain The main figure container element.
|
|
1176
|
+
*/
|
|
1177
|
+
_setDragEvent(figureMain) {
|
|
1178
|
+
const dragHandle = this.editor.frameContext.get('wrapper').querySelector('.se-drag-handle');
|
|
1179
|
+
dom.utils.removeClass(dragHandle, 'se-drag-handle-full');
|
|
1180
|
+
|
|
1181
|
+
dragHandle.style.opacity = '';
|
|
1182
|
+
dragHandle.style.width = '';
|
|
1183
|
+
dragHandle.style.height = '';
|
|
1184
|
+
|
|
1185
|
+
_DragHandle.set('__dragHandler', dragHandle);
|
|
1186
|
+
_DragHandle.set('__dragContainer', this._container);
|
|
1187
|
+
_DragHandle.set('__dragCover', this._cover);
|
|
1188
|
+
_DragHandle.set('__dragMove', this.#OnScrollDragHandler.bind(this, dragHandle, figureMain));
|
|
1189
|
+
|
|
1190
|
+
_DragHandle.get('__dragMove')();
|
|
1191
|
+
|
|
1192
|
+
dragHandle.style.display = 'block';
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
/**
|
|
1196
|
+
* @param {HTMLElement} dragHandle Drag handle element
|
|
1197
|
+
* @param {HTMLElement} figureMain Figure container element
|
|
1198
|
+
*/
|
|
1199
|
+
#OnScrollDragHandler(dragHandle, figureMain) {
|
|
1200
|
+
dragHandle.style.display = 'block';
|
|
1201
|
+
dragHandle.style.left = figureMain.offsetLeft + (this.options.get('_rtl') ? dragHandle.offsetWidth : figureMain.offsetWidth - dragHandle.offsetWidth * 1.5) + 'px';
|
|
1202
|
+
dragHandle.style.top = figureMain.offsetTop - dragHandle.offsetHeight + 'px';
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
/**
|
|
1206
|
+
* @param {MouseEvent} e Event object
|
|
1207
|
+
*/
|
|
1208
|
+
#OnResizeContainer(e) {
|
|
1209
|
+
e.stopPropagation();
|
|
1210
|
+
e.preventDefault();
|
|
1211
|
+
|
|
1212
|
+
const inst = _DragHandle.get('__figureInst');
|
|
1213
|
+
if (!inst) return;
|
|
1214
|
+
|
|
1215
|
+
const eventTarget = dom.query.getEventTarget(e);
|
|
1216
|
+
const direction = (inst._resize_direction = eventTarget.classList[0]);
|
|
1217
|
+
inst._resizeClientX = e.clientX;
|
|
1218
|
+
inst._resizeClientY = e.clientY;
|
|
1219
|
+
inst.editor.frameContext.get('_figure').main.style.float = /l/.test(direction) ? 'right' : /r/.test(direction) ? 'left' : 'none';
|
|
1220
|
+
this.ui.enableBackWrapper(DIRECTION_CURSOR_MAP[direction]);
|
|
1221
|
+
|
|
1222
|
+
const { w, h } = this.getSize(inst._element);
|
|
1223
|
+
__resizing_p_wh = __resizing_p_ow = false;
|
|
1224
|
+
__resizing_cw = __resizing_sw = 0;
|
|
1225
|
+
if (!this.isVertical) {
|
|
1226
|
+
const pw = !w || /auto|%$/.test(w);
|
|
1227
|
+
const ph = !h || /auto|%$/.test(h);
|
|
1228
|
+
if (DIR_DIAGONAL.includes(direction) && pw && ph) {
|
|
1229
|
+
__resizing_p_wh = true;
|
|
1230
|
+
} else if (DIR_W.includes(direction) && pw) {
|
|
1231
|
+
__resizing_p_ow = true;
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
if (__resizing_p_wh || __resizing_p_ow) {
|
|
1235
|
+
const sizeTarget = inst._cover || inst._element;
|
|
1236
|
+
__resizing_sw = sizeTarget.offsetWidth;
|
|
1237
|
+
__resizing_cw = converter.getWidthInPercentage(sizeTarget, this.editor.frameContext.get('wysiwygFrame')) / 100;
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
inst.__onContainerEvent = inst.eventManager.addGlobalEvent('mousemove', inst.__containerResizing);
|
|
1242
|
+
inst.__offContainerEvent = inst.eventManager.addGlobalEvent('mouseup', inst.__containerResizingOff);
|
|
1243
|
+
inst._displayResizeHandles(false);
|
|
1244
|
+
|
|
1245
|
+
const _display = this.editor.frameContext.get('_figure').display;
|
|
1246
|
+
_display.style.display = 'block';
|
|
1247
|
+
dom.utils.changeTxt(_display, w + ' x ' + h);
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
/**
|
|
1251
|
+
* @description Handles the resizing of the figure container.
|
|
1252
|
+
* @param {MouseEvent} e Mouse event.
|
|
1253
|
+
*/
|
|
1254
|
+
#ContainerResizing(e) {
|
|
1255
|
+
const direction = this._resize_direction;
|
|
1256
|
+
const clientX = e.clientX;
|
|
1257
|
+
const clientY = e.clientY;
|
|
1258
|
+
|
|
1259
|
+
let resultW = this._element_w;
|
|
1260
|
+
let resultH = this._element_h;
|
|
1261
|
+
|
|
1262
|
+
const w = resultW + (/r/.test(direction) ? clientX - this._resizeClientX : this._resizeClientX - clientX);
|
|
1263
|
+
const h = resultH + (/b/.test(direction) ? clientY - this._resizeClientY : this._resizeClientY - clientY);
|
|
1264
|
+
const wh = (resultH / resultW) * w;
|
|
1265
|
+
const resizeBorder = this.editor.frameContext.get('_figure').border;
|
|
1266
|
+
|
|
1267
|
+
if (/t/.test(direction)) resizeBorder.style.top = resultH - (/h/.test(direction) ? h : wh) + 'px';
|
|
1268
|
+
if (/l/.test(direction)) resizeBorder.style.left = resultW - w + 'px';
|
|
1269
|
+
|
|
1270
|
+
if (/r|l/.test(direction)) {
|
|
1271
|
+
resizeBorder.style.width = w + 'px';
|
|
1272
|
+
resultW = w;
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
if (/^(t|b)[^h]$/.test(direction)) {
|
|
1276
|
+
resizeBorder.style.height = wh + 'px';
|
|
1277
|
+
resultH = wh;
|
|
1278
|
+
} else if (/^(t|b)h$/.test(direction)) {
|
|
1279
|
+
resizeBorder.style.height = h + 'px';
|
|
1280
|
+
resultH = h;
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
this._resize_w = /** @type {number} */ (/h$/.test(direction) ? this._width : Math.round(resultW));
|
|
1284
|
+
this._resize_h = /** @type {number} */ (/w$/.test(direction) ? this._height : Math.round(resultH));
|
|
1285
|
+
const rw = __resizing_cw ? (this._resize_w / __resizing_sw) * __resizing_cw * 100 : this._resize_w;
|
|
1286
|
+
dom.utils.changeTxt(this.editor.frameContext.get('_figure').display, __resizing_cw ? numbers.get(rw > 100 ? 100 : rw, 2).toFixed(2) + '%' : rw + ' x ' + this._resize_h);
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
/**
|
|
1290
|
+
* @description Finalizes the resizing process of the figure container.
|
|
1291
|
+
*/
|
|
1292
|
+
#ContainerResizingOff() {
|
|
1293
|
+
this._offResizeEvent();
|
|
1294
|
+
|
|
1295
|
+
// set size
|
|
1296
|
+
let w = this.isVertical ? this._resize_h : this._resize_w;
|
|
1297
|
+
let h = this.isVertical ? this._resize_w : this._resize_h;
|
|
1298
|
+
w = Math.round(w) || w;
|
|
1299
|
+
h = Math.round(h) || h;
|
|
1300
|
+
|
|
1301
|
+
if (!this.isVertical && !/%$/.test(w + '')) {
|
|
1302
|
+
const limit =
|
|
1303
|
+
this.editor.frameContext.get('wysiwygFrame').clientWidth -
|
|
1304
|
+
numbers.get(this.editor.frameContext.get('wwComputedStyle').getPropertyValue('padding-left')) +
|
|
1305
|
+
numbers.get(this.editor.frameContext.get('wwComputedStyle').getPropertyValue('padding-right')) -
|
|
1306
|
+
2;
|
|
1307
|
+
if (numbers.get(w, 0) > limit) {
|
|
1308
|
+
h = Math.round((h / w) * limit);
|
|
1309
|
+
w = limit;
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
if (__resizing_p_wh || __resizing_p_ow) {
|
|
1314
|
+
const sizeTarget = this._cover || this._element;
|
|
1315
|
+
w = (w / sizeTarget.offsetWidth) * __resizing_cw * 100;
|
|
1316
|
+
const wp = numbers.get(w > 100 ? 100 : w, 2) + '%';
|
|
1317
|
+
this._setPercentSize(wp, __resizing_p_ow ? this.getSize(this._element).h : '');
|
|
1318
|
+
} else {
|
|
1319
|
+
this._applySize(w, h, this._resize_direction);
|
|
1320
|
+
if (this.isVertical) this.setTransform(this._element, w, h, 0);
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
this.history.push(false);
|
|
1324
|
+
this.component.select(this._element, this.kind);
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
/**
|
|
1328
|
+
* @description Cancels the resizing process when the escape key is pressed.
|
|
1329
|
+
* @param {KeyboardEvent} e Keyboard event.
|
|
1330
|
+
*/
|
|
1331
|
+
#ContainerResizingESC(e) {
|
|
1332
|
+
if (!keyCodeMap.isEsc(e.code)) return;
|
|
1333
|
+
this._offResizeEvent();
|
|
1334
|
+
this.component.select(this._element, this.kind);
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
/**
|
|
1338
|
+
* @param { "none"|"left"|"center"|"right"} value align value
|
|
1339
|
+
*/
|
|
1340
|
+
#SetMenuAlign(value) {
|
|
1341
|
+
this.setAlign(this._element, value);
|
|
1342
|
+
this.selectMenu_align.close();
|
|
1343
|
+
this.component.select(this._element, this.kind);
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
/**
|
|
1347
|
+
* @param {"block"|"inline"} value Format style
|
|
1348
|
+
*/
|
|
1349
|
+
#SetMenuAs(value) {
|
|
1350
|
+
this.convertAsFormat(this._element, value);
|
|
1351
|
+
this.selectMenu_as.close();
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
/**
|
|
1355
|
+
* @param {"auto"|number} value Resize value
|
|
1356
|
+
*/
|
|
1357
|
+
#SetResize(value) {
|
|
1358
|
+
if (value === 'auto') {
|
|
1359
|
+
this.deleteTransform();
|
|
1360
|
+
this._setAutoSize();
|
|
1361
|
+
} else {
|
|
1362
|
+
let dataY = this.getSize(this._element).h;
|
|
1363
|
+
if (this.isVertical) {
|
|
1364
|
+
const dataSize = (this._element.getAttribute('data-se-size') || ',').split(',');
|
|
1365
|
+
if (dataSize[1]) dataY = dataSize[1];
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
this.deleteTransform();
|
|
1369
|
+
this._setPercentSize(value * 1, numbers.get(dataY, 0) === null || !/%$/.test(dataY) ? '' : dataY);
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
this.selectMenu_resize.close();
|
|
1373
|
+
this.component.select(this._element, this.kind);
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
#OffFigureContainer() {
|
|
1377
|
+
this.editor.frameContext.get('_figure').main.style.display = 'none';
|
|
1378
|
+
this.editor._figureContainer = null;
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
#OnClick_alignButton() {
|
|
1382
|
+
this.selectMenu_align.open('', '[data-command="' + this.align + '"]');
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
#OnClick_asButton() {
|
|
1386
|
+
this.selectMenu_as.open('', '[data-command="' + this.as + '"]');
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
#OnClick_resizeButton() {
|
|
1390
|
+
const size = this.getSize(this._element);
|
|
1391
|
+
const w = size.w;
|
|
1392
|
+
const h = size.h;
|
|
1393
|
+
let command = '';
|
|
1394
|
+
if (this.autoRatio) {
|
|
1395
|
+
if (h === this.autoRatio.default && /%$/.test(w)) {
|
|
1396
|
+
const nw = numbers.get(w);
|
|
1397
|
+
if (nw === 100) command = 'auto';
|
|
1398
|
+
else command = 'resize_percent' + nw;
|
|
1399
|
+
}
|
|
1400
|
+
} else if (h === 'auto') {
|
|
1401
|
+
if (w === 'auto') {
|
|
1402
|
+
command = 'auto';
|
|
1403
|
+
} else if (/%$/.test(w)) {
|
|
1404
|
+
command = 'resize_percent' + numbers.get(w);
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
this.selectMenu_resize.open('', '[data-command="' + command + '"]');
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
/**
|
|
1412
|
+
* @param {Node} element Target element
|
|
1413
|
+
* @returns {{ r: *, x: *, y: * }} Rotation value
|
|
1414
|
+
*/
|
|
1415
|
+
#GetRotateValue(element) {
|
|
1416
|
+
const transform = /** @type {HTMLElement} */ (element).style.transform;
|
|
1417
|
+
if (!transform) return { r: 0, x: '', y: '' };
|
|
1418
|
+
return {
|
|
1419
|
+
r: Number((transform.match(/rotate\(([-0-9]+)deg\)/) || [])[1] || 0),
|
|
1420
|
+
x: (transform.match(/rotateX\(([-0-9]+)deg\)/) || [])[1] || '',
|
|
1421
|
+
y: (transform.match(/rotateY\(([-0-9]+)deg\)/) || [])[1] || ''
|
|
1422
|
+
};
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
function CreateAlign(inst, button) {
|
|
1427
|
+
if (!button) return null;
|
|
1428
|
+
|
|
1429
|
+
const icons = [inst._alignIcons.none, inst._alignIcons.left, inst._alignIcons.center, inst._alignIcons.right];
|
|
1430
|
+
const langs = [inst.lang.basic, inst.lang.left, inst.lang.center, inst.lang.right];
|
|
1431
|
+
const commands = ['none', 'left', 'center', 'right'];
|
|
1432
|
+
const html = [];
|
|
1433
|
+
const items = [];
|
|
1434
|
+
for (let i = 0; i < commands.length; i++) {
|
|
1435
|
+
html.push(/*html*/ `
|
|
1436
|
+
<button type="button" class="se-btn-list se-tooltip" data-command="${commands[i]}" data-type="selectMenu" >
|
|
1437
|
+
${icons[i]}
|
|
1438
|
+
<span class="se-tooltip-inner">
|
|
1439
|
+
<span class="se-tooltip-text">${langs[i]}</span>
|
|
1440
|
+
</span>
|
|
1441
|
+
</button>`);
|
|
1442
|
+
items.push(commands[i]);
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
return { html: html, items: items };
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
function CreateAs(inst, button) {
|
|
1449
|
+
if (!button) return null;
|
|
1450
|
+
|
|
1451
|
+
const icons = [inst.icons.as_block, inst.icons.as_inline];
|
|
1452
|
+
const langs = [inst.lang.asBlock, inst.lang.asInline];
|
|
1453
|
+
const commands = ['block', 'inline'];
|
|
1454
|
+
const html = [];
|
|
1455
|
+
const items = [];
|
|
1456
|
+
for (let i = 0; i < commands.length; i++) {
|
|
1457
|
+
html.push(/*html*/ `
|
|
1458
|
+
<button type="button" class="se-btn-list se-tooltip" data-command="${commands[i]}" data-type="selectMenu" >
|
|
1459
|
+
${icons[i]}
|
|
1460
|
+
<span class="se-tooltip-inner">
|
|
1461
|
+
<span class="se-tooltip-text">${langs[i]}</span>
|
|
1462
|
+
</span>
|
|
1463
|
+
</button>`);
|
|
1464
|
+
items.push(commands[i]);
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
return { html: html, items: items };
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
function CreateResize(editor, button) {
|
|
1471
|
+
if (!button) return null;
|
|
1472
|
+
|
|
1473
|
+
const items = button.getAttribute('data-value').split(',');
|
|
1474
|
+
const html = [];
|
|
1475
|
+
for (let i = 0, n, c, v, l; i < items.length; i++) {
|
|
1476
|
+
v = items[i];
|
|
1477
|
+
n = numbers.is(v);
|
|
1478
|
+
c = n ? 'resize_percent' + v : 'auto';
|
|
1479
|
+
l = n ? v + '%' : editor.lang.autoSize;
|
|
1480
|
+
html.push('<button type="button" class="se-btn-list" data-command="' + c + '" data-value="' + v + '"><span>' + l + '</span></button>');
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
return { html: html, items: items };
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
function CreateHTML_resizeDot() {
|
|
1487
|
+
const html = /*html*/ `
|
|
1488
|
+
<div class="se-resize-dot">
|
|
1489
|
+
<span class="tl"></span>
|
|
1490
|
+
<span class="tr"></span>
|
|
1491
|
+
<span class="bl"></span>
|
|
1492
|
+
<span class="br"></span>
|
|
1493
|
+
<span class="lw"></span>
|
|
1494
|
+
<span class="th"></span>
|
|
1495
|
+
<span class="rw"></span>
|
|
1496
|
+
<span class="bh"></span>
|
|
1497
|
+
<div class="se-resize-display"></div>
|
|
1498
|
+
</div>`;
|
|
1499
|
+
|
|
1500
|
+
return dom.utils.createElement('DIV', { class: 'se-controller se-resizing-container', style: 'display: none;' }, html);
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
function GET_CONTROLLER_BUTTONS(group) {
|
|
1504
|
+
const g = group.split('_');
|
|
1505
|
+
const command = g[0];
|
|
1506
|
+
const value = g[1];
|
|
1507
|
+
let c, v, l, t, i;
|
|
1508
|
+
|
|
1509
|
+
switch (command) {
|
|
1510
|
+
case 'resize':
|
|
1511
|
+
c = 'onresize';
|
|
1512
|
+
v = value;
|
|
1513
|
+
l = 'resize';
|
|
1514
|
+
i = 'resize';
|
|
1515
|
+
break;
|
|
1516
|
+
case 'auto':
|
|
1517
|
+
c = 'auto';
|
|
1518
|
+
l = 'autoSize';
|
|
1519
|
+
i = 'auto_size';
|
|
1520
|
+
break;
|
|
1521
|
+
case 'rotate':
|
|
1522
|
+
c = 'rotate';
|
|
1523
|
+
v = value === 'l' ? -90 : value === 'r' ? 90 : numbers.get(value);
|
|
1524
|
+
l = v < 0 ? 'rotateLeft' : 'rotateRight';
|
|
1525
|
+
i = v < 0 ? 'rotate_left' : 'rotate_right';
|
|
1526
|
+
break;
|
|
1527
|
+
case 'mirror':
|
|
1528
|
+
c = 'mirror';
|
|
1529
|
+
v = value;
|
|
1530
|
+
l = value === 'h' ? 'mirrorHorizontal' : 'mirrorVertical';
|
|
1531
|
+
i = value === 'h' ? 'mirror_horizontal' : 'mirror_vertical';
|
|
1532
|
+
break;
|
|
1533
|
+
case 'align':
|
|
1534
|
+
c = 'onalign';
|
|
1535
|
+
l = 'align';
|
|
1536
|
+
i = 'align_justify';
|
|
1537
|
+
break;
|
|
1538
|
+
case 'caption':
|
|
1539
|
+
c = 'caption';
|
|
1540
|
+
l = 'caption';
|
|
1541
|
+
i = 'caption';
|
|
1542
|
+
break;
|
|
1543
|
+
case 'revert':
|
|
1544
|
+
c = 'revert';
|
|
1545
|
+
l = 'revert';
|
|
1546
|
+
i = 'revert';
|
|
1547
|
+
break;
|
|
1548
|
+
case 'edit':
|
|
1549
|
+
c = 'edit';
|
|
1550
|
+
l = 'edit';
|
|
1551
|
+
i = 'edit';
|
|
1552
|
+
break;
|
|
1553
|
+
case 'as':
|
|
1554
|
+
c = 'onas';
|
|
1555
|
+
l = 'blockStyle';
|
|
1556
|
+
i = 'as_block';
|
|
1557
|
+
break;
|
|
1558
|
+
case 'copy':
|
|
1559
|
+
c = 'copy';
|
|
1560
|
+
l = 'copy';
|
|
1561
|
+
i = 'copy';
|
|
1562
|
+
break;
|
|
1563
|
+
case 'remove':
|
|
1564
|
+
c = 'remove';
|
|
1565
|
+
l = 'remove';
|
|
1566
|
+
i = 'delete';
|
|
1567
|
+
break;
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
if (!c) return null;
|
|
1571
|
+
|
|
1572
|
+
return {
|
|
1573
|
+
c: c,
|
|
1574
|
+
v: v,
|
|
1575
|
+
l: l,
|
|
1576
|
+
t: t,
|
|
1577
|
+
i: i
|
|
1578
|
+
};
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
function CreateHTML_controller(inst, controls) {
|
|
1582
|
+
let html = null;
|
|
1583
|
+
|
|
1584
|
+
if (controls?.length > 0) {
|
|
1585
|
+
const { lang, icons } = inst;
|
|
1586
|
+
html = '<div class="se-arrow se-arrow-up"></div>';
|
|
1587
|
+
for (let i = 0, group; i < controls.length; i++) {
|
|
1588
|
+
group = controls[i];
|
|
1589
|
+
html += '<div class="se-btn-group">';
|
|
1590
|
+
for (let j = 0, len = group.length, m; j < len; j++) {
|
|
1591
|
+
m = group[j];
|
|
1592
|
+
|
|
1593
|
+
if (typeof m?.action === 'function') {
|
|
1594
|
+
const g = m;
|
|
1595
|
+
m = {
|
|
1596
|
+
c: `__c__${g.command}`,
|
|
1597
|
+
v: g.value || '',
|
|
1598
|
+
l: g.title,
|
|
1599
|
+
i: g.icon
|
|
1600
|
+
};
|
|
1601
|
+
inst._action[m.c] = g.action;
|
|
1602
|
+
} else {
|
|
1603
|
+
m = GET_CONTROLLER_BUTTONS(m);
|
|
1604
|
+
if (!m) continue;
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
html += /*html*/ `
|
|
1608
|
+
<button type="button" data-command="${m.c}" data-value="${m.v}" class="se-btn se-tooltip">
|
|
1609
|
+
${icons[m.i] || m.i}
|
|
1610
|
+
<span class="se-tooltip-inner"><span class="se-tooltip-text">${lang[m.l] || m.l}</span></span>
|
|
1611
|
+
</button>`;
|
|
1612
|
+
}
|
|
1613
|
+
html += '</div>';
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
return dom.utils.createElement('DIV', { class: 'se-controller se-controller-resizing' + (!html ? ' se-empty-controller' : '') }, html);
|
|
1618
|
+
}
|
|
1619
|
+
|
|
1620
|
+
export default Figure;
|