@hairy/react-lib-composition 1.29.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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-PRESENT Hairyf <https://github.com/antfu>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # @hairy/react-lib
2
+
3
+ [![npm version][npm-version-src]][npm-version-href]
4
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
+ [![bundle][bundle-src]][bundle-href]
6
+ [![JSDocs][jsdocs-src]][jsdocs-href]
7
+ [![License][license-src]][license-href]
8
+
9
+ ## Install
10
+
11
+ ```
12
+ ni @hairy/react-lib
13
+ ```
14
+
15
+ ## CDN
16
+
17
+ ```html
18
+ <script src="https://unpkg.com/@hairy/react-lib"></script>
19
+ ```
20
+
21
+ ## License
22
+
23
+ [MIT](./LICENSE) License © [Hairyf](https://github.com/hairyf)
24
+
25
+ <!-- Badges -->
26
+
27
+ [npm-version-src]: https://img.shields.io/npm/v/@hairy/react-lib?style=flat&colorA=080f12&colorB=1fa669
28
+ [npm-version-href]: https://npmjs.com/package/@hairy/react-lib
29
+ [npm-downloads-src]: https://img.shields.io/npm/dm/@hairy/react-lib?style=flat&colorA=080f12&colorB=1fa669
30
+ [npm-downloads-href]: https://npmjs.com/package/@hairy/react-lib
31
+ [bundle-src]: https://img.shields.io/bundlephobia/minzip/@hairy/react-lib?style=flat&colorA=080f12&colorB=1fa669&label=minzip
32
+ [bundle-href]: https://bundlephobia.com/result?p=@hairy/react-lib
33
+ [license-src]: https://img.shields.io/github/license/hairyf/hairylib.svg?style=flat&colorA=080f12&colorB=1fa669
34
+ [license-href]: https://github.com/hairyf/hairylib/blob/main/LICENSE
35
+ [jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669
36
+ [jsdocs-href]: https://www.jsdocs.io/package/@hairy/react-lib
package/dist/index.cjs ADDED
@@ -0,0 +1,487 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ Fragment: () => import_react9.Fragment,
24
+ TransitionGroup: () => TransitionGroup,
25
+ computed: () => computed,
26
+ customRef: () => customRef,
27
+ defineComponent: () => defineComponent,
28
+ effectScope: () => effectScope,
29
+ getCurrentInstance: () => getCurrentInstance,
30
+ getCurrentScope: () => getCurrentScope,
31
+ h: () => import_react9.createElement,
32
+ hasInjectionContext: () => hasInjectionContext,
33
+ inject: () => inject,
34
+ isProxy: () => import_reactivity8.isProxy,
35
+ isReactive: () => import_reactivity8.isReactive,
36
+ isReadonly: () => import_reactivity8.isReadonly,
37
+ isRef: () => import_reactivity8.isRef,
38
+ isShallow: () => import_reactivity8.isShallow,
39
+ markRaw: () => import_reactivity8.markRaw,
40
+ nextTick: () => nextTick,
41
+ onBeforeMount: () => onBeforeMount,
42
+ onBeforeUnmount: () => onBeforeUnmount,
43
+ onBeforeUpdate: () => onBeforeUpdate,
44
+ onMounted: () => onMounted,
45
+ onScopeDispose: () => onScopeDispose,
46
+ onUnmounted: () => onUnmounted,
47
+ onUpdated: () => onUpdated,
48
+ provide: () => provide,
49
+ reactive: () => reactive,
50
+ reactivity: () => reactivity,
51
+ readonly: () => readonly,
52
+ ref: () => ref,
53
+ shallowReactive: () => shallowReactive,
54
+ shallowReadonly: () => shallowReadonly,
55
+ shallowRef: () => shallowRef,
56
+ toRaw: () => import_reactivity8.toRaw,
57
+ toReactive: () => import_reactivity8.toReactive,
58
+ toReadonly: () => import_reactivity8.toReadonly,
59
+ toRef: () => import_reactivity8.toRef,
60
+ toRefs: () => import_reactivity8.toRefs,
61
+ toValue: () => import_reactivity8.toValue,
62
+ unref: () => import_reactivity8.unref,
63
+ watch: () => watch,
64
+ watchEffect: () => watchEffect,
65
+ withEffectScope: () => withEffectScope
66
+ });
67
+ module.exports = __toCommonJS(index_exports);
68
+
69
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_freeGlobal.js
70
+ var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
71
+ var freeGlobal_default = freeGlobal;
72
+
73
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_root.js
74
+ var freeSelf = typeof self == "object" && self && self.Object === Object && self;
75
+ var root = freeGlobal_default || freeSelf || Function("return this")();
76
+ var root_default = root;
77
+
78
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_Symbol.js
79
+ var Symbol2 = root_default.Symbol;
80
+ var Symbol_default = Symbol2;
81
+
82
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_getRawTag.js
83
+ var objectProto = Object.prototype;
84
+ var hasOwnProperty = objectProto.hasOwnProperty;
85
+ var nativeObjectToString = objectProto.toString;
86
+ var symToStringTag = Symbol_default ? Symbol_default.toStringTag : void 0;
87
+ function getRawTag(value) {
88
+ var isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag];
89
+ try {
90
+ value[symToStringTag] = void 0;
91
+ var unmasked = true;
92
+ } catch (e) {
93
+ }
94
+ var result = nativeObjectToString.call(value);
95
+ if (unmasked) {
96
+ if (isOwn) {
97
+ value[symToStringTag] = tag;
98
+ } else {
99
+ delete value[symToStringTag];
100
+ }
101
+ }
102
+ return result;
103
+ }
104
+ var getRawTag_default = getRawTag;
105
+
106
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_objectToString.js
107
+ var objectProto2 = Object.prototype;
108
+ var nativeObjectToString2 = objectProto2.toString;
109
+ function objectToString(value) {
110
+ return nativeObjectToString2.call(value);
111
+ }
112
+ var objectToString_default = objectToString;
113
+
114
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseGetTag.js
115
+ var nullTag = "[object Null]";
116
+ var undefinedTag = "[object Undefined]";
117
+ var symToStringTag2 = Symbol_default ? Symbol_default.toStringTag : void 0;
118
+ function baseGetTag(value) {
119
+ if (value == null) {
120
+ return value === void 0 ? undefinedTag : nullTag;
121
+ }
122
+ return symToStringTag2 && symToStringTag2 in Object(value) ? getRawTag_default(value) : objectToString_default(value);
123
+ }
124
+ var baseGetTag_default = baseGetTag;
125
+
126
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isObject.js
127
+ function isObject(value) {
128
+ var type = typeof value;
129
+ return value != null && (type == "object" || type == "function");
130
+ }
131
+ var isObject_default = isObject;
132
+
133
+ // ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isFunction.js
134
+ var asyncTag = "[object AsyncFunction]";
135
+ var funcTag = "[object Function]";
136
+ var genTag = "[object GeneratorFunction]";
137
+ var proxyTag = "[object Proxy]";
138
+ function isFunction(value) {
139
+ if (!isObject_default(value)) {
140
+ return false;
141
+ }
142
+ var tag = baseGetTag_default(value);
143
+ return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
144
+ }
145
+ var isFunction_default = isFunction;
146
+
147
+ // ../util-core/src/util/noop.ts
148
+ var noop = () => {
149
+ };
150
+
151
+ // ../lib-react/src/hooks/tryUseCallback.ts
152
+ var import_react = require("react");
153
+ var tryUseCallback = (callback, deps) => {
154
+ try {
155
+ return (0, import_react.useCallback)(callback, deps);
156
+ } catch {
157
+ return callback;
158
+ }
159
+ };
160
+
161
+ // ../lib-react/src/hooks/tryUseEffect.ts
162
+ var import_react2 = require("react");
163
+ var tryUseEffect = (effect, deps) => {
164
+ try {
165
+ (0, import_react2.useEffect)(effect, deps);
166
+ } catch {
167
+ }
168
+ };
169
+
170
+ // ../lib-react/src/hooks/tryUseInsertionEffect.ts
171
+ var import_react3 = require("react");
172
+ var tryUseInsertionEffect = (callback, deps) => {
173
+ try {
174
+ (0, import_react3.useInsertionEffect)(callback, deps);
175
+ } catch {
176
+ }
177
+ };
178
+
179
+ // ../lib-react/src/hooks/tryUseReducer.ts
180
+ var import_react4 = require("react");
181
+ var tryUseReducer = (reducer, initializerArg, initializer) => {
182
+ try {
183
+ return (0, import_react4.useReducer)(reducer, initializerArg, initializer);
184
+ } catch {
185
+ return [initializerArg, () => {
186
+ }];
187
+ }
188
+ };
189
+
190
+ // ../lib-react/src/hooks/tryUseRef.ts
191
+ var import_react5 = require("react");
192
+ var tryUseRef = (initialValue) => {
193
+ try {
194
+ return (0, import_react5.useRef)(initialValue);
195
+ } catch {
196
+ return { current: initialValue };
197
+ }
198
+ };
199
+
200
+ // ../lib-react/src/hooks/tryUseState.ts
201
+ var import_react6 = require("react");
202
+ var tryUseState = (initialState) => {
203
+ try {
204
+ return (0, import_react6.useState)(initialState);
205
+ } catch {
206
+ return [isFunction_default(initialState) ? initialState() : initialState, noop];
207
+ }
208
+ };
209
+
210
+ // ../lib-react/src/hooks/useUpdate.ts
211
+ var updateReducer = (num) => (num + 1) % 1e6;
212
+ function useUpdate() {
213
+ const [, update] = tryUseReducer(updateReducer, 0);
214
+ return update;
215
+ }
216
+
217
+ // ../lib-react/src/hooks/tryUseUpdate.ts
218
+ function tryUseUpdate() {
219
+ try {
220
+ return useUpdate();
221
+ } catch {
222
+ return () => {
223
+ };
224
+ }
225
+ }
226
+
227
+ // src/computed.ts
228
+ var import_reactivity2 = require("@vue/reactivity");
229
+
230
+ // src/watch.ts
231
+ var import_reactivity = require("@vue/reactivity");
232
+
233
+ // src/lifecycle.ts
234
+ function onMounted(fn) {
235
+ tryUseEffect(() => {
236
+ fn();
237
+ }, []);
238
+ }
239
+ function onBeforeMount(fn) {
240
+ const isMounted = tryUseRef(false);
241
+ if (!isMounted.current) {
242
+ fn();
243
+ isMounted.current = true;
244
+ }
245
+ }
246
+ function onBeforeUnmount(fn) {
247
+ tryUseEffect(() => {
248
+ return () => {
249
+ fn();
250
+ };
251
+ }, []);
252
+ }
253
+ function onUnmounted(fn) {
254
+ onBeforeUnmount(() => setTimeout(fn, 0));
255
+ }
256
+ function onUpdated(fn) {
257
+ const isMounted = tryUseRef(false);
258
+ tryUseEffect(() => {
259
+ isMounted.current ? fn() : isMounted.current = true;
260
+ });
261
+ }
262
+ function onBeforeUpdate(fn) {
263
+ tryUseInsertionEffect(fn);
264
+ }
265
+
266
+ // src/watch.ts
267
+ function watch(source, callback, options = {}) {
268
+ const handle = tryUseRef();
269
+ const cancel = tryUseCallback(() => {
270
+ if (!handle.current)
271
+ return;
272
+ handle.current();
273
+ handle.current = void 0;
274
+ }, []);
275
+ const create = tryUseCallback(() => {
276
+ handle.current && cancel();
277
+ handle.current = (0, import_reactivity.watch)(
278
+ source,
279
+ callback,
280
+ {
281
+ ...options,
282
+ scheduler: (job) => job()
283
+ }
284
+ );
285
+ cancel.pause = handle.current.pause;
286
+ cancel.resume = handle.current.resume;
287
+ cancel.stop = handle.current.stop;
288
+ }, []);
289
+ !handle.current && create();
290
+ onMounted(create);
291
+ onBeforeUnmount(cancel);
292
+ return cancel;
293
+ }
294
+
295
+ // src/computed.ts
296
+ function computed(arg1, arg2) {
297
+ const [ref2] = tryUseState(() => (0, import_reactivity2.computed)(arg1, arg2));
298
+ watch(ref2, tryUseUpdate());
299
+ return ref2;
300
+ }
301
+
302
+ // src/effectScope.ts
303
+ var import_reactivity3 = require("@vue/reactivity");
304
+ var import_react7 = require("react");
305
+ var activeEffectScope;
306
+ function createVueEffectScope(...args) {
307
+ const scope = (0, import_reactivity3.effectScope)(...args);
308
+ Reflect.set(scope, "parent", activeEffectScope);
309
+ if (!args[0] && activeEffectScope) {
310
+ const scopes = activeEffectScope.scopes || (activeEffectScope.scopes = []);
311
+ Reflect.set(scope, "index", scopes.push(scope) - 1);
312
+ }
313
+ return scope;
314
+ }
315
+ function effectScope(...args) {
316
+ const hasRun = tryUseRef(false);
317
+ const [scope] = tryUseState(() => createVueEffectScope(...args));
318
+ const originalRunRef = tryUseRef(scope.run);
319
+ const runFn = tryUseCallback((fn) => {
320
+ if (!hasRun.current) {
321
+ hasRun.current = true;
322
+ return originalRunRef.current.bind(scope)(fn);
323
+ } else {
324
+ return void 0;
325
+ }
326
+ }, []);
327
+ scope.run = runFn;
328
+ return scope;
329
+ }
330
+ function withEffectScope(fn, detached) {
331
+ let currentEffectScope;
332
+ return (...props) => {
333
+ const scope = effectScope(detached);
334
+ const element = (0, import_react7.createElement)(fn, ...props);
335
+ onBeforeMount(() => {
336
+ currentEffectScope = activeEffectScope;
337
+ activeEffectScope = scope;
338
+ });
339
+ onMounted(() => activeEffectScope = currentEffectScope);
340
+ onUnmounted(() => scope.stop());
341
+ return element;
342
+ };
343
+ }
344
+ function getCurrentScope() {
345
+ const [effectScope2] = tryUseState(() => activeEffectScope || (0, import_reactivity3.getCurrentScope)());
346
+ return effectScope2;
347
+ }
348
+ function onScopeDispose(fn, _failSilently = false) {
349
+ if (activeEffectScope)
350
+ Reflect.get(activeEffectScope, "cleanups")?.push(fn);
351
+ }
352
+
353
+ // src/reactive.ts
354
+ var import_reactivity4 = require("@vue/reactivity");
355
+ var import_react8 = require("react");
356
+ function reactive(target) {
357
+ const [value] = (0, import_react8.useState)(() => (0, import_reactivity4.reactive)(target));
358
+ watch(value, tryUseUpdate());
359
+ return value;
360
+ }
361
+ function shallowReactive(target) {
362
+ const [value] = (0, import_react8.useState)(() => (0, import_reactivity4.shallowReactive)(target));
363
+ watch(value, tryUseUpdate());
364
+ return value;
365
+ }
366
+
367
+ // src/reactivity.ts
368
+ function reactivity(getter) {
369
+ watch(() => getter(), tryUseUpdate(), { deep: true });
370
+ return getter();
371
+ }
372
+
373
+ // src/readonly.ts
374
+ var import_reactivity5 = require("@vue/reactivity");
375
+ function readonly(target) {
376
+ const [value] = tryUseState(() => (0, import_reactivity5.readonly)(target));
377
+ watch(value, tryUseUpdate());
378
+ return value;
379
+ }
380
+ function shallowReadonly(target) {
381
+ const [value] = tryUseState(() => (0, import_reactivity5.shallowReadonly)(target));
382
+ watch(value, tryUseUpdate());
383
+ return value;
384
+ }
385
+
386
+ // src/ref.ts
387
+ var import_reactivity6 = require("@vue/reactivity");
388
+ function ref(initValue) {
389
+ const [ref2] = tryUseState(() => {
390
+ const r = (0, import_reactivity6.ref)(initValue);
391
+ Object.defineProperty(r, "current", { set: (value) => r.value = value });
392
+ return r;
393
+ });
394
+ watch(ref2, tryUseUpdate(), { deep: true });
395
+ return ref2;
396
+ }
397
+ function customRef(factory) {
398
+ const [ref2] = tryUseState(() => (0, import_reactivity6.customRef)(factory));
399
+ watch(ref2, tryUseUpdate());
400
+ return ref2;
401
+ }
402
+ function shallowRef(initValue) {
403
+ const [ref2] = tryUseState(() => (0, import_reactivity6.shallowRef)(initValue));
404
+ watch(ref2, tryUseUpdate());
405
+ return ref2;
406
+ }
407
+
408
+ // src/watchEffect.ts
409
+ var import_reactivity7 = require("@vue/reactivity");
410
+ function watchEffect(effect, options = {}) {
411
+ const [watchHandle] = tryUseState(() => (0, import_reactivity7.watch)(effect, null, {
412
+ ...options,
413
+ scheduler: (job) => job()
414
+ }));
415
+ onBeforeUnmount(() => watchHandle.stop());
416
+ return watchHandle;
417
+ }
418
+
419
+ // src/index.ts
420
+ var import_reactivity8 = require("@vue/reactivity");
421
+ var import_react9 = require("react");
422
+ var getCurrentInstance = noop;
423
+ var hasInjectionContext = noop;
424
+ var inject = noop;
425
+ var provide = noop;
426
+ var nextTick = noop;
427
+ var defineComponent = noop;
428
+ var TransitionGroup = noop;
429
+ // Annotate the CommonJS export names for ESM import in node:
430
+ 0 && (module.exports = {
431
+ Fragment,
432
+ TransitionGroup,
433
+ computed,
434
+ customRef,
435
+ defineComponent,
436
+ effectScope,
437
+ getCurrentInstance,
438
+ getCurrentScope,
439
+ h,
440
+ hasInjectionContext,
441
+ inject,
442
+ isProxy,
443
+ isReactive,
444
+ isReadonly,
445
+ isRef,
446
+ isShallow,
447
+ markRaw,
448
+ nextTick,
449
+ onBeforeMount,
450
+ onBeforeUnmount,
451
+ onBeforeUpdate,
452
+ onMounted,
453
+ onScopeDispose,
454
+ onUnmounted,
455
+ onUpdated,
456
+ provide,
457
+ reactive,
458
+ reactivity,
459
+ readonly,
460
+ ref,
461
+ shallowReactive,
462
+ shallowReadonly,
463
+ shallowRef,
464
+ toRaw,
465
+ toReactive,
466
+ toReadonly,
467
+ toRef,
468
+ toRefs,
469
+ toValue,
470
+ unref,
471
+ watch,
472
+ watchEffect,
473
+ withEffectScope
474
+ });
475
+ /*! Bundled license information:
476
+
477
+ lodash-es/lodash.js:
478
+ (**
479
+ * @license
480
+ * Lodash (Custom Build) <https://lodash.com/>
481
+ * Build: `lodash modularize exports="es" -o ./`
482
+ * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
483
+ * Released under MIT license <https://lodash.com/license>
484
+ * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
485
+ * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
486
+ *)
487
+ */