svelte-intersection-observer
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -8,2 +8,6 @@ # Changelog | ||
## [0.2.0](https://github.com/metonym/svelte-intersection-observer/releases/tag/v0.2.0) - 2020-11-18 | ||
- Add TypeScript definitions | ||
## [0.1.1](https://github.com/metonym/svelte-intersection-observer/releases/tag/v0.1.1) - 2020-04-05 | ||
@@ -10,0 +14,0 @@ |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = global || self, global['svelte-intersection-observer'] = factory()); | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global['svelte-intersection-observer'] = factory()); | ||
}(this, (function () { 'use strict'; | ||
@@ -29,2 +29,5 @@ | ||
} | ||
function is_empty(obj) { | ||
return Object.keys(obj).length === 0; | ||
} | ||
function create_slot(definition, ctx, $$scope, fn) { | ||
@@ -59,2 +62,9 @@ if (definition) { | ||
} | ||
function update_slot(slot, slot_definition, ctx, $$scope, dirty, get_slot_changes_fn, get_slot_context_fn) { | ||
const slot_changes = get_slot_changes(slot_definition, $$scope, dirty, get_slot_changes_fn); | ||
if (slot_changes) { | ||
const slot_context = get_slot_context(slot_definition, ctx, $$scope, get_slot_context_fn); | ||
slot.p(slot_context, slot_changes); | ||
} | ||
} | ||
function detach(node) { | ||
@@ -78,3 +88,3 @@ node.parentNode.removeChild(node); | ||
if (!current_component) | ||
throw new Error(`Function called outside component initialization`); | ||
throw new Error('Function called outside component initialization'); | ||
return current_component; | ||
@@ -136,2 +146,3 @@ } | ||
} | ||
set_current_component(null); | ||
dirty_components.length = 0; | ||
@@ -251,3 +262,4 @@ while (binding_callbacks.length) | ||
callbacks: blank_object(), | ||
dirty | ||
dirty, | ||
skip_bound: false | ||
}; | ||
@@ -259,3 +271,3 @@ let ready = false; | ||
if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) { | ||
if ($$.bound[i]) | ||
if (!$$.skip_bound && $$.bound[i]) | ||
$$.bound[i](value); | ||
@@ -305,8 +317,12 @@ if (ready) | ||
} | ||
$set() { | ||
// overridden by instance, if it has props | ||
$set($$props) { | ||
if (this.$$set && !is_empty($$props)) { | ||
this.$$.skip_bound = true; | ||
this.$$set($$props); | ||
this.$$.skip_bound = false; | ||
} | ||
} | ||
} | ||
/* src/IntersectionObserver.svelte generated by Svelte v3.20.1 */ | ||
/* src/IntersectionObserver.svelte generated by Svelte v3.29.7 */ | ||
@@ -325,4 +341,4 @@ const get_default_slot_changes = dirty => ({ | ||
let current; | ||
const default_slot_template = /*$$slots*/ ctx[9].default; | ||
const default_slot = create_slot(default_slot_template, ctx, /*$$scope*/ ctx[8], get_default_slot_context); | ||
const default_slot_template = /*#slots*/ ctx[7].default; | ||
const default_slot = create_slot(default_slot_template, ctx, /*$$scope*/ ctx[6], get_default_slot_context); | ||
@@ -342,4 +358,4 @@ return { | ||
if (default_slot) { | ||
if (default_slot.p && dirty & /*$$scope, intersecting, entry*/ 259) { | ||
default_slot.p(get_slot_context(default_slot_template, ctx, /*$$scope*/ ctx[8], get_default_slot_context), get_slot_changes(default_slot_template, /*$$scope*/ ctx[8], dirty, get_default_slot_changes)); | ||
if (default_slot.p && dirty & /*$$scope, intersecting, entry*/ 67) { | ||
update_slot(default_slot, default_slot_template, ctx, /*$$scope*/ ctx[6], dirty, get_default_slot_changes, get_default_slot_context); | ||
} | ||
@@ -366,4 +382,5 @@ } | ||
function instance($$self, $$props, $$invalidate) { | ||
let { element = null } = $$props; // HTMLElement | ||
let { root = null } = $$props; // HTMLElement | ||
let { $$slots: slots = {}, $$scope } = $$props; | ||
let { element = null } = $$props; | ||
let { root = null } = $$props; | ||
let { rootMargin = "0px" } = $$props; | ||
@@ -377,6 +394,3 @@ let { threshold = 0 } = $$props; | ||
afterUpdate(async () => { | ||
if (entry != null) { | ||
dispatch("observe", entry); | ||
} | ||
if (entry != null) dispatch("observe", entry); | ||
await tick(); | ||
@@ -386,7 +400,3 @@ | ||
observer.observe(element); | ||
if (prevElement != null) { | ||
observer.unobserve(prevElement); | ||
} | ||
if (prevElement != null) observer.unobserve(prevElement); | ||
prevElement = element; | ||
@@ -400,5 +410,3 @@ } | ||
let { $$slots = {}, $$scope } = $$props; | ||
$$self.$set = $$props => { | ||
$$self.$$set = $$props => { | ||
if ("element" in $$props) $$invalidate(2, element = $$props.element); | ||
@@ -408,3 +416,3 @@ if ("root" in $$props) $$invalidate(3, root = $$props.root); | ||
if ("threshold" in $$props) $$invalidate(5, threshold = $$props.threshold); | ||
if ("$$scope" in $$props) $$invalidate(8, $$scope = $$props.$$scope); | ||
if ("$$scope" in $$props) $$invalidate(6, $$scope = $$props.$$scope); | ||
}; | ||
@@ -424,14 +432,3 @@ | ||
return [ | ||
entry, | ||
intersecting, | ||
element, | ||
root, | ||
rootMargin, | ||
threshold, | ||
prevElement, | ||
dispatch, | ||
$$scope, | ||
$$slots | ||
]; | ||
return [entry, intersecting, element, root, rootMargin, threshold, $$scope, slots]; | ||
} | ||
@@ -438,0 +435,0 @@ |
{ | ||
"name": "svelte-intersection-observer", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"license": "MIT", | ||
"description": "Detect if an element is in the viewport using the Intersection Observer API", | ||
"author": "Eric Liu (https://github.com/metonym)", | ||
"svelte": "src/index.js", | ||
"main": "lib/index.js", | ||
"module": "lib/index.mjs", | ||
"svelte": "./src/index.js", | ||
"main": "./lib/index.js", | ||
"module": "./lib/index.mjs", | ||
"types": "./types/index.d.ts", | ||
"sideEffects": false, | ||
"scripts": { | ||
"prepublishOnly": "rollup -c", | ||
"build": "rollup -c", | ||
"postbuild": "prettier --write '**/*.{js,svelte}'" | ||
"dev": "rollup -c rollup.config.client.js -w", | ||
"build": "rollup -c rollup.config.client.js", | ||
"deploy": "npx gh-pages -d public", | ||
"prepack": "rollup -c" | ||
}, | ||
"devDependencies": { | ||
"prettier": "1.19.1", | ||
"prettier-plugin-svelte": "0.7.0", | ||
"rollup": "^2.3.3", | ||
"rollup-plugin-node-resolve": "^5.2.0", | ||
"rollup-plugin-svelte": "^5.2.1", | ||
"svelte": "^3.20.1" | ||
"@rollup/plugin-node-resolve": "^10.0.0", | ||
"@tsconfig/svelte": "^1.0.10", | ||
"rollup": "^2.33.3", | ||
"rollup-plugin-svelte": "^6.1.1", | ||
"svelte": "^3.29.7", | ||
"typescript": "^4.0.5" | ||
}, | ||
"prettier": { | ||
"printWidth": 100 | ||
}, | ||
"repository": { | ||
@@ -43,4 +42,5 @@ "type": "git", | ||
"lib", | ||
"src" | ||
"src", | ||
"types" | ||
] | ||
} |
@@ -10,3 +10,3 @@ # svelte-intersection-observer | ||
```bash | ||
```sh | ||
yarn add -D svelte-intersection-observer | ||
@@ -17,3 +17,3 @@ ``` | ||
```html | ||
```svelte | ||
<script> | ||
@@ -38,10 +38,10 @@ import IntersectionObserver from "svelte-intersection-observer"; | ||
| Property name | Description | Value | | ||
| ------------- | ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- | | ||
| element | Element observed for intersection | `HTMLElement` | | ||
| root | Containing element | `null` or `HTMLElement` (default: `null`) | | ||
| rootMargin | Offset of the containing element | `string` (default: `"0px"`) | | ||
| Property name | Description | Value | | ||
| :------------ | :---------------------------------------- | :------------------------------------------------------------------------------------------------------------------ | | ||
| element | Element observed for intersection | `HTMLElement` | | ||
| root | Containing element | `null` or `HTMLElement` (default: `null`) | | ||
| rootMargin | Offset of the containing element | `string` (default: `"0px"`) | | ||
| threshold | Percentage of element to trigger an event | `number` between 0 and 1 (default: `0`) | | ||
| intersecting | If the element is intersecting | `boolean` | | ||
| entry | Observed element metadata | `null` or [`IntersectionObserverEntry`](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserverEntry) | | ||
| intersecting | If the element is intersecting | `boolean` | | ||
| entry | Observed element metadata | `null` or [`IntersectionObserverEntry`](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserverEntry) | | ||
@@ -48,0 +48,0 @@ ### Dispatched Events |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
35218
10
855