kitzo 2.0.20 → 2.0.22

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
@@ -25,7 +25,7 @@ npm i kitzo
25
25
  or
26
26
 
27
27
  ```javascript
28
- <script src="https://cdn.jsdelivr.net/npm/kitzo@2.0.20/dist/kitzo.umd.min.js"></script>
28
+ <script src="https://cdn.jsdelivr.net/npm/kitzo@2.0.22/dist/kitzo.umd.min.js"></script>
29
29
  ```
30
30
 
31
31
  > Attach this script tag in the html head tag and you are good to go.
@@ -117,9 +117,10 @@ document.querySelector('#search').addEventListener('input', (e) => {
117
117
 
118
118
  ```javascript
119
119
  kitzo.clippath(selectors | element | NodeList, {
120
- text: string,
120
+ textOption: null | { selector: string, value: string | number },
121
121
  clippathSize: string | number,
122
122
  smooth: boolean,
123
+ class: string,
123
124
  style: object,
124
125
  });
125
126
  ```
package/dist/kitzo.d.ts CHANGED
@@ -63,7 +63,13 @@ export type clippath = (
63
63
  element: string | Element | NodeListOf<Element>,
64
64
  config?: {
65
65
  /** Optional text inside the clippath element */
66
- text?: string;
66
+ textOption?: {
67
+ selector: string;
68
+ value: string | number;
69
+ };
70
+
71
+ /** Custom class to clip-path element */
72
+ class?: string;
67
73
 
68
74
  /** Size of the clippath circle (px or %). Default: '20%' */
69
75
  clippathSize?: string | number;
package/dist/kitzo.esm.js CHANGED
@@ -447,9 +447,10 @@ function clippath(element, config = {}) {
447
447
 
448
448
  config = Object.assign(
449
449
  {
450
- text: '',
450
+ textOption: null,
451
451
  clippathSize: '20%',
452
452
  smooth: true,
453
+ class: '',
453
454
  style: {},
454
455
  },
455
456
  config
@@ -485,70 +486,61 @@ function clippath(element, config = {}) {
485
486
 
486
487
  document.addEventListener('mouseover', (e) => {
487
488
  const btn = e.target.closest('[data-kitzo-clippath]');
488
-
489
489
  if (btn) {
490
490
  isHovering = true;
491
- const { text, style, clippathSize, smooth } = clippathConfigMap.get(btn);
492
- const { width, height, top, left } = btn.getBoundingClientRect();
493
-
494
491
  clippathDiv.removeAttribute('style');
495
-
496
- clippathDiv.style.width = width + 'px';
497
- clippathDiv.style.height = height + 'px';
498
- clippathDiv.style.top = top + 'px';
499
- clippathDiv.style.left = left + 'px';
500
-
501
- if (!text) {
502
- clippathDiv.innerHTML = btn.innerHTML;
503
- } else {
504
- clippathDiv.innerHTML = text;
505
- }
506
-
507
- clippathDiv.style.setProperty('--kitzo-clippath-transition', smooth ? 'clip-path 150ms ease-out, opacity 150ms' : 'none');
508
- clippathDiv.style.setProperty('--kitzo-clippath-size', getClippathSize(clippathSize));
509
-
510
- const { borderRadius, font, letterSpacing, lineHeight, border, boxSizing, padding, display } = window.getComputedStyle(btn);
511
-
512
- Object.assign(clippathDiv.style, {
492
+ const { textOption, clippathSize, smooth, style } = clippathConfigMap.get(btn);
493
+
494
+ const { top, left, width, height } = btn.getBoundingClientRect();
495
+ const cloned = btn.cloneNode(true);
496
+ cloned.className = cloned.className + ` ${clippathConfigMap.get(btn).class}`;
497
+ cloned.removeAttribute('data-kitzo-clippath');
498
+ cloned.setAttribute('data-temp-clippath-el', true);
499
+ Object.assign(cloned.style, {
513
500
  backgroundColor: '#01c2b8',
514
501
  color: 'white',
515
- borderRadius,
516
- font,
517
- letterSpacing,
518
- lineHeight,
519
- border,
520
- boxSizing,
521
- padding,
522
- display,
523
502
  ...style,
524
503
  });
525
504
 
505
+ if (textOption && textOption instanceof Object) {
506
+ const target = cloned.querySelector(textOption.selector);
507
+ if (target && (typeof textOption.value === 'string' || typeof textOption.value === 'number')) {
508
+ target.textContent = textOption.value;
509
+ }
510
+ }
511
+
512
+ clippathDiv.style.width = `${width}px`;
513
+ clippathDiv.style.height = `${height}px`;
514
+ clippathDiv.style.translate = `${left}px ${top}px`;
515
+ clippathDiv.style.setProperty('--kitzo-clippath-size', getClippathSize(clippathSize));
516
+ clippathDiv.style.setProperty('--kitzo-clippath-transition', smooth ? 'clip-path 150ms ease-out, opacity 150ms' : 'none');
517
+ clippathDiv.appendChild(cloned);
526
518
  requestAnimationFrame(() => {
527
519
  clippathDiv.classList.add('show');
528
520
  });
529
521
  }
530
522
  });
531
-
532
523
  document.addEventListener('mouseout', (e) => {
533
524
  const btn = e.target.closest('[data-kitzo-clippath]');
534
-
535
525
  if (btn) {
536
526
  clippathDiv.classList.remove('show');
537
- isHovering = false;
527
+ setTimeout(() => {
528
+ clippathDiv.querySelectorAll('[data-temp-clippath-el]').forEach((el) => el.remove());
529
+ }, 150);
538
530
  }
539
531
  });
540
532
 
541
533
  document.addEventListener('mousemove', (e) => {
542
534
  if (!isHovering) return;
543
- const btn = e.target.closest('[data-kitzo-clippath]');
544
535
 
536
+ const btn = e.target.closest('[data-kitzo-clippath]');
545
537
  if (btn) {
546
- const { top, left } = btn.getBoundingClientRect();
547
- const localX = e.clientX - left;
548
- const localY = e.clientY - top;
538
+ const { left, top } = btn.getBoundingClientRect();
539
+ const x = e.clientX - left;
540
+ const y = e.clientY - top;
549
541
 
550
- clippathDiv.style.setProperty('--kitzo-clippath-pos-x', `${localX}px`);
551
- clippathDiv.style.setProperty('--kitzo-clippath-pos-y', `${localY}px`);
542
+ clippathDiv.style.setProperty('--kitzo-clippath-pos-x', `${x}px`);
543
+ clippathDiv.style.setProperty('--kitzo-clippath-pos-y', `${y}px`);
552
544
  }
553
545
  });
554
546
 
package/dist/kitzo.umd.js CHANGED
@@ -453,9 +453,10 @@
453
453
 
454
454
  config = Object.assign(
455
455
  {
456
- text: '',
456
+ textOption: null,
457
457
  clippathSize: '20%',
458
458
  smooth: true,
459
+ class: '',
459
460
  style: {},
460
461
  },
461
462
  config
@@ -491,70 +492,61 @@
491
492
 
492
493
  document.addEventListener('mouseover', (e) => {
493
494
  const btn = e.target.closest('[data-kitzo-clippath]');
494
-
495
495
  if (btn) {
496
496
  isHovering = true;
497
- const { text, style, clippathSize, smooth } = clippathConfigMap.get(btn);
498
- const { width, height, top, left } = btn.getBoundingClientRect();
499
-
500
497
  clippathDiv.removeAttribute('style');
501
-
502
- clippathDiv.style.width = width + 'px';
503
- clippathDiv.style.height = height + 'px';
504
- clippathDiv.style.top = top + 'px';
505
- clippathDiv.style.left = left + 'px';
506
-
507
- if (!text) {
508
- clippathDiv.innerHTML = btn.innerHTML;
509
- } else {
510
- clippathDiv.innerHTML = text;
511
- }
512
-
513
- clippathDiv.style.setProperty('--kitzo-clippath-transition', smooth ? 'clip-path 150ms ease-out, opacity 150ms' : 'none');
514
- clippathDiv.style.setProperty('--kitzo-clippath-size', getClippathSize(clippathSize));
515
-
516
- const { borderRadius, font, letterSpacing, lineHeight, border, boxSizing, padding, display } = window.getComputedStyle(btn);
517
-
518
- Object.assign(clippathDiv.style, {
498
+ const { textOption, clippathSize, smooth, style } = clippathConfigMap.get(btn);
499
+
500
+ const { top, left, width, height } = btn.getBoundingClientRect();
501
+ const cloned = btn.cloneNode(true);
502
+ cloned.className = cloned.className + ` ${clippathConfigMap.get(btn).class}`;
503
+ cloned.removeAttribute('data-kitzo-clippath');
504
+ cloned.setAttribute('data-temp-clippath-el', true);
505
+ Object.assign(cloned.style, {
519
506
  backgroundColor: '#01c2b8',
520
507
  color: 'white',
521
- borderRadius,
522
- font,
523
- letterSpacing,
524
- lineHeight,
525
- border,
526
- boxSizing,
527
- padding,
528
- display,
529
508
  ...style,
530
509
  });
531
510
 
511
+ if (textOption && textOption instanceof Object) {
512
+ const target = cloned.querySelector(textOption.selector);
513
+ if (target && (typeof textOption.value === 'string' || typeof textOption.value === 'number')) {
514
+ target.textContent = textOption.value;
515
+ }
516
+ }
517
+
518
+ clippathDiv.style.width = `${width}px`;
519
+ clippathDiv.style.height = `${height}px`;
520
+ clippathDiv.style.translate = `${left}px ${top}px`;
521
+ clippathDiv.style.setProperty('--kitzo-clippath-size', getClippathSize(clippathSize));
522
+ clippathDiv.style.setProperty('--kitzo-clippath-transition', smooth ? 'clip-path 150ms ease-out, opacity 150ms' : 'none');
523
+ clippathDiv.appendChild(cloned);
532
524
  requestAnimationFrame(() => {
533
525
  clippathDiv.classList.add('show');
534
526
  });
535
527
  }
536
528
  });
537
-
538
529
  document.addEventListener('mouseout', (e) => {
539
530
  const btn = e.target.closest('[data-kitzo-clippath]');
540
-
541
531
  if (btn) {
542
532
  clippathDiv.classList.remove('show');
543
- isHovering = false;
533
+ setTimeout(() => {
534
+ clippathDiv.querySelectorAll('[data-temp-clippath-el]').forEach((el) => el.remove());
535
+ }, 150);
544
536
  }
545
537
  });
546
538
 
547
539
  document.addEventListener('mousemove', (e) => {
548
540
  if (!isHovering) return;
549
- const btn = e.target.closest('[data-kitzo-clippath]');
550
541
 
542
+ const btn = e.target.closest('[data-kitzo-clippath]');
551
543
  if (btn) {
552
- const { top, left } = btn.getBoundingClientRect();
553
- const localX = e.clientX - left;
554
- const localY = e.clientY - top;
544
+ const { left, top } = btn.getBoundingClientRect();
545
+ const x = e.clientX - left;
546
+ const y = e.clientY - top;
555
547
 
556
- clippathDiv.style.setProperty('--kitzo-clippath-pos-x', `${localX}px`);
557
- clippathDiv.style.setProperty('--kitzo-clippath-pos-y', `${localY}px`);
548
+ clippathDiv.style.setProperty('--kitzo-clippath-pos-x', `${x}px`);
549
+ clippathDiv.style.setProperty('--kitzo-clippath-pos-y', `${y}px`);
558
550
  }
559
551
  });
560
552
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kitzo",
3
- "version": "2.0.20",
3
+ "version": "2.0.22",
4
4
  "description": "A lightweight JavaScript UI micro-library.",
5
5
  "type": "module",
6
6
  "main": "./dist/kitzo.umd.js",