snice 3.10.2 → 3.10.3

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/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * snice v3.10.1
2
+ * snice v3.10.2
3
3
  * Imperative TypeScript framework for building vanilla web components with decorators, differential rendering, routing, and controllers. No virtual DOM, no build complexity.
4
4
  * (c) 2024
5
5
  * Released under the MIT License.
@@ -3014,17 +3014,19 @@ function applyElementFunctionality(constructor) {
3014
3014
  }
3015
3015
  }
3016
3016
  }
3017
- // Apply any properties that were set before element was connected
3018
- // BUT only if they don't have an HTML attribute (don't override HTML attributes)
3017
+ // Clear pre-init values for properties that have HTML attributes
3018
+ // This prevents field initializers from overwriting HTML attributes later
3019
3019
  if (this[PRE_INIT_PROPERTY_VALUES]) {
3020
- for (const [propName, propValue] of this[PRE_INIT_PROPERTY_VALUES]) {
3021
- // Remove from map first so getter doesn't return it during setter call
3022
- this[PRE_INIT_PROPERTY_VALUES].delete(propName);
3023
- // Only apply pre-init value if NO HTML attribute exists
3024
- // This prevents field initializers from overwriting HTML attributes
3020
+ for (const [propName, propValue] of Array.from(this[PRE_INIT_PROPERTY_VALUES].entries())) {
3025
3021
  const propOptions = properties?.get(propName);
3026
3022
  const attributeName = typeof propOptions?.attribute === 'string' ? propOptions.attribute : propName.toLowerCase();
3027
- if (!this.hasAttribute(attributeName)) {
3023
+ if (this.hasAttribute(attributeName)) {
3024
+ // Attribute exists - remove from PRE_INIT to prevent overwriting
3025
+ this[PRE_INIT_PROPERTY_VALUES].delete(propName);
3026
+ }
3027
+ else {
3028
+ // No attribute - apply the pre-init value
3029
+ this[PRE_INIT_PROPERTY_VALUES].delete(propName);
3028
3030
  this[propName] = propValue;
3029
3031
  }
3030
3032
  }
@@ -3284,16 +3286,18 @@ function property(options) {
3284
3286
  context.metadata[PROPERTIES].set(propertyKey, options || {});
3285
3287
  // Return a field initializer function for new decorators
3286
3288
  return function (initialValue) {
3289
+ // Ensure constructor[PROPERTIES] exists
3290
+ const constructor = this.constructor;
3291
+ if (!constructor[PROPERTIES]) {
3292
+ constructor[PROPERTIES] = new Map();
3293
+ }
3287
3294
  // Detect type from initial value if not explicitly provided
3288
3295
  const finalOptions = { ...options };
3289
3296
  if (!finalOptions.type && initialValue !== undefined) {
3290
3297
  finalOptions.type = detectType(initialValue);
3291
- // Update the metadata with the detected type
3292
- const constructor = this.constructor;
3293
- if (constructor[PROPERTIES]) {
3294
- constructor[PROPERTIES].set(propertyKey, finalOptions);
3295
- }
3296
3298
  }
3299
+ // Always store property options on constructor for runtime access
3300
+ constructor[PROPERTIES].set(propertyKey, finalOptions);
3297
3301
  // Set up the property descriptor on first access
3298
3302
  if (!Object.hasOwnProperty.call(this.constructor.prototype, propertyKey)) {
3299
3303
  const descriptor = {
@@ -3322,8 +3326,9 @@ function property(options) {
3322
3326
  // Get old value by calling the getter (which reads from attribute)
3323
3327
  const oldValue = this[propertyKey];
3324
3328
  // Check if value actually changed
3325
- if (oldValue === newValue)
3329
+ if (oldValue === newValue) {
3326
3330
  return;
3331
+ }
3327
3332
  // Don't reflect to DOM until connectedCallback has started
3328
3333
  // This prevents field initializers from overwriting HTML attributes
3329
3334
  if (!this[PROPERTIES_INITIALIZED]) {