lightview 2.3.7 → 2.3.8
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/docs/cdom.html +6 -5
- package/package.json +1 -1
- package/1769196538097-package.json +0 -43
- package/build_tmp/lightview-router.js +0 -185
- package/build_tmp/lightview-x.js +0 -1608
- package/build_tmp/lightview.js +0 -932
package/build_tmp/lightview.js
DELETED
|
@@ -1,932 +0,0 @@
|
|
|
1
|
-
(function() {
|
|
2
|
-
"use strict";
|
|
3
|
-
const _LV = globalThis.__LIGHTVIEW_INTERNALS__ || (globalThis.__LIGHTVIEW_INTERNALS__ = {
|
|
4
|
-
currentEffect: null,
|
|
5
|
-
registry: /* @__PURE__ */ new Map(),
|
|
6
|
-
// Global name -> Signal/Proxy
|
|
7
|
-
localRegistries: /* @__PURE__ */ new WeakMap(),
|
|
8
|
-
// Object/Element -> Map(name -> Signal/Proxy)
|
|
9
|
-
futureSignals: /* @__PURE__ */ new Map(),
|
|
10
|
-
// name -> Set of (signal) => void
|
|
11
|
-
schemas: /* @__PURE__ */ new Map(),
|
|
12
|
-
// name -> Schema (Draft 7+ or Shorthand)
|
|
13
|
-
parents: /* @__PURE__ */ new WeakMap(),
|
|
14
|
-
// Proxy -> Parent (Proxy/Element)
|
|
15
|
-
helpers: /* @__PURE__ */ new Map(),
|
|
16
|
-
// name -> function (used for transforms and expressions)
|
|
17
|
-
hooks: {
|
|
18
|
-
validate: (value, schema) => true
|
|
19
|
-
// Hook for extensions (like JPRX) to provide full validation
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
const lookup = (name, scope) => {
|
|
23
|
-
let current = scope;
|
|
24
|
-
while (current && typeof current === "object") {
|
|
25
|
-
const registry2 = _LV.localRegistries.get(current);
|
|
26
|
-
if (registry2 && registry2.has(name)) return registry2.get(name);
|
|
27
|
-
current = current.parentElement || _LV.parents.get(current);
|
|
28
|
-
}
|
|
29
|
-
return _LV.registry.get(name);
|
|
30
|
-
};
|
|
31
|
-
const signal = (initialValue, optionsOrName) => {
|
|
32
|
-
const name = typeof optionsOrName === "string" ? optionsOrName : optionsOrName == null ? void 0 : optionsOrName.name;
|
|
33
|
-
const storage = optionsOrName == null ? void 0 : optionsOrName.storage;
|
|
34
|
-
const scope = optionsOrName == null ? void 0 : optionsOrName.scope;
|
|
35
|
-
if (name && storage) {
|
|
36
|
-
try {
|
|
37
|
-
const stored = storage.getItem(name);
|
|
38
|
-
if (stored !== null) initialValue = JSON.parse(stored);
|
|
39
|
-
} catch (e) {
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
let value = initialValue;
|
|
43
|
-
const subscribers = /* @__PURE__ */ new Set();
|
|
44
|
-
const f = (...args) => args.length === 0 ? f.value : f.value = args[0];
|
|
45
|
-
Object.defineProperty(f, "value", {
|
|
46
|
-
get() {
|
|
47
|
-
if (_LV.currentEffect) {
|
|
48
|
-
subscribers.add(_LV.currentEffect);
|
|
49
|
-
_LV.currentEffect.dependencies.add(subscribers);
|
|
50
|
-
}
|
|
51
|
-
return value;
|
|
52
|
-
},
|
|
53
|
-
set(newValue) {
|
|
54
|
-
if (value !== newValue) {
|
|
55
|
-
value = newValue;
|
|
56
|
-
if (name && storage) {
|
|
57
|
-
try {
|
|
58
|
-
storage.setItem(name, JSON.stringify(value));
|
|
59
|
-
} catch (e) {
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
[...subscribers].forEach((effect2) => effect2());
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
if (name) {
|
|
67
|
-
const registry2 = scope && typeof scope === "object" ? _LV.localRegistries.get(scope) || _LV.localRegistries.set(scope, /* @__PURE__ */ new Map()).get(scope) : _LV.registry;
|
|
68
|
-
if (registry2 && registry2.has(name) && registry2.get(name) !== f) {
|
|
69
|
-
throw new Error(`Lightview: A signal or state with the name "${name}" is already registered.`);
|
|
70
|
-
}
|
|
71
|
-
if (registry2) registry2.set(name, f);
|
|
72
|
-
const futures = _LV.futureSignals.get(name);
|
|
73
|
-
if (futures) {
|
|
74
|
-
futures.forEach((resolve) => resolve(f));
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return f;
|
|
78
|
-
};
|
|
79
|
-
const getSignal = (name, defaultValueOrOptions) => {
|
|
80
|
-
const options = typeof defaultValueOrOptions === "object" && defaultValueOrOptions !== null ? defaultValueOrOptions : { defaultValue: defaultValueOrOptions };
|
|
81
|
-
const { scope, defaultValue } = options;
|
|
82
|
-
const existing = lookup(name, scope);
|
|
83
|
-
if (existing) return existing;
|
|
84
|
-
if (defaultValue !== void 0) return signal(defaultValue, { name, scope });
|
|
85
|
-
const future = signal(void 0);
|
|
86
|
-
const handler = (realSignal) => {
|
|
87
|
-
const hasValue = realSignal && (typeof realSignal === "object" || typeof realSignal === "function") && "value" in realSignal;
|
|
88
|
-
if (hasValue) {
|
|
89
|
-
future.value = realSignal.value;
|
|
90
|
-
effect(() => {
|
|
91
|
-
future.value = realSignal.value;
|
|
92
|
-
});
|
|
93
|
-
} else {
|
|
94
|
-
future.value = realSignal;
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
if (!_LV.futureSignals.has(name)) _LV.futureSignals.set(name, /* @__PURE__ */ new Set());
|
|
98
|
-
_LV.futureSignals.get(name).add(handler);
|
|
99
|
-
return future;
|
|
100
|
-
};
|
|
101
|
-
signal.get = getSignal;
|
|
102
|
-
const effect = (fn) => {
|
|
103
|
-
const execute = () => {
|
|
104
|
-
if (!execute.active || execute.running) return;
|
|
105
|
-
execute.dependencies.forEach((dep) => dep.delete(execute));
|
|
106
|
-
execute.dependencies.clear();
|
|
107
|
-
execute.running = true;
|
|
108
|
-
_LV.currentEffect = execute;
|
|
109
|
-
try {
|
|
110
|
-
fn();
|
|
111
|
-
} finally {
|
|
112
|
-
_LV.currentEffect = null;
|
|
113
|
-
execute.running = false;
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
execute.active = true;
|
|
117
|
-
execute.running = false;
|
|
118
|
-
execute.dependencies = /* @__PURE__ */ new Set();
|
|
119
|
-
execute.stop = () => {
|
|
120
|
-
execute.dependencies.forEach((dep) => dep.delete(execute));
|
|
121
|
-
execute.dependencies.clear();
|
|
122
|
-
execute.active = false;
|
|
123
|
-
};
|
|
124
|
-
execute();
|
|
125
|
-
return execute;
|
|
126
|
-
};
|
|
127
|
-
const computed = (fn) => {
|
|
128
|
-
const sig = signal(void 0);
|
|
129
|
-
effect(() => {
|
|
130
|
-
sig.value = fn();
|
|
131
|
-
});
|
|
132
|
-
return sig;
|
|
133
|
-
};
|
|
134
|
-
const getRegistry = () => _LV.registry;
|
|
135
|
-
const internals = _LV;
|
|
136
|
-
const stateCache = /* @__PURE__ */ new WeakMap();
|
|
137
|
-
const stateSignals = /* @__PURE__ */ new WeakMap();
|
|
138
|
-
const stateSchemas = /* @__PURE__ */ new WeakMap();
|
|
139
|
-
const { parents, schemas, hooks } = internals;
|
|
140
|
-
const validate = (target, prop, value, schema) => {
|
|
141
|
-
var _a, _b;
|
|
142
|
-
const current = target[prop];
|
|
143
|
-
const type = typeof current;
|
|
144
|
-
const isNew = !(prop in target);
|
|
145
|
-
let behavior = schema;
|
|
146
|
-
if (typeof schema === "object" && schema !== null) behavior = schema.type;
|
|
147
|
-
if (behavior === "auto" && isNew) throw new Error(`Lightview: Cannot add new property "${prop}" to fixed 'auto' state.`);
|
|
148
|
-
if (behavior === "polymorphic" || typeof behavior === "object" && (behavior == null ? void 0 : behavior.coerce)) {
|
|
149
|
-
if (type === "number") return Number(value);
|
|
150
|
-
if (type === "boolean") return Boolean(value);
|
|
151
|
-
if (type === "string") return String(value);
|
|
152
|
-
} else if (behavior === "auto" || behavior === "dynamic") {
|
|
153
|
-
if (!isNew && typeof value !== type) {
|
|
154
|
-
throw new Error(`Lightview: Type mismatch for "${prop}". Expected ${type}, got ${typeof value}.`);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
if (typeof schema === "object" && schema !== null && schema.transform) {
|
|
158
|
-
const trans = schema.transform;
|
|
159
|
-
const transformFn = typeof trans === "function" ? trans : internals.helpers.get(trans) || ((_b = (_a = globalThis.Lightview) == null ? void 0 : _a.helpers) == null ? void 0 : _b[trans]);
|
|
160
|
-
if (transformFn) value = transformFn(value);
|
|
161
|
-
}
|
|
162
|
-
if (hooks.validate(value, schema) === false) {
|
|
163
|
-
throw new Error(`Lightview: Validation failed for "${prop}".`);
|
|
164
|
-
}
|
|
165
|
-
return value;
|
|
166
|
-
};
|
|
167
|
-
const protoMethods = (proto, test) => Object.getOwnPropertyNames(proto).filter((k) => typeof proto[k] === "function" && test(k));
|
|
168
|
-
const DATE_TRACKING = protoMethods(Date.prototype, (k) => /^(to|get|valueOf)/.test(k));
|
|
169
|
-
const DATE_MUTATING = protoMethods(Date.prototype, (k) => /^set/.test(k));
|
|
170
|
-
const ARRAY_TRACKING = [
|
|
171
|
-
"map",
|
|
172
|
-
"forEach",
|
|
173
|
-
"filter",
|
|
174
|
-
"find",
|
|
175
|
-
"findIndex",
|
|
176
|
-
"some",
|
|
177
|
-
"every",
|
|
178
|
-
"reduce",
|
|
179
|
-
"reduceRight",
|
|
180
|
-
"includes",
|
|
181
|
-
"indexOf",
|
|
182
|
-
"lastIndexOf",
|
|
183
|
-
"join",
|
|
184
|
-
"slice",
|
|
185
|
-
"concat",
|
|
186
|
-
"flat",
|
|
187
|
-
"flatMap",
|
|
188
|
-
"at",
|
|
189
|
-
"entries",
|
|
190
|
-
"keys",
|
|
191
|
-
"values"
|
|
192
|
-
];
|
|
193
|
-
const ARRAY_MUTATING = ["push", "pop", "shift", "unshift", "splice", "sort", "reverse", "fill", "copyWithin"];
|
|
194
|
-
const ARRAY_ITERATION = ["map", "forEach", "filter", "find", "findIndex", "some", "every", "flatMap"];
|
|
195
|
-
const getOrSet = (map, key, factory) => {
|
|
196
|
-
let v = map.get(key);
|
|
197
|
-
if (!v) {
|
|
198
|
-
v = factory();
|
|
199
|
-
map.set(key, v);
|
|
200
|
-
}
|
|
201
|
-
return v;
|
|
202
|
-
};
|
|
203
|
-
const proxyGet = (target, prop, receiver, signals) => {
|
|
204
|
-
if (prop === "__parent__") return parents.get(receiver);
|
|
205
|
-
if (!signals.has(prop)) {
|
|
206
|
-
signals.set(prop, signal(Reflect.get(target, prop, receiver)));
|
|
207
|
-
}
|
|
208
|
-
const signal$1 = signals.get(prop);
|
|
209
|
-
const val = signal$1.value;
|
|
210
|
-
if (typeof val === "object" && val !== null) {
|
|
211
|
-
const childProxy = state(val);
|
|
212
|
-
parents.set(childProxy, receiver);
|
|
213
|
-
return childProxy;
|
|
214
|
-
}
|
|
215
|
-
return val;
|
|
216
|
-
};
|
|
217
|
-
const proxySet = (target, prop, value, receiver, signals) => {
|
|
218
|
-
const schema = stateSchemas.get(receiver);
|
|
219
|
-
const validatedValue = schema ? validate(target, prop, value, schema) : value;
|
|
220
|
-
if (!signals.has(prop)) {
|
|
221
|
-
signals.set(prop, signal(Reflect.get(target, prop, receiver)));
|
|
222
|
-
}
|
|
223
|
-
const success = Reflect.set(target, prop, validatedValue, receiver);
|
|
224
|
-
const signal$1 = signals.get(prop);
|
|
225
|
-
if (success && signal$1) signal$1.value = validatedValue;
|
|
226
|
-
return success;
|
|
227
|
-
};
|
|
228
|
-
const createSpecialProxy = (obj, monitor, trackingProps = []) => {
|
|
229
|
-
const signals = getOrSet(stateSignals, obj, () => /* @__PURE__ */ new Map());
|
|
230
|
-
if (!signals.has(monitor)) {
|
|
231
|
-
const initialValue = typeof obj[monitor] === "function" ? obj[monitor].call(obj) : obj[monitor];
|
|
232
|
-
signals.set(monitor, signal(initialValue));
|
|
233
|
-
}
|
|
234
|
-
const isDate = obj instanceof Date;
|
|
235
|
-
const isArray = Array.isArray(obj);
|
|
236
|
-
const trackingMethods = isDate ? DATE_TRACKING : isArray ? ARRAY_TRACKING : trackingProps;
|
|
237
|
-
const mutatingMethods = isDate ? DATE_MUTATING : isArray ? ARRAY_MUTATING : [];
|
|
238
|
-
return new Proxy(obj, {
|
|
239
|
-
get(target, prop, receiver) {
|
|
240
|
-
if (prop === "__parent__") return parents.get(receiver);
|
|
241
|
-
const value = target[prop];
|
|
242
|
-
if (typeof value === "function") {
|
|
243
|
-
const isTracking = trackingMethods.includes(prop);
|
|
244
|
-
const isMutating = mutatingMethods.includes(prop);
|
|
245
|
-
return function(...args) {
|
|
246
|
-
if (isTracking) {
|
|
247
|
-
const sig = signals.get(monitor);
|
|
248
|
-
if (sig) void sig.value;
|
|
249
|
-
}
|
|
250
|
-
const startValue = typeof target[monitor] === "function" ? target[monitor].call(target) : target[monitor];
|
|
251
|
-
if (isArray && ARRAY_ITERATION.includes(prop) && typeof args[0] === "function") {
|
|
252
|
-
const originalCallback = args[0];
|
|
253
|
-
args[0] = function(element2, index, array) {
|
|
254
|
-
const wrappedElement = typeof element2 === "object" && element2 !== null ? state(element2) : element2;
|
|
255
|
-
if (wrappedElement && typeof wrappedElement === "object") {
|
|
256
|
-
parents.set(wrappedElement, receiver);
|
|
257
|
-
}
|
|
258
|
-
return originalCallback.call(this, wrappedElement, index, array);
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
const result = value.apply(target, args);
|
|
262
|
-
const endValue = typeof target[monitor] === "function" ? target[monitor].call(target) : target[monitor];
|
|
263
|
-
if (startValue !== endValue || isMutating) {
|
|
264
|
-
const sig = signals.get(monitor);
|
|
265
|
-
if (sig && sig.value !== endValue) {
|
|
266
|
-
sig.value = endValue;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
return result;
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
if (prop === monitor) {
|
|
273
|
-
const sig = signals.get(monitor);
|
|
274
|
-
return sig ? sig.value : Reflect.get(target, prop, receiver);
|
|
275
|
-
}
|
|
276
|
-
if (isArray && !isNaN(parseInt(prop))) {
|
|
277
|
-
const monitorSig = signals.get(monitor);
|
|
278
|
-
if (monitorSig) void monitorSig.value;
|
|
279
|
-
}
|
|
280
|
-
return proxyGet(target, prop, receiver, signals);
|
|
281
|
-
},
|
|
282
|
-
set(target, prop, value, receiver) {
|
|
283
|
-
if (prop === monitor) {
|
|
284
|
-
const success = Reflect.set(target, prop, value, receiver);
|
|
285
|
-
if (success) {
|
|
286
|
-
const sig = signals.get(monitor);
|
|
287
|
-
if (sig) sig.value = value;
|
|
288
|
-
}
|
|
289
|
-
return success;
|
|
290
|
-
}
|
|
291
|
-
return proxySet(target, prop, value, receiver, signals);
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
};
|
|
295
|
-
const state = (obj, optionsOrName) => {
|
|
296
|
-
if (typeof obj !== "object" || obj === null) return obj;
|
|
297
|
-
const name = typeof optionsOrName === "string" ? optionsOrName : optionsOrName == null ? void 0 : optionsOrName.name;
|
|
298
|
-
const storage = optionsOrName == null ? void 0 : optionsOrName.storage;
|
|
299
|
-
const scope = optionsOrName == null ? void 0 : optionsOrName.scope;
|
|
300
|
-
const schema = optionsOrName == null ? void 0 : optionsOrName.schema;
|
|
301
|
-
if (name && storage) {
|
|
302
|
-
try {
|
|
303
|
-
const item = storage.getItem(name);
|
|
304
|
-
if (item) {
|
|
305
|
-
const loaded = JSON.parse(item);
|
|
306
|
-
Array.isArray(obj) && Array.isArray(loaded) ? (obj.length = 0, obj.push(...loaded)) : Object.assign(obj, loaded);
|
|
307
|
-
}
|
|
308
|
-
} catch (e) {
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
let proxy = stateCache.get(obj);
|
|
312
|
-
if (!proxy) {
|
|
313
|
-
const isArray = Array.isArray(obj), isDate = obj instanceof Date;
|
|
314
|
-
const isSpecial = isArray || isDate;
|
|
315
|
-
const monitor = isArray ? "length" : isDate ? "getTime" : null;
|
|
316
|
-
if (isSpecial || !(obj instanceof RegExp || obj instanceof Map || obj instanceof Set || obj instanceof WeakMap || obj instanceof WeakSet)) {
|
|
317
|
-
proxy = isSpecial ? createSpecialProxy(obj, monitor) : new Proxy(obj, {
|
|
318
|
-
get(t, p, r) {
|
|
319
|
-
if (p === "__parent__") return parents.get(r);
|
|
320
|
-
return proxyGet(t, p, r, getOrSet(stateSignals, t, () => /* @__PURE__ */ new Map()));
|
|
321
|
-
},
|
|
322
|
-
set(t, p, v, r) {
|
|
323
|
-
return proxySet(t, p, v, r, getOrSet(stateSignals, t, () => /* @__PURE__ */ new Map()));
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
stateCache.set(obj, proxy);
|
|
327
|
-
} else return obj;
|
|
328
|
-
}
|
|
329
|
-
if (schema) stateSchemas.set(proxy, schema);
|
|
330
|
-
if (name && storage) {
|
|
331
|
-
effect(() => {
|
|
332
|
-
try {
|
|
333
|
-
storage.setItem(name, JSON.stringify(proxy));
|
|
334
|
-
} catch (e) {
|
|
335
|
-
}
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
if (name) {
|
|
339
|
-
const registry2 = scope && typeof scope === "object" ? internals.localRegistries.get(scope) || internals.localRegistries.set(scope, /* @__PURE__ */ new Map()).get(scope) : getRegistry();
|
|
340
|
-
if (registry2 && registry2.has(name) && registry2.get(name) !== proxy) {
|
|
341
|
-
throw new Error(`Lightview: A signal or state with the name "${name}" is already registered.`);
|
|
342
|
-
}
|
|
343
|
-
if (registry2) registry2.set(name, proxy);
|
|
344
|
-
const futures = internals.futureSignals.get(name);
|
|
345
|
-
if (futures) {
|
|
346
|
-
futures.forEach((resolve) => resolve(proxy));
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
return proxy;
|
|
350
|
-
};
|
|
351
|
-
const getState = (name, defaultValueOrOptions) => {
|
|
352
|
-
const options = typeof defaultValueOrOptions === "object" && defaultValueOrOptions !== null ? defaultValueOrOptions : { defaultValue: defaultValueOrOptions };
|
|
353
|
-
const { scope, defaultValue } = options;
|
|
354
|
-
const existing = lookup(name, scope);
|
|
355
|
-
if (existing) return existing;
|
|
356
|
-
if (defaultValue !== void 0) return state(defaultValue, { name, scope });
|
|
357
|
-
const future = signal(void 0);
|
|
358
|
-
const handler = (realState) => {
|
|
359
|
-
future.value = realState;
|
|
360
|
-
};
|
|
361
|
-
if (!internals.futureSignals.has(name)) internals.futureSignals.set(name, /* @__PURE__ */ new Set());
|
|
362
|
-
internals.futureSignals.get(name).add(handler);
|
|
363
|
-
return future;
|
|
364
|
-
};
|
|
365
|
-
state.get = getState;
|
|
366
|
-
const core = {
|
|
367
|
-
get currentEffect() {
|
|
368
|
-
return (globalThis.__LIGHTVIEW_INTERNALS__ || (globalThis.__LIGHTVIEW_INTERNALS__ = {})).currentEffect;
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
const nodeState = /* @__PURE__ */ new WeakMap();
|
|
372
|
-
const nodeStateFactory = () => ({ effects: [], onmount: null, onunmount: null });
|
|
373
|
-
const registry = getRegistry();
|
|
374
|
-
const scrollMemory = /* @__PURE__ */ new Map();
|
|
375
|
-
const initScrollMemory = () => {
|
|
376
|
-
if (typeof document === "undefined") return;
|
|
377
|
-
document.addEventListener("scroll", (e) => {
|
|
378
|
-
const el = e.target;
|
|
379
|
-
if (el === document || el === document.documentElement) return;
|
|
380
|
-
const key = el.id || el.getAttribute && el.getAttribute("data-preserve-scroll");
|
|
381
|
-
if (key) {
|
|
382
|
-
scrollMemory.set(key, { top: el.scrollTop, left: el.scrollLeft });
|
|
383
|
-
}
|
|
384
|
-
}, true);
|
|
385
|
-
};
|
|
386
|
-
if (typeof document !== "undefined") {
|
|
387
|
-
if (document.readyState === "loading") {
|
|
388
|
-
document.addEventListener("DOMContentLoaded", initScrollMemory);
|
|
389
|
-
} else {
|
|
390
|
-
initScrollMemory();
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
const saveScrolls = () => new Map(scrollMemory);
|
|
394
|
-
const restoreScrolls = (map, root = document) => {
|
|
395
|
-
if (!map || map.size === 0) return;
|
|
396
|
-
requestAnimationFrame(() => {
|
|
397
|
-
map.forEach((pos, key) => {
|
|
398
|
-
const node = document.getElementById(key) || document.querySelector(`[data-preserve-scroll="${key}"]`);
|
|
399
|
-
if (node) {
|
|
400
|
-
node.scrollTop = pos.top;
|
|
401
|
-
node.scrollLeft = pos.left;
|
|
402
|
-
}
|
|
403
|
-
});
|
|
404
|
-
});
|
|
405
|
-
};
|
|
406
|
-
const trackEffect = (node, effectFn) => {
|
|
407
|
-
const state2 = getOrSet(nodeState, node, nodeStateFactory);
|
|
408
|
-
if (!state2.effects) state2.effects = [];
|
|
409
|
-
state2.effects.push(effectFn);
|
|
410
|
-
};
|
|
411
|
-
const SHADOW_DOM_MARKER = Symbol("lightview.shadowDOM");
|
|
412
|
-
const createShadowDOMMarker = (attributes, children) => ({
|
|
413
|
-
[SHADOW_DOM_MARKER]: true,
|
|
414
|
-
mode: attributes.mode || "open",
|
|
415
|
-
styles: attributes.styles || [],
|
|
416
|
-
adoptedStyleSheets: attributes.adoptedStyleSheets || [],
|
|
417
|
-
children
|
|
418
|
-
});
|
|
419
|
-
const isShadowDOMMarker = (obj) => obj && typeof obj === "object" && obj[SHADOW_DOM_MARKER] === true;
|
|
420
|
-
const processShadowDOM = (marker, parentNode) => {
|
|
421
|
-
if (parentNode.shadowRoot) {
|
|
422
|
-
console.warn("Lightview: Element already has a shadowRoot, skipping shadowDOM directive");
|
|
423
|
-
return;
|
|
424
|
-
}
|
|
425
|
-
const shadowRoot = parentNode.attachShadow({ mode: marker.mode });
|
|
426
|
-
const sheets = [];
|
|
427
|
-
const linkUrls = [...marker.styles || []];
|
|
428
|
-
if (marker.adoptedStyleSheets && marker.adoptedStyleSheets.length > 0) {
|
|
429
|
-
marker.adoptedStyleSheets.forEach((item) => {
|
|
430
|
-
if (item instanceof CSSStyleSheet) {
|
|
431
|
-
sheets.push(item);
|
|
432
|
-
} else if (typeof item === "string") {
|
|
433
|
-
linkUrls.push(item);
|
|
434
|
-
}
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
if (sheets.length > 0) {
|
|
438
|
-
try {
|
|
439
|
-
shadowRoot.adoptedStyleSheets = sheets;
|
|
440
|
-
} catch (e) {
|
|
441
|
-
console.warn("Lightview: adoptedStyleSheets not supported");
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
for (const styleUrl of linkUrls) {
|
|
445
|
-
const link = document.createElement("link");
|
|
446
|
-
link.rel = "stylesheet";
|
|
447
|
-
link.href = styleUrl;
|
|
448
|
-
shadowRoot.appendChild(link);
|
|
449
|
-
}
|
|
450
|
-
if (marker.children && marker.children.length > 0) {
|
|
451
|
-
setupChildrenInTarget(marker.children, shadowRoot);
|
|
452
|
-
}
|
|
453
|
-
};
|
|
454
|
-
let inSVG = false;
|
|
455
|
-
const domToElement = /* @__PURE__ */ new WeakMap();
|
|
456
|
-
const wrapDomElement = (domNode, tag, attributes = {}, children = []) => {
|
|
457
|
-
const el = {
|
|
458
|
-
tag,
|
|
459
|
-
attributes,
|
|
460
|
-
children,
|
|
461
|
-
get domEl() {
|
|
462
|
-
return domNode;
|
|
463
|
-
}
|
|
464
|
-
};
|
|
465
|
-
const proxy = makeReactive(el);
|
|
466
|
-
domToElement.set(domNode, proxy);
|
|
467
|
-
return proxy;
|
|
468
|
-
};
|
|
469
|
-
const element = (tag, attributes = {}, children = []) => {
|
|
470
|
-
if (customTags[tag]) tag = customTags[tag];
|
|
471
|
-
if (typeof tag === "function") {
|
|
472
|
-
const result = tag({ ...attributes }, children);
|
|
473
|
-
return processComponentResult(result);
|
|
474
|
-
}
|
|
475
|
-
if (tag === "shadowDOM") {
|
|
476
|
-
return createShadowDOMMarker(attributes, children);
|
|
477
|
-
}
|
|
478
|
-
if (tag === "text" && !inSVG) {
|
|
479
|
-
const domNode2 = document.createTextNode("");
|
|
480
|
-
const el = {
|
|
481
|
-
tag,
|
|
482
|
-
attributes,
|
|
483
|
-
children,
|
|
484
|
-
get domEl() {
|
|
485
|
-
return domNode2;
|
|
486
|
-
}
|
|
487
|
-
};
|
|
488
|
-
const update = () => {
|
|
489
|
-
const flat = (Array.isArray(el.children) ? el.children : [el.children]).flat(Infinity);
|
|
490
|
-
const bits = flat.map((c) => {
|
|
491
|
-
const val = typeof c === "function" ? c() : c;
|
|
492
|
-
if (val && typeof val === "object" && val.domEl) return val.domEl.textContent;
|
|
493
|
-
return val === null || val === void 0 ? "" : String(val);
|
|
494
|
-
});
|
|
495
|
-
domNode2.textContent = bits.join(" ");
|
|
496
|
-
};
|
|
497
|
-
const proxy2 = new Proxy(el, {
|
|
498
|
-
set(target, prop, value) {
|
|
499
|
-
target[prop] = value;
|
|
500
|
-
if (prop === "children") update();
|
|
501
|
-
return true;
|
|
502
|
-
}
|
|
503
|
-
});
|
|
504
|
-
const hasReactive = children.flat(Infinity).some((c) => typeof c === "function");
|
|
505
|
-
if (hasReactive) {
|
|
506
|
-
const runner = effect(update);
|
|
507
|
-
trackEffect(domNode2, runner);
|
|
508
|
-
}
|
|
509
|
-
update();
|
|
510
|
-
return proxy2;
|
|
511
|
-
}
|
|
512
|
-
const isSVG = tag.toLowerCase() === "svg";
|
|
513
|
-
const wasInSVG = inSVG;
|
|
514
|
-
if (isSVG) inSVG = true;
|
|
515
|
-
const domNode = inSVG ? document.createElementNS("http://www.w3.org/2000/svg", tag) : document.createElement(tag);
|
|
516
|
-
const proxy = wrapDomElement(domNode, tag, attributes, children);
|
|
517
|
-
proxy.attributes = attributes;
|
|
518
|
-
proxy.children = children;
|
|
519
|
-
if (isSVG) inSVG = wasInSVG;
|
|
520
|
-
return proxy;
|
|
521
|
-
};
|
|
522
|
-
const processComponentResult = (result) => {
|
|
523
|
-
if (!result) return null;
|
|
524
|
-
if (Lightview.hooks.processChild) {
|
|
525
|
-
result = Lightview.hooks.processChild(result) ?? result;
|
|
526
|
-
}
|
|
527
|
-
if (result.domEl) return result;
|
|
528
|
-
const type = typeof result;
|
|
529
|
-
if (type === "object" && result instanceof HTMLElement) {
|
|
530
|
-
return wrapDomElement(result, result.tagName.toLowerCase(), {}, []);
|
|
531
|
-
}
|
|
532
|
-
if (type === "object" && result instanceof String) {
|
|
533
|
-
const span = document.createElement("span");
|
|
534
|
-
span.textContent = result.toString();
|
|
535
|
-
return wrapDomElement(span, "span", {}, []);
|
|
536
|
-
}
|
|
537
|
-
if (type === "string") {
|
|
538
|
-
const template = document.createElement("template");
|
|
539
|
-
template.innerHTML = result.trim();
|
|
540
|
-
const content = template.content;
|
|
541
|
-
if (content.childNodes.length === 1 && content.firstChild instanceof HTMLElement) {
|
|
542
|
-
const el = content.firstChild;
|
|
543
|
-
return wrapDomElement(el, el.tagName.toLowerCase(), {}, []);
|
|
544
|
-
} else {
|
|
545
|
-
const wrapper = document.createElement("span");
|
|
546
|
-
wrapper.style.display = "contents";
|
|
547
|
-
wrapper.appendChild(content);
|
|
548
|
-
return wrapDomElement(wrapper, "span", {}, []);
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
if (typeof result === "object" && result.tag) {
|
|
552
|
-
return element(result.tag, result.attributes || {}, result.children || []);
|
|
553
|
-
}
|
|
554
|
-
return null;
|
|
555
|
-
};
|
|
556
|
-
const makeReactive = (el) => {
|
|
557
|
-
const domNode = el.domEl;
|
|
558
|
-
return new Proxy(el, {
|
|
559
|
-
set(target, prop, value) {
|
|
560
|
-
if (prop === "attributes") {
|
|
561
|
-
target[prop] = makeReactiveAttributes(value, domNode);
|
|
562
|
-
} else if (prop === "children") {
|
|
563
|
-
target[prop] = setupChildren(value, domNode);
|
|
564
|
-
} else {
|
|
565
|
-
target[prop] = value;
|
|
566
|
-
}
|
|
567
|
-
return true;
|
|
568
|
-
}
|
|
569
|
-
});
|
|
570
|
-
};
|
|
571
|
-
const NODE_PROPERTIES = /* @__PURE__ */ new Set(["value", "checked", "selected", "selectedIndex", "className", "innerHTML", "innerText"]);
|
|
572
|
-
const setAttributeValue = (domNode, key, value) => {
|
|
573
|
-
const isBool = typeof domNode[key] === "boolean";
|
|
574
|
-
if ((key === "href" || key === "src") && typeof value === "string" && /^(javascript|vbscript|data:text\/html|data:application\/javascript)/i.test(value)) {
|
|
575
|
-
console.warn(`[Lightview] Blocked dangerous protocol in ${key}: ${value}`);
|
|
576
|
-
value = "javascript:void(0)";
|
|
577
|
-
}
|
|
578
|
-
if (NODE_PROPERTIES.has(key) || isBool || key.startsWith("cdom-")) {
|
|
579
|
-
domNode[key] = isBool ? value !== null && value !== void 0 && value !== false && value !== "false" : value;
|
|
580
|
-
} else if (value === null || value === void 0) {
|
|
581
|
-
domNode.removeAttribute(key);
|
|
582
|
-
} else {
|
|
583
|
-
domNode.setAttribute(key, value);
|
|
584
|
-
}
|
|
585
|
-
};
|
|
586
|
-
const makeReactiveAttributes = (attributes, domNode) => {
|
|
587
|
-
const reactiveAttrs = {};
|
|
588
|
-
for (let [key, value] of Object.entries(attributes)) {
|
|
589
|
-
if (value && typeof value === "object" && value.__xpath__ && value.__static__) {
|
|
590
|
-
domNode.setAttribute(`data-xpath-${key}`, value.__xpath__);
|
|
591
|
-
reactiveAttrs[key] = value;
|
|
592
|
-
continue;
|
|
593
|
-
}
|
|
594
|
-
if (key === "onmount" || key === "onunmount") {
|
|
595
|
-
const state2 = getOrSet(nodeState, domNode, nodeStateFactory);
|
|
596
|
-
state2[key] = value;
|
|
597
|
-
if (key === "onmount" && domNode.isConnected) {
|
|
598
|
-
value(domNode);
|
|
599
|
-
}
|
|
600
|
-
} else if (key.startsWith("on")) {
|
|
601
|
-
if (typeof value === "function") {
|
|
602
|
-
const eventName = key.slice(2).toLowerCase();
|
|
603
|
-
domNode.addEventListener(eventName, value);
|
|
604
|
-
} else if (typeof value === "string") {
|
|
605
|
-
domNode.setAttribute(key, value);
|
|
606
|
-
}
|
|
607
|
-
reactiveAttrs[key] = value;
|
|
608
|
-
} else if (typeof value === "object" && value !== null && Lightview.hooks.processAttribute) {
|
|
609
|
-
const processed = Lightview.hooks.processAttribute(domNode, key, value);
|
|
610
|
-
if (processed !== void 0) {
|
|
611
|
-
reactiveAttrs[key] = processed;
|
|
612
|
-
} else if (key === "style") {
|
|
613
|
-
Object.entries(value).forEach(([styleKey, styleValue]) => {
|
|
614
|
-
if (typeof styleValue === "function") {
|
|
615
|
-
const runner = effect(() => {
|
|
616
|
-
domNode.style[styleKey] = styleValue();
|
|
617
|
-
});
|
|
618
|
-
trackEffect(domNode, runner);
|
|
619
|
-
} else {
|
|
620
|
-
domNode.style[styleKey] = styleValue;
|
|
621
|
-
}
|
|
622
|
-
});
|
|
623
|
-
reactiveAttrs[key] = value;
|
|
624
|
-
} else {
|
|
625
|
-
setAttributeValue(domNode, key, value);
|
|
626
|
-
reactiveAttrs[key] = value;
|
|
627
|
-
}
|
|
628
|
-
} else if (typeof value === "function") {
|
|
629
|
-
const runner = effect(() => {
|
|
630
|
-
const result = value();
|
|
631
|
-
if (key === "style" && typeof result === "object") {
|
|
632
|
-
Object.assign(domNode.style, result);
|
|
633
|
-
} else {
|
|
634
|
-
setAttributeValue(domNode, key, result);
|
|
635
|
-
}
|
|
636
|
-
});
|
|
637
|
-
trackEffect(domNode, runner);
|
|
638
|
-
reactiveAttrs[key] = value;
|
|
639
|
-
} else {
|
|
640
|
-
setAttributeValue(domNode, key, value);
|
|
641
|
-
reactiveAttrs[key] = value;
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
return reactiveAttrs;
|
|
645
|
-
};
|
|
646
|
-
const processChildren = (children, targetNode, clearExisting = true) => {
|
|
647
|
-
if (clearExisting && targetNode.innerHTML !== void 0) {
|
|
648
|
-
targetNode.innerHTML = "";
|
|
649
|
-
}
|
|
650
|
-
const childElements = [];
|
|
651
|
-
const isSpecialElement = targetNode.tagName && (targetNode.tagName.toLowerCase() === "script" || targetNode.tagName.toLowerCase() === "style");
|
|
652
|
-
const flatChildren = children.flat(Infinity);
|
|
653
|
-
for (let child of flatChildren) {
|
|
654
|
-
if (Lightview.hooks.processChild && !isSpecialElement) {
|
|
655
|
-
child = Lightview.hooks.processChild(child) ?? child;
|
|
656
|
-
}
|
|
657
|
-
if (isShadowDOMMarker(child)) {
|
|
658
|
-
if (targetNode instanceof ShadowRoot) {
|
|
659
|
-
console.warn("Lightview: Cannot nest shadowDOM inside another shadowDOM");
|
|
660
|
-
continue;
|
|
661
|
-
}
|
|
662
|
-
processShadowDOM(child, targetNode);
|
|
663
|
-
continue;
|
|
664
|
-
}
|
|
665
|
-
const type = typeof child;
|
|
666
|
-
if (type === "function") {
|
|
667
|
-
const startMarker = document.createComment("lv:s");
|
|
668
|
-
const endMarker = document.createComment("lv:e");
|
|
669
|
-
targetNode.appendChild(startMarker);
|
|
670
|
-
targetNode.appendChild(endMarker);
|
|
671
|
-
let runner;
|
|
672
|
-
const update = () => {
|
|
673
|
-
while (startMarker.nextSibling && startMarker.nextSibling !== endMarker) {
|
|
674
|
-
startMarker.nextSibling.remove();
|
|
675
|
-
}
|
|
676
|
-
const val = child();
|
|
677
|
-
if (val === void 0 || val === null) return;
|
|
678
|
-
if (runner && !startMarker.isConnected) {
|
|
679
|
-
runner.stop();
|
|
680
|
-
return;
|
|
681
|
-
}
|
|
682
|
-
if (typeof val === "object" && val instanceof String) {
|
|
683
|
-
const textNode = document.createTextNode(val);
|
|
684
|
-
endMarker.parentNode.insertBefore(textNode, endMarker);
|
|
685
|
-
} else {
|
|
686
|
-
const fragment = document.createDocumentFragment();
|
|
687
|
-
const childrenToProcess = Array.isArray(val) ? val : [val];
|
|
688
|
-
processChildren(childrenToProcess, fragment, false);
|
|
689
|
-
endMarker.parentNode.insertBefore(fragment, endMarker);
|
|
690
|
-
}
|
|
691
|
-
};
|
|
692
|
-
runner = effect(update);
|
|
693
|
-
trackEffect(startMarker, runner);
|
|
694
|
-
childElements.push(child);
|
|
695
|
-
} else if (child && typeof child === "object" && child.__xpath__ && child.__static__) {
|
|
696
|
-
const textNode = document.createTextNode("");
|
|
697
|
-
textNode.__xpathExpr = child.__xpath__;
|
|
698
|
-
targetNode.appendChild(textNode);
|
|
699
|
-
childElements.push(child);
|
|
700
|
-
} else if (["string", "number", "boolean", "symbol"].includes(type) || child && type === "object" && child instanceof String) {
|
|
701
|
-
targetNode.appendChild(document.createTextNode(child));
|
|
702
|
-
childElements.push(child);
|
|
703
|
-
} else if (child instanceof Node) {
|
|
704
|
-
const node = child.domEl || child;
|
|
705
|
-
if (node instanceof HTMLElement || node instanceof SVGElement) {
|
|
706
|
-
const wrapped = wrapDomElement(node, node.tagName.toLowerCase());
|
|
707
|
-
targetNode.appendChild(node);
|
|
708
|
-
childElements.push(wrapped);
|
|
709
|
-
} else {
|
|
710
|
-
targetNode.appendChild(node);
|
|
711
|
-
childElements.push(child);
|
|
712
|
-
}
|
|
713
|
-
} else if (child && type === "object" && child.tag) {
|
|
714
|
-
const childEl = child.domEl ? child : element(child.tag, child.attributes || {}, child.children || []);
|
|
715
|
-
targetNode.appendChild(childEl.domEl);
|
|
716
|
-
childElements.push(childEl);
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
return childElements;
|
|
720
|
-
};
|
|
721
|
-
const setupChildrenInTarget = (children, targetNode) => {
|
|
722
|
-
return processChildren(children, targetNode, false);
|
|
723
|
-
};
|
|
724
|
-
const setupChildren = (children, domNode) => {
|
|
725
|
-
return processChildren(children, domNode, true);
|
|
726
|
-
};
|
|
727
|
-
const enhance = (selectorOrNode, options = {}) => {
|
|
728
|
-
const domNode = typeof selectorOrNode === "string" ? document.querySelector(selectorOrNode) : selectorOrNode;
|
|
729
|
-
const node = domNode.domEl || domNode;
|
|
730
|
-
if (!(node instanceof HTMLElement)) return null;
|
|
731
|
-
const tagName = node.tagName.toLowerCase();
|
|
732
|
-
let el = domToElement.get(node);
|
|
733
|
-
if (!el) {
|
|
734
|
-
el = wrapDomElement(node, tagName);
|
|
735
|
-
}
|
|
736
|
-
const { innerText, innerHTML, ...attrs } = options;
|
|
737
|
-
if (innerText !== void 0) {
|
|
738
|
-
if (typeof innerText === "function") {
|
|
739
|
-
effect(() => {
|
|
740
|
-
node.innerText = innerText();
|
|
741
|
-
});
|
|
742
|
-
} else {
|
|
743
|
-
node.innerText = innerText;
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
if (innerHTML !== void 0) {
|
|
747
|
-
if (typeof innerHTML === "function") {
|
|
748
|
-
effect(() => {
|
|
749
|
-
node.innerHTML = innerHTML();
|
|
750
|
-
});
|
|
751
|
-
} else {
|
|
752
|
-
node.innerHTML = innerHTML;
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
if (Object.keys(attrs).length > 0) {
|
|
756
|
-
el.attributes = attrs;
|
|
757
|
-
}
|
|
758
|
-
return el;
|
|
759
|
-
};
|
|
760
|
-
const $ = (cssSelectorOrElement, startingDomEl = document.body) => {
|
|
761
|
-
const el = typeof cssSelectorOrElement === "string" ? startingDomEl.querySelector(cssSelectorOrElement) : cssSelectorOrElement;
|
|
762
|
-
if (!el) return null;
|
|
763
|
-
Object.defineProperty(el, "content", {
|
|
764
|
-
value(child, location = "inner") {
|
|
765
|
-
location = location.toLowerCase();
|
|
766
|
-
Lightview.tags;
|
|
767
|
-
const isSpecialElement = el.tagName && (el.tagName.toLowerCase() === "script" || el.tagName.toLowerCase() === "style");
|
|
768
|
-
const array = (Array.isArray(child) ? child : [child]).map((item) => {
|
|
769
|
-
if (Lightview.hooks.processChild && !isSpecialElement) {
|
|
770
|
-
item = Lightview.hooks.processChild(item) ?? item;
|
|
771
|
-
}
|
|
772
|
-
if (item.tag && !item.domEl) {
|
|
773
|
-
return element(item.tag, item.attributes || {}, item.children || []).domEl;
|
|
774
|
-
} else {
|
|
775
|
-
return item.domEl || item;
|
|
776
|
-
}
|
|
777
|
-
});
|
|
778
|
-
const target = location === "shadow" ? el.shadowRoot || el.attachShadow({ mode: "open" }) : el;
|
|
779
|
-
if (location === "inner" || location === "shadow") {
|
|
780
|
-
target.replaceChildren(...array);
|
|
781
|
-
} else if (location === "outer") {
|
|
782
|
-
target.replaceWith(...array);
|
|
783
|
-
} else if (location === "afterbegin") {
|
|
784
|
-
target.prepend(...array);
|
|
785
|
-
} else if (location === "beforeend") {
|
|
786
|
-
target.append(...array);
|
|
787
|
-
} else {
|
|
788
|
-
array.forEach((item) => el.insertAdjacentElement(location, item));
|
|
789
|
-
}
|
|
790
|
-
return el;
|
|
791
|
-
},
|
|
792
|
-
configurable: true,
|
|
793
|
-
writable: true
|
|
794
|
-
});
|
|
795
|
-
return el;
|
|
796
|
-
};
|
|
797
|
-
const customTags = {};
|
|
798
|
-
const tags = new Proxy({}, {
|
|
799
|
-
get(_, tag) {
|
|
800
|
-
if (tag === "_customTags") return { ...customTags };
|
|
801
|
-
const wrapper = (...args) => {
|
|
802
|
-
let attributes = {};
|
|
803
|
-
let children = args;
|
|
804
|
-
const arg0 = args[0];
|
|
805
|
-
if (args.length > 0 && arg0 && typeof arg0 === "object" && !arg0.tag && !arg0.domEl && !Array.isArray(arg0)) {
|
|
806
|
-
attributes = arg0;
|
|
807
|
-
children = args.slice(1);
|
|
808
|
-
}
|
|
809
|
-
return element(customTags[tag] || tag, attributes, children);
|
|
810
|
-
};
|
|
811
|
-
if (customTags[tag]) {
|
|
812
|
-
Object.assign(wrapper, customTags[tag]);
|
|
813
|
-
}
|
|
814
|
-
return wrapper;
|
|
815
|
-
},
|
|
816
|
-
set(_, tag, value) {
|
|
817
|
-
customTags[tag] = value;
|
|
818
|
-
return true;
|
|
819
|
-
}
|
|
820
|
-
});
|
|
821
|
-
const Lightview = {
|
|
822
|
-
state,
|
|
823
|
-
getState,
|
|
824
|
-
registerSchema: (name, definition) => internals.schemas.set(name, definition),
|
|
825
|
-
signal,
|
|
826
|
-
get: signal.get,
|
|
827
|
-
computed,
|
|
828
|
-
effect,
|
|
829
|
-
registry,
|
|
830
|
-
element,
|
|
831
|
-
// do not document this
|
|
832
|
-
enhance,
|
|
833
|
-
tags,
|
|
834
|
-
$,
|
|
835
|
-
// Extension hooks
|
|
836
|
-
hooks: {
|
|
837
|
-
onNonStandardHref: null,
|
|
838
|
-
processChild: null,
|
|
839
|
-
processAttribute: null,
|
|
840
|
-
validateUrl: null,
|
|
841
|
-
validate: (value, schema) => internals.hooks.validate(value, schema)
|
|
842
|
-
},
|
|
843
|
-
// Internals exposed for extensions
|
|
844
|
-
internals: {
|
|
845
|
-
core,
|
|
846
|
-
domToElement,
|
|
847
|
-
wrapDomElement,
|
|
848
|
-
setupChildren,
|
|
849
|
-
trackEffect,
|
|
850
|
-
saveScrolls,
|
|
851
|
-
restoreScrolls,
|
|
852
|
-
localRegistries: internals.localRegistries,
|
|
853
|
-
futureSignals: internals.futureSignals,
|
|
854
|
-
schemas: internals.schemas,
|
|
855
|
-
parents: internals.parents,
|
|
856
|
-
hooks: internals.hooks
|
|
857
|
-
}
|
|
858
|
-
};
|
|
859
|
-
if (typeof module !== "undefined" && module.exports) {
|
|
860
|
-
module.exports = Lightview;
|
|
861
|
-
}
|
|
862
|
-
if (typeof window !== "undefined") {
|
|
863
|
-
globalThis.Lightview = Lightview;
|
|
864
|
-
globalThis.addEventListener("click", (e) => {
|
|
865
|
-
const path = e.composedPath();
|
|
866
|
-
const link = path.find((el) => {
|
|
867
|
-
var _a, _b;
|
|
868
|
-
return el.tagName === "A" && ((_b = (_a = el.getAttribute) == null ? void 0 : _a.call(el, "href")) == null ? void 0 : _b.startsWith("#"));
|
|
869
|
-
});
|
|
870
|
-
if (link && !e.defaultPrevented) {
|
|
871
|
-
const href = link.getAttribute("href");
|
|
872
|
-
if (href.length > 1) {
|
|
873
|
-
const id = href.slice(1);
|
|
874
|
-
const root = link.getRootNode();
|
|
875
|
-
const target = (root.getElementById ? root.getElementById(id) : null) || (root.querySelector ? root.querySelector(`#${id}`) : null);
|
|
876
|
-
if (target) {
|
|
877
|
-
e.preventDefault();
|
|
878
|
-
requestAnimationFrame(() => {
|
|
879
|
-
requestAnimationFrame(() => {
|
|
880
|
-
target.style.scrollMarginTop = "calc(var(--site-nav-height, 0px) + 2rem)";
|
|
881
|
-
target.scrollIntoView({ behavior: "smooth", block: "start", inline: "start" });
|
|
882
|
-
});
|
|
883
|
-
});
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
if (Lightview.hooks.onNonStandardHref) {
|
|
888
|
-
Lightview.hooks.onNonStandardHref(e);
|
|
889
|
-
}
|
|
890
|
-
});
|
|
891
|
-
if (typeof MutationObserver !== "undefined") {
|
|
892
|
-
const walkNodes = (node, fn) => {
|
|
893
|
-
var _a;
|
|
894
|
-
fn(node);
|
|
895
|
-
(_a = node.childNodes) == null ? void 0 : _a.forEach((n) => walkNodes(n, fn));
|
|
896
|
-
if (node.shadowRoot) walkNodes(node.shadowRoot, fn);
|
|
897
|
-
};
|
|
898
|
-
const cleanupNode = (node) => walkNodes(node, (n) => {
|
|
899
|
-
var _a, _b;
|
|
900
|
-
const s = nodeState.get(n);
|
|
901
|
-
if (s) {
|
|
902
|
-
(_a = s.effects) == null ? void 0 : _a.forEach((e) => e.stop());
|
|
903
|
-
(_b = s.onunmount) == null ? void 0 : _b.call(s, n);
|
|
904
|
-
nodeState.delete(n);
|
|
905
|
-
}
|
|
906
|
-
});
|
|
907
|
-
const mountNode = (node) => walkNodes(node, (n) => {
|
|
908
|
-
var _a, _b;
|
|
909
|
-
(_b = (_a = nodeState.get(n)) == null ? void 0 : _a.onmount) == null ? void 0 : _b.call(_a, n);
|
|
910
|
-
});
|
|
911
|
-
const observer = new MutationObserver((mutations) => {
|
|
912
|
-
mutations.forEach((mutation) => {
|
|
913
|
-
mutation.removedNodes.forEach(cleanupNode);
|
|
914
|
-
mutation.addedNodes.forEach(mountNode);
|
|
915
|
-
});
|
|
916
|
-
});
|
|
917
|
-
const startObserving = () => {
|
|
918
|
-
if (document.body) {
|
|
919
|
-
observer.observe(document.body, {
|
|
920
|
-
childList: true,
|
|
921
|
-
subtree: true
|
|
922
|
-
});
|
|
923
|
-
}
|
|
924
|
-
};
|
|
925
|
-
if (document.readyState === "loading") {
|
|
926
|
-
document.addEventListener("DOMContentLoaded", startObserving);
|
|
927
|
-
} else {
|
|
928
|
-
startObserving();
|
|
929
|
-
}
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
})();
|