nextia 7.0.0 → 7.0.3

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.
Files changed (77) hide show
  1. package/package.json +9 -13
  2. package/src/bin.js +4 -62
  3. package/src/{lib.js → lib/fx.js} +16 -31
  4. package/src/lib/index.js +32 -0
  5. package/src/lib/ui.js +121 -0
  6. package/src/lib/utils.js +107 -0
  7. package/template/README.md +0 -29
  8. package/template/_env.dev +0 -4
  9. package/template/_env.prod +0 -1
  10. package/template/_env.test +0 -1
  11. package/template/_gitignore +0 -10
  12. package/template/package.json +0 -35
  13. package/template/public/error.html +0 -14
  14. package/template/public/logo.svg +0 -105
  15. package/template/src/assets/i18n/index.js +0 -26
  16. package/template/src/assets/img/image.jpg +0 -0
  17. package/template/src/components/Counter/index.jsx +0 -34
  18. package/template/src/components/Counter/style.css +0 -5
  19. package/template/src/components/Message/index.jsx +0 -12
  20. package/template/src/components/index.js +0 -10
  21. package/template/src/components/ui/I18n/index.jsx +0 -23
  22. package/template/src/components/ui/Icon/index.jsx +0 -50
  23. package/template/src/components/ui/Link/index.jsx +0 -12
  24. package/template/src/components/ui/Svg/index.jsx +0 -54
  25. package/template/src/components/ui/Translate/index.jsx +0 -18
  26. package/template/src/index.html +0 -18
  27. package/template/src/index.jsx +0 -4
  28. package/template/src/pages/counter/functions.js +0 -6
  29. package/template/src/pages/counter/index.jsx +0 -51
  30. package/template/src/pages/counter/style.css +0 -2
  31. package/template/src/pages/env/functions.js +0 -3
  32. package/template/src/pages/env/index.jsx +0 -27
  33. package/template/src/pages/env/style.css +0 -2
  34. package/template/src/pages/functions.js +0 -37
  35. package/template/src/pages/home/functions.js +0 -43
  36. package/template/src/pages/home/index.jsx +0 -211
  37. package/template/src/pages/home/style.css +0 -51
  38. package/template/src/pages/http/not-found/index.jsx +0 -10
  39. package/template/src/pages/http/not-found/style.css +0 -2
  40. package/template/src/pages/icons/functions.js +0 -3
  41. package/template/src/pages/icons/index.jsx +0 -20
  42. package/template/src/pages/icons/style.css +0 -5
  43. package/template/src/pages/images/functions.js +0 -3
  44. package/template/src/pages/images/index.jsx +0 -20
  45. package/template/src/pages/images/style.css +0 -8
  46. package/template/src/pages/index.jsx +0 -114
  47. package/template/src/pages/mockapi/functions.js +0 -71
  48. package/template/src/pages/mockapi/index.jsx +0 -101
  49. package/template/src/pages/mockapi/style.css +0 -57
  50. package/template/src/pages/my-context/functions.js +0 -7
  51. package/template/src/pages/my-context/index.jsx +0 -32
  52. package/template/src/pages/my-context/style.css +0 -2
  53. package/template/src/pages/resize/functions.js +0 -3
  54. package/template/src/pages/resize/index.jsx +0 -15
  55. package/template/src/pages/resize/style.css +0 -2
  56. package/template/src/pages/search-params/functions.js +0 -3
  57. package/template/src/pages/search-params/index.jsx +0 -36
  58. package/template/src/pages/search-params/style.css +0 -2
  59. package/template/src/pages/subpage/hello/functions.js +0 -3
  60. package/template/src/pages/subpage/hello/index.jsx +0 -11
  61. package/template/src/pages/subpage/hello/style.css +0 -2
  62. package/template/src/pages/translate/functions.js +0 -5
  63. package/template/src/pages/translate/index.jsx +0 -31
  64. package/template/src/pages/translate/style.css +0 -12
  65. package/template/src/services/api.js +0 -9
  66. package/template/src/services/http.js +0 -40
  67. package/template/src/theme/animations.css +0 -72
  68. package/template/src/theme/fonts/Roboto-Regular.ttf +0 -0
  69. package/template/src/theme/fonts/index.css +0 -7
  70. package/template/src/theme/icons/exit.svg +0 -69
  71. package/template/src/theme/icons/icons.svg +0 -126
  72. package/template/src/theme/index.css +0 -39
  73. package/template/src/theme/util.css +0 -27
  74. package/template/src/utils/hooks.js +0 -49
  75. package/template/src/utils/index.js +0 -19
  76. package/template/test/index.test.js +0 -12
  77. package/template/vite.config.js +0 -97
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "nextia",
3
3
  "description": "Create fast web applications",
4
- "version": "7.0.0",
4
+ "version": "7.0.3",
5
+ "license": "MIT",
6
+ "type": "module",
5
7
  "engines": {
6
8
  "node": ">22"
7
9
  },
8
- "type": "module",
9
- "license": "MIT",
10
10
  "author": {
11
11
  "name": "Sinuhe Maceda",
12
12
  "email": "sinuhe.dev@gmail.com",
@@ -23,7 +23,9 @@
23
23
  "bin": {
24
24
  "nextia": "src/bin.js"
25
25
  },
26
- "main": "src/lib.js",
26
+ "exports": {
27
+ ".": "./src/lib/index.js"
28
+ },
27
29
  "scripts": {
28
30
  "clean": "rm -fr my-app node_modules package-lock.json .coverage out",
29
31
  "format": "biome format",
@@ -32,13 +34,7 @@
32
34
  "test": "vitest run",
33
35
  "test:name": "vitest run --testNamePattern",
34
36
  "test:silent": "vitest run --silent",
35
- "test:coverage": "vitest run --silent --coverage",
36
- "test:version": "./src/bin.js",
37
- "test:my-app": "rm -fr my-app && src/bin.js my-app",
38
- "test:my-app:exists": "src/bin.js my-app",
39
- "test:my-page": "cd my-app && ../src/bin.js page my-page",
40
- "test:my-component": "cd my-app && ../src/bin.js component MyComponent",
41
- "test:my-container": "cd my-app && ../src/bin.js container MyContainer"
37
+ "test:coverage": "vitest run --silent --coverage"
42
38
  },
43
39
  "peerDependencies": {
44
40
  "react": "^19.2.3",
@@ -46,8 +42,8 @@
46
42
  },
47
43
  "devDependencies": {
48
44
  "@vitejs/plugin-react": "^6.0.1",
49
- "@vitest/coverage-v8": "^4.0.18",
45
+ "@vitest/coverage-v8": "^4.1.2",
50
46
  "jsdom": "^29.0.1",
51
- "vitest": "^4.0.18"
47
+ "vitest": "^4.1.2"
52
48
  }
53
49
  }
package/src/bin.js CHANGED
@@ -6,20 +6,10 @@
6
6
  * This source code is licensed under the MIT license found in the
7
7
  * LICENSE file in the root directory of this source tree.
8
8
  *
9
- * https://github.com/sinuhedev/create-nextia
9
+ * https://github.com/sinuhedev/nextia
10
10
  */
11
11
 
12
- import {
13
- access,
14
- cp,
15
- mkdir,
16
- readFile,
17
- rename,
18
- writeFile
19
- } from 'node:fs/promises'
20
- import { dirname } from 'node:path'
21
- import { fileURLToPath } from 'node:url'
22
- import pkg from '../package.json' with { type: 'json' }
12
+ import { writeFile } from 'node:fs/promises'
23
13
 
24
14
  function toPascalCase(str) {
25
15
  return str
@@ -126,8 +116,8 @@ async function createContainer(name) {
126
116
  // index.jsx
127
117
  writeFile(
128
118
  `${dirName}/index.jsx`,
129
- `import { useEffect } from 'react'
130
- import { css, useFx } from 'nextia'
119
+ `import { css, useFx } from 'nextia'
120
+ import { useEffect } from 'react'
131
121
  import functions from './functions'
132
122
  import './style.css'
133
123
 
@@ -165,49 +155,6 @@ export default { initialState }
165
155
  }
166
156
  }
167
157
 
168
- async function createProject(name) {
169
- const projectPath = `${process.cwd()}/${name}/`
170
-
171
- try {
172
- await access(projectPath)
173
- console.error(`The ${name} already exists`)
174
- return
175
- } catch {
176
- /* directory doesn't exist, proceed */
177
- }
178
-
179
- try {
180
- const __dirname = dirname(fileURLToPath(import.meta.url))
181
- const templatePath = `${__dirname}/../template`
182
-
183
- const replaceToken = async (filename, token, value) => {
184
- const content = await readFile(projectPath + filename, 'utf8')
185
- await writeFile(
186
- projectPath + filename,
187
- content.replaceAll(token, value),
188
- 'utf8'
189
- )
190
- }
191
-
192
- await cp(templatePath, projectPath, { recursive: true })
193
- await cp(`${__dirname}/../biome.json`, `${projectPath}/biome.json`)
194
-
195
- await Promise.all(
196
- ['env.dev', 'env.prod', 'env.test', 'gitignore'].map((fileName) =>
197
- rename(`${projectPath}_${fileName}`, `${projectPath}.${fileName}`)
198
- )
199
- )
200
-
201
- await replaceToken('README.md', 'TEMPLATE', name)
202
- await replaceToken('package.json', 'TEMPLATE', name)
203
- await replaceToken('package.json', 'file:../', pkg.version)
204
-
205
- console.info(`✔ Project "${name}" created successfully!`)
206
- } catch (err) {
207
- console.error(`Failed to create project: ${err.message}`)
208
- }
209
- }
210
-
211
158
  async function main() {
212
159
  const ARG1 = process.argv[2]
213
160
  const ARG2 = process.argv[3]
@@ -227,11 +174,6 @@ async function main() {
227
174
  if (ARG2) await createContainer(ARG2)
228
175
  else console.warn('node --run nextia container <ContainerName>')
229
176
  break
230
-
231
- default:
232
- if (ARG1) await createProject(ARG1)
233
- else console.info(`v${pkg.version}\nnpm create nextia <ProjectName>`)
234
- break
235
177
  }
236
178
  }
237
179
 
@@ -10,31 +10,12 @@
10
10
  import { createContext, use, useReducer } from 'react'
11
11
 
12
12
  const LOGGER = import.meta.env.DEV && import.meta.env.PUBLIC_LOGGER !== 'false'
13
- const PagesContext = createContext()
13
+ const PagesFx = createContext()
14
14
 
15
15
  /**
16
16
  * util
17
17
  */
18
18
 
19
- function css(...classNames) {
20
- return classNames
21
- .reduce((accumulator, currentValue) => {
22
- if (typeof currentValue === 'string') {
23
- accumulator.push(currentValue.trim())
24
- } else if (
25
- !Array.isArray(currentValue) &&
26
- typeof currentValue === 'object'
27
- ) {
28
- for (const e in currentValue) {
29
- if (currentValue[e]) accumulator.push(e.trim())
30
- }
31
- }
32
- return accumulator
33
- }, [])
34
- .filter((e) => e)
35
- .join(' ')
36
- }
37
-
38
19
  function values(state, payload, value) {
39
20
  const paths = payload.split('.')
40
21
 
@@ -166,7 +147,7 @@ const reducerLogger = (state, action) => {
166
147
  */
167
148
 
168
149
  function useFx(functions = { initialState: {} }) {
169
- const pageContext = use(PagesContext)
150
+ const pagesFx = use(PagesFx)
170
151
  const { initialState } = functions
171
152
  const [state, dispatch] = useReducer(
172
153
  LOGGER ? reducerLogger : reducer,
@@ -177,7 +158,12 @@ function useFx(functions = { initialState: {} }) {
177
158
  const commonActions = ['set', 'show', 'hide', 'change', 'reset'].reduce(
178
159
  (acc, e) => {
179
160
  acc[e] = (payload) =>
180
- dispatch({ type: e, payload, initialState, isContext: !pageContext })
161
+ dispatch({
162
+ type: e,
163
+ payload,
164
+ initialState,
165
+ isContext: !pagesFx?.context
166
+ })
181
167
  return acc
182
168
  },
183
169
  {}
@@ -190,10 +176,8 @@ function useFx(functions = { initialState: {} }) {
190
176
  const actionsProps = {
191
177
  ...commonActions,
192
178
  state,
193
- payload
194
- }
195
- if (pageContext) {
196
- actionsProps.context = pageContext
179
+ payload,
180
+ context: pagesFx?.context
197
181
  }
198
182
 
199
183
  return functions[e](Object.freeze(actionsProps))
@@ -206,13 +190,14 @@ function useFx(functions = { initialState: {} }) {
206
190
  const props = {
207
191
  initialState,
208
192
  state,
209
- fx: { ...commonActions, ...actions }
210
- }
211
- if (pageContext) {
212
- props.context = pageContext
193
+ fx: { ...commonActions, ...actions },
194
+ //
195
+ context: pagesFx?.context,
196
+ icons: pagesFx?.icons,
197
+ i18n: pagesFx?.i18n
213
198
  }
214
199
 
215
200
  return Object.freeze(props)
216
201
  }
217
202
 
218
- export { css, PagesContext, useFx }
203
+ export { PagesFx, useFx }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Copyright (c) 2025 Sinuhe Maceda https://sinuhe.dev
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * https://github.com/sinuhedev/nextia
8
+ */
9
+
10
+ import { PagesFx, useFx } from './fx.js'
11
+ import { I18n, Icon, Link, Svg } from './ui.js'
12
+ import {
13
+ css,
14
+ env,
15
+ startViewTransition,
16
+ useQueryString,
17
+ useResize
18
+ } from './utils.js'
19
+
20
+ export {
21
+ css,
22
+ env,
23
+ I18n,
24
+ Icon,
25
+ Link,
26
+ PagesFx,
27
+ Svg,
28
+ startViewTransition,
29
+ useFx,
30
+ useQueryString,
31
+ useResize
32
+ }
package/src/lib/ui.js ADDED
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Copyright (c) 2025 Sinuhe Maceda https://sinuhe.dev
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * https://github.com/sinuhedev/nextia
8
+ */
9
+
10
+ import { createElement, useEffect, useRef } from 'react'
11
+ import { useFx } from './fx'
12
+ import { css } from './utils'
13
+
14
+ function Link({ children, href, value = {}, ...props }) {
15
+ href ??= window.location.hash.split('?')[0]
16
+ value = Object.keys(value).length
17
+ ? `?${new URLSearchParams(value).toString()}`
18
+ : ''
19
+
20
+ return createElement('a', { href: href + value, ...props }, children)
21
+ }
22
+
23
+ function I18n({ value, args = [] }) {
24
+ const { context, i18n } = useFx()
25
+
26
+ if (i18n) {
27
+ try {
28
+ let text = value.split('.').reduce((ac, el) => ac[el], i18n)
29
+ text = text[i18n.locales.indexOf(context.state.i18n.currentLocale)]
30
+
31
+ if (args) {
32
+ text = text.replace(
33
+ /([{}])\\1|[{](.*?)(?:!(.+?))?[}]/g,
34
+ (match, _literal, number) => args[number] || match
35
+ )
36
+ }
37
+
38
+ return text
39
+ } catch {
40
+ console.error(`Error in [il8n] => ${value}`)
41
+ return value
42
+ }
43
+ }
44
+ }
45
+
46
+ function Icon({
47
+ id,
48
+ className,
49
+ animate = false,
50
+ style,
51
+ width = '48',
52
+ height,
53
+ viewBox = '0 0 48 48',
54
+ fill = 'none',
55
+ color = 'currentColor',
56
+ stroke = 'currentColor',
57
+ strokeWidth = '2',
58
+ strokeLinecap = 'round',
59
+ strokeLinejoin = 'round',
60
+ ...props
61
+ }) {
62
+ const { icons } = useFx()
63
+ const ref = useRef()
64
+
65
+ useEffect(() => {
66
+ if (icons) {
67
+ const svg = new DOMParser()
68
+ .parseFromString(icons, 'image/svg+xml')
69
+ .documentElement.getElementById(id)
70
+
71
+ if (svg) {
72
+ ref.current.innerHTML = svg.innerHTML
73
+ }
74
+ }
75
+ }, [id, icons])
76
+
77
+ return createElement('svg', {
78
+ xmlns: 'http://www.w3.org/2000/svg',
79
+ ref,
80
+ id,
81
+ className: css({ 'nextia-animate-icon': animate }, className),
82
+ style,
83
+ width,
84
+ height: height ?? width,
85
+ viewBox,
86
+ fill,
87
+ color,
88
+ stroke,
89
+ strokeWidth,
90
+ strokeLinecap,
91
+ strokeLinejoin,
92
+ ...props
93
+ })
94
+ }
95
+
96
+ function Svg({ ref, src, width, height, ...props }) {
97
+ ref ??= useRef()
98
+
99
+ useEffect(() => {
100
+ const svg = new DOMParser().parseFromString(
101
+ src,
102
+ 'image/svg+xml'
103
+ ).documentElement
104
+
105
+ for (const { name, value } of svg.attributes) {
106
+ if (name !== 'width' && name !== 'height')
107
+ ref.current.setAttribute(name, value)
108
+ }
109
+
110
+ ref.current.replaceChildren(...svg.children)
111
+ }, [src, ref])
112
+
113
+ return createElement('svg', {
114
+ ref,
115
+ width,
116
+ height: height ?? width,
117
+ ...props
118
+ })
119
+ }
120
+
121
+ export { I18n, Icon, Link, Svg }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Copyright (c) 2025 Sinuhe Maceda https://sinuhe.dev
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * https://github.com/sinuhedev/nextia
8
+ */
9
+
10
+ import { useCallback, useEffect, useState } from 'react'
11
+ import { flushSync } from 'react-dom'
12
+
13
+ /**
14
+ * env
15
+ */
16
+
17
+ const env = import.meta.env
18
+
19
+ /**
20
+ * View Transition
21
+ */
22
+
23
+ async function startViewTransition(fun = () => {}, ref, animation = 'fade') {
24
+ if (!document.startViewTransition || env.PUBLIC_VIEW_TRANSITION === 'false')
25
+ return fun()
26
+
27
+ ref.style.viewTransitionName = animation
28
+ await document.startViewTransition(() => flushSync(fun)).finished
29
+ ref.style.viewTransitionName = ''
30
+ }
31
+
32
+ /**
33
+ * hooks
34
+ */
35
+
36
+ function useQueryString() {
37
+ const getQueryString = useCallback(
38
+ () => ({
39
+ hash: window.location.hash.split('?')[0],
40
+ queryString: Object.fromEntries(
41
+ new URLSearchParams(window.location.hash.split('?')[1])
42
+ )
43
+ }),
44
+ []
45
+ )
46
+
47
+ const [queryString, setQueryString] = useState(getQueryString)
48
+
49
+ useEffect(() => {
50
+ const handlePopState = () => setQueryString(getQueryString())
51
+
52
+ window.addEventListener('popstate', handlePopState)
53
+ return () => {
54
+ window.removeEventListener('popstate', handlePopState)
55
+ }
56
+ }, [getQueryString])
57
+
58
+ return queryString
59
+ }
60
+
61
+ function useResize() {
62
+ const getResize = useCallback(
63
+ () => ({
64
+ width: window.innerWidth,
65
+ height: window.innerHeight
66
+ }),
67
+ []
68
+ )
69
+
70
+ const [resize, setResize] = useState(getResize)
71
+
72
+ useEffect(() => {
73
+ const handleResize = () => setResize(getResize())
74
+
75
+ window.addEventListener('resize', handleResize)
76
+ return () => {
77
+ window.removeEventListener('resize', handleResize)
78
+ }
79
+ }, [getResize])
80
+
81
+ return resize
82
+ }
83
+
84
+ /**
85
+ * util
86
+ */
87
+
88
+ function css(...classNames) {
89
+ return classNames
90
+ .reduce((accumulator, currentValue) => {
91
+ if (typeof currentValue === 'string') {
92
+ accumulator.push(currentValue.trim())
93
+ } else if (
94
+ !Array.isArray(currentValue) &&
95
+ typeof currentValue === 'object'
96
+ ) {
97
+ for (const e in currentValue) {
98
+ if (currentValue[e]) accumulator.push(e.trim())
99
+ }
100
+ }
101
+ return accumulator
102
+ }, [])
103
+ .filter((e) => e)
104
+ .join(' ')
105
+ }
106
+
107
+ export { css, env, startViewTransition, useQueryString, useResize }
@@ -1,29 +0,0 @@
1
- # TEMPLATE
2
-
3
- # To start
4
- Open http://localhost:3000 to view it in the browser.
5
-
6
- ```sh
7
- npm install
8
- #
9
- node --run dev
10
- node --run test
11
- node --run build <ENV>
12
- node --run preview
13
- ```
14
-
15
- # env
16
- ```.env
17
- .env # loaded in all cases
18
- .env.[ENV] # only loaded in specified ENV [ dev, test, prod ]
19
- ```
20
-
21
- * .env.dev
22
- * .env.prod
23
- * .env.test
24
-
25
- ```env
26
- PUBLIC_TITLE=TITLE
27
- PUBLIC_LOGGER=true
28
- PUBLIC_VIEW_TRANSITION=true
29
- ```
package/template/_env.dev DELETED
@@ -1,4 +0,0 @@
1
- PUBLIC_TITLE=dev
2
- PUBLIC_LOGGER=true
3
- PUBLIC_VIEW_TRANSITION=true
4
- PUBLIC_API=https://65fd14fb9fc4425c653119c5.mockapi.io/api/v1
@@ -1 +0,0 @@
1
- PUBLIC_TITLE=prod
@@ -1 +0,0 @@
1
- PUBLIC_TITLE=test
@@ -1,10 +0,0 @@
1
- node_modules
2
-
3
- out
4
- deploy
5
- deploy-variables
6
-
7
- .coverage
8
- .env
9
- .env.*
10
-
@@ -1,35 +0,0 @@
1
- {
2
- "name": "TEMPLATE",
3
- "description": "description",
4
- "version": "0.0.0",
5
- "type": "module",
6
- "private": true,
7
- "scripts": {
8
- "dev": "vite --mode dev",
9
- "clean": "rm -fr node_modules package-lock.json .coverage out",
10
- "build": "vite build --mode",
11
- "preview": "vite preview",
12
- "format": "biome format",
13
- "lint": "biome lint",
14
- "check": "biome check --reporter=summary",
15
- "page": "nextia page",
16
- "component": "nextia component",
17
- "container": "nextia container",
18
- "test": "vitest",
19
- "test:name": "vitest run --testNamePattern",
20
- "test:silent": "vitest run --silent",
21
- "test:coverage": "vitest run --silent --coverage"
22
- },
23
- "devDependencies": {
24
- "@vitejs/plugin-react": "^6.0.1",
25
- "@vitest/coverage-v8": "^4.0.18",
26
- "jsdom": "^29.0.1",
27
- "vite": "^8.0.1",
28
- "vitest": "^4.0.18"
29
- },
30
- "dependencies": {
31
- "nextia": "file:../",
32
- "react": "^19.2.4",
33
- "react-dom": "^19.2.4"
34
- }
35
- }
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
-
4
- <head>
5
- <meta charset="UTF-8" />
6
- <title>Error</title>
7
- <link rel="shortcut icon" href="logo.svg" />
8
- </head>
9
-
10
- <body>
11
- Error ...
12
- </body>
13
-
14
- </html>