svelte-origin 1.0.0-next.17 → 1.0.0-next.18
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/cli.js +7 -2
- package/dist/post-process.js +7 -2
- package/dist/runtime/types.d.ts +22 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2945,6 +2945,9 @@ async function transformScriptContent(source, options) {
|
|
|
2945
2945
|
var EXTENSIONS = [".svelte", ".svelte.ts", ".svelte.js", ".js", ".ts"];
|
|
2946
2946
|
function cleanupForLibrary(code, schemaCache) {
|
|
2947
2947
|
let result = code;
|
|
2948
|
+
result = result.replace(/(?:var|const|let)\s+\$\w+\s*=\s*globalThis\.\$\w+(?:\s*,\s*\$\w+\s*=\s*globalThis\.\$\w+)*\s*;?\n?/g, "");
|
|
2949
|
+
result = result.replace(/(?:var|const|let)\s*\{\s*\$origin\s*(?:,\s*\$\w+\s*)*\}\s*=\s*globalThis\s*;?\n?/g, "");
|
|
2950
|
+
result = result.replace(/\/\/\s*@ts-ignore\s*-?\s*macros are transformed at build time\n?/g, "");
|
|
2948
2951
|
result = result.replace(/\ntype \$\$Props = \$attrs\.Of<[^>]+>\n/g, `
|
|
2949
2952
|
`);
|
|
2950
2953
|
const attrsOfPattern = /(\}\s*:\s*)\$attrs\.Of<typeof (\w+)>(\s*=\s*\$props\(\))/g;
|
|
@@ -3075,10 +3078,12 @@ async function postProcess(options) {
|
|
|
3075
3078
|
isComponent,
|
|
3076
3079
|
schemaResolver
|
|
3077
3080
|
});
|
|
3078
|
-
|
|
3081
|
+
let finalCode = cleanupForLibrary(transformed.changed ? transformed.code : source, schemaCache);
|
|
3082
|
+
const sourceToCompare = transformed.changed ? transformed.code : source;
|
|
3083
|
+
const cleanupChanged = finalCode !== sourceToCompare;
|
|
3084
|
+
if (transformed.changed || cleanupChanged) {
|
|
3079
3085
|
result.filesProcessed++;
|
|
3080
3086
|
result.files.push(filePath);
|
|
3081
|
-
let finalCode = cleanupForLibrary(transformed.code, schemaCache);
|
|
3082
3087
|
if (!dryRun) {
|
|
3083
3088
|
fs.writeFileSync(filePath, finalCode, "utf-8");
|
|
3084
3089
|
}
|
package/dist/post-process.js
CHANGED
|
@@ -2943,6 +2943,9 @@ async function transformScriptContent(source, options) {
|
|
|
2943
2943
|
var EXTENSIONS = [".svelte", ".svelte.ts", ".svelte.js", ".js", ".ts"];
|
|
2944
2944
|
function cleanupForLibrary(code, schemaCache) {
|
|
2945
2945
|
let result = code;
|
|
2946
|
+
result = result.replace(/(?:var|const|let)\s+\$\w+\s*=\s*globalThis\.\$\w+(?:\s*,\s*\$\w+\s*=\s*globalThis\.\$\w+)*\s*;?\n?/g, "");
|
|
2947
|
+
result = result.replace(/(?:var|const|let)\s*\{\s*\$origin\s*(?:,\s*\$\w+\s*)*\}\s*=\s*globalThis\s*;?\n?/g, "");
|
|
2948
|
+
result = result.replace(/\/\/\s*@ts-ignore\s*-?\s*macros are transformed at build time\n?/g, "");
|
|
2946
2949
|
result = result.replace(/\ntype \$\$Props = \$attrs\.Of<[^>]+>\n/g, `
|
|
2947
2950
|
`);
|
|
2948
2951
|
const attrsOfPattern = /(\}\s*:\s*)\$attrs\.Of<typeof (\w+)>(\s*=\s*\$props\(\))/g;
|
|
@@ -3073,10 +3076,12 @@ async function postProcess(options) {
|
|
|
3073
3076
|
isComponent,
|
|
3074
3077
|
schemaResolver
|
|
3075
3078
|
});
|
|
3076
|
-
|
|
3079
|
+
let finalCode = cleanupForLibrary(transformed.changed ? transformed.code : source, schemaCache);
|
|
3080
|
+
const sourceToCompare = transformed.changed ? transformed.code : source;
|
|
3081
|
+
const cleanupChanged = finalCode !== sourceToCompare;
|
|
3082
|
+
if (transformed.changed || cleanupChanged) {
|
|
3077
3083
|
result.filesProcessed++;
|
|
3078
3084
|
result.files.push(filePath);
|
|
3079
|
-
let finalCode = cleanupForLibrary(transformed.code, schemaCache);
|
|
3080
3085
|
if (!dryRun) {
|
|
3081
3086
|
fs.writeFileSync(filePath, finalCode, "utf-8");
|
|
3082
3087
|
}
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -75,7 +75,7 @@ export type UnwrapBindable<T> = T extends Bindable<infer U> ? U : T;
|
|
|
75
75
|
*/
|
|
76
76
|
export interface OriginFactory<TInstance = unknown, TAttrs = Record<string, any>> {
|
|
77
77
|
/** Create an instance with the given reactive attrs and optional init args */
|
|
78
|
-
(attrs?: TAttrs | null, ...initArgs: any[]): TInstance;
|
|
78
|
+
(attrs?: TAttrs | null, ...initArgs: any[]): TInstance & OriginInstanceExtras;
|
|
79
79
|
/** Marker to identify origin factories */
|
|
80
80
|
readonly __origin: true;
|
|
81
81
|
/** The attr schema extracted from the definition */
|
|
@@ -113,13 +113,33 @@ export interface AttrsFactory<_TAttrs = Record<string, any>> {
|
|
|
113
113
|
/** Parent attr factories (for inheritance) */
|
|
114
114
|
readonly __parents: AttrsFactory<any>[];
|
|
115
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Attachment registry returned by $attachments getter.
|
|
118
|
+
* Maps Symbol keys to attachment functions.
|
|
119
|
+
*/
|
|
120
|
+
export type AttachmentRegistry = Record<symbol, (element: Element) => void | (() => void)>;
|
|
121
|
+
/**
|
|
122
|
+
* Properties added to all origin instances at runtime.
|
|
123
|
+
* These are injected by __createOrigin after __create returns.
|
|
124
|
+
*/
|
|
125
|
+
export interface OriginInstanceExtras {
|
|
126
|
+
/**
|
|
127
|
+
* Attachment functions that can be spread onto elements.
|
|
128
|
+
* Returns an object with Symbol keys mapping to attachment functions.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* <div {...instance.$attachments}>
|
|
132
|
+
*/
|
|
133
|
+
readonly $attachments: AttachmentRegistry;
|
|
134
|
+
}
|
|
116
135
|
/**
|
|
117
136
|
* The origin instance has:
|
|
118
137
|
* - attrs: reactive attrs object (passed in)
|
|
119
138
|
* - super: parent instance (if extending)
|
|
139
|
+
* - $attachments: attachment registry (injected by runtime)
|
|
120
140
|
* - All other members from the definition (state, getters, methods)
|
|
121
141
|
*/
|
|
122
|
-
export interface OriginInstance<TAttrs = Record<string, any>> {
|
|
142
|
+
export interface OriginInstance<TAttrs = Record<string, any>> extends OriginInstanceExtras {
|
|
123
143
|
/** Reactive attrs object */
|
|
124
144
|
readonly attrs: TAttrs;
|
|
125
145
|
/** Parent instance (if extending) */
|