jqx-es 1.0.7 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/LifeCSS.js ADDED
@@ -0,0 +1,12 @@
1
+ var{IS:N,maybe:J,$Wrap:K,xProxy:Q,isNothing:V}=C();function C(){Symbol.proxy=Symbol.for("toa.proxy"),Symbol.is=Symbol.for("toa.is"),Symbol.type=Symbol.for("toa.type"),Symbol.isSymbol=Symbol.for("toa.isASymbol"),l();let n=h(),[i,f]=[u(),p()];return f.custom(),{IS:s,maybe:n,$Wrap:i,isNothing:b,xProxy:f};function s(e,...t){if(n({trial:c=>"isTypes"in(t?.[0]??{})})){let c=t[0];return"defaultValue"in c?y(e,c):"notTypes"in c?r(e,c):s(e,...[c.isTypes].flat())}let o=typeof e=="symbol"?Symbol.isSymbol:e;return t.length>1?P(o,...t):$(e,...t)}function S(e){return e?.[Symbol.proxy]??s(e)}function $(e,...t){let{noInput:o,noShouldbe:c,compareTo:g,inputCTOR:R,isNaN:j,isInfinity:F,shouldBeFirstElementIsNothing:A}=O(e,...t);switch(t=t.length&&t[0],!0){case A:return String(e)===String(g);case(e?.[Symbol.proxy]&&c):return e[Symbol.proxy];case j:return c?"NaN":n({trial:E=>String(g)})===String(e);case F:return c?"Infinity":n({trial:E=>String(g)})===String(e);case o:return c?String(e):String(g)===String(e);case R===Boolean:return t?R===t:"Boolean";default:return d(e,t,c,x(e,R))}}function x(e,t){return e===0?Number:e===""?String:e?t:{name:String(e)}}function O(e,...t){let o=t.length<1,c=!o&&t[0],g=!o&&b(t[0]),R=e==null,j=!R&&Object.getPrototypeOf(e)?.constructor,F=n({trial:E=>String(e)})==="NaN",A=n({trial:E=>String(e)})==="Infinity";return{noInput:R,noShouldbe:o,compareTo:c,inputCTOR:j,isNaN:F,isInfinity:A,shouldBeFirstElementIsNothing:g}}function d(e,t,o,c){switch(!0){case(!o&&t===e||e?.[Symbol.proxy]&&t===Proxy):return!0;case n({trial:g=>String(t)})==="NaN":return String(e)==="NaN";case(e?.[Symbol.toStringTag]&&s(t,String)):return String(t)===e[Symbol.toStringTag];default:return t?n({trial:g=>e instanceof t})||t===c||t===Object.getPrototypeOf(c)||`${t?.name}`===c?.name:e?.[Symbol.toStringTag]&&`[object ${e?.[Symbol.toStringTag]}]`||c?.name||String(c)}}function P(e,...t){return t.some(o=>s(e,o))}function b(e,t=!1){let o=e==null;return o=t?o||s(e,1/0)||s(e,NaN):o,o}function h(){let e=(t,o)=>t?.constructor===Function?t(o):void 0;return function({trial:t,whenError:o=()=>{}}={}){try{return e(t)}catch(c){return e(o,c)}}}function u(){return function(e){return Object.freeze({get value(){return e},get[Symbol.type](){return S(e)},get type(){return S(e)},[Symbol.is](...t){return s(e,...t)},is(...t){return s(e,...t)}})}}function y(e,{defaultValue:t,isTypes:o=[void 0],notTypes:c}={}){return o=o?.constructor!==Array?[o]:o,c=c&&c?.constructor!==Array?[c]:[],c.length<1?s(e,...o)?e:t:r(e,{isTypes:o,notTypes:c})?e:t}function r(e,{isTypes:t=[void 0],notTypes:o=[void 0]}={}){return t=t?.constructor!==Array?[t]:t,o=o?.constructor!==Array?[o]:o,s(e,...t)&&!s(e,...o)}function l(){Object.getOwnPropertyDescriptors(Object.prototype)[Symbol.is]||(Object.defineProperties(Object.prototype,{[Symbol.type]:{get(){return S(this)},enumerable:!1,configurable:!1},[Symbol.is]:{value:function(...e){return s(this,...e)},enumerable:!1,configurable:!1}}),Object.defineProperties(Object,{[Symbol.type]:{value(e){return S(e)},enumerable:!1,configurable:!1},[Symbol.is]:{value:function(e,...t){return s(e,...t)},enumerable:!1,configurable:!1}}))}function a(e){let t=String(Object.getPrototypeOf(e)?.constructor);return t.slice(t.indexOf("ion")+3,t.indexOf("(")).trim()}function m(e){let t=e.set;return e.set=(o,c,g)=>c===Symbol.proxy?o[c]=g:t(o,c,g),e}function p(){let e=Proxy;return{native(){Proxy=e},custom(){Proxy=new e(e,{construct(t,o){for(let g of o)g.set&&(g=m(g));let c=new t(...o);return c[Symbol.proxy]=`Proxy (${a(o[0])})`,c}})}}}}var M=k;function k({styleSheet:n,createWithId:i}={}){let{tryParseAtOrNestedRules:f,ruleExists:s,checkParams:S,sheet:$,removeRules:x,consider:O,currentSheetID:d}=L({styleSheet:n,createWithId:i});function P(r,l){if(r&&l.removeProperties){Object.keys(l.removeProperties).forEach(a=>r.style.removeProperty(I(a)));return}Object.entries(l).forEach(([a,m])=>{a=I(a.trim()),m=m.trim();let p;if(/!important/.test(m)&&(m=m.slice(0,m.indexOf("!important")).trim(),p="important"),!CSS.supports(a,m))return console.error(`StylingFactory ${d} error: '${a}' with value '${m}' not supported (yet)`);v(()=>r.style.setProperty(a,m,p),`StylingFactory ${d} (setRule4Selector) failed`)})}function b(r,l,a=$){if(r=r?.trim?.(),!N(r,String)||!r.length||/[;,]$/g.test(r))return console.error(`StylingFactory ${d} (setRules): [${r||"[no selector given]"}] is not a valid selector`);if(l.removeRule)return x(r);let m=s(r,!0),p=m||a.cssRules[a.insertRule(`${r} {}`,a.cssRules.length||0)];return O(()=>P(p,l),r,m)}function h(r){let l=r.trim().split(/{/,2),a=l.shift().trim();if(!N(a,String)||!a?.trim()?.length)return console.error(`StylingFactory ${d} (doParse): no (valid) selector could be extracted from rule ${w(r)}`);let m=G(l.shift());return v(()=>b(a,m),`StylingFactory ${d} (setRules) failed`)}function u(r){let l=f(r);return l.done?l.existing:h(r)}function y(r,l){return r.trim().startsWith("@media")?u(T(r,l)):b(r,l)}return function(r,l={}){return S(r,l)&&(Object.keys(l).length?y(r,l):u(r))}}function L({styleSheet:n,createWithId:i}){let f="Note: The rule or some of its properties may not be supported by your browser (yet)",s=`for style#${i}`;n=i?S(i):n;function S(u){let y=document.querySelector(`#${u}`)?.sheet;if(y)return y;let r=Object.assign(document.createElement("style"),{id:u});return document.head.insertAdjacentElement("beforeend",r),r.sheet}function $(u){return console.error(`StylingFactory ${s} [rule: ${u}]
2
+ => @charset, @namespace and @import are not supported here`),{done:!0}}function x(u,y){return[...n.rules].find(r=>y?_(r.selectorText||"",u):H`${z(u)}${[..."gim"]}`.test(r.cssText))}function O(u){return/^@charset|@import|namespace/i.test(u.trim())?$(u):u.match(/}/g)?.length>1?{existing:b(u,1),done:!0}:{done:!1}}function d(u){let y=[...n.cssRules].reduce((l,a,m)=>_(a.selectorText||"",u)&&l.concat(m)||l,[]),r=y.length;return y.forEach(l=>n.deleteRule(l)),r>0?console.info(`\u2714 Removed ${r} instance${r>1?"s":""} of selector ${u} from ${s.slice(4)}`):console.info(`\u2714 Remove rule: selector ${u} does not exist in ${s.slice(4)}`)}function P(u,y){return u&&N(u,String)&&u.trim().length>0&&N(y,Object)||(console.error(`StylingFactory ${s} called with invalid parameters`),!1)}function b(u){u=u.trim();let y=u.slice(0,u.indexOf("{")).trim(),r=!!x(y);try{return n.insertRule(`${u}`,n.cssRules.length),r}catch(l){return console.error(`StylingFactory ${s} (tryParse) ${l.name} Error:
3
+ ${l.message}
4
+ Rule: ${w(u)}
5
+ ${f}`),r}}function h(u,y,r){try{return u(),r}catch(l){return console.error(`StylingFactory ${s} (tryAddOrModify) ${l.name} Error:
6
+ ${l.message}
7
+ Rule: ${w(y)}
8
+ ${f}`),r}}return{sheet:n,removeRules:d,tryParseAtOrNestedRules:O,ruleExists:x,checkParams:P,tryParse:b,consider:h,currentSheetID:s}}function T(n,i){return`${n.trim()} ${Object.entries(i).map(([f,s])=>`${f}: { ${q(s)}`)}`}function w(n){let i=(n||"NO RULE").trim().slice(0,50).replace(/\n/g,"\\n").replace(/\s{2,}/g," ");return n.length>i.length?`${i.trim()}...truncated`:i}function q(n){return Object.entries(n).map(([i,f])=>`${i}: ${f.trim()}`).join(`;
9
+ `)}function z(n){return n.replace(/([*\[\]()-+{}.$?\\])/g,i=>`\\${i}`)}function H(n,...i){let f=i.length&&Array.isArray(i.slice(-1))?i.pop().join(""):"";return new RegExp((i.length&&n.raw.reduce((s,S,$)=>s.concat(i[$-1]||"").concat(S),"")||n.raw.join("")).split(`
10
+ `).map(s=>s.replace(/\s|\/\/.*$/g,"").trim().replace(/(@s!)/g," ")).join(""),f)}function I(n){return n.replace(/[A-Z]/g,i=>`-${i.toLowerCase()}`).replace(/[^--]^-|-$/,"")}function v(n,i){try{return n()}catch(f){console.error(`${i||"an error occured"}: ${f.message}`)}}function U(n){return n.replace(/\/\*.+?\*\//gm,"").replace(/[}{\r\n]/g,"").replace(/(data:.+?);/g,(i,f)=>`${f}\\3b`).split(";").map(i=>i.trim()).join(`;
11
+ `).replaceAll("\\3b",";").split(`
12
+ `)}function Z(n){return n.reduce((i,f)=>{let[s,S]=[f.slice(0,f.indexOf(":")).trim(),f.slice(f.indexOf(":")+1).trim().replace(/;$|;.+(?=\/*).+\/$/,"")];return s&&S?{...i,[s]:S}:i},{})}function G(n){return Z(U(n))}function _(n,i){return n?.replace("::",":")===i?.replace("::",":")}export{M as default};
@@ -0,0 +1,198 @@
1
+ const { IS, maybe, $Wrap, xProxy, isNothing } = TOAFactory();
2
+ export { IS as default, maybe, $Wrap, xProxy, isNothing };
3
+
4
+ function TOAFactory() {
5
+ Symbol.proxy = Symbol.for(`toa.proxy`);
6
+ Symbol.is = Symbol.for(`toa.is`);
7
+ Symbol.type = Symbol.for(`toa.type`);
8
+ Symbol.isSymbol = Symbol.for(`toa.isASymbol`);
9
+ addSymbols2Anything();
10
+ const maybe = maybeFactory();
11
+ const [$Wrap, xProxy] = [WrapAnyFactory(), setProxyFactory()];
12
+ xProxy.custom();
13
+ return {IS, maybe, $Wrap, isNothing, xProxy};
14
+
15
+ function IS(anything, ...shouldBe) {
16
+ if (maybe({trial: _ => `isTypes` in (shouldBe?.[0] ?? {})})) {
17
+ const isTypeObj = shouldBe[0];
18
+ return `defaultValue` in (isTypeObj)
19
+ ? isOrDefault(anything, isTypeObj) : `notTypes` in isTypeObj
20
+ ? isExcept(anything, isTypeObj) : IS(anything, ...[isTypeObj.isTypes].flat());
21
+ }
22
+
23
+ const input = typeof anything === `symbol` ? Symbol.isSymbol : anything;
24
+ return shouldBe.length > 1 ? ISOneOf(input, ...shouldBe) : determineType(anything, ...shouldBe);
25
+ }
26
+
27
+ function typeOf(anything) {
28
+ return anything?.[Symbol.proxy] ?? IS(anything);
29
+ }
30
+
31
+ function determineType(input, ...shouldBe) {
32
+ let {
33
+ noInput,
34
+ noShouldbe,
35
+ compareTo,
36
+ inputCTOR,
37
+ isNaN,
38
+ isInfinity,
39
+ shouldBeFirstElementIsNothing
40
+ } = processInput(input, ...shouldBe);
41
+ shouldBe = shouldBe.length && shouldBe[0];
42
+
43
+ switch (true) {
44
+ case shouldBeFirstElementIsNothing:
45
+ return String(input) === String(compareTo);
46
+ case input?.[Symbol.proxy] && noShouldbe:
47
+ return input[Symbol.proxy];
48
+ case isNaN:
49
+ return noShouldbe ? `NaN` : maybe({trial: _ => String(compareTo)}) === String(input);
50
+ case isInfinity:
51
+ return noShouldbe ? `Infinity` : maybe({trial: _ => String(compareTo)}) === String(input);
52
+ case noInput:
53
+ return noShouldbe ? String(input) : String(compareTo) === String(input);
54
+ case inputCTOR === Boolean:
55
+ return !shouldBe ? `Boolean` : inputCTOR === shouldBe;
56
+ default:
57
+ return getResult(input, shouldBe, noShouldbe, getMe(input, inputCTOR));
58
+ }
59
+ }
60
+
61
+ function getMe(input, inputCTOR) {
62
+ return input === 0 ? Number : input === `` ? String : !input ? {name: String(input)} : inputCTOR;
63
+ }
64
+
65
+ function processInput(input, ...shouldBe) {
66
+ const noShouldbe = shouldBe.length < 1;
67
+ const compareTo = !noShouldbe && shouldBe[0];
68
+ const shouldBeFirstElementIsNothing = !noShouldbe && isNothing(shouldBe[0]);
69
+ const noInput = input === undefined || input === null;
70
+ const inputCTOR = !noInput && Object.getPrototypeOf(input)?.constructor;
71
+ const isNaN = maybe({trial: _ => String(input)}) === `NaN`;
72
+ const isInfinity = maybe({trial: _ => String(input)}) === `Infinity`;
73
+ return {noInput, noShouldbe, compareTo, inputCTOR, isNaN, isInfinity, shouldBeFirstElementIsNothing};
74
+ }
75
+
76
+ function getResult(input, compareWith, noShouldbe, me) {
77
+ switch(true) {
78
+ case (!noShouldbe && compareWith === input) ||
79
+ (input?.[Symbol.proxy] && compareWith === Proxy):
80
+ return true;
81
+ case maybe({trial: _ => String(compareWith)}) === `NaN`:
82
+ return String(input) === `NaN`;
83
+ case input?.[Symbol.toStringTag] && IS(compareWith, String):
84
+ return String(compareWith) === input[Symbol.toStringTag];
85
+ default:
86
+ return compareWith
87
+ ? maybe({trial: _ => input instanceof compareWith,}) ||
88
+ compareWith === me || compareWith === Object.getPrototypeOf(me) ||
89
+ `${compareWith?.name}` === me?.name
90
+ : input?.[Symbol.toStringTag] && `[object ${input?.[Symbol.toStringTag]}]` ||
91
+ me?.name ||
92
+ String(me);
93
+ }
94
+ }
95
+
96
+ function ISOneOf(obj, ...params) {
97
+ return params.some(param => IS(obj, param));
98
+ }
99
+
100
+ function isNothing(maybeNothing, all = false) {
101
+ let nada = maybeNothing === null || maybeNothing === undefined;
102
+ nada = all ? nada || IS(maybeNothing, Infinity) || IS(maybeNothing, NaN) : nada;
103
+ return nada;
104
+ }
105
+
106
+ function maybeFactory() {
107
+ const tryFn = (maybeFn, maybeError) => maybeFn?.constructor === Function ? maybeFn(maybeError) : undefined;
108
+ return function ({trial, whenError = () => undefined} = {}) {
109
+ try {
110
+ return tryFn(trial)
111
+ } catch (err) {
112
+ return tryFn(whenError, err)
113
+ }
114
+ };
115
+ }
116
+
117
+ function WrapAnyFactory() {
118
+ return function (someObj) {
119
+ return Object.freeze({
120
+ get value() { return someObj; },
121
+ get [Symbol.type]() { return typeOf(someObj); },
122
+ get type() { return typeOf(someObj); },
123
+ [Symbol.is](...args) { return IS(someObj, ...args); },
124
+ is(...args) { return IS(someObj, ...args); }
125
+ });
126
+ }
127
+ }
128
+
129
+ function isOrDefault(input, {defaultValue, isTypes = [undefined], notTypes} = {}) {
130
+ isTypes = isTypes?.constructor !== Array ? [isTypes] : isTypes;
131
+ notTypes = notTypes && notTypes?.constructor !== Array ? [notTypes] : [];
132
+ return notTypes.length < 1
133
+ ? IS(input, ...isTypes) ? input : defaultValue
134
+ : isExcept(input, {isTypes, notTypes}) ? input : defaultValue;
135
+ }
136
+
137
+ function isExcept(input, {isTypes = [undefined], notTypes = [undefined]} = {}) {
138
+ isTypes = isTypes?.constructor !== Array ? [isTypes] : isTypes;
139
+ notTypes = notTypes?.constructor !== Array ? [notTypes] : notTypes;
140
+ return IS(input, ...isTypes) && !IS(input, ...notTypes);
141
+ }
142
+
143
+ function addSymbols2Anything() {
144
+ if (!Object.getOwnPropertyDescriptors(Object.prototype)[Symbol.is]) {
145
+ Object.defineProperties(Object.prototype, {
146
+ [Symbol.type]: { get() { return typeOf(this); }, enumerable: false, configurable: false },
147
+ [Symbol.is]: { value: function (...args) { return IS(this, ...args); }, enumerable: false, configurable: false },
148
+ });
149
+ Object.defineProperties(Object, {
150
+ [Symbol.type]: { value(obj) { return typeOf(obj); }, enumerable: false, configurable: false },
151
+ [Symbol.is]: { value: function (obj, ...args) { return IS(obj, ...args); }, enumerable: false, configurable: false },
152
+ });
153
+ }
154
+ }
155
+
156
+ function ctor2String(obj) {
157
+ const str = String(Object.getPrototypeOf(obj)?.constructor);
158
+ return str.slice(str.indexOf(`ion`) + 3, str.indexOf(`(`)).trim();
159
+ }
160
+
161
+ function modifySetter(setterMethod2Modify) {
162
+ const oldSetter = setterMethod2Modify.set;
163
+ setterMethod2Modify.set = (target, key, value) => {
164
+ if (key === Symbol.proxy) {
165
+ return target[key] = value;
166
+ }
167
+
168
+ return oldSetter(target, key, value);
169
+ }
170
+
171
+ return setterMethod2Modify;
172
+ }
173
+
174
+ function setProxyFactory() {
175
+ const nativeProxy = Proxy;
176
+ return {
177
+ native() {
178
+ Proxy = nativeProxy;
179
+ },
180
+ custom() {
181
+ // adaptation of https://stackoverflow.com/a/53463589
182
+ Proxy = new nativeProxy(nativeProxy, {
183
+ construct(target, args) {
184
+ for (let item of args) {
185
+ if (item.set) {
186
+ item = modifySetter(item);
187
+ }
188
+ }
189
+
190
+ const wrappedProxy = new target(...args);
191
+ wrappedProxy[Symbol.proxy] = `Proxy (${ctor2String(args[0])})`;
192
+ return wrappedProxy;
193
+ }
194
+ })
195
+ }
196
+ }
197
+ }
198
+ }
package/src/Utilities.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import jqx from "../index.js";
2
2
  import {default as tagFNFactory} from "./tinyDOM.js";
3
- import { IS, maybe, LifeStyleFactory as styleFactory } from "./SyncedExternals.js";
3
+ import {default as IS, maybe} from "./TypeofAnything.js";
4
+ import styleFactory from "./LifeCSS.js";
4
5
  const characters4RandomString = [...Array(26)]
5
6
  .map((x, i) => String.fromCharCode(i + 65))
6
7
  .concat([...Array(26)].map((x, i) => String.fromCharCode(i + 97)))
@@ -68,17 +69,17 @@ function ExamineElementFeatureFactory() {
68
69
  return elem.parentNode
69
70
  ? !!jqx.nodes(`:is(:read-write)`, elem?.parentNode)?.find(el => el === elem) : false;
70
71
  };
71
-
72
+
72
73
  const isModal = function(elem) {
73
74
  return elem.parentNode
74
75
  ? !!jqx.nodes(`:is(:modal)`, elem?.parentNode)?.find(el => el === elem) : false;
75
76
  };
76
-
77
+
77
78
  const noElements = { notInDOM: true, writable: notApplicable, modal: notApplicable, empty: true, open: notApplicable, visible: notApplicable, };
78
79
 
79
80
  return self => {
80
81
  const firstElem = self.node;
81
-
82
+
82
83
  return firstElem ? {
83
84
  get writable() {
84
85
  return isWritable(firstElem);
package/build.js DELETED
@@ -1,17 +0,0 @@
1
- import builder from 'esbuild';
2
- import process from 'node:process';
3
- const log = console.log.bind(console);
4
- const esContext = {
5
- entryPoints: ['./index.js'],
6
- bundle: true,
7
- outfile: './Bundle/jql.min.js',
8
- treeShaking: true,
9
- sourcemap: false, // don't need it
10
- minify: true,
11
- format: 'esm',
12
- target: ['esnext'],
13
- };
14
-
15
- const ctx = await builder.context(esContext);
16
- await ctx.rebuild().then(r => ctx.dispose());
17
- process.exit();