@uniformdev/assets 20.12.1-alpha.23 → 20.12.1-alpha.26

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
@@ -146,7 +146,7 @@ interface components$1 {
146
146
  categoryId?: string | null;
147
147
  /** @description Description of the component definition */
148
148
  description?: string;
149
- /** @description Description of the component definition */
149
+ /** @description Preview image URL for the component definition (shown in the UI) */
150
150
  previewImageUrl?: string;
151
151
  /**
152
152
  * @description if this component uses team permissions or custom permissions
@@ -1602,6 +1602,9 @@ type AssetDefinition = {
1602
1602
  };
1603
1603
  declare const assetDefinitions: Record<AssetDefinitionType, AssetDefinition>;
1604
1604
 
1605
+ /**
1606
+ * A union type of possible query parameters for the image delivery API.
1607
+ */
1605
1608
  type ImageDeliveryParams = XOR<{
1606
1609
  format: 'original';
1607
1610
  }, {
@@ -1615,6 +1618,7 @@ type ImageDeliveryParams = XOR<{
1615
1618
  * "cover" additionally supports specifying a focal point via the "focal" parameter
1616
1619
  */
1617
1620
  fit?: 'scale-down' | 'contain' | 'cover';
1621
+ focal?: undefined;
1618
1622
  }, {
1619
1623
  width?: number;
1620
1624
  height?: number;
@@ -1623,6 +1627,32 @@ type ImageDeliveryParams = XOR<{
1623
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 */
1624
1628
  focal: 'auto' | 'center' | string;
1625
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
+ };
1626
1656
 
1627
1657
  /**
1628
1658
  * Converts a content asset to a put content asset body that has only the properties expected to the PUT API.
@@ -1630,4 +1660,4 @@ type ImageDeliveryParams = XOR<{
1630
1660
  */
1631
1661
  declare function convertAssetToPutAsset(asset: AssetGetResponseSingle): AssetUpsertRequest;
1632
1662
 
1633
- 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, 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
@@ -146,7 +146,7 @@ interface components$1 {
146
146
  categoryId?: string | null;
147
147
  /** @description Description of the component definition */
148
148
  description?: string;
149
- /** @description Description of the component definition */
149
+ /** @description Preview image URL for the component definition (shown in the UI) */
150
150
  previewImageUrl?: string;
151
151
  /**
152
152
  * @description if this component uses team permissions or custom permissions
@@ -1602,6 +1602,9 @@ type AssetDefinition = {
1602
1602
  };
1603
1603
  declare const assetDefinitions: Record<AssetDefinitionType, AssetDefinition>;
1604
1604
 
1605
+ /**
1606
+ * A union type of possible query parameters for the image delivery API.
1607
+ */
1605
1608
  type ImageDeliveryParams = XOR<{
1606
1609
  format: 'original';
1607
1610
  }, {
@@ -1615,6 +1618,7 @@ type ImageDeliveryParams = XOR<{
1615
1618
  * "cover" additionally supports specifying a focal point via the "focal" parameter
1616
1619
  */
1617
1620
  fit?: 'scale-down' | 'contain' | 'cover';
1621
+ focal?: undefined;
1618
1622
  }, {
1619
1623
  width?: number;
1620
1624
  height?: number;
@@ -1623,6 +1627,32 @@ type ImageDeliveryParams = XOR<{
1623
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 */
1624
1628
  focal: 'auto' | 'center' | string;
1625
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
+ };
1626
1656
 
1627
1657
  /**
1628
1658
  * Converts a content asset to a put content asset body that has only the properties expected to the PUT API.
@@ -1630,4 +1660,4 @@ type ImageDeliveryParams = XOR<{
1630
1660
  */
1631
1661
  declare function convertAssetToPutAsset(asset: AssetGetResponseSingle): AssetUpsertRequest;
1632
1662
 
1633
- 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, 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,6 +62,77 @@ 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
138
  var _a, _b, _c, _d;
@@ -85,5 +156,6 @@ export {
85
156
  AssetClient,
86
157
  UncachedAssetClient,
87
158
  assetDefinitions,
88
- convertAssetToPutAsset
159
+ convertAssetToPutAsset,
160
+ imageFrom
89
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,6 +92,77 @@ 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
168
  var _a, _b, _c, _d;
@@ -115,5 +187,6 @@ function convertAssetToPutAsset(asset) {
115
187
  AssetClient,
116
188
  UncachedAssetClient,
117
189
  assetDefinitions,
118
- convertAssetToPutAsset
190
+ convertAssetToPutAsset,
191
+ imageFrom
119
192
  });
package/dist/index.mjs CHANGED
@@ -62,6 +62,77 @@ 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
138
  var _a, _b, _c, _d;
@@ -85,5 +156,6 @@ export {
85
156
  AssetClient,
86
157
  UncachedAssetClient,
87
158
  assetDefinitions,
88
- convertAssetToPutAsset
159
+ convertAssetToPutAsset,
160
+ imageFrom
89
161
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/assets",
3
- "version": "20.12.1-alpha.23+36df23cbe9",
3
+ "version": "20.12.1-alpha.26+727af74745",
4
4
  "description": "Uniform Assets",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -36,10 +36,10 @@
36
36
  "access": "public"
37
37
  },
38
38
  "dependencies": {
39
- "@uniformdev/context": "20.12.1-alpha.23+36df23cbe9"
39
+ "@uniformdev/context": "20.12.1-alpha.26+727af74745"
40
40
  },
41
41
  "devDependencies": {
42
42
  "ts-xor": "^1.3.0"
43
43
  },
44
- "gitHead": "36df23cbe9ca246137efcf2f4a57e04d029406cc"
44
+ "gitHead": "727af74745bafe690997e093f65e0c3d0aef5a45"
45
45
  }