@ckeditor/ckeditor5-image 39.0.2 → 40.0.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 (116) hide show
  1. package/build/image.js +1 -1
  2. package/build/image.js.map +1 -0
  3. package/build/translations/pt-br.js +1 -1
  4. package/ckeditor5-metadata.json +12 -0
  5. package/lang/translations/pt-br.po +1 -1
  6. package/package.json +3 -3
  7. package/src/augmentation.d.ts +56 -55
  8. package/src/augmentation.js +5 -5
  9. package/src/autoimage.d.ts +52 -52
  10. package/src/autoimage.js +132 -132
  11. package/src/image/converters.d.ts +66 -66
  12. package/src/image/converters.js +232 -242
  13. package/src/image/imageblockediting.d.ts +58 -55
  14. package/src/image/imageblockediting.js +152 -136
  15. package/src/image/imageediting.d.ts +30 -30
  16. package/src/image/imageediting.js +63 -74
  17. package/src/image/imageinlineediting.d.ts +59 -56
  18. package/src/image/imageinlineediting.js +176 -160
  19. package/src/image/imageloadobserver.d.ts +48 -48
  20. package/src/image/imageloadobserver.js +52 -52
  21. package/src/image/imagetypecommand.d.ts +44 -40
  22. package/src/image/imagetypecommand.js +80 -77
  23. package/src/image/insertimagecommand.d.ts +66 -66
  24. package/src/image/insertimagecommand.js +120 -120
  25. package/src/image/replaceimagesourcecommand.d.ts +34 -34
  26. package/src/image/replaceimagesourcecommand.js +44 -44
  27. package/src/image/ui/utils.d.ts +25 -25
  28. package/src/image/ui/utils.js +44 -44
  29. package/src/image/utils.d.ts +64 -52
  30. package/src/image/utils.js +121 -100
  31. package/src/image.d.ts +34 -34
  32. package/src/image.js +38 -38
  33. package/src/imageblock.d.ts +33 -33
  34. package/src/imageblock.js +37 -37
  35. package/src/imagecaption/imagecaptionediting.d.ts +89 -89
  36. package/src/imagecaption/imagecaptionediting.js +225 -225
  37. package/src/imagecaption/imagecaptionui.d.ts +26 -26
  38. package/src/imagecaption/imagecaptionui.js +61 -61
  39. package/src/imagecaption/imagecaptionutils.d.ts +38 -38
  40. package/src/imagecaption/imagecaptionutils.js +62 -62
  41. package/src/imagecaption/toggleimagecaptioncommand.d.ts +66 -66
  42. package/src/imagecaption/toggleimagecaptioncommand.js +138 -138
  43. package/src/imagecaption.d.ts +26 -26
  44. package/src/imagecaption.js +30 -30
  45. package/src/imageconfig.d.ts +713 -713
  46. package/src/imageconfig.js +5 -5
  47. package/src/imageinline.d.ts +33 -33
  48. package/src/imageinline.js +37 -37
  49. package/src/imageinsert/imageinsertui.d.ts +44 -44
  50. package/src/imageinsert/imageinsertui.js +141 -141
  51. package/src/imageinsert/ui/imageinsertformrowview.d.ts +61 -61
  52. package/src/imageinsert/ui/imageinsertformrowview.js +54 -54
  53. package/src/imageinsert/ui/imageinsertpanelview.d.ts +106 -106
  54. package/src/imageinsert/ui/imageinsertpanelview.js +161 -161
  55. package/src/imageinsert/utils.d.ts +25 -25
  56. package/src/imageinsert/utils.js +58 -58
  57. package/src/imageinsert.d.ts +33 -33
  58. package/src/imageinsert.js +37 -37
  59. package/src/imageinsertviaurl.d.ts +30 -30
  60. package/src/imageinsertviaurl.js +34 -34
  61. package/src/imageresize/imageresizebuttons.d.ts +67 -67
  62. package/src/imageresize/imageresizebuttons.js +217 -217
  63. package/src/imageresize/imageresizeediting.d.ts +37 -37
  64. package/src/imageresize/imageresizeediting.js +165 -114
  65. package/src/imageresize/imageresizehandles.d.ts +31 -30
  66. package/src/imageresize/imageresizehandles.js +114 -107
  67. package/src/imageresize/resizeimagecommand.d.ts +42 -42
  68. package/src/imageresize/resizeimagecommand.js +63 -61
  69. package/src/imageresize.d.ts +27 -27
  70. package/src/imageresize.js +31 -31
  71. package/src/imagesizeattributes.d.ts +34 -0
  72. package/src/imagesizeattributes.js +143 -0
  73. package/src/imagestyle/converters.d.ts +24 -24
  74. package/src/imagestyle/converters.js +79 -79
  75. package/src/imagestyle/imagestylecommand.d.ts +68 -65
  76. package/src/imagestyle/imagestylecommand.js +107 -101
  77. package/src/imagestyle/imagestyleediting.d.ts +50 -50
  78. package/src/imagestyle/imagestyleediting.js +108 -108
  79. package/src/imagestyle/imagestyleui.d.ts +56 -56
  80. package/src/imagestyle/imagestyleui.js +192 -192
  81. package/src/imagestyle/utils.d.ts +101 -101
  82. package/src/imagestyle/utils.js +329 -329
  83. package/src/imagestyle.d.ts +32 -32
  84. package/src/imagestyle.js +36 -36
  85. package/src/imagetextalternative/imagetextalternativecommand.d.ts +34 -34
  86. package/src/imagetextalternative/imagetextalternativecommand.js +44 -44
  87. package/src/imagetextalternative/imagetextalternativeediting.d.ts +28 -28
  88. package/src/imagetextalternative/imagetextalternativeediting.js +35 -35
  89. package/src/imagetextalternative/imagetextalternativeui.d.ts +68 -68
  90. package/src/imagetextalternative/imagetextalternativeui.js +173 -173
  91. package/src/imagetextalternative/ui/textalternativeformview.d.ts +72 -72
  92. package/src/imagetextalternative/ui/textalternativeformview.js +121 -121
  93. package/src/imagetextalternative.d.ts +29 -29
  94. package/src/imagetextalternative.js +33 -33
  95. package/src/imagetoolbar.d.ts +35 -35
  96. package/src/imagetoolbar.js +57 -57
  97. package/src/imageupload/imageuploadediting.d.ts +111 -111
  98. package/src/imageupload/imageuploadediting.js +337 -335
  99. package/src/imageupload/imageuploadprogress.d.ts +42 -42
  100. package/src/imageupload/imageuploadprogress.js +211 -211
  101. package/src/imageupload/imageuploadui.d.ts +23 -23
  102. package/src/imageupload/imageuploadui.js +57 -57
  103. package/src/imageupload/uploadimagecommand.d.ts +60 -60
  104. package/src/imageupload/uploadimagecommand.js +100 -100
  105. package/src/imageupload/utils.d.ts +33 -33
  106. package/src/imageupload/utils.js +112 -112
  107. package/src/imageupload.d.ts +32 -32
  108. package/src/imageupload.js +36 -36
  109. package/src/imageutils.d.ts +125 -102
  110. package/src/imageutils.js +306 -248
  111. package/src/index.d.ts +48 -47
  112. package/src/index.js +39 -38
  113. package/src/pictureediting.d.ts +88 -88
  114. package/src/pictureediting.js +130 -130
  115. package/theme/image.css +38 -11
  116. package/theme/imageresize.css +5 -0
@@ -1,112 +1,112 @@
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 { global } from 'ckeditor5/src/utils';
6
- /**
7
- * Creates a regular expression used to test for image files.
8
- *
9
- * ```ts
10
- * const imageType = createImageTypeRegExp( [ 'png', 'jpeg', 'svg+xml', 'vnd.microsoft.icon' ] );
11
- *
12
- * console.log( 'is supported image', imageType.test( file.type ) );
13
- * ```
14
- */
15
- export function createImageTypeRegExp(types) {
16
- // Sanitize the MIME type name which may include: "+", "-" or ".".
17
- const regExpSafeNames = types.map(type => type.replace('+', '\\+'));
18
- return new RegExp(`^image\\/(${regExpSafeNames.join('|')})$`);
19
- }
20
- /**
21
- * Creates a promise that fetches the image local source (Base64 or blob) and resolves with a `File` object.
22
- *
23
- * @param image Image whose source to fetch.
24
- * @returns A promise which resolves when an image source is fetched and converted to a `File` instance.
25
- * It resolves with a `File` object. If there were any errors during file processing, the promise will be rejected.
26
- */
27
- export function fetchLocalImage(image) {
28
- return new Promise((resolve, reject) => {
29
- const imageSrc = image.getAttribute('src');
30
- // Fetch works asynchronously and so does not block browser UI when processing data.
31
- fetch(imageSrc)
32
- .then(resource => resource.blob())
33
- .then(blob => {
34
- const mimeType = getImageMimeType(blob, imageSrc);
35
- const ext = mimeType.replace('image/', '');
36
- const filename = `image.${ext}`;
37
- const file = new File([blob], filename, { type: mimeType });
38
- resolve(file);
39
- })
40
- .catch(err => {
41
- // Fetch fails only, if it can't make a request due to a network failure or if anything prevented the request
42
- // from completing, i.e. the Content Security Policy rules. It is not possible to detect the exact cause of failure,
43
- // so we are just trying the fallback solution, if general TypeError is thrown.
44
- return err && err.name === 'TypeError' ?
45
- convertLocalImageOnCanvas(imageSrc).then(resolve).catch(reject) :
46
- reject(err);
47
- });
48
- });
49
- }
50
- /**
51
- * Checks whether a given node is an image element with a local source (Base64 or blob).
52
- *
53
- * @param node The node to check.
54
- */
55
- export function isLocalImage(imageUtils, node) {
56
- if (!imageUtils.isInlineImageView(node) || !node.getAttribute('src')) {
57
- return false;
58
- }
59
- return !!node.getAttribute('src').match(/^data:image\/\w+;base64,/g) ||
60
- !!node.getAttribute('src').match(/^blob:/g);
61
- }
62
- /**
63
- * Extracts an image type based on its blob representation or its source.
64
- * @param blob Image blob representation.
65
- * @param src Image `src` attribute value.
66
- */
67
- function getImageMimeType(blob, src) {
68
- if (blob.type) {
69
- return blob.type;
70
- }
71
- else if (src.match(/data:(image\/\w+);base64/)) {
72
- return src.match(/data:(image\/\w+);base64/)[1].toLowerCase();
73
- }
74
- else {
75
- // Fallback to 'jpeg' as common extension.
76
- return 'image/jpeg';
77
- }
78
- }
79
- /**
80
- * Creates a promise that converts the image local source (Base64 or blob) to a blob using canvas and resolves
81
- * with a `File` object.
82
- * @param imageSrc Image `src` attribute value.
83
- * @returns A promise which resolves when an image source is converted to a `File` instance.
84
- * It resolves with a `File` object. If there were any errors during file processing, the promise will be rejected.
85
- */
86
- function convertLocalImageOnCanvas(imageSrc) {
87
- return getBlobFromCanvas(imageSrc).then(blob => {
88
- const mimeType = getImageMimeType(blob, imageSrc);
89
- const ext = mimeType.replace('image/', '');
90
- const filename = `image.${ext}`;
91
- return new File([blob], filename, { type: mimeType });
92
- });
93
- }
94
- /**
95
- * Creates a promise that resolves with a `Blob` object converted from the image source (Base64 or blob).
96
- * @param imageSrc Image `src` attribute value.
97
- */
98
- function getBlobFromCanvas(imageSrc) {
99
- return new Promise((resolve, reject) => {
100
- const image = global.document.createElement('img');
101
- image.addEventListener('load', () => {
102
- const canvas = global.document.createElement('canvas');
103
- canvas.width = image.width;
104
- canvas.height = image.height;
105
- const ctx = canvas.getContext('2d');
106
- ctx.drawImage(image, 0, 0);
107
- canvas.toBlob(blob => blob ? resolve(blob) : reject());
108
- });
109
- image.addEventListener('error', () => reject());
110
- image.src = imageSrc;
111
- });
112
- }
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 { global } from 'ckeditor5/src/utils';
6
+ /**
7
+ * Creates a regular expression used to test for image files.
8
+ *
9
+ * ```ts
10
+ * const imageType = createImageTypeRegExp( [ 'png', 'jpeg', 'svg+xml', 'vnd.microsoft.icon' ] );
11
+ *
12
+ * console.log( 'is supported image', imageType.test( file.type ) );
13
+ * ```
14
+ */
15
+ export function createImageTypeRegExp(types) {
16
+ // Sanitize the MIME type name which may include: "+", "-" or ".".
17
+ const regExpSafeNames = types.map(type => type.replace('+', '\\+'));
18
+ return new RegExp(`^image\\/(${regExpSafeNames.join('|')})$`);
19
+ }
20
+ /**
21
+ * Creates a promise that fetches the image local source (Base64 or blob) and resolves with a `File` object.
22
+ *
23
+ * @param image Image whose source to fetch.
24
+ * @returns A promise which resolves when an image source is fetched and converted to a `File` instance.
25
+ * It resolves with a `File` object. If there were any errors during file processing, the promise will be rejected.
26
+ */
27
+ export function fetchLocalImage(image) {
28
+ return new Promise((resolve, reject) => {
29
+ const imageSrc = image.getAttribute('src');
30
+ // Fetch works asynchronously and so does not block browser UI when processing data.
31
+ fetch(imageSrc)
32
+ .then(resource => resource.blob())
33
+ .then(blob => {
34
+ const mimeType = getImageMimeType(blob, imageSrc);
35
+ const ext = mimeType.replace('image/', '');
36
+ const filename = `image.${ext}`;
37
+ const file = new File([blob], filename, { type: mimeType });
38
+ resolve(file);
39
+ })
40
+ .catch(err => {
41
+ // Fetch fails only, if it can't make a request due to a network failure or if anything prevented the request
42
+ // from completing, i.e. the Content Security Policy rules. It is not possible to detect the exact cause of failure,
43
+ // so we are just trying the fallback solution, if general TypeError is thrown.
44
+ return err && err.name === 'TypeError' ?
45
+ convertLocalImageOnCanvas(imageSrc).then(resolve).catch(reject) :
46
+ reject(err);
47
+ });
48
+ });
49
+ }
50
+ /**
51
+ * Checks whether a given node is an image element with a local source (Base64 or blob).
52
+ *
53
+ * @param node The node to check.
54
+ */
55
+ export function isLocalImage(imageUtils, node) {
56
+ if (!imageUtils.isInlineImageView(node) || !node.getAttribute('src')) {
57
+ return false;
58
+ }
59
+ return !!node.getAttribute('src').match(/^data:image\/\w+;base64,/g) ||
60
+ !!node.getAttribute('src').match(/^blob:/g);
61
+ }
62
+ /**
63
+ * Extracts an image type based on its blob representation or its source.
64
+ * @param blob Image blob representation.
65
+ * @param src Image `src` attribute value.
66
+ */
67
+ function getImageMimeType(blob, src) {
68
+ if (blob.type) {
69
+ return blob.type;
70
+ }
71
+ else if (src.match(/data:(image\/\w+);base64/)) {
72
+ return src.match(/data:(image\/\w+);base64/)[1].toLowerCase();
73
+ }
74
+ else {
75
+ // Fallback to 'jpeg' as common extension.
76
+ return 'image/jpeg';
77
+ }
78
+ }
79
+ /**
80
+ * Creates a promise that converts the image local source (Base64 or blob) to a blob using canvas and resolves
81
+ * with a `File` object.
82
+ * @param imageSrc Image `src` attribute value.
83
+ * @returns A promise which resolves when an image source is converted to a `File` instance.
84
+ * It resolves with a `File` object. If there were any errors during file processing, the promise will be rejected.
85
+ */
86
+ function convertLocalImageOnCanvas(imageSrc) {
87
+ return getBlobFromCanvas(imageSrc).then(blob => {
88
+ const mimeType = getImageMimeType(blob, imageSrc);
89
+ const ext = mimeType.replace('image/', '');
90
+ const filename = `image.${ext}`;
91
+ return new File([blob], filename, { type: mimeType });
92
+ });
93
+ }
94
+ /**
95
+ * Creates a promise that resolves with a `Blob` object converted from the image source (Base64 or blob).
96
+ * @param imageSrc Image `src` attribute value.
97
+ */
98
+ function getBlobFromCanvas(imageSrc) {
99
+ return new Promise((resolve, reject) => {
100
+ const image = global.document.createElement('img');
101
+ image.addEventListener('load', () => {
102
+ const canvas = global.document.createElement('canvas');
103
+ canvas.width = image.width;
104
+ canvas.height = image.height;
105
+ const ctx = canvas.getContext('2d');
106
+ ctx.drawImage(image, 0, 0);
107
+ canvas.toBlob(blob => blob ? resolve(blob) : reject());
108
+ });
109
+ image.addEventListener('error', () => reject());
110
+ image.src = imageSrc;
111
+ });
112
+ }
@@ -1,32 +1,32 @@
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 image/imageupload
7
- */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import ImageUploadUI from './imageupload/imageuploadui';
10
- import ImageUploadProgress from './imageupload/imageuploadprogress';
11
- import ImageUploadEditing from './imageupload/imageuploadediting';
12
- /**
13
- * The image upload plugin.
14
- *
15
- * For a detailed overview, check the {@glink features/images/image-upload/image-upload image upload feature} documentation.
16
- *
17
- * This plugin does not do anything directly, but it loads a set of specific plugins to enable image uploading:
18
- *
19
- * * {@link module:image/imageupload/imageuploadediting~ImageUploadEditing},
20
- * * {@link module:image/imageupload/imageuploadui~ImageUploadUI},
21
- * * {@link module:image/imageupload/imageuploadprogress~ImageUploadProgress}.
22
- */
23
- export default class ImageUpload extends Plugin {
24
- /**
25
- * @inheritDoc
26
- */
27
- static get pluginName(): "ImageUpload";
28
- /**
29
- * @inheritDoc
30
- */
31
- static get requires(): readonly [typeof ImageUploadEditing, typeof ImageUploadUI, typeof ImageUploadProgress];
32
- }
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 image/imageupload
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ import ImageUploadUI from './imageupload/imageuploadui';
10
+ import ImageUploadProgress from './imageupload/imageuploadprogress';
11
+ import ImageUploadEditing from './imageupload/imageuploadediting';
12
+ /**
13
+ * The image upload plugin.
14
+ *
15
+ * For a detailed overview, check the {@glink features/images/image-upload/image-upload image upload feature} documentation.
16
+ *
17
+ * This plugin does not do anything directly, but it loads a set of specific plugins to enable image uploading:
18
+ *
19
+ * * {@link module:image/imageupload/imageuploadediting~ImageUploadEditing},
20
+ * * {@link module:image/imageupload/imageuploadui~ImageUploadUI},
21
+ * * {@link module:image/imageupload/imageuploadprogress~ImageUploadProgress}.
22
+ */
23
+ export default class ImageUpload extends Plugin {
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ static get pluginName(): "ImageUpload";
28
+ /**
29
+ * @inheritDoc
30
+ */
31
+ static get requires(): readonly [typeof ImageUploadEditing, typeof ImageUploadUI, typeof ImageUploadProgress];
32
+ }
@@ -1,36 +1,36 @@
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 image/imageupload
7
- */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import ImageUploadUI from './imageupload/imageuploadui';
10
- import ImageUploadProgress from './imageupload/imageuploadprogress';
11
- import ImageUploadEditing from './imageupload/imageuploadediting';
12
- /**
13
- * The image upload plugin.
14
- *
15
- * For a detailed overview, check the {@glink features/images/image-upload/image-upload image upload feature} documentation.
16
- *
17
- * This plugin does not do anything directly, but it loads a set of specific plugins to enable image uploading:
18
- *
19
- * * {@link module:image/imageupload/imageuploadediting~ImageUploadEditing},
20
- * * {@link module:image/imageupload/imageuploadui~ImageUploadUI},
21
- * * {@link module:image/imageupload/imageuploadprogress~ImageUploadProgress}.
22
- */
23
- export default class ImageUpload extends Plugin {
24
- /**
25
- * @inheritDoc
26
- */
27
- static get pluginName() {
28
- return 'ImageUpload';
29
- }
30
- /**
31
- * @inheritDoc
32
- */
33
- static get requires() {
34
- return [ImageUploadEditing, ImageUploadUI, ImageUploadProgress];
35
- }
36
- }
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 image/imageupload
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ import ImageUploadUI from './imageupload/imageuploadui';
10
+ import ImageUploadProgress from './imageupload/imageuploadprogress';
11
+ import ImageUploadEditing from './imageupload/imageuploadediting';
12
+ /**
13
+ * The image upload plugin.
14
+ *
15
+ * For a detailed overview, check the {@glink features/images/image-upload/image-upload image upload feature} documentation.
16
+ *
17
+ * This plugin does not do anything directly, but it loads a set of specific plugins to enable image uploading:
18
+ *
19
+ * * {@link module:image/imageupload/imageuploadediting~ImageUploadEditing},
20
+ * * {@link module:image/imageupload/imageuploadui~ImageUploadUI},
21
+ * * {@link module:image/imageupload/imageuploadprogress~ImageUploadProgress}.
22
+ */
23
+ export default class ImageUpload extends Plugin {
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ static get pluginName() {
28
+ return 'ImageUpload';
29
+ }
30
+ /**
31
+ * @inheritDoc
32
+ */
33
+ static get requires() {
34
+ return [ImageUploadEditing, ImageUploadUI, ImageUploadProgress];
35
+ }
36
+ }
@@ -1,102 +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
- /**
6
- * @module image/imageutils
7
- */
8
- import type { Element, ViewElement, DocumentSelection, ViewDocumentSelection, Selection, ViewSelection, DowncastWriter, Position } from 'ckeditor5/src/engine';
9
- import { Plugin } from 'ckeditor5/src/core';
10
- /**
11
- * A set of helpers related to images.
12
- */
13
- export default class ImageUtils extends Plugin {
14
- /**
15
- * @inheritDoc
16
- */
17
- static get pluginName(): "ImageUtils";
18
- /**
19
- * Checks if the provided model element is an `image` or `imageInline`.
20
- */
21
- isImage(modelElement?: Element | null): modelElement is Element & {
22
- name: 'imageInline' | 'imageBlock';
23
- };
24
- /**
25
- * Checks if the provided view element represents an inline image.
26
- *
27
- * Also, see {@link module:image/imageutils~ImageUtils#isImageWidget}.
28
- */
29
- isInlineImageView(element?: ViewElement | null): boolean;
30
- /**
31
- * Checks if the provided view element represents a block image.
32
- *
33
- * Also, see {@link module:image/imageutils~ImageUtils#isImageWidget}.
34
- */
35
- isBlockImageView(element?: ViewElement | null): boolean;
36
- /**
37
- * Handles inserting single file. This method unifies image insertion using {@link module:widget/utils~findOptimalInsertionRange}
38
- * method.
39
- *
40
- * ```ts
41
- * const imageUtils = editor.plugins.get( 'ImageUtils' );
42
- *
43
- * imageUtils.insertImage( { src: 'path/to/image.jpg' } );
44
- * ```
45
- *
46
- * @param attributes Attributes of the inserted image.
47
- * This method filters out the attributes which are disallowed by the {@link module:engine/model/schema~Schema}.
48
- * @param selectable Place to insert the image. If not specified,
49
- * the {@link module:widget/utils~findOptimalInsertionRange} logic will be applied for the block images
50
- * and `model.document.selection` for the inline images.
51
- *
52
- * **Note**: If `selectable` is passed, this helper will not be able to set selection attributes (such as `linkHref`)
53
- * and apply them to the new image. In this case, make sure all selection attributes are passed in `attributes`.
54
- *
55
- * @param imageType Image type of inserted image. If not specified,
56
- * it will be determined automatically depending of editor config or place of the insertion.
57
- * @return The inserted model image element.
58
- */
59
- insertImage(attributes?: Record<string, unknown>, selectable?: Selection | Position | null, imageType?: ('imageBlock' | 'imageInline' | null)): Element | null;
60
- /**
61
- * Returns an image widget editing view element if one is selected or is among the selection's ancestors.
62
- */
63
- getClosestSelectedImageWidget(selection: ViewSelection | ViewDocumentSelection): ViewElement | null;
64
- /**
65
- * Returns a image model element if one is selected or is among the selection's ancestors.
66
- */
67
- getClosestSelectedImageElement(selection: Selection | DocumentSelection): Element | null;
68
- /**
69
- * Checks if image can be inserted at current model selection.
70
- *
71
- * @internal
72
- */
73
- isImageAllowed(): boolean;
74
- /**
75
- * Converts a given {@link module:engine/view/element~Element} to an image widget:
76
- * * Adds a {@link module:engine/view/element~Element#_setCustomProperty custom property} allowing to recognize the image widget
77
- * element.
78
- * * Calls the {@link module:widget/utils~toWidget} function with the proper element's label creator.
79
- *
80
- * @param writer An instance of the view writer.
81
- * @param label The element's label. It will be concatenated with the image `alt` attribute if one is present.
82
- */
83
- toImageWidget(viewElement: ViewElement, writer: DowncastWriter, label: string): ViewElement;
84
- /**
85
- * Checks if a given view element is an image widget.
86
- */
87
- protected isImageWidget(viewElement: ViewElement): boolean;
88
- /**
89
- * Checks if the provided model element is an `image`.
90
- */
91
- isBlockImage(modelElement?: Element | null): boolean;
92
- /**
93
- * Checks if the provided model element is an `imageInline`.
94
- */
95
- isInlineImage(modelElement?: Element | null): boolean;
96
- /**
97
- * Get the view `<img>` from another view element, e.g. a widget (`<figure class="image">`), a link (`<a>`).
98
- *
99
- * The `<img>` can be located deep in other elements, so this helper performs a deep tree search.
100
- */
101
- findViewImgElement(figureView: ViewElement): ViewElement | undefined;
102
- }
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 image/imageutils
7
+ */
8
+ import type { Element, ViewElement, DocumentSelection, ViewDocumentSelection, Selection, ViewSelection, DowncastWriter, Position, ViewContainerElement } from 'ckeditor5/src/engine';
9
+ import { Plugin } from 'ckeditor5/src/core';
10
+ /**
11
+ * A set of helpers related to images.
12
+ */
13
+ export default class ImageUtils extends Plugin {
14
+ /**
15
+ * DOM Emitter.
16
+ */
17
+ private _domEmitter;
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ static get pluginName(): "ImageUtils";
22
+ /**
23
+ * Checks if the provided model element is an `image` or `imageInline`.
24
+ */
25
+ isImage(modelElement?: Element | null): modelElement is Element & {
26
+ name: 'imageInline' | 'imageBlock';
27
+ };
28
+ /**
29
+ * Checks if the provided view element represents an inline image.
30
+ *
31
+ * Also, see {@link module:image/imageutils~ImageUtils#isImageWidget}.
32
+ */
33
+ isInlineImageView(element?: ViewElement | null): boolean;
34
+ /**
35
+ * Checks if the provided view element represents a block image.
36
+ *
37
+ * Also, see {@link module:image/imageutils~ImageUtils#isImageWidget}.
38
+ */
39
+ isBlockImageView(element?: ViewElement | null): boolean;
40
+ /**
41
+ * Handles inserting single file. This method unifies image insertion using {@link module:widget/utils~findOptimalInsertionRange}
42
+ * method.
43
+ *
44
+ * ```ts
45
+ * const imageUtils = editor.plugins.get( 'ImageUtils' );
46
+ *
47
+ * imageUtils.insertImage( { src: 'path/to/image.jpg' } );
48
+ * ```
49
+ *
50
+ * @param attributes Attributes of the inserted image.
51
+ * This method filters out the attributes which are disallowed by the {@link module:engine/model/schema~Schema}.
52
+ * @param selectable Place to insert the image. If not specified,
53
+ * the {@link module:widget/utils~findOptimalInsertionRange} logic will be applied for the block images
54
+ * and `model.document.selection` for the inline images.
55
+ *
56
+ * **Note**: If `selectable` is passed, this helper will not be able to set selection attributes (such as `linkHref`)
57
+ * and apply them to the new image. In this case, make sure all selection attributes are passed in `attributes`.
58
+ *
59
+ * @param imageType Image type of inserted image. If not specified,
60
+ * it will be determined automatically depending of editor config or place of the insertion.
61
+ * @param options.setImageSizes Specifies whether the image `width` and `height` attributes should be set automatically.
62
+ * The default is `true`.
63
+ * @return The inserted model image element.
64
+ */
65
+ insertImage(attributes?: Record<string, unknown>, selectable?: Selection | Position | null, imageType?: ('imageBlock' | 'imageInline' | null), options?: {
66
+ setImageSizes?: boolean;
67
+ }): Element | null;
68
+ /**
69
+ * Reads original image sizes and sets them as `width` and `height`.
70
+ *
71
+ * The `src` attribute may not be available if the user is using an upload adapter. In such a case,
72
+ * this method is called again after the upload process is complete and the `src` attribute is available.
73
+ */
74
+ setImageNaturalSizeAttributes(imageElement: Element): void;
75
+ /**
76
+ * Returns an image widget editing view element if one is selected or is among the selection's ancestors.
77
+ */
78
+ getClosestSelectedImageWidget(selection: ViewSelection | ViewDocumentSelection): ViewElement | null;
79
+ /**
80
+ * Returns a image model element if one is selected or is among the selection's ancestors.
81
+ */
82
+ getClosestSelectedImageElement(selection: Selection | DocumentSelection): Element | null;
83
+ /**
84
+ * Returns an image widget editing view based on the passed image view.
85
+ */
86
+ getImageWidgetFromImageView(imageView: ViewElement): ViewContainerElement | null;
87
+ /**
88
+ * Checks if image can be inserted at current model selection.
89
+ *
90
+ * @internal
91
+ */
92
+ isImageAllowed(): boolean;
93
+ /**
94
+ * Converts a given {@link module:engine/view/element~Element} to an image widget:
95
+ * * Adds a {@link module:engine/view/element~Element#_setCustomProperty custom property} allowing to recognize the image widget
96
+ * element.
97
+ * * Calls the {@link module:widget/utils~toWidget} function with the proper element's label creator.
98
+ *
99
+ * @param writer An instance of the view writer.
100
+ * @param label The element's label. It will be concatenated with the image `alt` attribute if one is present.
101
+ */
102
+ toImageWidget(viewElement: ViewElement, writer: DowncastWriter, label: string): ViewElement;
103
+ /**
104
+ * Checks if a given view element is an image widget.
105
+ */
106
+ protected isImageWidget(viewElement: ViewElement): boolean;
107
+ /**
108
+ * Checks if the provided model element is an `image`.
109
+ */
110
+ isBlockImage(modelElement?: Element | null): boolean;
111
+ /**
112
+ * Checks if the provided model element is an `imageInline`.
113
+ */
114
+ isInlineImage(modelElement?: Element | null): boolean;
115
+ /**
116
+ * Get the view `<img>` from another view element, e.g. a widget (`<figure class="image">`), a link (`<a>`).
117
+ *
118
+ * The `<img>` can be located deep in other elements, so this helper performs a deep tree search.
119
+ */
120
+ findViewImgElement(figureView: ViewElement): ViewElement | undefined;
121
+ /**
122
+ * @inheritDoc
123
+ */
124
+ destroy(): void;
125
+ }