@skeletonizer/utils 0.0.16-alpha.0 → 0.0.20-alpha.0
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/dist/src/components/skeleton.abstract.component.d.ts +1 -2
- package/dist/src/components/skeleton.adapter.component.d.ts +1 -2
- package/dist/src/directives/skeleton.directive.d.ts +0 -1
- package/dist/src/models/schema.model.d.ts +2 -2
- package/dist/src/models/schema.model.d.ts.map +1 -1
- package/dist/src/types/schema.types.d.ts +0 -1
- package/dist/src/types/transformer.types.d.ts +0 -1
- package/dist/utils.mjs +28 -31
- package/dist/utils.umd.js +2 -2
- package/package.json +5 -5
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { TSchemaConfig } from '../types';
|
|
2
1
|
import { Schema } from '../models';
|
|
3
|
-
|
|
2
|
+
import { TSchemaConfig } from '../types';
|
|
4
3
|
export declare abstract class SkeletonAbstractComponent<T extends object> {
|
|
5
4
|
abstract skeletonConfig: TSchemaConfig<T>;
|
|
6
5
|
abstract showSkeleton: boolean;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TSchemaGenerator, TSchemaTransformer } from '../types';
|
|
2
|
-
|
|
3
2
|
export declare class Schema<T extends object> {
|
|
4
3
|
readonly generator: TSchemaGenerator<T>;
|
|
5
|
-
|
|
4
|
+
readonly uuid: number;
|
|
5
|
+
readonly viewModel: TSchemaTransformer<T>;
|
|
6
6
|
get value(): T;
|
|
7
7
|
private readonly val;
|
|
8
8
|
constructor(generator: TSchemaGenerator<T>);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.model.d.ts","sourceRoot":"","sources":["../../../src/models/schema.model.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.model.d.ts","sourceRoot":"","sources":["../../../src/models/schema.model.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAIhE,qBAAa,MAAM,CAAC,CAAC,SAAS,MAAM;aAWhB,SAAS,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAVhD,SAAgB,IAAI,EAAE,MAAM,CAAe;IAC3C,SAAgB,SAAS,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC;IAEjD,IAAW,KAAK,IAAI,CAAC,CAEpB;IAED,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAI;gBAGN,SAAS,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAMhD,OAAO,CAAC,MAAM,CAAC,YAAY;CAiB5B"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { SchemaItem } from '../models';
|
|
2
|
-
|
|
3
2
|
export type TSchemaTransformer<T> = T extends Array<infer Element> ? Array<TSchemaTransformer<Element>> : T extends Date ? SchemaItem<Date> : T extends boolean ? SchemaItem<boolean> : T extends object ? {
|
|
4
3
|
[K in keyof T]: TSchemaTransformer<T[K]>;
|
|
5
4
|
} : SchemaItem<T>;
|
package/dist/utils.mjs
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
var b = (s
|
|
2
|
-
|
|
3
|
-
throw TypeError("Cannot " + t);
|
|
1
|
+
var b = (s) => {
|
|
2
|
+
throw TypeError(s);
|
|
4
3
|
};
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
e instanceof WeakSet ? e.add(s) : e.set(s, t);
|
|
9
|
-
}, u = (s, e, t, i) => (b(s, e, "write to private field"), i ? i.call(s, t) : e.set(s, t), t);
|
|
10
|
-
const q = [
|
|
4
|
+
var f = (s, e, t) => e.has(s) || b("Cannot " + t);
|
|
5
|
+
var h = (s, e, t) => (f(s, e, "read from private field"), t ? t.call(s) : e.get(s)), q = (s, e, t) => e.has(s) ? b("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(s) : e.set(s, t), u = (s, e, t, i) => (f(s, e, "write to private field"), i ? i.call(s, t) : e.set(s, t), t);
|
|
6
|
+
const y = [
|
|
11
7
|
"Lorem",
|
|
12
8
|
"ipsum",
|
|
13
9
|
"dolor",
|
|
@@ -503,7 +499,7 @@ const q = [
|
|
|
503
499
|
"dolor."
|
|
504
500
|
];
|
|
505
501
|
var l = /* @__PURE__ */ ((s) => (s.Text = "text", s.Input = "input", s.Image = "image", s.Video = "video", s.WrapperElement = "wrapper-element", s))(l || {}), v = /* @__PURE__ */ ((s) => (s.PrimaryColor = "rgba(100, 100, 100, .6)", s.SecondaryColor = "rgba(100, 100, 100, .3)", s))(v || {});
|
|
506
|
-
class
|
|
502
|
+
class g {
|
|
507
503
|
static daysInMs(e) {
|
|
508
504
|
return e * 24 * 60 * 60 * 1e3;
|
|
509
505
|
}
|
|
@@ -511,14 +507,14 @@ class h {
|
|
|
511
507
|
return new Date(e.getTime() + Math.random() * (t.getTime() - e.getTime()));
|
|
512
508
|
}
|
|
513
509
|
}
|
|
514
|
-
let
|
|
510
|
+
let M = 0;
|
|
515
511
|
var r;
|
|
516
|
-
class
|
|
512
|
+
class x {
|
|
517
513
|
constructor() {
|
|
518
|
-
|
|
514
|
+
q(this, r);
|
|
519
515
|
}
|
|
520
516
|
get value() {
|
|
521
|
-
return
|
|
517
|
+
return h(this, r);
|
|
522
518
|
}
|
|
523
519
|
words(e) {
|
|
524
520
|
this.assertType();
|
|
@@ -542,15 +538,15 @@ class w {
|
|
|
542
538
|
return this.assertType(), u(this, r, Math.ceil(Math.random() * (t - e)) + e), this;
|
|
543
539
|
}
|
|
544
540
|
multiply(e) {
|
|
545
|
-
return this.assertType(), u(this, r,
|
|
541
|
+
return this.assertType(), u(this, r, h(this, r) * e), this;
|
|
546
542
|
}
|
|
547
543
|
date(e = {}) {
|
|
548
544
|
this.assertType();
|
|
549
545
|
let t = e.max ?? /* @__PURE__ */ new Date("2100-01-01"), i = e.min ?? /* @__PURE__ */ new Date("1970-01-01");
|
|
550
|
-
return e.isFuture ? i = new Date(Date.now() +
|
|
546
|
+
return e.isFuture ? i = new Date(Date.now() + g.daysInMs(1)) : e.isPast && (t = new Date(Date.now() - g.daysInMs(1))), u(this, r, g.dateBetween(i, t)), this;
|
|
551
547
|
}
|
|
552
548
|
uuid() {
|
|
553
|
-
return
|
|
549
|
+
return M++, this.assertType(), u(this, r, M), this;
|
|
554
550
|
}
|
|
555
551
|
boolean() {
|
|
556
552
|
return this.assertType(), u(this, r, Math.random() <= 0.5), this;
|
|
@@ -564,20 +560,21 @@ class w {
|
|
|
564
560
|
assertType() {
|
|
565
561
|
}
|
|
566
562
|
randomLoremWord() {
|
|
567
|
-
const e = Math.floor(Math.random() *
|
|
568
|
-
return
|
|
563
|
+
const e = Math.floor(Math.random() * y.length);
|
|
564
|
+
return y[e] ?? "lorem";
|
|
569
565
|
}
|
|
570
566
|
}
|
|
571
567
|
r = new WeakMap();
|
|
568
|
+
let I = 0;
|
|
572
569
|
class d {
|
|
573
570
|
constructor(e) {
|
|
574
|
-
this.generator = e, this.viewModel = this.generator(), this.val = d.modelToValue(this.viewModel);
|
|
571
|
+
this.generator = e, this.uuid = I++, this.viewModel = this.generator(), this.val = d.modelToValue(this.viewModel);
|
|
575
572
|
}
|
|
576
573
|
get value() {
|
|
577
574
|
return this.val;
|
|
578
575
|
}
|
|
579
576
|
static modelToValue(e) {
|
|
580
|
-
if (e instanceof
|
|
577
|
+
if (e instanceof x)
|
|
581
578
|
return e.value;
|
|
582
579
|
if (Array.isArray(e))
|
|
583
580
|
return e.map(this.modelToValue);
|
|
@@ -591,7 +588,7 @@ class d {
|
|
|
591
588
|
}
|
|
592
589
|
}
|
|
593
590
|
}
|
|
594
|
-
class
|
|
591
|
+
class P {
|
|
595
592
|
// when accessing skeletonized component properties / methods from within the view, they should be accessed via proxy method
|
|
596
593
|
// this is necessary to ensure:
|
|
597
594
|
// - that all properties / methods accessed from within skeletonized part of the view are a part of skeletonSchema
|
|
@@ -600,7 +597,7 @@ class I {
|
|
|
600
597
|
return e instanceof d ? e.value : e;
|
|
601
598
|
}
|
|
602
599
|
}
|
|
603
|
-
class
|
|
600
|
+
class D {
|
|
604
601
|
constructor() {
|
|
605
602
|
this.config = null, this.viewModels = [];
|
|
606
603
|
}
|
|
@@ -619,7 +616,7 @@ const n = class n {
|
|
|
619
616
|
"style",
|
|
620
617
|
`--skeletonizer-primary-color: ${i}; --skeletonizer-secondary-color: ${c};`
|
|
621
618
|
), Array.from(e.querySelectorAll("*:not(svg, [data-skeletonizer])")).forEach((o) => {
|
|
622
|
-
const
|
|
619
|
+
const A = [
|
|
623
620
|
"br",
|
|
624
621
|
"b",
|
|
625
622
|
"strong",
|
|
@@ -631,12 +628,12 @@ const n = class n {
|
|
|
631
628
|
"ins",
|
|
632
629
|
"sub",
|
|
633
630
|
"sup"
|
|
634
|
-
], p = Array.from(o.childNodes).map((a) => a.nodeName.toLowerCase()).filter((a) => !
|
|
631
|
+
], p = Array.from(o.childNodes).map((a) => a.nodeName.toLowerCase()).filter((a) => !A.includes(a)), w = p.length > 0 && p.some((a) => a !== p[0]);
|
|
635
632
|
o.childNodes.forEach((a) => {
|
|
636
633
|
switch (a.nodeName.toLowerCase()) {
|
|
637
634
|
case "#text": {
|
|
638
635
|
if (this.assertAs(a), a.wholeText.trim())
|
|
639
|
-
if (
|
|
636
|
+
if (w) {
|
|
640
637
|
const m = document.createElement("span");
|
|
641
638
|
m.innerText = a.cloneNode().wholeText, m.innerText.length && a.replaceWith(
|
|
642
639
|
n.skeletonizedSpanGenerator(m.innerText, l.Text)
|
|
@@ -671,11 +668,11 @@ const n = class n {
|
|
|
671
668
|
}
|
|
672
669
|
};
|
|
673
670
|
n.dataAttr = "data-skeletonizer";
|
|
674
|
-
let
|
|
671
|
+
let T = n;
|
|
675
672
|
export {
|
|
676
673
|
d as Schema,
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
674
|
+
x as SchemaItem,
|
|
675
|
+
P as SkeletonAbstractComponent,
|
|
676
|
+
D as SkeletonAdapterComponent,
|
|
677
|
+
T as SkeletonDirective
|
|
681
678
|
};
|
package/dist/utils.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
`),r++}return m(this,
|
|
1
|
+
(function(t,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(t=typeof globalThis<"u"?globalThis:t||self,s(t["@skeletonizer/utils"]={}))})(this,function(t){"use strict";var M=t=>{throw TypeError(t)};var A=(t,s,a)=>s.has(t)||M("Cannot "+a);var y=(t,s,a)=>(A(t,s,"read from private field"),a?a.call(t):s.get(t)),w=(t,s,a)=>s.has(t)?M("Cannot add the same private member more than once"):s instanceof WeakSet?s.add(t):s.set(t,a),m=(t,s,a,d)=>(A(t,s,"write to private field"),d?d.call(t,a):s.set(t,a),a);var l;const s=["Lorem","ipsum","dolor","sit","amet,","consectetur","adipiscing","elit.","Mauris","posuere","tincidunt","purus,","id","laoreet","mauris","cursus","nec.","Quisque","id","ante","id","tellus","aliquam","pulvinar","eget","eu","dolor.","Donec","egestas","dapibus","massa,","vel","finibus","lectus","congue","eu.","Morbi","quis","erat","condimentum,","molestie","ex","a,","sollicitudin","metus.","Vestibulum","orci","metus,","sagittis","a","sagittis","a,","varius","id","diam.","Cras","egestas","eros","vestibulum,","tempus","ipsum","pellentesque,","dictum","justo.","Quisque","sed","justo","metus.","Suspendisse","id","felis","vitae","nunc","auctor","tristique","eu","sit","amet","mi.","Ut","luctus","posuere","viverra.","Nunc","sed","augue","a","velit","sodales","iaculis.","Sed","at","arcu","non","massa","hendrerit","scelerisque.","Nunc","commodo","vulputate","vestibulum.","Duis","ut","leo","nisi.","Mauris","dignissim","quis","sem","non","blandit.","Suspendisse","id","elit","eget","leo","efficitur","maximus.","Ut","eu","auctor","ligula.","Nulla","in","leo","luctus,","tempor","justo","vitae,","condimentum","massa.","Quisque","venenatis","elementum","posuere.","Sed","bibendum","bibendum","enim,","in","faucibus","ante.","Aliquam","pretium","sapien","ac","eleifend","suscipit.","Duis","lacinia","justo","quis","diam","elementum,","vitae","fringilla","lectus","faucibus.","Integer","dictum","commodo","diam","a","tempus.","Aenean","elementum","egestas","quam,","eget","feugiat","ligula","imperdiet","vitae.","Morbi","mattis","dui","sed","elementum","mollis.","In","interdum","viverra","urna,","at","scelerisque","sapien.","Sed","molestie","blandit","risus","nec","ornare.","Integer","pharetra","massa","purus,","ut","fringilla","augue","sollicitudin","in.","Pellentesque","eu","leo","pharetra,","hendrerit","lectus","id,","dapibus","ipsum.","Quisque","tincidunt","euismod","venenatis.","Sed","lacus","ex,","pulvinar","at","dui","vitae,","condimentum","rutrum","eros.","Nunc","viverra","cursus","ante,","ac","dapibus","ligula","volutpat","nec.","Integer","commodo","in","tortor","eget","aliquet.","Nam","bibendum","lectus","vitae","ligula","interdum","scelerisque.","Morbi","sit","amet","augue","diam.","Etiam","purus","lorem,","sodales","sed","sodales","ac,","dignissim","a","tellus.","Nunc","vehicula","nibh","in","erat","rhoncus","ullamcorper.","Orci","varius","natoque","penatibus","et","magnis","dis","parturient","montes,","nascetur","ridiculus","mus.","Aliquam","augue","nunc,","fringilla","at","dictum","quis,","luctus","sit","amet","nisl.","Nam","lectus","felis,","egestas","nec","lacinia","non,","auctor","eget","lorem.","Nunc","vel","velit","quis","magna","hendrerit","volutpat","in","nec","leo.","Aenean","tempor","lectus","tortor,","nec","bibendum","elit","aliquam","at.","In","id","libero","tincidunt,","interdum","libero","sit","amet,","gravida","est.","Morbi","ut","ipsum","enim.","Duis","vel","posuere","ante.","Praesent","sollicitudin","lacus","sit","amet","luctus","euismod.","Phasellus","lorem","elit,","auctor","sed","risus","a,","faucibus","tempor","lacus.","Integer","id","tellus","ut","eros","congue","ornare.","Cras","vitae","ornare","sem.","Cras","tincidunt","arcu","efficitur","mauris","molestie,","eu","eleifend","eros","mattis.","Integer","id","diam","mauris.","Duis","suscipit","enim","risus,","non","dignissim","nulla","imperdiet","hendrerit.","Vestibulum","sed","dignissim","erat.","Aliquam","erat","volutpat.","Nunc","mattis","auctor","justo,","non","fringilla","dolor","blandit","a.","Donec","et","velit","tristique","lacus","varius","aliquam.","Praesent","ac","molestie","quam,","vitae","scelerisque","tellus.","Praesent","eleifend","sed","diam","in","gravida.","Donec","tristique","sapien","ante,","in","egestas","diam","porta","ac.","Proin","ac","justo","eleifend,","consequat","ante","vitae,","laoreet","augue.","Mauris","scelerisque","arcu","dolor,","quis","lobortis","risus","pellentesque","eu.","Praesent","in","enim","a","elit","feugiat","dapibus.","Duis","quis","bibendum","mi.","Vestibulum","lacinia,","sem","at","efficitur","volutpat,","velit","ligula","vulputate","nisi,","sit","amet","dapibus","risus","metus","sed","est.","Sed","in","venenatis","ante.","Pellentesque","vel","ipsum","pharetra,","efficitur","quam","ut,","hendrerit","dolor."];var a=(u=>(u.Text="text",u.Input="input",u.Image="image",u.Video="video",u.WrapperElement="wrapper-element",u))(a||{}),d=(u=>(u.PrimaryColor="rgba(100, 100, 100, .6)",u.SecondaryColor="rgba(100, 100, 100, .3)",u))(d||{});class b{static daysInMs(e){return e*24*60*60*1e3}static dateBetween(e,i){return new Date(e.getTime()+Math.random()*(i.getTime()-e.getTime()))}}let q=0;class T{constructor(){w(this,l)}get value(){return y(this,l)}words(e){this.assertType();let i="",r=0;for(;r<e;)i+=this.randomLoremWord()+" ",r++;return m(this,l,i.trim()),this}paragraphs(e){this.assertType();let i="",r=0;const g=50;for(;r<e;){const p=g-Math.round(g*Math.random()*.2)*(Math.random()<.5?-1:1);i+=this.words(p).value,r!==e-1&&(i+=`
|
|
2
|
+
`),r++}return m(this,l,i),this}number(e=0,i=1e3){return this.assertType(),m(this,l,Math.ceil(Math.random()*(i-e))+e),this}multiply(e){return this.assertType(),m(this,l,y(this,l)*e),this}date(e={}){this.assertType();let i=e.max??new Date("2100-01-01"),r=e.min??new Date("1970-01-01");return e.isFuture?r=new Date(Date.now()+b.daysInMs(1)):e.isPast&&(i=new Date(Date.now()-b.daysInMs(1))),m(this,l,b.dateBetween(r,i)),this}uuid(){return q++,this.assertType(),m(this,l,q),this}boolean(){return this.assertType(),m(this,l,Math.random()<=.5),this}symbol(e=0){return this.assertType(),m(this,l,Symbol(e)),this}identical(e){return this.assertType(),m(this,l,e),this}assertType(){}randomLoremWord(){const e=Math.floor(Math.random()*s.length);return s[e]??"lorem"}}l=new WeakMap;let I=0;class c{constructor(e){this.generator=e,this.uuid=I++,this.viewModel=this.generator(),this.val=c.modelToValue(this.viewModel)}get value(){return this.val}static modelToValue(e){if(e instanceof T)return e.value;if(Array.isArray(e))return e.map(this.modelToValue);{const i={};return Object.keys(e).forEach(r=>{i[r]=c.modelToValue(e[r])}),i}}}class x{proxy(e){return e instanceof c?e.value:e}}class C{constructor(){this.config=null,this.viewModels=[]}setupModels(){if(this.config){const e=this.config.schemaGenerator;this.viewModels=Array.from({length:this.config.repeat},()=>new c(e))}}}const o=class o{static skeletonizeProjectedTemplate(e,i){const r=(i==null?void 0:i.primaryColor)??d.PrimaryColor,g=(i==null?void 0:i.secondaryColor)??d.SecondaryColor;e.setAttribute("style",`--skeletonizer-primary-color: ${r}; --skeletonizer-secondary-color: ${g};`),Array.from(e.querySelectorAll("*:not(svg, [data-skeletonizer])")).forEach(p=>{const P=["br","b","strong","i","em","mark","small","del","ins","sub","sup"],f=Array.from(p.childNodes).map(n=>n.nodeName.toLowerCase()).filter(n=>!P.includes(n)),k=f.length>0&&f.some(n=>n!==f[0]);p.childNodes.forEach(n=>{switch(n.nodeName.toLowerCase()){case"#text":{if(this.assertAs(n),n.wholeText.trim())if(k){const h=document.createElement("span");h.innerText=n.cloneNode().wholeText,h.innerText.length&&n.replaceWith(o.skeletonizedSpanGenerator(h.innerText,a.Text))}else{const h=o.skeletonizedSpanGenerator(p.innerHTML,a.Text);p.innerHTML=h.outerHTML}break}case"input":{n.setAttribute(o.dataAttr,a.Input);break}case"img":{n.setAttribute(o.dataAttr,a.Image);break}case"video":{n.setAttribute(o.dataAttr,a.Video);break}}})}),e.setAttribute(o.dataAttr,a.WrapperElement)}static skeletonizedSpanGenerator(e,i){const r=document.createElement("span");return r.innerHTML=e,r.setAttribute(o.dataAttr,i),r}static assertAs(e){}};o.dataAttr="data-skeletonizer";let v=o;t.Schema=c,t.SchemaItem=T,t.SkeletonAbstractComponent=x,t.SkeletonAdapterComponent=C,t.SkeletonDirective=v,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skeletonizer/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20-alpha.0",
|
|
4
4
|
"description": "Utils for all skeletonizer packages",
|
|
5
5
|
"author": "Luka Varga",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"**/*.{ts,js}": "eslint --fix"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@vitest/coverage-istanbul": "1.
|
|
52
|
+
"@vitest/coverage-istanbul": "2.1.2",
|
|
53
53
|
"sass": "^1.72.0",
|
|
54
|
-
"vite-plugin-dts": "^
|
|
55
|
-
"vitest": "1.
|
|
54
|
+
"vite-plugin-dts": "^4.2.3",
|
|
55
|
+
"vitest": "2.1.2"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "8c8651dfea6a80f5b85e17ff097e6e23024cc7ac"
|
|
58
58
|
}
|