metaviewport-parser
Advanced tools
Comparing version 0.2.0 to 0.3.0
33
index.js
@@ -6,3 +6,3 @@ exports.getRenderingDataFromViewport = function (viewportProperties, uaDeviceWidth, uaDeviceHeight, uaMaxZoom, uaMinZoom) { | ||
// Following http://dev.w3.org/csswg/css-device-adapt/#translation-into-atviewport-descriptors | ||
// Following https://www.w3.org/TR/css-device-adapt/#handling-auto-zoom | ||
// 'auto' is mapped to null by convention | ||
@@ -20,2 +20,3 @@ var maxZoom = null; | ||
var userZoom = "zoom"; | ||
var interactiveWidget = "resizes-visual"; | ||
@@ -52,3 +53,3 @@ if (viewportProperties["maximum-scale"] !== undefined) { | ||
// Following http://dev.w3.org/csswg/css-device-adapt/#user-scalable0 | ||
// Following https://www.w3.org/TR/css-device-adapt/#user-scalable | ||
if (viewportProperties["user-scalable"] !== undefined) { | ||
@@ -77,2 +78,16 @@ userZoom = viewportProperties["user-scalable"]; | ||
// Following https://w3c.github.io/csswg-drafts/css-viewport/#interactive-widget-section | ||
if (viewportProperties["interactive-widget"] !== undefined) { | ||
switch(viewportProperties["interactive-widget"]) { | ||
case "overlays-content": | ||
case "resizes-content": | ||
case "resizes-visual": | ||
interactiveWidget = viewportProperties["interactive-widget"]; | ||
break; | ||
default: | ||
interactiveWidget = "resizes-visual"; | ||
break; | ||
} | ||
} | ||
/* For a viewport META element that translates into an @viewport rule | ||
@@ -94,3 +109,3 @@ with a non-‘auto’ ‘zoom’ declaration and no ‘width’ declaration: */ | ||
// Following http://dev.w3.org/csswg/css-device-adapt/#constraining-procedure | ||
// Following https://www.w3.org/TR/css-device-adapt/#constraining | ||
@@ -170,3 +185,3 @@ // If min-zoom is not ‘auto’ and max-zoom is not ‘auto’, | ||
return { zoom: zoom, width: width, height: height, userZoom: userZoom}; | ||
return { zoom: zoom, width: width, height: height, userZoom: userZoom, interactiveWidget: interactiveWidget}; | ||
}; | ||
@@ -281,3 +296,3 @@ | ||
var propertyNames = ["width", "height", "initial-scale", "minimum-scale", "maximum-scale", "user-scalable", "shrink-to-fit", "viewport-fit"]; | ||
var propertyNames = ["width", "height", "initial-scale", "minimum-scale", "maximum-scale", "user-scalable", "shrink-to-fit", "viewport-fit", "interactive-widget"]; | ||
@@ -326,4 +341,7 @@ function parseProperty(parsedContent, S, i) { | ||
// https://webkit.org/blog/7929/designing-websites-for-iphone-x/ | ||
(name.toLowerCase() === 'viewport-fit' && (string === 'auto' || string === 'cover'))) { | ||
(name.toLowerCase() === 'viewport-fit' && (string === 'auto' || string === 'cover')) || | ||
(name.toLowerCase() === 'interactive-widget' && (exports.expectedValues["interactive-widget"].includes(string))) | ||
) { | ||
parsedContent.validProperties[name] = string; | ||
@@ -348,3 +366,4 @@ return; | ||
"shrink-to-fit": ["yes", "no"], | ||
"viewport-fit": ["auto", "cover"] | ||
"viewport-fit": ["auto", "cover"], | ||
"interactive-widget": ["overlays-content", "resizes-content", "resizes-visual"] | ||
}; |
{ | ||
"name": "metaviewport-parser", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Parser for the content attribute of the meta viewport", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
12
test.js
@@ -59,8 +59,8 @@ var metaparser = require("./index") | ||
var viewportRenderingTests = [ | ||
{inp: "width=400, initial-scale=1", ua: UA1, out:{zoom: 1, width: 400, height: 600, userZoom: "zoom"}}, | ||
{inp: "width=400, initial-scale=1", ua: UA2, out:{zoom: 1, width: 640, height: 960, userZoom: "zoom"}}, | ||
{inp: "width=400", ua: UA1, out:{zoom: null, width: 400, height: 600, userZoom: "zoom"}}, | ||
{inp: "initial-scale=1", ua: UA1, out:{zoom: 1, width: 320, height: 480, userZoom: "zoom"}}, | ||
{inp: "initial-scale=2.0,height=device-width", ua: UA1, out:{zoom: 2, width: 213, height: 320, userZoom: "zoom"}}, | ||
{inp: "width=480, initial-scale=2.0, user-scalable=no", ua: UA1, out:{zoom: 2, width: 480, height: 720, userZoom: "fixed"}}, | ||
{inp: "width=400, initial-scale=1", ua: UA1, out:{zoom: 1, width: 400, height: 600, userZoom: "zoom", interactiveWidget: "resizes-visual"}}, | ||
{inp: "width=400, initial-scale=1", ua: UA2, out:{zoom: 1, width: 640, height: 960, userZoom: "zoom", interactiveWidget: "resizes-visual"}}, | ||
{inp: "width=400", ua: UA1, out:{zoom: null, width: 400, height: 600, userZoom: "zoom", interactiveWidget: "resizes-visual"}}, | ||
{inp: "initial-scale=1", ua: UA1, out:{zoom: 1, width: 320, height: 480, userZoom: "zoom", interactiveWidget: "resizes-visual"}}, | ||
{inp: "initial-scale=2.0,height=device-width", ua: UA1, out:{zoom: 2, width: 213, height: 320, userZoom: "zoom", interactiveWidget: "resizes-visual"}}, | ||
{inp: "width=480, initial-scale=2.0, user-scalable=no, interactive-widget=overlays-content", ua: UA1, out:{zoom: 2, width: 480, height: 720, userZoom: "fixed", interactiveWidget: "overlays-content"}}, | ||
]; | ||
@@ -67,0 +67,0 @@ |
25713
406
8