diff --git a/core/source/Dom.mint b/core/source/Dom.mint index 05b85415..8da038c5 100644 --- a/core/source/Dom.mint +++ b/core/source/Dom.mint @@ -590,4 +590,34 @@ module Dom { ) : Promise(Void) { `#{element}.scrollTo({ behavior: 'smooth', left: #{left}, top: #{top} })` } + + /* + Returns the distance from the outer border of the element (including its + margin) to the left padding edge of the closest positioned ancestor element. + + If the element is not in the DOM or not an element is passed (for example + `TextNode`) then the value will be `0`. + + if let Just(div) = Document.getElementBySelector("div") { + Dom.offsetLeft(div) + } + */ + fun offsetLeft (element : Dom.Element) : Number { + `#{element}.offsetLeft || 0` + } + + /* + Returns the distance from the outer border of the element (including its + margin) to the top padding edge of the closest positioned ancestor element. + + If the element is not in the DOM or not an element is passed (for example + `TextNode`) then the value will be `0`. + + if let Just(div) = Document.getElementBySelector("div") { + Dom.offsetTop(div) + } + */ + fun offsetTop (element : Dom.Element) : Number { + `#{element}.offsetTop || 0` + } } diff --git a/core/source/Html/Event.mint b/core/source/Html/Event.mint index 5d947ef4..34e1af11 100644 --- a/core/source/Html/Event.mint +++ b/core/source/Html/Event.mint @@ -42,6 +42,10 @@ type Html.Event { clientY : Number, screenX : Number, screenY : Number, + offsetX : Number, + offsetY : Number, + layerX : Number, + layerY : Number, pageX : Number, pageY : Number, diff --git a/core/tests/tests/Dom.mint b/core/tests/tests/Dom.mint index 5e342bb3..a149db9d 100644 --- a/core/tests/tests/Dom.mint +++ b/core/tests/tests/Dom.mint @@ -152,3 +152,21 @@ suite "Dom.getChildren" { (element : Dom.Element) { Array.size(Dom.getChildren(element)) == 3 }) } } + +suite "Dom.offsetLeft" { + test "returns the offsetLeft value of the element" { +
+ |> Test.Html.start() + |> Test.Context.assert( + (element : Dom.Element) { Dom.offsetLeft(element) == 8 }) + } +} + +suite "Dom.offsetTop" { + test "returns the offsetTop value of the element" { + + |> Test.Html.start() + |> Test.Context.assert( + (element : Dom.Element) { Dom.offsetTop(element) == 8 }) + } +} diff --git a/runtime/src/normalize_event.js b/runtime/src/normalize_event.js index 3f37003c..97293074 100644 --- a/runtime/src/normalize_event.js +++ b/runtime/src/normalize_event.js @@ -102,6 +102,14 @@ export const normalizeEvent = (event) => { return -1; case "screenY": return -1; + case "layerX": + return -1; + case "layerY": + return -1; + case "offsetX": + return -1; + case "offsetY": + return -1; // onScroll case "detail": diff --git a/src/assets/runtime.js b/src/assets/runtime.js index 0ecd219b..057b7bda 100644 --- a/src/assets/runtime.js +++ b/src/assets/runtime.js @@ -1,29 +1,29 @@ -var Ar=Object.create;var ft=Object.defineProperty;var qr=Object.getOwnPropertyDescriptor;var Or=Object.getOwnPropertyNames;var Tr=Object.getPrototypeOf,Pr=Object.prototype.hasOwnProperty;var ge=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var C=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Nr=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Or(t))!Pr.call(e,i)&&i!==r&&ft(e,i,{get:()=>t[i],enumerable:!(n=qr(t,i))||n.enumerable});return e};var _t=(e,t,r)=>(r=e!=null?Ar(Tr(e)):{},Nr(t||!e||!e.__esModule?ft(r,"default",{value:e,enumerable:!0}):r,e));var zt=C(()=>{});var Kt=C((Li,st)=>{"use strict";(function(){var e,t=0,r=[],n;for(n=0;n<256;n++)r[n]=(n+256).toString(16).substr(1);c.BUFFER_SIZE=4096,c.bin=a,c.clearBuffer=function(){e=null,t=0},c.test=function(l){return typeof l=="string"?/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(l):!1};var i;typeof crypto<"u"?i=crypto:typeof window<"u"&&typeof window.msCrypto<"u"&&(i=window.msCrypto),typeof st<"u"&&typeof ge=="function"?(i=i||zt(),st.exports=c):typeof window<"u"&&(window.uuid=c),c.randomBytes=function(){if(i){if(i.randomBytes)return i.randomBytes;if(i.getRandomValues)return typeof Uint8Array.prototype.slice!="function"?function(l){var f=new Uint8Array(l);return i.getRandomValues(f),Array.from(f)}:function(l){var f=new Uint8Array(l);return i.getRandomValues(f),f}}return function(l){var f,u=[];for(f=0;f