@react-arch/shared 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 React Arch
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.
@@ -0,0 +1,32 @@
1
+ //#region src/index.d.ts
2
+ /**
3
+ * @react-arch/shared
4
+ *
5
+ * Framework-agnostic primitives shared across every React Arch package.
6
+ * No dependencies on React, Three.js, PixiJS, or browser APIs.
7
+ */
8
+ type Vec2 = [number, number];
9
+ type Vec3 = [number, number, number];
10
+ type Units = "metric" | "imperial";
11
+ /** Numeric tolerance for floating-point geometry comparisons. */
12
+ declare const EPSILON = 0.000001;
13
+ declare function approxEqual(a: number, b: number, eps?: number): boolean;
14
+ declare function clamp(value: number, min: number, max: number): number;
15
+ /** Round to a sane precision to avoid floating point noise in the model. */
16
+ declare function round(value: number, decimals?: number): number;
17
+ declare function createId(prefix?: string): string;
18
+ /** Branded result of a model mutation. */
19
+ type Severity = "error" | "warning" | "info";
20
+ interface Diagnostic {
21
+ severity: Severity;
22
+ code: string;
23
+ message: string;
24
+ entityId?: string;
25
+ path?: string[];
26
+ }
27
+ type DeepReadonly<T> = T extends (infer R)[] ? ReadonlyArray<DeepReadonly<R>> : T extends object ? { readonly [K in keyof T]: DeepReadonly<T[K]> } : T;
28
+ /** Structured-clone based deep copy, with a fallback for older runtimes. */
29
+ declare function deepClone<T>(value: T): T;
30
+ //#endregion
31
+ export { DeepReadonly, Diagnostic, EPSILON, Severity, Units, Vec2, Vec3, approxEqual, clamp, createId, deepClone, round };
32
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;AAOA;;;;AAAgB;KAAJ,IAAA;AAAA,KACA,IAAA;AAAA,KAEA,KAAA;;cAGC,OAAA;AAAA,iBAEG,WAAA,CAAY,CAAA,UAAW,CAAA,UAAW,GAAA;AAAA,iBAIlC,KAAA,CAAM,KAAA,UAAe,GAAA,UAAa,GAAA;;iBAKlC,KAAA,CAAM,KAAA,UAAe,QAAY;AAAA,iBAUjC,QAAA,CAAS,MAAa;AArBtC;AAAA,KA6BY,QAAA;AAAA,UAEK,UAAA;EACf,QAAA,EAAU,QAAQ;EAClB,IAAA;EACA,OAAA;EACA,QAAA;EACA,IAAA;AAAA;AAAA,KAGU,YAAA,MAAkB,CAAA,uBAC1B,aAAA,CAAc,YAAA,CAAa,CAAA,KAC3B,CAAA,yCACyB,CAAA,GAAI,YAAA,CAAa,CAAA,CAAE,CAAA,OAC1C,CAAA;;iBAGU,SAAA,IAAa,KAAA,EAAO,CAAA,GAAI,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
1
+ //#region src/index.ts
2
+ /** Numeric tolerance for floating-point geometry comparisons. */
3
+ const EPSILON = 1e-6;
4
+ function approxEqual(a, b, eps = EPSILON) {
5
+ return Math.abs(a - b) <= eps;
6
+ }
7
+ function clamp(value, min, max) {
8
+ return Math.min(max, Math.max(min, value));
9
+ }
10
+ /** Round to a sane precision to avoid floating point noise in the model. */
11
+ function round(value, decimals = 4) {
12
+ const f = 10 ** decimals;
13
+ return Math.round(value * f) / f;
14
+ }
15
+ /**
16
+ * Deterministic-ish id generator. Avoids `Math.random` at module load so the
17
+ * model layer stays predictable and testable; callers may inject their own.
18
+ */
19
+ let __counter = 0;
20
+ function createId(prefix = "id") {
21
+ __counter += 1;
22
+ return `${prefix}_${Date.now().toString(36)}${__counter.toString(36)}`;
23
+ }
24
+ /** Structured-clone based deep copy, with a fallback for older runtimes. */
25
+ function deepClone(value) {
26
+ if (typeof structuredClone === "function") return structuredClone(value);
27
+ return JSON.parse(JSON.stringify(value));
28
+ }
29
+ //#endregion
30
+ export { EPSILON, approxEqual, clamp, createId, deepClone, round };
31
+
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * @react-arch/shared\n *\n * Framework-agnostic primitives shared across every React Arch package.\n * No dependencies on React, Three.js, PixiJS, or browser APIs.\n */\n\nexport type Vec2 = [number, number];\nexport type Vec3 = [number, number, number];\n\nexport type Units = \"metric\" | \"imperial\";\n\n/** Numeric tolerance for floating-point geometry comparisons. */\nexport const EPSILON = 1e-6;\n\nexport function approxEqual(a: number, b: number, eps = EPSILON): boolean {\n return Math.abs(a - b) <= eps;\n}\n\nexport function clamp(value: number, min: number, max: number): number {\n return Math.min(max, Math.max(min, value));\n}\n\n/** Round to a sane precision to avoid floating point noise in the model. */\nexport function round(value: number, decimals = 4): number {\n const f = 10 ** decimals;\n return Math.round(value * f) / f;\n}\n\n/**\n * Deterministic-ish id generator. Avoids `Math.random` at module load so the\n * model layer stays predictable and testable; callers may inject their own.\n */\nlet __counter = 0;\nexport function createId(prefix = \"id\"): string {\n __counter += 1;\n const time = Date.now().toString(36);\n const seq = __counter.toString(36);\n return `${prefix}_${time}${seq}`;\n}\n\n/** Branded result of a model mutation. */\nexport type Severity = \"error\" | \"warning\" | \"info\";\n\nexport interface Diagnostic {\n severity: Severity;\n code: string;\n message: string;\n entityId?: string;\n path?: string[];\n}\n\nexport type DeepReadonly<T> = T extends (infer R)[]\n ? ReadonlyArray<DeepReadonly<R>>\n : T extends object\n ? { readonly [K in keyof T]: DeepReadonly<T[K]> }\n : T;\n\n/** Structured-clone based deep copy, with a fallback for older runtimes. */\nexport function deepClone<T>(value: T): T {\n if (typeof structuredClone === \"function\") {\n return structuredClone(value);\n }\n return JSON.parse(JSON.stringify(value)) as T;\n}\n"],"mappings":";;AAaA,MAAa,UAAU;AAEvB,SAAgB,YAAY,GAAW,GAAW,MAAM,SAAkB;CACxE,OAAO,KAAK,IAAI,IAAI,CAAC,KAAK;AAC5B;AAEA,SAAgB,MAAM,OAAe,KAAa,KAAqB;CACrE,OAAO,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,KAAK,CAAC;AAC3C;;AAGA,SAAgB,MAAM,OAAe,WAAW,GAAW;CACzD,MAAM,IAAI,MAAM;CAChB,OAAO,KAAK,MAAM,QAAQ,CAAC,IAAI;AACjC;;;;;AAMA,IAAI,YAAY;AAChB,SAAgB,SAAS,SAAS,MAAc;CAC9C,aAAa;CAGb,OAAO,GAAG,OAAO,GAFJ,KAAK,IAAI,CAAC,CAAC,SAAS,EAEV,IADX,UAAU,SAAS,EACF;AAC/B;;AAoBA,SAAgB,UAAa,OAAa;CACxC,IAAI,OAAO,oBAAoB,YAC7B,OAAO,gBAAgB,KAAK;CAE9B,OAAO,KAAK,MAAM,KAAK,UAAU,KAAK,CAAC;AACzC"}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@react-arch/shared",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "devDependencies": {
15
+ "typescript": "^5.7.2",
16
+ "vitest": "^2.1.8"
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/react-arch/react-arch.git",
27
+ "directory": "packages/shared"
28
+ },
29
+ "license": "MIT",
30
+ "scripts": {
31
+ "typecheck": "tsc --noEmit",
32
+ "test": "vitest run --passWithNoTests",
33
+ "lint": "oxlint src",
34
+ "build": "tsdown"
35
+ }
36
+ }