data-scroll-animation
Advanced tools
Comparing version 1.2.2 to 1.3.0
# CHANGELOG | ||
## [1.3.0] - 2021-10-12 | ||
- skip "html" element in rect calculations | ||
- emit ts declarations | ||
## [1.2.2] - 2021-06-08 | ||
@@ -4,0 +8,0 @@ - fix get rect top |
@@ -1,48 +0,10 @@ | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
function __read(o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
} | ||
function __spreadArray(to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
} | ||
var EXTRAPOLATE = Symbol("extrapolate"); | ||
const EXTRAPOLATE = Symbol("extrapolate"); | ||
function computeFrames(frames) { | ||
var staticString = null; | ||
var indexes = []; | ||
var frameNumbers = []; | ||
var frameValues = []; | ||
var beforeValue = null; | ||
var afterValue = null; | ||
var needUpdateAt = [false, null, null, false]; | ||
let staticString = null; | ||
let indexes = []; | ||
let frameNumbers = []; | ||
let frameValues = []; | ||
let beforeValue = null; | ||
let afterValue = null; | ||
const needUpdateAt = [false, null, null, false]; | ||
function getNearestLeftIndexOf(frameNumber) { | ||
@@ -52,4 +14,4 @@ if (frameNumbers.length === 0) { | ||
} | ||
var leftIndex = 0; | ||
for (var i = 1; i < frameNumbers.length; i++) { | ||
let leftIndex = 0; | ||
for (let i = 1; i < frameNumbers.length; i++) { | ||
if (frameNumbers[i] > frameNumber) { | ||
@@ -63,5 +25,5 @@ break; | ||
{ | ||
var constants_1 = false; | ||
frames.sort(function (a, b) { | ||
var result; | ||
let constants = false; | ||
frames.sort((a, b) => { | ||
let result; | ||
if (a[0] === "before") { | ||
@@ -84,3 +46,3 @@ result = b[0] === "after" ? -1 : b[0] === "before" ? 0 : 1; | ||
}); | ||
frames.forEach(function (frame) { | ||
frames.forEach(frame => { | ||
if (frame[1] === EXTRAPOLATE) { | ||
@@ -102,3 +64,3 @@ if (frame[0] !== "after" && frame[0] !== "before") { | ||
} | ||
var thisStaticString; | ||
let thisStaticString; | ||
frameNumbers.push(frame[0]); | ||
@@ -111,3 +73,3 @@ if (needUpdateAt[1] == null || needUpdateAt[1] > frame[0]) { | ||
} | ||
if (!constants_1) { | ||
if (!constants) { | ||
thisStaticString = frame[1].trim() | ||
@@ -118,4 +80,4 @@ .replace(/[ ]*,[ ]*/g, ",") | ||
.replace(/(?:\)[ ]{2,}(?! \w))/g, ")"); | ||
var thisStaticStringEmpty = thisStaticString.replace(/-?\d+(?:\.\d+)?/g, ""); | ||
var wasStaticStringNULL = staticString == null; | ||
const thisStaticStringEmpty = thisStaticString.replace(/-?\d+(?:\.\d+)?/g, ""); | ||
const wasStaticStringNULL = staticString == null; | ||
if (wasStaticStringNULL) { | ||
@@ -125,9 +87,9 @@ staticString = thisStaticStringEmpty; | ||
if (thisStaticStringEmpty !== staticString) { | ||
constants_1 = true; | ||
constants = true; | ||
} | ||
if (!constants_1) { | ||
var match = void 0; | ||
var thisValues = []; | ||
if (!constants) { | ||
let match; | ||
const thisValues = []; | ||
while (match = (/(?:-?\d+(?:\.\d+)?)/).exec(thisStaticString)) { | ||
var thisStaticStringArray = thisStaticString.split(""); | ||
let thisStaticStringArray = thisStaticString.split(""); | ||
thisStaticStringArray.splice(match.index, match[0].length); | ||
@@ -144,5 +106,5 @@ thisStaticString = thisStaticStringArray.join(""); | ||
}); | ||
if (constants_1) { | ||
if (constants) { | ||
return { | ||
compute: function (frameNumber) { | ||
compute: (frameNumber) => { | ||
if (frameNumber === "before") { | ||
@@ -160,3 +122,3 @@ if (beforeValue != null) { | ||
} | ||
var index = getNearestLeftIndexOf(frameNumber); | ||
const index = getNearestLeftIndexOf(frameNumber); | ||
if (index === -1) { | ||
@@ -167,3 +129,3 @@ return ""; | ||
}, | ||
needUpdateAt: needUpdateAt | ||
needUpdateAt | ||
}; | ||
@@ -174,3 +136,3 @@ } | ||
return { | ||
compute: function (frameNumber) { | ||
compute: (frameNumber) => { | ||
if (frameNumber === "before" && beforeValue != null) { | ||
@@ -187,4 +149,4 @@ return beforeValue; | ||
} | ||
var staticStringArray = staticString.split("").reduce(function (prev, current, index) { | ||
if (indexes.some(function (i) { return i === index; })) { | ||
const staticStringArray = staticString.split("").reduce((prev, current, index) => { | ||
if (indexes.some(i => i === index)) { | ||
prev.push(""); | ||
@@ -196,6 +158,6 @@ } | ||
function constructString(values) { | ||
var constructedString = ""; | ||
var index = 0; | ||
var indexesLength = indexes.length; | ||
for (var i = 0; i < indexesLength; i++) { | ||
let constructedString = ""; | ||
let index = 0; | ||
const indexesLength = indexes.length; | ||
for (let i = 0; i < indexesLength; i++) { | ||
constructedString += staticStringArray[index] + values[i].toString(); | ||
@@ -210,3 +172,3 @@ index++; | ||
return { | ||
compute: function (frameNumber) { | ||
compute: (frameNumber) => { | ||
if (frameNumber === "before") { | ||
@@ -225,3 +187,3 @@ if (beforeValue != null) { | ||
frameNumber = Math.min(Math.max(0, frameNumber), 1); | ||
var index = getNearestLeftIndexOf(frameNumber); | ||
const index = getNearestLeftIndexOf(frameNumber); | ||
if (index === -1) { | ||
@@ -233,12 +195,12 @@ return ""; | ||
} | ||
var left = frameNumbers[index]; | ||
var right = frameNumbers[index + 1]; | ||
var perc = (frameNumber - left) / (right - left); | ||
var computedValues = []; | ||
var frameValue = frameValues[index]; | ||
var nextFrameValue = frameValues[index + 1]; | ||
var frameValueLength = frameValue.length; | ||
for (var v_index = 0; v_index < frameValueLength; v_index++) { | ||
var value = frameValue[v_index]; | ||
var nextValue = nextFrameValue[v_index]; | ||
const left = frameNumbers[index]; | ||
const right = frameNumbers[index + 1]; | ||
const perc = (frameNumber - left) / (right - left); | ||
const computedValues = []; | ||
const frameValue = frameValues[index]; | ||
const nextFrameValue = frameValues[index + 1]; | ||
const frameValueLength = frameValue.length; | ||
for (let v_index = 0; v_index < frameValueLength; v_index++) { | ||
const value = frameValue[v_index]; | ||
const nextValue = nextFrameValue[v_index]; | ||
computedValues.push(value + ((nextValue - value) * perc)); | ||
@@ -248,30 +210,27 @@ } | ||
}, | ||
needUpdateAt: needUpdateAt | ||
needUpdateAt | ||
}; | ||
} | ||
var SCROLL_OBJECT = Symbol("scroll-object"); | ||
var SCROLL_PARENT = Symbol("scroll-parent"); | ||
var ScrollObject = (function () { | ||
function ScrollObject(el, frames) { | ||
const SCROLL_OBJECT = Symbol("scroll-object"); | ||
const SCROLL_PARENT = Symbol("scroll-parent"); | ||
class ScrollObject { | ||
el; | ||
constructor(el, frames) { | ||
this.el = el; | ||
this._needUpdateAt = [false, null, null, false]; | ||
this._frames = []; | ||
this._lastRenderFrame = null; | ||
this.refresh(frames); | ||
} | ||
ScrollObject.prototype.refresh = function (frames) { | ||
var _this = this; | ||
refresh(frames) { | ||
this.el[SCROLL_OBJECT] = this; | ||
this._frames = []; | ||
var _loop_1 = function (key) { | ||
for (let key in frames) { | ||
if (!Object.prototype.hasOwnProperty.call(frames, key)) { | ||
return "continue"; | ||
continue; | ||
} | ||
var splitKey = key.split("."); | ||
var _a = __read(splitKey.pop().match(/^([^\(\)]*)(\(\))?$/) || [], 3), isValid = _a[0], lastKey = _a[1], isFunction = _a[2]; | ||
const splitKey = key.split("."); | ||
const [isValid, lastKey, isFunction] = splitKey.pop().match(/^([^\(\)]*)(\(\))?$/) || []; | ||
if (!isValid) { | ||
return "continue"; | ||
continue; | ||
} | ||
var _b = computeFrames(frames[key]), compute = _b.compute, needUpdateAt = _b.needUpdateAt; | ||
if (isFunction && needUpdateAt.every(function (value, index) { | ||
const { compute, needUpdateAt } = computeFrames(frames[key]); | ||
if (isFunction && needUpdateAt.every((value, index) => { | ||
if (index === 0 || index === 3) { | ||
@@ -287,6 +246,6 @@ return value === false; | ||
} | ||
var keyLength = splitKey.length; | ||
var accessor = function () { | ||
var lastObject = _this.el; | ||
for (var i = 0; i < keyLength; i++) { | ||
const keyLength = splitKey.length; | ||
const accessor = () => { | ||
let lastObject = this.el; | ||
for (let i = 0; i < keyLength; i++) { | ||
if (lastObject == null) { | ||
@@ -299,19 +258,15 @@ return [null, ""]; | ||
}; | ||
this_1._frames.push([accessor, isFunction != null, compute]); | ||
this_1._needUpdateAt[0] = this_1._needUpdateAt[0] || needUpdateAt[0]; | ||
if (this_1._needUpdateAt[1] !== needUpdateAt[1] && | ||
needUpdateAt[1] != null && (this_1._needUpdateAt[1] == null || | ||
needUpdateAt[1] < this_1._needUpdateAt[1])) { | ||
this_1._needUpdateAt[1] = needUpdateAt[1]; | ||
this._frames.push([accessor, isFunction != null, compute]); | ||
this._needUpdateAt[0] = this._needUpdateAt[0] || needUpdateAt[0]; | ||
if (this._needUpdateAt[1] !== needUpdateAt[1] && | ||
needUpdateAt[1] != null && (this._needUpdateAt[1] == null || | ||
needUpdateAt[1] < this._needUpdateAt[1])) { | ||
this._needUpdateAt[1] = needUpdateAt[1]; | ||
} | ||
if (this_1._needUpdateAt[2] !== needUpdateAt[2] && | ||
needUpdateAt[2] != null && (this_1._needUpdateAt[2] == null || | ||
needUpdateAt[2] > this_1._needUpdateAt[2])) { | ||
this_1._needUpdateAt[2] = needUpdateAt[2]; | ||
if (this._needUpdateAt[2] !== needUpdateAt[2] && | ||
needUpdateAt[2] != null && (this._needUpdateAt[2] == null || | ||
needUpdateAt[2] > this._needUpdateAt[2])) { | ||
this._needUpdateAt[2] = needUpdateAt[2]; | ||
} | ||
this_1._needUpdateAt[3] = this_1._needUpdateAt[3] || needUpdateAt[3]; | ||
}; | ||
var this_1 = this; | ||
for (var key in frames) { | ||
_loop_1(key); | ||
this._needUpdateAt[3] = this._needUpdateAt[3] || needUpdateAt[3]; | ||
} | ||
@@ -321,5 +276,9 @@ this._lastRenderFrame = null; | ||
return this; | ||
}; | ||
ScrollObject.prototype.render = function (frame, renders, force) { | ||
if (force === void 0) { force = false; } | ||
} | ||
_needUpdateAt = [false, null, null, false]; | ||
// _frames: { [key: string]: (frame: FramePosition) => string } = {}; | ||
// [ accessor => [object, key], isFunction, computer ] | ||
_frames = []; | ||
_lastRenderFrame = null; | ||
render(frame, renders, force = false) { | ||
if (!force && | ||
@@ -340,15 +299,16 @@ this._lastRenderFrame === frame) { | ||
this._lastRenderFrame = frame; | ||
for (var i = this._frames.length - 1; i >= 0; i--) { | ||
var currentFrame = this._frames[i]; | ||
var accessor = currentFrame[0], isFunction = currentFrame[1], compute = currentFrame[2]; | ||
var accessorResult = accessor(); | ||
var object = accessorResult[0]; | ||
for (let i = this._frames.length - 1; i >= 0; i--) { | ||
const currentFrame = this._frames[i]; | ||
const accessor = currentFrame[0], isFunction = currentFrame[1], compute = currentFrame[2]; | ||
const accessorResult = accessor(); | ||
const object = accessorResult[0]; | ||
if (object == null) { | ||
continue; | ||
} | ||
var key = accessorResult[1]; | ||
const key = accessorResult[1]; | ||
if (isFunction) { | ||
renders.push([object, key, __spreadArray([ | ||
frame | ||
], __read(compute(frame).split(",").map(function (t) { return t.trim(); }).filter(function (t) { return t !== ""; })))]); | ||
renders.push([object, key, [ | ||
frame, | ||
...compute(frame).split(",").map(t => t.trim()).filter(t => t !== "") | ||
]]); | ||
} | ||
@@ -360,5 +320,4 @@ else { | ||
return renders; | ||
}; | ||
return ScrollObject; | ||
}()); | ||
} | ||
} | ||
function getFirstScrollParent(element) { | ||
@@ -374,18 +333,13 @@ if (element == null) { | ||
} | ||
var ScrollParent = (function () { | ||
function ScrollParent(el) { | ||
class ScrollParent { | ||
el; | ||
constructor(el) { | ||
this.el = el; | ||
this.children = []; | ||
this.trigger = 0; | ||
this.topOffset = 0; | ||
this.bottomOffset = 0; | ||
this._lastPosition = null; | ||
this._parents = []; | ||
el[SCROLL_PARENT] = this; | ||
this._computedStyle = window.getComputedStyle(this.el); | ||
} | ||
ScrollParent.prototype.refresh = function () { | ||
refresh() { | ||
this._lastPosition = null; | ||
this._parents = []; | ||
var el = this.el; | ||
let el = this.el; | ||
while (true) { | ||
@@ -396,3 +350,3 @@ el = getFirstScrollParent(el); | ||
} | ||
if (el !== this.el) { | ||
if (el !== this.el && el !== document.documentElement) { | ||
this._parents.push(el); | ||
@@ -403,27 +357,37 @@ } | ||
return this; | ||
}; | ||
ScrollParent.prototype._getRectTop = function () { | ||
var top = this.el.offsetTop; | ||
var lastParentScrollTop = null; | ||
for (var i = this._parents.length - 1; i >= 0; i--) { | ||
var parent_1 = this._parents[i]; | ||
top += parent_1.offsetTop - parent_1.scrollTop; | ||
if (parent_1.parentElement == null) { | ||
lastParentScrollTop = parent_1.scrollTop; | ||
} | ||
children = []; | ||
trigger = 0; | ||
topOffset = 0; | ||
bottomOffset = 0; | ||
_lastPosition = null; | ||
_computedStyle; | ||
_parents = []; | ||
_getRectTop() { | ||
let top = this.el.offsetTop; | ||
let lastParentScrollTop = null; | ||
for (let i = this._parents.length - 1; i >= 0; i--) { | ||
const parent = this._parents[i]; | ||
top += parent.offsetTop - parent.scrollTop; | ||
if (parent.parentElement == null) { | ||
lastParentScrollTop = parent.scrollTop; | ||
} | ||
} | ||
return top - (lastParentScrollTop == window.pageYOffset ? 0 : window.pageYOffset); | ||
}; | ||
ScrollParent.prototype.render = function (renders, force) { | ||
if (force === void 0) { force = false; } | ||
} | ||
; | ||
render(renders, force = false) { | ||
if (this.children.length === 0 || (this.el.clientHeight === 0 && this.el.clientWidth === 0)) { | ||
return renders; | ||
} | ||
var rectTop = this._getRectTop(); | ||
var rectBottom = rectTop + this.el.offsetHeight; | ||
var trigger = document.documentElement.clientHeight * this.trigger; | ||
var top = rectTop - this.topOffset; | ||
var bottom = rectBottom + this.bottomOffset; | ||
var position = (trigger - top) / (bottom - top); | ||
var actualPosition = position > 1 ? "after" : position < 0 ? "before" : position; | ||
// const rect: DOMRect = this.el.getBoundingClientRect(); | ||
// const rectTop: number = rect.top; | ||
// const rectBottom: number = rect.bottom; | ||
const rectTop = this._getRectTop(); | ||
const rectBottom = rectTop + this.el.offsetHeight; | ||
const trigger = document.documentElement.clientHeight * this.trigger; | ||
const top = rectTop - this.topOffset; | ||
const bottom = rectBottom + this.bottomOffset; | ||
const position = (trigger - top) / (bottom - top); | ||
const actualPosition = position > 1 ? "after" : position < 0 ? "before" : position; | ||
if (actualPosition === this._lastPosition && !force) { | ||
@@ -433,45 +397,45 @@ return renders; | ||
this._lastPosition = actualPosition; | ||
for (var i = this.children.length - 1; i >= 0; i--) { | ||
for (let i = this.children.length - 1; i >= 0; i--) { | ||
this.children[i].render(this._lastPosition, renders, force); | ||
} | ||
// this.el.dispatchEvent(new CustomEvent("render", { detail: { position: this._lastPosition }, bubbles: false })); | ||
return renders; | ||
}; | ||
ScrollParent.prototype.remove = function (obj) { | ||
var index = -1; | ||
if (this.children.some(function (child, i) { index = i; return child === obj || child.el === obj.el; })) { | ||
} | ||
remove(obj) { | ||
let index = -1; | ||
if (this.children.some((child, i) => { index = i; return child === obj || child.el === obj.el; })) { | ||
this.children.splice(index, 1); | ||
this._lastPosition = null; | ||
} | ||
}; | ||
ScrollParent.prototype.add = function (obj) { | ||
} | ||
add(obj) { | ||
this.remove(obj); | ||
this.children.push(obj); | ||
this._lastPosition = null; | ||
}; | ||
return ScrollParent; | ||
}()); | ||
var baseScrollParent = new ScrollParent(document.documentElement); | ||
} | ||
} | ||
const baseScrollParent = new ScrollParent(document.documentElement); | ||
document.body[SCROLL_PARENT] = baseScrollParent; | ||
var scrollParents = [ | ||
const scrollParents = [ | ||
baseScrollParent | ||
]; | ||
function render() { | ||
var renders = []; | ||
for (var i = scrollParents.length - 1; i >= 0; i--) { | ||
const renders = []; | ||
for (let i = scrollParents.length - 1; i >= 0; i--) { | ||
scrollParents[i].render(renders); | ||
} | ||
for (var i = renders.length - 1; i >= 0; i--) { | ||
var render_1 = renders[i]; | ||
var result = render_1[2]; | ||
var object = render_1[0]; | ||
for (let i = renders.length - 1; i >= 0; i--) { | ||
const render = renders[i]; | ||
const result = render[2]; | ||
const object = render[0]; | ||
if (Array.isArray(result)) { | ||
object[render_1[1]].apply(object, result); | ||
object[render[1]].apply(object, result); | ||
} | ||
else { | ||
object[render_1[1]] = result; | ||
object[render[1]] = result; | ||
} | ||
} | ||
} | ||
var stop = false; | ||
var started = false; | ||
let stop = false; | ||
let started = false; | ||
function startLoop() { | ||
@@ -498,14 +462,13 @@ stop = false; | ||
} | ||
var parent = new ScrollParent(element); | ||
const parent = new ScrollParent(element); | ||
scrollParents.push(parent); | ||
return parent; | ||
} | ||
function parse(element, parent, subtree) { | ||
if (subtree === void 0) { subtree = true; } | ||
var scrollOptions = null; | ||
Array.prototype.forEach.call(element.attributes, function (attr) { | ||
function parse(element, parent, subtree = true) { | ||
let scrollOptions = null; | ||
Array.prototype.forEach.call(element.attributes, (attr) => { | ||
if (!attr.name.match(/^data-scroll[\-\.]/)) { | ||
return; | ||
} | ||
var data = attr.name.substr(11); | ||
const data = attr.name.substr(11); | ||
if (data === "-parent") { | ||
@@ -515,3 +478,3 @@ parent = getRefreshedParent(element); | ||
else if (data === "-trigger") { | ||
var trigger = parseFloat(attr.value); | ||
let trigger = parseFloat(attr.value); | ||
if (!isNaN(trigger)) { | ||
@@ -523,3 +486,3 @@ parent = getRefreshedParent(element); | ||
else if (data === "-bottom") { | ||
var bottom = parseFloat(attr.value); | ||
let bottom = parseFloat(attr.value); | ||
if (!isNaN(bottom)) { | ||
@@ -531,10 +494,10 @@ parent = getRefreshedParent(element); | ||
else if (data === "-top") { | ||
var top_1 = parseFloat(attr.value); | ||
if (!isNaN(top_1)) { | ||
let top = parseFloat(attr.value); | ||
if (!isNaN(top)) { | ||
parent = getRefreshedParent(element); | ||
parent.topOffset = top_1; | ||
parent.topOffset = top; | ||
} | ||
} | ||
else { | ||
var dataSplit = data.split("-"); | ||
const dataSplit = data.split("-"); | ||
dataSplit.shift(); | ||
@@ -547,3 +510,4 @@ if (dataSplit.length > 2 || dataSplit.length === 0) { | ||
} | ||
var propertyName = dataSplit[0].replace(/(?:^|[\Wa-zA-Z])(_[a-zA-Z])/, function (_, g) { | ||
// convert "_[a-z]" to "[A-Z]" and "__" to "_" | ||
const propertyName = dataSplit[0].replace(/(?:^|[\Wa-zA-Z])(_[a-zA-Z])/, function (_, g) { | ||
return _.replace(g, g[1].toUpperCase()); | ||
@@ -555,3 +519,3 @@ }).replace("__", "_"); | ||
else { | ||
var frame = parseFloat(dataSplit[1]); | ||
const frame = parseFloat(dataSplit[1]); | ||
if (!isNaN(frame)) { | ||
@@ -584,9 +548,8 @@ scrollOptions[propertyName] = (scrollOptions[propertyName] || []).concat([[frame, attr.value]]); | ||
if (subtree) { | ||
Array.prototype.forEach.call(element.children, function (child) { parse(child, parent); }); | ||
Array.prototype.forEach.call(element.children, child => { parse(child, parent); }); | ||
} | ||
} | ||
function add(element, subtree) { | ||
if (subtree === void 0) { subtree = true; } | ||
var parent = element; | ||
var firstScrollParent = element[SCROLL_PARENT]; | ||
function add(element, subtree = true) { | ||
let parent = element; | ||
let firstScrollParent = element[SCROLL_PARENT]; | ||
while (parent !== document.body && parent != null) { | ||
@@ -610,14 +573,13 @@ parent = parent.parentElement; | ||
} | ||
function remove(element, renderFrame) { | ||
if (renderFrame === void 0) { renderFrame = null; } | ||
var scrollParent = element[SCROLL_PARENT]; | ||
var scrollObject = element[SCROLL_OBJECT]; | ||
function remove(element, renderFrame = null) { | ||
let scrollParent = element[SCROLL_PARENT]; | ||
let scrollObject = element[SCROLL_OBJECT]; | ||
if (scrollParent != null) { | ||
if (scrollParent.el === element) { | ||
var index_1 = -1; | ||
if (scrollParents.some(function (p, i) { | ||
index_1 = i; | ||
let index = -1; | ||
if (scrollParents.some((p, i) => { | ||
index = i; | ||
return p === scrollParent; | ||
})) { | ||
scrollParents.splice(index_1, 1); | ||
scrollParents.splice(index, 1); | ||
} | ||
@@ -628,7 +590,7 @@ } | ||
if (renderFrame != null) { | ||
var renders = []; | ||
const renders = []; | ||
scrollObject.render(renderFrame, renders, true); | ||
for (var i = renders.length - 1; i >= 0; i--) { | ||
var render_2 = renders[i]; | ||
render_2[0][render_2[1]] = render_2[2]; | ||
for (let i = renders.length - 1; i >= 0; i--) { | ||
const render = renders[i]; | ||
render[0][render[1]] = render[2]; | ||
} | ||
@@ -640,10 +602,10 @@ } | ||
} | ||
Array.prototype.forEach.call(element.children, function (child) { | ||
Array.prototype.forEach.call(element.children, child => { | ||
remove(child, renderFrame); | ||
}); | ||
if (scrollParent === baseScrollParent && baseScrollParent.children.length === 0) { | ||
var index_2 = -1; | ||
if (scrollParents.some(function (p, i) { | ||
let index = -1; | ||
if (scrollParents.some((p, i) => { | ||
if (p === baseScrollParent) { | ||
index_2 = i; | ||
index = i; | ||
return true; | ||
@@ -653,3 +615,3 @@ } | ||
})) { | ||
scrollParents.splice(index_2, 1); | ||
scrollParents.splice(index, 1); | ||
} | ||
@@ -656,0 +618,0 @@ } |
@@ -5,51 +5,13 @@ (function (global, factory) { | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.dataScrollAnimation = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
})(this, (function (exports) { 'use strict'; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
function __read(o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
} | ||
function __spreadArray(to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
} | ||
var EXTRAPOLATE = Symbol("extrapolate"); | ||
const EXTRAPOLATE = Symbol("extrapolate"); | ||
function computeFrames(frames) { | ||
var staticString = null; | ||
var indexes = []; | ||
var frameNumbers = []; | ||
var frameValues = []; | ||
var beforeValue = null; | ||
var afterValue = null; | ||
var needUpdateAt = [false, null, null, false]; | ||
let staticString = null; | ||
let indexes = []; | ||
let frameNumbers = []; | ||
let frameValues = []; | ||
let beforeValue = null; | ||
let afterValue = null; | ||
const needUpdateAt = [false, null, null, false]; | ||
function getNearestLeftIndexOf(frameNumber) { | ||
@@ -59,4 +21,4 @@ if (frameNumbers.length === 0) { | ||
} | ||
var leftIndex = 0; | ||
for (var i = 1; i < frameNumbers.length; i++) { | ||
let leftIndex = 0; | ||
for (let i = 1; i < frameNumbers.length; i++) { | ||
if (frameNumbers[i] > frameNumber) { | ||
@@ -70,5 +32,5 @@ break; | ||
{ | ||
var constants_1 = false; | ||
frames.sort(function (a, b) { | ||
var result; | ||
let constants = false; | ||
frames.sort((a, b) => { | ||
let result; | ||
if (a[0] === "before") { | ||
@@ -91,3 +53,3 @@ result = b[0] === "after" ? -1 : b[0] === "before" ? 0 : 1; | ||
}); | ||
frames.forEach(function (frame) { | ||
frames.forEach(frame => { | ||
if (frame[1] === EXTRAPOLATE) { | ||
@@ -109,3 +71,3 @@ if (frame[0] !== "after" && frame[0] !== "before") { | ||
} | ||
var thisStaticString; | ||
let thisStaticString; | ||
frameNumbers.push(frame[0]); | ||
@@ -118,3 +80,3 @@ if (needUpdateAt[1] == null || needUpdateAt[1] > frame[0]) { | ||
} | ||
if (!constants_1) { | ||
if (!constants) { | ||
thisStaticString = frame[1].trim() | ||
@@ -125,4 +87,4 @@ .replace(/[ ]*,[ ]*/g, ",") | ||
.replace(/(?:\)[ ]{2,}(?! \w))/g, ")"); | ||
var thisStaticStringEmpty = thisStaticString.replace(/-?\d+(?:\.\d+)?/g, ""); | ||
var wasStaticStringNULL = staticString == null; | ||
const thisStaticStringEmpty = thisStaticString.replace(/-?\d+(?:\.\d+)?/g, ""); | ||
const wasStaticStringNULL = staticString == null; | ||
if (wasStaticStringNULL) { | ||
@@ -132,9 +94,9 @@ staticString = thisStaticStringEmpty; | ||
if (thisStaticStringEmpty !== staticString) { | ||
constants_1 = true; | ||
constants = true; | ||
} | ||
if (!constants_1) { | ||
var match = void 0; | ||
var thisValues = []; | ||
if (!constants) { | ||
let match; | ||
const thisValues = []; | ||
while (match = (/(?:-?\d+(?:\.\d+)?)/).exec(thisStaticString)) { | ||
var thisStaticStringArray = thisStaticString.split(""); | ||
let thisStaticStringArray = thisStaticString.split(""); | ||
thisStaticStringArray.splice(match.index, match[0].length); | ||
@@ -151,5 +113,5 @@ thisStaticString = thisStaticStringArray.join(""); | ||
}); | ||
if (constants_1) { | ||
if (constants) { | ||
return { | ||
compute: function (frameNumber) { | ||
compute: (frameNumber) => { | ||
if (frameNumber === "before") { | ||
@@ -167,3 +129,3 @@ if (beforeValue != null) { | ||
} | ||
var index = getNearestLeftIndexOf(frameNumber); | ||
const index = getNearestLeftIndexOf(frameNumber); | ||
if (index === -1) { | ||
@@ -174,3 +136,3 @@ return ""; | ||
}, | ||
needUpdateAt: needUpdateAt | ||
needUpdateAt | ||
}; | ||
@@ -181,3 +143,3 @@ } | ||
return { | ||
compute: function (frameNumber) { | ||
compute: (frameNumber) => { | ||
if (frameNumber === "before" && beforeValue != null) { | ||
@@ -194,4 +156,4 @@ return beforeValue; | ||
} | ||
var staticStringArray = staticString.split("").reduce(function (prev, current, index) { | ||
if (indexes.some(function (i) { return i === index; })) { | ||
const staticStringArray = staticString.split("").reduce((prev, current, index) => { | ||
if (indexes.some(i => i === index)) { | ||
prev.push(""); | ||
@@ -203,6 +165,6 @@ } | ||
function constructString(values) { | ||
var constructedString = ""; | ||
var index = 0; | ||
var indexesLength = indexes.length; | ||
for (var i = 0; i < indexesLength; i++) { | ||
let constructedString = ""; | ||
let index = 0; | ||
const indexesLength = indexes.length; | ||
for (let i = 0; i < indexesLength; i++) { | ||
constructedString += staticStringArray[index] + values[i].toString(); | ||
@@ -217,3 +179,3 @@ index++; | ||
return { | ||
compute: function (frameNumber) { | ||
compute: (frameNumber) => { | ||
if (frameNumber === "before") { | ||
@@ -232,3 +194,3 @@ if (beforeValue != null) { | ||
frameNumber = Math.min(Math.max(0, frameNumber), 1); | ||
var index = getNearestLeftIndexOf(frameNumber); | ||
const index = getNearestLeftIndexOf(frameNumber); | ||
if (index === -1) { | ||
@@ -240,12 +202,12 @@ return ""; | ||
} | ||
var left = frameNumbers[index]; | ||
var right = frameNumbers[index + 1]; | ||
var perc = (frameNumber - left) / (right - left); | ||
var computedValues = []; | ||
var frameValue = frameValues[index]; | ||
var nextFrameValue = frameValues[index + 1]; | ||
var frameValueLength = frameValue.length; | ||
for (var v_index = 0; v_index < frameValueLength; v_index++) { | ||
var value = frameValue[v_index]; | ||
var nextValue = nextFrameValue[v_index]; | ||
const left = frameNumbers[index]; | ||
const right = frameNumbers[index + 1]; | ||
const perc = (frameNumber - left) / (right - left); | ||
const computedValues = []; | ||
const frameValue = frameValues[index]; | ||
const nextFrameValue = frameValues[index + 1]; | ||
const frameValueLength = frameValue.length; | ||
for (let v_index = 0; v_index < frameValueLength; v_index++) { | ||
const value = frameValue[v_index]; | ||
const nextValue = nextFrameValue[v_index]; | ||
computedValues.push(value + ((nextValue - value) * perc)); | ||
@@ -255,30 +217,27 @@ } | ||
}, | ||
needUpdateAt: needUpdateAt | ||
needUpdateAt | ||
}; | ||
} | ||
var SCROLL_OBJECT = Symbol("scroll-object"); | ||
var SCROLL_PARENT = Symbol("scroll-parent"); | ||
var ScrollObject = (function () { | ||
function ScrollObject(el, frames) { | ||
const SCROLL_OBJECT = Symbol("scroll-object"); | ||
const SCROLL_PARENT = Symbol("scroll-parent"); | ||
class ScrollObject { | ||
el; | ||
constructor(el, frames) { | ||
this.el = el; | ||
this._needUpdateAt = [false, null, null, false]; | ||
this._frames = []; | ||
this._lastRenderFrame = null; | ||
this.refresh(frames); | ||
} | ||
ScrollObject.prototype.refresh = function (frames) { | ||
var _this = this; | ||
refresh(frames) { | ||
this.el[SCROLL_OBJECT] = this; | ||
this._frames = []; | ||
var _loop_1 = function (key) { | ||
for (let key in frames) { | ||
if (!Object.prototype.hasOwnProperty.call(frames, key)) { | ||
return "continue"; | ||
continue; | ||
} | ||
var splitKey = key.split("."); | ||
var _a = __read(splitKey.pop().match(/^([^\(\)]*)(\(\))?$/) || [], 3), isValid = _a[0], lastKey = _a[1], isFunction = _a[2]; | ||
const splitKey = key.split("."); | ||
const [isValid, lastKey, isFunction] = splitKey.pop().match(/^([^\(\)]*)(\(\))?$/) || []; | ||
if (!isValid) { | ||
return "continue"; | ||
continue; | ||
} | ||
var _b = computeFrames(frames[key]), compute = _b.compute, needUpdateAt = _b.needUpdateAt; | ||
if (isFunction && needUpdateAt.every(function (value, index) { | ||
const { compute, needUpdateAt } = computeFrames(frames[key]); | ||
if (isFunction && needUpdateAt.every((value, index) => { | ||
if (index === 0 || index === 3) { | ||
@@ -294,6 +253,6 @@ return value === false; | ||
} | ||
var keyLength = splitKey.length; | ||
var accessor = function () { | ||
var lastObject = _this.el; | ||
for (var i = 0; i < keyLength; i++) { | ||
const keyLength = splitKey.length; | ||
const accessor = () => { | ||
let lastObject = this.el; | ||
for (let i = 0; i < keyLength; i++) { | ||
if (lastObject == null) { | ||
@@ -306,19 +265,15 @@ return [null, ""]; | ||
}; | ||
this_1._frames.push([accessor, isFunction != null, compute]); | ||
this_1._needUpdateAt[0] = this_1._needUpdateAt[0] || needUpdateAt[0]; | ||
if (this_1._needUpdateAt[1] !== needUpdateAt[1] && | ||
needUpdateAt[1] != null && (this_1._needUpdateAt[1] == null || | ||
needUpdateAt[1] < this_1._needUpdateAt[1])) { | ||
this_1._needUpdateAt[1] = needUpdateAt[1]; | ||
this._frames.push([accessor, isFunction != null, compute]); | ||
this._needUpdateAt[0] = this._needUpdateAt[0] || needUpdateAt[0]; | ||
if (this._needUpdateAt[1] !== needUpdateAt[1] && | ||
needUpdateAt[1] != null && (this._needUpdateAt[1] == null || | ||
needUpdateAt[1] < this._needUpdateAt[1])) { | ||
this._needUpdateAt[1] = needUpdateAt[1]; | ||
} | ||
if (this_1._needUpdateAt[2] !== needUpdateAt[2] && | ||
needUpdateAt[2] != null && (this_1._needUpdateAt[2] == null || | ||
needUpdateAt[2] > this_1._needUpdateAt[2])) { | ||
this_1._needUpdateAt[2] = needUpdateAt[2]; | ||
if (this._needUpdateAt[2] !== needUpdateAt[2] && | ||
needUpdateAt[2] != null && (this._needUpdateAt[2] == null || | ||
needUpdateAt[2] > this._needUpdateAt[2])) { | ||
this._needUpdateAt[2] = needUpdateAt[2]; | ||
} | ||
this_1._needUpdateAt[3] = this_1._needUpdateAt[3] || needUpdateAt[3]; | ||
}; | ||
var this_1 = this; | ||
for (var key in frames) { | ||
_loop_1(key); | ||
this._needUpdateAt[3] = this._needUpdateAt[3] || needUpdateAt[3]; | ||
} | ||
@@ -328,5 +283,9 @@ this._lastRenderFrame = null; | ||
return this; | ||
}; | ||
ScrollObject.prototype.render = function (frame, renders, force) { | ||
if (force === void 0) { force = false; } | ||
} | ||
_needUpdateAt = [false, null, null, false]; | ||
// _frames: { [key: string]: (frame: FramePosition) => string } = {}; | ||
// [ accessor => [object, key], isFunction, computer ] | ||
_frames = []; | ||
_lastRenderFrame = null; | ||
render(frame, renders, force = false) { | ||
if (!force && | ||
@@ -347,15 +306,16 @@ this._lastRenderFrame === frame) { | ||
this._lastRenderFrame = frame; | ||
for (var i = this._frames.length - 1; i >= 0; i--) { | ||
var currentFrame = this._frames[i]; | ||
var accessor = currentFrame[0], isFunction = currentFrame[1], compute = currentFrame[2]; | ||
var accessorResult = accessor(); | ||
var object = accessorResult[0]; | ||
for (let i = this._frames.length - 1; i >= 0; i--) { | ||
const currentFrame = this._frames[i]; | ||
const accessor = currentFrame[0], isFunction = currentFrame[1], compute = currentFrame[2]; | ||
const accessorResult = accessor(); | ||
const object = accessorResult[0]; | ||
if (object == null) { | ||
continue; | ||
} | ||
var key = accessorResult[1]; | ||
const key = accessorResult[1]; | ||
if (isFunction) { | ||
renders.push([object, key, __spreadArray([ | ||
frame | ||
], __read(compute(frame).split(",").map(function (t) { return t.trim(); }).filter(function (t) { return t !== ""; })))]); | ||
renders.push([object, key, [ | ||
frame, | ||
...compute(frame).split(",").map(t => t.trim()).filter(t => t !== "") | ||
]]); | ||
} | ||
@@ -367,5 +327,4 @@ else { | ||
return renders; | ||
}; | ||
return ScrollObject; | ||
}()); | ||
} | ||
} | ||
function getFirstScrollParent(element) { | ||
@@ -381,18 +340,13 @@ if (element == null) { | ||
} | ||
var ScrollParent = (function () { | ||
function ScrollParent(el) { | ||
class ScrollParent { | ||
el; | ||
constructor(el) { | ||
this.el = el; | ||
this.children = []; | ||
this.trigger = 0; | ||
this.topOffset = 0; | ||
this.bottomOffset = 0; | ||
this._lastPosition = null; | ||
this._parents = []; | ||
el[SCROLL_PARENT] = this; | ||
this._computedStyle = window.getComputedStyle(this.el); | ||
} | ||
ScrollParent.prototype.refresh = function () { | ||
refresh() { | ||
this._lastPosition = null; | ||
this._parents = []; | ||
var el = this.el; | ||
let el = this.el; | ||
while (true) { | ||
@@ -403,3 +357,3 @@ el = getFirstScrollParent(el); | ||
} | ||
if (el !== this.el) { | ||
if (el !== this.el && el !== document.documentElement) { | ||
this._parents.push(el); | ||
@@ -410,27 +364,37 @@ } | ||
return this; | ||
}; | ||
ScrollParent.prototype._getRectTop = function () { | ||
var top = this.el.offsetTop; | ||
var lastParentScrollTop = null; | ||
for (var i = this._parents.length - 1; i >= 0; i--) { | ||
var parent_1 = this._parents[i]; | ||
top += parent_1.offsetTop - parent_1.scrollTop; | ||
if (parent_1.parentElement == null) { | ||
lastParentScrollTop = parent_1.scrollTop; | ||
} | ||
children = []; | ||
trigger = 0; | ||
topOffset = 0; | ||
bottomOffset = 0; | ||
_lastPosition = null; | ||
_computedStyle; | ||
_parents = []; | ||
_getRectTop() { | ||
let top = this.el.offsetTop; | ||
let lastParentScrollTop = null; | ||
for (let i = this._parents.length - 1; i >= 0; i--) { | ||
const parent = this._parents[i]; | ||
top += parent.offsetTop - parent.scrollTop; | ||
if (parent.parentElement == null) { | ||
lastParentScrollTop = parent.scrollTop; | ||
} | ||
} | ||
return top - (lastParentScrollTop == window.pageYOffset ? 0 : window.pageYOffset); | ||
}; | ||
ScrollParent.prototype.render = function (renders, force) { | ||
if (force === void 0) { force = false; } | ||
} | ||
; | ||
render(renders, force = false) { | ||
if (this.children.length === 0 || (this.el.clientHeight === 0 && this.el.clientWidth === 0)) { | ||
return renders; | ||
} | ||
var rectTop = this._getRectTop(); | ||
var rectBottom = rectTop + this.el.offsetHeight; | ||
var trigger = document.documentElement.clientHeight * this.trigger; | ||
var top = rectTop - this.topOffset; | ||
var bottom = rectBottom + this.bottomOffset; | ||
var position = (trigger - top) / (bottom - top); | ||
var actualPosition = position > 1 ? "after" : position < 0 ? "before" : position; | ||
// const rect: DOMRect = this.el.getBoundingClientRect(); | ||
// const rectTop: number = rect.top; | ||
// const rectBottom: number = rect.bottom; | ||
const rectTop = this._getRectTop(); | ||
const rectBottom = rectTop + this.el.offsetHeight; | ||
const trigger = document.documentElement.clientHeight * this.trigger; | ||
const top = rectTop - this.topOffset; | ||
const bottom = rectBottom + this.bottomOffset; | ||
const position = (trigger - top) / (bottom - top); | ||
const actualPosition = position > 1 ? "after" : position < 0 ? "before" : position; | ||
if (actualPosition === this._lastPosition && !force) { | ||
@@ -440,45 +404,45 @@ return renders; | ||
this._lastPosition = actualPosition; | ||
for (var i = this.children.length - 1; i >= 0; i--) { | ||
for (let i = this.children.length - 1; i >= 0; i--) { | ||
this.children[i].render(this._lastPosition, renders, force); | ||
} | ||
// this.el.dispatchEvent(new CustomEvent("render", { detail: { position: this._lastPosition }, bubbles: false })); | ||
return renders; | ||
}; | ||
ScrollParent.prototype.remove = function (obj) { | ||
var index = -1; | ||
if (this.children.some(function (child, i) { index = i; return child === obj || child.el === obj.el; })) { | ||
} | ||
remove(obj) { | ||
let index = -1; | ||
if (this.children.some((child, i) => { index = i; return child === obj || child.el === obj.el; })) { | ||
this.children.splice(index, 1); | ||
this._lastPosition = null; | ||
} | ||
}; | ||
ScrollParent.prototype.add = function (obj) { | ||
} | ||
add(obj) { | ||
this.remove(obj); | ||
this.children.push(obj); | ||
this._lastPosition = null; | ||
}; | ||
return ScrollParent; | ||
}()); | ||
var baseScrollParent = new ScrollParent(document.documentElement); | ||
} | ||
} | ||
const baseScrollParent = new ScrollParent(document.documentElement); | ||
document.body[SCROLL_PARENT] = baseScrollParent; | ||
var scrollParents = [ | ||
const scrollParents = [ | ||
baseScrollParent | ||
]; | ||
function render() { | ||
var renders = []; | ||
for (var i = scrollParents.length - 1; i >= 0; i--) { | ||
const renders = []; | ||
for (let i = scrollParents.length - 1; i >= 0; i--) { | ||
scrollParents[i].render(renders); | ||
} | ||
for (var i = renders.length - 1; i >= 0; i--) { | ||
var render_1 = renders[i]; | ||
var result = render_1[2]; | ||
var object = render_1[0]; | ||
for (let i = renders.length - 1; i >= 0; i--) { | ||
const render = renders[i]; | ||
const result = render[2]; | ||
const object = render[0]; | ||
if (Array.isArray(result)) { | ||
object[render_1[1]].apply(object, result); | ||
object[render[1]].apply(object, result); | ||
} | ||
else { | ||
object[render_1[1]] = result; | ||
object[render[1]] = result; | ||
} | ||
} | ||
} | ||
var stop = false; | ||
var started = false; | ||
let stop = false; | ||
let started = false; | ||
function startLoop() { | ||
@@ -505,14 +469,13 @@ stop = false; | ||
} | ||
var parent = new ScrollParent(element); | ||
const parent = new ScrollParent(element); | ||
scrollParents.push(parent); | ||
return parent; | ||
} | ||
function parse(element, parent, subtree) { | ||
if (subtree === void 0) { subtree = true; } | ||
var scrollOptions = null; | ||
Array.prototype.forEach.call(element.attributes, function (attr) { | ||
function parse(element, parent, subtree = true) { | ||
let scrollOptions = null; | ||
Array.prototype.forEach.call(element.attributes, (attr) => { | ||
if (!attr.name.match(/^data-scroll[\-\.]/)) { | ||
return; | ||
} | ||
var data = attr.name.substr(11); | ||
const data = attr.name.substr(11); | ||
if (data === "-parent") { | ||
@@ -522,3 +485,3 @@ parent = getRefreshedParent(element); | ||
else if (data === "-trigger") { | ||
var trigger = parseFloat(attr.value); | ||
let trigger = parseFloat(attr.value); | ||
if (!isNaN(trigger)) { | ||
@@ -530,3 +493,3 @@ parent = getRefreshedParent(element); | ||
else if (data === "-bottom") { | ||
var bottom = parseFloat(attr.value); | ||
let bottom = parseFloat(attr.value); | ||
if (!isNaN(bottom)) { | ||
@@ -538,10 +501,10 @@ parent = getRefreshedParent(element); | ||
else if (data === "-top") { | ||
var top_1 = parseFloat(attr.value); | ||
if (!isNaN(top_1)) { | ||
let top = parseFloat(attr.value); | ||
if (!isNaN(top)) { | ||
parent = getRefreshedParent(element); | ||
parent.topOffset = top_1; | ||
parent.topOffset = top; | ||
} | ||
} | ||
else { | ||
var dataSplit = data.split("-"); | ||
const dataSplit = data.split("-"); | ||
dataSplit.shift(); | ||
@@ -554,3 +517,4 @@ if (dataSplit.length > 2 || dataSplit.length === 0) { | ||
} | ||
var propertyName = dataSplit[0].replace(/(?:^|[\Wa-zA-Z])(_[a-zA-Z])/, function (_, g) { | ||
// convert "_[a-z]" to "[A-Z]" and "__" to "_" | ||
const propertyName = dataSplit[0].replace(/(?:^|[\Wa-zA-Z])(_[a-zA-Z])/, function (_, g) { | ||
return _.replace(g, g[1].toUpperCase()); | ||
@@ -562,3 +526,3 @@ }).replace("__", "_"); | ||
else { | ||
var frame = parseFloat(dataSplit[1]); | ||
const frame = parseFloat(dataSplit[1]); | ||
if (!isNaN(frame)) { | ||
@@ -591,9 +555,8 @@ scrollOptions[propertyName] = (scrollOptions[propertyName] || []).concat([[frame, attr.value]]); | ||
if (subtree) { | ||
Array.prototype.forEach.call(element.children, function (child) { parse(child, parent); }); | ||
Array.prototype.forEach.call(element.children, child => { parse(child, parent); }); | ||
} | ||
} | ||
function add(element, subtree) { | ||
if (subtree === void 0) { subtree = true; } | ||
var parent = element; | ||
var firstScrollParent = element[SCROLL_PARENT]; | ||
function add(element, subtree = true) { | ||
let parent = element; | ||
let firstScrollParent = element[SCROLL_PARENT]; | ||
while (parent !== document.body && parent != null) { | ||
@@ -617,14 +580,13 @@ parent = parent.parentElement; | ||
} | ||
function remove(element, renderFrame) { | ||
if (renderFrame === void 0) { renderFrame = null; } | ||
var scrollParent = element[SCROLL_PARENT]; | ||
var scrollObject = element[SCROLL_OBJECT]; | ||
function remove(element, renderFrame = null) { | ||
let scrollParent = element[SCROLL_PARENT]; | ||
let scrollObject = element[SCROLL_OBJECT]; | ||
if (scrollParent != null) { | ||
if (scrollParent.el === element) { | ||
var index_1 = -1; | ||
if (scrollParents.some(function (p, i) { | ||
index_1 = i; | ||
let index = -1; | ||
if (scrollParents.some((p, i) => { | ||
index = i; | ||
return p === scrollParent; | ||
})) { | ||
scrollParents.splice(index_1, 1); | ||
scrollParents.splice(index, 1); | ||
} | ||
@@ -635,7 +597,7 @@ } | ||
if (renderFrame != null) { | ||
var renders = []; | ||
const renders = []; | ||
scrollObject.render(renderFrame, renders, true); | ||
for (var i = renders.length - 1; i >= 0; i--) { | ||
var render_2 = renders[i]; | ||
render_2[0][render_2[1]] = render_2[2]; | ||
for (let i = renders.length - 1; i >= 0; i--) { | ||
const render = renders[i]; | ||
render[0][render[1]] = render[2]; | ||
} | ||
@@ -647,10 +609,10 @@ } | ||
} | ||
Array.prototype.forEach.call(element.children, function (child) { | ||
Array.prototype.forEach.call(element.children, child => { | ||
remove(child, renderFrame); | ||
}); | ||
if (scrollParent === baseScrollParent && baseScrollParent.children.length === 0) { | ||
var index_2 = -1; | ||
if (scrollParents.some(function (p, i) { | ||
let index = -1; | ||
if (scrollParents.some((p, i) => { | ||
if (p === baseScrollParent) { | ||
index_2 = i; | ||
index = i; | ||
return true; | ||
@@ -660,3 +622,3 @@ } | ||
})) { | ||
scrollParents.splice(index_2, 1); | ||
scrollParents.splice(index, 1); | ||
} | ||
@@ -674,2 +636,2 @@ } | ||
}))); | ||
})); |
{ | ||
"name": "data-scroll-animation", | ||
"version": "1.2.2", | ||
"version": "1.3.0", | ||
"description": "", | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^17.1.0", | ||
"@rollup/plugin-node-resolve": "^11.2.1", | ||
"@rollup/plugin-typescript": "^8.2.1", | ||
"rollup": "^2.44.0", | ||
"tslib": "^2.2.0", | ||
"typescript": "^4.2.3" | ||
"@rollup/plugin-commonjs": "^21.0.0", | ||
"@rollup/plugin-node-resolve": "^13.0.5", | ||
"rollup": "^2.58.0", | ||
"rollup-plugin-ts": "^1.4.7" | ||
}, | ||
@@ -13,0 +11,0 @@ "scripts": {}, |
const commonjs = require('@rollup/plugin-commonjs'); | ||
const typescript = require('@rollup/plugin-typescript'); | ||
const nodeResolve = require("@rollup/plugin-node-resolve").default; | ||
const typescript = require('rollup-plugin-ts'); | ||
const { nodeResolve } = require("@rollup/plugin-node-resolve"); | ||
export default [ | ||
@@ -6,0 +7,0 @@ { |
@@ -349,3 +349,3 @@ const EXTRAPOLATE: unique symbol = Symbol("extrapolate"); | ||
} | ||
if (el !== this.el) { | ||
if (el !== this.el && el !== document.documentElement) { | ||
this._parents.push(el as HTMLElement); | ||
@@ -352,0 +352,0 @@ } |
(function (factory) { | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
factory(); | ||
}((function () { 'use strict'; | ||
})((function () { 'use strict'; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
function __read(o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
} | ||
function __spreadArray(to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
} | ||
var EXTRAPOLATE = Symbol("extrapolate"); | ||
const EXTRAPOLATE = Symbol("extrapolate"); | ||
function computeFrames(frames) { | ||
var staticString = null; | ||
var indexes = []; | ||
var frameNumbers = []; | ||
var frameValues = []; | ||
var beforeValue = null; | ||
var afterValue = null; | ||
var needUpdateAt = [false, null, null, false]; | ||
let staticString = null; | ||
let indexes = []; | ||
let frameNumbers = []; | ||
let frameValues = []; | ||
let beforeValue = null; | ||
let afterValue = null; | ||
const needUpdateAt = [false, null, null, false]; | ||
function getNearestLeftIndexOf(frameNumber) { | ||
@@ -57,4 +19,4 @@ if (frameNumbers.length === 0) { | ||
} | ||
var leftIndex = 0; | ||
for (var i = 1; i < frameNumbers.length; i++) { | ||
let leftIndex = 0; | ||
for (let i = 1; i < frameNumbers.length; i++) { | ||
if (frameNumbers[i] > frameNumber) { | ||
@@ -68,5 +30,5 @@ break; | ||
{ | ||
var constants_1 = false; | ||
frames.sort(function (a, b) { | ||
var result; | ||
let constants = false; | ||
frames.sort((a, b) => { | ||
let result; | ||
if (a[0] === "before") { | ||
@@ -89,3 +51,3 @@ result = b[0] === "after" ? -1 : b[0] === "before" ? 0 : 1; | ||
}); | ||
frames.forEach(function (frame) { | ||
frames.forEach(frame => { | ||
if (frame[1] === EXTRAPOLATE) { | ||
@@ -107,3 +69,3 @@ if (frame[0] !== "after" && frame[0] !== "before") { | ||
} | ||
var thisStaticString; | ||
let thisStaticString; | ||
frameNumbers.push(frame[0]); | ||
@@ -116,3 +78,3 @@ if (needUpdateAt[1] == null || needUpdateAt[1] > frame[0]) { | ||
} | ||
if (!constants_1) { | ||
if (!constants) { | ||
thisStaticString = frame[1].trim() | ||
@@ -123,4 +85,4 @@ .replace(/[ ]*,[ ]*/g, ",") | ||
.replace(/(?:\)[ ]{2,}(?! \w))/g, ")"); | ||
var thisStaticStringEmpty = thisStaticString.replace(/-?\d+(?:\.\d+)?/g, ""); | ||
var wasStaticStringNULL = staticString == null; | ||
const thisStaticStringEmpty = thisStaticString.replace(/-?\d+(?:\.\d+)?/g, ""); | ||
const wasStaticStringNULL = staticString == null; | ||
if (wasStaticStringNULL) { | ||
@@ -130,9 +92,9 @@ staticString = thisStaticStringEmpty; | ||
if (thisStaticStringEmpty !== staticString) { | ||
constants_1 = true; | ||
constants = true; | ||
} | ||
if (!constants_1) { | ||
var match = void 0; | ||
var thisValues = []; | ||
if (!constants) { | ||
let match; | ||
const thisValues = []; | ||
while (match = (/(?:-?\d+(?:\.\d+)?)/).exec(thisStaticString)) { | ||
var thisStaticStringArray = thisStaticString.split(""); | ||
let thisStaticStringArray = thisStaticString.split(""); | ||
thisStaticStringArray.splice(match.index, match[0].length); | ||
@@ -149,5 +111,5 @@ thisStaticString = thisStaticStringArray.join(""); | ||
}); | ||
if (constants_1) { | ||
if (constants) { | ||
return { | ||
compute: function (frameNumber) { | ||
compute: (frameNumber) => { | ||
if (frameNumber === "before") { | ||
@@ -165,3 +127,3 @@ if (beforeValue != null) { | ||
} | ||
var index = getNearestLeftIndexOf(frameNumber); | ||
const index = getNearestLeftIndexOf(frameNumber); | ||
if (index === -1) { | ||
@@ -172,3 +134,3 @@ return ""; | ||
}, | ||
needUpdateAt: needUpdateAt | ||
needUpdateAt | ||
}; | ||
@@ -179,3 +141,3 @@ } | ||
return { | ||
compute: function (frameNumber) { | ||
compute: (frameNumber) => { | ||
if (frameNumber === "before" && beforeValue != null) { | ||
@@ -192,4 +154,4 @@ return beforeValue; | ||
} | ||
var staticStringArray = staticString.split("").reduce(function (prev, current, index) { | ||
if (indexes.some(function (i) { return i === index; })) { | ||
const staticStringArray = staticString.split("").reduce((prev, current, index) => { | ||
if (indexes.some(i => i === index)) { | ||
prev.push(""); | ||
@@ -201,6 +163,6 @@ } | ||
function constructString(values) { | ||
var constructedString = ""; | ||
var index = 0; | ||
var indexesLength = indexes.length; | ||
for (var i = 0; i < indexesLength; i++) { | ||
let constructedString = ""; | ||
let index = 0; | ||
const indexesLength = indexes.length; | ||
for (let i = 0; i < indexesLength; i++) { | ||
constructedString += staticStringArray[index] + values[i].toString(); | ||
@@ -215,3 +177,3 @@ index++; | ||
return { | ||
compute: function (frameNumber) { | ||
compute: (frameNumber) => { | ||
if (frameNumber === "before") { | ||
@@ -230,3 +192,3 @@ if (beforeValue != null) { | ||
frameNumber = Math.min(Math.max(0, frameNumber), 1); | ||
var index = getNearestLeftIndexOf(frameNumber); | ||
const index = getNearestLeftIndexOf(frameNumber); | ||
if (index === -1) { | ||
@@ -238,12 +200,12 @@ return ""; | ||
} | ||
var left = frameNumbers[index]; | ||
var right = frameNumbers[index + 1]; | ||
var perc = (frameNumber - left) / (right - left); | ||
var computedValues = []; | ||
var frameValue = frameValues[index]; | ||
var nextFrameValue = frameValues[index + 1]; | ||
var frameValueLength = frameValue.length; | ||
for (var v_index = 0; v_index < frameValueLength; v_index++) { | ||
var value = frameValue[v_index]; | ||
var nextValue = nextFrameValue[v_index]; | ||
const left = frameNumbers[index]; | ||
const right = frameNumbers[index + 1]; | ||
const perc = (frameNumber - left) / (right - left); | ||
const computedValues = []; | ||
const frameValue = frameValues[index]; | ||
const nextFrameValue = frameValues[index + 1]; | ||
const frameValueLength = frameValue.length; | ||
for (let v_index = 0; v_index < frameValueLength; v_index++) { | ||
const value = frameValue[v_index]; | ||
const nextValue = nextFrameValue[v_index]; | ||
computedValues.push(value + ((nextValue - value) * perc)); | ||
@@ -253,30 +215,27 @@ } | ||
}, | ||
needUpdateAt: needUpdateAt | ||
needUpdateAt | ||
}; | ||
} | ||
var SCROLL_OBJECT = Symbol("scroll-object"); | ||
var SCROLL_PARENT = Symbol("scroll-parent"); | ||
var ScrollObject = (function () { | ||
function ScrollObject(el, frames) { | ||
const SCROLL_OBJECT = Symbol("scroll-object"); | ||
const SCROLL_PARENT = Symbol("scroll-parent"); | ||
class ScrollObject { | ||
el; | ||
constructor(el, frames) { | ||
this.el = el; | ||
this._needUpdateAt = [false, null, null, false]; | ||
this._frames = []; | ||
this._lastRenderFrame = null; | ||
this.refresh(frames); | ||
} | ||
ScrollObject.prototype.refresh = function (frames) { | ||
var _this = this; | ||
refresh(frames) { | ||
this.el[SCROLL_OBJECT] = this; | ||
this._frames = []; | ||
var _loop_1 = function (key) { | ||
for (let key in frames) { | ||
if (!Object.prototype.hasOwnProperty.call(frames, key)) { | ||
return "continue"; | ||
continue; | ||
} | ||
var splitKey = key.split("."); | ||
var _a = __read(splitKey.pop().match(/^([^\(\)]*)(\(\))?$/) || [], 3), isValid = _a[0], lastKey = _a[1], isFunction = _a[2]; | ||
const splitKey = key.split("."); | ||
const [isValid, lastKey, isFunction] = splitKey.pop().match(/^([^\(\)]*)(\(\))?$/) || []; | ||
if (!isValid) { | ||
return "continue"; | ||
continue; | ||
} | ||
var _b = computeFrames(frames[key]), compute = _b.compute, needUpdateAt = _b.needUpdateAt; | ||
if (isFunction && needUpdateAt.every(function (value, index) { | ||
const { compute, needUpdateAt } = computeFrames(frames[key]); | ||
if (isFunction && needUpdateAt.every((value, index) => { | ||
if (index === 0 || index === 3) { | ||
@@ -292,6 +251,6 @@ return value === false; | ||
} | ||
var keyLength = splitKey.length; | ||
var accessor = function () { | ||
var lastObject = _this.el; | ||
for (var i = 0; i < keyLength; i++) { | ||
const keyLength = splitKey.length; | ||
const accessor = () => { | ||
let lastObject = this.el; | ||
for (let i = 0; i < keyLength; i++) { | ||
if (lastObject == null) { | ||
@@ -304,19 +263,15 @@ return [null, ""]; | ||
}; | ||
this_1._frames.push([accessor, isFunction != null, compute]); | ||
this_1._needUpdateAt[0] = this_1._needUpdateAt[0] || needUpdateAt[0]; | ||
if (this_1._needUpdateAt[1] !== needUpdateAt[1] && | ||
needUpdateAt[1] != null && (this_1._needUpdateAt[1] == null || | ||
needUpdateAt[1] < this_1._needUpdateAt[1])) { | ||
this_1._needUpdateAt[1] = needUpdateAt[1]; | ||
this._frames.push([accessor, isFunction != null, compute]); | ||
this._needUpdateAt[0] = this._needUpdateAt[0] || needUpdateAt[0]; | ||
if (this._needUpdateAt[1] !== needUpdateAt[1] && | ||
needUpdateAt[1] != null && (this._needUpdateAt[1] == null || | ||
needUpdateAt[1] < this._needUpdateAt[1])) { | ||
this._needUpdateAt[1] = needUpdateAt[1]; | ||
} | ||
if (this_1._needUpdateAt[2] !== needUpdateAt[2] && | ||
needUpdateAt[2] != null && (this_1._needUpdateAt[2] == null || | ||
needUpdateAt[2] > this_1._needUpdateAt[2])) { | ||
this_1._needUpdateAt[2] = needUpdateAt[2]; | ||
if (this._needUpdateAt[2] !== needUpdateAt[2] && | ||
needUpdateAt[2] != null && (this._needUpdateAt[2] == null || | ||
needUpdateAt[2] > this._needUpdateAt[2])) { | ||
this._needUpdateAt[2] = needUpdateAt[2]; | ||
} | ||
this_1._needUpdateAt[3] = this_1._needUpdateAt[3] || needUpdateAt[3]; | ||
}; | ||
var this_1 = this; | ||
for (var key in frames) { | ||
_loop_1(key); | ||
this._needUpdateAt[3] = this._needUpdateAt[3] || needUpdateAt[3]; | ||
} | ||
@@ -326,5 +281,9 @@ this._lastRenderFrame = null; | ||
return this; | ||
}; | ||
ScrollObject.prototype.render = function (frame, renders, force) { | ||
if (force === void 0) { force = false; } | ||
} | ||
_needUpdateAt = [false, null, null, false]; | ||
// _frames: { [key: string]: (frame: FramePosition) => string } = {}; | ||
// [ accessor => [object, key], isFunction, computer ] | ||
_frames = []; | ||
_lastRenderFrame = null; | ||
render(frame, renders, force = false) { | ||
if (!force && | ||
@@ -345,15 +304,16 @@ this._lastRenderFrame === frame) { | ||
this._lastRenderFrame = frame; | ||
for (var i = this._frames.length - 1; i >= 0; i--) { | ||
var currentFrame = this._frames[i]; | ||
var accessor = currentFrame[0], isFunction = currentFrame[1], compute = currentFrame[2]; | ||
var accessorResult = accessor(); | ||
var object = accessorResult[0]; | ||
for (let i = this._frames.length - 1; i >= 0; i--) { | ||
const currentFrame = this._frames[i]; | ||
const accessor = currentFrame[0], isFunction = currentFrame[1], compute = currentFrame[2]; | ||
const accessorResult = accessor(); | ||
const object = accessorResult[0]; | ||
if (object == null) { | ||
continue; | ||
} | ||
var key = accessorResult[1]; | ||
const key = accessorResult[1]; | ||
if (isFunction) { | ||
renders.push([object, key, __spreadArray([ | ||
frame | ||
], __read(compute(frame).split(",").map(function (t) { return t.trim(); }).filter(function (t) { return t !== ""; })))]); | ||
renders.push([object, key, [ | ||
frame, | ||
...compute(frame).split(",").map(t => t.trim()).filter(t => t !== "") | ||
]]); | ||
} | ||
@@ -365,5 +325,4 @@ else { | ||
return renders; | ||
}; | ||
return ScrollObject; | ||
}()); | ||
} | ||
} | ||
function getFirstScrollParent(element) { | ||
@@ -379,18 +338,13 @@ if (element == null) { | ||
} | ||
var ScrollParent = (function () { | ||
function ScrollParent(el) { | ||
class ScrollParent { | ||
el; | ||
constructor(el) { | ||
this.el = el; | ||
this.children = []; | ||
this.trigger = 0; | ||
this.topOffset = 0; | ||
this.bottomOffset = 0; | ||
this._lastPosition = null; | ||
this._parents = []; | ||
el[SCROLL_PARENT] = this; | ||
this._computedStyle = window.getComputedStyle(this.el); | ||
} | ||
ScrollParent.prototype.refresh = function () { | ||
refresh() { | ||
this._lastPosition = null; | ||
this._parents = []; | ||
var el = this.el; | ||
let el = this.el; | ||
while (true) { | ||
@@ -401,3 +355,3 @@ el = getFirstScrollParent(el); | ||
} | ||
if (el !== this.el) { | ||
if (el !== this.el && el !== document.documentElement) { | ||
this._parents.push(el); | ||
@@ -408,27 +362,37 @@ } | ||
return this; | ||
}; | ||
ScrollParent.prototype._getRectTop = function () { | ||
var top = this.el.offsetTop; | ||
var lastParentScrollTop = null; | ||
for (var i = this._parents.length - 1; i >= 0; i--) { | ||
var parent_1 = this._parents[i]; | ||
top += parent_1.offsetTop - parent_1.scrollTop; | ||
if (parent_1.parentElement == null) { | ||
lastParentScrollTop = parent_1.scrollTop; | ||
} | ||
children = []; | ||
trigger = 0; | ||
topOffset = 0; | ||
bottomOffset = 0; | ||
_lastPosition = null; | ||
_computedStyle; | ||
_parents = []; | ||
_getRectTop() { | ||
let top = this.el.offsetTop; | ||
let lastParentScrollTop = null; | ||
for (let i = this._parents.length - 1; i >= 0; i--) { | ||
const parent = this._parents[i]; | ||
top += parent.offsetTop - parent.scrollTop; | ||
if (parent.parentElement == null) { | ||
lastParentScrollTop = parent.scrollTop; | ||
} | ||
} | ||
return top - (lastParentScrollTop == window.pageYOffset ? 0 : window.pageYOffset); | ||
}; | ||
ScrollParent.prototype.render = function (renders, force) { | ||
if (force === void 0) { force = false; } | ||
} | ||
; | ||
render(renders, force = false) { | ||
if (this.children.length === 0 || (this.el.clientHeight === 0 && this.el.clientWidth === 0)) { | ||
return renders; | ||
} | ||
var rectTop = this._getRectTop(); | ||
var rectBottom = rectTop + this.el.offsetHeight; | ||
var trigger = document.documentElement.clientHeight * this.trigger; | ||
var top = rectTop - this.topOffset; | ||
var bottom = rectBottom + this.bottomOffset; | ||
var position = (trigger - top) / (bottom - top); | ||
var actualPosition = position > 1 ? "after" : position < 0 ? "before" : position; | ||
// const rect: DOMRect = this.el.getBoundingClientRect(); | ||
// const rectTop: number = rect.top; | ||
// const rectBottom: number = rect.bottom; | ||
const rectTop = this._getRectTop(); | ||
const rectBottom = rectTop + this.el.offsetHeight; | ||
const trigger = document.documentElement.clientHeight * this.trigger; | ||
const top = rectTop - this.topOffset; | ||
const bottom = rectBottom + this.bottomOffset; | ||
const position = (trigger - top) / (bottom - top); | ||
const actualPosition = position > 1 ? "after" : position < 0 ? "before" : position; | ||
if (actualPosition === this._lastPosition && !force) { | ||
@@ -438,45 +402,45 @@ return renders; | ||
this._lastPosition = actualPosition; | ||
for (var i = this.children.length - 1; i >= 0; i--) { | ||
for (let i = this.children.length - 1; i >= 0; i--) { | ||
this.children[i].render(this._lastPosition, renders, force); | ||
} | ||
// this.el.dispatchEvent(new CustomEvent("render", { detail: { position: this._lastPosition }, bubbles: false })); | ||
return renders; | ||
}; | ||
ScrollParent.prototype.remove = function (obj) { | ||
var index = -1; | ||
if (this.children.some(function (child, i) { index = i; return child === obj || child.el === obj.el; })) { | ||
} | ||
remove(obj) { | ||
let index = -1; | ||
if (this.children.some((child, i) => { index = i; return child === obj || child.el === obj.el; })) { | ||
this.children.splice(index, 1); | ||
this._lastPosition = null; | ||
} | ||
}; | ||
ScrollParent.prototype.add = function (obj) { | ||
} | ||
add(obj) { | ||
this.remove(obj); | ||
this.children.push(obj); | ||
this._lastPosition = null; | ||
}; | ||
return ScrollParent; | ||
}()); | ||
var baseScrollParent = new ScrollParent(document.documentElement); | ||
} | ||
} | ||
const baseScrollParent = new ScrollParent(document.documentElement); | ||
document.body[SCROLL_PARENT] = baseScrollParent; | ||
var scrollParents = [ | ||
const scrollParents = [ | ||
baseScrollParent | ||
]; | ||
function render() { | ||
var renders = []; | ||
for (var i = scrollParents.length - 1; i >= 0; i--) { | ||
const renders = []; | ||
for (let i = scrollParents.length - 1; i >= 0; i--) { | ||
scrollParents[i].render(renders); | ||
} | ||
for (var i = renders.length - 1; i >= 0; i--) { | ||
var render_1 = renders[i]; | ||
var result = render_1[2]; | ||
var object = render_1[0]; | ||
for (let i = renders.length - 1; i >= 0; i--) { | ||
const render = renders[i]; | ||
const result = render[2]; | ||
const object = render[0]; | ||
if (Array.isArray(result)) { | ||
object[render_1[1]].apply(object, result); | ||
object[render[1]].apply(object, result); | ||
} | ||
else { | ||
object[render_1[1]] = result; | ||
object[render[1]] = result; | ||
} | ||
} | ||
} | ||
var stop = false; | ||
var started = false; | ||
let stop = false; | ||
let started = false; | ||
function startLoop() { | ||
@@ -503,14 +467,13 @@ stop = false; | ||
} | ||
var parent = new ScrollParent(element); | ||
const parent = new ScrollParent(element); | ||
scrollParents.push(parent); | ||
return parent; | ||
} | ||
function parse(element, parent, subtree) { | ||
if (subtree === void 0) { subtree = true; } | ||
var scrollOptions = null; | ||
Array.prototype.forEach.call(element.attributes, function (attr) { | ||
function parse(element, parent, subtree = true) { | ||
let scrollOptions = null; | ||
Array.prototype.forEach.call(element.attributes, (attr) => { | ||
if (!attr.name.match(/^data-scroll[\-\.]/)) { | ||
return; | ||
} | ||
var data = attr.name.substr(11); | ||
const data = attr.name.substr(11); | ||
if (data === "-parent") { | ||
@@ -520,3 +483,3 @@ parent = getRefreshedParent(element); | ||
else if (data === "-trigger") { | ||
var trigger = parseFloat(attr.value); | ||
let trigger = parseFloat(attr.value); | ||
if (!isNaN(trigger)) { | ||
@@ -528,3 +491,3 @@ parent = getRefreshedParent(element); | ||
else if (data === "-bottom") { | ||
var bottom = parseFloat(attr.value); | ||
let bottom = parseFloat(attr.value); | ||
if (!isNaN(bottom)) { | ||
@@ -536,10 +499,10 @@ parent = getRefreshedParent(element); | ||
else if (data === "-top") { | ||
var top_1 = parseFloat(attr.value); | ||
if (!isNaN(top_1)) { | ||
let top = parseFloat(attr.value); | ||
if (!isNaN(top)) { | ||
parent = getRefreshedParent(element); | ||
parent.topOffset = top_1; | ||
parent.topOffset = top; | ||
} | ||
} | ||
else { | ||
var dataSplit = data.split("-"); | ||
const dataSplit = data.split("-"); | ||
dataSplit.shift(); | ||
@@ -552,3 +515,4 @@ if (dataSplit.length > 2 || dataSplit.length === 0) { | ||
} | ||
var propertyName = dataSplit[0].replace(/(?:^|[\Wa-zA-Z])(_[a-zA-Z])/, function (_, g) { | ||
// convert "_[a-z]" to "[A-Z]" and "__" to "_" | ||
const propertyName = dataSplit[0].replace(/(?:^|[\Wa-zA-Z])(_[a-zA-Z])/, function (_, g) { | ||
return _.replace(g, g[1].toUpperCase()); | ||
@@ -560,3 +524,3 @@ }).replace("__", "_"); | ||
else { | ||
var frame = parseFloat(dataSplit[1]); | ||
const frame = parseFloat(dataSplit[1]); | ||
if (!isNaN(frame)) { | ||
@@ -589,9 +553,8 @@ scrollOptions[propertyName] = (scrollOptions[propertyName] || []).concat([[frame, attr.value]]); | ||
if (subtree) { | ||
Array.prototype.forEach.call(element.children, function (child) { parse(child, parent); }); | ||
Array.prototype.forEach.call(element.children, child => { parse(child, parent); }); | ||
} | ||
} | ||
function add(element, subtree) { | ||
if (subtree === void 0) { subtree = true; } | ||
var parent = element; | ||
var firstScrollParent = element[SCROLL_PARENT]; | ||
function add(element, subtree = true) { | ||
let parent = element; | ||
let firstScrollParent = element[SCROLL_PARENT]; | ||
while (parent !== document.body && parent != null) { | ||
@@ -615,14 +578,13 @@ parent = parent.parentElement; | ||
} | ||
function remove(element, renderFrame) { | ||
if (renderFrame === void 0) { renderFrame = null; } | ||
var scrollParent = element[SCROLL_PARENT]; | ||
var scrollObject = element[SCROLL_OBJECT]; | ||
function remove(element, renderFrame = null) { | ||
let scrollParent = element[SCROLL_PARENT]; | ||
let scrollObject = element[SCROLL_OBJECT]; | ||
if (scrollParent != null) { | ||
if (scrollParent.el === element) { | ||
var index_1 = -1; | ||
if (scrollParents.some(function (p, i) { | ||
index_1 = i; | ||
let index = -1; | ||
if (scrollParents.some((p, i) => { | ||
index = i; | ||
return p === scrollParent; | ||
})) { | ||
scrollParents.splice(index_1, 1); | ||
scrollParents.splice(index, 1); | ||
} | ||
@@ -633,7 +595,7 @@ } | ||
if (renderFrame != null) { | ||
var renders = []; | ||
const renders = []; | ||
scrollObject.render(renderFrame, renders, true); | ||
for (var i = renders.length - 1; i >= 0; i--) { | ||
var render_2 = renders[i]; | ||
render_2[0][render_2[1]] = render_2[2]; | ||
for (let i = renders.length - 1; i >= 0; i--) { | ||
const render = renders[i]; | ||
render[0][render[1]] = render[2]; | ||
} | ||
@@ -645,10 +607,10 @@ } | ||
} | ||
Array.prototype.forEach.call(element.children, function (child) { | ||
Array.prototype.forEach.call(element.children, child => { | ||
remove(child, renderFrame); | ||
}); | ||
if (scrollParent === baseScrollParent && baseScrollParent.children.length === 0) { | ||
var index_2 = -1; | ||
if (scrollParents.some(function (p, i) { | ||
let index = -1; | ||
if (scrollParents.some((p, i) => { | ||
if (p === baseScrollParent) { | ||
index_2 = i; | ||
index = i; | ||
return true; | ||
@@ -658,3 +620,3 @@ } | ||
})) { | ||
scrollParents.splice(index_2, 1); | ||
scrollParents.splice(index, 1); | ||
} | ||
@@ -674,4 +636,12 @@ } | ||
window.scrollAnimation = scrollAnimation; | ||
// scrollAnimation.add(document.body.querySelector("#test") as HTMLElement); | ||
// setTimeout(() => { | ||
add(document.body); | ||
// document.body.querySelector("#test")?.firstElementChild!.setAttribute("data-scroll-style.background-0", "rgb(0, 255, 0)"); | ||
// scrollAnimation.add(document.body.querySelector("#test") as HTMLElement); | ||
// setTimeout(() => { | ||
// scrollAnimation.remove(document.body.querySelector("#test2")); | ||
// }, 5000); | ||
// }, 2000); | ||
}))); | ||
})); |
{ | ||
"compilerOptions": { | ||
/* Visit https://aka.ms/tsconfig.json to read more about this file */ | ||
/* Basic Options */ | ||
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ | ||
"module": "esnext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ | ||
"lib": [ "DOM", "ES2015", "ES2017.Object" ], /* Specify library files to be included in the compilation. */ | ||
// "allowJs": true, /* Allow javascript files to be compiled. */ | ||
// "checkJs": true, /* Report errors in .js files. */ | ||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ | ||
// "declaration": true, /* Generates corresponding '.d.ts' file. */ | ||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ | ||
// "sourceMap": true, /* Generates corresponding '.map' file. */ | ||
// "outFile": "./", /* Concatenate and emit output to single file. */ | ||
// "outDir": "../www", /* Redirect output structure to the directory. */ | ||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ | ||
// "composite": true, /* Enable project compilation */ | ||
"removeComments": true, /* Do not emit comments to output. */ | ||
// "noEmit": true, /* Do not emit outputs. */ | ||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */ | ||
"downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ | ||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ | ||
// "incremental": true, /* Enable incremental compilation */ | ||
"target": "ESNext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ | ||
"module": "ESNext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ | ||
// "lib": [], /* Specify library files to be included in the compilation. */ | ||
// "allowJs": true, /* Allow javascript files to be compiled. */ | ||
// "checkJs": true, /* Report errors in .js files. */ | ||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */ | ||
"declaration": true, /* Generates corresponding '.d.ts' file. */ | ||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ | ||
// "sourceMap": true, /* Generates corresponding '.map' file. */ | ||
// "outFile": "./", /* Concatenate and emit output to single file. */ | ||
// "outDir": "./", /* Redirect output structure to the directory. */ | ||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ | ||
// "composite": true, /* Enable project compilation */ | ||
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ | ||
// "removeComments": true, /* Do not emit comments to output. */ | ||
// "noEmit": true, /* Do not emit outputs. */ | ||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */ | ||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ | ||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ | ||
/* Strict Type-Checking Options */ | ||
"strict": true, /* Enable all strict type-checking options. */ | ||
"noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */ | ||
// "strictNullChecks": true, /* Enable strict null checks. */ | ||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */ | ||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ | ||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ | ||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ | ||
"strict": true, /* Enable all strict type-checking options. */ | ||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ | ||
// "strictNullChecks": true, /* Enable strict null checks. */ | ||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */ | ||
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ | ||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ | ||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ | ||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ | ||
/* Additional Checks */ | ||
// "noUnusedLocals": true, /* Report errors on unused locals. */ | ||
// "noUnusedParameters": true, /* Report errors on unused parameters. */ | ||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ | ||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ | ||
// "noUnusedLocals": true, /* Report errors on unused locals. */ | ||
// "noUnusedParameters": true, /* Report errors on unused parameters. */ | ||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ | ||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ | ||
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ | ||
// "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ | ||
/* Module Resolution Options */ | ||
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ | ||
"baseUrl": "./", /* Base directory to resolve non-absolute module names. */ | ||
"paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ | ||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ | ||
// "typeRoots": [], /* List of folders to include type definitions from. */ | ||
"types": [], /* Type declaration files to be included in compilation. */ | ||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ | ||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ | ||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ | ||
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ | ||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ | ||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ | ||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ | ||
// "typeRoots": [], /* List of folders to include type definitions from. */ | ||
// "types": [], /* Type declaration files to be included in compilation. */ | ||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ | ||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ | ||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ | ||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ | ||
/* Source Map Options */ | ||
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ | ||
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */ | ||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ | ||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ | ||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ | ||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ | ||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ | ||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ | ||
/* Experimental Options */ | ||
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ | ||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ | ||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ | ||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ | ||
/* Advanced Options */ | ||
"skipLibCheck": true, /* Skip type checking of declaration files. */ | ||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ | ||
} | ||
} | ||
} |
4
17
2632
1379879