svelte-origin 1.0.0-next.19 → 1.0.0-next.20

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 CHANGED
@@ -2032,65 +2032,15 @@ function transformOriginBody(content, parents = [], attrDetails = [], propName =
2032
2032
  const hasParents = parents.length > 0;
2033
2033
  const propsLines = [];
2034
2034
  if (attrDetails.length > 0) {
2035
- const initialProps = [];
2035
+ const propDefs = [];
2036
2036
  for (const attr of attrDetails) {
2037
2037
  const defaultExpr = attr.hasDefault ? ` ?? ${attr.defaultValue}` : "";
2038
- initialProps.push(`${attr.key}: __inputAttrs.${attr.key}${defaultExpr}`);
2039
- }
2040
- propsLines.push(`let __props = $state({ ${initialProps.join(", ")} })`);
2041
- for (const attr of attrDetails) {
2042
- const defaultExpr = attr.hasDefault ? ` ?? ${attr.defaultValue}` : "";
2043
- const parentLast = `__last_parent_${attr.key}`;
2044
- const localLast = `__last_local_${attr.key}`;
2045
- propsLines.push(`let ${parentLast} = __inputAttrs.${attr.key}`, `let ${localLast} = __props.${attr.key}`, `$effect(() => {
2046
- ` + ` const __parent = __inputAttrs.${attr.key}
2047
- ` + ` const __local = __props.${attr.key}
2048
-
2049
- ` + ` // Parent -> local
2050
- ` + ` if (__parent !== ${parentLast}) {
2051
- ` + ` ${parentLast} = __parent
2052
- ` + ` if (__local !== __parent) {
2053
- ` + ` __props.${attr.key} = __parent${defaultExpr}
2054
- ` + ` }
2055
- ` + ` ${localLast} = __props.${attr.key}
2056
- ` + ` return
2057
- ` + ` }
2058
-
2059
- ` + ` // Local -> parent
2060
- ` + ` if (__local !== ${localLast}) {
2061
- ` + ` ${localLast} = __local
2062
- ` + (attr.bindable ? ` try { __inputAttrs.${attr.key} = __local } catch {}
2063
- ${parentLast} = __inputAttrs.${attr.key}
2064
- ` : "") + ` }
2065
- ` + `})`);
2038
+ propDefs.push(`get ${attr.key}() { return __inputAttrs.${attr.key}${defaultExpr} }`);
2039
+ propDefs.push(`set ${attr.key}(v) { __inputAttrs.${attr.key} = v }`);
2066
2040
  }
2041
+ propsLines.push(`const __props = { ${propDefs.join(", ")} }`);
2067
2042
  } else {
2068
- propsLines.push("let __props = $state({ ...__inputAttrs })", "const __syncState = new Map()", `$effect.pre(() => {
2069
- ` + ` // Bidirectional sync between __inputAttrs and __props
2070
- ` + ` for (const key of Object.keys(__inputAttrs)) {
2071
- ` + ` const parentVal = __inputAttrs[key]
2072
- ` + ` const localVal = __props[key]
2073
- ` + ` const state = __syncState.get(key) ?? { parent: parentVal, local: localVal }
2074
- ` + ` __syncState.set(key, state)
2075
-
2076
- ` + ` // Parent changed -> update local
2077
- ` + ` if (parentVal !== state.parent) {
2078
- ` + ` state.parent = parentVal
2079
- ` + ` if (localVal !== parentVal) {
2080
- ` + ` __props[key] = parentVal
2081
- ` + ` state.local = parentVal
2082
- ` + ` }
2083
- ` + ` continue
2084
- ` + ` }
2085
-
2086
- ` + ` // Local changed -> update parent (for bindable props)
2087
- ` + ` if (localVal !== state.local) {
2088
- ` + ` state.local = localVal
2089
- ` + ` try { __inputAttrs[key] = localVal } catch {}
2090
- ` + ` state.parent = __inputAttrs[key]
2091
- ` + ` }
2092
- ` + ` }
2093
- ` + ` })`);
2043
+ propsLines.push("const __props = __inputAttrs");
2094
2044
  }
2095
2045
  const propsObjectCode = "\t\t" + propsLines.join(`
2096
2046
  `);
package/dist/index.js CHANGED
@@ -6120,65 +6120,15 @@ function transformOriginBody(content, parents = [], attrDetails = [], propName =
6120
6120
  const hasParents = parents.length > 0;
6121
6121
  const propsLines = [];
6122
6122
  if (attrDetails.length > 0) {
6123
- const initialProps = [];
6123
+ const propDefs = [];
6124
6124
  for (const attr2 of attrDetails) {
6125
6125
  const defaultExpr = attr2.hasDefault ? ` ?? ${attr2.defaultValue}` : "";
6126
- initialProps.push(`${attr2.key}: __inputAttrs.${attr2.key}${defaultExpr}`);
6127
- }
6128
- propsLines.push(`let __props = $state({ ${initialProps.join(", ")} })`);
6129
- for (const attr2 of attrDetails) {
6130
- const defaultExpr = attr2.hasDefault ? ` ?? ${attr2.defaultValue}` : "";
6131
- const parentLast = `__last_parent_${attr2.key}`;
6132
- const localLast = `__last_local_${attr2.key}`;
6133
- propsLines.push(`let ${parentLast} = __inputAttrs.${attr2.key}`, `let ${localLast} = __props.${attr2.key}`, `$effect(() => {
6134
- ` + ` const __parent = __inputAttrs.${attr2.key}
6135
- ` + ` const __local = __props.${attr2.key}
6136
-
6137
- ` + ` // Parent -> local
6138
- ` + ` if (__parent !== ${parentLast}) {
6139
- ` + ` ${parentLast} = __parent
6140
- ` + ` if (__local !== __parent) {
6141
- ` + ` __props.${attr2.key} = __parent${defaultExpr}
6142
- ` + ` }
6143
- ` + ` ${localLast} = __props.${attr2.key}
6144
- ` + ` return
6145
- ` + ` }
6146
-
6147
- ` + ` // Local -> parent
6148
- ` + ` if (__local !== ${localLast}) {
6149
- ` + ` ${localLast} = __local
6150
- ` + (attr2.bindable ? ` try { __inputAttrs.${attr2.key} = __local } catch {}
6151
- ${parentLast} = __inputAttrs.${attr2.key}
6152
- ` : "") + ` }
6153
- ` + `})`);
6126
+ propDefs.push(`get ${attr2.key}() { return __inputAttrs.${attr2.key}${defaultExpr} }`);
6127
+ propDefs.push(`set ${attr2.key}(v) { __inputAttrs.${attr2.key} = v }`);
6154
6128
  }
6129
+ propsLines.push(`const __props = { ${propDefs.join(", ")} }`);
6155
6130
  } else {
6156
- propsLines.push("let __props = $state({ ...__inputAttrs })", "const __syncState = new Map()", `$effect.pre(() => {
6157
- ` + ` // Bidirectional sync between __inputAttrs and __props
6158
- ` + ` for (const key of Object.keys(__inputAttrs)) {
6159
- ` + ` const parentVal = __inputAttrs[key]
6160
- ` + ` const localVal = __props[key]
6161
- ` + ` const state = __syncState.get(key) ?? { parent: parentVal, local: localVal }
6162
- ` + ` __syncState.set(key, state)
6163
-
6164
- ` + ` // Parent changed -> update local
6165
- ` + ` if (parentVal !== state.parent) {
6166
- ` + ` state.parent = parentVal
6167
- ` + ` if (localVal !== parentVal) {
6168
- ` + ` __props[key] = parentVal
6169
- ` + ` state.local = parentVal
6170
- ` + ` }
6171
- ` + ` continue
6172
- ` + ` }
6173
-
6174
- ` + ` // Local changed -> update parent (for bindable props)
6175
- ` + ` if (localVal !== state.local) {
6176
- ` + ` state.local = localVal
6177
- ` + ` try { __inputAttrs[key] = localVal } catch {}
6178
- ` + ` state.parent = __inputAttrs[key]
6179
- ` + ` }
6180
- ` + ` }
6181
- ` + ` })`);
6131
+ propsLines.push("const __props = __inputAttrs");
6182
6132
  }
6183
6133
  const propsObjectCode = "\t\t" + propsLines.join(`
6184
6134
  `);
package/dist/plugin.js CHANGED
@@ -2026,65 +2026,15 @@ function transformOriginBody(content, parents = [], attrDetails = [], propName =
2026
2026
  const hasParents = parents.length > 0;
2027
2027
  const propsLines = [];
2028
2028
  if (attrDetails.length > 0) {
2029
- const initialProps = [];
2029
+ const propDefs = [];
2030
2030
  for (const attr of attrDetails) {
2031
2031
  const defaultExpr = attr.hasDefault ? ` ?? ${attr.defaultValue}` : "";
2032
- initialProps.push(`${attr.key}: __inputAttrs.${attr.key}${defaultExpr}`);
2033
- }
2034
- propsLines.push(`let __props = $state({ ${initialProps.join(", ")} })`);
2035
- for (const attr of attrDetails) {
2036
- const defaultExpr = attr.hasDefault ? ` ?? ${attr.defaultValue}` : "";
2037
- const parentLast = `__last_parent_${attr.key}`;
2038
- const localLast = `__last_local_${attr.key}`;
2039
- propsLines.push(`let ${parentLast} = __inputAttrs.${attr.key}`, `let ${localLast} = __props.${attr.key}`, `$effect(() => {
2040
- ` + ` const __parent = __inputAttrs.${attr.key}
2041
- ` + ` const __local = __props.${attr.key}
2042
-
2043
- ` + ` // Parent -> local
2044
- ` + ` if (__parent !== ${parentLast}) {
2045
- ` + ` ${parentLast} = __parent
2046
- ` + ` if (__local !== __parent) {
2047
- ` + ` __props.${attr.key} = __parent${defaultExpr}
2048
- ` + ` }
2049
- ` + ` ${localLast} = __props.${attr.key}
2050
- ` + ` return
2051
- ` + ` }
2052
-
2053
- ` + ` // Local -> parent
2054
- ` + ` if (__local !== ${localLast}) {
2055
- ` + ` ${localLast} = __local
2056
- ` + (attr.bindable ? ` try { __inputAttrs.${attr.key} = __local } catch {}
2057
- ${parentLast} = __inputAttrs.${attr.key}
2058
- ` : "") + ` }
2059
- ` + `})`);
2032
+ propDefs.push(`get ${attr.key}() { return __inputAttrs.${attr.key}${defaultExpr} }`);
2033
+ propDefs.push(`set ${attr.key}(v) { __inputAttrs.${attr.key} = v }`);
2060
2034
  }
2035
+ propsLines.push(`const __props = { ${propDefs.join(", ")} }`);
2061
2036
  } else {
2062
- propsLines.push("let __props = $state({ ...__inputAttrs })", "const __syncState = new Map()", `$effect.pre(() => {
2063
- ` + ` // Bidirectional sync between __inputAttrs and __props
2064
- ` + ` for (const key of Object.keys(__inputAttrs)) {
2065
- ` + ` const parentVal = __inputAttrs[key]
2066
- ` + ` const localVal = __props[key]
2067
- ` + ` const state = __syncState.get(key) ?? { parent: parentVal, local: localVal }
2068
- ` + ` __syncState.set(key, state)
2069
-
2070
- ` + ` // Parent changed -> update local
2071
- ` + ` if (parentVal !== state.parent) {
2072
- ` + ` state.parent = parentVal
2073
- ` + ` if (localVal !== parentVal) {
2074
- ` + ` __props[key] = parentVal
2075
- ` + ` state.local = parentVal
2076
- ` + ` }
2077
- ` + ` continue
2078
- ` + ` }
2079
-
2080
- ` + ` // Local changed -> update parent (for bindable props)
2081
- ` + ` if (localVal !== state.local) {
2082
- ` + ` state.local = localVal
2083
- ` + ` try { __inputAttrs[key] = localVal } catch {}
2084
- ` + ` state.parent = __inputAttrs[key]
2085
- ` + ` }
2086
- ` + ` }
2087
- ` + ` })`);
2037
+ propsLines.push("const __props = __inputAttrs");
2088
2038
  }
2089
2039
  const propsObjectCode = "\t\t" + propsLines.join(`
2090
2040
  `);
@@ -2030,65 +2030,15 @@ function transformOriginBody(content, parents = [], attrDetails = [], propName =
2030
2030
  const hasParents = parents.length > 0;
2031
2031
  const propsLines = [];
2032
2032
  if (attrDetails.length > 0) {
2033
- const initialProps = [];
2033
+ const propDefs = [];
2034
2034
  for (const attr of attrDetails) {
2035
2035
  const defaultExpr = attr.hasDefault ? ` ?? ${attr.defaultValue}` : "";
2036
- initialProps.push(`${attr.key}: __inputAttrs.${attr.key}${defaultExpr}`);
2037
- }
2038
- propsLines.push(`let __props = $state({ ${initialProps.join(", ")} })`);
2039
- for (const attr of attrDetails) {
2040
- const defaultExpr = attr.hasDefault ? ` ?? ${attr.defaultValue}` : "";
2041
- const parentLast = `__last_parent_${attr.key}`;
2042
- const localLast = `__last_local_${attr.key}`;
2043
- propsLines.push(`let ${parentLast} = __inputAttrs.${attr.key}`, `let ${localLast} = __props.${attr.key}`, `$effect(() => {
2044
- ` + ` const __parent = __inputAttrs.${attr.key}
2045
- ` + ` const __local = __props.${attr.key}
2046
-
2047
- ` + ` // Parent -> local
2048
- ` + ` if (__parent !== ${parentLast}) {
2049
- ` + ` ${parentLast} = __parent
2050
- ` + ` if (__local !== __parent) {
2051
- ` + ` __props.${attr.key} = __parent${defaultExpr}
2052
- ` + ` }
2053
- ` + ` ${localLast} = __props.${attr.key}
2054
- ` + ` return
2055
- ` + ` }
2056
-
2057
- ` + ` // Local -> parent
2058
- ` + ` if (__local !== ${localLast}) {
2059
- ` + ` ${localLast} = __local
2060
- ` + (attr.bindable ? ` try { __inputAttrs.${attr.key} = __local } catch {}
2061
- ${parentLast} = __inputAttrs.${attr.key}
2062
- ` : "") + ` }
2063
- ` + `})`);
2036
+ propDefs.push(`get ${attr.key}() { return __inputAttrs.${attr.key}${defaultExpr} }`);
2037
+ propDefs.push(`set ${attr.key}(v) { __inputAttrs.${attr.key} = v }`);
2064
2038
  }
2039
+ propsLines.push(`const __props = { ${propDefs.join(", ")} }`);
2065
2040
  } else {
2066
- propsLines.push("let __props = $state({ ...__inputAttrs })", "const __syncState = new Map()", `$effect.pre(() => {
2067
- ` + ` // Bidirectional sync between __inputAttrs and __props
2068
- ` + ` for (const key of Object.keys(__inputAttrs)) {
2069
- ` + ` const parentVal = __inputAttrs[key]
2070
- ` + ` const localVal = __props[key]
2071
- ` + ` const state = __syncState.get(key) ?? { parent: parentVal, local: localVal }
2072
- ` + ` __syncState.set(key, state)
2073
-
2074
- ` + ` // Parent changed -> update local
2075
- ` + ` if (parentVal !== state.parent) {
2076
- ` + ` state.parent = parentVal
2077
- ` + ` if (localVal !== parentVal) {
2078
- ` + ` __props[key] = parentVal
2079
- ` + ` state.local = parentVal
2080
- ` + ` }
2081
- ` + ` continue
2082
- ` + ` }
2083
-
2084
- ` + ` // Local changed -> update parent (for bindable props)
2085
- ` + ` if (localVal !== state.local) {
2086
- ` + ` state.local = localVal
2087
- ` + ` try { __inputAttrs[key] = localVal } catch {}
2088
- ` + ` state.parent = __inputAttrs[key]
2089
- ` + ` }
2090
- ` + ` }
2091
- ` + ` })`);
2041
+ propsLines.push("const __props = __inputAttrs");
2092
2042
  }
2093
2043
  const propsObjectCode = "\t\t" + propsLines.join(`
2094
2044
  `);
@@ -2026,65 +2026,15 @@ function transformOriginBody(content, parents = [], attrDetails = [], propName =
2026
2026
  const hasParents = parents.length > 0;
2027
2027
  const propsLines = [];
2028
2028
  if (attrDetails.length > 0) {
2029
- const initialProps = [];
2029
+ const propDefs = [];
2030
2030
  for (const attr of attrDetails) {
2031
2031
  const defaultExpr = attr.hasDefault ? ` ?? ${attr.defaultValue}` : "";
2032
- initialProps.push(`${attr.key}: __inputAttrs.${attr.key}${defaultExpr}`);
2033
- }
2034
- propsLines.push(`let __props = $state({ ${initialProps.join(", ")} })`);
2035
- for (const attr of attrDetails) {
2036
- const defaultExpr = attr.hasDefault ? ` ?? ${attr.defaultValue}` : "";
2037
- const parentLast = `__last_parent_${attr.key}`;
2038
- const localLast = `__last_local_${attr.key}`;
2039
- propsLines.push(`let ${parentLast} = __inputAttrs.${attr.key}`, `let ${localLast} = __props.${attr.key}`, `$effect(() => {
2040
- ` + ` const __parent = __inputAttrs.${attr.key}
2041
- ` + ` const __local = __props.${attr.key}
2042
-
2043
- ` + ` // Parent -> local
2044
- ` + ` if (__parent !== ${parentLast}) {
2045
- ` + ` ${parentLast} = __parent
2046
- ` + ` if (__local !== __parent) {
2047
- ` + ` __props.${attr.key} = __parent${defaultExpr}
2048
- ` + ` }
2049
- ` + ` ${localLast} = __props.${attr.key}
2050
- ` + ` return
2051
- ` + ` }
2052
-
2053
- ` + ` // Local -> parent
2054
- ` + ` if (__local !== ${localLast}) {
2055
- ` + ` ${localLast} = __local
2056
- ` + (attr.bindable ? ` try { __inputAttrs.${attr.key} = __local } catch {}
2057
- ${parentLast} = __inputAttrs.${attr.key}
2058
- ` : "") + ` }
2059
- ` + `})`);
2032
+ propDefs.push(`get ${attr.key}() { return __inputAttrs.${attr.key}${defaultExpr} }`);
2033
+ propDefs.push(`set ${attr.key}(v) { __inputAttrs.${attr.key} = v }`);
2060
2034
  }
2035
+ propsLines.push(`const __props = { ${propDefs.join(", ")} }`);
2061
2036
  } else {
2062
- propsLines.push("let __props = $state({ ...__inputAttrs })", "const __syncState = new Map()", `$effect.pre(() => {
2063
- ` + ` // Bidirectional sync between __inputAttrs and __props
2064
- ` + ` for (const key of Object.keys(__inputAttrs)) {
2065
- ` + ` const parentVal = __inputAttrs[key]
2066
- ` + ` const localVal = __props[key]
2067
- ` + ` const state = __syncState.get(key) ?? { parent: parentVal, local: localVal }
2068
- ` + ` __syncState.set(key, state)
2069
-
2070
- ` + ` // Parent changed -> update local
2071
- ` + ` if (parentVal !== state.parent) {
2072
- ` + ` state.parent = parentVal
2073
- ` + ` if (localVal !== parentVal) {
2074
- ` + ` __props[key] = parentVal
2075
- ` + ` state.local = parentVal
2076
- ` + ` }
2077
- ` + ` continue
2078
- ` + ` }
2079
-
2080
- ` + ` // Local changed -> update parent (for bindable props)
2081
- ` + ` if (localVal !== state.local) {
2082
- ` + ` state.local = localVal
2083
- ` + ` try { __inputAttrs[key] = localVal } catch {}
2084
- ` + ` state.parent = __inputAttrs[key]
2085
- ` + ` }
2086
- ` + ` }
2087
- ` + ` })`);
2037
+ propsLines.push("const __props = __inputAttrs");
2088
2038
  }
2089
2039
  const propsObjectCode = "\t\t" + propsLines.join(`
2090
2040
  `);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-origin",
3
- "version": "1.0.0-next.19",
3
+ "version": "1.0.0-next.20",
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",