react-native-uikit-colors
Version:
react native ui kit colors
479 lines (475 loc) • 16.6 kB
JavaScript
const require_colors = require('./colors-htXGIBre.js');
const react = require_colors.__toESM(require("react"));
//#region ../../node_modules/.pnpm/lodash.debounce@4.0.8/node_modules/lodash.debounce/index.js
var require_lodash = require_colors.__commonJS({ "../../node_modules/.pnpm/lodash.debounce@4.0.8/node_modules/lodash.debounce/index.js"(exports, module) {
/**
* lodash (Custom Build) <https://lodash.com/>
* Build: `lodash modularize exports="npm" -o ./`
* Copyright jQuery Foundation and other contributors <https://jquery.org/>
* Released under MIT license <https://lodash.com/license>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
*/
/** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = "Expected a function";
/** Used as references for various `Number` constants. */
var NAN = NaN;
/** `Object#toString` result references. */
var symbolTag = "[object Symbol]";
/** Used to match leading and trailing whitespace. */
var reTrim = /^\s+|\s+$/g;
/** Used to detect bad signed hexadecimal string values. */
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
/** Used to detect binary string values. */
var reIsBinary = /^0b[01]+$/i;
/** Used to detect octal string values. */
var reIsOctal = /^0o[0-7]+$/i;
/** Built-in method references without a dependency on `root`. */
var freeParseInt = parseInt;
/** Detect free variable `global` from Node.js. */
var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
/** Detect free variable `self`. */
var freeSelf = typeof self == "object" && self && self.Object === Object && self;
/** Used as a reference to the global object. */
var root = freeGlobal || freeSelf || Function("return this")();
/** Used for built-in method references. */
var objectProto = Object.prototype;
/**
* Used to resolve the
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
* of values.
*/
var objectToString = objectProto.toString;
var nativeMax = Math.max, nativeMin = Math.min;
/**
* Gets the timestamp of the number of milliseconds that have elapsed since
* the Unix epoch (1 January 1970 00:00:00 UTC).
*
* @static
* @memberOf _
* @since 2.4.0
* @category Date
* @returns {number} Returns the timestamp.
* @example
*
* _.defer(function(stamp) {
* console.log(_.now() - stamp);
* }, _.now());
* // => Logs the number of milliseconds it took for the deferred invocation.
*/
var now = function() {
return root.Date.now();
};
/**
* Creates a debounced function that delays invoking `func` until after `wait`
* milliseconds have elapsed since the last time the debounced function was
* invoked. The debounced function comes with a `cancel` method to cancel
* delayed `func` invocations and a `flush` method to immediately invoke them.
* Provide `options` to indicate whether `func` should be invoked on the
* leading and/or trailing edge of the `wait` timeout. The `func` is invoked
* with the last arguments provided to the debounced function. Subsequent
* calls to the debounced function return the result of the last `func`
* invocation.
*
* **Note:** If `leading` and `trailing` options are `true`, `func` is
* invoked on the trailing edge of the timeout only if the debounced function
* is invoked more than once during the `wait` timeout.
*
* If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
* until to the next tick, similar to `setTimeout` with a timeout of `0`.
*
* See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
* for details over the differences between `_.debounce` and `_.throttle`.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Function
* @param {Function} func The function to debounce.
* @param {number} [wait=0] The number of milliseconds to delay.
* @param {Object} [options={}] The options object.
* @param {boolean} [options.leading=false]
* Specify invoking on the leading edge of the timeout.
* @param {number} [options.maxWait]
* The maximum time `func` is allowed to be delayed before it's invoked.
* @param {boolean} [options.trailing=true]
* Specify invoking on the trailing edge of the timeout.
* @returns {Function} Returns the new debounced function.
* @example
*
* // Avoid costly calculations while the window size is in flux.
* jQuery(window).on('resize', _.debounce(calculateLayout, 150));
*
* // Invoke `sendMail` when clicked, debouncing subsequent calls.
* jQuery(element).on('click', _.debounce(sendMail, 300, {
* 'leading': true,
* 'trailing': false
* }));
*
* // Ensure `batchLog` is invoked once after 1 second of debounced calls.
* var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
* var source = new EventSource('/stream');
* jQuery(source).on('message', debounced);
*
* // Cancel the trailing debounced invocation.
* jQuery(window).on('popstate', debounced.cancel);
*/
function debounce(func, wait, options) {
var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
if (typeof func != "function") throw new TypeError(FUNC_ERROR_TEXT);
wait = toNumber(wait) || 0;
if (isObject(options)) {
leading = !!options.leading;
maxing = "maxWait" in options;
maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
trailing = "trailing" in options ? !!options.trailing : trailing;
}
function invokeFunc(time) {
var args = lastArgs, thisArg = lastThis;
lastArgs = lastThis = void 0;
lastInvokeTime = time;
result = func.apply(thisArg, args);
return result;
}
function leadingEdge(time) {
lastInvokeTime = time;
timerId = setTimeout(timerExpired, wait);
return leading ? invokeFunc(time) : result;
}
function remainingWait(time) {
var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime, result$1 = wait - timeSinceLastCall;
return maxing ? nativeMin(result$1, maxWait - timeSinceLastInvoke) : result$1;
}
function shouldInvoke(time) {
var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime;
return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
}
function timerExpired() {
var time = now();
if (shouldInvoke(time)) return trailingEdge(time);
timerId = setTimeout(timerExpired, remainingWait(time));
}
function trailingEdge(time) {
timerId = void 0;
if (trailing && lastArgs) return invokeFunc(time);
lastArgs = lastThis = void 0;
return result;
}
function cancel() {
if (timerId !== void 0) clearTimeout(timerId);
lastInvokeTime = 0;
lastArgs = lastCallTime = lastThis = timerId = void 0;
}
function flush() {
return timerId === void 0 ? result : trailingEdge(now());
}
function debounced() {
var time = now(), isInvoking = shouldInvoke(time);
lastArgs = arguments;
lastThis = this;
lastCallTime = time;
if (isInvoking) {
if (timerId === void 0) return leadingEdge(lastCallTime);
if (maxing) {
timerId = setTimeout(timerExpired, wait);
return invokeFunc(lastCallTime);
}
}
if (timerId === void 0) timerId = setTimeout(timerExpired, wait);
return result;
}
debounced.cancel = cancel;
debounced.flush = flush;
return debounced;
}
/**
* Checks if `value` is the
* [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
* @example
*
* _.isObject({});
* // => true
*
* _.isObject([1, 2, 3]);
* // => true
*
* _.isObject(_.noop);
* // => true
*
* _.isObject(null);
* // => false
*/
function isObject(value) {
var type = typeof value;
return !!value && (type == "object" || type == "function");
}
/**
* Checks if `value` is object-like. A value is object-like if it's not `null`
* and has a `typeof` result of "object".
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
* @example
*
* _.isObjectLike({});
* // => true
*
* _.isObjectLike([1, 2, 3]);
* // => true
*
* _.isObjectLike(_.noop);
* // => false
*
* _.isObjectLike(null);
* // => false
*/
function isObjectLike(value) {
return !!value && typeof value == "object";
}
/**
* Checks if `value` is classified as a `Symbol` primitive or object.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
* @example
*
* _.isSymbol(Symbol.iterator);
* // => true
*
* _.isSymbol('abc');
* // => false
*/
function isSymbol(value) {
return typeof value == "symbol" || isObjectLike(value) && objectToString.call(value) == symbolTag;
}
/**
* Converts `value` to a number.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to process.
* @returns {number} Returns the number.
* @example
*
* _.toNumber(3.2);
* // => 3.2
*
* _.toNumber(Number.MIN_VALUE);
* // => 5e-324
*
* _.toNumber(Infinity);
* // => Infinity
*
* _.toNumber('3.2');
* // => 3.2
*/
function toNumber(value) {
if (typeof value == "number") return value;
if (isSymbol(value)) return NAN;
if (isObject(value)) {
var other = typeof value.valueOf == "function" ? value.valueOf() : value;
value = isObject(other) ? other + "" : other;
}
if (typeof value != "string") return value === 0 ? value : +value;
value = value.replace(reTrim, "");
var isBinary = reIsBinary.test(value);
return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
}
module.exports = debounce;
} });
//#endregion
//#region ../../node_modules/.pnpm/usehooks-ts@3.1.1_react@19.0.0/node_modules/usehooks-ts/dist/index.js
var useIsomorphicLayoutEffect = typeof window !== "undefined" ? react.useLayoutEffect : react.useEffect;
function useEventListener(eventName, handler, element, options) {
const savedHandler = (0, react.useRef)(handler);
useIsomorphicLayoutEffect(() => {
savedHandler.current = handler;
}, [handler]);
(0, react.useEffect)(() => {
const targetElement = (element == null ? void 0 : element.current) ?? window;
if (!(targetElement && targetElement.addEventListener)) return;
const listener = (event) => {
savedHandler.current(event);
};
targetElement.addEventListener(eventName, listener, options);
return () => {
targetElement.removeEventListener(eventName, listener, options);
};
}, [
eventName,
element,
options
]);
}
function useEventCallback(fn) {
const ref = (0, react.useRef)(() => {
throw new Error("Cannot call an event handler while rendering.");
});
useIsomorphicLayoutEffect(() => {
ref.current = fn;
}, [fn]);
return (0, react.useCallback)((...args) => {
var _a;
return (_a = ref.current) == null ? void 0 : _a.call(ref, ...args);
}, [ref]);
}
var IS_SERVER = typeof window === "undefined";
function useLocalStorage(key, initialValue, options = {}) {
const { initializeWithValue = true } = options;
const serializer = (0, react.useCallback)((value) => {
if (options.serializer) return options.serializer(value);
return JSON.stringify(value);
}, [options]);
const deserializer = (0, react.useCallback)((value) => {
if (options.deserializer) return options.deserializer(value);
if (value === "undefined") return void 0;
const defaultValue = initialValue instanceof Function ? initialValue() : initialValue;
let parsed;
try {
parsed = JSON.parse(value);
} catch (error) {
console.error("Error parsing JSON:", error);
return defaultValue;
}
return parsed;
}, [options, initialValue]);
const readValue = (0, react.useCallback)(() => {
const initialValueToUse = initialValue instanceof Function ? initialValue() : initialValue;
if (IS_SERVER) return initialValueToUse;
try {
const raw = window.localStorage.getItem(key);
return raw ? deserializer(raw) : initialValueToUse;
} catch (error) {
console.warn(`Error reading localStorage key \u201C${key}\u201D:`, error);
return initialValueToUse;
}
}, [
initialValue,
key,
deserializer
]);
const [storedValue, setStoredValue] = (0, react.useState)(() => {
if (initializeWithValue) return readValue();
return initialValue instanceof Function ? initialValue() : initialValue;
});
const setValue = useEventCallback((value) => {
if (IS_SERVER) console.warn(`Tried setting localStorage key \u201C${key}\u201D even though environment is not a client`);
try {
const newValue = value instanceof Function ? value(readValue()) : value;
window.localStorage.setItem(key, serializer(newValue));
setStoredValue(newValue);
window.dispatchEvent(new StorageEvent("local-storage", { key }));
} catch (error) {
console.warn(`Error setting localStorage key \u201C${key}\u201D:`, error);
}
});
const removeValue = useEventCallback(() => {
if (IS_SERVER) console.warn(`Tried removing localStorage key \u201C${key}\u201D even though environment is not a client`);
const defaultValue = initialValue instanceof Function ? initialValue() : initialValue;
window.localStorage.removeItem(key);
setStoredValue(defaultValue);
window.dispatchEvent(new StorageEvent("local-storage", { key }));
});
(0, react.useEffect)(() => {
setStoredValue(readValue());
}, [key]);
const handleStorageChange = (0, react.useCallback)((event) => {
if (event.key && event.key !== key) return;
setStoredValue(readValue());
}, [key, readValue]);
useEventListener("storage", handleStorageChange);
useEventListener("local-storage", handleStorageChange);
return [
storedValue,
setValue,
removeValue
];
}
var IS_SERVER2 = typeof window === "undefined";
function useMediaQuery(query, { defaultValue = false, initializeWithValue = true } = {}) {
const getMatches = (query2) => {
if (IS_SERVER2) return defaultValue;
return window.matchMedia(query2).matches;
};
const [matches, setMatches] = (0, react.useState)(() => {
if (initializeWithValue) return getMatches(query);
return defaultValue;
});
function handleChange() {
setMatches(getMatches(query));
}
useIsomorphicLayoutEffect(() => {
const matchMedia = window.matchMedia(query);
handleChange();
if (matchMedia.addListener) matchMedia.addListener(handleChange);
else matchMedia.addEventListener("change", handleChange);
return () => {
if (matchMedia.removeListener) matchMedia.removeListener(handleChange);
else matchMedia.removeEventListener("change", handleChange);
};
}, [query]);
return matches;
}
var COLOR_SCHEME_QUERY = "(prefers-color-scheme: dark)";
var LOCAL_STORAGE_KEY = "usehooks-ts-dark-mode";
function useDarkMode(options = {}) {
const { defaultValue, localStorageKey = LOCAL_STORAGE_KEY, initializeWithValue = true } = options;
const isDarkOS = useMediaQuery(COLOR_SCHEME_QUERY, {
initializeWithValue,
defaultValue
});
const [isDarkMode, setDarkMode] = useLocalStorage(localStorageKey, defaultValue ?? isDarkOS ?? false, { initializeWithValue });
useIsomorphicLayoutEffect(() => {
if (isDarkOS !== isDarkMode) setDarkMode(isDarkOS);
}, [isDarkOS]);
return {
isDarkMode,
toggle: () => {
setDarkMode((prev) => !prev);
},
enable: () => {
setDarkMode(true);
},
disable: () => {
setDarkMode(false);
},
set: (value) => {
setDarkMode(value);
}
};
}
//#endregion
//#region src/web.ts
const useCSSInjection = () => {
const isDark = useDarkMode().isDarkMode;
(0, react.useInsertionEffect)(() => {
const style = document.createElement("style");
const vars1 = require_colors.colorVariants[isDark ? "dark" : "light"];
const vars2 = require_colors.palette[isDark ? "dark" : "light"];
style.innerHTML = `:root {${[...Object.entries(vars1), ...Object.entries(vars2)].map(([key, value]) => `${key}: ${value};`).join("\n")}}`;
document.head.append(style);
return () => {
style.remove();
};
}, [isDark]);
};
//#endregion
exports.useCSSInjection = useCSSInjection