@magicfeedback/popup-sdk 1.14.0 → 1.15.0

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.
@@ -2868,31 +2868,36 @@ function insertPopupLogo(parent, anchor, style, id) {
2868
2868
 
2869
2869
  // src/ui/renderPopup.ts
2870
2870
  var import_native = __toESM(require_magicfeedback_sdk_browser());
2871
- function ensureMagicFeedbackStyles(_popup) {
2872
- const STYLE_ID = "magicfeedback-sdk-styles";
2873
- if (document.getElementById(STYLE_ID)) return;
2874
- const style = document.createElement("style");
2875
- style.id = STYLE_ID;
2876
- style.textContent = style_default;
2877
- document.head.appendChild(style);
2871
+ function ensureStyle(id, css, nonce) {
2872
+ let el = document.getElementById(id);
2873
+ if (el && nonce && el.getAttribute("nonce") !== nonce) {
2874
+ el.remove();
2875
+ el = null;
2876
+ }
2877
+ if (!el) {
2878
+ el = document.createElement("style");
2879
+ el.id = id;
2880
+ if (nonce) el.setAttribute("nonce", nonce);
2881
+ el.textContent = css;
2882
+ document.head.appendChild(el);
2883
+ } else if (el.textContent !== css) {
2884
+ el.textContent = css;
2885
+ }
2886
+ return el;
2887
+ }
2888
+ function ensureMagicFeedbackStyles(nonce) {
2889
+ ensureStyle("magicfeedback-sdk-styles", style_default, nonce);
2878
2890
  }
2879
2891
  var SURVEY_ALIGNMENT_STYLE_ID = "deepdots-survey-alignment";
2880
- function ensureSurveyAlignmentStyles() {
2881
- if (document.getElementById(SURVEY_ALIGNMENT_STYLE_ID)) return;
2882
- const style = document.createElement("style");
2883
- style.id = SURVEY_ALIGNMENT_STYLE_ID;
2884
- style.textContent = `
2892
+ function ensureSurveyAlignmentStyles(nonce) {
2893
+ ensureStyle(SURVEY_ALIGNMENT_STYLE_ID, `
2885
2894
  .deepdots-popup .magicfeedback-container,
2886
2895
  .deepdots-popup .magicfeedback-form,
2887
2896
  .deepdots-popup .magicfeedback-div { padding-left: 0; padding-right: 0; }
2888
- `;
2889
- document.head.appendChild(style);
2897
+ `, nonce);
2890
2898
  }
2891
- function ensureSpinnerStyles(_popup) {
2892
- if (document.getElementById("deepdots-spinner-styles")) return;
2893
- const style = document.createElement("style");
2894
- style.id = "deepdots-spinner-styles";
2895
- style.textContent = `
2899
+ function ensureSpinnerStyles(nonce) {
2900
+ ensureStyle("deepdots-spinner-styles", `
2896
2901
  /* El enunciado trae margin-top:20px del CSS de surveys, que sumaba al hueco de la barra
2897
2902
  de progreso y descompensaba la simetr\xEDa. Solo se anula en el primero: entre preguntas
2898
2903
  de la misma p\xE1gina sigue separando. */
@@ -2900,14 +2905,10 @@ function ensureSpinnerStyles(_popup) {
2900
2905
  @keyframes ddspin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
2901
2906
  .mf-spinner { display:flex; justify-content:center; align-items:center; padding:8px 0; }
2902
2907
  .mf-spinner-circle { width:28px; height:28px; border:3px solid #e0e6ed; border-top-color:#1E293B; border-radius:50%; animation: ddspin 0.9s linear infinite; }
2903
- `;
2904
- document.head.appendChild(style);
2908
+ `, nonce);
2905
2909
  }
2906
- function ensureResponsiveStyles(_popup) {
2907
- if (document.getElementById("deepdots-responsive-styles")) return;
2908
- const style = document.createElement("style");
2909
- style.id = "deepdots-responsive-styles";
2910
- style.textContent = `
2910
+ function ensureResponsiveStyles(nonce) {
2911
+ ensureStyle("deepdots-responsive-styles", `
2911
2912
  /* Responsive adjustments */
2912
2913
  @media (max-width: 640px) {
2913
2914
  .deepdots-popup {
@@ -2940,32 +2941,20 @@ function ensureResponsiveStyles(_popup) {
2940
2941
  overflow-y: auto !important;
2941
2942
  }
2942
2943
  }
2943
- `;
2944
- document.head.appendChild(style);
2944
+ `, nonce);
2945
2945
  }
2946
- function ensureCustomCss(css) {
2946
+ function ensureCustomCss(css, nonce) {
2947
2947
  const STYLE_ID = "deepdots-custom-css";
2948
- const existing = document.getElementById(STYLE_ID);
2949
2948
  if (!css) {
2950
- existing?.remove();
2949
+ document.getElementById(STYLE_ID)?.remove();
2951
2950
  return;
2952
2951
  }
2953
- const el = existing ?? document.createElement("style");
2954
- el.id = STYLE_ID;
2955
- if (el.textContent !== css) el.textContent = css;
2956
- document.head.appendChild(el);
2952
+ document.head.appendChild(ensureStyle(STYLE_ID, css, nonce));
2957
2953
  }
2958
- function ensureFontFace(family, url) {
2954
+ function ensureFontFace(family, url, nonce) {
2959
2955
  const css = buildFontFaceCss(family, url);
2960
2956
  if (!css) return;
2961
- const STYLE_ID = "deepdots-font-face";
2962
- let el = document.getElementById(STYLE_ID);
2963
- if (!el) {
2964
- el = document.createElement("style");
2965
- el.id = STYLE_ID;
2966
- document.head.appendChild(el);
2967
- }
2968
- if (el.textContent !== css) el.textContent = css;
2957
+ ensureStyle("deepdots-font-face", css, nonce);
2969
2958
  }
2970
2959
  function hasFinePointer() {
2971
2960
  return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(pointer: fine)").matches;
@@ -2975,6 +2964,7 @@ async function renderPopup(container, surveyId, productId, actions, emit, onClos
2975
2964
  let stylesInjected = false;
2976
2965
  let pageDepth = 0;
2977
2966
  let onStartPage = false;
2967
+ const cspNonce = options?.cspNonce?.trim() || void 0;
2978
2968
  let labels = getLabels(options?.language);
2979
2969
  let actionLabels = resolveActionLabels(actions, options?.language);
2980
2970
  let direction = directionFor(options?.language);
@@ -3026,7 +3016,7 @@ async function renderPopup(container, surveyId, productId, actions, emit, onClos
3026
3016
  popup.style.fontFamily = familyValue;
3027
3017
  popup.style.setProperty("--deepdots-font", familyValue);
3028
3018
  popup.classList.add("deepdots-has-font");
3029
- if (font.url) ensureFontFace(font.family, font.url);
3019
+ if (font.url) ensureFontFace(font.family, font.url, cspNonce);
3030
3020
  }
3031
3021
  const header = document.createElement("div");
3032
3022
  header.className = "deepdots-popup-header";
@@ -3142,11 +3132,11 @@ async function renderPopup(container, surveyId, productId, actions, emit, onClos
3142
3132
  }
3143
3133
  progressFollowUp.style.display = p.followup ? "inline-block" : "none";
3144
3134
  }
3145
- ensureMagicFeedbackStyles(popup);
3146
- ensureSurveyAlignmentStyles();
3147
- ensureSpinnerStyles(popup);
3148
- ensureResponsiveStyles(popup);
3149
- ensureCustomCss(options?.surveyCss);
3135
+ ensureMagicFeedbackStyles(cspNonce);
3136
+ ensureSurveyAlignmentStyles(cspNonce);
3137
+ ensureSpinnerStyles(cspNonce);
3138
+ ensureResponsiveStyles(cspNonce);
3139
+ ensureCustomCss(options?.surveyCss, cspNonce);
3150
3140
  const containerContent = document.createElement("div");
3151
3141
  containerContent.id = "dd-content";
3152
3142
  containerContent.className = "deepdots-popup-container-content";
@@ -3587,4 +3577,4 @@ export {
3587
3577
  SURVEY_ALIGNMENT_STYLE_ID,
3588
3578
  renderPopup
3589
3579
  };
3590
- //# sourceMappingURL=renderPopup-Z6TENBP6.mjs.map
3580
+ //# sourceMappingURL=renderPopup-CHWH3KHR.mjs.map