streetui 2.5.0 → 2.7.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/dist/testing.cjs CHANGED
@@ -971,6 +971,13 @@ function applyProp(dom, element, name, value) {
971
971
  }
972
972
  return;
973
973
  }
974
+ if (name.startsWith("style.")) {
975
+ const el = element;
976
+ const prop = name.slice("style.".length);
977
+ if (value === null || value === void 0) el.style.removeProperty(prop);
978
+ else el.style.setProperty(prop, String(value));
979
+ return;
980
+ }
974
981
  if (value === null || value === void 0 || value === false) {
975
982
  dom.removeAttribute(element, name);
976
983
  return;
@@ -1021,6 +1028,11 @@ var TAG_MAP = {
1021
1028
  "list-item": "li",
1022
1029
  image: "img",
1023
1030
  link: "a",
1031
+ // A `code()` node renders as a semantic `<pre>` outer element; the mount/
1032
+ // hydrate branches add a single inner `<code>` holding the escaped source
1033
+ // (mirrors how `text` renders `<span>` + an inner text node). One graph
1034
+ // node → one outer element preserves positional hydration.
1035
+ code: "pre",
1024
1036
  component: "div",
1025
1037
  slot: "div",
1026
1038
  fragment: "div",
@@ -1739,6 +1751,23 @@ function mountNode(ctx, graphNode, parentDom) {
1739
1751
  dom.appendChild(parentDom, el2);
1740
1752
  return instance2;
1741
1753
  }
1754
+ if (graphNode.type === "code") {
1755
+ const source = String(graphNode.getProp("text") ?? "");
1756
+ const pre = dom.createElement("pre");
1757
+ const codeEl = dom.createElement("code");
1758
+ const textNode = dom.createTextNode(source);
1759
+ dom.appendChild(codeEl, textNode);
1760
+ dom.appendChild(pre, codeEl);
1761
+ applyNodeProps(ctx, graphNode, pre);
1762
+ const instance2 = new NodeInstance(graphNode, pre);
1763
+ ctx.instances.set(graphNode.id, instance2);
1764
+ wireEvents(dom, graph, graphNode, pre, instance2);
1765
+ if (graphNode.stateRefs.length !== 0) {
1766
+ wireSignalBindings(ctx, graphNode, instance2, textUpdate(dom, pre, textNode));
1767
+ }
1768
+ dom.appendChild(parentDom, pre);
1769
+ return instance2;
1770
+ }
1742
1771
  if (graphNode.type === "link") {
1743
1772
  const el2 = dom.createElement("a");
1744
1773
  const href = graphNode.getProp("href");
@@ -2041,6 +2070,188 @@ function wireComponentBehavior(ctx, graphNode, instance) {
2041
2070
  for (const cleanup of fn()) instance.trackCleanup(cleanup);
2042
2071
  }
2043
2072
 
2073
+ // ../state/src/signal.ts
2074
+ var _activeConsumer = null;
2075
+ function withConsumer(consumer, fn) {
2076
+ const prev = _activeConsumer;
2077
+ _activeConsumer = consumer;
2078
+ try {
2079
+ return fn();
2080
+ } finally {
2081
+ _activeConsumer = prev;
2082
+ }
2083
+ }
2084
+ var _batchDepth = 0;
2085
+ var _pendingFlushes = /* @__PURE__ */ new Map();
2086
+ function _enqueueBatchFlush(sig, value) {
2087
+ _pendingFlushes.set(sig, { signal: sig, value });
2088
+ }
2089
+ var Signal = class {
2090
+ _value;
2091
+ _subscribers = /* @__PURE__ */ new Set();
2092
+ _consumers = /* @__PURE__ */ new Set();
2093
+ constructor(initial) {
2094
+ this._value = initial;
2095
+ }
2096
+ get() {
2097
+ if (_activeConsumer !== null) {
2098
+ this._consumers.add(_activeConsumer);
2099
+ _activeConsumer._addSource(this);
2100
+ }
2101
+ return this._value;
2102
+ }
2103
+ peek() {
2104
+ return this._value;
2105
+ }
2106
+ set(value) {
2107
+ if (Object.is(this._value, value)) return;
2108
+ this._value = value;
2109
+ if (_batchDepth > 0) {
2110
+ _enqueueBatchFlush(this, value);
2111
+ } else {
2112
+ this._flush(value);
2113
+ }
2114
+ }
2115
+ update(fn) {
2116
+ this.set(fn(this._value));
2117
+ }
2118
+ subscribe(fn) {
2119
+ this._subscribers.add(fn);
2120
+ return () => {
2121
+ this._subscribers.delete(fn);
2122
+ };
2123
+ }
2124
+ _removeConsumer(consumer) {
2125
+ this._consumers.delete(consumer);
2126
+ }
2127
+ /**
2128
+ * Called by the batch machinery after the batch has completed.
2129
+ * Notifies subscribers with the final coalesced value.
2130
+ */
2131
+ _flushBatch(value) {
2132
+ this._flush(value);
2133
+ }
2134
+ _flush(value) {
2135
+ for (const sub of [...this._subscribers]) sub(value);
2136
+ for (const consumer of [...this._consumers]) consumer._invalidate();
2137
+ }
2138
+ /**
2139
+ * @internal DevTools inspection only. The number of live observers
2140
+ * (direct subscribers plus derived/effect consumers). Read-only; never
2141
+ * mutates reactive state.
2142
+ */
2143
+ _observerCount() {
2144
+ return this._subscribers.size + this._consumers.size;
2145
+ }
2146
+ };
2147
+ var DerivedSignal = class {
2148
+ _value = void 0;
2149
+ _dirty = true;
2150
+ _disposed = false;
2151
+ _fn;
2152
+ _subscribers = /* @__PURE__ */ new Set();
2153
+ /** All upstream sources this derived currently reads from. */
2154
+ _sources = /* @__PURE__ */ new Set();
2155
+ /** Downstream consumers that depend on this derived. */
2156
+ _consumers = /* @__PURE__ */ new Set();
2157
+ constructor(fn) {
2158
+ this._fn = fn;
2159
+ }
2160
+ get() {
2161
+ if (_activeConsumer !== null) {
2162
+ this._consumers.add(_activeConsumer);
2163
+ _activeConsumer._addSource(this);
2164
+ }
2165
+ if (this._dirty) this._recompute();
2166
+ return this._value;
2167
+ }
2168
+ peek() {
2169
+ if (this._dirty) this._recompute();
2170
+ return this._value;
2171
+ }
2172
+ subscribe(fn) {
2173
+ if (this._dirty) this._recompute();
2174
+ this._subscribers.add(fn);
2175
+ return () => {
2176
+ this._subscribers.delete(fn);
2177
+ };
2178
+ }
2179
+ _addSource(src) {
2180
+ this._sources.add(src);
2181
+ }
2182
+ _removeConsumer(consumer) {
2183
+ this._consumers.delete(consumer);
2184
+ }
2185
+ _invalidate() {
2186
+ if (this._disposed) return;
2187
+ this._dirty = true;
2188
+ const newVal = this.peek();
2189
+ for (const sub of [...this._subscribers]) sub(newVal);
2190
+ for (const consumer of [...this._consumers]) consumer._invalidate();
2191
+ }
2192
+ _recompute() {
2193
+ for (const src of this._sources) src._removeConsumer(this);
2194
+ this._sources.clear();
2195
+ this._value = withConsumer(this, this._fn);
2196
+ this._dirty = false;
2197
+ }
2198
+ dispose() {
2199
+ this._disposed = true;
2200
+ for (const src of this._sources) src._removeConsumer(this);
2201
+ this._sources.clear();
2202
+ this._subscribers.clear();
2203
+ this._consumers.clear();
2204
+ }
2205
+ /**
2206
+ * @internal DevTools inspection only. Live observers (subscribers plus
2207
+ * downstream consumers). Read-only.
2208
+ */
2209
+ _observerCount() {
2210
+ return this._subscribers.size + this._consumers.size;
2211
+ }
2212
+ };
2213
+ var Effect = class {
2214
+ _fn;
2215
+ _cleanup = void 0;
2216
+ _disposed = false;
2217
+ _sources = /* @__PURE__ */ new Set();
2218
+ constructor(fn) {
2219
+ this._fn = fn;
2220
+ this._run();
2221
+ }
2222
+ _addSource(src) {
2223
+ this._sources.add(src);
2224
+ }
2225
+ _invalidate() {
2226
+ if (this._disposed) return;
2227
+ this._run();
2228
+ }
2229
+ _run() {
2230
+ for (const src of this._sources) src._removeConsumer(this);
2231
+ this._sources.clear();
2232
+ if (typeof this._cleanup === "function") this._cleanup();
2233
+ const result = withConsumer(this, this._fn);
2234
+ this._cleanup = typeof result === "function" ? result : void 0;
2235
+ }
2236
+ dispose() {
2237
+ this._disposed = true;
2238
+ for (const src of this._sources) src._removeConsumer(this);
2239
+ this._sources.clear();
2240
+ if (typeof this._cleanup === "function") this._cleanup();
2241
+ this._cleanup = void 0;
2242
+ }
2243
+ };
2244
+ function signal(initial) {
2245
+ return new Signal(initial);
2246
+ }
2247
+ function derived(fn) {
2248
+ return new DerivedSignal(fn);
2249
+ }
2250
+ function effect(fn) {
2251
+ const e = new Effect(fn);
2252
+ return () => e.dispose();
2253
+ }
2254
+
2044
2255
  // ../renderer/src/hydration-diagnostics.ts
2045
2256
  function formatHydrationDiagnostic(d) {
2046
2257
  const at = ` at ${d.path}`;
@@ -2120,6 +2331,27 @@ function hydrateNode(ctx, graphNode, domNode, path) {
2120
2331
  }
2121
2332
  return instance;
2122
2333
  }
2334
+ case "code": {
2335
+ let codeEl = dom.firstChild(domNode);
2336
+ if (codeEl === null || dom.isTextNode(codeEl)) {
2337
+ const createdCode = dom.createElement("code");
2338
+ dom.appendChild(domNode, createdCode);
2339
+ codeEl = createdCode;
2340
+ }
2341
+ let textNode = dom.firstChild(codeEl);
2342
+ if (textNode === null || !dom.isTextNode(textNode)) {
2343
+ const created = dom.createTextNode(String(graphNode.getProp("text") ?? ""));
2344
+ dom.appendChild(codeEl, created);
2345
+ textNode = created;
2346
+ }
2347
+ const instance = new NodeInstance(graphNode, domNode);
2348
+ ctx.instances.set(graphNode.id, instance);
2349
+ wireEvents(dom, graph, graphNode, domNode, instance);
2350
+ if (graphNode.stateRefs.length !== 0) {
2351
+ wireSignalBindings(ctx, graphNode, instance, textUpdate(dom, domNode, textNode));
2352
+ }
2353
+ return instance;
2354
+ }
2123
2355
  case "image":
2124
2356
  case "link": {
2125
2357
  const instance = new NodeInstance(graphNode, domNode);
@@ -2271,6 +2503,8 @@ function expectedTag(ctx, graphNode) {
2271
2503
  return "img";
2272
2504
  case "link":
2273
2505
  return "a";
2506
+ case "code":
2507
+ return "pre";
2274
2508
  case "button":
2275
2509
  return "button";
2276
2510
  default:
@@ -2980,188 +3214,6 @@ function resolveHead(config) {
2980
3214
  return { entries };
2981
3215
  }
2982
3216
 
2983
- // ../state/src/signal.ts
2984
- var _activeConsumer = null;
2985
- function withConsumer(consumer, fn) {
2986
- const prev = _activeConsumer;
2987
- _activeConsumer = consumer;
2988
- try {
2989
- return fn();
2990
- } finally {
2991
- _activeConsumer = prev;
2992
- }
2993
- }
2994
- var _batchDepth = 0;
2995
- var _pendingFlushes = /* @__PURE__ */ new Map();
2996
- function _enqueueBatchFlush(sig, value) {
2997
- _pendingFlushes.set(sig, { signal: sig, value });
2998
- }
2999
- var Signal = class {
3000
- _value;
3001
- _subscribers = /* @__PURE__ */ new Set();
3002
- _consumers = /* @__PURE__ */ new Set();
3003
- constructor(initial) {
3004
- this._value = initial;
3005
- }
3006
- get() {
3007
- if (_activeConsumer !== null) {
3008
- this._consumers.add(_activeConsumer);
3009
- _activeConsumer._addSource(this);
3010
- }
3011
- return this._value;
3012
- }
3013
- peek() {
3014
- return this._value;
3015
- }
3016
- set(value) {
3017
- if (Object.is(this._value, value)) return;
3018
- this._value = value;
3019
- if (_batchDepth > 0) {
3020
- _enqueueBatchFlush(this, value);
3021
- } else {
3022
- this._flush(value);
3023
- }
3024
- }
3025
- update(fn) {
3026
- this.set(fn(this._value));
3027
- }
3028
- subscribe(fn) {
3029
- this._subscribers.add(fn);
3030
- return () => {
3031
- this._subscribers.delete(fn);
3032
- };
3033
- }
3034
- _removeConsumer(consumer) {
3035
- this._consumers.delete(consumer);
3036
- }
3037
- /**
3038
- * Called by the batch machinery after the batch has completed.
3039
- * Notifies subscribers with the final coalesced value.
3040
- */
3041
- _flushBatch(value) {
3042
- this._flush(value);
3043
- }
3044
- _flush(value) {
3045
- for (const sub of [...this._subscribers]) sub(value);
3046
- for (const consumer of [...this._consumers]) consumer._invalidate();
3047
- }
3048
- /**
3049
- * @internal DevTools inspection only. The number of live observers
3050
- * (direct subscribers plus derived/effect consumers). Read-only; never
3051
- * mutates reactive state.
3052
- */
3053
- _observerCount() {
3054
- return this._subscribers.size + this._consumers.size;
3055
- }
3056
- };
3057
- var DerivedSignal = class {
3058
- _value = void 0;
3059
- _dirty = true;
3060
- _disposed = false;
3061
- _fn;
3062
- _subscribers = /* @__PURE__ */ new Set();
3063
- /** All upstream sources this derived currently reads from. */
3064
- _sources = /* @__PURE__ */ new Set();
3065
- /** Downstream consumers that depend on this derived. */
3066
- _consumers = /* @__PURE__ */ new Set();
3067
- constructor(fn) {
3068
- this._fn = fn;
3069
- }
3070
- get() {
3071
- if (_activeConsumer !== null) {
3072
- this._consumers.add(_activeConsumer);
3073
- _activeConsumer._addSource(this);
3074
- }
3075
- if (this._dirty) this._recompute();
3076
- return this._value;
3077
- }
3078
- peek() {
3079
- if (this._dirty) this._recompute();
3080
- return this._value;
3081
- }
3082
- subscribe(fn) {
3083
- if (this._dirty) this._recompute();
3084
- this._subscribers.add(fn);
3085
- return () => {
3086
- this._subscribers.delete(fn);
3087
- };
3088
- }
3089
- _addSource(src) {
3090
- this._sources.add(src);
3091
- }
3092
- _removeConsumer(consumer) {
3093
- this._consumers.delete(consumer);
3094
- }
3095
- _invalidate() {
3096
- if (this._disposed) return;
3097
- this._dirty = true;
3098
- const newVal = this.peek();
3099
- for (const sub of [...this._subscribers]) sub(newVal);
3100
- for (const consumer of [...this._consumers]) consumer._invalidate();
3101
- }
3102
- _recompute() {
3103
- for (const src of this._sources) src._removeConsumer(this);
3104
- this._sources.clear();
3105
- this._value = withConsumer(this, this._fn);
3106
- this._dirty = false;
3107
- }
3108
- dispose() {
3109
- this._disposed = true;
3110
- for (const src of this._sources) src._removeConsumer(this);
3111
- this._sources.clear();
3112
- this._subscribers.clear();
3113
- this._consumers.clear();
3114
- }
3115
- /**
3116
- * @internal DevTools inspection only. Live observers (subscribers plus
3117
- * downstream consumers). Read-only.
3118
- */
3119
- _observerCount() {
3120
- return this._subscribers.size + this._consumers.size;
3121
- }
3122
- };
3123
- var Effect = class {
3124
- _fn;
3125
- _cleanup = void 0;
3126
- _disposed = false;
3127
- _sources = /* @__PURE__ */ new Set();
3128
- constructor(fn) {
3129
- this._fn = fn;
3130
- this._run();
3131
- }
3132
- _addSource(src) {
3133
- this._sources.add(src);
3134
- }
3135
- _invalidate() {
3136
- if (this._disposed) return;
3137
- this._run();
3138
- }
3139
- _run() {
3140
- for (const src of this._sources) src._removeConsumer(this);
3141
- this._sources.clear();
3142
- if (typeof this._cleanup === "function") this._cleanup();
3143
- const result = withConsumer(this, this._fn);
3144
- this._cleanup = typeof result === "function" ? result : void 0;
3145
- }
3146
- dispose() {
3147
- this._disposed = true;
3148
- for (const src of this._sources) src._removeConsumer(this);
3149
- this._sources.clear();
3150
- if (typeof this._cleanup === "function") this._cleanup();
3151
- this._cleanup = void 0;
3152
- }
3153
- };
3154
- function signal(initial) {
3155
- return new Signal(initial);
3156
- }
3157
- function derived(fn) {
3158
- return new DerivedSignal(fn);
3159
- }
3160
- function effect(fn) {
3161
- const e = new Effect(fn);
3162
- return () => e.dispose();
3163
- }
3164
-
3165
3217
  // ../dsl/src/builders.ts
3166
3218
  function isSignal(v) {
3167
3219
  return v !== null && typeof v === "object" && typeof v["get"] === "function" && typeof v["subscribe"] === "function";
@@ -3386,6 +3438,16 @@ var ContentBuilderBase = class {
3386
3438
  node.addEvent({ type: "click", handlerKey });
3387
3439
  }
3388
3440
  }
3441
+ code(source, options = {}) {
3442
+ const props = {};
3443
+ if (options.language !== void 0) props["data-language"] = options.language;
3444
+ if (options.class !== void 0) props["class"] = options.class;
3445
+ if (options.id !== void 0) props["id"] = options.id;
3446
+ applyA11yProps(props, options);
3447
+ const node = this._graph.createNode("code", { parent: this._node, props });
3448
+ const resolved = bindValue(this._graph, node, "text", source);
3449
+ node.setProp("text", resolved);
3450
+ }
3389
3451
  };
3390
3452
  var ContainerBuilderBase = class extends ContentBuilderBase {
3391
3453
  section(key, builder, options = {}) {
@@ -4122,7 +4184,7 @@ function trigger(el, type, init = {}) {
4122
4184
  }
4123
4185
 
4124
4186
  // src/version.ts
4125
- var VERSION = "2.5.0";
4187
+ var VERSION = "2.7.0";
4126
4188
  // Annotate the CommonJS export names for ESM import in node:
4127
4189
  0 && (module.exports = {
4128
4190
  VERSION,