@threekit-tools/treble 0.0.57 → 0.0.58

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.
@@ -129,53 +129,12 @@ var Snapshots = /** @class */ (function () {
129
129
  }, Promise.resolve(snapshots));
130
130
  };
131
131
  this.takeSnapshots = function (camerasList, snapshotsConfig) { return __awaiter(_this, void 0, void 0, function () {
132
- function saveSnapshotToPlatform(snapshot, filename) {
133
- return __awaiter(this, void 0, void 0, function () {
134
- var files, response;
135
- return __generator(this, function (_a) {
136
- switch (_a.label) {
137
- case 0:
138
- files = (0, utils_1.dataURItoFile)(snapshot, filename);
139
- return [4 /*yield*/, api_1.default.configurations.save({
140
- assetId: window.threekit.player.assetId,
141
- configuration: window.threekit.configurator.getConfiguration(),
142
- files: files,
143
- })];
144
- case 1:
145
- response = _a.sent();
146
- return [2 /*return*/, "".concat(threekitDomain, "/api/files/hash/").concat(response.data.thumbnail)];
147
- }
148
- });
149
- });
150
- }
151
- function downloadSnapshot(snapshot, filename) {
152
- return __awaiter(this, void 0, void 0, function () {
153
- var blob, blobUrl, link, clickHandler;
154
- return __generator(this, function (_a) {
155
- blob = (0, utils_1.dataURItoBlob)(snapshot);
156
- blobUrl = URL.createObjectURL(blob);
157
- link = document.createElement('a');
158
- link.href = blobUrl;
159
- link.download = filename;
160
- clickHandler = function () {
161
- setTimeout(function () {
162
- URL.revokeObjectURL(blobUrl);
163
- link.removeEventListener('click', clickHandler);
164
- }, 150);
165
- };
166
- link.addEventListener('click', clickHandler);
167
- document.body.appendChild(link);
168
- link.click();
169
- return [2 /*return*/];
170
- });
171
- });
172
- }
173
- var threekitDomain, filename, size, format, attributeName, output, cameras, snapshotsRaw, snapshotData, camerasMap_1, currentCamera, cameraPosition, _a, savedSnapshots, snapshotBlobs, snapshotFiles;
174
- var _b;
175
- return __generator(this, function (_c) {
176
- switch (_c.label) {
132
+ var _a, threekitDomain, orgId, filename, size, format, attributeName, output, cameras, snapshotsRaw, snapshotData, camerasMap_1, currentCamera, cameraPosition, _b, attachments, response_1, urlsArray, snapshotBlobs, snapshotFiles;
133
+ var _c;
134
+ return __generator(this, function (_d) {
135
+ switch (_d.label) {
177
136
  case 0:
178
- threekitDomain = connection_1.default.getConnection().threekitDomain;
137
+ _a = connection_1.default.getConnection(), threekitDomain = _a.threekitDomain, orgId = _a.orgId;
179
138
  filename = (snapshotsConfig === null || snapshotsConfig === void 0 ? void 0 : snapshotsConfig.filename) || DEFAULT_CAMERA_CONFIG.filename;
180
139
  size = (snapshotsConfig === null || snapshotsConfig === void 0 ? void 0 : snapshotsConfig.size) || DEFAULT_CAMERA_CONFIG.size;
181
140
  format = (snapshotsConfig === null || snapshotsConfig === void 0 ? void 0 : snapshotsConfig.format) || DEFAULT_CAMERA_CONFIG.format;
@@ -185,7 +144,7 @@ var Snapshots = /** @class */ (function () {
185
144
  if (!(cameras.length === 1 && cameras[0] === undefined)) return [3 /*break*/, 2];
186
145
  return [4 /*yield*/, this.getSnapshot({ size: size, format: format })];
187
146
  case 1:
188
- snapshotData = _c.sent();
147
+ snapshotData = _d.sent();
189
148
  snapshotsRaw = [snapshotData];
190
149
  return [3 /*break*/, 5];
191
150
  case 2:
@@ -197,17 +156,17 @@ var Snapshots = /** @class */ (function () {
197
156
  cameraPosition = (0, utils_1.getCameraPosition)(window.threekit.player.camera);
198
157
  return [4 /*yield*/, this.getSnapshots(cameras, camerasMap_1)];
199
158
  case 3:
200
- snapshotsRaw = _c.sent();
201
- return [4 /*yield*/, window.threekit.configurator.setConfiguration((_b = {},
202
- _b[attributeName] = currentCamera,
203
- _b))];
159
+ snapshotsRaw = _d.sent();
160
+ return [4 /*yield*/, window.threekit.configurator.setConfiguration((_c = {},
161
+ _c[attributeName] = currentCamera,
162
+ _c))];
204
163
  case 4:
205
- _c.sent();
164
+ _d.sent();
206
165
  (0, utils_1.setCameraPosition)(window.threekit.player.camera, cameraPosition);
207
- _c.label = 5;
166
+ _d.label = 5;
208
167
  case 5:
209
- _a = output;
210
- switch (_a) {
168
+ _b = output;
169
+ switch (_b) {
211
170
  case constants_1.SNAPSHOT_OUTPUTS.url: return [3 /*break*/, 6];
212
171
  case constants_1.SNAPSHOT_OUTPUTS.download: return [3 /*break*/, 8];
213
172
  case constants_1.SNAPSHOT_OUTPUTS.blob: return [3 /*break*/, 9];
@@ -215,21 +174,32 @@ var Snapshots = /** @class */ (function () {
215
174
  case constants_1.SNAPSHOT_OUTPUTS.dataUrl: return [3 /*break*/, 11];
216
175
  }
217
176
  return [3 /*break*/, 11];
218
- case 6: return [4 /*yield*/, Promise.all(snapshotsRaw.map(function (snapshotBlob, idx) {
177
+ case 6:
178
+ attachments = snapshotsRaw.reduce(function (output, el, idx) {
179
+ var _a;
219
180
  var cameraName = (camerasList === null || camerasList === void 0 ? void 0 : camerasList[idx])
220
- ? "-".concat((0, utils_1.regularToKebabCase)(camerasList[idx] || 'default'))
181
+ ? (0, utils_1.regularToKebabCase)(camerasList[idx] || 'default')
221
182
  : '';
222
- return saveSnapshotToPlatform(snapshotBlob, "".concat(filename).concat(cameraName, ".").concat(format));
223
- }))];
183
+ var file = (0, utils_1.dataURItoFile)(el, "".concat(filename, "-").concat(cameraName, ".").concat(format));
184
+ return Object.assign(output, (_a = {}, _a[cameraName] = file, _a));
185
+ }, {});
186
+ return [4 /*yield*/, api_1.default.configurations.save({
187
+ assetId: window.threekit.player.assetId,
188
+ configuration: window.threekit.configurator.getConfiguration(),
189
+ attachments: attachments,
190
+ })];
224
191
  case 7:
225
- savedSnapshots = _c.sent();
226
- return [2 /*return*/, Promise.resolve(savedSnapshots)];
192
+ response_1 = _d.sent();
193
+ urlsArray = Object.keys(response_1.data.attachments).map(function (key) {
194
+ return "".concat(threekitDomain, "/api/configurations/").concat(response_1.data.shortId, "/files/").concat(key, "?orgId=").concat(orgId);
195
+ });
196
+ return [2 /*return*/, Promise.resolve(urlsArray)];
227
197
  case 8:
228
198
  snapshotsRaw.forEach(function (snapshotBlob, idx) {
229
199
  var cameraName = (camerasList === null || camerasList === void 0 ? void 0 : camerasList[idx])
230
200
  ? "-".concat((0, utils_1.regularToKebabCase)(camerasList[idx] || 'default'))
231
201
  : '';
232
- downloadSnapshot(snapshotBlob, "".concat(filename).concat(cameraName, ".").concat(format));
202
+ (0, utils_1.downloadSnapshot)(snapshotBlob, "".concat(filename).concat(cameraName, ".").concat(format));
233
203
  });
234
204
  return [2 /*return*/, Promise.resolve()];
235
205
  case 9:
@@ -244,7 +214,6 @@ var Snapshots = /** @class */ (function () {
244
214
  });
245
215
  return [2 /*return*/, Promise.resolve(snapshotFiles)];
246
216
  case 11: return [2 /*return*/, Promise.resolve(snapshotsRaw)];
247
- case 12: return [2 /*return*/];
248
217
  }
249
218
  });
250
219
  }); };
@@ -1,17 +1,13 @@
1
1
  import threekitAPI from '../api';
2
- import { IThreekitPlayer, IMetadata, IConfiguration, ISetConfiguration } from '../threekit';
2
+ import { IThreekitPlayer, IConfiguration, ISetConfiguration } from '../threekit';
3
3
  import { IWishlist } from './Wishlist';
4
4
  import Snapshots from './Snapshots';
5
+ import { ISaveConfiguration } from '../api/configurations';
5
6
  interface ITreble {
6
7
  player: IThreekitPlayer;
7
8
  orgId: string;
8
9
  initialConfiguration: IConfiguration;
9
10
  }
10
- export interface ISaveConfigurationConfig {
11
- customerId?: string;
12
- metadata?: IMetadata;
13
- productVersion?: string;
14
- }
15
11
  declare class Treble {
16
12
  _api: typeof threekitAPI;
17
13
  _player: IThreekitPlayer;
@@ -20,7 +16,7 @@ declare class Treble {
20
16
  private _snapshots;
21
17
  takeSnapshots: Snapshots['takeSnapshots'];
22
18
  constructor({ player, orgId, initialConfiguration }: ITreble);
23
- saveConfiguration: (config?: ISaveConfigurationConfig | undefined) => Promise<{
19
+ saveConfiguration: (config?: Omit<ISaveConfiguration, "configuration"> | undefined) => Promise<{
24
20
  resumableUrl: string;
25
21
  } & import("../http/configurations").IConfigurationResponse & {
26
22
  thumbnail: string;
@@ -50,22 +50,21 @@ var Treble = /** @class */ (function () {
50
50
  var _this = this;
51
51
  var player = _a.player, orgId = _a.orgId, initialConfiguration = _a.initialConfiguration;
52
52
  this.saveConfiguration = function (config) { return __awaiter(_this, void 0, void 0, function () {
53
- var threekitDomain, _a, customerId, metadata, productVersion, files, response, params, url;
53
+ var threekitDomain, _a, customerId, metadata, productVersion, attachments, response, params, url;
54
54
  var _b;
55
55
  var _c;
56
56
  return __generator(this, function (_d) {
57
57
  switch (_d.label) {
58
58
  case 0:
59
59
  threekitDomain = connection_1.default.getConnection().threekitDomain;
60
- _a = Object.assign({}, config), customerId = _a.customerId, metadata = _a.metadata, productVersion = _a.productVersion;
61
- files = undefined;
60
+ _a = Object.assign({}, config), customerId = _a.customerId, metadata = _a.metadata, productVersion = _a.productVersion, attachments = _a.attachments;
62
61
  return [4 /*yield*/, api_1.default.configurations.save({
63
62
  assetId: window.threekit.player.assetId,
64
63
  configuration: window.threekit.configurator.getConfiguration(),
65
64
  customerId: customerId,
66
65
  metadata: metadata,
67
66
  productVersion: productVersion,
68
- files: files,
67
+ attachments: attachments,
69
68
  })];
70
69
  case 1:
71
70
  response = _d.sent();
@@ -1,9 +1,9 @@
1
1
  import { IConfigurationResponse } from '../http/configurations';
2
- import { ISaveConfigurationConfig } from './Treble';
2
+ import { ISaveConfiguration } from '../api/configurations';
3
3
  export declare type WishlistArray = Array<IConfigurationResponse>;
4
4
  export interface IWishlist {
5
5
  getWishlist(): Promise<Array<IConfigurationResponse>>;
6
- addItem(config?: ISaveConfigurationConfig): Promise<Array<IConfigurationResponse>>;
6
+ addItem(config?: Omit<ISaveConfiguration, 'configurator'>): Promise<Array<IConfigurationResponse>>;
7
7
  removeItemByIdx(idx: number): Array<IConfigurationResponse>;
8
8
  clearWishlist(): Array<IConfigurationResponse>;
9
9
  }
@@ -11,7 +11,7 @@ declare class Wishlist implements IWishlist {
11
11
  _wishlistKey: string;
12
12
  constructor(orgId: string);
13
13
  getWishlist: () => Promise<WishlistArray>;
14
- addItem: (config?: ISaveConfigurationConfig | undefined) => Promise<WishlistArray>;
14
+ addItem: (config?: Omit<ISaveConfiguration, "configurator"> | undefined) => Promise<WishlistArray>;
15
15
  removeItemByIdx: (idx: number) => WishlistArray;
16
16
  clearWishlist: () => WishlistArray;
17
17
  }
@@ -128,6 +128,7 @@ var Wishlist = /** @class */ (function () {
128
128
  };
129
129
  this._wishlistKey = "".concat(constants_1.WISHLIST_LOCALSTORAGE_KEY, "_").concat(orgId);
130
130
  this.getWishlist();
131
+ return this;
131
132
  }
132
133
  return Wishlist;
133
134
  }());
@@ -1,14 +1,13 @@
1
1
  import { IConfigurationResponse } from '../http/configurations';
2
2
  import { IConfiguration, IMetadata } from '../threekit';
3
- interface ISaveConfiguration {
3
+ export interface ISaveConfiguration {
4
4
  assetId: string;
5
5
  customerId?: string;
6
6
  configuration: IConfiguration;
7
7
  metadata?: IMetadata;
8
8
  productVersion?: string;
9
- files?: File;
9
+ attachments?: Record<string, File>;
10
10
  }
11
11
  export declare const save: (saveConfig: ISaveConfiguration) => Promise<import("axios").AxiosResponse<IConfigurationResponse>>;
12
12
  export declare const fetch: (configurationId: string) => Promise<import("axios").AxiosResponse<IConfigurationResponse>>;
13
13
  export declare const fetchAll: () => Promise<IConfigurationResponse[]>;
14
- export {};
@@ -42,30 +42,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
42
42
  exports.fetchAll = exports.fetch = exports.save = void 0;
43
43
  var http_1 = __importDefault(require("../http"));
44
44
  var save = function (saveConfig) { return __awaiter(void 0, void 0, void 0, function () {
45
- var assetId, customerId, configuration, metadata, productVersion, files, error, fd;
45
+ var assetId, customerId, configuration, metadata, productVersion, attachments, error, fd, attachmentsPrepped_1;
46
46
  return __generator(this, function (_a) {
47
- switch (_a.label) {
48
- case 0:
49
- assetId = saveConfig.assetId, customerId = saveConfig.customerId, configuration = saveConfig.configuration, metadata = saveConfig.metadata, productVersion = saveConfig.productVersion, files = saveConfig.files;
50
- if (!assetId)
51
- error = 'Requires Asset Id';
52
- if (!configuration)
53
- error = 'Requires a configuration';
54
- if (error)
55
- throw new Error(error);
56
- fd = new FormData();
57
- fd.append('productId', assetId);
58
- fd.append('variant', JSON.stringify(configuration));
59
- fd.append('productVersion', productVersion || 'v1');
60
- if (metadata && Object.keys(metadata))
61
- fd.append('metadata', JSON.stringify(metadata));
62
- if (customerId)
63
- fd.append('customerId', customerId);
64
- if (files)
65
- fd.append('files', files);
66
- return [4 /*yield*/, http_1.default.configurations.postConfiguration(fd)];
67
- case 1: return [2 /*return*/, _a.sent()];
47
+ assetId = saveConfig.assetId, customerId = saveConfig.customerId, configuration = saveConfig.configuration, metadata = saveConfig.metadata, productVersion = saveConfig.productVersion, attachments = saveConfig.attachments;
48
+ if (!assetId)
49
+ error = 'Requires Asset Id';
50
+ if (!configuration)
51
+ error = 'Requires a configuration';
52
+ if (error)
53
+ throw new Error(error);
54
+ fd = new FormData();
55
+ fd.append('productId', assetId);
56
+ fd.append('variant', JSON.stringify(configuration));
57
+ fd.append('productVersion', productVersion || 'v1');
58
+ if (metadata && Object.keys(metadata))
59
+ fd.append('metadata', JSON.stringify(metadata));
60
+ if (customerId)
61
+ fd.append('customerId', customerId);
62
+ if (attachments && Object.keys(attachments).length) {
63
+ attachmentsPrepped_1 = {};
64
+ Object.entries(attachments).forEach(function (_a) {
65
+ var _b;
66
+ var key = _a[0], file = _a[1];
67
+ fd.append('files', file);
68
+ attachmentsPrepped_1 = Object.assign({}, attachmentsPrepped_1, (_b = {},
69
+ _b[key] = file.name,
70
+ _b));
71
+ });
72
+ fd.append('attachments', JSON.stringify(attachmentsPrepped_1));
68
73
  }
74
+ return [2 /*return*/, http_1.default.configurations.postConfiguration(fd)];
69
75
  });
70
76
  }); };
71
77
  exports.save = save;
@@ -0,0 +1,17 @@
1
+ import { ICoordinates } from '../../threekit';
2
+ interface NodeConfig {
3
+ nodeId: string;
4
+ paddingStart: number;
5
+ paddingEnd: number;
6
+ delay: number;
7
+ duration: number;
8
+ translation: ICoordinates;
9
+ rotation: ICoordinates;
10
+ scale: ICoordinates;
11
+ }
12
+ interface AnimationConfig {
13
+ duration: number;
14
+ nodes: Array<NodeConfig>;
15
+ }
16
+ declare const useAnimation: (animationConfig: AnimationConfig) => undefined[] | (boolean | (() => Promise<void>))[];
17
+ export default useAnimation;
@@ -0,0 +1,264 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (_) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ var react_1 = require("react");
54
+ var useThreekitInitStatus_1 = __importDefault(require("../useThreekitInitStatus"));
55
+ var utils_1 = require("../../utils");
56
+ var prepAnimateConfig = function (config) {
57
+ return new Promise(function (resolve) { return __awaiter(void 0, void 0, void 0, function () {
58
+ var totalDuration, player, assetId, nodesRaw, nodes;
59
+ return __generator(this, function (_a) {
60
+ switch (_a.label) {
61
+ case 0:
62
+ totalDuration = config.duration * 1000 || 0;
63
+ player = window.threekit.player.enableApi('player');
64
+ return [4 /*yield*/, player.getAssetInstance(window.threekit.player.scene.find({
65
+ id: window.threekit.player.instanceId,
66
+ plug: 'Proxy',
67
+ property: 'asset',
68
+ }))];
69
+ case 1:
70
+ assetId = _a.sent();
71
+ nodesRaw = Object.entries(config.nodes).reduce(function (output, _a) {
72
+ var _b;
73
+ var name = _a[0], nodeData = _a[1];
74
+ var nodeId = window.threekit.player.scene.get({
75
+ from: assetId,
76
+ name: name,
77
+ }).id;
78
+ var node = Object.assign({ nodeId: nodeId }, { duration: (nodeData.duration || config.duration || 0) * 1000 }, { paddingStart: (nodeData.delay || 0) * 1000 }, 'translation' in nodeData
79
+ ? {
80
+ translation: [
81
+ window.threekit.player.scene.get({
82
+ from: assetId,
83
+ id: nodeId,
84
+ plug: 'Transform',
85
+ property: 'translation',
86
+ }),
87
+ Object.assign({ x: 0, y: 0, z: 0 }, nodeData.translation),
88
+ ],
89
+ }
90
+ : {}, 'rotation' in nodeData
91
+ ? {
92
+ rotation: [
93
+ window.threekit.player.scene.get({
94
+ from: assetId,
95
+ id: nodeId,
96
+ plug: 'Transform',
97
+ property: 'rotation',
98
+ }),
99
+ Object.assign({ x: 0, y: 0, z: 0 }, nodeData.rotation),
100
+ ],
101
+ }
102
+ : {}, 'scale' in nodeData
103
+ ? {
104
+ scale: [
105
+ window.threekit.player.scene.get({
106
+ from: assetId,
107
+ id: nodeId,
108
+ plug: 'Transform',
109
+ property: 'scale',
110
+ }),
111
+ Object.assign({ x: 0, y: 0, z: 0 }, nodeData.scale),
112
+ ],
113
+ }
114
+ : {});
115
+ var duration = node.duration + node.paddingStart;
116
+ if (duration > totalDuration)
117
+ totalDuration = duration;
118
+ return Object.assign(output, (_b = {}, _b[name] = node, _b));
119
+ }, {});
120
+ nodes = Object.entries(nodesRaw).reduce(function (output, _a) {
121
+ var _b;
122
+ var nodeName = _a[0], nodeData = _a[1];
123
+ var paddingEnd = 0;
124
+ if (totalDuration !== nodeData.duration + nodeData.paddingStart)
125
+ paddingEnd =
126
+ totalDuration - (nodeData.duration + nodeData.paddingStart);
127
+ return Object.assign(output, (_b = {},
128
+ _b[nodeName] = __assign(__assign({}, nodeData), { paddingEnd: paddingEnd }),
129
+ _b));
130
+ }, {});
131
+ resolve([assetId, totalDuration, nodes]);
132
+ return [2 /*return*/];
133
+ }
134
+ });
135
+ }); });
136
+ };
137
+ var useAnimation = function (animationConfig) {
138
+ var _a = (0, react_1.useState)(false), animationInProgress = _a[0], setAnimationInProgress = _a[1];
139
+ var ref = (0, react_1.useRef)({
140
+ assetId: undefined,
141
+ startTime: 0,
142
+ totalDuration: 0,
143
+ nodes: {},
144
+ isTransformed: false,
145
+ });
146
+ var isLoaded = (0, useThreekitInitStatus_1.default)();
147
+ if (!isLoaded)
148
+ return [undefined, undefined];
149
+ var animateFrame = function (timestamp) {
150
+ // if (startTime.current === undefined) startTime.current = timestamp;
151
+ // const elapsed = timestamp - startTime.current;
152
+ if (ref.current.startTime === undefined)
153
+ ref.current.startTime = timestamp;
154
+ var elapsed = timestamp - ref.current.startTime;
155
+ Object.values(ref.current.nodes).forEach(function (nodeConfig) {
156
+ if (!ref.current.isTransformed) {
157
+ // If its too early we don't animate
158
+ if (elapsed < nodeConfig.paddingStart)
159
+ return;
160
+ // If its too early we don't animate
161
+ if (elapsed > nodeConfig.duration + nodeConfig.paddingStart)
162
+ return;
163
+ }
164
+ else if (ref.current.isTransformed) {
165
+ // If its too early we don't animate
166
+ if (elapsed < nodeConfig.paddingEnd)
167
+ return;
168
+ // If its too early we don't animate
169
+ if (elapsed > nodeConfig.duration + nodeConfig.paddingEnd)
170
+ return;
171
+ }
172
+ var progressTime = !ref.current.isTransformed
173
+ ? elapsed - nodeConfig.paddingStart
174
+ : elapsed - nodeConfig.paddingEnd;
175
+ var animationPercent = (0, utils_1.easeInOutCubic)(progressTime / nodeConfig.duration);
176
+ var translation;
177
+ var rotation;
178
+ var scale;
179
+ if ('translation' in nodeConfig) {
180
+ translation = Object.keys(nodeConfig.translation[1]).reduce(function (output, axis) {
181
+ var _a;
182
+ var value = !ref.current.isTransformed
183
+ ? nodeConfig.translation[0][axis] +
184
+ nodeConfig.translation[1][axis] * animationPercent
185
+ : nodeConfig.translation[1][axis] +
186
+ nodeConfig.translation[0][axis] -
187
+ nodeConfig.translation[1][axis] * animationPercent;
188
+ return Object.assign(output, (_a = {}, _a[axis] = value, _a));
189
+ }, {});
190
+ window.threekit.player.scene.set({
191
+ from: ref.current.assetId,
192
+ id: nodeConfig.nodeId,
193
+ plug: 'Transform',
194
+ property: 'translation',
195
+ }, translation);
196
+ }
197
+ if ('rotation' in nodeConfig) {
198
+ rotation = Object.keys(nodeConfig.rotation[1]).reduce(function (output, axis) {
199
+ var _a;
200
+ var value = !ref.current.isTransformed
201
+ ? nodeConfig.rotation[0][axis] +
202
+ nodeConfig.rotation[1][axis] * animationPercent
203
+ : nodeConfig.rotation[1][axis] +
204
+ nodeConfig.rotation[0][axis] -
205
+ nodeConfig.rotation[1][axis] * animationPercent;
206
+ return Object.assign(output, (_a = {}, _a[axis] = value, _a));
207
+ }, {});
208
+ window.threekit.player.scene.set({
209
+ from: ref.current.assetId,
210
+ id: nodeConfig.nodeId,
211
+ plug: 'Transform',
212
+ property: 'rotation',
213
+ }, rotation);
214
+ }
215
+ if ('scale' in nodeConfig) {
216
+ scale = Object.keys(nodeConfig.scale[1]).reduce(function (output, axis) {
217
+ var _a;
218
+ var value = !ref.current.isTransformed
219
+ ? nodeConfig.scale[0][axis] +
220
+ nodeConfig.scale[1][axis] * animationPercent
221
+ : nodeConfig.scale[1][axis] +
222
+ nodeConfig.scale[0][axis] -
223
+ nodeConfig.scale[1][axis] * animationPercent;
224
+ return Object.assign(output, (_a = {}, _a[axis] = value, _a));
225
+ }, {});
226
+ window.threekit.player.scene.set({
227
+ from: ref.current.assetId,
228
+ id: nodeConfig.nodeId,
229
+ plug: 'Transform',
230
+ property: 'scale',
231
+ }, scale);
232
+ }
233
+ });
234
+ if (elapsed < ref.current.totalDuration) {
235
+ window.requestAnimationFrame(animateFrame);
236
+ }
237
+ else {
238
+ setAnimationInProgress(false);
239
+ ref.current.startTime = undefined;
240
+ ref.current.isTransformed = !ref.current.isTransformed;
241
+ }
242
+ };
243
+ var handleClickAnimate = function () { return __awaiter(void 0, void 0, void 0, function () {
244
+ var _a;
245
+ return __generator(this, function (_b) {
246
+ switch (_b.label) {
247
+ case 0:
248
+ ref.current.startTime = undefined;
249
+ if (!!ref.current.nodes) return [3 /*break*/, 2];
250
+ return [4 /*yield*/, prepAnimateConfig(animationConfig)];
251
+ case 1:
252
+ _a = _b.sent(), ref.current.assetId = _a[0], ref.current.totalDuration = _a[1], ref.current.nodes = _a[2];
253
+ ref.current.isTransformed = false;
254
+ _b.label = 2;
255
+ case 2:
256
+ setAnimationInProgress(true);
257
+ window.requestAnimationFrame(animateFrame);
258
+ return [2 /*return*/];
259
+ }
260
+ });
261
+ }); };
262
+ return [animationInProgress, handleClickAnimate];
263
+ };
264
+ exports.default = useAnimation;
@@ -1,7 +1,8 @@
1
- import { ISaveConfigurationConfig, WishlistArray } from '../../Treble';
1
+ import { WishlistArray } from '../../Treble';
2
+ import { ISaveConfiguration } from '../../api/configurations';
2
3
  declare type UseWishlistHook = [
3
4
  WishlistArray,
4
- (config?: ISaveConfigurationConfig) => void,
5
+ (config?: Omit<ISaveConfiguration, 'configurator'>) => void,
5
6
  (idx: number) => void,
6
7
  (idx: number) => void,
7
8
  (idx: number) => void,
@@ -14,9 +14,7 @@ var useWishlist = function () {
14
14
  var wishlist = (0, store_1.useThreekitSelector)(wishlist_1.getWishlist);
15
15
  if (!isLoaded)
16
16
  return [undefined, undefined, undefined, undefined, undefined, undefined];
17
- var handleAddToWishlist = function (config) {
18
- return dispatch((0, wishlist_1.addToWishlist)(config));
19
- };
17
+ var handleAddToWishlist = function (config) { return dispatch((0, wishlist_1.addToWishlist)(config)); };
20
18
  var handleRemoveFromWishlist = function (idx) {
21
19
  dispatch((0, wishlist_1.removeFromWishlist)(idx));
22
20
  message_1.default.info('Item removed from wishlist');
@@ -13,6 +13,7 @@ export interface IConfigurationResponse {
13
13
  shortId: string;
14
14
  thumbnail: null | string;
15
15
  variant: IConfiguration;
16
+ attachments: Record<string, string>;
16
17
  }
17
18
  interface IConfigurationsResponse extends IMultiPageResponse {
18
19
  configurations: Array<IConfigurationResponse>;
package/dist/index.js CHANGED
@@ -39,6 +39,7 @@ var useShare_1 = __importDefault(require("./hooks/useShare"));
39
39
  exports.useShare = useShare_1.default;
40
40
  var usePlayerPortal_1 = __importDefault(require("./hooks/usePlayerPortal"));
41
41
  exports.usePlayerPortal = usePlayerPortal_1.default;
42
+ // import useSingleAnimation from './hooks/useSingleAnimation';
42
43
  // Components
43
44
  var ThreekitProvider_1 = __importDefault(require("./components/ThreekitProvider"));
44
45
  exports.ThreekitProvider = ThreekitProvider_1.default;
@@ -55,9 +55,9 @@ var initPrice = function () { return function (dispatch) { return __awaiter(void
55
55
  case 0: return [4 /*yield*/, api_1.default.price.getPricebooksList()];
56
56
  case 1:
57
57
  pricebook = _a.sent();
58
- id = pricebook[0].id;
59
- currency = pricebook[0].currencies[0];
60
58
  if (pricebook.length) {
59
+ id = pricebook[0].id;
60
+ currency = pricebook[0].currencies[0];
61
61
  dispatch((0, exports.setPriceConfig)({ id: id, currency: currency }));
62
62
  price = window.threekit.configurator.getPrice(id, currency);
63
63
  dispatch((0, exports.setPrice)(price));
@@ -1,5 +1,6 @@
1
1
  import { RootState, ThreekitDispatch } from './index';
2
- import { ISaveConfigurationConfig, WishlistArray } from '../Treble';
2
+ import { WishlistArray } from '../Treble';
3
+ import { ISaveConfiguration } from '../api/configurations';
3
4
  /*****************************************************
4
5
  * Types and Interfaces
5
6
  ****************************************************/
@@ -8,7 +9,7 @@ export declare type WishlistState = WishlistArray;
8
9
  * Standard Selectors
9
10
  ****************************************************/
10
11
  export declare const refreshWishlist: import("@reduxjs/toolkit").AsyncThunk<import("../http/configurations").IConfigurationResponse[], void, {}>;
11
- export declare const addToWishlist: import("@reduxjs/toolkit").AsyncThunk<import("../http/configurations").IConfigurationResponse[], ISaveConfigurationConfig, {}>;
12
+ export declare const addToWishlist: import("@reduxjs/toolkit").AsyncThunk<import("../http/configurations").IConfigurationResponse[], Omit<ISaveConfiguration, "configurator">, {}>;
12
13
  export declare const clearWishlist: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[], import("../http/configurations").IConfigurationResponse[], "treble/wishlist/clear", never, never>;
13
14
  export declare const removeFromWishlist: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[idx: number], import("../http/configurations").IConfigurationResponse[], "treble/wishlist/remove-item", never, never>;
14
15
  /*****************************************************
@@ -20,7 +20,7 @@ export interface ISceneQuery {
20
20
  child?: string;
21
21
  parent?: boolean;
22
22
  includeParent?: boolean;
23
- from?: ISceneQuery;
23
+ from?: string | ISceneQuery;
24
24
  hasPlug?: string;
25
25
  operator?: any;
26
26
  operatorIndex?: number;
@@ -36,6 +36,7 @@ export interface ISceneQuery {
36
36
  hierarchial?: boolean;
37
37
  }
38
38
  export interface ISceneResult {
39
+ id: string;
39
40
  name: string;
40
41
  configurator: IThreekitPrivateConfigurator;
41
42
  }
@@ -160,6 +161,8 @@ export interface IThreekitScene {
160
161
  RENDERED: 'rendered';
161
162
  };
162
163
  get: (query: ISceneQuery | string) => ISceneResult;
164
+ find: (query: ISceneQuery | string) => ISceneResult;
165
+ set: (query: ISceneQuery | string, transform: ICoordinates) => void;
163
166
  }
164
167
  export interface IThreekitTools {
165
168
  addTool: (tool: string) => void;
package/dist/utils.d.ts CHANGED
@@ -22,7 +22,7 @@ export declare const generateLayoutClassName: (component: string, customClassNam
22
22
  export declare const generateToolClassName: (component: string, customClassName?: string | undefined, title?: string | undefined) => string;
23
23
  export declare const generateDisplayClassName: (component: string, customClassName?: string | undefined, title?: string | undefined) => string;
24
24
  export declare const generateFormClassName: (component: string, customClassName?: string | undefined, title?: string | undefined) => string;
25
- export declare const IsJsonString: (str: string) => boolean;
25
+ export declare const isJsonString: (str: string) => boolean;
26
26
  export declare const objectToQueryStr: (obj: Record<string, any>) => string;
27
27
  export declare const getParams: () => Record<string, string | {
28
28
  [key: string]: any;
@@ -43,6 +43,7 @@ export declare const getCameraPosition: (cameraApi: IThreekitCamera) => {
43
43
  export declare const setCameraPosition: (cameraApi: IThreekitCamera, cameraPosition: ICameraPosition) => void;
44
44
  export declare const dataURItoBlob: (dataURI: string) => Blob;
45
45
  export declare const dataURItoFile: (dataURI: string, filename: string) => File;
46
+ export declare const downloadSnapshot: (snapshot: string, filename: string) => Promise<void>;
46
47
  export declare const copyToClipboard: (data: string | Record<string, string | number | boolean>) => void;
47
48
  export declare const easeInOutCubic: (val: number) => number;
48
49
  export declare const metadataValueToObject: (data: string) => Record<string, string | number>;
package/dist/utils.js CHANGED
@@ -1,4 +1,40 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
2
38
  var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
39
  if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
40
  if (ar || !(i in from)) {
@@ -9,7 +45,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
9
45
  return to.concat(ar || Array.prototype.slice.call(from));
10
46
  };
11
47
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.loadTrebleConfig = exports.isUuid = exports.filterFormAttributes = exports.selectionToConfiguration = exports.translateAttribute = exports.createThreekitScriptEl = exports.metadataValueToObject = exports.easeInOutCubic = exports.copyToClipboard = exports.dataURItoFile = exports.dataURItoBlob = exports.setCameraPosition = exports.getCameraPosition = exports.findHitNode = exports.deflateRgb = exports.inflateRgb = exports.rgbToHex = exports.hexToRgb = exports.regularToKebabCase = exports.deepCompare = exports.shallowCompare = exports.getResumableUrl = exports.getParams = exports.objectToQueryStr = exports.IsJsonString = exports.generateFormClassName = exports.generateDisplayClassName = exports.generateToolClassName = exports.generateLayoutClassName = exports.generateWidgetClassName = exports.generateInputClassName = exports.generateClassName = void 0;
48
+ exports.loadTrebleConfig = exports.isUuid = exports.filterFormAttributes = exports.selectionToConfiguration = exports.translateAttribute = exports.createThreekitScriptEl = exports.metadataValueToObject = exports.easeInOutCubic = exports.copyToClipboard = exports.downloadSnapshot = exports.dataURItoFile = exports.dataURItoBlob = exports.setCameraPosition = exports.getCameraPosition = exports.findHitNode = exports.deflateRgb = exports.inflateRgb = exports.rgbToHex = exports.hexToRgb = exports.regularToKebabCase = exports.deepCompare = exports.shallowCompare = exports.getResumableUrl = exports.getParams = exports.objectToQueryStr = exports.isJsonString = exports.generateFormClassName = exports.generateDisplayClassName = exports.generateToolClassName = exports.generateLayoutClassName = exports.generateWidgetClassName = exports.generateInputClassName = exports.generateClassName = void 0;
13
49
  var constants_1 = require("./constants");
14
50
  var generateClassName = function (baseClass) {
15
51
  return function (component, customClassName, title) {
@@ -29,7 +65,7 @@ exports.generateLayoutClassName = (0, exports.generateClassName)(constants_1.LAY
29
65
  exports.generateToolClassName = (0, exports.generateClassName)(constants_1.TOOL_CLASS_NAME);
30
66
  exports.generateDisplayClassName = (0, exports.generateClassName)(constants_1.DISPLAY_CLASS_NAME);
31
67
  exports.generateFormClassName = (0, exports.generateClassName)(constants_1.FORM_CLASS_NAME);
32
- var IsJsonString = function (str) {
68
+ var isJsonString = function (str) {
33
69
  try {
34
70
  JSON.parse(str);
35
71
  }
@@ -38,7 +74,7 @@ var IsJsonString = function (str) {
38
74
  }
39
75
  return true;
40
76
  };
41
- exports.IsJsonString = IsJsonString;
77
+ exports.isJsonString = isJsonString;
42
78
  var isObject = function (object) {
43
79
  return object != null && typeof object === 'object';
44
80
  };
@@ -50,7 +86,7 @@ var objectToQueryStr = function (obj) {
50
86
  if (i)
51
87
  output += '&';
52
88
  if (val !== undefined)
53
- output += "".concat(key, "=").concat((0, exports.IsJsonString)(val) ? JSON.stringify(val) : val);
89
+ output += "".concat(key, "=").concat((0, exports.isJsonString)(val) ? JSON.stringify(val) : val);
54
90
  return output;
55
91
  }, '?');
56
92
  };
@@ -62,7 +98,7 @@ var getParams = function () {
62
98
  if (!(key === null || key === void 0 ? void 0 : key.length))
63
99
  return output;
64
100
  var preppedValue = decodeURIComponent(value);
65
- output[decodeURIComponent(key)] = (0, exports.IsJsonString)(preppedValue)
101
+ output[decodeURIComponent(key)] = (0, exports.isJsonString)(preppedValue)
66
102
  ? JSON.parse(preppedValue)
67
103
  : preppedValue;
68
104
  return output;
@@ -225,6 +261,27 @@ var dataURItoFile = function (dataURI, filename) {
225
261
  return new File([u8arr], filename, { type: mime });
226
262
  };
227
263
  exports.dataURItoFile = dataURItoFile;
264
+ var downloadSnapshot = function (snapshot, filename) { return __awaiter(void 0, void 0, void 0, function () {
265
+ var blob, blobUrl, link, clickHandler;
266
+ return __generator(this, function (_a) {
267
+ blob = (0, exports.dataURItoBlob)(snapshot);
268
+ blobUrl = URL.createObjectURL(blob);
269
+ link = document.createElement('a');
270
+ link.href = blobUrl;
271
+ link.download = filename;
272
+ clickHandler = function () {
273
+ setTimeout(function () {
274
+ URL.revokeObjectURL(blobUrl);
275
+ link.removeEventListener('click', clickHandler);
276
+ }, 150);
277
+ };
278
+ link.addEventListener('click', clickHandler);
279
+ document.body.appendChild(link);
280
+ link.click();
281
+ return [2 /*return*/];
282
+ });
283
+ }); };
284
+ exports.downloadSnapshot = downloadSnapshot;
228
285
  var copyToClipboard = function (data) {
229
286
  if (!data)
230
287
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threekit-tools/treble",
3
- "version": "0.0.57",
3
+ "version": "0.0.58",
4
4
  "author": "Amaan Saeed",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -13,6 +13,14 @@
13
13
  "publishConfig": {
14
14
  "directory": "dist"
15
15
  },
16
+ "jest": {
17
+ "verbose": true,
18
+ "globals": {
19
+ "ts-jest": {
20
+ "tsConfig": "tsconfig.json"
21
+ }
22
+ }
23
+ },
16
24
  "scripts": {
17
25
  "start": "tsc --watch",
18
26
  "build": "tsc",
@@ -21,7 +29,8 @@
21
29
  "build-storybook": "build-storybook -o build",
22
30
  "lint": "eslint ./src",
23
31
  "check-format": "prettier -c ./src",
24
- "format": "prettier --write ./src"
32
+ "format": "prettier --write ./src",
33
+ "test": "jest"
25
34
  },
26
35
  "dependencies": {
27
36
  "@reduxjs/toolkit": "^1.6.2",
@@ -40,18 +49,24 @@
40
49
  "@storybook/addon-links": "^6.3.12",
41
50
  "@storybook/addon-storysource": "^6.3.12",
42
51
  "@storybook/react": "^6.3.12",
52
+ "@testing-library/jest-dom": "^5.16.2",
53
+ "@testing-library/react": "^12.1.3",
54
+ "@types/jest": "^27.4.1",
43
55
  "@types/node": "^16.10.3",
44
56
  "@types/react": ">=17.0.27",
45
57
  "@types/react-dom": ">=17.0.9",
46
58
  "@types/redux-logger": "^3.0.9",
47
59
  "@types/styled-components": "^5.1.15",
48
60
  "@types/webpack-env": "^1.16.3",
61
+ "babel-jest": "^27.5.1",
49
62
  "babel-loader": "^8.2.2",
63
+ "jest": "^27.5.1",
50
64
  "react": ">=17.0.2",
51
65
  "react-dom": ">=17.0.2",
52
66
  "rimraf": "^3.0.2",
53
67
  "serve": "^12.0.1",
54
68
  "storybook-addon-styled-component-theme": "^2.0.0",
69
+ "ts-jest": "^27.1.3",
55
70
  "typescript": ">=4.4.4"
56
71
  },
57
72
  "gitHead": "2e16bcf98f81e16bb1768072fdb3968122e7966f"