@veloceapps/sdk 7.0.2-73 → 7.0.2-74

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.
@@ -1765,6 +1765,34 @@ const CONFIG = {
1765
1765
  },
1766
1766
  };
1767
1767
 
1768
+ function btoaSafe(str) {
1769
+ if (!str) {
1770
+ return '';
1771
+ }
1772
+ try {
1773
+ const encoder = new TextEncoder();
1774
+ const charCodes = encoder.encode(str);
1775
+ return window.btoa(String.fromCharCode(...charCodes)) || '';
1776
+ }
1777
+ catch (e) {
1778
+ return '';
1779
+ }
1780
+ }
1781
+ function atobSafe(str) {
1782
+ if (!str) {
1783
+ return '';
1784
+ }
1785
+ try {
1786
+ const binary = window.atob(str);
1787
+ const bytes = Uint8Array.from({ length: binary.length }, (_, index) => binary.charCodeAt(index));
1788
+ const decoder = new TextDecoder('utf-8');
1789
+ return decoder.decode(bytes);
1790
+ }
1791
+ catch (e) {
1792
+ return '';
1793
+ }
1794
+ }
1795
+
1768
1796
  const EXPORTED_CLASS_REGEX = /export class (\S+)/;
1769
1797
  const METADATA_DECORATOR_REGEX = /@ElementDefinition\(([\s\S]+)\)(\n|\r\n|.)*export class/g;
1770
1798
  class UiBuildError extends Error {
@@ -1775,9 +1803,9 @@ class UiBuildError extends Error {
1775
1803
  }
1776
1804
  }
1777
1805
  const elementToMetadata = (el, parentPath) => {
1778
- const script = el.script && window.atob(el.script);
1779
- const template = el.template && window.atob(el.template);
1780
- const styles = el.styles && window.atob(el.styles);
1806
+ const script = atobSafe(el.script);
1807
+ const template = atobSafe(el.template);
1808
+ const styles = atobSafe(el.styles);
1781
1809
  const exportedClassName = script && (EXPORTED_CLASS_REGEX.exec(script) ?? [])[1];
1782
1810
  if (!exportedClassName) {
1783
1811
  throw new Error("Script doesn't have exported class");
@@ -1809,10 +1837,9 @@ const metadataToElement = (metadata, recursive = true) => {
1809
1837
  if (!metadata.script || !EXPORTED_CLASS_REGEX.test(metadata.script)) {
1810
1838
  throw new UiBuildError(`'${metadata.name}' component script is missing an exported class`, metadata);
1811
1839
  }
1812
- const script = metadata.script &&
1813
- window.btoa(metadata.script.replace(EXPORTED_CLASS_REGEX, `@ElementDefinition(${stringifyElementMetadata(normalizedElMetadata)})\nexport class Script`));
1814
- const template = metadata.template && window.btoa(metadata.template);
1815
- const styles = metadata.styles && window.btoa(metadata.styles);
1840
+ const script = btoaSafe(metadata.script?.replace(EXPORTED_CLASS_REGEX, `@ElementDefinition(${stringifyElementMetadata(normalizedElMetadata)})\nexport class Script`));
1841
+ const template = btoaSafe(metadata.template);
1842
+ const styles = btoaSafe(metadata.styles);
1816
1843
  return {
1817
1844
  script,
1818
1845
  template,