@skeletonizer/vue 0.0.13-alpha.0 → 0.0.14-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/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { SkeletonizerComponentComposable } from './composables/skeletonizer.component.composable';
2
2
  import { default as SkeletonizerSkeleton } from './components/SkeletonizerSkeleton.vue';
3
3
 
4
- export { SkeletonizerSkeleton, SkeletonizerComponentComposable };
4
+ import * as SkeletonizerPlugin from './main';
5
+ export { SkeletonizerSkeleton, SkeletonizerComponentComposable, SkeletonizerPlugin };
package/dist/main.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { App } from 'vue';
2
+
3
+ declare const _default: {
4
+ install: (app: App) => void;
5
+ };
6
+ export default _default;
@@ -1,13 +1,13 @@
1
- import { defineComponent as y, reactive as g, watch as M, resolveDirective as S, openBlock as m, createElementBlock as c, Fragment as T, renderList as k, withDirectives as D, renderSlot as d } from "vue";
2
- var f = (s, e, t) => {
3
- if (!e.has(s))
1
+ import { defineComponent as D, reactive as T, watch as C, resolveDirective as x, openBlock as f, createElementBlock as b, Fragment as I, renderList as P, withDirectives as N, renderSlot as y } from "vue";
2
+ var M = (i, e, t) => {
3
+ if (!e.has(i))
4
4
  throw TypeError("Cannot " + t);
5
- }, p = (s, e, t) => (f(s, e, "read from private field"), t ? t.call(s) : e.get(s)), I = (s, e, t) => {
6
- if (e.has(s))
5
+ }, q = (i, e, t) => (M(i, e, "read from private field"), t ? t.call(i) : e.get(i)), j = (i, e, t) => {
6
+ if (e.has(i))
7
7
  throw TypeError("Cannot add the same private member more than once");
8
- e instanceof WeakSet ? e.add(s) : e.set(s, t);
9
- }, u = (s, e, t, i) => (f(s, e, "write to private field"), i ? i.call(s, t) : e.set(s, t), t);
10
- const h = [
8
+ e instanceof WeakSet ? e.add(i) : e.set(i, t);
9
+ }, n = (i, e, t, s) => (M(i, e, "write to private field"), s ? s.call(i, t) : e.set(i, t), t);
10
+ const k = [
11
11
  "Lorem",
12
12
  "ipsum",
13
13
  "dolor",
@@ -502,7 +502,8 @@ const h = [
502
502
  "hendrerit",
503
503
  "dolor."
504
504
  ];
505
- class l {
505
+ var l = /* @__PURE__ */ ((i) => (i.Text = "text", i.Input = "input", i.Image = "image", i.Video = "video", i.WrapperElement = "wrapper-element", i))(l || {}), v = /* @__PURE__ */ ((i) => (i.PrimaryColor = "rgba(100, 100, 100, .6)", i.SecondaryColor = "rgba(100, 100, 100, .3)", i))(v || {});
506
+ class g {
506
507
  static daysInMs(e) {
507
508
  return e * 24 * 60 * 60 * 1e3;
508
509
  }
@@ -510,96 +511,96 @@ class l {
510
511
  return new Date(e.getTime() + Math.random() * (t.getTime() - e.getTime()));
511
512
  }
512
513
  }
513
- let v = 0;
514
- var a;
515
- class N {
514
+ let w = 0;
515
+ var r;
516
+ class E {
516
517
  constructor() {
517
- I(this, a, void 0);
518
+ j(this, r, void 0);
518
519
  }
519
520
  get value() {
520
- return p(this, a);
521
+ return q(this, r);
521
522
  }
522
523
  words(e) {
523
524
  this.assertType();
524
- let t = "", i = 0;
525
- for (; i < e; )
526
- t += this.randomLoremWord() + " ", i++;
527
- return u(this, a, t.trim()), this;
525
+ let t = "", s = 0;
526
+ for (; s < e; )
527
+ t += this.randomLoremWord() + " ", s++;
528
+ return n(this, r, t.trim()), this;
528
529
  }
529
530
  paragraphs(e) {
530
531
  this.assertType();
531
- let t = "", i = 0;
532
- const n = 50;
533
- for (; i < e; ) {
534
- const o = n - Math.round(n * Math.random() * 0.2) * (Math.random() < 0.5 ? -1 : 1);
535
- t += this.words(o).value, i !== e - 1 && (t += `
536
- `), i++;
532
+ let t = "", s = 0;
533
+ const c = 50;
534
+ for (; s < e; ) {
535
+ const u = c - Math.round(c * Math.random() * 0.2) * (Math.random() < 0.5 ? -1 : 1);
536
+ t += this.words(u).value, s !== e - 1 && (t += `
537
+ `), s++;
537
538
  }
538
- return u(this, a, t), this;
539
+ return n(this, r, t), this;
539
540
  }
540
541
  number(e = 0, t = 1e3) {
541
- return this.assertType(), u(this, a, Math.ceil(Math.random() * (t - e)) + e), this;
542
+ return this.assertType(), n(this, r, Math.ceil(Math.random() * (t - e)) + e), this;
542
543
  }
543
544
  multiply(e) {
544
- return this.assertType(), u(this, a, p(this, a) * e), this;
545
+ return this.assertType(), n(this, r, q(this, r) * e), this;
545
546
  }
546
547
  date(e = {}) {
547
548
  this.assertType();
548
- let t = e.max ?? /* @__PURE__ */ new Date("2100-01-01"), i = e.min ?? /* @__PURE__ */ new Date("1970-01-01");
549
- return e.isFuture ? i = new Date(Date.now() + l.daysInMs(1)) : e.isPast && (t = new Date(Date.now() - l.daysInMs(1))), u(this, a, l.dateBetween(i, t)), this;
549
+ let t = e.max ?? /* @__PURE__ */ new Date("2100-01-01"), s = e.min ?? /* @__PURE__ */ new Date("1970-01-01");
550
+ return e.isFuture ? s = new Date(Date.now() + g.daysInMs(1)) : e.isPast && (t = new Date(Date.now() - g.daysInMs(1))), n(this, r, g.dateBetween(s, t)), this;
550
551
  }
551
552
  uuid() {
552
- return v++, this.assertType(), u(this, a, v), this;
553
+ return w++, this.assertType(), n(this, r, w), this;
553
554
  }
554
555
  boolean() {
555
- return this.assertType(), u(this, a, Math.random() <= 0.5), this;
556
+ return this.assertType(), n(this, r, Math.random() <= 0.5), this;
556
557
  }
557
558
  symbol(e = 0) {
558
- return this.assertType(), u(this, a, Symbol(e)), this;
559
+ return this.assertType(), n(this, r, Symbol(e)), this;
559
560
  }
560
561
  identical(e) {
561
- return this.assertType(), u(this, a, e), this;
562
+ return this.assertType(), n(this, r, e), this;
562
563
  }
563
564
  assertType() {
564
565
  }
565
566
  randomLoremWord() {
566
- const e = Math.floor(Math.random() * h.length);
567
- return h[e] ?? "lorem";
567
+ const e = Math.floor(Math.random() * k.length);
568
+ return k[e] ?? "lorem";
568
569
  }
569
570
  }
570
- a = /* @__PURE__ */ new WeakMap();
571
- class r {
571
+ r = /* @__PURE__ */ new WeakMap();
572
+ class p {
572
573
  constructor(e) {
573
- this.generator = e, this.viewModel = this.generator(), this.val = r.modelToValue(this.viewModel);
574
+ this.generator = e, this.viewModel = this.generator(), this.val = p.modelToValue(this.viewModel);
574
575
  }
575
576
  get value() {
576
577
  return this.val;
577
578
  }
578
579
  static modelToValue(e) {
579
- if (e instanceof N)
580
+ if (e instanceof E)
580
581
  return e.value;
581
582
  if (Array.isArray(e))
582
583
  return e.map(this.modelToValue);
583
584
  {
584
585
  const t = {};
585
- return Object.keys(e).forEach((i) => {
586
- t[i] = r.modelToValue(
587
- e[i]
586
+ return Object.keys(e).forEach((s) => {
587
+ t[s] = p.modelToValue(
588
+ e[s]
588
589
  );
589
590
  }), t;
590
591
  }
591
592
  }
592
593
  }
593
- class P {
594
+ class L {
594
595
  // when accessing skeletonized component properties / methods from within the view, they should be accessed via proxy method
595
596
  // this is necessary to ensure:
596
597
  // - that all properties / methods accessed from within skeletonized part of the view are a part of skeletonSchema
597
598
  // - that typescript understands correct type of each property / method accessed from within the skeletonized part of the view
598
599
  proxy(e) {
599
- return e instanceof r ? e.value : e;
600
+ return e instanceof p ? e.value : e;
600
601
  }
601
602
  }
602
- class A {
603
+ class V {
603
604
  constructor() {
604
605
  this.config = null, this.viewModels = [];
605
606
  }
@@ -607,11 +608,71 @@ class A {
607
608
  setupModels() {
608
609
  if (this.config) {
609
610
  const e = this.config.schemaGenerator;
610
- this.viewModels = Array.from({ length: this.config.repeat }, () => new r(e));
611
+ this.viewModels = Array.from({ length: this.config.repeat }, () => new p(e));
611
612
  }
612
613
  }
613
614
  }
614
- const j = /* @__PURE__ */ y({
615
+ const S = class o {
616
+ static skeletonizeProjectedTemplate(e, t) {
617
+ const s = (t == null ? void 0 : t.primaryColor) ?? v.PrimaryColor, c = (t == null ? void 0 : t.secondaryColor) ?? v.SecondaryColor;
618
+ e.setAttribute(
619
+ "style",
620
+ `--skeletonizer-primary-color: ${s}; --skeletonizer-secondary-color: ${c};`
621
+ ), Array.from(e.querySelectorAll("*:not(svg, [data-skeletonizer])")).forEach((u) => {
622
+ const h = [
623
+ "br",
624
+ "b",
625
+ "strong",
626
+ "i",
627
+ "em",
628
+ "mark",
629
+ "small",
630
+ "del",
631
+ "ins",
632
+ "sub",
633
+ "sup"
634
+ ], m = Array.from(u.childNodes).map((a) => a.nodeName.toLowerCase()).filter((a) => !h.includes(a)), z = m.length > 0 && m.some((a) => a !== m[0]);
635
+ u.childNodes.forEach((a) => {
636
+ switch (a.nodeName.toLowerCase()) {
637
+ case "#text": {
638
+ if (this.assertAs(a), a.wholeText.trim())
639
+ if (z) {
640
+ const d = document.createElement("span");
641
+ d.innerText = a.cloneNode().wholeText, d.innerText.length && a.replaceWith(
642
+ o.skeletonizedSpanGenerator(d.innerText, l.Text)
643
+ );
644
+ } else {
645
+ const d = o.skeletonizedSpanGenerator(u.innerHTML, l.Text);
646
+ u.innerHTML = d.outerHTML;
647
+ }
648
+ break;
649
+ }
650
+ case "input": {
651
+ a.setAttribute(o.dataAttr, l.Input);
652
+ break;
653
+ }
654
+ case "img": {
655
+ a.setAttribute(o.dataAttr, l.Image);
656
+ break;
657
+ }
658
+ case "video": {
659
+ a.setAttribute(o.dataAttr, l.Video);
660
+ break;
661
+ }
662
+ }
663
+ });
664
+ }), e.setAttribute(o.dataAttr, l.WrapperElement);
665
+ }
666
+ static skeletonizedSpanGenerator(e, t) {
667
+ const s = document.createElement("span");
668
+ return s.innerHTML = e, s.setAttribute(o.dataAttr, t), s;
669
+ }
670
+ static assertAs(e) {
671
+ }
672
+ };
673
+ S.dataAttr = "data-skeletonizer";
674
+ let W = S;
675
+ const B = /* @__PURE__ */ D({
615
676
  __name: "SkeletonizerSkeleton",
616
677
  props: {
617
678
  config: {},
@@ -619,38 +680,49 @@ const j = /* @__PURE__ */ y({
619
680
  scope: {},
620
681
  colorSchema: {}
621
682
  },
622
- setup(s) {
623
- const e = s, t = g(new A());
624
- return M(
683
+ setup(i) {
684
+ const e = i, t = T(new V());
685
+ return C(
625
686
  e.config,
626
- (i) => {
627
- t.config = i, t.setupModels();
687
+ (s) => {
688
+ t.config = s, t.setupModels();
628
689
  },
629
690
  { immediate: !0 }
630
- ), (i, n) => {
631
- const o = S("skeletonize");
632
- return i.showSkeleton ? (m(!0), c(T, { key: 0 }, k(t.viewModels, (q, w) => D((m(), c("div", { key: w }, [
633
- d(i.$slots, "default", {
634
- scope: q.value
691
+ ), (s, c) => {
692
+ const u = x("skeletonize");
693
+ return s.showSkeleton ? (f(!0), b(I, { key: 0 }, P(t.viewModels, (h, m) => N((f(), b("div", { key: m }, [
694
+ y(s.$slots, "default", {
695
+ scope: h.value
635
696
  })
636
697
  ])), [
637
- [o, e.colorSchema]
638
- ])), 128)) : d(i.$slots, "default", {
698
+ [u, e.colorSchema]
699
+ ])), 128)) : y(s.$slots, "default", {
639
700
  key: 1,
640
701
  scope: e.scope
641
702
  });
642
703
  };
643
704
  }
644
705
  });
645
- class b extends P {
706
+ class A extends L {
646
707
  constructor(e, t) {
647
708
  super(), this.skeletonConfig = e, this.showSkeleton = t;
648
709
  }
649
710
  static generate(e, t) {
650
- return g(new b(e, t));
711
+ return T(new A(e, t));
651
712
  }
652
713
  }
714
+ const $ = {
715
+ install: (i) => {
716
+ i.component("SkeletonizerSkeleton", B), i.directive("skeletonize", (e, t) => {
717
+ W.skeletonizeProjectedTemplate(e, t.value);
718
+ });
719
+ }
720
+ }, H = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
721
+ __proto__: null,
722
+ default: $
723
+ }, Symbol.toStringTag, { value: "Module" }));
653
724
  export {
654
- b as SkeletonizerComponentComposable,
655
- j as SkeletonizerSkeleton
725
+ A as SkeletonizerComponentComposable,
726
+ H as SkeletonizerPlugin,
727
+ B as SkeletonizerSkeleton
656
728
  };
@@ -1,3 +1,3 @@
1
- (function(u,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],a):(u=typeof globalThis<"u"?globalThis:u||self,a(u.SkeletonizerVue={},u.Vue))})(this,function(u,a){"use strict";var p=document.createElement("style");p.textContent=`[data-skeletonizer=wrapper-element]{--skeletonizer-text-background: rgba(0, 0, 0, .2);display:contents;filter:grayscale(100%);pointer-events:none}[data-skeletonizer=wrapper-element] *{pointer-events:none}[data-skeletonizer=wrapper-element] [data-skeletonizer=text]{animation:text-animation 2s infinite ease-in-out;background:var(--skeletonizer-primary-color);border-radius:50px;color:#0000!important}@keyframes text-animation{0%{background:var(--skeletonizer-primary-color)}50%{background:var(--skeletonizer-secondary-color)}to{background:var(--skeletonizer-primary-color)}}
2
- `,document.head.appendChild(p);var h=(s,e,t)=>{if(!e.has(s))throw TypeError("Cannot "+t)},g=(s,e,t)=>(h(s,e,"read from private field"),t?t.call(s):e.get(s)),b=(s,e,t)=>{if(e.has(s))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(s):e.set(s,t)},n=(s,e,t,i)=>(h(s,e,"write to private field"),i?i.call(s,t):e.set(s,t),t);const f=["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."];class l{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 v=0;var r;class y{constructor(){b(this,r,void 0)}get value(){return g(this,r)}words(e){this.assertType();let t="",i=0;for(;i<e;)t+=this.randomLoremWord()+" ",i++;return n(this,r,t.trim()),this}paragraphs(e){this.assertType();let t="",i=0;const c=50;for(;i<e;){const d=c-Math.round(c*Math.random()*.2)*(Math.random()<.5?-1:1);t+=this.words(d).value,i!==e-1&&(t+=`
3
- `),i++}return n(this,r,t),this}number(e=0,t=1e3){return this.assertType(),n(this,r,Math.ceil(Math.random()*(t-e))+e),this}multiply(e){return this.assertType(),n(this,r,g(this,r)*e),this}date(e={}){this.assertType();let t=e.max??new Date("2100-01-01"),i=e.min??new Date("1970-01-01");return e.isFuture?i=new Date(Date.now()+l.daysInMs(1)):e.isPast&&(t=new Date(Date.now()-l.daysInMs(1))),n(this,r,l.dateBetween(i,t)),this}uuid(){return v++,this.assertType(),n(this,r,v),this}boolean(){return this.assertType(),n(this,r,Math.random()<=.5),this}symbol(e=0){return this.assertType(),n(this,r,Symbol(e)),this}identical(e){return this.assertType(),n(this,r,e),this}assertType(){}randomLoremWord(){const e=Math.floor(Math.random()*f.length);return f[e]??"lorem"}}r=new WeakMap;class o{constructor(e){this.generator=e,this.viewModel=this.generator(),this.val=o.modelToValue(this.viewModel)}get value(){return this.val}static modelToValue(e){if(e instanceof y)return e.value;if(Array.isArray(e))return e.map(this.modelToValue);{const t={};return Object.keys(e).forEach(i=>{t[i]=o.modelToValue(e[i])}),t}}}class k{proxy(e){return e instanceof o?e.value:e}}class q{constructor(){this.config=null,this.viewModels=[]}setupModels(){if(this.config){const e=this.config.schemaGenerator;this.viewModels=Array.from({length:this.config.repeat},()=>new o(e))}}}const w=a.defineComponent({__name:"SkeletonizerSkeleton",props:{config:{},showSkeleton:{type:Boolean},scope:{},colorSchema:{}},setup(s){const e=s,t=a.reactive(new q);return a.watch(e.config,i=>{t.config=i,t.setupModels()},{immediate:!0}),(i,c)=>{const d=a.resolveDirective("skeletonize");return i.showSkeleton?(a.openBlock(!0),a.createElementBlock(a.Fragment,{key:0},a.renderList(t.viewModels,(M,S)=>a.withDirectives((a.openBlock(),a.createElementBlock("div",{key:S},[a.renderSlot(i.$slots,"default",{scope:M.value})])),[[d,e.colorSchema]])),128)):a.renderSlot(i.$slots,"default",{key:1,scope:e.scope})}}});class m extends k{constructor(e,t){super(),this.skeletonConfig=e,this.showSkeleton=t}static generate(e,t){return a.reactive(new m(e,t))}}u.SkeletonizerComponentComposable=m,u.SkeletonizerSkeleton=w,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
1
+ (function(o,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],r):(o=typeof globalThis<"u"?globalThis:o||self,r(o.SkeletonizerVue={},o.Vue))})(this,function(o,r){"use strict";var y=document.createElement("style");y.textContent=`[data-skeletonizer=wrapper-element]{--skeletonizer-text-background: rgba(0, 0, 0, .2);display:contents;filter:grayscale(100%);pointer-events:none}[data-skeletonizer=wrapper-element] *{pointer-events:none}[data-skeletonizer=wrapper-element] [data-skeletonizer=text]{animation:text-animation 2s infinite ease-in-out;background:var(--skeletonizer-primary-color);border-radius:50px;color:#0000!important}@keyframes text-animation{0%{background:var(--skeletonizer-primary-color)}50%{background:var(--skeletonizer-secondary-color)}to{background:var(--skeletonizer-primary-color)}}
2
+ `,document.head.appendChild(y);var q=(i,e,t)=>{if(!e.has(i))throw TypeError("Cannot "+t)},w=(i,e,t)=>(q(i,e,"read from private field"),t?t.call(i):e.get(i)),A=(i,e,t)=>{if(e.has(i))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(i):e.set(i,t)},u=(i,e,t,s)=>(q(i,e,"write to private field"),s?s.call(i,t):e.set(i,t),t);const T=["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 m=(i=>(i.Text="text",i.Input="input",i.Image="image",i.Video="video",i.WrapperElement="wrapper-element",i))(m||{}),f=(i=>(i.PrimaryColor="rgba(100, 100, 100, .6)",i.SecondaryColor="rgba(100, 100, 100, .3)",i))(f||{});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 S=0;var n;class x{constructor(){A(this,n,void 0)}get value(){return w(this,n)}words(e){this.assertType();let t="",s=0;for(;s<e;)t+=this.randomLoremWord()+" ",s++;return u(this,n,t.trim()),this}paragraphs(e){this.assertType();let t="",s=0;const p=50;for(;s<e;){const l=p-Math.round(p*Math.random()*.2)*(Math.random()<.5?-1:1);t+=this.words(l).value,s!==e-1&&(t+=`
3
+ `),s++}return u(this,n,t),this}number(e=0,t=1e3){return this.assertType(),u(this,n,Math.ceil(Math.random()*(t-e))+e),this}multiply(e){return this.assertType(),u(this,n,w(this,n)*e),this}date(e={}){this.assertType();let t=e.max??new Date("2100-01-01"),s=e.min??new Date("1970-01-01");return e.isFuture?s=new Date(Date.now()+v.daysInMs(1)):e.isPast&&(t=new Date(Date.now()-v.daysInMs(1))),u(this,n,v.dateBetween(s,t)),this}uuid(){return S++,this.assertType(),u(this,n,S),this}boolean(){return this.assertType(),u(this,n,Math.random()<=.5),this}symbol(e=0){return this.assertType(),u(this,n,Symbol(e)),this}identical(e){return this.assertType(),u(this,n,e),this}assertType(){}randomLoremWord(){const e=Math.floor(Math.random()*T.length);return T[e]??"lorem"}}n=new WeakMap;class d{constructor(e){this.generator=e,this.viewModel=this.generator(),this.val=d.modelToValue(this.viewModel)}get value(){return this.val}static modelToValue(e){if(e instanceof x)return e.value;if(Array.isArray(e))return e.map(this.modelToValue);{const t={};return Object.keys(e).forEach(s=>{t[s]=d.modelToValue(e[s])}),t}}}class C{proxy(e){return e instanceof d?e.value:e}}class D{constructor(){this.config=null,this.viewModels=[]}setupModels(){if(this.config){const e=this.config.schemaGenerator;this.viewModels=Array.from({length:this.config.repeat},()=>new d(e))}}}const M=class c{static skeletonizeProjectedTemplate(e,t){const s=(t==null?void 0:t.primaryColor)??f.PrimaryColor,p=(t==null?void 0:t.secondaryColor)??f.SecondaryColor;e.setAttribute("style",`--skeletonizer-primary-color: ${s}; --skeletonizer-secondary-color: ${p};`),Array.from(e.querySelectorAll("*:not(svg, [data-skeletonizer])")).forEach(l=>{const k=["br","b","strong","i","em","mark","small","del","ins","sub","sup"],h=Array.from(l.childNodes).map(a=>a.nodeName.toLowerCase()).filter(a=>!k.includes(a)),N=h.length>0&&h.some(a=>a!==h[0]);l.childNodes.forEach(a=>{switch(a.nodeName.toLowerCase()){case"#text":{if(this.assertAs(a),a.wholeText.trim())if(N){const g=document.createElement("span");g.innerText=a.cloneNode().wholeText,g.innerText.length&&a.replaceWith(c.skeletonizedSpanGenerator(g.innerText,m.Text))}else{const g=c.skeletonizedSpanGenerator(l.innerHTML,m.Text);l.innerHTML=g.outerHTML}break}case"input":{a.setAttribute(c.dataAttr,m.Input);break}case"img":{a.setAttribute(c.dataAttr,m.Image);break}case"video":{a.setAttribute(c.dataAttr,m.Video);break}}})}),e.setAttribute(c.dataAttr,m.WrapperElement)}static skeletonizedSpanGenerator(e,t){const s=document.createElement("span");return s.innerHTML=e,s.setAttribute(c.dataAttr,t),s}static assertAs(e){}};M.dataAttr="data-skeletonizer";let P=M;const z=r.defineComponent({__name:"SkeletonizerSkeleton",props:{config:{},showSkeleton:{type:Boolean},scope:{},colorSchema:{}},setup(i){const e=i,t=r.reactive(new D);return r.watch(e.config,s=>{t.config=s,t.setupModels()},{immediate:!0}),(s,p)=>{const l=r.resolveDirective("skeletonize");return s.showSkeleton?(r.openBlock(!0),r.createElementBlock(r.Fragment,{key:0},r.renderList(t.viewModels,(k,h)=>r.withDirectives((r.openBlock(),r.createElementBlock("div",{key:h},[r.renderSlot(s.$slots,"default",{scope:k.value})])),[[l,e.colorSchema]])),128)):r.renderSlot(s.$slots,"default",{key:1,scope:e.scope})}}});class b extends C{constructor(e,t){super(),this.skeletonConfig=e,this.showSkeleton=t}static generate(e,t){return r.reactive(new b(e,t))}}const I=Object.freeze(Object.defineProperty({__proto__:null,default:{install:i=>{i.component("SkeletonizerSkeleton",z),i.directive("skeletonize",(e,t)=>{P.skeletonizeProjectedTemplate(e,t.value)})}}},Symbol.toStringTag,{value:"Module"}));o.SkeletonizerComponentComposable=b,o.SkeletonizerPlugin=I,o.SkeletonizerSkeleton=z,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skeletonizer/vue",
3
- "version": "0.0.13-alpha.0",
3
+ "version": "0.0.14-alpha.0",
4
4
  "description": "The way to skeletonize your Vue.js components",
5
5
  "author": "Luka Varga",
6
6
  "license": "MIT",
@@ -17,11 +17,11 @@
17
17
  "loading"
18
18
  ],
19
19
  "main": "./dist/skeletonizer-vue.umd.js",
20
- "module": "./dist/skeletonizer-vue.js",
20
+ "module": "./dist/skeletonizer-vue.mjs",
21
21
  "exports": {
22
22
  ".": {
23
23
  "types": "./dist/index.d.ts",
24
- "import": "./dist/skeletonizer-vue.js",
24
+ "import": "./dist/skeletonizer-vue.mjs",
25
25
  "require": "./dist/skeletonizer-vue.umd.js"
26
26
  }
27
27
  },
@@ -80,5 +80,5 @@
80
80
  "**/*.{scss,css}": "stylelint --fix",
81
81
  "**/*.{ts,js,.vue}": "eslint --fix"
82
82
  },
83
- "gitHead": "bd0b1ba7a8cbb5ca810407d296d27127b9be3dcd"
83
+ "gitHead": "592b1af4eb3a15ced8effe39797fdf7c3f7765bc"
84
84
  }