@ckeditor/ckeditor5-image 47.6.1 → 48.0.0-alpha.1

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 (289) hide show
  1. package/LICENSE.md +1 -1
  2. package/ckeditor5-metadata.json +25 -25
  3. package/{src → dist}/autoimage.d.ts +4 -4
  4. package/{src → dist}/image/converters.d.ts +1 -1
  5. package/{src → dist}/image/imageblockediting.d.ts +2 -2
  6. package/{src → dist}/image/imageediting.d.ts +1 -1
  7. package/{src → dist}/image/imageinlineediting.d.ts +2 -2
  8. package/{src → dist}/image/imageloadobserver.d.ts +1 -1
  9. package/{src → dist}/image/imageplaceholder.d.ts +1 -1
  10. package/{src → dist}/image/imagetypecommand.d.ts +2 -2
  11. package/{src → dist}/image/insertimagecommand.d.ts +2 -2
  12. package/{src → dist}/image/replaceimagesourcecommand.d.ts +2 -2
  13. package/{src → dist}/image/ui/utils.d.ts +2 -2
  14. package/{src → dist}/image/utils.d.ts +2 -2
  15. package/{src → dist}/image.d.ts +1 -1
  16. package/{src → dist}/imageblock.d.ts +2 -2
  17. package/{src → dist}/imagecaption/imagecaptionediting.d.ts +2 -2
  18. package/{src → dist}/imagecaption/imagecaptionui.d.ts +1 -1
  19. package/{src → dist}/imagecaption/imagecaptionutils.d.ts +2 -2
  20. package/{src → dist}/imagecaption/toggleimagecaptioncommand.d.ts +1 -1
  21. package/{src → dist}/imagecaption.d.ts +1 -1
  22. package/{src → dist}/imageconfig.d.ts +25 -16
  23. package/{src → dist}/imageinline.d.ts +2 -2
  24. package/{src → dist}/imageinsert/imageinsertui.d.ts +3 -3
  25. package/{src → dist}/imageinsert/imageinsertviaurlui.d.ts +2 -2
  26. package/{src → dist}/imageinsert/ui/imageinsertformview.d.ts +2 -2
  27. package/{src → dist}/imageinsert/ui/imageinserturlview.d.ts +2 -2
  28. package/{src → dist}/imageinsert.d.ts +1 -1
  29. package/{src → dist}/imageinsertviaurl.d.ts +1 -1
  30. package/{src → dist}/imageresize/imagecustomresizeui.d.ts +2 -2
  31. package/{src → dist}/imageresize/imageresizebuttons.d.ts +1 -1
  32. package/{src → dist}/imageresize/imageresizeediting.d.ts +1 -1
  33. package/{src → dist}/imageresize/imageresizehandles.d.ts +2 -2
  34. package/{src → dist}/imageresize/resizeimagecommand.d.ts +1 -1
  35. package/{src → dist}/imageresize/ui/imagecustomresizeformview.d.ts +2 -4
  36. package/{src → dist}/imageresize/utils/getselectedimageeditornodes.d.ts +2 -2
  37. package/{src → dist}/imageresize/utils/getselectedimagepossibleresizerange.d.ts +1 -1
  38. package/{src → dist}/imageresize/utils/getselectedimagewidthinunits.d.ts +1 -1
  39. package/{src → dist}/imageresize.d.ts +1 -1
  40. package/{src → dist}/imagesizeattributes.d.ts +1 -1
  41. package/{src → dist}/imagestyle/converters.d.ts +2 -2
  42. package/{src → dist}/imagestyle/imagestylecommand.d.ts +2 -2
  43. package/{src → dist}/imagestyle/imagestyleediting.d.ts +1 -1
  44. package/{src → dist}/imagestyle/imagestyleui.d.ts +1 -1
  45. package/{src → dist}/imagestyle/utils.d.ts +1 -1
  46. package/{src → dist}/imagestyle.d.ts +1 -1
  47. package/{src → dist}/imagetextalternative/imagetextalternativecommand.d.ts +1 -1
  48. package/{src → dist}/imagetextalternative/imagetextalternativeediting.d.ts +1 -1
  49. package/{src → dist}/imagetextalternative/imagetextalternativeui.d.ts +2 -2
  50. package/{src → dist}/imagetextalternative/ui/textalternativeformview.d.ts +2 -4
  51. package/{src → dist}/imagetextalternative.d.ts +1 -1
  52. package/{src → dist}/imagetoolbar.d.ts +2 -2
  53. package/{src → dist}/imageupload/imageuploadediting.d.ts +5 -5
  54. package/{src → dist}/imageupload/imageuploadprogress.d.ts +1 -1
  55. package/{src → dist}/imageupload/imageuploadui.d.ts +1 -1
  56. package/{src → dist}/imageupload/uploadimagecommand.d.ts +2 -2
  57. package/{src → dist}/imageupload/utils.d.ts +1 -1
  58. package/{src → dist}/imageupload.d.ts +1 -1
  59. package/{src → dist}/imageutils.d.ts +2 -2
  60. package/dist/index-content.css +97 -100
  61. package/dist/index-editor.css +313 -190
  62. package/dist/index.css +388 -458
  63. package/dist/index.css.map +1 -1
  64. package/dist/index.js +1 -2
  65. package/dist/index.js.map +1 -1
  66. package/{src → dist}/pictureediting.d.ts +1 -1
  67. package/package.json +29 -53
  68. package/build/image.js +0 -5
  69. package/build/translations/af.js +0 -1
  70. package/build/translations/ar.js +0 -1
  71. package/build/translations/ast.js +0 -1
  72. package/build/translations/az.js +0 -1
  73. package/build/translations/be.js +0 -1
  74. package/build/translations/bg.js +0 -1
  75. package/build/translations/bn.js +0 -1
  76. package/build/translations/bs.js +0 -1
  77. package/build/translations/ca.js +0 -1
  78. package/build/translations/cs.js +0 -1
  79. package/build/translations/da.js +0 -1
  80. package/build/translations/de-ch.js +0 -1
  81. package/build/translations/de.js +0 -1
  82. package/build/translations/el.js +0 -1
  83. package/build/translations/en-au.js +0 -1
  84. package/build/translations/en-gb.js +0 -1
  85. package/build/translations/eo.js +0 -1
  86. package/build/translations/es-co.js +0 -1
  87. package/build/translations/es.js +0 -1
  88. package/build/translations/et.js +0 -1
  89. package/build/translations/eu.js +0 -1
  90. package/build/translations/fa.js +0 -1
  91. package/build/translations/fi.js +0 -1
  92. package/build/translations/fr.js +0 -1
  93. package/build/translations/gl.js +0 -1
  94. package/build/translations/gu.js +0 -1
  95. package/build/translations/he.js +0 -1
  96. package/build/translations/hi.js +0 -1
  97. package/build/translations/hr.js +0 -1
  98. package/build/translations/hu.js +0 -1
  99. package/build/translations/hy.js +0 -1
  100. package/build/translations/id.js +0 -1
  101. package/build/translations/it.js +0 -1
  102. package/build/translations/ja.js +0 -1
  103. package/build/translations/jv.js +0 -1
  104. package/build/translations/kk.js +0 -1
  105. package/build/translations/km.js +0 -1
  106. package/build/translations/kn.js +0 -1
  107. package/build/translations/ko.js +0 -1
  108. package/build/translations/ku.js +0 -1
  109. package/build/translations/lt.js +0 -1
  110. package/build/translations/lv.js +0 -1
  111. package/build/translations/ms.js +0 -1
  112. package/build/translations/nb.js +0 -1
  113. package/build/translations/ne.js +0 -1
  114. package/build/translations/nl.js +0 -1
  115. package/build/translations/no.js +0 -1
  116. package/build/translations/oc.js +0 -1
  117. package/build/translations/pl.js +0 -1
  118. package/build/translations/pt-br.js +0 -1
  119. package/build/translations/pt.js +0 -1
  120. package/build/translations/ro.js +0 -1
  121. package/build/translations/ru.js +0 -1
  122. package/build/translations/si.js +0 -1
  123. package/build/translations/sk.js +0 -1
  124. package/build/translations/sl.js +0 -1
  125. package/build/translations/sq.js +0 -1
  126. package/build/translations/sr-latn.js +0 -1
  127. package/build/translations/sr.js +0 -1
  128. package/build/translations/sv.js +0 -1
  129. package/build/translations/th.js +0 -1
  130. package/build/translations/ti.js +0 -1
  131. package/build/translations/tk.js +0 -1
  132. package/build/translations/tr.js +0 -1
  133. package/build/translations/tt.js +0 -1
  134. package/build/translations/ug.js +0 -1
  135. package/build/translations/uk.js +0 -1
  136. package/build/translations/ur.js +0 -1
  137. package/build/translations/uz.js +0 -1
  138. package/build/translations/vi.js +0 -1
  139. package/build/translations/zh-cn.js +0 -1
  140. package/build/translations/zh.js +0 -1
  141. package/lang/contexts.json +0 -48
  142. package/lang/translations/af.po +0 -196
  143. package/lang/translations/ar.po +0 -196
  144. package/lang/translations/ast.po +0 -196
  145. package/lang/translations/az.po +0 -196
  146. package/lang/translations/be.po +0 -196
  147. package/lang/translations/bg.po +0 -196
  148. package/lang/translations/bn.po +0 -196
  149. package/lang/translations/bs.po +0 -196
  150. package/lang/translations/ca.po +0 -196
  151. package/lang/translations/cs.po +0 -196
  152. package/lang/translations/da.po +0 -196
  153. package/lang/translations/de-ch.po +0 -196
  154. package/lang/translations/de.po +0 -196
  155. package/lang/translations/el.po +0 -196
  156. package/lang/translations/en-au.po +0 -196
  157. package/lang/translations/en-gb.po +0 -196
  158. package/lang/translations/en.po +0 -196
  159. package/lang/translations/eo.po +0 -196
  160. package/lang/translations/es-co.po +0 -196
  161. package/lang/translations/es.po +0 -196
  162. package/lang/translations/et.po +0 -196
  163. package/lang/translations/eu.po +0 -196
  164. package/lang/translations/fa.po +0 -196
  165. package/lang/translations/fi.po +0 -196
  166. package/lang/translations/fr.po +0 -196
  167. package/lang/translations/gl.po +0 -196
  168. package/lang/translations/gu.po +0 -196
  169. package/lang/translations/he.po +0 -196
  170. package/lang/translations/hi.po +0 -196
  171. package/lang/translations/hr.po +0 -196
  172. package/lang/translations/hu.po +0 -196
  173. package/lang/translations/hy.po +0 -196
  174. package/lang/translations/id.po +0 -196
  175. package/lang/translations/it.po +0 -196
  176. package/lang/translations/ja.po +0 -196
  177. package/lang/translations/jv.po +0 -196
  178. package/lang/translations/kk.po +0 -196
  179. package/lang/translations/km.po +0 -196
  180. package/lang/translations/kn.po +0 -196
  181. package/lang/translations/ko.po +0 -196
  182. package/lang/translations/ku.po +0 -196
  183. package/lang/translations/lt.po +0 -196
  184. package/lang/translations/lv.po +0 -196
  185. package/lang/translations/ms.po +0 -196
  186. package/lang/translations/nb.po +0 -196
  187. package/lang/translations/ne.po +0 -196
  188. package/lang/translations/nl.po +0 -196
  189. package/lang/translations/no.po +0 -196
  190. package/lang/translations/oc.po +0 -196
  191. package/lang/translations/pl.po +0 -196
  192. package/lang/translations/pt-br.po +0 -196
  193. package/lang/translations/pt.po +0 -196
  194. package/lang/translations/ro.po +0 -196
  195. package/lang/translations/ru.po +0 -196
  196. package/lang/translations/si.po +0 -196
  197. package/lang/translations/sk.po +0 -196
  198. package/lang/translations/sl.po +0 -196
  199. package/lang/translations/sq.po +0 -196
  200. package/lang/translations/sr-latn.po +0 -196
  201. package/lang/translations/sr.po +0 -196
  202. package/lang/translations/sv.po +0 -196
  203. package/lang/translations/th.po +0 -196
  204. package/lang/translations/ti.po +0 -196
  205. package/lang/translations/tk.po +0 -196
  206. package/lang/translations/tr.po +0 -196
  207. package/lang/translations/tt.po +0 -196
  208. package/lang/translations/ug.po +0 -196
  209. package/lang/translations/uk.po +0 -196
  210. package/lang/translations/ur.po +0 -196
  211. package/lang/translations/uz.po +0 -196
  212. package/lang/translations/vi.po +0 -196
  213. package/lang/translations/zh-cn.po +0 -196
  214. package/lang/translations/zh.po +0 -196
  215. package/src/augmentation.js +0 -5
  216. package/src/autoimage.js +0 -148
  217. package/src/image/converters.js +0 -236
  218. package/src/image/imageblockediting.js +0 -159
  219. package/src/image/imageediting.js +0 -69
  220. package/src/image/imageinlineediting.js +0 -178
  221. package/src/image/imageloadobserver.js +0 -52
  222. package/src/image/imageplaceholder.js +0 -119
  223. package/src/image/imagetypecommand.js +0 -84
  224. package/src/image/insertimagecommand.js +0 -125
  225. package/src/image/replaceimagesourcecommand.js +0 -75
  226. package/src/image/ui/utils.js +0 -46
  227. package/src/image/utils.js +0 -125
  228. package/src/image.js +0 -44
  229. package/src/imageblock.js +0 -44
  230. package/src/imagecaption/imagecaptionediting.js +0 -238
  231. package/src/imagecaption/imagecaptionui.js +0 -68
  232. package/src/imagecaption/imagecaptionutils.js +0 -68
  233. package/src/imagecaption/toggleimagecaptioncommand.js +0 -138
  234. package/src/imagecaption.js +0 -36
  235. package/src/imageconfig.js +0 -5
  236. package/src/imageinline.js +0 -44
  237. package/src/imageinsert/imageinsertui.js +0 -216
  238. package/src/imageinsert/imageinsertviaurlui.js +0 -175
  239. package/src/imageinsert/ui/imageinsertformview.js +0 -117
  240. package/src/imageinsert/ui/imageinserturlview.js +0 -102
  241. package/src/imageinsert.js +0 -43
  242. package/src/imageinsertviaurl.js +0 -41
  243. package/src/imageresize/imagecustomresizeui.js +0 -177
  244. package/src/imageresize/imageresizebuttons.js +0 -303
  245. package/src/imageresize/imageresizeediting.js +0 -206
  246. package/src/imageresize/imageresizehandles.js +0 -118
  247. package/src/imageresize/resizeimagecommand.js +0 -63
  248. package/src/imageresize/ui/imagecustomresizeformview.js +0 -264
  249. package/src/imageresize/utils/getselectedimageeditornodes.js +0 -25
  250. package/src/imageresize/utils/getselectedimagepossibleresizerange.js +0 -33
  251. package/src/imageresize/utils/getselectedimagewidthinunits.js +0 -42
  252. package/src/imageresize/utils/tryparsedimensionwithunit.js +0 -58
  253. package/src/imageresize.js +0 -38
  254. package/src/imagesizeattributes.js +0 -163
  255. package/src/imagestyle/converters.js +0 -118
  256. package/src/imagestyle/imagestylecommand.js +0 -117
  257. package/src/imagestyle/imagestyleediting.js +0 -127
  258. package/src/imagestyle/imagestyleui.js +0 -198
  259. package/src/imagestyle/utils.js +0 -333
  260. package/src/imagestyle.js +0 -42
  261. package/src/imagetextalternative/imagetextalternativecommand.js +0 -44
  262. package/src/imagetextalternative/imagetextalternativeediting.js +0 -41
  263. package/src/imagetextalternative/imagetextalternativeui.js +0 -183
  264. package/src/imagetextalternative/ui/textalternativeformview.js +0 -193
  265. package/src/imagetextalternative.js +0 -39
  266. package/src/imagetoolbar.js +0 -63
  267. package/src/imageupload/imageuploadediting.js +0 -482
  268. package/src/imageupload/imageuploadprogress.js +0 -222
  269. package/src/imageupload/imageuploadui.js +0 -135
  270. package/src/imageupload/uploadimagecommand.js +0 -110
  271. package/src/imageupload/utils.js +0 -114
  272. package/src/imageupload.js +0 -42
  273. package/src/imageutils.js +0 -309
  274. package/src/index.js +0 -67
  275. package/src/pictureediting.js +0 -136
  276. package/theme/image.css +0 -143
  277. package/theme/imagecaption.css +0 -53
  278. package/theme/imagecustomresizeform.css +0 -4
  279. package/theme/imageinsert.css +0 -14
  280. package/theme/imageplaceholder.css +0 -10
  281. package/theme/imageresize.css +0 -53
  282. package/theme/imagestyle.css +0 -120
  283. package/theme/imageuploadicon.css +0 -23
  284. package/theme/imageuploadloader.css +0 -18
  285. package/theme/imageuploadprogress.css +0 -19
  286. package/theme/textalternativeform.css +0 -4
  287. /package/{src → dist}/augmentation.d.ts +0 -0
  288. /package/{src → dist}/imageresize/utils/tryparsedimensionwithunit.d.ts +0 -0
  289. /package/{src → dist}/index.d.ts +0 -0
@@ -1,163 +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 image/imagesizeattributes
7
- */
8
- import { Plugin } from 'ckeditor5/src/core.js';
9
- import { ImageUtils } from './imageutils.js';
10
- import { widthAndHeightStylesAreBothSet, getSizeValueIfInPx } from './image/utils.js';
11
- /**
12
- * This plugin enables `width` and `height` attributes in inline and block image elements.
13
- */
14
- export class ImageSizeAttributes extends Plugin {
15
- /**
16
- * @inheritDoc
17
- */
18
- static get requires() {
19
- return [ImageUtils];
20
- }
21
- /**
22
- * @inheritDoc
23
- */
24
- static get pluginName() {
25
- return 'ImageSizeAttributes';
26
- }
27
- /**
28
- * @inheritDoc
29
- */
30
- static get isOfficialPlugin() {
31
- return true;
32
- }
33
- /**
34
- * @inheritDoc
35
- */
36
- afterInit() {
37
- this._registerSchema();
38
- this._registerConverters('imageBlock');
39
- this._registerConverters('imageInline');
40
- }
41
- /**
42
- * Registers the `width` and `height` attributes for inline and block images.
43
- */
44
- _registerSchema() {
45
- const schema = this.editor.model.schema;
46
- if (this.editor.plugins.has('ImageBlockEditing')) {
47
- schema.extend('imageBlock', { allowAttributes: ['width', 'height'] });
48
- }
49
- if (this.editor.plugins.has('ImageInlineEditing')) {
50
- schema.extend('imageInline', { allowAttributes: ['width', 'height'] });
51
- }
52
- }
53
- /**
54
- * Registers converters for `width` and `height` attributes.
55
- */
56
- _registerConverters(imageType) {
57
- const editor = this.editor;
58
- const imageUtils = editor.plugins.get('ImageUtils');
59
- const viewElementName = imageType === 'imageBlock' ? 'figure' : 'img';
60
- editor.conversion.for('upcast')
61
- .attributeToAttribute({
62
- view: {
63
- name: viewElementName,
64
- styles: {
65
- width: /.+/
66
- }
67
- },
68
- model: {
69
- key: 'width',
70
- value: (viewElement) => {
71
- if (widthAndHeightStylesAreBothSet(viewElement)) {
72
- return getSizeValueIfInPx(viewElement.getStyle('width'));
73
- }
74
- return null;
75
- }
76
- }
77
- })
78
- .attributeToAttribute({
79
- view: {
80
- name: viewElementName,
81
- key: 'width'
82
- },
83
- model: 'width'
84
- })
85
- .attributeToAttribute({
86
- view: {
87
- name: viewElementName,
88
- styles: {
89
- height: /.+/
90
- }
91
- },
92
- model: {
93
- key: 'height',
94
- value: (viewElement) => {
95
- if (widthAndHeightStylesAreBothSet(viewElement)) {
96
- return getSizeValueIfInPx(viewElement.getStyle('height'));
97
- }
98
- return null;
99
- }
100
- }
101
- })
102
- .attributeToAttribute({
103
- view: {
104
- name: viewElementName,
105
- key: 'height'
106
- },
107
- model: 'height'
108
- });
109
- // Dedicated converters to propagate attributes to the <img> element.
110
- editor.conversion.for('editingDowncast').add(dispatcher => {
111
- attachDowncastConverter(dispatcher, 'width', 'width', true, true);
112
- attachDowncastConverter(dispatcher, 'height', 'height', true, true);
113
- });
114
- editor.conversion.for('dataDowncast').add(dispatcher => {
115
- attachDowncastConverter(dispatcher, 'width', 'width', false);
116
- attachDowncastConverter(dispatcher, 'height', 'height', false);
117
- });
118
- // Consume `aspect-ratio` style if `width` and `height` attributes are set on the image.
119
- editor.conversion.for('upcast').add(dispatcher => {
120
- dispatcher.on('element:img', (evt, data, conversionApi) => {
121
- const width = data.viewItem.getAttribute('width');
122
- const height = data.viewItem.getAttribute('height');
123
- if (width && height) {
124
- conversionApi.consumable.consume(data.viewItem, { styles: ['aspect-ratio'] });
125
- }
126
- });
127
- });
128
- function attachDowncastConverter(dispatcher, modelAttributeName, viewAttributeName, setRatioForInlineImage, isEditingDowncast = false) {
129
- dispatcher.on(`attribute:${modelAttributeName}:${imageType}`, (evt, data, conversionApi) => {
130
- if (!conversionApi.consumable.consume(data.item, evt.name)) {
131
- return;
132
- }
133
- const viewWriter = conversionApi.writer;
134
- const viewElement = conversionApi.mapper.toViewElement(data.item);
135
- const img = imageUtils.findViewImgElement(viewElement);
136
- if (data.attributeNewValue !== null) {
137
- viewWriter.setAttribute(viewAttributeName, data.attributeNewValue, img);
138
- }
139
- else {
140
- viewWriter.removeAttribute(viewAttributeName, img);
141
- }
142
- const width = data.item.getAttribute('width');
143
- const height = data.item.getAttribute('height');
144
- const hasSizes = width && height;
145
- if (hasSizes && isEditingDowncast) {
146
- viewWriter.setAttribute('loading', 'lazy', img);
147
- }
148
- // Do not set aspect-ratio for pictures. See https://github.com/ckeditor/ckeditor5/issues/14579.
149
- if (data.item.hasAttribute('sources')) {
150
- return;
151
- }
152
- const isResized = data.item.hasAttribute('resizedWidth');
153
- // Do not set aspect ratio for inline images which are not resized (data pipeline).
154
- if (imageType === 'imageInline' && !isResized && !setRatioForInlineImage) {
155
- return;
156
- }
157
- if (hasSizes) {
158
- viewWriter.setStyle('aspect-ratio', `${width}/${height}`, img);
159
- }
160
- });
161
- }
162
- }
163
- }
@@ -1,118 +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
- import isEqual from 'es-toolkit/compat/isEqual';
6
- import { first } from 'ckeditor5/src/utils.js';
7
- import { DEFAULT_OPTIONS } from './utils.js';
8
- /**
9
- * @module image/imagestyle/converters
10
- */
11
- /**
12
- * Returns a converter for the `imageStyle` attribute. It can be used for adding, changing and removing the attribute.
13
- *
14
- * @param styles An array containing available image style options.
15
- * @returns A model-to-view attribute converter.
16
- * @internal
17
- */
18
- export function modelToViewStyleAttribute(styles) {
19
- return (evt, data, conversionApi) => {
20
- if (!conversionApi.consumable.consume(data.item, evt.name)) {
21
- return;
22
- }
23
- // Check if there is class name associated with given value.
24
- const newStyle = getStyleDefinitionByName(data.attributeNewValue, styles);
25
- const oldStyle = getStyleDefinitionByName(data.attributeOldValue, styles);
26
- const viewElement = conversionApi.mapper.toViewElement(data.item);
27
- const viewWriter = conversionApi.writer;
28
- if (oldStyle) {
29
- viewWriter.removeClass(oldStyle.className, viewElement);
30
- }
31
- if (newStyle) {
32
- viewWriter.addClass(newStyle.className, viewElement);
33
- }
34
- };
35
- }
36
- /**
37
- * Returns a view-to-model converter converting image CSS classes to a proper value in the model.
38
- *
39
- * @param styles Image style options for which the converter is created.
40
- * @returns A view-to-model converter.
41
- * @internal
42
- */
43
- export function viewToModelStyleAttribute(styles) {
44
- // Convert only non–default styles.
45
- const nonDefaultStyles = {
46
- imageInline: styles.filter(style => !style.isDefault && style.modelElements.includes('imageInline')),
47
- imageBlock: styles.filter(style => !style.isDefault && style.modelElements.includes('imageBlock'))
48
- };
49
- return (evt, data, conversionApi) => {
50
- if (!data.modelRange) {
51
- return;
52
- }
53
- const viewElement = data.viewItem;
54
- const modelImageElement = first(data.modelRange.getItems());
55
- // Run this converter only if an image has been found in the model.
56
- // In some cases it may not be found (for example if we run this on a figure with different type than image).
57
- if (!modelImageElement) {
58
- return;
59
- }
60
- // ...and the `imageStyle` attribute is allowed for that element, otherwise stop conversion early.
61
- if (!conversionApi.schema.checkAttribute(modelImageElement, 'imageStyle')) {
62
- return;
63
- }
64
- // Convert styles one by one.
65
- for (const style of nonDefaultStyles[modelImageElement.name]) {
66
- // Try to consume class corresponding with the style.
67
- if (conversionApi.consumable.consume(viewElement, { classes: style.className })) {
68
- // And convert this style to model attribute.
69
- conversionApi.writer.setAttribute('imageStyle', style.name, modelImageElement);
70
- }
71
- }
72
- // Normalize float styles (alignLeft, alignRight).
73
- normalizeFloatToDefinitionStyle(conversionApi, viewElement, modelImageElement, styles);
74
- };
75
- }
76
- /**
77
- * A helper function that attempts to convert the `float` CSS style into a corresponding `imageStyle` attribute.
78
- *
79
- * It maps `float: left` and `float: right` to standard alignment styles (e.g. `'alignLeft'`, `'alignRight'`),
80
- * but only if the target style definition matches one of the {@link module:image/image/utils~DEFAULT_OPTIONS default options}.
81
- */
82
- function normalizeFloatToDefinitionStyle(conversionApi, viewElement, modelElement, styles) {
83
- if (!conversionApi.consumable.test(viewElement, { styles: ['float'] })) {
84
- return;
85
- }
86
- let floatStyleName = null;
87
- switch (viewElement.getStyle('float')) {
88
- case 'left':
89
- floatStyleName = 'alignLeft';
90
- break;
91
- case 'right':
92
- floatStyleName = 'alignRight';
93
- break;
94
- }
95
- if (!floatStyleName) {
96
- return;
97
- }
98
- const definition = getStyleDefinitionByName(floatStyleName, styles);
99
- if (!definition) {
100
- return;
101
- }
102
- const builtinDefinition = DEFAULT_OPTIONS[definition.name];
103
- if (!isEqual(definition, builtinDefinition)) {
104
- return;
105
- }
106
- conversionApi.writer.setAttribute('imageStyle', floatStyleName, modelElement);
107
- conversionApi.consumable.consume(viewElement, { styles: ['float'] });
108
- }
109
- /**
110
- * Returns the style with a given `name` from an array of styles.
111
- */
112
- function getStyleDefinitionByName(name, styles) {
113
- for (const style of styles) {
114
- if (style.name === name) {
115
- return style;
116
- }
117
- }
118
- }
@@ -1,117 +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
- import { Command } from 'ckeditor5/src/core.js';
6
- /**
7
- * The image style command. It is used to apply {@link module:image/imageconfig~ImageStyleConfig#options image style option}
8
- * to a selected image.
9
- *
10
- * **Note**: Executing this command may change the image model element if the desired style requires an image of a different
11
- * type. See {@link module:image/imagestyle/imagestylecommand~ImageStyleCommand#execute} to learn more.
12
- */
13
- export class ImageStyleCommand extends Command {
14
- /**
15
- * An object containing names of default style options for the inline and block images.
16
- * If there is no default style option for the given image type in the configuration,
17
- * the name will be `false`.
18
- */
19
- _defaultStyles;
20
- /**
21
- * The styles handled by this command.
22
- */
23
- _styles;
24
- /**
25
- * Creates an instance of the image style command. When executed, the command applies one of
26
- * {@link module:image/imageconfig~ImageStyleConfig#options style options} to the currently selected image.
27
- *
28
- * @param editor The editor instance.
29
- * @param styles The style options that this command supports.
30
- */
31
- constructor(editor, styles) {
32
- super(editor);
33
- this._defaultStyles = {
34
- imageBlock: false,
35
- imageInline: false
36
- };
37
- this._styles = new Map(styles.map(style => {
38
- if (style.isDefault) {
39
- for (const modelElementName of style.modelElements) {
40
- this._defaultStyles[modelElementName] = style.name;
41
- }
42
- }
43
- return [style.name, style];
44
- }));
45
- }
46
- /**
47
- * @inheritDoc
48
- */
49
- refresh() {
50
- const editor = this.editor;
51
- const imageUtils = editor.plugins.get('ImageUtils');
52
- const element = imageUtils.getClosestSelectedImageElement(this.editor.model.document.selection);
53
- this.isEnabled = !!element;
54
- if (!this.isEnabled) {
55
- this.value = false;
56
- }
57
- else if (element.hasAttribute('imageStyle')) {
58
- this.value = element.getAttribute('imageStyle');
59
- }
60
- else {
61
- this.value = this._defaultStyles[element.name];
62
- }
63
- }
64
- /**
65
- * Executes the command and applies the style to the currently selected image:
66
- *
67
- * ```ts
68
- * editor.execute( 'imageStyle', { value: 'side' } );
69
- * ```
70
- *
71
- * **Note**: Executing this command may change the image model element if the desired style requires an image
72
- * of a different type. Learn more about {@link module:image/imageconfig~ImageStyleOptionDefinition#modelElements model element}
73
- * configuration for the style option.
74
- *
75
- * @param options.value The name of the style (as configured in {@link module:image/imageconfig~ImageStyleConfig#options}).
76
- * @param options.setImageSizes Specifies whether the image `width` and `height` attributes should be set automatically.
77
- * The default is `true`.
78
- * @fires execute
79
- */
80
- execute(options = {}) {
81
- const editor = this.editor;
82
- const model = editor.model;
83
- const imageUtils = editor.plugins.get('ImageUtils');
84
- model.change(writer => {
85
- const requestedStyle = options.value;
86
- const { setImageSizes = true } = options;
87
- let imageElement = imageUtils.getClosestSelectedImageElement(model.document.selection);
88
- // Change the image type if a style requires it.
89
- if (requestedStyle && this.shouldConvertImageType(requestedStyle, imageElement)) {
90
- this.editor.execute(imageUtils.isBlockImage(imageElement) ? 'imageTypeInline' : 'imageTypeBlock', { setImageSizes });
91
- // Update the imageElement to the newly created image.
92
- imageElement = imageUtils.getClosestSelectedImageElement(model.document.selection);
93
- }
94
- // Default style means that there is no `imageStyle` attribute in the model.
95
- // https://github.com/ckeditor/ckeditor5-image/issues/147
96
- if (!requestedStyle || this._styles.get(requestedStyle).isDefault) {
97
- writer.removeAttribute('imageStyle', imageElement);
98
- }
99
- else {
100
- writer.setAttribute('imageStyle', requestedStyle, imageElement);
101
- }
102
- if (setImageSizes) {
103
- imageUtils.setImageNaturalSizeAttributes(imageElement);
104
- }
105
- });
106
- }
107
- /**
108
- * Returns `true` if requested style change would trigger the image type change.
109
- *
110
- * @param requestedStyle The name of the style (as configured in {@link module:image/imageconfig~ImageStyleConfig#options}).
111
- * @param imageElement The image model element.
112
- */
113
- shouldConvertImageType(requestedStyle, imageElement) {
114
- const supportedTypes = this._styles.get(requestedStyle).modelElements;
115
- return !supportedTypes.includes(imageElement.name);
116
- }
117
- }
@@ -1,127 +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 image/imagestyle/imagestyleediting
7
- */
8
- import { Plugin } from 'ckeditor5/src/core.js';
9
- import { ImageStyleCommand } from './imagestylecommand.js';
10
- import { ImageUtils } from '../imageutils.js';
11
- import { utils } from './utils.js';
12
- import { viewToModelStyleAttribute, modelToViewStyleAttribute } from './converters.js';
13
- /**
14
- * The image style engine plugin. It sets the default configuration, creates converters and registers
15
- * {@link module:image/imagestyle/imagestylecommand~ImageStyleCommand ImageStyleCommand}.
16
- */
17
- export class ImageStyleEditing extends Plugin {
18
- /**
19
- * @inheritDoc
20
- */
21
- static get pluginName() {
22
- return 'ImageStyleEditing';
23
- }
24
- /**
25
- * @inheritDoc
26
- */
27
- static get isOfficialPlugin() {
28
- return true;
29
- }
30
- /**
31
- * @inheritDoc
32
- */
33
- static get requires() {
34
- return [ImageUtils];
35
- }
36
- /**
37
- * It contains a list of the normalized and validated style options.
38
- *
39
- * * Each option contains a complete icon markup.
40
- * * The style options not supported by any of the loaded image editing plugins (
41
- * {@link module:image/image/imageinlineediting~ImageInlineEditing `ImageInlineEditing`} or
42
- * {@link module:image/image/imageblockediting~ImageBlockEditing `ImageBlockEditing`}) are filtered out.
43
- *
44
- * @internal
45
- * @readonly
46
- */
47
- normalizedStyles;
48
- /**
49
- * @inheritDoc
50
- */
51
- init() {
52
- const editor = this.editor;
53
- const isBlockPluginLoaded = editor.plugins.has('ImageBlockEditing');
54
- const isInlinePluginLoaded = editor.plugins.has('ImageInlineEditing');
55
- editor.config.define('image.styles', utils.getDefaultStylesConfiguration(isBlockPluginLoaded, isInlinePluginLoaded));
56
- this.normalizedStyles = utils.normalizeStyles({
57
- configuredStyles: editor.config.get('image.styles'),
58
- isBlockPluginLoaded,
59
- isInlinePluginLoaded
60
- });
61
- this._setupConversion(isBlockPluginLoaded, isInlinePluginLoaded);
62
- this._setupPostFixer();
63
- // Register imageStyle command.
64
- editor.commands.add('imageStyle', new ImageStyleCommand(editor, this.normalizedStyles));
65
- }
66
- /**
67
- * Sets the editor conversion taking the presence of
68
- * {@link module:image/image/imageinlineediting~ImageInlineEditing `ImageInlineEditing`}
69
- * and {@link module:image/image/imageblockediting~ImageBlockEditing `ImageBlockEditing`} plugins into consideration.
70
- */
71
- _setupConversion(isBlockPluginLoaded, isInlinePluginLoaded) {
72
- const editor = this.editor;
73
- const schema = editor.model.schema;
74
- const modelToViewConverter = modelToViewStyleAttribute(this.normalizedStyles);
75
- const viewToModelConverter = viewToModelStyleAttribute(this.normalizedStyles);
76
- editor.editing.downcastDispatcher.on('attribute:imageStyle', modelToViewConverter);
77
- editor.data.downcastDispatcher.on('attribute:imageStyle', modelToViewConverter);
78
- // Allow imageStyle attribute in image and imageInline.
79
- // We could call it 'style' but https://github.com/ckeditor/ckeditor5-engine/issues/559.
80
- if (isBlockPluginLoaded) {
81
- schema.extend('imageBlock', { allowAttributes: 'imageStyle' });
82
- schema.setAttributeProperties('imageStyle', { isFormatting: true });
83
- // Converter for figure element from view to model.
84
- editor.data.upcastDispatcher.on('element:figure', viewToModelConverter, { priority: 'low' });
85
- }
86
- if (isInlinePluginLoaded) {
87
- schema.extend('imageInline', { allowAttributes: 'imageStyle' });
88
- schema.setAttributeProperties('imageStyle', { isFormatting: true });
89
- // Converter for the img element from view to model.
90
- editor.data.upcastDispatcher.on('element:img', viewToModelConverter, { priority: 'low' });
91
- }
92
- }
93
- /**
94
- * Registers a post-fixer that will make sure that the style attribute value is correct for a specific image type (block vs inline).
95
- */
96
- _setupPostFixer() {
97
- const editor = this.editor;
98
- const document = editor.model.document;
99
- const imageUtils = editor.plugins.get(ImageUtils);
100
- const stylesMap = new Map(this.normalizedStyles.map(style => [style.name, style]));
101
- // Make sure that style attribute is valid for the image type.
102
- document.registerPostFixer(writer => {
103
- let changed = false;
104
- for (const change of document.differ.getChanges()) {
105
- if (change.type == 'insert' || change.type == 'attribute' && change.attributeKey == 'imageStyle') {
106
- let element = change.type == 'insert' ? change.position.nodeAfter : change.range.start.nodeAfter;
107
- if (element && element.is('element', 'paragraph') && element.childCount > 0) {
108
- element = element.getChild(0);
109
- }
110
- if (!imageUtils.isImage(element)) {
111
- continue;
112
- }
113
- const imageStyle = element.getAttribute('imageStyle');
114
- if (!imageStyle) {
115
- continue;
116
- }
117
- const imageStyleDefinition = stylesMap.get(imageStyle);
118
- if (!imageStyleDefinition || !imageStyleDefinition.modelElements.includes(element.name)) {
119
- writer.removeAttribute('imageStyle', element);
120
- changed = true;
121
- }
122
- }
123
- }
124
- return changed;
125
- });
126
- }
127
- }