facade.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. var L = Object.defineProperty;
  2. var X = (r, t, e) => t in r ? L(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
  3. var T = (r, t, e) => X(r, typeof t != "symbol" ? t + "" : t, e);
  4. import { Inject as x, Injector as P, ICommandService as W, generateRandomId as Y, DrawingTypeEnum as _, ImageSourceType as I, FBase as V, ArrangeTypeEnum as v, toDisposable as C, FEnum as M, FEventName as z, FUniver as N } from "@univerjs/core";
  5. import { getImageSize as q, SetDrawingSelectedOperation as A, IDrawingManagerService as l } from "@univerjs/drawing";
  6. import { IRenderManagerService as F } from "@univerjs/engine-render";
  7. import { SetSheetDrawingCommand as m, SetDrawingArrangeCommand as w, SheetCanvasFloatDomManagerService as G, InsertSheetDrawingCommand as S, RemoveSheetDrawingCommand as D } from "@univerjs/sheets-drawing-ui";
  8. import { SheetSkeletonManagerService as U, ISheetSelectionRenderService as J, convertPositionSheetOverGridToAbsolute as Q, convertPositionCellToSheetOverGrid as Z } from "@univerjs/sheets-ui";
  9. import { ISheetDrawingService as u, SheetDrawingAnchorType as ee } from "@univerjs/sheets-drawing";
  10. import { transformComponentKey as E } from "@univerjs/sheets-ui/facade";
  11. import { FWorksheet as $ } from "@univerjs/sheets/facade";
  12. import { ComponentManager as y } from "@univerjs/ui";
  13. var te = Object.defineProperty, ie = Object.getOwnPropertyDescriptor, H = (r, t, e, i) => {
  14. for (var n = i > 1 ? void 0 : i ? ie(t, e) : t, s = r.length - 1, o; s >= 0; s--)
  15. (o = r[s]) && (n = (i ? o(t, e, n) : o(n)) || n);
  16. return i && n && te(t, e, n), n;
  17. }, R = (r, t) => (e, i) => t(e, i, r);
  18. function re(r, t) {
  19. const { from: e, to: i, flipY: n = !1, flipX: s = !1, angle: o = 0, skewX: c = 0, skewY: a = 0 } = r.sheetTransform, { column: h, columnOffset: d, row: f, rowOffset: p } = e, k = Q(
  20. r.unitId,
  21. r.subUnitId,
  22. { from: e, to: i },
  23. t
  24. ), { left: B, top: j, width: O, height: K } = k;
  25. return {
  26. ...r,
  27. column: h,
  28. columnOffset: d,
  29. row: f,
  30. rowOffset: p,
  31. width: O,
  32. height: K,
  33. flipY: n,
  34. flipX: s,
  35. angle: o,
  36. skewX: c,
  37. skewY: a
  38. };
  39. }
  40. function ne(r, t, e) {
  41. const { column: i, columnOffset: n, row: s, rowOffset: o, flipY: c = !1, flipX: a = !1, angle: h = 0, skewX: d = 0, skewY: f = 0, width: p, height: k } = r, B = Z(
  42. r.unitId,
  43. r.subUnitId,
  44. { column: i, columnOffset: n, row: s, rowOffset: o },
  45. p,
  46. k,
  47. t,
  48. e
  49. ), { sheetTransform: j, transform: O } = B;
  50. return {
  51. ...r,
  52. sheetTransform: {
  53. ...j,
  54. flipY: c,
  55. flipX: a,
  56. angle: h,
  57. skewX: d,
  58. skewY: f
  59. },
  60. transform: {
  61. ...O,
  62. flipY: c,
  63. flipX: a,
  64. angle: h,
  65. skewX: d,
  66. skewY: f
  67. }
  68. };
  69. }
  70. let b = class {
  71. constructor(r, t, e) {
  72. T(this, "_image");
  73. this._injector = e, this._image = {
  74. drawingId: Y(6),
  75. drawingType: _.DRAWING_IMAGE,
  76. imageSourceType: I.BASE64,
  77. source: "",
  78. unitId: r,
  79. subUnitId: t,
  80. column: 0,
  81. columnOffset: 0,
  82. row: 0,
  83. rowOffset: 0,
  84. width: 0,
  85. height: 0
  86. };
  87. }
  88. /**
  89. * Set the initial image configuration for the image builder.
  90. * @param image The image to be set. {@link ISheetImage}
  91. * @returns The builder. {@link FOverGridImageBuilder}
  92. * @example
  93. * ```ts
  94. * // create a new image builder.
  95. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  96. * const activeSheet = activeSpreadsheet.getActiveSheet();
  97. * const imageBuilder = activeSheet.newOverGridImage();
  98. * const param = await imageBuilder.setImage({
  99. * drawingId: '123456',
  100. * drawingType: univerAPI.Enum.DrawingType.DRAWING_IMAGE,
  101. * imageSourceType: univerAPI.Enum.ImageSourceType.BASE64,
  102. * source: 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4',
  103. * unitId: activeSpreadsheet.getId(),
  104. * subUnitId: activeSheet.getSheetId(),
  105. * }).setColumn(5).setRow(5).buildAsync();
  106. * activeSheet.insertImages([param]);
  107. * ```
  108. */
  109. setImage(r) {
  110. const e = this._injector.get(F).getRenderById(r.unitId);
  111. if (!e)
  112. throw new Error(`Render Unit with unitId ${r.unitId} not found`);
  113. const i = e.with(U);
  114. return r.sheetTransform == null && (r.sheetTransform = {
  115. from: {
  116. column: 0,
  117. columnOffset: 0,
  118. row: 0,
  119. rowOffset: 0
  120. },
  121. to: {
  122. column: 0,
  123. columnOffset: 0,
  124. row: 0,
  125. rowOffset: 0
  126. }
  127. }), this._image = re(r, i), this;
  128. }
  129. setSource(r, t) {
  130. const e = t != null ? t : I.URL;
  131. return this._image.source = r, this._image.imageSourceType = e, this;
  132. }
  133. getsource() {
  134. return this._image.source;
  135. }
  136. getSourceType() {
  137. return this._image.imageSourceType;
  138. }
  139. /**
  140. * Set the position of the image
  141. * @param column The sheet start column of the image
  142. * @returns The builder. {@link FOverGridImageBuilder}
  143. * @example
  144. * ```ts
  145. * // create a new image builder.
  146. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  147. * const activeSheet = activeSpreadsheet.getActiveSheet();
  148. * const imageBuilder = activeSheet.newOverGridImage();
  149. * const param = await imageBuilder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).buildAsync();
  150. * activeSheet.insertImages([param]);
  151. * ```
  152. */
  153. setColumn(r) {
  154. return this._image.column = r, this;
  155. }
  156. /**
  157. * Set the position of the image
  158. * @param row The sheet start row of the image
  159. * @returns The builder. {@link FOverGridImageBuilder}
  160. * @example
  161. * ```ts
  162. * // create a new image builder.
  163. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  164. * const activeSheet = activeSpreadsheet.getActiveSheet();
  165. * const imageBuilder = activeSheet.newOverGridImage();
  166. * const param = await imageBuilder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).buildAsync();
  167. * activeSheet.insertImages([param]);
  168. * ```
  169. */
  170. setRow(r) {
  171. return this._image.row = r, this;
  172. }
  173. /**
  174. * Set the column offset of the image in a unit
  175. * @param offset The offset in pixels
  176. * @returns The builder. {@link FOverGridImageBuilder}
  177. * @example
  178. * ```ts
  179. * // create a new image builder.
  180. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  181. * const activeSheet = activeSpreadsheet.getActiveSheet();
  182. * const imageBuilder = activeSheet.newOverGridImage();
  183. * const param = await imageBuilder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).setColumnOffset(10).setRowOffset(10).buildAsync();
  184. * activeSheet.insertImages([param]);
  185. * ```
  186. */
  187. setColumnOffset(r) {
  188. return this._image.columnOffset = r, this;
  189. }
  190. /**
  191. * Set the row offset of the image in a unit
  192. * @param offset The offset in pixels
  193. * @returns The builder. {@link FOverGridImageBuilder}
  194. * @example
  195. * ```ts
  196. * // create a new image builder.
  197. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  198. * const activeSheet = activeSpreadsheet.getActiveSheet();
  199. * const imageBuilder = activeSheet.newOverGridImage();
  200. * const param = await imageBuilder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).setColumnOffset(10).setRowOffset(10).buildAsync();
  201. * activeSheet.insertImages([param]);
  202. * ```
  203. */
  204. setRowOffset(r) {
  205. return this._image.rowOffset = r, this;
  206. }
  207. /**
  208. * set the width of the image
  209. * @param width The width of the image, in pixels
  210. * @returns The builder. {@link FOverGridImageBuilder}
  211. * @example
  212. * ```ts
  213. * // create a new image builder.
  214. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  215. * const activeSheet = activeSpreadsheet.getActiveSheet();
  216. * const imageBuilder = activeSheet.newOverGridImage();
  217. * const param = await imageBuilder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).setWidth(120).setHeight(50).buildAsync();
  218. * activeSheet.insertImages([param]);
  219. * ```
  220. */
  221. setWidth(r) {
  222. return this._image.width = r, this;
  223. }
  224. /**
  225. * Set the height of the image
  226. * @param height The height of the image, in pixels
  227. * @returns The builder. {@link FOverGridImageBuilder}
  228. * @example
  229. * ```ts
  230. * // create a new image builder.
  231. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  232. * const activeSheet = activeSpreadsheet.getActiveSheet();
  233. * const imageBuilder = activeSheet.newOverGridImage();
  234. * const param = await imageBuilder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).setWidth(120).setHeight(50).buildAsync();
  235. * activeSheet.insertImages([param]);
  236. * ```
  237. */
  238. setHeight(r) {
  239. return this._image.height = r, this;
  240. }
  241. /**
  242. * Set the anchor type of the image, whether the position and size change with the cell
  243. * @param anchorType The anchor type {@link SheetDrawingAnchorType}
  244. * @returns The builder. {@link FOverGridImageBuilder}
  245. * @example
  246. * ```ts
  247. * // create a new image builder.
  248. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  249. * const activeSheet = activeSpreadsheet.getActiveSheet();
  250. * const imageBuilder = activeSheet.newOverGridImage();
  251. * const param = await imageBuilder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).setAnchorType(univerAPI.Enum.SheetDrawingAnchorType.None).buildAsync();
  252. * activeSheet.insertImages([param]);
  253. * ```
  254. */
  255. setAnchorType(r) {
  256. return this._image.anchorType = r, this;
  257. }
  258. /**
  259. * Set the cropping region of the image by defining the top edges, thereby displaying the specific part of the image you want.
  260. * @param top The number of pixels to crop from the top of the image.
  261. * @returns The builder. {@link FOverGridImageBuilder}
  262. * @example
  263. * ```ts
  264. * // create a new image builder.
  265. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  266. * const activeSheet = activeSpreadsheet.getActiveSheet();
  267. * const imageBuilder = activeSheet.newOverGridImage();
  268. * const param = await imageBuilder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).setCropTop(10).setCropLeft(10).setCropBottom(10).setCropRight(10).buildAsync();
  269. * activeSheet.insertImages([param]);
  270. * ```
  271. */
  272. setCropTop(r) {
  273. return this._initializeSrcRect(), this._image.srcRect.top = r, this;
  274. }
  275. /**
  276. * Set the cropping region of the image by defining the left edges, thereby displaying the specific part of the image you want.
  277. * @param left The number of pixels to crop from the left side of the image.
  278. * @returns The builder. {@link FOverGridImageBuilder}
  279. * @example
  280. * ```ts
  281. * // create a new image builder.
  282. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  283. * const activeSheet = activeSpreadsheet.getActiveSheet();
  284. * const imageBuilder = activeSheet.newOverGridImage();
  285. * const param = await imageBuilder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).setCropTop(10).setCropLeft(10).setCropBottom(10).setCropRight(10).buildAsync();
  286. * activeSheet.insertImages([param]);
  287. * ```
  288. */
  289. setCropLeft(r) {
  290. return this._initializeSrcRect(), this._image.srcRect.left = r, this;
  291. }
  292. /**
  293. * Set the cropping region of the image by defining the bottom edges, thereby displaying the specific part of the image you want.
  294. * @param bottom The number of pixels to crop from the bottom of the image.
  295. * @returns The builder. {@link FOverGridImageBuilder}
  296. * @example
  297. * ```ts
  298. * // create a new image builder.
  299. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  300. * const activeSheet = activeSpreadsheet.getActiveSheet();
  301. * const imageBuilder = activeSheet.newOverGridImage();
  302. * const param = await imageBuilder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).setCropTop(10).setCropLeft(10).setCropBottom(10).setCropRight(10).buildAsync();
  303. * activeSheet.insertImages([param]);
  304. * ```
  305. */
  306. setCropBottom(r) {
  307. return this._initializeSrcRect(), this._image.srcRect.bottom = r, this;
  308. }
  309. /**
  310. * Set the cropping region of the image by defining the right edges, thereby displaying the specific part of the image you want.
  311. * @param right The number of pixels to crop from the right side of the image.
  312. * @returns The builder. {@link FOverGridImageBuilder}
  313. * @example
  314. * ```ts
  315. * // create a new image builder.
  316. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  317. * const activeSheet = activeSpreadsheet.getActiveSheet();
  318. * const imageBuilder = activeSheet.newOverGridImage();
  319. * const param = await imageBuilder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).setCropTop(10).setCropLeft(10).setCropBottom(10).setCropRight(10).buildAsync();
  320. * activeSheet.insertImages([param]);
  321. * ```
  322. */
  323. setCropRight(r) {
  324. return this._initializeSrcRect(), this._image.srcRect.right = r, this;
  325. }
  326. _initializeSrcRect() {
  327. this._image.srcRect == null && (this._image.srcRect = {
  328. top: 0,
  329. left: 0,
  330. bottom: 0,
  331. right: 0
  332. });
  333. }
  334. /**
  335. * Set the rotation angle of the image
  336. * @param angle Degree of rotation of the image, for example, 90, 180, 270, etc.
  337. * @returns The builder {@link FOverGridImageBuilder}
  338. * @example
  339. * ```ts
  340. * // create a new image builder.
  341. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  342. * const activeSheet = activeSpreadsheet.getActiveSheet();
  343. * const imageBuilder = activeSheet.newOverGridImage();
  344. * const param = await imageBuilder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).setRotate(90).buildAsync();
  345. * activeSheet.insertImages([param]);
  346. * ```
  347. */
  348. setRotate(r) {
  349. return this._image.angle = r, this;
  350. }
  351. // setPresetGeometry(prstGeom: PresetGeometryType): FOverGridImageBuilder {
  352. // this._image.prstGeom = prstGeom;
  353. // return this;
  354. // }
  355. setUnitId(r) {
  356. return this._image.unitId = r, this;
  357. }
  358. setSubUnitId(r) {
  359. return this._image.subUnitId = r, this;
  360. }
  361. async buildAsync() {
  362. const t = this._injector.get(F).getRenderById(this._image.unitId);
  363. if (!t)
  364. throw new Error(`Render Unit with unitId ${this._image.unitId} not found`);
  365. const e = t.with(J), i = t.with(U);
  366. if (this._image.width === 0 || this._image.height === 0) {
  367. const n = await q(this._image.source), s = n.width, o = n.height;
  368. this._image.width === 0 && (this._image.width = s), this._image.height === 0 && (this._image.height = o);
  369. }
  370. return ne(this._image, e, i);
  371. }
  372. };
  373. b = H([
  374. R(2, x(P))
  375. ], b);
  376. let g = class extends V {
  377. constructor(r, t, e) {
  378. super(), this._image = r, this._commandService = t, this._injector = e;
  379. }
  380. getId() {
  381. return this._image.drawingId;
  382. }
  383. getType() {
  384. return this._image.drawingType;
  385. }
  386. /**
  387. * Remove the image from the sheet
  388. * @returns success or not
  389. * @example
  390. * ```ts
  391. * // remove the image from the sheet
  392. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  393. * const activeSheet = activeSpreadsheet.getActiveSheet();
  394. * const image = activeSheet.getImages()[0];
  395. * console.log('Delete state is ', image?.remove());
  396. * ```
  397. */
  398. remove() {
  399. return this._commandService.syncExecuteCommand(m.id, { unitId: this._image.unitId, drawings: [this._image] });
  400. }
  401. /**
  402. * Convert the image to a FOverGridImageBuilder
  403. * @returns The builder FOverGridImageBuilder
  404. * @example
  405. * ```ts
  406. * // convert the image to a builder
  407. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  408. * const activeSheet = activeSpreadsheet.getActiveSheet();
  409. * const image = activeSheet.getImages()[0];
  410. * const builder = image.toBuilder();
  411. * const param = await builder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).buildAsync();
  412. * activeSheet.updateImages([param]);
  413. * ```
  414. */
  415. toBuilder() {
  416. const r = this._injector.createInstance(b);
  417. return r.setImage(this._image), r;
  418. }
  419. setSource(r, t) {
  420. const e = t != null ? t : I.URL;
  421. return this._image.source = r, this._image.imageSourceType = e, this._commandService.syncExecuteCommand(m.id, { unitId: this._image.unitId, drawings: [this._image] });
  422. }
  423. async setPositionAsync(r, t, e, i) {
  424. const n = this.toBuilder();
  425. n.setColumn(t), n.setRow(r), e != null && n.setRowOffset(e), i != null && n.setColumnOffset(i);
  426. const s = await n.buildAsync();
  427. return this._commandService.syncExecuteCommand(m.id, { unitId: this._image.unitId, drawings: [s] });
  428. }
  429. /**
  430. * Set the size of the image
  431. * @param width The width of the image
  432. * @param height The height of the image
  433. * @returns success or not
  434. * @example
  435. * ```ts
  436. * // set the size of the image
  437. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  438. * const activeSheet = activeSpreadsheet.getActiveSheet();
  439. * const image = activeSheet.getImages()[0];
  440. * console.log('Set size state is ', image.setSize(50, 120));
  441. */
  442. async setSizeAsync(r, t) {
  443. const e = this.toBuilder();
  444. e.setWidth(r), e.setHeight(t);
  445. const i = await e.buildAsync();
  446. return this._commandService.syncExecuteCommand(m.id, { unitId: this._image.unitId, drawings: [i] });
  447. }
  448. /**
  449. * Set the cropping region of the image by defining the top, bottom, left, and right edges, thereby displaying the specific part of the image you want.
  450. * @param top The number of pixels to crop from the top of the image.
  451. * @param left The number of pixels to crop from the left side of the image.
  452. * @param bottom The number of pixels to crop from the bottom of the image.
  453. * @param right The number of pixels to crop from the right side of the image.
  454. * @returns success or not
  455. * @example
  456. * ```ts
  457. * // set the crop of the image
  458. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  459. * const activeSheet = activeSpreadsheet.getActiveSheet();
  460. * const image = activeSheet.getImages()[0];
  461. * console.log('Set crop state is ', image.setCrop(10, 10, 10, 10));
  462. * ```
  463. */
  464. setCrop(r, t, e, i) {
  465. return this._image.srcRect == null && (this._image.srcRect = {
  466. top: 0,
  467. left: 0,
  468. bottom: 0,
  469. right: 0
  470. }), r != null && (this._image.srcRect.top = r), t != null && (this._image.srcRect.left = t), e != null && (this._image.srcRect.bottom = e), i != null && (this._image.srcRect.right = i), this._commandService.syncExecuteCommand(m.id, { unitId: this._image.unitId, drawings: [this._image] });
  471. }
  472. // setPresetGeometry(prstGeom: PresetGeometryType): boolean {
  473. // this._image.prstGeom = prstGeom;
  474. // return this._commandService.syncExecuteCommand(SetSheetDrawingCommand.id, { unitId: this._image.unitId, drawings: [this._image] });
  475. // }
  476. /**
  477. * Set the rotation angle of the image
  478. * @param angle Degree of rotation of the image, for example, 90, 180, 270, etc.
  479. * @returns success or not
  480. * @example
  481. * ```ts
  482. * // set the rotation angle of the image
  483. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  484. * const activeSheet = activeSpreadsheet.getActiveSheet();
  485. * const image = activeSheet.getImages()[0];
  486. * console.log('Set rotate state is ', image.setRotate(90));
  487. * ```
  488. */
  489. setRotate(r) {
  490. return this._image.sheetTransform.angle = r, this._commandService.syncExecuteCommand(m.id, { unitId: this._image.unitId, drawings: [this._image] });
  491. }
  492. /**
  493. * Move the image layer forward by one level
  494. * @returns success or not
  495. * @example
  496. * ```ts
  497. * // move the image forward
  498. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  499. * const activeSheet = activeSpreadsheet.getActiveSheet();
  500. * const image = activeSheet.getImages()[0];
  501. * console.log('Move forward state is ', image.setForward());
  502. * ```
  503. */
  504. setForward() {
  505. return this._commandService.syncExecuteCommand(w.id, {
  506. unitId: this._image.unitId,
  507. subUnitId: this._image.subUnitId,
  508. drawingIds: [this._image.drawingId],
  509. arrangeType: v.forward
  510. });
  511. }
  512. /**
  513. * Move the image layer backward by one level
  514. * @returns success or not
  515. * @example
  516. * ```ts
  517. * // move the image backward
  518. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  519. * const activeSheet = activeSpreadsheet.getActiveSheet();
  520. * const image = activeSheet.getImages()[0];
  521. * console.log('Move backward state is ', image.setBackward());
  522. * ```
  523. */
  524. setBackward() {
  525. return this._commandService.syncExecuteCommand(w.id, {
  526. unitId: this._image.unitId,
  527. subUnitId: this._image.subUnitId,
  528. drawingIds: [this._image.drawingId],
  529. arrangeType: v.backward
  530. });
  531. }
  532. /**
  533. * Move the image layer to the back
  534. * @returns success or not
  535. * @example
  536. * ```ts
  537. * // move the image to the back
  538. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  539. * const activeSheet = activeSpreadsheet.getActiveSheet();
  540. * const image = activeSheet.getImages()[0];
  541. * console.log('Move back state is ', image.setBack());
  542. * ```
  543. */
  544. setBack() {
  545. return this._commandService.syncExecuteCommand(w.id, {
  546. unitId: this._image.unitId,
  547. subUnitId: this._image.subUnitId,
  548. drawingIds: [this._image.drawingId],
  549. arrangeType: v.back
  550. });
  551. }
  552. /**
  553. * Move the image layer to the front
  554. * @returns success or not
  555. * @example
  556. * ```ts
  557. * // move the image to the front
  558. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  559. * const activeSheet = activeSpreadsheet.getActiveSheet();
  560. * const image = activeSheet.getImages()[0];
  561. * console.log('Move front state is ', image.setFront());
  562. * ```
  563. */
  564. setFront() {
  565. return this._commandService.syncExecuteCommand(w.id, {
  566. unitId: this._image.unitId,
  567. subUnitId: this._image.subUnitId,
  568. drawingIds: [this._image.drawingId],
  569. arrangeType: v.front
  570. });
  571. }
  572. };
  573. g = H([
  574. R(1, W),
  575. R(2, x(P))
  576. ], g);
  577. class se extends $ {
  578. addFloatDomToPosition(t, e) {
  579. const i = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), { key: s, disposableCollection: o } = E(t, this._injector.get(y)), a = this._injector.get(G).addFloatDomToPosition({ ...t, componentKey: s, unitId: i, subUnitId: n }, e);
  580. return a ? (o.add(a.dispose), {
  581. id: a.id,
  582. dispose: () => {
  583. o.dispose(), a.dispose();
  584. }
  585. }) : (o.dispose(), null);
  586. }
  587. addFloatDomToRange(t, e, i, n) {
  588. const s = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), { key: c, disposableCollection: a } = E(e, this._injector.get(y)), d = this._injector.get(G).addFloatDomToRange(t.getRange(), { ...e, componentKey: c, unitId: s, subUnitId: o }, i, n);
  589. return d ? (a.add(d.dispose), {
  590. id: d.id,
  591. dispose: () => {
  592. a.dispose(), d.dispose();
  593. }
  594. }) : (a.dispose(), null);
  595. }
  596. addFloatDomToColumnHeader(t, e, i, n) {
  597. const s = this._workbook.getUnitId(), o = this._worksheet.getSheetId(), { key: c, disposableCollection: a } = E(e, this._injector.get(y)), d = this._injector.get(G).addFloatDomToColumnHeader(t, { ...e, componentKey: c, unitId: s, subUnitId: o }, i, n);
  598. return d ? (a.add(d.dispose), {
  599. id: d.id,
  600. dispose: () => {
  601. a.dispose(), d.dispose();
  602. }
  603. }) : (a.dispose(), null);
  604. }
  605. async insertImage(t, e, i, n, s) {
  606. const o = this.newOverGridImage();
  607. if (typeof t == "string")
  608. o.setSource(t);
  609. else {
  610. const h = await t.getBlob().getDataAsString();
  611. o.setSource(h, I.BASE64);
  612. }
  613. e !== void 0 ? o.setColumn(e) : o.setColumn(0), i !== void 0 ? o.setRow(i) : o.setRow(0), n !== void 0 ? o.setColumnOffset(n) : o.setColumnOffset(0), s !== void 0 ? o.setRowOffset(s) : o.setRowOffset(0);
  614. const c = await o.buildAsync();
  615. return this._commandService.syncExecuteCommand(S.id, { unitId: this._fWorkbook.getId(), drawings: [c] });
  616. }
  617. insertImages(t) {
  618. const e = t.map((i) => (i.unitId = this._fWorkbook.getId(), i.subUnitId = this.getSheetId(), i));
  619. return this._commandService.syncExecuteCommand(S.id, { unitId: this._fWorkbook.getId(), drawings: e }), this;
  620. }
  621. deleteImages(t) {
  622. const e = t.map((i) => ({
  623. unitId: this._fWorkbook.getId(),
  624. drawingId: i.getId(),
  625. subUnitId: this.getSheetId(),
  626. drawingType: i.getType()
  627. }));
  628. return this._commandService.syncExecuteCommand(D.id, { unitId: this._fWorkbook.getId(), drawings: e }), this;
  629. }
  630. getImages() {
  631. const e = this._injector.get(u).getDrawingData(this._fWorkbook.getId(), this.getSheetId()), i = [];
  632. for (const n in e) {
  633. const s = e[n];
  634. s.drawingType === _.DRAWING_IMAGE && i.push(this._injector.createInstance(g, s));
  635. }
  636. return i;
  637. }
  638. getImageById(t) {
  639. const i = this._injector.get(u).getDrawingByParam({ unitId: this._fWorkbook.getId(), subUnitId: this.getSheetId(), drawingId: t });
  640. return i && i.drawingType === _.DRAWING_IMAGE ? this._injector.createInstance(g, i) : null;
  641. }
  642. getActiveImages() {
  643. const e = this._injector.get(u).getFocusDrawings(), i = [];
  644. for (const n in e) {
  645. const s = e[n];
  646. i.push(this._injector.createInstance(g, s));
  647. }
  648. return i;
  649. }
  650. updateImages(t) {
  651. return this._commandService.syncExecuteCommand(m.id, { unitId: this._fWorkbook.getId(), drawings: t }), this;
  652. }
  653. onImageInserted(t) {
  654. const e = this._injector.get(u);
  655. return C(e.add$.subscribe((i) => {
  656. const n = i.map(
  657. (s) => this._injector.createInstance(g, e.getDrawingByParam(s))
  658. );
  659. t(n);
  660. }));
  661. }
  662. onImageDeleted(t) {
  663. const e = this._injector.get(u);
  664. return C(e.remove$.subscribe((i) => {
  665. const n = i.map(
  666. (s) => this._injector.createInstance(g, e.getDrawingByParam(s))
  667. );
  668. t(n);
  669. }));
  670. }
  671. onImageChanged(t) {
  672. const e = this._injector.get(u);
  673. return C(e.update$.subscribe((i) => {
  674. const n = i.map(
  675. (s) => this._injector.createInstance(g, e.getDrawingByParam(s))
  676. );
  677. t(n);
  678. }));
  679. }
  680. newOverGridImage() {
  681. const t = this._fWorkbook.getId(), e = this.getSheetId();
  682. return this._injector.createInstance(b, t, e);
  683. }
  684. }
  685. $.extend(se);
  686. class oe extends M {
  687. get DrawingType() {
  688. return _;
  689. }
  690. get ImageSourceType() {
  691. return I;
  692. }
  693. get SheetDrawingAnchorType() {
  694. return ee;
  695. }
  696. }
  697. M.extend(oe);
  698. class ae extends z {
  699. get BeforeOverGridImageChange() {
  700. return "BeforeOverGridImageChange";
  701. }
  702. get OverGridImageChanged() {
  703. return "OverGridImageChanged";
  704. }
  705. get BeforeOverGridImageInsert() {
  706. return "BeforeOverGridImageInsert";
  707. }
  708. get OverGridImageInserted() {
  709. return "OverGridImageInserted";
  710. }
  711. get BeforeOverGridImageRemove() {
  712. return "BeforeOverGridImageRemove";
  713. }
  714. get OverGridImageRemoved() {
  715. return "OverGridImageRemoved";
  716. }
  717. get BeforeOverGridImageSelect() {
  718. return "BeforeOverGridImageSelect";
  719. }
  720. get OverGridImageSelected() {
  721. return "OverGridImageSelected";
  722. }
  723. }
  724. z.extend(ae);
  725. class ce extends N {
  726. _initialize(t) {
  727. const e = t.get(W);
  728. this.disposeWithMe(e.beforeCommandExecuted((i) => {
  729. switch (i.id) {
  730. case S.id:
  731. this._beforeOverGridImageInsert(i.params);
  732. break;
  733. case D.id:
  734. this._beforeOverGridImageRemove(i.params);
  735. break;
  736. case m.id:
  737. this._beforeOverGridImageChange(i.params);
  738. break;
  739. case A.id:
  740. this._beforeOverGridImageSelect(i.params);
  741. break;
  742. }
  743. })), this.disposeWithMe(e.onCommandExecuted((i) => {
  744. switch (i.id) {
  745. case S.id:
  746. this._overGridImageInserted(i.params);
  747. break;
  748. case D.id:
  749. this._overGridImageRemoved(i.params);
  750. break;
  751. case m.id:
  752. this._overGridImageChanged(i.params);
  753. break;
  754. case A.id:
  755. this._overGridImageSelected(i.params);
  756. break;
  757. }
  758. }));
  759. }
  760. _beforeOverGridImageInsert(t) {
  761. if (!this.hasEventCallback(this.Event.BeforeOverGridImageInsert))
  762. return;
  763. const e = this.getActiveWorkbook();
  764. if (e == null || t == null)
  765. return;
  766. const { drawings: i } = t, n = {
  767. workbook: e,
  768. insertImageParams: i
  769. };
  770. if (this.fireEvent(this.Event.BeforeOverGridImageInsert, n), n.cancel)
  771. throw new Error("Canceled by BeforeOverGridImageInsert event");
  772. }
  773. _overGridImageInserted(t) {
  774. if (!this.hasEventCallback(this.Event.OverGridImageInserted))
  775. return;
  776. const e = this.getActiveWorkbook();
  777. if (e == null || t == null)
  778. return;
  779. const { drawings: i } = t;
  780. this.fireEvent(this.Event.OverGridImageInserted, {
  781. workbook: e,
  782. images: this._createFOverGridImage(i)
  783. });
  784. }
  785. _beforeOverGridImageRemove(t) {
  786. if (!this.hasEventCallback(this.Event.BeforeOverGridImageRemove))
  787. return;
  788. const e = this.getActiveWorkbook();
  789. if (e == null || t == null)
  790. return;
  791. const { drawings: i } = t, n = this._injector.get(l), s = i.map((c) => n.getDrawingByParam(c)), o = {
  792. workbook: e,
  793. images: this._createFOverGridImage(s)
  794. };
  795. if (this.fireEvent(this.Event.BeforeOverGridImageRemove, o), o.cancel)
  796. throw new Error("Canceled by BeforeOverGridImageRemove event");
  797. }
  798. _overGridImageRemoved(t) {
  799. if (!this.hasEventCallback(this.Event.OverGridImageRemoved))
  800. return;
  801. const e = this.getActiveWorkbook();
  802. if (e == null || t == null)
  803. return;
  804. const { drawings: i } = t;
  805. this.fireEvent(this.Event.OverGridImageRemoved, {
  806. workbook: e,
  807. removeImageParams: i
  808. });
  809. }
  810. _beforeOverGridImageChange(t) {
  811. if (!this.hasEventCallback(this.Event.BeforeOverGridImageChange))
  812. return;
  813. const e = this.getActiveWorkbook();
  814. if (e == null || t == null)
  815. return;
  816. const { drawings: i } = t, n = this._injector.get(l), s = [];
  817. i.forEach((c) => {
  818. const a = n.getDrawingByParam(c);
  819. a != null && s.push({
  820. changeParam: c,
  821. image: this._injector.createInstance(g, a)
  822. });
  823. });
  824. const o = {
  825. workbook: e,
  826. images: s
  827. };
  828. if (this.fireEvent(this.Event.BeforeOverGridImageChange, o), o.cancel)
  829. throw n.updateNotification(i), new Error("Canceled by BeforeOverGridImageChange event");
  830. }
  831. _overGridImageChanged(t) {
  832. if (!this.hasEventCallback(this.Event.OverGridImageChanged))
  833. return;
  834. const e = this.getActiveWorkbook();
  835. if (e == null || t == null)
  836. return;
  837. const { drawings: i } = t, n = this._injector.get(l), s = i.map((o) => this._injector.createInstance(g, n.getDrawingByParam(o)));
  838. this.fireEvent(this.Event.OverGridImageChanged, {
  839. workbook: e,
  840. images: s
  841. });
  842. }
  843. _beforeOverGridImageSelect(t) {
  844. if (!this.hasEventCallback(this.Event.BeforeOverGridImageSelect))
  845. return;
  846. const e = this._injector.get(l), i = this.getActiveWorkbook();
  847. if (i == null)
  848. return;
  849. const n = e.getFocusDrawings(), s = t.map((c) => e.getDrawingByParam(c)), o = {
  850. workbook: i,
  851. selectedImages: this._createFOverGridImage(s),
  852. oldSelectedImages: this._createFOverGridImage(n)
  853. };
  854. if (this.fireEvent(this.Event.BeforeOverGridImageSelect, o), o.cancel)
  855. throw new Error("Canceled by BeforeOverGridImageSelect event");
  856. }
  857. _overGridImageSelected(t) {
  858. if (!this.hasEventCallback(this.Event.OverGridImageSelected))
  859. return;
  860. const e = this.getActiveWorkbook(), i = this._injector.get(l);
  861. if (e == null)
  862. return;
  863. const n = t.map((s) => i.getDrawingByParam(s));
  864. this.fireEvent(this.Event.OverGridImageSelected, {
  865. workbook: e,
  866. selectedImages: this._createFOverGridImage(n)
  867. });
  868. }
  869. _createFOverGridImage(t) {
  870. return t.map((e) => this._injector.createInstance(g, e));
  871. }
  872. }
  873. N.extend(ce);