@cfp-studio/iframe 18.2.0 → 18.4.0
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/README.md +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -769
- package/package.json +13 -6
- package/preview/__previewjs_internal__/runtime-bridge.ts +175 -0
package/README.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region
|
|
1
|
+
//#region ../../../../node_modules/.pnpm/vite@6.4.5_@types+node@24.19.2_jiti@2.6.1_less@4.2.2_lightningcss@1.30.2_sass@1.85.1_terser@5.40.0_tsx@4.19.3_yaml@2.7.0/node_modules/vite/types/hmrPayload.d.ts
|
|
2
2
|
interface UpdatePayload {
|
|
3
3
|
type: 'update';
|
|
4
4
|
updates: Update[];
|
package/dist/index.mjs
CHANGED
|
@@ -1,769 +1 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
3
|
-
//#endregion
|
|
4
|
-
//#region ../node_modules/.pnpm/immer@10.1.1/node_modules/immer/dist/immer.mjs
|
|
5
|
-
var import_assert_never = (/* @__PURE__ */ __commonJSMin(((exports) => {
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.assertNever = assertNever;
|
|
8
|
-
/**
|
|
9
|
-
* Helper function for exhaustive checks of discriminated unions.
|
|
10
|
-
* https://basarat.gitbooks.io/typescript/docs/types/discriminated-unions.html
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
*
|
|
14
|
-
* type A = {type: 'a'};
|
|
15
|
-
* type B = {type: 'b'};
|
|
16
|
-
* type Union = A | B;
|
|
17
|
-
*
|
|
18
|
-
* function doSomething(arg: Union) {
|
|
19
|
-
* if (arg.type === 'a') {
|
|
20
|
-
* return something;
|
|
21
|
-
* }
|
|
22
|
-
*
|
|
23
|
-
* if (arg.type === 'b') {
|
|
24
|
-
* return somethingElse;
|
|
25
|
-
* }
|
|
26
|
-
*
|
|
27
|
-
* // TS will error if there are other types in the union
|
|
28
|
-
* // Will throw an Error when called at runtime.
|
|
29
|
-
* // Use `assertNever(arg, true)` instead to fail silently.
|
|
30
|
-
* return assertNever(arg);
|
|
31
|
-
* }
|
|
32
|
-
*/
|
|
33
|
-
function assertNever(value, errorMessageOrNoThrow) {
|
|
34
|
-
if (typeof errorMessageOrNoThrow === "string") throw new Error(errorMessageOrNoThrow);
|
|
35
|
-
if (typeof errorMessageOrNoThrow === "function") throw new Error(errorMessageOrNoThrow(value));
|
|
36
|
-
if (errorMessageOrNoThrow) return value;
|
|
37
|
-
throw new Error("Unhandled discriminated union member: ".concat(JSON.stringify(value)));
|
|
38
|
-
}
|
|
39
|
-
})))();
|
|
40
|
-
var NOTHING = Symbol.for("immer-nothing");
|
|
41
|
-
var DRAFTABLE = Symbol.for("immer-draftable");
|
|
42
|
-
var DRAFT_STATE = Symbol.for("immer-state");
|
|
43
|
-
var errors = process.env.NODE_ENV !== "production" ? [
|
|
44
|
-
function(plugin) {
|
|
45
|
-
return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`;
|
|
46
|
-
},
|
|
47
|
-
function(thing) {
|
|
48
|
-
return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${thing}'`;
|
|
49
|
-
},
|
|
50
|
-
"This object has been frozen and should not be mutated",
|
|
51
|
-
function(data) {
|
|
52
|
-
return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
|
|
53
|
-
},
|
|
54
|
-
"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
|
|
55
|
-
"Immer forbids circular references",
|
|
56
|
-
"The first or second argument to `produce` must be a function",
|
|
57
|
-
"The third argument to `produce` must be a function or undefined",
|
|
58
|
-
"First argument to `createDraft` must be a plain object, an array, or an immerable object",
|
|
59
|
-
"First argument to `finishDraft` must be a draft returned by `createDraft`",
|
|
60
|
-
function(thing) {
|
|
61
|
-
return `'current' expects a draft, got: ${thing}`;
|
|
62
|
-
},
|
|
63
|
-
"Object.defineProperty() cannot be used on an Immer draft",
|
|
64
|
-
"Object.setPrototypeOf() cannot be used on an Immer draft",
|
|
65
|
-
"Immer only supports deleting array indices",
|
|
66
|
-
"Immer only supports setting array indices and the 'length' property",
|
|
67
|
-
function(thing) {
|
|
68
|
-
return `'original' expects a draft, got: ${thing}`;
|
|
69
|
-
}
|
|
70
|
-
] : [];
|
|
71
|
-
function die(error, ...args) {
|
|
72
|
-
if (process.env.NODE_ENV !== "production") {
|
|
73
|
-
const e = errors[error];
|
|
74
|
-
const msg = typeof e === "function" ? e.apply(null, args) : e;
|
|
75
|
-
throw new Error(`[Immer] ${msg}`);
|
|
76
|
-
}
|
|
77
|
-
throw new Error(`[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`);
|
|
78
|
-
}
|
|
79
|
-
var getPrototypeOf = Object.getPrototypeOf;
|
|
80
|
-
function isDraft(value) {
|
|
81
|
-
return !!value && !!value[DRAFT_STATE];
|
|
82
|
-
}
|
|
83
|
-
function isDraftable(value) {
|
|
84
|
-
if (!value) return false;
|
|
85
|
-
return isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!value.constructor?.[DRAFTABLE] || isMap(value) || isSet(value);
|
|
86
|
-
}
|
|
87
|
-
var objectCtorString = Object.prototype.constructor.toString();
|
|
88
|
-
function isPlainObject(value) {
|
|
89
|
-
if (!value || typeof value !== "object") return false;
|
|
90
|
-
const proto = getPrototypeOf(value);
|
|
91
|
-
if (proto === null) return true;
|
|
92
|
-
const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
93
|
-
if (Ctor === Object) return true;
|
|
94
|
-
return typeof Ctor == "function" && Function.toString.call(Ctor) === objectCtorString;
|
|
95
|
-
}
|
|
96
|
-
function each(obj, iter) {
|
|
97
|
-
if (getArchtype(obj) === 0) Reflect.ownKeys(obj).forEach((key) => {
|
|
98
|
-
iter(key, obj[key], obj);
|
|
99
|
-
});
|
|
100
|
-
else obj.forEach((entry, index) => iter(index, entry, obj));
|
|
101
|
-
}
|
|
102
|
-
function getArchtype(thing) {
|
|
103
|
-
const state = thing[DRAFT_STATE];
|
|
104
|
-
return state ? state.type_ : Array.isArray(thing) ? 1 : isMap(thing) ? 2 : isSet(thing) ? 3 : 0;
|
|
105
|
-
}
|
|
106
|
-
function has(thing, prop) {
|
|
107
|
-
return getArchtype(thing) === 2 ? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
|
|
108
|
-
}
|
|
109
|
-
function set(thing, propOrOldValue, value) {
|
|
110
|
-
const t = getArchtype(thing);
|
|
111
|
-
if (t === 2) thing.set(propOrOldValue, value);
|
|
112
|
-
else if (t === 3) thing.add(value);
|
|
113
|
-
else thing[propOrOldValue] = value;
|
|
114
|
-
}
|
|
115
|
-
function is(x, y) {
|
|
116
|
-
if (x === y) return x !== 0 || 1 / x === 1 / y;
|
|
117
|
-
else return x !== x && y !== y;
|
|
118
|
-
}
|
|
119
|
-
function isMap(target) {
|
|
120
|
-
return target instanceof Map;
|
|
121
|
-
}
|
|
122
|
-
function isSet(target) {
|
|
123
|
-
return target instanceof Set;
|
|
124
|
-
}
|
|
125
|
-
function latest(state) {
|
|
126
|
-
return state.copy_ || state.base_;
|
|
127
|
-
}
|
|
128
|
-
function shallowCopy(base, strict) {
|
|
129
|
-
if (isMap(base)) return new Map(base);
|
|
130
|
-
if (isSet(base)) return new Set(base);
|
|
131
|
-
if (Array.isArray(base)) return Array.prototype.slice.call(base);
|
|
132
|
-
const isPlain = isPlainObject(base);
|
|
133
|
-
if (strict === true || strict === "class_only" && !isPlain) {
|
|
134
|
-
const descriptors = Object.getOwnPropertyDescriptors(base);
|
|
135
|
-
delete descriptors[DRAFT_STATE];
|
|
136
|
-
let keys = Reflect.ownKeys(descriptors);
|
|
137
|
-
for (let i = 0; i < keys.length; i++) {
|
|
138
|
-
const key = keys[i];
|
|
139
|
-
const desc = descriptors[key];
|
|
140
|
-
if (desc.writable === false) {
|
|
141
|
-
desc.writable = true;
|
|
142
|
-
desc.configurable = true;
|
|
143
|
-
}
|
|
144
|
-
if (desc.get || desc.set) descriptors[key] = {
|
|
145
|
-
configurable: true,
|
|
146
|
-
writable: true,
|
|
147
|
-
enumerable: desc.enumerable,
|
|
148
|
-
value: base[key]
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
return Object.create(getPrototypeOf(base), descriptors);
|
|
152
|
-
} else {
|
|
153
|
-
const proto = getPrototypeOf(base);
|
|
154
|
-
if (proto !== null && isPlain) return { ...base };
|
|
155
|
-
const obj = Object.create(proto);
|
|
156
|
-
return Object.assign(obj, base);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
function freeze(obj, deep = false) {
|
|
160
|
-
if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj)) return obj;
|
|
161
|
-
if (getArchtype(obj) > 1) obj.set = obj.add = obj.clear = obj.delete = dontMutateFrozenCollections;
|
|
162
|
-
Object.freeze(obj);
|
|
163
|
-
if (deep) Object.entries(obj).forEach(([key, value]) => freeze(value, true));
|
|
164
|
-
return obj;
|
|
165
|
-
}
|
|
166
|
-
function dontMutateFrozenCollections() {
|
|
167
|
-
die(2);
|
|
168
|
-
}
|
|
169
|
-
function isFrozen(obj) {
|
|
170
|
-
return Object.isFrozen(obj);
|
|
171
|
-
}
|
|
172
|
-
var plugins = {};
|
|
173
|
-
function getPlugin(pluginKey) {
|
|
174
|
-
const plugin = plugins[pluginKey];
|
|
175
|
-
if (!plugin) die(0, pluginKey);
|
|
176
|
-
return plugin;
|
|
177
|
-
}
|
|
178
|
-
var currentScope;
|
|
179
|
-
function getCurrentScope() {
|
|
180
|
-
return currentScope;
|
|
181
|
-
}
|
|
182
|
-
function createScope(parent_, immer_) {
|
|
183
|
-
return {
|
|
184
|
-
drafts_: [],
|
|
185
|
-
parent_,
|
|
186
|
-
immer_,
|
|
187
|
-
canAutoFreeze_: true,
|
|
188
|
-
unfinalizedDrafts_: 0
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
function usePatchesInScope(scope, patchListener) {
|
|
192
|
-
if (patchListener) {
|
|
193
|
-
getPlugin("Patches");
|
|
194
|
-
scope.patches_ = [];
|
|
195
|
-
scope.inversePatches_ = [];
|
|
196
|
-
scope.patchListener_ = patchListener;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
function revokeScope(scope) {
|
|
200
|
-
leaveScope(scope);
|
|
201
|
-
scope.drafts_.forEach(revokeDraft);
|
|
202
|
-
scope.drafts_ = null;
|
|
203
|
-
}
|
|
204
|
-
function leaveScope(scope) {
|
|
205
|
-
if (scope === currentScope) currentScope = scope.parent_;
|
|
206
|
-
}
|
|
207
|
-
function enterScope(immer2) {
|
|
208
|
-
return currentScope = createScope(currentScope, immer2);
|
|
209
|
-
}
|
|
210
|
-
function revokeDraft(draft) {
|
|
211
|
-
const state = draft[DRAFT_STATE];
|
|
212
|
-
if (state.type_ === 0 || state.type_ === 1) state.revoke_();
|
|
213
|
-
else state.revoked_ = true;
|
|
214
|
-
}
|
|
215
|
-
function processResult(result, scope) {
|
|
216
|
-
scope.unfinalizedDrafts_ = scope.drafts_.length;
|
|
217
|
-
const baseDraft = scope.drafts_[0];
|
|
218
|
-
if (result !== void 0 && result !== baseDraft) {
|
|
219
|
-
if (baseDraft[DRAFT_STATE].modified_) {
|
|
220
|
-
revokeScope(scope);
|
|
221
|
-
die(4);
|
|
222
|
-
}
|
|
223
|
-
if (isDraftable(result)) {
|
|
224
|
-
result = finalize(scope, result);
|
|
225
|
-
if (!scope.parent_) maybeFreeze(scope, result);
|
|
226
|
-
}
|
|
227
|
-
if (scope.patches_) getPlugin("Patches").generateReplacementPatches_(baseDraft[DRAFT_STATE].base_, result, scope.patches_, scope.inversePatches_);
|
|
228
|
-
} else result = finalize(scope, baseDraft, []);
|
|
229
|
-
revokeScope(scope);
|
|
230
|
-
if (scope.patches_) scope.patchListener_(scope.patches_, scope.inversePatches_);
|
|
231
|
-
return result !== NOTHING ? result : void 0;
|
|
232
|
-
}
|
|
233
|
-
function finalize(rootScope, value, path) {
|
|
234
|
-
if (isFrozen(value)) return value;
|
|
235
|
-
const state = value[DRAFT_STATE];
|
|
236
|
-
if (!state) {
|
|
237
|
-
each(value, (key, childValue) => finalizeProperty(rootScope, state, value, key, childValue, path));
|
|
238
|
-
return value;
|
|
239
|
-
}
|
|
240
|
-
if (state.scope_ !== rootScope) return value;
|
|
241
|
-
if (!state.modified_) {
|
|
242
|
-
maybeFreeze(rootScope, state.base_, true);
|
|
243
|
-
return state.base_;
|
|
244
|
-
}
|
|
245
|
-
if (!state.finalized_) {
|
|
246
|
-
state.finalized_ = true;
|
|
247
|
-
state.scope_.unfinalizedDrafts_--;
|
|
248
|
-
const result = state.copy_;
|
|
249
|
-
let resultEach = result;
|
|
250
|
-
let isSet2 = false;
|
|
251
|
-
if (state.type_ === 3) {
|
|
252
|
-
resultEach = new Set(result);
|
|
253
|
-
result.clear();
|
|
254
|
-
isSet2 = true;
|
|
255
|
-
}
|
|
256
|
-
each(resultEach, (key, childValue) => finalizeProperty(rootScope, state, result, key, childValue, path, isSet2));
|
|
257
|
-
maybeFreeze(rootScope, result, false);
|
|
258
|
-
if (path && rootScope.patches_) getPlugin("Patches").generatePatches_(state, path, rootScope.patches_, rootScope.inversePatches_);
|
|
259
|
-
}
|
|
260
|
-
return state.copy_;
|
|
261
|
-
}
|
|
262
|
-
function finalizeProperty(rootScope, parentState, targetObject, prop, childValue, rootPath, targetIsSet) {
|
|
263
|
-
if (process.env.NODE_ENV !== "production" && childValue === targetObject) die(5);
|
|
264
|
-
if (isDraft(childValue)) {
|
|
265
|
-
const res = finalize(rootScope, childValue, rootPath && parentState && parentState.type_ !== 3 && !has(parentState.assigned_, prop) ? rootPath.concat(prop) : void 0);
|
|
266
|
-
set(targetObject, prop, res);
|
|
267
|
-
if (isDraft(res)) rootScope.canAutoFreeze_ = false;
|
|
268
|
-
else return;
|
|
269
|
-
} else if (targetIsSet) targetObject.add(childValue);
|
|
270
|
-
if (isDraftable(childValue) && !isFrozen(childValue)) {
|
|
271
|
-
if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) return;
|
|
272
|
-
finalize(rootScope, childValue);
|
|
273
|
-
if ((!parentState || !parentState.scope_.parent_) && typeof prop !== "symbol" && Object.prototype.propertyIsEnumerable.call(targetObject, prop)) maybeFreeze(rootScope, childValue);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
function maybeFreeze(scope, value, deep = false) {
|
|
277
|
-
if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) freeze(value, deep);
|
|
278
|
-
}
|
|
279
|
-
function createProxyProxy(base, parent) {
|
|
280
|
-
const isArray = Array.isArray(base);
|
|
281
|
-
const state = {
|
|
282
|
-
type_: isArray ? 1 : 0,
|
|
283
|
-
scope_: parent ? parent.scope_ : getCurrentScope(),
|
|
284
|
-
modified_: false,
|
|
285
|
-
finalized_: false,
|
|
286
|
-
assigned_: {},
|
|
287
|
-
parent_: parent,
|
|
288
|
-
base_: base,
|
|
289
|
-
draft_: null,
|
|
290
|
-
copy_: null,
|
|
291
|
-
revoke_: null,
|
|
292
|
-
isManual_: false
|
|
293
|
-
};
|
|
294
|
-
let target = state;
|
|
295
|
-
let traps = objectTraps;
|
|
296
|
-
if (isArray) {
|
|
297
|
-
target = [state];
|
|
298
|
-
traps = arrayTraps;
|
|
299
|
-
}
|
|
300
|
-
const { revoke, proxy } = Proxy.revocable(target, traps);
|
|
301
|
-
state.draft_ = proxy;
|
|
302
|
-
state.revoke_ = revoke;
|
|
303
|
-
return proxy;
|
|
304
|
-
}
|
|
305
|
-
var objectTraps = {
|
|
306
|
-
get(state, prop) {
|
|
307
|
-
if (prop === DRAFT_STATE) return state;
|
|
308
|
-
const source = latest(state);
|
|
309
|
-
if (!has(source, prop)) return readPropFromProto(state, source, prop);
|
|
310
|
-
const value = source[prop];
|
|
311
|
-
if (state.finalized_ || !isDraftable(value)) return value;
|
|
312
|
-
if (value === peek(state.base_, prop)) {
|
|
313
|
-
prepareCopy(state);
|
|
314
|
-
return state.copy_[prop] = createProxy(value, state);
|
|
315
|
-
}
|
|
316
|
-
return value;
|
|
317
|
-
},
|
|
318
|
-
has(state, prop) {
|
|
319
|
-
return prop in latest(state);
|
|
320
|
-
},
|
|
321
|
-
ownKeys(state) {
|
|
322
|
-
return Reflect.ownKeys(latest(state));
|
|
323
|
-
},
|
|
324
|
-
set(state, prop, value) {
|
|
325
|
-
const desc = getDescriptorFromProto(latest(state), prop);
|
|
326
|
-
if (desc?.set) {
|
|
327
|
-
desc.set.call(state.draft_, value);
|
|
328
|
-
return true;
|
|
329
|
-
}
|
|
330
|
-
if (!state.modified_) {
|
|
331
|
-
const current2 = peek(latest(state), prop);
|
|
332
|
-
const currentState = current2?.[DRAFT_STATE];
|
|
333
|
-
if (currentState && currentState.base_ === value) {
|
|
334
|
-
state.copy_[prop] = value;
|
|
335
|
-
state.assigned_[prop] = false;
|
|
336
|
-
return true;
|
|
337
|
-
}
|
|
338
|
-
if (is(value, current2) && (value !== void 0 || has(state.base_, prop))) return true;
|
|
339
|
-
prepareCopy(state);
|
|
340
|
-
markChanged(state);
|
|
341
|
-
}
|
|
342
|
-
if (state.copy_[prop] === value && (value !== void 0 || prop in state.copy_) || Number.isNaN(value) && Number.isNaN(state.copy_[prop])) return true;
|
|
343
|
-
state.copy_[prop] = value;
|
|
344
|
-
state.assigned_[prop] = true;
|
|
345
|
-
return true;
|
|
346
|
-
},
|
|
347
|
-
deleteProperty(state, prop) {
|
|
348
|
-
if (peek(state.base_, prop) !== void 0 || prop in state.base_) {
|
|
349
|
-
state.assigned_[prop] = false;
|
|
350
|
-
prepareCopy(state);
|
|
351
|
-
markChanged(state);
|
|
352
|
-
} else delete state.assigned_[prop];
|
|
353
|
-
if (state.copy_) delete state.copy_[prop];
|
|
354
|
-
return true;
|
|
355
|
-
},
|
|
356
|
-
getOwnPropertyDescriptor(state, prop) {
|
|
357
|
-
const owner = latest(state);
|
|
358
|
-
const desc = Reflect.getOwnPropertyDescriptor(owner, prop);
|
|
359
|
-
if (!desc) return desc;
|
|
360
|
-
return {
|
|
361
|
-
writable: true,
|
|
362
|
-
configurable: state.type_ !== 1 || prop !== "length",
|
|
363
|
-
enumerable: desc.enumerable,
|
|
364
|
-
value: owner[prop]
|
|
365
|
-
};
|
|
366
|
-
},
|
|
367
|
-
defineProperty() {
|
|
368
|
-
die(11);
|
|
369
|
-
},
|
|
370
|
-
getPrototypeOf(state) {
|
|
371
|
-
return getPrototypeOf(state.base_);
|
|
372
|
-
},
|
|
373
|
-
setPrototypeOf() {
|
|
374
|
-
die(12);
|
|
375
|
-
}
|
|
376
|
-
};
|
|
377
|
-
var arrayTraps = {};
|
|
378
|
-
each(objectTraps, (key, fn) => {
|
|
379
|
-
arrayTraps[key] = function() {
|
|
380
|
-
arguments[0] = arguments[0][0];
|
|
381
|
-
return fn.apply(this, arguments);
|
|
382
|
-
};
|
|
383
|
-
});
|
|
384
|
-
arrayTraps.deleteProperty = function(state, prop) {
|
|
385
|
-
if (process.env.NODE_ENV !== "production" && isNaN(parseInt(prop))) die(13);
|
|
386
|
-
return arrayTraps.set.call(this, state, prop, void 0);
|
|
387
|
-
};
|
|
388
|
-
arrayTraps.set = function(state, prop, value) {
|
|
389
|
-
if (process.env.NODE_ENV !== "production" && prop !== "length" && isNaN(parseInt(prop))) die(14);
|
|
390
|
-
return objectTraps.set.call(this, state[0], prop, value, state[0]);
|
|
391
|
-
};
|
|
392
|
-
function peek(draft, prop) {
|
|
393
|
-
const state = draft[DRAFT_STATE];
|
|
394
|
-
return (state ? latest(state) : draft)[prop];
|
|
395
|
-
}
|
|
396
|
-
function readPropFromProto(state, source, prop) {
|
|
397
|
-
const desc = getDescriptorFromProto(source, prop);
|
|
398
|
-
return desc ? `value` in desc ? desc.value : desc.get?.call(state.draft_) : void 0;
|
|
399
|
-
}
|
|
400
|
-
function getDescriptorFromProto(source, prop) {
|
|
401
|
-
if (!(prop in source)) return void 0;
|
|
402
|
-
let proto = getPrototypeOf(source);
|
|
403
|
-
while (proto) {
|
|
404
|
-
const desc = Object.getOwnPropertyDescriptor(proto, prop);
|
|
405
|
-
if (desc) return desc;
|
|
406
|
-
proto = getPrototypeOf(proto);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
function markChanged(state) {
|
|
410
|
-
if (!state.modified_) {
|
|
411
|
-
state.modified_ = true;
|
|
412
|
-
if (state.parent_) markChanged(state.parent_);
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
function prepareCopy(state) {
|
|
416
|
-
if (!state.copy_) state.copy_ = shallowCopy(state.base_, state.scope_.immer_.useStrictShallowCopy_);
|
|
417
|
-
}
|
|
418
|
-
var Immer2 = class {
|
|
419
|
-
constructor(config) {
|
|
420
|
-
this.autoFreeze_ = true;
|
|
421
|
-
this.useStrictShallowCopy_ = false;
|
|
422
|
-
/**
|
|
423
|
-
* The `produce` function takes a value and a "recipe function" (whose
|
|
424
|
-
* return value often depends on the base state). The recipe function is
|
|
425
|
-
* free to mutate its first argument however it wants. All mutations are
|
|
426
|
-
* only ever applied to a __copy__ of the base state.
|
|
427
|
-
*
|
|
428
|
-
* Pass only a function to create a "curried producer" which relieves you
|
|
429
|
-
* from passing the recipe function every time.
|
|
430
|
-
*
|
|
431
|
-
* Only plain objects and arrays are made mutable. All other objects are
|
|
432
|
-
* considered uncopyable.
|
|
433
|
-
*
|
|
434
|
-
* Note: This function is __bound__ to its `Immer` instance.
|
|
435
|
-
*
|
|
436
|
-
* @param {any} base - the initial state
|
|
437
|
-
* @param {Function} recipe - function that receives a proxy of the base state as first argument and which can be freely modified
|
|
438
|
-
* @param {Function} patchListener - optional function that will be called with all the patches produced here
|
|
439
|
-
* @returns {any} a new state, or the initial state if nothing was modified
|
|
440
|
-
*/
|
|
441
|
-
this.produce = (base, recipe, patchListener) => {
|
|
442
|
-
if (typeof base === "function" && typeof recipe !== "function") {
|
|
443
|
-
const defaultBase = recipe;
|
|
444
|
-
recipe = base;
|
|
445
|
-
const self = this;
|
|
446
|
-
return function curriedProduce(base2 = defaultBase, ...args) {
|
|
447
|
-
return self.produce(base2, (draft) => recipe.call(this, draft, ...args));
|
|
448
|
-
};
|
|
449
|
-
}
|
|
450
|
-
if (typeof recipe !== "function") die(6);
|
|
451
|
-
if (patchListener !== void 0 && typeof patchListener !== "function") die(7);
|
|
452
|
-
let result;
|
|
453
|
-
if (isDraftable(base)) {
|
|
454
|
-
const scope = enterScope(this);
|
|
455
|
-
const proxy = createProxy(base, void 0);
|
|
456
|
-
let hasError = true;
|
|
457
|
-
try {
|
|
458
|
-
result = recipe(proxy);
|
|
459
|
-
hasError = false;
|
|
460
|
-
} finally {
|
|
461
|
-
if (hasError) revokeScope(scope);
|
|
462
|
-
else leaveScope(scope);
|
|
463
|
-
}
|
|
464
|
-
usePatchesInScope(scope, patchListener);
|
|
465
|
-
return processResult(result, scope);
|
|
466
|
-
} else if (!base || typeof base !== "object") {
|
|
467
|
-
result = recipe(base);
|
|
468
|
-
if (result === void 0) result = base;
|
|
469
|
-
if (result === NOTHING) result = void 0;
|
|
470
|
-
if (this.autoFreeze_) freeze(result, true);
|
|
471
|
-
if (patchListener) {
|
|
472
|
-
const p = [];
|
|
473
|
-
const ip = [];
|
|
474
|
-
getPlugin("Patches").generateReplacementPatches_(base, result, p, ip);
|
|
475
|
-
patchListener(p, ip);
|
|
476
|
-
}
|
|
477
|
-
return result;
|
|
478
|
-
} else die(1, base);
|
|
479
|
-
};
|
|
480
|
-
this.produceWithPatches = (base, recipe) => {
|
|
481
|
-
if (typeof base === "function") return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));
|
|
482
|
-
let patches, inversePatches;
|
|
483
|
-
return [
|
|
484
|
-
this.produce(base, recipe, (p, ip) => {
|
|
485
|
-
patches = p;
|
|
486
|
-
inversePatches = ip;
|
|
487
|
-
}),
|
|
488
|
-
patches,
|
|
489
|
-
inversePatches
|
|
490
|
-
];
|
|
491
|
-
};
|
|
492
|
-
if (typeof config?.autoFreeze === "boolean") this.setAutoFreeze(config.autoFreeze);
|
|
493
|
-
if (typeof config?.useStrictShallowCopy === "boolean") this.setUseStrictShallowCopy(config.useStrictShallowCopy);
|
|
494
|
-
}
|
|
495
|
-
createDraft(base) {
|
|
496
|
-
if (!isDraftable(base)) die(8);
|
|
497
|
-
if (isDraft(base)) base = current(base);
|
|
498
|
-
const scope = enterScope(this);
|
|
499
|
-
const proxy = createProxy(base, void 0);
|
|
500
|
-
proxy[DRAFT_STATE].isManual_ = true;
|
|
501
|
-
leaveScope(scope);
|
|
502
|
-
return proxy;
|
|
503
|
-
}
|
|
504
|
-
finishDraft(draft, patchListener) {
|
|
505
|
-
const state = draft && draft[DRAFT_STATE];
|
|
506
|
-
if (!state || !state.isManual_) die(9);
|
|
507
|
-
const { scope_: scope } = state;
|
|
508
|
-
usePatchesInScope(scope, patchListener);
|
|
509
|
-
return processResult(void 0, scope);
|
|
510
|
-
}
|
|
511
|
-
/**
|
|
512
|
-
* Pass true to automatically freeze all copies created by Immer.
|
|
513
|
-
*
|
|
514
|
-
* By default, auto-freezing is enabled.
|
|
515
|
-
*/
|
|
516
|
-
setAutoFreeze(value) {
|
|
517
|
-
this.autoFreeze_ = value;
|
|
518
|
-
}
|
|
519
|
-
/**
|
|
520
|
-
* Pass true to enable strict shallow copy.
|
|
521
|
-
*
|
|
522
|
-
* By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
|
|
523
|
-
*/
|
|
524
|
-
setUseStrictShallowCopy(value) {
|
|
525
|
-
this.useStrictShallowCopy_ = value;
|
|
526
|
-
}
|
|
527
|
-
applyPatches(base, patches) {
|
|
528
|
-
let i;
|
|
529
|
-
for (i = patches.length - 1; i >= 0; i--) {
|
|
530
|
-
const patch = patches[i];
|
|
531
|
-
if (patch.path.length === 0 && patch.op === "replace") {
|
|
532
|
-
base = patch.value;
|
|
533
|
-
break;
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
if (i > -1) patches = patches.slice(i + 1);
|
|
537
|
-
const applyPatchesImpl = getPlugin("Patches").applyPatches_;
|
|
538
|
-
if (isDraft(base)) return applyPatchesImpl(base, patches);
|
|
539
|
-
return this.produce(base, (draft) => applyPatchesImpl(draft, patches));
|
|
540
|
-
}
|
|
541
|
-
};
|
|
542
|
-
function createProxy(value, parent) {
|
|
543
|
-
const draft = isMap(value) ? getPlugin("MapSet").proxyMap_(value, parent) : isSet(value) ? getPlugin("MapSet").proxySet_(value, parent) : createProxyProxy(value, parent);
|
|
544
|
-
(parent ? parent.scope_ : getCurrentScope()).drafts_.push(draft);
|
|
545
|
-
return draft;
|
|
546
|
-
}
|
|
547
|
-
function current(value) {
|
|
548
|
-
if (!isDraft(value)) die(10, value);
|
|
549
|
-
return currentImpl(value);
|
|
550
|
-
}
|
|
551
|
-
function currentImpl(value) {
|
|
552
|
-
if (!isDraftable(value) || isFrozen(value)) return value;
|
|
553
|
-
const state = value[DRAFT_STATE];
|
|
554
|
-
let copy;
|
|
555
|
-
if (state) {
|
|
556
|
-
if (!state.modified_) return state.base_;
|
|
557
|
-
state.finalized_ = true;
|
|
558
|
-
copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
|
|
559
|
-
} else copy = shallowCopy(value, true);
|
|
560
|
-
each(copy, (key, childValue) => {
|
|
561
|
-
set(copy, key, currentImpl(childValue));
|
|
562
|
-
});
|
|
563
|
-
if (state) state.finalized_ = false;
|
|
564
|
-
return copy;
|
|
565
|
-
}
|
|
566
|
-
var immer = new Immer2();
|
|
567
|
-
var produce = immer.produce;
|
|
568
|
-
immer.produceWithPatches.bind(immer);
|
|
569
|
-
immer.setAutoFreeze.bind(immer);
|
|
570
|
-
immer.setUseStrictShallowCopy.bind(immer);
|
|
571
|
-
immer.applyPatches.bind(immer);
|
|
572
|
-
immer.createDraft.bind(immer);
|
|
573
|
-
immer.finishDraft.bind(immer);
|
|
574
|
-
//#endregion
|
|
575
|
-
//#region src/index.ts
|
|
576
|
-
/**
|
|
577
|
-
* 创建预览 iframe 控制器
|
|
578
|
-
* @param options - 创建控制器的选项
|
|
579
|
-
* @returns 预览 iframe 控制器实例
|
|
580
|
-
*/
|
|
581
|
-
function createController(options) {
|
|
582
|
-
const controller = new PreviewIframeControllerImpl(options);
|
|
583
|
-
window.__PREVIEWJS_CONTROLLER__ = controller;
|
|
584
|
-
return controller;
|
|
585
|
-
}
|
|
586
|
-
/**
|
|
587
|
-
* 预览 iframe 控制器的实现类
|
|
588
|
-
*/
|
|
589
|
-
var PreviewIframeControllerImpl = class {
|
|
590
|
-
/**
|
|
591
|
-
* 构造函数
|
|
592
|
-
* @param options - 创建控制器的选项
|
|
593
|
-
*/
|
|
594
|
-
constructor(options) {
|
|
595
|
-
this.options = options;
|
|
596
|
-
this.lastRender = null;
|
|
597
|
-
this.bootstrapStatus = "pending";
|
|
598
|
-
this.state = {
|
|
599
|
-
loading: false,
|
|
600
|
-
rendered: false,
|
|
601
|
-
errors: [],
|
|
602
|
-
logs: [],
|
|
603
|
-
actions: []
|
|
604
|
-
};
|
|
605
|
-
this.onViteBeforeUpdateLogsLength = 0;
|
|
606
|
-
this.onViteBeforeUpdateErrorsLength = 0;
|
|
607
|
-
}
|
|
608
|
-
/**
|
|
609
|
-
* 渲染预览
|
|
610
|
-
* @param previewableId - 可预览项的 ID
|
|
611
|
-
* @param options - 渲染选项
|
|
612
|
-
*/
|
|
613
|
-
async render(previewableId, options) {
|
|
614
|
-
const previousRender = this.lastRender;
|
|
615
|
-
this.lastRender = {
|
|
616
|
-
previewableId,
|
|
617
|
-
options
|
|
618
|
-
};
|
|
619
|
-
if (previousRender?.previewableId !== previewableId || this.bootstrapStatus === "failure") {
|
|
620
|
-
this.resetIframe(previewableId);
|
|
621
|
-
return;
|
|
622
|
-
}
|
|
623
|
-
const iframeWindow = this.options.getIframe()?.contentWindow;
|
|
624
|
-
if (!iframeWindow || this.bootstrapStatus !== "success") return;
|
|
625
|
-
if (!iframeWindow.__PREVIEWJS_IFRAME__.render) {
|
|
626
|
-
iframeWindow.__PREVIEWJS_IFRAME__.reportEvent({
|
|
627
|
-
kind: "error",
|
|
628
|
-
source: "renderer",
|
|
629
|
-
message: "Iframe was bootstrapped but not fully initialised."
|
|
630
|
-
});
|
|
631
|
-
return;
|
|
632
|
-
}
|
|
633
|
-
const renderPromise = iframeWindow.__PREVIEWJS_IFRAME__.render(options);
|
|
634
|
-
this.clearExpectRenderTimeout();
|
|
635
|
-
this.expectRenderTimeout = setTimeout(() => {
|
|
636
|
-
console.warn("Expected render did not occur after 5 seconds. Reloading iframe...");
|
|
637
|
-
this.resetIframe(previewableId);
|
|
638
|
-
}, 5e3);
|
|
639
|
-
await renderPromise;
|
|
640
|
-
}
|
|
641
|
-
/**
|
|
642
|
-
* 重置 iframe
|
|
643
|
-
* @param id - 可预览项的 ID
|
|
644
|
-
*/
|
|
645
|
-
resetIframe(id) {
|
|
646
|
-
const iframe = this.options.getIframe();
|
|
647
|
-
if (!iframe) return;
|
|
648
|
-
iframe.src = `/${id}/?t=${Date.now()}`;
|
|
649
|
-
this.bootstrapStatus = "not-started";
|
|
650
|
-
}
|
|
651
|
-
/**
|
|
652
|
-
* 处理预览事件
|
|
653
|
-
* @param event - 预览事件对象
|
|
654
|
-
*/
|
|
655
|
-
onPreviewEvent(event) {
|
|
656
|
-
if (this.bootstrapStatus === "not-started") {
|
|
657
|
-
if (event.kind !== "bootstrapping") return;
|
|
658
|
-
}
|
|
659
|
-
switch (event.kind) {
|
|
660
|
-
case "bootstrapping":
|
|
661
|
-
this.bootstrapStatus = "pending";
|
|
662
|
-
break;
|
|
663
|
-
case "bootstrapped":
|
|
664
|
-
this.bootstrapStatus = "success";
|
|
665
|
-
this.onViteBeforeUpdateLogsLength = 0;
|
|
666
|
-
this.onViteBeforeUpdateErrorsLength = 0;
|
|
667
|
-
this.updateState((state) => {
|
|
668
|
-
state.loading = true;
|
|
669
|
-
state.rendered = false;
|
|
670
|
-
state.errors = [];
|
|
671
|
-
state.logs = [];
|
|
672
|
-
});
|
|
673
|
-
if (this.lastRender) this.render(this.lastRender.previewableId, this.lastRender.options).catch(console.error);
|
|
674
|
-
break;
|
|
675
|
-
case "vite-before-reload":
|
|
676
|
-
this.updateState((state) => {
|
|
677
|
-
state.logs = [];
|
|
678
|
-
state.errors = [];
|
|
679
|
-
});
|
|
680
|
-
if (this.lastRender) this.resetIframe(this.lastRender.previewableId);
|
|
681
|
-
break;
|
|
682
|
-
case "vite-before-update":
|
|
683
|
-
this.onViteBeforeUpdateLogsLength = this.state.logs.length;
|
|
684
|
-
this.updateState((state) => {
|
|
685
|
-
for (const update of event.payload.updates) state.errors = state.errors.filter((e) => e.source !== "hmr" || e.modulePath !== update.acceptedPath);
|
|
686
|
-
});
|
|
687
|
-
this.onViteBeforeUpdateErrorsLength = this.state.errors.length;
|
|
688
|
-
break;
|
|
689
|
-
case "vite-invalidate":
|
|
690
|
-
this.updateState((state) => {
|
|
691
|
-
this.onViteBeforeUpdateLogsLength = 0;
|
|
692
|
-
this.onViteBeforeUpdateErrorsLength = 0;
|
|
693
|
-
state.logs = [];
|
|
694
|
-
});
|
|
695
|
-
break;
|
|
696
|
-
case "vite-after-update":
|
|
697
|
-
this.updateState((state) => {
|
|
698
|
-
const logsSliceStart = this.onViteBeforeUpdateLogsLength;
|
|
699
|
-
const errorsSliceStart = this.onViteBeforeUpdateErrorsLength;
|
|
700
|
-
this.onViteBeforeUpdateLogsLength = 0;
|
|
701
|
-
this.onViteBeforeUpdateErrorsLength = 0;
|
|
702
|
-
state.logs = state.logs.slice(logsSliceStart);
|
|
703
|
-
state.errors = state.errors.slice(errorsSliceStart);
|
|
704
|
-
});
|
|
705
|
-
break;
|
|
706
|
-
case "before-render":
|
|
707
|
-
this.updateState((state) => {
|
|
708
|
-
this.onViteBeforeUpdateLogsLength = 0;
|
|
709
|
-
state.logs = [];
|
|
710
|
-
});
|
|
711
|
-
break;
|
|
712
|
-
case "rendered":
|
|
713
|
-
this.updateState((state) => {
|
|
714
|
-
state.loading = false;
|
|
715
|
-
state.rendered = true;
|
|
716
|
-
});
|
|
717
|
-
this.clearExpectRenderTimeout();
|
|
718
|
-
break;
|
|
719
|
-
case "error":
|
|
720
|
-
this.updateState((state) => {
|
|
721
|
-
state.loading = false;
|
|
722
|
-
if (event.source === "vite" && event.message.includes("Failed to fetch dynamically imported module") && state.errors.find((e) => e.source === "vite")) return;
|
|
723
|
-
state.errors = state.errors.filter((e) => e.source !== event.source);
|
|
724
|
-
state.errors.push(event);
|
|
725
|
-
});
|
|
726
|
-
this.clearExpectRenderTimeout();
|
|
727
|
-
if (this.bootstrapStatus === "pending") this.bootstrapStatus = "failure";
|
|
728
|
-
break;
|
|
729
|
-
case "log-message":
|
|
730
|
-
this.updateState((state) => {
|
|
731
|
-
state.logs.push(event);
|
|
732
|
-
});
|
|
733
|
-
break;
|
|
734
|
-
case "action":
|
|
735
|
-
this.updateState((state) => {
|
|
736
|
-
state.actions.push(event);
|
|
737
|
-
});
|
|
738
|
-
break;
|
|
739
|
-
case "toggle-inspect": {
|
|
740
|
-
const window = this.options.getIframe()?.contentWindow;
|
|
741
|
-
if (window) {
|
|
742
|
-
window.__PREVIEWJS_IFRAME__.toggleInspect = event.enabled;
|
|
743
|
-
window.__PREVIEWJS_IFRAME__.refresh({ refetchWrapperModule: true });
|
|
744
|
-
}
|
|
745
|
-
break;
|
|
746
|
-
}
|
|
747
|
-
default: throw (0, import_assert_never.assertNever)(event);
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
/**
|
|
751
|
-
* 更新状态
|
|
752
|
-
* @param stateModifier - 状态修改函数
|
|
753
|
-
*/
|
|
754
|
-
updateState(stateModifier) {
|
|
755
|
-
this.state = produce(this.state, stateModifier);
|
|
756
|
-
this.options.onStateUpdate?.(this.state);
|
|
757
|
-
}
|
|
758
|
-
/**
|
|
759
|
-
* 清除期望渲染的超时定时器
|
|
760
|
-
*/
|
|
761
|
-
clearExpectRenderTimeout() {
|
|
762
|
-
if (this.expectRenderTimeout) {
|
|
763
|
-
clearTimeout(this.expectRenderTimeout);
|
|
764
|
-
this.expectRenderTimeout = null;
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
};
|
|
768
|
-
//#endregion
|
|
769
|
-
export { createController };
|
|
1
|
+
var e=((e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports))((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.assertNever=t;function t(e,t){if(typeof t==`string`)throw Error(t);if(typeof t==`function`)throw Error(t(e));if(t)return e;throw Error(`Unhandled discriminated union member: ${JSON.stringify(e)}`)}}))(),t=Symbol.for(`immer-nothing`),n=Symbol.for(`immer-draftable`),r=Symbol.for(`immer-state`),i=process.env.NODE_ENV===`production`?[]:[function(e){return`The plugin for '${e}' has not been loaded into Immer. To enable the plugin, import and call \`enable${e}()\` when initializing your application.`},function(e){return`produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${e}'`},`This object has been frozen and should not be mutated`,function(e){return`Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? `+e},`An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.`,`Immer forbids circular references`,"The first or second argument to `produce` must be a function","The third argument to `produce` must be a function or undefined","First argument to `createDraft` must be a plain object, an array, or an immerable object","First argument to `finishDraft` must be a draft returned by `createDraft`",function(e){return`'current' expects a draft, got: ${e}`},`Object.defineProperty() cannot be used on an Immer draft`,`Object.setPrototypeOf() cannot be used on an Immer draft`,`Immer only supports deleting array indices`,`Immer only supports setting array indices and the 'length' property`,function(e){return`'original' expects a draft, got: ${e}`}];function a(e,...t){if(process.env.NODE_ENV!==`production`){let n=i[e],r=typeof n==`function`?n.apply(null,t):n;throw Error(`[Immer] ${r}`)}throw Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var o=Object.getPrototypeOf;function s(e){return!!e&&!!e[r]}function c(e){return e?u(e)||Array.isArray(e)||!!e[n]||!!e.constructor?.[n]||g(e)||_(e):!1}var l=Object.prototype.constructor.toString();function u(e){if(!e||typeof e!=`object`)return!1;let t=o(e);if(t===null)return!0;let n=Object.hasOwnProperty.call(t,`constructor`)&&t.constructor;return n===Object?!0:typeof n==`function`&&Function.toString.call(n)===l}function d(e,t){f(e)===0?Reflect.ownKeys(e).forEach(n=>{t(n,e[n],e)}):e.forEach((n,r)=>t(r,n,e))}function f(e){let t=e[r];return t?t.type_:Array.isArray(e)?1:g(e)?2:_(e)?3:0}function p(e,t){return f(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function m(e,t,n){let r=f(e);r===2?e.set(t,n):r===3?e.add(n):e[t]=n}function h(e,t){return e===t?e!==0||1/e==1/t:e!==e&&t!==t}function g(e){return e instanceof Map}function _(e){return e instanceof Set}function v(e){return e.copy_||e.base_}function y(e,t){if(g(e))return new Map(e);if(_(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);let n=u(e);if(t===!0||t===`class_only`&&!n){let t=Object.getOwnPropertyDescriptors(e);delete t[r];let n=Reflect.ownKeys(t);for(let r=0;r<n.length;r++){let i=n[r],a=t[i];a.writable===!1&&(a.writable=!0,a.configurable=!0),(a.get||a.set)&&(t[i]={configurable:!0,writable:!0,enumerable:a.enumerable,value:e[i]})}return Object.create(o(e),t)}else{let t=o(e);if(t!==null&&n)return{...e};let r=Object.create(t);return Object.assign(r,e)}}function b(e,t=!1){return S(e)||s(e)||!c(e)?e:(f(e)>1&&(e.set=e.add=e.clear=e.delete=x),Object.freeze(e),t&&Object.entries(e).forEach(([e,t])=>b(t,!0)),e)}function x(){a(2)}function S(e){return Object.isFrozen(e)}var C={};function w(e){let t=C[e];return t||a(0,e),t}var T;function E(){return T}function D(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function O(e,t){t&&(w(`Patches`),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function k(e){A(e),e.drafts_.forEach(M),e.drafts_=null}function A(e){e===T&&(T=e.parent_)}function j(e){return T=D(T,e)}function M(e){let t=e[r];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function N(e,n){n.unfinalizedDrafts_=n.drafts_.length;let i=n.drafts_[0];return e!==void 0&&e!==i?(i[r].modified_&&(k(n),a(4)),c(e)&&(e=P(n,e),n.parent_||I(n,e)),n.patches_&&w(`Patches`).generateReplacementPatches_(i[r].base_,e,n.patches_,n.inversePatches_)):e=P(n,i,[]),k(n),n.patches_&&n.patchListener_(n.patches_,n.inversePatches_),e===t?void 0:e}function P(e,t,n){if(S(t))return t;let i=t[r];if(!i)return d(t,(r,a)=>F(e,i,t,r,a,n)),t;if(i.scope_!==e)return t;if(!i.modified_)return I(e,i.base_,!0),i.base_;if(!i.finalized_){i.finalized_=!0,i.scope_.unfinalizedDrafts_--;let t=i.copy_,r=t,a=!1;i.type_===3&&(r=new Set(t),t.clear(),a=!0),d(r,(r,o)=>F(e,i,t,r,o,n,a)),I(e,t,!1),n&&e.patches_&&w(`Patches`).generatePatches_(i,n,e.patches_,e.inversePatches_)}return i.copy_}function F(e,t,n,r,i,o,l){if(process.env.NODE_ENV!==`production`&&i===n&&a(5),s(i)){let a=P(e,i,o&&t&&t.type_!==3&&!p(t.assigned_,r)?o.concat(r):void 0);if(m(n,r,a),s(a))e.canAutoFreeze_=!1;else return}else l&&n.add(i);if(c(i)&&!S(i)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;P(e,i),(!t||!t.scope_.parent_)&&typeof r!=`symbol`&&Object.prototype.propertyIsEnumerable.call(n,r)&&I(e,i)}}function I(e,t,n=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&b(t,n)}function L(e,t){let n=Array.isArray(e),r={type_:n?1:0,scope_:t?t.scope_:E(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1},i=r,a=R;n&&(i=[r],a=z);let{revoke:o,proxy:s}=Proxy.revocable(i,a);return r.draft_=s,r.revoke_=o,s}var R={get(e,t){if(t===r)return e;let n=v(e);if(!p(n,t))return V(e,n,t);let i=n[t];return e.finalized_||!c(i)?i:i===B(e.base_,t)?(W(e),e.copy_[t]=K(i,e)):i},has(e,t){return t in v(e)},ownKeys(e){return Reflect.ownKeys(v(e))},set(e,t,n){let i=H(v(e),t);if(i?.set)return i.set.call(e.draft_,n),!0;if(!e.modified_){let i=B(v(e),t),a=i?.[r];if(a&&a.base_===n)return e.copy_[t]=n,e.assigned_[t]=!1,!0;if(h(n,i)&&(n!==void 0||p(e.base_,t)))return!0;W(e),U(e)}return e.copy_[t]===n&&(n!==void 0||t in e.copy_)||Number.isNaN(n)&&Number.isNaN(e.copy_[t])?!0:(e.copy_[t]=n,e.assigned_[t]=!0,!0)},deleteProperty(e,t){return B(e.base_,t)!==void 0||t in e.base_?(e.assigned_[t]=!1,W(e),U(e)):delete e.assigned_[t],e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){let n=v(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r&&{writable:!0,configurable:e.type_!==1||t!==`length`,enumerable:r.enumerable,value:n[t]}},defineProperty(){a(11)},getPrototypeOf(e){return o(e.base_)},setPrototypeOf(){a(12)}},z={};d(R,(e,t)=>{z[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}}),z.deleteProperty=function(e,t){return process.env.NODE_ENV!==`production`&&isNaN(parseInt(t))&&a(13),z.set.call(this,e,t,void 0)},z.set=function(e,t,n){return process.env.NODE_ENV!==`production`&&t!==`length`&&isNaN(parseInt(t))&&a(14),R.set.call(this,e[0],t,n,e[0])};function B(e,t){let n=e[r];return(n?v(n):e)[t]}function V(e,t,n){let r=H(t,n);return r?`value`in r?r.value:r.get?.call(e.draft_):void 0}function H(e,t){if(!(t in e))return;let n=o(e);for(;n;){let e=Object.getOwnPropertyDescriptor(n,t);if(e)return e;n=o(n)}}function U(e){e.modified_||(e.modified_=!0,e.parent_&&U(e.parent_))}function W(e){e.copy_||=y(e.base_,e.scope_.immer_.useStrictShallowCopy_)}var G=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.produce=(e,n,r)=>{if(typeof e==`function`&&typeof n!=`function`){let t=n;n=e;let r=this;return function(e=t,...i){return r.produce(e,e=>n.call(this,e,...i))}}typeof n!=`function`&&a(6),r!==void 0&&typeof r!=`function`&&a(7);let i;if(c(e)){let t=j(this),a=K(e,void 0),o=!0;try{i=n(a),o=!1}finally{o?k(t):A(t)}return O(t,r),N(i,t)}else if(!e||typeof e!=`object`){if(i=n(e),i===void 0&&(i=e),i===t&&(i=void 0),this.autoFreeze_&&b(i,!0),r){let t=[],n=[];w(`Patches`).generateReplacementPatches_(e,i,t,n),r(t,n)}return i}else a(1,e)},this.produceWithPatches=(e,t)=>{if(typeof e==`function`)return(t,...n)=>this.produceWithPatches(t,t=>e(t,...n));let n,r;return[this.produce(e,t,(e,t)=>{n=e,r=t}),n,r]},typeof e?.autoFreeze==`boolean`&&this.setAutoFreeze(e.autoFreeze),typeof e?.useStrictShallowCopy==`boolean`&&this.setUseStrictShallowCopy(e.useStrictShallowCopy)}createDraft(e){c(e)||a(8),s(e)&&(e=q(e));let t=j(this),n=K(e,void 0);return n[r].isManual_=!0,A(t),n}finishDraft(e,t){let n=e&&e[r];(!n||!n.isManual_)&&a(9);let{scope_:i}=n;return O(i,t),N(void 0,i)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}applyPatches(e,t){let n;for(n=t.length-1;n>=0;n--){let r=t[n];if(r.path.length===0&&r.op===`replace`){e=r.value;break}}n>-1&&(t=t.slice(n+1));let r=w(`Patches`).applyPatches_;return s(e)?r(e,t):this.produce(e,e=>r(e,t))}};function K(e,t){let n=g(e)?w(`MapSet`).proxyMap_(e,t):_(e)?w(`MapSet`).proxySet_(e,t):L(e,t);return(t?t.scope_:E()).drafts_.push(n),n}function q(e){return s(e)||a(10,e),J(e)}function J(e){if(!c(e)||S(e))return e;let t=e[r],n;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,n=y(e,t.scope_.immer_.useStrictShallowCopy_)}else n=y(e,!0);return d(n,(e,t)=>{m(n,e,J(t))}),t&&(t.finalized_=!1),n}var Y=new G,X=Y.produce;Y.produceWithPatches.bind(Y),Y.setAutoFreeze.bind(Y),Y.setUseStrictShallowCopy.bind(Y),Y.applyPatches.bind(Y),Y.createDraft.bind(Y),Y.finishDraft.bind(Y);function Z(e){let t=new Q(e);return window.__PREVIEWJS_CONTROLLER__=t,t}var Q=class{constructor(e){this.options=e,this.lastRender=null,this.bootstrapStatus=`pending`,this.state={loading:!1,rendered:!1,errors:[],logs:[],actions:[]},this.onViteBeforeUpdateLogsLength=0,this.onViteBeforeUpdateErrorsLength=0}async render(e,t){let n=this.lastRender;if(this.lastRender={previewableId:e,options:t},n?.previewableId!==e||this.bootstrapStatus===`failure`){this.resetIframe(e);return}let r=this.options.getIframe()?.contentWindow;if(!r||this.bootstrapStatus!==`success`)return;if(!r.__PREVIEWJS_IFRAME__.render){r.__PREVIEWJS_IFRAME__.reportEvent({kind:`error`,source:`renderer`,message:`Iframe was bootstrapped but not fully initialised.`});return}let i=r.__PREVIEWJS_IFRAME__.render(t);this.clearExpectRenderTimeout(),this.expectRenderTimeout=setTimeout(()=>{console.warn(`Expected render did not occur after 5 seconds. Reloading iframe...`),this.resetIframe(e)},5e3),await i}resetIframe(e){let t=this.options.getIframe();t&&(t.src=`/${e}/?t=${Date.now()}`,this.bootstrapStatus=`not-started`)}onPreviewEvent(t){if(!(this.bootstrapStatus===`not-started`&&t.kind!==`bootstrapping`))switch(t.kind){case`bootstrapping`:this.bootstrapStatus=`pending`;break;case`bootstrapped`:this.bootstrapStatus=`success`,this.onViteBeforeUpdateLogsLength=0,this.onViteBeforeUpdateErrorsLength=0,this.updateState(e=>{e.loading=!0,e.rendered=!1,e.errors=[],e.logs=[]}),this.lastRender&&this.render(this.lastRender.previewableId,this.lastRender.options).catch(console.error);break;case`vite-before-reload`:this.updateState(e=>{e.logs=[],e.errors=[]}),this.lastRender&&this.resetIframe(this.lastRender.previewableId);break;case`vite-before-update`:this.onViteBeforeUpdateLogsLength=this.state.logs.length,this.updateState(e=>{for(let n of t.payload.updates)e.errors=e.errors.filter(e=>e.source!==`hmr`||e.modulePath!==n.acceptedPath)}),this.onViteBeforeUpdateErrorsLength=this.state.errors.length;break;case`vite-invalidate`:this.updateState(e=>{this.onViteBeforeUpdateLogsLength=0,this.onViteBeforeUpdateErrorsLength=0,e.logs=[]});break;case`vite-after-update`:this.updateState(e=>{let t=this.onViteBeforeUpdateLogsLength,n=this.onViteBeforeUpdateErrorsLength;this.onViteBeforeUpdateLogsLength=0,this.onViteBeforeUpdateErrorsLength=0,e.logs=e.logs.slice(t),e.errors=e.errors.slice(n)});break;case`before-render`:this.updateState(e=>{this.onViteBeforeUpdateLogsLength=0,e.logs=[]});break;case`rendered`:this.updateState(e=>{e.loading=!1,e.rendered=!0}),this.clearExpectRenderTimeout();break;case`error`:this.updateState(e=>{e.loading=!1,!(t.source===`vite`&&t.message.includes(`Failed to fetch dynamically imported module`)&&e.errors.find(e=>e.source===`vite`))&&(e.errors=e.errors.filter(e=>e.source!==t.source),e.errors.push(t))}),this.clearExpectRenderTimeout(),this.bootstrapStatus===`pending`&&(this.bootstrapStatus=`failure`);break;case`log-message`:this.updateState(e=>{e.logs.push(t)});break;case`action`:this.updateState(e=>{e.actions.push(t)});break;case`toggle-inspect`:{let e=this.options.getIframe()?.contentWindow;e&&(e.__PREVIEWJS_IFRAME__.toggleInspect=t.enabled,e.__PREVIEWJS_IFRAME__.refresh({refetchWrapperModule:!0}));break}default:throw(0,e.assertNever)(t)}}updateState(e){this.state=X(this.state,e),this.options.onStateUpdate?.(this.state)}clearExpectRenderTimeout(){this.expectRenderTimeout&&=(clearTimeout(this.expectRenderTimeout),null)}};export{Z as createController};
|
package/package.json
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cfp-studio/iframe",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.4.0",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "./dist/index.mjs",
|
|
7
|
-
"types": "./dist/index.d.mts",
|
|
8
5
|
"files": [
|
|
9
6
|
"dist",
|
|
10
7
|
"preview"
|
|
11
8
|
],
|
|
9
|
+
"type": "module",
|
|
10
|
+
"main": "./dist/index.mjs",
|
|
11
|
+
"types": "./dist/index.d.mts",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@cfp-studio/fiber-reader": "0.3.0"
|
|
14
|
+
},
|
|
12
15
|
"devDependencies": {
|
|
13
16
|
"assert-never": "1.4.0",
|
|
14
17
|
"immer": "10.1.1",
|
|
15
18
|
"typescript": "5.9.3",
|
|
16
19
|
"vite": "6.4.5"
|
|
17
20
|
},
|
|
18
|
-
"
|
|
19
|
-
"
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=20"
|
|
23
|
+
},
|
|
24
|
+
"cfp": {
|
|
25
|
+
"domain": "web-preview",
|
|
26
|
+
"layer": "engine"
|
|
20
27
|
},
|
|
21
28
|
"scripts": {
|
|
22
29
|
"build": "tsdown",
|
|
@@ -20,6 +20,8 @@ import {
|
|
|
20
20
|
type RuntimeNode,
|
|
21
21
|
type RuntimeNodeDetail,
|
|
22
22
|
type RuntimeSnapshot,
|
|
23
|
+
defaultStyleKeys,
|
|
24
|
+
summarizeComputedStyle,
|
|
23
25
|
type RuntimeSourceLocation,
|
|
24
26
|
} from "@cfp-studio/fiber-reader";
|
|
25
27
|
|
|
@@ -101,6 +103,15 @@ export function setupRuntimeBridge(): void {
|
|
|
101
103
|
const runtimeNodeId = String(event.data.runtimeNodeId ?? "");
|
|
102
104
|
const detail = collectRuntimeNodeDetail(runtimeNodeId);
|
|
103
105
|
publishToHost({ kind: "cfp-runtime-detail", requestId, detail });
|
|
106
|
+
} else if (event.data?.kind === "cfp:computed-style") {
|
|
107
|
+
// Computed Styles 视图的订阅:只在该视图可见且选中节点时建立,
|
|
108
|
+
// 之后由 MutationObserver + resize 触发增量推送(见 subscribeComputedStyle)。
|
|
109
|
+
const runtimeNodeId = String(event.data.runtimeNodeId ?? "");
|
|
110
|
+
if (event.data.subscribe === true && runtimeNodeId) {
|
|
111
|
+
subscribeComputedStyle(runtimeNodeId);
|
|
112
|
+
} else {
|
|
113
|
+
unsubscribeComputedStyle();
|
|
114
|
+
}
|
|
104
115
|
}
|
|
105
116
|
});
|
|
106
117
|
document.addEventListener("click", handleInspectClick, true);
|
|
@@ -210,6 +221,10 @@ export function publishRuntimeSnapshot(): void {
|
|
|
210
221
|
}
|
|
211
222
|
const snapshot = collectRuntimeSnapshot();
|
|
212
223
|
publishToHost({ kind: "cfp-runtime-snapshot", snapshot });
|
|
224
|
+
// 重新渲染会重建 nodeElements:订阅中的节点要么拿到新值,要么显式告知已消失。
|
|
225
|
+
if (computedStyleSubscription) {
|
|
226
|
+
scheduleComputedStylePublish();
|
|
227
|
+
}
|
|
213
228
|
}
|
|
214
229
|
|
|
215
230
|
/**
|
|
@@ -318,6 +333,41 @@ function walk(element: Element | null, parentId: string | undefined, path: strin
|
|
|
318
333
|
return truncated;
|
|
319
334
|
}
|
|
320
335
|
|
|
336
|
+
/**
|
|
337
|
+
* 初始值基线缓存:tag → 参考元素的 computed style 摘要。
|
|
338
|
+
*
|
|
339
|
+
* 参考元素放在 shadow root 里(作者样式匹配不到影子树内部),并显式 `all: initial`,
|
|
340
|
+
* 因此拿到的是**纯 CSS 初始值**:不继承页面、也不被任何作者规则命中。
|
|
341
|
+
*/
|
|
342
|
+
const baselineCache = new Map<string, Record<string, string>>();
|
|
343
|
+
let baselineHost: HTMLElement | undefined;
|
|
344
|
+
|
|
345
|
+
function measureBaseline(tagName: string): Record<string, string> {
|
|
346
|
+
const tag = tagName.toLowerCase();
|
|
347
|
+
const cached = baselineCache.get(tag);
|
|
348
|
+
if (cached) {
|
|
349
|
+
return cached;
|
|
350
|
+
}
|
|
351
|
+
if (!baselineHost) {
|
|
352
|
+
baselineHost = document.createElement("div");
|
|
353
|
+
baselineHost.setAttribute("aria-hidden", "true");
|
|
354
|
+
baselineHost.style.cssText =
|
|
355
|
+
"position:absolute;left:-9999px;top:0;width:0;height:0;overflow:hidden;visibility:hidden;pointer-events:none;";
|
|
356
|
+
document.body.appendChild(baselineHost);
|
|
357
|
+
}
|
|
358
|
+
const root = baselineHost.shadowRoot ?? baselineHost.attachShadow({ mode: "open" });
|
|
359
|
+
root.replaceChildren();
|
|
360
|
+
const reference = document.createElement(tag);
|
|
361
|
+
// `all: initial` 让参考元素回到 **CSS 初始值**(不继承宿主、也不被作者规则命中):
|
|
362
|
+
// 否则作者写 `div { letter-spacing: 2px }` 时,参考元素会通过继承拿到同一个值,
|
|
363
|
+
// 把用户真正设置的属性误判成默认值。
|
|
364
|
+
reference.style.all = "initial";
|
|
365
|
+
root.appendChild(reference);
|
|
366
|
+
const summary = summarizeComputedStyle(window.getComputedStyle(reference));
|
|
367
|
+
baselineCache.set(tag, summary);
|
|
368
|
+
return summary;
|
|
369
|
+
}
|
|
370
|
+
|
|
321
371
|
function collectRuntimeNodeDetail(runtimeNodeId: string): RuntimeNodeDetail | undefined {
|
|
322
372
|
const element = nodeElements.get(runtimeNodeId);
|
|
323
373
|
if (!element) {
|
|
@@ -331,6 +381,7 @@ function collectRuntimeNodeDetail(runtimeNodeId: string): RuntimeNodeDetail | un
|
|
|
331
381
|
}
|
|
332
382
|
const text = (element.textContent ?? "").replace(/\s+/g, " ").trim();
|
|
333
383
|
const outerHTML = element.outerHTML;
|
|
384
|
+
const computedStyle = summarizeComputedStyle(window.getComputedStyle(element));
|
|
334
385
|
return {
|
|
335
386
|
runtimeNodeId,
|
|
336
387
|
bounds: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
|
|
@@ -341,6 +392,8 @@ function collectRuntimeNodeDetail(runtimeNodeId: string): RuntimeNodeDetail | un
|
|
|
341
392
|
scrollY: window.scrollY,
|
|
342
393
|
devicePixelRatio: window.devicePixelRatio,
|
|
343
394
|
},
|
|
395
|
+
computedStyle,
|
|
396
|
+
computedStyleDefaults: defaultStyleKeys(computedStyle, measureBaseline(element.tagName)),
|
|
344
397
|
dom: {
|
|
345
398
|
tag: element.tagName.toLowerCase(),
|
|
346
399
|
id: element.id || undefined,
|
|
@@ -359,6 +412,128 @@ function collectRuntimeNodeDetail(runtimeNodeId: string): RuntimeNodeDetail | un
|
|
|
359
412
|
};
|
|
360
413
|
}
|
|
361
414
|
|
|
415
|
+
/**
|
|
416
|
+
* Computed Styles 视图的订阅态。
|
|
417
|
+
*
|
|
418
|
+
* 为什么不是"每次请求返回一次":视图要跟着 DOM / 样式变化刷新(Codux 的
|
|
419
|
+
* computed-styles 也是订阅式)。这里用 MutationObserver + resize,节流成
|
|
420
|
+
* "120ms 静默后推一次、最长 600ms 必推",并且只在摘要真的变了才发(避免噪声)。
|
|
421
|
+
*/
|
|
422
|
+
interface ComputedStyleSubscription {
|
|
423
|
+
runtimeNodeId: string;
|
|
424
|
+
/** 上次推送的摘要(JSON),用于去重。 */
|
|
425
|
+
lastPayload: string;
|
|
426
|
+
timer: number | undefined;
|
|
427
|
+
firstScheduledAt: number | undefined;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
const COMPUTED_STYLE_DEBOUNCE_MS = 120;
|
|
431
|
+
const COMPUTED_STYLE_MAX_DELAY_MS = 600;
|
|
432
|
+
|
|
433
|
+
let computedStyleSubscription: ComputedStyleSubscription | undefined;
|
|
434
|
+
let computedStyleObserver: MutationObserver | undefined;
|
|
435
|
+
let computedStyleResizeListener = false;
|
|
436
|
+
|
|
437
|
+
function publishComputedStyle(subscription: ComputedStyleSubscription): void {
|
|
438
|
+
const element = nodeElements.get(subscription.runtimeNodeId);
|
|
439
|
+
const computedStyle = element ? summarizeComputedStyle(window.getComputedStyle(element)) : null;
|
|
440
|
+
const payload = JSON.stringify(computedStyle);
|
|
441
|
+
if (payload === subscription.lastPayload) {
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
subscription.lastPayload = payload;
|
|
445
|
+
publishToHost({
|
|
446
|
+
kind: "cfp-computed-style",
|
|
447
|
+
runtimeNodeId: subscription.runtimeNodeId,
|
|
448
|
+
computedStyle,
|
|
449
|
+
computedStyleDefaults:
|
|
450
|
+
element && computedStyle ? defaultStyleKeys(computedStyle, measureBaseline(element.tagName)) : [],
|
|
451
|
+
capturedAt: Date.now(),
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
function scheduleComputedStylePublish(): void {
|
|
456
|
+
const subscription = computedStyleSubscription;
|
|
457
|
+
if (!subscription) {
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
const now = Date.now();
|
|
461
|
+
subscription.firstScheduledAt ??= now;
|
|
462
|
+
if (subscription.timer !== undefined) {
|
|
463
|
+
window.clearTimeout(subscription.timer);
|
|
464
|
+
}
|
|
465
|
+
const remaining = COMPUTED_STYLE_MAX_DELAY_MS - (now - subscription.firstScheduledAt);
|
|
466
|
+
const delay = Math.max(0, Math.min(COMPUTED_STYLE_DEBOUNCE_MS, remaining));
|
|
467
|
+
subscription.timer = window.setTimeout(() => {
|
|
468
|
+
if (computedStyleSubscription !== subscription) {
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
subscription.timer = undefined;
|
|
472
|
+
subscription.firstScheduledAt = undefined;
|
|
473
|
+
publishComputedStyle(subscription);
|
|
474
|
+
}, delay);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
function isOverlayMutation(record: MutationRecord): boolean {
|
|
478
|
+
const target = record.target;
|
|
479
|
+
if (target instanceof Element) {
|
|
480
|
+
return isOverlayChrome(target);
|
|
481
|
+
}
|
|
482
|
+
const parent = target.parentElement;
|
|
483
|
+
return Boolean(parent && isOverlayChrome(parent));
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
function subscribeComputedStyle(runtimeNodeId: string): void {
|
|
487
|
+
if (computedStyleSubscription?.runtimeNodeId === runtimeNodeId) {
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
unsubscribeComputedStyle();
|
|
491
|
+
const subscription: ComputedStyleSubscription = {
|
|
492
|
+
runtimeNodeId,
|
|
493
|
+
lastPayload: "",
|
|
494
|
+
timer: undefined,
|
|
495
|
+
firstScheduledAt: undefined,
|
|
496
|
+
};
|
|
497
|
+
computedStyleSubscription = subscription;
|
|
498
|
+
if (!computedStyleObserver && typeof MutationObserver !== "undefined") {
|
|
499
|
+
computedStyleObserver = new MutationObserver((records) => {
|
|
500
|
+
// inspect 悬停会让 overlay 自己变形;shadow root 内的变更本来就不上报,
|
|
501
|
+
// 但 host 节点的属性变更会——这类变更不影响被选节点的 computed style。
|
|
502
|
+
if (records.every(isOverlayMutation)) {
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
scheduleComputedStylePublish();
|
|
506
|
+
});
|
|
507
|
+
// 观察整棵树(父/兄弟节点变化也会改 computed style);overlay 自身的变更
|
|
508
|
+
// 由 isOverlayChrome 过滤,避免 inspect 悬停时无谓重算。
|
|
509
|
+
computedStyleObserver.observe(document.documentElement, {
|
|
510
|
+
subtree: true,
|
|
511
|
+
childList: true,
|
|
512
|
+
attributes: true,
|
|
513
|
+
characterData: true,
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
if (!computedStyleResizeListener) {
|
|
517
|
+
window.addEventListener("resize", scheduleComputedStylePublish);
|
|
518
|
+
computedStyleResizeListener = true;
|
|
519
|
+
}
|
|
520
|
+
publishComputedStyle(subscription);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function unsubscribeComputedStyle(): void {
|
|
524
|
+
const subscription = computedStyleSubscription;
|
|
525
|
+
if (subscription?.timer !== undefined) {
|
|
526
|
+
window.clearTimeout(subscription.timer);
|
|
527
|
+
}
|
|
528
|
+
computedStyleSubscription = undefined;
|
|
529
|
+
computedStyleObserver?.disconnect();
|
|
530
|
+
computedStyleObserver = undefined;
|
|
531
|
+
if (computedStyleResizeListener) {
|
|
532
|
+
window.removeEventListener("resize", scheduleComputedStylePublish);
|
|
533
|
+
computedStyleResizeListener = false;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
362
537
|
/**
|
|
363
538
|
* Turn a fiber chain into packet frames, root → node.
|
|
364
539
|
*
|