@absmartly/sdk-plugins 1.0.1 → 1.1.1
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/absmartly-cookie.min.js +1 -1
- package/dist/absmartly-dom-changes-core.min.js +1 -1
- package/dist/absmartly-dom-changes-lite.min.js +1 -1
- package/dist/absmartly-overrides-full.min.js +1 -1
- package/dist/absmartly-sdk-plugins.min.js +1 -1
- package/dist/absmartly-vitals.min.js +1 -1
- package/es/cookies/CookiePlugin.js +31 -61
- package/es/cookies/CookiePlugin.js.map +1 -1
- package/es/cookies/cookieUtils.js +82 -0
- package/es/cookies/cookieUtils.js.map +1 -0
- package/es/cookies/index.js +1 -0
- package/es/cookies/index.js.map +1 -1
- package/es/core/DOMChangesPluginLite.js +199 -103
- package/es/core/DOMChangesPluginLite.js.map +1 -1
- package/es/core/DOMManipulatorLite.js +64 -9
- package/es/core/DOMManipulatorLite.js.map +1 -1
- package/es/core/ExposureTracker.js +6 -15
- package/es/core/ExposureTracker.js.map +1 -1
- package/es/entries/dom-with-overrides-lite.js +6 -1
- package/es/entries/dom-with-overrides-lite.js.map +1 -1
- package/es/index.js +4 -0
- package/es/index.js.map +1 -1
- package/es/overrides/index.js +1 -0
- package/es/overrides/index.js.map +1 -1
- package/es/overrides/overridesUtils.js +255 -0
- package/es/overrides/overridesUtils.js.map +1 -0
- package/es/utils/debug.js +2 -1
- package/es/utils/debug.js.map +1 -1
- package/es/vitals/WebVitalsPlugin.js +65 -54
- package/es/vitals/WebVitalsPlugin.js.map +1 -1
- package/lib/cookies/CookiePlugin.d.ts +0 -3
- package/lib/cookies/CookiePlugin.js +31 -61
- package/lib/cookies/CookiePlugin.js.map +1 -1
- package/lib/cookies/cookieUtils.d.ts +34 -0
- package/lib/cookies/cookieUtils.js +90 -0
- package/lib/cookies/cookieUtils.js.map +1 -0
- package/lib/cookies/index.d.ts +2 -0
- package/lib/cookies/index.js +8 -1
- package/lib/cookies/index.js.map +1 -1
- package/lib/core/DOMChangesPluginLite.d.ts +1 -1
- package/lib/core/DOMChangesPluginLite.js +199 -103
- package/lib/core/DOMChangesPluginLite.js.map +1 -1
- package/lib/core/DOMManipulatorLite.js +64 -9
- package/lib/core/DOMManipulatorLite.js.map +1 -1
- package/lib/core/ExposureTracker.d.ts +4 -1
- package/lib/core/ExposureTracker.js +6 -15
- package/lib/core/ExposureTracker.js.map +1 -1
- package/lib/entries/dom-with-overrides-lite.d.ts +7 -1
- package/lib/entries/dom-with-overrides-lite.js +19 -1
- package/lib/entries/dom-with-overrides-lite.js.map +1 -1
- package/lib/index.d.ts +4 -0
- package/lib/index.js +17 -1
- package/lib/index.js.map +1 -1
- package/lib/overrides/index.d.ts +2 -0
- package/lib/overrides/index.js +8 -1
- package/lib/overrides/index.js.map +1 -1
- package/lib/overrides/overridesUtils.d.ts +48 -0
- package/lib/overrides/overridesUtils.js +263 -0
- package/lib/overrides/overridesUtils.js.map +1 -0
- package/lib/utils/debug.js +2 -1
- package/lib/utils/debug.js.map +1 -1
- package/lib/vitals/WebVitalsPlugin.d.ts +1 -2
- package/lib/vitals/WebVitalsPlugin.js +98 -54
- package/lib/vitals/WebVitalsPlugin.js.map +1 -1
- package/package.json +4 -1
- package/types/cookies/CookiePlugin.d.ts +0 -3
- package/types/cookies/cookieUtils.d.ts +34 -0
- package/types/cookies/index.d.ts +2 -0
- package/types/core/DOMChangesPluginLite.d.ts +1 -1
- package/types/core/ExposureTracker.d.ts +4 -1
- package/types/entries/dom-with-overrides-lite.d.ts +7 -1
- package/types/index.d.ts +4 -0
- package/types/overrides/index.d.ts +2 -0
- package/types/overrides/overridesUtils.d.ts +48 -0
- package/types/vitals/WebVitalsPlugin.d.ts +1 -2
|
@@ -94,7 +94,7 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
94
94
|
this.persistenceObserver = null;
|
|
95
95
|
this.reapplyingElements = new Set();
|
|
96
96
|
this.reapplyLogThrottle = new Map();
|
|
97
|
-
this.
|
|
97
|
+
this.appliedChanges = new Map();
|
|
98
98
|
this.antiFlickerTimeout = null;
|
|
99
99
|
this.antiFlickerStyleId = 'absmartly-antiflicker';
|
|
100
100
|
this.config = {
|
|
@@ -186,10 +186,45 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
186
186
|
});
|
|
187
187
|
};
|
|
188
188
|
DOMChangesPluginLite.prototype.setupMutationObserver = function () {
|
|
189
|
-
var
|
|
190
|
-
|
|
191
|
-
//
|
|
192
|
-
|
|
189
|
+
var _this = this;
|
|
190
|
+
var observer = new MutationObserver(function (mutations) {
|
|
191
|
+
// Re-apply ALL changes to elements that were replaced by React (hydration mismatch)
|
|
192
|
+
mutations.forEach(function (mutation) {
|
|
193
|
+
if (mutation.type === 'childList') {
|
|
194
|
+
// Check if any added nodes match our applied change selectors
|
|
195
|
+
mutation.addedNodes.forEach(function (node) {
|
|
196
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
197
|
+
var element_1 = node;
|
|
198
|
+
// Check all experiments with applied changes (not just style changes)
|
|
199
|
+
_this.appliedChanges.forEach(function (changes, experimentName) {
|
|
200
|
+
changes.forEach(function (change) {
|
|
201
|
+
try {
|
|
202
|
+
// Check if this new element or any of its descendants match the selector
|
|
203
|
+
var matchingElements = element_1.matches(change.selector)
|
|
204
|
+
? [element_1]
|
|
205
|
+
: Array.from(element_1.querySelectorAll(change.selector));
|
|
206
|
+
matchingElements.forEach(function (matchingEl) {
|
|
207
|
+
if (_this.config.debug) {
|
|
208
|
+
(0, debug_1.logDebug)('[SPA-REAPPLY] Re-applying change to newly added element (React hydration recovery)', {
|
|
209
|
+
experimentName: experimentName,
|
|
210
|
+
selector: change.selector,
|
|
211
|
+
element: matchingEl.tagName,
|
|
212
|
+
changeType: change.type,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
// Re-apply the change to the new element (ALL types: style, class, attribute, html, text, etc.)
|
|
216
|
+
_this.domManipulator.applyChange(change, experimentName);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
catch (e) {
|
|
220
|
+
// Invalid selector, skip
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
});
|
|
193
228
|
});
|
|
194
229
|
observer.observe(document.body, {
|
|
195
230
|
childList: true,
|
|
@@ -261,8 +296,8 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
261
296
|
// Clear style managers - StyleSheetManager doesn't have a remove method
|
|
262
297
|
// The stylesheets will be reused or cleared on next applyChanges
|
|
263
298
|
this.styleManagers.clear();
|
|
264
|
-
// Clear applied
|
|
265
|
-
this.
|
|
299
|
+
// Clear applied changes
|
|
300
|
+
this.appliedChanges.clear();
|
|
266
301
|
// Clear HTML injections
|
|
267
302
|
this.htmlInjector.destroy();
|
|
268
303
|
// Clear variant extractor cache to force re-extraction
|
|
@@ -345,8 +380,8 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
345
380
|
};
|
|
346
381
|
DOMChangesPluginLite.prototype.applyChanges = function (experimentName) {
|
|
347
382
|
return __awaiter(this, void 0, void 0, function () {
|
|
348
|
-
var startTime, currentURL, error_3, allExperiments, totalApplied, experimentStats, allExperiments_1, allExperiments_1_1, _a, expName, experimentData, currentVariant, variantData, urlFilter, globalDefaults, anyVariantMatchesURL, shouldApplyVisualChanges, changes, allVariantChanges, hasAnyChangesInAnyVariant, stats,
|
|
349
|
-
var e_1,
|
|
383
|
+
var startTime, currentURL, error_3, allExperiments, totalApplied, experimentStats, allExperiments_1, allExperiments_1_1, _a, expName, experimentData, currentVariant, variantData, urlFilter, globalDefaults, anyVariantMatchesURL, shouldApplyVisualChanges, changes, allVariantChanges, hasAnyChangesInAnyVariant, stats, changes_1, changes_1_1, change, success, elements, hasAnyViewportTriggerInAnyVariant, hasAnyImmediateTriggerInAnyVariant, allVariantsData, allVariantsData_1, allVariantsData_1_1, _b, variantIndex, variantData_1, variantChanges, variantMatchesURL, config, urlFilterConfig, variantChanges_1, variantChanges_1_1, change, duration;
|
|
384
|
+
var e_1, _c, e_2, _d, e_3, _e, e_4, _f;
|
|
350
385
|
return __generator(this, function (_g) {
|
|
351
386
|
switch (_g.label) {
|
|
352
387
|
case 0:
|
|
@@ -419,8 +454,6 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
419
454
|
}); })) || [],
|
|
420
455
|
});
|
|
421
456
|
}
|
|
422
|
-
hasImmediateTrigger = false;
|
|
423
|
-
hasViewportTrigger = false;
|
|
424
457
|
// Apply visual changes only if URL matches for user's variant AND user has changes
|
|
425
458
|
if (shouldApplyVisualChanges && changes && changes.length > 0) {
|
|
426
459
|
try {
|
|
@@ -430,12 +463,6 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
430
463
|
if (success) {
|
|
431
464
|
totalApplied++;
|
|
432
465
|
stats.success++;
|
|
433
|
-
if (change.trigger_on_view) {
|
|
434
|
-
hasViewportTrigger = true;
|
|
435
|
-
}
|
|
436
|
-
else {
|
|
437
|
-
hasImmediateTrigger = true;
|
|
438
|
-
}
|
|
439
466
|
}
|
|
440
467
|
else if (change.type !== 'create' && change.type !== 'styleRules') {
|
|
441
468
|
// Track pending changes for stats
|
|
@@ -443,9 +470,6 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
443
470
|
elements = document.querySelectorAll(change.selector);
|
|
444
471
|
if (elements.length === 0 && (this.config.spa || change.waitForElement)) {
|
|
445
472
|
stats.pending++;
|
|
446
|
-
if (change.trigger_on_view) {
|
|
447
|
-
hasViewportTrigger = true;
|
|
448
|
-
}
|
|
449
473
|
}
|
|
450
474
|
}
|
|
451
475
|
catch (error) {
|
|
@@ -459,82 +483,106 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
459
483
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
460
484
|
finally {
|
|
461
485
|
try {
|
|
462
|
-
if (changes_1_1 && !changes_1_1.done && (
|
|
486
|
+
if (changes_1_1 && !changes_1_1.done && (_d = changes_1.return)) _d.call(changes_1);
|
|
463
487
|
}
|
|
464
488
|
finally { if (e_2) throw e_2.error; }
|
|
465
489
|
}
|
|
466
490
|
}
|
|
467
491
|
else if (changes && changes.length > 0) {
|
|
468
|
-
try {
|
|
469
|
-
// URL doesn't match for user's variant OR user has no changes
|
|
470
|
-
// Check if user's changes have viewport trigger (if they exist)
|
|
471
|
-
// We still need to set up tracking for SRM prevention
|
|
472
|
-
for (changes_2 = (e_3 = void 0, __values(changes)), changes_2_1 = changes_2.next(); !changes_2_1.done; changes_2_1 = changes_2.next()) {
|
|
473
|
-
change = changes_2_1.value;
|
|
474
|
-
if (change.trigger_on_view) {
|
|
475
|
-
hasViewportTrigger = true;
|
|
476
|
-
}
|
|
477
|
-
else {
|
|
478
|
-
hasImmediateTrigger = true;
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
483
|
-
finally {
|
|
484
|
-
try {
|
|
485
|
-
if (changes_2_1 && !changes_2_1.done && (_d = changes_2.return)) _d.call(changes_2);
|
|
486
|
-
}
|
|
487
|
-
finally { if (e_3) throw e_3.error; }
|
|
488
|
-
}
|
|
489
492
|
(0, debug_1.logDebug)("[ABsmartly] Experiment '".concat(expName, "' variant ").concat(currentVariant, " doesn't match URL filter or has no changes, but setting up tracking for SRM prevention"));
|
|
490
493
|
}
|
|
491
|
-
hasAnyViewportTriggerInAnyVariant =
|
|
492
|
-
hasAnyImmediateTriggerInAnyVariant =
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
494
|
+
hasAnyViewportTriggerInAnyVariant = false;
|
|
495
|
+
hasAnyImmediateTriggerInAnyVariant = false;
|
|
496
|
+
allVariantsData = this.variantExtractor.getAllVariantsData(expName);
|
|
497
|
+
if (this.config.debug) {
|
|
498
|
+
(0, debug_1.logDebug)("[ABsmartly] Checking trigger types for experiment '".concat(expName, "' on URL: ").concat(currentURL), {
|
|
499
|
+
allVariantsDataSize: allVariantsData.size,
|
|
500
|
+
allVariantChangesLength: allVariantChanges.length,
|
|
501
|
+
});
|
|
502
|
+
// Log the structure of each variant's data
|
|
503
|
+
allVariantsData.forEach(function (data, idx) {
|
|
504
|
+
(0, debug_1.logDebug)("[ABsmartly] Variant ".concat(idx, " data structure:"), {
|
|
505
|
+
isArray: Array.isArray(data),
|
|
506
|
+
isObject: typeof data === 'object',
|
|
507
|
+
hasUrlFilter: data && typeof data === 'object' && !Array.isArray(data) && 'urlFilter' in data,
|
|
508
|
+
keys: data && typeof data === 'object' && !Array.isArray(data) ? Object.keys(data) : 'N/A',
|
|
509
|
+
});
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
try {
|
|
513
|
+
// Loop through ALL variants (not just ones with changes)
|
|
514
|
+
// We need to check URL filters from the raw data, which includes variants without changes
|
|
515
|
+
for (allVariantsData_1 = (e_3 = void 0, __values(allVariantsData)), allVariantsData_1_1 = allVariantsData_1.next(); !allVariantsData_1_1.done; allVariantsData_1_1 = allVariantsData_1.next()) {
|
|
516
|
+
_b = __read(allVariantsData_1_1.value, 2), variantIndex = _b[0], variantData_1 = _b[1];
|
|
517
|
+
variantChanges = allVariantChanges[variantIndex];
|
|
518
|
+
if (!variantChanges || variantChanges.length === 0) {
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
521
|
+
variantMatchesURL = true;
|
|
522
|
+
if (variantData_1 && typeof variantData_1 === 'object' && !Array.isArray(variantData_1)) {
|
|
523
|
+
config = variantData_1;
|
|
524
|
+
if ('urlFilter' in config && config.urlFilter) {
|
|
525
|
+
urlFilterConfig = config;
|
|
526
|
+
variantMatchesURL = URLMatcher_1.URLMatcher.matches(urlFilterConfig.urlFilter, currentURL);
|
|
527
|
+
if (this.config.debug) {
|
|
528
|
+
(0, debug_1.logDebug)("[ABsmartly] Variant ".concat(variantIndex, " has URL filter, matches: ").concat(variantMatchesURL));
|
|
512
529
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
530
|
+
}
|
|
531
|
+
// If no urlFilter property, variantMatchesURL stays true (legacy behavior)
|
|
532
|
+
}
|
|
533
|
+
// Only collect trigger types from variants whose URL filters match
|
|
534
|
+
if (variantMatchesURL) {
|
|
535
|
+
try {
|
|
536
|
+
for (variantChanges_1 = (e_4 = void 0, __values(variantChanges)), variantChanges_1_1 = variantChanges_1.next(); !variantChanges_1_1.done; variantChanges_1_1 = variantChanges_1.next()) {
|
|
537
|
+
change = variantChanges_1_1.value;
|
|
538
|
+
if (change.trigger_on_view) {
|
|
539
|
+
hasAnyViewportTriggerInAnyVariant = true;
|
|
540
|
+
}
|
|
541
|
+
else {
|
|
542
|
+
hasAnyImmediateTriggerInAnyVariant = true;
|
|
543
|
+
}
|
|
544
|
+
// Early exit if we found both types
|
|
545
|
+
if (hasAnyViewportTriggerInAnyVariant && hasAnyImmediateTriggerInAnyVariant) {
|
|
546
|
+
break;
|
|
517
547
|
}
|
|
518
|
-
finally { if (e_5) throw e_5.error; }
|
|
519
548
|
}
|
|
520
549
|
}
|
|
521
|
-
|
|
522
|
-
|
|
550
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
551
|
+
finally {
|
|
552
|
+
try {
|
|
553
|
+
if (variantChanges_1_1 && !variantChanges_1_1.done && (_f = variantChanges_1.return)) _f.call(variantChanges_1);
|
|
554
|
+
}
|
|
555
|
+
finally { if (e_4) throw e_4.error; }
|
|
556
|
+
}
|
|
557
|
+
if (this.config.debug) {
|
|
558
|
+
(0, debug_1.logDebug)("[ABsmartly] Variant ".concat(variantIndex, " matches URL - hasImmediate: ").concat(hasAnyImmediateTriggerInAnyVariant, ", hasViewport: ").concat(hasAnyViewportTriggerInAnyVariant));
|
|
523
559
|
}
|
|
524
560
|
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
561
|
+
else {
|
|
562
|
+
if (this.config.debug) {
|
|
563
|
+
(0, debug_1.logDebug)("[ABsmartly] Variant ".concat(variantIndex, " does NOT match URL - skipping"));
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
if (hasAnyViewportTriggerInAnyVariant && hasAnyImmediateTriggerInAnyVariant) {
|
|
567
|
+
break;
|
|
530
568
|
}
|
|
531
|
-
finally { if (e_4) throw e_4.error; }
|
|
532
569
|
}
|
|
533
570
|
}
|
|
571
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
572
|
+
finally {
|
|
573
|
+
try {
|
|
574
|
+
if (allVariantsData_1_1 && !allVariantsData_1_1.done && (_e = allVariantsData_1.return)) _e.call(allVariantsData_1);
|
|
575
|
+
}
|
|
576
|
+
finally { if (e_3) throw e_3.error; }
|
|
577
|
+
}
|
|
578
|
+
if (this.config.debug) {
|
|
579
|
+
(0, debug_1.logDebug)("[ABsmartly] Final trigger decision for '".concat(expName, "': hasImmediate=").concat(hasAnyImmediateTriggerInAnyVariant, ", hasViewport=").concat(hasAnyViewportTriggerInAnyVariant));
|
|
580
|
+
}
|
|
534
581
|
// CRITICAL: Always register experiment for tracking if ANY variant has ANY trigger type
|
|
535
582
|
// This prevents SRM even when user's variant doesn't match URL filter
|
|
583
|
+
// Pass the URL-filtered trigger flags to ExposureTracker
|
|
536
584
|
if (hasAnyViewportTriggerInAnyVariant || hasAnyImmediateTriggerInAnyVariant) {
|
|
537
|
-
this.exposureTracker.registerExperiment(expName, currentVariant || 0, changes || [], allVariantChanges);
|
|
585
|
+
this.exposureTracker.registerExperiment(expName, currentVariant || 0, changes || [], allVariantChanges, hasAnyImmediateTriggerInAnyVariant, hasAnyViewportTriggerInAnyVariant);
|
|
538
586
|
}
|
|
539
587
|
// Note: We do NOT call treatment() here anymore to avoid duplicate calls.
|
|
540
588
|
// The ExposureTracker.registerExperiment() will call triggerExposure() internally
|
|
@@ -547,7 +595,7 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
547
595
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
548
596
|
finally {
|
|
549
597
|
try {
|
|
550
|
-
if (allExperiments_1_1 && !allExperiments_1_1.done && (
|
|
598
|
+
if (allExperiments_1_1 && !allExperiments_1_1.done && (_c = allExperiments_1.return)) _c.call(allExperiments_1);
|
|
551
599
|
}
|
|
552
600
|
finally { if (e_1) throw e_1.error; }
|
|
553
601
|
}
|
|
@@ -588,7 +636,7 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
588
636
|
* Get all experiments with their variant data and metadata
|
|
589
637
|
*/
|
|
590
638
|
DOMChangesPluginLite.prototype.getAllExperimentsData = function () {
|
|
591
|
-
var
|
|
639
|
+
var e_5, _a;
|
|
592
640
|
var experiments = new Map();
|
|
593
641
|
var allVariants = this.variantExtractor.extractAllChanges();
|
|
594
642
|
try {
|
|
@@ -622,12 +670,12 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
622
670
|
experiments.set(expName, { variantData: variantData, urlFilter: urlFilter, globalDefaults: globalDefaults });
|
|
623
671
|
}
|
|
624
672
|
}
|
|
625
|
-
catch (
|
|
673
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
626
674
|
finally {
|
|
627
675
|
try {
|
|
628
676
|
if (allVariants_1_1 && !allVariants_1_1.done && (_a = allVariants_1.return)) _a.call(allVariants_1);
|
|
629
677
|
}
|
|
630
|
-
finally { if (
|
|
678
|
+
finally { if (e_5) throw e_5.error; }
|
|
631
679
|
}
|
|
632
680
|
return experiments;
|
|
633
681
|
};
|
|
@@ -752,7 +800,7 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
752
800
|
}
|
|
753
801
|
};
|
|
754
802
|
DOMChangesPluginLite.prototype.emit = function (event, data) {
|
|
755
|
-
var
|
|
803
|
+
var e_6, _a;
|
|
756
804
|
var listeners = this.eventListeners.get(event) || [];
|
|
757
805
|
try {
|
|
758
806
|
for (var listeners_1 = __values(listeners), listeners_1_1 = listeners_1.next(); !listeners_1_1.done; listeners_1_1 = listeners_1.next()) {
|
|
@@ -765,12 +813,12 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
765
813
|
}
|
|
766
814
|
}
|
|
767
815
|
}
|
|
768
|
-
catch (
|
|
816
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
769
817
|
finally {
|
|
770
818
|
try {
|
|
771
819
|
if (listeners_1_1 && !listeners_1_1.done && (_a = listeners_1.return)) _a.call(listeners_1);
|
|
772
820
|
}
|
|
773
|
-
finally { if (
|
|
821
|
+
finally { if (e_6) throw e_6.error; }
|
|
774
822
|
}
|
|
775
823
|
};
|
|
776
824
|
DOMChangesPluginLite.prototype.getStyleManager = function (experimentName) {
|
|
@@ -846,7 +894,7 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
846
894
|
this.eventListeners.clear();
|
|
847
895
|
this.exposedExperiments.clear();
|
|
848
896
|
this.watchedElements = new WeakMap();
|
|
849
|
-
this.
|
|
897
|
+
this.appliedChanges.clear();
|
|
850
898
|
this.reapplyingElements.clear();
|
|
851
899
|
this.reapplyLogThrottle.clear();
|
|
852
900
|
this.unregisterFromContext();
|
|
@@ -975,20 +1023,31 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
975
1023
|
this.watchedElements.set(element, experiments);
|
|
976
1024
|
}
|
|
977
1025
|
experiments.add(experimentName);
|
|
978
|
-
// Store the applied
|
|
979
|
-
if (!this.
|
|
980
|
-
this.
|
|
1026
|
+
// Store the applied change for this experiment (ALL types: style, class, attribute, html, text, etc.)
|
|
1027
|
+
if (!this.appliedChanges.has(experimentName)) {
|
|
1028
|
+
this.appliedChanges.set(experimentName, []);
|
|
981
1029
|
}
|
|
982
|
-
var changes = this.
|
|
1030
|
+
var changes = this.appliedChanges.get(experimentName);
|
|
983
1031
|
var isNewWatch = !changes.includes(change);
|
|
984
1032
|
if (isNewWatch) {
|
|
985
1033
|
changes.push(change);
|
|
986
1034
|
// Only log when actually adding a new watch, not on every reapply
|
|
987
1035
|
if (this.config.debug) {
|
|
988
|
-
|
|
1036
|
+
var currentStyles_1 = {};
|
|
1037
|
+
if (change.value && typeof change.value === 'object') {
|
|
1038
|
+
Object.keys(change.value).forEach(function (prop) {
|
|
1039
|
+
var cssProp = prop.replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
1040
|
+
currentStyles_1[cssProp] = element.style.getPropertyValue(cssProp);
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1043
|
+
(0, debug_1.logDebug)('[WATCH-ELEMENT] Started watching element for persistence/hydration recovery', {
|
|
989
1044
|
experimentName: experimentName,
|
|
990
1045
|
selector: change.selector,
|
|
991
1046
|
element: element.tagName,
|
|
1047
|
+
changeType: change.type,
|
|
1048
|
+
value: change.value,
|
|
1049
|
+
currentStyles: change.type === 'style' ? currentStyles_1 : undefined,
|
|
1050
|
+
timestamp: Date.now(),
|
|
992
1051
|
});
|
|
993
1052
|
}
|
|
994
1053
|
}
|
|
@@ -1009,10 +1068,34 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
1009
1068
|
var _this = this;
|
|
1010
1069
|
if (this.persistenceObserver)
|
|
1011
1070
|
return;
|
|
1071
|
+
if (this.config.debug) {
|
|
1072
|
+
(0, debug_1.logDebug)('[PERSISTENCE-OBSERVER] Setting up persistence observer', {
|
|
1073
|
+
timestamp: Date.now(),
|
|
1074
|
+
watchedElementsCount: this.watchedElements ? 'has WeakMap' : 'no WeakMap',
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1012
1077
|
this.persistenceObserver = new MutationObserver(function (mutations) {
|
|
1078
|
+
if (_this.config.debug) {
|
|
1079
|
+
(0, debug_1.logDebug)('[MUTATION-DETECTED] Persistence observer detected mutations', {
|
|
1080
|
+
mutationCount: mutations.length,
|
|
1081
|
+
timestamp: Date.now(),
|
|
1082
|
+
mutations: mutations.map(function (m) {
|
|
1083
|
+
var _a;
|
|
1084
|
+
return ({
|
|
1085
|
+
target: m.target.tagName,
|
|
1086
|
+
oldValue: (_a = m.oldValue) === null || _a === void 0 ? void 0 : _a.substring(0, 100),
|
|
1087
|
+
});
|
|
1088
|
+
}),
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1013
1091
|
mutations.forEach(function (mutation) {
|
|
1014
1092
|
var element = mutation.target;
|
|
1015
1093
|
if (_this.reapplyingElements.has(element)) {
|
|
1094
|
+
if (_this.config.debug) {
|
|
1095
|
+
(0, debug_1.logDebug)('[MUTATION-SKIP] Skipping mutation - currently reapplying', {
|
|
1096
|
+
element: element.tagName,
|
|
1097
|
+
});
|
|
1098
|
+
}
|
|
1016
1099
|
return;
|
|
1017
1100
|
}
|
|
1018
1101
|
var experiments = _this.watchedElements.get(element);
|
|
@@ -1023,31 +1106,37 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
1023
1106
|
var now = Date.now();
|
|
1024
1107
|
var lastLogged = _this.reapplyLogThrottle.get(elementKey) || 0;
|
|
1025
1108
|
if (now - lastLogged > 5000) {
|
|
1026
|
-
(0, debug_1.logDebug)('[
|
|
1109
|
+
(0, debug_1.logDebug)('[MUTATION-ON-WATCHED] Style mutation detected on watched element', {
|
|
1027
1110
|
element: element.tagName,
|
|
1028
1111
|
selector: element.getAttribute('name') || element.className,
|
|
1029
1112
|
oldValue: mutation.oldValue,
|
|
1113
|
+
newValue: element.getAttribute('style'),
|
|
1114
|
+
experiments: Array.from(experiments),
|
|
1030
1115
|
});
|
|
1031
1116
|
_this.reapplyLogThrottle.set(elementKey, now);
|
|
1032
1117
|
}
|
|
1033
1118
|
}
|
|
1034
1119
|
experiments.forEach(function (experimentName) {
|
|
1035
|
-
var appliedChanges = _this.
|
|
1120
|
+
var appliedChanges = _this.appliedChanges.get(experimentName);
|
|
1036
1121
|
if (appliedChanges) {
|
|
1037
1122
|
appliedChanges.forEach(function (change) {
|
|
1038
|
-
var
|
|
1039
|
-
|
|
1123
|
+
var e_7, _a;
|
|
1124
|
+
// Skip the .matches() check - we already know this element should have this change
|
|
1125
|
+
// because we added it to watchedElements when we applied it successfully.
|
|
1126
|
+
// The .matches() check fails for complex selectors with parent relationships (e.g., "div > p")
|
|
1127
|
+
if (change.type === 'style') {
|
|
1040
1128
|
var needsReapply = _this.checkStyleOverwritten(element, change.value);
|
|
1041
1129
|
if (needsReapply) {
|
|
1042
1130
|
_this.reapplyingElements.add(element);
|
|
1043
|
-
_this.domManipulator.applyChange(change, experimentName);
|
|
1044
1131
|
var logKey = "".concat(experimentName, "-").concat(change.selector);
|
|
1045
1132
|
var now = Date.now();
|
|
1046
1133
|
var lastLogged = _this.reapplyLogThrottle.get(logKey) || 0;
|
|
1047
1134
|
if (_this.config.debug && now - lastLogged > 5000) {
|
|
1048
|
-
(0, debug_1.logDebug)('
|
|
1135
|
+
(0, debug_1.logDebug)('[REAPPLY-TRIGGERED] Reapplying style after mutation (React/framework conflict detected)', {
|
|
1049
1136
|
experimentName: experimentName,
|
|
1050
1137
|
selector: change.selector,
|
|
1138
|
+
element: element.tagName,
|
|
1139
|
+
timestamp: now,
|
|
1051
1140
|
note: 'This happens when the page framework (React/Vue/etc) fights with DOM changes',
|
|
1052
1141
|
});
|
|
1053
1142
|
_this.reapplyLogThrottle.set(logKey, now);
|
|
@@ -1062,21 +1151,22 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
1062
1151
|
}
|
|
1063
1152
|
}
|
|
1064
1153
|
}
|
|
1065
|
-
catch (
|
|
1154
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
1066
1155
|
finally {
|
|
1067
1156
|
try {
|
|
1068
1157
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1069
1158
|
}
|
|
1070
|
-
finally { if (
|
|
1159
|
+
finally { if (e_7) throw e_7.error; }
|
|
1071
1160
|
}
|
|
1072
1161
|
}
|
|
1073
1162
|
}
|
|
1163
|
+
_this.domManipulator.applyChange(change, experimentName);
|
|
1074
1164
|
setTimeout(function () {
|
|
1075
1165
|
_this.reapplyingElements.delete(element);
|
|
1076
1166
|
}, 0);
|
|
1077
1167
|
}
|
|
1078
1168
|
else if (_this.config.debug) {
|
|
1079
|
-
(0, debug_1.logDebug)('[
|
|
1169
|
+
(0, debug_1.logDebug)('[MUTATION-NO-REAPPLY] Style mutation detected but no reapply needed', {
|
|
1080
1170
|
experimentName: experimentName,
|
|
1081
1171
|
selector: change.selector,
|
|
1082
1172
|
});
|
|
@@ -1095,11 +1185,17 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
1095
1185
|
attributeOldValue: true,
|
|
1096
1186
|
});
|
|
1097
1187
|
if (this.config.debug) {
|
|
1098
|
-
(0, debug_1.logDebug)('[
|
|
1188
|
+
(0, debug_1.logDebug)('[PERSISTENCE-OBSERVER] Setup complete - now observing style mutations', {
|
|
1189
|
+
target: 'document.body',
|
|
1190
|
+
attributeFilter: ['style'],
|
|
1191
|
+
subtree: true,
|
|
1192
|
+
attributeOldValue: true,
|
|
1193
|
+
timestamp: Date.now(),
|
|
1194
|
+
});
|
|
1099
1195
|
}
|
|
1100
1196
|
};
|
|
1101
1197
|
DOMChangesPluginLite.prototype.checkStyleOverwritten = function (element, expectedStyles) {
|
|
1102
|
-
var
|
|
1198
|
+
var e_8, _a;
|
|
1103
1199
|
try {
|
|
1104
1200
|
for (var _b = __values(Object.entries(expectedStyles)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1105
1201
|
var _d = __read(_c.value, 2), prop = _d[0], value = _d[1];
|
|
@@ -1111,12 +1207,12 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
1111
1207
|
}
|
|
1112
1208
|
}
|
|
1113
1209
|
}
|
|
1114
|
-
catch (
|
|
1210
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
1115
1211
|
finally {
|
|
1116
1212
|
try {
|
|
1117
1213
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1118
1214
|
}
|
|
1119
|
-
finally { if (
|
|
1215
|
+
finally { if (e_8) throw e_8.error; }
|
|
1120
1216
|
}
|
|
1121
1217
|
return false;
|
|
1122
1218
|
};
|