@uniformdev/assets 20.7.1-alpha.4 → 20.7.1-alpha.45

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.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ApiClient, ClientOptions } from '@uniformdev/context/api';
2
+ import { XOR } from 'ts-xor';
2
3
 
3
4
  interface components$1 {
4
5
  schemas: {
@@ -145,7 +146,7 @@ interface components$1 {
145
146
  categoryId?: string | null;
146
147
  /** @description Description of the component definition */
147
148
  description?: string;
148
- /** @description Description of the component definition */
149
+ /** @description Preview image URL for the component definition (shown in the UI) */
149
150
  previewImageUrl?: string;
150
151
  /**
151
152
  * @description if this component uses team permissions or custom permissions
@@ -218,6 +219,27 @@ interface components$1 {
218
219
  * @description ID of the workflow that instances of this content type will use by default. When not set, no workflow is attached
219
220
  */
220
221
  workflowId?: string;
222
+ /** @description Configurations for previewing an entry on a consuming pattern or composition. */
223
+ previewConfigurations?: components$1["schemas"]["ContentTypePreviewConfiguration"][];
224
+ };
225
+ /** @description Defines a configuration for previewing an entry on a consuming pattern or composition. */
226
+ ContentTypePreviewConfiguration: {
227
+ /**
228
+ * @description The type of preview configuration
229
+ * @enum {string}
230
+ */
231
+ type: "pattern" | "project-map";
232
+ /** @description Display label for the preview configuration */
233
+ label: string;
234
+ /**
235
+ * Format: uuid
236
+ * @description Target preview entity ID (project map node ID or pattern ID)
237
+ */
238
+ id: string;
239
+ /** @description Optional mapping of dynamic input names to their values */
240
+ dynamicInputs?: {
241
+ [key: string]: string;
242
+ };
221
243
  };
222
244
  /** @description Defines an editable parameter on a component */
223
245
  ComponentParameter: {
@@ -1157,6 +1179,14 @@ interface components {
1157
1179
  /** @constant */
1158
1180
  type: "number";
1159
1181
  };
1182
+ focalPoint?: {
1183
+ value: {
1184
+ x: number;
1185
+ y: number;
1186
+ };
1187
+ /** @constant */
1188
+ type: "focalPoint";
1189
+ };
1160
1190
  /** @description Asset field values */
1161
1191
  custom?: {
1162
1192
  [key: string]: components["schemas"]["ComponentParameter"];
@@ -1192,6 +1222,14 @@ interface components {
1192
1222
  /** @constant */
1193
1223
  type: "file";
1194
1224
  };
1225
+ focalPoint?: {
1226
+ value: {
1227
+ x: number;
1228
+ y: number;
1229
+ };
1230
+ /** @constant */
1231
+ type: "focalPoint";
1232
+ };
1195
1233
  };
1196
1234
  _dataResources?: components["schemas"]["DataResourceDefinitions"];
1197
1235
  };
@@ -1497,33 +1535,31 @@ type AssetParamValueItem = {
1497
1535
  };
1498
1536
  /**
1499
1537
  * The width of the original asset
1500
- *
1501
- * Should resolve to a number but might
1502
- * be a string with a pointer reference
1503
1538
  */
1504
1539
  width?: {
1505
1540
  type: 'number';
1506
- value: number | string | undefined;
1541
+ value: number | undefined;
1507
1542
  };
1508
1543
  /**
1509
1544
  * The height of the original asset
1510
- *
1511
- * Should resolve to a number but might
1512
- * be a string with a pointer reference
1513
1545
  */
1514
1546
  height?: {
1515
1547
  type: 'number';
1516
- value: number | string | undefined;
1548
+ value: number | undefined;
1517
1549
  };
1518
1550
  /**
1519
1551
  * The size in bytes of the original asset
1520
- *
1521
- * Should resolve to a number but might
1522
- * be a string with a pointer reference
1523
1552
  */
1524
1553
  size?: {
1525
1554
  type: 'number';
1526
- value: number | string | undefined;
1555
+ value: number | undefined;
1556
+ };
1557
+ focalPoint?: {
1558
+ type: 'focalPoint';
1559
+ value: {
1560
+ x: number;
1561
+ y: number;
1562
+ } | undefined;
1527
1563
  };
1528
1564
  /**
1529
1565
  * Any key/value properties which the source
@@ -1566,10 +1602,62 @@ type AssetDefinition = {
1566
1602
  };
1567
1603
  declare const assetDefinitions: Record<AssetDefinitionType, AssetDefinition>;
1568
1604
 
1605
+ /**
1606
+ * A union type of possible query parameters for the image delivery API.
1607
+ */
1608
+ type ImageDeliveryParams = XOR<{
1609
+ format: 'original';
1610
+ }, {
1611
+ width?: number;
1612
+ height?: number;
1613
+ /**
1614
+ * scale-down - resize the image to fit within the given dimensions, but never larger than the original size, while maintaining the aspect ratio
1615
+ * contain - resize the image to fit within the given dimensions, including possibly enlarging the image, while maintaining the aspect ratio
1616
+ * cover - resize the image to fully cover the given dimensions, cropping as needed
1617
+ *
1618
+ * "cover" additionally supports specifying a focal point via the "focal" parameter
1619
+ */
1620
+ fit?: 'scale-down' | 'contain' | 'cover';
1621
+ focal?: undefined;
1622
+ }, {
1623
+ width?: number;
1624
+ height?: number;
1625
+ /** cover - resize the image to fully cover the given dimensions, cropping as needed */
1626
+ fit: 'cover';
1627
+ /** "string" is in format NxM - N and M are numbers between 0.00 and 1.00, N representing the x-axis and M representing the y-axis */
1628
+ focal: 'auto' | 'center' | string;
1629
+ }>;
1630
+ /**
1631
+ * A union type of possible transformations accepted by the `imageFrom` function.
1632
+ * Differentiates slightly from the `ImageDeliveryParams` type, in that the focal
1633
+ * point is represented by an object { x: number, y: number }, and not a string.
1634
+ */
1635
+ type ImageFromTransformProps = XOR<{
1636
+ width?: number;
1637
+ height?: number;
1638
+ fit?: 'scale-down' | 'contain' | 'cover';
1639
+ }, {
1640
+ width?: number;
1641
+ height?: number;
1642
+ fit?: 'cover';
1643
+ focal: 'auto' | 'center' | {
1644
+ x: number;
1645
+ y: number;
1646
+ };
1647
+ }>;
1648
+ /**
1649
+ * A helper function for extracting the image URL from an asset and optionally
1650
+ * applying transformation URL query parameters.
1651
+ */
1652
+ declare const imageFrom: (asset: Asset | AssetParamValueItem | string) => {
1653
+ url: () => string;
1654
+ transform: (transformProps: ImageFromTransformProps) => /*elided*/ any;
1655
+ };
1656
+
1569
1657
  /**
1570
1658
  * Converts a content asset to a put content asset body that has only the properties expected to the PUT API.
1571
1659
  * Removes things like author, stats, etc.
1572
1660
  */
1573
1661
  declare function convertAssetToPutAsset(asset: AssetGetResponseSingle): AssetUpsertRequest;
1574
1662
 
1575
- export { type Asset, AssetClient, type AssetDefinitionType, type AssetDeleteRequest, type AssetGetRequest, type AssetGetRequestList, type AssetGetRequestSingle, type AssetGetResponse, type AssetGetResponseList, type AssetGetResponseSingle, type AssetParamValue, type AssetParamValueItem, type AssetUpsertRequest, UncachedAssetClient, assetDefinitions, convertAssetToPutAsset };
1663
+ export { type Asset, AssetClient, type AssetDefinitionType, type AssetDeleteRequest, type AssetGetRequest, type AssetGetRequestList, type AssetGetRequestSingle, type AssetGetResponse, type AssetGetResponseList, type AssetGetResponseSingle, type AssetParamValue, type AssetParamValueItem, type AssetUpsertRequest, type ImageDeliveryParams, type ImageFromTransformProps, UncachedAssetClient, assetDefinitions, convertAssetToPutAsset, imageFrom };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ApiClient, ClientOptions } from '@uniformdev/context/api';
2
+ import { XOR } from 'ts-xor';
2
3
 
3
4
  interface components$1 {
4
5
  schemas: {
@@ -145,7 +146,7 @@ interface components$1 {
145
146
  categoryId?: string | null;
146
147
  /** @description Description of the component definition */
147
148
  description?: string;
148
- /** @description Description of the component definition */
149
+ /** @description Preview image URL for the component definition (shown in the UI) */
149
150
  previewImageUrl?: string;
150
151
  /**
151
152
  * @description if this component uses team permissions or custom permissions
@@ -218,6 +219,27 @@ interface components$1 {
218
219
  * @description ID of the workflow that instances of this content type will use by default. When not set, no workflow is attached
219
220
  */
220
221
  workflowId?: string;
222
+ /** @description Configurations for previewing an entry on a consuming pattern or composition. */
223
+ previewConfigurations?: components$1["schemas"]["ContentTypePreviewConfiguration"][];
224
+ };
225
+ /** @description Defines a configuration for previewing an entry on a consuming pattern or composition. */
226
+ ContentTypePreviewConfiguration: {
227
+ /**
228
+ * @description The type of preview configuration
229
+ * @enum {string}
230
+ */
231
+ type: "pattern" | "project-map";
232
+ /** @description Display label for the preview configuration */
233
+ label: string;
234
+ /**
235
+ * Format: uuid
236
+ * @description Target preview entity ID (project map node ID or pattern ID)
237
+ */
238
+ id: string;
239
+ /** @description Optional mapping of dynamic input names to their values */
240
+ dynamicInputs?: {
241
+ [key: string]: string;
242
+ };
221
243
  };
222
244
  /** @description Defines an editable parameter on a component */
223
245
  ComponentParameter: {
@@ -1157,6 +1179,14 @@ interface components {
1157
1179
  /** @constant */
1158
1180
  type: "number";
1159
1181
  };
1182
+ focalPoint?: {
1183
+ value: {
1184
+ x: number;
1185
+ y: number;
1186
+ };
1187
+ /** @constant */
1188
+ type: "focalPoint";
1189
+ };
1160
1190
  /** @description Asset field values */
1161
1191
  custom?: {
1162
1192
  [key: string]: components["schemas"]["ComponentParameter"];
@@ -1192,6 +1222,14 @@ interface components {
1192
1222
  /** @constant */
1193
1223
  type: "file";
1194
1224
  };
1225
+ focalPoint?: {
1226
+ value: {
1227
+ x: number;
1228
+ y: number;
1229
+ };
1230
+ /** @constant */
1231
+ type: "focalPoint";
1232
+ };
1195
1233
  };
1196
1234
  _dataResources?: components["schemas"]["DataResourceDefinitions"];
1197
1235
  };
@@ -1497,33 +1535,31 @@ type AssetParamValueItem = {
1497
1535
  };
1498
1536
  /**
1499
1537
  * The width of the original asset
1500
- *
1501
- * Should resolve to a number but might
1502
- * be a string with a pointer reference
1503
1538
  */
1504
1539
  width?: {
1505
1540
  type: 'number';
1506
- value: number | string | undefined;
1541
+ value: number | undefined;
1507
1542
  };
1508
1543
  /**
1509
1544
  * The height of the original asset
1510
- *
1511
- * Should resolve to a number but might
1512
- * be a string with a pointer reference
1513
1545
  */
1514
1546
  height?: {
1515
1547
  type: 'number';
1516
- value: number | string | undefined;
1548
+ value: number | undefined;
1517
1549
  };
1518
1550
  /**
1519
1551
  * The size in bytes of the original asset
1520
- *
1521
- * Should resolve to a number but might
1522
- * be a string with a pointer reference
1523
1552
  */
1524
1553
  size?: {
1525
1554
  type: 'number';
1526
- value: number | string | undefined;
1555
+ value: number | undefined;
1556
+ };
1557
+ focalPoint?: {
1558
+ type: 'focalPoint';
1559
+ value: {
1560
+ x: number;
1561
+ y: number;
1562
+ } | undefined;
1527
1563
  };
1528
1564
  /**
1529
1565
  * Any key/value properties which the source
@@ -1566,10 +1602,62 @@ type AssetDefinition = {
1566
1602
  };
1567
1603
  declare const assetDefinitions: Record<AssetDefinitionType, AssetDefinition>;
1568
1604
 
1605
+ /**
1606
+ * A union type of possible query parameters for the image delivery API.
1607
+ */
1608
+ type ImageDeliveryParams = XOR<{
1609
+ format: 'original';
1610
+ }, {
1611
+ width?: number;
1612
+ height?: number;
1613
+ /**
1614
+ * scale-down - resize the image to fit within the given dimensions, but never larger than the original size, while maintaining the aspect ratio
1615
+ * contain - resize the image to fit within the given dimensions, including possibly enlarging the image, while maintaining the aspect ratio
1616
+ * cover - resize the image to fully cover the given dimensions, cropping as needed
1617
+ *
1618
+ * "cover" additionally supports specifying a focal point via the "focal" parameter
1619
+ */
1620
+ fit?: 'scale-down' | 'contain' | 'cover';
1621
+ focal?: undefined;
1622
+ }, {
1623
+ width?: number;
1624
+ height?: number;
1625
+ /** cover - resize the image to fully cover the given dimensions, cropping as needed */
1626
+ fit: 'cover';
1627
+ /** "string" is in format NxM - N and M are numbers between 0.00 and 1.00, N representing the x-axis and M representing the y-axis */
1628
+ focal: 'auto' | 'center' | string;
1629
+ }>;
1630
+ /**
1631
+ * A union type of possible transformations accepted by the `imageFrom` function.
1632
+ * Differentiates slightly from the `ImageDeliveryParams` type, in that the focal
1633
+ * point is represented by an object { x: number, y: number }, and not a string.
1634
+ */
1635
+ type ImageFromTransformProps = XOR<{
1636
+ width?: number;
1637
+ height?: number;
1638
+ fit?: 'scale-down' | 'contain' | 'cover';
1639
+ }, {
1640
+ width?: number;
1641
+ height?: number;
1642
+ fit?: 'cover';
1643
+ focal: 'auto' | 'center' | {
1644
+ x: number;
1645
+ y: number;
1646
+ };
1647
+ }>;
1648
+ /**
1649
+ * A helper function for extracting the image URL from an asset and optionally
1650
+ * applying transformation URL query parameters.
1651
+ */
1652
+ declare const imageFrom: (asset: Asset | AssetParamValueItem | string) => {
1653
+ url: () => string;
1654
+ transform: (transformProps: ImageFromTransformProps) => /*elided*/ any;
1655
+ };
1656
+
1569
1657
  /**
1570
1658
  * Converts a content asset to a put content asset body that has only the properties expected to the PUT API.
1571
1659
  * Removes things like author, stats, etc.
1572
1660
  */
1573
1661
  declare function convertAssetToPutAsset(asset: AssetGetResponseSingle): AssetUpsertRequest;
1574
1662
 
1575
- export { type Asset, AssetClient, type AssetDefinitionType, type AssetDeleteRequest, type AssetGetRequest, type AssetGetRequestList, type AssetGetRequestSingle, type AssetGetResponse, type AssetGetResponseList, type AssetGetResponseSingle, type AssetParamValue, type AssetParamValueItem, type AssetUpsertRequest, UncachedAssetClient, assetDefinitions, convertAssetToPutAsset };
1663
+ export { type Asset, AssetClient, type AssetDefinitionType, type AssetDeleteRequest, type AssetGetRequest, type AssetGetRequestList, type AssetGetRequestSingle, type AssetGetResponse, type AssetGetResponseList, type AssetGetResponseSingle, type AssetParamValue, type AssetParamValueItem, type AssetUpsertRequest, type ImageDeliveryParams, type ImageFromTransformProps, UncachedAssetClient, assetDefinitions, convertAssetToPutAsset, imageFrom };
package/dist/index.esm.js CHANGED
@@ -62,9 +62,80 @@ var assetDefinitions = {
62
62
  }
63
63
  };
64
64
 
65
+ // src/imageDelivery.ts
66
+ var isUniformImageUrl = (imageUrl) => {
67
+ try {
68
+ if (typeof imageUrl !== "string") {
69
+ return false;
70
+ }
71
+ return /(img).uniform.(rocks|global)$/.test(new URL(imageUrl).hostname);
72
+ } catch (e) {
73
+ return false;
74
+ }
75
+ };
76
+ var imageFrom = (asset) => {
77
+ var _a, _b, _c, _d;
78
+ const baseUrl = typeof asset === "string" ? asset : (_b = (_a = asset.fields) == null ? void 0 : _a.url) == null ? void 0 : _b.value;
79
+ const isUniformHosted = isUniformImageUrl(baseUrl);
80
+ const deliveryParams = {};
81
+ if (typeof asset !== "string") {
82
+ if ((_d = (_c = asset.fields) == null ? void 0 : _c.focalPoint) == null ? void 0 : _d.value) {
83
+ deliveryParams.focal = `${asset.fields.focalPoint.value.x}x${asset.fields.focalPoint.value.y}`;
84
+ }
85
+ }
86
+ const api = {
87
+ url: () => {
88
+ if (!baseUrl) {
89
+ return "";
90
+ }
91
+ if (!isUniformHosted) {
92
+ return baseUrl;
93
+ }
94
+ const url = new URL(baseUrl);
95
+ const params = deliveryParams;
96
+ if (params.width !== void 0) {
97
+ url.searchParams.set("width", params.width.toString());
98
+ }
99
+ if (params.height !== void 0) {
100
+ url.searchParams.set("height", params.height.toString());
101
+ }
102
+ if (params.fit !== void 0) {
103
+ url.searchParams.set("fit", params.fit);
104
+ } else if (params.width !== void 0 && params.height !== void 0) {
105
+ url.searchParams.set("fit", "cover");
106
+ params.fit = "cover";
107
+ }
108
+ if (params.width !== void 0 && params.height !== void 0 && params.focal !== void 0 && params.fit === "cover") {
109
+ url.searchParams.set("focal", params.focal);
110
+ }
111
+ return url.toString();
112
+ },
113
+ transform: (transformProps) => {
114
+ if (transformProps.width !== void 0) {
115
+ deliveryParams.width = transformProps.width;
116
+ }
117
+ if (transformProps.height !== void 0) {
118
+ deliveryParams.height = transformProps.height;
119
+ }
120
+ if (transformProps.fit !== void 0) {
121
+ deliveryParams.fit = transformProps.fit;
122
+ }
123
+ if (transformProps.focal !== void 0) {
124
+ if (typeof transformProps.focal === "string") {
125
+ deliveryParams.focal = transformProps.focal;
126
+ } else {
127
+ deliveryParams.focal = `${transformProps.focal.x}x${transformProps.focal.y}`;
128
+ }
129
+ }
130
+ return api;
131
+ }
132
+ };
133
+ return api;
134
+ };
135
+
65
136
  // src/utils/assetConverter.ts
66
137
  function convertAssetToPutAsset(asset) {
67
- var _a, _b, _c;
138
+ var _a, _b, _c, _d;
68
139
  return {
69
140
  asset: {
70
141
  _id: asset.asset._id,
@@ -74,7 +145,8 @@ function convertAssetToPutAsset(asset) {
74
145
  fields: {
75
146
  title: (_a = asset.asset.fields) == null ? void 0 : _a.title,
76
147
  description: (_b = asset.asset.fields) == null ? void 0 : _b.description,
77
- file: (_c = asset.asset.fields) == null ? void 0 : _c.file
148
+ file: (_c = asset.asset.fields) == null ? void 0 : _c.file,
149
+ focalPoint: (_d = asset.asset.fields) == null ? void 0 : _d.focalPoint
78
150
  }
79
151
  },
80
152
  projectId: asset.projectId
@@ -84,5 +156,6 @@ export {
84
156
  AssetClient,
85
157
  UncachedAssetClient,
86
158
  assetDefinitions,
87
- convertAssetToPutAsset
159
+ convertAssetToPutAsset,
160
+ imageFrom
88
161
  };
package/dist/index.js CHANGED
@@ -23,7 +23,8 @@ __export(src_exports, {
23
23
  AssetClient: () => AssetClient,
24
24
  UncachedAssetClient: () => UncachedAssetClient,
25
25
  assetDefinitions: () => assetDefinitions,
26
- convertAssetToPutAsset: () => convertAssetToPutAsset
26
+ convertAssetToPutAsset: () => convertAssetToPutAsset,
27
+ imageFrom: () => imageFrom
27
28
  });
28
29
  module.exports = __toCommonJS(src_exports);
29
30
 
@@ -91,9 +92,80 @@ var assetDefinitions = {
91
92
  }
92
93
  };
93
94
 
95
+ // src/imageDelivery.ts
96
+ var isUniformImageUrl = (imageUrl) => {
97
+ try {
98
+ if (typeof imageUrl !== "string") {
99
+ return false;
100
+ }
101
+ return /(img).uniform.(rocks|global)$/.test(new URL(imageUrl).hostname);
102
+ } catch (e) {
103
+ return false;
104
+ }
105
+ };
106
+ var imageFrom = (asset) => {
107
+ var _a, _b, _c, _d;
108
+ const baseUrl = typeof asset === "string" ? asset : (_b = (_a = asset.fields) == null ? void 0 : _a.url) == null ? void 0 : _b.value;
109
+ const isUniformHosted = isUniformImageUrl(baseUrl);
110
+ const deliveryParams = {};
111
+ if (typeof asset !== "string") {
112
+ if ((_d = (_c = asset.fields) == null ? void 0 : _c.focalPoint) == null ? void 0 : _d.value) {
113
+ deliveryParams.focal = `${asset.fields.focalPoint.value.x}x${asset.fields.focalPoint.value.y}`;
114
+ }
115
+ }
116
+ const api = {
117
+ url: () => {
118
+ if (!baseUrl) {
119
+ return "";
120
+ }
121
+ if (!isUniformHosted) {
122
+ return baseUrl;
123
+ }
124
+ const url = new URL(baseUrl);
125
+ const params = deliveryParams;
126
+ if (params.width !== void 0) {
127
+ url.searchParams.set("width", params.width.toString());
128
+ }
129
+ if (params.height !== void 0) {
130
+ url.searchParams.set("height", params.height.toString());
131
+ }
132
+ if (params.fit !== void 0) {
133
+ url.searchParams.set("fit", params.fit);
134
+ } else if (params.width !== void 0 && params.height !== void 0) {
135
+ url.searchParams.set("fit", "cover");
136
+ params.fit = "cover";
137
+ }
138
+ if (params.width !== void 0 && params.height !== void 0 && params.focal !== void 0 && params.fit === "cover") {
139
+ url.searchParams.set("focal", params.focal);
140
+ }
141
+ return url.toString();
142
+ },
143
+ transform: (transformProps) => {
144
+ if (transformProps.width !== void 0) {
145
+ deliveryParams.width = transformProps.width;
146
+ }
147
+ if (transformProps.height !== void 0) {
148
+ deliveryParams.height = transformProps.height;
149
+ }
150
+ if (transformProps.fit !== void 0) {
151
+ deliveryParams.fit = transformProps.fit;
152
+ }
153
+ if (transformProps.focal !== void 0) {
154
+ if (typeof transformProps.focal === "string") {
155
+ deliveryParams.focal = transformProps.focal;
156
+ } else {
157
+ deliveryParams.focal = `${transformProps.focal.x}x${transformProps.focal.y}`;
158
+ }
159
+ }
160
+ return api;
161
+ }
162
+ };
163
+ return api;
164
+ };
165
+
94
166
  // src/utils/assetConverter.ts
95
167
  function convertAssetToPutAsset(asset) {
96
- var _a, _b, _c;
168
+ var _a, _b, _c, _d;
97
169
  return {
98
170
  asset: {
99
171
  _id: asset.asset._id,
@@ -103,7 +175,8 @@ function convertAssetToPutAsset(asset) {
103
175
  fields: {
104
176
  title: (_a = asset.asset.fields) == null ? void 0 : _a.title,
105
177
  description: (_b = asset.asset.fields) == null ? void 0 : _b.description,
106
- file: (_c = asset.asset.fields) == null ? void 0 : _c.file
178
+ file: (_c = asset.asset.fields) == null ? void 0 : _c.file,
179
+ focalPoint: (_d = asset.asset.fields) == null ? void 0 : _d.focalPoint
107
180
  }
108
181
  },
109
182
  projectId: asset.projectId
@@ -114,5 +187,6 @@ function convertAssetToPutAsset(asset) {
114
187
  AssetClient,
115
188
  UncachedAssetClient,
116
189
  assetDefinitions,
117
- convertAssetToPutAsset
190
+ convertAssetToPutAsset,
191
+ imageFrom
118
192
  });
package/dist/index.mjs CHANGED
@@ -62,9 +62,80 @@ var assetDefinitions = {
62
62
  }
63
63
  };
64
64
 
65
+ // src/imageDelivery.ts
66
+ var isUniformImageUrl = (imageUrl) => {
67
+ try {
68
+ if (typeof imageUrl !== "string") {
69
+ return false;
70
+ }
71
+ return /(img).uniform.(rocks|global)$/.test(new URL(imageUrl).hostname);
72
+ } catch (e) {
73
+ return false;
74
+ }
75
+ };
76
+ var imageFrom = (asset) => {
77
+ var _a, _b, _c, _d;
78
+ const baseUrl = typeof asset === "string" ? asset : (_b = (_a = asset.fields) == null ? void 0 : _a.url) == null ? void 0 : _b.value;
79
+ const isUniformHosted = isUniformImageUrl(baseUrl);
80
+ const deliveryParams = {};
81
+ if (typeof asset !== "string") {
82
+ if ((_d = (_c = asset.fields) == null ? void 0 : _c.focalPoint) == null ? void 0 : _d.value) {
83
+ deliveryParams.focal = `${asset.fields.focalPoint.value.x}x${asset.fields.focalPoint.value.y}`;
84
+ }
85
+ }
86
+ const api = {
87
+ url: () => {
88
+ if (!baseUrl) {
89
+ return "";
90
+ }
91
+ if (!isUniformHosted) {
92
+ return baseUrl;
93
+ }
94
+ const url = new URL(baseUrl);
95
+ const params = deliveryParams;
96
+ if (params.width !== void 0) {
97
+ url.searchParams.set("width", params.width.toString());
98
+ }
99
+ if (params.height !== void 0) {
100
+ url.searchParams.set("height", params.height.toString());
101
+ }
102
+ if (params.fit !== void 0) {
103
+ url.searchParams.set("fit", params.fit);
104
+ } else if (params.width !== void 0 && params.height !== void 0) {
105
+ url.searchParams.set("fit", "cover");
106
+ params.fit = "cover";
107
+ }
108
+ if (params.width !== void 0 && params.height !== void 0 && params.focal !== void 0 && params.fit === "cover") {
109
+ url.searchParams.set("focal", params.focal);
110
+ }
111
+ return url.toString();
112
+ },
113
+ transform: (transformProps) => {
114
+ if (transformProps.width !== void 0) {
115
+ deliveryParams.width = transformProps.width;
116
+ }
117
+ if (transformProps.height !== void 0) {
118
+ deliveryParams.height = transformProps.height;
119
+ }
120
+ if (transformProps.fit !== void 0) {
121
+ deliveryParams.fit = transformProps.fit;
122
+ }
123
+ if (transformProps.focal !== void 0) {
124
+ if (typeof transformProps.focal === "string") {
125
+ deliveryParams.focal = transformProps.focal;
126
+ } else {
127
+ deliveryParams.focal = `${transformProps.focal.x}x${transformProps.focal.y}`;
128
+ }
129
+ }
130
+ return api;
131
+ }
132
+ };
133
+ return api;
134
+ };
135
+
65
136
  // src/utils/assetConverter.ts
66
137
  function convertAssetToPutAsset(asset) {
67
- var _a, _b, _c;
138
+ var _a, _b, _c, _d;
68
139
  return {
69
140
  asset: {
70
141
  _id: asset.asset._id,
@@ -74,7 +145,8 @@ function convertAssetToPutAsset(asset) {
74
145
  fields: {
75
146
  title: (_a = asset.asset.fields) == null ? void 0 : _a.title,
76
147
  description: (_b = asset.asset.fields) == null ? void 0 : _b.description,
77
- file: (_c = asset.asset.fields) == null ? void 0 : _c.file
148
+ file: (_c = asset.asset.fields) == null ? void 0 : _c.file,
149
+ focalPoint: (_d = asset.asset.fields) == null ? void 0 : _d.focalPoint
78
150
  }
79
151
  },
80
152
  projectId: asset.projectId
@@ -84,5 +156,6 @@ export {
84
156
  AssetClient,
85
157
  UncachedAssetClient,
86
158
  assetDefinitions,
87
- convertAssetToPutAsset
159
+ convertAssetToPutAsset,
160
+ imageFrom
88
161
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/assets",
3
- "version": "20.7.1-alpha.4+20185a97ff",
3
+ "version": "20.7.1-alpha.45+082e9e310e",
4
4
  "description": "Uniform Assets",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -36,7 +36,10 @@
36
36
  "access": "public"
37
37
  },
38
38
  "dependencies": {
39
- "@uniformdev/context": "20.7.1-alpha.4+20185a97ff"
39
+ "@uniformdev/context": "20.7.1-alpha.45+082e9e310e"
40
40
  },
41
- "gitHead": "20185a97ff6c2de2f871223af12d73583fe300af"
41
+ "devDependencies": {
42
+ "ts-xor": "^1.3.0"
43
+ },
44
+ "gitHead": "082e9e310e3f0a32074da8bc21a928e665041246"
42
45
  }