assign-gingerly 0.0.53 → 0.0.55

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.
Files changed (114) hide show
  1. package/README.md +847 -5
  2. package/assignFrom.js +229 -9
  3. package/assignFrom.ts +338 -9
  4. package/assignGingerly.js +34 -1
  5. package/assignGingerly.ts +54 -1
  6. package/beVigilant.js +73 -0
  7. package/beVigilant.ts +85 -0
  8. package/enhanceAll.js +106 -0
  9. package/enhanceAll.ts +138 -0
  10. package/handlers/join.js +74 -0
  11. package/handlers/join.ts +80 -0
  12. package/handlers/lazyLoad.js +212 -0
  13. package/handlers/lazyLoad.ts +307 -0
  14. package/handlers/lazyLoadSwitch.js +58 -0
  15. package/handlers/lazyLoadSwitch.ts +63 -0
  16. package/handlers/microDataJoin.js +184 -0
  17. package/handlers/microDataJoin.ts +270 -0
  18. package/inferencer/.gitmodules +3 -0
  19. package/inferencer/.vscode/settings.json +2 -0
  20. package/inferencer/InferencedPropagator.js +230 -0
  21. package/inferencer/InferencedPropagator.ts +269 -0
  22. package/inferencer/LICENSE +21 -0
  23. package/inferencer/README.md +524 -0
  24. package/inferencer/Requirements/SupportForPropagator.md +368 -0
  25. package/inferencer/imports.html +7 -0
  26. package/inferencer/inferencer.js +254 -0
  27. package/inferencer/inferencer.ts +292 -0
  28. package/inferencer/package-lock.json +129 -0
  29. package/inferencer/package.json +60 -0
  30. package/inferencer/playwright-report/data/507ad515125e13390ea07de92f22331c913fa068.md +55 -0
  31. package/inferencer/playwright-report/index.html +90 -0
  32. package/inferencer/playwright.config.ts +54 -0
  33. package/inferencer/test-results/.last-run.json +6 -0
  34. package/inferencer/test-results/inferencer-Inferencer-Enha-535bc-inferencer-tests-in-browser-chromium/error-context.md +55 -0
  35. package/inferencer/tests/inferencedPropagator.html +428 -0
  36. package/inferencer/tests/inferencedPropagator.spec.ts +18 -0
  37. package/inferencer/tests/inferencer.html +355 -0
  38. package/inferencer/tests/inferencer.spec.ts +19 -0
  39. package/inferencer/tsconfig.json +19 -0
  40. package/inferencer/types/.kiro/specs/conversion-template/README.md +128 -0
  41. package/inferencer/types/.kiro/specs/conversion-template/design.md +360 -0
  42. package/inferencer/types/.kiro/specs/conversion-template/requirements.md +191 -0
  43. package/inferencer/types/.kiro/specs/conversion-template/tasks.md +174 -0
  44. package/inferencer/types/.kiro/steering/coding-standards.md +53 -0
  45. package/inferencer/types/.kiro/steering/conversion-guide.md +108 -0
  46. package/inferencer/types/.kiro/steering/declarative-configuration.md +108 -0
  47. package/inferencer/types/.kiro/steering/emc-json-serializability.md +306 -0
  48. package/inferencer/types/EnhancementConversionInstructions.md +1854 -0
  49. package/inferencer/types/LICENSE +21 -0
  50. package/inferencer/types/NewCustomElement.md +388 -0
  51. package/inferencer/types/NewCustomElementFeature.md +683 -0
  52. package/inferencer/types/NewEnhancementInstructions.md +705 -0
  53. package/inferencer/types/README.md +2 -0
  54. package/inferencer/types/agrace/types.d.ts +11 -0
  55. package/inferencer/types/assign-gingerly/types.d.ts +572 -0
  56. package/inferencer/types/be-a-beacon/types.d.ts +17 -0
  57. package/inferencer/types/be-bound/types.d.ts +66 -0
  58. package/inferencer/types/be-buttoned-up/types.d.ts +19 -0
  59. package/inferencer/types/be-calculating/types.d.ts +54 -0
  60. package/inferencer/types/be-clonable/types.d.ts +38 -0
  61. package/inferencer/types/be-committed/types.d.ts +22 -0
  62. package/inferencer/types/be-consoling/types.d.ts +24 -0
  63. package/inferencer/types/be-decked-with/types.d.ts +26 -0
  64. package/inferencer/types/be-delible/types.d.ts +27 -0
  65. package/inferencer/types/be-dispatching/types.d.ts +34 -0
  66. package/inferencer/types/be-evanescent/types.d.ts +20 -0
  67. package/inferencer/types/be-flashy/types.d.ts +21 -0
  68. package/inferencer/types/be-gone/types.d.ts +25 -0
  69. package/inferencer/types/be-observing/types.d.ts +55 -0
  70. package/inferencer/types/be-reflective/types.d.ts +78 -0
  71. package/inferencer/types/be-reformable/types.d.ts +49 -0
  72. package/inferencer/types/be-render-neutral/types.d.ts +32 -0
  73. package/inferencer/types/be-switched/types.d.ts +146 -0
  74. package/inferencer/types/be-typed/types.d.ts +32 -0
  75. package/inferencer/types/be-valued/types.d.ts +22 -0
  76. package/inferencer/types/data-props/types.d.ts +34 -0
  77. package/inferencer/types/do-inc/types.d.ts +56 -0
  78. package/inferencer/types/do-invoke/types.d.ts +38 -0
  79. package/inferencer/types/do-merge/types.d.ts +28 -0
  80. package/inferencer/types/do-toggle/types.d.ts +31 -0
  81. package/inferencer/types/face-up/types.d.ts +100 -0
  82. package/inferencer/types/fetch-for/types.d.ts +36 -0
  83. package/inferencer/types/folder-picker/types.d.ts +21 -0
  84. package/inferencer/types/global.d.ts +29 -0
  85. package/inferencer/types/id-generation/types.d.ts +26 -0
  86. package/inferencer/types/inferencer/types.d.ts +46 -0
  87. package/inferencer/types/mount-observer/types.d.ts +363 -0
  88. package/inferencer/types/nested-regex-groups/types.d.ts +107 -0
  89. package/inferencer/types/pipe-in/types.d.ts +52 -0
  90. package/inferencer/types/roundabout/types.d.ts +268 -0
  91. package/inferencer/types/soak-up/types.d.ts +40 -0
  92. package/inferencer/types/templ-maker/types.d.ts +43 -0
  93. package/inferencer/types/time-ticker/types.d.ts +62 -0
  94. package/inferencer/types/truth-sourcer/types.d.ts +44 -0
  95. package/inferencer/upSearch.js +27 -0
  96. package/inferencer/upSearch.ts +26 -0
  97. package/inferencer/withScopePerimeter.js +27 -0
  98. package/inferencer/withScopePerimeter.ts +33 -0
  99. package/inferredAssignments.js +38 -0
  100. package/inferredAssignments.ts +65 -0
  101. package/isAllowedImportPath.js +42 -0
  102. package/isAllowedImportPath.ts +53 -0
  103. package/package.json +57 -3
  104. package/paths.js +231 -0
  105. package/paths.ts +413 -0
  106. package/processHandlerCommands.js +188 -0
  107. package/processHandlerCommands.ts +217 -0
  108. package/resolveIdRef.js +144 -0
  109. package/resolveIdRef.ts +170 -0
  110. package/resolveValues.js +41 -2
  111. package/resolveValues.ts +41 -1
  112. package/transitionHelper.js +109 -0
  113. package/transitionHelper.ts +132 -0
  114. package/types/assign-gingerly/types.d.ts +89 -0
@@ -0,0 +1,269 @@
1
+ import {Infer, inferEventType} from './inferencer.js';
2
+
3
+ /**
4
+ * An inferred propagator that extends EventTarget.
5
+ * Emits property change events by intelligently hooking into
6
+ * whatever change detection mechanism is available for the element.
7
+ *
8
+ * Property observation is lazy — wiring only happens when
9
+ * addEventListener is called for a given property name.
10
+ */
11
+ export class InferencedPropagator extends EventTarget {
12
+ #infer: Infer;
13
+ #watchedProperties: Map<string, () => void> = new Map();
14
+
15
+ constructor(infer: Infer) {
16
+ super();
17
+ this.#infer = infer;
18
+ }
19
+
20
+ override addEventListener(
21
+ type: string,
22
+ callback: EventListenerOrEventListenerObject | null,
23
+ options?: AddEventListenerOptions | boolean
24
+ ): void {
25
+ super.addEventListener(type, callback, options);
26
+
27
+ if (!this.#watchedProperties.has(type)) {
28
+ // Placeholder cleanup until async wiring completes
29
+ this.#watchedProperties.set(type, () => {});
30
+ this.#wireProperty(type);
31
+ }
32
+ }
33
+
34
+ override removeEventListener(
35
+ type: string,
36
+ callback: EventListenerOrEventListenerObject | null,
37
+ options?: EventListenerOptions | boolean
38
+ ): void {
39
+ super.removeEventListener(type, callback, options);
40
+ }
41
+
42
+ async #wireProperty(propName: string): Promise<void> {
43
+ const element = this.#infer.enhancedElement;
44
+
45
+ // Snapshot current value before async setup
46
+ const initialValue = (element as any)[propName];
47
+
48
+ const cleanup = await this.#setupStrategy(element, propName);
49
+ this.#watchedProperties.set(propName, cleanup);
50
+
51
+ // If value changed during async wiring, dispatch immediately
52
+ const currentValue = (element as any)[propName];
53
+ if (currentValue !== initialValue) {
54
+ this.dispatchEvent(new Event(propName));
55
+ }
56
+ }
57
+
58
+ /**
59
+ * Determine and set up the best observation strategy for a property.
60
+ * Returns a cleanup function.
61
+ */
62
+ async #setupStrategy(element: Element, propName: string): Promise<() => void> {
63
+ // Strategy 1: Attribute-reflected properties
64
+ const attrName = this.#toAttributeName(propName);
65
+ if (this.#isAttributeReflected(element, propName, attrName)) {
66
+ return this.#observeAttribute(element, propName, attrName);
67
+ }
68
+
69
+ // Strategy 2: Native event (user-driven) + setter interception (programmatic)
70
+ const eventType = this.#getNativeEventType(element, propName);
71
+ if (eventType) {
72
+ return this.#observeHybrid(element, propName, eventType);
73
+ }
74
+
75
+ // Strategy 3: Setter interception (custom elements or known prototypes)
76
+ const descriptor = this.#getPropertyDescriptor(element, propName);
77
+ if (descriptor?.set) {
78
+ return this.#interceptSetter(element, propName, descriptor);
79
+ }
80
+
81
+ // Strategy 4: Polling fallback
82
+ return this.#observePolling(element, propName);
83
+ }
84
+
85
+ // ─── Strategy Implementations ────────────────────────────────────────
86
+
87
+ /**
88
+ * Strategy 1: Use MutationObserver on the corresponding attribute.
89
+ */
90
+ #observeAttribute(element: Element, propName: string, attrName: string): () => void {
91
+ const observer = new MutationObserver(() => {
92
+ this.dispatchEvent(new Event(propName));
93
+ });
94
+ observer.observe(element, {
95
+ attributes: true,
96
+ attributeFilter: [attrName],
97
+ });
98
+ return () => observer.disconnect();
99
+ }
100
+
101
+ /**
102
+ * Strategy 2: Listen for native events AND intercept setter for programmatic changes.
103
+ */
104
+ #observeHybrid(element: Element, propName: string, eventType: string): () => void {
105
+ const ac = new AbortController();
106
+ const {signal} = ac;
107
+
108
+ // Listen for user-driven events
109
+ element.addEventListener(eventType, () => {
110
+ this.dispatchEvent(new Event(propName));
111
+ }, {signal});
112
+
113
+ // Also intercept setter for programmatic changes
114
+ const descriptor = this.#getPropertyDescriptor(element, propName);
115
+ let restoreSetter: (() => void) | undefined;
116
+ if (descriptor?.set) {
117
+ restoreSetter = this.#interceptSetter(element, propName, descriptor);
118
+ }
119
+
120
+ return () => {
121
+ ac.abort();
122
+ restoreSetter?.();
123
+ };
124
+ }
125
+
126
+ /**
127
+ * Strategy 3: Override the property setter on the instance to detect programmatic writes.
128
+ */
129
+ #interceptSetter(element: Element, propName: string, descriptor: PropertyDescriptor): () => void {
130
+ const originalSet = descriptor.set!;
131
+ const originalGet = descriptor.get;
132
+ const self = this;
133
+
134
+ Object.defineProperty(element, propName, {
135
+ get: originalGet ? function(this: any) { return originalGet.call(this); } : undefined,
136
+ set(this: any, newValue: any) {
137
+ const oldValue = originalGet ? originalGet.call(this) : undefined;
138
+ originalSet.call(this, newValue);
139
+ if (newValue !== oldValue) {
140
+ self.dispatchEvent(new Event(propName));
141
+ }
142
+ },
143
+ configurable: true,
144
+ enumerable: descriptor.enumerable,
145
+ });
146
+
147
+ return () => {
148
+ // Restore by deleting instance property — prototype descriptor takes over again
149
+ delete (element as any)[propName];
150
+ };
151
+ }
152
+
153
+ /**
154
+ * Strategy 4: Polling via requestAnimationFrame.
155
+ */
156
+ #observePolling(element: Element, propName: string): () => void {
157
+ let active = true;
158
+ let lastValue = (element as any)[propName];
159
+
160
+ const poll = () => {
161
+ if (!active) return;
162
+ const currentValue = (element as any)[propName];
163
+ if (currentValue !== lastValue) {
164
+ lastValue = currentValue;
165
+ this.dispatchEvent(new Event(propName));
166
+ }
167
+ requestAnimationFrame(poll);
168
+ };
169
+ requestAnimationFrame(poll);
170
+
171
+ return () => { active = false; };
172
+ }
173
+
174
+ // ─── Helpers ─────────────────────────────────────────────────────────
175
+
176
+ /**
177
+ * Convert a camelCase property name to its kebab-case attribute equivalent.
178
+ * e.g. ariaValueNow -> aria-valuenow
179
+ */
180
+ #toAttributeName(propName: string): string {
181
+ // aria properties have a direct mapping
182
+ if (propName.startsWith('aria')) {
183
+ return propName.replace(/([A-Z])/g, '-$1').toLowerCase();
184
+ }
185
+ // General camelCase to kebab-case
186
+ return propName.replace(/([A-Z])/g, '-$1').toLowerCase();
187
+ }
188
+
189
+ /**
190
+ * Check if setting a property updates the corresponding attribute.
191
+ */
192
+ #isAttributeReflected(element: Element, propName: string, attrName: string): boolean {
193
+ // For form elements, 'value' attribute is only the default — property changes
194
+ // from user input do NOT update the attribute, so it's not truly reflected.
195
+ const {localName} = element;
196
+ if (propName === 'value' && ['input', 'textarea', 'select', 'button'].includes(localName)) {
197
+ return false;
198
+ }
199
+
200
+ // For <data>, <meter>, <output>, <progress> the value property reflects to the value attribute
201
+ if (propName === 'value' && ['data', 'meter', 'output', 'progress'].includes(localName)) {
202
+ return true;
203
+ }
204
+
205
+ // Quick check: does the attribute currently exist or is the property known to reflect?
206
+ if (element.hasAttribute(attrName)) return true;
207
+
208
+ // For aria-* properties, they are spec-defined as reflecting
209
+ if (propName.startsWith('aria')) return true;
210
+
211
+ // For href, src on appropriate elements
212
+ const reflectedProps: Record<string, string[]> = {
213
+ 'href': ['a', 'area', 'link', 'base'],
214
+ 'src': ['img', 'script', 'iframe', 'audio', 'video', 'source', 'embed'],
215
+ 'action': ['form'],
216
+ 'value': ['option', 'param', 'li'],
217
+ };
218
+ if (reflectedProps[propName]?.includes(localName)) return true;
219
+
220
+ return false;
221
+ }
222
+
223
+ /**
224
+ * Determine the native event type that fires when a property changes (user-driven).
225
+ * Leverages Infer's inferEventType for elements known to have input-like behavior.
226
+ */
227
+ #getNativeEventType(element: Element, propName: string): string | undefined {
228
+ const {localName} = element;
229
+ // Only applicable for form-like elements with value/checked properties
230
+ if (['input', 'textarea', 'select'].includes(localName)) {
231
+ if (propName === 'value' || propName === 'valueAsNumber' || propName === 'valueAsDate' || propName === 'checked' || propName === 'selectedIndex') {
232
+ return inferEventType(element);
233
+ }
234
+ }
235
+ if (localName === 'details' && propName === 'open') {
236
+ return 'toggle';
237
+ }
238
+ // contentEditable elements fire 'input' events on user edits
239
+ if (element instanceof HTMLElement && element.isContentEditable) {
240
+ if (propName === 'textContent' || propName === 'innerHTML' || propName === 'innerText') {
241
+ return 'input';
242
+ }
243
+ }
244
+ return undefined;
245
+ }
246
+
247
+ /**
248
+ * Walk the prototype chain to find a property descriptor.
249
+ */
250
+ #getPropertyDescriptor(element: Element, propName: string): PropertyDescriptor | undefined {
251
+ let proto: any = Object.getPrototypeOf(element);
252
+ while (proto && proto !== Object.prototype) {
253
+ const desc = Object.getOwnPropertyDescriptor(proto, propName);
254
+ if (desc) return desc;
255
+ proto = Object.getPrototypeOf(proto);
256
+ }
257
+ return undefined;
258
+ }
259
+
260
+ /**
261
+ * Tear down all watchers and clean up resources.
262
+ */
263
+ destroy(): void {
264
+ for (const cleanup of this.#watchedProperties.values()) {
265
+ cleanup();
266
+ }
267
+ this.#watchedProperties.clear();
268
+ }
269
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bruce B. Anderson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.