| 1 |
(function() { |
| 2 |
|
| 3 |
//#region \0rolldown/runtime.js |
| 4 |
var __defProp = Object.defineProperty; |
| 5 |
var __name = (target, value) => __defProp(target, "name", { |
| 6 |
value, |
| 7 |
configurable: true |
| 8 |
}); |
| 9 |
|
| 10 |
//#endregion |
| 11 |
|
| 12 |
//#region modules/design-system-sync/assets/js/design-system-sync-handler.js |
| 13 |
(function() { |
| 14 |
"use strict"; |
| 15 |
var SYNC_ENDPOINT = wpApiSettings.root + "elementor/v1/design-system-sync/stylesheet"; |
| 16 |
var SYNC_STYLESHEET_ID = "elementor-design-system-sync-css"; |
| 17 |
var DEBOUNCE_MS = 500; |
| 18 |
var syncTimeout; |
| 19 |
function syncDesignSystem() { |
| 20 |
fetch(SYNC_ENDPOINT, { |
| 21 |
method: "POST", |
| 22 |
headers: { "X-WP-Nonce": wpApiSettings.nonce } |
| 23 |
}).then(function(response) { |
| 24 |
if (!response.ok) return; |
| 25 |
if (204 === response.status) return; |
| 26 |
return response.json(); |
| 27 |
}).then(function(data) { |
| 28 |
if (!data) return; |
| 29 |
refreshGlobals(); |
| 30 |
reloadCanvasDesignSyncStyles(data); |
| 31 |
}); |
| 32 |
} |
| 33 |
function refreshGlobals() { |
| 34 |
var globals = $e.components.get("globals"); |
| 35 |
globals === null || globals === void 0 || globals.refreshGlobalData(); |
| 36 |
globals === null || globals === void 0 || globals.populateGlobalData(); |
| 37 |
} |
| 38 |
function reloadCanvasDesignSyncStyles(_ref) { |
| 39 |
var url = _ref.url; |
| 40 |
var previewFrame = document.getElementById("elementor-preview-iframe"); |
| 41 |
if (!(previewFrame !== null && previewFrame !== void 0 && previewFrame.contentDocument)) return; |
| 42 |
var link = previewFrame.contentDocument.getElementById(SYNC_STYLESHEET_ID); |
| 43 |
if (!link) { |
| 44 |
link = previewFrame.contentDocument.createElement("link"); |
| 45 |
link.id = SYNC_STYLESHEET_ID; |
| 46 |
link.rel = "stylesheet"; |
| 47 |
previewFrame.contentDocument.head.appendChild(link); |
| 48 |
} |
| 49 |
link.href = url; |
| 50 |
} |
| 51 |
function onClassesUpdated(event) { |
| 52 |
if (event.detail.context !== "frontend") return; |
| 53 |
clearTimeout(syncTimeout); |
| 54 |
syncTimeout = setTimeout(syncDesignSystem, DEBOUNCE_MS); |
| 55 |
} |
| 56 |
window.addEventListener("classes:updated", onClassesUpdated); |
| 57 |
window.addEventListener("variables:updated", function() { |
| 58 |
clearTimeout(syncTimeout); |
| 59 |
syncTimeout = setTimeout(syncDesignSystem, DEBOUNCE_MS); |
| 60 |
}); |
| 61 |
})(); |
| 62 |
|
| 63 |
//#endregion |
| 64 |
})(); |
| 65 |
//# sourceMappingURL=design-system-sync.js.map |