@ckeditor/ckeditor5-widget 47.6.1 → 48.0.0-alpha.0

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.
Files changed (110) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/index-editor.css +484 -122
  3. package/dist/index.css +479 -187
  4. package/dist/index.css.map +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/index.js.map +1 -1
  7. package/package.json +26 -46
  8. package/lang/contexts.json +0 -12
  9. package/lang/translations/af.po +0 -52
  10. package/lang/translations/ar.po +0 -52
  11. package/lang/translations/ast.po +0 -52
  12. package/lang/translations/az.po +0 -52
  13. package/lang/translations/be.po +0 -52
  14. package/lang/translations/bg.po +0 -52
  15. package/lang/translations/bn.po +0 -52
  16. package/lang/translations/bs.po +0 -52
  17. package/lang/translations/ca.po +0 -52
  18. package/lang/translations/cs.po +0 -52
  19. package/lang/translations/da.po +0 -52
  20. package/lang/translations/de-ch.po +0 -52
  21. package/lang/translations/de.po +0 -52
  22. package/lang/translations/el.po +0 -52
  23. package/lang/translations/en-au.po +0 -52
  24. package/lang/translations/en-gb.po +0 -52
  25. package/lang/translations/en.po +0 -52
  26. package/lang/translations/eo.po +0 -52
  27. package/lang/translations/es-co.po +0 -52
  28. package/lang/translations/es.po +0 -52
  29. package/lang/translations/et.po +0 -52
  30. package/lang/translations/eu.po +0 -52
  31. package/lang/translations/fa.po +0 -52
  32. package/lang/translations/fi.po +0 -52
  33. package/lang/translations/fr.po +0 -52
  34. package/lang/translations/gl.po +0 -52
  35. package/lang/translations/gu.po +0 -52
  36. package/lang/translations/he.po +0 -52
  37. package/lang/translations/hi.po +0 -52
  38. package/lang/translations/hr.po +0 -52
  39. package/lang/translations/hu.po +0 -52
  40. package/lang/translations/hy.po +0 -52
  41. package/lang/translations/id.po +0 -52
  42. package/lang/translations/it.po +0 -52
  43. package/lang/translations/ja.po +0 -52
  44. package/lang/translations/jv.po +0 -52
  45. package/lang/translations/kk.po +0 -52
  46. package/lang/translations/km.po +0 -52
  47. package/lang/translations/kn.po +0 -52
  48. package/lang/translations/ko.po +0 -52
  49. package/lang/translations/ku.po +0 -52
  50. package/lang/translations/lt.po +0 -52
  51. package/lang/translations/lv.po +0 -52
  52. package/lang/translations/ms.po +0 -52
  53. package/lang/translations/nb.po +0 -52
  54. package/lang/translations/ne.po +0 -52
  55. package/lang/translations/nl.po +0 -52
  56. package/lang/translations/no.po +0 -52
  57. package/lang/translations/oc.po +0 -52
  58. package/lang/translations/pl.po +0 -52
  59. package/lang/translations/pt-br.po +0 -52
  60. package/lang/translations/pt.po +0 -52
  61. package/lang/translations/ro.po +0 -52
  62. package/lang/translations/ru.po +0 -52
  63. package/lang/translations/si.po +0 -52
  64. package/lang/translations/sk.po +0 -52
  65. package/lang/translations/sl.po +0 -52
  66. package/lang/translations/sq.po +0 -52
  67. package/lang/translations/sr-latn.po +0 -52
  68. package/lang/translations/sr.po +0 -52
  69. package/lang/translations/sv.po +0 -52
  70. package/lang/translations/th.po +0 -52
  71. package/lang/translations/ti.po +0 -52
  72. package/lang/translations/tk.po +0 -52
  73. package/lang/translations/tr.po +0 -52
  74. package/lang/translations/tt.po +0 -52
  75. package/lang/translations/ug.po +0 -52
  76. package/lang/translations/uk.po +0 -52
  77. package/lang/translations/ur.po +0 -52
  78. package/lang/translations/uz.po +0 -52
  79. package/lang/translations/vi.po +0 -52
  80. package/lang/translations/zh-cn.po +0 -52
  81. package/lang/translations/zh.po +0 -52
  82. package/src/augmentation.js +0 -5
  83. package/src/highlightstack.js +0 -126
  84. package/src/index.js +0 -19
  85. package/src/utils.js +0 -414
  86. package/src/verticalnavigation.js +0 -185
  87. package/src/widget.js +0 -727
  88. package/src/widgetresize/resizer.js +0 -390
  89. package/src/widgetresize/resizerstate.js +0 -165
  90. package/src/widgetresize/sizeview.js +0 -65
  91. package/src/widgetresize.js +0 -193
  92. package/src/widgettoolbarrepository.js +0 -274
  93. package/src/widgettypearound/utils.js +0 -60
  94. package/src/widgettypearound/widgettypearound.js +0 -778
  95. package/theme/widget.css +0 -91
  96. package/theme/widgetresize.css +0 -43
  97. package/theme/widgettypearound.css +0 -119
  98. /package/{src → dist}/augmentation.d.ts +0 -0
  99. /package/{src → dist}/highlightstack.d.ts +0 -0
  100. /package/{src → dist}/index.d.ts +0 -0
  101. /package/{src → dist}/utils.d.ts +0 -0
  102. /package/{src → dist}/verticalnavigation.d.ts +0 -0
  103. /package/{src → dist}/widget.d.ts +0 -0
  104. /package/{src → dist}/widgetresize/resizer.d.ts +0 -0
  105. /package/{src → dist}/widgetresize/resizerstate.d.ts +0 -0
  106. /package/{src → dist}/widgetresize/sizeview.d.ts +0 -0
  107. /package/{src → dist}/widgetresize.d.ts +0 -0
  108. /package/{src → dist}/widgettoolbarrepository.d.ts +0 -0
  109. /package/{src → dist}/widgettypearound/utils.d.ts +0 -0
  110. /package/{src → dist}/widgettypearound/widgettypearound.d.ts +0 -0
@@ -1,390 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module widget/widgetresize/resizer
7
- */
8
- import { Template } from '@ckeditor/ckeditor5-ui';
9
- import { Rect, ObservableMixin, compareArrays } from '@ckeditor/ckeditor5-utils';
10
- import { WidgetResizeState } from './resizerstate.js';
11
- import { SizeView } from './sizeview.js';
12
- /**
13
- * Represents a resizer for a single resizable object.
14
- */
15
- export class WidgetResizer extends /* #__PURE__ */ ObservableMixin() {
16
- /**
17
- * Stores the state of the resizable host geometry, such as the original width, the currently proposed height, etc.
18
- *
19
- * Note that a new state is created for each resize transaction.
20
- */
21
- _state;
22
- /**
23
- * A view displaying the proposed new element size during the resizing.
24
- */
25
- _sizeView;
26
- /**
27
- * Options passed to the {@link #constructor}.
28
- */
29
- _options;
30
- /**
31
- * A wrapper that is controlled by the resizer. This is usually a widget element.
32
- */
33
- _viewResizerWrapper = null;
34
- /**
35
- * The width of the resized {@link module:widget/widgetresize~WidgetResizerOptions#viewElement viewElement} before the resizing started.
36
- */
37
- _initialViewWidth;
38
- /**
39
- * @param options Resizer options.
40
- */
41
- constructor(options) {
42
- super();
43
- this._options = options;
44
- this.set('isEnabled', true);
45
- this.set('isSelected', false);
46
- this.bind('isVisible').to(this, 'isEnabled', this, 'isSelected', (isEnabled, isSelected) => isEnabled && isSelected);
47
- this.decorate('begin');
48
- this.decorate('cancel');
49
- this.decorate('commit');
50
- this.decorate('updateSize');
51
- this.on('commit', event => {
52
- // State might not be initialized yet. In this case, prevent further handling and make sure that the resizer is
53
- // cleaned up (#5195).
54
- if (!this.state.proposedWidth && !this.state.proposedWidthPercents) {
55
- this._cleanup();
56
- event.stop();
57
- }
58
- }, { priority: 'high' });
59
- }
60
- /**
61
- * Stores the state of the resizable host geometry, such as the original width, the currently proposed height, etc.
62
- *
63
- * Note that a new state is created for each resize transaction.
64
- */
65
- get state() {
66
- return this._state;
67
- }
68
- /**
69
- * Makes resizer visible in the UI.
70
- */
71
- show() {
72
- const editingView = this._options.editor.editing.view;
73
- editingView.change(writer => {
74
- writer.removeClass('ck-hidden', this._viewResizerWrapper);
75
- });
76
- }
77
- /**
78
- * Hides resizer in the UI.
79
- */
80
- hide() {
81
- const editingView = this._options.editor.editing.view;
82
- editingView.change(writer => {
83
- writer.addClass('ck-hidden', this._viewResizerWrapper);
84
- });
85
- }
86
- /**
87
- * Attaches the resizer to the DOM.
88
- */
89
- attach() {
90
- // eslint-disable-next-line @typescript-eslint/no-this-alias
91
- const that = this;
92
- const widgetElement = this._options.viewElement;
93
- const editingView = this._options.editor.editing.view;
94
- editingView.change(writer => {
95
- const viewResizerWrapper = writer.createUIElement('div', {
96
- class: 'ck ck-reset_all ck-widget__resizer'
97
- }, function (domDocument) {
98
- const domElement = this.toDomElement(domDocument);
99
- that._appendHandles(domElement);
100
- that._appendSizeUI(domElement);
101
- return domElement;
102
- });
103
- // Append the resizer wrapper to the widget's wrapper.
104
- writer.insert(writer.createPositionAt(widgetElement, 'end'), viewResizerWrapper);
105
- writer.addClass('ck-widget_with-resizer', widgetElement);
106
- this._viewResizerWrapper = viewResizerWrapper;
107
- if (!this.isVisible) {
108
- this.hide();
109
- }
110
- });
111
- this.on('change:isVisible', () => {
112
- if (this.isVisible) {
113
- this.show();
114
- this.redraw();
115
- }
116
- else {
117
- this.hide();
118
- }
119
- });
120
- }
121
- /**
122
- * Starts the resizing process.
123
- *
124
- * Creates a new {@link #state} for the current process.
125
- *
126
- * @fires begin
127
- * @param domResizeHandle Clicked handle.
128
- */
129
- begin(domResizeHandle) {
130
- this._state = new WidgetResizeState(this._options);
131
- this._sizeView._bindToState(this._options, this.state);
132
- this._initialViewWidth = this._options.viewElement.getStyle('width');
133
- this.state.begin(domResizeHandle, this._getHandleHost(), this._getResizeHost());
134
- }
135
- /**
136
- * Updates the proposed size based on `domEventData`.
137
- *
138
- * @fires updateSize
139
- */
140
- updateSize(domEventData) {
141
- const newSize = this._proposeNewSize(domEventData);
142
- const editingView = this._options.editor.editing.view;
143
- editingView.change(writer => {
144
- const unit = this._options.unit || '%';
145
- const newWidth = (unit === '%' ? newSize.widthPercents : newSize.width) + unit;
146
- writer.setStyle('width', newWidth, this._options.viewElement);
147
- });
148
- // Get an actual image width, and:
149
- // * reflect this size to the resize wrapper
150
- // * apply this **real** size to the state
151
- const domHandleHost = this._getHandleHost();
152
- const domHandleHostRect = new Rect(domHandleHost);
153
- const handleHostWidth = Math.round(domHandleHostRect.width);
154
- const handleHostHeight = Math.round(domHandleHostRect.height);
155
- // Handle max-width limitation.
156
- const domResizeHostRect = new Rect(domHandleHost);
157
- newSize.width = Math.round(domResizeHostRect.width);
158
- newSize.height = Math.round(domResizeHostRect.height);
159
- this.redraw(domHandleHostRect);
160
- this.state.update({
161
- ...newSize,
162
- handleHostWidth,
163
- handleHostHeight
164
- });
165
- }
166
- /**
167
- * Applies the geometry proposed with the resizer.
168
- *
169
- * @fires commit
170
- */
171
- commit() {
172
- const unit = this._options.unit || '%';
173
- const newValue = (unit === '%' ? this.state.proposedWidthPercents : this.state.proposedWidth) + unit;
174
- // Both cleanup and onCommit callback are very likely to make view changes. Ensure that it is made in a single step.
175
- this._options.editor.editing.view.change(() => {
176
- this._cleanup();
177
- this._options.onCommit(newValue);
178
- });
179
- }
180
- /**
181
- * Cancels and rejects the proposed resize dimensions, hiding the UI.
182
- *
183
- * @fires cancel
184
- */
185
- cancel() {
186
- this._cleanup();
187
- }
188
- /**
189
- * Destroys the resizer.
190
- */
191
- destroy() {
192
- this.cancel();
193
- }
194
- /**
195
- * Redraws the resizer.
196
- *
197
- * @param handleHostRect Handle host rectangle might be given to improve performance.
198
- */
199
- redraw(handleHostRect) {
200
- const domWrapper = this._domResizerWrapper;
201
- // Refresh only if resizer exists in the DOM.
202
- if (!existsInDom(domWrapper)) {
203
- return;
204
- }
205
- const widgetWrapper = domWrapper.parentElement;
206
- const handleHost = this._getHandleHost();
207
- const resizerWrapper = this._viewResizerWrapper;
208
- const currentDimensions = [
209
- resizerWrapper.getStyle('width'),
210
- resizerWrapper.getStyle('height'),
211
- resizerWrapper.getStyle('left'),
212
- resizerWrapper.getStyle('top')
213
- ];
214
- let newDimensions;
215
- if (widgetWrapper.isSameNode(handleHost)) {
216
- const clientRect = handleHostRect || new Rect(handleHost);
217
- newDimensions = [
218
- clientRect.width + 'px',
219
- clientRect.height + 'px',
220
- undefined,
221
- undefined
222
- ];
223
- }
224
- // In case a resizing host is not a widget wrapper, we need to compensate
225
- // for any additional offsets the resize host might have. E.g. wrapper padding
226
- // or simply another editable. By doing that the border and resizers are shown
227
- // only around the resize host.
228
- else {
229
- newDimensions = [
230
- handleHost.offsetWidth + 'px',
231
- handleHost.offsetHeight + 'px',
232
- handleHost.offsetLeft + 'px',
233
- handleHost.offsetTop + 'px'
234
- ];
235
- }
236
- // Make changes to the view only if the resizer should actually get new dimensions.
237
- // Otherwise, if View#change() was always called, this would cause EditorUI#update
238
- // loops because the WidgetResize plugin listens to EditorUI#update and updates
239
- // the resizer.
240
- // https://github.com/ckeditor/ckeditor5/issues/7633
241
- if (compareArrays(currentDimensions, newDimensions) !== 'same') {
242
- this._options.editor.editing.view.change(writer => {
243
- writer.setStyle({
244
- width: newDimensions[0],
245
- height: newDimensions[1],
246
- left: newDimensions[2],
247
- top: newDimensions[3]
248
- }, resizerWrapper);
249
- });
250
- }
251
- }
252
- containsHandle(domElement) {
253
- return this._domResizerWrapper.contains(domElement);
254
- }
255
- static isResizeHandle(domElement) {
256
- return domElement.classList.contains('ck-widget__resizer__handle');
257
- }
258
- /**
259
- * Cleans up the context state.
260
- */
261
- _cleanup() {
262
- this._sizeView._dismiss();
263
- const editingView = this._options.editor.editing.view;
264
- editingView.change(writer => {
265
- writer.setStyle('width', this._initialViewWidth, this._options.viewElement);
266
- });
267
- }
268
- /**
269
- * Calculates the proposed size as the resize handles are dragged.
270
- *
271
- * @param domEventData Event data that caused the size update request. It should be used to calculate the proposed size.
272
- */
273
- _proposeNewSize(domEventData) {
274
- const state = this.state;
275
- const currentCoordinates = extractCoordinates(domEventData);
276
- const isCentered = this._options.isCentered ? this._options.isCentered(this) : true;
277
- // Enlargement defines how much the resize host has changed in a given axis. Naturally it could be a negative number
278
- // meaning that it has been shrunk.
279
- //
280
- // +----------------+--+
281
- // | | |
282
- // | img | |
283
- // | /handle host | |
284
- // +----------------+ | ^
285
- // | | | - enlarge y
286
- // +-------------------+ v
287
- // <-->
288
- // enlarge x
289
- const enlargement = {
290
- x: state._referenceCoordinates.x - (currentCoordinates.x + state.originalWidth),
291
- y: (currentCoordinates.y - state.originalHeight) - state._referenceCoordinates.y
292
- };
293
- if (isCentered && state.activeHandlePosition.endsWith('-right')) {
294
- enlargement.x = currentCoordinates.x - (state._referenceCoordinates.x + state.originalWidth);
295
- }
296
- // Objects needs to be resized twice as much in horizontal axis if centered, since enlargement is counted from
297
- // one resized corner to your cursor. It needs to be duplicated to compensate for the other side too.
298
- if (isCentered) {
299
- enlargement.x *= 2;
300
- }
301
- // const resizeHost = this._getResizeHost();
302
- // The size proposed by the user. It does not consider the aspect ratio.
303
- let width = Math.abs(state.originalWidth + enlargement.x);
304
- let height = Math.abs(state.originalHeight + enlargement.y);
305
- // Dominant determination must take the ratio into account.
306
- const dominant = width / state.aspectRatio > height ? 'width' : 'height';
307
- if (dominant == 'width') {
308
- height = width / state.aspectRatio;
309
- }
310
- else {
311
- width = height * state.aspectRatio;
312
- }
313
- return {
314
- width: Math.round(width),
315
- height: Math.round(height),
316
- widthPercents: Math.min(Math.round(state.originalWidthPercents / state.originalWidth * width * 100) / 100, 100)
317
- };
318
- }
319
- /**
320
- * Obtains the resize host.
321
- *
322
- * Resize host is an object that receives dimensions which are the result of resizing.
323
- */
324
- _getResizeHost() {
325
- const widgetWrapper = this._domResizerWrapper.parentElement;
326
- return this._options.getResizeHost(widgetWrapper);
327
- }
328
- /**
329
- * Obtains the handle host.
330
- *
331
- * Handle host is an object that the handles are aligned to.
332
- *
333
- * Handle host will not always be an entire widget itself. Take an image as an example. The image widget
334
- * contains an image and a caption. Only the image should be surrounded with handles.
335
- */
336
- _getHandleHost() {
337
- const widgetWrapper = this._domResizerWrapper.parentElement;
338
- return this._options.getHandleHost(widgetWrapper);
339
- }
340
- /**
341
- * DOM container of the entire resize UI.
342
- *
343
- * Note that this property will have a value only after the element bound with the resizer is rendered
344
- * (otherwise `null`).
345
- */
346
- get _domResizerWrapper() {
347
- return this._options.editor.editing.view.domConverter.mapViewToDom(this._viewResizerWrapper);
348
- }
349
- /**
350
- * Renders the resize handles in the DOM.
351
- *
352
- * @param domElement The resizer wrapper.
353
- */
354
- _appendHandles(domElement) {
355
- const resizerPositions = ['top-left', 'top-right', 'bottom-right', 'bottom-left'];
356
- for (const currentPosition of resizerPositions) {
357
- domElement.appendChild((new Template({
358
- tag: 'div',
359
- attributes: {
360
- class: `ck-widget__resizer__handle ${getResizerClass(currentPosition)}`
361
- }
362
- }).render()));
363
- }
364
- }
365
- /**
366
- * Sets up the {@link #_sizeView} property and adds it to the passed `domElement`.
367
- */
368
- _appendSizeUI(domElement) {
369
- this._sizeView = new SizeView();
370
- // Make sure icon#element is rendered before passing to appendChild().
371
- this._sizeView.render();
372
- domElement.appendChild(this._sizeView.element);
373
- }
374
- }
375
- /**
376
- * @param resizerPosition Expected resizer position like `"top-left"`, `"bottom-right"`.
377
- * @returns A prefixed HTML class name for the resizer element
378
- */
379
- function getResizerClass(resizerPosition) {
380
- return `ck-widget__resizer__handle-${resizerPosition}`;
381
- }
382
- function extractCoordinates(event) {
383
- return {
384
- x: event.pageX,
385
- y: event.pageY
386
- };
387
- }
388
- function existsInDom(element) {
389
- return element && element.ownerDocument && element.ownerDocument.contains(element);
390
- }
@@ -1,165 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module widget/widgetresize/resizerstate
7
- */
8
- import { ObservableMixin, Rect } from '@ckeditor/ckeditor5-utils';
9
- import { calculateResizeHostPercentageWidth } from '../utils.js';
10
- /**
11
- * Stores the internal state of a single resizable object.
12
- */
13
- export class WidgetResizeState extends /* #__PURE__ */ ObservableMixin() {
14
- /**
15
- * The reference point of the resizer where the dragging started. It is used to measure the distance the user cursor
16
- * traveled, so how much the image should be enlarged.
17
- * This information is only known after the DOM was rendered, so it will be updated later.
18
- *
19
- * @internal
20
- */
21
- _referenceCoordinates;
22
- /**
23
- * Resizer options.
24
- */
25
- _options;
26
- /**
27
- * The original width (pixels) of the resized object when the resize process was started.
28
- *
29
- * @readonly
30
- */
31
- _originalWidth;
32
- /**
33
- * The original height (pixels) of the resized object when the resize process was started.
34
- *
35
- * @readonly
36
- */
37
- _originalHeight;
38
- /**
39
- * The original width (percents) of the resized object when the resize process was started.
40
- *
41
- * @readonly
42
- */
43
- _originalWidthPercents;
44
- /**
45
- * A width to height ratio of the resized image.
46
- *
47
- * @readonly
48
- */
49
- _aspectRatio;
50
- /**
51
- * @param options Resizer options.
52
- */
53
- constructor(options) {
54
- super();
55
- this.set('activeHandlePosition', null);
56
- this.set('proposedWidthPercents', null);
57
- this.set('proposedWidth', null);
58
- this.set('proposedHeight', null);
59
- this.set('proposedHandleHostWidth', null);
60
- this.set('proposedHandleHostHeight', null);
61
- this._options = options;
62
- this._referenceCoordinates = null;
63
- }
64
- /**
65
- * The original width (pixels) of the resized object when the resize process was started.
66
- */
67
- get originalWidth() {
68
- return this._originalWidth;
69
- }
70
- /**
71
- * The original height (pixels) of the resized object when the resize process was started.
72
- */
73
- get originalHeight() {
74
- return this._originalHeight;
75
- }
76
- /**
77
- * The original width (percents) of the resized object when the resize process was started.
78
- */
79
- get originalWidthPercents() {
80
- return this._originalWidthPercents;
81
- }
82
- /**
83
- * A width to height ratio of the resized image.
84
- */
85
- get aspectRatio() {
86
- return this._aspectRatio;
87
- }
88
- /**
89
- *
90
- * @param domResizeHandle The handle used to calculate the reference point.
91
- */
92
- begin(domResizeHandle, domHandleHost, domResizeHost) {
93
- const clientRect = new Rect(domHandleHost);
94
- this.activeHandlePosition = getHandlePosition(domResizeHandle);
95
- this._referenceCoordinates = getAbsoluteBoundaryPoint(domHandleHost, getOppositePosition(this.activeHandlePosition));
96
- this._originalWidth = clientRect.width;
97
- this._originalHeight = clientRect.height;
98
- this._aspectRatio = clientRect.width / clientRect.height;
99
- const widthStyle = domResizeHost.style.width;
100
- if (widthStyle && widthStyle.match(/^\d+(\.\d*)?%$/)) {
101
- this._originalWidthPercents = parseFloat(widthStyle);
102
- }
103
- else {
104
- this._originalWidthPercents = calculateResizeHostPercentageWidth(domResizeHost, clientRect);
105
- }
106
- }
107
- update(newSize) {
108
- this.proposedWidth = newSize.width;
109
- this.proposedHeight = newSize.height;
110
- this.proposedWidthPercents = newSize.widthPercents;
111
- this.proposedHandleHostWidth = newSize.handleHostWidth;
112
- this.proposedHandleHostHeight = newSize.handleHostHeight;
113
- }
114
- }
115
- /**
116
- * Returns coordinates of the top-left corner of an element, relative to the document's top-left corner.
117
- *
118
- * @param resizerPosition The position of the resize handle, e.g. `"top-left"`, `"bottom-right"`.
119
- */
120
- function getAbsoluteBoundaryPoint(element, resizerPosition) {
121
- const elementRect = new Rect(element);
122
- const positionParts = resizerPosition.split('-');
123
- const ret = {
124
- x: positionParts[1] == 'right' ? elementRect.right : elementRect.left,
125
- y: positionParts[0] == 'bottom' ? elementRect.bottom : elementRect.top
126
- };
127
- ret.x += element.ownerDocument.defaultView.scrollX;
128
- ret.y += element.ownerDocument.defaultView.scrollY;
129
- return ret;
130
- }
131
- /**
132
- * @param resizerPosition The expected resizer position, like `"top-left"`, `"bottom-right"`.
133
- * @returns A prefixed HTML class name for the resizer element.
134
- */
135
- function getResizerHandleClass(resizerPosition) {
136
- return `ck-widget__resizer__handle-${resizerPosition}`;
137
- }
138
- /**
139
- * Determines the position of a given resize handle.
140
- *
141
- * @param domHandle Handle used to calculate the reference point.
142
- * @returns Returns a string like `"top-left"` or `undefined` if not matched.
143
- */
144
- function getHandlePosition(domHandle) {
145
- const resizerPositions = ['top-left', 'top-right', 'bottom-right', 'bottom-left'];
146
- for (const position of resizerPositions) {
147
- if (domHandle.classList.contains(getResizerHandleClass(position))) {
148
- return position;
149
- }
150
- }
151
- }
152
- /**
153
- * @param position Like `"top-left"`.
154
- * @returns Inverted `position`, e.g. it returns `"bottom-right"` if `"top-left"` was given as `position`.
155
- */
156
- function getOppositePosition(position) {
157
- const parts = position.split('-');
158
- const replacements = {
159
- top: 'bottom',
160
- bottom: 'top',
161
- left: 'right',
162
- right: 'left'
163
- };
164
- return `${replacements[parts[0]]}-${replacements[parts[1]]}`;
165
- }
@@ -1,65 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module widget/widgetresize/sizeview
7
- */
8
- import { View } from '@ckeditor/ckeditor5-ui';
9
- /**
10
- * A view displaying the proposed new element size during the resizing.
11
- *
12
- * @internal
13
- */
14
- export class SizeView extends View {
15
- constructor() {
16
- super();
17
- const bind = this.bindTemplate;
18
- this.setTemplate({
19
- tag: 'div',
20
- attributes: {
21
- class: [
22
- 'ck',
23
- 'ck-size-view',
24
- bind.to('_viewPosition', value => value ? `ck-orientation-${value}` : '')
25
- ],
26
- style: {
27
- display: bind.if('_isVisible', 'none', visible => !visible)
28
- }
29
- },
30
- children: [{
31
- text: bind.to('_label')
32
- }]
33
- });
34
- }
35
- /**
36
- * A method used for binding the `SizeView` instance properties to the `ResizeState` instance observable properties.
37
- *
38
- * @internal
39
- * @param options An object defining the resizer options, used for setting the proper size label.
40
- * @param resizeState The `ResizeState` class instance, used for keeping the `SizeView` state up to date.
41
- */
42
- _bindToState(options, resizeState) {
43
- this.bind('_isVisible').to(resizeState, 'proposedWidth', resizeState, 'proposedHeight', (width, height) => width !== null && height !== null);
44
- this.bind('_label').to(resizeState, 'proposedHandleHostWidth', resizeState, 'proposedHandleHostHeight', resizeState, 'proposedWidthPercents', (width, height, widthPercents) => {
45
- if (options.unit === 'px') {
46
- return `${width}×${height}`;
47
- }
48
- else {
49
- return `${widthPercents}%`;
50
- }
51
- });
52
- this.bind('_viewPosition').to(resizeState, 'activeHandlePosition', resizeState, 'proposedHandleHostWidth', resizeState, 'proposedHandleHostHeight',
53
- // If the widget is too small to contain the size label, display the label above.
54
- (position, width, height) => width < 50 || height < 50 ? 'above-center' : position);
55
- }
56
- /**
57
- * A method used for cleaning up. It removes the bindings and hides the view.
58
- *
59
- * @internal
60
- */
61
- _dismiss() {
62
- this.unbind();
63
- this._isVisible = false;
64
- }
65
- }