Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@svelte-plugins/viewable

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@svelte-plugins/viewable - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

2

lib/index.js

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self)["@svelte-plugins/viewable"]=e()}(this,(function(){"use strict";function t(){}function e(t){return t()}function n(){return Object.create(null)}function o(t){t.forEach(e)}function r(t){return"function"==typeof t}function i(t,e){return t!=t?e==e:t!==e||t&&"object"==typeof t||"function"==typeof t}function c(t,e,n,o){return t[1]&&o?function(t,e){for(const n in e)t[n]=e[n];return t}(n.ctx.slice(),t[1](o(e))):n.ctx}function s(t,e,n,o,r,i,s){const l=function(t,e,n,o){if(t[2]&&o){const r=t[2](o(n));if(void 0===e.dirty)return r;if("object"==typeof r){const t=[],n=Math.max(e.dirty.length,r.length);for(let o=0;o<n;o+=1)t[o]=e.dirty[o]|r[o];return t}return e.dirty|r}return e.dirty}(e,o,r,i);if(l){const r=c(e,n,o,s);t.p(r,l)}}function l(t){t.parentNode.removeChild(t)}let u;function a(t){u=t}function f(){if(!u)throw new Error("Function called outside component initialization");return u}const d=[],h=[],p=[],g=[],$=Promise.resolve();let m=!1;function b(){m||(m=!0,$.then(w))}function y(t){p.push(t)}let x=!1;const v=new Set;function w(){if(!x){x=!0;do{for(let t=0;t<d.length;t+=1){const e=d[t];a(e),_(e.$$)}for(a(null),d.length=0;h.length;)h.pop()();for(let t=0;t<p.length;t+=1){const e=p[t];v.has(e)||(v.add(e),e())}p.length=0}while(d.length);for(;g.length;)g.pop()();m=!1,x=!1,v.clear()}}function _(t){if(null!==t.fragment){t.update(),o(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(y)}}const k=new Set;function M(t,e){t&&t.i&&(k.delete(t),t.i(e))}function O(i,c,s,f,h,p,g=[-1]){const $=u;a(i);const m=i.$$={fragment:null,ctx:null,props:p,update:t,not_equal:h,bound:n(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map($?$.$$.context:[]),callbacks:n(),dirty:g,skip_bound:!1};let x=!1;if(m.ctx=s?s(i,c.props||{},((t,e,...n)=>{const o=n.length?n[0]:e;return m.ctx&&h(m.ctx[t],m.ctx[t]=o)&&(!m.skip_bound&&m.bound[t]&&m.bound[t](o),x&&function(t,e){-1===t.$$.dirty[0]&&(d.push(t),b(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}(i,t)),e})):[],m.update(),x=!0,o(m.before_update),m.fragment=!!f&&f(m.ctx),c.target){if(c.hydrate){const t=(v=c.target,Array.from(v.childNodes));m.fragment&&m.fragment.l(t),t.forEach(l)}else m.fragment&&m.fragment.c();c.intro&&M(i.$$.fragment),function(t,n,i,c){const{fragment:s,on_mount:l,on_destroy:u,after_update:a}=t.$$;s&&s.m(n,i),c||y((()=>{const n=l.map(e).filter(r);u?u.push(...n):o(n),t.$$.on_mount=[]})),a.forEach(y)}(i,c.target,c.anchor,c.customElement),w()}var v;a($)}function E(t){let e;const n=t[11].default,o=function(t,e,n,o){if(t){const r=c(t,e,n,o);return t[0](r)}}(n,t,t[10],null);return{c(){o&&o.c()},m(t,n){o&&o.m(t,n),e=!0},p(t,[e]){o&&o.p&&1024&e&&s(o,n,t,t[10],e,null,null)},i(t){e||(M(o,t),e=!0)},o(t){!function(t,e,n,o){if(t&&t.o){if(k.has(t))return;k.add(t),(void 0).c.push((()=>{k.delete(t),o&&(n&&t.d(1),o())})),t.o(e)}}(o,t),e=!1},d(t){o&&o.d(t)}}}function D(t,e,n){let{$$slots:o={},$$scope:r}=e,{element:i}=e,{rules:c}=e,{debug:s=!1}=e,{duration:l=0}=e,{percent:u=0}=e,{percentX:a=0}=e,{percentY:d=0}=e,{intervalRate:h=200}=e,{gridSize:p=20}=e,{enableObstructionDetection:g=!1}=e,m=null,y=null;const x=[],v=(...t)=>s&&console.log(...t),w=(t,e)=>{const o=(t=>{const e=p+1,n=Math.floor(t.width/e),o=Math.floor(t.height/e),r=Math.max(0,t.left),i=t.top,c=[];for(let t=1;t<e;t++){const s=r+n*t;for(let t=1;t<e;t++){const e=i+o*t;c[c.length]=[s,e]}}return c})(t);let r=0;for(let t=0,e=o.length;t<e;t++){const e=o[t][0],n=o[t][1],c=document.elementFromPoint(e,n);c===i||i.contains(c)||r++}const c=100*e,s=100-r/o.length*100,l=s<c;return l&&n(1,u=s.toFixed(0)),l},_=t=>{const e=(()=>{const t=document.body,e=document.documentElement;return{height:window.innerHeight||e.clientHeight||t&&t.clientHeight,width:window.innerWidth||e.clientWidth||t&&t.clientWidth}})(),o=i.getBoundingClientRect(),r=Math.max(0,Math.min(o.bottom,e.height)-Math.max(o.top,0)),c=Math.max(0,Math.min(o.right,e.width)-Math.max(o.left,0)),s=r/(o.height||i.offsetHeight)||0,l=c/(o.width||i.offsetWidth)||0,f=Math.max(0,s+l-1);return n(2,a=(100*l).toFixed(0)),n(3,d=(100*s).toFixed(0)),n(1,u=(100*f).toFixed(0)),g&&w(o,t)?0:f},k=()=>{const t=x.length;for(let e=0;e<t;e++){const t=x[e];if(t)if(_(t.threshold)<t.threshold)t.history=null;else if(t.history||(n(0,l=0),t.history=Date.now()),n(0,l=(Date.now()-t.history)/1e3),v(`[ Tracking - ${l} - ${t.rule}]`),l>=t.duration&&(t.observer&&t.observer.unobserve(i),t.callback(t),t.history=Date.now(),x.splice(e,1),e-=1,v(x),!x.length)){v(`[ Finished - ${t.history} ]`),y&&(clearInterval(y),y=null);break}}},M=t=>{const e=e=>{const n=e[0];n.isIntersecting?n.isIntersecting&&!y&&(y=setInterval(k,h),k()):t.history=null};if(!t.observer){const n=new IntersectionObserver(e,{threshold:[0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1]});n.observe(i),t.observer=n}};var O;return O=async()=>{await(b(),$),null===i||m||((()=>{for(let t in c){const e=c[t],{duration:n=0,percentage:o=0,fn:r,...i}=e,s={...i,percentage:o,threshold:o/100,duration:n,callback:function(t){r(t),v("[ Viewable Rule ]\n"+JSON.stringify({...t},null,2))},rule:t,history:null};x.push(s),M(s)}})(),m=!0)},f().$$.after_update.push(O),function(t){f().$$.on_destroy.push(t)}((()=>{x.forEach((t=>{t.observer&&t.observer.disconnect()}))})),t.$$set=t=>{"element"in t&&n(4,i=t.element),"rules"in t&&n(5,c=t.rules),"debug"in t&&n(6,s=t.debug),"duration"in t&&n(0,l=t.duration),"percent"in t&&n(1,u=t.percent),"percentX"in t&&n(2,a=t.percentX),"percentY"in t&&n(3,d=t.percentY),"intervalRate"in t&&n(7,h=t.intervalRate),"gridSize"in t&&n(8,p=t.gridSize),"enableObstructionDetection"in t&&n(9,g=t.enableObstructionDetection),"$$scope"in t&&n(10,r=t.$$scope)},[l,u,a,d,i,c,s,h,p,g,r,o]}return class extends class{$destroy(){!function(t,e){const n=t.$$;null!==n.fragment&&(o(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}(this,1),this.$destroy=t}$on(t,e){const n=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return n.push(e),()=>{const t=n.indexOf(e);-1!==t&&n.splice(t,1)}}$set(t){var e;this.$$set&&(e=t,0!==Object.keys(e).length)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}{constructor(t){super(),O(this,t,D,E,i,{element:4,rules:5,debug:6,duration:0,percent:1,percentX:2,percentY:3,intervalRate:7,gridSize:8,enableObstructionDetection:9})}}}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self)["@svelte-plugins/viewable"]=t()}(this,(function(){"use strict";function e(e){return e()}function t(t){t.forEach(e)}let n;function o(e){n=e}function i(){if(!n)throw new Error("Function called outside component initialization");return n}const r=[],l=[],c=[],d=[],s=Promise.resolve();let a=!1;function u(){return a||(a=!0,s.then(p)),s}function h(e){c.push(e)}let f=!1;const g=new Set;function p(){if(!f){f=!0;do{for(let e=0;e<r.length;e+=1){const t=r[e];o(t),v(t.$$)}for(o(null),r.length=0;l.length;)l.pop()();for(let e=0;e<c.length;e+=1){const t=c[e];g.has(t)||(g.add(t),t())}c.length=0}while(r.length);for(;d.length;)d.pop()();a=!1,f=!1,g.clear()}}function v(e){if(null!==e.fragment){e.update(),t(e.before_update);const n=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,n),e.after_update.forEach(h)}}let b;return function(e){function i(t,i,r,l){const c=n;o({$$:{on_destroy:b,context:new Map(c?c.$$.context:[]),on_mount:[],before_update:[],after_update:[],callbacks:Object.create(null)}});const d=e(t,i,r,l);return o(c),d}return{render:(e={},n={})=>{b=[];const o={title:"",head:"",css:new Set},r=i(o,e,{},n);return t(b),{html:r,css:{code:Array.from(o.css).map((e=>e.code)).join("\n"),map:null},head:o.title+o.head}},$$render:i}}(((e,t,n,o)=>{let{element:r}=t,{rules:l}=t,{debug:c=!1}=t,{duration:d=0}=t,{percent:s=0}=t,{percentX:a=0}=t,{percentY:h=0}=t,{intervalRate:f=200}=t,{gridSize:g=20}=t,{enableObstructionDetection:p=!1}=t,v=null,b=null;const m=[],w=(...e)=>c&&console.log(...e),y=(e,t)=>{const n=(e=>{const t=g+1,n=Math.floor(e.width/t),o=Math.floor(e.height/t),i=Math.max(0,e.left),r=e.top,l=[];for(let e=1;e<t;e++){const c=i+n*e;for(let e=1;e<t;e++){const t=r+o*e;l[l.length]=[c,t]}}return l})(e);let o=0;for(let e=0,t=n.length;e<t;e++){const t=n[e][0],i=n[e][1],l=document.elementFromPoint(t,i);l===r||r.contains(l)||o++}const i=100*t,l=100-o/n.length*100,c=l<i;return c&&(s=l.toFixed(0)),c},$=e=>{const t=(()=>{const e=document.body,t=document.documentElement;return{height:window.innerHeight||t.clientHeight||e&&e.clientHeight,width:window.innerWidth||t.clientWidth||e&&e.clientWidth}})(),n=r.getBoundingClientRect(),o=Math.max(0,Math.min(n.bottom,t.height)-Math.max(n.top,0)),i=Math.max(0,Math.min(n.right,t.width)-Math.max(n.left,0)),l=o/(n.height||r.offsetHeight)||0,c=i/(n.width||r.offsetWidth)||0,d=Math.max(0,l+c-1);return a=(100*c).toFixed(0),h=(100*l).toFixed(0),s=(100*d).toFixed(0),p&&y(n,e)?0:d},x=()=>{const e=m.length;for(let t=0;t<e;t++){const e=m[t];if(e)if($(e.threshold)<e.threshold)e.history=null;else if(e.history||(d=0,e.history=Date.now()),d=(Date.now()-e.history)/1e3,w(`[ Tracking - ${d} - ${e.rule}]`),d>=e.duration&&(e.observer&&e.observer.unobserve(r),e.callback(e),e.history=Date.now(),m.splice(t,1),t-=1,w(m),!m.length)){w(`[ Finished - ${e.history} ]`),b&&(clearInterval(b),b=null);break}}},M=e=>{const t=t=>{const n=t[0];n.isIntersecting?n.isIntersecting&&!b&&(b=setInterval(x,f),x()):e.history=null};if(!e.observer){const n=new IntersectionObserver(t,{threshold:[0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1]});n.observe(r),e.observer=n}};var _;return _=async()=>{await u(),null===r||v||((()=>{for(let e in l){const t=l[e],{duration:n=0,percentage:o=0,fn:i,...r}=t,c={...r,percentage:o,threshold:o/100,duration:n,callback:function(e){i(e),w("[ Viewable Rule ]\n"+JSON.stringify({...e},null,2))},rule:e,history:null};m.push(c),M(c)}})(),v=!0)},i().$$.after_update.push(_),function(e){i().$$.on_destroy.push(e)}((()=>{m.forEach((e=>{e.observer&&e.observer.disconnect()}))})),void 0===t.element&&n.element&&void 0!==r&&n.element(r),void 0===t.rules&&n.rules&&void 0!==l&&n.rules(l),void 0===t.debug&&n.debug&&void 0!==c&&n.debug(c),void 0===t.duration&&n.duration&&void 0!==d&&n.duration(d),void 0===t.percent&&n.percent&&void 0!==s&&n.percent(s),void 0===t.percentX&&n.percentX&&void 0!==a&&n.percentX(a),void 0===t.percentY&&n.percentY&&void 0!==h&&n.percentY(h),void 0===t.intervalRate&&n.intervalRate&&void 0!==f&&n.intervalRate(f),void 0===t.gridSize&&n.gridSize&&void 0!==g&&n.gridSize(g),void 0===t.enableObstructionDetection&&n.enableObstructionDetection&&void 0!==p&&n.enableObstructionDetection(p),`${o.default?o.default({}):""}`}))}));
{
"name": "@svelte-plugins/viewable",
"version": "0.1.2",
"version": "0.1.3",
"license": "MIT",

@@ -5,0 +5,0 @@ "description": "A simple rule-based approach to tracking element viewability.",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc