Skip to content

Commit

Permalink
Export animate-on-reveal web-component independently
Browse files Browse the repository at this point in the history
  • Loading branch information
JayaKrishnaNamburu committed Jan 17, 2024
1 parent 21414e0 commit 4d5630b
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 224 deletions.
101 changes: 101 additions & 0 deletions dist/animate-on-reveal.es.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
const style = "";
const DEV_COMPONENT_TAG_NAME = "animate-on-reveal";
const _AnimateOnElementReveal = class _AnimateOnElementReveal2 extends HTMLElement {
constructor() {
super();
if (!this.firstElementChild) {
return;
}
this.nodeToObserve = this.findObservableNodeFromTree(
this.firstElementChild
);
this.intersectionObserver = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
this.setAttribute("revealed", "");
} else {
this.removeAttribute("revealed");
}
});
},
{ threshold: 0.5 }
);
this.style.display = "contents";
}
static registerSelf() {
if (!window.customElements.get(DEV_COMPONENT_TAG_NAME)) {
window.customElements.define(
DEV_COMPONENT_TAG_NAME,
_AnimateOnElementReveal2
);
}
}
connectedCallback() {
if (!this.nodeToObserve) {
return;
}
this.nodeToObserve.style.animationPlayState = "paused";
this.intersectionObserver.observe(this.nodeToObserve);
}
disconnectedCallback() {
this.intersectionObserver.disconnect();
}
findObservableNodeFromTree(node) {
const style2 = window.getComputedStyle(node);
if (style2.getPropertyValue("display") !== "contents") {
return node;
}
const children = node.children;
for (let i = 0; i < children.length; i++) {
const descendant = this.findObservableNodeFromTree(children[i]);
if (descendant) {
return descendant;
}
}
return null;
}
attributeChangedCallback(name) {
switch (name) {
case "animation":
this.nodeToObserve.style.animationName = this.getAttribute("animation") || "";
break;
case "duration":
this.nodeToObserve.style.animationDuration = this.getAttribute(name) || "0s";
break;
case "delay":
this.nodeToObserve.style.animationDelay = this.getAttribute(name) || "0s";
break;
case "easing":
this.nodeToObserve.style.animationTimingFunction = this.getAttribute(name) || "ease";
break;
case "iteration":
this.nodeToObserve.style.animationIterationCount = this.getAttribute(name) || "1";
break;
case "direction":
this.nodeToObserve.style.animationDirection = this.getAttribute(name) || "normal";
break;
case "revealed":
this.nodeToObserve.style.animationPlayState = this.hasAttribute(
"revealed"
) ? "running" : "paused";
break;
}
}
};
_AnimateOnElementReveal.observedAttributes = [
"animation",
"duration",
"delay",
"direction",
"easing",
"revealed",
"class",
"classname",
"iteration"
];
let AnimateOnElementReveal = _AnimateOnElementReveal;
AnimateOnElementReveal.registerSelf();
export {
AnimateOnElementReveal as default
};
5 changes: 3 additions & 2 deletions dist/animate-on-reveal.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory() : typeof define === "function" && define.amd ? define(factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, global["scroll-reveal"] = factory());
})(this, function() {
"use strict";
const style = "";
const DEV_COMPONENT_TAG_NAME = "animate-on-reveal";
const _AnimateOnElementReveal = class _AnimateOnElementReveal2 extends HTMLElement {
constructor() {
Expand Down Expand Up @@ -45,8 +46,8 @@
this.intersectionObserver.disconnect();
}
findObservableNodeFromTree(node) {
const style = window.getComputedStyle(node);
if (style.getPropertyValue("display") !== "contents") {
const style2 = window.getComputedStyle(node);
if (style2.getPropertyValue("display") !== "contents") {
return node;
}
const children = node.children;
Expand Down
101 changes: 0 additions & 101 deletions dist/react-components.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const dayjs = require('dayjs');
const React = require('react');

const style = '';

const DateTimePrimitive = ({ date, format }) => {
const dateTime = dayjs.unix(new Date(date).getTime() / 1e3);
const formattedDate = dayjs(dateTime).format(format);
Expand Down Expand Up @@ -128,105 +126,6 @@ const CMSMixedType = ({ itemData, mappingConfiguration, renderDefault, renderErr
}
};

const DEV_COMPONENT_TAG_NAME = "animate-on-reveal";
const _AnimateOnElementReveal = class _AnimateOnElementReveal extends HTMLElement {
constructor() {
super();
if (!this.firstElementChild) {
return;
}
this.nodeToObserve = this.findObservableNodeFromTree(
this.firstElementChild
);
this.intersectionObserver = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
this.setAttribute("revealed", "");
} else {
this.removeAttribute("revealed");
}
});
},
{ threshold: 0.5 }
);
this.style.display = "contents";
}
static registerSelf() {
if (!window.customElements.get(DEV_COMPONENT_TAG_NAME)) {
window.customElements.define(
DEV_COMPONENT_TAG_NAME,
_AnimateOnElementReveal
);
}
}
connectedCallback() {
if (!this.nodeToObserve) {
return;
}
this.nodeToObserve.style.animationPlayState = "paused";
this.intersectionObserver.observe(this.nodeToObserve);
}
disconnectedCallback() {
this.intersectionObserver.disconnect();
}
findObservableNodeFromTree(node) {
const style = window.getComputedStyle(node);
if (style.getPropertyValue("display") !== "contents") {
return node;
}
const children = node.children;
for (let i = 0; i < children.length; i++) {
const descendant = this.findObservableNodeFromTree(children[i]);
if (descendant) {
return descendant;
}
}
return null;
}
attributeChangedCallback(name) {
switch (name) {
case "animation":
this.nodeToObserve.style.animationName = this.getAttribute("animation") || "";
break;
case "duration":
this.nodeToObserve.style.animationDuration = this.getAttribute(name) || "0s";
break;
case "delay":
this.nodeToObserve.style.animationDelay = this.getAttribute(name) || "0s";
break;
case "easing":
this.nodeToObserve.style.animationTimingFunction = this.getAttribute(name) || "ease";
break;
case "iteration":
this.nodeToObserve.style.animationIterationCount = this.getAttribute(name) || "1";
break;
case "direction":
this.nodeToObserve.style.animationDirection = this.getAttribute(name) || "normal";
break;
case "revealed":
this.nodeToObserve.style.animationPlayState = this.hasAttribute(
"revealed"
) ? "running" : "paused";
break;
}
}
};
_AnimateOnElementReveal.observedAttributes = [
"animation",
"duration",
"delay",
"direction",
"easing",
"revealed",
"class",
"classname",
"iteration"
];
let AnimateOnElementReveal = _AnimateOnElementReveal;
AnimateOnElementReveal.registerSelf();

exports.AnimateOnElementReveal = AnimateOnElementReveal;
exports.CMSMixedType = CMSMixedType;
exports.CaisyDocumentLink = CaisyDocumentLink;
exports.DangerousHTML = DangerousHTML;
Expand Down
102 changes: 1 addition & 101 deletions dist/react-components.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import dayjs from 'dayjs';
import React, { useRef, useEffect, useState } from 'react';

const style = '';

const DateTimePrimitive = ({ date, format }) => {
const dateTime = dayjs.unix(new Date(date).getTime() / 1e3);
const formattedDate = dayjs(dateTime).format(format);
Expand Down Expand Up @@ -124,102 +122,4 @@ const CMSMixedType = ({ itemData, mappingConfiguration, renderDefault, renderErr
}
};

const DEV_COMPONENT_TAG_NAME = "animate-on-reveal";
const _AnimateOnElementReveal = class _AnimateOnElementReveal extends HTMLElement {
constructor() {
super();
if (!this.firstElementChild) {
return;
}
this.nodeToObserve = this.findObservableNodeFromTree(
this.firstElementChild
);
this.intersectionObserver = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
this.setAttribute("revealed", "");
} else {
this.removeAttribute("revealed");
}
});
},
{ threshold: 0.5 }
);
this.style.display = "contents";
}
static registerSelf() {
if (!window.customElements.get(DEV_COMPONENT_TAG_NAME)) {
window.customElements.define(
DEV_COMPONENT_TAG_NAME,
_AnimateOnElementReveal
);
}
}
connectedCallback() {
if (!this.nodeToObserve) {
return;
}
this.nodeToObserve.style.animationPlayState = "paused";
this.intersectionObserver.observe(this.nodeToObserve);
}
disconnectedCallback() {
this.intersectionObserver.disconnect();
}
findObservableNodeFromTree(node) {
const style = window.getComputedStyle(node);
if (style.getPropertyValue("display") !== "contents") {
return node;
}
const children = node.children;
for (let i = 0; i < children.length; i++) {
const descendant = this.findObservableNodeFromTree(children[i]);
if (descendant) {
return descendant;
}
}
return null;
}
attributeChangedCallback(name) {
switch (name) {
case "animation":
this.nodeToObserve.style.animationName = this.getAttribute("animation") || "";
break;
case "duration":
this.nodeToObserve.style.animationDuration = this.getAttribute(name) || "0s";
break;
case "delay":
this.nodeToObserve.style.animationDelay = this.getAttribute(name) || "0s";
break;
case "easing":
this.nodeToObserve.style.animationTimingFunction = this.getAttribute(name) || "ease";
break;
case "iteration":
this.nodeToObserve.style.animationIterationCount = this.getAttribute(name) || "1";
break;
case "direction":
this.nodeToObserve.style.animationDirection = this.getAttribute(name) || "normal";
break;
case "revealed":
this.nodeToObserve.style.animationPlayState = this.hasAttribute(
"revealed"
) ? "running" : "paused";
break;
}
}
};
_AnimateOnElementReveal.observedAttributes = [
"animation",
"duration",
"delay",
"direction",
"easing",
"revealed",
"class",
"classname",
"iteration"
];
let AnimateOnElementReveal = _AnimateOnElementReveal;
AnimateOnElementReveal.registerSelf();

export { AnimateOnElementReveal, CMSMixedType, CaisyDocumentLink, DangerousHTML, DataProvider, DateTimePrimitive, Repeater };
export { CMSMixedType, CaisyDocumentLink, DangerousHTML, DataProvider, DateTimePrimitive, Repeater };
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@teleporthq/react-components",
"version": "1.0.8",
"version": "1.0.9",
"description": "",
"main": "dist/react-components.js",
"type": "module",
Expand All @@ -9,7 +9,10 @@
"import": "./dist/react-components.js",
"require": "./dist/react-components.cjs"
},
"./animate-on-reveal": "./dist/animate-on-reveal.umd.js",
"./animate-on-reveal": {
"import": "./dist/animate-on-reveal.es.js",
"umd": "./dist/animate-on-reveal.umd.js"
},
"./style": "./style.css"
},
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/animate-on-reveal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "./style.css";
const DEV_COMPONENT_TAG_NAME = "animate-on-reveal";
class AnimateOnElementReveal extends HTMLElement {
static observedAttributes: string[] = [
Expand Down
14 changes: 6 additions & 8 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import './animate-on-reveal/style.css'
export { default as DateTimePrimitive } from './date-time'
export { default as DangerousHTML } from './dangerous-html'
export { default as DataProvider } from './data-provider'
export { default as Repeater } from './repeater'
export { default as CaisyDocumentLink } from './caisy-document-link'
export { default as CMSMixedType } from './cms-mixed-type'
export { default as AnimateOnElementReveal } from './animate-on-reveal'
export { default as DateTimePrimitive } from "./date-time";
export { default as DangerousHTML } from "./dangerous-html";
export { default as DataProvider } from "./data-provider";
export { default as Repeater } from "./repeater";
export { default as CaisyDocumentLink } from "./caisy-document-link";
export { default as CMSMixedType } from "./cms-mixed-type";
Loading

0 comments on commit 4d5630b

Please sign in to comment.