@jseeio/jsee 0.8.1 → 0.8.7

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/src/main.js CHANGED
@@ -1010,6 +1010,13 @@ export default class JSEE {
1010
1010
  || (output.alias && res[output.alias])
1011
1011
  if (typeof r !== 'undefined') {
1012
1012
  log(`Updating output: ${output.name} with data: ${typeof r}`)
1013
+ if (output.type === 'file') {
1014
+ const fileValue = utils.normalizeFileOutputValue(output, r)
1015
+ if (typeof fileValue.filename === 'string') output.filename = fileValue.filename
1016
+ if (typeof fileValue.mime === 'string') output.mime = fileValue.mime
1017
+ output.value = fileValue.value
1018
+ return
1019
+ }
1013
1020
  // Convert large base64 image data URLs to blob URLs for efficiency
1014
1021
  if (output.type === 'image' && typeof r === 'string'
1015
1022
  && r.startsWith('data:') && r.length > 50000) {
package/src/utils.js CHANGED
@@ -5,6 +5,41 @@ function isObject (item) {
5
5
  return (typeof item === 'object' && !Array.isArray(item) && item !== null)
6
6
  }
7
7
 
8
+ function isBinaryLike (value) {
9
+ if (!value || typeof value !== 'object') return false
10
+ if (typeof Buffer !== 'undefined' && Buffer.isBuffer && Buffer.isBuffer(value)) return true
11
+ if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) return true
12
+ if (typeof ArrayBuffer !== 'undefined' && ArrayBuffer.isView && ArrayBuffer.isView(value)) return true
13
+ return false
14
+ }
15
+
16
+ function isRecordObject (item) {
17
+ return isObject(item) && !isBinaryLike(item)
18
+ }
19
+
20
+ function normalizeFileOutputValue (output, value) {
21
+ const source = output || {}
22
+ const fallback = {
23
+ value,
24
+ filename: source.filename || source.name,
25
+ mime: source.mime || source.contentType
26
+ }
27
+
28
+ if (!isRecordObject(value)) return fallback
29
+
30
+ let content = value
31
+ if (Object.prototype.hasOwnProperty.call(value, 'content')) content = value.content
32
+ else if (Object.prototype.hasOwnProperty.call(value, 'value')) content = value.value
33
+ else if (Object.prototype.hasOwnProperty.call(value, 'data')) content = value.data
34
+ else if (Object.prototype.hasOwnProperty.call(value, 'url')) content = value.url
35
+
36
+ return {
37
+ value: content,
38
+ filename: value.filename || value.name || fallback.filename,
39
+ mime: value.mime || value.contentType || fallback.mime
40
+ }
41
+ }
42
+
8
43
  function shouldPreserveWorkerValue (value) {
9
44
  if (!value || typeof value !== 'object') {
10
45
  return true
@@ -1291,6 +1326,9 @@ function inferOutputType (key, value) {
1291
1326
 
1292
1327
  module.exports = {
1293
1328
  isObject,
1329
+ isBinaryLike,
1330
+ isRecordObject,
1331
+ normalizeFileOutputValue,
1294
1332
  loadFromDOM,
1295
1333
  getModelFuncJS,
1296
1334
  getModelFuncAPI,
@@ -19,6 +19,27 @@ function stringify (v) {
19
19
  : JSON.stringify(v)
20
20
  }
21
21
 
22
+ function getFileDescriptor (output) {
23
+ const value = output.value
24
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
25
+ return {
26
+ filename: output.filename || output.name || 'output',
27
+ content: value,
28
+ mime: output.mime || output.contentType || 'application/octet-stream'
29
+ }
30
+ }
31
+ const has = (key) => Object.prototype.hasOwnProperty.call(value, key)
32
+ return {
33
+ filename: value.filename || value.name || output.filename || output.name || 'output',
34
+ content: has('content') ? value.content
35
+ : has('value') ? value.value
36
+ : has('data') ? value.data
37
+ : has('url') ? value.url
38
+ : value,
39
+ mime: value.mime || value.contentType || output.mime || output.contentType || 'application/octet-stream'
40
+ }
41
+ }
42
+
22
43
  const component = {
23
44
  props: ['output'],
24
45
  emits: ['notification'],
@@ -260,19 +281,24 @@ const component = {
260
281
  }
261
282
  },
262
283
  downloadFile () {
263
- let filename = this.output.filename || this.output.name || 'output'
264
- let value = this.output.value
284
+ const file = getFileDescriptor(this.output)
285
+ let filename = file.filename
286
+ let value = file.content
265
287
  if (typeof value === 'string' && value.startsWith('data:')) {
266
288
  fetch(value)
267
289
  .then(r => r.blob())
268
290
  .then(blob => saveAs(blob, filename))
269
291
  .catch(() => {
270
- let blob = new Blob([value], { type: 'application/octet-stream' })
292
+ let blob = new Blob([value], { type: file.mime })
271
293
  saveAs(blob, filename)
272
294
  })
273
295
  } else {
296
+ if (typeof Blob !== 'undefined' && value instanceof Blob) {
297
+ saveAs(value, filename)
298
+ return
299
+ }
274
300
  let content = typeof value === 'string' ? value : JSON.stringify(value)
275
- let blob = new Blob([content], { type: 'application/octet-stream' })
301
+ let blob = new Blob([content], { type: file.mime })
276
302
  saveAs(blob, filename)
277
303
  }
278
304
  },
@@ -85,9 +85,10 @@
85
85
  }
86
86
 
87
87
  .jsee-card {
88
- border: 1px solid var(--jsee-border);
88
+ border: 0;
89
89
  border-radius: var(--jsee-radius);
90
90
  background: var(--jsee-card-bg);
91
+ box-shadow: rgba(14, 63, 126, 0.04) 0 0 0 1px, rgba(42, 51, 69, 0.04) 0 1px 1px -0.5px, rgba(42, 51, 70, 0.04) 0 3px 3px -1.5px, rgba(42, 51, 70, 0.04) 0 6px 6px -3px, rgba(14, 63, 126, 0.04) 0 12px 12px -6px, rgba(14, 63, 126, 0.04) 0 24px 24px -12px;
91
92
  position: relative;
92
93
  }
93
94