@avs/go 0.13.71758 → 0.13.71760

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avs/go",
3
- "version": "0.13.71758",
3
+ "version": "0.13.71760",
4
4
  "description": "AVS Go",
5
5
  "keywords": [
6
6
  "polymer",
@@ -1579,15 +1579,6 @@ export class AvsGoDataViz extends AvsDataSourceMixin(AvsStreamMixin(AvsHttpMixin
1579
1579
 
1580
1580
  this.animationTime = 0;
1581
1581
  this.transformAnimationFrames ??= [];
1582
- if (this.transformAnimationFrames.length > 0) {
1583
- this.$.animationDelay.value = 2;
1584
- this.$.animationDelay.disabled = false;
1585
- this.$.animationSnapshotLabel.innerHTML = this.transformAnimationFrames.length;
1586
- this.$.animationPlay.classList.remove("disabled");
1587
- this.$.animationCopy.classList.remove("disabled");
1588
- this.$.animationClear.classList.remove("disabled");
1589
- this.animationTime = this.transformAnimationFrames[this.transformAnimationFrames.length - 1].time / 1000;
1590
- }
1591
1582
 
1592
1583
  this._resetTimer();
1593
1584
 
@@ -1669,18 +1660,80 @@ export class AvsGoDataViz extends AvsDataSourceMixin(AvsStreamMixin(AvsHttpMixin
1669
1660
  this.animationTime = 0;
1670
1661
  }
1671
1662
 
1672
- _handleAnimationCopy() {
1663
+ async _handleAnimationCopy() {
1664
+ // Convert to JSON, compress and base64url encode
1673
1665
  const json = JSON.stringify(this.transformAnimationFrames);
1674
- const encoded = btoa(json);
1666
+ const compressed = await this._compress(json);
1667
+ const encoded = compressed.toBase64().replace('/', '_').replace('+', '-');
1675
1668
 
1676
1669
  /**
1677
1670
  * A transform animation share event occurred.
1678
1671
  * @event avs-transform-animation-share
1679
1672
  */
1680
-
1681
1673
  this.dispatchEvent(new CustomEvent('avs-transform-animation-share', { detail: encoded }));
1682
1674
  }
1683
1675
 
1676
+ /**
1677
+ * Convert a string to its UTF-8 bytes and compress it.
1678
+ *
1679
+ * @param {string} str
1680
+ * @returns {Promise<Uint8Array>}
1681
+ */
1682
+ async _compress(str) {
1683
+ // Convert the string to a byte stream.
1684
+ const stream = new Blob([str]).stream();
1685
+
1686
+ // Create a compressed stream.
1687
+ const compressedStream = stream.pipeThrough(
1688
+ new CompressionStream("gzip")
1689
+ );
1690
+
1691
+ // Read all the bytes from this stream.
1692
+ const chunks = [];
1693
+ for await (const chunk of compressedStream) {
1694
+ chunks.push(chunk);
1695
+ }
1696
+ return this._concatUint8Arrays(chunks);
1697
+ }
1698
+
1699
+ /**
1700
+ * Decompress bytes into a UTF-8 string.
1701
+ *
1702
+ * @param {Uint8Array} compressedBytes
1703
+ * @returns {Promise<string>}
1704
+ */
1705
+ async _decompress(compressedBytes) {
1706
+ // Convert the bytes to a stream.
1707
+ const stream = new Blob([compressedBytes]).stream();
1708
+
1709
+ // Create a decompressed stream.
1710
+ const decompressedStream = stream.pipeThrough(
1711
+ new DecompressionStream("gzip")
1712
+ );
1713
+
1714
+ // Read all the bytes from this stream.
1715
+ const chunks = [];
1716
+ for await (const chunk of decompressedStream) {
1717
+ chunks.push(chunk);
1718
+ }
1719
+ const stringBytes = await this._concatUint8Arrays(chunks);
1720
+
1721
+ // Convert the bytes to a string.
1722
+ return new TextDecoder().decode(stringBytes);
1723
+ }
1724
+
1725
+ /**
1726
+ * Combine multiple Uint8Arrays into one.
1727
+ *
1728
+ * @param {ReadonlyArray<Uint8Array>} uint8arrays
1729
+ * @returns {Promise<Uint8Array>}
1730
+ */
1731
+ async _concatUint8Arrays(uint8arrays) {
1732
+ const blob = new Blob(uint8arrays);
1733
+ const buffer = await blob.arrayBuffer();
1734
+ return new Uint8Array(buffer);
1735
+ }
1736
+
1684
1737
  _updatePixelRatio(change) {
1685
1738
  const pr = window.devicePixelRatio;
1686
1739
  matchMedia( `(resolution: ${pr}dppx)` ).addEventListener('change', this._updatePixelRatio.bind(this, true), { once: true } );
@@ -1912,10 +1965,35 @@ export class AvsGoDataViz extends AvsDataSourceMixin(AvsStreamMixin(AvsHttpMixin
1912
1965
  /**
1913
1966
  * Change in 'transform-animation' property.
1914
1967
  */
1915
- _transformAnimationValueChanged(newValue, oldValue) {
1968
+ async _transformAnimationValueChanged(newValue, oldValue) {
1916
1969
  if (newValue) {
1917
- const decoded = atob(newValue);
1918
- this.transformAnimationFrames = JSON.parse(decoded);
1970
+ // Decode from base64url, decompress and parse JSON
1971
+ const decoded = Uint8Array.fromBase64(newValue.replaceAll('_', '/').replaceAll('-', '+'));
1972
+ const decompressed = await this._decompress(decoded);
1973
+ this.transformAnimationFrames = JSON.parse(decompressed);
1974
+
1975
+ if (!this.transformAnimationFrames) {
1976
+ this.transformAnimationFrame = [];
1977
+ }
1978
+
1979
+ if (this.transformAnimationFrames.length > 0) {
1980
+ this.$.animationDelay.value = 2;
1981
+ this.$.animationDelay.disabled = false;
1982
+ this.$.animationSnapshotLabel.innerHTML = this.transformAnimationFrames.length;
1983
+ this.$.animationPlay.classList.remove("disabled");
1984
+ this.$.animationCopy.classList.remove("disabled");
1985
+ this.$.animationClear.classList.remove("disabled");
1986
+ this.animationTime = this.transformAnimationFrames[this.transformAnimationFrames.length - 1].time / 1000;
1987
+ }
1988
+ else {
1989
+ this.$.animationDelay.value = 0;
1990
+ this.$.animationDelay.disabled = true;
1991
+ this.$.animationSnapshotLabel.innerHTML = "0";
1992
+ this.$.animationPlay.classList.add("disabled");
1993
+ this.$.animationCopy.classList.add("disabled");
1994
+ this.$.animationClear.classList.add("disabled");
1995
+ this.animationTime = 0;
1996
+ }
1919
1997
  }
1920
1998
  }
1921
1999
 
package/src/constants.js CHANGED
@@ -18,4 +18,4 @@
18
18
  * Advanced Visual Systems Inc. (http://www.avs.com)
19
19
  */
20
20
 
21
- export var VERSION = '0.13.71758';
21
+ export var VERSION = '0.13.71760';