@axel669/zephyr 1.0.0-beta.0 → 1.0.0-dev.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 +21 -21
- package/compiler/build.js +13 -0
- package/compiler/parser.js +2973 -0
- package/compiler/rollup.js +28 -0
- package/compiler/transpiler.js +140 -0
- package/dist/zephyr-unstyled.js +555 -0
- package/dist/zephyr-unstyled.min.js +1 -0
- package/dist/zephyr.js +1946 -0
- package/dist/zephyr.min.js +47 -0
- package/package.json +50 -48
- package/readme.md +194 -19
- package/src/changed.svelte.js +0 -23
- package/src/component/adorn.svelte +0 -9
- package/src/component/alert.svelte +0 -32
- package/src/component/application.svelte +0 -17
- package/src/component/async-button.svelte +0 -53
- package/src/component/avatar.svelte +0 -15
- package/src/component/badge.svelte +0 -7
- package/src/component/button.svelte +0 -7
- package/src/component/chip.svelte +0 -10
- package/src/component/circle-spinner.svelte +0 -6
- package/src/component/confirm.svelte +0 -40
- package/src/component/control-label.svelte +0 -41
- package/src/component/data-table.svelte +0 -227
- package/src/component/details.svelte +0 -22
- package/src/component/dialog-element.svelte +0 -35
- package/src/component/dialog.svelte +0 -43
- package/src/component/drawer.svelte +0 -20
- package/src/component/flex.svelte +0 -7
- package/src/component/grid.svelte +0 -7
- package/src/component/hexagon-spinner.svelte +0 -6
- package/src/component/icon.svelte +0 -7
- package/src/component/link.svelte +0 -11
- package/src/component/modal.svelte +0 -32
- package/src/component/paper.svelte +0 -33
- package/src/component/popover.svelte +0 -19
- package/src/component/progress.svelte +0 -6
- package/src/component/prompt.svelte +0 -58
- package/src/component/route.svelte +0 -62
- package/src/component/routing.svelte.js +0 -63
- package/src/component/screen.svelte +0 -30
- package/src/component/select.svelte +0 -40
- package/src/component/suspend.svelte +0 -44
- package/src/component/table.svelte +0 -49
- package/src/component/tabs.svelte +0 -2
- package/src/component/text.svelte +0 -26
- package/src/component/title.svelte +0 -28
- package/src/component/titlebar.svelte +0 -23
- package/src/component/toast.svelte +0 -7
- package/src/component/toaster.svelte +0 -60
- package/src/component/toggle-label.svelte +0 -11
- package/src/component/tooltip.svelte +0 -11
- package/src/custom-macros.js +0 -11
- package/src/handler$.js +0 -20
- package/src/hash.js +0 -14
- package/src/index.js +0 -65
- package/src/internals.js +0 -12
- package/src/main.js +0 -47
- package/src/props.js +0 -24
- package/src/variant.js +0 -10
- package/src/wind.js +0 -4
- package/src/ws.js +0 -10
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import fs from "fs-jetpack"
|
|
2
|
+
|
|
3
|
+
import { transpile } from "./transpiler.js"
|
|
4
|
+
|
|
5
|
+
const defaults = {
|
|
6
|
+
sourceImport: "@axel669/zephyr"
|
|
7
|
+
}
|
|
8
|
+
export default (options) => {
|
|
9
|
+
const opts = {
|
|
10
|
+
...defaults,
|
|
11
|
+
...options,
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
name: "zephyr",
|
|
15
|
+
async load(filepath) {
|
|
16
|
+
if (filepath.includes("node_modules") === true) {
|
|
17
|
+
return null
|
|
18
|
+
}
|
|
19
|
+
const source = fs.read(filepath)
|
|
20
|
+
const code = await transpile({
|
|
21
|
+
filename: filepath,
|
|
22
|
+
source,
|
|
23
|
+
sourceImport: opts.sourceImport
|
|
24
|
+
})
|
|
25
|
+
return code
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import fs from "fs-jetpack"
|
|
2
|
+
import * as parser from "./parser.js"
|
|
3
|
+
import * as prettier from "prettier"
|
|
4
|
+
|
|
5
|
+
const stringifyContent = (content, props) => content.reduce(
|
|
6
|
+
(list, child) => {
|
|
7
|
+
if (child === null) {
|
|
8
|
+
return list
|
|
9
|
+
}
|
|
10
|
+
if (typeof child === "string") {
|
|
11
|
+
if (child.trim() === "") {
|
|
12
|
+
return list
|
|
13
|
+
}
|
|
14
|
+
return [...list, JSON.stringify(child)]
|
|
15
|
+
}
|
|
16
|
+
if (child.slot !== undefined) {
|
|
17
|
+
const content = stringifyContent(child.content).join(", ")
|
|
18
|
+
props.push([
|
|
19
|
+
`slot:${child.slot}`,
|
|
20
|
+
`(${child.propName ?? ""}) => [${content}]`
|
|
21
|
+
])
|
|
22
|
+
return list
|
|
23
|
+
}
|
|
24
|
+
if (child.condition !== undefined) {
|
|
25
|
+
const content = child.content.map(
|
|
26
|
+
child => stringifyPart(child)
|
|
27
|
+
).join(", ")
|
|
28
|
+
const alt = child.alt.map(
|
|
29
|
+
child => stringifyPart(child)
|
|
30
|
+
).join(", ")
|
|
31
|
+
return [
|
|
32
|
+
...list,
|
|
33
|
+
`(${child.condition}) ? [${content}] : [${alt}]`
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
if (child.each !== undefined) {
|
|
37
|
+
const content = stringifyContent(child.content).join(", ")
|
|
38
|
+
const each = `(${child.each})?.map((${child.expand}) => [${content}]) ?? []`
|
|
39
|
+
if (child.alt.length === 0) {
|
|
40
|
+
return [
|
|
41
|
+
...list,
|
|
42
|
+
each
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
const alt = stringifyContent(child.alt)
|
|
46
|
+
return [
|
|
47
|
+
...list,
|
|
48
|
+
`$galeCore.__eachAlt(${each}, () => [${alt}])`
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
return [...list, stringifyPart(child)]
|
|
52
|
+
},
|
|
53
|
+
[]
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
const tagstr = (isHTML, tag) => {
|
|
57
|
+
if (isHTML === true) {
|
|
58
|
+
return `"${tag}"`
|
|
59
|
+
}
|
|
60
|
+
return tag
|
|
61
|
+
}
|
|
62
|
+
const stringifyPart = (part) => {
|
|
63
|
+
if (typeof part === "string") {
|
|
64
|
+
return part
|
|
65
|
+
}
|
|
66
|
+
if (part.js !== undefined) {
|
|
67
|
+
return part.js
|
|
68
|
+
}
|
|
69
|
+
if (part.react !== undefined) {
|
|
70
|
+
return `$galeCore.useEffect(() => {${part.code}}, ${part.react})`
|
|
71
|
+
}
|
|
72
|
+
if (part.component !== undefined) {
|
|
73
|
+
return `memo((props) => ${part.component} , valtimemo)`
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const props = [ ...part.props ]
|
|
77
|
+
const children = stringifyContent(part.children, props)
|
|
78
|
+
const isHTMLElement = (/^[a-z\-_]+$/.test(part.tag) === true)
|
|
79
|
+
const propsCode = props.map(
|
|
80
|
+
(pair) => {
|
|
81
|
+
if (typeof pair === "string") {
|
|
82
|
+
return pair
|
|
83
|
+
}
|
|
84
|
+
const [prop, value] = pair
|
|
85
|
+
if (prop.startsWith("$$") === true && value.startsWith("#") === true) {
|
|
86
|
+
const key = prop.slice(2)
|
|
87
|
+
const val = value.slice(1)
|
|
88
|
+
return `"${prop}": { value: ${val}, update: (e) => ${val} = $galeCore.getInputValue(e.target) }`
|
|
89
|
+
}
|
|
90
|
+
if (value.startsWith("&") === true) {
|
|
91
|
+
const val = value.slice(1)
|
|
92
|
+
return `"${prop}": $galeCore.lock((node) => ${val} = $galeCore.ref(node))`
|
|
93
|
+
}
|
|
94
|
+
if (prop.startsWith("on:") === true) {
|
|
95
|
+
return `"${prop.replace(":", "")}": ${value}`
|
|
96
|
+
}
|
|
97
|
+
return `"${prop}": ${value}`
|
|
98
|
+
}
|
|
99
|
+
).join(", ")
|
|
100
|
+
const tag = tagstr(isHTMLElement, part.tag)
|
|
101
|
+
if (part.tag.startsWith("$:") === true) {
|
|
102
|
+
return `$galeCore.Element($galeCore.Slot, { "*render": ${tag.slice(2)}, ${propsCode} })`
|
|
103
|
+
}
|
|
104
|
+
if (children.length === 0) {
|
|
105
|
+
return `$galeCore.Element(${tag}, {${propsCode}})`
|
|
106
|
+
}
|
|
107
|
+
return `$galeCore.Element(${tag}, {${propsCode}},\n${children.join(",\n")}\n)`
|
|
108
|
+
}
|
|
109
|
+
const stringify = (parts) =>
|
|
110
|
+
parts.map(stringifyPart)
|
|
111
|
+
.join("")
|
|
112
|
+
const done = (parts) =>
|
|
113
|
+
parts.find(part => typeof part !== "string") === undefined
|
|
114
|
+
export const transpile = (options) => {
|
|
115
|
+
const {
|
|
116
|
+
filename,
|
|
117
|
+
source,
|
|
118
|
+
sourceImport = "@axel669/zephyr",
|
|
119
|
+
} = options
|
|
120
|
+
|
|
121
|
+
let step = parser.parse(source)
|
|
122
|
+
if (done(step) === true) {
|
|
123
|
+
return source
|
|
124
|
+
}
|
|
125
|
+
while (done(step) === false) {
|
|
126
|
+
step = parser.parse(
|
|
127
|
+
stringify(step)
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
return prettier.format(
|
|
131
|
+
`import * as $galeCore from "${sourceImport}"\n${step.join("")}`,
|
|
132
|
+
{
|
|
133
|
+
printWidth: 70,
|
|
134
|
+
experimentalOperatorPosition: "start",
|
|
135
|
+
tabWidth: 4,
|
|
136
|
+
semi: false,
|
|
137
|
+
parser: "babel",
|
|
138
|
+
}
|
|
139
|
+
)
|
|
140
|
+
}
|