orvyn-lang 0.1.0 → 0.2.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.
@@ -0,0 +1,55 @@
1
+ const RULES = /* @__PURE__ */ new Set(["label", "required", "minLength", "maxLength", "email", "message"]);
2
+ function object(value) {
3
+ return value !== null && typeof value === "object" && !Array.isArray(value);
4
+ }
5
+ function checkRules(field, value) {
6
+ const fail = (detail) => {
7
+ throw new Error(`[Orvyn] Invalid validation rules for "${field}": ${detail}`);
8
+ };
9
+ if (!object(value)) fail("use an object, like { required: true }");
10
+ for (const [key, rule] of Object.entries(value)) {
11
+ if (!RULES.has(key)) fail(`unknown rule "${key}". Use required, minLength, maxLength, email, label or message`);
12
+ if (["required", "email"].includes(key) && typeof rule !== "boolean") fail(`${key} must be true or false`);
13
+ if (["label", "message"].includes(key) && (typeof rule !== "string" || !rule.trim())) fail(`${key} must be non-empty text`);
14
+ if (["minLength", "maxLength"].includes(key) && (!Number.isInteger(rule) || rule < 0)) {
15
+ fail(`${key} must be a non-negative whole number`);
16
+ }
17
+ }
18
+ const rules = value;
19
+ if (rules.minLength !== void 0 && rules.maxLength !== void 0 && rules.minLength > rules.maxLength) {
20
+ fail("minLength cannot be greater than maxLength");
21
+ }
22
+ }
23
+ function validate(values, schema) {
24
+ if (!object(values) || !object(schema)) {
25
+ throw new Error("[Orvyn] validate needs a values object and a rules object: validate(values, rules)");
26
+ }
27
+ const failures = [];
28
+ for (const [field, rules] of Object.entries(schema)) {
29
+ checkRules(field, rules);
30
+ const raw = Object.hasOwn(values, field) ? values[field] : void 0;
31
+ const text = typeof raw === "string" ? raw.trim() : raw;
32
+ const label = rules.label ?? field;
33
+ let error = "";
34
+ const empty = text === "" || text === null || text === void 0;
35
+ if (empty) {
36
+ if (rules.required) error = `${label} is required.`;
37
+ } else if (typeof text !== "string") {
38
+ error = `${label} must be text.`;
39
+ } else {
40
+ const length = Array.from(text).length;
41
+ if (rules.minLength !== void 0 && length < rules.minLength) {
42
+ error = `${label} must have at least ${rules.minLength} characters.`;
43
+ } else if (rules.maxLength !== void 0 && length > rules.maxLength) {
44
+ error = `${label} must have at most ${rules.maxLength} characters.`;
45
+ } else if (rules.email && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(text)) {
46
+ error = `${label} must be a valid email address.`;
47
+ }
48
+ }
49
+ if (error) failures.push([field, rules.message ?? error]);
50
+ }
51
+ return { valid: failures.length === 0, errors: Object.fromEntries(failures) };
52
+ }
53
+ export {
54
+ validate
55
+ };
@@ -1,19 +0,0 @@
1
- const contextStore = /* @__PURE__ */ new Map();
2
- function createContext(defaultValue) {
3
- const id = /* @__PURE__ */ Symbol();
4
- contextStore.set(id, defaultValue);
5
- return {
6
- id,
7
- Provider(props) {
8
- contextStore.set(id, props.value);
9
- return props.children;
10
- }
11
- };
12
- }
13
- function useContext(context) {
14
- return contextStore.get(context.id);
15
- }
16
- export {
17
- createContext,
18
- useContext
19
- };
@@ -1,8 +0,0 @@
1
- function onMount(fn) {
2
- queueMicrotask(() => {
3
- fn();
4
- });
5
- }
6
- export {
7
- onMount
8
- };
@@ -1,27 +0,0 @@
1
- import { signal } from "./signal.js";
2
- function resource(fetcher) {
3
- const data = signal(null);
4
- const loading = signal(true);
5
- const error = signal(null);
6
- async function load() {
7
- loading.set(true);
8
- error.set(null);
9
- try {
10
- const result = await fetcher();
11
- data.set(result);
12
- } catch (err) {
13
- error.set(err);
14
- }
15
- loading.set(false);
16
- }
17
- load();
18
- return {
19
- data,
20
- loading,
21
- error,
22
- reload: load
23
- };
24
- }
25
- export {
26
- resource
27
- };
@@ -1,20 +0,0 @@
1
- import { signal } from "./signal.js";
2
- const currentRoute = signal(
3
- window.location.pathname
4
- );
5
- function navigate(path) {
6
- history.pushState({}, "", path);
7
- currentRoute.set(path);
8
- }
9
- window.addEventListener(
10
- "popstate",
11
- () => {
12
- currentRoute.set(
13
- window.location.pathname
14
- );
15
- }
16
- );
17
- export {
18
- currentRoute,
19
- navigate
20
- };
package/src/core/theme.js DELETED
@@ -1,10 +0,0 @@
1
- import { signal } from "./signal.js";
2
- const theme = signal({
3
- bg: "#000000",
4
- text: "#ffffff",
5
- primary: "#2563eb",
6
- card: "#111111"
7
- });
8
- export {
9
- theme
10
- };
@@ -1,214 +0,0 @@
1
- import {
2
- getDeviceProfiles,
3
- getPlatform,
4
- setPlatform,
5
- subscribePlatform
6
- } from "../../runtime/platform.js";
7
- let installed = false;
8
- const labels = {
9
- desktop: "Desktop",
10
- tablet: "Tablet",
11
- iphone: "iPhone",
12
- android: "Android"
13
- };
14
- function ensureStyles() {
15
- if (document.querySelector("#orvyn-device-preview-styles")) {
16
- return;
17
- }
18
- const style = document.createElement("style");
19
- style.id = "orvyn-device-preview-styles";
20
- style.textContent = `
21
- .orvyn-device-preview-shell {
22
- min-height: 100vh;
23
- padding: 72px 24px 32px;
24
- background: #eef2f7;
25
- box-sizing: border-box;
26
- }
27
-
28
- .orvyn-device-preview-toolbar,
29
- .orvyn-device-preview-panel {
30
- position: fixed;
31
- z-index: 99998;
32
- background: rgba(15, 23, 42, 0.92);
33
- color: white;
34
- border: 1px solid rgba(255,255,255,0.12);
35
- box-shadow: 0 16px 40px rgba(15, 23, 42, 0.24);
36
- backdrop-filter: blur(12px);
37
- font: 12px system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
38
- }
39
-
40
- .orvyn-device-preview-toolbar {
41
- top: 16px;
42
- left: 50%;
43
- display: flex;
44
- gap: 6px;
45
- padding: 6px;
46
- border-radius: 8px;
47
- transform: translateX(-50%);
48
- }
49
-
50
- .orvyn-device-preview-button {
51
- min-width: 76px;
52
- border: 0;
53
- border-radius: 6px;
54
- padding: 8px 10px;
55
- color: white;
56
- background: transparent;
57
- cursor: pointer;
58
- font: inherit;
59
- }
60
-
61
- .orvyn-device-preview-button[data-active="true"] {
62
- background: white;
63
- color: #0f172a;
64
- }
65
-
66
- .orvyn-device-preview-panel {
67
- right: 16px;
68
- bottom: 16px;
69
- display: grid;
70
- gap: 4px;
71
- min-width: 168px;
72
- padding: 10px 12px;
73
- border-radius: 8px;
74
- }
75
-
76
- .orvyn-device-preview-stage {
77
- display: grid;
78
- justify-items: center;
79
- min-height: calc(100vh - 120px);
80
- overflow: auto;
81
- }
82
-
83
- .orvyn-device-preview-frame {
84
- position: relative;
85
- width: var(--orvyn-preview-width);
86
- height: var(--orvyn-preview-height);
87
- max-width: calc(100vw - 48px);
88
- background: white;
89
- border: 1px solid rgba(15, 23, 42, 0.14);
90
- border-radius: var(--orvyn-preview-radius);
91
- box-shadow: 0 30px 80px rgba(15, 23, 42, 0.18);
92
- overflow: hidden;
93
- transition: width 180ms ease, height 180ms ease, border-radius 180ms ease;
94
- }
95
-
96
- .orvyn-device-preview-viewport {
97
- width: 100%;
98
- height: 100%;
99
- overflow: auto;
100
- background: white;
101
- box-sizing: border-box;
102
- padding: var(--orvyn-safe-area-top) var(--orvyn-safe-area-right) var(--orvyn-safe-area-bottom) var(--orvyn-safe-area-left);
103
- }
104
-
105
- .orvyn-device-preview-notch {
106
- position: absolute;
107
- top: 10px;
108
- left: 50%;
109
- width: 126px;
110
- height: 28px;
111
- border-radius: 0 0 18px 18px;
112
- background: #020617;
113
- transform: translateX(-50%);
114
- display: none;
115
- z-index: 2;
116
- }
117
-
118
- .orvyn-device-preview-frame[data-platform="iphone"] .orvyn-device-preview-notch {
119
- display: block;
120
- }
121
- `;
122
- document.head.appendChild(style);
123
- }
124
- function resolveRoot(root) {
125
- if (typeof root === "string") {
126
- const found = document.querySelector(root);
127
- if (found) return found;
128
- }
129
- if (root instanceof HTMLElement) {
130
- return root;
131
- }
132
- return document.querySelector("#app") || document.body;
133
- }
134
- function frameRadius(platform) {
135
- if (platform === "iphone") return "42px";
136
- if (platform === "android") return "30px";
137
- if (platform === "tablet") return "22px";
138
- return "10px";
139
- }
140
- function installDevicePreview(root) {
141
- if (installed || typeof document === "undefined") {
142
- return;
143
- }
144
- installed = true;
145
- ensureStyles();
146
- const appRoot = resolveRoot(root);
147
- const shell = document.createElement("div");
148
- shell.className = "orvyn-device-preview-shell";
149
- const stage = document.createElement("div");
150
- stage.className = "orvyn-device-preview-stage";
151
- const frame = document.createElement("div");
152
- frame.className = "orvyn-device-preview-frame";
153
- const notch = document.createElement("div");
154
- notch.className = "orvyn-device-preview-notch";
155
- const viewport = document.createElement("div");
156
- viewport.className = "orvyn-device-preview-viewport";
157
- const parent = appRoot.parentElement;
158
- if (parent) {
159
- parent.insertBefore(shell, appRoot);
160
- } else {
161
- document.body.appendChild(shell);
162
- }
163
- viewport.appendChild(appRoot);
164
- frame.appendChild(notch);
165
- frame.appendChild(viewport);
166
- stage.appendChild(frame);
167
- shell.appendChild(stage);
168
- const toolbar = document.createElement("div");
169
- toolbar.className = "orvyn-device-preview-toolbar";
170
- const buttons = /* @__PURE__ */ new Map();
171
- Object.keys(getDeviceProfiles()).forEach((platform) => {
172
- const button = document.createElement("button");
173
- button.className = "orvyn-device-preview-button";
174
- button.type = "button";
175
- button.textContent = labels[platform];
176
- button.addEventListener("click", () => {
177
- setPlatform(platform);
178
- });
179
- buttons.set(platform, button);
180
- toolbar.appendChild(button);
181
- });
182
- const panel = document.createElement("div");
183
- panel.className = "orvyn-device-preview-panel";
184
- document.body.appendChild(toolbar);
185
- document.body.appendChild(panel);
186
- subscribePlatform((profile) => {
187
- frame.dataset.platform = profile.platform;
188
- frame.style.setProperty(
189
- "--orvyn-preview-width",
190
- `${profile.width}px`
191
- );
192
- frame.style.setProperty(
193
- "--orvyn-preview-height",
194
- `${profile.height}px`
195
- );
196
- frame.style.setProperty(
197
- "--orvyn-preview-radius",
198
- frameRadius(profile.platform)
199
- );
200
- buttons.forEach((button, platform) => {
201
- button.dataset.active = String(platform === profile.platform);
202
- });
203
- panel.innerHTML = `
204
- <div>Current Platform: ${labels[profile.platform]}</div>
205
- <div>Current Renderer: ${profile.renderer}</div>
206
- <div>Current Width: ${profile.width}px</div>
207
- <div>Current Height: ${profile.height}px</div>
208
- `;
209
- });
210
- setPlatform(getPlatform());
211
- }
212
- export {
213
- installDevicePreview
214
- };
@@ -1,6 +0,0 @@
1
- import {
2
- installDevicePreview
3
- } from "./PreviewFrame.js";
4
- export {
5
- installDevicePreview
6
- };
@@ -1,105 +0,0 @@
1
- import {
2
- exposeDevToolsGlobal,
3
- getDevToolsSnapshot
4
- } from "./runtime.js";
5
- let panel = null;
6
- let refreshTimer = null;
7
- function section(title, value) {
8
- return `
9
- <div style="margin-bottom:12px">
10
- <div style="font-weight:700;margin-bottom:4px">${title}</div>
11
- <pre style="white-space:pre-wrap;margin:0;font:12px ui-monospace,monospace">${value}</pre>
12
- </div>
13
- `;
14
- }
15
- function renderPanel() {
16
- if (!panel) return;
17
- const snapshot = getDevToolsSnapshot();
18
- panel.innerHTML = `
19
- <div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:12px">
20
- <strong>Orvyn DevTools</strong>
21
- <button data-orvyn-close style="border:0;background:#333;color:white;border-radius:6px;padding:4px 8px">Close</button>
22
- </div>
23
-
24
- ${section(
25
- "Signals",
26
- JSON.stringify(snapshot.signals, null, 2)
27
- )}
28
-
29
- ${section(
30
- "Effects",
31
- JSON.stringify(snapshot.effects, null, 2)
32
- )}
33
-
34
- ${section(
35
- "Components",
36
- JSON.stringify(snapshot.components, null, 2)
37
- )}
38
-
39
- ${section(
40
- "Dependency Graph",
41
- JSON.stringify(snapshot.dependencyGraph, null, 2)
42
- )}
43
-
44
- ${section(
45
- "Render Profiler",
46
- JSON.stringify(snapshot.renders.slice(-10), null, 2)
47
- )}
48
- `;
49
- panel.querySelector("[data-orvyn-close]")?.addEventListener("click", () => {
50
- panel?.remove();
51
- panel = null;
52
- if (refreshTimer !== null) {
53
- clearInterval(refreshTimer);
54
- refreshTimer = null;
55
- }
56
- });
57
- }
58
- function installDevToolsOverlay() {
59
- if (typeof document === "undefined") return;
60
- exposeDevToolsGlobal();
61
- const toggle = document.createElement("button");
62
- toggle.textContent = "Orvyn";
63
- toggle.style.position = "fixed";
64
- toggle.style.right = "16px";
65
- toggle.style.bottom = "16px";
66
- toggle.style.zIndex = "99999";
67
- toggle.style.border = "0";
68
- toggle.style.borderRadius = "8px";
69
- toggle.style.padding = "10px 12px";
70
- toggle.style.background = "#111";
71
- toggle.style.color = "white";
72
- toggle.style.font = "13px system-ui";
73
- toggle.style.cursor = "pointer";
74
- toggle.addEventListener("click", () => {
75
- if (panel) {
76
- renderPanel();
77
- return;
78
- }
79
- panel = document.createElement("aside");
80
- panel.style.position = "fixed";
81
- panel.style.right = "16px";
82
- panel.style.bottom = "64px";
83
- panel.style.width = "420px";
84
- panel.style.maxHeight = "72vh";
85
- panel.style.overflow = "auto";
86
- panel.style.zIndex = "99999";
87
- panel.style.background = "white";
88
- panel.style.color = "#111";
89
- panel.style.border = "1px solid #ddd";
90
- panel.style.borderRadius = "8px";
91
- panel.style.boxShadow = "0 12px 40px rgba(0,0,0,0.2)";
92
- panel.style.padding = "14px";
93
- panel.style.font = "13px system-ui";
94
- document.body.appendChild(panel);
95
- renderPanel();
96
- refreshTimer = window.setInterval(
97
- renderPanel,
98
- 500
99
- );
100
- });
101
- document.body.appendChild(toggle);
102
- }
103
- export {
104
- installDevToolsOverlay
105
- };
@@ -1,22 +0,0 @@
1
- import { androidRenderer } from "../platforms/android/index.js";
2
- import { iosRenderer } from "../platforms/ios/index.js";
3
- import { webRenderer } from "../platforms/web/index.js";
4
- const renderers = {
5
- web: webRenderer,
6
- ios: iosRenderer,
7
- android: androidRenderer
8
- };
9
- function createRenderer(target = "web") {
10
- const renderer = renderers[target];
11
- if (!renderer) {
12
- throw new Error(
13
- `[Orvyn Renderer] Unknown target: ${target}`
14
- );
15
- }
16
- console.log("[Orvyn Renderer]");
17
- console.log(`Target: ${target}`);
18
- return renderer;
19
- }
20
- export {
21
- createRenderer
22
- };
package/src/runtime/h.js DELETED
@@ -1,93 +0,0 @@
1
- import { applyStyles } from "./style.js";
2
- import { isStyleProp } from "../styling/fluid.js";
3
- const nativeAppendChild = typeof Node !== "undefined" ? Node.prototype.appendChild : null;
4
- function isSignal(value) {
5
- return value && typeof value.get === "function" && typeof value.subscribe === "function";
6
- }
7
- function isVNode(value) {
8
- return value && value.__orvynVNode === true;
9
- }
10
- function appendRendered(parent, child) {
11
- const rendered = renderNode(child);
12
- if (rendered && nativeAppendChild) {
13
- nativeAppendChild.call(parent, rendered);
14
- }
15
- }
16
- function renderNode(value) {
17
- if (Array.isArray(value)) {
18
- const fragment = document.createDocumentFragment();
19
- value.forEach((child) => {
20
- appendRendered(fragment, child);
21
- });
22
- return fragment;
23
- }
24
- if (isVNode(value)) {
25
- return renderNode(
26
- value.tag({
27
- ...value.props,
28
- children: value.children
29
- })
30
- );
31
- }
32
- if (isSignal(value)) {
33
- const textNode = document.createTextNode(
34
- String(value.get())
35
- );
36
- value.subscribe(() => {
37
- textNode.textContent = String(value.get());
38
- });
39
- return textNode;
40
- }
41
- if (typeof value === "string" || typeof value === "number") {
42
- return document.createTextNode(String(value));
43
- }
44
- if (value instanceof Node) {
45
- return value;
46
- }
47
- return null;
48
- }
49
- if (nativeAppendChild && !Node.prototype.__orvynAppendPatched) {
50
- Node.prototype.appendChild = function(child) {
51
- const rendered = renderNode(child);
52
- if (!rendered) {
53
- return child;
54
- }
55
- return nativeAppendChild.call(this, rendered);
56
- };
57
- Node.prototype.__orvynAppendPatched = true;
58
- }
59
- function h(tag, props = {}, children = []) {
60
- if (typeof tag === "function") {
61
- return {
62
- __orvynVNode: true,
63
- tag,
64
- props,
65
- children
66
- };
67
- }
68
- const el = document.createElement(tag);
69
- applyStyles(el, props);
70
- for (const key in props) {
71
- if (key === "class" || key === "className" || key === "nativeRole") {
72
- continue;
73
- }
74
- if (key.startsWith("on")) {
75
- el.addEventListener(
76
- key.slice(2).toLowerCase(),
77
- props[key]
78
- );
79
- } else if (!isStyleProp(key)) {
80
- el.setAttribute(
81
- key === "className" ? "class" : key,
82
- props[key]
83
- );
84
- }
85
- }
86
- children.forEach((child) => {
87
- appendRendered(el, child);
88
- });
89
- return el;
90
- }
91
- export {
92
- h
93
- };
@@ -1,59 +0,0 @@
1
- function isSignal(value) {
2
- return value && typeof value.get === "function";
3
- }
4
- function normalizeChildren(children = []) {
5
- return children.flatMap((child) => {
6
- if (Array.isArray(child)) {
7
- return normalizeChildren(child);
8
- }
9
- if (child === null || child === void 0 || child === false) {
10
- return [];
11
- }
12
- return [child];
13
- });
14
- }
15
- function hydrate(vnode, el) {
16
- if (!vnode || !el) {
17
- return;
18
- }
19
- if (typeof vnode === "string" || typeof vnode === "number") {
20
- el.textContent = String(vnode);
21
- return;
22
- }
23
- if (isSignal(vnode)) {
24
- el.textContent = String(vnode.get());
25
- vnode.subscribe(() => {
26
- el.textContent = String(vnode.get());
27
- });
28
- return;
29
- }
30
- if (typeof vnode.tag === "function") {
31
- hydrate(
32
- vnode.tag({
33
- ...vnode.props,
34
- children: vnode.children
35
- }),
36
- el
37
- );
38
- return;
39
- }
40
- for (const key in vnode.props) {
41
- if (key.startsWith("on")) {
42
- el.addEventListener(
43
- key.slice(2).toLowerCase(),
44
- vnode.props[key]
45
- );
46
- }
47
- }
48
- normalizeChildren(vnode.children).forEach(
49
- (child, index) => {
50
- hydrate(
51
- child,
52
- el.childNodes[index]
53
- );
54
- }
55
- );
56
- }
57
- export {
58
- hydrate
59
- };
@@ -1,7 +0,0 @@
1
- import { jsx, jsxs } from "./jsx-runtime.js";
2
- const jsxDEV = jsx;
3
- export {
4
- jsx,
5
- jsxDEV,
6
- jsxs
7
- };
@@ -1,13 +0,0 @@
1
- import { createVNode } from "./vnode.js";
2
- function jsx(tag, props) {
3
- return createVNode(
4
- tag,
5
- props,
6
- props?.children ? Array.isArray(props.children) ? props.children : [props.children] : []
7
- );
8
- }
9
- const jsxs = jsx;
10
- export {
11
- jsx,
12
- jsxs
13
- };