preact-render-to-string 6.2.0 → 6.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs.js +1 -1
- package/dist/commonjs.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -0
- package/dist/index.module.js +1 -1
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/jsx-entry.js +1 -1
- package/dist/jsx-entry.js.map +1 -1
- package/dist/jsx.js.map +1 -1
- package/dist/jsx.mjs +1 -1
- package/dist/jsx.mjs.map +1 -1
- package/dist/jsx.modern.js +2 -0
- package/dist/jsx.modern.js.map +1 -0
- package/dist/jsx.module.js +1 -1
- package/dist/jsx.module.js.map +1 -1
- package/dist/jsx.umd.js +1 -1
- package/dist/jsx.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/index.js +25 -4
- package/src/pretty.js +19 -4
- package/src/util.js +3 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "preact-render-to-string",
|
|
3
3
|
"amdName": "preactRenderToString",
|
|
4
|
-
"version": "6.2.
|
|
4
|
+
"version": "6.2.1",
|
|
5
5
|
"description": "Render JSX to an HTML string, with support for Preact components.",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"umd:main": "dist/index.umd.js",
|
package/src/index.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
encodeEntities,
|
|
3
|
+
styleObjToCss,
|
|
4
|
+
UNSAFE_NAME,
|
|
5
|
+
NAMESPACE_REPLACE_REGEX,
|
|
6
|
+
HTML_LOWER_CASE,
|
|
7
|
+
SVG_CAMEL_CASE
|
|
8
|
+
} from './util.js';
|
|
2
9
|
import { options, h, Fragment } from 'preact';
|
|
3
10
|
import {
|
|
4
11
|
CHILDREN,
|
|
@@ -384,10 +391,16 @@ function _renderToString(vnode, context, isSvgMode, selectValue, parent) {
|
|
|
384
391
|
v = styleObjToCss(v);
|
|
385
392
|
}
|
|
386
393
|
break;
|
|
394
|
+
case 'acceptCharset':
|
|
395
|
+
name = 'accept-charset';
|
|
396
|
+
break;
|
|
397
|
+
case 'httpEquiv':
|
|
398
|
+
name = 'http-equiv';
|
|
399
|
+
break;
|
|
387
400
|
|
|
388
401
|
default: {
|
|
389
|
-
if (
|
|
390
|
-
name = name.
|
|
402
|
+
if (NAMESPACE_REPLACE_REGEX.test(name)) {
|
|
403
|
+
name = name.replace(NAMESPACE_REPLACE_REGEX, '$1:$2').toLowerCase();
|
|
391
404
|
} else if (UNSAFE_NAME.test(name)) {
|
|
392
405
|
continue;
|
|
393
406
|
} else if ((name[4] === '-' || name === 'draggable') && v != null) {
|
|
@@ -395,6 +408,15 @@ function _renderToString(vnode, context, isSvgMode, selectValue, parent) {
|
|
|
395
408
|
// `draggable` is an enumerated attribute and not Boolean. A value of `true` or `false` is mandatory
|
|
396
409
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/draggable
|
|
397
410
|
v += '';
|
|
411
|
+
} else if (isSvgMode) {
|
|
412
|
+
if (SVG_CAMEL_CASE.test(name)) {
|
|
413
|
+
name =
|
|
414
|
+
name === 'panose1'
|
|
415
|
+
? 'panose-1'
|
|
416
|
+
: name.replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
417
|
+
}
|
|
418
|
+
} else if (HTML_LOWER_CASE.test(name)) {
|
|
419
|
+
name = name.toLowerCase();
|
|
398
420
|
}
|
|
399
421
|
}
|
|
400
422
|
}
|
|
@@ -439,7 +461,6 @@ function _renderToString(vnode, context, isSvgMode, selectValue, parent) {
|
|
|
439
461
|
return s + '>' + html + '</' + type + '>';
|
|
440
462
|
}
|
|
441
463
|
|
|
442
|
-
const XLINK_REPLACE_REGEX = /^xlink:?/;
|
|
443
464
|
const SELF_CLOSING = new Set([
|
|
444
465
|
'area',
|
|
445
466
|
'base',
|
package/src/pretty.js
CHANGED
|
@@ -6,8 +6,10 @@ import {
|
|
|
6
6
|
getChildren,
|
|
7
7
|
createComponent,
|
|
8
8
|
UNSAFE_NAME,
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
VOID_ELEMENTS,
|
|
10
|
+
NAMESPACE_REPLACE_REGEX,
|
|
11
|
+
HTML_LOWER_CASE,
|
|
12
|
+
SVG_CAMEL_CASE
|
|
11
13
|
} from './util.js';
|
|
12
14
|
import { COMMIT, DIFF, DIFFED, RENDER, SKIP_EFFECTS } from './constants.js';
|
|
13
15
|
import { options, Fragment } from 'preact';
|
|
@@ -243,8 +245,21 @@ function _renderToStringPretty(
|
|
|
243
245
|
} else if (name === 'className') {
|
|
244
246
|
if (typeof props.class !== 'undefined') continue;
|
|
245
247
|
name = 'class';
|
|
246
|
-
} else if (
|
|
247
|
-
name =
|
|
248
|
+
} else if (name === 'acceptCharset') {
|
|
249
|
+
name = 'accept-charset';
|
|
250
|
+
} else if (name === 'httpEquiv') {
|
|
251
|
+
name = 'http-equiv';
|
|
252
|
+
} else if (NAMESPACE_REPLACE_REGEX.test(name)) {
|
|
253
|
+
name = name.replace(NAMESPACE_REPLACE_REGEX, '$1:$2').toLowerCase();
|
|
254
|
+
} else if (isSvgMode) {
|
|
255
|
+
if (SVG_CAMEL_CASE.test(name)) {
|
|
256
|
+
name =
|
|
257
|
+
name === 'panose1'
|
|
258
|
+
? 'panose-1'
|
|
259
|
+
: name.replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
260
|
+
}
|
|
261
|
+
} else if (HTML_LOWER_CASE.test(name)) {
|
|
262
|
+
name = name.toLowerCase();
|
|
248
263
|
}
|
|
249
264
|
|
|
250
265
|
if (name === 'htmlFor') {
|
package/src/util.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export const VOID_ELEMENTS = /^(?:area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/;
|
|
2
2
|
export const UNSAFE_NAME = /[\s\n\\/='"\0<>]/;
|
|
3
|
-
export const
|
|
3
|
+
export const NAMESPACE_REPLACE_REGEX = /^(xlink|xmlns|xml)(:|[A-Z])/;
|
|
4
|
+
export const HTML_LOWER_CASE = /^accessK|^auto[A-Z]|^ch|^col|cont|cross|dateT|encT|form[A-Z]|frame|hrefL|inputM|maxL|minL|noV|playsI|readO|rowS|spellC|src[A-Z]|tabI|item[A-Z]/;
|
|
5
|
+
export const SVG_CAMEL_CASE = /^ac|^ali|arabic|basel|cap|clipPath$|clipRule$|color|dominant|enable|fill|flood|font|glyph[^R]|horiz|image|letter|lighting|marker[^WUH]|overline|panose|pointe|paint|rendering|shape|stop|strikethrough|stroke|text[^L]|transform|underline|unicode|units|^v[^i]|^w|^xH/;
|
|
4
6
|
|
|
5
7
|
// DOM properties that should NOT have "px" added when numeric
|
|
6
8
|
const ENCODED_ENTITIES = /["&<]/;
|