preact-render-to-string 6.0.0 → 6.0.2

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/src/util.js CHANGED
@@ -1,150 +1,150 @@
1
- export const VOID_ELEMENTS = /^(?:area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/;
2
- export const UNSAFE_NAME = /[\s\n\\/='"\0<>]/;
3
- export const XLINK = /^xlink:?./;
4
-
5
- // DOM properties that should NOT have "px" added when numeric
6
- const ENCODED_ENTITIES = /["&<]/;
7
-
8
- /** @param {string} str */
9
- export function encodeEntities(str) {
10
- // Skip all work for strings with no entities needing encoding:
11
- if (str.length === 0 || ENCODED_ENTITIES.test(str) === false) return str;
12
-
13
- let last = 0,
14
- i = 0,
15
- out = '',
16
- ch = '';
17
-
18
- // Seek forward in str until the next entity char:
19
- for (; i < str.length; i++) {
20
- switch (str.charCodeAt(i)) {
21
- case 34:
22
- ch = '&quot;';
23
- break;
24
- case 38:
25
- ch = '&amp;';
26
- break;
27
- case 60:
28
- ch = '&lt;';
29
- break;
30
- default:
31
- continue;
32
- }
33
- // Append skipped/buffered characters and the encoded entity:
34
- if (i !== last) out += str.slice(last, i);
35
- out += ch;
36
- // Start the next seek/buffer after the entity's offset:
37
- last = i + 1;
38
- }
39
- if (i !== last) out += str.slice(last, i);
40
- return out;
41
- }
42
-
43
- export let indent = (s, char) =>
44
- String(s).replace(/(\n+)/g, '$1' + (char || '\t'));
45
-
46
- export let isLargeString = (s, length, ignoreLines) =>
47
- String(s).length > (length || 40) ||
48
- (!ignoreLines && String(s).indexOf('\n') !== -1) ||
49
- String(s).indexOf('<') !== -1;
50
-
51
- const JS_TO_CSS = {};
52
-
53
- const IS_NON_DIMENSIONAL = new Set([
54
- 'animation-iteration-count',
55
- 'border-image-outset',
56
- 'border-image-slice',
57
- 'border-image-width',
58
- 'box-flex',
59
- 'box-flex-group',
60
- 'box-ordinal-group',
61
- 'column-count',
62
- 'fill-opacity',
63
- 'flex',
64
- 'flex-grow',
65
- 'flex-negative',
66
- 'flex-order',
67
- 'flex-positive',
68
- 'flex-shrink',
69
- 'flood-opacity',
70
- 'font-weight',
71
- 'grid-column',
72
- 'grid-row',
73
- 'line-clamp',
74
- 'line-height',
75
- 'opacity',
76
- 'order',
77
- 'orphans',
78
- 'stop-opacity',
79
- 'stroke-dasharray',
80
- 'stroke-dashoffset',
81
- 'stroke-miterlimit',
82
- 'stroke-opacity',
83
- 'stroke-width',
84
- 'tab-size',
85
- 'widows',
86
- 'z-index',
87
- 'zoom'
88
- ]);
89
-
90
- const CSS_REGEX = /[A-Z]/g;
91
- // Convert an Object style to a CSSText string
92
- export function styleObjToCss(s) {
93
- let str = '';
94
- for (let prop in s) {
95
- let val = s[prop];
96
- if (val != null && val !== '') {
97
- const name =
98
- prop[0] == '-'
99
- ? prop
100
- : JS_TO_CSS[prop] ||
101
- (JS_TO_CSS[prop] = prop.replace(CSS_REGEX, '-$&').toLowerCase());
102
-
103
- let suffix = ';';
104
- if (
105
- typeof val === 'number' &&
106
- // Exclude custom-attributes
107
- !name.startsWith('--') &&
108
- !IS_NON_DIMENSIONAL.has(name)
109
- ) {
110
- suffix = 'px;';
111
- }
112
- str = str + name + ':' + val + suffix;
113
- }
114
- }
115
- return str || undefined;
116
- }
117
-
118
- /**
119
- * Get flattened children from the children prop
120
- * @param {Array} accumulator
121
- * @param {any} children A `props.children` opaque object.
122
- * @returns {Array} accumulator
123
- * @private
124
- */
125
- export function getChildren(accumulator, children) {
126
- if (Array.isArray(children)) {
127
- children.reduce(getChildren, accumulator);
128
- } else if (children != null && children !== false) {
129
- accumulator.push(children);
130
- }
131
- return accumulator;
132
- }
133
-
134
- function markAsDirty() {
135
- this.__d = true;
136
- }
137
-
138
- export function createComponent(vnode, context) {
139
- return {
140
- __v: vnode,
141
- context,
142
- props: vnode.props,
143
- // silently drop state updates
144
- setState: markAsDirty,
145
- forceUpdate: markAsDirty,
146
- __d: true,
147
- // hooks
148
- __h: []
149
- };
150
- }
1
+ export const VOID_ELEMENTS = /^(?:area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/;
2
+ export const UNSAFE_NAME = /[\s\n\\/='"\0<>]/;
3
+ export const XLINK = /^xlink:?./;
4
+
5
+ // DOM properties that should NOT have "px" added when numeric
6
+ const ENCODED_ENTITIES = /["&<]/;
7
+
8
+ /** @param {string} str */
9
+ export function encodeEntities(str) {
10
+ // Skip all work for strings with no entities needing encoding:
11
+ if (str.length === 0 || ENCODED_ENTITIES.test(str) === false) return str;
12
+
13
+ let last = 0,
14
+ i = 0,
15
+ out = '',
16
+ ch = '';
17
+
18
+ // Seek forward in str until the next entity char:
19
+ for (; i < str.length; i++) {
20
+ switch (str.charCodeAt(i)) {
21
+ case 34:
22
+ ch = '&quot;';
23
+ break;
24
+ case 38:
25
+ ch = '&amp;';
26
+ break;
27
+ case 60:
28
+ ch = '&lt;';
29
+ break;
30
+ default:
31
+ continue;
32
+ }
33
+ // Append skipped/buffered characters and the encoded entity:
34
+ if (i !== last) out += str.slice(last, i);
35
+ out += ch;
36
+ // Start the next seek/buffer after the entity's offset:
37
+ last = i + 1;
38
+ }
39
+ if (i !== last) out += str.slice(last, i);
40
+ return out;
41
+ }
42
+
43
+ export let indent = (s, char) =>
44
+ String(s).replace(/(\n+)/g, '$1' + (char || '\t'));
45
+
46
+ export let isLargeString = (s, length, ignoreLines) =>
47
+ String(s).length > (length || 40) ||
48
+ (!ignoreLines && String(s).indexOf('\n') !== -1) ||
49
+ String(s).indexOf('<') !== -1;
50
+
51
+ const JS_TO_CSS = {};
52
+
53
+ const IS_NON_DIMENSIONAL = new Set([
54
+ 'animation-iteration-count',
55
+ 'border-image-outset',
56
+ 'border-image-slice',
57
+ 'border-image-width',
58
+ 'box-flex',
59
+ 'box-flex-group',
60
+ 'box-ordinal-group',
61
+ 'column-count',
62
+ 'fill-opacity',
63
+ 'flex',
64
+ 'flex-grow',
65
+ 'flex-negative',
66
+ 'flex-order',
67
+ 'flex-positive',
68
+ 'flex-shrink',
69
+ 'flood-opacity',
70
+ 'font-weight',
71
+ 'grid-column',
72
+ 'grid-row',
73
+ 'line-clamp',
74
+ 'line-height',
75
+ 'opacity',
76
+ 'order',
77
+ 'orphans',
78
+ 'stop-opacity',
79
+ 'stroke-dasharray',
80
+ 'stroke-dashoffset',
81
+ 'stroke-miterlimit',
82
+ 'stroke-opacity',
83
+ 'stroke-width',
84
+ 'tab-size',
85
+ 'widows',
86
+ 'z-index',
87
+ 'zoom'
88
+ ]);
89
+
90
+ const CSS_REGEX = /[A-Z]/g;
91
+ // Convert an Object style to a CSSText string
92
+ export function styleObjToCss(s) {
93
+ let str = '';
94
+ for (let prop in s) {
95
+ let val = s[prop];
96
+ if (val != null && val !== '') {
97
+ const name =
98
+ prop[0] == '-'
99
+ ? prop
100
+ : JS_TO_CSS[prop] ||
101
+ (JS_TO_CSS[prop] = prop.replace(CSS_REGEX, '-$&').toLowerCase());
102
+
103
+ let suffix = ';';
104
+ if (
105
+ typeof val === 'number' &&
106
+ // Exclude custom-attributes
107
+ !name.startsWith('--') &&
108
+ !IS_NON_DIMENSIONAL.has(name)
109
+ ) {
110
+ suffix = 'px;';
111
+ }
112
+ str = str + name + ':' + val + suffix;
113
+ }
114
+ }
115
+ return str || undefined;
116
+ }
117
+
118
+ /**
119
+ * Get flattened children from the children prop
120
+ * @param {Array} accumulator
121
+ * @param {any} children A `props.children` opaque object.
122
+ * @returns {Array} accumulator
123
+ * @private
124
+ */
125
+ export function getChildren(accumulator, children) {
126
+ if (Array.isArray(children)) {
127
+ children.reduce(getChildren, accumulator);
128
+ } else if (children != null && children !== false) {
129
+ accumulator.push(children);
130
+ }
131
+ return accumulator;
132
+ }
133
+
134
+ function markAsDirty() {
135
+ this.__d = true;
136
+ }
137
+
138
+ export function createComponent(vnode, context) {
139
+ return {
140
+ __v: vnode,
141
+ context,
142
+ props: vnode.props,
143
+ // silently drop state updates
144
+ setState: markAsDirty,
145
+ forceUpdate: markAsDirty,
146
+ __d: true,
147
+ // hooks
148
+ __h: []
149
+ };
150
+ }
package/typings.json CHANGED
@@ -1,5 +1,5 @@
1
- {
2
- "name": "preact-render-to-string",
3
- "main": "src/index.d.ts",
4
- "version": false
5
- }
1
+ {
2
+ "name": "preact-render-to-string",
3
+ "main": "src/index.d.ts",
4
+ "version": false
5
+ }
@@ -1,38 +0,0 @@
1
- // import { VNode } from 'preact';
2
-
3
- type VNode = import('preact').VNode;
4
- type ComponentChildren = import('preact').ComponentChildren;
5
-
6
- interface Suspended {
7
- id: string;
8
- promise: Promise<any>;
9
- context: any;
10
- isSvgMode: boolean;
11
- selectValue: any;
12
- vnode: VNode;
13
- parent: VNode | null;
14
- }
15
-
16
- interface RendererErrorHandler {
17
- (
18
- this: RendererState,
19
- error: any,
20
- vnode: VNode<{ fallback: any }>,
21
- renderChild: (child: ComponentChildren) => string
22
- ): string | undefined;
23
- }
24
-
25
- interface RendererState {
26
- start: number;
27
- suspended: Suspended[];
28
- abortSignal?: AbortSignal | undefined;
29
- onWrite: (str: string) => void;
30
- onError?: RendererErrorHandler;
31
- }
32
-
33
- interface RenderToChunksOptions {
34
- context?: any;
35
- onError?: (error: any) => void;
36
- onWrite: (str: string) => void;
37
- abortSignal?: AbortSignal;
38
- }