hightjs 0.5.0 → 0.5.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.
@@ -0,0 +1,119 @@
1
+ /*
2
+ * This file is part of the HightJS Project.
3
+ * Copyright (c) 2025 itsmuzin
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import React from 'react';
18
+
19
+ export default function App() {
20
+
21
+
22
+ const globalStyles = `
23
+
24
+ html, body {
25
+ margin: 0;
26
+ padding: 0;
27
+ width: 100%;
28
+ height: 100%;
29
+ font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
30
+ -webkit-font-smoothing: antialiased;
31
+ -moz-osx-font-smoothing: grayscale;
32
+ box-sizing: border-box;
33
+ }
34
+
35
+ *, *:before, *:after {
36
+ box-sizing: inherit;
37
+ }
38
+
39
+ body {
40
+ color: #000;
41
+ background: linear-gradient(to bottom, #e9e9e9, #ffffff);
42
+ background-attachment: fixed;
43
+
44
+ display: flex;
45
+ align-items: center;
46
+ justify-content: center;
47
+ min-height: 100vh;
48
+ text-align: center;
49
+ padding: 20px;
50
+ }
51
+
52
+ .error-container {
53
+ /* Remove qualquer estilo de "card" anterior */
54
+ }
55
+
56
+ .hight-error-h1 {
57
+ border-right: 1px solid rgba(0, 0, 0, .3);
58
+ }
59
+
60
+ @media (prefers-color-scheme: dark) {
61
+ body {
62
+ color: #fff;
63
+ background: linear-gradient(to bottom, #222, #000);
64
+ }
65
+ .hight-error-h2 {
66
+ color: white;
67
+ }
68
+ .hight-error-h1 {
69
+ color: white;
70
+ border-right: 1px solid rgba(255, 255, 255, .3);
71
+ }
72
+ }
73
+ `;
74
+
75
+ // Estilos inline do seu exemplo original
76
+ const h1Styles = {
77
+ display: 'inline-block',
78
+ margin: '0px 20px 0px 0px',
79
+ padding: '0px 23px 0px 0px',
80
+ fontSize: '24px',
81
+ fontWeight: '500',
82
+ verticalAlign: 'top',
83
+ lineHeight: '49px'
84
+ };
85
+
86
+ const h2ContainerStyles = {
87
+ display: 'inline-block',
88
+ verticalAlign: 'top', // Alinha com o topo do H1
89
+ };
90
+
91
+ const h2Styles = {
92
+ fontSize: '14px',
93
+ fontWeight: '400',
94
+ lineHeight: '49px',
95
+ margin: '0px'
96
+ };
97
+
98
+
99
+ return (
100
+ <>
101
+ <style dangerouslySetInnerHTML={{ __html: globalStyles }} />
102
+
103
+ <div className="error-container">
104
+ <h1
105
+ className="hight-error-h1"
106
+ style={h1Styles}
107
+ >
108
+ 404
109
+ </h1>
110
+ <div style={h2ContainerStyles}>
111
+ <h2 style={h2Styles} className="hight-error-h2">
112
+ This page cannot be found.
113
+ </h2>
114
+ </div>
115
+ </div>
116
+ </>
117
+ );
118
+ }
119
+
@@ -0,0 +1,25 @@
1
+ /*
2
+ * This file is part of the HightJS Project.
3
+ * Copyright (c) 2025 itsmuzin
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ // Este arquivo exporta apenas código seguro para o cliente (navegador)
19
+ export { Link } from '../components/Link';
20
+ export { RouteConfig, Metadata } from "../types";
21
+ export { router } from './clientRouter';
22
+
23
+
24
+
25
+
@@ -0,0 +1,153 @@
1
+ /*
2
+ * This file is part of the HightJS Project.
3
+ * Copyright (c) 2025 itsmuzin
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ // Sistema de roteamento do lado do cliente para hweb-sdk
18
+
19
+ export interface RouterEvents {
20
+ beforeNavigate?: (url: string) => boolean | Promise<boolean>;
21
+ afterNavigate?: (url: string) => void;
22
+ }
23
+
24
+ class Router {
25
+ private events: RouterEvents = {};
26
+ private listeners: Set<() => void> = new Set();
27
+
28
+ /**
29
+ * Navega para uma nova rota
30
+ */
31
+ async push(url: string): Promise<void> {
32
+ // Callback antes de navegar
33
+ if (this.events.beforeNavigate) {
34
+ const shouldProceed = await this.events.beforeNavigate(url);
35
+ if (shouldProceed === false) return;
36
+ }
37
+
38
+ // Atualiza a URL na barra de endereço
39
+ window.history.pushState({ path: url }, '', url);
40
+
41
+ // Dispara evento para o roteador capturar de forma assíncrona
42
+ setTimeout(() => this.triggerNavigation(), 0);
43
+
44
+ // Callback após navegar
45
+ if (this.events.afterNavigate) {
46
+ this.events.afterNavigate(url);
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Substitui a entrada atual do histórico
52
+ */
53
+ async replace(url: string): Promise<void> {
54
+ // Callback antes de navegar
55
+ if (this.events.beforeNavigate) {
56
+ const shouldProceed = await this.events.beforeNavigate(url);
57
+ if (shouldProceed === false) return;
58
+ }
59
+
60
+ // Substitui a URL atual no histórico
61
+ window.history.replaceState({ path: url }, '', url);
62
+
63
+ // Dispara evento para o roteador capturar de forma assíncrona
64
+ setTimeout(() => this.triggerNavigation(), 0);
65
+
66
+ // Callback após navegar
67
+ if (this.events.afterNavigate) {
68
+ this.events.afterNavigate(url);
69
+ }
70
+ }
71
+
72
+ /**
73
+ * Volta uma página no histórico
74
+ */
75
+ back(): void {
76
+ window.history.back();
77
+ }
78
+
79
+ /**
80
+ * Avança uma página no histórico
81
+ */
82
+ forward(): void {
83
+ window.history.forward();
84
+ }
85
+
86
+ /**
87
+ * Recarrega a página atual (re-renderiza o componente)
88
+ */
89
+ refresh(): void {
90
+ setTimeout(() => this.triggerNavigation(), 0);
91
+ }
92
+
93
+ /**
94
+ * Obtém a URL atual
95
+ */
96
+ get pathname(): string {
97
+ return window.location.pathname;
98
+ }
99
+
100
+ /**
101
+ * Obtém os query parameters atuais
102
+ */
103
+ get query(): URLSearchParams {
104
+ return new URLSearchParams(window.location.search);
105
+ }
106
+
107
+ /**
108
+ * Obtém a URL completa atual
109
+ */
110
+ get url(): string {
111
+ return window.location.href;
112
+ }
113
+
114
+ /**
115
+ * Adiciona event listeners para eventos de roteamento
116
+ */
117
+ on(events: RouterEvents): void {
118
+ this.events = { ...this.events, ...events };
119
+ }
120
+
121
+ /**
122
+ * Remove event listeners
123
+ */
124
+ off(): void {
125
+ this.events = {};
126
+ }
127
+
128
+ /**
129
+ * Adiciona um listener para mudanças de rota
130
+ */
131
+ subscribe(listener: () => void): () => void {
132
+ this.listeners.add(listener);
133
+ return () => this.listeners.delete(listener);
134
+ }
135
+
136
+ /**
137
+ * Dispara evento de navegação para todos os listeners
138
+ */
139
+ private triggerNavigation(): void {
140
+ // Dispara o evento nativo para o roteador do hweb capturar
141
+ window.dispatchEvent(new PopStateEvent('popstate'));
142
+
143
+ // Notifica todos os listeners customizados
144
+ this.listeners.forEach(listener => listener());
145
+ }
146
+
147
+ }
148
+
149
+ // Instância singleton do router
150
+ export const router = new Router();
151
+
152
+ // Para compatibilidade, também exporta como default
153
+ export default router;