Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo-mod-jslibs-dist.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'alpinejs/packages/intersect/dist/module.esm.js')
-rw-r--r--alpinejs/packages/intersect/dist/module.esm.js20
1 files changed, 19 insertions, 1 deletions
diff --git a/alpinejs/packages/intersect/dist/module.esm.js b/alpinejs/packages/intersect/dist/module.esm.js
index 84aa068..d89a47c 100644
--- a/alpinejs/packages/intersect/dist/module.esm.js
+++ b/alpinejs/packages/intersect/dist/module.esm.js
@@ -3,11 +3,12 @@ function src_default(Alpine) {
Alpine.directive("intersect", (el, {value, expression, modifiers}, {evaluateLater, cleanup}) => {
let evaluate = evaluateLater(expression);
let options = {
+ rootMargin: getRootMargin(modifiers),
threshold: getThreshhold(modifiers)
};
let observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
- if (!entry.isIntersecting && value === "enter" || entry.isIntersecting && value === "leave" || entry.intersectionRatio === 0 && !value)
+ if (entry.isIntersecting === (value === "leave"))
return;
evaluate();
modifiers.includes("once") && observer.disconnect();
@@ -26,6 +27,23 @@ function getThreshhold(modifiers) {
return 0.5;
return 0;
}
+function getLengthValue(rawValue) {
+ let match = rawValue.match(/^(-?[0-9]+)(px|%)?$/);
+ return match ? match[1] + (match[2] || "px") : void 0;
+}
+function getRootMargin(modifiers) {
+ const key = "margin";
+ const fallback = "0px 0px 0px 0px";
+ const index = modifiers.indexOf(key);
+ if (index === -1)
+ return fallback;
+ let values = [];
+ for (let i = 1; i < 5; i++) {
+ values.push(getLengthValue(modifiers[index + i] || ""));
+ }
+ values = values.filter((v) => v !== void 0);
+ return values.length ? values.join(" ").trim() : fallback;
+}
// packages/intersect/builds/module.js
var module_default = src_default;