@onesy/style-react
Version:
Onesy CSS in JS styling solution for React
1,276 lines (1,145 loc) • 347 kB
JavaScript
/** @license StyleReact v1.0.2
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.StyleReact = {}, global.React));
})(this, (function (exports, React) { 'use strict';
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
function getDefaultExportFromCjs (x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}
function getAugmentedNamespace(n) {
if (n.__esModule) return n;
var a = Object.defineProperty({}, '__esModule', {value: true});
Object.keys(n).forEach(function (k) {
var d = Object.getOwnPropertyDescriptor(n, k);
Object.defineProperty(a, k, d.get ? d : {
enumerable: true,
get: function () {
return n[k];
}
});
});
return a;
}
function commonjsRequire (path) {
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
}
var variationWithRepetition$1 = {};
var permutationWithRepetition$1 = {};
var global$1 = (typeof global !== "undefined" ? global :
typeof self !== "undefined" ? self :
typeof window !== "undefined" ? window : {});
var is$3 = {exports: {}};
(function (module, exports) {
Object.defineProperty(exports, "__esModule", { value: true });
const optionsDefault = {};
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
const isNodejs = !!(typeof global$1 !== 'undefined' && 'object' !== 'undefined' && module.exports);
// Multiple is methods instead of one,
// so it's lighter for tree shaking usability reasons
function is(type, value, options_ = {}) {
var _a;
const options = Object.assign(Object.assign({}, optionsDefault), options_);
const { variant } = options;
const prototype = value && typeof value === 'object' && Object.getPrototypeOf(value);
switch (type) {
case 'string':
return typeof value === 'string';
case 'number':
return typeof value === 'number' && !Number.isNaN(value);
case 'boolean':
return typeof value === 'boolean';
case 'array':
return Array.isArray(value);
case 'object':
const isObject = typeof value === 'object' && !!value && value.constructor === Object;
return isObject;
// Map, null, WeakMap, Date, etc.
case 'object-like':
return typeof value === 'object' && (value === null || value.constructor !== Object);
case 'class':
return ((typeof value === 'object' || typeof value === 'function') &&
(/class/gi.test(String(value)) || /class/gi.test(String(value === null || value === void 0 ? void 0 : value.constructor))));
case 'function':
return !!(value && value instanceof Function);
case 'async':
// If it's browser avoid calling the method
// to see if it's async func or not,
// where as in nodejs we have no other choice
// that i know of when using transpilation
// And also it might not be always correct, as
// a method that returns a promise is also async
// but we can't know that until the method is called and
// we inspect the method's return value
return !!(is('function', value) && (isBrowser ? value.constructor.name === 'AsyncFunction' : value() instanceof Promise));
case 'map':
return !!(prototype === Map.prototype);
case 'weakmap':
return !!(prototype === WeakMap.prototype);
case 'set':
return !!(prototype === Set.prototype);
case 'weakset':
return !!(prototype === WeakSet.prototype);
case 'promise':
return !!(prototype === Promise.prototype);
case 'int8array':
return !!(prototype === Int8Array.prototype);
case 'uint8array':
return !!(prototype === Uint8Array.prototype);
case 'uint8clampedarray':
return !!(prototype === Uint8ClampedArray.prototype);
case 'int16array':
return !!(prototype === Int16Array.prototype);
case 'uint16array':
return !!(prototype === Uint16Array.prototype);
case 'int32array':
return !!(prototype === Int32Array.prototype);
case 'uint32array':
return !!(prototype === Uint32Array.prototype);
case 'float32array':
return !!(prototype === Float32Array.prototype);
case 'float64array':
return !!(prototype === Float64Array.prototype);
case 'bigint64array':
return !!(prototype === BigInt64Array.prototype);
case 'biguint64array':
return !!(prototype === BigUint64Array.prototype);
case 'typedarray':
return is('int8array', value) || is('uint8array', value) || is('uint8clampedarray', value) || is('int16array', value) || is('uint16array', value) || is('int32array', value) || is('uint32array', value) || is('float32array', value) || is('float64array', value) || is('bigint64array', value) || is('biguint64array', value);
case 'dataview':
return !!(prototype === DataView.prototype);
case 'arraybuffer':
return !!(prototype === ArrayBuffer.prototype);
case 'sharedarraybuffer':
return typeof SharedArrayBuffer !== 'undefined' && !!(prototype === SharedArrayBuffer.prototype);
case 'symbol':
return !!(typeof value === 'symbol');
case 'error':
return !!(value && value instanceof Error);
case 'date':
return !!(value && value instanceof Date);
case 'regexp':
return !!(value && value instanceof RegExp);
case 'arguments':
return !!(value && value.toString() === '[object Arguments]');
case 'null':
return value === null;
case 'undefined':
return value === undefined;
case 'blob':
return isBrowser && value instanceof Blob;
case 'buffer':
return !!(isNodejs && typeof ((_a = value === null || value === void 0 ? void 0 : value.constructor) === null || _a === void 0 ? void 0 : _a.isBuffer) === 'function' && value.constructor.isBuffer(value));
case 'element':
if (value) {
switch (variant) {
case undefined:
case 'html':
case 'element':
return isBrowser && (typeof HTMLElement === 'object' ?
value instanceof HTMLElement :
value && typeof value === 'object' && value !== null && value.nodeType === 1 && typeof value.nodeName === 'string');
case 'node':
return isBrowser && (typeof Node === 'object' ?
value instanceof Node :
value && typeof value === 'object' && value !== null && typeof value.nodeType === 'number' && typeof value.nodeName === 'string');
case 'react':
return value.elementType || value.hasOwnProperty('$$typeof');
default:
return false;
}
}
return false;
case 'simple':
return (is('string', value, options) ||
is('number', value, options) ||
is('boolean', value, options) ||
is('undefined', value, options) ||
is('null', value, options));
case 'not-array-object':
return !is('array', value, options) && !is('object', value, options);
default:
return false;
}
}
exports.default = is;
}(is$3, is$3.exports));
var is$2 = /*@__PURE__*/getDefaultExportFromCjs(is$3.exports);
var unique$1 = {};
var getObjectValue$1 = {};
var getObjectPropertyValue = {};
var castParam$3 = {};
var __importDefault$r = (undefined && undefined.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(castParam$3, "__esModule", { value: true });
const is_1$i = __importDefault$r(is$3.exports);
const optionsDefault$q = {
decode: false,
decodeMethod: decodeURIComponent,
};
const castParam$2 = (value, options_ = {}) => {
const options = Object.assign(Object.assign({}, optionsDefault$q), options_);
let newValue = value;
try {
if ((0, is_1$i.default)('string', value) &&
options.decode &&
(0, is_1$i.default)('function', options.decodeMethod))
newValue = options.decodeMethod(value);
}
catch (error) { }
try {
if ((0, is_1$i.default)('string', newValue)) {
if ('undefined' === newValue)
return undefined;
if ('NaN' === newValue)
return NaN;
return JSON.parse(newValue);
}
return newValue;
}
catch (error) { }
return newValue;
};
var _default$n = castParam$3.default = castParam$2;
(function (exports) {
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getObjectPropertyValue = void 0;
const is_1 = __importDefault(is$3.exports);
const castParam_1 = __importDefault(castParam$3);
const getObjectPropertyValue = (object, keys) => {
if (!object || !keys)
return;
if ((0, is_1.default)('string', keys)) {
const keys_ = keys.split('.').filter(Boolean).map(key => (0, castParam_1.default)(key));
return (0, exports.getObjectPropertyValue)(object, keys_);
}
if ((0, is_1.default)('array', keys)) {
const key = keys[0];
if (keys.length === 1)
return object[key];
if (object.hasOwnProperty(key))
return (0, exports.getObjectPropertyValue)(object[key], keys.slice(1));
}
};
exports.getObjectPropertyValue = getObjectPropertyValue;
exports.default = exports.getObjectPropertyValue;
}(getObjectPropertyValue));
var __importDefault$q = (undefined && undefined.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(getObjectValue$1, "__esModule", { value: true });
const getObjectPropertyValue_1 = __importDefault$q(getObjectPropertyValue);
const getObjectValue = (object, ...args) => {
if (!object || !args.length)
return;
let value;
const keys = args.filter(Boolean);
for (const key of keys) {
value = (0, getObjectPropertyValue_1.default)(object, key);
if (value !== undefined)
return value;
}
};
getObjectValue$1.default = getObjectValue;
var __importDefault$p = (undefined && undefined.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(unique$1, "__esModule", { value: true });
const is_1$h = __importDefault$p(is$3.exports);
const getObjectValue_1 = __importDefault$p(getObjectValue$1);
/**
* It returns an array with unique simple values
* and / or array and object values.
*
* Referenced values are only compared based on
* values in those reference type values based on array
* of keys provided in the second argument in the method.
*
* Uniqueness of array and object values is separatelly
* evaluated based on keys value and returned in the result.
*/
const unique = (object, ...args) => {
const cache = {
simple: [],
array: [],
object: [],
};
const output = [];
if ((0, is_1$h.default)('array', object)) {
object.forEach(item => {
const isNotArrayObject = (0, is_1$h.default)('not-array-object', item);
const isArray = (0, is_1$h.default)('array', item);
const value = (isNotArrayObject || !args.length) ? item : (0, getObjectValue_1.default)(item, ...args);
const cacheArray = cache[isNotArrayObject ? 'simple' : isArray ? 'array' : 'object'];
const exists = cacheArray.find(cacheItem => value === cacheItem);
if (!exists && value !== undefined) {
output.push(item);
cache[isNotArrayObject ? 'simple' : isArray ? 'array' : 'object'].push(value);
}
});
}
return output;
};
var _default$m = unique$1.default = unique;
var __importDefault$o = (undefined && undefined.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(permutationWithRepetition$1, "__esModule", { value: true });
const is_1$g = __importDefault$o(is$3.exports);
const unique_1 = __importDefault$o(unique$1);
const optionsDefault$p = {
response: 'array',
};
// m - array
// m! / a! * b! * c! ...
function permutationWithRepetition(value_, options_ = {}) {
const options = Object.assign(Object.assign({}, optionsDefault$p), options_);
if ((0, is_1$g.default)('array', value_)) {
const value = (0, unique_1.default)(value_);
const length = value.length;
const items = (0, is_1$g.default)('number', options.items) ? options.items : length;
if (items < 1)
return [value];
if (items === 1)
return value.map(item_ => [item_]);
const item = new Array(items).fill(0);
let index = items - 2;
const response = [];
// Starts with all 0 indexes for all items
// it loops for the last position and makes each item for each index
// then, it moves to the left and increments the index by 1
// once item on left index increment moves over amount of items
// it resets to 0 index, and then it moves left and increments that item
// using same methodology, etc. until item at index 0 has index value === items.length
if (options.response === 'array') {
while (index >= 0) {
// Reset
index = items - 2;
for (let i = 0; i < length; i++) {
item[items - 1] = i;
response.push(item.map(index_ => value[index_]));
}
// Move to the left of the values
while (true) {
if (item[index] === length - 1) {
item[index] = 0;
index--;
if (index < 0)
break;
}
else {
item[index]++;
break;
}
}
}
return response;
}
if (options.response === 'yield')
return function* () {
while (index >= 0) {
// Reset
index = items - 2;
for (let i = 0; i < length; i++) {
item[items - 1] = i;
const item_ = item.map(index_ => value[index_]);
yield item_;
response.push(item_);
}
// Move to the left of the values
while (true) {
if (item[index] === length - 1) {
item[index] = 0;
index--;
if (index < 0)
break;
}
else {
item[index]++;
break;
}
}
}
return response;
};
}
}
permutationWithRepetition$1.default = permutationWithRepetition;
var __importDefault$n = (undefined && undefined.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(variationWithRepetition$1, "__esModule", { value: true });
const permutationWithRepetition_1 = __importDefault$n(permutationWithRepetition$1);
const optionsDefault$o = {
response: 'array',
};
// m - array, n - items
// m ** n
function variationWithRepetition(value_, items = 0, options_ = {}) {
const options = Object.assign(Object.assign({}, optionsDefault$o), options_);
return (0, permutationWithRepetition_1.default)(value_, Object.assign(Object.assign({}, options), { items }));
}
var _default$l = variationWithRepetition$1.default = variationWithRepetition;
var getEnvironment$1 = {};
Object.defineProperty(getEnvironment$1, "__esModule", { value: true });
const getEnvironment = () => {
if (typeof self !== 'undefined')
return self;
if (typeof window !== 'undefined')
return window;
if (typeof global$1 !== 'undefined')
return global$1;
};
var _default$k = getEnvironment$1.default = getEnvironment;
function _typeof(o) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, _typeof(o);
}
function toPrimitive(t, r) {
if ("object" != _typeof(t) || !t) return t;
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != _typeof(i)) return i;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
function toPropertyKey(t) {
var i = toPrimitive(t, "string");
return "symbol" == _typeof(i) ? i : i + "";
}
function _defineProperty(e, r, t) {
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
value: t,
enumerable: !0,
configurable: !0,
writable: !0
}) : e[r] = t, e;
}
var copy$1 = {};
Object.defineProperty(copy$1, "__esModule", { value: true });
const isArray = value => Array.isArray(value);
const isObject = value => typeof value === 'object' && !!value && value.constructor === Object;
// It keeps the references of the methods and classes,
// unlike JSON.stringify usually used for deep simple copy
const copy = (value, values_) => {
const values = !values_ ? new WeakSet() : values_;
// Ref circular value
if (values.has(value))
return value;
if (isObject(value) || isArray(value))
values.add(value);
if (isArray(value))
return value.map(item => copy(item, values));
if (isObject(value)) {
const newValue = {};
Object.keys(value).forEach(key => newValue[key] = copy(value[key], values));
return newValue;
}
return value;
};
var _default$j = copy$1.default = copy;
var _try = {};
var setObjectValue$1 = {};
var cleanValue = {};
var capitalize$2 = {};
var __importDefault$m = (undefined && undefined.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(capitalize$2, "__esModule", { value: true });
const is_1$f = __importDefault$m(is$3.exports);
const capitalize$1 = (value) => {
if ((0, is_1$f.default)('string', value))
return `${value.charAt(0).toUpperCase()}${value.slice(1)}`;
return value;
};
capitalize$2.default = capitalize$1;
(function (exports) {
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.optionsDefault = void 0;
const is_1 = __importDefault(is$3.exports);
const capitalize_1 = __importDefault(capitalize$2);
exports.optionsDefault = {
filters: [',', '.', '-', '_', '\s+'],
replaceWith: ' ',
trim: true,
};
const cleanValue = (value_, options_ = {}) => {
try {
const options = Object.assign(Object.assign({}, exports.optionsDefault), options_);
// Few predefined options
// for className cammel case to regular
// css property names convert
if (options.className) {
options.replaceWith = '-';
options.cammelCaseTransform = true;
options.lowercase = true;
}
if ((0, is_1.default)('string', value_)) {
let value = value_;
if (options.url) {
const parts = value.split('?').filter(Boolean);
let path = parts[0];
const query = parts[1];
if (path.slice(-1) === '/')
path = path.slice(0, -1);
value = query ? [path, query].join('?') : path;
return value;
}
if (options.cammelCaseTransform)
value = value.split(/(?=[A-Z])/g).join(options.replaceWith || ' ');
options.filters.forEach(filter => {
const expression = `\\${filter}`;
const regexp = new RegExp(expression, 'g');
value = value.replace(regexp, options.replaceWith || ' ');
});
if (options.trim)
value = value.trim();
if (options.capitalize)
value = (0, capitalize_1.default)(value);
if (options.lowercase)
value = value.toLocaleLowerCase();
return value;
}
return value_;
}
catch (error) { }
return value_;
};
exports.default = cleanValue;
}(cleanValue));
var __importDefault$l = (undefined && undefined.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(setObjectValue$1, "__esModule", { value: true });
const is_1$e = __importDefault$l(is$3.exports);
const cleanValue_1 = __importDefault$l(cleanValue);
const castParam_1$5 = __importDefault$l(castParam$3);
const optionsDefault$n = {
valueOverride: false
};
const setObjectValue = (object, keys = '', value = undefined, options_ = {}) => {
const options = Object.assign(Object.assign({}, optionsDefault$n), options_);
if (!(object || keys))
return object;
if ((0, is_1$e.default)('string', keys)) {
const keys_ = keys.split('.').filter(Boolean).map(key => (0, castParam_1$5.default)(key));
return setObjectValue(object, keys_, value, options);
}
if ((0, is_1$e.default)('array', keys)) {
const key = keys[0];
const keyClean = (0, cleanValue_1.default)(String(key), { filters: ['.', ','], replaceWith: '' });
if (keys.length === 1) {
if (((0, is_1$e.default)('array', object) && (0, is_1$e.default)('number', key)) ||
(0, is_1$e.default)('object', object)) {
// Add array or object as a value of the key, if that key doesn't exist atm
if (!(object === null || object === void 0 ? void 0 : object.hasOwnProperty(key)) ||
options.valueOverride)
object[keyClean] = (0, is_1$e.default)('number', keys[1]) ? [] : {};
object[(0, is_1$e.default)('string', key) ? keyClean : key] = value;
}
}
else {
if (((0, is_1$e.default)('array', object) && (0, is_1$e.default)('number', key)) ||
(0, is_1$e.default)('object', object)) {
// Add array or object as a value of the key, if that key doesn't exist atm
if (!(object === null || object === void 0 ? void 0 : object.hasOwnProperty(key)) ||
options.valueOverride)
object[keyClean] = (0, is_1$e.default)('number', keys[1]) ? [] : {};
}
const value_ = object[keyClean];
// If we are trying to set a deeply nested value on a
// simple value type, meaning if it's not an array or an object,
// To override existing value use valueOverride: true option
if (!((0, is_1$e.default)('object', value_) || (0, is_1$e.default)('array', value_)))
return object;
return setObjectValue(object[key], keys.slice(1), value, options);
}
}
return object;
};
setObjectValue$1.default = setObjectValue;
var __importDefault$k = (undefined && undefined.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(_try, "__esModule", { value: true });
const is_1$d = __importDefault$k(is$3.exports);
const getEnvironment_1 = __importDefault$k(getEnvironment$1);
const setObjectValue_1 = __importDefault$k(setObjectValue$1);
const optionsDefault$m = {};
const Try = (value, options_ = {}) => {
var _a, _b, _c, _d;
const options = Object.assign(Object.assign({}, optionsDefault$m), options_);
try {
return (0, is_1$d.default)('function', value) ? value() : undefined;
}
catch (error) {
if (options.log) {
console.error('Try: ', error);
const env = (0, getEnvironment_1.default)();
if (((_a = env.AMAUI) === null || _a === void 0 ? void 0 : _a.env) === 'test') {
if (!((_d = (_c = (_b = env.AMAUI) === null || _b === void 0 ? void 0 : _b.test) === null || _c === void 0 ? void 0 : _c.Try) === null || _d === void 0 ? void 0 : _d.logs))
(0, setObjectValue_1.default)(env, 'AMAUI.test.Try.logs', []);
env.AMAUI.test.Try.logs.push(error);
}
}
}
};
var _default$i = _try.default = Try;
const optionsDefault$l = {
emit: {
priorValue: true,
copy: false,
pre: {},
post: {}
}
};
class OnesySubscription {
constructor(value) {
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
_defineProperty(this, "methods", []);
_defineProperty(this, "push", this.emit);
this.value = value;
this.options = options;
this.options = { ...optionsDefault$l,
...this.options
};
}
get length() {
return this.methods.length;
}
emit(value) {
var _this$options$emit, _this$options$emit$pr, _this$options$emit$po;
for (var _len = arguments.length, other = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
other[_key - 1] = arguments[_key];
}
const values = [value, ...other]; // Important for use cases,
// to be available pre emit,
// Save value as last emitted value as a previous state optionally
if ((_this$options$emit = this.options.emit) !== null && _this$options$emit !== void 0 && _this$options$emit.priorValue) this.value = values.length === 1 ? values[0] : values; // Pre
// Value might be of simple type so we have to assign a new value to the value
if (is$2('function', (_this$options$emit$pr = this.options.emit.pre) === null || _this$options$emit$pr === void 0 ? void 0 : _this$options$emit$pr.method)) this.options.emit.pre.method(...values); // Whether to send a copied value version or not,
// it might be useful since if value is of reference type,
// methods in the beginning might update the value,
// and other following methods wouldn't get the
// same value as it was sent to the first method.
const methodValue = this.options.emit.copy ? _default$j(values) : values;
const methods = this.methods.filter(method => is$2('function', method)); // Emit to methods
for (const method of methods) _default$i(() => method(...methodValue)); // Post
// Value might be of simple type so we have to assign a new value to the value
if (is$2('function', (_this$options$emit$po = this.options.emit.post) === null || _this$options$emit$po === void 0 ? void 0 : _this$options$emit$po.method)) this.options.emit.post.method(...values);
} // alias
forEach() {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
this.methods.forEach(method => _default$i(() => method(...args)));
}
map(value_) {
if (!this.methods.length) return;
let value = value_;
for (const method of this.methods) value = _default$i(() => method(value));
return value;
}
subscribe(method) {
if (is$2('function', method) && this.methods.indexOf(method) === -1) this.methods.push(method);
const instance = this;
return {
unsubscribe: () => {
instance.unsubscribe(method);
}
};
}
unsubscribe(method) {
if (is$2('function', method) && this.methods.indexOf(method) > -1) {
const index = this.methods.findIndex(method_ => method_ === method);
if (index > -1) this.methods.splice(index, 1);
}
}
}
var OnesySubscription$1 = OnesySubscription;
const cammelCaseToKebabCase = value => is$1('string', value) ? value.replace(/[A-Z]/g, v => "-".concat(v[0])).toLowerCase() : value;
const kebabCasetoCammelCase = value => is$1('string', value) ? value.replace(/-./g, v => v[1] !== undefined ? v[1].toUpperCase() : '') : value;
const capitalizedCammelCase = value => capitalize(kebabCasetoCammelCase(value));
const capitalize = value => is$1('string', value) ? value.charAt(0).toUpperCase() + value.slice(1) : value;
const is$1 = (version, value) => {
switch (version) {
case 'string':
return typeof value === 'string';
case 'number':
return typeof value === 'number' && !Number.isNaN(value);
case 'array':
return Array.isArray(value);
case 'boolean':
return typeof value === 'boolean';
case 'null':
return value === null;
case 'undefined':
return value === undefined;
case 'object':
const isObject = typeof value === 'object' && !!value && value.constructor === Object;
return isObject;
case 'function':
return !!(value && value instanceof Function);
case 'simple':
return is$1('string', value) || is$1('number', value) || is$1('boolean', value) || is$1('undefined', value) || is$1('null', value);
default:
return;
}
};
const isOnesySubscription = value => value instanceof OnesySubscription$1 || is$1('function', value === null || value === void 0 ? void 0 : value.emit);
const getRefs = value => {
const items = [];
if (is$1('string', value)) {
const regex = /\$[a-zA-Z1-9_]+/g;
items.push(...(value.match(regex) || []).map(item => item.replace('$', '')));
}
return items;
};
const valueResolve = (property, value, onesyStyle) => {
const response = {
value: [],
options: {}
}; // Mange all the values
if (is$1('string', property) && !!property.length && value !== undefined && onesyStyle) {
// String
if (is$1('string', value)) response.value = [value]; // Number
else if (is$1('number', value)) {
var _onesyStyle$subscript;
const unit = (_onesyStyle$subscript = onesyStyle.subscriptions.rule.unit.map({
property,
value
})) === null || _onesyStyle$subscript === void 0 ? void 0 : _onesyStyle$subscript.value;
response.value = [(unit === null || unit === void 0 ? void 0 : unit.value) || value];
} // Array of simple
else if (is$1('array', value) && value.every(item => is$1('simple', item))) {
response.value = [value.flatMap(item => valueResolve(property, item, onesyStyle).value).join(' ')];
} // Array of arrays
// Array of objects
else if (is$1('array', value) && value.every(item => is$1('array', item) || is$1('object', item))) {
response.value = [value.flatMap(item => valueResolve(property, item, onesyStyle).value).join(', ')];
} // Object
else if (is$1('object', value)) {
// Object value
if (value.value) {
const fallbacks = (value.fallbacks || []).flatMap(item => valueResolve(property, item, onesyStyle).value);
response.value = [fallbacks, valueResolve(property, value.value, onesyStyle).value].flat().filter(Boolean);
if (value.rule) response.options.rule = value.rule;
} else {
var _onesyStyle$subscript2;
// Value plugins
const value_ = (_onesyStyle$subscript2 = onesyStyle.subscriptions.rule.value.map({
property,
value
})) === null || _onesyStyle$subscript2 === void 0 ? void 0 : _onesyStyle$subscript2.value;
response.value = value_ || [];
}
} // Method
// OnesySubscription
// For methods and OnesySubscription leave as is
// these are only used during add method
else response.value = [value];
}
return response;
};
const dynamic = value => is$1('function', value) || isOnesySubscription(value) || is$1('object', value) && Object.keys(value).some(prop => dynamic(value[prop]));
function* makeName() {
let length_ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2;
let input_ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'abcdefghijklmnopqrstuvwxyz';
const input = is$1('array', input_) ? input_ : input_.split('');
let length = length_;
let value;
let methodNameGenerator = _default$l(input, length, {
response: 'yield'
})();
while (true) {
var _value;
value = methodNameGenerator.next();
if ((_value = value) !== null && _value !== void 0 && _value.done) {
methodNameGenerator = _default$l(input, ++length, {
response: 'yield'
})();
value = methodNameGenerator.next();
}
yield value.value.join('');
}
}
const pxToRem = function (value) {
let htmlFontSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 16;
return Number((value / htmlFontSize).toFixed(4));
};
const env$2 = _default$k();
env$2.onesy_methods = {
makeName: makeName()
};
const names = value => {
if (is$1('object', value)) {
// Update styles, className and class
if (!value.hasOwnProperty('className')) Object.defineProperty(value, 'className', {
get: function () {
return Object.keys(value.classNames).map(item => value.classNames[item]).join(' ');
}
});
if (!value.hasOwnProperty('class')) Object.defineProperty(value, 'class', {
get: function () {
return Object.keys(value.classes).map(item => value.classes[item]).join(' ');
}
});
if (!value.hasOwnProperty('styles')) value.styles = function () {
const values = [];
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
args.forEach(arg => {
if (value.classes[arg]) values.push(value.classes[arg]);
});
return values.join(' ');
};
return value;
}
return value;
};
let i$1 = 0;
const getID = () => "".concat(i$1++, "-").concat(new Date().getTime());
const minify = value => value.replace(/\n/g, '').replace(/ ?(\{|:|,|>|~) ?/g, '$1').replace(/;(\})/g, '$1');
var element$1 = {};
var isEnvironment$1 = {};
var __importDefault$j = (undefined && undefined.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(isEnvironment$1, "__esModule", { value: true });
const is_1$c = __importDefault$j(is$3.exports);
function isEnvironment(type, value) {
let value_;
switch (type) {
case 'browser':
return typeof window !== 'undefined' && typeof window.document !== 'undefined';
case 'worker':
return typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
case 'nodejs':
return (new Function('try {return this===global;}catch(e){return false;}'))();
case 'localhost':
value_ = value !== undefined ? value : (isEnvironment('browser') && window.location.hostname);
return (0, is_1$c.default)('string', value_) && ['localhost', '127.0.0.1'].some(value__ => value_.indexOf(value__) > -1);
default:
return false;
}
}
var _default$h = isEnvironment$1.default = isEnvironment;
var __importDefault$i = (undefined && undefined.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(element$1, "__esModule", { value: true });
const is_1$b = __importDefault$i(is$3.exports);
const isEnvironment_1$2 = __importDefault$i(isEnvironment$1);
const try_1 = __importDefault$i(_try);
function element(value) {
const object = {};
object.value = value;
if ((0, is_1$b.default)('string', value))
object.value = window.document.querySelector(value);
if (!(0, is_1$b.default)('element', object.value))
delete object.value;
const matches = (value_ = object.value) => {
const method = (0, is_1$b.default)('element', value_) && (value_.matches || value_['webkitMatchesSelector'] || value_['mozMatchesSelector'] || value_['oMatchesSelector'] || value_['msMatchesSelector']);
if (!method)
return () => false;
return method.bind(value_);
};
// Parent
object.parent = function () {
if (this.value && (0, isEnvironment_1$2.default)('browser') && this.value.parentNode)
return this.value.parentNode;
};
// Parents
object.parents = function (selectors, arrayMethod = 'some') {
const parents = [];
let parent = this.value;
while (parent && parent !== document) {
parent = element(parent).parent();
if (parent &&
(!(selectors === null || selectors === void 0 ? void 0 : selectors.length) ||
selectors[arrayMethod] && selectors[arrayMethod](item => (0, try_1.default)(() => matches(parent)(item)))))
parents.push(parent);
}
return parents;
};
// Nearest
object.nearest = function (selectors, arrayMethod = 'some') {
// Value matches
// return itself in that use case
if (!(selectors === null || selectors === void 0 ? void 0 : selectors.length) ||
selectors[arrayMethod] && selectors[arrayMethod](item => (0, try_1.default)(() => matches(this.value)(item))))
return this.value;
let parent = this.value;
while (parent && parent !== document) {
parent = element(parent).parent();
if (parent &&
(!(selectors === null || selectors === void 0 ? void 0 : selectors.length) ||
selectors[arrayMethod] && selectors[arrayMethod](item => (0, try_1.default)(() => matches(parent)(item)))))
return parent;
}
};
// Furthest
object.furthest = function (selectors, arrayMethod = 'some') {
const parents = this.parents(selectors, arrayMethod);
return parents[parents.length - 1];
};
// hasParent
object.hasParent = function (selectors, grandparents = true, arrayMethod = 'some') {
let parent = this.value;
if (!grandparents)
return (!(selectors === null || selectors === void 0 ? void 0 : selectors.length) ||
selectors[arrayMethod] && selectors[arrayMethod](item => (0, try_1.default)(() => matches(this.parent())(item))));
while (parent && parent !== document) {
parent = element(parent).parent();
if (parent &&
(!(selectors === null || selectors === void 0 ? void 0 : selectors.length) ||
selectors[arrayMethod] && selectors[arrayMethod](item => (0, try_1.default)(() => matches(parent)(item)))))
return true;
}
return false;
};
// hasParents
// If unique is true, sort selectors argument by most specifc first
// and lowest specificty last for the most proper result
object.hasParents = function (selectors, unique = true, arrayMethod = 'some') {
if (!(selectors === null || selectors === void 0 ? void 0 : selectors.length))
return !!this.parent();
const parents = this.parents();
return !!(this.value &&
((selectors === null || selectors === void 0 ? void 0 : selectors.length) &&
(selectors[arrayMethod] && selectors[arrayMethod](selector => {
const index = parents.findIndex((item) => (0, is_1$b.default)('string', selector) ? (0, try_1.default)(() => matches(item)(selector)) : item === selector);
if (index > -1) {
if (unique)
parents.splice(index, 1);
return true;
}
return false;
}))));
};
return object;
}
var _default$g = element$1.default = element;
var merge$1 = {};
var __importDefault$h = (undefined && undefined.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(merge$1, "__esModule", { value: true });
const is_1$a = __importDefault$h(is$3.exports);
const copy_1 = __importDefault$h(copy$1);
const optionsDefault$k = {
copy: false,
merge: {
array: false,
},
};
const merge = (target, source, options_ = {}) => {
const options = Object.assign(Object.assign({}, optionsDefault$k), options_);
if (options.merge.array &&
(0, is_1$a.default)('array', target) && (0, is_1$a.default)('array', source)) {
const length = Math.max(target.length, source.length);
for (let i = 0; i < length; i++) {
if (target[i] === undefined)
target[i] = source[i];
if (((0, is_1$a.default)('object', target[i]) && (0, is_1$a.default)('object', source[i])) ||
(0, is_1$a.default)('array', target[i]) && (0, is_1$a.default)('array', source[i]))
target[i] = merge(target[i], source[i], options);
}
}
if ((0, is_1$a.default)('object', target) && (0, is_1$a.default)('object', source)) {
Object.keys(source).forEach(key => {
// We only care about direct target object properties
// not about inherited properties from a prototype chain
if (target.hasOwnProperty(key)) {
if ((0, is_1$a.default)('object', target[key]) && (0, is_1$a.default)('object', source[key]))
target[key] = merge(target[key], source[key], options);
}
else
target[key] = options.copy ? (0, copy_1.default)(source[key]) : source[key];
});
}
return target;
};
var _default$f = merge$1.default = merge;
const unix = () => Math.floor(new Date().getTime() / 1000);
const optionsDefault$j = {
value: {
copy: false
},
add: {
override: true
}
};
class OnesyMeta {
static meta = new WeakMap();
static options_ = optionsDefault$j;
static get options() {
return this.options_;
}
static set options(value) {
this.options_ = { ...this.options,
...value
};
} // Class decorator
static class() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return object => {
const [key, value] = args; // Add key and value to object which is a class itself
this.add(key, value, object);
};
} // Method decorator
static method() {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return (object_, property) => {
const object = object_.constructor;
const [key, value] = args; // Add key and value to object property which is a class's method
this.add(key, value, object, property);
};
} // Property decorator
static property() {
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
return (object_, property) => {
const object = object_.constructor;
const [key, value] = args; // Add key and value to object property which is a class's property
this.add(key, value, object, property);
};
} // Parameter decorator
static parameter() {
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
args[_key4] = arguments[_key4];
}
return (object_, property, parameterIndex) => {
const object = object_.constructor;
const [value] = args; // Add key and value to object property which is a class's method
this.add("onesy-meta-param:".concat(parameterIndex), value, object, property);
};
}
static add(key, value, object, property) {
// A WeakMap's key can only be
// of a reference value type
if (!is$2('simple', object)) {
const value_ = this.options.value.copy ? _default$j(value) : value;
let mapObject = this.meta.get(object);
if (!mapObject) {
// Add a new map for the object
mapObject = new Map();
this.meta.set(object, mapObject);
}
if (property !== undefined) {
let mapProperty = mapObject.get(property);
if (!mapProperty) {
// Add a new map for the object's property
mapProperty = new Map();
mapObject.set(property, mapProperty);
}
if (!mapProperty.has(key) || this.options.add.override) {
// Set map property's key and value
mapProperty.set(key, {
value: this.options.value.copy ? _default$j(value) : value,
added_at: unix()
});
return value_;
}
} else {
if (!mapObject.has(key) || this.options.add.override) {
// Set map object's key and value
mapObject.set(key, {
value: this.options.value.copy ? _default$j(value) : value,
added_at: unix()
});
return value_;
}
}
}
}
static update(key, value, object, property) {
// A WeakMap's key can only be
// of a reference value type
if (!is$2('simple', object)) {
const value_ = this.options.value.copy ? _default$j(value) : value;
let mapObject = this.meta.get(object);
if (!mapObject) {
// Add a new map for the object
mapObject = new Map();
this.meta.set(object, mapObject);
}
if (property !== undefined) {
let mapProperty = mapObject.get(property);
if (!mapProperty) {
// Add a new map for the object's property
mapProperty = new Map();
mapObject.set(property, mapProperty);
}
if (mapProperty.has(key)) {
// Set map property's key and value
const atmValue = mapProperty.get(key);
atmValue.value = value_;
atmValue.updated_at = unix();
mapProperty.set(key, atmValue);
return value_;
}
} else {
if (mapObject.has(key)) {
// Set map object's key and value
const atmValue = mapObject.get(key);
atmValue.value = value_;
atmValue.updated_at = unix();
mapObject.set(key, atmValue);
return value_;
}
}
}
}
static get(key, object, property) {
// A WeakMap's key can only be
// of a reference value type
if (!is$2('simple', object)) {
const mapObject = this.meta.get(object);
if (!mapObject) return;
if (property !== undefined) {
const mapProperty = mapObject.get(property);
if (!mapProperty) return;
if (!mapProperty.has(key)) return; // Get map property key's and value
return this.options.value.copy ? _default$j(mapProperty.get(key).value) : mapProperty.get(key).value;
}
if (!mapObject.has(key)) return; // Get map object key's and value
return this.options.value.copy ? _default$j(mapObject.get(key).value) : mapObject.get(key).value;
}
}
static has(key, object, property) {
// A WeakMap's key can only be
// of a reference value type
if (!is$2('simple', object)) {
const mapObject = this.meta.get(object);
if (!mapObject) return false;
if (property !== undefined) {
const mapProperty = mapObject.get(property);
if (!mapProperty) return false; // Map has property key
return mapProperty.has(key);
} //