@linxin666/dsh-client-ui-skin-center 0.3.16 → 0.3.17

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/lib/client.js CHANGED
@@ -3365,6 +3365,48 @@ window.__ModuleLoader__.load({
3365
3365
  const extracted = extractSkinBackgroundUserLayer(user);
3366
3366
  return extracted === null ? "" : JSON.stringify(extracted);
3367
3367
  }
3368
+ /** Seed the reconcile state from the scope snapshot visible at construction. */
3369
+ function initialSkinBackgroundReconcileState(snapshot) {
3370
+ return {
3371
+ v2Loaded: false,
3372
+ bootSyncSeen: false,
3373
+ lastRevision: snapshot.revision,
3374
+ lastUserJson: serializeSkinBackgroundUserLayer(snapshot.user)
3375
+ };
3376
+ }
3377
+ /**
3378
+ * Fold one scope publication into the reconcile state and produce the v2-safe
3379
+ * patch to merge into the live background values (null = nothing to apply).
3380
+ *
3381
+ * The boot document never merges, whichever order it lands in:
3382
+ * - a publication seen before the v2 GET completes is only recorded, so the
3383
+ * post-load check reads it as the unchanged boot snapshot, not an edit;
3384
+ * - the first revisioned publication of the plugin's lifetime (the document
3385
+ * resync itself) is consumed as the boot sync even when it lands after the
3386
+ * GET, because a genuine settings-page edit can only follow the document.
3387
+ */
3388
+ function reconcileSkinBackgroundPublication(state, current, snapshot) {
3389
+ const seen = {
3390
+ ...state,
3391
+ lastRevision: snapshot.revision ?? state.lastRevision,
3392
+ lastUserJson: serializeSkinBackgroundUserLayer(snapshot.user)
3393
+ };
3394
+ if (!state.v2Loaded) return {
3395
+ state: seen,
3396
+ patch: null
3397
+ };
3398
+ if (!state.bootSyncSeen) return {
3399
+ state: snapshot.revision === void 0 ? seen : {
3400
+ ...seen,
3401
+ bootSyncSeen: true
3402
+ },
3403
+ patch: null
3404
+ };
3405
+ return {
3406
+ state: seen,
3407
+ patch: reconcileSkinBackgroundScope(current, snapshot, state.lastRevision, state.lastUserJson).patch
3408
+ };
3409
+ }
3368
3410
  /**
3369
3411
  * Accept a scope publication only when its namespace revision is new AND the
3370
3412
  * user layer has actually changed. A revision bump with identical user-layer
@@ -4969,7 +5011,7 @@ window.__ModuleLoader__.load({
4969
5011
  /** The building package's version, when the bundle carries it. */
4970
5012
  function bakedVersion() {
4971
5013
  try {
4972
- return "0.3.16";
5014
+ return "0.3.17";
4973
5015
  } catch {
4974
5016
  return;
4975
5017
  }
@@ -5121,33 +5163,31 @@ window.__ModuleLoader__.load({
5121
5163
  if (value === void 0 || value === null) return null;
5122
5164
  return value;
5123
5165
  };
5124
- let v2Loaded = false;
5125
- let lastScopeRevision = backgroundScope.getSnapshot().revision;
5126
- let lastUserJson = serializeSkinBackgroundUserLayer(backgroundScope.getSnapshot().user);
5127
5166
  const background = new BackgroundController(scopeConfig(), persistBackground);
5167
+ let reconcileState = initialSkinBackgroundReconcileState(backgroundScope.getSnapshot());
5128
5168
  const reconcileScope = () => {
5129
- if (!v2Loaded) return;
5130
- const snapshot = backgroundScope.getSnapshot();
5131
- const result = reconcileSkinBackgroundScope(background.snapshot(), {
5132
- revision: snapshot.revision,
5133
- user: snapshot.user
5134
- }, lastScopeRevision, lastUserJson);
5135
- lastScopeRevision = result.revision;
5136
- lastUserJson = result.lastUserJson;
5137
- if (!result.accepted || result.patch === null) return;
5138
- const current = background.snapshot();
5169
+ const result = reconcileSkinBackgroundPublication(reconcileState, background.snapshot(), backgroundScope.getSnapshot());
5170
+ reconcileState = result.state;
5171
+ if (result.patch === null) return;
5172
+ const currentSnapshot = background.snapshot();
5139
5173
  background.init({
5140
- ...current,
5174
+ ...currentSnapshot,
5141
5175
  ...result.patch
5142
5176
  });
5143
5177
  persistBackground(background.snapshot());
5144
5178
  };
5145
5179
  fetch(V2_ACTIVE_URL).then((res) => res.ok ? res.json() : null).then((body) => {
5146
- v2Loaded = true;
5180
+ reconcileState = {
5181
+ ...reconcileState,
5182
+ v2Loaded: true
5183
+ };
5147
5184
  if (body?.background) background.init(body.background);
5148
5185
  reconcileScope();
5149
5186
  }).catch(() => {
5150
- v2Loaded = true;
5187
+ reconcileState = {
5188
+ ...reconcileState,
5189
+ v2Loaded: true
5190
+ };
5151
5191
  reconcileScope();
5152
5192
  });
5153
5193
  ctx.effect(() => backgroundScope.subscribe(reconcileScope), "ui-skin-center: background scope sync");