@firebase/util 1.11.0-firebase-studio-sdk-integration.9de25069c → 1.11.0-firebase-studio-sdk-integration.927daddb8

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.
@@ -716,6 +716,97 @@ function createMockUserToken(token, projectId) {
716
716
  signature
717
717
  ].join('.');
718
718
  }
719
+ const emulatorStatus = {};
720
+ // Checks whether any products are running on an emulator
721
+ function getEmulatorSummary() {
722
+ const summary = {
723
+ prod: [],
724
+ emulator: []
725
+ };
726
+ for (const key of Object.keys(emulatorStatus)) {
727
+ if (emulatorStatus[key]) {
728
+ summary.emulator.push(key);
729
+ }
730
+ else {
731
+ summary.prod.push(key);
732
+ }
733
+ }
734
+ return summary;
735
+ }
736
+ function getOrCreateEl(id) {
737
+ let parentDiv = document.getElementById(id);
738
+ let created = false;
739
+ if (!parentDiv) {
740
+ parentDiv = document.createElement('div');
741
+ parentDiv.setAttribute('id', id);
742
+ created = true;
743
+ }
744
+ return { created, element: parentDiv };
745
+ }
746
+ /**
747
+ * Updates Emulator Banner. Primarily used for Firebase Studio
748
+ * @param name
749
+ * @param isRunningEmulator
750
+ * @public
751
+ */
752
+ function updateEmulatorBanner(name, isRunningEmulator) {
753
+ if (typeof window === 'undefined' ||
754
+ typeof document === 'undefined' ||
755
+ emulatorStatus[name] === isRunningEmulator) {
756
+ return;
757
+ }
758
+ emulatorStatus[name] = isRunningEmulator;
759
+ const bannerId = '__firebase__banner';
760
+ const summary = getEmulatorSummary();
761
+ const showError = summary.prod.length > 0;
762
+ function tearDown() {
763
+ const element = document.getElementById(bannerId);
764
+ if (element) {
765
+ element.remove();
766
+ }
767
+ }
768
+ function setupDom() {
769
+ const banner = getOrCreateEl(bannerId);
770
+ const firebaseText = document.getElementById('__firebase__text') ||
771
+ document.createElement('span');
772
+ if (banner.created) {
773
+ // update styles
774
+ const bannerEl = banner.element;
775
+ bannerEl.style.display = 'flex';
776
+ bannerEl.style.background = '#7faaf0';
777
+ bannerEl.style.position = 'absolute';
778
+ bannerEl.style.bottom = '5px';
779
+ bannerEl.style.left = '5px';
780
+ bannerEl.style.padding = '.5em';
781
+ bannerEl.style.borderRadius = '5px';
782
+ bannerEl.style.alignContent = 'center';
783
+ const closeBtn = document.createElement('span');
784
+ closeBtn.style.cursor = 'pointer';
785
+ closeBtn.style.paddingLeft = '5px';
786
+ closeBtn.innerHTML = ' ×';
787
+ closeBtn.onclick = () => {
788
+ tearDown();
789
+ };
790
+ bannerEl.appendChild(firebaseText);
791
+ bannerEl.appendChild(closeBtn);
792
+ document.body.appendChild(bannerEl);
793
+ }
794
+ if (showError) {
795
+ banner.element.style.background = '#cd5c5c';
796
+ firebaseText.innerText = `Product${summary.prod.length > 0 ? 's' : ''} Running in Production: ${summary.prod.join(', ')}`;
797
+ }
798
+ else {
799
+ firebaseText.innerText = 'Running in this workspace';
800
+ }
801
+ firebaseText.setAttribute('id', '__firebase__text');
802
+ }
803
+ if (document.readyState === 'loading') {
804
+ window.addEventListener('DOMContentLoaded', setupDom);
805
+ }
806
+ else {
807
+ setupDom();
808
+ }
809
+ }
719
810
 
720
811
  /**
721
812
  * @license
@@ -2227,6 +2318,7 @@ exports.safeGet = safeGet;
2227
2318
  exports.stringLength = stringLength;
2228
2319
  exports.stringToByteArray = stringToByteArray;
2229
2320
  exports.stringify = stringify;
2321
+ exports.updateEmulatorBanner = updateEmulatorBanner;
2230
2322
  exports.validateArgCount = validateArgCount;
2231
2323
  exports.validateCallback = validateCallback;
2232
2324
  exports.validateContextObject = validateContextObject;