151 lines
4.3 KiB
JavaScript
151 lines
4.3 KiB
JavaScript
"use strict";
|
|
var __create = Object.create;
|
|
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __getProtoOf = Object.getPrototypeOf;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
mod
|
|
));
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
|
|
// src/responsive.ts
|
|
var responsive_exports = {};
|
|
__export(responsive_exports, {
|
|
arrayToObjectNotation: () => arrayToObjectNotation,
|
|
breakpoints: () => breakpoints,
|
|
isCustomBreakpoint: () => isCustomBreakpoint,
|
|
isResponsiveObjectLike: () => isResponsiveObjectLike,
|
|
mapResponsive: () => mapResponsive,
|
|
objectToArrayNotation: () => objectToArrayNotation
|
|
});
|
|
module.exports = __toCommonJS(responsive_exports);
|
|
|
|
// src/array.ts
|
|
function getLastItem(array) {
|
|
const length = array == null ? 0 : array.length;
|
|
return length ? array[length - 1] : void 0;
|
|
}
|
|
|
|
// src/assertion.ts
|
|
function isArray(value) {
|
|
return Array.isArray(value);
|
|
}
|
|
function isObject(value) {
|
|
const type = typeof value;
|
|
return value != null && (type === "object" || type === "function") && !isArray(value);
|
|
}
|
|
var __DEV__ = process.env.NODE_ENV !== "production";
|
|
var __TEST__ = process.env.NODE_ENV === "test";
|
|
|
|
// src/object.ts
|
|
var import_lodash = __toESM(require("lodash.mergewith"));
|
|
function get(obj, path, fallback, index) {
|
|
const key = typeof path === "string" ? path.split(".") : [path];
|
|
for (index = 0; index < key.length; index += 1) {
|
|
if (!obj)
|
|
break;
|
|
obj = obj[key[index]];
|
|
}
|
|
return obj === void 0 ? fallback : obj;
|
|
}
|
|
var memoize = (fn) => {
|
|
const cache = /* @__PURE__ */ new WeakMap();
|
|
const memoizedFn = (obj, path, fallback, index) => {
|
|
if (typeof obj === "undefined") {
|
|
return fn(obj, path, fallback);
|
|
}
|
|
if (!cache.has(obj)) {
|
|
cache.set(obj, /* @__PURE__ */ new Map());
|
|
}
|
|
const map = cache.get(obj);
|
|
if (map.has(path)) {
|
|
return map.get(path);
|
|
}
|
|
const value = fn(obj, path, fallback, index);
|
|
map.set(path, value);
|
|
return value;
|
|
};
|
|
return memoizedFn;
|
|
};
|
|
var memoizedGet = memoize(get);
|
|
var objectKeys = (obj) => Object.keys(obj);
|
|
|
|
// src/responsive.ts
|
|
var breakpoints = Object.freeze([
|
|
"base",
|
|
"sm",
|
|
"md",
|
|
"lg",
|
|
"xl",
|
|
"2xl"
|
|
]);
|
|
function mapResponsive(prop, mapper) {
|
|
if (isArray(prop)) {
|
|
return prop.map((item) => {
|
|
if (item === null) {
|
|
return null;
|
|
}
|
|
return mapper(item);
|
|
});
|
|
}
|
|
if (isObject(prop)) {
|
|
return objectKeys(prop).reduce((result, key) => {
|
|
result[key] = mapper(prop[key]);
|
|
return result;
|
|
}, {});
|
|
}
|
|
if (prop != null) {
|
|
return mapper(prop);
|
|
}
|
|
return null;
|
|
}
|
|
function objectToArrayNotation(obj, bps = breakpoints) {
|
|
const result = bps.map((br) => {
|
|
var _a;
|
|
return (_a = obj[br]) != null ? _a : null;
|
|
});
|
|
while (getLastItem(result) === null) {
|
|
result.pop();
|
|
}
|
|
return result;
|
|
}
|
|
function arrayToObjectNotation(values, bps = breakpoints) {
|
|
const result = {};
|
|
values.forEach((value, index) => {
|
|
const key = bps[index];
|
|
if (value == null)
|
|
return;
|
|
result[key] = value;
|
|
});
|
|
return result;
|
|
}
|
|
function isResponsiveObjectLike(obj, bps = breakpoints) {
|
|
const keys = Object.keys(obj);
|
|
return keys.length > 0 && keys.every((key) => bps.includes(key));
|
|
}
|
|
var isCustomBreakpoint = (maybeBreakpoint) => Number.isNaN(Number(maybeBreakpoint));
|
|
// Annotate the CommonJS export names for ESM import in node:
|
|
0 && (module.exports = {
|
|
arrayToObjectNotation,
|
|
breakpoints,
|
|
isCustomBreakpoint,
|
|
isResponsiveObjectLike,
|
|
mapResponsive,
|
|
objectToArrayNotation
|
|
});
|