interweave-ssr
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -0,1 +1,7 @@ | ||
## 1.2.0 - 2021-01-18 | ||
#### 🛠 Internals | ||
- Switched to [Packemon](https://packemon.dev) for package building. | ||
### 1.1.1 - 2020-11-04 | ||
@@ -2,0 +8,0 @@ |
154
lib/index.js
@@ -0,54 +1,29 @@ | ||
// Generated with Packemon: https://packemon.dev | ||
// Platform: node, Support: stable, Format: lib | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
var parse5 = require('parse5'); | ||
var adapter = require('parse5/lib/tree-adapters/default'); | ||
var parseStyle = require('style-parser'); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
function _interopNamespace(e) { | ||
if (e && e.__esModule) return e; | ||
var n = Object.create(null); | ||
if (e) { | ||
Object.keys(e).forEach(function (k) { | ||
if (k !== 'default') { | ||
var d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.defineProperty(n, k, d.get ? d : { | ||
enumerable: true, | ||
get: function () { | ||
return e[k]; | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
n['default'] = e; | ||
return Object.freeze(n); | ||
function _interopDefaultLegacy(e) { | ||
return e && typeof e === 'object' && 'default' in e ? e : { | ||
'default': e | ||
}; | ||
} | ||
var adapter__namespace = /*#__PURE__*/_interopNamespace(adapter); | ||
var adapter__default = /*#__PURE__*/_interopDefaultLegacy(adapter); | ||
var parseStyle__default = /*#__PURE__*/_interopDefaultLegacy(parseStyle); | ||
/* eslint-disable @typescript-eslint/prefer-ts-expect-error, @typescript-eslint/no-unsafe-assignment */ | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function patchTextNodeInChildren(parentNode) { | ||
parentNode.childNodes.forEach(function (node) { | ||
parentNode.childNodes.forEach(node => { | ||
if (node.nodeName === '#text' && !node.textContent) { | ||
@@ -64,8 +39,10 @@ Object.defineProperties(node, { | ||
value: { | ||
get: function get() { | ||
get() { | ||
return this.textContent; | ||
}, | ||
set: function set(value) { | ||
set(value) { | ||
this.textContent = value; | ||
} | ||
} | ||
@@ -78,4 +55,4 @@ }); | ||
function createStyleDeclaration(decls) { | ||
var object = parseStyle__default['default'](decls); | ||
var style = Object.keys(object); | ||
const object = parseStyle__default['default'](decls); | ||
const style = Object.keys(object); | ||
Object.assign(style, object); | ||
@@ -85,35 +62,34 @@ return style; | ||
var treeAdapter = _extends({}, adapter__namespace, { | ||
createCommentNode: function createCommentNode(data) { | ||
return _extends({}, adapter.createCommentNode(data), { | ||
const treeAdapter = { ...adapter__default['default'], | ||
createCommentNode(data) { | ||
return { ...adapter__default['default'].createCommentNode(data), | ||
nodeType: 8 | ||
}); | ||
}; | ||
}, | ||
createElement: function createElement(tagName, namespace, attrs) { | ||
var attributes = [].concat(attrs); | ||
var element = _extends({}, adapter.createElement(tagName, namespace, attrs), { | ||
attributes: attributes, | ||
getAttribute: function getAttribute(name) { | ||
var result = attributes.find(function (attr) { | ||
return attr.name === name; | ||
}); | ||
createElement(tagName, namespace, attrs) { | ||
let attributes = [...attrs]; | ||
const element = { ...adapter__default['default'].createElement(tagName, namespace, attrs), | ||
attributes, | ||
getAttribute(name) { | ||
const result = attributes.find(attr => attr.name === name); | ||
return result ? result.value : null; | ||
}, | ||
hasAttribute: function hasAttribute(name) { | ||
return !!attributes.find(function (attr) { | ||
return attr.name === name; | ||
}); | ||
hasAttribute(name) { | ||
return attributes.some(attr => attr.name === name); | ||
}, | ||
nodeType: 1, | ||
removeAttribute: function removeAttribute(name) { | ||
attributes = attributes.filter(function (attr) { | ||
return attr.name !== name; | ||
}); | ||
protocol: '', | ||
removeAttribute(name) { | ||
attributes = attributes.filter(attr => attr.name !== name); | ||
}, | ||
setAttribute: function setAttribute(name, value) { | ||
var result = attributes.find(function (attr) { | ||
return attr.name === name; | ||
}); | ||
setAttribute(name, value) { | ||
const result = attributes.find(attr => attr.name === name); | ||
if (result) { | ||
@@ -123,14 +99,14 @@ result.value = value; | ||
attributes.push({ | ||
name: name, | ||
value: value | ||
name, | ||
value | ||
}); | ||
} | ||
}, | ||
style: [], | ||
tagName: tagName, | ||
tagName, | ||
textContent: '' | ||
}); | ||
}; | ||
const style = element.getAttribute('style'); | ||
var style = element.getAttribute('style'); | ||
if (style) { | ||
@@ -146,15 +122,18 @@ element.style = createStyleDeclaration(style); | ||
}, | ||
insertText: function insertText(parentNode, text) { | ||
adapter.insertText(parentNode, text); | ||
insertText(parentNode, text) { | ||
adapter__default['default'].insertText(parentNode, text); | ||
patchTextNodeInChildren(parentNode); | ||
}, | ||
insertTextBefore: function insertTextBefore(parentNode, text, referenceNode) { | ||
adapter.insertText(parentNode, text, referenceNode); | ||
insertTextBefore(parentNode, text, referenceNode) { | ||
adapter__default['default'].insertTextBefore(parentNode, text, referenceNode); | ||
patchTextNodeInChildren(parentNode); | ||
} | ||
}); | ||
}; | ||
function parseHTML(markup) { | ||
return parse5.parse(markup, { | ||
treeAdapter: treeAdapter | ||
treeAdapter | ||
}); | ||
@@ -164,5 +143,5 @@ } | ||
function createHTMLDocument() { | ||
var doc = parseHTML('<!DOCTYPE html><html><head></head><body></body></html>'); | ||
var html = doc.childNodes[1]; | ||
var body = html.childNodes[1]; | ||
const doc = parseHTML('<!DOCTYPE html><html><head></head><body></body></html>'); | ||
const html = doc.childNodes[1]; | ||
const body = html.childNodes[1]; | ||
Object.defineProperty(html, 'body', { | ||
@@ -172,5 +151,8 @@ value: body | ||
Object.defineProperty(body, 'innerHTML', { | ||
set: function set(value) { | ||
set(value) { | ||
// #document -> html -> body -> tag | ||
// @ts-expect-error | ||
this.childNodes = parseHTML(String(value)).childNodes[0].childNodes[1].childNodes; | ||
} | ||
}); | ||
@@ -183,4 +165,6 @@ return html; | ||
} | ||
function polyfillDOMImplementation() { | ||
if (typeof document === 'undefined') { | ||
// @ts-ignore | ||
global.document = {}; | ||
@@ -190,2 +174,3 @@ } | ||
if (typeof document.implementation === 'undefined') { | ||
// @ts-ignore | ||
global.document.implementation = {}; | ||
@@ -195,2 +180,3 @@ } | ||
if (typeof document.implementation.createHTMLDocument !== 'function') { | ||
// @ts-ignore | ||
global.document.implementation.createHTMLDocument = createHTMLDocument; | ||
@@ -197,0 +183,0 @@ } |
{ | ||
"name": "interweave-ssr", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "Server-side rendering support for Interweave.", | ||
@@ -11,4 +11,3 @@ "keywords": [ | ||
"main": "./lib/index.js", | ||
"module": "./esm/index.js", | ||
"types": "./lib/index.d.ts", | ||
"types": "./dts/index.d.ts", | ||
"sideEffects": false, | ||
@@ -18,3 +17,8 @@ "publishConfig": { | ||
}, | ||
"repository": "https://github.com/milesj/interweave/tree/master/packages/ssr", | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:milesj/interweave.git", | ||
"directory": "packages/ssr" | ||
}, | ||
"author": "Miles Johnson", | ||
"license": "MIT", | ||
@@ -29,3 +33,10 @@ "dependencies": { | ||
}, | ||
"gitHead": "07d1cf430c08e3952cf885068476bc66aecbf6c8" | ||
"packemon": { | ||
"platform": "node" | ||
}, | ||
"engines": { | ||
"node": ">=10.3.0", | ||
"npm": ">=6.1.0" | ||
}, | ||
"gitHead": "a0f490151c458f78d389173da74e48b54504a52d" | ||
} |
@@ -10,5 +10,5 @@ # Interweave SSR | ||
```ts | ||
import { polyfillDOMImplementation } from 'interweave-ssr'; | ||
import { polyfill } from 'interweave-ssr'; | ||
polyfillDOMImplementation(); | ||
polyfill(); | ||
``` | ||
@@ -15,0 +15,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
1
0
7856
7
150
1