UNPKG

@zubridge/electron

Version:

A streamlined state management library for Electron applications using Zustand.

580 lines (574 loc) 16.8 kB
// Renderer-safe build with polyfilled Node.js modules const require_os = require('./os-Dm0Fz436.cjs'); //#region ../../node_modules/.pnpm/ms@3.0.0-canary.202508261828/node_modules/ms/dist/index.js const e = 1e3, t = e * 60, n = t * 60, r = n * 24, i = r * 7, a = r * 365.25, o = a / 12; function s(e$1, t$1) { if (typeof e$1 == `string`) return l(e$1); if (typeof e$1 == `number`) return p(e$1, t$1); throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(e$1)}`); } var c = s; function l(s$1) { if (typeof s$1 != `string` || s$1.length === 0 || s$1.length > 100) throw Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(s$1)}`); let c$1 = /^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(s$1); if (!c$1?.groups) return NaN; let { value: l$1, unit: u = `ms` } = c$1.groups, d$1 = parseFloat(l$1), f$1 = u.toLowerCase(); switch (f$1) { case `years`: case `year`: case `yrs`: case `yr`: case `y`: return d$1 * a; case `months`: case `month`: case `mo`: return d$1 * o; case `weeks`: case `week`: case `w`: return d$1 * i; case `days`: case `day`: case `d`: return d$1 * r; case `hours`: case `hour`: case `hrs`: case `hr`: case `h`: return d$1 * n; case `minutes`: case `minute`: case `mins`: case `min`: case `m`: return d$1 * t; case `seconds`: case `second`: case `secs`: case `sec`: case `s`: return d$1 * e; case `milliseconds`: case `millisecond`: case `msecs`: case `msec`: case `ms`: return d$1; default: throw Error(`Unknown unit "${f$1}" provided to ms.parse(). value=${JSON.stringify(s$1)}`); } } function d(s$1) { let c$1 = Math.abs(s$1); return c$1 >= a ? `${Math.round(s$1 / a)}y` : c$1 >= o ? `${Math.round(s$1 / o)}mo` : c$1 >= i ? `${Math.round(s$1 / i)}w` : c$1 >= r ? `${Math.round(s$1 / r)}d` : c$1 >= n ? `${Math.round(s$1 / n)}h` : c$1 >= t ? `${Math.round(s$1 / t)}m` : c$1 >= e ? `${Math.round(s$1 / e)}s` : `${s$1}ms`; } function f(s$1) { let c$1 = Math.abs(s$1); return c$1 >= a ? m(s$1, c$1, a, `year`) : c$1 >= o ? m(s$1, c$1, o, `month`) : c$1 >= i ? m(s$1, c$1, i, `week`) : c$1 >= r ? m(s$1, c$1, r, `day`) : c$1 >= n ? m(s$1, c$1, n, `hour`) : c$1 >= t ? m(s$1, c$1, t, `minute`) : c$1 >= e ? m(s$1, c$1, e, `second`) : `${s$1} ms`; } function p(e$1, t$1) { if (typeof e$1 != `number` || !Number.isFinite(e$1)) throw Error(`Value provided to ms.format() must be of type number.`); return t$1?.long ? f(e$1) : d(e$1); } function m(e$1, t$1, n$1, r$1) { let i$1 = t$1 >= n$1 * 1.5; return `${Math.round(e$1 / n$1)} ${r$1}${i$1 ? `s` : ``}`; } //#endregion //#region ../../node_modules/.pnpm/supports-color@10.2.2/node_modules/supports-color/index.js function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : require_os.process_default.argv) { const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--"; const position = argv.indexOf(prefix + flag); const terminatorPosition = argv.indexOf("--"); return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition); } const { env } = require_os.process_default; let flagForceColor; if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) flagForceColor = 0; else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) flagForceColor = 1; function envForceColor() { if (!("FORCE_COLOR" in env)) return; if (env.FORCE_COLOR === "true") return 1; if (env.FORCE_COLOR === "false") return 0; if (env.FORCE_COLOR.length === 0) return 1; const level = Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3); if (![ 0, 1, 2, 3 ].includes(level)) return; return level; } function translateLevel(level) { if (level === 0) return false; return { level, hasBasic: true, has256: level >= 2, has16m: level >= 3 }; } function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) { const noFlagForceColor = envForceColor(); if (noFlagForceColor !== void 0) flagForceColor = noFlagForceColor; const forceColor = sniffFlags ? flagForceColor : noFlagForceColor; if (forceColor === 0) return 0; if (sniffFlags) { if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) return 3; if (hasFlag("color=256")) return 2; } if ("TF_BUILD" in env && "AGENT_NAME" in env) return 1; if (haveStream && !streamIsTTY && forceColor === void 0) return 0; const min = forceColor || 0; if (env.TERM === "dumb") return min; if (require_os.process_default.platform === "win32") { const osRelease = require_os.os_default.release().split("."); if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) return Number(osRelease[2]) >= 14931 ? 3 : 2; return 1; } if ("CI" in env) { if ([ "GITHUB_ACTIONS", "GITEA_ACTIONS", "CIRCLECI" ].some((key) => key in env)) return 3; if ([ "TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE" ].some((sign) => sign in env) || env.CI_NAME === "codeship") return 1; return min; } if ("TEAMCITY_VERSION" in env) return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0; if (env.COLORTERM === "truecolor") return 3; if (env.TERM === "xterm-kitty") return 3; if (env.TERM === "xterm-ghostty") return 3; if (env.TERM === "wezterm") return 3; if ("TERM_PROGRAM" in env) { const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10); switch (env.TERM_PROGRAM) { case "iTerm.app": return version >= 3 ? 3 : 2; case "Apple_Terminal": return 2; } } if (/-256(color)?$/i.test(env.TERM)) return 2; if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) return 1; if ("COLORTERM" in env) return 1; return min; } function createSupportsColor(stream, options = {}) { return translateLevel(_supportsColor(stream, { streamIsTTY: stream && stream.isTTY, ...options })); } const supportsColor = { stdout: createSupportsColor({ isTTY: require_os.tty_default.isatty(1) }), stderr: createSupportsColor({ isTTY: require_os.tty_default.isatty(2) }) }; var supports_color_default = supportsColor; //#endregion //#region ../../node_modules/.pnpm/weald@1.1.1/node_modules/weald/dist/src/common.js /** * This is the common logic for both the Node.js and web browser * implementations of `debug()`. */ function setup(env$1) { createDebug.debug = createDebug; createDebug.default = createDebug; createDebug.coerce = coerce; createDebug.disable = disable; createDebug.enable = enable; createDebug.enabled = enabled; createDebug.humanize = c; createDebug.destroy = destroy; Object.keys(env$1).forEach((key) => { createDebug[key] = env$1[key]; }); /** * The currently active debug mode names, and names to skip. */ createDebug.names = []; createDebug.skips = []; /** * Map of special "%n" handling functions, for the debug "format" argument. * * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N". */ createDebug.formatters = {}; /** * Selects a color for a debug namespace * * @param {string} namespace - The namespace string for the debug instance to be colored * @returns {number | string} An ANSI color code for the given namespace */ function selectColor(namespace) { let hash = 0; for (let i$1 = 0; i$1 < namespace.length; i$1++) { hash = (hash << 5) - hash + namespace.charCodeAt(i$1); hash |= 0; } return createDebug.colors[Math.abs(hash) % createDebug.colors.length]; } createDebug.selectColor = selectColor; /** * Create a debugger with the given `namespace`. * * @param {string} namespace * @returns {Function} */ function createDebug(namespace, options) { let prevTime; let enableOverride = null; let namespacesCache; let enabledCache; function debug(...args) { if (!debug.enabled) return; const self = debug; const curr = Number(/* @__PURE__ */ new Date()); self.diff = curr - (prevTime || curr); self.prev = prevTime; self.curr = curr; prevTime = curr; args[0] = createDebug.coerce(args[0]); if (typeof args[0] !== "string") args.unshift("%O"); let index = 0; args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => { if (match === "%%") return "%"; index++; const formatter = createDebug.formatters[format]; if (typeof formatter === "function") { const val = args[index]; match = formatter.call(self, val); args.splice(index, 1); index--; } return match; }); createDebug.formatArgs.call(self, args); if (options?.onLog != null) options.onLog(...args); (self.log || createDebug.log).apply(self, args); } debug.namespace = namespace; debug.useColors = createDebug.useColors(); debug.color = createDebug.selectColor(namespace); debug.extend = extend; debug.destroy = createDebug.destroy; Object.defineProperty(debug, "enabled", { enumerable: true, configurable: false, get: () => { if (enableOverride !== null) return enableOverride; if (namespacesCache !== createDebug.namespaces) { namespacesCache = createDebug.namespaces; enabledCache = createDebug.enabled(namespace); } return enabledCache; }, set: (v) => { enableOverride = v; } }); if (typeof createDebug.init === "function") createDebug.init(debug); return debug; } function extend(namespace, delimiter) { const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace); newDebug.log = this.log; return newDebug; } /** * Enables a debug mode by namespaces. This can include modes * separated by a colon and wildcards. * * @param {string} namespaces */ function enable(namespaces) { createDebug.save(namespaces); createDebug.namespaces = namespaces; createDebug.names = []; createDebug.skips = []; let i$1; const split = (typeof namespaces === "string" ? namespaces : "").split(/[\s,]+/); const len = split.length; for (i$1 = 0; i$1 < len; i$1++) { if (!split[i$1]) continue; namespaces = split[i$1].replace(/\*/g, ".*?"); if (namespaces[0] === "-") createDebug.skips.push(/* @__PURE__ */ new RegExp("^" + namespaces.substr(1) + "$")); else createDebug.names.push(/* @__PURE__ */ new RegExp("^" + namespaces + "$")); } } /** * Disable debug output. * * @returns {string} namespaces */ function disable() { const namespaces = [...createDebug.names.map(toNamespace), ...createDebug.skips.map(toNamespace).map((namespace) => "-" + namespace)].join(","); createDebug.enable(""); return namespaces; } /** * Returns true if the given mode name is enabled, false otherwise. * * @param {string} name * @returns {boolean} */ function enabled(name) { if (name[name.length - 1] === "*") return true; let i$1; let len; for (i$1 = 0, len = createDebug.skips.length; i$1 < len; i$1++) if (createDebug.skips[i$1].test(name)) return false; for (i$1 = 0, len = createDebug.names.length; i$1 < len; i$1++) if (createDebug.names[i$1].test(name)) return true; return false; } /** * Convert regexp to namespace */ function toNamespace(regexp) { return regexp.toString().substring(2, regexp.toString().length - 2).replace(/\.\*\?$/, "*"); } /** * Coerce `val`. */ function coerce(val) { if (val instanceof Error) return val.stack ?? val.message; return val; } /** * XXX DO NOT USE. This is a temporary stub function. * XXX It WILL be removed in the next major release. */ function destroy() { console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."); } createDebug.setupFormatters(createDebug.formatters); createDebug.enable(createDebug.load()); return createDebug; } //#endregion //#region ../../node_modules/.pnpm/weald@1.1.1/node_modules/weald/dist/src/node.js /** * @packageDocumentation * * This module is a fork of the [debug](https://www.npmjs.com/package/debug) module. It has been converted to TypeScript and the output is ESM. * * It is API compatible with no extra features or bug fixes, it should only be used if you want a 100% ESM application. * * ESM should be arriving in `debug@5.x.x` so this module can be retired after that. * * Please see [debug](https://www.npmjs.com/package/debug) for API details. */ /** * Module dependencies. */ /** * This is the Node.js implementation of `debug()`. */ /** * Colors. */ let colors = [ 6, 2, 3, 4, 5, 1 ]; if (supports_color_default.stderr !== false && (supports_color_default.stderr ?? supports_color_default).level >= 2) colors = [ 20, 21, 26, 27, 32, 33, 38, 39, 40, 41, 42, 43, 44, 45, 56, 57, 62, 63, 68, 69, 74, 75, 76, 77, 78, 79, 80, 81, 92, 93, 98, 99, 112, 113, 128, 129, 134, 135, 148, 149, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 178, 179, 184, 185, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 214, 215, 220, 221 ]; /** * Build up the default `inspectOpts` object from the environment variables. * * $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js */ const inspectOpts = Object.keys(process.env).filter((key) => { return /^debug_/i.test(key); }).reduce((obj, key) => { const prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, (_, k) => { return k.toUpperCase(); }); let val = process.env[key]; if (/^(yes|on|true|enabled)$/i.test(val)) val = true; else if (/^(no|off|false|disabled)$/i.test(val)) val = false; else if (val === "null") val = null; else val = Number(val); obj[prop] = val; return obj; }, {}); /** * Is stdout a TTY? Colored output is enabled when `true`. */ function useColors() { return "colors" in inspectOpts ? Boolean(inspectOpts.colors) : require_os.tty_default.isatty(process.stderr.fd); } /** * Adds ANSI color escape codes if enabled. */ function formatArgs(args) { const { namespace: name, useColors: useColors$1 } = this; if (useColors$1 === true) { const c$1 = this.color; const colorCode = "\x1B[3" + (c$1 < 8 ? c$1 : "8;5;" + c$1); const prefix = ` ${colorCode};1m${name} \u001B[0m`; args[0] = prefix + args[0].split("\n").join("\n" + prefix); args.push(colorCode + "m+" + c(this.diff) + "\x1B[0m"); } else args[0] = getDate() + name + " " + args[0]; } function getDate() { if (inspectOpts.hideDate != null) return ""; return (/* @__PURE__ */ new Date()).toISOString() + " "; } /** * Invokes `util.format()` with the specified arguments and writes to stderr. */ function log(...args) { return process.stderr.write(require_os.util_default.format(...args) + "\n"); } /** * Save `namespaces`. * * @param {string} namespaces */ function save(namespaces) { if (namespaces != null) process.env.DEBUG = namespaces; else delete process.env.DEBUG; } /** * Load `namespaces`. * * @returns {string} returns the previously persisted debug modes */ function load() { return process.env.DEBUG; } /** * Init logic for `debug` instances. * * Create a new `inspectOpts` object in case `useColors` is set * differently for a particular `debug` instance. */ function init(debug) { debug.inspectOpts = {}; const keys = Object.keys(inspectOpts); for (let i$1 = 0; i$1 < keys.length; i$1++) debug.inspectOpts[keys[i$1]] = inspectOpts[keys[i$1]]; } function setupFormatters(formatters) { /** * Map %o to `util.inspect()`, all on a single line. */ formatters.o = function(v) { this.inspectOpts.colors = this.useColors; return require_os.util_default.inspect(v, this.inspectOpts).split("\n").map((str) => str.trim()).join(" "); }; /** * Map %O to `util.inspect()`, allowing multiple lines if needed. */ formatters.O = function(v) { this.inspectOpts.colors = this.useColors; return require_os.util_default.inspect(v, this.inspectOpts); }; } var node_default = setup({ init, log, formatArgs, save, load, useColors, setupFormatters, colors, inspectOpts }); //#endregion //#region ../../node_modules/.pnpm/weald@1.1.1/node_modules/weald/dist/src/index.js /** * @packageDocumentation * * This module is a fork of the [debug](https://www.npmjs.com/package/debug) module. It has been converted to TypeScript and the output is ESM. * * It is API compatible with no extra features or bug fixes, it should only be used if you want a 100% ESM application. * * ESM should be arriving in `debug@5.x.x` so this module can be retired after that. * * Please see [debug](https://www.npmjs.com/package/debug) for API details. */ /** * Module dependencies. */ var src_default = node_default; //#endregion exports.default = src_default;