cradova 1.0.1 → 1.0.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.
- package/README.md +53 -19
- package/dist/index.d.ts +26 -0
- package/dist/index.js +468 -0
- package/dist/rolled-cradova.js +2366 -0
- package/dist/scripts/JsonDB.d.ts +287 -0
- package/dist/scripts/JsonDB.js +633 -0
- package/dist/scripts/Router.d.ts +5 -0
- package/dist/scripts/Router.js +170 -0
- package/dist/scripts/Screen.d.ts +51 -0
- package/dist/scripts/Screen.js +107 -0
- package/dist/scripts/ajax.d.ts +28 -0
- package/dist/scripts/ajax.js +63 -0
- package/dist/scripts/fns.d.ts +84 -0
- package/dist/scripts/fns.js +307 -0
- package/dist/scripts/init.d.ts +1 -0
- package/dist/scripts/init.js +25 -0
- package/dist/scripts/loadCss.d.ts +1 -0
- package/dist/scripts/loadCss.js +194 -0
- package/dist/scripts/memory.d.ts +12 -0
- package/dist/scripts/memory.js +46 -0
- package/dist/scripts/store.d.ts +12 -0
- package/dist/scripts/store.js +64 -0
- package/dist/scripts/swipe.d.ts +1 -0
- package/dist/scripts/swipe.js +114 -0
- package/dist/scripts/track.d.ts +12 -0
- package/dist/scripts/track.js +150 -0
- package/dist/scripts/widget.d.ts +8 -0
- package/dist/scripts/widget.js +21 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.js +1 -0
- package/index.ts +336 -147
- package/package.json +18 -11
- package/scripts/JsonDB.ts +134 -130
- package/scripts/Router.ts +94 -24
- package/scripts/Screen.ts +99 -39
- package/scripts/{littleAxios.ts → ajax.ts} +44 -6
- package/scripts/fns.ts +341 -0
- package/scripts/init.ts +11 -4
- package/scripts/loadCss.ts +194 -0
- package/scripts/memory.ts +44 -0
- package/scripts/store.ts +32 -21
- package/scripts/style.css +189 -0
- package/scripts/swipe.ts +4 -4
- package/scripts/track.ts +171 -0
- package/scripts/widget.ts +17 -15
- package/tsconfig.json +18 -98
- package/types.ts +15 -1
- package/{online-only-after-initial-cache.ts → workers/online-only-after-initial-cache.ts} +14 -11
- package/{service-worker.ts → workers/service-worker.ts} +17 -10
- package/docs/README.md +0 -0
- package/manifest.json +0 -38
- package/scripts/Metrics.ts +0 -66
- package/scripts/animate.ts +0 -55
- package/scripts/createState.ts +0 -27
- package/scripts/css.ts +0 -47
- package/scripts/dispatcher.ts +0 -158
- package/scripts/fetcher.ts +0 -31
- package/scripts/file-system.ts +0 -173
- package/scripts/fullscreen.ts +0 -21
- package/scripts/localStorage.ts +0 -19
- package/scripts/media.ts +0 -51
- package/scripts/promptbeforeleave.ts +0 -10
- package/scripts/reuse.ts +0 -79
- package/scripts/speaker.ts +0 -25
- package/scripts/uuid.ts +0 -10
- package/types.d.ts +0 -0
package/README.md
CHANGED
|
@@ -1,37 +1,38 @@
|
|
|
1
1
|
# cradova PWA sample
|
|
2
2
|
|
|
3
3
|
<p>
|
|
4
|
-
<a href="https://www.npmjs.com/package/
|
|
5
|
-
<img src="https://img.shields.io/npm/v/
|
|
4
|
+
<a href="https://www.npmjs.com/package/cradova">
|
|
5
|
+
<img src="https://img.shields.io/npm/v/cradova.svg" alt="npm Version" />
|
|
6
6
|
</a>
|
|
7
|
-
<a href="https://github.com/
|
|
8
|
-
<img src="https://img.shields.io/npm/l/
|
|
7
|
+
<a href="https://github.com/cradova/cradova.js/blob/next/LICENSE">
|
|
8
|
+
<img src="https://img.shields.io/npm/l/cradova.svg" alt="License" />
|
|
9
9
|
</a>
|
|
10
|
-
<a href="https://www.npmjs.com/package/
|
|
11
|
-
<img src="https://img.shields.io/npm/dm/
|
|
10
|
+
<a href="https://www.npmjs.com/package/cradova">
|
|
11
|
+
<img src="https://img.shields.io/npm/dm/cradova.svg" alt="npm Downloads">
|
|
12
12
|
</a>
|
|
13
|
-
<a href="https://www.npmjs.com/package/
|
|
14
|
-
<img src="https://img.shields.io/travis/
|
|
13
|
+
<a href="https://www.npmjs.com/package/cradova">
|
|
14
|
+
<img src="https://img.shields.io/travis/cradova/cradova.js/next.svg?colorB=brightgreen" alt="Build Status">
|
|
15
15
|
</a>
|
|
16
16
|
|
|
17
|
-
<a href="https://opencollective.com/
|
|
18
|
-
<img src="https://img.shields.io/opencollective/all/
|
|
17
|
+
<a href="https://opencollective.com/cradova">
|
|
18
|
+
<img src="https://img.shields.io/opencollective/all/cradova.svg?colorB=brightgreen" alt="Donate at OpenCollective">
|
|
19
19
|
</a>
|
|
20
20
|
</p>
|
|
21
21
|
|
|
22
|
-
- [What is
|
|
22
|
+
- [What is cradova.js?](#what-is-cradova?)
|
|
23
23
|
- [Installation](#installation)
|
|
24
24
|
- [Documentation](#documentation)
|
|
25
25
|
- [Getting Help](#getting-help)
|
|
26
|
-
- [Contributing](#building-
|
|
26
|
+
- [Contributing](#building-cradova-parkages)
|
|
27
27
|
|
|
28
|
-
## What is
|
|
28
|
+
## What is cradova.js?
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
cradova is a JavaScript framework for building Single Page Applications and PWAs.
|
|
31
31
|
|
|
32
32
|
It's small, fast and provides routing and XHR utilities out of the box.
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
cradova.js supports various versions of IE11, Firefox ESR, and Firefox,
|
|
35
|
+
Edge, Safari, and Chrome. No polyfills required.
|
|
35
36
|
|
|
36
37
|
## Installation
|
|
37
38
|
|
|
@@ -39,14 +40,47 @@ Cradova.js supports various versions of IE11, Firefox ESR, and Firefox, Edge, Sa
|
|
|
39
40
|
|
|
40
41
|
```html
|
|
41
42
|
<!-- Production: whichever you prefer -->
|
|
42
|
-
<script src="https://unpkg.com/
|
|
43
|
-
<script src="https://cdn.jsdelivr.net/npm/
|
|
43
|
+
<script src="https://unpkg.com/cradova/cradova.min.js"></script>
|
|
44
|
+
<script src="https://cdn.jsdelivr.net/npm/cradova/cradova.min.js"></script>
|
|
44
45
|
```
|
|
45
46
|
|
|
46
47
|
### npm
|
|
47
48
|
|
|
48
49
|
```bash
|
|
49
|
-
npm install
|
|
50
|
+
npm install cradova --save
|
|
50
51
|
```
|
|
51
52
|
|
|
52
|
-
<img src="
|
|
53
|
+
<img src="cradova.jpg">
|
|
54
|
+
|
|
55
|
+
### `npm start`
|
|
56
|
+
|
|
57
|
+
Runs the app in the development mode.\
|
|
58
|
+
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
|
|
59
|
+
|
|
60
|
+
The page will reload when you make changes.\
|
|
61
|
+
You may also see any lint errors in the console.
|
|
62
|
+
|
|
63
|
+
### `npm test`
|
|
64
|
+
|
|
65
|
+
Launches the test runner in the interactive watch mode.\
|
|
66
|
+
See the section about [running tests](https://fridaycandour.github.io/cradova/docs/running-tests) for more information.
|
|
67
|
+
|
|
68
|
+
### `npm run build`
|
|
69
|
+
|
|
70
|
+
Builds the app for production to the `build` folder.\
|
|
71
|
+
It correctly bundles React in production mode and optimizes the build for the best performance.
|
|
72
|
+
|
|
73
|
+
The build is minified and the filenames include the hashes.\
|
|
74
|
+
Your app is ready to be deployed!
|
|
75
|
+
|
|
76
|
+
See the section about [deployment](https://fridaycandour.github.io/cradova/docs/deployment) for more information.
|
|
77
|
+
|
|
78
|
+
### Analyzing the Bundle Size
|
|
79
|
+
|
|
80
|
+
This section has moved here: [https://fridaycandour.github.io/cradova/docs/analyzing-the-bundle-size](https://fridaycandour.github.io/cradova/docs/analyzing-the-bundle-size)
|
|
81
|
+
|
|
82
|
+
### Making a Progressive Web App
|
|
83
|
+
|
|
84
|
+
This section has moved here: [https://fridaycandour.github.io/cradova/docs/making-a-progressive-web-app](https://fridaycandour.github.io/cradova/docs/making-a-progressive-web-app)
|
|
85
|
+
|
|
86
|
+
"build:cradova": "tsc --build --clean && tsc && rollup dist/index.js --format umd --name 'cradova' --file dist/rolled-cradova.js && mkdir build && touch build/build.js && terser --compress --mangle -- dist/rolled-cradova.js --output build/build.js"
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates new cradova HTML element
|
|
3
|
+
* @example
|
|
4
|
+
* format for static _`p| am a p tag` // or _`p.class| am a p tag` or _`p#id| am a p tag` or _`p.class#id| am a p tag`
|
|
5
|
+
* format for dynamic _(
|
|
6
|
+
* "p| am a p tag" // or "p.class| am a p tag" or "p#id| am a p tag" or "p.class#id| am a p tag"
|
|
7
|
+
* , {
|
|
8
|
+
* //props like
|
|
9
|
+
* text: "am a p tag",
|
|
10
|
+
* style: {
|
|
11
|
+
* color: "blue"
|
|
12
|
+
* }
|
|
13
|
+
* },
|
|
14
|
+
* // place other children here like span
|
|
15
|
+
* _`span| am a span tag like so`, // this is a static child
|
|
16
|
+
* _("span| am a span tag like so", {style: {color: "brown"}}) // this is a dynamic child
|
|
17
|
+
* )
|
|
18
|
+
* @param {...any} element_initials
|
|
19
|
+
* @returns function | HTMLElement
|
|
20
|
+
*
|
|
21
|
+
* static elements cannot be given props nor children nor state but dynamic can
|
|
22
|
+
*
|
|
23
|
+
* and static are useful too
|
|
24
|
+
*/
|
|
25
|
+
declare const _: any;
|
|
26
|
+
export default _;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
4
|
+
"
|
|
5
|
+
" ██████╗ ██████╗ █████ ██████╗ ███████╗ ██╗ ██╗ █████
|
|
6
|
+
" ██╔════╝ ██╔══██╗ ██╔═╗██ █ ██ ██╔═════╝ ██║ ██║ ██╔═╗██
|
|
7
|
+
" ██║ ██████╔╝ ██████╗ █ ██ ██║ ██ ██║ ██║ ██████╗
|
|
8
|
+
" ██║ ██╔══██ ██║ ██║ █ ██ ██║ ██ ╚██╗ ██╔╝ ██║ ██
|
|
9
|
+
" ╚██████╗ ██║ ██║ ██║ ██║ ███████╔╝ ███████ ╚████╔╝ ██║ ██║
|
|
10
|
+
" ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ ╚════╝ ╚═══╝ ╚═╝ ╚═╝
|
|
11
|
+
" JSONDB inside
|
|
12
|
+
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
13
|
+
|
|
14
|
+
" =============================================================================
|
|
15
|
+
" By Friday Candour
|
|
16
|
+
" -----------------------------------------------------------------------------
|
|
17
|
+
" =============================================================================
|
|
18
|
+
" Cradova FrameWork
|
|
19
|
+
" @version 1.*.*
|
|
20
|
+
" -----------------------------------------------------------------------------
|
|
21
|
+
" License: Apache V2
|
|
22
|
+
" -----------------------------------------------------------------------------
|
|
23
|
+
" fridaymaxtour@gmail.com ...
|
|
24
|
+
" =============================================================================
|
|
25
|
+
|
|
26
|
+
Apache License
|
|
27
|
+
Version 2.0, January 2004
|
|
28
|
+
http://www.apache.org/licenses/
|
|
29
|
+
|
|
30
|
+
Copyright 2022 Friday Candour. All Rights Reserved.
|
|
31
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
32
|
+
you may not use this file except in compliance with the License.
|
|
33
|
+
You may obtain a copy of the License at
|
|
34
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
35
|
+
Unless required by applicable law or agreed to in writing, software
|
|
36
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
37
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
38
|
+
See the License for the specific language governing permissions and
|
|
39
|
+
limitations under the License.
|
|
40
|
+
*/
|
|
41
|
+
// importing cradova helper scripts
|
|
42
|
+
import { fragment } from "./scripts/widget.js";
|
|
43
|
+
import { swipe } from "./scripts/swipe.js";
|
|
44
|
+
import { Store } from "./scripts/store.js";
|
|
45
|
+
import { Router } from "./scripts/Router.js";
|
|
46
|
+
import { Screen } from "./scripts/Screen.js";
|
|
47
|
+
import { JSONDB } from "./scripts/JsonDB.js";
|
|
48
|
+
import { littleAxios, fetcher } from "./scripts/ajax.js";
|
|
49
|
+
import { loadCradovaUICss } from "./scripts/loadCss.js";
|
|
50
|
+
import { assert, animate, PromptBeforeLeave, css, media, ls, list, } from "./scripts/fns.js";
|
|
51
|
+
import { dispatch, fullScreen } from "./scripts/track.js";
|
|
52
|
+
import { uuid } from "./scripts/fns.js";
|
|
53
|
+
import { Init } from "./scripts/init.js";
|
|
54
|
+
("use strict");
|
|
55
|
+
const make = function (txx) {
|
|
56
|
+
if (Array.isArray(txx)) {
|
|
57
|
+
txx = txx[0].trim();
|
|
58
|
+
}
|
|
59
|
+
if (!txx) {
|
|
60
|
+
return {
|
|
61
|
+
tag: "div",
|
|
62
|
+
Classes: undefined,
|
|
63
|
+
ID: undefined,
|
|
64
|
+
innerValue: undefined,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
let tag;
|
|
68
|
+
const itemsPurifier = (impure, items) => {
|
|
69
|
+
const pureItems = [];
|
|
70
|
+
for (let i = 0; i < items.length; i++) {
|
|
71
|
+
if (items[i].includes(impure)) {
|
|
72
|
+
items[i] = items[i].split(impure)[0];
|
|
73
|
+
}
|
|
74
|
+
pureItems.push(items[i]);
|
|
75
|
+
}
|
|
76
|
+
return pureItems;
|
|
77
|
+
};
|
|
78
|
+
let textContent;
|
|
79
|
+
tag = txx.trim()[0] === "|" && "p";
|
|
80
|
+
if (txx.includes("|")) {
|
|
81
|
+
textContent = txx.split("|")[1];
|
|
82
|
+
txx = txx.split("|")[0] && txx.split("|")[0];
|
|
83
|
+
}
|
|
84
|
+
const classes = itemsPurifier("#", txx.split("."));
|
|
85
|
+
const ids = itemsPurifier(".", txx.split("#"));
|
|
86
|
+
if (!tag) {
|
|
87
|
+
tag = classes.shift();
|
|
88
|
+
}
|
|
89
|
+
if (!tag) {
|
|
90
|
+
tag = ids.shift();
|
|
91
|
+
}
|
|
92
|
+
if (!tag) {
|
|
93
|
+
tag = "div";
|
|
94
|
+
}
|
|
95
|
+
if (!txx.includes(".") && !txx.includes("#")) {
|
|
96
|
+
tag = txx;
|
|
97
|
+
ids.length = 0;
|
|
98
|
+
classes.length = 0;
|
|
99
|
+
}
|
|
100
|
+
let ID = ids[1] ? ids[1].trim() : null;
|
|
101
|
+
const className = classes.join(" ");
|
|
102
|
+
let innerValue;
|
|
103
|
+
if (textContent) {
|
|
104
|
+
innerValue = textContent;
|
|
105
|
+
}
|
|
106
|
+
return { tag, className, ID, innerValue };
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Creates new cradova HTML element
|
|
110
|
+
* @example
|
|
111
|
+
* format for static _`p| am a p tag` // or _`p.class| am a p tag` or _`p#id| am a p tag` or _`p.class#id| am a p tag`
|
|
112
|
+
* format for dynamic _(
|
|
113
|
+
* "p| am a p tag" // or "p.class| am a p tag" or "p#id| am a p tag" or "p.class#id| am a p tag"
|
|
114
|
+
* , {
|
|
115
|
+
* //props like
|
|
116
|
+
* text: "am a p tag",
|
|
117
|
+
* style: {
|
|
118
|
+
* color: "blue"
|
|
119
|
+
* }
|
|
120
|
+
* },
|
|
121
|
+
* // place other children here like span
|
|
122
|
+
* _`span| am a span tag like so`, // this is a static child
|
|
123
|
+
* _("span| am a span tag like so", {style: {color: "brown"}}) // this is a dynamic child
|
|
124
|
+
* )
|
|
125
|
+
* @param {...any} element_initials
|
|
126
|
+
* @returns function | HTMLElement
|
|
127
|
+
*
|
|
128
|
+
* static elements cannot be given props nor children nor state but dynamic can
|
|
129
|
+
*
|
|
130
|
+
* and static are useful too
|
|
131
|
+
*/
|
|
132
|
+
const _ = (...element_initials) => {
|
|
133
|
+
let properties, childrens = [], beforeMount;
|
|
134
|
+
if (typeof element_initials[1] == "object" &&
|
|
135
|
+
!(element_initials[1] instanceof HTMLElement && !element_initials[1].tagName)) {
|
|
136
|
+
properties = element_initials[1];
|
|
137
|
+
if (properties?.beforeMount) {
|
|
138
|
+
beforeMount = properties["beforeMount"];
|
|
139
|
+
}
|
|
140
|
+
if (element_initials.length > 2) {
|
|
141
|
+
childrens = element_initials.slice(2, element_initials.length);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
if (element_initials[1] instanceof HTMLElement ||
|
|
146
|
+
typeof element_initials[1] === "function") {
|
|
147
|
+
childrens = element_initials.slice(1, element_initials.length);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (element_initials[0].raw) {
|
|
151
|
+
// getting the value of static cradova calls
|
|
152
|
+
element_initials[0] = element_initials[0]["raw"][0];
|
|
153
|
+
}
|
|
154
|
+
// verifing the children array
|
|
155
|
+
function identify(element_initials) {
|
|
156
|
+
if (typeof element_initials !== "object") {
|
|
157
|
+
element_initials = [element_initials];
|
|
158
|
+
}
|
|
159
|
+
const initials = make(element_initials[0]);
|
|
160
|
+
// TODO: tag debugger
|
|
161
|
+
// const { tag, className, ID, innerValue } = initials;
|
|
162
|
+
// if (tag === "div" && properties?.style?.pp === "o") {
|
|
163
|
+
// // console.log(properties.beforeMount);
|
|
164
|
+
// properties.beforeMount();
|
|
165
|
+
// }
|
|
166
|
+
/**
|
|
167
|
+
*
|
|
168
|
+
* --- Cradova Element Initials ---
|
|
169
|
+
* --------------------------------
|
|
170
|
+
*
|
|
171
|
+
* Note: this element has not been initialised!
|
|
172
|
+
*
|
|
173
|
+
* add to a parent element or call this return fuction
|
|
174
|
+
*
|
|
175
|
+
* .
|
|
176
|
+
*/
|
|
177
|
+
return (...incoming) => {
|
|
178
|
+
/*
|
|
179
|
+
*
|
|
180
|
+
* --- Cradova Element Initials ---
|
|
181
|
+
* --------------------------------
|
|
182
|
+
*
|
|
183
|
+
* Note: this element has not been initialised!
|
|
184
|
+
*
|
|
185
|
+
* add to a parent element or call this return fuction
|
|
186
|
+
*
|
|
187
|
+
* .
|
|
188
|
+
*/
|
|
189
|
+
let childrens2rd = [], props = {}, text;
|
|
190
|
+
for (let i = 0; i < incoming.length; i++) {
|
|
191
|
+
if (typeof incoming[i] === "function" ||
|
|
192
|
+
incoming[i] instanceof HTMLElement
|
|
193
|
+
// ||
|
|
194
|
+
// incoming[i].tagName
|
|
195
|
+
) {
|
|
196
|
+
childrens2rd.push(incoming[i]);
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
// if (
|
|
200
|
+
// !incoming[i]
|
|
201
|
+
// ) {
|
|
202
|
+
// console.log(incoming[i]);
|
|
203
|
+
// continue;
|
|
204
|
+
// }
|
|
205
|
+
//
|
|
206
|
+
if (
|
|
207
|
+
// !incoming[i].tagName &&
|
|
208
|
+
!(incoming[i] instanceof HTMLElement) &&
|
|
209
|
+
!Array.isArray(incoming[i]) &&
|
|
210
|
+
typeof incoming[i] === "object" &&
|
|
211
|
+
!incoming[i].tagName) {
|
|
212
|
+
if (incoming[i].beforeMount) {
|
|
213
|
+
beforeMount = incoming[i]["beforeMount"];
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if (incoming[i].composedPath) {
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
props = incoming[i];
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
//
|
|
223
|
+
if (typeof incoming[i] === "string") {
|
|
224
|
+
text = incoming[i];
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (childrens.length) {
|
|
229
|
+
childrens2rd.push(...childrens);
|
|
230
|
+
}
|
|
231
|
+
let element;
|
|
232
|
+
try {
|
|
233
|
+
element = document.createElement(initials.tag.trim());
|
|
234
|
+
}
|
|
235
|
+
catch (error) {
|
|
236
|
+
throw new TypeError("cradova err invalid tag given " + initials.tag);
|
|
237
|
+
}
|
|
238
|
+
if (!element) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
if (initials.className) {
|
|
242
|
+
element.className = initials.className.trim();
|
|
243
|
+
}
|
|
244
|
+
if (initials.ID) {
|
|
245
|
+
element.id = initials.ID.trim();
|
|
246
|
+
}
|
|
247
|
+
if (initials.innerValue) {
|
|
248
|
+
element.append(initials.innerValue);
|
|
249
|
+
}
|
|
250
|
+
for (const prop in properties) {
|
|
251
|
+
if (prop === "style") {
|
|
252
|
+
for (const [k, v] of Object.entries(properties[prop])) {
|
|
253
|
+
element.style[k] = v;
|
|
254
|
+
}
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
if (element.style[prop] === "" && prop !== "src") {
|
|
258
|
+
element.style[prop] = properties[prop];
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
if (prop === "class" && typeof properties[prop] === "string") {
|
|
262
|
+
const classes = properties[prop].split(" ");
|
|
263
|
+
for (let i = 0; i < classes.length; i++) {
|
|
264
|
+
if (classes[i]) {
|
|
265
|
+
element.classList.add(classes[i]);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
if (prop === "text") {
|
|
271
|
+
element.innerText = properties[prop];
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
try {
|
|
275
|
+
element[prop] = properties[prop];
|
|
276
|
+
}
|
|
277
|
+
catch (error) {
|
|
278
|
+
throw new Error("cradova err invalid props " +
|
|
279
|
+
prop +
|
|
280
|
+
" for this element type with value " +
|
|
281
|
+
properties[prop]);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
//
|
|
285
|
+
// dynamic props
|
|
286
|
+
// over-rides props that appear in the first level
|
|
287
|
+
if (props && typeof props === "object" && !Array.isArray(props)) {
|
|
288
|
+
for (const prop in props) {
|
|
289
|
+
if (prop === "style") {
|
|
290
|
+
for (const [k, v] of Object.entries(props[prop])) {
|
|
291
|
+
element.style[k] = v;
|
|
292
|
+
}
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
if (prop === "text" && typeof props[prop] === "string") {
|
|
296
|
+
element.innerText = props[prop];
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
if (prop === "class" && typeof props[prop] === "string") {
|
|
300
|
+
element.classList.add(props[prop]);
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
if (prop === "beforeMount") {
|
|
304
|
+
beforeMount = props["beforeMount"];
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
if (prop === "fullscreen") {
|
|
308
|
+
if (properties[prop]) {
|
|
309
|
+
fullScreen(element).set();
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
fullScreen(element).exist();
|
|
313
|
+
}
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
try {
|
|
317
|
+
element[prop] = props[prop];
|
|
318
|
+
}
|
|
319
|
+
catch (error) {
|
|
320
|
+
// console.log(element);
|
|
321
|
+
// console.log(props);
|
|
322
|
+
console.error(error);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
if (childrens2rd && childrens2rd[0]) {
|
|
327
|
+
//
|
|
328
|
+
for (let i = 0; i < childrens2rd.length; i++) {
|
|
329
|
+
if (typeof childrens2rd[i] === "function") {
|
|
330
|
+
const child = childrens2rd[i]();
|
|
331
|
+
element.append(child);
|
|
332
|
+
if (child.afterMount) {
|
|
333
|
+
child.afterMount(child);
|
|
334
|
+
child.afterMount = undefined;
|
|
335
|
+
}
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
if (Array.isArray(childrens2rd[i])) {
|
|
339
|
+
const arrCX = childrens2rd[i];
|
|
340
|
+
const arrSET = [];
|
|
341
|
+
for (let p = 0; p < arrCX.length; p++) {
|
|
342
|
+
if (!(arrCX[p] instanceof HTMLElement) &&
|
|
343
|
+
typeof arrCX[p] !== "function" &&
|
|
344
|
+
!Array.isArray(arrCX[p])) {
|
|
345
|
+
throw new TypeError("cradova err invalid children list, should be a html element from cradova " +
|
|
346
|
+
arrCX[p]);
|
|
347
|
+
}
|
|
348
|
+
arrSET.push(arrCX[p]);
|
|
349
|
+
}
|
|
350
|
+
//
|
|
351
|
+
childrens2rd = [
|
|
352
|
+
...childrens2rd.slice(0, i + 1),
|
|
353
|
+
...arrSET,
|
|
354
|
+
...childrens2rd.slice(i + 1, childrens2rd.length),
|
|
355
|
+
];
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
const child = childrens2rd[i];
|
|
359
|
+
element.append(child);
|
|
360
|
+
if (child.afterMount) {
|
|
361
|
+
child.afterMount(child);
|
|
362
|
+
child.afterMount = undefined;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
if (text) {
|
|
367
|
+
element.append(text);
|
|
368
|
+
}
|
|
369
|
+
// TODO: this will be updated to use data-stateid soon
|
|
370
|
+
// spped test still going on
|
|
371
|
+
if (element.stateID) {
|
|
372
|
+
// adding cradova dynamic signature
|
|
373
|
+
element.classList.add("cra_child_doc");
|
|
374
|
+
}
|
|
375
|
+
if (beforeMount) {
|
|
376
|
+
beforeMount(element);
|
|
377
|
+
}
|
|
378
|
+
return element;
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
if (typeof element_initials[0] !== "string") {
|
|
382
|
+
return () => "empty cradova call";
|
|
383
|
+
}
|
|
384
|
+
const CradovaElemet = identify(element_initials);
|
|
385
|
+
if (!CradovaElemet) {
|
|
386
|
+
throw new Error("Cradova err invalid element initials " + element_initials);
|
|
387
|
+
}
|
|
388
|
+
return CradovaElemet;
|
|
389
|
+
};
|
|
390
|
+
Init(_);
|
|
391
|
+
/**
|
|
392
|
+
* Create element and get a callback to update their state
|
|
393
|
+
* no need to manage stateIDs
|
|
394
|
+
* ----------------------------------------------------------------
|
|
395
|
+
*
|
|
396
|
+
* @param element_initials
|
|
397
|
+
* @param props
|
|
398
|
+
* @returns
|
|
399
|
+
*/
|
|
400
|
+
function $(element_initials = "div", props = {}) {
|
|
401
|
+
props.stateID = uuid();
|
|
402
|
+
const element = _(element_initials, props);
|
|
403
|
+
return [element, dispatch.bind(null, props.stateID)];
|
|
404
|
+
}
|
|
405
|
+
const controls = function () {
|
|
406
|
+
const svg = `<svg width="20" height="20" viewBox="0 0 10 10" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
407
|
+
<path d="M4.49975 5.625C4.3402 5.6242 4.18282 5.58788 4.03904 5.5187C3.89526 5.44951 3.76869 5.34919 3.6685 5.225L1.03725 2.0375C0.8835 1.84561 0.786745 1.61438 0.758014 1.37017C0.729283 1.12596 0.769733 0.878589 0.874753 0.65625C0.959928 0.463017 1.09892 0.298383 1.27514 0.182014C1.45136 0.0656449 1.65734 0.00245816 1.8685 0H7.131C7.34216 0.00245816 7.54815 0.0656449 7.72437 0.182014C7.90058 0.298383 8.03958 0.463017 8.12475 0.65625C8.22977 0.878589 8.27023 1.12596 8.24149 1.37017C8.21276 1.61438 8.11601 1.84561 7.96226 2.0375L5.331 5.225C5.23082 5.34919 5.10424 5.44951 4.96047 5.5187C4.81669 5.58788 4.65931 5.6242 4.49975 5.625Z" fill="#2c3e50"/>
|
|
408
|
+
</svg>
|
|
409
|
+
`;
|
|
410
|
+
const icon = (styles) => _("div", { ...styles, innerHTML: svg });
|
|
411
|
+
const constr = _("div", {
|
|
412
|
+
display: "flex",
|
|
413
|
+
position: "fixed",
|
|
414
|
+
alignContent: "center",
|
|
415
|
+
justifyContent: "space-around",
|
|
416
|
+
flexDirection: "row",
|
|
417
|
+
width: "80px",
|
|
418
|
+
top: "4px",
|
|
419
|
+
right: "4px",
|
|
420
|
+
backgroundColor: "#fff",
|
|
421
|
+
transform: "rotate(0deg)",
|
|
422
|
+
border: "aqua 2px solid",
|
|
423
|
+
borderRadius: "6px",
|
|
424
|
+
}, icon({
|
|
425
|
+
transform: "rotate(90deg)",
|
|
426
|
+
/* border: "red 2px solid", */ onclick() {
|
|
427
|
+
window.history.back();
|
|
428
|
+
},
|
|
429
|
+
}), icon({
|
|
430
|
+
transform: "rotate(270deg)",
|
|
431
|
+
/* border: "red 2px solid", */ onclick() {
|
|
432
|
+
window.history.forward();
|
|
433
|
+
},
|
|
434
|
+
}));
|
|
435
|
+
const cont = constr();
|
|
436
|
+
if (cont) {
|
|
437
|
+
document.body.append(cont);
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
function register(modules) {
|
|
441
|
+
for (let i = 0; i < modules.length; i++) {
|
|
442
|
+
_[modules[i]] = modules[i];
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
register([
|
|
446
|
+
fragment,
|
|
447
|
+
swipe,
|
|
448
|
+
Store,
|
|
449
|
+
Router,
|
|
450
|
+
Screen,
|
|
451
|
+
JSONDB,
|
|
452
|
+
fetcher,
|
|
453
|
+
littleAxios,
|
|
454
|
+
loadCradovaUICss,
|
|
455
|
+
assert,
|
|
456
|
+
animate,
|
|
457
|
+
PromptBeforeLeave,
|
|
458
|
+
css,
|
|
459
|
+
media,
|
|
460
|
+
ls,
|
|
461
|
+
list,
|
|
462
|
+
$,
|
|
463
|
+
controls,
|
|
464
|
+
]);
|
|
465
|
+
for (const key in _) {
|
|
466
|
+
console.log(key);
|
|
467
|
+
}
|
|
468
|
+
export default _;
|