@skeletonizer/utils 1.1.2 → 1.3.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
@@ -1,4 +1,8 @@
1
1
  # `@skeletonizer/utils`
2
+ [![codecov](https://codecov.io/github/lukaVarga/skeletonizer/graph/badge.svg?token=4YZYRB9UN7)](https://codecov.io/github/lukaVarga/skeletonizer?style=for-the-badge)
3
+ ![NPM Downloads](https://img.shields.io/npm/dy/%40skeletonizer%2Futils?style=for-the-badge&labelColor=%23444&color=%23090)
4
+
5
+
2
6
  This is the general utility package for the Skeletonizer project. It should be used together with every adapter (eg. Vue, Angular) package.
3
7
  Roughly speaking, the usage of skeleton in the template boils down to the following steps:
4
8
  - surrounding the content you want to skeletonize with the `skeletonizer-skeleton` component and passing it through via content projection
@@ -50,6 +54,10 @@ This can be used eg. for simulating descriptions, articles, etc.
50
54
  Generates a random number between the `min` and `max` parameters.
51
55
  This can be used eg. for simulating prices, available quantities, etc.
52
56
 
57
+ ### `currency(config: { locale: string; currency: string; options?: Omit<Intl.NumberFormatOptions, 'style' | 'currency'> })`
58
+ Turns the string or number value of the `SchemaItem` instance into a currency string of the provided locale and currency.
59
+ 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' })`.
60
+
53
61
  ### `multiply(multiplier: number)`
54
62
  Multiplies the current value of the `SchemaItem` instance by the `multiplier` parameter.
55
63
  This can be used for chaining the `SchemaItem().foo()` methods if `foo` returns a number - ie `new SchemaItem().number(10, 100).multiply(5)`.
@@ -58,6 +66,10 @@ This can be used for chaining the `SchemaItem().foo()` methods if `foo` returns
58
66
  Generates a random date within the range specified by the `config` parameter.
59
67
  This can be used eg. for simulating dates of birth, dates of creation, etc.
60
68
 
69
+ ### `timeOfDay(config: Partial<{ use12HourFormat: boolean; showSeconds: boolean; showAmPm: boolean }> = {})`
70
+ Generates a random time of day, using the formatting specified by the `config` parameter.
71
+ It can be chained to the `date` method should you wish to further restrict available times (eg. by providing a min and max date to the `date` method that are on the same day within the desired time range).
72
+
61
73
  ### `uuid()`
62
74
  Increments a global `uuid` variable and sets the current value of the `SchemaItem` instance to this new value.
63
75
  This can be used eg. for simulating user ids, etc.
@@ -69,6 +81,17 @@ This can be used eg. for simulating whether a user is active, whether a product
69
81
  ### `symbol(val: string | number = 0)`
70
82
  Creates a new unique symbol with the provided `val` as the description.
71
83
 
84
+ ### `randomItem(items: R[])`
85
+ Sets the current value of the `SchemaItem` instance to a random item provided in the `items` parameter.
86
+
87
+ ### `prefix(prefix: string)`
88
+ Adds a prefix to the current value of the `SchemaItem` instance.
89
+ This can be used eg. to simulate currency when chaining with the `number` method - ie. `new SchemaItem().number(10, 100).prefix('$')`.
90
+
91
+ ### `suffix(suffix: string)`
92
+ Adds a suffix to the current value of the `SchemaItem` instance.
93
+ This can be used eg. to simulate percentages when chaining with the `number` method - ie. `new SchemaItem().number(10, 100).suffix('%')`.
94
+
72
95
  ### `identical(identity: R)`
73
96
  Sets the current value of the `SchemaItem` instance to the `identity` parameter.
74
97
  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;
@@ -12,9 +17,17 @@ export declare class SchemaItem<T = never> {
12
17
  max: Date;
13
18
  min: Date;
14
19
  }>): TSchemaInstance<Date>;
20
+ timeOfDay(this: TSchemaInstance<Date | undefined>, config?: Partial<{
21
+ use12HourFormat: boolean;
22
+ showSeconds: boolean;
23
+ showAmPm: boolean;
24
+ }>): TSchemaInstance<string>;
15
25
  uuid(this: TSchemaInstance<number | undefined>): TSchemaInstance<number>;
16
26
  boolean(this: TSchemaInstance<boolean | undefined>): TSchemaInstance<boolean>;
17
27
  symbol(this: TSchemaInstance<symbol | undefined>, val?: string | number): TSchemaInstance<symbol>;
28
+ randomItem<R>(this: TSchemaInstance<R | undefined>, items: R[]): TSchemaInstance<R>;
29
+ prefix(this: TSchemaInstance<number | string>, prefix: string): TSchemaInstance<string>;
30
+ suffix(this: TSchemaInstance<number | string>, suffix: string): TSchemaInstance<string>;
18
31
  identical<R>(this: TSchemaInstance<R | undefined>, identity: R): TSchemaInstance<R>;
19
32
  private assertType;
20
33
  private randomLoremWord;
@@ -1 +1 @@
1
- {"version":3,"file":"schema-item.model.d.ts","sourceRoot":"","sources":["../../../src/models/schema-item.model.ts"],"names":[],"mappings":"AAKA,KAAK,eAAe,CAAC,CAAC,IAAI,YAAY,CAAC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAE7D,qBAAa,UAAU,CAAC,CAAC,GAAG,KAAK;;IAC/B,IAAW,KAAK,IAAI,CAAC,CAEpB;IAIM,KAAK,CAAC,IAAI,EAAE,eAAe,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC;IAexF,UAAU,CAAC,IAAI,EAAE,eAAe,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC;IAsB7F,MAAM,CAAC,IAAI,EAAE,eAAe,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,GAAG,GAAE,MAAU,EAAE,GAAG,GAAE,MAAa,GAAG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AAI,EAAE,eAAe,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,eAAe,CAAC,MAAM,CAAC;IAQxE,OAAO,CAAC,IAAI,EAAE,eAAe,CAAC,OAAO,GAAG,SAAS,CAAC,GAAG,eAAe,CAAC,OAAO,CAAC;IAO7E,MAAM,CAAC,IAAI,EAAE,eAAe,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,GAAG,GAAE,MAAM,GAAG,MAAU,GAAG,eAAe,CAAC,MAAM,CAAC;IAOpG,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,eAAe,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,eAAe,CAAC,CAAC,CAAC;IAUnF,MAAM,CAAC,IAAI,EAAE,eAAe,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC;IAOvF,MAAM,CAAC,IAAI,EAAE,eAAe,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC;IAOvF,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,eAAe,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC;IAO1F,OAAO,CAAC,UAAU;IAElB,OAAO,CAAC,eAAe;CAKxB"}
package/dist/utils.mjs CHANGED
@@ -1,9 +1,9 @@
1
- var b = (s) => {
1
+ var f = (s) => {
2
2
  throw TypeError(s);
3
3
  };
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 = [
4
+ var y = (s, e, t) => e.has(s) || f("Cannot " + t);
5
+ var l = (s, e, t) => (y(s, e, "read from private field"), t ? t.call(s) : e.get(s)), T = (s, e, t) => e.has(s) ? f("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(s) : e.set(s, t), r = (s, e, t, i) => (y(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,8 +498,8 @@ 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 || {}), v = /* @__PURE__ */ ((s) => (s.PrimaryColor = "rgba(100, 100, 100, .6)", s.SecondaryColor = "rgba(100, 100, 100, .3)", s))(v || {});
502
- class g {
501
+ var c = /* @__PURE__ */ ((s) => (s.Text = "text", s.Input = "input", s.Image = "image", s.Video = "video", s.WrapperElement = "wrapper-element", s))(c || {}), b = /* @__PURE__ */ ((s) => (s.PrimaryColor = "rgba(100, 100, 100, .6)", s.SecondaryColor = "rgba(100, 100, 100, .3)", s))(b || {});
502
+ class v {
503
503
  static daysInMs(e) {
504
504
  return e * 24 * 60 * 60 * 1e3;
505
505
  }
@@ -508,67 +508,90 @@ class g {
508
508
  }
509
509
  }
510
510
  let M = 0;
511
- var r;
511
+ var a;
512
512
  class x {
513
513
  constructor() {
514
- q(this, r);
514
+ T(this, a);
515
515
  }
516
516
  get value() {
517
- return h(this, r);
517
+ return l(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, r, t.trim()), this;
524
+ return r(this, a, t.trim()), this;
525
525
  }
526
526
  paragraphs(e) {
527
527
  this.assertType();
528
528
  let t = "", i = 0;
529
- const c = 50;
529
+ const m = 50;
530
530
  for (; i < e; ) {
531
- const o = c - Math.round(c * Math.random() * 0.2) * (Math.random() < 0.5 ? -1 : 1);
531
+ const o = m - Math.round(m * 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, r, t), this;
535
+ return r(this, a, t), this;
536
536
  }
537
537
  number(e = 0, t = 1e3) {
538
- return this.assertType(), u(this, r, Math.ceil(Math.random() * (t - e)) + e), this;
538
+ return this.assertType(), r(this, a, Math.ceil(Math.random() * (t - e)) + e), this;
539
+ }
540
+ currency(e) {
541
+ return this.assertType(), r(this, a, new Intl.NumberFormat(
542
+ e.locale,
543
+ { ...e.options, style: "currency", currency: e.currency }
544
+ ).format(+l(this, a))), this;
539
545
  }
540
546
  multiply(e) {
541
- return this.assertType(), u(this, r, h(this, r) * e), this;
547
+ return this.assertType(), r(this, a, l(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, r, g.dateBetween(i, t)), this;
552
+ return e.isFuture ? i = new Date(Date.now() + v.daysInMs(1)) : e.isPast && (t = new Date(Date.now() - v.daysInMs(1))), r(this, a, v.dateBetween(i, t)), this;
553
+ }
554
+ timeOfDay(e = {}) {
555
+ const t = l(this, a) ?? this.date().value;
556
+ this.assertType();
557
+ const i = (e.use12HourFormat ? t.getUTCHours() % 12 : t.getUTCHours()).toString().padStart(2, "0"), m = t.getMinutes().toString().padStart(2, "0"), o = t.getSeconds().toString().padStart(2, "0"), d = this;
558
+ return r(d, a, e.showSeconds ? `${i}:${m}:${o}` : `${i}:${m}`), e.showAmPm && r(d, a, l(d, a) + (t.getUTCHours() >= 12 ? " PM" : " AM")), d;
547
559
  }
548
560
  uuid() {
549
- return M++, this.assertType(), u(this, r, M), this;
561
+ return M++, this.assertType(), r(this, a, M), this;
550
562
  }
551
563
  boolean() {
552
- return this.assertType(), u(this, r, Math.random() <= 0.5), this;
564
+ return this.assertType(), r(this, a, Math.random() <= 0.5), this;
553
565
  }
554
566
  symbol(e = 0) {
555
- return this.assertType(), u(this, r, Symbol(e)), this;
567
+ return this.assertType(), r(this, a, Symbol(e)), this;
568
+ }
569
+ randomItem(e) {
570
+ this.assertType();
571
+ const t = Math.floor(Math.random() * e.length);
572
+ return r(this, a, e[t]), this;
573
+ }
574
+ prefix(e) {
575
+ return this.assertType(), r(this, a, `${e}${l(this, a)}`), this;
576
+ }
577
+ suffix(e) {
578
+ return this.assertType(), r(this, a, `${l(this, a)}${e}`), this;
556
579
  }
557
580
  identical(e) {
558
- return this.assertType(), u(this, r, e), this;
581
+ return this.assertType(), r(this, a, e), this;
559
582
  }
560
583
  assertType() {
561
584
  }
562
585
  randomLoremWord() {
563
- const e = Math.floor(Math.random() * y.length);
564
- return y[e] ?? "lorem";
586
+ const e = Math.floor(Math.random() * q.length);
587
+ return q[e] ?? "lorem";
565
588
  }
566
589
  }
567
- r = new WeakMap();
590
+ a = new WeakMap();
568
591
  let I = 0;
569
- class d {
592
+ class h {
570
593
  constructor(e) {
571
- this.generator = e, this.uuid = I++, this.viewModel = this.generator(), this.val = d.modelToValue(this.viewModel);
594
+ this.generator = e, this.uuid = I++, this.viewModel = this.generator(), this.val = h.modelToValue(this.viewModel);
572
595
  }
573
596
  get value() {
574
597
  return this.val;
@@ -581,7 +604,7 @@ class d {
581
604
  {
582
605
  const t = {};
583
606
  return Object.keys(e).forEach((i) => {
584
- t[i] = d.modelToValue(
607
+ t[i] = h.modelToValue(
585
608
  e[i]
586
609
  );
587
610
  }), t;
@@ -594,7 +617,7 @@ class P {
594
617
  // - that all properties / methods accessed from within skeletonized part of the view are a part of skeletonSchema
595
618
  // - that typescript understands correct type of each property / method accessed from within the skeletonized part of the view
596
619
  proxy(e) {
597
- return e instanceof d ? e.value : e;
620
+ return e instanceof h ? e.value : e;
598
621
  }
599
622
  }
600
623
  class D {
@@ -605,18 +628,18 @@ class D {
605
628
  setupModels() {
606
629
  if (this.config) {
607
630
  const e = this.config.schemaGenerator;
608
- this.viewModels = Array.from({ length: this.config.repeat }, () => new d(e));
631
+ this.viewModels = Array.from({ length: this.config.repeat }, () => new h(e));
609
632
  }
610
633
  }
611
634
  }
612
635
  const n = class n {
613
636
  static skeletonizeProjectedTemplate(e, t) {
614
- const i = (t == null ? void 0 : t.primaryColor) ?? v.PrimaryColor, c = (t == null ? void 0 : t.secondaryColor) ?? v.SecondaryColor;
637
+ const i = (t == null ? void 0 : t.primaryColor) ?? b.PrimaryColor, m = (t == null ? void 0 : t.secondaryColor) ?? b.SecondaryColor;
615
638
  e.setAttribute(
616
639
  "style",
617
- `--skeletonizer-primary-color: ${i}; --skeletonizer-secondary-color: ${c};`
640
+ `--skeletonizer-primary-color: ${i}; --skeletonizer-secondary-color: ${m};`
618
641
  ), Array.from(e.querySelectorAll("*:not(svg, [data-skeletonizer])")).forEach((o) => {
619
- const A = [
642
+ const d = [
620
643
  "br",
621
644
  "b",
622
645
  "strong",
@@ -628,37 +651,37 @@ const n = class n {
628
651
  "ins",
629
652
  "sub",
630
653
  "sup"
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]);
632
- o.childNodes.forEach((a) => {
633
- switch (a.nodeName.toLowerCase()) {
654
+ ], g = Array.from(o.childNodes).map((u) => u.nodeName.toLowerCase()).filter((u) => !d.includes(u)), A = g.length > 0 && g.some((u) => u !== g[0]);
655
+ o.childNodes.forEach((u) => {
656
+ switch (u.nodeName.toLowerCase()) {
634
657
  case "#text": {
635
- if (this.assertAs(a), a.wholeText.trim())
636
- if (w) {
637
- const m = document.createElement("span");
638
- m.innerText = a.cloneNode().wholeText, m.innerText.length && a.replaceWith(
639
- n.skeletonizedSpanGenerator(m.innerText, l.Text)
658
+ if (this.assertAs(u), u.wholeText.trim())
659
+ if (A) {
660
+ const p = document.createElement("span");
661
+ p.innerText = u.cloneNode().wholeText, p.innerText.length && u.replaceWith(
662
+ n.skeletonizedSpanGenerator(p.innerText, c.Text)
640
663
  );
641
664
  } else {
642
- const m = n.skeletonizedSpanGenerator(o.innerHTML, l.Text);
643
- o.innerHTML = m.outerHTML;
665
+ const p = n.skeletonizedSpanGenerator(o.innerHTML, c.Text);
666
+ o.innerHTML = p.outerHTML;
644
667
  }
645
668
  break;
646
669
  }
647
670
  case "input": {
648
- a.setAttribute(n.dataAttr, l.Input);
671
+ u.setAttribute(n.dataAttr, c.Input);
649
672
  break;
650
673
  }
651
674
  case "img": {
652
- a.setAttribute(n.dataAttr, l.Image);
675
+ u.setAttribute(n.dataAttr, c.Image);
653
676
  break;
654
677
  }
655
678
  case "video": {
656
- a.setAttribute(n.dataAttr, l.Video);
679
+ u.setAttribute(n.dataAttr, c.Video);
657
680
  break;
658
681
  }
659
682
  }
660
683
  });
661
- }), e.setAttribute(n.dataAttr, l.WrapperElement);
684
+ }), e.setAttribute(n.dataAttr, c.WrapperElement);
662
685
  }
663
686
  static skeletonizedSpanGenerator(e, t) {
664
687
  const i = document.createElement("span");
@@ -668,11 +691,11 @@ const n = class n {
668
691
  }
669
692
  };
670
693
  n.dataAttr = "data-skeletonizer";
671
- let T = n;
694
+ let w = n;
672
695
  export {
673
- d as Schema,
696
+ h as Schema,
674
697
  x as SchemaItem,
675
698
  P as SkeletonAbstractComponent,
676
699
  D as SkeletonAdapterComponent,
677
- T as SkeletonDirective
700
+ w as SkeletonDirective
678
701
  };
package/dist/utils.umd.js CHANGED
@@ -1,2 +1,2 @@
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"})});
1
+ (function(s,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(s=typeof globalThis<"u"?globalThis:s||self,r(s["@skeletonizer/utils"]={}))})(this,function(s){"use strict";var A=s=>{throw TypeError(s)};var w=(s,r,n)=>r.has(s)||A("Cannot "+n);var c=(s,r,n)=>(w(s,r,"read from private field"),n?n.call(s):r.get(s)),x=(s,r,n)=>r.has(s)?A("Cannot add the same private member more than once"):r instanceof WeakSet?r.add(s):r.set(s,n),u=(s,r,n,g)=>(w(s,r,"write to private field"),g?g.call(s,n):r.set(s,n),n);var i;const r=["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 n=(o=>(o.Text="text",o.Input="input",o.Image="image",o.Video="video",o.WrapperElement="wrapper-element",o))(n||{}),g=(o=>(o.PrimaryColor="rgba(100, 100, 100, .6)",o.SecondaryColor="rgba(100, 100, 100, .3)",o))(g||{});class f{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 M=0;class q{constructor(){x(this,i)}get value(){return c(this,i)}words(e){this.assertType();let t="",a=0;for(;a<e;)t+=this.randomLoremWord()+" ",a++;return u(this,i,t.trim()),this}paragraphs(e){this.assertType();let t="",a=0;const p=50;for(;a<e;){const d=p-Math.round(p*Math.random()*.2)*(Math.random()<.5?-1:1);t+=this.words(d).value,a!==e-1&&(t+=`
2
+ `),a++}return u(this,i,t),this}number(e=0,t=1e3){return this.assertType(),u(this,i,Math.ceil(Math.random()*(t-e))+e),this}currency(e){return this.assertType(),u(this,i,new Intl.NumberFormat(e.locale,{...e.options,style:"currency",currency:e.currency}).format(+c(this,i))),this}multiply(e){return this.assertType(),u(this,i,c(this,i)*e),this}date(e={}){this.assertType();let t=e.max??new Date("2100-01-01"),a=e.min??new Date("1970-01-01");return e.isFuture?a=new Date(Date.now()+f.daysInMs(1)):e.isPast&&(t=new Date(Date.now()-f.daysInMs(1))),u(this,i,f.dateBetween(a,t)),this}timeOfDay(e={}){const t=c(this,i)??this.date().value;this.assertType();const a=(e.use12HourFormat?t.getUTCHours()%12:t.getUTCHours()).toString().padStart(2,"0"),p=t.getMinutes().toString().padStart(2,"0"),d=t.getSeconds().toString().padStart(2,"0"),h=this;return u(h,i,e.showSeconds?`${a}:${p}:${d}`:`${a}:${p}`),e.showAmPm&&u(h,i,c(h,i)+(t.getUTCHours()>=12?" PM":" AM")),h}uuid(){return M++,this.assertType(),u(this,i,M),this}boolean(){return this.assertType(),u(this,i,Math.random()<=.5),this}symbol(e=0){return this.assertType(),u(this,i,Symbol(e)),this}randomItem(e){this.assertType();const t=Math.floor(Math.random()*e.length);return u(this,i,e[t]),this}prefix(e){return this.assertType(),u(this,i,`${e}${c(this,i)}`),this}suffix(e){return this.assertType(),u(this,i,`${c(this,i)}${e}`),this}identical(e){return this.assertType(),u(this,i,e),this}assertType(){}randomLoremWord(){const e=Math.floor(Math.random()*r.length);return r[e]??"lorem"}}i=new WeakMap;let C=0;class b{constructor(e){this.generator=e,this.uuid=C++,this.viewModel=this.generator(),this.val=b.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(a=>{t[a]=b.modelToValue(e[a])}),t}}}class I{proxy(e){return e instanceof b?e.value:e}}class P{constructor(){this.config=null,this.viewModels=[]}setupModels(){if(this.config){const e=this.config.schemaGenerator;this.viewModels=Array.from({length:this.config.repeat},()=>new b(e))}}}const m=class m{static skeletonizeProjectedTemplate(e,t){const a=(t==null?void 0:t.primaryColor)??g.PrimaryColor,p=(t==null?void 0:t.secondaryColor)??g.SecondaryColor;e.setAttribute("style",`--skeletonizer-primary-color: ${a}; --skeletonizer-secondary-color: ${p};`),Array.from(e.querySelectorAll("*:not(svg, [data-skeletonizer])")).forEach(d=>{const h=["br","b","strong","i","em","mark","small","del","ins","sub","sup"],T=Array.from(d.childNodes).map(l=>l.nodeName.toLowerCase()).filter(l=>!h.includes(l)),S=T.length>0&&T.some(l=>l!==T[0]);d.childNodes.forEach(l=>{switch(l.nodeName.toLowerCase()){case"#text":{if(this.assertAs(l),l.wholeText.trim())if(S){const v=document.createElement("span");v.innerText=l.cloneNode().wholeText,v.innerText.length&&l.replaceWith(m.skeletonizedSpanGenerator(v.innerText,n.Text))}else{const v=m.skeletonizedSpanGenerator(d.innerHTML,n.Text);d.innerHTML=v.outerHTML}break}case"input":{l.setAttribute(m.dataAttr,n.Input);break}case"img":{l.setAttribute(m.dataAttr,n.Image);break}case"video":{l.setAttribute(m.dataAttr,n.Video);break}}})}),e.setAttribute(m.dataAttr,n.WrapperElement)}static skeletonizedSpanGenerator(e,t){const a=document.createElement("span");return a.innerHTML=e,a.setAttribute(m.dataAttr,t),a}static assertAs(e){}};m.dataAttr="data-skeletonizer";let y=m;s.Schema=b,s.SchemaItem=q,s.SkeletonAbstractComponent=I,s.SkeletonAdapterComponent=P,s.SkeletonDirective=y,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.1.2",
3
+ "version": "1.3.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": "5a9e8a309e8b9ac0649d1b84612389291920aff3"
58
+ "gitHead": "f92c5f202d62cb226317cf0c9a0a59e0921f5470"
59
59
  }