PluginProbe
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits / 3.1.9
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits v3.1.9
3.2.2 3.2.3 3.2.1 3.2.0 3.1.9 3.1.8 3.1.7 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.9 trunk 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.3 1.1.4 1.1.5 All 174 releases
master-addons / assets / js / modules / computed-style-capture.js

computed-style-capture.js in Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits 3.1.9, at assets/js/modules/computed-style-capture.js

99 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function(){
2 //#region dev/js/modules/free/computed-style-capture.js
3 var JLTMA_WIDGET_STYLE_MAP = {
4 heading: {
5 sel: ".elementor-heading-title",
6 typo: "typography_",
7 color: "title_color"
8 },
9 "text-editor": {
10 sel: ".elementor-widget-container",
11 typo: "typography_",
12 color: "text_color"
13 },
14 button: {
15 sel: ".elementor-button-text",
16 typo: "typography_",
17 color: "button_text_color"
18 },
19 "icon-box": {
20 sel: ".elementor-icon-box-title",
21 typo: "title_typography_",
22 color: "title_color"
23 }
24 };
25 function pxToObj(v) {
26 const n = parseFloat(v);
27 if (Number.isNaN(n)) return null;
28 return {
29 unit: "px",
30 size: n,
31 sizes: []
32 };
33 }
34 function firstFamily(ff) {
35 return String(ff || "").split(",")[0].replace(/['"]/g, "").trim();
36 }
37 function rgbToHex(c) {
38 const m = String(c || "").match(/rgba?\(([^)]+)\)/);
39 if (!m) return c || "";
40 const p = m[1].split(",").map((x) => x.trim());
41 const h = (n) => ("0" + parseInt(n, 10).toString(16)).slice(-2);
42 return ("#" + h(p[0]) + h(p[1]) + h(p[2])).toUpperCase();
43 }
44 function jltmaBakeComputedIntoSettings(settings, widgetType, computed) {
45 const map = JLTMA_WIDGET_STYLE_MAP[widgetType];
46 if (!map || !computed) return;
47 const p = map.typo;
48 if (settings.__globals__) {
49 [p + "typography", map.color].forEach((k) => {
50 if (settings.__globals__[k] === "") delete settings.__globals__[k];
51 });
52 if (!Object.keys(settings.__globals__).length) delete settings.__globals__;
53 }
54 const ff = firstFamily(computed.fontFamily);
55 if (ff) settings[p + "font_family"] = ff;
56 const fs = pxToObj(computed.fontSize);
57 if (fs) settings[p + "font_size"] = fs;
58 if (computed.fontWeight) settings[p + "font_weight"] = String(computed.fontWeight);
59 const lh = pxToObj(computed.lineHeight);
60 if (lh) settings[p + "line_height"] = lh;
61 if (computed.letterSpacing && computed.letterSpacing !== "normal") {
62 const ls = pxToObj(computed.letterSpacing);
63 if (ls) settings[p + "letter_spacing"] = ls;
64 }
65 if (computed.textTransform && computed.textTransform !== "none") settings[p + "text_transform"] = computed.textTransform;
66 if (computed.fontStyle && computed.fontStyle !== "normal") settings[p + "font_style"] = computed.fontStyle;
67 settings[p + "typography"] = "custom";
68 if (map.color) {
69 const hex = rgbToHex(computed.color);
70 if (hex) settings[map.color] = hex;
71 }
72 }
73 function jltmaCaptureComputedStyles(model, previewDoc) {
74 if (!model || !previewDoc) return model;
75 const walk = (node) => {
76 if (!node || typeof node !== "object") return;
77 const wt = node.widgetType;
78 if (node.elType === "widget" && JLTMA_WIDGET_STYLE_MAP[wt] && node.id) {
79 const root = previewDoc.querySelector(".elementor-element-" + node.id);
80 if (root) {
81 const map = JLTMA_WIDGET_STYLE_MAP[wt];
82 const el = root.querySelector(map.sel) || root;
83 const cs = previewDoc.defaultView.getComputedStyle(el);
84 node.settings = node.settings || {};
85 jltmaBakeComputedIntoSettings(node.settings, wt, cs);
86 }
87 }
88 (node.elements || []).forEach(walk);
89 };
90 walk(model);
91 return model;
92 }
93 if (typeof window !== "undefined") {
94 window.jltmaCaptureComputedStyles = jltmaCaptureComputedStyles;
95 window.jltmaBakeComputedIntoSettings = jltmaBakeComputedIntoSettings;
96 }
97 //#endregion
98 })();
99