| @@ -1,343 +1,2 @@ | ||
| 1 | -(function(react) { | |
| 2 | - | |
| 3 | -//#region \0rolldown/runtime.js | |
| 4 | - var __defProp$1 = Object.defineProperty; | |
| 5 | - var __name = (target, value) => __defProp$1(target, "name", { | |
| 6 | - value, | |
| 7 | - configurable: true | |
| 8 | - }); | |
| 9 | - var __exportAll = (all, no_symbols) => { | |
| 10 | - let target = {}; | |
| 11 | - for (var name in all) { | |
| 12 | - __defProp$1(target, name, { | |
| 13 | - get: all[name], | |
| 14 | - enumerable: true | |
| 15 | - }); | |
| 16 | - } | |
| 17 | - if (!no_symbols) { | |
| 18 | - __defProp$1(target, Symbol.toStringTag, { value: "Module" }); | |
| 19 | - } | |
| 20 | - return target; | |
| 21 | - }; | |
| 22 | - | |
| 23 | -//#endregion | |
| 24 | - | |
| 25 | -//#region packages/packages/libs/utils/src/errors/elementor-error.ts | |
| 26 | - var __defProp = Object.defineProperty; | |
| 27 | - var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { | |
| 28 | - enumerable: true, | |
| 29 | - configurable: true, | |
| 30 | - writable: true, | |
| 31 | - value | |
| 32 | - }) : obj[key] = value; | |
| 33 | - var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); | |
| 34 | - var ElementorError = class extends Error { | |
| 35 | - constructor(message, { code, context = null, cause = null }) { | |
| 36 | - super(message, { cause }); | |
| 37 | - __publicField(this, "context"); | |
| 38 | - __publicField(this, "code"); | |
| 39 | - this.context = context; | |
| 40 | - this.code = code; | |
| 41 | - } | |
| 42 | - }; | |
| 43 | - | |
| 44 | -//#endregion | |
| 45 | -//#region packages/packages/libs/utils/src/errors/create-error.ts | |
| 46 | - var createError = ({ code, message }) => { | |
| 47 | - return class extends ElementorError { | |
| 48 | - constructor({ cause, context } = {}) { | |
| 49 | - super(message, { | |
| 50 | - cause, | |
| 51 | - code, | |
| 52 | - context | |
| 53 | - }); | |
| 54 | - } | |
| 55 | - }; | |
| 56 | - }; | |
| 57 | - | |
| 58 | -//#endregion | |
| 59 | -//#region packages/packages/libs/utils/src/errors/ensure-error.ts | |
| 60 | - var ensureError = (error) => { | |
| 61 | - if (error instanceof Error) return error; | |
| 62 | - let message; | |
| 63 | - let cause = null; | |
| 64 | - try { | |
| 65 | - message = JSON.stringify(error); | |
| 66 | - } catch (e) { | |
| 67 | - cause = e; | |
| 68 | - message = "Unable to stringify the thrown value"; | |
| 69 | - } | |
| 70 | - return new Error(`Unexpected non-error thrown: ${message}`, { cause }); | |
| 71 | - }; | |
| 72 | - | |
| 73 | -//#endregion | |
| 74 | -//#region packages/packages/libs/utils/src/debounce.ts | |
| 75 | - function debounce(fn, wait) { | |
| 76 | - let timer = null; | |
| 77 | - const cancel = () => { | |
| 78 | - if (!timer) return; | |
| 79 | - clearTimeout(timer); | |
| 80 | - timer = null; | |
| 81 | - }; | |
| 82 | - const flush = (...args) => { | |
| 83 | - cancel(); | |
| 84 | - fn(...args); | |
| 85 | - }; | |
| 86 | - const run = (...args) => { | |
| 87 | - cancel(); | |
| 88 | - timer = setTimeout(() => { | |
| 89 | - fn(...args); | |
| 90 | - timer = null; | |
| 91 | - }, wait); | |
| 92 | - }; | |
| 93 | - const pending = () => !!timer; | |
| 94 | - run.flush = flush; | |
| 95 | - run.cancel = cancel; | |
| 96 | - run.pending = pending; | |
| 97 | - return run; | |
| 98 | - } | |
| 99 | - | |
| 100 | -//#endregion | |
| 101 | -//#region packages/packages/libs/utils/src/use-debounce-state.ts | |
| 102 | - function useDebounceState(options = {}) { | |
| 103 | - const { delay = 300, initialValue = "" } = options; | |
| 104 | - const [debouncedValue, setDebouncedValue] = (0, react.useState)(initialValue); | |
| 105 | - const [inputValue, setInputValue] = (0, react.useState)(initialValue); | |
| 106 | - const runRef = (0, react.useRef)(null); | |
| 107 | - (0, react.useEffect)(() => { | |
| 108 | - return () => { | |
| 109 | - runRef.current?.cancel?.(); | |
| 110 | - }; | |
| 111 | - }, []); | |
| 112 | - const debouncedSetValue = (0, react.useCallback)((val) => { | |
| 113 | - runRef.current?.cancel?.(); | |
| 114 | - runRef.current = debounce(() => { | |
| 115 | - setDebouncedValue(val); | |
| 116 | - }, delay); | |
| 117 | - runRef.current(); | |
| 118 | - }, [delay]); | |
| 119 | - const handleChange = (val) => { | |
| 120 | - setInputValue(val); | |
| 121 | - debouncedSetValue(val); | |
| 122 | - }; | |
| 123 | - return { | |
| 124 | - debouncedValue, | |
| 125 | - inputValue, | |
| 126 | - handleChange, | |
| 127 | - setInputValue | |
| 128 | - }; | |
| 129 | - } | |
| 130 | - | |
| 131 | -//#endregion | |
| 132 | -//#region packages/packages/libs/utils/src/use-debounced-callback.ts | |
| 133 | - function useDebouncedCallback(callback, delay) { | |
| 134 | - const callbackRef = (0, react.useRef)(callback); | |
| 135 | - (0, react.useEffect)(() => { | |
| 136 | - callbackRef.current = callback; | |
| 137 | - }, [callback]); | |
| 138 | - const debounced = (0, react.useMemo)(() => debounce((...args) => callbackRef.current(...args), delay), [delay]); | |
| 139 | - (0, react.useEffect)(() => { | |
| 140 | - return () => { | |
| 141 | - debounced.cancel(); | |
| 142 | - }; | |
| 143 | - }, [debounced]); | |
| 144 | - return debounced; | |
| 145 | - } | |
| 146 | - | |
| 147 | -//#endregion | |
| 148 | -//#region packages/packages/libs/utils/src/throttle.ts | |
| 149 | - function throttle(fn, wait, shouldExecuteIgnoredCalls = false) { | |
| 150 | - let timer = null; | |
| 151 | - let ignoredExecution = false; | |
| 152 | - const cancel = () => { | |
| 153 | - if (!timer) return; | |
| 154 | - clearTimeout(timer); | |
| 155 | - timer = null; | |
| 156 | - }; | |
| 157 | - const flush = (...args) => { | |
| 158 | - cancel(); | |
| 159 | - fn(...args); | |
| 160 | - }; | |
| 161 | - const run = (...args) => { | |
| 162 | - if (timer) { | |
| 163 | - ignoredExecution = true; | |
| 164 | - return; | |
| 165 | - } | |
| 166 | - fn(...args); | |
| 167 | - timer = setTimeout(() => { | |
| 168 | - timer = null; | |
| 169 | - if (ignoredExecution && shouldExecuteIgnoredCalls) fn(...args); | |
| 170 | - ignoredExecution = false; | |
| 171 | - }, wait); | |
| 172 | - }; | |
| 173 | - const pending = () => !!timer; | |
| 174 | - run.flush = flush; | |
| 175 | - run.cancel = cancel; | |
| 176 | - run.pending = pending; | |
| 177 | - return run; | |
| 178 | - } | |
| 179 | - | |
| 180 | -//#endregion | |
| 181 | -//#region packages/packages/libs/utils/src/encoding.ts | |
| 182 | - var encodeString = (value) => { | |
| 183 | - const binary = Array.from(new TextEncoder().encode(value), (b) => String.fromCharCode(b)).join(""); | |
| 184 | - return btoa(binary); | |
| 185 | - }; | |
| 186 | - var decodeString = (value, fallback) => { | |
| 187 | - try { | |
| 188 | - const binary = atob(value); | |
| 189 | - const bytes = new Uint8Array(Array.from(binary, (char) => char.charCodeAt(0))); | |
| 190 | - return new TextDecoder().decode(bytes); | |
| 191 | - } catch { | |
| 192 | - return fallback !== void 0 ? fallback : ""; | |
| 193 | - } | |
| 194 | - }; | |
| 195 | - | |
| 196 | -//#endregion | |
| 197 | -//#region packages/packages/libs/utils/src/hash.ts | |
| 198 | - function hash(obj) { | |
| 199 | - return JSON.stringify(obj, (_, value) => isPlainObject(value) ? Object.keys(value).sort().reduce((result, key) => { | |
| 200 | - result[key] = value[key]; | |
| 201 | - return result; | |
| 202 | - }, {}) : value); | |
| 203 | - } | |
| 204 | - function isPlainObject(value) { | |
| 205 | - return !!value && typeof value === "object" && !Array.isArray(value); | |
| 206 | - } | |
| 207 | - function hashString(str, length) { | |
| 208 | - let hashBasis = 5381; | |
| 209 | - let i = str.length; | |
| 210 | - while (i) hashBasis = hashBasis * 33 ^ str.charCodeAt(--i); | |
| 211 | - const result = (hashBasis >>> 0).toString(36); | |
| 212 | - if (length === void 0) return result; | |
| 213 | - return result.slice(-length).padStart(length, "0"); | |
| 214 | - } | |
| 215 | - | |
| 216 | -//#endregion | |
| 217 | -//#region packages/packages/libs/utils/src/use-search-state.ts | |
| 218 | - function useSearchState({ localStorageKey }) { | |
| 219 | - const getInitialSearchValue = () => { | |
| 220 | - if (localStorageKey) { | |
| 221 | - const storedValue = localStorage.getItem(localStorageKey); | |
| 222 | - if (storedValue) { | |
| 223 | - localStorage.removeItem(localStorageKey); | |
| 224 | - return storedValue; | |
| 225 | - } | |
| 226 | - } | |
| 227 | - return ""; | |
| 228 | - }; | |
| 229 | - const { debouncedValue, inputValue, handleChange } = useDebounceState({ | |
| 230 | - delay: 300, | |
| 231 | - initialValue: getInitialSearchValue() | |
| 232 | - }); | |
| 233 | - return { | |
| 234 | - debouncedValue, | |
| 235 | - inputValue, | |
| 236 | - handleChange | |
| 237 | - }; | |
| 238 | - } | |
| 239 | - | |
| 240 | -//#endregion | |
| 241 | -//#region packages/packages/libs/utils/src/generate-unique-id.ts | |
| 242 | - function generateUniqueId(prefix = "") { | |
| 243 | - return `${prefix ? `${prefix}-` : ""}${Date.now()}-${Math.random().toString(36).substring(2, 9)}`; | |
| 244 | - } | |
| 245 | - | |
| 246 | -//#endregion | |
| 247 | -//#region packages/packages/libs/utils/src/string-helpers.ts | |
| 248 | - var capitalize = (str) => { | |
| 249 | - return str.charAt(0).toUpperCase() + str.slice(1); | |
| 250 | - }; | |
| 251 | - | |
| 252 | -//#endregion | |
| 253 | -//#region packages/packages/libs/utils/src/version.ts | |
| 254 | - var compareVersions = (a, b) => { | |
| 255 | - const aParts = String(a || "0.0.0").split(".").map(Number); | |
| 256 | - const bParts = String(b || "0.0.0").split(".").map(Number); | |
| 257 | - for (let i = 0; i < Math.max(aParts.length, bParts.length); i++) { | |
| 258 | - const aVal = aParts[i] || 0; | |
| 259 | - const bVal = bParts[i] || 0; | |
| 260 | - if (aVal !== bVal) return aVal - bVal; | |
| 261 | - } | |
| 262 | - return 0; | |
| 263 | - }; | |
| 264 | - var isVersionLessThan = (a, b) => { | |
| 265 | - return compareVersions(a, b) < 0; | |
| 266 | - }; | |
| 267 | - var isVersionGreaterOrEqual = (a, b) => { | |
| 268 | - return compareVersions(a, b) >= 0; | |
| 269 | - }; | |
| 270 | - | |
| 271 | -//#endregion | |
| 272 | -//#region packages/packages/libs/utils/src/is-pro.ts | |
| 273 | - function hasProInstalled() { | |
| 274 | - return window.elementor?.helpers?.hasPro?.() ?? false; | |
| 275 | - } | |
| 276 | - function isProActive() { | |
| 277 | - if (!hasProInstalled()) return false; | |
| 278 | - return window.elementorPro?.config?.isActive ?? false; | |
| 279 | - } | |
| 280 | - function getProVersion() { | |
| 281 | - return window.elementorPro?.config?.version ?? "0.0"; | |
| 282 | - } | |
| 283 | - function isProAtLeast(targetVersion) { | |
| 284 | - const version = getProVersion(); | |
| 285 | - if (!version) return false; | |
| 286 | - const [major, minor] = version.split(".").map(Number); | |
| 287 | - const [targetMajor, targetMinor] = targetVersion.split(".").map(Number); | |
| 288 | - return major > targetMajor || major === targetMajor && minor >= targetMinor; | |
| 289 | - } | |
| 290 | - | |
| 291 | -//#endregion | |
| 292 | -//#region packages/packages/libs/utils/src/translations.ts | |
| 293 | - function createTranslate({ configKey, defaultStrings = {} }) { | |
| 294 | - return (key, ...args) => { | |
| 295 | - const appConfig = window.elementorAppConfig; | |
| 296 | - const remoteStrings = Object.fromEntries(Object.entries(appConfig?.[configKey]?.translations ?? {}).filter(([, value]) => "string" === typeof value && "" !== value.trim())); | |
| 297 | - let template = { | |
| 298 | - ...defaultStrings, | |
| 299 | - ...remoteStrings | |
| 300 | - }[key]; | |
| 301 | - if (!template) return key; | |
| 302 | - for (let i = 0; i < args.length; i++) { | |
| 303 | - template = template.replace(`%${i + 1}$s`, args[i]); | |
| 304 | - template = template.replace("%s", args[i]); | |
| 305 | - } | |
| 306 | - return template; | |
| 307 | - }; | |
| 308 | - } | |
| 309 | - | |
| 310 | -//#endregion | |
| 311 | -//#region packages/packages/libs/utils/src/index.ts | |
| 312 | - var src_exports = /* @__PURE__ */ __exportAll({ | |
| 313 | - ElementorError: () => ElementorError, | |
| 314 | - capitalize: () => capitalize, | |
| 315 | - compareVersions: () => compareVersions, | |
| 316 | - createError: () => createError, | |
| 317 | - createTranslate: () => createTranslate, | |
| 318 | - debounce: () => debounce, | |
| 319 | - decodeString: () => decodeString, | |
| 320 | - encodeString: () => encodeString, | |
| 321 | - ensureError: () => ensureError, | |
| 322 | - generateUniqueId: () => generateUniqueId, | |
| 323 | - hasProInstalled: () => hasProInstalled, | |
| 324 | - hash: () => hash, | |
| 325 | - hashString: () => hashString, | |
| 326 | - isProActive: () => isProActive, | |
| 327 | - isProAtLeast: () => isProAtLeast, | |
| 328 | - isVersionGreaterOrEqual: () => isVersionGreaterOrEqual, | |
| 329 | - isVersionLessThan: () => isVersionLessThan, | |
| 330 | - throttle: () => throttle, | |
| 331 | - useDebounceState: () => useDebounceState, | |
| 332 | - useDebouncedCallback: () => useDebouncedCallback, | |
| 333 | - useSearchState: () => useSearchState | |
| 334 | - }); | |
| 335 | - | |
| 336 | -//#endregion | |
| 337 | -//#region \0elementor-package-library-entry | |
| 338 | - (window.elementorV2 = window.elementorV2 || {}).utils = src_exports; | |
| 339 | - | |
| 340 | -//#endregion | |
| 341 | -})(React); | |
| 342 | -window.elementorV2.utils?.init?.(); | |
| 343 | -//# sourceMappingURL=utils.js.map | |
| 1 | +/*! For license information please see utils.js.LICENSE.txt */ | |
| 2 | +!function(){"use strict";var e={d:function(r,t){for(var n in t)e.o(t,n)&&!e.o(r,n)&&Object.defineProperty(r,n,{enumerable:!0,get:t[n]})},o:function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},r={};e.r(r),e.d(r,{ElementorError:function(){return t},createError:function(){return n},ensureError:function(){return o}});var t=class extends Error{context;code;constructor(e,{code:r,context:t=null,cause:n=null}){super(e,{cause:n}),this.context=t,this.code=r}},n=({code:e,message:r})=>class extends t{constructor({cause:t,context:n}={}){super(r,{cause:t,code:e,context:n})}},o=e=>{if(e instanceof Error)return e;let r,t=null;try{r=JSON.stringify(e)}catch(e){t=e,r="Unable to stringify the thrown value"}return new Error(`Unexpected non-error thrown: ${r}`,{cause:t})};(window.elementorV2=window.elementorV2||{}).utils=r}(); | |