@octanejs/codemod 0.1.4 → 0.2.0
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 +295 -4
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +162 -0
- package/dist/compiler.d.ts +11 -0
- package/dist/compiler.js +48 -0
- package/dist/effect-receivers.d.ts +11 -0
- package/dist/effect-receivers.js +315 -0
- package/dist/expression-wrappers.d.ts +6 -0
- package/dist/expression-wrappers.js +16 -0
- package/dist/forwarded-props.d.ts +27 -0
- package/dist/forwarded-props.js +489 -0
- package/dist/index.d.ts +6 -0
- package/{src → dist}/index.js +1 -0
- package/dist/linked-state.d.ts +17 -0
- package/dist/linked-state.js +126 -0
- package/dist/local-calls.d.ts +20 -0
- package/dist/local-calls.js +143 -0
- package/dist/local-react-hook.d.ts +15 -0
- package/dist/local-react-hook.js +353 -0
- package/dist/local-uses.d.ts +13 -0
- package/dist/local-uses.js +987 -0
- package/dist/mappings.d.ts +57 -0
- package/dist/mappings.js +343 -0
- package/dist/path-svg.d.ts +60 -0
- package/dist/path-svg.js +207 -0
- package/dist/project.d.ts +9 -0
- package/dist/project.js +1568 -0
- package/dist/react-intl.d.ts +4 -0
- package/dist/react-intl.js +389 -0
- package/dist/react-renderer.d.ts +9 -0
- package/dist/react-renderer.js +106 -0
- package/dist/scoped-signal.d.ts +4 -0
- package/dist/scoped-signal.js +480 -0
- package/dist/scoped-store-contract.d.ts +13 -0
- package/dist/scoped-store-contract.js +741 -0
- package/dist/store-hook-uses.d.ts +18 -0
- package/dist/store-hook-uses.js +403 -0
- package/dist/store-inputs.d.ts +16 -0
- package/dist/store-inputs.js +391 -0
- package/dist/strong.d.ts +24 -0
- package/dist/strong.js +142 -0
- package/dist/transform.d.ts +27 -0
- package/dist/transform.js +4890 -0
- package/dist/types.d.ts +203 -0
- package/dist/types.js +1 -0
- package/package.json +18 -6
- package/src/path-svg.ts +218 -0
- package/templates/octane-path-svg.ts +56 -0
- package/templates/octane-store-context.tsrx +49 -0
- package/templates/octane-store-hooks.ts +61 -0
- package/templates/react-intl.tsrx +116 -0
- package/src/bin.js +0 -151
- package/src/compiler.js +0 -61
- package/src/index.d.ts +0 -95
- package/src/mappings.js +0 -429
- package/src/project.js +0 -738
- package/src/strong.js +0 -149
- package/src/transform.js +0 -3455
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What each React module name means in Octane.
|
|
3
|
+
*
|
|
4
|
+
* Values and types are listed separately because Octane exports React's type
|
|
5
|
+
* names as migration aliases (`ReactNode`, `ChangeEvent`, `FC`, ...), while
|
|
6
|
+
* several React values have no Octane counterpart at all and need a rewrite or a
|
|
7
|
+
* person (`forwardRef`, class components).
|
|
8
|
+
*/
|
|
9
|
+
/** Modules whose imports this codemod owns, and the Octane module each becomes. * */
|
|
10
|
+
export declare const REACT_MODULES: Record<string, string>;
|
|
11
|
+
/** The types among them, which a named import reads as an alias, not a value. */
|
|
12
|
+
export declare const RADIX_TYPES: Set<string>;
|
|
13
|
+
/**
|
|
14
|
+
* React packages ported outside the binding catalog: a framework integration,
|
|
15
|
+
* TanStack's own adapters, and Radix's primitive packages, which
|
|
16
|
+
* `@octanejs/radix` serves as namespaces.
|
|
17
|
+
*/
|
|
18
|
+
export declare const PORTED_PACKAGES: Record<string, string>;
|
|
19
|
+
/**
|
|
20
|
+
* The `@octanejs/radix` namespace a Radix package's imports become, or null.
|
|
21
|
+
* `@radix-ui/react-slot` has none: its exports are the binding's own.
|
|
22
|
+
*/
|
|
23
|
+
export declare function radixNamespace(module: string): string | null;
|
|
24
|
+
/**
|
|
25
|
+
* The name an export of a ported package has in its port, or null when the
|
|
26
|
+
* port has none. Other packages keep every name.
|
|
27
|
+
*/
|
|
28
|
+
export declare function mapPackageExport(module: string, name: string): string | null;
|
|
29
|
+
/** Why the port of a ported package has no `name`. */
|
|
30
|
+
export declare function missingExport(module: string, name: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* React values with no Octane export, each with what to do instead. A value
|
|
33
|
+
* listed here is never imported from Octane; the codemod either rewrites its
|
|
34
|
+
* uses or reports them.
|
|
35
|
+
*/
|
|
36
|
+
export declare const UNSUPPORTED_VALUES: Record<string, string>;
|
|
37
|
+
/**
|
|
38
|
+
* @param module a key of {@link REACT_MODULES}
|
|
39
|
+
* @param name the imported name
|
|
40
|
+
* @returns null when the import needs a manual migration
|
|
41
|
+
*/
|
|
42
|
+
export declare function mapReactImport(module: string, name: string, typeOnly: boolean): {
|
|
43
|
+
module: string;
|
|
44
|
+
name: string;
|
|
45
|
+
} | null;
|
|
46
|
+
/** The Octane name for `React.<name>` in a type position. */
|
|
47
|
+
export declare function mapQualifiedType(name: string): string | null;
|
|
48
|
+
/** Built-in hooks whose omitted dependency list Octane infers. * */
|
|
49
|
+
export declare const DEPENDENCY_HOOKS: Record<string, number>;
|
|
50
|
+
/** `<input type>` values whose native `change` fires on commit, not per edit. */
|
|
51
|
+
export declare const TEXT_INPUT_TYPES: Set<string>;
|
|
52
|
+
/**
|
|
53
|
+
* Library components that render a text `<input>` and hand it the `onChange`
|
|
54
|
+
* they receive, by the module that exports each: React fires that per edit, as
|
|
55
|
+
* on the element itself.
|
|
56
|
+
*/
|
|
57
|
+
export declare const TEXT_FIELD_COMPONENTS: Record<string, string[]>;
|
package/dist/mappings.js
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What each React module name means in Octane.
|
|
3
|
+
*
|
|
4
|
+
* Values and types are listed separately because Octane exports React's type
|
|
5
|
+
* names as migration aliases (`ReactNode`, `ChangeEvent`, `FC`, ...), while
|
|
6
|
+
* several React values have no Octane counterpart at all and need a rewrite or a
|
|
7
|
+
* person (`forwardRef`, class components).
|
|
8
|
+
*/
|
|
9
|
+
/** React value exports that exist in `octane` under the same name. */
|
|
10
|
+
const OCTANE_VALUES = new Set([
|
|
11
|
+
'Activity',
|
|
12
|
+
'Children',
|
|
13
|
+
'Fragment',
|
|
14
|
+
'StrictMode',
|
|
15
|
+
'Suspense',
|
|
16
|
+
'ViewTransition',
|
|
17
|
+
'act',
|
|
18
|
+
'addTransitionType',
|
|
19
|
+
'cloneElement',
|
|
20
|
+
'createContext',
|
|
21
|
+
'createElement',
|
|
22
|
+
'createPortal',
|
|
23
|
+
'createRoot',
|
|
24
|
+
'flushSync',
|
|
25
|
+
'hydrateRoot',
|
|
26
|
+
'isValidElement',
|
|
27
|
+
'lazy',
|
|
28
|
+
'memo',
|
|
29
|
+
'preconnect',
|
|
30
|
+
'prefetchDNS',
|
|
31
|
+
'preinit',
|
|
32
|
+
'preinitModule',
|
|
33
|
+
'preload',
|
|
34
|
+
'preloadModule',
|
|
35
|
+
'requestFormReset',
|
|
36
|
+
'startTransition',
|
|
37
|
+
'unstable_Activity',
|
|
38
|
+
'unstable_ViewTransition',
|
|
39
|
+
'unstable_addTransitionType',
|
|
40
|
+
'unstable_batchedUpdates',
|
|
41
|
+
'use',
|
|
42
|
+
'useActionState',
|
|
43
|
+
'useCallback',
|
|
44
|
+
'useContext',
|
|
45
|
+
'useDebugValue',
|
|
46
|
+
'useDeferredValue',
|
|
47
|
+
'useEffect',
|
|
48
|
+
'useEffectEvent',
|
|
49
|
+
'useFormState',
|
|
50
|
+
'useFormStatus',
|
|
51
|
+
'useId',
|
|
52
|
+
'useImperativeHandle',
|
|
53
|
+
'useInsertionEffect',
|
|
54
|
+
'useLayoutEffect',
|
|
55
|
+
'useMemo',
|
|
56
|
+
'useOptimistic',
|
|
57
|
+
'useReducer',
|
|
58
|
+
'useRef',
|
|
59
|
+
'useState',
|
|
60
|
+
'useSyncExternalStore',
|
|
61
|
+
'useTransition',
|
|
62
|
+
'version',
|
|
63
|
+
]);
|
|
64
|
+
/** `react-dom/server` names served by `octane/server`. */
|
|
65
|
+
const OCTANE_SERVER_VALUES = new Set([
|
|
66
|
+
'renderToPipeableStream',
|
|
67
|
+
'renderToReadableStream',
|
|
68
|
+
'renderToStaticMarkup',
|
|
69
|
+
'renderToString',
|
|
70
|
+
]);
|
|
71
|
+
/** React and React DOM type names `octane` exports as-is. */
|
|
72
|
+
const OCTANE_TYPES = new Set(('AllHTMLAttributes AnchorHTMLAttributes AnimationEvent AnimationEventHandler AreaHTMLAttributes ' +
|
|
73
|
+
'AriaAttributes AriaRole Attributes AudioHTMLAttributes BaseHTMLAttributes BlockquoteHTMLAttributes ' +
|
|
74
|
+
'Booleanish ButtonHTMLAttributes CSSProperties CanvasHTMLAttributes ChangeEvent ChangeEventHandler ' +
|
|
75
|
+
'ClipboardEvent ClipboardEventHandler ColHTMLAttributes ColgroupHTMLAttributes ComponentProps ' +
|
|
76
|
+
'ComponentPropsWithRef ComponentPropsWithoutRef ComponentRef ComponentType CompositionEvent ' +
|
|
77
|
+
'CompositionEventHandler Context ContextType CrossOrigin CustomComponentPropsWithRef DOMAttributes ' +
|
|
78
|
+
'DOMElement DataHTMLAttributes DelHTMLAttributes DependencyList Destructor DetailedHTMLProps ' +
|
|
79
|
+
'DetailedReactHTMLElement DetailsHTMLAttributes DialogHTMLAttributes Dispatch DispatchWithoutAction ' +
|
|
80
|
+
'DragEvent DragEventHandler EffectCallback ElementRef ElementType EmbedHTMLAttributes EventHandler ' +
|
|
81
|
+
'ExoticComponent FC FieldsetHTMLAttributes FocusEvent FocusEventHandler FormEvent FormEventHandler ' +
|
|
82
|
+
'FormHTMLAttributes FunctionComponent FunctionComponentElement HTMLAttributeAnchorTarget ' +
|
|
83
|
+
'HTMLAttributeReferrerPolicy HTMLAttributes HTMLInputTypeAttribute HTMLProps HtmlHTMLAttributes ' +
|
|
84
|
+
'IframeHTMLAttributes ImgHTMLAttributes InputEvent InputEventHandler InputHTMLAttributes ' +
|
|
85
|
+
'InsHTMLAttributes InvalidEvent InvalidEventHandler JSX JSXElementConstructor Key KeyboardEvent ' +
|
|
86
|
+
'KeyboardEventHandler KeygenHTMLAttributes LabelHTMLAttributes LazyExoticComponent LiHTMLAttributes ' +
|
|
87
|
+
'LinkHTMLAttributes MapHTMLAttributes MemoExoticComponent MenuHTMLAttributes MetaHTMLAttributes ' +
|
|
88
|
+
'MeterHTMLAttributes MouseEvent MouseEventHandler MutableRefObject NamedExoticComponent ' +
|
|
89
|
+
'ObjectHTMLAttributes OlHTMLAttributes OptgroupHTMLAttributes OptionHTMLAttributes ' +
|
|
90
|
+
'OutputHTMLAttributes ParamHTMLAttributes PointerEvent PointerEventHandler ProgressHTMLAttributes ' +
|
|
91
|
+
'PropsWithChildren PropsWithRef PropsWithoutRef Provider ProviderProps QuoteHTMLAttributes ' +
|
|
92
|
+
'ReactElement ReactHTMLElement ReactNode ReactPortal ReactSVGElement Reducer ReducerAction ' +
|
|
93
|
+
'ReducerState ReducerStateWithoutAction ReducerWithoutAction Ref RefAttributes RefCallback RefObject Root ' +
|
|
94
|
+
'SVGAttributes SVGLineElementAttributes SVGProps SVGTextElementAttributes ScriptHTMLAttributes ' +
|
|
95
|
+
'SelectHTMLAttributes SetStateAction SlotHTMLAttributes SourceHTMLAttributes StrictModeProps ' +
|
|
96
|
+
'StyleHTMLAttributes SuspenseProps TableHTMLAttributes TdHTMLAttributes TextareaHTMLAttributes ' +
|
|
97
|
+
'ThHTMLAttributes TimeHTMLAttributes ToggleEvent ToggleEventHandler TouchEvent TouchEventHandler ' +
|
|
98
|
+
'TrackHTMLAttributes TransitionEvent TransitionEventHandler UIEvent UIEventHandler ' +
|
|
99
|
+
'VideoHTMLAttributes WebViewHTMLAttributes WheelEvent WheelEventHandler').split(' '));
|
|
100
|
+
/**
|
|
101
|
+
* React type names with an Octane spelling of their own. `ReactNode` keeps its
|
|
102
|
+
* alias when imported by name, so only namespace-qualified uses change; the
|
|
103
|
+
* rest have no alias in Octane.
|
|
104
|
+
*/
|
|
105
|
+
const RENAMED_TYPES = {
|
|
106
|
+
BaseSyntheticEvent: 'NativeEvent',
|
|
107
|
+
ForwardRefExoticComponent: 'FC',
|
|
108
|
+
ForwardedRef: 'Ref',
|
|
109
|
+
LegacyRef: 'Ref',
|
|
110
|
+
ReactChild: 'OctaneNode',
|
|
111
|
+
ReactFragment: 'OctaneNode',
|
|
112
|
+
ReactText: 'OctaneNode',
|
|
113
|
+
SyntheticEvent: 'NativeEvent',
|
|
114
|
+
};
|
|
115
|
+
/** Namespace-qualified spellings that read better as Octane's own name. * */
|
|
116
|
+
const QUALIFIED_TYPE_PREFERENCES = {
|
|
117
|
+
ReactElement: 'OctaneElement',
|
|
118
|
+
ReactNode: 'OctaneNode',
|
|
119
|
+
};
|
|
120
|
+
/** Modules whose imports this codemod owns, and the Octane module each becomes. * */
|
|
121
|
+
export const REACT_MODULES = {
|
|
122
|
+
react: 'octane',
|
|
123
|
+
'react-dom': 'octane',
|
|
124
|
+
'react-dom/client': 'octane',
|
|
125
|
+
'react-dom/server': 'octane/server',
|
|
126
|
+
'react-dom/server.browser': 'octane/server',
|
|
127
|
+
'react-dom/server.bun': 'octane/server',
|
|
128
|
+
'react-dom/server.edge': 'octane/server',
|
|
129
|
+
'react-dom/server.node': 'octane/server',
|
|
130
|
+
'react-dom/test-utils': 'octane',
|
|
131
|
+
'react/jsx-runtime': 'octane/jsx-runtime',
|
|
132
|
+
'react/jsx-dev-runtime': 'octane/jsx-dev-runtime',
|
|
133
|
+
// React's `useSyncExternalStore` for React 17 and earlier.
|
|
134
|
+
'use-sync-external-store': 'octane',
|
|
135
|
+
'use-sync-external-store/shim': 'octane',
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* What `@octanejs/radix` exports in each namespace. A namespace ports the
|
|
139
|
+
* `@radix-ui/react-*` package it names, as `Dialog` ports
|
|
140
|
+
* `@radix-ui/react-dialog`, except `Slot`, whose exports are the binding's own.
|
|
141
|
+
* A codemod test checks it against the binding and the Radix packages.
|
|
142
|
+
*/
|
|
143
|
+
const RADIX = Object.fromEntries(Object.entries({
|
|
144
|
+
AccessibleIcon: 'AccessibleIcon Root',
|
|
145
|
+
Accordion: 'Accordion Content Header Item Root Trigger createAccordionScope',
|
|
146
|
+
AlertDialog: 'Action AlertDialog Cancel Content Description Overlay Portal Root Title Trigger createAlertDialogScope',
|
|
147
|
+
Arrow: 'Arrow Root',
|
|
148
|
+
AspectRatio: 'AspectRatio Root',
|
|
149
|
+
Avatar: 'Avatar AvatarFallback AvatarImage Fallback Image Root createAvatarScope',
|
|
150
|
+
Checkbox: 'BubbleInput Checkbox CheckboxBubbleInput CheckboxIndicator CheckboxProvider CheckboxTrigger CheckedState Indicator Provider Root Trigger createCheckboxScope',
|
|
151
|
+
Collapsible: 'Collapsible Content Root Trigger createCollapsibleContext createCollapsibleScope useCollapsibleContext',
|
|
152
|
+
ContextMenu: 'Arrow CheckboxItem Content ContextMenu ContextMenuContent ContextMenuItem ContextMenuTrigger Group Item ItemIndicator Label Portal RadioGroup RadioItem Root Separator Sub SubContent SubTrigger Trigger createContextMenuScope',
|
|
153
|
+
Dialog: 'Close Content Description Dialog Overlay Portal Root Title Trigger createDialogContext createDialogScope',
|
|
154
|
+
Direction: 'DirectionProvider Provider useDirection',
|
|
155
|
+
DropdownMenu: 'Arrow CheckboxItem Content DropdownMenu DropdownMenuContent DropdownMenuItem DropdownMenuTrigger Group Item ItemIndicator Label Portal RadioGroup RadioItem Root Separator Sub SubContent SubTrigger Trigger createDropdownMenuScope',
|
|
156
|
+
Form: 'Control Field Form FormControl FormField FormLabel FormMessage FormSubmit FormValidityState Label Message Root Submit ValidityState createFormScope',
|
|
157
|
+
HoverCard: 'Arrow Content HoverCard HoverCardContent HoverCardTrigger Portal Root Trigger createHoverCardScope',
|
|
158
|
+
Label: 'Label Root',
|
|
159
|
+
Menu: 'Anchor Arrow CheckboxItem Content Group Item ItemIndicator Label Menu MenuAnchor MenuContent MenuItem Portal RadioGroup RadioItem Root Separator Sub SubContent SubTrigger createMenuScope',
|
|
160
|
+
Menubar: 'Arrow CheckboxItem Content Group Item ItemIndicator Label Menu Menubar MenubarArrow MenubarCheckboxItem MenubarContent MenubarGroup MenubarItem MenubarItemIndicator MenubarLabel MenubarMenu MenubarPortal MenubarRadioGroup MenubarRadioItem MenubarSeparator MenubarSub MenubarSubContent MenubarSubTrigger MenubarTrigger Portal RadioGroup RadioItem Root Separator Sub SubContent SubTrigger Trigger createMenubarScope',
|
|
161
|
+
NavigationMenu: 'Content Indicator Item Link List NavigationMenu NavigationMenuContent NavigationMenuIndicator NavigationMenuItem NavigationMenuLink NavigationMenuList NavigationMenuSub NavigationMenuTrigger NavigationMenuViewport Root Sub Trigger Viewport createNavigationMenuScope',
|
|
162
|
+
OneTimePasswordField: 'HiddenInput Input InputValidationType OneTimePasswordField OneTimePasswordFieldHiddenInput OneTimePasswordFieldInput Root createOneTimePasswordFieldScope',
|
|
163
|
+
PasswordToggleField: 'Icon Input PasswordToggleField PasswordToggleFieldIcon PasswordToggleFieldInput PasswordToggleFieldSlot PasswordToggleFieldToggle Root Slot Toggle createPasswordToggleFieldScope',
|
|
164
|
+
Popover: 'Anchor Arrow Close Content Popover PopoverAnchor PopoverTrigger Portal Root Trigger createPopoverScope',
|
|
165
|
+
Popper: 'ALIGN_OPTIONS Anchor Arrow Content Popper PopperAnchor PopperArrow PopperContent Root SIDE_OPTIONS createPopperScope',
|
|
166
|
+
Portal: 'Portal Root',
|
|
167
|
+
Progress: 'Indicator Progress ProgressIndicator Root createProgressScope',
|
|
168
|
+
RadioGroup: 'Indicator Item RadioGroup RadioGroupIndicator RadioGroupItem RadioGroupItemBubbleInput RadioGroupItemProvider RadioGroupItemTrigger Root createRadioGroupScope',
|
|
169
|
+
RovingFocus: 'Item Root RovingFocusGroup RovingFocusGroupItem createRovingFocusGroupContext createRovingFocusGroupScope',
|
|
170
|
+
ScrollArea: 'Corner Root ScrollArea ScrollAreaCorner ScrollAreaScrollbar ScrollAreaThumb ScrollAreaViewport Scrollbar Thumb Viewport createScrollAreaScope',
|
|
171
|
+
Select: 'Arrow BubbleInput Content Group Icon Item ItemIndicator ItemText Label Portal Provider Root ScrollDownButton ScrollUpButton Select SelectArrow SelectBubbleInput SelectContent SelectGroup SelectIcon SelectItem SelectItemIndicator SelectItemText SelectLabel SelectPortal SelectProvider SelectScrollDownButton SelectScrollUpButton SelectSeparator SelectTrigger SelectValue SelectViewport Separator Trigger Value Viewport createSelectScope',
|
|
172
|
+
Separator: 'Root Separator',
|
|
173
|
+
Slider: 'BubbleInput Range Root Slider SliderBubbleInput SliderRange SliderThumb SliderThumbProvider SliderThumbTrigger SliderTrack Thumb Track createSliderScope',
|
|
174
|
+
Slot: 'Slot Slottable',
|
|
175
|
+
Switch: 'BubbleInput Provider Root Switch SwitchBubbleInput SwitchProvider SwitchThumb SwitchTrigger Thumb Trigger createSwitchScope',
|
|
176
|
+
Tabs: 'Content List Root Tabs Trigger createTabsScope',
|
|
177
|
+
Toast: 'Action Close Description Provider Root Title Toast ToastAction ToastClose ToastDescription ToastProvider ToastTitle ToastViewport Viewport createToastScope',
|
|
178
|
+
Toggle: 'Root Toggle',
|
|
179
|
+
ToggleGroup: 'Item Root ToggleGroup ToggleGroupItem createToggleGroupScope',
|
|
180
|
+
Toolbar: 'Button Link Root Separator ToggleGroup ToggleItem Toolbar ToolbarButton ToolbarLink createToolbarScope',
|
|
181
|
+
Tooltip: 'Arrow Content Portal Provider Root Tooltip TooltipProvider Trigger createTooltipScope',
|
|
182
|
+
VisuallyHidden: 'Root VISUALLY_HIDDEN_STYLES VisuallyHidden',
|
|
183
|
+
}).map(([namespace, names]) => [namespace, new Set(names.split(' '))]));
|
|
184
|
+
/** The types among them, which a named import reads as an alias, not a value. */
|
|
185
|
+
export const RADIX_TYPES = new Set(['CheckedState', 'InputValidationType']);
|
|
186
|
+
/** Each Radix package the binding ports, and its namespace. */
|
|
187
|
+
const RADIX_PACKAGES = new Map(Object.keys(RADIX).map((namespace) => [
|
|
188
|
+
`@radix-ui/react-${namespace.replace(/[A-Z]/g, (c, i) => (i ? '-' : '') + c.toLowerCase())}`,
|
|
189
|
+
namespace,
|
|
190
|
+
]));
|
|
191
|
+
/**
|
|
192
|
+
* The adapters TanStack publishes for Octane, by the React adapter each
|
|
193
|
+
* replaces, with the exports each lacks and what to do instead.
|
|
194
|
+
*/
|
|
195
|
+
const TANSTACK_ADAPTERS = {
|
|
196
|
+
'@tanstack/react-hotkeys': {},
|
|
197
|
+
'@tanstack/react-pacer': {
|
|
198
|
+
usePacerContext: "`@tanstack/octane-pacer` has no `usePacerContext`; read the provider's options with `useDefaultPacerOptions()`.",
|
|
199
|
+
},
|
|
200
|
+
'@tanstack/react-table': Object.fromEntries(('getCoreRowModel getExpandedRowModel getFacetedMinMaxValues getFacetedRowModel ' +
|
|
201
|
+
'getFacetedUniqueValues getFilteredRowModel getGroupedRowModel getPaginationRowModel ' +
|
|
202
|
+
'getSortedRowModel legacyCreateColumnHelper sortingFns useLegacyTable useReactTable')
|
|
203
|
+
.split(' ')
|
|
204
|
+
.map((name) => [
|
|
205
|
+
name,
|
|
206
|
+
`\`${name}\` is TanStack Table v8's API, which \`@tanstack/octane-table\` does not adapt: move to v9's \`useTable\`, with \`_features\` and \`_rowModels\`, first.`,
|
|
207
|
+
])),
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* React packages ported outside the binding catalog: a framework integration,
|
|
211
|
+
* TanStack's own adapters, and Radix's primitive packages, which
|
|
212
|
+
* `@octanejs/radix` serves as namespaces.
|
|
213
|
+
*/
|
|
214
|
+
export const PORTED_PACKAGES = {
|
|
215
|
+
'@floating-ui/react-dom': '@octanejs/floating-ui/react-dom',
|
|
216
|
+
'@tanstack/react-start': '@octanejs/tanstack-start',
|
|
217
|
+
...Object.fromEntries(Object.keys(TANSTACK_ADAPTERS).map((name) => [name, name.replace('/react-', '/octane-')])),
|
|
218
|
+
...Object.fromEntries([...RADIX_PACKAGES.keys()].map((name) => [name, '@octanejs/radix'])),
|
|
219
|
+
};
|
|
220
|
+
/**
|
|
221
|
+
* The `@octanejs/radix` namespace a Radix package's imports become, or null.
|
|
222
|
+
* `@radix-ui/react-slot` has none: its exports are the binding's own.
|
|
223
|
+
*/
|
|
224
|
+
export function radixNamespace(module) {
|
|
225
|
+
const namespace = RADIX_PACKAGES.get(module) ?? null;
|
|
226
|
+
return namespace === 'Slot' ? null : namespace;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* The name an export of a ported package has in its port, or null when the
|
|
230
|
+
* port has none. Other packages keep every name.
|
|
231
|
+
*/
|
|
232
|
+
export function mapPackageExport(module, name) {
|
|
233
|
+
const namespace = RADIX_PACKAGES.get(module);
|
|
234
|
+
if (namespace !== undefined) {
|
|
235
|
+
const names = RADIX[namespace];
|
|
236
|
+
if (names.has(name))
|
|
237
|
+
return name;
|
|
238
|
+
// Radix exports each part twice, as `Content` and `DialogContent`, with
|
|
239
|
+
// `Root` as `Dialog`, and a part still in preview as `unstable_Content`.
|
|
240
|
+
const prefix = new RegExp(`^(?:unstable_)?(?:${namespace}(?![a-z]))?`);
|
|
241
|
+
const part = (name) => name.replace(prefix, '') || 'Root';
|
|
242
|
+
const wanted = part(name);
|
|
243
|
+
if (names.has(wanted))
|
|
244
|
+
return wanted;
|
|
245
|
+
return [...names].find((candidate) => part(candidate) === wanted) ?? null;
|
|
246
|
+
}
|
|
247
|
+
const adapter = adapterOf(module);
|
|
248
|
+
if (adapter === undefined)
|
|
249
|
+
return name;
|
|
250
|
+
if (Object.hasOwn(adapter, name))
|
|
251
|
+
return null;
|
|
252
|
+
// The adapters name their framework in their types: `ReactTable` is `OctaneTable`.
|
|
253
|
+
return name.replace(/React(?=[A-Z])/, 'Octane');
|
|
254
|
+
}
|
|
255
|
+
/** Why the port of a ported package has no `name`. */
|
|
256
|
+
export function missingExport(module, name) {
|
|
257
|
+
const adapter = adapterOf(module);
|
|
258
|
+
if (adapter !== undefined)
|
|
259
|
+
return adapter[name];
|
|
260
|
+
const namespace = RADIX_PACKAGES.get(module);
|
|
261
|
+
return `\`@octanejs/radix\` has no \`${namespace === 'Slot' ? name : `${namespace}.${name}`}\`.`;
|
|
262
|
+
}
|
|
263
|
+
/** The TanStack adapter a specifier imports, by its package. */
|
|
264
|
+
function adapterOf(module) {
|
|
265
|
+
const name = module.split('/', 2).join('/');
|
|
266
|
+
return Object.hasOwn(TANSTACK_ADAPTERS, name) ? TANSTACK_ADAPTERS[name] : undefined;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* React values with no Octane export, each with what to do instead. A value
|
|
270
|
+
* listed here is never imported from Octane; the codemod either rewrites its
|
|
271
|
+
* uses or reports them.
|
|
272
|
+
*/
|
|
273
|
+
export const UNSUPPORTED_VALUES = {
|
|
274
|
+
Component: 'Class components are not supported. Convert it to a function component.',
|
|
275
|
+
PureComponent: 'Class components are not supported. Convert it to a function component with `memo`.',
|
|
276
|
+
Profiler: 'Octane has no `Profiler`; use the Octane devtools profiler.',
|
|
277
|
+
SuspenseList: 'Octane has no `SuspenseList`.',
|
|
278
|
+
cache: 'Server Components are not supported, so `cache` has no Octane equivalent.',
|
|
279
|
+
cacheSignal: 'Server Components are not supported, so `cacheSignal` has no Octane equivalent.',
|
|
280
|
+
captureOwnerStack: 'Octane does not collect owner stacks.',
|
|
281
|
+
findDOMNode: 'Octane has no `findDOMNode`; pass a ref to the host element.',
|
|
282
|
+
forwardRef: 'Refs are props in Octane; the codemod unwraps `forwardRef` where it can.',
|
|
283
|
+
hydrate: 'Legacy roots are not supported; the codemod rewrites calls to `hydrateRoot`.',
|
|
284
|
+
render: 'Legacy roots are not supported; the codemod rewrites calls to `createRoot(...).render`.',
|
|
285
|
+
unmountComponentAtNode: 'Legacy roots are not supported; keep the `createRoot` result and call `root.unmount()`.',
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* @param module a key of {@link REACT_MODULES}
|
|
289
|
+
* @param name the imported name
|
|
290
|
+
* @returns null when the import needs a manual migration
|
|
291
|
+
*/
|
|
292
|
+
export function mapReactImport(module, name, typeOnly) {
|
|
293
|
+
// The allocator is renderer-independent and preserves React's ref object shape.
|
|
294
|
+
if (module === 'react' && name === 'createRef')
|
|
295
|
+
return { module, name };
|
|
296
|
+
if (module === 'react-dom/server' || module.startsWith('react-dom/server.')) {
|
|
297
|
+
return OCTANE_SERVER_VALUES.has(name) ? { module: 'octane/server', name } : null;
|
|
298
|
+
}
|
|
299
|
+
if (!typeOnly && OCTANE_VALUES.has(name))
|
|
300
|
+
return { module: 'octane', name };
|
|
301
|
+
if (OCTANE_TYPES.has(name))
|
|
302
|
+
return { module: 'octane', name };
|
|
303
|
+
if (name in RENAMED_TYPES)
|
|
304
|
+
return { module: 'octane', name: RENAMED_TYPES[name] };
|
|
305
|
+
return null;
|
|
306
|
+
}
|
|
307
|
+
/** The Octane name for `React.<name>` in a type position. */
|
|
308
|
+
export function mapQualifiedType(name) {
|
|
309
|
+
if (name in QUALIFIED_TYPE_PREFERENCES)
|
|
310
|
+
return QUALIFIED_TYPE_PREFERENCES[name];
|
|
311
|
+
if (OCTANE_TYPES.has(name))
|
|
312
|
+
return name;
|
|
313
|
+
return RENAMED_TYPES[name] ?? null;
|
|
314
|
+
}
|
|
315
|
+
/** Built-in hooks whose omitted dependency list Octane infers. * */
|
|
316
|
+
export const DEPENDENCY_HOOKS = {
|
|
317
|
+
useCallback: 1,
|
|
318
|
+
useEffect: 1,
|
|
319
|
+
useImperativeHandle: 2,
|
|
320
|
+
useInsertionEffect: 1,
|
|
321
|
+
useLayoutEffect: 1,
|
|
322
|
+
useMemo: 1,
|
|
323
|
+
};
|
|
324
|
+
/** `<input type>` values whose native `change` fires on commit, not per edit. */
|
|
325
|
+
export const TEXT_INPUT_TYPES = new Set([
|
|
326
|
+
'text',
|
|
327
|
+
'search',
|
|
328
|
+
'url',
|
|
329
|
+
'tel',
|
|
330
|
+
'password',
|
|
331
|
+
'email',
|
|
332
|
+
'number',
|
|
333
|
+
]);
|
|
334
|
+
/**
|
|
335
|
+
* Library components that render a text `<input>` and hand it the `onChange`
|
|
336
|
+
* they receive, by the module that exports each: React fires that per edit, as
|
|
337
|
+
* on the element itself.
|
|
338
|
+
*/
|
|
339
|
+
export const TEXT_FIELD_COMPONENTS = {
|
|
340
|
+
'@base-ui/react': ['Input', 'Field.Control'],
|
|
341
|
+
'@base-ui/react/input': ['Input'],
|
|
342
|
+
'@base-ui/react/field': ['Field.Control'],
|
|
343
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export declare function svgLiteralRootOverride(name: string, value: string): boolean;
|
|
2
|
+
declare const shapeAttributes: {
|
|
3
|
+
path: {
|
|
4
|
+
transform: RegExp;
|
|
5
|
+
d: RegExp;
|
|
6
|
+
'fill-rule': RegExp;
|
|
7
|
+
'clip-rule': RegExp;
|
|
8
|
+
'stroke-opacity': RegExp;
|
|
9
|
+
fill: RegExp;
|
|
10
|
+
stroke: RegExp;
|
|
11
|
+
'stroke-width': RegExp;
|
|
12
|
+
'stroke-linecap': RegExp;
|
|
13
|
+
'stroke-linejoin': RegExp;
|
|
14
|
+
opacity: RegExp;
|
|
15
|
+
};
|
|
16
|
+
rect: {
|
|
17
|
+
fill: RegExp;
|
|
18
|
+
x: RegExp;
|
|
19
|
+
y: RegExp;
|
|
20
|
+
width: RegExp;
|
|
21
|
+
height: RegExp;
|
|
22
|
+
rx: RegExp;
|
|
23
|
+
ry: RegExp;
|
|
24
|
+
stroke: RegExp;
|
|
25
|
+
'stroke-width': RegExp;
|
|
26
|
+
'stroke-linecap': RegExp;
|
|
27
|
+
'stroke-linejoin': RegExp;
|
|
28
|
+
opacity: RegExp;
|
|
29
|
+
};
|
|
30
|
+
g: {
|
|
31
|
+
transform: RegExp;
|
|
32
|
+
'clip-path': RegExp;
|
|
33
|
+
};
|
|
34
|
+
defs: {};
|
|
35
|
+
clipPath: {
|
|
36
|
+
id: RegExp;
|
|
37
|
+
};
|
|
38
|
+
pattern: {
|
|
39
|
+
id: RegExp;
|
|
40
|
+
width: RegExp;
|
|
41
|
+
height: RegExp;
|
|
42
|
+
patternUnits: RegExp;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export declare function svgDataAttribute(name: string): name is `data-${string}`;
|
|
46
|
+
type StaticSvgNode = {
|
|
47
|
+
tag: keyof typeof shapeAttributes;
|
|
48
|
+
attributes: Record<string, string>;
|
|
49
|
+
children: StaticSvgNode[];
|
|
50
|
+
};
|
|
51
|
+
/** Read authored geometry with a single local clip or paint definition. */
|
|
52
|
+
export declare function parseStaticSvg(source: string): {
|
|
53
|
+
root: Record<string, string>;
|
|
54
|
+
children: StaticSvgNode[];
|
|
55
|
+
} | null;
|
|
56
|
+
export declare function parsePathSvg(source: string): {
|
|
57
|
+
root: Record<string, string>;
|
|
58
|
+
paths: Record<string, string>[];
|
|
59
|
+
} | null;
|
|
60
|
+
export {};
|
package/dist/path-svg.js
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
const space = /^[ \t\r\n]*$/;
|
|
2
|
+
const number = '[+-]?(?:[0-9]+(?:\\.[0-9]*)?|\\.[0-9]+)(?:[eE][+-]?[0-9]+)?';
|
|
3
|
+
const length = new RegExp('^' + number + '(?:px|em|rem|%)?$');
|
|
4
|
+
const extent = new RegExp('^(?!-)' + number + '(?:px|em|rem|%)?$');
|
|
5
|
+
const separator = '(?: *, *| +)';
|
|
6
|
+
const paint = /^(?:[a-zA-Z]+|#[\da-fA-F]{3,4}|#[\da-fA-F]{6}(?:[\da-fA-F]{2})?|var\(--[A-Za-z_][A-Za-z0-9_-]*\))$/;
|
|
7
|
+
const opacity = /^(?:0|0?\.\d+|1)$/;
|
|
8
|
+
const nextNumber = '(?:' + separator + number + ')';
|
|
9
|
+
const operation = '(?:(?:scale|translate)\\(' +
|
|
10
|
+
number +
|
|
11
|
+
nextNumber +
|
|
12
|
+
'?\\)|matrix\\(' +
|
|
13
|
+
number +
|
|
14
|
+
nextNumber +
|
|
15
|
+
'{5}\\))';
|
|
16
|
+
const transform = new RegExp('^' + operation + '(?:' + separator + operation + ')*$');
|
|
17
|
+
const transformNumbers = new RegExp(number, 'g');
|
|
18
|
+
const localPaint = /^url\(#[A-Za-z_][A-Za-z0-9_-]*\)$/;
|
|
19
|
+
const tileSize = /^[1-9]\d*$/;
|
|
20
|
+
const rootAttributes = {
|
|
21
|
+
preserveAspectRatio: /^none$/,
|
|
22
|
+
xmlns: /^http:\/\/www\.w3\.org\/2000\/svg$/,
|
|
23
|
+
width: length,
|
|
24
|
+
height: length,
|
|
25
|
+
viewBox: new RegExp('^' + number + '(?:' + separator + number + '){3}$'),
|
|
26
|
+
fill: paint,
|
|
27
|
+
role: /^img$/,
|
|
28
|
+
focusable: /^(?:true|false)$/,
|
|
29
|
+
};
|
|
30
|
+
export function svgLiteralRootOverride(name, value) {
|
|
31
|
+
return (name === 'fill' || name === 'focusable') && rootAttributes[name].test(value);
|
|
32
|
+
}
|
|
33
|
+
const fillRule = /^(?:evenodd|nonzero)$/;
|
|
34
|
+
const presentation = {
|
|
35
|
+
fill: paint,
|
|
36
|
+
stroke: paint,
|
|
37
|
+
'stroke-width': length,
|
|
38
|
+
'stroke-linecap': /^(?:butt|round|square)$/,
|
|
39
|
+
'stroke-linejoin': /^(?:miter|round|bevel)$/,
|
|
40
|
+
opacity,
|
|
41
|
+
};
|
|
42
|
+
const pathAttributes = {
|
|
43
|
+
...presentation,
|
|
44
|
+
transform,
|
|
45
|
+
d: /^[Mm] *[+\-.\d][MmLlHhVvCcSsQqTtAaZzEe0-9.,+\- ]+$/,
|
|
46
|
+
'fill-rule': fillRule,
|
|
47
|
+
'clip-rule': fillRule,
|
|
48
|
+
'stroke-opacity': opacity,
|
|
49
|
+
};
|
|
50
|
+
const rectAttributes = {
|
|
51
|
+
...presentation,
|
|
52
|
+
fill: new RegExp(paint.source + '|' + localPaint.source),
|
|
53
|
+
x: length,
|
|
54
|
+
y: length,
|
|
55
|
+
width: extent,
|
|
56
|
+
height: extent,
|
|
57
|
+
rx: extent,
|
|
58
|
+
ry: extent,
|
|
59
|
+
};
|
|
60
|
+
const shapeAttributes = {
|
|
61
|
+
path: pathAttributes,
|
|
62
|
+
rect: rectAttributes,
|
|
63
|
+
g: { transform, 'clip-path': /^url\(#[A-Za-z_][A-Za-z0-9_-]*\)$/ },
|
|
64
|
+
defs: {},
|
|
65
|
+
clipPath: { id: /^[A-Za-z_][A-Za-z0-9_-]*$/ },
|
|
66
|
+
pattern: {
|
|
67
|
+
id: /^[A-Za-z_][A-Za-z0-9_-]*$/,
|
|
68
|
+
width: tileSize,
|
|
69
|
+
height: tileSize,
|
|
70
|
+
patternUnits: /^userSpaceOnUse$/,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
function attributes(text, allowed) {
|
|
74
|
+
const values = {};
|
|
75
|
+
const field = /[ \t\r\n]+([A-Za-z][A-Za-z-]*)[ \t\r\n]*=[ \t\r\n]*(?:"([^"&<>\t\r\n]*)"|'([^'&<>\t\r\n]*)')/gy;
|
|
76
|
+
let end = 0;
|
|
77
|
+
for (let match; (match = field.exec(text)); end = field.lastIndex) {
|
|
78
|
+
const name = match[1];
|
|
79
|
+
let value = (match[2] ?? match[3]);
|
|
80
|
+
if (name in values || !Object.prototype.hasOwnProperty.call(allowed, name))
|
|
81
|
+
return null;
|
|
82
|
+
const rule = allowed[name];
|
|
83
|
+
if (!rule.test(value))
|
|
84
|
+
return null;
|
|
85
|
+
// SVGR emits a numeric literal for a leading-dot opacity.
|
|
86
|
+
if (rule === opacity && value.startsWith('.'))
|
|
87
|
+
value = '0' + value;
|
|
88
|
+
// SVG component loaders can emit a numeric literal for unitless lengths.
|
|
89
|
+
if (rule === length || rule === extent || rule === opacity || rule === tileSize) {
|
|
90
|
+
const n = Number(value);
|
|
91
|
+
if ((!Number.isNaN(n) && String(n) !== value) ||
|
|
92
|
+
(rule === extent && !Number.isFinite(parseFloat(value))))
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
if (rule === transform &&
|
|
96
|
+
value.match(transformNumbers).some((n) => !Number.isFinite(Number(n))))
|
|
97
|
+
return null;
|
|
98
|
+
values[name] = value;
|
|
99
|
+
}
|
|
100
|
+
return space.test(text.slice(end)) ? values : null;
|
|
101
|
+
}
|
|
102
|
+
// Hydration and React interop use reserved data attributes.
|
|
103
|
+
export function svgDataAttribute(name) {
|
|
104
|
+
return /^data-(?!oct(?:ane)?(?:-|$)|react-compat$)[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(name);
|
|
105
|
+
}
|
|
106
|
+
/** Read authored geometry with a single local clip or paint definition. */
|
|
107
|
+
export function parseStaticSvg(source) {
|
|
108
|
+
if (typeof source !== 'string')
|
|
109
|
+
return null;
|
|
110
|
+
let root = null;
|
|
111
|
+
const children = [];
|
|
112
|
+
const open = [];
|
|
113
|
+
let clipId;
|
|
114
|
+
let reference;
|
|
115
|
+
let patternId;
|
|
116
|
+
let paintId;
|
|
117
|
+
const token = /[ \t\r\n]*(?:<!--([\s\S]*?)-->|<\/(svg|g|defs|clipPath|pattern)[ \t\r\n]*>|<(svg|g|rect|path|defs|clipPath|pattern)([^<>]*?)(\/?)>)/gy;
|
|
118
|
+
let hasShape = false;
|
|
119
|
+
let end = 0;
|
|
120
|
+
for (let match; (match = token.exec(source)); end = token.lastIndex) {
|
|
121
|
+
const [, comment, closing, tag, fields, selfClosing] = match;
|
|
122
|
+
const parent = open[open.length - 1];
|
|
123
|
+
if (comment !== undefined) {
|
|
124
|
+
if (/--|-$|[^\t\r\n\u0020-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/u.test(comment))
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
else if (closing) {
|
|
128
|
+
if (!parent || closing !== parent.tag)
|
|
129
|
+
return null;
|
|
130
|
+
if ((closing === 'defs' || closing === 'clipPath' || closing === 'pattern') &&
|
|
131
|
+
parent.children.length !== 1)
|
|
132
|
+
return null;
|
|
133
|
+
open.pop();
|
|
134
|
+
}
|
|
135
|
+
else if (tag === 'svg') {
|
|
136
|
+
if (root || selfClosing)
|
|
137
|
+
return null;
|
|
138
|
+
root = attributes(fields, rootAttributes);
|
|
139
|
+
if (!root)
|
|
140
|
+
return null;
|
|
141
|
+
open.push({ tag, children });
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
if (!parent)
|
|
145
|
+
return null;
|
|
146
|
+
const name = tag;
|
|
147
|
+
if ((name === 'defs' && parent.tag !== 'svg') ||
|
|
148
|
+
(name === 'clipPath' || name === 'pattern') !== (parent.tag === 'defs') ||
|
|
149
|
+
(parent.tag === 'clipPath' && name !== 'rect') ||
|
|
150
|
+
(parent.tag === 'pattern' && name !== 'path'))
|
|
151
|
+
return null;
|
|
152
|
+
const container = name !== 'path' && name !== 'rect';
|
|
153
|
+
if (container ? selfClosing || open.length > 32 : !selfClosing)
|
|
154
|
+
return null;
|
|
155
|
+
const props = attributes(fields, shapeAttributes[name]);
|
|
156
|
+
if (!props ||
|
|
157
|
+
(tag === 'path' && !props.d) ||
|
|
158
|
+
(tag === 'rect' && !(props.width && props.height)))
|
|
159
|
+
return null;
|
|
160
|
+
if (name === 'clipPath') {
|
|
161
|
+
if (!props.id || clipId !== undefined || patternId !== undefined)
|
|
162
|
+
return null;
|
|
163
|
+
clipId = props.id;
|
|
164
|
+
}
|
|
165
|
+
if (props['clip-path']) {
|
|
166
|
+
const id = props['clip-path'].slice(5, -1);
|
|
167
|
+
if (parent.tag !== 'svg' || (reference !== undefined && reference !== id))
|
|
168
|
+
return null;
|
|
169
|
+
reference = id;
|
|
170
|
+
}
|
|
171
|
+
if (name === 'pattern') {
|
|
172
|
+
if (patternId !== undefined ||
|
|
173
|
+
clipId !== undefined ||
|
|
174
|
+
!(props.id && props.width && props.height && props.patternUnits))
|
|
175
|
+
return null;
|
|
176
|
+
patternId = props.id;
|
|
177
|
+
}
|
|
178
|
+
if (name === 'rect' && props.fill?.startsWith('url(')) {
|
|
179
|
+
const id = props.fill.slice(5, -1);
|
|
180
|
+
if (parent.tag !== 'svg' || (paintId !== undefined && paintId !== id))
|
|
181
|
+
return null;
|
|
182
|
+
paintId = id;
|
|
183
|
+
}
|
|
184
|
+
const node = { tag: name, attributes: props, children: [] };
|
|
185
|
+
parent.children.push(node);
|
|
186
|
+
if (container)
|
|
187
|
+
open.push(node);
|
|
188
|
+
else if (parent.tag !== 'clipPath' && parent.tag !== 'pattern')
|
|
189
|
+
hasShape = true;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return root &&
|
|
193
|
+
hasShape &&
|
|
194
|
+
!open.length &&
|
|
195
|
+
clipId === reference &&
|
|
196
|
+
patternId === paintId &&
|
|
197
|
+
space.test(source.slice(end))
|
|
198
|
+
? { root, children }
|
|
199
|
+
: null;
|
|
200
|
+
}
|
|
201
|
+
// Existing generated helpers expose this path-only result to their importers.
|
|
202
|
+
export function parsePathSvg(source) {
|
|
203
|
+
const svg = parseStaticSvg(source);
|
|
204
|
+
return svg && svg.children.every((node) => node.tag === 'path')
|
|
205
|
+
? { root: svg.root, paths: svg.children.map((node) => node.attributes) }
|
|
206
|
+
: null;
|
|
207
|
+
}
|