UNPKG

js-web-tools

Version:
63 lines (49 loc) 1.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isDocument = isDocument; exports.isWindow = isWindow; exports.getWindow = getWindow; exports.canUseDOM = canUseDOM; exports.ownerDocument = ownerDocument; exports.ownerWindow = ownerWindow; exports.isTransform = isTransform; exports.getComputedStyle = getComputedStyle; exports.isDOMNode = isDOMNode; var _utils = require("./utils"); function isDocument(element) { return 'nodeType' in element && element.nodeType === document.DOCUMENT_NODE; } function isWindow(node) { if ('window' in node && node.window === node) { return node; } if (isDocument(node)) { return node.defaultView || false; } return false; } function getWindow(node) { return isWindow(node); } function canUseDOM() { return !!(typeof window !== 'undefined' && window.document && window.document.createElement); } function ownerDocument(node) { return node && node.ownerDocument || document; } function ownerWindow(node) { var doc = ownerDocument(node); return doc && doc.defaultView || window; } var SUPPORTED_TRANSFORMS = /^((translate|rotate|scale)(X|Y|Z|3d)?|matrix(3d)?|perspective|skew(X|Y)?)$/i; function isTransform(value) { return !!(value && SUPPORTED_TRANSFORMS.test(value)); } function getComputedStyle(node, psuedoElement) { return ownerWindow(node).getComputedStyle(node, psuedoElement); } function isDOMNode(obj) { return (0, _utils.isObject)(obj) && obj.nodeType > 0; }