hadars 0.4.2 → 1.0.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.
@@ -1,3 +1,6 @@
1
+ import { createRequire } from "node:module";
2
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
3
+
1
4
  // src/ssr-render-worker.ts
2
5
  import { workerData, parentPort } from "node:worker_threads";
3
6
  import { pathToFileURL } from "node:url";
@@ -7,25 +10,8 @@ var SLIM_ELEMENT = Symbol.for("react.element");
7
10
  var REACT19_ELEMENT = Symbol.for("react.transitional.element");
8
11
  var FRAGMENT_TYPE = Symbol.for("react.fragment");
9
12
  var SUSPENSE_TYPE = Symbol.for("react.suspense");
10
- // src/slim-react/jsx.ts
11
- function createElement(type, props, ...children) {
12
- const normalizedProps = { ...props || {} };
13
- if (children.length === 1) {
14
- normalizedProps.children = children[0];
15
- } else if (children.length > 1) {
16
- normalizedProps.children = children;
17
- }
18
- const key = normalizedProps.key ?? null;
19
- delete normalizedProps.key;
20
- return {
21
- $$typeof: SLIM_ELEMENT,
22
- type,
23
- props: normalizedProps,
24
- key
25
- };
26
- }
27
-
28
13
  // src/slim-react/renderContext.ts
14
+ import { createRequire as _nodeCreateRequire } from "node:module";
29
15
  var MAP_KEY = "__slimReactContextMap";
30
16
  var _g = globalThis;
31
17
  if (!("__slimReactContextMap" in _g))
@@ -49,8 +35,7 @@ function getContextValue(context) {
49
35
  const map = _g[MAP_KEY];
50
36
  if (map && map.has(context))
51
37
  return map.get(context);
52
- const c = context;
53
- return "_defaultValue" in c ? c._defaultValue : c._currentValue;
38
+ return context._currentValue;
54
39
  }
55
40
  function pushContextValue(context, value) {
56
41
  let map = _g[MAP_KEY];
@@ -58,8 +43,7 @@ function pushContextValue(context, value) {
58
43
  map = new Map;
59
44
  _g[MAP_KEY] = map;
60
45
  }
61
- const c = context;
62
- const prev = map.has(context) ? map.get(context) : ("_defaultValue" in c) ? c._defaultValue : c._currentValue;
46
+ const prev = map.has(context) ? map.get(context) : context._currentValue;
63
47
  map.set(context, value);
64
48
  return prev;
65
49
  }
@@ -164,14 +148,54 @@ function getTreeId() {
164
148
  const stripped = (id & ~(1 << 31 - Math.clz32(id))).toString(32);
165
149
  return stripped + overflow;
166
150
  }
151
+ var _detectReact = () => {
152
+ if (typeof __HADARS_REACT_MAJOR__ !== "undefined") {
153
+ const major = parseInt(String(__HADARS_REACT_MAJOR__), 10);
154
+ return {
155
+ major,
156
+ version: major < 19 ? "18.3.1" : "19.1.1"
157
+ };
158
+ }
159
+ const parse = (ver) => ({ major: parseInt(ver.split(".")[0], 10), version: ver });
160
+ try {
161
+ return parse(__require("react").version);
162
+ } catch {}
163
+ try {
164
+ const req = _nodeCreateRequire(process.cwd() + "/__hadars__.js");
165
+ return parse(req("react").version);
166
+ } catch {}
167
+ return { major: 19, version: "19.1.1" };
168
+ };
169
+ var _react = _detectReact();
170
+ var REACT_MAJOR = _react.major;
171
+ var REACT_VERSION = _react.version;
167
172
  function makeId() {
168
173
  const st = s();
169
174
  const treeId = getTreeId();
170
175
  const n = st.localIdCounter++;
171
- let id = "_R_" + st.idPrefix + treeId;
172
- if (n > 0)
173
- id += "H" + n.toString(32);
174
- return id + "_";
176
+ const suffix = n > 0 ? "H" + n.toString(32) : "";
177
+ if (REACT_MAJOR < 19) {
178
+ return ":" + st.idPrefix + "R" + treeId + suffix + ":";
179
+ }
180
+ return "_R_" + st.idPrefix + treeId + suffix + "_";
181
+ }
182
+
183
+ // src/slim-react/jsx.ts
184
+ function createElement(type, props, ...children) {
185
+ const normalizedProps = { ...props || {} };
186
+ if (children.length === 1) {
187
+ normalizedProps.children = children[0];
188
+ } else if (children.length > 1) {
189
+ normalizedProps.children = children;
190
+ }
191
+ const key = normalizedProps.key ?? null;
192
+ delete normalizedProps.key;
193
+ return {
194
+ $$typeof: SLIM_ELEMENT,
195
+ type,
196
+ props: normalizedProps,
197
+ key
198
+ };
175
199
  }
176
200
 
177
201
  // src/slim-react/hooks.ts
@@ -224,8 +248,9 @@ function use(usable) {
224
248
  }
225
249
  // src/slim-react/dispatcher.ts
226
250
  import * as ReactNS from "react";
227
- var _reactInternalsKey = "__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE";
228
- var _internals = ReactNS[_reactInternalsKey];
251
+ var _r19 = ReactNS.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
252
+ var _r18Raw = !_r19 ? ReactNS.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED : undefined;
253
+ var _r18 = _r18Raw?.ReactCurrentDispatcher ? _r18Raw : undefined;
229
254
  var slimDispatcher = {
230
255
  useId: makeId,
231
256
  readContext: (ctx) => getContextValue(ctx),
@@ -251,15 +276,23 @@ var slimDispatcher = {
251
276
  useHostTransitionStatus: () => false
252
277
  };
253
278
  function installDispatcher() {
254
- if (!_internals)
255
- return null;
256
- const prev = _internals.H;
257
- _internals.H = slimDispatcher;
258
- return prev;
279
+ if (_r19) {
280
+ const prev = _r19.H;
281
+ _r19.H = slimDispatcher;
282
+ return prev;
283
+ }
284
+ if (_r18) {
285
+ const prev = _r18.ReactCurrentDispatcher.current;
286
+ _r18.ReactCurrentDispatcher.current = slimDispatcher;
287
+ return prev;
288
+ }
289
+ return null;
259
290
  }
260
291
  function restoreDispatcher(prev) {
261
- if (_internals)
262
- _internals.H = prev;
292
+ if (_r19)
293
+ _r19.H = prev;
294
+ else if (_r18)
295
+ _r18.ReactCurrentDispatcher.current = prev;
263
296
  }
264
297
 
265
298
  // src/slim-react/render.ts
@@ -520,7 +553,7 @@ function writeAttributes(writer, props, isSvg, skip) {
520
553
  if (isSvg && key in SVG_ATTR_MAP) {
521
554
  attrName = SVG_ATTR_MAP[key];
522
555
  } else {
523
- attrName = key === "className" ? "class" : key === "htmlFor" ? "for" : key === "tabIndex" ? "tabindex" : key === "defaultValue" ? "value" : key === "defaultChecked" ? "checked" : key;
556
+ attrName = key === "className" ? "class" : key === "htmlFor" ? "for" : key === "tabIndex" ? "tabindex" : key === "defaultValue" ? "value" : key === "defaultChecked" ? "checked" : key === "contentEditable" && REACT_MAJOR < 19 ? "contenteditable" : key;
524
557
  }
525
558
  if (value === false || value == null) {
526
559
  if (value === false && (attrName.charCodeAt(0) === 97 && attrName.startsWith("aria-") || attrName.charCodeAt(0) === 100 && attrName.startsWith("data-"))) {
@@ -731,7 +764,8 @@ function renderComponent(type, props, writer, isSvg, _suspenseRetries = 0) {
731
764
  const LazyComp = resolved?.default ?? resolved;
732
765
  return renderComponent(LazyComp, props, writer, isSvg);
733
766
  }
734
- if (typeOf === REACT_CONSUMER) {
767
+ const isConsumer = typeOf === REACT_CONSUMER || typeOf === REACT_CONTEXT && "_context" in type && !("value" in props);
768
+ if (isConsumer) {
735
769
  const ctx2 = type._context;
736
770
  const value = ctx2 ? getContextValue(ctx2) : undefined;
737
771
  const result2 = typeof props.children === "function" ? props.children(value) : null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hadars",
3
- "version": "0.4.2",
3
+ "version": "1.0.1",
4
4
  "description": "Minimal SSR framework for React — rspack, HMR, TypeScript, Bun/Node/Deno",
5
5
  "module": "./dist/index.js",
6
6
  "type": "module",
@@ -58,8 +58,8 @@
58
58
  "node": ">=18.0.0"
59
59
  },
60
60
  "peerDependencies": {
61
- "react": "^19.2.0",
62
- "react-dom": "^19.2.0",
61
+ "react": "^18.0.0 || ^19.0.0",
62
+ "react-dom": "^18.0.0 || ^19.0.0",
63
63
  "typescript": "^5"
64
64
  },
65
65
  "peerDependenciesMeta": {