@skeletonizer/utils 1.1.1 → 1.2.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/README.md
CHANGED
|
@@ -50,6 +50,10 @@ This can be used eg. for simulating descriptions, articles, etc.
|
|
|
50
50
|
Generates a random number between the `min` and `max` parameters.
|
|
51
51
|
This can be used eg. for simulating prices, available quantities, etc.
|
|
52
52
|
|
|
53
|
+
### `currency(config: { locale: string; currency: string; options?: Omit<Intl.NumberFormatOptions, 'style' | 'currency'> })`
|
|
54
|
+
Turns the string or number value of the `SchemaItem` instance into a currency string of the provided locale and currency.
|
|
55
|
+
This can be used in combination with the `number` method to simulate prices in different currencies - eg. `new SchemaItem().number(10, 100).currency({ locale: 'en-US', currency: 'USD' })`.
|
|
56
|
+
|
|
53
57
|
### `multiply(multiplier: number)`
|
|
54
58
|
Multiplies the current value of the `SchemaItem` instance by the `multiplier` parameter.
|
|
55
59
|
This can be used for chaining the `SchemaItem().foo()` methods if `foo` returns a number - ie `new SchemaItem().number(10, 100).multiply(5)`.
|
|
@@ -69,6 +73,17 @@ This can be used eg. for simulating whether a user is active, whether a product
|
|
|
69
73
|
### `symbol(val: string | number = 0)`
|
|
70
74
|
Creates a new unique symbol with the provided `val` as the description.
|
|
71
75
|
|
|
76
|
+
### `randomItem(items: R[])`
|
|
77
|
+
Sets the current value of the `SchemaItem` instance to a random item provided in the `items` parameter.
|
|
78
|
+
|
|
79
|
+
### `prefix(prefix: string)`
|
|
80
|
+
Adds a prefix to the current value of the `SchemaItem` instance.
|
|
81
|
+
This can be used eg. to simulate currency when chaining with the `number` method - ie. `new SchemaItem().number(10, 100).prefix('$')`.
|
|
82
|
+
|
|
83
|
+
### `suffix(suffix: string)`
|
|
84
|
+
Adds a suffix to the current value of the `SchemaItem` instance.
|
|
85
|
+
This can be used eg. to simulate percentages when chaining with the `number` method - ie. `new SchemaItem().number(10, 100).suffix('%')`.
|
|
86
|
+
|
|
72
87
|
### `identical(identity: R)`
|
|
73
88
|
Sets the current value of the `SchemaItem` instance to the `identity` parameter.
|
|
74
89
|
This can be used eg. for providing a specific (general) placeholder image that you want to use in the skeleton in place of eg. profile pictures, product images, etc.
|
|
@@ -5,6 +5,11 @@ export declare class SchemaItem<T = never> {
|
|
|
5
5
|
words(this: TSchemaInstance<string | undefined>, count: number): TSchemaInstance<string>;
|
|
6
6
|
paragraphs(this: TSchemaInstance<string | undefined>, count: number): TSchemaInstance<string>;
|
|
7
7
|
number(this: TSchemaInstance<number | undefined>, min?: number, max?: number): TSchemaInstance<number>;
|
|
8
|
+
currency(this: TSchemaInstance<number | string>, config: {
|
|
9
|
+
locale: string;
|
|
10
|
+
currency: string;
|
|
11
|
+
options?: Omit<Intl.NumberFormatOptions, 'style' | 'currency'>;
|
|
12
|
+
}): TSchemaInstance<string>;
|
|
8
13
|
multiply(this: TSchemaInstance<number>, multiplier: number): TSchemaInstance<number>;
|
|
9
14
|
date(this: TSchemaInstance<Date | undefined>, config?: Partial<{
|
|
10
15
|
isFuture: boolean;
|
|
@@ -15,6 +20,9 @@ export declare class SchemaItem<T = never> {
|
|
|
15
20
|
uuid(this: TSchemaInstance<number | undefined>): TSchemaInstance<number>;
|
|
16
21
|
boolean(this: TSchemaInstance<boolean | undefined>): TSchemaInstance<boolean>;
|
|
17
22
|
symbol(this: TSchemaInstance<symbol | undefined>, val?: string | number): TSchemaInstance<symbol>;
|
|
23
|
+
randomItem<R>(this: TSchemaInstance<R | undefined>, items: R[]): TSchemaInstance<R>;
|
|
24
|
+
prefix(this: TSchemaInstance<number | string>, prefix: string): TSchemaInstance<string>;
|
|
25
|
+
suffix(this: TSchemaInstance<number | string>, suffix: string): TSchemaInstance<string>;
|
|
18
26
|
identical<R>(this: TSchemaInstance<R | undefined>, identity: R): TSchemaInstance<R>;
|
|
19
27
|
private assertType;
|
|
20
28
|
private randomLoremWord;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-item.model.d.ts","s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Ae;CAKxB"}
|
package/dist/utils.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var
|
|
1
|
+
var v = (s) => {
|
|
2
2
|
throw TypeError(s);
|
|
3
3
|
};
|
|
4
|
-
var f = (s, e, t) => e.has(s) ||
|
|
5
|
-
var
|
|
6
|
-
const
|
|
4
|
+
var f = (s, e, t) => e.has(s) || v("Cannot " + t);
|
|
5
|
+
var m = (s, e, t) => (f(s, e, "read from private field"), t ? t.call(s) : e.get(s)), y = (s, e, t) => e.has(s) ? v("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 q = [
|
|
7
7
|
"Lorem",
|
|
8
8
|
"ipsum",
|
|
9
9
|
"dolor",
|
|
@@ -498,7 +498,7 @@ const y = [
|
|
|
498
498
|
"hendrerit",
|
|
499
499
|
"dolor."
|
|
500
500
|
];
|
|
501
|
-
var l = /* @__PURE__ */ ((s) => (s.Text = "text", s.Input = "input", s.Image = "image", s.Video = "video", s.WrapperElement = "wrapper-element", s))(l || {}),
|
|
501
|
+
var l = /* @__PURE__ */ ((s) => (s.Text = "text", s.Input = "input", s.Image = "image", s.Video = "video", s.WrapperElement = "wrapper-element", s))(l || {}), b = /* @__PURE__ */ ((s) => (s.PrimaryColor = "rgba(100, 100, 100, .6)", s.SecondaryColor = "rgba(100, 100, 100, .3)", s))(b || {});
|
|
502
502
|
class g {
|
|
503
503
|
static daysInMs(e) {
|
|
504
504
|
return e * 24 * 60 * 60 * 1e3;
|
|
@@ -507,68 +507,85 @@ class g {
|
|
|
507
507
|
return new Date(e.getTime() + Math.random() * (t.getTime() - e.getTime()));
|
|
508
508
|
}
|
|
509
509
|
}
|
|
510
|
-
let
|
|
511
|
-
var
|
|
510
|
+
let T = 0;
|
|
511
|
+
var a;
|
|
512
512
|
class x {
|
|
513
513
|
constructor() {
|
|
514
|
-
|
|
514
|
+
y(this, a);
|
|
515
515
|
}
|
|
516
516
|
get value() {
|
|
517
|
-
return
|
|
517
|
+
return m(this, a);
|
|
518
518
|
}
|
|
519
519
|
words(e) {
|
|
520
520
|
this.assertType();
|
|
521
521
|
let t = "", i = 0;
|
|
522
522
|
for (; i < e; )
|
|
523
523
|
t += this.randomLoremWord() + " ", i++;
|
|
524
|
-
return u(this,
|
|
524
|
+
return u(this, a, t.trim()), this;
|
|
525
525
|
}
|
|
526
526
|
paragraphs(e) {
|
|
527
527
|
this.assertType();
|
|
528
528
|
let t = "", i = 0;
|
|
529
|
-
const
|
|
529
|
+
const p = 50;
|
|
530
530
|
for (; i < e; ) {
|
|
531
|
-
const o =
|
|
531
|
+
const o = p - Math.round(p * Math.random() * 0.2) * (Math.random() < 0.5 ? -1 : 1);
|
|
532
532
|
t += this.words(o).value, i !== e - 1 && (t += `
|
|
533
533
|
`), i++;
|
|
534
534
|
}
|
|
535
|
-
return u(this,
|
|
535
|
+
return u(this, a, t), this;
|
|
536
536
|
}
|
|
537
537
|
number(e = 0, t = 1e3) {
|
|
538
|
-
return this.assertType(), u(this,
|
|
538
|
+
return this.assertType(), u(this, a, Math.ceil(Math.random() * (t - e)) + e), this;
|
|
539
|
+
}
|
|
540
|
+
currency(e) {
|
|
541
|
+
return this.assertType(), u(this, a, new Intl.NumberFormat(
|
|
542
|
+
e.locale,
|
|
543
|
+
{ ...e.options, style: "currency", currency: e.currency }
|
|
544
|
+
).format(+m(this, a))), this;
|
|
539
545
|
}
|
|
540
546
|
multiply(e) {
|
|
541
|
-
return this.assertType(), u(this,
|
|
547
|
+
return this.assertType(), u(this, a, m(this, a) * e), this;
|
|
542
548
|
}
|
|
543
549
|
date(e = {}) {
|
|
544
550
|
this.assertType();
|
|
545
551
|
let t = e.max ?? /* @__PURE__ */ new Date("2100-01-01"), i = e.min ?? /* @__PURE__ */ new Date("1970-01-01");
|
|
546
|
-
return e.isFuture ? i = new Date(Date.now() + g.daysInMs(1)) : e.isPast && (t = new Date(Date.now() - g.daysInMs(1))), u(this,
|
|
552
|
+
return e.isFuture ? i = new Date(Date.now() + g.daysInMs(1)) : e.isPast && (t = new Date(Date.now() - g.daysInMs(1))), u(this, a, g.dateBetween(i, t)), this;
|
|
547
553
|
}
|
|
548
554
|
uuid() {
|
|
549
|
-
return
|
|
555
|
+
return T++, this.assertType(), u(this, a, T), this;
|
|
550
556
|
}
|
|
551
557
|
boolean() {
|
|
552
|
-
return this.assertType(), u(this,
|
|
558
|
+
return this.assertType(), u(this, a, Math.random() <= 0.5), this;
|
|
553
559
|
}
|
|
554
560
|
symbol(e = 0) {
|
|
555
|
-
return this.assertType(), u(this,
|
|
561
|
+
return this.assertType(), u(this, a, Symbol(e)), this;
|
|
562
|
+
}
|
|
563
|
+
randomItem(e) {
|
|
564
|
+
this.assertType();
|
|
565
|
+
const t = Math.floor(Math.random() * e.length);
|
|
566
|
+
return u(this, a, e[t]), this;
|
|
567
|
+
}
|
|
568
|
+
prefix(e) {
|
|
569
|
+
return this.assertType(), u(this, a, `${e}${m(this, a)}`), this;
|
|
570
|
+
}
|
|
571
|
+
suffix(e) {
|
|
572
|
+
return this.assertType(), u(this, a, `${m(this, a)}${e}`), this;
|
|
556
573
|
}
|
|
557
574
|
identical(e) {
|
|
558
|
-
return this.assertType(), u(this,
|
|
575
|
+
return this.assertType(), u(this, a, e), this;
|
|
559
576
|
}
|
|
560
577
|
assertType() {
|
|
561
578
|
}
|
|
562
579
|
randomLoremWord() {
|
|
563
|
-
const e = Math.floor(Math.random() *
|
|
564
|
-
return
|
|
580
|
+
const e = Math.floor(Math.random() * q.length);
|
|
581
|
+
return q[e] ?? "lorem";
|
|
565
582
|
}
|
|
566
583
|
}
|
|
567
|
-
|
|
584
|
+
a = new WeakMap();
|
|
568
585
|
let I = 0;
|
|
569
|
-
class
|
|
586
|
+
class c {
|
|
570
587
|
constructor(e) {
|
|
571
|
-
this.generator = e, this.uuid = I++, this.viewModel = this.generator(), this.val =
|
|
588
|
+
this.generator = e, this.uuid = I++, this.viewModel = this.generator(), this.val = c.modelToValue(this.viewModel);
|
|
572
589
|
}
|
|
573
590
|
get value() {
|
|
574
591
|
return this.val;
|
|
@@ -581,7 +598,7 @@ class d {
|
|
|
581
598
|
{
|
|
582
599
|
const t = {};
|
|
583
600
|
return Object.keys(e).forEach((i) => {
|
|
584
|
-
t[i] =
|
|
601
|
+
t[i] = c.modelToValue(
|
|
585
602
|
e[i]
|
|
586
603
|
);
|
|
587
604
|
}), t;
|
|
@@ -594,10 +611,10 @@ class P {
|
|
|
594
611
|
// - that all properties / methods accessed from within skeletonized part of the view are a part of skeletonSchema
|
|
595
612
|
// - that typescript understands correct type of each property / method accessed from within the skeletonized part of the view
|
|
596
613
|
proxy(e) {
|
|
597
|
-
return e instanceof
|
|
614
|
+
return e instanceof c ? e.value : e;
|
|
598
615
|
}
|
|
599
616
|
}
|
|
600
|
-
class
|
|
617
|
+
class N {
|
|
601
618
|
constructor() {
|
|
602
619
|
this.config = null, this.viewModels = [];
|
|
603
620
|
}
|
|
@@ -605,18 +622,18 @@ class D {
|
|
|
605
622
|
setupModels() {
|
|
606
623
|
if (this.config) {
|
|
607
624
|
const e = this.config.schemaGenerator;
|
|
608
|
-
this.viewModels = Array.from({ length: this.config.repeat }, () => new
|
|
625
|
+
this.viewModels = Array.from({ length: this.config.repeat }, () => new c(e));
|
|
609
626
|
}
|
|
610
627
|
}
|
|
611
628
|
}
|
|
612
629
|
const n = class n {
|
|
613
630
|
static skeletonizeProjectedTemplate(e, t) {
|
|
614
|
-
const i = (t == null ? void 0 : t.primaryColor) ??
|
|
631
|
+
const i = (t == null ? void 0 : t.primaryColor) ?? b.PrimaryColor, p = (t == null ? void 0 : t.secondaryColor) ?? b.SecondaryColor;
|
|
615
632
|
e.setAttribute(
|
|
616
633
|
"style",
|
|
617
|
-
`--skeletonizer-primary-color: ${i}; --skeletonizer-secondary-color: ${
|
|
634
|
+
`--skeletonizer-primary-color: ${i}; --skeletonizer-secondary-color: ${p};`
|
|
618
635
|
), Array.from(e.querySelectorAll("*:not(svg, [data-skeletonizer])")).forEach((o) => {
|
|
619
|
-
const
|
|
636
|
+
const w = [
|
|
620
637
|
"br",
|
|
621
638
|
"b",
|
|
622
639
|
"strong",
|
|
@@ -628,32 +645,32 @@ const n = class n {
|
|
|
628
645
|
"ins",
|
|
629
646
|
"sub",
|
|
630
647
|
"sup"
|
|
631
|
-
],
|
|
632
|
-
o.childNodes.forEach((
|
|
633
|
-
switch (
|
|
648
|
+
], h = Array.from(o.childNodes).map((r) => r.nodeName.toLowerCase()).filter((r) => !w.includes(r)), A = h.length > 0 && h.some((r) => r !== h[0]);
|
|
649
|
+
o.childNodes.forEach((r) => {
|
|
650
|
+
switch (r.nodeName.toLowerCase()) {
|
|
634
651
|
case "#text": {
|
|
635
|
-
if (this.assertAs(
|
|
636
|
-
if (
|
|
637
|
-
const
|
|
638
|
-
|
|
639
|
-
n.skeletonizedSpanGenerator(
|
|
652
|
+
if (this.assertAs(r), r.wholeText.trim())
|
|
653
|
+
if (A) {
|
|
654
|
+
const d = document.createElement("span");
|
|
655
|
+
d.innerText = r.cloneNode().wholeText, d.innerText.length && r.replaceWith(
|
|
656
|
+
n.skeletonizedSpanGenerator(d.innerText, l.Text)
|
|
640
657
|
);
|
|
641
658
|
} else {
|
|
642
|
-
const
|
|
643
|
-
o.innerHTML =
|
|
659
|
+
const d = n.skeletonizedSpanGenerator(o.innerHTML, l.Text);
|
|
660
|
+
o.innerHTML = d.outerHTML;
|
|
644
661
|
}
|
|
645
662
|
break;
|
|
646
663
|
}
|
|
647
664
|
case "input": {
|
|
648
|
-
|
|
665
|
+
r.setAttribute(n.dataAttr, l.Input);
|
|
649
666
|
break;
|
|
650
667
|
}
|
|
651
668
|
case "img": {
|
|
652
|
-
|
|
669
|
+
r.setAttribute(n.dataAttr, l.Image);
|
|
653
670
|
break;
|
|
654
671
|
}
|
|
655
672
|
case "video": {
|
|
656
|
-
|
|
673
|
+
r.setAttribute(n.dataAttr, l.Video);
|
|
657
674
|
break;
|
|
658
675
|
}
|
|
659
676
|
}
|
|
@@ -668,11 +685,11 @@ const n = class n {
|
|
|
668
685
|
}
|
|
669
686
|
};
|
|
670
687
|
n.dataAttr = "data-skeletonizer";
|
|
671
|
-
let
|
|
688
|
+
let M = n;
|
|
672
689
|
export {
|
|
673
|
-
|
|
690
|
+
c as Schema,
|
|
674
691
|
x as SchemaItem,
|
|
675
692
|
P as SkeletonAbstractComponent,
|
|
676
|
-
|
|
677
|
-
|
|
693
|
+
N as SkeletonAdapterComponent,
|
|
694
|
+
M as SkeletonDirective
|
|
678
695
|
};
|
package/dist/utils.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
`),
|
|
1
|
+
(function(s,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(s=typeof globalThis<"u"?globalThis:s||self,a(s["@skeletonizer/utils"]={}))})(this,function(s){"use strict";var M=s=>{throw TypeError(s)};var A=(s,a,r)=>a.has(s)||M("Cannot "+r);var h=(s,a,r)=>(A(s,a,"read from private field"),r?r.call(s):a.get(s)),w=(s,a,r)=>a.has(s)?M("Cannot add the same private member more than once"):a instanceof WeakSet?a.add(s):a.set(s,r),l=(s,a,r,d)=>(A(s,a,"write to private field"),d?d.call(s,r):a.set(s,r),r);var i;const a=["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 r=(u=>(u.Text="text",u.Input="input",u.Image="image",u.Video="video",u.WrapperElement="wrapper-element",u))(r||{}),d=(u=>(u.PrimaryColor="rgba(100, 100, 100, .6)",u.SecondaryColor="rgba(100, 100, 100, .3)",u))(d||{});class v{static daysInMs(e){return e*24*60*60*1e3}static dateBetween(e,t){return new Date(e.getTime()+Math.random()*(t.getTime()-e.getTime()))}}let T=0;class q{constructor(){w(this,i)}get value(){return h(this,i)}words(e){this.assertType();let t="",n=0;for(;n<e;)t+=this.randomLoremWord()+" ",n++;return l(this,i,t.trim()),this}paragraphs(e){this.assertType();let t="",n=0;const b=50;for(;n<e;){const p=b-Math.round(b*Math.random()*.2)*(Math.random()<.5?-1:1);t+=this.words(p).value,n!==e-1&&(t+=`
|
|
2
|
+
`),n++}return l(this,i,t),this}number(e=0,t=1e3){return this.assertType(),l(this,i,Math.ceil(Math.random()*(t-e))+e),this}currency(e){return this.assertType(),l(this,i,new Intl.NumberFormat(e.locale,{...e.options,style:"currency",currency:e.currency}).format(+h(this,i))),this}multiply(e){return this.assertType(),l(this,i,h(this,i)*e),this}date(e={}){this.assertType();let t=e.max??new Date("2100-01-01"),n=e.min??new Date("1970-01-01");return e.isFuture?n=new Date(Date.now()+v.daysInMs(1)):e.isPast&&(t=new Date(Date.now()-v.daysInMs(1))),l(this,i,v.dateBetween(n,t)),this}uuid(){return T++,this.assertType(),l(this,i,T),this}boolean(){return this.assertType(),l(this,i,Math.random()<=.5),this}symbol(e=0){return this.assertType(),l(this,i,Symbol(e)),this}randomItem(e){this.assertType();const t=Math.floor(Math.random()*e.length);return l(this,i,e[t]),this}prefix(e){return this.assertType(),l(this,i,`${e}${h(this,i)}`),this}suffix(e){return this.assertType(),l(this,i,`${h(this,i)}${e}`),this}identical(e){return this.assertType(),l(this,i,e),this}assertType(){}randomLoremWord(){const e=Math.floor(Math.random()*a.length);return a[e]??"lorem"}}i=new WeakMap;let x=0;class c{constructor(e){this.generator=e,this.uuid=x++,this.viewModel=this.generator(),this.val=c.modelToValue(this.viewModel)}get value(){return this.val}static modelToValue(e){if(e instanceof q)return e.value;if(Array.isArray(e))return e.map(this.modelToValue);{const t={};return Object.keys(e).forEach(n=>{t[n]=c.modelToValue(e[n])}),t}}}class I{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 m=class m{static skeletonizeProjectedTemplate(e,t){const n=(t==null?void 0:t.primaryColor)??d.PrimaryColor,b=(t==null?void 0:t.secondaryColor)??d.SecondaryColor;e.setAttribute("style",`--skeletonizer-primary-color: ${n}; --skeletonizer-secondary-color: ${b};`),Array.from(e.querySelectorAll("*:not(svg, [data-skeletonizer])")).forEach(p=>{const P=["br","b","strong","i","em","mark","small","del","ins","sub","sup"],y=Array.from(p.childNodes).map(o=>o.nodeName.toLowerCase()).filter(o=>!P.includes(o)),k=y.length>0&&y.some(o=>o!==y[0]);p.childNodes.forEach(o=>{switch(o.nodeName.toLowerCase()){case"#text":{if(this.assertAs(o),o.wholeText.trim())if(k){const g=document.createElement("span");g.innerText=o.cloneNode().wholeText,g.innerText.length&&o.replaceWith(m.skeletonizedSpanGenerator(g.innerText,r.Text))}else{const g=m.skeletonizedSpanGenerator(p.innerHTML,r.Text);p.innerHTML=g.outerHTML}break}case"input":{o.setAttribute(m.dataAttr,r.Input);break}case"img":{o.setAttribute(m.dataAttr,r.Image);break}case"video":{o.setAttribute(m.dataAttr,r.Video);break}}})}),e.setAttribute(m.dataAttr,r.WrapperElement)}static skeletonizedSpanGenerator(e,t){const n=document.createElement("span");return n.innerHTML=e,n.setAttribute(m.dataAttr,t),n}static assertAs(e){}};m.dataAttr="data-skeletonizer";let f=m;s.Schema=c,s.SchemaItem=q,s.SkeletonAbstractComponent=I,s.SkeletonAdapterComponent=C,s.SkeletonDirective=f,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skeletonizer/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Utils for all skeletonizer packages",
|
|
5
5
|
"author": "Luka Varga",
|
|
6
6
|
"license": "MIT",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"vite-plugin-dts": "^4.3.0",
|
|
56
56
|
"vitest": "2.1.4"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "fd61bebc869a7867b27c5f757961eaaa889c0021"
|
|
59
59
|
}
|