@skeletonizer/utils 1.3.7 → 1.4.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
@@ -55,6 +55,10 @@ This can be used eg. for simulating descriptions, articles, etc.
55
55
  Generates a random number between the `min` and `max` parameters.
56
56
  This can be used eg. for simulating prices, available quantities, etc.
57
57
 
58
+ ### `float(min: number = 0, max: number = 1000)`
59
+ Generates a random float number between the `min` and `max` parameters.
60
+ It can be chained on a number value - in that case, it turns the integer into a float.
61
+
58
62
  ### `currency(config: { locale: string; currency: string; options?: Omit<Intl.NumberFormatOptions, 'style' | 'currency'> })`
59
63
  Turns the string or number value of the `SchemaItem` instance into a currency string of the provided locale and currency.
60
64
  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' })`.
@@ -5,6 +5,7 @@ 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
+ float(this: TSchemaInstance<number | undefined>, min?: number, max?: number): TSchemaInstance<number>;
8
9
  currency(this: TSchemaInstance<number | string>, config: {
9
10
  locale: string;
10
11
  currency: string;
@@ -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,MAA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E,OAAO,CAAA;KAAE,CAAM,GAC1F,eAAe,CAAC,MAAM,CAAC;IAwBnB,IAAI,CAAC,IAAI,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
@@ -2,8 +2,8 @@ var f = (s) => {
2
2
  throw TypeError(s);
3
3
  };
4
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 = [
5
+ var n = (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, a) => (y(s, e, "write to private field"), a ? a.call(s, t) : e.set(s, t), t);
6
+ const M = [
7
7
  "Lorem",
8
8
  "ipsum",
9
9
  "dolor",
@@ -507,87 +507,90 @@ class v {
507
507
  return new Date(e.getTime() + Math.random() * (t.getTime() - e.getTime()));
508
508
  }
509
509
  }
510
- let M = 0;
511
- var a;
510
+ let q = 0;
511
+ var i;
512
512
  class x {
513
513
  constructor() {
514
- T(this, a);
514
+ T(this, i);
515
515
  }
516
516
  get value() {
517
- return l(this, a);
517
+ return n(this, i);
518
518
  }
519
519
  words(e) {
520
520
  this.assertType();
521
- let t = "", i = 0;
522
- for (; i < e; )
523
- t += this.randomLoremWord() + " ", i++;
524
- return r(this, a, t.trim()), this;
521
+ let t = "", a = 0;
522
+ for (; a < e; )
523
+ t += this.randomLoremWord() + " ", a++;
524
+ return r(this, i, t.trim()), this;
525
525
  }
526
526
  paragraphs(e) {
527
527
  this.assertType();
528
- let t = "", i = 0;
528
+ let t = "", a = 0;
529
529
  const m = 50;
530
- for (; i < e; ) {
531
- const o = m - Math.round(m * Math.random() * 0.2) * (Math.random() < 0.5 ? -1 : 1);
532
- t += this.words(o).value, i !== e - 1 && (t += `
533
- `), i++;
530
+ for (; a < e; ) {
531
+ const l = m - Math.round(m * Math.random() * 0.2) * (Math.random() < 0.5 ? -1 : 1);
532
+ t += this.words(l).value, a !== e - 1 && (t += `
533
+ `), a++;
534
534
  }
535
- return r(this, a, t), this;
535
+ return r(this, i, t), this;
536
536
  }
537
537
  number(e = 0, t = 1e3) {
538
- return this.assertType(), r(this, a, Math.ceil(Math.random() * (t - e)) + e), this;
538
+ return this.assertType(), r(this, i, Math.ceil(Math.random() * (t - e)) + e), this;
539
+ }
540
+ float(e = 0, t = 1e3) {
541
+ return this.assertType(), r(this, i, n(this, i) ? n(this, i) + Math.random() : Math.random() * (t - e) + e), this;
539
542
  }
540
543
  currency(e) {
541
- return this.assertType(), r(this, a, new Intl.NumberFormat(
544
+ return this.assertType(), r(this, i, new Intl.NumberFormat(
542
545
  e.locale,
543
546
  { ...e.options, style: "currency", currency: e.currency }
544
- ).format(+l(this, a))), this;
547
+ ).format(+n(this, i))), this;
545
548
  }
546
549
  multiply(e) {
547
- return this.assertType(), r(this, a, l(this, a) * e), this;
550
+ return this.assertType(), r(this, i, n(this, i) * e), this;
548
551
  }
549
552
  date(e = {}) {
550
553
  this.assertType();
551
- let t = e.max ?? /* @__PURE__ */ new Date("2100-01-01"), i = e.min ?? /* @__PURE__ */ new Date("1970-01-01");
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;
554
+ let t = e.max ?? /* @__PURE__ */ new Date("2100-01-01"), a = e.min ?? /* @__PURE__ */ new Date("1970-01-01");
555
+ return e.isFuture ? a = new Date(Date.now() + v.daysInMs(1)) : e.isPast && (t = new Date(Date.now() - v.daysInMs(1))), r(this, i, v.dateBetween(a, t)), this;
553
556
  }
554
557
  timeOfDay(e = {}) {
555
- const t = l(this, a) ?? this.date().value;
558
+ const t = n(this, i) ?? this.date().value;
556
559
  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;
560
+ const a = (e.use12HourFormat ? t.getUTCHours() % 12 : t.getUTCHours()).toString().padStart(2, "0"), m = t.getMinutes().toString().padStart(2, "0"), l = t.getSeconds().toString().padStart(2, "0"), d = this;
561
+ return r(d, i, e.showSeconds ? `${a}:${m}:${l}` : `${a}:${m}`), e.showAmPm && r(d, i, n(d, i) + (t.getUTCHours() >= 12 ? " PM" : " AM")), d;
559
562
  }
560
563
  uuid() {
561
- return M++, this.assertType(), r(this, a, M), this;
564
+ return q++, this.assertType(), r(this, i, q), this;
562
565
  }
563
566
  boolean() {
564
- return this.assertType(), r(this, a, Math.random() <= 0.5), this;
567
+ return this.assertType(), r(this, i, Math.random() <= 0.5), this;
565
568
  }
566
569
  symbol(e = 0) {
567
- return this.assertType(), r(this, a, Symbol(e)), this;
570
+ return this.assertType(), r(this, i, Symbol(e)), this;
568
571
  }
569
572
  randomItem(e) {
570
573
  this.assertType();
571
574
  const t = Math.floor(Math.random() * e.length);
572
- return r(this, a, e[t]), this;
575
+ return r(this, i, e[t]), this;
573
576
  }
574
577
  prefix(e) {
575
- return this.assertType(), r(this, a, `${e}${l(this, a)}`), this;
578
+ return this.assertType(), r(this, i, `${e}${n(this, i)}`), this;
576
579
  }
577
580
  suffix(e) {
578
- return this.assertType(), r(this, a, `${l(this, a)}${e}`), this;
581
+ return this.assertType(), r(this, i, `${n(this, i)}${e}`), this;
579
582
  }
580
583
  identical(e) {
581
- return this.assertType(), r(this, a, e), this;
584
+ return this.assertType(), r(this, i, e), this;
582
585
  }
583
586
  assertType() {
584
587
  }
585
588
  randomLoremWord() {
586
- const e = Math.floor(Math.random() * q.length);
587
- return q[e] ?? "lorem";
589
+ const e = Math.floor(Math.random() * M.length);
590
+ return M[e] ?? "lorem";
588
591
  }
589
592
  }
590
- a = new WeakMap();
593
+ i = new WeakMap();
591
594
  let I = 0;
592
595
  class h {
593
596
  constructor(e) {
@@ -603,9 +606,9 @@ class h {
603
606
  return e.map(this.modelToValue);
604
607
  {
605
608
  const t = {};
606
- return Object.keys(e).forEach((i) => {
607
- t[i] = h.modelToValue(
608
- e[i]
609
+ return Object.keys(e).forEach((a) => {
610
+ t[a] = h.modelToValue(
611
+ e[a]
609
612
  );
610
613
  }), t;
611
614
  }
@@ -632,13 +635,13 @@ class D {
632
635
  }
633
636
  }
634
637
  }
635
- const n = class n {
638
+ const o = class o {
636
639
  static skeletonizeProjectedTemplate(e, t) {
637
- const i = (t == null ? void 0 : t.primaryColor) ?? b.PrimaryColor, m = (t == null ? void 0 : t.secondaryColor) ?? b.SecondaryColor;
640
+ const a = (t == null ? void 0 : t.primaryColor) ?? b.PrimaryColor, m = (t == null ? void 0 : t.secondaryColor) ?? b.SecondaryColor;
638
641
  e.setAttribute(
639
642
  "style",
640
- `--skeletonizer-primary-color: ${i}; --skeletonizer-secondary-color: ${m};`
641
- ), Array.from(e.querySelectorAll("*:not(svg, [data-skeletonizer])")).forEach((o) => {
643
+ `--skeletonizer-primary-color: ${a}; --skeletonizer-secondary-color: ${m};`
644
+ ), Array.from(e.querySelectorAll("*:not(svg, [data-skeletonizer])")).forEach((l) => {
642
645
  const d = [
643
646
  "br",
644
647
  "b",
@@ -651,47 +654,47 @@ const n = class n {
651
654
  "ins",
652
655
  "sub",
653
656
  "sup"
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) => {
657
+ ], g = Array.from(l.childNodes).map((u) => u.nodeName.toLowerCase()).filter((u) => !d.includes(u)), A = g.length > 0 && g.some((u) => u !== g[0]);
658
+ l.childNodes.forEach((u) => {
656
659
  switch (u.nodeName.toLowerCase()) {
657
660
  case "#text": {
658
661
  if (this.assertAs(u), u.wholeText.trim())
659
662
  if (A) {
660
663
  const p = document.createElement("span");
661
664
  p.innerText = u.cloneNode().wholeText, p.innerText.length && u.replaceWith(
662
- n.skeletonizedSpanGenerator(p.innerText, c.Text)
665
+ o.skeletonizedSpanGenerator(p.innerText, c.Text)
663
666
  );
664
667
  } else {
665
- const p = n.skeletonizedSpanGenerator(o.innerHTML, c.Text);
666
- o.innerHTML = p.outerHTML;
668
+ const p = o.skeletonizedSpanGenerator(l.innerHTML, c.Text);
669
+ l.innerHTML = p.outerHTML;
667
670
  }
668
671
  break;
669
672
  }
670
673
  case "input": {
671
- u.setAttribute(n.dataAttr, c.Input);
674
+ u.setAttribute(o.dataAttr, c.Input);
672
675
  break;
673
676
  }
674
677
  case "img": {
675
- u.setAttribute(n.dataAttr, c.Image);
678
+ u.setAttribute(o.dataAttr, c.Image);
676
679
  break;
677
680
  }
678
681
  case "video": {
679
- u.setAttribute(n.dataAttr, c.Video);
682
+ u.setAttribute(o.dataAttr, c.Video);
680
683
  break;
681
684
  }
682
685
  }
683
686
  });
684
- }), e.setAttribute(n.dataAttr, c.WrapperElement);
687
+ }), e.setAttribute(o.dataAttr, c.WrapperElement);
685
688
  }
686
689
  static skeletonizedSpanGenerator(e, t) {
687
- const i = document.createElement("span");
688
- return i.innerHTML = e, i.setAttribute(n.dataAttr, t), i;
690
+ const a = document.createElement("span");
691
+ return a.innerHTML = e, a.setAttribute(o.dataAttr, t), a;
689
692
  }
690
693
  static assertAs(e) {
691
694
  }
692
695
  };
693
- n.dataAttr = "data-skeletonizer";
694
- let w = n;
696
+ o.dataAttr = "data-skeletonizer";
697
+ let w = o;
695
698
  export {
696
699
  h as Schema,
697
700
  x as SchemaItem,
package/dist/utils.umd.js CHANGED
@@ -1,2 +1,2 @@
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"})});
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 d=(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 d(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 c=p-Math.round(p*Math.random()*.2)*(Math.random()<.5?-1:1);t+=this.words(c).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}float(e=0,t=1e3){return this.assertType(),u(this,i,d(this,i)?d(this,i)+Math.random():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(+d(this,i))),this}multiply(e){return this.assertType(),u(this,i,d(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=d(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"),c=t.getSeconds().toString().padStart(2,"0"),h=this;return u(h,i,e.showSeconds?`${a}:${p}:${c}`:`${a}:${p}`),e.showAmPm&&u(h,i,d(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}${d(this,i)}`),this}suffix(e){return this.assertType(),u(this,i,`${d(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(c=>{const h=["br","b","strong","i","em","mark","small","del","ins","sub","sup"],T=Array.from(c.childNodes).map(l=>l.nodeName.toLowerCase()).filter(l=>!h.includes(l)),S=T.length>0&&T.some(l=>l!==T[0]);c.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(c.innerHTML,n.Text);c.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.3.7",
3
+ "version": "1.4.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.5"
57
57
  },
58
- "gitHead": "d06bdbda7b474224a5685cebd3fb794e3cd3cf1a"
58
+ "gitHead": "934d7afca4fa94addbb54fa28ecc758da51f5d64"
59
59
  }