@tagadapay/plugin-sdk 3.0.9 → 3.0.12

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * TagadaPay External Tracker v3.0.9
2
+ * TagadaPay External Tracker v3.0.12
3
3
  * CDN Bundle - Standalone tracking for external pages (Debug Build)
4
4
  * @license MIT
5
5
  */
@@ -4634,99 +4634,224 @@ var TagadaTrackerBundle = (() => {
4634
4634
  * Used by config editor to highlight elements in preview without altering the element's style
4635
4635
  */
4636
4636
  applyStylesToElement(elementId, styles) {
4637
- var _a;
4638
4637
  if (typeof document === "undefined") return;
4639
- const element = document.querySelector('[editor-id~="'.concat(elementId, '"]'));
4640
- if (!element) {
4641
- if (this.state.debugMode) {
4642
- console.warn('[TagadaClient] Element with editor-id containing "'.concat(elementId, '" not found'));
4643
- }
4644
- return;
4638
+ const staticHighlightId = "tagada-editor-highlight";
4639
+ const existingHighlight = document.getElementById(staticHighlightId);
4640
+ if (existingHighlight) {
4641
+ existingHighlight.remove();
4645
4642
  }
4646
- const voidElements = /* @__PURE__ */ new Set([
4647
- "area",
4648
- "base",
4649
- "br",
4650
- "col",
4651
- "embed",
4652
- "hr",
4653
- "img",
4654
- "input",
4655
- "link",
4656
- "meta",
4657
- "param",
4658
- "source",
4659
- "track",
4660
- "wbr"
4661
- ]);
4662
- const isVoidElement = voidElements.has(element.tagName.toLowerCase());
4663
- let targetElement = element;
4664
- let wrapper = null;
4665
- if (isVoidElement) {
4666
- const parent = element.parentElement;
4667
- const existingWrapper = parent == null ? void 0 : parent.getAttribute("data-tagada-highlight-wrapper");
4668
- if (existingWrapper === "true") {
4669
- targetElement = parent;
4670
- } else {
4671
- wrapper = document.createElement("div");
4672
- wrapper.setAttribute("data-tagada-highlight-wrapper", "true");
4673
- const computedStyle2 = window.getComputedStyle(element);
4674
- const elementDisplay = computedStyle2.display;
4675
- if (elementDisplay === "inline") {
4676
- wrapper.style.display = "inline-block";
4643
+ const applyToElement = (element) => {
4644
+ var _a;
4645
+ const voidElements = /* @__PURE__ */ new Set([
4646
+ "area",
4647
+ "base",
4648
+ "br",
4649
+ "col",
4650
+ "embed",
4651
+ "hr",
4652
+ "img",
4653
+ "input",
4654
+ "link",
4655
+ "meta",
4656
+ "param",
4657
+ "source",
4658
+ "track",
4659
+ "wbr"
4660
+ ]);
4661
+ const isVoidElement = voidElements.has(element.tagName.toLowerCase());
4662
+ let targetElement = element;
4663
+ if (isVoidElement) {
4664
+ const parent = element.parentElement;
4665
+ const existingWrapper = parent == null ? void 0 : parent.getAttribute("data-tagada-highlight-wrapper");
4666
+ if (existingWrapper === "true" && parent instanceof HTMLElement) {
4667
+ targetElement = parent;
4677
4668
  } else {
4678
- wrapper.style.display = elementDisplay;
4669
+ const newWrapper = document.createElement("div");
4670
+ newWrapper.setAttribute("data-tagada-highlight-wrapper", "true");
4671
+ const computedStyle2 = window.getComputedStyle(element);
4672
+ const elementDisplay = computedStyle2.display;
4673
+ if (elementDisplay === "inline") {
4674
+ newWrapper.style.display = "inline-block";
4675
+ } else {
4676
+ newWrapper.style.display = elementDisplay;
4677
+ }
4678
+ newWrapper.style.position = "relative";
4679
+ if (elementDisplay === "inline" || elementDisplay.includes("inline")) {
4680
+ const verticalAlign = computedStyle2.verticalAlign;
4681
+ if (verticalAlign && verticalAlign !== "baseline") {
4682
+ newWrapper.style.verticalAlign = verticalAlign;
4683
+ }
4684
+ }
4685
+ const spacingProperties = [
4686
+ // Width and height
4687
+ "width",
4688
+ "height",
4689
+ "minWidth",
4690
+ "minHeight",
4691
+ "maxWidth",
4692
+ "maxHeight",
4693
+ // Flex properties
4694
+ "flex",
4695
+ "flexGrow",
4696
+ "flexShrink",
4697
+ "flexBasis",
4698
+ // Grid properties
4699
+ "gridColumn",
4700
+ "gridRow",
4701
+ "gridColumnStart",
4702
+ "gridColumnEnd",
4703
+ "gridRowStart",
4704
+ "gridRowEnd",
4705
+ "gridArea",
4706
+ // Alignment properties
4707
+ "alignSelf",
4708
+ "justifySelf",
4709
+ // Box sizing
4710
+ "boxSizing",
4711
+ // Gap (for grid/flex)
4712
+ "gap",
4713
+ "rowGap",
4714
+ "columnGap",
4715
+ // Order (for flex/grid)
4716
+ "order",
4717
+ // Aspect ratio
4718
+ "aspectRatio"
4719
+ ];
4720
+ spacingProperties.forEach((prop) => {
4721
+ const camelProp = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
4722
+ const value = computedStyle2.getPropertyValue(camelProp);
4723
+ if (value && value.trim() !== "") {
4724
+ if (prop === "flex" && value !== "none" && value !== "0 1 auto") {
4725
+ newWrapper.style.flex = value;
4726
+ } else if (prop === "boxSizing") {
4727
+ newWrapper.style.boxSizing = value;
4728
+ } else {
4729
+ newWrapper.style.setProperty(camelProp, value);
4730
+ }
4731
+ }
4732
+ });
4733
+ if (element.style) {
4734
+ const inlineSpacingProps = [
4735
+ "width",
4736
+ "height",
4737
+ "min-width",
4738
+ "min-height",
4739
+ "max-width",
4740
+ "max-height",
4741
+ "flex",
4742
+ "flex-grow",
4743
+ "flex-shrink",
4744
+ "flex-basis",
4745
+ "grid-column",
4746
+ "grid-row",
4747
+ "grid-column-start",
4748
+ "grid-column-end",
4749
+ "grid-row-start",
4750
+ "grid-row-end",
4751
+ "grid-area",
4752
+ "align-self",
4753
+ "justify-self",
4754
+ "box-sizing",
4755
+ "gap",
4756
+ "row-gap",
4757
+ "column-gap",
4758
+ "order",
4759
+ "aspect-ratio"
4760
+ ];
4761
+ inlineSpacingProps.forEach((prop) => {
4762
+ const inlineValue = element.style.getPropertyValue(prop);
4763
+ if (inlineValue) {
4764
+ newWrapper.style.setProperty(prop, inlineValue);
4765
+ }
4766
+ });
4767
+ }
4768
+ (_a = element.parentNode) == null ? void 0 : _a.insertBefore(newWrapper, element);
4769
+ newWrapper.appendChild(element);
4770
+ targetElement = newWrapper;
4679
4771
  }
4680
- wrapper.style.position = "relative";
4681
- if (elementDisplay === "inline" || elementDisplay.includes("inline")) {
4682
- const verticalAlign = computedStyle2.verticalAlign;
4683
- if (verticalAlign && verticalAlign !== "baseline") {
4684
- wrapper.style.verticalAlign = verticalAlign;
4772
+ }
4773
+ const computedStyle = getComputedStyle(isVoidElement ? element : targetElement);
4774
+ if (targetElement.style.position === "static" || !targetElement.style.position) {
4775
+ targetElement.style.position = "relative";
4776
+ }
4777
+ const highlightDiv = document.createElement("div");
4778
+ highlightDiv.id = staticHighlightId;
4779
+ highlightDiv.style.position = "absolute";
4780
+ highlightDiv.style.inset = "0";
4781
+ highlightDiv.style.pointerEvents = "none";
4782
+ highlightDiv.style.zIndex = "9999";
4783
+ highlightDiv.style.boxSizing = "border-box";
4784
+ highlightDiv.style.background = "none";
4785
+ highlightDiv.style.border = "none";
4786
+ highlightDiv.style.outline = "none";
4787
+ highlightDiv.style.margin = "0";
4788
+ highlightDiv.style.padding = "0";
4789
+ const borderRadius = computedStyle.borderRadius;
4790
+ if (borderRadius) {
4791
+ highlightDiv.style.borderRadius = borderRadius;
4792
+ }
4793
+ targetElement.appendChild(highlightDiv);
4794
+ const stylesToApply = styles || { boxShadow: "0 0 0 2px rgb(239 68 68)" };
4795
+ Object.entries(stylesToApply).forEach(([property, value]) => {
4796
+ const camelProperty = property.includes("-") ? property.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()) : property;
4797
+ if (property.includes("-")) {
4798
+ highlightDiv.style.setProperty(property, value);
4799
+ } else {
4800
+ highlightDiv.style[camelProperty] = value;
4801
+ }
4802
+ });
4803
+ element.scrollIntoView({ behavior: "smooth", block: "center" });
4804
+ if (this.state.debugMode) {
4805
+ const appliedStyles = Object.entries(stylesToApply).map(([k, v]) => "".concat(k, ": ").concat(v)).join("; ");
4806
+ console.log("[TagadaClient] Applied styles to highlight div of element #".concat(elementId, ":"), appliedStyles);
4807
+ }
4808
+ };
4809
+ const maxAttempts = 5;
4810
+ const intervalMs = 1e3;
4811
+ let attempts = 0;
4812
+ const isElementHidden = (element) => {
4813
+ const style = window.getComputedStyle(element);
4814
+ return style.display === "none" || style.visibility === "hidden" || style.opacity === "0" || element.hidden || element.offsetWidth === 0 || element.offsetHeight === 0;
4815
+ };
4816
+ const findAndApply = () => {
4817
+ const elements = document.querySelectorAll('[editor-id~="'.concat(elementId, '"]'));
4818
+ if (elements.length === 0) {
4819
+ attempts += 1;
4820
+ if (attempts >= maxAttempts) {
4821
+ if (this.state.debugMode) {
4822
+ console.warn(
4823
+ '[TagadaClient] Element with editor-id containing "'.concat(elementId, '" not found after ').concat(maxAttempts, " attempts")
4824
+ );
4685
4825
  }
4826
+ return;
4827
+ }
4828
+ if (this.state.debugMode) {
4829
+ console.warn(
4830
+ '[TagadaClient] Element with editor-id containing "'.concat(elementId, '" not found (attempt ').concat(attempts, "/").concat(maxAttempts, "), retrying in ").concat(intervalMs / 1e3, "s")
4831
+ );
4686
4832
  }
4687
- (_a = element.parentNode) == null ? void 0 : _a.insertBefore(wrapper, element);
4688
- wrapper.appendChild(element);
4689
- targetElement = wrapper;
4833
+ setTimeout(findAndApply, intervalMs);
4834
+ return;
4690
4835
  }
4691
- }
4692
- const computedStyle = getComputedStyle(isVoidElement ? element : targetElement);
4693
- if (targetElement.style.position === "static" || !targetElement.style.position) {
4694
- targetElement.style.position = "relative";
4695
- }
4696
- const staticHighlightId = "tagada-editor-highlight";
4697
- const existingHighlight = document.getElementById(staticHighlightId);
4698
- if (existingHighlight) {
4699
- existingHighlight.remove();
4700
- }
4701
- const highlightDiv = document.createElement("div");
4702
- highlightDiv.id = staticHighlightId;
4703
- highlightDiv.style.position = "absolute";
4704
- highlightDiv.style.inset = "0";
4705
- highlightDiv.style.pointerEvents = "none";
4706
- highlightDiv.style.zIndex = "9999";
4707
- highlightDiv.style.boxSizing = "border-box";
4708
- highlightDiv.style.background = "none";
4709
- highlightDiv.style.border = "none";
4710
- highlightDiv.style.outline = "none";
4711
- const borderRadius = computedStyle.borderRadius;
4712
- if (borderRadius) {
4713
- highlightDiv.style.borderRadius = borderRadius;
4714
- }
4715
- targetElement.appendChild(highlightDiv);
4716
- const stylesToApply = styles || { boxShadow: "0 0 0 2px rgb(239 68 68)" };
4717
- Object.entries(stylesToApply).forEach(([property, value]) => {
4718
- const camelProperty = property.includes("-") ? property.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()) : property;
4719
- if (property.includes("-")) {
4720
- highlightDiv.style.setProperty(property, value);
4836
+ let element = null;
4837
+ if (elements.length === 1) {
4838
+ element = elements[0];
4721
4839
  } else {
4722
- highlightDiv.style[camelProperty] = value;
4840
+ for (let i = 0; i < elements.length; i++) {
4841
+ if (!isElementHidden(elements[i])) {
4842
+ element = elements[i];
4843
+ break;
4844
+ }
4845
+ }
4846
+ if (!element) {
4847
+ element = elements[0];
4848
+ }
4723
4849
  }
4724
- });
4725
- element.scrollIntoView({ behavior: "smooth", block: "center" });
4726
- if (this.state.debugMode) {
4727
- const appliedStyles = Object.entries(stylesToApply).map(([k, v]) => "".concat(k, ": ").concat(v)).join("; ");
4728
- console.log("[TagadaClient] Applied styles to highlight div of element #".concat(elementId, ":"), appliedStyles);
4729
- }
4850
+ if (element) {
4851
+ applyToElement(element);
4852
+ }
4853
+ };
4854
+ findAndApply();
4730
4855
  }
4731
4856
  };
4732
4857