gyosjs 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/gyos.auto.esm.js +120 -61
- package/dist/gyos.auto.esm.js.map +1 -1
- package/dist/gyos.auto.js +120 -61
- package/dist/gyos.auto.js.map +1 -1
- package/dist/gyos.auto.min.js +2 -2
- package/dist/gyos.csp.auto.esm.js +120 -61
- package/dist/gyos.csp.auto.esm.js.map +1 -1
- package/dist/gyos.csp.auto.js +120 -61
- package/dist/gyos.csp.auto.js.map +1 -1
- package/dist/gyos.csp.auto.min.js +2 -2
- package/dist/gyos.csp.esm.js +120 -61
- package/dist/gyos.csp.esm.js.map +1 -1
- package/dist/gyos.csp.js +120 -61
- package/dist/gyos.csp.js.map +1 -1
- package/dist/gyos.csp.min.js +2 -2
- package/dist/gyos.esm.js +120 -61
- package/dist/gyos.esm.js.map +1 -1
- package/dist/gyos.js +120 -61
- package/dist/gyos.js.map +1 -1
- package/dist/gyos.min.js +2 -2
- package/dist/reactivity/signal.d.ts.map +1 -1
- package/package.json +5 -4
package/dist/gyos.csp.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* GyosJS v0.4.
|
|
2
|
+
* GyosJS v0.4.1
|
|
3
3
|
* (c) 2026
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -6846,10 +6846,35 @@ function hasStructuralParent(el) {
|
|
|
6846
6846
|
* count.value++; // Triggers effect
|
|
6847
6847
|
* ```
|
|
6848
6848
|
*/
|
|
6849
|
-
/**
|
|
6850
|
-
* Current effect being tracked
|
|
6851
|
-
*/
|
|
6852
6849
|
let currentEffect = null;
|
|
6850
|
+
function track(source) {
|
|
6851
|
+
if (!currentEffect)
|
|
6852
|
+
return;
|
|
6853
|
+
source.subscribers.add(currentEffect);
|
|
6854
|
+
currentEffect.__dependencies?.add(source.subscribers);
|
|
6855
|
+
currentEffect.__versions?.set(source, source.version);
|
|
6856
|
+
}
|
|
6857
|
+
function dependenciesChanged(versions) {
|
|
6858
|
+
return untrack(() => {
|
|
6859
|
+
for (const [source, version] of versions) {
|
|
6860
|
+
source.refresh?.();
|
|
6861
|
+
if (source.version !== version)
|
|
6862
|
+
return true;
|
|
6863
|
+
}
|
|
6864
|
+
return false;
|
|
6865
|
+
});
|
|
6866
|
+
}
|
|
6867
|
+
// Invalidate derived caches synchronously; only user effects are deferred.
|
|
6868
|
+
function notifySubscribers(subscribers) {
|
|
6869
|
+
for (const sub of Array.from(subscribers)) {
|
|
6870
|
+
if (sub.__invalidate)
|
|
6871
|
+
sub();
|
|
6872
|
+
else if (isBatching)
|
|
6873
|
+
batchedEffects.add(sub);
|
|
6874
|
+
else
|
|
6875
|
+
queueEffect(sub);
|
|
6876
|
+
}
|
|
6877
|
+
}
|
|
6853
6878
|
// Simple counter for debug-friendly IDs
|
|
6854
6879
|
let signalIdCounter = 0;
|
|
6855
6880
|
const WARN_SUBSCRIBERS = () => typeof window !== 'undefined' && window.GYOS_DEBUG_WARN_SUBSCRIBERS;
|
|
@@ -6887,6 +6912,9 @@ function flushEffectQueue() {
|
|
|
6887
6912
|
}
|
|
6888
6913
|
});
|
|
6889
6914
|
isFlushingQueue = false;
|
|
6915
|
+
// A plain subscribe callback can enqueue more work without entering effect().
|
|
6916
|
+
if (effectQueue.size > 0)
|
|
6917
|
+
queueMicrotask(flushEffectQueue);
|
|
6890
6918
|
}
|
|
6891
6919
|
/**
|
|
6892
6920
|
* Queue an effect for execution in next microtask
|
|
@@ -6945,17 +6973,14 @@ function signal(initialValue, debugOrOptions) {
|
|
|
6945
6973
|
const debugId = ++signalIdCounter;
|
|
6946
6974
|
let value = initialValue;
|
|
6947
6975
|
const subscribers = new Set();
|
|
6976
|
+
const source = { subscribers, version: 0 };
|
|
6948
6977
|
let warnedSubscribers = false;
|
|
6949
6978
|
const read = () => {
|
|
6950
6979
|
// Track dependency
|
|
6951
6980
|
if (currentEffect) {
|
|
6952
|
-
|
|
6953
|
-
|
|
6954
|
-
|
|
6955
|
-
// Store the subscribers Set in the effect's dependencies for cleanup
|
|
6956
|
-
if (currentEffect.__dependencies) {
|
|
6957
|
-
currentEffect.__dependencies.add(subscribers);
|
|
6958
|
-
}
|
|
6981
|
+
const wasSubscribed = subscribers.has(currentEffect);
|
|
6982
|
+
track(source);
|
|
6983
|
+
if (!wasSubscribed) {
|
|
6959
6984
|
if (DEBUG_VERBOSE()) {
|
|
6960
6985
|
console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Added subscriber, total:', subscribers.size);
|
|
6961
6986
|
}
|
|
@@ -6974,18 +6999,13 @@ function signal(initialValue, debugOrOptions) {
|
|
|
6974
6999
|
// For objects/arrays, check if it's actually the same reference
|
|
6975
7000
|
// Deep equality is expensive, let user handle it
|
|
6976
7001
|
value = newValue;
|
|
7002
|
+
source.version++;
|
|
6977
7003
|
DEBUG_VERBOSE() && console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Value changed to:', newValue);
|
|
6978
7004
|
notify();
|
|
6979
7005
|
};
|
|
6980
7006
|
const notify = () => {
|
|
6981
7007
|
DEBUG_VERBOSE() && console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Notifying', subscribers.size, 'subscribers');
|
|
6982
|
-
|
|
6983
|
-
subscribers.forEach(sub => batchedEffects.add(sub));
|
|
6984
|
-
}
|
|
6985
|
-
else {
|
|
6986
|
-
// Always queue effects to prevent cascading updates
|
|
6987
|
-
subscribers.forEach(sub => queueEffect(sub));
|
|
6988
|
-
}
|
|
7008
|
+
notifySubscribers(subscribers);
|
|
6989
7009
|
};
|
|
6990
7010
|
// Create callable signal (like Angular/SolidJS)
|
|
6991
7011
|
// Call without args = read, call with arg = write
|
|
@@ -7020,8 +7040,16 @@ function signal(initialValue, debugOrOptions) {
|
|
|
7020
7040
|
},
|
|
7021
7041
|
subscribe: {
|
|
7022
7042
|
value: function (fn) {
|
|
7023
|
-
|
|
7024
|
-
|
|
7043
|
+
let active = true;
|
|
7044
|
+
const callback = () => { if (active)
|
|
7045
|
+
untrack(fn); };
|
|
7046
|
+
subscribers.add(callback);
|
|
7047
|
+
return () => {
|
|
7048
|
+
active = false;
|
|
7049
|
+
subscribers.delete(callback);
|
|
7050
|
+
effectQueue.delete(callback);
|
|
7051
|
+
batchedEffects.delete(callback);
|
|
7052
|
+
};
|
|
7025
7053
|
},
|
|
7026
7054
|
enumerable: true,
|
|
7027
7055
|
configurable: true
|
|
@@ -7081,49 +7109,60 @@ function computed(fn) {
|
|
|
7081
7109
|
let value;
|
|
7082
7110
|
let isDirty = true;
|
|
7083
7111
|
let isFirstRun = true;
|
|
7112
|
+
let computing = false;
|
|
7084
7113
|
const subscribers = new Set();
|
|
7085
|
-
|
|
7114
|
+
const dependencies = new Set();
|
|
7115
|
+
const versions = new Map();
|
|
7116
|
+
const source = { subscribers, version: 0, refresh: () => compute() };
|
|
7117
|
+
const invalidate = () => {
|
|
7118
|
+
// A later batched write must also move already queued consumers into
|
|
7119
|
+
// the batch, even when an earlier ordinary write dirtied this cache.
|
|
7120
|
+
if (isDirty && !isBatching)
|
|
7121
|
+
return;
|
|
7122
|
+
isDirty = true;
|
|
7123
|
+
notifySubscribers(subscribers);
|
|
7124
|
+
};
|
|
7125
|
+
invalidate.__invalidate = true;
|
|
7126
|
+
invalidate.__dependencies = dependencies;
|
|
7127
|
+
invalidate.__versions = versions;
|
|
7086
7128
|
const compute = () => {
|
|
7087
7129
|
if (!isDirty && !isFirstRun)
|
|
7088
7130
|
return;
|
|
7089
|
-
|
|
7090
|
-
|
|
7091
|
-
|
|
7092
|
-
|
|
7093
|
-
|
|
7094
|
-
|
|
7095
|
-
|
|
7096
|
-
|
|
7097
|
-
|
|
7098
|
-
value = newValue;
|
|
7099
|
-
isFirstRun = false;
|
|
7100
|
-
isDirty = false;
|
|
7101
|
-
// Notify subscribers
|
|
7102
|
-
if (!isBatching) {
|
|
7103
|
-
subscribers.forEach(sub => queueEffect(sub));
|
|
7104
|
-
}
|
|
7105
|
-
else {
|
|
7106
|
-
subscribers.forEach(sub => batchedEffects.add(sub));
|
|
7107
|
-
}
|
|
7108
|
-
}
|
|
7131
|
+
if (computing)
|
|
7132
|
+
throw new Error('[Computed] Circular dependency');
|
|
7133
|
+
computing = true;
|
|
7134
|
+
const previousEffect = currentEffect;
|
|
7135
|
+
try {
|
|
7136
|
+
// A dirty upstream computed may still resolve to its previous value.
|
|
7137
|
+
if (!isFirstRun && !dependenciesChanged(versions)) {
|
|
7138
|
+
isDirty = false;
|
|
7139
|
+
return;
|
|
7109
7140
|
}
|
|
7110
|
-
|
|
7111
|
-
|
|
7112
|
-
|
|
7141
|
+
dependencies.forEach(dependency => dependency.delete(invalidate));
|
|
7142
|
+
dependencies.clear();
|
|
7143
|
+
versions.clear();
|
|
7144
|
+
currentEffect = invalidate;
|
|
7145
|
+
const nextValue = fn();
|
|
7146
|
+
if (isFirstRun || !Object.is(value, nextValue)) {
|
|
7147
|
+
value = nextValue;
|
|
7148
|
+
source.version++;
|
|
7113
7149
|
}
|
|
7114
|
-
|
|
7115
|
-
|
|
7150
|
+
isFirstRun = false;
|
|
7151
|
+
isDirty = false;
|
|
7152
|
+
}
|
|
7153
|
+
catch (error) {
|
|
7154
|
+
// Preserve error isolation and the last successful value.
|
|
7155
|
+
console.error('[Computed] Error in computation:', error);
|
|
7156
|
+
isDirty = false;
|
|
7157
|
+
}
|
|
7158
|
+
finally {
|
|
7159
|
+
currentEffect = previousEffect;
|
|
7160
|
+
computing = false;
|
|
7161
|
+
}
|
|
7116
7162
|
};
|
|
7117
7163
|
const read = () => {
|
|
7118
|
-
|
|
7119
|
-
|
|
7120
|
-
// Track dependency
|
|
7121
|
-
if (currentEffect && !subscribers.has(currentEffect)) {
|
|
7122
|
-
subscribers.add(currentEffect);
|
|
7123
|
-
if (currentEffect.__dependencies) {
|
|
7124
|
-
currentEffect.__dependencies.add(subscribers);
|
|
7125
|
-
}
|
|
7126
|
-
}
|
|
7164
|
+
compute();
|
|
7165
|
+
track(source);
|
|
7127
7166
|
return value;
|
|
7128
7167
|
};
|
|
7129
7168
|
// Create callable computed (read-only)
|
|
@@ -7148,8 +7187,14 @@ function computed(fn) {
|
|
|
7148
7187
|
},
|
|
7149
7188
|
subscribe: {
|
|
7150
7189
|
value: function (fn) {
|
|
7151
|
-
|
|
7152
|
-
|
|
7190
|
+
// Establish dependencies even if subscribe() is the first access.
|
|
7191
|
+
let first = true;
|
|
7192
|
+
return effect(() => {
|
|
7193
|
+
read();
|
|
7194
|
+
if (!first)
|
|
7195
|
+
untrack(fn);
|
|
7196
|
+
first = false;
|
|
7197
|
+
});
|
|
7153
7198
|
},
|
|
7154
7199
|
enumerable: true,
|
|
7155
7200
|
configurable: true
|
|
@@ -7200,11 +7245,15 @@ function computed(fn) {
|
|
|
7200
7245
|
*/
|
|
7201
7246
|
function effect(fn) {
|
|
7202
7247
|
let cleanup;
|
|
7203
|
-
|
|
7248
|
+
const dependencies = new Set();
|
|
7249
|
+
const versions = new Map();
|
|
7204
7250
|
let active = true;
|
|
7251
|
+
let initialized = false;
|
|
7205
7252
|
const execute = () => {
|
|
7206
7253
|
if (!active)
|
|
7207
7254
|
return;
|
|
7255
|
+
if (initialized && !dependenciesChanged(versions))
|
|
7256
|
+
return;
|
|
7208
7257
|
// Prevent recursive execution - if already running, skip
|
|
7209
7258
|
if (runningEffects.has(execute)) {
|
|
7210
7259
|
DEBUG() && console.warn('[Effect] Skipped recursive execution');
|
|
@@ -7219,10 +7268,13 @@ function effect(fn) {
|
|
|
7219
7268
|
});
|
|
7220
7269
|
DEBUG() && console.log('[Effect] Cleaned up dependencies, count:', dependencies.size);
|
|
7221
7270
|
dependencies.clear();
|
|
7271
|
+
versions.clear();
|
|
7222
7272
|
// Clean up previous run
|
|
7223
7273
|
if (cleanup) {
|
|
7274
|
+
const previousCleanup = cleanup;
|
|
7275
|
+
cleanup = undefined;
|
|
7224
7276
|
try {
|
|
7225
|
-
|
|
7277
|
+
untrack(previousCleanup);
|
|
7226
7278
|
}
|
|
7227
7279
|
catch (error) {
|
|
7228
7280
|
console.error('[Effect] Error in cleanup:', error);
|
|
@@ -7233,6 +7285,7 @@ function effect(fn) {
|
|
|
7233
7285
|
currentEffect = execute;
|
|
7234
7286
|
// Store dependencies for cleanup
|
|
7235
7287
|
execute.__dependencies = dependencies;
|
|
7288
|
+
execute.__versions = versions;
|
|
7236
7289
|
try {
|
|
7237
7290
|
const nextCleanup = fn();
|
|
7238
7291
|
cleanup = typeof nextCleanup === 'function' ? nextCleanup : undefined;
|
|
@@ -7242,6 +7295,7 @@ function effect(fn) {
|
|
|
7242
7295
|
// Don't throw - allow other effects to continue
|
|
7243
7296
|
}
|
|
7244
7297
|
finally {
|
|
7298
|
+
initialized = true;
|
|
7245
7299
|
currentEffect = prevEffect;
|
|
7246
7300
|
effectDepth--;
|
|
7247
7301
|
runningEffects.delete(execute);
|
|
@@ -7258,14 +7312,17 @@ function effect(fn) {
|
|
|
7258
7312
|
if (!active)
|
|
7259
7313
|
return;
|
|
7260
7314
|
active = false;
|
|
7315
|
+
effectQueue.delete(execute);
|
|
7316
|
+
batchedEffects.delete(execute);
|
|
7261
7317
|
// Remove from all dependencies
|
|
7262
7318
|
dependencies.forEach(depSet => {
|
|
7263
7319
|
depSet.delete(execute);
|
|
7264
7320
|
});
|
|
7265
7321
|
dependencies.clear();
|
|
7322
|
+
versions.clear();
|
|
7266
7323
|
if (cleanup) {
|
|
7267
7324
|
try {
|
|
7268
|
-
cleanup
|
|
7325
|
+
untrack(cleanup);
|
|
7269
7326
|
}
|
|
7270
7327
|
catch (error) {
|
|
7271
7328
|
console.error('[Effect] Error in final cleanup:', error);
|
|
@@ -7325,6 +7382,8 @@ function batch(fn) {
|
|
|
7325
7382
|
const effects = Array.from(batchedEffects);
|
|
7326
7383
|
batchedEffects.clear();
|
|
7327
7384
|
effects.forEach(effect => {
|
|
7385
|
+
// This batch also settles any earlier queued write to this observer.
|
|
7386
|
+
effectQueue.delete(effect);
|
|
7328
7387
|
try {
|
|
7329
7388
|
effect();
|
|
7330
7389
|
}
|
|
@@ -15355,7 +15414,7 @@ const Gyos = {
|
|
|
15355
15414
|
portalCreate,
|
|
15356
15415
|
portalDestroy,
|
|
15357
15416
|
setCspNonce,
|
|
15358
|
-
version: '0.4.
|
|
15417
|
+
version: '0.4.1'
|
|
15359
15418
|
};
|
|
15360
15419
|
|
|
15361
15420
|
setExpressionRuntime(cspExpressionRuntime);
|