svelte-origin 1.0.0-next.21 → 1.0.0-next.22

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.

Potentially problematic release.


This version of svelte-origin might be problematic. Click here for more details.

package/dist/cli.js CHANGED
@@ -1975,6 +1975,7 @@ function transformOriginDefinition(content, svelteImports) {
1975
1975
  let attrsContent = "";
1976
1976
  let contentWithoutAttrs = bodyContent;
1977
1977
  let attrPropertyName = "props";
1978
+ let propsRef = null;
1978
1979
  if (attrsMatch) {
1979
1980
  attrPropertyName = attrsMatch[1];
1980
1981
  const attrsStart = attrsMatch.index;
@@ -2005,13 +2006,31 @@ function transformOriginDefinition(content, svelteImports) {
2005
2006
  }
2006
2007
  contentWithoutAttrs = bodyContent.slice(0, attrsStart) + bodyContent.slice(cutEnd);
2007
2008
  }
2009
+ } else {
2010
+ const externalRefMatch = bodyContent.match(/(\w+)\s*:\s*(\w+)\s*,/);
2011
+ if (externalRefMatch) {
2012
+ const propName = externalRefMatch[1];
2013
+ const refName = externalRefMatch[2];
2014
+ if ((propName === "props" || propName === "attrs") && /^[A-Z]/.test(refName) && !["$state", "$derived", "$effect", "$bindable"].includes(refName)) {
2015
+ attrPropertyName = propName;
2016
+ propsRef = refName;
2017
+ const refStart = externalRefMatch.index;
2018
+ const refEnd = refStart + externalRefMatch[0].length;
2019
+ contentWithoutAttrs = bodyContent.slice(0, refStart) + bodyContent.slice(refEnd);
2020
+ }
2021
+ }
2008
2022
  }
2009
2023
  const attrDetails = parseAttrsSource(attrsContent);
2010
2024
  const { body: createFnBody, attachments } = transformOriginBody(contentWithoutAttrs.trim(), parents, attrDetails, attrPropertyName, svelteImports);
2011
2025
  const parentsCode = parents.length > 0 ? `[${parents.join(", ")}]` : "undefined";
2012
2026
  let configCode = `{
2013
2027
  __attrSchema: ${attrSchemaCode},
2014
- __parents: ${parentsCode},
2028
+ __parents: ${parentsCode},`;
2029
+ if (propsRef) {
2030
+ configCode += `
2031
+ __propsRef: ${propsRef},`;
2032
+ }
2033
+ configCode += `
2015
2034
  __create: (__inputAttrs${parents.length > 0 ? ", __super" : ""}) => {
2016
2035
  ${createFnBody}
2017
2036
  }`;
@@ -2246,6 +2265,73 @@ function parseOriginSchemaFromSource(source, exportName) {
2246
2265
  return compiledResult;
2247
2266
  return null;
2248
2267
  }
2268
+ function parseAttrsSchemaFromSource(source, exportName) {
2269
+ const sourceResult = parseSourceAttrs(source, exportName);
2270
+ if (sourceResult)
2271
+ return sourceResult;
2272
+ const compiledResult = parseCompiledAttrs(source, exportName);
2273
+ if (compiledResult)
2274
+ return compiledResult;
2275
+ return null;
2276
+ }
2277
+ function parseSourceAttrs(source, exportName) {
2278
+ const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*\\$attrs\\s*\\(`, "s");
2279
+ const match = exportPattern.exec(source);
2280
+ if (!match)
2281
+ return null;
2282
+ const attrsStart = match.index + match[0].length - 1;
2283
+ const attrsEnd = findMatchingBracket(source, attrsStart);
2284
+ if (attrsEnd === -1)
2285
+ return null;
2286
+ let attrsContent = source.slice(attrsStart + 1, attrsEnd).trim();
2287
+ let parentNames = [];
2288
+ if (attrsContent.startsWith("[")) {
2289
+ const closeBracket = findMatchingBracket(attrsContent, 0, "[", "]");
2290
+ if (closeBracket !== -1) {
2291
+ const parentsContent = attrsContent.slice(1, closeBracket);
2292
+ parentNames = parentsContent.split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
2293
+ let i = closeBracket + 1;
2294
+ while (i < attrsContent.length && /[\s,]/.test(attrsContent[i]))
2295
+ i++;
2296
+ attrsContent = attrsContent.slice(i);
2297
+ }
2298
+ }
2299
+ if (!attrsContent.startsWith("{")) {
2300
+ return { attrs: [], parentNames };
2301
+ }
2302
+ const objEnd = findMatchingBracket(attrsContent, 0, "{", "}");
2303
+ if (objEnd === -1)
2304
+ return { attrs: [], parentNames };
2305
+ const objContent = attrsContent.slice(1, objEnd);
2306
+ const attrs = parseAttrsContent(objContent);
2307
+ return { attrs, parentNames };
2308
+ }
2309
+ function parseCompiledAttrs(source, exportName) {
2310
+ const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*__createAttrs\\s*\\(\\s*\\{`, "s");
2311
+ const match = exportPattern.exec(source);
2312
+ if (!match)
2313
+ return null;
2314
+ const braceStart = match.index + match[0].length - 1;
2315
+ const braceEnd = findMatchingBracket(source, braceStart, "{", "}");
2316
+ if (braceEnd === -1)
2317
+ return null;
2318
+ const configContent = source.slice(braceStart + 1, braceEnd);
2319
+ const schemaMatch = configContent.match(/__attrSchema\s*:\s*\{/);
2320
+ if (!schemaMatch)
2321
+ return { attrs: [], parentNames: [] };
2322
+ const schemaStart = schemaMatch.index + schemaMatch[0].length - 1;
2323
+ const schemaEnd = findMatchingBracket(configContent, schemaStart, "{", "}");
2324
+ if (schemaEnd === -1)
2325
+ return { attrs: [], parentNames: [] };
2326
+ const schemaContent = configContent.slice(schemaStart + 1, schemaEnd);
2327
+ const attrs = parseCompiledAttrSchema(schemaContent);
2328
+ const parentsMatch = configContent.match(/__parents\s*:\s*\[([^\]]*)\]/);
2329
+ let parentNames = [];
2330
+ if (parentsMatch && parentsMatch[1].trim()) {
2331
+ parentNames = parentsMatch[1].split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
2332
+ }
2333
+ return { attrs, parentNames };
2334
+ }
2249
2335
  function parseSourceOrigin(source, exportName) {
2250
2336
  const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*\\$origin\\s*\\(`, "s");
2251
2337
  const match = exportPattern.exec(source);
@@ -2271,6 +2357,13 @@ function parseSourceOrigin(source, exportName) {
2271
2357
  }
2272
2358
  const attrsMatch = bodyContent.match(/(\w+)\s*:\s*\$attrs\s*\(\s*\{/);
2273
2359
  if (!attrsMatch) {
2360
+ const externalRefMatch = bodyContent.match(/(?:props|attrs)\s*:\s*([A-Z]\w*)\b/);
2361
+ if (externalRefMatch) {
2362
+ const propsRef = externalRefMatch[1];
2363
+ if (!["Object", "Array", "String", "Number", "Boolean"].includes(propsRef)) {
2364
+ return { attrs: [], parentNames, propsRef };
2365
+ }
2366
+ }
2274
2367
  return { attrs: [], parentNames };
2275
2368
  }
2276
2369
  const attrsStart = attrsMatch.index;
@@ -2307,7 +2400,9 @@ function parseCompiledOrigin(source, exportName) {
2307
2400
  if (parentsMatch && parentsMatch[1].trim()) {
2308
2401
  parentNames = parentsMatch[1].split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
2309
2402
  }
2310
- return { attrs, parentNames };
2403
+ const propsRefMatch = configContent.match(/__propsRef\s*:\s*(\w+)/);
2404
+ const propsRef = propsRefMatch ? propsRefMatch[1] : undefined;
2405
+ return { attrs, parentNames, propsRef };
2311
2406
  }
2312
2407
  function parseCompiledAttrSchema(content) {
2313
2408
  const result = [];
package/dist/index.js CHANGED
@@ -3899,6 +3899,73 @@ function parseOriginSchemaFromSource(source2, exportName) {
3899
3899
  return compiledResult;
3900
3900
  return null;
3901
3901
  }
3902
+ function parseAttrsSchemaFromSource(source2, exportName) {
3903
+ const sourceResult = parseSourceAttrs(source2, exportName);
3904
+ if (sourceResult)
3905
+ return sourceResult;
3906
+ const compiledResult = parseCompiledAttrs(source2, exportName);
3907
+ if (compiledResult)
3908
+ return compiledResult;
3909
+ return null;
3910
+ }
3911
+ function parseSourceAttrs(source2, exportName) {
3912
+ const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*\\$attrs\\s*\\(`, "s");
3913
+ const match = exportPattern.exec(source2);
3914
+ if (!match)
3915
+ return null;
3916
+ const attrsStart = match.index + match[0].length - 1;
3917
+ const attrsEnd = findMatchingBracket(source2, attrsStart);
3918
+ if (attrsEnd === -1)
3919
+ return null;
3920
+ let attrsContent = source2.slice(attrsStart + 1, attrsEnd).trim();
3921
+ let parentNames = [];
3922
+ if (attrsContent.startsWith("[")) {
3923
+ const closeBracket = findMatchingBracket(attrsContent, 0, "[", "]");
3924
+ if (closeBracket !== -1) {
3925
+ const parentsContent = attrsContent.slice(1, closeBracket);
3926
+ parentNames = parentsContent.split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
3927
+ let i = closeBracket + 1;
3928
+ while (i < attrsContent.length && /[\s,]/.test(attrsContent[i]))
3929
+ i++;
3930
+ attrsContent = attrsContent.slice(i);
3931
+ }
3932
+ }
3933
+ if (!attrsContent.startsWith("{")) {
3934
+ return { attrs: [], parentNames };
3935
+ }
3936
+ const objEnd = findMatchingBracket(attrsContent, 0, "{", "}");
3937
+ if (objEnd === -1)
3938
+ return { attrs: [], parentNames };
3939
+ const objContent = attrsContent.slice(1, objEnd);
3940
+ const attrs = parseAttrsContent(objContent);
3941
+ return { attrs, parentNames };
3942
+ }
3943
+ function parseCompiledAttrs(source2, exportName) {
3944
+ const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*__createAttrs\\s*\\(\\s*\\{`, "s");
3945
+ const match = exportPattern.exec(source2);
3946
+ if (!match)
3947
+ return null;
3948
+ const braceStart = match.index + match[0].length - 1;
3949
+ const braceEnd = findMatchingBracket(source2, braceStart, "{", "}");
3950
+ if (braceEnd === -1)
3951
+ return null;
3952
+ const configContent = source2.slice(braceStart + 1, braceEnd);
3953
+ const schemaMatch = configContent.match(/__attrSchema\s*:\s*\{/);
3954
+ if (!schemaMatch)
3955
+ return { attrs: [], parentNames: [] };
3956
+ const schemaStart = schemaMatch.index + schemaMatch[0].length - 1;
3957
+ const schemaEnd = findMatchingBracket(configContent, schemaStart, "{", "}");
3958
+ if (schemaEnd === -1)
3959
+ return { attrs: [], parentNames: [] };
3960
+ const schemaContent = configContent.slice(schemaStart + 1, schemaEnd);
3961
+ const attrs = parseCompiledAttrSchema(schemaContent);
3962
+ const parentsMatch = configContent.match(/__parents\s*:\s*\[([^\]]*)\]/);
3963
+ let parentNames = [];
3964
+ if (parentsMatch && parentsMatch[1].trim()) {
3965
+ parentNames = parentsMatch[1].split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
3966
+ }
3967
+ return { attrs, parentNames };
3968
+ }
3902
3969
  function parseSourceOrigin(source2, exportName) {
3903
3970
  const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*\\$origin\\s*\\(`, "s");
3904
3971
  const match = exportPattern.exec(source2);
@@ -3924,6 +3991,13 @@ function parseSourceOrigin(source2, exportName) {
3924
3991
  }
3925
3992
  const attrsMatch = bodyContent.match(/(\w+)\s*:\s*\$attrs\s*\(\s*\{/);
3926
3993
  if (!attrsMatch) {
3994
+ const externalRefMatch = bodyContent.match(/(?:props|attrs)\s*:\s*([A-Z]\w*)\b/);
3995
+ if (externalRefMatch) {
3996
+ const propsRef = externalRefMatch[1];
3997
+ if (!["Object", "Array", "String", "Number", "Boolean"].includes(propsRef)) {
3998
+ return { attrs: [], parentNames, propsRef };
3999
+ }
4000
+ }
3927
4001
  return { attrs: [], parentNames };
3928
4002
  }
3929
4003
  const attrsStart = attrsMatch.index;
@@ -3960,7 +4034,9 @@ function parseCompiledOrigin(source2, exportName) {
3960
4034
  if (parentsMatch && parentsMatch[1].trim()) {
3961
4035
  parentNames = parentsMatch[1].split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
3962
4036
  }
3963
- return { attrs, parentNames };
4037
+ const propsRefMatch = configContent.match(/__propsRef\s*:\s*(\w+)/);
4038
+ const propsRef = propsRefMatch ? propsRefMatch[1] : undefined;
4039
+ return { attrs, parentNames, propsRef };
3964
4040
  }
3965
4041
  function parseCompiledAttrSchema(content) {
3966
4042
  const result = [];
@@ -6160,6 +6236,7 @@ function transformOriginDefinition(content, svelteImports) {
6160
6236
  let attrsContent = "";
6161
6237
  let contentWithoutAttrs = bodyContent;
6162
6238
  let attrPropertyName = "props";
6239
+ let propsRef = null;
6163
6240
  if (attrsMatch) {
6164
6241
  attrPropertyName = attrsMatch[1];
6165
6242
  const attrsStart = attrsMatch.index;
@@ -6190,13 +6267,31 @@ function transformOriginDefinition(content, svelteImports) {
6190
6267
  }
6191
6268
  contentWithoutAttrs = bodyContent.slice(0, attrsStart) + bodyContent.slice(cutEnd);
6192
6269
  }
6270
+ } else {
6271
+ const externalRefMatch = bodyContent.match(/(\w+)\s*:\s*(\w+)\s*,/);
6272
+ if (externalRefMatch) {
6273
+ const propName = externalRefMatch[1];
6274
+ const refName = externalRefMatch[2];
6275
+ if ((propName === "props" || propName === "attrs") && /^[A-Z]/.test(refName) && !["$state", "$derived", "$effect", "$bindable"].includes(refName)) {
6276
+ attrPropertyName = propName;
6277
+ propsRef = refName;
6278
+ const refStart = externalRefMatch.index;
6279
+ const refEnd = refStart + externalRefMatch[0].length;
6280
+ contentWithoutAttrs = bodyContent.slice(0, refStart) + bodyContent.slice(refEnd);
6281
+ }
6282
+ }
6193
6283
  }
6194
6284
  const attrDetails = parseAttrsSource(attrsContent);
6195
6285
  const { body: createFnBody, attachments } = transformOriginBody(contentWithoutAttrs.trim(), parents, attrDetails, attrPropertyName, svelteImports);
6196
6286
  const parentsCode = parents.length > 0 ? `[${parents.join(", ")}]` : "undefined";
6197
6287
  let configCode = `{
6198
6288
  __attrSchema: ${attrSchemaCode},
6199
- __parents: ${parentsCode},
6289
+ __parents: ${parentsCode},`;
6290
+ if (propsRef) {
6291
+ configCode += `
6292
+ __propsRef: ${propsRef},`;
6293
+ }
6294
+ configCode += `
6200
6295
  __create: (__inputAttrs${parents.length > 0 ? ", __super" : ""}) => {
6201
6296
  ${createFnBody}
6202
6297
  }`;
package/dist/plugin.js CHANGED
@@ -1969,6 +1969,7 @@ function transformOriginDefinition(content, svelteImports) {
1969
1969
  let attrsContent = "";
1970
1970
  let contentWithoutAttrs = bodyContent;
1971
1971
  let attrPropertyName = "props";
1972
+ let propsRef = null;
1972
1973
  if (attrsMatch) {
1973
1974
  attrPropertyName = attrsMatch[1];
1974
1975
  const attrsStart = attrsMatch.index;
@@ -1999,13 +2000,31 @@ function transformOriginDefinition(content, svelteImports) {
1999
2000
  }
2000
2001
  contentWithoutAttrs = bodyContent.slice(0, attrsStart) + bodyContent.slice(cutEnd);
2001
2002
  }
2003
+ } else {
2004
+ const externalRefMatch = bodyContent.match(/(\w+)\s*:\s*(\w+)\s*,/);
2005
+ if (externalRefMatch) {
2006
+ const propName = externalRefMatch[1];
2007
+ const refName = externalRefMatch[2];
2008
+ if ((propName === "props" || propName === "attrs") && /^[A-Z]/.test(refName) && !["$state", "$derived", "$effect", "$bindable"].includes(refName)) {
2009
+ attrPropertyName = propName;
2010
+ propsRef = refName;
2011
+ const refStart = externalRefMatch.index;
2012
+ const refEnd = refStart + externalRefMatch[0].length;
2013
+ contentWithoutAttrs = bodyContent.slice(0, refStart) + bodyContent.slice(refEnd);
2014
+ }
2015
+ }
2002
2016
  }
2003
2017
  const attrDetails = parseAttrsSource(attrsContent);
2004
2018
  const { body: createFnBody, attachments } = transformOriginBody(contentWithoutAttrs.trim(), parents, attrDetails, attrPropertyName, svelteImports);
2005
2019
  const parentsCode = parents.length > 0 ? `[${parents.join(", ")}]` : "undefined";
2006
2020
  let configCode = `{
2007
2021
  __attrSchema: ${attrSchemaCode},
2008
- __parents: ${parentsCode},
2022
+ __parents: ${parentsCode},`;
2023
+ if (propsRef) {
2024
+ configCode += `
2025
+ __propsRef: ${propsRef},`;
2026
+ }
2027
+ configCode += `
2009
2028
  __create: (__inputAttrs${parents.length > 0 ? ", __super" : ""}) => {
2010
2029
  ${createFnBody}
2011
2030
  }`;
@@ -2240,6 +2259,73 @@ function parseOriginSchemaFromSource(source, exportName) {
2240
2259
  return compiledResult;
2241
2260
  return null;
2242
2261
  }
2262
+ function parseAttrsSchemaFromSource(source, exportName) {
2263
+ const sourceResult = parseSourceAttrs(source, exportName);
2264
+ if (sourceResult)
2265
+ return sourceResult;
2266
+ const compiledResult = parseCompiledAttrs(source, exportName);
2267
+ if (compiledResult)
2268
+ return compiledResult;
2269
+ return null;
2270
+ }
2271
+ function parseSourceAttrs(source, exportName) {
2272
+ const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*\\$attrs\\s*\\(`, "s");
2273
+ const match = exportPattern.exec(source);
2274
+ if (!match)
2275
+ return null;
2276
+ const attrsStart = match.index + match[0].length - 1;
2277
+ const attrsEnd = findMatchingBracket(source, attrsStart);
2278
+ if (attrsEnd === -1)
2279
+ return null;
2280
+ let attrsContent = source.slice(attrsStart + 1, attrsEnd).trim();
2281
+ let parentNames = [];
2282
+ if (attrsContent.startsWith("[")) {
2283
+ const closeBracket = findMatchingBracket(attrsContent, 0, "[", "]");
2284
+ if (closeBracket !== -1) {
2285
+ const parentsContent = attrsContent.slice(1, closeBracket);
2286
+ parentNames = parentsContent.split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
2287
+ let i = closeBracket + 1;
2288
+ while (i < attrsContent.length && /[\s,]/.test(attrsContent[i]))
2289
+ i++;
2290
+ attrsContent = attrsContent.slice(i);
2291
+ }
2292
+ }
2293
+ if (!attrsContent.startsWith("{")) {
2294
+ return { attrs: [], parentNames };
2295
+ }
2296
+ const objEnd = findMatchingBracket(attrsContent, 0, "{", "}");
2297
+ if (objEnd === -1)
2298
+ return { attrs: [], parentNames };
2299
+ const objContent = attrsContent.slice(1, objEnd);
2300
+ const attrs = parseAttrsContent(objContent);
2301
+ return { attrs, parentNames };
2302
+ }
2303
+ function parseCompiledAttrs(source, exportName) {
2304
+ const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*__createAttrs\\s*\\(\\s*\\{`, "s");
2305
+ const match = exportPattern.exec(source);
2306
+ if (!match)
2307
+ return null;
2308
+ const braceStart = match.index + match[0].length - 1;
2309
+ const braceEnd = findMatchingBracket(source, braceStart, "{", "}");
2310
+ if (braceEnd === -1)
2311
+ return null;
2312
+ const configContent = source.slice(braceStart + 1, braceEnd);
2313
+ const schemaMatch = configContent.match(/__attrSchema\s*:\s*\{/);
2314
+ if (!schemaMatch)
2315
+ return { attrs: [], parentNames: [] };
2316
+ const schemaStart = schemaMatch.index + schemaMatch[0].length - 1;
2317
+ const schemaEnd = findMatchingBracket(configContent, schemaStart, "{", "}");
2318
+ if (schemaEnd === -1)
2319
+ return { attrs: [], parentNames: [] };
2320
+ const schemaContent = configContent.slice(schemaStart + 1, schemaEnd);
2321
+ const attrs = parseCompiledAttrSchema(schemaContent);
2322
+ const parentsMatch = configContent.match(/__parents\s*:\s*\[([^\]]*)\]/);
2323
+ let parentNames = [];
2324
+ if (parentsMatch && parentsMatch[1].trim()) {
2325
+ parentNames = parentsMatch[1].split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
2326
+ }
2327
+ return { attrs, parentNames };
2328
+ }
2243
2329
  function parseSourceOrigin(source, exportName) {
2244
2330
  const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*\\$origin\\s*\\(`, "s");
2245
2331
  const match = exportPattern.exec(source);
@@ -2265,6 +2351,13 @@ function parseSourceOrigin(source, exportName) {
2265
2351
  }
2266
2352
  const attrsMatch = bodyContent.match(/(\w+)\s*:\s*\$attrs\s*\(\s*\{/);
2267
2353
  if (!attrsMatch) {
2354
+ const externalRefMatch = bodyContent.match(/(?:props|attrs)\s*:\s*([A-Z]\w*)\b/);
2355
+ if (externalRefMatch) {
2356
+ const propsRef = externalRefMatch[1];
2357
+ if (!["Object", "Array", "String", "Number", "Boolean"].includes(propsRef)) {
2358
+ return { attrs: [], parentNames, propsRef };
2359
+ }
2360
+ }
2268
2361
  return { attrs: [], parentNames };
2269
2362
  }
2270
2363
  const attrsStart = attrsMatch.index;
@@ -2301,7 +2394,9 @@ function parseCompiledOrigin(source, exportName) {
2301
2394
  if (parentsMatch && parentsMatch[1].trim()) {
2302
2395
  parentNames = parentsMatch[1].split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
2303
2396
  }
2304
- return { attrs, parentNames };
2397
+ const propsRefMatch = configContent.match(/__propsRef\s*:\s*(\w+)/);
2398
+ const propsRef = propsRefMatch ? propsRefMatch[1] : undefined;
2399
+ return { attrs, parentNames, propsRef };
2305
2400
  }
2306
2401
  function parseCompiledAttrSchema(content) {
2307
2402
  const result = [];
@@ -3669,6 +3764,20 @@ async function resolveSchema(importPath, exportName, importerId, cache, debug, a
3669
3764
  mergedAttrs.push(attr);
3670
3765
  }
3671
3766
  }
3767
+ if (schema.propsRef) {
3768
+ const propsRefImportPath = findImportPath(source, schema.propsRef);
3769
+ if (propsRefImportPath) {
3770
+ const propsRefSchema = await resolveAttrsSchema(propsRefImportPath, schema.propsRef, filePath, cache, debug, aliases);
3771
+ if (propsRefSchema) {
3772
+ for (const attr of propsRefSchema.attrs) {
3773
+ const existingIndex = mergedAttrs.findIndex((a) => a.key === attr.key);
3774
+ if (existingIndex === -1) {
3775
+ mergedAttrs.push(attr);
3776
+ }
3777
+ }
3778
+ }
3779
+ }
3780
+ }
3672
3781
  const mergedSchema = {
3673
3782
  attrs: mergedAttrs,
3674
3783
  parentNames: schema.parentNames
@@ -3686,6 +3795,75 @@ async function resolveSchema(importPath, exportName, importerId, cache, debug, a
3686
3795
  return null;
3687
3796
  }
3688
3797
  }
3798
+ async function resolveAttrsSchema(importPath, exportName, importerId, cache, debug, aliases) {
3799
+ const cacheKey = `attrs::${importPath}::${exportName}`;
3800
+ if (cache.has(cacheKey)) {
3801
+ if (debug) {
3802
+ console.log(`[svelte-origin] Cache hit for ${cacheKey}`);
3803
+ }
3804
+ return cache.get(cacheKey) || null;
3805
+ }
3806
+ try {
3807
+ const importerDir = dirname2(importerId);
3808
+ if (debug) {
3809
+ console.log(`[svelte-origin] Resolving attrs: ${exportName} from ${importPath}`);
3810
+ }
3811
+ const resolvedPath = resolveImportPath(importPath, aliases, importerDir);
3812
+ if (!resolvedPath) {
3813
+ cache.set(cacheKey, null);
3814
+ return null;
3815
+ }
3816
+ const filePath = resolveFilePath(resolvedPath);
3817
+ if (!filePath) {
3818
+ cache.set(cacheKey, null);
3819
+ return null;
3820
+ }
3821
+ const source = readFileSync2(filePath, "utf-8");
3822
+ const schema = parseAttrsSchemaFromSource(source, exportName);
3823
+ if (!schema) {
3824
+ cache.set(cacheKey, null);
3825
+ return null;
3826
+ }
3827
+ const mergedAttrs = [];
3828
+ for (const parentName of schema.parentNames) {
3829
+ const parentImportPath = findImportPath(source, parentName);
3830
+ if (parentImportPath) {
3831
+ const parentSchema = await resolveAttrsSchema(parentImportPath, parentName, filePath, cache, debug, aliases);
3832
+ if (parentSchema) {
3833
+ for (const attr of parentSchema.attrs) {
3834
+ const existingIndex = mergedAttrs.findIndex((a) => a.key === attr.key);
3835
+ if (existingIndex === -1) {
3836
+ mergedAttrs.push(attr);
3837
+ }
3838
+ }
3839
+ }
3840
+ }
3841
+ }
3842
+ for (const attr of schema.attrs) {
3843
+ const existingIndex = mergedAttrs.findIndex((a) => a.key === attr.key);
3844
+ if (existingIndex !== -1) {
3845
+ mergedAttrs[existingIndex] = attr;
3846
+ } else {
3847
+ mergedAttrs.push(attr);
3848
+ }
3849
+ }
3850
+ const mergedSchema = {
3851
+ attrs: mergedAttrs,
3852
+ parentNames: schema.parentNames
3853
+ };
3854
+ if (debug) {
3855
+ console.log(`[svelte-origin] Resolved attrs schema for ${exportName}:`, mergedSchema.attrs.map((a) => a.key));
3856
+ }
3857
+ cache.set(cacheKey, mergedSchema);
3858
+ return mergedSchema;
3859
+ } catch (error) {
3860
+ if (debug) {
3861
+ console.error(`[svelte-origin] Error resolving attrs schema for ${importPath}:`, error);
3862
+ }
3863
+ cache.set(cacheKey, null);
3864
+ return null;
3865
+ }
3866
+ }
3689
3867
  var plugin_default = svelteOrigin;
3690
3868
  export {
3691
3869
  svelteOrigin,
@@ -1973,6 +1973,7 @@ function transformOriginDefinition(content, svelteImports) {
1973
1973
  let attrsContent = "";
1974
1974
  let contentWithoutAttrs = bodyContent;
1975
1975
  let attrPropertyName = "props";
1976
+ let propsRef = null;
1976
1977
  if (attrsMatch) {
1977
1978
  attrPropertyName = attrsMatch[1];
1978
1979
  const attrsStart = attrsMatch.index;
@@ -2003,13 +2004,31 @@ function transformOriginDefinition(content, svelteImports) {
2003
2004
  }
2004
2005
  contentWithoutAttrs = bodyContent.slice(0, attrsStart) + bodyContent.slice(cutEnd);
2005
2006
  }
2007
+ } else {
2008
+ const externalRefMatch = bodyContent.match(/(\w+)\s*:\s*(\w+)\s*,/);
2009
+ if (externalRefMatch) {
2010
+ const propName = externalRefMatch[1];
2011
+ const refName = externalRefMatch[2];
2012
+ if ((propName === "props" || propName === "attrs") && /^[A-Z]/.test(refName) && !["$state", "$derived", "$effect", "$bindable"].includes(refName)) {
2013
+ attrPropertyName = propName;
2014
+ propsRef = refName;
2015
+ const refStart = externalRefMatch.index;
2016
+ const refEnd = refStart + externalRefMatch[0].length;
2017
+ contentWithoutAttrs = bodyContent.slice(0, refStart) + bodyContent.slice(refEnd);
2018
+ }
2019
+ }
2006
2020
  }
2007
2021
  const attrDetails = parseAttrsSource(attrsContent);
2008
2022
  const { body: createFnBody, attachments } = transformOriginBody(contentWithoutAttrs.trim(), parents, attrDetails, attrPropertyName, svelteImports);
2009
2023
  const parentsCode = parents.length > 0 ? `[${parents.join(", ")}]` : "undefined";
2010
2024
  let configCode = `{
2011
2025
  __attrSchema: ${attrSchemaCode},
2012
- __parents: ${parentsCode},
2026
+ __parents: ${parentsCode},`;
2027
+ if (propsRef) {
2028
+ configCode += `
2029
+ __propsRef: ${propsRef},`;
2030
+ }
2031
+ configCode += `
2013
2032
  __create: (__inputAttrs${parents.length > 0 ? ", __super" : ""}) => {
2014
2033
  ${createFnBody}
2015
2034
  }`;
@@ -2244,6 +2263,73 @@ function parseOriginSchemaFromSource(source, exportName) {
2244
2263
  return compiledResult;
2245
2264
  return null;
2246
2265
  }
2266
+ function parseAttrsSchemaFromSource(source, exportName) {
2267
+ const sourceResult = parseSourceAttrs(source, exportName);
2268
+ if (sourceResult)
2269
+ return sourceResult;
2270
+ const compiledResult = parseCompiledAttrs(source, exportName);
2271
+ if (compiledResult)
2272
+ return compiledResult;
2273
+ return null;
2274
+ }
2275
+ function parseSourceAttrs(source, exportName) {
2276
+ const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*\\$attrs\\s*\\(`, "s");
2277
+ const match = exportPattern.exec(source);
2278
+ if (!match)
2279
+ return null;
2280
+ const attrsStart = match.index + match[0].length - 1;
2281
+ const attrsEnd = findMatchingBracket(source, attrsStart);
2282
+ if (attrsEnd === -1)
2283
+ return null;
2284
+ let attrsContent = source.slice(attrsStart + 1, attrsEnd).trim();
2285
+ let parentNames = [];
2286
+ if (attrsContent.startsWith("[")) {
2287
+ const closeBracket = findMatchingBracket(attrsContent, 0, "[", "]");
2288
+ if (closeBracket !== -1) {
2289
+ const parentsContent = attrsContent.slice(1, closeBracket);
2290
+ parentNames = parentsContent.split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
2291
+ let i = closeBracket + 1;
2292
+ while (i < attrsContent.length && /[\s,]/.test(attrsContent[i]))
2293
+ i++;
2294
+ attrsContent = attrsContent.slice(i);
2295
+ }
2296
+ }
2297
+ if (!attrsContent.startsWith("{")) {
2298
+ return { attrs: [], parentNames };
2299
+ }
2300
+ const objEnd = findMatchingBracket(attrsContent, 0, "{", "}");
2301
+ if (objEnd === -1)
2302
+ return { attrs: [], parentNames };
2303
+ const objContent = attrsContent.slice(1, objEnd);
2304
+ const attrs = parseAttrsContent(objContent);
2305
+ return { attrs, parentNames };
2306
+ }
2307
+ function parseCompiledAttrs(source, exportName) {
2308
+ const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*__createAttrs\\s*\\(\\s*\\{`, "s");
2309
+ const match = exportPattern.exec(source);
2310
+ if (!match)
2311
+ return null;
2312
+ const braceStart = match.index + match[0].length - 1;
2313
+ const braceEnd = findMatchingBracket(source, braceStart, "{", "}");
2314
+ if (braceEnd === -1)
2315
+ return null;
2316
+ const configContent = source.slice(braceStart + 1, braceEnd);
2317
+ const schemaMatch = configContent.match(/__attrSchema\s*:\s*\{/);
2318
+ if (!schemaMatch)
2319
+ return { attrs: [], parentNames: [] };
2320
+ const schemaStart = schemaMatch.index + schemaMatch[0].length - 1;
2321
+ const schemaEnd = findMatchingBracket(configContent, schemaStart, "{", "}");
2322
+ if (schemaEnd === -1)
2323
+ return { attrs: [], parentNames: [] };
2324
+ const schemaContent = configContent.slice(schemaStart + 1, schemaEnd);
2325
+ const attrs = parseCompiledAttrSchema(schemaContent);
2326
+ const parentsMatch = configContent.match(/__parents\s*:\s*\[([^\]]*)\]/);
2327
+ let parentNames = [];
2328
+ if (parentsMatch && parentsMatch[1].trim()) {
2329
+ parentNames = parentsMatch[1].split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
2330
+ }
2331
+ return { attrs, parentNames };
2332
+ }
2247
2333
  function parseSourceOrigin(source, exportName) {
2248
2334
  const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*\\$origin\\s*\\(`, "s");
2249
2335
  const match = exportPattern.exec(source);
@@ -2269,6 +2355,13 @@ function parseSourceOrigin(source, exportName) {
2269
2355
  }
2270
2356
  const attrsMatch = bodyContent.match(/(\w+)\s*:\s*\$attrs\s*\(\s*\{/);
2271
2357
  if (!attrsMatch) {
2358
+ const externalRefMatch = bodyContent.match(/(?:props|attrs)\s*:\s*([A-Z]\w*)\b/);
2359
+ if (externalRefMatch) {
2360
+ const propsRef = externalRefMatch[1];
2361
+ if (!["Object", "Array", "String", "Number", "Boolean"].includes(propsRef)) {
2362
+ return { attrs: [], parentNames, propsRef };
2363
+ }
2364
+ }
2272
2365
  return { attrs: [], parentNames };
2273
2366
  }
2274
2367
  const attrsStart = attrsMatch.index;
@@ -2305,7 +2398,9 @@ function parseCompiledOrigin(source, exportName) {
2305
2398
  if (parentsMatch && parentsMatch[1].trim()) {
2306
2399
  parentNames = parentsMatch[1].split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
2307
2400
  }
2308
- return { attrs, parentNames };
2401
+ const propsRefMatch = configContent.match(/__propsRef\s*:\s*(\w+)/);
2402
+ const propsRef = propsRefMatch ? propsRefMatch[1] : undefined;
2403
+ return { attrs, parentNames, propsRef };
2309
2404
  }
2310
2405
  function parseCompiledAttrSchema(content) {
2311
2406
  const result = [];
@@ -1969,6 +1969,7 @@ function transformOriginDefinition(content, svelteImports) {
1969
1969
  let attrsContent = "";
1970
1970
  let contentWithoutAttrs = bodyContent;
1971
1971
  let attrPropertyName = "props";
1972
+ let propsRef = null;
1972
1973
  if (attrsMatch) {
1973
1974
  attrPropertyName = attrsMatch[1];
1974
1975
  const attrsStart = attrsMatch.index;
@@ -1999,13 +2000,31 @@ function transformOriginDefinition(content, svelteImports) {
1999
2000
  }
2000
2001
  contentWithoutAttrs = bodyContent.slice(0, attrsStart) + bodyContent.slice(cutEnd);
2001
2002
  }
2003
+ } else {
2004
+ const externalRefMatch = bodyContent.match(/(\w+)\s*:\s*(\w+)\s*,/);
2005
+ if (externalRefMatch) {
2006
+ const propName = externalRefMatch[1];
2007
+ const refName = externalRefMatch[2];
2008
+ if ((propName === "props" || propName === "attrs") && /^[A-Z]/.test(refName) && !["$state", "$derived", "$effect", "$bindable"].includes(refName)) {
2009
+ attrPropertyName = propName;
2010
+ propsRef = refName;
2011
+ const refStart = externalRefMatch.index;
2012
+ const refEnd = refStart + externalRefMatch[0].length;
2013
+ contentWithoutAttrs = bodyContent.slice(0, refStart) + bodyContent.slice(refEnd);
2014
+ }
2015
+ }
2002
2016
  }
2003
2017
  const attrDetails = parseAttrsSource(attrsContent);
2004
2018
  const { body: createFnBody, attachments } = transformOriginBody(contentWithoutAttrs.trim(), parents, attrDetails, attrPropertyName, svelteImports);
2005
2019
  const parentsCode = parents.length > 0 ? `[${parents.join(", ")}]` : "undefined";
2006
2020
  let configCode = `{
2007
2021
  __attrSchema: ${attrSchemaCode},
2008
- __parents: ${parentsCode},
2022
+ __parents: ${parentsCode},`;
2023
+ if (propsRef) {
2024
+ configCode += `
2025
+ __propsRef: ${propsRef},`;
2026
+ }
2027
+ configCode += `
2009
2028
  __create: (__inputAttrs${parents.length > 0 ? ", __super" : ""}) => {
2010
2029
  ${createFnBody}
2011
2030
  }`;
@@ -2240,6 +2259,73 @@ function parseOriginSchemaFromSource(source, exportName) {
2240
2259
  return compiledResult;
2241
2260
  return null;
2242
2261
  }
2262
+ function parseAttrsSchemaFromSource(source, exportName) {
2263
+ const sourceResult = parseSourceAttrs(source, exportName);
2264
+ if (sourceResult)
2265
+ return sourceResult;
2266
+ const compiledResult = parseCompiledAttrs(source, exportName);
2267
+ if (compiledResult)
2268
+ return compiledResult;
2269
+ return null;
2270
+ }
2271
+ function parseSourceAttrs(source, exportName) {
2272
+ const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*\\$attrs\\s*\\(`, "s");
2273
+ const match = exportPattern.exec(source);
2274
+ if (!match)
2275
+ return null;
2276
+ const attrsStart = match.index + match[0].length - 1;
2277
+ const attrsEnd = findMatchingBracket(source, attrsStart);
2278
+ if (attrsEnd === -1)
2279
+ return null;
2280
+ let attrsContent = source.slice(attrsStart + 1, attrsEnd).trim();
2281
+ let parentNames = [];
2282
+ if (attrsContent.startsWith("[")) {
2283
+ const closeBracket = findMatchingBracket(attrsContent, 0, "[", "]");
2284
+ if (closeBracket !== -1) {
2285
+ const parentsContent = attrsContent.slice(1, closeBracket);
2286
+ parentNames = parentsContent.split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
2287
+ let i = closeBracket + 1;
2288
+ while (i < attrsContent.length && /[\s,]/.test(attrsContent[i]))
2289
+ i++;
2290
+ attrsContent = attrsContent.slice(i);
2291
+ }
2292
+ }
2293
+ if (!attrsContent.startsWith("{")) {
2294
+ return { attrs: [], parentNames };
2295
+ }
2296
+ const objEnd = findMatchingBracket(attrsContent, 0, "{", "}");
2297
+ if (objEnd === -1)
2298
+ return { attrs: [], parentNames };
2299
+ const objContent = attrsContent.slice(1, objEnd);
2300
+ const attrs = parseAttrsContent(objContent);
2301
+ return { attrs, parentNames };
2302
+ }
2303
+ function parseCompiledAttrs(source, exportName) {
2304
+ const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*__createAttrs\\s*\\(\\s*\\{`, "s");
2305
+ const match = exportPattern.exec(source);
2306
+ if (!match)
2307
+ return null;
2308
+ const braceStart = match.index + match[0].length - 1;
2309
+ const braceEnd = findMatchingBracket(source, braceStart, "{", "}");
2310
+ if (braceEnd === -1)
2311
+ return null;
2312
+ const configContent = source.slice(braceStart + 1, braceEnd);
2313
+ const schemaMatch = configContent.match(/__attrSchema\s*:\s*\{/);
2314
+ if (!schemaMatch)
2315
+ return { attrs: [], parentNames: [] };
2316
+ const schemaStart = schemaMatch.index + schemaMatch[0].length - 1;
2317
+ const schemaEnd = findMatchingBracket(configContent, schemaStart, "{", "}");
2318
+ if (schemaEnd === -1)
2319
+ return { attrs: [], parentNames: [] };
2320
+ const schemaContent = configContent.slice(schemaStart + 1, schemaEnd);
2321
+ const attrs = parseCompiledAttrSchema(schemaContent);
2322
+ const parentsMatch = configContent.match(/__parents\s*:\s*\[([^\]]*)\]/);
2323
+ let parentNames = [];
2324
+ if (parentsMatch && parentsMatch[1].trim()) {
2325
+ parentNames = parentsMatch[1].split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
2326
+ }
2327
+ return { attrs, parentNames };
2328
+ }
2243
2329
  function parseSourceOrigin(source, exportName) {
2244
2330
  const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*\\$origin\\s*\\(`, "s");
2245
2331
  const match = exportPattern.exec(source);
@@ -2265,6 +2351,13 @@ function parseSourceOrigin(source, exportName) {
2265
2351
  }
2266
2352
  const attrsMatch = bodyContent.match(/(\w+)\s*:\s*\$attrs\s*\(\s*\{/);
2267
2353
  if (!attrsMatch) {
2354
+ const externalRefMatch = bodyContent.match(/(?:props|attrs)\s*:\s*([A-Z]\w*)\b/);
2355
+ if (externalRefMatch) {
2356
+ const propsRef = externalRefMatch[1];
2357
+ if (!["Object", "Array", "String", "Number", "Boolean"].includes(propsRef)) {
2358
+ return { attrs: [], parentNames, propsRef };
2359
+ }
2360
+ }
2268
2361
  return { attrs: [], parentNames };
2269
2362
  }
2270
2363
  const attrsStart = attrsMatch.index;
@@ -2301,7 +2394,9 @@ function parseCompiledOrigin(source, exportName) {
2301
2394
  if (parentsMatch && parentsMatch[1].trim()) {
2302
2395
  parentNames = parentsMatch[1].split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
2303
2396
  }
2304
- return { attrs, parentNames };
2397
+ const propsRefMatch = configContent.match(/__propsRef\s*:\s*(\w+)/);
2398
+ const propsRef = propsRefMatch ? propsRefMatch[1] : undefined;
2399
+ return { attrs, parentNames, propsRef };
2305
2400
  }
2306
2401
  function parseCompiledAttrSchema(content) {
2307
2402
  const result = [];
@@ -3468,6 +3563,25 @@ async function resolveSchema(importPath, exportName, importerId, cache, debug, a
3468
3563
  }
3469
3564
  }
3470
3565
  }
3566
+ if (schema.propsRef) {
3567
+ const propsRefImportPath = findImportPath(source, schema.propsRef);
3568
+ if (propsRefImportPath) {
3569
+ if (debug) {
3570
+ console.log(`[svelte-origin-preprocess] Resolving propsRef: ${schema.propsRef} from ${propsRefImportPath}`);
3571
+ }
3572
+ const propsRefSchema = await resolveAttrsSchema(propsRefImportPath, schema.propsRef, filePath, cache, debug, aliases);
3573
+ if (propsRefSchema) {
3574
+ for (const attr of propsRefSchema.attrs) {
3575
+ const existingIndex = mergedAttrs.findIndex((a) => a.key === attr.key);
3576
+ if (existingIndex === -1) {
3577
+ mergedAttrs.push(attr);
3578
+ } else {
3579
+ mergedAttrs[existingIndex] = attr;
3580
+ }
3581
+ }
3582
+ }
3583
+ }
3584
+ }
3471
3585
  for (const attr of schema.attrs) {
3472
3586
  const existingIndex = mergedAttrs.findIndex((a) => a.key === attr.key);
3473
3587
  if (existingIndex !== -1) {
@@ -3493,6 +3607,75 @@ async function resolveSchema(importPath, exportName, importerId, cache, debug, a
3493
3607
  return null;
3494
3608
  }
3495
3609
  }
3610
+ async function resolveAttrsSchema(importPath, exportName, importerId, cache, debug, aliases) {
3611
+ const cacheKey = `attrs::${importPath}::${exportName}`;
3612
+ if (cache.has(cacheKey)) {
3613
+ if (debug) {
3614
+ console.log(`[svelte-origin-preprocess] Cache hit for ${cacheKey}`);
3615
+ }
3616
+ return cache.get(cacheKey) || null;
3617
+ }
3618
+ try {
3619
+ const importerDir = dirname2(importerId);
3620
+ if (debug) {
3621
+ console.log(`[svelte-origin-preprocess] Resolving attrs: ${exportName} from ${importPath}`);
3622
+ }
3623
+ const resolvedPath = resolveImportPath(importPath, aliases, importerDir);
3624
+ if (!resolvedPath) {
3625
+ cache.set(cacheKey, null);
3626
+ return null;
3627
+ }
3628
+ const filePath = resolveFilePath(resolvedPath);
3629
+ if (!filePath) {
3630
+ cache.set(cacheKey, null);
3631
+ return null;
3632
+ }
3633
+ const source = readFileSync2(filePath, "utf-8");
3634
+ const schema = parseAttrsSchemaFromSource(source, exportName);
3635
+ if (!schema) {
3636
+ cache.set(cacheKey, null);
3637
+ return null;
3638
+ }
3639
+ const mergedAttrs = [];
3640
+ for (const parentName of schema.parentNames) {
3641
+ const parentImportPath = findImportPath(source, parentName);
3642
+ if (parentImportPath) {
3643
+ const parentSchema = await resolveAttrsSchema(parentImportPath, parentName, filePath, cache, debug, aliases);
3644
+ if (parentSchema) {
3645
+ for (const attr of parentSchema.attrs) {
3646
+ const existingIndex = mergedAttrs.findIndex((a) => a.key === attr.key);
3647
+ if (existingIndex === -1) {
3648
+ mergedAttrs.push(attr);
3649
+ }
3650
+ }
3651
+ }
3652
+ }
3653
+ }
3654
+ for (const attr of schema.attrs) {
3655
+ const existingIndex = mergedAttrs.findIndex((a) => a.key === attr.key);
3656
+ if (existingIndex !== -1) {
3657
+ mergedAttrs[existingIndex] = attr;
3658
+ } else {
3659
+ mergedAttrs.push(attr);
3660
+ }
3661
+ }
3662
+ const mergedSchema = {
3663
+ attrs: mergedAttrs,
3664
+ parentNames: schema.parentNames
3665
+ };
3666
+ if (debug) {
3667
+ console.log(`[svelte-origin-preprocess] Resolved attrs schema for ${exportName}:`, mergedSchema.attrs.map((a) => a.key));
3668
+ }
3669
+ cache.set(cacheKey, mergedSchema);
3670
+ return mergedSchema;
3671
+ } catch (error) {
3672
+ if (debug) {
3673
+ console.error(`[svelte-origin-preprocess] Error resolving attrs schema for ${importPath}:`, error);
3674
+ }
3675
+ cache.set(cacheKey, null);
3676
+ return null;
3677
+ }
3678
+ }
3496
3679
  function svelteOriginPreprocess(options = {}) {
3497
3680
  const {
3498
3681
  debug = false,
@@ -19,6 +19,8 @@ export interface ParsedAttrInfo {
19
19
  export interface ParsedOriginSchema {
20
20
  attrs: ParsedAttrInfo[];
21
21
  parentNames: string[];
22
+ /** Reference to external $attrs factory (e.g., 'TextAttrs' when props: TextAttrs is used) */
23
+ propsRef?: string;
22
24
  }
23
25
  /**
24
26
  * Parse an origin's schema from its source code.
@@ -40,6 +42,21 @@ export interface ParsedOriginSchema {
40
42
  * @returns Parsed schema or null if not found
41
43
  */
42
44
  export declare function parseOriginSchemaFromSource(source: string, exportName: string): ParsedOriginSchema | null;
45
+ /**
46
+ * Parse an $attrs factory's schema from its source code.
47
+ *
48
+ * Looks for patterns like:
49
+ * ```ts
50
+ * export const TextAttrs = $attrs({ ... })
51
+ * export const TextAttrs = $attrs([BaseAttrs], { ... })
52
+ * ```
53
+ *
54
+ * Or compiled:
55
+ * ```js
56
+ * export var TextAttrs = __createAttrs({ __attrSchema: {...}, __parents: [...] })
57
+ * ```
58
+ */
59
+ export declare function parseAttrsSchemaFromSource(source: string, exportName: string): ParsedOriginSchema | null;
43
60
  /**
44
61
  * Generate $props() destructuring code from parsed attrs
45
62
  *
package/dist/vite-dts.js CHANGED
@@ -210,6 +210,73 @@ function parseOriginSchemaFromSource(source, exportName) {
210
210
  return compiledResult;
211
211
  return null;
212
212
  }
213
+ function parseAttrsSchemaFromSource(source, exportName) {
214
+ const sourceResult = parseSourceAttrs(source, exportName);
215
+ if (sourceResult)
216
+ return sourceResult;
217
+ const compiledResult = parseCompiledAttrs(source, exportName);
218
+ if (compiledResult)
219
+ return compiledResult;
220
+ return null;
221
+ }
222
+ function parseSourceAttrs(source, exportName) {
223
+ const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*\\$attrs\\s*\\(`, "s");
224
+ const match = exportPattern.exec(source);
225
+ if (!match)
226
+ return null;
227
+ const attrsStart = match.index + match[0].length - 1;
228
+ const attrsEnd = findMatchingBracket(source, attrsStart);
229
+ if (attrsEnd === -1)
230
+ return null;
231
+ let attrsContent = source.slice(attrsStart + 1, attrsEnd).trim();
232
+ let parentNames = [];
233
+ if (attrsContent.startsWith("[")) {
234
+ const closeBracket = findMatchingBracket(attrsContent, 0, "[", "]");
235
+ if (closeBracket !== -1) {
236
+ const parentsContent = attrsContent.slice(1, closeBracket);
237
+ parentNames = parentsContent.split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
238
+ let i = closeBracket + 1;
239
+ while (i < attrsContent.length && /[\s,]/.test(attrsContent[i]))
240
+ i++;
241
+ attrsContent = attrsContent.slice(i);
242
+ }
243
+ }
244
+ if (!attrsContent.startsWith("{")) {
245
+ return { attrs: [], parentNames };
246
+ }
247
+ const objEnd = findMatchingBracket(attrsContent, 0, "{", "}");
248
+ if (objEnd === -1)
249
+ return { attrs: [], parentNames };
250
+ const objContent = attrsContent.slice(1, objEnd);
251
+ const attrs = parseAttrsContent(objContent);
252
+ return { attrs, parentNames };
253
+ }
254
+ function parseCompiledAttrs(source, exportName) {
255
+ const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*__createAttrs\\s*\\(\\s*\\{`, "s");
256
+ const match = exportPattern.exec(source);
257
+ if (!match)
258
+ return null;
259
+ const braceStart = match.index + match[0].length - 1;
260
+ const braceEnd = findMatchingBracket(source, braceStart, "{", "}");
261
+ if (braceEnd === -1)
262
+ return null;
263
+ const configContent = source.slice(braceStart + 1, braceEnd);
264
+ const schemaMatch = configContent.match(/__attrSchema\s*:\s*\{/);
265
+ if (!schemaMatch)
266
+ return { attrs: [], parentNames: [] };
267
+ const schemaStart = schemaMatch.index + schemaMatch[0].length - 1;
268
+ const schemaEnd = findMatchingBracket(configContent, schemaStart, "{", "}");
269
+ if (schemaEnd === -1)
270
+ return { attrs: [], parentNames: [] };
271
+ const schemaContent = configContent.slice(schemaStart + 1, schemaEnd);
272
+ const attrs = parseCompiledAttrSchema(schemaContent);
273
+ const parentsMatch = configContent.match(/__parents\s*:\s*\[([^\]]*)\]/);
274
+ let parentNames = [];
275
+ if (parentsMatch && parentsMatch[1].trim()) {
276
+ parentNames = parentsMatch[1].split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
277
+ }
278
+ return { attrs, parentNames };
279
+ }
213
280
  function parseSourceOrigin(source, exportName) {
214
281
  const exportPattern = new RegExp(`export\\s+(?:const|var|let)\\s+${exportName}\\s*=\\s*\\$origin\\s*\\(`, "s");
215
282
  const match = exportPattern.exec(source);
@@ -235,6 +302,13 @@ function parseSourceOrigin(source, exportName) {
235
302
  }
236
303
  const attrsMatch = bodyContent.match(/(\w+)\s*:\s*\$attrs\s*\(\s*\{/);
237
304
  if (!attrsMatch) {
305
+ const externalRefMatch = bodyContent.match(/(?:props|attrs)\s*:\s*([A-Z]\w*)\b/);
306
+ if (externalRefMatch) {
307
+ const propsRef = externalRefMatch[1];
308
+ if (!["Object", "Array", "String", "Number", "Boolean"].includes(propsRef)) {
309
+ return { attrs: [], parentNames, propsRef };
310
+ }
311
+ }
238
312
  return { attrs: [], parentNames };
239
313
  }
240
314
  const attrsStart = attrsMatch.index;
@@ -271,7 +345,9 @@ function parseCompiledOrigin(source, exportName) {
271
345
  if (parentsMatch && parentsMatch[1].trim()) {
272
346
  parentNames = parentsMatch[1].split(",").map((p) => p.trim()).filter((p) => p && /^\w+$/.test(p));
273
347
  }
274
- return { attrs, parentNames };
348
+ const propsRefMatch = configContent.match(/__propsRef\s*:\s*(\w+)/);
349
+ const propsRef = propsRefMatch ? propsRefMatch[1] : undefined;
350
+ return { attrs, parentNames, propsRef };
275
351
  }
276
352
  function parseCompiledAttrSchema(content) {
277
353
  const result = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-origin",
3
- "version": "1.0.0-next.21",
3
+ "version": "1.0.0-next.22",
4
4
  "description": "Compiler-assisted state and prop ergonomics for Svelte 5",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",