UNPKG

next-csrf

Version:

CSRF mitigation library for Next.js

57 lines (47 loc) 1.63 kB
(/* istanbul ignore next */ function (global, factory) { if (typeof define === "function" && define.amd) { define(['module', 'exports', '../util/context-to-element'], factory); } else if (typeof exports !== "undefined") { factory(module, exports, require('../util/context-to-element')); } else { var mod = { exports: {} }; factory(mod, mod.exports, global.contextToElement); global.shadowHost = mod.exports; } })(this, function (module, exports, _contextToElement) { 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = function () { var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, context = _ref.context; var element = (0, _contextToElement2.default)({ label: 'get/shadow-host', context: context }); // walk up to the root var container = null; while (element) { container = element; element = element.parentNode; } // https://developer.mozilla.org/en-US/docs/Web/API/Node.nodeType // NOTE: Firefox 34 does not expose ShadowRoot.host (but 37 does) if (container.nodeType === container.DOCUMENT_FRAGMENT_NODE && container.host) { // the root is attached to a fragment node that has a host return container.host; } return null; }; var _contextToElement2 = _interopRequireDefault(_contextToElement); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } module.exports = exports['default']; }); //# sourceMappingURL=shadow-host.js.map