@octanejs/codemod 0.2.0 → 0.2.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/README.md +140 -12
- package/dist/bin.js +2 -2
- package/dist/effect-receivers.d.ts +14 -2
- package/dist/effect-receivers.js +171 -22
- package/dist/expression-wrappers.d.ts +2 -0
- package/dist/expression-wrappers.js +19 -0
- package/dist/forwarded-props.d.ts +4 -1
- package/dist/forwarded-props.js +18 -3
- package/dist/linked-state.d.ts +1 -1
- package/dist/linked-state.js +7 -3
- package/dist/local-react-hook.d.ts +13 -6
- package/dist/local-react-hook.js +316 -53
- package/dist/local-uses.d.ts +10 -1
- package/dist/local-uses.js +87 -5
- package/dist/mappings.d.ts +7 -1
- package/dist/mappings.js +21 -3
- package/dist/path-svg.d.ts +68 -4
- package/dist/path-svg.js +162 -56
- package/dist/project.js +1589 -147
- package/dist/react-intl.d.ts +1 -1
- package/dist/react-intl.js +43 -6
- package/dist/react-island-sources.d.ts +53 -0
- package/dist/react-island-sources.js +979 -0
- package/dist/react-renderer.d.ts +2 -0
- package/dist/react-renderer.js +94 -0
- package/dist/scoped-store-contract.d.ts +9 -2
- package/dist/scoped-store-contract.js +209 -33
- package/dist/store-hook-uses.d.ts +7 -5
- package/dist/store-hook-uses.js +218 -62
- package/dist/store-inputs.d.ts +9 -2
- package/dist/store-inputs.js +213 -16
- package/dist/strong.d.ts +2 -2
- package/dist/strong.js +72 -18
- package/dist/transform.d.ts +14 -0
- package/dist/transform.js +2856 -292
- package/dist/types.d.ts +40 -10
- package/package.json +4 -3
- package/src/path-svg.ts +183 -62
- package/templates/octane-path-svg.ts +5 -1
- package/templates/react-intl.tsrx +64 -11
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { StoreInputCheck } from './store-inputs.js';
|
|
1
2
|
import type ts from 'typescript';
|
|
2
3
|
export interface Note {
|
|
3
4
|
rule: string;
|
|
@@ -28,14 +29,38 @@ export interface TransformOptions {
|
|
|
28
29
|
};
|
|
29
30
|
/** The new spelling of an import specifier (a renamed module, a binding package), or null to keep it. */
|
|
30
31
|
resolveSpecifier?(specifier: string): string | null;
|
|
32
|
+
/** The catalog export names for a partial binding, when known. */
|
|
33
|
+
bindingExports?(from: string, to: string): ReadonlySet<string> | undefined;
|
|
34
|
+
/** Record a successful rewrite that was checked against a partial binding's catalog. */
|
|
35
|
+
recordBindingRewrite?(from: string, to: string): void;
|
|
36
|
+
/** Resolve a direct relative import of an unselected source in a single-file run. */
|
|
37
|
+
retainedRegistry?(specifier: string): ts.SourceFile | undefined;
|
|
31
38
|
/** The issuer resolves the original installed React runtime and types. */
|
|
32
39
|
originalReact?: boolean;
|
|
33
|
-
/**
|
|
40
|
+
/** The authored React bridge and its direct component import still resolve to React. */
|
|
41
|
+
retainedReactBridgeComponent?(bridge: string, module: string, name: string): boolean;
|
|
42
|
+
/** The issuer resolves the original React DOM server entry that this call will migrate. */
|
|
43
|
+
originalReactServerEntry?(module: string): boolean;
|
|
44
|
+
/** A React DOM resource hint called by an imported plain TypeScript function. */
|
|
45
|
+
initializerResourceHint?(module: string, name: string, retainedOnly?: boolean): string | undefined;
|
|
46
|
+
/** Renderer work called by an unchanged local TypeScript export. */
|
|
34
47
|
localReactHook?(module: string, name: string, nativeOnly: boolean): string | {
|
|
35
48
|
from: string;
|
|
49
|
+
} | {
|
|
50
|
+
privateContext: true;
|
|
51
|
+
} | {
|
|
52
|
+
retainedStore: true;
|
|
36
53
|
} | undefined;
|
|
54
|
+
/** A dispatcher hook directly called by an unchanged component at a migrated React DOM root. */
|
|
55
|
+
localReactRootComponent?(module: string, name: string): string | undefined;
|
|
56
|
+
/** Whether a retained local export returns JSX under the project's React JSX settings. */
|
|
57
|
+
localReactTemplateComponent?(module: string, name: string): boolean;
|
|
58
|
+
/** A directly imported context declaration that remains in React. */
|
|
59
|
+
localReactContext?(module: string, name: string, member: boolean): boolean;
|
|
60
|
+
/** Severity for a direct render of a local React class component. */
|
|
61
|
+
localReactClass?(module: string, name: string): 'error' | 'warning' | undefined;
|
|
37
62
|
/** Resolve a source-backed workspace hook after verifying its implementation and its call sites. */
|
|
38
|
-
resolveStoreHook?(module: string, name: string, safeUses: (sharedInput: (module: string, name: string) => boolean
|
|
63
|
+
resolveStoreHook?(module: string, name: string, safeUses: (sharedInput: StoreInputCheck, unchangedHelper?: (module: string, name: string) => boolean, retainedArgument?: (module: string, name: string) => boolean) => boolean): {
|
|
39
64
|
from: string;
|
|
40
65
|
name: string;
|
|
41
66
|
} | null;
|
|
@@ -43,19 +68,19 @@ export interface TransformOptions {
|
|
|
43
68
|
reactIntlAdapter?: string;
|
|
44
69
|
/** Whether a directly imported, selected component forwards this prop only to text attributes. */
|
|
45
70
|
forwardedText?(module: string, exported: string, prop: string, ordinaryCaller?: boolean, through?: boolean): boolean;
|
|
46
|
-
/** Whether
|
|
71
|
+
/** Whether this selected component accepts one explicit element, with separate review for path aliases. */
|
|
47
72
|
elementChild?(binding: number | {
|
|
48
73
|
module: string;
|
|
49
74
|
imported: string;
|
|
50
|
-
}): boolean;
|
|
75
|
+
}): boolean | 'review-alias';
|
|
51
76
|
/** Whether a selected, directly imported component inspects its child descriptors. */
|
|
52
77
|
descriptorChild?(binding: {
|
|
53
78
|
module: string;
|
|
54
79
|
imported: string;
|
|
55
80
|
}): boolean;
|
|
56
|
-
/** Whether an imported name is a context,
|
|
57
|
-
isContext?(specifier: string, name: string): boolean | null;
|
|
58
|
-
/** The React package an import specifier names when
|
|
81
|
+
/** Whether an imported name is a context, with separate review for selected alias targets. */
|
|
82
|
+
isContext?(specifier: string, name: string, local: string): boolean | 'review-alias' | null;
|
|
83
|
+
/** The React package an import specifier names when the codemod keeps it on React, or null. */
|
|
59
84
|
unported?(specifier: string): string | null;
|
|
60
85
|
/** The project has React and React DOM 19.2 or newer in the React 19 series, so `ReactCompat` can host an unported package's components. */
|
|
61
86
|
reactCompat?: boolean;
|
|
@@ -69,17 +94,21 @@ export interface TransformOptions {
|
|
|
69
94
|
cssModuleFile?(specifier: string): string | undefined;
|
|
70
95
|
/** The generated native SVG helper, if the project verified this raw asset. */
|
|
71
96
|
pathSvgAdapter?(specifier: string): string | null;
|
|
97
|
+
/** Whether a native server SVG entry resolves to the adapter's installed Octane. */
|
|
98
|
+
originalSvgServer?: boolean;
|
|
72
99
|
/** With pathSvgAdapter, supplies a native SVG adapter with the requested fixed root color. */
|
|
73
100
|
fixedColorSvgAdapter?(specifier: string, color: string): string | null;
|
|
101
|
+
/** The project compiles this file with the original React automatic JSX runtime. */
|
|
102
|
+
automaticReactJsx?: boolean;
|
|
74
103
|
/** This file uses React's automatic JSX runtime and the component resolves to its original React package. */
|
|
75
104
|
reactStoreComponent?(specifier: string): boolean;
|
|
76
105
|
}
|
|
77
|
-
/** A React package
|
|
106
|
+
/** A retained React package import and how migrated code uses it. */
|
|
78
107
|
export interface Unported {
|
|
79
108
|
name: string;
|
|
80
109
|
/** Elements now rendered in a `ReactCompat` island. */
|
|
81
110
|
islands: number;
|
|
82
|
-
/** Uses that
|
|
111
|
+
/** Uses that need review before migrating to an Octane renderer. */
|
|
83
112
|
blocked: number;
|
|
84
113
|
}
|
|
85
114
|
export interface TransformResult {
|
|
@@ -97,6 +126,7 @@ export interface TransformResult {
|
|
|
97
126
|
exported?: string;
|
|
98
127
|
}[];
|
|
99
128
|
descriptorChildren?: string[];
|
|
129
|
+
storeHookComponents?: string[];
|
|
100
130
|
contexts: string[];
|
|
101
131
|
reexports: {
|
|
102
132
|
specifier: string;
|
|
@@ -167,7 +197,7 @@ export interface CodemodResult {
|
|
|
167
197
|
name: string;
|
|
168
198
|
patch: string;
|
|
169
199
|
}[];
|
|
170
|
-
/** React
|
|
200
|
+
/** React package imports the codemod keeps on React, and how the code uses them. */
|
|
171
201
|
missing: (Unported & {
|
|
172
202
|
modules: number;
|
|
173
203
|
})[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octanejs/codemod",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.22.2"
|
|
@@ -45,9 +45,10 @@
|
|
|
45
45
|
"./package.json": "./package.json"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@octanejs/cli": "0.3.
|
|
48
|
+
"@octanejs/cli": "0.3.6",
|
|
49
49
|
"@tsrx/oxc": "0.23.0",
|
|
50
|
-
"octane": "0.
|
|
50
|
+
"octane": "0.19.0",
|
|
51
|
+
"parse5": "8.0.1",
|
|
51
52
|
"picocolors": "^1.1.1",
|
|
52
53
|
"typescript": "^5.9.3"
|
|
53
54
|
},
|
package/src/path-svg.ts
CHANGED
|
@@ -18,6 +18,7 @@ const operation =
|
|
|
18
18
|
const transform = new RegExp('^' + operation + '(?:' + separator + operation + ')*$');
|
|
19
19
|
const transformNumbers = new RegExp(number, 'g');
|
|
20
20
|
const localPaint = /^url\(#[A-Za-z_][A-Za-z0-9_-]*\)$/;
|
|
21
|
+
const identifier = /^[A-Za-z_][A-Za-z0-9_-]*$/;
|
|
21
22
|
const tileSize = /^[1-9]\d*$/;
|
|
22
23
|
const rootAttributes = {
|
|
23
24
|
preserveAspectRatio: /^none$/,
|
|
@@ -35,8 +36,12 @@ export function svgLiteralRootOverride(name: string, value: string) {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
const fillRule = /^(?:evenodd|nonzero)$/;
|
|
39
|
+
const referencedPaint = new RegExp(paint.source + '|' + localPaint.source);
|
|
40
|
+
const userSpace = /^userSpaceOnUse$/;
|
|
41
|
+
const bounds = { x: length, y: length, width: extent, height: extent };
|
|
42
|
+
const blur = /^(?:0|[1-9]\d*)(?:\.\d+)?$/;
|
|
38
43
|
const presentation = {
|
|
39
|
-
fill:
|
|
44
|
+
fill: referencedPaint,
|
|
40
45
|
stroke: paint,
|
|
41
46
|
'stroke-width': length,
|
|
42
47
|
'stroke-linecap': /^(?:butt|round|square)$/,
|
|
@@ -53,47 +58,80 @@ const pathAttributes = {
|
|
|
53
58
|
};
|
|
54
59
|
const rectAttributes = {
|
|
55
60
|
...presentation,
|
|
56
|
-
|
|
57
|
-
x: length,
|
|
58
|
-
y: length,
|
|
59
|
-
width: extent,
|
|
60
|
-
height: extent,
|
|
61
|
+
...bounds,
|
|
61
62
|
rx: extent,
|
|
62
63
|
ry: extent,
|
|
64
|
+
transform,
|
|
63
65
|
};
|
|
64
66
|
const shapeAttributes = {
|
|
65
67
|
path: pathAttributes,
|
|
66
68
|
rect: rectAttributes,
|
|
67
|
-
|
|
69
|
+
circle: { ...presentation, cx: length, cy: length, r: extent },
|
|
70
|
+
g: { transform, 'clip-path': localPaint, mask: localPaint, filter: localPaint },
|
|
68
71
|
defs: {},
|
|
69
|
-
clipPath: { id:
|
|
72
|
+
clipPath: { id: identifier },
|
|
70
73
|
pattern: {
|
|
71
|
-
id:
|
|
74
|
+
id: identifier,
|
|
72
75
|
width: tileSize,
|
|
73
76
|
height: tileSize,
|
|
74
|
-
patternUnits:
|
|
77
|
+
patternUnits: userSpace,
|
|
78
|
+
},
|
|
79
|
+
linearGradient: {
|
|
80
|
+
id: identifier,
|
|
81
|
+
gradientUnits: userSpace,
|
|
82
|
+
x1: length,
|
|
83
|
+
y1: length,
|
|
84
|
+
x2: length,
|
|
85
|
+
y2: length,
|
|
86
|
+
},
|
|
87
|
+
stop: { offset: opacity, 'stop-color': paint, 'stop-opacity': opacity },
|
|
88
|
+
mask: { id: identifier, ...bounds, maskUnits: userSpace, style: /^mask-type:alpha$/ },
|
|
89
|
+
filter: {
|
|
90
|
+
id: identifier,
|
|
91
|
+
...bounds,
|
|
92
|
+
filterUnits: userSpace,
|
|
93
|
+
'color-interpolation-filters': /^(?:sRGB|linearRGB)$/,
|
|
75
94
|
},
|
|
95
|
+
feFlood: { 'flood-opacity': opacity, result: identifier },
|
|
96
|
+
feBlend: { in: identifier, in2: identifier, mode: /^normal$/, result: identifier },
|
|
97
|
+
feGaussianBlur: { stdDeviation: blur, result: identifier },
|
|
76
98
|
};
|
|
77
99
|
|
|
78
|
-
function attributes(text: string, allowed: Record<string, RegExp
|
|
100
|
+
function attributes(text: string, allowed: Record<string, RegExp>, allowData = false) {
|
|
79
101
|
const values: Record<string, string> = {};
|
|
80
102
|
const field =
|
|
81
|
-
/[ \t\r\n]+([A-Za-z][A-Za-
|
|
103
|
+
/[ \t\r\n]+([A-Za-z][A-Za-z0-9-]*)[ \t\r\n]*=[ \t\r\n]*(?:"([^"&<>\t\r\n]*)"|'([^'&<>\t\r\n]*)')/gy;
|
|
82
104
|
let end = 0;
|
|
83
105
|
for (let match; (match = field.exec(text)); end = field.lastIndex) {
|
|
84
106
|
const name = match[1]!;
|
|
85
107
|
let value = (match[2] ?? match[3])!;
|
|
86
|
-
if (name in values
|
|
87
|
-
const rule = allowed[name]
|
|
88
|
-
|
|
108
|
+
if (name in values) return null;
|
|
109
|
+
const rule = Object.prototype.hasOwnProperty.call(allowed, name) ? allowed[name] : undefined;
|
|
110
|
+
// SVG JSX loaders can normalize numeric strings or escape punctuation differently.
|
|
111
|
+
if (
|
|
112
|
+
rule
|
|
113
|
+
? !rule.test(value)
|
|
114
|
+
: !(
|
|
115
|
+
allowData &&
|
|
116
|
+
svgDataAttribute(name) &&
|
|
117
|
+
/^(?:[a-z][a-z0-9_-]*(?: [a-z0-9_-]+)*)?$/.test(value)
|
|
118
|
+
)
|
|
119
|
+
)
|
|
120
|
+
return null;
|
|
89
121
|
// SVGR emits a numeric literal for a leading-dot opacity.
|
|
90
122
|
if (rule === opacity && value.startsWith('.')) value = '0' + value;
|
|
91
123
|
// SVG component loaders can emit a numeric literal for unitless lengths.
|
|
92
|
-
if (
|
|
124
|
+
if (
|
|
125
|
+
rule === length ||
|
|
126
|
+
rule === extent ||
|
|
127
|
+
rule === opacity ||
|
|
128
|
+
rule === tileSize ||
|
|
129
|
+
rule === blur
|
|
130
|
+
) {
|
|
93
131
|
const n = Number(value);
|
|
94
132
|
if (
|
|
95
133
|
(!Number.isNaN(n) && String(n) !== value) ||
|
|
96
|
-
(rule === extent && !Number.isFinite(parseFloat(value)))
|
|
134
|
+
((rule === extent || rule === blur) && !Number.isFinite(parseFloat(value)))
|
|
97
135
|
)
|
|
98
136
|
return null;
|
|
99
137
|
}
|
|
@@ -118,18 +156,78 @@ type StaticSvgNode = {
|
|
|
118
156
|
children: StaticSvgNode[];
|
|
119
157
|
};
|
|
120
158
|
|
|
121
|
-
|
|
159
|
+
type SvgTag = StaticSvgNode['tag'];
|
|
160
|
+
type SvgParent = 'svg' | SvgTag;
|
|
161
|
+
const containerTags = new Set<SvgTag>([
|
|
162
|
+
'g',
|
|
163
|
+
'defs',
|
|
164
|
+
'clipPath',
|
|
165
|
+
'pattern',
|
|
166
|
+
'linearGradient',
|
|
167
|
+
'mask',
|
|
168
|
+
'filter',
|
|
169
|
+
]);
|
|
170
|
+
const definitionTags = new Set<SvgTag>(['clipPath', 'pattern', 'linearGradient', 'mask', 'filter']);
|
|
171
|
+
const filterPrimitives = new Set<SvgTag>(['feFlood', 'feBlend', 'feGaussianBlur']);
|
|
172
|
+
const geometryTags = new Set<SvgTag>(['path', 'rect', 'circle']);
|
|
173
|
+
|
|
174
|
+
function allowedChild(parent: SvgParent, child: SvgTag) {
|
|
175
|
+
switch (parent) {
|
|
176
|
+
case 'defs':
|
|
177
|
+
return definitionTags.has(child) && child !== 'mask';
|
|
178
|
+
case 'linearGradient':
|
|
179
|
+
return child === 'stop';
|
|
180
|
+
case 'filter':
|
|
181
|
+
return filterPrimitives.has(child);
|
|
182
|
+
case 'clipPath':
|
|
183
|
+
return child === 'rect';
|
|
184
|
+
case 'pattern':
|
|
185
|
+
return child === 'path';
|
|
186
|
+
case 'mask':
|
|
187
|
+
return child === 'path' || child === 'rect';
|
|
188
|
+
default:
|
|
189
|
+
return (
|
|
190
|
+
geometryTags.has(child) ||
|
|
191
|
+
child === 'g' ||
|
|
192
|
+
(parent === 'svg' && (child === 'defs' || child === 'mask'))
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function closedContainer(tag: SvgParent, children: readonly StaticSvgNode[]) {
|
|
198
|
+
if (tag === 'clipPath' || tag === 'pattern') return children.length === 1;
|
|
199
|
+
if (tag === 'linearGradient') return children.length >= 2;
|
|
200
|
+
if (tag !== 'filter') return (tag !== 'defs' && tag !== 'mask') || children.length > 0;
|
|
201
|
+
const inputs = new Set(['SourceGraphic', 'SourceAlpha']);
|
|
202
|
+
return (
|
|
203
|
+
children.length > 0 &&
|
|
204
|
+
children.every(({ tag, attributes }) => {
|
|
205
|
+
const { in: input, in2, result, stdDeviation } = attributes;
|
|
206
|
+
if (
|
|
207
|
+
(tag === 'feBlend' && !(input && in2 && inputs.has(input) && inputs.has(in2))) ||
|
|
208
|
+
(tag === 'feGaussianBlur' && stdDeviation === undefined) ||
|
|
209
|
+
!result ||
|
|
210
|
+
inputs.has(result)
|
|
211
|
+
)
|
|
212
|
+
return false;
|
|
213
|
+
inputs.add(result);
|
|
214
|
+
return true;
|
|
215
|
+
})
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** Read authored geometry with bounded local paint and effect definitions. */
|
|
122
220
|
export function parseStaticSvg(source: string) {
|
|
123
221
|
if (typeof source !== 'string') return null;
|
|
124
222
|
let root: Record<string, string> | null = null;
|
|
223
|
+
let title: string | undefined;
|
|
125
224
|
const children: StaticSvgNode[] = [];
|
|
126
|
-
const open: { tag:
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
let
|
|
130
|
-
let paintId: string | undefined;
|
|
225
|
+
const open: { tag: SvgParent; children: StaticSvgNode[] }[] = [];
|
|
226
|
+
const definitions = new Map<string, SvgTag>();
|
|
227
|
+
const references: { id: string; target: SvgTag; rootRect?: boolean }[] = [];
|
|
228
|
+
let legacyDefinition = false;
|
|
131
229
|
const token =
|
|
132
|
-
/[ \t\r\n]*(?:<!--([\s\S]*?)-->|<\/(
|
|
230
|
+
/[ \t\r\n]*(?:<!--([\s\S]*?)-->|<\/([A-Za-z][A-Za-z0-9]*)[ \t\r\n]*>|<([A-Za-z][A-Za-z0-9]*)([^<>]*?)(\/?)>)/gy;
|
|
133
231
|
let hasShape = false;
|
|
134
232
|
let end = 0;
|
|
135
233
|
for (let match; (match = token.exec(source)); end = token.lastIndex) {
|
|
@@ -139,80 +237,103 @@ export function parseStaticSvg(source: string) {
|
|
|
139
237
|
if (/--|-$|[^\t\r\n\u0020-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/u.test(comment))
|
|
140
238
|
return null;
|
|
141
239
|
} else if (closing) {
|
|
142
|
-
if (!parent || closing !== parent.tag
|
|
143
|
-
if (
|
|
144
|
-
(closing === 'defs' || closing === 'clipPath' || closing === 'pattern') &&
|
|
145
|
-
parent.children.length !== 1
|
|
146
|
-
)
|
|
240
|
+
if (!parent || closing !== parent.tag || !closedContainer(parent.tag, parent.children))
|
|
147
241
|
return null;
|
|
148
242
|
open.pop();
|
|
149
243
|
} else if (tag === 'svg') {
|
|
150
244
|
if (root || selfClosing) return null;
|
|
151
|
-
root = attributes(fields!, rootAttributes);
|
|
245
|
+
root = attributes(fields!, rootAttributes, true);
|
|
152
246
|
if (!root) return null;
|
|
153
247
|
open.push({ tag, children });
|
|
154
|
-
} else {
|
|
155
|
-
if (
|
|
156
|
-
|
|
248
|
+
} else if (tag === 'title') {
|
|
249
|
+
if (parent?.tag !== 'svg' || children.length || title !== undefined || fields || selfClosing)
|
|
250
|
+
return null;
|
|
251
|
+
// Keep one literal text child. XML entities, markup, and line endings require loader rules.
|
|
252
|
+
const titleToken = /([^<&]+)<\/title>/uy;
|
|
253
|
+
titleToken.lastIndex = token.lastIndex;
|
|
254
|
+
const text = titleToken.exec(source);
|
|
157
255
|
if (
|
|
158
|
-
|
|
159
|
-
(
|
|
160
|
-
(
|
|
161
|
-
(parent.tag === 'pattern' && name !== 'path')
|
|
256
|
+
!text ||
|
|
257
|
+
/\]\]>|[^\u0020-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/u.test(text[1]) ||
|
|
258
|
+
!text[1].trim()
|
|
162
259
|
)
|
|
163
260
|
return null;
|
|
164
|
-
|
|
261
|
+
title = text[1];
|
|
262
|
+
token.lastIndex = titleToken.lastIndex;
|
|
263
|
+
} else {
|
|
264
|
+
if (!parent || !tag || !Object.prototype.hasOwnProperty.call(shapeAttributes, tag))
|
|
265
|
+
return null;
|
|
266
|
+
const name = tag as SvgTag;
|
|
267
|
+
if (!allowedChild(parent.tag, name)) return null;
|
|
268
|
+
if (name === 'defs' && children.some((node) => node.tag === 'defs')) return null;
|
|
269
|
+
const container = containerTags.has(name);
|
|
165
270
|
if (container ? selfClosing || open.length > 32 : !selfClosing) return null;
|
|
166
271
|
const props = attributes(fields!, shapeAttributes[name]);
|
|
167
272
|
if (
|
|
168
273
|
!props ||
|
|
169
274
|
(tag === 'path' && !props.d) ||
|
|
170
|
-
(tag === 'rect' && !(props.width && props.height))
|
|
275
|
+
(tag === 'rect' && !(props.width && props.height)) ||
|
|
276
|
+
(tag === 'circle' && !props.r) ||
|
|
277
|
+
(tag === 'stop' && !props['stop-color'])
|
|
171
278
|
)
|
|
172
279
|
return null;
|
|
173
|
-
if (name
|
|
174
|
-
if (!props.id ||
|
|
175
|
-
|
|
280
|
+
if (definitionTags.has(name)) {
|
|
281
|
+
if (!props.id || definitions.has(props.id)) return null;
|
|
282
|
+
legacyDefinition ||= name === 'clipPath' || name === 'pattern';
|
|
283
|
+
definitions.set(props.id, name);
|
|
176
284
|
}
|
|
177
285
|
if (props['clip-path']) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
reference = id;
|
|
286
|
+
if (parent.tag !== 'svg') return null;
|
|
287
|
+
references.push({ id: props['clip-path'].slice(5, -1), target: 'clipPath' });
|
|
181
288
|
}
|
|
182
|
-
if (name === 'pattern')
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
289
|
+
if (name === 'pattern' && !(props.width && props.height && props.patternUnits)) return null;
|
|
290
|
+
if (
|
|
291
|
+
name === 'linearGradient' &&
|
|
292
|
+
!(props.gradientUnits && props.x1 && props.y1 && props.x2 && props.y2)
|
|
293
|
+
)
|
|
294
|
+
return null;
|
|
295
|
+
if (
|
|
296
|
+
(name === 'mask' && !(props.maskUnits && props.style && props.width && props.height)) ||
|
|
297
|
+
(name === 'filter' && !(props.filterUnits && props.width && props.height))
|
|
298
|
+
)
|
|
299
|
+
return null;
|
|
300
|
+
for (const target of ['mask', 'filter'] as const) {
|
|
301
|
+
if (props[target]) references.push({ id: props[target].slice(5, -1), target });
|
|
190
302
|
}
|
|
191
|
-
if (
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
303
|
+
if (props.fill?.startsWith('url(')) {
|
|
304
|
+
if (parent.tag !== 'svg' && parent.tag !== 'g') return null;
|
|
305
|
+
references.push({
|
|
306
|
+
id: props.fill.slice(5, -1),
|
|
307
|
+
target: 'linearGradient',
|
|
308
|
+
rootRect: name === 'rect' && parent.tag === 'svg',
|
|
309
|
+
});
|
|
195
310
|
}
|
|
196
311
|
const node: StaticSvgNode = { tag: name, attributes: props, children: [] };
|
|
197
312
|
parent.children.push(node);
|
|
198
313
|
if (container) open.push(node);
|
|
199
|
-
else if (parent.tag
|
|
314
|
+
else if (parent.tag === 'svg' || parent.tag === 'g') hasShape = true;
|
|
200
315
|
}
|
|
201
316
|
}
|
|
202
317
|
return root &&
|
|
203
318
|
hasShape &&
|
|
204
319
|
!open.length &&
|
|
205
|
-
|
|
206
|
-
|
|
320
|
+
(!legacyDefinition || definitions.size === 1) &&
|
|
321
|
+
new Set(references.map(({ id }) => id)).size === definitions.size &&
|
|
322
|
+
references.every(
|
|
323
|
+
({ id, target, rootRect }) =>
|
|
324
|
+
definitions.get(id) === target || (rootRect && definitions.get(id) === 'pattern'),
|
|
325
|
+
) &&
|
|
207
326
|
space.test(source.slice(end))
|
|
208
|
-
?
|
|
327
|
+
? title === undefined
|
|
328
|
+
? { root, children }
|
|
329
|
+
: { root, children, title }
|
|
209
330
|
: null;
|
|
210
331
|
}
|
|
211
332
|
|
|
212
333
|
// Existing generated helpers expose this path-only result to their importers.
|
|
213
334
|
export function parsePathSvg(source: string) {
|
|
214
335
|
const svg = parseStaticSvg(source);
|
|
215
|
-
return svg && svg.children.every((node) => node.tag === 'path')
|
|
336
|
+
return svg && svg.title === undefined && svg.children.every((node) => node.tag === 'path')
|
|
216
337
|
? { root: svg.root, paths: svg.children.map((node) => node.attributes) }
|
|
217
338
|
: null;
|
|
218
339
|
}
|
|
@@ -14,7 +14,7 @@ function reactClassName(value: unknown) {
|
|
|
14
14
|
// Prepare static props once and create fresh elements for each mounted icon.
|
|
15
15
|
function prepareShape(node: StaticSvgNode, key: number): () => OctaneNode {
|
|
16
16
|
const props = { ...node.attributes, key };
|
|
17
|
-
if (
|
|
17
|
+
if (!containerTags.has(node.tag)) return () => createElement(node.tag, props);
|
|
18
18
|
const children = node.children.map(prepareShape);
|
|
19
19
|
return () => createElement(node.tag, { ...props, children: children.map((render) => render()) });
|
|
20
20
|
}
|
|
@@ -24,6 +24,10 @@ export function pathSvg(source: string, fixedStyle?: string) {
|
|
|
24
24
|
if (!geometry) throw new Error('Expected a raw SVG containing only supported static geometry.');
|
|
25
25
|
const root = fixedStyle === undefined ? geometry.root : { ...geometry.root, style: fixedStyle };
|
|
26
26
|
const children = geometry.children.map(prepareShape);
|
|
27
|
+
if (geometry.title !== undefined) {
|
|
28
|
+
const props = { key: -1, children: geometry.title };
|
|
29
|
+
children.unshift(() => createElement('title', props));
|
|
30
|
+
}
|
|
27
31
|
return function PathSvg(props: {
|
|
28
32
|
className?: unknown;
|
|
29
33
|
'aria-hidden'?: string | boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strong';
|
|
2
2
|
|
|
3
|
-
import { createContext, useContext, useMemo, type OctaneNode } from 'octane';
|
|
3
|
+
import { createContext, memo, useContext, useMemo, type OctaneNode } from 'octane';
|
|
4
4
|
import { ReactCompat } from 'octane/react';
|
|
5
5
|
import type { ChildrenBlock } from 'octane/tsrx-boundary';
|
|
6
6
|
import {
|
|
@@ -87,19 +87,47 @@ export function IntlProvider({
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
type MessageProps = MessageDescriptor &
|
|
90
|
-
Pick<ComponentProps<typeof ReactMessage>, 'values' | 'ignoreTag'
|
|
90
|
+
Pick<ComponentProps<typeof ReactMessage>, 'values' | 'ignoreTag'> & {
|
|
91
|
+
inlineHost?: typeof ReactCompat;
|
|
92
|
+
};
|
|
91
93
|
|
|
92
94
|
function ReactContent({ content }: { content: ReactNode }) {
|
|
93
95
|
return content;
|
|
94
96
|
}
|
|
95
97
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
type MessagePart = string | number | bigint | boolean | null | undefined;
|
|
99
|
+
|
|
100
|
+
function isMessagePart(value: unknown): value is MessagePart {
|
|
101
|
+
return (
|
|
102
|
+
typeof value === 'string' ||
|
|
103
|
+
typeof value === 'number' ||
|
|
104
|
+
typeof value === 'bigint' ||
|
|
105
|
+
typeof value === 'boolean' ||
|
|
106
|
+
value === null ||
|
|
107
|
+
value === undefined
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function plainMessageParts(value: unknown): MessagePart[] | undefined {
|
|
112
|
+
if (
|
|
113
|
+
!Array.isArray(value) ||
|
|
114
|
+
Object.getPrototypeOf(value) !== Array.prototype ||
|
|
115
|
+
Object.hasOwn(value, '$$typeof') ||
|
|
116
|
+
Object.hasOwn(value, 'then')
|
|
117
|
+
)
|
|
118
|
+
return;
|
|
119
|
+
// Copy dense data parts without calling methods or getters on custom formatter output.
|
|
120
|
+
const parts: MessagePart[] = [];
|
|
121
|
+
for (let i = 0, length = value.length; i < length; i++) {
|
|
122
|
+
const part = Object.getOwnPropertyDescriptor(value, i);
|
|
123
|
+
if (!part || !Object.hasOwn(part, 'value') || !isMessagePart(part.value)) return;
|
|
124
|
+
parts.push(part.value);
|
|
125
|
+
}
|
|
126
|
+
return parts;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function NativeFormattedMessage(props: MessageProps) @{
|
|
130
|
+
const { id, defaultMessage, description, values, ignoreTag } = props;
|
|
103
131
|
const intl = useIntl();
|
|
104
132
|
const descriptor = { id, defaultMessage, description };
|
|
105
133
|
const { textComponent, formatMessage } = intl;
|
|
@@ -109,8 +137,33 @@ export function FormattedMessage({
|
|
|
109
137
|
const content = requiresReact
|
|
110
138
|
? reactElement(ReactMessage, { ...descriptor, values, ignoreTag })
|
|
111
139
|
: formatMessage(descriptor, values, { ignoreTag });
|
|
112
|
-
if (
|
|
140
|
+
if (isMessagePart(content)) return content;
|
|
141
|
+
const parts = plainMessageParts(content);
|
|
142
|
+
if (parts) return parts;
|
|
143
|
+
const Island = Object.hasOwn(props, 'inlineHost')
|
|
144
|
+
? (props.inlineHost ?? ReactCompat)
|
|
145
|
+
: ReactCompat;
|
|
113
146
|
<Locale value={intl}>
|
|
114
|
-
<
|
|
147
|
+
<Island component={ReactContent} props={{ content }} contexts={intlContexts} />
|
|
115
148
|
</Locale>
|
|
116
149
|
}
|
|
150
|
+
|
|
151
|
+
function equalOwnValues<T extends object>(before: T | undefined, after: T | undefined): boolean {
|
|
152
|
+
if (before === after) return true;
|
|
153
|
+
if (!before || !after) return false;
|
|
154
|
+
const keys = Object.keys(before) as (keyof T)[];
|
|
155
|
+
if (keys.length !== Object.keys(after).length) return false;
|
|
156
|
+
for (const key of keys) {
|
|
157
|
+
if (before[key] !== after[key] || !Object.hasOwn(after, key)) return false;
|
|
158
|
+
}
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function equalMessages(previous: Readonly<MessageProps>, next: Readonly<MessageProps>): boolean {
|
|
163
|
+
const { values, ...message } = previous;
|
|
164
|
+
const { values: nextValues, ...nextMessage } = next;
|
|
165
|
+
// React Intl compares its values separately with strict equality (including ±0 and NaN).
|
|
166
|
+
return equalOwnValues(nextValues, values) && equalOwnValues(message, nextMessage);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export const FormattedMessage = memo(NativeFormattedMessage, equalMessages);
|