@contrail/documents 1.3.21 → 1.3.25

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.
@@ -1,10 +1,26 @@
1
1
  import { DocumentElement } from '../types';
2
2
  export declare const DEFAULT_THUMBNAIL_WIDTH = 200;
3
3
  export declare const MAX_CARD_WIDTH = 600;
4
+ export interface ItemCardDimensions {
5
+ thumbnailWidth: number;
6
+ thumbnailHeight: number;
7
+ cardWidth: number;
8
+ cardHeight: number;
9
+ }
10
+ export interface ScaledItemCardResult {
11
+ thumbnailWidth: number;
12
+ thumbnailHeight: number;
13
+ cardWidth: number;
14
+ }
4
15
  export declare class ItemComponentService {
5
16
  static isItemComponent(element: DocumentElement): boolean;
6
17
  static isThumbnailOnlyComponent(element: DocumentElement): boolean;
7
18
  static updateSizeAndPosition(propertyElements: any[], componentElement: DocumentElement, annotatedElements?: any[]): any;
8
19
  private static getYMargin;
9
20
  private static calculateAnnotationHeight;
21
+ static getImageElement(element: DocumentElement): DocumentElement | undefined;
22
+ static getItemCardDimensions(element: DocumentElement, visualHeight?: number): ItemCardDimensions;
23
+ static calculateScaledThumbnailHeight(thumbnailWidth: number, thumbnailHeight: number, newThumbnailWidth: number): number;
24
+ static calculateScaledCardWidth(thumbnailWidth: number, cardWidth: number, newThumbnailWidth: number): number;
25
+ static calculateScaledDimensions(dimensions: ItemCardDimensions, newThumbnailWidth: number): ScaledItemCardResult;
10
26
  }
@@ -135,5 +135,46 @@ class ItemComponentService {
135
135
  }
136
136
  return height;
137
137
  }
138
+ static getImageElement(element) {
139
+ var _a;
140
+ return (_a = element === null || element === void 0 ? void 0 : element.elements) === null || _a === void 0 ? void 0 : _a.find((e) => e.type === 'image');
141
+ }
142
+ static getItemCardDimensions(element, visualHeight) {
143
+ var _a, _b, _c;
144
+ const imageElement = this.getImageElement(element);
145
+ const thumbnailWidth = ((_a = imageElement === null || imageElement === void 0 ? void 0 : imageElement.size) === null || _a === void 0 ? void 0 : _a.width) || exports.DEFAULT_THUMBNAIL_WIDTH;
146
+ const thumbnailHeight = ((_b = imageElement === null || imageElement === void 0 ? void 0 : imageElement.size) === null || _b === void 0 ? void 0 : _b.height) || thumbnailWidth;
147
+ const cardWidth = ((_c = element === null || element === void 0 ? void 0 : element.size) === null || _c === void 0 ? void 0 : _c.width) || thumbnailWidth;
148
+ const cardHeight = visualHeight || thumbnailHeight;
149
+ return {
150
+ thumbnailWidth,
151
+ thumbnailHeight,
152
+ cardWidth,
153
+ cardHeight,
154
+ };
155
+ }
156
+ static calculateScaledThumbnailHeight(thumbnailWidth, thumbnailHeight, newThumbnailWidth) {
157
+ const aspectRatio = thumbnailWidth / thumbnailHeight;
158
+ if (aspectRatio === 1) {
159
+ return newThumbnailWidth;
160
+ }
161
+ else if (aspectRatio > 1) {
162
+ return Math.ceil(newThumbnailWidth * (3 / 4));
163
+ }
164
+ else {
165
+ return Math.ceil(newThumbnailWidth * (4 / 3));
166
+ }
167
+ }
168
+ static calculateScaledCardWidth(thumbnailWidth, cardWidth, newThumbnailWidth) {
169
+ const scaleFactor = newThumbnailWidth / thumbnailWidth;
170
+ return Math.max(newThumbnailWidth, Math.round(cardWidth * scaleFactor));
171
+ }
172
+ static calculateScaledDimensions(dimensions, newThumbnailWidth) {
173
+ return {
174
+ thumbnailWidth: newThumbnailWidth,
175
+ thumbnailHeight: this.calculateScaledThumbnailHeight(dimensions.thumbnailWidth, dimensions.thumbnailHeight, newThumbnailWidth),
176
+ cardWidth: this.calculateScaledCardWidth(dimensions.thumbnailWidth, dimensions.cardWidth, newThumbnailWidth),
177
+ };
178
+ }
138
179
  }
139
180
  exports.ItemComponentService = ItemComponentService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "1.3.21",
3
+ "version": "1.3.25",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -41,7 +41,7 @@
41
41
  "@contrail/actions": "^1.0.17",
42
42
  "@contrail/document-table": "^1.0.5",
43
43
  "@contrail/types": "^3.1.4",
44
- "@contrail/document-util": "^1.0.9",
44
+ "@contrail/document-util": "^1.0.15",
45
45
  "reflect-metadata": "^0.1.13"
46
46
  }
47
47
  }