hadars 1.0.0 → 1.0.2

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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  renderPreflight,
3
3
  renderToString
4
- } from "./chunk-2TMQUXFL.js";
4
+ } from "./chunk-QOTDCUE5.js";
5
5
  import {
6
6
  createElement
7
7
  } from "./chunk-OZUZS2PD.js";
@@ -29,8 +29,7 @@ function restoreUnsuspend(u) {
29
29
  function getContextValue(context) {
30
30
  const map = _g[MAP_KEY];
31
31
  if (map && map.has(context)) return map.get(context);
32
- const c = context;
33
- return "_defaultValue" in c ? c._defaultValue : c._currentValue;
32
+ return context._currentValue;
34
33
  }
35
34
  function pushContextValue(context, value) {
36
35
  let map = _g[MAP_KEY];
@@ -38,8 +37,7 @@ function pushContextValue(context, value) {
38
37
  map = /* @__PURE__ */ new Map();
39
38
  _g[MAP_KEY] = map;
40
39
  }
41
- const c = context;
42
- const prev = map.has(context) ? map.get(context) : "_defaultValue" in c ? c._defaultValue : c._currentValue;
40
+ const prev = map.has(context) ? map.get(context) : context._currentValue;
43
41
  map.set(context, value);
44
42
  return prev;
45
43
  }
@@ -144,13 +142,21 @@ function getTreeId() {
144
142
  const stripped = (id & ~(1 << 31 - Math.clz32(id))).toString(32);
145
143
  return stripped + overflow;
146
144
  }
145
+ var REACT_MAJOR = typeof __HADARS_REACT_MAJOR__ !== "undefined" ? parseInt(String(__HADARS_REACT_MAJOR__), 10) : 19;
146
+ var REACT_VERSION = REACT_MAJOR < 19 ? "18.3.1" : "19.1.1";
147
+ function setReactVersion(major, version2) {
148
+ REACT_MAJOR = major;
149
+ REACT_VERSION = version2 ?? (major < 19 ? "18.3.1" : "19.1.1");
150
+ }
147
151
  function makeId() {
148
152
  const st = s();
149
153
  const treeId = getTreeId();
150
154
  const n = st.localIdCounter++;
151
- let id = "_R_" + st.idPrefix + treeId;
152
- if (n > 0) id += "H" + n.toString(32);
153
- return id + "_";
155
+ const suffix = n > 0 ? "H" + n.toString(32) : "";
156
+ if (REACT_MAJOR < 19) {
157
+ return ":" + st.idPrefix + "R" + treeId + suffix + ":";
158
+ }
159
+ return "_R_" + st.idPrefix + treeId + suffix + "_";
154
160
  }
155
161
 
156
162
  // src/slim-react/hooks.ts
@@ -243,8 +249,22 @@ function createContext(defaultValue) {
243
249
 
244
250
  // src/slim-react/dispatcher.ts
245
251
  import * as ReactNS from "react";
246
- var _reactInternalsKey = "__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE";
247
- var _internals = ReactNS[_reactInternalsKey];
252
+ var _r19;
253
+ var _r18;
254
+ var _detected = false;
255
+ var _k19 = "__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE";
256
+ var _k18 = "__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED";
257
+ function _detect() {
258
+ if (_detected) return;
259
+ _detected = true;
260
+ const r19 = ReactNS[_k19];
261
+ if (r19) {
262
+ _r19 = r19;
263
+ return;
264
+ }
265
+ const raw = ReactNS[_k18];
266
+ if (raw?.ReactCurrentDispatcher) _r18 = raw;
267
+ }
248
268
  var slimDispatcher = {
249
269
  useId: makeId,
250
270
  readContext: (ctx) => getContextValue(ctx),
@@ -272,13 +292,23 @@ var slimDispatcher = {
272
292
  useHostTransitionStatus: () => false
273
293
  };
274
294
  function installDispatcher() {
275
- if (!_internals) return null;
276
- const prev = _internals.H;
277
- _internals.H = slimDispatcher;
278
- return prev;
295
+ _detect();
296
+ if (_r19) {
297
+ const prev = _r19.H;
298
+ _r19.H = slimDispatcher;
299
+ return prev;
300
+ }
301
+ if (_r18) {
302
+ const prev = _r18.ReactCurrentDispatcher.current;
303
+ _r18.ReactCurrentDispatcher.current = slimDispatcher;
304
+ return prev;
305
+ }
306
+ return null;
279
307
  }
280
308
  function restoreDispatcher(prev) {
281
- if (_internals) _internals.H = prev;
309
+ _detect();
310
+ if (_r19) _r19.H = prev;
311
+ else if (_r18) _r18.ReactCurrentDispatcher.current = prev;
282
312
  }
283
313
 
284
314
  // src/slim-react/render.ts
@@ -535,7 +565,7 @@ function writeAttributes(writer, props, isSvg, skip) {
535
565
  if (isSvg && key in SVG_ATTR_MAP) {
536
566
  attrName = SVG_ATTR_MAP[key];
537
567
  } else {
538
- attrName = key === "className" ? "class" : key === "htmlFor" ? "for" : key === "tabIndex" ? "tabindex" : key === "defaultValue" ? "value" : key === "defaultChecked" ? "checked" : key;
568
+ attrName = key === "className" ? "class" : key === "htmlFor" ? "for" : key === "tabIndex" ? "tabindex" : key === "defaultValue" ? "value" : key === "defaultChecked" ? "checked" : key === "contentEditable" && REACT_MAJOR < 19 ? "contenteditable" : key;
539
569
  }
540
570
  if (value === false || value == null) {
541
571
  if (value === false && (attrName.charCodeAt(0) === 97 && attrName.startsWith("aria-") || attrName.charCodeAt(0) === 100 && attrName.startsWith("data-"))) {
@@ -744,7 +774,8 @@ function renderComponent(type, props, writer, isSvg, _suspenseRetries = 0) {
744
774
  const LazyComp = resolved?.default ?? resolved;
745
775
  return renderComponent(LazyComp, props, writer, isSvg);
746
776
  }
747
- if (typeOf === REACT_CONSUMER) {
777
+ const isConsumer = typeOf === REACT_CONSUMER || typeOf === REACT_CONTEXT && "_context" in type && !("value" in props);
778
+ if (isConsumer) {
748
779
  const ctx2 = type._context;
749
780
  const value = ctx2 ? getContextValue(ctx2) : void 0;
750
781
  const result2 = typeof props.children === "function" ? props.children(value) : null;
@@ -1130,7 +1161,12 @@ var Component = class {
1130
1161
  };
1131
1162
  var PureComponent = class extends Component {
1132
1163
  };
1133
- var version = "19.1.1";
1164
+ var version = REACT_VERSION;
1165
+ var __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = {
1166
+ ReactCurrentDispatcher: { current: null },
1167
+ ReactCurrentBatchConfig: { transition: null },
1168
+ ReactCurrentOwner: { current: null }
1169
+ };
1134
1170
  var React = {
1135
1171
  // Hooks
1136
1172
  useState,
@@ -1174,11 +1210,14 @@ var React = {
1174
1210
  renderToReadableStream: renderToStream,
1175
1211
  renderPreflight,
1176
1212
  // Version
1177
- version
1213
+ version,
1214
+ // React 18 internals
1215
+ __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
1178
1216
  };
1179
1217
  var slim_react_default = React;
1180
1218
 
1181
1219
  export {
1220
+ setReactVersion,
1182
1221
  useState,
1183
1222
  useReducer,
1184
1223
  useEffect,
@@ -1213,5 +1252,6 @@ export {
1213
1252
  Component,
1214
1253
  PureComponent,
1215
1254
  version,
1255
+ __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
1216
1256
  slim_react_default
1217
1257
  };