@ckeditor/ckeditor5-widget 40.0.0 → 40.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE.md +3 -3
- package/package.json +7 -7
- package/src/augmentation.d.ts +13 -13
- package/src/augmentation.js +5 -5
- package/src/highlightstack.d.ts +74 -74
- package/src/highlightstack.js +129 -129
- package/src/index.d.ts +13 -13
- package/src/index.js +13 -13
- package/src/utils.d.ts +198 -198
- package/src/utils.js +348 -348
- package/src/verticalnavigation.d.ts +15 -15
- package/src/verticalnavigation.js +196 -196
- package/src/widget.d.ts +95 -91
- package/src/widget.js +429 -380
- package/src/widgetresize/resizer.d.ts +177 -177
- package/src/widgetresize/resizer.js +372 -372
- package/src/widgetresize/resizerstate.d.ts +125 -125
- package/src/widgetresize/resizerstate.js +150 -150
- package/src/widgetresize/sizeview.d.ts +55 -55
- package/src/widgetresize/sizeview.js +63 -63
- package/src/widgetresize.d.ts +125 -125
- package/src/widgetresize.js +188 -188
- package/src/widgettoolbarrepository.d.ts +94 -94
- package/src/widgettoolbarrepository.js +268 -268
- package/src/widgettypearound/utils.d.ts +38 -38
- package/src/widgettypearound/utils.js +52 -52
- package/src/widgettypearound/widgettypearound.d.ts +229 -229
- package/src/widgettypearound/widgettypearound.js +773 -773
@@ -1,125 +1,125 @@
|
|
1
|
-
/**
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
-
*/
|
5
|
-
import type { ResizerOptions } from '../widgetresize';
|
6
|
-
declare const ResizeState_base: {
|
7
|
-
new (): import("@ckeditor/ckeditor5-utils").Observable;
|
8
|
-
prototype: import("@ckeditor/ckeditor5-utils").Observable;
|
9
|
-
};
|
10
|
-
/**
|
11
|
-
* Stores the internal state of a single resizable object.
|
12
|
-
*/
|
13
|
-
export default class ResizeState extends ResizeState_base {
|
14
|
-
/**
|
15
|
-
* The position of the handle that initiated the resizing. E.g. `"top-left"`, `"bottom-right"` etc. or `null`
|
16
|
-
* if unknown.
|
17
|
-
*
|
18
|
-
* @readonly
|
19
|
-
* @observable
|
20
|
-
*/
|
21
|
-
activeHandlePosition: string | null;
|
22
|
-
/**
|
23
|
-
* The width (percents) proposed, but not committed yet, in the current resize process.
|
24
|
-
*
|
25
|
-
* @readonly
|
26
|
-
* @observable
|
27
|
-
*/
|
28
|
-
proposedWidthPercents: number | null;
|
29
|
-
/**
|
30
|
-
* The width (pixels) proposed, but not committed yet, in the current resize process.
|
31
|
-
*
|
32
|
-
* @readonly
|
33
|
-
* @observable
|
34
|
-
*/
|
35
|
-
proposedWidth: number | null;
|
36
|
-
/**
|
37
|
-
* The height (pixels) proposed, but not committed yet, in the current resize process.
|
38
|
-
*
|
39
|
-
* @readonly
|
40
|
-
* @observable
|
41
|
-
*/
|
42
|
-
proposedHeight: number | null;
|
43
|
-
/**
|
44
|
-
* @readonly
|
45
|
-
* @observable
|
46
|
-
*/
|
47
|
-
proposedHandleHostWidth: number | null;
|
48
|
-
/**
|
49
|
-
* @readonly
|
50
|
-
* @observable
|
51
|
-
*/
|
52
|
-
proposedHandleHostHeight: number | null;
|
53
|
-
/**
|
54
|
-
* The reference point of the resizer where the dragging started. It is used to measure the distance the user cursor
|
55
|
-
* traveled, so how much the image should be enlarged.
|
56
|
-
* This information is only known after the DOM was rendered, so it will be updated later.
|
57
|
-
*
|
58
|
-
* @internal
|
59
|
-
*/
|
60
|
-
_referenceCoordinates: {
|
61
|
-
x: number;
|
62
|
-
y: number;
|
63
|
-
} | null;
|
64
|
-
/**
|
65
|
-
* Resizer options.
|
66
|
-
*/
|
67
|
-
private readonly _options;
|
68
|
-
/**
|
69
|
-
* The original width (pixels) of the resized object when the resize process was started.
|
70
|
-
*
|
71
|
-
* @readonly
|
72
|
-
*/
|
73
|
-
private _originalWidth?;
|
74
|
-
/**
|
75
|
-
* The original height (pixels) of the resized object when the resize process was started.
|
76
|
-
*
|
77
|
-
* @readonly
|
78
|
-
*/
|
79
|
-
private _originalHeight?;
|
80
|
-
/**
|
81
|
-
* The original width (percents) of the resized object when the resize process was started.
|
82
|
-
*
|
83
|
-
* @readonly
|
84
|
-
*/
|
85
|
-
private _originalWidthPercents?;
|
86
|
-
/**
|
87
|
-
* A width to height ratio of the resized image.
|
88
|
-
*
|
89
|
-
* @readonly
|
90
|
-
*/
|
91
|
-
private _aspectRatio?;
|
92
|
-
/**
|
93
|
-
* @param options Resizer options.
|
94
|
-
*/
|
95
|
-
constructor(options: ResizerOptions);
|
96
|
-
/**
|
97
|
-
* The original width (pixels) of the resized object when the resize process was started.
|
98
|
-
*/
|
99
|
-
get originalWidth(): number | undefined;
|
100
|
-
/**
|
101
|
-
* The original height (pixels) of the resized object when the resize process was started.
|
102
|
-
*/
|
103
|
-
get originalHeight(): number | undefined;
|
104
|
-
/**
|
105
|
-
* The original width (percents) of the resized object when the resize process was started.
|
106
|
-
*/
|
107
|
-
get originalWidthPercents(): number | undefined;
|
108
|
-
/**
|
109
|
-
* A width to height ratio of the resized image.
|
110
|
-
*/
|
111
|
-
get aspectRatio(): number | undefined;
|
112
|
-
/**
|
113
|
-
*
|
114
|
-
* @param domResizeHandle The handle used to calculate the reference point.
|
115
|
-
*/
|
116
|
-
begin(domResizeHandle: HTMLElement, domHandleHost: HTMLElement, domResizeHost: HTMLElement): void;
|
117
|
-
update(newSize: {
|
118
|
-
width: number;
|
119
|
-
height: number;
|
120
|
-
widthPercents: number;
|
121
|
-
handleHostWidth: number;
|
122
|
-
handleHostHeight: number;
|
123
|
-
}): void;
|
124
|
-
}
|
125
|
-
export {};
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
import type { ResizerOptions } from '../widgetresize';
|
6
|
+
declare const ResizeState_base: {
|
7
|
+
new (): import("@ckeditor/ckeditor5-utils").Observable;
|
8
|
+
prototype: import("@ckeditor/ckeditor5-utils").Observable;
|
9
|
+
};
|
10
|
+
/**
|
11
|
+
* Stores the internal state of a single resizable object.
|
12
|
+
*/
|
13
|
+
export default class ResizeState extends ResizeState_base {
|
14
|
+
/**
|
15
|
+
* The position of the handle that initiated the resizing. E.g. `"top-left"`, `"bottom-right"` etc. or `null`
|
16
|
+
* if unknown.
|
17
|
+
*
|
18
|
+
* @readonly
|
19
|
+
* @observable
|
20
|
+
*/
|
21
|
+
activeHandlePosition: string | null;
|
22
|
+
/**
|
23
|
+
* The width (percents) proposed, but not committed yet, in the current resize process.
|
24
|
+
*
|
25
|
+
* @readonly
|
26
|
+
* @observable
|
27
|
+
*/
|
28
|
+
proposedWidthPercents: number | null;
|
29
|
+
/**
|
30
|
+
* The width (pixels) proposed, but not committed yet, in the current resize process.
|
31
|
+
*
|
32
|
+
* @readonly
|
33
|
+
* @observable
|
34
|
+
*/
|
35
|
+
proposedWidth: number | null;
|
36
|
+
/**
|
37
|
+
* The height (pixels) proposed, but not committed yet, in the current resize process.
|
38
|
+
*
|
39
|
+
* @readonly
|
40
|
+
* @observable
|
41
|
+
*/
|
42
|
+
proposedHeight: number | null;
|
43
|
+
/**
|
44
|
+
* @readonly
|
45
|
+
* @observable
|
46
|
+
*/
|
47
|
+
proposedHandleHostWidth: number | null;
|
48
|
+
/**
|
49
|
+
* @readonly
|
50
|
+
* @observable
|
51
|
+
*/
|
52
|
+
proposedHandleHostHeight: number | null;
|
53
|
+
/**
|
54
|
+
* The reference point of the resizer where the dragging started. It is used to measure the distance the user cursor
|
55
|
+
* traveled, so how much the image should be enlarged.
|
56
|
+
* This information is only known after the DOM was rendered, so it will be updated later.
|
57
|
+
*
|
58
|
+
* @internal
|
59
|
+
*/
|
60
|
+
_referenceCoordinates: {
|
61
|
+
x: number;
|
62
|
+
y: number;
|
63
|
+
} | null;
|
64
|
+
/**
|
65
|
+
* Resizer options.
|
66
|
+
*/
|
67
|
+
private readonly _options;
|
68
|
+
/**
|
69
|
+
* The original width (pixels) of the resized object when the resize process was started.
|
70
|
+
*
|
71
|
+
* @readonly
|
72
|
+
*/
|
73
|
+
private _originalWidth?;
|
74
|
+
/**
|
75
|
+
* The original height (pixels) of the resized object when the resize process was started.
|
76
|
+
*
|
77
|
+
* @readonly
|
78
|
+
*/
|
79
|
+
private _originalHeight?;
|
80
|
+
/**
|
81
|
+
* The original width (percents) of the resized object when the resize process was started.
|
82
|
+
*
|
83
|
+
* @readonly
|
84
|
+
*/
|
85
|
+
private _originalWidthPercents?;
|
86
|
+
/**
|
87
|
+
* A width to height ratio of the resized image.
|
88
|
+
*
|
89
|
+
* @readonly
|
90
|
+
*/
|
91
|
+
private _aspectRatio?;
|
92
|
+
/**
|
93
|
+
* @param options Resizer options.
|
94
|
+
*/
|
95
|
+
constructor(options: ResizerOptions);
|
96
|
+
/**
|
97
|
+
* The original width (pixels) of the resized object when the resize process was started.
|
98
|
+
*/
|
99
|
+
get originalWidth(): number | undefined;
|
100
|
+
/**
|
101
|
+
* The original height (pixels) of the resized object when the resize process was started.
|
102
|
+
*/
|
103
|
+
get originalHeight(): number | undefined;
|
104
|
+
/**
|
105
|
+
* The original width (percents) of the resized object when the resize process was started.
|
106
|
+
*/
|
107
|
+
get originalWidthPercents(): number | undefined;
|
108
|
+
/**
|
109
|
+
* A width to height ratio of the resized image.
|
110
|
+
*/
|
111
|
+
get aspectRatio(): number | undefined;
|
112
|
+
/**
|
113
|
+
*
|
114
|
+
* @param domResizeHandle The handle used to calculate the reference point.
|
115
|
+
*/
|
116
|
+
begin(domResizeHandle: HTMLElement, domHandleHost: HTMLElement, domResizeHost: HTMLElement): void;
|
117
|
+
update(newSize: {
|
118
|
+
width: number;
|
119
|
+
height: number;
|
120
|
+
widthPercents: number;
|
121
|
+
handleHostWidth: number;
|
122
|
+
handleHostHeight: number;
|
123
|
+
}): void;
|
124
|
+
}
|
125
|
+
export {};
|
@@ -1,150 +1,150 @@
|
|
1
|
-
/**
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
-
*/
|
5
|
-
/**
|
6
|
-
* @module widget/widgetresize/resizerstate
|
7
|
-
*/
|
8
|
-
import { ObservableMixin, Rect } from '@ckeditor/ckeditor5-utils';
|
9
|
-
/**
|
10
|
-
* Stores the internal state of a single resizable object.
|
11
|
-
*/
|
12
|
-
export default class ResizeState extends ObservableMixin() {
|
13
|
-
/**
|
14
|
-
* @param options Resizer options.
|
15
|
-
*/
|
16
|
-
constructor(options) {
|
17
|
-
super();
|
18
|
-
this.set('activeHandlePosition', null);
|
19
|
-
this.set('proposedWidthPercents', null);
|
20
|
-
this.set('proposedWidth', null);
|
21
|
-
this.set('proposedHeight', null);
|
22
|
-
this.set('proposedHandleHostWidth', null);
|
23
|
-
this.set('proposedHandleHostHeight', null);
|
24
|
-
this._options = options;
|
25
|
-
this._referenceCoordinates = null;
|
26
|
-
}
|
27
|
-
/**
|
28
|
-
* The original width (pixels) of the resized object when the resize process was started.
|
29
|
-
*/
|
30
|
-
get originalWidth() {
|
31
|
-
return this._originalWidth;
|
32
|
-
}
|
33
|
-
/**
|
34
|
-
* The original height (pixels) of the resized object when the resize process was started.
|
35
|
-
*/
|
36
|
-
get originalHeight() {
|
37
|
-
return this._originalHeight;
|
38
|
-
}
|
39
|
-
/**
|
40
|
-
* The original width (percents) of the resized object when the resize process was started.
|
41
|
-
*/
|
42
|
-
get originalWidthPercents() {
|
43
|
-
return this._originalWidthPercents;
|
44
|
-
}
|
45
|
-
/**
|
46
|
-
* A width to height ratio of the resized image.
|
47
|
-
*/
|
48
|
-
get aspectRatio() {
|
49
|
-
return this._aspectRatio;
|
50
|
-
}
|
51
|
-
/**
|
52
|
-
*
|
53
|
-
* @param domResizeHandle The handle used to calculate the reference point.
|
54
|
-
*/
|
55
|
-
begin(domResizeHandle, domHandleHost, domResizeHost) {
|
56
|
-
const clientRect = new Rect(domHandleHost);
|
57
|
-
this.activeHandlePosition = getHandlePosition(domResizeHandle);
|
58
|
-
this._referenceCoordinates = getAbsoluteBoundaryPoint(domHandleHost, getOppositePosition(this.activeHandlePosition));
|
59
|
-
this._originalWidth = clientRect.width;
|
60
|
-
this._originalHeight = clientRect.height;
|
61
|
-
this._aspectRatio = clientRect.width / clientRect.height;
|
62
|
-
const widthStyle = domResizeHost.style.width;
|
63
|
-
if (widthStyle && widthStyle.match(/^\d+(\.\d*)?%$/)) {
|
64
|
-
this._originalWidthPercents = parseFloat(widthStyle);
|
65
|
-
}
|
66
|
-
else {
|
67
|
-
this._originalWidthPercents = calculateHostPercentageWidth(domResizeHost, clientRect);
|
68
|
-
}
|
69
|
-
}
|
70
|
-
update(newSize) {
|
71
|
-
this.proposedWidth = newSize.width;
|
72
|
-
this.proposedHeight = newSize.height;
|
73
|
-
this.proposedWidthPercents = newSize.widthPercents;
|
74
|
-
this.proposedHandleHostWidth = newSize.handleHostWidth;
|
75
|
-
this.proposedHandleHostHeight = newSize.handleHostHeight;
|
76
|
-
}
|
77
|
-
}
|
78
|
-
/**
|
79
|
-
* Calculates a relative width of a `domResizeHost` compared to its ancestor in percents.
|
80
|
-
*/
|
81
|
-
function calculateHostPercentageWidth(domResizeHost, resizeHostRect) {
|
82
|
-
const domResizeHostParent = domResizeHost.parentElement;
|
83
|
-
// Need to use computed style as it properly excludes parent's paddings from the returned value.
|
84
|
-
let parentWidth = parseFloat(domResizeHostParent.ownerDocument.defaultView.getComputedStyle(domResizeHostParent).width);
|
85
|
-
// Sometimes parent width cannot be accessed. If that happens we should go up in the elements tree
|
86
|
-
// and try to get width from next ancestor.
|
87
|
-
// https://github.com/ckeditor/ckeditor5/issues/10776
|
88
|
-
const ancestorLevelLimit = 5;
|
89
|
-
let currentLevel = 0;
|
90
|
-
let checkedElement = domResizeHostParent;
|
91
|
-
while (isNaN(parentWidth)) {
|
92
|
-
checkedElement = checkedElement.parentElement;
|
93
|
-
if (++currentLevel > ancestorLevelLimit) {
|
94
|
-
return 0;
|
95
|
-
}
|
96
|
-
parentWidth = parseFloat(domResizeHostParent.ownerDocument.defaultView.getComputedStyle(checkedElement).width);
|
97
|
-
}
|
98
|
-
return resizeHostRect.width / parentWidth * 100;
|
99
|
-
}
|
100
|
-
/**
|
101
|
-
* Returns coordinates of the top-left corner of an element, relative to the document's top-left corner.
|
102
|
-
*
|
103
|
-
* @param resizerPosition The position of the resize handle, e.g. `"top-left"`, `"bottom-right"`.
|
104
|
-
*/
|
105
|
-
function getAbsoluteBoundaryPoint(element, resizerPosition) {
|
106
|
-
const elementRect = new Rect(element);
|
107
|
-
const positionParts = resizerPosition.split('-');
|
108
|
-
const ret = {
|
109
|
-
x: positionParts[1] == 'right' ? elementRect.right : elementRect.left,
|
110
|
-
y: positionParts[0] == 'bottom' ? elementRect.bottom : elementRect.top
|
111
|
-
};
|
112
|
-
ret.x += element.ownerDocument.defaultView.scrollX;
|
113
|
-
ret.y += element.ownerDocument.defaultView.scrollY;
|
114
|
-
return ret;
|
115
|
-
}
|
116
|
-
/**
|
117
|
-
* @param resizerPosition The expected resizer position, like `"top-left"`, `"bottom-right"`.
|
118
|
-
* @returns A prefixed HTML class name for the resizer element.
|
119
|
-
*/
|
120
|
-
function getResizerHandleClass(resizerPosition) {
|
121
|
-
return `ck-widget__resizer__handle-${resizerPosition}`;
|
122
|
-
}
|
123
|
-
/**
|
124
|
-
* Determines the position of a given resize handle.
|
125
|
-
*
|
126
|
-
* @param domHandle Handle used to calculate the reference point.
|
127
|
-
* @returns Returns a string like `"top-left"` or `undefined` if not matched.
|
128
|
-
*/
|
129
|
-
function getHandlePosition(domHandle) {
|
130
|
-
const resizerPositions = ['top-left', 'top-right', 'bottom-right', 'bottom-left'];
|
131
|
-
for (const position of resizerPositions) {
|
132
|
-
if (domHandle.classList.contains(getResizerHandleClass(position))) {
|
133
|
-
return position;
|
134
|
-
}
|
135
|
-
}
|
136
|
-
}
|
137
|
-
/**
|
138
|
-
* @param position Like `"top-left"`.
|
139
|
-
* @returns Inverted `position`, e.g. it returns `"bottom-right"` if `"top-left"` was given as `position`.
|
140
|
-
*/
|
141
|
-
function getOppositePosition(position) {
|
142
|
-
const parts = position.split('-');
|
143
|
-
const replacements = {
|
144
|
-
top: 'bottom',
|
145
|
-
bottom: 'top',
|
146
|
-
left: 'right',
|
147
|
-
right: 'left'
|
148
|
-
};
|
149
|
-
return `${replacements[parts[0]]}-${replacements[parts[1]]}`;
|
150
|
-
}
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
/**
|
6
|
+
* @module widget/widgetresize/resizerstate
|
7
|
+
*/
|
8
|
+
import { ObservableMixin, Rect } from '@ckeditor/ckeditor5-utils';
|
9
|
+
/**
|
10
|
+
* Stores the internal state of a single resizable object.
|
11
|
+
*/
|
12
|
+
export default class ResizeState extends ObservableMixin() {
|
13
|
+
/**
|
14
|
+
* @param options Resizer options.
|
15
|
+
*/
|
16
|
+
constructor(options) {
|
17
|
+
super();
|
18
|
+
this.set('activeHandlePosition', null);
|
19
|
+
this.set('proposedWidthPercents', null);
|
20
|
+
this.set('proposedWidth', null);
|
21
|
+
this.set('proposedHeight', null);
|
22
|
+
this.set('proposedHandleHostWidth', null);
|
23
|
+
this.set('proposedHandleHostHeight', null);
|
24
|
+
this._options = options;
|
25
|
+
this._referenceCoordinates = null;
|
26
|
+
}
|
27
|
+
/**
|
28
|
+
* The original width (pixels) of the resized object when the resize process was started.
|
29
|
+
*/
|
30
|
+
get originalWidth() {
|
31
|
+
return this._originalWidth;
|
32
|
+
}
|
33
|
+
/**
|
34
|
+
* The original height (pixels) of the resized object when the resize process was started.
|
35
|
+
*/
|
36
|
+
get originalHeight() {
|
37
|
+
return this._originalHeight;
|
38
|
+
}
|
39
|
+
/**
|
40
|
+
* The original width (percents) of the resized object when the resize process was started.
|
41
|
+
*/
|
42
|
+
get originalWidthPercents() {
|
43
|
+
return this._originalWidthPercents;
|
44
|
+
}
|
45
|
+
/**
|
46
|
+
* A width to height ratio of the resized image.
|
47
|
+
*/
|
48
|
+
get aspectRatio() {
|
49
|
+
return this._aspectRatio;
|
50
|
+
}
|
51
|
+
/**
|
52
|
+
*
|
53
|
+
* @param domResizeHandle The handle used to calculate the reference point.
|
54
|
+
*/
|
55
|
+
begin(domResizeHandle, domHandleHost, domResizeHost) {
|
56
|
+
const clientRect = new Rect(domHandleHost);
|
57
|
+
this.activeHandlePosition = getHandlePosition(domResizeHandle);
|
58
|
+
this._referenceCoordinates = getAbsoluteBoundaryPoint(domHandleHost, getOppositePosition(this.activeHandlePosition));
|
59
|
+
this._originalWidth = clientRect.width;
|
60
|
+
this._originalHeight = clientRect.height;
|
61
|
+
this._aspectRatio = clientRect.width / clientRect.height;
|
62
|
+
const widthStyle = domResizeHost.style.width;
|
63
|
+
if (widthStyle && widthStyle.match(/^\d+(\.\d*)?%$/)) {
|
64
|
+
this._originalWidthPercents = parseFloat(widthStyle);
|
65
|
+
}
|
66
|
+
else {
|
67
|
+
this._originalWidthPercents = calculateHostPercentageWidth(domResizeHost, clientRect);
|
68
|
+
}
|
69
|
+
}
|
70
|
+
update(newSize) {
|
71
|
+
this.proposedWidth = newSize.width;
|
72
|
+
this.proposedHeight = newSize.height;
|
73
|
+
this.proposedWidthPercents = newSize.widthPercents;
|
74
|
+
this.proposedHandleHostWidth = newSize.handleHostWidth;
|
75
|
+
this.proposedHandleHostHeight = newSize.handleHostHeight;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
/**
|
79
|
+
* Calculates a relative width of a `domResizeHost` compared to its ancestor in percents.
|
80
|
+
*/
|
81
|
+
function calculateHostPercentageWidth(domResizeHost, resizeHostRect) {
|
82
|
+
const domResizeHostParent = domResizeHost.parentElement;
|
83
|
+
// Need to use computed style as it properly excludes parent's paddings from the returned value.
|
84
|
+
let parentWidth = parseFloat(domResizeHostParent.ownerDocument.defaultView.getComputedStyle(domResizeHostParent).width);
|
85
|
+
// Sometimes parent width cannot be accessed. If that happens we should go up in the elements tree
|
86
|
+
// and try to get width from next ancestor.
|
87
|
+
// https://github.com/ckeditor/ckeditor5/issues/10776
|
88
|
+
const ancestorLevelLimit = 5;
|
89
|
+
let currentLevel = 0;
|
90
|
+
let checkedElement = domResizeHostParent;
|
91
|
+
while (isNaN(parentWidth)) {
|
92
|
+
checkedElement = checkedElement.parentElement;
|
93
|
+
if (++currentLevel > ancestorLevelLimit) {
|
94
|
+
return 0;
|
95
|
+
}
|
96
|
+
parentWidth = parseFloat(domResizeHostParent.ownerDocument.defaultView.getComputedStyle(checkedElement).width);
|
97
|
+
}
|
98
|
+
return resizeHostRect.width / parentWidth * 100;
|
99
|
+
}
|
100
|
+
/**
|
101
|
+
* Returns coordinates of the top-left corner of an element, relative to the document's top-left corner.
|
102
|
+
*
|
103
|
+
* @param resizerPosition The position of the resize handle, e.g. `"top-left"`, `"bottom-right"`.
|
104
|
+
*/
|
105
|
+
function getAbsoluteBoundaryPoint(element, resizerPosition) {
|
106
|
+
const elementRect = new Rect(element);
|
107
|
+
const positionParts = resizerPosition.split('-');
|
108
|
+
const ret = {
|
109
|
+
x: positionParts[1] == 'right' ? elementRect.right : elementRect.left,
|
110
|
+
y: positionParts[0] == 'bottom' ? elementRect.bottom : elementRect.top
|
111
|
+
};
|
112
|
+
ret.x += element.ownerDocument.defaultView.scrollX;
|
113
|
+
ret.y += element.ownerDocument.defaultView.scrollY;
|
114
|
+
return ret;
|
115
|
+
}
|
116
|
+
/**
|
117
|
+
* @param resizerPosition The expected resizer position, like `"top-left"`, `"bottom-right"`.
|
118
|
+
* @returns A prefixed HTML class name for the resizer element.
|
119
|
+
*/
|
120
|
+
function getResizerHandleClass(resizerPosition) {
|
121
|
+
return `ck-widget__resizer__handle-${resizerPosition}`;
|
122
|
+
}
|
123
|
+
/**
|
124
|
+
* Determines the position of a given resize handle.
|
125
|
+
*
|
126
|
+
* @param domHandle Handle used to calculate the reference point.
|
127
|
+
* @returns Returns a string like `"top-left"` or `undefined` if not matched.
|
128
|
+
*/
|
129
|
+
function getHandlePosition(domHandle) {
|
130
|
+
const resizerPositions = ['top-left', 'top-right', 'bottom-right', 'bottom-left'];
|
131
|
+
for (const position of resizerPositions) {
|
132
|
+
if (domHandle.classList.contains(getResizerHandleClass(position))) {
|
133
|
+
return position;
|
134
|
+
}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
/**
|
138
|
+
* @param position Like `"top-left"`.
|
139
|
+
* @returns Inverted `position`, e.g. it returns `"bottom-right"` if `"top-left"` was given as `position`.
|
140
|
+
*/
|
141
|
+
function getOppositePosition(position) {
|
142
|
+
const parts = position.split('-');
|
143
|
+
const replacements = {
|
144
|
+
top: 'bottom',
|
145
|
+
bottom: 'top',
|
146
|
+
left: 'right',
|
147
|
+
right: 'left'
|
148
|
+
};
|
149
|
+
return `${replacements[parts[0]]}-${replacements[parts[1]]}`;
|
150
|
+
}
|
@@ -1,55 +1,55 @@
|
|
1
|
-
/**
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
-
*/
|
5
|
-
/**
|
6
|
-
* @module widget/widgetresize/sizeview
|
7
|
-
*/
|
8
|
-
import { View } from '@ckeditor/ckeditor5-ui';
|
9
|
-
import type { ResizerOptions } from '../widgetresize';
|
10
|
-
import type ResizeState from './resizerstate';
|
11
|
-
/**
|
12
|
-
* A view displaying the proposed new element size during the resizing.
|
13
|
-
*/
|
14
|
-
export default class SizeView extends View {
|
15
|
-
/**
|
16
|
-
* The visibility of the view defined based on the existence of the host proposed dimensions.
|
17
|
-
*
|
18
|
-
* @internal
|
19
|
-
* @observable
|
20
|
-
* @readonly
|
21
|
-
*/
|
22
|
-
_isVisible: boolean;
|
23
|
-
/**
|
24
|
-
* The text that will be displayed in the `SizeView` child.
|
25
|
-
* It can be formatted as the pixel values (e.g. 10x20) or the percentage value (e.g. 10%).
|
26
|
-
*
|
27
|
-
* @internal
|
28
|
-
* @observable
|
29
|
-
* @readonly
|
30
|
-
*/
|
31
|
-
_label: string;
|
32
|
-
/**
|
33
|
-
* The position of the view defined based on the host size and active handle position.
|
34
|
-
*
|
35
|
-
* @internal
|
36
|
-
* @observable
|
37
|
-
* @readonly
|
38
|
-
*/
|
39
|
-
_viewPosition: string;
|
40
|
-
constructor();
|
41
|
-
/**
|
42
|
-
* A method used for binding the `SizeView` instance properties to the `ResizeState` instance observable properties.
|
43
|
-
*
|
44
|
-
* @internal
|
45
|
-
* @param options An object defining the resizer options, used for setting the proper size label.
|
46
|
-
* @param resizeState The `ResizeState` class instance, used for keeping the `SizeView` state up to date.
|
47
|
-
*/
|
48
|
-
_bindToState(options: ResizerOptions, resizeState: ResizeState): void;
|
49
|
-
/**
|
50
|
-
* A method used for cleaning up. It removes the bindings and hides the view.
|
51
|
-
*
|
52
|
-
* @internal
|
53
|
-
*/
|
54
|
-
_dismiss(): void;
|
55
|
-
}
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
/**
|
6
|
+
* @module widget/widgetresize/sizeview
|
7
|
+
*/
|
8
|
+
import { View } from '@ckeditor/ckeditor5-ui';
|
9
|
+
import type { ResizerOptions } from '../widgetresize';
|
10
|
+
import type ResizeState from './resizerstate';
|
11
|
+
/**
|
12
|
+
* A view displaying the proposed new element size during the resizing.
|
13
|
+
*/
|
14
|
+
export default class SizeView extends View {
|
15
|
+
/**
|
16
|
+
* The visibility of the view defined based on the existence of the host proposed dimensions.
|
17
|
+
*
|
18
|
+
* @internal
|
19
|
+
* @observable
|
20
|
+
* @readonly
|
21
|
+
*/
|
22
|
+
_isVisible: boolean;
|
23
|
+
/**
|
24
|
+
* The text that will be displayed in the `SizeView` child.
|
25
|
+
* It can be formatted as the pixel values (e.g. 10x20) or the percentage value (e.g. 10%).
|
26
|
+
*
|
27
|
+
* @internal
|
28
|
+
* @observable
|
29
|
+
* @readonly
|
30
|
+
*/
|
31
|
+
_label: string;
|
32
|
+
/**
|
33
|
+
* The position of the view defined based on the host size and active handle position.
|
34
|
+
*
|
35
|
+
* @internal
|
36
|
+
* @observable
|
37
|
+
* @readonly
|
38
|
+
*/
|
39
|
+
_viewPosition: string;
|
40
|
+
constructor();
|
41
|
+
/**
|
42
|
+
* A method used for binding the `SizeView` instance properties to the `ResizeState` instance observable properties.
|
43
|
+
*
|
44
|
+
* @internal
|
45
|
+
* @param options An object defining the resizer options, used for setting the proper size label.
|
46
|
+
* @param resizeState The `ResizeState` class instance, used for keeping the `SizeView` state up to date.
|
47
|
+
*/
|
48
|
+
_bindToState(options: ResizerOptions, resizeState: ResizeState): void;
|
49
|
+
/**
|
50
|
+
* A method used for cleaning up. It removes the bindings and hides the view.
|
51
|
+
*
|
52
|
+
* @internal
|
53
|
+
*/
|
54
|
+
_dismiss(): void;
|
55
|
+
}
|